2
This class serves as the main window for %{APPNAME}. It handles the
3
menus, toolbars, and status bars.
5
@short Main window class
6
@author %{AUTHOR} <%{EMAIL}>
10
class %{APPNAMESC} < KDE::MainWindow
17
'optionsPreferences()',
18
'changeStatusbar(const QString&)',
19
'changeCaption(const QString&)'
22
super( nil, "%{APPNAMESC}" )
23
@view = %{APPNAMESC}View.new(self)
28
# tell the KDE::MainWindow that this is indeed the main widget
29
setCentralWidget(@view)
31
# then, setup our actions
37
# Apply the create the main window and ask the mainwindow to
38
# automatically save settings if changed: window size, toolbar
39
# position, icon size, etc. Also to add actions for the statusbar
40
# toolbar, and keybindings if necessary.
43
# allow the view to change the statusbar and caption
44
connect(@view, SIGNAL('signalChangeStatusbar(const QString&)'),
45
self, SLOT('changeStatusbar(const QString&)'))
46
connect(@view, SIGNAL('signalChangeCaption(const QString&)'),
47
self, SLOT('changeCaption(const QString&)'))
54
# the below code is what you should normally do. in this
55
# example when, we want the url to our own. you probably
56
# want to use this code instead for your app
59
# download the contents
60
if KIO::NetAccess.download(url, target, self)
64
# load in the file (target is always local)
65
@view.openURL(KDE::URL.new(target))
67
# and remove the temp file
68
KIO::NetAccess.removeTempFile(target)
72
setCaption(url.prettyURL())
77
KDE::StdAction.openNew(self, SLOT('fileNew()'), actionCollection())
78
KDE::StdAction.open(self, SLOT('fileOpen()'), actionCollection())
79
KDE::StdAction.save(self, SLOT('fileSave()'), actionCollection())
80
KDE::StdAction.saveAs(self, SLOT('fileSaveAs()'), actionCollection())
81
KDE::StdAction.print(self, SLOT('filePrint()'), actionCollection())
82
KDE::StdAction.quit($kapp, SLOT('quit()'), actionCollection())
84
KDE::StdAction.preferences(self, SLOT('optionsPreferences()'), actionCollection())
86
# this doesn't do anything useful. it's just here to illustrate
87
# how to insert a custom menu and menu item
88
custom = KDE::Action.new(i18n("Cus&tom Menuitem"), KDE::Shortcut.new(),
89
self, SLOT('optionsPreferences()'),
90
actionCollection(), "custom_action")
93
def saveProperties(config)
94
# the 'config' object points to the session managed
95
# config file. anything you write here will be available
96
# later when this app is restored
98
if !@view.currentURL().empty?
99
config.writeEntry("lastURL", @view.currentURL())
103
def readProperties(config)
104
# the 'config' object points to the session managed
105
# config file. This function is automatically called whenever
106
# the app is being restored. read in here whatever you wrote
107
# in 'saveProperties'
109
url = config.readPathEntry("lastURL")
112
@view.openURL(KDE::URL.new(url))
116
def dragEnterEvent(event)
117
# accept uri drops only
118
event.accept(KDE::URLDrag.canDecode(event))
122
# This is a very simplistic implementation of a drop event. we
123
# will only accept a dropped URL. the Qt dnd code can do *much*
124
# much more, so please read the docs there
127
# see if we can decode a URI.. if not, just ignore it
128
if KDE::URLDrag.decode(event, urls) && !urls.empty?
129
# okay, we have a URI.. process it
138
# This slot is called whenever the File.New menu is selected,
139
# the New shortcut is pressed (usually CTRL+N) or the New toolbar
142
# create a new window
143
%{APPNAMESC}.new.show()
147
# This slot is called whenever the File.Open menu is selected,
148
# the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
151
# This brings up the generic open dialog
152
url = KDE::URLRequesterDlg.getURL(nil, self, i18n("Open Location") )
154
# standard filedialog
155
url = KDE::FileDialog.getOpenURL(nil, nil, self, i18n("Open Location"))
162
# This slot is called whenever the File.Save menu is selected,
163
# the Save shortcut is pressed (usually CTRL+S) or the Save toolbar
166
# save the current file
170
# This slot is called whenever the File.Save As menu is selected,
171
file_url = KDE::FileDialog.getSaveURL()
172
if !file_url.empty? && file_url.valid?
173
# save your info, here
178
# This slot is called whenever the File.Print menu is selected,
179
# the Print shortcut is pressed (usually CTRL+P) or the Print toolbar
181
if @printer.nil? then @printer = KDE::Printer.new end
182
if @printer.setup(self)
183
# setup the printer. with Qt, you always "print" to a
184
# Qt::Painter.. whether the output medium is a pixmap, a screen,
189
# we let our view do the actual printing
190
metrics = Qt::PaintDeviceMetrics.new(@printer)
191
@view.print(p, metrics.height(), metrics.width())
193
# and send the result to the printer
198
def optionsPreferences()
199
# popup some sort of preference dialog, here
200
dlg = %{APPNAMESC}Preferences.new
206
def changeStatusbar(text)
207
# display the text on the statusbar
208
statusBar().message(text)
211
def changeCaption(text)
212
# display the text on the caption