summaryrefslogtreecommitdiffstats
path: root/examples/widgets/orientation
diff options
context:
space:
mode:
authorDavid Boddie <david.boddie@nokia.com>2011-05-11 17:35:46 +0200
committerDavid Boddie <david.boddie@nokia.com>2011-05-23 14:24:07 +0200
commit0cbcc61ef35b9bce1d65d048853c79004b755b87 (patch)
tree0e10f00827d9d3b84862e371d163f1b2774ee996 /examples/widgets/orientation
parent0748751c9f097d9d866605306bbdd4b96e2a5c4e (diff)
Squashed commit of changes from the 4.8-temp branch.
Diffstat (limited to 'examples/widgets/orientation')
-rw-r--r--examples/widgets/orientation/image_a.pngbin0 -> 1075 bytes
-rw-r--r--examples/widgets/orientation/image_b.pngbin0 -> 1020 bytes
-rw-r--r--examples/widgets/orientation/image_c.pngbin0 -> 1163 bytes
-rw-r--r--examples/widgets/orientation/images.qrc7
-rw-r--r--examples/widgets/orientation/landscape.ui114
-rw-r--r--examples/widgets/orientation/main.cpp15
-rw-r--r--examples/widgets/orientation/mainwindow.cpp75
-rw-r--r--examples/widgets/orientation/mainwindow.h33
-rw-r--r--examples/widgets/orientation/orientation.desktop11
-rw-r--r--examples/widgets/orientation/orientation.pro30
-rw-r--r--examples/widgets/orientation/portrait.ui61
11 files changed, 346 insertions, 0 deletions
diff --git a/examples/widgets/orientation/image_a.png b/examples/widgets/orientation/image_a.png
new file mode 100644
index 0000000000..4a1a0d3252
--- /dev/null
+++ b/examples/widgets/orientation/image_a.png
Binary files differ
diff --git a/examples/widgets/orientation/image_b.png b/examples/widgets/orientation/image_b.png
new file mode 100644
index 0000000000..8722d1edee
--- /dev/null
+++ b/examples/widgets/orientation/image_b.png
Binary files differ
diff --git a/examples/widgets/orientation/image_c.png b/examples/widgets/orientation/image_c.png
new file mode 100644
index 0000000000..6c9304fda0
--- /dev/null
+++ b/examples/widgets/orientation/image_c.png
Binary files differ
diff --git a/examples/widgets/orientation/images.qrc b/examples/widgets/orientation/images.qrc
new file mode 100644
index 0000000000..b258291e6f
--- /dev/null
+++ b/examples/widgets/orientation/images.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>image_a.png</file>
+ <file>image_b.png</file>
+ <file>image_c.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/widgets/orientation/landscape.ui b/examples/widgets/orientation/landscape.ui
new file mode 100644
index 0000000000..4616c041dc
--- /dev/null
+++ b/examples/widgets/orientation/landscape.ui
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LandscapeUI</class>
+ <widget class="QWidget" name="LandscapeUI">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>514</width>
+ <height>265</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="2">
+ <widget class="QLabel" name="label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="styleSheet">
+ <string notr="true">font-weight: bold;</string>
+ </property>
+ <property name="text">
+ <string>Landscape mode</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QPushButton" name="exitButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Exit</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Choices</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="radioAButton">
+ <property name="text">
+ <string>Long description explaining choice A</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioBButton">
+ <property name="text">
+ <string>Long description explaining choice B</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioCButton">
+ <property name="text">
+ <string>Long description explaining choice C</string>
+ </property>
+ <attribute name="buttonGroup">
+ <string>buttonGroup</string>
+ </attribute>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QWidget" name="choiceWidget" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <buttongroups>
+ <buttongroup name="buttonGroup"/>
+ </buttongroups>
+</ui>
diff --git a/examples/widgets/orientation/main.cpp b/examples/widgets/orientation/main.cpp
new file mode 100644
index 0000000000..34b05d6a66
--- /dev/null
+++ b/examples/widgets/orientation/main.cpp
@@ -0,0 +1,15 @@
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+
+ MainWindow w;
+ w.showFullScreen();
+
+ return a.exec();
+}
+//! [0]
+
diff --git a/examples/widgets/orientation/mainwindow.cpp b/examples/widgets/orientation/mainwindow.cpp
new file mode 100644
index 0000000000..328af445c8
--- /dev/null
+++ b/examples/widgets/orientation/mainwindow.cpp
@@ -0,0 +1,75 @@
+#include "mainwindow.h"
+#include "ui_landscape.h"
+#include "ui_portrait.h"
+
+#include <QDesktopWidget>
+#include <QResizeEvent>
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent) :
+ QWidget(parent),
+ landscapeWidget(0),
+ portraitWidget(0)
+{
+ landscapeWidget = new QWidget(this);
+ landscape.setupUi(landscapeWidget);
+
+ portraitWidget = new QWidget(this);
+ portrait.setupUi(portraitWidget);
+//! [0]
+
+//! [1]
+ connect(portrait.exitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(landscape.exitButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(landscape.buttonGroup, SIGNAL(buttonClicked(QAbstractButton*)),
+ this, SLOT(onRadioButtonClicked(QAbstractButton*)));
+
+ landscape.radioAButton->setChecked(true);
+ onRadioButtonClicked(landscape.radioAButton);
+//! [1]
+
+//! [2]
+#ifdef Q_WS_MAEMO_5
+ setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+#endif
+}
+//! [2]
+
+//! [3]
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+ QSize size = event->size();
+ bool isLandscape = size.width() > size.height();
+
+ if (!isLandscape)
+ size.transpose();
+
+ landscapeWidget->setFixedSize(size);
+ size.transpose();
+ portraitWidget->setFixedSize(size);
+
+ landscapeWidget->setVisible(isLandscape);
+ portraitWidget->setVisible(!isLandscape);
+}
+//! [3]
+
+//! [4]
+void MainWindow::onRadioButtonClicked(QAbstractButton *button)
+{
+ QString styleTemplate = "background-image: url(:/image_%1.png);"
+ "background-repeat: no-repeat;"
+ "background-position: center center";
+
+ QString imageStyle("");
+ if (button == landscape.radioAButton)
+ imageStyle = styleTemplate.arg("a");
+ else if (button == landscape.radioBButton)
+ imageStyle = styleTemplate.arg("b");
+ else if (button == landscape.radioCButton)
+ imageStyle = styleTemplate.arg("c");
+
+ portrait.choiceWidget->setStyleSheet(imageStyle);
+ landscape.choiceWidget->setStyleSheet(imageStyle);
+}
+//! [4]
+
diff --git a/examples/widgets/orientation/mainwindow.h b/examples/widgets/orientation/mainwindow.h
new file mode 100644
index 0000000000..7c2546d4c4
--- /dev/null
+++ b/examples/widgets/orientation/mainwindow.h
@@ -0,0 +1,33 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QWidget>
+
+#include "ui_landscape.h"
+#include "ui_portrait.h"
+
+class QAbstractButton;
+
+//! [0]
+class MainWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+private slots:
+ void onRadioButtonClicked(QAbstractButton *button);
+
+private:
+ Ui::LandscapeUI landscape;
+ Ui::PortraitUI portrait;
+ QWidget *landscapeWidget;
+ QWidget *portraitWidget;
+};
+//! [0]
+
+#endif // MAINWINDOW_H
diff --git a/examples/widgets/orientation/orientation.desktop b/examples/widgets/orientation/orientation.desktop
new file mode 100644
index 0000000000..7bbf5584d3
--- /dev/null
+++ b/examples/widgets/orientation/orientation.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Orientation
+Exec=/opt/usr/bin/orientation
+Icon=orientation
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/orientation/orientation.pro b/examples/widgets/orientation/orientation.pro
new file mode 100644
index 0000000000..c146322635
--- /dev/null
+++ b/examples/widgets/orientation/orientation.pro
@@ -0,0 +1,30 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-08-04T10:27:31
+#
+#-------------------------------------------------
+
+QT += core gui
+
+TARGET = orientation
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ mainwindow.cpp
+
+HEADERS += mainwindow.h
+
+FORMS += \
+ portrait.ui \
+ landscape.ui
+
+RESOURCES += \
+ images.qrc
+
+symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)
+
+symbian: warning(This example might not fully work on Symbian platform)
+maemo5: warning(This example might not fully work on Maemo platform)
+simulator: warning(This example might not fully work on Simulator platform)
diff --git a/examples/widgets/orientation/portrait.ui b/examples/widgets/orientation/portrait.ui
new file mode 100644
index 0000000000..31a55aff73
--- /dev/null
+++ b/examples/widgets/orientation/portrait.ui
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PortraitUI</class>
+ <widget class="QWidget" name="PortraitUI">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>201</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="styleSheet">
+ <string notr="true">font-weight: bold;</string>
+ </property>
+ <property name="text">
+ <string>Portrait mode</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QPushButton" name="exitButton">
+ <property name="text">
+ <string>Exit</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="helpLabel">
+ <property name="text">
+ <string>Switch to landscape mode. In landscape mode you can change visible image.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QWidget" name="choiceWidget" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>