Drawer moved.
This commit is contained in:
parent
597ad493fb
commit
0e907a75c8
|
@ -9,6 +9,8 @@
|
|||
#include <QLinearGradient>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
#include "qtmaterialdrawer_internal.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
/*!
|
||||
* \class QtMaterialDrawerPrivate
|
||||
|
@ -18,7 +20,7 @@
|
|||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q)
|
||||
DrawerPrivate::DrawerPrivate(Drawer *q)
|
||||
: q_ptr(q)
|
||||
{
|
||||
}
|
||||
|
@ -26,19 +28,19 @@ QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q)
|
|||
/*!
|
||||
* \internal
|
||||
*/
|
||||
QtMaterialDrawerPrivate::~QtMaterialDrawerPrivate()
|
||||
DrawerPrivate::~DrawerPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \internal
|
||||
*/
|
||||
void QtMaterialDrawerPrivate::init()
|
||||
void DrawerPrivate::init()
|
||||
{
|
||||
Q_Q(QtMaterialDrawer);
|
||||
Q_Q(Drawer);
|
||||
|
||||
widget = new QtMaterialDrawerWidget;
|
||||
stateMachine = new QtMaterialDrawerStateMachine(widget, q);
|
||||
widget = new DrawerWidget;
|
||||
stateMachine = new DrawerStateMachine(widget, q);
|
||||
window = new QWidget;
|
||||
width = 250;
|
||||
clickToClose = false;
|
||||
|
@ -62,93 +64,93 @@ void QtMaterialDrawerPrivate::init()
|
|||
* \class QtMaterialDrawer
|
||||
*/
|
||||
|
||||
QtMaterialDrawer::QtMaterialDrawer(QWidget *parent)
|
||||
: QtMaterialOverlayWidget(parent),
|
||||
d_ptr(new QtMaterialDrawerPrivate(this))
|
||||
Drawer::Drawer(QWidget *parent)
|
||||
: OverlayWidget(parent),
|
||||
d_ptr(new DrawerPrivate(this))
|
||||
{
|
||||
d_func()->init();
|
||||
}
|
||||
|
||||
QtMaterialDrawer::~QtMaterialDrawer()
|
||||
Drawer::~Drawer()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::setDrawerWidth(int width)
|
||||
void Drawer::setDrawerWidth(int width)
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
d->width = width;
|
||||
d->stateMachine->updatePropertyAssignments();
|
||||
d->widget->setFixedWidth(width+16);
|
||||
}
|
||||
|
||||
int QtMaterialDrawer::drawerWidth() const
|
||||
int Drawer::drawerWidth() const
|
||||
{
|
||||
Q_D(const QtMaterialDrawer);
|
||||
Q_D(const Drawer);
|
||||
|
||||
return d->width;
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::setDrawerLayout(QLayout *layout)
|
||||
void Drawer::setDrawerLayout(QLayout *layout)
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
d->window->setLayout(layout);
|
||||
}
|
||||
|
||||
QLayout *QtMaterialDrawer::drawerLayout() const
|
||||
QLayout *Drawer::drawerLayout() const
|
||||
{
|
||||
Q_D(const QtMaterialDrawer);
|
||||
Q_D(const Drawer);
|
||||
|
||||
return d->window->layout();
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::setClickOutsideToClose(bool state)
|
||||
void Drawer::setClickOutsideToClose(bool state)
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
d->clickToClose = state;
|
||||
}
|
||||
|
||||
bool QtMaterialDrawer::clickOutsideToClose() const
|
||||
bool Drawer::clickOutsideToClose() const
|
||||
{
|
||||
Q_D(const QtMaterialDrawer);
|
||||
Q_D(const Drawer);
|
||||
|
||||
return d->clickToClose;
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::setAutoRaise(bool state)
|
||||
void Drawer::setAutoRaise(bool state)
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
d->autoRaise = state;
|
||||
}
|
||||
|
||||
bool QtMaterialDrawer::autoRaise() const
|
||||
bool Drawer::autoRaise() const
|
||||
{
|
||||
Q_D(const QtMaterialDrawer);
|
||||
Q_D(const Drawer);
|
||||
|
||||
return d->autoRaise;
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::setOverlayMode(bool value)
|
||||
void Drawer::setOverlayMode(bool value)
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
d->overlay = value;
|
||||
update();
|
||||
}
|
||||
|
||||
bool QtMaterialDrawer::overlayMode() const
|
||||
bool Drawer::overlayMode() const
|
||||
{
|
||||
Q_D(const QtMaterialDrawer);
|
||||
Q_D(const Drawer);
|
||||
|
||||
return d->overlay;
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::openDrawer()
|
||||
void Drawer::openDrawer()
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
emit d->stateMachine->signalOpen();
|
||||
|
||||
|
@ -159,9 +161,9 @@ void QtMaterialDrawer::openDrawer()
|
|||
setAttribute(Qt::WA_NoSystemBackground, false);
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::closeDrawer()
|
||||
void Drawer::closeDrawer()
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
emit d->stateMachine->signalClose();
|
||||
|
||||
|
@ -171,9 +173,9 @@ void QtMaterialDrawer::closeDrawer()
|
|||
}
|
||||
}
|
||||
|
||||
bool QtMaterialDrawer::event(QEvent *event)
|
||||
bool Drawer::event(QEvent *event)
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
switch (event->type())
|
||||
{
|
||||
|
@ -186,12 +188,12 @@ bool QtMaterialDrawer::event(QEvent *event)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return QtMaterialOverlayWidget::event(event);
|
||||
return OverlayWidget::event(event);
|
||||
}
|
||||
|
||||
bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event)
|
||||
bool Drawer::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
switch (event->type())
|
||||
{
|
||||
|
@ -216,14 +218,14 @@ bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
return QtMaterialOverlayWidget::eventFilter(obj, event);
|
||||
return OverlayWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void QtMaterialDrawer::paintEvent(QPaintEvent *event)
|
||||
void Drawer::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
Q_D(QtMaterialDrawer);
|
||||
Q_D(Drawer);
|
||||
|
||||
if (!d->overlay || d->stateMachine->isInClosedState()) {
|
||||
return;
|
||||
|
@ -232,3 +234,5 @@ void QtMaterialDrawer::paintEvent(QPaintEvent *event)
|
|||
painter.setOpacity(d->stateMachine->opacity());
|
||||
painter.fillRect(rect(), Qt::SolidPattern);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,17 +2,19 @@
|
|||
#define QTMATERIALDRAWER_H
|
||||
|
||||
#include "lib/qtmaterialoverlaywidget.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QtMaterialDrawerPrivate;
|
||||
class QtMaterialDrawerStateMachine;
|
||||
class DrawerPrivate;
|
||||
class DrawerStateMachine;
|
||||
|
||||
class QtMaterialDrawer : public QtMaterialOverlayWidget
|
||||
class Drawer : public OverlayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtMaterialDrawer(QWidget *parent = 0);
|
||||
~QtMaterialDrawer();
|
||||
explicit Drawer(QWidget *parent = 0);
|
||||
~Drawer();
|
||||
|
||||
void setDrawerWidth(int width);
|
||||
int drawerWidth() const;
|
||||
|
@ -38,11 +40,11 @@ protected:
|
|||
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
const QScopedPointer<QtMaterialDrawerPrivate> d_ptr;
|
||||
const QScopedPointer<DrawerPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialDrawer)
|
||||
Q_DECLARE_PRIVATE(QtMaterialDrawer)
|
||||
Q_DISABLE_COPY(Drawer)
|
||||
Q_DECLARE_PRIVATE(Drawer)
|
||||
};
|
||||
|
||||
}
|
||||
#endif // QTMATERIALDRAWER_H
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
#include <QSignalTransition>
|
||||
#include <QPropertyAnimation>
|
||||
#include "qtmaterialdrawer.h"
|
||||
|
||||
namespace md
|
||||
{
|
||||
/*!
|
||||
* \class QtMaterialDrawerStateMachine
|
||||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialDrawerStateMachine::QtMaterialDrawerStateMachine(QtMaterialDrawerWidget *drawer, QtMaterialDrawer *parent)
|
||||
DrawerStateMachine::DrawerStateMachine(DrawerWidget *drawer, Drawer *parent)
|
||||
: QStateMachine(parent),
|
||||
m_drawer(drawer),
|
||||
m_main(parent),
|
||||
|
@ -85,22 +86,22 @@ QtMaterialDrawerStateMachine::QtMaterialDrawerStateMachine(QtMaterialDrawerWidge
|
|||
updatePropertyAssignments();
|
||||
}
|
||||
|
||||
QtMaterialDrawerStateMachine::~QtMaterialDrawerStateMachine()
|
||||
DrawerStateMachine::~DrawerStateMachine()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialDrawerStateMachine::setOpacity(qreal opacity)
|
||||
void DrawerStateMachine::setOpacity(qreal opacity)
|
||||
{
|
||||
m_opacity = opacity;
|
||||
m_main->update();
|
||||
}
|
||||
|
||||
bool QtMaterialDrawerStateMachine::isInClosedState() const
|
||||
bool DrawerStateMachine::isInClosedState() const
|
||||
{
|
||||
return m_closedState->active();
|
||||
}
|
||||
|
||||
void QtMaterialDrawerStateMachine::updatePropertyAssignments()
|
||||
void DrawerStateMachine::updatePropertyAssignments()
|
||||
{
|
||||
const qreal closedOffset = -(m_drawer->width()+32);
|
||||
|
||||
|
@ -119,17 +120,17 @@ void QtMaterialDrawerStateMachine::updatePropertyAssignments()
|
|||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialDrawerWidget::QtMaterialDrawerWidget(QWidget *parent)
|
||||
: QtMaterialOverlayWidget(parent),
|
||||
DrawerWidget::DrawerWidget(QWidget *parent)
|
||||
: OverlayWidget(parent),
|
||||
m_offset(0)
|
||||
{
|
||||
}
|
||||
|
||||
QtMaterialDrawerWidget::~QtMaterialDrawerWidget()
|
||||
DrawerWidget::~DrawerWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialDrawerWidget::setOffset(int offset)
|
||||
void DrawerWidget::setOffset(int offset)
|
||||
{
|
||||
m_offset = offset;
|
||||
|
||||
|
@ -140,7 +141,7 @@ void QtMaterialDrawerWidget::setOffset(int offset)
|
|||
update();
|
||||
}
|
||||
|
||||
void QtMaterialDrawerWidget::paintEvent(QPaintEvent *event)
|
||||
void DrawerWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
|
@ -163,7 +164,9 @@ void QtMaterialDrawerWidget::paintEvent(QPaintEvent *event)
|
|||
painter.drawRect(width()-16, 0, 16, height());
|
||||
}
|
||||
|
||||
QRect QtMaterialDrawerWidget::overlayGeometry() const
|
||||
QRect DrawerWidget::overlayGeometry() const
|
||||
{
|
||||
return QtMaterialOverlayWidget::overlayGeometry().translated(m_offset, 0);
|
||||
return OverlayWidget::overlayGeometry().translated(m_offset, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,19 +4,22 @@
|
|||
#include <QStateMachine>
|
||||
#include "lib/qtmaterialoverlaywidget.h"
|
||||
|
||||
class QtMaterialDrawer;
|
||||
class QtMaterialDrawerWidget;
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QtMaterialDrawerStateMachine : public QStateMachine
|
||||
class Drawer;
|
||||
class DrawerWidget;
|
||||
|
||||
class DrawerStateMachine : public QStateMachine
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity)
|
||||
|
||||
public:
|
||||
explicit QtMaterialDrawerStateMachine(QtMaterialDrawerWidget *drawer,
|
||||
QtMaterialDrawer *parent);
|
||||
~QtMaterialDrawerStateMachine();
|
||||
explicit DrawerStateMachine(DrawerWidget *drawer,
|
||||
Drawer *parent);
|
||||
~DrawerStateMachine();
|
||||
|
||||
void setOpacity(qreal opacity);
|
||||
inline qreal opacity() const;
|
||||
|
@ -30,10 +33,10 @@ signals:
|
|||
void signalClose();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialDrawerStateMachine)
|
||||
Q_DISABLE_COPY(DrawerStateMachine)
|
||||
|
||||
QtMaterialDrawerWidget *const m_drawer;
|
||||
QtMaterialDrawer *const m_main;
|
||||
DrawerWidget *const m_drawer;
|
||||
Drawer *const m_main;
|
||||
QState *const m_openingState;
|
||||
QState *const m_openedState;
|
||||
QState *const m_closingState;
|
||||
|
@ -41,20 +44,20 @@ private:
|
|||
qreal m_opacity;
|
||||
};
|
||||
|
||||
inline qreal QtMaterialDrawerStateMachine::opacity() const
|
||||
inline qreal DrawerStateMachine::opacity() const
|
||||
{
|
||||
return m_opacity;
|
||||
}
|
||||
|
||||
class QtMaterialDrawerWidget : public QtMaterialOverlayWidget
|
||||
class DrawerWidget : public OverlayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int offset WRITE setOffset READ offset)
|
||||
|
||||
public:
|
||||
explicit QtMaterialDrawerWidget(QWidget *parent = 0);
|
||||
~QtMaterialDrawerWidget();
|
||||
explicit DrawerWidget(QWidget *parent = 0);
|
||||
~DrawerWidget();
|
||||
|
||||
void setOffset(int offset);
|
||||
inline int offset() const;
|
||||
|
@ -68,9 +71,9 @@ private:
|
|||
int m_offset;
|
||||
};
|
||||
|
||||
inline int QtMaterialDrawerWidget::offset() const
|
||||
inline int DrawerWidget::offset() const
|
||||
{
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
}
|
||||
#endif // DRAWER_INTERNAL_H
|
||||
|
|
|
@ -2,26 +2,28 @@
|
|||
#define DRAWER_P_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QtMaterialDrawer;
|
||||
class QtMaterialDrawerWidget;
|
||||
class QtMaterialDrawerStateMachine;
|
||||
|
||||
class QtMaterialDrawerPrivate
|
||||
namespace md
|
||||
{
|
||||
Q_DISABLE_COPY(QtMaterialDrawerPrivate)
|
||||
Q_DECLARE_PUBLIC(QtMaterialDrawer)
|
||||
|
||||
class Drawer;
|
||||
class DrawerWidget;
|
||||
class DrawerStateMachine;
|
||||
|
||||
class DrawerPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(DrawerPrivate)
|
||||
Q_DECLARE_PUBLIC(Drawer)
|
||||
|
||||
public:
|
||||
QtMaterialDrawerPrivate(QtMaterialDrawer *q);
|
||||
~QtMaterialDrawerPrivate();
|
||||
DrawerPrivate(Drawer *q);
|
||||
~DrawerPrivate();
|
||||
|
||||
void init();
|
||||
void setClosed(bool value = true);
|
||||
|
||||
QtMaterialDrawer *const q_ptr;
|
||||
QtMaterialDrawerWidget *widget;
|
||||
QtMaterialDrawerStateMachine *stateMachine;
|
||||
Drawer *const q_ptr;
|
||||
DrawerWidget *widget;
|
||||
DrawerStateMachine *stateMachine;
|
||||
QWidget *window;
|
||||
int width;
|
||||
bool clickToClose;
|
||||
|
@ -29,5 +31,5 @@ public:
|
|||
bool closed;
|
||||
bool overlay;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DRAWER_P_H
|
||||
|
|
Loading…
Reference in New Issue