summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-07-07 22:22:20 (UTC)
committer zautrix <zautrix>2005-07-07 22:22:20 (UTC)
commit876816e6582299d527610e847d259d2be6de403c (patch) (unidiff)
tree6683baf2835672d0d9b28b3cbbf90e84c398b835 /korganizer
parent3fe323e4e63f3b7c1cf8c96093fa14fd63fb4efc (diff)
downloadkdepimpi-876816e6582299d527610e847d259d2be6de403c.zip
kdepimpi-876816e6582299d527610e847d259d2be6de403c.tar.gz
kdepimpi-876816e6582299d527610e847d259d2be6de403c.tar.bz2
fixxx
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp64
-rw-r--r--korganizer/koagenda.cpp4
-rw-r--r--korganizer/koagenda.h1
-rw-r--r--korganizer/komonthview.cpp5
4 files changed, 15 insertions, 59 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 426e8f9..2582931 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1,1547 +1,1495 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Requires the Qt and KDE widget libraries, available at no cost at 4 Requires the Qt and KDE widget libraries, available at no cost at
5 http://www.troll.no and http://www.kde.org respectively 5 http://www.troll.no and http://www.kde.org respectively
6 6
7 Copyright (c) 1997, 1998, 1999 7 Copyright (c) 1997, 1998, 1999
8 Preston Brown (preton.brown@yale.edu) 8 Preston Brown (preton.brown@yale.edu)
9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 9 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
10 Ian Dawes (iadawes@globalserve.net) 10 Ian Dawes (iadawes@globalserve.net)
11 Laszlo Boloni (boloni@cs.purdue.edu) 11 Laszlo Boloni (boloni@cs.purdue.edu)
12 12
13 Copyright (c) 2000, 2001, 2002 13 Copyright (c) 2000, 2001, 2002
14 Cornelius Schumacher <schumacher@kde.org> 14 Cornelius Schumacher <schumacher@kde.org>
15 15
16 This program is free software; you can redistribute it and/or modify 16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by 17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or 18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version. 19 (at your option) any later version.
20 20
21 This program is distributed in the hope that it will be useful, 21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
24 GNU General Public License for more details. 24 GNU General Public License for more details.
25 25
26 You should have received a copy of the GNU General Public License 26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software 27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include <stdlib.h> 31#include <stdlib.h>
32 32
33#include <qapplication.h> 33#include <qapplication.h>
34#include <qradiobutton.h> 34#include <qradiobutton.h>
35#include <qbuttongroup.h> 35#include <qbuttongroup.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qclipboard.h> 37#include <qclipboard.h>
38#include <qcursor.h> 38#include <qcursor.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40#include <qprogressbar.h> 40#include <qprogressbar.h>
41#include <qmultilineedit.h> 41#include <qmultilineedit.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qwidgetstack.h> 43#include <qwidgetstack.h>
44#include <qptrlist.h> 44#include <qptrlist.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qgroupbox.h> 46#include <qgroupbox.h>
47#include <qfile.h> 47#include <qfile.h>
48#include <qdir.h> 48#include <qdir.h>
49#ifndef KORG_NOSPLITTER 49#ifndef KORG_NOSPLITTER
50#include <qsplitter.h> 50#include <qsplitter.h>
51#endif 51#endif
52 52
53#include <kglobal.h> 53#include <kglobal.h>
54#include <kdebug.h> 54#include <kdebug.h>
55#include <kstandarddirs.h> 55#include <kstandarddirs.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57#include <kmessagebox.h> 57#include <kmessagebox.h>
58#include <knotifyclient.h> 58#include <knotifyclient.h>
59#include <kconfig.h> 59#include <kconfig.h>
60 60
61#include <libkdepim/ksyncprefsdialog.h> 61#include <libkdepim/ksyncprefsdialog.h>
62#include <krun.h> 62#include <krun.h>
63#include <kdirwatch.h> 63#include <kdirwatch.h>
64#include <libkdepim/kdatepicker.h> 64#include <libkdepim/kdatepicker.h>
65#include <libkdepim/ksyncprofile.h> 65#include <libkdepim/ksyncprofile.h>
66#include <libkdepim/kpimglobalprefs.h> 66#include <libkdepim/kpimglobalprefs.h>
67 67
68#include <libkcal/vcaldrag.h> 68#include <libkcal/vcaldrag.h>
69#include <libkcal/icaldrag.h> 69#include <libkcal/icaldrag.h>
70#include <libkcal/icalformat.h> 70#include <libkcal/icalformat.h>
71#include <libkcal/vcalformat.h> 71#include <libkcal/vcalformat.h>
72#include <libkcal/scheduler.h> 72#include <libkcal/scheduler.h>
73#include <libkcal/calendarlocal.h> 73#include <libkcal/calendarlocal.h>
74#include <libkcal/journal.h> 74#include <libkcal/journal.h>
75#include <libkcal/calfilter.h> 75#include <libkcal/calfilter.h>
76#include <libkcal/attendee.h> 76#include <libkcal/attendee.h>
77#include <libkcal/dndfactory.h> 77#include <libkcal/dndfactory.h>
78#include <libkcal/freebusy.h> 78#include <libkcal/freebusy.h>
79#include <libkcal/filestorage.h> 79#include <libkcal/filestorage.h>
80#include <libkcal/calendarresources.h> 80#include <libkcal/calendarresources.h>
81#include <libkcal/qtopiaformat.h> 81#include <libkcal/qtopiaformat.h>
82#include "../kalarmd/alarmdialog.h" 82#include "../kalarmd/alarmdialog.h"
83 83
84#ifndef DESKTOP_VERSION 84#ifndef DESKTOP_VERSION
85#include <libkcal/sharpformat.h> 85#include <libkcal/sharpformat.h>
86#include <externalapphandler.h> 86#include <externalapphandler.h>
87#endif 87#endif
88#include <libkcal/phoneformat.h> 88#include <libkcal/phoneformat.h>
89#ifndef KORG_NOMAIL 89#ifndef KORG_NOMAIL
90#include "komailclient.h" 90#include "komailclient.h"
91#endif 91#endif
92#ifndef KORG_NOPRINTER 92#ifndef KORG_NOPRINTER
93#include "calprinter.h" 93#include "calprinter.h"
94#endif 94#endif
95#ifndef KORG_NOPLUGINS 95#ifndef KORG_NOPLUGINS
96#include "kocore.h" 96#include "kocore.h"
97#endif 97#endif
98#include "koeventeditor.h" 98#include "koeventeditor.h"
99#include "kotodoeditor.h" 99#include "kotodoeditor.h"
100#include "koprefs.h" 100#include "koprefs.h"
101#include "koeventviewerdialog.h" 101#include "koeventviewerdialog.h"
102#include "publishdialog.h" 102#include "publishdialog.h"
103#include "kofilterview.h" 103#include "kofilterview.h"
104#include "koglobals.h" 104#include "koglobals.h"
105#include "koviewmanager.h" 105#include "koviewmanager.h"
106#include "koagendaview.h" 106#include "koagendaview.h"
107#include "koagenda.h"
107#include "kodialogmanager.h" 108#include "kodialogmanager.h"
108#include "outgoingdialog.h" 109#include "outgoingdialog.h"
109#include "incomingdialog.h" 110#include "incomingdialog.h"
110#include "datenavigatorcontainer.h" 111#include "datenavigatorcontainer.h"
111#include "statusdialog.h" 112#include "statusdialog.h"
112#include "kdatenavigator.h" 113#include "kdatenavigator.h"
113#include "kotodoview.h" 114#include "kotodoview.h"
114#include "datenavigator.h" 115#include "datenavigator.h"
115#include "resourceview.h" 116#include "resourceview.h"
116#include "navigatorbar.h" 117#include "navigatorbar.h"
117#include "searchdialog.h" 118#include "searchdialog.h"
118#include "mainwindow.h" 119#include "mainwindow.h"
119#include "categoryeditdialog.h" 120#include "categoryeditdialog.h"
120 121
121#include "calendarview.h" 122#include "calendarview.h"
122#ifndef DESKTOP_VERSION 123#ifndef DESKTOP_VERSION
123#include <qtopia/alarmserver.h> 124#include <qtopia/alarmserver.h>
124#endif 125#endif
125#ifndef _WIN32_ 126#ifndef _WIN32_
126#include <stdlib.h> 127#include <stdlib.h>
127#include <stdio.h> 128#include <stdio.h>
128#include <unistd.h> 129#include <unistd.h>
129#else 130#else
130#include <qprocess.h> 131#include <qprocess.h>
131#endif 132#endif
132 133
133#ifdef DESKTOP_VERSION 134#ifdef DESKTOP_VERSION
134#include <kabc/stdaddressbook.h> 135#include <kabc/stdaddressbook.h>
135#endif 136#endif
136using namespace KOrg; 137using namespace KOrg;
137using namespace KCal; 138using namespace KCal;
138extern int globalFlagBlockAgenda; 139extern int globalFlagBlockAgenda;
139extern int globalFlagBlockStartup; 140extern int globalFlagBlockStartup;
140 141
141 142
142MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent) 143MissedAlarmTextBrowser::MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms,QDateTime start ) : QTextBrowser(parent)
143 144
144{ 145{
145 mAlarms = alarms; 146 mAlarms = alarms;
146 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) ); 147 viewport()->setBackgroundColor( QColor( 255, 255, 255 ) );
147 QString mText = "<table width=\"100%\">\n"; 148 QString mText = "<table width=\"100%\">\n";
148 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 149 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
149#ifdef DESKTOP_VERSION 150#ifdef DESKTOP_VERSION
150 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 151 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
151#else 152#else
152 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>"; 153 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h3>";
153#endif 154#endif
154 // mText += "<img src=\""; 155 // mText += "<img src=\"";
155 // mText += ipath; 156 // mText += ipath;
156 // mText += "\">"; 157 // mText += "\">";
157 //mEventDate = QDate::currentDate(); 158 //mEventDate = QDate::currentDate();
158#ifdef DESKTOP_VERSION 159#ifdef DESKTOP_VERSION
159 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>"; 160 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h2>";
160#else 161#else
161 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>"; 162 mText += "<font color=\"#FFFFFF\"> <em>" + i18n("You missed the alarms for the following events or todos:")+"</em></font></h3>";
162#endif 163#endif
163 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 164 //mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
164 165
165 Incidence * inc = getNextInc( start ); 166 Incidence * inc = getNextInc( start );
166 int time = 0; 167 int time = 0;
167 //mText += "<table>"; 168 //mText += "<table>";
168 while ( inc ) { 169 while ( inc ) {
169 QDateTime dt ; 170 QDateTime dt ;
170 QString tempText = "<a "; 171 QString tempText = "<a ";
171 bool ok; 172 bool ok;
172 dt = inc->getNextOccurence( start, &ok ); 173 dt = inc->getNextOccurence( start, &ok );
173 if ( !ok ) continue; 174 if ( !ok ) continue;
174 if ( inc->typeID() == eventID ) { 175 if ( inc->typeID() == eventID ) {
175 tempText += "href=\"event:"; 176 tempText += "href=\"event:";
176 } else if ( inc->typeID() == todoID ) { 177 } else if ( inc->typeID() == todoID ) {
177 tempText += "href=\"todo:"; 178 tempText += "href=\"todo:";
178 } 179 }
179 tempText += inc->uid() + "\">"; 180 tempText += inc->uid() + "\">";
180 if ( inc->typeID() == todoID ) 181 if ( inc->typeID() == todoID )
181 tempText += i18n("Todo: "); 182 tempText += i18n("Todo: ");
182 if ( inc->summary().length() > 0 ) 183 if ( inc->summary().length() > 0 )
183 tempText += inc->summary(); 184 tempText += inc->summary();
184 else 185 else
185 tempText += i18n("-no summary-"); 186 tempText += i18n("-no summary-");
186 QString timestr; 187 QString timestr;
187 if (!inc->doesFloat()) 188 if (!inc->doesFloat())
188 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": "; 189 timestr = KGlobal::locale()->formatDateTime( dt, KOPrefs::instance()->mShortDateInViewer) +": ";
189 else 190 else
190 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": "; 191 timestr = KGlobal::locale()->formatDate( dt.date() , KOPrefs::instance()->mShortDateInViewer) +": ";
191 if ( dt.date() < QDate::currentDate() && time == 0 ) { 192 if ( dt.date() < QDate::currentDate() && time == 0 ) {
192 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>"; 193 mText += "</td></tr>\n<tr bgcolor=\"#FF997D\"><td>";
193 mText += "<table>"; 194 mText += "<table>";
194 time = 1; 195 time = 1;
195 } 196 }
196 if ( dt.date() == QDate::currentDate() && time <= 1 ) { 197 if ( dt.date() == QDate::currentDate() && time <= 1 ) {
197 if ( time > 0 ) 198 if ( time > 0 )
198 mText +="</table>"; 199 mText +="</table>";
199 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>"; 200 mText += "</td></tr>\n<tr bgcolor=\"#FFDC64\"><td>";
200 mText += "<table>"; 201 mText += "<table>";
201 time = 2; 202 time = 2;
202 203
203 } 204 }
204 if ( dt.date() > QDate::currentDate() && time <= 2 ) { 205 if ( dt.date() > QDate::currentDate() && time <= 2 ) {
205 if ( time > 0 ) 206 if ( time > 0 )
206 mText +="</table>"; 207 mText +="</table>";
207 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>"; 208 mText += "</td></tr>\n<tr bgcolor=\"#6AFF6A\"><td>";
208 mText += "<table>"; 209 mText += "<table>";
209 time = 3; 210 time = 3;
210 } 211 }
211 mText +="<tr><td><b>"; 212 mText +="<tr><td><b>";
212 mText += timestr; 213 mText += timestr;
213 mText += "</b></td><td>"; 214 mText += "</b></td><td>";
214 mText += tempText; 215 mText += tempText;
215 mText += "</td></tr>\n"; 216 mText += "</td></tr>\n";
216 inc = getNextInc( start ); 217 inc = getNextInc( start );
217 } 218 }
218 mText +="</table>"; 219 mText +="</table>";
219 setText( mText ); 220 setText( mText );
220} 221}
221 222
222MissedAlarmTextBrowser::~MissedAlarmTextBrowser() 223MissedAlarmTextBrowser::~MissedAlarmTextBrowser()
223{ 224{
224 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() "); 225 //qDebug("delete MissedAlarmTextBrowser::~MissedAlarmTextBrowser() ");
225} 226}
226Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start ) 227Incidence * MissedAlarmTextBrowser::getNextInc( QDateTime start )
227{ 228{
228 QDateTime dt ; 229 QDateTime dt ;
229 Incidence * retInc; 230 Incidence * retInc;
230 Incidence * inc = mAlarms.first(); 231 Incidence * inc = mAlarms.first();
231 if ( inc == 0 ) 232 if ( inc == 0 )
232 return 0; 233 return 0;
233 bool ok; 234 bool ok;
234 dt = inc->getNextOccurence( start, &ok ); 235 dt = inc->getNextOccurence( start, &ok );
235 if ( ! ok ) return 0; 236 if ( ! ok ) return 0;
236 QDateTime dtn ; 237 QDateTime dtn ;
237 retInc = inc; 238 retInc = inc;
238 inc = mAlarms.next(); 239 inc = mAlarms.next();
239 while ( inc ) { 240 while ( inc ) {
240 dtn = inc->getNextOccurence( start, &ok ); 241 dtn = inc->getNextOccurence( start, &ok );
241 if ( ! ok ) return 0; 242 if ( ! ok ) return 0;
242 if ( dtn < dt ) { 243 if ( dtn < dt ) {
243 dt = dtn; 244 dt = dtn;
244 retInc = inc; 245 retInc = inc;
245 } 246 }
246 inc = mAlarms.next(); 247 inc = mAlarms.next();
247 } 248 }
248 mAlarms.remove( retInc ); 249 mAlarms.remove( retInc );
249 return retInc; 250 return retInc;
250 251
251} 252}
252void MissedAlarmTextBrowser::setSource(const QString & n) 253void MissedAlarmTextBrowser::setSource(const QString & n)
253{ 254{
254 if (n.startsWith("event:")) { 255 if (n.startsWith("event:")) {
255#ifdef DESKTOP_VERSION 256#ifdef DESKTOP_VERSION
256 emit showIncidence(n.mid(8)); 257 emit showIncidence(n.mid(8));
257#else 258#else
258 emit showIncidence(n.mid(6)); 259 emit showIncidence(n.mid(6));
259#endif 260#endif
260 return; 261 return;
261 } else if (n.startsWith("todo:")) { 262 } else if (n.startsWith("todo:")) {
262#ifdef DESKTOP_VERSION 263#ifdef DESKTOP_VERSION
263 emit showIncidence(n.mid(7)); 264 emit showIncidence(n.mid(7));
264#else 265#else
265 emit showIncidence(n.mid(5)); 266 emit showIncidence(n.mid(5));
266#endif 267#endif
267 return; 268 return;
268 } 269 }
269} 270}
270 271
271 272
272class KOBeamPrefs : public QDialog 273class KOBeamPrefs : public QDialog
273{ 274{
274 public: 275 public:
275 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) : 276 KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
276 QDialog( parent, name, true ) 277 QDialog( parent, name, true )
277 { 278 {
278 setCaption( i18n("Beam Options") ); 279 setCaption( i18n("Beam Options") );
279 QVBoxLayout* lay = new QVBoxLayout( this ); 280 QVBoxLayout* lay = new QVBoxLayout( this );
280 lay->setSpacing( 3 ); 281 lay->setSpacing( 3 );
281 lay->setMargin( 3 ); 282 lay->setMargin( 3 );
282 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this ); 283 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
283 lay->addWidget( format ); 284 lay->addWidget( format );
284 format->setExclusive ( true ) ; 285 format->setExclusive ( true ) ;
285 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this ); 286 QButtonGroup* time = new QButtonGroup(1, Horizontal, i18n("Time format"), this );
286 lay->addWidget( time ); time->setExclusive ( true ) ; 287 lay->addWidget( time ); time->setExclusive ( true ) ;
287 vcal = new QRadioButton(" vCalendar ", format ); 288 vcal = new QRadioButton(" vCalendar ", format );
288 ical = new QRadioButton(" iCalendar ", format ); 289 ical = new QRadioButton(" iCalendar ", format );
289 vcal->setChecked( true ); 290 vcal->setChecked( true );
290 tz = new QRadioButton(i18n(" With timezone "), time ); 291 tz = new QRadioButton(i18n(" With timezone "), time );
291 local = new QRadioButton(i18n(" Local time "), time ); 292 local = new QRadioButton(i18n(" Local time "), time );
292 tz->setChecked( true ); 293 tz->setChecked( true );
293 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this ); 294 QPushButton * ok = new QPushButton( i18n("Beam via IR!"), this );
294 lay->addWidget( ok ); 295 lay->addWidget( ok );
295 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 296 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
296 lay->addWidget( cancel ); 297 lay->addWidget( cancel );
297 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 298 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
298 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 299 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
299 resize( 200, 200 ); 300 resize( 200, 200 );
300 } 301 }
301 302
302 bool beamVcal() { return vcal->isChecked(); } 303 bool beamVcal() { return vcal->isChecked(); }
303 bool beamLocal() { return local->isChecked(); } 304 bool beamLocal() { return local->isChecked(); }
304private: 305private:
305 QRadioButton* vcal, *ical, *local, *tz; 306 QRadioButton* vcal, *ical, *local, *tz;
306}; 307};
307class KOCatPrefs : public QDialog 308class KOCatPrefs : public QDialog
308{ 309{
309 public: 310 public:
310 KOCatPrefs( QWidget *parent=0, const char *name=0 ) : 311 KOCatPrefs( QWidget *parent=0, const char *name=0 ) :
311 QDialog( parent, name, true ) 312 QDialog( parent, name, true )
312 { 313 {
313 setCaption( i18n("Manage new Categories") ); 314 setCaption( i18n("Manage new Categories") );
314 QVBoxLayout* lay = new QVBoxLayout( this ); 315 QVBoxLayout* lay = new QVBoxLayout( this );
315 lay->setSpacing( 3 ); 316 lay->setSpacing( 3 );
316 lay->setMargin( 3 ); 317 lay->setMargin( 3 );
317 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this ); 318 QLabel * lab = new QLabel( i18n("After importing/loading/syncing there may be new categories in events or todos which are not added automatically to the category list. Please choose what to do <b>now</b>:"), this );
318 lay->addWidget( lab ); 319 lay->addWidget( lab );
319 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); 320 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this );
320 lay->addWidget( format ); 321 lay->addWidget( format );
321 format->setExclusive ( true ) ; 322 format->setExclusive ( true ) ;
322 addCatBut = new QRadioButton(i18n("Add to category list"), format ); 323 addCatBut = new QRadioButton(i18n("Add to category list"), format );
323 new QRadioButton(i18n("Remove from Events/Todos"), format ); 324 new QRadioButton(i18n("Remove from Events/Todos"), format );
324 addCatBut->setChecked( true ); 325 addCatBut->setChecked( true );
325 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this ); 326 QPushButton * ok = new QPushButton( i18n("Change category list now!"), this );
326 lay->addWidget( ok ); 327 lay->addWidget( ok );
327 QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); 328 QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
328 lay->addWidget( cancel ); 329 lay->addWidget( cancel );
329 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 330 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
330 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); 331 connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
331 resize( 200, 200 ); 332 resize( 200, 200 );
332 } 333 }
333 334
334 bool addCat() { return addCatBut->isChecked(); } 335 bool addCat() { return addCatBut->isChecked(); }
335private: 336private:
336 QRadioButton* addCatBut; 337 QRadioButton* addCatBut;
337}; 338};
338 339
339 340
340 341
341CalendarView::CalendarView( CalendarResources *calendar, 342CalendarView::CalendarView( CalendarResources *calendar,
342 QWidget *parent, const char *name ) 343 QWidget *parent, const char *name )
343 : CalendarViewBase( parent, name ), 344 : CalendarViewBase( parent, name ),
344 mCalendar( calendar ), 345 mCalendar( calendar ),
345 mResourceManager( calendar->resourceManager() ) 346 mResourceManager( calendar->resourceManager() )
346{ 347{
347 348
348 mEventEditor = 0; 349 mEventEditor = 0;
349 mTodoEditor = 0; 350 mTodoEditor = 0;
350 351
351 init(); 352 init();
352} 353}
353 354
354CalendarView::CalendarView( Calendar *calendar, 355CalendarView::CalendarView( Calendar *calendar,
355 QWidget *parent, const char *name ) 356 QWidget *parent, const char *name )
356 : CalendarViewBase( parent, name ), 357 : CalendarViewBase( parent, name ),
357 mCalendar( calendar ), 358 mCalendar( calendar ),
358 mResourceManager( 0 ) 359 mResourceManager( 0 )
359{ 360{
360 361
361 mEventEditor = 0; 362 mEventEditor = 0;
362 mTodoEditor = 0; 363 mTodoEditor = 0;
363 init(); 364 init();
364} 365}
365 366
366void CalendarView::init() 367void CalendarView::init()
367{ 368{
368 mNextAlarmDateTime = QDateTime::currentDateTime(); 369 mNextAlarmDateTime = QDateTime::currentDateTime();
369 setFocusPolicy ( NoFocus ); 370 setFocusPolicy ( NoFocus );
370 mViewerCallerIsSearchDialog = false; 371 mViewerCallerIsSearchDialog = false;
371 mBlockShowDates = false; 372 mBlockShowDates = false;
372 373
373 mDatePickerMode = 0; 374 mDatePickerMode = 0;
374 mCurrentSyncDevice = ""; 375 mCurrentSyncDevice = "";
375 mViewManager = new KOViewManager( this ); 376 mViewManager = new KOViewManager( this );
376 mDialogManager = new KODialogManager( this ); 377 mDialogManager = new KODialogManager( this );
377 mEventViewerDialog = 0; 378 mEventViewerDialog = 0;
378 mModified = false; 379 mModified = false;
379 mReadOnly = false; 380 mReadOnly = false;
380 mSelectedIncidence = 0; 381 mSelectedIncidence = 0;
381 mCalPrinter = 0; 382 mCalPrinter = 0;
382 mFilters.setAutoDelete(true); 383 mFilters.setAutoDelete(true);
383 384
384 mCalendar->registerObserver( this ); 385 mCalendar->registerObserver( this );
385 // TODO: Make sure that view is updated, when calendar is changed. 386 // TODO: Make sure that view is updated, when calendar is changed.
386 387
387 mStorage = new FileStorage( mCalendar ); 388 mStorage = new FileStorage( mCalendar );
388 mNavigator = new DateNavigator( this, "datevav", mViewManager ); 389 mNavigator = new DateNavigator( this, "datevav", mViewManager );
389 390
390 QBoxLayout *topLayout = (QBoxLayout*)layout(); 391 QBoxLayout *topLayout = (QBoxLayout*)layout();
391#ifndef KORG_NOSPLITTER 392#ifndef KORG_NOSPLITTER
392 // create the main layout frames. 393 // create the main layout frames.
393 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner"); 394 mPanner = new QSplitter(QSplitter::Horizontal,this,"CalendarView::Panner");
394 topLayout->addWidget(mPanner); 395 topLayout->addWidget(mPanner);
395 396
396 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner, 397 mLeftSplitter = new QSplitter(QSplitter::Vertical,mPanner,
397 "CalendarView::LeftFrame"); 398 "CalendarView::LeftFrame");
398 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize); 399 mPanner->setResizeMode(mLeftSplitter,QSplitter::KeepSize);
399 400
400 mDateNavigator = new DateNavigatorContainer( mLeftSplitter, 401 mDateNavigator = new DateNavigatorContainer( mLeftSplitter,
401 "CalendarView::DateNavigator" ); 402 "CalendarView::DateNavigator" );
402 403
403 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize); 404 mLeftSplitter->setResizeMode(mDateNavigator,QSplitter::KeepSize);
404 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2"); 405 mTodoList = new KOTodoView(mCalendar, mLeftSplitter, "todolist_small2");
405 mTodoList->setNavigator( mNavigator ); 406 mTodoList->setNavigator( mNavigator );
406 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView"); 407 mFilterView = new KOFilterView(&mFilters,mLeftSplitter,"CalendarView::FilterView");
407 408
408#ifdef KORG_NORESOURCEVIEW 409#ifdef KORG_NORESOURCEVIEW
409 mResourceView = 0; 410 mResourceView = 0;
410#else 411#else
411 if ( mResourceManager ) { 412 if ( mResourceManager ) {
412 mResourceView = new ResourceView( mResourceManager, mLeftSplitter ); 413 mResourceView = new ResourceView( mResourceManager, mLeftSplitter );
413 mResourceView->updateView(); 414 mResourceView->updateView();
414 connect( mResourceView, SIGNAL( resourcesChanged() ), 415 connect( mResourceView, SIGNAL( resourcesChanged() ),
415 SLOT( updateView() ) ); 416 SLOT( updateView() ) );
416 } else { 417 } else {
417 mResourceView = 0; 418 mResourceView = 0;
418 } 419 }
419#endif 420#endif
420 QWidget *rightBox = new QWidget( mPanner ); 421 QWidget *rightBox = new QWidget( mPanner );
421 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 422 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
422 423
423 mRightFrame = new QWidgetStack( rightBox ); 424 mRightFrame = new QWidgetStack( rightBox );
424 rightLayout->addWidget( mRightFrame, 1 ); 425 rightLayout->addWidget( mRightFrame, 1 );
425 426
426 mLeftFrame = mLeftSplitter; 427 mLeftFrame = mLeftSplitter;
427#else 428#else
428 //QWidget *mainBox = new QWidget( this ); 429 //QWidget *mainBox = new QWidget( this );
429 //QWidget *leftFrame = new QWidget( mainBox ); 430 //QWidget *leftFrame = new QWidget( mainBox );
430 //QBoxLayout * mainBoxLayout; 431 //QBoxLayout * mainBoxLayout;
431 if ( KOPrefs::instance()->mVerticalScreen ) { 432 if ( KOPrefs::instance()->mVerticalScreen ) {
432 //mainBoxLayout = new QVBoxLayout(mainBox); 433 //mainBoxLayout = new QVBoxLayout(mainBox);
433 //leftFrameLayout = new QHBoxLayout(leftFrame ); 434 //leftFrameLayout = new QHBoxLayout(leftFrame );
434 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this ); 435 mMainFrame = new KDGanttMinimizeSplitter( Qt::Vertical, this );
435 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 436 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
436 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);; 437 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, mMainFrame);;
437 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 438 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
438 } else { 439 } else {
439 //mainBoxLayout = new QHBoxLayout(mainBox); 440 //mainBoxLayout = new QHBoxLayout(mainBox);
440 //leftFrameLayout = new QVBoxLayout(leftFrame ); 441 //leftFrameLayout = new QVBoxLayout(leftFrame );
441 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this); 442 mMainFrame = new KDGanttMinimizeSplitter( Qt::Horizontal, this);
442 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left); 443 mMainFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Left);
443 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame); 444 mLeftFrame = new KDGanttMinimizeSplitter( Qt::Vertical, mMainFrame);
444 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); 445 mLeftFrame->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
445 } 446 }
446 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 447 mMainFrame->setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
447 //QBoxLayout * leftFrameLayout; 448 //QBoxLayout * leftFrameLayout;
448 topLayout->addWidget( mMainFrame ); 449 topLayout->addWidget( mMainFrame );
449#ifdef DESKTOP_VERSION 450#ifdef DESKTOP_VERSION
450 mDateScrollBar = new QScrollBar ( 0, 364, 1,30, 200,QScrollBar::Horizontal, this ); 451 mDateScrollBar = new QScrollBar ( 0, 364, 1,30, 200,QScrollBar::Horizontal, this );
451 topLayout->addWidget( mDateScrollBar ); 452 topLayout->addWidget( mDateScrollBar );
452 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) ); 453 connect( mDateScrollBar, SIGNAL( valueChanged ( int ) ),this, SLOT( scrollBarValue( int )) );
453 if ( QApplication::desktop()->width() < 800 ) 454 if ( QApplication::desktop()->width() < 800 )
454 mDateScrollBar->hide(); 455 mDateScrollBar->hide();
455#endif 456#endif
456 //mainBoxLayout->addWidget (mLeftFrame); 457 //mainBoxLayout->addWidget (mLeftFrame);
457 mDateNavigator = new DateNavigatorContainer( mLeftFrame, 458 mDateNavigator = new DateNavigatorContainer( mLeftFrame,
458 "CalendarView::DateNavigator" ); 459 "CalendarView::DateNavigator" );
459#if 0 460#if 0
460 // FIXME 461 // FIXME
461 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE, 462 mDateNavigator = new KDateNavigator(mLeftFrame, mCalendar, TRUE,
462 "CalendarView::DateNavigator", QDate::currentDate()); 463 "CalendarView::DateNavigator", QDate::currentDate());
463#endif 464#endif
464 // mDateNavigator->blockSignals( true ); 465 // mDateNavigator->blockSignals( true );
465 //leftFrameLayout->addWidget( mDateNavigator ); 466 //leftFrameLayout->addWidget( mDateNavigator );
466 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall"); 467 mTodoList = new KOTodoView(mCalendar, mLeftFrame, "todolistsmall");
467 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView"); 468 mFilterView = new KOFilterView(&mFilters,mLeftFrame,"CalendarView::FilterView");
468 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView"); 469 mCalEditView = new KOCalEditView(mLeftFrame,"CalendarView::CaleditView");
469 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) ); 470 connect( mCalEditView, SIGNAL( calendarEnabled (int,bool) ),mCalendar, SLOT( setCalendarEnabled(int,bool)) );
470 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) ); 471 connect( mCalEditView, SIGNAL( alarmEnabled(int,bool) ),mCalendar, SLOT( setAlarmEnabled(int,bool)) );
471 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) ); 472 connect( mCalEditView, SIGNAL( calendarReadonly(int,bool) ),this, SLOT( setCalReadOnly(int,bool)) );
472 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) ); 473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mCalendar, SLOT( setDefaultCalendar(int)) );
473 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) ); 474 connect( mCalEditView, SIGNAL( setCalendarDefault(int) ),mViewManager, SLOT( setDefaultCalendar(int)) );
474 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) ); 475 connect( mCalEditView, SIGNAL( removeCalendar(int) ),mCalendar, SLOT( setCalendarRemove(int)) );
475 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) ); 476 connect( mCalEditView, SIGNAL( calendarAdded(int) ),this, SLOT( addCalendarId(int)) );
476 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) ); 477 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateView()) );
477 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() )); 478 connect( mCalEditView, SIGNAL( checkCalendar() ),this, SLOT( checkFiles() ));
478 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) ); 479 connect( mCalEditView, SIGNAL( needsUpdate() ),this, SLOT( updateUnmanagedViews()) );
479 480
480 mTodoList->setNavigator( mNavigator ); 481 mTodoList->setNavigator( mNavigator );
481#if 0 482#if 0
482 if ( QApplication::desktop()->width() < 480 ) { 483 if ( QApplication::desktop()->width() < 480 ) {
483 leftFrameLayout->addWidget(mFilterView); 484 leftFrameLayout->addWidget(mFilterView);
484 leftFrameLayout->addWidget(mTodoList, 2 ); 485 leftFrameLayout->addWidget(mTodoList, 2 );
485 486
486 } else { 487 } else {
487 leftFrameLayout->addWidget(mTodoList,2 ); 488 leftFrameLayout->addWidget(mTodoList,2 );
488 leftFrameLayout->addWidget(mFilterView ); 489 leftFrameLayout->addWidget(mFilterView );
489 } 490 }
490#endif 491#endif
491 mFilterView->hide(); 492 mFilterView->hide();
492 mCalEditView->hide(); 493 mCalEditView->hide();
493 QWidget *rightBox = new QWidget( mMainFrame ); 494 QWidget *rightBox = new QWidget( mMainFrame );
494 //mainBoxLayout->addWidget ( rightBox, 10 ); 495 //mainBoxLayout->addWidget ( rightBox, 10 );
495 QBoxLayout *rightLayout = new QVBoxLayout( rightBox ); 496 QBoxLayout *rightLayout = new QVBoxLayout( rightBox );
496 mRightFrame = new QWidgetStack( rightBox ); 497 mRightFrame = new QWidgetStack( rightBox );
497 rightLayout->addWidget( mRightFrame, 10 ); 498 rightLayout->addWidget( mRightFrame, 10 );
498 499
499 //mLeftFrame = (QWidget *)leftFrame; 500 //mLeftFrame = (QWidget *)leftFrame;
500 if ( KOPrefs::instance()->mVerticalScreen ) { 501 if ( KOPrefs::instance()->mVerticalScreen ) {
501 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() ); 502 //mDateNavigator->setFixedHeight( mDateNavigator->sizeHint().height() );
502 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() ); 503 //mDateNavigator->setMinimumWidth( mDateNavigator->sizeHint().width() );
503 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() ); 504 //mTodoList->setFixedHeight( mDateNavigator->sizeHint().height() );
504 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() ); 505 //leftFrame->setFixedHeight( mDateNavigator->sizeHint().height() );
505 } else { 506 } else {
506 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() ); 507 //mDateNavigator->setFixedWidth( mDateNavigator->sizeHint().width() );
507 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() ); 508 //mTodoList->setFixedWidth( mDateNavigator->sizeHint().width() );
508 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() ); 509 //leftFrame->setFixedWidth( mDateNavigator->sizeHint().width() );
509 } 510 }
510 if ( !KOPrefs::instance()->mShowDateNavigator) 511 if ( !KOPrefs::instance()->mShowDateNavigator)
511 mDateNavigator->hide(); 512 mDateNavigator->hide();
512 //qDebug("Calendarview Size %d %d ", width(), height()); 513 //qDebug("Calendarview Size %d %d ", width(), height());
513#endif 514#endif
514 515
515 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 516 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
516 SLOT( showDates( const KCal::DateList & ) ) ); 517 SLOT( showDates( const KCal::DateList & ) ) );
517 518
518 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 519 connect( mNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
519 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 520 mDateNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
520 521
521 522
522 523
523 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ), 524 connect( mDateNavigator, SIGNAL( showMonth( const QDate & ) ),
524 mViewManager, SLOT( showMonth( const QDate & ) ) ); 525 mViewManager, SLOT( showMonth( const QDate & ) ) );
525 526
526 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ), 527 connect( mDateNavigator, SIGNAL( weekClicked( const QDate & ) ),
527 mNavigator, SLOT( selectWeek( const QDate & ) ) ); 528 mNavigator, SLOT( selectWeek( const QDate & ) ) );
528 529
529 connect( mDateNavigator, SIGNAL( goPrevYear() ), 530 connect( mDateNavigator, SIGNAL( goPrevYear() ),
530 mNavigator, SLOT( selectPreviousYear() ) ); 531 mNavigator, SLOT( selectPreviousYear() ) );
531 connect( mDateNavigator, SIGNAL( goNextYear() ), 532 connect( mDateNavigator, SIGNAL( goNextYear() ),
532 mNavigator, SLOT( selectNextYear() ) ); 533 mNavigator, SLOT( selectNextYear() ) );
533 connect( mDateNavigator, SIGNAL( goPrevMonth() ), 534 connect( mDateNavigator, SIGNAL( goPrevMonth() ),
534 mNavigator, SLOT( selectPreviousMonth() ) ); 535 mNavigator, SLOT( selectPreviousMonth() ) );
535 connect( mDateNavigator, SIGNAL( goNextMonth() ), 536 connect( mDateNavigator, SIGNAL( goNextMonth() ),
536 mNavigator, SLOT( selectNextMonth() ) ); 537 mNavigator, SLOT( selectNextMonth() ) );
537 538
538 connect( mDateNavigator, SIGNAL( goPrevious() ), 539 connect( mDateNavigator, SIGNAL( goPrevious() ),
539 mNavigator, SLOT( selectPrevious() ) ); 540 mNavigator, SLOT( selectPrevious() ) );
540 connect( mDateNavigator, SIGNAL( goNext() ), 541 connect( mDateNavigator, SIGNAL( goNext() ),
541 mNavigator, SLOT( selectNext() ) ); 542 mNavigator, SLOT( selectNext() ) );
542 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ), 543 connect( mDateNavigator, SIGNAL( monthSelected ( int ) ),
543 mNavigator, SLOT( slotMonthSelect( int ) ) ); 544 mNavigator, SLOT( slotMonthSelect( int ) ) );
544 545
545 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ), 546 connect( mDateNavigator, SIGNAL( datesSelected( const KCal::DateList & ) ),
546 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) ); 547 mNavigator, SLOT( selectDates( const KCal::DateList & ) ) );
547#if 0 548#if 0
548 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ), 549 connect( mDateNavigator, SIGNAL( incidenceDropped( Incidence * ) ),
549 SLOT( incidenceAdded( Incidence *) ) ); 550 SLOT( incidenceAdded( Incidence *) ) );
550#endif 551#endif
551 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView())); 552 // connect(mDateNavigator,SIGNAL(dayPassed(QDate)),SLOT(updateView()));
552 553
553 connect( this, SIGNAL( configChanged() ), 554 connect( this, SIGNAL( configChanged() ),
554 mDateNavigator, SLOT( updateConfig() ) ); 555 mDateNavigator, SLOT( updateConfig() ) );
555 556
556 connect( mTodoList, SIGNAL( newTodoSignal() ), 557 connect( mTodoList, SIGNAL( newTodoSignal() ),
557 SLOT( newTodo() ) ); 558 SLOT( newTodo() ) );
558 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ), 559 connect( mTodoList, SIGNAL( newSubTodoSignal( Todo *) ),
559 SLOT( newSubTodo( Todo * ) ) ); 560 SLOT( newSubTodo( Todo * ) ) );
560 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ), 561 connect( mTodoList, SIGNAL( editTodoSignal( Todo * ) ),
561 SLOT( editTodo( Todo * ) ) ); 562 SLOT( editTodo( Todo * ) ) );
562 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ), 563 connect( mTodoList, SIGNAL( showTodoSignal( Todo * ) ),
563 SLOT( showTodo( Todo *) ) ); 564 SLOT( showTodo( Todo *) ) );
564 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ), 565 connect( mTodoList, SIGNAL( deleteTodoSignal( Todo *) ),
565 SLOT( deleteTodo( Todo *) ) ); 566 SLOT( deleteTodo( Todo *) ) );
566 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) ); 567 connect( this, SIGNAL( configChanged()), mTodoList, SLOT( updateConfig() ) );
567 connect( mTodoList, SIGNAL( purgeCompletedSignal() ), 568 connect( mTodoList, SIGNAL( purgeCompletedSignal() ),
568 SLOT( purgeCompleted() ) ); 569 SLOT( purgeCompleted() ) );
569 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ), 570 connect( mTodoList, SIGNAL( todoModifiedSignal( Todo *, int ) ),
570 SIGNAL( todoModified( Todo *, int ) ) ); 571 SIGNAL( todoModified( Todo *, int ) ) );
571 572
572 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ), 573 connect( mTodoList, SIGNAL( cloneTodoSignal( Incidence * ) ),
573 this, SLOT ( cloneIncidence( Incidence * ) ) ); 574 this, SLOT ( cloneIncidence( Incidence * ) ) );
574 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ), 575 connect( mTodoList, SIGNAL( cancelTodoSignal( Incidence * ) ),
575 this, SLOT (cancelIncidence( Incidence * ) ) ); 576 this, SLOT (cancelIncidence( Incidence * ) ) );
576 577
577 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ), 578 connect( mTodoList, SIGNAL( moveTodoSignal( Incidence * ) ),
578 this, SLOT ( moveIncidence( Incidence * ) ) ); 579 this, SLOT ( moveIncidence( Incidence * ) ) );
579 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ), 580 connect( mTodoList, SIGNAL( beamTodoSignal( Incidence * ) ),
580 this, SLOT ( beamIncidence( Incidence * ) ) ); 581 this, SLOT ( beamIncidence( Incidence * ) ) );
581 582
582 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ), 583 connect( mTodoList, SIGNAL( unparentTodoSignal( Todo * ) ),
583 this, SLOT ( todo_unsub( Todo * ) ) ); 584 this, SLOT ( todo_unsub( Todo * ) ) );
584 585
585 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), 586 connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ),
586 this, SLOT ( todo_resub( Todo *,Todo * ) ) ); 587 this, SLOT ( todo_resub( Todo *,Todo * ) ) );
587 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, 588 connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList,
588 SLOT( updateTodo( Todo *, int ) ) ); 589 SLOT( updateTodo( Todo *, int ) ) );
589 connect( this, SIGNAL( todoModified( Todo *, int )), this, 590 connect( this, SIGNAL( todoModified( Todo *, int )), this,
590 SLOT( changeTodoDisplay( Todo *, int ) ) ); 591 SLOT( changeTodoDisplay( Todo *, int ) ) );
591 592
592 593
593 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); 594 connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) );
594 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); 595 connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) );
595 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); 596 connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) );
596 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); 597 connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) );
597 598
598 599
599 600
600 601
601 602
602 connect(QApplication::clipboard(),SIGNAL(dataChanged()), 603 connect(QApplication::clipboard(),SIGNAL(dataChanged()),
603 SLOT(checkClipboard())); 604 SLOT(checkClipboard()));
604 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), 605 connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ),
605 SLOT( processTodoListSelection( Incidence * ) ) ); 606 SLOT( processTodoListSelection( Incidence * ) ) );
606 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); 607 connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool)));
607 608
608 // kdDebug() << "CalendarView::CalendarView() done" << endl; 609 // kdDebug() << "CalendarView::CalendarView() done" << endl;
609 610
610 mDateFrame = new QVBox(0,0,WType_Popup); 611 mDateFrame = new QVBox(0,0,WType_Popup);
611 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 612 //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
612 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 613 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
613 mDateFrame->setLineWidth(3); 614 mDateFrame->setLineWidth(3);
614 mDateFrame->hide(); 615 mDateFrame->hide();
615 mDateFrame->setCaption( i18n( "Pick a date to display")); 616 mDateFrame->setCaption( i18n( "Pick a date to display"));
616 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); 617 mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() );
617 618
618 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); 619 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate)));
619 620
620 mEventEditor = mDialogManager->getEventEditor(); 621 mEventEditor = mDialogManager->getEventEditor();
621 mTodoEditor = mDialogManager->getTodoEditor(); 622 mTodoEditor = mDialogManager->getTodoEditor();
622 623
623 mFlagEditDescription = false; 624 mFlagEditDescription = false;
624 625
625 mSuspendTimer = new QTimer( this ); 626 mSuspendTimer = new QTimer( this );
626 mAlarmTimer = new QTimer( this ); 627 mAlarmTimer = new QTimer( this );
627 mRecheckAlarmTimer = new QTimer( this ); 628 mRecheckAlarmTimer = new QTimer( this );
628 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); 629 connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) );
629 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
630 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
631 mAlarmDialog = new AlarmDialog( this ); 632 mAlarmDialog = new AlarmDialog( this );
632 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
633 mAlarmDialog->setServerNotification( false ); 634 mAlarmDialog->setServerNotification( false );
634 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
635 636
636 637
637#ifndef DESKTOP_VERSION 638#ifndef DESKTOP_VERSION
638//US listen for arriving address resultsets 639//US listen for arriving address resultsets
639 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
640 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
641#endif 642#endif
642 mDateNavigator->setCalendar( mCalendar ); 643 mDateNavigator->setCalendar( mCalendar );
643} 644}
644 645
645 646
646CalendarView::~CalendarView() 647CalendarView::~CalendarView()
647{ 648{
648 // kdDebug() << "~CalendarView()" << endl; 649 // kdDebug() << "~CalendarView()" << endl;
649 //qDebug("CalendarView::~CalendarView() "); 650 //qDebug("CalendarView::~CalendarView() ");
650 delete mDialogManager; 651 delete mDialogManager;
651 delete mViewManager; 652 delete mViewManager;
652 delete mStorage; 653 delete mStorage;
653 delete mDateFrame ; 654 delete mDateFrame ;
654 delete mEventViewerDialog; 655 delete mEventViewerDialog;
655 //kdDebug() << "~CalendarView() done" << endl; 656 //kdDebug() << "~CalendarView() done" << endl;
656} 657}
657void CalendarView::nextConflict( bool all, bool allday ) 658void CalendarView::nextConflict( bool all, bool allday )
658{ 659{
659 660
660 QPtrList<Event> testlist = mCalendar->events(); 661 QPtrList<Event> testlist = mCalendar->events();
661 Event * test = testlist.first(); 662 Event * test = testlist.first();
662 while ( test ) { 663 while ( test ) {
663 test->setTagged( false ); 664 test->setTagged( false );
664 test = testlist.next(); 665 test = testlist.next();
665 } 666 }
666 QDateTime startDT = QDateTime (mNavigator->selectedDates().first().addDays(1), QTime ( 0,0,0)); 667 QTime st ( 0,0,0);
668 if ( mViewManager->currentView() == mViewManager->agendaView() )
669 st = mViewManager->agendaView()->agenda()->getEndTime();
670 //qDebug("time %s ", st.toString().latin1());
671 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st);
667 QDateTime conflict; 672 QDateTime conflict;
668 QDateTime retVal; 673 QDateTime retVal;
669 bool found = false; 674 bool found = false;
670 Event * cE = 0; 675 Event * cE = 0;
671 Event * cE2 = 0; 676 Event * cE2 = 0;
672 QPtrList<Event> testlist2 = testlist; 677 QPtrList<Event> testlist2 = testlist;
673 test = testlist.first(); 678 test = testlist.first();
674 bool skip = false; 679 bool skip = false;
675 while ( test ) { 680 while ( test ) {
676 skip = false; 681 skip = false;
677 if ( !all ) skip = ( allday != test->doesFloat() ); 682 if ( !all ) skip = ( allday != test->doesFloat() );
678 if ( !skip ) { 683 if ( !skip ) {
679 Event * test2 = testlist2.first(); 684 Event * test2 = testlist2.first();
680 while ( test2 ) { 685 while ( test2 ) {
681 skip = false; 686 skip = false;
682 if ( !all ) skip = ( allday != test2->doesFloat() ); 687 if ( !all ) skip = ( allday != test2->doesFloat() );
683 if ( !skip ) { 688 if ( !skip ) {
684 if ( !test2->isTagged() ) { 689 if ( !test2->isTagged() ) {
685 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 690 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
686 //qDebug("overlap "); 691 //qDebug("overlap ");
687 if ( ! found ) { 692 if ( ! found ) {
688 if ( retVal >= startDT ) { 693 if ( retVal >= startDT ) {
689 conflict = retVal; 694 conflict = retVal;
690 cE = test; 695 cE = test;
691 cE2 = test2; 696 cE2 = test2;
692 found = true; 697 found = true;
693 } 698 }
694 } else { 699 } else {
695 if ( retVal >= startDT && retVal < conflict ) { 700 if ( retVal >= startDT && retVal < conflict ) {
696 conflict = retVal; 701 conflict = retVal;
697 cE = test; 702 cE = test;
698 cE2 = test2; 703 cE2 = test2;
699 } 704 }
700 } 705 }
701 } 706 }
702 } 707 }
703 } 708 }
704 test2 = testlist2.next(); 709 test2 = testlist2.next();
705 } 710 }
706 } 711 }
707 test->setTagged( true ); 712 test->setTagged( true );
708 test = testlist.next(); 713 test = testlist.next();
709 } 714 }
710 if ( found ) { 715 if ( found ) {
711 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 716 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
712 mViewManager->showDayView(); 717 mViewManager->showDayView();
713 mNavigator->slotDaySelect( conflict.date() ); 718 mNavigator->slotDaySelect( conflict.date() );
714 int hour = conflict.time().hour(); 719 int hour = conflict.time().hour();
715 mViewManager->agendaView()->setStartHour( hour ); 720 mViewManager->agendaView()->setStartHour( hour );
716 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 721 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
717 return; 722 return;
718 } 723 }
719 724
720 topLevelWidget()->setCaption( i18n("No conflict found") ); 725 topLevelWidget()->setCaption( i18n("No conflict found") );
721 qDebug("No conflict found "); 726 qDebug("No conflict found ");
722 return; 727 return;
723
724
725
726
727
728#if 0
729
730
731 QDate end = start.addDays( 365*2);
732 while ( start < end ) {
733 QPtrList<Event> eventList = calendar()->events( start );
734 Event * ev = eventList.first();
735 QPtrList<Event> test = eventList;
736 while ( ev ) {
737 //qDebug("found %d on %s ", eventList.count(), start.toString().latin1());
738 Event * t_ev = test.first();
739 QDateTime es = ev->dtStart();
740 QDateTime ee = ev->dtEnd();
741 if ( ev->doesFloat() )
742 ee = ee.addDays( 1 );
743 if ( ! all ) {
744 if ( ev->doesFloat() != allday )
745 t_ev = 0;
746 }
747 while ( t_ev ) {
748 bool skip = false;
749 if ( ! all ) {
750 if ( t_ev->doesFloat() != allday )
751 skip = true;
752 }
753 if ( !skip && ev != t_ev ) {
754 QDateTime ets = t_ev->dtStart();
755 QDateTime ete = t_ev->dtEnd();
756 if ( t_ev->doesFloat() )
757 ete = ete.addDays( 1 );
758 //qDebug("test %s -- %s -------- %s -- %s ", es.toString().latin1() , ee.toString().latin1(), ets.toString().latin1() , ete.toString().latin1() );
759 if ( es < ete && ets < ee ) {
760 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
761 mViewManager->showDayView();
762 mNavigator->slotDaySelect( start );
763 int hour = es.time().hour();
764 if ( ets > es )
765 hour = ets.time().hour();
766 mViewManager->agendaView()->setStartHour( hour );
767 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( ev->summary().left( 20 ) ).arg( t_ev->summary().left( 20 ) ) );
768 return;
769 }
770 }
771 t_ev = test.next();
772 }
773 ev = eventList.next();
774 }
775 start = start.addDays( 1 );
776 }
777 topLevelWidget()->setCaption( i18n("No conflict found within the next two years") );
778 qDebug("No conflict found ");
779#endif
780} 728}
781 729
782void CalendarView::conflictAll() 730void CalendarView::conflictAll()
783{ 731{
784 nextConflict ( true, true ); 732 nextConflict ( true, true );
785} 733}
786void CalendarView::conflictAllday() 734void CalendarView::conflictAllday()
787{ 735{
788 nextConflict ( false, true ); 736 nextConflict ( false, true );
789} 737}
790void CalendarView::conflictNotAll() 738void CalendarView::conflictNotAll()
791{ 739{
792 nextConflict ( false, false ); 740 nextConflict ( false, false );
793} 741}
794 742
795void CalendarView::setCalReadOnly( int id, bool readO ) 743void CalendarView::setCalReadOnly( int id, bool readO )
796{ 744{
797 if ( readO ) { 745 if ( readO ) {
798 emit save(); 746 emit save();
799 } 747 }
800 mCalendar->setReadOnly( id, readO ); 748 mCalendar->setReadOnly( id, readO );
801} 749}
802void CalendarView::setScrollBarStep(int val ) 750void CalendarView::setScrollBarStep(int val )
803{ 751{
804#ifdef DESKTOP_VERSION 752#ifdef DESKTOP_VERSION
805 mDateScrollBar->setLineStep ( val ); 753 mDateScrollBar->setLineStep ( val );
806#endif 754#endif
807} 755}
808void CalendarView::scrollBarValue(int val ) 756void CalendarView::scrollBarValue(int val )
809{ 757{
810#ifdef DESKTOP_VERSION 758#ifdef DESKTOP_VERSION
811 if ( QApplication::desktop()->width() < 800 ) return; 759 if ( QApplication::desktop()->width() < 800 ) return;
812 static bool block = false; 760 static bool block = false;
813 if ( block ) return; 761 if ( block ) return;
814 block = true; 762 block = true;
815 int count = mNavigator->selectedDates().count(); 763 int count = mNavigator->selectedDates().count();
816 int day = mNavigator->selectedDates().first().dayOfYear(); 764 int day = mNavigator->selectedDates().first().dayOfYear();
817 int stepdays = val; 765 int stepdays = val;
818 if ( mDateScrollBar->lineStep () <= count ) { 766 if ( mDateScrollBar->lineStep () <= count ) {
819 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 767 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
820 //qDebug("VAL %d ",val ); 768 //qDebug("VAL %d ",val );
821 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 769 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
822 stepdays = day+stepdays; 770 stepdays = day+stepdays;
823 if ( stepdays < 0 ) stepdays = 0; 771 if ( stepdays < 0 ) stepdays = 0;
824 } 772 }
825 if ( stepdays == day ) { 773 if ( stepdays == day ) {
826 block = false; 774 block = false;
827 return; 775 return;
828 } 776 }
829 int year = mNavigator->selectedDates().first().year(); 777 int year = mNavigator->selectedDates().first().year();
830 QDate d ( year,1,1 ); 778 QDate d ( year,1,1 );
831 mNavigator->selectDates( d.addDays( stepdays-1) , count ); 779 mNavigator->selectDates( d.addDays( stepdays-1) , count );
832 block = false; 780 block = false;
833#endif 781#endif
834 782
835} 783}
836void CalendarView::updateView(const QDate &start, const QDate &end) 784void CalendarView::updateView(const QDate &start, const QDate &end)
837{ 785{
838#ifdef DESKTOP_VERSION 786#ifdef DESKTOP_VERSION
839 if ( ! mDateScrollBar->draggingSlider () ) { 787 if ( ! mDateScrollBar->draggingSlider () ) {
840 int dof = start.dayOfYear(); 788 int dof = start.dayOfYear();
841 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); 789 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
842 if ( dof != mDateScrollBar->value() ) { 790 if ( dof != mDateScrollBar->value() ) {
843 mDateScrollBar->blockSignals( true ); 791 mDateScrollBar->blockSignals( true );
844 mDateScrollBar->setValue( start.dayOfYear()); 792 mDateScrollBar->setValue( start.dayOfYear());
845 mDateScrollBar->blockSignals( false ); 793 mDateScrollBar->blockSignals( false );
846 } 794 }
847 } 795 }
848#endif 796#endif
849 mTodoList->updateView(); 797 mTodoList->updateView();
850 mViewManager->updateView(start, end); 798 mViewManager->updateView(start, end);
851 //mDateNavigator->updateView(); 799 //mDateNavigator->updateView();
852} 800}
853 801
854 802
855 803
856void CalendarView::checkFiles() 804void CalendarView::checkFiles()
857{ 805{
858 QString message; 806 QString message;
859 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 807 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
860 KopiCalendarFile * cal = calendars.first(); 808 KopiCalendarFile * cal = calendars.first();
861 while ( cal ) { 809 while ( cal ) {
862 if ( cal->mErrorOnLoad ) { 810 if ( cal->mErrorOnLoad ) {
863 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; 811 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n";
864 } 812 }
865 cal = calendars.next(); 813 cal = calendars.next();
866 } 814 }
867 if ( !message.isEmpty() ) { 815 if ( !message.isEmpty() ) {
868 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); 816 message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0);
869 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); 817 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed"));
870 } 818 }
871 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 819 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
872} 820}
873void CalendarView::checkAlarms() 821void CalendarView::checkAlarms()
874{ 822{
875 823
876 824
877 KConfig *config = KOGlobals::config(); 825 KConfig *config = KOGlobals::config();
878 config->setGroup( "AppRun" ); 826 config->setGroup( "AppRun" );
879 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 827 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
880 int daysto = dt.daysTo( QDate::currentDate() ); 828 int daysto = dt.daysTo( QDate::currentDate() );
881 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 829 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
882 dt = dt.addDays( days ); 830 dt = dt.addDays( days );
883 int secto = dt.secsTo( QDateTime::currentDateTime() ); 831 int secto = dt.secsTo( QDateTime::currentDateTime() );
884 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 832 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
885 //qDebug("KO: Reading program stop %d ", secs); 833 //qDebug("KO: Reading program stop %d ", secs);
886 //secs -= ( 3600 * 24*3 ); // debug only 834 //secs -= ( 3600 * 24*3 ); // debug only
887 QDateTime latest = dt.addSecs ( secs ); 835 QDateTime latest = dt.addSecs ( secs );
888 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 836 qDebug("KO: Last termination on %s ", latest.toString().latin1());
889 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 837 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
890 QPtrList<Incidence> el = mCalendar->rawIncidences(); 838 QPtrList<Incidence> el = mCalendar->rawIncidences();
891 QPtrList<Incidence> al; 839 QPtrList<Incidence> al;
892 Incidence* inL = el.first(); 840 Incidence* inL = el.first();
893 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 841 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
894 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 842 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
895 while ( inL ) { 843 while ( inL ) {
896 bool ok = false; 844 bool ok = false;
897 int offset = 0; 845 int offset = 0;
898 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 846 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
899 if ( ok ) { 847 if ( ok ) {
900 //qDebug("OK %s",next.toString().latin1()); 848 //qDebug("OK %s",next.toString().latin1());
901 if ( next < cur ) { 849 if ( next < cur ) {
902 al.append( inL ); 850 al.append( inL );
903 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 851 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
904 } 852 }
905 } 853 }
906 inL = el.next(); 854 inL = el.next();
907 } 855 }
908 if ( al.count() ) { 856 if ( al.count() ) {
909 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 857 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
910 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 858 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
911 QVBoxLayout* lay = new QVBoxLayout( dia ); 859 QVBoxLayout* lay = new QVBoxLayout( dia );
912 lay->setSpacing( 0 ); 860 lay->setSpacing( 0 );
913 lay->setMargin( 0 ); 861 lay->setMargin( 0 );
914 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 862 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
915 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 863 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
916 lay->addWidget( matb ); 864 lay->addWidget( matb );
917 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 865 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
918 int wid = 210; 866 int wid = 210;
919 int x = QApplication::desktop()->width() - wid - 7; 867 int x = QApplication::desktop()->width() - wid - 7;
920 int y = QApplication::desktop()->height() - wid - 70; 868 int y = QApplication::desktop()->height() - wid - 70;
921 dia->setGeometry ( x,y,wid,wid); 869 dia->setGeometry ( x,y,wid,wid);
922 } else { 870 } else {
923 int si = 220; 871 int si = 220;
924 if ( QApplication::desktop()->width() > 470 ) 872 if ( QApplication::desktop()->width() > 470 )
925 si = 400; 873 si = 400;
926 dia->resize(si,si/2); 874 dia->resize(si,si/2);
927 } 875 }
928 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 876 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
929 dia->show(); 877 dia->show();
930 878
931 } 879 }
932} 880}
933void CalendarView::showDay( QDate d ) 881void CalendarView::showDay( QDate d )
934{ 882{
935 dateNavigator()->blockSignals( true ); 883 dateNavigator()->blockSignals( true );
936 dateNavigator()->selectDate( d ); 884 dateNavigator()->selectDate( d );
937 dateNavigator()->blockSignals( false ); 885 dateNavigator()->blockSignals( false );
938 mViewManager->showDayView(); 886 mViewManager->showDayView();
939 //dateNavigator()->selectDate( d ); 887 //dateNavigator()->selectDate( d );
940} 888}
941void CalendarView::timerAlarm() 889void CalendarView::timerAlarm()
942{ 890{
943 //qDebug("CalendarView::timerAlarm() "); 891 //qDebug("CalendarView::timerAlarm() ");
944 computeAlarm(mAlarmNotification ); 892 computeAlarm(mAlarmNotification );
945} 893}
946 894
947void CalendarView::suspendAlarm() 895void CalendarView::suspendAlarm()
948{ 896{
949 //qDebug(" CalendarView::suspendAlarm() "); 897 //qDebug(" CalendarView::suspendAlarm() ");
950 computeAlarm(mSuspendAlarmNotification ); 898 computeAlarm(mSuspendAlarmNotification );
951 899
952} 900}
953 901
954void CalendarView::startAlarm( QString mess , QString filename) 902void CalendarView::startAlarm( QString mess , QString filename)
955{ 903{
956 904
957 topLevelWidget()->showNormal(); 905 topLevelWidget()->showNormal();
958 topLevelWidget()->setActiveWindow(); 906 topLevelWidget()->setActiveWindow();
959 topLevelWidget()->raise(); 907 topLevelWidget()->raise();
960 908
961 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 909 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
962 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 910 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
963 911
964} 912}
965 913
966void CalendarView::checkNextTimerAlarm() 914void CalendarView::checkNextTimerAlarm()
967{ 915{
968 mCalendar->checkAlarmForIncidence( 0, true ); 916 mCalendar->checkAlarmForIncidence( 0, true );
969} 917}
970 918
971void CalendarView::computeAlarm( QString msg ) 919void CalendarView::computeAlarm( QString msg )
972{ 920{
973 921
974 QString mess = msg; 922 QString mess = msg;
975 QString mAlarmMessage = mess.mid( 9 ); 923 QString mAlarmMessage = mess.mid( 9 );
976 QString filename = MainWindow::resourcePath(); 924 QString filename = MainWindow::resourcePath();
977 filename += "koalarm.wav"; 925 filename += "koalarm.wav";
978 QString tempfilename; 926 QString tempfilename;
979 if ( mess.left( 13 ) == "suspend_alarm") { 927 if ( mess.left( 13 ) == "suspend_alarm") {
980 bool error = false; 928 bool error = false;
981 int len = mess.mid( 13 ).find("+++"); 929 int len = mess.mid( 13 ).find("+++");
982 if ( len < 2 ) 930 if ( len < 2 )
983 error = true; 931 error = true;
984 else { 932 else {
985 tempfilename = mess.mid( 13, len ); 933 tempfilename = mess.mid( 13, len );
986 if ( !QFile::exists( tempfilename ) ) 934 if ( !QFile::exists( tempfilename ) )
987 error = true; 935 error = true;
988 } 936 }
989 if ( ! error ) { 937 if ( ! error ) {
990 filename = tempfilename; 938 filename = tempfilename;
991 } 939 }
992 mAlarmMessage = mess.mid( 13+len+3 ); 940 mAlarmMessage = mess.mid( 13+len+3 );
993 //qDebug("suspend file %s ",tempfilename.latin1() ); 941 //qDebug("suspend file %s ",tempfilename.latin1() );
994 startAlarm( mAlarmMessage, filename); 942 startAlarm( mAlarmMessage, filename);
995 return; 943 return;
996 } 944 }
997 if ( mess.left( 11 ) == "timer_alarm") { 945 if ( mess.left( 11 ) == "timer_alarm") {
998 //mTimerTime = 0; 946 //mTimerTime = 0;
999 startAlarm( mess.mid( 11 ), filename ); 947 startAlarm( mess.mid( 11 ), filename );
1000 return; 948 return;
1001 } 949 }
1002 if ( mess.left( 10 ) == "proc_alarm") { 950 if ( mess.left( 10 ) == "proc_alarm") {
1003 bool error = false; 951 bool error = false;
1004 int len = mess.mid( 10 ).find("+++"); 952 int len = mess.mid( 10 ).find("+++");
1005 if ( len < 2 ) 953 if ( len < 2 )
1006 error = true; 954 error = true;
1007 else { 955 else {
1008 tempfilename = mess.mid( 10, len ); 956 tempfilename = mess.mid( 10, len );
1009 if ( !QFile::exists( tempfilename ) ) 957 if ( !QFile::exists( tempfilename ) )
1010 error = true; 958 error = true;
1011 } 959 }
1012 if ( error ) { 960 if ( error ) {
1013 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 961 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
1014 mAlarmMessage += mess.mid( 10+len+3+9 ); 962 mAlarmMessage += mess.mid( 10+len+3+9 );
1015 } else { 963 } else {
1016 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 964 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
1017 //qDebug("-----system command %s ",tempfilename.latin1() ); 965 //qDebug("-----system command %s ",tempfilename.latin1() );
1018#ifndef _WIN32_ 966#ifndef _WIN32_
1019 if ( vfork () == 0 ) { 967 if ( vfork () == 0 ) {
1020 execl ( tempfilename.latin1(), 0 ); 968 execl ( tempfilename.latin1(), 0 );
1021 return; 969 return;
1022 } 970 }
1023#else 971#else
1024 QProcess* p = new QProcess(); 972 QProcess* p = new QProcess();
1025 p->addArgument( tempfilename.latin1() ); 973 p->addArgument( tempfilename.latin1() );
1026 p->start(); 974 p->start();
1027 return; 975 return;
1028#endif 976#endif
1029 977
1030 return; 978 return;
1031 } 979 }
1032 980
1033 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 981 //qDebug("+++++++system command %s ",tempfilename.latin1() );
1034 } 982 }
1035 if ( mess.left( 11 ) == "audio_alarm") { 983 if ( mess.left( 11 ) == "audio_alarm") {
1036 bool error = false; 984 bool error = false;
1037 int len = mess.mid( 11 ).find("+++"); 985 int len = mess.mid( 11 ).find("+++");
1038 if ( len < 2 ) 986 if ( len < 2 )
1039 error = true; 987 error = true;
1040 else { 988 else {
1041 tempfilename = mess.mid( 11, len ); 989 tempfilename = mess.mid( 11, len );
1042 if ( !QFile::exists( tempfilename ) ) 990 if ( !QFile::exists( tempfilename ) )
1043 error = true; 991 error = true;
1044 } 992 }
1045 if ( ! error ) { 993 if ( ! error ) {
1046 filename = tempfilename; 994 filename = tempfilename;
1047 } 995 }
1048 mAlarmMessage = mess.mid( 11+len+3+9 ); 996 mAlarmMessage = mess.mid( 11+len+3+9 );
1049 //qDebug("audio file command %s ",tempfilename.latin1() ); 997 //qDebug("audio file command %s ",tempfilename.latin1() );
1050 } 998 }
1051 if ( mess.left( 9 ) == "cal_alarm") { 999 if ( mess.left( 9 ) == "cal_alarm") {
1052 mAlarmMessage = mess.mid( 9 ) ; 1000 mAlarmMessage = mess.mid( 9 ) ;
1053 } 1001 }
1054 1002
1055 startAlarm( mAlarmMessage, filename ); 1003 startAlarm( mAlarmMessage, filename );
1056 1004
1057 1005
1058} 1006}
1059 1007
1060void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1008void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1061{ 1009{
1062 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1010 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1063 1011
1064 mSuspendAlarmNotification = noti; 1012 mSuspendAlarmNotification = noti;
1065 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1013 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1066 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1014 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1067 mSuspendTimer->start( ms , true ); 1015 mSuspendTimer->start( ms , true );
1068 1016
1069} 1017}
1070 1018
1071void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1019void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1072{ 1020{
1073 mNextAlarmDateTime = qdt; 1021 mNextAlarmDateTime = qdt;
1074 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1022 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1075 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1023 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1076#ifndef DESKTOP_VERSION 1024#ifndef DESKTOP_VERSION
1077 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1025 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1078#endif 1026#endif
1079 return; 1027 return;
1080 } 1028 }
1081 int maxSec; 1029 int maxSec;
1082 //maxSec = 5; //testing only 1030 //maxSec = 5; //testing only
1083 maxSec = 86400+3600; // one day+1hour 1031 maxSec = 86400+3600; // one day+1hour
1084 mAlarmNotification = noti; 1032 mAlarmNotification = noti;
1085 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1033 int sec = QDateTime::currentDateTime().secsTo( qdt );
1086 if ( sec > maxSec ) { 1034 if ( sec > maxSec ) {
1087 mRecheckAlarmTimer->start( maxSec * 1000 ); 1035 mRecheckAlarmTimer->start( maxSec * 1000 );
1088 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1036 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1089 return; 1037 return;
1090 } else { 1038 } else {
1091 mRecheckAlarmTimer->stop(); 1039 mRecheckAlarmTimer->stop();
1092 } 1040 }
1093 //qDebug("Alarm timer started with secs: %d ", sec); 1041 //qDebug("Alarm timer started with secs: %d ", sec);
1094 mAlarmTimer->start( sec *1000 , true ); 1042 mAlarmTimer->start( sec *1000 , true );
1095 1043
1096} 1044}
1097// called by mRecheckAlarmTimer to get next alarm 1045// called by mRecheckAlarmTimer to get next alarm
1098// we need this, because a QTimer has only a max range of 25 days 1046// we need this, because a QTimer has only a max range of 25 days
1099void CalendarView::recheckTimerAlarm() 1047void CalendarView::recheckTimerAlarm()
1100{ 1048{
1101 mAlarmTimer->stop(); 1049 mAlarmTimer->stop();
1102 mRecheckAlarmTimer->stop(); 1050 mRecheckAlarmTimer->stop();
1103 mCalendar->checkAlarmForIncidence( 0, true ); 1051 mCalendar->checkAlarmForIncidence( 0, true );
1104} 1052}
1105#ifndef DESKTOP_VERSION 1053#ifndef DESKTOP_VERSION
1106void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1054void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1107#else 1055#else
1108void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1056void CalendarView::removeAlarm(const QDateTime &, const QString & )
1109#endif 1057#endif
1110{ 1058{
1111 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1059 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1112 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1060 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1113#ifndef DESKTOP_VERSION 1061#ifndef DESKTOP_VERSION
1114 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1062 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1115#endif 1063#endif
1116 return; 1064 return;
1117 } 1065 }
1118 mAlarmTimer->stop(); 1066 mAlarmTimer->stop();
1119} 1067}
1120void CalendarView::selectWeekNum ( int num ) 1068void CalendarView::selectWeekNum ( int num )
1121{ 1069{
1122 dateNavigator()->blockSignals( true ); 1070 dateNavigator()->blockSignals( true );
1123 dateNavigator()->selectWeek( num ); 1071 dateNavigator()->selectWeek( num );
1124 dateNavigator()->blockSignals( false ); 1072 dateNavigator()->blockSignals( false );
1125 mViewManager->showWeekView(); 1073 mViewManager->showWeekView();
1126} 1074}
1127KOViewManager *CalendarView::viewManager() 1075KOViewManager *CalendarView::viewManager()
1128{ 1076{
1129 return mViewManager; 1077 return mViewManager;
1130} 1078}
1131 1079
1132KODialogManager *CalendarView::dialogManager() 1080KODialogManager *CalendarView::dialogManager()
1133{ 1081{
1134 return mDialogManager; 1082 return mDialogManager;
1135} 1083}
1136 1084
1137QDate CalendarView::startDate() 1085QDate CalendarView::startDate()
1138{ 1086{
1139 DateList dates = mNavigator->selectedDates(); 1087 DateList dates = mNavigator->selectedDates();
1140 1088
1141 return dates.first(); 1089 return dates.first();
1142} 1090}
1143 1091
1144QDate CalendarView::endDate() 1092QDate CalendarView::endDate()
1145{ 1093{
1146 DateList dates = mNavigator->selectedDates(); 1094 DateList dates = mNavigator->selectedDates();
1147 1095
1148 return dates.last(); 1096 return dates.last();
1149} 1097}
1150 1098
1151 1099
1152void CalendarView::createPrinter() 1100void CalendarView::createPrinter()
1153{ 1101{
1154#ifndef KORG_NOPRINTER 1102#ifndef KORG_NOPRINTER
1155 if (!mCalPrinter) { 1103 if (!mCalPrinter) {
1156 mCalPrinter = new CalPrinter(this, mCalendar); 1104 mCalPrinter = new CalPrinter(this, mCalendar);
1157 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1105 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1158 } 1106 }
1159#endif 1107#endif
1160} 1108}
1161 1109
1162 1110
1163//KOPrefs::instance()->mWriteBackFile 1111//KOPrefs::instance()->mWriteBackFile
1164//KOPrefs::instance()->mWriteBackExistingOnly 1112//KOPrefs::instance()->mWriteBackExistingOnly
1165 1113
1166// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1114// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1167// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1115// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1168// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1116// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1169// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1117// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1170// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1118// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1171// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1119// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1172 1120
1173int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1121int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1174{ 1122{
1175 1123
1176 // 0 equal 1124 // 0 equal
1177 // 1 take local 1125 // 1 take local
1178 // 2 take remote 1126 // 2 take remote
1179 // 3 cancel 1127 // 3 cancel
1180 QDateTime lastSync = mLastCalendarSync; 1128 QDateTime lastSync = mLastCalendarSync;
1181 QDateTime localMod = local->lastModified(); 1129 QDateTime localMod = local->lastModified();
1182 QDateTime remoteMod = remote->lastModified(); 1130 QDateTime remoteMod = remote->lastModified();
1183 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1131 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1184 bool remCh, locCh; 1132 bool remCh, locCh;
1185 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1133 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1186 //if ( remCh ) 1134 //if ( remCh )
1187 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1135 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1188 locCh = ( localMod > mLastCalendarSync ); 1136 locCh = ( localMod > mLastCalendarSync );
1189 if ( !remCh && ! locCh ) { 1137 if ( !remCh && ! locCh ) {
1190 //qDebug("both not changed "); 1138 //qDebug("both not changed ");
1191 lastSync = localMod.addDays(1); 1139 lastSync = localMod.addDays(1);
1192 if ( mode <= SYNC_PREF_ASK ) 1140 if ( mode <= SYNC_PREF_ASK )
1193 return 0; 1141 return 0;
1194 } else { 1142 } else {
1195 if ( locCh ) { 1143 if ( locCh ) {
1196 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1144 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1197 lastSync = localMod.addDays( -1 ); 1145 lastSync = localMod.addDays( -1 );
1198 if ( !remCh ) 1146 if ( !remCh )
1199 remoteMod = ( lastSync.addDays( -1 ) ); 1147 remoteMod = ( lastSync.addDays( -1 ) );
1200 } else { 1148 } else {
1201 //qDebug(" not loc changed "); 1149 //qDebug(" not loc changed ");
1202 lastSync = localMod.addDays( 1 ); 1150 lastSync = localMod.addDays( 1 );
1203 if ( remCh ) 1151 if ( remCh )
1204 remoteMod =( lastSync.addDays( 1 ) ); 1152 remoteMod =( lastSync.addDays( 1 ) );
1205 1153
1206 } 1154 }
1207 } 1155 }
1208 full = true; 1156 full = true;
1209 if ( mode < SYNC_PREF_ASK ) 1157 if ( mode < SYNC_PREF_ASK )
1210 mode = SYNC_PREF_ASK; 1158 mode = SYNC_PREF_ASK;
1211 } else { 1159 } else {
1212 if ( localMod == remoteMod ) 1160 if ( localMod == remoteMod )
1213 // if ( local->revision() == remote->revision() ) 1161 // if ( local->revision() == remote->revision() )
1214 return 0; 1162 return 0;
1215 1163
1216 } 1164 }
1217 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1165 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1218 1166
1219 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1167 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1220 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1168 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1221 //full = true; //debug only 1169 //full = true; //debug only
1222 if ( full ) { 1170 if ( full ) {
1223 bool equ = false; 1171 bool equ = false;
1224 if ( local->typeID() == eventID ) { 1172 if ( local->typeID() == eventID ) {
1225 equ = (*((Event*) local) == *((Event*) remote)); 1173 equ = (*((Event*) local) == *((Event*) remote));
1226 } 1174 }
1227 else if ( local->typeID() == todoID ) 1175 else if ( local->typeID() == todoID )
1228 equ = (*((Todo*) local) == (*(Todo*) remote)); 1176 equ = (*((Todo*) local) == (*(Todo*) remote));
1229 else if ( local->typeID() == journalID ) 1177 else if ( local->typeID() == journalID )
1230 equ = (*((Journal*) local) == *((Journal*) remote)); 1178 equ = (*((Journal*) local) == *((Journal*) remote));
1231 if ( equ ) { 1179 if ( equ ) {
1232 //qDebug("equal "); 1180 //qDebug("equal ");
1233 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1181 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1234 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1182 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1235 } 1183 }
1236 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1184 if ( mode < SYNC_PREF_FORCE_LOCAL )
1237 return 0; 1185 return 0;
1238 1186
1239 }//else //debug only 1187 }//else //debug only
1240 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1188 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1241 } 1189 }
1242 int result; 1190 int result;
1243 bool localIsNew; 1191 bool localIsNew;
1244 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 1192 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
1245 1193
1246 1194
1247 // ************************************************ 1195 // ************************************************
1248 // ************************************************ 1196 // ************************************************
1249 // ************************************************ 1197 // ************************************************
1250 // We may have that lastSync > remoteMod AND lastSync > localMod 1198 // We may have that lastSync > remoteMod AND lastSync > localMod
1251 // BUT remoteMod != localMod 1199 // BUT remoteMod != localMod
1252 1200
1253 1201
1254 if ( full && mode < SYNC_PREF_NEWEST ) 1202 if ( full && mode < SYNC_PREF_NEWEST )
1255 mode = SYNC_PREF_ASK; 1203 mode = SYNC_PREF_ASK;
1256 1204
1257 switch( mode ) { 1205 switch( mode ) {
1258 case SYNC_PREF_LOCAL: 1206 case SYNC_PREF_LOCAL:
1259 if ( lastSync > remoteMod ) 1207 if ( lastSync > remoteMod )
1260 return 1; 1208 return 1;
1261 if ( lastSync > localMod ) 1209 if ( lastSync > localMod )
1262 return 2; 1210 return 2;
1263 return 1; 1211 return 1;
1264 break; 1212 break;
1265 case SYNC_PREF_REMOTE: 1213 case SYNC_PREF_REMOTE:
1266 if ( lastSync > localMod ) 1214 if ( lastSync > localMod )
1267 return 2; 1215 return 2;
1268 if ( lastSync > remoteMod ) 1216 if ( lastSync > remoteMod )
1269 return 1; 1217 return 1;
1270 return 2; 1218 return 2;
1271 break; 1219 break;
1272 case SYNC_PREF_NEWEST: 1220 case SYNC_PREF_NEWEST:
1273 if ( localMod >= remoteMod ) 1221 if ( localMod >= remoteMod )
1274 return 1; 1222 return 1;
1275 else 1223 else
1276 return 2; 1224 return 2;
1277 break; 1225 break;
1278 case SYNC_PREF_ASK: 1226 case SYNC_PREF_ASK:
1279 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1227 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1280 if ( lastSync > remoteMod && lastSync > localMod) 1228 if ( lastSync > remoteMod && lastSync > localMod)
1281 return 0; 1229 return 0;
1282 if ( lastSync > remoteMod ) 1230 if ( lastSync > remoteMod )
1283 return 1; 1231 return 1;
1284 if ( lastSync > localMod ) 1232 if ( lastSync > localMod )
1285 return 2; 1233 return 2;
1286 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1234 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1287 localIsNew = localMod >= remoteMod; 1235 localIsNew = localMod >= remoteMod;
1288 if ( localIsNew ) 1236 if ( localIsNew )
1289 getEventViewerDialog()->setColorMode( 1 ); 1237 getEventViewerDialog()->setColorMode( 1 );
1290 else 1238 else
1291 getEventViewerDialog()->setColorMode( 2 ); 1239 getEventViewerDialog()->setColorMode( 2 );
1292 getEventViewerDialog()->setIncidence(local); 1240 getEventViewerDialog()->setIncidence(local);
1293 if ( localIsNew ) 1241 if ( localIsNew )
1294 getEventViewerDialog()->setColorMode( 2 ); 1242 getEventViewerDialog()->setColorMode( 2 );
1295 else 1243 else
1296 getEventViewerDialog()->setColorMode( 1 ); 1244 getEventViewerDialog()->setColorMode( 1 );
1297 getEventViewerDialog()->addIncidence(remote); 1245 getEventViewerDialog()->addIncidence(remote);
1298 getEventViewerDialog()->setColorMode( 0 ); 1246 getEventViewerDialog()->setColorMode( 0 );
1299 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1247 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1300 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1248 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1301 getEventViewerDialog()->showMe(); 1249 getEventViewerDialog()->showMe();
1302 result = getEventViewerDialog()->executeS( localIsNew ); 1250 result = getEventViewerDialog()->executeS( localIsNew );
1303 return result; 1251 return result;
1304 1252
1305 break; 1253 break;
1306 case SYNC_PREF_FORCE_LOCAL: 1254 case SYNC_PREF_FORCE_LOCAL:
1307 return 1; 1255 return 1;
1308 break; 1256 break;
1309 case SYNC_PREF_FORCE_REMOTE: 1257 case SYNC_PREF_FORCE_REMOTE:
1310 return 2; 1258 return 2;
1311 break; 1259 break;
1312 1260
1313 default: 1261 default:
1314 // SYNC_PREF_TAKE_BOTH not implemented 1262 // SYNC_PREF_TAKE_BOTH not implemented
1315 break; 1263 break;
1316 } 1264 }
1317 return 0; 1265 return 0;
1318} 1266}
1319Event* CalendarView::getLastSyncEvent() 1267Event* CalendarView::getLastSyncEvent()
1320{ 1268{
1321 Event* lse; 1269 Event* lse;
1322 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1270 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1323 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1271 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1324 if (!lse) { 1272 if (!lse) {
1325 lse = new Event(); 1273 lse = new Event();
1326 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1274 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1327 QString sum = ""; 1275 QString sum = "";
1328 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1276 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1329 sum = "E: "; 1277 sum = "E: ";
1330 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1278 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1331 lse->setDtStart( mLastCalendarSync ); 1279 lse->setDtStart( mLastCalendarSync );
1332 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1280 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1333 lse->setCategories( i18n("SyncEvent") ); 1281 lse->setCategories( i18n("SyncEvent") );
1334 lse->setReadOnly( true ); 1282 lse->setReadOnly( true );
1335 mCalendar->addEvent( lse ); 1283 mCalendar->addEvent( lse );
1336 } 1284 }
1337 1285
1338 return lse; 1286 return lse;
1339 1287
1340} 1288}
1341 1289
1342// we check, if the to delete event has a id for a profile 1290// we check, if the to delete event has a id for a profile
1343// if yes, we set this id in the profile to delete 1291// if yes, we set this id in the profile to delete
1344void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1292void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1345{ 1293{
1346 if ( lastSync.count() == 0 ) { 1294 if ( lastSync.count() == 0 ) {
1347 //qDebug(" lastSync.count() == 0"); 1295 //qDebug(" lastSync.count() == 0");
1348 return; 1296 return;
1349 } 1297 }
1350 if ( toDelete->typeID() == journalID ) 1298 if ( toDelete->typeID() == journalID )
1351 return; 1299 return;
1352 1300
1353 Event* eve = lastSync.first(); 1301 Event* eve = lastSync.first();
1354 1302
1355 while ( eve ) { 1303 while ( eve ) {
1356 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1304 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1357 if ( !id.isEmpty() ) { 1305 if ( !id.isEmpty() ) {
1358 QString des = eve->description(); 1306 QString des = eve->description();
1359 QString pref = "e"; 1307 QString pref = "e";
1360 if ( toDelete->typeID() == todoID ) 1308 if ( toDelete->typeID() == todoID )
1361 pref = "t"; 1309 pref = "t";
1362 des += pref+ id + ","; 1310 des += pref+ id + ",";
1363 eve->setReadOnly( false ); 1311 eve->setReadOnly( false );
1364 eve->setDescription( des ); 1312 eve->setDescription( des );
1365 //qDebug("setdes %s ", des.latin1()); 1313 //qDebug("setdes %s ", des.latin1());
1366 eve->setReadOnly( true ); 1314 eve->setReadOnly( true );
1367 } 1315 }
1368 eve = lastSync.next(); 1316 eve = lastSync.next();
1369 } 1317 }
1370 1318
1371} 1319}
1372void CalendarView::checkExternalId( Incidence * inc ) 1320void CalendarView::checkExternalId( Incidence * inc )
1373{ 1321{
1374 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1322 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1375 checkExternSyncEvent( lastSync, inc ); 1323 checkExternSyncEvent( lastSync, inc );
1376 1324
1377} 1325}
1378bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1326bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1379{ 1327{
1380 bool syncOK = true; 1328 bool syncOK = true;
1381 int addedEvent = 0; 1329 int addedEvent = 0;
1382 int addedEventR = 0; 1330 int addedEventR = 0;
1383 int deletedEventR = 0; 1331 int deletedEventR = 0;
1384 int deletedEventL = 0; 1332 int deletedEventL = 0;
1385 int changedLocal = 0; 1333 int changedLocal = 0;
1386 int changedRemote = 0; 1334 int changedRemote = 0;
1387 int filteredIN = 0; 1335 int filteredIN = 0;
1388 int filteredOUT = 0; 1336 int filteredOUT = 0;
1389 //QPtrList<Event> el = local->rawEvents(); 1337 //QPtrList<Event> el = local->rawEvents();
1390 Event* eventR; 1338 Event* eventR;
1391 QString uid; 1339 QString uid;
1392 int take; 1340 int take;
1393 Event* eventRSync; 1341 Event* eventRSync;
1394 Event* eventLSync; 1342 Event* eventLSync;
1395 clearAllViews(); 1343 clearAllViews();
1396 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1344 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1397 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1345 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1398 bool fullDateRange = false; 1346 bool fullDateRange = false;
1399 local->resetTempSyncStat(); 1347 local->resetTempSyncStat();
1400 mLastCalendarSync = QDateTime::currentDateTime(); 1348 mLastCalendarSync = QDateTime::currentDateTime();
1401 if ( mSyncManager->syncWithDesktop() ) { 1349 if ( mSyncManager->syncWithDesktop() ) {
1402 remote->resetPilotStat(1); 1350 remote->resetPilotStat(1);
1403 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1351 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1404 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1352 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1405 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1353 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1406 } else { 1354 } else {
1407 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1355 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1408 } 1356 }
1409 } 1357 }
1410 QDateTime modifiedCalendar = mLastCalendarSync; 1358 QDateTime modifiedCalendar = mLastCalendarSync;
1411 eventLSync = getLastSyncEvent(); 1359 eventLSync = getLastSyncEvent();
1412 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1360 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1413 if ( eventR ) { 1361 if ( eventR ) {
1414 eventRSync = (Event*) eventR->clone(); 1362 eventRSync = (Event*) eventR->clone();
1415 remote->deleteEvent(eventR ); 1363 remote->deleteEvent(eventR );
1416 1364
1417 } else { 1365 } else {
1418 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1366 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1419 eventRSync = (Event*)eventLSync->clone(); 1367 eventRSync = (Event*)eventLSync->clone();
1420 } else { 1368 } else {
1421 fullDateRange = true; 1369 fullDateRange = true;
1422 eventRSync = new Event(); 1370 eventRSync = new Event();
1423 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1371 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1424 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1372 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1425 eventRSync->setDtStart( mLastCalendarSync ); 1373 eventRSync->setDtStart( mLastCalendarSync );
1426 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1374 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1427 eventRSync->setCategories( i18n("SyncEvent") ); 1375 eventRSync->setCategories( i18n("SyncEvent") );
1428 } 1376 }
1429 } 1377 }
1430 if ( eventLSync->dtStart() == mLastCalendarSync ) 1378 if ( eventLSync->dtStart() == mLastCalendarSync )
1431 fullDateRange = true; 1379 fullDateRange = true;
1432 1380
1433 if ( ! fullDateRange ) { 1381 if ( ! fullDateRange ) {
1434 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1382 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1435 1383
1436 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1384 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1437 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1385 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1438 fullDateRange = true; 1386 fullDateRange = true;
1439 } 1387 }
1440 } 1388 }
1441 if ( mSyncManager->syncWithDesktop() ) { 1389 if ( mSyncManager->syncWithDesktop() ) {
1442 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1390 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1443 } 1391 }
1444 if ( fullDateRange ) 1392 if ( fullDateRange )
1445 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1393 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1446 else 1394 else
1447 mLastCalendarSync = eventLSync->dtStart(); 1395 mLastCalendarSync = eventLSync->dtStart();
1448 // for resyncing if own file has changed 1396 // for resyncing if own file has changed
1449 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1397 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1450 mLastCalendarSync = loadedFileVersion; 1398 mLastCalendarSync = loadedFileVersion;
1451 //qDebug("setting mLastCalendarSync "); 1399 //qDebug("setting mLastCalendarSync ");
1452 } 1400 }
1453 //qDebug("*************************** "); 1401 //qDebug("*************************** ");
1454 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1402 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1455 QPtrList<Incidence> er = remote->rawIncidences(); 1403 QPtrList<Incidence> er = remote->rawIncidences();
1456 Incidence* inR = er.first(); 1404 Incidence* inR = er.first();
1457 Incidence* inL; 1405 Incidence* inL;
1458 QProgressBar bar( er.count(),0 ); 1406 QProgressBar bar( er.count(),0 );
1459 bar.setCaption (i18n("Syncing - close to abort!") ); 1407 bar.setCaption (i18n("Syncing - close to abort!") );
1460 1408
1461 // ************** setting up filter ************* 1409 // ************** setting up filter *************
1462 CalFilter *filterIN = 0; 1410 CalFilter *filterIN = 0;
1463 CalFilter *filterOUT = 0; 1411 CalFilter *filterOUT = 0;
1464 CalFilter *filter = mFilters.first(); 1412 CalFilter *filter = mFilters.first();
1465 while(filter) { 1413 while(filter) {
1466 if ( filter->name() == mSyncManager->mFilterInCal ) 1414 if ( filter->name() == mSyncManager->mFilterInCal )
1467 filterIN = filter; 1415 filterIN = filter;
1468 if ( filter->name() == mSyncManager->mFilterOutCal ) 1416 if ( filter->name() == mSyncManager->mFilterOutCal )
1469 filterOUT = filter; 1417 filterOUT = filter;
1470 filter = mFilters.next(); 1418 filter = mFilters.next();
1471 } 1419 }
1472 int w = 300; 1420 int w = 300;
1473 if ( QApplication::desktop()->width() < 320 ) 1421 if ( QApplication::desktop()->width() < 320 )
1474 w = 220; 1422 w = 220;
1475 int h = bar.sizeHint().height() ; 1423 int h = bar.sizeHint().height() ;
1476 int dw = QApplication::desktop()->width(); 1424 int dw = QApplication::desktop()->width();
1477 int dh = QApplication::desktop()->height(); 1425 int dh = QApplication::desktop()->height();
1478 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1426 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1479 bar.show(); 1427 bar.show();
1480 int modulo = (er.count()/10)+1; 1428 int modulo = (er.count()/10)+1;
1481 int incCounter = 0; 1429 int incCounter = 0;
1482 while ( inR ) { 1430 while ( inR ) {
1483 if ( ! bar.isVisible() ) 1431 if ( ! bar.isVisible() )
1484 return false; 1432 return false;
1485 if ( incCounter % modulo == 0 ) 1433 if ( incCounter % modulo == 0 )
1486 bar.setProgress( incCounter ); 1434 bar.setProgress( incCounter );
1487 ++incCounter; 1435 ++incCounter;
1488 uid = inR->uid(); 1436 uid = inR->uid();
1489 bool skipIncidence = false; 1437 bool skipIncidence = false;
1490 if ( uid.left(15) == QString("last-syncEvent-") ) 1438 if ( uid.left(15) == QString("last-syncEvent-") )
1491 skipIncidence = true; 1439 skipIncidence = true;
1492 QString idS; 1440 QString idS;
1493 qApp->processEvents(); 1441 qApp->processEvents();
1494 if ( !skipIncidence ) { 1442 if ( !skipIncidence ) {
1495 inL = local->incidence( uid ); 1443 inL = local->incidence( uid );
1496 if ( inL ) { // maybe conflict - same uid in both calendars 1444 if ( inL ) { // maybe conflict - same uid in both calendars
1497 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1445 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1498 //qDebug("take %d %s ", take, inL->summary().latin1()); 1446 //qDebug("take %d %s ", take, inL->summary().latin1());
1499 if ( take == 3 ) 1447 if ( take == 3 )
1500 return false; 1448 return false;
1501 if ( take == 1 ) {// take local ********************** 1449 if ( take == 1 ) {// take local **********************
1502 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1450 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1503 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1451 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1504 else 1452 else
1505 idS = inR->IDStr(); 1453 idS = inR->IDStr();
1506 remote->deleteIncidence( inR ); 1454 remote->deleteIncidence( inR );
1507 inR = inL->clone(); 1455 inR = inL->clone();
1508 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1456 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1509 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1457 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1510 inR->setIDStr( idS ); 1458 inR->setIDStr( idS );
1511 remote->addIncidence( inR ); 1459 remote->addIncidence( inR );
1512 if ( mSyncManager->syncWithDesktop() ) 1460 if ( mSyncManager->syncWithDesktop() )
1513 inR->setPilotId( 2 ); 1461 inR->setPilotId( 2 );
1514 ++changedRemote; 1462 ++changedRemote;
1515 } else {// take remote ********************** 1463 } else {// take remote **********************
1516 idS = inL->IDStr(); 1464 idS = inL->IDStr();
1517 int pid = inL->pilotId(); 1465 int pid = inL->pilotId();
1518 local->deleteIncidence( inL ); 1466 local->deleteIncidence( inL );
1519 inL = inR->clone(); 1467 inL = inR->clone();
1520 if ( mSyncManager->syncWithDesktop() ) 1468 if ( mSyncManager->syncWithDesktop() )
1521 inL->setPilotId( pid ); 1469 inL->setPilotId( pid );
1522 inL->setIDStr( idS ); 1470 inL->setIDStr( idS );
1523 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1471 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1524 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1472 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1525 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1473 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1526 } 1474 }
1527 local->addIncidence( inL ); 1475 local->addIncidence( inL );
1528 ++changedLocal; 1476 ++changedLocal;
1529 } 1477 }
1530 } 1478 }
1531 } else { // no conflict ********** add or delete remote 1479 } else { // no conflict ********** add or delete remote
1532 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1480 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1533 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1481 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1534 QString des = eventLSync->description(); 1482 QString des = eventLSync->description();
1535 QString pref = "e"; 1483 QString pref = "e";
1536 if ( inR->typeID() == todoID ) 1484 if ( inR->typeID() == todoID )
1537 pref = "t"; 1485 pref = "t";
1538 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1486 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1539 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1487 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1540 //remote->deleteIncidence( inR ); 1488 //remote->deleteIncidence( inR );
1541 ++deletedEventR; 1489 ++deletedEventR;
1542 } else { 1490 } else {
1543 inR->setLastModified( modifiedCalendar ); 1491 inR->setLastModified( modifiedCalendar );
1544 inL = inR->clone(); 1492 inL = inR->clone();
1545 inL->setIDStr( ":" ); 1493 inL->setIDStr( ":" );
1546 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1494 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1547 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1495 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp
index b290020..779f12e 100644
--- a/korganizer/koagenda.cpp
+++ b/korganizer/koagenda.cpp
@@ -868,1394 +868,1398 @@ void KOAgenda::startItemAction(QPoint viewportPos)
868 mActionItem->startMove(); 868 mActionItem->startMove();
869 setCursor(sizeAllCursor); 869 setCursor(sizeAllCursor);
870 } 870 }
871 } 871 }
872} 872}
873 873
874void KOAgenda::performItemAction(QPoint viewportPos) 874void KOAgenda::performItemAction(QPoint viewportPos)
875{ 875{
876// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 876// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
877// QPoint point = viewport()->mapToGlobal(viewportPos); 877// QPoint point = viewport()->mapToGlobal(viewportPos);
878// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 878// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
879// point = clipper()->mapFromGlobal(point); 879// point = clipper()->mapFromGlobal(point);
880// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 880// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
881// kdDebug() << "visible height: " << visibleHeight() << endl; 881// kdDebug() << "visible height: " << visibleHeight() << endl;
882 int x,y; 882 int x,y;
883 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 883 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
884// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 884// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
885 int gx,gy; 885 int gx,gy;
886 contentsToGrid(x,y,gx,gy); 886 contentsToGrid(x,y,gx,gy);
887 QPoint clipperPos = clipper()-> 887 QPoint clipperPos = clipper()->
888 mapFromGlobal(viewport()->mapToGlobal(viewportPos)); 888 mapFromGlobal(viewport()->mapToGlobal(viewportPos));
889 889
890 // Cursor left active agenda area. 890 // Cursor left active agenda area.
891 // This starts a drag. 891 // This starts a drag.
892 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ 892 if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/
893 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { 893 clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) {
894 if ( mActionType == MOVE ) { 894 if ( mActionType == MOVE ) {
895 mScrollUpTimer.stop(); 895 mScrollUpTimer.stop();
896 mScrollDownTimer.stop(); 896 mScrollDownTimer.stop();
897 mActionItem->resetMove(); 897 mActionItem->resetMove();
898 placeSubCells( mActionItem ); 898 placeSubCells( mActionItem );
899 // emit startDragSignal( mActionItem->incidence() ); 899 // emit startDragSignal( mActionItem->incidence() );
900 setCursor( arrowCursor ); 900 setCursor( arrowCursor );
901 mActionItem = 0; 901 mActionItem = 0;
902 mActionType = NOP; 902 mActionType = NOP;
903 mItemMoved = 0; 903 mItemMoved = 0;
904 return; 904 return;
905 } 905 }
906 } else { 906 } else {
907 switch ( mActionType ) { 907 switch ( mActionType ) {
908 case MOVE: 908 case MOVE:
909 setCursor( sizeAllCursor ); 909 setCursor( sizeAllCursor );
910 break; 910 break;
911 case RESIZETOP: 911 case RESIZETOP:
912 case RESIZEBOTTOM: 912 case RESIZEBOTTOM:
913 setCursor( sizeVerCursor ); 913 setCursor( sizeVerCursor );
914 break; 914 break;
915 case RESIZELEFT: 915 case RESIZELEFT:
916 case RESIZERIGHT: 916 case RESIZERIGHT:
917 setCursor( sizeHorCursor ); 917 setCursor( sizeHorCursor );
918 break; 918 break;
919 default: 919 default:
920 setCursor( arrowCursor ); 920 setCursor( arrowCursor );
921 } 921 }
922 } 922 }
923 923
924 // Scroll if item was moved to upper or lower end of agenda. 924 // Scroll if item was moved to upper or lower end of agenda.
925 if (clipperPos.y() < mScrollBorderWidth) { 925 if (clipperPos.y() < mScrollBorderWidth) {
926 mScrollUpTimer.start(mScrollDelay); 926 mScrollUpTimer.start(mScrollDelay);
927 } else if (visibleHeight() - clipperPos.y() < 927 } else if (visibleHeight() - clipperPos.y() <
928 mScrollBorderWidth) { 928 mScrollBorderWidth) {
929 mScrollDownTimer.start(mScrollDelay); 929 mScrollDownTimer.start(mScrollDelay);
930 } else { 930 } else {
931 mScrollUpTimer.stop(); 931 mScrollUpTimer.stop();
932 mScrollDownTimer.stop(); 932 mScrollDownTimer.stop();
933 } 933 }
934 934
935 // Move or resize item if necessary 935 // Move or resize item if necessary
936 if (mCurrentCellX != gx || mCurrentCellY != gy) { 936 if (mCurrentCellX != gx || mCurrentCellY != gy) {
937 mItemMoved = true; 937 mItemMoved = true;
938 mActionItem->raise(); 938 mActionItem->raise();
939 if (mActionType == MOVE) { 939 if (mActionType == MOVE) {
940 // Move all items belonging to a multi item 940 // Move all items belonging to a multi item
941 KOAgendaItem *moveItem = mActionItem->firstMultiItem(); 941 KOAgendaItem *moveItem = mActionItem->firstMultiItem();
942 bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); 942 bool isMultiItem = (moveItem || mActionItem->lastMultiItem());
943 if (!moveItem) moveItem = mActionItem; 943 if (!moveItem) moveItem = mActionItem;
944 while (moveItem) { 944 while (moveItem) {
945 int dy; 945 int dy;
946 if (isMultiItem) dy = 0; 946 if (isMultiItem) dy = 0;
947 else dy = gy - mCurrentCellY; 947 else dy = gy - mCurrentCellY;
948 moveItem->moveRelative(gx - mCurrentCellX,dy); 948 moveItem->moveRelative(gx - mCurrentCellX,dy);
949 int x,y; 949 int x,y;
950 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); 950 gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y);
951 moveItem->resize(mGridSpacingX * moveItem->cellWidth(), 951 moveItem->resize(mGridSpacingX * moveItem->cellWidth(),
952 mGridSpacingY * moveItem->cellHeight()); 952 mGridSpacingY * moveItem->cellHeight());
953 moveItem->raise(); 953 moveItem->raise();
954 moveChild(moveItem,x,y); 954 moveChild(moveItem,x,y);
955 moveItem = moveItem->nextMultiItem(); 955 moveItem = moveItem->nextMultiItem();
956 } 956 }
957 } else if (mActionType == RESIZETOP) { 957 } else if (mActionType == RESIZETOP) {
958 if (mCurrentCellY <= mActionItem->cellYBottom()) { 958 if (mCurrentCellY <= mActionItem->cellYBottom()) {
959 mActionItem->expandTop(gy - mCurrentCellY); 959 mActionItem->expandTop(gy - mCurrentCellY);
960 mActionItem->resize(mActionItem->width(), 960 mActionItem->resize(mActionItem->width(),
961 mGridSpacingY * mActionItem->cellHeight()); 961 mGridSpacingY * mActionItem->cellHeight());
962 int x,y; 962 int x,y;
963 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); 963 gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y);
964 //moveChild(mActionItem,childX(mActionItem),y); 964 //moveChild(mActionItem,childX(mActionItem),y);
965 QScrollView::moveChild( mActionItem,childX(mActionItem),y ); 965 QScrollView::moveChild( mActionItem,childX(mActionItem),y );
966 } 966 }
967 } else if (mActionType == RESIZEBOTTOM) { 967 } else if (mActionType == RESIZEBOTTOM) {
968 if (mCurrentCellY >= mActionItem->cellYTop()) { 968 if (mCurrentCellY >= mActionItem->cellYTop()) {
969 mActionItem->expandBottom(gy - mCurrentCellY); 969 mActionItem->expandBottom(gy - mCurrentCellY);
970 mActionItem->resize(mActionItem->width(), 970 mActionItem->resize(mActionItem->width(),
971 mGridSpacingY * mActionItem->cellHeight()); 971 mGridSpacingY * mActionItem->cellHeight());
972 } 972 }
973 } else if (mActionType == RESIZELEFT) { 973 } else if (mActionType == RESIZELEFT) {
974 if (mCurrentCellX <= mActionItem->cellXWidth()) { 974 if (mCurrentCellX <= mActionItem->cellXWidth()) {
975 mActionItem->expandLeft(gx - mCurrentCellX); 975 mActionItem->expandLeft(gx - mCurrentCellX);
976 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 976 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
977 mActionItem->height()); 977 mActionItem->height());
978 int x,y; 978 int x,y;
979 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); 979 gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y);
980 moveChild(mActionItem,x,childY(mActionItem)); 980 moveChild(mActionItem,x,childY(mActionItem));
981 } 981 }
982 } else if (mActionType == RESIZERIGHT) { 982 } else if (mActionType == RESIZERIGHT) {
983 if (mCurrentCellX >= mActionItem->cellX()) { 983 if (mCurrentCellX >= mActionItem->cellX()) {
984 mActionItem->expandRight(gx - mCurrentCellX); 984 mActionItem->expandRight(gx - mCurrentCellX);
985 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), 985 mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(),
986 mActionItem->height()); 986 mActionItem->height());
987 } 987 }
988 } 988 }
989 mCurrentCellX = gx; 989 mCurrentCellX = gx;
990 mCurrentCellY = gy; 990 mCurrentCellY = gy;
991 } 991 }
992} 992}
993 993
994void KOAgenda::endItemAction() 994void KOAgenda::endItemAction()
995{ 995{
996 996
997 if ( mItemMoved ) { 997 if ( mItemMoved ) {
998 KOAgendaItem *placeItem = mActionItem->firstMultiItem(); 998 KOAgendaItem *placeItem = mActionItem->firstMultiItem();
999 if ( !placeItem ) { 999 if ( !placeItem ) {
1000 placeItem = mActionItem; 1000 placeItem = mActionItem;
1001 } 1001 }
1002 if ( placeItem->incidence()->recurrence()->doesRecur() ) { 1002 if ( placeItem->incidence()->recurrence()->doesRecur() ) {
1003 Incidence* oldInc = placeItem->incidence(); 1003 Incidence* oldInc = placeItem->incidence();
1004 placeItem->recreateIncidence(); 1004 placeItem->recreateIncidence();
1005 emit addToCalSignal(placeItem->incidence(), oldInc ); 1005 emit addToCalSignal(placeItem->incidence(), oldInc );
1006 } 1006 }
1007 int type = mActionType; 1007 int type = mActionType;
1008 if ( mAllDayMode ) 1008 if ( mAllDayMode )
1009 type = -1; 1009 type = -1;
1010 KOAgendaItem *modifiedItem = placeItem; 1010 KOAgendaItem *modifiedItem = placeItem;
1011 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); 1011 //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */);
1012 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); 1012 QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems();
1013 KOAgendaItem *item; 1013 KOAgendaItem *item;
1014 1014
1015 if ( placeItem->incidence()->typeID() == todoID ) { 1015 if ( placeItem->incidence()->typeID() == todoID ) {
1016 mSelectedItem = 0; 1016 mSelectedItem = 0;
1017 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); 1017 //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth());
1018 modifiedItem->mLastMoveXPos = mCurrentCellX; 1018 modifiedItem->mLastMoveXPos = mCurrentCellX;
1019 emit itemModified( modifiedItem, mActionType ); 1019 emit itemModified( modifiedItem, mActionType );
1020 } 1020 }
1021 else { 1021 else {
1022 1022
1023 1023
1024 globalFlagBlockAgendaItemPaint = 1; 1024 globalFlagBlockAgendaItemPaint = 1;
1025 for ( item=oldconflictItems.first(); item != 0; 1025 for ( item=oldconflictItems.first(); item != 0;
1026 item=oldconflictItems.next() ) { 1026 item=oldconflictItems.next() ) {
1027 placeSubCells(item); 1027 placeSubCells(item);
1028 } 1028 }
1029 while ( placeItem ) { 1029 while ( placeItem ) {
1030 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1030 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1031 oldconflictItems = placeItem->conflictItems(); 1031 oldconflictItems = placeItem->conflictItems();
1032 for ( item=oldconflictItems.first(); item != 0; 1032 for ( item=oldconflictItems.first(); item != 0;
1033 item=oldconflictItems.next() ) { 1033 item=oldconflictItems.next() ) {
1034 placeSubCells(item); 1034 placeSubCells(item);
1035 } 1035 }
1036 placeSubCells( placeItem ); 1036 placeSubCells( placeItem );
1037 placeItem = placeItem->nextMultiItem(); 1037 placeItem = placeItem->nextMultiItem();
1038 } 1038 }
1039 globalFlagBlockAgendaItemPaint = 0; 1039 globalFlagBlockAgendaItemPaint = 0;
1040 for ( item=oldconflictItems.first(); item != 0; 1040 for ( item=oldconflictItems.first(); item != 0;
1041 item=oldconflictItems.next() ) { 1041 item=oldconflictItems.next() ) {
1042 globalFlagBlockAgendaItemUpdate = 0; 1042 globalFlagBlockAgendaItemUpdate = 0;
1043 item->repaintMe(); 1043 item->repaintMe();
1044 globalFlagBlockAgendaItemUpdate = 1; 1044 globalFlagBlockAgendaItemUpdate = 1;
1045 item->repaint( false ); 1045 item->repaint( false );
1046 } 1046 }
1047 placeItem = modifiedItem; 1047 placeItem = modifiedItem;
1048 1048
1049 while ( placeItem ) { 1049 while ( placeItem ) {
1050 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); 1050 //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1());
1051 globalFlagBlockAgendaItemUpdate = 0; 1051 globalFlagBlockAgendaItemUpdate = 0;
1052 placeItem->repaintMe(); 1052 placeItem->repaintMe();
1053 globalFlagBlockAgendaItemUpdate = 1; 1053 globalFlagBlockAgendaItemUpdate = 1;
1054 placeItem->repaint(false); 1054 placeItem->repaint(false);
1055 placeItem = placeItem->nextMultiItem(); 1055 placeItem = placeItem->nextMultiItem();
1056 } 1056 }
1057 emit itemModified( modifiedItem, mActionType ); 1057 emit itemModified( modifiedItem, mActionType );
1058 1058
1059 1059
1060 placeItem = modifiedItem; 1060 placeItem = modifiedItem;
1061 while ( placeItem ) { 1061 while ( placeItem ) {
1062 oldconflictItems = placeItem->conflictItems(); 1062 oldconflictItems = placeItem->conflictItems();
1063 for ( item=oldconflictItems.first(); item != 0; 1063 for ( item=oldconflictItems.first(); item != 0;
1064 item=oldconflictItems.next() ) { 1064 item=oldconflictItems.next() ) {
1065 placeSubCells(item); 1065 placeSubCells(item);
1066 } 1066 }
1067 placeSubCells( placeItem ); 1067 placeSubCells( placeItem );
1068 placeItem = placeItem->nextMultiItem(); 1068 placeItem = placeItem->nextMultiItem();
1069 1069
1070 } 1070 }
1071 placeItem = modifiedItem; 1071 placeItem = modifiedItem;
1072 while ( placeItem ) { 1072 while ( placeItem ) {
1073 oldconflictItems = placeItem->conflictItems(); 1073 oldconflictItems = placeItem->conflictItems();
1074 for ( item=oldconflictItems.first(); item != 0; 1074 for ( item=oldconflictItems.first(); item != 0;
1075 item=oldconflictItems.next() ) { 1075 item=oldconflictItems.next() ) {
1076 globalFlagBlockAgendaItemUpdate = 0; 1076 globalFlagBlockAgendaItemUpdate = 0;
1077 item->repaintMe(); 1077 item->repaintMe();
1078 globalFlagBlockAgendaItemUpdate = 1; 1078 globalFlagBlockAgendaItemUpdate = 1;
1079 item->repaint(false); 1079 item->repaint(false);
1080 } 1080 }
1081 placeItem = placeItem->nextMultiItem(); 1081 placeItem = placeItem->nextMultiItem();
1082 } 1082 }
1083 /* 1083 /*
1084 1084
1085 oldconflictItems = modifiedItem->conflictItems(); 1085 oldconflictItems = modifiedItem->conflictItems();
1086 for ( item=oldconflictItems.first(); item != 0; 1086 for ( item=oldconflictItems.first(); item != 0;
1087 item=oldconflictItems.next() ) { 1087 item=oldconflictItems.next() ) {
1088 globalFlagBlockAgendaItemUpdate = 0; 1088 globalFlagBlockAgendaItemUpdate = 0;
1089 item->paintMe(false); 1089 item->paintMe(false);
1090 globalFlagBlockAgendaItemUpdate = 1; 1090 globalFlagBlockAgendaItemUpdate = 1;
1091 item->repaint(false); 1091 item->repaint(false);
1092 } 1092 }
1093 */ 1093 */
1094 1094
1095 1095
1096 } 1096 }
1097 1097
1098 } 1098 }
1099 if ( mActionItem ) 1099 if ( mActionItem )
1100 emit incidenceSelected( mActionItem->incidence() ); 1100 emit incidenceSelected( mActionItem->incidence() );
1101 mScrollUpTimer.stop(); 1101 mScrollUpTimer.stop();
1102 mScrollDownTimer.stop(); 1102 mScrollDownTimer.stop();
1103 setCursor( arrowCursor ); 1103 setCursor( arrowCursor );
1104 mActionItem = 0; 1104 mActionItem = 0;
1105 mActionType = NOP; 1105 mActionType = NOP;
1106 mItemMoved = 0; 1106 mItemMoved = 0;
1107 1107
1108} 1108}
1109 1109
1110void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) 1110void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos)
1111{ 1111{
1112// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; 1112// kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl;
1113// QPoint point = viewport()->mapToGlobal(viewportPos); 1113// QPoint point = viewport()->mapToGlobal(viewportPos);
1114// kdDebug() << "Global: " << point.x() << "," << point.y() << endl; 1114// kdDebug() << "Global: " << point.x() << "," << point.y() << endl;
1115// point = clipper()->mapFromGlobal(point); 1115// point = clipper()->mapFromGlobal(point);
1116// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; 1116// kdDebug() << "clipper: " << point.x() << "," << point.y() << endl;
1117 1117
1118 int x,y; 1118 int x,y;
1119 viewportToContents(viewportPos.x(),viewportPos.y(),x,y); 1119 viewportToContents(viewportPos.x(),viewportPos.y(),x,y);
1120// kdDebug() << "contents: " << x << "," << y << "\n" << endl; 1120// kdDebug() << "contents: " << x << "," << y << "\n" << endl;
1121 int gx,gy; 1121 int gx,gy;
1122 contentsToGrid(x,y,gx,gy); 1122 contentsToGrid(x,y,gx,gy);
1123 1123
1124 // Change cursor to resize cursor if appropriate 1124 // Change cursor to resize cursor if appropriate
1125 if (mAllDayMode) { 1125 if (mAllDayMode) {
1126 int gridDistanceX = (x - gx * mGridSpacingX); 1126 int gridDistanceX = (x - gx * mGridSpacingX);
1127 if (gridDistanceX < mResizeBorderWidth && 1127 if (gridDistanceX < mResizeBorderWidth &&
1128 moveItem->cellX() == gx) { 1128 moveItem->cellX() == gx) {
1129 setCursor(sizeHorCursor); 1129 setCursor(sizeHorCursor);
1130 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && 1130 } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth &&
1131 moveItem->cellXWidth() == gx) { 1131 moveItem->cellXWidth() == gx) {
1132 setCursor(sizeHorCursor); 1132 setCursor(sizeHorCursor);
1133 } else { 1133 } else {
1134 setCursor(arrowCursor); 1134 setCursor(arrowCursor);
1135 } 1135 }
1136 } else { 1136 } else {
1137 int gridDistanceY = (y - gy * mGridSpacingY); 1137 int gridDistanceY = (y - gy * mGridSpacingY);
1138 if (gridDistanceY < mResizeBorderWidth && 1138 if (gridDistanceY < mResizeBorderWidth &&
1139 moveItem->cellYTop() == gy && 1139 moveItem->cellYTop() == gy &&
1140 !moveItem->firstMultiItem()) { 1140 !moveItem->firstMultiItem()) {
1141 setCursor(sizeVerCursor); 1141 setCursor(sizeVerCursor);
1142 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && 1142 } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth &&
1143 moveItem->cellYBottom() == gy && 1143 moveItem->cellYBottom() == gy &&
1144 !moveItem->lastMultiItem()) { 1144 !moveItem->lastMultiItem()) {
1145 setCursor(sizeVerCursor); 1145 setCursor(sizeVerCursor);
1146 } else { 1146 } else {
1147 setCursor(arrowCursor); 1147 setCursor(arrowCursor);
1148 } 1148 }
1149 } 1149 }
1150} 1150}
1151 1151
1152 1152
1153/* 1153/*
1154 Place item in cell and take care that multiple items using the same cell do 1154 Place item in cell and take care that multiple items using the same cell do
1155 not overlap. This method is not yet optimal. It doesn´t use the maximum space 1155 not overlap. This method is not yet optimal. It doesn´t use the maximum space
1156 it can get in all cases. 1156 it can get in all cases.
1157 At the moment the method has a bug: When an item is placed only the sub cell 1157 At the moment the method has a bug: When an item is placed only the sub cell
1158 widths of the items are changed, which are within the Y region the item to 1158 widths of the items are changed, which are within the Y region the item to
1159 place spans. When the sub cell width change of one of this items affects a 1159 place spans. When the sub cell width change of one of this items affects a
1160 cell, where other items are, which do not overlap in Y with the item to place, 1160 cell, where other items are, which do not overlap in Y with the item to place,
1161 the display gets corrupted, although the corruption looks quite nice. 1161 the display gets corrupted, although the corruption looks quite nice.
1162*/ 1162*/
1163void KOAgenda::placeSubCells(KOAgendaItem *placeItem) 1163void KOAgenda::placeSubCells(KOAgendaItem *placeItem)
1164{ 1164{
1165 1165
1166 QPtrList<KOAgendaItem> conflictItems; 1166 QPtrList<KOAgendaItem> conflictItems;
1167 int maxSubCells = 0; 1167 int maxSubCells = 0;
1168 QIntDict<KOAgendaItem> subCellDict(7); 1168 QIntDict<KOAgendaItem> subCellDict(7);
1169 1169
1170 KOAgendaItem *item; 1170 KOAgendaItem *item;
1171 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1171 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1172 if (item != placeItem) { 1172 if (item != placeItem) {
1173 if (placeItem->cellX() <= item->cellXWidth() && 1173 if (placeItem->cellX() <= item->cellXWidth() &&
1174 placeItem->cellXWidth() >= item->cellX()) { 1174 placeItem->cellXWidth() >= item->cellX()) {
1175 if ((placeItem->cellYTop() <= item->cellYBottom()) && 1175 if ((placeItem->cellYTop() <= item->cellYBottom()) &&
1176 (placeItem->cellYBottom() >= item->cellYTop())) { 1176 (placeItem->cellYBottom() >= item->cellYTop())) {
1177 conflictItems.append(item); 1177 conflictItems.append(item);
1178 if (item->subCells() > maxSubCells) 1178 if (item->subCells() > maxSubCells)
1179 maxSubCells = item->subCells(); 1179 maxSubCells = item->subCells();
1180 subCellDict.insert(item->subCell(),item); 1180 subCellDict.insert(item->subCell(),item);
1181 } 1181 }
1182 } 1182 }
1183 } 1183 }
1184 } 1184 }
1185 1185
1186 if (conflictItems.count() > 0) { 1186 if (conflictItems.count() > 0) {
1187 // Look for unused sub cell and insert item 1187 // Look for unused sub cell and insert item
1188 int i; 1188 int i;
1189 for(i=0;i<maxSubCells;++i) { 1189 for(i=0;i<maxSubCells;++i) {
1190 if (!subCellDict.find(i)) { 1190 if (!subCellDict.find(i)) {
1191 placeItem->setSubCell(i); 1191 placeItem->setSubCell(i);
1192 break; 1192 break;
1193 } 1193 }
1194 } 1194 }
1195 if (i == maxSubCells) { 1195 if (i == maxSubCells) {
1196 placeItem->setSubCell(maxSubCells); 1196 placeItem->setSubCell(maxSubCells);
1197 maxSubCells++; // add new item to number of sub cells 1197 maxSubCells++; // add new item to number of sub cells
1198 } 1198 }
1199 1199
1200 // Prepare for sub cell geometry adjustment 1200 // Prepare for sub cell geometry adjustment
1201 int newSubCellWidth; 1201 int newSubCellWidth;
1202 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; 1202 if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells;
1203 else newSubCellWidth = mGridSpacingX / maxSubCells; 1203 else newSubCellWidth = mGridSpacingX / maxSubCells;
1204 conflictItems.append(placeItem); 1204 conflictItems.append(placeItem);
1205 1205
1206 1206
1207 // Adjust sub cell geometry of all direct conflict items 1207 // Adjust sub cell geometry of all direct conflict items
1208 for ( item=conflictItems.first(); item != 0; 1208 for ( item=conflictItems.first(); item != 0;
1209 item=conflictItems.next() ) { 1209 item=conflictItems.next() ) {
1210 item->setSubCells(maxSubCells); 1210 item->setSubCells(maxSubCells);
1211 if (mAllDayMode) { 1211 if (mAllDayMode) {
1212 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1212 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1213 } else { 1213 } else {
1214 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1214 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1215 } 1215 }
1216 int x,y; 1216 int x,y;
1217 gridToContents(item->cellX(),item->cellYTop(),x,y); 1217 gridToContents(item->cellX(),item->cellYTop(),x,y);
1218 if (mAllDayMode) { 1218 if (mAllDayMode) {
1219 y += item->subCell() * newSubCellWidth; 1219 y += item->subCell() * newSubCellWidth;
1220 } else { 1220 } else {
1221 x += item->subCell() * newSubCellWidth; 1221 x += item->subCell() * newSubCellWidth;
1222 } 1222 }
1223 moveChild(item,x,y); 1223 moveChild(item,x,y);
1224 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); 1224 // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y);
1225 //item->updateItem(); 1225 //item->updateItem();
1226 } 1226 }
1227 // Adjust sub cell geometry of all conflict items of all conflict items 1227 // Adjust sub cell geometry of all conflict items of all conflict items
1228 for ( item=conflictItems.first(); item != 0; 1228 for ( item=conflictItems.first(); item != 0;
1229 item=conflictItems.next() ) { 1229 item=conflictItems.next() ) {
1230 if ( placeItem != item ) { 1230 if ( placeItem != item ) {
1231 KOAgendaItem *item2; 1231 KOAgendaItem *item2;
1232 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); 1232 QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems();
1233 for ( item2=conflictItems2.first(); item2 != 0; 1233 for ( item2=conflictItems2.first(); item2 != 0;
1234 item2=conflictItems2.next() ) { 1234 item2=conflictItems2.next() ) {
1235 if ( item2->subCells() != maxSubCells) { 1235 if ( item2->subCells() != maxSubCells) {
1236 item2->setSubCells(maxSubCells); 1236 item2->setSubCells(maxSubCells);
1237 if (mAllDayMode) { 1237 if (mAllDayMode) {
1238 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); 1238 item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth);
1239 } else { 1239 } else {
1240 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); 1240 item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY);
1241 } 1241 }
1242 int x,y; 1242 int x,y;
1243 gridToContents(item2->cellX(),item2->cellYTop(),x,y); 1243 gridToContents(item2->cellX(),item2->cellYTop(),x,y);
1244 if (mAllDayMode) { 1244 if (mAllDayMode) {
1245 y += item2->subCell() * newSubCellWidth; 1245 y += item2->subCell() * newSubCellWidth;
1246 } else { 1246 } else {
1247 x += item2->subCell() * newSubCellWidth; 1247 x += item2->subCell() * newSubCellWidth;
1248 } 1248 }
1249 moveChild(item2,x,y); 1249 moveChild(item2,x,y);
1250 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); 1250 //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() );
1251 } 1251 }
1252 } 1252 }
1253 } 1253 }
1254 } 1254 }
1255 } else { 1255 } else {
1256 placeItem->setSubCell(0); 1256 placeItem->setSubCell(0);
1257 placeItem->setSubCells(1); 1257 placeItem->setSubCells(1);
1258 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); 1258 if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY);
1259 else placeItem->resize(mGridSpacingX,placeItem->height()); 1259 else placeItem->resize(mGridSpacingX,placeItem->height());
1260 int x,y; 1260 int x,y;
1261 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); 1261 gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y);
1262 moveChild(placeItem,x,y); 1262 moveChild(placeItem,x,y);
1263 } 1263 }
1264 placeItem->setConflictItems(conflictItems); 1264 placeItem->setConflictItems(conflictItems);
1265 // for ( item=conflictItems.first(); item != 0; 1265 // for ( item=conflictItems.first(); item != 0;
1266// item=conflictItems.next() ) { 1266// item=conflictItems.next() ) {
1267// //item->updateItem(); 1267// //item->updateItem();
1268// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); 1268// //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() );
1269// } 1269// }
1270// placeItem->updateItem(); 1270// placeItem->updateItem();
1271} 1271}
1272 1272
1273void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) 1273void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
1274{ 1274{
1275 if ( globalFlagBlockAgenda ) 1275 if ( globalFlagBlockAgenda )
1276 return; 1276 return;
1277 1277
1278 if ( mInvalidPixmap ) { 1278 if ( mInvalidPixmap ) {
1279 mInvalidPixmap = false; 1279 mInvalidPixmap = false;
1280 qDebug("KO: Upsizing Pixmaps "); 1280 qDebug("KO: Upsizing Pixmaps ");
1281 computeSizes(); 1281 computeSizes();
1282 emit updateViewSignal(); 1282 emit updateViewSignal();
1283 return; 1283 return;
1284 } 1284 }
1285 if ( ! mAllDayMode ) { 1285 if ( ! mAllDayMode ) {
1286 // currently not working for 1286 // currently not working for
1287 1287
1288 //qDebug("KOAgenda::drawContents "); 1288 //qDebug("KOAgenda::drawContents ");
1289#if 0 1289#if 0
1290 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) { 1290 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) {
1291 qDebug("WAU "); 1291 qDebug("WAU ");
1292 drawContentsToPainter(); 1292 drawContentsToPainter();
1293 } 1293 }
1294#endif 1294#endif
1295 QPaintDevice* pd = p->device(); 1295 QPaintDevice* pd = p->device();
1296 p->end(); 1296 p->end();
1297 int vx, vy; 1297 int vx, vy;
1298 int selectionX = KOGlobals::self()->reverseLayout() ? 1298 int selectionX = KOGlobals::self()->reverseLayout() ?
1299 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1299 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1300 mSelectionCellX * mGridSpacingX; 1300 mSelectionCellX * mGridSpacingX;
1301 contentsToViewport ( cx, cy, vx,vy); 1301 contentsToViewport ( cx, cy, vx,vy);
1302 //qDebug(" %d %d %d %d %d", cx, cy, cw,ch,mGridSpacingX-1) ; 1302 //qDebug(" %d %d %d %d %d", cx, cy, cw,ch,mGridSpacingX-1) ;
1303 1303
1304 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) { 1304 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) {
1305 if ( mGridSpacingX == cw && mSelectionHeight > 0 && ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1305 if ( mGridSpacingX == cw && mSelectionHeight > 0 && ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1306 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) ) { 1306 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) ) {
1307 1307
1308 int vxSel, vySel; 1308 int vxSel, vySel;
1309 contentsToViewport ( selectionX, mSelectionYTop, vxSel,vySel); 1309 contentsToViewport ( selectionX, mSelectionYTop, vxSel,vySel);
1310 int off = mSelectionHeight; 1310 int off = mSelectionHeight;
1311 if ( vySel < 0 ) 1311 if ( vySel < 0 )
1312 off += vySel; 1312 off += vySel;
1313 //qDebug("OFF %d %d %d", off,vySel, vy ); 1313 //qDebug("OFF %d %d %d", off,vySel, vy );
1314 bitBlt ( pd, vx, vy+off, &mPaintPixmap, cx, cy+off, cw , ch-off ,CopyROP); 1314 bitBlt ( pd, vx, vy+off, &mPaintPixmap, cx, cy+off, cw , ch-off ,CopyROP);
1315 } else { 1315 } else {
1316 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1316 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1317 } 1317 }
1318 } 1318 }
1319 if ( mSelectionHeight > 0 ) { 1319 if ( mSelectionHeight > 0 ) {
1320 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1320 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1321 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1321 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1322 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1322 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1323 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1323 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1324 // bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1324 // bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1325 int hei = mSelectionHeight; 1325 int hei = mSelectionHeight;
1326 int offset = 0; 1326 int offset = 0;
1327 while ( hei > 0 ) { 1327 while ( hei > 0 ) {
1328 int p_hei = 5; 1328 int p_hei = 5;
1329 if ( hei < 5 ) p_hei = hei; 1329 if ( hei < 5 ) p_hei = hei;
1330 hei -= 5; 1330 hei -= 5;
1331 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP); 1331 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP);
1332 offset += 5; 1332 offset += 5;
1333 } 1333 }
1334 } 1334 }
1335 } 1335 }
1336 p->begin( pd ); 1336 p->begin( pd );
1337 } else { 1337 } else {
1338#if 0 1338#if 0
1339 qDebug("mCurPixWid %d %d ",mCurPixWid, contentsWidth() ); 1339 qDebug("mCurPixWid %d %d ",mCurPixWid, contentsWidth() );
1340 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) { 1340 if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) {
1341 qDebug("WAUWAU "); 1341 qDebug("WAUWAU ");
1342 drawContentsToPainter(); 1342 drawContentsToPainter();
1343 } 1343 }
1344#endif 1344#endif
1345 QPaintDevice* pd = p->device(); 1345 QPaintDevice* pd = p->device();
1346 p->end(); 1346 p->end();
1347 int vx, vy; 1347 int vx, vy;
1348 int selectionX = KOGlobals::self()->reverseLayout() ? 1348 int selectionX = KOGlobals::self()->reverseLayout() ?
1349 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1349 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1350 mSelectionCellX * mGridSpacingX; 1350 mSelectionCellX * mGridSpacingX;
1351 contentsToViewport ( cx, cy, vx,vy); 1351 contentsToViewport ( cx, cy, vx,vy);
1352 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; 1352 // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ;
1353 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) 1353 if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) )
1354 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); 1354 bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP);
1355 1355
1356 if ( mSelectionHeight > 0 ) { 1356 if ( mSelectionHeight > 0 ) {
1357 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); 1357 //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight );
1358 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1358 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1359 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1359 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1360 contentsToViewport ( selectionX, mSelectionYTop, vx,vy); 1360 contentsToViewport ( selectionX, mSelectionYTop, vx,vy);
1361 //bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); 1361 //bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP);
1362 int hei = mSelectionHeight; 1362 int hei = mSelectionHeight;
1363 int offset = 0; 1363 int offset = 0;
1364 while ( hei > 0 ) { 1364 while ( hei > 0 ) {
1365 int p_hei = 5; 1365 int p_hei = 5;
1366 if ( hei < 5 ) p_hei = hei; 1366 if ( hei < 5 ) p_hei = hei;
1367 hei -= 5; 1367 hei -= 5;
1368 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP); 1368 bitBlt ( pd, vx+1, vy+offset, &mHighlightPixmap, 0, 0, mGridSpacingX-1, p_hei ,CopyROP);
1369 offset += 5; 1369 offset += 5;
1370 } 1370 }
1371 } 1371 }
1372 } 1372 }
1373 p->begin( pd ); 1373 p->begin( pd );
1374 } 1374 }
1375 1375
1376} 1376}
1377 1377
1378void KOAgenda::finishUpdate() 1378void KOAgenda::finishUpdate()
1379{ 1379{
1380 1380
1381 KOAgendaItem *item; 1381 KOAgendaItem *item;
1382 globalFlagBlockAgendaItemPaint = 1; 1382 globalFlagBlockAgendaItemPaint = 1;
1383 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems 1383 // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems
1384 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1384 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1385 if ( !item->checkLayout() ) { 1385 if ( !item->checkLayout() ) {
1386 //qDebug(" conflictitem found "); 1386 //qDebug(" conflictitem found ");
1387 int newSubCellWidth; 1387 int newSubCellWidth;
1388 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); 1388 if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells();
1389 else newSubCellWidth = mGridSpacingX / item->subCells(); 1389 else newSubCellWidth = mGridSpacingX / item->subCells();
1390 1390
1391 if (mAllDayMode) { 1391 if (mAllDayMode) {
1392 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); 1392 item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth);
1393 } else { 1393 } else {
1394 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); 1394 item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY);
1395 } 1395 }
1396 int x,y; 1396 int x,y;
1397 gridToContents(item->cellX(),item->cellYTop(),x,y); 1397 gridToContents(item->cellX(),item->cellYTop(),x,y);
1398 if (mAllDayMode) { 1398 if (mAllDayMode) {
1399 y += item->subCell() * newSubCellWidth; 1399 y += item->subCell() * newSubCellWidth;
1400 } else { 1400 } else {
1401 x += item->subCell() * newSubCellWidth; 1401 x += item->subCell() * newSubCellWidth;
1402 } 1402 }
1403 moveChild(item,x,y); 1403 moveChild(item,x,y);
1404 } 1404 }
1405 } 1405 }
1406 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1406 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1407 if ( !item->isVisible() ) 1407 if ( !item->isVisible() )
1408 item->show(); 1408 item->show();
1409 1409
1410 } 1410 }
1411 globalFlagBlockAgendaItemUpdate = 0; 1411 globalFlagBlockAgendaItemUpdate = 0;
1412 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1412 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1413 item->repaintMe( ); 1413 item->repaintMe( );
1414 } 1414 }
1415 globalFlagBlockAgendaItemUpdate = 1; 1415 globalFlagBlockAgendaItemUpdate = 1;
1416 qApp->processEvents(); 1416 qApp->processEvents();
1417 globalFlagBlockAgendaItemPaint = 0; 1417 globalFlagBlockAgendaItemPaint = 0;
1418 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1418 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1419 item->repaint( false ); 1419 item->repaint( false );
1420 } 1420 }
1421 marcus_bains(); 1421 marcus_bains();
1422} 1422}
1423 1423
1424/* 1424/*
1425 Draw grid in the background of the agenda. 1425 Draw grid in the background of the agenda.
1426*/ 1426*/
1427void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) 1427void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch)
1428{ 1428{
1429 1429
1430 1430
1431 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) 1431 if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask )
1432 return; 1432 return;
1433 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) 1433 if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 )
1434 return; 1434 return;
1435 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); 1435 int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight();
1436 if ( ch < 1 ) 1436 if ( ch < 1 )
1437 ch = 1; 1437 ch = 1;
1438 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { 1438 if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) {
1439 mPaintPixmap.resize( contentsWidth()+42, ch ); 1439 mPaintPixmap.resize( contentsWidth()+42, ch );
1440 } 1440 }
1441 mCurPixWid = contentsWidth(); 1441 mCurPixWid = contentsWidth();
1442 mCurPixHei = ch; 1442 mCurPixHei = ch;
1443 if ( mHighlightPixmap.width() < mGridSpacingX-1 ) { 1443 if ( mHighlightPixmap.width() < mGridSpacingX-1 ) {
1444 mHighlightPixmap.resize( mGridSpacingX-1, 5 ); 1444 mHighlightPixmap.resize( mGridSpacingX-1, 5 );
1445 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); 1445 mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor );
1446 } 1446 }
1447 mPixPainter.begin( &mPaintPixmap) ; 1447 mPixPainter.begin( &mPaintPixmap) ;
1448 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); 1448 //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() );
1449 QPainter * p ; 1449 QPainter * p ;
1450 if (paint == 0) { 1450 if (paint == 0) {
1451 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); 1451 mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor);
1452 p = &mPixPainter; 1452 p = &mPixPainter;
1453 } 1453 }
1454 else 1454 else
1455 p = paint ; 1455 p = paint ;
1456 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); 1456 // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch);
1457 1457
1458 //--cx;++cw; 1458 //--cx;++cw;
1459 int lGridSpacingY = mGridSpacingY*2; 1459 int lGridSpacingY = mGridSpacingY*2;
1460 int selDay; 1460 int selDay;
1461 QDate curDate = QDate::currentDate(); 1461 QDate curDate = QDate::currentDate();
1462 if ( !backgroundOnly ) { 1462 if ( !backgroundOnly ) {
1463 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 1463 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
1464 { 1464 {
1465 if ( mSelectedDates[selDay] == curDate && KOPrefs::instance()->mHighlightCurrentDay) { 1465 if ( mSelectedDates[selDay] == curDate && KOPrefs::instance()->mHighlightCurrentDay) {
1466 int x1 = cx; 1466 int x1 = cx;
1467 int y1 = 0; 1467 int y1 = 0;
1468 if (y1 < cy) y1 = cy; 1468 if (y1 < cy) y1 = cy;
1469 int x2 = cx+cw-1; 1469 int x2 = cx+cw-1;
1470 int y2 = contentsHeight(); 1470 int y2 = contentsHeight();
1471 if (y2 > cy+ch-1) y2=cy+ch-1; 1471 if (y2 > cy+ch-1) y2=cy+ch-1;
1472 if (x2 >= x1 && y2 >= y1) { 1472 if (x2 >= x1 && y2 >= y1) {
1473 int gxStart = selDay; 1473 int gxStart = selDay;
1474 int gxEnd = gxStart ; 1474 int gxEnd = gxStart ;
1475 int xStart = KOGlobals::self()->reverseLayout() ? 1475 int xStart = KOGlobals::self()->reverseLayout() ?
1476 (mColumns - 1 - gxStart)*mGridSpacingX : 1476 (mColumns - 1 - gxStart)*mGridSpacingX :
1477 gxStart*mGridSpacingX; 1477 gxStart*mGridSpacingX;
1478 if (xStart < x1) xStart = x1; 1478 if (xStart < x1) xStart = x1;
1479 int xEnd = KOGlobals::self()->reverseLayout() ? 1479 int xEnd = KOGlobals::self()->reverseLayout() ?
1480 (mColumns - gxStart)*mGridSpacingX-1 : 1480 (mColumns - gxStart)*mGridSpacingX-1 :
1481 (gxStart+1)*mGridSpacingX-1; 1481 (gxStart+1)*mGridSpacingX-1;
1482 if (xEnd > x2) xEnd = x2; 1482 if (xEnd > x2) xEnd = x2;
1483 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1483 if ( KOPrefs::instance()->mUseHighlightLightColor )
1484 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1484 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1485 KOPrefs::instance()->mAgendaBgColor.light()); 1485 KOPrefs::instance()->mAgendaBgColor.light());
1486 else 1486 else
1487 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1487 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1488 KOPrefs::instance()->mAgendaBgColor.dark()); 1488 KOPrefs::instance()->mAgendaBgColor.dark());
1489 1489
1490 } 1490 }
1491 } 1491 }
1492 } 1492 }
1493 } 1493 }
1494 // Highlight working hours 1494 // Highlight working hours
1495 1495
1496 if ( !backgroundOnly ) 1496 if ( !backgroundOnly )
1497 if (mWorkingHoursEnable) { 1497 if (mWorkingHoursEnable) {
1498 int x1 = cx; 1498 int x1 = cx;
1499 int y1 = mWorkingHoursYTop; 1499 int y1 = mWorkingHoursYTop;
1500 if (y1 < cy) y1 = cy; 1500 if (y1 < cy) y1 = cy;
1501 int x2 = cx+cw-1; 1501 int x2 = cx+cw-1;
1502 // int x2 = mGridSpacingX * 5 - 1; 1502 // int x2 = mGridSpacingX * 5 - 1;
1503 // if (x2 > cx+cw-1) x2 = cx + cw - 1; 1503 // if (x2 > cx+cw-1) x2 = cx + cw - 1;
1504 int y2 = mWorkingHoursYBottom; 1504 int y2 = mWorkingHoursYBottom;
1505 if (y2 > cy+ch-1) y2=cy+ch-1; 1505 if (y2 > cy+ch-1) y2=cy+ch-1;
1506 1506
1507 if (x2 >= x1 && y2 >= y1) { 1507 if (x2 >= x1 && y2 >= y1) {
1508 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); 1508 // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX );
1509 int gxStart = x1/mGridSpacingX; 1509 int gxStart = x1/mGridSpacingX;
1510 int gxEnd = x2/mGridSpacingX; 1510 int gxEnd = x2/mGridSpacingX;
1511 while(gxStart <= gxEnd) { 1511 while(gxStart <= gxEnd) {
1512 if (gxStart < int(mHolidayMask->count()) && 1512 if (gxStart < int(mHolidayMask->count()) &&
1513 !mHolidayMask->at(gxStart)) { 1513 !mHolidayMask->at(gxStart)) {
1514 int xStart = KOGlobals::self()->reverseLayout() ? 1514 int xStart = KOGlobals::self()->reverseLayout() ?
1515 (mColumns - 1 - gxStart)*mGridSpacingX : 1515 (mColumns - 1 - gxStart)*mGridSpacingX :
1516 gxStart*mGridSpacingX; 1516 gxStart*mGridSpacingX;
1517 if (xStart < x1) xStart = x1; 1517 if (xStart < x1) xStart = x1;
1518 int xEnd = KOGlobals::self()->reverseLayout() ? 1518 int xEnd = KOGlobals::self()->reverseLayout() ?
1519 (mColumns - gxStart)*mGridSpacingX-1 : 1519 (mColumns - gxStart)*mGridSpacingX-1 :
1520 (gxStart+1)*mGridSpacingX-1; 1520 (gxStart+1)*mGridSpacingX-1;
1521 if (xEnd > x2) xEnd = x2; 1521 if (xEnd > x2) xEnd = x2;
1522 if ( mSelectedDates[gxStart] == curDate && KOPrefs::instance()->mHighlightCurrentDay ) { 1522 if ( mSelectedDates[gxStart] == curDate && KOPrefs::instance()->mHighlightCurrentDay ) {
1523 if ( KOPrefs::instance()->mUseHighlightLightColor ) 1523 if ( KOPrefs::instance()->mUseHighlightLightColor )
1524 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1524 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1525 KOPrefs::instance()->mWorkingHoursColor.light()); 1525 KOPrefs::instance()->mWorkingHoursColor.light());
1526 else 1526 else
1527 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1527 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1528 KOPrefs::instance()->mWorkingHoursColor.dark()); 1528 KOPrefs::instance()->mWorkingHoursColor.dark());
1529 } else { 1529 } else {
1530 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, 1530 p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1,
1531 KOPrefs::instance()->mWorkingHoursColor); 1531 KOPrefs::instance()->mWorkingHoursColor);
1532 } 1532 }
1533 } 1533 }
1534 ++gxStart; 1534 ++gxStart;
1535 } 1535 }
1536 } 1536 }
1537 } 1537 }
1538 /* 1538 /*
1539 int selectionX = KOGlobals::self()->reverseLayout() ? 1539 int selectionX = KOGlobals::self()->reverseLayout() ?
1540 (mColumns - 1 - mSelectionCellX) * mGridSpacingX : 1540 (mColumns - 1 - mSelectionCellX) * mGridSpacingX :
1541 mSelectionCellX * mGridSpacingX; 1541 mSelectionCellX * mGridSpacingX;
1542 1542
1543 // Draw selection 1543 // Draw selection
1544 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && 1544 if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) &&
1545 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { 1545 ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) {
1546 // TODO: paint only part within cx,cy,cw,ch 1546 // TODO: paint only part within cx,cy,cw,ch
1547 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, 1547 p->fillRect( selectionX, mSelectionYTop, mGridSpacingX,
1548 mSelectionHeight, KOPrefs::instance()->mHighlightColor ); 1548 mSelectionHeight, KOPrefs::instance()->mHighlightColor );
1549 } 1549 }
1550 */ 1550 */
1551 // Draw vertical lines of grid 1551 // Draw vertical lines of grid
1552 1552
1553 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; 1553 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
1554 if ( mGridSpacingX > 0 ) { 1554 if ( mGridSpacingX > 0 ) {
1555 while (x < cx + cw) { 1555 while (x < cx + cw) {
1556 p->drawLine(x,cy,x,cy+ch); 1556 p->drawLine(x,cy,x,cy+ch);
1557 x+=mGridSpacingX; 1557 x+=mGridSpacingX;
1558 } 1558 }
1559 } 1559 }
1560 // Draw horizontal lines of grid 1560 // Draw horizontal lines of grid
1561 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; 1561 int y = ((int)(cy/lGridSpacingY))*lGridSpacingY;
1562 if ( lGridSpacingY > 0 ) { 1562 if ( lGridSpacingY > 0 ) {
1563 while (y < cy + ch) { 1563 while (y < cy + ch) {
1564 p->setPen( SolidLine ); 1564 p->setPen( SolidLine );
1565 p->drawLine(cx,y,cx+cw,y); 1565 p->drawLine(cx,y,cx+cw,y);
1566 y+=lGridSpacingY; 1566 y+=lGridSpacingY;
1567 p->setPen( DotLine ); 1567 p->setPen( DotLine );
1568 p->drawLine(cx,y,cx+cw,y); 1568 p->drawLine(cx,y,cx+cw,y);
1569 y+=lGridSpacingY; 1569 y+=lGridSpacingY;
1570 } 1570 }
1571 p->setPen( SolidLine ); 1571 p->setPen( SolidLine );
1572 } 1572 }
1573 mPixPainter.end() ; 1573 mPixPainter.end() ;
1574} 1574}
1575 1575
1576/* 1576/*
1577 Convert srcollview contents coordinates to agenda grid coordinates. 1577 Convert srcollview contents coordinates to agenda grid coordinates.
1578*/ 1578*/
1579void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) 1579void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy)
1580{ 1580{
1581 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : 1581 gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX :
1582 x/mGridSpacingX; 1582 x/mGridSpacingX;
1583 gy = y/mGridSpacingY; 1583 gy = y/mGridSpacingY;
1584} 1584}
1585 1585
1586/* 1586/*
1587 Convert agenda grid coordinates to scrollview contents coordinates. 1587 Convert agenda grid coordinates to scrollview contents coordinates.
1588*/ 1588*/
1589void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) 1589void KOAgenda::gridToContents (int gx, int gy, int& x, int& y)
1590{ 1590{
1591 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: 1591 x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX:
1592 gx*mGridSpacingX; 1592 gx*mGridSpacingX;
1593 y = gy*mGridSpacingY; 1593 y = gy*mGridSpacingY;
1594} 1594}
1595 1595
1596 1596
1597/* 1597/*
1598 Return Y coordinate corresponding to time. Coordinates are rounded to fit into 1598 Return Y coordinate corresponding to time. Coordinates are rounded to fit into
1599 the grid. 1599 the grid.
1600*/ 1600*/
1601int KOAgenda::timeToY(const QTime &time) 1601int KOAgenda::timeToY(const QTime &time)
1602{ 1602{
1603 int minutesPerCell = 24 * 60 / mRows; 1603 int minutesPerCell = 24 * 60 / mRows;
1604 int timeMinutes = time.hour() * 60 + time.minute(); 1604 int timeMinutes = time.hour() * 60 + time.minute();
1605 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; 1605 int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell;
1606 return Y; 1606 return Y;
1607} 1607}
1608 1608
1609 1609
1610/* 1610/*
1611 Return time corresponding to cell y coordinate. Coordinates are rounded to 1611 Return time corresponding to cell y coordinate. Coordinates are rounded to
1612 fit into the grid. 1612 fit into the grid.
1613*/ 1613*/
1614QTime KOAgenda::gyToTime(int gy) 1614QTime KOAgenda::gyToTime(int gy)
1615{ 1615{
1616 1616
1617 int secondsPerCell = 24 * 60 * 60/ mRows; 1617 int secondsPerCell = 24 * 60 * 60/ mRows;
1618 1618
1619 int timeSeconds = secondsPerCell * gy; 1619 int timeSeconds = secondsPerCell * gy;
1620 1620
1621 QTime time( 0, 0, 0 ); 1621 QTime time( 0, 0, 0 );
1622 if ( timeSeconds < 24 * 60 * 60 ) { 1622 if ( timeSeconds < 24 * 60 * 60 ) {
1623 time = time.addSecs(timeSeconds); 1623 time = time.addSecs(timeSeconds);
1624 } else { 1624 } else {
1625 time.setHMS( 23, 59, 59 ); 1625 time.setHMS( 23, 59, 59 );
1626 } 1626 }
1627 1627
1628 return time; 1628 return time;
1629} 1629}
1630 1630
1631void KOAgenda::setStartHour(int startHour) 1631void KOAgenda::setStartHour(int startHour)
1632{ 1632{
1633 int startCell = startHour * mRows / 24; 1633 int startCell = startHour * mRows / 24;
1634 setContentsPos(0,startCell * gridSpacingY()); 1634 setContentsPos(0,startCell * gridSpacingY());
1635} 1635}
1636QTime KOAgenda::getEndTime()
1637{
1638 return QTime ( (contentsY ()+viewport()->height())*24/contentsHeight ()+1,0,0);
1639}
1636void KOAgenda::hideUnused() 1640void KOAgenda::hideUnused()
1637{ 1641{
1638 // experimental only 1642 // experimental only
1639 // return; 1643 // return;
1640 KOAgendaItem *item; 1644 KOAgendaItem *item;
1641 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { 1645 for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) {
1642 item->hide(); 1646 item->hide();
1643 } 1647 }
1644} 1648}
1645 1649
1646 1650
1647KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) 1651KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view)
1648{ 1652{
1649 1653
1650 KOAgendaItem *fi; 1654 KOAgendaItem *fi;
1651 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { 1655 for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) {
1652 if ( fi->incidence() == event ) { 1656 if ( fi->incidence() == event ) {
1653 mUnusedItems.remove(); 1657 mUnusedItems.remove();
1654 fi->init( event, qd ); 1658 fi->init( event, qd );
1655 return fi; 1659 return fi;
1656 } 1660 }
1657 } 1661 }
1658 fi=mUnusedItems.first(); 1662 fi=mUnusedItems.first();
1659 if ( fi ) { 1663 if ( fi ) {
1660 mUnusedItems.remove(); 1664 mUnusedItems.remove();
1661 fi->init( event, qd ); 1665 fi->init( event, qd );
1662 return fi; 1666 return fi;
1663 } 1667 }
1664 // qDebug("new KOAgendaItem "); 1668 // qDebug("new KOAgendaItem ");
1665 1669
1666 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); 1670 KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode );
1667 agendaItem->installEventFilter(this); 1671 agendaItem->installEventFilter(this);
1668 addChild(agendaItem,0,0); 1672 addChild(agendaItem,0,0);
1669 return agendaItem; 1673 return agendaItem;
1670} 1674}
1671KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) 1675KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo )
1672{ 1676{
1673 KOAgendaItem *item; 1677 KOAgendaItem *item;
1674 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1678 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1675 if ( item->incidence() == todo ) { 1679 if ( item->incidence() == todo ) {
1676 mItems.remove(); 1680 mItems.remove();
1677 return item; 1681 return item;
1678 } 1682 }
1679 } 1683 }
1680 return 0; 1684 return 0;
1681} 1685}
1682 1686
1683 1687
1684void KOAgenda::updateTodo( Todo * todo, int days, bool remove) 1688void KOAgenda::updateTodo( Todo * todo, int days, bool remove)
1685{ 1689{
1686 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| 1690 // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )||
1687 KOAgendaItem *item; 1691 KOAgendaItem *item;
1688 item = getItemForTodo ( todo ); 1692 item = getItemForTodo ( todo );
1689 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); 1693 //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove);
1690 if ( item ) { 1694 if ( item ) {
1691 blockSignals( true ); 1695 blockSignals( true );
1692 //qDebug("item found "); 1696 //qDebug("item found ");
1693 item->hide(); 1697 item->hide();
1694 item->setCellX(-2, -1 ); 1698 item->setCellX(-2, -1 );
1695 item->select(false); 1699 item->select(false);
1696 mUnusedItems.append( item ); 1700 mUnusedItems.append( item );
1697 mItems.remove( item ); 1701 mItems.remove( item );
1698 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1702 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1699 KOAgendaItem *itemit; 1703 KOAgendaItem *itemit;
1700 //globalFlagBlockAgendaItemPaint = 1; 1704 //globalFlagBlockAgendaItemPaint = 1;
1701 for ( itemit=oldconflictItems.first(); itemit != 0; 1705 for ( itemit=oldconflictItems.first(); itemit != 0;
1702 itemit=oldconflictItems.next() ) { 1706 itemit=oldconflictItems.next() ) {
1703 if ( itemit != item ) 1707 if ( itemit != item )
1704 placeSubCells(itemit); 1708 placeSubCells(itemit);
1705 } 1709 }
1706 qApp->processEvents(); 1710 qApp->processEvents();
1707 //globalFlagBlockAgendaItemPaint = 0; 1711 //globalFlagBlockAgendaItemPaint = 0;
1708 for ( itemit=oldconflictItems.first(); itemit != 0; 1712 for ( itemit=oldconflictItems.first(); itemit != 0;
1709 itemit=oldconflictItems.next() ) { 1713 itemit=oldconflictItems.next() ) {
1710 globalFlagBlockAgendaItemUpdate = 0; 1714 globalFlagBlockAgendaItemUpdate = 0;
1711 if ( itemit != item ) 1715 if ( itemit != item )
1712 itemit->repaintMe(); 1716 itemit->repaintMe();
1713 globalFlagBlockAgendaItemUpdate = 1; 1717 globalFlagBlockAgendaItemUpdate = 1;
1714 //qDebug("sigleshot "); 1718 //qDebug("sigleshot ");
1715 QTimer::singleShot( 0, itemit, SLOT ( repaintItem() )); 1719 QTimer::singleShot( 0, itemit, SLOT ( repaintItem() ));
1716 //itemit->repaint( false ); repaintItem() 1720 //itemit->repaint( false ); repaintItem()
1717 } 1721 }
1718 blockSignals( false ); 1722 blockSignals( false );
1719 } 1723 }
1720 if ( remove ) { 1724 if ( remove ) {
1721 //qDebug("remove****************************************** "); 1725 //qDebug("remove****************************************** ");
1722 return; 1726 return;
1723 } 1727 }
1724 if ( todo->hasCompletedDate() && !KOPrefs::instance()->mShowCompletedTodoInAgenda ) 1728 if ( todo->hasCompletedDate() && !KOPrefs::instance()->mShowCompletedTodoInAgenda )
1725 return; 1729 return;
1726 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); 1730 //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ ");
1727 QDate currentDate = QDate::currentDate(); 1731 QDate currentDate = QDate::currentDate();
1728 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < currentDate)&& ( KOPrefs::instance()->mShowTodoInAgenda ); 1732 bool overdue = (!todo->isCompleted()) && (todo->dtDue() < currentDate)&& ( KOPrefs::instance()->mShowTodoInAgenda );
1729 QDateTime dt; 1733 QDateTime dt;
1730 if ( todo->hasCompletedDate() ) 1734 if ( todo->hasCompletedDate() )
1731 dt = todo->completed(); 1735 dt = todo->completed();
1732 else 1736 else
1733 dt = todo->dtDue(); 1737 dt = todo->dtDue();
1734 if ( overdue ) { 1738 if ( overdue ) {
1735 days += todo->dtDue().date().daysTo( currentDate ); 1739 days += todo->dtDue().date().daysTo( currentDate );
1736 } 1740 }
1737 else 1741 else
1738 currentDate = dt.date(); 1742 currentDate = dt.date();
1739 1743
1740 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { 1744 if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) {
1741 if ( ! mAllDayMode ) return; 1745 if ( ! mAllDayMode ) return;
1742 // aldayagenda 1746 // aldayagenda
1743 globalFlagBlockAgendaItemPaint = 1; 1747 globalFlagBlockAgendaItemPaint = 1;
1744 item = insertAllDayItem(todo, currentDate,days, days); 1748 item = insertAllDayItem(todo, currentDate,days, days);
1745 item->show(); 1749 item->show();
1746 1750
1747 } 1751 }
1748 else { 1752 else {
1749 if ( mAllDayMode ) return; 1753 if ( mAllDayMode ) return;
1750 // mAgenda 1754 // mAgenda
1751 globalFlagBlockAgendaItemPaint = 1; 1755 globalFlagBlockAgendaItemPaint = 1;
1752 int endY = timeToY(dt.time()) - 1; 1756 int endY = timeToY(dt.time()) - 1;
1753 int hi = 12/KOPrefs::instance()->mHourSize; 1757 int hi = 12/KOPrefs::instance()->mHourSize;
1754 int startY = endY - 1-hi; 1758 int startY = endY - 1-hi;
1755 item = insertItem(todo,currentDate,days,startY,endY); 1759 item = insertItem(todo,currentDate,days,startY,endY);
1756 item->show(); 1760 item->show();
1757 } 1761 }
1758 qApp->processEvents(); 1762 qApp->processEvents();
1759 globalFlagBlockAgendaItemPaint = 0; 1763 globalFlagBlockAgendaItemPaint = 0;
1760 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); 1764 QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems();
1761 KOAgendaItem *itemit; 1765 KOAgendaItem *itemit;
1762 for ( itemit=oldconflictItems.first(); itemit != 0; 1766 for ( itemit=oldconflictItems.first(); itemit != 0;
1763 itemit=oldconflictItems.next() ) { 1767 itemit=oldconflictItems.next() ) {
1764 globalFlagBlockAgendaItemUpdate = 0; 1768 globalFlagBlockAgendaItemUpdate = 0;
1765 itemit->repaintMe(); 1769 itemit->repaintMe();
1766 globalFlagBlockAgendaItemUpdate = 1; 1770 globalFlagBlockAgendaItemUpdate = 1;
1767 itemit->repaint(); 1771 itemit->repaint();
1768 } 1772 }
1769 globalFlagBlockAgendaItemUpdate = 0; 1773 globalFlagBlockAgendaItemUpdate = 0;
1770 item->repaintMe(); 1774 item->repaintMe();
1771 globalFlagBlockAgendaItemUpdate = 1; 1775 globalFlagBlockAgendaItemUpdate = 1;
1772 item->repaint(); 1776 item->repaint();
1773} 1777}
1774/* 1778/*
1775 Insert KOAgendaItem into agenda. 1779 Insert KOAgendaItem into agenda.
1776*/ 1780*/
1777KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) 1781KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom)
1778{ 1782{
1779 if (mAllDayMode) { 1783 if (mAllDayMode) {
1780 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. "); 1784 qDebug("KOAgenda: calling insertItem in all-day mode is illegal. ");
1781 return 0; 1785 return 0;
1782 } 1786 }
1783 1787
1784 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1788 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1785 //agendaItem->setFrameStyle(WinPanel|Raised); 1789 //agendaItem->setFrameStyle(WinPanel|Raised);
1786 1790
1787 int YSize = YBottom - YTop + 1; 1791 int YSize = YBottom - YTop + 1;
1788 if (YSize < 0) { 1792 if (YSize < 0) {
1789 YSize = 1; 1793 YSize = 1;
1790 } 1794 }
1791 int iheight = mGridSpacingY * YSize; 1795 int iheight = mGridSpacingY * YSize;
1792 1796
1793 agendaItem->resize(mGridSpacingX,iheight ); 1797 agendaItem->resize(mGridSpacingX,iheight );
1794 agendaItem->setCellXY(X,YTop,YBottom); 1798 agendaItem->setCellXY(X,YTop,YBottom);
1795 agendaItem->setCellXWidth(X); 1799 agendaItem->setCellXWidth(X);
1796 1800
1797 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); 1801 //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY);
1798 mItems.append(agendaItem); 1802 mItems.append(agendaItem);
1799 1803
1800 placeSubCells(agendaItem); 1804 placeSubCells(agendaItem);
1801 1805
1802 //agendaItem->show(); 1806 //agendaItem->show();
1803 1807
1804 1808
1805 return agendaItem; 1809 return agendaItem;
1806} 1810}
1807 1811
1808 1812
1809/* 1813/*
1810 Insert all-day KOAgendaItem into agenda. 1814 Insert all-day KOAgendaItem into agenda.
1811*/ 1815*/
1812KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) 1816KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd)
1813{ 1817{
1814 if (!mAllDayMode) { 1818 if (!mAllDayMode) {
1815 return 0; 1819 return 0;
1816 } 1820 }
1817 1821
1818 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); 1822 KOAgendaItem *agendaItem = getNewItem(event,qd,viewport());
1819 1823
1820 agendaItem->setCellXY(XBegin,0,0); 1824 agendaItem->setCellXY(XBegin,0,0);
1821 agendaItem->setCellXWidth(XEnd); 1825 agendaItem->setCellXWidth(XEnd);
1822 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); 1826 agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY);
1823 1827
1824 //addChild(agendaItem,XBegin*mGridSpacingX,0); 1828 //addChild(agendaItem,XBegin*mGridSpacingX,0);
1825 mItems.append(agendaItem); 1829 mItems.append(agendaItem);
1826 1830
1827 placeSubCells(agendaItem); 1831 placeSubCells(agendaItem);
1828 1832
1829 //agendaItem->show(); 1833 //agendaItem->show();
1830 1834
1831 return agendaItem; 1835 return agendaItem;
1832} 1836}
1833 1837
1834 1838
1835void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 1839void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
1836 int YTop,int YBottom) 1840 int YTop,int YBottom)
1837{ 1841{
1838 if (mAllDayMode) { 1842 if (mAllDayMode) {
1839 ; 1843 ;
1840 return; 1844 return;
1841 } 1845 }
1842 1846
1843 int cellX,cellYTop,cellYBottom; 1847 int cellX,cellYTop,cellYBottom;
1844 QString newtext; 1848 QString newtext;
1845 int width = XEnd - XBegin + 1; 1849 int width = XEnd - XBegin + 1;
1846 int count = 0; 1850 int count = 0;
1847 KOAgendaItem *current = 0; 1851 KOAgendaItem *current = 0;
1848 QPtrList<KOAgendaItem> multiItems; 1852 QPtrList<KOAgendaItem> multiItems;
1849 for (cellX = XBegin;cellX <= XEnd;++cellX) { 1853 for (cellX = XBegin;cellX <= XEnd;++cellX) {
1850 if (cellX == XBegin) cellYTop = YTop; 1854 if (cellX == XBegin) cellYTop = YTop;
1851 else cellYTop = 0; 1855 else cellYTop = 0;
1852 if (cellX == XEnd) cellYBottom = YBottom; 1856 if (cellX == XEnd) cellYBottom = YBottom;
1853 else cellYBottom = rows() - 1; 1857 else cellYBottom = rows() - 1;
1854 newtext = QString("(%1/%2): ").arg(++count).arg(width); 1858 newtext = QString("(%1/%2): ").arg(++count).arg(width);
1855 newtext.append(event->summary()); 1859 newtext.append(event->summary());
1856 current = insertItem(event,qd,cellX,cellYTop,cellYBottom); 1860 current = insertItem(event,qd,cellX,cellYTop,cellYBottom);
1857 current->setText(newtext); 1861 current->setText(newtext);
1858 multiItems.append(current); 1862 multiItems.append(current);
1859 } 1863 }
1860 1864
1861 KOAgendaItem *next = 0; 1865 KOAgendaItem *next = 0;
1862 KOAgendaItem *last = multiItems.last(); 1866 KOAgendaItem *last = multiItems.last();
1863 KOAgendaItem *first = multiItems.first(); 1867 KOAgendaItem *first = multiItems.first();
1864 KOAgendaItem *setFirst,*setLast; 1868 KOAgendaItem *setFirst,*setLast;
1865 current = first; 1869 current = first;
1866 while (current) { 1870 while (current) {
1867 next = multiItems.next(); 1871 next = multiItems.next();
1868 if (current == first) setFirst = 0; 1872 if (current == first) setFirst = 0;
1869 else setFirst = first; 1873 else setFirst = first;
1870 if (current == last) setLast = 0; 1874 if (current == last) setLast = 0;
1871 else setLast = last; 1875 else setLast = last;
1872 1876
1873 current->setMultiItem(setFirst,next,setLast); 1877 current->setMultiItem(setFirst,next,setLast);
1874 current = next; 1878 current = next;
1875 } 1879 }
1876} 1880}
1877 1881
1878 1882
1879//QSizePolicy KOAgenda::sizePolicy() const 1883//QSizePolicy KOAgenda::sizePolicy() const
1880//{ 1884//{
1881 // Thought this would make the all-day event agenda minimum size and the 1885 // Thought this would make the all-day event agenda minimum size and the
1882 // normal agenda take the remaining space. But it doesn´t work. The QSplitter 1886 // normal agenda take the remaining space. But it doesn´t work. The QSplitter
1883 // don´t seem to think that an Expanding widget needs more space than a 1887 // don´t seem to think that an Expanding widget needs more space than a
1884 // Preferred one. 1888 // Preferred one.
1885 // But it doesn´t hurt, so it stays. 1889 // But it doesn´t hurt, so it stays.
1886// if (mAllDayMode) { 1890// if (mAllDayMode) {
1887// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 1891// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
1888// } else { 1892// } else {
1889// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); 1893// return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
1890// } 1894// }
1891//} 1895//}
1892void KOAgenda::finishResize ( ) 1896void KOAgenda::finishResize ( )
1893{ 1897{
1894 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); 1898 //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) ");
1895 if ( globalFlagBlockAgenda == 0 ) { 1899 if ( globalFlagBlockAgenda == 0 ) {
1896 finishUpdate(); 1900 finishUpdate();
1897 //qDebug("finishUpdate() called "); 1901 //qDebug("finishUpdate() called ");
1898 } 1902 }
1899} 1903}
1900/* 1904/*
1901 Overridden from QScrollView to provide proper resizing of KOAgendaItems. 1905 Overridden from QScrollView to provide proper resizing of KOAgendaItems.
1902*/ 1906*/
1903void KOAgenda::resizeEvent ( QResizeEvent *ev ) 1907void KOAgenda::resizeEvent ( QResizeEvent *ev )
1904{ 1908{
1905 mSelectionHeight = 0; 1909 mSelectionHeight = 0;
1906 mResizeTimer.start( 150 , true ); 1910 mResizeTimer.start( 150 , true );
1907 computeSizes(); 1911 computeSizes();
1908 return; 1912 return;
1909 1913
1910} 1914}
1911void KOAgenda::computeSizes() 1915void KOAgenda::computeSizes()
1912{ 1916{
1913 if ( globalFlagBlockStartup ) 1917 if ( globalFlagBlockStartup )
1914 return; 1918 return;
1915 int frameOffset = frameWidth() * 2 +1; 1919 int frameOffset = frameWidth() * 2 +1;
1916 if (mAllDayMode) { 1920 if (mAllDayMode) {
1917 mGridSpacingX = (width()-frameOffset) / mColumns; 1921 mGridSpacingX = (width()-frameOffset) / mColumns;
1918 mGridSpacingY = height() - 2 * frameWidth() - 1; 1922 mGridSpacingY = height() - 2 * frameWidth() - 1;
1919 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); 1923 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1);
1920 // mGridSpacingY = height(); 1924 // mGridSpacingY = height();
1921 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1925 // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1922 1926
1923 KOAgendaItem *item; 1927 KOAgendaItem *item;
1924 int subCellWidth; 1928 int subCellWidth;
1925 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1929 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1926 subCellWidth = mGridSpacingY / item->subCells(); 1930 subCellWidth = mGridSpacingY / item->subCells();
1927 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); 1931 item->resize(mGridSpacingX * item->cellWidth(),subCellWidth);
1928 moveChild(item,KOGlobals::self()->reverseLayout() ? 1932 moveChild(item,KOGlobals::self()->reverseLayout() ?
1929 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1933 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1930 item->cellX() * mGridSpacingX, 1934 item->cellX() * mGridSpacingX,
1931 item->subCell() * subCellWidth); 1935 item->subCell() * subCellWidth);
1932 } 1936 }
1933 KOPrefs::instance()->mAllDaySize = mGridSpacingY; 1937 KOPrefs::instance()->mAllDaySize = mGridSpacingY;
1934 } else { 1938 } else {
1935 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns; 1939 mGridSpacingX = (width() - verticalScrollBar()->width()-frameOffset)/mColumns;
1936 if (height() > mGridSpacingY * mRows + 1 ) { 1940 if (height() > mGridSpacingY * mRows + 1 ) {
1937 KOPrefs::instance()->mHourSize = ((height())/mRows)+1; 1941 KOPrefs::instance()->mHourSize = ((height())/mRows)+1;
1938 mGridSpacingY = KOPrefs::instance()->mHourSize ; 1942 mGridSpacingY = KOPrefs::instance()->mHourSize ;
1939 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1943 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1940 emit resizedSignal(); 1944 emit resizedSignal();
1941 } else 1945 } else
1942 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); 1946 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 );
1943 KOAgendaItem *item; 1947 KOAgendaItem *item;
1944 int subCellWidth; 1948 int subCellWidth;
1945 1949
1946 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 1950 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
1947 subCellWidth = mGridSpacingX / item->subCells(); 1951 subCellWidth = mGridSpacingX / item->subCells();
1948 item->resize(subCellWidth,item->height()); 1952 item->resize(subCellWidth,item->height());
1949 moveChild(item,(KOGlobals::self()->reverseLayout() ? 1953 moveChild(item,(KOGlobals::self()->reverseLayout() ?
1950 (mColumns - 1 - item->cellX()) * mGridSpacingX : 1954 (mColumns - 1 - item->cellX()) * mGridSpacingX :
1951 item->cellX() * mGridSpacingX) + 1955 item->cellX() * mGridSpacingX) +
1952 item->subCell() * subCellWidth,childY(item)); 1956 item->subCell() * subCellWidth,childY(item));
1953 } 1957 }
1954 } 1958 }
1955 int cw = contentsWidth(); 1959 int cw = contentsWidth();
1956 int ch = contentsHeight(); 1960 int ch = contentsHeight();
1957 if ( mAllDayMode ) { 1961 if ( mAllDayMode ) {
1958 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); 1962 QPixmap* paintPixAll = KOAgendaItem::paintPixAllday();
1959 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) { 1963 if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) {
1960 //qDebug("paintPixAll->resize "); 1964 //qDebug("paintPixAll->resize ");
1961 paintPixAll->resize( cw, ch ); 1965 paintPixAll->resize( cw, ch );
1962 } 1966 }
1963 } else { 1967 } else {
1964 QPixmap* paintPix = KOAgendaItem::paintPix(); 1968 QPixmap* paintPix = KOAgendaItem::paintPix();
1965 if ( paintPix->width() < cw || paintPix->height() < ch ) { 1969 if ( paintPix->width() < cw || paintPix->height() < ch ) {
1966 //qDebug("paintPix->resize "); 1970 //qDebug("paintPix->resize ");
1967 paintPix->resize( cw , ch ); 1971 paintPix->resize( cw , ch );
1968 } 1972 }
1969 } 1973 }
1970 1974
1971 checkScrollBoundaries(); 1975 checkScrollBoundaries();
1972 drawContentsToPainter(); 1976 drawContentsToPainter();
1973 viewport()->repaint(false); 1977 viewport()->repaint(false);
1974} 1978}
1975 1979
1976void KOAgenda::scrollUp() 1980void KOAgenda::scrollUp()
1977{ 1981{
1978 scrollBy(0,-mScrollOffset); 1982 scrollBy(0,-mScrollOffset);
1979} 1983}
1980 1984
1981 1985
1982void KOAgenda::scrollDown() 1986void KOAgenda::scrollDown()
1983{ 1987{
1984 scrollBy(0,mScrollOffset); 1988 scrollBy(0,mScrollOffset);
1985} 1989}
1986 1990
1987void KOAgenda::popupAlarm() 1991void KOAgenda::popupAlarm()
1988{ 1992{
1989 if (!mClickedItem) { 1993 if (!mClickedItem) {
1990 qDebug("KOAgenda::popupAlarm() called without having a clicked item "); 1994 qDebug("KOAgenda::popupAlarm() called without having a clicked item ");
1991 return; 1995 return;
1992 } 1996 }
1993 // TODO: deal correctly with multiple alarms 1997 // TODO: deal correctly with multiple alarms
1994 Alarm* alarm; 1998 Alarm* alarm;
1995 QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); 1999 QPtrList<Alarm> list(mClickedItem->incidence()->alarms());
1996 for(alarm=list.first();alarm;alarm=list.next()) { 2000 for(alarm=list.first();alarm;alarm=list.next()) {
1997 alarm->toggleAlarm(); 2001 alarm->toggleAlarm();
1998 } 2002 }
1999 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); 2003 emit itemModified( mClickedItem , KOGlobals::EVENTEDITED );
2000 mClickedItem->paintMe( true ); 2004 mClickedItem->paintMe( true );
2001 mClickedItem->repaint( false ); 2005 mClickedItem->repaint( false );
2002} 2006}
2003 2007
2004/* 2008/*
2005 Calculates the minimum width 2009 Calculates the minimum width
2006*/ 2010*/
2007int KOAgenda::minimumWidth() const 2011int KOAgenda::minimumWidth() const
2008{ 2012{
2009 // TODO:: develop a way to dynamically determine the minimum width 2013 // TODO:: develop a way to dynamically determine the minimum width
2010 int min = 100; 2014 int min = 100;
2011 2015
2012 return min; 2016 return min;
2013} 2017}
2014 2018
2015void KOAgenda::updateConfig() 2019void KOAgenda::updateConfig()
2016{ 2020{
2017 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) 2021 if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor)
2018 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); 2022 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
2019 if ( mAllDayMode ) { 2023 if ( mAllDayMode ) {
2020 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; 2024 mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize;
2021 //mGridSpacingY = KOPrefs::instance()->mAllDaySize; 2025 //mGridSpacingY = KOPrefs::instance()->mAllDaySize;
2022 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); 2026 resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 );
2023 // setMaximumHeight( mGridSpacingY+1 ); 2027 // setMaximumHeight( mGridSpacingY+1 );
2024 viewport()->repaint( false ); 2028 viewport()->repaint( false );
2025 //setFixedHeight( mGridSpacingY+1 ); 2029 //setFixedHeight( mGridSpacingY+1 );
2026 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); 2030 //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize);
2027 } 2031 }
2028 else { 2032 else {
2029 mGridSpacingY = KOPrefs::instance()->mHourSize; 2033 mGridSpacingY = KOPrefs::instance()->mHourSize;
2030 calculateWorkingHours(); 2034 calculateWorkingHours();
2031 } 2035 }
2032} 2036}
2033 2037
2034void KOAgenda::checkScrollBoundaries() 2038void KOAgenda::checkScrollBoundaries()
2035{ 2039{
2036 // Invalidate old values to force update 2040 // Invalidate old values to force update
2037 mOldLowerScrollValue = -1; 2041 mOldLowerScrollValue = -1;
2038 mOldUpperScrollValue = -1; 2042 mOldUpperScrollValue = -1;
2039 2043
2040 checkScrollBoundaries(verticalScrollBar()->value()); 2044 checkScrollBoundaries(verticalScrollBar()->value());
2041} 2045}
2042 2046
2043void KOAgenda::checkScrollBoundaries(int v) 2047void KOAgenda::checkScrollBoundaries(int v)
2044{ 2048{
2045 if ( mGridSpacingY == 0 ) 2049 if ( mGridSpacingY == 0 )
2046 return; 2050 return;
2047 int yMin = v/mGridSpacingY; 2051 int yMin = v/mGridSpacingY;
2048 int yMax = (v+visibleHeight())/mGridSpacingY; 2052 int yMax = (v+visibleHeight())/mGridSpacingY;
2049 2053
2050// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; 2054// kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl;
2051 2055
2052 if (yMin != mOldLowerScrollValue) { 2056 if (yMin != mOldLowerScrollValue) {
2053 mOldLowerScrollValue = yMin; 2057 mOldLowerScrollValue = yMin;
2054 emit lowerYChanged(yMin); 2058 emit lowerYChanged(yMin);
2055 } 2059 }
2056 if (yMax != mOldUpperScrollValue) { 2060 if (yMax != mOldUpperScrollValue) {
2057 mOldUpperScrollValue = yMax; 2061 mOldUpperScrollValue = yMax;
2058 emit upperYChanged(yMax); 2062 emit upperYChanged(yMax);
2059 } 2063 }
2060} 2064}
2061 2065
2062void KOAgenda::deselectItem() 2066void KOAgenda::deselectItem()
2063{ 2067{
2064 if (mSelectedItem.isNull()) return; 2068 if (mSelectedItem.isNull()) return;
2065 mSelectedItem->select(false); 2069 mSelectedItem->select(false);
2066 mSelectedItem = 0; 2070 mSelectedItem = 0;
2067} 2071}
2068 2072
2069void KOAgenda::selectItem(KOAgendaItem *item) 2073void KOAgenda::selectItem(KOAgendaItem *item)
2070{ 2074{
2071 if ((KOAgendaItem *)mSelectedItem == item) return; 2075 if ((KOAgendaItem *)mSelectedItem == item) return;
2072 deselectItem(); 2076 deselectItem();
2073 if (item == 0) { 2077 if (item == 0) {
2074 emit incidenceSelected( 0 ); 2078 emit incidenceSelected( 0 );
2075 return; 2079 return;
2076 } 2080 }
2077 mSelectedItem = item; 2081 mSelectedItem = item;
2078 mSelectedItem->select(); 2082 mSelectedItem->select();
2079 emit incidenceSelected( mSelectedItem->incidence() ); 2083 emit incidenceSelected( mSelectedItem->incidence() );
2080} 2084}
2081 2085
2082// This function seems never be called. 2086// This function seems never be called.
2083void KOAgenda::keyPressEvent( QKeyEvent *kev ) 2087void KOAgenda::keyPressEvent( QKeyEvent *kev )
2084{ 2088{
2085 switch(kev->key()) { 2089 switch(kev->key()) {
2086 case Key_PageDown: 2090 case Key_PageDown:
2087 verticalScrollBar()->addPage(); 2091 verticalScrollBar()->addPage();
2088 break; 2092 break;
2089 case Key_PageUp: 2093 case Key_PageUp:
2090 verticalScrollBar()->subtractPage(); 2094 verticalScrollBar()->subtractPage();
2091 break; 2095 break;
2092 case Key_Down: 2096 case Key_Down:
2093 verticalScrollBar()->addLine(); 2097 verticalScrollBar()->addLine();
2094 break; 2098 break;
2095 case Key_Up: 2099 case Key_Up:
2096 verticalScrollBar()->subtractLine(); 2100 verticalScrollBar()->subtractLine();
2097 break; 2101 break;
2098 default: 2102 default:
2099 ; 2103 ;
2100 } 2104 }
2101} 2105}
2102 2106
2103void KOAgenda::calculateWorkingHours() 2107void KOAgenda::calculateWorkingHours()
2104{ 2108{
2105// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; 2109// mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours;
2106 mWorkingHoursEnable = !mAllDayMode; 2110 mWorkingHoursEnable = !mAllDayMode;
2107 2111
2108 mWorkingHoursYTop = mGridSpacingY * 2112 mWorkingHoursYTop = mGridSpacingY *
2109 KOPrefs::instance()->mWorkingHoursStart * 4; 2113 KOPrefs::instance()->mWorkingHoursStart * 4;
2110 mWorkingHoursYBottom = mGridSpacingY * 2114 mWorkingHoursYBottom = mGridSpacingY *
2111 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; 2115 KOPrefs::instance()->mWorkingHoursEnd * 4 - 1;
2112} 2116}
2113 2117
2114 2118
2115DateList KOAgenda::dateList() const 2119DateList KOAgenda::dateList() const
2116{ 2120{
2117 return mSelectedDates; 2121 return mSelectedDates;
2118} 2122}
2119 2123
2120void KOAgenda::setDateList(const DateList &selectedDates) 2124void KOAgenda::setDateList(const DateList &selectedDates)
2121{ 2125{
2122 mSelectedDates = selectedDates; 2126 mSelectedDates = selectedDates;
2123} 2127}
2124 2128
2125void KOAgenda::setHolidayMask(QMemArray<bool> *mask) 2129void KOAgenda::setHolidayMask(QMemArray<bool> *mask)
2126{ 2130{
2127 mHolidayMask = mask; 2131 mHolidayMask = mask;
2128 2132
2129/* 2133/*
2130 kdDebug() << "HolidayMask: "; 2134 kdDebug() << "HolidayMask: ";
2131 for(uint i=0;i<mask->count();++i) { 2135 for(uint i=0;i<mask->count();++i) {
2132 kdDebug() << (mask->at(i) ? "*" : "o"); 2136 kdDebug() << (mask->at(i) ? "*" : "o");
2133 } 2137 }
2134 kdDebug() << endl; 2138 kdDebug() << endl;
2135*/ 2139*/
2136} 2140}
2137 2141
2138void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) 2142void KOAgenda::contentsMousePressEvent ( QMouseEvent *event )
2139{ 2143{
2140 2144
2141 QScrollView::contentsMousePressEvent(event); 2145 QScrollView::contentsMousePressEvent(event);
2142} 2146}
2143 2147
2144void KOAgenda::storePosition() 2148void KOAgenda::storePosition()
2145{ 2149{
2146 //mContentPosition 2150 //mContentPosition
2147 int max = mGridSpacingY*4*24; 2151 int max = mGridSpacingY*4*24;
2148 if ( contentsY() < 5 && max > viewport()->height()*3/2 ) 2152 if ( contentsY() < 5 && max > viewport()->height()*3/2 )
2149 mContentPosition = 0; 2153 mContentPosition = 0;
2150 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) 2154 else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2)
2151 mContentPosition = -1.0; 2155 mContentPosition = -1.0;
2152 else 2156 else
2153 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); 2157 mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2)));
2154 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); 2158 //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height());
2155 2159
2156} 2160}
2157void KOAgenda::restorePosition() 2161void KOAgenda::restorePosition()
2158{ 2162{
2159 int posY; 2163 int posY;
2160 int max = mGridSpacingY*4*24; 2164 int max = mGridSpacingY*4*24;
2161 if ( mContentPosition < 0 ) 2165 if ( mContentPosition < 0 )
2162 posY = max-viewport()->height(); 2166 posY = max-viewport()->height();
2163 else 2167 else
2164 if ( mContentPosition == 0 ) 2168 if ( mContentPosition == 0 )
2165 posY = 0; 2169 posY = 0;
2166 else 2170 else
2167 posY = (max/mContentPosition)-(viewport()->height()/2); 2171 posY = (max/mContentPosition)-(viewport()->height()/2);
2168 setContentsPos (0, posY ); 2172 setContentsPos (0, posY );
2169 //qDebug("posY %d hei %d", posY, max); 2173 //qDebug("posY %d hei %d", posY, max);
2170 2174
2171} 2175}
2172void KOAgenda::moveChild( QWidget *w, int x , int y ) 2176void KOAgenda::moveChild( QWidget *w, int x , int y )
2173{ 2177{
2174 ++x; 2178 ++x;
2175 QScrollView::moveChild( w, x , y ); 2179 QScrollView::moveChild( w, x , y );
2176} 2180}
2177#include <qmessagebox.h> 2181#include <qmessagebox.h>
2178#ifdef DESKTOP_VERSION 2182#ifdef DESKTOP_VERSION
2179#include <qprinter.h> 2183#include <qprinter.h>
2180#include <qpainter.h> 2184#include <qpainter.h>
2181#include <qpaintdevicemetrics.h> 2185#include <qpaintdevicemetrics.h>
2182 2186
2183#endif 2187#endif
2184void KOAgenda::printSelection() 2188void KOAgenda::printSelection()
2185{ 2189{
2186#ifdef DESKTOP_VERSION 2190#ifdef DESKTOP_VERSION
2187 if ( mStartCellY == mCurrentCellY ) { 2191 if ( mStartCellY == mCurrentCellY ) {
2188 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2192 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2189 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "), 2193 i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "),
2190 i18n("OK"), 0, 0, 2194 i18n("OK"), 0, 0,
2191 0, 1 ); 2195 0, 1 );
2192 return; 2196 return;
2193 } 2197 }
2194 2198
2195 float dx, dy; 2199 float dx, dy;
2196 int x,y,w,h; 2200 int x,y,w,h;
2197 x= 0; 2201 x= 0;
2198 w= contentsWidth()+2; 2202 w= contentsWidth()+2;
2199 // h= contentsHeight(); 2203 // h= contentsHeight();
2200 y = mGridSpacingY*mStartCellY; 2204 y = mGridSpacingY*mStartCellY;
2201 h = mGridSpacingY*(mCurrentCellY+1)-y+2; 2205 h = mGridSpacingY*(mCurrentCellY+1)-y+2;
2202 2206
2203 //return; 2207 //return;
2204 QPrinter* printer = new QPrinter(); 2208 QPrinter* printer = new QPrinter();
2205 if ( !printer->setup()) { 2209 if ( !printer->setup()) {
2206 delete printer; 2210 delete printer;
2207 return; 2211 return;
2208 } 2212 }
2209 QPainter p( printer ); 2213 QPainter p( printer );
2210 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); 2214 QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer );
2211 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); 2215 QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() );
2212 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); 2216 //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true );
2213 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); 2217 int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height();
2214 // p.drawText( 0, 0, date ); 2218 // p.drawText( 0, 0, date );
2215 int offset = m.width()/8; 2219 int offset = m.width()/8;
2216 // compute the scale 2220 // compute the scale
2217 dx = ((float) m.width()-offset) / (float)w; 2221 dx = ((float) m.width()-offset) / (float)w;
2218 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; 2222 dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h;
2219 float scale; 2223 float scale;
2220 // scale to fit the width or height of the paper 2224 // scale to fit the width or height of the paper
2221 if ( dx < dy ) 2225 if ( dx < dy )
2222 scale = dx; 2226 scale = dx;
2223 else 2227 else
2224 scale = dy; 2228 scale = dy;
2225 // set the scale 2229 // set the scale
2226 p.drawText( offset* scale, offset* scale*3/4, date ); 2230 p.drawText( offset* scale, offset* scale*3/4, date );
2227 2231
2228 int selDay; 2232 int selDay;
2229 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); 2233 float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count()));
2230 float startX = 1; 2234 float startX = 1;
2231 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) 2235 for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay)
2232 { 2236 {
2233 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); 2237 QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true );
2234 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); 2238 p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) );
2235 p.drawText( offset* scale+startX, (offset+hei)* scale, text ); 2239 p.drawText( offset* scale+startX, (offset+hei)* scale, text );
2236 startX += widOffset; 2240 startX += widOffset;
2237 2241
2238 } 2242 }
2239 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); 2243 p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale));
2240 p.scale( scale, scale ); 2244 p.scale( scale, scale );
2241 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); 2245 p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale );
2242 // now printing with y offset: 2 hei 2246 // now printing with y offset: 2 hei
2243 // p.translate( 0, -y*scale); 2247 // p.translate( 0, -y*scale);
2244 2248
2245 drawContentsToPainter(&p, true ); 2249 drawContentsToPainter(&p, true );
2246 globalFlagBlockAgendaItemUpdate = false; 2250 globalFlagBlockAgendaItemUpdate = false;
2247 KOAgendaItem *item; 2251 KOAgendaItem *item;
2248 for ( item=mItems.first(); item != 0; item=mItems.next() ) { 2252 for ( item=mItems.first(); item != 0; item=mItems.next() ) {
2249 item->select(false); 2253 item->select(false);
2250 item->paintMe( false, &p ); 2254 item->paintMe( false, &p );
2251 } 2255 }
2252 globalFlagBlockAgendaItemUpdate = true; 2256 globalFlagBlockAgendaItemUpdate = true;
2253 p.end(); 2257 p.end();
2254 delete printer; 2258 delete printer;
2255#else 2259#else
2256 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2260 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2257 i18n("Not supported \non PDA!\n"), 2261 i18n("Not supported \non PDA!\n"),
2258 i18n("OK"), 0, 0, 2262 i18n("OK"), 0, 0,
2259 0, 1 ); 2263 0, 1 );
2260#endif 2264#endif
2261} 2265}
diff --git a/korganizer/koagenda.h b/korganizer/koagenda.h
index 0e3aed8..86cf2f4 100644
--- a/korganizer/koagenda.h
+++ b/korganizer/koagenda.h
@@ -1,306 +1,307 @@
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 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef KOAGENDA_H 23#ifndef KOAGENDA_H
24#define KOAGENDA_H 24#define KOAGENDA_H
25 25
26#include <qscrollview.h> 26#include <qscrollview.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qmemarray.h> 28#include <qmemarray.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qpixmap.h> 30#include <qpixmap.h>
31#include <qguardedptr.h> 31#include <qguardedptr.h>
32 32
33#include "koagendaitem.h" 33#include "koagendaitem.h"
34#include "koeventview.h" 34#include "koeventview.h"
35 35
36class QPopupMenu; 36class QPopupMenu;
37class QTime; 37class QTime;
38class KConfig; 38class KConfig;
39class QFrame; 39class QFrame;
40class KOAgenda; 40class KOAgenda;
41class KCal::Event; 41class KCal::Event;
42class KCal::Todo; 42class KCal::Todo;
43 43
44using namespace KCal; 44using namespace KCal;
45 45
46class MarcusBains : public QFrame { 46class MarcusBains : public QFrame {
47 Q_OBJECT 47 Q_OBJECT
48 public: 48 public:
49 MarcusBains(KOAgenda *agenda=0,const char *name=0); 49 MarcusBains(KOAgenda *agenda=0,const char *name=0);
50 virtual ~MarcusBains(); 50 virtual ~MarcusBains();
51 51
52 public slots: 52 public slots:
53 void updateLocation(bool recalculate=false); 53 void updateLocation(bool recalculate=false);
54 void updateLoc(); 54 void updateLoc();
55 55
56 private: 56 private:
57 int todayColumn(); 57 int todayColumn();
58 QTimer *minutes; 58 QTimer *minutes;
59 QLabel *mTimeBox; 59 QLabel *mTimeBox;
60 KOAgenda *agenda; 60 KOAgenda *agenda;
61 QTime oldTime; 61 QTime oldTime;
62 int oldToday; 62 int oldToday;
63}; 63};
64 64
65 65
66class KOAgenda : public QScrollView 66class KOAgenda : public QScrollView
67{ 67{
68 Q_OBJECT 68 Q_OBJECT
69 public: 69 public:
70 enum MouseActionType { NOP, MOVE, SELECT, 70 enum MouseActionType { NOP, MOVE, SELECT,
71 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT }; 71 RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
72 72
73 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0, 73 KOAgenda ( int columns, int rows, int columnSize, QWidget * parent=0,
74 const char * name=0, WFlags f=0 ); 74 const char * name=0, WFlags f=0 );
75 KOAgenda ( int columns, QWidget * parent=0, 75 KOAgenda ( int columns, QWidget * parent=0,
76 const char * name=0, WFlags f=0 ); 76 const char * name=0, WFlags f=0 );
77 virtual ~KOAgenda(); 77 virtual ~KOAgenda();
78 bool mInvalidPixmap; 78 bool mInvalidPixmap;
79 79
80 Incidence *selectedIncidence() const; 80 Incidence *selectedIncidence() const;
81 QDate selectedIncidenceDate() const; 81 QDate selectedIncidenceDate() const;
82 82
83 virtual bool eventFilter ( QObject *, QEvent * ); 83 virtual bool eventFilter ( QObject *, QEvent * );
84 84
85 void contentsToGrid (int x, int y, int& gx, int& gy); 85 void contentsToGrid (int x, int y, int& gx, int& gy);
86 void gridToContents (int gx, int gy, int& x, int& y); 86 void gridToContents (int gx, int gy, int& x, int& y);
87 87
88 int timeToY (const QTime &time); 88 int timeToY (const QTime &time);
89 QTime gyToTime (int y); 89 QTime gyToTime (int y);
90 90
91 void setStartHour(int startHour); 91 void setStartHour(int startHour);
92 92
93 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom); 93 KOAgendaItem *insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom);
94 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd); 94 KOAgendaItem *insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd);
95 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, 95 void insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd,
96 int YTop,int YBottom); 96 int YTop,int YBottom);
97 97
98 void changeColumns(int columns); 98 void changeColumns(int columns);
99 99
100 int columns() { return mColumns; } 100 int columns() { return mColumns; }
101 int rows() { return mRows; } 101 int rows() { return mRows; }
102 102
103 int gridSpacingX() const { return mGridSpacingX; } 103 int gridSpacingX() const { return mGridSpacingX; }
104 int gridSpacingY() const { return mGridSpacingY; } 104 int gridSpacingY() const { return mGridSpacingY; }
105 105
106// virtual QSizePolicy sizePolicy() const; 106// virtual QSizePolicy sizePolicy() const;
107 107
108 void clear(); 108 void clear();
109 109
110 void clearSelection(); 110 void clearSelection();
111 void hideUnused(); 111 void hideUnused();
112 112
113 /** Calculates the minimum width */ 113 /** Calculates the minimum width */
114 virtual int minimumWidth() const; 114 virtual int minimumWidth() const;
115 /** Update configuration from preference settings */ 115 /** Update configuration from preference settings */
116 void updateConfig(); 116 void updateConfig();
117 117
118 void checkScrollBoundaries(); 118 void checkScrollBoundaries();
119 119
120 void setHolidayMask(QMemArray<bool> *); 120 void setHolidayMask(QMemArray<bool> *);
121 void setDateList(const DateList &selectedDates); 121 void setDateList(const DateList &selectedDates);
122 DateList dateList() const; 122 DateList dateList() const;
123 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false); 123 void drawContentsToPainter( QPainter* paint = 0, bool backgroundOnly = false);
124 void finishUpdate(); 124 void finishUpdate();
125 void printSelection(); 125 void printSelection();
126 void storePosition(); 126 void storePosition();
127 void restorePosition(); 127 void restorePosition();
128 void setPopup( KOEventPopupMenu * p ) { mAllAgendaPopup = p; } 128 void setPopup( KOEventPopupMenu * p ) { mAllAgendaPopup = p; }
129 void shrinkPixmap(); 129 void shrinkPixmap();
130 QTime getEndTime();
130 131
131 public slots: 132 public slots:
132 void slotContentMove(int,int); 133 void slotContentMove(int,int);
133 void categoryChanged(Incidence * inc); 134 void categoryChanged(Incidence * inc);
134 void slotClearSelection(); 135 void slotClearSelection();
135 void popupMenu(); 136 void popupMenu();
136 void newItem( int ); 137 void newItem( int );
137 void moveChild( QWidget *, int, int ); 138 void moveChild( QWidget *, int, int );
138 void scrollUp(); 139 void scrollUp();
139 void scrollDown(); 140 void scrollDown();
140 void updateTodo( Todo * t, int , bool ); 141 void updateTodo( Todo * t, int , bool );
141 void popupAlarm(); 142 void popupAlarm();
142 143
143 void checkScrollBoundaries(int); 144 void checkScrollBoundaries(int);
144 145
145 /** Deselect selected items. This function does not emit any signals. */ 146 /** Deselect selected items. This function does not emit any signals. */
146 void deselectItem(); 147 void deselectItem();
147 /** Select item. If the argument is 0, the currently selected item gets 148 /** Select item. If the argument is 0, the currently selected item gets
148 deselected. This function emits the itemSelected(bool) signal to inform 149 deselected. This function emits the itemSelected(bool) signal to inform
149 about selection/deseelction of events. */ 150 about selection/deseelction of events. */
150 void selectItem(KOAgendaItem *); 151 void selectItem(KOAgendaItem *);
151 void finishResize(); 152 void finishResize();
152 153
153 signals: 154 signals:
154 void signalClearSelection(); 155 void signalClearSelection();
155 void showDateView( int, int); 156 void showDateView( int, int);
156 void newEventSignal(); 157 void newEventSignal();
157 void newEventSignal(int gx,int gy); 158 void newEventSignal(int gx,int gy);
158 void newTodoSignal(int gx,int gy); 159 void newTodoSignal(int gx,int gy);
159 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 160 void newEventSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
160 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd); 161 void newTimeSpanSignal(int gxStart, int gyStart, int gxEnd, int gyEnd);
161 void newStartSelectSignal(); 162 void newStartSelectSignal();
162 void showIncidenceSignal(Incidence *); 163 void showIncidenceSignal(Incidence *);
163 void editIncidenceSignal(Incidence *); 164 void editIncidenceSignal(Incidence *);
164 void deleteIncidenceSignal(Incidence *); 165 void deleteIncidenceSignal(Incidence *);
165 void showIncidencePopupSignal(Incidence *); 166 void showIncidencePopupSignal(Incidence *);
166 167
167 void itemModified(KOAgendaItem *item, int ); 168 void itemModified(KOAgendaItem *item, int );
168 void incidenceSelected(Incidence *); 169 void incidenceSelected(Incidence *);
169 170
170 void lowerYChanged(int); 171 void lowerYChanged(int);
171 void upperYChanged(int); 172 void upperYChanged(int);
172 173
173 void startDragSignal(Incidence *); 174 void startDragSignal(Incidence *);
174 void addToCalSignal(Incidence *, Incidence *); 175 void addToCalSignal(Incidence *, Incidence *);
175 void resizedSignal(); 176 void resizedSignal();
176 void updateViewSignal(); 177 void updateViewSignal();
177 void sendPing(); 178 void sendPing();
178 179
179 protected: 180 protected:
180 KOEventPopupMenu * mAllAgendaPopup; 181 KOEventPopupMenu * mAllAgendaPopup;
181 QPainter mPixPainter; 182 QPainter mPixPainter;
182 QPixmap mPaintPixmap; 183 QPixmap mPaintPixmap;
183 QPixmap mHighlightPixmap; 184 QPixmap mHighlightPixmap;
184 void drawContents(QPainter *p,int cx, int cy, int cw, int ch); 185 void drawContents(QPainter *p,int cx, int cy, int cw, int ch);
185 virtual void resizeEvent ( QResizeEvent * ); 186 virtual void resizeEvent ( QResizeEvent * );
186 187
187 /** Handles mouse events. Called from eventFilter */ 188 /** Handles mouse events. Called from eventFilter */
188 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * ); 189 virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
189 190
190 /** Start selecting time span. */ 191 /** Start selecting time span. */
191 void startSelectAction(QPoint viewportPos); 192 void startSelectAction(QPoint viewportPos);
192 193
193 /** Select time span. */ 194 /** Select time span. */
194 void performSelectAction(QPoint viewportPos); 195 void performSelectAction(QPoint viewportPos);
195 196
196 /** Emd selecting time span. */ 197 /** Emd selecting time span. */
197 void endSelectAction( bool emitNewEvent = false ); 198 void endSelectAction( bool emitNewEvent = false );
198 199
199 /** Start moving/resizing agenda item */ 200 /** Start moving/resizing agenda item */
200 void startItemAction(QPoint viewportPos); 201 void startItemAction(QPoint viewportPos);
201 202
202 /** Move/resize agenda item */ 203 /** Move/resize agenda item */
203 void performItemAction(QPoint viewportPos); 204 void performItemAction(QPoint viewportPos);
204 205
205 /** End moving/resizing agenda item */ 206 /** End moving/resizing agenda item */
206 void endItemAction(); 207 void endItemAction();
207 208
208 /** Set cursor, when no item action is in progress */ 209 /** Set cursor, when no item action is in progress */
209 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos); 210 void setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos);
210 211
211 /** Place agenda item in agenda and adjust other cells if necessary */ 212 /** Place agenda item in agenda and adjust other cells if necessary */
212 void placeSubCells(KOAgendaItem *placeItem); 213 void placeSubCells(KOAgendaItem *placeItem);
213 214
214 /** Process the keyevent, including the ignored keyevents of eventwidgets. 215 /** Process the keyevent, including the ignored keyevents of eventwidgets.
215 * Implements pgup/pgdn and cursor key navigation in the view. 216 * Implements pgup/pgdn and cursor key navigation in the view.
216 */ 217 */
217 void keyPressEvent( QKeyEvent * ); 218 void keyPressEvent( QKeyEvent * );
218 219
219 void calculateWorkingHours(); 220 void calculateWorkingHours();
220 221
221 virtual void contentsMousePressEvent ( QMouseEvent * ); 222 virtual void contentsMousePressEvent ( QMouseEvent * );
222 223
223 private: 224 private:
224 void init(); 225 void init();
225 void marcus_bains(); 226 void marcus_bains();
226 bool mAllDayMode; 227 bool mAllDayMode;
227 bool blockResize; 228 bool blockResize;
228 bool mLeftMouseDown; 229 bool mLeftMouseDown;
229 KOAgendaItem *mPopupItem; 230 KOAgendaItem *mPopupItem;
230 QTimer* mPopupTimer; 231 QTimer* mPopupTimer;
231 int mPopupKind; 232 int mPopupKind;
232 QPoint mPopupPos; 233 QPoint mPopupPos;
233 QTimer mResizeTimer; 234 QTimer mResizeTimer;
234 double mContentPosition; 235 double mContentPosition;
235 236
236 // Width and height of agenda cells 237 // Width and height of agenda cells
237 int mGridSpacingX; 238 int mGridSpacingX;
238 int mGridSpacingY; 239 int mGridSpacingY;
239 240
240 // size of border, where mouse action will resize the KOAgendaItem 241 // size of border, where mouse action will resize the KOAgendaItem
241 int mResizeBorderWidth; 242 int mResizeBorderWidth;
242 243
243 // size of border, where mouse mve will cause a scroll of the agenda 244 // size of border, where mouse mve will cause a scroll of the agenda
244 int mScrollBorderWidth; 245 int mScrollBorderWidth;
245 int mScrollDelay; 246 int mScrollDelay;
246 int mScrollOffset; 247 int mScrollOffset;
247 248
248 QTimer mScrollUpTimer; 249 QTimer mScrollUpTimer;
249 QTimer mScrollDownTimer; 250 QTimer mScrollDownTimer;
250 251
251 // Number of Columns/Rows of agenda grid 252 // Number of Columns/Rows of agenda grid
252 int mColumns; 253 int mColumns;
253 int mRows; 254 int mRows;
254 255
255 // Cells to store Move and Resize coordiantes 256 // Cells to store Move and Resize coordiantes
256 int mStartCellX; 257 int mStartCellX;
257 int mStartCellY; 258 int mStartCellY;
258 int mCurrentCellX; 259 int mCurrentCellX;
259 int mCurrentCellY; 260 int mCurrentCellY;
260 261
261 // Working Hour coordiantes 262 // Working Hour coordiantes
262 bool mWorkingHoursEnable; 263 bool mWorkingHoursEnable;
263 int mWorkingHoursYTop; 264 int mWorkingHoursYTop;
264 int mWorkingHoursYBottom; 265 int mWorkingHoursYBottom;
265 266
266 // Selection 267 // Selection
267 int mSelectionCellX; 268 int mSelectionCellX;
268 int mSelectionYTop; 269 int mSelectionYTop;
269 int mSelectionHeight; 270 int mSelectionHeight;
270 271
271 // List of dates to be displayed 272 // List of dates to be displayed
272 DateList mSelectedDates; 273 DateList mSelectedDates;
273 274
274 // The KOAgendaItem, which has been right-clicked last 275 // The KOAgendaItem, which has been right-clicked last
275 KOAgendaItem *mClickedItem; 276 KOAgendaItem *mClickedItem;
276 277
277 // The KOAgendaItem, which is being moved/resized 278 // The KOAgendaItem, which is being moved/resized
278 QGuardedPtr<KOAgendaItem> mActionItem; 279 QGuardedPtr<KOAgendaItem> mActionItem;
279 280
280 // Currently selected item 281 // Currently selected item
281 QGuardedPtr<KOAgendaItem> mSelectedItem; 282 QGuardedPtr<KOAgendaItem> mSelectedItem;
282 283
283 // The Marcus Bains Line widget. 284 // The Marcus Bains Line widget.
284 MarcusBains *mMarcusBains; 285 MarcusBains *mMarcusBains;
285 void computeSizes(); 286 void computeSizes();
286 287
287 MouseActionType mActionType; 288 MouseActionType mActionType;
288 289
289 bool mItemMoved; 290 bool mItemMoved;
290 291
291 // List of all Items contained in agenda 292 // List of all Items contained in agenda
292 QPtrList<KOAgendaItem> mItems; 293 QPtrList<KOAgendaItem> mItems;
293 QPtrList<KOAgendaItem> mUnusedItems; 294 QPtrList<KOAgendaItem> mUnusedItems;
294 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport); 295 KOAgendaItem* getNewItem(Incidence * event,QDate qd, QWidget* viewport);
295 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems 296 QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
296 QPopupMenu *mNewItemPopup; 297 QPopupMenu *mNewItemPopup;
297 298
298 int mOldLowerScrollValue; 299 int mOldLowerScrollValue;
299 int mOldUpperScrollValue; 300 int mOldUpperScrollValue;
300 KOAgendaItem * getItemForTodo ( Todo * todo ); 301 KOAgendaItem * getItemForTodo ( Todo * todo );
301 QMemArray<bool> *mHolidayMask; 302 QMemArray<bool> *mHolidayMask;
302 int mCurPixWid; 303 int mCurPixWid;
303 int mCurPixHei; 304 int mCurPixHei;
304}; 305};
305 306
306#endif // KOAGENDA_H 307#endif // KOAGENDA_H
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp
index 53bbe28..b5a59af 100644
--- a/korganizer/komonthview.cpp
+++ b/korganizer/komonthview.cpp
@@ -1075,1247 +1075,1250 @@ void MonthViewCell::defaultAction( QListBoxItem *item )
1075 } 1075 }
1076 1076
1077 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1077 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1078 Incidence *incidence = eventItem->incidence(); 1078 Incidence *incidence = eventItem->incidence();
1079 if ( incidence ) mMonthView->defaultAction( incidence ); 1079 if ( incidence ) mMonthView->defaultAction( incidence );
1080} 1080}
1081void MonthViewCell::showDay() 1081void MonthViewCell::showDay()
1082{ 1082{
1083 emit showDaySignal( date() ); 1083 emit showDaySignal( date() );
1084} 1084}
1085void MonthViewCell::newEvent() 1085void MonthViewCell::newEvent()
1086{ 1086{
1087 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1087 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1088 emit newEventSignal( dt ); 1088 emit newEventSignal( dt );
1089} 1089}
1090void MonthViewCell::cellClicked( QListBoxItem *item ) 1090void MonthViewCell::cellClicked( QListBoxItem *item )
1091{ 1091{
1092 mMonthView->setSelectedCell( this ); 1092 mMonthView->setSelectedCell( this );
1093 if ( item == 0 ) { 1093 if ( item == 0 ) {
1094 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 1094 QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
1095 emit newEventSignal( dt ); 1095 emit newEventSignal( dt );
1096 return; 1096 return;
1097 } 1097 }
1098 1098
1099} 1099}
1100 1100
1101void MonthViewCell::contextMenu( QListBoxItem *item ) 1101void MonthViewCell::contextMenu( QListBoxItem *item )
1102{ 1102{
1103 mMonthView->setPopupCell( this ); 1103 mMonthView->setPopupCell( this );
1104 if ( !item ) { 1104 if ( !item ) {
1105 mMonthView->showContextMenu( 0 ); 1105 mMonthView->showContextMenu( 0 );
1106 return; 1106 return;
1107 } 1107 }
1108 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); 1108 MonthViewItem *eventItem = static_cast<MonthViewItem *>( item );
1109 Incidence *incidence = eventItem->incidence(); 1109 Incidence *incidence = eventItem->incidence();
1110 if ( incidence ) mMonthView->showContextMenu( incidence ); 1110 if ( incidence ) mMonthView->showContextMenu( incidence );
1111} 1111}
1112 1112
1113void MonthViewCell::selection( QListBoxItem *item ) 1113void MonthViewCell::selection( QListBoxItem *item )
1114{ 1114{
1115 if ( !item ) { 1115 if ( !item ) {
1116 emit highlightIncidence( 0 , this, 0 ); 1116 emit highlightIncidence( 0 , this, 0 );
1117 return; 1117 return;
1118 } 1118 }
1119 MonthViewItem * it = (static_cast<MonthViewItem *>( item )); 1119 MonthViewItem * it = (static_cast<MonthViewItem *>( item ));
1120 emit highlightIncidence( it->incidence(), this, it->multiDay() ); 1120 emit highlightIncidence( it->incidence(), this, it->multiDay() );
1121 mMonthView->setSelectedCell( this ); 1121 mMonthView->setSelectedCell( this );
1122} 1122}
1123 1123
1124void MonthViewCell::deHighLight() 1124void MonthViewCell::deHighLight()
1125{ 1125{
1126 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 1126 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
1127 while ( mitem ) { 1127 while ( mitem ) {
1128 if ( mitem->setHighlightedFalse() ) 1128 if ( mitem->setHighlightedFalse() )
1129 updateItem ( mitem ); 1129 updateItem ( mitem );
1130 mitem = (MonthViewItem *)mitem->next(); 1130 mitem = (MonthViewItem *)mitem->next();
1131 } 1131 }
1132} 1132}
1133// returns true if no inc found 1133// returns true if no inc found
1134bool MonthViewCell::doHighLight( Incidence * inc ) 1134bool MonthViewCell::doHighLight( Incidence * inc )
1135{ 1135{
1136 1136
1137 MonthViewItem *mitem = (MonthViewItem*) firstItem (); 1137 MonthViewItem *mitem = (MonthViewItem*) firstItem ();
1138 while ( mitem ) { 1138 while ( mitem ) {
1139 if ( mitem->incidence() == inc ) { 1139 if ( mitem->incidence() == inc ) {
1140 if ( mitem->setHighlighted( inc ) ) 1140 if ( mitem->setHighlighted( inc ) )
1141 updateItem ( mitem ); 1141 updateItem ( mitem );
1142 return false; 1142 return false;
1143 } 1143 }
1144 mitem = (MonthViewItem *)mitem->next(); 1144 mitem = (MonthViewItem *)mitem->next();
1145 } 1145 }
1146 return true; 1146 return true;
1147} 1147}
1148// ******************************************************************************* 1148// *******************************************************************************
1149// ******************************************************************************* 1149// *******************************************************************************
1150// ******************************************************************************* 1150// *******************************************************************************
1151 1151
1152 1152
1153KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) 1153KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name)
1154 : KOEventView( calendar, parent, name ), 1154 : KOEventView( calendar, parent, name ),
1155 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ), 1155 mDaysPerWeek( 7 ), mNumWeeks( 6 ), mNumCells( mDaysPerWeek * mNumWeeks ),
1156 mWidthLongDayLabel( 0 ), mSelectedCell( 0 ) 1156 mWidthLongDayLabel( 0 ), mSelectedCell( 0 )
1157{ 1157{
1158 mFlagKeyPressed = false; 1158 mFlagKeyPressed = false;
1159 mShortDayLabelsM = false; 1159 mShortDayLabelsM = false;
1160 mShortDayLabelsW = false; 1160 mShortDayLabelsW = false;
1161 skipResize = false; 1161 skipResize = false;
1162 clPending = true; 1162 clPending = true;
1163 mPopupCell = 0; 1163 mPopupCell = 0;
1164 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" ); 1164 mNavigatorBar = new NavigatorBar( QDate::currentDate(), this, "useBigPixmaps" );
1165 mWidStack = new QWidgetStack( this ); 1165 mWidStack = new QWidgetStack( this );
1166 QVBoxLayout* hb = new QVBoxLayout( this ); 1166 QVBoxLayout* hb = new QVBoxLayout( this );
1167 mMonthView = new QWidget( mWidStack ); 1167 mMonthView = new QWidget( mWidStack );
1168 mWeekView = new QWidget( mWidStack ); 1168 mWeekView = new QWidget( mWidStack );
1169#if QT_VERSION >= 0x030000 1169#if QT_VERSION >= 0x030000
1170 mWidStack->addWidget(mMonthView ); 1170 mWidStack->addWidget(mMonthView );
1171 mWidStack->addWidget(mWeekView ); 1171 mWidStack->addWidget(mWeekView );
1172#else 1172#else
1173 mWidStack->addWidget( mMonthView, 1 ); 1173 mWidStack->addWidget( mMonthView, 1 );
1174 mWidStack->addWidget( mWeekView , 1 ); 1174 mWidStack->addWidget( mWeekView , 1 );
1175#endif 1175#endif
1176 hb->addWidget( mNavigatorBar ); 1176 hb->addWidget( mNavigatorBar );
1177 hb->addWidget( mWidStack ); 1177 hb->addWidget( mWidStack );
1178 mShowWeekView = KOPrefs::instance()->mMonthViewWeek; 1178 mShowWeekView = KOPrefs::instance()->mMonthViewWeek;
1179 updatePossible = false; 1179 updatePossible = false;
1180 //updatePossible = true; 1180 //updatePossible = true;
1181 mCells.setAutoDelete( true ); 1181 mCells.setAutoDelete( true );
1182 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1182 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1183 mDayLabels.resize( mDaysPerWeek ); 1183 mDayLabels.resize( mDaysPerWeek );
1184 mDayLabelsW.resize( mDaysPerWeek ); 1184 mDayLabelsW.resize( mDaysPerWeek );
1185 QFont bfont = font(); 1185 QFont bfont = font();
1186 if ( QApplication::desktop()->width() < 650 ) { 1186 if ( QApplication::desktop()->width() < 650 ) {
1187 bfont.setPointSize( bfont.pointSize() - 2 ); 1187 bfont.setPointSize( bfont.pointSize() - 2 );
1188 } 1188 }
1189 bfont.setBold( true ); 1189 bfont.setBold( true );
1190 int i; 1190 int i;
1191 1191
1192 for( i = 0; i < mDaysPerWeek; i++ ) { 1192 for( i = 0; i < mDaysPerWeek; i++ ) {
1193 QLabel *label = new QLabel( mMonthView ); 1193 QLabel *label = new QLabel( mMonthView );
1194 label->setFont(bfont); 1194 label->setFont(bfont);
1195 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1195 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1196 label->setLineWidth(1); 1196 label->setLineWidth(1);
1197 label->setAlignment(AlignCenter); 1197 label->setAlignment(AlignCenter);
1198 mDayLabels.insert( i, label ); 1198 mDayLabels.insert( i, label );
1199 label = new QLabel( mWeekView ); 1199 label = new QLabel( mWeekView );
1200 label->setFont(bfont); 1200 label->setFont(bfont);
1201 label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1201 label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1202 label->setLineWidth(1); 1202 label->setLineWidth(1);
1203 label->setAlignment(AlignCenter); 1203 label->setAlignment(AlignCenter);
1204 mDayLabelsW.insert( i, label ); 1204 mDayLabelsW.insert( i, label );
1205 } 1205 }
1206 1206
1207 bfont.setBold( false ); 1207 bfont.setBold( false );
1208 mWeekLabels.resize( mNumWeeks+1 ); 1208 mWeekLabels.resize( mNumWeeks+1 );
1209 mWeekLabelsW.resize( 2 ); 1209 mWeekLabelsW.resize( 2 );
1210 for( i = 0; i < mNumWeeks+1; i++ ) { 1210 for( i = 0; i < mNumWeeks+1; i++ ) {
1211 KOWeekButton *label = new KOWeekButton( mMonthView ); 1211 KOWeekButton *label = new KOWeekButton( mMonthView );
1212 label->setFocusPolicy(NoFocus); 1212 label->setFocusPolicy(NoFocus);
1213 label->setFont(bfont); 1213 label->setFont(bfont);
1214 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1214 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1215 label->setFlat(true); 1215 label->setFlat(true);
1216 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1216 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1217 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1217 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1218 //label->setLineWidth(1); 1218 //label->setLineWidth(1);
1219 //label->setAlignment(AlignCenter); 1219 //label->setAlignment(AlignCenter);
1220 mWeekLabels.insert( i, label ); 1220 mWeekLabels.insert( i, label );
1221 } 1221 }
1222 mWeekLabels[mNumWeeks]->setText( i18n("W")); 1222 mWeekLabels[mNumWeeks]->setText( i18n("W"));
1223 mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus); 1223 mWeekLabels[mNumWeeks]->setFocusPolicy(WheelFocus);
1224 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number")); 1224 QWhatsThis::add(mWeekLabels[mNumWeeks],i18n("Click on this to\nselect week number"));
1225 1225
1226 for( i = 0; i < 1+1; i++ ) { 1226 for( i = 0; i < 1+1; i++ ) {
1227 KOWeekButton *label = new KOWeekButton( mWeekView ); 1227 KOWeekButton *label = new KOWeekButton( mWeekView );
1228 label->setFocusPolicy(NoFocus); 1228 label->setFocusPolicy(NoFocus);
1229 label->setFont(bfont); 1229 label->setFont(bfont);
1230 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) ); 1230 connect( label, SIGNAL( selectWeekNum ( int )),this, SLOT( selectInternalWeekNum ( int )) );
1231 label->setFlat(true); 1231 label->setFlat(true);
1232 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed")); 1232 QWhatsThis::add(label,i18n("Click on the week number to\nshow week zoomed"));
1233 //label->setFrameStyle(QFrame::Panel|QFrame::Raised); 1233 //label->setFrameStyle(QFrame::Panel|QFrame::Raised);
1234 //label->setLineWidth(1); 1234 //label->setLineWidth(1);
1235 //label->setAlignment(AlignCenter); 1235 //label->setAlignment(AlignCenter);
1236 mWeekLabelsW.insert( i, label ); 1236 mWeekLabelsW.insert( i, label );
1237 } 1237 }
1238 mWeekLabelsW[1]->setText( i18n("W")); 1238 mWeekLabelsW[1]->setText( i18n("W"));
1239 mWeekLabelsW[1]->setFocusPolicy(WheelFocus); 1239 mWeekLabelsW[1]->setFocusPolicy(WheelFocus);
1240 1240
1241 1241
1242 int row, col; 1242 int row, col;
1243 mCells.resize( mNumCells ); 1243 mCells.resize( mNumCells );
1244 for( row = 0; row < mNumWeeks; ++row ) { 1244 for( row = 0; row < mNumWeeks; ++row ) {
1245 for( col = 0; col < mDaysPerWeek; ++col ) { 1245 for( col = 0; col < mDaysPerWeek; ++col ) {
1246 MonthViewCell *cell = new MonthViewCell( this, mMonthView ); 1246 MonthViewCell *cell = new MonthViewCell( this, mMonthView );
1247 mCells.insert( row * mDaysPerWeek + col, cell ); 1247 mCells.insert( row * mDaysPerWeek + col, cell );
1248 1248
1249 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1249 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1250 SLOT( defaultAction( Incidence * ) ) ); 1250 SLOT( defaultAction( Incidence * ) ) );
1251 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1251 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1252 SIGNAL( newEventSignal( QDateTime ) ) ); 1252 SIGNAL( newEventSignal( QDateTime ) ) );
1253 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1253 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1254 SIGNAL( showDaySignal( QDate ) ) ); 1254 SIGNAL( showDaySignal( QDate ) ) );
1255 connect( cell, SIGNAL( nextCell() ), 1255 connect( cell, SIGNAL( nextCell() ),
1256 SLOT( nextCell() ) ); 1256 SLOT( nextCell() ) );
1257 connect( cell, SIGNAL( prevCell() ), 1257 connect( cell, SIGNAL( prevCell() ),
1258 SLOT( prevCell() ) ); 1258 SLOT( prevCell() ) );
1259 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), 1259 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ),
1260 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); 1260 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) ));
1261 } 1261 }
1262 } 1262 }
1263 mCellsW.resize( mDaysPerWeek ); 1263 mCellsW.resize( mDaysPerWeek );
1264 for( col = 0; col < mDaysPerWeek; ++col ) { 1264 for( col = 0; col < mDaysPerWeek; ++col ) {
1265 MonthViewCell *cell = new MonthViewCell( this, mWeekView ); 1265 MonthViewCell *cell = new MonthViewCell( this, mWeekView );
1266 mCellsW.insert( col, cell ); 1266 mCellsW.insert( col, cell );
1267 1267
1268 connect( cell, SIGNAL( defaultAction( Incidence * ) ), 1268 connect( cell, SIGNAL( defaultAction( Incidence * ) ),
1269 SLOT( defaultAction( Incidence * ) ) ); 1269 SLOT( defaultAction( Incidence * ) ) );
1270 connect( cell, SIGNAL( newEventSignal( QDateTime ) ), 1270 connect( cell, SIGNAL( newEventSignal( QDateTime ) ),
1271 SIGNAL( newEventSignal( QDateTime ) ) ); 1271 SIGNAL( newEventSignal( QDateTime ) ) );
1272 connect( cell, SIGNAL( showDaySignal( QDate ) ), 1272 connect( cell, SIGNAL( showDaySignal( QDate ) ),
1273 SIGNAL( showDaySignal( QDate ) ) ); 1273 SIGNAL( showDaySignal( QDate ) ) );
1274 connect( cell, SIGNAL( nextCell() ), 1274 connect( cell, SIGNAL( nextCell() ),
1275 SLOT( nextCell() ) ); 1275 SLOT( nextCell() ) );
1276 connect( cell, SIGNAL( prevCell() ), 1276 connect( cell, SIGNAL( prevCell() ),
1277 SLOT( prevCell() ) ); 1277 SLOT( prevCell() ) );
1278 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ), 1278 connect( cell, SIGNAL( highlightIncidence( Incidence * , MonthViewCell *, int ) ),
1279 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) )); 1279 SLOT( incidenceHighlighted( Incidence *, MonthViewCell *, int ) ));
1280 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); 1280 cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont );
1281 } 1281 }
1282 1282
1283 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); 1283 //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) );
1284 mContextMenu = eventPopup(); 1284 mContextMenu = eventPopup();
1285 mContextMenu->addAdditionalItem(QIconSet(QPixmap()), 1285 mContextMenu->addAdditionalItem(QIconSet(QPixmap()),
1286 i18n("New Event..."),this, 1286 i18n("New Event..."),this,
1287 SLOT(slotNewEvent()),false); 1287 SLOT(slotNewEvent()),false);
1288 mContextMenu->addAdditionalItem(QIconSet(QPixmap()), 1288 mContextMenu->addAdditionalItem(QIconSet(QPixmap()),
1289 i18n("New Todo..."),this, 1289 i18n("New Todo..."),this,
1290 SLOT(slotNewTodo()),false); 1290 SLOT(slotNewTodo()),false);
1291 mContextMenu->addAdditionalItem(QIconSet(QPixmap()), 1291 mContextMenu->addAdditionalItem(QIconSet(QPixmap()),
1292 i18n("Journal"),this, 1292 i18n("Journal"),this,
1293 SLOT(slotEditJournal()),false); 1293 SLOT(slotEditJournal()),false);
1294 1294
1295 connect (mContextMenu ,SIGNAL(categoryChanged( Incidence * )),this, 1295 connect (mContextMenu ,SIGNAL(categoryChanged( Incidence * )),this,
1296 SLOT( catChanged( Incidence * ) )); 1296 SLOT( catChanged( Incidence * ) ));
1297 1297
1298 1298
1299 QString pathString = ""; 1299 QString pathString = "";
1300 if ( !KOPrefs::instance()->mToolBarMiniIcons ) { 1300 if ( !KOPrefs::instance()->mToolBarMiniIcons ) {
1301 if ( QApplication::desktop()->width() < 480 ) 1301 if ( QApplication::desktop()->width() < 480 )
1302 pathString += "icons16/"; 1302 pathString += "icons16/";
1303 } else 1303 } else
1304 pathString += "iconsmini/"; 1304 pathString += "iconsmini/";
1305 mNewItemMenu = new QPopupMenu( this ); 1305 mNewItemMenu = new QPopupMenu( this );
1306 mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent())); 1306 mNewItemMenu->insertItem( SmallIcon( pathString +"newevent" ), i18n("New Event..."),this, SLOT(slotNewEvent()));
1307 mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false); 1307 mNewItemMenu->insertItem( SmallIcon( pathString +"newtodo" ),i18n("New Todo..."),this,SLOT(slotNewTodo()),false);
1308 mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false); 1308 mNewItemMenu->insertItem( SmallIcon( pathString +"journal" ),i18n("Journal"),this,SLOT(slotEditJournal()),false);
1309 1309
1310 // updateConfig(); //useless here... 1310 // updateConfig(); //useless here...
1311 // ... but we need mWidthLongDayLabel computed 1311 // ... but we need mWidthLongDayLabel computed
1312 QFontMetrics fontmetric(mDayLabels[0]->font()); 1312 QFontMetrics fontmetric(mDayLabels[0]->font());
1313 mWidthLongDayLabel = 0; 1313 mWidthLongDayLabel = 0;
1314 for (int i = 0; i < 7; i++) { 1314 for (int i = 0; i < 7; i++) {
1315 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1315 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1316 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1316 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1317 } 1317 }
1318 1318
1319 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 1319 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
1320 1320
1321#if 0 1321#if 0
1322 if ( mShowWeekView ) 1322 if ( mShowWeekView )
1323 mWidStack->raiseWidget( mWeekView ); 1323 mWidStack->raiseWidget( mWeekView );
1324 else 1324 else
1325 mWidStack->raiseWidget( mMonthView ); 1325 mWidStack->raiseWidget( mMonthView );
1326#endif 1326#endif
1327 1327
1328 emit incidenceSelected( 0 ); 1328 emit incidenceSelected( 0 );
1329 1329
1330 mComputeLayoutTimer = new QTimer( this ); 1330 mComputeLayoutTimer = new QTimer( this );
1331 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout())); 1331 connect (mComputeLayoutTimer ,SIGNAL(timeout()), this, SLOT ( slotComputeLayout()));
1332 1332
1333 1333
1334#ifndef DESKTOP_VERSION 1334#ifndef DESKTOP_VERSION
1335 resize( QApplication::desktop()->size() ); 1335 resize( QApplication::desktop()->size() );
1336#else 1336#else
1337 resize(640, 480 ); 1337 resize(640, 480 );
1338 updatePossible = true; 1338 updatePossible = true;
1339#endif 1339#endif
1340 computeLayout(); 1340 computeLayout();
1341 1341
1342 if ( mShowWeekView ) 1342 if ( mShowWeekView )
1343 mWidStack->raiseWidget( mWeekView ); 1343 mWidStack->raiseWidget( mWeekView );
1344 else 1344 else
1345 mWidStack->raiseWidget( mMonthView ); 1345 mWidStack->raiseWidget( mMonthView );
1346} 1346}
1347 1347
1348KOMonthView::~KOMonthView() 1348KOMonthView::~KOMonthView()
1349{ 1349{
1350 delete mContextMenu; 1350 delete mContextMenu;
1351} 1351}
1352 1352
1353void KOMonthView::catChanged( Incidence * ) 1353void KOMonthView::catChanged( Incidence * )
1354{ 1354{
1355 updateView(); 1355 updateView();
1356} 1356}
1357void KOMonthView::incidenceHighlighted( Incidence * inc , MonthViewCell* mc, int mday ) 1357void KOMonthView::incidenceHighlighted( Incidence * inc , MonthViewCell* mc, int mday )
1358{ 1358{
1359 static Incidence * lastInc = 0; 1359 static Incidence * lastInc = 0;
1360 static MonthViewCell * lastCell = 0; 1360 static MonthViewCell * lastCell = 0;
1361 1361
1362 if ( lastInc == inc && lastCell == mc ) 1362 if ( lastInc == inc && lastCell == mc )
1363 return; 1363 return;
1364 lastInc = inc; 1364 lastInc = inc;
1365 lastCell = mc; 1365 lastCell = mc;
1366 //qDebug("KOMonthView::incidenceHighlighted %d %d %d", inc, mc, mday ); 1366 //qDebug("KOMonthView::incidenceHighlighted %d %d %d", inc, mc, mday );
1367 1367
1368 bool weekview = false; 1368 bool weekview = false;
1369 uint index = 0; 1369 uint index = 0;
1370 for (uint i = 0; i < mCellsW.count(); ++i) { 1370 for (uint i = 0; i < mCellsW.count(); ++i) {
1371 if ( mCellsW[i] == mc ) { 1371 if ( mCellsW[i] == mc ) {
1372 weekview = true; 1372 weekview = true;
1373 index = i; 1373 index = i;
1374 break; 1374 break;
1375 } 1375 }
1376 } 1376 }
1377 QPtrVector<MonthViewCell> *cells; 1377 QPtrVector<MonthViewCell> *cells;
1378 if ( weekview ) 1378 if ( weekview )
1379 cells = &mCellsW; 1379 cells = &mCellsW;
1380 else { 1380 else {
1381 for (uint i = 0; i < mCells.count(); ++i) { 1381 for (uint i = 0; i < mCells.count(); ++i) {
1382 if ( mCells[i] == mc ) { 1382 if ( mCells[i] == mc ) {
1383 index = i; 1383 index = i;
1384 break; 1384 break;
1385 } 1385 }
1386 } 1386 }
1387 cells = &mCells; 1387 cells = &mCells;
1388 } 1388 }
1389 for (uint i = 0; i < (*cells).count(); ++i) { 1389 for (uint i = 0; i < (*cells).count(); ++i) {
1390 (*cells)[i]->deHighLight(); 1390 (*cells)[i]->deHighLight();
1391 } 1391 }
1392 if ( ! inc ) 1392 if ( ! inc )
1393 return; 1393 return;
1394 1394
1395 uint count = (*cells).count(); 1395 uint count = (*cells).count();
1396 bool goLeft = (mday > 1 && index > 0); 1396 bool goLeft = (mday > 1 && index > 0);
1397 bool goRight = (mday < 3 && mday > 0 && index < count -1); 1397 bool goRight = (mday < 3 && mday > 0 && index < count -1);
1398 for (uint iii = 1; iii < count; ++iii) { 1398 for (uint iii = 1; iii < count; ++iii) {
1399 if ( goLeft ) { 1399 if ( goLeft ) {
1400 int left = index - iii; 1400 int left = index - iii;
1401 if ( left >= 0 ) { 1401 if ( left >= 0 ) {
1402 if ( (*cells)[(uint)left]->doHighLight(inc) ) 1402 if ( (*cells)[(uint)left]->doHighLight(inc) )
1403 goLeft = false; 1403 goLeft = false;
1404 } else 1404 } else
1405 goLeft = false; 1405 goLeft = false;
1406 } 1406 }
1407 if ( goRight ) { 1407 if ( goRight ) {
1408 uint right = index + iii; 1408 uint right = index + iii;
1409 if ( right < count ) { 1409 if ( right < count ) {
1410 if ( (*cells)[right]->doHighLight(inc) ) 1410 if ( (*cells)[right]->doHighLight(inc) )
1411 goRight = false; 1411 goRight = false;
1412 1412
1413 } else 1413 } else
1414 goRight = false; 1414 goRight = false;
1415 } 1415 }
1416 1416
1417 } 1417 }
1418#if 0 1418#if 0
1419 if ( mday > 1 && index > 0 ) 1419 if ( mday > 1 && index > 0 )
1420 for (int i = index-1; i >= 0; --i) { 1420 for (int i = index-1; i >= 0; --i) {
1421 //qDebug("index %d iii %d ", index, i); 1421 //qDebug("index %d iii %d ", index, i);
1422 if ( (*cells)[(uint)i]->doHighLight(inc) ) 1422 if ( (*cells)[(uint)i]->doHighLight(inc) )
1423 break; 1423 break;
1424 } 1424 }
1425 if ( mday < 3 && mday > 0 && index < (*cells).count()-1) 1425 if ( mday < 3 && mday > 0 && index < (*cells).count()-1)
1426 for (uint i = index+1; i < (*cells).count(); ++i) { 1426 for (uint i = index+1; i < (*cells).count(); ++i) {
1427 if ( (*cells)[i]->doHighLight(inc) ) 1427 if ( (*cells)[i]->doHighLight(inc) )
1428 break; 1428 break;
1429 } 1429 }
1430#endif 1430#endif
1431 1431
1432} 1432}
1433void KOMonthView::selectInternalWeekNum ( int n ) 1433void KOMonthView::selectInternalWeekNum ( int n )
1434{ 1434{
1435 switchView(); 1435 switchView();
1436 if ( !KOPrefs::instance()->mMonthViewWeek ) 1436 if ( !KOPrefs::instance()->mMonthViewWeek )
1437 emit selectMonth (); 1437 emit selectMonth ();
1438 else 1438 else
1439 emit selectWeekNum ( n ); 1439 emit selectWeekNum ( n );
1440} 1440}
1441 1441
1442int KOMonthView::currentWeek() 1442int KOMonthView::currentWeek()
1443{ 1443{
1444 if ( mShowWeekView ) 1444 if ( mShowWeekView )
1445 return mWeekLabelsW[0]->getWeekNum(); 1445 return mWeekLabelsW[0]->getWeekNum();
1446 return mWeekLabels[0]->getWeekNum(); 1446 return mWeekLabels[0]->getWeekNum();
1447} 1447}
1448void KOMonthView::switchView() 1448void KOMonthView::switchView()
1449{ 1449{
1450 if ( selectedCell( ) ) 1450 if ( selectedCell( ) )
1451 selectedCell()->deselect(); 1451 selectedCell()->deselect();
1452 mShowWeekView = !mShowWeekView; 1452 mShowWeekView = !mShowWeekView;
1453 KOPrefs::instance()->mMonthViewWeek = mShowWeekView; 1453 KOPrefs::instance()->mMonthViewWeek = mShowWeekView;
1454 if ( clPending ) { 1454 if ( clPending ) {
1455 computeLayout(); 1455 computeLayout();
1456 updateConfig(); 1456 updateConfig();
1457 } 1457 }
1458 if ( mShowWeekView ) 1458 if ( mShowWeekView )
1459 mWidStack->raiseWidget( mWeekView ); 1459 mWidStack->raiseWidget( mWeekView );
1460 else 1460 else
1461 mWidStack->raiseWidget( mMonthView ); 1461 mWidStack->raiseWidget( mMonthView );
1462 clPending = false; 1462 clPending = false;
1463} 1463}
1464 1464
1465int KOMonthView::maxDatesHint() 1465int KOMonthView::maxDatesHint()
1466{ 1466{
1467 return mNumCells; 1467 return mNumCells;
1468} 1468}
1469 1469
1470int KOMonthView::currentDateCount() 1470int KOMonthView::currentDateCount()
1471{ 1471{
1472 return mNumCells; 1472 return mNumCells;
1473} 1473}
1474 1474
1475QPtrList<Incidence> KOMonthView::selectedIncidences() 1475QPtrList<Incidence> KOMonthView::selectedIncidences()
1476{ 1476{
1477 QPtrList<Incidence> selected; 1477 QPtrList<Incidence> selected;
1478 1478
1479 if ( mSelectedCell ) { 1479 if ( mSelectedCell ) {
1480 Incidence *incidence = mSelectedCell->selectedIncidence(); 1480 Incidence *incidence = mSelectedCell->selectedIncidence();
1481 if ( incidence ) selected.append( incidence ); 1481 if ( incidence ) selected.append( incidence );
1482 } 1482 }
1483 1483
1484 return selected; 1484 return selected;
1485} 1485}
1486 1486
1487DateList KOMonthView::selectedDates() 1487DateList KOMonthView::selectedDates()
1488{ 1488{
1489 DateList selected; 1489 DateList selected;
1490 1490
1491 if ( mSelectedCell ) { 1491 if ( mSelectedCell ) {
1492 QDate qd = mSelectedCell->selectedIncidenceDate(); 1492 QDate qd = mSelectedCell->selectedIncidenceDate();
1493 if ( qd.isValid() ) selected.append( qd ); 1493 if ( qd.isValid() ) selected.append( qd );
1494 } 1494 }
1495 1495
1496 return selected; 1496 return selected;
1497} 1497}
1498#if 0 1498#if 0
1499void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd, 1499void KOMonthView::printPreview(CalPrinter *calPrinter, const QDate &fd,
1500 const QDate &td) 1500 const QDate &td)
1501{ 1501{
1502#ifndef KORG_NOPRINTER 1502#ifndef KORG_NOPRINTER
1503 calPrinter->preview(CalPrinter::Month, fd, td); 1503 calPrinter->preview(CalPrinter::Month, fd, td);
1504#endif 1504#endif
1505} 1505}
1506#endif 1506#endif
1507void KOMonthView::updateConfig() 1507void KOMonthView::updateConfig()
1508{ 1508{
1509 1509
1510 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1510 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1511 1511
1512 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1512 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1513 mWeekStartsMonday = true; 1513 mWeekStartsMonday = true;
1514 } 1514 }
1515 QFontMetrics fontmetric(mDayLabels[0]->font()); 1515 QFontMetrics fontmetric(mDayLabels[0]->font());
1516 mWidthLongDayLabel = 0; 1516 mWidthLongDayLabel = 0;
1517 1517
1518 for (int i = 0; i < 7; i++) { 1518 for (int i = 0; i < 7; i++) {
1519 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); 1519 int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1));
1520 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; 1520 if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width;
1521 } 1521 }
1522 bool temp = mShowSatSunComp ; 1522 bool temp = mShowSatSunComp ;
1523 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ; 1523 mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ;
1524 if ( ! mShowWeekView ) { 1524 if ( ! mShowWeekView ) {
1525 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog ) 1525 if ( temp != KOPrefs::instance()->mMonthViewSatSunTog )
1526 computeLayout(); 1526 computeLayout();
1527 } else 1527 } else
1528 doComputeLayoutWeek(); 1528 doComputeLayoutWeek();
1529 updateDayLabels(); 1529 updateDayLabels();
1530 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks); 1530 //qDebug("KOMonthView::updateConfig() %d %d %d ",height(), mDayLabels[0]->sizeHint().height() ,mNumWeeks);
1531 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks; 1531 //int cellHeight = (height() - mDayLabels[0]->sizeHint().height()) /mNumWeeks;
1532 //resizeEvent( 0 ); 1532 //resizeEvent( 0 );
1533 for (uint i = 0; i < mCells.count(); ++i) { 1533 for (uint i = 0; i < mCells.count(); ++i) {
1534 mCells[i]->updateConfig(); 1534 mCells[i]->updateConfig();
1535 } 1535 }
1536 1536
1537 for (uint i = 0; i < mCellsW.count(); ++i) { 1537 for (uint i = 0; i < mCellsW.count(); ++i) {
1538 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont); 1538 mCellsW[i]->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont);
1539 } 1539 }
1540#ifdef DESKTOP_VERSION 1540#ifdef DESKTOP_VERSION
1541 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips); 1541 MonthViewCell::toolTipGroup()->setEnabled(KOPrefs::instance()->mEnableToolTips);
1542#endif 1542#endif
1543 updateView(); 1543 updateView();
1544} 1544}
1545 1545
1546void KOMonthView::updateDayLabels() 1546void KOMonthView::updateDayLabels()
1547{ 1547{
1548 1548
1549 QPtrVector<QLabel> *mDayLabelsT; 1549 QPtrVector<QLabel> *mDayLabelsT;
1550 1550
1551 mDayLabelsT = &mDayLabelsW; 1551 mDayLabelsT = &mDayLabelsW;
1552 for (int i = 0; i < 7; i++) { 1552 for (int i = 0; i < 7; i++) {
1553 { 1553 {
1554 bool show = mShortDayLabelsW; 1554 bool show = mShortDayLabelsW;
1555 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1555 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1556 show = true; 1556 show = true;
1557 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1557 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1558 } 1558 }
1559 } 1559 }
1560 mDayLabelsT = &mDayLabels; 1560 mDayLabelsT = &mDayLabels;
1561 for (int i = 0; i < 7; i++) { 1561 for (int i = 0; i < 7; i++) {
1562 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) { 1562 if (KGlobal::locale()->weekStartsMonday() || KOPrefs::instance()->mMonthViewSatSunTog ) {
1563 bool show = mShortDayLabelsM; 1563 bool show = mShortDayLabelsM;
1564 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() ) 1564 if ( i > 4 && mShowSatSunComp && mWidthLongDayLabel > (*mDayLabelsT)[i]->width() )
1565 show = true; 1565 show = true;
1566 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show)); 1566 (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i+1,show));
1567 } else { 1567 } else {
1568 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM)); 1568 if (i==0) (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(7,mShortDayLabelsM));
1569 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM)); 1569 else (*mDayLabelsT)[i]->setText(KOGlobals::self()->calendarSystem()->weekDayName(i,mShortDayLabelsM));
1570 1570
1571 } 1571 }
1572 } 1572 }
1573 1573
1574} 1574}
1575 1575
1576void KOMonthView::clearList() 1576void KOMonthView::clearList()
1577{ 1577{
1578 unsigned int i; 1578 unsigned int i;
1579 for( i = 0; i < mCells.size(); ++i ) { 1579 for( i = 0; i < mCells.size(); ++i ) {
1580 mCells[i]->clear(); 1580 mCells[i]->clear();
1581 } 1581 }
1582 for( i = 0; i < mCellsW.size(); ++i ) { 1582 for( i = 0; i < mCellsW.size(); ++i ) {
1583 mCellsW[i]->clear(); 1583 mCellsW[i]->clear();
1584 } 1584 }
1585} 1585}
1586void KOMonthView::showDates(const QDate &start, const QDate &) 1586void KOMonthView::showDates(const QDate &start, const QDate &)
1587{ 1587{
1588 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl; 1588 // kdDebug() << "KOMonthView::showDates(): " << start.toString() << endl;
1589 1589
1590 QPtrVector<MonthViewCell> *cells; 1590 QPtrVector<MonthViewCell> *cells;
1591 QPtrVector<QLabel> *dayLabels; 1591 QPtrVector<QLabel> *dayLabels;
1592 QPtrVector<KOWeekButton> *weekLabels; 1592 QPtrVector<KOWeekButton> *weekLabels;
1593 uint weekNum = 6; 1593 uint weekNum = 6;
1594 mStartDate = start; 1594 mStartDate = start;
1595 if ( mShowWeekView ) { 1595 if ( mShowWeekView ) {
1596 weekNum = 1; 1596 weekNum = 1;
1597 cells = &mCellsW; 1597 cells = &mCellsW;
1598 dayLabels = &mDayLabelsW; 1598 dayLabels = &mDayLabelsW;
1599 weekLabels = &mWeekLabelsW; 1599 weekLabels = &mWeekLabelsW;
1600 if ( !KGlobal::locale()->weekStartsMonday() ) { 1600 if ( !KGlobal::locale()->weekStartsMonday() ) {
1601 mStartDate = mStartDate.addDays( 1 ); 1601 mStartDate = mStartDate.addDays( 1 );
1602 } 1602 }
1603 } else { 1603 } else {
1604 cells = &mCells; 1604 cells = &mCells;
1605 dayLabels = &mDayLabels; 1605 dayLabels = &mDayLabels;
1606 weekLabels = &mWeekLabels; 1606 weekLabels = &mWeekLabels;
1607 } 1607 }
1608 1608
1609 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday(); 1609 int mWeekStartsMonday = KGlobal::locale()->weekStartsMonday();
1610 1610
1611 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) { 1611 if ( mShowWeekView || KOPrefs::instance()->mMonthViewSatSunTog ) {
1612 mWeekStartsMonday = true; 1612 mWeekStartsMonday = true;
1613 } 1613 }
1614 int startWeekDay = mWeekStartsMonday ? 1 : 7; 1614 int startWeekDay = mWeekStartsMonday ? 1 : 7;
1615 1615
1616 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) { 1616 while( KOGlobals::self()->calendarSystem()->dayOfWeek(mStartDate) != startWeekDay ) {
1617 mStartDate = mStartDate.addDays( -1 ); 1617 mStartDate = mStartDate.addDays( -1 );
1618 } 1618 }
1619 uint i; 1619 uint i;
1620 for( i = 0; i < (*cells).size(); ++i ) { 1620 for( i = 0; i < (*cells).size(); ++i ) {
1621 QDate date = mStartDate.addDays( i ); 1621 QDate date = mStartDate.addDays( i );
1622 (*cells)[i]->setDate( date ); 1622 (*cells)[i]->setDate( date );
1623 1623
1624#ifndef KORG_NOPLUGINS 1624#ifndef KORG_NOPLUGINS
1625 // add holiday, if present 1625 // add holiday, if present
1626 QString hstring(KOCore::self()->holiday(date)); 1626 QString hstring(KOCore::self()->holiday(date));
1627 (*cells)[i]->setHoliday( hstring ); 1627 (*cells)[i]->setHoliday( hstring );
1628#endif 1628#endif
1629 1629
1630 } 1630 }
1631 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 ); 1631 QDate date = mStartDate.addDays( mWeekStartsMonday ? 3 : 4 );
1632 for( i = 0; i < weekNum; ++i ) { 1632 for( i = 0; i < weekNum; ++i ) {
1633 int wno; 1633 int wno;
1634 // remember, according to ISO 8601, the first week of the year is the 1634 // remember, according to ISO 8601, the first week of the year is the
1635 // first week that contains a thursday. Thus we must subtract off 4, 1635 // first week that contains a thursday. Thus we must subtract off 4,
1636 // not just 1. 1636 // not just 1.
1637 int dayOfYear = date.dayOfYear(); 1637 int dayOfYear = date.dayOfYear();
1638 if (dayOfYear % 7 != 0) 1638 if (dayOfYear % 7 != 0)
1639 wno = dayOfYear / 7 + 1; 1639 wno = dayOfYear / 7 + 1;
1640 else 1640 else
1641 wno =dayOfYear / 7; 1641 wno =dayOfYear / 7;
1642 (*weekLabels)[i]->setWeekNum( wno ); 1642 (*weekLabels)[i]->setWeekNum( wno );
1643 date = date.addDays( 7 ); 1643 date = date.addDays( 7 );
1644 } 1644 }
1645 updateView(); 1645 updateView();
1646} 1646}
1647 1647
1648void KOMonthView::showEvents(QPtrList<Event>) 1648void KOMonthView::showEvents(QPtrList<Event>)
1649{ 1649{
1650 qDebug("KOMonthView::selectEvents is not implemented yet. "); 1650 qDebug("KOMonthView::selectEvents is not implemented yet. ");
1651} 1651}
1652 1652
1653void KOMonthView::changeEventDisplay(Event *, int) 1653void KOMonthView::changeEventDisplay(Event *, int)
1654{ 1654{
1655 // this should be re-written to be much more efficient, but this 1655 // this should be re-written to be much more efficient, but this
1656 // quick-and-dirty-hack gets the job done for right now. 1656 // quick-and-dirty-hack gets the job done for right now.
1657 //qDebug("KOMonthView::changeEventDisplay "); 1657 //qDebug("KOMonthView::changeEventDisplay ");
1658 updateView(); 1658 updateView();
1659} 1659}
1660 1660
1661void KOMonthView::updateView() 1661void KOMonthView::updateView()
1662{ 1662{
1663 1663
1664 if ( !updatePossible ) 1664 if ( !updatePossible )
1665 return; 1665 return;
1666 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU "); 1666 //qDebug("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU ");
1667 //QTime ti; 1667 //QTime ti;
1668 //ti.start(); 1668 //ti.start();
1669 clearSelection(); 1669 clearSelection();
1670 QPtrVector<MonthViewCell> *cells; 1670 QPtrVector<MonthViewCell> *cells;
1671 if ( mShowWeekView ) { 1671 if ( mShowWeekView ) {
1672 cells = &mCellsW; 1672 cells = &mCellsW;
1673 } else { 1673 } else {
1674 cells = &mCells; 1674 cells = &mCells;
1675 } 1675 }
1676#if 1 1676#if 1
1677 int i; 1677 int i;
1678 int timeSpan = (*cells).size()-1; 1678 int timeSpan = (*cells).size()-1;
1679 if ( KOPrefs::instance()->mMonthViewWeek ) 1679 if ( KOPrefs::instance()->mMonthViewWeek )
1680 timeSpan = 6; 1680 timeSpan = 6;
1681 for( i = 0; i < timeSpan + 1; ++i ) { 1681 for( i = 0; i < timeSpan + 1; ++i ) {
1682 (*cells)[i]->startUpdateCell(); 1682 (*cells)[i]->startUpdateCell();
1683 } 1683 }
1684 1684
1685 QPtrList<Event> events = calendar()->events(); 1685 QPtrList<Event> events = calendar()->events();
1686 Event *event; 1686 Event *event;
1687 QDateTime dt; 1687 QDateTime dt;
1688 QDate endDate = mStartDate.addDays( timeSpan ); 1688 QDate endDate = mStartDate.addDays( timeSpan );
1689 for( event = events.first(); event; event = events.next() ) { // for event 1689 for( event = events.first(); event; event = events.next() ) { // for event
1690 if ( event->doesRecur() ) { 1690 if ( event->doesRecur() ) {
1691 bool last; 1691 bool last;
1692 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last ); 1692 QDateTime incidenceStart = event->recurrence()->getPreviousDateTime( QDateTime( mStartDate ) , &last );
1693 QDateTime incidenceEnd; 1693 QDateTime incidenceEnd;
1694 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() ); 1694 int eventlen = event->dtStart().date().daysTo ( event->dtEnd().date() );
1695 bool invalid = false; 1695 bool invalid = false;
1696 while( true ) { 1696 while( true ) {
1697 if ( incidenceStart.isValid() ) { 1697 if ( incidenceStart.isValid() ) {
1698 incidenceEnd = incidenceStart.addDays( eventlen ); 1698 incidenceEnd = incidenceStart.addDays( eventlen );
1699 int st = incidenceStart.date().daysTo( endDate ); 1699 int st = incidenceStart.date().daysTo( endDate );
1700 if ( st >= 0 ) { // start before timeend 1700 if ( st >= 0 ) { // start before timeend
1701 int end = mStartDate.daysTo( incidenceEnd.date() ); 1701 int end = mStartDate.daysTo( incidenceEnd.date() );
1702 if ( end >= 0 ) { // end after timestart --- got one! 1702 if ( end >= 0 ) { // end after timestart --- got one!
1703 //normalize 1703 //normalize
1704 st = timeSpan - st; 1704 st = timeSpan - st;
1705 if ( st < 0 ) st = 0; 1705 if ( st < 0 ) st = 0;
1706 if ( end > timeSpan ) end = timeSpan; 1706 if ( end > timeSpan ) end = timeSpan;
1707 int iii; 1707 int iii;
1708 //qDebug("found %s %d %d ",event->summary().latin1(), st, end ); 1708 //qDebug("found %s %d %d ",event->summary().latin1(), st, end );
1709 for ( iii = st;iii<= end;++iii) 1709 for ( iii = st;iii<= end;++iii)
1710 (*cells)[iii]->insertEvent( event ); 1710 (*cells)[iii]->insertEvent( event );
1711 } 1711 }
1712 } 1712 }
1713 } else { 1713 } else {
1714 if ( invalid ) 1714 if ( invalid )
1715 break; 1715 break;
1716 invalid = true; 1716 invalid = true;
1717 //qDebug("invalid %s", event->summary().latin1()); 1717 //qDebug("invalid %s", event->summary().latin1());
1718 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );; 1718 incidenceStart = QDateTime( mStartDate ).addSecs( -2 );;
1719 } 1719 }
1720 if ( last ) 1720 if ( last )
1721 break; 1721 break;
1722 bool ok; 1722 bool ok;
1723 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok ); 1723 incidenceStart = event->getNextOccurence( incidenceStart.addSecs( 1 ) ,&ok );
1724 if ( ! ok ) 1724 if ( ! ok )
1725 break; 1725 break;
1726 if ( incidenceStart.date() > endDate ) 1726 if ( incidenceStart.date() > endDate )
1727 break; 1727 break;
1728 } 1728 }
1729 } else { // no recur 1729 } else { // no recur
1730 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) 1730 if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") )
1731 if ( event->uid().left(15) == QString("last-syncEvent-") ) 1731 if ( event->uid().left(15) == QString("last-syncEvent-") )
1732 continue; 1732 continue;
1733 int st = event->dtStart().date().daysTo( endDate ); 1733 int st = event->dtStart().date().daysTo( endDate );
1734 if ( st >= 0 ) { // start before timeend 1734 if ( st >= 0 ) { // start before timeend
1735 int end = mStartDate.daysTo( event->dtEnd().date() ); 1735 int end = mStartDate.daysTo( event->dtEnd().date() );
1736 if ( end >= 0 ) { // end after timestart --- got one! 1736 if ( end >= 0 ) { // end after timestart --- got one!
1737 //normalize 1737 //normalize
1738 st = timeSpan - st; 1738 st = timeSpan - st;
1739 if ( st < 0 ) st = 0; 1739 if ( st < 0 ) st = 0;
1740 if ( end > timeSpan ) end = timeSpan; 1740 if ( end > timeSpan ) end = timeSpan;
1741 int iii; 1741 int iii;
1742 for ( iii = st;iii<= end;++iii) 1742 for ( iii = st;iii<= end;++iii)
1743 (*cells)[iii]->insertEvent( event ); 1743 (*cells)[iii]->insertEvent( event );
1744 } 1744 }
1745 } 1745 }
1746 } 1746 }
1747 } 1747 }
1748 // insert due todos 1748 // insert due todos
1749 QPtrList<Todo> todos = calendar()->todos( ); 1749 QPtrList<Todo> todos = calendar()->todos( );
1750 Todo *todo; 1750 Todo *todo;
1751 for(todo = todos.first(); todo; todo = todos.next()) { 1751 for(todo = todos.first(); todo; todo = todos.next()) {
1752 //insertTodo( todo ); 1752 //insertTodo( todo );
1753 if ( todo->hasDueDate() ) { 1753 if ( todo->hasDueDate() ) {
1754 int day = mStartDate.daysTo( todo->dtDue().date() ); 1754 int day = mStartDate.daysTo( todo->dtDue().date() );
1755 if ( day >= 0 && day < timeSpan + 1) { 1755 if ( day >= 0 && day < timeSpan + 1) {
1756 (*cells)[day]->insertTodo( todo ); 1756 (*cells)[day]->insertTodo( todo );
1757 } 1757 }
1758 } 1758 }
1759 } 1759 }
1760 1760
1761 for( i = 0; i < timeSpan+1; ++i ) { 1761 for( i = 0; i < timeSpan+1; ++i ) {
1762 (*cells)[i]->finishUpdateCell(); 1762 (*cells)[i]->finishUpdateCell();
1763 } 1763 }
1764 processSelectionChange(); 1764 processSelectionChange();
1765 //qApp->processEvents(); 1765 //qApp->processEvents();
1766 for( i = 0; i < timeSpan+1; ++i ) { 1766 for( i = 0; i < timeSpan+1; ++i ) {
1767 //(*cells)[i]->repaintfinishUpdateCell(); 1767 //(*cells)[i]->repaintfinishUpdateCell();
1768 QTimer::singleShot( 0, (*cells)[i], SLOT ( repaintfinishUpdateCell() ) ); 1768 QTimer::singleShot( 0, (*cells)[i], SLOT ( repaintfinishUpdateCell() ) );
1769 } 1769 }
1770 setKeyBFocus(); 1770 setKeyBFocus();
1771#else 1771#else
1772 // old code 1772 // old code
1773 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "); 1773 //qDebug("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
1774 int i; 1774 int i;
1775 for( i = 0; i < (*cells).count(); ++i ) { 1775 for( i = 0; i < (*cells).count(); ++i ) {
1776 (*cells)[i]->updateCell(); 1776 (*cells)[i]->updateCell();
1777 } 1777 }
1778 1778
1779 //qDebug("KOMonthView::updateView() "); 1779 //qDebug("KOMonthView::updateView() ");
1780 processSelectionChange(); 1780 processSelectionChange();
1781 // qDebug("---------------------------------------------------------------------+ "); 1781 // qDebug("---------------------------------------------------------------------+ ");
1782 (*cells)[0]->setFocus(); 1782 (*cells)[0]->setFocus();
1783#endif 1783#endif
1784 1784
1785 //qDebug("update time %d ", ti.elapsed()); 1785 //qDebug("update time %d ", ti.elapsed());
1786} 1786}
1787 1787
1788void KOMonthView::setKeyBoardFocus() 1788void KOMonthView::setKeyBoardFocus()
1789{ 1789{
1790 //qDebug("KOMonthView::setKeyBoardFocus() "); 1790 //qDebug("KOMonthView::setKeyBoardFocus() ");
1791 bool shootAgain = false; 1791 bool shootAgain = false;
1792 if ( mShowWeekView ) { 1792 if ( mShowWeekView ) {
1793 shootAgain = !mWeekLabelsW[1]->hasFocus(); 1793 shootAgain = !mWeekLabelsW[1]->hasFocus();
1794 mWeekLabelsW[1]->setFocus(); 1794 mWeekLabelsW[1]->setFocus();
1795 } 1795 }
1796 else { 1796 else {
1797 shootAgain = !mWeekLabels[mNumWeeks]->hasFocus(); 1797 shootAgain = !mWeekLabels[mNumWeeks]->hasFocus();
1798 mWeekLabels[mNumWeeks]->setFocus(); 1798 mWeekLabels[mNumWeeks]->setFocus();
1799 } 1799 }
1800 --mKBFcounter; 1800 --mKBFcounter;
1801 if ( shootAgain && mKBFcounter > 0 ) { 1801 if ( shootAgain && mKBFcounter > 0 ) {
1802 QTimer::singleShot( 50, this, SLOT ( setKeyBoardFocus() ) ); 1802 QTimer::singleShot( 50, this, SLOT ( setKeyBoardFocus() ) );
1803 } 1803 }
1804} 1804}
1805void KOMonthView::setKeyBFocus() 1805void KOMonthView::setKeyBFocus()
1806{ 1806{
1807 //qDebug("KOMonthView::setKeyBFocus() "); 1807 //qDebug("KOMonthView::setKeyBFocus() ");
1808 mKBFcounter = 10; 1808 mKBFcounter = 10;
1809 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) ); 1809 QTimer::singleShot( 0, this, SLOT ( setKeyBoardFocus() ) );
1810} 1810}
1811void KOMonthView::resizeEvent(QResizeEvent * e) 1811void KOMonthView::resizeEvent(QResizeEvent * e)
1812{ 1812{
1813 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height()); 1813 //qDebug("KOMonthView::resizeEvent %d %d -- %d %d ", e->size().width(), e->size().height(), e->oldSize().width(), e->oldSize().height());
1814 if ( isVisible() ) { 1814 if ( isVisible() ) {
1815 //qDebug("KOMonthView::isVisible "); 1815 //qDebug("KOMonthView::isVisible ");
1816 slotComputeLayout(); 1816 slotComputeLayout();
1817 } else 1817 } else
1818 mComputeLayoutTimer->start( 100 ); 1818 mComputeLayoutTimer->start( 100 );
1819 if ( e ) 1819 if ( e )
1820 KOEventView::resizeEvent( e ); 1820 KOEventView::resizeEvent( e );
1821} 1821}
1822 1822
1823void KOMonthView::slotComputeLayout() 1823void KOMonthView::slotComputeLayout()
1824{ 1824{
1825 mComputeLayoutTimer->stop(); 1825 mComputeLayoutTimer->stop();
1826 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() ); 1826 //qDebug("KOMonthView::Post - resizeEvent %d %d ", width(), height() );
1827 computeLayout(); 1827 computeLayout();
1828 clPending = true; 1828 clPending = true;
1829 setKeyBFocus(); 1829 setKeyBFocus();
1830} 1830}
1831 1831
1832void KOMonthView::doComputeLayoutWeek() 1832void KOMonthView::doComputeLayoutWeek()
1833{ 1833{
1834 1834
1835 int daysToShow; 1835 int daysToShow;
1836 bool combinedSatSun = false; 1836 bool combinedSatSun = false;
1837 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 1837 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
1838 daysToShow = 6; 1838 daysToShow = 6;
1839 combinedSatSun = true; 1839 combinedSatSun = true;
1840 } 1840 }
1841 int wid = width();//e 1841 int wid = width();//e
1842 int hei = height()-1-mNavigatorBar->height(); 1842 int hei = height()-1-mNavigatorBar->height();
1843#ifdef DESKTOP_VERSION
1843 if ( !KOPrefs::instance()->mMonthViewWeekRowlayout ) { 1844 if ( !KOPrefs::instance()->mMonthViewWeekRowlayout ) {
1844 daysToShow = 2; 1845 daysToShow = 2;
1845 } else { 1846 } else
1847#endif
1848 {
1846 if ( wid < hei ) 1849 if ( wid < hei )
1847 daysToShow = 2; 1850 daysToShow = 2;
1848 else 1851 else
1849 daysToShow = 3; 1852 daysToShow = 3;
1850 } 1853 }
1851 bool landscape = (daysToShow == 3); 1854 bool landscape = (daysToShow == 3);
1852 mShowSatSunComp = true; 1855 mShowSatSunComp = true;
1853 combinedSatSun = true; 1856 combinedSatSun = true;
1854 1857
1855 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ "); 1858 //qDebug("KOMonthView::computeLayout() WWW ------------------------------------ ");
1856 QFontMetrics fm ( mWeekLabels[0]->font() ); 1859 QFontMetrics fm ( mWeekLabels[0]->font() );
1857 int weeklabelwid = fm.width( "888" ); 1860 int weeklabelwid = fm.width( "888" );
1858 wid -= weeklabelwid; 1861 wid -= weeklabelwid;
1859 1862
1860 int colWid = wid / daysToShow; 1863 int colWid = wid / daysToShow;
1861 int dayLabelHei = mDayLabelsW[0]->sizeHint().height(); 1864 int dayLabelHei = mDayLabelsW[0]->sizeHint().height();
1862 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow ); 1865 int cellHei = (hei - (5- daysToShow )*dayLabelHei) /(5- daysToShow );
1863 int colModulo = wid % daysToShow; 1866 int colModulo = wid % daysToShow;
1864 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1; 1867 int rowModulo = (hei- (5- daysToShow )*dayLabelHei) % daysToShow-1;
1865 //qDebug("rowmod %d ", rowModulo); 1868 //qDebug("rowmod %d ", rowModulo);
1866 int i; 1869 int i;
1867 int x,y,w,h; 1870 int x,y,w,h;
1868 x= 0; 1871 x= 0;
1869 y= 0; 1872 y= 0;
1870 w = colWid; 1873 w = colWid;
1871 h = dayLabelHei ; 1874 h = dayLabelHei ;
1872 for ( i = 0; i < 7; i++) { 1875 for ( i = 0; i < 7; i++) {
1873 if ( i && !( i % daysToShow) && i < 6) { 1876 if ( i && !( i % daysToShow) && i < 6) {
1874 y += hei/(5-daysToShow); 1877 y += hei/(5-daysToShow);
1875 x = 0; 1878 x = 0;
1876 w = colWid; 1879 w = colWid;
1877 } 1880 }
1878 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1881 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1879 ++w; 1882 ++w;
1880 } 1883 }
1881 int xC,yC,wC,hC; 1884 int xC,yC,wC,hC;
1882 if ( i >= 5 ) { 1885 if ( i >= 5 ) {
1883 int wi = width() - x - weeklabelwid; 1886 int wi = width() - x - weeklabelwid;
1884 if ( i == 5 ) { 1887 if ( i == 5 ) {
1885 xC = x+weeklabelwid; 1888 xC = x+weeklabelwid;
1886 yC = y; 1889 yC = y;
1887 wC = wi/2+wi%2; 1890 wC = wi/2+wi%2;
1888 hC = h; 1891 hC = h;
1889 } else { 1892 } else {
1890 xC = x+weeklabelwid; 1893 xC = x+weeklabelwid;
1891 yC = y; 1894 yC = y;
1892 wC = wi; 1895 wC = wi;
1893 hC = h; 1896 hC = h;
1894 } 1897 }
1895 x = x - w + wi - (wi/2 ); 1898 x = x - w + wi - (wi/2 );
1896 } 1899 }
1897 else { 1900 else {
1898 int wi = w; 1901 int wi = w;
1899 if ( !(( i+1) % daysToShow)) { 1902 if ( !(( i+1) % daysToShow)) {
1900 wi = width() - x - weeklabelwid; 1903 wi = width() - x - weeklabelwid;
1901 } 1904 }
1902 xC = x+weeklabelwid; 1905 xC = x+weeklabelwid;
1903 yC = y; 1906 yC = y;
1904 wC = wi; 1907 wC = wi;
1905 hC = h; 1908 hC = h;
1906 } 1909 }
1907 mDayLabelsW[mapWeekLayout(i,landscape)]->setGeometry( xC,yC,wC,hC); 1910 mDayLabelsW[mapWeekLayout(i,landscape)]->setGeometry( xC,yC,wC,hC);
1908 1911
1909 1912
1910 x += w; 1913 x += w;
1911 } 1914 }
1912 x= 0; 1915 x= 0;
1913 y= dayLabelHei; 1916 y= dayLabelHei;
1914 w = colWid; 1917 w = colWid;
1915 h = cellHei; 1918 h = cellHei;
1916 int max = 0; 1919 int max = 0;
1917 int w_count = mCellsW.count(); 1920 int w_count = mCellsW.count();
1918 for ( i = 0; i < w_count; ++i) { 1921 for ( i = 0; i < w_count; ++i) {
1919 if ( i > 6 ) { 1922 if ( i > 6 ) {
1920 mCellsW[i]->hide(); 1923 mCellsW[i]->hide();
1921 continue; 1924 continue;
1922 } 1925 }
1923 1926
1924 w = colWid; 1927 w = colWid;
1925 if ( ((i) % daysToShow) >= daysToShow-colModulo ) { 1928 if ( ((i) % daysToShow) >= daysToShow-colModulo ) {
1926 ++w; 1929 ++w;
1927 } 1930 }
1928 if ( i == (daysToShow-1-rowModulo)*7) 1931 if ( i == (daysToShow-1-rowModulo)*7)
1929 ++h; 1932 ++h;
1930 1933
1931 int xC,yC,wC,hC; 1934 int xC,yC,wC,hC;
1932 if ( i >= 5 ) { 1935 if ( i >= 5 ) {
1933 if ( i ==5 ) { 1936 if ( i ==5 ) {
1934 max = h/2; 1937 max = h/2;
1935 xC = x+weeklabelwid; 1938 xC = x+weeklabelwid;
1936 yC = y; 1939 yC = y;
1937 wC = w; 1940 wC = w;
1938 hC = max; 1941 hC = max;
1939 x -= w ;y += h/2; 1942 x -= w ;y += h/2;
1940 } else { 1943 } else {
1941 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) { 1944 if ( ((i-1) % daysToShow) >= daysToShow-colModulo ) {
1942 ++w; 1945 ++w;
1943 } 1946 }
1944 max = h-h/2; 1947 max = h-h/2;
1945 xC = x+weeklabelwid; 1948 xC = x+weeklabelwid;
1946 yC = y; 1949 yC = y;
1947 wC = w; 1950 wC = w;
1948 hC = max; 1951 hC = max;
1949 y -= h/2; 1952 y -= h/2;
1950 } 1953 }
1951 } else { 1954 } else {
1952 max = h; 1955 max = h;
1953 xC = x+weeklabelwid; 1956 xC = x+weeklabelwid;
1954 yC = y; 1957 yC = y;
1955 wC = w; 1958 wC = w;
1956 hC = h; 1959 hC = h;
1957 } 1960 }
1958 mCellsW[mapWeekLayout(i,landscape)]->setGeometry ( xC,yC,wC,hC ); 1961 mCellsW[mapWeekLayout(i,landscape)]->setGeometry ( xC,yC,wC,hC );
1959 1962
1960 1963
1961 x += w; 1964 x += w;
1962 if ( x + w/2 > wid ) { 1965 if ( x + w/2 > wid ) {
1963 x = 0; 1966 x = 0;
1964 y += h+dayLabelHei ; 1967 y += h+dayLabelHei ;
1965 } 1968 }
1966 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 ); 1969 //mCellsW[i]->dateLabel()->setMaximumHeight( max - mCellsW[i]->lineWidth()*2 );
1967 } 1970 }
1968 y= dayLabelHei; 1971 y= dayLabelHei;
1969 h = cellHei ; 1972 h = cellHei ;
1970 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei); 1973 mWeekLabelsW[0]->setGeometry( 0,y,weeklabelwid,hei-dayLabelHei);
1971 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 1974 mWeekLabelsW[1]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
1972 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 1975 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
1973 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 1976 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
1974 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ; 1977 mShortDayLabelsW = mDayLabelsW[0]->width()-2 < mWidthLongDayLabel ;
1975 updateDayLabels(); 1978 updateDayLabels();
1976 //bool forceUpdate = !updatePossible; 1979 //bool forceUpdate = !updatePossible;
1977 updatePossible = true; 1980 updatePossible = true;
1978 //mWeekLabels[mNumWeeks]->setText( i18n("M")); 1981 //mWeekLabels[mNumWeeks]->setText( i18n("M"));
1979 //if ( forceUpdate ) 1982 //if ( forceUpdate )
1980 // updateView(); 1983 // updateView();
1981} 1984}
1982void KOMonthView::computeLayoutWeek() 1985void KOMonthView::computeLayoutWeek()
1983{ 1986{
1984 static int lastWid = 0; 1987 static int lastWid = 0;
1985 static int lastHei = 0; 1988 static int lastHei = 0;
1986 int tWid = topLevelWidget()->size().width(); 1989 int tWid = topLevelWidget()->size().width();
1987 int tHei = topLevelWidget()->size().height(); 1990 int tHei = topLevelWidget()->size().height();
1988 int wid = width();//e 1991 int wid = width();//e
1989 int hei = height()-1-mNavigatorBar->height(); 1992 int hei = height()-1-mNavigatorBar->height();
1990 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) 1993 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei )
1991 return; 1994 return;
1992 1995
1993 if ( lastWid == width() && lastHei == height() ) { 1996 if ( lastWid == width() && lastHei == height() ) {
1994 //qDebug("KOListWeekView::No compute layout needed "); 1997 //qDebug("KOListWeekView::No compute layout needed ");
1995 return; 1998 return;
1996 } 1999 }
1997 lastWid = width(); 2000 lastWid = width();
1998 lastHei = height(); 2001 lastHei = height();
1999 doComputeLayoutWeek(); 2002 doComputeLayoutWeek();
2000} 2003}
2001int KOMonthView::mapWeekLayout( int index, bool landscape ) 2004int KOMonthView::mapWeekLayout( int index, bool landscape )
2002{ 2005{
2003 if ( KOPrefs::instance()->mMonthViewWeekRowlayout ) 2006 if ( KOPrefs::instance()->mMonthViewWeekRowlayout )
2004 return index; 2007 return index;
2005 int diff = 0; 2008 int diff = 0;
2006 if ( !landscape ) diff = 1; 2009 if ( !landscape ) diff = 1;
2007 switch( index ) { 2010 switch( index ) {
2008 case 0: 2011 case 0:
2009 case 5: 2012 case 5:
2010 case 6: 2013 case 6:
2011 return index; 2014 return index;
2012 break; 2015 break;
2013 case 1: 2016 case 1:
2014 return 2+diff; 2017 return 2+diff;
2015 break; 2018 break;
2016 case 2: 2019 case 2:
2017 return 4-(3*diff); 2020 return 4-(3*diff);
2018 break; 2021 break;
2019 case 3: 2022 case 3:
2020 return 1+(3*diff); 2023 return 1+(3*diff);
2021 break; 2024 break;
2022 case 4: 2025 case 4:
2023 return 3-diff; 2026 return 3-diff;
2024 break; 2027 break;
2025 default: 2028 default:
2026 qDebug("KO: Error in mapping week layout "); 2029 qDebug("KO: Error in mapping week layout ");
2027 return index; 2030 return index;
2028 break; 2031 break;
2029 } 2032 }
2030 return index; 2033 return index;
2031} 2034}
2032void KOMonthView::computeLayout() 2035void KOMonthView::computeLayout()
2033{ 2036{
2034 2037
2035 2038
2036 static int lastWid = 0; 2039 static int lastWid = 0;
2037 static int lastHei = 0; 2040 static int lastHei = 0;
2038 2041
2039 if ( mShowWeekView ){ 2042 if ( mShowWeekView ){
2040 computeLayoutWeek(); 2043 computeLayoutWeek();
2041 return; 2044 return;
2042 } 2045 }
2043 int daysToShow = 7; 2046 int daysToShow = 7;
2044 bool combinedSatSun = false; 2047 bool combinedSatSun = false;
2045 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) { 2048 if (mShowSatSunComp = KOPrefs::instance()->mMonthViewSatSunTog ) {
2046 daysToShow = 6; 2049 daysToShow = 6;
2047 combinedSatSun = true; 2050 combinedSatSun = true;
2048 } 2051 }
2049 int tWid = topLevelWidget()->size().width(); 2052 int tWid = topLevelWidget()->size().width();
2050 int tHei = topLevelWidget()->size().height(); 2053 int tHei = topLevelWidget()->size().height();
2051 2054
2052 int wid = width();//e 2055 int wid = width();//e
2053 int hei = height()-1-mNavigatorBar->height(); 2056 int hei = height()-1-mNavigatorBar->height();
2054 2057
2055 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) { 2058 if ( ((wid *3)/2) < tWid && (( hei *3) /2) < tHei ) {
2056 return; 2059 return;
2057 } 2060 }
2058 if ( lastWid == width() && lastHei == height() ){ 2061 if ( lastWid == width() && lastHei == height() ){
2059 //qDebug("KOMonthview::No compute layout needed "); 2062 //qDebug("KOMonthview::No compute layout needed ");
2060 return; 2063 return;
2061 } 2064 }
2062 2065
2063 lastWid = width(); 2066 lastWid = width();
2064 lastHei = height(); 2067 lastHei = height();
2065 //qDebug("KOMonthView::computeLayout() MMM ------------------- "); 2068 //qDebug("KOMonthView::computeLayout() MMM ------------------- ");
2066 QFontMetrics fm ( mWeekLabels[0]->font() ); 2069 QFontMetrics fm ( mWeekLabels[0]->font() );
2067 int weeklabelwid = fm.width( "888" ); 2070 int weeklabelwid = fm.width( "888" );
2068 wid -= weeklabelwid; 2071 wid -= weeklabelwid;
2069 2072
2070 int colWid = wid / daysToShow; 2073 int colWid = wid / daysToShow;
2071 int dayLabelHei = mDayLabels[0]->sizeHint().height(); 2074 int dayLabelHei = mDayLabels[0]->sizeHint().height();
2072 int cellHei = (hei - dayLabelHei) /6; 2075 int cellHei = (hei - dayLabelHei) /6;
2073 int colModulo = wid % daysToShow; 2076 int colModulo = wid % daysToShow;
2074 int rowModulo = (hei- dayLabelHei) % 6; 2077 int rowModulo = (hei- dayLabelHei) % 6;
2075 //qDebug("rowmod %d ", rowModulo); 2078 //qDebug("rowmod %d ", rowModulo);
2076 int i; 2079 int i;
2077 int x,y,w,h; 2080 int x,y,w,h;
2078 x= 0; 2081 x= 0;
2079 y= 0; 2082 y= 0;
2080 w = colWid; 2083 w = colWid;
2081 h = dayLabelHei ; 2084 h = dayLabelHei ;
2082 for ( i = 0; i < 7; i++) { 2085 for ( i = 0; i < 7; i++) {
2083 if ( i == daysToShow-colModulo ) 2086 if ( i == daysToShow-colModulo )
2084 ++w; 2087 ++w;
2085 if ( combinedSatSun ) { 2088 if ( combinedSatSun ) {
2086 if ( i >= daysToShow-1 ) { 2089 if ( i >= daysToShow-1 ) {
2087 2090
2088 if ( i == 6 ) 2091 if ( i == 6 )
2089 mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h); 2092 mDayLabels[i]->setGeometry( x+weeklabelwid,y,width()-x-weeklabelwid,h);
2090 else 2093 else
2091 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h); 2094 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w/2,h);
2092 x -= w/2 ; 2095 x -= w/2 ;
2093 } 2096 }
2094 else 2097 else
2095 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 2098 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
2096 } else 2099 } else
2097 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h); 2100 mDayLabels[i]->setGeometry( x+weeklabelwid,y,w,h);
2098 x += w; 2101 x += w;
2099 } 2102 }
2100 x= 0; 2103 x= 0;
2101 y= dayLabelHei; 2104 y= dayLabelHei;
2102 w = colWid; 2105 w = colWid;
2103 h = cellHei ; 2106 h = cellHei ;
2104 int max = 0; 2107 int max = 0;
2105 int mc_count = mCells.count(); 2108 int mc_count = mCells.count();
2106 for ( i = 0; i < mc_count; ++i) { 2109 for ( i = 0; i < mc_count; ++i) {
2107 //qDebug("iii %d ", i); 2110 //qDebug("iii %d ", i);
2108 w = colWid; 2111 w = colWid;
2109 if ( ((i) % 7) >= 7-colModulo ) { 2112 if ( ((i) % 7) >= 7-colModulo ) {
2110 ++w; 2113 ++w;
2111 } 2114 }
2112 if ( i == (6-rowModulo)*7) 2115 if ( i == (6-rowModulo)*7)
2113 ++h; 2116 ++h;
2114 if ( combinedSatSun ) { 2117 if ( combinedSatSun ) {
2115 if ( (i)%7 >= daysToShow-1 ) { 2118 if ( (i)%7 >= daysToShow-1 ) {
2116 if ( (i)%7 == daysToShow-1 ) { 2119 if ( (i)%7 == daysToShow-1 ) {
2117 w = width()-x-weeklabelwid; 2120 w = width()-x-weeklabelwid;
2118 max = h/2; 2121 max = h/2;
2119 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 2122 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
2120 x -= w ;y += h/2; 2123 x -= w ;y += h/2;
2121 } else { 2124 } else {
2122 w = width()-x-weeklabelwid; 2125 w = width()-x-weeklabelwid;
2123 max = h-h/2; 2126 max = h-h/2;
2124 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max ); 2127 mCells[i]->setGeometry ( x+weeklabelwid,y,w,max );
2125 y -= h/2; 2128 y -= h/2;
2126 } 2129 }
2127 } else { 2130 } else {
2128 max = h; 2131 max = h;
2129 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 2132 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
2130 } 2133 }
2131 2134
2132 } 2135 }
2133 else { 2136 else {
2134 max = h; 2137 max = h;
2135 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h ); 2138 mCells[i]->setGeometry ( x+weeklabelwid,y,w,h );
2136 } 2139 }
2137 x += w; 2140 x += w;
2138 if ( x + w/2 > wid ) { 2141 if ( x + w/2 > wid ) {
2139 x = 0; 2142 x = 0;
2140 y += h; 2143 y += h;
2141 } 2144 }
2142 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 ); 2145 //mCells[i]->dateLabel()->setMaximumHeight( max- mCells[i]->lineWidth()*2 );
2143 } 2146 }
2144 y= dayLabelHei; 2147 y= dayLabelHei;
2145 h = cellHei ; 2148 h = cellHei ;
2146 for ( i = 0; i < 6; i++) { 2149 for ( i = 0; i < 6; i++) {
2147 if ( i == (6-rowModulo)) 2150 if ( i == (6-rowModulo))
2148 ++h; 2151 ++h;
2149 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h); 2152 mWeekLabels[i]->setGeometry( 0,y,weeklabelwid,h);
2150 y += h; 2153 y += h;
2151 } 2154 }
2152 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei); 2155 mWeekLabels[6]->setGeometry( 0,0,weeklabelwid,dayLabelHei);
2153 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height()); 2156 // qDebug("RRRRRRRRRRRRR %d %d old %d %d", e->size().width(),e->size().height() , e->oldSize().width(),e->oldSize().height());
2154 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height()); 2157 //qDebug("parent %d %d ", topLevelWidget()->size().width(), topLevelWidget()->size().height());
2155 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ; 2158 mShortDayLabelsM = mDayLabels[0]->width()-2 < mWidthLongDayLabel ;
2156 updateDayLabels(); 2159 updateDayLabels();
2157 //bool forceUpdate = !updatePossible; 2160 //bool forceUpdate = !updatePossible;
2158 updatePossible = true; 2161 updatePossible = true;
2159 //mWeekLabels[mNumWeeks]->setText( i18n("W")); 2162 //mWeekLabels[mNumWeeks]->setText( i18n("W"));
2160} 2163}
2161 2164
2162void KOMonthView::showContextMenu( Incidence *incidence ) 2165void KOMonthView::showContextMenu( Incidence *incidence )
2163{ 2166{
2164 if( incidence ) 2167 if( incidence )
2165 mContextMenu->showIncidencePopup(incidence); 2168 mContextMenu->showIncidencePopup(incidence);
2166 else { 2169 else {
2167 //qDebug("KOMonthView::showContextMenu "); 2170 //qDebug("KOMonthView::showContextMenu ");
2168 mNewItemMenu->popup(QCursor::pos()); 2171 mNewItemMenu->popup(QCursor::pos());
2169 } 2172 }
2170 /* 2173 /*
2171 if( incidence && incidence->typeID() == eventID ) { 2174 if( incidence && incidence->typeID() == eventID ) {
2172 Event *event = static_cast<Event *>(incidence); 2175 Event *event = static_cast<Event *>(incidence);
2173 mContextMenu->showEventPopup(event); 2176 mContextMenu->showEventPopup(event);
2174 } else { 2177 } else {
2175 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl; 2178 kdDebug() << "MonthView::showContextMenu(): cast failed." << endl;
2176 } 2179 }
2177 */ 2180 */
2178} 2181}
2179MonthViewCell * KOMonthView::selectedCell( ) 2182MonthViewCell * KOMonthView::selectedCell( )
2180{ 2183{
2181 return mSelectedCell; 2184 return mSelectedCell;
2182} 2185}
2183void KOMonthView::setSelectedCell( MonthViewCell *cell ) 2186void KOMonthView::setSelectedCell( MonthViewCell *cell )
2184{ 2187{
2185 //qDebug("KOMonthView::setSelectedCell %d", cell); 2188 //qDebug("KOMonthView::setSelectedCell %d", cell);
2186 if ( mSelectedCell && mSelectedCell != cell ) { 2189 if ( mSelectedCell && mSelectedCell != cell ) {
2187 MonthViewCell * mvc = mSelectedCell; 2190 MonthViewCell * mvc = mSelectedCell;
2188 mSelectedCell = cell; 2191 mSelectedCell = cell;
2189 mvc->deselect(); 2192 mvc->deselect();
2190 } else 2193 } else
2191 mSelectedCell = cell; 2194 mSelectedCell = cell;
2192 // if ( mSelectedCell ) 2195 // if ( mSelectedCell )
2193 // mSelectedCell->select(); 2196 // mSelectedCell->select();
2194 if ( !mSelectedCell ) 2197 if ( !mSelectedCell )
2195 emit incidenceSelected( 0 ); 2198 emit incidenceSelected( 0 );
2196 else 2199 else
2197 emit incidenceSelected( mSelectedCell->selectedIncidence() ); 2200 emit incidenceSelected( mSelectedCell->selectedIncidence() );
2198} 2201}
2199 2202
2200void KOMonthView::processSelectionChange() 2203void KOMonthView::processSelectionChange()
2201{ 2204{
2202 QPtrList<Incidence> incidences = selectedIncidences(); 2205 QPtrList<Incidence> incidences = selectedIncidences();
2203 if (incidences.count() > 0) { 2206 if (incidences.count() > 0) {
2204 emit incidenceSelected( incidences.first() ); 2207 emit incidenceSelected( incidences.first() );
2205 } else { 2208 } else {
2206 emit incidenceSelected( 0 ); 2209 emit incidenceSelected( 0 );
2207 clearSelection(); 2210 clearSelection();
2208 } 2211 }
2209} 2212}
2210 2213
2211void KOMonthView::clearSelection() 2214void KOMonthView::clearSelection()
2212{ 2215{
2213 if ( mSelectedCell ) { 2216 if ( mSelectedCell ) {
2214 mSelectedCell->deselect(); 2217 mSelectedCell->deselect();
2215 mSelectedCell = 0; 2218 mSelectedCell = 0;
2216 } 2219 }
2217} 2220}
2218 2221
2219void KOMonthView::keyReleaseEvent ( QKeyEvent * e) 2222void KOMonthView::keyReleaseEvent ( QKeyEvent * e)
2220{ 2223{
2221 if ( !e->isAutoRepeat() ) { 2224 if ( !e->isAutoRepeat() ) {
2222 mFlagKeyPressed = false; 2225 mFlagKeyPressed = false;
2223 } 2226 }
2224} 2227}
2225 2228
2226void KOMonthView::keyPressEvent ( QKeyEvent * e ) 2229void KOMonthView::keyPressEvent ( QKeyEvent * e )
2227{ 2230{
2228 2231
2229 qApp->processEvents(); 2232 qApp->processEvents();
2230 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 2233 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
2231 //e->ignore(); 2234 //e->ignore();
2232 e->accept(); 2235 e->accept();
2233 return; 2236 return;
2234 } 2237 }
2235 if (! e->isAutoRepeat() ) 2238 if (! e->isAutoRepeat() )
2236 mFlagKeyPressed = true; 2239 mFlagKeyPressed = true;
2237 switch(e->key()) { 2240 switch(e->key()) {
2238 case Key_Up: 2241 case Key_Up:
2239 { 2242 {
2240 if ( mShowWeekView ) { 2243 if ( mShowWeekView ) {
2241 emit selectWeekNum ( currentWeek() - 1 ); 2244 emit selectWeekNum ( currentWeek() - 1 );
2242 } 2245 }
2243 else { 2246 else {
2244 emit prevMonth(); 2247 emit prevMonth();
2245 } 2248 }
2246 } 2249 }
2247 e->accept(); 2250 e->accept();
2248 break; 2251 break;
2249 case Key_Down: 2252 case Key_Down:
2250 { 2253 {
2251 if ( mShowWeekView ) { 2254 if ( mShowWeekView ) {
2252 emit selectWeekNum ( currentWeek() +1); 2255 emit selectWeekNum ( currentWeek() +1);
2253 } 2256 }
2254 else { 2257 else {
2255 emit nextMonth(); 2258 emit nextMonth();
2256 } 2259 }
2257 2260
2258 } 2261 }
2259 e->accept(); 2262 e->accept();
2260 break; 2263 break;
2261 case Key_Return: 2264 case Key_Return:
2262 case Key_Enter: 2265 case Key_Enter:
2263 { 2266 {
2264 selectInternalWeekNum ( currentWeek() ); 2267 selectInternalWeekNum ( currentWeek() );
2265 } 2268 }
2266 e->accept(); 2269 e->accept();
2267 break; 2270 break;
2268 case Key_D: 2271 case Key_D:
2269 if ( mSelectedCell ) { 2272 if ( mSelectedCell ) {
2270 mSelectedCell->showDay(); 2273 mSelectedCell->showDay();
2271 e->accept(); 2274 e->accept();
2272 } else { 2275 } else {
2273 e->ignore(); 2276 e->ignore();
2274 } 2277 }
2275 break; 2278 break;
2276 default: 2279 default:
2277 e->ignore(); 2280 e->ignore();
2278 break; 2281 break;
2279 } 2282 }
2280} 2283}
2281 2284
2282void KOMonthView::nextCell() 2285void KOMonthView::nextCell()
2283{ 2286{
2284 focusNextPrevChild ( true ); 2287 focusNextPrevChild ( true );
2285} 2288}
2286void KOMonthView::prevCell() 2289void KOMonthView::prevCell()
2287{ 2290{
2288 focusNextPrevChild ( false ); 2291 focusNextPrevChild ( false );
2289} 2292}
2290 2293
2291void KOMonthView::slotNewTodo() 2294void KOMonthView::slotNewTodo()
2292{ 2295{
2293 //qDebug("KOMonthView::slotNewTodo() "); 2296 //qDebug("KOMonthView::slotNewTodo() ");
2294 if ( mPopupCell ){ 2297 if ( mPopupCell ){
2295 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 2298 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
2296 emit newTodoSignal(dt,true); 2299 emit newTodoSignal(dt,true);
2297 } 2300 }
2298 mPopupCell = 0; 2301 mPopupCell = 0;
2299} 2302}
2300void KOMonthView::slotNewEvent() 2303void KOMonthView::slotNewEvent()
2301{ 2304{
2302 if ( mPopupCell ) { 2305 if ( mPopupCell ) {
2303 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); 2306 QDateTime dt( mPopupCell->date(), QTime( KOPrefs::instance()->mStartTime, 0 ) );
2304 emit newEventSignal( dt ); 2307 emit newEventSignal( dt );
2305 } 2308 }
2306 //qDebug("KOMonthView::slotNewEvent() "); 2309 //qDebug("KOMonthView::slotNewEvent() ");
2307 mPopupCell = 0; 2310 mPopupCell = 0;
2308} 2311}
2309 2312
2310void KOMonthView::slotEditJournal() 2313void KOMonthView::slotEditJournal()
2311{ 2314{
2312 if ( mPopupCell ) 2315 if ( mPopupCell )
2313 emit showJournalSignal( 7, mPopupCell->date() ); 2316 emit showJournalSignal( 7, mPopupCell->date() );
2314 //qDebug("KOMonthView::slotEditJournal() "); 2317 //qDebug("KOMonthView::slotEditJournal() ");
2315 mPopupCell = 0; 2318 mPopupCell = 0;
2316} 2319}
2317 2320
2318void KOMonthView::setPopupCell( MonthViewCell * c) 2321void KOMonthView::setPopupCell( MonthViewCell * c)
2319{ 2322{
2320 mPopupCell = c; 2323 mPopupCell = c;
2321} 2324}