aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/desktop-plugins
diff options
context:
space:
mode:
Diffstat (limited to 'lumina-desktop/desktop-plugins')
-rw-r--r--lumina-desktop/desktop-plugins/LDPlugin.cpp24
-rw-r--r--lumina-desktop/desktop-plugins/LDPlugin.h83
-rw-r--r--lumina-desktop/desktop-plugins/LDPluginContainer.h152
-rw-r--r--lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp58
-rw-r--r--lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h20
-rw-r--r--lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp3
6 files changed, 129 insertions, 211 deletions
diff --git a/lumina-desktop/desktop-plugins/LDPlugin.cpp b/lumina-desktop/desktop-plugins/LDPlugin.cpp
index 26ed7eff..c6d2e320 100644
--- a/lumina-desktop/desktop-plugins/LDPlugin.cpp
+++ b/lumina-desktop/desktop-plugins/LDPlugin.cpp
@@ -7,16 +7,36 @@
#include "LDPlugin.h"
#include "../LSession.h"
+#include <LuminaXDG.h>
LDPlugin::LDPlugin(QWidget *parent, QString id) : QFrame(parent){
PLUGID=id;
prefix = id.replace("/","_")+"/";
//qDebug() << "ID:" << PLUGID << prefix;
settings = LSession::handle()->DesktopPluginSettings();
+ //Setup the plugin system control menu
+ menu = new QMenu(this);
+ setupMenu();
+ //Setup the internal timer for when to start/stop drag events
+ dragTimer = new QTimer(this);
+ dragTimer->setSingleShot(true);
+ dragTimer->setInterval(500); //1/2 second to show the plugin menu
+ connect(dragTimer, SIGNAL(timeout()), this, SLOT(showPluginMenu()));
//Use plugin-specific values for stylesheet control (applauncher, desktopview, etc...)
this->setObjectName(id.section("---",0,0).section("::",0,0));
+ this->setContextMenuPolicy(Qt::CustomContextMenu);
+ this->setMouseTracking(false); //only catch mouse movement events if the mouse is clicked/held on the plugin
connect(QApplication::instance(), SIGNAL(LocaleChanged()), this, SLOT(LocaleChange()) );
connect(QApplication::instance(), SIGNAL(IconThemeChanged()), this, SLOT(ThemeChange()) );
+ connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPluginMenu()) );
+}
+
+void LDPlugin::setupMenu(){
+ menu->clear();
+ menu->addAction( LXDG::findIcon("transform-move",""), tr("Start Moving Item"), this, SLOT(slotStartMove()) );
+ menu->addAction( LXDG::findIcon("transform-scale",""), tr("Start Resizing Item"), this, SLOT(slotStartResize()) );
+ menu->addSeparator();
+ menu->addAction( LXDG::findIcon("edit-delete",""), tr("Remove Item"), this, SLOT(slotRemovePlugin()) );
}
void LDPlugin::setInitialSize(int width, int height){
@@ -33,10 +53,10 @@ void LDPlugin::setInitialSize(int width, int height){
this->resize( settings->value(prefix+"location/width").toInt(), settings->value(prefix+"location/height").toInt());
}
-void LDPlugin::adjustSize(int width, int height){
+/*void LDPlugin::adjustSize(int width, int height){
settings->setValue(prefix+"location/width",width);
settings->setValue(prefix+"location/height",height);
settings->sync();
this->resize(width,height);
emit PluginResized();
-} \ No newline at end of file
+}*/ \ No newline at end of file
diff --git a/lumina-desktop/desktop-plugins/LDPlugin.h b/lumina-desktop/desktop-plugins/LDPlugin.h
index a77674ee..6c34ab9c 100644
--- a/lumina-desktop/desktop-plugins/LDPlugin.h
+++ b/lumina-desktop/desktop-plugins/LDPlugin.h
@@ -23,6 +23,9 @@
#include <QSettings>
#include <QMoveEvent>
#include <QResizeEvent>
+#include <QMouseEvent>
+#include <QTimer>
+#include <QMenu>
class LDPlugin : public QFrame{
Q_OBJECT
@@ -30,6 +33,10 @@ class LDPlugin : public QFrame{
private:
QString PLUGID, prefix;
QSettings *settings;
+ QMenu *menu;
+ QTimer *dragTimer;
+
+ void setupMenu();
public:
LDPlugin(QWidget *parent = 0, QString id="unknown");
@@ -41,7 +48,16 @@ public:
}
void setInitialSize(int width, int height);
- void adjustSize(int width, int height);
+ //void adjustSize(int width, int height);
+
+ void savePluginGeometry(QRect geom){
+ settings->setValue(prefix+"geometry/desktopGridPoints", geom);
+ settings->sync();
+ }
+
+ QRect loadPluginGeometry(){
+ return settings->value(prefix+"geometry/desktopGridPoints", QRect()).toRect();
+ }
void saveSetting(QString var, QVariant val){
//qDebug() << "Saving Setting:" << prefix+var+QString(" = ")+val.toString();
@@ -67,40 +83,63 @@ public:
}
- /*virtual void scalePlugin(double xscale, double yscale){
- //This can be re-implemented in the subclassed plugin as necessary
- // Example: If there are icons in the plugin which should also be re-scaled
-
- int val = settings->value("location/width",0).toInt();
- if(val>0){ val = qRound(val*xscale); }
- settings->setValue("location/width",val);
-
- val = settings->value("location/height",0).toInt();
- if(val>0){ val = qRound(val*yscale); }
- settings->setValue("location/height",val);
-
- val = settings->value("location/x",0).toInt();
- if(val>0){ val = qRound(val*xscale); }
- settings->setValue("location/x",val);
-
- val = settings->value("location/y",0).toInt();
- if(val>0){ val = qRound(val*yscale); }
- settings->setValue("location/y",val);
- }*/
-
public slots:
virtual void LocaleChange(){
//This needs to be re-implemented in the subclassed plugin
//This is where all text is set/translated
+ setupMenu();
}
virtual void ThemeChange(){
//This needs to be re-implemented in the subclassed plugin
//This is where all the visuals are set if using Theme-dependant icons.
+ setupMenu();
+ }
+ void showPluginMenu(){
+ menu->popup( QCursor::pos() );
}
signals:
void OpenDesktopMenu();
void PluginResized();
+
+ //Signals for communication with the desktop layout system (not generally used by hand)
+ void StartMoving(QString); //ID of plugin
+ void StartResizing(QString); //ID of plugin
+ void RemovePlugin(QString); //ID of plugin
+
+private slots:
+ void slotStartMove(){
+ QCursor::setPos( this->mapToGlobal(QPoint(this->width()/2, this->height()/2)) );
+ emit StartMoving(PLUGID);
+ }
+
+ void slotStartResize(){
+ QCursor::setPos( this->mapToGlobal(QPoint(this->width()/2, this->height()/2)) );
+ emit StartResizing(PLUGID);
+ }
+
+ void slotRemovePlugin(){
+ removeSettings(true);
+ emit RemovePlugin(PLUGID);
+ }
+
+protected:
+ void mousePressEvent(QMouseEvent *ev){
+ if(!dragTimer->isActive() && ev->buttons().testFlag(Qt::LeftButton) ){ dragTimer->start(); }
+ QWidget::mousePressEvent(ev);
+ }
+ void mouseReleaseEvent(QMouseEvent *ev){
+ if(dragTimer->isActive()){ dragTimer->stop(); }
+ QWidget::mouseReleaseEvent(ev);
+ }
+ void mouseMoveEvent(QMouseEvent *ev){
+ if(ev->buttons().testFlag(Qt::LeftButton)){
+ if(dragTimer->isActive()){ dragTimer->stop(); }
+ slotStartMove();
+ }
+ QWidget::mouseMoveEvent(ev);
+ }
+
};
#endif
diff --git a/lumina-desktop/desktop-plugins/LDPluginContainer.h b/lumina-desktop/desktop-plugins/LDPluginContainer.h
deleted file mode 100644
index e7388a80..00000000
--- a/lumina-desktop/desktop-plugins/LDPluginContainer.h
+++ /dev/null
@@ -1,152 +0,0 @@
-//===========================================
-// Lumina-DE source code
-// Copyright (c) 2014, Ken Moore
-// Available under the 3-clause BSD license
-// See the LICENSE file for full details
-//===========================================
-// This class is the generic container for a desktop plugin that handles
-// saving/restoring all the movement and sizing
-//===========================================
-#ifndef _LUMINA_DESKTOP_DESKTOP_PLUGIN_CONTAINER_H
-#define _LUMINA_DESKTOP_DESKTOP_PLUGIN_CONTAINER_H
-
-#include <QObject>
-#include <QMdiSubWindow>
-#include <QApplication>
-#include <QSettings>
-#include <QMoveEvent>
-#include <QResizeEvent>
-#include <QCloseEvent>
-#include <QString>
-#include <QFile>
-#include <QIcon>
-#include <QTimer>
-
-#include "LDPlugin.h"
-
-class LDPluginContainer : public QMdiSubWindow{
- Q_OBJECT
-
-private:
- QTimer *syncTimer;
- bool locked, setup;
- LDPlugin *PLUG;
-
-private slots:
- void saveGeometry(){
- if(PLUG==0){ return; }
- //if(!locked && !setup){
- PLUG->saveSetting("location/x", this->pos().x());
- PLUG->saveSetting("location/y", this->pos().y());
- PLUG->saveSetting("location/width", this->width()-4);
- PLUG->saveSetting("location/height", this->height()-4);
- //}
- }
-
-public:
- LDPluginContainer(LDPlugin *plugin = 0, bool islocked = true) : QMdiSubWindow(){
- locked = islocked;
- setup=true;
- PLUG = plugin;
- syncTimer = new QTimer(this);
- syncTimer->setInterval(500); //save settings 1/2 second after it is moved
- syncTimer->setSingleShot(true); //no repeats
- connect(syncTimer, SIGNAL(timeout()), this, SLOT(saveGeometry()) );
- this->setWhatsThis(plugin->ID());
- this->setContentsMargins(0,0,0,0);
- if(!locked){
- //this->setStyleSheet("LDPluginContainer{ border-width: 1px;}");
- this->setWindowTitle( plugin->ID().replace("---"," - ") );
- //this->setWidget( new QWidget() );
- this->setWidget( plugin );
- //this->setWindowIcon(QIcon()); //remove the Qt icon
- }else{
- this->setStyleSheet("LDPluginContainer{ background: transparent; border: none;}");
- this->setWidget(plugin);
- }
- //qDebug() << "New Container:" << PLUG->size() << PLUG->sizeHint();
- connect(PLUG, SIGNAL(PluginResized()), this, SLOT(loadInitialPosition()) );
- }
-
- ~LDPluginContainer(){
- }
-
- void saveNewPosition(QPoint pt){
- //generally only used while a plugin is locked and does not have an initial position
- // This works around an issue with QMdiArea moving the new container out of alignment
- if(PLUG==0){ return; }
- PLUG->saveSetting("location/x",pt.x());
- PLUG->saveSetting("location/y", pt.y());
- }
-
- bool hasFixedPosition(){
- return (PLUG->readSetting("location/x",-12345).toInt() != -12345);
- }
-
-public slots:
- void loadInitialSize(){
- if(PLUG==0){ return; }
- QSize sz(PLUG->readSetting("location/width",100).toInt(), PLUG->readSetting("location/height",100).toInt());
- this->resize(sz);
- }
-
- void loadInitialPosition(){
- QRect set(PLUG->readSetting("location/x",-12345).toInt(), PLUG->readSetting("location/y",-12345).toInt(), PLUG->readSetting("location/width",PLUG->size().width()).toInt() +4, PLUG->readSetting("location/height",PLUG->size().height()).toInt()+4);
- //qDebug() << "Initial Plugin Location:" << set.x() << set.y() << set.width() << set.height();
- if(set.height() < 10){ set.setHeight(10); } //to prevent foot-shooting
- if(set.width() < 10){ set.setWidth(10); } //to prevent foot-shooting
- if(set.x()!=-12345 && set.y()!=-12345){
- //this->move(set.x(), set.y());
- this->setGeometry(set);
- }else{
- qDebug() << " - Found Size:" << set;
- this->resize(set.width(), set.height());
- qDebug() << " - Assigning location:" << this->pos();
- saveNewPosition(this->pos());
- }
- this->show();
- QApplication::processEvents();
- setup=false; //done with setup
- }
-
-
-signals:
- void PluginRemoved(QString);
-
-protected:
- void moveEvent(QMoveEvent *event){
- //qDebug() << "Move Event: " << PLUG->ID() << setup;
- //Save this location to the settings
- if( !setup ){
- if(syncTimer->isActive()){ syncTimer->stop(); }
- syncTimer->start();
- //qDebug() << "DP Move:" << event->pos().x() << event->pos().y();
- }
- QMdiSubWindow::moveEvent(event); //be sure to pass this event along to the container
- }
-
- void resizeEvent(QResizeEvent *event){
- //Save this size info to the settings
- if(!setup){
- //qDebug() << "DP Resize:" << event->size().width() << event->size().height();
- if(syncTimer->isActive()){ syncTimer->stop(); }
- syncTimer->start();
- }
- QMdiSubWindow::resizeEvent(event); //be sure to pass this event along to the container
- }
-
- void closeEvent(QCloseEvent *event){
- //qDebug() << "Desktop Plugin Close Event:" << this->whatsThis();
- if( !this->whatsThis().isEmpty() && !locked){
- //Plugin removed by the user - delete the settings file
- locked = true; //ensure that the save settings routines don't do anything during the close
- emit PluginRemoved( this->whatsThis() );
- }
- if(syncTimer->isActive()){ syncTimer->stop(); } //prevent save routine from running in a moment
- //settings = 0; //ensure we don't touch the settings file after a close event
- QMdiSubWindow::closeEvent(event); //continue closing this window
- }
-
-};
-
-#endif
diff --git a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp
index ae454511..3acb83fb 100644
--- a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp
+++ b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp
@@ -9,42 +9,46 @@ AppLauncherPlugin::AppLauncherPlugin(QWidget* parent, QString ID) : LDPlugin(par
button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
button->setAutoRaise(true);
button->setText("...\n..."); //Need to set something here so that initial sizing works properly
-
+ button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
lay->addWidget(button, 0, Qt::AlignCenter);
connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()) );
- menu = new QMenu(this);
- int icosize = this->readSetting("iconsize",-1).toInt();
+ //menu = new QMenu(this);
+ /*int icosize = this->readSetting("iconsize",-1).toInt();
if(icosize <1){
icosize = LSession::handle()->sessionSettings()->value("DefaultIconSize",64).toInt();
this->saveSetting("iconsize",icosize);
- }
- button->setIconSize(QSize(icosize,icosize));
- this->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(openContextMenu()) );
+ }*/
+ //int icosize
+ //button->setIconSize(QSize(icosize,icosize));
+ button->setContextMenuPolicy(Qt::NoContextMenu);
+ //connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(openContextMenu()) );
watcher = new QFileSystemWatcher(this);
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT( loadButton()) );
//Calculate the initial size of the button
//qDebug() << "Button Size:" << button->size();
//qDebug() << "Calculated:" << icosize+4 << icosize+8+qRound(2.15*button->fontMetrics().height());
//qDebug() << "Preferred Size:" << button->sizeHint();
- QSize sz(qRound(1.1*icosize), icosize+qRound(2.7*button->fontMetrics().height()) );
- button->setFixedSize(sz); //make sure to adjust the button on first show.
- this->setInitialSize(this->sizeHint().width()+2, this->sizeHint().height()+2); //give the container a bit of a buffer
+ //QSize sz(qRound(1.1*icosize), icosize+qRound(2.7*button->fontMetrics().height()) );
+ //button->setFixedSize(sz); //make sure to adjust the button on first show.
+ this->setInitialSize(120, 100); //give the container a bit of a buffer
QTimer::singleShot(100,this, SLOT(loadButton()) );
}
void AppLauncherPlugin::Cleanup(){
//This is run only when the plugin was forcibly closed/removed
- if(QFile::exists(button->whatsThis()) && button->whatsThis().startsWith(QDir::homePath()+"/Desktop") ){
+ /*if(QFile::exists(button->whatsThis()) && button->whatsThis().startsWith(QDir::homePath()+"/Desktop") ){
deleteFile();
- }
+ }*/
}
-void AppLauncherPlugin::loadButton(bool onchange){
+void AppLauncherPlugin::loadButton(){
QString def = this->ID().section("::",1,50).section("---",0,0).simplified();
QString path = this->readSetting("applicationpath",def).toString(); //use the default if necessary
//qDebug() << "Default Application Launcher:" << def << path;
bool ok = QFile::exists(path);
+ int icosize = this->width()/1.8; //This is the same calculation as in the LDesktopPluginSpace
+ button->setFixedSize( this->width()-4, this->height()-4);
+ button->setIconSize( QSize(icosize,icosize) );
QString txt;
if(path.endsWith(".desktop") && ok){
XDGDesktop file = LXDG::loadDesktopFile(path, ok);
@@ -82,12 +86,12 @@ void AppLauncherPlugin::loadButton(bool onchange){
}
//Now adjust the visible text as necessary based on font/grid sizing
button->setToolTip(txt);
- int icosize = this->readSetting("iconsize",64).toInt();
- int bwid = qRound(1.1*icosize);
- this->setFixedSize(bwid, icosize+qRound(2.5*button->fontMetrics().height()) ); //make sure to adjust the button on first show.
- if(onchange){ this->adjustSize( bwid+4, icosize+8+qRound(2.5*button->fontMetrics().height())); }
+ //int icosize = this->readSetting("iconsize",64).toInt();
+ //int bwid = qRound(1.1*icosize);
+ //this->setFixedSize(bwid, icosize+qRound(2.5*button->fontMetrics().height()) ); //make sure to adjust the button on first show.
+ //if(onchange){ this->adjustSize( bwid+4, icosize+8+qRound(2.5*button->fontMetrics().height())); }
//qDebug() << "Initial Button Text:" << txt << icosize;
- if(button->fontMetrics().width(txt) > (bwid-2) ){
+ if(button->fontMetrics().width(txt) > (button->width()-2) ){
//int dash = this->fontMetrics().width("-");
//Text too long, try to show it on two lines
txt = txt.section(" ",0,2).replace(" ","\n"); //First take care of any natural breaks
@@ -96,11 +100,11 @@ void AppLauncherPlugin::loadButton(bool onchange){
QStringList txtL = txt.split("\n");
for(int i=0; i<txtL.length(); i++){
if(i>1){ txtL.removeAt(i); i--; } //Only take the first two lines
- else{ txtL[i] = button->fontMetrics().elidedText(txtL[i], Qt::ElideRight, bwid-2); }
+ else{ txtL[i] = button->fontMetrics().elidedText(txtL[i], Qt::ElideRight, (button->width()-2) ); }
}
txt = txtL.join("\n");
}else{
- txt = this->fontMetrics().elidedText(txt,Qt::ElideRight, 2*bwid -4);
+ txt = this->fontMetrics().elidedText(txt,Qt::ElideRight, 2*button->width() -4);
//Now split the line in half for the two lines
txt.insert( (txt.count()/2), "\n");
}
@@ -109,12 +113,12 @@ void AppLauncherPlugin::loadButton(bool onchange){
//qDebug() << " - Setting Button Text:" << txt;
button->setText(txt);
//Now setup the menu again
- menu->clear();
- menu->addAction(LXDG::findIcon("zoom-in",""), tr("Increase Size"), this, SLOT(increaseIconSize()));
+ //menu->clear();
+ /*menu->addAction(LXDG::findIcon("zoom-in",""), tr("Increase Size"), this, SLOT(increaseIconSize()));
menu->addAction(LXDG::findIcon("zoom-out",""), tr("Decrease Size"), this, SLOT(decreaseIconSize()));
if( !button->whatsThis().isEmpty() && button->whatsThis().startsWith(QDir::homePath()+"/Desktop") ){
menu->addAction(LXDG::findIcon("list-remove",""), tr("Delete File"), this, SLOT(deleteFile()) );
- }
+ }*/
QTimer::singleShot(100, this, SLOT(update()) ); //Make sure to re-draw the image in a moment
}
@@ -137,15 +141,15 @@ void AppLauncherPlugin::buttonClicked(){
}
-void AppLauncherPlugin::openContextMenu(){
+/*void AppLauncherPlugin::openContextMenu(){
if(button->underMouse()){
menu->popup(QCursor::pos());
}else{
emit OpenDesktopMenu();
}
-}
+}*/
-void AppLauncherPlugin::increaseIconSize(){
+/*void AppLauncherPlugin::increaseIconSize(){
int icosize = this->readSetting("iconsize",64).toInt();
icosize += 16;
button->setIconSize(QSize(icosize,icosize));
@@ -169,4 +173,4 @@ void AppLauncherPlugin::deleteFile(){
}else{
QFile::remove(button->whatsThis());
}
-} \ No newline at end of file
+}*/ \ No newline at end of file
diff --git a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h
index 796d8f04..d6e75fec 100644
--- a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h
+++ b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.h
@@ -34,20 +34,26 @@ public:
private:
QToolButton *button;
QFileSystemWatcher *watcher;
- QMenu *menu;
+ //QMenu *menu;
private slots:
- void loadButton(bool onchange = false);
+ void loadButton();
void buttonClicked();
- void openContextMenu();
+ //void openContextMenu();
- void increaseIconSize();
- void decreaseIconSize();
- void deleteFile();
+ //void increaseIconSize();
+ //void decreaseIconSize();
+ //void deleteFile();
public slots:
void LocaleChange(){
- loadButton(true); //force reload
+ loadButton(); //force reload
+ }
+
+protected:
+ void resizeEvent(QResizeEvent *ev){
+ LDPlugin::resizeEvent(ev);
+ QTimer::singleShot(10, this, SLOT(loadButton()) );
}
};
#endif
diff --git a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp
index b1300ec8..0b48a049 100644
--- a/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp
+++ b/lumina-desktop/desktop-plugins/desktopview/DesktopViewPlugin.cpp
@@ -107,7 +107,8 @@ void DesktopViewPlugin::showMenu(const QPoint &pos){
menu->popup(this->mapToGlobal(pos));
}else{
//Pass the context menu request on to the desktop (emit it from the plugin)
- emit OpenDesktopMenu();
+ this->showPluginMenu();
+ //emit OpenDesktopMenu();
}
}
bgstack15