-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
133 lines (114 loc) · 3.73 KB
/
mainwindow.cpp
File metadata and controls
133 lines (114 loc) · 3.73 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "mainwindow.h"
#include "theme.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setup_views(this, *ui);
lightThemeStyle = QStyleFactory::create("windowsvista");
darkThemeStyle = QStyleFactory::create("fusion");
themeContents = darkTheme;
themeState = darkThemeState;
QApplication::setStyle(QStyleFactory::create("fusion"));
this->setStyleSheet(themeContents);
rightShiftTimer = new QTimer(this);
leftShiftTimer = new QTimer(this);
QObject::connect(rightShiftTimer,&QTimer::timeout,
this, &MainWindow::shiftTimerHandle);
QObject::connect(leftShiftTimer,&QTimer::timeout,
this, &MainWindow::shiftTimerHandle);
QObject::connect(this,&MainWindow::openRecentFilesDialog,
view_handler.get(),&ViewsHandler::openRecentFilesDialogHandle);
QObject::connect(this,&MainWindow::startSearchAll,
view_handler.get(),&ViewsHandler::startTextSearchInAllFilesHandle);
QObject::connect(this,&MainWindow::startFileSearch,
view_handler.get(),&ViewsHandler::startFileSearchHandle);
QObject::connect(this,&MainWindow::sendFocusToNavigationView,
view_handler.get(),&ViewsHandler::sendFocusToNavigationViewHandler);
QObject::connect(this,&MainWindow::editLock,
view_handler.get(),&ViewsHandler::editLockHandle);
#ifdef _WIN32
win = &WindowApi::instance();
QObject::connect(win, &WindowApi::showApp,
this,&MainWindow::showHideApp);
#endif
}
MainWindow::~MainWindow()
{
delete rightShiftTimer;
delete lightThemeStyle;
delete darkThemeStyle;
//delete ui;
}
void MainWindow::keyReleaseEvent(QKeyEvent *event)
{
switch (event->nativeScanCode()) {
case RIGHT_SHIFT_KEY:
if(rightShiftTimer->isActive()){
emit startSearchAll();
}
rightShiftTimer->start(DOUBLE_SHIFT_TIMER_MS);
leftShiftTimer->stop();
break;
case LEFT_SHIFT_KEY:
if(leftShiftTimer->isActive()){
emit startFileSearch();
}
leftShiftTimer->start(DOUBLE_SHIFT_TIMER_MS);
rightShiftTimer->stop();
break;
default:
rightShiftTimer->stop();
leftShiftTimer->stop();
};
switch(event->key()){
case Qt::Key_Escape:
emit sendFocusToNavigationView();
break;
case Qt::Key_F12:
if (themeState == darkThemeState){
themeState = lightThemeState;
this->setStyleSheet(lightTheme);
QApplication::setStyle(lightThemeStyle);
}else{
themeState = darkThemeState;
this->setStyleSheet(darkTheme);
QApplication::setStyle(darkThemeStyle);
}
break;
case Qt::Key_L:{
if(event->modifiers() == Qt::AltModifier){
emit editLock();
}
}
}
}
void MainWindow::recentFilesHandler(bool show)
{
emit openRecentFilesDialog(show);
}
void MainWindow::showHideApp()
{
#ifdef _WIN32
if(this->isMinimized()){
this->showNormal();
}else{
if(QWidget::winId() == win->GetForegroundWindowInvoke()){
this->showMinimized();
}else{
this->showMinimized();
this->showNormal();
}
}
#endif
}
void MainWindow::shiftTimerHandle()
{
rightShiftTimer->stop();
leftShiftTimer->stop();
}
void MainWindow::setup_views(QWidget *parent, Ui::MainWindow &ui)
{
view_handler = ViewsHandler::getInstance(parent, ui);
}