You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdevelop/languages/ruby/app_templates/kapp/appview.rb

104 lines
3.4 KiB

=begin
This is the main view class for %{APPNAME}. Most of the non-menu,
non-toolbar, and non-statusbar (e.g., non frame) GUI code should go
here.
This %{APPNAMELC} uses an HTML component as an example.
@short Main view
@author %{AUTHOR} <%{EMAIL}>
@version %{VERSION}
=end
class %{APPNAMESC}View < TQt::Widget
#
# Use this signal to change the content of the statusbar
#
signals 'signalChangeStatusbar(const TQString&)'
#
# Use this signal to change the content of the caption
#
signals 'signalChangeCaption(const TQString&)'
slots 'slotOnURL(const TQString&)',
'slotSetTitle(const TQString&)'
def initialize(parent)
super(parent)
# keep a reference to the DCOP Interface so it doesn't get gc'd
@dcop = %{APPNAMESC}Iface.new(self)
# setup our layout manager to automatically add our widgets
top_layout = TQt::HBoxLayout.new(self)
top_layout.setAutoAdd(true)
# we want to look for all components that satisfy our needs. the
# trader will actually search through *all* registered KDE
# applications and components -- not just KParts. So we have to
# specify two things: a service type and a constraint
#
# the service type is like a mime type. we say that we want all
# applications and components that can handle HTML -- 'text/html'
#
# however, by itself, this will return such things as Netscape..
# not what we wanted. so we constrain it by saying that the
# string 'KParts/ReadOnlyPart' must be found in the ServiceTypes
# field. with this, only components of the type we want will be
# returned.
offers = KDE::Trader.self().query("text/html", "'KParts/ReadOnlyPart' in ServiceTypes")
factory = nil
# in theory, we only care about the first one.. but let's try all
# offers just in when the first can't be loaded for some reason
offers.each do |ptr|
# we now know that our offer can handle HTML and is a part.
# since it is a part, it must also have a library... let's try to
# load that now
factory = KDE::LibLoader.self().factory( ptr.library() )
if ! factory.nil?
@html = factory.create(self, ptr.name(), "KParts::ReadOnlyPart")
break
end
end
# if our factory is invalid, then we never found our component
# and we might as well just exit now
if factory.nil?
KDE::MessageBox.error(self, i18n("Could not find a suitable HTML component"))
return
end
connect(@html, TQ_SIGNAL('setWindowCaption(const TQString&)'),
self, TQ_SLOT('slotSetTitle(const TQString&)'))
connect(@html, TQ_SIGNAL('setStatusBarText(const TQString&)'),
self, TQ_SLOT('slotOnURL(const TQString&)'))
end
def print(p, height, width)
# do the actual printing, here
# p.drawText(etc..)
end
def currentURL()
return @html.url().url()
end
def openURL(url)
@html.openURL(KDE::URL.new(url))
end
def slotOnURL(url)
emit signalChangeStatusbar(url)
end
def slotSetTitle(title)
emit signalChangeCaption(title)
end
end