File indexing completed on 2024-04-28 03:51:19
0001 /*. 0002 SPDX-FileCopyrightText: 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef STEP_SPRINGGRAPHICS_H 0008 #define STEP_SPRINGGRAPHICS_H 0009 0010 #include "worldgraphics.h" 0011 #include "stepgraphicsitem.h" 0012 #include <stepcore/spring.h> 0013 0014 class SpringCreator: public AttachableItemCreator 0015 { 0016 public: 0017 SpringCreator(const QString& className, WorldModel* worldModel, WorldScene* worldScene) 0018 : AttachableItemCreator(className, worldModel, worldScene, 0019 WorldScene::SnapRigidBody | WorldScene::SnapParticle | 0020 WorldScene::SnapSetLocalPosition, nullptr, true) {} 0021 }; 0022 0023 class SpringHandlerGraphicsItem : public StepGraphicsItem { 0024 public: 0025 SpringHandlerGraphicsItem(StepCore::Item* item, WorldModel* worldModel, 0026 QGraphicsItem* parent, int num); 0027 0028 void viewScaleChanged() override; 0029 void worldDataChanged(bool) override; 0030 0031 protected: 0032 void mouseSetPos(const QPointF& pos, const QPointF& diff, MovingState movingState) override; 0033 int _num; 0034 }; 0035 0036 class SpringGraphicsItem: public StepGraphicsItem { 0037 public: 0038 SpringGraphicsItem(StepCore::Item* item, WorldModel* worldModel); 0039 0040 QPainterPath shape() const override; 0041 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; 0042 0043 void viewScaleChanged() override; 0044 void stateChanged() override; 0045 void worldDataChanged(bool) override; 0046 0047 protected: 0048 static void tryAttach(StepCore::Item* item, WorldScene* worldScene, const QPointF& pos, int num); 0049 0050 void mouseSetPos(const QPointF& pos, const QPointF& diff, MovingState) override; 0051 StepCore::Spring* spring() const { 0052 return static_cast<StepCore::Spring*>(_item); } 0053 0054 QPainterPath _painterPath; 0055 double _rnorm; 0056 double _rscale; 0057 double _radius; 0058 0059 SpringHandlerGraphicsItem* _handler1; 0060 SpringHandlerGraphicsItem* _handler2; 0061 0062 static const int RADIUS = 6; 0063 0064 friend class SpringCreator; 0065 }; 0066 0067 #endif 0068