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