/
mainwindow.cpp
executable file
·80 lines (68 loc) · 2.57 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//get geometry
QDesktopWidget desktop;
QRect primaryScreenGeometry = desktop.availableGeometry(desktop.primaryScreen());
int frameHeightDifference = desktop.frameGeometry().height() - primaryScreenGeometry.height();
//define window parameters
this->setGeometry(0,0,250,primaryScreenGeometry.height() - frameHeightDifference);
this->move(primaryScreenGeometry.topLeft());
//window flags
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint);
//toolbar spacer for right alignet items
QWidget* spacer = new QWidget();
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
//add spacer to toolbar
ui->toolBar->addWidget(spacer);
//help menu
QMenu* helpMenu = new QMenu(this);
helpMenu->addAction(ui->actionAbout);
//help icon
QIcon helpIcon;
helpIcon.addFile(QStringLiteral(":/Icons/Help"), QSize(), QIcon::Normal, QIcon::Off);
//help button
QToolButton* helpButton = new QToolButton();
helpButton->setMenu(helpMenu);
helpButton->setPopupMode(QToolButton::InstantPopup);
helpButton->setStyleSheet("QToolButton::menu-indicator{ image: url(none.jpg); }");
helpButton->setIcon(helpIcon);
helpButton->setToolTip("Help");
//help menu to toolbar
ui->toolBar->addWidget(helpButton);
//set splitter initial size
ui->splitter->setStretchFactor(0,2);
ui->splitter->setStretchFactor(1,1);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionAdd_New_Host_triggered()
{
ui->treeView_Hosts->addHost();
}
void MainWindow::on_actionEdit_Selected_Host_triggered()
{
ui->treeView_Hosts->editHost();
}
void MainWindow::on_actionRemove_Host_triggered()
{
ui->treeView_Hosts->removeHost();
}
void MainWindow::closeEvent(QCloseEvent*)
{
this->destroy(true, true);
QCoreApplication::quit();
}
void MainWindow::on_actionAbout_triggered()
{
QString aboutText = QString("<b>").append(APPLICATION_NAME).append(" ").append(APPLICATION_VERSION).append("</b><br>\n<br>\n");
aboutText.append("Access <a href='https://github.com/renatoferreirarenatoferreira/quickmon'>").append(APPLICATION_NAME).append(" Project on GitHub</a>!");
QMessageBox::about(this, QString("About ").append(APPLICATION_NAME), aboutText);
}