summaryrefslogtreecommitdiff
authordrw <drw>2002-12-22 15:54:54 (UTC)
committer drw <drw>2002-12-22 15:54:54 (UTC)
commit043abeb16589fa2aaa0881d2781bb46fa99007b6 (patch) (unidiff)
tree9a36c9bf485dd72d021b57a3de56b2f27f2e7f96
parent255d01d91f79b27765a03e100a6704fb43e1a9c1 (diff)
downloadopie-043abeb16589fa2aaa0881d2781bb46fa99007b6.zip
opie-043abeb16589fa2aaa0881d2781bb46fa99007b6.tar.gz
opie-043abeb16589fa2aaa0881d2781bb46fa99007b6.tar.bz2
Main todo view text color and column width fixes.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/todo/tableview.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/core/pim/todo/tableview.cpp b/core/pim/todo/tableview.cpp
index faf4611..d229f52 100644
--- a/core/pim/todo/tableview.cpp
+++ b/core/pim/todo/tableview.cpp
@@ -37,123 +37,107 @@
37#include <qpe/config.h> 37#include <qpe/config.h>
38#include <qpe/resource.h> 38#include <qpe/resource.h>
39 39
40#include <opie/orecur.h> 40#include <opie/orecur.h>
41 41
42#include "mainwindow.h" 42#include "mainwindow.h"
43//#include "tableitems.h" 43//#include "tableitems.h"
44#include "tableview.h" 44#include "tableview.h"
45 45
46using namespace Todo; 46using namespace Todo;
47 47
48namespace { 48namespace {
49 static const int BoxSize = 14; 49 static const int BoxSize = 14;
50 static const int RowHeight = 20; 50 static const int RowHeight = 20;
51} 51}
52 52
53 53
54void TableView::initConfig() { 54void TableView::initConfig() {
55 Config config( "todo" ); 55 Config config( "todo" );
56 config.setGroup( "Options" ); 56 config.setGroup( "Options" );
57 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 ); 57 m_completeStrokeWidth = config.readNumEntry( "CompleteStrokeWidth", 8 );
58} 58}
59 59
60TableView::TableView( MainWindow* window, QWidget* wid ) 60TableView::TableView( MainWindow* window, QWidget* wid )
61 : QTable( wid ), TodoView( window ) { 61 : QTable( wid ), TodoView( window ) {
62 setUpdatesEnabled( false ); 62 setUpdatesEnabled( false );
63 viewport()->setUpdatesEnabled( false ); 63 viewport()->setUpdatesEnabled( false );
64 m_enablePaint = false; 64 m_enablePaint = false;
65 setNumRows(0); 65 setNumRows(0);
66 setNumCols(4); 66 setNumCols(4);
67 67
68 horizontalHeader()->setLabel( 0, tr("C.") ); 68 horizontalHeader()->setLabel( 0, tr("C.") );
69 horizontalHeader()->setLabel( 1, tr("Prior.") ); 69 horizontalHeader()->setLabel( 1, tr("Priority") );
70 horizontalHeader()->setLabel( 2, tr("Description" ) ); 70 horizontalHeader()->setLabel( 2, tr("Description" ) );
71 horizontalHeader()->setLabel( 3, tr("Deadline") ); 71 horizontalHeader()->setLabel( 3, tr("Deadline") );
72 72
73 setShowDeadline( todoWindow()->showDeadline() );
74
73 setSorting( TRUE ); 75 setSorting( TRUE );
74 setSelectionMode( NoSelection ); 76 setSelectionMode( NoSelection );
75 77
76 setLeftMargin( 0 ); 78 setLeftMargin( 0 );
77 verticalHeader()->hide(); 79 verticalHeader()->hide();
78 80
79 if ( todoWindow()->showDeadline() )
80 showColumn( 3 );
81 else
82 hideColumn( 3 );
83
84 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ), 81 connect((QTable*)this, SIGNAL( clicked( int, int, int, const QPoint& ) ),
85 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) ); 82 this, SLOT( slotClicked(int, int, int, const QPoint& ) ) );
86 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ), 83 connect((QTable*)this, SIGNAL( pressed( int, int, int, const QPoint& ) ),
87 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) ); 84 this, SLOT( slotPressed(int, int, int, const QPoint& ) ) );
88 connect((QTable*)this, SIGNAL(valueChanged(int, int) ), 85 connect((QTable*)this, SIGNAL(valueChanged(int, int) ),
89 this, SLOT( slotValueChanged(int, int) ) ); 86 this, SLOT( slotValueChanged(int, int) ) );
90 connect((QTable*)this, SIGNAL(currentChanged(int, int) ), 87 connect((QTable*)this, SIGNAL(currentChanged(int, int) ),
91 this, SLOT( slotCurrentChanged(int, int) ) ); 88 this, SLOT( slotCurrentChanged(int, int) ) );
92 89
93 m_menuTimer = new QTimer( this ); 90 m_menuTimer = new QTimer( this );
94 connect( m_menuTimer, SIGNAL(timeout()), 91 connect( m_menuTimer, SIGNAL(timeout()),
95 this, SLOT(slotShowMenu()) ); 92 this, SLOT(slotShowMenu()) );
96 93
97 m_enablePaint = true; 94 m_enablePaint = true;
98 setUpdatesEnabled( true ); 95 setUpdatesEnabled( true );
99 viewport()->setUpdatesEnabled( true ); 96 viewport()->setUpdatesEnabled( true );
100 viewport()->update(); 97 viewport()->update();
101 setSortOrder( 0 ); 98 setSortOrder( 0 );
102 setAscending( TRUE ); 99 setAscending( TRUE );
103 m_first = true; 100 m_first = true;
104 101
105 // Load icons 102 // Load icons
106 // TODO - probably should be done globally somewhere else, see also quickeditimpl.cpp/h 103 // TODO - probably should be done globally somewhere else, see also quickeditimpl.cpp/h
107 m_pic_completed = Resource::loadPixmap( "todo/completed" ); 104 m_pic_completed = Resource::loadPixmap( "todo/completed" );
108 QString namestr; 105 QString namestr;
109 for ( unsigned int i = 1; i < 6; i++ ) { 106 for ( unsigned int i = 1; i < 6; i++ ) {
110 namestr = "todo/priority"; 107 namestr = "todo/priority";
111 namestr.append( QString::number( i ) ); 108 namestr.append( QString::number( i ) );
112 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr ); 109 m_pic_priority[ i - 1 ] = Resource::loadPixmap( namestr );
113 } 110 }
114 111
115 // Try to intelligently size columns
116 int col2width = 240;
117 int width = m_pic_completed.width();
118 setColumnWidth( 0, width );
119 col2width -= width;
120 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width()+8;
121 setColumnWidth( 1, width );
122 col2width -= width;
123 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width()+8;
124 setColumnWidth( 3, width );
125 col2width -= width;
126 setColumnWidth( 2, col2width - 2 );
127
128 /* now let's init the config */ 112 /* now let's init the config */
129 initConfig(); 113 initConfig();
130} 114}
131/* a new day has started 115/* a new day has started
132 * update the day 116 * update the day
133 */ 117 */
134void TableView::newDay() { 118void TableView::newDay() {
135 clear(); 119 clear();
136 updateView(); 120 updateView();
137} 121}
138TableView::~TableView() { 122TableView::~TableView() {
139 123
140} 124}
141void TableView::slotShowMenu() { 125void TableView::slotShowMenu() {
142 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() ); 126 QPopupMenu *menu = todoWindow()->contextMenu( current(), sorted()[currentRow()].recurrence().doesRecur() );
143 menu->exec(QCursor::pos() ); 127 menu->exec(QCursor::pos() );
144 delete menu; 128 delete menu;
145} 129}
146QString TableView::type() const { 130QString TableView::type() const {
147 return QString::fromLatin1( tr("Table View") ); 131 return QString::fromLatin1( tr("Table View") );
148} 132}
149int TableView::current() { 133int TableView::current() {
150 int uid = sorted().uidAt(currentRow() ); 134 int uid = sorted().uidAt(currentRow() );
151 135
152 return uid; 136 return uid;
153} 137}
154QString TableView::currentRepresentation() { 138QString TableView::currentRepresentation() {
155 OTodo to = sorted()[currentRow()]; 139 OTodo to = sorted()[currentRow()];
156 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ; 140 return to.summary().isEmpty() ? to.description().left(20) : to.summary() ;
157} 141}
158/* show overdue */ 142/* show overdue */
159void TableView::showOverDue( bool ) { 143void TableView::showOverDue( bool ) {
@@ -196,70 +180,86 @@ void TableView::updateView( ) {
196// int el = time.elapsed(); 180// int el = time.elapsed();
197} 181}
198void TableView::setTodo( int, const OTodo&) { 182void TableView::setTodo( int, const OTodo&) {
199 sort(); 183 sort();
200 184
201 /* repaint */ 185 /* repaint */
202 repaint(); 186 repaint();
203} 187}
204void TableView::addEvent( const OTodo&) { 188void TableView::addEvent( const OTodo&) {
205 189
206 /* fix problems of not showing the 'Haken' */ 190 /* fix problems of not showing the 'Haken' */
207 updateView(); 191 updateView();
208} 192}
209/* 193/*
210 * find the event 194 * find the event
211 * and then replace the complete row 195 * and then replace the complete row
212 */ 196 */
213void TableView::replaceEvent( const OTodo& ev) { 197void TableView::replaceEvent( const OTodo& ev) {
214 addEvent( ev ); 198 addEvent( ev );
215} 199}
216/* 200/*
217 * re aligning table can be slow too 201 * re aligning table can be slow too
218 * FIXME: look what performs better 202 * FIXME: look what performs better
219 * either this or the old align table 203 * either this or the old align table
220 */ 204 */
221void TableView::removeEvent( int ) { 205void TableView::removeEvent( int ) {
222 updateView(); 206 updateView();
223} 207}
224void TableView::setShowCompleted( bool b) { 208void TableView::setShowCompleted( bool b) {
225 qWarning("Show Completed %d" + b ); 209 qWarning("Show Completed %d" + b );
226 updateView(); 210 updateView();
227} 211}
228void TableView::setShowDeadline( bool b) { 212void TableView::setShowDeadline( bool b ) {
229 qWarning("Show DeadLine %d" + b ); 213 qWarning( "Show DeadLine %d" + b );
230 if (b) 214 if ( b )
231 showColumn(3 ); 215 showColumn( 3 );
232 else 216 else
233 hideColumn(3 ); 217 hideColumn( 3 );
218
219 // Try to intelligently size columns
220 // TODO - would use width() below, but doesn't have valid value at time of c'tor
221 int col2width = 238;
222 int width = m_pic_completed.width();
223 setColumnWidth( 0, width );
224 col2width -= width;
225 width = fontMetrics().boundingRect( horizontalHeader()->label( 1 ) ).width() + 8;
226 setColumnWidth( 1, width );
227 col2width -= width;
228 if ( b ) {
229 width = fontMetrics().boundingRect( horizontalHeader()->label( 3 ) ).width() + 8;
230 setColumnWidth( 3, width );
231 col2width -= width;
232 }
233 setColumnWidth( 2, col2width );
234} 234}
235void TableView::setShowCategory( const QString& str) { 235void TableView::setShowCategory( const QString& str) {
236 qWarning("setShowCategory"); 236 qWarning("setShowCategory");
237 if ( str != m_oleCat || m_first ) 237 if ( str != m_oleCat || m_first )
238 updateView(); 238 updateView();
239 239
240 m_oleCat = str; 240 m_oleCat = str;
241 m_first = false; 241 m_first = false;
242 242
243} 243}
244void TableView::clear() { 244void TableView::clear() {
245 setNumRows(0); 245 setNumRows(0);
246} 246}
247void TableView::slotClicked(int row, int col, int, 247void TableView::slotClicked(int row, int col, int,
248 const QPoint& point) { 248 const QPoint& point) {
249 if ( !cellGeometry(row, col ).contains(point ) ) 249 if ( !cellGeometry(row, col ).contains(point ) )
250 return; 250 return;
251 251
252 int ui= sorted().uidAt( row ); 252 int ui= sorted().uidAt( row );
253 253
254 254
255 switch( col ) { 255 switch( col ) {
256 case 0:{ 256 case 0:{
257 int x = point.x() -columnPos( col ); 257 int x = point.x() -columnPos( col );
258 int y = point.y() -rowPos( row ); 258 int y = point.y() -rowPos( row );
259 int w = columnWidth( col ); 259 int w = columnWidth( col );
260 int h = rowHeight( row ); 260 int h = rowHeight( row );
261 if ( x >= ( w - BoxSize ) / 2 && 261 if ( x >= ( w - BoxSize ) / 2 &&
262 x <= ( w - BoxSize ) / 2 + BoxSize && 262 x <= ( w - BoxSize ) / 2 + BoxSize &&
263 y >= ( h - BoxSize ) / 2 && 263 y >= ( h - BoxSize ) / 2 &&
264 y <= ( h - BoxSize ) / 2 + BoxSize ) { 264 y <= ( h - BoxSize ) / 2 + BoxSize ) {
265 TodoView::complete(sorted()[row] ); 265 TodoView::complete(sorted()[row] );
@@ -307,67 +307,69 @@ QWidget* TableView::widget() {
307 * because we want to sort whole row 307 * because we want to sort whole row
308 * based 308 * based
309 * We event want to set the setOrder 309 * We event want to set the setOrder
310 * to a sort() and update() 310 * to a sort() and update()
311 */ 311 */
312void TableView::sortColumn( int col, bool asc, bool ) { 312void TableView::sortColumn( int col, bool asc, bool ) {
313 qWarning("bool %d", asc ); 313 qWarning("bool %d", asc );
314 setSortOrder( col ); 314 setSortOrder( col );
315 setAscending( asc ); 315 setAscending( asc );
316 updateView(); 316 updateView();
317} 317}
318void TableView::viewportPaintEvent( QPaintEvent* e) { 318void TableView::viewportPaintEvent( QPaintEvent* e) {
319 if (m_enablePaint ) 319 if (m_enablePaint )
320 QTable::viewportPaintEvent( e ); 320 QTable::viewportPaintEvent( e );
321} 321}
322/* 322/*
323 * This segment is copyrighted by TT 323 * This segment is copyrighted by TT
324 * it was taken from their todolist 324 * it was taken from their todolist
325 * application this code is GPL 325 * application this code is GPL
326 */ 326 */
327void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 327void TableView::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
328 const QColorGroup &cg = colorGroup(); 328 const QColorGroup &cg = colorGroup();
329 329
330 p->save(); 330 p->save();
331 331
332 OTodo task = sorted()[row]; 332 OTodo task = sorted()[row];
333 333
334 // TODO - give user option for grid or bars? 334 // TODO - give user option for grid or bars?
335 335
336 // Paint alternating background bars 336 // Paint alternating background bars
337 if ( (row % 2 ) == 0 ) { 337 if ( (row % 2 ) == 0 ) {
338 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 338 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
339 p->setPen( QPen( cg.text() ) );
339 } 340 }
340 else { 341 else {
341 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) ); 342 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) );
343 p->setPen( QPen( cg.buttonText() ) );
342 } 344 }
343 345
344 // Paint grid 346 // Paint grid
345 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 347 //p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
346 //QPen op = p->pen(); 348 //QPen op = p->pen();
347 //p->setPen(cg.mid()); 349 //p->setPen(cg.mid());
348 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 ); 350 //p->drawLine( 0, cr.height() - 1, cr.width() - 1, cr.height() - 1 );
349 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 ); 351 //p->drawLine( cr.width() - 1, 0, cr.width() - 1, cr.height() - 1 );
350 //p->setPen(op); 352 //p->setPen(op);
351 353
352 QFont f = p->font(); 354 QFont f = p->font();
353 QFontMetrics fm(f); 355 QFontMetrics fm(f);
354 356
355 int marg = ( cr.width() - BoxSize ) / 2; 357 int marg = ( cr.width() - BoxSize ) / 2;
356 int x = 0; 358 int x = 0;
357 int y = ( cr.height() - BoxSize ) / 2; 359 int y = ( cr.height() - BoxSize ) / 2;
358 360
359 switch(col) { 361 switch(col) {
360 case 0: // completed field 362 case 0: // completed field
361 { 363 {
362 //p->setPen( QPen( cg.text() ) ); 364 //p->setPen( QPen( cg.text() ) );
363 //p->drawRect( x + marg, y, BoxSize, BoxSize ); 365 //p->drawRect( x + marg, y, BoxSize, BoxSize );
364 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 ); 366 //p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
365 if ( task.isCompleted() ) { 367 if ( task.isCompleted() ) {
366 p->drawPixmap( x + marg, y, m_pic_completed ); 368 p->drawPixmap( x + marg, y, m_pic_completed );
367 } 369 }
368 } 370 }
369 break; 371 break;
370 case 1: // priority field 372 case 1: // priority field
371 { 373 {
372 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] ); 374 p->drawPixmap( x + marg, y, m_pic_priority[ task.priority() - 1 ] );
373 } 375 }