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
|
/***************************************************************************
* Copyright (C) 2005 by David Saxton *
* david@bluehaze.org *
* *
* 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. *
***************************************************************************/
#ifndef DOCUMENT_H
#define DOCUMENT_H
#include <kurl.h>
#include <tqguardedptr.h>
class DCOPObject;
class Document;
class DocumentIface;
class KTechlab;
class View;
class ViewContainer;
typedef TQValueList<TQGuardedPtr<View> > ViewList;
/**
@author David Saxton
*/
class Document : public TQObject
{
Q_OBJECT
public:
enum DocumentType
{
dt_none, // Used to denote document type not known / specified / etc, when appropriate
dt_flowcode,
dt_circuit,
dt_mechanics,
dt_text,
dt_pinMapEditor
};
Document( const TQString &caption, KTechlab *ktechlab, const char *name = 0 );
virtual ~Document();
/**
* If the user has created a new document from the new file dialog, and
* wants to add it to the project, then this must wait until this file is
* given a url. Set this to true to add the file to the active project when
* it is first saved.
*/
void setAddToProjectOnSave( bool add ) { m_bAddToProjectOnSave = add; }
/**
* Caption of document, e.g. "Untitled 2"
*/
TQString caption() const { return m_caption; }
/**
* Set the caption of the document, to be displayed in the tab bar when
* active
*/
void setCaption( const TQString &caption );
/**
* Return the dcop object for this document
*/
DCOPObject * dcopObject() const;
/**
* Returns the dcop suffix for this document - a unique ID for the current
* app session. DCOP name will be "Document#dcopID()"
*/
unsigned dcopID() const { return m_dcopID; }
/**
* Sets the dcop suffix. The DCOP object for this document will be renamed.
* @see dcopID
*/
void setDCOPID( unsigned id );
/**
* Returns the active view, which is the last view to be used to edit in
*/
View *activeView() const { return p_activeView; }
ViewList viewList() const { return m_viewList; }
/**
* Returns the type of document.
* @see Document::DocumentType
*/
DocumentType type() const { return m_type; }
/**
* Returns the number of open views.
*/
uint numberOfViews() const { return m_viewList.size(); }
/**
* Create a view that will display the document data. In all reimplemented
* functions, you must call handleNewView after creating the view, so that
* the appropriate slots, pointers, etc can all be initialised.
*/
virtual View *createView( ViewContainer *viewContainer, uint viewAreaId, const char *name = 0l ) = 0;
/**
* Returns the url of the file that the Document refers to
*/
const KURL& url() const { return m_url; }
/**
* Prompts the user for a url, with the given types for the filter.
* If user accepts, returns true, and set the url to the new url.
*/
bool getURL( const TQString &types );
/**
* Attempts to open a url, and returns true if succesful.
* You must reinherit this function.
*/
virtual bool openURL( const KURL &url ) = 0;
/**
* Sets the url of the file that this Document refers to
*/
void setURL( const KURL &url );
/**
* Sets whether the file is modified or not. Will emit modifiedStateChanged
* if state changes. You must emit this signal if you reinherit this
*/
virtual void setModified( bool modified );
/**
* Returns the modification state since last-save.
*/
virtual bool isModified() const { return b_modified; }
/**
* Returns true if undo is avilable.
*/
virtual bool isUndoAvailable() const { return false; }
/**
* Returns true if redo is avilable.
*/
virtual bool isRedoAvailable() const { return false; }
/**
* Saves the file to a new name.
*/
virtual void fileSaveAs() = 0;
/**
* Attempts to close the file without saving, prompting the user if the
* file has been modified. If succesful, calls TQObject::deleteLater(), and
* returns true (otherwise returns false).
*/
virtual bool fileClose();
/**
* Saves the file.
*/
virtual void fileSave() = 0;
/**
* Prints the file.
*/
virtual void print() {};
/**
* Cuts whatever is selected.
*/
virtual void cut() {};
/**
* Copies whatever is selected.
*/
virtual void copy() {};
/**
* Attempts to paste whatever is in the clipboard.
*/
virtual void paste() {};
/**
* Undo the last operation. You should reinherit this function.
*/
virtual void undo() {};
/**
* Redo the undone last operation. You should reinherit this function.
*/
virtual void redo() {};
/**
* Selects everything in the view.
*/
virtual void selectAll() {};
virtual void convertToMicrobe() {};
virtual void convertToHex() {};
virtual void convertToPIC() {};
virtual void convertToAssembly() {};
virtual void debugRun() {};
virtual void debugInterrupt() {};
virtual void debugStop() {};
virtual void debugStep() {};
KTechlab *ktechlab() const { return p_ktechlab; }
bool isDeleted() const { return m_bDeleted; }
protected slots:
/**
* Called when the user changes the configuration.
*/
virtual void slotUpdateConfiguration() {};
#define protected public
signals:
/**
* Emitted when an operation has been performed that
* has caused the stack of available undo/redo operations to
* have changed
*/
void undoRedoStateChanged();
#undef protected
signals:
/**
* Emitted when the Document goes from modified to unmodified,
* or vice-versa
*/
void modifiedStateChanged();
/**
* Emitted when the name of the file that the Document refers to
* is changed.
*/
void fileNameChanged( const KURL &url );
void viewFocused( View *view );
void viewUnfocused();
private slots:
void slotViewDestroyed( TQObject *obj );
void slotViewFocused( View *view );
protected:
/**
* You must call this function after creating a new view
*/
virtual void handleNewView( View *view );
bool b_modified;
KTechlab *p_ktechlab;
TQGuardedPtr<View> p_activeView;
DocumentType m_type;
ViewList m_viewList;
TQString m_caption;
bool m_bAddToProjectOnSave;
DocumentIface * m_pDocumentIface;
unsigned m_dcopID;
unsigned m_nextViewID;
// Set to true by the document et subclasses destructors, used to avoid
// doing stuff that might lead to crash when being deleted.
bool m_bDeleted;
private:
KURL m_url;
};
#endif
|