Skip to content

Commit fc8fc1e

Browse files
committed
refactoring align edit dialog
1 parent 822f7b8 commit fc8fc1e

10 files changed

+158
-60
lines changed

relightlab/alignframe.cpp

+86-35
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,47 @@
1111
#include <QHBoxLayout>
1212
#include <QGraphicsRectItem>
1313
#include <QPushButton>
14+
#include <QStackedWidget>
1415

1516
#include <iostream>
1617
using namespace std;
1718

1819
AlignFrame::AlignFrame(QWidget *parent): QFrame(parent) {
19-
QVBoxLayout *content = new QVBoxLayout(this);
20-
21-
content->addSpacing(10);
22-
QPushButton *new_align = new QPushButton("New alignment...");
23-
new_align->setProperty("class", "large");
24-
content->addWidget(new_align);
25-
new_align->setMinimumWidth(200);
26-
new_align->setMaximumWidth(300);
27-
28-
QFrame *aligns_frame = new QFrame;
29-
content->addWidget(aligns_frame, 0);
30-
aligns = new QVBoxLayout(aligns_frame);
31-
32-
content->addStretch(1);
33-
//content->addStretch();
34-
connect(new_align, SIGNAL(clicked()), this, SLOT(newAlign()));
20+
21+
stack = new QStackedWidget;
22+
23+
{
24+
QFrame *align_rows = new QFrame;
25+
QVBoxLayout *content = new QVBoxLayout(align_rows);
26+
content->addSpacing(10);
27+
{
28+
QPushButton *new_align = new QPushButton("New alignment...");
29+
new_align->setProperty("class", "large");
30+
new_align->setMinimumWidth(200);
31+
new_align->setMaximumWidth(300);
32+
connect(new_align, SIGNAL(clicked()), this, SLOT(newAlign()));
33+
content->addWidget(new_align);
34+
}
35+
{
36+
QFrame *aligns_frame = new QFrame;
37+
content->addWidget(aligns_frame, 0);
38+
aligns = new QVBoxLayout(aligns_frame);
39+
}
40+
content->addStretch(1);
41+
42+
stack->addWidget(align_rows);
43+
}
44+
45+
{
46+
marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this);
47+
marker_dialog->setWindowFlags(Qt::Widget);
48+
connect(marker_dialog, SIGNAL(accepted()), this, SLOT(okMarker()));
49+
connect(marker_dialog, SIGNAL(rejected()), this, SLOT(cancelMarker()));
50+
stack->addWidget(marker_dialog);
51+
}
52+
53+
QVBoxLayout *layout = new QVBoxLayout(this);
54+
layout->addWidget(stack);
3555
}
3656

3757
void AlignFrame::clear() {
@@ -50,39 +70,61 @@ void AlignFrame::init() {
5070
}
5171
}
5272

53-
/* on user button press */
54-
void AlignFrame::newAlign() {
55-
if(!marker_dialog)
56-
marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this);
73+
void AlignFrame::okMarker() {
74+
75+
AlignRow *row = findRow(provisional_align);
5776

58-
Align *align = new Align(qRelightApp->project().images.size());
59-
marker_dialog->setAlign(align);
60-
int answer = marker_dialog->exec();
61-
if(answer == QDialog::Rejected) {
62-
delete align;
63-
return;
77+
provisional_align->rect = marker_dialog->getAlign();
78+
if(!row) { //new align
79+
qRelightApp->project().aligns.push_back(provisional_align);
80+
row = addAlign(provisional_align);
81+
} else {
82+
row->setRect(provisional_align->rect);
6483
}
65-
qRelightApp->project().aligns.push_back(align);
66-
AlignRow *row = addAlign(align);
6784
row->findAlignment();
85+
86+
provisional_align = nullptr;
87+
stack->setCurrentIndex(0);
88+
89+
}
90+
91+
void AlignFrame::cancelMarker() {
92+
AlignRow *row = findRow(provisional_align);
93+
94+
if(!row) //this was a new align cancelled
95+
delete provisional_align;
96+
97+
provisional_align = nullptr;
98+
stack->setCurrentIndex(0);
99+
}
100+
101+
102+
/* on user button press */
103+
void AlignFrame::newAlign() {
104+
stack->setCurrentIndex(1);
105+
provisional_align = new Align(qRelightApp->project().images.size());
106+
marker_dialog->setAlign(provisional_align);
107+
}
108+
109+
110+
void AlignFrame::editAlign(AlignRow *row) {
111+
stack->setCurrentIndex(1); //needs to be called before setAlign, for correct resize.
112+
provisional_align = row->align;
113+
marker_dialog->setAlign(provisional_align);
68114
}
69115

70116
void AlignFrame::projectUpdate() {
71117
auto &project = qRelightApp->project();
72118
project.computeOffsets();
73-
74-
auto offsets = qRelightApp->project().offsets;
75-
for(auto &o: offsets) {
76-
o -= project.offsets[0];
77-
cout << o.x() << " " << o.y() << endl;
78-
}
79-
80119
}
81120

82121
AlignRow *AlignFrame::addAlign(Align *align) {
83122
AlignRow *row = new AlignRow(align);
84123
aligns->addWidget(row);
85124

125+
cout << aligns->children().size() << endl;
126+
127+
connect(row, SIGNAL(edit(AlignRow *)), this, SLOT(editAlign(AlignRow *)));
86128
connect(row, SIGNAL(removeme(AlignRow *)), this, SLOT(removeAlign(AlignRow *)));
87129
connect(row, SIGNAL(updated()), this, SLOT(projectUpdate()));
88130
return row;
@@ -105,3 +147,12 @@ void AlignFrame::removeAlign(AlignRow *row) {
105147
delete row;
106148
projectUpdate();
107149
}
150+
151+
AlignRow *AlignFrame::findRow(Align *align) {
152+
for(int i = 0; i < aligns->count(); i++) {
153+
AlignRow *r = static_cast<AlignRow *>(aligns->itemAt(i)->widget());
154+
if(r->align == align)
155+
return r;
156+
}
157+
return nullptr;
158+
}

relightlab/alignframe.h

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Align;
99
class AlignRow;
1010
class MarkerDialog;
1111
class QVBoxLayout;
12+
class QStackedWidget;
1213

1314
class AlignFrame: public QFrame {
1415
Q_OBJECT
@@ -21,11 +22,18 @@ Q_OBJECT
2122
public slots:
2223
void projectUpdate();
2324
void newAlign();
25+
void editAlign(AlignRow *align);
2426
void removeAlign(AlignRow *align);
27+
void okMarker();
28+
void cancelMarker();
2529

2630
private:
31+
Align *provisional_align = nullptr;
32+
QStackedWidget *stack = nullptr;
2733
MarkerDialog *marker_dialog = nullptr;
2834
QVBoxLayout *aligns = nullptr;
35+
36+
AlignRow *findRow(Align *align);
2937
};
3038

3139
#endif // ALIGNFRAME_H

relightlab/alignpicking.cpp

+20-11
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ void AlignRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidg
3333

3434
QVariant AlignRect::itemChange(GraphicsItemChange change, const QVariant &value) {
3535
if ((change == ItemPositionChange && scene()) || change == ItemScenePositionHasChanged) {
36-
picker->updateAlignPoint();
36+
// picker->updateAlignPoint();
3737
}
3838
return QGraphicsItem::itemChange(change, value);
3939
}
4040

41+
void AlignRect::setRect(QRectF r) {
42+
prepareGeometryChange(); // Notify the scene about bounding rect change
43+
QRectF oldRect = boundingRect();
44+
rect = r;
45+
update(oldRect.united(boundingRect())); // Repaint both old and new areas
46+
}
47+
4148

4249

4350

@@ -55,13 +62,14 @@ void AlignPicking::clear() {
5562
if(rect) {
5663
scene().removeItem(rect);
5764
}
65+
// align = nullptr;
5866
}
5967

60-
void AlignPicking::setAlign(Align *a) {
68+
void AlignPicking::setAlign(QRectF align_rect) {
6169
clear();
62-
align = a;
63-
rect->setPos(align->rect.center());
64-
rect->side = align->rect.width();
70+
// align = a;
71+
rect->setPos(align_rect.center());
72+
rect->side = align_rect.width();
6573

6674
scene().addItem(rect);
6775

@@ -85,12 +93,12 @@ void AlignPicking::click(QPoint p) {
8593

8694
rect->setPos(pos);
8795
rect->update();
88-
updateAlignPoint();
96+
// updateAlignPoint();
8997
}
9098

91-
void AlignPicking::updateAlignPoint() {
99+
/*void AlignPicking::updateAlignPoint() {
92100
align->rect = rect->getRect();
93-
}
101+
}*/
94102

95103
void AlignPicking::keyPressEvent(QKeyEvent *event) {
96104
if(event->key() == Qt::Key_Plus)
@@ -99,8 +107,9 @@ void AlignPicking::keyPressEvent(QKeyEvent *event) {
99107
marker_side -= 5;
100108
QPointF center = rect->rect.center();
101109

102-
rect->rect.setTopLeft(center - QPointF(marker_side, marker_side));
103-
rect->rect.setBottomRight(center + QPointF(marker_side, marker_side));
110+
QRectF r(center - QPointF(marker_side/2.0, marker_side/2.0),
111+
center + QPointF(marker_side/2.0, marker_side/2.0));
112+
rect->setRect(r);
104113
rect->update();
105-
updateAlignPoint();
114+
// updateAlignPoint();
106115
}

relightlab/alignpicking.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,19 @@ class AlignPicking: public ImageViewer {
4141
Q_OBJECT
4242
public:
4343
int marker_side = 40;
44-
Align *align = nullptr;
44+
//Align *align = nullptr;
4545

4646
AlignRect *rect = nullptr;
4747

4848
AlignPicking(QWidget *parent = nullptr);
49-
void setAlign(Align *sphere);
49+
void setAlign(QRectF r);
5050
void updateAlign();
5151
void clear();
52+
QRectF getRect() { return rect->getRect(); }
5253

5354
public slots:
5455
void click(QPoint);
55-
void updateAlignPoint();
56+
//void updateAlignPoint();
5657

5758
protected:
5859
void keyPressEvent(QKeyEvent *event) override;

relightlab/alignrow.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ AlignRow::AlignRow(Align *_align, QWidget *parent): QWidget(parent) {
8888

8989
edit_layout->setRowStretch(3,1);
9090

91-
connect(edit_button, SIGNAL(clicked()), this, SLOT(edit()));
92-
connect(remove_button, SIGNAL(clicked()), this, SLOT(remove()));
91+
connect(edit_button, &QPushButton::clicked, [this]() { emit edit(this); });
92+
connect(remove_button, &QPushButton::clicked, [this]() { emit removeme(this); });
9393
connect(verify_button, SIGNAL(clicked()), this, SLOT(verify()));
9494
}
9595

@@ -99,7 +99,7 @@ AlignRow::~AlignRow() {
9999
}
100100
delete find_alignment;
101101
}
102-
102+
/*
103103
void AlignRow::edit() {
104104
MarkerDialog *marker_dialog = new MarkerDialog(MarkerDialog::ALIGN, this);
105105
marker_dialog->setAlign(align);
@@ -110,22 +110,26 @@ void AlignRow::edit() {
110110
updateRegion();
111111
findAlignment();
112112
}
113-
}
113+
}*/
114114

115115
void AlignRow::verify() {
116116
VerifyDialog *verify_dialog = new VerifyDialog(align->thumbs, align->offsets, VerifyDialog::ALIGN, this);
117117
verify_dialog->exec();
118118
}
119119

120-
void AlignRow::remove() {
121-
emit removeme(this);
122-
}
123120

124121
void AlignRow::updateRegion() {
125122
QRectF r = align->rect;
126123
region->setText(QString("Sample region: %1x%2+%3+%4").arg(r.width()).arg(r.height()).arg(r.left()).arg(r.top()));
127124
}
128125

126+
void AlignRow::setRect(QRectF rect) {
127+
position->rect = align->rect;
128+
position->update();
129+
updateRegion();
130+
findAlignment();
131+
}
132+
129133
void AlignRow::updateStatus(QString msg, int percent) {
130134
status->setText(msg);
131135
progress->setValue(percent);

relightlab/alignrow.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ class AlignRow: public QWidget {
4343
void findAlignment(bool update = true);
4444
void stopFinding();
4545
void updateRegion();
46+
void setRect(QRectF rect);
4647

4748
signals:
49+
void edit(AlignRow *row);
4850
void removeme(AlignRow *row);
4951
void updated(); //emit when status changes
5052

5153
public slots:
52-
void edit();
53-
void remove();
5454
void verify();
5555
void updateStatus(QString msg, int percent);
5656
};

relightlab/markerdialog.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <QVBoxLayout>
77
#include <QDialogButtonBox>
8+
#include "../src/align.h"
89

910
MarkerDialog::MarkerDialog(Marker marker, QWidget *parent): QDialog(parent) {
1011

@@ -32,14 +33,27 @@ MarkerDialog::MarkerDialog(Marker marker, QWidget *parent): QDialog(parent) {
3233
showMaximized();
3334
}
3435

36+
3537
void MarkerDialog::setAlign(Align *align) {
36-
align_picking->setAlign(align);
38+
align_picking->setAlign(align->rect);
3739
}
3840

41+
QRectF MarkerDialog::getAlign() {
42+
return align_picking->getRect();
43+
44+
}
3945
void MarkerDialog::setSphere(Sphere *sphere) {
4046
sphere_picking->setSphere(sphere);
4147
}
4248

49+
void MarkerDialog::clear() {
50+
if(align_picking) {
51+
align_picking->clear();
52+
}
53+
if(sphere_picking)
54+
sphere_picking->clear();
55+
56+
}
4357

4458
void MarkerDialog::accept() {
4559
QDialog::accept();

relightlab/markerdialog.h

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class MarkerDialog: public QDialog {
1515
MarkerDialog(Marker marker, QWidget *parent = nullptr);
1616
void setAlign(Align *align);
1717
void setSphere(Sphere *sphere);
18+
QRectF getAlign();
19+
void clear();
1820

1921
public slots:
2022
void accept();

relightlab/relightlab.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CONFIG += c++17
66
#target_link_libraries( ${APP_NAME} Qt5::Svg )
77

88
DEFINES += QT_DEPRECATED_WARNINGS
9-
DEFINES += _USE_MATH_DEFINES
9+
DEFINES += _USE_MATH_DEFINES WITH_OPENCV
1010
DEFINES += NOMINMAX
1111

1212
INCLUDEPATH += ../external/

0 commit comments

Comments
 (0)