1 #include "CmdMediator.h"
2 #include "CmdSettingsPointMatch.h"
3 #include "DlgSettingsPointMatch.h"
4 #include "EngaugeAssert.h"
6 #include "MainWindow.h"
8 #include <QGraphicsEllipseItem>
9 #include <QGraphicsPixmapItem>
10 #include <QGraphicsRectItem>
11 #include <QGraphicsScene>
12 #include <QGridLayout>
17 #include "ViewPreview.h"
19 const int POINT_SIZE_MAX = 1024;
20 const int POINT_SIZE_MIN = 5;
24 "DlgSettingsPointMatch",
29 m_modelPointMatchBefore (0),
30 m_modelPointMatchAfter (0)
32 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::DlgSettingsPointMatch";
38 DlgSettingsPointMatch::~DlgSettingsPointMatch()
40 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::~DlgSettingsPointMatch";
43 QPointF DlgSettingsPointMatch::boxPositionConstraint(
const QPointF &posIn)
45 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::boxPositionConstraint";
47 double radius = radiusAlongDiagonal();
48 double diameter = 2.0 * radius;
52 if (pos.x() - radius < 0) {
56 if (pos.y() - radius < 0) {
60 if (pos.x() + diameter > m_scenePreview->sceneRect().width ()) {
61 pos.setX (m_scenePreview->sceneRect().width() - diameter);
64 if (pos.y() + diameter > m_scenePreview->sceneRect().height ()) {
65 pos.setY (m_scenePreview->sceneRect().height() - diameter);
71 void DlgSettingsPointMatch::createControls (QGridLayout *layout,
74 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createControls";
76 QLabel *labelPointSize =
new QLabel (
"Maximum point size (pixels):");
77 layout->addWidget (labelPointSize, row, 1);
79 m_spinPointSize =
new QSpinBox;
80 m_spinPointSize->setWhatsThis (tr (
"Select a maximum point size in pixels.\n\n"
81 "Sample match points must fit within a square box, around the cursor, having width and height "
82 "equal to this maximum.\n\n"
83 "This size is also used to determine if a region of pixels that are on, in the processed image, "
84 "should be ignored since that region is wider or taller than this limit.\n\n"
85 "This value has a lower limit"));
86 m_spinPointSize->setMinimum (POINT_SIZE_MIN);
87 m_spinPointSize->setMaximum (POINT_SIZE_MAX);
88 connect (m_spinPointSize, SIGNAL (valueChanged (
int)),
this, SLOT (slotMaxPointSize (
int)));
89 layout->addWidget (m_spinPointSize, row++, 2);
91 QLabel *labelAcceptedPointColor =
new QLabel (
"Accepted point color:");
92 layout->addWidget (labelAcceptedPointColor, row, 1);
94 m_cmbAcceptedPointColor =
new QComboBox;
95 m_cmbAcceptedPointColor->setWhatsThis (tr (
"Select a color for matched points that are accepted"));
97 connect (m_cmbAcceptedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotAcceptedPointColor (
const QString &)));
98 layout->addWidget (m_cmbAcceptedPointColor, row++, 2);
100 QLabel *labelRejectedPointColor =
new QLabel (
"Rejected point color:");
101 layout->addWidget (labelRejectedPointColor, row, 1);
103 m_cmbRejectedPointColor =
new QComboBox;
104 m_cmbRejectedPointColor->setWhatsThis (tr (
"Select a color for matched points that are rejected"));
106 connect (m_cmbRejectedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotRejectedPointColor (
const QString &)));
107 layout->addWidget (m_cmbRejectedPointColor, row++, 2);
109 QLabel *labelCandidatePointColor =
new QLabel (
"Candidate point color:");
110 layout->addWidget (labelCandidatePointColor, row, 1);
112 m_cmbCandidatePointColor =
new QComboBox;
113 m_cmbCandidatePointColor->setWhatsThis (tr (
"Select a color for the point being decided upon"));
115 connect (m_cmbCandidatePointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotCandidatePointColor (
const QString &)));
116 layout->addWidget (m_cmbCandidatePointColor, row++, 2);
119 void DlgSettingsPointMatch::createPreview (QGridLayout *layout,
122 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createPreview";
124 QLabel *labelPreview =
new QLabel (
"Preview");
125 layout->addWidget (labelPreview, row++, 0, 1, 4);
127 m_scenePreview =
new QGraphicsScene (
this);
129 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
131 m_viewPreview->setWhatsThis (tr (
"Preview window shows how current settings affect "
132 "point matching, and how the marked and candidate points are displayed.\n\nThe points are separated "
133 "by the point separation value, and the maximum point size is shown as a box in the center"));
134 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
135 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
137 connect (m_viewPreview, SIGNAL (signalMouseMove (QPointF)),
this, SLOT (slotMouseMove (QPointF)));
139 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
144 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createSubPanel";
146 QWidget *subPanel =
new QWidget ();
147 QGridLayout *layout =
new QGridLayout (subPanel);
148 subPanel->setLayout (layout);
150 layout->setColumnStretch(0, 1);
151 layout->setColumnStretch(1, 0);
152 layout->setColumnStretch(2, 0);
153 layout->setColumnStretch(3, 1);
156 createControls (layout, row);
157 createPreview (layout, row);
163 void DlgSettingsPointMatch::createTemplate ()
165 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createTemplate";
167 QPen pen (QBrush (Qt::black), 0);
169 m_circle =
new QGraphicsEllipseItem;
170 m_circle->setPen (pen);
171 m_circle->setZValue (100);
172 m_scenePreview->addItem (m_circle);
177 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::handleOk";
181 *m_modelPointMatchBefore,
182 *m_modelPointMatchAfter);
188 void DlgSettingsPointMatch::initializeBox ()
190 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::initializeBox";
192 m_circle->setPos (
cmdMediator().document().pixmap().width () / 2.0,
193 cmdMediator().document().pixmap().height () / 2.0);
198 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::load";
203 if (m_modelPointMatchBefore != 0) {
204 delete m_modelPointMatchBefore;
206 if (m_modelPointMatchAfter != 0) {
207 delete m_modelPointMatchAfter;
215 ENGAUGE_ASSERT (POINT_SIZE_MIN <= m_modelPointMatchAfter->maxPointSize());
216 ENGAUGE_ASSERT (POINT_SIZE_MAX > m_modelPointMatchAfter->
maxPointSize());
219 m_spinPointSize->setValue(m_modelPointMatchAfter->
maxPointSize());
221 int indexAccepted = m_cmbAcceptedPointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorAccepted()));
222 ENGAUGE_ASSERT (indexAccepted >= 0);
223 m_cmbAcceptedPointColor->setCurrentIndex(indexAccepted);
225 int indexCandidate = m_cmbCandidatePointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorCandidate()));
226 ENGAUGE_ASSERT (indexCandidate >= 0);
227 m_cmbCandidatePointColor->setCurrentIndex(indexCandidate);
229 int indexRejected = m_cmbRejectedPointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorRejected()));
230 ENGAUGE_ASSERT (indexRejected >= 0);
231 m_cmbRejectedPointColor->setCurrentIndex(indexRejected);
236 QGraphicsRectItem *boundary = m_scenePreview->addRect (QRect (0,
240 boundary->setVisible (
false);
249 double DlgSettingsPointMatch::radiusAlongDiagonal ()
const
251 double maxPointSize = m_modelPointMatchAfter->
maxPointSize();
253 return qSqrt (2.0) * maxPointSize / 2.0;
256 void DlgSettingsPointMatch::slotAcceptedPointColor (
const QString &)
258 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotAcceptedPointColor";
260 m_modelPointMatchAfter->
setPaletteColorAccepted((ColorPalette) m_cmbAcceptedPointColor->currentData().toInt());
266 void DlgSettingsPointMatch::slotCandidatePointColor (
const QString &)
268 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotCandidatePointColor";
275 void DlgSettingsPointMatch::slotMaxPointSize (
int maxPointSize)
277 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotMaxPointSize";
284 void DlgSettingsPointMatch::slotMouseMove (QPointF pos)
288 pos = boxPositionConstraint (pos);
290 m_circle->setPos (pos);
293 void DlgSettingsPointMatch::slotRejectedPointColor (
const QString &)
295 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotRejectedPointColor";
297 m_modelPointMatchAfter->
setPaletteColorRejected((ColorPalette) m_cmbRejectedPointColor->currentData().toInt());
302 void DlgSettingsPointMatch::updateControls()
308 void DlgSettingsPointMatch::updatePreview()
311 double maxPointSize = m_modelPointMatchAfter->
maxPointSize();
313 double xLeft = -1.0 * maxPointSize / 2.0;
314 double yTop = -1.0 * maxPointSize / 2.0;
317 m_circle->setRect (xLeft,
double maxPointSize() const
Get method for max point size.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
void setPaletteColorCandidate(ColorPalette paletteColorCandidate)
Set method for candidate color.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
QPixmap pixmap() const
Return the image that is being digitized.
Command for DlgSettingsPointMatch.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
void setMaxPointSize(double maxPointSize)
Set method for max point size.
void setPaletteColorRejected(ColorPalette paletteColorRejected)
Set method for rejected color.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
ColorPalette paletteColorCandidate() const
Get method for candidate color.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
virtual void handleOk()
Process slotOk.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
void populateColorComboWithTransparent(QComboBox &combo)
Add colors in color palette to combobox, with transparent entry at end.
Abstract base class for all Settings dialogs.
ColorPalette paletteColorRejected() const
Get method for rejected color.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
DlgSettingsPointMatch(MainWindow &mainWindow)
Single constructor.
ColorPalette paletteColorAccepted() const
Get method for accepted color.
MainWindow & mainWindow()
Get method for MainWindow.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void setPaletteColorAccepted(ColorPalette paletteColorAccepted)
Set method for accepted color.