Source

Target

Showing with 45 additions and 284 deletions
examples/sql/drilldown/images/qt-creator.png

45.8 KB

examples/sql/drilldown/images/qt-logo.png

44.6 KB

examples/sql/drilldown/images/qt-project.png

36.9 KB

examples/sql/drilldown/images/qt-quick.png

42.2 KB

examples/sql/drilldown/images/redwood.png

38.1 KB

......@@ -41,38 +41,35 @@
#include "informationwindow.h"
//! [0]
InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices,
InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items,
QWidget *parent)
: QDialog(parent)
{
//! [0] //! [1]
QLabel *locationLabel = new QLabel(tr("Location: "));
QLabel *countryLabel = new QLabel(tr("Country: "));
QLabel *itemLabel = new QLabel(tr("Item: "));
QLabel *descriptionLabel = new QLabel(tr("Description: "));
QLabel *imageFileLabel = new QLabel(tr("Image file: "));
createButtons();
locationText = new QLabel;
countryText = new QLabel;
itemText = new QLabel;
descriptionEditor = new QTextEdit;
//! [1]
//! [2]
imageFileEditor = new QComboBox;
imageFileEditor->setModel(offices->relationModel(1));
imageFileEditor->setModelColumn(offices->relationModel(1)->fieldIndex("file"));
imageFileEditor->setModel(items->relationModel(1));
imageFileEditor->setModelColumn(items->relationModel(1)->fieldIndex("file"));
//! [2]
//! [3]
mapper = new QDataWidgetMapper(this);
mapper->setModel(offices);
mapper->setModel(items);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setItemDelegate(new QSqlRelationalDelegate(mapper));
mapper->addMapping(imageFileEditor, 1);
mapper->addMapping(locationText, 2, "text");
mapper->addMapping(countryText, 3, "text");
mapper->addMapping(descriptionEditor, 4);
mapper->addMapping(itemText, 2, "text");
mapper->addMapping(descriptionEditor, 3);
mapper->setCurrentIndex(id);
//! [3]
......@@ -83,8 +80,7 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices,
this, SLOT(enableButtons()));
QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(locationLabel, locationText);
formLayout->addRow(countryLabel, countryText);
formLayout->addRow(itemLabel, itemText);
formLayout->addRow(imageFileLabel, imageFileEditor);
formLayout->addRow(descriptionLabel, descriptionEditor);
......@@ -93,23 +89,19 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices,
layout->addWidget(buttonBox);
setLayout(layout);
locationId = id;
itemId = id;
displayedImage = imageFileEditor->currentText();
// Commented the following line. Now the window will look like dialog and the Qt will place the QDialogBox buttons to menu area in Symbian.
// Too bad that the revert button is missing, Should the Qt place the buttons under Option menu in the menu area?!
// If the Qt::Window flag was used, the background of window is white in symbian and the QLabels can't be regognized from the background.
//setWindowFlags(Qt::Window);
setWindowFlags(Qt::Window);
enableButtons(false);
setWindowTitle(tr("Office: %1").arg(locationText->text()));
setWindowTitle(itemText->text());
}
//! [4]
//! [5]
int InformationWindow::id()
{
return locationId;
return itemId;
}
//! [5]
......@@ -128,11 +120,11 @@ void InformationWindow::submit()
if (displayedImage != newImage) {
displayedImage = newImage;
emit imageChanged(locationId, newImage);
emit imageChanged(itemId, newImage);
}
mapper->submit();
mapper->setCurrentIndex(locationId);
mapper->setCurrentIndex(itemId);
enableButtons(false);
}
......
......@@ -50,7 +50,7 @@ class InformationWindow : public QDialog
Q_OBJECT
public:
InformationWindow(int id, QSqlRelationalTableModel *offices,
InformationWindow(int id, QSqlRelationalTableModel *items,
QWidget *parent = 0);
int id();
......@@ -70,12 +70,11 @@ private slots:
private:
void createButtons();
int locationId;
int itemId;
QString displayedImage;
QComboBox *imageFileEditor;
QLabel *locationText;
QLabel *countryText;
QLabel *itemText;
QTextEdit *descriptionEditor;
QPushButton *closeButton;
......
examples/sql/drilldown/logo.png

13.1 KB

......@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
if (!createConnection())
return 1;
View view("offices", "images");
View view("items", "images");
view.show();
#ifdef QT_KEYPAD_NAVIGATION
QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
......
......@@ -43,61 +43,62 @@
#include "view.h"
//! [0]
View::View(const QString &offices, const QString &images, QWidget *parent)
View::View(const QString &items, const QString &images, QWidget *parent)
: QGraphicsView(parent)
{
officeTable = new QSqlRelationalTableModel(this);
officeTable->setTable(offices);
officeTable->setRelation(1, QSqlRelation(images, "locationid", "file"));
officeTable->select();
itemTable = new QSqlRelationalTableModel(this);
itemTable->setTable(items);
itemTable->setRelation(1, QSqlRelation(images, "itemid", "file"));
itemTable->select();
//! [0]
//! [1]
scene = new QGraphicsScene(this);
scene->setSceneRect(0, 0, 465, 615);
scene->setSceneRect(0, 0, 465, 365);
setScene(scene);
addItems();
QGraphicsPixmapItem *logo = scene->addPixmap(QPixmap(":/logo.png"));
logo->setPos(30, 515);
setMinimumSize(470, 370);
setMaximumSize(470, 370);
setMinimumSize(470, 620);
setMaximumSize(470, 620);
setWindowTitle(tr("Offices World Wide"));
QLinearGradient gradient(QPointF(0, 0), QPointF(0, 370));
gradient.setColorAt(0, QColor("#868482"));
gradient.setColorAt(1, QColor("#5d5b59"));
setBackgroundBrush(gradient);
}
//! [1]
//! [3]
void View::addItems()
{
int officeCount = officeTable->rowCount();
int itemCount = itemTable->rowCount();
int imageOffset = 150;
int leftMargin = 70;
int topMargin = 40;
for (int i = 0; i < officeCount; i++) {
for (int i = 0; i < itemCount; i++) {
ImageItem *image;
QGraphicsTextItem *label;
QSqlRecord record = officeTable->record(i);
QSqlRecord record = itemTable->record(i);
int id = record.value("id").toInt();
QString file = record.value("file").toString();
QString location = record.value("location").toString();
QString item = record.value("itemtype").toString();
int columnOffset = ((i / 3) * 37);
int x = ((i / 3) * imageOffset) + leftMargin + columnOffset;
int y = ((i % 3) * imageOffset) + topMargin;
int columnOffset = ((i % 2) * 37);
int x = ((i % 2) * imageOffset) + leftMargin + columnOffset;
int y = ((i / 2) * imageOffset) + topMargin;
image = new ImageItem(id, QPixmap(":/" + file));
image->setData(0, i);
image->setPos(x, y);
scene->addItem(image);
label = scene->addText(location);
QPointF labelOffset((150 - label->boundingRect().width()) / 2, 120.0);
label = scene->addText(item);
label->setDefaultTextColor(QColor("#d7d6d5"));
QPointF labelOffset((120 - label->boundingRect().width()) / 2, 120.0);
label->setPos(QPointF(x, y) + labelOffset);
}
}
......@@ -118,7 +119,7 @@ void View::mouseReleaseEvent(QMouseEvent *event)
void View::showInformation(ImageItem *image)
{
int id = image->id();
if (id < 0 || id >= officeTable->rowCount())
if (id < 0 || id >= itemTable->rowCount())
return;
InformationWindow *window = findWindow(id);
......@@ -129,7 +130,7 @@ void View::showInformation(ImageItem *image)
window->show();
} else {
InformationWindow *window;
window = new InformationWindow(id, officeTable, this);
window = new InformationWindow(id, itemTable, this);
connect(window, SIGNAL(imageChanged(int,QString)),
this, SLOT(updateImage(int,QString)));
......
......@@ -53,7 +53,7 @@ class View : public QGraphicsView
Q_OBJECT
public:
View(const QString &offices, const QString &images, QWidget *parent = 0);
View(const QString &items, const QString &images, QWidget *parent = 0);
protected:
void mouseReleaseEvent(QMouseEvent *event);
......@@ -73,7 +73,7 @@ private:
QGraphicsScene *scene;
QList<InformationWindow *> informationWindows;
//! [2] //! [3]
QSqlRelationalTableModel *officeTable;
QSqlRelationalTableModel *itemTable;
};
//! [3]
......
examples/widgets/doc/images/orientation-landscape-ui.png

17.7 KB

examples/widgets/doc/images/orientation-landscape.png

45.4 KB

examples/widgets/doc/images/orientation-portrait-ui.png

9.56 KB

examples/widgets/doc/images/orientation-portrait.png

17 KB

/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*! \example widgets/orientation
\title Orientation Example
\brief The example shows a simple way to use different UIs depending on the screen
orientation of a mobile device.
\image orientation-landscape.png The UI in landscape mode
\image orientation-portrait.png The UI in portrait mode
The screen on many mobile devices can be viewed in both portrait and
landscape orientation. The orientation can be swiched with the help of a
hardware or software trigger. Due to the often small physical screen size,
user interfaces has to be very simple and compact to stay usable, and
applications usually occupy the whole screen. Designing a user interface
that works equally well in both landscape and portrait mode is not always
possible, however, so making a different layout for each case usually pays
off.
The example application makes use of two different UI widgets created with
the Qt Designer, one for portrait and one for landscape orientation. The
application has a widget that contains an image and the user is able to
select one of three images for it to show. In addition to the two UIs, the
application consists of a \c MainWindow class.
\section1 Landscape UI
If the screen is in landscape mode, the user probably holds the device with
both hands and is ready to give full attention to the application. The
landscape UI looks like this:
\image orientation-landscape-ui.png The landscape UI
To the left is a QWidget called \c choiceWidget, which will show the
current image, and to the right are three QRadioButton instances. The
active radio button specifies the image to show.
\section1 Portrait UI
When the device is in portrait mode, it usually means that the user holds
it with one hand, and can comfortably use the thumb for small amounts of
input. The layout is simpler, and is focused on consuming content. The
portrait UI looks like this:
\image orientation-portrait-ui.png The portrait UI
Similarly, it contains a QWidget, also called \c choiceWidget, that will
show the current image. In contrast to the landscape UI, this one doesn't
provide any controls to change the image.
\section1 MainWindow Class Definition
\c MainWindow inherits from QWidget and acts as the top level widget of the
application.
\snippet widgets/orientation/mainwindow.h 0
The \c resizeEvent() method is re-implemented, and used to check which
UI to show. The \c onRadioButtonClicked() slot is connected to the
landscape UI's radio button group and selects the current image.
\c landscapeWidget and \c portraitWidget will contain the UI layouts. Only
one of them is visible at a time.
\section1 MainWindow Class Implementation
In the constructor, the widgets that will hold the UIs are created and set
up.
\snippet widgets/orientation/mainwindow.cpp 0
Since the exit buttons on the layouts are different from each other, both
of them have to have their \c clicked() signal connected to the \c close()
slot of the main widget. The first image is also made current with the call
to \c onRadioButtonClicked().
\snippet widgets/orientation/mainwindow.cpp 1
On the Maemo platform, windows are stuck in landscape mode by default. The
application has to explicitly say that rotation is supported.
\snippet widgets/orientation/mainwindow.cpp 2
The \c resizeEvent() is called when the main window is first created, and
also whenever the window has been resized. If the window is shown in
full screen, this is an indication that the orientation of the screen has
changed.
The dimensions of \c landscapeWidget is the transpose of the dimensions of
\c portraitWidget. When the orientation is known, both are set to the
(possibly transposed) size of the window. Depending on the orientation, one
widget is made visible and the other invisible.
\snippet widgets/orientation/mainwindow.cpp 3
When the user selects one of the radio buttons in the landscape UI, the
current image is changed. The image is displayed by specifying the
background style of the choice widget. Since both \c portrait and
\c landscape have a \c choiceWidget of their own, the change has to be
reflected in both instances.
\snippet widgets/orientation/mainwindow.cpp 4
Synchronizing both UIs like this might become unfeasible when there are
many things that can change. In that case it is better to make use of the
\l{Introduction to Model/View Programming}{Model-View-Controller pattern}
more extensively and share the content between both portrait and landscape
widgets. Then an interface for displaying and manipulating it can be tailor
made for both orientations.
\section1 The \c main() Function
The main function creates a \c MainWindow instance and shows it full
screen.
\snippet widgets/orientation/main.cpp 0
*/
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*! \example widgets/applicationicon
\title Application Icon Example
\brief The example shows how to add an application icon to a mobile application.
\image appicon_screenshot.png The icon on a Nokia XPressMusic 5800
\section1 Adding the icons to the project
For Maemo, we need to add that the \c .desktop and icon file should be
installed.
\quotefile widgets/applicationicon/applicationicon.pro
Currently, Qt Creator doesn't include the icon and desktop files in the
application package for Maemo, merely the executable file is included. As a
workaround for this, the files can be added manually in the Projects tab.
In the "Create Package" build step for the Maemo target, the \c .desktop
file and icon can be added to be a part of the package contents.
Unfortunately, these additions are only stored as a part of the
\c .pro.user file. This issue will be resolved in a future release of
Qt Creator.
\image appicon_packagecontents.png Manual addition of files to the "Create Package" build step
*/
examples/widgets/widgets/applicationicon/applicationicon.png

3.93 KB

QT += core gui widgets
TARGET = applicationicon
TEMPLATE = app
SOURCES += main.cpp
OTHER_FILES += applicationicon.svg \
applicationicon.png \
applicationicon.desktop
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/applicationicon
INSTALLS += target
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" width="44" height="44" baseProfile="tiny" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 44 44">
<defs>
<linearGradient id="linearGradient2824" y2="1051.4" gradientUnits="userSpaceOnUse" x2="30.217" y1="1009.4" x1="15.109">
<stop stop-color="#41a200" offset="0"/>
<stop stop-color="#9be948" offset="0.63897"/>
<stop stop-color="#beff61" offset="1"/>
</linearGradient>
<linearGradient id="linearGradient2848" y2="1009.4" gradientUnits="userSpaceOnUse" y1="1053.7" gradientTransform="matrix(0.85714286,0,0,0.85714286,2.1428572,146.19467)" x2="15.085" x1="31.027">
<stop stop-color="#41a200" offset="0"/>
<stop stop-color="#9be948" offset="0.88602"/>
<stop stop-color="#beff61" offset="1"/>
</linearGradient>
</defs>
<g id="layer1" transform="translate(0,-1008.3622)">
<path id="rect2816" d="m8.412,1009h27.18c4.106,0,7.412,3.306,7.412,7.412v27.18c0,4.106-3.306,7.412-7.412,7.412h-27.18c-4.106,0-7.412-3-7.412-7v-27.18c0-4.106,3.306-7.412,7.412-7.412z" stroke-linecap="round" stroke-miterlimit="4" stroke-width="0.64300001" fill="url(#linearGradient2824)"/>
<path id="rect2816-4" d="m9.353,1011h25.29c3.52,0,6.353,2.833,6.353,6.353v25.29c0,3.519-2.833,6.353-6.353,6.353h-25.29c-3.52-0.1-6.353-2.1-6.353-6.1v-25.29c0-3.519,2.833-6.353,6.353-6.353z" stroke-linecap="round" stroke-miterlimit="4" stroke-width="0.64300001" fill="url(#linearGradient2848)"/>
<g id="text2893" font-weight="normal" transform="translate(-1.100281,1010.3622)" font-style="normal" font-stretch="normal" font-size="48px" font-variant="normal" font-family="Cambria Math" fill="#e5ffd5">
<path id="path2908" fill="#e5ffd5" d="m11.92,35.44c1.359-1.719,2.672-3.828,3.938-6.328l7.522-14.742c-0.8-3.13-1.54-5.321-2.24-6.586-0.69-1.266-1.76-1.899-3.2-1.899-1.328,0.0000307-2.594,0.6563-3.797,1.969l-1.148-1.266c2.156-2.359,4.289-3.539,6.398-3.539,1.469,0.0000335,2.609,0.418,3.422,1.254,0.8125,0.836,1.492,2.168,2.039,3.996,0.5469,1.828,1.32,5.359,2.32,10.59,1.297,6.828,2.309,11.14,3.035,12.93,0.7265,1.789,1.59,2.684,2.59,2.684,0.7187,0.000002,1.383-0.25,1.992-0.75l0.8906,1.406c-1.547,1.203-2.938,1.805-4.172,1.805-1.75,0-3-0.8984-3.75-2.695-0.75-1.797-1.797-6.633-3.141-14.51h-0.1406c-2.658,5.391-5.258,11.001-7.798,16.831h-4.758z"/>
</g>
</g>
</svg>
\ No newline at end of file