diff --git a/GUI/coregui/Views/CommonWidgets/StatusLabel.cpp b/GUI/coregui/Views/CommonWidgets/StatusLabel.cpp index 2cdfb49964bebd56f9f5db6e35b66858a5bd0020..c27be1f8a21b19691887b3fdd1ffef22a556831f 100644 --- a/GUI/coregui/Views/CommonWidgets/StatusLabel.cpp +++ b/GUI/coregui/Views/CommonWidgets/StatusLabel.cpp @@ -21,14 +21,16 @@ #include <QDebug> namespace { -const int default_height = 20; +const int default_label_height = 20; +const int default_text_size = 12; } StatusLabel::StatusLabel(QWidget *parent) : QFrame(parent) + , m_font("Monospace", default_text_size, QFont::Normal, false) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - setFixedHeight(default_height); + setFixedHeight(default_label_height); } void StatusLabel::setText(const QString &text) @@ -37,6 +39,18 @@ void StatusLabel::setText(const QString &text) update(); } +void StatusLabel::setFont(const QFont &font) +{ + m_font = font; + update(); +} + +void StatusLabel::setPointSize(int pointSize) +{ + m_font.setPointSize(pointSize); + update(); +} + void StatusLabel::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); @@ -44,8 +58,7 @@ void StatusLabel::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setBrush(QColor(Qt::black)); painter.setPen(QColor(Qt::black)); - QFont serifFont("Monospace", 12, QFont::Normal, false); - painter.setFont(serifFont); + painter.setFont(m_font); QRect textRect(0, 0, geometry().width(), geometry().height()); painter.fillRect(textRect, QColor(Qt::white)); diff --git a/GUI/coregui/Views/CommonWidgets/StatusLabel.h b/GUI/coregui/Views/CommonWidgets/StatusLabel.h index 129acbdaa1dbac32e9dc50cc077ecd3c9b1b75b6..2b81e514ed313c81b69e643491942ba31fe179bc 100644 --- a/GUI/coregui/Views/CommonWidgets/StatusLabel.h +++ b/GUI/coregui/Views/CommonWidgets/StatusLabel.h @@ -23,22 +23,28 @@ class QPaintEvent; //! The StatusLabel class shows a single line of text on a white background. Opposite to QLabel, -//! it adjusts size of text depending on available space. +//! 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 BA_CORE_API_ StatusLabel : public QFrame { Q_OBJECT public: - StatusLabel(QWidget *parent = 0); + explicit StatusLabel(QWidget *parent = 0); void setText(const QString &text); + void setFont(const QFont &font); + void setPointSize(int pointSize); protected: void paintEvent(QPaintEvent *event); private: QString m_text; + QFont m_font; }; #endif diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.cpp b/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.cpp index 1bc0b316fccf93fd7ee1d6fc6c659536c3a75594..50245a22740ca3bff5c3f485add0feaed980b455 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.cpp @@ -17,35 +17,29 @@ #include "ColorMapCanvas.h" #include "ColorMap.h" #include "ColorMapCanvasEvent.h" -#include "StatusLabel.h" +#include "ColorMapLabel.h" #include <QVBoxLayout> #include <QLabel> #include <QDebug> -namespace { -const int initial_label_width = 100; -} ColorMapCanvas::ColorMapCanvas(QWidget *parent) : QWidget(parent) , m_colorMap(new ColorMap) , m_canvasEvent(new ColorMapCanvasEvent(this)) - , m_statusLabel(new StatusLabel) + , m_statusLabel(new ColorMapLabel(m_colorMap, this)) { QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); layout->setSpacing(0); -// m_statusLabel->setAlignment(Qt::AlignVCenter| Qt::AlignLeft); -// m_statusLabel->setStyleSheet("background-color:white;"); -// m_statusLabel->setMargin(3); layout->addWidget(m_colorMap); layout->addWidget(m_statusLabel); setLayout(layout); - setStatusLabelEnabled(true); + m_statusLabel->setLabelEnabled(true); } @@ -65,25 +59,3 @@ void ColorMapCanvas::onStatusString(const QString &name) } -//! Enables/disables status label with bins/amplitudes at the bottom of widget. - -void ColorMapCanvas::setStatusLabelEnabled(bool flag) -{ - m_colorMap->setMouseTrackingEnabled(true); - setStatusLabelConnected(flag); - m_statusLabel->setVisible(flag); - -} - -//! Connects/disconnects signals for status label. - -void ColorMapCanvas::setStatusLabelConnected(bool flag) -{ - if(flag) { - connect(m_colorMap, SIGNAL(statusString(const QString&)), - this, SLOT(onStatusString(const QString&)), Qt::UniqueConnection); - } else { - disconnect(m_colorMap, SIGNAL(statusString(const QString&)), - this, SLOT(onStatusString(const QString&))); - } -} diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.h b/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.h index aaa9c2154f5c7970f80ec6150e25db17da6f862c..4fae5713522680476114e71fa7caa09d7478f1ab 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.h +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapCanvas.h @@ -23,8 +23,7 @@ class ColorMap; class ColorMapCanvasEvent; class IntensityDataItem; -//class QLabel; -class StatusLabel; +class ColorMapLabel; //! The ColorMapCanvas class contains ColorMap for intensity data presentation, and provide //! control of font size, status string appearance, defines common actions @@ -43,14 +42,13 @@ public: public slots: void onStatusString(const QString &name); - void setStatusLabelEnabled(bool flag); private: void setStatusLabelConnected(bool flag); ColorMap *m_colorMap; ColorMapCanvasEvent *m_canvasEvent; - StatusLabel *m_statusLabel; + ColorMapLabel *m_statusLabel; }; #endif diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.cpp b/GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2894065532054013a671bc1a47a4119fbb42f7af --- /dev/null +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.cpp @@ -0,0 +1,70 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.cpp +//! @brief Implements class ColorMapLabel +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2016 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov +//! @authors Walter Van Herck, Joachim Wuttke +// +// ************************************************************************** // + +#include "ColorMapLabel.h" +#include "ColorMap.h" + +ColorMapLabel::ColorMapLabel(ColorMap *colorMap, QWidget *parent) + : StatusLabel(parent) +{ + addColorMap(colorMap); +} + +void ColorMapLabel::addColorMap(ColorMap *colorMap) +{ + if(m_colorMaps.contains(colorMap)) + return; + + m_colorMaps.push_back(colorMap); + + setColorMapLabelEnabled(colorMap, true); +} + +//! Enables/disables label. If disabled, all colorMaps are disconnected and label is hiding. + +void ColorMapLabel::setLabelEnabled(bool flag) +{ + foreach(ColorMap *colorMap, m_colorMaps) + setColorMapLabelEnabled(colorMap, flag); + + setEnabled(flag); +} + +void ColorMapLabel::onColorMapStatusString(const QString &text) +{ + setText(text); +} + +//! Enables/disables showing of label for given color map. + +void ColorMapLabel::setColorMapLabelEnabled(ColorMap *colorMap, bool flag) +{ + colorMap->setMouseTrackingEnabled(flag); + setConnected(colorMap, flag); +} + +//! Connects with colorMap's status string signal. + +void ColorMapLabel::setConnected(ColorMap *colorMap, bool flag) +{ + if(flag) { + connect(colorMap, SIGNAL(statusString(const QString&)), + this, SLOT(onColorMapStatusString(const QString&)), Qt::UniqueConnection); + } else { + disconnect(colorMap, SIGNAL(statusString(const QString&)), + this, SLOT(onColorMapStatusString(const QString&))); + } +} diff --git a/GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.h b/GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.h new file mode 100644 index 0000000000000000000000000000000000000000..bb064a4ea4310dc2e96a8cdd69e0b275453a88e6 --- /dev/null +++ b/GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.h @@ -0,0 +1,52 @@ +// ************************************************************************** // +// +// BornAgain: simulate and fit scattering at grazing incidence +// +//! @file GUI/coregui/Views/IntensityDataWidgets/ColorMapLabel.h +//! @brief Declares class ColorMapLabel +//! +//! @homepage http://www.bornagainproject.org +//! @license GNU General Public License v3 or higher (see COPYING) +//! @copyright Forschungszentrum Jülich GmbH 2016 +//! @authors Scientific Computing Group at MLZ Garching +//! @authors Céline Durniak, Marina Ganeva, David Li, Gennady Pospelov +//! @authors Walter Van Herck, Joachim Wuttke +// +// ************************************************************************** // + +#ifndef COLORMAPLABEL_H +#define COLORMAPLABEL_H + +#include "StatusLabel.h" +#include <QList> + +class ColorMap; + +//! The ColorMapLabel class shows status string as reported by ColorMap in a frame. +//! Can work with more than one ColorMap. Provides automatic adjustment of font size, +//! depending on available space in parent layout. Also doesn't trigger layout resize, +//! beeing happy with place it has. + +class BA_CORE_API_ ColorMapLabel : public StatusLabel +{ + Q_OBJECT +public: + ColorMapLabel(ColorMap *colorMap, QWidget *parent = 0); + + void addColorMap(ColorMap *colorMap); + + void setLabelEnabled(bool flag); + + +public slots: + void onColorMapStatusString(const QString &text); + +private: + void setColorMapLabelEnabled(ColorMap *colorMap, bool flag); + void setConnected(ColorMap *colorMap, bool flag); + + QList<ColorMap *> m_colorMaps; +}; + +#endif +