-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagecontrolhandler.cpp
More file actions
133 lines (104 loc) · 3.7 KB
/
imagecontrolhandler.cpp
File metadata and controls
133 lines (104 loc) · 3.7 KB
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
#include "imagecontrolhandler.h"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QSlider>
#include <QDebug>
#include <QString>
#include <qsizepolicy.h>
#include <QToolTip>
imagecontrolhandler::imagecontrolhandler(QWidget *parent) : QWidget(parent)
{
this->setObjectName("webImageHandler");
master = new QGridLayout(this);
scrollGrid = new QGridLayout(this);
layout = new QHBoxLayout(this);
imageView = new QLabel(this);
scrollArea = new QScrollArea(this);
counterClockWise = new QPushButton(this);
clockWise = new QPushButton(this);
minScale = new QLineEdit(this);
maxScale = new QLineEdit(this);
scaler = new QSlider(Qt::Horizontal, this);
counterClockWise->setText("CCW");
clockWise->setText("CW");
minValidator = new QDoubleValidator(minValue, 0.9999, 4);
maxValidator = new QDoubleValidator(1.1111, maxValue, 4);
minScale->setValidator(minValidator);
maxScale->setValidator(maxValidator);
minScale->setText(QString::number(minStartValue));
maxScale->setText(QString::number(maxStartValue));
scaler->setMinimum(minScalerValue);
scaler->setMaximum(maxScalerValue);
scaler->setValue(map(1, minStartValue, maxStartValue, minScalerValue, maxScalerValue));
layout->addWidget(counterClockWise);
layout->addWidget(minScale);
layout->addWidget(scaler);
layout->addWidget(maxScale);
layout->addWidget(clockWise);
connect(counterClockWise, SIGNAL(clicked()), this, SLOT(rotateCounterClockWise()));
connect(clockWise, SIGNAL(clicked()), this, SLOT(rotateClockWise()));
connect(minScale, SIGNAL(editingFinished()), this, SLOT(scaleChanged()));
connect(maxScale, SIGNAL(editingFinished()), this, SLOT(scaleChangedM()));
connect(scaler, SIGNAL(sliderReleased()), this, SLOT(scalerChanged()));
connect(scaler, SIGNAL(valueChanged()), this, SLOT(scalerChangedT()));
scrollArea->setLayout(scrollGrid);
scrollArea->setWidget(imageView);
scrollArea->show();
master->addLayout(layout, 0, 0);
master->addWidget(scrollArea);
}
void imagecontrolhandler::setPixMap(QPixmap image)
{
this->original = image;
rotation = 0;
imageChange();
}
void imagecontrolhandler::rotateCounterClockWise()
{
rotation -= 90;
imageChange();
}
void imagecontrolhandler::rotateClockWise()
{
rotation += 90;
imageChange();
}
void imagecontrolhandler::scaleChanged()
{
qDebug() << "Value";
scaleBoundsChanged();
}
void imagecontrolhandler::scaleChangedM()
{
scaleBoundsChanged();
}
void imagecontrolhandler::scalerChanged()
{
imageChange();
}
void imagecontrolhandler::scalerChangedT()
{
QToolTip::showText(scaler->pos(), "x" + QString::number(map(scaler->value(), minScalerValue, maxScalerValue, minValue, maxValue)));
}
double imagecontrolhandler::map(double x, double in_min, double in_max, double out_min, double out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void imagecontrolhandler::imageChange()
{
this->image = this->original.scaledToWidth(original.width() * map(scaler->value(), minScalerValue, maxScalerValue, minValue, maxValue));
QMatrix rm;
rm.rotate(rotation);
imageView->setPixmap(image.transformed(rm));
image = *imageView->pixmap();
imageView->resize(image.size());
}
void imagecontrolhandler::scaleBoundsChanged()
{
double actualValue = map(scaler->value(), minScalerValue, maxScalerValue, minValue, maxValue);
minValue = minScale->text().toDouble();
maxValue = maxScale->text().toDouble();
scaler->setValue(map(actualValue, minValue, maxValue, minScalerValue, maxScalerValue));
qDebug() << "Min " << QString::number(minValue) << " max " << QString::number(maxValue);
}