┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-11-27 00:27:59 +0100
committerPeter Penz <[email protected]>2011-11-27 00:29:25 +0100
commitd7f89808f7620e5b4cecc606e1fd3ac1df43c1b4 (patch)
treef108509599e9f063044fb4919dc3145499fbfde3
parent362817d1834f2ada3ea4552a25fa39bbbb540f8c (diff)
Apply icon effect for cut items
Fix issue that no icon effect got applied to icons that have been cut.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/kitemviews/kfileitemclipboard.cpp76
-rw-r--r--src/kitemviews/kfileitemclipboard_p.h62
-rw-r--r--src/kitemviews/kfileitemlistwidget.cpp73
-rw-r--r--src/kitemviews/kfileitemlistwidget.h10
-rw-r--r--src/kitemviews/kfileitemmodel.cpp1
6 files changed, 210 insertions, 13 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index af82e74fe..c5c02e1c5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -18,6 +18,7 @@ add_subdirectory(tests)
########### next target ###############
set(dolphinprivate_LIB_SRCS
+ kitemviews/kfileitemclipboard.cpp
kitemviews/kfileitemlistgroupheader.cpp
kitemviews/kfileitemlistview.cpp
kitemviews/kfileitemlistwidget.cpp
diff --git a/src/kitemviews/kfileitemclipboard.cpp b/src/kitemviews/kfileitemclipboard.cpp
new file mode 100644
index 000000000..fb63f9530
--- /dev/null
+++ b/src/kitemviews/kfileitemclipboard.cpp
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * 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 *
+ ***************************************************************************/
+
+#include "kfileitemclipboard_p.h"
+
+#include <KGlobal>
+#include <QApplication>
+#include <QClipboard>
+#include <QMimeData>
+
+class KFileItemClipboardSingleton
+{
+public:
+ KFileItemClipboard instance;
+};
+K_GLOBAL_STATIC(KFileItemClipboardSingleton, s_KFileItemClipboard)
+
+
+
+KFileItemClipboard* KFileItemClipboard::instance()
+{
+ return &s_KFileItemClipboard->instance;
+}
+
+bool KFileItemClipboard::isCut(const KUrl& url) const
+{
+ return m_cutItems.contains(url);
+}
+
+QList<KUrl> KFileItemClipboard::cutItems() const
+{
+ return m_cutItems.toList();
+}
+
+KFileItemClipboard::~KFileItemClipboard()
+{
+}
+
+void KFileItemClipboard::updateCutItems()
+{
+ const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+ const QByteArray data = mimeData->data("application/x-kde-cutselection");
+ const bool isCutSelection = (!data.isEmpty() && data.at(0) == QLatin1Char('1'));
+ if (isCutSelection) {
+ m_cutItems = KUrl::List::fromMimeData(mimeData).toSet();
+ emit cutItemsChanged();
+ }
+}
+
+KFileItemClipboard::KFileItemClipboard() :
+ QObject(0),
+ m_cutItems()
+{
+ updateCutItems();
+
+ connect(QApplication::clipboard(), SIGNAL(dataChanged()),
+ this, SLOT(updateCutItems()));
+}
+
+#include "kfileitemclipboard_p.moc"
diff --git a/src/kitemviews/kfileitemclipboard_p.h b/src/kitemviews/kfileitemclipboard_p.h
new file mode 100644
index 000000000..86eb8e9fc
--- /dev/null
+++ b/src/kitemviews/kfileitemclipboard_p.h
@@ -0,0 +1,62 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <[email protected]> *
+ * *
+ * 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 *
+ ***************************************************************************/
+
+#ifndef KFILEITEMCLIPBOARD_H
+#define KFILEITEMCLIPBOARD_H
+
+#include <KUrl>
+#include <QList>
+#include <QSet>
+#include <QObject>
+
+#include "libdolphin_export.h"
+
+/**
+ * @brief Wrapper for QClipboard to provide fast access for checking
+ * whether a KFileItem has been clipped.
+ */
+class LIBDOLPHINPRIVATE_EXPORT KFileItemClipboard : public QObject
+{
+ Q_OBJECT
+
+public:
+ static KFileItemClipboard* instance();
+
+ bool isCut(const KUrl& url) const;
+
+ QList<KUrl> cutItems() const;
+
+signals:
+ void cutItemsChanged();
+
+protected:
+ virtual ~KFileItemClipboard();
+
+private slots:
+ void updateCutItems();
+
+private:
+ KFileItemClipboard();
+
+ QSet<KUrl> m_cutItems;
+
+ friend class KFileItemClipboardSingleton;
+};
+
+#endif
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp
index 897600e60..4eccf6862 100644
--- a/src/kitemviews/kfileitemlistwidget.cpp
+++ b/src/kitemviews/kfileitemlistwidget.cpp
@@ -19,6 +19,7 @@
#include "kfileitemlistwidget.h"
+#include "kfileitemclipboard_p.h"
#include "kfileitemmodel.h"
#include "kitemlistview.h"
#include "kpixmapmodifier_p.h"
@@ -41,6 +42,8 @@
KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
KItemListWidget(parent),
+ m_isCut(false),
+ m_isHidden(false),
m_isDir(false),
m_dirtyLayout(true),
m_dirtyContent(true),
@@ -362,6 +365,40 @@ void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
m_dirtyLayout = true;
}
+void KFileItemListWidget::showEvent(QShowEvent* event)
+{
+ KItemListWidget::showEvent(event);
+
+ // Listen to changes of the clipboard to mark the item as cut/uncut
+ KFileItemClipboard* clipboard = KFileItemClipboard::instance();
+
+ const KUrl itemUrl = data().value("url").value<KUrl>();
+ m_isCut = clipboard->isCut(itemUrl);
+
+ connect(clipboard, SIGNAL(cutItemsChanged()),
+ this, SLOT(slotCutItemsChanged()));
+}
+
+void KFileItemListWidget::hideEvent(QHideEvent* event)
+{
+ disconnect(KFileItemClipboard::instance(), SIGNAL(cutItemsChanged()),
+ this, SLOT(slotCutItemsChanged()));
+
+ KItemListWidget::hideEvent(event);
+}
+
+void KFileItemListWidget::slotCutItemsChanged()
+{
+ const KUrl itemUrl = data().value("url").value<KUrl>();
+ const bool isCut = KFileItemClipboard::instance()->isCut(itemUrl);
+ if (m_isCut != isCut) {
+ m_isCut = isCut;
+ m_pixmap = QPixmap();
+ m_dirtyContent = true;
+ update();
+ }
+}
+
void KFileItemListWidget::triggerCacheRefreshing()
{
if ((!m_dirtyContent && !m_dirtyLayout) || index() < 0) {
@@ -370,7 +407,9 @@ void KFileItemListWidget::triggerCacheRefreshing()
refreshCache();
- m_isDir = data()["isDir"].toBool();
+ const QHash<QByteArray, QVariant> values = data();
+ m_isDir = values["isDir"].toBool();
+ m_isHidden = values["name"].toString().startsWith(QLatin1Char('.'));
updateExpansionArea();
updateTextsCache();
@@ -471,6 +510,14 @@ void KFileItemListWidget::updatePixmapCache()
m_hoverPixmapRect.setSize(m_pixmap.size());
}
+ if (m_isCut) {
+ applyCutEffect(m_pixmap);
+ }
+
+ if (m_isHidden) {
+ applyHiddenEffect(m_pixmap);
+ }
+
Q_ASSERT(m_pixmap.height() == iconHeight);
}
if (!m_overlay.isNull()) {
@@ -498,7 +545,7 @@ void KFileItemListWidget::updatePixmapCache()
KIconEffect* effect = KIconLoader::global()->iconEffect();
// In the KIconLoader terminology, active = hover.
if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState)) {
- m_hoverPixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::ActiveState);
+ m_hoverPixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::ActiveState);
} else {
m_hoverPixmap = m_pixmap;
}
@@ -765,13 +812,6 @@ void KFileItemListWidget::updateAdditionalInfoTextColor()
void KFileItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
{
- const bool isHiddenItem = m_text[Name].text().startsWith(QLatin1Char('.'));
- qreal opacity;
- if (isHiddenItem) {
- opacity = painter->opacity();
- painter->setOpacity(opacity * 0.3);
- }
-
if (m_scaledPixmapSize != pixmap.size()) {
QPixmap scaledPixmap = pixmap;
KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize);
@@ -784,10 +824,6 @@ void KFileItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
} else {
painter->drawPixmap(m_pixmapPos, pixmap);
}
-
- if (isHiddenItem) {
- painter->setOpacity(opacity);
- }
}
QPixmap KFileItemListWidget::pixmapForIcon(const QString& name, int size)
@@ -839,4 +875,15 @@ KFileItemListWidget::TextId KFileItemListWidget::roleTextId(const QByteArray& ro
return rolesHash.value(role);
}
+void KFileItemListWidget::applyCutEffect(QPixmap& pixmap)
+{
+ KIconEffect* effect = KIconLoader::global()->iconEffect();
+ pixmap = effect->apply(pixmap, KIconLoader::Desktop, KIconLoader::DisabledState);
+}
+
+void KFileItemListWidget::applyHiddenEffect(QPixmap& pixmap)
+{
+ KIconEffect::semiTransparent(pixmap);
+}
+
#include "kfileitemlistwidget.moc"
diff --git a/src/kitemviews/kfileitemlistwidget.h b/src/kitemviews/kfileitemlistwidget.h
index 3e47b567b..5baaa1b28 100644
--- a/src/kitemviews/kfileitemlistwidget.h
+++ b/src/kitemviews/kfileitemlistwidget.h
@@ -87,6 +87,11 @@ protected:
virtual void hoveredChanged(bool hovered);
virtual void selectedChanged(bool selected);
virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
+ virtual void showEvent(QShowEvent* event);
+ virtual void hideEvent(QHideEvent* event);
+
+private slots:
+ void slotCutItemsChanged();
private:
enum TextId {
@@ -117,9 +122,14 @@ private:
static QPixmap pixmapForIcon(const QString& name, int size);
static TextId roleTextId(const QByteArray& role);
+ static void applyCutEffect(QPixmap& pixmap);
+ static void applyHiddenEffect(QPixmap& pixmap);
private:
+ bool m_isCut;
+ bool m_isHidden;
bool m_isDir;
+
bool m_dirtyLayout;
bool m_dirtyContent;
QSet<QByteArray> m_dirtyContentRoles;
diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index 945aa82c8..d1e0fc6f1 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -946,6 +946,7 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item)
// and hence will be retrieved asynchronously by KFileItemModelRolesUpdater.
QHash<QByteArray, QVariant> data;
data.insert("iconPixmap", QPixmap());
+ data.insert("url", item.url());
const bool isDir = item.isDir();
if (m_requestRole[IsDirRole]) {