author | zautrix <zautrix> | 2005-02-19 15:39:43 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-19 15:39:43 (UTC) |
commit | 4858dcb045afc57ce98877cca787c4430146bea8 (patch) (side-by-side diff) | |
tree | 9c9ea4b6d93a34d4bea97d7cea0b294c9c8665de | |
parent | d2ed2aaddb88f39f8b2ced18a4ea7f06a63237d3 (diff) | |
download | kdepimpi-4858dcb045afc57ce98877cca787c4430146bea8.zip kdepimpi-4858dcb045afc57ce98877cca787c4430146bea8.tar.gz kdepimpi-4858dcb045afc57ce98877cca787c4430146bea8.tar.bz2 |
multiday fixes in monthview
-rw-r--r-- | korganizer/komonthview.cpp | 91 | ||||
-rw-r--r-- | korganizer/komonthview.h | 2 |
2 files changed, 69 insertions, 24 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 2fe80af..f558084 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp @@ -127,514 +127,557 @@ void KNoScrollListBox::keyPressEvent(QKeyEvent *e) 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); } } 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); } } } 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() { setText( s ); mIncidence = incidence; mDate = qd; mRecur = false; mAlarm = false; mReply = false; mInfo = false; } void MonthViewItem::paint(QPainter *p) { #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 y = 3;//(height() - mRecurPixmap.height()) /2; int size = PIXMAP_SIZE; if ( QApplication::desktop()->width() < 300 ) size = 3; + int y = (height( listBox () ) - 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+sizeM/2, yyy, x +sizeM +sizeM/2-2, 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 ) ); + + } + if ( mMultiday == 3 ) { + p->fillRect ( x+sizeM, yyy-sizeM/2+1, sizeM/2, size, QBrush ( QBrush::SolidPattern ) ); + + } + x += sizeM/2 + 1; + x += sizeM + 1; + } 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, yPos- fm.height()/2+3,x+wid, yPos- fm.height()/2 +3); } } int MonthViewItem::height(const QListBox *lb) const { - return lb->fontMetrics().lineSpacing()+1; + if ( lb ) + return lb->fontMetrics().lineSpacing()+1; + return 10; } int MonthViewItem::width(const QListBox *lb) const { int size = PIXMAP_SIZE; if ( QApplication::desktop()->width() < 300 ) size = 3; int x = 1; - if ( mInfo ) { - x += size + 1; - } - if( mRecur ) { - x += size+1; - } - if( mAlarm ) { - x += size+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( mReply ) { - x += size+1; + if( mMultiday ) { + x += size+1+2+size/2; } return( x + lb->fontMetrics().width( text() ) + 1 ); } MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) : QWidget( par ), mMonthView( parent ) { QVBoxLayout *topLayout = new QVBoxLayout( this ); // 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 ); mItemList->setMinimumSize( 10, 10 ); mItemList->setFrameStyle( QFrame::Panel | QFrame::Plain ); mItemList->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( mItemList, SIGNAL( doubleClicked( QListBoxItem *) ), SLOT( defaultAction( QListBoxItem * ) ) ); connect( mItemList, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint &) ), SLOT( contextMenu( QListBoxItem * ) ) ); connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), SLOT( selection( QListBoxItem * ) ) ); connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), SLOT( cellClicked( QListBoxItem * ) ) ); connect( mItemList, 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) { setPalette( mHolidayPalette ); } else { if ( mPrimary ) { setPalette( mPrimaryPalette ); } else { setPalette( mNonPrimaryPalette ); } } 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::keyPressEvent ( QKeyEvent * e ) { e->ignore(); } void MonthViewCell::startUpdateCell() { mItemList->setFocusPolicy(NoFocus); if ( !mMonthView->isUpdatePossible() ) return; /* 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() ) { mItemList->setLineWidth( 3 ); } else { mItemList->setLineWidth( 1 ); } mItemList->clear(); #ifdef DESKTOP_VERSION QToolTip::remove(this); #endif mToolTip = ""; //qApp->processEvents(); if ( !mHolidayString.isEmpty() ) { MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); item->setPalette( mHolidayPalette ); mItemList->insertItem( item ); mToolTip += mHolidayString+"\n"; } } void MonthViewCell::insertEvent(Event *event) { mItemList->setFocusPolicy(WheelFocus); if ( !(event->doesRecur() == Recurrence::rNone) ) { if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) return; else if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) return; } if ( event->categories().contains("Holiday") || event->categories().contains(i18n("Holiday"))) { setHoliday( true ); if ( mDate.dayOfWeek() == 7 ) mItemList->setLineWidth( 3 ); } QString text; + int multiday = 0;// 1 = start, 2 = midddle, 3 = end day if (event->isMultiDay()) { - QString prefix = "<->"; + QString prefix = "<->";multiday = 2; + QString time; if ( event->doesRecur() ) { - if ( event->recursOn( mDate) ) - prefix ="->" ; + if ( event->recursOn( mDate) ) { + prefix ="->" ;multiday = 1; + } else { int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); if ( event->recursOn( mDate.addDays( -days)) ) - prefix ="<-" ; + prefix ="<-" ;multiday = 3; } } else { if (mDate == event->dtStart().date()) { - prefix ="->" ; + prefix ="->" ;multiday = 1; } else if (mDate == event->dtEnd().date()) { - prefix ="<-" ; + prefix ="<-" ;multiday = 3; } } if ( !event->doesFloat() ) { if ( mDate == event->dtStart().date () ) - prefix += KGlobal::locale()->formatTime(event->dtStart().time())+" "; + time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; else if ( mDate == event->dtEnd().date () ) - prefix += KGlobal::locale()->formatTime(event->dtEnd().time())+" "; + time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; } - text = prefix + event->summary(); - mToolTip += text; + text = time + event->summary(); + mToolTip += prefix + text; } else { if (event->doesFloat()) { text = event->summary(); mToolTip += text; } else { text = KGlobal::locale()->formatTime(event->dtStart().time()); text += " " + event->summary(); mToolTip += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); } } MonthViewItem *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() ); + 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); + item->setReply(true && multiday < 2); else item->setReply(false); } else item->setReply(false); #endif + item->setMultiDay( multiday ); mItemList->insertItem( item ); mToolTip += "\n"; } void MonthViewCell::insertTodo(Todo *todo) { mItemList->setFocusPolicy(WheelFocus); QString text; if (todo->hasDueDate()) { if (!todo->doesFloat()) { text += KGlobal::locale()->formatTime(todo->dtDue().time()); text += " "; } } text += i18n("T: %1").arg(todo->summary()); 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 ); mItemList->insertItem( item ); mToolTip += text+"\n"; } void MonthViewCell::finishUpdateCell() { #ifdef DESKTOP_VERSION if (mToolTip != "") QToolTip::add(this,mToolTip,toolTipGroup(),""); #endif mItemList->sort(); //setMyPalette(); setMyPalette(); QString 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 ); resizeEvent( 0 ); } void MonthViewCell::updateCell() { qDebug("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 { diff --git a/korganizer/komonthview.h b/korganizer/komonthview.h index 2f6f5dc..b79a41f 100644 --- a/korganizer/komonthview.h +++ b/korganizer/komonthview.h @@ -4,206 +4,208 @@ 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. */ #ifndef _KOMONTHVIEW_H #define _KOMONTHVIEW_H #include <qlabel.h> #include <qframe.h> #include <qdatetime.h> #include <qlistbox.h> #include <qpoint.h> #include <qwidgetstack.h> #include <qlayout.h> #include <qintdict.h> #include <qpushbutton.h> #include <qvaluelist.h> #include <qptrvector.h> #include <libkcal/calendar.h> #include <libkcal/event.h> #include "koeventview.h" #include "navigatorbar.h" #ifdef DESKTOP_VERSION class QToolTipGroup; #endif class KNOWhatsThis; class KOWeekButton : public QPushButton { Q_OBJECT public: KOWeekButton( QWidget *parent=0, const char *name=0 ) : QPushButton( parent, name) { connect( this, SIGNAL( clicked() ), SLOT( bottonClicked() )); mNumber = -1; } void setWeekNum ( int num ) {mNumber = num; setText( QString::number ( num ));} int getWeekNum() { return mNumber;} signals: void selectWeekNum ( int ); private: int mNumber; private slots : void bottonClicked() { if ( mNumber > 0 ) emit selectWeekNum ( mNumber ); } }; class KNoScrollListBox: public QListBox { Q_OBJECT public: KNoScrollListBox(QWidget *parent=0, const char *name=0); ~KNoScrollListBox(); QString getWhatsThisText(QPoint p) ; signals: void shiftDown(); void shiftUp(); void rightClick(); protected slots: void oneDown(); void keyPressEvent(QKeyEvent *); void keyReleaseEvent(QKeyEvent *); void mousePressEvent(QMouseEvent *); private: KNOWhatsThis * mWT; }; class MonthViewItem: public QListBoxItem { public: MonthViewItem( Incidence *, QDate qd, const QString & title ); void setRecur(bool on) { mRecur = on; } void setAlarm(bool on) { mAlarm = on; } void setReply(bool on) { mReply = on; } void setMoreInfo(bool on) { mInfo = on; } + void setMultiDay(int type) { mMultiday = type; } void setPalette(const QPalette &p) { mPalette = p; } QPalette palette() const { return mPalette; } Incidence *incidence() const { return mIncidence; } QDate incidenceDate() { return mDate; } protected: virtual void paint(QPainter *); virtual int height(const QListBox *) const; virtual int width(const QListBox *) const; private: + int mMultiday; bool mRecur; bool mAlarm; bool mReply; bool mInfo; QPalette mPalette; QDate mDate; Incidence *mIncidence; }; class KOMonthView; class MonthViewCell : public QWidget { Q_OBJECT public: MonthViewCell(KOMonthView *,QWidget* ); void setDate( const QDate & ); QDate date() const; void setPrimary( bool ); bool isPrimary() const; void setHoliday( bool ); void setHoliday( const QString & ); void updateCell(); void startUpdateCell(); void finishUpdateCell(); void insertEvent(Event *); void insertTodo(Todo *); void updateConfig( bool bigFont = false ); void enableScrollBars( bool ); Incidence *selectedIncidence(); QDate selectedIncidenceDate(); void deselect(); void select(); #ifdef DESKTOP_VERSION static QToolTipGroup *toolTipGroup(); #endif signals: void defaultAction( Incidence * ); void newEventSignal( QDateTime ); void showDaySignal( QDate ); protected: QString mToolTip; void resizeEvent( QResizeEvent * ); protected slots: void defaultAction( QListBoxItem * ); void contextMenu( QListBoxItem * ); void selection( QListBoxItem * ); void cellClicked( QListBoxItem * ); void newEvent(); void showDay(); private: KOMonthView *mMonthView; QDate mDate; bool mPrimary; bool mHoliday; QString mHolidayString; //QLabel *mLabel; QPushButton *mLabel; QListBox *mItemList; #ifdef DESKTOP_VERSION static QToolTipGroup *mToolTipGroup; #endif QSize mLabelSize; QSize mLabelBigSize; QPalette mHolidayPalette; QPalette mStandardPalette; QPalette mPrimaryPalette; QPalette mNonPrimaryPalette; void setMyPalette(); QPalette getPalette (); void keyPressEvent ( QKeyEvent * ) ; }; class KOMonthView: public KOEventView { Q_OBJECT public: |