From 0f4bbbfba15ccab4ab0ca9a640e91b1aa274c772 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Wed, 12 Nov 2014 05:16:05 +0300 Subject: [PATCH] some intermediate commit --- sources/awesome-widget/awesome-widget.cpp | 3 + sources/awesome-widget/graphicalitem.cpp | 269 ++++++++++++++++++ sources/awesome-widget/graphicalitem.h | 70 +++++ .../plasma_applet_awesome-widget.notifyrc | 5 + sources/desktop-panel/desktop-panel.cpp | 3 +- sources/ext-sysmon/extscript.h | 2 + 6 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 sources/awesome-widget/graphicalitem.cpp create mode 100644 sources/awesome-widget/graphicalitem.h diff --git a/sources/awesome-widget/awesome-widget.cpp b/sources/awesome-widget/awesome-widget.cpp index 2378a42..ce4a6b5 100644 --- a/sources/awesome-widget/awesome-widget.cpp +++ b/sources/awesome-widget/awesome-widget.cpp @@ -35,6 +35,7 @@ #include #include "customlabel.h" +#include "graphicalitem.h" #include #include #include "version.h" @@ -58,6 +59,8 @@ AwesomeWidget::AwesomeWidget(QObject *parent, const QVariantList &args) // text format init formatLine.append(QString("")); formatLine.append(QString("")); + GraphicalItem *item = new GraphicalItem(this, QString("test"), QString("${cpu;255,0,0,255;0,255,0,255;2;-1;300;500}"), true); + qDebug() << item->getImage(75.0); } diff --git a/sources/awesome-widget/graphicalitem.cpp b/sources/awesome-widget/graphicalitem.cpp new file mode 100644 index 0000000..c7efb5c --- /dev/null +++ b/sources/awesome-widget/graphicalitem.cpp @@ -0,0 +1,269 @@ +/*************************************************************************** + * 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 +#include +#include +#include +#include +#include + +#include + + +GraphicalItem::GraphicalItem(QObject *wid, const QString assignName, const QString tag, const bool debugCmd) + : QObject(wid), + name(assignName), + debug(debugCmd) +{ + if (debug) qDebug() << PDEBUG << ":" << "Name" << name; + parseTag(tag); +} + + +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 + QPainterPath ppath; + 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 Ring: + QGraphicsEllipseItem *circle; + pen.setWidth(1.0); + // inactive + pen.setColor(inactiveColor); + circle = scene->addEllipse(0.0, 0.0, width, height, pen, QBrush(inactiveColor, Qt::SolidPattern)); + // 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); + // null + pen.setColor(QColor(255, 255, 255, 0)); + ppath.addEllipse(0.16 * width, 0.16 * height, 0.66 * width, 0.66 * height); + scene->setSelectionArea(ppath); + scene->clearSelection(); +// scene->addPath(ppath, pen, QBrush(QColor(255,255,255,0), Qt::SolidPattern)); +// pen.setColor(QColor(255, 255, 255, 0)); +// scene->addEllipse(0.16 * width, 0.16 * height, 0.66 * width, 0.66 * height, pen, QBrush(QColor(255,255,255,255), Qt::SolidPattern)); +// scene->addEllipse(0.16 * width, 0.16 * height, 0.66 * width, 0.66 * height, pen, QBrush(QColor(255,255,255,0), Qt::SolidPattern)); + // 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("").arg(QString(byteArray.toBase64())); + delete view; + delete scene; + + return url; +} + + +QString GraphicalItem::getName() +{ + if (debug) qDebug() << PDEBUG; + + return name; +} + + +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; +} + + +QList GraphicalItem::parseColor(const QString stringColor) +{ + if (debug) qDebug() << PDEBUG; + + QList color; + color.append(0); + color.append(0); + color.append(0); + color.append(0); + + QStringList colors = stringColor.split(QChar(',')); + for (int i=0; i 0) + bar = parsedTag[0]; + if (parsedTag.count() > 1) { + QList color = parseColor(parsedTag[1]); + activeColor = QColor(color[0], color[1], color[2], color[3]); + } + if (parsedTag.count() > 2) { + QList color = parseColor(parsedTag[2]); + inactiveColor = QColor(color[0], color[1], color[2], color[3]); + } + if (parsedTag.count() > 3) + switch(parsedTag[3].toInt()) { + case Vertical: + type = Vertical; + break; + case Ring: + type = Ring; + break; + default: + type = Horizontal; + break; + } + if (parsedTag.count() > 4) + switch (parsedTag[4].toInt()) { + case RightToLeft: + direction = RightToLeft; + break; + default: + direction = LeftToRight; + break; + } + if (parsedTag.count() > 5) + height = parsedTag[5].toInt(); + if (parsedTag.count() > 6) + width = parsedTag[6].toInt(); + + 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"); + + if (debug) qDebug() << PDEBUG << ":" << "Bar" << bar; + if (debug) qDebug() << PDEBUG << ":" << "Active color" << activeColor; + if (debug) qDebug() << PDEBUG << ":" << "Inactive color" << inactiveColor; + if (debug) qDebug() << PDEBUG << ":" << "Type" << type; + if (debug) qDebug() << PDEBUG << ":" << "Direction" << direction; + if (debug) qDebug() << PDEBUG << ":" << "Size" << height << width; +} diff --git a/sources/awesome-widget/graphicalitem.h b/sources/awesome-widget/graphicalitem.h new file mode 100644 index 0000000..c096107 --- /dev/null +++ b/sources/awesome-widget/graphicalitem.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * 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 +#include + + +class GraphicalItem : public QObject +{ + Q_OBJECT + +public: + enum Direction { + RightToLeft = -1, + LeftToRight = 1 + }; + enum Type { + Horizontal = 0, + Vertical, + Ring + }; + + GraphicalItem(QObject *wid, const QString assignName, const QString tag, const bool debugCmd = false); + ~GraphicalItem(); + QString getImage(const float value); + QString getName(); + QString getBar(); + QColor getActiveColor(); + QColor getInactiveColor(); + Type getType(); + Direction getDirection(); + int getHeight(); + int getWidth(); + +public slots: + void parseTag(const QString tag); + +private: + QList parseColor(const QString stringColor); + QString name; + bool debug; + // properties + QString bar = QString("cpu"); + QColor activeColor = QColor(QString("#ffffff")); + QColor inactiveColor = QColor(QString("#000000")); + Type type = Horizontal; + Direction direction; + int height = 100; + int width = 100; +}; + + +#endif /* GRAPHICALITEM_H */ diff --git a/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc b/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc index 676cc62..5cca673 100644 --- a/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc +++ b/sources/awesome-widget/plasma_applet_awesome-widget.notifyrc @@ -7,3 +7,8 @@ Comment=Awesome widget information Name=System information Comment=System information Action=Popup + +[Event/tag] +Name=Tag information +Comment=Tag information +Action=Popup diff --git a/sources/desktop-panel/desktop-panel.cpp b/sources/desktop-panel/desktop-panel.cpp index 1d5ebbc..497563e 100644 --- a/sources/desktop-panel/desktop-panel.cpp +++ b/sources/desktop-panel/desktop-panel.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -52,6 +51,7 @@ CustomPlasmaLabel::CustomPlasmaLabel(DesktopPanel *wid, const int num, const boo CustomPlasmaLabel::~CustomPlasmaLabel() { + if (debug) qDebug() << PDEBUG; } @@ -111,6 +111,7 @@ DesktopPanel::DesktopPanel(QObject *parent, const QVariantList &args) DesktopPanel::~DesktopPanel() { + if (debug) qDebug() << PDEBUG; } diff --git a/sources/ext-sysmon/extscript.h b/sources/ext-sysmon/extscript.h index 77a54c8..b24d3a5 100644 --- a/sources/ext-sysmon/extscript.h +++ b/sources/ext-sysmon/extscript.h @@ -24,6 +24,8 @@ class ExtScript : public QObject { + Q_OBJECT + public: enum Redirect { stdout2stderr = -1,