author | zautrix <zautrix> | 2004-09-13 21:35:12 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-13 21:35:12 (UTC) |
commit | bd6b4acb39498ffea3beea7d9b5f7620b60c14db (patch) (unidiff) | |
tree | e2d7425b7bb49fbcb7acb5ced497ac1fed06dfaf /libkdepim | |
parent | 06eabf6e82c0390699d11fd12580d91261829431 (diff) | |
download | kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.zip kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.tar.gz kdepimpi-bd6b4acb39498ffea3beea7d9b5f7620b60c14db.tar.bz2 |
Many bugfixes
-rw-r--r-- | libkdepim/addresseeview.cpp | 10 | ||||
-rw-r--r-- | libkdepim/kdateedit.cpp | 17 | ||||
-rw-r--r-- | libkdepim/kdateedit.h | 3 |
3 files changed, 24 insertions, 6 deletions
diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp index d710541..5c69010 100644 --- a/libkdepim/addresseeview.cpp +++ b/libkdepim/addresseeview.cpp | |||
@@ -1,389 +1,395 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | 3 | ||
4 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | 4 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <kabc/address.h> | 22 | #include <kabc/address.h> |
23 | #include <kabc/addressee.h> | 23 | #include <kabc/addressee.h> |
24 | #include <kabc/phonenumber.h> | 24 | #include <kabc/phonenumber.h> |
25 | #include <kglobal.h> | 25 | #include <kglobal.h> |
26 | //US#include <kglobalsettings.h> | 26 | //US#include <kglobalsettings.h> |
27 | #include <kiconloader.h> | 27 | #include <kiconloader.h> |
28 | #include <klocale.h> | 28 | #include <klocale.h> |
29 | //US #include <kstringhandler.h> | 29 | //US #include <kstringhandler.h> |
30 | #include <qscrollview.h> | 30 | #include <qscrollview.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | 34 | ||
35 | 35 | ||
36 | #include "externalapphandler.h" | 36 | #include "externalapphandler.h" |
37 | #include "addresseeview.h" | 37 | #include "addresseeview.h" |
38 | 38 | ||
39 | 39 | ||
40 | //US #ifndef DESKTOP_VERSION | 40 | //US #ifndef DESKTOP_VERSION |
41 | //US #include <qtopia/qcopenvelope_qws.h> | 41 | //US #include <qtopia/qcopenvelope_qws.h> |
42 | //US #include <qpe/qpeapplication.h> | 42 | //US #include <qpe/qpeapplication.h> |
43 | //US #endif | 43 | //US #endif |
44 | 44 | ||
45 | //US static int kphoneInstalled = 0; | 45 | //US static int kphoneInstalled = 0; |
46 | 46 | ||
47 | using namespace KPIM; | 47 | using namespace KPIM; |
48 | 48 | ||
49 | AddresseeView::AddresseeView( QWidget *parent, const char *name ) | 49 | AddresseeView::AddresseeView( QWidget *parent, const char *name ) |
50 | //US : KTextBrowser( parent, name ) | 50 | //US : KTextBrowser( parent, name ) |
51 | : QTextBrowser( parent, name ) | 51 | : QTextBrowser( parent, name ) |
52 | 52 | ||
53 | 53 | ||
54 | { | 54 | { |
55 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); | 55 | //US setWrapPolicy( QTextEdit::AtWordBoundary ); |
56 | setLinkUnderline( false ); | 56 | setLinkUnderline( false ); |
57 | // setVScrollBarMode( QScrollView::AlwaysOff ); | 57 | // setVScrollBarMode( QScrollView::AlwaysOff ); |
58 | //setHScrollBarMode( QScrollView::AlwaysOff ); | 58 | //setHScrollBarMode( QScrollView::AlwaysOff ); |
59 | 59 | ||
60 | //US QStyleSheet *sheet = styleSheet(); | 60 | //US QStyleSheet *sheet = styleSheet(); |
61 | //US QStyleSheetItem *link = sheet->item( "a" ); | 61 | //US QStyleSheetItem *link = sheet->item( "a" ); |
62 | //US link->setColor( KGlobalSettings::linkColor() ); | 62 | //US link->setColor( KGlobalSettings::linkColor() ); |
63 | 63 | ||
64 | } | 64 | } |
65 | 65 | ||
66 | void AddresseeView::setSource(const QString& n) | 66 | void AddresseeView::setSource(const QString& n) |
67 | { | 67 | { |
68 | qDebug("********AddresseeView::setSource %s", n.latin1()); | 68 | //qDebug("********AddresseeView::setSource %s", n.latin1()); |
69 | 69 | ||
70 | if ( n.left( 6 ) == "mailto" ) | 70 | if ( n.left( 6 ) == "mailto" ) |
71 | ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); | 71 | ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); |
72 | else if ( n.left( 7 ) == "phoneto" ) | 72 | else if ( n.left( 7 ) == "phoneto" ) |
73 | ExternalAppHandler::instance()->callByPhone( n.mid(8) ); | 73 | ExternalAppHandler::instance()->callByPhone( n.mid(8) ); |
74 | else if ( n.left( 5 ) == "faxto" ) | 74 | else if ( n.left( 5 ) == "faxto" ) |
75 | ExternalAppHandler::instance()->callByFax( n.mid(6) ); | 75 | ExternalAppHandler::instance()->callByFax( n.mid(6) ); |
76 | else if ( n.left( 5 ) == "smsto" ) | 76 | else if ( n.left( 5 ) == "smsto" ) |
77 | ExternalAppHandler::instance()->callBySMS( n.mid(6) ); | 77 | ExternalAppHandler::instance()->callBySMS( n.mid(6) ); |
78 | else if ( n.left( 7 ) == "pagerto" ) | 78 | else if ( n.left( 7 ) == "pagerto" ) |
79 | ExternalAppHandler::instance()->callByPager( n.mid(8) ); | 79 | ExternalAppHandler::instance()->callByPager( n.mid(8) ); |
80 | 80 | ||
81 | } | 81 | } |
82 | void AddresseeView::setAddressee( const KABC::Addressee& addr ) | 82 | void AddresseeView::setAddressee( const KABC::Addressee& addr ) |
83 | { | 83 | { |
84 | ExternalAppHandler* eah = ExternalAppHandler::instance(); | 84 | ExternalAppHandler* eah = ExternalAppHandler::instance(); |
85 | bool kemailAvail = eah->isEmailAppAvailable(); | 85 | bool kemailAvail = eah->isEmailAppAvailable(); |
86 | bool kphoneAvail = eah->isPhoneAppAvailable(); | 86 | bool kphoneAvail = eah->isPhoneAppAvailable(); |
87 | bool kfaxAvail = eah->isFaxAppAvailable(); | 87 | bool kfaxAvail = eah->isFaxAppAvailable(); |
88 | bool ksmsAvail = eah->isSMSAppAvailable(); | 88 | bool ksmsAvail = eah->isSMSAppAvailable(); |
89 | bool kpagerAvail = eah->isPagerAppAvailable(); | 89 | bool kpagerAvail = eah->isPagerAppAvailable(); |
90 | 90 | ||
91 | 91 | ||
92 | mAddressee = addr; | 92 | mAddressee = addr; |
93 | // clear view | 93 | // clear view |
94 | setText( QString::null ); | 94 | setText( QString::null ); |
95 | 95 | ||
96 | if ( mAddressee.isEmpty() ) | 96 | if ( mAddressee.isEmpty() ) |
97 | return; | 97 | return; |
98 | 98 | ||
99 | QString name = ( mAddressee.assembledName().isEmpty() ? | 99 | QString name = ( mAddressee.assembledName().isEmpty() ? |
100 | mAddressee.formattedName() : mAddressee.assembledName() ); | 100 | mAddressee.formattedName() : mAddressee.assembledName() ); |
101 | 101 | ||
102 | QString dynamicPart; | 102 | QString dynamicPart; |
103 | 103 | ||
104 | QStringList emails = mAddressee.emails(); | 104 | QStringList emails = mAddressee.emails(); |
105 | QStringList::ConstIterator emailIt; | 105 | QStringList::ConstIterator emailIt; |
106 | QString type = i18n( "Email" ); | 106 | QString type = i18n( "Email" ); |
107 | emailIt = emails.begin(); | 107 | emailIt = emails.begin(); |
108 | if ( emailIt != emails.end() ) { | 108 | if ( emailIt != emails.end() ) { |
109 | if ( kemailAvail ) { | 109 | if ( kemailAvail ) { |
110 | dynamicPart += QString( | 110 | dynamicPart += QString( |
111 | "<tr><td align=\"right\"><b>%1</b></td>" | 111 | "<tr><td align=\"right\"><b>%1</b></td>" |
112 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) | 112 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) |
113 | .arg( type ) | 113 | .arg( type ) |
114 | .arg( name ) | 114 | .arg( name ) |
115 | .arg( *emailIt ) | 115 | .arg( *emailIt ) |
116 | .arg( *emailIt ); | 116 | .arg( *emailIt ); |
117 | ++emailIt; | 117 | ++emailIt; |
118 | } else { | 118 | } else { |
119 | dynamicPart += QString( | 119 | dynamicPart += QString( |
120 | "<tr><td align=\"right\"><b>%1</b></td>" | 120 | "<tr><td align=\"right\"><b>%1</b></td>" |
121 | "<td align=\"left\">%2</td></tr>" ) | 121 | "<td align=\"left\">%2</td></tr>" ) |
122 | .arg( type ) | 122 | .arg( type ) |
123 | .arg( *emailIt ); | 123 | .arg( *emailIt ); |
124 | ++emailIt; | 124 | ++emailIt; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | if ( mAddressee.birthday().date().isValid() ) { | |
128 | dynamicPart += QString( | ||
129 | "<tr><td align=\"right\"><b>%1</b></td>" | ||
130 | "<td align=\"left\">%2</td></tr>" ) | ||
131 | .arg( i18n ("Birthday") ) | ||
132 | .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); | ||
133 | } | ||
128 | KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); | 134 | KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); |
129 | KABC::PhoneNumber::List::ConstIterator phoneIt; | 135 | KABC::PhoneNumber::List::ConstIterator phoneIt; |
130 | QString extension; | 136 | QString extension; |
131 | int phonetype; | 137 | int phonetype; |
132 | QString sms; | 138 | QString sms; |
133 | for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { | 139 | for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) { |
134 | phonetype = (*phoneIt).type(); | 140 | phonetype = (*phoneIt).type(); |
135 | if (ksmsAvail && | 141 | if (ksmsAvail && |
136 | ( | 142 | ( |
137 | ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || | 143 | ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) || |
138 | ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) | 144 | ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell) |
139 | ) | 145 | ) |
140 | ) | 146 | ) |
141 | { | 147 | { |
142 | sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) | 148 | sms = QString("<a href=\"smsto:%1 \">(sms)</a>" ) |
143 | .arg( (*phoneIt).number() ); | 149 | .arg( (*phoneIt).number() ); |
144 | 150 | ||
145 | } | 151 | } |
146 | else | 152 | else |
147 | sms = ""; | 153 | sms = ""; |
148 | 154 | ||
149 | extension = QString::null; | 155 | extension = QString::null; |
150 | if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { | 156 | if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) { |
151 | if (kfaxAvail) extension = "faxto:"; | 157 | if (kfaxAvail) extension = "faxto:"; |
152 | } | 158 | } |
153 | else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { | 159 | else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) { |
154 | if (kpagerAvail) extension = "pagerto:"; | 160 | if (kpagerAvail) extension = "pagerto:"; |
155 | } | 161 | } |
156 | else if (kphoneAvail) { | 162 | else if (kphoneAvail) { |
157 | extension = "phoneto:"; | 163 | extension = "phoneto:"; |
158 | } | 164 | } |
159 | else | 165 | else |
160 | extension = QString::null; | 166 | extension = QString::null; |
161 | 167 | ||
162 | if ( !extension.isEmpty() ) { | 168 | if ( !extension.isEmpty() ) { |
163 | dynamicPart += QString( | 169 | dynamicPart += QString( |
164 | "<tr><td align=\"right\"><b>%1</b></td>" | 170 | "<tr><td align=\"right\"><b>%1</b></td>" |
165 | "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) | 171 | "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" ) |
166 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) | 172 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) |
167 | .arg( extension ) | 173 | .arg( extension ) |
168 | .arg( (*phoneIt).number() ) | 174 | .arg( (*phoneIt).number() ) |
169 | .arg( (*phoneIt).number() ) | 175 | .arg( (*phoneIt).number() ) |
170 | .arg( sms ); | 176 | .arg( sms ); |
171 | 177 | ||
172 | } else { | 178 | } else { |
173 | dynamicPart += QString( | 179 | dynamicPart += QString( |
174 | "<tr><td align=\"right\"><b>%1</b></td>" | 180 | "<tr><td align=\"right\"><b>%1</b></td>" |
175 | "<td align=\"left\">%2 %3</td></tr>" ) | 181 | "<td align=\"left\">%2 %3</td></tr>" ) |
176 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) | 182 | .arg( KABC::PhoneNumber::typeLabel( phonetype ) ) |
177 | .arg( (*phoneIt).number() ) | 183 | .arg( (*phoneIt).number() ) |
178 | .arg( sms ); | 184 | .arg( sms ); |
179 | } | 185 | } |
180 | } | 186 | } |
181 | 187 | ||
182 | 188 | ||
183 | for ( ; emailIt != emails.end(); ++emailIt ) { | 189 | for ( ; emailIt != emails.end(); ++emailIt ) { |
184 | if ( kemailAvail ) { | 190 | if ( kemailAvail ) { |
185 | dynamicPart += QString( | 191 | dynamicPart += QString( |
186 | "<tr><td align=\"right\"><b>%1</b></td>" | 192 | "<tr><td align=\"right\"><b>%1</b></td>" |
187 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) | 193 | "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) |
188 | .arg( type ) | 194 | .arg( type ) |
189 | .arg( name ) | 195 | .arg( name ) |
190 | .arg( *emailIt ) | 196 | .arg( *emailIt ) |
191 | .arg( *emailIt ); | 197 | .arg( *emailIt ); |
192 | } else { | 198 | } else { |
193 | dynamicPart += QString( | 199 | dynamicPart += QString( |
194 | "<tr><td align=\"right\"><b>%1</b></td>" | 200 | "<tr><td align=\"right\"><b>%1</b></td>" |
195 | "<td align=\"left\">%2</td></tr>" ) | 201 | "<td align=\"left\">%2</td></tr>" ) |
196 | .arg( type ) | 202 | .arg( type ) |
197 | .arg( *emailIt ); | 203 | .arg( *emailIt ); |
198 | } | 204 | } |
199 | } | 205 | } |
200 | 206 | ||
201 | if ( !mAddressee.url().url().isEmpty() ) { | 207 | if ( !mAddressee.url().url().isEmpty() ) { |
202 | dynamicPart += QString( | 208 | dynamicPart += QString( |
203 | "<tr><td align=\"right\"><b>%1</b></td>" | 209 | "<tr><td align=\"right\"><b>%1</b></td>" |
204 | "<td align=\"left\">%2</td></tr>" ) | 210 | "<td align=\"left\">%2</td></tr>" ) |
205 | .arg( i18n( "Homepage" ) ) | 211 | .arg( i18n( "Homepage" ) ) |
206 | //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); | 212 | //US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); |
207 | .arg( mAddressee.url().url() ); | 213 | .arg( mAddressee.url().url() ); |
208 | //qDebug("AddresseeView::setAddressee has to be verified."); | 214 | //qDebug("AddresseeView::setAddressee has to be verified."); |
209 | } | 215 | } |
210 | 216 | ||
211 | KABC::Address::List addresses = mAddressee.addresses(); | 217 | KABC::Address::List addresses = mAddressee.addresses(); |
212 | KABC::Address::List::ConstIterator addrIt; | 218 | KABC::Address::List::ConstIterator addrIt; |
213 | for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { | 219 | for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { |
214 | if ( true /*(*addrIt).label().isEmpty()*/ ) { | 220 | if ( true /*(*addrIt).label().isEmpty()*/ ) { |
215 | QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); | 221 | QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); |
216 | //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); | 222 | //US formattedAddress = formattedAddress.replace( '\n', "<br>" ); |
217 | //qDebug("adresss %s ",formattedAddress.latin1() ); | 223 | //qDebug("adresss %s ",formattedAddress.latin1() ); |
218 | formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); | 224 | formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); |
219 | //qDebug("AddresseeView::setAddressee has to be verified."); | 225 | //qDebug("AddresseeView::setAddressee has to be verified."); |
220 | 226 | ||
221 | dynamicPart += QString( | 227 | dynamicPart += QString( |
222 | "<tr><td align=\"right\"><b>%1</b></td>" | 228 | "<tr><td align=\"right\"><b>%1</b></td>" |
223 | "<td align=\"left\">%2</td></tr>" ) | 229 | "<td align=\"left\">%2</td></tr>" ) |
224 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) | 230 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) |
225 | .arg( formattedAddress ); | 231 | .arg( formattedAddress ); |
226 | } else { | 232 | } else { |
227 | 233 | ||
228 | dynamicPart += QString( | 234 | dynamicPart += QString( |
229 | "<tr><td align=\"right\"><b>%1</b></td>" | 235 | "<tr><td align=\"right\"><b>%1</b></td>" |
230 | "<td align=\"left\">%2</td></tr>" ) | 236 | "<td align=\"left\">%2</td></tr>" ) |
231 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) | 237 | .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) |
232 | //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); | 238 | //US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); |
233 | .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); | 239 | .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); |
234 | 240 | ||
235 | } | 241 | } |
236 | } | 242 | } |
237 | 243 | ||
238 | QString notes; | 244 | QString notes; |
239 | if ( !mAddressee.note().isEmpty() ) { | 245 | if ( !mAddressee.note().isEmpty() ) { |
240 | notes = QString( | 246 | notes = QString( |
241 | "<tr>" | 247 | "<tr>" |
242 | "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label | 248 | "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label |
243 | "<td align=\"left\">%2</td>" // note | 249 | "<td align=\"left\">%2</td>" // note |
244 | "</tr>" ).arg( i18n( "Notes" ) ) | 250 | "</tr>" ).arg( i18n( "Notes" ) ) |
245 | //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); | 251 | //US .arg( mAddressee.note().replace( '\n', "<br>" ) ); |
246 | .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); | 252 | .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); |
247 | //qDebug("AddresseeView::setAddressee has to be verified."); | 253 | //qDebug("AddresseeView::setAddressee has to be verified."); |
248 | } | 254 | } |
249 | 255 | ||
250 | QString aRole = ""; | 256 | QString aRole = ""; |
251 | QString aOrga = ""; | 257 | QString aOrga = ""; |
252 | if ( true /*!mAddressee.role().isEmpty()*/ ) { | 258 | if ( true /*!mAddressee.role().isEmpty()*/ ) { |
253 | aRole = "<tr>" | 259 | aRole = "<tr>" |
254 | "<td align=\"left\">" + mAddressee.role() + "</td>" | 260 | "<td align=\"left\">" + mAddressee.role() + "</td>" |
255 | "</tr>"; | 261 | "</tr>"; |
256 | } | 262 | } |
257 | if ( true /*!mAddressee.organization().isEmpty()*/ ) { | 263 | if ( true /*!mAddressee.organization().isEmpty()*/ ) { |
258 | aOrga = "<tr>" | 264 | aOrga = "<tr>" |
259 | "<td align=\"left\">" + mAddressee.organization() + "</td>" ; | 265 | "<td align=\"left\">" + mAddressee.organization() + "</td>" ; |
260 | "</tr>"; | 266 | "</tr>"; |
261 | } | 267 | } |
262 | mText = ""; | 268 | mText = ""; |
263 | QString picString = ""; | 269 | QString picString = ""; |
264 | KABC::Picture picture = mAddressee.photo(); | 270 | KABC::Picture picture = mAddressee.photo(); |
265 | bool picAvailintern = false; | 271 | bool picAvailintern = false; |
266 | bool picAvailUrl = false; | 272 | bool picAvailUrl = false; |
267 | if (! picture.undefined() ) { | 273 | if (! picture.undefined() ) { |
268 | picAvailintern = (picture.isIntern() && !picture.data().isNull()); | 274 | picAvailintern = (picture.isIntern() && !picture.data().isNull()); |
269 | picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); | 275 | picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); |
270 | } | 276 | } |
271 | if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { | 277 | if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { |
272 | if ( picAvailintern ) { | 278 | if ( picAvailintern ) { |
273 | QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); | 279 | QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); |
274 | } else { | 280 | } else { |
275 | if ( picAvailUrl ) { | 281 | if ( picAvailUrl ) { |
276 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); | 282 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); |
277 | } else { | 283 | } else { |
278 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); | 284 | QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); |
279 | } | 285 | } |
280 | } | 286 | } |
281 | picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; | 287 | picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; |
282 | mText = QString::fromLatin1( | 288 | mText = QString::fromLatin1( |
283 | "<html>" | 289 | "<html>" |
284 | "<body text=\"%1\" bgcolor=\"%2\">" // text and background color | 290 | "<body text=\"%1\" bgcolor=\"%2\">" // text and background color |
285 | "<table>" | 291 | "<table>" |
286 | "<tr>" | 292 | "<tr>" |
287 | "<td rowspan=\"3\" align=\"right\" valign=\"top\">" | 293 | "<td rowspan=\"3\" align=\"right\" valign=\"top\">" |
288 | "%3" | 294 | "%3" |
289 | "</td>" | 295 | "</td>" |
290 | "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name | 296 | "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name |
291 | "</tr>" | 297 | "</tr>" |
292 | "%5" // role | 298 | "%5" // role |
293 | "%6" // organization | 299 | "%6" // organization |
294 | "<td colspan=\"2\"> </td>" | 300 | "<td colspan=\"2\"> </td>" |
295 | "%7" // dynamic part | 301 | "%7" // dynamic part |
296 | "%8" // notes | 302 | "%8" // notes |
297 | "</table>" | 303 | "</table>" |
298 | "</body>" | 304 | "</body>" |
299 | "</html>") | 305 | "</html>") |
300 | //US | 306 | //US |
301 | .arg( /*KGlobalSettings::textColor().name()*/ "black" ) | 307 | .arg( /*KGlobalSettings::textColor().name()*/ "black" ) |
302 | //US | 308 | //US |
303 | .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) | 309 | .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) |
304 | .arg( picString ) | 310 | .arg( picString ) |
305 | .arg( name ) | 311 | .arg( name ) |
306 | .arg( aRole ) | 312 | .arg( aRole ) |
307 | .arg( aOrga ) | 313 | .arg( aOrga ) |
308 | .arg( dynamicPart ) | 314 | .arg( dynamicPart ) |
309 | .arg( notes ); | 315 | .arg( notes ); |
310 | 316 | ||
311 | } else { // no picture! | 317 | } else { // no picture! |
312 | 318 | ||
313 | mText = "<table width=\"100%\">\n"; | 319 | mText = "<table width=\"100%\">\n"; |
314 | //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; | 320 | //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; |
315 | #ifdef DESKTOP_VERSION | 321 | #ifdef DESKTOP_VERSION |
316 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; | 322 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; |
317 | #else | 323 | #else |
318 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>"; | 324 | mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>"; |
319 | #endif | 325 | #endif |
320 | 326 | ||
321 | #ifdef DESKTOP_VERSION | 327 | #ifdef DESKTOP_VERSION |
322 | mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>"; | 328 | mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>"; |
323 | #else | 329 | #else |
324 | mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>"; | 330 | mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>"; |
325 | #endif | 331 | #endif |
326 | mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; | 332 | mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; |
327 | 333 | ||
328 | mText += "<table><td colspan=\"2\"> </td>"; | 334 | mText += "<table><td colspan=\"2\"> </td>"; |
329 | /* | 335 | /* |
330 | mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" | 336 | mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" |
331 | "<td align=\"left\"><b>%2</b></td></tr>" ) | 337 | "<td align=\"left\"><b>%2</b></td></tr>" ) |
332 | .arg( i18n(" ") ) | 338 | .arg( i18n(" ") ) |
333 | .arg( name ); | 339 | .arg( name ); |
334 | */ | 340 | */ |
335 | if ( ! mAddressee.role().isEmpty() ) | 341 | if ( ! mAddressee.role().isEmpty() ) |
336 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" | 342 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" |
337 | "<td align=\"left\">%2</td></tr>" ) | 343 | "<td align=\"left\">%2</td></tr>" ) |
338 | .arg( i18n(" ") ) | 344 | .arg( i18n(" ") ) |
339 | .arg( mAddressee.role()); | 345 | .arg( mAddressee.role()); |
340 | if ( ! mAddressee.organization().isEmpty() ) | 346 | if ( ! mAddressee.organization().isEmpty() ) |
341 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" | 347 | mText += QString("<tr><td align=\"right\"><b>%1</b></td>" |
342 | "<td align=\"left\">%2</td></tr>" ) | 348 | "<td align=\"left\">%2</td></tr>" ) |
343 | .arg( i18n(" ") ) | 349 | .arg( i18n(" ") ) |
344 | .arg( mAddressee.organization()); | 350 | .arg( mAddressee.organization()); |
345 | mText += dynamicPart; | 351 | mText += dynamicPart; |
346 | mText += notes; | 352 | mText += notes; |
347 | mText += "</table>"; | 353 | mText += "</table>"; |
348 | 354 | ||
349 | } | 355 | } |
350 | 356 | ||
351 | // at last display it... | 357 | // at last display it... |
352 | setText( mText ); | 358 | setText( mText ); |
353 | 359 | ||
354 | } | 360 | } |
355 | 361 | ||
356 | KABC::Addressee AddresseeView::addressee() const | 362 | KABC::Addressee AddresseeView::addressee() const |
357 | { | 363 | { |
358 | return mAddressee; | 364 | return mAddressee; |
359 | } | 365 | } |
360 | void AddresseeView::addTag(const QString & tag,const QString & text) | 366 | void AddresseeView::addTag(const QString & tag,const QString & text) |
361 | { | 367 | { |
362 | if ( text.isEmpty() ) | 368 | if ( text.isEmpty() ) |
363 | return; | 369 | return; |
364 | int number=text.contains("\n"); | 370 | int number=text.contains("\n"); |
365 | QString str = "<" + tag + ">"; | 371 | QString str = "<" + tag + ">"; |
366 | QString tmpText=text; | 372 | QString tmpText=text; |
367 | QString tmpStr=str; | 373 | QString tmpStr=str; |
368 | if(number !=-1) | 374 | if(number !=-1) |
369 | { | 375 | { |
370 | if (number > 0) { | 376 | if (number > 0) { |
371 | int pos=0; | 377 | int pos=0; |
372 | QString tmp; | 378 | QString tmp; |
373 | for(int i=0;i<=number;i++) { | 379 | for(int i=0;i<=number;i++) { |
374 | pos=tmpText.find("\n"); | 380 | pos=tmpText.find("\n"); |
375 | tmp=tmpText.left(pos); | 381 | tmp=tmpText.left(pos); |
376 | tmpText=tmpText.right(tmpText.length()-pos-1); | 382 | tmpText=tmpText.right(tmpText.length()-pos-1); |
377 | tmpStr+=tmp+"<br>"; | 383 | tmpStr+=tmp+"<br>"; |
378 | } | 384 | } |
379 | } | 385 | } |
380 | else tmpStr += tmpText; | 386 | else tmpStr += tmpText; |
381 | tmpStr+="</" + tag + ">"; | 387 | tmpStr+="</" + tag + ">"; |
382 | mText.append(tmpStr); | 388 | mText.append(tmpStr); |
383 | } | 389 | } |
384 | else | 390 | else |
385 | { | 391 | { |
386 | str += text + "</" + tag + ">"; | 392 | str += text + "</" + tag + ">"; |
387 | mText.append(str); | 393 | mText.append(str); |
388 | } | 394 | } |
389 | } | 395 | } |
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp index 5fb948a..c4c0081 100644 --- a/libkdepim/kdateedit.cpp +++ b/libkdepim/kdateedit.cpp | |||
@@ -1,486 +1,497 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | 3 | ||
4 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qapplication.h> | 25 | #include <qapplication.h> |
26 | #include <qevent.h> | 26 | #include <qevent.h> |
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qpixmap.h> | 28 | #include <qpixmap.h> |
29 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
30 | 30 | ||
31 | #include <kdatepicker.h> | 31 | #include <kdatepicker.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kglobal.h> | 33 | #include <kglobal.h> |
34 | #include <kiconloader.h> | 34 | #include <kiconloader.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | #include <kmessagebox.h> | 36 | #include <kmessagebox.h> |
37 | #include <knotifyclient.h> | 37 | #include <knotifyclient.h> |
38 | #include <qpalette.h> | 38 | #include <qpalette.h> |
39 | 39 | ||
40 | #include "kdateedit.h" | 40 | #include "kdateedit.h" |
41 | //#include "kdateedit.moc" | 41 | //#include "kdateedit.moc" |
42 | 42 | ||
43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) | 43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) |
44 | : QHBox(parent, name) | 44 | : QHBox(parent, name) |
45 | { | 45 | { |
46 | dateFormShort = true; | 46 | dateFormShort = true; |
47 | withoutDp = withoutDP; | 47 | withoutDp = withoutDP; |
48 | mDateEdit = new QLineEdit(this); | 48 | mDateEdit = new QLineEdit(this); |
49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); | 49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); |
50 | setFocusProxy(mDateEdit); | 50 | setFocusProxy(mDateEdit); |
51 | mDateEdit->installEventFilter(this); | 51 | mDateEdit->installEventFilter(this); |
52 | 52 | ||
53 | // Highlight Background and Textcolor | 53 | // Highlight Background and Textcolor |
54 | QPalette palette = QWidget::palette(); | 54 | QPalette palette = QWidget::palette(); |
55 | unsigned char red, green, blue; | 55 | unsigned char red, green, blue; |
56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; | 56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; |
57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; | 57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; |
58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; | 58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; |
59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); | 59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); |
60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); | 60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); |
61 | mDateEdit->setPalette( palette ); | 61 | mDateEdit->setPalette( palette ); |
62 | 62 | ||
63 | if ( withoutDP ) { | 63 | if ( withoutDP ) { |
64 | mDateFrame = 0; | 64 | mDateFrame = 0; |
65 | mDateButton = 0; | 65 | mDateButton = 0; |
66 | mDatePicker = 0; | 66 | mDatePicker = 0; |
67 | } else { | 67 | } else { |
68 | QPixmap pixmap = SmallIcon("smallcal"); | 68 | QPixmap pixmap = SmallIcon("smallcal"); |
69 | mDateButton = new QPushButton(this); | 69 | mDateButton = new QPushButton(this); |
70 | mDateButton->setPixmap(pixmap); | 70 | mDateButton->setPixmap(pixmap); |
71 | 71 | ||
72 | mDateFrame = new QVBox(0,0,WType_Popup); | 72 | mDateFrame = new QVBox(0,0,WType_Popup); |
73 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 73 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
74 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 74 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
75 | mDateFrame->setLineWidth(3); | 75 | mDateFrame->setLineWidth(3); |
76 | mDateFrame->hide(); | 76 | mDateFrame->hide(); |
77 | 77 | ||
78 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); | 78 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); |
79 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); | 79 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); |
80 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); | 80 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); |
81 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); | 81 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); |
82 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); | 82 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); |
83 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); | 83 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); |
84 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); | 84 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); |
85 | 85 | ||
86 | //mDateFrame->resize( 400, 300 ); | 86 | //mDateFrame->resize( 400, 300 ); |
87 | 87 | ||
88 | } | 88 | } |
89 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); | 89 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); |
90 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), | 90 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), |
91 | SLOT(textChanged(const QString &))); | 91 | SLOT(textChanged(const QString &))); |
92 | 92 | ||
93 | // Create the keyword list. This will be used to match against when the user | 93 | // Create the keyword list. This will be used to match against when the user |
94 | // enters information. | 94 | // enters information. |
95 | mKeywordMap[i18n("tomorrow")] = 1; | 95 | mKeywordMap[i18n("tomorrow")] = 1; |
96 | mKeywordMap[i18n("today")] = 0; | 96 | mKeywordMap[i18n("today")] = 0; |
97 | mKeywordMap[i18n("yesterday")] = -1; | 97 | mKeywordMap[i18n("yesterday")] = -1; |
98 | 98 | ||
99 | /* | 99 | /* |
100 | * This loop uses some math tricks to figure out the offset in days | 100 | * This loop uses some math tricks to figure out the offset in days |
101 | * to the next date the given day of the week occurs. There | 101 | * to the next date the given day of the week occurs. There |
102 | * are two cases, that the new day is >= the current day, which means | 102 | * are two cases, that the new day is >= the current day, which means |
103 | * the new day has not occured yet or that the new day < the current day, | 103 | * the new day has not occured yet or that the new day < the current day, |
104 | * which means the new day is already passed (so we need to find the | 104 | * which means the new day is already passed (so we need to find the |
105 | * day in the next week). | 105 | * day in the next week). |
106 | */ | 106 | */ |
107 | QString dayName; | 107 | QString dayName; |
108 | int currentDay = QDate::currentDate().dayOfWeek(); | 108 | int currentDay = QDate::currentDate().dayOfWeek(); |
109 | for (int i = 1; i <= 7; ++i) | 109 | for (int i = 1; i <= 7; ++i) |
110 | { | 110 | { |
111 | dayName = KGlobal::locale()->weekDayName(i).lower(); | 111 | dayName = KGlobal::locale()->weekDayName(i).lower(); |
112 | if (i >= currentDay) | 112 | if (i >= currentDay) |
113 | mKeywordMap[dayName] = i - currentDay; | 113 | mKeywordMap[dayName] = i - currentDay; |
114 | else | 114 | else |
115 | mKeywordMap[dayName] = 7 - currentDay + i; | 115 | mKeywordMap[dayName] = 7 - currentDay + i; |
116 | } | 116 | } |
117 | 117 | ||
118 | mTextChanged = false; | 118 | mTextChanged = false; |
119 | mHandleInvalid = false; | 119 | mHandleInvalid = false; |
120 | QWidget::setTabOrder( mDateEdit, mDateButton ); | 120 | QWidget::setTabOrder( mDateEdit, mDateButton ); |
121 | } | 121 | } |
122 | 122 | ||
123 | KDateEdit::~KDateEdit() | 123 | KDateEdit::~KDateEdit() |
124 | { | 124 | { |
125 | delete mDateFrame; | 125 | delete mDateFrame; |
126 | } | 126 | } |
127 | 127 | void KDateEdit::clear() | |
128 | { | ||
129 | bool b = mDateEdit->signalsBlocked(); | ||
130 | mDateEdit->blockSignals(true); | ||
131 | mDateEdit->setText(""); | ||
132 | mDateEdit->blockSignals(b); | ||
133 | } | ||
128 | void KDateEdit::setDate(QDate newDate) | 134 | void KDateEdit::setDate(QDate newDate) |
129 | { | 135 | { |
130 | if (!newDate.isValid() && !mHandleInvalid) | 136 | if (!newDate.isValid() && !mHandleInvalid) |
131 | return; | 137 | return; |
132 | if ( readDate() == newDate ) | 138 | if ( readDate() == newDate ) |
133 | return; | 139 | return; |
134 | QString dateString = ""; | 140 | QString dateString = ""; |
135 | if(newDate.isValid()) | 141 | if(newDate.isValid()) |
136 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); | 142 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); |
137 | 143 | ||
138 | mTextChanged = false; | 144 | mTextChanged = false; |
139 | 145 | ||
140 | // We do not want to generate a signal here, since we explicity setting | 146 | // We do not want to generate a signal here, since we explicity setting |
141 | // the date | 147 | // the date |
142 | bool b = mDateEdit->signalsBlocked(); | 148 | bool b = mDateEdit->signalsBlocked(); |
143 | mDateEdit->blockSignals(true); | 149 | mDateEdit->blockSignals(true); |
144 | mDateEdit->setText(dateString); | 150 | mDateEdit->setText(dateString); |
145 | mDateEdit->blockSignals(b); | 151 | mDateEdit->blockSignals(b); |
146 | } | 152 | } |
147 | 153 | ||
148 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) | 154 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) |
149 | { | 155 | { |
150 | QString dateForm = dateFormShort ? | 156 | QString dateForm = dateFormShort ? |
151 | KGlobal::locale()->dateFormatShort() : | 157 | KGlobal::locale()->dateFormatShort() : |
152 | KGlobal::locale()->dateFormat(); | 158 | KGlobal::locale()->dateFormat(); |
153 | 159 | ||
154 | int begin = dateForm.find("%"); | 160 | int begin = dateForm.find("%"); |
155 | int space = 0; | 161 | int space = 0; |
156 | int allStrLength = 0; | 162 | int allStrLength = 0; |
157 | int strLength = 0; | 163 | int strLength = 0; |
158 | int repeat = 0; | 164 | int repeat = 0; |
159 | 165 | ||
160 | // witch? Day, Month or Year switch? | 166 | // witch? Day, Month or Year switch? |
161 | while(1){ | 167 | while(1){ |
162 | switch ( dateForm.at(begin + 1).latin1() ) | 168 | switch ( dateForm.at(begin + 1).latin1() ) |
163 | { | 169 | { |
164 | case 'd':// 16 (month day) | 170 | case 'd':// 16 (month day) |
165 | strLength = 2; //Ok | 171 | strLength = 2; //Ok |
166 | break; | 172 | break; |
167 | case 'm':// 01 (month) | 173 | case 'm':// 01 (month) |
168 | strLength = 2; //Ok | 174 | strLength = 2; //Ok |
169 | break; | 175 | break; |
170 | case 'a':// Mon (Weekday) | 176 | case 'a':// Mon (Weekday) |
171 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); | 177 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); |
172 | break; | 178 | break; |
173 | case 'A':// Monday (Weekday) | 179 | case 'A':// Monday (Weekday) |
174 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); | 180 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); |
175 | break; | 181 | break; |
176 | case 'b':// Jan (monthName) | 182 | case 'b':// Jan (monthName) |
177 | strLength = KGlobal::locale()->monthName(date.month(), true).length(); | 183 | strLength = KGlobal::locale()->monthName(date.month(), true).length(); |
178 | break; | 184 | break; |
179 | case 'B':// January (monthName) | 185 | case 'B':// January (monthName) |
180 | strLength = KGlobal::locale()->monthName(date.month(), false).length(); | 186 | strLength = KGlobal::locale()->monthName(date.month(), false).length(); |
181 | break; | 187 | break; |
182 | case 'y':// 04 (year short) | 188 | case 'y':// 04 (year short) |
183 | strLength = 2; //Ok | 189 | strLength = 2; //Ok |
184 | break; | 190 | break; |
185 | case 'Y':// 2004 (year) | 191 | case 'Y':// 2004 (year) |
186 | strLength = 4; //Ok | 192 | strLength = 4; //Ok |
187 | break; | 193 | break; |
188 | default: | 194 | default: |
189 | break; | 195 | break; |
190 | } | 196 | } |
191 | space = begin - (repeat++ * 2); | 197 | space = begin - (repeat++ * 2); |
192 | // all select? then dayswitch | 198 | // all select? then dayswitch |
193 | if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) && | 199 | if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) && |
194 | ( (dateForm.at(begin + 1).latin1() == 'd') || | 200 | ( (dateForm.at(begin + 1).latin1() == 'd') || |
195 | (dateForm.at(begin + 1).latin1() == 'a') || | 201 | (dateForm.at(begin + 1).latin1() == 'a') || |
196 | (dateForm.at(begin + 1).latin1() == 'A') ) ) { | 202 | (dateForm.at(begin + 1).latin1() == 'A') ) ) { |
197 | break; | 203 | break; |
198 | } | 204 | } |
199 | // mDateEdit-StringPos == CursorPosition(cpos) then break and set date | 205 | // mDateEdit-StringPos == CursorPosition(cpos) then break and set date |
200 | if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) { | 206 | if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) { |
201 | break; | 207 | break; |
202 | } | 208 | } |
203 | allStrLength += strLength; | 209 | allStrLength += strLength; |
204 | begin = dateForm.find("%", begin +1); | 210 | begin = dateForm.find("%", begin +1); |
205 | } | 211 | } |
206 | 212 | ||
207 | // set date | 213 | // set date |
208 | switch ( dateForm.at(begin + 1).latin1() ) { | 214 | switch ( dateForm.at(begin + 1).latin1() ) { |
209 | case 'd': | 215 | case 'd': |
210 | case 'a': | 216 | case 'a': |
211 | case 'A': | 217 | case 'A': |
212 | if(key == Key_Up) { | 218 | if(key == Key_Up) { |
213 | setDate( date.addDays( 1 ) ); | 219 | setDate( date.addDays( 1 ) ); |
214 | } | 220 | } |
215 | else if(key == Key_Down) { | 221 | else if(key == Key_Down) { |
216 | setDate( date.addDays( -1 ) ); | 222 | setDate( date.addDays( -1 ) ); |
217 | } | 223 | } |
218 | maxDay = readDate().day(); | 224 | maxDay = readDate().day(); |
219 | break; | 225 | break; |
220 | case 'm': | 226 | case 'm': |
221 | case 'b': | 227 | case 'b': |
222 | case 'B': | 228 | case 'B': |
223 | if(key == Key_Up) { | 229 | if(key == Key_Up) { |
224 | int year = ((date.month()+1)>12)?date.year()+1:date.year(); | 230 | int year = ((date.month()+1)>12)?date.year()+1:date.year(); |
225 | int month = ((date.month()+1)>12)?1:date.month()+1; | 231 | int month = ((date.month()+1)>12)?1:date.month()+1; |
226 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; | 232 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; |
227 | setDate( QDate( year, month, day ) ); | 233 | setDate( QDate( year, month, day ) ); |
228 | } else if(key == Key_Down) { | 234 | } else if(key == Key_Down) { |
229 | int year = ((date.month()-1)<1)?date.year()-1:date.year(); | 235 | int year = ((date.month()-1)<1)?date.year()-1:date.year(); |
230 | int month = ((date.month()-1)<1)?12:date.month()-1; | 236 | int month = ((date.month()-1)<1)?12:date.month()-1; |
231 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; | 237 | int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay; |
232 | setDate( QDate( year, month, day ) ); | 238 | setDate( QDate( year, month, day ) ); |
233 | } | 239 | } |
234 | break; | 240 | break; |
235 | case 'y': | 241 | case 'y': |
236 | case 'Y': | 242 | case 'Y': |
237 | if(key == Key_Up) { | 243 | if(key == Key_Up) { |
238 | setDate( QDate( date.year() + 1, date.month() , date.day()) ); | 244 | setDate( QDate( date.year() + 1, date.month() , date.day()) ); |
239 | } | 245 | } |
240 | else if(key == Key_Down) { | 246 | else if(key == Key_Down) { |
241 | setDate( QDate( date.year() - 1, date.month() , date.day()) ); | 247 | setDate( QDate( date.year() - 1, date.month() , date.day()) ); |
242 | } | 248 | } |
243 | break; | 249 | break; |
244 | /* default: | 250 | /* default: |
245 | if(key == Key_Up) { | 251 | if(key == Key_Up) { |
246 | setDate( date.addDays( 1 ) ); | 252 | setDate( date.addDays( 1 ) ); |
247 | } else if(key == Key_Down) { | 253 | } else if(key == Key_Down) { |
248 | setDate( date.addDays( -1 ) ); | 254 | setDate( date.addDays( -1 ) ); |
249 | } | 255 | } |
250 | break;*/ | 256 | break;*/ |
251 | } | 257 | } |
252 | 258 | ||
253 | date = readDate(); | 259 | date = readDate(); |
254 | begin = dateForm.find("%"); | 260 | begin = dateForm.find("%"); |
255 | int allSelectStrLength = 0; | 261 | int allSelectStrLength = 0; |
256 | int selectStrLength = 0; | 262 | int selectStrLength = 0; |
257 | 263 | ||
258 | // set selection do new date an set cursor at end of selection | 264 | // set selection do new date an set cursor at end of selection |
259 | for(int i = 0; i < repeat; i++){ | 265 | for(int i = 0; i < repeat; i++){ |
260 | switch ( dateForm.at(begin + 1).latin1() ) | 266 | switch ( dateForm.at(begin + 1).latin1() ) |
261 | { | 267 | { |
262 | case 'd':// 16 (month day) | 268 | case 'd':// 16 (month day) |
263 | selectStrLength = 2; //Ok | 269 | selectStrLength = 2; //Ok |
264 | break; | 270 | break; |
265 | case 'm':// 01 (month) | 271 | case 'm':// 01 (month) |
266 | selectStrLength = 2; //Ok | 272 | selectStrLength = 2; //Ok |
267 | break; | 273 | break; |
268 | case 'a':// Mon (Weekday short) | 274 | case 'a':// Mon (Weekday short) |
269 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); | 275 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); |
270 | break; | 276 | break; |
271 | case 'A':// Monday (Weekday) | 277 | case 'A':// Monday (Weekday) |
272 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); | 278 | selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); |
273 | break; | 279 | break; |
274 | case 'b':// Jan (monthName short) | 280 | case 'b':// Jan (monthName short) |
275 | selectStrLength = KGlobal::locale()->monthName(date.month(), true).length(); | 281 | selectStrLength = KGlobal::locale()->monthName(date.month(), true).length(); |
276 | break; | 282 | break; |
277 | case 'B':// January (monthName) | 283 | case 'B':// January (monthName) |
278 | selectStrLength = KGlobal::locale()->monthName(date.month(), false).length(); | 284 | selectStrLength = KGlobal::locale()->monthName(date.month(), false).length(); |
279 | break; | 285 | break; |
280 | case 'y':// 04 (year short) | 286 | case 'y':// 04 (year short) |
281 | selectStrLength = 2; //Ok | 287 | selectStrLength = 2; //Ok |
282 | break; | 288 | break; |
283 | case 'Y':// 2004 (year) | 289 | case 'Y':// 2004 (year) |
284 | selectStrLength = 4; //Ok | 290 | selectStrLength = 4; //Ok |
285 | break; | 291 | break; |
286 | default: | 292 | default: |
287 | break; | 293 | break; |
288 | } | 294 | } |
289 | space = begin - (i * 2); | 295 | space = begin - (i * 2); |
290 | allSelectStrLength += selectStrLength; | 296 | allSelectStrLength += selectStrLength; |
291 | begin = dateForm.find("%", begin +1); | 297 | begin = dateForm.find("%", begin +1); |
292 | } | 298 | } |
293 | // set selection from begin of date | 299 | // set selection from begin of date |
294 | setSelect( space + allSelectStrLength - selectStrLength , selectStrLength); | 300 | setSelect( space + allSelectStrLength - selectStrLength , selectStrLength); |
295 | *cpos = space + allSelectStrLength; | 301 | *cpos = space + allSelectStrLength; |
296 | emit(dateChanged(date)); | 302 | emit(dateChanged(date)); |
297 | 303 | ||
298 | return; | 304 | return; |
299 | } | 305 | } |
300 | 306 | ||
301 | void KDateEdit::setHandleInvalid(bool handleInvalid) | 307 | void KDateEdit::setHandleInvalid(bool handleInvalid) |
302 | { | 308 | { |
303 | mHandleInvalid = handleInvalid; | 309 | mHandleInvalid = handleInvalid; |
304 | } | 310 | } |
305 | 311 | ||
306 | void KDateEdit::setEnabled(bool on) | 312 | void KDateEdit::setEnabled(bool on) |
307 | { | 313 | { |
308 | mDateEdit->setEnabled(on); | 314 | mDateEdit->setEnabled(on); |
309 | mDateButton->setEnabled(on); | 315 | mDateButton->setEnabled(on); |
310 | } | 316 | } |
311 | 317 | ||
312 | QDate KDateEdit::date() const | 318 | QDate KDateEdit::date() const |
313 | { | 319 | { |
314 | QDate date = readDate(); | 320 | QDate date = readDate(); |
315 | 321 | ||
316 | if (date.isValid() || mHandleInvalid) { | 322 | if (date.isValid() || mHandleInvalid) { |
317 | return date; | 323 | return date; |
318 | } else { | 324 | } else { |
319 | KNotifyClient::beep(); | 325 | KNotifyClient::beep(); |
320 | return QDate::currentDate(); | 326 | return QDate::currentDate(); |
321 | } | 327 | } |
322 | } | 328 | } |
323 | 329 | ||
324 | void KDateEdit::keyPressEvent(QKeyEvent *e) | 330 | void KDateEdit::keyPressEvent(QKeyEvent *e) |
325 | { | 331 | { |
326 | QDate date = readDate(); | 332 | QDate date = readDate(); |
327 | int cpos = mDateEdit->cursorPosition(); | 333 | int cpos = mDateEdit->cursorPosition(); |
328 | 334 | ||
329 | switch(e->key()) | 335 | switch(e->key()) |
330 | { | 336 | { |
331 | case Key_Escape: | 337 | case Key_Escape: |
332 | mDateEdit->deselect(); | 338 | mDateEdit->deselect(); |
333 | case Key_Tab: | 339 | case Key_Tab: |
334 | QHBox::keyPressEvent(e); | 340 | QHBox::keyPressEvent(e); |
335 | break; | 341 | break; |
336 | case Key_Up: | 342 | case Key_Up: |
337 | // when date invalid then set to currend and return | 343 | // when date invalid then set to currend and return |
338 | if(!date.isValid()) { | 344 | if(!date.isValid()) { |
339 | date = QDate::currentDate(); | 345 | date = QDate::currentDate(); |
340 | setDate(date); | 346 | setDate(date); |
341 | mDateEdit->setCursorPosition(cpos); | 347 | mDateEdit->setCursorPosition(cpos); |
342 | emit(dateChanged(date)); | 348 | emit(dateChanged(date)); |
343 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); | 349 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); |
344 | KMessageBox::information( 0, text ); | 350 | KMessageBox::information( 0, text ); |
345 | return; | 351 | return; |
346 | } | 352 | } |
347 | setDate(date, &cpos, Key_Up, dateFormShort); | 353 | setDate(date, &cpos, Key_Up, dateFormShort); |
348 | break; | 354 | break; |
349 | case Key_Down: | 355 | case Key_Down: |
350 | // when date invalid then set to current and return | 356 | // when date invalid then set to current and return |
351 | if(!date.isValid()) { | 357 | if(!date.isValid()) { |
352 | date = QDate::currentDate(); | 358 | date = QDate::currentDate(); |
353 | setDate(date); | 359 | setDate(date); |
354 | mDateEdit->setCursorPosition(cpos); | 360 | mDateEdit->setCursorPosition(cpos); |
355 | emit(dateChanged(date)); | 361 | emit(dateChanged(date)); |
356 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); | 362 | QString text = i18n( "You entered an invalid date!\n Date changed to current date." ); |
357 | KMessageBox::information( 0, text ); | 363 | KMessageBox::information( 0, text ); |
358 | return; | 364 | return; |
359 | } | 365 | } |
360 | setDate(date, &cpos, Key_Down, dateFormShort); | 366 | setDate(date, &cpos, Key_Down, dateFormShort); |
361 | break; | 367 | break; |
362 | default: | 368 | default: |
363 | QHBox::keyPressEvent(e); | 369 | QHBox::keyPressEvent(e); |
364 | break; | 370 | break; |
365 | } // switch | 371 | } // switch |
366 | mDateEdit->setCursorPosition(cpos); | 372 | mDateEdit->setCursorPosition(cpos); |
367 | } | 373 | } |
368 | 374 | ||
369 | void KDateEdit::setSelect( int from, int to ) | 375 | void KDateEdit::setSelect( int from, int to ) |
370 | { | 376 | { |
371 | // return; | 377 | // return; |
372 | mDateEdit->setSelection( from , to ); | 378 | mDateEdit->setSelection( from , to ); |
373 | } | 379 | } |
374 | 380 | ||
375 | void KDateEdit::toggleDatePicker() | 381 | void KDateEdit::toggleDatePicker() |
376 | { | 382 | { |
377 | if( mDateFrame->isVisible() ) { | 383 | if( mDateFrame->isVisible() ) { |
378 | mDateFrame->hide(); | 384 | mDateFrame->hide(); |
379 | } else { | 385 | } else { |
380 | QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight()); | 386 | QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight()); |
381 | QSize datepickersize = mDatePicker->sizeHint(); | 387 | QSize datepickersize = mDatePicker->sizeHint(); |
382 | 388 | ||
383 | if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() ); | 389 | if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() ); |
384 | 390 | ||
385 | int h = QApplication::desktop()->height(); | 391 | int h = QApplication::desktop()->height(); |
386 | 392 | ||
387 | if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() ); | 393 | if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() ); |
388 | 394 | ||
389 | mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(), | 395 | mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(), |
390 | datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth()); | 396 | datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth()); |
391 | 397 | ||
392 | QDate date = readDate(); | 398 | QDate date = readDate(); |
393 | if(date.isValid()) { | 399 | if(date.isValid()) { |
394 | mDatePicker->setDate(date); | 400 | mDatePicker->setDate(date); |
395 | } else { | 401 | } else { |
396 | mDatePicker->setDate(QDate::currentDate()); | 402 | mDatePicker->setDate(QDate::currentDate()); |
397 | } | 403 | } |
398 | mDateFrame->show(); | 404 | mDateFrame->show(); |
399 | } | 405 | } |
400 | } | 406 | } |
401 | 407 | ||
402 | 408 | ||
403 | void KDateEdit::lineEnterPressed() | 409 | void KDateEdit::lineEnterPressed() |
404 | { | 410 | { |
405 | QDate date = readDate(); | 411 | QDate date = readDate(); |
406 | 412 | ||
407 | if(date.isValid()) | 413 | if(date.isValid()) |
408 | { | 414 | { |
409 | // Update the edit. This is needed if the user has entered a | 415 | // Update the edit. This is needed if the user has entered a |
410 | // word rather than the actual date. | 416 | // word rather than the actual date. |
411 | setDate(date); | 417 | setDate(date); |
412 | emit(dateChanged(date)); | 418 | emit(dateChanged(date)); |
413 | emit returnPressed(); | 419 | emit returnPressed(); |
414 | } | 420 | } |
415 | else | 421 | else |
416 | { | 422 | { |
417 | if ( withoutDp ) { | 423 | if ( withoutDp ) { |
418 | KNotifyClient::beep(); | 424 | KNotifyClient::beep(); |
419 | } else { | 425 | } else { |
420 | if ( !mDateEdit->text().isEmpty() ) { | 426 | if ( !mDateEdit->text().isEmpty() ) { |
421 | mTextChanged = false; | 427 | mTextChanged = false; |
422 | QString text = i18n( "You entered an invalid date!\n Will use current date instead." ); | 428 | QString text = i18n( "You entered an invalid date!\n Will use current date instead." ); |
423 | if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { | 429 | if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) { |
424 | setDate( QDate::currentDate() ); | 430 | setDate( QDate::currentDate() ); |
425 | emit dateChanged( QDate::currentDate() ); | 431 | emit dateChanged( QDate::currentDate() ); |
426 | } | 432 | } |
427 | } | 433 | } |
428 | } | 434 | } |
429 | } | 435 | } |
430 | } | 436 | } |
431 | 437 | ||
432 | bool KDateEdit::inputIsValid() | 438 | bool KDateEdit::inputIsValid() |
433 | { | 439 | { |
434 | return readDate().isValid(); | 440 | return readDate().isValid(); |
435 | } | 441 | } |
436 | 442 | ||
437 | QDate KDateEdit::readDate() const | 443 | QDate KDateEdit::readDate() const |
438 | { | 444 | { |
439 | QString text = mDateEdit->text(); | 445 | QString text = mDateEdit->text(); |
440 | QDate date; | 446 | QDate date; |
441 | 447 | ||
442 | if (mKeywordMap.contains(text.lower())) | 448 | if (mKeywordMap.contains(text.lower())) |
443 | { | 449 | { |
444 | date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); | 450 | date = QDate::currentDate().addDays(mKeywordMap[text.lower()]); |
445 | } | 451 | } |
446 | else | 452 | else |
447 | { | 453 | { |
448 | date = KGlobal::locale()->readDate(text); | 454 | date = KGlobal::locale()->readDate(text); |
449 | } | 455 | } |
450 | 456 | ||
451 | return date; | 457 | return date; |
452 | } | 458 | } |
453 | 459 | ||
454 | bool KDateEdit::eventFilter(QObject *, QEvent *e) | 460 | bool KDateEdit::eventFilter(QObject *, QEvent *e) |
455 | { | 461 | { |
456 | // We only process the focus out event if the text has changed | 462 | // We only process the focus out event if the text has changed |
457 | // since we got focus | 463 | // since we got focus |
458 | if ((e->type() == QEvent::FocusOut) && mTextChanged) | 464 | if ((e->type() == QEvent::FocusOut) && mTextChanged) |
459 | { | 465 | { |
460 | lineEnterPressed(); | 466 | lineEnterPressed(); |
461 | mTextChanged = false; | 467 | mTextChanged = false; |
462 | } | 468 | } |
463 | // switch dateFormShort by double klick with mouse | 469 | // switch dateFormShort by double klick with mouse |
464 | else if (e->type() == QEvent::MouseButtonDblClick) | 470 | else if (e->type() == QEvent::MouseButtonDblClick) |
465 | { | 471 | { |
466 | dateFormShort = dateFormShort?false:true; | 472 | toggleDateFormat(); |
467 | mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); | ||
468 | } | 473 | } |
469 | else if (e->type() == QEvent::FocusIn) | 474 | else if (e->type() == QEvent::FocusIn) |
470 | { | 475 | { |
471 | maxDay = readDate().day(); | 476 | maxDay = readDate().day(); |
472 | } | 477 | } |
473 | 478 | ||
474 | return false; | 479 | return false; |
475 | } | 480 | } |
481 | void KDateEdit::toggleDateFormat() | ||
482 | { | ||
483 | dateFormShort = ! dateFormShort; | ||
484 | mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort)); | ||
485 | |||
486 | } | ||
476 | 487 | ||
477 | void KDateEdit::textChanged(const QString &) | 488 | void KDateEdit::textChanged(const QString &) |
478 | { | 489 | { |
479 | if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) { | 490 | if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) { |
480 | QDate date; //invalid date | 491 | QDate date; //invalid date |
481 | emit(dateChanged(date)); | 492 | emit(dateChanged(date)); |
482 | } else { | 493 | } else { |
483 | mTextChanged = true; | 494 | mTextChanged = true; |
484 | } | 495 | } |
485 | maxDay = readDate().day(); | 496 | maxDay = readDate().day(); |
486 | } | 497 | } |
diff --git a/libkdepim/kdateedit.h b/libkdepim/kdateedit.h index 742d843..cf3b90a 100644 --- a/libkdepim/kdateedit.h +++ b/libkdepim/kdateedit.h | |||
@@ -1,140 +1,141 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | 3 | ||
4 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or | 8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | 9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, | 11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. | 14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License | 16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | 17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | 19 | ||
20 | As a special exception, permission is given to link this program | 20 | As a special exception, permission is given to link this program |
21 | with any edition of Qt, and distribute the resulting executable, | 21 | with any edition of Qt, and distribute the resulting executable, |
22 | without including the source code for Qt in the source distribution. | 22 | without including the source code for Qt in the source distribution. |
23 | */ | 23 | */ |
24 | #ifndef KDATEEDIT_H | 24 | #ifndef KDATEEDIT_H |
25 | #define KDATEEDIT_H | 25 | #define KDATEEDIT_H |
26 | 26 | ||
27 | #include <qhbox.h> | 27 | #include <qhbox.h> |
28 | #include <qvbox.h> | 28 | #include <qvbox.h> |
29 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
30 | #include <qmap.h> | 30 | #include <qmap.h> |
31 | 31 | ||
32 | class QLineEdit; | 32 | class QLineEdit; |
33 | class QPushButton; | 33 | class QPushButton; |
34 | class QObject; | 34 | class QObject; |
35 | class QEvent; | 35 | class QEvent; |
36 | class KDatePicker; | 36 | class KDatePicker; |
37 | class KDateValidator; | 37 | class KDateValidator; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * A date editing widget that consists of a line edit followed by | 40 | * A date editing widget that consists of a line edit followed by |
41 | * a small push button. The line edit contains the date in text form, | 41 | * a small push button. The line edit contains the date in text form, |
42 | * and the push button will display a 'popup' style date picker. | 42 | * and the push button will display a 'popup' style date picker. |
43 | * | 43 | * |
44 | * This widget also supports advanced features like allowing the user | 44 | * This widget also supports advanced features like allowing the user |
45 | * to type in the day name to get the date. The following keywords | 45 | * to type in the day name to get the date. The following keywords |
46 | * are supported (in the native language): tomorrow, yesturday, today, | 46 | * are supported (in the native language): tomorrow, yesturday, today, |
47 | * monday, tuesday, wednesday, thursday, friday, saturday, sunday. | 47 | * monday, tuesday, wednesday, thursday, friday, saturday, sunday. |
48 | * | 48 | * |
49 | * @author Cornelius Schumacher <schumacher@kde.org> | 49 | * @author Cornelius Schumacher <schumacher@kde.org> |
50 | * @author Mike Pilone <mpilone@slac.com> | 50 | * @author Mike Pilone <mpilone@slac.com> |
51 | */ | 51 | */ |
52 | class KDateEdit : public QHBox | 52 | class KDateEdit : public QHBox |
53 | { | 53 | { |
54 | Q_OBJECT | 54 | Q_OBJECT |
55 | public: | 55 | public: |
56 | KDateEdit(QWidget *parent=0, const char *name=0, bool withoutDP = false ); | 56 | KDateEdit(QWidget *parent=0, const char *name=0, bool withoutDP = false ); |
57 | virtual ~KDateEdit(); | 57 | virtual ~KDateEdit(); |
58 | 58 | ||
59 | /** @return True if the date in the text edit is valid, | 59 | /** @return True if the date in the text edit is valid, |
60 | * false otherwise. This will not modify the display of the date, | 60 | * false otherwise. This will not modify the display of the date, |
61 | * but only check for validity. | 61 | * but only check for validity. |
62 | */ | 62 | */ |
63 | bool inputIsValid(); | 63 | bool inputIsValid(); |
64 | 64 | ||
65 | /** @return The date entered. This will not | 65 | /** @return The date entered. This will not |
66 | * modify the display of the date, but only return it. | 66 | * modify the display of the date, but only return it. |
67 | */ | 67 | */ |
68 | QDate date() const; | 68 | QDate date() const; |
69 | 69 | ||
70 | /** @param handleInvalid If true the date edit accepts invalid dates | 70 | /** @param handleInvalid If true the date edit accepts invalid dates |
71 | * and displays them as the empty ("") string. It also returns an invalid date. | 71 | * and displays them as the empty ("") string. It also returns an invalid date. |
72 | * If false (default) invalid dates are not accepted and instead the date | 72 | * If false (default) invalid dates are not accepted and instead the date |
73 | * of today will be returned. | 73 | * of today will be returned. |
74 | */ | 74 | */ |
75 | void setHandleInvalid(bool handleInvalid); | 75 | void setHandleInvalid(bool handleInvalid); |
76 | 76 | ||
77 | /** Checks for a focus out event. The display of the date is updated | 77 | /** Checks for a focus out event. The display of the date is updated |
78 | * to display the proper date when the focus leaves. | 78 | * to display the proper date when the focus leaves. |
79 | */ | 79 | */ |
80 | virtual bool eventFilter(QObject *o, QEvent *e); | 80 | virtual bool eventFilter(QObject *o, QEvent *e); |
81 | 81 | void toggleDateFormat(); | |
82 | void clear(); | ||
82 | signals: | 83 | signals: |
83 | /** This signal is emitted whenever the user modifies the date. This | 84 | /** This signal is emitted whenever the user modifies the date. This |
84 | * may not get emitted until the user presses enter in the line edit or | 85 | * may not get emitted until the user presses enter in the line edit or |
85 | * focus leaves the widget (ie: the user confirms their selection). | 86 | * focus leaves the widget (ie: the user confirms their selection). |
86 | */ | 87 | */ |
87 | void dateChanged(QDate); | 88 | void dateChanged(QDate); |
88 | void returnPressed(); | 89 | void returnPressed(); |
89 | public slots: | 90 | public slots: |
90 | /** Sets the date. | 91 | /** Sets the date. |
91 | * | 92 | * |
92 | * @param date The new date to display. This date must be valid or | 93 | * @param date The new date to display. This date must be valid or |
93 | * it will not be displayed. | 94 | * it will not be displayed. |
94 | */ | 95 | */ |
95 | void setDate(QDate date); | 96 | void setDate(QDate date); |
96 | // set Date with key_up key_down to relation of cursor Position | 97 | // set Date with key_up key_down to relation of cursor Position |
97 | // and set selection from begin to end of single date | 98 | // and set selection from begin to end of single date |
98 | void setDate(QDate, int *cpos, const int, const bool); | 99 | void setDate(QDate, int *cpos, const int, const bool); |
99 | 100 | ||
100 | /** Sets the date edit to be enabled or disabled (grayed out) | 101 | /** Sets the date edit to be enabled or disabled (grayed out) |
101 | * | 102 | * |
102 | * @param on Enabled if true, disabled if false | 103 | * @param on Enabled if true, disabled if false |
103 | */ | 104 | */ |
104 | void setEnabled(bool on); | 105 | void setEnabled(bool on); |
105 | 106 | ||
106 | protected slots: | 107 | protected slots: |
107 | void toggleDatePicker(); | 108 | void toggleDatePicker(); |
108 | void lineEnterPressed(); | 109 | void lineEnterPressed(); |
109 | void textChanged(const QString &); | 110 | void textChanged(const QString &); |
110 | 111 | ||
111 | private: | 112 | private: |
112 | /** Reads the text from the line edit. If the text is a keyword, the | 113 | /** Reads the text from the line edit. If the text is a keyword, the |
113 | * word will be translated to a date. If the text is not a keyword, the | 114 | * word will be translated to a date. If the text is not a keyword, the |
114 | * text will be interpreted as a date. | 115 | * text will be interpreted as a date. |
115 | */ | 116 | */ |
116 | QDate readDate() const; | 117 | QDate readDate() const; |
117 | 118 | ||
118 | /** Maps the text that the user can enter to the offset in days from | 119 | /** Maps the text that the user can enter to the offset in days from |
119 | * today. For example, the text 'tomorrow' is mapped to +1. | 120 | * today. For example, the text 'tomorrow' is mapped to +1. |
120 | */ | 121 | */ |
121 | QMap<QString, int> mKeywordMap; | 122 | QMap<QString, int> mKeywordMap; |
122 | bool mTextChanged; | 123 | bool mTextChanged; |
123 | bool mHandleInvalid; | 124 | bool mHandleInvalid; |
124 | 125 | ||
125 | QPushButton *mDateButton; | 126 | QPushButton *mDateButton; |
126 | QLineEdit *mDateEdit; | 127 | QLineEdit *mDateEdit; |
127 | KDatePicker *mDatePicker; | 128 | KDatePicker *mDatePicker; |
128 | QVBox *mDateFrame; | 129 | QVBox *mDateFrame; |
129 | int maxDay; | 130 | int maxDay; |
130 | bool withoutDp; | 131 | bool withoutDp; |
131 | 132 | ||
132 | protected: | 133 | protected: |
133 | virtual void keyPressEvent(QKeyEvent *qke); | 134 | virtual void keyPressEvent(QKeyEvent *qke); |
134 | void setSelect ( int, int ); | 135 | void setSelect ( int, int ); |
135 | bool dateFormShort; | 136 | bool dateFormShort; |
136 | char lengthMonthName; | 137 | char lengthMonthName; |
137 | 138 | ||
138 | }; | 139 | }; |
139 | 140 | ||
140 | #endif | 141 | #endif |