From 9428483d02a33087298015b7f4679888ba1070ef Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Tue, 8 Jun 2021 07:49:52 -0400 Subject: [PATCH] Add QTextBrowser widget and dialog Some things, such as UIDs, just couldn't display normally and we need such a browser for them. I'll work on implementing as the main engine for the Reader framework. --- functions.h | 4 ++ generaldialog.cpp | 16 ++++-- generaldialog.h | 3 ++ generaldialog.ui | 133 +++++++++++++++++++++++++++++++++++----------- inkbox.pro | 3 ++ mainwindow.cpp | 7 +++ mainwindow.h | 2 + textwidget.cpp | 26 +++++++++ textwidget.h | 22 ++++++++ textwidget.ui | 40 ++++++++++++++ 10 files changed, 220 insertions(+), 36 deletions(-) create mode 100644 textwidget.cpp create mode 100644 textwidget.h create mode 100644 textwidget.ui diff --git a/functions.h b/functions.h index c2e17d2..bd2febe 100644 --- a/functions.h +++ b/functions.h @@ -46,6 +46,10 @@ namespace global { namespace settings { inline bool settingsRebootDialog; } + namespace text { + inline bool textBrowserDialog; + inline QString textBrowserContents; + } } // https://stackoverflow.com/questions/6080853/c-multiple-definition-error-for-global-functions-in-the-header-file/20679534#20679534 diff --git a/generaldialog.cpp b/generaldialog.cpp index 143aef7..65b26b3 100644 --- a/generaldialog.cpp +++ b/generaldialog.cpp @@ -94,6 +94,13 @@ generalDialog::generalDialog(QWidget *parent) : ui->headerLabel->setText("USB cable connected"); this->adjustSize(); } + else if(global::text::textBrowserDialog == true) { + textwidgetWindow = new textwidget(); + ui->headerLabel->setText("Information"); + ui->mainStackedWidget->insertWidget(1, textwidgetWindow); + ui->mainStackedWidget->setCurrentIndex(1); + this->adjustSize(); + } else { // We shouldn't be there ;) ; @@ -113,14 +120,11 @@ generalDialog::~generalDialog() void generalDialog::on_cancelBtn_clicked() { - if(resetDialog == true) { - generalDialog::close(); - } if(updateDialog == true) { string_writeconfig("/tmp/cancelUpdateDialog", "true"); generalDialog::close(); } - if(usbmsDialog == true) { + else { generalDialog::close(); } } @@ -192,6 +196,10 @@ void generalDialog::on_acceptBtn_clicked() qApp->quit(); } } + if(textBrowserDialog == true) { + global::text::textBrowserContents = ""; + global::text::textBrowserDialog = false; + } // We don't have any other option ;p generalDialog::close(); diff --git a/generaldialog.h b/generaldialog.h index 3431f1a..5de829d 100644 --- a/generaldialog.h +++ b/generaldialog.h @@ -4,6 +4,7 @@ #include #include "usbms_splash.h" +#include "textwidget.h" using namespace std; @@ -24,6 +25,7 @@ public: bool koboxSettingsRebootDialog = false; bool lowBatteryDialog = false; bool usbmsDialog = false; + bool textBrowserDialog = false; private slots: void on_cancelBtn_clicked(); @@ -33,6 +35,7 @@ private slots: private: Ui::generalDialog *ui; usbms_splash *usbmsWindow; + textwidget *textwidgetWindow; }; #endif // GENERALDIALOG_H diff --git a/generaldialog.ui b/generaldialog.ui index 421293c..82f1a02 100644 --- a/generaldialog.ui +++ b/generaldialog.ui @@ -16,19 +16,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -53,10 +40,10 @@ - + - 0 + 1 @@ -148,28 +135,110 @@ - - - - - Inter - 50 - false - + + + + Qt::Vertical - - Body + + + 20 + 40 + - - Qt::AlignCenter - - - true + + + + + + 1 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Inter + 50 + false + + + + Body + + + Qt::AlignCenter + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + - - + + Qt::Vertical diff --git a/inkbox.pro b/inkbox.pro index fafa4c8..75284c3 100644 --- a/inkbox.pro +++ b/inkbox.pro @@ -25,6 +25,7 @@ SOURCES += \ savedwords.cpp \ settings.cpp \ settingschooser.cpp \ + textwidget.cpp \ usbms_splash.cpp HEADERS += \ @@ -42,6 +43,7 @@ HEADERS += \ savedwords.h \ settings.h \ settingschooser.h \ + textwidget.h \ usbms_splash.h FORMS += \ @@ -58,6 +60,7 @@ FORMS += \ savedwords.ui \ settings.ui \ settingschooser.ui \ + textwidget.ui \ usbms_splash.ui # Default rules for deployment. diff --git a/mainwindow.cpp b/mainwindow.cpp index e9834ed..24e7f76 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -651,6 +651,13 @@ void MainWindow::on_pushButton_clicked() void MainWindow::on_searchBtn_clicked() { // Hopefully this button will do something one day... + /* + global::text::textBrowserDialog = true; + global::text::textBrowserContents = "Hullo"; + generalDialogWindow = new generalDialog(); + generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); + generalDialogWindow->show(); + */ } void MainWindow::on_quitBtn_clicked() diff --git a/mainwindow.h b/mainwindow.h index 35ca220..6009faf 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -13,6 +13,7 @@ #include "generaldialog.h" #include "koboxsettings.h" #include "koboxappsdialog.h" +#include "textwidget.h" using namespace std; @@ -76,5 +77,6 @@ private: generalDialog *generalDialogWindow; koboxSettings *koboxSettingsWindow; koboxAppsDialog *koboxAppsDialogWindow; + textwidget *textwidgetWindow; }; #endif // MAINWINDOW_H diff --git a/textwidget.cpp b/textwidget.cpp new file mode 100644 index 0000000..78c9c14 --- /dev/null +++ b/textwidget.cpp @@ -0,0 +1,26 @@ +#include "textwidget.h" +#include "ui_textwidget.h" +#include "functions.h" + +#include +#include + +textwidget::textwidget(QWidget *parent) : + QWidget(parent), + ui(new Ui::textwidget) +{ + ui->setupUi(this); + + // Stylesheet + QFile stylesheetFile(":/resources/eink.qss"); + stylesheetFile.open(QFile::ReadOnly); + this->setStyleSheet(stylesheetFile.readAll()); + stylesheetFile.close(); + + ui->textBrowser->setText(global::text::textBrowserContents); +} + +textwidget::~textwidget() +{ + delete ui; +} diff --git a/textwidget.h b/textwidget.h new file mode 100644 index 0000000..f17f7d7 --- /dev/null +++ b/textwidget.h @@ -0,0 +1,22 @@ +#ifndef TEXTWIDGET_H +#define TEXTWIDGET_H + +#include + +namespace Ui { +class textwidget; +} + +class textwidget : public QWidget +{ + Q_OBJECT + +public: + explicit textwidget(QWidget *parent = nullptr); + ~textwidget(); + +private: + Ui::textwidget *ui; +}; + +#endif // TEXTWIDGET_H diff --git a/textwidget.ui b/textwidget.ui new file mode 100644 index 0000000..fcc5b51 --- /dev/null +++ b/textwidget.ui @@ -0,0 +1,40 @@ + + + textwidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + +