|
Line 0
Link Here
|
|
|
1 |
/******************************************************************* |
| 2 |
* osdwidget.cpp |
| 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> |
| 6 |
* |
| 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. |
| 11 |
* |
| 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. |
| 16 |
* |
| 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/>. |
| 19 |
* |
| 20 |
******************************************************************/ |
| 21 |
|
| 22 |
#include "brightnessosdwidget.h" |
| 23 |
|
| 24 |
// Qt |
| 25 |
#include <QGraphicsLinearLayout> |
| 26 |
#include <QPainter> |
| 27 |
#include <QTimer> |
| 28 |
#include <QLabel> |
| 29 |
|
| 30 |
// KDE |
| 31 |
#include <KIcon> |
| 32 |
#include <KDialog> |
| 33 |
#include <Plasma/FrameSvg> |
| 34 |
#include <Plasma/Label> |
| 35 |
#include <Plasma/Meter> |
| 36 |
|
| 37 |
BrightnessOSDWidget::BrightnessOSDWidget(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)) |
| 46 |
{ |
| 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); |
| 54 |
|
| 55 |
//Cache the icon pixmaps |
| 56 |
QSize iconSize = QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium); |
| 57 |
m_brightnessPixmap = KIcon("video-display").pixmap(iconSize); |
| 58 |
/*m_volumeHighPixmap = KIcon("audio-volume-high").pixmap(iconSize); |
| 59 |
m_volumeMediumPixmap = KIcon("audio-volume-medium").pixmap(iconSize); |
| 60 |
m_volumeLowPixmap = KIcon("audio-volume-low").pixmap(iconSize);*/ |
| 61 |
|
| 62 |
//Setup the widgets |
| 63 |
m_background->setImagePath("widgets/tooltip"); |
| 64 |
|
| 65 |
m_iconLabel->nativeWidget()->setPixmap(m_brightnessPixmap); |
| 66 |
m_iconLabel->nativeWidget()->setFixedSize(iconSize); |
| 67 |
m_iconLabel->setMinimumSize(iconSize); |
| 68 |
m_iconLabel->setMaximumSize(iconSize); |
| 69 |
|
| 70 |
m_meter->setMeterType(Plasma::Meter::BarMeterHorizontal); |
| 71 |
m_meter->setMaximum(100); |
| 72 |
m_meter->setMaximumHeight(iconSize.height()); |
| 73 |
|
| 74 |
m_volumeLabel->setAlignment(Qt::AlignCenter); |
| 75 |
|
| 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())); |
| 80 |
|
| 81 |
//Setup the OSD layout |
| 82 |
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(m_container); |
| 83 |
layout->addItem(m_iconLabel); |
| 84 |
layout->addItem(m_meter); |
| 85 |
|
| 86 |
m_scene->addItem(m_container); |
| 87 |
setScene(m_scene); |
| 88 |
} |
| 89 |
|
| 90 |
void BrightnessOSDWidget::activateOSD() |
| 91 |
{ |
| 92 |
m_hideTimer->start(); |
| 93 |
} |
| 94 |
|
| 95 |
void BrightnessOSDWidget::setCurrentBrightness(int brightnessLevel) |
| 96 |
{ |
| 97 |
m_meter->setValue(brightnessLevel); |
| 98 |
|
| 99 |
/*if (volumeLevel < 25) { |
| 100 |
m_iconLabel->nativeWidget()->setPixmap(m_volumeLowPixmap); |
| 101 |
} else if (volumeLevel < 75) { |
| 102 |
m_iconLabel->nativeWidget()->setPixmap(m_volumeMediumPixmap); |
| 103 |
} else { |
| 104 |
m_iconLabel->nativeWidget()->setPixmap(m_volumeHighPixmap); |
| 105 |
}*/ |
| 106 |
|
| 107 |
//Show the volume % |
| 108 |
//m_meter->setLabel(0, QString::number(volumeLevel) + " %"); |
| 109 |
} |
| 110 |
|
| 111 |
void BrightnessOSDWidget::drawBackground(QPainter *painter, const QRectF &/*rectF*/) |
| 112 |
{ |
| 113 |
painter->save(); |
| 114 |
painter->setCompositionMode(QPainter::CompositionMode_Source); |
| 115 |
m_background->paintFrame(painter); |
| 116 |
painter->restore(); |
| 117 |
} |
| 118 |
|
| 119 |
QSize BrightnessOSDWidget::sizeHint() const |
| 120 |
{ |
| 121 |
int iconSize = m_iconLabel->nativeWidget()->pixmap()->height(); |
| 122 |
int meterHeight = iconSize; |
| 123 |
int meterWidth = iconSize * 12; |
| 124 |
qreal left, top, right, bottom; |
| 125 |
m_background->getMargins(left, top, right, bottom); |
| 126 |
return QSize(meterWidth + iconSize + left + right, meterHeight + top + bottom); |
| 127 |
} |
| 128 |
|
| 129 |
void BrightnessOSDWidget::resizeEvent(QResizeEvent*) |
| 130 |
{ |
| 131 |
m_background->resizeFrame(size()); |
| 132 |
m_container->setGeometry(0, 0, width(), height()); |
| 133 |
qreal left, top, right, bottom; |
| 134 |
m_background->getMargins(left, top, right, bottom); |
| 135 |
m_container->layout()->setContentsMargins(left, top, right, bottom); |
| 136 |
|
| 137 |
m_scene->setSceneRect(0, 0, width(), height()); |
| 138 |
setMask(m_background->mask()); |
| 139 |
} |
| 140 |
|
| 141 |
#include "brightnessosdwidget.moc" |