mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
improve the handling when applying item effects to cut items
svn path=/trunk/KDE/kdebase/apps/; revision=645516
This commit is contained in:
parent
e74cc60fef
commit
ae338af474
|
@ -585,32 +585,11 @@ void DolphinMainWindow::undo()
|
||||||
|
|
||||||
void DolphinMainWindow::cut()
|
void DolphinMainWindow::cut()
|
||||||
{
|
{
|
||||||
QClipboard* clipboard = QApplication::clipboard();
|
|
||||||
const QMimeData* currentMimeData = clipboard->mimeData();
|
|
||||||
const bool hadCutSelection = KonqMimeData::decodeIsCutSelection(currentMimeData);
|
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData();
|
QMimeData* mimeData = new QMimeData();
|
||||||
const KUrl::List kdeUrls = m_activeView->selectedUrls();
|
const KUrl::List kdeUrls = m_activeView->selectedUrls();
|
||||||
const KUrl::List mostLocalUrls;
|
const KUrl::List mostLocalUrls;
|
||||||
KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
|
KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
|
||||||
QApplication::clipboard()->setMimeData(mimeData);
|
QApplication::clipboard()->setMimeData(mimeData);
|
||||||
|
|
||||||
if (hadCutSelection) {
|
|
||||||
// If an old cut selection has been applied, the view must
|
|
||||||
// be reloaded to get the original icons of the items without an
|
|
||||||
// applied item effect.
|
|
||||||
m_view[PrimaryIdx]->reload();
|
|
||||||
if (m_view[SecondaryIdx] != 0) {
|
|
||||||
m_view[SecondaryIdx]->reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// apply an item effect for the icons of all cut items
|
|
||||||
m_view[PrimaryIdx]->updateCutItems();
|
|
||||||
if (m_view[SecondaryIdx] != 0) {
|
|
||||||
m_view[SecondaryIdx]->updateCutItems();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinMainWindow::copy()
|
void DolphinMainWindow::copy()
|
||||||
|
|
|
@ -86,6 +86,10 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
|
||||||
connect(m_mainWindow, SIGNAL(activeViewChanged()),
|
connect(m_mainWindow, SIGNAL(activeViewChanged()),
|
||||||
this, SLOT(updateActivationState()));
|
this, SLOT(updateActivationState()));
|
||||||
|
|
||||||
|
QClipboard* clipboard = QApplication::clipboard();
|
||||||
|
connect(clipboard, SIGNAL(dataChanged()),
|
||||||
|
this, SLOT(updateCutItems()));
|
||||||
|
|
||||||
m_urlNavigator = new UrlNavigator(url, this);
|
m_urlNavigator = new UrlNavigator(url, this);
|
||||||
m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
|
m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
|
||||||
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
|
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
|
||||||
|
@ -823,6 +827,7 @@ void DolphinView::startDirLister(const KUrl& url, bool reload)
|
||||||
m_statusBar->setProgress(0);
|
m_statusBar->setProgress(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_cutItemsCache.clear();
|
||||||
m_blockContentsMovedSignal = true;
|
m_blockContentsMovedSignal = true;
|
||||||
m_dirLister->stop();
|
m_dirLister->stop();
|
||||||
m_dirLister->openUrl(url, false, reload);
|
m_dirLister->openUrl(url, false, reload);
|
||||||
|
@ -917,34 +922,6 @@ void DolphinView::requestActivation()
|
||||||
m_mainWindow->setActiveView(this);
|
m_mainWindow->setActiveView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinView::updateCutItems()
|
|
||||||
{
|
|
||||||
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
|
||||||
if (!KonqMimeData::decodeIsCutSelection(mimeData)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KFileItemList items(m_dirLister->items());
|
|
||||||
KFileItemList::const_iterator it = items.begin();
|
|
||||||
const KFileItemList::const_iterator end = items.end();
|
|
||||||
while (it != end) {
|
|
||||||
KFileItem* item = *it;
|
|
||||||
if (isCutItem(*item)) {
|
|
||||||
const QModelIndex idx = m_dirModel->indexForItem(*item);
|
|
||||||
const QVariant value = m_dirModel->data(idx, Qt::DecorationRole);
|
|
||||||
if (value.type() == QVariant::Icon) {
|
|
||||||
const QIcon icon(qvariant_cast<QIcon>(value));
|
|
||||||
KIconEffect iconEffect;
|
|
||||||
const QPixmap pixmap = iconEffect.apply(icon.pixmap(128, 128),
|
|
||||||
K3Icon::Desktop,
|
|
||||||
K3Icon::DisabledState);
|
|
||||||
m_dirModel->setData(idx, QIcon(pixmap), Qt::DecorationRole);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DolphinView::changeNameFilter(const QString& nameFilter)
|
void DolphinView::changeNameFilter(const QString& nameFilter)
|
||||||
{
|
{
|
||||||
// The name filter of KDirLister does a 'hard' filtering, which
|
// The name filter of KDirLister does a 'hard' filtering, which
|
||||||
|
@ -1005,7 +982,6 @@ void DolphinView::dropUrls(const KUrl::List& urls,
|
||||||
|
|
||||||
const KUrl& destination = (directory == 0) ? url() :
|
const KUrl& destination = (directory == 0) ? url() :
|
||||||
directory->url();
|
directory->url();
|
||||||
|
|
||||||
dropUrls(urls, destination);
|
dropUrls(urls, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1015,7 +991,6 @@ void DolphinView::dropUrls(const KUrl::List& urls,
|
||||||
m_mainWindow->dropUrls(urls, destination);
|
m_mainWindow->dropUrls(urls, destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DolphinView::updateSorting(DolphinView::Sorting sorting)
|
void DolphinView::updateSorting(DolphinView::Sorting sorting)
|
||||||
{
|
{
|
||||||
ViewProperties props(url());
|
ViewProperties props(url());
|
||||||
|
@ -1048,6 +1023,25 @@ void DolphinView::updateActivationState()
|
||||||
m_urlNavigator->setActive(isActive());
|
m_urlNavigator->setActive(isActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinView::updateCutItems()
|
||||||
|
{
|
||||||
|
// restore the icons of all previously selected items to the
|
||||||
|
// original state...
|
||||||
|
QList<CutItem>::const_iterator it = m_cutItemsCache.begin();
|
||||||
|
QList<CutItem>::const_iterator end = m_cutItemsCache.end();
|
||||||
|
while (it != end) {
|
||||||
|
const QModelIndex index = m_dirModel->indexForUrl((*it).url);
|
||||||
|
if (index.isValid()) {
|
||||||
|
m_dirModel->setData(index, QIcon((*it).pixmap), Qt::DecorationRole);
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
m_cutItemsCache.clear();
|
||||||
|
|
||||||
|
// ... and apply an item effect to all currently cut items
|
||||||
|
applyCutItemEffect();
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinView::createView()
|
void DolphinView::createView()
|
||||||
{
|
{
|
||||||
// delete current view
|
// delete current view
|
||||||
|
@ -1142,4 +1136,41 @@ bool DolphinView::isCutItem(const KFileItem& item) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinView::applyCutItemEffect()
|
||||||
|
{
|
||||||
|
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
||||||
|
if (!KonqMimeData::decodeIsCutSelection(mimeData)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
KFileItemList items(m_dirLister->items());
|
||||||
|
KFileItemList::const_iterator it = items.begin();
|
||||||
|
const KFileItemList::const_iterator end = items.end();
|
||||||
|
while (it != end) {
|
||||||
|
KFileItem* item = *it;
|
||||||
|
if (isCutItem(*item)) {
|
||||||
|
const QModelIndex index = m_dirModel->indexForItem(*item);
|
||||||
|
const KFileItem* item = m_dirModel->itemForIndex(index);
|
||||||
|
const QVariant value = m_dirModel->data(index, Qt::DecorationRole);
|
||||||
|
if ((value.type() == QVariant::Icon) && (item != 0)) {
|
||||||
|
const QIcon icon(qvariant_cast<QIcon>(value));
|
||||||
|
QPixmap pixmap = icon.pixmap(128, 128);
|
||||||
|
|
||||||
|
// remember current pixmap for the item to be able
|
||||||
|
// to restore it when other items get cut
|
||||||
|
CutItem cutItem;
|
||||||
|
cutItem.url = item->url();
|
||||||
|
cutItem.pixmap = pixmap;
|
||||||
|
m_cutItemsCache.append(cutItem);
|
||||||
|
|
||||||
|
// apply icon effect to the cut item
|
||||||
|
KIconEffect iconEffect;
|
||||||
|
pixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState);
|
||||||
|
m_dirModel->setData(index, QIcon(pixmap), Qt::DecorationRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "dolphinview.moc"
|
#include "dolphinview.moc"
|
||||||
|
|
|
@ -353,9 +353,6 @@ public slots:
|
||||||
*/
|
*/
|
||||||
void requestActivation();
|
void requestActivation();
|
||||||
|
|
||||||
/** Applies an item effect to all cut items of the clipboard. */
|
|
||||||
void updateCutItems();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/** Is emitted if URL of the view has been changed to \a url. */
|
/** Is emitted if URL of the view has been changed to \a url. */
|
||||||
void urlChanged(const KUrl& url);
|
void urlChanged(const KUrl& url);
|
||||||
|
@ -496,6 +493,9 @@ private slots:
|
||||||
*/
|
*/
|
||||||
void updateActivationState();
|
void updateActivationState();
|
||||||
|
|
||||||
|
/** Applies an item effect to all cut items of the clipboard. */
|
||||||
|
void updateCutItems();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void startDirLister(const KUrl& url, bool reload = false);
|
void startDirLister(const KUrl& url, bool reload = false);
|
||||||
|
|
||||||
|
@ -541,7 +541,19 @@ private:
|
||||||
*/
|
*/
|
||||||
bool isCutItem(const KFileItem& item) const;
|
bool isCutItem(const KFileItem& item) const;
|
||||||
|
|
||||||
|
/** Applies an item effect to all cut items. */
|
||||||
|
void applyCutItemEffect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* Remembers the original pixmap for an item before
|
||||||
|
* the cut effect is applied.
|
||||||
|
*/
|
||||||
|
struct CutItem {
|
||||||
|
KUrl url;
|
||||||
|
QPixmap pixmap;
|
||||||
|
};
|
||||||
|
|
||||||
bool m_showProgress;
|
bool m_showProgress;
|
||||||
bool m_blockContentsMovedSignal;
|
bool m_blockContentsMovedSignal;
|
||||||
Mode m_mode;
|
Mode m_mode;
|
||||||
|
@ -565,6 +577,8 @@ private:
|
||||||
KDirModel* m_dirModel;
|
KDirModel* m_dirModel;
|
||||||
DolphinDirLister* m_dirLister;
|
DolphinDirLister* m_dirLister;
|
||||||
DolphinSortFilterProxyModel* m_proxyModel;
|
DolphinSortFilterProxyModel* m_proxyModel;
|
||||||
|
|
||||||
|
QList<CutItem> m_cutItemsCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _DOLPHINVIEW_H_
|
#endif // _DOLPHINVIEW_H_
|
||||||
|
|
Loading…
Reference in a new issue