]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Tooltip improvements
authorPeter Penz <peter.penz19@gmail.com>
Tue, 22 Mar 2011 17:43:12 +0000 (18:43 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 22 Mar 2011 17:46:11 +0000 (18:46 +0100)
- Use the default style for drawing the tooltip background
- Get rid of the workaround to keep only one KFileMetaDataWidget instance. This is not required anymore as internally in KFileMetaDataWidget a process is used to get the metadata instead of a thread.

src/views/tooltips/filemetadatatooltip.cpp
src/views/tooltips/filemetadatatooltip.h
src/views/tooltips/tooltipmanager.cpp

index b8e1724d8a13ad15fca4dc55103c08310c27575a..deda38ab6ebaa3ca61bcc9713da78bf2a1db223a 100644 (file)
@@ -26,7 +26,8 @@
 #include <KWindowSystem>
 
 #include <QLabel>
-#include <QPainter>
+#include <QStyleOptionFrame>
+#include <QStylePainter>
 #include <QVBoxLayout>
 
 FileMetaDataToolTip::FileMetaDataToolTip(QWidget* parent) :
@@ -49,7 +50,7 @@ FileMetaDataToolTip::FileMetaDataToolTip(QWidget* parent) :
     m_name->setFont(font);
 
     // Create widget for the meta data
-    m_fileMetaDataWidget = new KFileMetaDataWidget();
+    m_fileMetaDataWidget = new KFileMetaDataWidget(this);
     m_fileMetaDataWidget->setForegroundRole(QPalette::ToolTipText);
     m_fileMetaDataWidget->setReadOnly(true);
     connect(m_fileMetaDataWidget, SIGNAL(metaDataRequestFinished(KFileItemList)),
@@ -112,51 +113,13 @@ KFileItemList FileMetaDataToolTip::items() const
 
 void FileMetaDataToolTip::paintEvent(QPaintEvent* event)
 {
-    Q_UNUSED(event);
+    QStylePainter painter(this);
+    QStyleOptionFrame option;
+    option.init(this);
+    painter.drawPrimitive(QStyle::PE_PanelTipLabel, option);
+    painter.end();
 
-    QPainter painter(this);
-
-    QColor toColor = palette().brush(QPalette::ToolTipBase).color();
-    QColor fromColor = KColorScheme::shade(toColor, KColorScheme::LightShade, 0.2);
-
-    const bool haveAlphaChannel = KWindowSystem::compositingActive();
-    if (haveAlphaChannel) {
-        painter.setRenderHint(QPainter::Antialiasing);
-        painter.translate(0.5, 0.5);
-        toColor.setAlpha(220);
-        fromColor.setAlpha(220);
-    }
-
-    QLinearGradient gradient(QPointF(0.0, 0.0), QPointF(0.0, height()));
-    gradient.setColorAt(0.0, fromColor);
-    gradient.setColorAt(1.0, toColor);
-    painter.setPen(Qt::NoPen);
-    painter.setBrush(gradient);
-
-    const QRect rect(0, 0, width(), height());
-    if (haveAlphaChannel) {
-        const qreal radius = 5.0;
-
-        QPainterPath path;
-        path.moveTo(rect.left(), rect.top() + radius);
-        arc(path, rect.left()  + radius, rect.top()    + radius, radius, 180, -90);
-        arc(path, rect.right() - radius, rect.top()    + radius, radius,  90, -90);
-        arc(path, rect.right() - radius, rect.bottom() - radius, radius,   0, -90);
-        arc(path, rect.left()  + radius, rect.bottom() - radius, radius, 270, -90);
-        path.closeSubpath();
-
-        painter.drawPath(path);
-    } else {
-        painter.drawRect(rect);
-    }
-}
-
-void FileMetaDataToolTip::arc(QPainterPath& path,
-                              qreal cx, qreal cy,
-                              qreal radius, qreal angle,
-                              qreal sweepLength)
-{
-    path.arcTo(cx-radius, cy-radius, radius * 2, radius * 2, angle, sweepLength);
+    QWidget::paintEvent(event);
 }
 
 #include "filemetadatatooltip.moc"
index 14be5427c75cee85ebd9f734522b6dce5ca78809..0f614d7d0b810c19c1218b579a3cc6ad6c7d3c0d 100644 (file)
@@ -63,16 +63,6 @@ signals:
 protected:
     virtual void paintEvent(QPaintEvent* event);
 
-private:
-    /**
-     * Helper method for FileMetaDataToolTip::paintEvent() to adjust the painter path \p path
-     * by rounded corners.
-     */
-    static void arc(QPainterPath& path,
-                    qreal cx, qreal cy,
-                    qreal radius, qreal angle,
-                    qreal sweepLength);
-
 private:
     QLabel* m_preview;
     QLabel* m_name;
index 44e60049f42f813b0f768ca486ada93514aefbff..f93dd90bed2d158e2c62c0727cf964fd880effb0 100644 (file)
@@ -48,17 +48,6 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent,
     m_item(),
     m_itemRect()
 {
-    static FileMetaDataToolTip* sharedToolTip = 0;
-    if (!sharedToolTip) {
-        sharedToolTip = new FileMetaDataToolTip();
-        // TODO: Using K_GLOBAL_STATIC would be preferable to maintain the
-        // instance, but the cleanup of KFileMetaDataWidget at this stage does
-        // not work.
-    }
-    m_fileMetaDataToolTip = sharedToolTip;
-    connect(m_fileMetaDataToolTip, SIGNAL(metaDataRequestFinished(KFileItemList)),
-            this, SLOT(slotMetaDataRequestFinished()));
-
     m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel());
     connect(parent, SIGNAL(entered(const QModelIndex&)),
             this, SLOT(requestToolTip(const QModelIndex&)));
@@ -86,6 +75,7 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent,
     connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(hideToolTip()));
 
+    Q_ASSERT(m_view);
     m_view->viewport()->installEventFilter(this);
     m_view->installEventFilter(this);
 }
@@ -106,9 +96,9 @@ void ToolTipManager::hideToolTip()
     m_showToolTipTimer->stop();
     m_contentRetrievalTimer->stop();
 
-    m_fileMetaDataToolTip->setItems(KFileItemList());
-    m_fileMetaDataToolTip->hide();
-}
+    delete m_fileMetaDataToolTip;
+    m_fileMetaDataToolTip = 0;}
+
 
 bool ToolTipManager::eventFilter(QObject* watched, QEvent* event)
 {
@@ -145,6 +135,11 @@ void ToolTipManager::requestToolTip(const QModelIndex& index)
         // Only start the retrieving of the content, when the mouse has been over this
         // item for 200 milliseconds. This prevents a lot of useless preview jobs and
         // meta data retrieval, when passing rapidly over a lot of items.
+        Q_ASSERT(!m_fileMetaDataToolTip);
+        m_fileMetaDataToolTip = new FileMetaDataToolTip(m_view);
+        connect(m_fileMetaDataToolTip, SIGNAL(metaDataRequestFinished(KFileItemList)),
+                this, SLOT(slotMetaDataRequestFinished()));
+
         m_contentRetrievalTimer->start();
         m_showToolTipTimer->start();
         m_toolTipRequested = true;