-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsynchresultdialog.cpp
261 lines (216 loc) · 8.7 KB
/
synchresultdialog.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/** @file synchresultdialog.cp
* Soubor s tridou SynchResultDialog dedici ze tridy QDialog, ktera
* implementuje dialog s vysledky synchronizace
*/
#include "synchresultdialog.h"
SynchResultDialog::SynchResultDialog(QWidget* parent)
: QDialog(parent)
{
QPalette pal = this->palette();
pal.setColor(QPalette::Window, "#D0D0E7");
setPalette(pal);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
colorFailed = "#FFAA88"; //"#FFD8A7";
colorOk = "#AFFFA6";
colorOkUnchecked = "#FFFF77";
colorFailedChecked = "#FFDD77"; //"#FFE07F"; //"#FFD877";
legend = createLegend();
legendButton = new QPushButton(tr("Key"));
QDialogButtonBox* buttonBox = new QDialogButtonBox();
buttonBox->addButton(QDialogButtonBox::Save);
buttonBox->addButton(QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(buttonBox, SIGNAL(accepted()), parent, SLOT(saveSynchChanges()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
/////////////////////////////////////////////
timeEdit = new QTimeEdit;
timeEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
timeEdit->setDisplayFormat("hh:mm:ss");
checkButton = new QPushButton(tr("Check"));
checkButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(checkButton, SIGNAL(clicked()), this, SLOT(checkButtonClicked()));
/////////////////////////////////////////////
sa = new QScrollArea;
saveExifCheckbox = new QCheckBox(tr("Save in pictures EXIF data"));
QGridLayout* dialogLayout = new QGridLayout;
checkDistLabel = new QLabel(tr("Check pictures with time distance <"));
dialogLayout->addWidget(sa, 0, 0, 1, 4);
dialogLayout->addWidget(checkDistLabel, 1, 0, 1, 1);
dialogLayout->addWidget(timeEdit, 1, 1, 1, 1);
dialogLayout->addWidget(checkButton, 1, 2, 1, 1);
dialogLayout->addWidget(saveExifCheckbox, 2, 0, 1, 4);
dialogLayout->addWidget(legendButton, 3, 0, 1, 4);
dialogLayout->addWidget(legend, 4, 0, 1, 4);
dialogLayout->addWidget(buttonBox, 5, 0, 1, 4);
legend->setVisible(false);
legendButton->setCheckable(true);
legendButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(legendButton, SIGNAL(toggled(bool)), this, SLOT(legendButtonToggled(bool)));
this->setLayout(dialogLayout);
sa->setBackgroundRole(QPalette::Light);
sa->setWidgetResizable(true);
tw = new QTreeWidget;
sa->setWidget(tw);
tw->setHeaderLabels(QStringList()
<< tr("Picture")
<< tr("Picture Time")
<< tr("New coordinates")
<< tr("Synchronisation type")
<< tr("Time distance")
<< tr("From route"));
tw->setIndentation(0);
connect(tw, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*, int)));
tw->setSelectionMode(QAbstractItemView::ExtendedSelection);
checkItemsAction = new QAction(tr("Check selected"), tw);
connect(checkItemsAction, SIGNAL(triggered()), this, SLOT(checkSelectedItems()));
uncheckItemsAction = new QAction(tr("Uncheck selected"), tw);
connect(uncheckItemsAction, SIGNAL(triggered()), this, SLOT(uncheckSelectedItems()));
tw->setContextMenuPolicy(Qt::ActionsContextMenu);
tw->addAction(checkItemsAction);
tw->addAction(uncheckItemsAction);
this->adjustSize();
this->resize(QSize(700, 450));
this->setWindowTitle(tr("Synchronisation"));
}
void SynchResultDialog::retranslateUi()
{
this->setWindowTitle(tr("Synchronisation"));
checkButton->setText(tr("Check"));
checkItemsAction->setText(tr("Check selected"));
uncheckItemsAction->setText(tr("Uncheck selected"));
saveExifCheckbox->setText(tr("Save in pictures EXIF data"));
tw->setHeaderLabels(QStringList()
<< tr("Picture")
<< tr("Picture Time")
<< tr("New coordinates")
<< tr("Synchronisation type")
<< tr("Time distance")
<< tr("From route"));
checkDistLabel->setText(tr("Check pictures with time distance <"));
legend->setTitle(tr("Key"));
ltOk->setText(tr("Correctly assigned coordinates, will be saved"));
ltFailed->setText(tr("Picture time doesn't fit any route, no coordinates will be saved"));
ltOkUnchecked->setText(tr("Correctly assigned coordinates, won't be saved"));
ltFailedChecked->setText(tr("Picture time doesn't fit any route, will be saved coordinates of nearest known point"));
ltBold->setText(tr("Picture already has assigned coordinates"));
ltBoldShow->setText(tr("Bold"));
}
void SynchResultDialog::legendButtonToggled(bool n)
{
legend->setVisible(n);
if (n) {
resize(width(), height() + legend->height() + layout()->contentsMargins().bottom());
} else {
resize(width(), height() - legend->height() - layout()->contentsMargins().bottom());
}
}
QGroupBox* SynchResultDialog::createLegend()
{
QGroupBox* box = new QGroupBox(tr("Legend"));
box->setAutoFillBackground(true);
QPalette palBox = box->palette();
palBox.setColor(QPalette::Window, "#FFFFFF");
box->setPalette(palBox);
QGridLayout* l = new QGridLayout;
QLabel* lOk = new QLabel;
QLabel* lOkU = new QLabel;
QLabel* lFailed = new QLabel;
QLabel* lFailedC = new QLabel;
int size = lOk->style()->pixelMetric(QStyle::PM_SmallIconSize);
QPixmap pixmap(size, size);
pixmap.fill(QColor(colorOk));
lOk->setPixmap(pixmap);
pixmap.fill(QColor(colorOkUnchecked));
lOkU->setPixmap(pixmap);
pixmap.fill(QColor(colorFailed));
lFailed->setPixmap(pixmap);
pixmap.fill(QColor(colorFailedChecked));
lFailedC->setPixmap(pixmap);
ltOk = new QLabel(tr("Correctly assigned coordinates, will be saved"));
ltFailed = new QLabel(tr("Picture time doesn't fit any route, no coordinates will be saved"));
ltOkUnchecked = new QLabel(tr("Correctly assigned coordinates, won't be saved"));
ltFailedChecked = new QLabel(tr("Picture time doesn't fit any route, will be saved coordinates of nearest known point"));
ltBoldShow = new QLabel(tr("Bold"));
QFont font = ltBoldShow->font();
font.setBold(true);
ltBoldShow->setFont(font);
ltBold = new QLabel(tr("Picture already has assigned coordinates"));
l->addWidget(lOk, 0, 0);
l->addWidget(ltOk, 0, 1);
l->addWidget(lOkU, 1, 0);
l->addWidget(ltOkUnchecked, 1, 1);
l->addWidget(lFailed, 2, 0);
l->addWidget(ltFailed, 2, 1);
l->addWidget(lFailedC, 3, 0);
l->addWidget(ltFailedChecked, 3, 1);
l->addWidget(ltBoldShow, 4, 0);
l->addWidget(ltBold, 4, 1);
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
box->setLayout(l);
return box;
}
// pri vybrani "zaskrtnout vybrane" z kontextoveho menu
void SynchResultDialog::checkSelectedItems()
{
QTreeWidgetItem* twi;
foreach (twi, tw->selectedItems()) {
int i = tw->indexOfTopLevelItem(twi);
treeWidgetList.at(i)->setChecked(true);
}
}
void SynchResultDialog::uncheckSelectedItems()
{
QTreeWidgetItem* twi;
foreach (twi, tw->selectedItems()) {
int i = tw->indexOfTopLevelItem(twi);
treeWidgetList.at(i)->setChecked(false);
}
}
void SynchResultDialog::itemDoubleClicked(QTreeWidgetItem* twi, int col)
{
Q_UNUSED(col)
int i = tw->indexOfTopLevelItem(twi);
if (treeWidgetList.at(i)->checkBox->isEnabled()) {
treeWidgetList.at(i)->checkBox->toggle();
treeWidgetList.at(i)->setItemColor();
}
}
void SynchResultDialog::setNewDialog()
{
tw->clear();
treeWidgetList.clear();
}
void SynchResultDialog::addNewItem(ImageInfo* image, int existingGpsMode)
{
SynchResultItem* widget = new SynchResultItem(image, colorOk, colorFailed, colorOkUnchecked, colorFailedChecked, tw);
if (existingGpsMode == 1 && image->imageData->isGps) { // tucne, nezaskrtnout
widget->checkBox->setChecked(false);
}
treeWidgetList.append(widget);
image->synchCheckBox = widget->checkBox;
}
void SynchResultDialog::showDialog()
{
for (int i = 0; i < tw->columnCount(); i++) {
tw->resizeColumnToContents(i);
tw->setColumnWidth(i, tw->columnWidth(i) + 5);
}
tw->adjustSize();
sa->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
sa->resize(tw->width(), (tw->height() > 500 ? 500 : tw->height()));
resize(contentsRect().width() + 30, contentsRect().height() + 30);
exec();
}
void SynchResultDialog::checkButtonClicked()
{
int time = timeEdit->time().hour() * 3600 + timeEdit->time().minute() * 60 + timeEdit->time().second();
for (int i = 0; i < treeWidgetList.length(); i++) {
if (treeWidgetList.at(i)->timeDiff < time) {
treeWidgetList.at(i)->setChecked(true);
}
}
}
QSize SynchResultDialog::sizeHint()
{
return QSize(0, 0);
}