~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to words/part/KWDocument.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "frames/KWFrameLayout.h"
40
40
#include "frames/KWOutlineShape.h"
41
41
#include "dialogs/KWFrameDialog.h"
42
 
#include "dialogs/KWStartupWidget.h"
43
42
#include "commands/KWPageInsertCommand.h"
44
43
#include "commands/KWPageRemoveCommand.h"
45
44
#include "KWRootAreaProvider.h"
58
57
#include <KoStyleManager.h>
59
58
#include <KoDocumentResourceManager.h>
60
59
#include <KoCanvasResourceManager.h>
61
 
#include <KoInteractionTool.h>
62
60
#include <KoInlineTextObjectManager.h>
63
61
#include <KoDocumentInfo.h>
64
62
#include <KoCharacterStyle.h>
81
79
// KDE + Qt includes
82
80
#include <klocale.h>
83
81
#include <kstandardaction.h>
84
 
#include <kmessagebox.h>
85
82
#include <kaction.h>
86
83
#include <kdebug.h>
87
84
#include <QIODevice>
91
88
#include <QTextBlock>
92
89
#include <QTime>
93
90
 
94
 
KWDocument::KWDocument(QObject *parent)
95
 
        : KoDocument(parent),
 
91
KWDocument::KWDocument(KoPart *part)
 
92
        : KoDocument(part),
96
93
        m_frameLayout(&m_pageManager, m_frameSets),
97
94
        m_mainFramesetEverFinished(false)
98
95
{
99
96
    m_frameLayout.setDocument(this);
100
97
    resourceManager()->setOdfDocument(this);
101
98
 
102
 
    setComponentData(KWFactory::componentData(), false);
103
 
    setTemplateType("words_template");
104
 
 
105
99
    connect(&m_frameLayout, SIGNAL(newFrameSet(KWFrameSet*)), this, SLOT(addFrameSet(KWFrameSet*)));
106
100
    connect(&m_frameLayout, SIGNAL(removedFrameSet(KWFrameSet*)), this, SLOT(removeFrameSet(KWFrameSet*)));
107
101
 
166
160
    if (!m_frameSets.contains(frame->frameSet())) {
167
161
        addFrameSet(frame->frameSet());
168
162
    }
169
 
    foreach (KoView *view, views()) {
170
 
        KoCanvasBase *canvas = static_cast<KWView*>(view)->canvasBase();
171
 
        canvas->shapeManager()->addShape(shape);
172
 
    }
 
163
 
 
164
    emit shapeAdded(shape);
 
165
 
173
166
    shape->update();
174
167
}
175
168
 
185
178
        else
186
179
            fs->removeFrame(frame);
187
180
    } else { // not a frame, but we still have to remove it from views.
188
 
        foreach (KoView *view, views()) {
189
 
            KoCanvasBase *canvas = static_cast<KWView*>(view)->canvasBase();
190
 
            canvas->shapeManager()->remove(shape);
191
 
        }
 
181
        emit shapeRemoved(shape);
192
182
    }
193
183
}
194
184
 
212
202
    }
213
203
}
214
204
 
215
 
QPixmap KWDocument::generatePreview(const QSize &size)
 
205
QPixmap KWDocument::generatePreview(const QSize &/*size*/)
216
206
{
217
207
    // use first page as preview for all pages
218
208
    KWPage firstPage = pageManager()->begin();
224
214
    // use shape manager from canvasItem even for QWidget environments
225
215
    // if using the shape manager from one of the views there is no guarantee
226
216
    // that the view, its canvas and the shapemanager is not destroyed in between
227
 
    KoShapeManager* shapeManager = static_cast<KWCanvasItem*>(canvasItem())->shapeManager();
 
217
//FIXME    KoShapeManager* shapeManager = static_cast<KWCanvasItem*>(canvasItem())->shapeManager();
228
218
 
229
 
    return QPixmap::fromImage(firstPage.thumbnail(size, shapeManager));
 
219
//FIXME    return QPixmap::fromImage(firstPage.thumbnail(size, shapeManager));
 
220
        return QPixmap();
230
221
}
231
222
 
232
223
void KWDocument::paintContent(QPainter &, const QRect &)
233
224
{
234
225
}
235
226
 
236
 
KoView *KWDocument::createViewInstance(QWidget *parent)
237
 
{
238
 
    KWView *view = new KWView(m_viewMode, this, parent);
239
 
    bool switchToolCalled = false;
240
 
    foreach (KWFrameSet *fs, m_frameSets) {
241
 
        if (fs->frameCount() == 0)
242
 
            continue;
243
 
        foreach (KWFrame *frame, fs->frames())
244
 
            view->canvasBase()->shapeManager()->addShape(frame->shape(), KoShapeManager::AddWithoutRepaint);
245
 
        if (switchToolCalled)
246
 
            continue;
247
 
        KWTextFrameSet *tfs = dynamic_cast<KWTextFrameSet*>(fs);
248
 
        if (tfs && tfs->textFrameSetType() == Words::MainTextFrameSet) {
249
 
            KoSelection *selection = view->canvasBase()->shapeManager()->selection();
250
 
            selection->select(fs->frames().first()->shape());
251
 
 
252
 
            KoToolManager::instance()->switchToolRequested(
253
 
                KoToolManager::instance()->preferredToolForSelection(selection->selectedShapes()));
254
 
            switchToolCalled = true;
255
 
        }
256
 
    }
257
 
    if (!switchToolCalled)
258
 
        KoToolManager::instance()->switchToolRequested(KoInteractionTool_ID);
259
 
    return view;
260
 
}
261
 
 
262
 
QGraphicsItem *KWDocument::createCanvasItem()
263
 
{
264
 
    // caller owns the canvas item
265
 
    KWCanvasItem *item = new KWCanvasItem(m_viewMode, this);
266
 
    foreach (KWFrameSet *fs, m_frameSets) {
267
 
        if (fs->frameCount() == 0) {
268
 
            continue;
269
 
        }
270
 
        foreach (KWFrame *frame, fs->frames()) {
271
 
            item->shapeManager()->addShape(frame->shape(), KoShapeManager::AddWithoutRepaint);
272
 
        }
273
 
    }
274
 
    return item;
275
 
}
276
 
 
277
227
KWPage KWDocument::insertPage(int afterPageNum, const QString &masterPageName, bool addUndoRedoCommand)
278
228
{
279
229
    kDebug(32001) << "afterPageNum=" << afterPageNum << "masterPageName=" << masterPageName;
325
275
    setModified(true);
326
276
    foreach (KWFrame *frame, fs->frames())
327
277
        removeFrame(frame);
328
 
    foreach (KoView *view, views()) {
329
 
        KoCanvasBase *canvas = static_cast<KWView*>(view)->canvasBase();
330
 
        canvas->resourceManager()->setResource(Words::CurrentFrameSetCount, m_frameSets.count());
331
 
    }
 
278
 
 
279
    emit resourceChanged(Words::CurrentFrameSetCount, m_frameSets.count());
 
280
 
332
281
    disconnect(fs, SIGNAL(frameAdded(KWFrame*)), this, SLOT(addFrame(KWFrame*)));
333
282
    disconnect(fs, SIGNAL(frameRemoved(KWFrame*)), this, SLOT(removeFrame(KWFrame*)));
334
283
}
459
408
{
460
409
    kDebug(32001) << "frame=" << frame << "frameSet=" << frame->frameSet();
461
410
    //firePageSetupChanged();
462
 
    foreach (KoView *view, views()) {
463
 
        KoCanvasBase *canvas = static_cast<KWView*>(view)->canvasBase();
464
 
        canvas->shapeManager()->addShape(frame->shape(), KoShapeManager::AddWithoutRepaint);
465
 
        canvas->resourceManager()->setResource(Words::CurrentFrameSetCount, m_frameSets.count());
466
 
    }
467
 
    if (viewCount() == 0) {
468
 
        KoCanvasBase *canvas = dynamic_cast<KoCanvasBase *>(canvasItem(false));
469
 
        if (canvas) {
470
 
            canvas->shapeManager()->addShape(frame->shape(), KoShapeManager::AddWithoutRepaint);
471
 
            canvas->resourceManager()->setResource(Words::CurrentFrameSetCount, m_frameSets.count());
472
 
        }
473
 
    }
474
 
    //frame->shape()->update();
 
411
    emit resourceChanged(Words::CurrentFrameSetCount, m_frameSets.count());
 
412
    emit shapeAdded(frame->shape(), KoShapeManager::AddWithoutRepaint);
475
413
}
476
414
 
477
415
void KWDocument::removeFrame(KWFrame *frame)
479
417
    if (frame->shape() == 0) return;
480
418
    kDebug(32001) << "frame=" << frame << "frameSet=" << frame->frameSet();
481
419
 
482
 
    removeFrameFromViews(frame);
 
420
    emit shapeRemoved(frame->shape());
483
421
    KWPage page = pageManager()->page(frame->shape());
484
422
    if (!page.isValid()) return;
485
423
    if (!page.isAutoGenerated()) return;
799
737
    relayout(framesets);
800
738
}
801
739
 
802
 
void KWDocument::showStartUpWidget(KoMainWindow *parent, bool alwaysShow)
803
 
{
804
 
    // print error if kotext not available
805
 
    if (KoShapeRegistry::instance()->value(TextShape_SHAPEID) == 0)
806
 
        // need to wait 1 event since exiting here would not work.
807
 
        QTimer::singleShot(0, this, SLOT(showErrorAndDie()));
808
 
    else
809
 
        KoDocument::showStartUpWidget(parent, alwaysShow);
810
 
}
811
 
 
812
 
void KWDocument::showErrorAndDie()
813
 
{
814
 
    KMessageBox::error(widget(),
815
 
                       i18n("Can not find needed text component, Words will quit now"),
816
 
                       i18n("Installation Error"));
817
 
    QCoreApplication::exit(10);
818
 
}
819
 
 
820
 
void KWDocument::removeFrameFromViews(KWFrame *frame)
821
 
{
822
 
    Q_ASSERT(frame);
823
 
    foreach (KoView *view, views()) {
824
 
        KoCanvasBase *canvas = static_cast<KWView*>(view)->canvasBase();
825
 
        canvas->shapeManager()->remove(frame->shape());
826
 
    }
827
 
}
828
 
 
829
 
QList<KoDocument::CustomDocumentWidgetItem> KWDocument::createCustomDocumentWidgets(QWidget *parent)
830
 
{
831
 
    KoColumns columns;
832
 
    columns.gapWidth = m_config.defaultColumnSpacing();
833
 
 
834
 
    QList<KoDocument::CustomDocumentWidgetItem> widgetList;
835
 
    KoDocument::CustomDocumentWidgetItem item;
836
 
    item.widget = new KWStartupWidget(parent, this, columns);
837
 
    widgetList << item;
838
 
    return widgetList;
839
 
}
840
 
 
841
740
void KWDocument::saveConfig()
842
741
{
843
 
    if (!isReadWrite())
844
 
        return;
845
742
//   KConfigGroup group(KoGlobal::calligraConfig(), "Spelling");
846
743
//   group.writeEntry("PersonalDict", m_spellCheckPersonalDict);
847
744