1
/*******************************************************************
3
* Copyright 2009 Aurélien Gâteau <agateau@kde.org>
4
* Copyright 2009 Dario Andres Rodriguez <andresbajotierra@gmail.com>
5
* Copyright 2009 Christian Esken <christian.esken@arcor.de>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation; either version 2 of
10
* the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
******************************************************************/
22
#include "osdwidget.h"
25
#include <QGraphicsLinearLayout>
33
#include <Plasma/FrameSvg>
34
#include <Plasma/Label>
35
#include <Plasma/Meter>
37
OSDWidget::OSDWidget(QWidget * parent)
38
: QGraphicsView(parent),
39
m_background(new Plasma::FrameSvg(this)),
40
m_scene(new QGraphicsScene(this)),
41
m_container(new QGraphicsWidget),
42
m_iconLabel(new Plasma::Label),
43
m_volumeLabel(new Plasma::Label),
44
m_meter(new Plasma::Meter),
45
m_hideTimer(new QTimer(this))
47
//Setup the window properties
48
setWindowFlags(Qt::X11BypassWindowManagerHint);
49
setFrameStyle(QFrame::NoFrame);
50
viewport()->setAutoFillBackground(false);
51
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
52
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
53
setAttribute(Qt::WA_TranslucentBackground);
55
//Cache the icon pixmaps
56
QSize iconSize = QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium);
57
m_volumeHighPixmap = KIcon("audio-volume-high").pixmap(iconSize);
58
m_volumeMediumPixmap = KIcon("audio-volume-medium").pixmap(iconSize);
59
m_volumeLowPixmap = KIcon("audio-volume-low").pixmap(iconSize);
60
m_volumeMutedPixmap = KIcon("audio-volume-muted").pixmap(iconSize);
63
m_background->setImagePath("widgets/tooltip");
65
m_iconLabel->nativeWidget()->setPixmap(m_volumeHighPixmap);
66
m_iconLabel->nativeWidget()->setFixedSize(iconSize);
67
m_iconLabel->setMinimumSize(iconSize);
68
m_iconLabel->setMaximumSize(iconSize);
70
m_meter->setMeterType(Plasma::Meter::BarMeterHorizontal);
71
m_meter->setMaximum(100);
72
m_meter->setMaximumHeight(iconSize.height());
74
m_volumeLabel->setAlignment(Qt::AlignCenter);
76
//Setup the auto-hide timer
77
m_hideTimer->setInterval(2000);
78
m_hideTimer->setSingleShot(true);
79
connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hide()));
81
//Setup the OSD layout
82
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(m_container);
83
layout->addItem(m_iconLabel);
84
layout->addItem(m_meter);
86
m_scene->addItem(m_container);
90
void OSDWidget::activateOSD()
95
void OSDWidget::setCurrentVolume(int volumeLevel, bool muted)
97
m_meter->setValue(volumeLevel);
100
if (volumeLevel < 25) {
101
m_iconLabel->nativeWidget()->setPixmap(m_volumeLowPixmap);
102
} else if (volumeLevel < 75) {
103
m_iconLabel->nativeWidget()->setPixmap(m_volumeMediumPixmap);
105
m_iconLabel->nativeWidget()->setPixmap(m_volumeHighPixmap);
108
m_iconLabel->nativeWidget()->setPixmap(m_volumeMutedPixmap);
112
//m_meter->setLabel(0, QString::number(volumeLevel) + " %");
115
void OSDWidget::drawBackground(QPainter *painter, const QRectF &/*rectF*/)
118
painter->setCompositionMode(QPainter::CompositionMode_Source);
119
m_background->paintFrame(painter);
123
QSize OSDWidget::sizeHint() const
125
int iconSize = m_iconLabel->nativeWidget()->pixmap()->height();
126
int meterHeight = iconSize;
127
int meterWidth = iconSize * 12;
128
qreal left, top, right, bottom;
129
m_background->getMargins(left, top, right, bottom);
130
return QSize(meterWidth + iconSize + left + right, meterHeight + top + bottom);
133
void OSDWidget::resizeEvent(QResizeEvent*)
135
m_background->resizeFrame(size());
136
m_container->setGeometry(0, 0, width(), height());
137
qreal left, top, right, bottom;
138
m_background->getMargins(left, top, right, bottom);
139
m_container->layout()->setContentsMargins(left, top, right, bottom);
141
m_scene->setSceneRect(0, 0, width(), height());
142
setMask(m_background->mask());
145
#include "osdwidget.moc"