📄 dayview.cpp
字号:
switch (typ) { case ScrollingDay: { int rx = 0; int ry = 0; int rh = 0; int t = 0; while (t < 24) { QString s = TimeString::localH(t); ry = posOfHour(t); t++; rh = posOfHour(t) - ry; if (ry > y + h) break; if (ry + rh < y) continue; // draw this rect. QPen pn = p->pen(); p->setPen(lightGray); p->drawLine( rx, ry - 1, width(), ry - 1); p->setPen(pn); bool isDown; if ( t > firstSel && t <= lastSel + 1 ){ p->setFont(selectFont); isDown = TRUE; } else { p->setFont(f); isDown = FALSE; }#if (QT_VERSION-0 >= 0x030000) style().drawPrimitive( QStyle::PE_ButtonBevel, p, QRect(rx, ry, time_width, time_height), cgUp, isDown ? QStyle::Style_Enabled | QStyle::Style_Down : QStyle::Style_Raised);//QStyle::Style_Enabled | QStyle::Style_Up); //style().drawToolButton(p, rx, ry, time_width, time_height, //cgUp, t > firstSel && t <= lastSel + 1 ); style().drawItem(p, QRect(rx+day_time_margin, ry, time_width-day_time_margin*2, time_height), AlignRight | AlignTop, cgUp, TRUE, 0, s);#else p->fillRect( rx, ry, time_width, time_height, white );# ifndef QTOPIA_PHONE style().drawToolButton(p, rx, ry, time_width, time_height, cgUp, t > firstSel && t <= lastSel + 1 );#endif style().drawItem(p, rx+day_time_margin, ry, time_width-day_time_margin*2, time_height, AlignRight | AlignTop, cgUp, TRUE, 0, s);#endif p->setPen(pn); } } break; case CompressedDay: { int hours[24]; QString hourStrings[24]; int num_hours = 0; const TimeList × = ((CompressedDayLayout *)itemList)->times; int cur = 0; int prev = 0; int i; for ( i = 0; i < 24; i++ ) { cur = times.hits(i); if ( cur != prev ) { prev = cur; hours[num_hours] = i; //hourStrings[num_hours] = TimeString::timeString( times.time( i ), FALSE ); hourStrings[num_hours] = TimeString::localHM( times.time(i), TimeString::Short ); num_hours++; } } int rx = 0; int ry = 0; int rh = 0; int t = 0; for ( i = 0; i < num_hours; i++ ) { t = hours[i]; QString s = hourStrings[i]; ry = posOfHour(t); t++; rh = posOfHour(t + 1) - ry; if (ry > y + h) break; if (ry + rh < y) continue; // draw this rect. QPen pn = p->pen(); p->setPen(lightGray); p->drawLine( rx, ry - 1, width(), ry - 1); p->setPen(pn); bool isDown; if ( t > firstSel && t <= lastSel + 1 ){ p->setFont(selectFont); isDown = TRUE; } else { p->setFont(f); isDown = FALSE; }#if (QT_VERSION-0 >= 0x030000) style().drawPrimitive( QStyle::PE_ButtonBevel, p, QRect(rx, ry, time_width, rh), cgUp, isDown ? QStyle::Style_Enabled | QStyle::Style_Down : QStyle::Style_Raised);//QStyle::Style_Enabled | QStyle::Style_Up); //style().drawToolButton(p, rx, ry, time_width, rh, //cgUp, t > firstSel && t <= lastSel + 1 ); style().drawItem(p, QRect(rx+day_time_margin, ry, time_width-day_time_margin*2, rh), AlignRight | AlignTop, cgUp, TRUE, 0, s);#else p->fillRect( rx, ry, time_width, rh, white );# ifndef QTOPIA_PHONE style().drawToolButton(p, rx, ry, time_width, rh, cgUp, t > firstSel && t <= lastSel + 1 );# endif style().drawItem(p, rx+day_time_margin, ry, time_width-day_time_margin*2, rh, AlignRight | AlignTop, cgUp, TRUE, 0, s);#endif p->setPen(pn); } } break; case AllDay: break; } if ( isClipped ) p->setClipRegion( oldClip ); p->setClipping( isClipped );}int DayViewContents::posOfHour(int h) const{ switch (typ) { case ScrollingDay: // all hours, regardless of height. return h < 0 ? 0 : h*time_height; case CompressedDay: if ( h <= 0 ) return 0; else if ( h > 25 ) return height(); else { const TimeList × = ((CompressedDayLayout *)itemList)->times; int n = times.scale( times.height( h ), height() ); if ( h == 24 && n == 0 ) return height(); return n; } default: return 0; } return 0;}int DayViewContents::hourAtPos(int h) const { switch (typ) { case ScrollingDay: // all hours, regardless of height. return h == 0 ? 0 : h/time_height; case CompressedDay: { const TimeList × = ((CompressedDayLayout *)itemList)->times; for ( int i = 1; i <= 24; i++ ) { int n = times.scale( times.height( i ), height() ); if ( n >= h ) return i - 1; } return 0; } default: return 0; } return 0;}//===========================================================================DayView::DayView( DateBookTable *newDb, bool startOnMonday, QWidget *parent, const char *name ) : PeriodView( newDb, startOnMonday, parent, name ){ QFontMetrics fm( font() ); day_height = fm.height() + 5;#ifdef QTOPIA_DESKTOP day_height += 2; // difference in font metrics?#endif QVBoxLayout *layout = new QVBoxLayout(this);#ifdef USE_LABEL_HEADER QHBox *header = new QHBox( this ); header->setBackgroundMode(PaletteButton); header->setMargin( 2 ); header1 = new QLabel(header); header1->setBackgroundMode(PaletteButton); header1->setAlignment(AlignLeft); header1->setText(header1Text(cDate)); header2 = new QLabel(header); header2->setBackgroundMode(PaletteButton); header2->setAlignment(AlignRight); header2->setText(header2Text(cDate));#else header = new DayViewHeader( startOnMonday, this, "day header" ); // No tr header->setDate( cDate.year(), cDate.month(), cDate.day() );#endif layout->addWidget(header); allView = new DayViewContents( DayViewContents::AllDay, this, "all day view" ); // No tr allView->setFocusPolicy(NoFocus); layout->addWidget(allView); view = new DayViewContents( DayViewContents::ScrollingDay, this, "day view" ); // No tr view->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); view->setFrameStyle( QFrame::NoFrame ); allView->setFrameStyle( QFrame::NoFrame ); layout->addWidget(view);#ifndef USE_LABEL_HEADER connect( header, SIGNAL( dateChanged(const QDate&) ), this, SLOT( selectDate(const QDate&) ) );#endif connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); connect( view, SIGNAL(keyPressed(const QString&)), this, SIGNAL(newEvent(const QString&)) ); connect( view, SIGNAL(editEvent(const PimEvent&)), this, SIGNAL(editEvent(const PimEvent&)) ); connect( view, SIGNAL(removeEvent(const PimEvent&)), this, SIGNAL(removeEvent(const PimEvent&)) ); connect( view, SIGNAL(beamEvent(const PimEvent&)), this, SIGNAL(beamEvent(const PimEvent&)) ); connect( view, SIGNAL(editOccurrence(const Occurrence&)), this, SIGNAL(editOccurrence(const Occurrence&)) ); connect( view, SIGNAL(removeOccurrence(const Occurrence&)), this, SIGNAL(removeOccurrence(const Occurrence&)) ); connect( view, SIGNAL(showDetails()), this, SIGNAL(showDetails()) ); connect( view, SIGNAL(setCurrentEvent(const PimEvent&)), this, SLOT(setCurrentEvent(const PimEvent&)) ); connect( allView, SIGNAL(editOccurrence(const Occurrence&)), this, SIGNAL(editOccurrence(const Occurrence&)) ); connect( allView, SIGNAL(removeOccurrence(const Occurrence&)), this, SIGNAL(removeOccurrence(const Occurrence&)) ); connect( allView, SIGNAL(beamEvent(const PimEvent&)), this, SIGNAL(beamEvent(const PimEvent&)) ); connect( allView, SIGNAL(showDetails()), this, SIGNAL(showDetails()) ); connect( allView, SIGNAL(setCurrentEvent(const PimEvent&)), this, SLOT(setCurrentEvent(const PimEvent&)) ); setFocusPolicy(StrongFocus); setFocus();}#ifdef USE_LABEL_HEADERQString DayView::header1Text(const QDate &d) const{ return tr("%1", "Date as day of week") .arg(TimeString::localDayOfWeek(d, TimeString::Long));}QString DayView::header2Text(const QDate &d) const{ return tr("%1", "Date in local format") .arg(TimeString::localYMD(d));}#endifvoid DayView::selectedDates( QDateTime &start, QDateTime &end ){ int sh = view->startHour(); int eh = view->endHour(); if (sh >= 0) { start.setTime( QTime( sh, 0, 0 ) ); if (eh == 24) { end.setDate(cDate.addDays(1)); end.setTime( QTime(0,0,0) ); } else { end.setTime( QTime( eh, 0, 0 ) ); } }}void DayView::clearSelectedDates(){ view->clearSelectedTimes();}void DayView::selectDate(int y, int m){ if ( y != cDate.year() || m != cDate.month() ) { QDate nd( y, m, 1 ); if ( nd.daysInMonth() < cDate.day() ) selectDate(QDate(y, m, nd.daysInMonth())); else selectDate(QDate(y, m, cDate.day())); }}void DayView::selectDate( const QDate &d){ if ( cDate == d ) return; PeriodView::selectDate(d);#ifdef USE_LABEL_HEADER header1->setText(header1Text(d)); header2->setText(header2Text(d));#else header->setDate( d.year(), d.month(), d.day() );#endif view->selectDate(d); relayoutPage();}bool DayView::hasSelection() const{ return (allView->currentItem() || view->currentItem());}PimEvent DayView::currentEvent() const{ DayItem *dim = allView->currentItem(); if (dim) return dim->event(); dim = view->currentItem(); if (dim) return dim->event(); return PimEvent();}Occurrence DayView::currentItem() const{ DayItem *dim = allView->currentItem(); if (dim) return dim->occurrence(); dim = view->currentItem(); if (dim) return dim->occurrence(); return Occurrence();}void DayView::setCurrentItem( const Occurrence &o ){ setCurrentEvent(o.event());}void DayView::setCurrentEvent( const PimEvent &e ){ DayViewContents *views[2] = { allView, view }; DayItem *curr[2] = { allView->currentItem(), view->currentItem() }; for ( int i = 0; i < 2; i++ ) { int other = (i + 1) % 2; DayItem *orig = views[i]->currentItem(); DayItem *dim = views[i]->firstItem(FALSE); if (dim) { do { if (dim->event() == e) { views[i]->setCurrentItem( dim, FALSE ); views[i]->moveSelection(orig, dim); if (!orig) views[other]->moveSelection( curr[other], 0 ); break; viewWithFocus = i; break; } } while ((dim = views[i]->nextItem(FALSE)) != 0); } }}void DayView::setCompressDay( bool compressDay ){ view->setType( compressDay ? DayViewContents::CompressedDay : DayViewContents::ScrollingDay );}void DayView::redraw(){ //if ( isUpdatesEnabled() ) relayoutPage();}void DayView::getEvents(){ view->clearItems(); allView->clearItems(); QValueList<Occurrence> eventList = db->getOccurrences( cDate, cDate ); int allDayCount = 0; QValueListIterator<Occurrence> it; for ( it = eventList.begin(); it != eventList.end(); ++it ) { if ((*it).event().isAllDay()) { allView->addOccurrence(*it, cDate); allDayCount++; } else { view->addOccurrence(*it, cDate); } } if (allDayCount) { int fixed_height; if (allDayCount > 4) fixed_height = 2 * day_height + (day_height / 2 ); else fixed_height = day_height * (++allDayCount / 2 ); allView->setMaximumHeight(fixed_height); allView->setMinimumHeight(fixed_height); allView->layoutItems(); allView->show(); allView->firstItem(); viewWithFocus = 0; } else { allView->hide(); view->firstItem(FALSE); viewWithFocus = 1; } emit selectionChanged();}void DayView::relayoutPage( bool fromResize ){ if ( !fromResize ) getEvents(); // no need we already have them! view->setMetrics( QFontMetrics( qApp->font() ) ); allView->layoutItems(); return;}void DayView::setDayStarts( int startHere ){ PeriodView::setDayStarts(startHere); view->startAtTime(startHere);}void DayView::setStartOnMonday( bool bStartOnMonday ){#ifndef USE_LABEL_HEADER header->setStartOfWeek( bStartOnMonday );#else Q_UNUSED(bStartOnMonday)#endif}void DayView::keyPressEvent(QKeyEvent *e){ switch(e->key()) { case Key_Up: previousEvent(); break; case Key_Down: nextEvent(); break; case Key_Left: selectDate(cDate.addDays(-1)); break; case Key_Right: selectDate(cDate.addDays(1)); break;#ifdef QTOPIA_PHONE case Key_1: selectDate(cDate.addDays(-7)); break; case Key_3: selectDate(cDate.addDays(7)); break; case Key_4: if (cDate.month() == 1) selectDate(cDate.year()-1, 12); else selectDate(cDate.year(), cDate.month()-1); break; case Key_6: if (cDate.month() == 12) selectDate(cDate.year()+1, 1); else selectDate(cDate.year(), cDate.month()+1); break; case Key_7: selectDate(cDate.year()-1, cDate.month()); break; case Key_9: selectDate(cDate.year()+1, cDate.month()); break; case Key_5: selectDate(QDate::currentDate()); break; case Key_Select: if ( hasSelection() ) emit showDetails(); break;#endif default: e->ignore(); }}void DayView::previousEvent(){ if (viewWithFocus == 0) { if (!allView->previousItem()) if ( view->lastItem() ) viewWithFocus = 1; else allView->lastItem(); } else { if (!view->previousItem()) { if (allView->lastItem()) viewWithFocus = 0; else view->lastItem(); } }}void DayView::nextEvent(){ if (viewWithFocus == 0) { if (!allView->nextItem()) { if (view->firstItem()) viewWithFocus = 1; else allView->firstItem(); } } else { if (!view->nextItem()) if ( allView->firstItem() ) viewWithFocus = 0; else view->firstItem(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -