Changeset View
Changeset View
Standalone View
Standalone View
libs/flake/KoCanvasControllerWidgetViewport_p.cpp
Show All 36 Lines | |||||
37 | #include "KoShape_p.h" | 37 | #include "KoShape_p.h" | ||
38 | #include "KoShapeFactoryBase.h" // for the SHAPE mimetypes | 38 | #include "KoShapeFactoryBase.h" // for the SHAPE mimetypes | ||
39 | #include "KoShapeRegistry.h" | 39 | #include "KoShapeRegistry.h" | ||
40 | #include "KoShapeController.h" | 40 | #include "KoShapeController.h" | ||
41 | #include "KoShapeManager.h" | 41 | #include "KoShapeManager.h" | ||
42 | #include "KoSelection.h" | 42 | #include "KoSelection.h" | ||
43 | #include "KoCanvasBase.h" | 43 | #include "KoCanvasBase.h" | ||
44 | #include "KoShapeLayer.h" | 44 | #include "KoShapeLayer.h" | ||
45 | #include "KoShapePaste.h" | | |||
46 | #include "KoShapePaintingContext.h" | 45 | #include "KoShapePaintingContext.h" | ||
47 | #include "KoToolProxy.h" | 46 | #include "KoToolProxy.h" | ||
48 | #include "KoCanvasControllerWidget.h" | 47 | #include "KoCanvasControllerWidget.h" | ||
49 | #include "KoViewConverter.h" | 48 | #include "KoViewConverter.h" | ||
50 | 49 | | |||
51 | 50 | | |||
52 | // ********** Viewport ********** | 51 | // ********** Viewport ********** | ||
53 | Viewport::Viewport(KoCanvasControllerWidget *parent) | 52 | Viewport::Viewport(KoCanvasControllerWidget *parent) | ||
Show All 38 Lines | 89 | { | |||
92 | resetLayout(); | 91 | resetLayout(); | ||
93 | } | 92 | } | ||
94 | 93 | | |||
95 | void Viewport::setDrawShadow(bool drawShadow) | 94 | void Viewport::setDrawShadow(bool drawShadow) | ||
96 | { | 95 | { | ||
97 | m_drawShadow = drawShadow; | 96 | m_drawShadow = drawShadow; | ||
98 | } | 97 | } | ||
99 | 98 | | |||
100 | | ||||
101 | void Viewport::handleDragEnterEvent(QDragEnterEvent *event) | 99 | void Viewport::handleDragEnterEvent(QDragEnterEvent *event) | ||
102 | { | 100 | { | ||
103 | // if not a canvas set then ignore this, makes it possible to assume | 101 | // if not a canvas set then ignore this, makes it possible to assume | ||
104 | // we have a canvas in all the support methods. | 102 | // we have a canvas in all the support methods. | ||
105 | if (!(m_parent->canvas() && m_parent->canvas()->canvasWidget())) | 103 | if (!(m_parent->canvas() && m_parent->canvas()->canvasWidget())) { | ||
104 | event->ignore(); | ||||
106 | return; | 105 | return; | ||
106 | } | ||||
107 | 107 | | |||
108 | // only allow dropping when active layer is editable | 108 | // only allow dropping when active layer is editable | ||
109 | KoSelection *selection = m_parent->canvas()->shapeManager()->selection(); | 109 | KoSelection *selection = m_parent->canvas()->shapeManager()->selection(); | ||
110 | KoShapeLayer *activeLayer = selection->activeLayer(); | 110 | KoShapeLayer *activeLayer = selection->activeLayer(); | ||
111 | if (activeLayer && (!activeLayer->isEditable() || activeLayer->isGeometryProtected())) | 111 | if (activeLayer && (!activeLayer->isEditable() || activeLayer->isGeometryProtected())) { | ||
112 | event->ignore(); | ||||
112 | return; | 113 | return; | ||
114 | } | ||||
113 | 115 | | |||
114 | const QMimeData *data = event->mimeData(); | 116 | const QMimeData *data = event->mimeData(); | ||
115 | if (data->hasFormat(SHAPETEMPLATE_MIMETYPE) || | 117 | if (data->hasFormat(SHAPETEMPLATE_MIMETYPE) || | ||
116 | data->hasFormat(SHAPEID_MIMETYPE)) { | 118 | data->hasFormat(SHAPEID_MIMETYPE)) { | ||
117 | QByteArray itemData; | 119 | QByteArray itemData; | ||
118 | bool isTemplate = true; | 120 | bool isTemplate = true; | ||
119 | if (data->hasFormat(SHAPETEMPLATE_MIMETYPE)) | 121 | if (data->hasFormat(SHAPETEMPLATE_MIMETYPE)) | ||
120 | itemData = data->data(SHAPETEMPLATE_MIMETYPE); | 122 | itemData = data->data(SHAPETEMPLATE_MIMETYPE); | ||
Show All 35 Lines | |||||
156 | if (!m_draggedShape) return; | 158 | if (!m_draggedShape) return; | ||
157 | 159 | | |||
158 | if (m_draggedShape->shapeId().isEmpty()) | 160 | if (m_draggedShape->shapeId().isEmpty()) | ||
159 | m_draggedShape->setShapeId(factory->id()); | 161 | m_draggedShape->setShapeId(factory->id()); | ||
160 | m_draggedShape->setZIndex(KoShapePrivate::MaxZIndex); | 162 | m_draggedShape->setZIndex(KoShapePrivate::MaxZIndex); | ||
161 | m_draggedShape->setAbsolutePosition(correctPosition(event->pos())); | 163 | m_draggedShape->setAbsolutePosition(correctPosition(event->pos())); | ||
162 | 164 | | |||
163 | m_parent->canvas()->shapeManager()->addShape(m_draggedShape); | 165 | m_parent->canvas()->shapeManager()->addShape(m_draggedShape); | ||
164 | } | | |||
165 | else if (data->hasFormat(KoOdf::mimeType(KoOdf::Text))) { | | |||
166 | KoShapeManager *sm = m_parent->canvas()->shapeManager(); | | |||
167 | KoShapePaste paste(m_parent->canvas(), sm->selection()->activeLayer()); | | |||
168 | if (paste.paste(KoOdf::Text, data)) { | | |||
169 | QList<KoShape *> shapes = paste.pastedShapes(); | | |||
170 | if (shapes.count() == 1) { | | |||
171 | m_draggedShape = shapes.first(); | | |||
172 | m_draggedShape->setZIndex(KoShapePrivate::MaxZIndex); | | |||
173 | event->setDropAction(Qt::CopyAction); | | |||
174 | } | | |||
175 | event->accept(); | | |||
176 | } | | |||
177 | } else { | 166 | } else { | ||
178 | event->ignore(); | 167 | event->ignore(); | ||
179 | } | 168 | } | ||
180 | } | 169 | } | ||
181 | 170 | | |||
182 | void Viewport::handleDropEvent(QDropEvent *event) | 171 | void Viewport::handleDropEvent(QDropEvent *event) | ||
183 | { | 172 | { | ||
184 | if (!m_draggedShape) { | 173 | if (!m_draggedShape) { | ||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |