diff options
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 | 55 | ||||
-rw-r--r-- | examples/widgets/orientation/mainwindow.cpp | 115 | ||||
-rw-r--r-- | examples/widgets/orientation/mainwindow.h | 73 | ||||
-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, 466 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..17e0da0 --- /dev/null +++ b/examples/widgets/orientation/main.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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..246a79d --- /dev/null +++ b/examples/widgets/orientation/mainwindow.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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..400a6a5 --- /dev/null +++ b/examples/widgets/orientation/mainwindow.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#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> |