add Dialog boilerplate code
This commit is contained in:
parent
d2c3f904db
commit
4956b2720a
|
@ -1,8 +1,8 @@
|
|||
#include "avatar_p.h"
|
||||
#include "avatar.h"
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
#include "avatar.h"
|
||||
#include "avatar_p.h"
|
||||
#include "lib/style.h"
|
||||
|
||||
AvatarPrivate::AvatarPrivate(Avatar *q)
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#define AVATAR_P_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
#include <QIcon>
|
||||
#include <QPixmap>
|
||||
#include "lib/theme.h"
|
||||
|
||||
class Avatar;
|
||||
|
|
|
@ -1,10 +1,85 @@
|
|||
#include "dialog_p.h"
|
||||
#include "dialog.h"
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
#include "dialog_internal.h"
|
||||
|
||||
DialogPrivate::DialogPrivate(Dialog *q)
|
||||
: q_ptr(q)
|
||||
{
|
||||
}
|
||||
|
||||
void DialogPrivate::init()
|
||||
{
|
||||
Q_Q(Dialog);
|
||||
|
||||
DialogWindow *window = new DialogWindow(q);
|
||||
}
|
||||
|
||||
Dialog::Dialog(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
d_ptr(new DialogPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
Dialog::~Dialog()
|
||||
{
|
||||
}
|
||||
|
||||
bool Dialog::event(QEvent *event)
|
||||
{
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::ParentChange:
|
||||
{
|
||||
if (!parent())
|
||||
break;
|
||||
|
||||
parent()->installEventFilter(this);
|
||||
|
||||
QWidget *widget;
|
||||
if ((widget = parentWidget())) {
|
||||
setGeometry(widget->rect());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::ParentAboutToChange:
|
||||
{
|
||||
if (!parent())
|
||||
break;
|
||||
|
||||
parent()->removeEventFilter(this);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QWidget::event(event);
|
||||
}
|
||||
|
||||
bool Dialog::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
QEvent::Type type = event->type();
|
||||
|
||||
if (QEvent::Move == type || QEvent::Resize == type)
|
||||
{
|
||||
QWidget *widget;
|
||||
if ((widget = parentWidget())) {
|
||||
setGeometry(widget->rect());
|
||||
}
|
||||
}
|
||||
return QWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void Dialog::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(4);
|
||||
painter.setPen(pen);
|
||||
|
||||
painter.drawRect(rect());
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <QWidget>
|
||||
|
||||
class DialogPrivate;
|
||||
|
||||
class Dialog : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -11,9 +13,16 @@ public:
|
|||
explicit Dialog(QWidget *parent = 0);
|
||||
~Dialog();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) Q_DECL_OVERRIDE;
|
||||
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
const QScopedPointer<DialogPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(Dialog)
|
||||
//Q_DECLARE_PRIVATE(Dialog)
|
||||
Q_DECLARE_PRIVATE(Dialog)
|
||||
};
|
||||
|
||||
#endif // DIALOG_H
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#include "dialog_internal.h"
|
||||
#include <QPainter>
|
||||
#include "dialog.h"
|
||||
|
||||
DialogWindow::DialogWindow(Dialog *parent)
|
||||
: QWidget(parent),
|
||||
dialog(parent)
|
||||
{
|
||||
}
|
||||
|
||||
DialogWindow::~DialogWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void DialogWindow::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QPainter painter(this);
|
||||
|
||||
QBrush brush;
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
brush.setColor(Qt::white);
|
||||
|
||||
painter.setBrush(brush);
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
QRectF r(0, 0, 200, 200);
|
||||
r.moveCenter(rect().center());
|
||||
|
||||
painter.drawRect(r);
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef DIALOG_INTERNAL_H
|
||||
#define DIALOG_INTERNAL_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class Dialog;
|
||||
|
||||
class DialogWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DialogWindow(Dialog *parent);
|
||||
~DialogWindow();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogWindow)
|
||||
|
||||
Dialog *const dialog;
|
||||
};
|
||||
|
||||
#endif // DIALOG_INTERNAL_H
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef DIALOG_P_H
|
||||
#define DIALOG_P_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Dialog;
|
||||
class DialogWindow;
|
||||
|
||||
class DialogPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(DialogPrivate)
|
||||
Q_DECLARE_PUBLIC(Dialog)
|
||||
|
||||
public:
|
||||
DialogPrivate(Dialog *q);
|
||||
|
||||
void init();
|
||||
|
||||
Dialog *const q_ptr;
|
||||
DialogWindow *window;
|
||||
};
|
||||
|
||||
#endif // DIALOG_P_H
|
|
@ -23,6 +23,7 @@
|
|||
#include "examples/iconmenuexamples.h"
|
||||
#include "components/fab.h"
|
||||
#include "components/snackbar.h"
|
||||
#include "components/dialog.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
|
@ -78,6 +79,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
btn->setParent(this);
|
||||
|
||||
connect(btn, SIGNAL(pressed()), this, SLOT(addInstantMsg()));
|
||||
|
||||
//
|
||||
|
||||
Dialog *dialog = new Dialog;
|
||||
dialog->setParent(this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
|
|
@ -69,7 +69,8 @@ SOURCES += main.cpp\
|
|||
components/circularprogress_internal.cpp \
|
||||
components/progress_internal.cpp \
|
||||
components/scrollwidget.cpp \
|
||||
components/scrollwidget_internal.cpp
|
||||
components/scrollwidget_internal.cpp \
|
||||
components/dialog_internal.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
components/appbar.h \
|
||||
|
@ -150,7 +151,9 @@ HEADERS += mainwindow.h \
|
|||
components/progress_internal.h \
|
||||
components/scrollwidget_p.h \
|
||||
components/scrollwidget.h \
|
||||
components/scrollwidget_internal.h
|
||||
components/scrollwidget_internal.h \
|
||||
components/dialog_p.h \
|
||||
components/dialog_internal.h
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
|
Loading…
Reference in New Issue