########### next target ###############
set(dolphinprivate_LIB_SRCS
+ kitemviews/kfileitemclipboard.cpp
kitemviews/kfileitemlistgroupheader.cpp
kitemviews/kfileitemlistview.cpp
kitemviews/kfileitemlistwidget.cpp
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.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 *
+ ***************************************************************************/
+
+#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"
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.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 *
+ ***************************************************************************/
+
+#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
#include "kfileitemlistwidget.h"
+#include "kfileitemclipboard_p.h"
#include "kfileitemmodel.h"
#include "kitemlistview.h"
#include "kpixmapmodifier_p.h"
KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
KItemListWidget(parent),
+ m_isCut(false),
+ m_isHidden(false),
m_isDir(false),
m_dirtyLayout(true),
m_dirtyContent(true),
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) {
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();
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()) {
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;
}
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);
} else {
painter->drawPixmap(m_pixmapPos, pixmap);
}
-
- if (isHiddenItem) {
- painter->setOpacity(opacity);
- }
}
QPixmap KFileItemListWidget::pixmapForIcon(const QString& name, int size)
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"
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 {
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;
// 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]) {