diff --git a/functions.h b/functions.h index 3d26fde..2a3bf3e 100644 --- a/functions.h +++ b/functions.h @@ -28,7 +28,8 @@ namespace global { inline bool appsWidgetCreated; inline bool appsWidgetSelected; - inline bool settingsWidgetSelected; + inline bool settingsChooserWidgetCreated; + inline bool settingsChooserWidgetSelected; } inline bool updateDialog; inline bool lowBatteryDialog; diff --git a/inkbox.pro b/inkbox.pro index 3919623..cfd5f64 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -22,6 +22,7 @@ SOURCES += \ reader.cpp \ savedwords.cpp \ settings.cpp \ + settingschooser.cpp \ usbms_splash.cpp HEADERS += \ @@ -36,6 +37,7 @@ HEADERS += \ reader.h \ savedwords.h \ settings.h \ + settingschooser.h \ usbms_splash.h FORMS += \ @@ -49,6 +51,7 @@ FORMS += \ reader.ui \ savedwords.ui \ settings.ui \ + settingschooser.ui \ usbms_splash.ui # Default rules for deployment. diff --git a/mainwindow.cpp b/mainwindow.cpp index 1e83f88..eb18100 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -37,8 +37,6 @@ MainWindow::MainWindow(QWidget *parent) ui->pushButton->setProperty("type", "borderless"); ui->brightnessBtn->setProperty("type", "borderless"); ui->homeBtn->setProperty("type", "borderless"); - ui->inkboxSettingsBtn->setProperty("type", "borderless"); - ui->koboxSettingsBtn->setProperty("type", "borderless"); ui->settingsBtn->setText(""); ui->appsBtn->setText(""); @@ -47,16 +45,12 @@ MainWindow::MainWindow(QWidget *parent) ui->searchBtn->setText(""); ui->brightnessBtn->setText(""); ui->homeBtn->setText(""); - ui->inkboxSettingsBtn->setText("\t\t\tInkBox settings"); - ui->koboxSettingsBtn->setText("\t\t\tKoBox settings"); ui->quoteLabel->setText(""); ui->quotePictureLabel->setText(""); ui->quoteHeadingLabel->setStyleSheet("padding: 30px"); ui->homeBtn->setStyleSheet("padding: 5px"); - ui->inkboxSettingsBtn->setStyleSheet("padding: 40px; Text-align: left"); - ui->koboxSettingsBtn->setStyleSheet("padding: 40px; Text-align: left"); // Variables global::battery::showLowBatteryDialog = true; @@ -104,11 +98,6 @@ MainWindow::MainWindow(QWidget *parent) ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png")); ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight)); - ui->inkboxSettingsBtn->setIcon(QIcon(":/resources/settings.png")); - ui->inkboxSettingsBtn->setIconSize(QSize(homeIconWidth, homeIconHeight)); - ui->koboxSettingsBtn->setIcon(QIcon(":/resources/X11.png")); - ui->koboxSettingsBtn->setIconSize(QSize(homeIconWidth, homeIconHeight)); - // Battery string_checkconfig_ro("/opt/inkbox_device"); if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") { @@ -516,10 +505,10 @@ MainWindow::~MainWindow() void MainWindow::openUpdateDialog() { global::mainwindow::updateDialog = true; - // We write to a temporary file to show a "Reset" prompt + // Write to a temporary file to show a "Reset" prompt string_writeconfig("/inkbox/updateDialog", "true"); - // We show the dialog + // Show the dialog generalDialogWindow = new generalDialog(this); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); generalDialogWindow->show(); @@ -549,13 +538,18 @@ void MainWindow::openCriticalBatteryAlertWindow() { void MainWindow::on_settingsBtn_clicked() { resetWindow(false); - if(global::mainwindow::tabSwitcher::settingsWidgetSelected != true) { + if(global::mainwindow::tabSwitcher::settingsChooserWidgetSelected != true) { ui->settingsBtn->setStyleSheet("background: black"); ui->settingsBtn->setIcon(QIcon(":/resources/settings-inverted.png")); + // Create widget + settingsChooserWindow = new settingsChooser(); + ui->stackedWidget->insertWidget(2, settingsChooserWindow); + global::mainwindow::tabSwitcher::settingsChooserWidgetCreated = true; + // Switch tab ui->stackedWidget->setCurrentIndex(2); - global::mainwindow::tabSwitcher::settingsWidgetSelected = true; + global::mainwindow::tabSwitcher::settingsChooserWidgetSelected = true; // Repaint this->repaint(); @@ -572,12 +566,10 @@ void MainWindow::on_appsBtn_clicked() ui->appsBtn->setStyleSheet("background: black"); ui->appsBtn->setIcon(QIcon(":/resources/apps-inverted.png")); - // Create the widget only once - if(global::mainwindow::tabSwitcher::appsWidgetCreated != true) { - appsWindow = new apps(); - ui->stackedWidget->insertWidget(1, appsWindow); - global::mainwindow::tabSwitcher::appsWidgetCreated = true; - } + // Create widget + appsWindow = new apps(); + ui->stackedWidget->insertWidget(1, appsWindow); + global::mainwindow::tabSwitcher::appsWidgetCreated = true; // Switch tab ui->stackedWidget->setCurrentIndex(1); @@ -600,11 +592,7 @@ void MainWindow::on_pushButton_clicked() void MainWindow::on_searchBtn_clicked() { - /*global::battery::showCriticalBatteryAlert = true; - global::battery::showLowBatteryDialog = false; - settingsWindow = new settings(); - ui->stackedWidget->insertWidget(2, settingsWindow); - ui->stackedWidget->setCurrentIndex(2);*/ + // Hopefully this button will do something one day... } void MainWindow::on_quitBtn_clicked() @@ -672,8 +660,20 @@ void MainWindow::resetWindow(bool resetStackedWidget) { if(resetStackedWidget == true) { ui->stackedWidget->setCurrentIndex(0); } + + // Destroy widgets + if(global::mainwindow::tabSwitcher::appsWidgetCreated == true) { + appsWindow->deleteLater(); + } + if(global::mainwindow::tabSwitcher::settingsChooserWidgetCreated == true) { + settingsChooserWindow->deleteLater(); + } + + global::mainwindow::tabSwitcher::appsWidgetCreated = false; + global::mainwindow::tabSwitcher::settingsChooserWidgetCreated = false; global::mainwindow::tabSwitcher::appsWidgetSelected = false; - global::mainwindow::tabSwitcher::settingsWidgetSelected = false; + global::mainwindow::tabSwitcher::settingsChooserWidgetSelected = false; + resetIcons(); if(global::mainwindow::tabSwitcher::repaint == true) { this->repaint(); diff --git a/mainwindow.h b/mainwindow.h index a85710d..fbe3913 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,6 +3,7 @@ #include #include "settings.h" +#include "settingschooser.h" #include "apps.h" #include "reader.h" #include "quit.h" @@ -62,7 +63,7 @@ private slots: private: Ui::MainWindow *ui; - settings *settingsWindow; + settingsChooser *settingsChooserWindow; apps *appsWindow; reader *readerWindow; quit *quitWindow; diff --git a/mainwindow.ui b/mainwindow.ui index 33ba5ac..ec87f6e 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -400,107 +400,6 @@ 0 - - - - - - QFrame::Plain - - - 3 - - - Qt::Horizontal - - - - - - - 0 - - - - - - Chivo - 50 - true - false - - - - KoBox settings - - - - - - - - Chivo - true - - - - InkBox settings - - - - - - - QFrame::Plain - - - Qt::Horizontal - - - - - - - QFrame::Plain - - - Qt::Horizontal - - - - - - - - - - 75 - true - - - - Settings - - - Qt::AlignCenter - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - diff --git a/settingschooser.cpp b/settingschooser.cpp new file mode 100644 index 0000000..a651f48 --- /dev/null +++ b/settingschooser.cpp @@ -0,0 +1,59 @@ +#include "settingschooser.h" +#include "ui_settingschooser.h" +#include "functions.h" + +#include +#include + +settingsChooser::settingsChooser(QWidget *parent) : + QWidget(parent), + ui(new Ui::settingsChooser) +{ + ui->setupUi(this); + + // Stylesheet + QFile stylesheetFile(":/resources/eink.qss"); + stylesheetFile.open(QFile::ReadOnly); + this->setStyleSheet(stylesheetFile.readAll()); + stylesheetFile.close(); + + // Getting the screen's size + sW = QGuiApplication::screens()[0]->size().width(); + sH = QGuiApplication::screens()[0]->size().height(); + + // Defining what the default icon size will be + string_checkconfig("/opt/inkbox_device"); + if(checkconfig_str_val == "n705\n") { + homeIconWidth = sW / 18; + homeIconHeight = sW / 18; + } + else { + homeIconWidth = sW / 20; + homeIconHeight = sW / 20; + } + + ui->inkboxSettingsBtn->setProperty("type", "borderless"); + ui->koboxSettingsBtn->setProperty("type", "borderless"); + + ui->inkboxSettingsBtn->setStyleSheet("padding: 40px; Text-align: left"); + ui->koboxSettingsBtn->setStyleSheet("padding: 40px; Text-align: left"); + ui->inkboxSettingsBtn->setText("\t\t\tInkBox settings"); + ui->koboxSettingsBtn->setText("\t\t\tKoBox settings"); + + ui->inkboxSettingsBtn->setIcon(QIcon(":/resources/settings.png")); + ui->inkboxSettingsBtn->setIconSize(QSize(homeIconWidth, homeIconHeight)); + ui->koboxSettingsBtn->setIcon(QIcon(":/resources/X11.png")); + ui->koboxSettingsBtn->setIconSize(QSize(homeIconWidth, homeIconHeight)); +} + +settingsChooser::~settingsChooser() +{ + delete ui; +} + +void settingsChooser::on_inkboxSettingsBtn_clicked() +{ + settingsWindow = new settings(); + settingsWindow->setAttribute(Qt::WA_DeleteOnClose); + settingsWindow->showFullScreen(); +} diff --git a/settingschooser.h b/settingschooser.h new file mode 100644 index 0000000..77b2961 --- /dev/null +++ b/settingschooser.h @@ -0,0 +1,33 @@ +#ifndef SETTINGSCHOOSER_H +#define SETTINGSCHOOSER_H + +#include + +#include "settings.h" + +namespace Ui { +class settingsChooser; +} + +class settingsChooser : public QWidget +{ + Q_OBJECT + +public: + explicit settingsChooser(QWidget *parent = nullptr); + ~settingsChooser(); + + float sW; + float sH; + float homeIconWidth; + float homeIconHeight; + +private slots: + void on_inkboxSettingsBtn_clicked(); + +private: + Ui::settingsChooser *ui; + settings *settingsWindow; +}; + +#endif // SETTINGSCHOOSER_H diff --git a/settingschooser.ui b/settingschooser.ui new file mode 100644 index 0000000..8ce280a --- /dev/null +++ b/settingschooser.ui @@ -0,0 +1,128 @@ + + + settingsChooser + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Inter + 75 + true + + + + Settings + + + Qt::AlignCenter + + + + + + + + Chivo + true + + + + KoBox settings + + + + + + + + Chivo + 50 + true + false + + + + InkBox settings + + + + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + + QFrame::Plain + + + 3 + + + Qt::Horizontal + + + + + + + QFrame::Plain + + + Qt::Horizontal + + + + + + + + + +