diff --git a/gpxsee.pro b/gpxsee.pro index a0ba0616..39df89b9 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -76,7 +76,8 @@ HEADERS += src/config.h \ src/optionsdialog.h \ src/colorbox.h \ src/stylecombobox.h \ - src/opengl.h + src/opengl.h \ + src/fliplabel.h SOURCES += src/main.cpp \ src/gui.cpp \ src/poi.cpp \ @@ -130,7 +131,8 @@ SOURCES += src/main.cpp \ src/nmeaparser.cpp \ src/optionsdialog.cpp \ src/colorbox.cpp \ - src/stylecombobox.cpp + src/stylecombobox.cpp \ + src/fliplabel.cpp RESOURCES += gpxsee.qrc TRANSLATIONS = lang/gpxsee_cs.ts \ lang/gpxsee_sv.ts diff --git a/src/fliplabel.cpp b/src/fliplabel.cpp new file mode 100644 index 00000000..0e7471d9 --- /dev/null +++ b/src/fliplabel.cpp @@ -0,0 +1,28 @@ +#include "fliplabel.h" + + +void FlipLabel::addItem(const QString &key, const QString &value) +{ + _labels.insert(key, value); + + if (_labels.size() == 1) + _it = _labels.constBegin(); + + QLabel::setText(_it.value()); + QLabel::setToolTip(_it.key()); +} + +void FlipLabel::mousePressEvent(QMouseEvent *event) +{ + Q_UNUSED(event); + + if (!_labels.count()) + return; + + _it++; + if (_it == _labels.constEnd()) + _it = _labels.constBegin(); + + QLabel::setText(_it.value()); + QLabel::setToolTip(_it.key()); +} diff --git a/src/fliplabel.h b/src/fliplabel.h new file mode 100644 index 00000000..35ba2a47 --- /dev/null +++ b/src/fliplabel.h @@ -0,0 +1,22 @@ +#ifndef FLIPLABEL_H +#define FLIPLABEL_H + +#include +#include + +class FlipLabel : public QLabel +{ +public: + FlipLabel(QWidget *parent = 0) : QLabel(parent) {} + + void addItem(const QString &key, const QString &value); + +protected: + void mousePressEvent(QMouseEvent *event); + +private: + QMap _labels; + QMap::const_iterator _it; +}; + +#endif // FLIPLABEL_H diff --git a/src/gui.cpp b/src/gui.cpp index 4a7b1cb7..bf7f8c77 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -40,6 +40,7 @@ #include "cpuarch.h" #include "graphtab.h" #include "format.h" +#include "fliplabel.h" #include "gui.h" @@ -530,7 +531,7 @@ void GUI::createStatusBar() { _fileNameLabel = new QLabel(); _distanceLabel = new QLabel(); - _timeLabel = new QLabel(); + _timeLabel = new FlipLabel(); _distanceLabel->setAlignment(Qt::AlignHCenter); _timeLabel->setAlignment(Qt::AlignHCenter); @@ -1072,15 +1073,12 @@ void GUI::updateStatusBarInfo() else _distanceLabel->clear(); - if (time() > 0) - _timeLabel->setText(Format::timeSpan(time())); - else + if (time() > 0) { + _timeLabel->addItem(tr("Total time"), Format::timeSpan(time())); + _timeLabel->addItem(tr("Moving time"), Format::timeSpan(movingTime()) + + "M"); + } else _timeLabel->clear(); - - if (movingTime() > 0) - _timeLabel->setToolTip(Format::timeSpan(movingTime())); - else - _timeLabel->setToolTip(QString()); } void GUI::updateWindowTitle() diff --git a/src/gui.h b/src/gui.h index 74a2ad25..81fa1a78 100644 --- a/src/gui.h +++ b/src/gui.h @@ -18,6 +18,7 @@ class QTabWidget; class QActionGroup; class QAction; class QLabel; +class FlipLabel; class QSignalMapper; class QPrinter; class FileBrowser; @@ -171,7 +172,7 @@ private: QLabel *_fileNameLabel; QLabel *_distanceLabel; - QLabel *_timeLabel; + FlipLabel *_timeLabel; PathView *_pathView; QTabWidget *_graphTabWidget;