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.
This commit is contained in:
Nicolas Mailloux 2021-06-08 07:49:52 -04:00
parent b91e30d05a
commit 9428483d02
10 changed files with 220 additions and 36 deletions

View file

@ -46,6 +46,10 @@ namespace global {
namespace settings { namespace settings {
inline bool settingsRebootDialog; 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 // https://stackoverflow.com/questions/6080853/c-multiple-definition-error-for-global-functions-in-the-header-file/20679534#20679534

View file

@ -94,6 +94,13 @@ generalDialog::generalDialog(QWidget *parent) :
ui->headerLabel->setText("USB cable connected"); ui->headerLabel->setText("USB cable connected");
this->adjustSize(); 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 { else {
// We shouldn't be there ;) // We shouldn't be there ;)
; ;
@ -113,14 +120,11 @@ generalDialog::~generalDialog()
void generalDialog::on_cancelBtn_clicked() void generalDialog::on_cancelBtn_clicked()
{ {
if(resetDialog == true) {
generalDialog::close();
}
if(updateDialog == true) { if(updateDialog == true) {
string_writeconfig("/tmp/cancelUpdateDialog", "true"); string_writeconfig("/tmp/cancelUpdateDialog", "true");
generalDialog::close(); generalDialog::close();
} }
if(usbmsDialog == true) { else {
generalDialog::close(); generalDialog::close();
} }
} }
@ -192,6 +196,10 @@ void generalDialog::on_acceptBtn_clicked()
qApp->quit(); qApp->quit();
} }
} }
if(textBrowserDialog == true) {
global::text::textBrowserContents = "";
global::text::textBrowserDialog = false;
}
// We don't have any other option ;p // We don't have any other option ;p
generalDialog::close(); generalDialog::close();

View file

@ -4,6 +4,7 @@
#include <QDialog> #include <QDialog>
#include "usbms_splash.h" #include "usbms_splash.h"
#include "textwidget.h"
using namespace std; using namespace std;
@ -24,6 +25,7 @@ public:
bool koboxSettingsRebootDialog = false; bool koboxSettingsRebootDialog = false;
bool lowBatteryDialog = false; bool lowBatteryDialog = false;
bool usbmsDialog = false; bool usbmsDialog = false;
bool textBrowserDialog = false;
private slots: private slots:
void on_cancelBtn_clicked(); void on_cancelBtn_clicked();
@ -33,6 +35,7 @@ private slots:
private: private:
Ui::generalDialog *ui; Ui::generalDialog *ui;
usbms_splash *usbmsWindow; usbms_splash *usbmsWindow;
textwidget *textwidgetWindow;
}; };
#endif // GENERALDIALOG_H #endif // GENERALDIALOG_H

View file

@ -16,19 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="5" 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>
<item row="0" column="0"> <item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin"> <property name="bottomMargin">
@ -53,10 +40,10 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="6" column="0"> <item row="8" column="0">
<widget class="QStackedWidget" name="stackedWidget"> <widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="page"> <widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -148,28 +135,110 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="1" column="0">
<widget class="QLabel" name="bodyLabel"> <spacer name="verticalSpacer_3">
<property name="font"> <property name="orientation">
<font> <enum>Qt::Vertical</enum>
<family>Inter</family>
<weight>50</weight>
<bold>false</bold>
</font>
</property> </property>
<property name="text"> <property name="sizeHint" stdset="0">
<string>Body</string> <size>
<width>20</width>
<height>40</height>
</size>
</property> </property>
<property name="alignment"> </spacer>
<set>Qt::AlignCenter</set> </item>
</property> <item row="6" column="0">
<property name="wordWrap"> <widget class="QStackedWidget" name="mainStackedWidget">
<bool>true</bool> <property name="currentIndex">
<number>1</number>
</property> </property>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_4">
<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="2" 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>
<item row="1" column="0">
<widget class="QLabel" name="bodyLabel">
<property name="font">
<font>
<family>Inter</family>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Body</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" 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>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_4">
<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>
</layout>
</widget>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="7" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer_4">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>

View file

@ -25,6 +25,7 @@ SOURCES += \
savedwords.cpp \ savedwords.cpp \
settings.cpp \ settings.cpp \
settingschooser.cpp \ settingschooser.cpp \
textwidget.cpp \
usbms_splash.cpp usbms_splash.cpp
HEADERS += \ HEADERS += \
@ -42,6 +43,7 @@ HEADERS += \
savedwords.h \ savedwords.h \
settings.h \ settings.h \
settingschooser.h \ settingschooser.h \
textwidget.h \
usbms_splash.h usbms_splash.h
FORMS += \ FORMS += \
@ -58,6 +60,7 @@ FORMS += \
savedwords.ui \ savedwords.ui \
settings.ui \ settings.ui \
settingschooser.ui \ settingschooser.ui \
textwidget.ui \
usbms_splash.ui usbms_splash.ui
# Default rules for deployment. # Default rules for deployment.

View file

@ -651,6 +651,13 @@ void MainWindow::on_pushButton_clicked()
void MainWindow::on_searchBtn_clicked() void MainWindow::on_searchBtn_clicked()
{ {
// Hopefully this button will do something one day... // 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() void MainWindow::on_quitBtn_clicked()

View file

@ -13,6 +13,7 @@
#include "generaldialog.h" #include "generaldialog.h"
#include "koboxsettings.h" #include "koboxsettings.h"
#include "koboxappsdialog.h" #include "koboxappsdialog.h"
#include "textwidget.h"
using namespace std; using namespace std;
@ -76,5 +77,6 @@ private:
generalDialog *generalDialogWindow; generalDialog *generalDialogWindow;
koboxSettings *koboxSettingsWindow; koboxSettings *koboxSettingsWindow;
koboxAppsDialog *koboxAppsDialogWindow; koboxAppsDialog *koboxAppsDialogWindow;
textwidget *textwidgetWindow;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

26
textwidget.cpp Normal file
View file

@ -0,0 +1,26 @@
#include "textwidget.h"
#include "ui_textwidget.h"
#include "functions.h"
#include <QFile>
#include <QProcess>
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;
}

22
textwidget.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef TEXTWIDGET_H
#define TEXTWIDGET_H
#include <QWidget>
namespace Ui {
class textwidget;
}
class textwidget : public QWidget
{
Q_OBJECT
public:
explicit textwidget(QWidget *parent = nullptr);
~textwidget();
private:
Ui::textwidget *ui;
};
#endif // TEXTWIDGET_H

40
textwidget.ui Normal file
View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>textwidget</class>
<widget class="QWidget" name="textwidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<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">
<item row="0" column="0">
<widget class="QTextBrowser" name="textBrowser"/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>