1 /*
2 Copyright (C) 2016 P.L. Lucas <selairi@gmail.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "outputwidget.h"
20
OutputWidget(MonitorInfo monitor,QWidget * parent)21 OutputWidget::OutputWidget(MonitorInfo monitor, QWidget *parent):QWidget(parent), mMonitor(monitor)
22 {
23 ui = new Ui::OutputWidget();
24 ui->setupUi(this);
25
26 ui->label->setText(QStringLiteral("<b>")+monitor.name()+QStringLiteral(":</b>"));
27
28 ui->brightnessSlider->setMinimum(0);
29 ui->brightnessSlider->setMaximum(200);
30 ui->brightnessSlider->setValue(monitor.brightness()*100);
31
32 connect(ui->brightnessSlider, &QSlider::valueChanged, this, &OutputWidget::brightnessChanged);
33 connect(ui->brightnessDownButton, &QToolButton::clicked,
34 [this](bool){ ui->brightnessSlider->setValue(ui->brightnessSlider->value()-1); });
35 connect(ui->brightnessUpButton, &QToolButton::clicked,
36 [this](bool){ ui->brightnessSlider->setValue(ui->brightnessSlider->value()+1); });
37 }
38
~OutputWidget()39 OutputWidget::~OutputWidget()
40 {
41 delete ui;
42 ui = nullptr;
43 }
44
mouseReleaseEvent(QMouseEvent * event)45 void OutputWidget::mouseReleaseEvent(QMouseEvent *event)
46 {
47 if ( event->button() == Qt::RightButton && ui->brightnessSlider->underMouse() ) {
48 ui->brightnessSlider->setValue(100);
49 }
50 }
51
52
53
brightnessChanged(int value)54 void OutputWidget::brightnessChanged(int value)
55 {
56 mMonitor.setBrightness((float)value/100.0);
57 emit changed(mMonitor);
58 }
59
setRevertedValues(const MonitorInfo & monitor)60 void OutputWidget::setRevertedValues(const MonitorInfo & monitor)
61 {
62 if (mMonitor.id() == monitor.id() && mMonitor.name() == monitor.name()) {
63 ui->brightnessSlider->blockSignals(true);
64 ui->brightnessSlider->setValue(monitor.brightness()*100);
65 ui->brightnessSlider->blockSignals(false);
66 }
67 }
68