author | zautrix <zautrix> | 2005-04-02 08:36:37 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-02 08:36:37 (UTC) |
commit | e7cb4c20af8b07bf923c864026481ce316c40e1d (patch) (side-by-side diff) | |
tree | c88b2d0c01ce683e73ea9f4657f4d5c6fbe6f922 /korganizer | |
parent | 7aefe488d1fe0c34cf29460f48a9a97d632f615e (diff) | |
download | kdepimpi-e7cb4c20af8b07bf923c864026481ce316c40e1d.zip kdepimpi-e7cb4c20af8b07bf923c864026481ce316c40e1d.tar.gz kdepimpi-e7cb4c20af8b07bf923c864026481ce316c40e1d.tar.bz2 |
more fixes
-rw-r--r-- | korganizer/koagendaview.cpp | 86 | ||||
-rw-r--r-- | korganizer/kodaymatrix.cpp | 8 |
2 files changed, 81 insertions, 13 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index 2b05d37..8d32152 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp @@ -1,413 +1,477 @@ /* This file is part of KOrganizer. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qhbox.h> #include <qvbox.h> #include <qlabel.h> #include <qframe.h> #include <qlayout.h> #ifndef KORG_NOSPLITTER #include <qsplitter.h> #endif #include <qfont.h> #include <qfontmetrics.h> #include <qpopupmenu.h> #include <qtooltip.h> #include <qpainter.h> #include <qpushbutton.h> #include <qapplication.h> #include <kapplication.h> #include <KDGanttMinimizeSplitter.h> #include <kdebug.h> #include <kstandarddirs.h> #include <kiconloader.h> #include <klocale.h> #include <kconfig.h> #include <kglobal.h> #include "calendarview.h" #include "koviewmanager.h" #include <libkcal/calendar.h> #include <libkcal/icaldrag.h> #include <libkcal/dndfactory.h> #include <kcalendarsystem.h> #include "koglobals.h" #ifndef KORG_NOPLUGINS #include "kocore.h" #endif #include "koprefs.h" #include "koagenda.h" #include "koagendaitem.h" #ifndef KORG_NOPRINTER #include "calprinter.h" #endif #include "koagendaview.h" //#include "koagendaview.moc" //extern bool globalFlagBlockPainting; extern int globalFlagBlockAgenda; extern int globalFlagBlockStartup; 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) { - // if ( globalFlagBlockAgenda ) - // return; - // bug: the parameters cx, cy, cw, ch are the areas that need to be - // redrawn, not the area of the widget. unfortunately, this - // code assumes the latter... - - // now, for a workaround... - // these two assignments fix the weird redraw bug + 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(); + + if (!KGlobal::locale()->use12Clock()) { + if ( QApplication::desktop()->width() <= 320 ) + suffix = "00"; + 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); + timeHeight = (timeHeight-1) /2 -1; + while (y < cy + ch+mCellHeight) { + p->drawLine(startW-tw2+1 ,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); + } + + // 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 -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 = ""; + test = "00"; else test = "00"; } QFont sFont = font(); sFont.setPointSize( sFont.pointSize()/2 ); QFontMetrics fmS( sFont ); mMiniWidth += fmS.width( test ) + frameWidth()*2 +4 ; // 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); if ( tSize < 4 ) tSize = 4; if ( tSize > 22 ) tSize = 22; tSize = (tSize/2)*2; if ( tSize == KOPrefs::instance()->mHourSize ) return; KOPrefs::instance()->mHourSize = tSize; emit scaleChanged(); } /** This is called in response to repaint() */ void TimeLabels::paintEvent(QPaintEvent*) { // kdDebug() << "paintevent..." << endl; // this is another hack! // QPainter painter(this); //QString c repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); } //////////////////////////////////////////////////////////////////////////// EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) : QFrame(parent,name) { mColumns = 1; mTopBox = 0; mLocation = loc; mTopLayout = 0; mPaintWidget = 0; mXOffset = 0; if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); else mPixmap = SmallIcon("1downarrow"); mEnabled.resize(mColumns); mEnabled.fill( false ); setMinimumHeight(mPixmap.height()); } EventIndicator::~EventIndicator() { } void EventIndicator::drawContents(QPainter *p) { // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; KDGanttSplitterHandle* han = 0; if ( mPaintWidget ) han = mPaintWidget->firstHandle(); if ( ! han ) { int i; for(i=0;i<mColumns;++i) { if (mEnabled[i]) { int cellWidth = contentsRect().right()/mColumns; int xOffset = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : i*cellWidth + (cellWidth -mPixmap.width()) /2; p->drawPixmap(QPoint(1+xOffset,0),mPixmap); } } } else { han->repaint(); //mPaintWidget->setBackgroundColor( red ); QPainter pa( han ); int i; bool setColor = false; for(i=0;i<mColumns;++i) { if (mEnabled[i]) { setColor = true; int cellWidth = contentsRect().right()/mColumns; int xOffset = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : i*cellWidth + cellWidth/2 -mPixmap.width()/2; pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); //qDebug("222draw pix %d ",xOffset ); } } pa.end(); } } void EventIndicator::setXOffset( int x ) { mXOffset = x; } void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) { mPaintWidget = w; setMaximumHeight(0); setMinimumHeight(0); } void EventIndicator::changeColumns(int columns) { mColumns = columns; mEnabled.resize(mColumns); update(); } void EventIndicator::enableColumn(int column, bool enable) { mEnabled[column] = enable; } //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : KOEventView (cal,parent,name) { mBlockUpdating = true; mStartHour = 8; mSelectedDates.append(QDate::currentDate()); mLayoutDayLabels = 0; mDayLabelsFrame = 0; mDayLabels = 0; bool isRTL = KOGlobals::self()->reverseLayout(); QPixmap expandPix; if ( KOPrefs::instance()->mVerticalScreen ) { expandPix = SmallIcon( "1updownarrow" ); } else { expandPix = SmallIcon("1leftrightarrow" ); } QBoxLayout *topLayout = new QVBoxLayout(this); // Create day name labels for agenda columns @@ -485,445 +549,449 @@ KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), i18n("Toggle Alarm"),mAgenda, SLOT(popupAlarm()),true); connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); // make connections between dependent widgets mTimeLabels->setAgenda(mAgenda); // Update widgets to reflect user preferences // updateConfig(); // createDayLabels(); // these blank widgets make the All Day Event box line up with the agenda dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); // Scrolling connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), mTimeLabels, SLOT(positionChanged())); connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), SLOT(setContentsPos(int))); connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); // Create/Show/Edit/Delete Event connect(mAgenda,SIGNAL(newEventSignal(int,int)), SLOT(newEvent(int,int))); connect(mAgenda,SIGNAL(newTodoSignal(int,int)), SLOT(newTodo(int,int))); connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), SLOT(newEvent(int,int,int,int))); connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), SLOT(newEventAllDay(int,int))); connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), SLOT(newTodoAllDay(int,int))); connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), SLOT(newEventAllDay(int,int))); connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), SLOT(newTimeSpanSelected(int,int,int,int))); connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), SIGNAL(editIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), SIGNAL(editIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), SIGNAL(showIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), SIGNAL(deleteIncidenceSignal(Incidence *))); connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), SIGNAL(deleteIncidenceSignal(Incidence *))); connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), SLOT(updateEventDates(KOAgendaItem *, int ))); connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), SLOT(updateEventDates(KOAgendaItem *, int))); // event indicator update connect(mAgenda,SIGNAL(lowerYChanged(int)), SLOT(updateEventIndicatorTop(int))); connect(mAgenda,SIGNAL(upperYChanged(int)), SLOT(updateEventIndicatorBottom(int))); // drag signals /* connect(mAgenda,SIGNAL(startDragSignal(Event *)), SLOT(startDrag(Event *))); connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), SLOT(startDrag(Event *))); */ // synchronize selections connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), mAllDayAgenda, SLOT( deselectItem() ) ); connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), mAgenda, SLOT( deselectItem() ) ); connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), SIGNAL( incidenceSelected( Incidence * ) ) ); connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), SIGNAL( incidenceSelected( Incidence * ) ) ); connect( mAgenda, SIGNAL( resizedSignal() ), SLOT( updateConfig( ) ) ); connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), SLOT( addToCalSlot(Incidence * , Incidence *) ) ); // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); } void KOAgendaView::toggleAllDay() { if ( mSplitterAgenda->firstHandle() ) mSplitterAgenda->firstHandle()->toggle(); } void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) { calendar()->addIncidence( inc ); if ( incOld ) { if ( incOld->type() == "Todo" ) emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); else emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); } } KOAgendaView::~KOAgendaView() { delete mAgendaPopup; delete mAllDayAgendaPopup; delete KOAgendaItem::paintPix(); delete KOAgendaItem::paintPixSel(); } void KOAgendaView::resizeEvent( QResizeEvent* e ) { //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); bool uc = false; int ow = e->oldSize().width(); int oh = e->oldSize().height(); int w = e->size().width(); int h = e->size().height(); if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) uc = true; //qDebug("view changed %d %d %d %d ", ow, oh , w , h); } 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; // ### 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 ) maxWid = 20; QFont dlf = KOPrefs::instance()->mTimeLabelsFont; QFontMetrics fm ( dlf ); int selCount = mSelectedDates.count(); 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 ( 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 ) dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ).left(2) ); else +#endif dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); dayLabel->show(); DateList::ConstIterator dit; bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); int counter = -1; for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { ++counter; QDate date = *dit; // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); if ( ! appendLabels ) { dayLabel = mDayLabelsList.next(); if ( !dayLabel ) appendLabels = true; } if ( appendLabels ) { dayLabel = getNewDaylabel(); } dayLabel->setMinimumWidth( 1 ); dayLabel->setMaximumWidth( 10240 ); dayLabel->setFont( dlf ); dayLabel->show(); dayLabel->setAutoRepeat( false ); dayLabel->setNum( counter ); QString str; int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); switch ( maxLen ) { case 2: str = QString::number( date.day() ); break; case 3: str = dayName.left( 1 ) +QString::number( date.day()); break; case 4: str = dayName.left( 1 ) + " " +QString::number( date.day()); break; case 5: str = dayName.left( 2 ) + " " +QString::number( date.day()); break; case 6: str = dayName.left( 3 ) + " " +QString::number( date.day()); break; default: break; } if ( oneday ) { QString addString; if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) addString = i18n("Today"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) addString = i18n("Tomorrow"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) addString = i18n("Yesterday"); else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) 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->setFont( dlf ); dayLabel->setAutoRepeat( true ); dayLabel->show(); dayLabel->setNum( -2 ); dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); //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); return selected; } void KOAgendaView::updateView() { if ( mBlockUpdating ) return; // kdDebug() << "KOAgendaView::updateView()" << endl; fillAgenda(); } /* Update configuration settings for the agenda view. This method is not complete. */ void KOAgendaView::updateConfig() { if ( mBlockUpdating ) return; if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { int old = KOPrefs::instance()->mHourSize; KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index b8a0f09..8affe50 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp @@ -578,397 +578,397 @@ void KODayMatrix::mouseMoveEvent (QMouseEvent* e) repaint(false); } } } // ---------------------------------------------------------------------------- // D R A G ' N D R O P H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) { #ifndef KORG_NODND if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } // some visual feedback // oldPalette = palette(); // setPalette(my_HilitePalette); // update(); #endif } void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) { #ifndef KORG_NODND if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } e->accept(); #endif } void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) { #ifndef KORG_NODND // setPalette(oldPalette); // update(); #endif } void KODayMatrix::dropEvent(QDropEvent *e) { #ifndef KORG_NODND // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { e->ignore(); return; } DndFactory factory( mCalendar ); Event *event = factory.createDrop(e); if (event) { e->acceptAction(); Event *existingEvent = mCalendar->event(event->uid()); if(existingEvent) { // uniquify event event->recreate(); /* KMessageBox::sorry(this, i18n("Event already exists in this calendar."), i18n("Drop Event")); delete event; return; */ } // kdDebug() << "Drop new Event" << endl; // Adjust date QDateTime start = event->dtStart(); QDateTime end = event->dtEnd(); int duration = start.daysTo(end); int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); start.setDate(days[idx]); end.setDate(days[idx].addDays(duration)); event->setDtStart(start); event->setDtEnd(end); mCalendar->addEvent(event); emit eventDropped(event); } else { // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; e->ignore(); } #endif } // ---------------------------------------------------------------------------- // P A I N T E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::paintEvent(QPaintEvent * pevent) { if ( width() <= 0 || height() <= 0 ) return; if ( mPendingUpdateBeforeRepaint ) { updateViewTimed(); mPendingUpdateBeforeRepaint = false; } if ( myPix.width() != width() || myPix.height()!=height() ) { myPix.resize(size() ); mRedrawNeeded = true; } if ( mRedrawNeeded ) { //qDebug("REDRAW "); QPainter p(&myPix); p.setFont(font()); int dheight = daysize.height(); int dwidth = daysize.width(); int row,col; int selw, selh; int xyOff = frameWidth(); int colModulo = (width()-2) % 7; int rowModulo = (height()-2) % 6; //qDebug("col %d row %d ",colModulo,rowModulo ); bool isRTL = KOGlobals::self()->reverseLayout(); // draw background and topleft frame p.fillRect(0,0,width(),height(), mDefaultBackColor); p.setPen(mDefaultTextColor); p.drawRect(0, 0, width(), height()); int mSelStartT = mSelStart; int mSelEndT = mSelEnd; if ( mSelEndT >= NUMDAYS ) mSelEndT = NUMDAYS-1; // draw selected days with highlighted background color if (mSelStart != NOSELECTION) { bool skip = false; if ( ! mouseDown ) { int mo = days[20].month(); //qDebug("-- %d %d ", mSelStartT, mSelEndT); //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); int startMo = days[mSelStartT].month(); int endMo = days[mSelEndT].month(); if ( startMo == 12 && mo == 1 && endMo <= 2 ) startMo = 1; if ( endMo == 1 && mo == 12 ) endMo = 12; if ( mo == 12 && startMo == 1 ) startMo = 13; if ( (startMo > mo || endMo < mo) ) { skip = true; } else { if ( days[mSelStartT].month() != mo ) { int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); mSelStartT += add +1; } if ( days[mSelEndT].month() != mo ) { int sub = days[mSelEndT].day(); mSelEndT -= sub ; } } } //qDebug("SKIP %d ", skip); if ( ! skip ) { row = mSelStartT/7; col = mSelStartT -row*7; QColor selcol = KOPrefs::instance()->mHighlightColor; int addCol = 0; int addRow = 0; int addRow2 = 0; int addCol2 = 0; if (row == mSelEndT/7) { if ( rowModulo ) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } if ( colModulo ) { int colt1 = mSelEndT%7; //qDebug("colt1 %d ", colt1 ); if ( colt1 >= 7 - colModulo ) addCol = colt1 - 7 + colModulo+1; int colt = mSelStartT%7; if ( colt >= 7 - colModulo ) addCol2 = colt - 7 + colModulo; addCol -= addCol2; //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); } // Single row selection - if ( row == 0) - addRow = 1; + //if ( row == 0) + // addRow = 1; p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); } else { // draw first row to the right if ( colModulo ) { if ( col >= 7 - colModulo ) addCol2 = col - 7 + colModulo; } if ( rowModulo ) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } - if ( row == 0) - addRow = 1; + //if ( row == 0) + // addRow = 1; int drawWid = width()-(col*dwidth+1+addCol2)-1; p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, drawWid, dheight+1, selcol); // draw full block till last line selh = mSelEndT/7-row; addRow = 0; if ( rowModulo ) { if ( mSelEndT/7 >= 6 - rowModulo ) addRow = mSelEndT/7 - 5 + rowModulo; } //qDebug("%d %d %d ",selh, row, addRow ); int addrow2 = addRow-selh+1; if ( addrow2 < 0 ) addrow2 = 0; if (selh > 1) { p.fillRect(1, (row+1)*dheight+addrow2, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); } // draw last block from left to mSelEndT selw = mSelEndT-7*(mSelEndT/7)+1; //qDebug("esl %d ",selw ); int add = 0; if ( colModulo ) { add = 7 - colModulo; if ( selw > add ) add = selw - add; else add = 0; } //qDebug("add %d ", add); p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, selw*dwidth+add, dheight+1, selcol); } } } // iterate over all days in the matrix and draw the day label in appropriate colors QColor actcol = mDefaultTextColorShaded; p.setPen(actcol); QPen tmppen; for(int i = 0; i < NUMDAYS; i++) { row = i/7; col = isRTL ? 6-(i-row*7) : i-row*7; // if it is the first day of a month switch color from normal to shaded and vice versa if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { if (actcol == mDefaultTextColorShaded) { actcol = mDefaultTextColor; } else { actcol = mDefaultTextColorShaded; } p.setPen(actcol); } if (actcol == mDefaultTextColorShaded) { if ( ! mouseDown ) { continue; } } //Reset pen color after selected days block if (i == mSelEndT+1) { p.setPen(actcol); } // if today then draw rectangle around day if (today == i) { tmppen = p.pen(); QPen mTodayPen(p.pen()); if ( daysize.width() < 20 ) mTodayPen.setWidth(1); else mTodayPen.setWidth(mTodayMarginWidth); //draw red rectangle for holidays if (!mHolidays[i].isNull()) { if (actcol == mDefaultTextColor) { mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); } else { mTodayPen.setColor(mHolidayColorShaded); } } //draw gray rectangle for today if in selection if (i >= mSelStartT && i <= mSelEndT) { QColor grey("grey"); mTodayPen.setColor(grey); } p.setPen(mTodayPen); int addCol = 0; int addRow = 0; if (rowModulo) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } if ( colModulo ) { if ( col >= 7 - colModulo ) addCol = col - 6 + colModulo-1; } addCol += 1; if ( row == 0 ) addRow = 1; p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth+1, dheight+1); p.setPen(tmppen); } // if any events are on that day then draw it using a bold font if ( eDays.testBit(i) ) { QFont myFont = font(); myFont.setBold(true); p.setFont(myFont); } // if it is a holiday then use the default holiday color if ( !mHolidays[i].isNull()) { if ( bDays.testBit(i) ) { if ( hDays.testBit(i) ) p.setPen(QColor(Qt::green)); else p.setPen(QColor(Qt::green).dark()); } else { if (actcol == mDefaultTextColor ) { p.setPen(KOPrefs::instance()->mHolidayColor); } else { p.setPen(mHolidayColorShaded); } } } // draw selected days with special color // DO NOT specially highlight holidays in selection ! if (i >= mSelStartT && i <= mSelEndT) { ;//p.setPen(mSelectedDaysColor); } int addCol = 0; int addRow = 0; if ( colModulo ) { if ( col >= 7 - colModulo ) addCol = col - 7 + colModulo; } if ( rowModulo ) { if ( row >= 6 - rowModulo ) addRow = row - 5 + rowModulo; } //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); ++addCol;//++addCol; if ( row == 0) addRow = 1; p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); // reset color to actual color if (!mHolidays[i].isNull()) { p.setPen(actcol); } // reset bold font to plain font if ( eDays.testBit(i)) { QFont myFont = font(); myFont.setBold(false); p.setFont(myFont); } } } else { //qDebug("NO redraw "); } bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); mRedrawNeeded = false; } // ---------------------------------------------------------------------------- // R E SI Z E E V E N T H A N D L I N G // ---------------------------------------------------------------------------- void KODayMatrix::resizeEvent(QResizeEvent *) { QRect sz = frameRect(); daysize.setHeight(sz.height()*7 / NUMDAYS); daysize.setWidth(sz.width() / 7); } QSize KODayMatrix::sizeHint() const { QFontMetrics fm ( font() ); int wid = fm.width( "30") *7+3; int hei = fm.height() * 6+3; //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); return QSize ( wid, hei ); } |