summaryrefslogtreecommitdiffstats
path: root/tdeui/kbuttonbox.h
blob: 4fd9e7ddb38845698724a1414eda441eeccf9bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* 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., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef __KBUTTONBOX__H__
#define __KBUTTONBOX__H__

#include <tdelibs_export.h>

#include <tqwidget.h>
class TQPushButton;
class KGuiItem;

class KButtonBoxPrivate;
/**
 * Container widget for buttons.
 *
 * This class uses Qt layout control to place the buttons; can handle
 * both vertical and horizontal button placement.  The default border
 * is now @p 0 (making it easier to deal with layouts). The space
 * between buttons is now more Motif compliant.
 *
 * @author Mario Weilguni <mweilguni@sime.com>
 * @version $Id$
 **/

class TDEUI_EXPORT KButtonBox : public TQWidget
{
  TQ_OBJECT

public:
  /**
    * Create an empty container for buttons.
    *
    * If @p _orientation is @p Vertical, the buttons inserted with
    * addButton() are laid out from top to bottom, otherwise they
    * are laid out from left to right.
    */
  KButtonBox(TQWidget *parent, Orientation _orientation = Qt::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 TQSize sizeHint() const;
  virtual TQSizePolicy sizePolicy() const;
  virtual void resizeEvent(TQResizeEvent *);

  /**
    * Add a new TQPushButton.
    *
    * @param text the text of the button to add
    * @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 is @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.
    */
  TQPushButton *addButton(const TQString& text, bool noexpand = false);

  /**
    * Add a new TQPushButton.
    *
    * @param text the text of the button to add.
    * @param receiver An object to connect to.
    * @param slot A Qt slot to connect the 'clicked()' signal to.
    * @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.
    */
  TQPushButton *addButton(const TQString& text, TQObject * receiver, const char * slot, bool noexpand = false);

  /**
    * Add a new TQPushButton.
    *
    * @param guiitem text and icon on the button
    * @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 is @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.
    *
    * @since 3.3
    */
  TQPushButton *addButton(const KGuiItem& guiitem, bool noexpand = false);

  /**
    * Add a new TQPushButton.
    *
    * @param guiitem text and icon on the button
    * @param receiver An object to connect to.
    * @param slot A Qt slot to connect the 'clicked()' signal to.
    * @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.
    *
    * @since 3.3
    */
  TQPushButton *addButton(const KGuiItem& guiitem, TQObject * receiver, const char * slot, bool noexpand = false);

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

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

public: // as PrivateData needs Item, it has to be exported
  class Item;
protected:
  /**
    * @return the best size for a button. Checks all buttons and takes
    * the maximum width/height.
    */
  TQSize bestButtonSize() const;
  void  placeButtons();
  TQSize buttonSizeHint(TQPushButton *) const;

protected:
  virtual void virtual_hook( int id, void* data );
private:
  KButtonBoxPrivate* const data;
};

#endif