2014-05-17 19:53:48 +05:30
|
|
|
#include "LineSeparator.h"
|
|
|
|
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QStyleOption>
|
|
|
|
#include <QLayout>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
void LineSeparator::initStyleOption(QStyleOption *option) const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
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 19:53:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
LineSeparator::LineSeparator(QWidget *parent, Qt::Orientation orientation)
|
2018-07-15 18:21:05 +05:30
|
|
|
: QWidget(parent), m_orientation(orientation)
|
2014-05-17 19:53:48 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
2014-05-17 19:53:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
QSize LineSeparator::sizeHint() const
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QStyleOption opt;
|
|
|
|
initStyleOption(&opt);
|
|
|
|
const int extent =
|
|
|
|
style()->pixelMetric(QStyle::PM_ToolBarSeparatorExtent, &opt, parentWidget());
|
|
|
|
return QSize(extent, extent);
|
2014-05-17 19:53:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void LineSeparator::paintEvent(QPaintEvent *)
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
QPainter p(this);
|
|
|
|
QStyleOption opt;
|
|
|
|
initStyleOption(&opt);
|
|
|
|
style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, &p, parentWidget());
|
2014-05-17 19:53:48 +05:30
|
|
|
}
|