git-svn-id: svn://db.shs.com.ru/libs@316 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,20 +1,8 @@
|
||||
#ifndef BLOCKITEM_H
|
||||
#define BLOCKITEM_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsObject>
|
||||
#include <QGraphicsEllipseItem>
|
||||
#include <QGraphicsSceneHoverEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QStack>
|
||||
#include <QDebug>
|
||||
#include <qmath.h>
|
||||
#include "blockbase.h"
|
||||
#include "alignedtextitem.h"
|
||||
#include "chunkstream.h"
|
||||
|
||||
#include "blockitempin.h"
|
||||
#include <QTime>
|
||||
|
||||
/// data:
|
||||
/// 1002 - flag for move parent (true)
|
||||
@@ -29,93 +17,14 @@
|
||||
/// 1011 - item is BlockItem decor ("decor")
|
||||
/// 1100 - flag for correct move (true)
|
||||
|
||||
|
||||
class BlockItem;
|
||||
class BlockBusItem;
|
||||
|
||||
|
||||
class BlockItemPin: public QGraphicsItem, public PropertyStorage
|
||||
{
|
||||
friend class BlockView;
|
||||
friend class BlockItem;
|
||||
public:
|
||||
BlockItemPin(Qt::Alignment a = Qt::AlignLeft, int bus_type = 0, const QString & text_ = QString(), QGraphicsItem * parent_ = 0);
|
||||
|
||||
enum State {
|
||||
Disconnected,
|
||||
Connected,
|
||||
Hover,
|
||||
Drop,
|
||||
Accept,
|
||||
Reject
|
||||
};
|
||||
|
||||
enum Direction {
|
||||
None = 0x0,
|
||||
Input = 0x1,
|
||||
Output = 0x2,
|
||||
InputOutput = 0x3
|
||||
};
|
||||
|
||||
void setPen(const QPen & p) {ell_item.setPen(p);}
|
||||
QPen pen() const {return ell_item.pen();}
|
||||
void setBrush(const QBrush & b) {ell_item.setBrush(b);}
|
||||
QBrush brush() const {return ell_item.brush();}
|
||||
|
||||
int busType() const {return bus_type;}
|
||||
Qt::Alignment alignment() const {return align;}
|
||||
Direction direction() const {return dir;}
|
||||
QString text() const {return text_item.text();}
|
||||
State state() const {return state_;}
|
||||
|
||||
void setBusType(int type_) {bus_type = type_;}
|
||||
void setAlignment(Qt::Alignment a) {align = a; _init(true);}
|
||||
void setDirection(Direction d) {dir = d; _init(true);}
|
||||
void setText(const QString & t) {text_item.setText(t); _init(true);}
|
||||
void setState(State s) {state_ = s; setBrush(br[int(state_)]); update();}
|
||||
|
||||
void saveState() {sstate_.push(state_);}
|
||||
bool restoreState() {if (sstate_.isEmpty()) return false; setState(sstate_.pop()); return true;}
|
||||
void clearStateStack() {sstate_.clear();}
|
||||
|
||||
void resizePin(double r = 7.);
|
||||
|
||||
BlockItem * parent() const {return parent_;}
|
||||
QList<BlockBusItem * > connectedBuses() const {return buses_;}
|
||||
|
||||
enum {Type = UserType + 3};
|
||||
|
||||
protected:
|
||||
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0) {}
|
||||
QRectF boundingRect() const {return ell_item.boundingRect().translated(ell_item.pos()) | text_item.boundingRect().translated(text_item.pos());}
|
||||
int type() const {return Type;}
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant & value);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent * e);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent * e);
|
||||
void _init(bool affect_parent = false);
|
||||
void _reparent();
|
||||
int bus_type;
|
||||
State state_;
|
||||
QGraphicsEllipseItem ell_item;
|
||||
QGraphicsSimpleTextItem text_item;
|
||||
QStack<State> sstate_;
|
||||
QList<BlockBusItem * > buses_;
|
||||
BlockItem * parent_;
|
||||
Qt::Alignment align;
|
||||
Direction dir;
|
||||
QBrush br[6];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class BlockItem: public QGraphicsObject, public PropertyStorage
|
||||
{
|
||||
friend class BlockView;
|
||||
friend class BlockItemPin;
|
||||
friend class DrawTools;
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(double _thickness READ thickness WRITE setThickness DESIGNABLE false SCRIPTABLE false)
|
||||
Q_PROPERTY(QRectF _selRect READ selectionRect WRITE setSelectionRect DESIGNABLE false SCRIPTABLE false)
|
||||
public:
|
||||
BlockItem(QGraphicsItem * parent = 0);
|
||||
~BlockItem();
|
||||
@@ -176,6 +85,15 @@ protected:
|
||||
QMap<Qt::Alignment, QVector<BlockItemPin * > > pins_;
|
||||
QList<QGraphicsItem * > decors_;
|
||||
|
||||
private:
|
||||
double thickness() const;
|
||||
void setThickness(double w);
|
||||
QRectF selectionRect() const;
|
||||
void setSelectionRect(const QRectF & r);
|
||||
|
||||
QPropertyAnimation anim_thick, anim_sel;
|
||||
QTime t_sel;
|
||||
|
||||
signals:
|
||||
void blockHoverEnter(BlockItem * b);
|
||||
void blockHoverLeave(BlockItem * b);
|
||||
|
||||
Reference in New Issue
Block a user