create skel for aw

This commit is contained in:
arcan1s 2015-01-16 05:27:41 +03:00
parent 3e709f549d
commit cc7b7b5659
63 changed files with 1124 additions and 7 deletions

View File

@ -10,7 +10,7 @@ set (PROJECT_AUTHOR "Evgeniy Alekseev")
set (PROJECT_CONTACT "esalexeev@gmail.com")
set (PROJECT_LICENSE "GPLv3")
set (PROJECT_VERSION_MAJOR 2)
set (PROJECT_VERSION_MINOR 1)
set (PROJECT_VERSION_MINOR 2)
set (PROJECT_VERSION_PATCH 0)
set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
@ -38,5 +38,15 @@ configure_file (${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/ver
set (PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
add_subdirectory (ext-sysmon)
#add_subdirectory (awesome-widget)
#add_subdirectory (desktop-panel)
if (BUILD_KDE4)
add_subdirectory (awesome-widget-kde4)
add_subdirectory (desktop-panel-kde4)
else ()
add_subdirectory (awesome-widget-kf5)
endif ()
# translations
add_subdirectory (translations)
# aw bars desktops
set (AW_DESKTOPS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
install (DIRECTORY ${AW_DESKTOPS} DESTINATION ${DATA_INSTALL_DIR}/plasma_applet_awesome-widget)

View File

@ -7,8 +7,6 @@ message (STATUS "Subproject ${SUBPROJECT}")
find_package (KDE4 REQUIRED)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
add_subdirectory (po)
include (KDE4Defaults)
include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
@ -28,7 +26,6 @@ file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp ${PROJECT_TRDPARTY_DIR}/task/*.cpp
set (TASK_HEADER ${PROJECT_TRDPARTY_DIR}/task/task.h)
file (GLOB SUBPROJECT_UI *.ui ${PROJECT_TRDPARTY_DIR}/about/*.ui)
file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
set (SUBPROJECT_DESKTOPS ${CMAKE_CURRENT_SOURCE_DIR}/desktops)
# prepare
configure_file (${SUBPROJECT_DESKTOP_IN} ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP})
@ -43,4 +40,3 @@ target_link_libraries (${PLUGIN_NAME} ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS} ${K
install (TARGETS ${PLUGIN_NAME} DESTINATION ${PLUGIN_INSTALL_DIR})
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_DESKTOP} DESTINATION ${SERVICES_INSTALL_DIR})
install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME})
install (DIRECTORY ${SUBPROJECT_DESKTOPS} DESTINATION ${DATA_INSTALL_DIR}/${PLUGIN_NAME})

View File

@ -0,0 +1,16 @@
# set project name
set (SUBPROJECT plasma_applet_awesome-widget)
message (STATUS "Subproject ${SUBPROJECT}")
find_package (ECM 0.0.12 REQUIRED NO_MODULE)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
find_package (Qt5 REQUIRED COMPONENTS Core DBus Qml)
find_package (KF5 REQUIRED COMPONENTS I18n Notifications Plasma)
include (KDEInstallDirs)
include (KDECMakeSettings)
include (KDECompilerSettings)
add_subdirectory (plugin)
plasma_install_package (package org.kde.plasma.awesome-widget)

View File

@ -0,0 +1,29 @@
[Desktop Entry]
Encoding=UTF-8
Name=Awesome Widget
Comment=A minimalistic Plasmoid
Comment[en]=A minimalistic Plasmoid
Comment[es]=Un plasmoide minimalista
Comment[es]=Un script Plasmoïde minimaliste
Comment[pt_BR]=Um script Plasmoid
Comment[ru]=Минималистичный плазмоид
Comment[uk]=Мінімалістичний плазмоїд
X-KDE-ServiceTypes=Plasma/Applet
Type=Service
Icon=utilities-system-monitor
X-KDE-ServiceTypes=Plasma/Applet
X-Plasma-API=declarativeappletscript
X-Plasma-MainScript=ui/main.qml
X-Plasma-NotificationArea=true
X-Plasma-RemoteLocation=
X-KDE-PluginInfo-Author=Evgeniy Alekseev aka arcanis
X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=org.kde.plasma.awesome-widget
X-KDE-PluginInfo-Version=@PROJECT_VERSION@
X-KDE-PluginInfo-Website=http://arcanis.name/projects/awesome-widgets/
X-KDE-PluginInfo-Category=System Information
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3
X-KDE-PluginInfo-EnabledByDefault=true

View File

@ -0,0 +1,31 @@
set (PLUGIN_NAME awplugin)
add_definitions (${Qt5Core_DEFINITIONS})
set (Qt_INCLUDE ${Qt5Core_INCLUDE_DIRS}
${Qt5Qml_INCLUDE_DIRS})
set (Qt_LIBRARIES ${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES})
set (Kf5_INCLUDE ${I18n_INCLUDE_DIR}
${Notifications_INCLUDE_DIR})
set (Kf5_LIBRARIES KF5::I18n
KF5::Notifications)
include_directories (${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/../
${PROJECT_TRDPARTY_DIR}
${Qt_INCLUDE}
${Kf5_INCLUDE})
file (GLOB SUBPROJECT_SOURCE *.cpp)
file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
file (GLOB SUBPROJECT_UI *.ui)
qt5_wrap_ui (SUBPROJECT_UI_HEADER ${SUBPROJECT_UI})
add_library (${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE} ${SUBPROJECT_UI_HEADER})
target_link_libraries (${PLUGIN_NAME} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesome-widget)
install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/awesome-widget)
install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR})

View File

@ -0,0 +1,47 @@
/***************************************************************************
* 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 <KI18n/KLocalizedString>
#include <KNotifications/KNotification>
#include <QDebug>
#include <QInputDialog>
#include <QProcessEnvironment>
#include <QSettings>
#include <QStandardPaths>
#include <pdebug/pdebug.h>
#include "awadds.h"
#include "graphicalitem.h"
#include "version.h"
AWAdds::AWAdds(QObject *parent)
: QObject(parent)
{
// debug
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
debug = (debugEnv == QString("yes"));
}
AWAdds::~AWAdds()
{
if (debug) qDebug() << PDEBUG;
}

View 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 AWADDS_H
#define AWADDS_H
#include <QObject>
class AWAdds : public QObject
{
Q_OBJECT
public:
AWAdds(QObject *parent = 0);
~AWAdds();
private:
bool debug = false;
};
#endif /* AWADDS_H */

View File

@ -0,0 +1,36 @@
/***************************************************************************
* 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 "awesomewidget.h"
#include "awadds.h"
static QObject *aw_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return new AWAdds();
}
void AWPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.awesome-widget"));
qmlRegisterSingletonType<AWAdds>(uri, 1, 0, "AWAdds", aw_singletontype_provider);
}

View File

@ -0,0 +1,36 @@
/***************************************************************************
* 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 AWPLUGIN_H
#define AWPLUGIN_H
#include <QQmlExtensionPlugin>
class AWPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
void initializeEngine(QQmlEngine *engine, const char *uri);
void registerTypes(const char *uri);
};
#endif /* AWPLUGIN_H */

View File

@ -0,0 +1,470 @@
/***************************************************************************
* 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 "ui_graphicalitem.h"
#include <QBuffer>
#include <QColorDialog>
#include <QDebug>
#include <QDir>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QSettings>
#include <pdebug/pdebug.h>
GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName, const QStringList directories, const bool debugCmd)
: QDialog(parent),
fileName(desktopName),
dirs(directories),
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;
}
QString GraphicalItem::getImage(const float value)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Value" << value;
if (_bar == QString("none")) return QString("");
QColor active = stringToColor(_activeColor);
QColor inactive = stringToColor(_inactiveColor);
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->setFrameShape(QFrame::NoFrame);
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(inactive);
scene->addLine(0.5 * _width, -0.5 * _width, 0.5 * _width, (1.0 - percent) * _height - 0.5 * _width, pen);
// active
pen.setColor(active);
scene->addLine(0.5 * _width, (1.0 - percent) * _height + 0.5 * _width, 0.5 * _width, _height + 0.5 * _width, pen);
// scale
scale[1] = -2 * (int)_direction + 1;
break;
case Circle:
QGraphicsEllipseItem *circle;
pen.setWidth(1.0);
// inactive
pen.setColor(inactive);
circle = scene->addEllipse(0.0, 0.0, _width, _height, pen, QBrush(inactive, Qt::SolidPattern));
circle->setSpanAngle(- (1.0 - percent) * 360.0 * 16.0);
circle->setStartAngle(90.0 * 16.0 - percent * 360.0 * 16.0);
// active
pen.setColor(active);
circle = scene->addEllipse(0.0, 0.0, _width, _height, pen, QBrush(active, Qt::SolidPattern));
circle->setSpanAngle(- percent * 360.0 * 16.0);
circle->setStartAngle(90.0 * 16.0);
// scale
scale[0] = -2 *(int)_direction + 1;
break;
default:
pen.setWidth(_height);
// inactive
pen.setColor(inactive);
scene->addLine(percent * _width + 0.5 * _height, 0.5 * _height, _width + 0.5 * _height, 0.5 * _height, pen);
// active
pen.setColor(active);
scene->addLine(-0.5 * _height, 0.5 * _height, percent * _width - 0.5 * _height, 0.5 * _height, pen);
// scale
scale[0] = -2 * (int)_direction + 1;
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::getFileName()
{
if (debug) qDebug() << PDEBUG;
return fileName;
}
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;
}
QString GraphicalItem::getActiveColor()
{
if (debug) qDebug() << PDEBUG;
return _activeColor;
}
QString GraphicalItem::getInactiveColor()
{
if (debug) qDebug() << PDEBUG;
return _inactiveColor;
}
GraphicalItem::Type GraphicalItem::getType()
{
if (debug) qDebug() << PDEBUG;
return _type;
}
QString GraphicalItem::getStrType()
{
if (debug) qDebug() << PDEBUG;
QString value;
switch(_type) {
case Vertical:
value = QString("Vertical");
break;
case Circle:
value = QString("Circle");
break;
default:
value = QString("Horizontal");
break;
}\
return value;
}
GraphicalItem::Direction GraphicalItem::getDirection()
{
if (debug) qDebug() << PDEBUG;
return _direction;
}
QString GraphicalItem::getStrDirection()
{
if (debug) qDebug() << PDEBUG;
QString value;
switch (_direction) {
case RightToLeft:
value = QString("RightToLeft");
break;
default:
value = QString("LeftToRight");
break;
}
return value;
}
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 QString color)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << color;
_activeColor = color;
}
void GraphicalItem::setInactiveColor(const QString 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;
if (height <= 0) return;
_height = height;
}
void GraphicalItem::setWidth(const int width)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Width" << width;
if (width <= 0) return;
_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"));
setName(settings.value(QString("Name"), _name).toString());
setComment(settings.value(QString("Comment"), _comment).toString());
setBar(settings.value(QString("X-AW-Value"), _bar).toString());
setActiveColor(settings.value(QString("X-AW-ActiveColor"), _activeColor).toString());
setInactiveColor(settings.value(QString("X-AW-InactiveColor"), _inactiveColor).toString());
setType(settings.value(QString("X-AW-Type"), getStrType()).toString());
setDirection(settings.value(QString("X-AW-Direction"), getStrDirection()).toString());
setHeight(settings.value(QString("X-AW-Height"), QString::number(_height)).toInt());
setWidth(settings.value(QString("X-AW-Width"), QString::number(_width)).toInt());
settings.endGroup();
}
}
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(_activeColor);
ui->pushButton_inactiveColor->setText(_inactiveColor);
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 != 1) return;
setName(ui->label_nameValue->text());
setComment(ui->lineEdit_comment->text());
setBar(ui->comboBox_value->currentText());
setActiveColor(ui->pushButton_activeColor->text().remove(QChar('&')));
setInactiveColor(ui->pushButton_inactiveColor->text().remove(QChar('&')));
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;
for (int i=0; i<dirs.count(); i++)
if (debug) qDebug() << PDEBUG << ":" << "Remove file" << dirs[i] + QDir::separator() + fileName <<
QFile::remove(dirs[i] + QDir::separator() + 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"));
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"), _activeColor);
settings.setValue(QString("X-AW-InactiveColor"), _inactiveColor);
settings.setValue(QString("X-AW-Type"), getStrType());
settings.setValue(QString("X-AW-Direction"), getStrDirection());
settings.setValue(QString("X-AW-Height"), _height);
settings.setValue(QString("X-AW-Width"), _width);
settings.endGroup();
settings.sync();
}
void GraphicalItem::changeColor()
{
if (debug) qDebug() << PDEBUG;
QColor color = stringToColor(((QPushButton *)sender())->text());
QColor newColor = QColorDialog::getColor(color, 0, i18n("Select color"),
QColorDialog::ShowAlphaChannel);
if (!newColor.isValid()) return;
QStringList colorText;
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(',')));
}
QColor GraphicalItem::stringToColor(const QString color)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Color" << color;
QColor qcolor;
QStringList listColor = color.split(QChar(','));
while (listColor.count() < 4)
listColor.append(QString("0"));
qcolor.setRed(listColor[0].toInt());
qcolor.setGreen(listColor[1].toInt());
qcolor.setBlue(listColor[2].toInt());
qcolor.setAlpha(listColor[3].toInt());
return qcolor;
}

View File

@ -0,0 +1,98 @@
/***************************************************************************
* 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 <QDialog>
namespace Ui {
class GraphicalItem;
}
class GraphicalItem : public QDialog
{
Q_OBJECT
public:
enum Direction {
LeftToRight = 0,
RightToLeft
};
enum Type {
Horizontal = 0,
Vertical,
Circle
};
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
QString getFileName();
QString getName();
QString getComment();
QString getBar();
QString getActiveColor();
QString getInactiveColor();
Type getType();
QString getStrType();
Direction getDirection();
QString getStrDirection();
int getHeight();
int getWidth();
// set methods
void setName(const QString name = QString("none"));
void setComment(const QString comment = QString("empty"));
void setBar(const QString bar = QString("cpu"));
void setActiveColor(const QString color = QString("0,0,0,130"));
void setInactiveColor(const QString color = QString("255,255,255,130"));
void setType(const QString type = QString("Horizontal"));
void setDirection(const QString direction = QString("LeftToRight"));
void setHeight(const int height = 100);
void setWidth(const int width = 100);
public slots:
void readConfiguration();
void showConfiguration(const QStringList tags = QStringList());
void tryDelete();
void writeConfiguration();
private slots:
void changeColor();
private:
QColor stringToColor(const QString color);
QString fileName;
QStringList dirs;
bool debug;
Ui::GraphicalItem *ui;
// properties
QString _name = QString("none");
QString _comment = QString("empty");
QString _bar = QString("cpu");
QString _activeColor = QString("0,0,0,130");
QString _inactiveColor = QString("255,255,255,130");
Type _type = Horizontal;
Direction _direction = LeftToRight;
int _height = 100;
int _width = 100;
};
#endif /* GRAPHICALITEM_H */

View File

@ -0,0 +1,293 @@
<?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>416</width>
<height>325</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="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<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>false</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 notr="true"/>
</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 notr="true"/>
</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>

View File

@ -0,0 +1,14 @@
[Global]
IconName=system
Name=Awesome Widget
Comment=Awesome widget information
[Event/system]
Name=System information
Comment=System information
Action=Popup
[Event/tag]
Name=Tag information
Comment=Tag information
Action=Popup

View File

@ -0,0 +1,3 @@
module org.kde.plasma.private.awesome-widget
plugin awplugin