aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kapusta <dominik.kapusta@teleca.com>2010-06-16 13:40:08 +0200
committerDaniel d'Andrada <daniel.dandrada@nokia.com>2010-06-29 10:56:52 +0300
commit3755059abdf029ef713e220a9bed1d06c738c894 (patch)
tree84f409e2a2f7b8290ab14588df063a3dbed12cb0
parentc02dc119a863677de88c27459f1e2f35a0eba02f (diff)
New: Support for setting video global alpha in MWindow.
RevBy: Daniel d'Andrada Details: Provide an easy API in MWindow to use the video global alpha feature in Harmattan.
-rw-r--r--doc/src/news.dox5
-rw-r--r--src/corelib/widgets/mwindow.cpp70
-rw-r--r--src/corelib/widgets/mwindow.h35
-rw-r--r--src/corelib/widgets/mwindow_p.h2
-rw-r--r--tests/ut_mwindow/ut_mwindow.cpp22
-rw-r--r--tests/ut_mwindow/ut_mwindow.h1
6 files changed, 118 insertions, 17 deletions
diff --git a/doc/src/news.dox b/doc/src/news.dox
index ba4922b3..490d67a1 100644
--- a/doc/src/news.dox
+++ b/doc/src/news.dox
@@ -1,5 +1,10 @@
/*! \page news What's New in DirectUI
+\section v02024 0.20.24
+
+\subsection New
+- videoGlobalAlpha property in MWindow.
+
\section v02020 0.20.20
\subsection New
diff --git a/src/corelib/widgets/mwindow.cpp b/src/corelib/widgets/mwindow.cpp
index e4f6182d..05397b75 100644
--- a/src/corelib/widgets/mwindow.cpp
+++ b/src/corelib/widgets/mwindow.cpp
@@ -477,30 +477,30 @@ void MWindow::setTranslucentBackground(bool enable)
d->initGLViewport();
}
-void MWindow::setGlobalAlpha(qreal level)
-{
#ifdef Q_WS_X11
- Atom globalAlpha = XInternAtom(QX11Info::display(), "_MEEGOTOUCH_GLOBAL_ALPHA", False);
+void MWindowPrivate::setX11Property(const char *propertyName, qreal value)
+{
+ Q_Q(MWindow);
+
+ Atom atom = XInternAtom(QX11Info::display(), propertyName, False);
- if (level < 0.0 || level >= 1.0) {
- XDeleteProperty(QX11Info::display(), winId(), globalAlpha);
+ if (value < 0.0 || value >= 1.0) {
+ XDeleteProperty(QX11Info::display(), q->winId(), atom);
} else {
// We use same conventions as _NET_WM_WINDOW_OPACITY so we could re-use
// same code in the compositor
- unsigned int opacity = (unsigned int) (0xffffffff * level);
+ unsigned int opacity = (unsigned int) (0xffffffff * value);
- XChangeProperty(QX11Info::display(), winId(), globalAlpha, XA_CARDINAL, 32 ,
+ XChangeProperty(QX11Info::display(), q->winId(), atom, XA_CARDINAL, 32 ,
PropModeReplace, (unsigned char *) &opacity, 1);
}
-#else
- Q_UNUSED(level);
-#endif
}
-qreal MWindow::globalAlpha()
+qreal MWindowPrivate::getX11Property(const char *propertyName) const
{
+ Q_Q(const MWindow);
+
qreal level = 1.0;
-#ifdef Q_WS_X11
Atom actualType = 0;
int actualFormat = 0;
unsigned long nitems = 0;
@@ -511,9 +511,9 @@ qreal MWindow::globalAlpha()
unsigned long* asULong;
} data = {0};
- Atom globalAlpha = XInternAtom(QX11Info::display(), "_MEEGOTOUCH_GLOBAL_ALPHA", False);
+ Atom propertyAtom = XInternAtom(QX11Info::display(), propertyName, False);
- int status = XGetWindowProperty(QX11Info::display(), winId(), globalAlpha,
+ int status = XGetWindowProperty(QX11Info::display(), q->winId(), propertyAtom,
0, 1, False, AnyPropertyType,
&actualType, &actualFormat, &nitems,
&bytes, &data.asUChar);
@@ -522,9 +522,49 @@ qreal MWindow::globalAlpha()
level = (qreal)data.asULong[0] / 0xffffffff;
if (status == Success)
XFree(data.asUChar);
-#endif
return level;
}
+#endif
+
+void MWindow::setGlobalAlpha(qreal level)
+{
+#ifdef Q_WS_X11
+ Q_D(MWindow);
+ d->setX11Property("_MEEGOTOUCH_GLOBAL_ALPHA", level);
+#else
+ Q_UNUSED(level);
+#endif
+}
+
+qreal MWindow::globalAlpha()
+{
+#ifdef Q_WS_X11
+ Q_D(MWindow);
+ return d->getX11Property("_MEEGOTOUCH_GLOBAL_ALPHA");
+#else
+ return 1.0;
+#endif
+}
+
+void MWindow::setVideoGlobalAlpha(qreal level)
+{
+#ifdef Q_WS_X11
+ Q_D(MWindow);
+ d->setX11Property("_MEEGOTOUCH_VIDEO_ALPHA", level);
+#else
+ Q_UNUSED(level);
+#endif
+}
+
+qreal MWindow::videoGlobalAlpha()
+{
+#ifdef Q_WS_X11
+ Q_D(MWindow);
+ return d->getX11Property("_MEEGOTOUCH_VIDEO_ALPHA");
+#else
+ return 1.0;
+#endif
+}
MScene *MWindow::scene()
{
diff --git a/src/corelib/widgets/mwindow.h b/src/corelib/widgets/mwindow.h
index 8a3a2e2e..603cdc90 100644
--- a/src/corelib/widgets/mwindow.h
+++ b/src/corelib/widgets/mwindow.h
@@ -96,6 +96,12 @@ class M_EXPORT MWindow : public QGraphicsView
*/
Q_PROPERTY(qreal globalAlpha READ globalAlpha WRITE setGlobalAlpha)
+ /*!
+ \property videoGlobalAlpha
+ The global alpha of the hardware video overlay for use by this window.
+ */
+ Q_PROPERTY(qreal videoGlobalAlpha READ videoGlobalAlpha WRITE setVideoGlobalAlpha)
+
public:
/*!
\brief Creates a MWindow without a scene manager.
@@ -168,13 +174,38 @@ public:
*
* \param level The valid range of global alpha can be 1.0 (completely opaque) to 0.0 (completely transparent).
*/
- void setGlobalAlpha(qreal level);
+ void setGlobalAlpha(qreal level);
/*!
\brief Returns the global alpha of the hardware graphics overlay for use
by this window.
*/
- qreal globalAlpha();
+ qreal globalAlpha();
+
+ /*!
+ * \brief Sets the alpha of the hardware video overlay for use
+ * by this window.
+ *
+ * Video alpha is the is used to control the dimming of the video overlay
+ * where hardware accelerated video is rendering.
+ *
+ * By default, each MWindow does not enable the video alpha. When this
+ * window is destroyed or hidden, the system will revert the video alpha
+ * back to its previous state.
+ *
+ * Platform notes:
+ * - This is a Harmattan-specific implementation and will require
+ * interaction with the Harmattan compositing window manager
+ * (MCompositor)
+ *
+ * \param level The valid range of video alpha can be 1.0 (completely opaque) to 0.0 (completely transparent)
+ */
+ void setVideoGlobalAlpha(qreal level);
+
+ /*!
+ * \brief Returns the alpha of the hardware video overlay for use by this window.
+ */
+ qreal videoGlobalAlpha();
/*!
\brief Returns the window's MScene.
diff --git a/src/corelib/widgets/mwindow_p.h b/src/corelib/widgets/mwindow_p.h
index c9b542b1..9f6520e6 100644
--- a/src/corelib/widgets/mwindow_p.h
+++ b/src/corelib/widgets/mwindow_p.h
@@ -44,6 +44,8 @@ public:
#ifdef Q_WS_X11
void appendVisibilityChangeMask();
+ void setX11Property(const char *propertyName, qreal value);
+ qreal getX11Property(const char *propertyName) const;
#endif
void _q_onPixmapRequestsFinished();
diff --git a/tests/ut_mwindow/ut_mwindow.cpp b/tests/ut_mwindow/ut_mwindow.cpp
index eadf2b5d..2aebe71b 100644
--- a/tests/ut_mwindow/ut_mwindow.cpp
+++ b/tests/ut_mwindow/ut_mwindow.cpp
@@ -335,4 +335,26 @@ void Ut_MWindow::testGlobalAlpha()
QCOMPARE(alpha, 1.0);
}
+void Ut_MWindow::testVideoGlobalAlpha()
+{
+ qreal alpha = win->videoGlobalAlpha();
+ QCOMPARE(alpha, 1.0);
+
+ win->setVideoGlobalAlpha(0.5);
+ alpha = win->videoGlobalAlpha();
+ QVERIFY( qAbs(alpha - 0.5) < 0.001 );
+
+ win->setVideoGlobalAlpha(0.0);
+ alpha = win->videoGlobalAlpha();
+ QCOMPARE(alpha, 0.0);
+
+ win->setVideoGlobalAlpha(1.0);
+ alpha = win->videoGlobalAlpha();
+ QCOMPARE(alpha, 1.0);
+
+ win->setVideoGlobalAlpha(-2.0);
+ alpha = win->videoGlobalAlpha();
+ QCOMPARE(alpha, 1.0);
+}
+
QTEST_MAIN(Ut_MWindow);
diff --git a/tests/ut_mwindow/ut_mwindow.h b/tests/ut_mwindow/ut_mwindow.h
index 60477b6a..e623ab7f 100644
--- a/tests/ut_mwindow/ut_mwindow.h
+++ b/tests/ut_mwindow/ut_mwindow.h
@@ -62,6 +62,7 @@ private slots:
void testDisplayExitedOnCloseLazyShutdownApp();
void testCloseOnLazyShutdown();
void testGlobalAlpha();
+ void testVideoGlobalAlpha();
public slots:
void onDisplayTestSlot();