2016-06-12 08:21:58 +00:00
|
|
|
#include "fab.h"
|
2016-06-12 11:05:31 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QDebug>
|
|
|
|
#include "fab_p.h"
|
|
|
|
|
|
|
|
FloatingActionButtonPrivate::FloatingActionButtonPrivate(FloatingActionButton *q)
|
|
|
|
: RaisedButtonPrivate(q),
|
|
|
|
mini(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FloatingActionButtonPrivate::~FloatingActionButtonPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FloatingActionButtonPrivate::init()
|
|
|
|
{
|
|
|
|
Q_Q(FloatingActionButton);
|
|
|
|
|
|
|
|
q->setRole(Material::Primary);
|
|
|
|
}
|
2016-06-12 08:21:58 +00:00
|
|
|
|
2016-06-12 09:03:29 +00:00
|
|
|
FloatingActionButton::FloatingActionButton(QWidget *parent)
|
2016-06-12 10:26:38 +00:00
|
|
|
: RaisedButton(parent)
|
2016-06-12 08:21:58 +00:00
|
|
|
{
|
2016-06-12 11:05:31 +00:00
|
|
|
d_func()->init();
|
2016-06-12 08:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FloatingActionButton::~FloatingActionButton()
|
|
|
|
{
|
|
|
|
}
|
2016-06-12 11:05:31 +00:00
|
|
|
|
|
|
|
QSize FloatingActionButton::sizeHint() const
|
|
|
|
{
|
|
|
|
Q_D(const FloatingActionButton);
|
|
|
|
|
|
|
|
if (d->mini) {
|
|
|
|
return QSize(40, 40);
|
|
|
|
}
|
|
|
|
return QSize(56, 56);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FloatingActionButton::setMini(bool state)
|
|
|
|
{
|
|
|
|
Q_D(FloatingActionButton);
|
|
|
|
|
|
|
|
d->mini = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FloatingActionButton::isMini() const
|
|
|
|
{
|
|
|
|
Q_D(const FloatingActionButton);
|
|
|
|
|
|
|
|
return d->mini;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FloatingActionButton::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
|
|
|
int s = qMin(width(), height());
|
|
|
|
QRect square = QRect(0, 0, s, s);
|
|
|
|
square.moveCenter(rect().center());
|
|
|
|
|
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHints(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
QBrush brush;
|
|
|
|
brush.setStyle(Qt::SolidPattern);
|
|
|
|
brush.setColor(isEnabled()
|
|
|
|
? backgroundColor() : palette().color(QPalette::Disabled, QPalette::Background));
|
|
|
|
painter.setBrush(brush);
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
|
|
|
|
painter.drawEllipse(square);
|
|
|
|
}
|