1
1
/* This file is part of the KDE project
2
2
* Copyright (C) 2001 David Faure <faure@kde.org>
3
3
* Copyright (C) 2005-2007, 2009, 2010 Thomas Zander <zander@kde.org>
4
* Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com>
5
6
* This library is free software; you can redistribute it and/or
6
7
* modify it under the terms of the GNU Library General Public
47
49
#include "dockers/KWStatisticsDocker.h"
48
50
#include "commands/KWFrameCreateCommand.h"
49
51
#include "commands/KWCreateOutlineCommand.h"
52
#include "commands/KWClipFrameCommand.h"
53
#include "commands/KWRemoveFrameClipCommand.h"
51
55
// koffice libs includes
56
#include <kofficeversion.h>
52
57
#include <KoCopyController.h>
53
58
#include <KoTextDocument.h>
54
59
#include <KoTextShapeData.h>
97
102
static KWFrame *frameForShape(KoShape *shape)
99
KoShape *parent = shape;
100
while (parent->parent())
101
parent = parent->parent();
102
return dynamic_cast<KWFrame*>(parent->applicationData());
105
KWFrame *answer = dynamic_cast<KWFrame*>(shape->applicationData());
108
if (shape->parent() == 0)
110
shape = shape->parent();
113
KWFrame *answer = dynamic_cast<KWFrame*>(shape->applicationData());
114
if (answer == 0) { // this may be a clipping shape containing the frame-shape
115
KoShapeContainer *container = dynamic_cast<KoShapeContainer*>(shape);
116
if (container && container->shapeCount() == 1) {
117
answer = dynamic_cast<KWFrame*>(container->shapes()[0]->applicationData());
105
123
KWView::KWView(const QString &viewMode, KWDocument *document, QWidget *parent)
106
124
: KoView(document, parent)
125
, m_canvas(0), m_actionMenu(0)
108
127
m_document = document;
109
128
m_snapToGrid = m_document->gridData().snapToGrid();
179
204
void KWView::updateReadWrite(bool readWrite)
206
m_canvas->setReadWrite(readWrite);
207
KoToolManager::instance()->updateReadWrite(m_gui->canvasController(), readWrite);
181
208
m_actionFormatFrameSet->setEnabled(readWrite);
182
209
m_actionInsertFrameBreak->setEnabled(readWrite);
183
210
m_actionViewHeader->setEnabled(readWrite);
282
309
actionCollection()->addAction("send_toback_frame", m_actionSendBackward);
283
310
connect(m_actionSendBackward, SIGNAL(triggered()), this, SLOT(sendToBack()));
285
KActionMenu *actionMenu = new KActionMenu(i18n("Variable"), this);
286
foreach (QAction *action, m_document->inlineTextObjectManager()->createInsertVariableActions(kwcanvas()))
287
actionMenu->addAction(action);
288
actionCollection()->addAction("insert_variable", actionMenu);
312
m_actionMenu = new KActionMenu(i18n("Variable"), this);
313
foreach (QAction *action, m_document->inlineTextObjectManager()->createInsertVariableActions(canvasBase()))
314
m_actionMenu->addAction(action);
315
actionCollection()->addAction("insert_variable", m_actionMenu);
316
connect(m_document->inlineTextObjectManager()->variableManager(), SIGNAL(valueChanged()), this, SLOT(variableChanged()));
290
318
#ifdef SHOULD_BUILD_RDF
291
319
if (KoDocumentRdf* rdf = m_document->documentRdf()) {
292
KAction* createRef = rdf->createInsertSemanticObjectReferenceAction(kwcanvas());
320
KAction* createRef = rdf->createInsertSemanticObjectReferenceAction(canvasBase());
293
321
actionCollection()->addAction("insert_semanticobject_ref", createRef);
294
322
KActionMenu *subMenu = new KActionMenu(i18n("Create"), this);
295
323
actionCollection()->addAction("insert_semanticobject_new", subMenu);
296
foreach(KAction *action, rdf->createInsertSemanticObjectNewActions(kwcanvas())) {
324
foreach(KAction *action, rdf->createInsertSemanticObjectNewActions(canvasBase())) {
297
325
subMenu->addAction(action);
354
382
// -------------- Edit actions
355
383
action = actionCollection()->addAction(KStandardAction::Cut, "edit_cut", 0, 0);
356
new KoCutController(kwcanvas(), action);
384
new KoCutController(canvasBase(), action);
357
385
action = actionCollection()->addAction(KStandardAction::Copy, "edit_copy", 0, 0);
358
new KoCopyController(kwcanvas(), action);
386
new KoCopyController(canvasBase(), action);
359
387
action = actionCollection()->addAction(KStandardAction::Paste, "edit_paste", 0, 0);
360
new KoPasteController(kwcanvas(), action);
388
new KoPasteController(canvasBase(), action);
362
390
action = new KAction(i18n("Statistics"), this);
363
391
actionCollection()->addAction("file_statistics", action);
403
431
action = new KAction(KIcon("edit-delete"), i18n("Delete"), this);
404
432
action->setShortcut(QKeySequence("Del"));
405
433
connect(action, SIGNAL(triggered()), this, SLOT(editDeleteSelection()));
406
connect(kwcanvas()->toolProxy(), SIGNAL(selectionChanged(bool)), action, SLOT(setEnabled(bool)));
434
connect(canvasBase()->toolProxy(), SIGNAL(selectionChanged(bool)), action, SLOT(setEnabled(bool)));
407
435
actionCollection()->addAction("edit_delete", action);
409
437
action = m_document->gridData().gridToggleAction(m_canvas);
419
447
action->setWhatsThis(i18n("Create a copy of the current frame, that remains linked to it. This means they always show the same contents: modifying the contents in such a frame will update all its linked copies."));
420
448
connect(action, SIGNAL(triggered()), this, SLOT(createLinkedFrame()));
422
action = new KAction(i18n("Create custom outline"), this);
450
action = new KAction(i18n("Create Custom Outline"), this);
423
451
actionCollection()->addAction("create_custom_outline", action);
424
452
action->setToolTip(i18n("Create a custom vector outline that text will run around"));
425
453
action->setWhatsThis(i18n("Text normally runs around the content of a shape, when you want a custom outline that is independent of the content you can create one and alter it with the vector tools"));
426
454
connect(action, SIGNAL(triggered()), this, SLOT(createCustomOutline()));
429
//------------------------ Settings menu
430
action = new KToggleAction(i18n("Status Bar"), this);
431
action->setToolTip(i18n("Shows or hides the status bar"));
432
actionCollection()->addAction("showStatusBar", action);
433
connect(action, SIGNAL(toggled(bool)), this, SLOT(showStatusBar(bool)));
456
action = new KAction(i18n("Create Frame-clip"), this);
457
actionCollection()->addAction("create_clipped_frame", action);
458
connect(action, SIGNAL(triggered()), this, SLOT(createFrameClipping()));
460
action = new KAction(i18n("Remove Frame-clip"), this);
461
actionCollection()->addAction("remove_clipped_frame", action);
462
connect(action, SIGNAL(triggered()), this, SLOT(removeFrameClipping()));
464
action = new KAction(i18n("Add Text on Shape"), this);
465
actionCollection()->addAction("add_text_on_shape", action);
466
connect(action, SIGNAL(triggered()), this, SLOT(createTextOnShape()));
468
KToggleAction *tAction = new KToggleAction(i18n("Show Status Bar"), this);
469
tAction->setCheckedState(KGuiItem(i18n("Hide Status Bar")));
470
tAction->setToolTip(i18n("Shows or hides the status bar"));
471
actionCollection()->addAction("showStatusBar", tAction);
472
connect(tAction, SIGNAL(toggled(bool)), this, SLOT(showStatusBar(bool)));
435
474
// -------------- Insert menu
436
475
/* ********** From old kwview ****
915
954
KoPrintJob *KWView::createPrintJob()
917
KWPrintingDialog *dia = new KWPrintingDialog(this);
956
KWPrintingDialog *dia = new KWPrintingDialog(m_document, m_canvas->shapeManager(), this);
918
957
dia->printer().setResolution(600);
919
dia->printer().setCreator("KWord 2.2");
958
dia->printer().setCreator(QString("KWord %1.%2.$3").arg(KOffice::versionMajor(),
959
KOffice::versionMinor(), KOffice::versionRelease()));
920
960
dia->printer().setFullPage(true); // ignore printer margins
924
964
void KWView::insertFrameBreak()
926
KoTextEditor *handler = qobject_cast<KoTextEditor*> (kwcanvas()->toolProxy()->selection());
966
KoTextEditor *handler = qobject_cast<KoTextEditor*> (canvasBase()->toolProxy()->selection());
928
968
// this means we have the text tool selected right now.
929
969
handler->insertFrameBreak();
1027
1067
void KWView::editDeleteFrame()
1029
1069
QList<KoShape*> frames;
1030
foreach (KoShape *shape, kwcanvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection)) {
1070
foreach (KoShape *shape, canvasBase()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection)) {
1031
1071
KWFrame *frame = frameForShape(shape);
1033
1073
KWTextFrameSet *fs = dynamic_cast<KWTextFrameSet*>(frame->frameSet());
1067
1107
void KWView::adjustZOrderOfSelectedFrames(KoShapeReorderCommand::MoveShapeType direction)
1069
1109
// TODO we should not allow any shapes to fall behind the main text frame.
1070
QUndoCommand *cmd = KoShapeReorderCommand::createCommand(kwcanvas()->shapeManager()->selection()->selectedShapes(),
1071
kwcanvas()->shapeManager(), direction);
1110
QUndoCommand *cmd = KoShapeReorderCommand::createCommand(canvasBase()->shapeManager()->selection()->selectedShapes(),
1111
canvasBase()->shapeManager(), direction);
1073
1113
m_document->addCommand(cmd);
1076
1116
void KWView::toggleViewFrameBorders(bool on)
1078
kwcanvas()->resourceManager()->setResource(KoText::ShowTextFrames, on);
1079
kwcanvas()->update();
1118
m_canvas->resourceManager()->setResource(KoText::ShowTextFrames, on);
1080
1120
m_document->config().setViewFrameBorders(on);
1108
1148
void KWView::inlineFrame()
1110
1150
Q_ASSERT(kwdocument()->mainFrameSet());
1111
KoSelection *selection = kwcanvas()->shapeManager()->selection();
1151
KoSelection *selection = canvasBase()->shapeManager()->selection();
1113
1153
KoShape *targetShape = 0;
1114
1154
foreach (KoShape *shape, selection->selectedShapes(KoFlake::TopLevelSelection)) {
1153
1193
QString tool = KoToolManager::instance()->preferredToolForSelection(selection->selectedShapes());
1154
1194
KoToolManager::instance()->switchToolRequested(tool);
1155
KoTextEditor *handler = qobject_cast<KoTextEditor*> (kwcanvas()->toolProxy()->selection());
1195
KoTextEditor *handler = qobject_cast<KoTextEditor*> (canvasBase()->toolProxy()->selection());
1156
1196
Q_ASSERT(handler);
1157
1197
KoTextAnchor *anchor = new KoTextAnchor(targetShape);
1158
1198
anchor->setOffset(QPointF(0, -targetShape->size().height()));
1188
1228
KWCopyShape *copy = new KWCopyShape(frame->shape(), m_document->pageManager());
1189
1229
copy->setPosition(frame->shape()->position());
1190
1230
QPointF offset(40, 40);
1191
kwcanvas()->clipToDocument(copy, offset);
1231
canvasBase()->clipToDocument(copy, offset);
1192
1232
copy->setPosition(frame->shape()->position() + offset);
1193
1233
copy->setZIndex(frame->shape()->zIndex() + 1);
1194
1234
KWFrame *newFrame = new KWFrame(copy, frame->frameSet());
1239
1279
void KWView::editSelectAllFrames()
1241
KoSelection *selection = kwcanvas()->shapeManager()->selection();
1281
KoSelection *selection = canvasBase()->shapeManager()->selection();
1242
1282
foreach (KWFrameSet *fs, m_document->frameSets()) {
1243
1283
foreach (KWFrame *frame, fs->frames()) {
1244
1284
if (frame->shape()->isVisible())
1266
1306
m_document->addCommand(cmd);
1269
KoSelection *selection = kwcanvas()->shapeManager()->selection();
1309
KoSelection *selection = canvasBase()->shapeManager()->selection();
1270
1310
selection->deselectAll();
1271
1311
foreach (KWFrame *frame, frames) {
1272
1312
KoShapeContainer *group = frame->shape()->parent();
1277
1317
KoToolManager::instance()->switchToolRequested("PathToolFactoryId");
1320
void KWView::createFrameClipping()
1322
QSet<KWFrame *> clipFrames;
1323
foreach (KoShape *shape, canvasBase()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection)) {
1324
KWFrame *frame = frameForShape(shape);
1326
if (frame->shape()->parent() == 0)
1327
clipFrames << frame;
1329
if (!clipFrames.isEmpty()) {
1330
KWClipFrameCommand *cmd = new KWClipFrameCommand(clipFrames.toList(), m_document);
1331
m_document->addCommand(cmd);
1335
void KWView::removeFrameClipping()
1337
QSet<KWFrame *> unClipFrames;
1338
foreach (KoShape *shape, canvasBase()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection)) {
1339
KWFrame *frame = frameForShape(shape);
1341
if (frame->shape()->parent())
1342
unClipFrames << frame;
1344
if (!unClipFrames.isEmpty()) {
1345
KWRemoveFrameClipCommand *cmd = new KWRemoveFrameClipCommand(unClipFrames.toList(), m_document);
1346
m_document->addCommand(cmd);
1280
1350
void KWView::insertImage()
1282
1352
KoShape *shape = KoImageSelectionWidget::selectImageShape(m_document->resourceManager(), this);
1313
1383
void KWView::setGuideVisibility(bool on)
1315
1385
m_document->guidesData().setShowGuideLines(on);
1316
kwcanvas()->update();
1389
void KWView::createTextOnShape()
1391
QSet<KoShape *> frameShapes;
1392
KoSelection *selection = canvasBase()->shapeManager()->selection();
1393
foreach (KoShape *shape, selection->selectedShapes(KoFlake::TopLevelSelection)) {
1394
KWFrame *frame = frameForShape(shape);
1396
if (frame->shape()->parent() == 0) {
1397
frameShapes << frame->shape();
1401
if (!frameShapes.isEmpty()) {
1402
KoAddTextOnShapeCommand *cmd = new KoAddTextOnShapeCommand(frameShapes.toList(), m_document);
1403
m_document->addCommand(cmd);
1406
foreach (KoShape *shape, frameShapes) {
1407
selection->deselect(shape);
1408
KoTextOnShapeContainer *decorator = new KoTextOnShapeContainer(shape, m_document->resourceManager());
1409
decorator->setPlainText("dummy text, la la la enzo");
1410
m_document->addShape(decorator);
1411
selection->select(decorator);
1319
1416
// end of actions
1350
1447
m_actionAddBookmark->setEnabled(false);
1352
// actions need at least one shape selected
1353
actionCollection()->action("create_linked_frame")->setEnabled(shape);
1449
// actions that need at least one shape selected
1450
QAction *action = actionCollection()->action("create_linked_frame");
1451
if (action) action->setEnabled(shape);
1452
action = actionCollection()->action("inline_frame");
1453
if (action) action->setEnabled(shape && kwdocument()->mainFrameSet());
1355
foreach (KoShape *shape, kwcanvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection)) {
1455
foreach (KoShape *shape, canvasBase()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection)) {
1356
1456
KWFrame *frame = frameForShape(shape);
1357
1457
Q_ASSERT(frame);
1358
1458
QVariant variant;