libs/flake
KoCopyController.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "KoCopyController.h"
00021
00022 #include <KoTool.h>
00023 #include <KoCanvasBase.h>
00024 #include <KoToolProxy.h>
00025 #include <KoToolSelection.h>
00026
00027 #include <KDebug>
00028 #include <QAction>
00029
00030
00031 class KoCopyControllerPrivate
00032 {
00033 public:
00034 KoCopyControllerPrivate(KoCopyController *p, KoCanvasBase *c, QAction *a);
00035
00036
00037 void copy();
00038
00039
00040 void cut();
00041
00042 void selectionChanged(bool hasSelection);
00043
00044 KoCopyController *parent;
00045 KoCanvasBase *canvas;
00046 QAction *action;
00047 bool appHasSelection;
00048 };
00049
00050 KoCopyControllerPrivate::KoCopyControllerPrivate(KoCopyController *p, KoCanvasBase *c, QAction *a)
00051 : parent(p),
00052 canvas(c),
00053 action(a)
00054 {
00055 appHasSelection = false;
00056 }
00057
00058 void KoCopyControllerPrivate::copy()
00059 {
00060 if (canvas->toolProxy()->selection() && canvas->toolProxy()->selection()->hasSelection())
00061
00062 canvas->toolProxy()->copy();
00063 else
00064 emit parent->copyRequested();
00065 }
00066
00067 void KoCopyControllerPrivate::cut()
00068 {
00069 canvas->toolProxy()->cut();
00070 }
00071
00072 void KoCopyControllerPrivate::selectionChanged(bool hasSelection)
00073 {
00074 action->setEnabled(appHasSelection || hasSelection);
00075 }
00076
00077
00078
00079 KoCopyController::KoCopyController(KoCanvasBase *canvas, QAction *copyAction)
00080 : QObject(copyAction),
00081 d(new KoCopyControllerPrivate(this, canvas, copyAction))
00082 {
00083 connect(canvas->toolProxy(), SIGNAL(selectionChanged(bool)), this, SLOT(selectionChanged(bool)));
00084 connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
00085 hasSelection(false);
00086 }
00087
00088 KoCopyController::~KoCopyController()
00089 {
00090 delete d;
00091 }
00092
00093 void KoCopyController::hasSelection(bool selection)
00094 {
00095 d->appHasSelection = selection;
00096 d->action->setEnabled(d->appHasSelection ||
00097 (d->canvas->toolProxy()->selection() && d->canvas->toolProxy()->selection()->hasSelection()));
00098 }
00099
00100 #include "KoCopyController.moc"
|