File indexing completed on 2024-05-05 04:35:17

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "CurveHandle.h"
0021 #include "PathItem.h"
0022 
0023 #include <QPainter>
0024 #include <QStyleOptionGraphicsItem>
0025 #include <QEvent>
0026 #include <QGraphicsSceneMouseEvent>
0027 
0028 #include <QDebug>
0029 
0030 class CurveHandlePrivate
0031 {
0032     public:
0033 };
0034 
0035 CurveHandle::CurveHandle(tikz::ui::PathItem * path)
0036     : TikzItem(path)
0037     , d(new CurveHandlePrivate())
0038 {
0039     // show above paths
0040     setZValue(10.0);
0041 
0042     setFlag(QGraphicsItem::ItemIsSelectable, true);
0043 }
0044 
0045 CurveHandle::~CurveHandle()
0046 {
0047     delete d;
0048 }
0049 
0050 int CurveHandle::type() const
0051 {
0052     return UserType + 5;
0053 }
0054 
0055 void CurveHandle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
0056 {
0057     Q_UNUSED(widget);
0058     Q_UNUSED(option);
0059 
0060     // debugging
0061 //     painter->drawRect(boundingRect());
0062 
0063     painter->save();
0064     painter->setRenderHints(QPainter::Antialiasing);
0065 
0066     painter->setPen(isHovered() || isSelected() ? Qt::green : Qt::blue);
0067     painter->setBrush(isHovered() || isSelected() ? QColor(0, 255, 0, 125) : QColor(0, 0, 255, 125));
0068     painter->drawEllipse(QPointF(0, 0), 0.2, 0.2);
0069 
0070     painter->restore();
0071 }
0072 
0073 QRectF CurveHandle::boundingRect() const
0074 {
0075     return QRectF(-0.25, -0.25, 0.5, 0.5);
0076 }
0077 
0078 bool CurveHandle::contains(const QPointF &point) const
0079 {
0080     // within circle of 2.5 mm?
0081     return (point.x() * point.x() + point.y() * point.y()) <= (0.25 * 0.25);
0082 }
0083 
0084 void CurveHandle::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
0085 {
0086     event->accept();
0087     Q_EMIT positionChanged(event->pos());
0088 }
0089 
0090 void CurveHandle::mousePressEvent(QGraphicsSceneMouseEvent * event)
0091 {
0092     event->accept();
0093 }
0094 
0095 void CurveHandle::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
0096 {
0097     event->accept();
0098 }
0099 
0100 // kate: indent-width 4; replace-tabs on;