summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/graphicsview/dragdroprobot/main.cpp102
-rw-r--r--examples/graphicsview/dragdroprobot/robot.cpp7
2 files changed, 107 insertions, 2 deletions
diff --git a/examples/graphicsview/dragdroprobot/main.cpp b/examples/graphicsview/dragdroprobot/main.cpp
index 30b8b70..b00bf72 100644
--- a/examples/graphicsview/dragdroprobot/main.cpp
+++ b/examples/graphicsview/dragdroprobot/main.cpp
@@ -46,6 +46,100 @@
#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);
@@ -62,17 +156,21 @@ int main(int argc, char **argv)
scene.addItem(item);
}
- Robot *robot = new 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::BoundingRectViewportUpdate);
+ view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
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 029a2ce..796336a 100644
--- a/examples/graphicsview/dragdroprobot/robot.cpp
+++ b/examples/graphicsview/dragdroprobot/robot.cpp
@@ -164,6 +164,13 @@ 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);