HAL
node_drag_shadow.cpp
Go to the documentation of this file.
2 
4 
5 #include <assert.h>
6 
7 #include <QParallelAnimationGroup>
8 #include <QPropertyAnimation>
9 #include <QPainter>
10 #include <QPaintEvent>
11 #include <iostream>
12 
13 namespace hal
14 {
15  QPen NodeDragShadow::sPen;
16  qreal NodeDragShadow::sLod;
17 
18  QColor NodeDragShadow::sColorPen[3];
19  QColor NodeDragShadow::sColorSolid[3];
20  QColor NodeDragShadow::sColorTranslucent[3];
21 
23  {
24  sColorPen[static_cast<int>(DragCue::Rejected)] = QColor(166, 31, 31, 255);
25  sColorPen[static_cast<int>(DragCue::Movable)] = QColor(48, 172, 79, 255);
26  sColorPen[static_cast<int>(DragCue::Swappable)] = QColor(37, 97, 176, 255);
27 
28  sColorSolid[static_cast<int>(DragCue::Rejected)] = QColor(166, 31, 31, 200);
29  sColorSolid[static_cast<int>(DragCue::Movable)] = QColor(48, 172, 79, 200);
30  sColorSolid[static_cast<int>(DragCue::Swappable)] = QColor(37, 97, 176, 200);
31 
32  sColorTranslucent[static_cast<int>(DragCue::Rejected)] = QColor(166, 31, 31, 150);
33  sColorTranslucent[static_cast<int>(DragCue::Movable)] = QColor(48, 172, 79, 150);
34  sColorTranslucent[static_cast<int>(DragCue::Swappable)] = QColor(37, 97, 176, 150);
35 
36  sPen.setCosmetic(true);
38  }
39 
41  : QGraphicsItem(), mRect(0,0,100,100)
42  {
44  }
45 
46  void NodeDragShadow::start(const QPointF& posF, const QSizeF& sizeF)
47  {
48  mRect = QRectF(QPointF(0,0),sizeF);
49  setPos(posF);
50  setZValue(1);
51  show();
52  }
53 
54  /*
55  qreal NodeDragShadow::width() const
56  {
57  return mWidth;
58  }
59 
60  qreal NodeDragShadow::height() const
61  {
62  return mHeight;
63  }
64 
65  QSizeF NodeDragShadow::size() const
66  {
67  return QSizeF(mWidth, mHeight);
68  }
69 
70  void NodeDragShadow::setWidth(const qreal width)
71  {
72  mWidth = width;
73  }
74 
75  void NodeDragShadow::setHeight(const qreal height)
76  {
77  mHeight = height;
78  }
79 */
80 
81  void NodeDragShadow::setLod(const qreal lod)
82  {
83  sLod = lod;
84  }
85 
87  {
88  mCue = cue;
89  update();
90  }
91 
93  {
94  Q_UNUSED(option)
95  Q_UNUSED(widget)
96 
97  int color_index = static_cast<int>(mCue);
98  assert(color_index <= 3);
99 
100  sPen.setColor(sColorPen[color_index]);
101  painter->setPen(sPen);
102 
103  if (sLod < 0.5)
104  {
105 
106  painter->fillRect(mRect, sColorSolid[color_index]);
107  }
108  else
109  {
110  painter->drawRect(mRect);
111  painter->fillRect(mRect, sColorTranslucent[color_index]);
112  }
113  }
114 
116  {
117  return mRect;
118  }
119 
121  {
122  QPainterPath path;
123  path.addRect(mRect);
124  return path;
125  }
126 }
QRectF boundingRect() const override
void start(const QPointF &posF, const QSizeF &sizeF)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override
void setVisualCue(const DragCue cue)
QPainterPath shape() const override
static void loadSettings()
static void setLod(const qreal lod)
option(PL_GUI "PL_GUI" ON) if(PL_GUI OR BUILD_ALL_PLUGINS) cmake_minimum_required(VERSION 3.1.0) if(APPLE AND CMAKE_HOST_APPLE AND NOT Qt5_DIR) set(Qt5_DIR "/usr/local/opt/qt@5/lib/cmake") endif(APPLE AND CMAKE_HOST_APPLE AND NOT Qt5_DIR) find_package(Qt5 COMPONENTS Core REQUIRED) find_package(Qt5 COMPONENTS Widgets REQUIRED) if(Qt5Widgets_FOUND) message(VERBOSE "Qt5Widgets_INCLUDE_DIRS
Definition: CMakeLists.txt:1
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
void setPos(const QPointF &pos)
void setZValue(qreal z)
void update(const QRectF &rect)
void drawRect(const QRectF &rectangle)
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setPen(const QColor &color)
void addRect(const QRectF &rectangle)
void setColor(const QColor &color)
void setCosmetic(bool cosmetic)
void setJoinStyle(Qt::PenJoinStyle style)
MiterJoin