7 #include "EngaugeAssert.h"
10 #include <QHBoxLayout>
16 #include "StatusBar.h"
17 #include "ZoomFactor.h"
18 #include "ZoomLabels.h"
20 const QString LABEL_COORDS_SCREEN (
"Coordinates (pixels):");
21 const QString LABEL_COORDS_GRAPH (
"Coordinates (graph):");
22 const QString LABEL_RESOLUTION_GRAPH (
"Resolution (graph):");
24 const int TEMPORARY_MESSAGE_LIFETIME = 5000;
26 const int MIN_WIDTH_COMBO_UNITS = 160;
27 const int MAX_WIDTH_GROUP_UNITS = 400;
28 const int MAX_SIZE_EDIT_COORDS = 550;
29 const int MAX_HEIGHT_EDIT_COORDS = 24;
32 m_statusBar (statusBar),
33 m_statusBarMode (STATUS_BAR_MODE_ALWAYS),
39 connect (&m_statusBar, SIGNAL (messageChanged (
const QString &)),
this, SLOT (slotStatusBarChanged (
const QString &)));
41 m_statusBar.setMaximumHeight (60);
45 StatusBar::~StatusBar ()
53 void StatusBar::createGroupUnits ()
55 m_cmbUnits =
new QComboBox;
56 m_cmbUnits->setEnabled (
false);
57 m_cmbUnits->addItem (LABEL_COORDS_SCREEN, QVariant (STATUS_BAR_UNITS_COORDS_SCREEN));
58 m_cmbUnits->addItem (LABEL_COORDS_GRAPH, QVariant (STATUS_BAR_UNITS_COORDS_GRAPH));
59 m_cmbUnits->addItem (LABEL_RESOLUTION_GRAPH, QVariant (STATUS_BAR_UNITS_RESOLUTION_GRAPH));
60 m_cmbUnits->setCurrentText (LABEL_COORDS_GRAPH);
61 m_cmbUnits->setMaximumWidth (MIN_WIDTH_COMBO_UNITS);
62 m_cmbUnits->setToolTip (tr (
"Select cursor coordinate values to display."));
63 m_cmbUnits->setWhatsThis (tr(
"Select Cursor Coordinate Values\n\n"
64 "Values at cursor coordinates to display. Coordinates are in screen (pixels) or "
65 "graph units. Resolution (which is the number of graph units per pixel) is "
66 "in graph units. Graph units are only available after axis points have been defined."));
67 connect (m_cmbUnits, SIGNAL (activated(
const QString &)),
this, SLOT (slotComboUnits (
const QString &)));
69 m_editCoords =
new QTextEdit;
70 m_editCoords->setEnabled (
false);
71 m_editCoords->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
72 m_editCoords->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
73 m_editCoords->setMinimumSize (MAX_SIZE_EDIT_COORDS, MAX_HEIGHT_EDIT_COORDS);
74 m_editCoords->setMaximumSize (MAX_SIZE_EDIT_COORDS, MAX_HEIGHT_EDIT_COORDS);
75 m_editCoords->setReadOnly(
true);
76 m_editCoords->setToolTip (tr (
"Cursor coordinate values."));
77 m_editCoords->setWhatsThis (tr (
"Cursor Coordinate Values\n\n"
78 "Values at cursor coordinates. Coordinates are in screen (pixels) or "
79 "graph units. Resolution (which is the number of graph units per pixel) is "
80 "in graph units. Graph units are only available after axis points have been defined."));
82 m_groupUnits =
new QFrame;
83 m_groupUnits->setFrameStyle (QFrame::Box);
84 QPalette *palette =
new QPalette;
85 palette->setColor (QPalette::Foreground, Qt::gray);
86 m_groupUnits->setPalette (*palette);
87 m_groupUnits->setMaximumWidth (MAX_WIDTH_GROUP_UNITS);
89 QHBoxLayout *groupLayout =
new QHBoxLayout;
90 m_groupUnits->setLayout (groupLayout);
91 groupLayout->setContentsMargins (0, 0, 0, 0);
92 groupLayout->addWidget (m_cmbUnits);
93 groupLayout->addWidget (m_editCoords);
94 groupLayout->setMargin (2);
96 m_statusBar.addPermanentWidget (m_groupUnits);
99 void StatusBar::createZoom ()
101 m_cmbZoom =
new QComboBox ();
102 m_cmbZoom->setEnabled (
false);
103 m_cmbZoom->addItem (LABEL_ZOOM_16_TO_1);
104 m_cmbZoom->addItem (LABEL_ZOOM_8_TO_1);
105 m_cmbZoom->addItem (LABEL_ZOOM_4_TO_1);
106 m_cmbZoom->addItem (LABEL_ZOOM_2_TO_1);
107 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_1);
108 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_2);
109 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_4);
110 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_8);
111 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_16);
112 m_cmbZoom->addItem (LABEL_ZOOM_FILL);
113 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_1);
114 m_cmbZoom->setMaximumWidth (80);
115 m_cmbZoom->setToolTip (tr (
"Select zoom."));
116 m_cmbZoom->setWhatsThis (tr(
"Select Zoom\n\n"
117 "Points can be more accurately placed by zooming in."));
119 connect (m_cmbZoom, SIGNAL (currentTextChanged(
const QString &)),
this, SLOT (slotComboZoom (
const QString &)));
121 m_statusBar.addPermanentWidget (m_cmbZoom);
125 const QString &coordsGraph,
126 const QString &resolutionGraph)
133 if (m_cmbUnits->isEnabled ()) {
135 m_coordsScreen = coordsScreen;
136 m_coordsGraph = coordsGraph;
137 m_resolutionGraph = resolutionGraph;
146 if (m_statusBarMode == STATUS_BAR_MODE_ALWAYS) {
155 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::showTemporaryMessage message=" << message.toLatin1 ().data ();
157 if (m_statusBarMode != STATUS_BAR_MODE_NEVER) {
158 if (m_statusBarMode == STATUS_BAR_MODE_TEMPORARY) {
161 m_timer =
new QTimer;
162 connect (m_timer, SIGNAL (timeout ()),
this, SLOT (slotTimeout()));
163 m_timer->setSingleShot(
true);
166 m_statusBar.showMessage (message, TEMPORARY_MESSAGE_LIFETIME);
170 void StatusBar::slotComboUnits (
const QString &text)
172 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::slotComboUnits text=" << text.toLatin1 ().data ();
177 void StatusBar::slotComboZoom (
const QString &text)
179 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::slotComboZoom text=" << text.toLatin1 ().data ();
181 if (text == LABEL_ZOOM_16_TO_1) {
183 }
else if (text == LABEL_ZOOM_8_TO_1) {
185 }
else if (text == LABEL_ZOOM_4_TO_1) {
187 }
else if (text == LABEL_ZOOM_2_TO_1) {
189 }
else if (text == LABEL_ZOOM_1_TO_1) {
191 }
else if (text == LABEL_ZOOM_1_TO_2) {
193 }
else if (text == LABEL_ZOOM_1_TO_4) {
195 }
else if (text == LABEL_ZOOM_1_TO_8) {
197 }
else if (text == LABEL_ZOOM_1_TO_16) {
199 }
else if (text == LABEL_ZOOM_FILL) {
202 ENGAUGE_ASSERT (
false);
206 void StatusBar::slotStatusBarChanged(
const QString &message)
208 LOG4CPP_DEBUG_S ((*mainCat)) <<
"StatusBar::slotStatusBarChanged message=" << message.toLatin1 ().data ();
210 if (m_statusBarMode == STATUS_BAR_MODE_TEMPORARY) {
215 void StatusBar::slotTimeout()
217 LOG4CPP_INFO_S ((*mainCat)) <<
"StatusBar::slotTimeout";
227 LOG4CPP_INFO_S ((*mainCat)) <<
"StatusBar::slotZoom zoom=" << zoom;
230 switch ((ZoomFactor) zoom) {
232 m_cmbZoom->setCurrentText (LABEL_ZOOM_16_TO_1);
235 m_cmbZoom->setCurrentText (LABEL_ZOOM_8_TO_1);
238 m_cmbZoom->setCurrentText (LABEL_ZOOM_4_TO_1);
241 m_cmbZoom->setCurrentText (LABEL_ZOOM_2_TO_1);
244 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_1);
247 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_2);
250 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_4);
253 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_8);
256 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_16);
259 m_cmbZoom->setCurrentText (LABEL_ZOOM_FILL);
263 void StatusBar::updateCoordsText()
265 if (m_cmbUnits->currentText() == LABEL_COORDS_SCREEN) {
266 m_editCoords->setText (m_coordsScreen);
267 }
else if (m_cmbUnits->currentText() == LABEL_COORDS_GRAPH) {
268 m_editCoords->setText (m_coordsGraph);
270 m_editCoords->setText (m_resolutionGraph);
276 if (!m_cmbUnits->isEnabled ()) {
279 m_cmbZoom->setEnabled (
true);
280 m_cmbUnits->setEnabled (
true);
281 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.