diff --git a/sources/plasmoid/netctl.cpp b/sources/plasmoid/netctl.cpp index f6005ef..f17b4ea 100644 --- a/sources/plasmoid/netctl.cpp +++ b/sources/plasmoid/netctl.cpp @@ -28,13 +28,36 @@ #include #include -#include +#include #include #include #include +IconLabel::IconLabel(Netctl *wid, const bool debugCmd) + : QLabel(), + debug(debugCmd), + widget(wid) +{ +} + + +IconLabel::~IconLabel() +{ + if (debug) qDebug() << "[PLASMOID]" << "[IconLabel]"; +} + + +void IconLabel::mousePressEvent(QMouseEvent *event) +{ + if (debug) qDebug() << "[PLASMOID]" << "[mousePressEvent]"; + + if (event->button() == Qt::LeftButton) + widget->showGui(); +} + + Netctl::Netctl(QObject *parent, const QVariantList &args) : Plasma::PopupApplet(parent, args) { @@ -48,6 +71,7 @@ Netctl::Netctl(QObject *parent, const QVariantList &args) this->setBackgroundHints(DefaultBackground); this->setHasConfigurationInterface(true); + connect(this, SIGNAL(activate()), this, SLOT(showGui())); // text format init formatLine.append(QString("")); formatLine.append(QString("")); @@ -81,23 +105,15 @@ void Netctl::init() netctlEngine = dataEngine(QString("netctl")); createActions(); // generate ui - graphicsWidget = new QGraphicsWidget(); - this->setGraphicsWidget(graphicsWidget); - // main layout - fullSpaceLayout = new QGraphicsLinearLayout(graphicsWidget); - fullSpaceLayout->setContentsMargins(1, 1, 1, 1); - graphicsWidget->setLayout(fullSpaceLayout); - - // frames - // icon - iconWidget = new Plasma::IconWidget(KIcon(""), QString(), this); - iconWidget->setPreferredSize(30, 30); - connect(iconWidget, SIGNAL(clicked()), this, SLOT(showGui())); - fullSpaceLayout->addItem(iconWidget); - // text - textLabel = new Plasma::Label(); - textLabel->setPreferredHeight(30); - fullSpaceLayout->addItem(textLabel); + graphicsWidget = new QWidget(); + graphicsWidget->setAttribute(Qt::WA_TranslucentBackground, true); + this->setWidget(graphicsWidget); + // layouts + layout = new QHBoxLayout(graphicsWidget); + layout->setContentsMargins(1, 1, 1, 1); + iconLabel = new IconLabel(this, debug); + layout->addWidget(iconLabel); + layout->addWidget(&textLabel); // read variables configChanged(); @@ -198,8 +214,10 @@ void Netctl::updateIcon() else icon = paths[QString("inactive")]; - iconWidget->setIcon(icon); this->setPopupIcon(KIcon(icon)); + QPixmap iconPixmap; + iconPixmap.load(icon); + iconLabel->setPixmap(iconPixmap); } @@ -208,16 +226,9 @@ void Netctl::updateInterface(bool setShown) if (debug) qDebug() << "[PLASMOID]" << "[updateInterface]"; if (debug) qDebug() << "[PLASMOID]" << "[updateInterface]" << ":" << "State" << setShown; - if (setShown) { - textLabel->show(); - fullSpaceLayout->updateGeometry(); - updateGeometry(); - } - else { - textLabel->hide(); - fullSpaceLayout->updateGeometry(); - updateGeometry(); - } + textLabel.setHidden(!setShown); + layout->setSizeConstraint(QLayout::SetMinimumSize); + graphicsWidget->resize(1, 1); } @@ -523,7 +534,7 @@ void Netctl::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Da if (bigInterface[QString("netDev")]) text.append(info[QString("interfaces")]); if (bigInterface[QString("main")]) - textLabel->setText(formatLine[0] + text.join(QString("
")) + formatLine[1]); + textLabel.setText(formatLine[0] + text.join(QString("
")) + formatLine[1]); } else if (sourceName == QString("extIp")) { info[QString("extIp")] = value; diff --git a/sources/plasmoid/netctl.h b/sources/plasmoid/netctl.h index 359dcb3..034f0a2 100644 --- a/sources/plasmoid/netctl.h +++ b/sources/plasmoid/netctl.h @@ -18,11 +18,7 @@ #ifndef NETCTL_PLASMOID_H #define NETCTL_PLASMOID_H -#include #include -#include -#include -#include #include #include @@ -33,6 +29,23 @@ class QGraphicsLinearLayout; +class Netctl; + +class IconLabel : public QLabel +{ + Q_OBJECT + +public: + IconLabel(Netctl *wid, const bool debugCmd); + ~IconLabel(); + +protected: + void mousePressEvent(QMouseEvent *event); + +private: + bool debug; + Netctl *widget; +}; class Netctl : public Plasma::PopupApplet { @@ -92,12 +105,11 @@ protected: private: // ui - QGraphicsWidget *graphicsWidget; - QGraphicsLinearLayout *fullSpaceLayout; - // icon - Plasma::IconWidget *iconWidget; - // text - Plasma::Label *textLabel; + QWidget *graphicsWidget; + QHBoxLayout *layout; + IconLabel *iconLabel; + QLabel textLabel; + // information bool status; QMap info; QStringList profileList; diff --git a/sources/plasmoid/widget.ui b/sources/plasmoid/widget.ui index 59e42b1..c65895b 100644 --- a/sources/plasmoid/widget.ui +++ b/sources/plasmoid/widget.ui @@ -7,7 +7,7 @@ 0 0 480 - 339 + 337 @@ -20,16 +20,6 @@ Configuration Window - - - - - - - Qt::AlignCenter - - -