Fix Drawer peculiarities

This commit is contained in:
johanneshilden 2017-10-12 22:10:43 +03:00
parent f72cb03f0b
commit 62108fd5b7
2 changed files with 29 additions and 13 deletions

View File

@ -54,9 +54,6 @@ void QtMaterialDrawerPrivate::init()
widget->setParent(q); widget->setParent(q);
q->setAttribute(Qt::WA_TransparentForMouseEvents);
q->setAttribute(Qt::WA_NoSystemBackground);
stateMachine->start(); stateMachine->start();
QCoreApplication::processEvents(); QCoreApplication::processEvents();
} }
@ -157,10 +154,8 @@ void QtMaterialDrawer::openDrawer()
if (d->autoRaise) { if (d->autoRaise) {
raise(); raise();
} }
if (d->overlay) { setAttribute(Qt::WA_TransparentForMouseEvents, false);
setAttribute(Qt::WA_TransparentForMouseEvents, false); setAttribute(Qt::WA_NoSystemBackground, false);
setAttribute(Qt::WA_NoSystemBackground, false);
}
} }
void QtMaterialDrawer::closeDrawer() void QtMaterialDrawer::closeDrawer()
@ -169,8 +164,28 @@ void QtMaterialDrawer::closeDrawer()
emit d->stateMachine->signalClose(); emit d->stateMachine->signalClose();
setAttribute(Qt::WA_TransparentForMouseEvents); if (d->overlay) {
setAttribute(Qt::WA_NoSystemBackground); setAttribute(Qt::WA_TransparentForMouseEvents);
setAttribute(Qt::WA_NoSystemBackground);
}
}
bool QtMaterialDrawer::event(QEvent *event)
{
Q_D(QtMaterialDrawer);
switch (event->type())
{
case QEvent::Move:
case QEvent::Resize:
if (!d->overlay) {
setMask(QRegion(d->widget->rect()));
}
break;
default:
break;
}
return QtMaterialOverlayWidget::event(event);
} }
bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event) bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event)
@ -191,10 +206,11 @@ bool QtMaterialDrawer::eventFilter(QObject *obj, QEvent *event)
} }
case QEvent::Move: case QEvent::Move:
case QEvent::Resize: { case QEvent::Resize: {
QLayout *lout = d->widget->layout(); QLayout *lw = d->widget->layout();
if (lout && 16 != lout->contentsMargins().right()) { if (lw && 16 != lw->contentsMargins().right()) {
lout->setContentsMargins(0, 0, 16, 0); lw->setContentsMargins(0, 0, 16, 0);
} }
break;
} }
default: default:
break; break;
@ -211,7 +227,6 @@ void QtMaterialDrawer::paintEvent(QPaintEvent *event)
if (!d->overlay || d->stateMachine->isInClosedState()) { if (!d->overlay || d->stateMachine->isInClosedState()) {
return; return;
} }
QPainter painter(this); QPainter painter(this);
painter.setOpacity(d->stateMachine->opacity()); painter.setOpacity(d->stateMachine->opacity());
painter.fillRect(rect(), Qt::SolidPattern); painter.fillRect(rect(), Qt::SolidPattern);

View File

@ -34,6 +34,7 @@ public slots:
void closeDrawer(); void closeDrawer();
protected: protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
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;