Friday, July 31, 2009

Qt::Enum

Most of QtRuby classes have basic classes of Qt. But Qt::Enum is QtRuby original class. Its behavior is almost same with Qt::Integer. And we can use it like as C++ enum.
require 'Qt4'

class Suits < Qt::Object
Heart = Qt::Enum.new(0, self)
Clover = Qt::Enum.new(1, self)
Diamond = Qt::Enum.new(2, self)
Spade = Qt::Enum.new(3, self)
end

Tuesday, July 28, 2009

What does "compatible for Ruby 1.9.1" mean ?

In phosphorescence: The 2nd day of RubyKaigi 2009 (Morning), I mentioned about "Ruby 1.9.x is compatible for Ruby 1.9.1" and announced to describe it after. So I describe about it.

It's simple, but outlandish rule. For example in 1.8.x(1.8.7),
> ruby -e 'puts RUBY_VERSION, $:'
1.8.7
/usr/lib64/ruby/site_ruby/1.8
/usr/lib64/ruby/site_ruby/1.8/x86_64-linux
/usr/lib64/ruby/site_ruby
/usr/lib64/ruby/vendor_ruby/1.8
/usr/lib64/ruby/vendor_ruby/1.8/x86_64-linux
/usr/lib64/ruby/vendor_ruby
/usr/lib64/ruby/1.8
/usr/lib64/ruby/1.8/x86_64-linux
.

But for example in 1.9.x(1.9.2),
> /opt/ruby-1.9.1/bin/ruby -e 'puts RUBY_VERSION, $:'
1.9.2
/opt/ruby-1.9.1/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin
/opt/ruby-1.9.1/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib
/opt/ruby-1.9.1/lib/ruby/gems/1.9.1/gems/rdoc-2.4.3/bin
/opt/ruby-1.9.1/lib/ruby/gems/1.9.1/gems/rdoc-2.4.3/lib
/opt/ruby-1.9.1/lib/ruby/gems/1.9.1/gems/rubygems-update-1.3.5/bin
/opt/ruby-1.9.1/lib/ruby/gems/1.9.1/gems/rubygems-update-1.3.5/lib
/opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1
/opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/x86_64-linux
/opt/ruby-1.9.1/lib/ruby/site_ruby
/opt/ruby-1.9.1/lib/ruby/vendor_ruby/1.9.1
/opt/ruby-1.9.1/lib/ruby/vendor_ruby/1.9.1/x86_64-linux
/opt/ruby-1.9.1/lib/ruby/vendor_ruby
/opt/ruby-1.9.1/lib/ruby/1.9.1
/opt/ruby-1.9.1/lib/ruby/1.9.1/x86_64-linux

We need imprinting "such a thing" to ourselves. But more confusion from late majorities will occur perhaps when first stable 1.9.2 will be released.

Saturday, July 25, 2009

Ruby 1.9.2 preview 1 was released

During RubyKaigi 2009, ruby 1.9.2 preview 1 was also released. So I download and install its package like this entry. Let's check.
>/opt/ruby-1.9.1/bin/ruby --version
ruby 1.9.2dev (2009-07-18 trunk 24186) [x86_64-linux]

Then I re-build Qtruby, but make fails with below messages:
Scanning dependencies of target qtruby4shared
[ 56%] Building CXX object ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/Qt.o
[ 57%] Building CXX object ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/handlers.o
[ 59%] Building CXX object ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/marshall_types.o
/home/youhei/downloads/qt4-qtruby-2.0.3/ruby/qtruby/src/marshall_types.cpp: In function ‘void show_exception_message()’:
/home/youhei/downloads/qt4-qtruby-2.0.3/ruby/qtruby/src/marshall_types.cpp:77: error: ‘STR2CSTR’ was not declared in this scope
make[2]: *** [ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/marshall_types.o] エラー 1
make[1]: *** [ruby/qtruby/src/CMakeFiles/qtruby4shared.dir/all] エラー 2
make: *** [all] エラー 2

Well, it's often matter of preview release. See the ChangeLog of ruby trunk...
Sat Jan 31 22:29:05 2009 Tanaka Akira <akr ! fsij ! org>

* include/ruby/ruby.h (STR2CSTR): removed.
(rb_str2cstr): removed.

* object.c (rb_str2cstr): removed.

So I fix to use new ruby.h API(refer also some commit comments of the ChangeLog of ruby trunk), send a patch. Currently, it's committed into QtRuby's trunk.

After the revision number 1001987, Building QtRuby with Ruby 1.9.2 succeeds.

update summaries of RubyKaigi

I update summaries that I attend of RubyKaigi.

phosphorescence: The 1st day of RubyKaigi 2009
phosphorescence: The 2nd day of RubyKaigi 2009 (Morning)
phosphorescence: The 2nd day of RubyKaigi 2009 (Afternoon)
phosphorescence: The 3rd day of RubyKaigi 2009 (Morning)
phosphorescence: The 3rd day of RubyKaigi 2009 (Afternoon)

And I say again thanks to all staffs, speakers and attendees.

Wednesday, July 22, 2009

Ruby 1.9.1 p243 was released

During RubyKaigi 2009, ruby 1.9.1 p243 was released. So I download and re-install its package like this entry. Let's check.
>/opt/ruby-1.9.1/bin/ruby --version
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]

Then I re-build Qtruby like this entry.

Sunday, July 19, 2009

The 3rd day of RubyKaigi 2009 (Afternoon)


All sessions of RubyKaigi 2009 is over.
Above photo is a novelty souvenir at this conference. This is a hand-held fan (in Japanese : 扇子).

In this afternoon, I attended these sessions:

The 3rd day of RubyKaigi 2009 (Morning)


Today is the 3rd day (a.k.a. last day) of RubyKaigi 2009. Order of today's session has been changed because of speaker's machine trouble. "Ruby - The Script Language" has become after "socket library improvement".

So I attended these sessions:

Saturday, July 18, 2009

The 2nd day of RubyKaigi 2009 (Afternoon)

In this afternoon, I attended these sessions:

The 2nd day of RubyKaigi 2009 (Morning)


Today is the 2nd day of RubyKaigi 2009.

I attended these sessions:

Friday, July 17, 2009

The 1st day of RubyKaigi 2009

Today is the 1st day of RubyKaigi 2009(only afternoon).
It held at here.



I attended these sessions:

Thursday, July 9, 2009

Summer vacation

I take a summer vacation, so I suspend posts and comments to this blog for a moment. Resume will be July 17, 2009: The 1st day of RubyKaigi 2009.

Tuesday, July 7, 2009

Transparent QtWebView #2

(continued from phosphorescence: Transparent QtWebView #1)
This entry had rewritten in 2009/08/03

The biggest reason of this failure is the impedance between Qt that allows overload to Ruby that doesn't allow overload. But in this case, it's 2nd biggest reason: type of Qt class mismatches. A type of Qt::transparent is Qt::GlobalColor, but 2nd argument type of Qt::Palette#setBrush is Qt::Brush. So Qt::GlobalColor object have to be wrapped with Qt::Brush class.

In addition, Qt::Painter#setBrush method is also too. To see the document of QBrush, constructor can take QGradient(superclass of Qt::LinearGradient corrsponding class) and Qt::GlobalColor.

Then I rewrite the previous code like below:
require 'Qt4'
require 'qtwebkit'

class Container < Qt::Widget
  def initialize parent = nil
    super

    @view = Qt::WebView.new self
    pal = @view.palette
    pal.set_brush(Qt::Palette::Base, Qt::Brush.new(Qt::transparent))
    @view.page.palette = pal
    @view.set_attribute(Qt::WA_OpaquePaintEvent, false)
    @view.load Qt::Url.new('http://en.mobile.wikipedia.org/')
    @view.zoom_factor = 0.8

    Qt::Object.connect(@view, SIGNAL( 'titleChanged(const QString&)' ),
      self, SLOT( 'setWindowTitle(const QString&)' ))

    @layout = Qt::VBoxLayout.new self
    @layout.add_widget @view

    linear_gradient = Qt::LinearGradient.new
    linear_gradient.set_color_at(0.0, Qt::Color.new(249, 247, 96))
    linear_gradient.set_color_at(1.0, Qt::Color.new(235, 203, 32))
    linear_gradient.coordinate_mode = Qt::Gradient::ObjectBoundingMode
    @gradient = Qt::Brush.new(linear_gradient)

    self.resize 320, 480
  end

  protected
  def paint_event event
    @painter = Qt::Painter.new self
    @painter.fill_rect(event.rect, Qt::transparent)
    @painter.pen = Qt::NoPen
    @painter.brush = @gradient
    @painter.opacity = 0.6
    @painter.draw_rounded_rect(self.rect, 10, 10)
    @painter.end
  end

  alias :paintEvent :paint_event
end

Qt::Application.new(ARGV) do
  Container.new do
    self.set_attribute(Qt::WA_TranslucentBackground, true)
    self.window_flags = Qt::FramelessWindowHint
    show
  end
  exec
end


And run it.

Run successfully. I push this code to my gitorious clone repository, see here.

Saturday, July 4, 2009

Transparent QtWebView #1

When I read Qt Labs Blogs, I found interesting post titled Transparent QWebView (or QWebPage). As reading this, it's easy that adding a few lines makes background of Webkit transparent, and it can make also by Python (via PyQt).

Then I learn example source codes from Qt's gitorius repository and start to try it by QtRuby. I write sample codes in rubyish like below:

require 'Qt4'
require 'qtwebkit'

class Container < Qt::Widget

  def initialize parent = nil
    super

    @view = Qt::WebView.new self
    transparent_palette = palette
    transparent_palette.setBrush(Qt::Palette::Base, Qt::transparent)
    @view.page.palette = transparent_palette
    @view.set_attribute(Qt::WA_OpaquePaintEvent, false)
    @view.load Qt::Url.new('http://en.mobile.wikipedia.org/')
    @view.zoom_factor = 0.8

    Qt::Object.connect(@view, SIGNAL( 'titleChanged(const QString&)' ),
      self, SLOT( 'setWindowTitle(const QString&)' ))

    @layout = Qt::VBoxLayout.new self
    @layout.add_widget @view

    @gradient = Qt::LinearGradient.new
    @gradient.set_color_at(0.0, Qt::Color.new(249, 247, 96))
    @gradient.set_color_at(1.0, Qt::Color.new(235, 203, 32))
    @gradient.set_coordinate_mode(Qt::Gradient::ObjectBoundingMode)

    self.resize 320, 480
  end

  protected
  def paint_event event
    @painter = Qt::Painter.new self
    @painter.fill_rect(event.rect, Qt::transparent)
    @painter.pen = Qt::NoPen
    @painter.brush = @gradient
    @painter.opacity = 0.6
    @painter.draw_rounded_rect(self.rect, 10, 10)
    @painter.end
  end

  alias :paintEvent :paint_event
end

Qt::Application.new(ARGV) do
  Container.new do
    self.set_attribute(Qt::WA_TranslucentBackground, true)
    self.window_flags = Qt::FramelessWindowHint
    show
  end
  exec
end

Let's run it!
> /opt/ruby-1.9.1/bin/ruby transparentweb.rb
transparentweb.rb:10:in `method_missing': undefined method `setBrush' for #<Qt::Palette:0x00000000bd3738> (NoMethodError)
from transparentweb.rb:10:in `initialize'
from transparentweb.rb:45:in `new'
from transparentweb.rb:45:in `block in <main>'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2568:in `instance_eval'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:2568:in `run_initializer_block'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:431:in `initialize'
from /opt/ruby-1.9.1/lib/ruby/site_ruby/1.9.1/Qt/qtruby4.rb:431:in `initialize'
from transparentweb.rb:44:in `new'
from transparentweb.rb:44:in `<main>'

Oops, undefined method! Really?
> /opt/ruby-1.9.1/bin/rbqtapi -s Qt::Palette | grep setBrush
Qt::Palette#setBrush(Qt::Palette::ColorRole, Qt::Brush)
Qt::Palette#setBrush(Qt::Palette::ColorGroup, Qt::Palette::ColorRole, Qt::Brush)

Qt::Palette#setBrush exists. Umm... to be continued...

Thursday, July 2, 2009

QtWebkit over the proxy

I wrote some posts about QtWebkit. But these may fail if your program runs behind the proxy. Then I rewrite programs in phosphorescence: QtWebkit HTML5 practice like below. Additional codes are blue characters.

Qt program
#include <QApplication>
#include <QUrl>
#include <QWebView>
#include <QNetworkProxy>

int main(int argc, char *argv[]){
QApplication a(argc, argv);
QNetworkProxy proxy(QNetworkProxy::HttpProxy, "proxy.host", proxy.port);
QNetworkProxy::setApplicationProxy(proxy);

QUrl url("http://htmlfive.appspot.com/static/draw.html");
QWebView* webView = new QWebView();
webView->load(url);
webView->show();
return a.exec();
}

QtRuby program
require 'Qt4'
require 'qtwebkit'

Qt::Application.new(ARGV) do
proxy = Qt::NetworkProxy.new(Qt::NetworkProxy::HttpProxy, "proxy.host", proxy.port)
Qt::NetworkProxy.application_proxy = proxy

Qt::WebView.new do
self.load Qt::Url.new('http://htmlfive.appspot.com/static/gifter.html')
show
end
exec
end


proxy.host and proxy.port should replace ones of your proxy environment.