diff options
author | Arno <am@disconnect.de> | 2010-10-16 12:47:49 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-10-16 12:47:49 +0200 |
commit | f10a0a63e699288f1288c193c49795cae9cb3b40 (patch) | |
tree | a4bd7c83440223a2eeec787f8f50c070e34fbe72 /hoverwindow.cpp | |
parent | 101cc9ec266a2d3b5168ab5053efbf868be7e25b (diff) | |
download | SheMov-f10a0a63e699288f1288c193c49795cae9cb3b40.tar.gz SheMov-f10a0a63e699288f1288c193c49795cae9cb3b40.tar.bz2 SheMov-f10a0a63e699288f1288c193c49795cae9cb3b40.zip |
Created general purpose HoverWidget
This commit outsources the HoverWindow to a seperate file and makes it
possible to set a pixmap to the window. Also the cursor offset is only
calculated once in SmGlobals.
Diffstat (limited to 'hoverwindow.cpp')
-rw-r--r-- | hoverwindow.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/hoverwindow.cpp b/hoverwindow.cpp new file mode 100644 index 0000000..59c851e --- /dev/null +++ b/hoverwindow.cpp @@ -0,0 +1,41 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include <QHBoxLayout> +#include <QLabel> + +#include "hoverwindow.h" + +HoverWindow::HoverWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f){ + setVisible(false); + setWindowOpacity(0.7); + setStyleSheet("QLabel { background-color: #D6A583; color: black; border-width: 2px; border-style: solid; padding: 4px; }"); + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->setContentsMargins(4, 4, 4, 4); + mLabel = new QLabel; + mainLayout->addWidget(mLabel); + setLayout(mainLayout); +} + +void HoverWindow::setContent(const QString &parent, const QStringList &children){ + QString curText = QString("<p style=\"align: center; text-decoration: underline; font-weight: bold; margin-bottom: 0;\">%1</p>").arg(parent); + curText.append("<ul style=\"margin-left: -25; margin-top: 0px;\">"); + int count = qMin(6, children.size()); + int i = 0; + for(i = 0; i < count; ++i){ + curText.append(QString("<li>%1</li>").arg(children.at(i))); + } + if(i < children.count()){ + curText.append("<li>...</li>"); + } + curText.append("</ul>"); + mLabel->setText(curText); +} + +void HoverWindow::setPixmap(const QPixmap &pm){ + mLabel->setPixmap(pm); +} |