mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Implemented brightness control dialog in MainWindow
This commit is contained in:
parent
640991db98
commit
83777b6482
12 changed files with 365 additions and 0 deletions
106
brightnessdialog.cpp
Normal file
106
brightnessdialog.cpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
#include "brightnessdialog.h"
|
||||
#include "ui_brightnessdialog.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
brightnessDialog::brightnessDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::brightnessDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Stylesheet, style & misc.
|
||||
QFile stylesheetFile(":/resources/eink.qss");
|
||||
stylesheetFile.open(QFile::ReadOnly);
|
||||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
stylesheetFile.close();
|
||||
|
||||
int value = get_brightness();
|
||||
|
||||
// Setting the slider to the appropriate position
|
||||
ui->horizontalSlider->setValue(value);
|
||||
|
||||
// Showing brightness percentage on label
|
||||
QString valueStr = QString::number(value);
|
||||
valueStr = valueStr.append("%");
|
||||
ui->valueLabel->setText(valueStr);
|
||||
|
||||
ui->quitBtn->setProperty("type", "borderless");
|
||||
ui->quitBtn->setText("");
|
||||
ui->quitBtn->setIcon(QIcon(":/resources/close.png"));
|
||||
ui->okBtn->setProperty("type", "borderless");
|
||||
ui->okBtn->setText("");
|
||||
ui->okBtn->setIcon(QIcon(":/resources/check.png"));
|
||||
ui->decBtn->setProperty("type", "borderless");
|
||||
ui->decBtn->setText("");
|
||||
ui->decBtn->setIcon(QIcon(":/resources/minus.png"));
|
||||
ui->incBtn->setProperty("type", "borderless");
|
||||
ui->incBtn->setText("");
|
||||
ui->incBtn->setIcon(QIcon(":/resources/plus.png"));
|
||||
ui->brightnessLabel->setStyleSheet("font-size: 11pt; padding-left: 125px; padding-right: 125px; font:bold");
|
||||
ui->valueLabel->setStyleSheet("font-size: 9pt");
|
||||
|
||||
// UI fonts
|
||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Bold.ttf");
|
||||
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||
QFont crimson_bold(family);
|
||||
|
||||
ui->brightnessLabel->setFont(QFont(crimson_bold));
|
||||
|
||||
// Saving current brightness value in case we want to go backwards
|
||||
oldValue = get_brightness();
|
||||
}
|
||||
|
||||
brightnessDialog::~brightnessDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void brightnessDialog::on_quitBtn_clicked()
|
||||
{
|
||||
// Reverting back to the old value
|
||||
set_brightness(oldValue);
|
||||
|
||||
// Just in case ;)
|
||||
brightness_writeconfig(oldValue);
|
||||
|
||||
// Leaving
|
||||
brightnessDialog::close();
|
||||
}
|
||||
|
||||
void brightnessDialog::on_horizontalSlider_valueChanged(int value)
|
||||
{
|
||||
set_brightness(value);
|
||||
QString valueStr = QString::number(value);
|
||||
valueStr = valueStr.append("%");
|
||||
ui->valueLabel->setText(valueStr);
|
||||
}
|
||||
|
||||
void brightnessDialog::on_incBtn_clicked()
|
||||
{
|
||||
int value = ui->horizontalSlider->value();
|
||||
value = value + 1;
|
||||
ui->horizontalSlider->setValue(value);
|
||||
}
|
||||
|
||||
void brightnessDialog::on_decBtn_clicked()
|
||||
{
|
||||
int value = ui->horizontalSlider->value();
|
||||
value = value - 1;
|
||||
ui->horizontalSlider->setValue(value);
|
||||
}
|
||||
|
||||
void brightnessDialog::on_okBtn_clicked()
|
||||
{
|
||||
// Get set brightness value
|
||||
int value = ui->horizontalSlider->value();
|
||||
|
||||
// Write brightness config
|
||||
brightness_writeconfig(value);
|
||||
|
||||
// Leaving
|
||||
brightnessDialog::close();
|
||||
}
|
68
brightnessdialog.h
Normal file
68
brightnessdialog.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef BRIGHTNESSDIALOG_H
|
||||
#define BRIGHTNESSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <QTextStream>
|
||||
#include <QFile>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Ui {
|
||||
class brightnessDialog;
|
||||
}
|
||||
|
||||
class brightnessDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QString checkconfig_str_val;
|
||||
int oldValue;
|
||||
explicit brightnessDialog(QWidget *parent = nullptr);
|
||||
~brightnessDialog();
|
||||
void brightness_writeconfig(int value) {
|
||||
ofstream fhandler;
|
||||
fhandler.open(".config/03-brightness/config");
|
||||
fhandler << value;
|
||||
fhandler.close();
|
||||
}
|
||||
void string_checkconfig_ro(QString file) {
|
||||
QFile config(file);
|
||||
config.open(QIODevice::ReadOnly);
|
||||
QTextStream in (&config);
|
||||
checkconfig_str_val = in.readAll();
|
||||
config.close();
|
||||
}
|
||||
int get_brightness() {
|
||||
QFile brightness("/var/run/brightness");
|
||||
brightness.open(QIODevice::ReadOnly);
|
||||
QString valuestr = brightness.readAll();
|
||||
int value = valuestr.toInt();
|
||||
brightness.close();
|
||||
return value;
|
||||
}
|
||||
void set_brightness(int value) {
|
||||
ofstream fhandler;
|
||||
fhandler.open("/var/run/brightness");
|
||||
fhandler << value;
|
||||
fhandler.close();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void on_quitBtn_clicked();
|
||||
|
||||
void on_horizontalSlider_valueChanged(int value);
|
||||
|
||||
void on_incBtn_clicked();
|
||||
|
||||
void on_decBtn_clicked();
|
||||
|
||||
void on_okBtn_clicked();
|
||||
|
||||
private:
|
||||
Ui::brightnessDialog *ui;
|
||||
};
|
||||
|
||||
#endif // BRIGHTNESSDIALOG_H
|
167
brightnessdialog.ui
Normal file
167
brightnessdialog.ui
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>brightnessDialog</class>
|
||||
<widget class="QDialog" name="brightnessDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>128</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="valueLabel">
|
||||
<property name="text">
|
||||
<string>Brightness Value</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="brightnessLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Chivo</family>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Brightness</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QPushButton" name="okBtn">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="quitBtn">
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="horizontalSlider">
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="incBtn">
|
||||
<property name="text">
|
||||
<string>Up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="decBtn">
|
||||
<property name="text">
|
||||
<string>Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -11,6 +11,7 @@ CONFIG += c++11
|
|||
SOURCES += \
|
||||
alert.cpp \
|
||||
apps.cpp \
|
||||
brightnessdialog.cpp \
|
||||
calendarapp.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
|
@ -23,6 +24,7 @@ SOURCES += \
|
|||
HEADERS += \
|
||||
alert.h \
|
||||
apps.h \
|
||||
brightnessdialog.h \
|
||||
calendarapp.h \
|
||||
mainwindow.h \
|
||||
quit.h \
|
||||
|
@ -34,6 +36,7 @@ HEADERS += \
|
|||
FORMS += \
|
||||
alert.ui \
|
||||
apps.ui \
|
||||
brightnessdialog.ui \
|
||||
calendarapp.ui \
|
||||
mainwindow.ui \
|
||||
quit.ui \
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <QTextStream>
|
||||
#include <QPixmap>
|
||||
#include <QScreen>
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -146,6 +148,14 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
}
|
||||
}
|
||||
|
||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
|
||||
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||
QFont crimson(family);
|
||||
|
||||
ui->book1Btn->setFont(QFont(crimson));
|
||||
ui->book2Btn->setFont(QFont(crimson));
|
||||
ui->book3Btn->setFont(QFont(crimson));
|
||||
ui->book4Btn->setFont(QFont(crimson));
|
||||
ui->book1Btn->setStyleSheet("font-size: 11pt; padding: 25px");
|
||||
ui->book2Btn->setStyleSheet("font-size: 11pt; padding: 25px");
|
||||
ui->book3Btn->setStyleSheet("font-size: 11pt; padding: 25px");
|
||||
|
@ -503,3 +513,10 @@ void MainWindow::on_book4Btn_clicked()
|
|||
readerWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
readerWindow->showFullScreen();
|
||||
}
|
||||
|
||||
void MainWindow::on_brightnessBtn_clicked()
|
||||
{
|
||||
brightnessDialogWindow = new brightnessDialog();
|
||||
brightnessDialogWindow->setAttribute(Qt::WA_DeleteOnClose);
|
||||
brightnessDialogWindow->show();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "quit.h"
|
||||
#include "alert.h"
|
||||
#include "usbms_splash.h"
|
||||
#include "brightnessdialog.h"
|
||||
#include <iostream>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
@ -150,6 +151,8 @@ private slots:
|
|||
|
||||
void on_book4Btn_clicked();
|
||||
|
||||
void on_brightnessBtn_clicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
settings *settingsWindow;
|
||||
|
@ -158,5 +161,6 @@ private:
|
|||
quit *quitWindow;
|
||||
alert *alertWindow;
|
||||
usbms_splash *usbmsWindow;
|
||||
brightnessDialog *brightnessDialogWindow;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
BIN
resources/check.png
Normal file
BIN
resources/check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
resources/fonts/CrimsonPro-Bold.ttf
Normal file
BIN
resources/fonts/CrimsonPro-Bold.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/CrimsonPro-Italic.ttf
Normal file
BIN
resources/fonts/CrimsonPro-Italic.ttf
Normal file
Binary file not shown.
BIN
resources/fonts/CrimsonPro-Regular.ttf
Normal file
BIN
resources/fonts/CrimsonPro-Regular.ttf
Normal file
Binary file not shown.
BIN
resources/minus.png
Normal file
BIN
resources/minus.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 885 B |
BIN
resources/plus.png
Normal file
BIN
resources/plus.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in a new issue