summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-02-07 21:06:04 (UTC)
committer zautrix <zautrix>2005-02-07 21:06:04 (UTC)
commitedaad9a9d7ede1b4bc50b9e758eaf32a5fbb547e (patch) (unidiff)
tree7653e521f003a0c4e316530d38c09f3190c4edaf
parentda5e47069d88fa9aa656423ce4c60bf505728e1c (diff)
downloadkdepimpi-edaad9a9d7ede1b4bc50b9e758eaf32a5fbb547e.zip
kdepimpi-edaad9a9d7ede1b4bc50b9e758eaf32a5fbb547e.tar.gz
kdepimpi-edaad9a9d7ede1b4bc50b9e758eaf32a5fbb547e.tar.bz2
recurrence fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeventviewer.cpp23
-rw-r--r--libkcal/kincidenceformatter.cpp24
-rw-r--r--libkcal/recurrence.cpp2
-rw-r--r--microkde/kdeui/ktoolbar.cpp2
-rw-r--r--microkde/kdeui/ktoolbar.h2
5 files changed, 32 insertions, 21 deletions
diff --git a/korganizer/koeventviewer.cpp b/korganizer/koeventviewer.cpp
index de11c13..39921a0 100644
--- a/korganizer/koeventviewer.cpp
+++ b/korganizer/koeventviewer.cpp
@@ -1,660 +1,663 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qcstring.h> 20#include <qcstring.h>
21#include <qwhatsthis.h> 21#include <qwhatsthis.h>
22#include <qdialog.h> 22#include <qdialog.h>
23#include <qapplication.h> 23#include <qapplication.h>
24#include <qlabel.h> 24#include <qlabel.h>
25#include <qlayout.h> 25#include <qlayout.h>
26 26
27#include <klocale.h> 27#include <klocale.h>
28#include <kapplication.h> 28#include <kapplication.h>
29#include <libkcal/event.h> 29#include <libkcal/event.h>
30#include <libkcal/todo.h> 30#include <libkcal/todo.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kiconloader.h> 32#include <kiconloader.h>
33#include <krun.h> 33#include <krun.h>
34#include <kglobal.h> 34#include <kglobal.h>
35#include <kprocess.h> 35#include <kprocess.h>
36#include "koprefs.h" 36#include "koprefs.h"
37 37
38#include <kabc/stdaddressbook.h> 38#include <kabc/stdaddressbook.h>
39 39
40#ifndef KORG_NODCOP 40#ifndef KORG_NODCOP
41#include <dcopclient.h> 41#include <dcopclient.h>
42#include "korganizer.h" 42#include "korganizer.h"
43#include "koprefs.h" 43#include "koprefs.h"
44#include "actionmanager.h" 44#include "actionmanager.h"
45#endif 45#endif
46 46
47#include "koeventviewer.h" 47#include "koeventviewer.h"
48//#ifndef KORG_NOKABC 48//#ifndef KORG_NOKABC
49//#include <kabc/stdaddressbook.h> 49//#include <kabc/stdaddressbook.h>
50//#define size count 50//#define size count
51//#endif 51//#endif
52 52
53#ifdef DESKTOP_VERSION 53#ifdef DESKTOP_VERSION
54#include <kabc/addresseedialog.h> 54#include <kabc/addresseedialog.h>
55#include <kabc/addresseeview.h> 55#include <kabc/addresseeview.h>
56#else //DESKTOP_VERSION 56#else //DESKTOP_VERSION
57#include <externalapphandler.h> 57#include <externalapphandler.h>
58#include <qtopia/qcopenvelope_qws.h> 58#include <qtopia/qcopenvelope_qws.h>
59#endif //DESKTOP_VERSION 59#endif //DESKTOP_VERSION
60 60
61KOEventViewer::KOEventViewer(QWidget *parent,const char *name) 61KOEventViewer::KOEventViewer(QWidget *parent,const char *name)
62 : QTextBrowser(parent,name) 62 : QTextBrowser(parent,name)
63{ 63{
64 mSyncMode = false; 64 mSyncMode = false;
65 mColorMode = 0; 65 mColorMode = 0;
66} 66}
67 67
68KOEventViewer::~KOEventViewer() 68KOEventViewer::~KOEventViewer()
69{ 69{
70} 70}
71 71
72void KOEventViewer::setSource(const QString& n) 72void KOEventViewer::setSource(const QString& n)
73{ 73{
74 74
75 if ( n.left(3) == "uid" ) 75 if ( n.left(3) == "uid" )
76#ifdef DESKTOP_VERSION 76#ifdef DESKTOP_VERSION
77 { 77 {
78 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 78 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
79 KABC::AddressBook::Iterator it; 79 KABC::AddressBook::Iterator it;
80 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 80 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
81 // LR I do not understand, why the uid string is different on zaurus and desktop 81 // LR I do not understand, why the uid string is different on zaurus and desktop
82 QString uid = "uid://"+(*it).uid(); 82 QString uid = "uid://"+(*it).uid();
83 83
84 //qDebug("for *%s* +%s+ ", n.latin1(), uid.latin1()); 84 //qDebug("for *%s* +%s+ ", n.latin1(), uid.latin1());
85 if (n == uid ) { 85 if (n == uid ) {
86 //qDebug("found %s ",(*it).mobileHomePhone().latin1() ); 86 //qDebug("found %s ",(*it).mobileHomePhone().latin1() );
87 QDialog dia( this,"dia123", true ); 87 QDialog dia( this,"dia123", true );
88 dia.setCaption( i18n("Details of attendee") ); 88 dia.setCaption( i18n("Details of attendee") );
89 QVBoxLayout lay ( &dia ); 89 QVBoxLayout lay ( &dia );
90 KABC::AddresseeView av ( &dia ); 90 KABC::AddresseeView av ( &dia );
91 av.setAddressee( (*it) ); 91 av.setAddressee( (*it) );
92 lay.addWidget( &av ); 92 lay.addWidget( &av );
93 if ( QApplication::desktop()->width() < 480 ) 93 if ( QApplication::desktop()->width() < 480 )
94 dia.resize( 220, 240); 94 dia.resize( 220, 240);
95 else { 95 else {
96 dia.resize( 400,400); 96 dia.resize( 400,400);
97 } 97 }
98 dia.exec(); 98 dia.exec();
99 break; 99 break;
100 } 100 }
101 } 101 }
102 return; 102 return;
103 } 103 }
104#else 104#else
105 { 105 {
106 if ( "uid:organizer" == n ) { 106 if ( "uid:organizer" == n ) {
107 ExternalAppHandler::instance()->requestDetailsFromKAPI("", mCurrentIncidence->organizer(),""); 107 ExternalAppHandler::instance()->requestDetailsFromKAPI("", mCurrentIncidence->organizer(),"");
108 return; 108 return;
109 } 109 }
110 QPtrList<Attendee> attendees = mCurrentIncidence->attendees(); 110 QPtrList<Attendee> attendees = mCurrentIncidence->attendees();
111 if (attendees.count()) { 111 if (attendees.count()) {
112 Attendee *a; 112 Attendee *a;
113 for(a=attendees.first();a;a=attendees.next()) { 113 for(a=attendees.first();a;a=attendees.next()) {
114 if ( "uid:"+a->uid() == n ) { 114 if ( "uid:"+a->uid() == n ) {
115 bool res = ExternalAppHandler::instance()->requestDetailsFromKAPI(a->name(), a->email(), a->uid()); 115 bool res = ExternalAppHandler::instance()->requestDetailsFromKAPI(a->name(), a->email(), a->uid());
116 return; 116 return;
117 } 117 }
118 } 118 }
119 } 119 }
120 return; 120 return;
121 } 121 }
122 //requestNameEmailUidListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 122 //requestNameEmailUidListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
123 // the result should now arrive through method insertAttendees 123 // the result should now arrive through method insertAttendees
124 //QString uid = "uid:"+(*it).uid(); 124 //QString uid = "uid:"+(*it).uid();
125#endif 125#endif
126 if ( n.left(6) == "mailto" ) { 126 if ( n.left(6) == "mailto" ) {
127 // qDebug("KOEventViewer::setSource %s ", n.mid(7).latin1()); 127 // qDebug("KOEventViewer::setSource %s ", n.mid(7).latin1());
128#ifndef DESKTOP_VERSION 128#ifndef DESKTOP_VERSION
129 if ( n.mid(7,3) == "ALL" ) { 129 if ( n.mid(7,3) == "ALL" ) {
130 qDebug("all "); 130 qDebug("all ");
131 mailToAttendees( true ); 131 mailToAttendees( true );
132 } else if ( n.mid(7,4) == "RSVP" ) { 132 } else if ( n.mid(7,4) == "RSVP" ) {
133 mailToAttendees( false ); 133 mailToAttendees( false );
134 qDebug("rsvp "); 134 qDebug("rsvp ");
135 } else { 135 } else {
136 QCopEnvelope e("QPE/Application/ompi", "newMail(QString)" ); 136 QCopEnvelope e("QPE/Application/ompi", "newMail(QString)" );
137 e << n.mid(7); 137 e << n.mid(7);
138 } 138 }
139#endif 139#endif
140 140
141 } 141 }
142 142
143 143
144#ifndef KORG_NODCOP 144#ifndef KORG_NODCOP
145 kdDebug() << "KOEventViewer::setSource(): " << n << endl; 145 kdDebug() << "KOEventViewer::setSource(): " << n << endl;
146 QString tmpStr; 146 QString tmpStr;
147 if (n.startsWith("mailto:")) { 147 if (n.startsWith("mailto:")) {
148 KApplication::kApplication()->invokeMailer(n.mid(7),QString::null); 148 KApplication::kApplication()->invokeMailer(n.mid(7),QString::null);
149 //emit showIncidence(n); 149 //emit showIncidence(n);
150 return; 150 return;
151 } else if (n.startsWith("uid:")) { 151 } else if (n.startsWith("uid:")) {
152 DCOPClient *client = KApplication::kApplication()->dcopClient(); 152 DCOPClient *client = KApplication::kApplication()->dcopClient();
153 const QByteArray noParamData; 153 const QByteArray noParamData;
154 const QByteArray paramData; 154 const QByteArray paramData;
155 QByteArray replyData; 155 QByteArray replyData;
156 QCString replyTypeStr; 156 QCString replyTypeStr;
157#define PING_ABBROWSER (client->call("kaddressbook", "KAddressBookIface", "interfaces()", noParamData, replyTypeStr, replyData)) 157#define PING_ABBROWSER (client->call("kaddressbook", "KAddressBookIface", "interfaces()", noParamData, replyTypeStr, replyData))
158 bool foundAbbrowser = PING_ABBROWSER; 158 bool foundAbbrowser = PING_ABBROWSER;
159 159
160 if (foundAbbrowser) { 160 if (foundAbbrowser) {
161 //KAddressbook is already running, so just DCOP to it to bring up the contact editor 161 //KAddressbook is already running, so just DCOP to it to bring up the contact editor
162 //client->send("kaddressbook","KAddressBookIface", 162 //client->send("kaddressbook","KAddressBookIface",
163 QDataStream arg(paramData, IO_WriteOnly); 163 QDataStream arg(paramData, IO_WriteOnly);
164 arg << n.mid(6); 164 arg << n.mid(6);
165 client->send("kaddressbook", "KAddressBookIface", "showContactEditor( QString )", paramData); 165 client->send("kaddressbook", "KAddressBookIface", "showContactEditor( QString )", paramData);
166 return; 166 return;
167 } else { 167 } else {
168 /* 168 /*
169 KaddressBook is not already running. Pass it the UID of the contact via the command line while starting it - its neater. 169 KaddressBook is not already running. Pass it the UID of the contact via the command line while starting it - its neater.
170 We start it without its main interface 170 We start it without its main interface
171 */ 171 */
172 KIconLoader* iconLoader = new KIconLoader(); 172 KIconLoader* iconLoader = new KIconLoader();
173 QString iconPath = iconLoader->iconPath("go",KIcon::Small); 173 QString iconPath = iconLoader->iconPath("go",KIcon::Small);
174 ActionManager::setStartedKAddressBook(true); 174 ActionManager::setStartedKAddressBook(true);
175 tmpStr = "kaddressbook --editor-only --uid "; 175 tmpStr = "kaddressbook --editor-only --uid ";
176 tmpStr += KProcess::quote(n.mid(6)); 176 tmpStr += KProcess::quote(n.mid(6));
177 KRun::runCommand(tmpStr,"KAddressBook",iconPath); 177 KRun::runCommand(tmpStr,"KAddressBook",iconPath);
178 return; 178 return;
179 } 179 }
180 } else { 180 } else {
181 //QTextBrowser::setSource(n); 181 //QTextBrowser::setSource(n);
182 } 182 }
183#endif 183#endif
184} 184}
185void KOEventViewer::mailToAttendees( bool all ) 185void KOEventViewer::mailToAttendees( bool all )
186{ 186{
187 QPtrList<Attendee> attendees = mCurrentIncidence->attendees(); 187 QPtrList<Attendee> attendees = mCurrentIncidence->attendees();
188 if (attendees.count() == 0) return; 188 if (attendees.count() == 0) return;
189 QStringList nameList; 189 QStringList nameList;
190 QStringList emailList; 190 QStringList emailList;
191 QStringList uidList; 191 QStringList uidList;
192 Attendee* a; 192 Attendee* a;
193 for(a=attendees.first();a;a=attendees.next()) { 193 for(a=attendees.first();a;a=attendees.next()) {
194 if ( !all && !a->RSVP() ) continue; 194 if ( !all && !a->RSVP() ) continue;
195 if (!a->email().isEmpty()) { 195 if (!a->email().isEmpty()) {
196 nameList.append (a->name() ); 196 nameList.append (a->name() );
197 emailList.append (a->email() ); 197 emailList.append (a->email() );
198 uidList.append (a->uid() ); 198 uidList.append (a->uid() );
199 } 199 }
200 } 200 }
201 QString uid = "ComposeMailUIpick2"+mMailSubject; 201 QString uid = "ComposeMailUIpick2"+mMailSubject;
202#ifndef DESKTOP_VERSION 202#ifndef DESKTOP_VERSION
203 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); 203 bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
204#endif 204#endif
205 205
206} 206}
207void KOEventViewer::addTag(const QString & tag,const QString & text) 207void KOEventViewer::addTag(const QString & tag,const QString & text)
208{ 208{
209 int number=text.contains("\n"); 209 int number=text.contains("\n");
210 QString str = "<" + tag + ">"; 210 QString str = "<" + tag + ">";
211 QString tmpText=text; 211 QString tmpText=text;
212 QString tmpStr=str; 212 QString tmpStr=str;
213 if(number !=-1) 213 if(number !=-1)
214 { 214 {
215 if (number > 0) { 215 if (number > 0) {
216 int pos=0; 216 int pos=0;
217 QString tmp; 217 QString tmp;
218 for(int i=0;i<=number;i++) { 218 for(int i=0;i<=number;i++) {
219 pos=tmpText.find("\n"); 219 pos=tmpText.find("\n");
220 tmp=tmpText.left(pos); 220 tmp=tmpText.left(pos);
221 tmpText=tmpText.right(tmpText.length()-pos-1); 221 tmpText=tmpText.right(tmpText.length()-pos-1);
222 tmpStr+=tmp+"<br>"; 222 tmpStr+=tmp+"<br>";
223 } 223 }
224 } 224 }
225 else tmpStr += tmpText; 225 else tmpStr += tmpText;
226 tmpStr+="</" + tag + ">"; 226 tmpStr+="</" + tag + ">";
227 mText.append(tmpStr); 227 mText.append(tmpStr);
228 } 228 }
229 else 229 else
230 { 230 {
231 str += text + "</" + tag + ">"; 231 str += text + "</" + tag + ">";
232 mText.append(str); 232 mText.append(str);
233 } 233 }
234} 234}
235 235
236void KOEventViewer::setColorMode( int m ) 236void KOEventViewer::setColorMode( int m )
237{ 237{
238 mColorMode = m; 238 mColorMode = m;
239} 239}
240void KOEventViewer::appendEvent(Event *event, int mode ) 240void KOEventViewer::appendEvent(Event *event, int mode )
241{ 241{
242 mMailSubject = ""; 242 mMailSubject = "";
243 mCurrentIncidence = event; 243 mCurrentIncidence = event;
244 bool shortDate = KOPrefs::instance()->mShortDateInViewer; 244 bool shortDate = KOPrefs::instance()->mShortDateInViewer;
245 topLevelWidget()->setCaption(i18n("Event Viewer")); 245 topLevelWidget()->setCaption(i18n("Event Viewer"));
246 if ( mode == 0 ) { 246 if ( mode == 0 ) {
247 addTag("h2",event->summary()); 247 addTag("h2",event->summary());
248 } 248 }
249 else { 249 else {
250 if ( mColorMode == 1 ) { 250 if ( mColorMode == 1 ) {
251 mText +="<font color=\"#00A000\">"; 251 mText +="<font color=\"#00A000\">";
252 } 252 }
253 if ( mColorMode == 2 ) { 253 if ( mColorMode == 2 ) {
254 mText +="<font color=\"#C00000\">"; 254 mText +="<font color=\"#C00000\">";
255 } 255 }
256 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; 256 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
257 if ( mode == 1 ) { 257 if ( mode == 1 ) {
258 addTag("h2",i18n( "Local: " ) +event->summary()); 258 addTag("h2",i18n( "Local: " ) +event->summary());
259 } else { 259 } else {
260 addTag("h2",i18n( "Remote: " ) +event->summary()); 260 addTag("h2",i18n( "Remote: " ) +event->summary());
261 } 261 }
262 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 262 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
263 if ( mColorMode ) 263 if ( mColorMode )
264 mText += "</font>"; 264 mText += "</font>";
265 } 265 }
266 mMailSubject += i18n( "Meeting " )+ event->summary(); 266 mMailSubject += i18n( "Meeting " )+ event->summary();
267 if (event->cancelled ()) { 267 if (event->cancelled ()) {
268 mText +="<font color=\"#B00000\">"; 268 mText +="<font color=\"#B00000\">";
269 addTag("i",i18n("This event has been cancelled!")); 269 addTag("i",i18n("This event has been cancelled!"));
270 mText.append("<br>"); 270 mText.append("<br>");
271 mText += "</font>"; 271 mText += "</font>";
272 mMailSubject += i18n("(cancelled)"); 272 mMailSubject += i18n("(cancelled)");
273 } 273 }
274 if (!event->location().isEmpty()) { 274 if (!event->location().isEmpty()) {
275 addTag("b",i18n("Location: ")); 275 addTag("b",i18n("Location: "));
276 mText.append(event->location()+"<br>"); 276 mText.append(event->location()+"<br>");
277 mMailSubject += i18n(" at ") + event->location(); 277 mMailSubject += i18n(" at ") + event->location();
278 } 278 }
279 if (event->doesFloat()) { 279 if (event->doesFloat()) {
280 if (event->isMultiDay()) { 280 if (event->isMultiDay()) {
281 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") 281 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>")
282 .arg(event->dtStartDateStr(shortDate)) 282 .arg(event->dtStartDateStr(shortDate))
283 .arg(event->dtEndDateStr(shortDate))); 283 .arg(event->dtEndDateStr(shortDate)));
284 } else { 284 } else {
285 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); 285 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate )));
286 } 286 }
287 } else { 287 } else {
288 if (event->isMultiDay()) { 288 if (event->isMultiDay()) {
289 mText.append(i18n("<p><b>From:</b> %1</p> ") 289 mText.append(i18n("<p><b>From:</b> %1</p> ")
290 .arg(event->dtStartStr( shortDate))); 290 .arg(event->dtStartStr( shortDate)));
291 mText.append(i18n("<p><b>To:</b> %1</p>") 291 mText.append(i18n("<p><b>To:</b> %1</p>")
292 .arg(event->dtEndStr(shortDate))); 292 .arg(event->dtEndStr(shortDate)));
293 } else { 293 } else {
294 mText.append(i18n("<p><b>On:</b> %1</p> ") 294 mText.append(i18n("<p><b>On:</b> %1</p> ")
295 .arg(event->dtStartDateStr( shortDate ))); 295 .arg(event->dtStartDateStr( shortDate )));
296 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") 296 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>")
297 .arg(event->dtStartTimeStr()) 297 .arg(event->dtStartTimeStr())
298 .arg(event->dtEndTimeStr())); 298 .arg(event->dtEndTimeStr()));
299 } 299 }
300 } 300 }
301 301
302 if (event->recurrence()->doesRecur()) { 302 if (event->recurrence()->doesRecur()) {
303 303
304 QString recurText = event->recurrence()->recurrenceText(); 304 QString recurText = event->recurrence()->recurrenceText();
305 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); 305 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>");
306 bool last; 306 bool ok;
307 QDate start = QDate::currentDate(); 307 QDate start = QDate::currentDate();
308 QDate next; 308 QDateTime next;
309 next = event->recurrence()->getPreviousDate( start , &last ); 309 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok );
310 if ( !last ) { 310 if ( ok ) {
311 next = event->recurrence()->getNextDate( start.addDays( - 1 ) );
312 addTag("p",i18n("<b>Next recurrence is on:</b>") ); 311 addTag("p",i18n("<b>Next recurrence is on:</b>") );
313 addTag("p", KGlobal::locale()->formatDate( next, shortDate )); 312 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate ));
314 QDateTime nextdt = QDateTime( next, event->dtStart().time()); 313 mMailSubject += i18n(" - " )+ KGlobal::locale()->formatDateTime( next, true );
315 mMailSubject += i18n(" - " )+ KGlobal::locale()->formatDateTime( nextdt, true );
316 314
317 } else { 315 } else {
318 addTag("p",i18n("<b>Last recurrence was on:</b>") ); 316 bool last;
319 addTag("p", KGlobal::locale()->formatDate( next, shortDate )); 317 QDate nextd;
318 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last );
319 if ( last ) {
320 addTag("p",i18n("<b>Last recurrence was on:</b>") );
321 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate ));
322 }
320 } 323 }
321 } else { 324 } else {
322 mMailSubject += i18n(" - " )+event->dtStartStr( true ); 325 mMailSubject += i18n(" - " )+event->dtStartStr( true );
323 326
324 } 327 }
325 328
326 329
327 if (event->isAlarmEnabled()) { 330 if (event->isAlarmEnabled()) {
328 Alarm *alarm =event->alarms().first() ; 331 Alarm *alarm =event->alarms().first() ;
329 QDateTime t = alarm->time(); 332 QDateTime t = alarm->time();
330 int min = t.secsTo( event->dtStart() )/60; 333 int min = t.secsTo( event->dtStart() )/60;
331 QString s =i18n("( %1 min before )").arg( min ); 334 QString s =i18n("( %1 min before )").arg( min );
332 addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); 335 addTag("p",i18n("<b>Alarm on: ") + s +" </b>");
333 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 336 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
334 //addTag("p",s); 337 //addTag("p",s);
335 } 338 }
336 339
337 addTag("b",i18n("Access: ")); 340 addTag("b",i18n("Access: "));
338 mText.append(event->secrecyStr()+"<br>"); 341 mText.append(event->secrecyStr()+"<br>");
339 if (!event->description().isEmpty()) { 342 if (!event->description().isEmpty()) {
340 addTag("p",i18n("<b>Details: </b>")); 343 addTag("p",i18n("<b>Details: </b>"));
341 addTag("p",event->description()); 344 addTag("p",event->description());
342 } 345 }
343 346
344 formatCategories(event); 347 formatCategories(event);
345 348
346 formatReadOnly(event); 349 formatReadOnly(event);
347 formatAttendees(event); 350 formatAttendees(event);
348 351
349 setText(mText); 352 setText(mText);
350 //QWhatsThis::add(this,mText); 353 //QWhatsThis::add(this,mText);
351 354
352} 355}
353 356
354void KOEventViewer::appendTodo(Todo *event, int mode ) 357void KOEventViewer::appendTodo(Todo *event, int mode )
355{ 358{
356 mMailSubject = ""; 359 mMailSubject = "";
357 mCurrentIncidence = event; 360 mCurrentIncidence = event;
358 topLevelWidget()->setCaption(i18n("Todo Viewer")); 361 topLevelWidget()->setCaption(i18n("Todo Viewer"));
359 bool shortDate = KOPrefs::instance()->mShortDateInViewer; 362 bool shortDate = KOPrefs::instance()->mShortDateInViewer;
360 if (mode == 0 ) 363 if (mode == 0 )
361 addTag("h2",event->summary()); 364 addTag("h2",event->summary());
362 else { 365 else {
363 if ( mColorMode == 1 ) { 366 if ( mColorMode == 1 ) {
364 mText +="<font color=\"#00A000\">"; 367 mText +="<font color=\"#00A000\">";
365 } 368 }
366 if ( mColorMode == 2 ) { 369 if ( mColorMode == 2 ) {
367 mText +="<font color=\"#B00000\">"; 370 mText +="<font color=\"#B00000\">";
368 } 371 }
369 if ( mode == 1 ) { 372 if ( mode == 1 ) {
370 addTag("h2",i18n( "Local: " ) +event->summary()); 373 addTag("h2",i18n( "Local: " ) +event->summary());
371 } else { 374 } else {
372 addTag("h2",i18n( "Remote: " ) +event->summary()); 375 addTag("h2",i18n( "Remote: " ) +event->summary());
373 } 376 }
374 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 377 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
375 if ( mColorMode ) 378 if ( mColorMode )
376 mText += "</font>"; 379 mText += "</font>";
377 } 380 }
378 mMailSubject += i18n( "Todo " )+ event->summary(); 381 mMailSubject += i18n( "Todo " )+ event->summary();
379 382
380 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { 383 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) {
381 mText +="<font color=\"#B00000\">"; 384 mText +="<font color=\"#B00000\">";
382 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(KOPrefs::instance()->mShortDateInViewer) ) ); 385 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(KOPrefs::instance()->mShortDateInViewer) ) );
383 mText += "</font>"; 386 mText += "</font>";
384 } else { 387 } else {
385 mText.append(i18n("<p><i>%1 % completed</i></p>") 388 mText.append(i18n("<p><i>%1 % completed</i></p>")
386 .arg(event->percentComplete())); 389 .arg(event->percentComplete()));
387 } 390 }
388 391
389 if (event->cancelled ()) { 392 if (event->cancelled ()) {
390 mText +="<font color=\"#B00000\">"; 393 mText +="<font color=\"#B00000\">";
391 addTag("i",i18n("This todo has been cancelled!")); 394 addTag("i",i18n("This todo has been cancelled!"));
392 mText.append("<br>"); 395 mText.append("<br>");
393 mText += "</font>"; 396 mText += "</font>";
394 mMailSubject += i18n("(cancelled)"); 397 mMailSubject += i18n("(cancelled)");
395 } 398 }
396 399
397 if (!event->location().isEmpty()) { 400 if (!event->location().isEmpty()) {
398 addTag("b",i18n("Location: ")); 401 addTag("b",i18n("Location: "));
399 mText.append(event->location()+"<br>"); 402 mText.append(event->location()+"<br>");
400 mMailSubject += i18n(" at ") + event->location(); 403 mMailSubject += i18n(" at ") + event->location();
401 } 404 }
402 if (event->hasStartDate()) { 405 if (event->hasStartDate()) {
403 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(KOPrefs::instance()->mShortDateInViewer))); 406 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(KOPrefs::instance()->mShortDateInViewer)));
404 } 407 }
405 if (event->hasDueDate()) { 408 if (event->hasDueDate()) {
406 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(KOPrefs::instance()->mShortDateInViewer))); 409 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(KOPrefs::instance()->mShortDateInViewer)));
407 mMailSubject += i18n(" - " )+event->dtDueStr( true ); 410 mMailSubject += i18n(" - " )+event->dtDueStr( true );
408 } 411 }
409 addTag("b",i18n("Access: ")); 412 addTag("b",i18n("Access: "));
410 mText.append(event->secrecyStr()+"<br>"); 413 mText.append(event->secrecyStr()+"<br>");
411 if (!event->description().isEmpty()) { 414 if (!event->description().isEmpty()) {
412 addTag("p",i18n("<b>Details: </b>")); 415 addTag("p",i18n("<b>Details: </b>"));
413 addTag("p",event->description()); 416 addTag("p",event->description());
414 } 417 }
415 418
416 formatCategories(event); 419 formatCategories(event);
417 420
418 mText.append(i18n("<p><b>Priority:</b> %2</p>") 421 mText.append(i18n("<p><b>Priority:</b> %2</p>")
419 .arg(QString::number(event->priority()))); 422 .arg(QString::number(event->priority())));
420 423
421 formatReadOnly(event); 424 formatReadOnly(event);
422 formatAttendees(event); 425 formatAttendees(event);
423 if ( event->relatedTo() ) { 426 if ( event->relatedTo() ) {
424 addTag("b",i18n("Parent todo:<br>")); 427 addTag("b",i18n("Parent todo:<br>"));
425 mText.append(event->relatedTo()->summary()+" [" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] <br>"); 428 mText.append(event->relatedTo()->summary()+" [" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] <br>");
426 } 429 }
427 QPtrList<Incidence> Relations = event->relations(); 430 QPtrList<Incidence> Relations = event->relations();
428 Incidence *to; 431 Incidence *to;
429 if ( Relations.first() ) 432 if ( Relations.first() )
430 addTag("b",i18n("Sub todos:<br>")); 433 addTag("b",i18n("Sub todos:<br>"));
431 for (to=Relations.first();to;to=Relations.next()) { 434 for (to=Relations.first();to;to=Relations.next()) {
432 mText.append( to->summary()+" [" +QString::number(to->priority()) + "/" + QString::number(((Todo*)to)->percentComplete())+"%]<br>"); 435 mText.append( to->summary()+" [" +QString::number(to->priority()) + "/" + QString::number(((Todo*)to)->percentComplete())+"%]<br>");
433 436
434 } 437 }
435 setText(mText); 438 setText(mText);
436} 439}
437 440
438void KOEventViewer::formatCategories(Incidence *event) 441void KOEventViewer::formatCategories(Incidence *event)
439{ 442{
440 if (!event->categoriesStr().isEmpty()) { 443 if (!event->categoriesStr().isEmpty()) {
441 if (event->categories().count() == 1) { 444 if (event->categories().count() == 1) {
442 addTag("h3",i18n("Category")); 445 addTag("h3",i18n("Category"));
443 } else { 446 } else {
444 addTag("h3",i18n("Categories")); 447 addTag("h3",i18n("Categories"));
445 } 448 }
446 addTag("p",event->categoriesStr()); 449 addTag("p",event->categoriesStr());
447 } 450 }
448} 451}
449void KOEventViewer::formatAttendees(Incidence *event) 452void KOEventViewer::formatAttendees(Incidence *event)
450{ 453{
451 QPtrList<Attendee> attendees = event->attendees(); 454 QPtrList<Attendee> attendees = event->attendees();
452 if (attendees.count()) { 455 if (attendees.count()) {
453 456
454 457
455 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); 458 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small);
456 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); 459 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small);
457 addTag("h3",i18n("Organizer")); 460 addTag("h3",i18n("Organizer"));
458 mText.append("<ul><li>"); 461 mText.append("<ul><li>");
459#ifndef KORG_NOKABC 462#ifndef KORG_NOKABC
460 463
461#ifdef DESKTOP_VERSION 464#ifdef DESKTOP_VERSION
462 KABC::AddressBook *add_book = KABC::StdAddressBook::self(); 465 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
463 KABC::Addressee::List addressList; 466 KABC::Addressee::List addressList;
464 addressList = add_book->findByEmail(event->organizer()); 467 addressList = add_book->findByEmail(event->organizer());
465 KABC::Addressee o = addressList.first(); 468 KABC::Addressee o = addressList.first();
466 if (!o.isEmpty() && addressList.size()<2) { 469 if (!o.isEmpty() && addressList.size()<2) {
467 mText += "<a href=\"uid:" + o.uid() + "\">"; 470 mText += "<a href=\"uid:" + o.uid() + "\">";
468 mText += o.formattedName(); 471 mText += o.formattedName();
469 mText += "</a>\n"; 472 mText += "</a>\n";
470 } else { 473 } else {
471 mText.append(event->organizer()); 474 mText.append(event->organizer());
472 } 475 }
473#else //DESKTOP_VERSION 476#else //DESKTOP_VERSION
474 mText += "<a href=\"uid:organizer\">"; 477 mText += "<a href=\"uid:organizer\">";
475 mText += event->organizer(); 478 mText += event->organizer();
476 mText += "</a>\n"; 479 mText += "</a>\n";
477#endif //DESKTOP_VERSION 480#endif //DESKTOP_VERSION
478 481
479 482
480#else 483#else
481 mText.append(event->organizer()); 484 mText.append(event->organizer());
482#endif 485#endif
483 486
484 if (iconPath) { 487 if (iconPath) {
485 mText += " <a href=\"mailto:" + event->organizer() + "\">"; 488 mText += " <a href=\"mailto:" + event->organizer() + "\">";
486 mText += "<IMG src=\"" + iconPath + "\">"; 489 mText += "<IMG src=\"" + iconPath + "\">";
487 mText += "</a>\n"; 490 mText += "</a>\n";
488 } 491 }
489 mText.append("</li></ul>"); 492 mText.append("</li></ul>");
490 493
491 addTag("h3",i18n("Attendees")); 494 addTag("h3",i18n("Attendees"));
492 Attendee *a; 495 Attendee *a;
493 mText.append("<ul>"); 496 mText.append("<ul>");
494 int a_count = 0; 497 int a_count = 0;
495 int a_count_nr = 0; 498 int a_count_nr = 0;
496 499
497 for(a=attendees.first();a;a=attendees.next()) { 500 for(a=attendees.first();a;a=attendees.next()) {
498#ifndef KORG_NOKABC 501#ifndef KORG_NOKABC
499#ifdef DESKTOP_VERSION 502#ifdef DESKTOP_VERSION
500 if (a->name().isEmpty()) { 503 if (a->name().isEmpty()) {
501 addressList = add_book->findByEmail(a->email()); 504 addressList = add_book->findByEmail(a->email());
502 KABC::Addressee o = addressList.first(); 505 KABC::Addressee o = addressList.first();
503 if (!o.isEmpty() && addressList.size()<2) { 506 if (!o.isEmpty() && addressList.size()<2) {
504 mText += "<a href=\"uid:" + o.uid() + "\">"; 507 mText += "<a href=\"uid:" + o.uid() + "\">";
505 mText += o.formattedName(); 508 mText += o.formattedName();
506 mText += "</a>\n"; 509 mText += "</a>\n";
507 } else { 510 } else {
508 mText += "<li>"; 511 mText += "<li>";
509 mText.append(a->email()); 512 mText.append(a->email());
510 mText += "\n"; 513 mText += "\n";
511 } 514 }
512 } else { 515 } else {
513 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 516 mText += "<li><a href=\"uid:" + a->uid() + "\">";
514 if (!a->name().isEmpty()) mText += a->name(); 517 if (!a->name().isEmpty()) mText += a->name();
515 else mText += a->email(); 518 else mText += a->email();
516 mText += "</a>\n"; 519 mText += "</a>\n";
517 } 520 }
518#else //DESKTOP_VERSION 521#else //DESKTOP_VERSION
519 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 522 mText += "<li><a href=\"uid:" + a->uid() + "\">";
520 if (!a->name().isEmpty()) mText += a->name(); 523 if (!a->name().isEmpty()) mText += a->name();
521 else mText += a->email(); 524 else mText += a->email();
522 mText += "</a>\n"; 525 mText += "</a>\n";
523#endif //DESKTOP_VERSION 526#endif //DESKTOP_VERSION
524#else 527#else
525 //qDebug("nokabc "); 528 //qDebug("nokabc ");
526 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 529 mText += "<li><a href=\"uid:" + a->uid() + "\">";
527 if (!a->name().isEmpty()) mText += a->name(); 530 if (!a->name().isEmpty()) mText += a->name();
528 else mText += a->email(); 531 else mText += a->email();
529 mText += "</a>\n"; 532 mText += "</a>\n";
530#endif 533#endif
531 534
532 535
533 if (!a->email().isEmpty()) { 536 if (!a->email().isEmpty()) {
534 if (iconPath) { 537 if (iconPath) {
535 mText += "<a href=\"mailto:" + a->name() +" <" + a->email() + ">:" + mMailSubject + "\">"; 538 mText += "<a href=\"mailto:" + a->name() +" <" + a->email() + ">:" + mMailSubject + "\">";
536 if ( a->RSVP() ) { 539 if ( a->RSVP() ) {
537 ++a_count_nr; 540 ++a_count_nr;
538 mText += "<IMG src=\"" + iconPath + "\">"; 541 mText += "<IMG src=\"" + iconPath + "\">";
539 } 542 }
540 else { 543 else {
541 ++a_count; 544 ++a_count;
542 mText += "<IMG src=\"" + NOiconPath + "\">"; 545 mText += "<IMG src=\"" + NOiconPath + "\">";
543 } 546 }
544 mText += "</a>\n"; 547 mText += "</a>\n";
545 } 548 }
546 } 549 }
547 if (a->status() != Attendee::NeedsAction ) 550 if (a->status() != Attendee::NeedsAction )
548 mText +="[" + a->statusStr() + "] "; 551 mText +="[" + a->statusStr() + "] ";
549 if (a->role() == Attendee::Chair ) 552 if (a->role() == Attendee::Chair )
550 mText +="(" + a->roleStr().left(1) + ".)"; 553 mText +="(" + a->roleStr().left(1) + ".)";
551 } 554 }
552 mText.append("</li></ul>"); 555 mText.append("</li></ul>");
553 if ( (a_count+a_count_nr) > 1 ) { 556 if ( (a_count+a_count_nr) > 1 ) {
554 mText += "<a href=\"mailto:ALL\">"; 557 mText += "<a href=\"mailto:ALL\">";
555 mText += i18n( "Mail to all" ); 558 mText += i18n( "Mail to all" );
556 mText += "</a> ( "; 559 mText += "</a> ( ";
557 mText += "<IMG src=\"" + iconPath + "\">"; 560 mText += "<IMG src=\"" + iconPath + "\">";
558 mText += i18n( " and " ); 561 mText += i18n( " and " );
559 mText += "<IMG src=\"" + NOiconPath + "\"> )"; 562 mText += "<IMG src=\"" + NOiconPath + "\"> )";
560 mText += "<br>\n"; 563 mText += "<br>\n";
561 564
562 565
563 } 566 }
564 if ( a_count_nr > 1 ) { 567 if ( a_count_nr > 1 ) {
565 mText += "<a href=\"mailto:RSVP\">"; 568 mText += "<a href=\"mailto:RSVP\">";
566 mText += i18n( "Mail to selected" ); 569 mText += i18n( "Mail to selected" );
567 mText += "</a> ( "; 570 mText += "</a> ( ";
568 mText += i18n( "<IMG src=\"%1\"> only )").arg ( iconPath ); 571 mText += i18n( "<IMG src=\"%1\"> only )").arg ( iconPath );
569 mText += "<br>\n"; 572 mText += "<br>\n";
570 } 573 }
571 } 574 }
572 575
573} 576}
574void KOEventViewer::appendJournal(Journal *jour, int mode ) 577void KOEventViewer::appendJournal(Journal *jour, int mode )
575{ 578{
576 bool shortDate = KOPrefs::instance()->mShortDateInViewer; 579 bool shortDate = KOPrefs::instance()->mShortDateInViewer;
577 if (mode == 0 ) { 580 if (mode == 0 ) {
578 addTag("h2",i18n("Journal from: ")); 581 addTag("h2",i18n("Journal from: "));
579 } 582 }
580 else { 583 else {
581 if ( mode == 1 ) { 584 if ( mode == 1 ) {
582 addTag("h2",i18n( "Local: " ) +i18n("Journal from: ")); 585 addTag("h2",i18n( "Local: " ) +i18n("Journal from: "));
583 } else { 586 } else {
584 addTag("h2",i18n( "Remote: " ) +i18n("Journal from: ")); 587 addTag("h2",i18n( "Remote: " ) +i18n("Journal from: "));
585 } 588 }
586 } 589 }
587 topLevelWidget()->setCaption("Journal Viewer"); 590 topLevelWidget()->setCaption("Journal Viewer");
588 mText.append(i18n("<h3> %1 </h3> ").arg(jour->dtStartDateStr(KOPrefs::instance()->mShortDateInViewer))); 591 mText.append(i18n("<h3> %1 </h3> ").arg(jour->dtStartDateStr(KOPrefs::instance()->mShortDateInViewer)));
589 addTag("b",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(jour->lastModified(),shortDate ) ); 592 addTag("b",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(jour->lastModified(),shortDate ) );
590 if (!jour->description().isEmpty()) { 593 if (!jour->description().isEmpty()) {
591 addTag("p",jour->description()); 594 addTag("p",jour->description());
592 } 595 }
593 setText(mText); 596 setText(mText);
594} 597}
595 598
596void KOEventViewer::formatReadOnly(Incidence *event) 599void KOEventViewer::formatReadOnly(Incidence *event)
597{ 600{
598 if (event->isReadOnly()) { 601 if (event->isReadOnly()) {
599 addTag("p","<em>(" + i18n("read-only") + ")</em>"); 602 addTag("p","<em>(" + i18n("read-only") + ")</em>");
600 } 603 }
601} 604}
602void KOEventViewer::setSyncMode( bool b ) 605void KOEventViewer::setSyncMode( bool b )
603{ 606{
604 mSyncMode = b; 607 mSyncMode = b;
605} 608}
606 609
607 610
608void KOEventViewer::setTodo(Todo *event, bool clearV ) 611void KOEventViewer::setTodo(Todo *event, bool clearV )
609{ 612{
610 if ( clearV ) 613 if ( clearV )
611 clearEvents(); 614 clearEvents();
612 if ( mSyncMode ) { 615 if ( mSyncMode ) {
613 if ( clearV ) 616 if ( clearV )
614 appendTodo(event,1 ); 617 appendTodo(event,1 );
615 else 618 else
616 appendTodo(event,2); 619 appendTodo(event,2);
617 } else 620 } else
618 appendTodo(event); 621 appendTodo(event);
619} 622}
620void KOEventViewer::setJournal(Journal *event, bool clearV ) 623void KOEventViewer::setJournal(Journal *event, bool clearV )
621{ 624{
622 if ( clearV ) 625 if ( clearV )
623 clearEvents(); 626 clearEvents();
624 if ( mSyncMode ) { 627 if ( mSyncMode ) {
625 if ( clearV ) 628 if ( clearV )
626 appendJournal(event, 1); 629 appendJournal(event, 1);
627 else 630 else
628 appendJournal(event, 2); 631 appendJournal(event, 2);
629 } else 632 } else
630 appendJournal(event); 633 appendJournal(event);
631} 634}
632 635
633void KOEventViewer::setEvent(Event *event) 636void KOEventViewer::setEvent(Event *event)
634{ 637{
635 clearEvents(); 638 clearEvents();
636 if ( mSyncMode ) 639 if ( mSyncMode )
637 appendEvent(event, 1); 640 appendEvent(event, 1);
638 else 641 else
639 appendEvent(event); 642 appendEvent(event);
640} 643}
641 644
642void KOEventViewer::addEvent(Event *event) 645void KOEventViewer::addEvent(Event *event)
643{ 646{
644 if ( mSyncMode ) 647 if ( mSyncMode )
645 appendEvent(event, 2); 648 appendEvent(event, 2);
646 else 649 else
647 appendEvent(event); 650 appendEvent(event);
648} 651}
649 652
650void KOEventViewer::clearEvents(bool now) 653void KOEventViewer::clearEvents(bool now)
651{ 654{
652 mText = ""; 655 mText = "";
653 if (now) setText(mText); 656 if (now) setText(mText);
654} 657}
655 658
656void KOEventViewer::addText(QString text) 659void KOEventViewer::addText(QString text)
657{ 660{
658 mText.append(text); 661 mText.append(text);
659 setText(mText); 662 setText(mText);
660} 663}
diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp
index 6d07d4c..0d9c3f4 100644
--- a/libkcal/kincidenceformatter.cpp
+++ b/libkcal/kincidenceformatter.cpp
@@ -1,338 +1,344 @@
1#include "kincidenceformatter.h" 1#include "kincidenceformatter.h"
2#include <kstaticdeleter.h> 2#include <kstaticdeleter.h>
3#include <kglobal.h> 3#include <kglobal.h>
4#include <klocale.h> 4#include <klocale.h>
5#ifdef DEKTOP_VERSION 5#ifdef DEKTOP_VERSION
6#include <kabc/stdaddressbook.h> 6#include <kabc/stdaddressbook.h>
7#define size count 7#define size count
8#endif 8#endif
9 9
10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; 10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0;
11static KStaticDeleter<KIncidenceFormatter> insd; 11static KStaticDeleter<KIncidenceFormatter> insd;
12 12
13QString KIncidenceFormatter::getFormattedText( Incidence * inc ) 13QString KIncidenceFormatter::getFormattedText( Incidence * inc )
14{ 14{
15// #ifndef QT_NO_INPUTDIALOG 15// #ifndef QT_NO_INPUTDIALOG
16// return QInputDialog::getItem( caption, label, items, current, editable ); 16// return QInputDialog::getItem( caption, label, items, current, editable );
17// #else 17// #else
18// return QString::null; 18// return QString::null;
19// #endif 19// #endif
20 mText = ""; 20 mText = "";
21 if ( inc->type() == "Event" ) 21 if ( inc->type() == "Event" )
22 setEvent((Event *) inc ); 22 setEvent((Event *) inc );
23 else if ( inc->type() == "Todo" ) 23 else if ( inc->type() == "Todo" )
24 setTodo((Todo *) inc ); 24 setTodo((Todo *) inc );
25 return mText; 25 return mText;
26} 26}
27 27
28KIncidenceFormatter* KIncidenceFormatter::instance() 28KIncidenceFormatter* KIncidenceFormatter::instance()
29{ 29{
30 if (!mInstance) { 30 if (!mInstance) {
31 mInstance = insd.setObject(new KIncidenceFormatter()); 31 mInstance = insd.setObject(new KIncidenceFormatter());
32 } 32 }
33 return mInstance; 33 return mInstance;
34} 34}
35KIncidenceFormatter::~KIncidenceFormatter() 35KIncidenceFormatter::~KIncidenceFormatter()
36{ 36{
37 if (mInstance == this) 37 if (mInstance == this)
38 mInstance = insd.setObject(0); 38 mInstance = insd.setObject(0);
39 //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); 39 //qDebug("KIncidenceFormatter::~KIncidenceFormatter ");
40} 40}
41KIncidenceFormatter::KIncidenceFormatter() 41KIncidenceFormatter::KIncidenceFormatter()
42{ 42{
43 mColorMode = 0; 43 mColorMode = 0;
44} 44}
45void KIncidenceFormatter::setEvent(Event *event) 45void KIncidenceFormatter::setEvent(Event *event)
46{ 46{
47 int mode = 0; 47 int mode = 0;
48 mCurrentIncidence = event; 48 mCurrentIncidence = event;
49 bool shortDate = true; 49 bool shortDate = true;
50 if ( mode == 0 ) { 50 if ( mode == 0 ) {
51 addTag("h3",event->summary()); 51 addTag("h3",event->summary());
52 } 52 }
53 else { 53 else {
54 if ( mColorMode == 1 ) { 54 if ( mColorMode == 1 ) {
55 mText +="<font color=\"#00A000\">"; 55 mText +="<font color=\"#00A000\">";
56 } 56 }
57 if ( mColorMode == 2 ) { 57 if ( mColorMode == 2 ) {
58 mText +="<font color=\"#C00000\">"; 58 mText +="<font color=\"#C00000\">";
59 } 59 }
60 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; 60 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
61 if ( mode == 1 ) { 61 if ( mode == 1 ) {
62 addTag("h2",i18n( "Local: " ) +event->summary()); 62 addTag("h2",i18n( "Local: " ) +event->summary());
63 } else { 63 } else {
64 addTag("h2",i18n( "Remote: " ) +event->summary()); 64 addTag("h2",i18n( "Remote: " ) +event->summary());
65 } 65 }
66 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 66 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
67 if ( mColorMode ) 67 if ( mColorMode )
68 mText += "</font>"; 68 mText += "</font>";
69 } 69 }
70 if (event->cancelled ()) { 70 if (event->cancelled ()) {
71 mText +="<font color=\"#B00000\">"; 71 mText +="<font color=\"#B00000\">";
72 addTag("i",i18n("This event has been cancelled!")); 72 addTag("i",i18n("This event has been cancelled!"));
73 mText.append("<br>"); 73 mText.append("<br>");
74 mText += "</font>"; 74 mText += "</font>";
75 } 75 }
76 if (!event->location().isEmpty()) { 76 if (!event->location().isEmpty()) {
77 addTag("b",i18n("Location: ")); 77 addTag("b",i18n("Location: "));
78 mText.append(event->location()+"<br>"); 78 mText.append(event->location()+"<br>");
79 } 79 }
80 if (event->doesFloat()) { 80 if (event->doesFloat()) {
81 if (event->isMultiDay()) { 81 if (event->isMultiDay()) {
82 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") 82 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>")
83 .arg(event->dtStartDateStr(shortDate)) 83 .arg(event->dtStartDateStr(shortDate))
84 .arg(event->dtEndDateStr(shortDate))); 84 .arg(event->dtEndDateStr(shortDate)));
85 } else { 85 } else {
86 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); 86 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate )));
87 } 87 }
88 } else { 88 } else {
89 if (event->isMultiDay()) { 89 if (event->isMultiDay()) {
90 mText.append(i18n("<p><b>From:</b> %1</p> ") 90 mText.append(i18n("<p><b>From:</b> %1</p> ")
91 .arg(event->dtStartStr( shortDate))); 91 .arg(event->dtStartStr( shortDate)));
92 mText.append(i18n("<p><b>To:</b> %1</p>") 92 mText.append(i18n("<p><b>To:</b> %1</p>")
93 .arg(event->dtEndStr(shortDate))); 93 .arg(event->dtEndStr(shortDate)));
94 } else { 94 } else {
95 mText.append(i18n("<p><b>On:</b> %1</p> ") 95 mText.append(i18n("<p><b>On:</b> %1</p> ")
96 .arg(event->dtStartDateStr( shortDate ))); 96 .arg(event->dtStartDateStr( shortDate )));
97 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") 97 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>")
98 .arg(event->dtStartTimeStr()) 98 .arg(event->dtStartTimeStr())
99 .arg(event->dtEndTimeStr())); 99 .arg(event->dtEndTimeStr()));
100 } 100 }
101 } 101 }
102 102
103 if (event->recurrence()->doesRecur()) { 103 if (event->recurrence()->doesRecur()) {
104 104
105 QString recurText = event->recurrence()->recurrenceText(); 105 QString recurText = event->recurrence()->recurrenceText();
106 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); 106 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>");
107 bool last; 107
108 bool ok;
108 QDate start = QDate::currentDate(); 109 QDate start = QDate::currentDate();
109 QDate next; 110 QDateTime next;
110 next = event->recurrence()->getPreviousDate( start , &last ); 111 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok );
111 if ( !last ) { 112 if ( ok ) {
112 next = event->recurrence()->getNextDate( start.addDays( - 1 ) ); 113 addTag("p",i18n("<b>Next recurrence is on:</b>") );
113 addTag("p",i18n("Next recurrence is on: ")+ KGlobal::locale()->formatDate( next, shortDate ) ); 114 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate ));
114 //addTag("p", KGlobal::locale()->formatDate( next, shortDate )); 115
115 } else { 116 } else {
116 addTag("p",i18n("<b>Last recurrence was on:</b>") ); 117 bool last;
117 addTag("p", KGlobal::locale()->formatDate( next, shortDate )); 118 QDate nextd;
119 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last );
120 if ( last ) {
121 addTag("p",i18n("<b>Last recurrence was on:</b>") );
122 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate ));
123 }
118 } 124 }
119 } 125 }
120 126
121 127
122 if (event->isAlarmEnabled()) { 128 if (event->isAlarmEnabled()) {
123 Alarm *alarm =event->alarms().first() ; 129 Alarm *alarm =event->alarms().first() ;
124 QDateTime t = alarm->time(); 130 QDateTime t = alarm->time();
125 int min = t.secsTo( event->dtStart() )/60; 131 int min = t.secsTo( event->dtStart() )/60;
126 QString s =i18n("(%1 min before)").arg( min ); 132 QString s =i18n("(%1 min before)").arg( min );
127 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); 133 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate ));
128 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 134 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
129 //addTag("p",s); 135 //addTag("p",s);
130 } 136 }
131 137
132 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 138 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
133 // mText.append(event->secrecyStr()+"<br>"); 139 // mText.append(event->secrecyStr()+"<br>");
134 formatCategories(event); 140 formatCategories(event);
135 if (!event->description().isEmpty()) { 141 if (!event->description().isEmpty()) {
136 addTag("p",i18n("<b>Details: </b>")); 142 addTag("p",i18n("<b>Details: </b>"));
137 addTag("p",event->description()); 143 addTag("p",event->description());
138 } 144 }
139 145
140 146
141 formatReadOnly(event); 147 formatReadOnly(event);
142 formatAttendees(event); 148 formatAttendees(event);
143 149
144 150
145} 151}
146 152
147void KIncidenceFormatter::setTodo(Todo *event ) 153void KIncidenceFormatter::setTodo(Todo *event )
148{ 154{
149 int mode = 0; 155 int mode = 0;
150 mCurrentIncidence = event; 156 mCurrentIncidence = event;
151 bool shortDate = true; 157 bool shortDate = true;
152 if (mode == 0 ) 158 if (mode == 0 )
153 addTag("h3",event->summary()); 159 addTag("h3",event->summary());
154 else { 160 else {
155 if ( mColorMode == 1 ) { 161 if ( mColorMode == 1 ) {
156 mText +="<font color=\"#00A000\">"; 162 mText +="<font color=\"#00A000\">";
157 } 163 }
158 if ( mColorMode == 2 ) { 164 if ( mColorMode == 2 ) {
159 mText +="<font color=\"#B00000\">"; 165 mText +="<font color=\"#B00000\">";
160 } 166 }
161 if ( mode == 1 ) { 167 if ( mode == 1 ) {
162 addTag("h2",i18n( "Local: " ) +event->summary()); 168 addTag("h2",i18n( "Local: " ) +event->summary());
163 } else { 169 } else {
164 addTag("h2",i18n( "Remote: " ) +event->summary()); 170 addTag("h2",i18n( "Remote: " ) +event->summary());
165 } 171 }
166 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 172 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
167 if ( mColorMode ) 173 if ( mColorMode )
168 mText += "</font>"; 174 mText += "</font>";
169 } 175 }
170 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { 176 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) {
171 mText +="<font color=\"#B00000\">"; 177 mText +="<font color=\"#B00000\">";
172 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); 178 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) );
173 mText += "</font>"; 179 mText += "</font>";
174 } else { 180 } else {
175 mText.append(i18n("<p><i>%1 % completed</i></p>") 181 mText.append(i18n("<p><i>%1 % completed</i></p>")
176 .arg(event->percentComplete())); 182 .arg(event->percentComplete()));
177 } 183 }
178 if (event->cancelled ()) { 184 if (event->cancelled ()) {
179 mText +="<font color=\"#B00000\">"; 185 mText +="<font color=\"#B00000\">";
180 addTag("i",i18n("This todo has been cancelled!")); 186 addTag("i",i18n("This todo has been cancelled!"));
181 mText.append("<br>"); 187 mText.append("<br>");
182 mText += "</font>"; 188 mText += "</font>";
183 } 189 }
184 190
185 if (!event->location().isEmpty()) { 191 if (!event->location().isEmpty()) {
186 addTag("b",i18n("Location: ")); 192 addTag("b",i18n("Location: "));
187 mText.append(event->location()+"<br>"); 193 mText.append(event->location()+"<br>");
188 } 194 }
189 if (event->hasDueDate()) { 195 if (event->hasDueDate()) {
190 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); 196 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate)));
191 } 197 }
192 mText.append(i18n("<p><b>Priority:</b> %2</p>") 198 mText.append(i18n("<p><b>Priority:</b> %2</p>")
193 .arg(QString::number(event->priority()))); 199 .arg(QString::number(event->priority())));
194 200
195 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 201 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
196 formatCategories(event); 202 formatCategories(event);
197 if (!event->description().isEmpty()) { 203 if (!event->description().isEmpty()) {
198 addTag("p",i18n("<b>Details: </b>")); 204 addTag("p",i18n("<b>Details: </b>"));
199 addTag("p",event->description()); 205 addTag("p",event->description());
200 } 206 }
201 207
202 208
203 209
204 formatReadOnly(event); 210 formatReadOnly(event);
205 formatAttendees(event); 211 formatAttendees(event);
206 212
207} 213}
208 214
209void KIncidenceFormatter::setJournal(Journal* ) 215void KIncidenceFormatter::setJournal(Journal* )
210{ 216{
211 217
212} 218}
213 219
214void KIncidenceFormatter::formatCategories(Incidence *event) 220void KIncidenceFormatter::formatCategories(Incidence *event)
215{ 221{
216 if (!event->categoriesStr().isEmpty()) { 222 if (!event->categoriesStr().isEmpty()) {
217 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() ); 223 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() );
218 //mText.append(event->categoriesStr()); 224 //mText.append(event->categoriesStr());
219 } 225 }
220} 226}
221void KIncidenceFormatter::addTag(const QString & tag,const QString & text) 227void KIncidenceFormatter::addTag(const QString & tag,const QString & text)
222{ 228{
223 int number=text.contains("\n"); 229 int number=text.contains("\n");
224 QString str = "<" + tag + ">"; 230 QString str = "<" + tag + ">";
225 QString tmpText=text; 231 QString tmpText=text;
226 QString tmpStr=str; 232 QString tmpStr=str;
227 if(number !=-1) 233 if(number !=-1)
228 { 234 {
229 if (number > 0) { 235 if (number > 0) {
230 int pos=0; 236 int pos=0;
231 QString tmp; 237 QString tmp;
232 for(int i=0;i<=number;i++) { 238 for(int i=0;i<=number;i++) {
233 pos=tmpText.find("\n"); 239 pos=tmpText.find("\n");
234 tmp=tmpText.left(pos); 240 tmp=tmpText.left(pos);
235 tmpText=tmpText.right(tmpText.length()-pos-1); 241 tmpText=tmpText.right(tmpText.length()-pos-1);
236 tmpStr+=tmp+"<br>"; 242 tmpStr+=tmp+"<br>";
237 } 243 }
238 } 244 }
239 else tmpStr += tmpText; 245 else tmpStr += tmpText;
240 tmpStr+="</" + tag + ">"; 246 tmpStr+="</" + tag + ">";
241 mText.append(tmpStr); 247 mText.append(tmpStr);
242 } 248 }
243 else 249 else
244 { 250 {
245 str += text + "</" + tag + ">"; 251 str += text + "</" + tag + ">";
246 mText.append(str); 252 mText.append(str);
247 } 253 }
248} 254}
249 255
250void KIncidenceFormatter::formatAttendees(Incidence *event) 256void KIncidenceFormatter::formatAttendees(Incidence *event)
251{ 257{
252 QPtrList<Attendee> attendees = event->attendees(); 258 QPtrList<Attendee> attendees = event->attendees();
253 if (attendees.count()) { 259 if (attendees.count()) {
254 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); 260 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small);
255 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); 261 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small);
256 addTag("h3",i18n("Organizer")); 262 addTag("h3",i18n("Organizer"));
257 mText.append("<ul><li>"); 263 mText.append("<ul><li>");
258#if 0 264#if 0
259 //ndef KORG_NOKABC 265 //ndef KORG_NOKABC
260 266
261 KABC::AddressBook *add_book = KABC::StdAddressBook::self(); 267 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
262 KABC::Addressee::List addressList; 268 KABC::Addressee::List addressList;
263 addressList = add_book->findByEmail(event->organizer()); 269 addressList = add_book->findByEmail(event->organizer());
264 KABC::Addressee o = addressList.first(); 270 KABC::Addressee o = addressList.first();
265 if (!o.isEmpty() && addressList.size()<2) { 271 if (!o.isEmpty() && addressList.size()<2) {
266 mText += "<a href=\"uid:" + o.uid() + "\">"; 272 mText += "<a href=\"uid:" + o.uid() + "\">";
267 mText += o.formattedName(); 273 mText += o.formattedName();
268 mText += "</a>\n"; 274 mText += "</a>\n";
269 } else { 275 } else {
270 mText.append(event->organizer()); 276 mText.append(event->organizer());
271 } 277 }
272#else 278#else
273 mText.append(event->organizer()); 279 mText.append(event->organizer());
274#endif 280#endif
275 if (iconPath) { 281 if (iconPath) {
276 mText += " <a href=\"mailto:" + event->organizer() + "\">"; 282 mText += " <a href=\"mailto:" + event->organizer() + "\">";
277 mText += "<IMG src=\"" + iconPath + "\">"; 283 mText += "<IMG src=\"" + iconPath + "\">";
278 mText += "</a>\n"; 284 mText += "</a>\n";
279 } 285 }
280 mText.append("</li></ul>"); 286 mText.append("</li></ul>");
281 287
282 addTag("h3",i18n("Attendees")); 288 addTag("h3",i18n("Attendees"));
283 Attendee *a; 289 Attendee *a;
284 mText.append("<ul>"); 290 mText.append("<ul>");
285 for(a=attendees.first();a;a=attendees.next()) { 291 for(a=attendees.first();a;a=attendees.next()) {
286#if 0 292#if 0
287//ndef KORG_NOKABC 293//ndef KORG_NOKABC
288 if (a->name().isEmpty()) { 294 if (a->name().isEmpty()) {
289 addressList = add_book->findByEmail(a->email()); 295 addressList = add_book->findByEmail(a->email());
290 KABC::Addressee o = addressList.first(); 296 KABC::Addressee o = addressList.first();
291 if (!o.isEmpty() && addressList.size()<2) { 297 if (!o.isEmpty() && addressList.size()<2) {
292 mText += "<a href=\"uid:" + o.uid() + "\">"; 298 mText += "<a href=\"uid:" + o.uid() + "\">";
293 mText += o.formattedName(); 299 mText += o.formattedName();
294 mText += "</a>\n"; 300 mText += "</a>\n";
295 } else { 301 } else {
296 mText += "<li>"; 302 mText += "<li>";
297 mText.append(a->email()); 303 mText.append(a->email());
298 mText += "\n"; 304 mText += "\n";
299 } 305 }
300 } else { 306 } else {
301 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 307 mText += "<li><a href=\"uid:" + a->uid() + "\">";
302 if (!a->name().isEmpty()) mText += a->name(); 308 if (!a->name().isEmpty()) mText += a->name();
303 else mText += a->email(); 309 else mText += a->email();
304 mText += "</a>\n"; 310 mText += "</a>\n";
305 } 311 }
306#else 312#else
307 //qDebug("nokabc "); 313 //qDebug("nokabc ");
308 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 314 mText += "<li><a href=\"uid:" + a->uid() + "\">";
309 if (!a->name().isEmpty()) mText += a->name(); 315 if (!a->name().isEmpty()) mText += a->name();
310 else mText += a->email(); 316 else mText += a->email();
311 mText += "</a>\n"; 317 mText += "</a>\n";
312#endif 318#endif
313 319
314 if (!a->email().isEmpty()) { 320 if (!a->email().isEmpty()) {
315 if (iconPath) { 321 if (iconPath) {
316 mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; 322 mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">";
317 if ( a->RSVP() ) 323 if ( a->RSVP() )
318 mText += "<IMG src=\"" + iconPath + "\">"; 324 mText += "<IMG src=\"" + iconPath + "\">";
319 else 325 else
320 mText += "<IMG src=\"" + NOiconPath + "\">"; 326 mText += "<IMG src=\"" + NOiconPath + "\">";
321 mText += "</a>\n"; 327 mText += "</a>\n";
322 } 328 }
323 } 329 }
324 if (a->status() != Attendee::NeedsAction ) 330 if (a->status() != Attendee::NeedsAction )
325 mText +="[" + a->statusStr() + "] "; 331 mText +="[" + a->statusStr() + "] ";
326 if (a->role() == Attendee::Chair ) 332 if (a->role() == Attendee::Chair )
327 mText +="(" + a->roleStr().left(1) + ".)"; 333 mText +="(" + a->roleStr().left(1) + ".)";
328 } 334 }
329 mText.append("</li></ul>"); 335 mText.append("</li></ul>");
330 } 336 }
331} 337}
332 338
333void KIncidenceFormatter::formatReadOnly(Incidence *event) 339void KIncidenceFormatter::formatReadOnly(Incidence *event)
334{ 340{
335 if (event->isReadOnly()) { 341 if (event->isReadOnly()) {
336 addTag("p","<em>(" + i18n("read-only") + ")</em>"); 342 addTag("p","<em>(" + i18n("read-only") + ")</em>");
337 } 343 }
338} 344}
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index e84f672..5181eaf 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -1,2704 +1,2706 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> 5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <limits.h> 23#include <limits.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "incidence.h" 29#include "incidence.h"
30 30
31#include "recurrence.h" 31#include "recurrence.h"
32 32
33using namespace KCal; 33using namespace KCal;
34 34
35Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1; 35Recurrence::Feb29Type Recurrence::mFeb29YearlyDefaultType = Recurrence::rMar1;
36 36
37 37
38Recurrence::Recurrence(Incidence *parent, int compatVersion) 38Recurrence::Recurrence(Incidence *parent, int compatVersion)
39: recurs(rNone), // by default, it's not a recurring event 39: recurs(rNone), // by default, it's not a recurring event
40 rWeekStart(1), // default is Monday 40 rWeekStart(1), // default is Monday
41 rDays(7), 41 rDays(7),
42 mFloats(parent ? parent->doesFloat() : false), 42 mFloats(parent ? parent->doesFloat() : false),
43 mRecurReadOnly(false), 43 mRecurReadOnly(false),
44 mRecurExDatesCount(0), 44 mRecurExDatesCount(0),
45 mFeb29YearlyType(mFeb29YearlyDefaultType), 45 mFeb29YearlyType(mFeb29YearlyDefaultType),
46 mCompatVersion(compatVersion ? compatVersion : INT_MAX), 46 mCompatVersion(compatVersion ? compatVersion : INT_MAX),
47 mCompatRecurs(rNone), 47 mCompatRecurs(rNone),
48 mCompatDuration(0), 48 mCompatDuration(0),
49 mParent(parent) 49 mParent(parent)
50{ 50{
51 rMonthDays.setAutoDelete( true ); 51 rMonthDays.setAutoDelete( true );
52 rMonthPositions.setAutoDelete( true ); 52 rMonthPositions.setAutoDelete( true );
53 rYearNums.setAutoDelete( true ); 53 rYearNums.setAutoDelete( true );
54} 54}
55 55
56Recurrence::Recurrence(const Recurrence &r, Incidence *parent) 56Recurrence::Recurrence(const Recurrence &r, Incidence *parent)
57: recurs(r.recurs), 57: recurs(r.recurs),
58 rWeekStart(r.rWeekStart), 58 rWeekStart(r.rWeekStart),
59 rDays(r.rDays.copy()), 59 rDays(r.rDays.copy()),
60 rFreq(r.rFreq), 60 rFreq(r.rFreq),
61 rDuration(r.rDuration), 61 rDuration(r.rDuration),
62 rEndDateTime(r.rEndDateTime), 62 rEndDateTime(r.rEndDateTime),
63 mRecurStart(r.mRecurStart), 63 mRecurStart(r.mRecurStart),
64 mFloats(r.mFloats), 64 mFloats(r.mFloats),
65 mRecurReadOnly(r.mRecurReadOnly), 65 mRecurReadOnly(r.mRecurReadOnly),
66 mRecurExDatesCount(r.mRecurExDatesCount), 66 mRecurExDatesCount(r.mRecurExDatesCount),
67 mFeb29YearlyType(r.mFeb29YearlyType), 67 mFeb29YearlyType(r.mFeb29YearlyType),
68 mCompatVersion(r.mCompatVersion), 68 mCompatVersion(r.mCompatVersion),
69 mCompatRecurs(r.mCompatRecurs), 69 mCompatRecurs(r.mCompatRecurs),
70 mCompatDuration(r.mCompatDuration), 70 mCompatDuration(r.mCompatDuration),
71 mParent(parent) 71 mParent(parent)
72{ 72{
73 for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) { 73 for (QPtrListIterator<rMonthPos> mp(r.rMonthPositions); mp.current(); ++mp) {
74 rMonthPos *tmp = new rMonthPos; 74 rMonthPos *tmp = new rMonthPos;
75 tmp->rPos = mp.current()->rPos; 75 tmp->rPos = mp.current()->rPos;
76 tmp->negative = mp.current()->negative; 76 tmp->negative = mp.current()->negative;
77 tmp->rDays = mp.current()->rDays.copy(); 77 tmp->rDays = mp.current()->rDays.copy();
78 rMonthPositions.append(tmp); 78 rMonthPositions.append(tmp);
79 } 79 }
80 for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) { 80 for (QPtrListIterator<int> md(r.rMonthDays); md.current(); ++md) {
81 int *tmp = new int; 81 int *tmp = new int;
82 *tmp = *md.current(); 82 *tmp = *md.current();
83 rMonthDays.append(tmp); 83 rMonthDays.append(tmp);
84 } 84 }
85 for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) { 85 for (QPtrListIterator<int> yn(r.rYearNums); yn.current(); ++yn) {
86 int *tmp = new int; 86 int *tmp = new int;
87 *tmp = *yn.current(); 87 *tmp = *yn.current();
88 rYearNums.append(tmp); 88 rYearNums.append(tmp);
89 } 89 }
90 rMonthDays.setAutoDelete( true ); 90 rMonthDays.setAutoDelete( true );
91 rMonthPositions.setAutoDelete( true ); 91 rMonthPositions.setAutoDelete( true );
92 rYearNums.setAutoDelete( true ); 92 rYearNums.setAutoDelete( true );
93} 93}
94 94
95Recurrence::~Recurrence() 95Recurrence::~Recurrence()
96{ 96{
97} 97}
98 98
99 99
100bool Recurrence::operator==( const Recurrence& r2 ) const 100bool Recurrence::operator==( const Recurrence& r2 ) const
101{ 101{
102 102
103 // the following line is obvious 103 // the following line is obvious
104 if ( recurs == rNone && r2.recurs == rNone ) 104 if ( recurs == rNone && r2.recurs == rNone )
105 return true; 105 return true;
106 // we need the above line, because two non recurring events may 106 // we need the above line, because two non recurring events may
107 // differ in the other settings, because one (or both) 107 // differ in the other settings, because one (or both)
108 // may be not initialized properly 108 // may be not initialized properly
109 109
110 if ( recurs != r2.recurs 110 if ( recurs != r2.recurs
111 || rFreq != r2.rFreq 111 || rFreq != r2.rFreq
112 || rDuration != r2.rDuration 112 || rDuration != r2.rDuration
113 || !rDuration && rEndDateTime != r2.rEndDateTime 113 || !rDuration && rEndDateTime != r2.rEndDateTime
114 || mRecurStart != r2.mRecurStart 114 || mRecurStart != r2.mRecurStart
115 || mFloats != r2.mFloats 115 || mFloats != r2.mFloats
116 || mRecurReadOnly != r2.mRecurReadOnly 116 || mRecurReadOnly != r2.mRecurReadOnly
117 || mRecurExDatesCount != r2.mRecurExDatesCount ) 117 || mRecurExDatesCount != r2.mRecurExDatesCount )
118 return false; 118 return false;
119 // no need to compare mCompat* and mParent 119 // no need to compare mCompat* and mParent
120 // OK to compare the pointers 120 // OK to compare the pointers
121 switch ( recurs ) 121 switch ( recurs )
122 { 122 {
123 case rWeekly: 123 case rWeekly:
124 return rDays == r2.rDays 124 return rDays == r2.rDays
125 && rWeekStart == r2.rWeekStart; 125 && rWeekStart == r2.rWeekStart;
126 case rMonthlyPos: { 126 case rMonthlyPos: {
127 QPtrList<rMonthPos> MonthPositions = rMonthPositions; 127 QPtrList<rMonthPos> MonthPositions = rMonthPositions;
128 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; 128 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
129 if ( !MonthPositions.count() ) 129 if ( !MonthPositions.count() )
130 return false; 130 return false;
131 if ( !MonthPositions2.count() ) 131 if ( !MonthPositions2.count() )
132 return false; 132 return false;
133 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; 133 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
134 } 134 }
135 case rMonthlyDay: { 135 case rMonthlyDay: {
136 QPtrList<int> MonthDays = rMonthDays ; 136 QPtrList<int> MonthDays = rMonthDays ;
137 QPtrList<int> MonthDays2 = r2.rMonthDays ; 137 QPtrList<int> MonthDays2 = r2.rMonthDays ;
138 if ( !MonthDays.count() ) 138 if ( !MonthDays.count() )
139 return false; 139 return false;
140 if ( !MonthDays2.count() ) 140 if ( !MonthDays2.count() )
141 return false; 141 return false;
142 return *MonthDays.first() == *MonthDays2.first() ; 142 return *MonthDays.first() == *MonthDays2.first() ;
143 } 143 }
144 case rYearlyPos: { 144 case rYearlyPos: {
145 145
146 QPtrList<int> YearNums = rYearNums; 146 QPtrList<int> YearNums = rYearNums;
147 QPtrList<int> YearNums2 = r2.rYearNums; 147 QPtrList<int> YearNums2 = r2.rYearNums;
148 if ( *YearNums.first() != *YearNums2.first() ) 148 if ( *YearNums.first() != *YearNums2.first() )
149 return false; 149 return false;
150 QPtrList<rMonthPos> MonthPositions = rMonthPositions; 150 QPtrList<rMonthPos> MonthPositions = rMonthPositions;
151 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions; 151 QPtrList<rMonthPos> MonthPositions2 = r2.rMonthPositions;
152 if ( !MonthPositions.count() ) 152 if ( !MonthPositions.count() )
153 return false; 153 return false;
154 if ( !MonthPositions2.count() ) 154 if ( !MonthPositions2.count() )
155 return false; 155 return false;
156 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos; 156 return MonthPositions.first()->rPos == MonthPositions2.first()->rPos;
157 157
158 } 158 }
159 case rYearlyMonth: { 159 case rYearlyMonth: {
160 QPtrList<int> YearNums = rYearNums; 160 QPtrList<int> YearNums = rYearNums;
161 QPtrList<int> YearNums2 = r2.rYearNums; 161 QPtrList<int> YearNums2 = r2.rYearNums;
162 return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType); 162 return ( *YearNums.first() == *YearNums2.first() && mFeb29YearlyType == r2.mFeb29YearlyType);
163 } 163 }
164 case rYearlyDay: { 164 case rYearlyDay: {
165 QPtrList<int> YearNums = rYearNums; 165 QPtrList<int> YearNums = rYearNums;
166 QPtrList<int> YearNums2 = r2.rYearNums; 166 QPtrList<int> YearNums2 = r2.rYearNums;
167 return ( *YearNums.first() == *YearNums2.first() ); 167 return ( *YearNums.first() == *YearNums2.first() );
168 } 168 }
169 case rNone: 169 case rNone:
170 case rMinutely: 170 case rMinutely:
171 case rHourly: 171 case rHourly:
172 case rDaily: 172 case rDaily:
173 default: 173 default:
174 return true; 174 return true;
175 } 175 }
176} 176}
177/* 177/*
178bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2) 178bool Recurrence::compareLists( const QPtrList<int> &l1 ,const QPtrList<int> &l2)
179{ 179{
180 if ( l1.count() != l2.count() ) 180 if ( l1.count() != l2.count() )
181 return false; 181 return false;
182 int count = l1.count(); 182 int count = l1.count();
183 int i; 183 int i;
184 for ( i = 0; i < count ; ++i ) { 184 for ( i = 0; i < count ; ++i ) {
185 // if ( l1.at(i) != l2.at(i) ) 185 // if ( l1.at(i) != l2.at(i) )
186 return false; 186 return false;
187 qDebug("compüare "); 187 qDebug("compüare ");
188 } 188 }
189 return true; 189 return true;
190} 190}
191*/ 191*/
192QString Recurrence::recurrenceText() const 192QString Recurrence::recurrenceText() const
193{ 193{
194 QString recurText = i18n("No"); 194 QString recurText = i18n("No");
195 if ( recurs == Recurrence::rMinutely ) 195 if ( recurs == Recurrence::rMinutely )
196 recurText = i18n("minutely"); 196 recurText = i18n("minutely");
197 else if ( recurs == Recurrence::rHourly ) 197 else if ( recurs == Recurrence::rHourly )
198 recurText = i18n("hourly"); 198 recurText = i18n("hourly");
199 else if ( recurs == Recurrence::rDaily ) 199 else if ( recurs == Recurrence::rDaily )
200 recurText = i18n("daily"); 200 recurText = i18n("daily");
201 else if ( recurs == Recurrence::rWeekly ) 201 else if ( recurs == Recurrence::rWeekly )
202 recurText = i18n("weekly"); 202 recurText = i18n("weekly");
203 else if ( recurs == Recurrence::rMonthlyPos ) 203 else if ( recurs == Recurrence::rMonthlyPos )
204 recurText = i18n("monthly"); 204 recurText = i18n("monthly");
205 else if ( recurs == Recurrence::rMonthlyDay ) 205 else if ( recurs == Recurrence::rMonthlyDay )
206 recurText = i18n("day-monthly"); 206 recurText = i18n("day-monthly");
207 else if ( recurs == Recurrence::rYearlyMonth ) 207 else if ( recurs == Recurrence::rYearlyMonth )
208 recurText = i18n("month-yearly"); 208 recurText = i18n("month-yearly");
209 else if ( recurs == Recurrence::rYearlyDay ) 209 else if ( recurs == Recurrence::rYearlyDay )
210 recurText = i18n("day-yearly"); 210 recurText = i18n("day-yearly");
211 else if ( recurs == Recurrence::rYearlyPos ) 211 else if ( recurs == Recurrence::rYearlyPos )
212 recurText = i18n("position-yearly"); 212 recurText = i18n("position-yearly");
213 return recurText; 213 return recurText;
214} 214}
215 215
216void Recurrence::setCompatVersion(int version) 216void Recurrence::setCompatVersion(int version)
217{ 217{
218 mCompatVersion = version ? version : INT_MAX; 218 mCompatVersion = version ? version : INT_MAX;
219} 219}
220 220
221ushort Recurrence::doesRecur() const 221ushort Recurrence::doesRecur() const
222{ 222{
223 return recurs; 223 return recurs;
224} 224}
225 225
226bool Recurrence::recursOnPure(const QDate &qd) const 226bool Recurrence::recursOnPure(const QDate &qd) const
227{ 227{
228 switch(recurs) { 228 switch(recurs) {
229 case rMinutely: 229 case rMinutely:
230 return recursSecondly(qd, rFreq*60); 230 return recursSecondly(qd, rFreq*60);
231 case rHourly: 231 case rHourly:
232 return recursSecondly(qd, rFreq*3600); 232 return recursSecondly(qd, rFreq*3600);
233 case rDaily: 233 case rDaily:
234 return recursDaily(qd); 234 return recursDaily(qd);
235 case rWeekly: 235 case rWeekly:
236 return recursWeekly(qd); 236 return recursWeekly(qd);
237 case rMonthlyPos: 237 case rMonthlyPos:
238 case rMonthlyDay: 238 case rMonthlyDay:
239 return recursMonthly(qd); 239 return recursMonthly(qd);
240 case rYearlyMonth: 240 case rYearlyMonth:
241 return recursYearlyByMonth(qd); 241 return recursYearlyByMonth(qd);
242 case rYearlyDay: 242 case rYearlyDay:
243 return recursYearlyByDay(qd); 243 return recursYearlyByDay(qd);
244 case rYearlyPos: 244 case rYearlyPos:
245 return recursYearlyByPos(qd); 245 return recursYearlyByPos(qd);
246 default: 246 default:
247 return false; 247 return false;
248 case rNone: 248 case rNone:
249 return false; 249 return false;
250 } // case 250 } // case
251 return false; 251 return false;
252} 252}
253 253
254bool Recurrence::recursAtPure(const QDateTime &dt) const 254bool Recurrence::recursAtPure(const QDateTime &dt) const
255{ 255{
256 switch(recurs) { 256 switch(recurs) {
257 case rMinutely: 257 case rMinutely:
258 return recursMinutelyAt(dt, rFreq); 258 return recursMinutelyAt(dt, rFreq);
259 case rHourly: 259 case rHourly:
260 return recursMinutelyAt(dt, rFreq*60); 260 return recursMinutelyAt(dt, rFreq*60);
261 default: 261 default:
262 if (dt.time() != mRecurStart.time()) 262 if (dt.time() != mRecurStart.time())
263 return false; 263 return false;
264 switch(recurs) { 264 switch(recurs) {
265 case rDaily: 265 case rDaily:
266 return recursDaily(dt.date()); 266 return recursDaily(dt.date());
267 case rWeekly: 267 case rWeekly:
268 return recursWeekly(dt.date()); 268 return recursWeekly(dt.date());
269 case rMonthlyPos: 269 case rMonthlyPos:
270 case rMonthlyDay: 270 case rMonthlyDay:
271 return recursMonthly(dt.date()); 271 return recursMonthly(dt.date());
272 case rYearlyMonth: 272 case rYearlyMonth:
273 return recursYearlyByMonth(dt.date()); 273 return recursYearlyByMonth(dt.date());
274 case rYearlyDay: 274 case rYearlyDay:
275 return recursYearlyByDay(dt.date()); 275 return recursYearlyByDay(dt.date());
276 case rYearlyPos: 276 case rYearlyPos:
277 return recursYearlyByPos(dt.date()); 277 return recursYearlyByPos(dt.date());
278 default: 278 default:
279 return false; 279 return false;
280 case rNone: 280 case rNone:
281 return false; 281 return false;
282 } 282 }
283 } // case 283 } // case
284 return false; 284 return false;
285} 285}
286 286
287QDate Recurrence::endDate() const 287QDate Recurrence::endDate() const
288{ 288{
289 int count = 0; 289 int count = 0;
290 QDate end; 290 QDate end;
291 if (recurs != rNone) { 291 if (recurs != rNone) {
292 if (rDuration < 0) 292 if (rDuration < 0)
293 return QDate(); // infinite recurrence 293 return QDate(); // infinite recurrence
294 if (rDuration == 0) 294 if (rDuration == 0)
295 return rEndDateTime.date(); 295 return rEndDateTime.date();
296 296
297 // The end date is determined by the recurrence count 297 // The end date is determined by the recurrence count
298 QDate dStart = mRecurStart.date(); 298 QDate dStart = mRecurStart.date();
299 switch (recurs) 299 switch (recurs)
300 { 300 {
301 case rMinutely: 301 case rMinutely:
302 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date(); 302 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60).date();
303 case rHourly: 303 case rHourly:
304 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date(); 304 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600).date();
305 case rDaily: 305 case rDaily:
306 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); 306 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq);
307 307
308 case rWeekly: 308 case rWeekly:
309 count = weeklyCalc(END_DATE_AND_COUNT, end); 309 count = weeklyCalc(END_DATE_AND_COUNT, end);
310 break; 310 break;
311 case rMonthlyPos: 311 case rMonthlyPos:
312 case rMonthlyDay: 312 case rMonthlyDay:
313 count = monthlyCalc(END_DATE_AND_COUNT, end); 313 count = monthlyCalc(END_DATE_AND_COUNT, end);
314 break; 314 break;
315 case rYearlyMonth: 315 case rYearlyMonth:
316 count = yearlyMonthCalc(END_DATE_AND_COUNT, end); 316 count = yearlyMonthCalc(END_DATE_AND_COUNT, end);
317 break; 317 break;
318 case rYearlyDay: 318 case rYearlyDay:
319 count = yearlyDayCalc(END_DATE_AND_COUNT, end); 319 count = yearlyDayCalc(END_DATE_AND_COUNT, end);
320 break; 320 break;
321 case rYearlyPos: 321 case rYearlyPos:
322 count = yearlyPosCalc(END_DATE_AND_COUNT, end); 322 count = yearlyPosCalc(END_DATE_AND_COUNT, end);
323 break; 323 break;
324 default: 324 default:
325 // catch-all. Should never get here. 325 // catch-all. Should never get here.
326 kdDebug(5800) << "Control should never reach here in endDate()!" << endl; 326 kdDebug(5800) << "Control should never reach here in endDate()!" << endl;
327 break; 327 break;
328 } 328 }
329 } 329 }
330 if (!count) 330 if (!count)
331 return QDate(); // error - there is no recurrence 331 return QDate(); // error - there is no recurrence
332 return end; 332 return end;
333} 333}
334 334
335QDateTime Recurrence::endDateTime() const 335QDateTime Recurrence::endDateTime() const
336{ 336{
337 int count = 0; 337 int count = 0;
338 QDate end; 338 QDate end;
339 if (recurs != rNone) { 339 if (recurs != rNone) {
340 if (rDuration < 0) 340 if (rDuration < 0)
341 return QDateTime(); // infinite recurrence 341 return QDateTime(); // infinite recurrence
342 if (rDuration == 0) 342 if (rDuration == 0)
343 return rEndDateTime; 343 return rEndDateTime;
344 344
345 // The end date is determined by the recurrence count 345 // The end date is determined by the recurrence count
346 QDate dStart = mRecurStart.date(); 346 QDate dStart = mRecurStart.date();
347 switch (recurs) 347 switch (recurs)
348 { 348 {
349 case rMinutely: 349 case rMinutely:
350 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); 350 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60);
351 case rHourly: 351 case rHourly:
352 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); 352 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600);
353 case rDaily: 353 case rDaily:
354 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); 354 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq);
355 355
356 case rWeekly: 356 case rWeekly:
357 count = weeklyCalc(END_DATE_AND_COUNT, end); 357 count = weeklyCalc(END_DATE_AND_COUNT, end);
358 break; 358 break;
359 case rMonthlyPos: 359 case rMonthlyPos:
360 case rMonthlyDay: 360 case rMonthlyDay:
361 count = monthlyCalc(END_DATE_AND_COUNT, end); 361 count = monthlyCalc(END_DATE_AND_COUNT, end);
362 break; 362 break;
363 case rYearlyMonth: 363 case rYearlyMonth:
364 count = yearlyMonthCalc(END_DATE_AND_COUNT, end); 364 count = yearlyMonthCalc(END_DATE_AND_COUNT, end);
365 break; 365 break;
366 case rYearlyDay: 366 case rYearlyDay:
367 count = yearlyDayCalc(END_DATE_AND_COUNT, end); 367 count = yearlyDayCalc(END_DATE_AND_COUNT, end);
368 break; 368 break;
369 case rYearlyPos: 369 case rYearlyPos:
370 count = yearlyPosCalc(END_DATE_AND_COUNT, end); 370 count = yearlyPosCalc(END_DATE_AND_COUNT, end);
371 break; 371 break;
372 default: 372 default:
373 // catch-all. Should never get here. 373 // catch-all. Should never get here.
374 kdDebug(5800) << "Control should never reach here in endDate()!" << endl; 374 kdDebug(5800) << "Control should never reach here in endDate()!" << endl;
375 break; 375 break;
376 } 376 }
377 } 377 }
378 if (!count) 378 if (!count)
379 return QDateTime(); // error - there is no recurrence 379 return QDateTime(); // error - there is no recurrence
380 return QDateTime(end, mRecurStart.time()); 380 return QDateTime(end, mRecurStart.time());
381} 381}
382 382
383int Recurrence::durationTo(const QDate &date) const 383int Recurrence::durationTo(const QDate &date) const
384{ 384{
385 QDate d = date; 385 QDate d = date;
386 return recurCalc(COUNT_TO_DATE, d); 386 return recurCalc(COUNT_TO_DATE, d);
387} 387}
388 388
389int Recurrence::durationTo(const QDateTime &datetime) const 389int Recurrence::durationTo(const QDateTime &datetime) const
390{ 390{
391 QDateTime dt = datetime; 391 QDateTime dt = datetime;
392 return recurCalc(COUNT_TO_DATE, dt); 392 return recurCalc(COUNT_TO_DATE, dt);
393} 393}
394 394
395void Recurrence::unsetRecurs() 395void Recurrence::unsetRecurs()
396{ 396{
397 if (mRecurReadOnly) return; 397 if (mRecurReadOnly) return;
398 recurs = rNone; 398 recurs = rNone;
399 rMonthPositions.clear(); 399 rMonthPositions.clear();
400 rMonthDays.clear(); 400 rMonthDays.clear();
401 rYearNums.clear(); 401 rYearNums.clear();
402} 402}
403 403
404void Recurrence::setRecurStart(const QDateTime &start) 404void Recurrence::setRecurStart(const QDateTime &start)
405{ 405{
406 mRecurStart = start; 406 mRecurStart = start;
407 mFloats = false; 407 mFloats = false;
408 switch (recurs) 408 switch (recurs)
409 { 409 {
410 case rMinutely: 410 case rMinutely:
411 case rHourly: 411 case rHourly:
412 break; 412 break;
413 case rDaily: 413 case rDaily:
414 case rWeekly: 414 case rWeekly:
415 case rMonthlyPos: 415 case rMonthlyPos:
416 case rMonthlyDay: 416 case rMonthlyDay:
417 case rYearlyMonth: 417 case rYearlyMonth:
418 case rYearlyDay: 418 case rYearlyDay:
419 case rYearlyPos: 419 case rYearlyPos:
420 default: 420 default:
421 rEndDateTime.setTime(start.time()); 421 rEndDateTime.setTime(start.time());
422 break; 422 break;
423 } 423 }
424} 424}
425 425
426void Recurrence::setRecurStart(const QDate &start) 426void Recurrence::setRecurStart(const QDate &start)
427{ 427{
428 mRecurStart.setDate(start); 428 mRecurStart.setDate(start);
429 mRecurStart.setTime(QTime(0,0,0)); 429 mRecurStart.setTime(QTime(0,0,0));
430 switch (recurs) 430 switch (recurs)
431 { 431 {
432 case rMinutely: 432 case rMinutely:
433 case rHourly: 433 case rHourly:
434 break; 434 break;
435 case rDaily: 435 case rDaily:
436 case rWeekly: 436 case rWeekly:
437 case rMonthlyPos: 437 case rMonthlyPos:
438 case rMonthlyDay: 438 case rMonthlyDay:
439 case rYearlyMonth: 439 case rYearlyMonth:
440 case rYearlyDay: 440 case rYearlyDay:
441 case rYearlyPos: 441 case rYearlyPos:
442 default: 442 default:
443 mFloats = true; 443 mFloats = true;
444 break; 444 break;
445 } 445 }
446} 446}
447 447
448void Recurrence::setFloats(bool f) 448void Recurrence::setFloats(bool f)
449{ 449{
450 switch (recurs) 450 switch (recurs)
451 { 451 {
452 case rDaily: 452 case rDaily:
453 case rWeekly: 453 case rWeekly:
454 case rMonthlyPos: 454 case rMonthlyPos:
455 case rMonthlyDay: 455 case rMonthlyDay:
456 case rYearlyMonth: 456 case rYearlyMonth:
457 case rYearlyDay: 457 case rYearlyDay:
458 case rYearlyPos: 458 case rYearlyPos:
459 break; 459 break;
460 case rMinutely: 460 case rMinutely:
461 case rHourly: 461 case rHourly:
462 default: 462 default:
463 return; // can't set sub-daily to floating 463 return; // can't set sub-daily to floating
464 } 464 }
465 mFloats = f; 465 mFloats = f;
466 if (f) { 466 if (f) {
467 mRecurStart.setTime(QTime(0,0,0)); 467 mRecurStart.setTime(QTime(0,0,0));
468 rEndDateTime.setTime(QTime(0,0,0)); 468 rEndDateTime.setTime(QTime(0,0,0));
469 } 469 }
470} 470}
471 471
472int Recurrence::frequency() const 472int Recurrence::frequency() const
473{ 473{
474 return rFreq; 474 return rFreq;
475} 475}
476 476
477int Recurrence::duration() const 477int Recurrence::duration() const
478{ 478{
479 return rDuration; 479 return rDuration;
480} 480}
481 481
482void Recurrence::setDuration(int _rDuration) 482void Recurrence::setDuration(int _rDuration)
483{ 483{
484 if (mRecurReadOnly) return; 484 if (mRecurReadOnly) return;
485 if (_rDuration > 0) { 485 if (_rDuration > 0) {
486 rDuration = _rDuration; 486 rDuration = _rDuration;
487 // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, 487 // Compatibility mode is only needed when reading the calendar in ICalFormatImpl,
488 // so explicitly setting the duration means no backwards compatibility is needed. 488 // so explicitly setting the duration means no backwards compatibility is needed.
489 mCompatDuration = 0; 489 mCompatDuration = 0;
490 } 490 }
491} 491}
492 492
493QString Recurrence::endDateStr(bool shortfmt) const 493QString Recurrence::endDateStr(bool shortfmt) const
494{ 494{
495 return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); 495 return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt);
496} 496}
497 497
498const QBitArray &Recurrence::days() const 498const QBitArray &Recurrence::days() const
499{ 499{
500 return rDays; 500 return rDays;
501} 501}
502 502
503const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const 503const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const
504{ 504{
505 return rMonthPositions; 505 return rMonthPositions;
506} 506}
507 507
508const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const 508const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const
509{ 509{
510 return rMonthPositions; 510 return rMonthPositions;
511} 511}
512 512
513const QPtrList<int> &Recurrence::monthDays() const 513const QPtrList<int> &Recurrence::monthDays() const
514{ 514{
515 return rMonthDays; 515 return rMonthDays;
516} 516}
517 517
518void Recurrence::setMinutely(int _rFreq, int _rDuration) 518void Recurrence::setMinutely(int _rFreq, int _rDuration)
519{ 519{
520 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 520 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
521 return; 521 return;
522 setDailySub(rMinutely, _rFreq, _rDuration); 522 setDailySub(rMinutely, _rFreq, _rDuration);
523} 523}
524 524
525void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) 525void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime)
526{ 526{
527 if (mRecurReadOnly) return; 527 if (mRecurReadOnly) return;
528 rEndDateTime = _rEndDateTime; 528 rEndDateTime = _rEndDateTime;
529 setDailySub(rMinutely, _rFreq, 0); 529 setDailySub(rMinutely, _rFreq, 0);
530} 530}
531 531
532void Recurrence::setHourly(int _rFreq, int _rDuration) 532void Recurrence::setHourly(int _rFreq, int _rDuration)
533{ 533{
534 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 534 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
535 return; 535 return;
536 setDailySub(rHourly, _rFreq, _rDuration); 536 setDailySub(rHourly, _rFreq, _rDuration);
537} 537}
538 538
539void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) 539void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime)
540{ 540{
541 if (mRecurReadOnly) return; 541 if (mRecurReadOnly) return;
542 rEndDateTime = _rEndDateTime; 542 rEndDateTime = _rEndDateTime;
543 setDailySub(rHourly, _rFreq, 0); 543 setDailySub(rHourly, _rFreq, 0);
544} 544}
545 545
546void Recurrence::setDaily(int _rFreq, int _rDuration) 546void Recurrence::setDaily(int _rFreq, int _rDuration)
547{ 547{
548 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 548 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
549 return; 549 return;
550 setDailySub(rDaily, _rFreq, _rDuration); 550 setDailySub(rDaily, _rFreq, _rDuration);
551} 551}
552 552
553void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) 553void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate)
554{ 554{
555 if (mRecurReadOnly) return; 555 if (mRecurReadOnly) return;
556 rEndDateTime.setDate(_rEndDate); 556 rEndDateTime.setDate(_rEndDate);
557 rEndDateTime.setTime(mRecurStart.time()); 557 rEndDateTime.setTime(mRecurStart.time());
558 setDailySub(rDaily, _rFreq, 0); 558 setDailySub(rDaily, _rFreq, 0);
559} 559}
560 560
561void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, 561void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays,
562 int _rDuration, int _rWeekStart) 562 int _rDuration, int _rWeekStart)
563{ 563{
564 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 564 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
565 return; 565 return;
566 recurs = rWeekly; 566 recurs = rWeekly;
567 567
568 rFreq = _rFreq; 568 rFreq = _rFreq;
569 rDays = _rDays; 569 rDays = _rDays;
570 rWeekStart = _rWeekStart; 570 rWeekStart = _rWeekStart;
571 rDuration = _rDuration; 571 rDuration = _rDuration;
572 if (mCompatVersion < 310 && _rDuration > 0) { 572 if (mCompatVersion < 310 && _rDuration > 0) {
573 // Backwards compatibility for KDE < 3.1. 573 // Backwards compatibility for KDE < 3.1.
574 // rDuration was set to the number of time periods to recur, 574 // rDuration was set to the number of time periods to recur,
575 // with week start always on a Monday. 575 // with week start always on a Monday.
576 // Convert this to the number of occurrences. 576 // Convert this to the number of occurrences.
577 mCompatDuration = _rDuration; 577 mCompatDuration = _rDuration;
578 int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); 578 int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek());
579 QDate end(mRecurStart.date().addDays(weeks * rFreq)); 579 QDate end(mRecurStart.date().addDays(weeks * rFreq));
580 rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly 580 rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly
581 rDuration = weeklyCalc(COUNT_TO_DATE, end); 581 rDuration = weeklyCalc(COUNT_TO_DATE, end);
582 } else { 582 } else {
583 mCompatDuration = 0; 583 mCompatDuration = 0;
584 } 584 }
585 rMonthPositions.clear(); 585 rMonthPositions.clear();
586 rMonthDays.clear(); 586 rMonthDays.clear();
587 if (mParent) mParent->updated(); 587 if (mParent) mParent->updated();
588} 588}
589 589
590void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, 590void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays,
591 const QDate &_rEndDate, int _rWeekStart) 591 const QDate &_rEndDate, int _rWeekStart)
592{ 592{
593 if (mRecurReadOnly) return; 593 if (mRecurReadOnly) return;
594 recurs = rWeekly; 594 recurs = rWeekly;
595 595
596 rFreq = _rFreq; 596 rFreq = _rFreq;
597 rDays = _rDays; 597 rDays = _rDays;
598 rWeekStart = _rWeekStart; 598 rWeekStart = _rWeekStart;
599 rEndDateTime.setDate(_rEndDate); 599 rEndDateTime.setDate(_rEndDate);
600 rEndDateTime.setTime(mRecurStart.time()); 600 rEndDateTime.setTime(mRecurStart.time());
601 rDuration = 0; // set to 0 because there is an end date 601 rDuration = 0; // set to 0 because there is an end date
602 mCompatDuration = 0; 602 mCompatDuration = 0;
603 rMonthPositions.clear(); 603 rMonthPositions.clear();
604 rMonthDays.clear(); 604 rMonthDays.clear();
605 rYearNums.clear(); 605 rYearNums.clear();
606 if (mParent) mParent->updated(); 606 if (mParent) mParent->updated();
607} 607}
608 608
609void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) 609void Recurrence::setMonthly(short type, int _rFreq, int _rDuration)
610{ 610{
611 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 611 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
612 return; 612 return;
613 recurs = type; 613 recurs = type;
614 614
615 rFreq = _rFreq; 615 rFreq = _rFreq;
616 rDuration = _rDuration; 616 rDuration = _rDuration;
617 if (mCompatVersion < 310) 617 if (mCompatVersion < 310)
618 mCompatDuration = (_rDuration > 0) ? _rDuration : 0; 618 mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
619 rYearNums.clear(); 619 rYearNums.clear();
620 if (mParent) mParent->updated(); 620 if (mParent) mParent->updated();
621} 621}
622 622
623void Recurrence::setMonthly(short type, int _rFreq, 623void Recurrence::setMonthly(short type, int _rFreq,
624 const QDate &_rEndDate) 624 const QDate &_rEndDate)
625{ 625{
626 if (mRecurReadOnly) return; 626 if (mRecurReadOnly) return;
627 recurs = type; 627 recurs = type;
628 628
629 rFreq = _rFreq; 629 rFreq = _rFreq;
630 rEndDateTime.setDate(_rEndDate); 630 rEndDateTime.setDate(_rEndDate);
631 rEndDateTime.setTime(mRecurStart.time()); 631 rEndDateTime.setTime(mRecurStart.time());
632 rDuration = 0; // set to 0 because there is an end date 632 rDuration = 0; // set to 0 because there is an end date
633 mCompatDuration = 0; 633 mCompatDuration = 0;
634 rYearNums.clear(); 634 rYearNums.clear();
635 if (mParent) mParent->updated(); 635 if (mParent) mParent->updated();
636} 636}
637 637
638void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) 638void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays)
639{ 639{
640 if (recurs == rMonthlyPos) 640 if (recurs == rMonthlyPos)
641 addMonthlyPos_(_rPos, _rDays); 641 addMonthlyPos_(_rPos, _rDays);
642} 642}
643 643
644void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) 644void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays)
645{ 645{
646 if (mRecurReadOnly 646 if (mRecurReadOnly
647 || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number 647 || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number
648 return; 648 return;
649 649
650 for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { 650 for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) {
651 int itPos = it->negative ? -it->rPos : it->rPos; 651 int itPos = it->negative ? -it->rPos : it->rPos;
652 if (_rPos == itPos) { 652 if (_rPos == itPos) {
653 // This week is already in the list. 653 // This week is already in the list.
654 // Combine the specified days with those in the list. 654 // Combine the specified days with those in the list.
655 it->rDays |= _rDays; 655 it->rDays |= _rDays;
656 if (mParent) mParent->updated(); 656 if (mParent) mParent->updated();
657 return; 657 return;
658 } 658 }
659 } 659 }
660 // Add the new position to the list 660 // Add the new position to the list
661 rMonthPos *tmpPos = new rMonthPos; 661 rMonthPos *tmpPos = new rMonthPos;
662 if (_rPos > 0) { 662 if (_rPos > 0) {
663 tmpPos->rPos = _rPos; 663 tmpPos->rPos = _rPos;
664 tmpPos->negative = false; 664 tmpPos->negative = false;
665 } else { 665 } else {
666 tmpPos->rPos = -_rPos; // take abs() 666 tmpPos->rPos = -_rPos; // take abs()
667 tmpPos->negative = true; 667 tmpPos->negative = true;
668 } 668 }
669 tmpPos->rDays = _rDays; 669 tmpPos->rDays = _rDays;
670 tmpPos->rDays.detach(); 670 tmpPos->rDays.detach();
671 rMonthPositions.append(tmpPos); 671 rMonthPositions.append(tmpPos);
672 672
673 if (mCompatVersion < 310 && mCompatDuration > 0) { 673 if (mCompatVersion < 310 && mCompatDuration > 0) {
674 // Backwards compatibility for KDE < 3.1. 674 // Backwards compatibility for KDE < 3.1.
675 // rDuration was set to the number of time periods to recur. 675 // rDuration was set to the number of time periods to recur.
676 // Convert this to the number of occurrences. 676 // Convert this to the number of occurrences.
677 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; 677 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
678 int month = mRecurStart.date().month() - 1 + monthsAhead; 678 int month = mRecurStart.date().month() - 1 + monthsAhead;
679 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); 679 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
680 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 680 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
681 rDuration = recurCalc(COUNT_TO_DATE, end); 681 rDuration = recurCalc(COUNT_TO_DATE, end);
682 } 682 }
683 683
684 if (mParent) mParent->updated(); 684 if (mParent) mParent->updated();
685} 685}
686 686
687void Recurrence::addMonthlyDay(short _rDay) 687void Recurrence::addMonthlyDay(short _rDay)
688{ 688{
689 if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth) 689 if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth)
690 || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number 690 || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number
691 return; 691 return;
692 for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { 692 for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) {
693 if (_rDay == *it) 693 if (_rDay == *it)
694 return; // this day is already in the list - avoid duplication 694 return; // this day is already in the list - avoid duplication
695 } 695 }
696 int *tmpDay = new int; 696 int *tmpDay = new int;
697 *tmpDay = _rDay; 697 *tmpDay = _rDay;
698 rMonthDays.append(tmpDay); 698 rMonthDays.append(tmpDay);
699 699
700 if (mCompatVersion < 310 && mCompatDuration > 0) { 700 if (mCompatVersion < 310 && mCompatDuration > 0) {
701 // Backwards compatibility for KDE < 3.1. 701 // Backwards compatibility for KDE < 3.1.
702 // rDuration was set to the number of time periods to recur. 702 // rDuration was set to the number of time periods to recur.
703 // Convert this to the number of occurrences. 703 // Convert this to the number of occurrences.
704 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; 704 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
705 int month = mRecurStart.date().month() - 1 + monthsAhead; 705 int month = mRecurStart.date().month() - 1 + monthsAhead;
706 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); 706 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
707 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 707 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
708 rDuration = recurCalc(COUNT_TO_DATE, end); 708 rDuration = recurCalc(COUNT_TO_DATE, end);
709 } 709 }
710 710
711 if (mParent) mParent->updated(); 711 if (mParent) mParent->updated();
712} 712}
713 713
714void Recurrence::setYearly(int type, int _rFreq, int _rDuration) 714void Recurrence::setYearly(int type, int _rFreq, int _rDuration)
715{ 715{
716 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 716 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
717 return; 717 return;
718 if (mCompatVersion < 310) 718 if (mCompatVersion < 310)
719 mCompatDuration = (_rDuration > 0) ? _rDuration : 0; 719 mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
720 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); 720 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration);
721} 721}
722 722
723void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) 723void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate)
724{ 724{
725 if (mRecurReadOnly) return; 725 if (mRecurReadOnly) return;
726 rEndDateTime.setDate(_rEndDate); 726 rEndDateTime.setDate(_rEndDate);
727 rEndDateTime.setTime(mRecurStart.time()); 727 rEndDateTime.setTime(mRecurStart.time());
728 mCompatDuration = 0; 728 mCompatDuration = 0;
729 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); 729 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0);
730} 730}
731 731
732void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) 732void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration)
733{ 733{
734 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 734 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
735 return; 735 return;
736 if (mCompatVersion < 310) 736 if (mCompatVersion < 310)
737 mCompatDuration = (_rDuration > 0) ? _rDuration : 0; 737 mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
738 setYearly_(rYearlyMonth, type, _rFreq, _rDuration); 738 setYearly_(rYearlyMonth, type, _rFreq, _rDuration);
739} 739}
740 740
741void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) 741void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate)
742{ 742{
743 if (mRecurReadOnly) return; 743 if (mRecurReadOnly) return;
744 rEndDateTime.setDate(_rEndDate); 744 rEndDateTime.setDate(_rEndDate);
745 rEndDateTime.setTime(mRecurStart.time()); 745 rEndDateTime.setTime(mRecurStart.time());
746 mCompatDuration = 0; 746 mCompatDuration = 0;
747 setYearly_(rYearlyMonth, type, _rFreq, 0); 747 setYearly_(rYearlyMonth, type, _rFreq, 0);
748} 748}
749 749
750void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) 750void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays)
751{ 751{
752 if (recurs == rYearlyPos) 752 if (recurs == rYearlyPos)
753 addMonthlyPos_(_rPos, _rDays); 753 addMonthlyPos_(_rPos, _rDays);
754} 754}
755 755
756const QPtrList<int> &Recurrence::yearNums() const 756const QPtrList<int> &Recurrence::yearNums() const
757{ 757{
758 return rYearNums; 758 return rYearNums;
759} 759}
760void Recurrence::addYearlyMonth(short _rPos ) 760void Recurrence::addYearlyMonth(short _rPos )
761{ 761{
762 if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number 762 if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number
763 return; 763 return;
764 rMonthPos *tmpPos = new rMonthPos; 764 rMonthPos *tmpPos = new rMonthPos;
765 if ( _rPos > 0) { 765 if ( _rPos > 0) {
766 tmpPos->rPos = _rPos; 766 tmpPos->rPos = _rPos;
767 tmpPos->negative = false; 767 tmpPos->negative = false;
768 } else { 768 } else {
769 tmpPos->rPos = -_rPos; // take abs() 769 tmpPos->rPos = -_rPos; // take abs()
770 tmpPos->negative = true; 770 tmpPos->negative = true;
771 } 771 }
772 rMonthPositions.append(tmpPos); 772 rMonthPositions.append(tmpPos);
773} 773}
774void Recurrence::addYearlyNum(short _rNum) 774void Recurrence::addYearlyNum(short _rNum)
775{ 775{
776 if (mRecurReadOnly 776 if (mRecurReadOnly
777 || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) 777 || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos)
778 || _rNum <= 0) // invalid day/month number 778 || _rNum <= 0) // invalid day/month number
779 return; 779 return;
780 780
781 if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { 781 if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) {
782 // Backwards compatibility for KDE < 3.1. 782 // Backwards compatibility for KDE < 3.1.
783 // Dates were stored as day numbers, with a fiddle to take account of leap years. 783 // Dates were stored as day numbers, with a fiddle to take account of leap years.
784 // Convert the day number to a month. 784 // Convert the day number to a month.
785 if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) 785 if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366))
786 return; // invalid day number 786 return; // invalid day number
787 _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); 787 _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month();
788 } else 788 } else
789 if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 789 if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12
790 || recurs == rYearlyDay && _rNum > 366) 790 || recurs == rYearlyDay && _rNum > 366)
791 return; // invalid day number 791 return; // invalid day number
792 792
793 uint i = 0; 793 uint i = 0;
794 for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { 794 for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) {
795 if (_rNum == *it) 795 if (_rNum == *it)
796 return; // this day/month is already in the list - avoid duplication 796 return; // this day/month is already in the list - avoid duplication
797 ++i; 797 ++i;
798 } 798 }
799 799
800 int *tmpNum = new int; 800 int *tmpNum = new int;
801 *tmpNum = _rNum; 801 *tmpNum = _rNum;
802 rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position 802 rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position
803 803
804 if (mCompatVersion < 310 && mCompatDuration > 0) { 804 if (mCompatVersion < 310 && mCompatDuration > 0) {
805 // Backwards compatibility for KDE < 3.1. 805 // Backwards compatibility for KDE < 3.1.
806 // rDuration was set to the number of time periods to recur. 806 // rDuration was set to the number of time periods to recur.
807 // Convert this to the number of occurrences. 807 // Convert this to the number of occurrences.
808 QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); 808 QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31);
809 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 809 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
810 rDuration = recurCalc(COUNT_TO_DATE, end); 810 rDuration = recurCalc(COUNT_TO_DATE, end);
811 } 811 }
812 812
813 if (mParent) mParent->updated(); 813 if (mParent) mParent->updated();
814} 814}
815 815
816 816
817QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const 817QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const
818{ 818{
819 if (last) 819 if (last)
820 *last = false; 820 *last = false;
821 int freq; 821 int freq;
822 switch (recurs) 822 switch (recurs)
823 { 823 {
824 case rMinutely: 824 case rMinutely:
825 freq = rFreq * 60; 825 freq = rFreq * 60;
826 break; 826 break;
827 case rHourly: 827 case rHourly:
828 freq = rFreq * 3600; 828 freq = rFreq * 3600;
829 break; 829 break;
830 case rDaily: 830 case rDaily:
831 case rWeekly: 831 case rWeekly:
832 case rMonthlyPos: 832 case rMonthlyPos:
833 case rMonthlyDay: 833 case rMonthlyDay:
834 case rYearlyMonth: 834 case rYearlyMonth:
835 case rYearlyDay: 835 case rYearlyDay:
836 case rYearlyPos: { 836 case rYearlyPos: {
837 QDate preDate = preDateTime.date(); 837 QDate preDate = preDateTime.date();
838 if (!mFloats && mRecurStart.time() > preDateTime.time()) 838 if (!mFloats && mRecurStart.time() > preDateTime.time())
839 preDate = preDate.addDays(-1); 839 preDate = preDate.addDays(-1);
840 return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); 840 return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time());
841 } 841 }
842 default: 842 default:
843 return QDateTime(); 843 return QDateTime();
844 } 844 }
845 845
846 // It's a sub-daily recurrence 846 // It's a sub-daily recurrence
847 if (preDateTime < mRecurStart) 847 if (preDateTime < mRecurStart)
848 return mRecurStart; 848 return mRecurStart;
849 int count = mRecurStart.secsTo(preDateTime) / freq + 2; 849 int count = mRecurStart.secsTo(preDateTime) / freq + 2;
850 if (rDuration > 0) { 850 if (rDuration > 0) {
851 if (count > rDuration) 851 if (count > rDuration)
852 return QDateTime(); 852 return QDateTime();
853 if (last && count == rDuration) 853 if (last && count == rDuration)
854 *last = true; 854 *last = true;
855 } 855 }
856 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); 856 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq);
857 if (rDuration == 0) { 857 if (rDuration == 0) {
858 if (endtime > rEndDateTime) 858 if (endtime > rEndDateTime)
859 return QDateTime(); 859 return QDateTime();
860 if (last && endtime == rEndDateTime) 860 if (last && endtime == rEndDateTime)
861 *last = true; 861 *last = true;
862 } 862 }
863 return endtime; 863 return endtime;
864} 864}
865 865
866QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const 866QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const
867{ 867{
868 if (last) 868 if (last)
869 *last = false; 869 *last = false;
870 switch (recurs) 870 switch (recurs)
871 { 871 {
872 case rMinutely: 872 case rMinutely:
873 case rHourly: 873 case rHourly:
874 return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); 874 return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date();
875 case rDaily: 875 case rDaily:
876 case rWeekly: 876 case rWeekly:
877 case rMonthlyPos: 877 case rMonthlyPos:
878 case rMonthlyDay: 878 case rMonthlyDay:
879 case rYearlyMonth: 879 case rYearlyMonth:
880 case rYearlyDay: 880 case rYearlyDay:
881 case rYearlyPos: 881 case rYearlyPos:
882 qDebug("Recurrence::getNextDate: MAY BE BROKEN ");
882 return getNextDateNoTime(preDate, last); 883 return getNextDateNoTime(preDate, last);
883 default: 884 default:
884 return QDate(); 885 return QDate();
885 } 886 }
886} 887}
887 888
888 889
889QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const 890QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const
890{ 891{
891 if (last) 892 if (last)
892 *last = false; 893 *last = false;
893 int freq; 894 int freq;
894 switch (recurs) 895 switch (recurs)
895 { 896 {
896 case rMinutely: 897 case rMinutely:
897 freq = rFreq * 60; 898 freq = rFreq * 60;
898 break; 899 break;
899 case rHourly: 900 case rHourly:
900 freq = rFreq * 3600; 901 freq = rFreq * 3600;
901 break; 902 break;
902 case rDaily: 903 case rDaily:
903 case rWeekly: 904 case rWeekly:
904 case rMonthlyPos: 905 case rMonthlyPos:
905 case rMonthlyDay: 906 case rMonthlyDay:
906 case rYearlyMonth: 907 case rYearlyMonth:
907 case rYearlyDay: 908 case rYearlyDay:
908 case rYearlyPos: { 909 case rYearlyPos: {
909 QDate afterDate = afterDateTime.date(); 910 QDate afterDate = afterDateTime.date();
910 if (!mFloats && mRecurStart.time() < afterDateTime.time()) 911 if (!mFloats && mRecurStart.time() < afterDateTime.time())
911 afterDate = afterDate.addDays(1); 912 afterDate = afterDate.addDays(1);
912 return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); 913 return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time());
913 } 914 }
914 default: 915 default:
915 return QDateTime(); 916 return QDateTime();
916 } 917 }
917 918
918 // It's a sub-daily recurrence 919 // It's a sub-daily recurrence
919 if (afterDateTime <= mRecurStart) 920 if (afterDateTime <= mRecurStart)
920 return QDateTime(); 921 return QDateTime();
921 int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; 922 int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1;
922 if (rDuration > 0) { 923 if (rDuration > 0) {
923 if (count > rDuration) 924 if (count > rDuration)
924 count = rDuration; 925 count = rDuration;
925 if (last && count == rDuration) 926 if (last && count == rDuration)
926 *last = true; 927 *last = true;
927 } 928 }
928 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); 929 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq);
929 if (rDuration == 0) { 930 if (rDuration == 0) {
930 if (endtime > rEndDateTime) 931 if (endtime > rEndDateTime)
931 endtime = rEndDateTime; 932 endtime = rEndDateTime;
932 if (last && endtime == rEndDateTime) 933 if (last && endtime == rEndDateTime)
933 *last = true; 934 *last = true;
934 } 935 }
935 return endtime; 936 return endtime;
936} 937}
937 938
938QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const 939QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const
939{ 940{
940 if (last) 941 if (last)
941 *last = false; 942 *last = false;
942 switch (recurs) 943 switch (recurs)
943 { 944 {
944 case rMinutely: 945 case rMinutely:
945 case rHourly: 946 case rHourly:
946 return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); 947 return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date();
947 case rDaily: 948 case rDaily:
948 case rWeekly: 949 case rWeekly:
949 case rMonthlyPos: 950 case rMonthlyPos:
950 case rMonthlyDay: 951 case rMonthlyDay:
951 case rYearlyMonth: 952 case rYearlyMonth:
952 case rYearlyDay: 953 case rYearlyDay:
953 case rYearlyPos: 954 case rYearlyPos:
954 return getPreviousDateNoTime(afterDate, last); 955 return getPreviousDateNoTime(afterDate, last);
955 default: 956 default:
956 return QDate(); 957 return QDate();
957 } 958 }
958} 959}
959 960
960 961
961/***************************** PROTECTED FUNCTIONS ***************************/ 962/***************************** PROTECTED FUNCTIONS ***************************/
962 963
963bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const 964bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const
964{ 965{
965 if ((qd >= mRecurStart.date()) && 966 if ((qd >= mRecurStart.date()) &&
966 ((rDuration > 0) && (qd <= endDate()) || 967 ((rDuration > 0) && (qd <= endDate()) ||
967 ((rDuration == 0) && (qd <= rEndDateTime.date())) || 968 ((rDuration == 0) && (qd <= rEndDateTime.date())) ||
968 (rDuration == -1))) { 969 (rDuration == -1))) {
969 // The date queried falls within the range of the event. 970 // The date queried falls within the range of the event.
970 if (secondFreq < 24*3600) 971 if (secondFreq < 24*3600)
971 return true; // the event recurs at least once each day 972 return true; // the event recurs at least once each day
972 int after = mRecurStart.secsTo(QDateTime(qd)); 973 int after = mRecurStart.secsTo(QDateTime(qd));
973 if (after / secondFreq != (after + 24*3600) / secondFreq) 974 if (after / secondFreq != (after + 24*3600) / secondFreq)
974 return true; 975 return true;
975 } 976 }
976 return false; 977 return false;
977} 978}
978 979
979bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const 980bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const
980{ 981{
981 if ((dt >= mRecurStart) && 982 if ((dt >= mRecurStart) &&
982 ((rDuration > 0) && (dt <= endDateTime()) || 983 ((rDuration > 0) && (dt <= endDateTime()) ||
983 ((rDuration == 0) && (dt <= rEndDateTime)) || 984 ((rDuration == 0) && (dt <= rEndDateTime)) ||
984 (rDuration == -1))) { 985 (rDuration == -1))) {
985 // The time queried falls within the range of the event. 986 // The time queried falls within the range of the event.
986 if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) 987 if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0)
987 return true; 988 return true;
988 } 989 }
989 return false; 990 return false;
990} 991}
991 992
992bool Recurrence::recursDaily(const QDate &qd) const 993bool Recurrence::recursDaily(const QDate &qd) const
993{ 994{
994 QDate dStart = mRecurStart.date(); 995 QDate dStart = mRecurStart.date();
995 if ((dStart.daysTo(qd) % rFreq) == 0) { 996 if ((dStart.daysTo(qd) % rFreq) == 0) {
996 // The date is a day which recurs 997 // The date is a day which recurs
997 if (qd >= dStart 998 if (qd >= dStart
998 && ((rDuration > 0 && qd <= endDate()) || 999 && ((rDuration > 0 && qd <= endDate()) ||
999 (rDuration == 0 && qd <= rEndDateTime.date()) || 1000 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1000 rDuration == -1)) { 1001 rDuration == -1)) {
1001 // The date queried falls within the range of the event. 1002 // The date queried falls within the range of the event.
1002 return true; 1003 return true;
1003 } 1004 }
1004 } 1005 }
1005 return false; 1006 return false;
1006} 1007}
1007 1008
1008bool Recurrence::recursWeekly(const QDate &qd) const 1009bool Recurrence::recursWeekly(const QDate &qd) const
1009{ 1010{
1010 QDate dStart = mRecurStart.date(); 1011 QDate dStart = mRecurStart.date();
1011 if ((dStart.daysTo(qd)/7) % rFreq == 0) { 1012 if ((dStart.daysTo(qd)/7) % rFreq == 0) {
1012 // The date is in a week which recurs 1013 // The date is in a week which recurs
1013 if (qd >= dStart 1014 if (qd >= dStart
1014 && ((rDuration > 0 && qd <= endDate()) || 1015 && ((rDuration > 0 && qd <= endDate()) ||
1015 (rDuration == 0 && qd <= rEndDateTime.date()) || 1016 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1016 rDuration == -1)) { 1017 rDuration == -1)) {
1017 // The date queried falls within the range of the event. 1018 // The date queried falls within the range of the event.
1018 // check if the bits set match today. 1019 // check if the bits set match today.
1019 int i = qd.dayOfWeek()-1; 1020 int i = qd.dayOfWeek()-1;
1020 if (rDays.testBit((uint) i)) 1021 if (rDays.testBit((uint) i))
1021 return true; 1022 return true;
1022 } 1023 }
1023 } 1024 }
1024 return false; 1025 return false;
1025} 1026}
1026 1027
1027bool Recurrence::recursMonthly(const QDate &qd) const 1028bool Recurrence::recursMonthly(const QDate &qd) const
1028{ 1029{
1029 QDate dStart = mRecurStart.date(); 1030 QDate dStart = mRecurStart.date();
1030 int year = qd.year(); 1031 int year = qd.year();
1031 int month = qd.month(); 1032 int month = qd.month();
1032 int day = qd.day(); 1033 int day = qd.day();
1033 // calculate how many months ahead this date is from the original 1034 // calculate how many months ahead this date is from the original
1034 // event's date 1035 // event's date
1035 int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); 1036 int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month());
1036 if ((monthsAhead % rFreq) == 0) { 1037 if ((monthsAhead % rFreq) == 0) {
1037 // The date is in a month which recurs 1038 // The date is in a month which recurs
1038 if (qd >= dStart 1039 if (qd >= dStart
1039 && ((rDuration > 0 && qd <= endDate()) || 1040 && ((rDuration > 0 && qd <= endDate()) ||
1040 (rDuration == 0 && qd <= rEndDateTime.date()) || 1041 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1041 rDuration == -1)) { 1042 rDuration == -1)) {
1042 // The date queried falls within the range of the event. 1043 // The date queried falls within the range of the event.
1043 QValueList<int> days; 1044 QValueList<int> days;
1044 int daysInMonth = qd.daysInMonth(); 1045 int daysInMonth = qd.daysInMonth();
1045 if (recurs == rMonthlyDay) 1046 if (recurs == rMonthlyDay)
1046 getMonthlyDayDays(days, daysInMonth); 1047 getMonthlyDayDays(days, daysInMonth);
1047 else if (recurs == rMonthlyPos) 1048 else if (recurs == rMonthlyPos)
1048 getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); 1049 getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek());
1049 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { 1050 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) {
1050 if (*it == day) 1051 if (*it == day)
1051 return true; 1052 return true;
1052 } 1053 }
1053 // no dates matched 1054 // no dates matched
1054 } 1055 }
1055 } 1056 }
1056 return false; 1057 return false;
1057} 1058}
1058 1059
1059bool Recurrence::recursYearlyByMonth(const QDate &qd) const 1060bool Recurrence::recursYearlyByMonth(const QDate &qd) const
1060{ 1061{
1061 QDate dStart = mRecurStart.date(); 1062 QDate dStart = mRecurStart.date();
1062 int startDay = dStart.day(); 1063 int startDay = dStart.day();
1063 int qday = qd.day(); 1064 int qday = qd.day();
1064 int qmonth = qd.month(); 1065 int qmonth = qd.month();
1065 int qyear = qd.year(); 1066 int qyear = qd.year();
1066 bool match = (qday == startDay); 1067 bool match = (qday == startDay);
1067 if (!match && startDay == 29 && dStart.month() == 2) { 1068 if (!match && startDay == 29 && dStart.month() == 2) {
1068 // It's a recurrence on February 29th 1069 // It's a recurrence on February 29th
1069 switch (mFeb29YearlyType) { 1070 switch (mFeb29YearlyType) {
1070 case rFeb28: 1071 case rFeb28:
1071 if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) 1072 if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear))
1072 match = true; 1073 match = true;
1073 break; 1074 break;
1074 case rMar1: 1075 case rMar1:
1075 if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { 1076 if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) {
1076 qmonth = 2; 1077 qmonth = 2;
1077 match = true; 1078 match = true;
1078 } 1079 }
1079 break; 1080 break;
1080 case rFeb29: 1081 case rFeb29:
1081 break; 1082 break;
1082 } 1083 }
1083 } 1084 }
1084 1085
1085 if (match) { 1086 if (match) {
1086 // The day of the month matches. Calculate how many years ahead 1087 // The day of the month matches. Calculate how many years ahead
1087 // this date is from the original event's date. 1088 // this date is from the original event's date.
1088 int yearsAhead = (qyear - dStart.year()); 1089 int yearsAhead = (qyear - dStart.year());
1089 if (yearsAhead % rFreq == 0) { 1090 if (yearsAhead % rFreq == 0) {
1090 // The date is in a year which recurs 1091 // The date is in a year which recurs
1091 if (qd >= dStart 1092 if (qd >= dStart
1092 && ((rDuration > 0 && qd <= endDate()) || 1093 && ((rDuration > 0 && qd <= endDate()) ||
1093 (rDuration == 0 && qd <= rEndDateTime.date()) || 1094 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1094 rDuration == -1)) { 1095 rDuration == -1)) {
1095 // The date queried falls within the range of the event. 1096 // The date queried falls within the range of the event.
1096 int i = qmonth; 1097 int i = qmonth;
1097 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { 1098 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) {
1098 if (i == *qlin.current()) 1099 if (i == *qlin.current())
1099 return true; 1100 return true;
1100 } 1101 }
1101 } 1102 }
1102 } 1103 }
1103 } 1104 }
1104 return false; 1105 return false;
1105} 1106}
1106 1107
1107bool Recurrence::recursYearlyByPos(const QDate &qd) const 1108bool Recurrence::recursYearlyByPos(const QDate &qd) const
1108{ 1109{
1109 QDate dStart = mRecurStart.date(); 1110 QDate dStart = mRecurStart.date();
1110 int year = qd.year(); 1111 int year = qd.year();
1111 int month = qd.month(); 1112 int month = qd.month();
1112 int day = qd.day(); 1113 int day = qd.day();
1113 // calculate how many years ahead this date is from the original 1114 // calculate how many years ahead this date is from the original
1114 // event's date 1115 // event's date
1115 int yearsAhead = (year - dStart.year()); 1116 int yearsAhead = (year - dStart.year());
1116 if (yearsAhead % rFreq == 0) { 1117 if (yearsAhead % rFreq == 0) {
1117 // The date is in a year which recurs 1118 // The date is in a year which recurs
1118 if (qd >= dStart 1119 if (qd >= dStart
1119 && ((rDuration > 0 && qd <= endDate()) || 1120 && ((rDuration > 0 && qd <= endDate()) ||
1120 (rDuration == 0 && qd <= rEndDateTime.date()) || 1121 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1121 rDuration == -1)) { 1122 rDuration == -1)) {
1122 // The date queried falls within the range of the event. 1123 // The date queried falls within the range of the event.
1123 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { 1124 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) {
1124 if (month == *qlin.current()) { 1125 if (month == *qlin.current()) {
1125 // The month recurs 1126 // The month recurs
1126 QValueList<int> days; 1127 QValueList<int> days;
1127 getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); 1128 getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek());
1128 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { 1129 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) {
1129 if (*it == day) 1130 if (*it == day)
1130 return true; 1131 return true;
1131 } 1132 }
1132 } 1133 }
1133 } 1134 }
1134 } 1135 }
1135 } 1136 }
1136 return false; 1137 return false;
1137} 1138}
1138 1139
1139bool Recurrence::recursYearlyByDay(const QDate &qd) const 1140bool Recurrence::recursYearlyByDay(const QDate &qd) const
1140{ 1141{
1141 QDate dStart = mRecurStart.date(); 1142 QDate dStart = mRecurStart.date();
1142 // calculate how many years ahead this date is from the original 1143 // calculate how many years ahead this date is from the original
1143 // event's date 1144 // event's date
1144 int yearsAhead = (qd.year() - dStart.year()); 1145 int yearsAhead = (qd.year() - dStart.year());
1145 if (yearsAhead % rFreq == 0) { 1146 if (yearsAhead % rFreq == 0) {
1146 // The date is in a year which recurs 1147 // The date is in a year which recurs
1147 if (qd >= dStart 1148 if (qd >= dStart
1148 && ((rDuration > 0 && qd <= endDate()) || 1149 && ((rDuration > 0 && qd <= endDate()) ||
1149 (rDuration == 0 && qd <= rEndDateTime.date()) || 1150 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1150 rDuration == -1)) { 1151 rDuration == -1)) {
1151 // The date queried falls within the range of the event. 1152 // The date queried falls within the range of the event.
1152 int i = qd.dayOfYear(); 1153 int i = qd.dayOfYear();
1153 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { 1154 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) {
1154 if (i == *qlin.current()) 1155 if (i == *qlin.current())
1155 return true; 1156 return true;
1156 } 1157 }
1157 } 1158 }
1158 } 1159 }
1159 return false; 1160 return false;
1160} 1161}
1161 1162
1162/* Get the date of the next recurrence, after the specified date. 1163/* Get the date of the next recurrence, after the specified date.
1163 * If 'last' is non-null, '*last' is set to true if the next recurrence is the 1164 * If 'last' is non-null, '*last' is set to true if the next recurrence is the
1164 * last recurrence, else false. 1165 * last recurrence, else false.
1165 * Reply = date of next recurrence, or invalid date if none. 1166 * Reply = date of next recurrence, or invalid date if none.
1166 */ 1167 */
1167QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const 1168QDate Recurrence::getNextDateNoTime(const QDate &preDate, bool *last) const
1168{ 1169{
1170
1169 if (last) 1171 if (last)
1170 *last = false; 1172 *last = false;
1171 QDate dStart = mRecurStart.date(); 1173 QDate dStart = mRecurStart.date();
1172 if (preDate < dStart) 1174 if (preDate < dStart)
1173 return dStart; 1175 return dStart;
1174 QDate earliestDate = preDate.addDays(1); 1176 QDate earliestDate = preDate.addDays(1);
1175 QDate nextDate; 1177 QDate nextDate;
1176 1178
1177 switch (recurs) { 1179 switch (recurs) {
1178 case rDaily: 1180 case rDaily:
1179 nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq); 1181 nextDate = dStart.addDays((dStart.daysTo(preDate)/rFreq + 1) * rFreq);
1180 break; 1182 break;
1181 1183
1182 case rWeekly: { 1184 case rWeekly: {
1183 QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart 1185 QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart
1184 int earliestDayOfWeek = earliestDate.dayOfWeek(); 1186 int earliestDayOfWeek = earliestDate.dayOfWeek();
1185 int weeksAhead = start.daysTo(earliestDate) / 7; 1187 int weeksAhead = start.daysTo(earliestDate) / 7;
1186 int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week 1188 int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week
1187 weeksAhead -= notThisWeek; // latest week which recurred 1189 weeksAhead -= notThisWeek; // latest week which recurred
1188 int weekday = 0; 1190 int weekday = 0;
1189 // First check for any remaining day this week, if this week is a recurring week 1191 // First check for any remaining day this week, if this week is a recurring week
1190 if (!notThisWeek) 1192 if (!notThisWeek)
1191 weekday = getFirstDayInWeek(earliestDayOfWeek); 1193 weekday = getFirstDayInWeek(earliestDayOfWeek);
1192 // Check for a day in the next scheduled week 1194 // Check for a day in the next scheduled week
1193 if (!weekday && earliestDayOfWeek > 1) 1195 if (!weekday && earliestDayOfWeek > 1)
1194 weekday = getFirstDayInWeek(rWeekStart) + rFreq*7; 1196 weekday = getFirstDayInWeek(rWeekStart) + rFreq*7;
1195 if (weekday) 1197 if (weekday)
1196 nextDate = start.addDays(weeksAhead*7 + weekday - 1); 1198 nextDate = start.addDays(weeksAhead*7 + weekday - 1);
1197 break; 1199 break;
1198 } 1200 }
1199 case rMonthlyDay: 1201 case rMonthlyDay:
1200 case rMonthlyPos: { 1202 case rMonthlyPos: {
1201 int startYear = dStart.year(); 1203 int startYear = dStart.year();
1202 int startMonth = dStart.month(); // 1..12 1204 int startMonth = dStart.month(); // 1..12
1203 int earliestYear = earliestDate.year(); 1205 int earliestYear = earliestDate.year();
1204 int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth; 1206 int monthsAhead = (earliestYear - startYear)*12 + earliestDate.month() - startMonth;
1205 int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month 1207 int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month
1206 monthsAhead -= notThisMonth; // latest month which recurred 1208 monthsAhead -= notThisMonth; // latest month which recurred
1207 // Check for the first later day in the current month 1209 // Check for the first later day in the current month
1208 if (!notThisMonth) 1210 if (!notThisMonth)
1209 nextDate = getFirstDateInMonth(earliestDate); 1211 nextDate = getFirstDateInMonth(earliestDate);
1210 if (!nextDate.isValid() && earliestDate.day() > 1) { 1212 if (!nextDate.isValid() && earliestDate.day() > 1) {
1211 // Check for a day in the next scheduled month 1213 // Check for a day in the next scheduled month
1212 int months = startMonth - 1 + monthsAhead + rFreq; 1214 int months = startMonth - 1 + monthsAhead + rFreq;
1213 nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1)); 1215 nextDate = getFirstDateInMonth(QDate(startYear + months/12, months%12 + 1, 1));
1214 } 1216 }
1215 break; 1217 break;
1216 } 1218 }
1217 case rYearlyMonth: 1219 case rYearlyMonth:
1218 case rYearlyPos: 1220 case rYearlyPos:
1219 case rYearlyDay: { 1221 case rYearlyDay: {
1220 int startYear = dStart.year(); 1222 int startYear = dStart.year();
1221 int yearsAhead = earliestDate.year() - startYear; 1223 int yearsAhead = earliestDate.year() - startYear;
1222 int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year 1224 int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year
1223 yearsAhead -= notThisYear; // latest year which recurred 1225 yearsAhead -= notThisYear; // latest year which recurred
1224 // Check for the first later date in the current year 1226 // Check for the first later date in the current year
1225 if (!notThisYear) 1227 if (!notThisYear)
1226 nextDate = getFirstDateInYear(earliestDate); 1228 nextDate = getFirstDateInYear(earliestDate);
1227 // Check for a date in the next scheduled year 1229 // Check for a date in the next scheduled year
1228 if (!nextDate.isValid() && earliestDate.dayOfYear() > 1) 1230 if (!nextDate.isValid() && earliestDate.dayOfYear() > 1)
1229 nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1)); 1231 nextDate = getFirstDateInYear(QDate(startYear + yearsAhead + rFreq, 1, 1));
1230 break; 1232 break;
1231 } 1233 }
1232 case rNone: 1234 case rNone:
1233 default: 1235 default:
1234 return QDate(); 1236 return QDate();
1235 } 1237 }
1236 1238
1237 if (rDuration >= 0 && nextDate.isValid()) { 1239 if (rDuration >= 0 && nextDate.isValid()) {
1238 // Check that the date found is within the range of the recurrence 1240 // Check that the date found is within the range of the recurrence
1239 QDate end = endDate(); 1241 QDate end = endDate();
1240 if (nextDate > end) 1242 if (nextDate > end)
1241 return QDate(); 1243 return QDate();
1242 if (last && nextDate == end) 1244 if (last && nextDate == end)
1243 *last = true; 1245 *last = true;
1244 } 1246 }
1245 return nextDate; 1247 return nextDate;
1246} 1248}
1247 1249
1248/* Get the date of the last previous recurrence, before the specified date. 1250/* Get the date of the last previous recurrence, before the specified date.
1249 * Reply = date of previous recurrence, or invalid date if none. 1251 * Reply = date of previous recurrence, or invalid date if none.
1250 */ 1252 */
1251QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const 1253QDate Recurrence::getPreviousDateNoTime(const QDate &afterDate, bool *last) const
1252{ 1254{
1253 if (last) 1255 if (last)
1254 *last = false; 1256 *last = false;
1255 QDate dStart = mRecurStart.date(); 1257 QDate dStart = mRecurStart.date();
1256 QDate latestDate = afterDate.addDays(-1); 1258 QDate latestDate = afterDate.addDays(-1);
1257 if (latestDate < dStart) 1259 if (latestDate < dStart)
1258 return QDate(); 1260 return QDate();
1259 QDate prevDate; 1261 QDate prevDate;
1260 1262
1261 switch (recurs) { 1263 switch (recurs) {
1262 case rDaily: 1264 case rDaily:
1263 prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq); 1265 prevDate = dStart.addDays((dStart.daysTo(latestDate) / rFreq) * rFreq);
1264 break; 1266 break;
1265 1267
1266 case rWeekly: { 1268 case rWeekly: {
1267 QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart 1269 QDate start = dStart.addDays(1 - dStart.dayOfWeek()); // start of week for dStart
1268 int latestDayOfWeek = latestDate.dayOfWeek(); 1270 int latestDayOfWeek = latestDate.dayOfWeek();
1269 int weeksAhead = start.daysTo(latestDate) / 7; 1271 int weeksAhead = start.daysTo(latestDate) / 7;
1270 int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week 1272 int notThisWeek = weeksAhead % rFreq; // zero if this week is a recurring week
1271 weeksAhead -= notThisWeek; // latest week which recurred 1273 weeksAhead -= notThisWeek; // latest week which recurred
1272 int weekday = 0; 1274 int weekday = 0;
1273 // First check for any previous day this week, if this week is a recurring week 1275 // First check for any previous day this week, if this week is a recurring week
1274 if (!notThisWeek) 1276 if (!notThisWeek)
1275 weekday = getLastDayInWeek(latestDayOfWeek); 1277 weekday = getLastDayInWeek(latestDayOfWeek);
1276 // Check for a day in the previous scheduled week 1278 // Check for a day in the previous scheduled week
1277 if (!weekday) { 1279 if (!weekday) {
1278 int weekEnd = (rWeekStart + 5)%7 + 1; 1280 int weekEnd = (rWeekStart + 5)%7 + 1;
1279 if (latestDayOfWeek < weekEnd) { 1281 if (latestDayOfWeek < weekEnd) {
1280 if (!notThisWeek) 1282 if (!notThisWeek)
1281 weeksAhead -= rFreq; 1283 weeksAhead -= rFreq;
1282 weekday = getLastDayInWeek(weekEnd); 1284 weekday = getLastDayInWeek(weekEnd);
1283 } 1285 }
1284 } 1286 }
1285 if (weekday) 1287 if (weekday)
1286 prevDate = start.addDays(weeksAhead*7 + weekday - 1); 1288 prevDate = start.addDays(weeksAhead*7 + weekday - 1);
1287 break; 1289 break;
1288 } 1290 }
1289 case rMonthlyDay: 1291 case rMonthlyDay:
1290 case rMonthlyPos: { 1292 case rMonthlyPos: {
1291 int startYear = dStart.year(); 1293 int startYear = dStart.year();
1292 int startMonth = dStart.month(); // 1..12 1294 int startMonth = dStart.month(); // 1..12
1293 int latestYear = latestDate.year(); 1295 int latestYear = latestDate.year();
1294 int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth; 1296 int monthsAhead = (latestYear - startYear)*12 + latestDate.month() - startMonth;
1295 int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month 1297 int notThisMonth = monthsAhead % rFreq; // zero if this month is a recurring month
1296 monthsAhead -= notThisMonth; // latest month which recurred 1298 monthsAhead -= notThisMonth; // latest month which recurred
1297 // Check for the last earlier day in the current month 1299 // Check for the last earlier day in the current month
1298 if (!notThisMonth) 1300 if (!notThisMonth)
1299 prevDate = getLastDateInMonth(latestDate); 1301 prevDate = getLastDateInMonth(latestDate);
1300 if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) { 1302 if (!prevDate.isValid() && latestDate.day() < latestDate.daysInMonth()) {
1301 // Check for a day in the previous scheduled month 1303 // Check for a day in the previous scheduled month
1302 if (!notThisMonth) 1304 if (!notThisMonth)
1303 monthsAhead -= rFreq; 1305 monthsAhead -= rFreq;
1304 int months = startMonth + monthsAhead; // get the month after the one that recurs 1306 int months = startMonth + monthsAhead; // get the month after the one that recurs
1305 prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1)); 1307 prevDate = getLastDateInMonth(QDate(startYear + months/12, months%12 + 1, 1).addDays(-1));
1306 } 1308 }
1307 break; 1309 break;
1308 } 1310 }
1309 case rYearlyMonth: 1311 case rYearlyMonth:
1310 case rYearlyPos: 1312 case rYearlyPos:
1311 case rYearlyDay: { 1313 case rYearlyDay: {
1312 int startYear = dStart.year(); 1314 int startYear = dStart.year();
1313 int yearsAhead = latestDate.year() - startYear; 1315 int yearsAhead = latestDate.year() - startYear;
1314 int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year 1316 int notThisYear = yearsAhead % rFreq; // zero if this year is a recurring year
1315 yearsAhead -= notThisYear; // latest year which recurred 1317 yearsAhead -= notThisYear; // latest year which recurred
1316 // Check for the first later date in the current year 1318 // Check for the first later date in the current year
1317 if (!notThisYear) 1319 if (!notThisYear)
1318 prevDate = getLastDateInYear(latestDate); 1320 prevDate = getLastDateInYear(latestDate);
1319 if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) { 1321 if (!prevDate.isValid() && latestDate.dayOfYear() < latestDate.daysInYear()) {
1320 // Check for a date in the next scheduled year 1322 // Check for a date in the next scheduled year
1321 if (!notThisYear) 1323 if (!notThisYear)
1322 yearsAhead -= rFreq; 1324 yearsAhead -= rFreq;
1323 prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31)); 1325 prevDate = getLastDateInYear(QDate(startYear + yearsAhead, 12, 31));
1324 } 1326 }
1325 break; 1327 break;
1326 } 1328 }
1327 case rNone: 1329 case rNone:
1328 default: 1330 default:
1329 return QDate(); 1331 return QDate();
1330 } 1332 }
1331 1333
1332 if (prevDate.isValid()) { 1334 if (prevDate.isValid()) {
1333 // Check that the date found is within the range of the recurrence 1335 // Check that the date found is within the range of the recurrence
1334 if (prevDate < dStart) 1336 if (prevDate < dStart)
1335 return QDate(); 1337 return QDate();
1336 if (rDuration >= 0) { 1338 if (rDuration >= 0) {
1337 QDate end = endDate(); 1339 QDate end = endDate();
1338 if (prevDate >= end) { 1340 if (prevDate >= end) {
1339 if (last) 1341 if (last)
1340 *last = true; 1342 *last = true;
1341 return end; 1343 return end;
1342 } 1344 }
1343 } 1345 }
1344 } 1346 }
1345 return prevDate; 1347 return prevDate;
1346} 1348}
1347 1349
1348void Recurrence::setDailySub(short type, int freq, int duration) 1350void Recurrence::setDailySub(short type, int freq, int duration)
1349{ 1351{
1350 recurs = type; 1352 recurs = type;
1351 rFreq = freq; 1353 rFreq = freq;
1352 rDuration = duration; 1354 rDuration = duration;
1353 rMonthPositions.clear(); 1355 rMonthPositions.clear();
1354 rMonthDays.clear(); 1356 rMonthDays.clear();
1355 rYearNums.clear(); 1357 rYearNums.clear();
1356 if (type != rDaily) 1358 if (type != rDaily)
1357 mFloats = false; // sub-daily types can't be floating 1359 mFloats = false; // sub-daily types can't be floating
1358 1360
1359 if (mParent) mParent->updated(); 1361 if (mParent) mParent->updated();
1360} 1362}
1361 1363
1362void Recurrence::setYearly_(short type, Feb29Type feb29type, int freq, int duration) 1364void Recurrence::setYearly_(short type, Feb29Type feb29type, int freq, int duration)
1363{ 1365{
1364 recurs = type; 1366 recurs = type;
1365 if (mCompatVersion < 310 && type == rYearlyDay) { 1367 if (mCompatVersion < 310 && type == rYearlyDay) {
1366 mCompatRecurs = rYearlyDay; 1368 mCompatRecurs = rYearlyDay;
1367 recurs = rYearlyMonth; // convert old yearly-by-day to yearly-by-month 1369 recurs = rYearlyMonth; // convert old yearly-by-day to yearly-by-month
1368 feb29type = rMar1; // retain the same day number in the year 1370 feb29type = rMar1; // retain the same day number in the year
1369 } 1371 }
1370 1372
1371 mFeb29YearlyType = feb29type; 1373 mFeb29YearlyType = feb29type;
1372 rFreq = freq; 1374 rFreq = freq;
1373 rDuration = duration; 1375 rDuration = duration;
1374 if (type != rYearlyPos) 1376 if (type != rYearlyPos)
1375 rMonthPositions.clear(); 1377 rMonthPositions.clear();
1376 rMonthDays.clear(); 1378 rMonthDays.clear();
1377 if (mParent) mParent->updated(); 1379 if (mParent) mParent->updated();
1378} 1380}
1379 1381
1380int Recurrence::recurCalc(PeriodFunc func, QDateTime &endtime) const 1382int Recurrence::recurCalc(PeriodFunc func, QDateTime &endtime) const
1381{ 1383{
1382 QDate enddate = endtime.date(); 1384 QDate enddate = endtime.date();
1383 switch (func) { 1385 switch (func) {
1384 case END_DATE_AND_COUNT: 1386 case END_DATE_AND_COUNT:
1385 if (rDuration < 0) { 1387 if (rDuration < 0) {
1386 endtime = QDateTime(); 1388 endtime = QDateTime();
1387 return 0; // infinite recurrence 1389 return 0; // infinite recurrence
1388 } 1390 }
1389 if (rDuration == 0) { 1391 if (rDuration == 0) {
1390 endtime = rEndDateTime; 1392 endtime = rEndDateTime;
1391 func = COUNT_TO_DATE; 1393 func = COUNT_TO_DATE;
1392 } 1394 }
1393 break; 1395 break;
1394 case COUNT_TO_DATE: 1396 case COUNT_TO_DATE:
1395 // Count recurrences up to and including the specified date/time. 1397 // Count recurrences up to and including the specified date/time.
1396 if (endtime < mRecurStart) 1398 if (endtime < mRecurStart)
1397 return 0; 1399 return 0;
1398 if (rDuration == 0 && endtime > rEndDateTime) 1400 if (rDuration == 0 && endtime > rEndDateTime)
1399 enddate = rEndDateTime.date(); 1401 enddate = rEndDateTime.date();
1400 else if (!mFloats && mRecurStart.time() > endtime.time()) 1402 else if (!mFloats && mRecurStart.time() > endtime.time())
1401 enddate = enddate.addDays(-1); 1403 enddate = enddate.addDays(-1);
1402 break; 1404 break;
1403 case NEXT_AFTER_DATE: 1405 case NEXT_AFTER_DATE:
1404 // Find next recurrence AFTER endtime 1406 // Find next recurrence AFTER endtime
1405 if (endtime < mRecurStart) { 1407 if (endtime < mRecurStart) {
1406 endtime = mRecurStart; 1408 endtime = mRecurStart;
1407 return 1; 1409 return 1;
1408 } 1410 }
1409 if (rDuration == 0 && endtime >= rEndDateTime) { 1411 if (rDuration == 0 && endtime >= rEndDateTime) {
1410 endtime = QDateTime(); 1412 endtime = QDateTime();
1411 return 0; 1413 return 0;
1412 } 1414 }
1413 if (!mFloats && mRecurStart.time() > endtime.time()) 1415 if (!mFloats && mRecurStart.time() > endtime.time())
1414 enddate = enddate.addDays(-1); 1416 enddate = enddate.addDays(-1);
1415 break; 1417 break;
1416 default: 1418 default:
1417 endtime = QDateTime(); 1419 endtime = QDateTime();
1418 return 0; 1420 return 0;
1419 } 1421 }
1420 1422
1421 int count = 0; // default = error 1423 int count = 0; // default = error
1422 bool timed = false; 1424 bool timed = false;
1423 switch (recurs) { 1425 switch (recurs) {
1424 case rMinutely: 1426 case rMinutely:
1425 timed = true; 1427 timed = true;
1426 count = secondlyCalc(func, endtime, rFreq*60); 1428 count = secondlyCalc(func, endtime, rFreq*60);
1427 break; 1429 break;
1428 case rHourly: 1430 case rHourly:
1429 timed = true; 1431 timed = true;
1430 count = secondlyCalc(func, endtime, rFreq*3600); 1432 count = secondlyCalc(func, endtime, rFreq*3600);
1431 break; 1433 break;
1432 case rDaily: 1434 case rDaily:
1433 count = dailyCalc(func, enddate); 1435 count = dailyCalc(func, enddate);
1434 break; 1436 break;
1435 case rWeekly: 1437 case rWeekly:
1436 count = weeklyCalc(func, enddate); 1438 count = weeklyCalc(func, enddate);
1437 break; 1439 break;
1438 case rMonthlyPos: 1440 case rMonthlyPos:
1439 case rMonthlyDay: 1441 case rMonthlyDay:
1440 count = monthlyCalc(func, enddate); 1442 count = monthlyCalc(func, enddate);
1441 break; 1443 break;
1442 case rYearlyMonth: 1444 case rYearlyMonth:
1443 count = yearlyMonthCalc(func, enddate); 1445 count = yearlyMonthCalc(func, enddate);
1444 break; 1446 break;
1445 case rYearlyPos: 1447 case rYearlyPos:
1446 count = yearlyPosCalc(func, enddate); 1448 count = yearlyPosCalc(func, enddate);
1447 break; 1449 break;
1448 case rYearlyDay: 1450 case rYearlyDay:
1449 count = yearlyDayCalc(func, enddate); 1451 count = yearlyDayCalc(func, enddate);
1450 break; 1452 break;
1451 default: 1453 default:
1452 break; 1454 break;
1453 } 1455 }
1454 1456
1455 switch (func) { 1457 switch (func) {
1456 case END_DATE_AND_COUNT: 1458 case END_DATE_AND_COUNT:
1457 case NEXT_AFTER_DATE: 1459 case NEXT_AFTER_DATE:
1458 if (count == 0) 1460 if (count == 0)
1459 endtime = QDateTime(); 1461 endtime = QDateTime();
1460 else if (!timed) { 1462 else if (!timed) {
1461 endtime.setDate(enddate); 1463 endtime.setDate(enddate);
1462 endtime.setTime(mRecurStart.time()); 1464 endtime.setTime(mRecurStart.time());
1463 } 1465 }
1464 break; 1466 break;
1465 case COUNT_TO_DATE: 1467 case COUNT_TO_DATE:
1466 break; 1468 break;
1467 } 1469 }
1468 return count; 1470 return count;
1469} 1471}
1470 1472
1471int Recurrence::recurCalc(PeriodFunc func, QDate &enddate) const 1473int Recurrence::recurCalc(PeriodFunc func, QDate &enddate) const
1472{ 1474{
1473 QDateTime endtime(enddate, QTime(23,59,59)); 1475 QDateTime endtime(enddate, QTime(23,59,59));
1474 switch (func) { 1476 switch (func) {
1475 case END_DATE_AND_COUNT: 1477 case END_DATE_AND_COUNT:
1476 if (rDuration < 0) { 1478 if (rDuration < 0) {
1477 enddate = QDate(); 1479 enddate = QDate();
1478 return 0; // infinite recurrence 1480 return 0; // infinite recurrence
1479 } 1481 }
1480 if (rDuration == 0) { 1482 if (rDuration == 0) {
1481 enddate = rEndDateTime.date(); 1483 enddate = rEndDateTime.date();
1482 func = COUNT_TO_DATE; 1484 func = COUNT_TO_DATE;
1483 } 1485 }
1484 break; 1486 break;
1485 case COUNT_TO_DATE: 1487 case COUNT_TO_DATE:
1486 // Count recurrences up to and including the specified date. 1488 // Count recurrences up to and including the specified date.
1487 if (enddate < mRecurStart.date()) 1489 if (enddate < mRecurStart.date())
1488 return 0; 1490 return 0;
1489 if (rDuration == 0 && enddate > rEndDateTime.date()) { 1491 if (rDuration == 0 && enddate > rEndDateTime.date()) {
1490 enddate = rEndDateTime.date(); 1492 enddate = rEndDateTime.date();
1491 endtime.setDate(enddate); 1493 endtime.setDate(enddate);
1492 } 1494 }
1493 break; 1495 break;
1494 case NEXT_AFTER_DATE: 1496 case NEXT_AFTER_DATE:
1495 if (enddate < mRecurStart.date()) { 1497 if (enddate < mRecurStart.date()) {
1496 enddate = mRecurStart.date(); 1498 enddate = mRecurStart.date();
1497 return 1; 1499 return 1;
1498 } 1500 }
1499 if (rDuration == 0 && enddate >= rEndDateTime.date()) { 1501 if (rDuration == 0 && enddate >= rEndDateTime.date()) {
1500 enddate = QDate(); 1502 enddate = QDate();
1501 return 0; 1503 return 0;
1502 } 1504 }
1503 break; 1505 break;
1504 default: 1506 default:
1505 enddate = QDate(); 1507 enddate = QDate();
1506 return 0; 1508 return 0;
1507 } 1509 }
1508 1510
1509 int count = 0; // default = error 1511 int count = 0; // default = error
1510 bool timed = false; 1512 bool timed = false;
1511 switch (recurs) { 1513 switch (recurs) {
1512 case rMinutely: 1514 case rMinutely:
1513 timed = true; 1515 timed = true;
1514 count = secondlyCalc(func, endtime, rFreq*60); 1516 count = secondlyCalc(func, endtime, rFreq*60);
1515 break; 1517 break;
1516 case rHourly: 1518 case rHourly:
1517 timed = true; 1519 timed = true;
1518 count = secondlyCalc(func, endtime, rFreq*3600); 1520 count = secondlyCalc(func, endtime, rFreq*3600);
1519 break; 1521 break;
1520 case rDaily: 1522 case rDaily:
1521 count = dailyCalc(func, enddate); 1523 count = dailyCalc(func, enddate);
1522 break; 1524 break;
1523 case rWeekly: 1525 case rWeekly:
1524 count = weeklyCalc(func, enddate); 1526 count = weeklyCalc(func, enddate);
1525 break; 1527 break;
1526 case rMonthlyPos: 1528 case rMonthlyPos:
1527 case rMonthlyDay: 1529 case rMonthlyDay:
1528 count = monthlyCalc(func, enddate); 1530 count = monthlyCalc(func, enddate);
1529 break; 1531 break;
1530 case rYearlyMonth: 1532 case rYearlyMonth:
1531 count = yearlyMonthCalc(func, enddate); 1533 count = yearlyMonthCalc(func, enddate);
1532 break; 1534 break;
1533 case rYearlyPos: 1535 case rYearlyPos:
1534 count = yearlyPosCalc(func, enddate); 1536 count = yearlyPosCalc(func, enddate);
1535 break; 1537 break;
1536 case rYearlyDay: 1538 case rYearlyDay:
1537 count = yearlyDayCalc(func, enddate); 1539 count = yearlyDayCalc(func, enddate);
1538 break; 1540 break;
1539 default: 1541 default:
1540 break; 1542 break;
1541 } 1543 }
1542 1544
1543 switch (func) { 1545 switch (func) {
1544 case END_DATE_AND_COUNT: 1546 case END_DATE_AND_COUNT:
1545 case NEXT_AFTER_DATE: 1547 case NEXT_AFTER_DATE:
1546 if (count == 0) 1548 if (count == 0)
1547 endtime = QDate(); 1549 endtime = QDate();
1548 else if (timed) 1550 else if (timed)
1549 enddate = endtime.date(); 1551 enddate = endtime.date();
1550 break; 1552 break;
1551 case COUNT_TO_DATE: 1553 case COUNT_TO_DATE:
1552 break; 1554 break;
1553 } 1555 }
1554 return count; 1556 return count;
1555} 1557}
1556 1558
1557/* Find count and, depending on 'func', the end date/time of a secondly recurrence. 1559/* Find count and, depending on 'func', the end date/time of a secondly recurrence.
1558 * Reply = total number of occurrences up to 'endtime', or 0 if error. 1560 * Reply = total number of occurrences up to 'endtime', or 0 if error.
1559 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'endtime' is updated to the 1561 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'endtime' is updated to the
1560 * recurrence end date/time. 1562 * recurrence end date/time.
1561 */ 1563 */
1562int Recurrence::secondlyCalc(PeriodFunc func, QDateTime &endtime, int freq) const 1564int Recurrence::secondlyCalc(PeriodFunc func, QDateTime &endtime, int freq) const
1563{ 1565{
1564 switch (func) { 1566 switch (func) {
1565 case END_DATE_AND_COUNT: 1567 case END_DATE_AND_COUNT:
1566 endtime = mRecurStart.addSecs((rDuration + mRecurExDatesCount - 1) * freq); 1568 endtime = mRecurStart.addSecs((rDuration + mRecurExDatesCount - 1) * freq);
1567 return rDuration + mRecurExDatesCount; 1569 return rDuration + mRecurExDatesCount;
1568 case COUNT_TO_DATE: { 1570 case COUNT_TO_DATE: {
1569 int n = mRecurStart.secsTo(endtime)/freq + 1; 1571 int n = mRecurStart.secsTo(endtime)/freq + 1;
1570 if (rDuration > 0 && n > rDuration + mRecurExDatesCount) 1572 if (rDuration > 0 && n > rDuration + mRecurExDatesCount)
1571 return rDuration + mRecurExDatesCount; 1573 return rDuration + mRecurExDatesCount;
1572 return n; 1574 return n;
1573 } 1575 }
1574 case NEXT_AFTER_DATE: { 1576 case NEXT_AFTER_DATE: {
1575 int count = mRecurStart.secsTo(endtime) / freq + 2; 1577 int count = mRecurStart.secsTo(endtime) / freq + 2;
1576 if (rDuration > 0 && count > rDuration) 1578 if (rDuration > 0 && count > rDuration)
1577 return 0; 1579 return 0;
1578 endtime = mRecurStart.addSecs((count - 1)*freq); 1580 endtime = mRecurStart.addSecs((count - 1)*freq);
1579 return count; 1581 return count;
1580 } 1582 }
1581 } 1583 }
1582 return 0; 1584 return 0;
1583} 1585}
1584 1586
1585/* Find count and, depending on 'func', the end date of a daily recurrence. 1587/* Find count and, depending on 'func', the end date of a daily recurrence.
1586 * Reply = total number of occurrences up to 'enddate', or 0 if error. 1588 * Reply = total number of occurrences up to 'enddate', or 0 if error.
1587 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the 1589 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the
1588 * recurrence end date. 1590 * recurrence end date.
1589 */ 1591 */
1590int Recurrence::dailyCalc(PeriodFunc func, QDate &enddate) const 1592int Recurrence::dailyCalc(PeriodFunc func, QDate &enddate) const
1591{ 1593{
1592 QDate dStart = mRecurStart.date(); 1594 QDate dStart = mRecurStart.date();
1593 switch (func) { 1595 switch (func) {
1594 case END_DATE_AND_COUNT: 1596 case END_DATE_AND_COUNT:
1595 enddate = dStart.addDays((rDuration + mRecurExDatesCount - 1) * rFreq); 1597 enddate = dStart.addDays((rDuration + mRecurExDatesCount - 1) * rFreq);
1596 return rDuration + mRecurExDatesCount; 1598 return rDuration + mRecurExDatesCount;
1597 case COUNT_TO_DATE: { 1599 case COUNT_TO_DATE: {
1598 int n = dStart.daysTo(enddate)/rFreq + 1; 1600 int n = dStart.daysTo(enddate)/rFreq + 1;
1599 if (rDuration > 0 && n > rDuration + mRecurExDatesCount) 1601 if (rDuration > 0 && n > rDuration + mRecurExDatesCount)
1600 return rDuration + mRecurExDatesCount; 1602 return rDuration + mRecurExDatesCount;
1601 return n; 1603 return n;
1602 } 1604 }
1603 case NEXT_AFTER_DATE: { 1605 case NEXT_AFTER_DATE: {
1604 int count = dStart.daysTo(enddate) / rFreq + 2; 1606 int count = dStart.daysTo(enddate) / rFreq + 2;
1605 if (rDuration > 0 && count > rDuration) 1607 if (rDuration > 0 && count > rDuration)
1606 return 0; 1608 return 0;
1607 enddate = dStart.addDays((count - 1)*rFreq); 1609 enddate = dStart.addDays((count - 1)*rFreq);
1608 return count; 1610 return count;
1609 } 1611 }
1610 } 1612 }
1611 return 0; 1613 return 0;
1612} 1614}
1613 1615
1614/* Find count and, depending on 'func', the end date of a weekly recurrence. 1616/* Find count and, depending on 'func', the end date of a weekly recurrence.
1615 * Reply = total number of occurrences up to 'enddate', or 0 if error. 1617 * Reply = total number of occurrences up to 'enddate', or 0 if error.
1616 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the 1618 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the
1617 * recurrence end date. 1619 * recurrence end date.
1618 */ 1620 */
1619int Recurrence::weeklyCalc(PeriodFunc func, QDate &enddate) const 1621int Recurrence::weeklyCalc(PeriodFunc func, QDate &enddate) const
1620{ 1622{
1621 int daysPerWeek = 0; 1623 int daysPerWeek = 0;
1622 for (int i = 0; i < 7; ++i) { 1624 for (int i = 0; i < 7; ++i) {
1623 if (rDays.testBit((uint)i)) 1625 if (rDays.testBit((uint)i))
1624 ++daysPerWeek; 1626 ++daysPerWeek;
1625 } 1627 }
1626 if (!daysPerWeek) 1628 if (!daysPerWeek)
1627 return 0; // there are no days to recur on 1629 return 0; // there are no days to recur on
1628 1630
1629 switch (func) { 1631 switch (func) {
1630 case END_DATE_AND_COUNT: 1632 case END_DATE_AND_COUNT:
1631 return weeklyCalcEndDate(enddate, daysPerWeek); 1633 return weeklyCalcEndDate(enddate, daysPerWeek);
1632 case COUNT_TO_DATE: 1634 case COUNT_TO_DATE:
1633 return weeklyCalcToDate(enddate, daysPerWeek); 1635 return weeklyCalcToDate(enddate, daysPerWeek);
1634 case NEXT_AFTER_DATE: 1636 case NEXT_AFTER_DATE:
1635 return weeklyCalcNextAfter(enddate, daysPerWeek); 1637 return weeklyCalcNextAfter(enddate, daysPerWeek);
1636 } 1638 }
1637 return 0; 1639 return 0;
1638} 1640}
1639 1641
1640int Recurrence::weeklyCalcEndDate(QDate &enddate, int daysPerWeek) const 1642int Recurrence::weeklyCalcEndDate(QDate &enddate, int daysPerWeek) const
1641{ 1643{
1642 int startDayOfWeek = mRecurStart.date().dayOfWeek(); // 1..7 1644 int startDayOfWeek = mRecurStart.date().dayOfWeek(); // 1..7
1643 int countGone = 0; 1645 int countGone = 0;
1644 int daysGone = 0; 1646 int daysGone = 0;
1645 uint countTogo = rDuration + mRecurExDatesCount; 1647 uint countTogo = rDuration + mRecurExDatesCount;
1646 if (startDayOfWeek != rWeekStart) { 1648 if (startDayOfWeek != rWeekStart) {
1647 // Check what remains of the start week 1649 // Check what remains of the start week
1648 for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { 1650 for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) {
1649 ++daysGone; 1651 ++daysGone;
1650 if (rDays.testBit((uint)i)) { 1652 if (rDays.testBit((uint)i)) {
1651 ++countGone; 1653 ++countGone;
1652 if (--countTogo == 0) 1654 if (--countTogo == 0)
1653 break; 1655 break;
1654 } 1656 }
1655 } 1657 }
1656 daysGone += 7 * (rFreq - 1); 1658 daysGone += 7 * (rFreq - 1);
1657 } 1659 }
1658 if (countTogo) { 1660 if (countTogo) {
1659 // Skip the remaining whole weeks 1661 // Skip the remaining whole weeks
1660 // Leave at least 1 recurrence remaining, in order to get its date 1662 // Leave at least 1 recurrence remaining, in order to get its date
1661 int wholeWeeks = (countTogo - 1) / daysPerWeek; 1663 int wholeWeeks = (countTogo - 1) / daysPerWeek;
1662 daysGone += wholeWeeks * 7 * rFreq; 1664 daysGone += wholeWeeks * 7 * rFreq;
1663 countGone += wholeWeeks * daysPerWeek; 1665 countGone += wholeWeeks * daysPerWeek;
1664 countTogo -= wholeWeeks * daysPerWeek; 1666 countTogo -= wholeWeeks * daysPerWeek;
1665 // Check the last week in the recurrence 1667 // Check the last week in the recurrence
1666 for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { 1668 for (int i = rWeekStart - 1; ; i = (i + 1) % 7) {
1667 ++daysGone; 1669 ++daysGone;
1668 if (rDays.testBit((uint)i)) { 1670 if (rDays.testBit((uint)i)) {
1669 ++countGone; 1671 ++countGone;
1670 if (--countTogo == 0) 1672 if (--countTogo == 0)
1671 break; 1673 break;
1672 } 1674 }
1673 } 1675 }
1674 } 1676 }
1675 enddate = mRecurStart.date().addDays(daysGone); 1677 enddate = mRecurStart.date().addDays(daysGone);
1676 return countGone; 1678 return countGone;
1677} 1679}
1678 1680
1679int Recurrence::weeklyCalcToDate(const QDate &enddate, int daysPerWeek) const 1681int Recurrence::weeklyCalcToDate(const QDate &enddate, int daysPerWeek) const
1680{ 1682{
1681 QDate dStart = mRecurStart.date(); 1683 QDate dStart = mRecurStart.date();
1682 int startDayOfWeek = dStart.dayOfWeek(); // 1..7 1684 int startDayOfWeek = dStart.dayOfWeek(); // 1..7
1683 int countGone = 0; 1685 int countGone = 0;
1684 int daysGone = 0; 1686 int daysGone = 0;
1685 int totalDays = dStart.daysTo(enddate) + 1; 1687 int totalDays = dStart.daysTo(enddate) + 1;
1686 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; 1688 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX;
1687 1689
1688 if (startDayOfWeek != rWeekStart) { 1690 if (startDayOfWeek != rWeekStart) {
1689 // Check what remains of the start week 1691 // Check what remains of the start week
1690 for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { 1692 for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) {
1691 if (rDays.testBit((uint)i)) { 1693 if (rDays.testBit((uint)i)) {
1692 if (++countGone >= countMax) 1694 if (++countGone >= countMax)
1693 return countMax; 1695 return countMax;
1694 } 1696 }
1695 if (++daysGone == totalDays) 1697 if (++daysGone == totalDays)
1696 return countGone; 1698 return countGone;
1697 } 1699 }
1698 daysGone += 7 * (rFreq - 1); 1700 daysGone += 7 * (rFreq - 1);
1699 if (daysGone >= totalDays) 1701 if (daysGone >= totalDays)
1700 return countGone; 1702 return countGone;
1701 } 1703 }
1702 // Skip the remaining whole weeks 1704 // Skip the remaining whole weeks
1703 int wholeWeeks = (totalDays - daysGone) / 7; 1705 int wholeWeeks = (totalDays - daysGone) / 7;
1704 countGone += (wholeWeeks / rFreq) * daysPerWeek; 1706 countGone += (wholeWeeks / rFreq) * daysPerWeek;
1705 if (countGone >= countMax) 1707 if (countGone >= countMax)
1706 return countMax; 1708 return countMax;
1707 daysGone += wholeWeeks * 7; 1709 daysGone += wholeWeeks * 7;
1708 if (daysGone >= totalDays // have we reached the end date? 1710 if (daysGone >= totalDays // have we reached the end date?
1709 || wholeWeeks % rFreq) // is end week a recurrence week? 1711 || wholeWeeks % rFreq) // is end week a recurrence week?
1710 return countGone; 1712 return countGone;
1711 1713
1712 // Check the last week in the recurrence 1714 // Check the last week in the recurrence
1713 for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { 1715 for (int i = rWeekStart - 1; ; i = (i + 1) % 7) {
1714 if (rDays.testBit((uint)i)) { 1716 if (rDays.testBit((uint)i)) {
1715 if (++countGone >= countMax) 1717 if (++countGone >= countMax)
1716 return countMax; 1718 return countMax;
1717 } 1719 }
1718 if (++daysGone == totalDays) 1720 if (++daysGone == totalDays)
1719 return countGone; 1721 return countGone;
1720 } 1722 }
1721 return countGone; 1723 return countGone;
1722} 1724}
1723 1725
1724int Recurrence::weeklyCalcNextAfter(QDate &enddate, int daysPerWeek) const 1726int Recurrence::weeklyCalcNextAfter(QDate &enddate, int daysPerWeek) const
1725{ 1727{
1726 QDate dStart = mRecurStart.date(); 1728 QDate dStart = mRecurStart.date();
1727 int startDayOfWeek = dStart.dayOfWeek(); // 1..7 1729 int startDayOfWeek = dStart.dayOfWeek(); // 1..7
1728 int totalDays = dStart.daysTo(enddate) + 1; 1730 int totalDays = dStart.daysTo(enddate) + 1;
1729 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; 1731 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX;
1730 int countGone = 0; 1732 int countGone = 0;
1731 int daysGone = 0; 1733 int daysGone = 0;
1732 int recurWeeks; 1734 int recurWeeks;
1733 1735
1734 if (startDayOfWeek != rWeekStart) { 1736 if (startDayOfWeek != rWeekStart) {
1735 // Check what remains of the start week 1737 // Check what remains of the start week
1736 for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) { 1738 for (int i = startDayOfWeek - 1; i != rWeekStart - 1; i = (i + 1) % 7) {
1737 ++daysGone; 1739 ++daysGone;
1738 if (rDays.testBit((uint)i)) { 1740 if (rDays.testBit((uint)i)) {
1739 ++countGone; 1741 ++countGone;
1740 if (daysGone > totalDays) 1742 if (daysGone > totalDays)
1741 goto ex; 1743 goto ex;
1742 if (--countTogo == 0) 1744 if (--countTogo == 0)
1743 return 0; 1745 return 0;
1744 } 1746 }
1745 } 1747 }
1746 daysGone += 7 * (rFreq - 1); 1748 daysGone += 7 * (rFreq - 1);
1747 } 1749 }
1748 1750
1749 // Skip the remaining whole weeks 1751 // Skip the remaining whole weeks
1750 recurWeeks = (totalDays - daysGone) / (7 * rFreq); 1752 recurWeeks = (totalDays - daysGone) / (7 * rFreq);
1751 if (recurWeeks) { 1753 if (recurWeeks) {
1752 int n = recurWeeks * daysPerWeek; 1754 int n = recurWeeks * daysPerWeek;
1753 if (static_cast<uint>(n) > countTogo) 1755 if (static_cast<uint>(n) > countTogo)
1754 return 0; // reached end of recurrence 1756 return 0; // reached end of recurrence
1755 countGone += n; 1757 countGone += n;
1756 countTogo -= n; 1758 countTogo -= n;
1757 daysGone += recurWeeks * 7 * rFreq; 1759 daysGone += recurWeeks * 7 * rFreq;
1758 } 1760 }
1759 1761
1760 // Check the last week or two in the recurrence 1762 // Check the last week or two in the recurrence
1761 for ( ; ; ) { 1763 for ( ; ; ) {
1762 for (int i = rWeekStart - 1; ; i = (i + 1) % 7) { 1764 for (int i = rWeekStart - 1; ; i = (i + 1) % 7) {
1763 ++daysGone; 1765 ++daysGone;
1764 if (rDays.testBit((uint)i)) { 1766 if (rDays.testBit((uint)i)) {
1765 ++countGone; 1767 ++countGone;
1766 if (daysGone > totalDays) 1768 if (daysGone > totalDays)
1767 goto ex; 1769 goto ex;
1768 if (--countTogo == 0) 1770 if (--countTogo == 0)
1769 return 0; 1771 return 0;
1770 } 1772 }
1771 } 1773 }
1772 daysGone += 7 * (rFreq - 1); 1774 daysGone += 7 * (rFreq - 1);
1773 } 1775 }
1774ex: 1776ex:
1775 enddate = dStart.addDays(daysGone); 1777 enddate = dStart.addDays(daysGone);
1776 return countGone; 1778 return countGone;
1777} 1779}
1778 1780
1779/* Find count and, depending on 'func', the end date of a monthly recurrence. 1781/* Find count and, depending on 'func', the end date of a monthly recurrence.
1780 * Reply = total number of occurrences up to 'enddate', or 0 if error. 1782 * Reply = total number of occurrences up to 'enddate', or 0 if error.
1781 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the 1783 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the
1782 * recurrence end date. 1784 * recurrence end date.
1783 */ 1785 */
1784struct Recurrence::MonthlyData { 1786struct Recurrence::MonthlyData {
1785 const Recurrence *recurrence; 1787 const Recurrence *recurrence;
1786 int year; // current year 1788 int year; // current year
1787 int month; // current month 0..11 1789 int month; // current month 0..11
1788 int day; // current day of month 1..31 1790 int day; // current day of month 1..31
1789 bool varies; // true if recurring days vary between different months 1791 bool varies; // true if recurring days vary between different months
1790 private: 1792 private:
1791 QValueList<int> days28, days29, days30, days31; // recurring days in months of each length 1793 QValueList<int> days28, days29, days30, days31; // recurring days in months of each length
1792 QValueList<int> *recurDays[4]; 1794 QValueList<int> *recurDays[4];
1793 public: 1795 public:
1794 MonthlyData(const Recurrence* r, const QDate &date) 1796 MonthlyData(const Recurrence* r, const QDate &date)
1795 : recurrence(r), year(date.year()), month(date.month()-1), day(date.day()) 1797 : recurrence(r), year(date.year()), month(date.month()-1), day(date.day())
1796 { recurDays[0] = &days28; 1798 { recurDays[0] = &days28;
1797 recurDays[1] = &days29; 1799 recurDays[1] = &days29;
1798 recurDays[2] = &days30; 1800 recurDays[2] = &days30;
1799 recurDays[3] = &days31; 1801 recurDays[3] = &days31;
1800 varies = (recurrence->recurs == rMonthlyPos) 1802 varies = (recurrence->recurs == rMonthlyPos)
1801 ? true : recurrence->getMonthlyDayDays(days31, 31); 1803 ? true : recurrence->getMonthlyDayDays(days31, 31);
1802 } 1804 }
1803 const QValueList<int>* dayList() const { 1805 const QValueList<int>* dayList() const {
1804 if (!varies) 1806 if (!varies)
1805 return &days31; 1807 return &days31;
1806 QDate startOfMonth(year, month + 1, 1); 1808 QDate startOfMonth(year, month + 1, 1);
1807 int daysInMonth = startOfMonth.daysInMonth(); 1809 int daysInMonth = startOfMonth.daysInMonth();
1808 QValueList<int>* days = recurDays[daysInMonth - 28]; 1810 QValueList<int>* days = recurDays[daysInMonth - 28];
1809 if (recurrence->recurs == rMonthlyPos) 1811 if (recurrence->recurs == rMonthlyPos)
1810 recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek()); 1812 recurrence->getMonthlyPosDays(*days, daysInMonth, startOfMonth.dayOfWeek());
1811 else if (days->isEmpty()) 1813 else if (days->isEmpty())
1812 recurrence->getMonthlyDayDays(*days, daysInMonth); 1814 recurrence->getMonthlyDayDays(*days, daysInMonth);
1813 return days; 1815 return days;
1814 } 1816 }
1815 int yearMonth() const { return year*12 + month; } 1817 int yearMonth() const { return year*12 + month; }
1816 void addMonths(int diff) { month += diff; year += month / 12; month %= 12; } 1818 void addMonths(int diff) { month += diff; year += month / 12; month %= 12; }
1817 QDate date() const { return QDate(year, month + 1, day); } 1819 QDate date() const { return QDate(year, month + 1, day); }
1818}; 1820};
1819 1821
1820int Recurrence::monthlyCalc(PeriodFunc func, QDate &enddate) const 1822int Recurrence::monthlyCalc(PeriodFunc func, QDate &enddate) const
1821{ 1823{
1822 if (recurs == rMonthlyPos && rMonthPositions.isEmpty() 1824 if (recurs == rMonthlyPos && rMonthPositions.isEmpty()
1823 || recurs == rMonthlyDay && rMonthDays.isEmpty()) 1825 || recurs == rMonthlyDay && rMonthDays.isEmpty())
1824 return 0; 1826 return 0;
1825 1827
1826 MonthlyData data(this, mRecurStart.date()); 1828 MonthlyData data(this, mRecurStart.date());
1827 switch (func) { 1829 switch (func) {
1828 case END_DATE_AND_COUNT: 1830 case END_DATE_AND_COUNT:
1829 return monthlyCalcEndDate(enddate, data); 1831 return monthlyCalcEndDate(enddate, data);
1830 case COUNT_TO_DATE: 1832 case COUNT_TO_DATE:
1831 return monthlyCalcToDate(enddate, data); 1833 return monthlyCalcToDate(enddate, data);
1832 case NEXT_AFTER_DATE: 1834 case NEXT_AFTER_DATE:
1833 return monthlyCalcNextAfter(enddate, data); 1835 return monthlyCalcNextAfter(enddate, data);
1834 } 1836 }
1835 return 0; 1837 return 0;
1836} 1838}
1837 1839
1838int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const 1840int Recurrence::monthlyCalcEndDate(QDate &enddate, MonthlyData &data) const
1839{ 1841{
1840 uint countTogo = rDuration + mRecurExDatesCount; 1842 uint countTogo = rDuration + mRecurExDatesCount;
1841 int countGone = 0; 1843 int countGone = 0;
1842 QValueList<int>::ConstIterator it; 1844 QValueList<int>::ConstIterator it;
1843 const QValueList<int>* days = data.dayList(); 1845 const QValueList<int>* days = data.dayList();
1844 1846
1845 if (data.day > 1) { 1847 if (data.day > 1) {
1846 // Check what remains of the start month 1848 // Check what remains of the start month
1847 for (it = days->begin(); it != days->end(); ++it) { 1849 for (it = days->begin(); it != days->end(); ++it) {
1848 if (*it >= data.day) { 1850 if (*it >= data.day) {
1849 ++countGone; 1851 ++countGone;
1850 if (--countTogo == 0) { 1852 if (--countTogo == 0) {
1851 data.day = *it; 1853 data.day = *it;
1852 break; 1854 break;
1853 } 1855 }
1854 } 1856 }
1855 } 1857 }
1856 if (countTogo) { 1858 if (countTogo) {
1857 data.day = 1; 1859 data.day = 1;
1858 data.addMonths(rFreq); 1860 data.addMonths(rFreq);
1859 } 1861 }
1860 } 1862 }
1861 if (countTogo) { 1863 if (countTogo) {
1862 if (data.varies) { 1864 if (data.varies) {
1863 // The number of recurrence days varies from month to month, 1865 // The number of recurrence days varies from month to month,
1864 // so we need to check month by month. 1866 // so we need to check month by month.
1865 for ( ; ; ) { 1867 for ( ; ; ) {
1866 days = data.dayList(); 1868 days = data.dayList();
1867 uint n = days->count(); // number of recurrence days in this month 1869 uint n = days->count(); // number of recurrence days in this month
1868 if (n >= countTogo) 1870 if (n >= countTogo)
1869 break; 1871 break;
1870 countTogo -= n; 1872 countTogo -= n;
1871 countGone += n; 1873 countGone += n;
1872 data.addMonths(rFreq); 1874 data.addMonths(rFreq);
1873 } 1875 }
1874 } else { 1876 } else {
1875 // The number of recurrences is the same every month, 1877 // The number of recurrences is the same every month,
1876 // so skip the month-by-month check. 1878 // so skip the month-by-month check.
1877 // Skip the remaining whole months, but leave at least 1879 // Skip the remaining whole months, but leave at least
1878 // 1 recurrence remaining, in order to get its date. 1880 // 1 recurrence remaining, in order to get its date.
1879 int daysPerMonth = days->count(); 1881 int daysPerMonth = days->count();
1880 int wholeMonths = (countTogo - 1) / daysPerMonth; 1882 int wholeMonths = (countTogo - 1) / daysPerMonth;
1881 data.addMonths(wholeMonths * rFreq); 1883 data.addMonths(wholeMonths * rFreq);
1882 countGone += wholeMonths * daysPerMonth; 1884 countGone += wholeMonths * daysPerMonth;
1883 countTogo -= wholeMonths * daysPerMonth; 1885 countTogo -= wholeMonths * daysPerMonth;
1884 } 1886 }
1885 if (countTogo) { 1887 if (countTogo) {
1886 // Check the last month in the recurrence 1888 // Check the last month in the recurrence
1887 for (it = days->begin(); it != days->end(); ++it) { 1889 for (it = days->begin(); it != days->end(); ++it) {
1888 ++countGone; 1890 ++countGone;
1889 if (--countTogo == 0) { 1891 if (--countTogo == 0) {
1890 data.day = *it; 1892 data.day = *it;
1891 break; 1893 break;
1892 } 1894 }
1893 } 1895 }
1894 } 1896 }
1895 } 1897 }
1896 enddate = data.date(); 1898 enddate = data.date();
1897 return countGone; 1899 return countGone;
1898} 1900}
1899 1901
1900int Recurrence::monthlyCalcToDate(const QDate &enddate, MonthlyData &data) const 1902int Recurrence::monthlyCalcToDate(const QDate &enddate, MonthlyData &data) const
1901{ 1903{
1902 int countGone = 0; 1904 int countGone = 0;
1903 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; 1905 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX;
1904 int endYear = enddate.year(); 1906 int endYear = enddate.year();
1905 int endMonth = enddate.month() - 1; // zero-based 1907 int endMonth = enddate.month() - 1; // zero-based
1906 int endDay = enddate.day(); 1908 int endDay = enddate.day();
1907 int endYearMonth = endYear*12 + endMonth; 1909 int endYearMonth = endYear*12 + endMonth;
1908 QValueList<int>::ConstIterator it; 1910 QValueList<int>::ConstIterator it;
1909 const QValueList<int>* days = data.dayList(); 1911 const QValueList<int>* days = data.dayList();
1910 1912
1911 if (data.day > 1) { 1913 if (data.day > 1) {
1912 // Check what remains of the start month 1914 // Check what remains of the start month
1913 for (it = days->begin(); it != days->end(); ++it) { 1915 for (it = days->begin(); it != days->end(); ++it) {
1914 if (*it >= data.day) { 1916 if (*it >= data.day) {
1915 if (data.yearMonth() == endYearMonth && *it > endDay) 1917 if (data.yearMonth() == endYearMonth && *it > endDay)
1916 return countGone; 1918 return countGone;
1917 if (++countGone >= countMax) 1919 if (++countGone >= countMax)
1918 return countMax; 1920 return countMax;
1919 } 1921 }
1920 } 1922 }
1921 data.day = 1; 1923 data.day = 1;
1922 data.addMonths(rFreq); 1924 data.addMonths(rFreq);
1923 } 1925 }
1924 1926
1925 if (data.varies) { 1927 if (data.varies) {
1926 // The number of recurrence days varies from month to month, 1928 // The number of recurrence days varies from month to month,
1927 // so we need to check month by month. 1929 // so we need to check month by month.
1928 while (data.yearMonth() < endYearMonth) { 1930 while (data.yearMonth() < endYearMonth) {
1929 countGone += data.dayList()->count(); 1931 countGone += data.dayList()->count();
1930 if (countGone >= countMax) 1932 if (countGone >= countMax)
1931 return countMax; 1933 return countMax;
1932 data.addMonths(rFreq); 1934 data.addMonths(rFreq);
1933 } 1935 }
1934 days = data.dayList(); 1936 days = data.dayList();
1935 } else { 1937 } else {
1936 // The number of recurrences is the same every month, 1938 // The number of recurrences is the same every month,
1937 // so skip the month-by-month check. 1939 // so skip the month-by-month check.
1938 // Skip the remaining whole months. 1940 // Skip the remaining whole months.
1939 int daysPerMonth = days->count(); 1941 int daysPerMonth = days->count();
1940 int wholeMonths = endYearMonth - data.yearMonth(); 1942 int wholeMonths = endYearMonth - data.yearMonth();
1941 countGone += (wholeMonths / rFreq) * daysPerMonth; 1943 countGone += (wholeMonths / rFreq) * daysPerMonth;
1942 if (countGone >= countMax) 1944 if (countGone >= countMax)
1943 return countMax; 1945 return countMax;
1944 if (wholeMonths % rFreq) 1946 if (wholeMonths % rFreq)
1945 return countGone; // end year isn't a recurrence year 1947 return countGone; // end year isn't a recurrence year
1946 data.year = endYear; 1948 data.year = endYear;
1947 data.month = endMonth; 1949 data.month = endMonth;
1948 } 1950 }
1949 1951
1950 // Check the last month in the recurrence 1952 // Check the last month in the recurrence
1951 for (it = days->begin(); it != days->end(); ++it) { 1953 for (it = days->begin(); it != days->end(); ++it) {
1952 if (*it > endDay) 1954 if (*it > endDay)
1953 return countGone; 1955 return countGone;
1954 if (++countGone >= countMax) 1956 if (++countGone >= countMax)
1955 return countMax; 1957 return countMax;
1956 } 1958 }
1957 return countGone; 1959 return countGone;
1958} 1960}
1959 1961
1960int Recurrence::monthlyCalcNextAfter(QDate &enddate, MonthlyData &data) const 1962int Recurrence::monthlyCalcNextAfter(QDate &enddate, MonthlyData &data) const
1961{ 1963{
1962 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; 1964 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX;
1963 int countGone = 0; 1965 int countGone = 0;
1964 int endYear = enddate.year(); 1966 int endYear = enddate.year();
1965 int endDay = enddate.day(); 1967 int endDay = enddate.day();
1966 int endYearMonth = endYear*12 + enddate.month() - 1; 1968 int endYearMonth = endYear*12 + enddate.month() - 1;
1967 QValueList<int>::ConstIterator it; 1969 QValueList<int>::ConstIterator it;
1968 const QValueList<int>* days = data.dayList(); 1970 const QValueList<int>* days = data.dayList();
1969 1971
1970 if (data.day > 1) { 1972 if (data.day > 1) {
1971 // Check what remains of the start month 1973 // Check what remains of the start month
1972 for (it = days->begin(); it != days->end(); ++it) { 1974 for (it = days->begin(); it != days->end(); ++it) {
1973 if (*it >= data.day) { 1975 if (*it >= data.day) {
1974 ++countGone; 1976 ++countGone;
1975 if (data.yearMonth() == endYearMonth && *it > endDay) { 1977 if (data.yearMonth() == endYearMonth && *it > endDay) {
1976 data.day = *it; 1978 data.day = *it;
1977 goto ex; 1979 goto ex;
1978 } 1980 }
1979 if (--countTogo == 0) 1981 if (--countTogo == 0)
1980 return 0; 1982 return 0;
1981 } 1983 }
1982 } 1984 }
1983 data.day = 1; 1985 data.day = 1;
1984 data.addMonths(rFreq); 1986 data.addMonths(rFreq);
1985 } 1987 }
1986 1988
1987 if (data.varies) { 1989 if (data.varies) {
1988 // The number of recurrence days varies from month to month, 1990 // The number of recurrence days varies from month to month,
1989 // so we need to check month by month. 1991 // so we need to check month by month.
1990 while (data.yearMonth() <= endYearMonth) { 1992 while (data.yearMonth() <= endYearMonth) {
1991 days = data.dayList(); 1993 days = data.dayList();
1992 uint n = days->count(); // number of recurrence days in this month 1994 uint n = days->count(); // number of recurrence days in this month
1993 if (data.yearMonth() == endYearMonth && days->last() > endDay) 1995 if (data.yearMonth() == endYearMonth && days->last() > endDay)
1994 break; 1996 break;
1995 if (n >= countTogo) 1997 if (n >= countTogo)
1996 return 0; 1998 return 0;
1997 countGone += n; 1999 countGone += n;
1998 countTogo -= n; 2000 countTogo -= n;
1999 data.addMonths(rFreq); 2001 data.addMonths(rFreq);
2000 } 2002 }
2001 days = data.dayList(); 2003 days = data.dayList();
2002 } else { 2004 } else {
2003 // The number of recurrences is the same every month, 2005 // The number of recurrences is the same every month,
2004 // so skip the month-by-month check. 2006 // so skip the month-by-month check.
2005 // Skip the remaining whole months to at least end year/month. 2007 // Skip the remaining whole months to at least end year/month.
2006 int daysPerMonth = days->count(); 2008 int daysPerMonth = days->count();
2007 int elapsed = endYearMonth - data.yearMonth(); 2009 int elapsed = endYearMonth - data.yearMonth();
2008 int recurMonths = (elapsed + rFreq - 1) / rFreq; 2010 int recurMonths = (elapsed + rFreq - 1) / rFreq;
2009 if (elapsed % rFreq == 0 && days->last() <= endDay) 2011 if (elapsed % rFreq == 0 && days->last() <= endDay)
2010 ++recurMonths; // required month is after endYearMonth 2012 ++recurMonths; // required month is after endYearMonth
2011 if (recurMonths) { 2013 if (recurMonths) {
2012 int n = recurMonths * daysPerMonth; 2014 int n = recurMonths * daysPerMonth;
2013 if (static_cast<uint>(n) > countTogo) 2015 if (static_cast<uint>(n) > countTogo)
2014 return 0; // reached end of recurrence 2016 return 0; // reached end of recurrence
2015 countTogo -= n; 2017 countTogo -= n;
2016 countGone += n; 2018 countGone += n;
2017 data.addMonths(recurMonths * rFreq); 2019 data.addMonths(recurMonths * rFreq);
2018 } 2020 }
2019 } 2021 }
2020 2022
2021 // Check the last month in the recurrence 2023 // Check the last month in the recurrence
2022 for (it = days->begin(); it != days->end(); ++it) { 2024 for (it = days->begin(); it != days->end(); ++it) {
2023 ++countGone; 2025 ++countGone;
2024 if (data.yearMonth() > endYearMonth || *it > endDay) { 2026 if (data.yearMonth() > endYearMonth || *it > endDay) {
2025 data.day = *it; 2027 data.day = *it;
2026 break; 2028 break;
2027 } 2029 }
2028 if (--countTogo == 0) 2030 if (--countTogo == 0)
2029 return 0; 2031 return 0;
2030 } 2032 }
2031ex: 2033ex:
2032 enddate = data.date(); 2034 enddate = data.date();
2033 return countGone; 2035 return countGone;
2034} 2036}
2035 2037
2036 2038
2037/* Find count and, depending on 'func', the end date of an annual recurrence by date. 2039/* Find count and, depending on 'func', the end date of an annual recurrence by date.
2038 * Reply = total number of occurrences up to 'enddate', or 0 if error. 2040 * Reply = total number of occurrences up to 'enddate', or 0 if error.
2039 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the 2041 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the
2040 * recurrence end date. 2042 * recurrence end date.
2041 */ 2043 */
2042struct Recurrence::YearlyMonthData { 2044struct Recurrence::YearlyMonthData {
2043 const Recurrence *recurrence; 2045 const Recurrence *recurrence;
2044 int year; // current year 2046 int year; // current year
2045 int month; // current month 1..12 2047 int month; // current month 1..12
2046 int day; // current day of month 1..31 2048 int day; // current day of month 1..31
2047 bool leapyear; // true if February 29th recurs and current year is a leap year 2049 bool leapyear; // true if February 29th recurs and current year is a leap year
2048 bool feb29; // true if February 29th recurs 2050 bool feb29; // true if February 29th recurs
2049 private: 2051 private:
2050 QValueList<int> months; // recurring months in non-leap years 1..12 2052 QValueList<int> months; // recurring months in non-leap years 1..12
2051 QValueList<int> leapMonths; // recurring months in leap years 1..12 2053 QValueList<int> leapMonths; // recurring months in leap years 1..12
2052 public: 2054 public:
2053 YearlyMonthData(const Recurrence* r, const QDate &date) 2055 YearlyMonthData(const Recurrence* r, const QDate &date)
2054 : recurrence(r), year(date.year()), month(date.month()), day(date.day()) 2056 : recurrence(r), year(date.year()), month(date.month()), day(date.day())
2055 { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths); 2057 { feb29 = recurrence->getYearlyMonthMonths(day, months, leapMonths);
2056 leapyear = feb29 && QDate::leapYear(year); 2058 leapyear = feb29 && QDate::leapYear(year);
2057 } 2059 }
2058 const QValueList<int>* monthList() const 2060 const QValueList<int>* monthList() const
2059 { return leapyear ? &leapMonths : &months; } 2061 { return leapyear ? &leapMonths : &months; }
2060 const QValueList<int>* leapMonthList() const { return &leapMonths; } 2062 const QValueList<int>* leapMonthList() const { return &leapMonths; }
2061 QDate date() const { return QDate(year, month, day); } 2063 QDate date() const { return QDate(year, month, day); }
2062}; 2064};
2063 2065
2064int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const 2066int Recurrence::yearlyMonthCalc(PeriodFunc func, QDate &enddate) const
2065{ 2067{
2066 if (rYearNums.isEmpty()) 2068 if (rYearNums.isEmpty())
2067 return 0; 2069 return 0;
2068 YearlyMonthData data(this, mRecurStart.date()); 2070 YearlyMonthData data(this, mRecurStart.date());
2069 switch (func) { 2071 switch (func) {
2070 case END_DATE_AND_COUNT: 2072 case END_DATE_AND_COUNT:
2071 return yearlyMonthCalcEndDate(enddate, data); 2073 return yearlyMonthCalcEndDate(enddate, data);
2072 case COUNT_TO_DATE: 2074 case COUNT_TO_DATE:
2073 return yearlyMonthCalcToDate(enddate, data); 2075 return yearlyMonthCalcToDate(enddate, data);
2074 case NEXT_AFTER_DATE: 2076 case NEXT_AFTER_DATE:
2075 return yearlyMonthCalcNextAfter(enddate, data); 2077 return yearlyMonthCalcNextAfter(enddate, data);
2076 } 2078 }
2077 return 0; 2079 return 0;
2078} 2080}
2079 2081
2080// Find total count and end date of an annual recurrence by date. 2082// Find total count and end date of an annual recurrence by date.
2081// Reply = total number of occurrences. 2083// Reply = total number of occurrences.
2082int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const 2084int Recurrence::yearlyMonthCalcEndDate(QDate &enddate, YearlyMonthData &data) const
2083{ 2085{
2084 uint countTogo = rDuration + mRecurExDatesCount; 2086 uint countTogo = rDuration + mRecurExDatesCount;
2085 int countGone = 0; 2087 int countGone = 0;
2086 QValueList<int>::ConstIterator it; 2088 QValueList<int>::ConstIterator it;
2087 const QValueList<int>* mons = data.monthList(); // get recurring months for this year 2089 const QValueList<int>* mons = data.monthList(); // get recurring months for this year
2088 2090
2089 if (data.month > 1) { 2091 if (data.month > 1) {
2090 // Check what remains of the start year 2092 // Check what remains of the start year
2091 for (it = mons->begin(); it != mons->end(); ++it) { 2093 for (it = mons->begin(); it != mons->end(); ++it) {
2092 if (*it >= data.month) { 2094 if (*it >= data.month) {
2093 ++countGone; 2095 ++countGone;
2094 if (--countTogo == 0) { 2096 if (--countTogo == 0) {
2095 data.month = *it; 2097 data.month = *it;
2096 if (data.month == 2 && data.feb29 && !data.leapyear) { 2098 if (data.month == 2 && data.feb29 && !data.leapyear) {
2097 // The recurrence should end on February 29th, but it's a non-leap year 2099 // The recurrence should end on February 29th, but it's a non-leap year
2098 switch (mFeb29YearlyType) { 2100 switch (mFeb29YearlyType) {
2099 case rFeb28: 2101 case rFeb28:
2100 data.day = 28; 2102 data.day = 28;
2101 break; 2103 break;
2102 case rMar1: 2104 case rMar1:
2103 data.month = 3; 2105 data.month = 3;
2104 data.day = 1; 2106 data.day = 1;
2105 break; 2107 break;
2106 case rFeb29: 2108 case rFeb29:
2107 break; 2109 break;
2108 } 2110 }
2109 } 2111 }
2110 break; 2112 break;
2111 } 2113 }
2112 } 2114 }
2113 } 2115 }
2114 if (countTogo) { 2116 if (countTogo) {
2115 data.month = 1; 2117 data.month = 1;
2116 data.year += rFreq; 2118 data.year += rFreq;
2117 } 2119 }
2118 } 2120 }
2119 if (countTogo) { 2121 if (countTogo) {
2120 if (data.feb29 && mFeb29YearlyType == rFeb29) { 2122 if (data.feb29 && mFeb29YearlyType == rFeb29) {
2121 // The number of recurrences is different on leap years, 2123 // The number of recurrences is different on leap years,
2122 // so check year-by-year. 2124 // so check year-by-year.
2123 for ( ; ; ) { 2125 for ( ; ; ) {
2124 mons = data.monthList(); 2126 mons = data.monthList();
2125 uint n = mons->count(); 2127 uint n = mons->count();
2126 if (n >= countTogo) 2128 if (n >= countTogo)
2127 break; 2129 break;
2128 countTogo -= n; 2130 countTogo -= n;
2129 countGone += n; 2131 countGone += n;
2130 data.year += rFreq; 2132 data.year += rFreq;
2131 } 2133 }
2132 } else { 2134 } else {
2133 // The number of recurrences is the same every year, 2135 // The number of recurrences is the same every year,
2134 // so skip the year-by-year check. 2136 // so skip the year-by-year check.
2135 // Skip the remaining whole years, but leave at least 2137 // Skip the remaining whole years, but leave at least
2136 // 1 recurrence remaining, in order to get its date. 2138 // 1 recurrence remaining, in order to get its date.
2137 int monthsPerYear = mons->count(); 2139 int monthsPerYear = mons->count();
2138 int wholeYears = (countTogo - 1) / monthsPerYear; 2140 int wholeYears = (countTogo - 1) / monthsPerYear;
2139 data.year += wholeYears * rFreq; 2141 data.year += wholeYears * rFreq;
2140 countGone += wholeYears * monthsPerYear; 2142 countGone += wholeYears * monthsPerYear;
2141 countTogo -= wholeYears * monthsPerYear; 2143 countTogo -= wholeYears * monthsPerYear;
2142 } 2144 }
2143 if (countTogo) { 2145 if (countTogo) {
2144 // Check the last year in the recurrence 2146 // Check the last year in the recurrence
2145 for (it = mons->begin(); it != mons->end(); ++it) { 2147 for (it = mons->begin(); it != mons->end(); ++it) {
2146 ++countGone; 2148 ++countGone;
2147 if (--countTogo == 0) { 2149 if (--countTogo == 0) {
2148 data.month = *it; 2150 data.month = *it;
2149 if (data.month == 2 && data.feb29 && !QDate::leapYear(data.year)) { 2151 if (data.month == 2 && data.feb29 && !QDate::leapYear(data.year)) {
2150 // The recurrence should end on February 29th, but it's a non-leap year 2152 // The recurrence should end on February 29th, but it's a non-leap year
2151 switch (mFeb29YearlyType) { 2153 switch (mFeb29YearlyType) {
2152 case rFeb28: 2154 case rFeb28:
2153 data.day = 28; 2155 data.day = 28;
2154 break; 2156 break;
2155 case rMar1: 2157 case rMar1:
2156 data.month = 3; 2158 data.month = 3;
2157 data.day = 1; 2159 data.day = 1;
2158 break; 2160 break;
2159 case rFeb29: 2161 case rFeb29:
2160 break; 2162 break;
2161 } 2163 }
2162 } 2164 }
2163 break; 2165 break;
2164 } 2166 }
2165 } 2167 }
2166 } 2168 }
2167 } 2169 }
2168 enddate = data.date(); 2170 enddate = data.date();
2169 return countGone; 2171 return countGone;
2170} 2172}
2171 2173
2172// Find count of an annual recurrence by date. 2174// Find count of an annual recurrence by date.
2173// Reply = total number of occurrences up to 'enddate'. 2175// Reply = total number of occurrences up to 'enddate'.
2174int Recurrence::yearlyMonthCalcToDate(const QDate &enddate, YearlyMonthData &data) const 2176int Recurrence::yearlyMonthCalcToDate(const QDate &enddate, YearlyMonthData &data) const
2175{ 2177{
2176 int countGone = 0; 2178 int countGone = 0;
2177 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; 2179 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX;
2178 int endYear = enddate.year(); 2180 int endYear = enddate.year();
2179 int endMonth = enddate.month(); 2181 int endMonth = enddate.month();
2180 int endDay = enddate.day(); 2182 int endDay = enddate.day();
2181 if (endDay < data.day) { 2183 if (endDay < data.day) {
2182 /* The end day of the month is earlier than the recurrence day of the month. 2184 /* The end day of the month is earlier than the recurrence day of the month.
2183 * If Feb 29th recurs and: 2185 * If Feb 29th recurs and:
2184 * 1) it recurs on Feb 28th in non-leap years, don't adjust the end month 2186 * 1) it recurs on Feb 28th in non-leap years, don't adjust the end month
2185 * if enddate is Feb 28th on a non-leap year. 2187 * if enddate is Feb 28th on a non-leap year.
2186 * 2) it recurs on Mar 1st in non-leap years, allow the end month to be 2188 * 2) it recurs on Mar 1st in non-leap years, allow the end month to be
2187 * adjusted to February, to simplify calculations. 2189 * adjusted to February, to simplify calculations.
2188 */ 2190 */
2189 if (data.feb29 && !QDate::leapYear(endYear) 2191 if (data.feb29 && !QDate::leapYear(endYear)
2190 && mFeb29YearlyType == rFeb28 && endDay == 28 && endMonth == 2) { 2192 && mFeb29YearlyType == rFeb28 && endDay == 28 && endMonth == 2) {
2191 } 2193 }
2192 else if (--endMonth == 0) { 2194 else if (--endMonth == 0) {
2193 endMonth = 12; 2195 endMonth = 12;
2194 --endYear; 2196 --endYear;
2195 } 2197 }
2196 } 2198 }
2197 QValueList<int>::ConstIterator it; 2199 QValueList<int>::ConstIterator it;
2198 const QValueList<int>* mons = data.monthList(); 2200 const QValueList<int>* mons = data.monthList();
2199 2201
2200 if (data.month > 1) { 2202 if (data.month > 1) {
2201 // Check what remains of the start year 2203 // Check what remains of the start year
2202 for (it = mons->begin(); it != mons->end(); ++it) { 2204 for (it = mons->begin(); it != mons->end(); ++it) {
2203 if (*it >= data.month) { 2205 if (*it >= data.month) {
2204 if (data.year == endYear && *it > endMonth) 2206 if (data.year == endYear && *it > endMonth)
2205 return countGone; 2207 return countGone;
2206 if (++countGone >= countMax) 2208 if (++countGone >= countMax)
2207 return countMax; 2209 return countMax;
2208 } 2210 }
2209 } 2211 }
2210 data.month = 1; 2212 data.month = 1;
2211 data.year += rFreq; 2213 data.year += rFreq;
2212 } 2214 }
2213 if (data.feb29 && mFeb29YearlyType == rFeb29) { 2215 if (data.feb29 && mFeb29YearlyType == rFeb29) {
2214 // The number of recurrences is different on leap years, 2216 // The number of recurrences is different on leap years,
2215 // so check year-by-year. 2217 // so check year-by-year.
2216 while (data.year < endYear) { 2218 while (data.year < endYear) {
2217 countGone += data.monthList()->count(); 2219 countGone += data.monthList()->count();
2218 if (countGone >= countMax) 2220 if (countGone >= countMax)
2219 return countMax; 2221 return countMax;
2220 data.year += rFreq; 2222 data.year += rFreq;
2221 } 2223 }
2222 mons = data.monthList(); 2224 mons = data.monthList();
2223 } else { 2225 } else {
2224 // The number of recurrences is the same every year, 2226 // The number of recurrences is the same every year,
2225 // so skip the year-by-year check. 2227 // so skip the year-by-year check.
2226 // Skip the remaining whole years. 2228 // Skip the remaining whole years.
2227 int monthsPerYear = mons->count(); 2229 int monthsPerYear = mons->count();
2228 int wholeYears = endYear - data.year; 2230 int wholeYears = endYear - data.year;
2229 countGone += (wholeYears / rFreq) * monthsPerYear; 2231 countGone += (wholeYears / rFreq) * monthsPerYear;
2230 if (countGone >= countMax) 2232 if (countGone >= countMax)
2231 return countMax; 2233 return countMax;
2232 if (wholeYears % rFreq) 2234 if (wholeYears % rFreq)
2233 return countGone; // end year isn't a recurrence year 2235 return countGone; // end year isn't a recurrence year
2234 data.year = endYear; 2236 data.year = endYear;
2235 } 2237 }
2236 2238
2237 // Check the last year in the recurrence 2239 // Check the last year in the recurrence
2238 for (it = mons->begin(); it != mons->end(); ++it) { 2240 for (it = mons->begin(); it != mons->end(); ++it) {
2239 if (*it > endMonth) 2241 if (*it > endMonth)
2240 return countGone; 2242 return countGone;
2241 if (++countGone >= countMax) 2243 if (++countGone >= countMax)
2242 return countMax; 2244 return countMax;
2243 } 2245 }
2244 return countGone; 2246 return countGone;
2245} 2247}
2246 2248
2247// Find count and date of first recurrence after 'enddate' of an annual recurrence by date. 2249// Find count and date of first recurrence after 'enddate' of an annual recurrence by date.
2248// Reply = total number of occurrences up to 'enddate'. 2250// Reply = total number of occurrences up to 'enddate'.
2249int Recurrence::yearlyMonthCalcNextAfter(QDate &enddate, YearlyMonthData &data) const 2251int Recurrence::yearlyMonthCalcNextAfter(QDate &enddate, YearlyMonthData &data) const
2250{ 2252{
2251 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; 2253 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX;
2252 int countGone = 0; 2254 int countGone = 0;
2253 int endYear = enddate.year(); 2255 int endYear = enddate.year();
2254 int endMonth = enddate.month(); 2256 int endMonth = enddate.month();
2255 int endDay = enddate.day(); 2257 int endDay = enddate.day();
2256 bool mar1TooEarly = false; 2258 bool mar1TooEarly = false;
2257 bool feb28ok = false; 2259 bool feb28ok = false;
2258 if (endDay < data.day) { 2260 if (endDay < data.day) {
2259 if (data.feb29 && mFeb29YearlyType == rMar1 && endMonth == 3) 2261 if (data.feb29 && mFeb29YearlyType == rMar1 && endMonth == 3)
2260 mar1TooEarly = true; 2262 mar1TooEarly = true;
2261 if (data.feb29 && mFeb29YearlyType == rFeb28 && endMonth == 2 && endDay == 28) 2263 if (data.feb29 && mFeb29YearlyType == rFeb28 && endMonth == 2 && endDay == 28)
2262 feb28ok = true; 2264 feb28ok = true;
2263 else if (--endMonth == 0) { 2265 else if (--endMonth == 0) {
2264 endMonth = 12; 2266 endMonth = 12;
2265 --endYear; 2267 --endYear;
2266 } 2268 }
2267 } 2269 }
2268 QValueList<int>::ConstIterator it; 2270 QValueList<int>::ConstIterator it;
2269 const QValueList<int>* mons = data.monthList(); 2271 const QValueList<int>* mons = data.monthList();
2270 2272
2271 if (data.month > 1) { 2273 if (data.month > 1) {
2272 // Check what remains of the start year 2274 // Check what remains of the start year
2273 for (it = mons->begin(); it != mons->end(); ++it) { 2275 for (it = mons->begin(); it != mons->end(); ++it) {
2274 if (*it >= data.month) { 2276 if (*it >= data.month) {
2275 ++countGone; 2277 ++countGone;
2276 if (data.year == endYear 2278 if (data.year == endYear
2277 && ( *it > endMonth && (*it > 3 || !mar1TooEarly) 2279 && ( *it > endMonth && (*it > 3 || !mar1TooEarly)
2278 || *it == 2 && feb28ok && data.leapyear)) { 2280 || *it == 2 && feb28ok && data.leapyear)) {
2279 if (*it == 2 && data.feb29 && !data.leapyear) { 2281 if (*it == 2 && data.feb29 && !data.leapyear) {
2280 // The next recurrence should be on February 29th, but it's a non-leap year 2282 // The next recurrence should be on February 29th, but it's a non-leap year
2281 switch (mFeb29YearlyType) { 2283 switch (mFeb29YearlyType) {
2282 case rFeb28: 2284 case rFeb28:
2283 data.month = 2; 2285 data.month = 2;
2284 data.day = 28; 2286 data.day = 28;
2285 break; 2287 break;
2286 case rMar1: 2288 case rMar1:
2287 data.month = 3; 2289 data.month = 3;
2288 data.day = 1; 2290 data.day = 1;
2289 break; 2291 break;
2290 case rFeb29: // impossible in this context! 2292 case rFeb29: // impossible in this context!
2291 break; 2293 break;
2292 } 2294 }
2293 } 2295 }
2294 else 2296 else
2295 data.month = *it; 2297 data.month = *it;
2296 goto ex; 2298 goto ex;
2297 } 2299 }
2298 if (--countTogo == 0) 2300 if (--countTogo == 0)
2299 return 0; 2301 return 0;
2300 } 2302 }
2301 } 2303 }
2302 data.month = 1; 2304 data.month = 1;
2303 data.year += rFreq; 2305 data.year += rFreq;
2304 } 2306 }
2305 2307
2306 if (data.feb29 && mFeb29YearlyType == rFeb29) { 2308 if (data.feb29 && mFeb29YearlyType == rFeb29) {
2307 // The number of recurrences is different on leap years, 2309 // The number of recurrences is different on leap years,
2308 // so check year-by-year. 2310 // so check year-by-year.
2309 while (data.year <= endYear) { 2311 while (data.year <= endYear) {
2310 mons = data.monthList(); 2312 mons = data.monthList();
2311 if (data.year == endYear && mons->last() > endMonth) 2313 if (data.year == endYear && mons->last() > endMonth)
2312 break; 2314 break;
2313 uint n = mons->count(); 2315 uint n = mons->count();
2314 if (n >= countTogo) 2316 if (n >= countTogo)
2315 break; 2317 break;
2316 countTogo -= n; 2318 countTogo -= n;
2317 countGone += n; 2319 countGone += n;
2318 data.year += rFreq; 2320 data.year += rFreq;
2319 } 2321 }
2320 mons = data.monthList(); 2322 mons = data.monthList();
2321 } else { 2323 } else {
2322 // The number of recurrences is the same every year, 2324 // The number of recurrences is the same every year,
2323 // so skip the year-by-year check. 2325 // so skip the year-by-year check.
2324 // Skip the remaining whole years to at least endYear. 2326 // Skip the remaining whole years to at least endYear.
2325 int monthsPerYear = mons->count(); 2327 int monthsPerYear = mons->count();
2326 int recurYears = (endYear - data.year + rFreq - 1) / rFreq; 2328 int recurYears = (endYear - data.year + rFreq - 1) / rFreq;
2327 if ((endYear - data.year)%rFreq == 0 2329 if ((endYear - data.year)%rFreq == 0
2328 && mons->last() <= endMonth) 2330 && mons->last() <= endMonth)
2329 ++recurYears; // required year is after endYear 2331 ++recurYears; // required year is after endYear
2330 if (recurYears) { 2332 if (recurYears) {
2331 int n = recurYears * monthsPerYear; 2333 int n = recurYears * monthsPerYear;
2332 if (static_cast<uint>(n) > countTogo) 2334 if (static_cast<uint>(n) > countTogo)
2333 return 0; // reached end of recurrence 2335 return 0; // reached end of recurrence
2334 countTogo -= n; 2336 countTogo -= n;
2335 countGone += n; 2337 countGone += n;
2336 data.year += recurYears * rFreq; 2338 data.year += recurYears * rFreq;
2337 } 2339 }
2338 } 2340 }
2339 2341
2340 // Check the last year in the recurrence 2342 // Check the last year in the recurrence
2341 for (it = mons->begin(); it != mons->end(); ++it) { 2343 for (it = mons->begin(); it != mons->end(); ++it) {
2342 ++countGone; 2344 ++countGone;
2343 if (data.year > endYear 2345 if (data.year > endYear
2344 || ( *it > endMonth && (*it > 3 || !mar1TooEarly) 2346 || ( *it > endMonth && (*it > 3 || !mar1TooEarly)
2345 || *it == 2 && feb28ok && QDate::leapYear(data.year))) { 2347 || *it == 2 && feb28ok && QDate::leapYear(data.year))) {
2346 if (*it == 2 && data.feb29 && !QDate::leapYear(data.year)) { 2348 if (*it == 2 && data.feb29 && !QDate::leapYear(data.year)) {
2347 // The next recurrence should be on February 29th, but it's a non-leap year 2349 // The next recurrence should be on February 29th, but it's a non-leap year
2348 switch (mFeb29YearlyType) { 2350 switch (mFeb29YearlyType) {
2349 case rFeb28: 2351 case rFeb28:
2350 data.month = 2; 2352 data.month = 2;
2351 data.day = 28; 2353 data.day = 28;
2352 break; 2354 break;
2353 case rMar1: 2355 case rMar1:
2354 data.month = 3; 2356 data.month = 3;
2355 data.day = 1; 2357 data.day = 1;
2356 break; 2358 break;
2357 case rFeb29: // impossible in this context! 2359 case rFeb29: // impossible in this context!
2358 break; 2360 break;
2359 } 2361 }
2360 } 2362 }
2361 else 2363 else
2362 data.month = *it; 2364 data.month = *it;
2363 break; 2365 break;
2364 } 2366 }
2365 if (--countTogo == 0) 2367 if (--countTogo == 0)
2366 return 0; 2368 return 0;
2367 } 2369 }
2368ex: 2370ex:
2369 enddate = data.date(); 2371 enddate = data.date();
2370 return countGone; 2372 return countGone;
2371} 2373}
2372 2374
2373 2375
2374/* Find count and, depending on 'func', the end date of an annual recurrence by date. 2376/* Find count and, depending on 'func', the end date of an annual recurrence by date.
2375 * Reply = total number of occurrences up to 'enddate', or 0 if error. 2377 * Reply = total number of occurrences up to 'enddate', or 0 if error.
2376 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the 2378 * If 'func' = END_DATE_AND_COUNT or NEXT_AFTER_DATE, 'enddate' is updated to the
2377 * recurrence end date. 2379 * recurrence end date.
2378 */ 2380 */
2379struct Recurrence::YearlyPosData { 2381struct Recurrence::YearlyPosData {
2380 const Recurrence *recurrence; 2382 const Recurrence *recurrence;
2381 int year; // current year 2383 int year; // current year
2382 int month; // current month 1..12 2384 int month; // current month 1..12
2383 int day; // current day of month 1..31 2385 int day; // current day of month 1..31
2384 int daysPerMonth; // number of days which recur each month, or -1 if variable 2386 int daysPerMonth; // number of days which recur each month, or -1 if variable
2385 int count; // number of days which recur each year, or -1 if variable 2387 int count; // number of days which recur each year, or -1 if variable
2386 bool varies; // true if number of days varies from year to year 2388 bool varies; // true if number of days varies from year to year
2387 private: 2389 private:
2388 mutable QValueList<int> days; 2390 mutable QValueList<int> days;
2389 public: 2391 public:
2390 YearlyPosData(const Recurrence* r, const QDate &date) 2392 YearlyPosData(const Recurrence* r, const QDate &date)
2391 : recurrence(r), year(date.year()), month(date.month()), day(date.day()), count(-1) 2393 : recurrence(r), year(date.year()), month(date.month()), day(date.day()), count(-1)
2392 { if ((daysPerMonth = r->countMonthlyPosDays()) > 0) 2394 { if ((daysPerMonth = r->countMonthlyPosDays()) > 0)
2393 count = daysPerMonth * r->rYearNums.count(); 2395 count = daysPerMonth * r->rYearNums.count();
2394 varies = (daysPerMonth < 0); 2396 varies = (daysPerMonth < 0);
2395 } 2397 }
2396 const QValueList<int>* dayList() const { 2398 const QValueList<int>* dayList() const {
2397 QDate startOfMonth(year, month, 1); 2399 QDate startOfMonth(year, month, 1);
2398 recurrence->getMonthlyPosDays(days, startOfMonth.daysInMonth(), startOfMonth.dayOfWeek()); 2400 recurrence->getMonthlyPosDays(days, startOfMonth.daysInMonth(), startOfMonth.dayOfWeek());
2399 return &days; 2401 return &days;
2400 } 2402 }
2401 int yearMonth() const { return year*12 + month - 1; } 2403 int yearMonth() const { return year*12 + month - 1; }
2402 void addMonths(int diff) { month += diff - 1; year += month / 12; month = month % 12 + 1; } 2404 void addMonths(int diff) { month += diff - 1; year += month / 12; month = month % 12 + 1; }
2403 QDate date() const { return QDate(year, month, day); } 2405 QDate date() const { return QDate(year, month, day); }
2404}; 2406};
2405 2407
2406int Recurrence::yearlyPosCalc(PeriodFunc func, QDate &enddate) const 2408int Recurrence::yearlyPosCalc(PeriodFunc func, QDate &enddate) const
2407{ 2409{
2408 if (rYearNums.isEmpty() || rMonthPositions.isEmpty()) 2410 if (rYearNums.isEmpty() || rMonthPositions.isEmpty())
2409 return 0; 2411 return 0;
2410 YearlyPosData data(this, mRecurStart.date()); 2412 YearlyPosData data(this, mRecurStart.date());
2411 switch (func) { 2413 switch (func) {
2412 case END_DATE_AND_COUNT: 2414 case END_DATE_AND_COUNT:
2413 return yearlyPosCalcEndDate(enddate, data); 2415 return yearlyPosCalcEndDate(enddate, data);
2414 case COUNT_TO_DATE: 2416 case COUNT_TO_DATE:
2415 return yearlyPosCalcToDate(enddate, data); 2417 return yearlyPosCalcToDate(enddate, data);
2416 case NEXT_AFTER_DATE: 2418 case NEXT_AFTER_DATE:
2417 return yearlyPosCalcNextAfter(enddate, data); 2419 return yearlyPosCalcNextAfter(enddate, data);
2418 } 2420 }
2419 return 0; 2421 return 0;
2420} 2422}
2421 2423
2422int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const 2424int Recurrence::yearlyPosCalcEndDate(QDate &enddate, YearlyPosData &data) const
2423{ 2425{
2424 uint countTogo = rDuration + mRecurExDatesCount; 2426 uint countTogo = rDuration + mRecurExDatesCount;
2425 int countGone = 0; 2427 int countGone = 0;
2426 QValueList<int>::ConstIterator id; 2428 QValueList<int>::ConstIterator id;
2427 const QValueList<int>* days; 2429 const QValueList<int>* days;
2428 2430
2429 if (data.month > 1 || data.day > 1) { 2431 if (data.month > 1 || data.day > 1) {
2430 // Check what remains of the start year 2432 // Check what remains of the start year
2431 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2433 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2432 if (*im.current() >= data.month) { 2434 if (*im.current() >= data.month) {
2433 // Check what remains of the start month 2435 // Check what remains of the start month
2434 if (data.day > 1 || data.varies 2436 if (data.day > 1 || data.varies
2435 || static_cast<uint>(data.daysPerMonth) >= countTogo) { 2437 || static_cast<uint>(data.daysPerMonth) >= countTogo) {
2436 data.month = *im.current(); 2438 data.month = *im.current();
2437 days = data.dayList(); 2439 days = data.dayList();
2438 for (id = days->begin(); id != days->end(); ++id) { 2440 for (id = days->begin(); id != days->end(); ++id) {
2439 if (*id >= data.day) { 2441 if (*id >= data.day) {
2440 ++countGone; 2442 ++countGone;
2441 if (--countTogo == 0) { 2443 if (--countTogo == 0) {
2442 data.month = *im.current(); 2444 data.month = *im.current();
2443 data.day = *id; 2445 data.day = *id;
2444 goto ex; 2446 goto ex;
2445 } 2447 }
2446 } 2448 }
2447 } 2449 }
2448 data.day = 1; 2450 data.day = 1;
2449 } else { 2451 } else {
2450 // The number of days per month is constant, so skip 2452 // The number of days per month is constant, so skip
2451 // the whole month. 2453 // the whole month.
2452 countTogo -= data.daysPerMonth; 2454 countTogo -= data.daysPerMonth;
2453 countGone += data.daysPerMonth; 2455 countGone += data.daysPerMonth;
2454 } 2456 }
2455 } 2457 }
2456 } 2458 }
2457 data.month = 1; 2459 data.month = 1;
2458 data.year += rFreq; 2460 data.year += rFreq;
2459 } 2461 }
2460 2462
2461 if (data.varies) { 2463 if (data.varies) {
2462 // The number of recurrences varies from year to year. 2464 // The number of recurrences varies from year to year.
2463 for ( ; ; ) { 2465 for ( ; ; ) {
2464 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2466 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2465 data.month = *im.current(); 2467 data.month = *im.current();
2466 days = data.dayList(); 2468 days = data.dayList();
2467 int n = days->count(); 2469 int n = days->count();
2468 if (static_cast<uint>(n) >= countTogo) { 2470 if (static_cast<uint>(n) >= countTogo) {
2469 // Check the last month in the recurrence 2471 // Check the last month in the recurrence
2470 for (id = days->begin(); id != days->end(); ++id) { 2472 for (id = days->begin(); id != days->end(); ++id) {
2471 ++countGone; 2473 ++countGone;
2472 if (--countTogo == 0) { 2474 if (--countTogo == 0) {
2473 data.day = *id; 2475 data.day = *id;
2474 goto ex; 2476 goto ex;
2475 } 2477 }
2476 } 2478 }
2477 } 2479 }
2478 countTogo -= n; 2480 countTogo -= n;
2479 countGone += n; 2481 countGone += n;
2480 } 2482 }
2481 data.year += rFreq; 2483 data.year += rFreq;
2482 } 2484 }
2483 } else { 2485 } else {
2484 // The number of recurrences is the same every year, 2486 // The number of recurrences is the same every year,
2485 // so skip the year-by-year check. 2487 // so skip the year-by-year check.
2486 // Skip the remaining whole years, but leave at least 2488 // Skip the remaining whole years, but leave at least
2487 // 1 recurrence remaining, in order to get its date. 2489 // 1 recurrence remaining, in order to get its date.
2488 int wholeYears = (countTogo - 1) / data.count; 2490 int wholeYears = (countTogo - 1) / data.count;
2489 data.year += wholeYears * rFreq; 2491 data.year += wholeYears * rFreq;
2490 countGone += wholeYears * data.count; 2492 countGone += wholeYears * data.count;
2491 countTogo -= wholeYears * data.count; 2493 countTogo -= wholeYears * data.count;
2492 2494
2493 // Check the last year in the recurrence. 2495 // Check the last year in the recurrence.
2494 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2496 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2495 if (static_cast<uint>(data.daysPerMonth) >= countTogo) { 2497 if (static_cast<uint>(data.daysPerMonth) >= countTogo) {
2496 // Check the last month in the recurrence 2498 // Check the last month in the recurrence
2497 data.month = *im.current(); 2499 data.month = *im.current();
2498 days = data.dayList(); 2500 days = data.dayList();
2499 for (id = days->begin(); id != days->end(); ++id) { 2501 for (id = days->begin(); id != days->end(); ++id) {
2500 ++countGone; 2502 ++countGone;
2501 if (--countTogo == 0) { 2503 if (--countTogo == 0) {
2502 data.day = *id; 2504 data.day = *id;
2503 goto ex; 2505 goto ex;
2504 } 2506 }
2505 } 2507 }
2506 } 2508 }
2507 countTogo -= data.daysPerMonth; 2509 countTogo -= data.daysPerMonth;
2508 countGone += data.daysPerMonth; 2510 countGone += data.daysPerMonth;
2509 } 2511 }
2510 data.year += rFreq; 2512 data.year += rFreq;
2511 } 2513 }
2512ex: 2514ex:
2513 enddate = data.date(); 2515 enddate = data.date();
2514 return countGone; 2516 return countGone;
2515} 2517}
2516 2518
2517int Recurrence::yearlyPosCalcToDate(const QDate &enddate, YearlyPosData &data) const 2519int Recurrence::yearlyPosCalcToDate(const QDate &enddate, YearlyPosData &data) const
2518{ 2520{
2519 int countGone = 0; 2521 int countGone = 0;
2520 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX; 2522 int countMax = (rDuration > 0) ? rDuration + mRecurExDatesCount : INT_MAX;
2521 int endYear = enddate.year(); 2523 int endYear = enddate.year();
2522 int endMonth = enddate.month(); 2524 int endMonth = enddate.month();
2523 int endDay = enddate.day(); 2525 int endDay = enddate.day();
2524 if (endDay < data.day && --endMonth == 0) { 2526 if (endDay < data.day && --endMonth == 0) {
2525 endMonth = 12; 2527 endMonth = 12;
2526 --endYear; 2528 --endYear;
2527 } 2529 }
2528 int endYearMonth = endYear*12 + endMonth; 2530 int endYearMonth = endYear*12 + endMonth;
2529 QValueList<int>::ConstIterator id; 2531 QValueList<int>::ConstIterator id;
2530 const QValueList<int>* days; 2532 const QValueList<int>* days;
2531 2533
2532 if (data.month > 1 || data.day > 1) { 2534 if (data.month > 1 || data.day > 1) {
2533 // Check what remains of the start year 2535 // Check what remains of the start year
2534 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2536 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2535 if (*im.current() >= data.month) { 2537 if (*im.current() >= data.month) {
2536 data.month = *im.current(); 2538 data.month = *im.current();
2537 if (data.yearMonth() > endYearMonth) 2539 if (data.yearMonth() > endYearMonth)
2538 return countGone; 2540 return countGone;
2539 // Check what remains of the start month 2541 // Check what remains of the start month
2540 bool lastMonth = (data.yearMonth() == endYearMonth); 2542 bool lastMonth = (data.yearMonth() == endYearMonth);
2541 if (lastMonth || data.day > 1 || data.varies) { 2543 if (lastMonth || data.day > 1 || data.varies) {
2542 days = data.dayList(); 2544 days = data.dayList();
2543 if (lastMonth || data.day > 1) { 2545 if (lastMonth || data.day > 1) {
2544 for (id = days->begin(); id != days->end(); ++id) { 2546 for (id = days->begin(); id != days->end(); ++id) {
2545 if (*id >= data.day) { 2547 if (*id >= data.day) {
2546 if (lastMonth && *id > endDay) 2548 if (lastMonth && *id > endDay)
2547 return countGone; 2549 return countGone;
2548 if (++countGone >= countMax) 2550 if (++countGone >= countMax)
2549 return countMax; 2551 return countMax;
2550 } 2552 }
2551 } 2553 }
2552 } else { 2554 } else {
2553 countGone += days->count(); 2555 countGone += days->count();
2554 if (countGone >= countMax) 2556 if (countGone >= countMax)
2555 return countMax; 2557 return countMax;
2556 } 2558 }
2557 data.day = 1; 2559 data.day = 1;
2558 } else { 2560 } else {
2559 // The number of days per month is constant, so skip 2561 // The number of days per month is constant, so skip
2560 // the whole month. 2562 // the whole month.
2561 countGone += data.daysPerMonth; 2563 countGone += data.daysPerMonth;
2562 if (countGone >= countMax) 2564 if (countGone >= countMax)
2563 return countMax; 2565 return countMax;
2564 } 2566 }
2565 } 2567 }
2566 } 2568 }
2567 data.month = 1; 2569 data.month = 1;
2568 data.year += rFreq; 2570 data.year += rFreq;
2569 } 2571 }
2570 2572
2571 if (data.varies) { 2573 if (data.varies) {
2572 // The number of recurrences varies from year to year. 2574 // The number of recurrences varies from year to year.
2573 for ( ; ; ) { 2575 for ( ; ; ) {
2574 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2576 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2575 data.month = *im.current(); 2577 data.month = *im.current();
2576 days = data.dayList(); 2578 days = data.dayList();
2577 if (data.yearMonth() >= endYearMonth) { 2579 if (data.yearMonth() >= endYearMonth) {
2578 if (data.yearMonth() > endYearMonth) 2580 if (data.yearMonth() > endYearMonth)
2579 return countGone; 2581 return countGone;
2580 // Check the last month in the recurrence 2582 // Check the last month in the recurrence
2581 for (id = days->begin(); id != days->end(); ++id) { 2583 for (id = days->begin(); id != days->end(); ++id) {
2582 if (*id > endDay) 2584 if (*id > endDay)
2583 return countGone; 2585 return countGone;
2584 if (++countGone >= countMax) 2586 if (++countGone >= countMax)
2585 return countMax; 2587 return countMax;
2586 } 2588 }
2587 } else { 2589 } else {
2588 countGone += days->count(); 2590 countGone += days->count();
2589 if (countGone >= countMax) 2591 if (countGone >= countMax)
2590 return countMax; 2592 return countMax;
2591 } 2593 }
2592 } 2594 }
2593 data.year += rFreq; 2595 data.year += rFreq;
2594 } 2596 }
2595 } else { 2597 } else {
2596 // The number of recurrences is the same every year, 2598 // The number of recurrences is the same every year,
2597 // so skip the year-by-year check. 2599 // so skip the year-by-year check.
2598 // Skip the remaining whole years, but leave at least 2600 // Skip the remaining whole years, but leave at least
2599 // 1 recurrence remaining, in order to get its date. 2601 // 1 recurrence remaining, in order to get its date.
2600 int wholeYears = endYear - data.year; 2602 int wholeYears = endYear - data.year;
2601 countGone += (wholeYears / rFreq) * data.count; 2603 countGone += (wholeYears / rFreq) * data.count;
2602 if (countGone >= countMax) 2604 if (countGone >= countMax)
2603 return countMax; 2605 return countMax;
2604 if (wholeYears % rFreq) 2606 if (wholeYears % rFreq)
2605 return countGone; // end year isn't a recurrence year 2607 return countGone; // end year isn't a recurrence year
2606 data.year = endYear; 2608 data.year = endYear;
2607 2609
2608 // Check the last year in the recurrence. 2610 // Check the last year in the recurrence.
2609 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2611 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2610 data.month = *im.current(); 2612 data.month = *im.current();
2611 if (data.month >= endMonth) { 2613 if (data.month >= endMonth) {
2612 if (data.month > endMonth) 2614 if (data.month > endMonth)
2613 return countGone; 2615 return countGone;
2614 // Check the last month in the recurrence 2616 // Check the last month in the recurrence
2615 days = data.dayList(); 2617 days = data.dayList();
2616 for (id = days->begin(); id != days->end(); ++id) { 2618 for (id = days->begin(); id != days->end(); ++id) {
2617 if (*id > endDay) 2619 if (*id > endDay)
2618 return countGone; 2620 return countGone;
2619 if (++countGone >= countMax) 2621 if (++countGone >= countMax)
2620 return countMax; 2622 return countMax;
2621 } 2623 }
2622 } else { 2624 } else {
2623 countGone += data.daysPerMonth; 2625 countGone += data.daysPerMonth;
2624 if (countGone >= countMax) 2626 if (countGone >= countMax)
2625 return countMax; 2627 return countMax;
2626 } 2628 }
2627 } 2629 }
2628 } 2630 }
2629 return countGone; 2631 return countGone;
2630} 2632}
2631 2633
2632int Recurrence::yearlyPosCalcNextAfter(QDate &enddate, YearlyPosData &data) const 2634int Recurrence::yearlyPosCalcNextAfter(QDate &enddate, YearlyPosData &data) const
2633{ 2635{
2634 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX; 2636 uint countTogo = (rDuration > 0) ? rDuration + mRecurExDatesCount : UINT_MAX;
2635 int countGone = 0; 2637 int countGone = 0;
2636 int endYear = enddate.year(); 2638 int endYear = enddate.year();
2637 int endMonth = enddate.month(); 2639 int endMonth = enddate.month();
2638 int endDay = enddate.day(); 2640 int endDay = enddate.day();
2639 if (endDay < data.day && --endMonth == 0) { 2641 if (endDay < data.day && --endMonth == 0) {
2640 endMonth = 12; 2642 endMonth = 12;
2641 --endYear; 2643 --endYear;
2642 } 2644 }
2643 int endYearMonth = endYear*12 + endMonth; 2645 int endYearMonth = endYear*12 + endMonth;
2644 QValueList<int>::ConstIterator id; 2646 QValueList<int>::ConstIterator id;
2645 const QValueList<int>* days; 2647 const QValueList<int>* days;
2646 2648
2647 if (data.varies) { 2649 if (data.varies) {
2648 // The number of recurrences varies from year to year. 2650 // The number of recurrences varies from year to year.
2649 for ( ; ; ) { 2651 for ( ; ; ) {
2650 // Check the next year 2652 // Check the next year
2651 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2653 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2652 if (*im.current() >= data.month) { 2654 if (*im.current() >= data.month) {
2653 // Check the next month 2655 // Check the next month
2654 data.month = *im.current(); 2656 data.month = *im.current();
2655 int ended = data.yearMonth() - endYearMonth; 2657 int ended = data.yearMonth() - endYearMonth;
2656 days = data.dayList(); 2658 days = data.dayList();
2657 if (ended >= 0 || data.day > 1) { 2659 if (ended >= 0 || data.day > 1) {
2658 // This is the start or end month, so check each day 2660 // This is the start or end month, so check each day
2659 for (id = days->begin(); id != days->end(); ++id) { 2661 for (id = days->begin(); id != days->end(); ++id) {
2660 if (*id >= data.day) { 2662 if (*id >= data.day) {
2661 ++countGone; 2663 ++countGone;
2662 if (ended > 0 || (ended == 0 && *id > endDay)) { 2664 if (ended > 0 || (ended == 0 && *id > endDay)) {
2663 data.day = *id; 2665 data.day = *id;
2664 goto ex; 2666 goto ex;
2665 } 2667 }
2666 if (--countTogo == 0) 2668 if (--countTogo == 0)
2667 return 0; 2669 return 0;
2668 } 2670 }
2669 } 2671 }
2670 } else { 2672 } else {
2671 // Skip the whole month 2673 // Skip the whole month
2672 uint n = days->count(); 2674 uint n = days->count();
2673 if (n >= countTogo) 2675 if (n >= countTogo)
2674 return 0; 2676 return 0;
2675 countGone += n; 2677 countGone += n;
2676 } 2678 }
2677 data.day = 1; // we've checked the start month now 2679 data.day = 1; // we've checked the start month now
2678 } 2680 }
2679 } 2681 }
2680 data.month = 1; // we've checked the start year now 2682 data.month = 1; // we've checked the start year now
2681 data.year += rFreq; 2683 data.year += rFreq;
2682 } 2684 }
2683 } else { 2685 } else {
2684 // The number of recurrences is the same every year. 2686 // The number of recurrences is the same every year.
2685 if (data.month > 1 || data.day > 1) { 2687 if (data.month > 1 || data.day > 1) {
2686 // Check what remains of the start year 2688 // Check what remains of the start year
2687 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) { 2689 for (QPtrListIterator<int> im(rYearNums); im.current(); ++im) {
2688 if (*im.current() >= data.month) { 2690 if (*im.current() >= data.month) {
2689 // Check what remains of the start month 2691 // Check what remains of the start month
2690 data.month = *im.current(); 2692 data.month = *im.current();
2691 int ended = data.yearMonth() - endYearMonth; 2693 int ended = data.yearMonth() - endYearMonth;
2692 if (ended >= 0 || data.day > 1) { 2694 if (ended >= 0 || data.day > 1) {
2693 // This is the start or end month, so check each day 2695 // This is the start or end month, so check each day
2694 days = data.dayList(); 2696 days = data.dayList();
2695 for (id = days->begin(); id != days->end(); ++id) { 2697 for (id = days->begin(); id != days->end(); ++id) {
2696 if (*id >= data.day) { 2698 if (*id >= data.day) {
2697 ++countGone; 2699 ++countGone;
2698 if (ended > 0 || (ended == 0 && *id > endDay)) { 2700 if (ended > 0 || (ended == 0 && *id > endDay)) {
2699 data.day = *id; 2701 data.day = *id;
2700 goto ex; 2702 goto ex;
2701 } 2703 }
2702 if (--countTogo == 0) 2704 if (--countTogo == 0)
2703 return 0; 2705 return 0;
2704 } 2706 }
diff --git a/microkde/kdeui/ktoolbar.cpp b/microkde/kdeui/ktoolbar.cpp
index 09ad0c8..35d4916 100644
--- a/microkde/kdeui/ktoolbar.cpp
+++ b/microkde/kdeui/ktoolbar.cpp
@@ -1,2266 +1,2266 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright 2 Copyright
3 (C) 2000 Reginald Stadlbauer (reggie@kde.org) 3 (C) 2000 Reginald Stadlbauer (reggie@kde.org)
4 (C) 1997, 1998 Stephan Kulow (coolo@kde.org) 4 (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
5 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) 5 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
6 (C) 1997, 1998 Sven Radej (radej@kde.org) 6 (C) 1997, 1998 Sven Radej (radej@kde.org)
7 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) 7 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
8 (C) 1999 Chris Schlaeger (cs@kde.org) 8 (C) 1999 Chris Schlaeger (cs@kde.org)
9 (C) 1999 Kurt Granroth (granroth@kde.org) 9 (C) 1999 Kurt Granroth (granroth@kde.org)
10 10
11 This library is free software; you can redistribute it and/or 11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public 12 modify it under the terms of the GNU Library General Public
13 License version 2 as published by the Free Software Foundation. 13 License version 2 as published by the Free Software Foundation.
14 14
15 This library is distributed in the hope that it will be useful, 15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details. 18 Library General Public License for more details.
19 19
20 You should have received a copy of the GNU Library General Public License 20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to 21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. 23 Boston, MA 02111-1307, USA.
24*/ 24*/
25 25
26#ifdef KDE_USE_FINAL 26#ifdef KDE_USE_FINAL
27#undef Always 27#undef Always
28#include <qdockwindow.h> 28#include <qdockwindow.h>
29#endif 29#endif
30 30
31 31
32 32
33#include "ktoolbar.h" 33#include "ktoolbar.h"
34#include "kmainwindow.h" 34#include "kmainwindow.h"
35 35
36#include <string.h> 36#include <string.h>
37 37
38#include <qpainter.h> 38#include <qpainter.h>
39#include <qtooltip.h> 39#include <qtooltip.h>
40#include <qdrawutil.h> 40#include <qdrawutil.h>
41#include <qstring.h> 41#include <qstring.h>
42#include <qrect.h> 42#include <qrect.h>
43#include <qobjectlist.h> 43#include <qobjectlist.h>
44#include <qtimer.h> 44#include <qtimer.h>
45#include <qstyle.h> 45#include <qstyle.h>
46#include <qapplication.h> 46#include <qapplication.h>
47 47
48//US #include <config.h> 48//US #include <config.h>
49 49
50#include "klineedit.h" 50#include "klineedit.h"
51#include "kseparator.h" 51#include "kseparator.h"
52#include <klocale.h> 52#include <klocale.h>
53#include <kapplication.h> 53#include <kapplication.h>
54#include <kaction.h> 54#include <kaction.h>
55#include <kstdaction.h> 55#include <kstdaction.h>
56#include <kglobal.h> 56#include <kglobal.h>
57#include <kconfig.h> 57#include <kconfig.h>
58#include <kiconloader.h> 58#include <kiconloader.h>
59#include <kcombobox.h> 59#include <kcombobox.h>
60//US #include <kpopupmenu.h> 60//US #include <kpopupmenu.h>
61//US #include <kanimwidget.h> 61//US #include <kanimwidget.h>
62//US #include <kipc.h> 62//US #include <kipc.h>
63//US #include <kwin.h> 63//US #include <kwin.h>
64#include <kdebug.h> 64#include <kdebug.h>
65#include <qlayout.h> 65#include <qlayout.h>
66 66
67#include "ktoolbarbutton.h" 67#include "ktoolbarbutton.h"
68 68
69//US 69//US
70#include "kconfigbase.h" 70#include "kconfigbase.h"
71 71
72#include <qpopupmenu.h> 72#include <qpopupmenu.h>
73#include <qmainwindow.h> 73#include <qmainwindow.h>
74 74
75enum { 75enum {
76 CONTEXT_TOP = 0, 76 CONTEXT_TOP = 0,
77 CONTEXT_LEFT = 1, 77 CONTEXT_LEFT = 1,
78 CONTEXT_RIGHT = 2, 78 CONTEXT_RIGHT = 2,
79 CONTEXT_BOTTOM = 3, 79 CONTEXT_BOTTOM = 3,
80 CONTEXT_FLOAT = 4, 80 CONTEXT_FLOAT = 4,
81 CONTEXT_FLAT = 5, 81 CONTEXT_FLAT = 5,
82 CONTEXT_ICONS = 6, 82 CONTEXT_ICONS = 6,
83 CONTEXT_TEXT = 7, 83 CONTEXT_TEXT = 7,
84 CONTEXT_TEXTRIGHT = 8, 84 CONTEXT_TEXTRIGHT = 8,
85 CONTEXT_TEXTUNDER = 9, 85 CONTEXT_TEXTUNDER = 9,
86 CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything else before 86 CONTEXT_ICONSIZES = 50 // starting point for the icon size list, put everything else before
87}; 87};
88 88
89class KToolBarPrivate 89class KToolBarPrivate
90{ 90{
91public: 91public:
92 KToolBarPrivate() { 92 KToolBarPrivate() {
93 m_iconSize = 0; 93 m_iconSize = 0;
94 m_iconText = KToolBar::IconOnly; 94 m_iconText = KToolBar::IconOnly;
95 m_highlight = true; 95 m_highlight = true;
96 m_transparent = true; 96 m_transparent = true;
97 m_honorStyle = false; 97 m_honorStyle = false;
98 98
99 m_enableContext = true; 99 m_enableContext = true;
100 100
101 m_xmlguiClient = 0; 101 m_xmlguiClient = 0;
102 m_configurePlugged = false; 102 m_configurePlugged = false;
103 103
104//US oldPos = Qt::DockUnmanaged; 104//US oldPos = Qt::DockUnmanaged;
105 oldPos = QMainWindow::Unmanaged; 105 oldPos = QMainWindow::Unmanaged;
106 106
107 modified = m_isHorizontal = positioned = FALSE; 107 modified = m_isHorizontal = positioned = FALSE;
108 108
109 HiddenDefault = false; 109 HiddenDefault = false;
110 IconSizeDefault = 0; 110 IconSizeDefault = 0;
111 IconTextDefault = "IconOnly"; 111 IconTextDefault = "IconOnly";
112 IndexDefault = -1; 112 IndexDefault = -1;
113 NewLineDefault = false; 113 NewLineDefault = false;
114 OffsetDefault = -1; 114 OffsetDefault = -1;
115 PositionDefault = "Top"; 115 PositionDefault = "Top";
116 idleButtons.setAutoDelete(true); 116 idleButtons.setAutoDelete(true);
117 } 117 }
118 118
119 int m_iconSize; 119 int m_iconSize;
120 KToolBar::IconText m_iconText; 120 KToolBar::IconText m_iconText;
121 bool m_highlight : 1; 121 bool m_highlight : 1;
122 bool m_transparent : 1; 122 bool m_transparent : 1;
123 bool m_honorStyle : 1; 123 bool m_honorStyle : 1;
124 bool m_isHorizontal : 1; 124 bool m_isHorizontal : 1;
125 bool m_enableContext : 1; 125 bool m_enableContext : 1;
126 bool m_configurePlugged : 1; 126 bool m_configurePlugged : 1;
127 bool modified : 1; 127 bool modified : 1;
128 bool positioned : 1; 128 bool positioned : 1;
129 129
130 QWidget *m_parent; 130 QWidget *m_parent;
131 131
132 QMainWindow::ToolBarDock oldPos; 132 QMainWindow::ToolBarDock oldPos;
133 133
134 KXMLGUIClient *m_xmlguiClient; 134 KXMLGUIClient *m_xmlguiClient;
135 135
136 struct ToolBarInfo 136 struct ToolBarInfo
137 { 137 {
138//US ToolBarInfo() : index( 0 ), offset( -1 ), newline( FALSE ), dock( Qt::DockTop ) {} 138//US ToolBarInfo() : index( 0 ), offset( -1 ), newline( FALSE ), dock( Qt::DockTop ) {}
139 ToolBarInfo() : index( 0 ), offset( -1 ), newline( FALSE ), dock( QMainWindow::Top ) {} 139 ToolBarInfo() : index( 0 ), offset( -1 ), newline( FALSE ), dock( QMainWindow::Top ) {}
140//US ToolBarInfo( Qt::Dock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {} 140//US ToolBarInfo( Qt::Dock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {}
141 ToolBarInfo( QMainWindow::ToolBarDock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {} 141 ToolBarInfo( QMainWindow::ToolBarDock d, int i, bool n, int o ) : index( i ), offset( o ), newline( n ), dock( d ) {}
142 int index, offset; 142 int index, offset;
143 bool newline; 143 bool newline;
144//US Qt::Dock dock; 144//US Qt::Dock dock;
145 QMainWindow::ToolBarDock dock; 145 QMainWindow::ToolBarDock dock;
146 }; 146 };
147 147
148 ToolBarInfo toolBarInfo; 148 ToolBarInfo toolBarInfo;
149 QValueList<int> iconSizes; 149 QValueList<int> iconSizes;
150 QTimer repaintTimer; 150 QTimer repaintTimer;
151 151
152 // Default Values. 152 // Default Values.
153 bool HiddenDefault; 153 bool HiddenDefault;
154 int IconSizeDefault; 154 int IconSizeDefault;
155 QString IconTextDefault; 155 QString IconTextDefault;
156 int IndexDefault; 156 int IndexDefault;
157 bool NewLineDefault; 157 bool NewLineDefault;
158 int OffsetDefault; 158 int OffsetDefault;
159 QString PositionDefault; 159 QString PositionDefault;
160 160
161 QPtrList<QWidget> idleButtons; 161 QPtrList<QWidget> idleButtons;
162}; 162};
163 163
164KToolBarSeparator::KToolBarSeparator(Orientation o , bool l, QToolBar *parent, 164KToolBarSeparator::KToolBarSeparator(Orientation o , bool l, QToolBar *parent,
165 const char* name ) 165 const char* name )
166 :QFrame( parent, name ), line( l ) 166 :QFrame( parent, name ), line( l )
167{ 167{
168 connect( parent, SIGNAL(orientationChanged(Orientation)), 168 connect( parent, SIGNAL(orientationChanged(Orientation)),
169 this, SLOT(setOrientation(Orientation)) ); 169 this, SLOT(setOrientation(Orientation)) );
170 setOrientation( o ); 170 setOrientation( o );
171 setBackgroundMode( parent->backgroundMode() ); 171 setBackgroundMode( parent->backgroundMode() );
172 setBackgroundOrigin( ParentOrigin ); 172 setBackgroundOrigin( ParentOrigin );
173} 173}
174 174
175void KToolBarSeparator::setOrientation( Orientation o ) 175void KToolBarSeparator::setOrientation( Orientation o )
176{ 176{
177 orient = o; 177 orient = o;
178 if ( line ) { 178 if ( line ) {
179 if ( orientation() == Vertical ) 179 if ( orientation() == Vertical )
180 setFrameStyle( HLine + Sunken ); 180 setFrameStyle( HLine + Sunken );
181 else 181 else
182 setFrameStyle( VLine + Sunken ); 182 setFrameStyle( VLine + Sunken );
183 } else { 183 } else {
184 setFrameStyle( NoFrame ); 184 setFrameStyle( NoFrame );
185 } 185 }
186} 186}
187 187
188void KToolBarSeparator::styleChange( QStyle& ) 188void KToolBarSeparator::styleChange( QStyle& )
189{ 189{
190 setOrientation( orient ); 190 setOrientation( orient );
191} 191}
192 192
193QSize KToolBarSeparator::sizeHint() const 193QSize KToolBarSeparator::sizeHint() const
194{ 194{
195 return orientation() == Vertical ? QSize( 0, 6 ) : QSize( 6, 0 ); 195 return orientation() == Vertical ? QSize( 0, 6 ) : QSize( 6, 0 );
196} 196}
197 197
198QSizePolicy KToolBarSeparator::sizePolicy() const 198QSizePolicy KToolBarSeparator::sizePolicy() const
199{ 199{
200 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); 200 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
201} 201}
202 202
203KToolBar::KToolBar( QWidget *parent, const char *name, bool honorStyle, bool readConfig ) 203KToolBar::KToolBar( QWidget *parent, const char *name, bool honorStyle, bool readConfig )
204#ifdef DESKTOP_VERSION 204#ifdef DESKTOP_VERSION
205 : QToolBar( QString::fromLatin1( name ), 205 : QToolBar( QString::fromLatin1( name ),
206 parent && parent->inherits( "QMainWindow" ) ? static_cast<QMainWindow*>(parent) : 0, 206 parent && parent->inherits( "QMainWindow" ) ? static_cast<QMainWindow*>(parent) : 0,
207 parent, FALSE, 207 parent, FALSE,
208 name ? name : "mainToolBar") 208 name ? name : "mainToolBar")
209#else 209#else
210 : QPEToolBar( parent && parent->inherits( "QMainWindow" ) ? static_cast<QMainWindow*>(parent) : 0, 210 : QPEToolBar( parent && parent->inherits( "QMainWindow" ) ? static_cast<QMainWindow*>(parent) : 0,
211 QString::fromLatin1( name )) 211 QString::fromLatin1( name ))
212 212
213 213
214#endif 214#endif
215{ 215{
216 init( readConfig, honorStyle ); 216 init( readConfig, honorStyle );
217} 217}
218 218
219KToolBar::KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) 219KToolBar::KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock, bool newLine, const char *name, bool honorStyle, bool readConfig )
220#ifdef DESKTOP_VERSION 220#ifdef DESKTOP_VERSION
221 : QToolBar( QString::fromLatin1( name ), 221 : QToolBar( QString::fromLatin1( name ),
222 parentWindow, dock, newLine, 222 parentWindow, dock, newLine,
223 name ? name : "mainToolBar") 223 name ? name : "mainToolBar")
224#else 224#else
225 : QPEToolBar( parentWindow,QString::fromLatin1( name )) 225 : QPEToolBar( parentWindow,QString::fromLatin1( name ))
226 226
227 227
228#endif 228#endif
229 229
230{ 230{
231 init( readConfig, honorStyle ); 231 init( readConfig, honorStyle );
232} 232}
233 233
234KToolBar::KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine, const char *name, bool honorStyle, bool readConfig ) 234KToolBar::KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine, const char *name, bool honorStyle, bool readConfig )
235#ifdef DESKTOP_VERSION 235#ifdef DESKTOP_VERSION
236 : QToolBar( QString::fromLatin1( name ), 236 : QToolBar( QString::fromLatin1( name ),
237 parentWindow, dock, newLine, 237 parentWindow, dock, newLine,
238 name ? name : "mainToolBar") 238 name ? name : "mainToolBar")
239#else 239#else
240 : QPEToolBar( parentWindow,QString::fromLatin1( name )) 240 : QPEToolBar( parentWindow,QString::fromLatin1( name ))
241 241
242 242
243#endif 243#endif
244 244
245{ 245{
246 init( readConfig, honorStyle ); 246 init( readConfig, honorStyle );
247} 247}
248 248
249KToolBar::~KToolBar() 249KToolBar::~KToolBar()
250{ 250{
251 inshutdownprocess = true; 251 inshutdownprocess = true;
252 emit toolbarDestroyed(); 252 emit toolbarDestroyed();
253 delete d; 253 delete d;
254} 254}
255 255
256void KToolBar::init( bool readConfig, bool honorStyle ) 256void KToolBar::init( bool readConfig, bool honorStyle )
257{ 257{
258 inshutdownprocess = false; 258 inshutdownprocess = false;
259 d = new KToolBarPrivate; 259 d = new KToolBarPrivate;
260 setFullSize( TRUE ); 260 setFullSize( TRUE );
261 d->m_honorStyle = honorStyle; 261 d->m_honorStyle = honorStyle;
262 context = 0; 262 context = 0;
263 layoutTimer = new QTimer( this ); 263 layoutTimer = new QTimer( this );
264 connect( layoutTimer, SIGNAL( timeout() ), 264 connect( layoutTimer, SIGNAL( timeout() ),
265 this, SLOT( rebuildLayout() ) ); 265 this, SLOT( rebuildLayout() ) );
266 connect( &(d->repaintTimer), SIGNAL( timeout() ), 266 connect( &(d->repaintTimer), SIGNAL( timeout() ),
267 this, SLOT( slotRepaint() ) ); 267 this, SLOT( slotRepaint() ) );
268/*US 268/*US
269 if ( kapp ) { // may be null when started inside designer 269 if ( kapp ) { // may be null when started inside designer
270 connect(kapp, SIGNAL(toolbarAppearanceChanged(int)), this, SLOT(slotAppearanceChanged())); 270 connect(kapp, SIGNAL(toolbarAppearanceChanged(int)), this, SLOT(slotAppearanceChanged()));
271 // request notification of changes in icon style 271 // request notification of changes in icon style
272 kapp->addKipcEventMask(KIPC::IconChanged); 272 kapp->addKipcEventMask(KIPC::IconChanged);
273 connect(kapp, SIGNAL(iconChanged(int)), this, SLOT(slotIconChanged(int))); 273 connect(kapp, SIGNAL(iconChanged(int)), this, SLOT(slotIconChanged(int)));
274 } 274 }
275*/ 275*/
276 // finally, read in our configurable settings 276 // finally, read in our configurable settings
277 if ( readConfig ) 277 if ( readConfig )
278 slotReadConfig(); 278 slotReadConfig();
279 279
280 if ( mainWindow() ) 280 if ( mainWindow() )
281 connect( mainWindow(), SIGNAL( toolBarPositionChanged( QToolBar * ) ), 281 connect( mainWindow(), SIGNAL( toolBarPositionChanged( QToolBar * ) ),
282 this, SLOT( toolBarPosChanged( QToolBar * ) ) ); 282 this, SLOT( toolBarPosChanged( QToolBar * ) ) );
283 283
284 // Hack to make sure we recalculate our size when we dock. 284 // Hack to make sure we recalculate our size when we dock.
285//US connect( this, SIGNAL(placeChanged(QDockWindow::Place)), SLOT(rebuildLayout()) ); 285//US connect( this, SIGNAL(placeChanged(QDockWindow::Place)), SLOT(rebuildLayout()) );
286} 286}
287 287
288int KToolBar::insertButton(const QString& icon, int id, bool enabled, 288int KToolBar::insertButton(const QString& icon, int id, bool enabled,
289 const QString& text, int index/*US, KInstance *_instance*/ ) 289 const QString& text, int index/*US, KInstance *_instance*/ )
290{ 290{
291 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text/*US, _instance*/ ); 291 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text/*US, _instance*/ );
292 292
293 insertWidgetInternal( button, index, id ); 293 insertWidgetInternal( button, index, id );
294 button->setEnabled( enabled ); 294 button->setEnabled( enabled );
295 doConnections( button ); 295 doConnections( button );
296 return index; 296 return index;
297} 297}
298 298
299 299
300int KToolBar::insertButton(const QString& icon, int id, const char *signal, 300int KToolBar::insertButton(const QString& icon, int id, const char *signal,
301 const QObject *receiver, const char *slot, 301 const QObject *receiver, const char *slot,
302 bool enabled, const QString& text, int index/*US, KInstance *_instance*/ ) 302 bool enabled, const QString& text, int index/*US, KInstance *_instance*/ )
303{ 303{
304 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text/*US, _instance*/); 304 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text/*US, _instance*/);
305 insertWidgetInternal( button, index, id ); 305 insertWidgetInternal( button, index, id );
306 button->setEnabled( enabled ); 306 button->setEnabled( enabled );
307 connect( button, signal, receiver, slot ); 307 connect( button, signal, receiver, slot );
308 doConnections( button ); 308 doConnections( button );
309 return index; 309 return index;
310} 310}
311 311
312 312
313int KToolBar::insertButton(const QPixmap& pixmap, int id, bool enabled, 313int KToolBar::insertButton(const QPixmap& pixmap, int id, bool enabled,
314 const QString& text, int index ) 314 const QString& text, int index )
315{ 315{
316 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text); 316 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text);
317 insertWidgetInternal( button, index, id ); 317 insertWidgetInternal( button, index, id );
318 button->setEnabled( enabled ); 318 button->setEnabled( enabled );
319 doConnections( button ); 319 doConnections( button );
320 return index; 320 return index;
321} 321}
322#if 0 322#if 0
323 bar->insertButton( icon, id_, SIGNAL( clicked() ), this, 323 bar->insertButton( icon, id_, SIGNAL( clicked() ), this,
324 SLOT( slotActivated() ), 324 SLOT( slotActivated() ),
325 d->isEnabled(), d->plainText(), index/*US, instance*/ ); 325 d->isEnabled(), d->plainText(), index/*US, instance*/ );
326#endif 326#endif
327 327
328int KToolBar::insertButton(const QPixmap& pixmap, int id, const char *signal, 328int KToolBar::insertButton(const QPixmap& pixmap, int id, const char *signal,
329 const QObject *receiver, const char *slot, 329 const QObject *receiver, const char *slot,
330 bool enabled, const QString& text, 330 bool enabled, const QString& text,
331 int index ) 331 int index )
332{ 332{
333 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text); 333 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text);
334 insertWidgetInternal( button, index, id ); 334 insertWidgetInternal( button, index, id );
335 button->setEnabled( enabled ); 335 button->setEnabled( enabled );
336 connect( button, signal, receiver, slot ); 336 connect( button, signal, receiver, slot );
337 doConnections( button ); 337 doConnections( button );
338 return index; 338 return index;
339} 339}
340 340
341 341
342int KToolBar::insertButton(const QString& icon, int id, QPopupMenu *popup, 342int KToolBar::insertButton(const QString& icon, int id, QPopupMenu *popup,
343 bool enabled, const QString &text, int index ) 343 bool enabled, const QString &text, int index )
344{ 344{
345 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text ); 345 KToolBarButton *button = new KToolBarButton( icon, id, this, 0, text );
346 insertWidgetInternal( button, index, id ); 346 insertWidgetInternal( button, index, id );
347 button->setEnabled( enabled ); 347 button->setEnabled( enabled );
348 button->setPopup( popup ); 348 button->setPopup( popup );
349 doConnections( button ); 349 doConnections( button );
350 return index; 350 return index;
351} 351}
352 352
353 353
354int KToolBar::insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup, 354int KToolBar::insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
355 bool enabled, const QString &text, int index ) 355 bool enabled, const QString &text, int index )
356{ 356{
357 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text ); 357 KToolBarButton *button = new KToolBarButton( pixmap, id, this, 0, text );
358 insertWidgetInternal( button, index, id ); 358 insertWidgetInternal( button, index, id );
359 button->setEnabled( enabled ); 359 button->setEnabled( enabled );
360 button->setPopup( popup ); 360 button->setPopup( popup );
361 doConnections( button ); 361 doConnections( button );
362 return index; 362 return index;
363} 363}
364 364
365 365
366int KToolBar::insertLined (const QString& text, int id, 366int KToolBar::insertLined (const QString& text, int id,
367 const char *signal, 367 const char *signal,
368 const QObject *receiver, const char *slot, 368 const QObject *receiver, const char *slot,
369 bool enabled , 369 bool enabled ,
370 const QString& toolTipText, 370 const QString& toolTipText,
371 int size, int index ) 371 int size, int index )
372{ 372{
373 KLineEdit *lined = new KLineEdit ( this, 0 ); 373 KLineEdit *lined = new KLineEdit ( this, 0 );
374 if ( !toolTipText.isEmpty() ) 374 if ( !toolTipText.isEmpty() )
375 QToolTip::add( lined, toolTipText ); 375 QToolTip::add( lined, toolTipText );
376 if ( size > 0 ) 376 if ( size > 0 )
377 lined->setMinimumWidth( size ); 377 lined->setMinimumWidth( size );
378 insertWidgetInternal( lined, index, id ); 378 insertWidgetInternal( lined, index, id );
379 connect( lined, signal, receiver, slot ); 379 connect( lined, signal, receiver, slot );
380 lined->setText(text); 380 lined->setText(text);
381 lined->setEnabled( enabled ); 381 lined->setEnabled( enabled );
382 return index; 382 return index;
383} 383}
384 384
385int KToolBar::insertCombo (const QStringList &list, int id, bool writable, 385int KToolBar::insertCombo (const QStringList &list, int id, bool writable,
386 const char *signal, const QObject *receiver, 386 const char *signal, const QObject *receiver,
387 const char *slot, bool enabled, 387 const char *slot, bool enabled,
388 const QString& tooltiptext, 388 const QString& tooltiptext,
389 int size, int index, 389 int size, int index,
390 QComboBox::Policy policy ) 390 QComboBox::Policy policy )
391{ 391{
392//US KComboBox *combo = new KComboBox ( writable, this ); 392//US KComboBox *combo = new KComboBox ( writable, this );
393 KComboBox *combo = new KComboBox ( this ); 393 KComboBox *combo = new KComboBox ( this );
394 combo->setEditable(writable); 394 combo->setEditable(writable);
395 395
396 insertWidgetInternal( combo, index, id ); 396 insertWidgetInternal( combo, index, id );
397 combo->insertStringList (list); 397 combo->insertStringList (list);
398 combo->setInsertionPolicy(policy); 398 combo->setInsertionPolicy(policy);
399 combo->setEnabled( enabled ); 399 combo->setEnabled( enabled );
400 if ( !tooltiptext.isEmpty() ) 400 if ( !tooltiptext.isEmpty() )
401 QToolTip::add( combo, tooltiptext ); 401 QToolTip::add( combo, tooltiptext );
402 if ( size > 0 ) 402 if ( size > 0 )
403 combo->setMinimumWidth( size ); 403 combo->setMinimumWidth( size );
404 if (!tooltiptext.isNull()) 404 if (!tooltiptext.isNull())
405 QToolTip::add( combo, tooltiptext ); 405 QToolTip::add( combo, tooltiptext );
406 406
407 if ( signal && receiver && slot ) 407 if ( signal && receiver && slot )
408 connect ( combo, signal, receiver, slot ); 408 connect ( combo, signal, receiver, slot );
409 return index; 409 return index;
410} 410}
411 411
412 412
413int KToolBar::insertCombo (const QString& text, int id, bool writable, 413int KToolBar::insertCombo (const QString& text, int id, bool writable,
414 const char *signal, QObject *receiver, 414 const char *signal, QObject *receiver,
415 const char *slot, bool enabled, 415 const char *slot, bool enabled,
416 const QString& tooltiptext, 416 const QString& tooltiptext,
417 int size, int index, 417 int size, int index,
418 QComboBox::Policy policy ) 418 QComboBox::Policy policy )
419{ 419{
420//US KComboBox *combo = new KComboBox ( writable, this ); 420//US KComboBox *combo = new KComboBox ( writable, this );
421 KComboBox *combo = new KComboBox ( this ); 421 KComboBox *combo = new KComboBox ( this );
422 combo->setEditable(writable); 422 combo->setEditable(writable);
423 423
424 insertWidgetInternal( combo, index, id ); 424 insertWidgetInternal( combo, index, id );
425 combo->insertItem (text); 425 combo->insertItem (text);
426 combo->setInsertionPolicy(policy); 426 combo->setInsertionPolicy(policy);
427 combo->setEnabled( enabled ); 427 combo->setEnabled( enabled );
428 if ( !tooltiptext.isEmpty() ) 428 if ( !tooltiptext.isEmpty() )
429 QToolTip::add( combo, tooltiptext ); 429 QToolTip::add( combo, tooltiptext );
430 if ( size > 0 ) 430 if ( size > 0 )
431 combo->setMinimumWidth( size ); 431 combo->setMinimumWidth( size );
432 if (!tooltiptext.isNull()) 432 if (!tooltiptext.isNull())
433 QToolTip::add( combo, tooltiptext ); 433 QToolTip::add( combo, tooltiptext );
434 connect (combo, signal, receiver, slot); 434 connect (combo, signal, receiver, slot);
435 return index; 435 return index;
436} 436}
437 437
438int KToolBar::insertSeparator(int index, int id) 438int KToolBar::insertSeparator(int index, int id)
439{ 439{
440 QWidget *w = new KToolBarSeparator( orientation(), FALSE, this, "tool bar separator" ); 440 QWidget *w = new KToolBarSeparator( orientation(), FALSE, this, "tool bar separator" );
441 insertWidgetInternal( w, index, id ); 441 insertWidgetInternal( w, index, id );
442 return index; 442 return index;
443} 443}
444 444
445int KToolBar::insertLineSeparator(int index, int id) 445int KToolBar::insertLineSeparator(int index, int id)
446{ 446{
447 QWidget *w = new KToolBarSeparator( orientation(), TRUE, this, "tool bar separator" ); 447 QWidget *w = new KToolBarSeparator( orientation(), TRUE, this, "tool bar separator" );
448 insertWidgetInternal( w, index, id ); 448 insertWidgetInternal( w, index, id );
449 return index; 449 return index;
450} 450}
451 451
452 452
453int KToolBar::insertWidget(int id, int /*width*/, QWidget *widget, int index) 453int KToolBar::insertWidget(int id, int /*width*/, QWidget *widget, int index)
454{ 454{
455 // removeWidgetInternal( widget ); // in case we already have it ? 455 // removeWidgetInternal( widget ); // in case we already have it ?
456 insertWidgetInternal( widget, index, id ); 456 insertWidgetInternal( widget, index, id );
457 return index; 457 return index;
458} 458}
459/*US 459/*US
460int KToolBar::insertAnimatedWidget(int id, QObject *receiver, const char *slot, 460int KToolBar::insertAnimatedWidget(int id, QObject *receiver, const char *slot,
461 const QString& icons, int index ) 461 const QString& icons, int index )
462{ 462{
463 KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this ); 463 KAnimWidget *anim = new KAnimWidget( icons, d->m_iconSize, this );
464 insertWidgetInternal( anim, index, id ); 464 insertWidgetInternal( anim, index, id );
465 465
466 if ( receiver ) 466 if ( receiver )
467 connect( anim, SIGNAL(clicked()), receiver, slot); 467 connect( anim, SIGNAL(clicked()), receiver, slot);
468 468
469 return index; 469 return index;
470} 470}
471 471
472KAnimWidget *KToolBar::animatedWidget( int id ) 472KAnimWidget *KToolBar::animatedWidget( int id )
473{ 473{
474 Id2WidgetMap::Iterator it = id2widget.find( id ); 474 Id2WidgetMap::Iterator it = id2widget.find( id );
475 if ( it == id2widget.end() ) 475 if ( it == id2widget.end() )
476 return 0; 476 return 0;
477 if ( (*it) && (*it)->inherits( "KAnimWidget" ) ) 477 if ( (*it) && (*it)->inherits( "KAnimWidget" ) )
478 return (KAnimWidget*)(*it); 478 return (KAnimWidget*)(*it);
479 QObjectList *l = queryList( "KAnimWidget" ); 479 QObjectList *l = queryList( "KAnimWidget" );
480 if ( !l || !l->first() ) { 480 if ( !l || !l->first() ) {
481 delete l; 481 delete l;
482 return 0; 482 return 0;
483 } 483 }
484 484
485 for ( QObject *o = l->first(); o; o = l->next() ) { 485 for ( QObject *o = l->first(); o; o = l->next() ) {
486 if ( o->inherits( "KAnimWidget" ) ) 486 if ( o->inherits( "KAnimWidget" ) )
487 { 487 {
488 delete l; 488 delete l;
489 return (KAnimWidget*)o; 489 return (KAnimWidget*)o;
490 } 490 }
491 } 491 }
492 492
493 delete l; 493 delete l;
494 return 0; 494 return 0;
495} 495}
496*/ 496*/
497 497
498void KToolBar::addConnection (int id, const char *signal, 498void KToolBar::addConnection (int id, const char *signal,
499 const QObject *receiver, const char *slot) 499 const QObject *receiver, const char *slot)
500{ 500{
501 Id2WidgetMap::Iterator it = id2widget.find( id ); 501 Id2WidgetMap::Iterator it = id2widget.find( id );
502 if ( it == id2widget.end() ) 502 if ( it == id2widget.end() )
503 return; 503 return;
504 if ( (*it) ) 504 if ( (*it) )
505 connect( (*it), signal, receiver, slot ); 505 connect( (*it), signal, receiver, slot );
506} 506}
507 507
508void KToolBar::setItemEnabled( int id, bool enabled ) 508void KToolBar::setItemEnabled( int id, bool enabled )
509{ 509{
510 Id2WidgetMap::Iterator it = id2widget.find( id ); 510 Id2WidgetMap::Iterator it = id2widget.find( id );
511 if ( it == id2widget.end() ) 511 if ( it == id2widget.end() )
512 return; 512 return;
513 if ( (*it) ) 513 if ( (*it) )
514 (*it)->setEnabled( enabled ); 514 (*it)->setEnabled( enabled );
515} 515}
516 516
517 517
518void KToolBar::setButtonPixmap( int id, const QPixmap& _pixmap ) 518void KToolBar::setButtonPixmap( int id, const QPixmap& _pixmap )
519{ 519{
520 Id2WidgetMap::Iterator it = id2widget.find( id ); 520 Id2WidgetMap::Iterator it = id2widget.find( id );
521 if ( it == id2widget.end() ) 521 if ( it == id2widget.end() )
522 return; 522 return;
523//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 523//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
524 KToolBarButton * button = (KToolBarButton *)( *it ); 524 KToolBarButton * button = (KToolBarButton *)( *it );
525 if ( button ) 525 if ( button )
526 button->setPixmap( _pixmap ); 526 button->setPixmap( _pixmap );
527} 527}
528 528
529 529
530void KToolBar::setButtonIcon( int id, const QString& _icon ) 530void KToolBar::setButtonIcon( int id, const QString& _icon )
531{ 531{
532 Id2WidgetMap::Iterator it = id2widget.find( id ); 532 Id2WidgetMap::Iterator it = id2widget.find( id );
533 if ( it == id2widget.end() ) 533 if ( it == id2widget.end() )
534 return; 534 return;
535//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 535//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
536 KToolBarButton * button = (KToolBarButton *)( *it ); 536 KToolBarButton * button = (KToolBarButton *)( *it );
537 if ( button ) 537 if ( button )
538 button->setIcon( _icon ); 538 button->setIcon( _icon );
539} 539}
540 540
541void KToolBar::setButtonIconSet( int id, const QIconSet& iconset ) 541void KToolBar::setButtonIconSet( int id, const QIconSet& iconset )
542{ 542{
543 Id2WidgetMap::Iterator it = id2widget.find( id ); 543 Id2WidgetMap::Iterator it = id2widget.find( id );
544 if ( it == id2widget.end() ) 544 if ( it == id2widget.end() )
545 return; 545 return;
546//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 546//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
547 KToolBarButton * button = (KToolBarButton *)( *it ); 547 KToolBarButton * button = (KToolBarButton *)( *it );
548 if ( button ) 548 if ( button )
549 button->setIconSet( iconset ); 549 button->setIconSet( iconset );
550} 550}
551 551
552 552
553void KToolBar::setDelayedPopup (int id , QPopupMenu *_popup, bool toggle ) 553void KToolBar::setDelayedPopup (int id , QPopupMenu *_popup, bool toggle )
554{ 554{
555 Id2WidgetMap::Iterator it = id2widget.find( id ); 555 Id2WidgetMap::Iterator it = id2widget.find( id );
556 if ( it == id2widget.end() ) 556 if ( it == id2widget.end() )
557 return; 557 return;
558//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 558//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
559 KToolBarButton * button = (KToolBarButton *)( *it ); 559 KToolBarButton * button = (KToolBarButton *)( *it );
560 if ( button ) 560 if ( button )
561 button->setDelayedPopup( _popup, toggle ); 561 button->setDelayedPopup( _popup, toggle );
562} 562}
563 563
564 564
565void KToolBar::setAutoRepeat (int id, bool flag) 565void KToolBar::setAutoRepeat (int id, bool flag)
566{ 566{
567 Id2WidgetMap::Iterator it = id2widget.find( id ); 567 Id2WidgetMap::Iterator it = id2widget.find( id );
568 if ( it == id2widget.end() ) 568 if ( it == id2widget.end() )
569 return; 569 return;
570//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 570//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
571 KToolBarButton * button = (KToolBarButton *)( *it ); 571 KToolBarButton * button = (KToolBarButton *)( *it );
572 if ( button ) 572 if ( button )
573 button->setAutoRepeat( flag ); 573 button->setAutoRepeat( flag );
574} 574}
575 575
576 576
577void KToolBar::setToggle (int id, bool flag ) 577void KToolBar::setToggle (int id, bool flag )
578{ 578{
579 Id2WidgetMap::Iterator it = id2widget.find( id ); 579 Id2WidgetMap::Iterator it = id2widget.find( id );
580 if ( it == id2widget.end() ) 580 if ( it == id2widget.end() )
581 return; 581 return;
582//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 582//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
583 KToolBarButton * button = (KToolBarButton *)( *it ); 583 KToolBarButton * button = (KToolBarButton *)( *it );
584 if ( button ) 584 if ( button )
585 button->setToggle( flag ); 585 button->setToggle( flag );
586} 586}
587 587
588 588
589void KToolBar::toggleButton (int id) 589void KToolBar::toggleButton (int id)
590{ 590{
591 Id2WidgetMap::Iterator it = id2widget.find( id ); 591 Id2WidgetMap::Iterator it = id2widget.find( id );
592 if ( it == id2widget.end() ) 592 if ( it == id2widget.end() )
593 return; 593 return;
594//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 594//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
595 KToolBarButton * button = (KToolBarButton *)( *it ); 595 KToolBarButton * button = (KToolBarButton *)( *it );
596 if ( button ) 596 if ( button )
597 button->toggle(); 597 button->toggle();
598} 598}
599 599
600 600
601void KToolBar::setButton (int id, bool flag) 601void KToolBar::setButton (int id, bool flag)
602{ 602{
603 Id2WidgetMap::Iterator it = id2widget.find( id ); 603 Id2WidgetMap::Iterator it = id2widget.find( id );
604 if ( it == id2widget.end() ) 604 if ( it == id2widget.end() )
605 return; 605 return;
606//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 606//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
607 KToolBarButton * button = (KToolBarButton *)( *it ); 607 KToolBarButton * button = (KToolBarButton *)( *it );
608 if ( button ) 608 if ( button )
609 button->on( flag ); 609 button->on( flag );
610} 610}
611 611
612 612
613bool KToolBar::isButtonOn (int id) const 613bool KToolBar::isButtonOn (int id) const
614{ 614{
615 Id2WidgetMap::ConstIterator it = id2widget.find( id ); 615 Id2WidgetMap::ConstIterator it = id2widget.find( id );
616 if ( it == id2widget.end() ) 616 if ( it == id2widget.end() )
617 return false; 617 return false;
618//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 618//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
619 KToolBarButton * button = (KToolBarButton *)( *it ); 619 KToolBarButton * button = (KToolBarButton *)( *it );
620 return button ? button->isOn() : false; 620 return button ? button->isOn() : false;
621} 621}
622 622
623 623
624void KToolBar::setLinedText (int id, const QString& text) 624void KToolBar::setLinedText (int id, const QString& text)
625{ 625{
626 Id2WidgetMap::Iterator it = id2widget.find( id ); 626 Id2WidgetMap::Iterator it = id2widget.find( id );
627 if ( it == id2widget.end() ) 627 if ( it == id2widget.end() )
628 return; 628 return;
629//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it ); 629//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it );
630 QLineEdit * lineEdit = (QLineEdit *)( *it ); 630 QLineEdit * lineEdit = (QLineEdit *)( *it );
631 if ( lineEdit ) 631 if ( lineEdit )
632 lineEdit->setText( text ); 632 lineEdit->setText( text );
633} 633}
634 634
635 635
636QString KToolBar::getLinedText (int id) const 636QString KToolBar::getLinedText (int id) const
637{ 637{
638 Id2WidgetMap::ConstIterator it = id2widget.find( id ); 638 Id2WidgetMap::ConstIterator it = id2widget.find( id );
639 if ( it == id2widget.end() ) 639 if ( it == id2widget.end() )
640 return QString::null; 640 return QString::null;
641//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it ); 641//US QLineEdit * lineEdit = dynamic_cast<QLineEdit *>( *it );
642 QLineEdit * lineEdit = (QLineEdit *)( *it ); 642 QLineEdit * lineEdit = (QLineEdit *)( *it );
643 return lineEdit ? lineEdit->text() : QString::null; 643 return lineEdit ? lineEdit->text() : QString::null;
644} 644}
645 645
646 646
647void KToolBar::insertComboItem (int id, const QString& text, int index) 647void KToolBar::insertComboItem (int id, const QString& text, int index)
648{ 648{
649 Id2WidgetMap::Iterator it = id2widget.find( id ); 649 Id2WidgetMap::Iterator it = id2widget.find( id );
650 if ( it == id2widget.end() ) 650 if ( it == id2widget.end() )
651 return; 651 return;
652//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it ); 652//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
653 QComboBox * comboBox = (QComboBox *)( *it ); 653 QComboBox * comboBox = (QComboBox *)( *it );
654 if (comboBox) 654 if (comboBox)
655 comboBox->insertItem( text, index ); 655 comboBox->insertItem( text, index );
656} 656}
657 657
658void KToolBar::insertComboList (int id, const QStringList &list, int index) 658void KToolBar::insertComboList (int id, const QStringList &list, int index)
659{ 659{
660 Id2WidgetMap::Iterator it = id2widget.find( id ); 660 Id2WidgetMap::Iterator it = id2widget.find( id );
661 if ( it == id2widget.end() ) 661 if ( it == id2widget.end() )
662 return; 662 return;
663//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it ); 663//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
664 QComboBox * comboBox = (QComboBox *)( *it ); 664 QComboBox * comboBox = (QComboBox *)( *it );
665 if (comboBox) 665 if (comboBox)
666 comboBox->insertStringList( list, index ); 666 comboBox->insertStringList( list, index );
667} 667}
668 668
669 669
670void KToolBar::removeComboItem (int id, int index) 670void KToolBar::removeComboItem (int id, int index)
671{ 671{
672 Id2WidgetMap::Iterator it = id2widget.find( id ); 672 Id2WidgetMap::Iterator it = id2widget.find( id );
673 if ( it == id2widget.end() ) 673 if ( it == id2widget.end() )
674 return; 674 return;
675//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it ); 675//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
676 QComboBox * comboBox = (QComboBox *)( *it ); 676 QComboBox * comboBox = (QComboBox *)( *it );
677 if (comboBox) 677 if (comboBox)
678 comboBox->removeItem( index ); 678 comboBox->removeItem( index );
679} 679}
680 680
681 681
682void KToolBar::setCurrentComboItem (int id, int index) 682void KToolBar::setCurrentComboItem (int id, int index)
683{ 683{
684 Id2WidgetMap::Iterator it = id2widget.find( id ); 684 Id2WidgetMap::Iterator it = id2widget.find( id );
685 if ( it == id2widget.end() ) 685 if ( it == id2widget.end() )
686 return; 686 return;
687//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it ); 687//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
688 QComboBox * comboBox = (QComboBox *)( *it ); 688 QComboBox * comboBox = (QComboBox *)( *it );
689 if (comboBox) 689 if (comboBox)
690 comboBox->setCurrentItem( index ); 690 comboBox->setCurrentItem( index );
691} 691}
692 692
693 693
694void KToolBar::changeComboItem (int id, const QString& text, int index) 694void KToolBar::changeComboItem (int id, const QString& text, int index)
695{ 695{
696 Id2WidgetMap::Iterator it = id2widget.find( id ); 696 Id2WidgetMap::Iterator it = id2widget.find( id );
697 if ( it == id2widget.end() ) 697 if ( it == id2widget.end() )
698 return; 698 return;
699//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it ); 699//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
700 QComboBox * comboBox = (QComboBox *)( *it ); 700 QComboBox * comboBox = (QComboBox *)( *it );
701 if (comboBox) 701 if (comboBox)
702 comboBox->changeItem( text, index ); 702 comboBox->changeItem( text, index );
703} 703}
704 704
705 705
706void KToolBar::clearCombo (int id) 706void KToolBar::clearCombo (int id)
707{ 707{
708 Id2WidgetMap::Iterator it = id2widget.find( id ); 708 Id2WidgetMap::Iterator it = id2widget.find( id );
709 if ( it == id2widget.end() ) 709 if ( it == id2widget.end() )
710 return; 710 return;
711//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it ); 711//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
712 QComboBox * comboBox = (QComboBox *)( *it ); 712 QComboBox * comboBox = (QComboBox *)( *it );
713 if (comboBox) 713 if (comboBox)
714 comboBox->clear(); 714 comboBox->clear();
715} 715}
716 716
717 717
718QString KToolBar::getComboItem (int id, int index) const 718QString KToolBar::getComboItem (int id, int index) const
719{ 719{
720 Id2WidgetMap::ConstIterator it = id2widget.find( id ); 720 Id2WidgetMap::ConstIterator it = id2widget.find( id );
721 if ( it == id2widget.end() ) 721 if ( it == id2widget.end() )
722 return QString::null; 722 return QString::null;
723//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it ); 723//US QComboBox * comboBox = dynamic_cast<QComboBox *>( *it );
724 QComboBox * comboBox = (QComboBox *)( *it ); 724 QComboBox * comboBox = (QComboBox *)( *it );
725 return comboBox ? comboBox->text( index ) : QString::null; 725 return comboBox ? comboBox->text( index ) : QString::null;
726} 726}
727 727
728 728
729KComboBox * KToolBar::getCombo(int id) 729KComboBox * KToolBar::getCombo(int id)
730{ 730{
731 Id2WidgetMap::Iterator it = id2widget.find( id ); 731 Id2WidgetMap::Iterator it = id2widget.find( id );
732 if ( it == id2widget.end() ) 732 if ( it == id2widget.end() )
733 return 0; 733 return 0;
734//US return dynamic_cast<KComboBox *>( *it ); 734//US return dynamic_cast<KComboBox *>( *it );
735 return (KComboBox *)( *it ); 735 return (KComboBox *)( *it );
736} 736}
737 737
738 738
739KLineEdit * KToolBar::getLined (int id) 739KLineEdit * KToolBar::getLined (int id)
740{ 740{
741 Id2WidgetMap::Iterator it = id2widget.find( id ); 741 Id2WidgetMap::Iterator it = id2widget.find( id );
742 if ( it == id2widget.end() ) 742 if ( it == id2widget.end() )
743 return 0; 743 return 0;
744//US return dynamic_cast<KLineEdit *>( *it ); 744//US return dynamic_cast<KLineEdit *>( *it );
745 return (KLineEdit *)( *it ); 745 return (KLineEdit *)( *it );
746} 746}
747 747
748 748
749KToolBarButton * KToolBar::getButton (int id) 749KToolBarButton * KToolBar::getButton (int id)
750{ 750{
751 Id2WidgetMap::Iterator it = id2widget.find( id ); 751 Id2WidgetMap::Iterator it = id2widget.find( id );
752 if ( it == id2widget.end() ) 752 if ( it == id2widget.end() )
753 return 0; 753 return 0;
754//US return dynamic_cast<KToolBarButton *>( *it ); 754//US return dynamic_cast<KToolBarButton *>( *it );
755 return (KToolBarButton *)( *it ); 755 return (KToolBarButton *)( *it );
756} 756}
757 757
758 758
759void KToolBar::alignItemRight (int id, bool right ) 759void KToolBar::alignItemRight (int id, bool right )
760{ 760{
761 Id2WidgetMap::Iterator it = id2widget.find( id ); 761 Id2WidgetMap::Iterator it = id2widget.find( id );
762 if ( it == id2widget.end() ) 762 if ( it == id2widget.end() )
763 return; 763 return;
764 if ( rightAligned && !right && (*it) == rightAligned ) 764 if ( rightAligned && !right && (*it) == rightAligned )
765 rightAligned = 0; 765 rightAligned = 0;
766 if ( (*it) && right ) 766 if ( (*it) && right )
767 rightAligned = (*it); 767 rightAligned = (*it);
768} 768}
769 769
770 770
771QWidget *KToolBar::getWidget (int id) 771QWidget *KToolBar::getWidget (int id)
772{ 772{
773 Id2WidgetMap::Iterator it = id2widget.find( id ); 773 Id2WidgetMap::Iterator it = id2widget.find( id );
774 return ( it == id2widget.end() ) ? 0 : (*it); 774 return ( it == id2widget.end() ) ? 0 : (*it);
775} 775}
776 776
777 777
778void KToolBar::setItemAutoSized (int id, bool yes ) 778void KToolBar::setItemAutoSized (int id, bool yes )
779{ 779{
780 QWidget *w = getWidget(id); 780 QWidget *w = getWidget(id);
781 if ( w && yes ) 781 if ( w && yes )
782 setStretchableWidget( w ); 782 setStretchableWidget( w );
783} 783}
784 784
785 785
786void KToolBar::clear () 786void KToolBar::clear ()
787{ 787{
788 QToolBar::clear(); 788 QToolBar::clear();
789 widget2id.clear(); 789 widget2id.clear();
790 id2widget.clear(); 790 id2widget.clear();
791} 791}
792 792
793 793
794void KToolBar::removeItem(int id) 794void KToolBar::removeItem(int id)
795{ 795{
796 Id2WidgetMap::Iterator it = id2widget.find( id ); 796 Id2WidgetMap::Iterator it = id2widget.find( id );
797 if ( it == id2widget.end() ) 797 if ( it == id2widget.end() )
798 { 798 {
799 kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl; 799 kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl;
800 return; 800 return;
801 } 801 }
802 QWidget * w = (*it); 802 QWidget * w = (*it);
803 id2widget.remove( id ); 803 id2widget.remove( id );
804 widget2id.remove( w ); 804 widget2id.remove( w );
805 widgets.removeRef( w ); 805 widgets.removeRef( w );
806 delete w; 806 delete w;
807} 807}
808 808
809 809
810void KToolBar::removeItemDelayed(int id) 810void KToolBar::removeItemDelayed(int id)
811{ 811{
812 Id2WidgetMap::Iterator it = id2widget.find( id ); 812 Id2WidgetMap::Iterator it = id2widget.find( id );
813 if ( it == id2widget.end() ) 813 if ( it == id2widget.end() )
814 { 814 {
815 kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl; 815 kdDebug(220) << "KToolBar::removeItem item " << id << " not found" << endl;
816 return; 816 return;
817 } 817 }
818 QWidget * w = (*it); 818 QWidget * w = (*it);
819 id2widget.remove( id ); 819 id2widget.remove( id );
820 widget2id.remove( w ); 820 widget2id.remove( w );
821 widgets.removeRef( w ); 821 widgets.removeRef( w );
822 822
823 w->blockSignals(true); 823 w->blockSignals(true);
824 d->idleButtons.append(w); 824 d->idleButtons.append(w);
825 layoutTimer->start( 50, TRUE ); 825 layoutTimer->start( 50, TRUE );
826} 826}
827 827
828 828
829void KToolBar::hideItem (int id) 829void KToolBar::hideItem (int id)
830{ 830{
831 QWidget *w = getWidget(id); 831 QWidget *w = getWidget(id);
832 if ( w ) 832 if ( w )
833 w->hide(); 833 w->hide();
834} 834}
835 835
836 836
837void KToolBar::showItem (int id) 837void KToolBar::showItem (int id)
838{ 838{
839 QWidget *w = getWidget(id); 839 QWidget *w = getWidget(id);
840 if ( w ) 840 if ( w )
841 w->show(); 841 w->show();
842} 842}
843 843
844 844
845int KToolBar::itemIndex (int id) 845int KToolBar::itemIndex (int id)
846{ 846{
847 QWidget *w = getWidget(id); 847 QWidget *w = getWidget(id);
848 return w ? widgets.findRef(w) : -1; 848 return w ? widgets.findRef(w) : -1;
849} 849}
850 850
851 851
852void KToolBar::setFullSize(bool flag ) 852void KToolBar::setFullSize(bool flag )
853{ 853{
854 setHorizontalStretchable( flag ); 854 setHorizontalStretchable( flag );
855 setVerticalStretchable( flag ); 855 setVerticalStretchable( flag );
856} 856}
857 857
858 858
859bool KToolBar::fullSize() const 859bool KToolBar::fullSize() const
860{ 860{
861 return isHorizontalStretchable() || isVerticalStretchable(); 861 return isHorizontalStretchable() || isVerticalStretchable();
862} 862}
863 863
864 864
865void KToolBar::enableMoving(bool flag ) 865void KToolBar::enableMoving(bool flag )
866{ 866{
867//US setMovingEnabled(flag); 867//US setMovingEnabled(flag);
868 this->mainWindow()->setToolBarsMovable(flag); 868 this->mainWindow()->setToolBarsMovable(flag);
869} 869}
870 870
871 871
872void KToolBar::setBarPos (BarPosition bpos) 872void KToolBar::setBarPos (BarPosition bpos)
873{ 873{
874 if ( !mainWindow() ) 874 if ( !mainWindow() )
875 return; 875 return;
876//US mainWindow()->moveDockWindow( this, (Dock)bpos ); 876//US mainWindow()->moveDockWindow( this, (Dock)bpos );
877 mainWindow()->moveToolBar( this, (QMainWindow::ToolBarDock)bpos ); 877 mainWindow()->moveToolBar( this, (QMainWindow::ToolBarDock)bpos );
878} 878}
879 879
880 880
881KToolBar::BarPosition KToolBar::barPos() const 881const KToolBar::BarPosition KToolBar::barPos()
882{ 882{
883 if ( !(QMainWindow*)mainWindow() ) 883 if ( !(QMainWindow*)mainWindow() )
884 return KToolBar::Top; 884 return KToolBar::Top;
885//US Dock dock; 885//US Dock dock;
886 QMainWindow::ToolBarDock dock; 886 QMainWindow::ToolBarDock dock;
887 int dm1, dm2; 887 int dm1, dm2;
888 bool dm3; 888 bool dm3;
889 ((QMainWindow*)mainWindow())->getLocation( (QToolBar*)this, dock, dm1, dm3, dm2 ); 889 ((QMainWindow*)mainWindow())->getLocation( (QToolBar*)this, dock, dm1, dm3, dm2 );
890//US if ( dock == DockUnmanaged ) { 890//US if ( dock == DockUnmanaged ) {
891 if ( dock == QMainWindow::Unmanaged ) { 891 if ( dock == QMainWindow::Unmanaged ) {
892 return (KToolBar::BarPosition)Top; 892 return (KToolBar::BarPosition)Top;
893 } 893 }
894 return (BarPosition)dock; 894 return (BarPosition)dock;
895} 895}
896 896
897 897
898bool KToolBar::enable(BarStatus stat) 898bool KToolBar::enable(BarStatus stat)
899{ 899{
900 bool mystat = isVisible(); 900 bool mystat = isVisible();
901 901
902 if ( (stat == Toggle && mystat) || stat == Hide ) 902 if ( (stat == Toggle && mystat) || stat == Hide )
903 hide(); 903 hide();
904 else 904 else
905 show(); 905 show();
906 906
907 return isVisible() == mystat; 907 return isVisible() == mystat;
908} 908}
909 909
910 910
911void KToolBar::setMaxHeight ( int h ) 911void KToolBar::setMaxHeight ( int h )
912{ 912{
913 setMaximumHeight( h ); 913 setMaximumHeight( h );
914} 914}
915 915
916int KToolBar::maxHeight() 916int KToolBar::maxHeight()
917{ 917{
918 return maximumHeight(); 918 return maximumHeight();
919} 919}
920 920
921 921
922void KToolBar::setMaxWidth (int dw) 922void KToolBar::setMaxWidth (int dw)
923{ 923{
924 setMaximumWidth( dw ); 924 setMaximumWidth( dw );
925} 925}
926 926
927 927
928int KToolBar::maxWidth() 928int KToolBar::maxWidth()
929{ 929{
930 return maximumWidth(); 930 return maximumWidth();
931} 931}
932 932
933 933
934void KToolBar::setTitle (const QString& _title) 934void KToolBar::setTitle (const QString& _title)
935{ 935{
936 setLabel( _title ); 936 setLabel( _title );
937} 937}
938 938
939 939
940void KToolBar::enableFloating (bool ) 940void KToolBar::enableFloating (bool )
941{ 941{
942} 942}
943 943
944 944
945void KToolBar::setIconText(IconText it) 945void KToolBar::setIconText(IconText it)
946{ 946{
947 setIconText( it, true ); 947 setIconText( it, true );
948} 948}
949 949
950 950
951void KToolBar::setIconText(IconText icontext, bool update) 951void KToolBar::setIconText(IconText icontext, bool update)
952{ 952{
953 bool doUpdate=false; 953 bool doUpdate=false;
954 954
955 if (icontext != d->m_iconText) { 955 if (icontext != d->m_iconText) {
956 d->m_iconText = icontext; 956 d->m_iconText = icontext;
957 doUpdate=true; 957 doUpdate=true;
958 } 958 }
959 959
960 if (update == false) 960 if (update == false)
961 return; 961 return;
962 962
963 if (doUpdate) 963 if (doUpdate)
964 emit modechange(); // tell buttons what happened 964 emit modechange(); // tell buttons what happened
965 965
966 // ugly hack to force a QMainWindow::triggerLayout( TRUE ) 966 // ugly hack to force a QMainWindow::triggerLayout( TRUE )
967 if ( mainWindow() ) { 967 if ( mainWindow() ) {
968 QMainWindow *mw = mainWindow(); 968 QMainWindow *mw = mainWindow();
969 mw->setUpdatesEnabled( FALSE ); 969 mw->setUpdatesEnabled( FALSE );
970 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 970 mw->setToolBarsMovable( !mw->toolBarsMovable() );
971 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 971 mw->setToolBarsMovable( !mw->toolBarsMovable() );
972 mw->setUpdatesEnabled( TRUE ); 972 mw->setUpdatesEnabled( TRUE );
973 } 973 }
974} 974}
975 975
976 976
977KToolBar::IconText KToolBar::iconText() const 977KToolBar::IconText KToolBar::iconText() const
978{ 978{
979 return d->m_iconText; 979 return d->m_iconText;
980} 980}
981 981
982 982
983void KToolBar::setIconSize(int size) 983void KToolBar::setIconSize(int size)
984{ 984{
985 setIconSize( size, true ); 985 setIconSize( size, true );
986} 986}
987 987
988void KToolBar::setIconSize(int size, bool update) 988void KToolBar::setIconSize(int size, bool update)
989{ 989{
990 bool doUpdate=false; 990 bool doUpdate=false;
991 991
992 if ( size != d->m_iconSize ) { 992 if ( size != d->m_iconSize ) {
993 d->m_iconSize = size; 993 d->m_iconSize = size;
994 doUpdate=true; 994 doUpdate=true;
995 } 995 }
996 996
997 if (update == false) 997 if (update == false)
998 return; 998 return;
999 999
1000 if (doUpdate) 1000 if (doUpdate)
1001 emit modechange(); // tell buttons what happened 1001 emit modechange(); // tell buttons what happened
1002 1002
1003 // ugly hack to force a QMainWindow::triggerLayout( TRUE ) 1003 // ugly hack to force a QMainWindow::triggerLayout( TRUE )
1004 if ( mainWindow() ) { 1004 if ( mainWindow() ) {
1005 QMainWindow *mw = mainWindow(); 1005 QMainWindow *mw = mainWindow();
1006 mw->setUpdatesEnabled( FALSE ); 1006 mw->setUpdatesEnabled( FALSE );
1007 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 1007 mw->setToolBarsMovable( !mw->toolBarsMovable() );
1008 mw->setToolBarsMovable( !mw->toolBarsMovable() ); 1008 mw->setToolBarsMovable( !mw->toolBarsMovable() );
1009 mw->setUpdatesEnabled( TRUE ); 1009 mw->setUpdatesEnabled( TRUE );
1010 } 1010 }
1011} 1011}
1012 1012
1013 1013
1014int KToolBar::iconSize() const 1014int KToolBar::iconSize() const
1015{ 1015{
1016/*US 1016/*US
1017 if ( !d->m_iconSize ) // default value? 1017 if ( !d->m_iconSize ) // default value?
1018 { 1018 {
1019 if (!::qstrcmp(QObject::name(), "mainToolBar")) 1019 if (!::qstrcmp(QObject::name(), "mainToolBar"))
1020 return KGlobal::iconLoader()->currentSize(KIcon::MainToolbar); 1020 return KGlobal::iconLoader()->currentSize(KIcon::MainToolbar);
1021 else 1021 else
1022 return KGlobal::iconLoader()->currentSize(KIcon::Toolbar); 1022 return KGlobal::iconLoader()->currentSize(KIcon::Toolbar);
1023 } 1023 }
1024 return d->m_iconSize; 1024 return d->m_iconSize;
1025*/ 1025*/
1026 int ret = 18; 1026 int ret = 18;
1027 if ( QApplication::desktop()->width() > 320 ) 1027 if ( QApplication::desktop()->width() > 320 )
1028 ret = 30; 1028 ret = 30;
1029 return ret; 1029 return ret;
1030} 1030}
1031 1031
1032 1032
1033void KToolBar::setEnableContextMenu(bool enable ) 1033void KToolBar::setEnableContextMenu(bool enable )
1034{ 1034{
1035 d->m_enableContext = enable; 1035 d->m_enableContext = enable;
1036} 1036}
1037 1037
1038 1038
1039bool KToolBar::contextMenuEnabled() const 1039bool KToolBar::contextMenuEnabled() const
1040{ 1040{
1041 return d->m_enableContext; 1041 return d->m_enableContext;
1042} 1042}
1043 1043
1044 1044
1045void KToolBar::setItemNoStyle(int id, bool no_style ) 1045void KToolBar::setItemNoStyle(int id, bool no_style )
1046{ 1046{
1047 Id2WidgetMap::Iterator it = id2widget.find( id ); 1047 Id2WidgetMap::Iterator it = id2widget.find( id );
1048 if ( it == id2widget.end() ) 1048 if ( it == id2widget.end() )
1049 return; 1049 return;
1050//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it ); 1050//US KToolBarButton * button = dynamic_cast<KToolBarButton *>( *it );
1051 KToolBarButton * button = (KToolBarButton *)( *it ); 1051 KToolBarButton * button = (KToolBarButton *)( *it );
1052 if (button) 1052 if (button)
1053 button->setNoStyle( no_style ); 1053 button->setNoStyle( no_style );
1054} 1054}
1055 1055
1056 1056
1057void KToolBar::setFlat (bool flag) 1057void KToolBar::setFlat (bool flag)
1058{ 1058{
1059 if ( !mainWindow() ) 1059 if ( !mainWindow() )
1060 return; 1060 return;
1061 if ( flag ) 1061 if ( flag )
1062//US mainWindow()->moveDockWindow( this, DockMinimized ); 1062//US mainWindow()->moveDockWindow( this, DockMinimized );
1063 mainWindow()->moveToolBar( this, QMainWindow::Minimized ); 1063 mainWindow()->moveToolBar( this, QMainWindow::Minimized );
1064 else 1064 else
1065//US mainWindow()->moveDockWindow( this, DockTop ); 1065//US mainWindow()->moveDockWindow( this, DockTop );
1066 mainWindow()->moveToolBar( this, QMainWindow::Top ); 1066 mainWindow()->moveToolBar( this, QMainWindow::Top );
1067 // And remember to save the new look later 1067 // And remember to save the new look later
1068/*US 1068/*US
1069 if ( mainWindow()->inherits( "KMainWindow" ) ) 1069 if ( mainWindow()->inherits( "KMainWindow" ) )
1070 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty(); 1070 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
1071*/ 1071*/
1072} 1072}
1073 1073
1074 1074
1075int KToolBar::count() const 1075int KToolBar::count() const
1076{ 1076{
1077 return id2widget.count(); 1077 return id2widget.count();
1078} 1078}
1079 1079
1080 1080
1081void KToolBar::saveState() 1081void KToolBar::saveState()
1082{ 1082{
1083/*US 1083/*US
1084 // first, try to save to the xml file 1084 // first, try to save to the xml file
1085 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) { 1085 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() ) {
1086 // go down one level to get to the right tags 1086 // go down one level to get to the right tags
1087 QDomElement elem = d->m_xmlguiClient->domDocument().documentElement().toElement(); 1087 QDomElement elem = d->m_xmlguiClient->domDocument().documentElement().toElement();
1088 elem = elem.firstChild().toElement(); 1088 elem = elem.firstChild().toElement();
1089 QString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name()); 1089 QString barname(!::qstrcmp(name(), "unnamed") ? "mainToolBar" : name());
1090 QDomElement current; 1090 QDomElement current;
1091 // now try to find our toolbar 1091 // now try to find our toolbar
1092 d->modified = false; 1092 d->modified = false;
1093 for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) { 1093 for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) {
1094 current = elem; 1094 current = elem;
1095 1095
1096 if ( current.tagName().lower() != "toolbar" ) 1096 if ( current.tagName().lower() != "toolbar" )
1097 continue; 1097 continue;
1098 1098
1099 QString curname(current.attribute( "name" )); 1099 QString curname(current.attribute( "name" ));
1100 1100
1101 if ( curname == barname ) { 1101 if ( curname == barname ) {
1102 saveState( current ); 1102 saveState( current );
1103 break; 1103 break;
1104 } 1104 }
1105 } 1105 }
1106 // if we didn't make changes, then just return 1106 // if we didn't make changes, then just return
1107 if ( !d->modified ) 1107 if ( !d->modified )
1108 return; 1108 return;
1109 1109
1110 // now we load in the (non-merged) local file 1110 // now we load in the (non-merged) local file
1111 QString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance())); 1111 QString local_xml(KXMLGUIFactory::readConfigFile(d->m_xmlguiClient->xmlFile(), true, d->m_xmlguiClient->instance()));
1112 QDomDocument local; 1112 QDomDocument local;
1113 local.setContent(local_xml); 1113 local.setContent(local_xml);
1114 1114
1115 // make sure we don't append if this toolbar already exists locally 1115 // make sure we don't append if this toolbar already exists locally
1116 bool just_append = true; 1116 bool just_append = true;
1117 elem = local.documentElement().toElement(); 1117 elem = local.documentElement().toElement();
1118 KXMLGUIFactory::removeDOMComments( elem ); 1118 KXMLGUIFactory::removeDOMComments( elem );
1119 elem = elem.firstChild().toElement(); 1119 elem = elem.firstChild().toElement();
1120 for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) { 1120 for( ; !elem.isNull(); elem = elem.nextSibling().toElement() ) {
1121 if ( elem.tagName().lower() != "toolbar" ) 1121 if ( elem.tagName().lower() != "toolbar" )
1122 continue; 1122 continue;
1123 1123
1124 QString curname(elem.attribute( "name" )); 1124 QString curname(elem.attribute( "name" ));
1125 1125
1126 if ( curname == barname ) { 1126 if ( curname == barname ) {
1127 just_append = false; 1127 just_append = false;
1128 local.documentElement().replaceChild( current, elem ); 1128 local.documentElement().replaceChild( current, elem );
1129 break; 1129 break;
1130 } 1130 }
1131 } 1131 }
1132 1132
1133 if (just_append) 1133 if (just_append)
1134 local.documentElement().appendChild( current ); 1134 local.documentElement().appendChild( current );
1135 1135
1136 KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() ); 1136 KXMLGUIFactory::saveConfigFile(local, d->m_xmlguiClient->localXMLFile(), d->m_xmlguiClient->instance() );
1137 1137
1138 return; 1138 return;
1139 } 1139 }
1140*/ 1140*/
1141 // if that didn't work, we save to the config file 1141 // if that didn't work, we save to the config file
1142 KConfig *config = KGlobal::config(); 1142 KConfig *config = KGlobal::config();
1143 saveSettings(config, QString::null); 1143 saveSettings(config, QString::null);
1144 config->sync(); 1144 config->sync();
1145} 1145}
1146 1146
1147QString KToolBar::settingsGroup() 1147QString KToolBar::settingsGroup()
1148{ 1148{
1149 QString configGroup; 1149 QString configGroup;
1150 if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar")) 1150 if (!::qstrcmp(name(), "unnamed") || !::qstrcmp(name(), "mainToolBar"))
1151 configGroup = "Toolbar style"; 1151 configGroup = "Toolbar style";
1152 else 1152 else
1153 configGroup = QString(name()) + " Toolbar style"; 1153 configGroup = QString(name()) + " Toolbar style";
1154 if ( this->mainWindow() ) 1154 if ( this->mainWindow() )
1155 { 1155 {
1156 configGroup.prepend(" "); 1156 configGroup.prepend(" ");
1157 configGroup.prepend( this->mainWindow()->name() ); 1157 configGroup.prepend( this->mainWindow()->name() );
1158 } 1158 }
1159 return configGroup; 1159 return configGroup;
1160} 1160}
1161 1161
1162void KToolBar::saveSettings(KConfig *config, const QString &_configGroup) 1162void KToolBar::saveSettings(KConfig *config, const QString &_configGroup)
1163{ 1163{
1164 QString configGroup = _configGroup; 1164 QString configGroup = _configGroup;
1165 if (configGroup.isEmpty()) 1165 if (configGroup.isEmpty())
1166 configGroup = settingsGroup(); 1166 configGroup = settingsGroup();
1167 //kdDebug(220) << "KToolBar::saveSettings group=" << _configGroup << " -> " << configGroup << endl; 1167 //kdDebug(220) << "KToolBar::saveSettings group=" << _configGroup << " -> " << configGroup << endl;
1168 1168
1169 QString position, icontext; 1169 QString position, icontext;
1170 int index; 1170 int index;
1171 getAttributes( position, icontext, index ); 1171 getAttributes( position, icontext, index );
1172 1172
1173 //kdDebug(220) << "KToolBar::saveSettings " << name() << " newLine=" << newLine << endl; 1173 //kdDebug(220) << "KToolBar::saveSettings " << name() << " newLine=" << newLine << endl;
1174 1174
1175 KConfigGroupSaver saver(config, configGroup); 1175 KConfigGroupSaver saver(config, configGroup);
1176 1176
1177 if ( position != d->PositionDefault ) 1177 if ( position != d->PositionDefault )
1178 config->writeEntry("Position", position); 1178 config->writeEntry("Position", position);
1179 else 1179 else
1180 config->deleteEntry("Position"); 1180 config->deleteEntry("Position");
1181 1181
1182 if ( icontext != d->IconTextDefault ) 1182 if ( icontext != d->IconTextDefault )
1183 config->writeEntry("IconText", icontext); 1183 config->writeEntry("IconText", icontext);
1184 else 1184 else
1185 config->deleteEntry("IconText"); 1185 config->deleteEntry("IconText");
1186 1186
1187 if ( iconSize() != d->IconSizeDefault ) 1187 if ( iconSize() != d->IconSizeDefault )
1188 config->writeEntry("IconSize", iconSize()); 1188 config->writeEntry("IconSize", iconSize());
1189 else 1189 else
1190 config->deleteEntry("IconSize"); 1190 config->deleteEntry("IconSize");
1191 1191
1192 if ( isHidden() != d->HiddenDefault ) 1192 if ( isHidden() != d->HiddenDefault )
1193 config->writeEntry("Hidden", isHidden()); 1193 config->writeEntry("Hidden", isHidden());
1194 else 1194 else
1195 config->deleteEntry("Hidden"); 1195 config->deleteEntry("Hidden");
1196 1196
1197 if ( index != d->IndexDefault ) 1197 if ( index != d->IndexDefault )
1198 config->writeEntry( "Index", index ); 1198 config->writeEntry( "Index", index );
1199 else 1199 else
1200 config->deleteEntry("Index"); 1200 config->deleteEntry("Index");
1201//US the older version of KDE (used on the Zaurus) has no Offset property 1201//US the older version of KDE (used on the Zaurus) has no Offset property
1202/* if ( offset() != d->OffsetDefault ) 1202/* if ( offset() != d->OffsetDefault )
1203 config->writeEntry( "Offset", offset() ); 1203 config->writeEntry( "Offset", offset() );
1204 else 1204 else
1205*/ 1205*/
1206 config->deleteEntry("Offset"); 1206 config->deleteEntry("Offset");
1207 1207
1208//US the older version of KDE (used on the Zaurus) has no NewLine property 1208//US the older version of KDE (used on the Zaurus) has no NewLine property
1209/* 1209/*
1210 if ( newLine() != d->NewLineDefault ) 1210 if ( newLine() != d->NewLineDefault )
1211 config->writeEntry( "NewLine", newLine() ); 1211 config->writeEntry( "NewLine", newLine() );
1212 else 1212 else
1213*/ 1213*/
1214 config->deleteEntry("NewLine"); 1214 config->deleteEntry("NewLine");
1215} 1215}
1216 1216
1217void KToolBar::setXMLGUIClient( KXMLGUIClient *client ) 1217void KToolBar::setXMLGUIClient( KXMLGUIClient *client )
1218{ 1218{
1219 d->m_xmlguiClient = client; 1219 d->m_xmlguiClient = client;
1220} 1220}
1221 1221
1222void KToolBar::setText( const QString & txt ) 1222void KToolBar::setText( const QString & txt )
1223{ 1223{
1224//US setLabel( txt + " ( " + kapp->caption() + " ) " ); 1224//US setLabel( txt + " ( " + kapp->caption() + " ) " );
1225 setLabel( txt + " ( " + KGlobal::getAppName() + " ) " ); 1225 setLabel( txt + " ( " + KGlobal::getAppName() + " ) " );
1226} 1226}
1227 1227
1228 1228
1229QString KToolBar::text() const 1229QString KToolBar::text() const
1230{ 1230{
1231 return label(); 1231 return label();
1232} 1232}
1233 1233
1234 1234
1235void KToolBar::doConnections( KToolBarButton *button ) 1235void KToolBar::doConnections( KToolBarButton *button )
1236{ 1236{
1237 connect(button, SIGNAL(clicked(int)), this, SIGNAL( clicked( int ) ) ); 1237 connect(button, SIGNAL(clicked(int)), this, SIGNAL( clicked( int ) ) );
1238 connect(button, SIGNAL(doubleClicked(int)), this, SIGNAL( doubleClicked( int ) ) ); 1238 connect(button, SIGNAL(doubleClicked(int)), this, SIGNAL( doubleClicked( int ) ) );
1239 connect(button, SIGNAL(released(int)), this, SIGNAL( released( int ) ) ); 1239 connect(button, SIGNAL(released(int)), this, SIGNAL( released( int ) ) );
1240 connect(button, SIGNAL(pressed(int)), this, SIGNAL( pressed( int ) ) ); 1240 connect(button, SIGNAL(pressed(int)), this, SIGNAL( pressed( int ) ) );
1241 connect(button, SIGNAL(toggled(int)), this, SIGNAL( toggled( int ) ) ); 1241 connect(button, SIGNAL(toggled(int)), this, SIGNAL( toggled( int ) ) );
1242 connect(button, SIGNAL(highlighted(int, bool)), this, SIGNAL( highlighted( int, bool ) ) ); 1242 connect(button, SIGNAL(highlighted(int, bool)), this, SIGNAL( highlighted( int, bool ) ) );
1243} 1243}
1244 1244
1245void KToolBar::mousePressEvent ( QMouseEvent *m ) 1245void KToolBar::mousePressEvent ( QMouseEvent *m )
1246{ 1246{
1247 if ( !mainWindow() ) 1247 if ( !mainWindow() )
1248 return; 1248 return;
1249 QMainWindow *mw = mainWindow(); 1249 QMainWindow *mw = mainWindow();
1250 if ( mw->toolBarsMovable() && d->m_enableContext ) { 1250 if ( mw->toolBarsMovable() && d->m_enableContext ) {
1251 if ( m->button() == RightButton ) { 1251 if ( m->button() == RightButton ) {
1252 int i = contextMenu()->exec( m->globalPos(), 0 ); 1252 int i = contextMenu()->exec( m->globalPos(), 0 );
1253 switch ( i ) { 1253 switch ( i ) {
1254 case -1: 1254 case -1:
1255 return; // popup cancelled 1255 return; // popup cancelled
1256 case CONTEXT_LEFT: 1256 case CONTEXT_LEFT:
1257//US mw->moveDockWindow( this, DockLeft ); 1257//US mw->moveDockWindow( this, DockLeft );
1258 mw->moveToolBar( this, QMainWindow::Left ); 1258 mw->moveToolBar( this, QMainWindow::Left );
1259 break; 1259 break;
1260 case CONTEXT_RIGHT: 1260 case CONTEXT_RIGHT:
1261//US mw->moveDockWindow( this, DockRight ); 1261//US mw->moveDockWindow( this, DockRight );
1262 mw->moveToolBar( this, QMainWindow::Right ); 1262 mw->moveToolBar( this, QMainWindow::Right );
1263 break; 1263 break;
1264 case CONTEXT_TOP: 1264 case CONTEXT_TOP:
1265//US mw->moveDockWindow( this, DockTop ); 1265//US mw->moveDockWindow( this, DockTop );
1266 mw->moveToolBar( this, QMainWindow::Top ); 1266 mw->moveToolBar( this, QMainWindow::Top );
1267 break; 1267 break;
1268 case CONTEXT_BOTTOM: 1268 case CONTEXT_BOTTOM:
1269//US mw->moveDockWindow( this, DockBottom ); 1269//US mw->moveDockWindow( this, DockBottom );
1270 mw->moveToolBar( this, QMainWindow::Bottom ); 1270 mw->moveToolBar( this, QMainWindow::Bottom );
1271 break; 1271 break;
1272 case CONTEXT_FLOAT: 1272 case CONTEXT_FLOAT:
1273 break; 1273 break;
1274 case CONTEXT_FLAT: 1274 case CONTEXT_FLAT:
1275//US mw->moveDockWindow( this, DockMinimized ); 1275//US mw->moveDockWindow( this, DockMinimized );
1276 mw->moveToolBar( this, QMainWindow::Minimized ); 1276 mw->moveToolBar( this, QMainWindow::Minimized );
1277 break; 1277 break;
1278 case CONTEXT_ICONS: 1278 case CONTEXT_ICONS:
1279 setIconText( IconOnly ); 1279 setIconText( IconOnly );
1280 break; 1280 break;
1281 case CONTEXT_TEXTRIGHT: 1281 case CONTEXT_TEXTRIGHT:
1282 setIconText( IconTextRight ); 1282 setIconText( IconTextRight );
1283 break; 1283 break;
1284 case CONTEXT_TEXT: 1284 case CONTEXT_TEXT:
1285 setIconText( TextOnly ); 1285 setIconText( TextOnly );
1286 break; 1286 break;
1287 case CONTEXT_TEXTUNDER: 1287 case CONTEXT_TEXTUNDER:
1288 setIconText( IconTextBottom ); 1288 setIconText( IconTextBottom );
1289 break; 1289 break;
1290 default: 1290 default:
1291 if ( i >= CONTEXT_ICONSIZES ) 1291 if ( i >= CONTEXT_ICONSIZES )
1292 setIconSize( i - CONTEXT_ICONSIZES ); 1292 setIconSize( i - CONTEXT_ICONSIZES );
1293 else 1293 else
1294 return; // assume this was an action handled elsewhere, no need for setSettingsDirty() 1294 return; // assume this was an action handled elsewhere, no need for setSettingsDirty()
1295 } 1295 }
1296/*US 1296/*US
1297 if ( mw->inherits("KMainWindow") ) 1297 if ( mw->inherits("KMainWindow") )
1298 static_cast<KMainWindow *>(mw)->setSettingsDirty(); 1298 static_cast<KMainWindow *>(mw)->setSettingsDirty();
1299*/ 1299*/
1300 } 1300 }
1301 } 1301 }
1302} 1302}
1303 1303
1304 1304
1305void KToolBar::rebuildLayout() 1305void KToolBar::rebuildLayout()
1306{ 1306{
1307 1307
1308 for(QWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next()) 1308 for(QWidget *w=d->idleButtons.first(); w; w=d->idleButtons.next())
1309 w->blockSignals(false); 1309 w->blockSignals(false);
1310 d->idleButtons.clear(); 1310 d->idleButtons.clear();
1311 1311
1312 layoutTimer->stop(); 1312 layoutTimer->stop();
1313 QApplication::sendPostedEvents( this, QEvent::ChildInserted ); 1313 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
1314 QBoxLayout *l = boxLayout(); 1314 QBoxLayout *l = boxLayout();
1315 l->setMargin( 1 ); 1315 l->setMargin( 1 );
1316 // clear the old layout 1316 // clear the old layout
1317 QLayoutIterator it = l->iterator(); 1317 QLayoutIterator it = l->iterator();
1318 1318
1319 while ( it.current() ) { 1319 while ( it.current() ) {
1320 it.deleteCurrent(); 1320 it.deleteCurrent();
1321 } 1321 }
1322 for ( QWidget *w = widgets.first(); w; w = widgets.next() ) { 1322 for ( QWidget *w = widgets.first(); w; w = widgets.next() ) {
1323 if ( w == rightAligned ) { 1323 if ( w == rightAligned ) {
1324 continue; 1324 continue;
1325 } 1325 }
1326 if ( w->inherits( "KToolBarSeparator" ) && 1326 if ( w->inherits( "KToolBarSeparator" ) &&
1327 !( (KToolBarSeparator*)w )->showLine() ) { 1327 !( (KToolBarSeparator*)w )->showLine() ) {
1328 l->addSpacing( 6 ); 1328 l->addSpacing( 6 );
1329 w->hide(); 1329 w->hide();
1330 continue; 1330 continue;
1331 } 1331 }
1332 if ( w->inherits( "QPopupMenu" ) ) 1332 if ( w->inherits( "QPopupMenu" ) )
1333 continue; 1333 continue;
1334 l->addWidget( w ); 1334 l->addWidget( w );
1335 w->show(); 1335 w->show();
1336 } 1336 }
1337 if ( rightAligned ) { 1337 if ( rightAligned ) {
1338 l->addStretch(); 1338 l->addStretch();
1339 l->addWidget( rightAligned ); 1339 l->addWidget( rightAligned );
1340 rightAligned->show(); 1340 rightAligned->show();
1341 } 1341 }
1342 1342
1343 if ( fullSize() ) { 1343 if ( fullSize() ) {
1344 // This code sucks. It makes the last combo in a toolbar VERY big (e.g. zoom combo in kword). 1344 // This code sucks. It makes the last combo in a toolbar VERY big (e.g. zoom combo in kword).
1345 //if ( !stretchableWidget && widgets.last() && 1345 //if ( !stretchableWidget && widgets.last() &&
1346 // !widgets.last()->inherits( "QButton" ) && !widgets.last()->inherits( "KAnimWidget" ) ) 1346 // !widgets.last()->inherits( "QButton" ) && !widgets.last()->inherits( "KAnimWidget" ) )
1347 // setStretchableWidget( widgets.last() ); 1347 // setStretchableWidget( widgets.last() );
1348 if ( !rightAligned ) 1348 if ( !rightAligned )
1349 l->addStretch(); 1349 l->addStretch();
1350 if ( stretchableWidget ) 1350 if ( stretchableWidget )
1351 l->setStretchFactor( stretchableWidget, 10 ); 1351 l->setStretchFactor( stretchableWidget, 10 );
1352 } 1352 }
1353 l->invalidate(); 1353 l->invalidate();
1354 QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) ); 1354 QApplication::postEvent( this, new QEvent( QEvent::LayoutHint ) );
1355 //#endif //DESKTOP_VERSION 1355 //#endif //DESKTOP_VERSION
1356} 1356}
1357 1357
1358void KToolBar::childEvent( QChildEvent *e ) 1358void KToolBar::childEvent( QChildEvent *e )
1359{ 1359{
1360 1360
1361 if ( e->child()->isWidgetType() ) { 1361 if ( e->child()->isWidgetType() ) {
1362 QWidget * w = (QWidget*)e->child(); 1362 QWidget * w = (QWidget*)e->child();
1363 if ( e->type() == QEvent::ChildInserted ) { 1363 if ( e->type() == QEvent::ChildInserted ) {
1364 if ( !e->child()->inherits( "QPopupMenu" ) && 1364 if ( !e->child()->inherits( "QPopupMenu" ) &&
1365 ::qstrcmp( "qt_dockwidget_internal", e->child()->name() ) != 0 ) { 1365 ::qstrcmp( "qt_dockwidget_internal", e->child()->name() ) != 0 ) {
1366 1366
1367 // prevent items that have been explicitly inserted by insert*() from 1367 // prevent items that have been explicitly inserted by insert*() from
1368 // being inserted again 1368 // being inserted again
1369 if ( !widget2id.contains( w ) ) 1369 if ( !widget2id.contains( w ) )
1370 { 1370 {
1371 int dummy = -1; 1371 int dummy = -1;
1372 insertWidgetInternal( w, dummy, -1 ); 1372 insertWidgetInternal( w, dummy, -1 );
1373 } 1373 }
1374 } 1374 }
1375 } else { 1375 } else {
1376 removeWidgetInternal( w ); 1376 removeWidgetInternal( w );
1377 } 1377 }
1378 if ( isVisibleTo( 0 ) ) 1378 if ( isVisibleTo( 0 ) )
1379 { 1379 {
1380 QBoxLayout *l = boxLayout(); 1380 QBoxLayout *l = boxLayout();
1381 // QLayout *l = layout(); 1381 // QLayout *l = layout();
1382 1382
1383 // clear the old layout so that we don't get unnecassery layout 1383 // clear the old layout so that we don't get unnecassery layout
1384 // changes till we have rebuild the thing 1384 // changes till we have rebuild the thing
1385 QLayoutIterator it = l->iterator(); 1385 QLayoutIterator it = l->iterator();
1386 while ( it.current() ) { 1386 while ( it.current() ) {
1387 it.deleteCurrent(); 1387 it.deleteCurrent();
1388 } 1388 }
1389 layoutTimer->start( 50, TRUE ); 1389 layoutTimer->start( 50, TRUE );
1390 } 1390 }
1391 } 1391 }
1392 QToolBar::childEvent( e ); 1392 QToolBar::childEvent( e );
1393} 1393}
1394 1394
1395void KToolBar::insertWidgetInternal( QWidget *w, int &index, int id ) 1395void KToolBar::insertWidgetInternal( QWidget *w, int &index, int id )
1396{ 1396{
1397 // we can't have it in widgets, or something is really wrong 1397 // we can't have it in widgets, or something is really wrong
1398 //widgets.removeRef( w ); 1398 //widgets.removeRef( w );
1399 1399
1400 connect( w, SIGNAL( destroyed() ), 1400 connect( w, SIGNAL( destroyed() ),
1401 this, SLOT( widgetDestroyed() ) ); 1401 this, SLOT( widgetDestroyed() ) );
1402 if ( index == -1 || index > (int)widgets.count() ) { 1402 if ( index == -1 || index > (int)widgets.count() ) {
1403 widgets.append( w ); 1403 widgets.append( w );
1404 index = (int)widgets.count(); 1404 index = (int)widgets.count();
1405 } 1405 }
1406 else 1406 else
1407 widgets.insert( index, w ); 1407 widgets.insert( index, w );
1408 if ( id == -1 ) 1408 if ( id == -1 )
1409 id = id2widget.count(); 1409 id = id2widget.count();
1410 id2widget.insert( id, w ); 1410 id2widget.insert( id, w );
1411 widget2id.insert( w, id ); 1411 widget2id.insert( w, id );
1412} 1412}
1413void KToolBar::repaintMe() 1413void KToolBar::repaintMe()
1414{ 1414{
1415 setUpdatesEnabled( true ); 1415 setUpdatesEnabled( true );
1416 QToolBar::repaint( true ); 1416 QToolBar::repaint( true );
1417 //qDebug(" KToolBar::repaintMe() "); 1417 //qDebug(" KToolBar::repaintMe() ");
1418} 1418}
1419 1419
1420void KToolBar::showEvent( QShowEvent *e ) 1420void KToolBar::showEvent( QShowEvent *e )
1421{ 1421{
1422 QToolBar::showEvent( e ); 1422 QToolBar::showEvent( e );
1423 rebuildLayout(); 1423 rebuildLayout();
1424} 1424}
1425 1425
1426void KToolBar::setStretchableWidget( QWidget *w ) 1426void KToolBar::setStretchableWidget( QWidget *w )
1427{ 1427{
1428 QToolBar::setStretchableWidget( w ); 1428 QToolBar::setStretchableWidget( w );
1429 stretchableWidget = w; 1429 stretchableWidget = w;
1430} 1430}
1431 1431
1432QSizePolicy KToolBar::sizePolicy() const 1432QSizePolicy KToolBar::sizePolicy() const
1433{ 1433{
1434 if ( orientation() == Horizontal ) 1434 if ( orientation() == Horizontal )
1435 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ); 1435 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
1436 else 1436 else
1437 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ); 1437 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding );
1438} 1438}
1439 1439
1440QSize KToolBar::sizeHint() const 1440QSize KToolBar::sizeHint() const
1441{ 1441{
1442 return QToolBar::sizeHint(); 1442 return QToolBar::sizeHint();
1443#if 0 1443#if 0
1444 QWidget::polish(); 1444 QWidget::polish();
1445 static int iii = 0; 1445 static int iii = 0;
1446 ++iii; 1446 ++iii;
1447 qDebug("++++++++ KToolBar::sizeHint() %d ", iii ); 1447 qDebug("++++++++ KToolBar::sizeHint() %d ", iii );
1448 int margin = static_cast<QWidget*>(ncThis)->layout()->margin(); 1448 int margin = static_cast<QWidget*>(ncThis)->layout()->margin();
1449 switch( barPos() ) 1449 switch( barPos() )
1450 { 1450 {
1451 case KToolBar::Top: 1451 case KToolBar::Top:
1452 case KToolBar::Bottom: 1452 case KToolBar::Bottom:
1453 for ( QWidget *w = widgets.first(); w; w =widgets.next() ) 1453 for ( QWidget *w = widgets.first(); w; w =widgets.next() )
1454 { 1454 {
1455 if ( w->inherits( "KToolBarSeparator" ) && 1455 if ( w->inherits( "KToolBarSeparator" ) &&
1456 !( static_cast<KToolBarSeparator*>(w)->showLine() ) ) 1456 !( static_cast<KToolBarSeparator*>(w)->showLine() ) )
1457 { 1457 {
1458 minSize += QSize(6, 0); 1458 minSize += QSize(6, 0);
1459 } 1459 }
1460 else 1460 else
1461 { 1461 {
1462 QSize sh = w->sizeHint(); 1462 QSize sh = w->sizeHint();
1463 if (!sh.isValid()) 1463 if (!sh.isValid())
1464 sh = w->minimumSize(); 1464 sh = w->minimumSize();
1465 minSize = minSize.expandedTo(QSize(0, sh.height())); 1465 minSize = minSize.expandedTo(QSize(0, sh.height()));
1466 minSize += QSize(sh.width()+1, 0); 1466 minSize += QSize(sh.width()+1, 0);
1467 } 1467 }
1468 } 1468 }
1469/*US 1469/*US
1470 minSize += QSize(QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ), 0); 1470 minSize += QSize(QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ), 0);
1471*/ 1471*/
1472 minSize += QSize(margin*2, margin*2); 1472 minSize += QSize(margin*2, margin*2);
1473 break; 1473 break;
1474 1474
1475 case KToolBar::Left: 1475 case KToolBar::Left:
1476 case KToolBar::Right: 1476 case KToolBar::Right:
1477 for ( QWidget *w = widgets.first(); w; w = widgets.next() ) 1477 for ( QWidget *w = widgets.first(); w; w = widgets.next() )
1478 { 1478 {
1479 if ( w->inherits( "KToolBarSeparator" ) && 1479 if ( w->inherits( "KToolBarSeparator" ) &&
1480 !( static_cast<KToolBarSeparator*>(w)->showLine() ) ) 1480 !( static_cast<KToolBarSeparator*>(w)->showLine() ) )
1481 { 1481 {
1482 minSize += QSize(0, 6); 1482 minSize += QSize(0, 6);
1483 } 1483 }
1484 else 1484 else
1485 { 1485 {
1486 QSize sh = w->sizeHint(); 1486 QSize sh = w->sizeHint();
1487 if (!sh.isValid()) 1487 if (!sh.isValid())
1488 sh = w->minimumSize(); 1488 sh = w->minimumSize();
1489 minSize = minSize.expandedTo(QSize(sh.width(), 0)); 1489 minSize = minSize.expandedTo(QSize(sh.width(), 0));
1490 minSize += QSize(0, sh.height()+1); 1490 minSize += QSize(0, sh.height()+1);
1491 } 1491 }
1492 } 1492 }
1493/*US 1493/*US
1494 minSize += QSize(0, QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent )); 1494 minSize += QSize(0, QApplication::style().pixelMetric( QStyle::PM_DockWindowHandleExtent ));
1495*/ 1495*/
1496 minSize += QSize(margin*2, margin*2); 1496 minSize += QSize(margin*2, margin*2);
1497 break; 1497 break;
1498 1498
1499 default: 1499 default:
1500 minSize = QToolBar::sizeHint(); 1500 minSize = QToolBar::sizeHint();
1501 break; 1501 break;
1502 } 1502 }
1503 return minSize; 1503 return minSize;
1504#endif 1504#endif
1505} 1505}
1506 1506
1507QSize KToolBar::minimumSize() const 1507QSize KToolBar::minimumSize() const
1508{ 1508{
1509 return minimumSizeHint(); 1509 return minimumSizeHint();
1510} 1510}
1511 1511
1512QSize KToolBar::minimumSizeHint() const 1512QSize KToolBar::minimumSizeHint() const
1513{ 1513{
1514 return sizeHint(); 1514 return sizeHint();
1515} 1515}
1516 1516
1517bool KToolBar::highlight() const 1517bool KToolBar::highlight() const
1518{ 1518{
1519 return d->m_highlight; 1519 return d->m_highlight;
1520} 1520}
1521 1521
1522void KToolBar::hide() 1522void KToolBar::hide()
1523{ 1523{
1524 QToolBar::hide(); 1524 QToolBar::hide();
1525} 1525}
1526 1526
1527void KToolBar::show() 1527void KToolBar::show()
1528{ 1528{
1529 QToolBar::show(); 1529 QToolBar::show();
1530} 1530}
1531 1531
1532void KToolBar::resizeEvent( QResizeEvent *e ) 1532void KToolBar::resizeEvent( QResizeEvent *e )
1533{ 1533{
1534 bool b = isUpdatesEnabled(); 1534 bool b = isUpdatesEnabled();
1535 setUpdatesEnabled( FALSE ); 1535 setUpdatesEnabled( FALSE );
1536 QToolBar::resizeEvent( e ); 1536 QToolBar::resizeEvent( e );
1537 if (b) 1537 if (b)
1538 d->repaintTimer.start( 100, true ); 1538 d->repaintTimer.start( 100, true );
1539} 1539}
1540 1540
1541void KToolBar::slotIconChanged(int group) 1541void KToolBar::slotIconChanged(int group)
1542{ 1542{
1543 if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar)) 1543 if ((group != KIcon::Toolbar) && (group != KIcon::MainToolbar))
1544 return; 1544 return;
1545 if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar")) 1545 if ((group == KIcon::MainToolbar) != !::qstrcmp(name(), "mainToolBar"))
1546 return; 1546 return;
1547 1547
1548 emit modechange(); 1548 emit modechange();
1549 if (isVisible()) 1549 if (isVisible())
1550 updateGeometry(); 1550 updateGeometry();
1551} 1551}
1552 1552
1553void KToolBar::slotReadConfig() 1553void KToolBar::slotReadConfig()
1554{ 1554{
1555 //kdDebug(220) << "KToolBar::slotReadConfig" << endl; 1555 //kdDebug(220) << "KToolBar::slotReadConfig" << endl;
1556 // Read appearance settings (hmm, we used to do both here, 1556 // Read appearance settings (hmm, we used to do both here,
1557 // but a well behaved application will call applyMainWindowSettings 1557 // but a well behaved application will call applyMainWindowSettings
1558 // anyway, right ?) 1558 // anyway, right ?)
1559 applyAppearanceSettings(KGlobal::config(), QString::null ); 1559 applyAppearanceSettings(KGlobal::config(), QString::null );
1560} 1560}
1561 1561
1562void KToolBar::slotAppearanceChanged() 1562void KToolBar::slotAppearanceChanged()
1563{ 1563{
1564 // Read appearance settings from global file. 1564 // Read appearance settings from global file.
1565 applyAppearanceSettings(KGlobal::config(), QString::null, true /* lose local settings */ ); 1565 applyAppearanceSettings(KGlobal::config(), QString::null, true /* lose local settings */ );
1566 // And remember to save the new look later 1566 // And remember to save the new look later
1567/*US 1567/*US
1568 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) ) 1568 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
1569 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty(); 1569 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
1570*/ 1570*/
1571} 1571}
1572 1572
1573//static 1573//static
1574bool KToolBar::highlightSetting() 1574bool KToolBar::highlightSetting()
1575{ 1575{
1576 QString grpToolbar(QString::fromLatin1("Toolbar style")); 1576 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1577 KConfigGroupSaver saver(KGlobal::config(), grpToolbar); 1577 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1578 return KGlobal::config()->readBoolEntry(QString::fromLatin1("Highlighting"),true); 1578 return KGlobal::config()->readBoolEntry(QString::fromLatin1("Highlighting"),true);
1579} 1579}
1580 1580
1581//static 1581//static
1582bool KToolBar::transparentSetting() 1582bool KToolBar::transparentSetting()
1583{ 1583{
1584 QString grpToolbar(QString::fromLatin1("Toolbar style")); 1584 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1585 KConfigGroupSaver saver(KGlobal::config(), grpToolbar); 1585 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1586 return KGlobal::config()->readBoolEntry(QString::fromLatin1("TransparentMoving"),true); 1586 return KGlobal::config()->readBoolEntry(QString::fromLatin1("TransparentMoving"),true);
1587} 1587}
1588 1588
1589//static 1589//static
1590KToolBar::IconText KToolBar::iconTextSetting() 1590KToolBar::IconText KToolBar::iconTextSetting()
1591{ 1591{
1592 QString grpToolbar(QString::fromLatin1("Toolbar style")); 1592 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1593 KConfigGroupSaver saver(KGlobal::config(), grpToolbar); 1593 KConfigGroupSaver saver(KGlobal::config(), grpToolbar);
1594 QString icontext = KGlobal::config()->readEntry(QString::fromLatin1("IconText"),QString::fromLatin1("IconOnly")); 1594 QString icontext = KGlobal::config()->readEntry(QString::fromLatin1("IconText"),QString::fromLatin1("IconOnly"));
1595 if ( icontext == "IconTextRight" ) 1595 if ( icontext == "IconTextRight" )
1596 return IconTextRight; 1596 return IconTextRight;
1597 else if ( icontext == "IconTextBottom" ) 1597 else if ( icontext == "IconTextBottom" )
1598 return IconTextBottom; 1598 return IconTextBottom;
1599 else if ( icontext == "TextOnly" ) 1599 else if ( icontext == "TextOnly" )
1600 return TextOnly; 1600 return TextOnly;
1601 else 1601 else
1602 return IconOnly; 1602 return IconOnly;
1603} 1603}
1604 1604
1605void KToolBar::applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal) 1605void KToolBar::applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal)
1606{ 1606{
1607 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; 1607 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1608 //kdDebug(220) << "KToolBar::applyAppearanceSettings: configGroup=" << configGroup << endl; 1608 //kdDebug(220) << "KToolBar::applyAppearanceSettings: configGroup=" << configGroup << endl;
1609 // We have application-specific settings in the XML file, 1609 // We have application-specific settings in the XML file,
1610 // and nothing in the application's config file 1610 // and nothing in the application's config file
1611 // -> don't apply the global defaults, the XML ones are preferred 1611 // -> don't apply the global defaults, the XML ones are preferred
1612 // See applySettings for a full explanation 1612 // See applySettings for a full explanation
1613/*US :we do not support xml files 1613/*US :we do not support xml files
1614 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() && 1614 if ( d->m_xmlguiClient && !d->m_xmlguiClient->xmlFile().isEmpty() &&
1615 !config->hasGroup(configGroup) ) 1615 !config->hasGroup(configGroup) )
1616 { 1616 {
1617 //kdDebug(220) << "skipping global defaults, using XML ones instead" << endl; 1617 //kdDebug(220) << "skipping global defaults, using XML ones instead" << endl;
1618 return; 1618 return;
1619 } 1619 }
1620*/ 1620*/
1621 if ( !config->hasGroup(configGroup) ) 1621 if ( !config->hasGroup(configGroup) )
1622 { 1622 {
1623 //kdDebug(220) << "skipping global defaults, using XML ones instead" << endl; 1623 //kdDebug(220) << "skipping global defaults, using XML ones instead" << endl;
1624 return; 1624 return;
1625 } 1625 }
1626 1626
1627 1627
1628 KConfig *gconfig = KGlobal::config(); 1628 KConfig *gconfig = KGlobal::config();
1629/*US 1629/*US
1630 static const QString &attrIconText = KGlobal::staticQString("IconText"); 1630 static const QString &attrIconText = KGlobal::staticQString("IconText");
1631 static const QString &attrHighlight = KGlobal::staticQString("Highlighting"); 1631 static const QString &attrHighlight = KGlobal::staticQString("Highlighting");
1632 static const QString &attrTrans = KGlobal::staticQString("TransparentMoving"); 1632 static const QString &attrTrans = KGlobal::staticQString("TransparentMoving");
1633 static const QString &attrSize = KGlobal::staticQString("IconSize"); 1633 static const QString &attrSize = KGlobal::staticQString("IconSize");
1634*/ 1634*/
1635 // we actually do this in two steps. 1635 // we actually do this in two steps.
1636 // First, we read in the global styles [Toolbar style] (from the KControl module). 1636 // First, we read in the global styles [Toolbar style] (from the KControl module).
1637 // Then, if the toolbar is NOT 'mainToolBar', we will also try to read in [barname Toolbar style] 1637 // Then, if the toolbar is NOT 'mainToolBar', we will also try to read in [barname Toolbar style]
1638 bool highlight; 1638 bool highlight;
1639 int transparent; 1639 int transparent;
1640 QString icontext; 1640 QString icontext;
1641 int iconsize = 0; 1641 int iconsize = 0;
1642 1642
1643 // this is the first iteration 1643 // this is the first iteration
1644 QString grpToolbar(QString::fromLatin1("Toolbar style")); 1644 QString grpToolbar(QString::fromLatin1("Toolbar style"));
1645 { // start block for KConfigGroupSaver 1645 { // start block for KConfigGroupSaver
1646 KConfigGroupSaver saver(gconfig, grpToolbar); 1646 KConfigGroupSaver saver(gconfig, grpToolbar);
1647 1647
1648 // first, get the generic settings 1648 // first, get the generic settings
1649//US highlight = gconfig->readBoolEntry(attrHighlight, true); 1649//US highlight = gconfig->readBoolEntry(attrHighlight, true);
1650 highlight = gconfig->readBoolEntry("Highlighting", true); 1650 highlight = gconfig->readBoolEntry("Highlighting", true);
1651//US transparent = gconfig->readBoolEntry(attrTrans, true); 1651//US transparent = gconfig->readBoolEntry(attrTrans, true);
1652 transparent = gconfig->readBoolEntry("TransparentMoving", true); 1652 transparent = gconfig->readBoolEntry("TransparentMoving", true);
1653 1653
1654 // we read in the IconText property *only* if we intend on actually 1654 // we read in the IconText property *only* if we intend on actually
1655 // honoring it 1655 // honoring it
1656 if (d->m_honorStyle) 1656 if (d->m_honorStyle)
1657//US d->IconTextDefault = gconfig->readEntry(attrIconText, d->IconTextDefault); 1657//US d->IconTextDefault = gconfig->readEntry(attrIconText, d->IconTextDefault);
1658 d->IconTextDefault = gconfig->readEntry("IconText", d->IconTextDefault); 1658 d->IconTextDefault = gconfig->readEntry("IconText", d->IconTextDefault);
1659 else 1659 else
1660 d->IconTextDefault = "IconOnly"; 1660 d->IconTextDefault = "IconOnly";
1661 1661
1662 // Use the default icon size for toolbar icons. 1662 // Use the default icon size for toolbar icons.
1663//US d->IconSizeDefault = gconfig->readNumEntry(attrSize, d->IconSizeDefault); 1663//US d->IconSizeDefault = gconfig->readNumEntry(attrSize, d->IconSizeDefault);
1664 d->IconSizeDefault = gconfig->readNumEntry("IconSize", d->IconSizeDefault); 1664 d->IconSizeDefault = gconfig->readNumEntry("IconSize", d->IconSizeDefault);
1665 1665
1666 if ( !forceGlobal && config->hasGroup(configGroup) ) 1666 if ( !forceGlobal && config->hasGroup(configGroup) )
1667 { 1667 {
1668 config->setGroup(configGroup); 1668 config->setGroup(configGroup);
1669 1669
1670 // first, get the generic settings 1670 // first, get the generic settings
1671//US highlight = config->readBoolEntry(attrHighlight, highlight); 1671//US highlight = config->readBoolEntry(attrHighlight, highlight);
1672 highlight = config->readBoolEntry("Highlighting", highlight); 1672 highlight = config->readBoolEntry("Highlighting", highlight);
1673//US transparent = config->readBoolEntry(attrTrans, transparent); 1673//US transparent = config->readBoolEntry(attrTrans, transparent);
1674 transparent = config->readBoolEntry("TransparentMoving", transparent); 1674 transparent = config->readBoolEntry("TransparentMoving", transparent);
1675 // now we always read in the IconText property 1675 // now we always read in the IconText property
1676//US icontext = config->readEntry(attrIconText, d->IconTextDefault); 1676//US icontext = config->readEntry(attrIconText, d->IconTextDefault);
1677 icontext = config->readEntry("IconText", d->IconTextDefault); 1677 icontext = config->readEntry("IconText", d->IconTextDefault);
1678 1678
1679 // now get the size 1679 // now get the size
1680//US iconsize = config->readNumEntry(attrSize, d->IconSizeDefault); 1680//US iconsize = config->readNumEntry(attrSize, d->IconSizeDefault);
1681 iconsize = config->readNumEntry("IconSize", d->IconSizeDefault); 1681 iconsize = config->readNumEntry("IconSize", d->IconSizeDefault);
1682 } 1682 }
1683 else 1683 else
1684 { 1684 {
1685 iconsize = d->IconSizeDefault; 1685 iconsize = d->IconSizeDefault;
1686 icontext = d->IconTextDefault; 1686 icontext = d->IconTextDefault;
1687 } 1687 }
1688 1688
1689 // revert back to the old group 1689 // revert back to the old group
1690 } // end block for KConfigGroupSaver 1690 } // end block for KConfigGroupSaver
1691 1691
1692 bool doUpdate = false; 1692 bool doUpdate = false;
1693 1693
1694 IconText icon_text; 1694 IconText icon_text;
1695 if ( icontext == "IconTextRight" ) 1695 if ( icontext == "IconTextRight" )
1696 icon_text = IconTextRight; 1696 icon_text = IconTextRight;
1697 else if ( icontext == "IconTextBottom" ) 1697 else if ( icontext == "IconTextBottom" )
1698 icon_text = IconTextBottom; 1698 icon_text = IconTextBottom;
1699 else if ( icontext == "TextOnly" ) 1699 else if ( icontext == "TextOnly" )
1700 icon_text = TextOnly; 1700 icon_text = TextOnly;
1701 else 1701 else
1702 icon_text = IconOnly; 1702 icon_text = IconOnly;
1703 1703
1704 // check if the icon/text has changed 1704 // check if the icon/text has changed
1705 if (icon_text != d->m_iconText) { 1705 if (icon_text != d->m_iconText) {
1706 //kdDebug(220) << "KToolBar::applyAppearanceSettings setIconText " << icon_text << endl; 1706 //kdDebug(220) << "KToolBar::applyAppearanceSettings setIconText " << icon_text << endl;
1707 setIconText(icon_text, false); 1707 setIconText(icon_text, false);
1708 doUpdate = true; 1708 doUpdate = true;
1709 } 1709 }
1710 1710
1711 // ...and check if the icon size has changed 1711 // ...and check if the icon size has changed
1712 if (iconsize != d->m_iconSize) { 1712 if (iconsize != d->m_iconSize) {
1713 setIconSize(iconsize, false); 1713 setIconSize(iconsize, false);
1714 doUpdate = true; 1714 doUpdate = true;
1715 } 1715 }
1716 1716
1717 QMainWindow *mw = mainWindow(); 1717 QMainWindow *mw = mainWindow();
1718 1718
1719 // ...and if we should highlight 1719 // ...and if we should highlight
1720 if ( highlight != d->m_highlight ) { 1720 if ( highlight != d->m_highlight ) {
1721 d->m_highlight = highlight; 1721 d->m_highlight = highlight;
1722 doUpdate = true; 1722 doUpdate = true;
1723 } 1723 }
1724 1724
1725 // ...and if we should move transparently 1725 // ...and if we should move transparently
1726 if ( mw && transparent != (!mw->opaqueMoving()) ) { 1726 if ( mw && transparent != (!mw->opaqueMoving()) ) {
1727 mw->setOpaqueMoving( !transparent ); 1727 mw->setOpaqueMoving( !transparent );
1728 } 1728 }
1729 1729
1730 if (doUpdate) 1730 if (doUpdate)
1731 emit modechange(); // tell buttons what happened 1731 emit modechange(); // tell buttons what happened
1732 if (isVisible ()) 1732 if (isVisible ())
1733 updateGeometry(); 1733 updateGeometry();
1734} 1734}
1735 1735
1736void KToolBar::applySettings(KConfig *config, const QString &_configGroup) 1736void KToolBar::applySettings(KConfig *config, const QString &_configGroup)
1737{ 1737{
1738 //kdDebug(220) << "KToolBar::applySettings group=" << _configGroup << endl; 1738 //kdDebug(220) << "KToolBar::applySettings group=" << _configGroup << endl;
1739 1739
1740 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup; 1740 QString configGroup = _configGroup.isEmpty() ? settingsGroup() : _configGroup;
1741 1741
1742 /* 1742 /*
1743 Let's explain this a bit more in details. 1743 Let's explain this a bit more in details.
1744 The order in which we apply settings is : 1744 The order in which we apply settings is :
1745 Global config / <appnamerc> user settings if no XMLGUI is used 1745 Global config / <appnamerc> user settings if no XMLGUI is used
1746 Global config / App-XML attributes / <appnamerc> user settings if XMLGUI is used 1746 Global config / App-XML attributes / <appnamerc> user settings if XMLGUI is used
1747 1747
1748 So in the first case, we simply read everything from KConfig as below, 1748 So in the first case, we simply read everything from KConfig as below,
1749 but in the second case we don't do anything here if there is no app-specific config, 1749 but in the second case we don't do anything here if there is no app-specific config,
1750 and the XMLGUI uses the static methods of this class to get the global defaults. 1750 and the XMLGUI uses the static methods of this class to get the global defaults.
1751 1751
1752 Global config doesn't include position (index, offset, newline and hidden/shown). 1752 Global config doesn't include position (index, offset, newline and hidden/shown).
1753 */ 1753 */
1754 1754
1755 // First the appearance stuff - the one which has a global config 1755 // First the appearance stuff - the one which has a global config
1756 applyAppearanceSettings( config, _configGroup ); 1756 applyAppearanceSettings( config, _configGroup );
1757 1757
1758 // ...and now the position stuff 1758 // ...and now the position stuff
1759 if ( config->hasGroup(configGroup) ) 1759 if ( config->hasGroup(configGroup) )
1760 { 1760 {
1761 KConfigGroupSaver cgs(config, configGroup); 1761 KConfigGroupSaver cgs(config, configGroup);
1762/*US 1762/*US
1763 static const QString &attrPosition = KGlobal::staticQString("Position"); 1763 static const QString &attrPosition = KGlobal::staticQString("Position");
1764 static const QString &attrIndex = KGlobal::staticQString("Index"); 1764 static const QString &attrIndex = KGlobal::staticQString("Index");
1765 static const QString &attrOffset = KGlobal::staticQString("Offset"); 1765 static const QString &attrOffset = KGlobal::staticQString("Offset");
1766 static const QString &attrNewLine = KGlobal::staticQString("NewLine"); 1766 static const QString &attrNewLine = KGlobal::staticQString("NewLine");
1767 static const QString &attrHidden = KGlobal::staticQString("Hidden"); 1767 static const QString &attrHidden = KGlobal::staticQString("Hidden");
1768 1768
1769 QString position = config->readEntry(attrPosition, d->PositionDefault); 1769 QString position = config->readEntry(attrPosition, d->PositionDefault);
1770 int index = config->readNumEntry(attrIndex, d->IndexDefault); 1770 int index = config->readNumEntry(attrIndex, d->IndexDefault);
1771 int offset = config->readNumEntry(attrOffset, d->OffsetDefault); 1771 int offset = config->readNumEntry(attrOffset, d->OffsetDefault);
1772 bool newLine = config->readBoolEntry(attrNewLine, d->NewLineDefault); 1772 bool newLine = config->readBoolEntry(attrNewLine, d->NewLineDefault);
1773 bool hidden = config->readBoolEntry(attrHidden, d->HiddenDefault); 1773 bool hidden = config->readBoolEntry(attrHidden, d->HiddenDefault);
1774*/ 1774*/
1775 1775
1776 QString position = config->readEntry("Position", d->PositionDefault); 1776 QString position = config->readEntry("Position", d->PositionDefault);
1777 int index = config->readNumEntry("Index", d->IndexDefault); 1777 int index = config->readNumEntry("Index", d->IndexDefault);
1778 int offset = config->readNumEntry("Offset", d->OffsetDefault); 1778 int offset = config->readNumEntry("Offset", d->OffsetDefault);
1779 bool newLine = config->readBoolEntry("NewLine", d->NewLineDefault); 1779 bool newLine = config->readBoolEntry("NewLine", d->NewLineDefault);
1780 bool hidden = config->readBoolEntry("Hidden", d->HiddenDefault); 1780 bool hidden = config->readBoolEntry("Hidden", d->HiddenDefault);
1781 1781
1782/*US Dock pos(DockTop); 1782/*US Dock pos(DockTop);
1783 if ( position == "Top" ) 1783 if ( position == "Top" )
1784 pos = DockTop; 1784 pos = DockTop;
1785 else if ( position == "Bottom" ) 1785 else if ( position == "Bottom" )
1786 pos = DockBottom; 1786 pos = DockBottom;
1787 else if ( position == "Left" ) 1787 else if ( position == "Left" )
1788 pos = DockLeft; 1788 pos = DockLeft;
1789 else if ( position == "Right" ) 1789 else if ( position == "Right" )
1790 pos = DockRight; 1790 pos = DockRight;
1791 else if ( position == "Floating" ) 1791 else if ( position == "Floating" )
1792 pos = DockTornOff; 1792 pos = DockTornOff;
1793 else if ( position == "Flat" ) 1793 else if ( position == "Flat" )
1794 pos = DockMinimized; 1794 pos = DockMinimized;
1795*/ 1795*/
1796 QMainWindow::ToolBarDock pos(QMainWindow::Top); 1796 QMainWindow::ToolBarDock pos(QMainWindow::Top);
1797 if ( position == "Top" ) 1797 if ( position == "Top" )
1798 pos = QMainWindow::Top; 1798 pos = QMainWindow::Top;
1799 else if ( position == "Bottom" ) 1799 else if ( position == "Bottom" )
1800 pos = QMainWindow::Bottom; 1800 pos = QMainWindow::Bottom;
1801 else if ( position == "Left" ) 1801 else if ( position == "Left" )
1802 pos = QMainWindow::Left; 1802 pos = QMainWindow::Left;
1803 else if ( position == "Right" ) 1803 else if ( position == "Right" )
1804 pos = QMainWindow::Right; 1804 pos = QMainWindow::Right;
1805 else if ( position == "Floating" ) 1805 else if ( position == "Floating" )
1806 pos = QMainWindow::TornOff; 1806 pos = QMainWindow::TornOff;
1807 else if ( position == "Flat" ) 1807 else if ( position == "Flat" )
1808 pos = QMainWindow::Minimized; 1808 pos = QMainWindow::Minimized;
1809 1809
1810 //kdDebug(220) << "KToolBar::applySettings hidden=" << hidden << endl; 1810 //kdDebug(220) << "KToolBar::applySettings hidden=" << hidden << endl;
1811 if (hidden) 1811 if (hidden)
1812 hide(); 1812 hide();
1813 else 1813 else
1814 show(); 1814 show();
1815 1815
1816 if ( mainWindow() ) 1816 if ( mainWindow() )
1817 { 1817 {
1818 QMainWindow *mw = mainWindow(); 1818 QMainWindow *mw = mainWindow();
1819 1819
1820 //kdDebug(220) << "KToolBar::applySettings updating ToolbarInfo" << endl; 1820 //kdDebug(220) << "KToolBar::applySettings updating ToolbarInfo" << endl;
1821 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( pos, index, newLine, offset ); 1821 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( pos, index, newLine, offset );
1822 1822
1823 // moveDockWindow calls QDockArea which does a reparent() on us with 1823 // moveDockWindow calls QDockArea which does a reparent() on us with
1824 // showIt = true, so we loose our visibility status 1824 // showIt = true, so we loose our visibility status
1825 bool doHide = isHidden(); 1825 bool doHide = isHidden();
1826 1826
1827//US mw->moveDockWindow( this, pos, newLine, index, offset ); 1827//US mw->moveDockWindow( this, pos, newLine, index, offset );
1828 mw->moveToolBar( this, pos, newLine, index, offset ); 1828 mw->moveToolBar( this, pos, newLine, index, offset );
1829 1829
1830 //kdDebug(220) << "KToolBar::applySettings " << name() << " moveDockWindow with pos=" << pos << " newLine=" << newLine << " idx=" << index << " offs=" << offset << endl; 1830 //kdDebug(220) << "KToolBar::applySettings " << name() << " moveDockWindow with pos=" << pos << " newLine=" << newLine << " idx=" << index << " offs=" << offset << endl;
1831 if ( doHide ) 1831 if ( doHide )
1832 hide(); 1832 hide();
1833 } 1833 }
1834 if (isVisible ()) 1834 if (isVisible ())
1835 updateGeometry(); 1835 updateGeometry();
1836 } 1836 }
1837} 1837}
1838 1838
1839bool KToolBar::event( QEvent *e ) 1839bool KToolBar::event( QEvent *e )
1840{ 1840{
1841 if ( (e->type() == QEvent::LayoutHint) && isUpdatesEnabled() ) 1841 if ( (e->type() == QEvent::LayoutHint) && isUpdatesEnabled() )
1842 d->repaintTimer.start( 100, true ); 1842 d->repaintTimer.start( 100, true );
1843 1843
1844 if (e->type() == QEvent::ChildInserted ) 1844 if (e->type() == QEvent::ChildInserted )
1845 { 1845 {
1846 // By pass QToolBar::event, 1846 // By pass QToolBar::event,
1847 // it will show() the inserted child and we don't want to 1847 // it will show() the inserted child and we don't want to
1848 // do that until we have rebuild the layout. 1848 // do that until we have rebuild the layout.
1849 childEvent((QChildEvent *)e); 1849 childEvent((QChildEvent *)e);
1850 return true; 1850 return true;
1851 } 1851 }
1852 1852
1853 return QToolBar::event( e ); 1853 return QToolBar::event( e );
1854} 1854}
1855 1855
1856void KToolBar::slotRepaint() 1856void KToolBar::slotRepaint()
1857{ 1857{
1858 setUpdatesEnabled( FALSE ); 1858 setUpdatesEnabled( FALSE );
1859 // Send a resizeEvent to update the "toolbar extension arrow" 1859 // Send a resizeEvent to update the "toolbar extension arrow"
1860 // (The button you get when your toolbar-items don't fit in 1860 // (The button you get when your toolbar-items don't fit in
1861 // the available space) 1861 // the available space)
1862 QResizeEvent ev(size(), size()); 1862 QResizeEvent ev(size(), size());
1863 resizeEvent(&ev); 1863 resizeEvent(&ev);
1864 //#ifdef DESKTOP_VERSION 1864 //#ifdef DESKTOP_VERSION
1865 QApplication::sendPostedEvents( this, QEvent::LayoutHint ); 1865 QApplication::sendPostedEvents( this, QEvent::LayoutHint );
1866 //#endif //DESKTOP_VERSION 1866 //#endif //DESKTOP_VERSION
1867 setUpdatesEnabled( TRUE ); 1867 setUpdatesEnabled( TRUE );
1868 repaint( TRUE ); 1868 repaint( TRUE );
1869} 1869}
1870 1870
1871void KToolBar::toolBarPosChanged( QToolBar *tb ) 1871void KToolBar::toolBarPosChanged( QToolBar *tb )
1872{ 1872{
1873 if ( tb != this ) 1873 if ( tb != this )
1874 return; 1874 return;
1875//US if ( d->oldPos == DockMinimized ) 1875//US if ( d->oldPos == DockMinimized )
1876 if ( d->oldPos == QMainWindow::Minimized ) 1876 if ( d->oldPos == QMainWindow::Minimized )
1877 rebuildLayout(); 1877 rebuildLayout();
1878 d->oldPos = (QMainWindow::ToolBarDock)barPos(); 1878 d->oldPos = (QMainWindow::ToolBarDock)barPos();
1879/*US 1879/*US
1880 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) ) 1880 if ( mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
1881 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty(); 1881 static_cast<KMainWindow *>(mainWindow())->setSettingsDirty();
1882*/ 1882*/
1883} 1883}
1884 1884
1885/*US 1885/*US
1886void KToolBar::loadState( const QDomElement &element ) 1886void KToolBar::loadState( const QDomElement &element )
1887{ 1887{
1888 //kdDebug(220) << "KToolBar::loadState " << this << endl; 1888 //kdDebug(220) << "KToolBar::loadState " << this << endl;
1889 if ( !mainWindow() ) 1889 if ( !mainWindow() )
1890 return; 1890 return;
1891 1891
1892 { 1892 {
1893 QCString text = element.namedItem( "text" ).toElement().text().utf8(); 1893 QCString text = element.namedItem( "text" ).toElement().text().utf8();
1894 if ( text.isEmpty() ) 1894 if ( text.isEmpty() )
1895 text = element.namedItem( "Text" ).toElement().text().utf8(); 1895 text = element.namedItem( "Text" ).toElement().text().utf8();
1896 if ( !text.isEmpty() ) 1896 if ( !text.isEmpty() )
1897 setText( i18n( text ) ); 1897 setText( i18n( text ) );
1898 } 1898 }
1899 1899
1900 { 1900 {
1901 QCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1(); 1901 QCString attrFullWidth = element.attribute( "fullWidth" ).lower().latin1();
1902 if ( !attrFullWidth.isEmpty() ) 1902 if ( !attrFullWidth.isEmpty() )
1903 setFullSize( attrFullWidth == "true" ); 1903 setFullSize( attrFullWidth == "true" );
1904 } 1904 }
1905 1905
1906 Dock dock = DockTop; 1906 Dock dock = DockTop;
1907 { 1907 {
1908 QCString attrPosition = element.attribute( "position" ).lower().latin1(); 1908 QCString attrPosition = element.attribute( "position" ).lower().latin1();
1909 //kdDebug(220) << "KToolBar::loadState attrPosition=" << attrPosition << endl; 1909 //kdDebug(220) << "KToolBar::loadState attrPosition=" << attrPosition << endl;
1910 if ( !attrPosition.isEmpty() ) { 1910 if ( !attrPosition.isEmpty() ) {
1911 if ( attrPosition == "top" ) 1911 if ( attrPosition == "top" )
1912 dock = DockTop; 1912 dock = DockTop;
1913 else if ( attrPosition == "left" ) 1913 else if ( attrPosition == "left" )
1914 dock = DockLeft; 1914 dock = DockLeft;
1915 else if ( attrPosition == "right" ) 1915 else if ( attrPosition == "right" )
1916 dock = DockRight; 1916 dock = DockRight;
1917 else if ( attrPosition == "bottom" ) 1917 else if ( attrPosition == "bottom" )
1918 dock = DockBottom; 1918 dock = DockBottom;
1919 else if ( attrPosition == "floating" ) 1919 else if ( attrPosition == "floating" )
1920 dock = DockTornOff; 1920 dock = DockTornOff;
1921 else if ( attrPosition == "flat" ) 1921 else if ( attrPosition == "flat" )
1922 dock = DockMinimized; 1922 dock = DockMinimized;
1923 } 1923 }
1924 } 1924 }
1925 1925
1926 { 1926 {
1927 QCString attrIconText = element.attribute( "iconText" ).lower().latin1(); 1927 QCString attrIconText = element.attribute( "iconText" ).lower().latin1();
1928 if ( !attrIconText.isEmpty() ) { 1928 if ( !attrIconText.isEmpty() ) {
1929 //kdDebug(220) << "KToolBar::loadState attrIconText=" << attrIconText << endl; 1929 //kdDebug(220) << "KToolBar::loadState attrIconText=" << attrIconText << endl;
1930 if ( attrIconText == "icontextright" ) 1930 if ( attrIconText == "icontextright" )
1931 setIconText( KToolBar::IconTextRight ); 1931 setIconText( KToolBar::IconTextRight );
1932 else if ( attrIconText == "textonly" ) 1932 else if ( attrIconText == "textonly" )
1933 setIconText( KToolBar::TextOnly ); 1933 setIconText( KToolBar::TextOnly );
1934 else if ( attrIconText == "icontextbottom" ) 1934 else if ( attrIconText == "icontextbottom" )
1935 setIconText( KToolBar::IconTextBottom ); 1935 setIconText( KToolBar::IconTextBottom );
1936 else if ( attrIconText == "icononly" ) 1936 else if ( attrIconText == "icononly" )
1937 setIconText( KToolBar::IconOnly ); 1937 setIconText( KToolBar::IconOnly );
1938 } else 1938 } else
1939 // Use global setting 1939 // Use global setting
1940 setIconText( iconTextSetting() ); 1940 setIconText( iconTextSetting() );
1941 } 1941 }
1942 1942
1943 { 1943 {
1944 QString attrIconSize = element.attribute( "iconSize" ).lower(); 1944 QString attrIconSize = element.attribute( "iconSize" ).lower();
1945 if ( !attrIconSize.isEmpty() ) 1945 if ( !attrIconSize.isEmpty() )
1946 d->IconSizeDefault = attrIconSize.toInt(); 1946 d->IconSizeDefault = attrIconSize.toInt();
1947 setIconSize( d->IconSizeDefault ); 1947 setIconSize( d->IconSizeDefault );
1948 } 1948 }
1949 1949
1950 { 1950 {
1951 QString attrIndex = element.attribute( "index" ).lower(); 1951 QString attrIndex = element.attribute( "index" ).lower();
1952 if ( !attrIndex.isEmpty() ) 1952 if ( !attrIndex.isEmpty() )
1953 d->IndexDefault = attrIndex.toInt(); 1953 d->IndexDefault = attrIndex.toInt();
1954 } 1954 }
1955 1955
1956 { 1956 {
1957 QString attrOffset = element.attribute( "offset" ).lower(); 1957 QString attrOffset = element.attribute( "offset" ).lower();
1958 if ( !attrOffset.isEmpty() ) 1958 if ( !attrOffset.isEmpty() )
1959 d->OffsetDefault = attrOffset.toInt(); 1959 d->OffsetDefault = attrOffset.toInt();
1960 } 1960 }
1961 1961
1962 { 1962 {
1963 QString attrNewLine = element.attribute( "newline" ).lower(); 1963 QString attrNewLine = element.attribute( "newline" ).lower();
1964 if ( !attrNewLine.isEmpty() ) 1964 if ( !attrNewLine.isEmpty() )
1965 d->NewLineDefault = attrNewLine == "true"; 1965 d->NewLineDefault = attrNewLine == "true";
1966 } 1966 }
1967 1967
1968 { 1968 {
1969 QString attrHidden = element.attribute( "hidden" ).lower(); 1969 QString attrHidden = element.attribute( "hidden" ).lower();
1970 if ( !attrHidden.isEmpty() ) 1970 if ( !attrHidden.isEmpty() )
1971 d->HiddenDefault = attrHidden == "true"; 1971 d->HiddenDefault = attrHidden == "true";
1972 } 1972 }
1973 1973
1974 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( dock, d->IndexDefault, d->NewLineDefault, d->OffsetDefault ); 1974 d->toolBarInfo = KToolBarPrivate::ToolBarInfo( dock, d->IndexDefault, d->NewLineDefault, d->OffsetDefault );
1975 mainWindow()->addDockWindow( this, dock, d->NewLineDefault ); 1975 mainWindow()->addDockWindow( this, dock, d->NewLineDefault );
1976//US mainWindow()->moveDockWindow( this, dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault ); 1976//US mainWindow()->moveDockWindow( this, dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault );
1977 mainWindow()->moveToolBar( this, dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault ); 1977 mainWindow()->moveToolBar( this, dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault );
1978 1978
1979 // Apply the highlight button setting 1979 // Apply the highlight button setting
1980 d->m_highlight = highlightSetting(); 1980 d->m_highlight = highlightSetting();
1981 1981
1982 // Apply transparent-toolbar-moving setting (ok, this is global to the mainwindow, 1982 // Apply transparent-toolbar-moving setting (ok, this is global to the mainwindow,
1983 // but we do it only if there are toolbars...) 1983 // but we do it only if there are toolbars...)
1984 if ( transparentSetting() != !mainWindow()->opaqueMoving() ) 1984 if ( transparentSetting() != !mainWindow()->opaqueMoving() )
1985 mainWindow()->setOpaqueMoving( !transparentSetting() ); 1985 mainWindow()->setOpaqueMoving( !transparentSetting() );
1986 1986
1987 if ( d->HiddenDefault ) 1987 if ( d->HiddenDefault )
1988 hide(); 1988 hide();
1989 else 1989 else
1990 show(); 1990 show();
1991 1991
1992 getAttributes( d->PositionDefault, d->IconTextDefault, d->IndexDefault ); 1992 getAttributes( d->PositionDefault, d->IconTextDefault, d->IndexDefault );
1993} 1993}
1994*/ 1994*/
1995 1995
1996void KToolBar::getAttributes( QString &position, QString &icontext, int &index ) 1996void KToolBar::getAttributes( QString &position, QString &icontext, int &index )
1997{ 1997{
1998 // get all of the stuff to save 1998 // get all of the stuff to save
1999 switch ( barPos() ) { 1999 switch ( barPos() ) {
2000 case KToolBar::Flat: 2000 case KToolBar::Flat:
2001 position = "Flat"; 2001 position = "Flat";
2002 break; 2002 break;
2003 case KToolBar::Bottom: 2003 case KToolBar::Bottom:
2004 position = "Bottom"; 2004 position = "Bottom";
2005 break; 2005 break;
2006 case KToolBar::Left: 2006 case KToolBar::Left:
2007 position = "Left"; 2007 position = "Left";
2008 break; 2008 break;
2009 case KToolBar::Right: 2009 case KToolBar::Right:
2010 position = "Right"; 2010 position = "Right";
2011 break; 2011 break;
2012 case KToolBar::Floating: 2012 case KToolBar::Floating:
2013 position = "Floating"; 2013 position = "Floating";
2014 break; 2014 break;
2015 case KToolBar::Top: 2015 case KToolBar::Top:
2016 default: 2016 default:
2017 position = "Top"; 2017 position = "Top";
2018 break; 2018 break;
2019 } 2019 }
2020 2020
2021 if ( mainWindow() ) { 2021 if ( mainWindow() ) {
2022 QMainWindow::ToolBarDock dock; 2022 QMainWindow::ToolBarDock dock;
2023 bool newLine; 2023 bool newLine;
2024 int offset; 2024 int offset;
2025 mainWindow()->getLocation( this, dock, index, newLine, offset ); 2025 mainWindow()->getLocation( this, dock, index, newLine, offset );
2026 } 2026 }
2027 2027
2028 switch (d->m_iconText) { 2028 switch (d->m_iconText) {
2029 case KToolBar::IconTextRight: 2029 case KToolBar::IconTextRight:
2030 icontext = "IconTextRight"; 2030 icontext = "IconTextRight";
2031 break; 2031 break;
2032 case KToolBar::IconTextBottom: 2032 case KToolBar::IconTextBottom:
2033 icontext = "IconTextBottom"; 2033 icontext = "IconTextBottom";
2034 break; 2034 break;
2035 case KToolBar::TextOnly: 2035 case KToolBar::TextOnly:
2036 icontext = "TextOnly"; 2036 icontext = "TextOnly";
2037 break; 2037 break;
2038 case KToolBar::IconOnly: 2038 case KToolBar::IconOnly:
2039 default: 2039 default:
2040 icontext = "IconOnly"; 2040 icontext = "IconOnly";
2041 break; 2041 break;
2042 } 2042 }
2043} 2043}
2044/*US 2044/*US
2045void KToolBar::saveState( QDomElement &current ) 2045void KToolBar::saveState( QDomElement &current )
2046{ 2046{
2047 QString position, icontext; 2047 QString position, icontext;
2048 int index = -1; 2048 int index = -1;
2049 getAttributes( position, icontext, index ); 2049 getAttributes( position, icontext, index );
2050 2050
2051 current.setAttribute( "noMerge", "1" ); 2051 current.setAttribute( "noMerge", "1" );
2052 current.setAttribute( "position", position ); 2052 current.setAttribute( "position", position );
2053 current.setAttribute( "iconText", icontext ); 2053 current.setAttribute( "iconText", icontext );
2054 current.setAttribute( "index", index ); 2054 current.setAttribute( "index", index );
2055 current.setAttribute( "offset", offset() ); 2055 current.setAttribute( "offset", offset() );
2056 current.setAttribute( "newline", newLine() ); 2056 current.setAttribute( "newline", newLine() );
2057 if ( isHidden() ) 2057 if ( isHidden() )
2058 current.setAttribute( "hidden", "true" ); 2058 current.setAttribute( "hidden", "true" );
2059 d->modified = true; 2059 d->modified = true;
2060} 2060}
2061*/ 2061*/
2062 2062
2063void KToolBar::positionYourself( bool force ) 2063void KToolBar::positionYourself( bool force )
2064{ 2064{
2065 if (force) 2065 if (force)
2066 d->positioned = false; 2066 d->positioned = false;
2067 2067
2068 if ( d->positioned || !mainWindow() ) 2068 if ( d->positioned || !mainWindow() )
2069 { 2069 {
2070 //kdDebug(220) << "KToolBar::positionYourself d->positioned=true ALREADY DONE" << endl; 2070 //kdDebug(220) << "KToolBar::positionYourself d->positioned=true ALREADY DONE" << endl;
2071 return; 2071 return;
2072 } 2072 }
2073 // we can't test for ForceHide after moveDockWindow because QDockArea 2073 // we can't test for ForceHide after moveDockWindow because QDockArea
2074 // does a reparent() with showIt == true 2074 // does a reparent() with showIt == true
2075 bool doHide = isHidden(); 2075 bool doHide = isHidden();
2076 //kdDebug(220) << "positionYourself " << name() << " dock=" << d->toolBarInfo.dock << " newLine=" << d->toolBarInfo.newline << " offset=" << d->toolBarInfo.offset << endl; 2076 //kdDebug(220) << "positionYourself " << name() << " dock=" << d->toolBarInfo.dock << " newLine=" << d->toolBarInfo.newline << " offset=" << d->toolBarInfo.offset << endl;
2077/*US mainWindow()->moveDockWindow( this, d->toolBarInfo.dock, 2077/*US mainWindow()->moveDockWindow( this, d->toolBarInfo.dock,
2078 d->toolBarInfo.newline, 2078 d->toolBarInfo.newline,
2079 d->toolBarInfo.index, 2079 d->toolBarInfo.index,
2080 d->toolBarInfo.offset ); 2080 d->toolBarInfo.offset );
2081*/ 2081*/
2082 mainWindow()->moveToolBar( this, d->toolBarInfo.dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault ); 2082 mainWindow()->moveToolBar( this, d->toolBarInfo.dock, d->NewLineDefault, d->IndexDefault, d->OffsetDefault );
2083 2083
2084 if ( doHide ) 2084 if ( doHide )
2085 hide(); 2085 hide();
2086 // This method can only have an effect once - unless force is set 2086 // This method can only have an effect once - unless force is set
2087 d->positioned = TRUE; 2087 d->positioned = TRUE;
2088} 2088}
2089 2089
2090//US KPopupMenu *KToolBar::contextMenu() 2090//US KPopupMenu *KToolBar::contextMenu()
2091QPopupMenu *KToolBar::contextMenu() 2091QPopupMenu *KToolBar::contextMenu()
2092{ 2092{
2093 if ( context ) 2093 if ( context )
2094 return context; 2094 return context;
2095 2095
2096 // Construct our context popup menu. Name it qt_dockwidget_internal so it 2096 // Construct our context popup menu. Name it qt_dockwidget_internal so it
2097 // won't be deleted by QToolBar::clear(). 2097 // won't be deleted by QToolBar::clear().
2098//US context = new KPopupMenu( this, "qt_dockwidget_internal" ); 2098//US context = new KPopupMenu( this, "qt_dockwidget_internal" );
2099 context = new QPopupMenu( this, "qt_dockwidget_internal" ); 2099 context = new QPopupMenu( this, "qt_dockwidget_internal" );
2100//US context->insertTitle(i18n("Toolbar Menu")); 2100//US context->insertTitle(i18n("Toolbar Menu"));
2101 2101
2102//US KPopupMenu *orient = new KPopupMenu( context, "orient" ); 2102//US KPopupMenu *orient = new KPopupMenu( context, "orient" );
2103 QPopupMenu *orient = new QPopupMenu( context, "orient" ); 2103 QPopupMenu *orient = new QPopupMenu( context, "orient" );
2104 orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP ); 2104 orient->insertItem( i18n("toolbar position string","Top"), CONTEXT_TOP );
2105 orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT ); 2105 orient->insertItem( i18n("toolbar position string","Left"), CONTEXT_LEFT );
2106 orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT ); 2106 orient->insertItem( i18n("toolbar position string","Right"), CONTEXT_RIGHT );
2107 orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM ); 2107 orient->insertItem( i18n("toolbar position string","Bottom"), CONTEXT_BOTTOM );
2108 orient->insertSeparator(-1); 2108 orient->insertSeparator(-1);
2109 //orient->insertItem( i18n("toolbar position string","Floating"), CONTEXT_FLOAT ); 2109 //orient->insertItem( i18n("toolbar position string","Floating"), CONTEXT_FLOAT );
2110 orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT ); 2110 orient->insertItem( i18n("min toolbar", "Flat"), CONTEXT_FLAT );
2111 2111
2112//US KPopupMenu *mode = new KPopupMenu( context, "mode" ); 2112//US KPopupMenu *mode = new KPopupMenu( context, "mode" );
2113 QPopupMenu *mode = new QPopupMenu( context, "mode" ); 2113 QPopupMenu *mode = new QPopupMenu( context, "mode" );
2114 mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS ); 2114 mode->insertItem( i18n("Icons Only"), CONTEXT_ICONS );
2115 mode->insertItem( i18n("Text Only"), CONTEXT_TEXT ); 2115 mode->insertItem( i18n("Text Only"), CONTEXT_TEXT );
2116 mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT ); 2116 mode->insertItem( i18n("Text Alongside Icons"), CONTEXT_TEXTRIGHT );
2117 mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER ); 2117 mode->insertItem( i18n("Text Under Icons"), CONTEXT_TEXTUNDER );
2118 2118
2119//US KPopupMenu *size = new KPopupMenu( context, "size" ); 2119//US KPopupMenu *size = new KPopupMenu( context, "size" );
2120 QPopupMenu *size = new QPopupMenu( context, "size" ); 2120 QPopupMenu *size = new QPopupMenu( context, "size" );
2121 size->insertItem( i18n("Default"), CONTEXT_ICONSIZES ); 2121 size->insertItem( i18n("Default"), CONTEXT_ICONSIZES );
2122 // Query the current theme for available sizes 2122 // Query the current theme for available sizes
2123 QValueList<int> avSizes; 2123 QValueList<int> avSizes;
2124/*US 2124/*US
2125 KIconTheme *theme = KGlobal::instance()->iconLoader()->theme(); 2125 KIconTheme *theme = KGlobal::instance()->iconLoader()->theme();
2126 if (!::qstrcmp(QObject::name(), "mainToolBar")) 2126 if (!::qstrcmp(QObject::name(), "mainToolBar"))
2127 avSizes = theme->querySizes( KIcon::MainToolbar); 2127 avSizes = theme->querySizes( KIcon::MainToolbar);
2128 else 2128 else
2129 avSizes = theme->querySizes( KIcon::Toolbar); 2129 avSizes = theme->querySizes( KIcon::Toolbar);
2130*/ 2130*/
2131 avSizes << 16; 2131 avSizes << 16;
2132 avSizes << 32; 2132 avSizes << 32;
2133 2133
2134 d->iconSizes = avSizes; 2134 d->iconSizes = avSizes;
2135 2135
2136 QValueList<int>::Iterator it; 2136 QValueList<int>::Iterator it;
2137 for (it=avSizes.begin(); it!=avSizes.end(); it++) { 2137 for (it=avSizes.begin(); it!=avSizes.end(); it++) {
2138 QString text; 2138 QString text;
2139 if ( *it < 19 ) 2139 if ( *it < 19 )
2140 text = i18n("Small (%1x%2)").arg(*it).arg(*it); 2140 text = i18n("Small (%1x%2)").arg(*it).arg(*it);
2141 else if (*it < 25) 2141 else if (*it < 25)
2142 text = i18n("Medium (%1x%2)").arg(*it).arg(*it); 2142 text = i18n("Medium (%1x%2)").arg(*it).arg(*it);
2143 else 2143 else
2144 text = i18n("Large (%1x%2)").arg(*it).arg(*it); 2144 text = i18n("Large (%1x%2)").arg(*it).arg(*it);
2145 //we use the size as an id, with an offset 2145 //we use the size as an id, with an offset
2146 size->insertItem( text, CONTEXT_ICONSIZES + *it ); 2146 size->insertItem( text, CONTEXT_ICONSIZES + *it );
2147 } 2147 }
2148 2148
2149 context->insertItem( i18n("Orientation"), orient ); 2149 context->insertItem( i18n("Orientation"), orient );
2150 orient->setItemChecked(CONTEXT_TOP, true); 2150 orient->setItemChecked(CONTEXT_TOP, true);
2151 context->insertItem( i18n("Text Position"), mode ); 2151 context->insertItem( i18n("Text Position"), mode );
2152 context->setItemChecked(CONTEXT_ICONS, true); 2152 context->setItemChecked(CONTEXT_ICONS, true);
2153 context->insertItem( i18n("Icon Size"), size ); 2153 context->insertItem( i18n("Icon Size"), size );
2154 2154
2155/*US 2155/*US
2156 if (mainWindow()->inherits("KMainWindow")) 2156 if (mainWindow()->inherits("KMainWindow"))
2157 { 2157 {
2158 if ( (static_cast<KMainWindow*>(mainWindow())->toolBarMenuAction()) && 2158 if ( (static_cast<KMainWindow*>(mainWindow())->toolBarMenuAction()) &&
2159 (static_cast<KMainWindow*>(mainWindow())->hasMenuBar()) ) 2159 (static_cast<KMainWindow*>(mainWindow())->hasMenuBar()) )
2160 2160
2161 (static_cast<KMainWindow*>(mainWindow()))->toolBarMenuAction()->plug(context); 2161 (static_cast<KMainWindow*>(mainWindow()))->toolBarMenuAction()->plug(context);
2162 } 2162 }
2163*/ 2163*/
2164 2164
2165 connect( context, SIGNAL( aboutToShow() ), this, SLOT( slotContextAboutToShow() ) ); 2165 connect( context, SIGNAL( aboutToShow() ), this, SLOT( slotContextAboutToShow() ) );
2166 return context; 2166 return context;
2167} 2167}
2168 2168
2169void KToolBar::slotContextAboutToShow() 2169void KToolBar::slotContextAboutToShow()
2170{ 2170{
2171 if (!d->m_configurePlugged) 2171 if (!d->m_configurePlugged)
2172 { 2172 {
2173 // try to find "configure toolbars" action 2173 // try to find "configure toolbars" action
2174 2174
2175 KXMLGUIClient *xmlGuiClient = d->m_xmlguiClient; 2175 KXMLGUIClient *xmlGuiClient = d->m_xmlguiClient;
2176 if ( !xmlGuiClient && mainWindow() && mainWindow()->inherits( "KMainWindow" ) ) 2176 if ( !xmlGuiClient && mainWindow() && mainWindow()->inherits( "KMainWindow" ) )
2177 xmlGuiClient = (KXMLGUIClient *)mainWindow(); 2177 xmlGuiClient = (KXMLGUIClient *)mainWindow();
2178 if ( xmlGuiClient ) 2178 if ( xmlGuiClient )
2179 { 2179 {
2180 KAction *configureAction = xmlGuiClient->actionCollection()->action(KStdAction::stdName(KStdAction::ConfigureToolbars)); 2180 KAction *configureAction = xmlGuiClient->actionCollection()->action(KStdAction::stdName(KStdAction::ConfigureToolbars));
2181 if ( configureAction ) 2181 if ( configureAction )
2182 { 2182 {
2183 configureAction->plug(context); 2183 configureAction->plug(context);
2184 d->m_configurePlugged = true; 2184 d->m_configurePlugged = true;
2185 } 2185 }
2186 } 2186 }
2187 } 2187 }
2188 2188
2189 for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i) 2189 for(int i = CONTEXT_ICONS; i <= CONTEXT_TEXTUNDER; ++i)
2190 context->setItemChecked(i, false); 2190 context->setItemChecked(i, false);
2191 2191
2192 switch( d->m_iconText ) 2192 switch( d->m_iconText )
2193 { 2193 {
2194 case IconOnly: 2194 case IconOnly:
2195 default: 2195 default:
2196 context->setItemChecked(CONTEXT_ICONS, true); 2196 context->setItemChecked(CONTEXT_ICONS, true);
2197 break; 2197 break;
2198 case IconTextRight: 2198 case IconTextRight:
2199 context->setItemChecked(CONTEXT_TEXTRIGHT, true); 2199 context->setItemChecked(CONTEXT_TEXTRIGHT, true);
2200 break; 2200 break;
2201 case TextOnly: 2201 case TextOnly:
2202 context->setItemChecked(CONTEXT_TEXT, true); 2202 context->setItemChecked(CONTEXT_TEXT, true);
2203 break; 2203 break;
2204 case IconTextBottom: 2204 case IconTextBottom:
2205 context->setItemChecked(CONTEXT_TEXTUNDER, true); 2205 context->setItemChecked(CONTEXT_TEXTUNDER, true);
2206 break; 2206 break;
2207 } 2207 }
2208 2208
2209 QValueList<int>::ConstIterator iIt = d->iconSizes.begin(); 2209 QValueList<int>::ConstIterator iIt = d->iconSizes.begin();
2210 QValueList<int>::ConstIterator iEnd = d->iconSizes.end(); 2210 QValueList<int>::ConstIterator iEnd = d->iconSizes.end();
2211 for (; iIt != iEnd; ++iIt ) 2211 for (; iIt != iEnd; ++iIt )
2212 context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false ); 2212 context->setItemChecked( CONTEXT_ICONSIZES + *iIt, false );
2213 2213
2214 context->setItemChecked( CONTEXT_ICONSIZES, false ); 2214 context->setItemChecked( CONTEXT_ICONSIZES, false );
2215 2215
2216 context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true ); 2216 context->setItemChecked( CONTEXT_ICONSIZES + d->m_iconSize, true );
2217 2217
2218 for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i ) 2218 for ( int i = CONTEXT_TOP; i <= CONTEXT_FLAT; ++i )
2219 context->setItemChecked( i, false ); 2219 context->setItemChecked( i, false );
2220 2220
2221 switch ( barPos() ) 2221 switch ( barPos() )
2222 { 2222 {
2223 case KToolBar::Flat: 2223 case KToolBar::Flat:
2224 context->setItemChecked( CONTEXT_FLAT, true ); 2224 context->setItemChecked( CONTEXT_FLAT, true );
2225 break; 2225 break;
2226 case KToolBar::Bottom: 2226 case KToolBar::Bottom:
2227 context->setItemChecked( CONTEXT_BOTTOM, true ); 2227 context->setItemChecked( CONTEXT_BOTTOM, true );
2228 break; 2228 break;
2229 case KToolBar::Left: 2229 case KToolBar::Left:
2230 context->setItemChecked( CONTEXT_LEFT, true ); 2230 context->setItemChecked( CONTEXT_LEFT, true );
2231 break; 2231 break;
2232 case KToolBar::Right: 2232 case KToolBar::Right:
2233 context->setItemChecked( CONTEXT_RIGHT, true ); 2233 context->setItemChecked( CONTEXT_RIGHT, true );
2234 break; 2234 break;
2235 case KToolBar::Floating: 2235 case KToolBar::Floating:
2236 context->setItemChecked( CONTEXT_FLOAT, true ); 2236 context->setItemChecked( CONTEXT_FLOAT, true );
2237 break; 2237 break;
2238 case KToolBar::Top: 2238 case KToolBar::Top:
2239 context->setItemChecked( CONTEXT_TOP, true ); 2239 context->setItemChecked( CONTEXT_TOP, true );
2240 break; 2240 break;
2241 default: break; 2241 default: break;
2242 } 2242 }
2243} 2243}
2244 2244
2245void KToolBar::widgetDestroyed() 2245void KToolBar::widgetDestroyed()
2246{ 2246{
2247 removeWidgetInternal( (QWidget*)sender() ); 2247 removeWidgetInternal( (QWidget*)sender() );
2248} 2248}
2249 2249
2250void KToolBar::removeWidgetInternal( QWidget * w ) 2250void KToolBar::removeWidgetInternal( QWidget * w )
2251{ 2251{
2252 if ( inshutdownprocess ) 2252 if ( inshutdownprocess )
2253 return; 2253 return;
2254 widgets.removeRef( w ); 2254 widgets.removeRef( w );
2255 QMap< QWidget*, int >::Iterator it = widget2id.find( w ); 2255 QMap< QWidget*, int >::Iterator it = widget2id.find( w );
2256 if ( it == widget2id.end() ) 2256 if ( it == widget2id.end() )
2257 return; 2257 return;
2258 id2widget.remove( *it ); 2258 id2widget.remove( *it );
2259 widget2id.remove( it ); 2259 widget2id.remove( it );
2260} 2260}
2261 2261
2262void KToolBar::virtual_hook( int, void* ) 2262void KToolBar::virtual_hook( int, void* )
2263{ /*BASE::virtual_hook( id, data );*/ } 2263{ /*BASE::virtual_hook( id, data );*/ }
2264 2264
2265//US #include "ktoolbar.moc" 2265//US #include "ktoolbar.moc"
2266 2266
diff --git a/microkde/kdeui/ktoolbar.h b/microkde/kdeui/ktoolbar.h
index 49ff856..7a5c114 100644
--- a/microkde/kdeui/ktoolbar.h
+++ b/microkde/kdeui/ktoolbar.h
@@ -1,1108 +1,1108 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org) 2 Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org)
3 (C) 1997, 1998 Stephan Kulow (coolo@kde.org) 3 (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
4 (C) 1997, 1998 Sven Radej (radej@kde.org) 4 (C) 1997, 1998 Sven Radej (radej@kde.org)
5 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) 5 (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
6 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) 6 (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
7 (C) 1999, 2000 Kurt Granroth (granroth@kde.org) 7 (C) 1999, 2000 Kurt Granroth (granroth@kde.org)
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
11 License version 2 as published by the Free Software Foundation. 11 License version 2 as published by the Free Software Foundation.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22 */ 22 */
23 23
24#ifndef KTOOLBAR_H 24#ifndef KTOOLBAR_H
25#define KTOOLBAR_H 25#define KTOOLBAR_H
26 26
27#ifndef DESKTOP_VERSION 27#ifndef DESKTOP_VERSION
28#define private public 28#define private public
29#include <qtoolbar.h> 29#include <qtoolbar.h>
30#undef private 30#undef private
31#include <qpe/qpetoolbar.h> 31#include <qpe/qpetoolbar.h>
32#else 32#else
33#include <qtoolbar.h> 33#include <qtoolbar.h>
34#endif 34#endif
35 35
36 36
37#include <qmainwindow.h> 37#include <qmainwindow.h>
38#include <qcombobox.h> 38#include <qcombobox.h>
39#include <qmap.h> 39#include <qmap.h>
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <kglobal.h> 41#include <kglobal.h>
42#include <qguardedptr.h> 42#include <qguardedptr.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qiconset.h> 44#include <qiconset.h>
45 45
46class QDomElement; 46class QDomElement;
47class QSize; 47class QSize;
48class QPixmap; 48class QPixmap;
49class QPopupMenu; 49class QPopupMenu;
50class QStringList; 50class QStringList;
51class QDomDocument; 51class QDomDocument;
52class QTimer; 52class QTimer;
53 53
54class KLineEdit; 54class KLineEdit;
55class KToolBar; 55class KToolBar;
56class KToolBarButton; 56class KToolBarButton;
57class KToolBoxManager; 57class KToolBoxManager;
58//US class KAnimWidget; 58//US class KAnimWidget;
59//US class KPopupMenu; 59//US class KPopupMenu;
60//US class KInstance; 60//US class KInstance;
61class KComboBox; 61class KComboBox;
62class KXMLGUIClient; 62class KXMLGUIClient;
63 63
64class KToolBarPrivate; 64class KToolBarPrivate;
65 65
66class KToolBarSeparator : public QFrame 66class KToolBarSeparator : public QFrame
67{ 67{
68 Q_OBJECT 68 Q_OBJECT
69public: 69public:
70 KToolBarSeparator( Orientation, bool l, QToolBar *parent, const char* name=0 ); 70 KToolBarSeparator( Orientation, bool l, QToolBar *parent, const char* name=0 );
71 71
72 QSize sizeHint() const; 72 QSize sizeHint() const;
73 Orientation orientation() const { return orient; } 73 Orientation orientation() const { return orient; }
74 QSizePolicy sizePolicy() const; 74 QSizePolicy sizePolicy() const;
75 bool showLine() const { return line; } 75 bool showLine() const { return line; }
76public slots: 76public slots:
77 void setOrientation( Orientation ); 77 void setOrientation( Orientation );
78protected: 78protected:
79 void styleChange( QStyle& ); 79 void styleChange( QStyle& );
80private: 80private:
81 Orientation orient; 81 Orientation orient;
82 bool line; 82 bool line;
83}; 83};
84 84
85 85
86 /** 86 /**
87 * A KDE-style toolbar. 87 * A KDE-style toolbar.
88 * 88 *
89 * KToolBar can be dragged around in and between different docks. 89 * KToolBar can be dragged around in and between different docks.
90 * 90 *
91 * A KToolBar can contain all sorts of widgets. 91 * A KToolBar can contain all sorts of widgets.
92 * 92 *
93 * KToolBar can be used as a standalone widget, but @ref KMainWindow 93 * KToolBar can be used as a standalone widget, but @ref KMainWindow
94 * provides easy factories and management of one or more toolbars. 94 * provides easy factories and management of one or more toolbars.
95 * Once you have a KToolBar object, you can insert items into it with the 95 * Once you have a KToolBar object, you can insert items into it with the
96 * insert... methods, or remove them with the @ref removeItem() method. This 96 * insert... methods, or remove them with the @ref removeItem() method. This
97 * can be done at any time; the toolbar will be automatically updated. 97 * can be done at any time; the toolbar will be automatically updated.
98 * There are also many methods to set per-child properties like alignment 98 * There are also many methods to set per-child properties like alignment
99 * and toggle behaviour. 99 * and toggle behaviour.
100 * 100 *
101 * KToolBar uses a global config group to load toolbar settings on 101 * KToolBar uses a global config group to load toolbar settings on
102 * construction. It will reread this config group on a 102 * construction. It will reread this config group on a
103 * @ref KApplication::appearanceChanged() signal. 103 * @ref KApplication::appearanceChanged() signal.
104 * 104 *
105 * @short Floatable toolbar with auto resize. 105 * @short Floatable toolbar with auto resize.
106 * @version $Id$ 106 * @version $Id$
107 * @author Reginald Stadlbauer <reggie@kde.org>, Stephan Kulow <coolo@kde.org>, Sven Radej <radej@kde.org>. 107 * @author Reginald Stadlbauer <reggie@kde.org>, Stephan Kulow <coolo@kde.org>, Sven Radej <radej@kde.org>.
108 */ 108 */
109 109
110// strange things are happening ... so I have to use strange define methods ... 110// strange things are happening ... so I have to use strange define methods ...
111// porting KToolBar back to Qt2 really needs some strange hacks 111// porting KToolBar back to Qt2 really needs some strange hacks
112 112
113#ifndef DESKTOP_VERSION 113#ifndef DESKTOP_VERSION
114#define QToolBar QPEToolBar 114#define QToolBar QPEToolBar
115#endif 115#endif
116 116
117 class KToolBar : public QToolBar 117 class KToolBar : public QToolBar
118{ 118{
119 Q_OBJECT 119 Q_OBJECT
120 120
121 121
122 Q_ENUMS( IconText BarPosition ) 122 Q_ENUMS( IconText BarPosition )
123 123
124 Q_PROPERTY( IconText iconText READ iconText WRITE setIconText ) 124 Q_PROPERTY( IconText iconText READ iconText WRITE setIconText )
125 Q_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos ) 125 Q_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos )
126 Q_PROPERTY( bool fullSize READ fullSize WRITE setFullSize ) 126 Q_PROPERTY( bool fullSize READ fullSize WRITE setFullSize )
127 Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize ) 127 Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize )
128 Q_PROPERTY( QString text READ text WRITE setText ) 128 Q_PROPERTY( QString text READ text WRITE setText )
129#ifndef DESKTOP_VERSION 129#ifndef DESKTOP_VERSION
130#undef QToolBar 130#undef QToolBar
131#endif 131#endif
132public: 132public:
133 enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom}; 133 enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom};
134 /** 134 /**
135 * The state of the status bar. 135 * The state of the status bar.
136 * @deprecated 136 * @deprecated
137 **/ 137 **/
138 enum BarStatus{Toggle, Show, Hide}; 138 enum BarStatus{Toggle, Show, Hide};
139 /** 139 /**
140 * Possible bar positions. 140 * Possible bar positions.
141 **/ 141 **/
142 enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat}; 142 enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat};
143 143
144 /** 144 /**
145 * Constructor. 145 * Constructor.
146 * This constructor is used by the XML-GUI. If you use it, you need 146 * This constructor is used by the XML-GUI. If you use it, you need
147 * to call QMainWindow::addToolBar to specify the position of the toolbar. 147 * to call QMainWindow::addToolBar to specify the position of the toolbar.
148 * So it's simpler to use the other constructor. 148 * So it's simpler to use the other constructor.
149 * 149 *
150 * The toolbar will read in various global config settings for 150 * The toolbar will read in various global config settings for
151 * things like icon size and text position, etc. However, some of 151 * things like icon size and text position, etc. However, some of
152 * the settings will be honored only if @ref #_honor_mode is set to 152 * the settings will be honored only if @ref #_honor_mode is set to
153 * true. All other toolbars will be IconOnly and use Medium icons. 153 * true. All other toolbars will be IconOnly and use Medium icons.
154 * 154 *
155 * @param parent The standard toolbar parent (usually a 155 * @param parent The standard toolbar parent (usually a
156 * @ref KMainWindow) 156 * @ref KMainWindow)
157 * @param name The standard internal name 157 * @param name The standard internal name
158 * @param honor_style If true, then global settings for IconSize and IconText will be honored 158 * @param honor_style If true, then global settings for IconSize and IconText will be honored
159 * @param readConfig whether to apply the configuration (global and application-specific) 159 * @param readConfig whether to apply the configuration (global and application-specific)
160 */ 160 */
161 KToolBar( QWidget *parent, const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE ); 161 KToolBar( QWidget *parent, const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE );
162 162
163 /** 163 /**
164 * Constructor for non-XML-GUI applications. 164 * Constructor for non-XML-GUI applications.
165 * 165 *
166 * The toolbar will read in various global config settings for 166 * The toolbar will read in various global config settings for
167 * things like icon size and text position, etc. However, some of 167 * things like icon size and text position, etc. However, some of
168 * the settings will be honored only if @ref #_honor_mode is set to 168 * the settings will be honored only if @ref #_honor_mode is set to
169 * true. All other toolbars will be IconOnly and use Medium icons. 169 * true. All other toolbars will be IconOnly and use Medium icons.
170 * 170 *
171 * @param parentWindow The window that should be the parent of this toolbar 171 * @param parentWindow The window that should be the parent of this toolbar
172 * @param dock The position of the toolbar. Usually QMainWindow::Top. 172 * @param dock The position of the toolbar. Usually QMainWindow::Top.
173 * @param newLine If true, start a new line in the dock for this toolbar. 173 * @param newLine If true, start a new line in the dock for this toolbar.
174 * @param name The standard internal name 174 * @param name The standard internal name
175 * @param honor_style If true, then global settings for IconSize and IconText will be honored 175 * @param honor_style If true, then global settings for IconSize and IconText will be honored
176 * @param readConfig whether to apply the configuration (global and application-specific) 176 * @param readConfig whether to apply the configuration (global and application-specific)
177 */ 177 */
178 KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock /*= QMainWindow::Top*/, bool newLine = false, 178 KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock /*= QMainWindow::Top*/, bool newLine = false,
179 const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE ); 179 const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE );
180 180
181 /** 181 /**
182 * Constructor for non-XML-GUI applications. 182 * Constructor for non-XML-GUI applications.
183 * 183 *
184 * The toolbar will read in various global config settings for 184 * The toolbar will read in various global config settings for
185 * things like icon size and text position, etc. However, some of 185 * things like icon size and text position, etc. However, some of
186 * the settings will be honored only if @ref #_honor_mode is set to 186 * the settings will be honored only if @ref #_honor_mode is set to
187 * true. All other toolbars will be IconOnly and use Medium icons. 187 * true. All other toolbars will be IconOnly and use Medium icons.
188 * 188 *
189 * @param parentWindow The window that should be the parent of this toolbar 189 * @param parentWindow The window that should be the parent of this toolbar
190 * @param dock Another widget than the mainwindow to dock toolbar to. 190 * @param dock Another widget than the mainwindow to dock toolbar to.
191 * @param newLine If true, start a new line in the dock for this toolbar. 191 * @param newLine If true, start a new line in the dock for this toolbar.
192 * @param name The standard internal name 192 * @param name The standard internal name
193 * @param honor_style If true, then global settings for IconSize and IconText will be honored 193 * @param honor_style If true, then global settings for IconSize and IconText will be honored
194 * @param readConfig whether to apply the configuration (global and application-specific) 194 * @param readConfig whether to apply the configuration (global and application-specific)
195 */ 195 */
196 KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine = false, 196 KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine = false,
197 const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE ); 197 const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE );
198 198
199 virtual ~KToolBar(); 199 virtual ~KToolBar();
200 200
201 /** 201 /**
202 * Insert a button (a @ref KToolBarButton) with a pixmap. The 202 * Insert a button (a @ref KToolBarButton) with a pixmap. The
203 * pixmap is loaded by the button itself based on the global icon 203 * pixmap is loaded by the button itself based on the global icon
204 * settings. 204 * settings.
205 * 205 *
206 * You should connect to one or more signals in KToolBar: 206 * You should connect to one or more signals in KToolBar:
207 * @ref clicked() , @ref pressed() , @ref released() , or 207 * @ref clicked() , @ref pressed() , @ref released() , or
208 * @ref highlighted() and if the button is a toggle button 208 * @ref highlighted() and if the button is a toggle button
209 * (@ref setToggle() ) @ref toggled() . Those signals have @p id 209 * (@ref setToggle() ) @ref toggled() . Those signals have @p id
210 * of a button that caused the signal. If you want to bind a popup 210 * of a button that caused the signal. If you want to bind a popup
211 * to button, see @ref setButton(). 211 * to button, see @ref setButton().
212 * 212 *
213 * @param icon The name of the icon to use as the active pixmap 213 * @param icon The name of the icon to use as the active pixmap
214 * @param id The id of this button 214 * @param id The id of this button
215 * @param enabled Enable or disable the button at startup 215 * @param enabled Enable or disable the button at startup
216 * @param text The tooltip or toolbar text (depending on state) 216 * @param text The tooltip or toolbar text (depending on state)
217 * @param index The position of the button. (-1 = at end). 217 * @param index The position of the button. (-1 = at end).
218 * 218 *
219 * @return The item index. 219 * @return The item index.
220 */ 220 */
221 int insertButton(const QString& icon, int id, bool enabled = true, 221 int insertButton(const QString& icon, int id, bool enabled = true,
222 const QString& text = QString::null, int index=-1/*US , 222 const QString& text = QString::null, int index=-1/*US ,
223 KInstance *_instance = KGlobal::instance()*/); 223 KInstance *_instance = KGlobal::instance()*/);
224 224
225 /** 225 /**
226 * This is the same as above, but with specified signals and 226 * This is the same as above, but with specified signals and
227 * slots to which this button will be connected. 227 * slots to which this button will be connected.
228 * 228 *
229 * You can add more signals with @ref addConnection(). 229 * You can add more signals with @ref addConnection().
230 * 230 *
231 * @param icon The name of the icon to use as the active pixmap 231 * @param icon The name of the icon to use as the active pixmap
232 * @param id The id of this button 232 * @param id The id of this button
233 * @param signal The signal to connect to 233 * @param signal The signal to connect to
234 * @param receiver The slot's parent 234 * @param receiver The slot's parent
235 * @param enabled Enable or disable the button at startup 235 * @param enabled Enable or disable the button at startup
236 * @param text The tooltip or toolbar text (depending on state) 236 * @param text The tooltip or toolbar text (depending on state)
237 * @param index The position of the button. (-1 = at end). 237 * @param index The position of the button. (-1 = at end).
238 * 238 *
239 * @return The item index. 239 * @return The item index.
240 */ 240 */
241 int insertButton(const QString& icon, int id, const char *signal, 241 int insertButton(const QString& icon, int id, const char *signal,
242 const QObject *receiver, const char *slot, 242 const QObject *receiver, const char *slot,
243 bool enabled = true, const QString& text = QString::null, 243 bool enabled = true, const QString& text = QString::null,
244 int index=-1/*US, KInstance *_instance = KGlobal::instance()*/ ); 244 int index=-1/*US, KInstance *_instance = KGlobal::instance()*/ );
245 245
246 /** 246 /**
247 * Inserts a button (a @ref KToolBarButton) with the specified 247 * Inserts a button (a @ref KToolBarButton) with the specified
248 * pixmap. This pixmap will be used as the "active" one and the 248 * pixmap. This pixmap will be used as the "active" one and the
249 * disabled and default ones will be autogenerated. 249 * disabled and default ones will be autogenerated.
250 * 250 *
251 * It is recommended that you use the insertButton function that 251 * It is recommended that you use the insertButton function that
252 * allows you to specify the icon name rather then the pixmap 252 * allows you to specify the icon name rather then the pixmap
253 * itself. Specifying the icon name is much more flexible. 253 * itself. Specifying the icon name is much more flexible.
254 * 254 *
255 * You should connect to one or more signals in KToolBar: 255 * You should connect to one or more signals in KToolBar:
256 * @ref clicked() , @ref pressed() , @ref released() , or 256 * @ref clicked() , @ref pressed() , @ref released() , or
257 * @ref highlighted() and if the button is a toggle button 257 * @ref highlighted() and if the button is a toggle button
258 * (@ref setToggle() ) @ref toggled() . Those signals have @p id 258 * (@ref setToggle() ) @ref toggled() . Those signals have @p id
259 * of a button that caused the signal. If you want to bind a popup 259 * of a button that caused the signal. If you want to bind a popup
260 * to button, see @ref setButton(). 260 * to button, see @ref setButton().
261 * 261 *
262 * @param pixmap The active pixmap 262 * @param pixmap The active pixmap
263 * @param id The id of this button 263 * @param id The id of this button
264 * @param enabled Enable or disable the button at startup 264 * @param enabled Enable or disable the button at startup
265 * @param text The tooltip or toolbar text (depending on state) 265 * @param text The tooltip or toolbar text (depending on state)
266 * @param index The position of the button. (-1 = at end). 266 * @param index The position of the button. (-1 = at end).
267 * 267 *
268 * @return The item index. 268 * @return The item index.
269 */ 269 */
270 int insertButton(const QPixmap& pixmap, int id, bool enabled = true, 270 int insertButton(const QPixmap& pixmap, int id, bool enabled = true,
271 const QString& text = QString::null, int index=-1 ); 271 const QString& text = QString::null, int index=-1 );
272 272
273 /** 273 /**
274 * This is the same as above, but with specified signals and 274 * This is the same as above, but with specified signals and
275 * slots to which this button will be connected. 275 * slots to which this button will be connected.
276 * 276 *
277 * You can add more signals with @ref addConnection(). 277 * You can add more signals with @ref addConnection().
278 * 278 *
279 * @param icon The name of the icon to use as the active pixmap 279 * @param icon The name of the icon to use as the active pixmap
280 * @param id The id of this button 280 * @param id The id of this button
281 * @param signal The signal to connect to 281 * @param signal The signal to connect to
282 * @param receiver The slot's parent 282 * @param receiver The slot's parent
283 * @param enabled Enable or disable the button at startup 283 * @param enabled Enable or disable the button at startup
284 * @param text The tooltip or toolbar text (depending on state) 284 * @param text The tooltip or toolbar text (depending on state)
285 * @param index The position of the button. (-1 = at end). 285 * @param index The position of the button. (-1 = at end).
286 * 286 *
287 * @return The item index. 287 * @return The item index.
288 */ 288 */
289 int insertButton(const QPixmap& pixmap, int id, const char *signal, 289 int insertButton(const QPixmap& pixmap, int id, const char *signal,
290 const QObject *receiver, const char *slot, 290 const QObject *receiver, const char *slot,
291 bool enabled = true, const QString& text = QString::null, 291 bool enabled = true, const QString& text = QString::null,
292 int index=-1 ); 292 int index=-1 );
293 293
294 /** 294 /**
295 * Inserts a button with popupmenu. 295 * Inserts a button with popupmenu.
296 * 296 *
297 * Button will have small 297 * Button will have small
298 * triangle. You have to connect to popup's signals. The 298 * triangle. You have to connect to popup's signals. The
299 * signals @ref KButton::pressed(), @ref KButton::released(), 299 * signals @ref KButton::pressed(), @ref KButton::released(),
300 * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not 300 * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not
301 * emmited by 301 * emmited by
302 * this button (see @ref setDelayedPopup() for that). 302 * this button (see @ref setDelayedPopup() for that).
303 * You can add custom popups which inherit @ref QPopupMenu to get popups 303 * You can add custom popups which inherit @ref QPopupMenu to get popups
304 * with tables, drawings etc. Just don't fiddle with events there. 304 * with tables, drawings etc. Just don't fiddle with events there.
305 */ 305 */
306 int insertButton(const QString& icon, int id, QPopupMenu *popup, 306 int insertButton(const QString& icon, int id, QPopupMenu *popup,
307 bool enabled, const QString&_text, int index=-1); 307 bool enabled, const QString&_text, int index=-1);
308 308
309 /** 309 /**
310 * Inserts a button with popupmenu. 310 * Inserts a button with popupmenu.
311 * 311 *
312 * Button will have small 312 * Button will have small
313 * triangle. You have to connect to popup's signals. The 313 * triangle. You have to connect to popup's signals. The
314 * signals @ref KButton::pressed(), @ref KButton::released(), 314 * signals @ref KButton::pressed(), @ref KButton::released(),
315 * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not 315 * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not
316 * emmited by 316 * emmited by
317 * this button (see @ref setDelayedPopup() for that). 317 * this button (see @ref setDelayedPopup() for that).
318 * You can add custom popups which inherit @ref QPopupMenu to get popups 318 * You can add custom popups which inherit @ref QPopupMenu to get popups
319 * with tables, drawings etc. Just don't fiddle with events there. 319 * with tables, drawings etc. Just don't fiddle with events there.
320 */ 320 */
321 int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup, 321 int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
322 bool enabled, const QString&_text, int index=-1); 322 bool enabled, const QString&_text, int index=-1);
323 323
324 /** 324 /**
325 * Inserts a @ref KLineEdit. You have to specify signals and slots to 325 * Inserts a @ref KLineEdit. You have to specify signals and slots to
326 * which KLineEdit will be connected. KLineEdit has all slots QLineEdit 326 * which KLineEdit will be connected. KLineEdit has all slots QLineEdit
327 * has, plus signals @ref KLineEdit::completion and @ref KLineEdit::textRotation 327 * has, plus signals @ref KLineEdit::completion and @ref KLineEdit::textRotation
328 * KLineEdit can be set to autoresize itself to full free width 328 * KLineEdit can be set to autoresize itself to full free width
329 * in toolbar, that is to last right aligned item. For that, 329 * in toolbar, that is to last right aligned item. For that,
330 * toolbar must be set to full width (which it is by default). 330 * toolbar must be set to full width (which it is by default).
331 * @see setFullWidth() 331 * @see setFullWidth()
332 * @see setItemAutoSized() 332 * @see setItemAutoSized()
333 * @see KLineEdit 333 * @see KLineEdit
334 * @return Item index. 334 * @return Item index.
335 */ 335 */
336 int insertLined (const QString& text, int id, 336 int insertLined (const QString& text, int id,
337 const char *signal, 337 const char *signal,
338 const QObject *receiver, const char *slot, 338 const QObject *receiver, const char *slot,
339 bool enabled = true, 339 bool enabled = true,
340 const QString& toolTipText = QString::null, 340 const QString& toolTipText = QString::null,
341 int size = 70, int index =-1); 341 int size = 70, int index =-1);
342 342
343 /** 343 /**
344 * Inserts a @ref KComboBox with list. 344 * Inserts a @ref KComboBox with list.
345 * 345 *
346 * Can be writable, but cannot contain 346 * Can be writable, but cannot contain
347 * pixmaps. By default inserting policy is AtBottom, i.e. typed items 347 * pixmaps. By default inserting policy is AtBottom, i.e. typed items
348 * are placed at the bottom of the list. Can be autosized. If the size 348 * are placed at the bottom of the list. Can be autosized. If the size
349 * argument is specified as -1, the width of the combobox is automatically 349 * argument is specified as -1, the width of the combobox is automatically
350 * computed. 350 * computed.
351 * 351 *
352 * @see setFullWidth() 352 * @see setFullWidth()
353 * @see setItemAutoSized() 353 * @see setItemAutoSized()
354 * @see KComboBox 354 * @see KComboBox
355 * @return Item index. 355 * @return Item index.
356 */ 356 */
357 int insertCombo (const QStringList &list, int id, bool writable, 357 int insertCombo (const QStringList &list, int id, bool writable,
358 const char *signal, const QObject *receiver, 358 const char *signal, const QObject *receiver,
359 const char *slot, bool enabled=true, 359 const char *slot, bool enabled=true,
360 const QString& tooltiptext=QString::null, 360 const QString& tooltiptext=QString::null,
361 int size=70, int index=-1, 361 int size=70, int index=-1,
362 QComboBox::Policy policy = QComboBox::AtBottom); 362 QComboBox::Policy policy = QComboBox::AtBottom);
363 363
364 /** 364 /**
365 * Insert a @ref KComboBox with text. 365 * Insert a @ref KComboBox with text.
366 * 366 *
367 * The rest is the same as above. 367 * The rest is the same as above.
368 * @see setItemAutoSized() 368 * @see setItemAutoSized()
369 * 369 *
370 * @see KComboBox 370 * @see KComboBox
371 * @return Item index. 371 * @return Item index.
372 */ 372 */
373 int insertCombo (const QString& text, int id, bool writable, 373 int insertCombo (const QString& text, int id, bool writable,
374 const char *signal, QObject *recevier, 374 const char *signal, QObject *recevier,
375 const char *slot, bool enabled=true, 375 const char *slot, bool enabled=true,
376 const QString& tooltiptext=QString::null, 376 const QString& tooltiptext=QString::null,
377 int size=70, int index=-1, 377 int size=70, int index=-1,
378 QComboBox::Policy policy = QComboBox::AtBottom); 378 QComboBox::Policy policy = QComboBox::AtBottom);
379 379
380 /** 380 /**
381 * Inserts a separator into the toolbar with the given id. 381 * Inserts a separator into the toolbar with the given id.
382 * Returns the separator's index 382 * Returns the separator's index
383 */ 383 */
384 int insertSeparator( int index = -1, int id = -1 ); 384 int insertSeparator( int index = -1, int id = -1 );
385 385
386 /** 386 /**
387 * Inserts a line separator into the toolbar with the given id. 387 * Inserts a line separator into the toolbar with the given id.
388 * Returns the separator's index 388 * Returns the separator's index
389 */ 389 */
390 int insertLineSeparator( int index = -1, int id = -1 ); 390 int insertLineSeparator( int index = -1, int id = -1 );
391 391
392 /** 392 /**
393 * Inserts a user-defined widget. The widget @p must have this 393 * Inserts a user-defined widget. The widget @p must have this
394 * toolbar as its parent. 394 * toolbar as its parent.
395 * 395 *
396 * Widget must have a QWidget for base class. Widget can be 396 * Widget must have a QWidget for base class. Widget can be
397 * autosized to full width. If you forget about it, you can get a 397 * autosized to full width. If you forget about it, you can get a
398 * pointer to this widget with @ref getWidget(). 398 * pointer to this widget with @ref getWidget().
399 * @see setItemAutoSized() 399 * @see setItemAutoSized()
400 * @return Item index. 400 * @return Item index.
401 */ 401 */
402 int insertWidget(int id, int width, QWidget *_widget, int index=-1); 402 int insertWidget(int id, int width, QWidget *_widget, int index=-1);
403 403
404 /** 404 /**
405 * Inserts an animated widget. A @ref KAnimWidget will be created 405 * Inserts an animated widget. A @ref KAnimWidget will be created
406 * internally using the icon name you provide. 406 * internally using the icon name you provide.
407 * This will emit a signal (clicked()) whenever the 407 * This will emit a signal (clicked()) whenever the
408 * animation widget is clicked. 408 * animation widget is clicked.
409 * 409 *
410 * @see animatedWidget() 410 * @see animatedWidget()
411 * 411 *
412 * @param id The id for this toolbar item 412 * @param id The id for this toolbar item
413 * @param receiver The parent of your slot 413 * @param receiver The parent of your slot
414 * @param slot The slot to receive the clicked() signal 414 * @param slot The slot to receive the clicked() signal
415 * @param icons The name of the animation icon group to use 415 * @param icons The name of the animation icon group to use
416 * @param index The item index 416 * @param index The item index
417 * 417 *
418 * @return The item index 418 * @return The item index
419 */ 419 */
420/*US 420/*US
421 int insertAnimatedWidget(int id, QObject *receiver, const char *slot, 421 int insertAnimatedWidget(int id, QObject *receiver, const char *slot,
422 const QString& icons, int index = -1); 422 const QString& icons, int index = -1);
423*/ 423*/
424 /** 424 /**
425 * This will return a pointer to the given animated widget, if it 425 * This will return a pointer to the given animated widget, if it
426 * exists. 426 * exists.
427 * 427 *
428 * @see insertAnimatedWidget 428 * @see insertAnimatedWidget
429 * 429 *
430 * @param id The id for the widget you want to get a pointer to 430 * @param id The id for the widget you want to get a pointer to
431 * 431 *
432 * @return A pointer to the current animated widget or 0L 432 * @return A pointer to the current animated widget or 0L
433 */ 433 */
434//US KAnimWidget *animatedWidget( int id ); 434//US KAnimWidget *animatedWidget( int id );
435 435
436 /** 436 /**
437 * Adds connections to items. 437 * Adds connections to items.
438 * 438 *
439 * It is important that you 439 * It is important that you
440 * know the @p id of particular item. Nothing happens if you forget @p id. 440 * know the @p id of particular item. Nothing happens if you forget @p id.
441 */ 441 */
442 void addConnection (int id, const char *signal, 442 void addConnection (int id, const char *signal,
443 const QObject *receiver, const char *slot); 443 const QObject *receiver, const char *slot);
444 /** 444 /**
445 * Enables/disables item. 445 * Enables/disables item.
446 */ 446 */
447 void setItemEnabled( int id, bool enabled ); 447 void setItemEnabled( int id, bool enabled );
448 448
449 /** 449 /**
450 * Sets the icon for a button. 450 * Sets the icon for a button.
451 * 451 *
452 * Can be used while button is visible. 452 * Can be used while button is visible.
453 */ 453 */
454 void setButtonIcon( int id, const QString& _icon ); 454 void setButtonIcon( int id, const QString& _icon );
455 455
456 /** 456 /**
457 * Sets button pixmap. 457 * Sets button pixmap.
458 * 458 *
459 * Can be used while button is visible. 459 * Can be used while button is visible.
460 */ 460 */
461 void setButtonPixmap( int id, const QPixmap& _pixmap ); 461 void setButtonPixmap( int id, const QPixmap& _pixmap );
462 462
463 /** 463 /**
464 * Sets a button icon from a QIconSet. 464 * Sets a button icon from a QIconSet.
465 * 465 *
466 * Can be used while button is visible. 466 * Can be used while button is visible.
467 */ 467 */
468 void setButtonIconSet( int id, const QIconSet& iconset ); 468 void setButtonIconSet( int id, const QIconSet& iconset );
469 469
470 /** 470 /**
471 * Sets a delayed popup for a button. 471 * Sets a delayed popup for a button.
472 * 472 *
473 * Delayed popup is what you see in 473 * Delayed popup is what you see in
474 * Netscape Navigator's Previous and Next buttons: If you click them you 474 * Netscape Navigator's Previous and Next buttons: If you click them you
475 * go back 475 * go back
476 * or forth. If you press them long enough, you get a history-menu. 476 * or forth. If you press them long enough, you get a history-menu.
477 * This is exactly what we do here. 477 * This is exactly what we do here.
478 * 478 *
479 * You will insert normal a button with connection (or use signals from 479 * You will insert normal a button with connection (or use signals from
480 * toolbar): 480 * toolbar):
481 * <pre> 481 * <pre>
482 * bar->insertButton(icon, id, SIGNAL(clicked ()), this, 482 * bar->insertButton(icon, id, SIGNAL(clicked ()), this,
483 * SLOT (slotClick()), true, "click or wait for popup"); 483 * SLOT (slotClick()), true, "click or wait for popup");
484 * </pre> And then add a delayed popup: 484 * </pre> And then add a delayed popup:
485 * <pre> 485 * <pre>
486 * bar->setDelayedPopup (id, historyPopup); </pre> 486 * bar->setDelayedPopup (id, historyPopup); </pre>
487 * 487 *
488 * Don't add delayed popups to buttons which have normal popups. 488 * Don't add delayed popups to buttons which have normal popups.
489 * 489 *
490 * You may add popups which are derived from @ref QPopupMenu. You may 490 * You may add popups which are derived from @ref QPopupMenu. You may
491 * add popups that are already in the menu bar or are submenus of 491 * add popups that are already in the menu bar or are submenus of
492 * other popups. 492 * other popups.
493 */ 493 */
494 void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false); 494 void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false);
495 495
496 /** 496 /**
497 * Turns a button into an autorepeat button. 497 * Turns a button into an autorepeat button.
498 * 498 *
499 * Toggle buttons, buttons with menus, or 499 * Toggle buttons, buttons with menus, or
500 * buttons with delayed menus cannot be made into autorepeat buttons. 500 * buttons with delayed menus cannot be made into autorepeat buttons.
501 * Moreover, you can and will receive 501 * Moreover, you can and will receive
502 * only the signal clicked(), but not pressed() or released(). 502 * only the signal clicked(), but not pressed() or released().
503 * When the user presses this button, you will receive the signal clicked(), 503 * When the user presses this button, you will receive the signal clicked(),
504 * and if the button is still pressed after some time, 504 * and if the button is still pressed after some time,
505 * you will receive more clicked() signals separated by regular 505 * you will receive more clicked() signals separated by regular
506 * intervals. Since this uses @ref QButton::setAutoRepeat() , 506 * intervals. Since this uses @ref QButton::setAutoRepeat() ,
507 * I can't quantify 'some'. 507 * I can't quantify 'some'.
508 */ 508 */
509 void setAutoRepeat (int id, bool flag=true); 509 void setAutoRepeat (int id, bool flag=true);
510 510
511 511
512 /** 512 /**
513 * Turns button into a toggle button if @p flag is true. 513 * Turns button into a toggle button if @p flag is true.
514 */ 514 */
515 void setToggle (int id, bool flag = true); 515 void setToggle (int id, bool flag = true);
516 516
517 /** 517 /**
518 * Toggles a togglebutton. 518 * Toggles a togglebutton.
519 * 519 *
520 * If the button is a toggle button (see @ref setToggle()) 520 * If the button is a toggle button (see @ref setToggle())
521 * the button state will be toggled. This will also cause the toolbar to 521 * the button state will be toggled. This will also cause the toolbar to
522 * emit the signal @ref KButton::toggled() with parameter @p id. You must connect to 522 * emit the signal @ref KButton::toggled() with parameter @p id. You must connect to
523 * this signal, or use @ref addConnection() to connect directly to the 523 * this signal, or use @ref addConnection() to connect directly to the
524 * button signal @ref KButton::toggled(). 524 * button signal @ref KButton::toggled().
525 */ 525 */
526 void toggleButton (int id); 526 void toggleButton (int id);
527 527
528 /** 528 /**
529 * Sets a toggle button state. 529 * Sets a toggle button state.
530 * 530 *
531 * If the button is a toggle button (see @ref setToggle()) 531 * If the button is a toggle button (see @ref setToggle())
532 * this will set its state flag. This will also emit the signal 532 * this will set its state flag. This will also emit the signal
533 * @ref KButton::toggled(). 533 * @ref KButton::toggled().
534 * 534 *
535 * @see setToggle() 535 * @see setToggle()
536 */ 536 */
537 void setButton (int id, bool flag); 537 void setButton (int id, bool flag);
538 538
539 /** 539 /**
540 * @return @p true if button is on, @p false if button is off or if the 540 * @return @p true if button is on, @p false if button is off or if the
541 * button is not a toggle button. 541 * button is not a toggle button.
542 * @see setToggle() 542 * @see setToggle()
543 */ 543 */
544 bool isButtonOn (int id) const; 544 bool isButtonOn (int id) const;
545 545
546 /** 546 /**
547 * Sets the text of a line editor. 547 * Sets the text of a line editor.
548 * 548 *
549 * Cursor is set at end of text. 549 * Cursor is set at end of text.
550 */ 550 */
551 void setLinedText (int id, const QString& text); 551 void setLinedText (int id, const QString& text);
552 552
553 /** 553 /**
554 * Returns a line editor text. 554 * Returns a line editor text.
555 */ 555 */
556 QString getLinedText (int id) const; 556 QString getLinedText (int id) const;
557 557
558 /** 558 /**
559 * Inserts @p text in combobox @p id at position @p index. 559 * Inserts @p text in combobox @p id at position @p index.
560 */ 560 */
561 void insertComboItem (int id, const QString& text, int index); 561 void insertComboItem (int id, const QString& text, int index);
562 562
563 /** 563 /**
564 * Inserts @p list in combobox @p id at position @p index. 564 * Inserts @p list in combobox @p id at position @p index.
565 */ 565 */
566 void insertComboList (int id, const QStringList &list, int index); 566 void insertComboList (int id, const QStringList &list, int index);
567 567
568 /** 568 /**
569 * Removes item @p index from combobox @p id. 569 * Removes item @p index from combobox @p id.
570 */ 570 */
571 void removeComboItem (int id, int index); 571 void removeComboItem (int id, int index);
572 572
573 /** 573 /**
574 * Sets item @p index to be current item in combobox @p id. 574 * Sets item @p index to be current item in combobox @p id.
575 */ 575 */
576 void setCurrentComboItem (int id, int index); 576 void setCurrentComboItem (int id, int index);
577 577
578 /** 578 /**
579 * Changes item @p index in combobox @p id to text. 579 * Changes item @p index in combobox @p id to text.
580 * 580 *
581 * @p index = -1 refers current item (one displayed in the button). 581 * @p index = -1 refers current item (one displayed in the button).
582 */ 582 */
583 void changeComboItem (int id, const QString& text, int index=-1); 583 void changeComboItem (int id, const QString& text, int index=-1);
584 584
585 /** 585 /**
586 * Clears the combobox @p id. 586 * Clears the combobox @p id.
587 * 587 *
588 * Does not delete it or hide it. 588 * Does not delete it or hide it.
589 */ 589 */
590 void clearCombo (int id); 590 void clearCombo (int id);
591 591
592 /** 592 /**
593 * Returns text of item @p index from combobox @p id. 593 * Returns text of item @p index from combobox @p id.
594 * 594 *
595 * @p index = -1 refers to current item. 595 * @p index = -1 refers to current item.
596 */ 596 */
597 597
598 QString getComboItem (int id, int index=-1) const; 598 QString getComboItem (int id, int index=-1) const;
599 599
600 /** 600 /**
601 * Returns a pointer to the combobox. 601 * Returns a pointer to the combobox.
602 * 602 *
603 * Example: 603 * Example:
604 * <pre> 604 * <pre>
605 * KComboBox *combo = toolbar->getCombo(combo_id); 605 * KComboBox *combo = toolbar->getCombo(combo_id);
606 * </pre> 606 * </pre>
607 * That way you can get access to other public methods 607 * That way you can get access to other public methods
608 * that @ref KComboBox provides. 608 * that @ref KComboBox provides.
609 */ 609 */
610 KComboBox * getCombo(int id); 610 KComboBox * getCombo(int id);
611 611
612 /** 612 /**
613 * Returns a pointer to KToolBarLined. 613 * Returns a pointer to KToolBarLined.
614 * 614 *
615 * Example: 615 * Example:
616 * <pre> 616 * <pre>
617 * KLineEdit * lined = toolbar->getKToolBarLined(lined_id); 617 * KLineEdit * lined = toolbar->getKToolBarLined(lined_id);
618 * </pre> 618 * </pre>
619 * That way you can get access to other public methods 619 * That way you can get access to other public methods
620 * that @ref KLineEdit provides. @ref KLineEdit is the same thing 620 * that @ref KLineEdit provides. @ref KLineEdit is the same thing
621 * as @ref QLineEdit plus completion signals. 621 * as @ref QLineEdit plus completion signals.
622 */ 622 */
623 KLineEdit * getLined (int id); 623 KLineEdit * getLined (int id);
624 624
625 /** 625 /**
626 * Returns a pointer to KToolBarButton. 626 * Returns a pointer to KToolBarButton.
627 * 627 *
628 * Example: 628 * Example:
629 * <pre> 629 * <pre>
630 * KToolBarButton * button = toolbar->getButton(button_id); 630 * KToolBarButton * button = toolbar->getButton(button_id);
631 * </pre> 631 * </pre>
632 * That way you can get access to other public methods 632 * That way you can get access to other public methods
633 * that @ref KToolBarButton provides. 633 * that @ref KToolBarButton provides.
634 * 634 *
635 * Using this method is not recommended. 635 * Using this method is not recommended.
636 */ 636 */
637 KToolBarButton * getButton (int id); 637 KToolBarButton * getButton (int id);
638 638
639 /** 639 /**
640 * Align item to the right. 640 * Align item to the right.
641 * 641 *
642 * This works only if toolbar is set to full width. 642 * This works only if toolbar is set to full width.
643 * @see setFullWidth() 643 * @see setFullWidth()
644 */ 644 */
645 void alignItemRight (int id, bool right = true); 645 void alignItemRight (int id, bool right = true);
646 646
647 /** 647 /**
648 * Returns a pointer to an inserted widget. 648 * Returns a pointer to an inserted widget.
649 * 649 *
650 * Wrong ids are not tested. 650 * Wrong ids are not tested.
651 * You can do with this whatever you want, 651 * You can do with this whatever you want,
652 * except change its height (hardcoded). If you change its width 652 * except change its height (hardcoded). If you change its width
653 * you will probably have to call QToolBar::updateRects(true) 653 * you will probably have to call QToolBar::updateRects(true)
654 * @see QWidget 654 * @see QWidget
655 * @see updateRects() 655 * @see updateRects()
656 * 656 *
657 * KDE4: make this const! 657 * KDE4: make this const!
658 */ 658 */
659 QWidget *getWidget (int id); 659 QWidget *getWidget (int id);
660 660
661 /** 661 /**
662 * Set item autosized. 662 * Set item autosized.
663 * 663 *
664 * This works only if the toolbar is set to full width. 664 * This works only if the toolbar is set to full width.
665 * Only @p one item can be autosized, and it has to be 665 * Only @p one item can be autosized, and it has to be
666 * the last left-aligned item. Items that come after this must be right 666 * the last left-aligned item. Items that come after this must be right
667 * aligned. Items that can be right aligned are Lineds, Frames, Widgets and 667 * aligned. Items that can be right aligned are Lineds, Frames, Widgets and
668 * Combos. An autosized item will resize itself whenever the toolbar geometry 668 * Combos. An autosized item will resize itself whenever the toolbar geometry
669 * changes to the last right-aligned item (or to end of toolbar if there 669 * changes to the last right-aligned item (or to end of toolbar if there
670 * are no right-aligned items.) 670 * are no right-aligned items.)
671 * @see setFullWidth() 671 * @see setFullWidth()
672 * @see alignItemRight() 672 * @see alignItemRight()
673 */ 673 */
674 void setItemAutoSized (int id, bool yes = true); 674 void setItemAutoSized (int id, bool yes = true);
675 675
676 /** 676 /**
677 * Remove all items. 677 * Remove all items.
678 * 678 *
679 * The toolbar is redrawn after it. 679 * The toolbar is redrawn after it.
680 */ 680 */
681 void clear (); 681 void clear ();
682 682
683 /** 683 /**
684 * Remove item @p id. 684 * Remove item @p id.
685 * 685 *
686 * Item is deleted. Toolbar is redrawn after it. 686 * Item is deleted. Toolbar is redrawn after it.
687 */ 687 */
688 void removeItem (int id); 688 void removeItem (int id);
689 689
690 /** 690 /**
691 * Remove item @p id. 691 * Remove item @p id.
692 * 692 *
693 * Item is deleted when toolbar is redrawn. 693 * Item is deleted when toolbar is redrawn.
694 */ 694 */
695 void removeItemDelayed (int id); 695 void removeItemDelayed (int id);
696 696
697 /** 697 /**
698 * Hide item. 698 * Hide item.
699 */ 699 */
700 void hideItem (int id); 700 void hideItem (int id);
701 701
702 /** 702 /**
703 * Show item. 703 * Show item.
704 */ 704 */
705 void showItem (int id); 705 void showItem (int id);
706 706
707 /** 707 /**
708 * Returns the index of the given item. 708 * Returns the index of the given item.
709 * 709 *
710 * KDE4: make this const! 710 * KDE4: make this const!
711 */ 711 */
712 int itemIndex (int id); 712 int itemIndex (int id);
713 713
714 /** 714 /**
715 * Set toolbar to full parent size (default). 715 * Set toolbar to full parent size (default).
716 * 716 *
717 * In full size mode the bar 717 * In full size mode the bar
718 * extends over the parent's full width or height. If the mode is disabled 718 * extends over the parent's full width or height. If the mode is disabled
719 * the toolbar tries to take as much space as it needs without wrapping, but 719 * the toolbar tries to take as much space as it needs without wrapping, but
720 * it does not exceed the parent box. You can force a certain width or 720 * it does not exceed the parent box. You can force a certain width or
721 * height with @ref setMaxWidth() or @ref setMaxHeight(). 721 * height with @ref setMaxWidth() or @ref setMaxHeight().
722 * 722 *
723 * If you want to use right-aligned items or auto-sized items you must use 723 * If you want to use right-aligned items or auto-sized items you must use
724 * full size mode. 724 * full size mode.
725 */ 725 */
726 void setFullSize(bool flag = true); 726 void setFullSize(bool flag = true);
727 727
728 /** 728 /**
729 * @return @p true if the full-size mode is enabled. Otherwise 729 * @return @p true if the full-size mode is enabled. Otherwise
730 * it returns @false. 730 * it returns @false.
731 */ 731 */
732 bool fullSize() const; 732 bool fullSize() const;
733 733
734 /** 734 /**
735 * @deprecated use setMovingEnabled(bool) instead. 735 * @deprecated use setMovingEnabled(bool) instead.
736 * Enable or disable moving of toolbar. 736 * Enable or disable moving of toolbar.
737 */ 737 */
738 void enableMoving(bool flag = true); 738 void enableMoving(bool flag = true);
739 739
740 /** 740 /**
741 * Set position of toolbar. 741 * Set position of toolbar.
742 * @see BarPosition() 742 * @see BarPosition()
743 */ 743 */
744 void setBarPos (BarPosition bpos); 744 void setBarPos (BarPosition bpos);
745 745
746 /** 746 /**
747 * Returns position of toolbar. 747 * Returns position of toolbar.
748 */ 748 */
749 BarPosition barPos() const; 749 const BarPosition barPos();
750 750
751 /** 751 /**
752 * @deprecated 752 * @deprecated
753 * Show, hide, or toggle toolbar. 753 * Show, hide, or toggle toolbar.
754 * 754 *
755 * This method is provided for compatibility only, 755 * This method is provided for compatibility only,
756 * please use show() and/or hide() instead. 756 * please use show() and/or hide() instead.
757 * @see BarStatus 757 * @see BarStatus
758 */ 758 */
759 bool enable(BarStatus stat); 759 bool enable(BarStatus stat);
760 760
761 /** 761 /**
762 * @deprecated 762 * @deprecated
763 * Use setMaximumHeight() instead. 763 * Use setMaximumHeight() instead.
764 */ 764 */
765 void setMaxHeight (int h); // Set max height for vertical toolbars 765 void setMaxHeight (int h); // Set max height for vertical toolbars
766 766
767 /** 767 /**
768 * @deprecated 768 * @deprecated
769 * Use maximumHeight() instead. 769 * Use maximumHeight() instead.
770 * Returns the value that was set with @ref setMaxHeight(). 770 * Returns the value that was set with @ref setMaxHeight().
771 */ 771 */
772 int maxHeight(); 772 int maxHeight();
773 773
774 /** 774 /**
775 * @deprecated 775 * @deprecated
776 * Use setMaximumWidth() instead. 776 * Use setMaximumWidth() instead.
777 * Set maximal width of horizontal (top or bottom) toolbar. 777 * Set maximal width of horizontal (top or bottom) toolbar.
778 */ 778 */
779 void setMaxWidth (int dw); 779 void setMaxWidth (int dw);
780 780
781 /** 781 /**
782 * @deprecated 782 * @deprecated
783 * Use maximumWidth() instead. 783 * Use maximumWidth() instead.
784 * Returns the value that was set with @ref setMaxWidth(). 784 * Returns the value that was set with @ref setMaxWidth().
785 */ 785 */
786 int maxWidth(); 786 int maxWidth();
787 787
788 /** 788 /**
789 * Set title for toolbar when it floats. 789 * Set title for toolbar when it floats.
790 * 790 *
791 * Titles are however not (yet) 791 * Titles are however not (yet)
792 * visible. You can't change toolbar's title while it's floating. 792 * visible. You can't change toolbar's title while it's floating.
793 */ 793 */
794 void setTitle (const QString& _title); 794 void setTitle (const QString& _title);
795 795
796 /** 796 /**
797 * @deprecated 797 * @deprecated
798 * Use enableMoving() instead. 798 * Use enableMoving() instead.
799 */ 799 */
800 void enableFloating (bool arrrrrrgh); 800 void enableFloating (bool arrrrrrgh);
801 801
802 /** 802 /**
803 * Set the kind of painting for buttons. 803 * Set the kind of painting for buttons.
804 * 804 *
805 * Choose from: 805 * Choose from:
806 * @li IconOnly (only icons), 806 * @li IconOnly (only icons),
807 * @li IconTextRight (icon and text, text is left from icons), 807 * @li IconTextRight (icon and text, text is left from icons),
808 * @li TextOnly (only text), 808 * @li TextOnly (only text),
809 * @li IconTextBottom (icons and text, text is under icons). 809 * @li IconTextBottom (icons and text, text is under icons).
810 * @see IconText 810 * @see IconText
811 * 811 *
812 */ 812 */
813 void setIconText(IconText it); 813 void setIconText(IconText it);
814 // Note: don't merge with the next one, it breaks Qt properties 814 // Note: don't merge with the next one, it breaks Qt properties
815 815
816 /** 816 /**
817 * Similar to @ref setIconText(IconText it) but allows you to 817 * Similar to @ref setIconText(IconText it) but allows you to
818 * disable or enable updating. If @p update is false, then the 818 * disable or enable updating. If @p update is false, then the
819 * buttons will not be updated. This is useful only if you know 819 * buttons will not be updated. This is useful only if you know
820 * that you will be forcing an update later. 820 * that you will be forcing an update later.
821 */ 821 */
822 void setIconText(IconText it, bool update); 822 void setIconText(IconText it, bool update);
823 823
824 /** 824 /**
825 * @return The current text style for buttons. 825 * @return The current text style for buttons.
826 */ 826 */
827 IconText iconText() const; 827 IconText iconText() const;
828 828
829 /** 829 /**
830 * Set the icon size to load. Usually you should not call 830 * Set the icon size to load. Usually you should not call
831 * this, the icon size is taken care of by KIconLoader 831 * this, the icon size is taken care of by KIconLoader
832 * and globally configured. 832 * and globally configured.
833 * By default, the toolbar will load icons of size 32 for main 833 * By default, the toolbar will load icons of size 32 for main
834 * toolbars and 22 for other toolbars 834 * toolbars and 22 for other toolbars
835 * @see KIconLoader. 835 * @see KIconLoader.
836 * 836 *
837 * @param size The size to use 837 * @param size The size to use
838 */ 838 */
839 void setIconSize(int size); 839 void setIconSize(int size);
840 // Note: don't merge with the next one, it breaks Qt properties 840 // Note: don't merge with the next one, it breaks Qt properties
841 841
842 /** 842 /**
843 * Same as @ref setIconText(int size) but allows you 843 * Same as @ref setIconText(int size) but allows you
844 * to disable the toolbar update. 844 * to disable the toolbar update.
845 * 845 *
846 * @param size The size to use 846 * @param size The size to use
847 * @param update If true, then the toolbar will be updated after 847 * @param update If true, then the toolbar will be updated after
848 * this 848 * this
849 */ 849 */
850 void setIconSize(int size, bool update); 850 void setIconSize(int size, bool update);
851 851
852 /** 852 /**
853 * @return The current icon size for buttons. 853 * @return The current icon size for buttons.
854 */ 854 */
855 int iconSize() const; 855 int iconSize() const;
856 856
857 /** 857 /**
858 * This allows you to enable or disable the context menu. 858 * This allows you to enable or disable the context menu.
859 * 859 *
860 * @param enable If false, then the context menu will be disabled 860 * @param enable If false, then the context menu will be disabled
861 */ 861 */
862 void setEnableContextMenu(bool enable = true); 862 void setEnableContextMenu(bool enable = true);
863 863
864 /** 864 /**
865 * Returns whether or not the context menu is disabled 865 * Returns whether or not the context menu is disabled
866 * 866 *
867 * @return The context menu state 867 * @return The context menu state
868 */ 868 */
869 bool contextMenuEnabled() const; 869 bool contextMenuEnabled() const;
870 870
871 /** 871 /**
872 * This will inform a toolbar button to ignore certain style 872 * This will inform a toolbar button to ignore certain style
873 * changes. Specifically, it will ignore IconText (always IconOnly) 873 * changes. Specifically, it will ignore IconText (always IconOnly)
874 * and will not allow image effects to apply. 874 * and will not allow image effects to apply.
875 * 875 *
876 * @param id The button to exclude from styles 876 * @param id The button to exclude from styles
877 * @param no_style If true, then it is excluded (default: true). 877 * @param no_style If true, then it is excluded (default: true).
878 */ 878 */
879 void setItemNoStyle(int id, bool no_style = true); 879 void setItemNoStyle(int id, bool no_style = true);
880 880
881 void setFlat (bool flag); 881 void setFlat (bool flag);
882 882
883 /** 883 /**
884 * @return the number of items in the toolbar 884 * @return the number of items in the toolbar
885 */ 885 */
886 int count() const; 886 int count() const;
887 887
888 /** 888 /**
889 * Instruct the toolbar to save it's current state to either the app 889 * Instruct the toolbar to save it's current state to either the app
890 * config file or to the XML-GUI resource file (whichever has 890 * config file or to the XML-GUI resource file (whichever has
891 * precedence). 891 * precedence).
892 */ 892 */
893 void saveState(); 893 void saveState();
894 894
895 /** 895 /**
896 * Save the toolbar settings to group @p configGroup in @p config. 896 * Save the toolbar settings to group @p configGroup in @p config.
897 */ 897 */
898 void saveSettings(KConfig *config, const QString &configGroup); 898 void saveSettings(KConfig *config, const QString &configGroup);
899 899
900 /** 900 /**
901 * Read the toolbar settings from group @p configGroup in @p config 901 * Read the toolbar settings from group @p configGroup in @p config
902 * and apply them. 902 * and apply them.
903 */ 903 */
904 void applySettings(KConfig *config, const QString &configGroup); 904 void applySettings(KConfig *config, const QString &configGroup);
905 905
906 /** 906 /**
907 * Tell the toolbar what XML-GUI resource file it should use to save 907 * Tell the toolbar what XML-GUI resource file it should use to save
908 * it's state. The state of the toolbar (position, size, etc) is 908 * it's state. The state of the toolbar (position, size, etc) is
909 * saved in KConfig files if the application does not use XML-GUI.. 909 * saved in KConfig files if the application does not use XML-GUI..
910 * but if the app does, then it's saved the XML file. This function 910 * but if the app does, then it's saved the XML file. This function
911 * allows this to happen. 911 * allows this to happen.
912 * 912 *
913 * @param xmlfile The XML-GUI resource file to write to 913 * @param xmlfile The XML-GUI resource file to write to
914 * @param xml The DOM document for the XML-GUI building 914 * @param xml The DOM document for the XML-GUI building
915 */ 915 */
916 // void setXML(const QString& xmlfile, const QDomDocument& xml); 916 // void setXML(const QString& xmlfile, const QDomDocument& xml);
917 /* @internal */ 917 /* @internal */
918 void setXMLGUIClient( KXMLGUIClient *client ); 918 void setXMLGUIClient( KXMLGUIClient *client );
919 919
920 /** 920 /**
921 * Assign a (translated) text to this toolbar. This is used 921 * Assign a (translated) text to this toolbar. This is used
922 * for the tooltip on the handle, and when listing the toolbars. 922 * for the tooltip on the handle, and when listing the toolbars.
923 */ 923 */
924 void setText( const QString & txt ); 924 void setText( const QString & txt );
925 925
926 /** 926 /**
927 * @return the toolbar's text. 927 * @return the toolbar's text.
928 */ 928 */
929 QString text() const; 929 QString text() const;
930 930
931 void setStretchableWidget( QWidget *w ); 931 void setStretchableWidget( QWidget *w );
932 QSizePolicy sizePolicy() const; 932 QSizePolicy sizePolicy() const;
933 bool highlight() const; 933 bool highlight() const;
934 QSize sizeHint() const; 934 QSize sizeHint() const;
935 QSize minimumSizeHint() const; 935 QSize minimumSizeHint() const;
936 QSize minimumSize() const; 936 QSize minimumSize() const;
937 937
938 void hide(); 938 void hide();
939 void show(); 939 void show();
940 940
941 void updateRects( bool = FALSE ) {} 941 void updateRects( bool = FALSE ) {}
942 942
943//US void loadState( const QDomElement &e ); 943//US void loadState( const QDomElement &e );
944//US void saveState( QDomElement &e ); 944//US void saveState( QDomElement &e );
945 945
946 /** 946 /**
947 * @internal 947 * @internal
948 */ 948 */
949 void positionYourself( bool force = false); 949 void positionYourself( bool force = false);
950 950
951signals: 951signals:
952 /** 952 /**
953 * Emitted when button @p id is clicked. 953 * Emitted when button @p id is clicked.
954 */ 954 */
955 void clicked(int id); 955 void clicked(int id);
956 956
957 /** 957 /**
958 * Emitted when button @p id is double-clicked. 958 * Emitted when button @p id is double-clicked.
959 * 959 *
960 * Note: you will always 960 * Note: you will always
961 * recive two @ref clicked() , @ref pressed() and @ref released() signals. 961 * recive two @ref clicked() , @ref pressed() and @ref released() signals.
962 * There is no way to avoid it - at least no easy way. 962 * There is no way to avoid it - at least no easy way.
963 * If you need to resolve this all you can do is set up timers 963 * If you need to resolve this all you can do is set up timers
964 * which wait for @ref QApplication::doubleClickInterval() to expire. 964 * which wait for @ref QApplication::doubleClickInterval() to expire.
965 * If in that time you don't get this signal, you may belive that 965 * If in that time you don't get this signal, you may belive that
966 * button was only clicked and not double-clicked. 966 * button was only clicked and not double-clicked.
967 * And please note that butons with popup menus do not emit this signal, 967 * And please note that butons with popup menus do not emit this signal,
968 * but those with delayed popup do. 968 * but those with delayed popup do.
969 */ 969 */
970 void doubleClicked (int id); 970 void doubleClicked (int id);
971 971
972 /** 972 /**
973 * Emitted when button @p id is pressed. 973 * Emitted when button @p id is pressed.
974 */ 974 */
975 void pressed(int); 975 void pressed(int);
976 976
977 /** 977 /**
978 * Emits when button @p id is released. 978 * Emits when button @p id is released.
979 */ 979 */
980 void released(int); 980 void released(int);
981 981
982 /** 982 /**
983 * Emitted when a toggle button changes state. 983 * Emitted when a toggle button changes state.
984 * 984 *
985 * Emitted also if you change state 985 * Emitted also if you change state
986 * with @ref setButton() or @ref toggleButton() 986 * with @ref setButton() or @ref toggleButton()
987 * If you make a button normal again, with 987 * If you make a button normal again, with
988 * setToggle(false), this signal won't 988 * setToggle(false), this signal won't
989 * be emitted. 989 * be emitted.
990 */ 990 */
991 void toggled(int); 991 void toggled(int);
992 992
993 /** 993 /**
994 * This signal is emitted when item id gets highlighted/unhighlighted 994 * This signal is emitted when item id gets highlighted/unhighlighted
995 * (i.e when mouse enters/exits). 995 * (i.e when mouse enters/exits).
996 * 996 *
997 * Note that this signal is emitted from 997 * Note that this signal is emitted from
998 * all buttons (normal, disabled and toggle) even when there is no visible 998 * all buttons (normal, disabled and toggle) even when there is no visible
999 * change in buttons (i.e., buttons do not raise when mouse enters). 999 * change in buttons (i.e., buttons do not raise when mouse enters).
1000 * The parameter @p isHighlighted is @p true when mouse enters and @p false when 1000 * The parameter @p isHighlighted is @p true when mouse enters and @p false when
1001 * mouse exits. 1001 * mouse exits.
1002 */ 1002 */
1003 void highlighted(int id, bool isHighlighted); 1003 void highlighted(int id, bool isHighlighted);
1004 1004
1005 /** 1005 /**
1006 * This signal is emitted when item id gets highlighted/unhighlighted 1006 * This signal is emitted when item id gets highlighted/unhighlighted
1007 * (i.e when mouse enters/exits). 1007 * (i.e when mouse enters/exits).
1008 * 1008 *
1009 * Note that this signal is emitted from 1009 * Note that this signal is emitted from
1010 * all buttons (normal, disabled and toggle) even when there is no visible 1010 * all buttons (normal, disabled and toggle) even when there is no visible
1011 * change in buttons (i.e., buttons do not raise when mouse enters). 1011 * change in buttons (i.e., buttons do not raise when mouse enters).
1012 */ 1012 */
1013 void highlighted(int id ); 1013 void highlighted(int id );
1014 1014
1015 /** 1015 /**
1016 * Emitted when toolbar changes position, or when 1016 * Emitted when toolbar changes position, or when
1017 * an item is removed from toolbar. 1017 * an item is removed from toolbar.
1018 * 1018 *
1019 * If you subclass @ref KMainWindow and reimplement 1019 * If you subclass @ref KMainWindow and reimplement
1020 * @ref KMainWindow::resizeEvent() be sure to connect to 1020 * @ref KMainWindow::resizeEvent() be sure to connect to
1021 * this signal. Note: You can connect this signal to a slot that 1021 * this signal. Note: You can connect this signal to a slot that
1022 * doesn't take parameter. 1022 * doesn't take parameter.
1023 */ 1023 */
1024 void moved( BarPosition ); 1024 void moved( BarPosition );
1025 1025
1026 /** 1026 /**
1027 * @internal 1027 * @internal
1028 * This signal is emitted when toolbar detects changing of 1028 * This signal is emitted when toolbar detects changing of
1029 * following parameters: 1029 * following parameters:
1030 * highlighting, button-size, button-mode. This signal is 1030 * highlighting, button-size, button-mode. This signal is
1031 * internal, aimed to buttons. 1031 * internal, aimed to buttons.
1032 */ 1032 */
1033 void modechange (); 1033 void modechange ();
1034 1034
1035 /** 1035 /**
1036 * This signal is emitted when the toolbar is getting deleted, 1036 * This signal is emitted when the toolbar is getting deleted,
1037 * and before ~KToolbar finishes (so it's still time to remove 1037 * and before ~KToolbar finishes (so it's still time to remove
1038 * widgets from the toolbar). 1038 * widgets from the toolbar).
1039 * Used by KWidgetAction. 1039 * Used by KWidgetAction.
1040 * @since 3.2 1040 * @since 3.2
1041 */ 1041 */
1042 void toolbarDestroyed(); 1042 void toolbarDestroyed();
1043 1043
1044public: 1044public:
1045 /** 1045 /**
1046 * @return global setting for "Highlight buttons under mouse" 1046 * @return global setting for "Highlight buttons under mouse"
1047 */ 1047 */
1048 void repaintMe(); 1048 void repaintMe();
1049 static bool highlightSetting(); 1049 static bool highlightSetting();
1050 1050
1051 /** 1051 /**
1052 * @return global setting for "Toolbars transparent when moving" 1052 * @return global setting for "Toolbars transparent when moving"
1053 */ 1053 */
1054 static bool transparentSetting(); 1054 static bool transparentSetting();
1055 1055
1056 /** 1056 /**
1057 * @return global setting for "Icon Text" 1057 * @return global setting for "Icon Text"
1058 */ 1058 */
1059 static IconText iconTextSetting(); 1059 static IconText iconTextSetting();
1060 1060
1061public slots: 1061public slots:
1062 virtual void setIconText( const QString &txt ) 1062 virtual void setIconText( const QString &txt )
1063 { QToolBar::setIconText( txt ); } 1063 { QToolBar::setIconText( txt ); }
1064 void slotRepaint(); 1064 void slotRepaint();
1065 1065
1066protected: 1066protected:
1067 void mousePressEvent( QMouseEvent * ); 1067 void mousePressEvent( QMouseEvent * );
1068 void childEvent( QChildEvent *e ); 1068 void childEvent( QChildEvent *e );
1069 void showEvent( QShowEvent *e ); 1069 void showEvent( QShowEvent *e );
1070 void resizeEvent( QResizeEvent *e ); 1070 void resizeEvent( QResizeEvent *e );
1071 bool event( QEvent *e ); 1071 bool event( QEvent *e );
1072 void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false); 1072 void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false);
1073 QString settingsGroup(); 1073 QString settingsGroup();
1074 1074
1075private slots: 1075private slots:
1076 void rebuildLayout(); 1076 void rebuildLayout();
1077 void slotReadConfig (); 1077 void slotReadConfig ();
1078 void slotAppearanceChanged(); 1078 void slotAppearanceChanged();
1079 void slotIconChanged(int); 1079 void slotIconChanged(int);
1080 void toolBarPosChanged( QToolBar *tb ); 1080 void toolBarPosChanged( QToolBar *tb );
1081 void slotContextAboutToShow(); 1081 void slotContextAboutToShow();
1082 void widgetDestroyed(); 1082 void widgetDestroyed();
1083 1083
1084private: 1084private:
1085 void init( bool readConfig = true, bool honorStyle = false ); 1085 void init( bool readConfig = true, bool honorStyle = false );
1086 void doConnections( KToolBarButton *button ); 1086 void doConnections( KToolBarButton *button );
1087 void insertWidgetInternal( QWidget *w, int &index, int id ); 1087 void insertWidgetInternal( QWidget *w, int &index, int id );
1088 void removeWidgetInternal( QWidget *w ); 1088 void removeWidgetInternal( QWidget *w );
1089 void getAttributes( QString &position, QString &icontext, int &index ); 1089 void getAttributes( QString &position, QString &icontext, int &index );
1090//US KPopupMenu *contextMenu(); 1090//US KPopupMenu *contextMenu();
1091 QPopupMenu *contextMenu(); 1091 QPopupMenu *contextMenu();
1092 1092
1093 QMap<QWidget*, int > widget2id; 1093 QMap<QWidget*, int > widget2id;
1094 typedef QMap<int, QWidget* > Id2WidgetMap; 1094 typedef QMap<int, QWidget* > Id2WidgetMap;
1095 Id2WidgetMap id2widget; 1095 Id2WidgetMap id2widget;
1096//US KPopupMenu *context; 1096//US KPopupMenu *context;
1097 QPopupMenu *context; 1097 QPopupMenu *context;
1098 QPtrList<QWidget> widgets; 1098 QPtrList<QWidget> widgets;
1099 QTimer *layoutTimer; 1099 QTimer *layoutTimer;
1100 QGuardedPtr<QWidget> stretchableWidget, rightAligned; 1100 QGuardedPtr<QWidget> stretchableWidget, rightAligned;
1101protected: 1101protected:
1102 virtual void virtual_hook( int id, void* data ); 1102 virtual void virtual_hook( int id, void* data );
1103private: 1103private:
1104 KToolBarPrivate *d; 1104 KToolBarPrivate *d;
1105 bool inshutdownprocess; 1105 bool inshutdownprocess;
1106}; 1106};
1107 1107
1108#endif 1108#endif