diff --git a/components/dialog.cpp b/components/dialog.cpp index fdc3265..e707391 100644 --- a/components/dialog.cpp +++ b/components/dialog.cpp @@ -1,7 +1,10 @@ #include "dialog.h" #include "dialog_p.h" -#include #include +#include +#include +#include +#include "lib/transparencyproxy.h" #include "dialog_internal.h" DialogPrivate::DialogPrivate(Dialog *q) @@ -13,19 +16,117 @@ void DialogPrivate::init() { Q_Q(Dialog); - DialogWindow *window = new DialogWindow(q); + QVBoxLayout *layout = new QVBoxLayout; + q->setLayout(layout); + + QWidget *widget = new QWidget; + + proxy = new TransparencyProxy; + widget->setLayout(proxy); + layout->addWidget(widget); + layout->setAlignment(widget, Qt::AlignCenter); + + widget->setMinimumWidth(400); + widget->setMinimumHeight(400); + + window = new DialogWindow(q); + proxy->setWidget(window); + + QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; + effect->setColor(QColor(0, 0, 0, 200)); + effect->setBlurRadius(64); + effect->setOffset(0, 13); + widget->setGraphicsEffect(effect); + +/* + { + QVBoxLayout *layout = new QVBoxLayout; + window->setLayout(layout); + + QPushButton *button = new QPushButton; + button->setText("Hello test!"); + layout->addWidget(button); + + button = new QPushButton; + button->setText("Hello test!"); + layout->addWidget(button); + + button = new QPushButton; + button->setText("Hello test!"); + layout->addWidget(button); + + button = new QPushButton; + button->setText("Hello test!"); + layout->addWidget(button); + + button = new QPushButton; + button->setText("Hello test!"); + layout->addWidget(button); + } + */ + + // + + proxy->setCurrentIndex(1); + + // + + + + QPushButton *btn; + + btn = new QPushButton; + btn->setText("One"); + layout->addWidget(btn); + + QObject::connect(btn, SIGNAL(pressed()), q, SLOT(pressOne())); + + btn = new QPushButton; + btn->setText("Two"); + layout->addWidget(btn); + + QObject::connect(btn, SIGNAL(pressed()), q, SLOT(pressTwo())); } Dialog::Dialog(QWidget *parent) : QWidget(parent), d_ptr(new DialogPrivate(this)) { + d_func()->init(); } Dialog::~Dialog() { } +QLayout *Dialog::windowLayout() const +{ + Q_D(const Dialog); + + return d->window->layout(); +} + +void Dialog::setWindowLayout(QLayout *layout) +{ + Q_D(Dialog); + + d->window->setLayout(layout); +} + +void Dialog::pressOne() +{ + Q_D(Dialog); + + d->proxy->setOpaque(); +} + +void Dialog::pressTwo() +{ + Q_D(Dialog); + + d->proxy->setOpacity(0.5); +} + bool Dialog::event(QEvent *event) { switch (event->type()) @@ -77,9 +178,256 @@ void Dialog::paintEvent(QPaintEvent *event) QPainter painter(this); - QPen pen; - pen.setWidth(4); - painter.setPen(pen); + //QPen pen; + //pen.setColor(Qt::blue); + //pen.setWidth(3); + //painter.setPen(pen); + + //painter.drawRect(rect()); + + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor(Qt::black); + painter.setBrush(brush); + painter.setPen(Qt::NoPen); + painter.setOpacity(0.5); painter.drawRect(rect()); } + +//#include "dialog.h" +//#include "dialog_p.h" +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include "lib/customshadoweffect.h" +//#include "dialog_internal.h" +// +//DialogPrivate::DialogPrivate(Dialog *q) +// : q_ptr(q) +//// window(new DialogWindow(q)), +//// shadow(new DialogShadow(q)) +//{ +//} +// +//void DialogPrivate::init() +//{ +// Q_Q(Dialog); +// +// QVBoxLayout *l = new QVBoxLayout; +// +// layout = new QStackedLayout; +// l->addLayout(layout); +// +// QPushButton *button = new QPushButton; +// button->setText("Hello test!"); +// layout->addWidget(button); +// +// proxy = new DialogProxy(q, button); +// layout->addWidget(proxy); +// +// //q->setLayout(layout); +// q->setLayout(l); +// +// layout->setCurrentIndex(1); +// +// button = new QPushButton; +// button->setText("one"); +// l->addWidget(button); +// +// QObject::connect(button, SIGNAL(pressed()), q, SLOT(pressOne())); +// +// button = new QPushButton; +// button->setText("two"); +// l->addWidget(button); +// +// QObject::connect(button, SIGNAL(pressed()), q, SLOT(pressTwo())); +// +// /* +// +// return; +// +// QVBoxLayout *layout = new QVBoxLayout; +// +// dialogWidget = new QWidget; +// dialogWidget->setLayout(layout); +// +// //q->setLayout(layout); +// +// layout->addWidget(window); +// layout->setAlignment(window, Qt::AlignCenter); +// +// window->setMinimumWidth(500); +// window->setMinimumHeight(500); +// +// shadow->setWindow(window); +// +// //window->setAttribute(Qt::WA_DontShowOnScreen); +// +// //QSizePolicy sp = window->sizePolicy(); +// //sp.setRetainSizeWhenHidden(true); +// //window->setSizePolicy(sp); +// +// //window->setHidden(true); +// +// //CustomShadowEffect *fx = new CustomShadowEffect; +// //fx->setBlurRadius(8); +// //fx->setColor(Qt::black); +// +// //window->setGraphicsEffect(fx); +// +// //QGraphicsOpacityEffect *opacity = new QGraphicsOpacityEffect; +// //opacity->setOpacity(1); +// //q->setGraphicsEffect(opacity); +// +// //QGraphicsBlurEffect *blur = new QGraphicsBlurEffect; +// //blur->setBlurRadius(32); +// //shadow->setGraphicsEffect(blur); +// +// QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; +// effect->setColor(QColor(0, 0, 0, 200)); +// effect->setBlurRadius(64); +// effect->setOffset(0, 13); +// window->setGraphicsEffect(effect); +// +// // QVBoxLayout *layout = new QVBoxLayout; +// // window->setLayout(layout); +// +//// QPushButton *button = new QPushButton; +//// button->setText("Hello test!"); +//// layout->addWidget(button); +//// +//// button = new QPushButton; +//// button->setText("Hello test!"); +//// layout->addWidget(button); +//// +//// button = new QPushButton; +//// button->setText("Hello test!"); +//// layout->addWidget(button); +//// +//// button = new QPushButton; +//// button->setText("Hello test!"); +//// layout->addWidget(button); +//// +//// button = new QPushButton; +//// button->setText("Hello test!"); +//// layout->addWidget(button); +// +// //window->setGeometry(0, 0, 500, 500); +// window->setFixedSize(500, 500); +// +// */ +//} +// +//Dialog::Dialog(QWidget *parent) +// : QWidget(parent), +// d_ptr(new DialogPrivate(this)) +//{ +// d_func()->init(); +//} +// +//Dialog::~Dialog() +//{ +//} +// +//void Dialog::pressOne() +//{ +// Q_D(Dialog); +// +// d->layout->setCurrentIndex(0); +//} +// +//void Dialog::pressTwo() +//{ +// Q_D(Dialog); +// +// d->layout->setCurrentIndex(1); +//} +// +////QWidget *Dialog::dialogWidget() const +////{ +//// Q_D(const Dialog); +//// +//// return d->dialogWidget; +////} +// +///* +//bool Dialog::event(QEvent *event) +//{ +// Q_D(Dialog); +// +// switch (event->type()) +// { +// case QEvent::ParentChange: +// { +// if (!parent()) +// break; +// +// parent()->installEventFilter(this); +// +// QWidget *widget; +// if ((widget = parentWidget())) { +// d->window->setParent(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); +// +// QBrush brush; +// brush.setStyle(Qt::SolidPattern); +// brush.setColor(Qt::black); +// painter.setBrush(brush); +// painter.setPen(Qt::NoPen); +// +// painter.setOpacity(0.5); +// +// painter.drawRect(rect()); +// +// //QPainter painter(this); +// +// //QPen pen; +// //pen.setWidth(12); +// //painter.setPen(pen); +// +// //painter.drawRect(rect()); +//} +// diff --git a/components/dialog.h b/components/dialog.h index 18229c8..2deecf6 100644 --- a/components/dialog.h +++ b/components/dialog.h @@ -13,6 +13,13 @@ public: explicit Dialog(QWidget *parent = 0); ~Dialog(); + QLayout *windowLayout() const; + void setWindowLayout(QLayout *layout); + +protected slots: + void pressOne(); + void pressTwo(); + protected: bool event(QEvent *event) Q_DECL_OVERRIDE; bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; @@ -25,4 +32,22 @@ private: Q_DECLARE_PRIVATE(Dialog) }; +// //QWidget *dialogWidget() const; +// +//protected slots: +// void pressOne(); +// void pressTwo(); +// +//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 d_ptr; +// +//private: +// Q_DISABLE_COPY(Dialog) +// Q_DECLARE_PRIVATE(Dialog) +//}; + #endif // DIALOG_H diff --git a/components/dialog_internal.cpp b/components/dialog_internal.cpp index 2e58b4f..0dc812a 100644 --- a/components/dialog_internal.cpp +++ b/components/dialog_internal.cpp @@ -2,9 +2,8 @@ #include #include "dialog.h" -DialogWindow::DialogWindow(Dialog *parent) - : QWidget(parent), - dialog(parent) +DialogWindow::DialogWindow(QWidget *parent) + : QWidget(parent) { } @@ -21,13 +20,231 @@ void DialogWindow::paintEvent(QPaintEvent *event) QBrush brush; brush.setStyle(Qt::SolidPattern); brush.setColor(Qt::white); - - painter.setBrush(brush); painter.setPen(Qt::NoPen); + painter.setBrush(brush); - QRectF r(0, 0, 200, 200); - r.moveCenter(rect().center()); - - painter.drawRect(r); + painter.drawRect(rect()); } +//DialogProxy::DialogProxy(Dialog *dialog, QWidget *widget) +// : QWidget(dialog), +// dialog(dialog), +// widget(widget) +//{ +//} +// +//DialogProxy::~DialogProxy() +//{ +//} +// +//void DialogProxy::paintEvent(QPaintEvent *event) +//{ +// Q_UNUSED(event) +// +// QPainter painter(this); +// +// //QPen pen; +// //pen.setWidth(4); +// //pen.setColor(Qt::red); +// //painter.setPen(pen); +// +// //painter.drawRect(rect()); +// +// // +// +// painter.setOpacity(0.3); +// +// QPixmap pm = widget->grab(rect()); +// painter.drawPixmap(rect(), pm); +// +//} +// +//DialogWindow::DialogWindow(Dialog *dialog) +// : QWidget(dialog->parentWidget()), +// dialog(dialog) +//{ +// setContentsMargins(32, 32, 32, 32); +// +// qDebug() << dialog->parentWidget(); +//} +// +//DialogWindow::~DialogWindow() +//{ +//} +// +//void DialogWindow::paintEvent(QPaintEvent *event) +//{ +// Q_UNUSED(event) +// +// QPainter painter(this); +// +// QPen pen; +// pen.setColor(Qt::red); +// pen.setWidth(1); +// painter.setPen(pen); +// painter.drawRect(rect().adjusted(0, 0, -1, -1)); +// +//// QLinearGradient tl(QPointF(0, 0), QPointF(32, 32)); +//// tl.setColorAt(0, QColor(0, 0, 0, 0)); +//// tl.setColorAt(1, QColor(0, 0, 0)); +// +//// QColor shadow(0, 0, 0, 240); +//// +//// QRadialGradient tl(rect().center(), 130); +//// tl.setColorAt(0, shadow); +//// tl.setColorAt(0.5, QColor(0, 0, 0)); +//// tl.setColorAt(1, QColor(0, 0, 0, 0)); +//// +//// painter.setBrush(QBrush(tl)); +//// painter.setPen(Qt::NoPen); +//// painter.drawRect(rect().adjusted(32, 32, -32, -32)); +// +// /* +// QColor shadow(0, 0, 0, 240); +// +// const int sz = 48; +// +// QLinearGradient top(QPointF(0, 0), QPointF(0, sz)); +// top.setColorAt(0, QColor(0, 0, 0, 0)); +// top.setColorAt(1, shadow); +// +// painter.setBrush(QBrush(top)); +// painter.setPen(Qt::NoPen); +// painter.drawRect(sz, 0, width()-sz*2, sz); +// +// QLinearGradient left(QPointF(0, 0), QPointF(sz, 0)); +// left.setColorAt(0, QColor(0, 0, 0, 0)); +// left.setColorAt(1, shadow); +// +// painter.setBrush(QBrush(left)); +// painter.drawRect(0, sz, sz, height()-sz*2); +// +// QLinearGradient right(QPointF(width()-sz, 0), QPointF(width(), 0)); +// right.setColorAt(0, shadow); +// right.setColorAt(1, QColor(0, 0, 0, 0)); +// +// painter.setBrush(QBrush(right)); +// painter.drawRect(width()-sz, sz, sz, height()-sz*2); +// +// QLinearGradient bottom(QPointF(0, height()-sz), QPointF(0, height())); +// bottom.setColorAt(0, shadow); +// bottom.setColorAt(1, QColor(0, 0, 0, 0)); +// +// painter.setBrush(QBrush(bottom)); +// painter.setPen(Qt::NoPen); +// painter.drawRect(sz, height()-sz, width()-sz*2, sz); +// +// QRadialGradient tl(QPointF(sz, sz), sz); +// tl.setColorAt(0, shadow); +// tl.setColorAt(1, QColor(0, 0, 0, 0)); +// +// painter.setBrush(QBrush(tl)); +// painter.drawRect(0, 0, sz, sz); +// +// QRadialGradient tr(QPointF(width()-sz, sz), sz); +// tr.setColorAt(0, shadow); +// tr.setColorAt(1, QColor(0, 0, 0, 0)); +// +// painter.setBrush(QBrush(tr)); +// painter.drawRect(width()-sz, 0, sz, sz); +// +// QRadialGradient br(QPointF(width()-sz, height()-sz), sz); +// br.setColorAt(0, shadow); +// br.setColorAt(1, QColor(0, 0, 0, 0)); +// +// painter.setBrush(QBrush(br)); +// painter.drawRect(width()-sz, height()-sz, sz, sz); +// +// QRadialGradient bl(QPointF(sz, height()-sz), sz); +// bl.setColorAt(0, shadow); +// bl.setColorAt(1, QColor(0, 0, 0, 0)); +// +// painter.setBrush(QBrush(bl)); +// painter.drawRect(0, height()-sz, sz, sz); +// */ +// +// // +// +// QBrush brush; +// brush.setStyle(Qt::SolidPattern); +// brush.setColor(Qt::white); +// painter.setPen(Qt::NoPen); +// //painter.setOpacity(0.5); +// painter.setBrush(brush); +// +// //QRectF r(0, 0, 200, 200); +// //r.moveCenter(rect().center()); +// +// painter.drawRect(rect().adjusted(32, 32, -32, -32)); +// +// { +// QWidget *w = new QWidget; +// +// QVBoxLayout *layout = new QVBoxLayout; +// w->setLayout(layout); +// +// QPushButton *button = new QPushButton; +// button->setText("Hello test!"); +// layout->addWidget(button); +// +// //QPixmap pm = w->grab(rect().adjusted(0, 0, -64, -64)); +// +// //QPixmap pm = dialog->dialogWidget()->grab(rect().adjusted(0, 0, -64, -64)); +// +// //painter.drawPixmap(rect().adjusted(32, 32, -32, -32), pm); +// +// painter.drawRect(rect()); +// } +// +// +// //brush.setColor(Qt::black); +// //painter.setBrush(brush); +// //painter.setOpacity(0.8); +// +// //painter.drawRect(rect().adjusted(32, 32, -32, -32)); +//} +// +//DialogShadow::DialogShadow(QWidget *dialog) +// : QWidget(dialog) +//{ +//} +// +//DialogShadow::~DialogShadow() +//{ +//} +// +//void DialogShadow::setWindow(DialogWindow *window) +//{ +// this->window = window; +// window->installEventFilter(this); +//} +// +//void DialogShadow::paintEvent(QPaintEvent *event) +//{ +// Q_UNUSED(event) +// +// QPainter painter(this); +// +//// QBrush brush; +//// brush.setStyle(Qt::SolidPattern); +//// brush.setColor(Qt::black); +//// painter.setBrush(brush); +//// painter.setOpacity(1); +//// +//// painter.drawRect(rect()); +//} +// +//bool DialogShadow::eventFilter(QObject *obj, QEvent *event) +//{ +// QEvent::Type type = event->type(); +// +// if (QEvent::Move == type || QEvent::Resize == type) +// { +// QWidget *widget; +// if ((widget = static_cast(obj))) { +// setGeometry(widget->geometry()); +// } +// } +// return QWidget::eventFilter(obj, event); +//} +// diff --git a/components/dialog_internal.h b/components/dialog_internal.h index 3065e8d..513d7cd 100644 --- a/components/dialog_internal.h +++ b/components/dialog_internal.h @@ -10,7 +10,7 @@ class DialogWindow : public QWidget Q_OBJECT public: - DialogWindow(Dialog *parent); + DialogWindow(QWidget *parent = 0); ~DialogWindow(); protected: @@ -18,8 +18,67 @@ protected: private: Q_DISABLE_COPY(DialogWindow) - - Dialog *const dialog; }; +//#include +// +//class Dialog; +// +//class DialogProxy : public QWidget +//{ +// Q_OBJECT +// +//public: +// DialogProxy(Dialog *dialog, QWidget *widget); +// ~DialogProxy(); +// +//protected: +// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; +// +//private: +// Q_DISABLE_COPY(DialogProxy) +// +// Dialog *const dialog; +// QWidget *widget; +//}; +// +///* -- */ +// +//class DialogWindow : public QWidget +//{ +// Q_OBJECT +// +//public: +// DialogWindow(Dialog *dialog); +// ~DialogWindow(); +// +//protected: +// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; +// +//private: +// Q_DISABLE_COPY(DialogWindow) +// +// Dialog *const dialog; +//}; +// +//class DialogShadow : public QWidget +//{ +// Q_OBJECT +// +//public: +// DialogShadow(QWidget *dialog); +// ~DialogShadow(); +// +// void setWindow(DialogWindow *window); +// +//protected: +// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; +// bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; +// +//private: +// Q_DISABLE_COPY(DialogShadow) +// +// DialogWindow *window; +//}; + #endif // DIALOG_INTERNAL_H diff --git a/components/dialog_p.h b/components/dialog_p.h index 22ea94c..0efd03a 100644 --- a/components/dialog_p.h +++ b/components/dialog_p.h @@ -5,6 +5,7 @@ class Dialog; class DialogWindow; +class TransparencyProxy; class DialogPrivate { @@ -18,6 +19,7 @@ public: Dialog *const q_ptr; DialogWindow *window; + TransparencyProxy *proxy; }; #endif // DIALOG_P_H diff --git a/components/flatbutton.cpp b/components/flatbutton.cpp index 59269e7..b4975c2 100644 --- a/components/flatbutton.cpp +++ b/components/flatbutton.cpp @@ -309,6 +309,7 @@ void FlatButton::paintEvent(QPaintEvent *event) initStyleOption(&option); option.features |= QStyleOptionButton::Flat; + style.setOpacity(1); style.drawControl(QStyle::CE_PushButtonLabel, option); #ifdef DEBUG_LAYOUT diff --git a/components/flatbutton.h b/components/flatbutton.h index d2b3f2c..b820fa9 100644 --- a/components/flatbutton.h +++ b/components/flatbutton.h @@ -9,6 +9,8 @@ class FlatButtonPrivate; /* * @TODO: implement checkable behavior + * + * @TODO: set default minimum height? */ class FlatButton : public QPushButton diff --git a/lib/transparencyproxy.cpp b/lib/transparencyproxy.cpp new file mode 100644 index 0000000..562830f --- /dev/null +++ b/lib/transparencyproxy.cpp @@ -0,0 +1,76 @@ +#include "transparencyproxy.h" +#include "transparencyproxy_p.h" +#include +#include +#include +#include "transparencyproxy_internal.h" + +TransparencyProxyPrivate::TransparencyProxyPrivate(TransparencyProxy *q) + : q_ptr(q), + widget(0), + proxy(0) +{ +} + +TransparencyProxyPrivate::~TransparencyProxyPrivate() +{ +} + +void TransparencyProxyPrivate::init() +{ +} + +TransparencyProxy::TransparencyProxy() + : QStackedLayout(), + d_ptr(new TransparencyProxyPrivate(this)) +{ + d_func()->init(); +} + +TransparencyProxy::~TransparencyProxy() +{ +} + +void TransparencyProxy::setWidget(QWidget *widget) +{ + Q_D(TransparencyProxy); + + if(d->widget) { + removeWidget(d->widget); + delete d->widget; + } + d->widget = widget; + + if (d->proxy) { + removeWidget(d->proxy); + delete d->proxy; + } + d->proxy = new ProxyWidget(widget); + + addWidget(widget); + addWidget(d->proxy); +} + +void TransparencyProxy::setOpaque() +{ + Q_D(TransparencyProxy); + + if (!d->proxy) { + return; + } + + d->proxy->setOpacity(1); + setCurrentIndex(0); +} + +void TransparencyProxy::setOpacity(qreal opacity) +{ + Q_D(TransparencyProxy); + + if (!d->proxy) { + return; + } + + d->proxy->setOpacity(opacity); + setCurrentIndex(1); +} diff --git a/lib/transparencyproxy.h b/lib/transparencyproxy.h new file mode 100644 index 0000000..e7e6a49 --- /dev/null +++ b/lib/transparencyproxy.h @@ -0,0 +1,30 @@ +#ifndef TRANSPARENCYPROXY_H +#define TRANSPARENCYPROXY_H + +#include + +class QWidget; +class TransparencyProxyPrivate; + +class TransparencyProxy : public QStackedLayout +{ + Q_OBJECT + +public: + TransparencyProxy(); + ~TransparencyProxy(); + + void setWidget(QWidget *widget); + + void setOpaque(); + void setOpacity(qreal opacity); + +protected: + const QScopedPointer d_ptr; + +private: + Q_DISABLE_COPY(TransparencyProxy) + Q_DECLARE_PRIVATE(TransparencyProxy) +}; + +#endif // TRANSPARENCYPROXY_H diff --git a/lib/transparencyproxy_internal.cpp b/lib/transparencyproxy_internal.cpp new file mode 100644 index 0000000..26568a7 --- /dev/null +++ b/lib/transparencyproxy_internal.cpp @@ -0,0 +1,32 @@ +#include "transparencyproxy_internal.h" +#include + +ProxyWidget::ProxyWidget(QWidget *widget, QWidget *parent) + : QWidget(parent), + _widget(widget), + _opacity(1.0) +{ +} + +ProxyWidget::~ProxyWidget() +{ +} + +void ProxyWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event) + + QPainter painter(this); + + //QPen pen; + //pen.setColor(Qt::red); + //pen.setWidth(5); + //painter.setPen(pen); + + //painter.drawRect(rect()); + + painter.setOpacity(_opacity); + + QPixmap pixmap = _widget->grab(rect()); + painter.drawPixmap(rect(), pixmap); +} diff --git a/lib/transparencyproxy_internal.h b/lib/transparencyproxy_internal.h new file mode 100644 index 0000000..9e67892 --- /dev/null +++ b/lib/transparencyproxy_internal.h @@ -0,0 +1,27 @@ +#ifndef TRANSPARENCYPROXY_INTERNAL_H +#define TRANSPARENCYPROXY_INTERNAL_H + +#include + +class ProxyWidget : public QWidget +{ + Q_OBJECT + +public: + ProxyWidget(QWidget *widget, QWidget *parent = 0); + ~ProxyWidget(); + + inline void setOpacity(qreal opacity) { _opacity = opacity; update(); } + inline qreal opacity() const { return _opacity; } + +protected: + void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + +private: + Q_DISABLE_COPY(ProxyWidget) + + QWidget *const _widget; + qreal _opacity; +}; + +#endif // TRANSPARENCYPROXY_INTERNAL_H diff --git a/lib/transparencyproxy_p.h b/lib/transparencyproxy_p.h new file mode 100644 index 0000000..4c33f7d --- /dev/null +++ b/lib/transparencyproxy_p.h @@ -0,0 +1,25 @@ +#ifndef TRANSPARENCYPROXY_P_H +#define TRANSPARENCYPROXY_P_H + +#include + +class TransparencyProxy; +class ProxyWidget; + +class TransparencyProxyPrivate +{ + Q_DISABLE_COPY(TransparencyProxyPrivate) + Q_DECLARE_PUBLIC(TransparencyProxy) + +public: + TransparencyProxyPrivate(TransparencyProxy *q); + ~TransparencyProxyPrivate(); + + void init(); + + TransparencyProxy *const q_ptr; + QWidget *widget; + ProxyWidget *proxy; +}; + +#endif // TRANSPARENCYPROXY_P_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 9fa8836..a1eb59e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -82,8 +82,24 @@ MainWindow::MainWindow(QWidget *parent) // - Dialog *dialog = new Dialog; - dialog->setParent(this); + { + Dialog *dialog = new Dialog; + dialog->setParent(this); + + FlatButton *btn = new FlatButton; + btn->setMinimumHeight(40); + btn->setText("Hello world"); + + QPushButton *btn2 = new QPushButton; + btn2->setText("Hello world"); + + QVBoxLayout *layout = new QVBoxLayout; + dialog->setWindowLayout(layout); + + layout->addWidget(btn); + layout->addWidget(btn2); + } + } MainWindow::~MainWindow() diff --git a/qt-material-widgets.pro b/qt-material-widgets.pro index 50dea6c..e25b732 100644 --- a/qt-material-widgets.pro +++ b/qt-material-widgets.pro @@ -70,7 +70,9 @@ SOURCES += main.cpp\ components/progress_internal.cpp \ components/scrollwidget.cpp \ components/scrollwidget_internal.cpp \ - components/dialog_internal.cpp + components/dialog_internal.cpp \ + lib/transparencyproxy.cpp \ + lib/transparencyproxy_internal.cpp HEADERS += mainwindow.h \ components/appbar.h \ @@ -153,7 +155,10 @@ HEADERS += mainwindow.h \ components/scrollwidget.h \ components/scrollwidget_internal.h \ components/dialog_p.h \ - components/dialog_internal.h + components/dialog_internal.h \ + lib/transparencyproxy.h \ + lib/transparencyproxy_p.h \ + lib/transparencyproxy_internal.h RESOURCES += \ resources.qrc