1 #include <QtDebug>
2 #include "utility.h"
3 #include "helpwindow.h"
4 #include "ui_helpwindow.h"
5 
6 HelpWindow* HelpWindow::self = nullptr;
7 
HelpWindow(QWidget * parent)8 HelpWindow::HelpWindow(QWidget *parent) :
9     QDialog(parent),
10     ui(new Ui::HelpWindow)
11 {
12     ui->setupUi(this);
13     setWindowFlags(Qt::Window);
14 
15     readSettings();
16 }
17 
~HelpWindow()18 HelpWindow::~HelpWindow()
19 {
20     writeSettings();
21     delete ui;
22 }
23 
closeEvent(QCloseEvent * event)24 void HelpWindow::closeEvent(QCloseEvent *event)
25 {
26     Q_UNUSED(event);
27     writeSettings();
28 }
29 
readSettings()30 void HelpWindow::readSettings()
31 {
32     QSettings settings;
33     if (settings.value("Main/SaveRestorePositions", false).toBool())
34     {
35         resize(settings.value("HelpViewer/WindowSize", QSize(600, 700)).toSize());
36         move(Utility::constrainedWindowPos(settings.value("HelpViewer/WindowPos", QPoint(50, 50)).toPoint()));
37     }
38 }
39 
writeSettings()40 void HelpWindow::writeSettings()
41 {
42     QSettings settings;
43 
44     if (settings.value("Main/SaveRestorePositions", false).toBool())
45     {
46         settings.setValue("HelpViewer/WindowSize", size());
47         settings.setValue("HelpViewer/WindowPos", pos());
48     }
49 }
50 
getRef()51 HelpWindow* HelpWindow::getRef()
52 {
53     if (!self)
54     {
55         self = new HelpWindow();
56     }
57 
58     return self;
59 }
60 
showHelp(QString help)61 void HelpWindow::showHelp(QString help)
62 {
63     QString url = QCoreApplication::applicationDirPath() + "/help/" + help;
64     qDebug() << "Searching for " << url;
65     ui->textHelp->setSource(url);
66 
67     readSettings();
68     self->show();
69 }
70 
71 
72