Source: kbuttonbox.h


Annotated List
Files
Globals
Hierarchy
Index
/* This file is part of the KDE libraries
    Copyright (C) 1997 Mario Weilguni (mweilguni@sime.com)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    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 __KBUTTONBOX__H__
#define __KBUTTONBOX__H__

#include <qwidget.h>
#include <qpushbutton.h>

/**
 * Container widget for buttons. 
 * 
 * Uses Qt layout control to place the buttons, can handle both vertical
 * and horizontal button placement.  The default border is now 0 (easier
 * to deal with layouts). The space between buttons is now more Motif
 * compliant.
 *
 * @author Mario Weilguni <mweilguni@sime.com>
 * @version $Id: kbuttonbox.h,v 1.13 2000/03/12 10:36:16 mario Exp $
 **/

class KButtonBox : public QWidget {
  Q_OBJECT
public:
  /**
   * Orientations for the button box.
   **/
  enum { VERTICAL = 1, HORIZONTAL = 2 };

  /**
    * Create an empty container for buttons.
    *
    *  If @p _orientation is 
    * @p KButtonBox::VERTICAL, the buttons inserted with @ref addButton()
    * are laid out from top to bottom, otherwise they are laid out
    * from left to right.
    */
  KButtonBox(QWidget *parent, int _orientation = HORIZONTAL, 
	     int border = 0, int _autoborder = 6);

  /**
    * Free private data field
    */
  ~KButtonBox();

  /**
    * @return The minimum size needed to fit all buttons.
    *
    * This size is
    * calculated by the width/height of all buttons plus border/autoborder.
    */
  virtual QSize sizeHint() const;

  virtual void resizeEvent(QResizeEvent *);

  /**
    * Add a new @ref QPushButton.  
    *
    * @param noexpand If @p noexpand is @p false, the width
    * of the button is adjusted to fit the other buttons (the maximum
    * of all buttons is taken). If @p noexpand @p true, the width of this
    * button will be set to the minimum width needed for the given text).
    *
    * @return A pointer to the new button.
    */
  QPushButton *addButton(const QString& text, bool noexpand = FALSE);

  /**
    * Add a stretch to the buttonbox. 
    *
    * @see QBoxLayout for details.
    * Can be used to separate buttons (i.e. if you add the buttons "OK",
    * "Cancel", add a stretch and then add the button "Help", "OK" and
    * "Cancel" will be left-aligned (or top-aligned for vertical) while
    * "Help" will be right-aligned (or bottom-aligned for vertical).
    */
  void addStretch(int scale = 1);

  /**
    * This function must be called @bf once after all buttons have been
    * inserted.
    *
    * It will start layout control.
    */
  void layout();

protected:
  class Item;
  class PrivateData;  

  /**
    * @return the best size for a button. Checks all buttons and takes
    * the maximum width/height.
    */
  QSize bestButtonSize() const;
  void  placeButtons();
  QSize buttonSizeHint(QPushButton *) const;
  
  PrivateData *data;
};

#endif

Generated by: root@porky.devel.redhat.com on Wed May 10 08:56:43 2000, using kdoc 2.0a35.