MultiMC5/launcher/ui/widgets/LineSeparator.cpp

38 lines
1008 B
C++
Raw Normal View History

2014-05-17 14:23:48 +00:00
#include "LineSeparator.h"
#include <QStyle>
#include <QStyleOption>
#include <QLayout>
#include <QPainter>
void LineSeparator::initStyleOption(QStyleOption *option) const
{
2018-07-15 12:51:05 +00:00
option->initFrom(this);
// in a horizontal layout, the line is vertical (and vice versa)
if (m_orientation == Qt::Vertical)
option->state |= QStyle::State_Horizontal;
2014-05-17 14:23:48 +00:00
}
LineSeparator::LineSeparator(QWidget *parent, Qt::Orientation orientation)
2018-07-15 12:51:05 +00:00
: QWidget(parent), m_orientation(orientation)
2014-05-17 14:23:48 +00:00
{
2018-07-15 12:51:05 +00:00
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
2014-05-17 14:23:48 +00:00
}
QSize LineSeparator::sizeHint() const
{
2018-07-15 12:51:05 +00:00
QStyleOption opt;
initStyleOption(&opt);
const int extent =
style()->pixelMetric(QStyle::PM_ToolBarSeparatorExtent, &opt, parentWidget());
return QSize(extent, extent);
2014-05-17 14:23:48 +00:00
}
void LineSeparator::paintEvent(QPaintEvent *)
{
2018-07-15 12:51:05 +00:00
QPainter p(this);
QStyleOption opt;
initStyleOption(&opt);
style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, &p, parentWidget());
2014-05-17 14:23:48 +00:00
}