Add getContentWidget
This commit is contained in:
parent
7beeadccf6
commit
c729b34716
|
@ -2,6 +2,7 @@
|
||||||
#define QTMATERIALDIALOG_H
|
#define QTMATERIALDIALOG_H
|
||||||
|
|
||||||
#include <QScopedPointer>
|
#include <QScopedPointer>
|
||||||
|
#include <qwidget.h>
|
||||||
|
|
||||||
#include "qt-material-widgets/lib/qtmaterialoverlaywidget.h"
|
#include "qt-material-widgets/lib/qtmaterialoverlaywidget.h"
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ public:
|
||||||
|
|
||||||
QLayout *windowLayout() const;
|
QLayout *windowLayout() const;
|
||||||
void setWindowLayout(QLayout *layout);
|
void setWindowLayout(QLayout *layout);
|
||||||
|
QWidget* getContentWidget() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showDialog();
|
void showDialog();
|
||||||
|
@ -34,4 +36,5 @@ private:
|
||||||
Q_DECLARE_PRIVATE(QtMaterialDialog)
|
Q_DECLARE_PRIVATE(QtMaterialDialog)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // QTMATERIALDIALOG_H
|
#endif // QTMATERIALDIALOG_H
|
||||||
|
|
|
@ -1,167 +1,177 @@
|
||||||
#include "qtmaterialdialog.h"
|
|
||||||
#include "qtmaterialdialog_p.h"
|
|
||||||
#include <QtWidgets/QStackedLayout>
|
|
||||||
#include <QtWidgets/QGraphicsDropShadowEffect>
|
|
||||||
#include <QStateMachine>
|
|
||||||
#include <QState>
|
|
||||||
#include <QtWidgets/QApplication>
|
|
||||||
#include <QPropertyAnimation>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "qtmaterialdialog_internal.h"
|
#include <QPropertyAnimation>
|
||||||
|
#include <QState>
|
||||||
|
#include <QStateMachine>
|
||||||
|
|
||||||
|
#include "qtmaterialdialog.h"
|
||||||
|
|
||||||
|
#include <QtWidgets/QApplication>
|
||||||
|
#include <QtWidgets/QGraphicsDropShadowEffect>
|
||||||
|
#include <QtWidgets/QStackedLayout>
|
||||||
|
|
||||||
#include "lib/qtmaterialstatetransition.h"
|
#include "lib/qtmaterialstatetransition.h"
|
||||||
|
#include "qtmaterialdialog_internal.h"
|
||||||
|
#include "qtmaterialdialog_p.h"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialDialogPrivate
|
* \class QtMaterialDialogPrivate
|
||||||
* \internal
|
* \internal
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialDialogPrivate::QtMaterialDialogPrivate(QtMaterialDialog *q)
|
QtMaterialDialogPrivate::QtMaterialDialogPrivate(QtMaterialDialog* q)
|
||||||
: q_ptr(q)
|
: q_ptr(q)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialDialogPrivate::~QtMaterialDialogPrivate()
|
QtMaterialDialogPrivate::~QtMaterialDialogPrivate() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtMaterialDialogPrivate::init()
|
void QtMaterialDialogPrivate::init()
|
||||||
{
|
{
|
||||||
Q_Q(QtMaterialDialog);
|
Q_Q(QtMaterialDialog);
|
||||||
|
|
||||||
dialogWindow = new QtMaterialDialogWindow(q);
|
dialogWindow = new QtMaterialDialogWindow(q);
|
||||||
proxyStack = new QStackedLayout;
|
proxyStack = new QStackedLayout;
|
||||||
stateMachine = new QStateMachine(q);
|
stateMachine = new QStateMachine(q);
|
||||||
proxy = new QtMaterialDialogProxy(dialogWindow, proxyStack, q);
|
proxy = new QtMaterialDialogProxy(dialogWindow, proxyStack, q);
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout* layout = new QVBoxLayout;
|
||||||
q->setLayout(layout);
|
q->setLayout(layout);
|
||||||
|
|
||||||
QWidget *widget = new QWidget;
|
QWidget* widget = new QWidget;
|
||||||
widget->setLayout(proxyStack);
|
widget->setLayout(proxyStack);
|
||||||
widget->setMinimumWidth(400);
|
widget->setMinimumWidth(400);
|
||||||
|
|
||||||
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
|
QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect;
|
||||||
effect->setColor(QColor(0, 0, 0, 200));
|
effect->setColor(QColor(0, 0, 0, 200));
|
||||||
effect->setBlurRadius(64);
|
effect->setBlurRadius(64);
|
||||||
effect->setOffset(0, 13);
|
effect->setOffset(0, 13);
|
||||||
widget->setGraphicsEffect(effect);
|
widget->setGraphicsEffect(effect);
|
||||||
|
|
||||||
layout->addWidget(widget);
|
layout->addWidget(widget);
|
||||||
layout->setAlignment(widget, Qt::AlignCenter);
|
layout->setAlignment(widget, Qt::AlignCenter);
|
||||||
|
|
||||||
proxyStack->addWidget(dialogWindow);
|
proxyStack->addWidget(dialogWindow);
|
||||||
proxyStack->addWidget(proxy);
|
proxyStack->addWidget(proxy);
|
||||||
proxyStack->setCurrentIndex(1);
|
proxyStack->setCurrentIndex(1);
|
||||||
|
|
||||||
q->setAttribute(Qt::WA_TransparentForMouseEvents);
|
q->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
|
||||||
QState *hiddenState = new QState;
|
QState* hiddenState = new QState;
|
||||||
QState *visibleState = new QState;
|
QState* visibleState = new QState;
|
||||||
|
|
||||||
stateMachine->addState(hiddenState);
|
stateMachine->addState(hiddenState);
|
||||||
stateMachine->addState(visibleState);
|
stateMachine->addState(visibleState);
|
||||||
stateMachine->setInitialState(hiddenState);
|
stateMachine->setInitialState(hiddenState);
|
||||||
|
|
||||||
QtMaterialStateTransition *transition;
|
QtMaterialStateTransition* transition;
|
||||||
|
|
||||||
transition = new QtMaterialStateTransition(DialogShowTransition);
|
transition = new QtMaterialStateTransition(DialogShowTransition);
|
||||||
transition->setTargetState(visibleState);
|
transition->setTargetState(visibleState);
|
||||||
hiddenState->addTransition(transition);
|
hiddenState->addTransition(transition);
|
||||||
|
|
||||||
transition = new QtMaterialStateTransition(DialogHideTransition);
|
transition = new QtMaterialStateTransition(DialogHideTransition);
|
||||||
transition->setTargetState(hiddenState);
|
transition->setTargetState(hiddenState);
|
||||||
visibleState->addTransition(transition);
|
visibleState->addTransition(transition);
|
||||||
|
|
||||||
visibleState->assignProperty(proxy, "opacity", 1);
|
visibleState->assignProperty(proxy, "opacity", 1);
|
||||||
visibleState->assignProperty(effect, "color", QColor(0, 0, 0, 200));
|
visibleState->assignProperty(effect, "color", QColor(0, 0, 0, 200));
|
||||||
visibleState->assignProperty(dialogWindow, "offset", 0);
|
visibleState->assignProperty(dialogWindow, "offset", 0);
|
||||||
hiddenState->assignProperty(proxy, "opacity", 0);
|
hiddenState->assignProperty(proxy, "opacity", 0);
|
||||||
hiddenState->assignProperty(effect, "color", QColor(0, 0, 0, 0));
|
hiddenState->assignProperty(effect, "color", QColor(0, 0, 0, 0));
|
||||||
hiddenState->assignProperty(dialogWindow, "offset", 200);
|
hiddenState->assignProperty(dialogWindow, "offset", 200);
|
||||||
|
|
||||||
QPropertyAnimation *animation;
|
QPropertyAnimation* animation;
|
||||||
|
|
||||||
animation = new QPropertyAnimation(proxy, "opacity", q);
|
animation = new QPropertyAnimation(proxy, "opacity", q);
|
||||||
animation->setDuration(280);
|
animation->setDuration(280);
|
||||||
stateMachine->addDefaultAnimation(animation);
|
stateMachine->addDefaultAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(effect, "color", q);
|
animation = new QPropertyAnimation(effect, "color", q);
|
||||||
animation->setDuration(280);
|
animation->setDuration(280);
|
||||||
stateMachine->addDefaultAnimation(animation);
|
stateMachine->addDefaultAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation(dialogWindow, "offset", q);
|
animation = new QPropertyAnimation(dialogWindow, "offset", q);
|
||||||
animation->setDuration(280);
|
animation->setDuration(280);
|
||||||
animation->setEasingCurve(QEasingCurve::OutCirc);
|
animation->setEasingCurve(QEasingCurve::OutCirc);
|
||||||
stateMachine->addDefaultAnimation(animation);
|
stateMachine->addDefaultAnimation(animation);
|
||||||
|
|
||||||
QObject::connect(visibleState, SIGNAL(propertiesAssigned()),
|
QObject::connect(
|
||||||
proxy, SLOT(makeOpaque()));
|
visibleState, SIGNAL(propertiesAssigned()), proxy, SLOT(makeOpaque()));
|
||||||
QObject::connect(hiddenState, SIGNAL(propertiesAssigned()),
|
QObject::connect(hiddenState,
|
||||||
proxy, SLOT(makeTransparent()));
|
SIGNAL(propertiesAssigned()),
|
||||||
|
proxy,
|
||||||
|
SLOT(makeTransparent()));
|
||||||
|
|
||||||
stateMachine->start();
|
stateMachine->start();
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \class QtMaterialDialog
|
* \class QtMaterialDialog
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QtMaterialDialog::QtMaterialDialog(QWidget *parent)
|
QtMaterialDialog::QtMaterialDialog(QWidget* parent)
|
||||||
: QtMaterialOverlayWidget(parent),
|
: QtMaterialOverlayWidget(parent)
|
||||||
d_ptr(new QtMaterialDialogPrivate(this))
|
, d_ptr(new QtMaterialDialogPrivate(this))
|
||||||
{
|
{
|
||||||
d_func()->init();
|
d_func()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMaterialDialog::~QtMaterialDialog()
|
QtMaterialDialog::~QtMaterialDialog() {}
|
||||||
|
|
||||||
|
QLayout* QtMaterialDialog::windowLayout() const
|
||||||
{
|
{
|
||||||
|
Q_D(const QtMaterialDialog);
|
||||||
|
|
||||||
|
return d->dialogWindow->layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
QLayout *QtMaterialDialog::windowLayout() const
|
QWidget* QtMaterialDialog::getContentWidget() const
|
||||||
{
|
{
|
||||||
Q_D(const QtMaterialDialog);
|
Q_D(const QtMaterialDialog);
|
||||||
|
|
||||||
return d->dialogWindow->layout();
|
return d->dialogWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialDialog::setWindowLayout(QLayout *layout)
|
void QtMaterialDialog::setWindowLayout(QLayout* layout)
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialDialog);
|
Q_D(QtMaterialDialog);
|
||||||
|
|
||||||
d->dialogWindow->setLayout(layout);
|
d->dialogWindow->setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialDialog::showDialog()
|
void QtMaterialDialog::showDialog()
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialDialog);
|
Q_D(QtMaterialDialog);
|
||||||
|
|
||||||
d->stateMachine->postEvent(new QtMaterialStateTransitionEvent(DialogShowTransition));
|
d->stateMachine->postEvent(
|
||||||
raise();
|
new QtMaterialStateTransitionEvent(DialogShowTransition));
|
||||||
|
raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialDialog::hideDialog()
|
void QtMaterialDialog::hideDialog()
|
||||||
{
|
{
|
||||||
Q_D(QtMaterialDialog);
|
Q_D(QtMaterialDialog);
|
||||||
|
|
||||||
d->stateMachine->postEvent(new QtMaterialStateTransitionEvent(DialogHideTransition));
|
d->stateMachine->postEvent(
|
||||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
new QtMaterialStateTransitionEvent(DialogHideTransition));
|
||||||
d->proxyStack->setCurrentIndex(1);
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
d->proxyStack->setCurrentIndex(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMaterialDialog::paintEvent(QPaintEvent *event)
|
void QtMaterialDialog::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
Q_D(QtMaterialDialog);
|
Q_D(QtMaterialDialog);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
QBrush brush;
|
QBrush brush;
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
brush.setColor(Qt::black);
|
brush.setColor(Qt::black);
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.setOpacity(d->proxy->opacity()/2.4);
|
painter.setOpacity(d->proxy->opacity() / 2.4);
|
||||||
painter.drawRect(rect());
|
painter.drawRect(rect());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue