From 662b9529618e0fdc239154767bcda83c13537ee8 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 9 Jul 2014 09:42:58 +0400 Subject: [PATCH] ended work on ptm-desktop-panel --- sources/desktop-panel/desktop-panel.cpp | 57 ++++++++++++++++++++++++- sources/desktop-panel/desktop-panel.h | 28 +++++++++++- sources/desktop-panel/widget.ui | 24 +++++++++++ 3 files changed, 105 insertions(+), 4 deletions(-) diff --git a/sources/desktop-panel/desktop-panel.cpp b/sources/desktop-panel/desktop-panel.cpp index acf95d3..fcae593 100644 --- a/sources/desktop-panel/desktop-panel.cpp +++ b/sources/desktop-panel/desktop-panel.cpp @@ -26,7 +26,48 @@ #include #include #include +#include #include +#include + + +CustomPlasmaLabel::CustomPlasmaLabel(DesktopPanel *wid, const int num) + : Plasma::Label(wid) +{ + // debug + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + QString debugEnv = environment.value(QString("PTM_DEBUG"), QString("no")); + if (debugEnv == QString("yes")) + debug = true; + else + debug = false; + + if (debug) qDebug() << "[PTM-DP]" << "Init label" << num; + number = num; + widget = wid; +} + + +CustomPlasmaLabel::~CustomPlasmaLabel() +{ +} + + +int CustomPlasmaLabel::getNumber() +{ + if (debug) qDebug() << "[PTM-DP]" << "[" << number << "]" << "[getNumber]"; + return number; +} + + +void CustomPlasmaLabel::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (debug) qDebug() << "[PTM-DP]" << "[" << number << "]" << "[mouseMoveEvent]"; + if (debug) qDebug() << "[PTM-DP]" << "[" << number << "]" << "[mouseMoveEvent]" << "Get signal" << event->button(); + if (event->button() == Qt::LeftButton) + widget->setCurrentDesktop(number); +} + DesktopPanel::DesktopPanel(QObject *parent, const QVariantList &args) @@ -139,7 +180,7 @@ void DesktopPanel::reinit() layout->addStretch(1); // labels for (int i=0; iaddItem(labels[i]); } // right stretch @@ -150,9 +191,18 @@ void DesktopPanel::reinit() } -void DesktopPanel::setCurrentDesktop() +int DesktopPanel::setCurrentDesktop(const int number) { if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]"; + if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Set desktop" << number; + if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Run cmd " << configuration[QString("desktopcmd")] << QString::number(number+1); + + QProcess command; + command.start(configuration[QString("desktopcmd")] + QString(" ") + QString::number(number+1)); + command.waitForFinished(-1); + int status = command.exitCode(); + if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Cmd returns " << status; + return status; } @@ -238,6 +288,7 @@ void DesktopPanel::createConfigurationInterface(KConfigDialog *parent) uiWidConfig.spinBox_interval->setValue(configuration[QString("interval")].toInt()); uiWidConfig.lineEdit_mark->setText(configuration[QString("mark")]); uiWidConfig.lineEdit_pattern->setText(configuration[QString("pattern")]); + uiWidConfig.lineEdit_desktopcmd->setText(configuration[QString("desktopcmd")]); KConfigGroup cg = config(); QString fontFamily = cg.readEntry("currentFontFamily", "Terminus"); @@ -291,6 +342,7 @@ void DesktopPanel::configAccepted() cg.writeEntry("interval", QString::number(uiWidConfig.spinBox_interval->value())); cg.writeEntry("mark", uiWidConfig.lineEdit_mark->text()); cg.writeEntry("pattern", uiWidConfig.lineEdit_pattern->text()); + cg.writeEntry("desktopcmd", uiWidConfig.lineEdit_desktopcmd->text()); cg.writeEntry("currentFontFamily", uiAppConfig.fontComboBox_fontActive->currentFont().family()); cg.writeEntry("currentFontSize", uiAppConfig.spinBox_fontSizeActive->value()); @@ -312,6 +364,7 @@ void DesktopPanel::configChanged() KConfigGroup cg = config(); configuration[QString("background")] = cg.readEntry("background", "0"); + configuration[QString("desktopcmd")] = cg.readEntry("desktopcmd", "qdbus org.kde.kwin /KWin setCurrentDesktop"); configuration[QString("interval")] = cg.readEntry("interval", "1000"); configuration[QString("layout")] = cg.readEntry("layout", "0"); configuration[QString("leftStretch")] = cg.readEntry("leftStretch", "2"); diff --git a/sources/desktop-panel/desktop-panel.h b/sources/desktop-panel/desktop-panel.h index 1e05a78..15c3038 100644 --- a/sources/desktop-panel/desktop-panel.h +++ b/sources/desktop-panel/desktop-panel.h @@ -28,6 +28,29 @@ class QGraphicsLinearLayout; +class DesktopPanel; + + +class CustomPlasmaLabel : public Plasma::Label +{ + Q_OBJECT + +public: + CustomPlasmaLabel(DesktopPanel *wid, const int num); + ~CustomPlasmaLabel(); + int getNumber(); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event); + +private: + // debug + bool debug; + // variables + int number; + DesktopPanel *widget; +}; + class DesktopPanel : public Plasma::Applet { @@ -44,10 +67,11 @@ public slots: // configuration interface void configAccepted(); void configChanged(); + // event + int setCurrentDesktop(const int number); private slots: void reinit(); - void setCurrentDesktop(); protected: void createConfigurationInterface(KConfigDialog *parent); @@ -58,7 +82,7 @@ private: void updateText(); // ui QGraphicsLinearLayout *layout; - QList labels; + QList labels; // debug bool debug; // data engine diff --git a/sources/desktop-panel/widget.ui b/sources/desktop-panel/widget.ui index 677c208..c70b410 100644 --- a/sources/desktop-panel/widget.ui +++ b/sources/desktop-panel/widget.ui @@ -169,6 +169,30 @@ $total - total number of desktops + + + + + + + 200 + 0 + + + + Command to change desktop + + + + + + + Command which will change the current desktop + + + + +