draganddrophelper.cpp
dolphinmodel.cpp
dolphinsettings.cpp
+ dolphintooltip.cpp
dolphincategorydrawer.cpp
dolphinview.cpp
dolphinviewactionhandler.cpp
--- /dev/null
+#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
--- /dev/null
+/***************************************************************************
+ * 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
#include "tooltipmanager.h"
+#include "dolphintooltip.h"
#include "dolphinmodel.h"
#include "dolphinsortfilterproxymodel.h"
-#include <kformattedballoontipdelegate.h>
#include <kicon.h>
#include <ktooltip.h>
#include <QTimer>
#include <QToolTip>
-K_GLOBAL_STATIC(KFormattedBalloonTipDelegate, g_delegate)
+K_GLOBAL_STATIC(DolphinBalloonTooltipDelegate, g_delegate)
ToolTipManager::ToolTipManager(QAbstractItemView* parent,
DolphinSortFilterProxyModel* model) :
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
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();
}
-
KToolTip::showTip(QPoint(x, y), tip);
}