2021-12-18 18:02:01 +00:00
|
|
|
#include "LabeledSeparator.hpp"
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2021-12-18 18:02:01 +00:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
void LabeledSeparator::paintEvent(QPaintEvent* event) {
|
|
|
|
|
auto painter = QPainter(this);
|
|
|
|
|
this->drawWidget(painter);
|
|
|
|
|
}
|
2021-12-18 18:02:01 +00:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
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
|
|
|
|
|
);
|
2021-12-18 18:02:01 +00:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
const auto lineYPosition = titleRect.y() + (titleRect.height() / 2);
|
|
|
|
|
const auto line = QLine(
|
|
|
|
|
titleRect.right() + 8,
|
|
|
|
|
lineYPosition,
|
|
|
|
|
this->width() - this->marginRight,
|
|
|
|
|
lineYPosition
|
|
|
|
|
);
|
2021-12-18 18:02:01 +00:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
painter.drawText(titleRect, Qt::AlignCenter, this->title);
|
2021-12-18 18:02:01 +00:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
painter.setPen(this->lineColor);
|
|
|
|
|
painter.drawLine(line);
|
|
|
|
|
}
|
2021-12-18 18:02:01 +00:00
|
|
|
}
|