File indexing completed on 2024-05-05 04:35:18
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 "TikzToolBox.h" 0021 0022 #include "Document.h" 0023 #include "View.h" 0024 #include "MainWindow.h" 0025 #include "ToolLayout.h" 0026 0027 #include <QDebug> 0028 #include <QVBoxLayout> 0029 #include <QButtonGroup> 0030 #include <QToolButton> 0031 0032 namespace tikz { 0033 namespace ui { 0034 0035 class TikzToolBoxPrivate 0036 { 0037 public: 0038 // associated Document 0039 Document * doc = nullptr; 0040 0041 // this button group contains all tools 0042 QButtonGroup * group = nullptr; 0043 }; 0044 0045 TikzToolBox::TikzToolBox(tikz::ui::MainWindow * mainWin, QWidget * parent) 0046 : QWidget(parent) 0047 , d(new TikzToolBoxPrivate()) 0048 { 0049 QVBoxLayout * vbox = new QVBoxLayout(this); 0050 setLayout(vbox); 0051 0052 auto grid = new ToolLayout(); 0053 vbox->addLayout(grid); 0054 vbox->addStretch(); 0055 0056 auto selectAction = new QToolButton(this); 0057 auto createCoordAction = new QToolButton(this); 0058 auto createNodeAction = new QToolButton(this); 0059 auto createEdgeAction = new QToolButton(this); 0060 0061 selectAction->setText("Select"); 0062 selectAction->setIcon(QIcon::fromTheme("edit-select", QIcon(":/icons/icons/edit-select.png"))); 0063 createCoordAction->setText("Add Coordinate"); 0064 createCoordAction->setIcon(QIcon::fromTheme("draw-circle", QIcon(":/icons/icons/edit-select.png"))); 0065 createNodeAction->setText("Create Node"); 0066 createNodeAction->setIcon(QIcon::fromTheme("draw-ellipse", QIcon(":/icons/icons/edit-select.png"))); 0067 createEdgeAction->setText("Create Edge"); 0068 createEdgeAction->setIcon(QIcon::fromTheme("draw-line", QIcon(":/icons/icons/edit-select.png"))); 0069 0070 selectAction->setCheckable(true); 0071 createCoordAction->setCheckable(true); 0072 createNodeAction->setCheckable(true); 0073 createEdgeAction->setCheckable(true); 0074 0075 selectAction->setAutoRaise(true); 0076 createCoordAction->setAutoRaise(true); 0077 createNodeAction->setAutoRaise(true); 0078 createEdgeAction->setAutoRaise(true); 0079 0080 grid->addWidget(selectAction); 0081 grid->addWidget(createCoordAction); 0082 grid->addWidget(createNodeAction); 0083 grid->addWidget(createEdgeAction); 0084 0085 // create button group 0086 d->group = new QButtonGroup(this); 0087 0088 d->group->addButton(selectAction, static_cast<int>(TikzEditMode::ModeSelect)); 0089 d->group->addButton(createCoordAction, static_cast<int>(TikzEditMode::ModePlaceCoord)); 0090 d->group->addButton(createNodeAction, static_cast<int>(TikzEditMode::ModePlaceNode)); 0091 d->group->addButton(createEdgeAction, static_cast<int>(TikzEditMode::ModePlaceEdge)); 0092 d->group->setExclusive(true); 0093 0094 const int initialMode = static_cast<int>(TikzEditMode::ModePlaceNode); 0095 Q_ASSERT(d->group->button(initialMode) != nullptr); 0096 d->group->button(initialMode)->setChecked(true); 0097 0098 connect(d->group, &QButtonGroup::idClicked, [this](int mode) { 0099 Q_ASSERT(mode >= 0); 0100 Q_EMIT editModeChanged(static_cast<TikzEditMode>(mode)); 0101 }); 0102 } 0103 0104 TikzToolBox::~TikzToolBox() 0105 { 0106 delete d; 0107 } 0108 0109 void TikzToolBox::setEditMode(TikzEditMode mode) 0110 { 0111 if (editMode() != mode) { 0112 d->group->button(static_cast<int>(mode))->setChecked(true); 0113 } 0114 } 0115 0116 TikzEditMode TikzToolBox::editMode() const 0117 { 0118 const int id = d->group->checkedId(); 0119 Q_ASSERT(id >= 0); 0120 0121 return static_cast<TikzEditMode>(id); 0122 } 0123 0124 } 0125 } 0126 0127 // kate: indent-width 4; replace-tabs on;