7 #include "CmdMediator.h"
8 #include "CmdSettingsPointMatch.h"
9 #include "DlgSettingsPointMatch.h"
10 #include "EngaugeAssert.h"
12 #include "MainWindow.h"
14 #include <QGraphicsEllipseItem>
15 #include <QGraphicsPixmapItem>
16 #include <QGraphicsRectItem>
17 #include <QGraphicsScene>
18 #include <QGridLayout>
23 #include "ViewPreview.h"
25 const int POINT_SIZE_MAX = 1024;
26 const int POINT_SIZE_MIN = 5;
30 "DlgSettingsPointMatch",
35 m_modelPointMatchBefore (0),
36 m_modelPointMatchAfter (0)
38 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::DlgSettingsPointMatch";
44 DlgSettingsPointMatch::~DlgSettingsPointMatch()
46 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::~DlgSettingsPointMatch";
49 QPointF DlgSettingsPointMatch::boxPositionConstraint(
const QPointF &posIn)
51 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::boxPositionConstraint";
53 double radius = radiusAlongDiagonal();
54 double diameter = 2.0 * radius;
58 if (pos.x() - radius < 0) {
62 if (pos.y() - radius < 0) {
66 if (pos.x() + diameter > m_scenePreview->sceneRect().width ()) {
67 pos.setX (m_scenePreview->sceneRect().width() - diameter);
70 if (pos.y() + diameter > m_scenePreview->sceneRect().height ()) {
71 pos.setY (m_scenePreview->sceneRect().height() - diameter);
77 void DlgSettingsPointMatch::createControls (QGridLayout *layout,
80 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createControls";
82 QLabel *labelPointSize =
new QLabel (tr (
"Maximum point size (pixels):"));
83 layout->addWidget (labelPointSize, row, 1);
85 m_spinPointSize =
new QSpinBox;
86 m_spinPointSize->setWhatsThis (tr (
"Select a maximum point size in pixels.\n\n"
87 "Sample match points must fit within a square box, around the cursor, having width and height "
88 "equal to this maximum.\n\n"
89 "This size is also used to determine if a region of pixels that are on, in the processed image, "
90 "should be ignored since that region is wider or taller than this limit.\n\n"
91 "This value has a lower limit"));
92 m_spinPointSize->setMinimum (POINT_SIZE_MIN);
93 m_spinPointSize->setMaximum (POINT_SIZE_MAX);
94 connect (m_spinPointSize, SIGNAL (valueChanged (
int)),
this, SLOT (slotMaxPointSize (
int)));
95 layout->addWidget (m_spinPointSize, row++, 2);
97 QLabel *labelAcceptedPointColor =
new QLabel (tr (
"Accepted point color:"));
98 layout->addWidget (labelAcceptedPointColor, row, 1);
100 m_cmbAcceptedPointColor =
new QComboBox;
101 m_cmbAcceptedPointColor->setWhatsThis (tr (
"Select a color for matched points that are accepted"));
103 connect (m_cmbAcceptedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotAcceptedPointColor (
const QString &)));
104 layout->addWidget (m_cmbAcceptedPointColor, row++, 2);
106 QLabel *labelRejectedPointColor =
new QLabel (tr (
"Rejected point color:"));
107 layout->addWidget (labelRejectedPointColor, row, 1);
109 m_cmbRejectedPointColor =
new QComboBox;
110 m_cmbRejectedPointColor->setWhatsThis (tr (
"Select a color for matched points that are rejected"));
112 connect (m_cmbRejectedPointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotRejectedPointColor (
const QString &)));
113 layout->addWidget (m_cmbRejectedPointColor, row++, 2);
115 QLabel *labelCandidatePointColor =
new QLabel (tr (
"Candidate point color:"));
116 layout->addWidget (labelCandidatePointColor, row, 1);
118 m_cmbCandidatePointColor =
new QComboBox;
119 m_cmbCandidatePointColor->setWhatsThis (tr (
"Select a color for the point being decided upon"));
121 connect (m_cmbCandidatePointColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotCandidatePointColor (
const QString &)));
122 layout->addWidget (m_cmbCandidatePointColor, row++, 2);
129 void DlgSettingsPointMatch::createPreview (QGridLayout *layout,
132 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createPreview";
134 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
135 layout->addWidget (labelPreview, row++, 0, 1, 4);
137 m_scenePreview =
new QGraphicsScene (
this);
139 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
141 m_viewPreview->setWhatsThis (tr (
"Preview window shows how current settings affect "
142 "point matching, and how the marked and candidate points are displayed.\n\nThe points are separated "
143 "by the point separation value, and the maximum point size is shown as a box in the center"));
144 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
145 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
147 connect (m_viewPreview, SIGNAL (signalMouseMove (QPointF)),
this, SLOT (slotMouseMove (QPointF)));
149 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
154 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createSubPanel";
156 QWidget *subPanel =
new QWidget ();
157 QGridLayout *layout =
new QGridLayout (subPanel);
158 subPanel->setLayout (layout);
160 layout->setColumnStretch(0, 1);
161 layout->setColumnStretch(1, 0);
162 layout->setColumnStretch(2, 0);
163 layout->setColumnStretch(3, 1);
166 createControls (layout, row);
167 createPreview (layout, row);
173 void DlgSettingsPointMatch::createTemplate ()
175 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::createTemplate";
177 QPen pen (QBrush (Qt::black), 0);
179 m_circle =
new QGraphicsEllipseItem;
180 m_circle->setPen (pen);
181 m_circle->setZValue (100);
182 m_scenePreview->addItem (m_circle);
187 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::handleOk";
191 *m_modelPointMatchBefore,
192 *m_modelPointMatchAfter);
198 void DlgSettingsPointMatch::initializeBox ()
200 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::initializeBox";
202 m_circle->setPos (
cmdMediator().document().pixmap().width () / 2.0,
203 cmdMediator().document().pixmap().height () / 2.0);
208 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::load";
213 if (m_modelPointMatchBefore != 0) {
214 delete m_modelPointMatchBefore;
216 if (m_modelPointMatchAfter != 0) {
217 delete m_modelPointMatchAfter;
225 ENGAUGE_ASSERT (POINT_SIZE_MIN <= m_modelPointMatchAfter->maxPointSize());
226 ENGAUGE_ASSERT (POINT_SIZE_MAX > m_modelPointMatchAfter->
maxPointSize());
229 m_spinPointSize->setValue(m_modelPointMatchAfter->
maxPointSize());
231 int indexAccepted = m_cmbAcceptedPointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorAccepted()));
232 ENGAUGE_ASSERT (indexAccepted >= 0);
233 m_cmbAcceptedPointColor->setCurrentIndex(indexAccepted);
235 int indexCandidate = m_cmbCandidatePointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorCandidate()));
236 ENGAUGE_ASSERT (indexCandidate >= 0);
237 m_cmbCandidatePointColor->setCurrentIndex(indexCandidate);
239 int indexRejected = m_cmbRejectedPointColor->findData(QVariant(m_modelPointMatchAfter->
paletteColorRejected()));
240 ENGAUGE_ASSERT (indexRejected >= 0);
241 m_cmbRejectedPointColor->setCurrentIndex(indexRejected);
246 QGraphicsRectItem *boundary = m_scenePreview->addRect (QRect (0,
250 boundary->setVisible (
false);
259 double DlgSettingsPointMatch::radiusAlongDiagonal ()
const
261 double maxPointSize = m_modelPointMatchAfter->
maxPointSize();
263 return qSqrt (2.0) * maxPointSize / 2.0;
266 void DlgSettingsPointMatch::slotAcceptedPointColor (
const QString &)
268 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotAcceptedPointColor";
270 m_modelPointMatchAfter->
setPaletteColorAccepted((ColorPalette) m_cmbAcceptedPointColor->currentData().toInt());
276 void DlgSettingsPointMatch::slotCandidatePointColor (
const QString &)
278 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotCandidatePointColor";
285 void DlgSettingsPointMatch::slotMaxPointSize (
int maxPointSize)
287 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotMaxPointSize";
294 void DlgSettingsPointMatch::slotMouseMove (QPointF pos)
298 pos = boxPositionConstraint (pos);
300 m_circle->setPos (pos);
303 void DlgSettingsPointMatch::slotRejectedPointColor (
const QString &)
305 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsPointMatch::slotRejectedPointColor";
307 m_modelPointMatchAfter->
setPaletteColorRejected((ColorPalette) m_cmbRejectedPointColor->currentData().toInt());
312 void DlgSettingsPointMatch::updateControls()
318 void DlgSettingsPointMatch::updatePreview()
321 double maxPointSize = m_modelPointMatchAfter->
maxPointSize();
323 double xLeft = -1.0 * maxPointSize / 2.0;
324 double yTop = -1.0 * maxPointSize / 2.0;
327 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.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
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.