add basic FAB painting
This commit is contained in:
parent
1ed5df9999
commit
7f8c9312d9
|
@ -1,10 +1,76 @@
|
|||
#include "fab.h"
|
||||
#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);
|
||||
}
|
||||
|
||||
FloatingActionButton::FloatingActionButton(QWidget *parent)
|
||||
: RaisedButton(parent)
|
||||
{
|
||||
d_func()->init();
|
||||
}
|
||||
|
||||
FloatingActionButton::~FloatingActionButton()
|
||||
{
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "raisedbutton.h"
|
||||
|
||||
class FloatingActionButtonPrivate;
|
||||
|
||||
class FloatingActionButton : public RaisedButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -11,6 +13,14 @@ public:
|
|||
explicit FloatingActionButton(QWidget *parent = 0);
|
||||
~FloatingActionButton();
|
||||
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
||||
void setMini(bool state);
|
||||
bool isMini() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(FloatingActionButton)
|
||||
Q_DECLARE_PRIVATE(FloatingActionButton)
|
||||
|
|
|
@ -9,18 +9,12 @@ class FloatingActionButtonPrivate : public RaisedButtonPrivate
|
|||
Q_DECLARE_PUBLIC(FloatingActionButton)
|
||||
|
||||
public:
|
||||
FloatingActionButtonPrivate(FloatingActionButton *q)
|
||||
: RaisedButtonPrivate(q)
|
||||
{
|
||||
}
|
||||
FloatingActionButtonPrivate(FloatingActionButton *q);
|
||||
~FloatingActionButtonPrivate();
|
||||
|
||||
~FloatingActionButtonPrivate()
|
||||
{
|
||||
}
|
||||
void init();
|
||||
|
||||
void init()
|
||||
{
|
||||
}
|
||||
bool mini;
|
||||
};
|
||||
|
||||
#endif // FAB_P_H
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "flatbuttonexamples.h"
|
||||
#include "lib/style.h"
|
||||
#include "components/flatbutton.h"
|
||||
#include "components/fab.h"
|
||||
#include "exampleview.h"
|
||||
#include "frame.h"
|
||||
|
||||
|
@ -196,6 +197,26 @@ FlatButtonExamples::FlatButtonExamples(QWidget *parent)
|
|||
);
|
||||
frame->setWidget(view);
|
||||
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
{
|
||||
//QPushButton *flatButton = new QPushButton;
|
||||
//flatButton->setText("Press me!");
|
||||
//flatButton->setIcon(QIcon("../qt-material-widgets/face.svg"));
|
||||
//flatButton->setMinimumSize(200, 50);
|
||||
//flatButton->setCheckable(true);
|
||||
|
||||
FloatingActionButton *button = new FloatingActionButton;
|
||||
|
||||
ExampleView *view = new ExampleView;
|
||||
view->setWidget(button);
|
||||
|
||||
Frame *frame = new Frame;
|
||||
frame->setCodeSnippet(
|
||||
""
|
||||
);
|
||||
frame->setWidget(view);
|
||||
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue