diff options
author | Ken Moore <ken@ixsystems.com> | 2018-05-16 03:54:25 -0400 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2018-05-16 03:54:25 -0400 |
commit | 0ac1591f4727a5770dd25ae1decc9a141993862c (patch) | |
tree | a896d72d23ca05fcfe1b7829b3cc9e5ca729cda7 /src-qt5/core/lumina-desktop-unified | |
parent | Couple more gitignore changes which I missed in the last commit. (diff) | |
download | lumina-0ac1591f4727a5770dd25ae1decc9a141993862c.tar.gz lumina-0ac1591f4727a5770dd25ae1decc9a141993862c.tar.bz2 lumina-0ac1591f4727a5770dd25ae1decc9a141993862c.zip |
Get the Clock plugin all finished up.
Now the text should format properly, and we have a single-instanced calendar menu popup for all clock plugins now.
Diffstat (limited to 'src-qt5/core/lumina-desktop-unified')
5 files changed, 75 insertions, 13 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/LSession.cpp b/src-qt5/core/lumina-desktop-unified/LSession.cpp index 5f2dc5ab..a17ed060 100644 --- a/src-qt5/core/lumina-desktop-unified/LSession.cpp +++ b/src-qt5/core/lumina-desktop-unified/LSession.cpp @@ -88,7 +88,7 @@ LSession::~LSession(){ void LSession::setupSession(){ BootSplash splash; splash.showScreen("init"); - qDebug() << "Initializing Session:" << QDateTime::currentDateTime().toString( Qt::SystemLocaleShortDate);; + qDebug() << "Setting up session:" << QDateTime::currentDateTime().toString( Qt::SystemLocaleShortDate);; if(QFile::exists("/tmp/.luminastopping")){ QFile::remove("/tmp/.luminastopping"); } QTime* timer = 0; if(DEBUG){ timer = new QTime(); timer->start(); qDebug() << " - Init srand:" << timer->elapsed();} 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 db8c4e54..a8dc8869 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 @@ -73,6 +73,7 @@ public: button = new QToolButton(this); button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); button->setAutoRaise(true); + button->setPopupMode(QToolButton::InstantPopup); this->layout()->addWidget(button); } diff --git a/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/CalendarMenu.h b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/CalendarMenu.h new file mode 100644 index 00000000..6bf3fefe --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets/plugins/CalendarMenu.h @@ -0,0 +1,40 @@ +//=========================================== +// Lumina-desktop source code +// Copyright (c) 2018, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// Simple menu popup with a calendar in it +//=========================================== +#ifndef _LUMINA_DESKTOP_WIDGET_MENU_CALENDAR_H +#define _LUMINA_DESKTOP_WIDGET_MENU_CALENDAR_H + +#include <QMenu> +#include <QWidgetAction> +#include <QCalendarWidget> +#include <QDate> + +class CalendarMenu : public QMenu { + Q_OBJECT +private: + QCalendarWidget *cal; + QWidgetAction *WA; +public: + CalendarMenu(){ + cal = new QCalendarWidget(); + WA = new QWidgetAction(this); + WA->setDefaultWidget(cal); + this->addAction(WA); + connect(this, SIGNAL(aboutToShow()), this, SLOT(resetDate()) ); + } + ~CalendarMenu(){ + cal->deleteLater(); + } + +private slots: + void resetDate(){ + cal->setSelectedDate(QDate::currentDate()); + } + +}; +#endif 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 7e7b06c7..7bf48cc2 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 @@ -9,6 +9,7 @@ #include <Plugin.h> #include <RootDesktopObject.h> +#include <CalendarMenu.h> class ClockPlugin : public PluginButton{ Q_OBJECT @@ -24,20 +25,32 @@ private slots: //qDebug() << "Clock: Update Time:" << textRows << text << text.split(" "); if(textRows>1){ QStringList textL = text.split(" "); //natural breaks + int max = button->width() + (isVertical ? -1 : 200); //button->height() for vertical panels once text rotation is worked out while(textL.length()!=textRows){ if(textL.length() > textRows){ //Need to get a bit more complicated - join the shorter sections together - //Look for an am/pm section and combine that with the previous one - int index = textL.lastIndexOf(QRegExp("(AM|am|PM|pm)")); - //qDebug() << "Got AM/PM index:" << index; - if(index>0){ textL[index-1] = textL[index-1]+" "+textL[index]; textL.removeAt(index); } - else{ - //TO-DO - break; + //Find the smallest section and merge it into the previous one + //Note: This is horribly inefficient, but due to the inherently short length of textL it is acceptable + int min = -1; int index = -1; + for(int i=1; i<textL.length(); i++){ + int combined = button->fontMetrics().width(textL[i-1]+" "+textL[i]); + int tmp = button->fontMetrics().width(textL[i]); + if( max>combined && (min<0 || tmp<min)){ min = tmp; index = i; } } + if(index>0){ textL[index-1] = textL[index-1]+" "+textL[index]; textL.removeAt(index); } + else{ break; } }else{ - //Need to get a lot more complicated - need to break up sections based on widget width - // TO-DO + //Need to get a lot more complicated - need to break up sections mid-word based on widget width + for(int i=0; i<textL.length(); i++){ + int tmp = button->fontMetrics().width(textL[i]); + if(tmp>max){ + //qDebug() << "CLOCK:" << i << tmp << max << textL[i]; + QString tmps = button->fontMetrics().elidedText(textL[i], Qt::ElideRight, max).section("...",0,-2); //remove the three dots at end + QString rem = textL[i].remove(tmps); + textL[i] = tmps; textL.insert(i+1, rem); + } + } + //Now go ahead and break the main loop - text all fits width-wise now break; } } //end of loop @@ -50,10 +63,16 @@ private slots: public: ClockPlugin(QWidget *parent, QString id, bool panelplug) : PluginButton(parent, id, panelplug){ connect(RootDesktopObject::instance(), SIGNAL(currentTimeChanged()), this, SLOT(updateTime()) ); - /*QFont tmp = button->font(); + QFont tmp = button->font(); tmp.setBold(true); - button->setFont( tmp );*/ + button->setFont( tmp ); textRows = 1; + //Setup the popup menu + static QMenu *calMenu = 0; + if(calMenu == 0){ + calMenu = new CalendarMenu(); + } + button->setMenu(calMenu); QTimer::singleShot(0, this, SLOT(updateTime()) ); } ~ClockPlugin(){ } @@ -63,11 +82,12 @@ protected: Plugin::resizeEvent(ev); //Re-calculate the text sizing for display int tmp = button->height() / button->fontMetrics().height(); + if(isVertical && isPanelPlugin){ tmp+=5; } //non-rotated text - need more columns //qDebug() << "Got height/font ratio:" << tmp; if(tmp!=textRows){ textRows = tmp; if(textRows<1){ textRows = 1; } - QTimer::singleShot(0, this, SLOT(updateTime()) ); + if(button->isVisible() && !button->text().isEmpty()){ QTimer::singleShot(0, this, SLOT(updateTime()) ); } } } }; 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 d7082141..8931d413 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 @@ -4,4 +4,5 @@ INCLUDEPATH *= $${PWD} #SOURCES *= HEADERS *= $${PWD}/ClockPlugin.h \ + $${PWD}/CalendarMenu.h \ $${PWD}/SpacerPlugin.h |