aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernd Lamecker <bernd.lamecker@basyskom.de>2010-03-02 14:50:04 +0100
committerBernd Lamecker <bernd.lamecker@basyskom.de>2010-03-05 14:18:45 +0100
commitdab5ba9f4e74e3ff5d3d9801fde667ab3f830158 (patch)
tree695de53c015f0b0cad9e20e2b4544510c9f55448
parent043d8f5f2730bfbc348939a0f3ad94ca130feb93 (diff)
Changes: Transparency on menus and dialogs
RevBy: Torsten Rahn Details: Drawing correct transparencys around menu and dialog proxys
-rw-r--r--plainqt/style/qtmaemo6dialogproxy.cpp2
-rw-r--r--plainqt/style/qtmaemo6menuproxy.cpp56
-rw-r--r--plainqt/style/qtmaemo6style.cpp10
-rw-r--r--plainqt/style/qtmaemo6styleeventfilter.cpp8
-rw-r--r--plainqt/style/qtmaemo6submenu.cpp1
-rw-r--r--plainqt/style/qtmaemo6window.cpp20
-rw-r--r--plainqt/style/qtmaemo6window.h29
-rw-r--r--plainqt/style/qtmaemo6windowdecoration.cpp6
8 files changed, 104 insertions, 28 deletions
diff --git a/plainqt/style/qtmaemo6dialogproxy.cpp b/plainqt/style/qtmaemo6dialogproxy.cpp
index 5a65f355..a4ee2e8c 100644
--- a/plainqt/style/qtmaemo6dialogproxy.cpp
+++ b/plainqt/style/qtmaemo6dialogproxy.cpp
@@ -49,7 +49,7 @@ QtMaemo6DialogProxy::QtMaemo6DialogProxy(QWidget *mw, QWidget *parent)
m_windowLayout->addItem(topSpacer, 0, 0, 1, 3);
m_windowLayout->addItem(leftSideSpacer, 1, 0, 2, 1);
m_windowLayout->addWidget(m_dialogTitle, 1, 1, 1, 1);
- m_windowLayout->addWidget(m_scrollArea, 2, 1, 1, 1);
+ m_windowLayout->addWidget(centralWidget(), 2, 1, 1, 1);
m_windowLayout->addItem(rightSideSpacer, 1, 2, 2, 1);
//only works if mw is a QDialog, otherwise the connect simply fails
diff --git a/plainqt/style/qtmaemo6menuproxy.cpp b/plainqt/style/qtmaemo6menuproxy.cpp
index f2ddf36e..dbc57809 100644
--- a/plainqt/style/qtmaemo6menuproxy.cpp
+++ b/plainqt/style/qtmaemo6menuproxy.cpp
@@ -27,20 +27,59 @@
#include <QCloseEvent>
#include <QStyleOption>
#include <QPushButton>
+#include <QPaintEvent>
+#include <QPainter>
#include <duiapplicationmenustyle.h>
+#include <QDebug>
+
+/* unforunately this is required to force widgets drawing it's background, even
+ if there are widget attributes are set, that suppress the drawing!
+*/
+class DrawBackgroundEventFilter : public QObject {
+protected:
+ bool eventFilter(QObject* obj, QEvent* e) {
+ if(QPaintEvent* pe = dynamic_cast<QPaintEvent*>(e)) {
+ if(QWidget* w = qobject_cast<QWidget*>(obj)) {
+ qCritical() << "EventFilter:" << w->objectName() << w->geometry() << pe->rect();
+
+ Q_UNUSED(pe);
+ QPainter p(w);
+ p.setPen(Qt::NoPen);
+ p.setBrush(w->palette().window());
+ p.drawRect(pe->rect());
+ }
+ }
+ return QObject::eventFilter(obj, e);
+ };
+};
QtMaemo6MenuProxy::QtMaemo6MenuProxy(QMenuBar *mb, QWidget *parent)
: QtMaemo6Window(NULL, parent),
m_menuBar(mb)
{
+ //must be set, to activate the compositing
setAttribute(Qt::WA_TranslucentBackground);
-
QPalette palette;
- palette.setBrush(QPalette::Window, QBrush(QColor(0, 0, 0, 192)));
+ palette.setBrush(QPalette::Window, Qt::transparent);
setPalette(palette);
+ QWidget* appArea = new QWidget();
+ appArea->setObjectName("appArea");
+ appArea->installEventFilter(new DrawBackgroundEventFilter());
+
+ appArea->setAttribute(Qt::WA_TranslucentBackground);
+ palette.setBrush(QPalette::Window, QBrush(QColor(0, 0, 0, 192)));
+ appArea->setPalette(palette);
+
+ QGridLayout* gridLayout = new QGridLayout(appArea);
+ gridLayout->setMargin(0);
+ gridLayout->setSpacing(0);
+
m_menu = new QtMaemo6Menu(mb, NULL);
+ m_menu->setAttribute(Qt::WA_TranslucentBackground, false);
+ palette.setBrush(QPalette::Window, QBrush(QColor(0, 0, 0, 0)));
+ m_menu->setPalette(palette);
setCentralWidget(m_menu);
QStyleOption option;
@@ -55,10 +94,13 @@ QtMaemo6MenuProxy::QtMaemo6MenuProxy(QMenuBar *mb, QWidget *parent)
QSpacerItem *bottomSpacer = new QSpacerItem(1, style->paddingBottom());
QSpacerItem *leftSpacer = new QSpacerItem(style->paddingLeft(), 1);
- m_windowLayout->addItem(topSpacer, 0, 0, 1, 3);
- m_windowLayout->addItem(leftSpacer, 1, 0, 1, 1);
- m_windowLayout->addItem(rightSpacer, 1, 2, 1, 1);
- m_windowLayout->addItem(bottomSpacer, 2, 0, 1, 3);
+ gridLayout->addItem(leftSpacer, 0, 0, 1, 1);
+ gridLayout->addWidget(centralWidget(), 0, 1, 1, 1);
+ gridLayout->addItem(rightSpacer, 0, 2, 1, 1);
+ gridLayout->addItem(bottomSpacer, 1, 0, 1, 3);
+
+ m_windowLayout->addItem(topSpacer, 0, 0, 1, 1);
+ m_windowLayout->addWidget(appArea, 1, 0, 1, 1);
}
QtMaemo6MenuProxy::~QtMaemo6MenuProxy()
@@ -69,6 +111,6 @@ QtMaemo6MenuProxy::~QtMaemo6MenuProxy()
void QtMaemo6MenuProxy::mousePressEvent(QMouseEvent *event)
{
- Q_UNUSED(event);
close();
+ QtMaemo6Window::mousePressEvent(event);
}
diff --git a/plainqt/style/qtmaemo6style.cpp b/plainqt/style/qtmaemo6style.cpp
index 725ca809..64bd14d3 100644
--- a/plainqt/style/qtmaemo6style.cpp
+++ b/plainqt/style/qtmaemo6style.cpp
@@ -834,10 +834,12 @@ void QtMaemo6Style::polish(QWidget *widget)
if (!qobject_cast<QtMaemo6WindowDecoration *>(widget)
&& !qobject_cast<QMenu *>(widget)
&& !qobject_cast<QtMaemo6DialogProxy *>(widget)) {
- //FIXME: public API usage
- QPalette pal = widget->palette();
- pal.setBrush(QPalette::Window, Qt::transparent);
- widget->setPalette(pal);
+ if(!widget->testAttribute(Qt::WA_TranslucentBackground)) {
+ //FIXME: public API usage
+ QPalette pal = widget->palette();
+ pal.setBrush(QPalette::Window, Qt::transparent);
+ widget->setPalette(pal);
+ }
}
widget->installEventFilter(d->m_windowEventFilter);
diff --git a/plainqt/style/qtmaemo6styleeventfilter.cpp b/plainqt/style/qtmaemo6styleeventfilter.cpp
index 967480ba..46d74c6a 100644
--- a/plainqt/style/qtmaemo6styleeventfilter.cpp
+++ b/plainqt/style/qtmaemo6styleeventfilter.cpp
@@ -57,15 +57,11 @@ bool QtMaemo6StyleEventFilter::eventFilter(QObject *obj, QEvent *event)
{
QWidget *widget = qobject_cast<QWidget *>(obj);
- //unused
- //QWidget * parent = widget->parentWidget();
-
switch (event->type()) {
case QEvent::Show: {
if (NULL != widget) {
if (widget->isWindow()) {
if (QDialog *dialog = qobject_cast<QDialog *>(widget)) {
- qCritical() << "Generating and Showing DuiDialog";
QtMaemo6DialogProxy *dialogProxy = new QtMaemo6DialogProxy(dialog, m_style->m_windowDecoration);
dialogProxy->setTitle(widget->windowTitle());
@@ -86,8 +82,8 @@ bool QtMaemo6StyleEventFilter::eventFilter(QObject *obj, QEvent *event)
decoration->setStatusBar(NULL);
decoration->setMenuBar(NULL);
QtMaemo6StylePrivate::drawWindowBackground(decoration);
- } else if (!qobject_cast<QtMaemo6Window *>(widget)) {
- qCritical() << "Generating and Showing DuiWindowDecoration";
+ } else if (!qobject_cast<QtMaemo6Window *>(widget) &&
+ !widget->inherits("QTipLabel")) { //don't create a new window for every tooltip!
m_style->m_windowDecoration = new QtMaemo6WindowDecoration(widget);
m_style->m_windowDecoration->showFastMaximized();
QtMaemo6StylePrivate::drawWindowBackground(m_style->m_windowDecoration);
diff --git a/plainqt/style/qtmaemo6submenu.cpp b/plainqt/style/qtmaemo6submenu.cpp
index e1e9817b..894f261f 100644
--- a/plainqt/style/qtmaemo6submenu.cpp
+++ b/plainqt/style/qtmaemo6submenu.cpp
@@ -62,7 +62,6 @@ void QtMaemo6SubMenu::listItemClicked(QListWidgetItem *item)
decoration->setStatusBar(NULL);
decoration->setMenuBar(NULL);
QtMaemo6StylePrivate::drawWindowBackground(decoration);
- close();
} else {
action->activate(QAction::Trigger);
}
diff --git a/plainqt/style/qtmaemo6window.cpp b/plainqt/style/qtmaemo6window.cpp
index 5204f865..3ba0af31 100644
--- a/plainqt/style/qtmaemo6window.cpp
+++ b/plainqt/style/qtmaemo6window.cpp
@@ -27,6 +27,7 @@
#include <QCloseEvent>
#include <QDialog>
#include <QDebug>
+#include <QPainter>
#include <duideviceprofile.h>
@@ -35,9 +36,9 @@
QtMaemo6Window::QtMaemo6Window(QWidget *originalWidget, QWidget *parent /*= NULL*/)
: QWidget(parent)
+ , m_window(originalWidget)
, m_centralWidget(0)
, m_scrollArea(0)
- , m_window(originalWidget)
, m_closeFromChild(false)
{
setWindowFlags(Qt::Window
@@ -56,7 +57,6 @@ QtMaemo6Window::QtMaemo6Window(QWidget *originalWidget, QWidget *parent /*= NULL
QtMaemo6Window::~QtMaemo6Window()
{
- qCritical() << "QtMaemo6Window deleted";
}
QSize QtMaemo6Window::maxViewportSize() const
@@ -107,6 +107,15 @@ bool QtMaemo6Window::eventFilter(QObject *obj, QEvent *event)
return QWidget::eventFilter(obj, event);
}
+void QtMaemo6Window::paintEvent(QPaintEvent* e) {
+ //force drawing the background on windows
+ QPainter p(this);
+ p.setPen(Qt::NoPen);
+ p.setBrush(palette().window());
+ p.drawRect(e->rect());
+ QWidget::paintEvent(e);
+}
+
void QtMaemo6Window::showFastMaximized()
{
// Size policy instead?
@@ -150,6 +159,11 @@ void QtMaemo6Window::setCentralWidget(QWidget *widget)
widget->setMinimumWidth(maxViewportSize().width());
if(widget->sizePolicy().verticalPolicy() == QSizePolicy::Expanding)
widget->setMinimumHeight(maxViewportSize().height());
- m_windowLayout->addWidget(m_centralWidget, 1, 1, 1, 1);
}
}
+
+QWidget* QtMaemo6Window::centralWidget() const {
+ if(!m_scrollArea)
+ return m_window;
+ return m_scrollArea;
+}
diff --git a/plainqt/style/qtmaemo6window.h b/plainqt/style/qtmaemo6window.h
index c2354067..76b2fe5b 100644
--- a/plainqt/style/qtmaemo6window.h
+++ b/plainqt/style/qtmaemo6window.h
@@ -23,6 +23,7 @@
#include <QWidget>
#include <QScrollArea>
#include <QPointer>
+#include <QPen>
class QGridLayout;
@@ -68,24 +69,46 @@ public:
void showFastMaximized();
/*!
- * sets the widget that is shown inside the window
+ * \brief sets the widget that is shown inside the window
+ * the given widget will be used as the central widget within this window.
+ * The widget is not added to any layout, this must be done by the user.
+ * If the widget inherits QAbstractScrollArea, it will be added directly. If
+ * it does not, a scrollArea will be created and the widget is set as the
+ * scrollarea's viewport. Note: in this case, the centralWidget of the window
+ * will be the scrollArea, not the given widget!
*/
void setCentralWidget(QWidget *widget);
+ /*!
+ * \brief returns the central widget of this window
+ * If no widget is set, this returns NULL. The returned widget may not be
+ * the widget, which was set with setCentralWidget().
+ * \see setCentralWidget()
+ */
+ QWidget* centralWidget() const;
+
+ /*!
+ * \brief returns the widget set with central widget
+ * in opposite to centralWidget() this always returns the added widget.
+ */
+ QWidget* widget() const { return m_window; };
+
protected:
QtMaemo6Window() {};
/*! \reimp */
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
+ void paintEvent(QPaintEvent* e);
/*! \reimp_end */
protected:
QGridLayout *m_windowLayout;
+private:
+ QPointer<QWidget> m_window;
QAbstractScrollArea *m_centralWidget;
QScrollArea *m_scrollArea;
- QPointer<QWidget> m_window;
-private:
+
Qt::WindowFlags m_originalFlags;
bool m_closeFromChild;
bool m_hideFromChild;
diff --git a/plainqt/style/qtmaemo6windowdecoration.cpp b/plainqt/style/qtmaemo6windowdecoration.cpp
index 1bc237fc..973230bb 100644
--- a/plainqt/style/qtmaemo6windowdecoration.cpp
+++ b/plainqt/style/qtmaemo6windowdecoration.cpp
@@ -43,7 +43,7 @@ QtMaemo6WindowDecoration::QtMaemo6WindowDecoration(QWidget *mw, QWidget *parent
m_titleBar->setTitle(mw->windowTitle());
m_windowLayout->addWidget(m_titleBar, 0, 1);
- m_windowLayout->addWidget(m_scrollArea, 1, 1);
+ m_windowLayout->addWidget(centralWidget(), 1, 1);
connect(m_titleBar, SIGNAL(closeButtonClicked()), this, SLOT(close()));
connect(m_titleBar, SIGNAL(minimizeButtonClicked()), this, SLOT(hide()));
@@ -92,7 +92,7 @@ void QtMaemo6WindowDecoration::setMenuBar(QMenuBar *menuBar)
void QtMaemo6WindowDecoration::showMenuBar()
{
if (m_menuBar) {
- QtMaemo6MenuProxy *menuProxy = new QtMaemo6MenuProxy(m_menuBar, this);
+ QtMaemo6MenuProxy* menuProxy = new QtMaemo6MenuProxy(m_menuBar, this);
menuProxy->showFastMaximized();
}
}
@@ -100,7 +100,7 @@ void QtMaemo6WindowDecoration::showMenuBar()
bool QtMaemo6WindowDecoration::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::WindowTitleChange) {
- m_titleBar->setTitle(m_window->windowTitle());
+ m_titleBar->setTitle(widget()->windowTitle());
} else if (event->type() == QEvent::Close) {
hide();
}