Warning, file /office/calligra/libs/flake/KoCopyController.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 KDE project 0002 * Copyright (C) 2006-2008 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2011 Boudewijn Rempt <boud@valdyas.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 "KoCopyController.h" 0022 0023 #include <KoToolBase.h> 0024 #include <KoCanvasBase.h> 0025 #include <KoToolProxy.h> 0026 #include <KoToolSelection.h> 0027 0028 #include <FlakeDebug.h> 0029 #include <QAction> 0030 0031 // KoCopyControllerPrivate 0032 class KoCopyControllerPrivate 0033 { 0034 public: 0035 KoCopyControllerPrivate(KoCopyController *p, KoCanvasBase *c, QAction *a); 0036 0037 // request to start the actual copy 0038 void copy(); 0039 0040 // request to start the actual cut 0041 void cut(); 0042 0043 void selectionChanged(bool hasSelection); 0044 0045 KoCopyController *parent; 0046 KoCanvasBase *canvas; 0047 QAction *action; 0048 bool appHasSelection; 0049 }; 0050 0051 KoCopyControllerPrivate::KoCopyControllerPrivate(KoCopyController *p, KoCanvasBase *c, QAction *a) 0052 : parent(p), 0053 canvas(c), 0054 action(a) 0055 { 0056 appHasSelection = false; 0057 } 0058 0059 void KoCopyControllerPrivate::copy() 0060 { 0061 if (canvas->toolProxy()->hasSelection()) 0062 // means the copy can be done by a flake tool 0063 canvas->toolProxy()->copy(); 0064 else // if not; then the application gets a request to do the copy 0065 emit parent->copyRequested(); 0066 } 0067 0068 void KoCopyControllerPrivate::cut() 0069 { 0070 if (canvas->toolProxy()->hasSelection()) { 0071 canvas->toolProxy()->cut(); 0072 } 0073 else { 0074 emit parent->copyRequested(); 0075 } 0076 } 0077 0078 void KoCopyControllerPrivate::selectionChanged(bool hasSelection) 0079 { 0080 action->setEnabled(appHasSelection || hasSelection); 0081 } 0082 0083 0084 // KoCopyController 0085 KoCopyController::KoCopyController(KoCanvasBase *canvas, QAction *copyAction) 0086 : QObject(copyAction), 0087 d(new KoCopyControllerPrivate(this, canvas, copyAction)) 0088 { 0089 connect(canvas->toolProxy(), SIGNAL(selectionChanged(bool)), this, SLOT(selectionChanged(bool))); 0090 connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())); 0091 hasSelection(false); 0092 } 0093 0094 KoCopyController::~KoCopyController() 0095 { 0096 delete d; 0097 } 0098 0099 void KoCopyController::hasSelection(bool selection) 0100 { 0101 d->appHasSelection = selection; 0102 d->action->setEnabled(d->appHasSelection || 0103 d->canvas->toolProxy()->hasSelection()); 0104 } 0105 0106 //have to include this because of Q_PRIVATE_SLOT 0107 #include "moc_KoCopyController.cpp"