00001
00002
00003
00004
00005
00006
00007 #include "EngaugeAssert.h"
00008 #include "Logger.h"
00009 #include <QFrame>
00010 #include <QHBoxLayout>
00011 #include <QLineEdit>
00012 #include <QStatusBar>
00013 #include <QTextEdit>
00014 #include <QTimer>
00015 #include <QWhatsThis>
00016 #include "StatusBar.h"
00017 #include "ZoomFactor.h"
00018 #include "ZoomLabels.h"
00019
00020 const QString LABEL_COORDS_SCREEN ("Coordinates (pixels):");
00021 const QString LABEL_COORDS_GRAPH ("Coordinates (graph):");
00022 const QString LABEL_RESOLUTION_GRAPH ("Resolution (graph):");
00023
00024 const int TEMPORARY_MESSAGE_LIFETIME = 5000;
00025
00026 const int MIN_WIDTH_COMBO_UNITS = 160;
00027 const int MAX_WIDTH_GROUP_UNITS = 400;
00028 const int MAX_SIZE_EDIT_COORDS = 550;
00029 const int MAX_HEIGHT_EDIT_COORDS = 24;
00030
00031 StatusBar::StatusBar(QStatusBar &statusBar) :
00032 m_statusBar (statusBar),
00033 m_statusBarMode (STATUS_BAR_MODE_ALWAYS),
00034 m_timer (0)
00035 {
00036 createZoom ();
00037 createGroupUnits ();
00038
00039 connect (&m_statusBar, SIGNAL (messageChanged (const QString &)), this, SLOT (slotStatusBarChanged (const QString &)));
00040
00041 m_statusBar.setMaximumHeight (60);
00042 m_statusBar.hide();
00043 }
00044
00045 StatusBar::~StatusBar ()
00046 {
00047 if (m_timer != 0) {
00048 delete m_timer;
00049 m_timer = 0;
00050 }
00051 }
00052
00053 void StatusBar::createGroupUnits ()
00054 {
00055 m_cmbUnits = new QComboBox;
00056 m_cmbUnits->setEnabled (false);
00057 m_cmbUnits->addItem (LABEL_COORDS_SCREEN, QVariant (STATUS_BAR_UNITS_COORDS_SCREEN));
00058 m_cmbUnits->addItem (LABEL_COORDS_GRAPH, QVariant (STATUS_BAR_UNITS_COORDS_GRAPH));
00059 m_cmbUnits->addItem (LABEL_RESOLUTION_GRAPH, QVariant (STATUS_BAR_UNITS_RESOLUTION_GRAPH));
00060 m_cmbUnits->setCurrentText (LABEL_COORDS_GRAPH);
00061 m_cmbUnits->setMaximumWidth (MIN_WIDTH_COMBO_UNITS);
00062 m_cmbUnits->setToolTip (tr ("Select cursor coordinate values to display."));
00063 m_cmbUnits->setWhatsThis (tr("Select Cursor Coordinate Values\n\n"
00064 "Values at cursor coordinates to display. Coordinates are in screen (pixels) or "
00065 "graph units. Resolution (which is the number of graph units per pixel) is "
00066 "in graph units. Graph units are only available after axis points have been defined."));
00067 connect (m_cmbUnits, SIGNAL (activated(const QString &)), this, SLOT (slotComboUnits (const QString &)));
00068
00069 m_editCoords = new QTextEdit;
00070 m_editCoords->setEnabled (false);
00071 m_editCoords->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00072 m_editCoords->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00073 m_editCoords->setMinimumSize (MAX_SIZE_EDIT_COORDS, MAX_HEIGHT_EDIT_COORDS);
00074 m_editCoords->setMaximumSize (MAX_SIZE_EDIT_COORDS, MAX_HEIGHT_EDIT_COORDS);
00075 m_editCoords->setReadOnly(true);
00076 m_editCoords->setToolTip (tr ("Cursor coordinate values."));
00077 m_editCoords->setWhatsThis (tr ("Cursor Coordinate Values\n\n"
00078 "Values at cursor coordinates. Coordinates are in screen (pixels) or "
00079 "graph units. Resolution (which is the number of graph units per pixel) is "
00080 "in graph units. Graph units are only available after axis points have been defined."));
00081
00082 m_groupUnits = new QFrame;
00083 m_groupUnits->setFrameStyle (QFrame::Box);
00084 QPalette *palette = new QPalette;
00085 palette->setColor (QPalette::Foreground, Qt::gray);
00086 m_groupUnits->setPalette (*palette);
00087 m_groupUnits->setMaximumWidth (MAX_WIDTH_GROUP_UNITS);
00088
00089 QHBoxLayout *groupLayout = new QHBoxLayout;
00090 m_groupUnits->setLayout (groupLayout);
00091 groupLayout->setContentsMargins (0, 0, 0, 0);
00092 groupLayout->addWidget (m_cmbUnits);
00093 groupLayout->addWidget (m_editCoords);
00094 groupLayout->setMargin (2);
00095
00096 m_statusBar.addPermanentWidget (m_groupUnits);
00097 }
00098
00099 void StatusBar::createZoom ()
00100 {
00101 m_cmbZoom = new QComboBox ();
00102 m_cmbZoom->setEnabled (false);
00103 m_cmbZoom->addItem (LABEL_ZOOM_16_TO_1);
00104 m_cmbZoom->addItem (LABEL_ZOOM_8_TO_1);
00105 m_cmbZoom->addItem (LABEL_ZOOM_4_TO_1);
00106 m_cmbZoom->addItem (LABEL_ZOOM_2_TO_1);
00107 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_1);
00108 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_2);
00109 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_4);
00110 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_8);
00111 m_cmbZoom->addItem (LABEL_ZOOM_1_TO_16);
00112 m_cmbZoom->addItem (LABEL_ZOOM_FILL);
00113 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_1);
00114 m_cmbZoom->setMaximumWidth (80);
00115 m_cmbZoom->setToolTip (tr ("Select zoom."));
00116 m_cmbZoom->setWhatsThis (tr("Select Zoom\n\n"
00117 "Points can be more accurately placed by zooming in."));
00118
00119 connect (m_cmbZoom, SIGNAL (currentTextChanged(const QString &)), this, SLOT (slotComboZoom (const QString &)));
00120
00121 m_statusBar.addPermanentWidget (m_cmbZoom);
00122 }
00123
00124 void StatusBar::setCoordinates (const QString &coordsScreen,
00125 const QString &coordsGraph,
00126 const QString &resolutionGraph)
00127 {
00128
00129
00130
00131
00132
00133 if (m_cmbUnits->isEnabled ()) {
00134
00135 m_coordsScreen = coordsScreen;
00136 m_coordsGraph = coordsGraph;
00137 m_resolutionGraph = resolutionGraph;
00138
00139 updateCoordsText();
00140 }
00141 }
00142
00143 void StatusBar::setStatusBarMode(StatusBarMode statusBarMode)
00144 {
00145 m_statusBarMode = statusBarMode;
00146 if (m_statusBarMode == STATUS_BAR_MODE_ALWAYS) {
00147 m_statusBar.show();
00148 } else {
00149 m_statusBar.hide();
00150 }
00151 }
00152
00153 void StatusBar::showTemporaryMessage(const QString &message)
00154 {
00155 LOG4CPP_DEBUG_S ((*mainCat)) << "StatusBar::showTemporaryMessage message=" << message.toLatin1 ().data ();
00156
00157 if (m_statusBarMode != STATUS_BAR_MODE_NEVER) {
00158 if (m_statusBarMode == STATUS_BAR_MODE_TEMPORARY) {
00159
00160
00161 m_timer = new QTimer;
00162 connect (m_timer, SIGNAL (timeout ()), this, SLOT (slotTimeout()));
00163 m_timer->setSingleShot(true);
00164 m_timer->start (0);
00165 }
00166 m_statusBar.showMessage (message, TEMPORARY_MESSAGE_LIFETIME);
00167 }
00168 }
00169
00170 void StatusBar::slotComboUnits (const QString &text)
00171 {
00172 LOG4CPP_DEBUG_S ((*mainCat)) << "StatusBar::slotComboUnits text=" << text.toLatin1 ().data ();
00173
00174 updateCoordsText();
00175 }
00176
00177 void StatusBar::slotComboZoom (const QString &text)
00178 {
00179 LOG4CPP_DEBUG_S ((*mainCat)) << "StatusBar::slotComboZoom text=" << text.toLatin1 ().data ();
00180
00181 if (text == LABEL_ZOOM_16_TO_1) {
00182 emit signalZoom (ZOOM_16_TO_1);
00183 } else if (text == LABEL_ZOOM_8_TO_1) {
00184 emit signalZoom (ZOOM_8_TO_1);
00185 } else if (text == LABEL_ZOOM_4_TO_1) {
00186 emit signalZoom (ZOOM_4_TO_1);
00187 } else if (text == LABEL_ZOOM_2_TO_1) {
00188 emit signalZoom (ZOOM_2_TO_1);
00189 } else if (text == LABEL_ZOOM_1_TO_1) {
00190 emit signalZoom (ZOOM_1_TO_1);
00191 } else if (text == LABEL_ZOOM_1_TO_2) {
00192 emit signalZoom (ZOOM_1_TO_2);
00193 } else if (text == LABEL_ZOOM_1_TO_4) {
00194 emit signalZoom (ZOOM_1_TO_4);
00195 } else if (text == LABEL_ZOOM_1_TO_8) {
00196 emit signalZoom (ZOOM_1_TO_8);
00197 } else if (text == LABEL_ZOOM_1_TO_16) {
00198 emit signalZoom (ZOOM_1_TO_16);
00199 } else if (text == LABEL_ZOOM_FILL) {
00200 emit signalZoom (ZOOM_FILL);
00201 } else {
00202 ENGAUGE_ASSERT (false);
00203 }
00204 }
00205
00206 void StatusBar::slotStatusBarChanged(const QString &message)
00207 {
00208 LOG4CPP_DEBUG_S ((*mainCat)) << "StatusBar::slotStatusBarChanged message=" << message.toLatin1 ().data ();
00209
00210 if (m_statusBarMode == STATUS_BAR_MODE_TEMPORARY) {
00211 m_statusBar.hide();
00212 }
00213 }
00214
00215 void StatusBar::slotTimeout()
00216 {
00217 LOG4CPP_INFO_S ((*mainCat)) << "StatusBar::slotTimeout";
00218
00219 delete m_timer;
00220 m_timer = 0;
00221
00222 m_statusBar.show();
00223 }
00224
00225 void StatusBar::slotZoom(int zoom)
00226 {
00227 LOG4CPP_INFO_S ((*mainCat)) << "StatusBar::slotZoom zoom=" << zoom;
00228
00229
00230 switch ((ZoomFactor) zoom) {
00231 case ZOOM_16_TO_1:
00232 m_cmbZoom->setCurrentText (LABEL_ZOOM_16_TO_1);
00233 break;
00234 case ZOOM_8_TO_1:
00235 m_cmbZoom->setCurrentText (LABEL_ZOOM_8_TO_1);
00236 break;
00237 case ZOOM_4_TO_1:
00238 m_cmbZoom->setCurrentText (LABEL_ZOOM_4_TO_1);
00239 break;
00240 case ZOOM_2_TO_1:
00241 m_cmbZoom->setCurrentText (LABEL_ZOOM_2_TO_1);
00242 break;
00243 case ZOOM_1_TO_1:
00244 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_1);
00245 break;
00246 case ZOOM_1_TO_2:
00247 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_2);
00248 break;
00249 case ZOOM_1_TO_4:
00250 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_4);
00251 break;
00252 case ZOOM_1_TO_8:
00253 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_8);
00254 break;
00255 case ZOOM_1_TO_16:
00256 m_cmbZoom->setCurrentText (LABEL_ZOOM_1_TO_16);
00257 break;
00258 case ZOOM_FILL:
00259 m_cmbZoom->setCurrentText (LABEL_ZOOM_FILL);
00260 }
00261 }
00262
00263 void StatusBar::updateCoordsText()
00264 {
00265 if (m_cmbUnits->currentText() == LABEL_COORDS_SCREEN) {
00266 m_editCoords->setText (m_coordsScreen);
00267 } else if (m_cmbUnits->currentText() == LABEL_COORDS_GRAPH) {
00268 m_editCoords->setText (m_coordsGraph);
00269 } else {
00270 m_editCoords->setText (m_resolutionGraph);
00271 }
00272 }
00273
00274 void StatusBar::wakeUp ()
00275 {
00276 if (!m_cmbUnits->isEnabled ()) {
00277
00278
00279 m_cmbZoom->setEnabled (true);
00280 m_cmbUnits->setEnabled (true);
00281 m_editCoords->setEnabled (true);
00282 }
00283 }