20#include <QGraphicsScene>
42 "DlgSettingsSegments",
44 m_scenePreviewActive (nullptr),
45 m_scenePreviewInactive (nullptr),
46 m_viewPreviewActive (nullptr),
47 m_viewPreviewInactive (nullptr),
48 m_modelSegmentsBefore (nullptr),
49 m_modelSegmentsAfter (nullptr),
63void DlgSettingsSegments::clearPointsOneScene (
GraphicsPoints &points)
65 QList<GraphicsPoint*>::iterator itrP;
66 for (itrP = points.begin(); itrP != points.end(); itrP++) {
74void DlgSettingsSegments::createControls (QGridLayout *layout,
79 QLabel *labelMinLength =
new QLabel(QString (
"%1:").arg (tr (
"Minimum length (points)")));
80 layout->addWidget(labelMinLength, row, 1);
82 m_spinMinLength =
new QSpinBox;
84 m_spinMinLength->setWhatsThis (tr (
"Select a minimum number of points in a segment.\n\n"
85 "Only segments with more points will be created.\n\n"
86 "This value should be as large as possible to reduce memory usage. This value has "
88 connect (m_spinMinLength, SIGNAL (valueChanged (
const QString &)),
this, SLOT (slotMinLength (
const QString &)));
89 layout->addWidget(m_spinMinLength, row++, 2);
91 QLabel *labelPointSeparation =
new QLabel(QString (
"%1:").arg (tr (
"Point separation (pixels)")));
92 layout->addWidget (labelPointSeparation, row, 1);
94 m_spinPointSeparation =
new QSpinBox;
96 m_spinPointSeparation->setWhatsThis (tr (
"Select a point separation in pixels.\n\n"
97 "Successive points added to a segment will be separated by this number of pixels. "
98 "If Fill Corners is enabled, then additional points will be inserted at corners so some points "
100 "This value has a lower limit"));
101 connect (m_spinPointSeparation, SIGNAL (valueChanged (
const QString &)),
this, SLOT (slotPointSeparation (
const QString &)));
102 layout->addWidget (m_spinPointSeparation, row++, 2);
104 QLabel *labelFillCorners =
new QLabel (QString (
"%1:").arg (tr (
"Fill corners")));
105 layout->addWidget (labelFillCorners, row, 1);
107 m_chkFillCorners =
new QCheckBox;
108 m_chkFillCorners->setWhatsThis (tr (
"Fill corners.\n\n"
109 "In addition to the points placed at regular intervals, this option causes a point to be "
110 "placed at each corner. This option can capture important information in piecewise linear graphs, "
111 "but gradually curving graphs may not benefit from the additional points"));
112 connect (m_chkFillCorners, SIGNAL (stateChanged (
int)),
this, SLOT (slotFillCorners (
int)));
113 layout->addWidget (m_chkFillCorners, row++, 2);
115 QLabel *labelLineWidthActive =
new QLabel(QString (
"%1:").arg (tr (
"Active line width")));
116 layout->addWidget (labelLineWidthActive, row, 1);
118 m_spinLineWidthActive =
new QSpinBox;
119 m_spinLineWidthActive->setWhatsThis (tr (
"Select a size for the lines drawn along a segment when hovering over the segment"));
120 m_spinLineWidthActive->setMinimum(1);
121 connect (m_spinLineWidthActive, SIGNAL (valueChanged (
int)),
this, SLOT (slotLineWidthActive (
int)));
122 layout->addWidget (m_spinLineWidthActive, row++, 2);
124 QLabel *labelLineWidthInactive =
new QLabel(QString (
"%1:").arg (tr (
"Inactive line width")));
125 layout->addWidget (labelLineWidthInactive, row, 1);
127 m_spinLineWidthInactive =
new QSpinBox;
128 m_spinLineWidthInactive->setWhatsThis (tr (
"Select a size for the lines drawn along a segment when not hovering over the segment"));
129 m_spinLineWidthInactive->setMinimum(1);
130 connect (m_spinLineWidthInactive, SIGNAL (valueChanged (
int)),
this, SLOT (slotLineWidthInactive (
int)));
131 layout->addWidget (m_spinLineWidthInactive, row++, 2);
133 QLabel *labelLineColor =
new QLabel(QString (
"%1:").arg (tr (
"Line color")));
134 layout->addWidget (labelLineColor, row, 1);
136 m_cmbLineColor =
new QComboBox;
137 m_cmbLineColor->setWhatsThis (tr (
"Select a color for the lines drawn along a segment"));
139 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
140 this, SLOT (slotLineColor (
const QString &)));
141 layout->addWidget (m_cmbLineColor, row++, 2);
143 QLabel *labelInactiveOpacity =
new QLabel(QString (
"%1:").arg (tr (
"Inactive opacity")));
144 layout->addWidget (labelInactiveOpacity, row, 1);
146 m_cmbInactiveOpacity =
new QComboBox;
147 m_cmbInactiveOpacity->setWhatsThis (tr (
"Select an opacity for the inactive segments that are not under the cursor"));
166 connect (m_cmbInactiveOpacity, SIGNAL (activated (
const QString &)),
167 this, SLOT (slotInactiveOpacity (
const QString &)));
168 layout->addWidget (m_cmbInactiveOpacity, row++, 2);
175void DlgSettingsSegments::createPreview (QGridLayout *layout,
180 QLabel *labelPreviewActive =
new QLabel (tr (
"Hover Preview"));
181 layout->addWidget (labelPreviewActive, row, 0, 1, 2);
183 QLabel *labelPreviewInactive =
new QLabel (tr (
"Inactive Preview"));
184 layout->addWidget (labelPreviewInactive, row++, 2, 1, 2);
186 m_scenePreviewActive =
new QGraphicsScene (
this);
187 m_viewPreviewActive =
new ViewPreview (m_scenePreviewActive,
190 m_viewPreviewActive->setWhatsThis (tr (
"For segments under the cursor, this preview window shows the shortest "
191 "line that can be segment filled, "
192 "and the effects of current settings on segments and points generated by segment fill"));
193 m_viewPreviewActive->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
194 m_viewPreviewActive->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
196 layout->addWidget (m_viewPreviewActive, row, 0, 1, 2);
198 m_scenePreviewInactive =
new QGraphicsScene (
this);
199 m_viewPreviewInactive =
new ViewPreview (m_scenePreviewInactive,
202 m_viewPreviewInactive->setWhatsThis (tr (
"For segments not under the cursor, this preview window shows the shortest "
203 "line that can be segment filled, "
204 "and the effects of current settings on segments and points generated by segment fill"));
205 m_viewPreviewInactive->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
206 m_viewPreviewInactive->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
208 layout->addWidget (m_viewPreviewInactive, row++, 2, 1, 2);
211QImage DlgSettingsSegments::createPreviewImage ()
const
217 QImage::Format_RGB32);
218 image.fill (Qt::white);
219 QPainter painter (&image);
220 painter.setRenderHint(QPainter::Antialiasing);
221 painter.setPen (QPen (QBrush (Qt::black),
BRUSH_WIDTH));
226 int x, y, xLast = 0, yLast = 0;
231 int xStart = margin, xEnd =
IMAGE_WIDTH / 2 - margin;
232 for (x = xStart; x < xEnd; x++) {
233 double s = double (x - xStart) / double (xEnd - xStart);
234 int y = qFloor (yCenter - yHeight * qSin (2.0 * M_PI * s));
237 painter.drawLine (xLast, yLast, x, y);
248 for (x = xStart; x < xEnd; x++) {
249 double s = double (x - xStart) / double (xEnd - xStart);
251 y = qFloor (yCenter - yHeight * (4.0 * s));
252 }
else if (s < 0.75) {
253 y = qFloor (yCenter - yHeight * (1.0 - 4.0 * (s - 0.25)));
255 y = qFloor (yCenter + yHeight * (1.0 - 4 * (s - 0.75)));
259 painter.drawLine (xLast, yLast, x, y);
273 QWidget *subPanel =
new QWidget ();
274 QGridLayout *layout =
new QGridLayout (subPanel);
275 subPanel->setLayout (layout);
277 layout->setColumnStretch (0, 1);
278 layout->setColumnStretch (1, 0);
279 layout->setColumnStretch (2, 0);
280 layout->setColumnStretch (3, 1);
287 createControls(layout, row);
288 createPreview (layout, row);
289 QPixmap pixmap = QPixmap::fromImage (createPreviewImage());
292 pixmap = QPixmap::fromImage (createPreviewImage());
305 *m_modelSegmentsBefore,
306 *m_modelSegmentsAfter);
322 delete m_modelSegmentsBefore;
323 delete m_modelSegmentsAfter;
336 m_spinPointSeparation->setValue (qFloor (m_modelSegmentsAfter->pointSeparation()));
337 m_spinMinLength->setValue (qFloor (m_modelSegmentsAfter->minLength()));
338 m_chkFillCorners->setChecked (m_modelSegmentsAfter->fillCorners ());
339 m_spinLineWidthActive->setValue (qFloor (m_modelSegmentsAfter->lineWidthActive()));
340 m_spinLineWidthInactive->setValue (qFloor (m_modelSegmentsAfter->lineWidthInactive()));
342 int indexLineColor = m_cmbLineColor->findData(QVariant (m_modelSegmentsAfter->lineColor()));
344 m_cmbLineColor->setCurrentIndex(indexLineColor);
346 int indexInactiveOpacity = m_cmbInactiveOpacity->findData (QVariant (m_modelSegmentsAfter->inactiveOpacity()));
348 m_cmbInactiveOpacity->setCurrentIndex (indexInactiveOpacity);
365void DlgSettingsSegments::slotFillCorners (
int state)
374void DlgSettingsSegments::slotInactiveOpacity (
const QString &)
379 m_modelSegmentsAfter->setInactiveOpacity(inactiveOpacity);
384void DlgSettingsSegments::slotLineColor (
const QString &)
388 m_modelSegmentsAfter->setLineColor(
static_cast<ColorPalette> (m_cmbLineColor->currentData().toInt()));
393void DlgSettingsSegments::slotLineWidthActive (
int lineWidthActive)
397 m_modelSegmentsAfter->setLineWidthActive(lineWidthActive);
402void DlgSettingsSegments::slotLineWidthInactive (
int lineWidthInactive)
406 m_modelSegmentsAfter->setLineWidthInactive(lineWidthInactive);
411void DlgSettingsSegments::slotMinLength (
const QString &minLength)
415 m_modelSegmentsAfter->setMinLength(minLength.toDouble());
420void DlgSettingsSegments::slotPointSeparation (
const QString &pointSeparation)
424 m_modelSegmentsAfter->setPointSeparation(pointSeparation.toDouble());
429void DlgSettingsSegments::slotWhatsThis ()
431 QWhatsThis::enterWhatsThisMode();
434void DlgSettingsSegments::updateControls()
439void DlgSettingsSegments::updatePreview()
442 <<
" loading=" << (m_loading ?
"true" :
"false");
444 updatePreviewOneScene (m_scenePreviewActive,
448 updatePreviewOneScene (m_scenePreviewInactive,
454void DlgSettingsSegments::updatePreviewOneScene (QGraphicsScene *scenePreview,
455 QList<Segment*> &segments,
457 HoverState hoverState)
459 const QString ARBITRARY_IDENTIFIER (
"");
460 const QColor COLOR (Qt::blue);
461 const int RADIUS = 5;
462 GeometryWindow *NULL_GEOMETRY_WINDOW =
nullptr;
463 const bool NO_DIALOG =
false;
467 SegmentFactory segmentFactory (*scenePreview,
470 clearPointsOneScene (points);
471 segmentFactory.clearSegments (segments);
474 segmentFactory.makeSegments (createPreviewImage(),
475 *m_modelSegmentsAfter,
480 QList<Segment*>::iterator itrS;
481 for (itrS = segments.begin(); itrS != segments.end(); itrS++) {
482 Segment *segment = *itrS;
484 segment->
slotHover (hoverState == HOVER_ACTIVE);
493 QPolygonF polygon = pointStyle.polygon();
494 QList<QPoint> pointsFill = segmentFactory.fillPoints (*m_modelSegmentsAfter,
497 QList<QPoint>::iterator itrP;
498 for (itrP = pointsFill.begin(); itrP != pointsFill.end(); itrP++) {
500 GraphicsPoint *graphicsPoint =
new GraphicsPoint (*scenePreview,
501 ARBITRARY_IDENTIFIER,
506 NULL_GEOMETRY_WINDOW);
508 points.push_back (graphicsPoint);
const int POINT_SEPARATION_MIN
const int POINT_SEPARATION_MAX
QList< GraphicsPoint * > GraphicsPoints
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
QString inactiveOpacityEnumToQString(InactiveOpacity inactiveOpacity)
Map InactiveOpacity enum to corresponding string value.
InactiveOpacity
Enum for opacity/alpha values used for segments that are not currently under hover.
log4cpp::Category * mainCat
Command for DlgSettingsSegments.
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 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 ~DlgSettingsSegments()
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
DlgSettingsSegments(MainWindow &mainWindow)
Single constructor.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
Model for DlgSettingsSegments and CmdSettingsSegments.
void setFillCorners(bool fillCorners)
Set method for fill corners.
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...
void lockHoverState()
Disable hover events. This is used only by DlgSettingsSegments to stop hover events in the preview wi...
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,...
@ VIEW_ASPECT_RATIO_VARIABLE
#define LOG4CPP_INFO_S(logger)