summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--korganizer/komonthview.cpp2
-rw-r--r--microkde/KDGanttMinimizeSplitter.cpp21
-rw-r--r--microkde/KDGanttMinimizeSplitter.h5
3 files changed, 22 insertions, 6 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 7927307..8ee1363 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -389,769 +389,769 @@ void MonthViewItem::paint(QPainter *p)
p->drawLine ( x, heihei/2, x +half , heihei/2 +half ) ;
p->drawLine ( x +half , heihei/2 +half , x +half+half +2 , heihei/2 -2 ) ;
x += half+half + 4;
} else {
int val = td->percentComplete()/20;
p->fillRect ( x+1, y-2, val ,size+4,Qt::black );
p->drawRect ( x, y-2,7,size+4);
x += size + 3;
}
}
QFontMetrics fm = p->fontMetrics();
int yPos;
int pmheight = size;
if( pmheight < fm.height() )
yPos = fm.ascent() + fm.leading()/2;
else
yPos = pmheight/2 - fm.height()/2 + fm.ascent();
p->setPen( palette().color( QPalette::Normal, sel ? \
QColorGroup::HighlightedText : QColorGroup::Foreground ) );
if ( KOPrefs::instance()->mMonthShowTimes || isWeekItem) {
p->drawText( x, yPos, text() );
if ( mIncidence->cancelled() ) {
int wid = fm.width( text() );
p->drawLine( x, heihei/2 ,x+wid, heihei/2 );
}
} else {
QString pText = text();
if( pText.mid(2,1) == ":" )
pText = pText.mid( 6 );
p->drawText( x, yPos, pText );
if ( mIncidence->cancelled() ) {
int wid = fm.width( pText );
p->drawLine( x, heihei/2 ,x+wid, heihei/2 );
}
}
}
int MonthViewItem::height(const QListBox *lb) const
{
int ret = 10;
if ( lb )
ret = lb->fontMetrics().lineSpacing()+1;
return ret;
}
int MonthViewItem::width(const QListBox *lb) const
{
if( KOPrefs::instance()->mEnableMonthScroll || isWeekItem ) {
int size = PIXMAP_SIZE;
if ( QApplication::desktop()->width() < 300 )
size = 3;
int x = 1;
if ( KOPrefs::instance()->mMonthShowIcons ) {
if ( mInfo ) {
x += size + 1;
}
if( mRecur ) {
x += size+1;
}
if( mAlarm ) {
x += size+1;
}
if( mReply ) {
x += size+1;
}
}
if( mMultiday ) {
x += size+1+2+size/2;
}
return( x + lb->fontMetrics().width( text() ) + 1 );
}
if ( ! lb )
return 10;
return lb->width();
}
MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par )
: KNoScrollListBox( par ),
mMonthView( parent )
{
//QVBoxLayout *topLayout = new QVBoxLayout( this );
currentPalette = 0;
// mLabel = new QLabel( this );QPushButton
mLabel = new QPushButton( this );
//mLabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
//mLabel->setLineWidth( 1 );
//mLabel->setAlignment( AlignCenter );
mLabel->setFlat( true );
mLabel->setFocusPolicy(NoFocus);
//mItemList = new KNoScrollListBox( this );
setMinimumSize( 10, 10 );
setFrameStyle( QFrame::Panel | QFrame::Plain );
setLineWidth( 1 );
//topLayout->addWidget( mItemList );
mLabel->raise();
// QColor( 0,0,255 ) QColor( 160,1600,255 )
mStandardPalette = palette();
mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) );
enableScrollBars( false );
updateConfig();
//connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() ));
connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() ));
connect( this , SIGNAL( doubleClicked( QListBoxItem *) ),
SLOT( defaultAction( QListBoxItem * ) ) );
connect( this, SIGNAL( rightButtonPressed( QListBoxItem *,
const QPoint &) ),
SLOT( contextMenu( QListBoxItem * ) ) );
connect( this, SIGNAL( highlighted( QListBoxItem *) ),
SLOT( selection( QListBoxItem * ) ) );
/*
connect( this, SIGNAL( clicked( QListBoxItem * ) ),
SLOT( selection( QListBoxItem * ) ) );
*/
}
#ifdef DESKTOP_VERSION
QToolTipGroup *MonthViewCell::toolTipGroup()
{
if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
return mToolTipGroup;
}
#endif
void MonthViewCell::setDate( const QDate &date )
{
// kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl;
mDate = date;
//resizeEvent( 0 );
}
QDate MonthViewCell::date() const
{
return mDate;
}
void MonthViewCell::setPrimary( bool primary )
{
mPrimary = primary;
//setMyPalette();
}
void MonthViewCell::setMyPalette()
{
if ( mHoliday) {
if ( currentPalette == 1 ) return;
mLabel->setPalette( QPalette ( mHolidayPalette.color( QPalette::Normal,QColorGroup::Base),mHolidayPalette.color(QPalette::Normal,QColorGroup::Base ) ));
setPalette( mHolidayPalette );
//mLabel->setPalette( mHolidayPalette );
currentPalette = 1;
} else {
if ( mPrimary ) {
if ( currentPalette == 2 ) return;
mLabel->setPalette( QPalette ( mPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
//mLabel->setPalette( mPrimaryPalette );
setPalette( mPrimaryPalette );
currentPalette = 2;
} else {
if ( currentPalette == 3 ) return;
setPalette( mNonPrimaryPalette );
mLabel->setPalette( QPalette ( mNonPrimaryPalette.color( QPalette::Normal,QColorGroup::Base),mNonPrimaryPalette.color(QPalette::Normal,QColorGroup::Base ) ));
//mLabel->setPalette( mNonPrimaryPalette );;
currentPalette = 3;
}
}
//QPalette pal = palette();
//mLabel->setPalette( QPalette ( pal.color( QPalette::Normal,QColorGroup::Base),pal.color(QPalette::Normal,QColorGroup::Base ) ));
}
QPalette MonthViewCell::getPalette ()
{
if ( !KOPrefs::instance()->mMonthViewUsesDayColors )
return mStandardPalette;
if ( mHoliday) {
return mHolidayPalette ;
} else {
if ( mPrimary ) {
return mPrimaryPalette ;
}
}
return mNonPrimaryPalette;
}
bool MonthViewCell::isPrimary() const
{
return mPrimary;
}
void MonthViewCell::setHoliday( bool holiday )
{
mHoliday = holiday;
//setMyPalette();
}
void MonthViewCell::setHoliday( const QString &holiday )
{
mHolidayString = holiday;
if ( !holiday.isEmpty() ) {
setHoliday( true );
}
}
void MonthViewCell::startUpdateCell()
{
mdayCount = 0;
setFocusPolicy(NoFocus);
if ( !mMonthView->isUpdatePossible() )
return;
MonthViewItem *mitem = (MonthViewItem*) firstItem ();
while ( mitem ) {
mitem->setBlockRepaint( true );
mitem = (MonthViewItem *)mitem->next();
}
if ( mAvailItemList.count() > 20 ) {
mAvailItemList.setAutoDelete( true );
mAvailItemList.clear();
mAvailItemList.setAutoDelete( false );
}
setPrimary( mDate.month()%2 );
setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays);
if ( mDate == QDate::currentDate() ) {
setLineWidth( 3 );
} else {
setLineWidth( 1 );
}
MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem ();
//clear();
while ( CurrentAvailItem ) {
MonthViewItem *item = CurrentAvailItem;
CurrentAvailItem = (MonthViewItem *)item->next();
mAvailItemList.append( item );
takeItem ( item );
}
#ifdef DESKTOP_VERSION
QToolTip::remove(this);
#endif
mToolTip.clear();
//qApp->processEvents();
#if 0
if ( !mHolidayString.isEmpty() ) {
MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString );
item->setPalette( mHolidayPalette );
insertItem( item );
mToolTip.append ( mHolidayString );
}
#endif
}
int MonthViewCell::insertEvent(Event *event)
{
bool useToolTips = true;
#ifndef DESKTOP_VERSION
useToolTips = false;
#endif
QString mToolTipText;
setFocusPolicy(WheelFocus);
if ( !(event->doesRecur() == Recurrence::rNone) ) {
if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily )
return mdayCount;
else
if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly )
return mdayCount;
}
if ( event->isHoliday()) {
setHoliday( true );
if ( mDate.dayOfWeek() == 7 )
setLineWidth( 3 );
}
QString text;
int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
if (event->isMultiDay()) {
QString prefix = "<->";multiday = 2;
QString time;
if ( event->doesRecur() ) {
if ( event->recursOn( mDate) ) {
prefix ="->" ;multiday = 1;
}
else {
int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
if ( event->recursOn( mDate.addDays( -days)) ) {
prefix ="<-" ;multiday = 3;
}
}
} else {
if (mDate == event->dtStart().date()) {
prefix ="->" ;multiday = 1;
} else if (mDate == event->dtEnd().date()) {
prefix ="<-" ;multiday = 3;
}
}
if ( !event->doesFloat() ) {
if ( mDate == event->dtStart().date () )
time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
else if ( mDate == event->dtEnd().date () )
time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
}
text = time + event->summary();
if ( useToolTips )
mToolTipText += prefix + text;
} else {
if (event->doesFloat()) {
text = event->summary();
if ( useToolTips )
mToolTipText += text;
}
else {
text = KGlobal::locale()->formatTime(event->dtStart().time());
text += " " + event->summary();
if ( useToolTips )
mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
}
}
if ( useToolTips && ! event->location().isEmpty() ) {
mToolTipText += " (" + event->location() +")";
}
MonthViewItem *item ;
if ( mAvailItemList.count() ) {
item = mAvailItemList.first();
mAvailItemList.remove( item );
item->recycle( event, mDate, text );
} else {
item = new MonthViewItem( event, mDate, text );
}
QPalette pal;
if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
QStringList categories = event->categories();
QString cat = categories.first();
if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
pal = getPalette();
if (cat.isEmpty()) {
pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
} else {
pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
}
} else {
if (cat.isEmpty()) {
pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
} else {
pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
}
}
} else {
pal = mStandardPalette ;
}
item->setPalette( pal );
item->setRecur( event->recurrence()->doesRecur() );
item->setAlarm( event->isAlarmEnabled() && multiday < 2 );
item->setMoreInfo( event->description().length() > 0 );
#ifdef DESKTOP_VERSION
Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails,
KOPrefs::instance()->email());
if ( me != 0 ) {
if ( me->status() == Attendee::NeedsAction && me->RSVP())
item->setReply(true && multiday < 2);
else
item->setReply(false);
} else
item->setReply(false);
#endif
item->setMultiDay( multiday );
if ( multiday ) {
insertItem( item ,mdayCount);
++mdayCount;
} else {
uint i;
int pos = mdayCount;
for ( i = mdayCount; i < count();++i ) {
QListBoxItem* it = this->item ( i );
- if ( text < it->text() ) {
+ if ( it && text < it->text() ) {
pos = i;
break;
}
++pos;
}
insertItem( item ,pos);
}
if ( useToolTips ) {
mToolTip.append( mToolTipText );
}
return mdayCount;
}
void MonthViewCell::insertTodo(Todo *todo)
{
setFocusPolicy(WheelFocus);
QString text;
if (todo->hasDueDate()) {
if (!todo->doesFloat()) {
text += KGlobal::locale()->formatTime(todo->dtDue().time());
text += " ";
}
}
text += todo->summary();
MonthViewItem *item ;
if ( mAvailItemList.count() ) {
item = mAvailItemList.first();
mAvailItemList.remove( item );
item->recycle( todo, mDate, text );
} else {
item = new MonthViewItem( todo, mDate, text );
}
//MonthViewItem *item = new MonthViewItem( todo, mDate, text );
//item->setPalette( mStandardPalette );
QPalette pal;
if (KOPrefs::instance()->mMonthViewUsesCategoryColor) {
QStringList categories = todo->categories();
QString cat = categories.first();
if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) {
pal = getPalette();
if (cat.isEmpty()) {
pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor);
} else {
pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat)));
}
} else {
if (cat.isEmpty()) {
pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor);
} else {
pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat)));
}
}
} else {
pal = mStandardPalette ;
}
item->setPalette( pal );
item->setRecur( todo->recurrence()->doesRecur() );
item->setAlarm( todo->isAlarmEnabled() );
item->setMoreInfo( todo->description().length() > 0 );
insertItem( item , count());
#ifdef DESKTOP_VERSION
mToolTip.append( text );
#endif
}
void MonthViewCell::repaintfinishUpdateCell()
{
MonthViewItem *mitem = (MonthViewItem*) firstItem ();
while ( mitem ) {
mitem->setBlockRepaint( false );
updateItem ( mitem );
mitem = (MonthViewItem *)mitem->next();
}
}
void MonthViewCell::finishUpdateCell()
{
#ifdef DESKTOP_VERSION
if (mToolTip.count() > 0 ) {
mToolTip.sort();
QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),"");
}
#endif
//sort();
//setMyPalette();
setMyPalette();
resizeEvent( 0 );
}
void MonthViewCell::updateCell()
{
if ( !mMonthView->isUpdatePossible() )
return;
startUpdateCell();
//mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
QPtrList<Event> events = mMonthView->calendar()->events( mDate, true );
Event *event;
for( event = events.first(); event; event = events.next() ) { // for event
insertEvent(event);
}
// insert due todos
QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate );
Todo *todo;
for(todo = todos.first(); todo; todo = todos.next()) {
insertTodo( todo );
}
finishUpdateCell();
// if ( isVisible())
//qApp->processEvents();
}
void MonthViewCell::updateConfig( bool bigFont ) // = false
{
if ( bigFont ) {
QFont fo = KOPrefs::instance()->mMonthViewFont;
int ps = fo.pointSize() + 2;
if ( ps < 18 )
ps += 2;
fo.setPointSize( ps );
setFont( fo );
} else
setFont( KOPrefs::instance()->mMonthViewFont );
QFontMetrics fm( font() );
mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 );
mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 );
mHolidayPalette = mStandardPalette;
mPrimaryPalette = mStandardPalette;
mNonPrimaryPalette = mStandardPalette;
if ( KOPrefs::instance()->mMonthViewUsesDayColors ) {
mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor );
mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor );
mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark());
mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark());
mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor);
mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor);
mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark());
mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor);
mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor);
}
//updateCell();
}
void MonthViewCell::enableScrollBars( bool enabled )
{
return;
if ( enabled ) {
QListBoxItem *fi = firstItem ();
if (fi ) {
int ihei = fi->height( this );
int hei = numRows () * ihei;
if ( hei < height() - horizontalScrollBar()->height () ) {
setVScrollBarMode(QScrollView::AlwaysOff);
}
else
setVScrollBarMode(QScrollView::Auto);
if ( ihei *3 > height() ) {
setHScrollBarMode(QScrollView::AlwaysOff);
}
else {
setHScrollBarMode(QScrollView::Auto);
}
} else {
setVScrollBarMode(QScrollView::Auto);
setHScrollBarMode(QScrollView::Auto);
}
} else {
setVScrollBarMode(QScrollView::AlwaysOff);
setHScrollBarMode(QScrollView::AlwaysOff);
}
}
Incidence *MonthViewCell::selectedIncidence()
{
int index = currentItem();
if ( index < 0 ) return 0;
MonthViewItem *mitem =
static_cast<MonthViewItem *>( item( index ) );
if ( !mitem ) return 0;
return mitem->incidence();
}
QDate MonthViewCell::selectedIncidenceDate()
{
QDate qd;
int index = currentItem();
if ( index < 0 ) return qd;
MonthViewItem *mitem =
static_cast<MonthViewItem *>( item( index ) );
if ( !mitem ) return qd;
return mitem->incidenceDate();
}
void MonthViewCell::deselect()
{
clearSelection();
enableScrollBars( false );
// updateCell();
}
void MonthViewCell::select()
{
;// updateCell();
}
void MonthViewCell::resizeEvent ( QResizeEvent * e )
{
if ( !mMonthView->isUpdatePossible() )
return;
//qDebug("++++++++++++++MonthViewCell::resizeEvent %d %d ", width(), height());
deselect();
mLabel->setMaximumHeight( height() - lineWidth()*2 );
QString text;
mLabel->setText( text );
bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
mLabel->resize( mLabelBigSize );
text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
} else {
mLabel->resize( mLabelSize );
text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
}
mLabel->setText( text );
int size = height() - mLabel->height() - lineWidth()-1;
//qDebug("LW %d ", lineWidth());
if ( size > 0 )
verticalScrollBar()->setMaximumHeight( size );
size = width() - mLabel->width() -lineWidth()-1;
if ( size > 0 )
horizontalScrollBar()->setMaximumWidth( size );
mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() );
//mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
// mItemList->resize ( width(), height () );
if ( e )
KNoScrollListBox::resizeEvent ( e );
}
void MonthViewCell::defaultAction( QListBoxItem *item )
{
if ( !item ) {
QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
emit newEventSignal( dt );
return;
}
MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
Incidence *incidence = eventItem->incidence();
if ( incidence ) mMonthView->defaultAction( incidence );
}
void MonthViewCell::showDay()
{
emit showDaySignal( date() );
}
void MonthViewCell::newEvent()
{
QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
emit newEventSignal( dt );
}
void MonthViewCell::cellClicked( QListBoxItem *item )
{
mMonthView->setSelectedCell( this );
if ( item == 0 ) {
QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
emit newEventSignal( dt );
return;
}
}
void MonthViewCell::contextMenu( QListBoxItem *item )
{
mMonthView->setPopupCell( this );
if ( !item ) {
mMonthView->showContextMenu( 0 );
return;
}
MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
Incidence *incidence = eventItem->incidence();
if ( incidence ) mMonthView->showContextMenu( incidence );
}
void MonthViewCell::selection( QListBoxItem *item )
{
if ( !item ) return;
mMonthView->setSelectedCell( this );
}
// *******************************************************************************
// *******************************************************************************
// *******************************************************************************
KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
: KOEventView( calendar, parent, name ),
mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
{
mFlagKeyPressed = false;
mShortDayLabelsM = false;
mShortDayLabelsW = false;
skipResize = false;
clPending = true;
mPopupCell = 0;
mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
mWidStack = new QWidgetStack( this );
QVBoxLayout* hb = new QVBoxLayout( this );
mMonthView = new QWidget( mWidStack );
mWeekView = new QWidget( mWidStack );
#if QT_VERSION >= 0x030000
mWidStack->addWidget(mMonthView );
mWidStack->addWidget(mWeekView );
#else
mWidStack->addWidget( mMonthView, 1 );
mWidStack->addWidget( mWeekView , 1 );
#endif
hb->addWidget( mNavigatorBar );
hb->addWidget( mWidStack );
mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
updatePossible = false;
//updatePossible = true;
mCells.setAutoDelete( true );
mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
mDayLabels.resize( mDaysPerWeek );
mDayLabelsW.resize( mDaysPerWeek );
QFont bfont = font();
if ( QApplication::desktop()->width() < 650 ) {
bfont.setPointSize( bfont.pointSize() - 2 );
}
bfont.setBold( true );
int i;
for( i = 0; i < mDaysPerWeek; i++ ) {
QLabel *label = new QLabel( mMonthView );
label->setFont(bfont);
label->setFrameStyle(QFrame::Panel|QFrame::Raised);
label->setLineWidth(1);
label->setAlignment(AlignCenter);
mDayLabels.insert( i, label );
label = new QLabel( mWeekView );
label->setFont(bfont);
label->setFrameStyle(QFrame::Panel|QFrame::Raised);
label->setLineWidth(1);
label->setAlignment(AlignCenter);
mDayLabelsW.insert( i, label );
}
bfont.setBold( false );
mWeekLabels.resize( mNumWeeks+1 );
mWeekLabelsW.resize( 2 );
for( i = 0; i < mNumWeeks+1; i++ ) {
KOWeekButton *label = new KOWeekButton( mMonthView );
label->setFocusPolicy(NoFocus);
label->setFont(bfont);
connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
label->setFlat(true);
QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
//label->setFrameStyle(QFrame::Panel|QFrame::Raised);
//label->setLineWidth(1);
//label->setAlignment(AlignCenter);
mWeekLabels.insert( i, label );
}
mWeekLabels[mNumWeeks]->setText( i18n("W"));
mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus);
QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
for( i = 0; i < 1+1; i++ ) {
KOWeekButton *label = new KOWeekButton( mWeekView );
label->setFocusPolicy(NoFocus);
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp
index fb5d4e3..72c4e60 100644
--- a/microkde/KDGanttMinimizeSplitter.cpp
+++ b/microkde/KDGanttMinimizeSplitter.cpp
@@ -1,1068 +1,1083 @@
/* -*- 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>
+#include <qframe.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
+class KDRubberBand: public QFrame
+{
+public:
+ KDRubberBand( QWidget *parent, const char * name, WFlags f ) :QFrame ( parent, name, f ) {;}
+
+protected:
+ virtual void mousePressEvent ( QMouseEvent * )
+ {
+ close();
+ };
+
+};
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 ( 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());
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() );
}
}
- if ( s->rubberBand() )
- s->rubberBand()->hide();
+ if ( s->rubberBand() ) {
+ //qDebug("hide rubberband ");
+ s->rubberBand()->close();
+ }
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() );
#ifndef DESKTOP_VERSION
if ( mMouseDown && ! _activeButton)
buffer.fill( colorGroup().background().dark() );
else
#endif
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 {
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)
{
mRubberBand = 0;
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)
{
mRubberBand = 0;
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 ( mRubberBand )
delete mRubberBand;
}
#if QT_VERSION >= 232
void KDGanttMinimizeSplitter::init()
{
data = new QSplitterData;
if ( orient == Horizontal )
setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) );
else
setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) );
#ifndef DESKTOP_VERSION
setOpaqueResize( false );
#else
setOpaqueResize( true );
#endif
}
#endif
void KDGanttMinimizeSplitter::toggle()
{
if ( mFirstHandle )
mFirstHandle->toggle();
else
qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available ");
}
/*!
\brief the orientation of the splitter
By default the orientation is horizontal (the widgets are side by side).
The possible orientations are Qt:Vertical and Qt::Horizontal (the default).
*/
void KDGanttMinimizeSplitter::setOrientation( Orientation o )
{
#if QT_VERSION >= 232
if ( orient == o )
return;
orient = o;
if ( orient == Horizontal )
setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
else
setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->isSplitter )
((KDGanttSplitterHandle*)s->wid)->setOrientation( o );
s = data->list.next(); // ### next at end of loop, no iterator
}
recalc( isVisible() );
#endif
}
#if QT_VERSION >= 232
/*!
\reimp
*/
void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * )
{
doResize();
}
/*
Inserts the widget \a w at the end (or at the beginning if \a first
is TRUE) of the splitter's list of widgets.
It is the responsibility of the caller of this function to make sure
that \a w is not already in the splitter and to call recalcId if
needed. (If \a first is TRUE, then recalcId is very probably
needed.)
*/
QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first )
{
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 )
{
#ifdef DESKTOP_VERSION
QPainter paint( this );
paint.setPen( gray );
paint.setBrush( gray );
paint.setRasterOp( XorROP );
QRect r = contentsRect();
const int rBord = 3; //Themable????
#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;
#else
if ( !mRubberBand ) {
- mRubberBand = new QFrame( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop);
+ mRubberBand = new KDRubberBand( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop);
mRubberBand->setFrameStyle( Box | Raised );
//mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) );
mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() ));
}
QRect r = contentsRect();
static int rBord = 0; //Themable????
if ( !rBord ) {
if (QApplication::desktop()->width() <= 320 )
rBord = 3;
else
rBord = 4;
}
int sw = style().splitterWidth();
if ( orient == Horizontal ) {
if ( p >= 0 ) {
QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y()));
mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() );
}
} else {
if ( p >= 0 ) {
QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord));
mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord);
}
}
opaqueOldPos = p;
if ( ! mRubberBand->isVisible() ) {
mRubberBand->show();
}
#endif
}
/*! \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;
moveAfter( p, id, upLeft );
moveBefore( p-1, id-1, upLeft );
storeSizes();
}
void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter )
{
if ( orient == Horizontal ) {
if ( false && orient == Horizontal && !isSplitter )
p = contentsRect().width() - p - s;
w->setGeometry( p, contentsRect().y(), s, contentsRect().height() );
} else
w->setGeometry( contentsRect().x(), p, contentsRect().width(), s );
}
/*
Places the right/bottom edge of the widget at \a id at position \a pos.
\sa idAfter()
*/
void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft )
{
if( id < 0 )
return;
QSplitterLayoutStruct *s = data->list.at(id);
if ( !s )
return;
QWidget *w = s->wid;
if ( w->isHidden() ) {
moveBefore( pos, id-1, upLeft );
} else if ( s->isSplitter ) {
int pos1, pos2;
int dd = s->sizer;
if( false && orient == Horizontal ) {
pos1 = pos;
pos2 = pos + dd;
} else {
pos2 = pos - dd;
pos1 = pos2 + 1;
}
if ( upLeft ) {
setG( w, pos1, dd, TRUE );
moveBefore( pos2, id-1, upLeft );
} else {
moveBefore( pos2, id-1, upLeft );
setG( w, pos1, dd, TRUE );
}
} else {
int dd, newLeft, nextPos;
if( false && orient == Horizontal ) {
dd = w->geometry().right() - pos;
dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
newLeft = pos+1;
nextPos = newLeft + dd;
} else {
dd = pos - pick( w->pos() ) + 1;
dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
newLeft = pos-dd+1;
nextPos = newLeft - 1;
}
setG( w, newLeft, dd, TRUE );
moveBefore( nextPos, id-1, upLeft );
}
}
/*
Places the left/top edge of the widget at \a id at position \a pos.
\sa idAfter()
*/
void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft )
{
QSplitterLayoutStruct *s = id < int(data->list.count()) ?
data->list.at(id) : 0;
if ( !s )
return;
QWidget *w = s->wid;
if ( w->isHidden() ) {
moveAfter( pos, id+1, upLeft );
} else if ( pick( w->pos() ) == pos ) {
//No need to do anything if it's already there.
return;
} else if ( s->isSplitter ) {
int dd = s->sizer;
int pos1, pos2;
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 >= 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;
/*
diff --git a/microkde/KDGanttMinimizeSplitter.h b/microkde/KDGanttMinimizeSplitter.h
index 585298d..3042e0a 100644
--- a/microkde/KDGanttMinimizeSplitter.h
+++ b/microkde/KDGanttMinimizeSplitter.h
@@ -1,191 +1,192 @@
/* -*- 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 KDRubberBand;
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 );
- QFrame* rubberBand() { return mRubberBand ;}
+ KDRubberBand* rubberBand() { return mRubberBand ;}
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:
- QFrame* mRubberBand;
+ KDRubberBand* mRubberBand;
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