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