Permalink
Browse files

Panel Keyboard indicator plugin - skeleton

  • Loading branch information...
1 parent ca91dbe commit a867f27407dd8f102d4e4f98d5f79813d1e8bf94 @kuzmas kuzmas committed with amoskvin Sep 24, 2012
@@ -34,6 +34,7 @@ setByDefault(CPULOAD_PLUGIN Yes)
setByDefault(NETWORKMONITOR_PLUGIN Yes)
setByDefault(SENSORS_PLUGIN Yes)
setByDefault(VOLUME_PLUGIN Yes)
+setByDefault(KBINDICATOR_PLUGIN Yes)
# *******************************************************************
@@ -183,6 +184,11 @@ if (VOLUME_PLUGIN)
endif (VOLUME_PLUGIN)
+if (KBINDICATOR_PLUGIN)
+ set(ENABLED_PLUGINS ${ENABLED_PLUGINS} "Keyboard indicator")
+ add_subdirectory(plugin-kbindicator)
+endif (KBINDICATOR_PLUGIN)
+
message(STATUS "**************** The following plugins will be built ****************")
foreach (PLUGIN_STR ${ENABLED_PLUGINS})
@@ -0,0 +1,29 @@
+cmake_minimum_required(VERSION 2.6)
+
+set(PLUGIN "panelkbindicator")
+
+
+set(HEADERS
+ razorkbindicator.h
+ razorkbindicatorconfiguration.h
+)
+
+set(SOURCES
+ razorkbindicator.cpp
+ razorkbindicatorconfiguration.cpp
+)
+
+set(MOCS
+ razorkbindicator.h
+ razorkbindicatorconfiguration.h
+)
+
+set(UIS
+ razorkbindicatorconfiguration.ui
+)
+
+
+#*******************************************
+include ("../BuildPlugin.cmake")
+BUILD_RAZOR_PLUGIN(${PLUGIN})
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
@@ -0,0 +1,73 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Kuzma Shapran <kuzma.shapran@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#include "razorkbindicator.h"
+
+#include <QtGui/QLabel>
+
+
+EXPORT_RAZOR_PANEL_PLUGIN_CPP(RazorKbIndicator)
+
+RazorKbIndicator::RazorKbIndicator(const RazorPanelPluginStartInfo *startInfo, QWidget *parent):
+ RazorPanelPlugin(startInfo, parent),
+ content(new QLabel(this))
+{
+ setObjectName("KbIndicator");
+
+ addWidget(content);
+
+ this->layout()->setContentsMargins(0, 0, 0, 0);
+ this->layout()->setSpacing(0);
+
+ settingsChanged();
+}
+
+RazorKbIndicator::~RazorKbIndicator()
+{
+}
+
+void RazorKbIndicator::settingsChanged()
+{
+ bit = settings().value("bit", 0).toInt();
+ content->setText(settings().value("text", QString("C")).toString());
+
+ update();
+}
+
+void RazorKbIndicator::showConfigureDialog()
+{
+ RazorKbIndicatorConfiguration *confWindow = this->findChild<RazorKbIndicatorConfiguration*>("KbIndicatorConfigurationWindow");
+
+ if (!confWindow)
+ {
+ confWindow = new RazorKbIndicatorConfiguration(settings(), this);
+ }
+
+ confWindow->show();
+ confWindow->raise();
+ confWindow->activateWindow();
+}
@@ -0,0 +1,66 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Kuzma Shapran <kuzma.shapran@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#ifndef RAZORPANELKBINDICATOR_H
+#define RAZORPANELKBINDICATOR_H
+
+#include "../panel/razorpanelplugin.h"
+#include "razorkbindicatorconfiguration.h"
+
+
+class QLabel;
+
+namespace KbIndicator {
+ class BaseStat;
+}
+
+class RazorKbIndicator : public RazorPanelPlugin
+{
+ Q_OBJECT
+public:
+ RazorKbIndicator(const RazorPanelPluginStartInfo* startInfo, QWidget *parent = NULL);
+ ~RazorKbIndicator();
+
+ virtual RazorPanelPlugin::Flags flags() const { return PreferRightAlignment | HaveConfigDialog; }
+
+protected slots:
+ virtual void settingsChanged();
+ virtual void showConfigureDialog();
+
+protected:
+// void paintEvent(QPaintEvent *);
+
+private:
+ QLabel *content;
+
+ int bit;
+};
+
+
+EXPORT_RAZOR_PANEL_PLUGIN_H
+
+#endif // RAZORPANELKBINDICATOR_H
@@ -0,0 +1,116 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Kuzma Shapran <kuzma.shapran@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+
+#include "razorkbindicatorconfiguration.h"
+#include "ui_razorkbindicatorconfiguration.h"
+
+
+RazorKbIndicatorConfiguration::RazorKbIndicatorConfiguration(QSettings &settings, QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::RazorKbIndicatorConfiguration),
+ mSettings(settings),
+ oldSettings(settings),
+ lockSaving(false)
+{
+ setAttribute(Qt::WA_DeleteOnClose);
+ setObjectName("KbIndicatorConfigurationWindow");
+ ui->setupUi(this);
+
+ connect(ui->buttons, SIGNAL(clicked(QAbstractButton*)), this, SLOT(dialogButtonsAction(QAbstractButton*)));
+
+ connect(ui->capsLockRB, SIGNAL(clicked()), this, SLOT(saveSettings()));
+ connect(ui->numLockRB, SIGNAL(clicked()), this, SLOT(saveSettings()));
+ connect(ui->scrollLockRB, SIGNAL(clicked()), this, SLOT(saveSettings()));
+ connect(ui->advancedRB, SIGNAL(clicked()), this, SLOT(saveSettings()));
+ connect(ui->bitSB, SIGNAL(valueChanged(int)), this, SLOT(saveSettings()));
+ connect(ui->textLE, SIGNAL(textChanged(QString)), this, SLOT(saveSettings()));
+
+ loadSettings();
+}
+
+RazorKbIndicatorConfiguration::~RazorKbIndicatorConfiguration()
+{
+ delete ui;
+}
+
+void RazorKbIndicatorConfiguration::loadSettings()
+{
+ lockSaving = true;
+
+ ui->bitSB->setValue( mSettings.value("bit", 0).toInt() );
+ ui->textLE->setText( mSettings.value("text", QString("C")).toString() );
+
+ if ((ui->bitSB->value() == 0) && (ui->textLE->text() == QString("C")))
+ ui->capsLockRB->setChecked(true);
+ else if ((ui->bitSB->value() == 1) && (ui->textLE->text() == QString("1")))
+ ui->numLockRB->setChecked(true);
+ else if ((ui->bitSB->value() == 2) && (ui->textLE->text() == QString("S")))
+ ui->scrollLockRB->setChecked(true);
+ else
+ ui->advancedRB->setChecked(true);
+
+ ui->advancedW->setVisible(ui->advancedRB->isChecked());
+
+ lockSaving = false;
+}
+
+void RazorKbIndicatorConfiguration::saveSettings()
+{
+ if (lockSaving)
+ return;
+
+ if (ui->capsLockRB->isChecked())
+ {
+ ui->bitSB->setValue(0);
+ ui->textLE->setText(QString("C"));
+ }
+ else if (ui->numLockRB->isChecked())
+ {
+ ui->bitSB->setValue(1);
+ ui->textLE->setText(QString("1"));
+ }
+ else if (ui->scrollLockRB->isChecked())
+ {
+ ui->bitSB->setValue(2);
+ ui->textLE->setText(QString("S"));
+ }
+
+ mSettings.setValue("bit", ui->bitSB->value());
+ mSettings.setValue("text", ui->textLE->text());
+}
+
+void RazorKbIndicatorConfiguration::dialogButtonsAction(QAbstractButton *btn)
+{
+ if (ui->buttons->buttonRole(btn) == QDialogButtonBox::ResetRole)
+ {
+ oldSettings.loadToSettings();
+ loadSettings();
+ }
+ else
+ close();
+}
@@ -0,0 +1,88 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Kuzma Shapran <kuzma.shapran@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+
+#ifndef RAZORKBINDICATORCONFIGURATION_H
+#define RAZORKBINDICATORCONFIGURATION_H
+
+#include "razorqt/razorsettings.h"
+
+#include <QtGui/QDialog>
+#include <QtGui/QAbstractButton>
+#include <QtGui/QFont>
+#include <QtCore/QMap>
+
+
+namespace Ui {
+ class RazorKbIndicatorConfiguration;
+}
+
+namespace KbIndicator {
+ class BaseStat;
+}
+
+class QSignalMapper;
+class QFrame;
+
+class RazorKbIndicatorConfiguration : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit RazorKbIndicatorConfiguration(QSettings &settings, QWidget *parent = 0);
+ ~RazorKbIndicatorConfiguration();
+
+public slots:
+ void saveSettings();
+
+ void selectColour(const QString &);
+ void on_typeCOB_currentIndexChanged(int);
+ void on_sourceCOB_currentIndexChanged(int);
+ void on_maximumHS_valueChanged(int);
+ void on_fontB_clicked(void);
+
+
+private:
+ Ui::RazorKbIndicatorConfiguration *ui;
+ QSettings &mSettings;
+ RazorSettingsCache oldSettings;
+
+ /*
+ Read settings from conf file and put data into controls.
+ */
+ void loadSettings();
+
+ bool lockSaving;
+
+private slots:
+ /*
+ Saves settings in conf file.
+ */
+ void dialogButtonsAction(QAbstractButton *btn);
+};
+
+#endif // RAZORKBINDICATORCONFIGURATION_H
Oops, something went wrong.

0 comments on commit a867f27

Please sign in to comment.