-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclipdialog.cpp
123 lines (100 loc) · 3.91 KB
/
clipdialog.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
#include "clipdialog.h"
#include <QtWidgets>
ClipDialog::ClipDialog(QPixmap pixmap)
{
this->setMouseTracking(true);
w = pixmap.width();
h = pixmap.height();
maxWidth = 800;
pixmap = pixmap.scaled(maxWidth, maxWidth * h / w, Qt::KeepAspectRatio);
clipBox = new ClipBox(pixmap, this);
clipBox->setMouseTracking(true);
clipBox->show();
QVBoxLayout *imageLayout = new QVBoxLayout;
imageLayout->addWidget(clipBox);
QGroupBox *imageGroup = new QGroupBox(tr("Image View"));
imageGroup->setLayout(imageLayout);
QLabel *leftLabel = new QLabel;
leftLabel->setText("Left:");
leftMarginLabel = new QLabel;
leftMarginLabel->setAlignment(Qt::AlignRight);
QHBoxLayout *leftLayout = new QHBoxLayout;
leftLayout->addWidget(leftLabel);
leftLayout->addWidget(leftMarginLabel);
QLabel *rightLabel = new QLabel;
rightLabel->setText("Right: ");
rightMarginLabel = new QLabel;
rightMarginLabel->setAlignment(Qt::AlignRight);
QHBoxLayout *rightLayout = new QHBoxLayout;
rightLayout->addWidget(rightLabel);
rightLayout->addWidget(rightMarginLabel);
QLabel *topLabel = new QLabel;
topLabel->setText("Top: ");
topMarginLabel = new QLabel;
topMarginLabel->setAlignment(Qt::AlignRight);
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(topLabel);
topLayout->addWidget(topMarginLabel);
QLabel *bottomLabel = new QLabel;
bottomLabel->setText("Bottom: ");
bottomMarginLabel = new QLabel;
bottomMarginLabel->setAlignment(Qt::AlignRight);
QHBoxLayout *bottomLayout = new QHBoxLayout;
bottomLayout->addWidget(bottomLabel);
bottomLayout->addWidget(bottomMarginLabel);
QVBoxLayout *marginLayout = new QVBoxLayout;
marginLayout->addLayout(leftLayout);
marginLayout->addLayout(rightLayout);
marginLayout->addLayout(topLayout);
marginLayout->addLayout(bottomLayout);
marginLayout->setContentsMargins(10, 10, 10, 10);
QGroupBox *clipmarginBox = new QGroupBox(tr("Clip Margins"));
clipmarginBox->setLayout(marginLayout);
applyButton = new QPushButton(tr("Apply"));
applyButton->setEnabled(false);
QPushButton *closeButton = new QPushButton(tr("Close"));
QHBoxLayout *btnLayout = new QHBoxLayout;
btnLayout->addStretch(1);
btnLayout->addWidget(applyButton);
btnLayout->addWidget(closeButton);
QVBoxLayout *rLayout = new QVBoxLayout;
rLayout->addWidget(clipmarginBox);
rLayout->addStretch(1);
rLayout->addSpacing(12);
rLayout->addLayout(btnLayout);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(imageGroup);
mainLayout->addLayout(rLayout);
setLayout(mainLayout);
connect(closeButton, &QAbstractButton::clicked, this, &QWidget::close);
connect(applyButton, &QAbstractButton::clicked, this, &ClipDialog::apply);
connect(clipBox, SIGNAL(sendEnable()), this, SLOT(receiveEnable()));
connect(clipBox, SIGNAL(currentRect(QRect)), this, SLOT(setEdit(QRect)));
setWindowTitle(tr("Clip Dialog"));
}
void ClipDialog::apply(){
QJsonObject obj;
int left = leftMarginLabel->text().toInt();
int right = w - rightMarginLabel->text().toInt();
int top = topMarginLabel->text().toInt();
int bottom = h - bottomMarginLabel->text().toInt();
obj.insert("left", left);
obj.insert("right", right);
obj.insert("top", top);
obj.insert("bottom", bottom);
emit sendApplyClip(obj);
close();
}
void ClipDialog::receiveEnable(){
applyButton->setEnabled(true);
}
void ClipDialog::setEdit(QRect rect){
int left = rect.left() * w / maxWidth;
int right = w - rect.right() * w / maxWidth;
int top = rect.top() * w / maxWidth;
int bottom = h - rect.bottom() * w / maxWidth;
leftMarginLabel->setText(QString::number(left));
rightMarginLabel->setText(QString::number(right));
topMarginLabel->setText(QString::number(top));
bottomMarginLabel->setText(QString::number(bottom));
}