Commit 014b1d5731c0ece5fb9c51e36a99e3f8953b4aa4

  • avatar
  • Robert Griebl <rgriebl @trol…ech.com>
  • Tue Feb 09 19:12:26 GMT 2010
1) Prepare the widget attribute enum for the 4.6 merge
2) Make auto-rotation mode (with PR1.2 only) more obvious by using a separate flag
doc/src/platforms/platform-notes.qdoc
(2 / 2)
  
569569 \o The portrait or landscape orientation is not a global setting, but is
570570 handled on a per window basis. By default, Qt's windows use whatever orientation
571571 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.
574574
575575 The \l{Maemo 5 Rotation Example} shows how to dynamically rotate top-level
576576 widgets.
examples/maemo5/rotation/main.cpp
(2 / 2)
  
7272 void setLandscape()
7373 {
7474// ![2]
75 setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, true);
75 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
7676// ![2]
7777
7878 label->setText("<p align=\"center\">In landscape mode now</p>");
8181 void setPortrait()
8282 {
8383// ![3]
84 setAttribute(Qt::WA_Maemo5ForcePortraitOrientation, true);
84 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
8585// ![3]
8686
8787 label->setText("<p align=\"center\">In portrait mode now</p>");
examples/maemo5/widgetgallery/main.cpp
(2 / 3)
  
110110 if (!triggered)
111111 return;
112112#ifdef Q_WS_MAEMO_5
113 setAttribute(Qt::WA_Maemo5ForcePortraitOrientation, true);
113 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
114114#endif
115115 }
116116
119119 if (!triggered)
120120 return;
121121#ifdef Q_WS_MAEMO_5
122 setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, true);
122 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
123123#endif
124124 }
125125};
133133
134134#ifdef Q_WS_MAEMO_5
135135 window.setAttribute(Qt::WA_Maemo5StackedWindow);
136 window.setAttribute(Qt::WA_Maemo5ForceLandscapeOrientation, true);
137136
138137 QActionGroup *orientation = new QActionGroup(&window);
139138 orientation->setExclusive(true);
examples/maemo5/widgets/window.cpp
(16 / 41)
  
9999{
100100 setAttribute(Qt::WA_Maemo5StackedWindow);
101101
102 bool isPortrait = (qApp->desktop()->screenGeometry().width() < qApp->desktop()->screenGeometry().height());
103
104102 m_fullscreen = new QAction(QIcon::fromTheme("general_fullsize"), QString(), this);
105103 m_fullscreen->setCheckable(true);
106104 QActionGroup *orientation = new QActionGroup(this);
107105 orientation->setExclusive(true);
108106 m_portrait = new QAction(QIcon::fromTheme("general_portrait", QIcon(QLatin1String(":/images/portrait"))), QString(), orientation);
109107 m_portrait->setCheckable(true);
110 m_portrait->setChecked(isPortrait);
108 m_portrait->setChecked(false);
111109 m_landscape = new QAction(QIcon::fromTheme("general_landscape", QIcon(QLatin1String(":/images/landscape"))), QString(), orientation);
112110 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);
114115
115116 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 *)));
117118
118119 // add some radio/exclusive actions (which will be converted to filter actions in the application menu)
119120 // The Maemo 5 UI specification limits this to up to four actions in up to one group
137137{
138138}
139139
140void Window::toggleLandscape(bool b)
140void Window::orientationChanged(QAction *action)
141141{
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);
144146 else
145 setAttribute(Qt::WA_Maemo5ForcePortraitOrientation, true);
147 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
146148
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
151153 relayout();
152154}
153155
165165{
166166 setWindowState(b ? windowState() | Qt::WindowFullScreen
167167 : windowState() & ~Qt::WindowFullScreen);
168}
169
170void 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
181void 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
190void 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);
196168}
197169
198170void Window::relayout()
examples/maemo5/widgets/window.h
(2 / 5)
  
5555 virtual ~Window();
5656
5757protected slots:
58 void orientationChanged(QString);
59 void toggleLandscape(bool);
58 void orientationChanged(QAction *);
6059 void toggleFullScreen(bool);
6160 void enableChildren(bool);
6261
6362protected:
64 void showEvent(QShowEvent *e);
65 void hideEvent(QHideEvent *e);
66
6763 virtual void relayout();
6864
6965 QAction *m_fullscreen;
7066 QAction *m_landscape;
7167 QAction *m_portrait;
68 QAction *m_auto;
7269 QAction *m_enable_children;
7370 QAction *m_disable_children;
7471};
src/corelib/global/qnamespace.h
(4 / 4)
  
497497 WA_WState_AcceptedTouchBeginEvent = 122,
498498 WA_TouchPadAcceptSingleTouchEvents = 123,
499499
500 WA_Maemo5ShowProgressIndicator = 124,
501 WA_Maemo5DesktopApplet = 125,
502500 WA_Maemo5NonComposited = 126,
503501 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,
506506
507507 // Add new attributes before this line
508508 WA_AttributeCount
src/corelib/global/qnamespace.qdoc
(6 / 6)
  
12461246 \value WA_Maemo5StackedWindow Flags this window to be part of a
12471247 Maemo 5 Window Stack. This flag is only available on Maemo 5.
12481248
1249 \value WA_Maemo5ForceLandscapeOrientation Forces this window
1249 \value WA_Maemo5LandscapeOrientation Forces this window
12501250 into landscape orientation, independent of the device's prior
12511251 orientation. This flag is only available on Maemo 5.
12521252
1253 \value WA_Maemo5ForcePortraitOrientation Forces this window
1253 \value WA_Maemo5PortraitOrientation Forces this window
12541254 into portrait orientation, independent of the device's prior
12551255 orientation. This flag is only available on Maemo 5.
12561256
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
12571261 \value WA_Maemo5ShowProgressIndicator Shows a busy indicator
12581262 on this window's title bar. This flag is only available on Maemo 5.
12591263
12651265 that this window should not be part of the composition. Might
12661266 speed up rendering, but makes top-level transparency impossible.
12671267 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.
12721268
12731269 \omitvalue WA_SetLayoutDirection
12741270 \omitvalue WA_InputMethodTransparent
src/gui/kernel/qwidget.cpp
(11 / 8)
  
1049310493 d->setNetWmWindowTypes();
1049410494 break;
1049510495# ifdef Q_WS_MAEMO_5
10496 case Qt::WA_Maemo5DesktopApplet:
1049710496 case Qt::WA_Maemo5NonComposited:
1049810497 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:
1050110501 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 }
1050710510 }
1050810511 if (testAttribute(Qt::WA_WState_Created))
1050910512 d->setNetWmWindowTypes();
src/gui/kernel/qwidget_x11.cpp
(12 / 19)
  
130130 if (!q->isWindow())
131131 return;
132132
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];
135137
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 }
139143 }
140144
141 if (force_portrait) {
145 if (orientation == Qt::WA_Maemo5PortraitOrientation) {
142146 long on = 1;
143147 XChangeProperty(X11->display, q->winId(), ATOM(_HILDON_PORTRAIT_MODE_REQUEST), XA_CARDINAL, 32,
144148 PropModeReplace, (unsigned char *) &on, 1);
145149 } else {
146150 XDeleteProperty(X11->display, q->winId(), ATOM(_HILDON_PORTRAIT_MODE_REQUEST));
147151 }
148 if (!force_landscape) {
152 if (orientation != Qt::WA_Maemo5LandscapeOrientation) {
149153 long on = 1;
150154 XChangeProperty(X11->display, q->winId(), ATOM(_HILDON_PORTRAIT_MODE_SUPPORT), XA_CARDINAL, 32,
151155 PropModeReplace, (unsigned char *) &on, 1);
22762276 }
22772277
22782278#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
22902279 // 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.
22922281 maemo5CheckOrientation(q);
22932282 maemo5CheckNonComposited(q);
22942283 maemo5CheckStackedWindow(q);

Comments

Add a new comment:

Login or create an account to post a comment

Add your comment