1
/*******************************************************************
2
* brightnessosdwidget.cpp
3
* adapted from kdemultimedia/kmix/osdwidget.cpp
4
* Copyright 2009 Aurélien Gâteau <agateau@kde.org>
5
* Copyright 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
6
* Copyright 2009 Christian Esken <christian.esken@arcor.de>
7
* Copyright 2010 Felix Geyer <debfx-kde@fobos.de>
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License as
11
* published by the Free Software Foundation; either version 2 of
12
* the License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
******************************************************************/
24
#include "brightnessosdwidget.h"
27
#include <QGraphicsLinearLayout>
35
#include <KWindowSystem>
36
#include <Plasma/FrameSvg>
37
#include <Plasma/Label>
38
#include <Plasma/Meter>
39
#include <Plasma/Theme>
40
#include <Plasma/WindowEffects>
42
BrightnessOSDWidget::BrightnessOSDWidget(QWidget * parent)
43
: QGraphicsView(parent),
44
m_background(new Plasma::FrameSvg(this)),
45
m_scene(new QGraphicsScene(this)),
46
m_container(new QGraphicsWidget),
47
m_iconLabel(new Plasma::Label),
48
m_volumeLabel(new Plasma::Label),
49
m_meter(new Plasma::Meter),
50
m_hideTimer(new QTimer(this))
52
//Setup the window properties
53
setWindowFlags(Qt::X11BypassWindowManagerHint);
54
setFrameStyle(QFrame::NoFrame);
55
viewport()->setAutoFillBackground(false);
56
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
57
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58
setAttribute(Qt::WA_TranslucentBackground);
60
//Cache the icon pixmaps
61
QSize iconSize = QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium);
63
m_brightnessPixmap = KIcon("video-display").pixmap(iconSize);
66
m_background->setImagePath("widgets/tooltip");
68
m_iconLabel->nativeWidget()->setPixmap(m_brightnessPixmap);
69
m_iconLabel->nativeWidget()->setFixedSize(iconSize);
70
m_iconLabel->setMinimumSize(iconSize);
71
m_iconLabel->setMaximumSize(iconSize);
73
m_meter->setMeterType(Plasma::Meter::BarMeterHorizontal);
74
m_meter->setMaximum(100);
75
m_meter->setMaximumHeight(iconSize.height());
77
m_volumeLabel->setAlignment(Qt::AlignCenter);
79
//Setup the auto-hide timer
80
m_hideTimer->setInterval(2000);
81
m_hideTimer->setSingleShot(true);
82
connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hide()));
84
//Setup the OSD layout
85
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(m_container);
86
layout->addItem(m_iconLabel);
87
layout->addItem(m_meter);
89
m_scene->addItem(m_container);
93
void BrightnessOSDWidget::activateOSD()
98
void BrightnessOSDWidget::setCurrentBrightness(int brightnessLevel)
100
m_meter->setValue(brightnessLevel);
103
void BrightnessOSDWidget::drawBackground(QPainter *painter, const QRectF &/*rectF*/)
106
painter->setCompositionMode(QPainter::CompositionMode_Source);
107
m_background->paintFrame(painter);
111
QSize BrightnessOSDWidget::sizeHint() const
113
int iconSize = m_iconLabel->nativeWidget()->pixmap()->height();
114
int meterHeight = iconSize;
115
int meterWidth = iconSize * 12;
116
qreal left, top, right, bottom;
117
m_background->getMargins(left, top, right, bottom);
118
return QSize(meterWidth + iconSize + left + right, meterHeight + top + bottom);
121
void BrightnessOSDWidget::resizeEvent(QResizeEvent*)
123
m_background->resizeFrame(size());
124
m_container->setGeometry(0, 0, width(), height());
125
qreal left, top, right, bottom;
126
m_background->getMargins(left, top, right, bottom);
127
m_container->layout()->setContentsMargins(left, top, right, bottom);
129
m_scene->setSceneRect(0, 0, width(), height());
130
if (!KWindowSystem::compositingActive()) {
131
setMask(m_background->mask());
135
void BrightnessOSDWidget::showEvent(QShowEvent *event)
137
Plasma::WindowEffects::overrideShadow(winId(), true);
140
#include "brightnessosdwidget.moc"