-rw-r--r-- | korganizer/koagendaview.cpp | 130 |
1 files changed, 26 insertions, 104 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index 95388ef..880d399 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp @@ -75,266 +75,187 @@ extern int globalFlagBlockAgendaItemPaint; extern int globalFlagBlockAgendaItemUpdate; extern int globalFlagBlockLabel; using namespace KOrg; TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : QScrollView(parent,name,f) { myPix.resize( 1, 1 ); mRows = rows; mRedrawNeeded = true; setMinimumHeight( 20 ); mCellHeight = KOPrefs::instance()->mHourSize*4; enableClipper(true); setHScrollBarMode(AlwaysOff); setVScrollBarMode(AlwaysOff); resizeContents(50,mRows * mCellHeight); viewport()->setBackgroundMode( PaletteBackground ); } void TimeLabels::setCellHeight(int height) { mCellHeight = height; } /* Optimization so that only the "dirty" portion of the scroll view is redrawn. Unfortunately, this is not called by default paintEvent() method. */ void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) { cx = contentsX() + frameWidth()*2; cw = contentsWidth() ; // end of workaround int cell = ((int)(cy/mCellHeight)); int y = cell * mCellHeight; QFontMetrics fm = fontMetrics(); QString hour; QString suffix = "am"; int timeHeight = fm.ascent(); - QFont nFont = p->font(); + QFont nFont = font(); + p->setFont( font()); if (!KGlobal::locale()->use12Clock()) { - if ( QApplication::desktop()->width() <= 320 ) suffix = "00"; - else - suffix = "00"; - } + } else + if (cell > 11) suffix = "pm"; if ( timeHeight > mCellHeight ) { timeHeight = mCellHeight-1; int pointS = nFont.pointSize(); while ( pointS > 4 ) { nFont.setPointSize( pointS ); fm = QFontMetrics( nFont ); if ( fm.ascent() < mCellHeight ) break; -- pointS; } fm = QFontMetrics( nFont ); timeHeight = fm.ascent(); } //timeHeight -= (timeHeight/4-2); QFont sFont = nFont; sFont.setPointSize( sFont.pointSize()/2 ); QFontMetrics fmS( sFont ); int sHei = fmS.ascent() ; //sHei -= (sHei/4-2); - int startW = this->width() - frameWidth()-2; + int startW = mMiniWidth - frameWidth()-2 ; int tw2 = fmS.width(suffix); - timeHeight = (timeHeight-1) /2 -1; + timeHeight = (timeHeight-1) /2 -1; + //testline + //p->drawLine(0,0,0,contentsHeight()); while (y < cy + ch+mCellHeight) { - p->drawLine(startW-tw2+1 ,y,cw,y); + p->drawLine(startW-tw2 ,y,cw+2,y); hour.setNum(cell); // handle 24h and am/pm time formats if (KGlobal::locale()->use12Clock()) { - if (cell > 11) suffix = "pm"; - else - suffix = "am"; + if (cell == 12) suffix = "pm"; if (cell == 0) hour.setNum(12); if (cell > 12) hour.setNum(cell - 12); } // center and draw the time label int timeWidth = fm.width(hour); - int offset = startW - timeWidth - tw2 ; + int offset = startW - timeWidth - tw2 -1 ; p->setFont( nFont ); p->drawText( offset, y+ timeHeight, hour); p->setFont( sFont ); - offset = startW - tw2+1; + offset = startW - tw2; p->drawText( offset, y -1, suffix); // increment indices y += mCellHeight; cell++; } -#if 0 - mRedrawNeeded = true; - if ( mRedrawNeeded ) { - cx = contentsX() + frameWidth()*2; - cw = contentsWidth() ; - // end of workaround - - int cell = ((int)(cy/mCellHeight)); - int y = cell * mCellHeight; - QFontMetrics fm = fontMetrics(); - QString hour; - QString suffix; - int timeHeight = fm.ascent(); - QFont nFont = p->font(); - - if (!KGlobal::locale()->use12Clock()) { - if ( QApplication::desktop()->width() <= 320 ) - suffix = ""; - else - suffix = "00"; - } - - if ( timeHeight > mCellHeight ) { - timeHeight = mCellHeight-1; - int pointS = nFont.pointSize(); - while ( pointS > 4 ) { - nFont.setPointSize( pointS ); - fm = QFontMetrics( nFont ); - if ( fm.ascent() < mCellHeight ) - break; - -- pointS; - } - fm = QFontMetrics( nFont ); - timeHeight = fm.ascent(); - } - //timeHeight -= (timeHeight/4-2); - QFont sFont = nFont; - sFont.setPointSize( sFont.pointSize()/2 ); - QFontMetrics fmS( sFont ); - int sHei = fmS.ascent() ; - //sHei -= (sHei/4-2); - int startW = this->width() - frameWidth()-2; - int tw2 = fmS.width(suffix); - while (y < cy + ch) { - p->drawLine(cx,y,cw,y); - hour.setNum(cell); - // handle 24h and am/pm time formats - if (KGlobal::locale()->use12Clock()) { - if (cell > 11) suffix = "pm"; - else - suffix = "am"; - if (cell == 0) hour.setNum(12); - if (cell > 12) hour.setNum(cell - 12); - tw2 = fmS.width(suffix); - } - - // center and draw the time label - int timeWidth = fm.width(hour); - int offset = startW - timeWidth - tw2 ; - p->setFont( nFont ); - p->drawText( offset, y+ timeHeight, hour); - p->setFont( sFont ); - offset = startW - tw2+1; - p->drawText( offset, y+ sHei, suffix); - - // increment indices - y += mCellHeight; - cell++; - } - } else { - //qDebug("NO redraw "); - } - // double buffer not yet implemented - //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); - //mRedrawNeeded = false; -#endif } /** Calculates the minimum width. */ int TimeLabels::minimumWidth() const { return mMiniWidth; } /** updates widget's internal state */ void TimeLabels::updateConfig() { mRedrawNeeded = true; // set the font // config->setGroup("Fonts"); // QFont font = config->readFontEntry("TimeBar Font"); setFont(KOPrefs::instance()->mTimeBarFont); QString test = "20"; if (KGlobal::locale()->use12Clock()) test = "12"; mMiniWidth = fontMetrics().width(test); if (KGlobal::locale()->use12Clock()) test = "pm"; else { - if ( QApplication::desktop()->width() <= 320 ) - test = "00"; - else - test = "00"; + test = "00"; } QFont sFont = font(); sFont.setPointSize( sFont.pointSize()/2 ); QFontMetrics fmS( sFont ); - mMiniWidth += fmS.width( test ) + frameWidth()*2 +4 ; + mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ; + qDebug("testwid %d %d", mMiniWidth ,fmS.width( test )); // update geometry restrictions based on new settings setFixedWidth( mMiniWidth ); // update HourSize mCellHeight = KOPrefs::instance()->mHourSize*4; resizeContents(50,mRows * mCellHeight); } /** update time label positions */ void TimeLabels::positionChanged() { int adjustment = mAgenda->contentsY(); setContentsPos(0, adjustment); } /** */ void TimeLabels::setAgenda(KOAgenda* agenda) { mAgenda = agenda; } void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) { mMouseDownY = e->pos().y(); mOrgCap = topLevelWidget()->caption(); } void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) { int diff = mMouseDownY - e->pos().y(); if ( diff < 10 && diff > -10 ) return; int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; if ( tSize < 4 ) tSize = 4; if ( tSize > 22 ) tSize = 22; tSize = (tSize-2)/2; topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); } void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) { topLevelWidget()->setCaption( mOrgCap ); int diff = mMouseDownY - e->pos().y(); if ( diff < 10 && diff > -10 ) return; int tSize = KOPrefs::instance()->mHourSize + (diff/10); @@ -689,116 +610,120 @@ void KOAgendaView::resizeEvent( QResizeEvent* e ) } mUpcomingWidth = e->size().width() ; if ( mBlockUpdating || uc ) { mBlockUpdating = false; //mAgenda->setMinimumSize(800 , 600 ); //qDebug("mAgenda->resize+++++++++++++++ "); updateConfig(); //qDebug("KOAgendaView::Updating now possible "); } else createDayLabels(); //qDebug("resizeEvent end "); } void KOAgendaView::slotDaylabelClicked( int num ) { QDate firstDate = mSelectedDates.first(); if ( num == -1 ) emit showDateView( 6, firstDate ); else if (num >= 0 ) { if ( mSelectedDates.count() == 1) emit showDateView( 9, firstDate.addDays( num ) ); else emit showDateView( 3, firstDate.addDays( num ) ); } else showDateView( 10, firstDate.addDays(1) ); } KOAgendaButton* KOAgendaView::getNewDaylabel() { KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); mDayLabelsList.append( dayLabel ); mLayoutDayLabels->addWidget(dayLabel); return dayLabel ; } void KOAgendaView::createDayLabels() { if ( mBlockUpdating || globalFlagBlockLabel == 1) { // qDebug(" KOAgendaView::createDayLabels() blocked "); return; } int newHight; + if ( !mSelectedDates.count()) + return; // ### Before deleting and recreating we could check if mSelectedDates changed... // It would remove some flickering and gain speed (since this is called by // each updateView() call) int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; - if ( QApplication::desktop()->width() <= 320 ) - maxWid -= 10; mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); - if ( maxWid < 0 ) + if ( maxWid < 20 ) maxWid = 20; QFont dlf = KOPrefs::instance()->mTimeLabelsFont; QFontMetrics fm ( dlf ); int selCount = mSelectedDates.count(); + int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1; QString dayTest = "Mon 20"; //QString dayTest = "Mon 20"; int wid = fm.width( dayTest ); //maxWid -= ( selCount * 3 ); //working for QLabels - maxWid -= ( selCount * 3 ); //working for QPushButton + if ( QApplication::desktop()->width() <= 320 ) + maxWid -= ( selCount * 3 ); //working for QPushButton + else + maxWid -= ( selCount * 3 ); //working for QPushButton if ( maxWid < 0 ) maxWid = 20; int needWid = wid * selCount; //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); //if ( needWid > maxWid ) // qDebug("DAYLABELS TOOOOOOO BIG "); while ( needWid > maxWid ) { dayTest = dayTest.left( dayTest.length() - 1 ); wid = fm.width( dayTest ); needWid = wid * selCount; } int maxLen = dayTest.length(); int fontPoint = dlf.pointSize(); if ( maxLen < 2 ) { int fontPoint = dlf.pointSize(); while ( fontPoint > 4 ) { --fontPoint; dlf.setPointSize( fontPoint ); QFontMetrics f( dlf ); wid = f.width( "30" ); needWid = wid * selCount; if ( needWid < maxWid ) break; } maxLen = 2; } //qDebug("Max len %d ", dayTest.length() ); QFontMetrics tempF( dlf ); newHight = tempF.height(); mDayLabels->setFont( dlf ); // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; // mLayoutDayLabels->addSpacing(mTimeLabels->width()); //mLayoutDayLabels->addSpacing( 2 ); // QFont lFont = dlf; bool appendLabels = false; KOAgendaButton *dayLabel; dayLabel = mDayLabelsList.first(); if ( !dayLabel ) { appendLabels = true; dayLabel = getNewDaylabel(); } dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); dayLabel->setFont( dlf ); dayLabel->setNum( -1 ); //dayLabel->setAlignment(QLabel::AlignHCenter); #if 0 if ( QApplication::desktop()->width() <= 320 ) @@ -867,107 +792,104 @@ void KOAgendaView::createDayLabels() addString = i18n("Day before yesterday"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) addString = i18n("Day after tomorrow"); if ( !addString.isEmpty() ) { str = addString+", " + str; } else { str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); } } dayLabel->setText(str); //dayLabel->setAlignment(QLabel::AlignHCenter); if (date == QDate::currentDate()) { QFont bFont = dlf; bFont.setBold( true ); dayLabel->setFont(bFont); } //dayLayout->addWidget(dayLabel); #ifndef KORG_NOPLUGINS CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); CalendarDecoration *it; for(it = cds.first(); it; it = cds.next()) { QString text = it->shortText( date ); if ( !text.isEmpty() ) { QLabel *label = new QLabel(text,mDayLabels); label->setAlignment(AlignCenter); dayLayout->addWidget(label); } } for(it = cds.first(); it; it = cds.next()) { QWidget *wid = it->smallWidget(mDayLabels,date); if ( wid ) { // wid->setHeight(20); dayLayout->addWidget(wid); } } #endif } if ( ! appendLabels ) { dayLabel = mDayLabelsList.next(); if ( !dayLabel ) appendLabels = true; } if ( appendLabels ) { dayLabel = getNewDaylabel(); } //dayLabel->hide();//test only - int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ; - if ( offset < 0 ) offset = 0; - //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); - dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); + + dayLabel->setText(">"); dayLabel->setFont( dlf ); dayLabel->setAutoRepeat( true ); dayLabel->show(); dayLabel->setNum( -2 ); - dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); + dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo ); - //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); if ( !appendLabels ) { dayLabel = mDayLabelsList.next(); while ( dayLabel ) { //qDebug("!dayLabel %d",dayLabel ); dayLabel->hide(); dayLabel = mDayLabelsList.next(); } } mDayLabelsFrame->setFixedHeight( newHight + 4 ); } int KOAgendaView::maxDatesHint() { // Not sure about the max number of events, so return 0 for now. return 0; } int KOAgendaView::currentDateCount() { return mSelectedDates.count(); } QPtrList<Incidence> KOAgendaView::selectedIncidences() { QPtrList<Incidence> selected; Incidence *incidence; incidence = mAgenda->selectedIncidence(); if (incidence) selected.append(incidence); incidence = mAllDayAgenda->selectedIncidence(); if (incidence) selected.append(incidence); return selected; } DateList KOAgendaView::selectedDates() { DateList selected; QDate qd; qd = mAgenda->selectedIncidenceDate(); if (qd.isValid()) selected.append(qd); qd = mAllDayAgenda->selectedIncidenceDate(); if (qd.isValid()) selected.append(qd); |