7 #include "CmdMediator.h"
8 #include "CmdSettingsSegments.h"
9 #include "DlgSettingsSegments.h"
10 #include "EngaugeAssert.h"
11 #include "GeometryWindow.h"
13 #include "MainWindow.h"
14 #include "PointStyle.h"
17 #include <QGridLayout>
18 #include <QGraphicsScene>
23 #include "SegmentFactory.h"
24 #include "ViewPreview.h"
26 const int MIN_LENGTH_MIN = 1;
27 const int MIN_LENGTH_MAX = 10000;
28 const int POINT_SEPARATION_MIN = 5;
29 const int POINT_SEPARATION_MAX = 10000;
31 const int IMAGE_WIDTH = 400;
32 const int IMAGE_HEIGHT = 300;
34 const double TWOPI = 2.0 * 3.1415926535;
36 const double BRUSH_WIDTH = 2.0;
40 "DlgSettingsSegments",
44 m_modelSegmentsBefore (0),
45 m_modelSegmentsAfter (0),
48 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::DlgSettingsSegments";
54 DlgSettingsSegments::~DlgSettingsSegments()
56 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::~DlgSettingsSegments";
59 void DlgSettingsSegments::clearPoints ()
61 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::clearPoints";
63 QList<GraphicsPoint*>::iterator itrP;
64 for (itrP = m_points.begin(); itrP != m_points.end(); itrP++) {
72 void DlgSettingsSegments::createControls (QGridLayout *layout,
75 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createControls";
77 QLabel *labelMinLength =
new QLabel(tr (
"Minimum length (points):"));
78 layout->addWidget(labelMinLength, row, 1);
80 m_spinMinLength =
new QSpinBox;
81 m_spinMinLength->setRange (MIN_LENGTH_MIN, MIN_LENGTH_MAX);
82 m_spinMinLength->setWhatsThis (tr (
"Select a minimum number of points in a segment.\n\n"
83 "Only segments with more points will be created.\n\n"
84 "This value should be as large as possible to reduce memory usage. This value has "
86 connect (m_spinMinLength, SIGNAL (valueChanged (
const QString &)),
this, SLOT (slotMinLength (
const QString &)));
87 layout->addWidget(m_spinMinLength, row++, 2);
89 QLabel *labelPointSeparation =
new QLabel(tr (
"Point separation (pixels):"));
90 layout->addWidget (labelPointSeparation, row, 1);
92 m_spinPointSeparation =
new QSpinBox;
93 m_spinPointSeparation->setRange (POINT_SEPARATION_MIN, POINT_SEPARATION_MAX);
94 m_spinPointSeparation->setWhatsThis (tr (
"Select a point separation in pixels.\n\n"
95 "Successive points added to a segment will be separated by this number of pixels. "
96 "If Fill Corners is enabled, then additional points will be inserted at corners so some points "
98 "This value has a lower limit"));
99 connect (m_spinPointSeparation, SIGNAL (valueChanged (
const QString &)),
this, SLOT (slotPointSeparation (
const QString &)));
100 layout->addWidget (m_spinPointSeparation, row++, 2);
102 QLabel *labelFillCorners =
new QLabel (tr (
"Fill corners:"));
103 layout->addWidget (labelFillCorners, row, 1);
105 m_chkFillCorners =
new QCheckBox;
106 m_chkFillCorners->setWhatsThis (tr (
"Fill corners.\n\n"
107 "In addition to the points placed at regular intervals, this option causes a point to be "
108 "placed at each corner. This option can capture important information in piecewise linear graphs, "
109 "but gradually curving graphs may not benefit from the additional points"));
110 connect (m_chkFillCorners, SIGNAL (stateChanged (
int)),
this, SLOT (slotFillCorners (
int)));
111 layout->addWidget (m_chkFillCorners, row++, 2);
113 QLabel *labelLineWidth =
new QLabel(tr (
"Line width:"));
114 layout->addWidget (labelLineWidth, row, 1);
116 m_spinLineWidth =
new QSpinBox;
117 m_spinLineWidth->setWhatsThis (tr (
"Select a size for the lines drawn along a segment"));
118 m_spinLineWidth->setMinimum(1);
119 connect (m_spinLineWidth, SIGNAL (valueChanged (
int)),
this, SLOT (slotLineWidth (
int)));
120 layout->addWidget (m_spinLineWidth, row++, 2);
122 QLabel *labelLineColor =
new QLabel(tr (
"Line color:"));
123 layout->addWidget (labelLineColor, row, 1);
125 m_cmbLineColor =
new QComboBox;
126 m_cmbLineColor->setWhatsThis (tr (
"Select a color for the lines drawn along a segment"));
128 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
129 layout->addWidget (m_cmbLineColor, row++, 2);
136 void DlgSettingsSegments::createPreview (QGridLayout *layout,
139 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createPreview";
141 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
142 layout->addWidget (labelPreview, row++, 0, 1, 4);
144 m_scenePreview =
new QGraphicsScene (
this);
146 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
148 m_viewPreview->setWhatsThis (tr (
"Preview window shows the shortest line that can be segment filled, "
149 "and the effects of current settings on segments and points generated by segment fill"));
150 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
151 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
154 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
157 QImage DlgSettingsSegments::createPreviewImage ()
const
159 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createPreviewImage";
161 QImage image (IMAGE_WIDTH,
163 QImage::Format_RGB32);
164 image.fill (Qt::white);
165 QPainter painter (&image);
166 painter.setRenderHint(QPainter::Antialiasing);
167 painter.setPen (QPen (QBrush (Qt::black), BRUSH_WIDTH));
169 int margin = IMAGE_WIDTH / 15;
170 int yCenter = IMAGE_HEIGHT / 2;
171 int yHeight = IMAGE_HEIGHT / 4;
172 int x, y, xLast, yLast;
177 int xStart = margin, xEnd = IMAGE_WIDTH / 2 - margin;
178 for (x = xStart; x < xEnd; x++) {
179 double s = (double) (x - xStart) / (double) (xEnd - xStart);
180 int y = yCenter - yHeight * qSin (TWOPI * s);
183 painter.drawLine (xLast, yLast, x, y);
192 xStart = IMAGE_WIDTH / 2 + margin, xEnd = IMAGE_WIDTH - margin;
193 for (x = xStart; x < xEnd; x++) {
194 double s = (double) (x - xStart) / (double) (xEnd - xStart);
196 y = yCenter - yHeight * (4.0 * s);
197 }
else if (s < 0.75) {
198 y = yCenter - yHeight * (1.0 - 4.0 * (s - 0.25));
200 y = yCenter + yHeight * (1.0 - 4 * (s - 0.75));
204 painter.drawLine (xLast, yLast, x, y);
216 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createSubPanel";
218 QWidget *subPanel =
new QWidget ();
219 QGridLayout *layout =
new QGridLayout (subPanel);
220 subPanel->setLayout (layout);
222 layout->setColumnStretch (0, 1);
223 layout->setColumnStretch (1, 0);
224 layout->setColumnStretch (2, 0);
225 layout->setColumnStretch (3, 1);
228 createControls(layout, row);
229 createPreview (layout, row);
230 QPixmap pixmap = QPixmap::fromImage (createPreviewImage());
231 m_scenePreview->addPixmap (pixmap);
238 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::handleOk";
242 *m_modelSegmentsBefore,
243 *m_modelSegmentsAfter);
251 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::load";
259 if (m_modelSegmentsBefore != 0) {
260 delete m_modelSegmentsBefore;
262 if (m_modelSegmentsAfter != 0) {
263 delete m_modelSegmentsAfter;
271 ENGAUGE_ASSERT (MIN_LENGTH_MIN <= m_modelSegmentsAfter->minLength ());
272 ENGAUGE_ASSERT (MIN_LENGTH_MAX >= m_modelSegmentsAfter->
minLength ());
273 ENGAUGE_ASSERT (POINT_SEPARATION_MIN <= m_modelSegmentsAfter->pointSeparation());
274 ENGAUGE_ASSERT (POINT_SEPARATION_MAX >= m_modelSegmentsAfter->
pointSeparation());
277 m_spinPointSeparation->setValue (m_modelSegmentsAfter->
pointSeparation());
278 m_spinMinLength->setValue (m_modelSegmentsAfter->
minLength());
279 m_chkFillCorners->setChecked (m_modelSegmentsAfter->
fillCorners ());
280 m_spinLineWidth->setValue (m_modelSegmentsAfter->
lineWidth());
282 int indexLineColor = m_cmbLineColor->findData(QVariant (m_modelSegmentsAfter->
lineColor()));
283 ENGAUGE_ASSERT (indexLineColor >= 0);
284 m_cmbLineColor->setCurrentIndex(indexLineColor);
294 void DlgSettingsSegments::slotFillCorners (
int state)
296 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotFillCorner";
303 void DlgSettingsSegments::slotLineColor (
const QString &)
305 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotLineColor";
307 m_modelSegmentsAfter->
setLineColor((ColorPalette) m_cmbLineColor->currentData().toInt());
312 void DlgSettingsSegments::slotLineWidth (
int lineWidth)
314 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotLineWidth";
321 void DlgSettingsSegments::slotMinLength (
const QString &minLength)
323 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotMinLength";
325 m_modelSegmentsAfter->
setMinLength(minLength.toDouble());
330 void DlgSettingsSegments::slotPointSeparation (
const QString &pointSeparation)
332 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotPointSeparation";
339 void DlgSettingsSegments::updateControls()
344 void DlgSettingsSegments::updatePreview()
346 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::updatePreview"
347 <<
" loading=" << (m_loading ?
"true" :
"false");
349 const QString ARBITRARY_IDENTIFIER (
"");
350 const QColor COLOR (Qt::blue);
351 const int RADIUS = 5;
360 segmentFactory.clearSegments (m_segments);
363 segmentFactory.makeSegments (createPreviewImage(),
364 *m_modelSegmentsAfter,
368 QList<Segment*>::iterator itrS;
369 for (itrS = m_segments.begin(); itrS != m_segments.end(); itrS++) {
379 QPolygonF polygon = pointStyle.polygon();
380 QList<QPoint> points = segmentFactory.fillPoints (*m_modelSegmentsAfter,
382 QList<QPoint>::iterator itrP;
383 for (itrP = points.begin(); itrP != points.end(); itrP++) {
386 ARBITRARY_IDENTIFIER,
391 NULL_GEOMETRY_WINDOW);
393 m_points.push_back (graphicsPoint);
ColorPalette lineColor() const
Get method for line color.
void setLineColor(ColorPalette lineColor)
Set method for line color.
void setMinLength(double minLength)
Set method for min length.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
Window that displays the geometry information, as a table, for the current curve. ...
double pointSeparation() const
Get method for point separation.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
void setLineWidth(double lineWidth)
Set method for line width.
Factory class for Segment objects.
void slotHover(bool hover)
Slot for hover enter/leave events in the associated SegmentLines.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
void setFillCorners(bool fillCorners)
Set method for fill corners.
Details for a specific Point.
Selectable piecewise-defined line that follows a filtered line in the image.
double lineWidth() const
Get method for line width.
Graphics item for drawing a circular or polygonal Point.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
Command for DlgSettingsSegments.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
void finishPanel(QWidget *subPanel, int minimumWidth=MINIMUM_DIALOG_WIDTH)
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.
DlgSettingsSegments(MainWindow &mainWindow)
Single constructor.
double minLength() const
Get method for min length.
Model for DlgSettingsSegments and CmdSettingsSegments.
Abstract base class for all Settings dialogs.
virtual void handleOk()
Process slotOk.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
void setPointSeparation(double pointSeparation)
Set method for point separation.
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.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
bool fillCorners() const
Get method for fill corners.