author | zecke <zecke> | 2002-04-23 12:04:28 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-04-23 12:04:28 (UTC) |
commit | 367304a610dd618ad45ddce8256ba4d7d8ded442 (patch) (unidiff) | |
tree | c73838ac2bb496f6233ac6b793d5b17c867efbdb | |
parent | 3197bbef89e9001929d826a8cbe39d675bcf7917 (diff) | |
download | opie-367304a610dd618ad45ddce8256ba4d7d8ded442.zip opie-367304a610dd618ad45ddce8256ba4d7d8ded442.tar.gz opie-367304a610dd618ad45ddce8256ba4d7d8ded442.tar.bz2 |
ToDoEvent::richText() added
this patch came from Stefan Eilers
is that the right place for it or does it belong into
the todo app itself?
-rw-r--r-- | libopie/todoevent.cpp | 46 | ||||
-rw-r--r-- | libopie/todoevent.h | 27 |
2 files changed, 73 insertions, 0 deletions
diff --git a/libopie/todoevent.cpp b/libopie/todoevent.cpp index a5dba4f..5537b77 100644 --- a/libopie/todoevent.cpp +++ b/libopie/todoevent.cpp | |||
@@ -1,30 +1,38 @@ | |||
1 | 1 | ||
2 | #include <opie/todoevent.h> | 2 | #include <opie/todoevent.h> |
3 | |||
4 | |||
3 | #include <qpe/palmtopuidgen.h> | 5 | #include <qpe/palmtopuidgen.h> |
4 | #include <qpe/stringutil.h> | 6 | #include <qpe/stringutil.h> |
5 | #include <qpe/palmtoprecord.h> | 7 | #include <qpe/palmtoprecord.h> |
6 | 8 | ||
9 | #include <qpe/stringutil.h> | ||
10 | #include <qpe/categories.h> | ||
11 | #include <qpe/categoryselect.h> | ||
12 | |||
13 | #include <qobject.h> | ||
14 | |||
7 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) | 15 | ToDoEvent::ToDoEvent(const ToDoEvent &event ) |
8 | { | 16 | { |
9 | *this = event; | 17 | *this = event; |
10 | } | 18 | } |
11 | 19 | ||
12 | ToDoEvent::ToDoEvent(bool completed, int priority, const QStringList &category, | 20 | ToDoEvent::ToDoEvent(bool completed, int priority, const QStringList &category, |
13 | const QString &description, bool hasDate, QDate date, int uid ) | 21 | const QString &description, bool hasDate, QDate date, int uid ) |
14 | { | 22 | { |
15 | m_date = date; | 23 | m_date = date; |
16 | m_isCompleted = completed; | 24 | m_isCompleted = completed; |
17 | m_hasDate = hasDate; | 25 | m_hasDate = hasDate; |
18 | m_priority = priority; | 26 | m_priority = priority; |
19 | m_category = category; | 27 | m_category = category; |
20 | m_desc = Qtopia::simplifyMultiLineSpace(description ); | 28 | m_desc = Qtopia::simplifyMultiLineSpace(description ); |
21 | if (uid == -1 ) { | 29 | if (uid == -1 ) { |
22 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); | 30 | Qtopia::UidGen *uidgen = new Qtopia::UidGen(); |
23 | uid = uidgen->generate(); | 31 | uid = uidgen->generate(); |
24 | delete uidgen; | 32 | delete uidgen; |
25 | }// generate the ids | 33 | }// generate the ids |
26 | m_uid = uid; | 34 | m_uid = uid; |
27 | } | 35 | } |
28 | QArray<int> ToDoEvent::categories()const | 36 | QArray<int> ToDoEvent::categories()const |
29 | { | 37 | { |
30 | QArray<int> array(m_category.count() ); // currently the datebook can be only in one category | 38 | QArray<int> array(m_category.count() ); // currently the datebook can be only in one category |
@@ -90,48 +98,86 @@ void ToDoEvent::setHasDate( bool hasDate ) | |||
90 | void ToDoEvent::setDescription(const QString &desc ) | 98 | void ToDoEvent::setDescription(const QString &desc ) |
91 | { | 99 | { |
92 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); | 100 | m_desc = Qtopia::simplifyMultiLineSpace(desc ); |
93 | } | 101 | } |
94 | void ToDoEvent::setCategory( const QString &cat ) | 102 | void ToDoEvent::setCategory( const QString &cat ) |
95 | { | 103 | { |
96 | qWarning("setCategory %s", cat.latin1() ); | 104 | qWarning("setCategory %s", cat.latin1() ); |
97 | m_category.clear(); | 105 | m_category.clear(); |
98 | m_category << cat; | 106 | m_category << cat; |
99 | } | 107 | } |
100 | void ToDoEvent::setPriority(int prio ) | 108 | void ToDoEvent::setPriority(int prio ) |
101 | { | 109 | { |
102 | m_priority = prio; | 110 | m_priority = prio; |
103 | } | 111 | } |
104 | void ToDoEvent::setDate( QDate date ) | 112 | void ToDoEvent::setDate( QDate date ) |
105 | { | 113 | { |
106 | m_date = date; | 114 | m_date = date; |
107 | } | 115 | } |
108 | bool ToDoEvent::isOverdue( ) | 116 | bool ToDoEvent::isOverdue( ) |
109 | { | 117 | { |
110 | if( m_hasDate ) | 118 | if( m_hasDate ) |
111 | return QDate::currentDate() > m_date; | 119 | return QDate::currentDate() > m_date; |
112 | return false; | 120 | return false; |
113 | } | 121 | } |
122 | |||
123 | /*! | ||
124 | Returns a richt text string | ||
125 | */ | ||
126 | QString ToDoEvent::richText() const | ||
127 | { | ||
128 | QString text; | ||
129 | QStringList catlist; | ||
130 | |||
131 | // Description of the todo | ||
132 | if ( !description().isEmpty() ){ | ||
133 | text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; | ||
134 | text += Qtopia::escapeString(description() ) + "<br>"; | ||
135 | } | ||
136 | text += "<b>" + QObject::tr( "Priority:") +" </b>" | ||
137 | + QString::number( priority() ) + "<br>"; | ||
138 | if (hasDate() ){ | ||
139 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; | ||
140 | text += date().toString(); | ||
141 | text += "<br>"; | ||
142 | } | ||
143 | |||
144 | // Open database of all categories and get the list of | ||
145 | // the categories this todoevent belongs to. | ||
146 | // Then print them... | ||
147 | // I am not sure whether there is no better way doing this !? | ||
148 | Categories catdb; | ||
149 | catdb.load( categoryFileName() ); | ||
150 | catlist = allCategories(); | ||
151 | |||
152 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | ||
153 | for ( QStringList::Iterator it = catlist.begin(); it != catlist.end(); ++it ) { | ||
154 | text += catdb.label ("todo", (*it).toInt()); | ||
155 | } | ||
156 | text += "<br>"; | ||
157 | return text; | ||
158 | } | ||
159 | |||
114 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ | 160 | bool ToDoEvent::operator<( const ToDoEvent &toDoEvent )const{ |
115 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 161 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
116 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 162 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
117 | if( hasDate() && toDoEvent.hasDate() ){ | 163 | if( hasDate() && toDoEvent.hasDate() ){ |
118 | if( date() == toDoEvent.date() ){ // let's the priority decide | 164 | if( date() == toDoEvent.date() ){ // let's the priority decide |
119 | return priority() < toDoEvent.priority(); | 165 | return priority() < toDoEvent.priority(); |
120 | }else{ | 166 | }else{ |
121 | return date() < toDoEvent.date(); | 167 | return date() < toDoEvent.date(); |
122 | } | 168 | } |
123 | } | 169 | } |
124 | return false; | 170 | return false; |
125 | } | 171 | } |
126 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const | 172 | bool ToDoEvent::operator<=(const ToDoEvent &toDoEvent )const |
127 | { | 173 | { |
128 | if( !hasDate() && !toDoEvent.hasDate() ) return true; | 174 | if( !hasDate() && !toDoEvent.hasDate() ) return true; |
129 | if( !hasDate() && toDoEvent.hasDate() ) return true; | 175 | if( !hasDate() && toDoEvent.hasDate() ) return true; |
130 | if( hasDate() && toDoEvent.hasDate() ){ | 176 | if( hasDate() && toDoEvent.hasDate() ){ |
131 | if( date() == toDoEvent.date() ){ // let's the priority decide | 177 | if( date() == toDoEvent.date() ){ // let's the priority decide |
132 | return priority() <= toDoEvent.priority(); | 178 | return priority() <= toDoEvent.priority(); |
133 | }else{ | 179 | }else{ |
134 | return date() <= toDoEvent.date(); | 180 | return date() <= toDoEvent.date(); |
135 | } | 181 | } |
136 | } | 182 | } |
137 | return true; | 183 | return true; |
diff --git a/libopie/todoevent.h b/libopie/todoevent.h index 0d477fd..40d8f0b 100644 --- a/libopie/todoevent.h +++ b/libopie/todoevent.h | |||
@@ -1,48 +1,75 @@ | |||
1 | 1 | ||
2 | #ifndef todoevent_h | 2 | #ifndef todoevent_h |
3 | #define todoevent_h | 3 | #define todoevent_h |
4 | 4 | ||
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | #include <qdatetime.h> | 6 | #include <qdatetime.h> |
7 | 7 | ||
8 | class ToDoEvent { | 8 | class ToDoEvent { |
9 | friend class ToDoDB; | 9 | friend class ToDoDB; |
10 | public: | 10 | public: |
11 | // priorities from Very low to very high | ||
11 | enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; | 12 | enum Priority { VERYHIGH=1, HIGH, NORMAL, LOW, VERYLOW }; |
13 | /* Constructs a new ToDoEvent | ||
14 | @param completed Is the TodoEvent completed | ||
15 | @param priority What is the priority of this ToDoEvent | ||
16 | @param category Which category does it belong( uid ) | ||
17 | @param description What is this ToDoEvent about | ||
18 | @param hasDate Does this Event got a deadline | ||
19 | @param date what is the deadline? | ||
20 | @param uid what is the UUID of this Event | ||
21 | **/ | ||
12 | ToDoEvent( bool completed = false, int priority = NORMAL, | 22 | ToDoEvent( bool completed = false, int priority = NORMAL, |
13 | const QStringList &category = QStringList(), | 23 | const QStringList &category = QStringList(), |
14 | const QString &description = QString::null , | 24 | const QString &description = QString::null , |
15 | bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); | 25 | bool hasDate = false, QDate date = QDate::currentDate(), int uid = -1 ); |
26 | /* Copy c'tor | ||
27 | |||
28 | **/ | ||
16 | ToDoEvent(const ToDoEvent & ); | 29 | ToDoEvent(const ToDoEvent & ); |
30 | |||
31 | /* | ||
32 | Is this event completed? | ||
33 | **/ | ||
17 | bool isCompleted() const; | 34 | bool isCompleted() const; |
35 | |||
36 | /* | ||
37 | Does this Event have a deadline | ||
38 | **/ | ||
18 | bool hasDate() const; | 39 | bool hasDate() const; |
40 | |||
41 | /* | ||
42 | What is the priority? | ||
43 | **/ | ||
19 | int priority()const ; | 44 | int priority()const ; |
20 | QStringList allCategories()const; | 45 | QStringList allCategories()const; |
21 | QArray<int> categories() const; | 46 | QArray<int> categories() const; |
22 | QDate date()const; | 47 | QDate date()const; |
23 | QString description()const; | 48 | QString description()const; |
24 | 49 | ||
50 | QString richText() const; | ||
51 | |||
25 | int uid()const { return m_uid;}; | 52 | int uid()const { return m_uid;}; |
26 | void setCompleted(bool completed ); | 53 | void setCompleted(bool completed ); |
27 | void setHasDate( bool hasDate ); | 54 | void setHasDate( bool hasDate ); |
28 | // if the category doesn't exist we will create it | 55 | // if the category doesn't exist we will create it |
29 | // this sets the the Category after this call category will be the only category | 56 | // this sets the the Category after this call category will be the only category |
30 | void setCategory( const QString &category ); | 57 | void setCategory( const QString &category ); |
31 | // adds a category to the Categories of this event | 58 | // adds a category to the Categories of this event |
32 | void insertCategory(const QString &category ); | 59 | void insertCategory(const QString &category ); |
33 | void clearCategories(); | 60 | void clearCategories(); |
34 | void setCategories(const QStringList& ); | 61 | void setCategories(const QStringList& ); |
35 | 62 | ||
36 | void setPriority(int priority ); | 63 | void setPriority(int priority ); |
37 | void setDate( QDate date ); | 64 | void setDate( QDate date ); |
38 | void setDescription(const QString& ); | 65 | void setDescription(const QString& ); |
39 | bool isOverdue(); | 66 | bool isOverdue(); |
40 | 67 | ||
41 | bool match( const QRegExp &r )const; | 68 | bool match( const QRegExp &r )const; |
42 | 69 | ||
43 | void setUid(int id) {m_uid = id; }; | 70 | void setUid(int id) {m_uid = id; }; |
44 | bool operator<(const ToDoEvent &toDoEvent )const; | 71 | bool operator<(const ToDoEvent &toDoEvent )const; |
45 | bool operator<=(const ToDoEvent &toDoEvent )const; | 72 | bool operator<=(const ToDoEvent &toDoEvent )const; |
46 | bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; | 73 | bool operator!=(const ToDoEvent &toDoEvent )const { return !(*this == toDoEvent); }; |
47 | bool operator>(const ToDoEvent &toDoEvent )const; | 74 | bool operator>(const ToDoEvent &toDoEvent )const; |
48 | bool operator>=(const ToDoEvent &toDoEvent)const; | 75 | bool operator>=(const ToDoEvent &toDoEvent)const; |