From afc19166fcdc09d3d5b757a84abfeb0b2746f35f Mon Sep 17 00:00:00 2001 From: zautrix Date: Mon, 07 Feb 2005 10:32:40 +0000 Subject: month fixes --- (limited to 'korganizer') diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 70cbf96..234375b 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -74,7 +73,7 @@ private: KNoScrollListBox* _wid; }; - + KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) : QListBox(parent, name, WRepaintNoErase) @@ -92,7 +91,7 @@ QString KNoScrollListBox::getWhatsThisText(QPoint p) { QListBoxItem* item = itemAt ( p ); if ( ! item ) { - return i18n("Click in the cell\nto add an event!"); + return i18n("Click in the cell\nto add an event!"); } return KIncidenceFormatter::instance()->getFormattedText(((MonthViewItem*) item)->incidence()); } @@ -319,7 +318,7 @@ MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) const QPoint &) ), SLOT( contextMenu( QListBoxItem * ) ) ); connect( mItemList, SIGNAL( highlighted( QListBoxItem *) ), - SLOT( selection( QListBoxItem * ) ) ); + SLOT( selection( QListBoxItem * ) ) ); connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), SLOT( cellClicked( QListBoxItem * ) ) ); connect( mItemList, SIGNAL( clicked( QListBoxItem * ) ), @@ -407,13 +406,6 @@ void MonthViewCell::keyPressEvent ( QKeyEvent * e ) e->ignore(); } -void MonthViewCell::clear() -{ - mItemList->clear(); - QApplication::removePostedEvents ( mItemList ); - QApplication::removePostedEvents ( mLabel ); - QApplication::removePostedEvents ( this ); -} void MonthViewCell::startUpdateCell() { @@ -552,44 +544,44 @@ void MonthViewCell::insertEvent(Event *event) } void MonthViewCell::insertTodo(Todo *todo) { - QString text; mItemList->setFocusPolicy(WheelFocus); - if (todo->hasDueDate()) { - if (!todo->doesFloat()) { - text += KGlobal::locale()->formatTime(todo->dtDue().time()); - text += " "; + 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); + text += i18n("Td: %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 { - pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); + if (cat.isEmpty()) { + pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); + } else { + pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(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))); - } + pal = mStandardPalette ; } - - } else { - pal = mStandardPalette ; - } - item->setPalette( pal ); - mItemList->insertItem( item ); - mToolTip += text+"\n"; + item->setPalette( pal ); + mItemList->insertItem( item ); + mToolTip += text+"\n"; } void MonthViewCell::finishUpdateCell() { @@ -616,6 +608,7 @@ void MonthViewCell::finishUpdateCell() } void MonthViewCell::updateCell() { + qDebug("MonthViewCell::updateCell() "); if ( !mMonthView->isUpdatePossible() ) return; startUpdateCell(); @@ -783,6 +776,7 @@ void MonthViewCell::contextMenu( QListBoxItem *item ) void MonthViewCell::selection( QListBoxItem *item ) { if ( !item ) return; + mMonthView->setSelectedCell( this ); } @@ -795,11 +789,9 @@ void MonthViewCell::selection( QListBoxItem *item ) KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) : KOEventView( calendar, parent, name ), mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), - mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) + mShortDayLabels( false ), mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) { - ignoreResizeEvent = 0; - mShortDayLabelsW = false; - mShortDayLabelsM = false; + skipResize = false; clPending = true; mWidStack = new QWidgetStack( this ); QHBoxLayout* hb = new QHBoxLayout( this ); @@ -819,6 +811,7 @@ KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) mWeekStartsMonday = true; updatePossible = false; mCells.setAutoDelete( true ); + mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; mDayLabels.resize( mDaysPerWeek ); mDayLabelsW.resize( mDaysPerWeek ); QFont bfont = font(); @@ -907,7 +900,7 @@ KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); mContextMenu = eventPopup(); - //updateConfig(); //useless here ... + // updateConfig(); //useless here... // ... but we need mWidthLongDayLabel computed QFontMetrics fontmetric(mDayLabels[0]->font()); mWidthLongDayLabel = 0; @@ -1014,11 +1007,15 @@ void KOMonthView::updateConfig() } QFontMetrics fontmetric(mDayLabels[0]->font()); mWidthLongDayLabel = 0; + for (int i = 0; i < 7; i++) { int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; } + bool temp = mShowSatSunComp ; + mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; if ( ! mShowWeekView ) { + if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) computeLayout(); } updateDayLabels(); @@ -1046,26 +1043,26 @@ void KOMonthView::updateDayLabels() mDayLabelsT = &mDayLabelsW; for (int i = 0; i < 7; i++) { if (mWeekStartsMonday) { - bool show = mShortDayLabelsW; - if ( i > 4 && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) + bool show = mShortDayLabels; + if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) show = true; (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); } else { - if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsW)); - else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsW)); + if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); + else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); } } mDayLabelsT = &mDayLabels; for (int i = 0; i < 7; i++) { if (mWeekStartsMonday) { - bool show = mShortDayLabelsM; - if ( i > 4 && KOPrefs::instance()->mMonthViewSatSunTog && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) + bool show = mShortDayLabels; + if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) show = true; (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); } else { - if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); - else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); + if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabels)); + else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabels)); } } @@ -1263,14 +1260,12 @@ void KOMonthView::updateView() void KOMonthView::resizeEvent(QResizeEvent * e) { - //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); - if ( ignoreResizeEvent ) { - //qDebug("KOMonthView::resizeEvent ignored "); - --ignoreResizeEvent; + qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); + if ( skipResize ) { + skipResize = false; + qDebug("skipResize "); return; } - if ( e->size().width()+ e->size().height() < 240 ) - return; computeLayout(); clPending = true; if ( mShowWeekView ) @@ -1280,22 +1275,38 @@ void KOMonthView::resizeEvent(QResizeEvent * e) } void KOMonthView::computeLayoutWeek() { - static int widd = 0; - static int heigg = 0; - if ( widd == width() && heigg == height () ) { - return; - } - widd = width() ; - heigg = height (); + static int lastWid = 0; + static int lastHei = 0; int daysToShow; + bool combinedSatSun = false; + if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { + daysToShow = 6; + combinedSatSun = true; + } + int tWid = topLevelWidget()->size().width(); + int tHei = topLevelWidget()->size().height(); + int wid = size().width();//e int hei = size().height()-1; + + if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) + return; + + + if ( lastWid == width() && lastHei ==height() ) + return; + lastWid =width(); + lastHei = height(); + + if ( wid < hei ) daysToShow = 2; else daysToShow = 3; - bool combinedSatSun = true; + mShowSatSunComp = true; + combinedSatSun = true; + qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); QFontMetrics fm ( mWeekLabels[0]->font() ); int weeklabelwid = fm.width( "888" ); wid -= weeklabelwid; @@ -1372,8 +1383,9 @@ void KOMonthView::computeLayoutWeek() h = cellHei ; mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); - - mShortDayLabelsW = mDayLabelsW[0]->width() < mWidthLongDayLabel ; + // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); + //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); + mShortDayLabels = mDayLabelsW[0]->width() < mWidthLongDayLabel ; updateDayLabels(); bool forceUpdate = !updatePossible; updatePossible = true; @@ -1383,39 +1395,34 @@ void KOMonthView::computeLayoutWeek() } void KOMonthView::computeLayout() { - // select the appropriate heading string size. E.g. "Wednesday" or "Wed". - // note this only changes the text if the requested size crosses the - // threshold between big enough to support the full name and not big - // enough. - - int tWid = topLevelWidget()->size().width(); - int tHei = topLevelWidget()->size().height(); - - int wid = size().width();//e - int hei = size().height()-1; + - if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) - return; + static int lastWid = 0; + static int lastHei = 0; - if ( mShowWeekView ){ computeLayoutWeek(); return; } - static int widd = 0; - static int heigg = 0; - if ( widd == width() && heigg == height () ) { - return; - } - widd = width() ; - heigg = height (); - int daysToShow = 7; bool combinedSatSun = false; - if (KOPrefs::instance()->mMonthViewSatSunTog ) { + if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { daysToShow = 6; combinedSatSun = true; } + int tWid = topLevelWidget()->size().width(); + int tHei = topLevelWidget()->size().height(); + + int wid = size().width();//e + int hei = size().height()-1; + + if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) + return; + if ( lastWid == width() && lastHei ==height() ) + return; + lastWid =width(); + lastHei = height(); + qDebug("KOMonthView::computeLayout() MMM ------------------------------------ "); QFontMetrics fm ( mWeekLabels[0]->font() ); int weeklabelwid = fm.width( "888" ); wid -= weeklabelwid; @@ -1452,6 +1459,7 @@ void KOMonthView::computeLayout() w = colWid; h = cellHei ; for ( i = 0; i < mCells.count(); ++i) { + //qDebug("iii %d ", i); w = colWid; if ( ((i) % 7) >= 7-colModulo ) { ++w; @@ -1488,11 +1496,13 @@ void KOMonthView::computeLayout() y += h; } mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); - mShortDayLabelsM = mDayLabels[0]->width() < mWidthLongDayLabel ; - qDebug("dlwid %d %d ",mDayLabels[0]->width() , mWidthLongDayLabel); + // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); + //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); + mShortDayLabels = mDayLabels[0]->width() < mWidthLongDayLabel ; updateDayLabels(); bool forceUpdate = !updatePossible; updatePossible = true; + //mWeekLabels[mNumWeeks]->setText( i18n("W")); if ( forceUpdate ) updateView(); } @@ -1500,7 +1510,14 @@ void KOMonthView::computeLayout() void KOMonthView::showContextMenu( Incidence *incidence ) { mContextMenu->showIncidencePopup(incidence); - + /* + if( incidence && incidence->type() == "Event" ) { + Event *event = static_cast(incidence); + mContextMenu->showEventPopup(event); + } else { + kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; + } + */ } MonthViewCell * KOMonthView::selectedCell( ) { @@ -1508,12 +1525,15 @@ MonthViewCell * KOMonthView::selectedCell( ) } void KOMonthView::setSelectedCell( MonthViewCell *cell ) { + // qDebug("KOMonthView::setSelectedCell "); if ( mSelectedCell && mSelectedCell != cell ) { MonthViewCell * mvc = mSelectedCell; mSelectedCell = cell; mvc->deselect(); } else mSelectedCell = cell; + // if ( mSelectedCell ) + // mSelectedCell->select(); if ( !mSelectedCell ) emit incidenceSelected( 0 ); else @@ -1558,7 +1578,7 @@ void KOMonthView::keyPressEvent ( QKeyEvent * e ) mCellsW[0]->setFocus(); else mCells[0]->setFocus(); - + } e->accept(); break; diff --git a/korganizer/komonthview.h b/korganizer/komonthview.h index 9dbe319..a29a1a8 100644 --- a/korganizer/komonthview.h +++ b/korganizer/komonthview.h @@ -154,7 +154,6 @@ class MonthViewCell : public QWidget void deselect(); void select(); - void clear(); #ifdef DESKTOP_VERSION static QToolTipGroup *toolTipGroup(); @@ -226,9 +225,9 @@ class KOMonthView: public KOEventView const QDate &, const QDate &); bool isMonthView() { return true; } bool isUpdatePossible() { return updatePossible; } - void setIgnoreResizeEvent( int c ) { ignoreResizeEvent = c ;} MonthViewCell * selectedCell(); + bool skipResize; public slots: virtual void updateView(); virtual void updateConfig(); @@ -259,7 +258,6 @@ class KOMonthView: public KOEventView void updateDayLabels(); private: - int ignoreResizeEvent; int currentWeek(); bool clPending; QWidgetStack * mWidStack; @@ -271,6 +269,7 @@ class KOMonthView: public KOEventView int mNumWeeks; int mNumCells; bool mWeekStartsMonday; + bool mShowSatSunComp; void computeLayout(); void computeLayoutWeek(); @@ -281,8 +280,7 @@ class KOMonthView: public KOEventView QPtrVector mDayLabelsW; QPtrVector mWeekLabelsW; - bool mShortDayLabelsM; - bool mShortDayLabelsW; + bool mShortDayLabels; int mWidthLongDayLabel; QDate mStartDate; diff --git a/korganizer/koviewmanager.cpp b/korganizer/koviewmanager.cpp index 62d3e7f..ba15f7f 100644 --- a/korganizer/koviewmanager.cpp +++ b/korganizer/koviewmanager.cpp @@ -201,7 +201,7 @@ void KOViewManager::showView(KOrg::BaseView *view, bool fullScreen ) full = mMainView->leftFrame()->isVisible(); } else { if ( view == mMonthView && mMonthView) - mMonthView->setIgnoreResizeEvent( 1 ); + mMonthView->skipResize = true ; mCurrentView = view; // bool full = fullScreen; bool isFull = !mMainView->leftFrame()->isVisible(); -- cgit v0.9.0.2