📄 mainwindow.cpp
字号:
#if defined(Q_WS_QWS) || defined(_WS_QWS_)// showMaximized();#else// show();#endif// raise(); QPEApplication::setKeepRunning();// setActiveWindow(); }}void TodoWindow::slotListView(){ listAction->setOn(TRUE); detailsAction->setOn(FALSE); if ( centralWidget() != listView ) { todoView()->hide(); setCentralWidget( listView ); listView->show(); table->setFocus(); setCaption( tr("Todo") ); }}void TodoWindow::slotDetailView(){ todoView()->init( table->currentEntry() ); showView();}TodoView* TodoWindow::todoView(){ if ( !tView ) { tView = new TodoView(this); connect( tView, SIGNAL(done()), this, SLOT(slotListView()) ); connect( tView, SIGNAL(previous()), this, SLOT(viewPrevious()) ); connect( tView, SIGNAL(next()), this, SLOT(viewNext()) ); } return tView;}void TodoWindow::showView(){ listView->hide(); setCentralWidget( todoView() ); tView->show(); tView->setFocus(); //To avoid events being passed to QTable setCaption( tr("Task Details") ); listAction->setOn(FALSE); detailsAction->setOn(TRUE);}void TodoWindow::slotNew(){ NewTaskDialog e( catSelect->currentCategory(), this, 0, TRUE ); e.setCaption( tr( "New Task" ) ); int ret = QPEApplication::execDialog(&e); if ( ret == QDialog::Accepted ) { PimTask todo = e.todoEntry(); if ( todo.description().isEmpty() && !todo.notes().isEmpty() ) { // Don't want to loose an entry that has some useful data QString desc = todo.notes(); if ( desc.length() > 30 ) { // keep description length sensible desc.truncate(27); desc.append( "..." ); // no tr } todo.setDescription( desc ); } if ( !todo.description().isEmpty() ) { addEntry( todo ); findAction->setEnabled( TRUE ); currentEntryChanged( 0, 0 ); slotListView(); } }}void TodoWindow::slotDelete(){ if ( table->currentRow() == -1 ) return; QString strName = table->currentEntry().description().left(30); if ( table->selectionMode() == TodoTable::Extended ) { QValueList<QUuid> t = table->selectedTasks(); if ( !t.count() ) return; QString str; if ( t.count() > 1 ) str = tr("<qt>Are you sure you want to delete the %1 selected tasks?</qt>").arg( t.count() ); else str = tr("<qt>Are you sure you want to delete:<p><b>%1</b>?</qt>").arg( table->currentEntry().description().left(30) ); switch( QMessageBox::warning( this, tr("Todo"), tr(str), tr("Yes"), tr("No"), 0, 0, 1 ) ) { case 0: { deleteTasks(t); currentEntryChanged(0, 0); slotListView(); } break; case 1: break; } } else if ( QPEMessageBox::confirmDelete( this, tr( "Todo" ), strName.simplifyWhiteSpace() ) ) { return; removeEntry( table->currentEntry() ); currentEntryChanged(0, 0); slotListView(); } if ( !table->numRows() && findAction->isOn()) { findAction->setOn(FALSE); }}void TodoWindow::deleteTasks(const QValueList<QUuid> &t){ for (QValueList<QUuid>::ConstIterator it = t.begin(); it != t.end(); ++it) { PrTask t; t.setUid( *it ); tasks.removeTask(t); } table->reload();}void TodoWindow::slotEdit(){ PimTask todo = table->currentEntry(); NewTaskDialog e( todo, this, 0, TRUE ); e.setCaption( tr( "Edit Task" ) ); int ret = QPEApplication::execDialog(&e); if ( ret == QDialog::Accepted ) { todo = e.todoEntry(); updateEntry( todo ); if ( centralWidget() == todoView() ) { todoView()->init( table->currentEntry() ); tView->setFocus(); //To avoid events being passed to QTable } } }void TodoWindow::viewPrevious(){ int cr = table->currentRow(); if ( --cr >= 0 ) { table->setCurrentCell( cr, table->currentColumn() ); todoView()->init( table->currentEntry() ); }}void TodoWindow::viewNext(){ int cr = table->currentRow(); if ( ++cr < table->numRows() ) { table->setCurrentCell( cr, table->currentColumn() ); todoView()->init( table->currentEntry() ); }}void TodoWindow::setShowCompleted( int s ){ if ( !table->isUpdatesEnabled() ) return; tasks.setCompletedFilter( s != 1 ); table->reload();}void TodoWindow::currentEntryChanged( int , int ){ bool entrySelected = table->hasCurrentEntry(); editAction->setEnabled(entrySelected); deleteAction->setEnabled(entrySelected); findAction->setEnabled(entrySelected); detailsAction->setEnabled(entrySelected); if (beamAction) { beamAction->setEnabled(entrySelected); }}void TodoWindow::reload(){ QArray<int> vl( 0 ); catSelect->setCategories( vl, "Todo List", // No tr tr("Todo List") ); catSelect->setAllCategories( TRUE ); tasks.ensureDataCurrent(TRUE); catSelected( catSelect->currentCategory() ); if ( centralWidget() == tView ) slotDetailView();}void TodoWindow::flush(){ tasks.saveData();}void TodoWindow::catSelected( int c ){ tasks.setFilter( c ); setCaption( tr("Todo") + " - " + table->categoryLabel( c ) ); table->reload(); currentEntryChanged(0, 0);}// Loop through and validate the categories. If any records' category list was// modified we need to updatevoid TodoWindow::catChanged(){ QListIterator<PrTask> it(tasks.tasks() ); Categories c; c.load( categoryFileName() ); QArray<int> cats = c.ids("Todo List", c.labels("Todo List", TRUE) ); // No tr bool changed = FALSE; for(; it.current(); ++it) { PimTask t( *(*it) ); if ( t.pruneDeadCategories( cats ) ) { tasks.updateTask( t ); changed = TRUE; } } if ( changed ) reload();}void TodoWindow::closeEvent( QCloseEvent *e ){ e->accept(); // repeat for categories... // if writing configs fail, it will emit an // error, but I feel that it is "ok" for us to exit // espically since we aren't told if the write succeeded... Config config( "todo" ); config.setGroup( "View" ); config.writeEntry( "ShowComplete", !tasks.completedFilter() ); config.writeEntry( "Category", tasks.filter() );}void TodoWindow::slotFind( bool s ){ slotListView(); if ( s ) { searchBar->show(); searchEdit->setFocus(); } else { searchBar->hide(); if ( table->numSelections() ) table->clearSelection(); table->clearFindRow(); }}void TodoWindow::search(){ table->slotDoFind( searchEdit->text(), tasks.filter() );}void TodoWindow::findNotFound(){ Global::statusMessage( tr("Find: not found") );}void TodoWindow::findFound(){ Global::statusMessage( "" );}void TodoWindow::findWrapped(){ Global::statusMessage( tr("Find: reached end") );}void TodoWindow::setDocument( const QString &filename ){ DocLnk doc(filename); if ( doc.isValid() ) receiveFile(doc.file()); else receiveFile(filename);}bool TodoWindow::receiveFile( const QString &filename ){ QValueList<PimTask> tl = PimTask::readVCalendar( filename ); QString msg = tr("<P>%1 new tasks.<p>Do you want to add them to your Todo List?"). arg(tl.count()); if ( QMessageBox::information(this, tr("New Tasks"), msg, QMessageBox::Ok, QMessageBox::Cancel)==QMessageBox::Ok ) { for( QValueList<PimTask>::Iterator it = tl.begin(); it != tl.end(); ++it ) { addEntry( *it ); } return TRUE; } return FALSE;}static const char * beamfile = "/tmp/obex/todo.vcs";void TodoWindow::slotBeam(){ if ( !table->hasCurrentEntry() ) { qWarning("todo::slotBeam called with nothing to beam"); return; } QString description; unlink( beamfile ); // delete if exists PimTask c = table->currentEntry();#ifndef Q_OS_WIN32 mkdir("/tmp/obex/", 0755);#else QDir d; d.mkdir("/tmp/obex");#endif if ( table->selectionMode() == TodoTable::Extended ) { QValueList<PimTask> l = table->selected(); PimTask::writeVCalendar( beamfile, l ); if ( l.count() > 1 ) description = tr("the %1 selected tasks").arg( l.count() ); else description = c.description(); } else { PimTask::writeVCalendar( beamfile, c ); description = c.description(); } Ir *ir = new Ir( this ); connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); ir->send( beamfile, description, "text/x-vCalendar" );}void TodoWindow::beamDone( Ir *ir ){ delete ir; unlink( beamfile );}void TodoWindow::configure(){ TodoSettings settings(this, "", TRUE); settings.setCurrentFields( table->fields() ); if ( QPEApplication::execDialog(&settings) == QDialog::Accepted ) { table->setFields( settings.fields() ); table->reload(); }}void TodoWindow::selectAll(){ table->selectAll();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -