summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui
authorzautrix <zautrix>2005-07-10 10:17:55 (UTC)
committer zautrix <zautrix>2005-07-10 10:17:55 (UTC)
commit58b7818a74809dc9280a3249eeb7e0195a66f93d (patch) (unidiff)
tree04b04b867647a8c48d59e7a0fa89df6430039599 /microkde/kdeui
parente8b6635ef7c98996f0415e6a77394569493ab151 (diff)
downloadkdepimpi-58b7818a74809dc9280a3249eeb7e0195a66f93d.zip
kdepimpi-58b7818a74809dc9280a3249eeb7e0195a66f93d.tar.gz
kdepimpi-58b7818a74809dc9280a3249eeb7e0195a66f93d.tar.bz2
fixx
Diffstat (limited to 'microkde/kdeui') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/kbuttonbox.cpp2
-rw-r--r--microkde/kdeui/kpopupmenu.cpp19
-rw-r--r--microkde/kdeui/kpopupmenu.h22
3 files changed, 40 insertions, 3 deletions
diff --git a/microkde/kdeui/kbuttonbox.cpp b/microkde/kdeui/kbuttonbox.cpp
index 16206e8..83d622a 100644
--- a/microkde/kdeui/kbuttonbox.cpp
+++ b/microkde/kdeui/kbuttonbox.cpp
@@ -1,300 +1,300 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Mario Weilguni (mweilguni@sime.com) 2 Copyright (C) 1997 Mario Weilguni (mweilguni@sime.com)
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either 6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version. 7 version 2 of the License, or (at your option) any later version.
8 8
9 This library is distributed in the hope that it will be useful, 9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20/* 20/*
21 * KButtonBox class 21 * KButtonBox class
22 * 22 *
23 * A container widget for buttons. Uses Qt layout control to place the 23 * A container widget for buttons. Uses Qt layout control to place the
24 * buttons, can handle both vertical and horizontal button placement. 24 * buttons, can handle both vertical and horizontal button placement.
25* 25*
26 * HISTORY 26 * HISTORY
27 * 27 *
28 * 03/08/2000 Mario Weilguni <mweilguni@kde.org> 28 * 03/08/2000 Mario Weilguni <mweilguni@kde.org>
29 * Removed all those long outdated Motif stuff 29 * Removed all those long outdated Motif stuff
30 * Improved and clarified some if conditions (easier to understand) 30 * Improved and clarified some if conditions (easier to understand)
31 * 31 *
32 * 11/13/98 Reginald Stadlbauer <reggie@kde.org> 32 * 11/13/98 Reginald Stadlbauer <reggie@kde.org>
33 * Now in Qt 1.4x motif default buttons have no extra width/height anymore. 33 * Now in Qt 1.4x motif default buttons have no extra width/height anymore.
34 * So the KButtonBox doesn't add this width/height to default buttons anymore 34 * So the KButtonBox doesn't add this width/height to default buttons anymore
35 * which makes the buttons look better. 35 * which makes the buttons look better.
36 * 36 *
37 * 01/17/98 Mario Weilguni <mweilguni@sime.com> 37 * 01/17/98 Mario Weilguni <mweilguni@sime.com>
38 * Fixed a bug in sizeHint() 38 * Fixed a bug in sizeHint()
39 * Improved the handling of Motif default buttons 39 * Improved the handling of Motif default buttons
40 * 40 *
41 * 01/09/98 Mario Weilguni <mweilguni@sime.com> 41 * 01/09/98 Mario Weilguni <mweilguni@sime.com>
42 * The last button was to far right away from the right/bottom border. 42 * The last button was to far right away from the right/bottom border.
43 * Fixed this. Removed old code. Buttons get now a minimum width. 43 * Fixed this. Removed old code. Buttons get now a minimum width.
44 * Programmer may now override minimum width and height of a button. 44 * Programmer may now override minimum width and height of a button.
45 * 45 *
46 */ 46 */
47 47
48//US #include "kbuttonbox.moc" 48//US #include "kbuttonbox.moc"
49 49
50#include <kbuttonbox.h> 50#include <kbuttonbox.h>
51#include <qpushbutton.h> 51#include <qpushbutton.h>
52#include <qptrlist.h> 52#include <qptrlist.h>
53#include <assert.h> 53#include <assert.h>
54 54
55#define minButtonWidth 50 55#define minButtonWidth 50
56 56
57class KButtonBox::Item { 57class KButtonBox::Item {
58public: 58public:
59 QPushButton *button; 59 QPushButton *button;
60 bool noexpand; 60 bool noexpand;
61 unsigned short stretch; 61 unsigned short stretch;
62 unsigned short actual_size; 62 unsigned short actual_size;
63}; 63};
64 64
65template class QPtrList<KButtonBox::Item>; 65template class QPtrList<KButtonBox::Item>;
66 66
67class KButtonBoxPrivate { 67class KButtonBoxPrivate {
68public: 68public:
69 unsigned short border; 69 unsigned short border;
70 unsigned short autoborder; 70 unsigned short autoborder;
71 unsigned short orientation; 71 unsigned short orientation;
72 bool activated; 72 bool activated;
73 QPtrList<KButtonBox::Item> buttons; 73 QPtrList<KButtonBox::Item> buttons;
74}; 74};
75 75
76KButtonBox::KButtonBox(QWidget *parent, Orientation _orientation, 76KButtonBox::KButtonBox(QWidget *parent, Orientation _orientation,
77 int border, int autoborder) 77 int border, int autoborder)
78 : QWidget(parent) 78 : QWidget(parent)
79{ 79{
80 data = new KButtonBoxPrivate; 80 data = new KButtonBoxPrivate;
81 assert(data != 0); 81 assert(data != 0);
82 82
83 data->orientation = _orientation; 83 data->orientation = _orientation;
84 data->border = border; 84 data->border = border;
85 data->autoborder = autoborder < 0 ? border : autoborder; 85 data->autoborder = autoborder < 0 ? border : autoborder;
86 data->buttons.setAutoDelete(TRUE); 86 data->buttons.setAutoDelete(TRUE);
87} 87}
88 88
89KButtonBox::~KButtonBox() { 89KButtonBox::~KButtonBox() {
90 delete data; 90 delete data;
91} 91}
92 92
93QPushButton *KButtonBox::addButton(const QString& text, bool noexpand) { 93QPushButton *KButtonBox::addButton(const QString& text, bool noexpand) {
94 Item *item = new Item; 94 Item *item = new Item;
95 95
96 item->button = new QPushButton(text, this); 96 item->button = new QPushButton(text, this);
97 item->noexpand = noexpand; 97 item->noexpand = noexpand;
98 data->buttons.append(item); 98 data->buttons.append(item);
99 item->button->adjustSize(); 99 item->button->adjustSize();
100 100
101 return item->button; 101 return item->button;
102} 102}
103 103
104 QPushButton * 104 QPushButton *
105KButtonBox::addButton( 105KButtonBox::addButton(
106 const QString & text, 106 const QString & text,
107 QObject * receiver, 107 QObject * receiver,
108 const char * slot, 108 const char * slot,
109 bool noexpand 109 bool noexpand
110) 110)
111{ 111{
112 QPushButton * pb = addButton(text, noexpand); 112 QPushButton * pb = addButton(text, noexpand);
113 113
114 if ((0 != receiver) && (0 != slot)) 114 if ((0 != receiver) && (0 != slot))
115 QObject::connect(pb, SIGNAL(clicked()), receiver, slot); 115 QObject::connect(pb, SIGNAL(clicked()), receiver, slot);
116 116
117 return pb; 117 return pb;
118} 118}
119 119
120 120
121void KButtonBox::addStretch(int scale) { 121void KButtonBox::addStretch(int scale) {
122 if(scale > 0) { 122 if(scale > 0) {
123 Item *item = new Item; 123 Item *item = new Item;
124 item->button = 0; 124 item->button = 0;
125 item->noexpand = FALSE; 125 item->noexpand = FALSE;
126 item->stretch = scale; 126 item->stretch = scale;
127 data->buttons.append(item); 127 data->buttons.append(item);
128 } 128 }
129} 129}
130 130
131void KButtonBox::layout() { 131void KButtonBox::layout() {
132 // resize all buttons 132 // resize all buttons
133 QSize bs = bestButtonSize(); 133 QSize bs = bestButtonSize();
134 134
135 for(unsigned int i = 0; i < data->buttons.count(); i++) { 135 for(unsigned int i = 0; i < data->buttons.count(); i++) {
136 Item *item = data->buttons.at(i); 136 Item *item = data->buttons.at(i);
137 QPushButton *b = item->button; 137 QPushButton *b = item->button;
138 if(b != 0) { 138 if(b != 0) {
139 if(item->noexpand) 139 if(item->noexpand)
140 b->setFixedSize(buttonSizeHint(b)); 140 b->setFixedSize(buttonSizeHint(b));
141 else 141 else
142 b->setFixedSize(bs); 142 b->setFixedSize(bs);
143 } 143 }
144 } 144 }
145 145
146 setMinimumSize(sizeHint()); 146 setMinimumSize(sizeHint());
147} 147}
148 148
149void KButtonBox::placeButtons() { 149void KButtonBox::placeButtons() {
150 unsigned int i; 150 unsigned int i;
151 151
152 if(data->orientation == Horizontal) { 152 if(data->orientation == Horizontal) {
153 // calculate free size and stretches 153 // calculate free size and stretches
154 int fs = width() - 2 * data->border; 154 int fs = width() - 2 * data->border;
155 int stretch = 0; 155 int stretch = 0;
156 for(i = 0; i < data->buttons.count(); i++) { 156 for(i = 0; i < data->buttons.count(); i++) {
157 Item *item = data->buttons.at(i); 157 Item *item = data->buttons.at(i);
158 if(item->button != 0) { 158 if(item->button != 0) {
159 fs -= item->button->width(); 159 fs -= item->button->width();
160 160
161 // Last button? 161 // Last button?
162 if(i != data->buttons.count() - 1) 162 if(i != data->buttons.count() - 1)
163 fs -= data->autoborder; 163 fs -= data->autoborder;
164 } else 164 } else
165 stretch +=item->stretch; 165 stretch +=item->stretch;
166 } 166 }
167 167
168 // distribute buttons 168 // distribute buttons
169 int x_pos = data->border; 169 int x_pos = data->border;
170 for(i = 0; i < data->buttons.count(); i++) { 170 for(i = 0; i < data->buttons.count(); i++) {
171 Item *item = data->buttons.at(i); 171 Item *item = data->buttons.at(i);
172 if(item->button != 0) { 172 if(item->button != 0) {
173 QPushButton *b = item->button; 173 QPushButton *b = item->button;
174 b->move(x_pos, (height() - b->height()) / 2); 174 b->move(x_pos, (height() - b->height()) / 2);
175 175
176 x_pos += b->width() + data->autoborder; 176 x_pos += b->width() + data->autoborder;
177 } else 177 } else
178 x_pos += (int)((((double)fs) * item->stretch) / stretch); 178 x_pos += (int)((((double)fs) * item->stretch) / stretch);
179 } 179 }
180 } else { // VERTICAL 180 } else { // VERTICAL
181 // calcualte free size and stretches 181 // calcualte free size and stretches
182 int fs = height() - 2 * data->border; 182 int fs = height() - 2 * data->border;
183 int stretch = 0; 183 int stretch = 0;
184 for(i = 0; i < data->buttons.count(); i++) { 184 for(i = 0; i < data->buttons.count(); i++) {
185 Item *item = data->buttons.at(i); 185 Item *item = data->buttons.at(i);
186 if(item->button != 0) 186 if(item->button != 0)
187 fs -= item->button->height() + data->autoborder; 187 fs -= item->button->height() + data->autoborder;
188 else 188 else
189 stretch +=item->stretch; 189 stretch +=item->stretch;
190 } 190 }
191 191
192 // distribute buttons 192 // distribute buttons
193 int y_pos = data->border; 193 int y_pos = data->border;
194 for(i = 0; i < data->buttons.count(); i++) { 194 for(i = 0; i < data->buttons.count(); i++) {
195 Item *item = data->buttons.at(i); 195 Item *item = data->buttons.at(i);
196 if(item->button != 0) { 196 if(item->button != 0) {
197 QPushButton *b = item->button; 197 QPushButton *b = item->button;
198 b->move((width() - b->width()) / 2, y_pos); 198 b->move((width() - b->width()) / 2, y_pos);
199 199
200 y_pos += b->height() + data->autoborder; 200 y_pos += b->height() + data->autoborder;
201 } else 201 } else
202 y_pos += (int)((((double)fs) * item->stretch) / stretch); 202 y_pos += (int)((((double)fs) * item->stretch) / stretch);
203 } 203 }
204 } 204 }
205} 205}
206 206
207void KButtonBox::resizeEvent(QResizeEvent *) { 207void KButtonBox::resizeEvent(QResizeEvent *) {
208 placeButtons(); 208 placeButtons();
209} 209}
210 210
211QSize KButtonBox::bestButtonSize() const { 211QSize KButtonBox::bestButtonSize() const {
212 QSize s(0, 0); 212 QSize s(0, 0);
213 unsigned int i; 213 unsigned int i;
214 214
215 // calculate optimal size 215 // calculate optimal size
216 for(i = 0; i < data->buttons.count(); i++) { 216 for(i = 0; i < data->buttons.count(); i++) {
217 KButtonBox *that = (KButtonBox*)this; // to remove the const ;( 217 KButtonBox *that = (KButtonBox*)this; // to remove the const ;(
218 Item *item = that->data->buttons.at(i); 218 Item *item = that->data->buttons.at(i);
219 QPushButton *b = item->button; 219 QPushButton *b = item->button;
220 220
221 if(b != 0 && !item->noexpand) { 221 if(b != 0 && !item->noexpand) {
222 QSize bs = buttonSizeHint(b); 222 QSize bs = buttonSizeHint(b);
223 223
224 if(bs.width() > s.width()) 224 if(bs.width() > s.width())
225 s.setWidth(bs.width()); 225 s.setWidth(bs.width());
226 if(bs.height() > s.height()) 226 if(bs.height() > s.height())
227 s.setHeight(bs.height()); 227 s.setHeight(bs.height());
228 } 228 }
229 } 229 }
230 230
231 return s; 231 return s;
232} 232}
233 233
234QSize KButtonBox::sizeHint() const { 234QSize KButtonBox::sizeHint() const {
235 unsigned int i, dw; 235 unsigned int i, dw;
236 236
237 if(data->buttons.count() == 0) 237 if(data->buttons.count() == 0)
238 return QSize(0, 0); 238 return QSize(0, 0);
239 else { 239 else {
240 dw = 2 * data->border; 240 dw = 2 * data->border;
241 241
242 QSize bs = bestButtonSize(); 242 QSize bs = bestButtonSize();
243 for(i = 0; i < data->buttons.count(); i++) { 243 for(i = 0; i < data->buttons.count(); i++) {
244 KButtonBox *that = (KButtonBox*)this; 244 KButtonBox *that = (KButtonBox*)this;
245 Item *item = that->data->buttons.at(i); 245 Item *item = that->data->buttons.at(i);
246 QPushButton *b = item->button; 246 QPushButton *b = item->button;
247 if(b != 0) { 247 if(b != 0) {
248 QSize s; 248 QSize s;
249 if(item->noexpand) 249 if(item->noexpand)
250 s = that->buttonSizeHint(b); 250 s = that->buttonSizeHint(b);
251 else 251 else
252 s = bs; 252 s = bs;
253 253
254 if(data->orientation == Horizontal) 254 if(data->orientation == Horizontal)
255 dw += s.width(); 255 dw += s.width();
256 else 256 else
257 dw += s.height(); 257 dw += s.height();
258 258
259 if( i != data->buttons.count() - 1 ) 259 if( i != data->buttons.count() - 1 )
260 dw += data->autoborder; 260 dw += data->autoborder;
261 } 261 }
262 } 262 }
263 263
264 if(data->orientation == Horizontal) 264 if(data->orientation == Horizontal)
265 return QSize(dw, bs.height() + 2 * data->border); 265 return QSize(dw, bs.height() + 2 * data->border);
266 else 266 else
267 return QSize(bs.width() + 2 * data->border, dw); 267 return QSize(bs.width() + 2 * data->border, dw);
268 } 268 }
269} 269}
270 270
271QSizePolicy KButtonBox::sizePolicy() const 271QSizePolicy KButtonBox::sizePolicy() const
272{ 272{
273 return data->orientation == Horizontal? 273 return data->orientation == Horizontal?
274 QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) : 274 QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) :
275 QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum ); 275 QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum );
276} 276}
277 277
278/* 278/*
279 * Returns the best size for a button. If a button is less than 279 * Returns the best size for a button. If a button is less than
280 * minButtonWidth pixels wide, return minButtonWidth pixels 280 * minButtonWidth pixels wide, return minButtonWidth pixels
281 * as minimum width 281 * as minimum width
282 */ 282 */
283QSize KButtonBox::buttonSizeHint(QPushButton *b) const { 283QSize KButtonBox::buttonSizeHint(QPushButton *b) const {
284 QSize s = b->sizeHint(); 284 QSize s = b->sizeHint();
285 QSize ms = b->minimumSize(); 285 QSize ms = b->minimumSize();
286 if(s.width() < minButtonWidth) 286 if(s.width() < minButtonWidth)
287 s.setWidth(minButtonWidth); 287 s.setWidth(minButtonWidth);
288 288
289 // allows the programmer to override the settings 289 // allows the programmer to override the settings
290 if(ms.width() > s.width()) 290 if(ms.width() > s.width())
291 s.setWidth(ms.width()); 291 s.setWidth(ms.width());
292 if(ms.height() > s.height()) 292 if(ms.height() > s.height())
293 s.setHeight(ms.height()); 293 s.setHeight(ms.height());
294 294
295 return s; 295 return s;
296} 296}
297 297
298void KButtonBox::virtual_hook( int, void* ) 298void KButtonBox::virtual_hook( int, void* )
299{ /*BASE::virtual_hook( id, data );*/ } 299{ /*BASE::virtual_hook( id, data );*/ }
300 300
diff --git a/microkde/kdeui/kpopupmenu.cpp b/microkde/kdeui/kpopupmenu.cpp
new file mode 100644
index 0000000..96d2a87
--- a/dev/null
+++ b/microkde/kdeui/kpopupmenu.cpp
@@ -0,0 +1,19 @@
1
2#include <kpopupmenu.h>
3#include <qtimer.h>
4
5
6KPopupMenu::KPopupMenu ( QWidget * parent, const char * name )
7 : QPopupMenu ( parent, name ) {;}
8
9
10
11KMenuBar::KMenuBar ( QWidget * parent, const char * name )
12 : QPEMenuBar ( parent, name ) {}
13
14void KMenuBar::focusOutEvent ( QFocusEvent * e)
15{
16 QPEMenuBar::focusOutEvent( e );
17 QTimer::singleShot( 100, this, SIGNAL ( lostFocus() ) );
18
19}
diff --git a/microkde/kdeui/kpopupmenu.h b/microkde/kdeui/kpopupmenu.h
index 1352429..f16ce77 100644
--- a/microkde/kdeui/kpopupmenu.h
+++ b/microkde/kdeui/kpopupmenu.h
@@ -1,14 +1,32 @@
1#ifndef KPOPUPMENU_H 1#ifndef KPOPUPMENU_H
2#define KPOPUPMENU_H 2#define KPOPUPMENU_H
3 3
4#include <qpopupmenu.h> 4#include <qpopupmenu.h>
5#ifdef DESKTOP_VERSION
6#include <qmenubar.h>
7#define QPEMenuBar QMenubar
8#else
9#include <qpe/qpemenubar.h>
10#endif
5 11
6class KPopupMenu : public QPopupMenu 12class KPopupMenu : public QPopupMenu
7{ 13{
14Q_OBJECT
8 public: 15 public:
9 KPopupMenu ( QWidget * parent=0, const char * name=0 ) 16 KPopupMenu ( QWidget * parent=0, const char * name=0 );
10 : QPopupMenu ( parent, name ) {} 17
18};
11 19
20
21class KMenuBar : public QPEMenuBar
22{
23Q_OBJECT
24 public:
25 KMenuBar ( QWidget * parent=0, const char * name=0 );
26 signals:
27 void lostFocus();
28 protected:
29 void focusOutEvent ( QFocusEvent * e);
12}; 30};
13 31
14#endif 32#endif