diff options
author | David Boddie <david.boddie@nokia.com> | 2011-04-28 17:39:11 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2011-04-28 17:39:11 (GMT) |
commit | 3abaecc3aec4e46f1c5969c33875fd45aa542385 (patch) | |
tree | 58613c5d2b765018c31d0b189e9c5a34d8adde69 /examples/widgets/orientation | |
parent | ddb22795641253a026b72f752ebc769745dd41be (diff) | |
download | Qt-3abaecc3aec4e46f1c5969c33875fd45aa542385.zip Qt-3abaecc3aec4e46f1c5969c33875fd45aa542385.tar.gz Qt-3abaecc3aec4e46f1c5969c33875fd45aa542385.tar.bz2 |
Squashed commit of the changes from the mobile-examples repository
(4.7-generated-declarative branch).
Diffstat (limited to 'examples/widgets/orientation')
-rw-r--r-- | examples/widgets/orientation/image_a.png | bin | 0 -> 1075 bytes | |||
-rw-r--r-- | examples/widgets/orientation/image_b.png | bin | 0 -> 1020 bytes | |||
-rw-r--r-- | examples/widgets/orientation/image_c.png | bin | 0 -> 1163 bytes | |||
-rw-r--r-- | examples/widgets/orientation/images.qrc | 7 | ||||
-rw-r--r-- | examples/widgets/orientation/landscape.ui | 114 | ||||
-rw-r--r-- | examples/widgets/orientation/main.cpp | 15 | ||||
-rw-r--r-- | examples/widgets/orientation/mainwindow.cpp | 75 | ||||
-rw-r--r-- | examples/widgets/orientation/mainwindow.h | 33 | ||||
-rw-r--r-- | examples/widgets/orientation/orientation.desktop | 11 | ||||
-rw-r--r-- | examples/widgets/orientation/orientation.pro | 30 | ||||
-rw-r--r-- | examples/widgets/orientation/portrait.ui | 61 |
11 files changed, 346 insertions, 0 deletions
diff --git a/examples/widgets/orientation/image_a.png b/examples/widgets/orientation/image_a.png Binary files differnew file mode 100644 index 0000000..4a1a0d3 --- /dev/null +++ b/examples/widgets/orientation/image_a.png diff --git a/examples/widgets/orientation/image_b.png b/examples/widgets/orientation/image_b.png Binary files differnew file mode 100644 index 0000000..8722d1e --- /dev/null +++ b/examples/widgets/orientation/image_b.png diff --git a/examples/widgets/orientation/image_c.png b/examples/widgets/orientation/image_c.png Binary files differnew file mode 100644 index 0000000..6c9304f --- /dev/null +++ b/examples/widgets/orientation/image_c.png diff --git a/examples/widgets/orientation/images.qrc b/examples/widgets/orientation/images.qrc new file mode 100644 index 0000000..b258291 --- /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 0000000..4616c04 --- /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 0000000..34b05d6 --- /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 0000000..328af44 --- /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 0000000..7c2546d --- /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 0000000..7bbf558 --- /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 0000000..c146322 --- /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 0000000..31a55af --- /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> |