-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
173 lines (153 loc) · 5.74 KB
/
Copy pathmainwindow.cpp
File metadata and controls
173 lines (153 loc) · 5.74 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
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
/*-----------------------------------------------------------------------------
* This file is part of Gameroni -
* http://www.vitorian.com/x1/archives/419
* https://github.com/hftrader/gameroni
*
* Gameroni is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Gameroni is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
* -----------------------------------------------------------------------------*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileInfo>
#include <QSettings>
#include <QSet>
#include <QDebug>
#include <QMap>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect( ui->toolBox, SIGNAL(currentChanged(int)),
ui->wcDisplay, SLOT(setAlgorithm(int)) );
connect( ui->sbLaplacianRadius, SIGNAL(valueChanged(int)),
this, SLOT(updateState()) );
connect( ui->sbLaplacianKernel, SIGNAL(valueChanged(int)),
this, SLOT(updateState()) );
connect( ui->sbMotionDuration, SIGNAL(valueChanged(double)),
this, SLOT(updateState()) );
connect( ui->sbMotionWidth, SIGNAL(valueChanged(int)),
this, SLOT(updateState()) );
connect( ui->cbRigidTransform, SIGNAL(toggled(bool)),
this, SLOT(updateState()) );
connect( ui->cbMotionGrayscale, SIGNAL(toggled(bool)),
this, SLOT(updateState()) );
connect( ui->cbExecutable, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateExecutableChoice(int)));
// Try to remember last settings
QSettings qs;
lastKey = qs.value("LastExecutable").toString();
qDebug() << "Last key:" << lastKey;
populateProcessList();
ui->toolBox->setCurrentIndex(0);
ui->wcDisplay->setAlgorithm(0);
updateState();
popTimerId = startTimer( 5000 );
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::timerEvent(QTimerEvent *event)
{
if ( event->timerId() == popTimerId ) {
populateProcessList();
}
}
void MainWindow::populateProcessList()
{
// Get a list of processes
std::vector<ProcessInfo> plist;
getProcessList( plist, true );
// Create a list of QString items to populate the combo box
QVariantMap newMap;
for ( uint32_t j=0; j<plist.size(); ++j ) {
// Extract values
QString pname = QString::fromStdWString( plist[j].name );
QString exename = QString::fromStdWString( plist[j].process );
QString filename = QFileInfo( exename ).fileName();
QString key = filename + " | " + pname;
// Create variant map and update new map
QVariantMap pmap;
pmap["ExeName"] = exename;
pmap["Process"] = pname;
pmap["hWnd"] = uint64_t(plist[j].hWnd);
pmap["Filename"] = filename;
pmap["Key"] = key;
newMap[key] = pmap;
}
// Poor man's diff
QSet<QString> oldKeys, newKeys;
for ( QVariantMap::const_iterator ic = exeMap.constBegin(); ic!=exeMap.constEnd(); ++ic ) {
oldKeys.insert(ic.key());
}
for ( QVariantMap::const_iterator ic = newMap.constBegin(); ic!=newMap.constEnd(); ++ic ) {
newKeys.insert(ic.key());
}
// Added Keys
QSet<QString> addedKeys = newKeys - oldKeys;
for ( const QString& key : addedKeys ) {
QVariantMap pmap = newMap.value(key).toMap();
ui->cbExecutable->addItem( key, pmap );
qDebug() << "Adding key " << key;
}
// Removed keys
QSet<QString> removedKeys = oldKeys - newKeys;
for ( const QString& key : removedKeys ) {
int idx = ui->cbExecutable->findText( key );
ui->cbExecutable->removeItem( idx );
qDebug() << "Removing key " << key;
}
// Update keys
QSet<QString> currentKeys( newKeys );
currentKeys.intersect( oldKeys );
for ( const QString& key: currentKeys ) {
QVariantMap pmap = newMap.value(key).toMap();
int idx = ui->cbExecutable->findText( key );
ui->cbExecutable->setItemData( idx, pmap );
}
// Update map
exeMap = newMap;
int idx = ui->cbExecutable->findText( lastKey );
if ( idx>=0 ) {
ui->cbExecutable->setCurrentIndex( idx );
}
}
void MainWindow::updateExecutableChoice( int index )
{
QVariantMap qv = ui->cbExecutable->itemData( index ).toMap();
HWND hWnd = (HWND)qv["hWnd"].toULongLong();
ui->wcDisplay->updateWindow( hWnd );
// Update settings
lastKey = qv["Key"].toString();
QSettings qs;
qs.setValue( "LastExecutable", lastKey );
qs.sync();
qDebug() << "Updating process choice to " << lastKey;
}
void MainWindow::updateState()
{
int index = ui->toolBox->currentIndex();
QVariantMap vmap;
if ( index==0 ) { // Laplacian
vmap["Radius"] = ui->sbLaplacianRadius->value();
vmap["Kernel"] = ui->sbLaplacianKernel->value();
}
else if ( index==1 ) { // Motion
vmap["Duration"] = ui->sbMotionDuration->value();
vmap["Width"] = ui->sbMotionWidth->value();
vmap["RigidTransform"] = ui->cbRigidTransform->isChecked();
vmap["Grayscale"] = ui->cbMotionGrayscale->isChecked();
}
ui->wcDisplay->updateState( vmap );
}