summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/kivio_doc.h
blob: 72bc3d07c4f5ba2c918e81e51acbd065bcf764f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
 * Kivio - Visual Modelling and Flowcharting
 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
#ifndef __kivio_doc_h__
#define __kivio_doc_h__

#include "kivio_grid_data.h"

#include <tqptrlist.h>
#include <tqobject.h>

#include <KoDocument.h>
#include <KoMainWindow.h>
#include <KoGlobal.h>

#include "kivio_config.h"
#include <koffice_export.h>
class KivioDoc;
class KivioView;
class KivioMap;
class KivioPage;

class ExportPageDialog;
class KivioGroupStencil;
class KivioStencilSpawner;
class KivioStencilSpawnerSet;
class KivioStackBar;
class KivioPainter;
class KivioStencil;

namespace Kivio {
  class DragBarButton;
}

class KoStore;
class TQDomDocument;
class DCOPObject;
class KoCommandHistory;

class TQPainter;
class KPrinter;
class KCommand;
class KoZoomHandler;
class TQFont;

#define MIME_TYPE "application/x-kivio"

using namespace Kivio;

class KIVIO_EXPORT KivioDoc : public KoDocument
{
  Q_OBJECT
  TQ_OBJECT
  friend class KivioPage;
  public:
    KivioDoc( TQWidget *parentWidget = 0, const char* widgetName = 0, TQObject* parent = 0, const char* name = 0, bool singleViewMode = false );
    ~KivioDoc();

    virtual DCOPObject* dcopObject();

    virtual TQDomDocument saveXML();
    virtual bool saveOasis(KoStore* store, KoXmlWriter* manifestWriter);

    virtual bool loadXML( TQIODevice *, const TQDomDocument& doc );
    virtual bool loadOasis( const TQDomDocument& doc, KoOasisStyles& oasisStyles, const TQDomDocument& settings, KoStore* );

    virtual bool initDoc(InitDocFlags flags, TQWidget* parentWidget=0);

    virtual TQCString mimeType() const { return MIME_TYPE; }

    /**
    * @return a pointer to a new KivioPage. The KivioPage is not added to the map nor added to the GUI.
    */
    KivioPage* createPage();

    /**
    * Adds a KivioPage to the GUI and makes it active. In addition the KivioPage is
    * added to the map.
    *
    * @see KivioView
    * @see KivioMap
    */
    void addPage( KivioPage* page );

    /**
    * Adds a KivioStencilSpawnerSet to the list of spawner sets and make it active.
    *
    */
    void addSpawnerSet( const TQString& );
    void addSpawnerSetDuringLoad(const TQString& dirName, bool hidden);
    bool removeSpawnerSet( KivioStencilSpawnerSet * );

    TQPtrList<KivioStencilSpawnerSet> *spawnerSets()const { return m_pLstSpawnerSets; }

    KivioStencilSpawner *findStencilSpawner( const TQString& setId, const TQString& stencilId );
    KivioStencilSpawner *findInternalStencilSpawner( const TQString& title );

    void addInternalStencilSpawner(KivioStencilSpawner* spawner);
    KivioStencilSpawnerSet* internalSpawnerSet() { return m_pInternalSet; }

    KivioMap* map() const { return m_pMap; }

    /**
    * @return true if the document is currently loading.
    */
    bool isLoading()const { return m_bLoading; }

    virtual void paintContent( TQPainter& painter, const TQRect& rect, bool transparent = false, double zoomX = 1.0, double zoomY = 1.0 );
    void paintContent(KivioPainter& painter, const TQRect& rect, bool transparent, KivioPage* page,
                      TQPoint, KoZoomHandler*, bool, bool);

    void printContent( KPrinter& prn );

    static TQPtrList<KivioDoc>& documents();

    KivioGridData grid() { return Kivio::Config::grid(); }

    void initConfig();
    void saveConfig();
    void updateButton();
    void addCommand( KCommand * cmd );

    int undoRedoLimit() const;
    void setUndoRedoLimit(int val);
    KoCommandHistory * commandHistory()const { return m_commandHistory; }

    void insertPage( KivioPage * page );
    void takePage( KivioPage * page );
    void resetLayerPanel();
    void updateProtectPanelCheckBox();

    TQFont defaultFont() const { return m_font; }

  public slots:
    void updateView(KivioPage*);

    void slotDeleteStencilSet( DragBarButton *, TQWidget *, KivioStackBar * );
    void slotSelectionChanged();

    void setDefaultFont(const TQFont& f) { m_font = f; }

    void updateGuideLines(KoView* sender);
    void updateGuideLines(KivioPage* page);

    virtual void initEmpty();

  protected slots:
    void slotDocumentRestored();
    void slotCommandExecuted();
    void loadStencil();

    virtual void openExistingFile( const TQString& file );
    virtual void openTemplate( const TQString& file );

  signals:
    void sig_selectionChanged();
    void sig_addPage(KivioPage*);
    void sig_addSpawnerSet( KivioStencilSpawnerSet * );
    void sig_updateView(KivioPage*);
    void sig_pageNameChanged(KivioPage*, const TQString&);
    void sig_deleteStencilSet( DragBarButton*, TQWidget *, KivioStackBar * );
    void sig_updateGrid();

    void initProgress();
    void progress(int);
    void endProgress();

    void loadingFinished();

  protected:
    bool checkStencilsForSpawnerSet(KivioStencilSpawnerSet *);
    bool checkGroupForSpawnerSet(KivioStencil *, KivioStencilSpawnerSet *);
    KivioStencilSpawnerSet* findSpawnerSet(const TQString& dirName, const TQString& name);

    void saveOasisSettings( KoXmlWriter &/*settingsWriter*/ );
    void loadOasisSettings( const TQDomDocument&settingsDoc );

    KoView* createViewInstance( TQWidget* parent, const char* name );

    /**
    * List of stencil spawner sets
    */
    TQPtrList <KivioStencilSpawnerSet> *m_pLstSpawnerSets;


    /**
    * Loads a KivioStencilSpawnerSet based on it's id
    */
    bool loadStencilSpawnerSet(const TQString &id, bool hidden);

    /**
    * Overloaded function of @ref KoDocument.
    */
    virtual bool completeLoading( KoStore* );

    /**
    * Pointer to the map that holds all the pages.
    */
    KivioMap *m_pMap;

    /**
    * This variable is used to give every KivioPage a unique default name.
    *
    * @see #newKivioPage
    */
    int m_iPageId;

    /**
    * The URL of the this part. This variable is only set if the @ref #load function
    * had been called with an URL as argument.
    *
    * @see #load
    */
    TQString m_strFileURL;

    /**
    * true if loading is in process, otherwise false.
    * This flag is used to avoid updates etc. during loading.
    *
    * @see #isLoading
    */
    bool m_bLoading;

    static TQPtrList<KivioDoc>* s_docs;
    static int s_docId;

    KivioStencilSpawnerSet* m_pInternalSet;

    KivioGridData gridData;

    DCOPObject *dcop;
    KoCommandHistory * m_commandHistory;

    TQFont m_font;

    TQTimer* m_loadTimer;
    unsigned int m_currentFile;
    KivioStencilSpawnerSet* m_currentSet;
    TQValueList<KivioStencilSpawnerSet*> m_stencilSetLoadQueue;

    bool m_docOpened; // Used to for a hack that make kivio not crash if you cancel startup dialog.
};

#endif