[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: kdegames/kreversi
From:       "Nicolas Hadacek" <hadacek () kde ! org>
Date:       2004-07-05 18:15:10
Message-ID: 200407051215.10027.hadacek () kde ! org
[Download RAW message or body]

On Monday 05 July 2004 11:58 am, Andy Fawcett wrote:
> After this commit, with srcdir != builddir,
>
> nobby# pwd
> /mnt/src/head/build/kdegames/kreversi
> nobby# gmake
> Making all in .
> gmake[1]: Entering directory `/mnt/src/head/build/kdegames/kreversi'
> gmake[1]: *** No rule to make target `kzoommainwindow.cpp', needed by
> `kzoommainwindow.o'.  Stop.
> gmake[1]: Leaving directory `/mnt/src/head/build/kdegames/kreversi'
> gmake: *** [all-recursive] Error 1

oops sorry I failed to commit the new files (should be ok by now).

BTW is it too late to add the attached files to kdegames library ?
This new class will be used by kreversi, kmines, ksirtet, kfouleggs and 
klickety. Otherwise I just duplicate the files in each directory.

Nicolas

["kzoommainwindow.h" (text/x-chdr)]

/*
    This file is part of the KDE games library
    Copyright (C) 2004 Nicolas Hadacek (hadacek@kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef KZOOMMAINWINDOW_H
#define KZOOMMAINWINDOW_H

#include <kmainwindow.h>

class KToggleAction;

/**
 * KZoomMainWindow is a main window of fixed size. Its size can be
 * modified with the "zoom in"/"zoom out" actions.
 *
 * It manages one or several widgets: their adjustSize() method is
 * called whenever the zoom level is changed.
 * The usual implementation for those widget is to redefine adjustSize()
 * with code like:
 * /code
 * setFixedSize(newsize);
 * /endcode
 *
 * This class also has a "show/hide menubar" action and allows the use
 * of a context popup menu (useful to restore the menubar when hidden).
 */
class KZoomMainWindow : public KMainWindow
{
  Q_OBJECT
public:
  /** Constructor. */
  KZoomMainWindow(uint minZoom, uint maxZoom, uint zoomStep,
                  const char *name = 0);

  /** Add a widget to be managed i.e. the adjustSize() method of the
   * widget is called whenever the zoom is changed.
   * This function assumes that the topLevelWidget() is the KZoomMainWindow.
   */
  static void addWidget(QWidget *widget);
                  
  uint zoom() const { return _zoom; }
  
public slots:
  void zoomIn();
  void zoomOut();
  void toggleMenubar();

protected:
  /** You need to call this after the createGUI or setupGUI method
   * is called.
   * @param popupName is the name of the context popup menu as defined in
   * the ui.rc file.
   */
  void init(const char *popupName = 0);
    
  virtual void setZoom(uint zoom);
  virtual bool eventFilter(QObject *o, QEvent *e);
  virtual bool queryExit();
  
  /** You need to implement this method since different application
   * use different setting class names and keys.
   * Use something like:
   * /code
   * Settings::setZoom(zoom);
   * Settings::writeConfig();
   * /endcode
   */
  virtual void writeZoomSetting(uint zoom) = 0;
  
  /** Youneed to implement this method since different application
   * use different setting class names and keys.
   * Use something like:
   * /code
   * return Settings::zoom();
   * /endcode
   */
  virtual uint readZoomSetting() const = 0;
  
  /** You need to implement this method since different application
   * use different setting class names and keys.
   * Use something like:
   * /code
   * Settings::setMenubarVisible(visible);
   * Settings::writeConfig();
   * /endcode
   */
  virtual void writeMenubarVisibleSetting(bool visible) = 0;
  
  /** You need to implement this method since different application
   * use different setting class names and keys.
   * Use something like: 
   * /code
   * Settings::menubarVisible();
   * /endcode
   */
  virtual bool menubarVisibleSetting() const = 0;

private slots:
  void widgetDestroyed();
  
private:
  uint _zoom, _zoomStep, _minZoom, _maxZoom;
  QPtrList<QWidget> _widgets;
  KAction *_zoomInAction, *_zoomOutAction;
  KToggleAction *_menu;
  
  class KZoomMainWindowPrivate;
  KZoomMainWindowPrivate *d;
};

#endif

["kzoommainwindow.cpp" (text/x-c++src)]

/*
    This file is part of the KDE games library
    Copyright (C) 2004 Nicolas Hadacek (hadacek@kde.org)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License version 2 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include "kzoommainwindow.h"
#include "kzoommainwindow.moc"

#include <kaction.h>
#include <kstdaction.h>
#include <kmenubar.h>
#include <kcmenumngr.h>

KZoomMainWindow::KZoomMainWindow(uint min, uint max, uint step, const char *name)
  : KMainWindow(0, name), _zoomStep(step), _minZoom(min), _maxZoom(max)
{
  installEventFilter(this);
  
  _zoomInAction = KStdAction::zoomIn(this, SLOT(zoomIn()), actionCollection());
  _zoomOutAction =
    KStdAction::zoomOut(this, SLOT(zoomOut()), actionCollection());
  _menu =
    KStdAction::showMenubar(this, SLOT(toggleMenubar()), actionCollection());
}

void KZoomMainWindow::init(const char *popupName)
{
  // zoom
  setZoom(readZoomSetting());

  // menubar
  _menu->setChecked( menubarVisibleSetting() );  
  toggleMenubar();
  
  // context popup
  if (popupName) {
    QPopupMenu *popup =
      static_cast<QPopupMenu *>(factory()->container(popupName, this));
    Q_ASSERT(popup);
    if (popup) KContextMenuManager::insert(this, popup);
  }
}

void KZoomMainWindow::addWidget(QWidget *widget)
{
  widget->adjustSize();
  QWidget *tlw = widget->topLevelWidget();
  KZoomMainWindow *zm = 
    static_cast<KZoomMainWindow *>(tlw->qt_cast("KZoomMainWindow"));
  Q_ASSERT(zm);
  zm->_widgets.append(widget);
  connect(widget, SIGNAL(destroyed()), zm, SLOT(widgetDestroyed()));
}

void KZoomMainWindow::widgetDestroyed()
{
  _widgets.remove(static_cast<const QWidget *>(sender()));
}

bool KZoomMainWindow::eventFilter(QObject *o, QEvent *e)
{
  if ( e->type()==QEvent::LayoutHint )
    setFixedSize(minimumSize()); // because K/QMainWindow
                                 // does not manage fixed central widget
                                 // with hidden menubar...
  return KMainWindow::eventFilter(o, e);
}

void KZoomMainWindow::setZoom(uint zoom)
{
  _zoom = zoom;
  writeZoomSetting(_zoom);
  QPtrListIterator<QWidget> it(_widgets);
  for (; it.current(); ++it)
    (*it)->adjustSize();; 
  _zoomOutAction->setEnabled( _zoom>_minZoom );
  _zoomInAction->setEnabled( _zoom<_maxZoom );
}

void KZoomMainWindow::zoomIn()
{
  setZoom(_zoom + _zoomStep);
}

void KZoomMainWindow::zoomOut()
{
  Q_ASSERT( _zoom>=_zoomStep );
  setZoom(_zoom - _zoomStep);
}

void KZoomMainWindow::toggleMenubar()
{
  if ( _menu->isChecked() ) menuBar()->show();
  else menuBar()->hide();
}

bool KZoomMainWindow::queryExit()
{
  writeMenubarVisibleSetting(_menu->isChecked());
  return KMainWindow::queryExit();
}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic