summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/KDGanttMinimizeSplitter.cpp14
-rw-r--r--microkde/KDGanttMinimizeSplitter.h1
2 files changed, 11 insertions, 4 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp
index 84edc0d..c60b566 100644
--- a/microkde/KDGanttMinimizeSplitter.cpp
+++ b/microkde/KDGanttMinimizeSplitter.cpp
@@ -1,473 +1,479 @@
/* -*- 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 >= 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 );
+ mMouseDown = false;
//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();
+ mMouseDown = true;
+ repaint();
updateCursor( e->pos() );
}
}
void KDGanttSplitterHandle::updateCursor( const QPoint& p)
{
if ( onButton( p ) != 0 ) {
setCursor( arrowCursor );
}
else {
if ( orient == KDGanttMinimizeSplitter::Horizontal )
setCursor( splitHCursor );
else
setCursor( splitVCursor );
}
}
void KDGanttSplitterHandle::toggle()
{
int pos;
int min, max;
if ( !_collapsed ) {
s->expandPos( id(), &min, &max );
if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left
|| s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) {
pos = min;
}
else {
pos = max;
}
_origPos = s->pick(mapToParent( QPoint( 0,0 ) ));
s->moveSplitter( pos, id() );
_collapsed = true;
}
else {
s->moveSplitter( _origPos, id() );
_collapsed = false;
}
repaint();
}
void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e )
{
+ mMouseDown = false;
if ( _activeButton != 0 ) {
if ( onButton( e->pos() ) == _activeButton )
{
toggle();
}
_activeButton = 0;
updateCursor( e->pos() );
}
else {
if ( !opaque() && e->button() == LeftButton ) {
QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
- mouseOffset;
s->setRubberband( -1 );
s->moveSplitter( pos, id() );
}
}
repaint();
}
int KDGanttSplitterHandle::onButton( const QPoint& p )
{
QValueList<QPointArray> list = buttonRegions();
int index = 1;
int add = 12;
for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) {
QRect rect = (*it).boundingRect();
rect.setLeft( rect.left()- add );
rect.setRight( rect.right() + add);
rect.setTop( rect.top()- add );
rect.setBottom( rect.bottom() + add);
if ( rect.contains( p ) ) {
return index;
}
index++;
}
return 0;
}
QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions()
{
QValueList<QPointArray> list;
int sw = 8;
int yyy = 1;
int xxx = 1;
int voffset[] = { (int) -sw*3, (int) sw*3 };
for ( int i = 0; i < 2; i++ ) {
QPointArray arr;
if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ||
_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) {
int mid = height()/2 + voffset[i];
arr.setPoints( 3,
1-xxx, mid - sw + 4,
sw-3-xxx, mid,
1-xxx, mid + sw -4);
}
else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left ||
_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) {
int mid = height()/2 + voffset[i];
arr.setPoints( 3,
sw-4, mid - sw + 4,
0, mid,
sw-4, mid + sw - 4);
}
else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ||
_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) {
int mid = width()/2 + voffset[i];
arr.setPoints( 3,
mid - sw + 4, sw-4,
mid, 0,
mid + sw - 4, sw-4 );
}
else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down ||
_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) {
int mid = width()/2 + voffset[i];
arr.setPoints( 3,
mid - sw + 4, 1-yyy,
mid, sw-3-yyy,
mid + sw -4, 1-yyy);
}
list.append( arr );
}
return list;
}
void KDGanttSplitterHandle::paintEvent( QPaintEvent * )
{
QPixmap buffer( size() );
QPainter p( &buffer );
//LR
// Draw the splitter rectangle
p.setBrush( colorGroup().background() );
p.setPen( colorGroup().foreground() );
//p.drawRect( rect() );
buffer.fill( colorGroup().background() );
//buffer.fill( backgroundColor() );
// parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup());
int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size
// arrow color
QColor col;
if ( _activeButton )
col = colorGroup().background().dark( 250 );
- else
- col = colorGroup().background().dark( 150 );
+ else {
+ if ( mMouseDown )
+ col = Qt::white;
+ else
+ col = colorGroup().background().dark( 150 );
+ }
//QColor col = backgroundColor().dark( 130 );
p.setBrush( col );
p.setPen( col );
QValueList<QPointArray> list = buttonRegions();
int index = 1;
if ( mUseOffset )
p.translate( 0, 1 );
for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) {
if ( index == _activeButton ) {
/*
if ( ! _collapsed ) {
p.save();
// p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ),
// parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) );
p.translate( -1, 0 );
p.drawPolygon( *it, true );
p.restore(); } else
*/
p.drawPolygon( *it, true );
}
else {
/*
if ( ! _collapsed ) {
p.save();
p.translate( -1, 0 );
p.drawPolygon( *it, true );
p.restore();
} else
*/
p.drawPolygon( *it, true );
}
index++;
}
// Draw the lines between the arrows
if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left ||
s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) {
int mid = height()/2;
p.drawLine ( 1, mid - sw, 1, mid + sw );
p.drawLine ( 3, mid - sw, 3, mid + sw );
}
else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up ||
s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) {
int mid = width()/2;
p.drawLine( mid -sw, 1, mid +sw, 1 );
p.drawLine( mid -sw, 3, mid +sw, 3 );
}
bitBlt( this, 0, 0, &buffer );
}
#endif
class QSplitterLayoutStruct
{
public:
KDGanttMinimizeSplitter::ResizeMode mode;
QCOORD sizer;
bool isSplitter;
QWidget *wid;
};
class QSplitterData
{
public:
QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {}
QPtrList<QSplitterLayoutStruct> list;
bool opaque;
bool firstShow;
};
void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos,
int space, int spacer );
#endif // DOXYGEN_SKIP_INTERNAL
/*!
\class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h
\brief The KDGanttMinimizeSplitter class implements a splitter
widget with minimize buttons.
This class (and its documentation) is largely a copy of Qt's
QSplitter; the copying was necessary because QSplitter is not
extensible at all. QSplitter and its documentation are licensed
according to the GPL and the Qt Professional License (if you hold
such a license) and are (C) Trolltech AS.
A splitter lets the user control the size of child widgets by
dragging the boundary between the children. Any number of widgets
may be controlled.
To show a QListBox, a QListView and a QTextEdit side by side:
\code
KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent );
QListBox *lb = new QListBox( split );
QListView *lv = new QListView( split );
QTextEdit *ed = new QTextEdit( split );
\endcode
In KDGanttMinimizeSplitter, the boundary can be either horizontal or
vertical. The default is horizontal (the children are side by side)
but you can use setOrientation( QSplitter::Vertical ) to set it to
vertical.
Use setResizeMode() to specify
that a widget should keep its size when the splitter is resized.
Although KDGanttMinimizeSplitter normally resizes the children only
at the end of a resize operation, if you call setOpaqueResize( TRUE
) the widgets are resized as often as possible.
The initial distribution of size between the widgets is determined
by the initial size of each widget. You can also use setSizes() to
set the sizes of all the widgets. The function sizes() returns the
sizes set by the user.
If you hide() a child, its space will be distributed among the other
children. It will be reinstated when you show() it again. It is also
possible to reorder the widgets within the splitter using
moveToFirst() and moveToLast().
*/
static QSize minSize( const QWidget* /*w*/ )
{
return QSize(0,0);
}
// This is the original version of minSize
static QSize minSizeHint( const QWidget* w )
{
QSize min = w->minimumSize();
QSize s;
if ( min.height() <= 0 || min.width() <= 0 )
s = w->minimumSizeHint();
if ( min.height() > 0 )
s.setHeight( min.height() );
if ( min.width() > 0 )
s.setWidth( min.width() );
return s.expandedTo(QSize(0,0));
}
/*!
Constructs a horizontal splitter with the \a parent and \a
name arguments being passed on to the QFrame constructor.
*/
KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name )
:QFrame(parent,name,WPaintUnclipped)
{
mFirstHandle = 0;
#if QT_VERSION >= 232
orient = Horizontal;
init();
#endif
}
/*!
Constructs a splitter with orientation \a o with the \a parent
and \a name arguments being passed on to the QFrame constructor.
*/
KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name )
:QFrame(parent,name,WPaintUnclipped)
{
mFirstHandle = 0;
#if QT_VERSION >= 232
orient = o;
init();
#endif
}
/*!
Destroys the splitter and any children.
*/
KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter()
{
#if QT_VERSION >= 232
data->list.setAutoDelete( TRUE );
delete data;
#endif
}
#if QT_VERSION >= 232
void KDGanttMinimizeSplitter::init()
diff --git a/microkde/KDGanttMinimizeSplitter.h b/microkde/KDGanttMinimizeSplitter.h
index 8120d14..84d3d8e 100644
--- a/microkde/KDGanttMinimizeSplitter.h
+++ b/microkde/KDGanttMinimizeSplitter.h
@@ -1,188 +1,189 @@
/* -*- Mode: C++ -*-
$Id$
*/
/****************************************************************************
** Copyright (C) 2001-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.
**
**********************************************************************/
#ifndef KDGANTTMINIMIZESPLITTER_H
#define KDGANTTMINIMIZESPLITTER_H
#ifndef QT_H
#include "qframe.h"
#include "qvaluelist.h"
#endif // QT_H
#ifndef QT_NO_SPLITTER___
class QSplitterData;
class QSplitterLayoutStruct;
class KDGanttSplitterHandle;
class KDGanttMinimizeSplitter : public QFrame
{
Q_OBJECT
// Q_ENUMS( Direction )
// Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
// Q_PROPERTY( Direction minimizeDirection READ minimizeDirection WRITE setMinimizeDirection )
public:
enum ResizeMode { Stretch, KeepSize, FollowSizeHint };
enum Direction { Left, Right, Up, Down };
KDGanttMinimizeSplitter( QWidget* parent=0, const char* name=0 );
KDGanttMinimizeSplitter( Orientation, QWidget* parent=0, const char* name=0 );
~KDGanttMinimizeSplitter();
virtual void setOrientation( Orientation );
Orientation orientation() const { return orient; }
void setMinimizeDirection( Direction );
Direction minimizeDirection() const;
#if QT_VERSION >= 232
virtual void setResizeMode( QWidget *w, ResizeMode );
virtual void setOpaqueResize( bool = TRUE );
bool opaqueResize() const;
void moveToFirst( QWidget * );
void moveToLast( QWidget * );
void refresh() { recalc( TRUE ); }
QSize sizeHint() const;
QSize minimumSizeHint() const;
QValueList<int> sizes() const;
void setSizes( QValueList<int> );
KDGanttSplitterHandle* firstHandle(){ return mFirstHandle;}
void expandPos( int id, int* min, int* max );
public slots:
void toggle();
protected:
void childEvent( QChildEvent * );
bool event( QEvent * );
void resizeEvent( QResizeEvent * );
int idAfter( QWidget* ) const;
void moveSplitter( QCOORD pos, int id );
virtual void drawSplitter( QPainter*, QCOORD x, QCOORD y,
QCOORD w, QCOORD h );
void styleChange( QStyle& );
int adjustPos( int , int );
virtual void setRubberband( int );
void getRange( int id, int*, int* );
private:
void init();
void recalc( bool update = FALSE );
void doResize();
void storeSizes();
void processChildEvents();
QSplitterLayoutStruct *addWidget( QWidget*, bool first = FALSE );
void recalcId();
void moveBefore( int pos, int id, bool upLeft );
void moveAfter( int pos, int id, bool upLeft );
void setG( QWidget *w, int p, int s, bool isSplitter = FALSE );
QCOORD pick( const QPoint &p ) const
{ return orient == Horizontal ? p.x() : p.y(); }
QCOORD pick( const QSize &s ) const
{ return orient == Horizontal ? s.width() : s.height(); }
QCOORD trans( const QPoint &p ) const
{ return orient == Vertical ? p.x() : p.y(); }
QCOORD trans( const QSize &s ) const
{ return orient == Vertical ? s.width() : s.height(); }
KDGanttSplitterHandle* mFirstHandle;
QSplitterData *data;
#endif
private:
Orientation orient;
Direction _direction;
#ifndef DOXYGEN_SKIP_INTERNAL
friend class KDGanttSplitterHandle;
#endif
private: // Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
KDGanttMinimizeSplitter( const KDGanttMinimizeSplitter & );
KDGanttMinimizeSplitter& operator=( const KDGanttMinimizeSplitter & );
#endif
};
#ifndef DOXYGEN_SKIP_INTERNAL
// This class was continued from a verbatim copy of the
// QSplitterHandle pertaining to the Qt Enterprise License and the
// GPL. It has only been renamed to KDGanttSplitterHandler in order to
// avoid a symbol clash on some platforms.
class KDGanttSplitterHandle : public QWidget
{
Q_OBJECT
#if QT_VERSION >= 232
public:
KDGanttSplitterHandle( Qt::Orientation o,
KDGanttMinimizeSplitter *parent, const char* name=0 );
void setOrientation( Qt::Orientation o );
Qt::Orientation orientation() const { return orient; }
bool opaque() const { return s->opaqueResize(); }
QSize sizeHint() const;
void toggle();
int id() const { return myId; } // data->list.at(id())->wid == this
void setId( int i ) { myId = i; }
protected:
QValueList<QPointArray> buttonRegions();
void paintEvent( QPaintEvent * );
void mouseMoveEvent( QMouseEvent * );
void mousePressEvent( QMouseEvent * );
void mouseReleaseEvent( QMouseEvent * );
int onButton( const QPoint& p );
void updateCursor( const QPoint& p );
private:
+ bool mMouseDown;
QSize mSizeHint;
bool mUseOffset;
Qt::Orientation orient;
bool opaq;
int myId;
KDGanttMinimizeSplitter *s;
int _activeButton;
bool _collapsed;
int _origPos;
#endif
};
#endif
#endif // QT_NO_SPLITTER
#endif // KDGANTTMINIMIZESPLITTER_H