summaryrefslogtreecommitdiffabout
path: root/microkde/KDGanttMinimizeSplitter.cpp
Side-by-side diff
Diffstat (limited to 'microkde/KDGanttMinimizeSplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/KDGanttMinimizeSplitter.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp
index 60b8bc7..567ae54 100644
--- a/microkde/KDGanttMinimizeSplitter.cpp
+++ b/microkde/KDGanttMinimizeSplitter.cpp
@@ -1,136 +1,136 @@
/* -*- Mode: C++ -*-
$Id$
*/
/****************************************************************************
** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
**
** This file is part of the KDGantt library.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid commercial KDGantt licenses may use this file in
** accordance with the KDGantt Commercial License Agreement provided with
** the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
** information about KDGantt Commercial License Agreements.
**
** Contact info@klaralvdalens-datakonsult.se if any conditions of this
** licensing are not clear to you.
**
** As a special exception, permission is given to link this program
** with any edition of Qt, and distribute the resulting executable,
** without including the source code for Qt in the source distribution.
**
**********************************************************************/
#include "KDGanttMinimizeSplitter.h"
#ifndef QT_NO_SPLITTER___
#include "qpainter.h"
#include "qdrawutil.h"
-#include "qbitmap.h"
-#if QT_VERSION >= 300
+#include "qbitmap.h"
+#if QT_VERSION >= 0x030000
#include "qptrlist.h"
#include "qmemarray.h"
#else
#include <qlist.h>
#include <qarray.h>
#define QPtrList QList
#define QMemArray QArray
#endif
#include "qlayoutengine_p.h"
#include "qobjectlist.h"
#include "qstyle.h"
#include "qapplication.h" //sendPostedEvents
#include <qvaluelist.h>
#include <qcursor.h>
#ifndef KDGANTT_MASTER_CVS
//#include "KDGanttMinimizeSplitter.moc"
#endif
#ifndef DOXYGEN_SKIP_INTERNAL
#if QT_VERSION >= 232
static int mouseOffset;
static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky
KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o,
KDGanttMinimizeSplitter *parent, const char * name )
: QWidget( parent, name ), _activeButton( 0 ), _collapsed( false )
{
if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) {
mSizeHint = QSize(7,7);
mUseOffset = true;
} else {
mSizeHint = QSize(6,6);
mUseOffset = false;
}
s = parent;
setOrientation(o);
setMouseTracking( true );
//setMaximumHeight( 5 ); // test only
}
QSize KDGanttSplitterHandle::sizeHint() const
{
return mSizeHint;
}
void KDGanttSplitterHandle::setOrientation( Qt::Orientation o )
{
orient = o;
#ifndef QT_NO_CURSOR
if ( o == KDGanttMinimizeSplitter::Horizontal )
setCursor( splitHCursor );
else
setCursor( splitVCursor );
#endif
}
void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e )
{
updateCursor( e->pos() );
if ( !(e->state()&LeftButton) )
return;
if ( _activeButton != 0)
return;
QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
- mouseOffset;
if ( true /*opaque()*/ ) {
s->moveSplitter( pos, id() );
} else {
int min = pos; int max = pos;
s->getRange( id(), &min, &max );
s->setRubberband( QMAX( min, QMIN(max, pos )));
}
_collapsed = false;
}
void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e )
{
if ( e->button() == LeftButton ) {
_activeButton = onButton( e->pos() );
mouseOffset = s->pick(e->pos());
if ( _activeButton != 0)
repaint();
updateCursor( e->pos() );
}
}
void KDGanttSplitterHandle::updateCursor( const QPoint& p)
{
@@ -534,193 +534,193 @@ QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool firs
QSplitterLayoutStruct *s;
KDGanttSplitterHandle *newHandle = 0;
if ( data->list.count() > 0 ) {
s = new QSplitterLayoutStruct;
s->mode = KeepSize;
QString tmp = "qt_splithandle_";
tmp += w->name();
newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() );
if ( ! mFirstHandle )
mFirstHandle = newHandle;
s->wid = newHandle;
newHandle->setId(data->list.count());
s->isSplitter = TRUE;
s->sizer = pick( newHandle->sizeHint() );
if ( first )
data->list.insert( 0, s );
else
data->list.append( s );
}
s = new QSplitterLayoutStruct;
s->mode = Stretch;
s->wid = w;
if ( !testWState( WState_Resized ) && w->sizeHint().isValid() )
s->sizer = pick( w->sizeHint() );
else
s->sizer = pick( w->size() );
s->isSplitter = FALSE;
if ( first )
data->list.insert( 0, s );
else
data->list.append( s );
if ( newHandle && isVisible() )
newHandle->show(); //will trigger sending of post events
return s;
}
/*!
Tells the splitter that a child widget has been inserted or removed.
The event is passed in \a c.
*/
void KDGanttMinimizeSplitter::childEvent( QChildEvent *c )
{
if ( c->type() == QEvent::ChildInserted ) {
if ( !c->child()->isWidgetType() )
return;
if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) )
return;
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->wid == c->child() )
return;
s = data->list.next();
}
addWidget( (QWidget*)c->child() );
recalc( isVisible() );
} else if ( c->type() == QEvent::ChildRemoved ) {
QSplitterLayoutStruct *p = 0;
if ( data->list.count() > 1 )
p = data->list.at(1); //remove handle _after_ first widget.
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->wid == c->child() ) {
data->list.removeRef( s );
delete s;
if ( p && p->isSplitter ) {
data->list.removeRef( p );
delete p->wid; //will call childEvent
delete p;
}
recalcId();
doResize();
return;
}
p = s;
s = data->list.next();
}
}
}
/*!
Shows a rubber band at position \a p. If \a p is negative, the
rubber band is removed.
*/
void KDGanttMinimizeSplitter::setRubberband( int p )
{
QPainter paint( this );
paint.setPen( gray );
paint.setBrush( gray );
paint.setRasterOp( XorROP );
QRect r = contentsRect();
const int rBord = 3; //Themable????
-#if QT_VERSION >= 300
+#if QT_VERSION >= 0x030000
int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this);
#else
int sw = style().splitterWidth();
#endif
if ( orient == Horizontal ) {
if ( opaqueOldPos >= 0 )
paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(),
2*rBord, r.height() );
if ( p >= 0 )
paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() );
} else {
if ( opaqueOldPos >= 0 )
paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord,
r.width(), 2*rBord );
if ( p >= 0 )
paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
}
opaqueOldPos = p;
}
/*! \reimp */
bool KDGanttMinimizeSplitter::event( QEvent *e )
{
if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) {
recalc( isVisible() );
if ( e->type() == QEvent::Show )
data->firstShow = FALSE;
}
return QWidget::event( e );
}
/*!
\obsolete
Draws the splitter handle in the rectangle described by \a x, \a y,
\a w, \a h using painter \a p.
\sa QStyle::drawPrimitive()
*/
void KDGanttMinimizeSplitter::drawSplitter( QPainter *p,
QCOORD x, QCOORD y, QCOORD w, QCOORD h )
{
#if 0
// LR
style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(),
(orientation() == Qt::Horizontal ?
QStyle::Style_Horizontal : 0));
#endif
}
/*!
Returns the id of the splitter to the right of or below the widget \a w,
or 0 if there is no such splitter
(i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end).
*/
int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const
{
QSplitterLayoutStruct *s = data->list.first();
bool seen_w = FALSE;
while ( s ) {
if ( s->isSplitter && seen_w )
return data->list.at();
if ( !s->isSplitter && s->wid == w )
seen_w = TRUE;
s = data->list.next();
}
return 0;
}
/*!
Moves the left/top edge of the splitter handle with id \a id as
close as possible to position \a p, which is the distance from the
left (or top) edge of the widget.
For Arabic and Hebrew the layout is reversed, and using this
function to set the position of the splitter might lead to
unexpected results, since in Arabic and Hebrew the position of
splitter one is to the left of the position of splitter zero.
\sa idAfter()
*/
void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id )
{
p = adjustPos( p, id );
QSplitterLayoutStruct *s = data->list.at(id);
int oldP = orient == Horizontal ? s->wid->x() : s->wid->y();
bool upLeft;
if ( false && orient == Horizontal ) {
p += s->wid->width();
upLeft = p > oldP;
} else
upLeft = p < oldP;
@@ -816,193 +816,193 @@ void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft )
if( false && orient == Horizontal ) {
pos2 = pos - dd;
pos1 = pos2 + 1;
} else {
pos1 = pos;
pos2 = pos + dd;
}
if ( upLeft ) {
setG( w, pos1, dd, TRUE );
moveAfter( pos2, id+1, upLeft );
} else {
moveAfter( pos2, id+1, upLeft );
setG( w, pos1, dd, TRUE );
}
} else {
int left = pick( w->pos() );
int right, dd,/* newRight,*/ newLeft, nextPos;
if ( false && orient == Horizontal ) {
dd = pos - left + 1;
dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
newLeft = pos-dd+1;
nextPos = newLeft - 1;
} else {
right = pick( w->geometry().bottomRight() );
dd = right - pos + 1;
dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
/*newRight = pos+dd-1;*/
newLeft = pos;
nextPos = newLeft + dd;
}
setG( w, newLeft, dd, TRUE );
/*if( right != newRight )*/
moveAfter( nextPos, id+1, upLeft );
}
}
void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max )
{
QSplitterLayoutStruct *s = data->list.at(id-1);
QWidget* w = s->wid;
*min = pick( w->mapToParent( QPoint(0,0) ) );
if ( (uint) id == data->list.count() ) {
pick( size() );
}
else {
QSplitterLayoutStruct *s = data->list.at(id+1);
QWidget* w = s->wid;
*max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8;
}
}
/*!
Returns the valid range of the splitter with id \a id in \a *min and \a *max.
\sa idAfter()
*/
void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max )
{
int minB = 0; //before
int maxB = 0;
int minA = 0;
int maxA = 0; //after
int n = data->list.count();
if ( id < 0 || id >= n )
return;
int i;
for ( i = 0; i < id; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
if ( s->wid->isHidden() ) {
//ignore
} else if ( s->isSplitter ) {
minB += s->sizer;
maxB += s->sizer;
} else {
minB += pick( minSize(s->wid) );
maxB += pick( s->wid->maximumSize() );
}
}
for ( i = id; i < n; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
if ( s->wid->isHidden() ) {
//ignore
} else if ( s->isSplitter ) {
minA += s->sizer;
maxA += s->sizer;
} else {
minA += pick( minSize(s->wid) );
maxA += pick( s->wid->maximumSize() );
}
}
QRect r = contentsRect();
if ( orient == Horizontal && false ) {
-#if QT_VERSION >= 300
+#if QT_VERSION >= 0x030000
int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this);
#else
int splitterWidth = style().splitterWidth();
#endif
if ( min )
*min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth;
if ( max )
*max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth;
} else {
if ( min )
*min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA );
if ( max )
*max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA );
}
}
/*!
Returns the closest legal position to \a p of the splitter with id \a id.
\sa idAfter()
*/
int KDGanttMinimizeSplitter::adjustPos( int p, int id )
{
int min = 0;
int max = 0;
getRange( id, &min, &max );
p = QMAX( min, QMIN( p, max ) );
return p;
}
void KDGanttMinimizeSplitter::doResize()
{
QRect r = contentsRect();
int i;
int n = data->list.count();
QMemArray<QLayoutStruct> a( n );
for ( i = 0; i< n; i++ ) {
a[i].init();
QSplitterLayoutStruct *s = data->list.at(i);
if ( s->wid->isHidden() ) {
a[i].stretch = 0;
a[i].sizeHint = a[i].minimumSize = 0;
a[i].maximumSize = 0;
} else if ( s->isSplitter ) {
a[i].stretch = 0;
a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer;
a[i].empty = FALSE;
} else if ( s->mode == KeepSize ) {
a[i].stretch = 0;
a[i].minimumSize = pick( minSize(s->wid) );
a[i].sizeHint = s->sizer;
a[i].maximumSize = pick( s->wid->maximumSize() );
a[i].empty = FALSE;
} else if ( s->mode == FollowSizeHint ) {
a[i].stretch = 0;
a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() );
a[i].maximumSize = pick( s->wid->maximumSize() );
a[i].empty = FALSE;
} else { //proportional
a[i].stretch = s->sizer;
a[i].maximumSize = pick( s->wid->maximumSize() );
a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) );
a[i].empty = FALSE;
}
}
kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 );
for ( i = 0; i< n; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
setG( s->wid, a[i].pos, a[i].size );
}
}
void KDGanttMinimizeSplitter::recalc( bool update )
{
int fi = 2*frameWidth();
int maxl = fi;
int minl = fi;
int maxt = QWIDGETSIZE_MAX;
int mint = fi;
int n = data->list.count();
bool first = TRUE;
/*
The splitter before a hidden widget is always hidden.
The splitter before the first visible widget is hidden.
The splitter before any other visible widget is visible.
*/
for ( int i = 0; i< n; i++ ) {
@@ -1294,193 +1294,193 @@ bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const
return !w2show;
#ifdef QT_CHECK_RANGE
else
qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" );
#endif
return FALSE;
}
#endif
/*!
Returns a list of the size parameters of all the widgets in this
splitter.
Giving the values to another splitter's setSizes() function will
produce a splitter with the same layout as this one.
Note that if you want to iterate over the list, you should
iterate over a copy, e.g.
\code
QValueList<int> list = mySplitter.sizes();
QValueList<int>::Iterator it = list.begin();
while( it != list.end() ) {
myProcessing( *it );
++it;
}
\endcode
\sa setSizes()
*/
QValueList<int> KDGanttMinimizeSplitter::sizes() const
{
if ( !testWState(WState_Polished) ) {
QWidget* that = (QWidget*) this;
that->polish();
}
QValueList<int> list;
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( !s->isSplitter )
list.append( s->sizer );
s = data->list.next();
}
return list;
}
/*!
Sets the size parameters to the values given in \a list.
If the splitter is horizontal, the values set the sizes from
left to right. If it is vertical, the sizes are applied from
top to bottom.
Extra values in \a list are ignored.
If \a list contains too few values, the result is undefined
but the program will still be well-behaved.
\sa sizes()
*/
void KDGanttMinimizeSplitter::setSizes( QValueList<int> list )
{
processChildEvents();
QValueList<int>::Iterator it = list.begin();
QSplitterLayoutStruct *s = data->list.first();
while ( s && it != list.end() ) {
if ( !s->isSplitter ) {
s->sizer = *it;
++it;
}
s = data->list.next();
}
doResize();
}
/*!
Gets all posted child events, ensuring that the internal state of
the splitter is consistent.
*/
void KDGanttMinimizeSplitter::processChildEvents()
{
QApplication::sendPostedEvents( this, QEvent::ChildInserted );
}
/*!
\reimp
*/
void KDGanttMinimizeSplitter::styleChange( QStyle& old )
{
-#if QT_VERSION >= 300
+#if QT_VERSION >= 0x030000
int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this);
#else
int sw = style().splitterWidth();
#endif
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->isSplitter )
s->sizer = sw;
s = data->list.next();
}
doResize();
QFrame::styleChange( old );
}
#endif
/*!
Specifies the direction of the minimize buttons.
If the orientation of the splitter is horizontal then with
KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used,
otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down
should be used.
*/
void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction )
{
_direction = direction;
}
/*!
Returns the direction of the minimize buttons.
*/
KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const
{
return _direction;
}
/*
This is a copy of qGeomCalc() in qlayoutengine.cpp which
unfortunately isn't exported.
*/
static inline int toFixed( int i ) { return i * 256; }
static inline int fRound( int i ) {
return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256;
}
void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos,
int space, int spacer )
{
typedef int fixed;
int cHint = 0;
int cMin = 0;
int cMax = 0;
int sumStretch = 0;
int spacerCount = 0;
bool wannaGrow = FALSE; // anyone who really wants to grow?
// bool canShrink = FALSE; // anyone who could be persuaded to shrink?
int i;
for ( i = start; i < start + count; i++ ) {
chain[i].done = FALSE;
cHint += chain[i].sizeHint;
cMin += chain[i].minimumSize;
cMax += chain[i].maximumSize;
sumStretch += chain[i].stretch;
if ( !chain[i].empty )
spacerCount++;
wannaGrow = wannaGrow || chain[i].expansive;
}
int extraspace = 0;
if ( spacerCount )
spacerCount--; // only spacers between things
if ( space < cMin + spacerCount * spacer ) {
// qDebug("not enough space");
for ( i = start; i < start+count; i++ ) {
chain[i].size = chain[i].minimumSize;
chain[i].done = TRUE;
}
} else if ( space < cHint + spacerCount*spacer ) {
// Less space than sizeHint, but more than minimum.
// Currently take space equally from each, like in Qt 2.x.
// Commented-out lines will give more space to stretchier items.
int n = count;
int space_left = space - spacerCount*spacer;
int overdraft = cHint - space_left;
//first give to the fixed ones:
for ( i = start; i < start+count; i++ ) {
if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) {
chain[i].size = chain[i].sizeHint;
chain[i].done = TRUE;
space_left -= chain[i].sizeHint;
// sumStretch -= chain[i].stretch;
n--;
}
}
bool finished = n == 0;