[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [tikzkit] src/ui: make anchor matching work also in all cases
From: Dominik Haumann <dhaumann () kde ! org>
Date: 2014-01-11 21:18:07
Message-ID: E1W25wV-0000md-VF () scm ! kde ! org
[Download RAW message or body]
Git commit ce9d4d8405bbe96fa63dd1d65f52da9a495b3a09 by Dominik Haumann.
Committed on 11/01/2014 at 21:16.
Pushed by dhaumann into branch 'master'.
make anchor matching work also in all cases
M +38 -1 src/ui/handle/AnchorHandle.cpp
M +20 -1 src/ui/handle/AnchorHandle.h
M +4 -3 src/ui/utils/AnchorManager.cpp
http://commits.kde.org/tikzkit/ce9d4d8405bbe96fa63dd1d65f52da9a495b3a09
diff --git a/src/ui/handle/AnchorHandle.cpp b/src/ui/handle/AnchorHandle.cpp
index f381f8e..fe257b1 100644
--- a/src/ui/handle/AnchorHandle.cpp
+++ b/src/ui/handle/AnchorHandle.cpp
@@ -40,6 +40,11 @@ AnchorHandle::AnchorHandle(TikzNode * node, tikz::Anchor anchor)
m_metaPos->setNode(node->node());
m_metaPos->setAnchor(anchor);
+ // set transform property correctly in case of NoAnchor type
+ if (anchor == tikz::NoAnchor) {
+ setFlag(ItemIgnoresTransformations, false);
+ }
+
// set position depending on the anchor
setPos(node->mapToScene(node->anchor(anchor)));
}
@@ -63,20 +68,52 @@ tikz::Anchor AnchorHandle::anchor() const
return m_metaPos->anchor();
}
+tikz::core::MetaPos::Ptr AnchorHandle::metaPos() const
+{
+ return m_metaPos;
+}
+
void AnchorHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget) {
Q_UNUSED(widget);
Q_UNUSED(option);
-qDebug() << "is under mouse:" << isUnderMouse();
+
+ // do not draw at all if the anchor matches the entire node shape
+ if (anchor() == tikz::NoAnchor) {
+ return;
+ }
+
painter->save();
painter->setRenderHints(QPainter::Antialiasing);
painter->setPen(QColor(164, 0, 0)); // dark red
painter->setBrush(isHovered() ? Qt::yellow : QColor(221, 99, 99));
+ if (!isActive()) {
+ painter->setOpacity(0.5);
+ }
+
painter->drawEllipse(rect());
painter->restore();
}
+QRectF AnchorHandle::boundingRect() const
+{
+ if (anchor() == tikz::NoAnchor) {
+ return m_node->boundingRect();
+ } else {
+ return Handle::boundingRect();
+ }
+}
+
+bool AnchorHandle::contains(const QPointF &point) const
+{
+ if (anchor() == tikz::NoAnchor) {
+ return m_node->contains(point);
+ }
+
+ return Handle::contains(point);
+}
+
// kate: indent-width 4; replace-tabs on;
diff --git a/src/ui/handle/AnchorHandle.h b/src/ui/handle/AnchorHandle.h
index a071a12..75c9711 100644
--- a/src/ui/handle/AnchorHandle.h
+++ b/src/ui/handle/AnchorHandle.h
@@ -45,6 +45,10 @@ class AnchorHandle : public Handle
*/
virtual int type() const;
+ //
+ // node/anchor accessors
+ //
+ public:
/**
* Get the node this anchor handle.
*/
@@ -55,6 +59,11 @@ class AnchorHandle : public Handle
*/
tikz::Anchor anchor() const;
+ /**
+ * Get the tikz::core::Node and anchor as MetaPos.
+ */
+ tikz::core::MetaPos::Ptr metaPos() const;
+
//
// reimplemented from QGraphicsItem
//
@@ -62,7 +71,17 @@ class AnchorHandle : public Handle
/**
* Paint this item.
*/
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, \
QWidget *widget = 0); + void paint(QPainter *painter, const \
QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; +
+ /**
+ * Reimplemented, depending on tikz::Anchor type.
+ */
+ QRectF boundingRect() const override;
+
+ /**
+ * Reimplemented, depending on tikz::Anchor type.
+ */
+ bool contains(const QPointF &point) const override;
//
// internal
diff --git a/src/ui/utils/AnchorManager.cpp b/src/ui/utils/AnchorManager.cpp
index 00ebce8..3ef4e28 100644
--- a/src/ui/utils/AnchorManager.cpp
+++ b/src/ui/utils/AnchorManager.cpp
@@ -170,9 +170,10 @@ tikz::core::MetaPos::Ptr AnchorManager::anchorAt(const QPointF & \
scenePos, QGrap
const QPoint p = view->viewportTransform().map(scenePos).toPoint();
const QList<QGraphicsItem *> items = view->items(p);
AnchorHandle * handle = first<AnchorHandle>(items);
- if (handle) {
- metaPos->setNode(handle->node()->node());
- metaPos->setAnchor(handle->anchor());
+ if (handle &&
+ handle->contains(handle->mapFromScene(scenePos)))
+ {
+ metaPos = handle->metaPos();
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic