1 /* 2 * LibrePCB - Professional EDA for everyone! 3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors. 4 * https://librepcb.org/ 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef LIBREPCB_PROJECT_EDITOR_SCHEMATICEDITORSTATE_SELECT_H 21 #define LIBREPCB_PROJECT_EDITOR_SCHEMATICEDITORSTATE_SELECT_H 22 23 /******************************************************************************* 24 * Includes 25 ******************************************************************************/ 26 #include "schematiceditorstate.h" 27 28 #include <QtCore> 29 #include <QtWidgets> 30 31 /******************************************************************************* 32 * Namespace / Forward Declarations 33 ******************************************************************************/ 34 namespace librepcb { 35 36 class Angle; 37 38 namespace project { 39 40 class SI_Base; 41 class SI_Symbol; 42 class SI_NetLabel; 43 class Schematic; 44 45 namespace editor { 46 47 class CmdMoveSelectedSchematicItems; 48 49 /******************************************************************************* 50 * Class SchematicEditorState_Select 51 ******************************************************************************/ 52 53 /** 54 * @brief The "select" state/tool of the schematic editor (default state) 55 */ 56 class SchematicEditorState_Select final : public SchematicEditorState { 57 Q_OBJECT 58 59 public: 60 // Constructors / Destructor 61 SchematicEditorState_Select() = delete; 62 SchematicEditorState_Select(const SchematicEditorState_Select& other) = 63 delete; 64 explicit SchematicEditorState_Select(const Context& context) noexcept; 65 virtual ~SchematicEditorState_Select() noexcept; 66 67 // General Methods 68 virtual bool entry() noexcept override; 69 virtual bool exit() noexcept override; 70 71 // Event Handlers 72 virtual bool processSelectAll() noexcept override; 73 virtual bool processCut() noexcept override; 74 virtual bool processCopy() noexcept override; 75 virtual bool processPaste() noexcept override; 76 virtual bool processRotateCw() noexcept override; 77 virtual bool processRotateCcw() noexcept override; 78 virtual bool processMirror() noexcept override; 79 virtual bool processRemove() noexcept override; 80 virtual bool processAbortCommand() noexcept override; 81 virtual bool processGraphicsSceneMouseMoved( 82 QGraphicsSceneMouseEvent& e) noexcept override; 83 virtual bool processGraphicsSceneLeftMouseButtonPressed( 84 QGraphicsSceneMouseEvent& e) noexcept override; 85 virtual bool processGraphicsSceneLeftMouseButtonReleased( 86 QGraphicsSceneMouseEvent& e) noexcept override; 87 virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked( 88 QGraphicsSceneMouseEvent& e) noexcept override; 89 virtual bool processGraphicsSceneRightMouseButtonReleased( 90 QGraphicsSceneMouseEvent& e) noexcept override; 91 virtual bool processSwitchToSchematicPage(int index) noexcept override; 92 93 // Operator Overloadings 94 SchematicEditorState_Select& operator=( 95 const SchematicEditorState_Select& rhs) = delete; 96 97 private: // Methods 98 bool startMovingSelectedItems(Schematic& schematic, 99 const Point& startPos) noexcept; 100 bool rotateSelectedItems(const Angle& angle) noexcept; 101 bool mirrorSelectedItems() noexcept; 102 bool removeSelectedItems() noexcept; 103 bool copySelectedItemsToClipboard() noexcept; 104 bool pasteFromClipboard() noexcept; 105 void openPropertiesDialog(SI_Base* item) noexcept; 106 void openSymbolPropertiesDialog(SI_Symbol& symbol) noexcept; 107 void openNetLabelPropertiesDialog(SI_NetLabel& netlabel) noexcept; 108 109 // Right Click Menu 110 QAction* addActionCut(QMenu& menu, const QString& text = tr("Cut")) noexcept; 111 QAction* addActionCopy(QMenu& menu, 112 const QString& text = tr("Copy")) noexcept; 113 QAction* addActionRemove(QMenu& menu, 114 const QString& text = tr("Remove")) noexcept; 115 QAction* addActionMirror(QMenu& menu, 116 const QString& text = tr("Mirror")) noexcept; 117 QAction* addActionRotate(QMenu& menu, 118 const QString& text = tr("Rotate")) noexcept; 119 QAction* addActionOpenProperties( 120 QMenu& menu, SI_Base* item, 121 const QString& text = tr("Properties")) noexcept; 122 123 private: // Data 124 /// enum for all possible substates 125 enum class SubState { 126 IDLE, ///< left mouse button is not pressed (default state) 127 SELECTING, ///< left mouse button pressed to draw selection rect 128 MOVING, ///< left mouse button pressed to move items 129 PASTING, ///< move pasted items 130 }; 131 132 SubState mSubState; ///< the current substate 133 Point mStartPos; 134 QScopedPointer<CmdMoveSelectedSchematicItems> mSelectedItemsMoveCommand; 135 int mCurrentSelectionIndex; 136 }; 137 138 /******************************************************************************* 139 * End of File 140 ******************************************************************************/ 141 142 } // namespace editor 143 } // namespace project 144 } // namespace librepcb 145 146 #endif 147