Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'osd' into dev

  • Loading branch information...
commit 9c22176ff2d5e2a6e76aaee675512956e63263ca 2 parents 5b89390 + 6005037
@simgunz authored
View
2  applet/CMakeLists.txt
@@ -1,4 +1,4 @@
-set(redshiftapplet_SRCS redshiftapplet.cpp)
+set(redshiftapplet_SRCS redshiftapplet.cpp redshiftosdwidget.cpp)
kde4_add_ui_files(redshiftapplet_SRCS redshift.ui)
kde4_add_ui_files(redshiftapplet_SRCS activities.ui)
kde4_add_kcfg_files(redshiftapplet_SRCS ../redshiftsettings.kcfgc)
View
29 applet/redshiftapplet.cpp
@@ -17,7 +17,11 @@
#include "redshiftapplet.h"
+#include "redshiftsettings.h"
+#include "redshiftosdwidget.h"
+
#include <QGraphicsLinearLayout>
+#include <QtGui/QDesktopWidget>
#include <QDebug>
#include <Plasma/Svg>
@@ -29,13 +33,14 @@
#include <KLocale>
#include <KConfigDialog>
#include <KComboBox>
+#include <KApplication>
-#include "redshiftsettings.h"
RedshiftApplet::RedshiftApplet(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
m_icon("redshift"),
- m_theme(this)
+ m_theme(this),
+ m_redshiftOSD(new RedshiftOSDWidget())
{
setBackgroundHints(StandardBackground);
setAspectRatioMode(Plasma::ConstrainedSquare);
@@ -57,7 +62,6 @@ void RedshiftApplet::init()
m_engine = dataEngine("redshift");
m_engine->connectSource("Controller", this);
connect(m_button, SIGNAL(clicked()), this, SLOT(toggle()));
-
/* This action is not needed anymore since it was just a workaround to prevent some bugs
QAction *action = new QAction(this);
action->setIcon(KIcon("system-reboot"));
@@ -85,6 +89,10 @@ void RedshiftApplet::dataUpdated(const QString &sourceName, const Plasma::DataEn
}
Plasma::ToolTipManager::self()->setContent(this, m_tooltip);
}
+ int temperature = data["Temperature"].toInt();
+ if(temperature) {
+ showRedshiftOSD(temperature);
+ }
}
void RedshiftApplet::createConfigurationInterface(KConfigDialog *parent)
@@ -141,6 +149,7 @@ void RedshiftApplet::createConfigurationInterface(KConfigDialog *parent)
void RedshiftApplet::toggle()
{
+ m_redshiftOSD.data()->hide();
Plasma::Service *service = m_engine->serviceForSource("Controller");
service->startOperationCall(service->operationDescription("toggle"));
}
@@ -182,6 +191,7 @@ QList<QAction*> RedshiftApplet::contextualActions()
void RedshiftApplet::wheelEvent(QGraphicsSceneWheelEvent *e)
{
+ Plasma::ToolTipManager::self()->hide(this);
Plasma::Service *service = m_engine->serviceForSource("Controller");
if(e->delta() < 0) {
@@ -191,6 +201,19 @@ void RedshiftApplet::wheelEvent(QGraphicsSceneWheelEvent *e)
}
}
+void RedshiftApplet::showRedshiftOSD(int temperature)
+{
+ m_redshiftOSD.data()->setCurrentTemperature(temperature);
+ m_redshiftOSD.data()->activateOSD(); //Show and enable the hide timer
+
+ //Center the OSD
+ QRect rect = KApplication::kApplication()->desktop()->screenGeometry(QCursor::pos());
+ QSize size = m_redshiftOSD.data()->sizeHint();
+ int posX = rect.x() + (rect.width() - size.width()) / 2;
+ int posY = rect.y() + 4 * rect.height() / 5;
+ m_redshiftOSD.data()->setGeometry(posX, posY, size.width(), size.height());
+}
+
K_EXPORT_PLASMA_APPLET(redshift, RedshiftApplet)
#include "redshiftapplet.moc"
View
4 applet/redshiftapplet.h
@@ -30,6 +30,8 @@
#include "ui_redshift.h"
#include "ui_activities.h"
+class RedshiftOSDWidget;
+
class RedshiftApplet : public Plasma::Applet
{
Q_OBJECT
@@ -40,6 +42,7 @@ public Q_SLOTS:
void toggle();
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
QList<QAction*> contextualActions();
+ void showRedshiftOSD(int brightness);
protected:
void createConfigurationInterface(KConfigDialog *parent);
void configChanged();
@@ -56,6 +59,7 @@ private Q_SLOTS:
Ui::RedshiftConfig m_redshiftUi;
Ui::ActivitiesConfig m_activitiesUi;
Plasma::DataEngine *m_engine;
+ QWeakPointer< RedshiftOSDWidget > m_redshiftOSD;
};
#endif
View
97 applet/redshiftosdwidget.cpp
@@ -0,0 +1,97 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Simone Gaiarin <simgunz@gmail.com> *
+ * Adapted from kdemultimedia/kmix/osdwidget.cpp *
+ * *
+ * This program 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. *
+ * *
+ * This program 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 this program; if not, see <http://www.gnu.org/licenses/>. *
+ **************************************************************************/
+
+#include "redshiftosdwidget.h"
+
+// Qt
+#include <QGraphicsLinearLayout>
+#include <QTimer>
+#include <QLabel>
+#include <QFont>
+
+// KDE
+#include <KIcon>
+#include <KDialog>
+#include <KWindowSystem>
+#include <Plasma/FrameSvg>
+#include <Plasma/Label>
+#include <Plasma/Meter>
+#include <Plasma/Theme>
+#include <Plasma/WindowEffects>
+
+RedshiftOSDWidget::RedshiftOSDWidget(QWidget * parent)
+ : Plasma::Dialog(parent, Qt::ToolTip),
+ m_iconLabel(new Plasma::Label),
+ m_temperatureLabel(new Plasma::Label),
+ m_hideTimer(new QTimer(this))
+{
+ //Setup the window properties
+ KWindowSystem::setState(winId(), NET::KeepAbove);
+ KWindowSystem::setType(winId(), NET::Tooltip);
+ setAttribute(Qt::WA_X11NetWmWindowTypeToolTip, true);
+
+ //Setup the auto-hide timer
+ m_hideTimer->setInterval(2000);
+ m_hideTimer->setSingleShot(true);
+ connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hide()));
+
+ //Cache the icon pixmaps
+ QSize iconSize = QSize(KIconLoader::SizeLarge, KIconLoader::SizeLarge);
+ m_redshiftPixmap = KIcon("redshift").pixmap(iconSize);
+
+ //Setup the widgets
+ m_iconLabel->nativeWidget()->setPixmap(m_redshiftPixmap);
+ m_iconLabel->nativeWidget()->setFixedSize(iconSize);
+
+ QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
+ font.setPixelSize(iconSize.height()-iconSize.height()*0.15);
+
+ m_temperatureLabel->setFont(font);
+ m_temperatureLabel->setText(QString::fromUtf8("9999 K"));
+ m_temperatureLabel->setWordWrap(false);
+
+ //Setup the OSD layout
+ QGraphicsWidget *widget = new QGraphicsWidget();
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget);
+ layout->addItem(m_iconLabel);
+ layout->addItem(m_temperatureLabel);
+
+ QGraphicsScene *scene = new QGraphicsScene(this);
+ scene->addItem(widget);
+
+ setGraphicsWidget(widget);
+}
+
+void RedshiftOSDWidget::activateOSD()
+{
+ show();
+ m_hideTimer->start();
+}
+
+void RedshiftOSDWidget::setCurrentTemperature(int temperature)
+{
+ m_temperatureLabel->setText(QString::fromUtf8("%1 K").arg(temperature));
+}
+
+QSize RedshiftOSDWidget::sizeHint() const
+{
+ int iconSize = m_iconLabel->nativeWidget()->pixmap()->height();
+ return QSize(iconSize + m_temperatureLabel->nativeWidget()->sizeHint().width(), iconSize);
+}
+
+#include "redshiftosdwidget.moc"
View
48 applet/redshiftosdwidget.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Simone Gaiarin <simgunz@gmail.com> *
+ * Adapted from kdemultimedia/kmix/osdwidget.h *
+ * *
+ * This program 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. *
+ * *
+ * This program 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 this program; if not, see <http://www.gnu.org/licenses/>. *
+ **************************************************************************/
+
+#ifndef REDSHIFTOSDWIDGET__H
+#define REDSHIFTOSDWIDGET__H
+
+#include <Plasma/Dialog>
+
+class QTimer;
+class QPixmap;
+
+namespace Plasma
+{
+class Label;
+}
+
+class RedshiftOSDWidget : public Plasma::Dialog
+{
+Q_OBJECT
+public:
+ RedshiftOSDWidget(QWidget * parent = 0);
+ void setCurrentTemperature(int temperature);
+ void activateOSD();
+ virtual QSize sizeHint() const;
+
+private:
+ Plasma::Label *m_iconLabel;
+ Plasma::Label *m_temperatureLabel;
+ QTimer *m_hideTimer;
+ QPixmap m_redshiftPixmap;
+};
+
+#endif
View
7 dataengine/redshiftcontainer.cpp
@@ -25,8 +25,8 @@ RedshiftContainer::RedshiftContainer(QObject* parent)
{
setObjectName("Controller");
m_controller = new RedshiftController();
- QObject::connect(m_controller, SIGNAL(stateChanged(int)), this, SLOT(updateStatus(int)));
- updateStatus(m_controller->state());
+ QObject::connect(m_controller, SIGNAL(stateChanged(int, int)), this, SLOT(updateStatus(int, int)));
+ updateStatus(m_controller->state(), m_controller->currentTemperature());
}
RedshiftContainer::~RedshiftContainer()
@@ -34,13 +34,14 @@ RedshiftContainer::~RedshiftContainer()
delete m_controller;
}
-void RedshiftContainer::updateStatus(int state)
+void RedshiftContainer::updateStatus(int state, int temp)
{
switch (state) {
case 0: setData("Status", "Stopped"); break;
case 1: setData("Status", "Running"); break;
case 2: setData("Status", "RunningManual"); break;
}
+ setData("Temperature", temp);
checkForUpdate();
}
View
2  dataengine/redshiftcontainer.h
@@ -30,7 +30,7 @@ class RedshiftContainer : public Plasma::DataContainer
~RedshiftContainer();
Plasma::Service* service(QObject* parent = 0);
public slots:
- void updateStatus(int state);
+ void updateStatus(int state, int temp);
private:
RedshiftController *m_controller;
View
16 dataengine/redshiftcontroller.cpp
@@ -59,6 +59,15 @@ bool RedshiftController::state()
return static_cast<bool>(m_state);
}
+int RedshiftController::currentTemperature()
+{
+ if(m_manualMode) {
+ return m_manualTemp;
+ } else {
+ return 0;
+ }
+}
+
void RedshiftController::start()
{
if (m_state == Stopped) {
@@ -125,13 +134,14 @@ void RedshiftController::applyChanges(bool toggle)
}
m_autoState = m_state;
}
+ //TODO: Explain what the states are
if (m_manualMode) {
- emit stateChanged(2);
+ emit stateChanged(2, currentTemperature());
} else {
if (m_state == Running) {
- emit stateChanged(1);
+ emit stateChanged(1, currentTemperature());
} else {
- emit stateChanged(0);
+ emit stateChanged(0, currentTemperature());
}
}
View
3  dataengine/redshiftcontroller.h
@@ -43,6 +43,7 @@ class RedshiftController : public QThread
void toggle();
void restart();
bool state();
+ int currentTemperature();
void setTemp(bool increase);
private Q_SLOTS:
void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data);
@@ -78,7 +79,7 @@ private Q_SLOTS:
int m_manualTemp;
signals:
- void stateChanged(int state);
+ void stateChanged(int state, int temperature);
};
#endif // REDSHIFTCONTROLLER_H
Please sign in to comment.
Something went wrong with that request. Please try again.