diff options
author | Ken Moore <ken@pcbsd.org> | 2015-03-12 08:10:56 -0400 |
---|---|---|
committer | Ken Moore <ken@pcbsd.org> | 2015-03-12 08:10:56 -0400 |
commit | 6f2d86bca68975dc311a4838dbbb30e059d1fc1d (patch) | |
tree | 86cf376d5d63858048539e95282808d60eef57df /lumina-desktop/desktop-plugins | |
parent | Clean up some of the Lumina theme watcher usage (add a 1/2 second delay after... (diff) | |
download | lumina-6f2d86bca68975dc311a4838dbbb30e059d1fc1d.tar.gz lumina-6f2d86bca68975dc311a4838dbbb30e059d1fc1d.tar.bz2 lumina-6f2d86bca68975dc311a4838dbbb30e059d1fc1d.zip |
Update a bunch of icons in the desktop session, and also add a few abilities to the desktopview plugin:
1) Multi-item selection
2) cut/copy files to clipboard
3) delete files
4) increase/decrease icon sizes
Diffstat (limited to 'lumina-desktop/desktop-plugins')
3 files changed, 119 insertions, 7 deletions
diff --git a/lumina-desktop/desktop-plugins/LDPlugin.h b/lumina-desktop/desktop-plugins/LDPlugin.h index 0e1f6847..9660a85c 100644 --- a/lumina-desktop/desktop-plugins/LDPlugin.h +++ b/lumina-desktop/desktop-plugins/LDPlugin.h @@ -68,6 +68,10 @@ public slots: //This needs to be re-implemented in the subclassed plugin //This is where all the visuals are set if using Theme-dependant icons. } + +signals: + void OpenDesktopMenu(); + }; #endif
\ No newline at end of file diff --git a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp index 018f96e8..0aa4a3de 100644 --- a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp +++ b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp @@ -2,6 +2,8 @@ #include <QFileInfo> #include <QDir> +#include <QClipboard> +#include <QMimeData> #include <LuminaXDG.h> #include "LSession.h" @@ -17,17 +19,31 @@ DesktopViewPlugin::DesktopViewPlugin(QWidget* parent, QString ID) : LDPlugin(par list->setBatchSize(10); //keep it snappy list->setSpacing(2); list->setSelectionBehavior(QAbstractItemView::SelectItems); - list->setSelectionMode(QAbstractItemView::NoSelection); + list->setSelectionMode(QAbstractItemView::ExtendedSelection); list->setStyleSheet( "QListWidget{ background: transparent; border: none; }" ); - list->setIconSize(QSize(64,64)); + int icosize = settings->value("IconSize",64).toInt(); + list->setIconSize(QSize(icosize,icosize)); list->setUniformItemSizes(true); + list->setContextMenuPolicy(Qt::CustomContextMenu); + + menu = new QMenu(this); + menu->addAction( LXDG::findIcon("run-build-file",""), tr("Open"), this, SLOT(runItems()) ); + menu->addSeparator(); + menu->addAction( LXDG::findIcon("edit-cut",""), tr("Cut"), this, SLOT(cutItems()) ); + menu->addAction( LXDG::findIcon("edit-copy",""), tr("Copy"), this, SLOT(copyItems()) ); + menu->addSeparator(); + menu->addAction( LXDG::findIcon("zoom-in",""), tr("Increase Icons"), this, SLOT(increaseIconSize()) ); + menu->addAction( LXDG::findIcon("zoom-out",""), tr("Decrease Icons"), this, SLOT(decreaseIconSize()) ); + menu->addSeparator(); + menu->addAction( LXDG::findIcon("edit-delete",""), tr("Delete"), this, SLOT(deleteItems()) ); this->layout()->addWidget(list); this->setInitialSize(600,600); watcher = new QFileSystemWatcher(this); watcher->addPath(QDir::homePath()+"/Desktop"); connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateContents()) ); - connect(list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(runItem(QListWidgetItem*)) ); + connect(list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(runItems()) ); + connect(list, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&)) ); QTimer::singleShot(0,this, SLOT(updateContents()) ); } @@ -35,13 +51,83 @@ DesktopViewPlugin::~DesktopViewPlugin(){ } -void DesktopViewPlugin::runItem(QListWidgetItem *item){ - LSession::LaunchApplication("lumina-open \""+item->whatsThis()+"\""); +void DesktopViewPlugin::runItems(){ + QList<QListWidgetItem*> sel = list->selectedItems(); + for(int i=0; i<sel.length(); i++){ + LSession::LaunchApplication("lumina-open \""+sel[i]->whatsThis()+"\""); + } +} + +void DesktopViewPlugin::copyItems(){ + QList<QListWidgetItem*> sel = list->selectedItems(); + if(sel.isEmpty()){ return; } //nothing selected + QStringList items; + //Format the data string + for(int i=0; i<sel.length(); i++){ + items << "copy::::"+sel[i]->whatsThis(); + } + //Now save that data to the global clipboard + QMimeData *dat = new QMimeData; + dat->clear(); + dat->setData("x-special/lumina-copied-files", items.join("\n").toLocal8Bit()); + QApplication::clipboard()->clear(); + QApplication::clipboard()->setMimeData(dat); +} + +void DesktopViewPlugin::cutItems(){ + QList<QListWidgetItem*> sel = list->selectedItems(); + if(sel.isEmpty()){ return; } //nothing selected + QStringList items; + //Format the data string + for(int i=0; i<sel.length(); i++){ + items << "cut::::"+sel[i]->whatsThis(); + } + //Now save that data to the global clipboard + QMimeData *dat = new QMimeData; + dat->clear(); + dat->setData("x-special/lumina-copied-files", items.join("\n").toLocal8Bit()); + QApplication::clipboard()->clear(); + QApplication::clipboard()->setMimeData(dat); +} + +void DesktopViewPlugin::deleteItems(){ + QList<QListWidgetItem*> sel = list->selectedItems(); + for(int i=0; i<sel.length(); i++){ + QFile::remove(sel[i]->whatsThis()); + } +} + +void DesktopViewPlugin::showMenu(const QPoint &pos){ + //Make sure there is an item underneath the mouse first + if(list->itemAt(pos)!=0){ + menu->popup(pos); + }else{ + //Pass the context menu request on to the desktop (emit it from the plugin) + emit OpenDesktopMenu(); + } +} + +void DesktopViewPlugin::increaseIconSize(){ + int icosize = settings->value("IconSize",64).toInt(); + icosize+=16; //go in orders of 16 pixels + list->setIconSize(QSize(icosize,icosize)); + settings->setValue("IconSize",icosize); + updateContents(); +} + +void DesktopViewPlugin::decreaseIconSize(){ + int icosize = settings->value("IconSize",64).toInt(); + if(icosize < 20){ return; } //too small to decrease more + icosize-=16; //go in orders of 16 pixels + list->setIconSize(QSize(icosize,icosize)); + settings->setValue("IconSize",icosize); + updateContents(); } void DesktopViewPlugin::updateContents(){ list->clear(); - list->setGridSize(QSize(80,70+this->fontMetrics().height())); + int icosize = settings->value("IconSize",64).toInt(); + list->setGridSize(QSize(icosize+8,icosize+4+this->fontMetrics().height())); QDir dir(QDir::homePath()+"/Desktop"); QFileInfoList files = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name | QDir::Type | QDir::DirsFirst); for(int i=0; i<files.length(); i++){ diff --git a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.h b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.h index 6ec35276..61e1caf9 100644 --- a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.h +++ b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.h @@ -13,6 +13,8 @@ #include <QVBoxLayout> #include <QTimer> #include <QFileSystemWatcher> +#include <QMouseEvent> + #include "../LDPlugin.h" class DesktopViewPlugin : public LDPlugin{ @@ -24,9 +26,16 @@ public: private: QListWidget *list; QFileSystemWatcher *watcher; + QMenu *menu; private slots: - void runItem(QListWidgetItem*); + void runItems(); + void copyItems(); + void cutItems(); + void deleteItems(); + void showMenu(const QPoint&); + void increaseIconSize(); + void decreaseIconSize(); void updateContents(); @@ -37,6 +46,19 @@ public slots: void ThemeChange(){ QTimer::singleShot(0,this, SLOT(updateContents())); } + +/*protected: + void mousePressEvent(QMouseEvent *ev){ + if(ev->button()==Qt::RightButton){ + qDebug() << " - got mouse event"; + //Only show the context menu if an item is under the mouse (don't block the desktop menu) + if(list->itemAt( ev->globalPos()) !=0){ + ev->accept(); + showMenu(ev->globalPos()); + } + } + } + */ }; #endif |