summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-04-17 07:23:47 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-04-17 07:23:47 (GMT)
commit58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b (patch)
tree5f265a6f87cabef61dd763aab3d76e200d8d67a3 /examples
parentac7484e36bfab69473278d7268cf37f7c69abfd2 (diff)
parentd43d33eb3121519d0025ad433d5c186365c47ef6 (diff)
downloadQt-58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b.zip
Qt-58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b.tar.gz
Qt-58f8796ae4d9dcb9e741d2a07c87e6b82a2a4d9b.tar.bz2
Merge branch 'qt/main'
Conflicts: src/opengl/opengl.pro
Diffstat (limited to 'examples')
-rw-r--r--examples/graphicsview/collidingmice/main.cpp4
-rw-r--r--examples/graphicsview/collidingmice/mouse.cpp5
-rw-r--r--examples/graphicsview/collidingmice/mouse.h7
-rw-r--r--examples/graphicsview/flowlayout/flowlayout.cpp49
-rw-r--r--examples/graphicsview/flowlayout/flowlayout.h43
-rw-r--r--examples/graphicsview/flowlayout/main.cpp43
-rw-r--r--examples/graphicsview/flowlayout/window.cpp47
-rw-r--r--examples/graphicsview/flowlayout/window.h43
-rw-r--r--examples/layouts/flowlayout/flowlayout.cpp63
-rw-r--r--examples/layouts/flowlayout/flowlayout.h9
-rw-r--r--examples/widgets/codeeditor/codeeditor.cpp2
-rw-r--r--examples/widgets/movie/movie.pro2
12 files changed, 285 insertions, 32 deletions
diff --git a/examples/graphicsview/collidingmice/main.cpp b/examples/graphicsview/collidingmice/main.cpp
index 4a44481..23c91b0 100644
--- a/examples/graphicsview/collidingmice/main.cpp
+++ b/examples/graphicsview/collidingmice/main.cpp
@@ -83,6 +83,10 @@ int main(int argc, char **argv)
view.resize(400, 300);
view.show();
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
+ timer.start(1000 / 33);
+
return app.exec();
}
//! [6]
diff --git a/examples/graphicsview/collidingmice/mouse.cpp b/examples/graphicsview/collidingmice/mouse.cpp
index 1d10574..bbdb4e3 100644
--- a/examples/graphicsview/collidingmice/mouse.cpp
+++ b/examples/graphicsview/collidingmice/mouse.cpp
@@ -65,7 +65,6 @@ Mouse::Mouse()
color(qrand() % 256, qrand() % 256, qrand() % 256)
{
rotate(qrand() % (360 * 16));
- startTimer(1000 / 33);
}
//! [0]
@@ -123,8 +122,10 @@ void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *
//! [3]
//! [4]
-void Mouse::timerEvent(QTimerEvent *)
+void Mouse::advance(int step)
{
+ if (!step)
+ return;
//! [4]
// Don't move too far away
//! [5]
diff --git a/examples/graphicsview/collidingmice/mouse.h b/examples/graphicsview/collidingmice/mouse.h
index 832ea53..c08ce4a 100644
--- a/examples/graphicsview/collidingmice/mouse.h
+++ b/examples/graphicsview/collidingmice/mouse.h
@@ -43,13 +43,10 @@
#define MOUSE_H
#include <QGraphicsItem>
-#include <QObject>
//! [0]
-class Mouse : public QObject, public QGraphicsItem
+class Mouse : public QGraphicsItem
{
- Q_OBJECT
-
public:
Mouse();
@@ -59,7 +56,7 @@ public:
QWidget *widget);
protected:
- void timerEvent(QTimerEvent *event);
+ void advance(int step);
private:
qreal angle;
diff --git a/examples/graphicsview/flowlayout/flowlayout.cpp b/examples/graphicsview/flowlayout/flowlayout.cpp
index d1676bc..d36c37f 100644
--- a/examples/graphicsview/flowlayout/flowlayout.cpp
+++ b/examples/graphicsview/flowlayout/flowlayout.cpp
@@ -1,3 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include "flowlayout.h"
#include <QtGui/qwidget.h>
#include <QtCore/qmath.h>
@@ -33,6 +74,7 @@ QGraphicsLayoutItem *FlowLayout::itemAt(int index) const
void FlowLayout::removeAt(int index)
{
m_items.removeAt(index);
+ invalidate();
}
qreal FlowLayout::spacing(Qt::Orientation o) const
@@ -54,7 +96,7 @@ void FlowLayout::setGeometry(const QRectF &geom)
doLayout(geom, true);
}
-qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry)
+qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
{
QPointF tl = geom.topLeft();
qreal maxw = geom.width();
@@ -98,15 +140,14 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
if (constraint.width() > 0) { // height for width
- FlowLayout *that = const_cast<FlowLayout *>(this);
- qreal height = that->doLayout(QRectF(QPointF(0,0), constraint), false);
+ qreal height = doLayout(QRectF(QPointF(0,0), constraint), false);
size = QSizeF(constraint.width(), height);
} else {
QGraphicsLayoutItem *item;
foreach (item, m_items)
size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
size += QSize(left + right, top + bottom);
- }
+ }
return size;
}
diff --git a/examples/graphicsview/flowlayout/flowlayout.h b/examples/graphicsview/flowlayout/flowlayout.h
index ab3d33b..c1e5635 100644
--- a/examples/graphicsview/flowlayout/flowlayout.h
+++ b/examples/graphicsview/flowlayout/flowlayout.h
@@ -1,3 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include <QtGui/qgraphicslayout.h>
class FlowLayout : public QGraphicsLayout
@@ -20,7 +61,7 @@ protected:
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
private:
- qreal doLayout(const QRectF &geom, bool applyNewGeometry);
+ qreal doLayout(const QRectF &geom, bool applyNewGeometry) const;
QSizeF minSize(const QSizeF &constraint) const;
QSizeF prefSize() const;
QSizeF maxSize() const;
diff --git a/examples/graphicsview/flowlayout/main.cpp b/examples/graphicsview/flowlayout/main.cpp
index a7af2d4..d1a40c7 100644
--- a/examples/graphicsview/flowlayout/main.cpp
+++ b/examples/graphicsview/flowlayout/main.cpp
@@ -1,3 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include <QtGui>
#include "window.h"
@@ -11,4 +52,4 @@ int main(int argc, char **argv)
scene.addItem(w);
view->show();
return app.exec();
-} \ No newline at end of file
+}
diff --git a/examples/graphicsview/flowlayout/window.cpp b/examples/graphicsview/flowlayout/window.cpp
index b632bc9..dd53b56 100644
--- a/examples/graphicsview/flowlayout/window.cpp
+++ b/examples/graphicsview/flowlayout/window.cpp
@@ -1,3 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include <QtGui/qgraphicsproxywidget.h>
#include <QtGui/qlabel.h>
#include "flowlayout.h"
@@ -7,7 +48,9 @@ Window::Window()
: QGraphicsWidget(0, Qt::Window)
{
FlowLayout *lay = new FlowLayout;
- QString sentence(QLatin1String("I am not bothered by the fact that I am unknown. I am bothered when I do not know others."));
+ QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
+ "I am bothered when I do not know others. (Confucius)");
+ QString sentence(wiseWords);
QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
for (int i = 0; i < words.count(); ++i) {
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
@@ -17,4 +60,4 @@ Window::Window()
lay->addItem(proxy);
}
setLayout(lay);
-} \ No newline at end of file
+}
diff --git a/examples/graphicsview/flowlayout/window.h b/examples/graphicsview/flowlayout/window.h
index 50dac92..6d315f5 100644
--- a/examples/graphicsview/flowlayout/window.h
+++ b/examples/graphicsview/flowlayout/window.h
@@ -1,7 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include <QtGui/qgraphicswidget.h>
class Window : public QGraphicsWidget {
Q_OBJECT
public:
Window();
-}; \ No newline at end of file
+};
diff --git a/examples/layouts/flowlayout/flowlayout.cpp b/examples/layouts/flowlayout/flowlayout.cpp
index d1e857d..be6b476 100644
--- a/examples/layouts/flowlayout/flowlayout.cpp
+++ b/examples/layouts/flowlayout/flowlayout.cpp
@@ -43,16 +43,16 @@
#include "flowlayout.h"
-FlowLayout::FlowLayout(QWidget *parent, int margin, int spacing)
- : QLayout(parent)
+FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
+ : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setMargin(margin);
- setSpacing(spacing);
}
-FlowLayout::FlowLayout(int spacing)
+FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
+ : m_hSpace(hSpacing), m_vSpace(vSpacing)
{
- setSpacing(spacing);
+ setMargin(margin);
}
FlowLayout::~FlowLayout()
@@ -67,6 +67,24 @@ void FlowLayout::addItem(QLayoutItem *item)
itemList.append(item);
}
+int FlowLayout::horizontalSpacing() const
+{
+ if (m_hSpace >= 0) {
+ return m_hSpace;
+ } else {
+ return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
+ }
+}
+
+int FlowLayout::verticalSpacing() const
+{
+ if (m_vSpace >= 0) {
+ return m_vSpace;
+ } else {
+ return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
+ }
+}
+
int FlowLayout::count() const
{
return itemList.size();
@@ -125,20 +143,27 @@ QSize FlowLayout::minimumSize() const
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
- int x = rect.x();
- int y = rect.y();
+ int left, top, right, bottom;
+ getContentsMargins(&left, &top, &right, &bottom);
+ QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
+ int x = effectiveRect.x();
+ int y = effectiveRect.y();
int lineHeight = 0;
QLayoutItem *item;
foreach (item, itemList) {
QWidget *wid = item->widget();
- int spaceX = spacing() + wid->style()->layoutSpacing(
+ int spaceX = horizontalSpacing();
+ if (spaceX == -1)
+ spaceX = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
- int spaceY = spacing() + wid->style()->layoutSpacing(
+ int spaceY = verticalSpacing();
+ if (spaceY == -1)
+ spaceY = wid->style()->layoutSpacing(
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
int nextX = x + item->sizeHint().width() + spaceX;
- if (nextX - spaceX > rect.right() && lineHeight > 0) {
- x = rect.x();
+ if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
+ x = effectiveRect.x();
y = y + lineHeight + spaceY;
nextX = x + item->sizeHint().width() + spaceX;
lineHeight = 0;
@@ -150,5 +175,19 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
x = nextX;
lineHeight = qMax(lineHeight, item->sizeHint().height());
}
- return y + lineHeight - rect.y();
+ return y + lineHeight - rect.y() + bottom;
}
+
+int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
+{
+ QObject *parent = this->parent();
+ if (!parent) {
+ return -1;
+ } else if (parent->isWidgetType()) {
+ QWidget *pw = static_cast<QWidget *>(parent);
+ return pw->style()->pixelMetric(pm, 0, pw);
+ } else {
+ return static_cast<QLayout *>(parent)->spacing();
+ }
+}
+
diff --git a/examples/layouts/flowlayout/flowlayout.h b/examples/layouts/flowlayout/flowlayout.h
index f864d8e..9940e55 100644
--- a/examples/layouts/flowlayout/flowlayout.h
+++ b/examples/layouts/flowlayout/flowlayout.h
@@ -49,11 +49,13 @@
class FlowLayout : public QLayout
{
public:
- FlowLayout(QWidget *parent, int margin = -1, int spacing = 0);
- FlowLayout(int spacing = 0);
+ FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
+ FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void addItem(QLayoutItem *item);
+ int horizontalSpacing() const;
+ int verticalSpacing() const;
Qt::Orientations expandingDirections() const;
bool hasHeightForWidth() const;
int heightForWidth(int) const;
@@ -66,8 +68,11 @@ public:
private:
int doLayout(const QRect &rect, bool testOnly) const;
+ int smartSpacing(QStyle::PixelMetric pm) const;
QList<QLayoutItem *> itemList;
+ int m_hSpace;
+ int m_vSpace;
};
#endif
diff --git a/examples/widgets/codeeditor/codeeditor.cpp b/examples/widgets/codeeditor/codeeditor.cpp
index b855c7a..615f39f 100644
--- a/examples/widgets/codeeditor/codeeditor.cpp
+++ b/examples/widgets/codeeditor/codeeditor.cpp
@@ -41,7 +41,7 @@
#include <QtGui>
-#include <codeeditor.h>
+#include "codeeditor.h"
//![constructor]
diff --git a/examples/widgets/movie/movie.pro b/examples/widgets/movie/movie.pro
index b5f0a7a..1c7cbae 100644
--- a/examples/widgets/movie/movie.pro
+++ b/examples/widgets/movie/movie.pro
@@ -4,6 +4,6 @@ SOURCES = main.cpp \
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie
-sources.files = $$SOURCES $$HEADERS $$RESOURCES movie.pro movies
+sources.files = $$SOURCES $$HEADERS $$RESOURCES movie.pro animation.mng
sources.path = $$[QT_INSTALL_EXAMPLES]/widgets/movie
INSTALLS += target sources