[Kde-games-devel] KZoomMainWindow and adjustSize() tale :)

Dmitry Suzdalev dimsuz at gmail.com
Mon Jul 31 12:38:30 CEST 2006


Hello, gamers!

First some facts:
KZoomMainWindow is used to introduce a common window with "zoomIn",
"zoomOut" actions.
Each child widget which supports this actions can call a static
KZoomMainWindow::addWidget(this) to add itself to KZoomMainWindow pets list :).
And then, after user activates zoomIn/Out actions, KZoomMainWindows
walks through the list of its "pet" widgets and calls adjustSize() on
each.
Widgets were supposed to reimplement this adjustSize() method to make
the zoomed resize.

Well, now the problem:
In Qt4 adjustSize() is non-virtual. So it can't be safely overridden.

I see two solutions here:
1. Drop KZoomMainWindow. Its _separate_ copies are used in libksirtet,
kreversi, kmines ONLY. And in kdegames only. I checked in lxr.kde.org.
2. Don't drop it, but implement something like this instead:

class ZoomableWidget : public QWidget
{
....
protected:
     /* This virtual is here instead of adjustSize */
     virtual void zoomChanged() { }
....
};

class KZoomMainWindow : public KMainWindow
{
....
public:
   // earlier had QWidget* param
   static addWidget( ZoomedWidget*);
};

And later when KZoomMainWindow iterates over it's zoomable-widgets
list it should call zoomChanged instead of adjustSize().

Several things to note:
- why is KZoomMainWindow _explicitly_ defined three times in three
games, rather than being in libkdegames?
- is the 2. worth it? That's not a lot funtionality to put it in
common shared class, wont it be easier to add two slots
(zoomIn/zoomOut)+three variables(minZoom,maxZoom,zoom) to games that
need it and be done?

Thanks in advance for your fast replies,
Dmitry :).


More information about the kde-games-devel mailing list