Dialog moved
This commit is contained in:
parent
336b50e2ad
commit
597ad493fb
|
@ -9,29 +9,31 @@
|
|||
#include <QPainter>
|
||||
#include "qtmaterialdialog_internal.h"
|
||||
#include "lib/qtmaterialstatetransition.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
/*!
|
||||
* \class QtMaterialDialogPrivate
|
||||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialDialogPrivate::QtMaterialDialogPrivate(QtMaterialDialog *q)
|
||||
DialogPrivate::DialogPrivate(Dialog *q)
|
||||
: q_ptr(q)
|
||||
{
|
||||
}
|
||||
|
||||
QtMaterialDialogPrivate::~QtMaterialDialogPrivate()
|
||||
DialogPrivate::~DialogPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialDialogPrivate::init()
|
||||
void DialogPrivate::init()
|
||||
{
|
||||
Q_Q(QtMaterialDialog);
|
||||
Q_Q(Dialog);
|
||||
|
||||
dialogWindow = new QtMaterialDialogWindow(q);
|
||||
dialogWindow = new DialogWindow(q);
|
||||
proxyStack = new QStackedLayout;
|
||||
stateMachine = new QStateMachine(q);
|
||||
proxy = new QtMaterialDialogProxy(dialogWindow, proxyStack, q);
|
||||
proxy = new DialogProxy(dialogWindow, proxyStack, q);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout;
|
||||
q->setLayout(layout);
|
||||
|
@ -62,13 +64,13 @@ void QtMaterialDialogPrivate::init()
|
|||
stateMachine->addState(visibleState);
|
||||
stateMachine->setInitialState(hiddenState);
|
||||
|
||||
QtMaterialStateTransition *transition;
|
||||
StateTransition *transition;
|
||||
|
||||
transition = new QtMaterialStateTransition(DialogShowTransition);
|
||||
transition = new StateTransition(DialogShowTransition);
|
||||
transition->setTargetState(visibleState);
|
||||
hiddenState->addTransition(transition);
|
||||
|
||||
transition = new QtMaterialStateTransition(DialogHideTransition);
|
||||
transition = new StateTransition(DialogHideTransition);
|
||||
transition->setTargetState(hiddenState);
|
||||
visibleState->addTransition(transition);
|
||||
|
||||
|
@ -107,53 +109,53 @@ void QtMaterialDialogPrivate::init()
|
|||
* \class QtMaterialDialog
|
||||
*/
|
||||
|
||||
QtMaterialDialog::QtMaterialDialog(QWidget *parent)
|
||||
: QtMaterialOverlayWidget(parent),
|
||||
d_ptr(new QtMaterialDialogPrivate(this))
|
||||
Dialog::Dialog(QWidget *parent)
|
||||
: OverlayWidget(parent),
|
||||
d_ptr(new DialogPrivate(this))
|
||||
{
|
||||
d_func()->init();
|
||||
}
|
||||
|
||||
QtMaterialDialog::~QtMaterialDialog()
|
||||
Dialog::~Dialog()
|
||||
{
|
||||
}
|
||||
|
||||
QLayout *QtMaterialDialog::windowLayout() const
|
||||
QLayout *Dialog::windowLayout() const
|
||||
{
|
||||
Q_D(const QtMaterialDialog);
|
||||
Q_D(const Dialog);
|
||||
|
||||
return d->dialogWindow->layout();
|
||||
}
|
||||
|
||||
void QtMaterialDialog::setWindowLayout(QLayout *layout)
|
||||
void Dialog::setWindowLayout(QLayout *layout)
|
||||
{
|
||||
Q_D(QtMaterialDialog);
|
||||
Q_D(Dialog);
|
||||
|
||||
d->dialogWindow->setLayout(layout);
|
||||
}
|
||||
|
||||
void QtMaterialDialog::showDialog()
|
||||
void Dialog::showDialog()
|
||||
{
|
||||
Q_D(QtMaterialDialog);
|
||||
Q_D(Dialog);
|
||||
|
||||
d->stateMachine->postEvent(new QtMaterialStateTransitionEvent(DialogShowTransition));
|
||||
d->stateMachine->postEvent(new StateTransitionEvent(DialogShowTransition));
|
||||
raise();
|
||||
}
|
||||
|
||||
void QtMaterialDialog::hideDialog()
|
||||
void Dialog::hideDialog()
|
||||
{
|
||||
Q_D(QtMaterialDialog);
|
||||
Q_D(Dialog);
|
||||
|
||||
d->stateMachine->postEvent(new QtMaterialStateTransitionEvent(DialogHideTransition));
|
||||
d->stateMachine->postEvent(new StateTransitionEvent(DialogHideTransition));
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
d->proxyStack->setCurrentIndex(1);
|
||||
}
|
||||
|
||||
void QtMaterialDialog::paintEvent(QPaintEvent *event)
|
||||
void Dialog::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
Q_D(QtMaterialDialog);
|
||||
Q_D(Dialog);
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
|
@ -165,3 +167,4 @@ void QtMaterialDialog::paintEvent(QPaintEvent *event)
|
|||
painter.setOpacity(d->proxy->opacity()/2.4);
|
||||
painter.drawRect(rect());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,17 +3,19 @@
|
|||
|
||||
#include <QScopedPointer>
|
||||
#include "lib/qtmaterialoverlaywidget.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QLayout;
|
||||
class QtMaterialDialogPrivate;
|
||||
class DialogPrivate;
|
||||
|
||||
class QtMaterialDialog : public QtMaterialOverlayWidget
|
||||
class Dialog : public OverlayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QtMaterialDialog(QWidget *parent = 0);
|
||||
~QtMaterialDialog();
|
||||
explicit Dialog(QWidget *parent = 0);
|
||||
~Dialog();
|
||||
|
||||
QLayout *windowLayout() const;
|
||||
void setWindowLayout(QLayout *layout);
|
||||
|
@ -25,11 +27,11 @@ public slots:
|
|||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
const QScopedPointer<QtMaterialDialogPrivate> d_ptr;
|
||||
const QScopedPointer<DialogPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialDialog)
|
||||
Q_DECLARE_PRIVATE(QtMaterialDialog)
|
||||
Q_DISABLE_COPY(Dialog)
|
||||
Q_DECLARE_PRIVATE(Dialog)
|
||||
};
|
||||
|
||||
}
|
||||
#endif // QTMATERIALDIALOG_H
|
||||
|
|
|
@ -4,16 +4,18 @@
|
|||
#include <QEvent>
|
||||
#include <QtWidgets/QStackedLayout>
|
||||
#include "qtmaterialdialog.h"
|
||||
namespace md
|
||||
{
|
||||
|
||||
/*!
|
||||
* \class QtMaterialDialogProxy
|
||||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialDialogProxy::QtMaterialDialogProxy(
|
||||
QtMaterialDialogWindow *source,
|
||||
DialogProxy::DialogProxy(
|
||||
DialogWindow *source,
|
||||
QStackedLayout *layout,
|
||||
QtMaterialDialog *dialog,
|
||||
Dialog *dialog,
|
||||
QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_source(source),
|
||||
|
@ -24,11 +26,11 @@ QtMaterialDialogProxy::QtMaterialDialogProxy(
|
|||
{
|
||||
}
|
||||
|
||||
QtMaterialDialogProxy::~QtMaterialDialogProxy()
|
||||
DialogProxy::~DialogProxy()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialDialogProxy::setOpacity(qreal opacity)
|
||||
void DialogProxy::setOpacity(qreal opacity)
|
||||
{
|
||||
m_opacity = opacity;
|
||||
m_mode = SemiTransparent;
|
||||
|
@ -37,7 +39,7 @@ void QtMaterialDialogProxy::setOpacity(qreal opacity)
|
|||
}
|
||||
|
||||
|
||||
void QtMaterialDialogProxy::makeOpaque()
|
||||
void DialogProxy::makeOpaque()
|
||||
{
|
||||
m_dialog->setAttribute(Qt::WA_TransparentForMouseEvents, false);
|
||||
m_layout->setCurrentIndex(0);
|
||||
|
@ -46,19 +48,19 @@ void QtMaterialDialogProxy::makeOpaque()
|
|||
update();
|
||||
}
|
||||
|
||||
void QtMaterialDialogProxy::makeTransparent()
|
||||
void DialogProxy::makeTransparent()
|
||||
{
|
||||
m_opacity = 0.0;
|
||||
m_mode = Transparent;
|
||||
update();
|
||||
}
|
||||
|
||||
QSize QtMaterialDialogProxy::sizeHint() const
|
||||
QSize DialogProxy::sizeHint() const
|
||||
{
|
||||
return m_source->sizeHint();
|
||||
}
|
||||
|
||||
bool QtMaterialDialogProxy::event(QEvent *event)
|
||||
bool DialogProxy::event(QEvent *event)
|
||||
{
|
||||
const QEvent::Type type = event->type();
|
||||
|
||||
|
@ -68,7 +70,7 @@ bool QtMaterialDialogProxy::event(QEvent *event)
|
|||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
void QtMaterialDialogProxy::paintEvent(QPaintEvent *event)
|
||||
void DialogProxy::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
|
@ -88,31 +90,31 @@ void QtMaterialDialogProxy::paintEvent(QPaintEvent *event)
|
|||
* \internal
|
||||
*/
|
||||
|
||||
QtMaterialDialogWindow::QtMaterialDialogWindow(
|
||||
QtMaterialDialog *dialog,
|
||||
DialogWindow::DialogWindow(
|
||||
Dialog *dialog,
|
||||
QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_dialog(dialog)
|
||||
{
|
||||
}
|
||||
|
||||
QtMaterialDialogWindow::~QtMaterialDialogWindow()
|
||||
DialogWindow::~DialogWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void QtMaterialDialogWindow::setOffset(int offset)
|
||||
void DialogWindow::setOffset(int offset)
|
||||
{
|
||||
QMargins margins = m_dialog->layout()->contentsMargins();
|
||||
margins.setBottom(offset);
|
||||
m_dialog->layout()->setContentsMargins(margins);
|
||||
}
|
||||
|
||||
int QtMaterialDialogWindow::offset() const
|
||||
int DialogWindow::offset() const
|
||||
{
|
||||
return m_dialog->layout()->contentsMargins().bottom();
|
||||
}
|
||||
|
||||
void QtMaterialDialogWindow::paintEvent(QPaintEvent *event)
|
||||
void DialogWindow::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
|
@ -125,3 +127,5 @@ void QtMaterialDialogWindow::paintEvent(QPaintEvent *event)
|
|||
painter.setBrush(brush);
|
||||
painter.drawRect(rect());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
#define QTMATERIALDIALOG_INTERNAL_H
|
||||
|
||||
#include <QtWidgets/QWidget>
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QStackedLayout;
|
||||
class QtMaterialDialog;
|
||||
class QtMaterialDialogWindow;
|
||||
class Dialog;
|
||||
class DialogWindow;
|
||||
|
||||
class QtMaterialDialogProxy : public QWidget
|
||||
class DialogProxy : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -20,11 +22,11 @@ class QtMaterialDialogProxy : public QWidget
|
|||
};
|
||||
|
||||
public:
|
||||
QtMaterialDialogProxy(QtMaterialDialogWindow *source,
|
||||
DialogProxy(DialogWindow *source,
|
||||
QStackedLayout *layout,
|
||||
QtMaterialDialog *dialog,
|
||||
Dialog *dialog,
|
||||
QWidget *parent = 0);
|
||||
~QtMaterialDialogProxy();
|
||||
~DialogProxy();
|
||||
|
||||
void setOpacity(qreal opacity);
|
||||
inline qreal opacity() const;
|
||||
|
@ -40,29 +42,29 @@ protected:
|
|||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialDialogProxy)
|
||||
Q_DISABLE_COPY(DialogProxy)
|
||||
|
||||
QtMaterialDialogWindow *const m_source;
|
||||
DialogWindow *const m_source;
|
||||
QStackedLayout *const m_layout;
|
||||
QtMaterialDialog *const m_dialog;
|
||||
Dialog *const m_dialog;
|
||||
qreal m_opacity;
|
||||
TransparencyMode m_mode;
|
||||
};
|
||||
|
||||
inline qreal QtMaterialDialogProxy::opacity() const
|
||||
inline qreal DialogProxy::opacity() const
|
||||
{
|
||||
return m_opacity;
|
||||
}
|
||||
|
||||
class QtMaterialDialogWindow : public QWidget
|
||||
class DialogWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int offset WRITE setOffset READ offset)
|
||||
|
||||
public:
|
||||
explicit QtMaterialDialogWindow(QtMaterialDialog *dialog, QWidget *parent = 0);
|
||||
~QtMaterialDialogWindow();
|
||||
explicit DialogWindow(Dialog *dialog, QWidget *parent = 0);
|
||||
~DialogWindow();
|
||||
|
||||
void setOffset(int offset);
|
||||
int offset() const;
|
||||
|
@ -71,9 +73,10 @@ protected:
|
|||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(QtMaterialDialogWindow)
|
||||
Q_DISABLE_COPY(DialogWindow)
|
||||
|
||||
QtMaterialDialog *const m_dialog;
|
||||
Dialog *const m_dialog;
|
||||
};
|
||||
|
||||
#endif // QTMATERIALDIALOG_INTERNAL_H
|
||||
}
|
||||
|
|
|
@ -2,29 +2,31 @@
|
|||
#define QTMATERIALDIALOG_P_H
|
||||
|
||||
#include <QtGlobal>
|
||||
namespace md
|
||||
{
|
||||
|
||||
class QStateMachine;
|
||||
class QtMaterialDialog;
|
||||
class Dialog;
|
||||
class QStackedLayout;
|
||||
class QtMaterialDialogWindow;
|
||||
class QtMaterialDialogProxy;
|
||||
class DialogWindow;
|
||||
class DialogProxy;
|
||||
|
||||
class QtMaterialDialogPrivate
|
||||
class DialogPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(QtMaterialDialogPrivate)
|
||||
Q_DECLARE_PUBLIC(QtMaterialDialog)
|
||||
Q_DISABLE_COPY(DialogPrivate)
|
||||
Q_DECLARE_PUBLIC(Dialog)
|
||||
|
||||
public:
|
||||
QtMaterialDialogPrivate(QtMaterialDialog *q);
|
||||
~QtMaterialDialogPrivate();
|
||||
DialogPrivate(Dialog *q);
|
||||
~DialogPrivate();
|
||||
|
||||
void init();
|
||||
|
||||
QtMaterialDialog *const q_ptr;
|
||||
QtMaterialDialogWindow *dialogWindow;
|
||||
Dialog *const q_ptr;
|
||||
DialogWindow *dialogWindow;
|
||||
QStackedLayout *proxyStack;
|
||||
QStateMachine *stateMachine;
|
||||
QtMaterialDialogProxy *proxy;
|
||||
DialogProxy *proxy;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // QTMATERIALDIALOG_P_H
|
||||
|
|
Loading…
Reference in New Issue