⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datebookweek.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	    QRect geo = i->geometry();	    geo.moveBy(x,-1); // up and to the left	    geo.setSize(geo.size() + QSize(1,1));	    if ( geo.intersects( ur ) ) {		p->setBrush( i->event().color());		p->drawRect( geo );	    }	}    }}void WeekViewContents::resizeEvent( QResizeEvent *e ){    QFontMetrics fm(qApp->font());    rowHeight = QMIN(fm.height() * 3, QMAX(fm.height(), e->size().height() / 10));    int hourWidth = fm.width(tr("%1am").arg(12))+hourMargin*2;    QScrollView::resizeEvent( e );    int avail = width() - ( qApp->style().scrollBarExtent().width() );    resizeContents( avail, posOfHour(24) );    header->setGeometry( 0, 0, avail, header->sizeHint().height() );    setMargins( 0, header->height() + allDayHeight * 2 + 1, 0, 0 );    header->resizeSection( 0, hourWidth );    int sw = (avail - hourWidth) / 7;    int i;    for ( i = 1; i < 7; i++ )	header->resizeSection( i, sw );    header->resizeSection( 7, avail - hourWidth - sw*6 );    ((WeekView*)parent())->redraw();}void WeekViewContents::setStartOfWeek( bool bStartOnMonday ){    updateWeekNames(bStartOnMonday);}int WeekViewContents::posOfHour(int h) const{    return h*rowHeight;}int WeekViewContents::hourAtPos(int h) const{    return h == 0 ? 0 : h/rowHeight;}//-------------------------------------------------------------------WeekView::WeekView( DateBookTable *newDB, bool startOnMonday, 			QWidget *parent, const char *name )    : PeriodView( newDB, startOnMonday,  parent, name ), year(0), _week(0){    setFocusPolicy(StrongFocus);    QVBoxLayout *vb = new QVBoxLayout( this );    header = new WeekViewHeader( startOnMonday, this );    contents = new WeekViewContents( this );    contents->setFrameStyle( QFrame::NoFrame );    contents->setFrameRect( QRect(0,0,0,0) );    vb->addWidget( header );    vb->addWidget( contents );    lblDesc = new QLabel( this, "event label" ); // No tr    lblDesc->setFrameStyle( QFrame::Plain | QFrame::Box );    lblDesc->setBackgroundColor( yellow );    lblDesc->hide();    tHide = new QTimer( this );    connect( contents, SIGNAL( activateWeekDay(int) ),             this, SLOT( dayActivated(int) ) );    connect( contents, SIGNAL(eventsSelected(QValueList<Occurrence>&)),	     this, SLOT(showEventsLabel(QValueList<Occurrence>&)) );    connect( contents, SIGNAL(selectionCleared()),	     this, SLOT(hideEventsLabel()) );    connect( header, SIGNAL( dateChanged(int,int) ),             this, SLOT( setWeek(int,int) ) );    connect( tHide, SIGNAL( timeout() ),             lblDesc, SLOT( hide() ) );    connect( header->spinYear, SIGNAL(valueChanged(int)),	     this, SLOT(setYear(int)) );    connect( qApp, SIGNAL( weekChanged(bool) ),             this, SLOT( setStartsOnMonday(bool) ) );    selectDate(QDate::currentDate());}void WeekView::keyPressEvent(QKeyEvent *e){    switch(e->key()) {	case Key_Up:	    contents->scrollBy(0, -20);	    break;	case Key_Down:	    contents->scrollBy(0, 20);	    break;	case Key_Left:	    selectDate(currentDate().addDays(-7));	    break;	case Key_Right:	    selectDate(currentDate().addDays(7));	    break;	default:	    e->ignore();    }}void WeekView::dayActivated( int day ){    QDate d;    d = dateFromWeek( _week, year, bOnMonday );    day--;    d = d.addDays( day );    emit dateActivated(d);}bool WeekView::calcWeek( const QDate &d, int &week, int &year ) const{// For Weeks that start on Monday... (EASY!)// At the moment we will use ISO 8601 method for computing// the week.  Granted, other countries use other methods,// bet we aren't doing any Locale stuff at the moment.  So,// this should pass.  This Algorithim is public domain and// available at:// http://personal.ecu.edu/mccartyr/ISOwdALG.txt// the week number is return, and the year number is returned in year// for Instance 2001/12/31 is actually the first week in 2002.// There is a more mathematical definition, but I will implement it when// we are pass our deadline.// For Weeks that start on Sunday... (ahh... home rolled)// okay, if Jan 1 is on Friday or Saturday,// it will go to the pervious// week...    int weekNumber;    int yearNumber;    // remove a pesky warning, (Optimizations on g++)    weekNumber = -1;    int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek();    int dayOfWeek = d.dayOfWeek();    if ( !d.isValid() )	return false;    if ( startsOnMonday() ) {	// find the Jan1Weekday;	if ( d.dayOfYear() <= ( 8 - jan1WeekDay) && jan1WeekDay > 4 ) {	    yearNumber = d.year() - 1;	    if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) )		weekNumber = 53;	    else		weekNumber = 52;	} else	    yearNumber = d.year();	if ( yearNumber == d.year() ) {	    int totalDays = 365;	    if ( QDate::leapYear(yearNumber) )		totalDays++;	    if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) )		 || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) {		yearNumber++;		weekNumber = 1;	    }	}	if ( yearNumber == d.year() ) {	    int j = d.dayOfYear() + (7 - dayOfWeek) + ( jan1WeekDay - 1 );	    weekNumber = j / 7;	    if ( jan1WeekDay > 4 )		weekNumber--;	}    } else {	// it's better to keep these cases separate...	if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4	     && jan1WeekDay != 7 ) {	    yearNumber = d.year() - 1;	    if ( jan1WeekDay == 6		 || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) {		weekNumber = 53;	    }else		weekNumber = 52;	} else	    yearNumber = d.year();	if ( yearNumber == d.year() ) {	    int totalDays = 365;	    if ( QDate::leapYear( yearNumber ) )		totalDays++;	    if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek % 7)) ) {		yearNumber++;		weekNumber = 1;	    }	}	if ( yearNumber == d.year() ) {	    int j = d.dayOfYear() + (7 - dayOfWeek % 7) + ( jan1WeekDay - 1 );	    weekNumber = j / 7;	    if ( jan1WeekDay > 4 ) {		weekNumber--;	    }	}    }    year = yearNumber;    week = weekNumber;    return true;}void WeekView::selectDate(const QDate &date){    int w, y;    calcWeek( date, w, y );    header->setDate( y, w );    cDate = date;    getEvents();}void WeekView::setWeek( int y, int w ){    if (y == year && w == _week)	return;    year = y;    _week = w;        selectDate( weekDate() );   // getEvents();}void WeekView::setYear( int y ){    if (y == year)	return;    setWeek(y, _week);#if 0    int totWeek;    QDate d( y, 12, 31 );    int throwAway;    calcWeek( d, totWeek, throwAway, bOnMonday );    while ( totWeek == 1 ) {	d = d.addDays( -1 );	calcWeek( d, totWeek, throwAway, bOnMonday );    }    if ( totWeek != totalWeeks() )	setTotalWeeks( totWeek );    cDate = weekDate();#endif}void WeekView::databaseUpdated(){    getEvents();}void WeekView::getEvents(){    QDate startWeek = weekDate();    QDate endWeek = startWeek.addDays( 6 );    QValueList<Occurrence> eventList = db->getOccurrences(startWeek,								  endWeek);    contents->showEvents( eventList , startWeek );    contents->moveToHour( sHour );}void WeekView::showEventsLabel( QValueList<Occurrence> &events ){    if ( tHide->isActive() )        tHide->stop();    QString str = "";    // why would someone use "<"?  Oh well, fix it up...    // I wonder what other things may be messed up...    QValueListIterator<Occurrence> it;    for(it = events.begin(); it != events.end(); ++it) {	Occurrence ev = (*it);	QString strDesc = ev.event().description();	int where = strDesc.find( "<" );	while ( where != -1 ) {	    strDesc.remove( where, 1 );	    strDesc.insert( where, "&#60;" );	    where = strDesc.find( "<", where );	}	QString strCat;	// ### FIX later...	//     QString strCat = ev.category();	//     where = strCat.find( "<" );	//     while ( where != -1 ) {	// 	strCat.remove( where, 1 );	// 	strCat.insert( where, "&#60;" );	// 	where = strCat.find( "<", where );	//     }	QString strNote = ev.event().notes();	where = strNote.find( "<" );	while ( where != -1 ) {	    strNote.remove( where, 1 );	    strNote.insert( where, "&#60;" );	    where = strNote.find( "<", where );	}	str += "<b>" + strDesc + "</b><br>" + "<i>"	    + strCat + "</i><br>";	if (ev.start().date() == ev.end().date()) {	    str += TimeString::localYMD( ev.date(), TimeString::Long )	    + "<br>";	}	/*	if (ev.event().isAllDay()) {	    if (ev.event().start().date() != ev.event().end().date()) {		str += TimeString::longDateString( ev.event().end().date() );		str += "<br>";	    }	    str += "<b>" + tr("All day") + "</b>";	} else {	*/	if (ev.start().date() != ev.end().date() || !ev.event().isAllDay()) {	    str += "<b>" + tr("Start") + "</b>: ";	    if (ev.start().date() != ev.end().date()) {		// multi-day event.  Show start date		str += TimeString::localYMD( ev.start().date(), TimeString::Long );		str += ", ";	    }	    if (! ev.event().isAllDay())		str += TimeString::localHM(ev.start().time());	    str += "<br><b>" + tr("End") + "</b>: ";	    if (ev.start().date() != ev.end().date()) {		str += TimeString::localYMD( ev.end().date(), TimeString::Long );		str += ", ";	    }	    if (! ev.event().isAllDay())		str += TimeString::localHM(ev.end().time());	    str += "<br>";	}	if (ev.event().isAllDay())	    str += "<b>" + tr("All day") + "</b><br>";	str += "<br>" + strNote;    }    lblDesc->setText( str );    lblDesc->resize( lblDesc->sizeHint() );    // move the label so it is "centerd" horizontally...    lblDesc->move( QMAX(0,(width() - lblDesc->width()) / 2), 0 );    lblDesc->show();}void WeekView::hideEventsLabel(){    tHide->start( 2000, true );}void WeekView::setDayStarts( int startHere ){    sHour = startHere;    contents->moveToHour( sHour );}void WeekView::redraw(){    getEvents();}void WeekView::setTotalWeeks( int numWeeks ){    header->spinWeek->setMaxValue( numWeeks );}int WeekView::totalWeeks() const{    return header->spinWeek->maxValue();}void WeekView::setStartsOnMonday( bool onMonday ){    bOnMonday = onMonday;    contents->setStartOfWeek( bOnMonday );    header->setStartOfWeek( bOnMonday );    redraw();}// return the date at the beginning of the week...QDate WeekView::weekDate() const{    return dateFromWeek( _week, year, bOnMonday );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -