summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorRafael Roquetto <rafael.roquetto.qnx@kdab.com>2012-09-20 15:11:43 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-21 08:11:40 (GMT)
commit3a6c8cdb0bed87622c2e1e9fca5c2fa03028be9c (patch)
tree246baeb1fbd67f5c7ce6ea03dd7c47822bbea8ec /src/plugins
parent8efe2390a35cd76abbe474650ee8af8df5a31a20 (diff)
downloadQt-3a6c8cdb0bed87622c2e1e9fca5c2fa03028be9c.zip
Qt-3a6c8cdb0bed87622c2e1e9fca5c2fa03028be9c.tar.gz
Qt-3a6c8cdb0bed87622c2e1e9fca5c2fa03028be9c.tar.bz2
Rotate non maximized windows
There are two types of rotation to be considered: 1. Rotation of native widgets The corresponding window should be rotated and resized proportionally to the new screen geometry. 2. Rotation of toplevel windows. The window will be only rotated. It will be only moved or resized if it becomes clipped, in order to be fitted on the screen properly. cherry-picked from qt5 89d9f8fe949e65e7455fabe288ea284aa6de06b1 Change-Id: I837da53f1a12a7b8aff1e0e9d6f4579e3aefaf2a Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/blackberry/qbbscreen.cpp106
-rw-r--r--src/plugins/platforms/blackberry/qbbscreen.h3
2 files changed, 109 insertions, 0 deletions
diff --git a/src/plugins/platforms/blackberry/qbbscreen.cpp b/src/plugins/platforms/blackberry/qbbscreen.cpp
index 54ae8e1..6d1d4df 100644
--- a/src/plugins/platforms/blackberry/qbbscreen.cpp
+++ b/src/plugins/platforms/blackberry/qbbscreen.cpp
@@ -191,6 +191,8 @@ void QBBScreen::setRotation(int rotation)
if (mRootWindow)
mRootWindow->setRotation(rotation);
+ const QRect previousScreenGeometry = geometry();
+
// swap dimensions if we've rotated 90 or 270 from initial orientation
if (isOrthogonal(mStartRotation, rotation)) {
mCurrentGeometry = QRect(0, 0, mStartGeometry.height(), mStartGeometry.width());
@@ -208,6 +210,9 @@ void QBBScreen::setRotation(int rotation)
#endif
if (mRootWindow)
mRootWindow->resize(mCurrentGeometry.size());
+
+ if (mPrimaryDisplay)
+ resizeWindows(previousScreenGeometry);
} else {
// TODO: find one global place to flush display updates
#if defined(QBBSCREEN_DEBUG)
@@ -233,6 +238,107 @@ void QBBScreen::setRotation(int rotation)
}
}
+void QBBScreen::resizeNativeWidgetWindow(QBBWindow *w, const QRect &previousScreenGeometry) const
+{
+ const qreal relativeX = static_cast<qreal>(w->geometry().topLeft().x()) / previousScreenGeometry.width();
+ const qreal relativeY = static_cast<qreal>(w->geometry().topLeft().y()) / previousScreenGeometry.height();
+ const qreal relativeWidth = static_cast<qreal>(w->geometry().width()) / previousScreenGeometry.width();
+ const qreal relativeHeight = static_cast<qreal>(w->geometry().height()) / previousScreenGeometry.height();
+
+ const QRect windowGeometry(relativeX * geometry().width(), relativeY * geometry().height(),
+ relativeWidth * geometry().width(), relativeHeight * geometry().height());
+
+ w->widget()->setGeometry(windowGeometry);
+}
+
+/*!
+ Resize the given window to fit the screen geometry
+*/
+void QBBScreen::resizeTopLevelWindow(QBBWindow *w, const QRect &previousScreenGeometry) const
+{
+ QRect windowGeometry = w->geometry();
+
+ const qreal relativeCenterX = static_cast<qreal>(w->geometry().center().x()) / previousScreenGeometry.width();
+ const qreal relativeCenterY = static_cast<qreal>(w->geometry().center().y()) / previousScreenGeometry.height();
+ const QPoint newCenter(relativeCenterX * geometry().width(), relativeCenterY * geometry().height());
+
+ windowGeometry.moveCenter(newCenter);
+
+ // adjust center position in case the window
+ // is clipped
+ if (!geometry().contains(windowGeometry)) {
+ const int x1 = windowGeometry.x();
+ const int y1 = windowGeometry.y();
+ const int x2 = x1 + windowGeometry.width();
+ const int y2 = y1 + windowGeometry.height();
+
+ if (x1 < 0) {
+ const int centerX = qMin(qAbs(x1) + windowGeometry.center().x(),
+ geometry().center().x());
+
+ windowGeometry.moveCenter(QPoint(centerX, windowGeometry.center().y()));
+ }
+
+ if (y1 < 0) {
+ const int centerY = qMin(qAbs(y1) + windowGeometry.center().y(),
+ geometry().center().y());
+
+ windowGeometry.moveCenter(QPoint(windowGeometry.center().x(), centerY));
+ }
+
+ if (x2 > geometry().width()) {
+ const int centerX = qMax(windowGeometry.center().x() - (x2 - geometry().width()),
+ geometry().center().x());
+
+ windowGeometry.moveCenter(QPoint(centerX, windowGeometry.center().y()));
+ }
+
+ if (y2 > geometry().height()) {
+ const int centerY = qMax(windowGeometry.center().y() - (y2 - geometry().height()),
+ geometry().center().y());
+
+ windowGeometry.moveCenter(QPoint(windowGeometry.center().x(), centerY));
+ }
+ }
+
+ // at this point, if the window is still clipped,
+ // it means that it's too big to fit on the screen,
+ // so we need to proportionally shrink it
+ if (!geometry().contains(windowGeometry)) {
+ QSize newSize = windowGeometry.size();
+ newSize.scale(geometry().size(), Qt::KeepAspectRatio);
+ windowGeometry.setSize(newSize);
+
+ if (windowGeometry.x() < 0)
+ windowGeometry.moveCenter(QPoint(geometry().center().x(), windowGeometry.center().y()));
+
+ if (windowGeometry.y() < 0)
+ windowGeometry.moveCenter(QPoint(windowGeometry.center().x(), geometry().center().y()));
+ }
+
+ w->widget()->setGeometry(windowGeometry);
+}
+
+/*!
+ Adjust windows to the new screen geometry.
+*/
+void QBBScreen::resizeWindows(const QRect &previousScreenGeometry)
+{
+ Q_FOREACH (QBBWindow *w, mChildren) {
+
+ if (w->widget()->windowState() & Qt::WindowFullScreen || w->widget()->windowState() & Qt::WindowMaximized)
+ continue;
+
+ if (w->widget()->parent()) {
+ // This is a native (non-alien) widget window
+ resizeNativeWidgetWindow(w, previousScreenGeometry);
+ } else {
+ // This is a toplevel window
+ resizeTopLevelWindow(w, previousScreenGeometry);
+ }
+ }
+}
+
QBBWindow *QBBScreen::findWindow(screen_window_t windowHandle)
{
Q_FOREACH (QBBWindow *window, mChildren) {
diff --git a/src/plugins/platforms/blackberry/qbbscreen.h b/src/plugins/platforms/blackberry/qbbscreen.h
index d74a45c..42aa074 100644
--- a/src/plugins/platforms/blackberry/qbbscreen.h
+++ b/src/plugins/platforms/blackberry/qbbscreen.h
@@ -93,6 +93,9 @@ private Q_SLOTS:
void keyboardHeightChanged(int height);
private:
+ void resizeNativeWidgetWindow(QBBWindow *w, const QRect &previousScreenGeometry) const;
+ void resizeTopLevelWindow(QBBWindow *w, const QRect &previousScreenGeometry) const;
+ void resizeWindows(const QRect &previousScreenGeometry);
void addOverlayWindow(screen_window_t window);
void removeOverlayWindow(screen_window_t window);