mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
add formatter configuration to ui
This commit is contained in:
parent
6bd7788aa9
commit
301a908aed
@ -31,6 +31,9 @@ Item {
|
||||
AWActions {
|
||||
id: awActions
|
||||
}
|
||||
AWFormatterConfigFactory {
|
||||
id: awFormatter
|
||||
}
|
||||
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
@ -320,10 +323,15 @@ Item {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 5
|
||||
width: parent.width * 3 / 10
|
||||
text: i18n("Edit bars")
|
||||
onClicked: awKeys.editItem("graphicalitem")
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 3 / 10
|
||||
text: i18n("Formatters")
|
||||
onClicked: awFormatter.showDialog(awKeys.dictKeys(true))
|
||||
}
|
||||
QtControls.Button {
|
||||
width: parent.width * 2 / 5
|
||||
text: i18n("Preview")
|
||||
|
76
sources/awesome-widget/plugin/awabstractselector.cpp
Normal file
76
sources/awesome-widget/plugin/awabstractselector.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awabstractselector.h"
|
||||
#include "ui_awabstractselector.h"
|
||||
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
AWAbstractSelector::AWAbstractSelector(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::AWAbstractSelector)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->comboBox_key, SIGNAL(currentIndexChanged(int)), this,
|
||||
SIGNAL(selectionChanged()));
|
||||
connect(ui->comboBox_value, SIGNAL(currentIndexChanged(int)), this,
|
||||
SIGNAL(selectionChanged()));
|
||||
}
|
||||
|
||||
|
||||
AWAbstractSelector::~AWAbstractSelector()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
QPair<QString, QString> AWAbstractSelector::current() const
|
||||
{
|
||||
QString key = ui->comboBox_key->currentText();
|
||||
QString value = ui->comboBox_value->currentText();
|
||||
|
||||
return QPair<QString, QString>(key, value);
|
||||
}
|
||||
|
||||
|
||||
void AWAbstractSelector::init(const QStringList keys, const QStringList values,
|
||||
const QPair<QString, QString> current)
|
||||
{
|
||||
if ((!keys.contains(current.first)) || (!values.contains(current.second))) {
|
||||
qCWarning(LOG_AW) << "Invalid current value" << current
|
||||
<< "not found in default ones";
|
||||
return;
|
||||
}
|
||||
qCDebug(LOG_AW) << "Init selector with keys" << keys << "and values"
|
||||
<< values << "and current ones are" << current;
|
||||
|
||||
// set data
|
||||
ui->comboBox_key->clear();
|
||||
ui->comboBox_key->addItems(keys);
|
||||
ui->comboBox_value->clear();
|
||||
ui->comboBox_value->addItems(values);
|
||||
|
||||
// set current values
|
||||
ui->comboBox_key->setCurrentText(current.first);
|
||||
ui->comboBox_value->setCurrentText(current.second);
|
||||
}
|
49
sources/awesome-widget/plugin/awabstractselector.h
Normal file
49
sources/awesome-widget/plugin/awabstractselector.h
Normal file
@ -0,0 +1,49 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWABSTRACTSELECTOR_H
|
||||
#define AWABSTRACTSELECTOR_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class AWAbstractSelector;
|
||||
}
|
||||
|
||||
class AWAbstractSelector : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWAbstractSelector(QWidget *parent = nullptr);
|
||||
virtual ~AWAbstractSelector();
|
||||
QPair<QString, QString> current() const;
|
||||
void init(const QStringList keys, const QStringList values,
|
||||
const QPair<QString, QString> current);
|
||||
|
||||
signals:
|
||||
void selectionChanged();
|
||||
|
||||
private:
|
||||
Ui::AWAbstractSelector *ui = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWABSTRACTSELECTOR_H */
|
36
sources/awesome-widget/plugin/awabstractselector.ui
Normal file
36
sources/awesome-widget/plugin/awabstractselector.ui
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWAbstractSelector</class>
|
||||
<widget class="QWidget" name="AWAbstractSelector">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_key"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_value"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "awactions.h"
|
||||
#include "awconfighelper.h"
|
||||
#include "awformatterhelper.h"
|
||||
#include "awformatterconfigfactory.h"
|
||||
#include "awkeys.h"
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ void AWPlugin::registerTypes(const char *uri)
|
||||
|
||||
qmlRegisterType<AWActions>(uri, 1, 0, "AWActions");
|
||||
qmlRegisterType<AWConfigHelper>(uri, 1, 0, "AWConfigHelper");
|
||||
qmlRegisterType<AWFormatterHelper>(uri, 1, 0, "AWFormatterHelper");
|
||||
qmlRegisterType<AWFormatterConfigFactory>(uri, 1, 0,
|
||||
"AWFormatterConfigFactory");
|
||||
qmlRegisterType<AWKeys>(uri, 1, 0, "AWKeys");
|
||||
}
|
||||
|
159
sources/awesome-widget/plugin/awformatterconfig.cpp
Normal file
159
sources/awesome-widget/plugin/awformatterconfig.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awformatterconfig.h"
|
||||
#include "ui_awformatterconfig.h"
|
||||
|
||||
#include <KI18n/KLocalizedString>
|
||||
|
||||
#include "awabstractselector.h"
|
||||
#include "awdebug.h"
|
||||
#include "awformatterhelper.h"
|
||||
|
||||
|
||||
AWFormatterConfig::AWFormatterConfig(QWidget *parent, const QStringList keys)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::AWFormatterConfig)
|
||||
, m_keys(keys)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
ui->setupUi(this);
|
||||
init();
|
||||
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
}
|
||||
|
||||
|
||||
AWFormatterConfig::~AWFormatterConfig()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
|
||||
clearSelectors();
|
||||
|
||||
delete m_helper;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::showDialog()
|
||||
{
|
||||
clearSelectors();
|
||||
QHash<QString, QString> appliedFormatters = m_helper->getFormatters();
|
||||
auto keys = initKeys();
|
||||
|
||||
for (auto key : appliedFormatters.keys())
|
||||
addSelector(keys.first, keys.second,
|
||||
QPair<QString, QString>(key, appliedFormatters[key]));
|
||||
// empty one
|
||||
addSelector(keys.first, keys.second, QPair<QString, QString>());
|
||||
|
||||
// exec dialog
|
||||
return execDialog();
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::updateUi()
|
||||
{
|
||||
QPair<QString, QString> current
|
||||
= static_cast<AWAbstractSelector *>(sender())->current();
|
||||
int index
|
||||
= m_selectors.indexOf(static_cast<AWAbstractSelector *>(sender()));
|
||||
|
||||
if ((current.first.isEmpty()) && (current.second.isEmpty())) {
|
||||
if (sender() == m_selectors.last())
|
||||
return;
|
||||
AWAbstractSelector *selector = m_selectors.takeAt(index);
|
||||
ui->verticalLayout->removeWidget(selector);
|
||||
selector->deleteLater();
|
||||
} else {
|
||||
if (sender() != m_selectors.last())
|
||||
return;
|
||||
auto keys = initKeys();
|
||||
addSelector(keys.first, keys.second, QPair<QString, QString>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::addSelector(const QStringList &keys,
|
||||
const QStringList &values,
|
||||
const QPair<QString, QString> ¤t)
|
||||
{
|
||||
qCDebug(LOG_AW) << "Add selector with keys" << keys << "values" << values
|
||||
<< "and current ones" << current;
|
||||
|
||||
AWAbstractSelector *selector
|
||||
= new AWAbstractSelector(ui->scrollAreaWidgetContents);
|
||||
selector->init(keys, values, current);
|
||||
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
|
||||
connect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi()));
|
||||
m_selectors.append(selector);
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::clearSelectors()
|
||||
{
|
||||
for (auto selector : m_selectors)
|
||||
disconnect(selector, SIGNAL(selectionChanged()), this,
|
||||
SLOT(updateUi()));
|
||||
m_selectors.clear();
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::execDialog()
|
||||
{
|
||||
int ret = exec();
|
||||
QHash<QString, QString> data;
|
||||
for (auto selector : m_selectors) {
|
||||
QPair<QString, QString> select = selector->current();
|
||||
if ((select.first.isEmpty()) || (select.second.isEmpty()))
|
||||
continue;
|
||||
data[select.first] = select.second;
|
||||
}
|
||||
|
||||
// save configuration if required
|
||||
switch (ret) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
default:
|
||||
m_helper->writeFormatters(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfig::init()
|
||||
{
|
||||
delete m_helper;
|
||||
m_helper = new AWFormatterHelper(this);
|
||||
}
|
||||
|
||||
|
||||
QPair<QStringList, QStringList> AWFormatterConfig::initKeys() const
|
||||
{
|
||||
// we are adding empty string at the start
|
||||
QStringList keys = QStringList() << QString("");
|
||||
keys.append(m_keys);
|
||||
keys.sort();
|
||||
QStringList knownFormatters = QStringList() << QString("");
|
||||
knownFormatters.append(m_helper->knownFormatters());
|
||||
knownFormatters.sort();
|
||||
|
||||
return QPair<QStringList, QStringList>(keys, knownFormatters);
|
||||
}
|
61
sources/awesome-widget/plugin/awformatterconfig.h
Normal file
61
sources/awesome-widget/plugin/awformatterconfig.h
Normal file
@ -0,0 +1,61 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWFORMATTERCONFIG_H
|
||||
#define AWFORMATTERCONFIG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
class AWAbstractSelector;
|
||||
class AWFormatterHelper;
|
||||
namespace Ui
|
||||
{
|
||||
class AWFormatterConfig;
|
||||
}
|
||||
|
||||
class AWFormatterConfig : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWFormatterConfig(QWidget *parent = nullptr,
|
||||
const QStringList keys = QStringList());
|
||||
virtual ~AWFormatterConfig();
|
||||
Q_INVOKABLE void showDialog();
|
||||
|
||||
private slots:
|
||||
void updateUi();
|
||||
|
||||
private:
|
||||
Ui::AWFormatterConfig *ui = nullptr;
|
||||
AWFormatterHelper *m_helper = nullptr;
|
||||
QList<AWAbstractSelector *> m_selectors;
|
||||
// properties
|
||||
QStringList m_keys;
|
||||
// methods
|
||||
void addSelector(const QStringList &keys, const QStringList &values,
|
||||
const QPair<QString, QString> ¤t);
|
||||
void clearSelectors();
|
||||
void execDialog();
|
||||
void init();
|
||||
QPair<QStringList, QStringList> initKeys() const;
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWFORMATTERCONFIG_H */
|
93
sources/awesome-widget/plugin/awformatterconfig.ui
Normal file
93
sources/awesome-widget/plugin/awformatterconfig.ui
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AWFormatterConfig</class>
|
||||
<widget class="QDialog" name="AWFormatterConfig">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<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>384</width>
|
||||
<height>249</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AWFormatterConfig</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AWFormatterConfig</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
42
sources/awesome-widget/plugin/awformatterconfigfactory.cpp
Normal file
42
sources/awesome-widget/plugin/awformatterconfigfactory.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "awformatterconfigfactory.h"
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "awformatterconfig.h"
|
||||
|
||||
|
||||
AWFormatterConfigFactory::AWFormatterConfigFactory(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
AWFormatterConfigFactory::~AWFormatterConfigFactory()
|
||||
{
|
||||
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
void AWFormatterConfigFactory::showDialog(const QStringList keys)
|
||||
{
|
||||
AWFormatterConfig *config = new AWFormatterConfig(nullptr, keys);
|
||||
config->showDialog();
|
||||
config->deleteLater();
|
||||
}
|
38
sources/awesome-widget/plugin/awformatterconfigfactory.h
Normal file
38
sources/awesome-widget/plugin/awformatterconfigfactory.h
Normal file
@ -0,0 +1,38 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef AWFORMATTERCONFIGFACTORY_H
|
||||
#define AWFORMATTERCONFIGFACTORY_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class AWFormatterConfigFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWFormatterConfigFactory(QObject *parent = nullptr);
|
||||
virtual ~AWFormatterConfigFactory();
|
||||
Q_INVOKABLE void showDialog(const QStringList keys);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* AWFORMATTERCONFIGFACTORY_H */
|
@ -66,9 +66,9 @@ QStringList AWFormatterHelper::definedFormatters() const
|
||||
}
|
||||
|
||||
|
||||
QVariantMap AWFormatterHelper::getFormatters() const
|
||||
QHash<QString, QString> AWFormatterHelper::getFormatters() const
|
||||
{
|
||||
QVariantMap map;
|
||||
QHash<QString, QString> map;
|
||||
for (auto tag : m_formatters.keys())
|
||||
map[tag] = m_formatters[tag]->name();
|
||||
|
||||
@ -76,14 +76,27 @@ QVariantMap AWFormatterHelper::getFormatters() const
|
||||
}
|
||||
|
||||
|
||||
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||
{
|
||||
QList<AbstractExtItem *> converted;
|
||||
for (auto item : m_formattersClasses.values())
|
||||
converted.append(item);
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
|
||||
QStringList AWFormatterHelper::knownFormatters() const
|
||||
{
|
||||
return m_formattersClasses.keys();
|
||||
}
|
||||
|
||||
|
||||
bool AWFormatterHelper::writeFormatters(const QVariantMap configuration) const
|
||||
bool AWFormatterHelper::writeFormatters(
|
||||
const QHash<QString, QString> configuration) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Write configuration" << configuration;
|
||||
|
||||
QString fileName = QString("%1/awesomewidgets/formatters/formatters.ini")
|
||||
.arg(QStandardPaths::writableLocation(
|
||||
QStandardPaths::GenericDataLocation));
|
||||
@ -101,16 +114,6 @@ bool AWFormatterHelper::writeFormatters(const QVariantMap configuration) const
|
||||
}
|
||||
|
||||
|
||||
QList<AbstractExtItem *> AWFormatterHelper::items() const
|
||||
{
|
||||
QList<AbstractExtItem *> converted;
|
||||
for (auto item : m_formattersClasses.values())
|
||||
converted.append(item);
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
|
||||
AWFormatterHelper::FormatterClass
|
||||
AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
||||
{
|
||||
@ -121,6 +124,8 @@ AWFormatterHelper::defineFormatterClass(const QString stringType) const
|
||||
formatter = FormatterClass::DateTime;
|
||||
else if (stringType == QString("Float"))
|
||||
formatter = FormatterClass::Float;
|
||||
else if (stringType == QString("NoFormat"))
|
||||
;
|
||||
else if (stringType == QString("Script"))
|
||||
formatter = FormatterClass::Script;
|
||||
else
|
||||
|
@ -34,11 +34,11 @@ public:
|
||||
explicit AWFormatterHelper(QWidget *parent = nullptr);
|
||||
virtual ~AWFormatterHelper();
|
||||
QString convert(const QVariant &value, const QString name) const;
|
||||
Q_INVOKABLE QStringList definedFormatters() const;
|
||||
Q_INVOKABLE QVariantMap getFormatters() const;
|
||||
Q_INVOKABLE QStringList knownFormatters() const;
|
||||
Q_INVOKABLE bool writeFormatters(const QVariantMap configuration) const;
|
||||
QStringList definedFormatters() const;
|
||||
QHash<QString, QString> getFormatters() const;
|
||||
QList<AbstractExtItem *> items() const;
|
||||
QStringList knownFormatters() const;
|
||||
bool writeFormatters(const QHash<QString, QString> configuration) const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
|
@ -194,14 +194,12 @@ QString AWKeyOperations::infoByKey(QString key) const
|
||||
else if (key.startsWith(QString("custom")))
|
||||
return extScripts->itemByTag(key, QString("custom"))->uniq();
|
||||
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("disk")]
|
||||
[key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||
else if (key.contains(QRegExp(
|
||||
QString("^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)"))))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("mount")]
|
||||
[key
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"mount")][key
|
||||
.remove(QRegExp(QString(
|
||||
"^hdd([0-9]|mb|gb|freemb|freegb|totmb|totgb)")))
|
||||
.toInt()]);
|
||||
@ -209,9 +207,8 @@ QString AWKeyOperations::infoByKey(QString key) const
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("hdd")][key.remove(QString("hddtemp")).toInt()]);
|
||||
else if (key.contains(QRegExp(QString("^(down|up)[0-9]"))))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("net")]
|
||||
[key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
else if (key.startsWith(QString("pkgcount")))
|
||||
return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq();
|
||||
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
||||
|
@ -156,22 +156,22 @@ QString DPAdds::toolTipImage(const int desktop) const
|
||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||
[&toolTipScene, &screen](WindowData data) {
|
||||
QPixmap desktop = screen->grabWindow(data.id);
|
||||
toolTipScene->addPixmap(desktop)->setOffset(
|
||||
data.rect.left(), data.rect.top());
|
||||
toolTipScene->addPixmap(desktop)
|
||||
->setOffset(data.rect.left(), data.rect.top());
|
||||
});
|
||||
} else if (m_tooltipType == QString("windows")) {
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
std::for_each(info.desktopsData.cbegin(), info.desktopsData.cend(),
|
||||
[&toolTipScene, &screen](WindowData data) {
|
||||
QPixmap desktop = screen->grabWindow(data.id);
|
||||
toolTipScene->addPixmap(desktop)->setOffset(
|
||||
data.rect.left(), data.rect.top());
|
||||
toolTipScene->addPixmap(desktop)
|
||||
->setOffset(data.rect.left(), data.rect.top());
|
||||
});
|
||||
std::for_each(info.windowsData.cbegin(), info.windowsData.cend(),
|
||||
[&toolTipScene, &screen](WindowData data) {
|
||||
QPixmap window = screen->grabWindow(data.id);
|
||||
toolTipScene->addPixmap(window)->setOffset(
|
||||
data.rect.left(), data.rect.top());
|
||||
toolTipScene->addPixmap(window)
|
||||
->setOffset(data.rect.left(), data.rect.top());
|
||||
});
|
||||
}
|
||||
|
||||
@ -232,8 +232,8 @@ QString DPAdds::valueByKey(const QString key, int desktop) const
|
||||
.arg(currentMark, m_mark.count(), QLatin1Char(' '))
|
||||
.replace(QString(" "), QString(" "));
|
||||
else if (key == QString("name"))
|
||||
return KWindowSystem::desktopName(desktop).replace(QString(" "),
|
||||
QString(" "));
|
||||
return KWindowSystem::desktopName(desktop)
|
||||
.replace(QString(" "), QString(" "));
|
||||
else if (key == QString("number"))
|
||||
return QString::number(desktop);
|
||||
else if (key == QString("total"))
|
||||
|
@ -125,8 +125,8 @@ void ExtendedSysMon::readConfiguration()
|
||||
|
||||
settings.beginGroup(QString("Configuration"));
|
||||
rawConfig[QString("ACPIPATH")]
|
||||
= settings
|
||||
.value(QString("ACPIPATH"), QString("/sys/class/power_supply/"))
|
||||
= settings.value(QString("ACPIPATH"),
|
||||
QString("/sys/class/power_supply/"))
|
||||
.toString();
|
||||
rawConfig[QString("GPUDEV")]
|
||||
= settings.value(QString("GPUDEV"), QString("auto")).toString();
|
||||
|
Loading…
Reference in New Issue
Block a user