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> 19 #include <QGridLayout> 24 #include <QRadioButton> 25 #include "ViewPreview.h" 27 const int AXIS_WIDTH = 4;
28 const int MINIMUM_HEIGHT = 500;
29 const int RECT_WIDTH = 640;
30 const int RECT_HEIGHT = 480;
31 const int X_LEFT = RECT_WIDTH / 8;
32 const int X_RIGHT = RECT_WIDTH * 7 / 8;
33 const int Y_TOP = RECT_HEIGHT / 8;
34 const int Y_BOTTOM = RECT_HEIGHT * 7 / 8;
35 const int TICKS_PER_AXIS = 6;
36 const int TICK_MARK_LENGTH = 8;
40 "DlgSettingsAxesChecker",
43 m_modelAxesCheckerBefore (0),
44 m_modelAxesCheckerAfter (0),
47 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::DlgSettingsAxesChecker";
53 DlgSettingsAxesChecker::~DlgSettingsAxesChecker()
55 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::~DlgSettingsAxesChecker";
58 void DlgSettingsAxesChecker::createControls (QGridLayout *layout,
61 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createControls";
63 QGroupBox *groupBox =
new QGroupBox (tr (
"Axes Checker Lifetime"));
64 layout->addWidget (groupBox, row++, 1, 1, 2);
66 QGridLayout *layoutLifetime =
new QGridLayout;
67 groupBox->setLayout (layoutLifetime);
70 m_btnNever =
new QRadioButton (tr (
"Do not show"), groupBox);
71 m_btnNever->setWhatsThis (tr (
"Never show axes checker."));
72 layoutLifetime->addWidget (m_btnNever, rowLifetime++, 0, 1, 2);
74 m_btnNSeconds =
new QRadioButton (tr (
"Show for a number of seconds"), groupBox);
75 m_btnNSeconds->setWhatsThis (tr (
"Show axes checker for a number of seconds after changing axes points."));
76 layoutLifetime->addWidget (m_btnNSeconds, rowLifetime, 0, 1, 1);
78 m_cmbSeconds =
new QComboBox;
79 for (
int seconds = 1; seconds <= 10; seconds++) {
80 m_cmbSeconds->addItem (QString::number (seconds), QVariant (seconds));
82 layoutLifetime->addWidget (m_cmbSeconds, rowLifetime++, 1);
83 connect (m_cmbSeconds, SIGNAL (activated (
const QString &)),
this, SLOT (slotSeconds (
const QString &)));
85 m_btnForever =
new QRadioButton (tr (
"Show always"), groupBox);
86 m_btnForever->setWhatsThis (tr (
"Always show axes checker."));
87 layoutLifetime->addWidget (m_btnForever, rowLifetime++, 0, 1, 2);
89 m_groupMode =
new QButtonGroup;
90 m_groupMode->addButton (m_btnNever);
91 m_groupMode->addButton (m_btnNSeconds);
92 m_groupMode->addButton (m_btnForever);
93 connect (m_groupMode, SIGNAL (buttonReleased (QAbstractButton*)),
this, SLOT (slotGroupMode (QAbstractButton*)));
95 QLabel *labelLineColor =
new QLabel (tr (
"Line color:"));
96 layout->addWidget (labelLineColor, row, 1);
98 m_cmbLineColor =
new QComboBox;
99 m_cmbLineColor->setWhatsThis (tr (
"Select a color for the highlight lines drawn at each axis point"));
101 connect (m_cmbLineColor, SIGNAL (activated (
const QString &)),
this, SLOT (slotLineColor (
const QString &)));
102 layout->addWidget (m_cmbLineColor, row++, 2);
109 void DlgSettingsAxesChecker::createPoints ()
111 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createPoints";
113 QBrush AXES_BRUSH (Qt::gray);
115 m_checker =
new Checker (*m_scenePreview);
119 QGraphicsRectItem *itemRect =
new QGraphicsRectItem (0,
123 itemRect->setPen (Qt::NoPen);
124 m_scenePreview->addItem (itemRect);
127 QGraphicsRectItem *frameBox =
new QGraphicsRectItem (X_LEFT,
131 frameBox->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
132 frameBox->setZValue (-1);
133 m_scenePreview->addItem (frameBox);
134 for (
int x = X_LEFT; x < X_RIGHT; x += (X_RIGHT - X_LEFT) / TICKS_PER_AXIS) {
135 QGraphicsLineItem *tick =
new QGraphicsLineItem (x, Y_BOTTOM, x, Y_BOTTOM + TICK_MARK_LENGTH);
136 tick->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
137 tick->setZValue (-1);
138 m_scenePreview->addItem (tick);
140 for (
int y = Y_TOP; y < Y_BOTTOM; y += (Y_BOTTOM - Y_TOP) / TICKS_PER_AXIS) {
141 QGraphicsLineItem *tick =
new QGraphicsLineItem (X_LEFT, y, X_LEFT + TICK_MARK_LENGTH, y);
142 tick->setPen (QPen (AXES_BRUSH, AXIS_WIDTH));
143 tick->setZValue (-1);
144 m_scenePreview->addItem (tick);
148 void DlgSettingsAxesChecker::createPreview (QGridLayout *layout,
151 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createPreview";
153 QLabel *labelPreview =
new QLabel (tr (
"Preview"));
154 layout->addWidget (labelPreview, row++, 0, 1, 4);
156 m_scenePreview =
new QGraphicsScene (
this);
158 ViewPreview::VIEW_ASPECT_RATIO_VARIABLE,
160 m_viewPreview->setWhatsThis (tr (
"Preview window that shows how current settings affect the displayed axes checker"));
161 m_viewPreview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
162 m_viewPreview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
165 layout->addWidget (m_viewPreview, row++, 0, 1, 4);
170 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::createSubPanel";
172 QWidget *subPanel =
new QWidget ();
173 QGridLayout *layout =
new QGridLayout (subPanel);
174 subPanel->setLayout (layout);
176 layout->setColumnStretch(0, 1);
177 layout->setColumnStretch(1, 0);
178 layout->setColumnStretch(2, 0);
179 layout->setColumnStretch(3, 1);
182 createControls (layout, row);
183 createPreview (layout, row);
192 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::handleOk";
196 *m_modelAxesCheckerBefore,
197 *m_modelAxesCheckerAfter);
205 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::load";
210 if (m_modelAxesCheckerBefore != 0) {
211 delete m_modelAxesCheckerBefore;
213 if (m_modelAxesCheckerAfter != 0) {
214 delete m_modelAxesCheckerAfter;
216 if (m_modelCoords != 0) {
217 delete m_modelCoords;
226 CheckerMode checkerMode = m_modelAxesCheckerAfter->
checkerMode();
227 m_btnNever->setChecked (checkerMode == CHECKER_MODE_NEVER);
228 m_btnNSeconds->setChecked (checkerMode == CHECKER_MODE_N_SECONDS);
229 m_btnForever->setChecked (checkerMode == CHECKER_MODE_FOREVER);
230 int indexSeconds = m_cmbSeconds->findData (QVariant (m_modelAxesCheckerAfter->
checkerSeconds()));
231 ENGAUGE_ASSERT (indexSeconds >= 0);
232 m_cmbSeconds->setCurrentIndex(indexSeconds);
234 int indexLineColor = m_cmbLineColor->findData (QVariant (m_modelAxesCheckerAfter->
lineColor()));
235 ENGAUGE_ASSERT (indexLineColor >= 0);
236 m_cmbLineColor->setCurrentIndex (indexLineColor);
246 setMinimumHeight (MINIMUM_HEIGHT);
250 void DlgSettingsAxesChecker::slotGroupMode (QAbstractButton*)
252 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotGroupMode";
254 if (m_btnNever->isChecked ()) {
256 }
else if (m_btnNSeconds->isChecked ()) {
266 void DlgSettingsAxesChecker::slotLineColor(
const QString &)
268 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotLineColor";
270 m_modelAxesCheckerAfter->
setLineColor ((ColorPalette) m_cmbLineColor->currentData().toInt());
275 void DlgSettingsAxesChecker::slotSeconds (
const QString &)
277 LOG4CPP_INFO_S ((*mainCat)) <<
"DlgSettingsAxesChecker::slotLineColor";
283 void DlgSettingsAxesChecker::updateControls ()
287 m_cmbSeconds->setEnabled (m_btnNSeconds->isChecked ());
290 void DlgSettingsAxesChecker::updatePreview()
292 const int ZERO_RADIUS_SINCE_NO_POINTS = 0;
294 QVector<QPointF> points;
295 points.push_back (QPointF (X_LEFT, Y_TOP));
296 points.push_back (QPointF (X_LEFT, Y_BOTTOM));
297 points.push_back (QPointF (X_RIGHT, Y_BOTTOM));
299 QPolygonF polygon (points);
301 ENGAUGE_ASSERT (m_checker != 0);
303 ZERO_RADIUS_SINCE_NO_POINTS,
304 *m_modelAxesCheckerAfter,
void setCheckerMode(CheckerMode checkerMode)
Set method for checker mode.
void setCheckerSeconds(int seconds)
Set method for checker lifetime in seconds.
int checkerSeconds() const
Get method for checker lifetime in seconds.
void setCmdMediator(CmdMediator &cmdMediator)
Store CmdMediator for easy access by the leaf class.
Box shape that is drawn through the three axis points, to temporarily (usually) or permanently (rarel...
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 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.
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...
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.
ColorPalette lineColor() const
Get method for line color.
virtual void setSmallDialogs(bool smallDialogs)
If false then dialogs have a minimum size so all controls are visible.
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.
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.
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.