Warning, file /graphics/tikzkit/src/ui/view/ViewPrivate.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 "ViewPrivate.h" 0021 #include "DocumentPrivate.h" 0022 #include "Renderer.h" 0023 #include "Ruler.h" 0024 #include "EditorPrivate.h" 0025 #include "TikzScene.h" 0026 #include "TikzItem.h" 0027 0028 #include <tikz/core/Document.h> 0029 0030 #include <math.h> 0031 #include <QApplication> 0032 #include <QDebug> 0033 #include <QScrollBar> 0034 #include <QGridLayout> 0035 0036 namespace tikz { 0037 namespace ui { 0038 0039 static const int s_ruler_size = 16; 0040 0041 ViewPrivate::ViewPrivate(tikz::ui::DocumentPrivate * doc, 0042 QWidget * parent, 0043 tikz::ui::MainWindow * mainWindow) 0044 : tikz::ui::View(this, parent) 0045 , m_doc(doc) 0046 , m_mainWindow(mainWindow) 0047 , m_renderer(new Renderer(doc, this)) 0048 { 0049 auto vboxLayout = new QVBoxLayout(this); 0050 vboxLayout->setContentsMargins(0, 0, 0, 0); 0051 vboxLayout->addWidget(m_renderer); 0052 0053 // register View 0054 EditorPrivate::self()->registerView(this); 0055 m_doc->registerView(this); 0056 0057 connect(doc->scene(), SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged())); 0058 connect(m_renderer, SIGNAL(mousePositionChanged(tikz::Pos)), this, SIGNAL(mousePositionChanged(tikz::Pos))); 0059 } 0060 0061 ViewPrivate::~ViewPrivate() 0062 { 0063 // unregister view 0064 EditorPrivate::self()->unregisterView(this); 0065 m_doc->unregisterView(this); 0066 } 0067 0068 tikz::ui::Document * ViewPrivate::document() const 0069 { 0070 return m_doc; 0071 } 0072 0073 tikz::ui::MainWindow * ViewPrivate::mainWindow() const 0074 { 0075 return m_mainWindow; 0076 } 0077 0078 tikz::ui::ZoomController * ViewPrivate::zoomController() const 0079 { 0080 return m_renderer->zoomController(); 0081 } 0082 0083 TikzEditMode ViewPrivate::editMode() const 0084 { 0085 return m_doc->scene()->editMode(); 0086 } 0087 0088 void ViewPrivate::setEditMode(TikzEditMode mode) const 0089 { 0090 m_doc->scene()->setEditMode(mode); 0091 } 0092 0093 bool ViewPrivate::hasSelection() const 0094 { 0095 return ! m_doc->scene()->selectedItems().isEmpty(); 0096 } 0097 0098 void ViewPrivate::clearSelection() 0099 { 0100 m_doc->scene()->clearSelection(); 0101 } 0102 0103 QList<TikzItem *> ViewPrivate::selectedItems() const 0104 { 0105 QList<QGraphicsItem *> items = m_doc->scene()->selectedItems(); 0106 QList<TikzItem *> filteredItems; 0107 for (auto item : items) { 0108 auto tikzItem = dynamic_cast<TikzItem *>(item); 0109 if (tikzItem) { 0110 filteredItems.append(tikzItem); 0111 } 0112 } 0113 return filteredItems; 0114 } 0115 0116 tikz::Value ViewPrivate::snapValue(const tikz::Value & value) const 0117 { 0118 return m_renderer->snapValue(value); 0119 } 0120 0121 tikz::Pos ViewPrivate::snapPos(const tikz::Pos & pos) const 0122 { 0123 return m_renderer->snapPos(pos); 0124 } 0125 0126 qreal ViewPrivate::snapAngle(qreal angle) const 0127 { 0128 const bool snap = QApplication::keyboardModifiers() ^ Qt::ShiftModifier; 0129 return snap ? (qRound(angle / 15) * 15) : angle; 0130 } 0131 0132 Renderer * ViewPrivate::renderer() const 0133 { 0134 return m_renderer; 0135 } 0136 0137 void ViewPrivate::slotSelectionChanged() 0138 { 0139 Q_EMIT selectionChanged(this); 0140 } 0141 0142 } 0143 } 0144 0145 // kate: indent-width 4; replace-tabs on;