From 90825e2392b2d70e43c7a25b8a3752299a933894 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- qtruby/rubylib/examples/base/kicons.rb | 54 ++++++++++++++++++++++++++++++++++ qtruby/rubylib/examples/base/rui.rb | 21 +++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 qtruby/rubylib/examples/base/kicons.rb create mode 100644 qtruby/rubylib/examples/base/rui.rb (limited to 'qtruby/rubylib/examples/base') diff --git a/qtruby/rubylib/examples/base/kicons.rb b/qtruby/rubylib/examples/base/kicons.rb new file mode 100644 index 00000000..0d0a2c01 --- /dev/null +++ b/qtruby/rubylib/examples/base/kicons.rb @@ -0,0 +1,54 @@ +class KIconCollection + IconInfo = Struct.new(:collection, :id, :filetype) + def initialize(icon_collections) + @icon_info = {} + icon_collections.each_pair { + |collection_name, collection| + collection.each_pair { + |key, value| + info = IconInfo.new(collection_name, value, "png") + @icon_info[key] = info + } + } + end + def dims + "32x32" + end + def kdedir + ENV["KDEDIR"] + end + def get_icon_path(icon_type) + info = @icon_info[icon_type] + "#{kdedir}/share/icons/default.kde/#{dims}/#{info.collection}/#{info.id}.#{info.filetype}" + end + def get_icon_set(icon_type) + path = get_icon_path(icon_type) + pixmap = Qt::Pixmap.new(path) + icon_set = Qt::IconSet.new + icon_set.setPixmap(pixmap, Qt::IconSet.Small) + icon_set + end + def make_qt_action(parent, text_with_accel, icon_type) + act = Qt::Action.new(parent) + act.setIconSet(get_icon_set(icon_type)) + act.setMenuText(text_with_accel) + act + end +end + +module Icons + FILE_NEW, FILE_OPEN, FILE_CLOSE, FILE_SAVE, FILE_SAVE_AS, EXIT = 1,2,3,4,5,6 +end + +icon_collections = { + "actions" => { + Icons::FILE_NEW => "filenew", + Icons::FILE_OPEN => "fileopen", + Icons::FILE_CLOSE => "fileclose", + Icons::FILE_SAVE => "filesave", + Icons::FILE_SAVE_AS => "filesaveas", + Icons::EXIT => "exit" + } +} +$kIcons = KIconCollection.new(icon_collections) +print "Using KDEDIR == ", $kIcons.kdedir, "\n" diff --git a/qtruby/rubylib/examples/base/rui.rb b/qtruby/rubylib/examples/base/rui.rb new file mode 100644 index 00000000..ad14bc11 --- /dev/null +++ b/qtruby/rubylib/examples/base/rui.rb @@ -0,0 +1,21 @@ +require '../base/kicons.rb' + +RAction = Struct.new(:text_with_accel, :icon_type, :rec, :slot, :included_in, :action) +RSeperator = Struct.new(:included_in, :id) + +def build_actions(actions) + actions.each { |a| + if a.is_a? RSeperator + a.included_in.each { + |to| a.id = to.insertSeparator() + } + else + qt_action = $kIcons.make_qt_action(self, a.text_with_accel, a.icon_type) + connect(qt_action, SIGNAL('activated()'), a.rec, a.slot) + a.included_in.each { + |to| qt_action.addTo(to) + } + a.action = qt_action + end + } +end -- cgit v1.2.3