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
261
262
263
|
echo "Creating $LOCATION_ROOT/${APP_NAME_LC}/${APP_NAME_LC}.cpp...";
cat << EOF > $LOCATION_ROOT/${APP_NAME_LC}/${APP_NAME_LC}.cpp
/*
* ${APP_NAME_LC}.cpp
*
* Copyright (C) 2004 $AUTHOR <$EMAIL>
*/
#include "${APP_NAME_LC}.h"
#include "${APP_NAME_LC}pref.h"
#include <kprinter.h>
#include <tqpainter.h>
#include <tqpaintdevicemetrics.h>
#include <kdeversion.h>
#include <kglobal.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kmenubar.h>
#include <kstatusbar.h>
#include <kaccel.h>
#include <kio/netaccess.h>
#include <kfiledialog.h>
#include <kconfig.h>
#include <kurl.h>
#include <kurldrag.h>
#include <kurlrequesterdlg.h>
#include <kedittoolbar.h>
#include <kstdaccel.h>
#include <kaction.h>
#include <kstdaction.h>
${APP_NAME}::${APP_NAME}()
: KMainWindow( 0, "${APP_NAME}" ),
m_view(new ${APP_NAME}View(this)),
m_printer(0)
{
// accept dnd
setAcceptDrops(true);
// tell the KMainWindow that this is indeed the main widget
setCentralWidget(m_view);
// then, setup our actions
setupActions();
// Add typical actions and save size/toolbars/statusbar
setupGUI();
// allow the view to change the statusbar and caption
connect(m_view, TQT_SIGNAL(signalChangeStatusbar(const TQString&)),
this, TQT_SLOT(changeStatusbar(const TQString&)));
connect(m_view, TQT_SIGNAL(signalChangeCaption(const TQString&)),
this, TQT_SLOT(changeCaption(const TQString&)));
}
${APP_NAME}::~${APP_NAME}()
{
delete m_printer;
}
void ${APP_NAME}::load(const KURL& url)
{
TQString target;
// the below code is what you should normally do. in this
// example case, we want the url to our own. you probably
// want to use this code instead for your app
#if 0
// download the contents
if (KIO::NetAccess::download(url, target))
{
// set our caption
setCaption(url.prettyURL());
// load in the file (target is always local)
loadFile(target);
// and remove the temp file
KIO::NetAccess::removeTempFile(target);
}
#endif
setCaption(url.prettyURL());
m_view->openURL(url);
}
void ${APP_NAME}::setupActions()
{
KStdAction::openNew(this, TQT_SLOT(fileNew()), actionCollection());
KStdAction::open(this, TQT_SLOT(fileOpen()), actionCollection());
KStdAction::save(this, TQT_SLOT(fileSave()), actionCollection());
KStdAction::saveAs(this, TQT_SLOT(fileSaveAs()), actionCollection());
KStdAction::print(this, TQT_SLOT(filePrint()), actionCollection());
KStdAction::quit(kapp, TQT_SLOT(quit()), actionCollection());
KStdAction::preferences(this, TQT_SLOT(optionsPreferences()), actionCollection());
// this doesn't do anything useful. it's just here to illustrate
// how to insert a custom menu and menu item
KAction *custom = new KAction(i18n("Cus&tom Menuitem"), 0,
this, TQT_SLOT(optionsPreferences()),
actionCollection(), "custom_action");
}
void ${APP_NAME}::saveProperties(KConfig *config)
{
// the 'config' object points to the session managed
// config file. anything you write here will be available
// later when this app is restored
if (!m_view->currentURL().isNull()) {
#if KDE_IS_VERSION(3,1,3)
config->writePathEntry("lastURL", m_view->currentURL());
#else
config->writeEntry("lastURL", m_view->currentURL());
#endif
}
}
void ${APP_NAME}::readProperties(KConfig *config)
{
// the 'config' object points to the session managed
// config file. this function is automatically called whenever
// the app is being restored. read in here whatever you wrote
// in 'saveProperties'
TQString url = config->readPathEntry("lastURL");
if (!url.isEmpty())
m_view->openURL(KURL::fromPathOrURL(url));
}
void ${APP_NAME}::dragEnterEvent(TQDragEnterEvent *event)
{
// accept uri drops only
event->accept(KURLDrag::canDecode(event));
}
void ${APP_NAME}::dropEvent(TQDropEvent *event)
{
// this is a very simplistic implementation of a drop event. we
// will only accept a dropped URL. the TQt dnd code can do *much*
// much more, so please read the docs there
KURL::List urls;
// see if we can decode a URI.. if not, just ignore it
if (KURLDrag::decode(event, urls) && !urls.isEmpty())
{
// okay, we have a URI.. process it
const KURL &url = urls.first();
// load in the file
load(url);
}
}
void ${APP_NAME}::fileNew()
{
// this slot is called whenever the File->New menu is selected,
// the New shortcut is pressed (usually CTRL+N) or the New toolbar
// button is clicked
// create a new window
(new ${APP_NAME})->show();
}
void ${APP_NAME}::fileOpen()
{
// this slot is called whenever the File->Open menu is selected,
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
// button is clicked
KURL url = KURLRequesterDlg::getURL(TQString(), this, i18n("Open Location") );
if (!url.isEmpty())
m_view->openURL(url);
}
void ${APP_NAME}::fileSave()
{
// this slot is called whenever the File->Save menu is selected,
// the Save shortcut is pressed (usually CTRL+S) or the Save toolbar
// button is clicked
// save the current file
}
void ${APP_NAME}::fileSaveAs()
{
// this slot is called whenever the File->Save As menu is selected,
KURL file_url = KFileDialog::getSaveURL();
if (!file_url.isEmpty() && file_url.isValid())
{
// save your info, here
}
}
void ${APP_NAME}::filePrint()
{
// this slot is called whenever the File->Print menu is selected,
// the Print shortcut is pressed (usually CTRL+P) or the Print toolbar
// button is clicked
if (!m_printer) m_printer = new KPrinter;
if (m_printer->setup(this))
{
// setup the printer. with TQt, you always "print" to a
// TQPainter.. whether the output medium is a pixmap, a screen,
// or paper
TQPainter p;
p.begin(m_printer);
// we let our view do the actual printing
TQPaintDeviceMetrics metrics(m_printer);
m_view->print(&p, metrics.height(), metrics.width());
// and send the result to the printer
p.end();
}
}
void ${APP_NAME}::optionsConfigureToolbars()
{
// use the standard toolbar editor
saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
KEditToolbar dlg(actionCollection());
connect(&dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(newToolbarConfig()));
dlg.exec();
}
void ${APP_NAME}::newToolbarConfig()
{
// this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
// recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
createGUI();
applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
}
void ${APP_NAME}::optionsPreferences()
{
// popup some sort of preference dialog, here
${APP_NAME}Preferences dlg;
if (dlg.exec())
{
// redo your settings
}
}
void ${APP_NAME}::changeStatusbar(const TQString& text)
{
// display the text on the statusbar
statusBar()->message(text);
}
void ${APP_NAME}::changeCaption(const TQString& text)
{
// display the text on the caption
setCaption(text);
}
#include "${APP_NAME_LC}.moc"
|