1 //===========================================
2 // Lumina-DE source code
3 // Copyright (c) 2014-2015, Ken Moore
4 // Available under the 3-clause BSD license
5 // See the LICENSE file for full details
6 //===========================================
7 #include "LDPlugin.h"
8
9 #include "../LSession.h"
10 #include <LuminaXDG.h>
11
LDPlugin(QWidget * parent,QString id)12 LDPlugin::LDPlugin(QWidget *parent, QString id) : QFrame(parent){
13 PLUGID=id;
14 prefix = id.replace("/","_")+"/";
15 //qDebug() << "ID:" << PLUGID << prefix;
16 settings = LSession::handle()->DesktopPluginSettings();
17 //Setup the plugin system control menu
18 menu = new QMenu(this);
19 contextM = 0;
20 setupMenu();
21 //Setup the internal timer for when to start/stop drag events
22 dragTimer = new QTimer(this);
23 dragTimer->setSingleShot(true);
24 dragTimer->setInterval(500); //1/2 second to show the plugin menu
25 connect(dragTimer, SIGNAL(timeout()), this, SLOT(showPluginMenu()));
26 //Use plugin-specific values for stylesheet control (applauncher, desktopview, etc...)
27 this->setObjectName(id.section("---",0,0).section("::",0,0));
28 this->setContextMenuPolicy(Qt::CustomContextMenu);
29 this->setMouseTracking(false); //only catch mouse movement events if the mouse is clicked/held on the plugin
30 connect(QApplication::instance(), SIGNAL(LocaleChanged()), this, SLOT(LocaleChange()) );
31 connect(QApplication::instance(), SIGNAL(IconThemeChanged()), this, SLOT(ThemeChange()) );
32 connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPluginMenu()) );
33 }
34
setupMenu()35 void LDPlugin::setupMenu(){
36 menu->clear();
37 menu->setTitle(tr("Modify Item"));
38 menu->setIcon(LXDG::findIcon("preferences-desktop-icons","") );
39 //SPECIAL CONTEXT MENU OPTIONS FOR PARTICULAR PLUGIN TYPES
40 /*if(PLUGID.startsWith("applauncher::")){
41 menu->addAction( LXDG::findIcon("quickopen",""), tr("Launch Item"), this, SIGNAL(PluginActivated()) );
42 menu->addSeparator();
43 }*/
44 //General Options
45 menu->addAction( LXDG::findIcon("transform-move",""), tr("Start Moving Item"), this, SLOT(slotStartMove()) );
46 menu->addAction( LXDG::findIcon("transform-scale",""), tr("Start Resizing Item"), this, SLOT(slotStartResize()) );
47 menu->addSeparator();
48 menu->addAction( LXDG::findIcon("zoom-in",""), tr("Increase Item Sizes"), this, SIGNAL(IncreaseIconSize()) );
49 menu->addAction( LXDG::findIcon("zoom-out",""), tr("Decrease Item Sizes"), this, SIGNAL(DecreaseIconSize()) );
50 menu->addSeparator();
51 menu->addAction( LXDG::findIcon("edit-delete",""), tr("Remove Item"), this, SLOT(slotRemovePlugin()) );
52 }
53
showPluginMenu()54 void LDPlugin::showPluginMenu(){
55 emit CloseDesktopMenu();
56 //Double check which menu should be shown
57 if(this->contextMenu()!=0){
58 //Got a special context menu for this plugin - need to layer them together
59 if(!this->contextMenu()->actions().contains(menu->menuAction())){
60 this->contextMenu()->addSeparator();
61 this->contextMenu()->addMenu(menu);
62 }
63 this->contextMenu()->popup( QCursor::pos() );
64 }else{
65 menu->popup( QCursor::pos() );
66 }
67 }
68