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