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
|
=begin
This class serves as the main window for %{APPNAME}. It handles the
menus, toolbars, and status bars.
@short Main window class
@author %{AUTHOR} <%{EMAIL}>
@version %{VERSION}
=end
class %{APPNAMESC} < KDE::MainWindow
slots 'fileNew()',
'optionsPreferences()',
'newToolbarConfig()',
'changeStatusbar(const TQString&)',
'changeCaption(const TQString&)'
def initialize()
super( nil, "%{APPNAMESC}" )
Settings.instance.readConfig
@view = %{APPNAMESC}View.new(self)
@printer = nil
# accept dnd
setAcceptDrops(true)
# tell the KDE::MainWindow that this is indeed the main widget
setCentralWidget(@view)
# then, setup our actions
setupActions()
# and a status bar
statusBar().show()
# Apply the create the main window and ask the mainwindow to
# automatically save settings if changed: window size, toolbar
# position, icon size, etc. Also to add actions for the statusbar
# toolbar, and keybindings if necessary.
setupGUI();
# allow the view to change the statusbar and caption
connect(@view, TQ_SIGNAL('signalChangeStatusbar(const TQString&)'),
self, TQ_SLOT('changeStatusbar(const TQString&)'))
connect(@view, TQ_SIGNAL('signalChangeCaption(const TQString&)'),
self, TQ_SLOT('changeCaption(const TQString&)'))
end
def setupActions()
KDE::StdAction.openNew(self, TQ_SLOT('fileNew()'), actionCollection())
KDE::StdAction.quit($kapp, TQ_SLOT('quit()'), actionCollection())
KDE::StdAction.preferences(self, TQ_SLOT('optionsPreferences()'), actionCollection())
# this doesn't do anything useful. it's just here to illustrate
# how to insert a custom menu and menu item
custom = KDE::Action.new(i18n("Swi&tch Colors"), KDE::Shortcut.new(),
@view, TQ_SLOT('switchColors()'),
actionCollection(), "switch_action")
end
def 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
%{APPNAMESC}.new.show()
end
def optionsPreferences()
# The preference dialog is derived from prefs-base.ui which is subclassed into Prefs
#
# compare the names of the widgets in the .ui file
# to the names of the variables in the .kcfg file
dialog = KDE::ConfigDialog.new(self, "settings", Settings.instance, KDE::DialogBase::Swallow)
dialog.addPage(Prefs.new(), i18n("General"), "package_settings")
connect(dialog, TQ_SIGNAL('settingsChanged()'), @view, TQ_SLOT('settingsChanged()'))
dialog.show()
end
def changeStatusbar(text)
# display the text on the statusbar
statusBar().message(text)
end
def changeCaption(text)
# display the text on the caption
setCaption(text)
end
end
|