author | zautrix <zautrix> | 2005-04-02 17:04:37 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-02 17:04:37 (UTC) |
commit | f3c3a836ae97ef3e65cfbcd22156b0ba6eaae578 (patch) (side-by-side diff) | |
tree | 726772f4d535882705cda8cab76ae5460a29beab /korganizer/koagendaview.cpp | |
parent | 470327bf20835778a29cd2ce9414baa0cc176829 (diff) | |
download | kdepimpi-f3c3a836ae97ef3e65cfbcd22156b0ba6eaae578.zip kdepimpi-f3c3a836ae97ef3e65cfbcd22156b0ba6eaae578.tar.gz kdepimpi-f3c3a836ae97ef3e65cfbcd22156b0ba6eaae578.tar.bz2 |
fixes
-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 @@ -99,218 +99,139 @@ TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : } 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(); @@ -713,68 +634,72 @@ void KOAgendaView::slotDaylabelClicked( int 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; } @@ -891,59 +816,56 @@ void KOAgendaView::createDayLabels() 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(); } |