diff --git a/brightnessdialog.cpp b/brightnessdialog.cpp new file mode 100644 index 0000000..66ead4e --- /dev/null +++ b/brightnessdialog.cpp @@ -0,0 +1,106 @@ +#include "brightnessdialog.h" +#include "ui_brightnessdialog.h" + +#include +#include +#include +#include + +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(); +} diff --git a/brightnessdialog.h b/brightnessdialog.h new file mode 100644 index 0000000..c90e2fa --- /dev/null +++ b/brightnessdialog.h @@ -0,0 +1,68 @@ +#ifndef BRIGHTNESSDIALOG_H +#define BRIGHTNESSDIALOG_H + +#include +#include +#include +#include +#include + +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 diff --git a/brightnessdialog.ui b/brightnessdialog.ui new file mode 100644 index 0000000..18756bb --- /dev/null +++ b/brightnessdialog.ui @@ -0,0 +1,167 @@ + + + brightnessDialog + + + + 0 + 0 + 400 + 128 + + + + + 0 + 0 + + + + Dialog + + + true + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Brightness Value + + + Qt::AlignCenter + + + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Chivo + true + + + + Brightness + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + Quit + + + + + + + + + 0 + + + + + 100 + + + 1 + + + Qt::Horizontal + + + + + + + Up + + + + + + + Down + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/inkbox.pro b/inkbox.pro index 0089360..520766b 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -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 \ diff --git a/mainwindow.cpp b/mainwindow.cpp index 49c784f..fe93245 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -16,6 +16,8 @@ #include #include #include +#include +#include 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(); +} diff --git a/mainwindow.h b/mainwindow.h index c645daa..b6e039f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -8,6 +8,7 @@ #include "quit.h" #include "alert.h" #include "usbms_splash.h" +#include "brightnessdialog.h" #include #include #include @@ -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 diff --git a/resources/check.png b/resources/check.png new file mode 100644 index 0000000..e0ca033 Binary files /dev/null and b/resources/check.png differ diff --git a/resources/fonts/CrimsonPro-Bold.ttf b/resources/fonts/CrimsonPro-Bold.ttf new file mode 100644 index 0000000..ed9bd81 Binary files /dev/null and b/resources/fonts/CrimsonPro-Bold.ttf differ diff --git a/resources/fonts/CrimsonPro-Italic.ttf b/resources/fonts/CrimsonPro-Italic.ttf new file mode 100644 index 0000000..a2b63e3 Binary files /dev/null and b/resources/fonts/CrimsonPro-Italic.ttf differ diff --git a/resources/fonts/CrimsonPro-Regular.ttf b/resources/fonts/CrimsonPro-Regular.ttf new file mode 100644 index 0000000..ad53bfb Binary files /dev/null and b/resources/fonts/CrimsonPro-Regular.ttf differ diff --git a/resources/minus.png b/resources/minus.png new file mode 100644 index 0000000..b0e8cd3 Binary files /dev/null and b/resources/minus.png differ diff --git a/resources/plus.png b/resources/plus.png new file mode 100644 index 0000000..7d56edd Binary files /dev/null and b/resources/plus.png differ