diff options
author | Jason Barron <jbarron@trolltech.com> | 2009-06-25 13:49:53 (GMT) |
---|---|---|
committer | Jason Barron <jbarron@trolltech.com> | 2009-06-25 13:49:53 (GMT) |
commit | db8f05e257019694f5e8076845626008f2adc3dd (patch) | |
tree | 05d3959403cf15ac5f702091439e028af01f343b /examples/graphicsview/basicgraphicslayouts | |
parent | 8aafaa65a1d16f8b982279f5aceedf1e281ddb5a (diff) | |
parent | 796a5a2c7d8c91a46ac761dde18b7da2ec6c177b (diff) | |
download | Qt-db8f05e257019694f5e8076845626008f2adc3dd.zip Qt-db8f05e257019694f5e8076845626008f2adc3dd.tar.gz Qt-db8f05e257019694f5e8076845626008f2adc3dd.tar.bz2 |
Merge commit 'qt/master-stable' into 4.6-stable
Bring Qt 4.6 into the Qt-S60 repo.
Conflicts:
configure.exe
mkspecs/features/qttest_p4.prf
qmake/generators/makefile.cpp
src/corelib/io/qdir.cpp
src/corelib/io/qprocess.h
src/corelib/kernel/qcoreevent.h
src/corelib/kernel/qobject.cpp
src/corelib/kernel/qsharedmemory_unix.cpp
src/corelib/thread/qthread_p.h
src/corelib/tools/qvector.h
src/gui/dialogs/qdialog.cpp
src/gui/dialogs/qfiledialog.cpp
src/gui/dialogs/qfiledialog_p.h
src/gui/dialogs/qmessagebox.cpp
src/gui/graphicsview/qgraphicsitem.cpp
src/gui/graphicsview/qgraphicsview.cpp
src/gui/image/qpixmapcache.cpp
src/gui/kernel/qapplication.cpp
src/gui/kernel/qapplication_p.h
src/gui/kernel/qwidget.cpp
src/gui/kernel/qwidget_p.h
src/gui/painting/qdrawhelper.cpp
src/gui/painting/qpaintengine_raster.cpp
src/gui/text/qfontengine_qpf.cpp
src/gui/widgets/qmenubar.cpp
src/network/socket/qlocalserver.cpp
src/testlib/qtestcase.cpp
src/testlib/testlib.pro
tests/auto/qimagereader/tst_qimagereader.cpp
tests/auto/qitemdelegate/tst_qitemdelegate.cpp
tests/auto/qnetworkreply/tst_qnetworkreply.cpp
tests/auto/qpixmap/qpixmap.pro
Diffstat (limited to 'examples/graphicsview/basicgraphicslayouts')
-rw-r--r-- | examples/graphicsview/basicgraphicslayouts/layoutitem.cpp | 50 | ||||
-rw-r--r-- | examples/graphicsview/basicgraphicslayouts/layoutitem.h | 12 |
2 files changed, 49 insertions, 13 deletions
diff --git a/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp b/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp index 8216b6e..7311b65 100644 --- a/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp +++ b/examples/graphicsview/basicgraphicslayouts/layoutitem.cpp @@ -43,19 +43,18 @@ //! [0] LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/) - : QGraphicsWidget(parent) + : QGraphicsLayoutItem(), QGraphicsItem(parent) { - pix = new QPixmap(QLatin1String(":/images/block.png")); - // Do not allow a size smaller than the pixmap with two frames around it. - setMinimumSize(pix->size() + QSize(12, 12)); + m_pix = new QPixmap(QLatin1String(":/images/block.png")); + setGraphicsItem(this); } //! [0] LayoutItem::~LayoutItem() { - delete pix; + delete m_pix; } - + //! [1] void LayoutItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/) @@ -64,8 +63,8 @@ void LayoutItem::paint(QPainter *painter, Q_UNUSED(option); QRectF frame(QPointF(0,0), geometry().size()); - qreal w = pix->width(); - qreal h = pix->height(); + qreal w = m_pix->width(); + qreal h = m_pix->height(); QGradientStops stops; //! [1] @@ -94,6 +93,39 @@ void LayoutItem::paint(QPainter *painter, gradient.setStops(stops); painter->setBrush(QBrush(gradient)); painter->drawRoundedRect(innerFrame, 10.0, 10.0); - painter->drawPixmap(pixpos, *pix); + painter->drawPixmap(pixpos, *m_pix); } //! [2] + +//! [3] +QRectF LayoutItem::boundingRect() const +{ + return QRectF(QPointF(0,0), geometry().size()); +} +//! [3] + +//! [4] +void LayoutItem::setGeometry(const QRectF &geom) +{ + prepareGeometryChange(); + QGraphicsLayoutItem::setGeometry(geom); + setPos(geom.topLeft()); +} +//! [4] + +//! [5] +QSizeF LayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const +{ + switch (which) { + case Qt::MinimumSize: + case Qt::PreferredSize: + // Do not allow a size smaller than the pixmap with two frames around it. + return m_pix->size() + QSize(12, 12); + case Qt::MaximumSize: + return QSizeF(1000,1000); + default: + break; + } + return constraint; +} +//! [5] diff --git a/examples/graphicsview/basicgraphicslayouts/layoutitem.h b/examples/graphicsview/basicgraphicslayouts/layoutitem.h index cbda636..8ec9038 100644 --- a/examples/graphicsview/basicgraphicslayouts/layoutitem.h +++ b/examples/graphicsview/basicgraphicslayouts/layoutitem.h @@ -44,18 +44,22 @@ #include <QtGui> //! [0] -class LayoutItem : public QGraphicsWidget +class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem { - Q_OBJECT - public: LayoutItem(QGraphicsItem *parent = 0); ~LayoutItem(); + // Inherited from QGraphicsLayoutItem + void setGeometry(const QRectF &geom); + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; + + // Inherited from QGraphicsItem + QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); private: - QPixmap *pix; + QPixmap *m_pix; }; //! [0] |