3
#include "%{APPNAMELC}.h"
6
#include <qdragobject.h>
9
#include <qpaintdevicemetrics.h>
13
#include <kiconloader.h>
14
#include <kdeversion.h>
15
#include <kstatusbar.h>
17
#include <kio/netaccess.h>
18
#include <kfiledialog.h>
22
#include <kurlrequesterdlg.h>
24
#include <kstdaccel.h>
26
#include <kstdaction.h>
28
%{APPNAME}::%{APPNAME}()
29
: KMainWindow( 0, "%{APPNAME}" ),
30
m_view(new %{APPNAME}View(this)),
36
// tell the KMainWindow that this is indeed the main widget
37
setCentralWidget(m_view);
39
// then, setup our actions
45
// Apply the create the main window and ask the mainwindow to
46
// automatically save settings if changed: window size, toolbar
47
// position, icon size, etc. Also to add actions for the statusbar
48
// toolbar, and keybindings if necessary.
51
// allow the view to change the statusbar and caption
52
connect(m_view, SIGNAL(signalChangeStatusbar(const QString&)),
53
this, SLOT(changeStatusbar(const QString&)));
54
connect(m_view, SIGNAL(signalChangeCaption(const QString&)),
55
this, SLOT(changeCaption(const QString&)));
59
%{APPNAME}::~%{APPNAME}()
63
void %{APPNAME}::load(const KURL& url)
66
// the below code is what you should normally do. in this
67
// example case, we want the url to our own. you probably
68
// want to use this code instead for your app
71
// download the contents
72
if (KIO::NetAccess::download(url, target))
77
// load in the file (target is always local)
80
// and remove the temp file
81
KIO::NetAccess::removeTempFile(target);
85
setCaption(url.prettyURL());
89
void %{APPNAME}::setupActions()
91
KStdAction::openNew(this, SLOT(fileNew()), actionCollection());
92
KStdAction::open(this, SLOT(fileOpen()), actionCollection());
93
KStdAction::save(this, SLOT(fileSave()), actionCollection());
94
KStdAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
95
KStdAction::print(this, SLOT(filePrint()), actionCollection());
96
KStdAction::quit(kapp, SLOT(quit()), actionCollection());
98
KStdAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
100
// this doesn't do anything useful. it's just here to illustrate
101
// how to insert a custom menu and menu item
102
KAction *custom = new KAction(i18n("Cus&tom Menuitem"), 0,
103
this, SLOT(optionsPreferences()),
104
actionCollection(), "custom_action");
107
void %{APPNAME}::saveProperties(KConfig *config)
109
// the 'config' object points to the session managed
110
// config file. anything you write here will be available
111
// later when this app is restored
113
if (!m_view->currentURL().isEmpty()) {
114
#if KDE_IS_VERSION(3,1,3)
115
config->writePathEntry("lastURL", m_view->currentURL());
117
config->writeEntry("lastURL", m_view->currentURL());
122
void %{APPNAME}::readProperties(KConfig *config)
124
// the 'config' object points to the session managed
125
// config file. this function is automatically called whenever
126
// the app is being restored. read in here whatever you wrote
127
// in 'saveProperties'
129
QString url = config->readPathEntry("lastURL");
132
m_view->openURL(KURL(url));
135
void %{APPNAME}::dragEnterEvent(QDragEnterEvent *event)
137
// accept uri drops only
138
event->accept(KURLDrag::canDecode(event));
141
void %{APPNAME}::dropEvent(QDropEvent *event)
143
// this is a very simplistic implementation of a drop event. we
144
// will only accept a dropped URL. the Qt dnd code can do *much*
145
// much more, so please read the docs there
148
// see if we can decode a URI.. if not, just ignore it
149
if (KURLDrag::decode(event, urls) && !urls.isEmpty())
151
// okay, we have a URI.. process it
152
const KURL &url = urls.first();
159
void %{APPNAME}::fileNew()
161
// this slot is called whenever the File->New menu is selected,
162
// the New shortcut is pressed (usually CTRL+N) or the New toolbar
165
// create a new window
166
(new %{APPNAME})->show();
169
void %{APPNAME}::fileOpen()
171
// this slot is called whenever the File->Open menu is selected,
172
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
175
// this brings up the generic open dialog
176
KURL url = KURLRequesterDlg::getURL(QString::null, this, i18n("Open Location") );
178
// standard filedialog
179
KURL url = KFileDialog::getOpenURL(QString::null, QString::null, this, i18n("Open Location"));
181
m_view->openURL(url);
184
void %{APPNAME}::fileSave()
186
// this slot is called whenever the File->Save menu is selected,
187
// the Save shortcut is pressed (usually CTRL+S) or the Save toolbar
190
// save the current file
193
void %{APPNAME}::fileSaveAs()
195
// this slot is called whenever the File->Save As menu is selected,
196
KURL file_url = KFileDialog::getSaveURL();
197
if (!file_url.isEmpty() && file_url.isValid())
199
// save your info, here
203
void %{APPNAME}::filePrint()
205
// this slot is called whenever the File->Print menu is selected,
206
// the Print shortcut is pressed (usually CTRL+P) or the Print toolbar
208
if (!m_printer) m_printer = new KPrinter;
209
if (m_printer->setup(this))
211
// setup the printer. with Qt, you always "print" to a
212
// QPainter.. whether the output medium is a pixmap, a screen,
217
// we let our view do the actual printing
218
QPaintDeviceMetrics metrics(m_printer);
219
m_view->print(&p, metrics.height(), metrics.width());
221
// and send the result to the printer
226
void %{APPNAME}::optionsPreferences()
228
// popup some sort of preference dialog, here
229
%{APPNAME}Preferences dlg;
232
// redo your settings
236
void %{APPNAME}::changeStatusbar(const QString& text)
238
// display the text on the statusbar
239
statusBar()->message(text);
242
void %{APPNAME}::changeCaption(const QString& text)
244
// display the text on the caption
247
#include "%{APPNAMELC}.moc"