move aw plugin to template-based system

bump graphicalitems to ApiVer 2 (add number property)
This commit is contained in:
arcan1s
2015-07-27 00:05:15 +03:00
parent c61a5ac092
commit 983b808247
12 changed files with 155 additions and 810 deletions

View File

@ -19,6 +19,8 @@
#include <QDebug>
#include <QHBoxLayout>
#include <QInputDialog>
#include <QLineEdit>
#include <pdebug/pdebug.h>
@ -42,6 +44,8 @@ AbstractExtItemAggregator::AbstractExtItemAggregator(QWidget *parent, const bool
connect(dialogButtons, SIGNAL(clicked(QAbstractButton *)),
this, SLOT(editItemButtonPressed(QAbstractButton *)));
connect(dialogButtons, SIGNAL(rejected()), dialog, SLOT(reject()));
connect(widgetDialog, SIGNAL(itemActivated(QListWidgetItem *)),
this, SLOT(editItemActivated(QListWidgetItem *)));
}
@ -53,6 +57,47 @@ AbstractExtItemAggregator::~AbstractExtItemAggregator()
}
QString AbstractExtItemAggregator::getName()
{
if (debug) qDebug() << PDEBUG;
bool ok;
QString name = QInputDialog::getText(this, tr("Enter file name"),
tr("File name"), QLineEdit::Normal,
QString(""), &ok);
if ((!ok) || (name.isEmpty())) return QString("");
if (!name.endsWith(QString(".desktop"))) name += QString(".desktop");
return name;
}
QVariant AbstractExtItemAggregator::configArgs() const
{
if (debug) qDebug() << PDEBUG;
return m_configArgs;
}
void AbstractExtItemAggregator::setConfigArgs(const QVariant _configArgs)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Configuration arguments" << _configArgs;
m_configArgs = _configArgs;
}
void AbstractExtItemAggregator::editItemActivated(QListWidgetItem *item)
{
Q_UNUSED(item)
if (debug) qDebug() << PDEBUG;
return editItem();
}
void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
{
if (debug) qDebug() << PDEBUG;
@ -61,7 +106,7 @@ void AbstractExtItemAggregator::editItemButtonPressed(QAbstractButton *button)
return copyItem();
else if (static_cast<QPushButton *>(button) == createButton)
return createItem();
else if (dynamic_cast<QPushButton *>(button) == deleteButton)
else if (static_cast<QPushButton *>(button) == deleteButton)
return deleteItem();
else if (dialogButtons->buttonRole(button) == QDialogButtonBox::AcceptRole)
return editItem();

View File

@ -29,9 +29,12 @@
class AbstractExtItemAggregator : public QWidget
{
Q_OBJECT
Q_PROPERTY(QVariant configArgs READ configArgs WRITE setConfigArgs)
public:
AbstractExtItemAggregator(QWidget *parent = nullptr, const bool debugCmd = false);
virtual ~AbstractExtItemAggregator();
QString getName();
// ui
QDialog *dialog = nullptr;
QListWidget *widgetDialog = nullptr;
@ -39,12 +42,18 @@ public:
QPushButton *copyButton = nullptr;
QPushButton *createButton = nullptr;
QPushButton *deleteButton = nullptr;
// get methods
QVariant configArgs() const;
// set methods
void setConfigArgs(const QVariant _configArgs);
private slots:
void editItemActivated(QListWidgetItem *item);
void editItemButtonPressed(QAbstractButton *button);
private:
bool debug;
QVariant m_configArgs;
// methods
virtual void copyItem() = 0;
virtual void createItem() = 0;

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=3

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=0

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=1

View File

@ -9,4 +9,5 @@ X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=1
X-AW-ApiVersion=2
X-AW-Number=2

View File

@ -20,8 +20,6 @@
#include <QDebug>
#include <QDir>
#include <QInputDialog>
#include <QLineEdit>
#include <QSettings>
#include <QStandardPaths>
@ -30,7 +28,8 @@
#include "abstractextitemaggregator.h"
template <class T> class ExtItemAggregator : public AbstractExtItemAggregator
template <class T>
class ExtItemAggregator : public AbstractExtItemAggregator
{
public:
explicit ExtItemAggregator(QWidget *parent, const QString type,
@ -49,20 +48,6 @@ public:
m_items.clear();
}
QString getName() const
{
if (debug) qDebug() << PDEBUG;
bool ok;
QString name = QInputDialog::getText(nullptr, tr("Enter file name"),
tr("File name"), QLineEdit::Normal,
QString(""), &ok);
if ((!ok) || (name.isEmpty())) return QString("");
if (!name.endsWith(QString(".desktop"))) name += QString(".desktop");
return name;
};
void editItems()
{
if (debug) qDebug() << PDEBUG;
@ -122,6 +107,7 @@ private:
bool debug;
QList<T *> m_items;
QString m_type;
// init method
QList<T *> getItems()
{
@ -167,6 +153,7 @@ private:
widgetDialog->addItem(item);
}
};
// methods
void copyItem()
{
@ -178,7 +165,7 @@ private:
if ((source == nullptr) || (fileName.isEmpty())) return;
T *newItem = source->copy(fileName, number);
if (newItem->showConfiguration() == 1) {
if (newItem->showConfiguration(configArgs()) == 1) {
initItems();
repaint();
}
@ -197,7 +184,7 @@ private:
T *newItem = new T(this, fileName, dirs, debug);
newItem->setNumber(number);
if (newItem->showConfiguration() == 1) {
if (newItem->showConfiguration(configArgs()) == 1) {
initItems();
repaint();
}
@ -223,7 +210,7 @@ private:
T *source = itemFromWidget();
if (source == nullptr) return;
if (source->showConfiguration() == 1) {
if (source->showConfiguration(configArgs()) == 1) {
initItems();
repaint();
}

View File

@ -377,8 +377,16 @@ void GraphicalItem::readConfiguration()
setStrDirection(settings.value(QString("X-AW-Direction"), strDirection()).toString());
setHeight(settings.value(QString("X-AW-Height"), m_height).toInt());
setWidth(settings.value(QString("X-AW-Width"), m_width).toInt());
// api == 2
if (apiVersion() < 2) setNumber(bar().remove(QString("bar")).toInt());
settings.endGroup();
}
// update for current API
if ((apiVersion() > 0) && (apiVersion() < AWGIAPI)) {
setApiVersion(AWGIAPI);
writeConfiguration();
}
}
@ -436,7 +444,6 @@ void GraphicalItem::writeConfiguration() const
if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
settings.beginGroup(QString("Desktop Entry"));
settings.setValue(QString("X-AW-ApiVersion"), m_apiVersion);
settings.setValue(QString("X-AW-Value"), m_bar);
settings.setValue(QString("X-AW-ActiveColor"), m_activeColor);
settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor);
@ -454,8 +461,8 @@ void GraphicalItem::changeColor()
{
if (debug) qDebug() << PDEBUG;
QColor color = stringToColor((dynamic_cast<QPushButton *>(sender()))->text());
QColor newColor = QColorDialog::getColor(color, 0, tr("Select color"),
QColor color = stringToColor((static_cast<QPushButton *>(sender()))->text());
QColor newColor = QColorDialog::getColor(color, this, tr("Select color"),
QColorDialog::ShowAlphaChannel);
if (!newColor.isValid()) return;
@ -464,7 +471,7 @@ void GraphicalItem::changeColor()
colorText.append(QString("%1").arg(newColor.green()));
colorText.append(QString("%1").arg(newColor.blue()));
colorText.append(QString("%1").arg(newColor.alpha()));
dynamic_cast<QPushButton *>(sender())->setText(colorText.join(QChar(',')));
static_cast<QPushButton *>(sender())->setText(colorText.join(QChar(',')));
}