1 #include "EngaugeAssert.h"
10 #include "StatusBar.h"
11 #include "ZoomFactor.h"
12 #include "ZoomLabels.h"
14 const QString LABEL_COORDS_SCREEN (
"Coordinates (pixels):");
15 const QString LABEL_COORDS_GRAPH (
"Coordinates (graph):");
16 const QString LABEL_RESOLUTION_GRAPH (
"Resolution (graph):");
18 const int TEMPORARY_MESSAGE_LIFETIME = 5000;
20 const int MIN_WIDTH_COMBO_UNITS = 160;
21 const int MAX_WIDTH_GROUP_UNITS = 400;
22 const int MAX_SIZE_EDIT_COORDS = 550;
23 const int MAX_HEIGHT_EDIT_COORDS = 24;
26 m_statusBar (statusBar),
27 m_statusBarMode (STATUS_BAR_MODE_ALWAYS),
33 connect (&m_statusBar, SIGNAL (messageChanged (
const QString &)),
this, SLOT (slotStatusBarChanged (
const QString &)));
35 m_statusBar.setMaximumHeight (60);
39 StatusBar::~StatusBar ()
47 void StatusBar::createGroupUnits ()
49 m_cmbUnits =
new QComboBox;
50 m_cmbUnits->setEnabled (
false);
51 m_cmbUnits->addItem (LABEL_COORDS_SCREEN, QVariant (STATUS_BAR_UNITS_COORDS_SCREEN));
52 m_cmbUnits->addItem (LABEL_COORDS_GRAPH, QVariant (STATUS_BAR_UNITS_COORDS_GRAPH));
53 m_cmbUnits->addItem (LABEL_RESOLUTION_GRAPH, QVariant (STATUS_BAR_UNITS_RESOLUTION_GRAPH));
54 m_cmbUnits->setCurrentText (LABEL_COORDS_GRAPH);
55 m_cmbUnits->setMaximumWidth (MIN_WIDTH_COMBO_UNITS);
56 m_cmbUnits->setToolTip (tr (
"Select cursor coordinate values to display."));
57 m_cmbUnits->setWhatsThis (tr(
"Select Cursor Coordinate Values\n\n"
58 "Values at cursor coordinates to display. Coordinates are in screen (pixels) or "
59 "graph units. Resolution (which is the number of graph units per pixel) is "
60 "in graph units. Graph units are only available after axis points have been defined."));
61 connect (m_cmbUnits, SIGNAL (activated(
const QString &)),
this, SLOT (slotComboUnits (
const QString &)));
63 m_editCoords =
new QTextEdit;
64 m_editCoords->setEnabled (
false);
65 m_editCoords->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 m_editCoords->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67 m_editCoords->setMinimumSize (MAX_SIZE_EDIT_COORDS, MAX_HEIGHT_EDIT_COORDS);
68 m_editCoords->setMaximumSize (MAX_SIZE_EDIT_COORDS, MAX_HEIGHT_EDIT_COORDS);
69 m_editCoords->setReadOnly(
true);
70 m_editCoords->setToolTip (tr (
"Cursor coordinate values."));
71 m_editCoords->setWhatsThis (tr (
"Cursor Coordinate Values\n\n"
72 "Values at cursor coordinates. Coordinates are in screen (pixels) or "
73 "graph units. Resolution (which is the number of graph units per pixel) is "
74 "in graph units. Graph units are only available after axis points have been defined."));
76 m_groupUnits =
new QFrame;
77 m_groupUnits->setFrameStyle (QFrame::Box);
78 QPalette *palette =
new QPalette;
79 palette->setColor (QPalette::Foreground, Qt::gray);
80 m_groupUnits->setPalette (*palette);
81 m_groupUnits->setMaximumWidth (MAX_WIDTH_GROUP_UNITS);
83 QHBoxLayout *groupLayout =
new QHBoxLayout;
84 m_groupUnits->setLayout (groupLayout);
85 groupLayout->setContentsMargins (0, 0, 0, 0);
86 groupLayout->addWidget (m_cmbUnits);
87 groupLayout->addWidget (m_editCoords);
88 groupLayout->setMargin (2);
90 m_statusBar.addPermanentWidget (m_groupUnits);
93 void StatusBar::createZoom ()
95 m_cmbZoom =
new QComboBox ();
96 m_cmbZoom->setEnabled (
false);
97 m_cmbZoom->addItem (LABEL_ZOOM_16_TO_1);
98 m_cmbZoom->addItem (LABEL_ZOOM_8_TO_1);
99 m_cmbZoom->addItem (LABEL_ZOOM_4_TO_1);
100 m_cmbZoom->addItem (LABEL_ZOOM_2_TO_1);
101 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_1);
102 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_2);
103 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_4);
104 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_8);
105 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_16);
106 m_cmbZoom->addItem (LABEL_ZOOM_FILL);
107 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_1);
108 m_cmbZoom->setMaximumWidth (80);
109 m_cmbZoom->setToolTip (tr (
"Select zoom."));
110 m_cmbZoom->setWhatsThis (tr(
"Select Zoom\n\n"
111 "Points can be more accurately placed by zooming in."));
113 connect (m_cmbZoom, SIGNAL (currentTextChanged(
const QString &)),
this, SLOT (slotComboZoom (
const QString &)));
115 m_statusBar.addPermanentWidget (m_cmbZoom);
119 const QString &coordsGraph,
120 const QString &resolutionGraph)
127 if (m_cmbUnits->isEnabled ()) {
129 m_coordsScreen = coordsScreen;
130 m_coordsGraph = coordsGraph;
131 m_resolutionGraph = resolutionGraph;
140 if (m_statusBarMode == STATUS_BAR_MODE_ALWAYS) {
149 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::showTemporaryMessage message=" << message.toLatin1 ().data ();
151 if (m_statusBarMode != STATUS_BAR_MODE_NEVER) {
152 if (m_statusBarMode == STATUS_BAR_MODE_TEMPORARY) {
155 m_timer =
new QTimer;
156 connect (m_timer, SIGNAL (timeout ()),
this, SLOT (slotTimeout()));
157 m_timer->setSingleShot(
true);
160 m_statusBar.showMessage (message, TEMPORARY_MESSAGE_LIFETIME);
164 void StatusBar::slotComboUnits (
const QString &text)
166 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::slotComboUnits text=" << text.toLatin1 ().data ();
171 void StatusBar::slotComboZoom (
const QString &text)
173 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::slotComboZoom text=" << text.toLatin1 ().data ();
175 if (text == LABEL_ZOOM_16_TO_1) {
177 }
else if (text == LABEL_ZOOM_8_TO_1) {
179 }
else if (text == LABEL_ZOOM_4_TO_1) {
181 }
else if (text == LABEL_ZOOM_2_TO_1) {
183 }
else if (text == LABEL_ZOOM_1_TO_1) {
185 }
else if (text == LABEL_ZOOM_1_TO_2) {
187 }
else if (text == LABEL_ZOOM_1_TO_4) {
189 }
else if (text == LABEL_ZOOM_1_TO_8) {
191 }
else if (text == LABEL_ZOOM_1_TO_16) {
193 }
else if (text == LABEL_ZOOM_FILL) {
196 ENGAUGE_ASSERT (
false);
200 void StatusBar::slotStatusBarChanged(
const QString &message)
202 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::slotStatusBarChanged message=" << message.toLatin1 ().data ();
204 if (m_statusBarMode == STATUS_BAR_MODE_TEMPORARY) {
209 void StatusBar::slotTimeout()
211 LOG4CPP_INFO_S ((*mainCat)) <<
"StatusBar::slotTimeout";
221 LOG4CPP_INFO_S ((*mainCat)) <<
"StatusBar::slotZoom zoom=" << zoom;
224 switch ((ZoomFactor) zoom) {
226 m_cmbZoom->setCurrentText (LABEL_ZOOM_16_TO_1);
229 m_cmbZoom->setCurrentText (LABEL_ZOOM_8_TO_1);
232 m_cmbZoom->setCurrentText (LABEL_ZOOM_4_TO_1);
235 m_cmbZoom->setCurrentText (LABEL_ZOOM_2_TO_1);
238 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_1);
241 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_2);
244 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_4);
247 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_8);
250 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_16);
253 m_cmbZoom->setCurrentText (LABEL_ZOOM_FILL);
257 void StatusBar::updateCoordsText()
259 if (m_cmbUnits->currentText() == LABEL_COORDS_SCREEN) {
260 m_editCoords->setText (m_coordsScreen);
261 }
else if (m_cmbUnits->currentText() == LABEL_COORDS_GRAPH) {
262 m_editCoords->setText (m_coordsGraph);
264 m_editCoords->setText (m_resolutionGraph);
270 if (!m_cmbUnits->isEnabled ()) {
273 m_cmbZoom->setEnabled (
true);
274 m_cmbUnits->setEnabled (
true);
275 m_editCoords->setEnabled (
true);
void setStatusBarMode(StatusBarMode statusBarMode)
Set the status bar visibility mode.
StatusBar(QStatusBar &statusBar)
Single constructor that accepts the previously-constructed standard QStatusBar.
void setCoordinates(const QString &coordsScreen, const QString &coordsGraph, const QString &resolutionGraph)
Populate the coordinates fields. Unavailable values are empty. Html-encoding to highlight with colors...
void slotZoom(int)
Receive zoom selection from MainWindow.
void wakeUp()
Enable all widgets in the status bar. This is called just after a Document becomes active...
void signalZoom(int)
Send zoom factor, that was just selected in the status bar, to MainWindow.
StatusBarMode statusBarMode() const
Current mode for status bar visibility. This is tracked locally so this class knows when to hide/show...
void showTemporaryMessage(const QString &message)
Show temporary message in status bar. After a short interval the message will disappear.