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

📄 todotable.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{	    case PimTask::CompletedField:		{		    int x = pos.x() - columnPos( col );		    int y = pos.y() - rowPos( row );		    int w = columnWidth( col );		    int h = rowHeight( row );		    if ( x >= ( w - BoxSize ) / 2 && x <= ( w - BoxSize ) / 2 + BoxSize &&			    y >= ( h - BoxSize ) / 2 && y <= ( h - BoxSize ) / 2 + BoxSize ) {			toggleTaskCompletion(row);			return;		    }		}		break;	    case PimTask::Priority:		{		    QWidget *w = priorityEdit(row, col);		    d->setEditorWidget(w, row, col );		    return;		}		break;	    default:		menuTimer->stop();		emit clicked();		break;	}    }}void TodoTable::toggleTaskCompletion(int row){    PimTask task= mTasks->filteredItem(row);// Go to 'next' when marking done. A bit confusing.#ifdef QTOPIA_TODOLIST_NEXT_UPON_DONE    QUuid n = mTasks->filteredItem((row+1)%numRows()).uid();#endif    bool c = !task.isCompleted();    task.setCompleted(c);    if ( c )	task.setCompletedDate(QDate::currentDate());    d->setModifiedTask(task.uid(), PimTask::CompletedField);    emit updateTask(task);#ifdef QTOPIA_TODOLIST_NEXT_UPON_DONE    setCurrentEntry(n);#endif}void TodoTable::keyPressEvent( QKeyEvent *e ){    if ( d->editorWidget() ) {	endEdit(d->editorRow(), d->editorColumn(), FALSE, TRUE );	d->clearEditorWidget();	setFocus();    }    int col  = currentColumn();    int row = currentRow();    if (row < 0 || row >= (int)mFiltered.size()) {	QTable::keyPressEvent( e );	return;    }#ifdef QTOPIA_PHONE    if( !Global::mousePreferred() ) {	switch( e->key() ) {	    case Qt::Key_Select:		if ( !isModalEditing() ) {		    QTable::keyPressEvent( e );		    break;		}	    case Qt::Key_Space:	    case Qt::Key_Return:	    case Qt::Key_Enter:		if (ro) {		    emit clicked();		} else {		    if (headerKeyFields[col] ==  PimTask::CompletedField) {			toggleTaskCompletion(row);		    } else if (headerKeyFields[col] ==  PimTask::Priority) {			QWidget *w = priorityEdit(row, col);			d->setEditorWidget(w, row, col );			return;		    } else {			emit clicked();		    }		}		break;	    default:		QTable::keyPressEvent( e );	}    } else#endif	// non phone or touchscreen phone    if ( e->key() == Key_Space || e->key() == Key_Return#ifdef QTOPIA_PHONE	|| e->key() == Key_Select#endif	|| e->key() == Key_Enter ) {	if (ro) {	    emit clicked();	} else {	    int field = headerKeyFields[ col ];	    switch ( field ) {		case PimTask::CompletedField:		    {			toggleTaskCompletion(row);			return;		    }		    break;		case PimTask::Priority:		    {			QWidget *w = priorityEdit(row, col);			d->setEditorWidget(w, row, col );			return;		    }		    break;		default:		    emit clicked();		    break;	    }	}    } else {	QTable::keyPressEvent( e );    }}void TodoTable::startMenuTimer( int row, int col, int, const QPoint &pos ){    if ( col == 2 && cellGeometry( row, col ).contains(pos) )	menuTimer->start( 750, TRUE );}void TodoTable::refreshCell( int row, int ){//    qDebug("slotCurrentChanged %d", row );    bool needRefresh = d->hasModifiedTask();    if ( mSel == Extended ) {	if ( (bState & Qt::LeftButton) ) {	    if ( selectionBeginRow == -1 ) {		selectionBeginRow = row;	    } else {		selectionEndRow = row;	    }	    needRefresh = TRUE;	} else if (selectionBeginRow != -1 || selectionEndRow != -1) {	    selectionBeginRow = -1;	    selectionEndRow = -1;	    needRefresh = TRUE;	}    }        if ( needRefresh ) {	d->clearModifiedTask();	refresh();    }    menuTimer->stop();    emit currentChanged();}bool TodoTable::hasCurrentEntry(){    return mFiltered.size() != 0;}PimTask TodoTable::currentEntry(){    // if count is a long op, get it once damn it.    int fcount = (int)mFiltered.size();    if (fcount == 0)	return PimTask();    if (currentRow() >= fcount) {	setCurrentCell(fcount - 1, currentColumn());    } else if (currentRow() < 0) {	setCurrentCell(0, currentColumn());    }    return mTasks->filteredItem(currentRow());}void TodoTable::setCurrentEntry(const QUuid &uid){    int index = mTasks->filteredPos(TodoXmlIO::uuidToInt(uid));    if (index >= 0)	setCurrentCell(index, currentColumn());}#ifdef QTOPIA_PHONEvoid TodoTable::setCurrentCell(int r, int c){    if (ro) {	int oldrow = currentRow();	if (r == oldrow)	    return;	for (int i = 0; i < numCols(); ++i) {	    updateCell(oldrow, i);	    updateCell(r, i);	}	QTable::setCurrentCell(r, 0);    } else {	if (headerKeyFields[c] == PimTask::CompletedField || headerKeyFields[c] == PimTask::Priority)	    ContextBar::setLabel(this, Qt::Key_Select, ContextBar::Select);	else 	    ContextBar::setLabel(this, Qt::Key_Select, ContextBar::View);	QTable::setCurrentCell(r,c);    }}#endifvoid TodoTable::setCompletedFilter(bool b){    mTasks->setCompletedFilter(b);    // refresh.}bool TodoTable::completedFilter() const{    return mTasks->completedFilter();    // refresh.}void TodoTable::setFilter(int b){    mTasks->setFilter(b);    // refresh.}int TodoTable::filter() const{    return mTasks->filter();    // refresh.}void TodoTable::addEntry( const PimTask &todo, bool auid ){    if (ro)	return;    bool before = verticalScrollBar()->isVisible();    QUuid uid = mTasks->addTask( todo, auid );    reload();    setCurrentEntry( uid );    bool after =  verticalScrollBar()->isVisible();    if (before != after) {	fitHeadersToWidth();    }}void TodoTable::removeEntry(const PimTask &todo ){    if (ro)	return;    bool before = verticalScrollBar()->isVisible();    mTasks->removeTask( todo );    reload();    bool after = verticalScrollBar()->isVisible();    if (before != after) {	fitHeadersToWidth();    }}void TodoTable::removeList(const QValueList<int> &t){    if (ro)	return;    for (QValueList<int>::ConstIterator it = t.begin(); it != t.end(); ++it) {	PrTask t;	t.setUid( TodoXmlIO::uuidFromInt(*it) );	mTasks->removeTask(t);    }        reload();}void TodoTable::updateEntry(const PimTask &todo ){    if (ro)	return;    mTasks->updateTask( todo );    reload();    setCurrentEntry( todo.uid() );}void TodoTable::sortColumn( int , bool, bool ){/*    // external sort.    switch(col) {	case 0:	    ta.setSortOrder(SortedTasks::Completed);	    break;	case 1:	    ta.setSortOrder(SortedTasks::Priority);	    break;	case 2:	    ta.setSortOrder(SortedTasks::Description);	    break;	case 3:	    ta.setSortOrder(SortedTasks::DueDate);	    break;    }    // gets QTable to repaint....    refresh();*/}void TodoTable::rowHeightChanged( int ){}void TodoTable::fontChange( const QFont &oldFont ){    QFont f = font();    if ( oldFont != f ) {	QFontMetrics fm(f);	RowHeight = QMAX(20, fm.height() + 2);	// keep it an even number, a bit over 3 / 4 of rowHeight.	BoxSize =  ( RowHeight * 3 ) / 4;	BoxSize += BoxSize % 2;	fitHeadersToWidth();    }    QTable::fontChange(oldFont);}void TodoTable::contentsMousePressEvent( QMouseEvent *e ){    if ( mSel == Extended ) {	selectionBeginRow = -1;	selectionEndRow = -1;	bState = e->button();    }    QTable::contentsMousePressEvent( e );}void TodoTable::contentsMouseReleaseEvent( QMouseEvent *e ){    if ( mSel == Extended ) {	//selectionBeginRow = -1;	bState = Qt::NoButton;    }    QTable::contentsMouseReleaseEvent( e );}void TodoTable::resizeEvent( QResizeEvent *e ){    QTable::resizeEvent( e );        // we receive a resize event from qtable in the middle of the constrution, since    // QTable::columnwidth does qApp->processEvents.  Ignore this event as it causes    // all sorts of init problems for us}void TodoTable::showEvent( QShowEvent *e){    QTable::showEvent(e);#ifdef QTOPIA_DESKTOP    fitHeadersToWidth();#endif}void TodoTable::fitHeadersToWidth(){    int w = width() - frameWidth();    if (contentsHeight() >= (height() - horizontalHeader()->height()) )	w -= (style().scrollBarExtent().width());        calcFieldSizes( 0, w );    refresh();}void TodoTable::calcFieldSizes(int oldSize, int size){//    qDebug("resize event called for todotable, which we will process");    constructorDone = FALSE; //don't let QTable mess up our logic    int col = headerKeyFields.count();        int max = 0;    int i;    for (i = 0; i < col; i++) {	max += columnWidth(i);    }    if ( oldSize < max )	oldSize = max;        int accumulated = 0;    for (i = 0; i < col; i++) {	// not all fields benifit from streatching	int min = minimumFieldSize( (PimTask::TaskFields) headerKeyFields[i] );	int newColLen = min;	switch (headerKeyFields[i]) {	    case PimTask::CompletedField:	    case PimTask::PercentCompleted:	    case PimTask::DueDateYear:	    case PimTask::DueDateMonth:	    case PimTask::DueDateDay:	    case PimTask::Status:	    case PimTask::StartedDate:	    case PimTask::CompletedDate:	    case PimTask::Priority:		newColLen = min;		break;	    default:		{		    float l = (float) columnWidth( i )			/ (float) oldSize;		    float l2 = l * size;		    newColLen = (int) l2;		    if ( newColLen < min )			newColLen =  min;		}		break;	}		// make sure we fill out the space if there's some integer rounding leftover	if ( i == col - 1 && size - accumulated - 2 > min )	   newColLen = size - accumulated - 2;	else	    accumulated += newColLen;	setColumnWidth( i, newColLen );    }    constructorDone = TRUE;}QString TodoTable::categoryLabel( int id ){    // This is called seldom, so calling a load in here    // should be fine.    mCat.load( categoryFileName() );    if ( id == -1 )	return tr( "Unfiled" );    else if ( id == -2 )	return tr( "All" );    QArray<int> ids( 1 );    ids[0] = id;        return mCat.displaySingle( "Todo List", ids, Categories::ShowFirst ); //No tr}void TodoTable::cornerButtonClicked(){    int row = pos( TodoXmlIO::uuidToInt(d->modifiedTask()) );    if ( row > -1 ) {	int col = currentColumn();	setCurrentCell( row, col );	ensureCellVisible( row, col );    }}void TodoTable::refresh(){    mLastRowShown = -1;    if ( d->hasModifiedTask() ) {	// we might have an invalid uid at this point.  Check row within bounds	// just to be sure	if ( currentRow() < (int)mFiltered.size() && mTasks->filteredItem(currentRow()).uid() == d->modifiedTask() ) {	    d->clearModifiedTask();	} else  {	    // Our modified task can have been filtered out	    int i = pos( TodoXmlIO::uuidToInt(d->modifiedTask()) );	    if ( i == -1 )		d->clearModifiedTask();	}    }    if ( numRows() != (int)mFiltered.size() )	setNumRows(mFiltered.size());    else	updateContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());}// find next form current row, OR findvoid TodoTable::find( const QString &findString ){    if (findString.isEmpty())	return;    searchResults = mTasks->filteredSearch(findString);    //qDebug("search size %d", searchResults.count());    if (searchResults.count() == 0) {	emit findNotFound();    }#define FASTFIND#ifdef FASTFIND    currFind = searchResults.begin();#else    for (currFind = searchResults.begin(); currFind != searchResults.end(); ++currFind) {	if (currentRow() <= pos(*currFind)) {	    break;	}    }#endif    clearSelection( TRUE );    if (currFind == searchResults.end()) {	emit findWrapAround();    } else {	setCurrentCell( pos(*currFind), currentColumn() );	// we should always be able to wrap around and find this again,	// so don't give confusing not found message...	emit findFound();    }}void TodoTable::findNext(){    if (searchResults.count() == 0)	emit findNotFound();    if (currFind == searchResults.end())	currFind = searchResults.begin();    else	++currFind;    if (currFind == searchResults.end()) {	emit findWrapAround();    } else {	//qDebug("found pos %d, (%d)", pos(*currFind), *currFind);	setCurrentCell( pos(*currFind), currentColumn() );	emit findFound();    }}#if 0 static bool taskCompare( const PimTask &task, const QRegExp &r, int category ){    bool returnMe;    QArray<int> cats;    cats = task.categories();    returnMe = false;    if ( (category == -1 && cats.count() == 0) || category == -2 )	returnMe = task.match( r );    else {	int i;

⌨️ 快捷键说明

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