chengxr 1 年間 前
コミット
1e2c22a2b3

+ 2 - 0
QFD/CCanvas/CCanvas.pri

@@ -4,11 +4,13 @@ HEADERS += \
     $$PWD/CMind.h \
     $$PWD/CMindView.h \
     $$PWD/CNode.h \
+    $$PWD/CPathItem.h \
     $$PWD/CRectItem.h
 
 SOURCES += \
     $$PWD/CMind.cpp \
     $$PWD/CMindView.cpp \
     $$PWD/CNode.cpp \
+    $$PWD/CPathItem.cpp \
     $$PWD/CRectItem.cpp
 

+ 48 - 0
QFD/CCanvas/CPathItem.cpp

@@ -0,0 +1,48 @@
+#include "CPathItem.h"
+
+#include <QPen>
+
+CPathItem::CPathItem(QGraphicsItem *parent) : QGraphicsPathItem(parent) { }
+
+int CPathItem::lineWidth() const
+{
+    QPen pen = this->pen();
+    return pen.width();
+}
+
+void CPathItem::setLineWidth(int width)
+{
+    QPen pen = this->pen();
+    pen.setWidth(width);
+    setPen(pen);
+}
+
+QColor CPathItem::lineColor() const
+{
+    QPen pen = this->pen();
+    return pen.color();
+}
+
+void CPathItem::setLineColor(QColor color)
+{
+    QPen pen = this->pen();
+    pen.setColor(color);
+    setPen(pen);
+}
+
+QColor CPathItem::fillColor() const
+{
+    QBrush brush = this->brush();
+    return brush.color();
+}
+
+void CPathItem::setFillColor(QColor color)
+{
+    setBrush(color);
+}
+
+void CPathItem::setHighlighted(bool highlighted)
+{
+    setLineColor(highlighted ? Qt::blue : Qt::transparent);
+    setFillColor(highlighted ? Qt::gray : Qt::white);
+}

+ 23 - 0
QFD/CCanvas/CPathItem.h

@@ -0,0 +1,23 @@
+#ifndef CPATHITEM_H
+#define CPATHITEM_H
+
+#include <QGraphicsPathItem>
+
+class CPathItem : public QGraphicsPathItem
+{
+public:
+    CPathItem(QGraphicsItem *parent = nullptr);
+
+    int lineWidth() const;
+    void setLineWidth(int width);
+
+    QColor lineColor() const;
+    void setLineColor(QColor color);
+
+    QColor fillColor() const;
+    void setFillColor(QColor color);
+
+    virtual void setHighlighted(bool highlighted);
+};
+
+#endif  // CPATHITEM_H

+ 1 - 1
QFD/CCanvas/CRectItem.cpp

@@ -1,5 +1,5 @@
 #include "CRectItem.h"
 
-CRectItem::CRectItem(QGraphicsItem *parent) : QGraphicsPathItem(parent) { }
+CRectItem::CRectItem(QGraphicsItem *parent) : CPathItem(parent) { }
 
 void CRectItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { }

+ 2 - 2
QFD/CCanvas/CRectItem.h

@@ -1,9 +1,9 @@
 #ifndef CRECTITEM_H
 #define CRECTITEM_H
 
-#include <QGraphicsPathItem>
+#include "CPathItem.h"
 
-class CRectItem : public QGraphicsPathItem
+class CRectItem : public CPathItem
 {
 public:
     explicit CRectItem(QGraphicsItem *parent = nullptr);