14 #include <QGraphicsEllipseItem>
15 #include <QGraphicsPixmapItem>
16 #include <QGraphicsRectItem>
17 #include <QGraphicsScene>
18 #include <QGridLayout>
31 "DlgSettingsPointMatch",
33 m_scenePreview (nullptr),
34 m_viewPreview (nullptr),
36 m_modelPointMatchBefore (nullptr),
37 m_modelPointMatchAfter (nullptr)
50 QPointF DlgSettingsPointMatch::boxPositionConstraint(
const QPointF &posIn)
54 double radius = radiusAlongDiagonal();
55 double diameter = 2.0 * radius;
59 if (pos.x() - radius < 0) {
63 if (pos.y() - radius < 0) {
67 if (pos.x() + diameter > m_scenePreview->sceneRect().width ()) {
68 pos.setX (m_scenePreview->sceneRect().width() - diameter);
71 if (pos.y() + diameter > m_scenePreview->sceneRect().height ()) {
72 pos.setY (m_scenePreview->sceneRect().height() - diameter);
78 void DlgSettingsPointMatch::createControls (QGridLayout *layout,
83 QLabel *labelPointSize =
new QLabel (QString (
"%1:").arg (tr (
"Maximum point size (pixels)")));
84 layout->addWidget (labelPointSize, row, 1);
86 m_spinPointSize =
new QSpinBox;
87 m_spinPointSize->setWhatsThis (tr (
"Select a maximum point size in pixels.\n\n"
88 "Sample match points must fit within a square box, around the cursor, having width and height "
89 "equal to this maximum.\n\n"
90 "This size is also used to determine if a region of pixels that are on, in the processed image, "
91 "should be ignored since that region is wider or taller than this limit.\n\n"
92 "This value has a lower limit"));
95 connect (m_spinPointSize, SIGNAL (valueChanged (
int)),
this, SLOT (slotMaxPointSize (
int)));
96 layout->addWidget (m_spinPointSize, row++, 2);
98 QLabel *labelAcceptedPointColor =
new QLabel (QString (
"%1:").arg (tr (
"Accepted point color")));
99 layout->addWidget (labelAcceptedPointColor, row, 1);
101 m_cmbAcceptedPointColor =
new QComboBox;
102 m_cmbAcceptedPointColor->setWhatsThis (tr (
"Select a color for matched points that are accepted"));
104 connect (m_cmbAcceptedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotAcceptedPointColor (
const QString &)));
105 layout->addWidget (m_cmbAcceptedPointColor, row++, 2);
107 QLabel *labelRejectedPointColor =
new QLabel (QString (
"%1:").arg (tr (
"Rejected point color")));
108 layout->addWidget (labelRejectedPointColor, row, 1);
110 m_cmbRejectedPointColor =
new QComboBox;
111 m_cmbRejectedPointColor->setWhatsThis (tr (
"Select a color for matched points that are rejected"));
113 connect (m_cmbRejectedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotRejectedPointColor (
const QString &)));
114 layout->addWidget (m_cmbRejectedPointColor, row++, 2);
116 QLabel *labelCandidatePointColor =
new QLabel (QString (
"%1:").arg (tr (
"Candidate point color")));
117 layout->addWidget (labelCandidatePointColor, row, 1);
119 m_cmbCandidatePointColor =
new QComboBox;
120 m_cmbCandidatePointColor->setWhatsThis (tr (
"Select a color for the point being decided upon"));
122 connect (m_cmbCandidatePointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotCandidatePointColor (
const QString &)));
123 layout->addWidget (m_cmbCandidatePointColor, row++, 2);
130 void DlgSettingsPointMatch::createPreview (QGridLayout *layout,
135 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
136 layout->addWidget (labelPreview, row++, 0, 1, 4);
138 m_scenePreview =
new QGraphicsScene (
this);
142 m_viewPreview->setWhatsThis (tr (
"Preview window shows how current settings affect "
143 "point matching, and how the marked and candidate points are displayed.\n\nThe points are separated "
144 "by the point separation value, and the maximum point size is shown as a box in the center"));
145 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
146 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
148 connect (m_viewPreview, SIGNAL (signalMouseMove (QPointF)),
this, SLOT (slotMouseMove (QPointF)));
150 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
157 QWidget *subPanel =
new QWidget ();
158 QGridLayout *layout =
new QGridLayout (subPanel);
159 subPanel->setLayout (layout);
161 layout->setColumnStretch(0, 1);
162 layout->setColumnStretch(1, 0);
163 layout->setColumnStretch(2, 0);
164 layout->setColumnStretch(3, 1);
167 createControls (layout, row);
168 createPreview (layout, row);
174 void DlgSettingsPointMatch::createTemplate ()
178 QPen pen (QBrush (Qt::black), 0);
180 m_circle =
new QGraphicsEllipseItem;
181 m_circle->setPen (pen);
182 m_circle->setZValue (100);
183 m_scenePreview->addItem (m_circle);
192 *m_modelPointMatchBefore,
193 *m_modelPointMatchAfter);
199 void DlgSettingsPointMatch::initializeBox ()
203 m_circle->setPos (
cmdMediator().document().pixmap().width () / 2.0,
204 cmdMediator().document().pixmap().height () / 2.0);
214 delete m_modelPointMatchBefore;
215 delete m_modelPointMatchAfter;
222 ENGAUGE_ASSERT (POINT_SIZE_MIN <= m_modelPointMatchAfter->maxPointSize());
226 m_spinPointSize->setValue(qFloor (m_modelPointMatchAfter->
maxPointSize()));
228 int indexAccepted = m_cmbAcceptedPointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorAccepted()));
230 m_cmbAcceptedPointColor->setCurrentIndex(indexAccepted);
232 int indexCandidate = m_cmbCandidatePointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorCandidate()));
234 m_cmbCandidatePointColor->setCurrentIndex(indexCandidate);
236 int indexRejected = m_cmbRejectedPointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorRejected()));
238 m_cmbRejectedPointColor->setCurrentIndex(indexRejected);
243 QGraphicsRectItem *boundary = m_scenePreview->addRect (QRect (0,
247 boundary->setVisible (
false);
256 double DlgSettingsPointMatch::radiusAlongDiagonal ()
const
258 double maxPointSize = m_modelPointMatchAfter->
maxPointSize();
260 return qSqrt (2.0) * maxPointSize / 2.0;
270 void DlgSettingsPointMatch::slotAcceptedPointColor (
const QString &)
274 m_modelPointMatchAfter->
setPaletteColorAccepted(static_cast<ColorPalette> (m_cmbAcceptedPointColor->currentData().toInt()));
280 void DlgSettingsPointMatch::slotCandidatePointColor (
const QString &)
284 m_modelPointMatchAfter->
setPaletteColorCandidate(static_cast<ColorPalette> (m_cmbCandidatePointColor->currentData().toInt()));
289 void DlgSettingsPointMatch::slotMaxPointSize (
int maxPointSize)
298 void DlgSettingsPointMatch::slotMouseMove (QPointF pos)
302 pos = boxPositionConstraint (pos);
304 m_circle->setPos (pos);
307 void DlgSettingsPointMatch::slotRejectedPointColor (
const QString &)
311 m_modelPointMatchAfter->
setPaletteColorRejected(static_cast<ColorPalette> (m_cmbRejectedPointColor->currentData().toInt()));
316 void DlgSettingsPointMatch::updateControls()
322 void DlgSettingsPointMatch::updatePreview()
325 double maxPointSize = m_modelPointMatchAfter->
maxPointSize();
327 double xLeft = -1.0 * maxPointSize / 2.0;
328 double yTop = -1.0 * maxPointSize / 2.0;
331 m_circle->setRect (xLeft,