8#include "CmdMediator.h"
9#include "CmdSettingsAxesChecker.h"
10#include "CoordScale.h"
11#include "DlgSettingsAxesChecker.h"
12#include "EngaugeAssert.h"
14#include "MainWindow.h"
15#include <QButtonGroup>
17#include <QGraphicsRectItem>
18#include <QGraphicsScene>
24#include <QRadioButton>
25#include "ViewPreview.h"
27const int AXIS_WIDTH = 4;
28const int RECT_WIDTH = 640;
29const int RECT_HEIGHT = 480;
30const int X_LEFT = RECT_WIDTH / 8;
31const int X_RIGHT = RECT_WIDTH * 7 / 8;
32const int Y_TOP = RECT_HEIGHT / 8;
33const int Y_BOTTOM = RECT_HEIGHT * 7 / 8;
34const int TICKS_PER_AXIS = 6;
35const int TICK_MARK_LENGTH = 8;
39 "DlgSettingsAxesChecker",
42 m_modelAxesCheckerBefore (0),
43 m_modelAxesCheckerAfter (0),
46 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::DlgSettingsAxesChecker";
52DlgSettingsAxesChecker::~DlgSettingsAxesChecker()
54 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::~DlgSettingsAxesChecker";
57void DlgSettingsAxesChecker::createControls (QGridLayout *layout,
60 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createControls";
62 QGroupBox *groupBox =
new QGroupBox (tr (
"Axes Checker Lifetime"));
63 layout->addWidget (groupBox, row++, 1, 1, 2);
65 QGridLayout *layoutLifetime =
new QGridLayout;
66 groupBox->setLayout (layoutLifetime);
69 m_btnNever =
new QRadioButton (tr (
"Do not show"), groupBox);
70 m_btnNever->setWhatsThis (tr (
"Never show axes checker."));
71 layoutLifetime->addWidget (m_btnNever, rowLifetime++, 0, 1, 2);
73 m_btnNSeconds =
new QRadioButton (tr (
"Show for a number of seconds"), groupBox);
74 m_btnNSeconds->setWhatsThis (tr (
"Show axes checker for a number of seconds after changing axes points."));
75 layoutLifetime->addWidget (m_btnNSeconds, rowLifetime, 0, 1, 1);
77 m_cmbSeconds =
new QComboBox;
78 for (
int seconds = 1; seconds <= 10; seconds++) {
79 m_cmbSeconds->addItem (QString::number (seconds), QVariant (seconds));
81 layoutLifetime->addWidget (m_cmbSeconds, rowLifetime++, 1);
82 connect (m_cmbSeconds, SIGNAL (activated (
const QString &)),
this, SLOT (slotSeconds (
const QString &)));
84 m_btnForever =
new QRadioButton (tr (
"Show always"), groupBox);
85 m_btnForever->setWhatsThis (tr (
"Always show axes checker."));
86 layoutLifetime->addWidget (m_btnForever, rowLifetime++, 0, 1, 2);
88 m_groupMode =
new QButtonGroup;
89 m_groupMode->addButton (m_btnNever);
90 m_groupMode->addButton (m_btnNSeconds);
91 m_groupMode->addButton (m_btnForever);
92 connect (m_groupMode, SIGNAL (buttonReleased (QAbstractButton*)),
this, SLOT (slotGroupMode (QAbstractButton*)));
94 QLabel *labelLineColor =
new QLabel (tr (
"Line color:"));
95 layout->addWidget (labelLineColor, row, 1);
97 m_cmbLineColor =
new QComboBox;
98 m_cmbLineColor->setWhatsThis (tr (
"Select a color for the highlight lines drawn at each axis point"));
100 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
101 layout->addWidget (m_cmbLineColor, row++, 2);
108void DlgSettingsAxesChecker::createPoints ()
110 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createPoints";
112 QBrush AXES_BRUSH (Qt::gray);
114 m_checker =
new Checker (*m_scenePreview);
118 QGraphicsRectItem *itemRect =
new QGraphicsRectItem (0,
122 itemRect->setPen (Qt::NoPen);
123 m_scenePreview->addItem (itemRect);
126 QGraphicsRectItem *frameBox =
new QGraphicsRectItem (X_LEFT,
130 frameBox->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
131 frameBox->setZValue (-1);
132 m_scenePreview->addItem (frameBox);
133 for (
int x = X_LEFT; x < X_RIGHT; x += (X_RIGHT - X_LEFT) / TICKS_PER_AXIS) {
134 QGraphicsLineItem *tick =
new QGraphicsLineItem (x, Y_BOTTOM, x, Y_BOTTOM + TICK_MARK_LENGTH);
135 tick->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
136 tick->setZValue (-1);
137 m_scenePreview->addItem (tick);
139 for (
int y = Y_TOP; y < Y_BOTTOM; y += (Y_BOTTOM - Y_TOP) / TICKS_PER_AXIS) {
140 QGraphicsLineItem *tick =
new QGraphicsLineItem (X_LEFT, y, X_LEFT + TICK_MARK_LENGTH, y);
141 tick->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
142 tick->setZValue (-1);
143 m_scenePreview->addItem (tick);
147void DlgSettingsAxesChecker::createPreview (QGridLayout *layout,
150 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createPreview";
152 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
153 layout->addWidget (labelPreview, row++, 0, 1, 4);
155 m_scenePreview =
new QGraphicsScene (
this);
157 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
159 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect the displayed axes checker"));
160 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
161 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
164 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
169 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createSubPanel";
171 QWidget *subPanel =
new QWidget ();
172 QGridLayout *layout =
new QGridLayout (subPanel);
173 subPanel->setLayout (layout);
175 layout->setColumnStretch(0, 1);
176 layout->setColumnStretch(1, 0);
177 layout->setColumnStretch(2, 0);
178 layout->setColumnStretch(3, 1);
181 createControls (layout, row);
182 createPreview (layout, row);
191 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::handleOk";
195 *m_modelAxesCheckerBefore,
196 *m_modelAxesCheckerAfter);
204 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::load";
209 if (m_modelAxesCheckerBefore != 0) {
210 delete m_modelAxesCheckerBefore;
212 if (m_modelAxesCheckerAfter != 0) {
213 delete m_modelAxesCheckerAfter;
215 if (m_modelCoords != 0) {
216 delete m_modelCoords;
225 CheckerMode checkerMode = m_modelAxesCheckerAfter->
checkerMode();
226 m_btnNever->setChecked (checkerMode == CHECKER_MODE_NEVER);
227 m_btnNSeconds->setChecked (checkerMode == CHECKER_MODE_N_SECONDS);
228 m_btnForever->setChecked (checkerMode == CHECKER_MODE_FOREVER);
229 int indexSeconds = m_cmbSeconds->findData (QVariant (m_modelAxesCheckerAfter->
checkerSeconds()));
230 ENGAUGE_ASSERT (indexSeconds >= 0);
231 m_cmbSeconds->setCurrentIndex(indexSeconds);
233 int indexLineColor = m_cmbLineColor->findData (QVariant (m_modelAxesCheckerAfter->
lineColor()));
234 ENGAUGE_ASSERT (indexLineColor >= 0);
235 m_cmbLineColor->setCurrentIndex (indexLineColor);
242void DlgSettingsAxesChecker::slotGroupMode (QAbstractButton*)
244 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotGroupMode";
246 if (m_btnNever->isChecked ()) {
248 }
else if (m_btnNSeconds->isChecked ()) {
258void DlgSettingsAxesChecker::slotLineColor(
const QString &)
260 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotLineColor";
262 m_modelAxesCheckerAfter->
setLineColor ((ColorPalette) m_cmbLineColor->currentData().toInt());
267void DlgSettingsAxesChecker::slotSeconds (
const QString &)
269 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotLineColor";
275void DlgSettingsAxesChecker::updateControls ()
279 m_cmbSeconds->setEnabled (m_btnNSeconds->isChecked ());
282void DlgSettingsAxesChecker::updatePreview()
284 const int ZERO_RADIUS_SINCE_NO_POINTS = 0;
286 QVector<QPointF> points;
287 points.push_back (QPointF (X_LEFT, Y_TOP));
288 points.push_back (QPointF (X_LEFT, Y_BOTTOM));
289 points.push_back (QPointF (X_RIGHT, Y_BOTTOM));
291 QPolygonF polygon (points);
293 ENGAUGE_ASSERT (m_checker != 0);
295 ZERO_RADIUS_SINCE_NO_POINTS,
296 *m_modelAxesCheckerAfter,
Box shape that is drawn through the three axis points, to temporarily (usually) or permanently (rarel...
void prepareForDisplay(const QPolygonF &polygon, int pointRadius, const DocumentModelAxesChecker &modelAxesChecker, const DocumentModelCoords &modelCoords, DocumentAxesPointsRequired documentAxesPointsRequired)
Create the polygon from current information, including pixel coordinates, just prior to display.
Command for DlgSettingsAxesChecker.
Abstract base class for all Settings dialogs.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
CmdMediator & cmdMediator()
Provide access to Document information wrapped inside CmdMediator.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
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 void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
DlgSettingsAxesChecker(MainWindow &mainWindow)
Single constructor.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
Model for DlgSettingsAxesChecker and CmdSettingsAxesChecker.
void setLineColor(ColorPalette lineColor)
Set method for line color.
ColorPalette lineColor() const
Get method for line color.
int checkerSeconds() const
Get method for checker lifetime in seconds.
void setCheckerSeconds(int seconds)
Set method for checker lifetime in seconds.
CheckerMode checkerMode() const
Get method for checker lifetime mode.
void setCheckerMode(CheckerMode checkerMode)
Set method for checker mode.
Model for DlgSettingsCoords and CmdSettingsCoords.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...