kdgantt

KDGanttSemiSizingControl.cpp
1/*
2 $Id$
3*/
4
5/****************************************************************************
6 ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
7 **
8 ** This file is part of the KDGantt library.
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.GPL included in the
13 ** packaging of this file.
14 **
15 ** Licensees holding valid commercial KDGantt licenses may use this file in
16 ** accordance with the KDGantt Commercial License Agreement provided with
17 ** the Software.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
23 ** information about KDGantt Commercial License Agreements.
24 **
25 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26 ** licensing are not clear to you.
27 **
28 ** As a special exception, permission is given to link this program
29 ** with any edition of TQt, and distribute the resulting executable,
30 ** without including the source code for TQt in the source distribution.
31 **
32 **********************************************************************/
33
34
35#include "KDGanttSemiSizingControl.h"
36#include <tqpushbutton.h>
37#include <tqpointarray.h>
38#include <tqpainter.h>
39#include <tqbitmap.h>
40#include <tqtooltip.h>
41#include <tqwhatsthis.h>
67 const char* name ) :
68 KDGanttSizingControl( parent, name ), _orient( TQt::Horizontal ),
69 _arrowPos( Before ), _minimizedWidget(0), _maximizedWidget(0)
70{
71 init();
72}
73
74
88 TQWidget* parent,
89 const char* name ) :
90 KDGanttSizingControl( parent, name ), _orient( orientation ),
91 _arrowPos( Before ), _minimizedWidget(0), _maximizedWidget(0)
92{
93 init();
94}
95
96
111 TQt::Orientation orientation,
112 TQWidget* parent,
113 const char* name ) :
114 KDGanttSizingControl( parent, name ), _orient( orientation ),
115 _arrowPos( arrowPosition ), _minimizedWidget(0), _maximizedWidget(0)
116{
117 init();
118}
119
120
131{
132 _minimizedWidget = widget;
133 if( _minimizedWidget ) _minimizedWidget->hide();
134 setup();
135}
136
137
147{
148 return _minimizedWidget;
149}
150
161{
162 _maximizedWidget = widget;
163 //if( _maximizedWidget ) _maximizedWidget->show();
164 setup();
165}
166
176{
177 return _maximizedWidget;
178}
179
180
181
189void KDGanttSemiSizingControl::setOrientation( TQt::Orientation orientation )
190{
191 if ( _orient != orientation ) {
192 _orient = orientation;
193 setup();
194 }
195}
196
197
205{
206 return _orient;
207}
208
209
218{
219 if ( _arrowPos != arrowPosition ) {
220 _arrowPos = arrowPosition;
221 setup();
222 }
223}
224
225
234{
235 return _arrowPos;
236}
237
238
247void KDGanttSemiSizingControl::init()
248{
249 _but = new TQPushButton( this );
250 _but->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) );
251 connect( _but, TQ_SIGNAL( clicked() ), this, TQ_SLOT(changeState()) );
252 _layout = 0;
253 TQWhatsThis::add( _but, "Click on this button to show the \nlegend at the bottom of the widget");
254 TQToolTip::add( _but, "Show / hide legend");
255
256
257}
258
259void KDGanttSemiSizingControl::setup()
260{
261 //-------------------------------------------------- Setup layout
262 delete _layout;
263 TQBoxLayout* butLayout; // _layout will delete me
264
265 if ( _orient == TQt::Horizontal || isMinimized() )
266 _layout = new TQHBoxLayout( this );
267 else
268 _layout = new TQVBoxLayout( this );
269
270 if ( _orient == TQt::Vertical && !isMinimized() )
271 butLayout = new TQHBoxLayout( _layout );
272 else
273 butLayout = new TQVBoxLayout( _layout );
274
275
276
277 //---------------------------------------- Set the arrow on the button
278 if ( !isMinimized() ) {
279 _but->setPixmap( pixmap( Down ) );
280 }
281 else {
282 if ( _arrowPos == Before ) {
283 _but->setPixmap( pixmap( Right ) );
284 }
285 else {
286 _but->setPixmap( pixmap( Left ) );
287 }
288 }
289
290 //------------------------------ Setup the button at the correct possition
291 if ( _arrowPos == After && _orient == TQt::Vertical && !isMinimized() ) {
292 butLayout->addStretch( 1 );
293 butLayout->addWidget( _but, 0, TQt::AlignLeft );
294 }
295 else {
296 butLayout->addWidget( _but, 0, TQt::AlignRight );
297 butLayout->addStretch( 1 );
298 }
299
300 // Set widget in the correct possition
301 TQWidget* widget;
302 /* ************************** old code ***************
303 if ( isMinimized() )
304 widget = _minimizedWidget;
305 else
306 widget = _maximizedWidget;
307 if( widget ) {
308 if ( _arrowPos == Before || _orient == TQt::Vertical && !isMinimized() )
309 _layout->addWidget( widget, 1 );
310 else
311 _layout->insertWidget( 0, widget, 1 );
312 }
313 ************************************************** */
314 // hack for the usage in KDGantt as pop-up legend widget
315 // for this purpose,
316 // the _maximizedWidget must be a child of the parent of this widget
317
318 if ( isMinimized() ) {
319 widget = _minimizedWidget;
320 if( widget ) {
321 if ( _arrowPos == Before || _orient == TQt::Vertical && !isMinimized() )
322 _layout->addWidget( widget, 1 );
323 else
324 _layout->insertWidget( 0, widget, 1 );
325 }
326 }
327 else {
328 if ( _arrowPos == Before || _orient == TQt::Vertical && !isMinimized() )
329 _layout->addStretch( 1 );
330 else
331 _layout->insertStretch( 0, 1 );
332 widget = _maximizedWidget;
333 // the following is only the special case
334 // arrowPos == Before and _orient == TQt::Vertical
335 //widget->move( 0+x(), _but->height()+y());
336 }
337}
338
339
349{
350 if ( ! restore ) {
351 minimize( true );
352 }
353 else {
354 if( _maximizedWidget ) _maximizedWidget->show();
355 if( _minimizedWidget ) _minimizedWidget->hide();
357 setup();
358 }
359}
360
371{
372 if ( ! minimize ) {
373 restore( true );
374 }
375 else {
376 if( _minimizedWidget ) _minimizedWidget->show();
377 if( _maximizedWidget ) _maximizedWidget->hide();
379 setup();
380 }
381}
382
383TQPixmap KDGanttSemiSizingControl::pixmap( Direction direction ) {
384 int s = 10;
385 TQPixmap pix( s, s );
386 pix.fill( blue );
387
388 TQPointArray arr;
389 switch ( direction ) {
390 case Up: arr.setPoints( 3, 0, s-1, s-1, s-1, 0, s/2 ); ;break;
391 case Down: arr.setPoints( 3, 0, 0, s-1, 0, s/2, s-1 ); break;
392 case Left: arr.setPoints( 3, s-1, 0, s-1, s-1, 0, s/2 ); break;
393 case Right: arr.setPoints( 3, 0,0, s-1, s/2, 0, s-1 ); break;
394 }
395
396 TQPainter p( &pix );
397 p.setPen( black );
398 p.setBrush( colorGroup().button() );
399 p.drawPolygon( arr );
400 TQBitmap bit( s, s );
401 bit.fill( color0 );
402
403 TQPainter p2( &bit );
404 p2.setPen( color1 );
405 p2.setBrush( color1 );
406 p2.drawPolygon( arr );
407 pix.setMask( bit );
408 return pix;
409}
410
411#ifndef KDGANTT_MASTER_CVS
412#include "KDGanttSemiSizingControl.moc"
413#endif
virtual void restore(bool restore)
TQt::Orientation orientation() const
void setArrowPosition(ArrowPosition arrowPosition)
KDGanttSemiSizingControl(TQWidget *parent=0, const char *name=0)
void setOrientation(TQt::Orientation orientation)
void setMaximizedWidget(TQWidget *widget)
virtual void minimize(bool minimize)
void setMinimizedWidget(TQWidget *widget)
virtual void minimize(bool minimize)
virtual void restore(bool restore)