diff options
-rw-r--r-- | examples/graphicsview/dragdroprobot/main.cpp | 102 | ||||
-rw-r--r-- | examples/graphicsview/dragdroprobot/robot.cpp | 7 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect.cpp | 3 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect.h | 53 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicseffect_p.h | 13 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 12 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 4 |
7 files changed, 39 insertions, 155 deletions
diff --git a/examples/graphicsview/dragdroprobot/main.cpp b/examples/graphicsview/dragdroprobot/main.cpp index b00bf72..30b8b70 100644 --- a/examples/graphicsview/dragdroprobot/main.cpp +++ b/examples/graphicsview/dragdroprobot/main.cpp @@ -46,100 +46,6 @@ #include <math.h> -Robot *robot = 0; - -class MyGraphicsEffect : public QGraphicsEffect -{ -public: - void draw(QPainter *painter, QGraphicsEffectSource *source) - { - painter->save(); - - QPen pen; - static int color = Qt::black; - pen.setColor(Qt::GlobalColor(color)); - if (color++ >= Qt::darkYellow) - color = Qt::black; - pen.setWidth(3); - painter->setPen(pen); - - source->draw(painter); - - painter->restore(); - } -}; - -class MyWidget : public QWidget -{ - Q_OBJECT -public: - MyWidget(QWidget *parent = 0) : QWidget(parent) - { - setLayout(new QVBoxLayout); - QComboBox *box = new QComboBox; - box->addItem("None"); - box->addItem("Blur"); - box->addItem("Colorize"); - box->addItem("Pixelize"); - box->addItem("Grayscale"); - box->addItem("Bloom"); - box->addItem("Shadow"); - box->addItem("Custom"); - layout()->addWidget(box); - connect(box, SIGNAL(currentIndexChanged(int)), this, SLOT(changeEffect(int))); - } - -public slots: - void changeEffect(int index) - { - switch (index) { - case 0: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(0); - break; - case 1: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(new QGraphicsBlurEffect); - break; - case 2: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(new QGraphicsColorizeEffect); - break; - case 3: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(new QGraphicsPixelizeEffect); - break; - case 4: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(new QGraphicsGrayscaleEffect); - break; - case 5: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(new QGraphicsBloomEffect); - break; - case 6: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(new QGraphicsShadowEffect); - break; - case 7: - delete robot->graphicsEffect(); - robot->setGraphicsEffect(new MyGraphicsEffect); - break; - default: - break; - } - } -protected: - void paintEvent(QPaintEvent *) {} - void mousePressEvent(QMouseEvent *) {} - void mouseReleaseEvent(QMouseEvent *) {} - -private: -}; - -#include "main.moc" - - int main(int argc, char **argv) { QApplication app(argc, argv); @@ -156,21 +62,17 @@ int main(int argc, char **argv) scene.addItem(item); } - robot = new Robot; + Robot *robot = new Robot; robot->scale(1.2, 1.2); robot->setPos(0, -20); scene.addItem(robot); QGraphicsView view(&scene); view.setRenderHint(QPainter::Antialiasing); - view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); view.setBackgroundBrush(QColor(230, 200, 167)); view.setWindowTitle("Drag and Drop Robot"); - // view.rotate(45); view.show(); - MyWidget widget; - widget.show(); - return app.exec(); } diff --git a/examples/graphicsview/dragdroprobot/robot.cpp b/examples/graphicsview/dragdroprobot/robot.cpp index 796336a..029a2ce 100644 --- a/examples/graphicsview/dragdroprobot/robot.cpp +++ b/examples/graphicsview/dragdroprobot/robot.cpp @@ -164,13 +164,6 @@ void RobotLimb::paint(QPainter *painter, Robot::Robot() { QGraphicsItem *torsoItem = new RobotTorso(this); - // torsoItem->setGraphicsEffect(new QGraphicsBloomEffect); - // torsoItem->setGraphicsEffect(new QGraphicsBlurEffect); - // torsoItem->setGraphicsEffect(new QGraphicsFrameEffect); - // torsoItem->setGraphicsEffect(new QGraphicsShadowEffect); - // torsoItem->setGraphicsEffect(new QGraphicsColorizeEffect); - // torsoItem->setGraphicsEffect(new QGraphicsPixelizeEffect); - // torsoItem->setGraphicsEffect(new QGraphicsGrayscaleEffect); QGraphicsItem *headItem = new RobotHead(torsoItem); QGraphicsItem *upperLeftArmItem = new RobotLimb(torsoItem); QGraphicsItem *lowerLeftArmItem = new RobotLimb(upperLeftArmItem); diff --git a/src/gui/graphicsview/qgraphicseffect.cpp b/src/gui/graphicsview/qgraphicseffect.cpp index d98ea3c..ef7341a 100644 --- a/src/gui/graphicsview/qgraphicseffect.cpp +++ b/src/gui/graphicsview/qgraphicseffect.cpp @@ -44,9 +44,8 @@ #ifndef QT_NO_GRAPHICSVIEW #include <QtGui/qimage.h> -#include <QtGui/qgraphicsitem.h> -#include <QtGui/qgraphicsscene.h> #include <QtGui/qpainter.h> +#include <QtCore/qrect.h> /* diff --git a/src/gui/graphicsview/qgraphicseffect.h b/src/gui/graphicsview/qgraphicseffect.h index 9714d3e..8cf80b9 100644 --- a/src/gui/graphicsview/qgraphicseffect.h +++ b/src/gui/graphicsview/qgraphicseffect.h @@ -43,18 +43,7 @@ #define QGRAPHICSEFFECT_H #include <QtCore/qobject.h> -#include <QtCore/qglobal.h> #include <QtCore/qpoint.h> -#include <QtCore/qvariant.h> -#include <QtGui/qtransform.h> -#include <QtGui/qcolor.h> - -QT_FORWARD_DECLARE_CLASS(QGraphicsItem); -QT_FORWARD_DECLARE_CLASS(QStyleOptionGraphicsItem); -QT_FORWARD_DECLARE_CLASS(QPainter); -QT_FORWARD_DECLARE_CLASS(QPixmap); -QT_FORWARD_DECLARE_CLASS(QWidget); -QT_FORWARD_DECLARE_CLASS(QPixmapColorizeFilter); QT_BEGIN_HEADER @@ -64,8 +53,14 @@ QT_MODULE(Gui) #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW -class QGraphicsEffectSourcePrivate; +class QGraphicsItem; class QStyleOption; +class QColor; +class QPainter; +class QRectF; +class QPixmap; + +class QGraphicsEffectSourcePrivate; class Q_GUI_EXPORT QGraphicsEffectSource : public QObject { Q_OBJECT @@ -73,9 +68,11 @@ public: ~QGraphicsEffectSource(); const QGraphicsItem *graphicsItem() const; const QStyleOption *styleOption() const; + + bool isPixmap() const; void draw(QPainter *painter); void update(); - bool isPixmap() const; + QRectF boundingRect(Qt::CoordinateSystem coordinateSystem = Qt::LogicalCoordinates) const; QPixmap pixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, QPoint *offset = 0) const; @@ -99,15 +96,18 @@ class Q_GUI_EXPORT QGraphicsEffect : public QObject public: QGraphicsEffect(); virtual ~QGraphicsEffect(); + + virtual QRectF boundingRectFor(const QRectF &rect) const; QRectF boundingRect() const; void setSourcePixmap(const QPixmap &pixmap); QPixmap sourcePixmap() const; bool hasSourcePixmap() const; - virtual QRectF boundingRectFor(const QRectF &rect) const; - bool isEnabled() const; + QGraphicsEffectSource *source() const; + bool isEnabled() const; + public Q_SLOTS: void setEnabled(bool enable); @@ -187,8 +187,6 @@ public: int blurRadius() const; void setBlurRadius(int blurRadius); - // QRectF boundingRect() const; - protected: QRectF boundingRectFor(const QRectF &rect) const; void draw(QPainter *painter, QGraphicsEffectSource *source); @@ -211,8 +209,6 @@ public: qreal opacity() const; void setOpacity(qreal opacity); - // QRectF boundingRect() const; - protected: QRectF boundingRectFor(const QRectF &rect) const; void draw(QPainter *painter, QGraphicsEffectSource *source); @@ -238,8 +234,6 @@ public: qreal frameOpacity() const; void setFrameOpacity(qreal opacity); - // QRectF boundingRect() const; - protected: QRectF boundingRectFor(const QRectF &rect) const; void draw(QPainter *painter, QGraphicsEffectSource *source); @@ -258,8 +252,10 @@ public: QPointF shadowOffset() const; void setShadowOffset(const QPointF &ofs); - inline void setShadowOffset(qreal dx, qreal dy) { setShadowOffset(QPointF(dx, dy)); } - inline void setShadowOffset(qreal d) { setShadowOffset(QPointF(d, d)); } + inline void setShadowOffset(qreal dx, qreal dy) + { setShadowOffset(QPointF(dx, dy)); } + inline void setShadowOffset(qreal d) + { setShadowOffset(QPointF(d, d)); } int blurRadius() const; void setBlurRadius(int blurRadius); @@ -267,8 +263,6 @@ public: qreal opacity() const; void setOpacity(qreal opacity); - // QRectF boundingRect() const; - protected: QRectF boundingRectFor(const QRectF &rect) const; void draw(QPainter *painter, QGraphicsEffectSource *source); @@ -278,15 +272,6 @@ private: Q_DISABLE_COPY(QGraphicsShadowEffect) }; -Q_DECLARE_METATYPE(QGraphicsEffect *) -Q_DECLARE_METATYPE(QGraphicsGrayscaleEffect *) -Q_DECLARE_METATYPE(QGraphicsColorizeEffect *) -Q_DECLARE_METATYPE(QGraphicsPixelizeEffect *) -Q_DECLARE_METATYPE(QGraphicsBlurEffect *) -Q_DECLARE_METATYPE(QGraphicsBloomEffect *) -Q_DECLARE_METATYPE(QGraphicsFrameEffect *) -Q_DECLARE_METATYPE(QGraphicsShadowEffect *) - #endif // QT_NO_GRAPHICSVIEW QT_END_NAMESPACE diff --git a/src/gui/graphicsview/qgraphicseffect_p.h b/src/gui/graphicsview/qgraphicseffect_p.h index 6a0bb3f..2d4a5ee 100644 --- a/src/gui/graphicsview/qgraphicseffect_p.h +++ b/src/gui/graphicsview/qgraphicseffect_p.h @@ -54,13 +54,20 @@ // #include "qgraphicseffect.h" + +#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW + #include <private/qobject_p.h> #include <private/qpixmapfilter_p.h> -#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW +#include <QtCore/qrect.h> +#include <QtCore/qpoint.h> +#include <QtGui/qcolor.h> QT_BEGIN_NAMESPACE +class QPainter; + class QGraphicsEffectSourcePrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QGraphicsEffectSource) @@ -85,7 +92,7 @@ class QGraphicsEffectPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QGraphicsEffect) public: QGraphicsEffectPrivate() : source(0), hasSourcePixmap(0), isEnabled(1) {} - QGraphicsEffectSource *source; + inline void setGraphicsEffectSource(QGraphicsEffectSource *newSource) { if (source) { @@ -95,6 +102,8 @@ public: source = newSource; q_func()->sourceChanged(newSource); } + + QGraphicsEffectSource *source; QRectF boundingRect; QPixmap sourcePixmap; quint32 hasSourcePixmap : 1; diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 392fdaa..223c747 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1016,10 +1016,10 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent) */ void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rect) { - // if (!dirtyChildrenBoundingRect) { - // *rect |= x->mapRect(childrenBoundingRect); - // return; - // } + if (!dirtyChildrenBoundingRect) { + *rect |= x->mapRect(childrenBoundingRect); + return; + } for (int i = 0; i < children.size(); ++i) { QGraphicsItem *child = children.at(i); @@ -3845,8 +3845,8 @@ void QGraphicsItem::setZValue(qreal z) */ QRectF QGraphicsItem::childrenBoundingRect() const { - // if (!d_ptr->dirtyChildrenBoundingRect) - // return d_ptr->childrenBoundingRect; + if (!d_ptr->dirtyChildrenBoundingRect) + return d_ptr->childrenBoundingRect; QRectF childRect; QTransform x; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 9ce02a2..7b02883 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4304,10 +4304,6 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * ENSURE_TRANSFORM_PTR; if (item->d_ptr->graphicsEffect && item->d_ptr->graphicsEffect->isEnabled()) { - if (item->type() == 7) { - item->d_ptr->graphicsEffect->setSourcePixmap(static_cast<QGraphicsPixmapItem*>(item) - ->pixmap()); - } ENSURE_TRANSFORM_PTR; QGraphicsItemPaintInfo info(viewTransform, transformPtr, exposedRegion, widget, &styleOptionTmp, painter, opacity, wasDirtyParentSceneTransform, drawItem); |