15#include <QGraphicsEllipseItem>
16#include <QGraphicsPixmapItem>
17#include <QGraphicsRectItem>
18#include <QGraphicsScene>
33 "DlgSettingsPointMatch",
35 m_scenePreview (nullptr),
36 m_viewPreview (nullptr),
38 m_modelPointMatchBefore (nullptr),
39 m_modelPointMatchAfter (nullptr)
52QPointF DlgSettingsPointMatch::boxPositionConstraint(
const QPointF &posIn)
56 double radius = radiusAlongDiagonal();
57 double diameter = 2.0 * radius;
61 if (pos.x() - radius < 0) {
65 if (pos.y() - radius < 0) {
69 if (pos.x() + diameter > m_scenePreview->sceneRect().width ()) {
70 pos.setX (m_scenePreview->sceneRect().width() - diameter);
73 if (pos.y() + diameter > m_scenePreview->sceneRect().height ()) {
74 pos.setY (m_scenePreview->sceneRect().height() - diameter);
80void DlgSettingsPointMatch::createControls (QGridLayout *layout,
85 QLabel *labelPointSize =
new QLabel (QString (
"%1:").arg (tr (
"Maximum point size (pixels)")));
86 layout->addWidget (labelPointSize, row, 1);
88 m_spinPointSize =
new QSpinBox;
89 m_spinPointSize->setWhatsThis (tr (
"Select a maximum point size in pixels.\n\n"
90 "Sample match points must fit within a square box, around the cursor, having width and height "
91 "equal to this maximum.\n\n"
92 "This size is also used to determine if a region of pixels that are on, in the processed image, "
93 "should be ignored since that region is wider or taller than this limit.\n\n"
94 "This value has a lower limit"));
97 connect (m_spinPointSize, SIGNAL (valueChanged (
int)),
this, SLOT (slotMaxPointSize (
int)));
98 layout->addWidget (m_spinPointSize, row++, 2);
100 QLabel *labelAcceptedPointColor =
new QLabel (QString (
"%1:").arg (tr (
"Accepted point color")));
101 layout->addWidget (labelAcceptedPointColor, row, 1);
103 m_cmbAcceptedPointColor =
new QComboBox;
104 m_cmbAcceptedPointColor->setWhatsThis (tr (
"Select a color for matched points that are accepted"));
106 connect (m_cmbAcceptedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotAcceptedPointColor (
const QString &)));
107 layout->addWidget (m_cmbAcceptedPointColor, row++, 2);
109 QLabel *labelRejectedPointColor =
new QLabel (QString (
"%1:").arg (tr (
"Rejected point color")));
110 layout->addWidget (labelRejectedPointColor, row, 1);
112 m_cmbRejectedPointColor =
new QComboBox;
113 m_cmbRejectedPointColor->setWhatsThis (tr (
"Select a color for matched points that are rejected"));
115 connect (m_cmbRejectedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotRejectedPointColor (
const QString &)));
116 layout->addWidget (m_cmbRejectedPointColor, row++, 2);
118 QLabel *labelCandidatePointColor =
new QLabel (QString (
"%1:").arg (tr (
"Candidate point color")));
119 layout->addWidget (labelCandidatePointColor, row, 1);
121 m_cmbCandidatePointColor =
new QComboBox;
122 m_cmbCandidatePointColor->setWhatsThis (tr (
"Select a color for the point being decided upon"));
124 connect (m_cmbCandidatePointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotCandidatePointColor (
const QString &)));
125 layout->addWidget (m_cmbCandidatePointColor, row++, 2);
132void DlgSettingsPointMatch::createPreview (QGridLayout *layout,
137 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
138 layout->addWidget (labelPreview, row++, 0, 1, 4);
140 m_scenePreview =
new QGraphicsScene (
this);
144 m_viewPreview->setWhatsThis (tr (
"Preview window shows how current settings affect "
145 "point matching, and how the marked and candidate points are displayed.\n\nThe points are separated "
146 "by the point separation value, and the maximum point size is shown as a box in the center"));
147 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
148 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
150 connect (m_viewPreview, SIGNAL (signalMouseMove (QPointF)),
this, SLOT (slotMouseMove (QPointF)));
152 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
159 QWidget *subPanel =
new QWidget ();
160 QGridLayout *layout =
new QGridLayout (subPanel);
161 subPanel->setLayout (layout);
163 layout->setColumnStretch(0, 1);
164 layout->setColumnStretch(1, 0);
165 layout->setColumnStretch(2, 0);
166 layout->setColumnStretch(3, 1);
175 createControls (layout, row);
176 createPreview (layout, row);
182void DlgSettingsPointMatch::createTemplate ()
186 QPen pen (QBrush (Qt::black), 0);
188 m_circle =
new QGraphicsEllipseItem;
189 m_circle->setPen (pen);
190 m_circle->setZValue (100);
191 m_scenePreview->addItem (m_circle);
200 *m_modelPointMatchBefore,
201 *m_modelPointMatchAfter);
207void DlgSettingsPointMatch::initializeBox ()
211 m_circle->setPos (
cmdMediator().document().pixmap().width () / 2.0,
212 cmdMediator().document().pixmap().height () / 2.0);
222 delete m_modelPointMatchBefore;
223 delete m_modelPointMatchAfter;
234 m_spinPointSize->setValue(qFloor (m_modelPointMatchAfter->maxPointSize()));
236 int indexAccepted = m_cmbAcceptedPointColor->findData(QVariant(m_modelPointMatchAfter->paletteColorAccepted()));
238 m_cmbAcceptedPointColor->setCurrentIndex(indexAccepted);
240 int indexCandidate = m_cmbCandidatePointColor->findData(QVariant(m_modelPointMatchAfter->paletteColorCandidate()));
242 m_cmbCandidatePointColor->setCurrentIndex(indexCandidate);
244 int indexRejected = m_cmbRejectedPointColor->findData(QVariant(m_modelPointMatchAfter->paletteColorRejected()));
246 m_cmbRejectedPointColor->setCurrentIndex(indexRejected);
251 QGraphicsRectItem *boundary = m_scenePreview->addRect (QRect (0,
255 boundary->setVisible (
false);
265double DlgSettingsPointMatch::radiusAlongDiagonal ()
const
267 double maxPointSize = m_modelPointMatchAfter->
maxPointSize();
269 return qSqrt (2.0) * maxPointSize / 2.0;
279void DlgSettingsPointMatch::slotAcceptedPointColor (
const QString &)
289void DlgSettingsPointMatch::slotCandidatePointColor (
const QString &)
293 m_modelPointMatchAfter->setPaletteColorCandidate(
static_cast<ColorPalette> (m_cmbCandidatePointColor->currentData().toInt()));
298void DlgSettingsPointMatch::slotMaxPointSize (
int maxPointSize)
302 m_modelPointMatchAfter->setMaxPointSize(maxPointSize);
307void DlgSettingsPointMatch::slotMouseMove (QPointF pos)
311 pos = boxPositionConstraint (pos);
313 m_circle->setPos (pos);
316void DlgSettingsPointMatch::slotRejectedPointColor (
const QString &)
320 m_modelPointMatchAfter->setPaletteColorRejected(
static_cast<ColorPalette> (m_cmbRejectedPointColor->currentData().toInt()));
325void DlgSettingsPointMatch::slotWhatsThis ()
327 QWhatsThis::enterWhatsThisMode();
330void DlgSettingsPointMatch::updateControls()
336void DlgSettingsPointMatch::updatePreview()
339 double maxPointSize = m_modelPointMatchAfter->maxPointSize();
341 double xLeft = -1.0 * maxPointSize / 2.0;
342 double yTop = -1.0 * maxPointSize / 2.0;
345 m_circle->setRect (xLeft,
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Command for DlgSettingsPointMatch.
DlgSettingsAbstractBase(const QString &title, const QString &dialogName, MainWindow &mainWindow)
Single constructor.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH, int minimumHeightOrZero=0)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
void populateColorComboWithTransparent(QComboBox &combo)
Add colors in color palette to combobox, with transparent entry at end.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void createWhatsThis(QGridLayout *layout, ButtonWhatsThis *button, int row, int column)
Create a WhatsThis button in a grid layout.
void addPixmap(QGraphicsScene &scene, const QPixmap &pixmap)
Adds pixmap to the scene.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
virtual ~DlgSettingsPointMatch()
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
DlgSettingsPointMatch(MainWindow &mainWindow)
Single constructor.
virtual void handleOk()
Process slotOk.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
void setPaletteColorAccepted(ColorPalette paletteColorAccepted)
Set method for accepted color.
double maxPointSize() const
Get method for max point size.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
@ VIEW_ASPECT_RATIO_VARIABLE
#define LOG4CPP_INFO_S(logger)