summaryrefslogtreecommitdiff
path: root/core/pim/todo/tableitems.cpp
Unidiff
Diffstat (limited to 'core/pim/todo/tableitems.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/todo/tableitems.cpp181
1 files changed, 181 insertions, 0 deletions
diff --git a/core/pim/todo/tableitems.cpp b/core/pim/todo/tableitems.cpp
new file mode 100644
index 0000000..ebfefc8
--- a/dev/null
+++ b/core/pim/todo/tableitems.cpp
@@ -0,0 +1,181 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 <>
4           .>+-=
5 _;:,     .>    :=|. This program is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This program is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28#include "tableview.h"
29
30#include "tableitems.h"
31#include <string.h>
32
33using namespace Todo;
34
35CheckItem::CheckItem( QTable* t,
36 const QString& sortKey,
37 int uid,
38 const QArray<int>& lis)
39 : OCheckItem(t, sortKey), m_uid(uid ), m_cat( lis )
40{
41}
42CheckItem::~CheckItem() {
43}
44void CheckItem::setChecked( bool b ) {
45 OCheckItem::setChecked(b);
46}
47void CheckItem::toggle() {
48 TableView* view = static_cast<TableView*>( table() );
49 OTodo ev = view->find( view->current() );
50 ev.setCompleted(!isChecked() );
51 view->updateFromTable( ev );
52
53 OCheckItem::toggle();
54 table()->updateCell( row(), col() );
55}
56int CheckItem::uid() const {
57 return m_uid;
58}
59QArray<int> CheckItem::cats() {
60 return m_cat;
61}
62
63/* ComboItem */
64ComboItem::ComboItem( QTable* t, EditType et )
65 : QTableItem( t, et, "3" ), m_cb(0)
66{
67 setReplaceable( FALSE );
68}
69ComboItem::~ComboItem() {
70
71}
72QWidget* ComboItem::createEditor()const {
73 qWarning( "create editor");
74 QString txt = text();
75
76 ( (ComboItem*)this)-> m_cb = new QComboBox( table()->viewport() );
77
78 m_cb->insertItem( "1" );
79 m_cb->insertItem( "2" );
80 m_cb->insertItem( "3" );
81 m_cb->insertItem( "4" );
82 m_cb->insertItem( "5" );
83 m_cb->setCurrentItem( txt.toInt() - 1 );
84
85 return m_cb;
86}
87void ComboItem::setContentFromEditor( QWidget* w) {
88 TableView* view = static_cast<TableView*>( table() );
89 OTodo ev = view->find( view->current() );
90
91 if ( w->inherits( "QComboBox" ) )
92 setText( ( (QComboBox*)w )->currentText() );
93 else
94 QTableItem::setContentFromEditor( w );
95
96 ev.setPriority( text().toInt() );
97 view->updateFromTable( ev );
98}
99void ComboItem::setText( const QString& s ) {
100 if ( m_cb )
101 m_cb->setCurrentItem( s.toInt()-1 );
102
103 QTableItem::setText( s );
104}
105QString ComboItem::text()const {
106 if ( m_cb)
107 return m_cb->currentText();
108
109 return QTableItem::text();
110}
111
112/* TodoTextItem */
113TodoTextItem::~TodoTextItem() {
114
115}
116TodoTextItem::TodoTextItem( QTable* t,
117 const QString& string )
118 : QTableItem( t, QTableItem::Never, string )
119{}
120
121/* DueTextItem */
122DueTextItem::DueTextItem( QTable* t, const OTodo& ev)
123 : QTableItem(t, Never, QString::null )
124{
125 setToDoEvent( ev );
126}
127DueTextItem::~DueTextItem() {
128
129}
130QString DueTextItem::key() const {
131 QString key;
132
133 if( m_hasDate ){
134 if(m_off == 0 ){
135 key.append("b");
136 }else if( m_off > 0 ){
137 key.append("c");
138 }else if( m_off < 0 ){
139 key.append("a");
140 }
141 key.append(QString::number(m_off ) );
142 }else{
143 key.append("d");
144 }
145 return key;
146}
147void DueTextItem::setCompleted( bool comp ) {
148 m_completed = comp;
149 table()->updateCell( row(), col() );
150}
151void DueTextItem::setToDoEvent( const OTodo& ev ) {
152 m_hasDate = ev.hasDueDate();
153 m_completed = ev.isCompleted();
154
155 if( ev.hasDueDate() ){
156 QDate today = QDate::currentDate();
157 m_off = today.daysTo(ev.dueDate() );
158 setText( QString::number(m_off) + " day(s) " );
159 }else{
160 setText("n.d." );
161 m_off = 0;
162 }
163}
164void DueTextItem::paint( QPainter* p, const QColorGroup &cg,
165 const QRect& cr, bool selected ) {
166 QColorGroup cg2(cg);
167
168 QColor text = cg.text();
169 if( m_hasDate && !m_completed ){
170 if( m_off < 0 ){
171 cg2.setColor(QColorGroup::Text, QColor(red ) );
172 }else if( m_off == 0 ){
173 cg2.setColor(QColorGroup::Text, QColor(yellow) ); // orange isn't predefined
174 }else if( m_off > 0){
175 cg2.setColor(QColorGroup::Text, QColor(green ) );
176 }
177 }
178 QTableItem::paint(p, cg2, cr, selected );
179 /* restore default color */
180 cg2.setColor(QColorGroup::Text, text );
181}