Divider
This commit is contained in:
parent
fae8e8c5d4
commit
4953fcd1e1
|
@ -30,13 +30,12 @@ void QtMaterialDividerPrivate::init()
|
|||
{
|
||||
Q_Q(QtMaterialDivider);
|
||||
|
||||
size = 40;
|
||||
useThemeColors = true;
|
||||
size = 0;
|
||||
|
||||
QSizePolicy policy(QSizePolicy::Ignored,
|
||||
// QSizePolicy policy(QSizePolicy::Expanding,
|
||||
QSizePolicy policy(QSizePolicy::MinimumExpanding,
|
||||
QSizePolicy::Fixed);
|
||||
q->setSizePolicy(policy);
|
||||
q->setMinimumHeight( 4 );
|
||||
q->setMaximumHeight( 14 );
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -54,37 +53,11 @@ QtMaterialDivider::~QtMaterialDivider()
|
|||
{
|
||||
}
|
||||
|
||||
void QtMaterialDivider::setUseThemeColors(bool value)
|
||||
{
|
||||
Q_D(QtMaterialDivider);
|
||||
|
||||
if (d->useThemeColors == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
d->useThemeColors = value;
|
||||
update();
|
||||
}
|
||||
|
||||
bool QtMaterialDivider::useThemeColors() const
|
||||
{
|
||||
Q_D(const QtMaterialDivider);
|
||||
|
||||
return d->useThemeColors;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
QSize QtMaterialDivider::sizeHint() const
|
||||
{
|
||||
Q_D(const QtMaterialDivider);
|
||||
|
||||
return QSize(d->size, 2+2);
|
||||
}
|
||||
|
||||
void QtMaterialDivider::setSize(int size)
|
||||
void QtMaterialDivider::setInsetSize(int size)
|
||||
{
|
||||
Q_D(QtMaterialDivider);
|
||||
|
||||
|
@ -93,27 +66,13 @@ void QtMaterialDivider::setSize(int size)
|
|||
update();
|
||||
}
|
||||
|
||||
int QtMaterialDivider::size() const
|
||||
int QtMaterialDivider::insetSize() const
|
||||
{
|
||||
Q_D(const QtMaterialDivider);
|
||||
|
||||
return d->size;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
void QtMaterialDivider::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
Q_D(QtMaterialDivider);
|
||||
|
||||
QWidget::resizeEvent(event);
|
||||
QSize sz = event->size();
|
||||
d->size = width();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \reimp
|
||||
*/
|
||||
|
@ -124,15 +83,23 @@ void QtMaterialDivider::paintEvent(QPaintEvent *event)
|
|||
Q_D(QtMaterialDivider);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
// TODO: QtMaterialText doesn't use Antialiasing. Usng it the line is more "heavy"
|
||||
// painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
const int wd = d->size; // width();
|
||||
QPen pen;
|
||||
pen.setWidth(2);
|
||||
// pen.setColor(QtMaterialStyle::instance().themeColor("border"));
|
||||
pen.setColor(QColor(255,0,0));
|
||||
pen.setWidth(1);
|
||||
/*
|
||||
* DEBUG: to paint in blue the full widget
|
||||
*
|
||||
*/
|
||||
// painter.fillRect( rect() ,QColor(0,0,255));
|
||||
|
||||
// TODO: is this the right color to use?
|
||||
pen.setColor(QtMaterialStyle::instance().themeColor("border"));
|
||||
|
||||
painter.setPen(pen);
|
||||
painter.setOpacity(1);
|
||||
painter.drawLine(0, 1, wd, 1);
|
||||
|
||||
// TODO: implementing inset, 0 will be changed to a calculated point.
|
||||
// Normally, line should go from 0 to the end
|
||||
painter.drawLine( d->size, height()/2, width(), height()/2);
|
||||
}
|
||||
|
|
|
@ -13,33 +13,12 @@ class QtMaterialDivider : public QWidget
|
|||
|
||||
public:
|
||||
explicit QtMaterialDivider(QWidget *parent = 0);
|
||||
//explicit QtMaterialDivider(const QIcon &icon, QWidget *parent = 0);
|
||||
//explicit QtMaterialDivider(const QChar &letter, QWidget *parent = 0);
|
||||
//explicit QtMaterialDivider(const QImage &image, QWidget *parent = 0);
|
||||
~QtMaterialDivider();
|
||||
|
||||
void setUseThemeColors(bool value);
|
||||
bool useThemeColors() const;
|
||||
|
||||
//void setTextColor(const QColor &color);
|
||||
//QColor textColor() const;
|
||||
|
||||
//void setBackgroundColor(const QColor &color);
|
||||
//QColor backgroundColor() const;
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
void setSize(int size);
|
||||
int size() const;
|
||||
|
||||
//void setLetter(const QChar &letter);
|
||||
//void setImage(const QImage &image);
|
||||
//void setIcon(const QIcon &icon);
|
||||
|
||||
//Material::DividerType type() const;
|
||||
void setInsetSize(int size);
|
||||
int insetSize() const;
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
const QScopedPointer<QtMaterialDividerPrivate> d_ptr;
|
||||
|
|
|
@ -20,14 +20,6 @@ public:
|
|||
|
||||
QtMaterialDivider *const q_ptr;
|
||||
int size;
|
||||
// Material::DividerType type;
|
||||
// QChar letter;
|
||||
// QImage image;
|
||||
// QIcon icon;
|
||||
// QPixmap pixmap;
|
||||
bool useThemeColors;
|
||||
// QColor textColor;
|
||||
// QColor backgroundColor;
|
||||
};
|
||||
|
||||
#endif // QTMATERIALDIVIDER_P_H
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <QColorDialog>
|
||||
#include <QLabel>
|
||||
#include <qtmaterialdivider.h>
|
||||
#include <qtmaterialtextfield.h>
|
||||
|
||||
DividerSettingsEditor::DividerSettingsEditor(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
@ -20,22 +21,30 @@ DividerSettingsEditor::DividerSettingsEditor(QWidget *parent)
|
|||
layout->addWidget(canvas);
|
||||
|
||||
ui->setupUi(widget);
|
||||
layout->setContentsMargins(20, 20, 20, 20);
|
||||
// layout->setContentsMargins(20, 20, 20, 20);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
QLabel *lbl = new QLabel;
|
||||
lbl->setText( "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 " );
|
||||
lbl->setText( "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 " );
|
||||
|
||||
QtMaterialTextField *txt1 = new QtMaterialTextField;
|
||||
txt1->setLabel( "First Name" );
|
||||
txt1->setPlaceholderText( "Placeholder" );
|
||||
|
||||
QtMaterialTextField *txt2 = new QtMaterialTextField;
|
||||
txt2->setLabel( "Middle Name" );
|
||||
|
||||
QtMaterialDivider *div2 = new QtMaterialDivider;
|
||||
div2->setInsetSize( 40 );
|
||||
|
||||
layout = new QVBoxLayout;
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
canvas->setLayout(layout);
|
||||
layout->addWidget(txt1);
|
||||
layout->addWidget(m_divider);
|
||||
layout->setAlignment(m_divider, Qt::AlignCenter);
|
||||
m_divider->setSize( canvas->width() );
|
||||
layout->addWidget(txt2);
|
||||
layout->addWidget(div2);
|
||||
layout->addWidget(lbl);
|
||||
QSizePolicy policy(QSizePolicy::Ignored,
|
||||
QSizePolicy::Fixed);
|
||||
lbl->setSizePolicy(policy);
|
||||
m_divider->setSizePolicy(policy);
|
||||
|
||||
|
||||
setupForm();
|
||||
|
||||
|
|
Loading…
Reference in New Issue