From f10a0a63e699288f1288c193c49795cae9cb3b40 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 16 Oct 2010 12:47:49 +0200 Subject: 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. --- hoverwindow.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 hoverwindow.cpp (limited to 'hoverwindow.cpp') 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 +#include + +#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("

%1

").arg(parent); + curText.append("
    "); + int count = qMin(6, children.size()); + int i = 0; + for(i = 0; i < count; ++i){ + curText.append(QString("
  • %1
  • ").arg(children.at(i))); + } + if(i < children.count()){ + curText.append("
  • ...
  • "); + } + curText.append("
"); + mLabel->setText(curText); +} + +void HoverWindow::setPixmap(const QPixmap &pm){ + mLabel->setPixmap(pm); +} -- cgit v1.2.3-70-g09d2