-rw-r--r-- | korganizer/komonthview.cpp | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index b175f9a..2b7e41f 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp | |||
@@ -397,30 +397,40 @@ void MonthViewItem::paint(QPainter *p) | |||
397 | x += size + 3; | 397 | x += size + 3; |
398 | } | 398 | } |
399 | } | 399 | } |
400 | QFontMetrics fm = p->fontMetrics(); | 400 | QFontMetrics fm = p->fontMetrics(); |
401 | int yPos; | 401 | int yPos; |
402 | int pmheight = size; | 402 | int pmheight = size; |
403 | if( pmheight < fm.height() ) | 403 | if( pmheight < fm.height() ) |
404 | yPos = fm.ascent() + fm.leading()/2; | 404 | yPos = fm.ascent() + fm.leading()/2; |
405 | else | 405 | else |
406 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); | 406 | yPos = pmheight/2 - fm.height()/2 + fm.ascent(); |
407 | p->setPen( palette().color( QPalette::Normal, sel ? \ | 407 | p->setPen( palette().color( QPalette::Normal, sel ? \ |
408 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); | 408 | QColorGroup::HighlightedText : QColorGroup::Foreground ) ); |
409 | if ( KOPrefs::instance()->mMonthShowTimes || isWeekItem) { | ||
409 | p->drawText( x, yPos, text() ); | 410 | p->drawText( x, yPos, text() ); |
410 | if ( mIncidence->cancelled() ) { | 411 | if ( mIncidence->cancelled() ) { |
411 | int wid = fm.width( text() ); | 412 | int wid = fm.width( text() ); |
412 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); | 413 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); |
413 | } | 414 | } |
414 | 415 | } else { | |
416 | QString pText = text(); | ||
417 | if( pText.mid(2,1) == ":" ) | ||
418 | pText = pText.mid( 6 ); | ||
419 | p->drawText( x, yPos, pText ); | ||
420 | if ( mIncidence->cancelled() ) { | ||
421 | int wid = fm.width( pText ); | ||
422 | p->drawLine( x, heihei/2 ,x+wid, heihei/2 ); | ||
423 | } | ||
424 | } | ||
415 | } | 425 | } |
416 | 426 | ||
417 | int MonthViewItem::height(const QListBox *lb) const | 427 | int MonthViewItem::height(const QListBox *lb) const |
418 | { | 428 | { |
419 | int ret = 10; | 429 | int ret = 10; |
420 | if ( lb ) | 430 | if ( lb ) |
421 | ret = lb->fontMetrics().lineSpacing()+1; | 431 | ret = lb->fontMetrics().lineSpacing()+1; |
422 | return ret; | 432 | return ret; |
423 | } | 433 | } |
424 | 434 | ||
425 | int MonthViewItem::width(const QListBox *lb) const | 435 | int MonthViewItem::width(const QListBox *lb) const |
426 | { | 436 | { |
@@ -1033,37 +1043,41 @@ void MonthViewCell::defaultAction( QListBoxItem *item ) | |||
1033 | } | 1043 | } |
1034 | void MonthViewCell::showDay() | 1044 | void MonthViewCell::showDay() |
1035 | { | 1045 | { |
1036 | emit showDaySignal( date() ); | 1046 | emit showDaySignal( date() ); |
1037 | } | 1047 | } |
1038 | void MonthViewCell::newEvent() | 1048 | void MonthViewCell::newEvent() |
1039 | { | 1049 | { |
1040 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 1050 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
1041 | emit newEventSignal( dt ); | 1051 | emit newEventSignal( dt ); |
1042 | } | 1052 | } |
1043 | void MonthViewCell::cellClicked( QListBoxItem *item ) | 1053 | void MonthViewCell::cellClicked( QListBoxItem *item ) |
1044 | { | 1054 | { |
1055 | mMonthView->setSelectedCell( this ); | ||
1045 | qDebug("CELL "); | 1056 | qDebug("CELL "); |
1046 | if ( item == 0 ) { | 1057 | if ( item == 0 ) { |
1047 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | 1058 | QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); |
1048 | emit newEventSignal( dt ); | 1059 | emit newEventSignal( dt ); |
1049 | return; | 1060 | return; |
1050 | } | 1061 | } |
1051 | 1062 | ||
1052 | } | 1063 | } |
1053 | 1064 | ||
1054 | void MonthViewCell::contextMenu( QListBoxItem *item ) | 1065 | void MonthViewCell::contextMenu( QListBoxItem *item ) |
1055 | { | 1066 | { |
1056 | if ( !item ) return; | 1067 | mMonthView->setPopupCell( this ); |
1057 | 1068 | if ( !item ) { | |
1069 | mMonthView->showContextMenu( 0 ); | ||
1070 | return; | ||
1071 | } | ||
1058 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); | 1072 | MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); |
1059 | Incidence *incidence = eventItem->incidence(); | 1073 | Incidence *incidence = eventItem->incidence(); |
1060 | if ( incidence ) mMonthView->showContextMenu( incidence ); | 1074 | if ( incidence ) mMonthView->showContextMenu( incidence ); |
1061 | } | 1075 | } |
1062 | 1076 | ||
1063 | void MonthViewCell::selection( QListBoxItem *item ) | 1077 | void MonthViewCell::selection( QListBoxItem *item ) |
1064 | { | 1078 | { |
1065 | if ( !item ) return; | 1079 | if ( !item ) return; |
1066 | 1080 | ||
1067 | mMonthView->setSelectedCell( this ); | 1081 | mMonthView->setSelectedCell( this ); |
1068 | } | 1082 | } |
1069 | 1083 | ||
@@ -1074,24 +1088,25 @@ void MonthViewCell::selection( QListBoxItem *item ) | |||
1074 | 1088 | ||
1075 | 1089 | ||
1076 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) | 1090 | KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) |
1077 | : KOEventView( calendar, parent, name ), | 1091 | : KOEventView( calendar, parent, name ), |
1078 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), | 1092 | mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), |
1079 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) | 1093 | mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) |
1080 | { | 1094 | { |
1081 | mFlagKeyPressed = false; | 1095 | mFlagKeyPressed = false; |
1082 | mShortDayLabelsM = false; | 1096 | mShortDayLabelsM = false; |
1083 | mShortDayLabelsW = false; | 1097 | mShortDayLabelsW = false; |
1084 | skipResize = false; | 1098 | skipResize = false; |
1085 | clPending = true; | 1099 | clPending = true; |
1100 | mPopupCell = 0; | ||
1086 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); | 1101 | mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); |
1087 | mWidStack = new QWidgetStack( this ); | 1102 | mWidStack = new QWidgetStack( this ); |
1088 | QVBoxLayout* hb = new QVBoxLayout( this ); | 1103 | QVBoxLayout* hb = new QVBoxLayout( this ); |
1089 | mMonthView = new QWidget( mWidStack ); | 1104 | mMonthView = new QWidget( mWidStack ); |
1090 | mWeekView = new QWidget( mWidStack ); | 1105 | mWeekView = new QWidget( mWidStack ); |
1091 | #if QT_VERSION >= 0x030000 | 1106 | #if QT_VERSION >= 0x030000 |
1092 | mWidStack->addWidget(mMonthView ); | 1107 | mWidStack->addWidget(mMonthView ); |
1093 | mWidStack->addWidget(mWeekView ); | 1108 | mWidStack->addWidget(mWeekView ); |
1094 | #else | 1109 | #else |
1095 | mWidStack->addWidget( mMonthView, 1 ); | 1110 | mWidStack->addWidget( mMonthView, 1 ); |
1096 | mWidStack->addWidget( mWeekView , 1 ); | 1111 | mWidStack->addWidget( mWeekView , 1 ); |
1097 | #endif | 1112 | #endif |
@@ -1191,24 +1206,47 @@ KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) | |||
1191 | SIGNAL( newEventSignal( QDateTime ) ) ); | 1206 | SIGNAL( newEventSignal( QDateTime ) ) ); |
1192 | connect( cell, SIGNAL( showDaySignal( QDate ) ), | 1207 | connect( cell, SIGNAL( showDaySignal( QDate ) ), |
1193 | SIGNAL( showDaySignal( QDate ) ) ); | 1208 | SIGNAL( showDaySignal( QDate ) ) ); |
1194 | connect( cell, SIGNAL( nextCell() ), | 1209 | connect( cell, SIGNAL( nextCell() ), |
1195 | SLOT( nextCell() ) ); | 1210 | SLOT( nextCell() ) ); |
1196 | connect( cell, SIGNAL( prevCell() ), | 1211 | connect( cell, SIGNAL( prevCell() ), |
1197 | SLOT( prevCell() ) ); | 1212 | SLOT( prevCell() ) ); |
1198 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); | 1213 | cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); |
1199 | } | 1214 | } |
1200 | 1215 | ||
1201 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); | 1216 | //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); |
1202 | mContextMenu = eventPopup(); | 1217 | mContextMenu = eventPopup(); |
1218 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
1219 | i18n("New Event..."),this, | ||
1220 | SLOT(slotNewEvent()),false); | ||
1221 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
1222 | i18n("New Todo..."),this, | ||
1223 | SLOT(slotNewTodo()),false); | ||
1224 | mContextMenu->addAdditionalItem(QIconSet(QPixmap()), | ||
1225 | i18n("Journal"),this, | ||
1226 | SLOT(slotEditJournal()),false); | ||
1227 | |||
1228 | |||
1229 | |||
1230 | QString pathString = ""; | ||
1231 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { | ||
1232 | if ( QApplication::desktop()->width() < 480 ) | ||
1233 | pathString += "icons16/"; | ||
1234 | } else | ||
1235 | pathString += "iconsmini/"; | ||
1236 | mNewItemMenu = new QPopupMenu( this ); | ||
1237 | mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent())); | ||
1238 | mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false); | ||
1239 | mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false); | ||
1240 | |||
1203 | // updateConfig(); //useless here... | 1241 | // updateConfig(); //useless here... |
1204 | // ... but we need mWidthLongDayLabel computed | 1242 | // ... but we need mWidthLongDayLabel computed |
1205 | QFontMetrics fontmetric(mDayLabels[0]->font()); | 1243 | QFontMetrics fontmetric(mDayLabels[0]->font()); |
1206 | mWidthLongDayLabel = 0; | 1244 | mWidthLongDayLabel = 0; |
1207 | for (int i = 0; i < 7; i++) { | 1245 | for (int i = 0; i < 7; i++) { |
1208 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); | 1246 | int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); |
1209 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; | 1247 | if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; |
1210 | } | 1248 | } |
1211 | 1249 | ||
1212 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1250 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1213 | 1251 | ||
1214 | #if 0 | 1252 | #if 0 |
@@ -1884,41 +1922,46 @@ void KOMonthView::computeLayout() | |||
1884 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); | 1922 | mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); |
1885 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); | 1923 | // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); |
1886 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); | 1924 | //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); |
1887 | mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; | 1925 | mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; |
1888 | updateDayLabels(); | 1926 | updateDayLabels(); |
1889 | //bool forceUpdate = !updatePossible; | 1927 | //bool forceUpdate = !updatePossible; |
1890 | updatePossible = true; | 1928 | updatePossible = true; |
1891 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); | 1929 | //mWeekLabels[mNumWeeks]->setText( i18n("W")); |
1892 | } | 1930 | } |
1893 | 1931 | ||
1894 | void KOMonthView::showContextMenu( Incidence *incidence ) | 1932 | void KOMonthView::showContextMenu( Incidence *incidence ) |
1895 | { | 1933 | { |
1934 | if( incidence ) | ||
1896 | mContextMenu->showIncidencePopup(incidence); | 1935 | mContextMenu->showIncidencePopup(incidence); |
1936 | else { | ||
1937 | //qDebug("KOMonthView::showContextMenu "); | ||
1938 | mNewItemMenu->popup(QCursor::pos()); | ||
1939 | } | ||
1897 | /* | 1940 | /* |
1898 | if( incidence && incidence->type() == "Event" ) { | 1941 | if( incidence && incidence->type() == "Event" ) { |
1899 | Event *event = static_cast<Event *>(incidence); | 1942 | Event *event = static_cast<Event *>(incidence); |
1900 | mContextMenu->showEventPopup(event); | 1943 | mContextMenu->showEventPopup(event); |
1901 | } else { | 1944 | } else { |
1902 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; | 1945 | kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; |
1903 | } | 1946 | } |
1904 | */ | 1947 | */ |
1905 | } | 1948 | } |
1906 | MonthViewCell * KOMonthView::selectedCell( ) | 1949 | MonthViewCell * KOMonthView::selectedCell( ) |
1907 | { | 1950 | { |
1908 | return mSelectedCell; | 1951 | return mSelectedCell; |
1909 | } | 1952 | } |
1910 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) | 1953 | void KOMonthView::setSelectedCell( MonthViewCell *cell ) |
1911 | { | 1954 | { |
1912 | //qDebug("KOMonthView::setSelectedCell "); | 1955 | //qDebug("KOMonthView::setSelectedCell %d", cell); |
1913 | if ( mSelectedCell && mSelectedCell != cell ) { | 1956 | if ( mSelectedCell && mSelectedCell != cell ) { |
1914 | MonthViewCell * mvc = mSelectedCell; | 1957 | MonthViewCell * mvc = mSelectedCell; |
1915 | mSelectedCell = cell; | 1958 | mSelectedCell = cell; |
1916 | mvc->deselect(); | 1959 | mvc->deselect(); |
1917 | } else | 1960 | } else |
1918 | mSelectedCell = cell; | 1961 | mSelectedCell = cell; |
1919 | // if ( mSelectedCell ) | 1962 | // if ( mSelectedCell ) |
1920 | // mSelectedCell->select(); | 1963 | // mSelectedCell->select(); |
1921 | if ( !mSelectedCell ) | 1964 | if ( !mSelectedCell ) |
1922 | emit incidenceSelected( 0 ); | 1965 | emit incidenceSelected( 0 ); |
1923 | else | 1966 | else |
1924 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); | 1967 | emit incidenceSelected( mSelectedCell->selectedIncidence() ); |
@@ -2005,12 +2048,44 @@ void KOMonthView::keyPressEvent ( QKeyEvent * e ) | |||
2005 | break; | 2048 | break; |
2006 | } | 2049 | } |
2007 | } | 2050 | } |
2008 | 2051 | ||
2009 | void KOMonthView::nextCell() | 2052 | void KOMonthView::nextCell() |
2010 | { | 2053 | { |
2011 | bool res = focusNextPrevChild ( true ); | 2054 | bool res = focusNextPrevChild ( true ); |
2012 | } | 2055 | } |
2013 | void KOMonthView::prevCell() | 2056 | void KOMonthView::prevCell() |
2014 | { | 2057 | { |
2015 | focusNextPrevChild ( false ); | 2058 | focusNextPrevChild ( false ); |
2016 | } | 2059 | } |
2060 | |||
2061 | void KOMonthView::slotNewTodo() | ||
2062 | { | ||
2063 | //qDebug("KOMonthView::slotNewTodo() "); | ||
2064 | if ( mPopupCell ){ | ||
2065 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | ||
2066 | emit newTodoSignal(dt,true); | ||
2067 | } | ||
2068 | mPopupCell = 0; | ||
2069 | } | ||
2070 | void KOMonthView::slotNewEvent() | ||
2071 | { | ||
2072 | if ( mPopupCell ) { | ||
2073 | QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); | ||
2074 | emit newEventSignal( dt ); | ||
2075 | } | ||
2076 | //qDebug("KOMonthView::slotNewEvent() "); | ||
2077 | mPopupCell = 0; | ||
2078 | } | ||
2079 | |||
2080 | void KOMonthView::slotEditJournal() | ||
2081 | { | ||
2082 | if ( mPopupCell ) | ||
2083 | emit showJournalSignal( 7, mPopupCell->date() ); | ||
2084 | //qDebug("KOMonthView::slotEditJournal() "); | ||
2085 | mPopupCell = 0; | ||
2086 | } | ||
2087 | |||
2088 | void KOMonthView::setPopupCell( MonthViewCell * c) | ||
2089 | { | ||
2090 | mPopupCell = c; | ||
2091 | } | ||