-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmainwindow.cpp
83 lines (65 loc) · 2.37 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
#include "mainwindow.h"
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QDesktopWidget>
#include <QPropertyAnimation>
#include <QApplication>
#include <QRect>
#include <QStatusBar>
#include <QSettings>
MainWindow::MainWindow(){
downloader = new DownloadWidget;
setWindowTitle("Download Manager");
setCentralWidget(downloader);
setup();
loadSettings();
startUpAnimation();
}
MainWindow::~MainWindow(){
saveSettings();
}
void MainWindow::setup(){
QMenu *fileMenu = menuBar()->addMenu("File");
add = new QAction("New", this);
fileMenu->addAction(add);
add->setShortcut(QKeySequence::New);
connect(add, SIGNAL(triggered(bool)), downloader, SLOT(start()));
remove = new QAction("Remove", this);
fileMenu->addAction(remove);
remove->setShortcut(QKeySequence::Delete);
connect(remove, SIGNAL(triggered(bool)), downloader, SLOT(remove()));
fileMenu->addSeparator();
auto exitFromProgram = new QAction("Exit", this);
fileMenu->addAction(exitFromProgram);
exitFromProgram->setShortcut(QKeySequence::Quit);
connect(exitFromProgram, SIGNAL(triggered(bool)), this, SLOT(close()));
QMenu *downloadMenu = menuBar()->addMenu("Download");
resume = new QAction("Resume", this);
downloadMenu->addAction(resume);
resume->setShortcut(QKeySequence("CTRL+R"));
connect(resume, SIGNAL(triggered(bool)), downloader, SLOT(resume()));
abort = new QAction("Abort", this);
downloadMenu->addAction(abort);
abort->setShortcut(QKeySequence("CTRL+A"));
connect(abort, SIGNAL(triggered(bool)), downloader, SLOT(abort()));
}
void MainWindow::startUpAnimation(){
QPropertyAnimation *fadein_animation = new QPropertyAnimation(this, "windowOpacity", this);
fadein_animation->setStartValue(0);
fadein_animation->setEndValue(1);
fadein_animation->setDuration(410);
fadein_animation->start();
}
void MainWindow::saveSettings(){
QSettings settings("Download Manager", "Dimensions");
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
}
void MainWindow::loadSettings(){
QSettings settings("Download Manager", "Dimensions");
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(960, 640)).toSize());
move(settings.value("pos", QPoint(50, 50)).toPoint());
settings.endGroup();
}