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 --- .../qt-examples/fonts/simple-qfont-demo/main.rb | 14 +++ .../qt-examples/fonts/simple-qfont-demo/viewer.rb | 140 +++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100755 qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/main.rb create mode 100644 qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/viewer.rb (limited to 'qtruby/rubylib/examples/qt-examples/fonts') diff --git a/qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/main.rb b/qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/main.rb new file mode 100755 index 00000000..9559a921 --- /dev/null +++ b/qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/main.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require 'Qt' +require 'viewer' +$KCODE='u' + + +a = Qt::Application.new(ARGV) + +textViewer = Viewer.new +textViewer.setCaption('QtRuby Example - Simple QFont Demo') +a.setMainWidget(textViewer) +textViewer.show +a.exec() diff --git a/qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/viewer.rb b/qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/viewer.rb new file mode 100644 index 00000000..d9c16a62 --- /dev/null +++ b/qtruby/rubylib/examples/qt-examples/fonts/simple-qfont-demo/viewer.rb @@ -0,0 +1,140 @@ +class Viewer < Qt::Widget + slots 'setDefault()', 'setSansSerif()', 'setItalics()' + + def initialize + super + + setFontSubstitutions + + codec = Qt::TextCodec::codecForName("utf8") + + # Shouldn't 'pack("U*")' for UTF-8 work here? - Richard + # The 'U' option packs each element into two bytes and doesn't work + # The 'c' option packs them into a single byte and does work + greeting_heb = codec.toUnicode([0327, 0251, 0327, 0234, 0327, 0225, 0327, 0235].pack("C*")) + greeting_ru = codec.toUnicode([0320, 0227, 0320, 0264, 0321, 0200, 0320, 0260, 0320, 0262, 0321, 0201, 0321, 0202, 0320, 0262, 0321, 0203, 0320, 0271, 0321, 0202, 0320, 0265].pack("C*")) + greeting_en = 'Hello' + + @greetings = Qt::TextView.new(self, 'textview') + @greetings.setText( + greeting_en + "\n" + + greeting_ru + "\n" + + greeting_heb) + + @fontInfo = Qt::TextView.new(self, 'fontinfo') + + setDefault + + @defaultButton = Qt::PushButton.new('Default', self, 'pushbutton1') + @defaultButton.setFont(Qt::Font.new('times')) + connect(@defaultButton, SIGNAL('clicked()'), self, SLOT('setDefault()')) + + + @sansSerifButton = Qt::PushButton.new('Sans Serif', self, 'pushbutton2') + @sansSerifButton.setFont(Qt::Font.new('Helvetica', 12)) + connect(@sansSerifButton, SIGNAL('clicked()'), self, SLOT('setSansSerif()')) + + @italicsButton = Qt::PushButton.new('Italics', self, 'pushbutton1') + @italicsButton.setFont(Qt::Font.new('lucida', 12, Qt::Font.Bold, true)) + connect(@italicsButton, SIGNAL('clicked()'), self, SLOT('setItalics()')) + + layout + end + + def setDefault + font = Qt::Font.new('Bavaria') + font.setPointSize(24) + font.setWeight(Qt::Font.Bold) + font.setUnderline(true) + + @greetings.setFont(font) + showFontInfo(font) + end + + def setSansSerif + font = Qt::Font.new('Newyork', 18) + font.setStyleHint(Qt::Font.SansSerif) + + @greetings.setFont(font) + showFontInfo(font) + end + + def setItalics + font = Qt::Font.new('Tokyo') + font.setPointSize(32) + font.setWeight(Qt::Font.Bold) + font.setItalic(true) + + @greetings.setFont(font) + showFontInfo(font) + end + + def setFontSubstitutions + substitutes = Array.new + + substitutes.push('Times') + substitutes.push('Mincho') + substitutes.push('Arabic Newspaper') + substitutes.push('crox') + + Qt::Font.insertSubstitutions('Bavaria', substitutes) + Qt::Font.insertSubstitution('Tokyo', 'Lucida') + end + + def layout + textViewContainer = Qt::HBoxLayout.new + textViewContainer.addWidget(@greetings) + textViewContainer.addWidget(@fontInfo) + + buttonContainer = Qt::HBoxLayout.new + buttonContainer.addWidget(@defaultButton) + buttonContainer.addWidget(@sansSerifButton) + buttonContainer.addWidget(@italicsButton) + + maxButtonHeight = @defaultButton.height + + if (@sansSerifButton.height > maxButtonHeight) + maxButtonHeight = @sansSerifButton.height + end + + if (@italicsButton.height > maxButtonHeight) + maxButtonHeight = @italicsButton.height + end + + @defaultButton.setFixedHeight(maxButtonHeight) + @sansSerifButton.setFixedHeight(maxButtonHeight) + @italicsButton.setFixedHeight(maxButtonHeight) + + container = Qt::VBoxLayout.new(self) + container.addLayout(textViewContainer) + container.addLayout(buttonContainer) + + resize(700, 250) + end + + def showFontInfo (font) + info = Qt::FontInfo.new(font) + messageText = + 'Font requested: "' + + font.family + '" ' + + font.pointSize.to_s + 'pt
' + + 'Font used: "' + + info.family.to_s + '" ' + + info.pointSize.to_s + 'pt

' + + substitutions = Qt::Font.substitutes(font.family) + + unless substitutions.size == 0 + messageText = messageText + 'The following substitutions exist for ' + + font.family + ':

' + else + messageText = messageText + 'No substitutions exist for ' + font.family + '.' + end + + @fontInfo.setText(messageText) + end +end -- cgit v1.2.1