mirror of
				https://github.com/arcan1s/awesome-widgets.git
				synced 2025-11-03 22:33:42 +00:00 
			
		
		
		
	implement grapicalitem settings
This commit is contained in:
		@ -41,9 +41,9 @@
 | 
			
		||||
      <property name="geometry">
 | 
			
		||||
       <rect>
 | 
			
		||||
        <x>0</x>
 | 
			
		||||
        <y>-126</y>
 | 
			
		||||
        <y>-225</y>
 | 
			
		||||
        <width>677</width>
 | 
			
		||||
        <height>702</height>
 | 
			
		||||
        <height>801</height>
 | 
			
		||||
       </rect>
 | 
			
		||||
      </property>
 | 
			
		||||
      <layout class="QVBoxLayout" name="verticalLayout_8">
 | 
			
		||||
@ -74,6 +74,9 @@
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Custom time format</string>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
@ -96,9 +99,6 @@ $m - minutes w\o zero
 | 
			
		||||
$ss - seconds
 | 
			
		||||
$s - seconds w\o zero</string>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
@ -116,6 +116,9 @@ $s - seconds w\o zero</string>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Custom uptime format</string>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
@ -128,9 +131,6 @@ $h - uptime hours without zero
 | 
			
		||||
$mm - uptime minutes
 | 
			
		||||
$m - uptime minutes without zero</string>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
@ -148,6 +148,9 @@ $m - uptime minutes without zero</string>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Temperature units</string>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
@ -376,6 +379,9 @@ $m - uptime minutes without zero</string>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>AC online tag</string>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
@ -386,9 +392,6 @@ $m - uptime minutes without zero</string>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string/>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
@ -406,6 +409,9 @@ $m - uptime minutes without zero</string>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>AC offline tag</string>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
@ -416,13 +422,57 @@ $m - uptime minutes without zero</string>
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string/>
 | 
			
		||||
           </property>
 | 
			
		||||
           <property name="alignment">
 | 
			
		||||
            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <layout class="QVBoxLayout" name="layout_bars">
 | 
			
		||||
         <item>
 | 
			
		||||
          <layout class="QHBoxLayout" name="layout_barsAdd">
 | 
			
		||||
           <item>
 | 
			
		||||
            <widget class="QLabel" name="label_bars">
 | 
			
		||||
             <property name="minimumSize">
 | 
			
		||||
              <size>
 | 
			
		||||
               <width>200</width>
 | 
			
		||||
               <height>0</height>
 | 
			
		||||
              </size>
 | 
			
		||||
             </property>
 | 
			
		||||
             <property name="text">
 | 
			
		||||
              <string>Bars</string>
 | 
			
		||||
             </property>
 | 
			
		||||
             <property name="alignment">
 | 
			
		||||
              <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
             </property>
 | 
			
		||||
            </widget>
 | 
			
		||||
           </item>
 | 
			
		||||
           <item>
 | 
			
		||||
            <spacer name="spacer_bars">
 | 
			
		||||
             <property name="orientation">
 | 
			
		||||
              <enum>Qt::Horizontal</enum>
 | 
			
		||||
             </property>
 | 
			
		||||
             <property name="sizeHint" stdset="0">
 | 
			
		||||
              <size>
 | 
			
		||||
               <width>40</width>
 | 
			
		||||
               <height>20</height>
 | 
			
		||||
              </size>
 | 
			
		||||
             </property>
 | 
			
		||||
            </spacer>
 | 
			
		||||
           </item>
 | 
			
		||||
           <item>
 | 
			
		||||
            <widget class="QPushButton" name="pushButton_bars">
 | 
			
		||||
             <property name="text">
 | 
			
		||||
              <string>Add</string>
 | 
			
		||||
             </property>
 | 
			
		||||
            </widget>
 | 
			
		||||
           </item>
 | 
			
		||||
          </layout>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <widget class="QListWidget" name="listWidget_bars"/>
 | 
			
		||||
         </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <widget class="QCheckBox" name="checkBox_updates">
 | 
			
		||||
         <property name="text">
 | 
			
		||||
 | 
			
		||||
@ -429,7 +429,7 @@ void AwesomeWidget::getGraphicalItems()
 | 
			
		||||
            if (names.contains(files[j])) continue;
 | 
			
		||||
            if (debug) qDebug() << PDEBUG << ":" << "Found file" << files[j] << "in" << dirs[i];
 | 
			
		||||
            names.append(files[j]);
 | 
			
		||||
            GraphicalItem *item = new GraphicalItem(files[j], dirs, debug);
 | 
			
		||||
            GraphicalItem *item = new GraphicalItem(0, files[j], dirs, debug);
 | 
			
		||||
            graphicalItems[item->getName() + item->getBar()] = item;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -79,10 +79,12 @@ private slots:
 | 
			
		||||
    void reinit();
 | 
			
		||||
    void replyRecieved(QNetworkReply *reply);
 | 
			
		||||
    // configuration interface
 | 
			
		||||
    void addBar();
 | 
			
		||||
    void addCustomScript();
 | 
			
		||||
    void addNewPkgCommand(QTableWidgetItem *item);
 | 
			
		||||
    void contextMenuCustomCommand(const QPoint pos);
 | 
			
		||||
    void contextMenuPkgCommand(const QPoint pos);
 | 
			
		||||
    void editBar(QListWidgetItem *item);
 | 
			
		||||
    void editCustomCommand(const int row, const int column);
 | 
			
		||||
    void editFanItem(QListWidgetItem *item);
 | 
			
		||||
    void editHddItem(QListWidgetItem *item);
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,7 @@
 | 
			
		||||
#include <QTextCodec>
 | 
			
		||||
 | 
			
		||||
#include <extscript.h>
 | 
			
		||||
#include <graphicalitem.h>
 | 
			
		||||
#include <fontdialog/fontdialog.h>
 | 
			
		||||
#include <pdebug/pdebug.h>
 | 
			
		||||
#include <task/taskadds.h>
 | 
			
		||||
@ -297,6 +298,9 @@ void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent)
 | 
			
		||||
                Qt::MatchFixedString));
 | 
			
		||||
    uiAdvancedConfig.lineEdit_acOnline->setText(configuration[QString("acOnline")]);
 | 
			
		||||
    uiAdvancedConfig.lineEdit_acOffline->setText(configuration[QString("acOffline")]);
 | 
			
		||||
    uiAdvancedConfig.listWidget_bars->clear();
 | 
			
		||||
    for (int i=0; i<graphicalItems.keys().count(); i++)
 | 
			
		||||
        uiAdvancedConfig.listWidget_bars->addItem(new QListWidgetItem(graphicalItems.keys()[i]));
 | 
			
		||||
    if (configuration[QString("checkUpdates")].toInt() == 0)
 | 
			
		||||
        uiAdvancedConfig.checkBox_updates->setCheckState(Qt::Unchecked);
 | 
			
		||||
    else
 | 
			
		||||
@ -473,6 +477,8 @@ void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent)
 | 
			
		||||
            this, SLOT(editMountItem(QListWidgetItem *)));
 | 
			
		||||
    connect(uiAdvancedConfig.listWidget_tempDevice, SIGNAL(itemActivated(QListWidgetItem *)),
 | 
			
		||||
            this, SLOT(editTempItem(QListWidgetItem *)));
 | 
			
		||||
    connect(uiAdvancedConfig.listWidget_bars, SIGNAL(itemActivated(QListWidgetItem *)),
 | 
			
		||||
            this, SLOT(editBar(QListWidgetItem *)));
 | 
			
		||||
    connect(uiDEConfig.tableWidget_customCommand, SIGNAL(cellDoubleClicked(int, int)),
 | 
			
		||||
            this, SLOT(editCustomCommand(int, int)));
 | 
			
		||||
    connect(uiDEConfig.tableWidget_customCommand, SIGNAL(customContextMenuRequested(QPoint)),
 | 
			
		||||
@ -481,6 +487,7 @@ void AwesomeWidget::createConfigurationInterface(KConfigDialog *parent)
 | 
			
		||||
            this, SLOT(addNewPkgCommand(QTableWidgetItem *)));
 | 
			
		||||
    connect(uiDEConfig.tableWidget_pkgCommand, SIGNAL(customContextMenuRequested(QPoint)),
 | 
			
		||||
            this, SLOT(contextMenuPkgCommand(QPoint)));
 | 
			
		||||
    connect(uiAdvancedConfig.pushButton_bars, SIGNAL(clicked(bool)), this, SLOT(addBar()));
 | 
			
		||||
    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()));
 | 
			
		||||
@ -737,6 +744,41 @@ void AwesomeWidget::configChanged()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AwesomeWidget::addBar()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    int number = 0;
 | 
			
		||||
    while (true) {
 | 
			
		||||
        bool exit = true;
 | 
			
		||||
        for (int i=0; i<graphicalItems.keys().count(); i++)
 | 
			
		||||
            if (graphicalItems[graphicalItems.keys()[i]]->getName() == QString("bar%1").arg(number)) {
 | 
			
		||||
                number++;
 | 
			
		||||
                exit = false;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        if (exit) break;
 | 
			
		||||
    }
 | 
			
		||||
    QStringList dirs = KGlobal::dirs()->findDirs("data", "plasma_applet_awesome-widget/desktops");
 | 
			
		||||
    bool ok;
 | 
			
		||||
    QString name = QInputDialog::getText(0, i18n("Enter file name"),
 | 
			
		||||
                                         i18n("File name"), QLineEdit::Normal,
 | 
			
		||||
                                         QString(""), &ok);
 | 
			
		||||
    if ((!ok) || (name.isEmpty())) return;
 | 
			
		||||
    QStringList bars;
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("cpu(?!cl).*")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("gpu")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("mem")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("swap")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("hdd[0-9].*")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("bat.*")))));
 | 
			
		||||
 | 
			
		||||
    GraphicalItem *item = new GraphicalItem(0, name, dirs, debug);
 | 
			
		||||
    item->setName(QString("bar%1").arg(number));
 | 
			
		||||
    item->showConfiguration(bars);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AwesomeWidget::addCustomScript()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
@ -842,6 +884,22 @@ void AwesomeWidget::contextMenuPkgCommand(const QPoint pos)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AwesomeWidget::editBar(QListWidgetItem *item)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    QStringList bars;
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("cpu(?!cl).*")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("gpu$")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("mem$")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("swap$")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("hdd[0-9].*")))));
 | 
			
		||||
    bars.append(keys.filter((QRegExp(QString("bat.*")))));
 | 
			
		||||
 | 
			
		||||
    graphicalItems[item->text()]->showConfiguration(bars);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AwesomeWidget::editCustomCommand(const int row, const int column)
 | 
			
		||||
{
 | 
			
		||||
    Q_UNUSED(column);
 | 
			
		||||
 | 
			
		||||
@ -16,8 +16,10 @@
 | 
			
		||||
 ***************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "graphicalitem.h"
 | 
			
		||||
#include "ui_graphicalitem.h"
 | 
			
		||||
 | 
			
		||||
#include <QBuffer>
 | 
			
		||||
#include <QColorDialog>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QGraphicsEllipseItem>
 | 
			
		||||
@ -28,18 +30,26 @@
 | 
			
		||||
#include <pdebug/pdebug.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GraphicalItem::GraphicalItem(const QString desktopName, const QStringList directories, const bool debugCmd)
 | 
			
		||||
    : fileName(desktopName),
 | 
			
		||||
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, const QStringList directories, const bool debugCmd)
 | 
			
		||||
    : QDialog(parent),
 | 
			
		||||
      fileName(desktopName),
 | 
			
		||||
      dirs(directories),
 | 
			
		||||
      debug(debugCmd)
 | 
			
		||||
      debug(debugCmd),
 | 
			
		||||
      ui(new Ui::GraphicalItem)
 | 
			
		||||
{
 | 
			
		||||
    readConfiguration();
 | 
			
		||||
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    connect(ui->pushButton_activeColor, SIGNAL(clicked()), this, SLOT(changeColor()));
 | 
			
		||||
    connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this, SLOT(changeColor()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GraphicalItem::~GraphicalItem()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -321,6 +331,47 @@ void GraphicalItem::readConfiguration()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::showConfiguration(const QStringList tags)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    ui->label_nameValue->setText(_name);
 | 
			
		||||
    ui->lineEdit_comment->setText(_comment);
 | 
			
		||||
    ui->comboBox_value->addItems(tags);
 | 
			
		||||
    ui->comboBox_value->addItem(_bar);
 | 
			
		||||
    ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count()-1);
 | 
			
		||||
    ui->pushButton_activeColor->setText(QString("%1,%2,%3,%4")
 | 
			
		||||
                                        .arg(_activeColor.red()).arg(_activeColor.green())
 | 
			
		||||
                                        .arg(_activeColor.blue()).arg(_activeColor.alpha()));
 | 
			
		||||
    ui->pushButton_inactiveColor->setText(QString("%1,%2,%3,%4")
 | 
			
		||||
                                          .arg(_inactiveColor.red()).arg(_inactiveColor.green())
 | 
			
		||||
                                          .arg(_inactiveColor.blue()).arg(_inactiveColor.alpha()));
 | 
			
		||||
    ui->comboBox_type->setCurrentIndex((int)_type);
 | 
			
		||||
    ui->comboBox_direction->setCurrentIndex((int)_direction);
 | 
			
		||||
    ui->spinBox_height->setValue(_height);
 | 
			
		||||
    ui->spinBox_width->setValue(_width);
 | 
			
		||||
 | 
			
		||||
    int ret = exec();
 | 
			
		||||
    if (ret == 0) {
 | 
			
		||||
        QStringList colorText;
 | 
			
		||||
        setName(ui->label_nameValue->text());
 | 
			
		||||
        setComment(ui->label_comment->text());
 | 
			
		||||
        setBar(ui->comboBox_value->currentText());
 | 
			
		||||
        colorText = ui->pushButton_activeColor->text().split(QChar(','));
 | 
			
		||||
        setActiveColor(QColor(colorText[0].toInt(), colorText[1].toInt(),
 | 
			
		||||
                              colorText[2].toInt(), colorText[3].toInt()));
 | 
			
		||||
        colorText = ui->pushButton_inactiveColor->text().split(QChar(','));
 | 
			
		||||
        setInactiveColor(QColor(colorText[0].toInt(), colorText[1].toInt(),
 | 
			
		||||
                                colorText[2].toInt(), colorText[3].toInt()));
 | 
			
		||||
        setType(ui->comboBox_type->currentText());
 | 
			
		||||
        setDirection(ui->comboBox_direction->currentText());
 | 
			
		||||
        setHeight(ui->spinBox_height->value());
 | 
			
		||||
        setWidth(ui->spinBox_width->value());
 | 
			
		||||
        writeConfiguration();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::tryDelete()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
@ -376,3 +427,22 @@ void GraphicalItem::writeConfiguration()
 | 
			
		||||
    settings.endGroup();
 | 
			
		||||
    settings.sync();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::changeColor()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    QStringList colorText = ((QPushButton *)sender())->text().split(QChar(','));
 | 
			
		||||
    QColor color = QColor(colorText[0].toInt(), colorText[1].toInt(),
 | 
			
		||||
                          colorText[2].toInt(), colorText[3].toInt());
 | 
			
		||||
    QColor newColor = QColorDialog::getColor(color, 0, i18n("Select color"),
 | 
			
		||||
                                             QColorDialog::ShowAlphaChannel);
 | 
			
		||||
 | 
			
		||||
    colorText.clear();
 | 
			
		||||
    colorText.append(QString("%1").arg(newColor.red()));
 | 
			
		||||
    colorText.append(QString("%1").arg(newColor.green()));
 | 
			
		||||
    colorText.append(QString("%1").arg(newColor.blue()));
 | 
			
		||||
    colorText.append(QString("%1").arg(newColor.alpha()));
 | 
			
		||||
    ((QPushButton *)sender())->setText(colorText.join(QChar(',')));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -19,16 +19,19 @@
 | 
			
		||||
#define GRAPHICALITEM_H
 | 
			
		||||
 | 
			
		||||
#include <QColor>
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class GraphicalItem;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class GraphicalItem : public QObject
 | 
			
		||||
class GraphicalItem : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    enum Direction {
 | 
			
		||||
        RightToLeft = -1,
 | 
			
		||||
        RightToLeft = 0,
 | 
			
		||||
        LeftToRight = 1
 | 
			
		||||
    };
 | 
			
		||||
    enum Type {
 | 
			
		||||
@ -37,7 +40,8 @@ public:
 | 
			
		||||
        Circle
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    GraphicalItem(const QString desktopName, const QStringList directories, const bool debugCmd = false);
 | 
			
		||||
    explicit GraphicalItem(QWidget *parent = 0, const QString desktopName = QString(),
 | 
			
		||||
                           const QStringList directories = QStringList(), const bool debugCmd = false);
 | 
			
		||||
    ~GraphicalItem();
 | 
			
		||||
    QString getImage(const float value);
 | 
			
		||||
    // get methods
 | 
			
		||||
@ -63,13 +67,18 @@ public:
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void readConfiguration();
 | 
			
		||||
    void showConfiguration(const QStringList tags = QStringList());
 | 
			
		||||
    void tryDelete();
 | 
			
		||||
    void writeConfiguration();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void changeColor();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QString fileName;
 | 
			
		||||
    QStringList dirs;
 | 
			
		||||
    bool debug;
 | 
			
		||||
    Ui::GraphicalItem *ui;
 | 
			
		||||
    // properties
 | 
			
		||||
    QString _name = QString("none");
 | 
			
		||||
    QString _comment = QString("empty");
 | 
			
		||||
@ -82,5 +91,4 @@ private:
 | 
			
		||||
    int _width = 100;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif /* GRAPHICALITEM_H */
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										287
									
								
								sources/awesome-widget/graphicalitem.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										287
									
								
								sources/awesome-widget/graphicalitem.ui
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,287 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>GraphicalItem</class>
 | 
			
		||||
 <widget class="QDialog" name="GraphicalItem">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>408</width>
 | 
			
		||||
    <height>329</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Configuration</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" name="verticalLayout">
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_name">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_name">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Name</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_nameValue">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string/>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_comment">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_comment">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Comment</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLineEdit" name="lineEdit_comment"/>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_value">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_value">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Value</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QComboBox" name="comboBox_value">
 | 
			
		||||
       <property name="editable">
 | 
			
		||||
        <bool>true</bool>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_activeColor">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_activeColor">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Active color</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="pushButton_activeColor">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string/>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_inactiveColor">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_inactiveColor">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Inactive color</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="pushButton_inactiveColor">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string/>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_type">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_type">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Type</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QComboBox" name="comboBox_type">
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string notr="true">Horizontal</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string notr="true">Vertical</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string notr="true">Circle</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_direction">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_direction">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Direction</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QComboBox" name="comboBox_direction">
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string notr="true">LeftToRight</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
       <item>
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string notr="true">RightToLeft</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </item>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_height">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_height">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Height</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QSpinBox" name="spinBox_height">
 | 
			
		||||
       <property name="maximum">
 | 
			
		||||
        <number>2000</number>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="singleStep">
 | 
			
		||||
        <number>25</number>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="layout_width">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QLabel" name="label_width">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Width</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="alignment">
 | 
			
		||||
        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QSpinBox" name="spinBox_width">
 | 
			
		||||
       <property name="maximum">
 | 
			
		||||
        <number>2000</number>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="singleStep">
 | 
			
		||||
        <number>25</number>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <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>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QDialogButtonBox" name="buttonBox">
 | 
			
		||||
     <property name="orientation">
 | 
			
		||||
      <enum>Qt::Horizontal</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="standardButtons">
 | 
			
		||||
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>accepted()</signal>
 | 
			
		||||
   <receiver>GraphicalItem</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>GraphicalItem</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>
 | 
			
		||||
							
								
								
									
										384
									
								
								sources/graphicalitem.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										384
									
								
								sources/graphicalitem.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,384 @@
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
 *   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 "graphicalitem.h"
 | 
			
		||||
 | 
			
		||||
#include <QBuffer>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QDir>
 | 
			
		||||
#include <QGraphicsEllipseItem>
 | 
			
		||||
#include <QGraphicsScene>
 | 
			
		||||
#include <QGraphicsView>
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
 | 
			
		||||
#include <pdebug/pdebug.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GraphicalItem::GraphicalItem(const QString desktopName, const QStringList directories, const bool debugCmd)
 | 
			
		||||
    : fileName(desktopName),
 | 
			
		||||
      dirs(directories),
 | 
			
		||||
      debug(debugCmd)
 | 
			
		||||
{
 | 
			
		||||
    readConfiguration();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GraphicalItem::~GraphicalItem()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QString GraphicalItem::getImage(const float value)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Value" << value;
 | 
			
		||||
    if (_bar == QString("none")) return QString("");
 | 
			
		||||
 | 
			
		||||
    float percent = value / 100.0;
 | 
			
		||||
    int scale[2] = {1, 1};
 | 
			
		||||
    QPen pen = QPen();
 | 
			
		||||
    QGraphicsScene *scene = new QGraphicsScene();
 | 
			
		||||
    scene->setBackgroundBrush(QBrush(Qt::NoBrush));
 | 
			
		||||
    QGraphicsView *view = new QGraphicsView(scene);
 | 
			
		||||
    view->setStyleSheet(QString("background: transparent"));
 | 
			
		||||
    view->setContentsMargins(0, 0, 0, 0);
 | 
			
		||||
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 | 
			
		||||
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 | 
			
		||||
    view->resize(_width + 5.0, _height + 5.0);
 | 
			
		||||
 | 
			
		||||
    // paint
 | 
			
		||||
    switch(_type) {
 | 
			
		||||
    case Vertical:
 | 
			
		||||
        pen.setWidth(_width);
 | 
			
		||||
        // inactive
 | 
			
		||||
        pen.setColor(_inactiveColor);
 | 
			
		||||
        scene->addLine(0.5 * _width, 0.0, 0.5 * _width, _height, pen);
 | 
			
		||||
        // active
 | 
			
		||||
        pen.setColor(_activeColor);
 | 
			
		||||
        scene->addLine(0.5 * _width, (1.0 - percent) * _height + 0.5 * _width, 0.5 * _width, _height + 0.5 * _width, pen);
 | 
			
		||||
        // scale
 | 
			
		||||
        scale[1] = (int)_direction;
 | 
			
		||||
        break;
 | 
			
		||||
    case Circle:
 | 
			
		||||
        QGraphicsEllipseItem *circle;
 | 
			
		||||
        pen.setWidth(1.0);
 | 
			
		||||
        // inactive
 | 
			
		||||
        pen.setColor(_inactiveColor);
 | 
			
		||||
        circle = scene->addEllipse(0.0, 0.0, _width, _height, pen, QBrush(_inactiveColor, Qt::SolidPattern));
 | 
			
		||||
        circle->setSpanAngle((1.0 - percent) * 360.0 * 16.0);
 | 
			
		||||
        circle->setStartAngle(180.0 * 16.0 - (1.0 - percent) * 360.0 * 16.0);
 | 
			
		||||
        // active
 | 
			
		||||
        pen.setColor(_activeColor);
 | 
			
		||||
        circle = scene->addEllipse(0.0, 0.0, _width, _height, pen, QBrush(_activeColor, Qt::SolidPattern));
 | 
			
		||||
        circle->setSpanAngle(percent * 360.0 * 16.0);
 | 
			
		||||
        circle->setStartAngle(180.0 * 16.0);
 | 
			
		||||
        // scale
 | 
			
		||||
        scale[0] = (int)_direction;
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        pen.setWidth(_height);
 | 
			
		||||
        // inactive
 | 
			
		||||
        pen.setColor(_inactiveColor);
 | 
			
		||||
        scene->addLine(0.0, 0.5 * _height, _width, 0.5 * _height, pen);
 | 
			
		||||
        // active
 | 
			
		||||
        pen.setColor(_activeColor);
 | 
			
		||||
        scene->addLine(-0.5 * _height, 0.5 * _height, percent * _width - 0.5 * _height, 0.5 * _height, pen);
 | 
			
		||||
        // scale
 | 
			
		||||
        scale[0] = (int)_direction;
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // convert
 | 
			
		||||
    QPixmap pixmap = QPixmap::grabWidget(view).transformed(QTransform().scale(scale[0], scale[1]));
 | 
			
		||||
    QByteArray byteArray;
 | 
			
		||||
    QBuffer buffer(&byteArray);
 | 
			
		||||
    pixmap.save(&buffer, "PNG");
 | 
			
		||||
    QString url = QString("<img src=\"data:image/png;base64,%1\"/>").arg(QString(byteArray.toBase64()));
 | 
			
		||||
    delete view;
 | 
			
		||||
    delete scene;
 | 
			
		||||
 | 
			
		||||
    return url;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QString GraphicalItem::getName()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QString GraphicalItem::getComment()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _comment;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QString GraphicalItem::getBar()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _bar;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QColor GraphicalItem::getActiveColor()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _activeColor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QColor GraphicalItem::getInactiveColor()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _inactiveColor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GraphicalItem::Type GraphicalItem::getType()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _type;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
GraphicalItem::Direction GraphicalItem::getDirection()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _direction;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int GraphicalItem::getHeight()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _height;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int GraphicalItem::getWidth()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    return _width;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setName(const QString name)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Name" << name;
 | 
			
		||||
 | 
			
		||||
    _name = name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setComment(const QString comment)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Comment" << comment;
 | 
			
		||||
 | 
			
		||||
    _comment = comment;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setBar(const QString bar)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Bar" << bar;
 | 
			
		||||
 | 
			
		||||
    _bar = bar;
 | 
			
		||||
    if ((!_bar.contains(QRegExp(QString("cpu(?!cl).*")))) &&
 | 
			
		||||
        (!_bar.contains(QRegExp(QString("gpu")))) &&
 | 
			
		||||
        (!_bar.contains(QRegExp(QString("mem")))) &&
 | 
			
		||||
        (!_bar.contains(QRegExp(QString("swap")))) &&
 | 
			
		||||
        (!_bar.contains(QRegExp(QString("hdd[0-9].*")))) &&
 | 
			
		||||
        (!_bar.contains(QRegExp(QString("bat.*")))))
 | 
			
		||||
        _bar = QString("none");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setActiveColor(const QColor color)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Color" << color;
 | 
			
		||||
 | 
			
		||||
    _activeColor = color;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setInactiveColor(const QColor color)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Color" << color;
 | 
			
		||||
 | 
			
		||||
    _inactiveColor = color;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setType(const QString type)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Type" << type;
 | 
			
		||||
 | 
			
		||||
    if (type == QString("Vertical"))
 | 
			
		||||
        _type = Vertical;
 | 
			
		||||
    else if (type == QString("Circle"))
 | 
			
		||||
        _type = Circle;
 | 
			
		||||
    else
 | 
			
		||||
        _type = Horizontal;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setDirection(const QString direction)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Direction" << direction;
 | 
			
		||||
 | 
			
		||||
    if (direction == QString("RightToLeft"))
 | 
			
		||||
        _direction = RightToLeft;
 | 
			
		||||
    else
 | 
			
		||||
        _direction = LeftToRight;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setHeight(const int height)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Height" << height;
 | 
			
		||||
 | 
			
		||||
    _height = height;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::setWidth(const int width)
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Width" << width;
 | 
			
		||||
 | 
			
		||||
    _width = width;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::readConfiguration()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    for (int i=dirs.count()-1; i>=0; i--) {
 | 
			
		||||
        if (!QDir(dirs[i]).entryList(QDir::Files).contains(fileName)) continue;
 | 
			
		||||
        QSettings settings(dirs[i] + QDir::separator() + fileName, QSettings::IniFormat);
 | 
			
		||||
        settings.beginGroup(QString("Desktop Entry"));
 | 
			
		||||
        QStringList childKeys = settings.childKeys();
 | 
			
		||||
        for (int i=0; i<childKeys.count(); i++) {
 | 
			
		||||
            if (childKeys[i] == QString("Name")) {
 | 
			
		||||
                setName(settings.value(childKeys[i]).toString());
 | 
			
		||||
            } else if (childKeys[i] == QString("Comment")) {
 | 
			
		||||
                setComment(settings.value(childKeys[i]).toString());
 | 
			
		||||
            } else if (childKeys[i] == QString("X-AW-Value")) {
 | 
			
		||||
                setBar(settings.value(childKeys[i]).toString());
 | 
			
		||||
            } else if (childKeys[i] == QString("X-AW-ActiveColor")) {
 | 
			
		||||
                QStringList color = settings.value(childKeys[i]).toString().split(QChar(','));
 | 
			
		||||
                setActiveColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt(), color[3].toInt()));
 | 
			
		||||
            } else if (childKeys[i] == QString("X-AW-InactiveColor")) {
 | 
			
		||||
                QStringList color = settings.value(childKeys[i]).toString().split(QChar(','));
 | 
			
		||||
                setInactiveColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt(), color[3].toInt()));
 | 
			
		||||
            } else if (childKeys[i] == QString("X-AW-Type")) {
 | 
			
		||||
                setType(settings.value(childKeys[i]).toString());
 | 
			
		||||
            } else if (childKeys[i] == QString("X-AW-Direction")) {
 | 
			
		||||
                setDirection(settings.value(childKeys[i]).toString());
 | 
			
		||||
            } else if (childKeys[i] == QString("X-AW-Height")) {
 | 
			
		||||
                setHeight(settings.value(childKeys[i]).toInt());
 | 
			
		||||
            } else if (childKeys[i] == QString("X-AW-Width")) {
 | 
			
		||||
                setWidth(settings.value(childKeys[i]).toInt());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        settings.endGroup();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::showConfiguration()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::tryDelete()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    for (int i=0; i<dirs.count(); i++)
 | 
			
		||||
        if (debug) qDebug() << PDEBUG << ":" << "Remove file" << fileName << QFile::remove(fileName);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void GraphicalItem::writeConfiguration()
 | 
			
		||||
{
 | 
			
		||||
    if (debug) qDebug() << PDEBUG;
 | 
			
		||||
 | 
			
		||||
    QSettings settings(dirs[0] + QDir::separator() + fileName, QSettings::IniFormat);
 | 
			
		||||
    if (debug) qDebug() << PDEBUG << ":" << "Configuration file" << settings.fileName();
 | 
			
		||||
    settings.beginGroup(QString("Desktop Entry"));
 | 
			
		||||
 | 
			
		||||
    QString strValue;
 | 
			
		||||
    settings.setValue(QString("Encoding"), QString("UTF-8"));
 | 
			
		||||
    settings.setValue(QString("Name"), _name);
 | 
			
		||||
    settings.setValue(QString("Comment"), _comment);
 | 
			
		||||
    settings.setValue(QString("X-AW-Value"), _bar);
 | 
			
		||||
    settings.setValue(QString("X-AW-ActiveColor"), QString("%1,%2,%3,%4")
 | 
			
		||||
                      .arg(_activeColor.red()).arg(_activeColor.green())
 | 
			
		||||
                      .arg(_activeColor.blue()).arg(_activeColor.alpha()));
 | 
			
		||||
    settings.setValue(QString("X-AW-InactiveColor"), QString("%1,%2,%3,%4")
 | 
			
		||||
                      .arg(_inactiveColor.red()).arg(_inactiveColor.green())
 | 
			
		||||
                      .arg(_inactiveColor.blue()).arg(_inactiveColor.alpha()));
 | 
			
		||||
    switch(_type) {
 | 
			
		||||
    case Vertical:
 | 
			
		||||
        strValue = QString("Vertical");
 | 
			
		||||
        break;
 | 
			
		||||
    case Circle:
 | 
			
		||||
        strValue = QString("Circle");
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        strValue = QString("Horizontal");
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    settings.setValue(QString("X-AW-Type"), strValue);
 | 
			
		||||
    switch (_direction) {
 | 
			
		||||
    case RightToLeft:
 | 
			
		||||
        strValue = QString("RightToLeft");
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        strValue = QString("LeftToRight");
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    settings.setValue(QString("X-AW-Direction"), strValue);
 | 
			
		||||
    settings.setValue(QString("X-AW-Height"), _height);
 | 
			
		||||
    settings.setValue(QString("X-AW-Width"), _width);
 | 
			
		||||
 | 
			
		||||
    settings.endGroup();
 | 
			
		||||
    settings.sync();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										87
									
								
								sources/graphicalitem.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								sources/graphicalitem.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,87 @@
 | 
			
		||||
/***************************************************************************
 | 
			
		||||
 *   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 GRAPHICALITEM_H
 | 
			
		||||
#define GRAPHICALITEM_H
 | 
			
		||||
 | 
			
		||||
#include <QColor>
 | 
			
		||||
#include <QObject>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class GraphicalItem : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    enum Direction {
 | 
			
		||||
        RightToLeft = -1,
 | 
			
		||||
        LeftToRight = 1
 | 
			
		||||
    };
 | 
			
		||||
    enum Type {
 | 
			
		||||
        Horizontal = 0,
 | 
			
		||||
        Vertical,
 | 
			
		||||
        Circle
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    GraphicalItem(const QString desktopName, const QStringList directories, const bool debugCmd = false);
 | 
			
		||||
    ~GraphicalItem();
 | 
			
		||||
    QString getImage(const float value);
 | 
			
		||||
    // get methods
 | 
			
		||||
    QString getName();
 | 
			
		||||
    QString getComment();
 | 
			
		||||
    QString getBar();
 | 
			
		||||
    QColor getActiveColor();
 | 
			
		||||
    QColor getInactiveColor();
 | 
			
		||||
    Type getType();
 | 
			
		||||
    Direction getDirection();
 | 
			
		||||
    int getHeight();
 | 
			
		||||
    int getWidth();
 | 
			
		||||
    // set methods
 | 
			
		||||
    void setName(const QString name);
 | 
			
		||||
    void setComment(const QString comment);
 | 
			
		||||
    void setBar(const QString bar);
 | 
			
		||||
    void setActiveColor(const QColor color);
 | 
			
		||||
    void setInactiveColor(const QColor color);
 | 
			
		||||
    void setType(const QString type);
 | 
			
		||||
    void setDirection(const QString direction);
 | 
			
		||||
    void setHeight(const int height);
 | 
			
		||||
    void setWidth(const int width);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void readConfiguration();
 | 
			
		||||
    void showConfiguration();
 | 
			
		||||
    void tryDelete();
 | 
			
		||||
    void writeConfiguration();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QString fileName;
 | 
			
		||||
    QStringList dirs;
 | 
			
		||||
    bool debug;
 | 
			
		||||
    // properties
 | 
			
		||||
    QString _name = QString("none");
 | 
			
		||||
    QString _comment = QString("empty");
 | 
			
		||||
    QString _bar = QString("cpu");
 | 
			
		||||
    QColor _activeColor = QColor(255, 255, 255, 0);
 | 
			
		||||
    QColor _inactiveColor = QColor(255, 255, 255, 255);
 | 
			
		||||
    Type _type = Horizontal;
 | 
			
		||||
    Direction _direction = LeftToRight;
 | 
			
		||||
    int _height = 100;
 | 
			
		||||
    int _width = 100;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif /* GRAPHICALITEM_H */
 | 
			
		||||
		Reference in New Issue
	
	Block a user