From 1d1fe469f8c5858312773591b4a49a5484a9bc7d Mon Sep 17 00:00:00 2001 From: arcan1s Date: Fri, 12 Sep 2014 19:29:31 +0400 Subject: [PATCH] rewrite DP configuration interface --- CHANGELOG | 1 + CHANGELOG-RU | 1 + sources/desktop-panel/desktop-panel.cpp | 75 ++- sources/desktop-panel/desktop-panel.h | 6 +- sources/desktop-panel/widget.ui | 623 ++++++++++++++---------- 5 files changed, 451 insertions(+), 255 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ea27702..dee759d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ Ver.2.0.2: + add Chinese translation (thanks to @Lemueler) - remove ps stats from notification * yet another fix cpu* and cpucl* +* rewrite DP configuration interface Ver.2.0.1: + add support of custom interfaces diff --git a/CHANGELOG-RU b/CHANGELOG-RU index ae0cf6e..94e1fa1 100644 --- a/CHANGELOG-RU +++ b/CHANGELOG-RU @@ -3,6 +3,7 @@ + добавлен китайский перевод (спасибо @Lemueler) - удалено ps stats из уведомлений * еще один фикс тегов cpu* и cpucl +* переписан конфигурационный интерфейс DP Вер.2.0.1: + добавлена поддержка кастомных интерфейсов diff --git a/sources/desktop-panel/desktop-panel.cpp b/sources/desktop-panel/desktop-panel.cpp index 7aca7db..8c81b96 100644 --- a/sources/desktop-panel/desktop-panel.cpp +++ b/sources/desktop-panel/desktop-panel.cpp @@ -154,15 +154,18 @@ QString DesktopPanel::panelLocationToStr(Plasma::Location loc) QString DesktopPanel::parsePattern(const QString rawLine, const int num) { if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Run function with raw line" << rawLine; - if (debug) qDebug() << PDEBUG << ":" << "Run function with number" << num; + if (debug) qDebug() << PDEBUG << ":" << "Raw line" << rawLine; + if (debug) qDebug() << PDEBUG << ":" << "Number" << num; - QString line, mark; + QString line, fullMark, mark; line = rawLine; if (currentDesktop == num + 1) mark = configuration[QString("mark")]; else mark = QString(""); + fullMark = QString("%1").arg(mark, configuration[QString("mark")].count(), QLatin1Char(' ')); + if (line.contains(QString("$fullmark"))) + line.replace(QString("$fullmark"), fullMark); if (line.contains(QString("$mark"))) line.replace(QString("$mark"), mark); if (line.contains(QString("$name"))) @@ -207,6 +210,7 @@ void DesktopPanel::reinit() // labels for (int i=0; isetWordWrap(false); layout->addItem(labels[i]); } // right stretch @@ -281,7 +285,7 @@ void DesktopPanel::updateText() void DesktopPanel::dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data) { if (debug) qDebug() << PDEBUG; - if (debug) qDebug() << PDEBUG << ":" << "Run function with source name" << sourceName; + if (debug) qDebug() << PDEBUG << ":" << "Source name" << sourceName; if (data.keys().count() == 0) return; @@ -308,6 +312,7 @@ void DesktopPanel::createConfigurationInterface(KConfigDialog *parent) QWidget *toggleWidget = new QWidget; uiToggleConfig.setupUi(toggleWidget); + uiWidConfig.textEdit_elements->setPlainText(configuration[QString("pattern")]); if (configuration[QString("background")].toInt() == 0) uiWidConfig.checkBox_background->setCheckState(Qt::Unchecked); else @@ -327,7 +332,6 @@ void DesktopPanel::createConfigurationInterface(KConfigDialog *parent) uiWidConfig.spinBox_interval->setValue(configuration[QString("interval")].toInt()); uiWidConfig.comboBox_mark->setItemText(uiWidConfig.comboBox_mark->count()-1, configuration[QString("mark")]); uiWidConfig.comboBox_mark->setCurrentIndex(uiWidConfig.comboBox_mark->count()-1); - uiWidConfig.lineEdit_pattern->setText(configuration[QString("pattern")]); uiWidConfig.lineEdit_desktopcmd->setText(configuration[QString("desktopcmd")]); KConfigGroup cg = config(); @@ -376,6 +380,18 @@ void DesktopPanel::createConfigurationInterface(KConfigDialog *parent) parent->addPage(appWidget, i18n("Appearance"), QString("preferences-desktop-theme")); parent->addPage(toggleWidget, i18n("Toggle panels"), QString("plasma")); + connect(uiWidConfig.pushButton_tags, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_br, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_font, SIGNAL(clicked(bool)), this, SLOT(setFontFormating())); + connect(uiWidConfig.pushButton_bold, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_italic, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_underline, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_strike, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_left, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_center, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_right, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(uiWidConfig.pushButton_fill, SIGNAL(clicked(bool)), this, SLOT(setFormating())); + connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted())); connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted())); } @@ -388,13 +404,13 @@ void DesktopPanel::configAccepted() extsysmonEngine->disconnectSource(QString("desktop"), this); KConfigGroup cg = config(); + cg.writeEntry("pattern", uiWidConfig.textEdit_elements->toPlainText()); cg.writeEntry("background", QString::number(uiWidConfig.checkBox_background->checkState())); cg.writeEntry("layout", QString::number(uiWidConfig.checkBox_layout->checkState())); cg.writeEntry("leftStretch", QString::number(uiWidConfig.checkBox_leftStretch->checkState())); cg.writeEntry("rightStretch", QString::number(uiWidConfig.checkBox_rightStretch->checkState())); cg.writeEntry("interval", QString::number(uiWidConfig.spinBox_interval->value())); cg.writeEntry("mark", uiWidConfig.comboBox_mark->currentText()); - cg.writeEntry("pattern", uiWidConfig.lineEdit_pattern->text()); cg.writeEntry("desktopcmd", uiWidConfig.lineEdit_desktopcmd->text()); cg.writeEntry("currentFontFamily", uiAppConfig.fontComboBox_fontActive->currentFont().family()); @@ -426,6 +442,7 @@ void DesktopPanel::configChanged() KConfigGroup cg = config(); + configuration[QString("pattern")] = cg.readEntry("pattern", "[$fullmark$number/$total: $name]"); configuration[QString("background")] = cg.readEntry("background", "2"); configuration[QString("desktopcmd")] = cg.readEntry("desktopcmd", "qdbus org.kde.kwin /KWin setCurrentDesktop $number"); configuration[QString("interval")] = cg.readEntry("interval", "1000"); @@ -433,7 +450,6 @@ void DesktopPanel::configChanged() configuration[QString("leftStretch")] = cg.readEntry("leftStretch", "2"); configuration[QString("mark")] = cg.readEntry("mark", "¤"); configuration[QString("panels")] = cg.readEntry("panels", "-1"); - configuration[QString("pattern")] = cg.readEntry("pattern", "[$mark$number/$total: $name]"); configuration[QString("rightStretch")] = cg.readEntry("rightStretch", "2"); extsysmonEngine->connectSource(QString("desktop"), this, configuration[QString("interval")].toInt()); @@ -479,4 +495,49 @@ void DesktopPanel::configChanged() } +void DesktopPanel::setFontFormating() +{ + if (debug) qDebug() << PDEBUG; + + CFont defaultFont = CFont(uiAppConfig.fontComboBox_fontInactive->currentFont().family(), + uiAppConfig.spinBox_fontSizeInactive->value(), + 400, false, uiAppConfig.kcolorcombo_fontColorInactive->color()); + CFont font = CFontDialog::getFont(i18n("Select font"), defaultFont, + false, false); + QString selectedText = uiWidConfig.textEdit_elements->textCursor().selectedText(); + uiWidConfig.textEdit_elements->insertPlainText(QString("") + .arg(font.color().name()).arg(font.family()).arg(font.pointSize()) + + selectedText + QString("")); +} + + +void DesktopPanel::setFormating() +{ + if (debug) qDebug() << PDEBUG; + if (debug) qDebug() << PDEBUG << ":" << "Sender" << sender(); + + QString selectedText = uiWidConfig.textEdit_elements->textCursor().selectedText(); + if (sender() == uiWidConfig.pushButton_tags) + uiWidConfig.textEdit_elements->insertPlainText(QString("$") + uiWidConfig.comboBox_tags->currentText()); + else if (sender() == uiWidConfig.pushButton_br) + uiWidConfig.textEdit_elements->insertPlainText(QString("
\n")); + else if (sender() == uiWidConfig.pushButton_bold) + uiWidConfig.textEdit_elements->insertPlainText(QString("") + selectedText + QString("")); + else if (sender() == uiWidConfig.pushButton_italic) + uiWidConfig.textEdit_elements->insertPlainText(QString("") + selectedText + QString("")); + else if (sender() == uiWidConfig.pushButton_underline) + uiWidConfig.textEdit_elements->insertPlainText(QString("") + selectedText + QString("")); + else if (sender() == uiWidConfig.pushButton_strike) + uiWidConfig.textEdit_elements->insertPlainText(QString("") + selectedText + QString("")); + else if (sender() == uiWidConfig.pushButton_left) + uiWidConfig.textEdit_elements->insertPlainText(QString("

") + selectedText + QString("

")); + else if (sender() == uiWidConfig.pushButton_center) + uiWidConfig.textEdit_elements->insertPlainText(QString("

") + selectedText + QString("

")); + else if (sender() == uiWidConfig.pushButton_right) + uiWidConfig.textEdit_elements->insertPlainText(QString("

") + selectedText + QString("

")); + else if (sender() == uiWidConfig.pushButton_fill) + uiWidConfig.textEdit_elements->insertPlainText(QString("

") + selectedText + QString("

")); +} + + #include "desktop-panel.moc" diff --git a/sources/desktop-panel/desktop-panel.h b/sources/desktop-panel/desktop-panel.h index d9232e4..39128c3 100644 --- a/sources/desktop-panel/desktop-panel.h +++ b/sources/desktop-panel/desktop-panel.h @@ -76,6 +76,8 @@ public slots: private slots: void reinit(); + void setFontFormating(); + void setFormating(); protected: void createConfigurationInterface(KConfigDialog *parent); @@ -100,9 +102,7 @@ private: Ui::ToggleWindow uiToggleConfig; // configuration QMap configuration; - QStringList desktopNames; - QStringList currentFormatLine; - QStringList formatLine; + QStringList desktopNames, currentFormatLine, formatLine; }; K_EXPORT_PLASMA_APPLET(desktop-panel, DesktopPanel) diff --git a/sources/desktop-panel/widget.ui b/sources/desktop-panel/widget.ui index 409caec..138a8bf 100644 --- a/sources/desktop-panel/widget.ui +++ b/sources/desktop-panel/widget.ui @@ -6,13 +6,13 @@ 0 0 - 480 - 343 + 729 + 428 - 480 + 700 320 @@ -20,267 +20,400 @@ Widget - - - - true + + + + + + + 200 + 0 + + + + Time interval + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 180 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 1 + + + 10000 + + + 500 + + + 1000 + + + + + + + + + Add stretch to left/top of the layout - - - - 0 - 0 - 464 - 327 - - - + + + + + + Enable background + + + + + + + + + + 200 + 0 + + + + Mark + + + + + + + A mark which will be shown if this desktop is active + + + true + - - - Enable background - - + + # + - - - Vertical layout - - + + $ + - - - Add stretch to left/top of the layout - - + + % + - - - Add stretch to right/bottom of the layout - - + + & + - - - - - - 200 - 0 - - - - Time interval - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 180 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 1 - - - 10000 - - - 500 - - - 1000 - - - - + + * + - - - - - - 200 - 0 - - - - Mark - - - - - - - A mark which will be shown if this desktop is active - - - true - - - - # - - - - - $ - - - - - % - - - - - & - - - - - * - - - - - @ - - - - - ¤ - - - - - - - - - - · - - - - - º - - - - - × - - - - - - - - - - - - - - - (current) - - - - - + + @ + - - - - - - 200 - 0 - - - - Pattern - - - - - - - $mark - show mark if the current desktop is active -$name - desktop name -$number - desktop number -$total - total number of desktops - - - - + + ¤ + - - - - - - 200 - 0 - - - - Command to change desktop - - - - - - - Command which will change the current desktop - - - - + + + - - - Qt::Vertical - - - - 20 - 152 - - - + + · + - - + + + º + + + + + × + + + + + + + + + + + + + + + (current) + + + + + + + + + + Add stretch to right/bottom of the layout + + + + + + + Vertical layout + + + + + + + + + + 200 + 0 + + + + Command to change desktop + + + + + + + Command which will change the current desktop + + + + + + + + + + + Font + + + + + + + + ../awesome-widget../awesome-widget + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + ../awesome-widget../awesome-widget + + + Ctrl+B + + + + + + + + ../awesome-widget../awesome-widget + + + Ctrl+I + + + + + + + + ../awesome-widget../awesome-widget + + + Ctrl+U + + + + + + + + ../awesome-widget../awesome-widget + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + ../awesome-widget../awesome-widget + + + + + + + + ../awesome-widget../awesome-widget + + + + + + + + ../awesome-widget../awesome-widget + + + + + + + + ../awesome-widget../awesome-widget + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + + fullmark + + + + + mark + + + + + name + + + + + number + + + + + total + + + + + + + + Add + + + + + + + + + QTextEdit::NoWrap + + + false +