author | zautrix <zautrix> | 2005-03-29 00:10:48 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-29 00:10:48 (UTC) |
commit | a5d52c19d2cd9b008e5cf41d5c7d2c193df7ee46 (patch) (side-by-side diff) | |
tree | b9f1b2710da1cd0105382831ac0a3e3d7d44f09c | |
parent | 4e7c45695672ecdbd0cd14cac0ea29a8e134ee78 (diff) | |
download | kdepimpi-a5d52c19d2cd9b008e5cf41d5c7d2c193df7ee46.zip kdepimpi-a5d52c19d2cd9b008e5cf41d5c7d2c193df7ee46.tar.gz kdepimpi-a5d52c19d2cd9b008e5cf41d5c7d2c193df7ee46.tar.bz2 |
fix
-rw-r--r-- | korganizer/komonthview.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index d825493..940d288 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp @@ -1,554 +1,560 @@ /* This file is part of KOrganizer. Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <qpopupmenu.h> #include <qfont.h> #include <qfontmetrics.h> #include <qkeycode.h> #include <qhbox.h> #include <qvbox.h> #include <qwidgetstack.h> #include <qpushbutton.h> #include <qtooltip.h> #include <qpainter.h> #include <qtimer.h> #include <qwhatsthis.h> #ifndef DESKTOP_VERSION #include <qpe/qpeapplication.h> #else #include <qapplication.h> #endif #include <kdebug.h> #include <klocale.h> #include <kglobal.h> #include <kconfig.h> #include <kiconloader.h> #include <kcalendarsystem.h> #ifndef KORG_NOPRINTER #include "calprinter.h" #endif #include "koprefs.h" #ifndef KORG_NOPLUGINS #include "kocore.h" #endif #include "koglobals.h" #include <libkcal/kincidenceformatter.h> #include "komonthview.h" #define PIXMAP_SIZE 5 #ifdef DESKTOP_VERSION QToolTipGroup *MonthViewCell::mToolTipGroup = 0; #endif class KNOWhatsThis :public QWhatsThis { public: KNOWhatsThis( KNoScrollListBox* sbox ) : QWhatsThis( sbox ), _wid( sbox) { }; //~KNOWhatsThis( ) {qDebug("~KNOWhatsThis( ) "); }; protected: virtual QString text( const QPoint& p) { return _wid->getWhatsThisText(p) ; }; private: KNoScrollListBox* _wid; }; KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) : QListBox(parent, name, WRepaintNoErase) { #ifndef DESKTOP_VERSION QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); #endif mWT = new KNOWhatsThis(this); } KNoScrollListBox::~KNoScrollListBox() { } QString KNoScrollListBox::getWhatsThisText(QPoint p) { QListBoxItem* item = itemAt ( p ); if ( ! item ) { return i18n("Click in the cell\nto add an event!"); } return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence(), KOPrefs::instance()->mWTshowDetails, KOPrefs::instance()->mWTshowCreated, KOPrefs::instance()->mWTshowChanged); } void KNoScrollListBox::keyPressEvent(QKeyEvent *e) { switch(e->key()) { case Key_Right: if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { e->ignore(); return; } scrollBy(10,0); break; case Key_Left: if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { e->ignore(); return; } scrollBy(-10,0); break; case Key_Up: if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { e->ignore(); break; } - setCurrentItem((currentItem()+count()-1)%count()); - if(!itemVisible(currentItem())) { - if((unsigned int) currentItem() == (count()-1)) { - setTopItem(currentItem()-numItemsVisible()+1); - } else { - setTopItem(topItem()-1); + if ( count() ) { + setCurrentItem((currentItem()+count()-1)%count()); + if(!itemVisible(currentItem())) { + if((unsigned int) currentItem() == (count()-1)) { + setTopItem(currentItem()-numItemsVisible()+1); + } else { + setTopItem(topItem()-1); + } } } break; case Key_Down: if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { e->ignore(); break; } - setCurrentItem((currentItem()+1)%count()); - if(!itemVisible(currentItem())) { - if(currentItem() == 0) { - setTopItem(0); - } else { - setTopItem(topItem()+1); + if ( count () ) { + setCurrentItem((currentItem()+1)%count()); + if(!itemVisible(currentItem())) { + if(currentItem() == 0) { + setTopItem(0); + } else { + setTopItem(topItem()+1); + } } } break; case Key_I: QTimer::singleShot( 11, this, SLOT ( oneDown() ) ); e->ignore(); break; case Key_Shift: emit shiftDown(); break; default: e->ignore(); break; } } void KNoScrollListBox::oneDown() { - setCurrentItem((currentItem()+1)%count()); - if(!itemVisible(currentItem())) { - if(currentItem() == 0) { - setTopItem(0); - } else { - setTopItem(topItem()+1); + if ( count () ) { + setCurrentItem((currentItem()+1)%count()); + if(!itemVisible(currentItem())) { + if(currentItem() == 0) { + setTopItem(0); + } else { + setTopItem(topItem()+1); + } } } } void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) { switch(e->key()) { case Key_Shift: emit shiftUp(); break; default: break; } } void KNoScrollListBox::mousePressEvent(QMouseEvent *e) { QListBox::mousePressEvent(e); if(e->button() == RightButton) { emit rightClick(); } } MonthViewItem::MonthViewItem( Incidence *incidence, QDate qd, const QString & s) : QListBoxItem() { mblockRepaint = true; setText( s ); mMultiday = 0; mIncidence = incidence; mDate = qd; mRecur = false; mAlarm = false; mReply = false; mInfo = false; //qDebug("NEWWWWWWWWWWWWW "); } void MonthViewItem::recycle( Incidence *incidence, QDate qd, const QString & s) { setText( s ); mMultiday = 0; mIncidence = incidence; mDate = qd; mRecur = false; mAlarm = false; mReply = false; mInfo = false; //qDebug("recucleeeeeeeeeeeeeeeee "); } void MonthViewItem::paint(QPainter *p) { if ( mblockRepaint ) { //qDebug("block "); return; } //qDebug("NON block "); #if QT_VERSION >= 0x030000 bool sel = isSelected(); #else bool sel = selected(); #endif if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { p->setBackgroundColor( palette().color( QPalette::Normal, \ sel ? QColorGroup::Highlight : QColorGroup::Background ) ); p->eraseRect( 0, 0, listBox()->maxItemWidth(), height( listBox() ) ); } int x = 1; //int y = 3;//(height() - mRecurPixmap.height()) /2; int size = PIXMAP_SIZE; if ( QApplication::desktop()->width() < 300 ) size = 3; int heihei = height( listBox () ); int y = (heihei - size -1 ) /2; if ( KOPrefs::instance()->mMonthShowIcons ) { if ( mInfo ) { p->fillRect ( x, y,size,size, Qt::darkGreen ); x += size + 1; } if ( mRecur ) { p->fillRect ( x, y,size,size, Qt::blue ); x += size + 1; } if ( mAlarm ) { p->fillRect ( x, y,size,size, Qt::red ); x += size + 1; } if ( mReply ) { p->fillRect ( x, y,size,size, Qt::yellow ); x += size + 1; } } if ( mMultiday ) { int yyy = y+(size/2); int sizeM = size+2; p->setBrush( QBrush::SolidPattern ); p->drawLine ( x+1, yyy, x +sizeM +sizeM/2-1, yyy ) ; if ( mMultiday == 2 || mMultiday == 3 ) { QPointArray pa ( 3 ); pa.setPoint (0, x, yyy ); pa.setPoint (1, x+sizeM/2, yyy+sizeM/2 ); pa.setPoint (2, x+sizeM/2, yyy-sizeM/2 ); p->drawPolygon( pa ); } if ( mMultiday == 2 || mMultiday == 1 ) { QPointArray pa ( 3 ); pa.setPoint (0, x+sizeM +sizeM/2, yyy ); pa.setPoint (1, x+sizeM, yyy+sizeM/2 ); pa.setPoint (2, x+sizeM, yyy-sizeM/2 ); p->drawPolygon( pa ); } if ( mMultiday == 1 ) { // p->fillRect ( x, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); p->drawLine ( x+1, yyy-sizeM/2, x+1, yyy+sizeM/2 ); } if ( mMultiday == 3 ) { // p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); p->drawLine ( x+sizeM +sizeM/2-1, yyy-sizeM/2, x+sizeM +sizeM/2-1, yyy+sizeM/2 ); } x += sizeM/2 + 1; x += sizeM + 1; } if ( mIncidence->type() == "Todo" ){ Todo* td = ( Todo* ) mIncidence; if ( td->isCompleted() ) { int half = size/2; 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-1, val ,size+2,Qt::black ); p->drawRect ( x, y-1,7,size+2); 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 ) ); p->drawText( x, yPos, text() ); if ( mIncidence->cancelled() ) { int wid = fm.width( text() ); p->drawLine( x, heihei/2-1 ,x+wid, heihei/2-1 ); } } 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 || KOPrefs::instance()->mMonthViewWeek ) { 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; //qDebug("ret wid %d ", lb->width()); return lb->width(); } MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) : KNoScrollListBox( par ), mMonthView( parent ) { mCurrentAvailItem = 0; //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( cellClicked( 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() { 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 ); } /* if ( !isVisible() ){ return; } */ // qDebug("MonthViewCell::updateCell() "); 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 ); } mCurrentAvailItem = (MonthViewItem*) firstItem (); //clear(); #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 } void MonthViewCell::insertEvent(Event *event) { |