-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
88 lines (77 loc) · 2.12 KB
/
mainwindow.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "mainwindow.h"
#include <DMainWindow>
#include <DTitlebar>
#include <QtWidgets/QVBoxLayout>
#include <DToolButton>
#include <QFileInfo>
DWIDGET_USE_NAMESPACE
MainWindow::MainWindow(QString szTitle,
QString szUrl,
int nWidth,
int nHeight,
QWidget *parent)
: DMainWindow(parent)
, m_widget(nullptr)
{
m_widget = new Widget(szUrl);
setFixedSize(nWidth, nHeight);
titlebar()->setTitle(szTitle);
setCentralWidget(m_widget);
centralWidget()->layout()->setContentsMargins(0, 0, 0, 0);
titlebar()->setIcon(QIcon(":/images/logo.svg"));
DToolButton *btnBack = new DToolButton(titlebar());
btnBack->setIcon(QIcon(":/images/go-previous-24.svg"));
btnBack->setIconSize(QSize(36, 36));
DToolButton *btnForward = new DToolButton(titlebar());
btnForward->setIcon(QIcon(":/images/go-next-24.svg"));
btnForward->setIconSize(QSize(36, 36));
DToolButton *btnRefresh = new DToolButton(titlebar());
btnRefresh->setIcon(QIcon(":/images/view-refresh.svg"));
btnRefresh->setIconSize(QSize(36, 36));
connect(btnBack, &DToolButton::clicked, this, [&]()
{
if (m_widget)
{
m_widget->goBack();
}
});
connect(btnForward, &DToolButton::clicked, this, [&]()
{
if (m_widget)
{
m_widget->goForward();
}
});
connect(btnRefresh, &DToolButton::clicked, this, [&]()
{
if (m_widget)
{
m_widget->refresh();
}
});
titlebar()->addWidget(btnBack, Qt::AlignLeft);
titlebar()->addWidget(btnForward, Qt::AlignLeft);
titlebar()->addWidget(btnRefresh, Qt::AlignLeft);
}
MainWindow::~MainWindow()
{
emit sigQuit();
if (m_widget)
{
delete m_widget;
m_widget = nullptr;
}
}
void MainWindow::setIcon(QString szIconPath)
{
QFileInfo fi(szIconPath);
if (fi.exists())
{
titlebar()->setIcon(QIcon(szIconPath));
qDebug() << szIconPath << "is Set!";
}
else
{
qDebug() << szIconPath << "is Not Exists!";
}
}