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

📄 datebookweek.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** 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.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** 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.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "datebookweek.h"#include "datebookweekheaderimpl.h"#include <qtopia/calendar.h>#include "datebookdb.h"#include <qtopia/pim/event.h>#include <qtopia/qpeapplication.h>#include <qtopia/timestring.h>#include <qdatetime.h>#include <qheader.h>#include <qlabel.h>#include <qlayout.h>#include <qpainter.h>#include <qpopupmenu.h>#include <qtimer.h>#include <qspinbox.h>#include <qstyle.h>static const int allDayHeight = 8;static const int hourMargin = 4;WeekViewContents::WeekViewContents( WeekView *parent, const char *name )    : QScrollView( parent, name ),      showingEvent( false ), wv(parent){    items.setAutoDelete( true );    dayItems.setAutoDelete( true );    viewport()->setBackgroundMode( PaletteBase );    header = new QHeader( this );    header->addLabel( "" );    header->setMovingEnabled( false );    header->setResizeEnabled( false );    header->setClickEnabled( false, 0 );    updateWeekNames(parent->startsOnMonday());    connect( header, SIGNAL(clicked(int)), this, SIGNAL(activateWeekDay(int)) );    TimeString::connectChange( this, SLOT(timeStringChanged()) );    QFontMetrics fm( font() );    rowHeight = fm.height()+2;    resizeContents( width(), 24*rowHeight );}void WeekViewContents::updateWeekNames(bool bOnMonday){    static bool bFirst = true;    if ( bFirst ) {	bFirst = false;	// NO TR. We are inserting dummy labels that are overwritten below.	header->addLabel( "Monday" );	header->addLabel( "Tuesday");	header->addLabel( "Wednesday" );	header->addLabel( "Thursday" );	header->addLabel( "Friday" );	header->addLabel( "Saturday" );	header->addLabel( "Sunday" );    }    TimeString::Length len = TimeString::Short;    int approxSize = QFontMetrics(QFont()).width(" Wed ") * 7;    if ( QApplication::desktop()->width() > approxSize )	len = TimeString::Medium;    for ( int i = 0; i < 7; i++ ) {	if ( bOnMonday )	    header->setLabel( i + 1, TimeString::localDayOfWeek( i + 1, len ) );	else	    header->setLabel( i + 1, TimeString::localDayOfWeek( ((i + 6) % 7) + 1, len ) );    }}void WeekViewContents::showEvents( QValueList<Occurrence> &ev, const QDate &startWeek ){    items.clear();    items.resize(7);    int i;    for (i = 0; i < 7; i++) {	LayoutManager *lm = new LayoutManager(header->sectionSize(i+1), rowHeight*24);	lm->setDate(startWeek.addDays(i));	items.insert(i, lm);    }    dayItems.clear();    QValueListIterator<Occurrence> it;    for ( it = ev.begin(); it != ev.end(); ++it ) {	if ((*it).event().isAllDay()) {	    LayoutItem *i = new LayoutItem(*it);	    positionItem(i);	    dayItems.append(i);	} else {	    int firstdow = startWeek.daysTo((*it).startInCurrentTZ().date());	    int lastdow = startWeek.daysTo((*it).endInCurrentTZ().date());	    if (firstdow < 0) firstdow = 0;	    if (lastdow > 6) lastdow = 6;	    for (int i = firstdow; i <= lastdow; i++)		items.at(i)->addOccurrence( *it );	}    }    int mWidth = contentsWidth();    for (i = 0; i < 7; i++) {	items.at(i)->layoutItems(FALSE);	mWidth = QMIN(mWidth, items.at(i)->maximumColumnWidth());    }    for (i = 0; i < 7; i++) {	items.at(i)->setMaximumColumnWidth(mWidth);	items.at(i)->layoutItems(FALSE);    }    viewport()->update();    update();}void WeekViewContents::moveToHour( int h ){    int offset = h*rowHeight;    setContentsPos( 0, offset );}void WeekViewContents::keyPressEvent( QKeyEvent *e ){    e->ignore();}void WeekViewContents::timeStringChanged(){    viewport()->update();}static inline int db_round30min( int m ){    if ( m < 15 )	m = 0;    else if ( m < 45 )	m = 1;    else	m = 2;    return m;}void WeekViewContents::alterDay( int day ){    if ( !wv->startsOnMonday() ) {	    day--;    }    emit activateWeekDay( day );}// Only for all day items which we have a very custom layout for.void WeekViewContents::positionItem( LayoutItem *i ){    const Occurrence ev = i->occurrence();    int dow, duration;    if (ev.startInCurrentTZ().date() < ((WeekView *)parent())->weekDate())  {	dow = 0;	duration = ((WeekView *)parent())->weekDate().daysTo(		ev.endInCurrentTZ().date());    } else  {	dow = ev.startInCurrentTZ().date().dayOfWeek();	duration = ev.startInCurrentTZ().date().daysTo(	    ev.endInCurrentTZ().date());    }    if ( !wv->startsOnMonday() ) {	if ( dow == 7 )	    dow = 1;	else	    dow++;    }    // now make sure duration doesn't extend of the end fo the week.    if (dow + duration > 7) {	duration = 7 - dow;    }    int x = header->sectionPos( dow );    int hwidth = header->sectionSize( dow );    hwidth += hwidth*duration;    LayoutItem *inter = 0;    i->setGeometry(x, header->height(), hwidth, allDayHeight * 2);    inter = intersects( i );    if (inter) {	// need to change geom of both;	i->setGeometry( x, header->height() + 		(ev.event().hasRepeat() ? allDayHeight : 0), 		hwidth , allDayHeight);	inter->setGeometry( inter->geometry().x(), header->height() +		(inter->event().hasRepeat() ? allDayHeight : 0), 		inter->geometry().width(), allDayHeight);    }}LayoutItem *WeekViewContents::intersects( const LayoutItem *item ){    QRect geom = item->geometry();    // We allow the edges to overlap    geom.moveBy( 1, 1 );    geom.setSize( geom.size()-QSize(2,2) );    const PimEvent itemEvent = item->event();    QListIterator<LayoutItem> it(dayItems);    for ( ; it.current(); ++it ) {	LayoutItem *i = it.current();	const PimEvent iEvent = i->event();	if (i != item && iEvent.hasRepeat() != itemEvent.hasRepeat()) {	    if (i->geometry().intersects( geom ) )		return i;	}    }    return 0;}void WeekViewContents::contentsMousePressEvent( QMouseEvent *e ){    QValueList<Occurrence> list;    for (int j = 0; j < 7; j++) {	QVector<LayoutItem> v = items.at(j)->items();	int x = header->sectionPos(j+1)-1;	for ( uint k = 0; k < v.size(); k++) {	    LayoutItem *i = v.at(k);	    // Change to	    QRect geo = i->geometry();	    geo.moveBy(x,0);	    if ( geo.contains( e->pos() ) ) {		showingEvent = true;		list.append(i->occurrence());	    }	}    }    if (list.count())	emit eventsSelected( list );}void WeekViewContents::contentsMouseReleaseEvent( QMouseEvent *e ){    if ( showingEvent ) {	showingEvent = false;	emit selectionCleared();    } else {	int d = header->sectionAt( e->pos().x() );	if ( d > 0 ) {// 	    if ( !bOnMonday )// 		d--;	    emit activateWeekDay( d );	}    }}void WeekViewContents::mousePressEvent( QMouseEvent *e ){//#if (QT_VERSION-0 >= 0x030000)#if 0    // hack to get around dumb 3.1 scrollview mouse events.    if  (e->pos().y() > topMargin())	return;#endif    QValueList<Occurrence> list;    QListIterator<LayoutItem> it(dayItems);    for ( ; it.current(); ++it ) {	LayoutItem *i = it.current();	if ( i->geometry().contains( e->pos() ) ) {	    showingEvent = true;	    list.append(i->occurrence());	}    }    if (list.count())	emit eventsSelected( list );}void WeekViewContents::mouseReleaseEvent( QMouseEvent *e ){//#if (QT_VERSION-0 >= 0x030000)#if 0    // hack to get around dumb 3.1 scrollview mouse events.    if  (e->pos().y() > topMargin())	return;#endif    if ( showingEvent ) {	showingEvent = false;	emit selectionCleared();    } else {	int d = header->sectionAt( e->pos().x() );	if ( d > 0 ) {	    emit activateWeekDay( d );	}    }}void WeekViewContents::drawContents( QPainter *p ) {    p->fillRect(0, header->height(), header->width(), allDayHeight * 2, 	    white);	    //palette().color(QPalette::Normal , QColorGroup::Dark ));    // draw day events.      QListIterator<LayoutItem> it(dayItems);    for ( ; it.current(); ++it ) {	LayoutItem *i = it.current();	if ( i->event().isAllDay() ) {	    p->fillRect( i->geometry(), i->event().color().light(175));	}    }    QPen pen = p->pen();    p->setPen( lightGray );    // header->sectionPos(i)-1 because we want the end of the last header,    // not the start of this one.    for ( int i = 1; i <= 7; i++ )	p->drawLine( header->sectionPos(i)-1, header->height(), 		header->sectionPos(i)-1, header->height() + 2 * allDayHeight );    p->drawLine( 0, header->height() + 2 * allDayHeight, 	    header->width(), header->height() + 2 * allDayHeight );    p->setPen(pen);}void WeekViewContents::drawContents( QPainter *p, int cx, int cy, int cw, int ch ){    QRect ur( cx, cy, cw, ch );    p->setPen( lightGray );    // -1 because end of last header, not this.    for ( int i = 1; i <= 7; i++ )	p->drawLine( header->sectionPos(i)-1, cy, header->sectionPos(i)-1, cy+ch );    int w = header->sectionPos(1);    p->setPen( black );    for ( int t = 0; t < 24; t++ ) {	int y = t*rowHeight;	QRect r( hourMargin, y, w-hourMargin*2, rowHeight );	if ( r.intersects( ur ) ) {	    p->drawText( r, AlignRight | AlignTop, TimeString::localH(t) );	}    }    for (int j = 0; j < 7; j++) {	QVector<LayoutItem> v = items.at(j)->items();	int x = header->sectionPos(j+1)-1; // 1 for end of last, 1 for contenst shift.	for ( uint k = 0; k < v.size(); k++) {	    LayoutItem *i = v.at(k);	    // Change to

⌨️ 快捷键说明

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