author | eilers <eilers> | 2003-08-01 14:22:29 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-08-01 14:22:29 (UTC) |
commit | 7d51872c86155fbbf27aeb8e49e7a336d909caac (patch) (side-by-side diff) | |
tree | 55ecf3452d6711065e36c6bceab8ec52bd5525d8 /core/pim/todo/tableview.cpp | |
parent | 34991bac7d96b1c17601be6a5607819342571e0c (diff) | |
download | opie-7d51872c86155fbbf27aeb8e49e7a336d909caac.zip opie-7d51872c86155fbbf27aeb8e49e7a336d909caac.tar.gz opie-7d51872c86155fbbf27aeb8e49e7a336d909caac.tar.bz2 |
Merging changes from BRANCH_1_0 to HEAD
-rw-r--r-- | core/pim/todo/tableview.cpp | 86 |
1 files changed, 80 insertions, 6 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp index d9cda09..2e252d5 100644 --- a/core/pim/todo/tableview.cpp +++ b/core/pim/todo/tableview.cpp @@ -6,71 +6,92 @@ .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. 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 ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <stdlib.h> #include <cmath> +#include <cctype> #include <qcombobox.h> #include <qlineedit.h> #include <qtimer.h> -#include <qpoint.h> #include <qpopupmenu.h> #include <qpe/config.h> #include <qpe/resource.h> #include <opie/orecur.h> #include "mainwindow.h" //#include "tableitems.h" #include "tableview.h" using namespace Todo; namespace { static const int BoxSize = 14; static const int RowHeight = 20; } +TableView::EditorWidget::EditorWidget() : m_wid(0l), m_row(-1), m_col(-1) { +} +void TableView::EditorWidget::setCellWidget(QWidget* wid, int row, int col ) { + m_wid = wid; + m_row = row; + m_col = col; +} +void TableView::EditorWidget::releaseCellWidget() { + m_wid = 0; + m_row = m_col = -1; +} +QWidget* TableView::EditorWidget::cellWidget()const { + return m_wid; +} +int TableView::EditorWidget::cellRow()const { + return m_row; +} +int TableView::EditorWidget::cellCol()const { + return m_col; +} + void TableView::initConfig() { Config config( "todo" ); config.setGroup( "Options" ); m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 ); for (int i = 0; i < numCols(); i++ ) { int width = config.readNumEntry("Width"+QString::number(i), -1 ); setColumnWidth(i, width == -1 ? columnWidth(i) : width ); } } TableView::TableView( MainWindow* window, QWidget* wid ) : QTable( wid ), TodoView( window ) { // Load icons // TODO - probably should be done globally somewhere else, // see also quickeditimpl.cpp/h, taskeditoroverview.cpp/h m_pic_completed = Resource::loadPixmap( "todo/completed" ); QString namestr; for ( unsigned int i = 1; i < 6; i++ ) { namestr = "todo/priority"; namestr.append( QString::number( i ) ); m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr ); } @@ -122,53 +143,66 @@ TableView::TableView( MainWindow* window, QWidget* wid ) } /* a new day has started * update the day */ void TableView::newDay() { clear(); updateView(); } TableView::~TableView() { Config config( "todo" ); config.setGroup( "Options" ); for (int i = 0; i < numCols(); i++ ) config.writeEntry("Width"+QString::number(i), columnWidth(i) ); } void TableView::slotShowMenu() { QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() ); menu->exec(QCursor::pos() ); delete menu; } QString TableView::type() const { return QString::fromLatin1( tr("Table View") ); } int TableView::current() { - if (numRows() == 0 ) return 1; + if (numRows() == 0 ) return 0; int uid = sorted().uidAt(currentRow() ); return uid; } +int TableView::next() { + if ( numRows() == 0 ) return 0; + if ( currentRow() + 1 >= numRows() ) return 0; + setCurrentCell( currentRow() +1, currentColumn() ); + return sorted().uidAt( currentRow() ); +} +int TableView::prev() { + if ( numRows() == 0 ) return 0; + if ( currentRow() - 1 < 0 ) return 0; + setCurrentCell( currentRow() -1, currentColumn() ); + return sorted().uidAt( currentRow() ); + +} QString TableView::currentRepresentation() { OTodo to = sorted()[currentRow()]; return to.summary().isEmpty() ? to.description().left(20) : to.summary() ; } /* show overdue */ void TableView::showOverDue( bool ) { clear(); updateView(); } void TableView::updateView( ) { qWarning("update view"); m_row = false; static int id; id = startTimer(4000 ); /* FIXME we want one page to be read! * * Calculate that screensize */ todoWindow()->setReadAhead( 4 ); sort(); OTodoAccess::List::Iterator it, end; it = sorted().begin(); end = sorted().end(); @@ -198,110 +232,121 @@ void TableView::setTodo( int, const OTodo&) { /* repaint */ repaint(); } void TableView::addEvent( const OTodo&) { /* fix problems of not showing the 'Haken' */ updateView(); } /* * find the event * and then replace the complete row */ void TableView::replaceEvent( const OTodo& ev) { addEvent( ev ); } /* * re aligning table can be slow too * FIXME: look what performs better * either this or the old align table */ void TableView::removeEvent( int ) { updateView(); } void TableView::setShowCompleted( bool b) { - qWarning("Show Completed %d" + b ); + qWarning("Show Completed %d" , b ); updateView(); } void TableView::setShowDeadline( bool b ) { - qWarning( "Show DeadLine %d" + b ); + qWarning( "Show DeadLine %d" , b ); if ( b ) showColumn( 3 ); else hideColumn( 3 ); // Try to intelligently size columns // TODO - would use width() below, but doesn't have valid value at time of c'tor int col2width = 238; int width = m_pic_completed.width(); setColumnWidth( 0, width ); col2width -= width; width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8; setColumnWidth( 1, width ); col2width -= width; if ( b ) { width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8; setColumnWidth( 3, width ); col2width -= width; } setColumnWidth( 2, col2width ); } void TableView::setShowCategory( const QString& str) { qWarning("setShowCategory"); if ( str != m_oleCat || m_first ) updateView(); m_oleCat = str; m_first = false; } void TableView::clear() { setNumRows(0); } void TableView::slotClicked(int row, int col, int, const QPoint& point) { + if ( m_editorWidget.cellWidget() ) { + //setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() ); + endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(), + true, true ); + m_editorWidget.releaseCellWidget(); + } + if ( !cellGeometry(row, col ).contains(point ) ) return; int ui= sorted().uidAt( row ); switch( col ) { case 0:{ int x = point.x() -columnPos( col ); int y = point.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 ) { TodoView::complete(sorted()[row] ); } } break; - case 1: + // Priority emit a double click... + case 1:{ + QWidget* wid = beginEdit( row, col, FALSE ); + m_editorWidget.setCellWidget( wid, row, col ); + } break; case 2: { m_menuTimer->stop(); showTodo( ui ); break; } case 3: { m_menuTimer->stop(); TodoView::edit( ui ); break; } } } void TableView::slotPressed(int row, int col, int, const QPoint& point) { qWarning("pressed row %d col %d x:%d+y:%d", row,col,point.x(),point.y() ); m_prevP = point; /* TextColumn column */ if ( col == 2 && cellGeometry( row, col ).contains( point ) ) m_menuTimer->start( 750, TRUE ); @@ -425,48 +470,49 @@ void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool } QWidget* TableView::createEditor(int row, int col, bool )const { switch( col ) { case 1: { /* the priority stuff */ QComboBox* combo = new QComboBox( viewport() ); for ( int i = 0; i < 5; i++ ) { combo->insertItem( m_pic_priority[ i ] ); } combo->setCurrentItem( sorted()[row].priority()-1 ); return combo; } /* summary */ case 2:{ QLineEdit* edit = new QLineEdit( viewport() ); edit->setText( sorted()[row].summary() ); return edit; } case 0: default: return 0l; } } void TableView::setCellContentFromEditor(int row, int col ) { + qWarning("set cell content from editor"); if ( col == 1 ) { QWidget* wid = cellWidget(row, 1 ); if ( wid->inherits("QComboBox") ) { int pri = ((QComboBox*)wid)->currentItem() + 1; OTodo todo = sorted()[row]; if ( todo.priority() != pri ) { todo.setPriority( pri ); TodoView::update( todo.uid(), todo ); updateView(); } } }else if ( col == 2) { QWidget* wid = cellWidget(row, 2); if ( wid->inherits("QLineEdit") ) { QString text = ((QLineEdit*)wid)->text(); OTodo todo = sorted()[row]; if ( todo.summary() != text ) { todo.setSummary( text ); TodoView::update( todo.uid(), todo ); updateView(); } } } } @@ -521,34 +567,62 @@ void TableView::timerEvent( QTimerEvent* ) { * the todo is marked as completed... * REASON: QTable is doing auto scrolling which leads to a move * in the x coordinate and this way it's able to pass the * m_completeStrokeWidth criteria * WORKAROUND: strike through needs to strike through the same * row and two columns! */ void TableView::contentsMouseReleaseEvent( QMouseEvent* e) { int row = rowAt(m_prevP.y()); int colOld = columnAt(m_prevP.x() ); int colNew = columnAt(e->x() ); qWarning("colNew: %d colOld: %d", colNew, colOld ); if ( row == rowAt( e->y() ) && row != -1 && colOld != colNew ) { TodoView::complete( sorted()[row] ); return; } QTable::contentsMouseReleaseEvent( e ); } void TableView::contentsMouseMoveEvent( QMouseEvent* e ) { m_menuTimer->stop(); QTable::contentsMouseMoveEvent( e ); } void TableView::keyPressEvent( QKeyEvent* event) { + if ( m_editorWidget.cellWidget() ) { +// setCellContentFromEditor(m_editorWidget.cellRow(), m_editorWidget.cellCol() ); + endEdit(m_editorWidget.cellRow(), m_editorWidget.cellCol(), + true, true ); + m_editorWidget.releaseCellWidget(); + setFocus(); + } + int row = currentRow(); + int col = currentColumn(); + + char key = ::toupper( event->ascii() ); + /* let QTable also handle the d later */ + if ( key == 'D' ) + removeQuery( sorted().uidAt( row ) ); + + switch( event->key() ) { case Qt::Key_F33: case Qt::Key_Enter: case Qt::Key_Return: - showTodo( sorted().uidAt( currentRow() ) ); + case Qt::Key_Space: + if ( col == 0 ) { + TodoView::complete(sorted()[row]); + }else if ( col == 1 ) { + QWidget* wid = beginEdit(row, col, FALSE ); + m_editorWidget.setCellWidget( wid, row, col ); + }else if ( col == 2 ) { + showTodo( sorted().uidAt( currentRow() ) ); + }else if ( col == 3 ) { + TodoView::edit( sorted().uidAt(row) ); + } + break; default: QTable::keyPressEvent( event ); } } + |