Add autoRaise property to Drawer

This commit is contained in:
johanneshilden 2017-10-05 11:13:21 +03:00
parent c8fbfb019d
commit 5d584d44c3
3 changed files with 56 additions and 11 deletions

View File

@ -14,13 +14,34 @@
* \internal * \internal
*/ */
/*!
* \internal
*/
QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q) QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q)
: q_ptr(q), : q_ptr(q)
stateMachine(new QtMaterialDrawerStateMachine(q)),
window(new QWidget),
width(250),
clickToClose(false)
{ {
}
/*!
* \internal
*/
QtMaterialDrawerPrivate::~QtMaterialDrawerPrivate()
{
}
/*!
* \internal
*/
void QtMaterialDrawerPrivate::init()
{
Q_Q(QtMaterialDrawer);
stateMachine = new QtMaterialDrawerStateMachine(q);
window = new QWidget;
width = 250;
clickToClose = false;
autoRaise = true;
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(window); layout->addWidget(window);
@ -28,7 +49,6 @@ QtMaterialDrawerPrivate::QtMaterialDrawerPrivate(QtMaterialDrawer *q)
q->setFixedWidth(width+16); q->setFixedWidth(width+16);
stateMachine->start(); stateMachine->start();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
} }
@ -40,6 +60,7 @@ QtMaterialDrawer::QtMaterialDrawer(QWidget *parent)
: QtMaterialOverlayWidget(parent), : QtMaterialOverlayWidget(parent),
d_ptr(new QtMaterialDrawerPrivate(this)) d_ptr(new QtMaterialDrawerPrivate(this))
{ {
d_func()->init();
} }
QtMaterialDrawer::~QtMaterialDrawer() QtMaterialDrawer::~QtMaterialDrawer()
@ -90,12 +111,29 @@ bool QtMaterialDrawer::clickOutsideToClose() const
return d->clickToClose; return d->clickToClose;
} }
void QtMaterialDrawer::setAutoRaise(bool state)
{
Q_D(QtMaterialDrawer);
d->autoRaise = state;
}
bool QtMaterialDrawer::autoRaise() const
{
Q_D(const QtMaterialDrawer);
return d->autoRaise;
}
void QtMaterialDrawer::openDrawer() void QtMaterialDrawer::openDrawer()
{ {
Q_D(QtMaterialDrawer); Q_D(QtMaterialDrawer);
emit d->stateMachine->enterOpenedState(); emit d->stateMachine->enterOpenedState();
raise();
if (d->autoRaise) {
raise();
}
} }
void QtMaterialDrawer::closeDrawer() void QtMaterialDrawer::closeDrawer()

View File

@ -23,6 +23,9 @@ public:
void setClickOutsideToClose(bool state); void setClickOutsideToClose(bool state);
bool clickOutsideToClose() const; bool clickOutsideToClose() const;
void setAutoRaise(bool state);
bool autoRaise() const;
public slots: public slots:
void openDrawer(); void openDrawer();
void closeDrawer(); void closeDrawer();

View File

@ -13,12 +13,16 @@ class QtMaterialDrawerPrivate
public: public:
QtMaterialDrawerPrivate(QtMaterialDrawer *q); QtMaterialDrawerPrivate(QtMaterialDrawer *q);
~QtMaterialDrawerPrivate();
void init();
QtMaterialDrawer *const q_ptr; QtMaterialDrawer *const q_ptr;
QtMaterialDrawerStateMachine *const stateMachine; QtMaterialDrawerStateMachine *stateMachine;
QWidget *const window; QWidget *window;
int width; int width;
bool clickToClose; bool clickToClose;
bool autoRaise;
}; };
#endif // DRAWER_P_H #endif // DRAWER_P_H