amuse/Editor/StatusBarWidget.hpp

67 lines
1.7 KiB
C++
Raw Normal View History

#ifndef AMUSE_STATUSBAR_WIDGET_HPP
#define AMUSE_STATUSBAR_WIDGET_HPP
#include <QStatusBar>
2018-07-18 07:39:26 +00:00
#include <QLabel>
class StatusBarFocus;
class StatusBarWidget : public QStatusBar
{
2018-07-18 07:39:26 +00:00
friend class StatusBarFocus;
Q_OBJECT
2018-07-18 07:39:26 +00:00
QLabel* m_normalMessage;
StatusBarFocus* m_curFocus = nullptr;
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-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;
}
}
}
};
#endif //AMUSE_STATUSBAR_WIDGET_HPP