![]() |
Здравствуйте, гость ( Вход | Регистрация )
![]() |
_Vitaliy_ |
![]()
Сообщение
#1
|
Студент ![]() Группа: Участник Сообщений: 59 Регистрация: 20.11.2008 Пользователь №: 428 Спасибо сказали: 3 раз(а) Репутация: ![]() ![]() ![]() |
Доброго времени суток.
Практически "нубский" вопрос, поэтому прошу отнестись с нисхождением, графику только осваиваю. В связи с "корявыми руками" не получается реализовать ограничения перемещения объекта на сцене по оси "Y". Беру пример Шлее: CustomGraphicsView, смотрю в стандартных примерах diagramscene, а именно diagramitem.h, там есть QVariant itemChange(GraphicsItemChange change, const QVariant &value); как раз то, что нужно но у меня не получается реализовать это в примере Шлее... выдает ошибку: 'GraphicsItemChange' has not been declared. Взял скопировал целый класс из diagramitem.h, ошибок не выдает, но как его завязать на пример Шлее мозгов не хватает... На всякий случай привожу код: main.cpp Раскрывающийся текст /* ====================================================================== ** main.cpp ** ====================================================================== ** ** ====================================================================== ** Copyright © 2007 by Max Schlee ** ====================================================================== */ #include <QtGui> #include "MyView.h" // ====================================================================== class SimpleItem : public QGraphicsItem { private: enum {nPenWidth = 3}; public: virtual QRectF boundingRect() const { QPointF ptPosition(-10 - nPenWidth, -10 - nPenWidth); QSizeF size(20 + nPenWidth * 2, 20 + nPenWidth * 2); return QRectF(ptPosition, size); } virtual void paint(QPainter* ppainter, const QStyleOptionGraphicsItem*, QWidget* ) { ppainter->save(); ppainter->setPen(QPen(Qt::blue, nPenWidth)); ppainter->drawEllipse(-10, -10, 20, 20); ppainter->restore(); } virtual void mousePressEvent(QGraphicsSceneMouseEvent* pe) { QApplication::setOverrideCursor(Qt::PointingHandCursor); QGraphicsItem::mousePressEvent(pe); } virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* pe) { QApplication::restoreOverrideCursor(); QGraphicsItem::mouseReleaseEvent(pe); } QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; // ---------------------------------------------------------------------- int main(int argc, char** argv) { QApplication app(argc, argv); QWidget wgt; QGraphicsScene scene(QRectF(-100, -100, 640, 480)); MyView* pView = new MyView(&scene); QPushButton* pcmdZoomIn = new QPushButton("&Zoom In"); QPushButton* pcmdZoomOut = new QPushButton("Z&oom Out"); QPushButton* pcmdRotateLeft = new QPushButton("&Rotate Left"); QPushButton* pcmdRotateRight = new QPushButton("Ro&tate Right"); pView->setRenderHint(QPainter::Antialiasing, true); SimpleItem* pSimpleItem = new SimpleItem; scene.addItem(pSimpleItem); pSimpleItem->setPos(0, 0); pSimpleItem->setFlags(QGraphicsItem::ItemIsMovable); QGraphicsPixmapItem* pPixmapItem = scene.addPixmap(QPixmap("haus2.jpg")); pPixmapItem->setParentItem(pSimpleItem); pPixmapItem->setFlags(QGraphicsItem::ItemIsMovable); QObject::connect(pcmdZoomIn, SIGNAL(clicked()), pView, SLOT(slotZoomIn()) ); QObject::connect(pcmdZoomOut, SIGNAL(clicked()), pView, SLOT(slotZoomOut()) ); QObject::connect(pcmdRotateLeft, SIGNAL(clicked()), pView, SLOT(slotRotateLeft()) ); QObject::connect(pcmdRotateRight, SIGNAL(clicked()), pView, SLOT(slotRotateRight()) ); //Layout setup QVBoxLayout* pvbxLayout = new QVBoxLayout; pvbxLayout->addWidget(pView); pvbxLayout->addWidget(pcmdZoomIn); pvbxLayout->addWidget(pcmdZoomOut); pvbxLayout->addWidget(pcmdRotateLeft); pvbxLayout->addWidget(pcmdRotateRight); wgt.setLayout(pvbxLayout); wgt.show(); return app.exec(); } MyView.h Раскрывающийся текст #ifndef _MyView_h_ #define _MyView_h_ #include <QGraphicsView> class QGraphicsItem; class QGraphicsScene; #include <QList> #include <QGraphicsPixmapItem> #include <QList> QT_BEGIN_NAMESPACE class QPixmap; class QGraphicsItem; class QGraphicsScene; class QTextEdit; class QGraphicsSceneMouseEvent; class QMenu; class QGraphicsSceneContextMenuEvent; class QPainter; class QStyleOptionGraphicsItem; class QWidget; class QPolygonF; QT_END_NAMESPACE // ====================================================================== class MyView: public QGraphicsView { Q_OBJECT public: MyView(QGraphicsScene* pScene, QWidget* pwgt = 0) : QGraphicsView(pScene, pwgt) { } public slots: void slotZoomIn() { scale(1.1, 1.1); } void slotZoomOut() { scale(1 / 1.1, 1 / 1.1); } void slotRotateLeft() { rotate(-5); } void slotRotateRight() { rotate(5); } private: }; class DiagramItem : public QGraphicsPolygonItem { public: enum { Type = UserType + 15 }; enum DiagramType { Step, Conditional, StartEnd, Io }; DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = 0, QGraphicsScene *scene = 0); DiagramType diagramType() const { return myDiagramType; } QPolygonF polygon() const { return myPolygon; } QPixmap image() const; int type() const { return Type;} protected: void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); QVariant itemChange(GraphicsItemChange change, const QVariant &value); private: DiagramType myDiagramType; QPolygonF myPolygon; QMenu *myContextMenu; }; Честно признаюсь, по форумам смотрел, у поисковиков спрашивал... Просьба подсказать как реализовать или дать вектор направления. |
|
|
![]() ![]() ![]() |
![]() |
|
Текстовая версия | Сейчас: 13.7.2025, 15:27 |