7#include "CmdMediator.h"
8#include "CmdSettingsSegments.h"
9#include "DlgSettingsSegments.h"
10#include "EngaugeAssert.h"
12#include "MainWindow.h"
13#include "PointStyle.h"
17#include <QGraphicsScene>
22#include "SegmentFactory.h"
23#include "ViewPreview.h"
25const int MIN_LENGTH_MIN = 1;
26const int MIN_LENGTH_MAX = 10000;
27const int POINT_SEPARATION_MIN = 5;
28const int POINT_SEPARATION_MAX = 10000;
30const int IMAGE_WIDTH = 400;
31const int IMAGE_HEIGHT = 300;
33const double TWOPI = 2.0 * 3.1415926535;
35const double BRUSH_WIDTH = 2.0;
39 "DlgSettingsSegments",
43 m_modelSegmentsBefore (0),
44 m_modelSegmentsAfter (0),
47 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::DlgSettingsSegments";
53DlgSettingsSegments::~DlgSettingsSegments()
55 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::~DlgSettingsSegments";
58void DlgSettingsSegments::clearPoints ()
60 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::clearPoints";
62 QList<GraphicsPoint*>::iterator itrP;
63 for (itrP = m_points.begin(); itrP != m_points.end(); itrP++) {
71void DlgSettingsSegments::createControls (QGridLayout *layout,
74 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createControls";
76 QLabel *labelMinLength =
new QLabel(tr (
"Minimum length (points):"));
77 layout->addWidget(labelMinLength, row, 1);
79 m_spinMinLength =
new QSpinBox;
80 m_spinMinLength->setRange (MIN_LENGTH_MIN, MIN_LENGTH_MAX);
81 m_spinMinLength->setWhatsThis (tr (
"Select a minimum number of points in a segment.\n\n"
82 "Only segments with more points will be created.\n\n"
83 "This value should be as large as possible to reduce memory usage. This value has "
85 connect (m_spinMinLength, SIGNAL (valueChanged (
const QString &)),
this, SLOT (slotMinLength (
const QString &)));
86 layout->addWidget(m_spinMinLength, row++, 2);
88 QLabel *labelPointSeparation =
new QLabel(tr (
"Point separation (pixels):"));
89 layout->addWidget (labelPointSeparation, row, 1);
91 m_spinPointSeparation =
new QSpinBox;
92 m_spinPointSeparation->setRange (POINT_SEPARATION_MIN, POINT_SEPARATION_MAX);
93 m_spinPointSeparation->setWhatsThis (tr (
"Select a point separation in pixels.\n\n"
94 "Successive points added to a segment will be separated by this number of pixels. "
95 "If Fill Corners is enabled, then additional points will be inserted at corners so some points "
97 "This value has a lower limit"));
98 connect (m_spinPointSeparation, SIGNAL (valueChanged (
const QString &)),
this, SLOT (slotPointSeparation (
const QString &)));
99 layout->addWidget (m_spinPointSeparation, row++, 2);
101 QLabel *labelFillCorners =
new QLabel (tr (
"Fill corners:"));
102 layout->addWidget (labelFillCorners, row, 1);
104 m_chkFillCorners =
new QCheckBox;
105 m_chkFillCorners->setWhatsThis (tr (
"Fill corners.\n\n"
106 "In addition to the points placed at regular intervals, this option causes a point to be "
107 "placed at each corner. This option can capture important information in piecewise linear graphs, "
108 "but gradually curving graphs may not benefit from the additional points"));
109 connect (m_chkFillCorners, SIGNAL (stateChanged (
int)),
this, SLOT (slotFillCorners (
int)));
110 layout->addWidget (m_chkFillCorners, row++, 2);
112 QLabel *labelLineWidth =
new QLabel(tr (
"Line width:"));
113 layout->addWidget (labelLineWidth, row, 1);
115 m_spinLineWidth =
new QSpinBox;
116 m_spinLineWidth->setWhatsThis (tr (
"Select a size for the lines drawn along a segment"));
117 m_spinLineWidth->setMinimum(1);
118 connect (m_spinLineWidth, SIGNAL (valueChanged (
int)),
this, SLOT (slotLineWidth (
int)));
119 layout->addWidget (m_spinLineWidth, row++, 2);
121 QLabel *labelLineColor =
new QLabel(tr (
"Line color:"));
122 layout->addWidget (labelLineColor, row, 1);
124 m_cmbLineColor =
new QComboBox;
125 m_cmbLineColor->setWhatsThis (tr (
"Select a color for the lines drawn along a segment"));
127 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
128 layout->addWidget (m_cmbLineColor, row++, 2);
135void DlgSettingsSegments::createPreview (QGridLayout *layout,
138 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createPreview";
140 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
141 layout->addWidget (labelPreview, row++, 0, 1, 4);
143 m_scenePreview =
new QGraphicsScene (
this);
145 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
147 m_viewPreview->setWhatsThis (tr (
"Preview window shows the shortest line that can be segment filled, "
148 "and the effects of current settings on segments and points generated by segment fill"));
149 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
150 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
153 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
156QImage DlgSettingsSegments::createPreviewImage ()
const
158 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createPreviewImage";
160 QImage image (IMAGE_WIDTH,
162 QImage::Format_RGB32);
163 image.fill (Qt::white);
164 QPainter painter (&image);
165 painter.setRenderHint(QPainter::Antialiasing);
166 painter.setPen (QPen (QBrush (Qt::black), BRUSH_WIDTH));
168 int margin = IMAGE_WIDTH / 15;
169 int yCenter = IMAGE_HEIGHT / 2;
170 int yHeight = IMAGE_HEIGHT / 4;
171 int x, y, xLast, yLast;
176 int xStart = margin, xEnd = IMAGE_WIDTH / 2 - margin;
177 for (x = xStart; x < xEnd; x++) {
178 double s = (double) (x - xStart) / (double) (xEnd - xStart);
179 int y = yCenter - yHeight * qSin (TWOPI * s);
182 painter.drawLine (xLast, yLast, x, y);
191 xStart = IMAGE_WIDTH / 2 + margin, xEnd = IMAGE_WIDTH - margin;
192 for (x = xStart; x < xEnd; x++) {
193 double s = (double) (x - xStart) / (double) (xEnd - xStart);
195 y = yCenter - yHeight * (4.0 * s);
196 }
else if (s < 0.75) {
197 y = yCenter - yHeight * (1.0 - 4.0 * (s - 0.25));
199 y = yCenter + yHeight * (1.0 - 4 * (s - 0.75));
203 painter.drawLine (xLast, yLast, x, y);
215 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::createSubPanel";
217 QWidget *subPanel =
new QWidget ();
218 QGridLayout *layout =
new QGridLayout (subPanel);
219 subPanel->setLayout (layout);
221 layout->setColumnStretch (0, 1);
222 layout->setColumnStretch (1, 0);
223 layout->setColumnStretch (2, 0);
224 layout->setColumnStretch (3, 1);
227 createControls(layout, row);
228 createPreview (layout, row);
229 QPixmap pixmap = QPixmap::fromImage (createPreviewImage());
230 m_scenePreview->addPixmap (pixmap);
237 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::handleOk";
241 *m_modelSegmentsBefore,
242 *m_modelSegmentsAfter);
250 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::load";
258 if (m_modelSegmentsBefore != 0) {
259 delete m_modelSegmentsBefore;
261 if (m_modelSegmentsAfter != 0) {
262 delete m_modelSegmentsAfter;
270 ENGAUGE_ASSERT (MIN_LENGTH_MIN <= m_modelSegmentsAfter->minLength ());
271 ENGAUGE_ASSERT (MIN_LENGTH_MAX >= m_modelSegmentsAfter->
minLength ());
272 ENGAUGE_ASSERT (POINT_SEPARATION_MIN <= m_modelSegmentsAfter->pointSeparation());
273 ENGAUGE_ASSERT (POINT_SEPARATION_MAX >= m_modelSegmentsAfter->
pointSeparation());
276 m_spinPointSeparation->setValue (m_modelSegmentsAfter->
pointSeparation());
277 m_spinMinLength->setValue (m_modelSegmentsAfter->
minLength());
278 m_chkFillCorners->setChecked (m_modelSegmentsAfter->
fillCorners ());
279 m_spinLineWidth->setValue (m_modelSegmentsAfter->
lineWidth());
281 int indexLineColor = m_cmbLineColor->findData(QVariant (m_modelSegmentsAfter->
lineColor()));
282 ENGAUGE_ASSERT (indexLineColor >= 0);
283 m_cmbLineColor->setCurrentIndex(indexLineColor);
293void DlgSettingsSegments::slotFillCorners (
int state)
295 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotFillCorner";
302void DlgSettingsSegments::slotLineColor (
const QString &)
304 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotLineColor";
306 m_modelSegmentsAfter->
setLineColor((ColorPalette) m_cmbLineColor->currentData().toInt());
311void DlgSettingsSegments::slotLineWidth (
int lineWidth)
313 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotLineWidth";
320void DlgSettingsSegments::slotMinLength (
const QString &minLength)
322 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotMinLength";
324 m_modelSegmentsAfter->
setMinLength(minLength.toDouble());
329void DlgSettingsSegments::slotPointSeparation (
const QString &pointSeparation)
331 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::slotPointSeparation";
338void DlgSettingsSegments::updateControls()
343void DlgSettingsSegments::updatePreview()
345 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsSegments::updatePreview"
346 <<
" loading=" << (m_loading ?
"true" :
"false");
348 const QString ARBITRARY_IDENTIFIER (
"");
349 const QColor COLOR (Qt::blue);
350 const int RADIUS = 5;
358 segmentFactory.clearSegments (m_segments);
361 segmentFactory.makeSegments (createPreviewImage(),
362 *m_modelSegmentsAfter,
366 QList<Segment*>::iterator itrS;
367 for (itrS = m_segments.begin(); itrS != m_segments.end(); itrS++) {
377 QPolygonF polygon = pointStyle.polygon();
378 QList<QPoint> points = segmentFactory.fillPoints (*m_modelSegmentsAfter,
380 QList<QPoint>::iterator itrP;
381 for (itrP = points.begin(); itrP != points.end(); itrP++) {
384 ARBITRARY_IDENTIFIER,
389 m_points.push_back (graphicsPoint);
Command for DlgSettingsSegments.
Abstract base class for all Settings dialogs.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
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 enableOk(bool enable)
Let leaf subclass control the Ok button.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
MainWindow & mainWindow()
Get method for MainWindow.
virtual void handleOk()
Process slotOk.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
DlgSettingsSegments(MainWindow &mainWindow)
Single constructor.
Model for DlgSettingsSegments and CmdSettingsSegments.
void setFillCorners(bool fillCorners)
Set method for fill corners.
void setPointSeparation(double pointSeparation)
Set method for point separation.
ColorPalette lineColor() const
Get method for line color.
double minLength() const
Get method for min length.
void setLineColor(ColorPalette lineColor)
Set method for line color.
bool fillCorners() const
Get method for fill corners.
void setLineWidth(double lineWidth)
Set method for line width.
double pointSeparation() const
Get method for point separation.
double lineWidth() const
Get method for line width.
void setMinLength(double minLength)
Set method for min length.
Graphics item for drawing a circular or polygonal Point.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Details for a specific Point.
Factory class for Segment objects.
Selectable piecewise-defined line that follows a filtered line in the image.
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,...