]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Very rough initial attempt at previews-in-tooltip for Konqueror and Dolphin. Still...
authorSimon Paul St James <kdedevel@etotheipiplusone.com>
Mon, 18 Aug 2008 20:33:21 +0000 (20:33 +0000)
committerSimon Paul St James <kdedevel@etotheipiplusone.com>
Mon, 18 Aug 2008 20:33:21 +0000 (20:33 +0000)
CCBUG:161848

svn path=/trunk/KDE/kdebase/apps/; revision=848984

src/CMakeLists.txt
src/dolphintooltip.cpp [new file with mode: 0644]
src/dolphintooltip.h [new file with mode: 0644]
src/tooltipmanager.cpp

index f09810b71608ace5ac21b170e5c6c54559db0c04..96941803bb94e31a4124ec5c7a02f7ddb7fd5789 100644 (file)
@@ -28,6 +28,7 @@ set(dolphinprivate_LIB_SRCS
     draganddrophelper.cpp
     dolphinmodel.cpp
     dolphinsettings.cpp
     draganddrophelper.cpp
     dolphinmodel.cpp
     dolphinsettings.cpp
+    dolphintooltip.cpp
     dolphincategorydrawer.cpp
     dolphinview.cpp
     dolphinviewactionhandler.cpp
     dolphincategorydrawer.cpp
     dolphinview.cpp
     dolphinviewactionhandler.cpp
diff --git a/src/dolphintooltip.cpp b/src/dolphintooltip.cpp
new file mode 100644 (file)
index 0000000..67b5fd6
--- /dev/null
@@ -0,0 +1,61 @@
+#include "dolphintooltip.h"
+
+#include <kicon.h>
+#include <kio/previewjob.h>
+#include <kfileitem.h>
+
+#include <QtGui/QPixmap>
+
+const int PREVIEW_WIDTH = 256;
+const int PREVIEW_HEIGHT = 256;
+
+DolphinToolTipItem::DolphinToolTipItem(const KFileItem & fileItem) :
+        KToolTipItem(KIcon(fileItem.iconName()), fileItem.getToolTipText(), UserType)
+{
+
+    //if (icon().actualSize(QSize(256,256)).width() != PREVIEW_WIDTH)
+    /*{
+        QPixmap paddedImage(QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT));
+        paddedImage.fill(Qt::transparent);
+        QPainter painter(&paddedImage);
+        KIcon kicon(fileItem.iconName());
+        painter.drawPixmap((PREVIEW_WIDTH - 128) / 2, (PREVIEW_HEIGHT - 128) / 2, kicon.pixmap(QSize(128,128))); 
+        setData(Qt::DecorationRole, QIcon(paddedImage));
+    }*/
+
+    // Initiate the preview job.
+    KFileItemList fileItems;
+    fileItems << fileItem;
+    KIO::PreviewJob* job = KIO::filePreview(fileItems, PREVIEW_WIDTH, PREVIEW_HEIGHT );
+    connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
+            this, SLOT(setPreview(const KFileItem&, const QPixmap&)));
+
+}
+DolphinToolTipItem::~DolphinToolTipItem()
+{
+}
+void DolphinToolTipItem::setPreview(const KFileItem& fileItem, const QPixmap& preview)
+{
+    Q_UNUSED(fileItem);
+   /* QPixmap paddedImage(QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT));
+    paddedImage.fill(Qt::transparent);
+    QPainter painter(&paddedImage);
+    KIcon kicon(fileItem.iconName());
+    painter.drawPixmap((PREVIEW_WIDTH - preview.width()) / 2, (PREVIEW_HEIGHT - preview.height()) / 2, preview); 
+    setData(Qt::DecorationRole, QIcon(paddedImage));*/
+    setData(Qt::DecorationRole, QIcon(preview));
+};
+// Delegate everything to the base class, after re-setting the decorationSize
+// to the preview size.
+QSize DolphinBalloonTooltipDelegate::sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const
+{
+    KStyleOptionToolTip updatedStyleOption = *option;
+    updatedStyleOption.decorationSize = QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
+    return KFormattedBalloonTipDelegate::sizeHint(&updatedStyleOption, item);
+}
+void DolphinBalloonTooltipDelegate::paint(QPainter *painter, const KStyleOptionToolTip *option, const KToolTipItem *item) const
+{    
+    KStyleOptionToolTip updatedStyleOption = *option;
+    updatedStyleOption.decorationSize = QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
+    return KFormattedBalloonTipDelegate::paint(painter, &updatedStyleOption, item);
+}
\ No newline at end of file
diff --git a/src/dolphintooltip.h b/src/dolphintooltip.h
new file mode 100644 (file)
index 0000000..32cc340
--- /dev/null
@@ -0,0 +1,55 @@
+/***************************************************************************
+ *   Copyright (C) 2008 by Simon St James <kdedevel@etotheipiplusone.com>  *
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+// NOTE: proper documentation will be added once the code is better developed.
+#ifndef DOLPHINTOOLTIP_H
+#define DOLPHINTOOLTIP_H
+
+#include "ktooltip.h"
+#include "kformattedballoontipdelegate.h"
+
+#include <kio/previewjob.h>
+#include <QtCore/QObject>
+
+class KFileItem;
+class QPixmap;
+
+class DolphinToolTipItem : public QObject, public KToolTipItem
+{
+    Q_OBJECT
+public:
+        DolphinToolTipItem(const KFileItem & fileItem);
+        virtual ~DolphinToolTipItem();
+private slots:
+        void setPreview(const KFileItem& fileItem, const QPixmap& preview);
+private:
+};
+
+class DolphinBalloonTooltipDelegate : public KFormattedBalloonTipDelegate
+{
+public:
+    DolphinBalloonTooltipDelegate() {}
+    virtual ~DolphinBalloonTooltipDelegate() {}
+
+    virtual QSize sizeHint(const KStyleOptionToolTip *option, const KToolTipItem *item) const;
+    virtual void paint(QPainter *painter, const KStyleOptionToolTip *option, const KToolTipItem *item) const;
+private:
+};
+#endif
\ No newline at end of file
index 8e4ad0eba986fdea3cd7a5ee4ca826a9356b56eb..2b41ac48f797a0361f79502950f8a1499cb52f03 100644 (file)
 
 #include "tooltipmanager.h"
 
 
 #include "tooltipmanager.h"
 
+#include "dolphintooltip.h"
 #include "dolphinmodel.h"
 #include "dolphinsortfilterproxymodel.h"
 
 #include "dolphinmodel.h"
 #include "dolphinsortfilterproxymodel.h"
 
-#include <kformattedballoontipdelegate.h>
 #include <kicon.h>
 #include <ktooltip.h>
 
 #include <kicon.h>
 #include <ktooltip.h>
 
@@ -31,7 +31,7 @@
 #include <QTimer>
 #include <QToolTip>
 
 #include <QTimer>
 #include <QToolTip>
 
-K_GLOBAL_STATIC(KFormattedBalloonTipDelegate, g_delegate)
+K_GLOBAL_STATIC(DolphinBalloonTooltipDelegate, g_delegate)
 
 ToolTipManager::ToolTipManager(QAbstractItemView* parent,
                                DolphinSortFilterProxyModel* model) :
 
 ToolTipManager::ToolTipManager(QAbstractItemView* parent,
                                DolphinSortFilterProxyModel* model) :
@@ -103,7 +103,10 @@ void ToolTipManager::hideToolTip()
 
 void ToolTipManager::showToolTip()
 {
 
 void ToolTipManager::showToolTip()
 {
-    KToolTipItem* tip = new KToolTipItem(KIcon(m_item.iconName()), m_item.getToolTipText());
+    // TODO - create tip during requestTip(...) - this makes it more likely that the previews
+    // job will have completed by the time the tooltip is shown, resulting in less flicker.
+    // The memory management will be more intricate, though.
+    DolphinToolTipItem *tip = new DolphinToolTipItem(m_item);
 
     KStyleOptionToolTip option;
     // TODO: get option content from KToolTip or add KToolTip::sizeHint() method
 
     KStyleOptionToolTip option;
     // TODO: get option content from KToolTip or add KToolTip::sizeHint() method
@@ -127,12 +130,22 @@ void ToolTipManager::showToolTip()
     int x = m_itemRect.right();
     int y = m_itemRect.bottom();
     if (x + size.width() - 1 > desktop.right()) {
     int x = m_itemRect.right();
     int y = m_itemRect.bottom();
     if (x + size.width() - 1 > desktop.right()) {
-        x = m_itemRect.left() - size.width();
+        // Any room to the left of the item? 
+        if (m_itemRect.left() - size.width() > desktop.left())
+        {
+            x = m_itemRect.left() - size.width();
+        }
+        else
+        {
+            // Move left until we are back onscreen; we'll be horizontally
+            // overlapping m_itemRect, but hopefully the y value will keep us
+            // from drawing inside it.
+            x = desktop.right() - size.width();
+        }
     }
     if (y + size.height() - 1 > desktop.bottom()) {
         y = m_itemRect.top() - size.height();
     }
     }
     if (y + size.height() - 1 > desktop.bottom()) {
         y = m_itemRect.top() - size.height();
     }
-
     KToolTip::showTip(QPoint(x, y), tip);
 }
 
     KToolTip::showTip(QPoint(x, y), tip);
 }