2 #include "CmdMediator.h"
3 #include "CmdSettingsAxesChecker.h"
4 #include "CoordScale.h"
5 #include "DlgSettingsAxesChecker.h"
6 #include "EngaugeAssert.h"
8 #include "MainWindow.h"
9 #include <QButtonGroup>
11 #include <QGraphicsRectItem>
12 #include <QGraphicsScene>
13 #include <QGridLayout>
18 #include <QRadioButton>
19 #include "ViewPreview.h"
21 const int AXIS_WIDTH = 4;
22 const int RECT_WIDTH = 640;
23 const int RECT_HEIGHT = 480;
24 const int X_LEFT = RECT_WIDTH / 8;
25 const int X_RIGHT = RECT_WIDTH * 7 / 8;
26 const int Y_TOP = RECT_HEIGHT / 8;
27 const int Y_BOTTOM = RECT_HEIGHT * 7 / 8;
28 const int TICKS_PER_AXIS = 6;
29 const int TICK_MARK_LENGTH = 8;
33 "DlgSettingsAxesChecker",
36 m_modelAxesCheckerBefore (0),
37 m_modelAxesCheckerAfter (0),
40 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::DlgSettingsAxesChecker";
46 DlgSettingsAxesChecker::~DlgSettingsAxesChecker()
48 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::~DlgSettingsAxesChecker";
51 void DlgSettingsAxesChecker::createControls (QGridLayout *layout,
54 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createControls";
56 QGroupBox *groupBox =
new QGroupBox (tr (
"Axes Checker Lifetime"));
57 layout->addWidget (groupBox, row++, 1, 1, 2);
59 QGridLayout *layoutLifetime =
new QGridLayout;
60 groupBox->setLayout (layoutLifetime);
63 m_btnNever =
new QRadioButton (
"Do not show", groupBox);
64 m_btnNever->setWhatsThis (tr (
"Never show axes checker."));
65 layoutLifetime->addWidget (m_btnNever, rowLifetime++, 0, 1, 2);
67 m_btnNSeconds =
new QRadioButton (
"Show for a number of seconds", groupBox);
68 m_btnNSeconds->setWhatsThis (tr (
"Show axes checker for a number of seconds after changing axes points."));
69 layoutLifetime->addWidget (m_btnNSeconds, rowLifetime, 0, 1, 1);
71 m_cmbSeconds =
new QComboBox;
72 for (
int seconds = 1; seconds <= 10; seconds++) {
73 m_cmbSeconds->addItem (QString::number (seconds), QVariant (seconds));
75 layoutLifetime->addWidget (m_cmbSeconds, rowLifetime++, 1);
76 connect (m_cmbSeconds, SIGNAL (activated (
const QString &)),
this, SLOT (slotSeconds (
const QString &)));
78 m_btnForever =
new QRadioButton (
"Show always", groupBox);
79 m_btnForever->setWhatsThis (tr (
"Always show axes checker."));
80 layoutLifetime->addWidget (m_btnForever, rowLifetime++, 0, 1, 2);
82 m_groupMode =
new QButtonGroup;
83 m_groupMode->addButton (m_btnNever);
84 m_groupMode->addButton (m_btnNSeconds);
85 m_groupMode->addButton (m_btnForever);
86 connect (m_groupMode, SIGNAL (buttonReleased (QAbstractButton*)),
this, SLOT (slotGroupMode (QAbstractButton*)));
88 QLabel *labelLineColor =
new QLabel (
"Line color:");
89 layout->addWidget (labelLineColor, row, 1);
91 m_cmbLineColor =
new QComboBox;
92 m_cmbLineColor->setWhatsThis (tr (
"Select a color for the highlight lines drawn at each axis point"));
94 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
95 layout->addWidget (m_cmbLineColor, row++, 2);
102 void DlgSettingsAxesChecker::createPoints ()
104 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createPoints";
106 QBrush AXES_BRUSH (Qt::gray);
108 m_checker =
new Checker (*m_scenePreview);
112 QGraphicsRectItem *itemRect =
new QGraphicsRectItem (0,
116 itemRect->setPen (Qt::NoPen);
117 m_scenePreview->addItem (itemRect);
120 QGraphicsRectItem *frameBox =
new QGraphicsRectItem (X_LEFT,
124 frameBox->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
125 frameBox->setZValue (-1);
126 m_scenePreview->addItem (frameBox);
127 for (
int x = X_LEFT; x < X_RIGHT; x += (X_RIGHT - X_LEFT) / TICKS_PER_AXIS) {
128 QGraphicsLineItem *tick =
new QGraphicsLineItem (x, Y_BOTTOM, x, Y_BOTTOM + TICK_MARK_LENGTH);
129 tick->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
130 tick->setZValue (-1);
131 m_scenePreview->addItem (tick);
133 for (
int y = Y_TOP; y < Y_BOTTOM; y += (Y_BOTTOM - Y_TOP) / TICKS_PER_AXIS) {
134 QGraphicsLineItem *tick =
new QGraphicsLineItem (X_LEFT, y, X_LEFT + TICK_MARK_LENGTH, y);
135 tick->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
136 tick->setZValue (-1);
137 m_scenePreview->addItem (tick);
141 void DlgSettingsAxesChecker::createPreview (QGridLayout *layout,
144 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createPreview";
146 QLabel *labelPreview =
new QLabel (
"Preview");
147 layout->addWidget (labelPreview, row++, 0, 1, 4);
149 m_scenePreview =
new QGraphicsScene (
this);
151 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
153 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect the displayed axes checker"));
154 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
155 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
158 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
163 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createSubPanel";
165 QWidget *subPanel =
new QWidget ();
166 QGridLayout *layout =
new QGridLayout (subPanel);
167 subPanel->setLayout (layout);
169 layout->setColumnStretch(0, 1);
170 layout->setColumnStretch(1, 0);
171 layout->setColumnStretch(2, 0);
172 layout->setColumnStretch(3, 1);
175 createControls (layout, row);
176 createPreview (layout, row);
185 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::handleOk";
189 *m_modelAxesCheckerBefore,
190 *m_modelAxesCheckerAfter);
198 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::load";
203 if (m_modelAxesCheckerBefore != 0) {
204 delete m_modelAxesCheckerBefore;
206 if (m_modelAxesCheckerAfter != 0) {
207 delete m_modelAxesCheckerAfter;
209 if (m_modelCoords != 0) {
210 delete m_modelCoords;
219 CheckerMode checkerMode = m_modelAxesCheckerAfter->
checkerMode();
220 m_btnNever->setChecked (checkerMode == CHECKER_MODE_NEVER);
221 m_btnNSeconds->setChecked (checkerMode == CHECKER_MODE_N_SECONDS);
222 m_btnForever->setChecked (checkerMode == CHECKER_MODE_FOREVER);
223 int indexSeconds = m_cmbSeconds->findData (QVariant (m_modelAxesCheckerAfter->
checkerSeconds()));
224 ENGAUGE_ASSERT (indexSeconds >= 0);
225 m_cmbSeconds->setCurrentIndex(indexSeconds);
227 int indexLineColor = m_cmbLineColor->findData (QVariant (m_modelAxesCheckerAfter->
lineColor()));
228 ENGAUGE_ASSERT (indexLineColor >= 0);
229 m_cmbLineColor->setCurrentIndex (indexLineColor);
236 void DlgSettingsAxesChecker::slotGroupMode (QAbstractButton*)
238 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotGroupMode";
240 if (m_btnNever->isChecked ()) {
242 }
else if (m_btnNSeconds->isChecked ()) {
252 void DlgSettingsAxesChecker::slotLineColor(
const QString &)
254 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotLineColor";
256 m_modelAxesCheckerAfter->
setLineColor ((ColorPalette) m_cmbLineColor->currentData().toInt());
261 void DlgSettingsAxesChecker::slotSeconds (
const QString &)
263 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotLineColor";
269 void DlgSettingsAxesChecker::updateControls ()
273 m_cmbSeconds->setEnabled (m_btnNSeconds->isChecked ());
276 void DlgSettingsAxesChecker::updatePreview()
278 const int ZERO_RADIUS_SINCE_NO_POINTS = 0;
280 QVector<QPointF> points;
281 points.push_back (QPointF (X_LEFT, Y_TOP));
282 points.push_back (QPointF (X_LEFT, Y_BOTTOM));
283 points.push_back (QPointF (X_RIGHT, Y_BOTTOM));
285 QPolygonF polygon (points);
287 ENGAUGE_ASSERT (m_checker != 0);
289 ZERO_RADIUS_SINCE_NO_POINTS,
290 *m_modelAxesCheckerAfter,
int checkerSeconds() const
Get method for checker lifetime in seconds.
void setCheckerMode(CheckerMode checkerMode)
Set method for checker mode.
void setCheckerSeconds(int seconds)
Set method for checker lifetime in seconds.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
ColorPalette lineColor() const
Get method for line color.
Box shape that is drawn through the three axis points, to temporarily (usually) or permanently (rarel...
void setLineColor(ColorPalette lineColor)
Set method for line color.
virtual void load(CmdMediator &cmdMediator)
Load settings from Document.
CheckerMode checkerMode() const
Get method for checker lifetime mode.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window...
Command for DlgSettingsAxesChecker.
void populateColorComboWithoutTransparent(QComboBox &combo)
Add colors in color palette to combobox, without transparent entry at end.
Model for DlgSettingsCoords and CmdSettingsCoords.
virtual void createOptionalSaveDefault(QHBoxLayout *layout)
Let subclass define an optional Save As Default button.
virtual QWidget * createSubPanel()
Create dialog-specific panel to which base class will add Ok and Cancel buttons.
void finishPanel(QWidget *subPanel)
Add Ok and Cancel buttons to subpanel to get the whole dialog.
virtual void handleOk()
Process slotOk.
Model for DlgSettingsAxesChecker and CmdSettingsAxesChecker.
static int MINIMUM_PREVIEW_HEIGHT
Dialog layout constant that guarantees preview has sufficent room.
void enableOk(bool enable)
Let leaf subclass control the Ok button.
Abstract base class for all Settings dialogs.
DlgSettingsAxesChecker(MainWindow &mainWindow)
Single constructor.
void prepareForDisplay(const QPolygonF &polygon, int pointRadius, const DocumentModelAxesChecker &modelAxesChecker, const DocumentModelCoords &modelCoords)
Create the polygon from current information, including pixel coordinates, just prior to display...
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.