add click event, remove button

TODO: refactoring (including removal of unneeded pointers) and normal resize event
This commit is contained in:
arcan1s 2014-08-01 20:24:40 +04:00
parent c1e23d38a9
commit eefe196b69
3 changed files with 64 additions and 51 deletions

View File

@ -28,13 +28,36 @@
#include <plasma/theme.h>
#include <QDebug>
#include <QGraphicsLinearLayout>
#include <QGraphicsSceneMouseEvent>
#include <QMenu>
#include <QProcessEnvironment>
#include <version.h>
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("<br>")) + formatLine[1]);
textLabel.setText(formatLine[0] + text.join(QString("<br>")) + formatLine[1]);
}
else if (sourceName == QString("extIp")) {
info[QString("extIp")] = value;

View File

@ -18,11 +18,7 @@
#ifndef NETCTL_PLASMOID_H
#define NETCTL_PLASMOID_H
#include <Plasma/Applet>
#include <Plasma/DataEngine>
#include <Plasma/Frame>
#include <Plasma/IconWidget>
#include <Plasma/Label>
#include <Plasma/PopupApplet>
#include <QProcess>
@ -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<QString, QString> info;
QStringList profileList;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>480</width>
<height>339</height>
<height>337</height>
</rect>
</property>
<property name="minimumSize">
@ -20,16 +20,6 @@
<string notr="true">Configuration Window</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_info">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_autoUpdate">
<item>