12
12
#include < QLabel>
13
13
#include < QProgressBar>
14
14
#include < QPushButton>
15
+ #include < QMessageBox>
15
16
16
17
FindAlignment::FindAlignment (Align *_align, bool update) {
17
18
align = _align;
18
19
update_positions = update;
19
20
visible = false ;
21
+ owned = true ;
20
22
}
21
23
22
24
void FindAlignment::run () {
23
25
setStatus (RUNNING);
24
26
27
+ QRect inner = align->rect ;
28
+ QString cache_filename = QString (" resources/align_%1x%2+%3+%4.jpg" )
29
+ .arg (inner.width ())
30
+ .arg (inner.height ())
31
+ .arg (inner.left ())
32
+ .arg (inner.top ());
33
+
34
+ QImage img (cache_filename);
35
+ if (!img.isNull ()) {
36
+ align->readCacheThumbs (img);
37
+ progressed (QString (" Done." ), 100 );
38
+ setStatus (DONE);
39
+ return ;
40
+ }
41
+
42
+
25
43
Project &project = qRelightApp->project ();
26
44
for (size_t i = 0 ; i < project.images .size (); i++) {
27
45
@@ -40,6 +58,7 @@ void FindAlignment::run() {
40
58
if (!progressed (QString (" Collecting patches" ), progress))
41
59
return ;
42
60
}
61
+ align->saveCacheThumbs (cache_filename);
43
62
progressed (QString (" Done" ), 100 );
44
63
setStatus (DONE);
45
64
}
@@ -90,8 +109,8 @@ AlignRow::AlignRow(Align *_align, QWidget *parent): QWidget(parent) {
90
109
91
110
edit_layout->setRowStretch (3 ,1 );
92
111
93
- connect (edit_button, &QPushButton::clicked, [this ]() { emit edit (this ); });
94
- connect (remove_button, &QPushButton:: clicked, [ this ]() { emit removeme ( this ); } );
112
+ connect (edit_button, &QPushButton::clicked, [this ]() { emit editme (this ); });
113
+ connect (remove_button, SIGNAL ( clicked ()), this , SLOT ( remove ()) );
95
114
connect (verify_button, SIGNAL (clicked ()), this , SLOT (verify ()));
96
115
}
97
116
@@ -101,24 +120,27 @@ AlignRow::~AlignRow() {
101
120
}
102
121
delete find_alignment;
103
122
}
104
- /*
105
- void AlignRow::edit() {
106
- MarkerDialog *marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this);
107
- marker_dialog->setAlign(align);
108
- int answer = marker_dialog->exec();
109
- if(answer == QDialog::Accepted) {
110
- position->rect = align->rect;
111
- position->update();
112
- updateRegion();
113
- findAlignment();
114
- }
115
- }*/
116
123
117
124
void AlignRow::verify () {
118
125
VerifyDialog *verify_dialog = new VerifyDialog (align->thumbs , align->offsets , VerifyDialog::ALIGN, this );
119
126
verify_dialog->exec ();
127
+
128
+ emit updated ();
120
129
}
121
130
131
+ void AlignRow::remove () {
132
+ stopFinding ();
133
+ auto &aligns = qRelightApp->project ().aligns ;
134
+ auto it = std::find (aligns.begin (), aligns.end (), align);
135
+ assert (it != aligns.end ());
136
+
137
+ delete align;
138
+ aligns.erase (it);
139
+
140
+ qRelightApp->project ().cleanAlignCache ();
141
+
142
+ emit removeme (this );
143
+ }
122
144
123
145
void AlignRow::updateRegion () {
124
146
QRectF r = align->rect ;
@@ -133,6 +155,12 @@ void AlignRow::setRect(QRectF rect) {
133
155
}
134
156
135
157
void AlignRow::updateStatus (QString msg, int percent) {
158
+ if (find_alignment->status == Task::FAILED) {
159
+ QMessageBox::critical (this , " Could not load patches!" , msg);
160
+ progress->setValue (0 );
161
+ return ;
162
+ }
163
+
136
164
status->setText (msg);
137
165
progress->setValue (percent);
138
166
// reflections->update();
@@ -164,6 +192,7 @@ void AlignRow::stopFinding() {
164
192
find_alignment->stop ();
165
193
find_alignment->wait ();
166
194
}
195
+ verify_button->setEnabled (true );
167
196
ProcessQueue &queue = ProcessQueue::instance ();
168
197
queue.removeTask (find_alignment);
169
198
}
0 commit comments