rewrite DP configuration interface

This commit is contained in:
arcan1s 2014-09-12 19:29:31 +04:00
parent 99049164be
commit 1d1fe469f8
5 changed files with 451 additions and 255 deletions

View File

@ -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

View File

@ -3,6 +3,7 @@
+ добавлен китайский перевод (спасибо @Lemueler)
- удалено ps stats из уведомлений
* еще один фикс тегов cpu* и cpucl
* переписан конфигурационный интерфейс DP
Вер.2.0.1:
+ добавлена поддержка кастомных интерфейсов

View File

@ -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; i<desktopNames.count(); i++) {
labels.append(new CustomPlasmaLabel(this, i));
labels[i]->setWordWrap(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("<font color=\"%1\" face=\"%2\" size=\"%3\">")
.arg(font.color().name()).arg(font.family()).arg(font.pointSize()) +
selectedText + QString("</font>"));
}
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("<br>\n"));
else if (sender() == uiWidConfig.pushButton_bold)
uiWidConfig.textEdit_elements->insertPlainText(QString("<b>") + selectedText + QString("</b>"));
else if (sender() == uiWidConfig.pushButton_italic)
uiWidConfig.textEdit_elements->insertPlainText(QString("<i>") + selectedText + QString("</i>"));
else if (sender() == uiWidConfig.pushButton_underline)
uiWidConfig.textEdit_elements->insertPlainText(QString("<u>") + selectedText + QString("</u>"));
else if (sender() == uiWidConfig.pushButton_strike)
uiWidConfig.textEdit_elements->insertPlainText(QString("<s>") + selectedText + QString("</s>"));
else if (sender() == uiWidConfig.pushButton_left)
uiWidConfig.textEdit_elements->insertPlainText(QString("<p align=\"left\">") + selectedText + QString("</p>"));
else if (sender() == uiWidConfig.pushButton_center)
uiWidConfig.textEdit_elements->insertPlainText(QString("<p align=\"center\">") + selectedText + QString("</p>"));
else if (sender() == uiWidConfig.pushButton_right)
uiWidConfig.textEdit_elements->insertPlainText(QString("<p align=\"right\">") + selectedText + QString("</p>"));
else if (sender() == uiWidConfig.pushButton_fill)
uiWidConfig.textEdit_elements->insertPlainText(QString("<p align=\"justify\">") + selectedText + QString("</p>"));
}
#include "desktop-panel.moc"

View File

@ -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<QString, QString> configuration;
QStringList desktopNames;
QStringList currentFormatLine;
QStringList formatLine;
QStringList desktopNames, currentFormatLine, formatLine;
};
K_EXPORT_PLASMA_APPLET(desktop-panel, DesktopPanel)

View File

@ -6,13 +6,13 @@
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>343</height>
<width>729</width>
<height>428</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>480</width>
<width>700</width>
<height>320</height>
</size>
</property>
@ -20,50 +20,7 @@
<string notr="true">Widget</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>327</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="checkBox_background">
<property name="text">
<string>Enable background</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_layout">
<property name="text">
<string>Vertical layout</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_leftStretch">
<property name="text">
<string>Add stretch to left/top of the layout</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_rightStretch">
<property name="text">
<string>Add stretch to right/bottom of the layout</string>
</property>
</widget>
</item>
<item>
<item row="6" column="0">
<layout class="QHBoxLayout" name="layout_interval">
<item>
<widget class="QLabel" name="label_interval">
@ -118,7 +75,21 @@
</item>
</layout>
</item>
<item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBox_leftStretch">
<property name="text">
<string>Add stretch to left/top of the layout</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox_background">
<property name="text">
<string>Enable background</string>
</property>
</widget>
</item>
<item row="7" column="0">
<layout class="QHBoxLayout" name="layout_mark">
<item>
<widget class="QLabel" name="label_mark">
@ -215,34 +186,21 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_pattern">
<item>
<widget class="QLabel" name="label_pattern">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<item row="5" column="0">
<widget class="QCheckBox" name="checkBox_rightStretch">
<property name="text">
<string>Pattern</string>
<string>Add stretch to right/bottom of the layout</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_pattern">
<property name="toolTip">
<string>$mark - show mark if the current desktop is active
$name - desktop name
$number - desktop number
$total - total number of desktops</string>
<item row="3" column="0">
<widget class="QCheckBox" name="checkBox_layout">
<property name="text">
<string>Vertical layout</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<item row="8" column="0">
<layout class="QHBoxLayout" name="layout_desktopcmd">
<item>
<widget class="QLabel" name="label_desktopcmd">
@ -266,21 +224,196 @@ $total - total number of desktops</string>
</item>
</layout>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="layput_mainFormating">
<item>
<spacer name="spacer_widget">
<widget class="QPushButton" name="pushButton_font">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_br">
<property name="icon">
<iconset theme="stock_text_indent">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
</widget>
</item>
<item>
<spacer name="spacer_mainFormatingCenter1">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>152</height>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<item>
<widget class="QPushButton" name="pushButton_bold">
<property name="icon">
<iconset theme="format-text-bold">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
<property name="shortcut">
<string>Ctrl+B</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_italic">
<property name="icon">
<iconset theme="format-text-italic">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_underline">
<property name="icon">
<iconset theme="format-text-underline">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
<property name="shortcut">
<string>Ctrl+U</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_strike">
<property name="icon">
<iconset theme="format-text-strikethrough">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
</widget>
</item>
<item>
<spacer name="spacer_mainFormatingCenter2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_left">
<property name="icon">
<iconset theme="format-justify-left">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_center">
<property name="icon">
<iconset theme="format-justify-center">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_right">
<property name="icon">
<iconset theme="format-justify-right">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_fill">
<property name="icon">
<iconset theme="format-justify-fill">
<normaloff>../awesome-widget</normaloff>../awesome-widget</iconset>
</property>
</widget>
</item>
<item>
<spacer name="spacer_mainFormatingCenter3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="comboBox_tags">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string notr="true">fullmark</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">mark</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">name</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">number</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">total</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_tags">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QTextEdit" name="textEdit_elements">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
</layout>