From 7cd80e14a7233290942ecee50ee4d0a3862adaee Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 30 Aug 2014 17:40:25 +0400 Subject: [PATCH] create initialization skeleton --- sources/awesome-widget/awesome-widget.cpp | 36 +++++++++++++-- sources/awesome-widget/awesome-widget.h | 15 ++++-- sources/awesome-widget/customlabel.cpp | 56 +++++++++++++++++++++++ sources/awesome-widget/customlabel.h | 44 ++++++++++++++++++ sources/awesome-widget/reinit.cpp | 34 ++++++++++++++ 5 files changed, 177 insertions(+), 8 deletions(-) create mode 100644 sources/awesome-widget/customlabel.cpp create mode 100644 sources/awesome-widget/customlabel.h diff --git a/sources/awesome-widget/awesome-widget.cpp b/sources/awesome-widget/awesome-widget.cpp index cee242e..7113cd7 100644 --- a/sources/awesome-widget/awesome-widget.cpp +++ b/sources/awesome-widget/awesome-widget.cpp @@ -18,8 +18,11 @@ #include "awesome-widget.h" #include +#include #include +#include +#include "customlabel.h" #include @@ -46,6 +49,25 @@ AwesomeWidget::~AwesomeWidget() } +QString AwesomeWidget::getNetworkDevice() +{ + if (debug) qDebug() << PDEBUG; + + QString device = QString("lo"); + if (configuration[QString("useCustomNetdev")].toInt() == 2) + device = configuration[QString("customNetdev")]; + else { + QList rawInterfaceList = QNetworkInterface::allInterfaces(); + for (int i=0; isetContentsMargins(1, 1, 1, 1); - setLayout(layout); + mainLayout = new QGraphicsLinearLayout(); + mainLayout->setContentsMargins(1, 1, 1, 1); + setLayout(mainLayout); + + textLabel = new CustomLabel(this, debug); // read variables configChanged(); + timer = new QTimer(this); + timer->setSingleShot(false); + timer->setInterval(configuration[QString("interval")].toInt()); + connect(timer, SIGNAL(timeout()), this, SLOT(updateText())); + connect(timer, SIGNAL(timeout()), this, SLOT(updateTooltip())); + timer->start(); } diff --git a/sources/awesome-widget/awesome-widget.h b/sources/awesome-widget/awesome-widget.h index b2a02ce..df0064c 100644 --- a/sources/awesome-widget/awesome-widget.h +++ b/sources/awesome-widget/awesome-widget.h @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -30,6 +29,7 @@ #include +class CustomLabel; class QGraphicsLinearLayout; class AwesomeWidget : public Plasma::Applet @@ -54,6 +54,9 @@ public slots: // configuration interface void configAccepted(); void configChanged(); + // update events + void updateText(); + void updateTooltip(); private slots: void reinit(); @@ -64,9 +67,12 @@ protected: private: // functions - void updateText(); + QTimer *timer; // ui - QGraphicsLinearLayout *layout; + QGraphicsLinearLayout *mainLayout; + CustomLabel *textLabel; + // values + QMap values; // debug bool debug; // data engine @@ -81,8 +87,7 @@ private: Ui::TooltipWindow uiTooltipConfig; // configuration QMap configuration; - QStringList diskDevices; - QStringList formatLine; + QStringList diskDevices, keys, formatLine, foundKeys; }; diff --git a/sources/awesome-widget/customlabel.cpp b/sources/awesome-widget/customlabel.cpp new file mode 100644 index 0000000..41fad68 --- /dev/null +++ b/sources/awesome-widget/customlabel.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + * This file is part of pytextmonitor * + * * + * pytextmonitor is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * pytextmonitor is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with pytextmonitor. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "customlabel.h" + +#include + +#include "awesome-widget.h" +#include + + +CustomLabel::CustomLabel(AwesomeWidget *wid, const bool debugCmd) + : Plasma::Label(wid), + debug(debugCmd) +{ +} + + +CustomLabel::~CustomLabel() +{ + if (debug) qDebug() << PDEBUG; +} + + +void CustomLabel::setPopupEnabled(const bool state) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "State" << state; + + enablePopup = state; +} + + +void CustomLabel::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Get signal" << event->button(); + + if ((enablePopup) && (event->button() == Qt::LeftButton)) + {} + emit(Plasma::Label::mousePressEvent(event)); +} diff --git a/sources/awesome-widget/customlabel.h b/sources/awesome-widget/customlabel.h new file mode 100644 index 0000000..abd5e74 --- /dev/null +++ b/sources/awesome-widget/customlabel.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * This file is part of pytextmonitor * + * * + * pytextmonitor is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * pytextmonitor is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with pytextmonitor. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef CUSTOMLABEL_H +#define CUSTOMLABEL_H + +#include + + +class AwesomeWidget; + +class CustomLabel : public Plasma::Label +{ + Q_OBJECT + +public: + CustomLabel(AwesomeWidget *wid, const bool debugCmd); + ~CustomLabel(); + void setPopupEnabled(const bool state); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + +private: + bool debug; + bool enablePopup; +}; + + +#endif /* CUSTOMLABEL_H */ diff --git a/sources/awesome-widget/reinit.cpp b/sources/awesome-widget/reinit.cpp index df4049a..44b241e 100644 --- a/sources/awesome-widget/reinit.cpp +++ b/sources/awesome-widget/reinit.cpp @@ -17,13 +17,41 @@ #include "awesome-widget.h" +#include +//#include +#include "customlabel.h" #include void AwesomeWidget::reinit() { if (debug) qDebug() << PDEBUG; + + mainLayout = new QGraphicsLinearLayout(); + mainLayout->setContentsMargins(1, 1, 1, 1); + setLayout(mainLayout); + + if (configuration[QString("background")].toInt() == 0) + setBackgroundHints(NoBackground); + else + setBackgroundHints(DefaultBackground); + if (configuration[QString("layout")].toInt() == 0) + mainLayout->setOrientation(Qt::Horizontal); + else + mainLayout->setOrientation(Qt::Vertical); + if (configuration[QString("leftStretch")].toInt() == 2) + mainLayout->addStretch(1); + if (configuration[QString("popup")].toInt() == 0) + textLabel->setPopupEnabled(true); + mainLayout->addItem(textLabel); + if (configuration[QString("rightStretch")].toInt() == 2) + mainLayout->addStretch(1); + + values[QString("netdev")] = getNetworkDevice(); +// thread()->wait(60000); + connectToEngine(); + resize(10, 10); } @@ -31,3 +59,9 @@ void AwesomeWidget::updateText() { if (debug) qDebug() << PDEBUG; } + + +void AwesomeWidget::updateTooltip() +{ + if (debug) qDebug() << PDEBUG; +}