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. --- seriestreewidget.cpp | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) (limited to 'seriestreewidget.cpp') diff --git a/seriestreewidget.cpp b/seriestreewidget.cpp index 791fb9e..b5a3feb 100644 --- a/seriestreewidget.cpp +++ b/seriestreewidget.cpp @@ -24,12 +24,6 @@ #include #include #include -#include -#include - -#include -#include -#include #include "seriestreewidget.h" #include "smtreemodel.h" @@ -37,6 +31,7 @@ #include "seriestreemodel.h" #include "filestreemodel.h" #include "helper.h" +#include "hoverwindow.h" SeriesTreeWidget::SeriesTreeWidget(QWidget *parent) : QWidget(parent){ //filter bar @@ -318,12 +313,9 @@ void SeriesTreeWidget::addCover(){ } } -SeriesTreeView::SeriesTreeView(QWidget *parent) : QTreeView(parent), mCursorOffset(0) { +SeriesTreeView::SeriesTreeView(QWidget *parent) : QTreeView(parent) { setAttribute(Qt::WA_Hover); - mHoverWin = new SeriesTreeHoverWindow; - XFixesCursorImage *curImage = XFixesGetCursorImage(QX11Info::display()); - mCursorOffset = curImage->height; - XFree(curImage); + mHoverWin = new HoverWindow; } void SeriesTreeView::contextMenuEvent(QContextMenuEvent *e){ @@ -337,7 +329,7 @@ void SeriesTreeView::contextMenuEvent(QContextMenuEvent *e){ bool SeriesTreeView::event(QEvent *e){ QModelIndex curIdx; QHoverEvent *hEvent = static_cast(e); - QPoint hotSpot(hEvent->pos().x(), hEvent->pos().y() - mCursorOffset); + QPoint hotSpot(hEvent->pos().x(), hEvent->pos().y() - SmGlobals::instance()->cursorOffset()); QPoint globalPos = mapToGlobal(hotSpot); QPoint where = globalPos + QPoint(30, 30); @@ -393,32 +385,6 @@ QStringList SeriesTreeView::children(const QModelIndex &idx) const{ return retval; } -SeriesTreeHoverWindow::SeriesTreeHoverWindow(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 SeriesTreeHoverWindow::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); -} - SeriesTreeSortModel::SeriesTreeSortModel(QObject *parent) : QSortFilterProxyModel(parent) {} bool SeriesTreeSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{ -- cgit v1.2.3-70-g09d2