forked from zhengran14/SwitchGamepad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minitool.cpp
202 lines (177 loc) · 5.39 KB
/
minitool.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "minitool.h"
#include "ui_minitool.h"
#include <QWindow>
#include <QMouseEvent>
#include <QDebug>
MiniTool::MiniTool(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MiniTool)
{
this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
ui->setupUi(this);
ui->centralwidget->installEventFilter(this);
ui->videoCaptureFrame->installEventFilter(this);
}
MiniTool::~MiniTool()
{
delete ui;
}
void MiniTool::clearScriptList()
{
ui->scriptList->blockSignals(true);
ui->scriptList->clear();
ui->scriptList->blockSignals(false);
}
void MiniTool::AddScriptList(QStringList scripts)
{
ui->scriptList->blockSignals(true);
for(QString script : scripts) {
ui->scriptList->addItem(script.split(".")[0]);
}
ui->scriptList->blockSignals(false);
}
void MiniTool::AddScript(QString script)
{
ui->scriptList->blockSignals(true);
ui->scriptList->addItem(script.split(".")[0]);
ui->scriptList->blockSignals(false);
}
void MiniTool::InsertScript(int index, QString script)
{
ui->scriptList->blockSignals(true);
ui->scriptList->insertItem(index, script.split(".")[0]);
ui->scriptList->blockSignals(true);
}
void MiniTool::RefreshScriptList(QStringList scripts)
{
clearScriptList();
AddScriptList(scripts);
}
QLayout *MiniTool::GetVideoCaptionFrameLayout()
{
return ui->videoCaptureFrame->layout();
}
void MiniTool::setScriptRunText(QString text)
{
ui->runScript->setText(text);
}
void MiniTool::setScriptName(int index, QString name)
{
ui->scriptList->setItemText(index, name);
}
void MiniTool::setScriptListCurrentIndex(int index)
{
ui->scriptList->blockSignals(true);
ui->scriptList->setCurrentIndex(index);
ui->scriptList->blockSignals(false);
}
void MiniTool::adjustVideoCaptionFrameLayout()
{
ui->videoCaptureFrame->setGeometry(0, 0, ui->videoCaptureFrameParent->width(), ui->videoCaptureFrameParent->height());
ui->zoom->move(ui->videoCaptureFrameParent->width() - ui->zoom->width(), ui->videoCaptureFrameParent->height() - ui->zoom->height());
// ui->videoCaptureFrame->repaint();
}
void MiniTool::setScriptListEnabled(bool b)
{
ui->scriptList->setEnabled(b);
}
void MiniTool::setScriptRunEnabled(bool b)
{
ui->runScript->setEnabled(b);
}
bool MiniTool::eventFilter(QObject *target, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress) {
if (target != ui->videoCaptureFrame) {
if (!ui->resize->isChecked()) {
this->windowHandle()->startSystemMove();
}
}
else {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
lastPoint = mouseEvent->pos();
}
return true;
}
else if (event->type() == QEvent::MouseMove) {
if (target == ui->videoCaptureFrame) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (lastPoint.x() != 0 && lastPoint.y() != 0) {
QPoint p = mouseEvent->pos() - lastPoint;
ui->videoCaptureFrame->move(ui->videoCaptureFrame->pos() + p);
}
else {
lastPoint = mouseEvent->pos();
}
return true;
}
}
// switch (event->type()) {
// case QEvent::MouseMove: {
// const int border = 5;
// QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
// Qt::Edges edge = 0;
// if (mouseEvent->pos().x() < border) edge |= Qt::LeftEdge;
// if (mouseEvent->pos().x() >= this->width() - border) edge |= Qt::RightEdge;
// if (mouseEvent->pos().y() < border) edge |= Qt::TopEdge;
// if (mouseEvent->pos().y() >= this->height() - border) edge |= Qt::BottomEdge;
// if (edge == 0) {
// this->windowHandle()->startSystemMove();
// }
// else {
// qDebug() << this->windowHandle()->startSystemResize(edge);
// }
// return true;
// }
// }
return QWidget::eventFilter(target, event);
}
void MiniTool::resizeEvent(QResizeEvent *event)
{
adjustVideoCaptionFrameLayout();
QWidget::resizeEvent(event);
}
void MiniTool::on_resize_clicked(bool checked)
{
if (checked) {
this->setWindowFlags(this->windowFlags() & ~Qt::FramelessWindowHint);
}
else {
this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint);
}
this->show();
}
void MiniTool::on_runScript_clicked()
{
emit runScriptClicked();
}
void MiniTool::on_scriptList_currentIndexChanged(int index)
{
emit scriptListCurrentIndexChanged(index);
}
void MiniTool::on_showMainWindow_clicked()
{
((QMainWindow*)this->parent())->show();
}
void MiniTool::on_zoomIn_clicked()
{
QRect rc = ui->videoCaptureFrame->geometry();
ui->videoCaptureFrame->setGeometry(rc.x() - 20, rc.y() - 20, rc.width() + 40, rc.height() + 40);
}
void MiniTool::on_zoomOut_clicked()
{
QRect rc = ui->videoCaptureFrame->geometry();
rc.setWidth(rc.width() - 40);
rc.setHeight(rc.height() - 40);
rc.moveTo(rc.x() + 20, rc.y() + 20);
if (rc.width() < ui->videoCaptureFrameParent->width() || rc.height() < ui->videoCaptureFrameParent->height()) {
ui->videoCaptureFrame->setGeometry(0, 0, ui->videoCaptureFrameParent->width(), ui->videoCaptureFrameParent->height());
}
else {
ui->videoCaptureFrame->setGeometry(rc);
}
}
void MiniTool::on_restore_clicked()
{
adjustVideoCaptionFrameLayout();
}