add toggle panel configuration

This commit is contained in:
arcan1s 2014-08-28 12:28:52 +04:00
parent d28d7156ce
commit 2c35031549
3 changed files with 126 additions and 11 deletions

View File

@ -165,16 +165,34 @@ QList<Plasma::Containment *> DesktopPanel::getPanels()
if (debug) qDebug() << "[PTM-DP]" << "[getPanels]";
QList<Plasma::Containment *> panels;
for (int i=0; i<containment()->corona()->containments().count(); i++) {
qDebug() << containment()->corona()->containments()[i]->containmentType();
for (int i=0; i<containment()->corona()->containments().count(); i++)
if (containment()->corona()->containments()[i]->containmentType() == Plasma::Containment::PanelContainment)
panels.append(containment()->corona()->containments()[i]);
}
return panels;
}
QString DesktopPanel::panelLocationToStr(Plasma::Location loc)
{
if (debug) qDebug() << "[PTM-DP]" << "[panelLocationToStr]";
if (debug) qDebug() << "[PTM-DP]" << "[panelLocationToStr]" << ":" << "Location" << loc;
switch(loc) {
case Plasma::TopEdge:
return i18n("Top Edge");
case Plasma::BottomEdge:
return i18n("Bottom Edge");
case Plasma::LeftEdge:
return i18n("Left Edge");
case Plasma::RightEdge:
return i18n("Right Edge");
default:
return i18n("Unknown Position (%1)", loc);
}
}
QString DesktopPanel::parsePattern(const QString rawLine, const int num)
{
if (debug) qDebug() << "[PTM-DP]" << "[parsePattern]";
@ -257,6 +275,10 @@ void DesktopPanel::changePanelsState()
QList<Plasma::Containment *> panels = getPanels();
for (int i=0; i<panels.count(); i++) {
if ((configuration[QString("panels")].split(QChar(','))
.contains(QString::number(i))) ||
(configuration[QString("panels")] == QString("-1")))
continue;
bool wasVisible = panels[i]->view()->isVisible();
int winId = panels[i]->view()->winId();
if (wasVisible) {
@ -275,7 +297,7 @@ void DesktopPanel::changePanelsState()
}
int DesktopPanel::setCurrentDesktop(const int number)
void DesktopPanel::setCurrentDesktop(const int number)
{
if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]";
if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Set desktop" << number + 1;
@ -284,12 +306,7 @@ int DesktopPanel::setCurrentDesktop(const int number)
if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Run cmd " << cmd;
QProcess command;
command.start(cmd);
command.waitForFinished(-1);
int status = command.exitCode();
if (debug) qDebug() << "[PTM-DP]" << "[setCurrentDesktop]" << "Cmd returns " << status;
return status;
command.startDetached(cmd);
}
@ -335,6 +352,8 @@ void DesktopPanel::createConfigurationInterface(KConfigDialog *parent)
uiAppConfig.setupUi(appWidget);
QWidget *configWidget = new QWidget;
uiWidConfig.setupUi(configWidget);
QWidget *toggleWidget = new QWidget;
uiToggleConfig.setupUi(toggleWidget);
if (configuration[QString("background")].toInt() == 0)
uiWidConfig.checkBox_background->setCheckState(Qt::Unchecked);
@ -389,8 +408,22 @@ void DesktopPanel::createConfigurationInterface(KConfigDialog *parent)
else if (fontStyle == "italic")
uiAppConfig.comboBox_fontStyleInactive->setCurrentIndex(1);
uiToggleConfig.listWidget_list->clear();
QList<Plasma::Containment *> panels = getPanels();
for (int i=0; i<panels.count(); i++) {
QListWidgetItem *item = new QListWidgetItem(panelLocationToStr(panels[i]->location()), uiToggleConfig.listWidget_list);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
if ((configuration[QString("panels")].split(QChar(','))
.contains(QString::number(i))) ||
(configuration[QString("panels")] == QString("-1")))
item->setCheckState(Qt::Checked);
else
item->setCheckState(Qt::Unchecked);
}
parent->addPage(configWidget, i18n("Widget"), Applet::icon());
parent->addPage(appWidget, i18n("Appearance"), QString("preferences-desktop-theme"));
parent->addPage(toggleWidget, i18n("Toggle panels"), QString("plasma"));
connect(parent, SIGNAL(okClicked()), this, SLOT(configAccepted()));
connect(parent, SIGNAL(applyClicked()), this, SLOT(configAccepted()));
@ -424,6 +457,15 @@ void DesktopPanel::configAccepted()
cg.writeEntry("fontColor", uiAppConfig.kcolorcombo_fontColorInactive->color().name());
cg.writeEntry("fontWeight", uiAppConfig.spinBox_fontWeightInactive->value());
cg.writeEntry("fontStyle", uiAppConfig.comboBox_fontStyleInactive->currentText());
QStringList indexes;
for (int i=0; i<uiToggleConfig.listWidget_list->count(); i++)
if (uiToggleConfig.listWidget_list->item(i)->checkState() == Qt::Checked)
indexes.append(QString::number(i));
if (indexes.count() == uiToggleConfig.listWidget_list->count())
cg.writeEntry("panels", QString("-1"));
else
cg.writeEntry("panels", indexes.join(QChar(',')));
}
@ -439,6 +481,7 @@ void DesktopPanel::configChanged()
configuration[QString("layout")] = cg.readEntry("layout", "0");
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");

View File

@ -24,6 +24,7 @@
#include <Plasma/Label>
#include <ui_appearance.h>
#include <ui_toggle.h>
#include <ui_widget.h>
@ -70,7 +71,7 @@ public slots:
void configChanged();
// events
void changePanelsState();
int setCurrentDesktop(const int number);
void setCurrentDesktop(const int number);
private slots:
void reinit();
@ -82,6 +83,7 @@ private:
// functions
QStringList getDesktopNames();
QList<Plasma::Containment *> getPanels();
QString panelLocationToStr(Plasma::Location loc);
void updateText();
// ui
QGraphicsLinearLayout *layout;
@ -95,6 +97,7 @@ private:
// configuration interface
Ui::AppearanceWidget uiAppConfig;
Ui::ConfigWindow uiWidConfig;
Ui::ToggleWindow uiToggleConfig;
// configuration
QMap<QString, QString> configuration;
QStringList desktopNames;

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ToggleWindow</class>
<widget class="QWidget" name="ToggleWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>343</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>480</width>
<height>320</height>
</size>
</property>
<property name="windowTitle">
<string notr="true">Toggle Window</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="QLabel" name="label_info">
<property name="text">
<string>To control panels please set widget shortcut.</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidget_list"/>
</item>
<item>
<spacer name="spacer_widget">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>152</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>