Commit 014b1d5731c0ece5fb9c51e36a99e3f8953b4aa4
- Diff rendering mode:
- inline
- side by side
doc/src/platforms/platform-notes.qdoc
(2 / 2)
|   | |||
| 569 | 569 | \o The portrait or landscape orientation is not a global setting, but is | |
| 570 | 570 | handled on a per window basis. By default, Qt's windows use whatever orientation | |
| 571 | 571 | the window manager is in. For top-level widgets this default can be | |
| 572 | changed by setting the Qt::WA_Maemo5ForcePortraitOrientation and | ||
| 573 | Qt::WA_Maemo5ForceLandscapeOrientation widget attributes. | ||
| 572 | changed by setting the Qt::WA_Maemo5PortraitOrientation and | ||
| 573 | Qt::WA_Maemo5LandscapeOrientation widget attributes. | ||
| 574 | 574 | ||
| 575 | 575 | The \l{Maemo 5 Rotation Example} shows how to dynamically rotate top-level | |
| 576 | 576 | widgets. |
examples/maemo5/rotation/main.cpp
(2 / 2)
|   | |||
| 72 | 72 | void setLandscape() | |
| 73 | 73 | { | |
| 74 | 74 | // ![2] | |
| 75 | setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, true); | ||
| 75 | setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); | ||
| 76 | 76 | // ![2] | |
| 77 | 77 | ||
| 78 | 78 | label->setText("<p align=\"center\">In landscape mode now</p>"); | |
| … | … | ||
| 81 | 81 | void setPortrait() | |
| 82 | 82 | { | |
| 83 | 83 | // ![3] | |
| 84 | setAttribute(Qt::WA_Maemo5ForcePortraitOrientation, true); | ||
| 84 | setAttribute(Qt::WA_Maemo5PortraitOrientation, true); | ||
| 85 | 85 | // ![3] | |
| 86 | 86 | ||
| 87 | 87 | label->setText("<p align=\"center\">In portrait mode now</p>"); |
examples/maemo5/widgetgallery/main.cpp
(2 / 3)
|   | |||
| 110 | 110 | if (!triggered) | |
| 111 | 111 | return; | |
| 112 | 112 | #ifdef Q_WS_MAEMO_5 | |
| 113 | setAttribute(Qt::WA_Maemo5ForcePortraitOrientation, true); | ||
| 113 | setAttribute(Qt::WA_Maemo5PortraitOrientation, true); | ||
| 114 | 114 | #endif | |
| 115 | 115 | } | |
| 116 | 116 | ||
| … | … | ||
| 119 | 119 | if (!triggered) | |
| 120 | 120 | return; | |
| 121 | 121 | #ifdef Q_WS_MAEMO_5 | |
| 122 | setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, true); | ||
| 122 | setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); | ||
| 123 | 123 | #endif | |
| 124 | 124 | } | |
| 125 | 125 | }; | |
| … | … | ||
| 133 | 133 | ||
| 134 | 134 | #ifdef Q_WS_MAEMO_5 | |
| 135 | 135 | window.setAttribute(Qt::WA_Maemo5StackedWindow); | |
| 136 | window.setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, true); | ||
| 137 | 136 | ||
| 138 | 137 | QActionGroup *orientation = new QActionGroup(&window); | |
| 139 | 138 | orientation->setExclusive(true); |
examples/maemo5/widgets/window.cpp
(16 / 41)
|   | |||
| 99 | 99 | { | |
| 100 | 100 | setAttribute(Qt::WA_Maemo5StackedWindow); | |
| 101 | 101 | ||
| 102 | bool isPortrait = (qApp->desktop()->screenGeometry().width() < qApp->desktop()->screenGeometry().height()); | ||
| 103 | |||
| 104 | 102 | m_fullscreen = new QAction(QIcon::fromTheme("general_fullsize"), QString(), this); | |
| 105 | 103 | m_fullscreen->setCheckable(true); | |
| 106 | 104 | QActionGroup *orientation = new QActionGroup(this); | |
| 107 | 105 | orientation->setExclusive(true); | |
| 108 | 106 | m_portrait = new QAction(QIcon::fromTheme("general_portrait", QIcon(QLatin1String(":/images/portrait"))), QString(), orientation); | |
| 109 | 107 | m_portrait->setCheckable(true); | |
| 110 | m_portrait->setChecked(isPortrait); | ||
| 108 | m_portrait->setChecked(false); | ||
| 111 | 109 | m_landscape = new QAction(QIcon::fromTheme("general_landscape", QIcon(QLatin1String(":/images/landscape"))), QString(), orientation); | |
| 112 | 110 | m_landscape->setCheckable(true); | |
| 113 | m_landscape->setChecked(!isPortrait); | ||
| 111 | m_landscape->setChecked(false); | ||
| 112 | m_auto = new QAction(tr("Auto"), orientation); | ||
| 113 | m_auto->setCheckable(true); | ||
| 114 | m_auto->setChecked(true); | ||
| 114 | 115 | ||
| 115 | 116 | connect(m_fullscreen, SIGNAL(toggled(bool)), this, SLOT(toggleFullScreen(bool))); | |
| 116 | connect(m_landscape, SIGNAL(toggled(bool)), this, SLOT(toggleLandscape(bool))); | ||
| 117 | connect(orientation, SIGNAL(triggered(QAction *)), this, SLOT(orientationChanged(QAction *))); | ||
| 117 | 118 | ||
| 118 | 119 | // add some radio/exclusive actions (which will be converted to filter actions in the application menu) | |
| 119 | 120 | // The Maemo 5 UI specification limits this to up to four actions in up to one group | |
| … | … | ||
| 137 | 137 | { | |
| 138 | 138 | } | |
| 139 | 139 | ||
| 140 | void Window::toggleLandscape(bool b) | ||
| 140 | void Window::orientationChanged(QAction *action) | ||
| 141 | 141 | { | |
| 142 | if (b) | ||
| 143 | setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, true); | ||
| 142 | if (action == m_auto) | ||
| 143 | setAttribute(Qt::WA_Maemo5AutoOrientation, true); | ||
| 144 | else if (action == m_portrait) | ||
| 145 | setAttribute(Qt::WA_Maemo5PortraitOrientation, true); | ||
| 144 | 146 | else | |
| 145 | setAttribute(Qt::WA_Maemo5ForcePortraitOrientation, true); | ||
| 147 | setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); | ||
| 146 | 148 | ||
| 147 | if (b != m_landscape->isChecked()) { | ||
| 148 | m_landscape->setChecked(b); | ||
| 149 | m_portrait->setChecked(!b); | ||
| 150 | } | ||
| 149 | m_landscape->setChecked(action == m_landscape); | ||
| 150 | m_portrait->setChecked(action == m_portrait); | ||
| 151 | m_auto->setChecked(action == m_auto); | ||
| 152 | |||
| 151 | 153 | relayout(); | |
| 152 | 154 | } | |
| 153 | 155 | ||
| … | … | ||
| 165 | 165 | { | |
| 166 | 166 | setWindowState(b ? windowState() | Qt::WindowFullScreen | |
| 167 | 167 | : windowState() & ~Qt::WindowFullScreen); | |
| 168 | } | ||
| 169 | |||
| 170 | void Window::showEvent(QShowEvent *se) | ||
| 171 | { | ||
| 172 | QDBusMessage reply = QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, | ||
| 173 | MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); | ||
| 174 | if (reply.type() != QDBusMessage::ErrorMessage) | ||
| 175 | orientationChanged(reply.arguments().value(0).toString()); | ||
| 176 | QDBusConnection::systemBus().connect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF, | ||
| 177 | MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationChanged(QString))); | ||
| 178 | QMainWindow::showEvent(se); | ||
| 179 | } | ||
| 180 | |||
| 181 | void Window::hideEvent(QHideEvent *he) | ||
| 182 | { | ||
| 183 | QDBusConnection::systemBus().disconnect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF, | ||
| 184 | MCE_DEVICE_ORIENTATION_SIG, this, SLOT(orientationChanged(QString, QString, QString, int, int, int))); | ||
| 185 | QDBusConnection::systemBus().call(QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, | ||
| 186 | MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); | ||
| 187 | QMainWindow::hideEvent(he); | ||
| 188 | } | ||
| 189 | |||
| 190 | void Window::orientationChanged(QString landscape) | ||
| 191 | { | ||
| 192 | if (landscape == QLatin1String(MCE_ORIENTATION_LANDSCAPE)) | ||
| 193 | toggleLandscape(true); | ||
| 194 | else if (landscape == QLatin1String(MCE_ORIENTATION_PORTRAIT)) | ||
| 195 | toggleLandscape(false); | ||
| 196 | 168 | } | |
| 197 | 169 | ||
| 198 | 170 | void Window::relayout() |
examples/maemo5/widgets/window.h
(2 / 5)
|   | |||
| 55 | 55 | virtual ~Window(); | |
| 56 | 56 | ||
| 57 | 57 | protected slots: | |
| 58 | void orientationChanged(QString); | ||
| 59 | void toggleLandscape(bool); | ||
| 58 | void orientationChanged(QAction *); | ||
| 60 | 59 | void toggleFullScreen(bool); | |
| 61 | 60 | void enableChildren(bool); | |
| 62 | 61 | ||
| 63 | 62 | protected: | |
| 64 | void showEvent(QShowEvent *e); | ||
| 65 | void hideEvent(QHideEvent *e); | ||
| 66 | |||
| 67 | 63 | virtual void relayout(); | |
| 68 | 64 | ||
| 69 | 65 | QAction *m_fullscreen; | |
| 70 | 66 | QAction *m_landscape; | |
| 71 | 67 | QAction *m_portrait; | |
| 68 | QAction *m_auto; | ||
| 72 | 69 | QAction *m_enable_children; | |
| 73 | 70 | QAction *m_disable_children; | |
| 74 | 71 | }; |
src/corelib/global/qnamespace.h
(4 / 4)
|   | |||
| 497 | 497 | WA_WState_AcceptedTouchBeginEvent = 122, | |
| 498 | 498 | WA_TouchPadAcceptSingleTouchEvents = 123, | |
| 499 | 499 | ||
| 500 | WA_Maemo5ShowProgressIndicator = 124, | ||
| 501 | WA_Maemo5DesktopApplet = 125, | ||
| 502 | 500 | WA_Maemo5NonComposited = 126, | |
| 503 | 501 | WA_Maemo5StackedWindow = 127, | |
| 504 | WA_Maemo5ForcePortraitOrientation = 128, | ||
| 505 | WA_Maemo5ForceLandscapeOrientation = 129, | ||
| 502 | WA_Maemo5PortraitOrientation = 128, | ||
| 503 | WA_Maemo5LandscapeOrientation = 129, | ||
| 504 | WA_Maemo5AutoOrientation = 130, | ||
| 505 | WA_Maemo5ShowProgressIndicator = 131, | ||
| 506 | 506 | ||
| 507 | 507 | // Add new attributes before this line | |
| 508 | 508 | WA_AttributeCount |
src/corelib/global/qnamespace.qdoc
(6 / 6)
|   | |||
| 1246 | 1246 | \value WA_Maemo5StackedWindow Flags this window to be part of a | |
| 1247 | 1247 | Maemo 5 Window Stack. This flag is only available on Maemo 5. | |
| 1248 | 1248 | ||
| 1249 | \value WA_Maemo5ForceLandscapeOrientation Forces this window | ||
| 1249 | \value WA_Maemo5LandscapeOrientation Forces this window | ||
| 1250 | 1250 | into landscape orientation, independent of the device's prior | |
| 1251 | 1251 | orientation. This flag is only available on Maemo 5. | |
| 1252 | 1252 | ||
| 1253 | \value WA_Maemo5ForcePortraitOrientation Forces this window | ||
| 1253 | \value WA_Maemo5PortraitOrientation Forces this window | ||
| 1254 | 1254 | into portrait orientation, independent of the device's prior | |
| 1255 | 1255 | orientation. This flag is only available on Maemo 5. | |
| 1256 | 1256 | ||
| 1257 | \value WA_Maemo5AutoOrientation This window will auto-rotate into | ||
| 1258 | portrait or landscape orientation, depending on the device's | ||
| 1259 | orientation. This flag is only available on Maemo 5. | ||
| 1260 | |||
| 1257 | 1261 | \value WA_Maemo5ShowProgressIndicator Shows a busy indicator | |
| 1258 | 1262 | on this window's title bar. This flag is only available on Maemo 5. | |
| 1259 | 1263 | ||
| … | … | ||
| 1265 | 1265 | that this window should not be part of the composition. Might | |
| 1266 | 1266 | speed up rendering, but makes top-level transparency impossible. | |
| 1267 | 1267 | This flag is only available on Maemo 5. | |
| 1268 | |||
| 1269 | \value WA_Maemo5DesktopApplet Indicates that this window is | ||
| 1270 | a desktop applet rather than a top-level window. This flag | ||
| 1271 | is only available on Maemo 5. | ||
| 1272 | 1268 | ||
| 1273 | 1269 | \omitvalue WA_SetLayoutDirection | |
| 1274 | 1270 | \omitvalue WA_InputMethodTransparent |
src/gui/kernel/qwidget.cpp
(11 / 8)
|   | |||
| 10493 | 10493 | d->setNetWmWindowTypes(); | |
| 10494 | 10494 | break; | |
| 10495 | 10495 | # ifdef Q_WS_MAEMO_5 | |
| 10496 | case Qt::WA_Maemo5DesktopApplet: | ||
| 10497 | 10496 | case Qt::WA_Maemo5NonComposited: | |
| 10498 | 10497 | case Qt::WA_Maemo5StackedWindow: | |
| 10499 | case Qt::WA_Maemo5ForcePortraitOrientation: | ||
| 10500 | case Qt::WA_Maemo5ForceLandscapeOrientation: | ||
| 10498 | case Qt::WA_Maemo5PortraitOrientation: | ||
| 10499 | case Qt::WA_Maemo5LandscapeOrientation: | ||
| 10500 | case Qt::WA_Maemo5AutoOrientation: | ||
| 10501 | 10501 | if (on) { | |
| 10502 | // Portrait and Landscape are mutually exclusive | ||
| 10503 | if (attribute == Qt::WA_Maemo5ForcePortraitOrientation) | ||
| 10504 | setAttribute_internal(Qt::WA_Maemo5ForceLandscapeOrientation, false, data, d); | ||
| 10505 | else if (attribute == Qt::WA_Maemo5ForceLandscapeOrientation) | ||
| 10506 | setAttribute_internal(Qt::WA_Maemo5ForcePortraitOrientation, false, data, d); | ||
| 10502 | // We can only have one of these set at a time | ||
| 10503 | const Qt::WidgetAttribute Maemo5Orientations[] = { Qt::WA_Maemo5PortraitOrientation, | ||
| 10504 | Qt::WA_Maemo5LandscapeOrientation, | ||
| 10505 | Qt::WA_Maemo5AutoOrientation }; | ||
| 10506 | for (int i = 0; i < 3; ++i) { | ||
| 10507 | if (Maemo5Orientations[i] != attribute) | ||
| 10508 | setAttribute_internal(Maemo5Orientations[i], false, data, d); | ||
| 10509 | } | ||
| 10507 | 10510 | } | |
| 10508 | 10511 | if (testAttribute(Qt::WA_WState_Created)) | |
| 10509 | 10512 | d->setNetWmWindowTypes(); |
src/gui/kernel/qwidget_x11.cpp
(12 / 19)
|   | |||
| 130 | 130 | if (!q->isWindow()) | |
| 131 | 131 | return; | |
| 132 | 132 | ||
| 133 | bool force_portrait = q->testAttribute(Qt::WA_Maemo5ForcePortraitOrientation); | ||
| 134 | bool force_landscape = q->testAttribute(Qt::WA_Maemo5ForceLandscapeOrientation); | ||
| 133 | const Qt::WidgetAttribute Maemo5Orientations[] = { Qt::WA_Maemo5LandscapeOrientation, | ||
| 134 | Qt::WA_Maemo5PortraitOrientation, | ||
| 135 | Qt::WA_Maemo5AutoOrientation }; | ||
| 136 | Qt::WidgetAttribute orientation = Maemo5Orientations[0]; | ||
| 135 | 137 | ||
| 136 | if (force_portrait && force_landscape) { | ||
| 137 | qWarning() << "QWidget: Incompatible window attributes: the window can't be forced to portrait and landscape orientation at the same time"; | ||
| 138 | force_portrait = force_landscape = false; | ||
| 138 | for (int i = 0; i < 3; ++i) { | ||
| 139 | if (q->testAttribute(Maemo5Orientations[i])) { | ||
| 140 | orientation = Maemo5Orientations[i]; | ||
| 141 | break; | ||
| 142 | } | ||
| 139 | 143 | } | |
| 140 | 144 | ||
| 141 | if (force_portrait) { | ||
| 145 | if (orientation == Qt::WA_Maemo5PortraitOrientation) { | ||
| 142 | 146 | long on = 1; | |
| 143 | 147 | XChangeProperty(X11->display, q->winId(), ATOM(_HILDON_PORTRAIT_MODE_REQUEST), XA_CARDINAL, 32, | |
| 144 | 148 | PropModeReplace, (unsigned char *) &on, 1); | |
| 145 | 149 | } else { | |
| 146 | 150 | XDeleteProperty(X11->display, q->winId(), ATOM(_HILDON_PORTRAIT_MODE_REQUEST)); | |
| 147 | 151 | } | |
| 148 | if (!force_landscape) { | ||
| 152 | if (orientation != Qt::WA_Maemo5LandscapeOrientation) { | ||
| 149 | 153 | long on = 1; | |
| 150 | 154 | XChangeProperty(X11->display, q->winId(), ATOM(_HILDON_PORTRAIT_MODE_SUPPORT), XA_CARDINAL, 32, | |
| 151 | 155 | PropModeReplace, (unsigned char *) &on, 1); | |
| … | … | ||
| 2276 | 2276 | } | |
| 2277 | 2277 | ||
| 2278 | 2278 | #ifdef Q_WS_MAEMO_5 | |
| 2279 | if (q->testAttribute(Qt::WA_Maemo5DesktopApplet)) { | ||
| 2280 | windowTypes.prepend(ATOM(_HILDON_WM_WINDOW_TYPE_HOME_APPLET)); | ||
| 2281 | |||
| 2282 | QByteArray appletid = q->objectName().toLocal8Bit(); | ||
| 2283 | if (appletid.isEmpty()) | ||
| 2284 | appletid = "qt_desktop_applet_" + QByteArray::number(qrand(), 16); | ||
| 2285 | |||
| 2286 | XChangeProperty(X11->display, q->winId(), ATOM(_HILDON_APPLET_ID), XA_STRING, 8, | ||
| 2287 | PropModeReplace, (unsigned char *) appletid.constData(), appletid.length()); | ||
| 2288 | } | ||
| 2289 | |||
| 2290 | 2279 | // this is not really netwm stuff, but it still makes sense | |
| 2291 | // to fiddle with all those X atoms at central location. | ||
| 2280 | // to fiddle with all those X atoms at a central location. | ||
| 2292 | 2281 | maemo5CheckOrientation(q); | |
| 2293 | 2282 | maemo5CheckNonComposited(q); | |
| 2294 | 2283 | maemo5CheckStackedWindow(q); |
Comments
Add your comment
Please log in to comment



Add a new comment:
Login or create an account to post a comment