File indexing completed on 2024-05-19 04:36:38
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 2014 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 "SelectTool.h" 0021 0022 #include "NodeItem.h" 0023 #include "EdgePathItem.h" 0024 #include <tikz/core/EdgePath.h> 0025 #include <tikz/core/Transaction.h> 0026 #include <tikz/core/Style.h> 0027 #include <tikz/core/UndoSetProperty.h> 0028 #include "Document.h" 0029 0030 #include <QGraphicsScene> 0031 #include <QKeyEvent> 0032 0033 #include <QDebug> 0034 0035 namespace tikz { 0036 namespace ui { 0037 0038 static void setProp(const tikz::core::Uid & entity, const QString & key, const QVariant & value) 0039 { 0040 entity.document()->addUndoItem(new tikz::core::UndoSetProperty(entity, key, value)); 0041 } 0042 0043 SelectTool::SelectTool(tikz::ui::Document * doc, QGraphicsScene * scene) 0044 : AbstractTool(doc, scene) 0045 { 0046 } 0047 0048 SelectTool::~SelectTool() 0049 { 0050 } 0051 0052 void SelectTool::mouseMoveEvent(QGraphicsSceneMouseEvent * event) 0053 { 0054 } 0055 0056 void SelectTool::mousePressEvent(QGraphicsSceneMouseEvent * event) 0057 { 0058 } 0059 0060 void SelectTool::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) 0061 { 0062 } 0063 0064 void SelectTool::keyPressEvent(QKeyEvent * event) 0065 { 0066 if (event->key() == Qt::Key_N) { 0067 tikz::core::Transaction transaction(document(), QStringLiteral("Create Node")); 0068 tikz::ui::NodeItem * node = document()->createNodeItem(); 0069 node->setPos(tikz::Pos(0, 0)); 0070 setProp(node->style()->uid(), "shape", QVariant::fromValue(tikz::Shape::ShapeRectangle)); 0071 setProp(node->style()->uid(), "minimumWidth", 4.0_mm); 0072 setProp(node->style()->uid(), "minimumHeight", 4.0_mm); 0073 } 0074 0075 if (event->key() == Qt::Key_M) { 0076 tikz::core::Transaction transaction(document(), QStringLiteral("Create Node")); 0077 tikz::ui::NodeItem * node = document()->createNodeItem(); 0078 node->setPos(tikz::Pos(0, 0)); 0079 setProp(node->style()->uid(), "minimumWidth", 4.0_mm); 0080 setProp(node->style()->uid(), "minimumHeight", 4.0_mm); 0081 setProp(node->node()->uid(), "text", "x"); 0082 } 0083 0084 if (event->key() == Qt::Key_E) { 0085 tikz::core::Transaction transaction(document(), QStringLiteral("Create Edge")); 0086 auto path = dynamic_cast<EdgePathItem *>(document()->createPathItem(tikz::PathType::Line)); 0087 path->edgePath()->setEndPos(tikz::Pos(1, 0, tikz::Unit::Centimeter)); 0088 setProp(path->path()->styleUid(), "arrowHead", QVariant::fromValue(tikz::Arrow::ToArrow)); 0089 } 0090 0091 if (event->key() == Qt::Key_C) { 0092 tikz::core::Transaction transaction(document(), QStringLiteral("Create Ellipse")); 0093 tikz::ui::NodeItem * node = document()->createNodeItem(); 0094 node->setPos(tikz::Pos(0, 0)); 0095 setProp(node->style()->uid(), "shape", QVariant::fromValue(tikz::Shape::ShapeEllipse)); 0096 setProp(node->style()->uid(), "minimumWidth", 4.0_mm); 0097 setProp(node->style()->uid(), "minimumHeight", 4.0_mm); 0098 } 0099 0100 if (event->key() == Qt::Key_V) { 0101 tikz::core::Transaction transaction(document(), QStringLiteral("Create Ellipse")); 0102 tikz::ui::NodeItem * node = document()->createNodeItem(); 0103 node->setPos(tikz::Pos(0, 0)); 0104 tikz::core::Style ns; 0105 ns.setStyle(node->node()->style()); 0106 ns.setFillColor(Qt::black); 0107 setProp(node->style()->uid(), "shape", QVariant::fromValue(tikz::Shape::ShapeEllipse)); 0108 setProp(node->style()->uid(), "minimumWidth", 1.0_mm); 0109 setProp(node->style()->uid(), "minimumHeight", 1.0_mm); 0110 setProp(node->style()->uid(), "innerSep", 0.0_mm); 0111 } 0112 } 0113 0114 } 0115 } 0116 0117 // kate: indent-width 4; replace-tabs on;