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>
91
88
#include <QTextBlock>
94
KWDocument::KWDocument(QObject *parent)
91
KWDocument::KWDocument(KoPart *part)
96
93
m_frameLayout(&m_pageManager, m_frameSets),
97
94
m_mainFramesetEverFinished(false)
99
96
m_frameLayout.setDocument(this);
100
97
resourceManager()->setOdfDocument(this);
102
setComponentData(KWFactory::componentData(), false);
103
setTemplateType("words_template");
105
99
connect(&m_frameLayout, SIGNAL(newFrameSet(KWFrameSet*)), this, SLOT(addFrameSet(KWFrameSet*)));
106
100
connect(&m_frameLayout, SIGNAL(removedFrameSet(KWFrameSet*)), this, SLOT(removeFrameSet(KWFrameSet*)));
166
160
if (!m_frameSets.contains(frame->frameSet())) {
167
161
addFrameSet(frame->frameSet());
169
foreach (KoView *view, views()) {
170
KoCanvasBase *canvas = static_cast<KWView*>(view)->canvasBase();
171
canvas->shapeManager()->addShape(shape);
164
emit shapeAdded(shape);
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);
181
emit shapeRemoved(shape);
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();
229
return QPixmap::fromImage(firstPage.thumbnail(size, shapeManager));
219
//FIXME return QPixmap::fromImage(firstPage.thumbnail(size, shapeManager));
232
223
void KWDocument::paintContent(QPainter &, const QRect &)
236
KoView *KWDocument::createViewInstance(QWidget *parent)
238
KWView *view = new KWView(m_viewMode, this, parent);
239
bool switchToolCalled = false;
240
foreach (KWFrameSet *fs, m_frameSets) {
241
if (fs->frameCount() == 0)
243
foreach (KWFrame *frame, fs->frames())
244
view->canvasBase()->shapeManager()->addShape(frame->shape(), KoShapeManager::AddWithoutRepaint);
245
if (switchToolCalled)
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());
252
KoToolManager::instance()->switchToolRequested(
253
KoToolManager::instance()->preferredToolForSelection(selection->selectedShapes()));
254
switchToolCalled = true;
257
if (!switchToolCalled)
258
KoToolManager::instance()->switchToolRequested(KoInteractionTool_ID);
262
QGraphicsItem *KWDocument::createCanvasItem()
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) {
270
foreach (KWFrame *frame, fs->frames()) {
271
item->shapeManager()->addShape(frame->shape(), KoShapeManager::AddWithoutRepaint);
277
227
KWPage KWDocument::insertPage(int afterPageNum, const QString &masterPageName, bool addUndoRedoCommand)
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());
279
emit resourceChanged(Words::CurrentFrameSetCount, m_frameSets.count());
332
281
disconnect(fs, SIGNAL(frameAdded(KWFrame*)), this, SLOT(addFrame(KWFrame*)));
333
282
disconnect(fs, SIGNAL(frameRemoved(KWFrame*)), this, SLOT(removeFrame(KWFrame*)));
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());
467
if (viewCount() == 0) {
468
KoCanvasBase *canvas = dynamic_cast<KoCanvasBase *>(canvasItem(false));
470
canvas->shapeManager()->addShape(frame->shape(), KoShapeManager::AddWithoutRepaint);
471
canvas->resourceManager()->setResource(Words::CurrentFrameSetCount, m_frameSets.count());
474
//frame->shape()->update();
411
emit resourceChanged(Words::CurrentFrameSetCount, m_frameSets.count());
412
emit shapeAdded(frame->shape(), KoShapeManager::AddWithoutRepaint);
477
415
void KWDocument::removeFrame(KWFrame *frame)
479
417
if (frame->shape() == 0) return;
480
418
kDebug(32001) << "frame=" << frame << "frameSet=" << frame->frameSet();
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);
802
void KWDocument::showStartUpWidget(KoMainWindow *parent, bool alwaysShow)
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()));
809
KoDocument::showStartUpWidget(parent, alwaysShow);
812
void KWDocument::showErrorAndDie()
814
KMessageBox::error(widget(),
815
i18n("Can not find needed text component, Words will quit now"),
816
i18n("Installation Error"));
817
QCoreApplication::exit(10);
820
void KWDocument::removeFrameFromViews(KWFrame *frame)
823
foreach (KoView *view, views()) {
824
KoCanvasBase *canvas = static_cast<KWView*>(view)->canvasBase();
825
canvas->shapeManager()->remove(frame->shape());
829
QList<KoDocument::CustomDocumentWidgetItem> KWDocument::createCustomDocumentWidgets(QWidget *parent)
832
columns.gapWidth = m_config.defaultColumnSpacing();
834
QList<KoDocument::CustomDocumentWidgetItem> widgetList;
835
KoDocument::CustomDocumentWidgetItem item;
836
item.widget = new KWStartupWidget(parent, this, columns);
841
740
void KWDocument::saveConfig()
845
742
// KConfigGroup group(KoGlobal::calligraConfig(), "Spelling");
846
743
// group.writeEntry("PersonalDict", m_spellCheckPersonalDict);