
Instructions to port applications using Qt library and KDE to use 
gtk-- and gnome.

This text was produced while converting kmahjongg to gtk. (I've not
yet finished porting the app completely)

Class matches:
QMainWidget => Gtk_Window
QPopupMenu => Gtk_Menu
QMenuBar => Gtk_MenuBar
KStatusBar => (nothing available to replace it yet, 
               gnome is working on statusbar though (a rumor))


Problems found:


Header files:
* Signals/Slots/Classes
Qt uses a parser from which all files with any signal or slot handling must
go through before compilation.

Qt:
class Foo : public QMainWidget {
Q_OBJECT
public signals:
   void statusMsgChanged(char *pszMessage);
public slots:
   void menuCallback(int a);
};

Gtk-- uses templates and function objects to generate the code needed
to implement callbacks.

Gtk--:
class Foo : public Gtk_Window {
public:
  Signal1<char*> statusMsgChanged; /* pszMessage */
  void menuCallBack(int a); 
};

Constructors:
* Every Qt widget has a parent and all of them usually take the parent as
   constructor argument, while gtk-- has add() method for containers and
   pack_start() for Boxes.
   - convert  p=new QWidget(this);   to   p=new Gtk_Widget; add(p);
      and keep sure the current object is derived from Gtk_Container.

* Seems to be common practice in Qt to Move() the object around.
   (for example in Qt to make a menubar, they create a menubar and
   another widget and then move the 2nd widget to its correct position.
   - deal this with a VBox widget in gtk--. For example, to make a menubar
   and another widget, make a VBox, add it to the window, and then pack the
   menubar and the another widget to the VBox using pack_start.

* Connecting signals in Qt is made with some sort of macro-hackery and
  separate parser.
  Qt: connect( bw, SIGNAL( tileNumberChanged(int,int) ), 
                   SLOT( showTileNumber(int,int) ) );

Gtk--'s callbacks use template functions.
gtk--: connect( bw.tileNumberChanged, this, showTileNumber );
  (this is inside constructor of a class which have 
     void Signal2<int,int> tileNumberChanged; /* iMaximum, iCurrent */
   declared)

* In Qt you can connect many menu items to one SLOT and identify the
   menu from the integer passed to the activated-signal.
   QPopupMenu p;
   p.insertItem("menu1",1)
   p.insertItem("menu2",2)
   ...
   connect( p, SIGNAL(activated(int)), SLOT(menuCallback(int)) );
=> 
  In Gtk--, you can pass an extra argument of any type to a connect() and 
  thus at the callback, identify the item from that value.

  void menuCallback(int);
  Gtk_Menu b;
  Gtk_MenuItem *t;
  b.append(t=new Gtk_MenuItem("menu1"));
  connect(t->select, this, menuCallback, 1);
  b.append(t=new Gtk_MenuItem("menu2"));
  connect(t->select, this, menuCallback, 2);
  ...

* In Qt there's insertSeparator() function in QPopupMenu for adding separator
  for a Menu. Gtk-- uses default constructor of Gtk_MenuItem.

Qt:
  QPopupMenu p;
  p.insertSeparator();

Gtk--:
  Gtk_Menu b;
  b.append(new Gtk_MenuItem);

* Inserting a submenu to a menu item in Qt is made with overloaded insertItem()
  method. In Gtk, there's separate set_submenu() method for it.

Qt:
  QPopupMenu p,p1;
  p.insertItem("submenu1",&p1,1);
Gtk--:
  Gtk_Menu p,p1;
  Gtk_MenuItem *t;
  p.append(t=new Gtk_MenuItem("submenu1"));
  t.set_submenu(&p1);
  connect(t->select, this, menuCallback, 1);

(oh, btw, these are the hard ways of creating menus in gtk, menufactory
should be easier to use for your own code :)

* Qt's Setmenu() should be replaced by adding MenuBar to some gtk container,
  for example Gtk_VBox.


-------------------------
* QFileDialog::getOpenFileName
- Better make it nonmodal.
=> we'll create the Gtk_FileSelection widget at constructor of current
   object and where getOpenFileName is called, we'll just show the
   fileselection widget. Then we connect the ok_button and cancel_button
   of the file selection widget to the actions that do what they need to do.

* Qt has QmessageBox class for easy to use messages.
QMessageBox::message( NULL,  "message", NULL, this );
There seems to be no replacement - I made quickly a replacement for it...
Check MessageBox.cc/MessageBox.h

* Qt's QImage can reads .bmp files.
  Gtk's image stuffs seems to be kinda difficult. Need to use
  gdk_pixmap_create_from_xpm() and it'll be problematic... here's a code that
  loads an xpm format images: (needs to be inside widget's member function)
  (I think there's a Pixmap_Factory available somewhere too which makes this
  alittle easier...)
    GdkBitmap *bitmap;
    GtkStyle *style=GTK_WIDGET(gtkobject)->style;
    GdkWindow *gdkwin=GTK_WIDGET(gtkobject)->window;
    GdkPixmap *pm;
    if (! (pm=gdk_pixmap_create_from_xpm(gdkwin,&bitmap,&style->bg[GTK_STATE_NORMAL],pszFileName)) ) {
        /* error */
   }
   GtkPixmap *p=new Gtk_Pixmap(pm,bitmap);

