Make TX volatge for simu more flexible (#7124)
[opentx.git] / companion / src / modeledit / node.h
blob17aab3015bd50d9a6aec0648eafda095de95a495
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _NODE_H_
22 #define _NODE_H_
24 #include <QtWidgets>
26 #define DEFAULT_BALL_SIZE 10
27 #define DEFAULT_BALL_HEIGHT 2
29 class Edge;
30 QT_BEGIN_NAMESPACE
31 class QGraphicsSceneMouseEvent;
32 QT_END_NAMESPACE
34 class Node : public QGraphicsObject
36 Q_OBJECT
38 public:
39 Node();
41 void addEdge(Edge *edge);
42 QList<Edge *> edges() const;
44 enum { Type = UserType + 1 };
45 int type() const { return Type; }
46 QRectF boundingRect() const;
47 QPainterPath shape() const;
48 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
49 void setBallSize(int size);
50 void stepToCenter(qreal step=10);
51 int getBallSize() { return ballSize; }
52 qreal getX();
53 qreal getY();
54 void setX(qreal newX);
55 void setY(qreal newX);
57 void setCenteringX(bool val) { centerX = val; }
58 void setCenteringY(bool val) { centerY = val; }
59 void setFixedX(bool val) { fixedX = val; }
60 void setFixedY(bool val) { fixedY = val; }
61 bool getFixedX() { return fixedX; }
62 bool getFixedY() { return fixedY; }
63 void setMinX(int val) { minX = val; }
64 void setMaxX(int val) { maxX = val; }
65 void setPressed(bool pressed) { bPressed = pressed; }
66 bool isPressed() const { return bPressed; }
67 void setColor(const QColor & color);
68 void setBallHeight(int height);
69 int geBallHeight() { return ballHeight; }
71 signals:
72 void moved(int x, int y);
73 void focus();
74 void unfocus();
75 void deleteMe();
77 protected:
78 QVariant itemChange(GraphicsItemChange change, const QVariant &value);
79 void mousePressEvent(QGraphicsSceneMouseEvent *event);
80 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
82 private:
83 bool bPressed;
84 bool centerX;
85 bool centerY;
86 bool fixedX;
87 bool fixedY;
88 int ballSize;
89 int minX;
90 int maxX;
91 QList<Edge *> edgeList;
92 QPointF newPos;
93 QColor nodecolor;
94 int ballHeight;
97 #endif // _NODE_H_