summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);