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