From 09c67100e98d8a73f3d480217250b220d731ebd0 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 15 May 2018 07:46:19 -0400 Subject: Get the plugin system working with the panels. Also add a spacer plugin. --- .../src-desktop/RootWindow-Widgets.cpp | 4 +++- .../src-desktop/src-cpp/PanelObject.cpp | 10 ++++++++- .../src-desktop/src-cpp/RootDesktopObject.cpp | 5 ++++- .../src-desktop/src-widgets/Panel.cpp | 2 ++ .../src-desktop/src-widgets/Plugin.cpp | 13 ++++++++---- .../src-desktop/src-widgets/Plugin.h | 13 ++++++++++++ .../src-desktop/src-widgets/plugins/ClockPlugin.h | 20 ++++++++++++------ .../src-desktop/src-widgets/plugins/SpacerPlugin.h | 24 ++++++++++++++++++++++ .../src-desktop/src-widgets/plugins/plugins.pri | 3 ++- 9 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/SpacerPlugin.h (limited to 'src-qt5/core/lumina-desktop-unified/src-desktop') diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow-Widgets.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow-Widgets.cpp index 6a4c4cb0..44007b08 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow-Widgets.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/RootWindow-Widgets.cpp @@ -13,8 +13,10 @@ RootDesktop *root_view; RootWindow::RootWindow() : QObject(){ root_win = QWindow::fromWinId( QX11Info::appRootWindow() ); - root_view = new RootDesktop(root_win); //make it a child of the root window + //qDebug() << "Creating RootDesktop Object"; root_obj = RootDesktopObject::instance(); + //qDebug() << "Creating RootDesktop View"; + root_view = new RootDesktop(root_win); //make it a child of the root window syncRootSize(); connect(root_win, SIGNAL(widthChanged(int)), this, SLOT(syncRootSize()) ); connect(root_win, SIGNAL(heightChanged(int)),this, SLOT(syncRootSize()) ); diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp index 94079bf7..035dd29c 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-cpp/PanelObject.cpp @@ -10,6 +10,10 @@ #include #include +#ifdef USE_WIDGETS +#include +#endif + PanelObject::PanelObject(QString id, QObject *parent) : QObject(parent){ panel_id = id; } @@ -56,8 +60,12 @@ void PanelObject::setGeometry( QRect newgeom ){ void PanelObject::setPlugins( QStringList plist){ //Iterate through the list and find the URL's for the files QStringList dirs; dirs << ":/qml/plugins/"; //add local directories here + static QStringList built_in; +#ifdef USE_WIDGETS + if(built_in.isEmpty()){ built_in = Plugin::built_in_plugins(); } +#endif for(int i=0; iname(); } @@ -53,6 +54,7 @@ QStringList RootDesktopObject::screens(){ } ScreenObject* RootDesktopObject::screen(QString id){ + if(s_objects.length()<1){ updateScreens(); } //qDebug() << "Got Screen Request:" << id; for(int i=0; iname()==id){ return s_objects[i]; } @@ -315,6 +317,7 @@ void RootDesktopObject::updateCurrentTime(){ currentDateTimeStruct = DT; currentTimeString = tmp; emit currentTimeChanged(); + //qDebug() << "Current Time Changed:" << currentTimeString; } } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Panel.cpp b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Panel.cpp index 5b2a8a08..52642235 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Panel.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Panel.cpp @@ -11,6 +11,7 @@ Panel::Panel(PanelObject *pobj) : QWidget(0, Qt::Window | Qt::FramelessWindowHin this->setObjectName("LuminaPanelBackgroundWidget"); obj = pobj; layout = new QBoxLayout(QBoxLayout::LeftToRight, this); + layout->setContentsMargins(0,0,0,0); this->setBackgroundRole(QPalette::AlternateBase); connect(obj, SIGNAL(backgroundChanged()), this, SLOT(updateBackground()) ); connect(obj, SIGNAL(geomChanged()), this, SLOT(updateGeom()) ); @@ -75,6 +76,7 @@ void Panel::updatePlugins(){ layout->removeWidget(plug); //remove from the layout for a moment } layout->insertWidget(i, plug); + plug->setupSizing(); } //Now remove any plugins which were deleted from config for(int i=0; i +#include QStringList Plugin::built_in_plugins(){ QStringList list; - list << "clock"; + list << "clock" << "spacer"; return list; } Plugin* Plugin::createPlugin(QWidget *parent, QString id, bool panelplug){ Plugin *plug = 0; - //QString id_extra; - //if(id.contains("--")){ id_extra = id.section("--",1,-1); id = id.section("--",0,0); } - if(id=="clock"){ + QString id_extra, id_primary; + if(id.contains("--")){ id_extra = id.section("--",1,-1); id_primary = id.section("--",0,0); } + else{ id_primary = id; } //no extra info on this one + id_primary = id_primary.toLower(); + if(id_primary=="clock"){ plug = new ClockPlugin(parent, id, panelplug); + }else if(id_primary=="spacer"){ + plug = new SpacerPlugin(parent, id, panelplug); } return plug; diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Plugin.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Plugin.h index 1bc0476f..db8c4e54 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Plugin.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/Plugin.h @@ -36,16 +36,27 @@ public: boxLayout = new QBoxLayout(QBoxLayout::LeftToRight); this->setLayout( boxLayout ); boxLayout->setContentsMargins(0,0,0,0); + this->setContentsMargins(0,0,0,0); updateLayoutOrientation(); connect(this, SIGNAL(orientationChanged()), this, SLOT(updateLayoutOrientation()) ); } void setVertical(bool set){ if(set!=isVertical){ isVertical = set; emit orientationChanged(); } + setupSizing(); } QString id(){ return _id; } + virtual void setupSizing(){ + if(isPanelPlugin){ + if(!isVertical){ this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); } + else{ this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); } + }else{ + this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + } + } + private slots: void updateLayoutOrientation(){ boxLayout->setDirection( this->isVertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight ); @@ -60,6 +71,8 @@ public: QToolButton *button; PluginButton(QWidget *parent, QString id, bool panelplug=false) : Plugin(parent, id, panelplug) { button = new QToolButton(this); + button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + button->setAutoRaise(true); this->layout()->addWidget(button); } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/ClockPlugin.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/ClockPlugin.h index b5510ad7..be5d017b 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/ClockPlugin.h +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/ClockPlugin.h @@ -4,22 +4,30 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== +#ifndef _LUMINA_DESKTOP_PLUGIN_CLOCK_H +#define _LUMINA_DESKTOP_PLUGIN_CLOCK_H + #include #include class ClockPlugin : public PluginButton{ Q_OBJECT -private: +private slots: + void updateTime(){ + //qDebug() << "Clock: Update Time"; + this->button->setText(RootDesktopObject::instance()->currentTime() ); + } public: ClockPlugin(QWidget *parent, QString id, bool panelplug) : PluginButton(parent, id, panelplug){ connect(RootDesktopObject::instance(), SIGNAL(currentTimeChanged()), this, SLOT(updateTime()) ); + QFont tmp = button->font(); + tmp.setBold(true); + button->setFont( tmp ); + QTimer::singleShot(0, this, SLOT(updateTime()) ); } ~ClockPlugin(){ } -private slots: - void updateTime(){ - this->button->setText(RootDesktopObject::instance()->currentTime() ); - } - }; + +#endif diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/SpacerPlugin.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/SpacerPlugin.h new file mode 100644 index 00000000..0f8d8809 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/SpacerPlugin.h @@ -0,0 +1,24 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2018, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_DESKTOP_PLUGIN_SPACER_H +#define _LUMINA_DESKTOP_PLUGIN_SPACER_H +#include + +class SpacerPlugin : public Plugin{ + Q_OBJECT + +public: + SpacerPlugin(QWidget *parent, QString id, bool panelplug) : Plugin(parent, id, panelplug){} + ~SpacerPlugin(){ } + + //Replace the virtual sizing function + void setupSizing(){ + this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + } +}; + +#endif diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/plugins.pri b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/plugins.pri index 6031a0d4..d7082141 100644 --- a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/plugins.pri +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/plugins.pri @@ -3,4 +3,5 @@ INCLUDEPATH *= $${PWD} #SOURCES *= -HEADERS *= $${PWD}/ClockPlugin.h +HEADERS *= $${PWD}/ClockPlugin.h \ + $${PWD}/SpacerPlugin.h -- cgit