summaryrefslogtreecommitdiff
path: root/core/pim/todo/tableview.cpp
Side-by-side diff
Diffstat (limited to 'core/pim/todo/tableview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableview.cpp86
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
@@ -18,47 +18,68 @@
++=   -.     .`     .: 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 )
@@ -134,29 +155,42 @@ TableView::~TableView() {
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");
@@ -210,29 +244,29 @@ void TableView::addEvent( const OTodo&) {
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;
@@ -250,46 +284,57 @@ void TableView::setShowCategory( const QString& str) {
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;
}
@@ -437,24 +482,25 @@ QWidget* TableView::createEditor(int row, int col, bool )const {
/* 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) {
@@ -533,22 +579,50 @@ void TableView::contentsMouseReleaseEvent( QMouseEvent* e) {
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 );
}
}
+