File indexing completed on 2024-05-12 16:34:58
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2009-2010 Pierre Stirnweiss <pstirnweiss@googlemail.com> 0003 * Copyright (C) 2010 Thomas Zander <zander@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (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 GNU 0013 * 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, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "ReviewTool.h" 0022 #include "AnnotationTextShape.h" 0023 0024 #include <KoToolBase.h> 0025 #include <KoCanvasBase.h> 0026 #include <KoPointerEvent.h> 0027 #include <KoAnnotation.h> 0028 #include <KoShapeController.h> 0029 #include "KoShapeBasedDocumentBase.h" 0030 #include <KoCanvasResourceManager.h> 0031 #include <KoTextRangeManager.h> 0032 #include <KoAnnotationManager.h> 0033 #include <KoShapeUserData.h> 0034 #include <KoTextShapeData.h> 0035 0036 #include <dialogs/SimpleSpellCheckingWidget.h> 0037 #include <dialogs/SimpleAnnotationWidget.h> 0038 0039 #include <QDebug> 0040 #include <klocalizedstring.h> 0041 #include <QAction> 0042 #include <kuser.h> 0043 0044 #include <QDate> 0045 0046 0047 //#include "TextShape.h" 0048 #define AnnotationShape_SHAPEID "AnnotationTextShapeID" 0049 0050 ReviewTool::ReviewTool(KoCanvasBase* canvas): TextTool(canvas), 0051 m_textEditor(0), 0052 m_textShapeData(0), 0053 m_canvas(canvas), 0054 m_textShape(0), 0055 m_currentAnnotationShape(0) 0056 { 0057 createActions(); 0058 } 0059 0060 ReviewTool::~ReviewTool() 0061 { 0062 } 0063 0064 void ReviewTool::createActions() 0065 { 0066 m_removeAnnotationAction = new QAction(i18n("Remove Comment"), this); 0067 m_removeAnnotationAction->setToolTip(i18n("Remove Comment")); 0068 addAction("remove_annotation", m_removeAnnotationAction); 0069 connect(m_removeAnnotationAction, SIGNAL(triggered()), this, SLOT(removeAnnotation())); 0070 } 0071 0072 void ReviewTool::mouseReleaseEvent(KoPointerEvent* event) 0073 { 0074 TextTool::mouseReleaseEvent(event); 0075 event->accept(); 0076 } 0077 void ReviewTool::activate(KoToolBase::ToolActivation toolActivation, const QSet< KoShape* >& shapes) 0078 { 0079 TextTool::activate(toolActivation, shapes); 0080 } 0081 void ReviewTool::deactivate() 0082 { 0083 TextTool::deactivate(); 0084 } 0085 void ReviewTool::mouseMoveEvent(KoPointerEvent* event) 0086 { 0087 TextTool::mouseMoveEvent(event); 0088 } 0089 void ReviewTool::mousePressEvent(KoPointerEvent *event) 0090 { 0091 TextTool::mousePressEvent(event); 0092 m_currentAnnotationShape = dynamic_cast<AnnotationTextShape *>(textShape()); 0093 } 0094 void ReviewTool::keyPressEvent(QKeyEvent* event) 0095 { 0096 TextTool::keyPressEvent(event); 0097 } 0098 void ReviewTool::paint(QPainter& painter, const KoViewConverter& converter) 0099 { 0100 TextTool::paint(painter,converter); 0101 } 0102 0103 QList<QPointer<QWidget> > ReviewTool::createOptionWidgets() 0104 { 0105 QList<QPointer<QWidget> > widgets; 0106 SimpleSpellCheckingWidget* sscw = new SimpleSpellCheckingWidget(this, 0); 0107 SimpleAnnotationWidget *saw = new SimpleAnnotationWidget(this, 0); 0108 0109 connect(saw, SIGNAL(doneWithFocus()), this, SLOT(returnFocusToCanvas())); 0110 0111 sscw->setWindowTitle(i18n("Spell check")); 0112 widgets.append(sscw); 0113 0114 saw->setWindowTitle(i18n("Comments")); 0115 widgets.append(saw); 0116 0117 return widgets; 0118 } 0119 0120 void ReviewTool::removeAnnotation() 0121 { 0122 if (m_currentAnnotationShape) { 0123 QList<KoShape *> shapes; 0124 shapes << m_currentAnnotationShape; 0125 canvas()->addCommand(canvas()->shapeController()->removeShapes(shapes)); 0126 m_currentAnnotationShape = 0; 0127 } 0128 }