2018-07-09 18:05:31 +00:00
|
|
|
#ifndef AMUSE_STATUSBAR_WIDGET_HPP
|
|
|
|
#define AMUSE_STATUSBAR_WIDGET_HPP
|
|
|
|
|
|
|
|
#include <QStatusBar>
|
2018-07-18 07:39:26 +00:00
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
class StatusBarFocus;
|
2018-07-09 18:05:31 +00:00
|
|
|
|
|
|
|
class StatusBarWidget : public QStatusBar
|
|
|
|
{
|
2018-07-18 07:39:26 +00:00
|
|
|
friend class StatusBarFocus;
|
2018-07-09 18:05:31 +00:00
|
|
|
Q_OBJECT
|
2018-07-18 07:39:26 +00:00
|
|
|
QLabel* m_normalMessage;
|
|
|
|
StatusBarFocus* m_curFocus = nullptr;
|
2018-07-09 18:05:31 +00:00
|
|
|
public:
|
2018-07-18 07:39:26 +00:00
|
|
|
explicit StatusBarWidget(QWidget* parent = Q_NULLPTR) : QStatusBar(parent) {}
|
|
|
|
void setNormalMessage(const QString& message) { m_normalMessage->setText(message); }
|
2018-07-09 18:05:31 +00:00
|
|
|
};
|
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
class StatusBarFocus : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
QString m_message;
|
|
|
|
public:
|
|
|
|
explicit StatusBarFocus(StatusBarWidget* statusWidget)
|
|
|
|
: QObject(statusWidget) {}
|
|
|
|
~StatusBarFocus() { exit(); }
|
|
|
|
void setMessage(const QString& message)
|
|
|
|
{
|
|
|
|
m_message = message;
|
|
|
|
if (StatusBarWidget* widget = qobject_cast<StatusBarWidget*>(parent()))
|
|
|
|
{
|
|
|
|
if (widget->m_curFocus == this)
|
|
|
|
{
|
|
|
|
if (m_message.isEmpty())
|
|
|
|
widget->clearMessage();
|
|
|
|
else
|
|
|
|
widget->showMessage(m_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void enter()
|
|
|
|
{
|
|
|
|
if (StatusBarWidget* widget = qobject_cast<StatusBarWidget*>(parent()))
|
|
|
|
{
|
|
|
|
widget->m_curFocus = this;
|
|
|
|
if (m_message.isEmpty())
|
|
|
|
widget->clearMessage();
|
|
|
|
else
|
|
|
|
widget->showMessage(m_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void exit()
|
|
|
|
{
|
|
|
|
if (StatusBarWidget* widget = qobject_cast<StatusBarWidget*>(parent()))
|
|
|
|
{
|
|
|
|
if (widget->m_curFocus == this)
|
|
|
|
{
|
|
|
|
widget->clearMessage();
|
|
|
|
widget->m_curFocus = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-07-09 18:05:31 +00:00
|
|
|
|
|
|
|
#endif //AMUSE_STATUSBAR_WIDGET_HPP
|