File widgets.h
Go to the documentation of this file
/*******************************************************
* Author: Intelligent Medical Systems
* License: see LICENSE.md file
*******************************************************/
#ifndef XILENS_WIDGETS_H
#define XILENS_WIDGETS_H
#include <QColor>
#include <QEvent>
#include <QLineEdit>
#include <QPushButton>
#include <QSlider>
#include <QSpinBox>
#include <QToolButton>
#include <QVBoxLayout>
class QSliderLabeled : public QSlider
{
public:
explicit QSliderLabeled(QWidget *parent = nullptr);
void SetGrooveMargin(const int value)
{
m_grooveMargin = value;
}
void SetMaxNumberOfLabels(const int value)
{
m_maxNumberOfLabels = value;
}
void ApplyStyleSheet();
void SetSliderSpread(const int value)
{
m_sliderSpread = value;
}
void SetDisplayLabels(const bool value)
{
m_displayLabels = value;
}
void SetLabelInterval(const int value)
{
m_labelInterval = value;
}
protected:
void paintEvent(QPaintEvent *event) override;
void showEvent(QShowEvent *event) override
{
QSlider::showEvent(event);
ApplyStyleSheet();
}
bool event(QEvent *e) override
{
if (e->type() == QEvent::EnabledChange)
{
UpdatePainterPen();
}
return QSlider::event(e);
}
void mouseMoveEvent(QMouseEvent *event) override;
int m_grooveMargin = 12;
int m_labelInterval;
int m_maxNumberOfLabels = 8;
int m_sliderSpread = 48;
private:
QColor m_penColor;
void UpdatePainterPen();
int GetLabelInterval() const;
bool m_displayLabels;
};
class QSliderPopup : public QWidget
{
public:
QSliderPopup(int min, int max, int value, Qt::Orientation orientation, QWidget *parent = nullptr);
int value() const
{
return m_slider->value();
}
void SetMinimum(const int min) const
{
m_slider->setMinimum(min);
}
void SetMaximum(const int max) const
{
m_slider->setMaximum(max);
}
void SetDisplayLabels(const bool value) const
{
m_slider->SetDisplayLabels(value);
}
void SetLabelInterval(const int value) const
{
m_slider->SetLabelInterval(value);
}
private:
QSliderLabeled *m_slider;
QVBoxLayout *m_layout;
QHBoxLayout *m_backgroundFrameLayout;
QFrame *m_frame;
static constexpr int m_contentMargin = 10;
static constexpr int m_windowBorderRadius = 5;
};
class QLineSpinPopup : public QWidget
{
public:
explicit QLineSpinPopup(QWidget *parent = nullptr);
QString text() const
{
return m_lineEdit->text();
}
void setText(const QString &fileName) const
{
m_lineEdit->setText(fileName);
}
int value() const
{
return m_spinBox->value();
}
void setValue(const int value) const
{
m_spinBox->setValue(value);
}
QLineEdit *m_lineEdit;
QSpinBox *m_spinBox;
private:
QVBoxLayout *m_layout;
QHBoxLayout *m_backgroundFrameLayout;
QFrame *m_frame;
static constexpr int m_contentMargin = 10;
static constexpr int m_windowBorderRadius = 5;
};
class QDoubleSpinBoxesPopup : public QWidget
{
Q_OBJECT
public:
explicit QDoubleSpinBoxesPopup(QWidget *parent = nullptr);
int minValue() const
{
return m_spinBox1->value();
}
int maxValue() const
{
return m_spinBox2->value();
}
void setMinValue(const int value) const
{
m_spinBox1->setValue(value);
}
void setMaxValue(const int value) const
{
m_spinBox2->setValue(value);
}
QSpinBox *m_spinBox1;
QSpinBox *m_spinBox2;
signals:
void minValueChanged(int value);
void maxValueChanged(int value);
private:
QHBoxLayout *m_layout;
QFrame *m_frame;
static constexpr int m_contentMargin = 10;
static constexpr int m_windowBorderRadius = 5;
protected:
QHBoxLayout *m_backgroundFrameLayout;
};
class QDoubleSpinBoxesWithColorPickersPopup : public QDoubleSpinBoxesPopup
{
Q_OBJECT
public:
explicit QDoubleSpinBoxesWithColorPickersPopup(QWidget *parent = nullptr);
QColor getLeftColor() const;
QColor getRightColor() const;
void setLeftColor(const QColor &color);
void setRightColor(const QColor &color);
void setToolTips(const QString &leftColorTooltip, const QString &rightColorTooltip, const QString &minValueTooltip,
const QString &maxValueTooltip) const;
signals:
void leftColorChanged(const QColor &color);
void rightColorChanged(const QColor &color);
private slots:
void onLeftColorButtonClicked();
void onRightColorButtonClicked();
private:
void updateColorButtonStyles() const;
QPushButton *m_leftColorButton;
QPushButton *m_rightColorButton;
QColor m_leftColor;
QColor m_rightColor;
};
class QRgbChannelSpinBoxesPopup : public QWidget
{
Q_OBJECT
public:
explicit QRgbChannelSpinBoxesPopup(QWidget *parent = nullptr);
std::vector<int> getRgb() const;
QSpinBox *m_spinBox1;
QSpinBox *m_spinBox2;
QSpinBox *m_spinBox3;
signals:
void ValueChanged(std::vector<int> rgb) const;
private slots:
void RedValueChanged(int value) const;
void GreenValueChanged(int value) const;
void BlueValueChanged(int value) const;
public slots:
void UpdateRgb(int red, int green, int blue) const;
private:
QHBoxLayout *m_layout;
QHBoxLayout *m_backgroundFrameLayout;
QFrame *m_frame;
static constexpr int m_contentMargin = 10;
static constexpr int m_windowBorderRadius = 5;
};
class QArrowToolButton : public QToolButton
{
Q_OBJECT
public:
explicit QArrowToolButton(QWidget *parent = nullptr);
signals:
void ArrowClicked();
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
private:
QRect ArrowRect() const;
};
void StyleQFrameInPopupWindow(QFrame *frame, QLayout *layout, int borderRadius, int contentMargin);
#endif // XILENS_WIDGETS_H