New LabeledSeparator widget
This commit is contained in:
@@ -139,6 +139,7 @@ add_executable(Bloom
|
|||||||
src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp
|
src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp
|
||||||
|
src/Insight/UserInterfaces/InsightWindow/Widgets/LabeledSeparator.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
// Custom widgets
|
// Custom widgets
|
||||||
#include "Widgets/PanelWidget.hpp"
|
#include "Widgets/PanelWidget.hpp"
|
||||||
#include "Widgets/RotatableLabel.hpp"
|
#include "Widgets/RotatableLabel.hpp"
|
||||||
|
#include "Widgets/LabeledSeparator.hpp"
|
||||||
#include "Widgets/SvgWidget.hpp"
|
#include "Widgets/SvgWidget.hpp"
|
||||||
#include "Widgets/SvgToolButton.hpp"
|
#include "Widgets/SvgToolButton.hpp"
|
||||||
#include "Widgets/ExpandingHeightScrollAreaWidget.hpp"
|
#include "Widgets/ExpandingHeightScrollAreaWidget.hpp"
|
||||||
@@ -33,6 +34,15 @@ UiLoader::UiLoader(QObject* parent): QUiLoader(parent) {
|
|||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"LabeledSeparator",
|
||||||
|
[this] (QWidget* parent, const QString& name) {
|
||||||
|
auto* widget = new LabeledSeparator(parent);
|
||||||
|
widget->setObjectName(name);
|
||||||
|
widget->setStyleSheet(parent->styleSheet());
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"ExpandingHeightScrollAreaWidget",
|
"ExpandingHeightScrollAreaWidget",
|
||||||
[this] (QWidget* parent, const QString& name) {
|
[this] (QWidget* parent, const QString& name) {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#include "LabeledSeparator.hpp"
|
||||||
|
|
||||||
|
using namespace Bloom::Widgets;
|
||||||
|
|
||||||
|
LabeledSeparator::LabeledSeparator(QString title, QWidget* parent): title(std::move(title)), QWidget(parent) {
|
||||||
|
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
||||||
|
this->setFixedHeight(LabeledSeparator::DEFAULT_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LabeledSeparator::paintEvent(QPaintEvent* event) {
|
||||||
|
auto painter = QPainter(this);
|
||||||
|
this->drawWidget(painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LabeledSeparator::drawWidget(QPainter& painter) {
|
||||||
|
const auto fontMetrics = painter.fontMetrics();
|
||||||
|
const auto titleSize = fontMetrics.size(Qt::TextFlag::TextSingleLine, this->title);
|
||||||
|
const auto titleRect = QRect(
|
||||||
|
QPoint(this->marginLeft, (this->height() - titleSize.height()) / 2),
|
||||||
|
titleSize
|
||||||
|
);
|
||||||
|
|
||||||
|
const auto lineYPosition = titleRect.y() + (titleRect.height() / 2);
|
||||||
|
const auto line = QLine(
|
||||||
|
titleRect.right() + 8,
|
||||||
|
lineYPosition,
|
||||||
|
this->width() - this->marginRight,
|
||||||
|
lineYPosition
|
||||||
|
);
|
||||||
|
|
||||||
|
painter.drawText(titleRect, Qt::AlignCenter, this->title);
|
||||||
|
|
||||||
|
painter.setPen(this->lineColor);
|
||||||
|
painter.drawLine(line);
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QString>
|
||||||
|
#include <QColor>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
namespace Bloom::Widgets
|
||||||
|
{
|
||||||
|
class LabeledSeparator: public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString title READ getTitle WRITE setTitle DESIGNABLE true)
|
||||||
|
Q_PROPERTY(QColor lineColor READ getLineColor WRITE setLineColor DESIGNABLE true)
|
||||||
|
Q_PROPERTY(int marginLeft READ getMarginLeft WRITE setMarginLeft DESIGNABLE true)
|
||||||
|
Q_PROPERTY(int marginRight READ getMarginRight WRITE setMarginRight DESIGNABLE true)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LabeledSeparator(QString title = "", QWidget* parent = nullptr);
|
||||||
|
explicit LabeledSeparator(QWidget* parent = nullptr): LabeledSeparator("", parent) {};
|
||||||
|
|
||||||
|
[[nodiscard]] QString getTitle() const {
|
||||||
|
return this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTitle(const QString& title) {
|
||||||
|
this->title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] QColor getLineColor() const {
|
||||||
|
return this->lineColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLineColor(QColor lineColor) {
|
||||||
|
this->lineColor = lineColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] int getMarginLeft() const {
|
||||||
|
return this->marginLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMarginLeft(int marginLeft) {
|
||||||
|
this->marginLeft = marginLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] int getMarginRight() const {
|
||||||
|
return this->marginRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMarginRight(int marginRight) {
|
||||||
|
this->marginRight = marginRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
void drawWidget(QPainter& painter);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr int DEFAULT_HEIGHT = 20;
|
||||||
|
|
||||||
|
QString title;
|
||||||
|
QColor lineColor = QColor(0x4A, 0x4A, 0x4A);
|
||||||
|
int marginLeft = 0;
|
||||||
|
int marginRight = 10;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user