From 1d06950a02d5d8312d0f179e11dee8d7a37adb6d Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 15 May 2018 08:55:31 -0400 Subject: Get the Clock plugin cleaned up a bit so it better supports multi-line panels. --- .../src-desktop/src-widgets/plugins/ClockPlugin.h | 48 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'src-qt5/core/lumina-desktop-unified/src-desktop/src-widgets') 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 be5d017b..7e7b06c7 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 @@ -12,22 +12,64 @@ class ClockPlugin : public PluginButton{ Q_OBJECT + +private: + int textRows; + private slots: void updateTime(){ //qDebug() << "Clock: Update Time"; - this->button->setText(RootDesktopObject::instance()->currentTime() ); + QString text = RootDesktopObject::instance()->currentTime(); + //Adjust the text to fix the widget as needed + //qDebug() << "Clock: Update Time:" << textRows << text << text.split(" "); + if(textRows>1){ + QStringList textL = text.split(" "); //natural breaks + 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; + } + }else{ + //Need to get a lot more complicated - need to break up sections based on widget width + // TO-DO + break; + } + } //end of loop + text = textL.join("\n"); + } + //qDebug() << "Got Text:" << text; + this->button->setText(text); } 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; QTimer::singleShot(0, this, SLOT(updateTime()) ); } ~ClockPlugin(){ } +protected: + void resizeEvent(QResizeEvent *ev){ + Plugin::resizeEvent(ev); + //Re-calculate the text sizing for display + int tmp = button->height() / button->fontMetrics().height(); + //qDebug() << "Got height/font ratio:" << tmp; + if(tmp!=textRows){ + textRows = tmp; + if(textRows<1){ textRows = 1; } + QTimer::singleShot(0, this, SLOT(updateTime()) ); + } + } }; #endif -- cgit