Skip to content
Snippets Groups Projects
Commit 93ac0e9e authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

rm StatusLabel

parent cc9230d8
No related branches found
No related tags found
1 merge request!2315simplify PlotStatusLabel
......@@ -14,13 +14,55 @@
#include "GUI/View/Plotter/PlotStatusLabel.h"
#include "GUI/View/Plotter/ScientificPlot.h"
#include "GUI/Support/Style/Style.h"
#include <QColor>
#include <QFont>
#include <QPainter>
namespace {
int default_text_size()
{
return GUI::Style::fontSizeRegular();
}
int default_label_height()
{
return GUI::Style::SizeOfLetterM().height() * 1.75;
}
} // namespace
PlotStatusLabel::PlotStatusLabel(ScientificPlot* plot)
: m_font("Monospace", default_text_size(), QFont::Normal, false)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setFixedHeight(default_label_height());
if (plot)
addPlot(plot);
}
void PlotStatusLabel::setText(const QString& text)
{
m_text = text;
update();
}
void PlotStatusLabel::paintEvent(QPaintEvent* event)
{
QWidget::paintEvent(event);
QPainter painter(this);
painter.setBrush(QColor(Qt::black));
painter.setPen(QColor(Qt::black));
painter.setFont(m_font);
QRect textRect(0, 0, geometry().width(), geometry().height());
painter.fillRect(textRect, QColor(Qt::white));
painter.drawText(textRect, m_alignment, m_text);
}
//! Disconnects all color maps from the label.
void PlotStatusLabel::reset()
{
......
......@@ -15,8 +15,9 @@
#ifndef BORNAGAIN_GUI_VIEW_PLOTTER_PLOTSTATUSLABEL_H
#define BORNAGAIN_GUI_VIEW_PLOTTER_PLOTSTATUSLABEL_H
#include "GUI/View/Plotter/StatusLabel.h"
#include <QFrame>
#include <QList>
#include <QPaintEvent>
class ScientificPlot;
......@@ -25,7 +26,7 @@ class ScientificPlot;
//! depending on available space in parent layout. Also doesn't trigger layout resize,
//! being happy with place it has.
class PlotStatusLabel : public StatusLabel {
class PlotStatusLabel : public QFrame {
Q_OBJECT
public:
PlotStatusLabel(ScientificPlot* plot);
......@@ -34,6 +35,8 @@ public:
void addPlot(ScientificPlot* plot);
void setPlot(ScientificPlot* plot);
void setText(const QString& text);
void setLabelEnabled(bool flag);
public slots:
......@@ -43,9 +46,14 @@ private slots:
void onPlotDestroyed(QObject* obj);
private:
void paintEvent(QPaintEvent* event) override;
void setPlotLabelEnabled(ScientificPlot* plot, bool flag);
void setConnected(ScientificPlot* plot, bool flag) const;
QString m_text;
Qt::Alignment m_alignment;
QFont m_font;
QList<ScientificPlot*> m_plots;
};
......
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Plotter/StatusLabel.cpp
//! @brief Implements class StatusLabel.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "GUI/View/Plotter/StatusLabel.h"
#include "GUI/Support/Style/Style.h"
#include <QColor>
#include <QFont>
#include <QPainter>
namespace {
int default_text_size()
{
return GUI::Style::fontSizeRegular();
}
int default_label_height()
{
return GUI::Style::SizeOfLetterM().height() * 1.75;
}
} // namespace
StatusLabel::StatusLabel()
: m_font("Monospace", default_text_size(), QFont::Normal, false)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setFixedHeight(default_label_height());
}
void StatusLabel::setText(const QString& text)
{
m_text = text;
update();
}
void StatusLabel::paintEvent(QPaintEvent* event)
{
QWidget::paintEvent(event);
QPainter painter(this);
painter.setBrush(QColor(Qt::black));
painter.setPen(QColor(Qt::black));
painter.setFont(m_font);
QRect textRect(0, 0, geometry().width(), geometry().height());
painter.fillRect(textRect, QColor(Qt::white));
painter.drawText(textRect, m_alignment, m_text);
}
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/View/Plotter/StatusLabel.h
//! @brief Defines class StatusLabel.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_VIEW_PLOTTER_STATUSLABEL_H
#define BORNAGAIN_GUI_VIEW_PLOTTER_STATUSLABEL_H
#include <QFrame>
#include <QPaintEvent>
//! The StatusLabel class shows a single line of text on a white background. Opposite to QLabel,
//! if text string is too long for current size, it will be clipped.
//! This class is intended for ColorMapLabel, where the size of font is adjusted automatically
//! depending from available space.
class StatusLabel : public QFrame {
Q_OBJECT
public:
StatusLabel();
void setText(const QString& text);
protected:
void paintEvent(QPaintEvent* event) override;
private:
QString m_text;
Qt::Alignment m_alignment;
QFont m_font;
};
#endif // BORNAGAIN_GUI_VIEW_PLOTTER_STATUSLABEL_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment