-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathConfigDialog.cpp
124 lines (116 loc) · 3.76 KB
/
ConfigDialog.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
#include <QFileDialog>
#include <QMessageBox>
#include "ConfigDialog.h"
#include "VirtualTouchScreen.h"
ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent)
{
ui_.setupUi(this);
//setup
mainWnd_ = dynamic_cast<VirtualTouchScreen*>(parent);
if (NULL != mainWnd_) {
ui_.spinBoxThreshold->setValue(static_cast<int>(100*mainWnd_->virtualScreenThreshold_));
ui_.spinBoxOffsetX->setValue(mainWnd_->offset.x());
ui_.spinBoxOffsetY->setValue(mainWnd_->offset.y());
ui_.spinBoxScaleFactor->setValue(static_cast<int>(100*mainWnd_->scaleFactor));
//setup icons list
icons_["Fingerprint"] = ":/icons/fingerprint.png";
icons_["Black Circle"] = ":/icons/circleblack.png";
icons_["Round Shape"] = ":/icons/round.png";
QList<QString> keys = icons_.keys();
int curIdx = icons_.count();
int i = 0;
foreach(const QString key, keys)
{
QString iconPath = icons_.value(key);
if (iconPath == mainWnd_->fingerIcon_)
{
curIdx = i;
}
++i;
QIcon iconImage(iconPath);
if (!iconImage.isNull())
{
ui_.comboBoxFingerIcon->addItem(iconImage, key);
}
}
if (curIdx >= icons_.count())
{
QIcon icon(mainWnd_->fingerIcon_);
if (!icon.isNull())
{
int nbItems = icons_.count();
ui_.comboBoxFingerIcon->insertItem(nbItems, icon, mainWnd_->fingerIcon_);
}
else
{
curIdx = 0;//use default icon
}
}
ui_.comboBoxFingerIcon->setCurrentIndex(curIdx);
ui_.spinBoxIconSize->setValue(mainWnd_->fingerIconSize_);
ui_.checkBoxHideThumb->setChecked(mainWnd_->hideThumb_);
}
connect(ui_.pushButtonBrowse, SIGNAL(clicked(bool)), this, SLOT(onBrowse()));
connect(ui_.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(onOk()));
connect(ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(onCancel()));
connect(ui_.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(onApply()));
}
void ConfigDialog::onBrowse()
{
QFileDialog openFile(this, "Select an Image File");//always in the center of the screen
openFile.setFileMode(QFileDialog::ExistingFile);
openFile.setViewMode(QFileDialog::Detail);
openFile.setNameFilter("*.png *.jpg *.jpeg");
QStringList fileNames;
if (openFile.exec())
{
fileNames = openFile.selectedFiles();
if (0 < fileNames.size())
{
QIcon icon(fileNames[0]);
if (!icon.isNull())
{
int nbItems = icons_.count();
if (nbItems < ui_.comboBoxFingerIcon->count()) {
ui_.comboBoxFingerIcon->removeItem(nbItems);
}
ui_.comboBoxFingerIcon->insertItem(nbItems, icon, fileNames[0]);
ui_.comboBoxFingerIcon->setCurrentIndex(nbItems);
}
else
{
QMessageBox::warning(this, "Virtual Touch Screen", "Cannot load cursor pixmap");
}
}
}
}
void ConfigDialog::onOk()
{
onApply();
onCancel();
}
void ConfigDialog::onCancel()
{
hide();
}
void ConfigDialog::onApply()
{
if (NULL != mainWnd_) {
mainWnd_->virtualScreenThreshold_ = ui_.spinBoxThreshold->value()/100.0;
mainWnd_->offset.setX(ui_.spinBoxOffsetX->value());
mainWnd_->offset.setY(ui_.spinBoxOffsetY->value());
mainWnd_->scaleFactor = ui_.spinBoxScaleFactor->value()/100.0;
mainWnd_->fingerIcon_ = ui_.comboBoxFingerIcon->currentText();
int index = ui_.comboBoxFingerIcon->currentIndex();
if (index < icons_.count() && 0 <= index)
{
mainWnd_->fingerIcon_ = icons_.value(mainWnd_->fingerIcon_);
}
mainWnd_->fingerIconSize_ = ui_.spinBoxIconSize->value();
mainWnd_->loadFingerIcons(mainWnd_->fingerIcon_, mainWnd_->fingerIconSize_);
mainWnd_->hideThumb_ = ui_.checkBoxHideThumb->isChecked();
mainWnd_->onShowThumb(!mainWnd_->hideThumb_);
} else {
QMessageBox::warning(this, "Virtual Touch Screen", "Cannot apply settings");
}
}