summaryrefslogtreecommitdiffabout
path: root/korganizer/komonthview.cpp
Unidiff
Diffstat (limited to 'korganizer/komonthview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/komonthview.cpp163
1 files changed, 151 insertions, 12 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 6411156..9888566 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -462,12 +462,19 @@ void MonthViewCell::insertEvent(Event *event)
462 if (mDate == event->dtStart().date()) { 462 if (mDate == event->dtStart().date()) {
463 prefix ="->" ; 463 prefix ="->" ;
464 } else if (mDate == event->dtEnd().date()) { 464 } else if (mDate == event->dtEnd().date()) {
465 prefix ="<-" ; 465 prefix ="<-" ;
466 } 466 }
467 } 467 }
468 if ( !event->doesFloat() ) {
469 if ( mDate == event->dtStart().date () )
470 prefix += KGlobal::locale()->formatTime(event->dtStart().time())+" ";
471 else if ( mDate == event->dtEnd().date () )
472 prefix += KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
473
474 }
468 text = prefix + event->summary(); 475 text = prefix + event->summary();
469 mToolTip += text; 476 mToolTip += text;
470 } else { 477 } else {
471 if (event->doesFloat()) { 478 if (event->doesFloat()) {
472 text = event->summary(); 479 text = event->summary();
473 mToolTip += text; 480 mToolTip += text;
@@ -564,18 +571,18 @@ void MonthViewCell::insertTodo(Todo *todo)
564void MonthViewCell::finishUpdateCell() 571void MonthViewCell::finishUpdateCell()
565{ 572{
566#ifdef DESKTOP_VERSION 573#ifdef DESKTOP_VERSION
567 if (mToolTip != "") 574 if (mToolTip != "")
568 QToolTip::add(this,mToolTip,toolTipGroup(),""); 575 QToolTip::add(this,mToolTip,toolTipGroup(),"");
569#endif 576#endif
570 577 mItemList->sort();
571 //setMyPalette(); 578 //setMyPalette();
572 setMyPalette(); 579 setMyPalette();
573 QString text; 580 QString text;
574 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog; 581 bool smallDisplay = QApplication::desktop()->width() < 320 && KOPrefs::instance()->mMonthViewSatSunTog;
575 if ( KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) { 582 if ( KOPrefs::instance()->mMonthViewWeek || KOGlobals::self()->calendarSystem()->day( mDate ) == 1 || (mDate.dayOfWeek() == 7 && !smallDisplay ) || KOPrefs::instance()->mMonthShowShort) {
576 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " "; 583 text = KOGlobals::self()->calendarSystem()->monthName( mDate, true ) + " ";
577 mLabel->resize( mLabelBigSize ); 584 mLabel->resize( mLabelBigSize );
578 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 585 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
579 } else { 586 } else {
580 mLabel->resize( mLabelSize ); 587 mLabel->resize( mLabelSize );
581 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) ); 588 text += QString::number( KOGlobals::self()->calendarSystem()->day(mDate) );
@@ -685,16 +692,16 @@ void MonthViewCell::resizeEvent ( QResizeEvent * )
685 return; 692 return;
686#ifndef DESKTOP_VERSION 693#ifndef DESKTOP_VERSION
687 if ( !isVisible() ){ 694 if ( !isVisible() ){
688 return; 695 return;
689 } 696 }
690#endif 697#endif
691 int size = height() - mLabel->height(); 698 int size = height() - mLabel->height() - 2;
692 if ( size > 0 ) 699 if ( size > 0 )
693 mItemList->verticalScrollBar()->setMaximumHeight( size ); 700 mItemList->verticalScrollBar()->setMaximumHeight( size );
694 size = width() - mLabel->width(); 701 size = width() - mLabel->width() -2;
695 if ( size > 0 ) 702 if ( size > 0 )
696 mItemList->horizontalScrollBar()->setMaximumWidth( size ); 703 mItemList->horizontalScrollBar()->setMaximumWidth( size );
697 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() ); 704 mLabel->move( width()-mItemList->lineWidth() - mLabel->width(), height()-mItemList->lineWidth() - mLabel->height() );
698 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); 705 //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2);
699} 706}
700 707
@@ -729,13 +736,13 @@ void MonthViewCell::cellClicked( QListBoxItem *item )
729 if ( lastClicked->listBox() != item->listBox() ) 736 if ( lastClicked->listBox() != item->listBox() )
730 lastClicked->listBox()->clearSelection(); 737 lastClicked->listBox()->clearSelection();
731 } 738 }
732 */ 739 */
733 740
734 mMonthView->setSelectedCell( this ); 741 mMonthView->setSelectedCell( this );
735 if( KOPrefs::instance()->mEnableMonthScroll ) enableScrollBars( true ); 742 if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true );
736 select(); 743 select();
737} 744}
738 745
739void MonthViewCell::contextMenu( QListBoxItem *item ) 746void MonthViewCell::contextMenu( QListBoxItem *item )
740{ 747{
741 if ( !item ) return; 748 if ( !item ) return;
@@ -760,13 +767,16 @@ void MonthViewCell::selection( QListBoxItem *item )
760 767
761KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 768KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
762 : KOEventView( calendar, parent, name ), 769 : KOEventView( calendar, parent, name ),
763 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 770 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
764 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 771 mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
765{ 772{
766 773 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
774 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
775 if ( mShowWeekView )
776 mWeekStartsMonday = true;
767 updatePossible = false; 777 updatePossible = false;
768 mCells.setAutoDelete( true ); 778 mCells.setAutoDelete( true );
769 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 779 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
770 // mDayLayout = new QGridLayout( this ); 780 // mDayLayout = new QGridLayout( this );
771 // create the day of the week labels (Sun, Mon, etc) and add them to 781 // create the day of the week labels (Sun, Mon, etc) and add them to
772 // the layout. 782 // the layout.
@@ -814,22 +824,32 @@ KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
814 SIGNAL( newEventSignal( QDateTime ) ) ); 824 SIGNAL( newEventSignal( QDateTime ) ) );
815 connect( cell, SIGNAL( showDaySignal( QDate ) ), 825 connect( cell, SIGNAL( showDaySignal( QDate ) ),
816 SIGNAL( showDaySignal( QDate ) ) ); 826 SIGNAL( showDaySignal( QDate ) ) );
817 } 827 }
818 } 828 }
819 829
830 connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ),
831 SLOT( switchView() ) );
820 mContextMenu = eventPopup(); 832 mContextMenu = eventPopup();
821 // updateConfig(); //useless here 833 // updateConfig(); //useless here
822 834
823 emit incidenceSelected( 0 ); 835 emit incidenceSelected( 0 );
824} 836}
825 837
826KOMonthView::~KOMonthView() 838KOMonthView::~KOMonthView()
827{ 839{
828 delete mContextMenu; 840 delete mContextMenu;
829} 841}
842void KOMonthView::switchView()
843{
844 mShowWeekView = !mShowWeekView;
845 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
846 emit showNavigator( !mShowWeekView );
847 computeLayout();
848 updateConfig();
849}
830 850
831int KOMonthView::maxDatesHint() 851int KOMonthView::maxDatesHint()
832{ 852{
833 return mNumCells; 853 return mNumCells;
834} 854}
835 855
@@ -872,12 +892,14 @@ void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
872 892
873void KOMonthView::updateConfig() 893void KOMonthView::updateConfig()
874{ 894{
875 895
876 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 896 mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
877 897
898 if ( mShowWeekView )
899 mWeekStartsMonday = true;
878 QFontMetrics fontmetric(mDayLabels[0]->font()); 900 QFontMetrics fontmetric(mDayLabels[0]->font());
879 mWidthLongDayLabel = 0; 901 mWidthLongDayLabel = 0;
880 902
881 for (int i = 0; i < 7; i++) { 903 for (int i = 0; i < 7; i++) {
882 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 904 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
883 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 905 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
@@ -977,21 +999,23 @@ void KOMonthView::updateView()
977 if ( !updatePossible ) 999 if ( !updatePossible )
978 return; 1000 return;
979 //QTime ti; 1001 //QTime ti;
980 //ti.start(); 1002 //ti.start();
981#if 1 1003#if 1
982 int i; 1004 int i;
983 for( i = 0; i < mCells.count(); ++i ) { 1005 int timeSpan = mCells.size()-1;
1006 if ( KOPrefs::instance()->mMonthViewWeek )
1007 timeSpan = 6;
1008 for( i = 0; i < timeSpan + 1; ++i ) {
984 mCells[i]->startUpdateCell(); 1009 mCells[i]->startUpdateCell();
985 } 1010 }
986 1011
987 QPtrList<Event> events = calendar()->events(); 1012 QPtrList<Event> events = calendar()->events();
988 Event *event; 1013 Event *event;
989 QDateTime dt; 1014 QDateTime dt;
990 bool ok; 1015 bool ok;
991 int timeSpan = mCells.size()-1;
992 QDate endDate = mStartDate.addDays( timeSpan ); 1016 QDate endDate = mStartDate.addDays( timeSpan );
993 for( event = events.first(); event; event = events.next() ) { // for event 1017 for( event = events.first(); event; event = events.next() ) { // for event
994 if ( event->doesRecur() ) { 1018 if ( event->doesRecur() ) {
995 bool last; 1019 bool last;
996 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1020 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
997 QDateTime incidenceEnd; 1021 QDateTime incidenceEnd;
@@ -1050,19 +1074,19 @@ void KOMonthView::updateView()
1050 QPtrList<Todo> todos = calendar()->todos( ); 1074 QPtrList<Todo> todos = calendar()->todos( );
1051 Todo *todo; 1075 Todo *todo;
1052 for(todo = todos.first(); todo; todo = todos.next()) { 1076 for(todo = todos.first(); todo; todo = todos.next()) {
1053 //insertTodo( todo ); 1077 //insertTodo( todo );
1054 if ( todo->hasDueDate() ) { 1078 if ( todo->hasDueDate() ) {
1055 int day = mStartDate.daysTo( todo->dtDue().date() ); 1079 int day = mStartDate.daysTo( todo->dtDue().date() );
1056 if ( day >= 0 && day < mCells.size() ) { 1080 if ( day >= 0 && day < timeSpan + 1) {
1057 mCells[day]->insertTodo( todo ); 1081 mCells[day]->insertTodo( todo );
1058 } 1082 }
1059 } 1083 }
1060 } 1084 }
1061 1085
1062 for( i = 0; i < mCells.count(); ++i ) { 1086 for( i = 0; i < timeSpan+1; ++i ) {
1063 mCells[i]->finishUpdateCell(); 1087 mCells[i]->finishUpdateCell();
1064 } 1088 }
1065 processSelectionChange(); 1089 processSelectionChange();
1066 mCells[0]->setFocus(); 1090 mCells[0]->setFocus();
1067 1091
1068 1092
@@ -1085,19 +1109,132 @@ void KOMonthView::updateView()
1085 1109
1086void KOMonthView::resizeEvent(QResizeEvent * e) 1110void KOMonthView::resizeEvent(QResizeEvent * e)
1087{ 1111{
1088 computeLayout(); 1112 computeLayout();
1089 mCells[0]->setFocus(); 1113 mCells[0]->setFocus();
1090} 1114}
1115void KOMonthView::computeLayoutWeek()
1116{
1117
1118 int daysToShow;
1119 bool combinedSatSun = false;
1120 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1121 daysToShow = 6;
1122 combinedSatSun = true;
1123 }
1124 int tWid = topLevelWidget()->size().width();
1125 int tHei = topLevelWidget()->size().height();
1126
1127 int wid = size().width();//e
1128 int hei = size().height()-1;
1129
1130 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1131 return;
1132
1133 if ( wid < hei )
1134 daysToShow = 2;
1135 else
1136 daysToShow = 3;
1137 mShowSatSunComp = true;
1138 combinedSatSun = true;
1139
1140 //qDebug("KOMonthView::computeLayout()------------------------------------ ");
1141 QFontMetrics fm ( mWeekLabels[0]->font() );
1142 int weeklabelwid = fm.width( "888" );
1143 wid -= weeklabelwid;
1144
1145 int colWid = wid / daysToShow;
1146 int lastCol = wid - ( colWid*6 );
1147 int dayLabelHei = mDayLabels[0]->sizeHint().height();
1148 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1149 int colModulo = wid % daysToShow;
1150 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1151 //qDebug("rowmod %d ", rowModulo);
1152 int i;
1153 int x,y,w,h;
1154 x= 0;
1155 y= 0;
1156 w = colWid;
1157 h = dayLabelHei ;
1158 for ( i = 0; i < 7; i++) {
1159 if ( i && !( i % daysToShow) && i < 6) {
1160 y += hei/(5-daysToShow);
1161 x = 0;
1162 }
1163 if ( i == daysToShow-colModulo )
1164 ++w;
1165 if ( i >= 5 ) {
1166 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
1167 x -= w/2 ;
1168 }
1169 else
1170 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
1171 x += w;
1172 }
1173 x= 0;
1174 y= dayLabelHei;
1175 w = colWid;
1176 h = cellHei;
1177 for ( i = 0; i < mCells.count(); ++i) {
1178 if ( i > 6 ) {
1179 mCells[i]->hide();
1180 continue;
1181 }
1182
1183 w = colWid;
1184 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1185 ++w;
1186 }
1187 if ( i == (daysToShow-1-rowModulo)*7)
1188 ++h;
1189
1190 if ( i >= 5 ) {
1191 if ( i ==5 ) {
1192 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h/2 );
1193 x -= w ;y += h/2;
1194 } else {
1195 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h-h/2 );
1196 y -= h/2;
1197 }
1198 } else
1199 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
1200
1201
1202 x += w;
1203 if ( x + w/2 > wid ) {
1204 x = 0;
1205 y += h+dayLabelHei ;
1206 }
1207 }
1208 y= dayLabelHei;
1209 h = cellHei ;
1210 mWeekLabels[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1211 for ( i = 1; i < 6; i++) {
1212 mWeekLabels[i]->hide();
1213 }
1214 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1215 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1216 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1217 mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ;
1218 updateDayLabels();
1219 bool forceUpdate = !updatePossible;
1220 updatePossible = true;
1221 mWeekLabels[mNumWeeks]->setText( i18n("M"));
1222 if ( forceUpdate )
1223 updateView();
1224}
1091void KOMonthView::computeLayout() 1225void KOMonthView::computeLayout()
1092{ 1226{
1093 // select the appropriate heading string size. E.g. "Wednesday" or "Wed". 1227 // select the appropriate heading string size. E.g. "Wednesday" or "Wed".
1094 // note this only changes the text if the requested size crosses the 1228 // note this only changes the text if the requested size crosses the
1095 // threshold between big enough to support the full name and not big 1229 // threshold between big enough to support the full name and not big
1096 // enough. 1230 // enough.
1097 1231 if ( mShowWeekView ){
1232 computeLayoutWeek();
1233 return;
1234 }
1098 int daysToShow = 7; 1235 int daysToShow = 7;
1099 bool combinedSatSun = false; 1236 bool combinedSatSun = false;
1100 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1237 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1101 daysToShow = 6; 1238 daysToShow = 6;
1102 combinedSatSun = true; 1239 combinedSatSun = true;
1103 } 1240 }
@@ -1143,13 +1280,13 @@ void KOMonthView::computeLayout()
1143 } 1280 }
1144 x= 0; 1281 x= 0;
1145 y= dayLabelHei; 1282 y= dayLabelHei;
1146 w = colWid; 1283 w = colWid;
1147 h = cellHei ; 1284 h = cellHei ;
1148 for ( i = 0; i < mCells.count(); ++i) { 1285 for ( i = 0; i < mCells.count(); ++i) {
1149 1286 mCells[i]->show();
1150 w = colWid; 1287 w = colWid;
1151 if ( ((i) % 7) >= 7-colModulo ) { 1288 if ( ((i) % 7) >= 7-colModulo ) {
1152 ++w; 1289 ++w;
1153 } 1290 }
1154 if ( i == (6-rowModulo)*7) 1291 if ( i == (6-rowModulo)*7)
1155 ++h; 1292 ++h;
@@ -1174,24 +1311,26 @@ void KOMonthView::computeLayout()
1174 y += h; 1311 y += h;
1175 } 1312 }
1176 } 1313 }
1177 y= dayLabelHei; 1314 y= dayLabelHei;
1178 h = cellHei ; 1315 h = cellHei ;
1179 for ( i = 0; i < 6; i++) { 1316 for ( i = 0; i < 6; i++) {
1317 mWeekLabels[i]->show();
1180 if ( i == (6-rowModulo)) 1318 if ( i == (6-rowModulo))
1181 ++h; 1319 ++h;
1182 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 1320 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
1183 y += h; 1321 y += h;
1184 } 1322 }
1185 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1323 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1186 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1324 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1187 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1325 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1188 mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ; 1326 mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ;
1189 updateDayLabels(); 1327 updateDayLabels();
1190 bool forceUpdate = !updatePossible; 1328 bool forceUpdate = !updatePossible;
1191 updatePossible = true; 1329 updatePossible = true;
1330 mWeekLabels[mNumWeeks]->setText( i18n("W"));
1192 if ( forceUpdate ) 1331 if ( forceUpdate )
1193 updateView(); 1332 updateView();
1194} 1333}
1195 1334
1196void KOMonthView::showContextMenu( Incidence *incidence ) 1335void KOMonthView::showContextMenu( Incidence *incidence )
1197{ 1336{