Basic settings stacked widget implementation

This commit is contained in:
Nicolas Mailloux 2021-04-24 09:34:35 -04:00
parent d1d03ae16e
commit 6eefeed69f
9 changed files with 257 additions and 63 deletions

View file

@ -204,7 +204,7 @@
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>5</number>
<number>3</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>

View file

@ -40,5 +40,8 @@
<file>resources/battery_alert.png</file>
<file>resources/apps-inverted.png</file>
<file>resources/home.png</file>
<file>resources/settings-inverted.png</file>
<file>resources/kobox-icon.png</file>
<file>resources/X11.png</file>
</qresource>
</RCC>

View file

@ -24,8 +24,11 @@ namespace global {
}
namespace mainwindow {
namespace tabSwitcher {
inline bool repaint;
inline bool appsWidgetCreated;
inline bool appsWidgetSelected;
inline bool settingsWidgetSelected;
}
inline bool updateDialog;
inline bool lowBatteryDialog;

View file

@ -20,6 +20,7 @@
#include <QScreen>
#include <QFont>
#include <QFontDatabase>
#include <QPagedPaintDevice>
using namespace std;
@ -36,6 +37,8 @@ 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("");
@ -44,12 +47,21 @@ 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;
global::battery::showCriticalBatteryAlert = true;
global::mainwindow::tabSwitcher::repaint = true;
// Getting the screen's size
sW = QGuiApplication::screens()[0]->size().width();
@ -92,6 +104,11 @@ 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") {
@ -387,8 +404,9 @@ MainWindow::MainWindow(QWidget *parent)
}
}
else {
ui->quoteLabel->hide();
ui->quotePictureLabel->hide();
ui->gridLayout_4->deleteLater();
ui->quotePictureLabel->deleteLater();
ui->quoteLabel->deleteLater();
ui->quoteHeadingLabel->setText("Books");
ui->book1Btn->show();
ui->book2Btn->show();
@ -530,26 +548,47 @@ void MainWindow::openCriticalBatteryAlertWindow() {
void MainWindow::on_settingsBtn_clicked()
{
settingsWindow = new settings();
settingsWindow->setAttribute(Qt::WA_DeleteOnClose);
settingsWindow->showFullScreen();
resetWindow(false);
if(global::mainwindow::tabSwitcher::settingsWidgetSelected != true) {
ui->settingsBtn->setStyleSheet("background: black");
ui->settingsBtn->setIcon(QIcon(":/resources/settings-inverted.png"));
// Switch tab
ui->stackedWidget->setCurrentIndex(2);
global::mainwindow::tabSwitcher::settingsWidgetSelected = true;
// Repaint
this->repaint();
}
else {
;
}
}
void MainWindow::on_appsBtn_clicked()
{
ui->appsBtn->setStyleSheet("background: black");
ui->appsBtn->setIcon(QIcon(":/resources/apps-inverted.png"));
resetWindow(false);
if(global::mainwindow::tabSwitcher::appsWidgetSelected != true) {
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 the widget only once
if(global::mainwindow::tabSwitcher::appsWidgetCreated != true) {
appsWindow = new apps();
ui->stackedWidget->insertWidget(1, appsWindow);
global::mainwindow::tabSwitcher::appsWidgetCreated = true;
}
// Switch tab
ui->stackedWidget->setCurrentIndex(1);
global::mainwindow::tabSwitcher::appsWidgetSelected = true;
// Repaint
this->repaint();
}
else {
;
}
// Switch tab
ui->stackedWidget->setCurrentIndex(1);
global::mainwindow::tabSwitcher::appsWidgetSelected = true;
}
void MainWindow::on_pushButton_clicked()
@ -563,11 +602,9 @@ void MainWindow::on_searchBtn_clicked()
{
/*global::battery::showCriticalBatteryAlert = true;
global::battery::showLowBatteryDialog = false;
alertWindow = new alert();
alertWindow->setAttribute(Qt::WA_DeleteOnClose);
alertWindow->setGeometry(QRect(QPoint(0,0), screen()->geometry ().size()));
alertWindow->show();*/
settingsWindow = new settings();
ui->stackedWidget->insertWidget(2, settingsWindow);
ui->stackedWidget->setCurrentIndex(2);*/
}
void MainWindow::on_quitBtn_clicked()
@ -626,18 +663,27 @@ void MainWindow::on_brightnessBtn_clicked()
void MainWindow::on_homeBtn_clicked()
{
resetWindow();
global::mainwindow::tabSwitcher::repaint = true;
resetWindow(true);
}
void MainWindow::resetWindow() {
void MainWindow::resetWindow(bool resetStackedWidget) {
// Reset layout
ui->stackedWidget->setCurrentIndex(0);
if(resetStackedWidget == true) {
ui->stackedWidget->setCurrentIndex(0);
}
global::mainwindow::tabSwitcher::appsWidgetSelected = false;
global::mainwindow::tabSwitcher::settingsWidgetSelected = false;
resetIcons();
this->repaint();
if(global::mainwindow::tabSwitcher::repaint == true) {
this->repaint();
}
}
void MainWindow::resetIcons() {
// Reset icons
ui->appsBtn->setStyleSheet("background: white");
ui->appsBtn->setIcon(QIcon(":/resources/apps.png"));
ui->settingsBtn->setStyleSheet("background: white");
ui->settingsBtn->setIcon(QIcon(":/resources/settings.png"));
}

View file

@ -41,7 +41,7 @@ public:
void openLowBatteryDialog();
void openCriticalBatteryAlertWindow();
void resetWindow();
void resetWindow(bool resetStackedWidget);
void resetIcons();
public slots:

View file

@ -167,16 +167,29 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="0">
<widget class="QLabel" name="recentBooksLabel">
<item row="0" column="0">
<spacer name="verticalSpacer_4">
<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="1" column="0">
<widget class="QLabel" name="quoteHeadingLabel">
<property name="font">
<font>
<family>Chivo</family>
<italic>true</italic>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Recently read books will appear here.</string>
<string>Author's quote</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
@ -275,35 +288,6 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="quoteHeadingLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Author's quote</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="verticalSpacer_4">
<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="3" column="0">
<layout class="QGridLayout" name="gridLayout">
<property name="bottomMargin">
@ -353,14 +337,172 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="recentBooksLabel">
<property name="font">
<font>
<family>Chivo</family>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Recently read books will appear here.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer_3">
<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>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3"/>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="0">
<widget class="Line" name="line_9">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>3</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<layout class="QGridLayout" name="gridLayout_9">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="2" column="0">
<widget class="QPushButton" name="koboxSettingsBtn">
<property name="font">
<font>
<family>Chivo</family>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>KoBox settings</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="inkboxSettingsBtn">
<property name="font">
<font>
<family>Chivo</family>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>InkBox settings</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="Line" name="line_10">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="Line" name="line_11">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="settingsLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Settings</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer_5">
<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>
<widget class="QWidget" name="page_3"/>
</widget>
</item>
<item>

BIN
resources/X11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
resources/kobox-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB