summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-03-21 10:47:16 (UTC)
committer zautrix <zautrix>2005-03-21 10:47:16 (UTC)
commitb40a7cc0a8cf0bd06b0f404f58e89980d1291beb (patch) (unidiff)
tree62e02fdc8eb02039eb7fa8a181b8ca879ef13e77 /korganizer
parent5b9e0451514d65ab576b51e0f9d3515fa6b9e4e6 (diff)
downloadkdepimpi-b40a7cc0a8cf0bd06b0f404f58e89980d1291beb.zip
kdepimpi-b40a7cc0a8cf0bd06b0f404f58e89980d1291beb.tar.gz
kdepimpi-b40a7cc0a8cf0bd06b0f404f58e89980d1291beb.tar.bz2
nf
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/datenavigatorcontainer.cpp10
-rw-r--r--korganizer/koagendaitem.cpp4
-rw-r--r--korganizer/koagendaitem.h2
-rw-r--r--korganizer/kodaymatrix.cpp6
-rw-r--r--korganizer/kodaymatrix.h2
-rw-r--r--korganizer/kotodoview.cpp3
-rw-r--r--korganizer/kotodoview.h2
7 files changed, 21 insertions, 8 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
index 5cdaa83..5941337 100644
--- a/korganizer/datenavigatorcontainer.cpp
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -1,257 +1,261 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 20
21 As a special exception, permission is given to link this program 21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable, 22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution. 23 without including the source code for Qt in the source distribution.
24*/ 24*/
25 25
26#include <kdebug.h> 26#include <kdebug.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29//#include "koglobals.h" 29//#include "koglobals.h"
30#include "navigatorbar.h" 30#include "navigatorbar.h"
31#include "kdatenavigator.h" 31#include "kdatenavigator.h"
32 32
33#include <kcalendarsystem.h> 33#include <kcalendarsystem.h>
34 34
35#include "datenavigatorcontainer.h" 35#include "datenavigatorcontainer.h"
36#include "koprefs.h" 36#include "koprefs.h"
37 37
38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, 38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
39 const char *name ) 39 const char *name )
40 : QWidget( parent, name ), mCalendar( 0 ), 40 : QWidget( parent, name ), mCalendar( 0 ),
41 mHorizontalCount( 1 ), mVerticalCount( 1 ) 41 mHorizontalCount( 1 ), mVerticalCount( 1 )
42{ 42{
43 mExtraViews.setAutoDelete( true ); 43 mExtraViews.setAutoDelete( true );
44 44
45 mNavigatorView = new KDateNavigator( this, name ); 45 mNavigatorView = new KDateNavigator( this, name );
46 46
47 connectNavigatorView( mNavigatorView ); 47 connectNavigatorView( mNavigatorView );
48} 48}
49 49
50DateNavigatorContainer::~DateNavigatorContainer() 50DateNavigatorContainer::~DateNavigatorContainer()
51{ 51{
52} 52}
53 53
54void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) 54void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
55{ 55{
56 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), 56 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
57 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 57 SIGNAL( datesSelected( const KCal::DateList & ) ) );
58#if 0 58#if 0
59 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), 59 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
60 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); 60 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
61 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), 61 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
62 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); 62 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
63#endif 63#endif
64 connect( v, SIGNAL( weekClicked( const QDate & ) ), 64 connect( v, SIGNAL( weekClicked( const QDate & ) ),
65 SIGNAL( weekClicked( const QDate & ) ) ); 65 SIGNAL( weekClicked( const QDate & ) ) );
66 66
67 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); 67 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
68 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); 68 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
69 69
70 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 70 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
71 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 71 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
72 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 72 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
73 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 73 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
74 74
75 connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); 75 connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) );
76} 76}
77 77
78void DateNavigatorContainer::setCalendar( Calendar *cal ) 78void DateNavigatorContainer::setCalendar( Calendar *cal )
79{ 79{
80 mCalendar = cal; 80 mCalendar = cal;
81 mNavigatorView->setCalendar( cal ); 81 mNavigatorView->setCalendar( cal );
82 KDateNavigator *n; 82 KDateNavigator *n;
83 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 83 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
84 n->setCalendar( cal ); 84 n->setCalendar( cal );
85 } 85 }
86} 86}
87 87
88void DateNavigatorContainer::updateDayMatrix() 88void DateNavigatorContainer::updateDayMatrix()
89{ 89{
90 mNavigatorView->updateDayMatrix(); 90 mNavigatorView->updateDayMatrix();
91 KDateNavigator *n; 91 KDateNavigator *n;
92 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 92 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
93 n->updateDayMatrix(); 93 n->updateDayMatrix();
94 } 94 }
95} 95}
96 96
97void DateNavigatorContainer::updateToday() 97void DateNavigatorContainer::updateToday()
98{ 98{
99 qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); 99 qDebug("DateNavigatorContainer::updateToday() NOT IMPL ");
100#if 0 100#if 0
101 mNavigatorView->updateToday(); 101 mNavigatorView->updateToday();
102 KDateNavigator *n; 102 KDateNavigator *n;
103 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 103 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
104 n->updateToday(); 104 n->updateToday();
105 } 105 }
106#endif 106#endif
107} 107}
108 108
109void DateNavigatorContainer::updateView() 109void DateNavigatorContainer::updateView()
110{ 110{
111 mNavigatorView->updateView(); 111 mNavigatorView->updateView();
112 KDateNavigator *n; 112 KDateNavigator *n;
113 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 113 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
114 n->updateView(); 114 n->updateView();
115 } 115 }
116} 116}
117 117
118void DateNavigatorContainer::updateConfig() 118void DateNavigatorContainer::updateConfig()
119{ 119{
120 mNavigatorView->updateConfig(); 120 mNavigatorView->updateConfig();
121 KDateNavigator *n; 121 KDateNavigator *n;
122 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 122 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
123 n->updateConfig(); 123 n->updateConfig();
124 } 124 }
125} 125}
126 126
127void DateNavigatorContainer::selectDates( const DateList &dateList ) 127void DateNavigatorContainer::selectDates( const DateList &dateList )
128{ 128{
129 mNavigatorView->selectDates( dateList ); 129 mNavigatorView->selectDates( dateList );
130 setBaseDates(); 130 setBaseDates();
131 if ( mExtraViews.count() ) { 131 if ( mExtraViews.count() ) {
132 KDateNavigator *view = mExtraViews.at( 0 ); 132 KDateNavigator *view = mExtraViews.at( 0 );
133 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 133 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
134 view->dayMatrix()->repaint(); 134 view->dayMatrix()->repaint();
135 } 135 }
136} 136}
137 137
138void DateNavigatorContainer::setBaseDates() 138void DateNavigatorContainer::setBaseDates()
139{ 139{
140 KCal::DateList dateList = mNavigatorView->selectedDates(); 140 KCal::DateList dateList = mNavigatorView->selectedDates();
141 if ( dateList.isEmpty() ) { 141 if ( dateList.isEmpty() ) {
142 kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; 142 kdError() << "DateNavigatorContainer::selectDates() empty list." << endl;
143 } 143 }
144 QDate baseDate = dateList.first(); 144 QDate baseDate = dateList.first();
145 KDateNavigator *n; 145 KDateNavigator *n;
146 bool doRepaint = false; // skip first repaint 146 bool doRepaint = false; // skip first repaint
147 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 147 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
148 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); 148 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 );
149 n->setBaseDate( baseDate, doRepaint ); 149 n->setBaseDate( baseDate, doRepaint );
150 doRepaint = true; 150 doRepaint = true;
151 } 151 }
152} 152}
153 153
154void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) 154void DateNavigatorContainer::resizeEvent( QResizeEvent * e )
155{ 155{
156#if 0 156#if 0
157 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; 157 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
158 kdDebug(5850) << " CURRENT SIZE: " << size() << endl; 158 kdDebug(5850) << " CURRENT SIZE: " << size() << endl;
159 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; 159 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
160 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; 160 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl;
161 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; 161 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl;
162#endif 162#endif
163 QSize minSize = mNavigatorView->sizeHintTwoButtons(); 163 QSize minSize = mNavigatorView->sizeHintTwoButtons();
164 164
165// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; 165// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
166 166
167 int verticalCount = size().height() / minSize.height(); 167 int verticalCount = size().height() / minSize.height();
168 int horizontalCount = size().width() / minSize.width(); 168 int horizontalCount = size().width() / minSize.width();
169 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); 169 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() );
170 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); 170 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount );
171 bool fontchange = false; 171 bool fontchange = false;
172 QFont fo; 172 QFont fo;
173 if ( horizontalCount != mHorizontalCount || 173 if ( horizontalCount != mHorizontalCount ||
174 verticalCount != mVerticalCount ) { 174 verticalCount != mVerticalCount ) {
175 uint count = horizontalCount * verticalCount; 175 uint count = horizontalCount * verticalCount;
176 if ( count == 0 ) { 176 if ( count == 0 ) {
177 bool ok; 177 bool ok;
178 fo = mNavigatorView->yourFontHint( size() , &ok); 178 fo = mNavigatorView->yourFontHint( size() , &ok);
179 //mNavigatorView->resize( size() ); 179 //mNavigatorView->resize( size() );
180 //if ( ! ok ) 180 //if ( ! ok )
181 // return; 181 // return;
182 minSize = mNavigatorView->sizeHintTwoButtons(); 182 minSize = mNavigatorView->sizeHintTwoButtons();
183 verticalCount = size().height() / minSize.height(); 183 verticalCount = size().height() / minSize.height();
184 horizontalCount = size().width() / minSize.width(); 184 horizontalCount = size().width() / minSize.width();
185 if ( horizontalCount == 0 ) 185 if ( horizontalCount == 0 )
186 horizontalCount = 1; 186 horizontalCount = 1;
187 if ( verticalCount == 0 ) 187 if ( verticalCount == 0 )
188 verticalCount = 1; 188 verticalCount = 1;
189 fontchange = true; 189 fontchange = true;
190 count = horizontalCount * verticalCount; 190 count = horizontalCount * verticalCount;
191 } else { 191 } else {
192 if ( mNavigatorView->fontChanged() ) { 192 if ( mNavigatorView->fontChanged() ) {
193 fontchange = true; 193 fontchange = true;
194 fo = KOPrefs::instance()->mDateNavigatorFont; 194 fo = KOPrefs::instance()->mDateNavigatorFont;
195 mNavigatorView->changeFont( fo ); 195 mNavigatorView->changeFont( fo );
196 mNavigatorView->unsetFontChanged(); 196 mNavigatorView->unsetFontChanged();
197 } 197 }
198 } 198 }
199 199
200 while ( count > ( mExtraViews.count() + 1 ) ) { 200 while ( count > ( mExtraViews.count() + 1 ) ) {
201 KDateNavigator *n = new KDateNavigator( this ); 201 KDateNavigator *n = new KDateNavigator( this );
202 n->setMonthSignalOffset ( mExtraViews.count()+1 ); 202 n->setMonthSignalOffset ( mExtraViews.count()+1 );
203 mExtraViews.append( n ); 203 mExtraViews.append( n );
204 n->setCalendar( mCalendar ); 204 n->setCalendar( mCalendar );
205 setBaseDates(); 205 setBaseDates();
206 connectNavigatorView( n ); 206 connectNavigatorView( n );
207 n->show(); 207 n->show();
208 } 208 }
209 209 int iii = 0;
210 while ( count < ( mExtraViews.count() + 1 ) ) { 210 while ( iii < ( mExtraViews.count() ) ) {
211 mExtraViews.removeLast(); 211 if ( iii < count-1 )
212 mExtraViews.at( iii )->show();
213 else
214 mExtraViews.at( iii )->hide();
215 ++iii;
212 } 216 }
213 if ( fontchange ) { 217 if ( fontchange ) {
214 //mNavigatorView->changeFont( fo ); 218 //mNavigatorView->changeFont( fo );
215 uint i; 219 uint i;
216 for( i = 0; i < mExtraViews.count(); ++i ) { 220 for( i = 0; i < mExtraViews.count(); ++i ) {
217 KDateNavigator *view = mExtraViews.at( i ); 221 KDateNavigator *view = mExtraViews.at( i );
218 view->changeFont( fo ); 222 view->changeFont( fo );
219 } 223 }
220 } 224 }
221 mHorizontalCount = horizontalCount; 225 mHorizontalCount = horizontalCount;
222 mVerticalCount = verticalCount; 226 mVerticalCount = verticalCount;
223 } 227 }
224 int height = size().height() / verticalCount; 228 int height = size().height() / verticalCount;
225 int width = size().width() / horizontalCount; 229 int width = size().width() / horizontalCount;
226 230
227 NavigatorBar *bar = mNavigatorView->navigatorBar(); 231 NavigatorBar *bar = mNavigatorView->navigatorBar();
228 if ( horizontalCount > 1 ) bar->showButtons( true, false ); 232 if ( horizontalCount > 1 ) bar->showButtons( true, false );
229 else bar->showButtons( true, true ); 233 else bar->showButtons( true, true );
230 234
231 mNavigatorView->setGeometry(0, 235 mNavigatorView->setGeometry(0,
232 0, width, height ); 236 0, width, height );
233 for( uint i = 0; i < mExtraViews.count(); ++i ) { 237 for( uint i = 0; i < mExtraViews.count(); ++i ) {
234 int x = ( i + 1 ) % horizontalCount; 238 int x = ( i + 1 ) % horizontalCount;
235 int y = ( i + 1 ) / horizontalCount; 239 int y = ( i + 1 ) / horizontalCount;
236 240
237 KDateNavigator *view = mExtraViews.at( i ); 241 KDateNavigator *view = mExtraViews.at( i );
238 bar = view->navigatorBar(); 242 bar = view->navigatorBar();
239 if ( y > 0 ) bar->showButtons( false, false ); 243 if ( y > 0 ) bar->showButtons( false, false );
240 else { 244 else {
241 if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); 245 if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
242 else bar->showButtons( false, false ); 246 else bar->showButtons( false, false );
243 } 247 }
244 view->setGeometry( x * width, 248 view->setGeometry( x * width,
245 y * height, width, height ); 249 y * height, width, height );
246 } 250 }
247} 251}
248 252
249QSize DateNavigatorContainer::minimumSizeHint() const 253QSize DateNavigatorContainer::minimumSizeHint() const
250{ 254{
251 return mNavigatorView->minimumSizeHint(); 255 return mNavigatorView->minimumSizeHint();
252} 256}
253 257
254QSize DateNavigatorContainer::sizeHint() const 258QSize DateNavigatorContainer::sizeHint() const
255{ 259{
256 return mNavigatorView->sizeHint(); 260 return mNavigatorView->sizeHint();
257} 261}
diff --git a/korganizer/koagendaitem.cpp b/korganizer/koagendaitem.cpp
index 0ea2860..19cc0e3 100644
--- a/korganizer/koagendaitem.cpp
+++ b/korganizer/koagendaitem.cpp
@@ -1,784 +1,784 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18*/ 18*/
19 19
20#include <qlabel.h> 20#include <qlabel.h>
21#include <qlayout.h> 21#include <qlayout.h>
22#include <qhbox.h> 22#include <qhbox.h>
23#include <qvbox.h> 23#include <qvbox.h>
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qdragobject.h> 26#include <qdragobject.h>
27#include <qdrawutil.h> 27#include <qdrawutil.h>
28#include <qpainter.h> 28#include <qpainter.h>
29 29
30#include <kiconloader.h> 30#include <kiconloader.h>
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <klocale.h> 33#include <klocale.h>
34#ifndef DESKTOP_VERSION 34#ifndef DESKTOP_VERSION
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#define AGENDA_ICON_SIZE 5 36#define AGENDA_ICON_SIZE 5
37#else 37#else
38#define AGENDA_ICON_SIZE 7 38#define AGENDA_ICON_SIZE 7
39#endif 39#endif
40#include <libkcal/icaldrag.h> 40#include <libkcal/icaldrag.h>
41#include <libkcal/vcaldrag.h> 41#include <libkcal/vcaldrag.h>
42#include <libkcal/kincidenceformatter.h> 42#include <libkcal/kincidenceformatter.h>
43extern int globalFlagBlockAgenda; 43extern int globalFlagBlockAgenda;
44extern int globalFlagBlockAgendaItemPaint; 44extern int globalFlagBlockAgendaItemPaint;
45extern int globalFlagBlockAgendaItemUpdate; 45extern int globalFlagBlockAgendaItemUpdate;
46 46
47#include "koprefs.h" 47#include "koprefs.h"
48 48
49#include "koagendaitem.h" 49#include "koagendaitem.h"
50//#include "koagendaitem.moc" 50//#include "koagendaitem.moc"
51 51
52 52
53//-------------------------------------------------------------------------- 53//--------------------------------------------------------------------------
54 54
55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0; 55QToolTipGroup *KOAgendaItem::mToolTipGroup = 0;
56 56
57//-------------------------------------------------------------------------- 57//--------------------------------------------------------------------------
58 58
59class KOAgendaItemWhatsThis :public QWhatsThis 59class KOAgendaItemWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { }; 62 KOAgendaItemWhatsThis( KOAgendaItem* view ) : QWhatsThis( view ),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& ) 65 virtual QString text( const QPoint& )
66 { 66 {
67 return _view->getWhatsThisText() ; 67 return _view->getWhatsThisText() ;
68 } 68 }
69private: 69private:
70 KOAgendaItem * _view; 70 KOAgendaItem * _view;
71}; 71};
72 72
73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday, 73KOAgendaItem::KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent,bool allday,
74 const char *name,WFlags) : 74 const char *name,WFlags) :
75 QWidget(parent, name), mIncidence(incidence), mDate(qd) 75 QWidget(parent, name), mIncidence(incidence), mDate(qd)
76{ 76{
77#ifndef DESKTOP_VERSION 77#ifndef DESKTOP_VERSION
78 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold ); 78 //QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
79#endif 79#endif
80 new KOAgendaItemWhatsThis(this); 80 mKOAgendaItemWhatsThis = new KOAgendaItemWhatsThis(this);
81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase 81 int wflags = getWFlags() |WRepaintNoErase;// WResizeNoErase
82 setWFlags ( wflags); 82 setWFlags ( wflags);
83 mAllDay = allday; 83 mAllDay = allday;
84 init ( incidence, qd ); 84 init ( incidence, qd );
85 //setMouseTracking(true); 85 //setMouseTracking(true);
86 //setAcceptDrops(true); 86 //setAcceptDrops(true);
87 xPaintCoord = -1; 87 xPaintCoord = -1;
88 yPaintCoord = -1; 88 yPaintCoord = -1;
89} 89}
90QString KOAgendaItem::getWhatsThisText() 90QString KOAgendaItem::getWhatsThisText()
91{ 91{
92 if ( mIncidence ) 92 if ( mIncidence )
93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence, 93 return KIncidenceFormatter::instance()->getFormattedText( mIncidence,
94 KOPrefs::instance()->mWTshowDetails, 94 KOPrefs::instance()->mWTshowDetails,
95 KOPrefs::instance()->mWTshowCreated, 95 KOPrefs::instance()->mWTshowCreated,
96 KOPrefs::instance()->mWTshowChanged); 96 KOPrefs::instance()->mWTshowChanged);
97 return "KOAgendaItem::getWhatsThisText()::internal error"; 97 return "KOAgendaItem::getWhatsThisText()::internal error";
98} 98}
99void KOAgendaItem::init ( Incidence *incidence, QDate qd ) 99void KOAgendaItem::init ( Incidence *incidence, QDate qd )
100{ 100{
101 mIncidence = incidence; 101 mIncidence = incidence;
102 mDate = qd; 102 mDate = qd;
103 mFirstMultiItem = 0; 103 mFirstMultiItem = 0;
104 mNextMultiItem = 0; 104 mNextMultiItem = 0;
105 mLastMultiItem = 0; 105 mLastMultiItem = 0;
106 computeText(); 106 computeText();
107 107
108 if ( (incidence->type() == "Todo") && 108 if ( (incidence->type() == "Todo") &&
109 ( !((static_cast<Todo*>(incidence))->isCompleted()) && 109 ( !((static_cast<Todo*>(incidence))->isCompleted()) &&
110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) { 110 ((static_cast<Todo*>(incidence))->dtDue().date() <= QDate::currentDate()) ) ) {
111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date()) 111 if ( (static_cast<Todo*>(incidence))->dtDue() < QDateTime::currentDateTime().date())
112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ; 112 mBackgroundColor = KOPrefs::instance()->mTodoOverdueColor ;
113 else 113 else
114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor; 114 mBackgroundColor = KOPrefs::instance()->mTodoDueTodayColor;
115 } 115 }
116 else { 116 else {
117 QStringList categories = mIncidence->categories(); 117 QStringList categories = mIncidence->categories();
118 QString cat = categories.first(); 118 QString cat = categories.first();
119 if (cat.isEmpty()) { 119 if (cat.isEmpty()) {
120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) 120 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) )
121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 121 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
122 else 122 else
123 mBackgroundColor =KOPrefs::instance()->mEventColor; 123 mBackgroundColor =KOPrefs::instance()->mEventColor;
124 } else { 124 } else {
125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat); 125 mBackgroundColor = *KOPrefs::instance()->categoryColor(cat);
126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) { 126 if ( (incidence->type() == "Todo") &&((static_cast<Todo*>(incidence))->isCompleted()) ) {
127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor ) 127 if ( mBackgroundColor == KOPrefs::instance()->mEventColor )
128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor; 128 mBackgroundColor =KOPrefs::instance()->mTodoDoneColor;
129 } 129 }
130 } 130 }
131 131
132 } 132 }
133 mColorGroup = QColorGroup( mBackgroundColor.light(), 133 mColorGroup = QColorGroup( mBackgroundColor.light(),
134 mBackgroundColor.dark(),mBackgroundColor.light(), 134 mBackgroundColor.dark(),mBackgroundColor.light(),
135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ; 135 mBackgroundColor.dark(),mBackgroundColor, black, mBackgroundColor) ;
136 setBackgroundColor( mBackgroundColor ); 136 setBackgroundColor( mBackgroundColor );
137 137
138 mConflictItems.clear(); 138 mConflictItems.clear();
139 setCellXY(0,0,1); 139 setCellXY(0,0,1);
140 setCellXWidth(0); 140 setCellXWidth(0);
141 setSubCell(0); 141 setSubCell(0);
142 setSubCells(1); 142 setSubCells(1);
143 setMultiItem(0,0,0); 143 setMultiItem(0,0,0);
144 startMove(); 144 startMove();
145 mSelected = true; 145 mSelected = true;
146 select(false); 146 select(false);
147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont); 147 QFontMetrics fontinf(KOPrefs::instance()->mAgendaViewFont);
148 mFontPixelSize = fontinf.height();; 148 mFontPixelSize = fontinf.height();;
149 hide(); 149 hide();
150 xPaintCoord = -1; 150 xPaintCoord = -1;
151 yPaintCoord = -1; 151 yPaintCoord = -1;
152} 152}
153 153
154 154
155KOAgendaItem::~KOAgendaItem() 155KOAgendaItem::~KOAgendaItem()
156{ 156{
157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( "); 157 // qDebug("deleteKOAgendaItem::~KOAgendaItem( ");
158 158 delete mKOAgendaItemWhatsThis;
159} 159}
160 160
161void KOAgendaItem::recreateIncidence() 161void KOAgendaItem::recreateIncidence()
162{ 162{
163#if 0 163#if 0
164 Incidence* newInc = mIncidence->clone(); 164 Incidence* newInc = mIncidence->clone();
165 newInc->recreate(); 165 newInc->recreate();
166 if ( mIncidence->doesRecur() ) { 166 if ( mIncidence->doesRecur() ) {
167 mIncidence->addExDate( mDate ); 167 mIncidence->addExDate( mDate );
168 newInc->recurrence()->unsetRecurs(); 168 newInc->recurrence()->unsetRecurs();
169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd()); 169 int len = mIncidence->dtStart().secsTo( ((Event*)mIncidence)->dtEnd());
170 QTime tim = mIncidence->dtStart().time(); 170 QTime tim = mIncidence->dtStart().time();
171 newInc->setDtStart( QDateTime(mDate, tim) ); 171 newInc->setDtStart( QDateTime(mDate, tim) );
172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 172 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
173 } 173 }
174#endif 174#endif
175 mIncidence = mIncidence->recreateCloneException( mDate ); 175 mIncidence = mIncidence->recreateCloneException( mDate );
176} 176}
177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout) 177bool KOAgendaItem::updateIcons(QPainter * p, bool horLayout)
178{ 178{
179 int size = AGENDA_ICON_SIZE; 179 int size = AGENDA_ICON_SIZE;
180 180
181 int yOff = 0; 181 int yOff = 0;
182 int xOff = 0; 182 int xOff = 0;
183 int x = pos().x() +3; 183 int x = pos().x() +3;
184 int y; 184 int y;
185 if ( mAllDay ) 185 if ( mAllDay )
186 y = pos().y()+3; 186 y = pos().y()+3;
187 else 187 else
188 y = mCellYTop * ( height() / cellHeight() ) +3; 188 y = mCellYTop * ( height() / cellHeight() ) +3;
189 if (mIncidence->cancelled()) { 189 if (mIncidence->cancelled()) {
190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x; 190 int xpos = xOff*( 1 +AGENDA_ICON_SIZE )+x;
191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y; 191 int ypos = yOff*( 1 +AGENDA_ICON_SIZE)+y;
192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 ); 192 p->drawLine( xpos, ypos, xpos+AGENDA_ICON_SIZE-1, ypos+AGENDA_ICON_SIZE-1 );
193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos ); 193 p->drawLine( xpos, ypos+AGENDA_ICON_SIZE-1, xpos+AGENDA_ICON_SIZE-1, ypos );
194 if ( horLayout ) 194 if ( horLayout )
195 ++xOff; 195 ++xOff;
196 else 196 else
197 ++yOff; 197 ++yOff;
198 } 198 }
199 if (mIncidence->isAlarmEnabled()) { 199 if (mIncidence->isAlarmEnabled()) {
200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red ); 200 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, red );
201 if ( horLayout ) 201 if ( horLayout )
202 ++xOff; 202 ++xOff;
203 else 203 else
204 ++yOff; 204 ++yOff;
205 } 205 }
206 if (mIncidence->recurrence()->doesRecur()) { 206 if (mIncidence->recurrence()->doesRecur()) {
207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue ); 207 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, blue );
208 if ( horLayout ) 208 if ( horLayout )
209 ++xOff; 209 ++xOff;
210 else 210 else
211 ++yOff; 211 ++yOff;
212 } 212 }
213 if (mIncidence->description().length() > 0) { 213 if (mIncidence->description().length() > 0) {
214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen ); 214 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkGreen );
215 if ( horLayout ) 215 if ( horLayout )
216 ++xOff; 216 ++xOff;
217 else 217 else
218 ++yOff; 218 ++yOff;
219 } 219 }
220 if (mIncidence->isReadOnly()) { 220 if (mIncidence->isReadOnly()) {
221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white ); 221 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, white );
222 if ( horLayout ) 222 if ( horLayout )
223 ++xOff; 223 ++xOff;
224 else 224 else
225 ++yOff; 225 ++yOff;
226 } 226 }
227 227
228 if (mIncidence->attendeeCount()>0) { 228 if (mIncidence->attendeeCount()>0) {
229 229
230 if (mIncidence->organizer() == KOPrefs::instance()->email()) { 230 if (mIncidence->organizer() == KOPrefs::instance()->email()) {
231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black ); 231 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, black );
232 if ( horLayout ) 232 if ( horLayout )
233 ++xOff; 233 ++xOff;
234 else 234 else
235 ++yOff; 235 ++yOff;
236 } else { 236 } else {
237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 237 Attendee *me = mIncidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
238 if (me!=0) { 238 if (me!=0) {
239 239
240 240
241 } else { 241 } else {
242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow ); 242 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, yellow );
243 if ( horLayout ) 243 if ( horLayout )
244 ++xOff; 244 ++xOff;
245 else 245 else
246 ++yOff; 246 ++yOff;
247 247
248 } 248 }
249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow ); 249 p->fillRect ( xOff*( 1 +AGENDA_ICON_SIZE )+x, yOff*( 1 +AGENDA_ICON_SIZE)+y, AGENDA_ICON_SIZE, AGENDA_ICON_SIZE, darkYellow );
250 if ( horLayout ) 250 if ( horLayout )
251 ++xOff; 251 ++xOff;
252 else 252 else
253 ++yOff; 253 ++yOff;
254 254
255 } 255 }
256 256
257 } 257 }
258 return ( yOff || xOff ); 258 return ( yOff || xOff );
259} 259}
260 260
261 261
262void KOAgendaItem::select(bool selected) 262void KOAgendaItem::select(bool selected)
263{ 263{
264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() ); 264 //qDebug("select %d %d",firstMultiItem(), nextMultiItem() );
265 if (mSelected == selected) return; 265 if (mSelected == selected) return;
266 mSelected = selected; 266 mSelected = selected;
267 if ( ! isVisible() ) 267 if ( ! isVisible() )
268 return; 268 return;
269 if ( firstMultiItem() ) 269 if ( firstMultiItem() )
270 firstMultiItem()->select( selected ); 270 firstMultiItem()->select( selected );
271 if ( !firstMultiItem() && nextMultiItem() ) { 271 if ( !firstMultiItem() && nextMultiItem() ) {
272 KOAgendaItem * placeItem = nextMultiItem(); 272 KOAgendaItem * placeItem = nextMultiItem();
273 while ( placeItem ) { 273 while ( placeItem ) {
274 placeItem->select( selected ); 274 placeItem->select( selected );
275 placeItem = placeItem->nextMultiItem(); 275 placeItem = placeItem->nextMultiItem();
276 } 276 }
277 } 277 }
278 globalFlagBlockAgendaItemUpdate = 0; 278 globalFlagBlockAgendaItemUpdate = 0;
279 paintMe( selected ); 279 paintMe( selected );
280 globalFlagBlockAgendaItemUpdate = 1; 280 globalFlagBlockAgendaItemUpdate = 1;
281 repaint( false ); 281 repaint( false );
282} 282}
283 283
284 284
285/* 285/*
286 The eventFilter has to filter the mouse events of the agenda item childs. The 286 The eventFilter has to filter the mouse events of the agenda item childs. The
287 events are fed into the event handling method of KOAgendaItem. This allows the 287 events are fed into the event handling method of KOAgendaItem. This allows the
288 KOAgenda to handle the KOAgendaItems by using an eventFilter. 288 KOAgenda to handle the KOAgendaItems by using an eventFilter.
289*/ 289*/
290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e ) 290bool KOAgendaItem::eventFilter ( QObject *object, QEvent *e )
291{ 291{
292 if (e->type() == QEvent::MouseButtonPress || 292 if (e->type() == QEvent::MouseButtonPress ||
293 e->type() == QEvent::MouseButtonDblClick || 293 e->type() == QEvent::MouseButtonDblClick ||
294 e->type() == QEvent::MouseButtonRelease || 294 e->type() == QEvent::MouseButtonRelease ||
295 e->type() == QEvent::MouseMove) { 295 e->type() == QEvent::MouseMove) {
296 QMouseEvent *me = (QMouseEvent *)e; 296 QMouseEvent *me = (QMouseEvent *)e;
297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)-> 297 QPoint itemPos = this->mapFromGlobal(((QWidget *)object)->
298 mapToGlobal(me->pos())); 298 mapToGlobal(me->pos()));
299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state()); 299 QMouseEvent returnEvent (e->type(),itemPos,me->button(),me->state());
300 return event(&returnEvent); 300 return event(&returnEvent);
301 } else { 301 } else {
302 return false; 302 return false;
303 } 303 }
304} 304}
305void KOAgendaItem::repaintMe( ) 305void KOAgendaItem::repaintMe( )
306{ 306{
307 paintMe ( mSelected ); 307 paintMe ( mSelected );
308} 308}
309void KOAgendaItem::paintMe( bool selected, QPainter* paint ) 309void KOAgendaItem::paintMe( bool selected, QPainter* paint )
310{ 310{
311 if ( globalFlagBlockAgendaItemUpdate && ! selected) 311 if ( globalFlagBlockAgendaItemUpdate && ! selected)
312 return; 312 return;
313 QPainter pa; 313 QPainter pa;
314 314
315 if ( mSelected ) { 315 if ( mSelected ) {
316 pa.begin( paintPixSel() ); 316 pa.begin( paintPixSel() );
317 } else { 317 } else {
318 if ( mAllDay ) 318 if ( mAllDay )
319 pa.begin( paintPixAllday() ); 319 pa.begin( paintPixAllday() );
320 else 320 else
321 pa.begin( paintPix() ); 321 pa.begin( paintPix() );
322 } 322 }
323 int x, yy, w, h; 323 int x, yy, w, h;
324 float nfh = 7.0; 324 float nfh = 7.0;
325 x = pos().x(); w = width(); h = height (); 325 x = pos().x(); w = width(); h = height ();
326 if ( mAllDay ) 326 if ( mAllDay )
327 yy = y(); 327 yy = y();
328 else 328 else
329 yy = mCellYTop * ( height() / cellHeight() ); 329 yy = mCellYTop * ( height() / cellHeight() );
330 xPaintCoord= x; 330 xPaintCoord= x;
331 yPaintCoord = yy; 331 yPaintCoord = yy;
332 wPaintCoord = width(); 332 wPaintCoord = width();
333 hPaintCoord = height(); 333 hPaintCoord = height();
334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height()); 334 //qDebug("paintMe %s %d %d %d %d",incidence()->summary().latin1(), x, yy, width(), height());
335 if ( paint == 0 ) 335 if ( paint == 0 )
336 paint = &pa; 336 paint = &pa;
337 bool horLayout = ( w < h ); 337 bool horLayout = ( w < h );
338 int maxhei = mFontPixelSize+4; 338 int maxhei = mFontPixelSize+4;
339 if ( horLayout ) 339 if ( horLayout )
340 maxhei += AGENDA_ICON_SIZE -4; 340 maxhei += AGENDA_ICON_SIZE -4;
341 bool small = ( h < maxhei ); 341 bool small = ( h < maxhei );
342 if ( ! small ) 342 if ( ! small )
343 paint->setFont(KOPrefs::instance()->mAgendaViewFont); 343 paint->setFont(KOPrefs::instance()->mAgendaViewFont);
344 else { 344 else {
345 QFont f = KOPrefs::instance()->mAgendaViewFont; 345 QFont f = KOPrefs::instance()->mAgendaViewFont;
346 f.setBold( false ); 346 f.setBold( false );
347 int fh = f.pointSize(); 347 int fh = f.pointSize();
348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh; 348 nfh = (((float)height())/(float)(mFontPixelSize+4))*fh;
349 if ( nfh < 6 ) 349 if ( nfh < 6 )
350 nfh = 6; 350 nfh = 6;
351 f.setPointSize( nfh ); 351 f.setPointSize( nfh );
352 paint->setFont(f); 352 paint->setFont(f);
353 } 353 }
354 paint->fillRect ( x, yy, w, h, mBackgroundColor ); 354 paint->fillRect ( x, yy, w, h, mBackgroundColor );
355 static const QPixmap completedPxmp = SmallIcon("greenhook16"); 355 static const QPixmap completedPxmp = SmallIcon("greenhook16");
356 static const QPixmap overduePxmp = SmallIcon("redcross16"); 356 static const QPixmap overduePxmp = SmallIcon("redcross16");
357 if ( mIncidence->type() == "Todo" ) { 357 if ( mIncidence->type() == "Todo" ) {
358 Todo* tempTodo = static_cast<Todo*>(mIncidence); 358 Todo* tempTodo = static_cast<Todo*>(mIncidence);
359 int xx = pos().x()+(width()-completedPxmp.width()-3 ); 359 int xx = pos().x()+(width()-completedPxmp.width()-3 );
360 int yyy = yy+3; 360 int yyy = yy+3;
361 if ( tempTodo->isCompleted() ) 361 if ( tempTodo->isCompleted() )
362 paint->drawPixmap ( xx, yyy, completedPxmp ); 362 paint->drawPixmap ( xx, yyy, completedPxmp );
363 else { 363 else {
364 paint->drawPixmap ( xx, yyy, overduePxmp ); 364 paint->drawPixmap ( xx, yyy, overduePxmp );
365 365
366 } 366 }
367 } 367 }
368 bool addIcon = false; 368 bool addIcon = false;
369 if ( ! small || w > 3 * h || h > 3* w ) 369 if ( ! small || w > 3 * h || h > 3* w )
370 addIcon = updateIcons( paint, horLayout ); 370 addIcon = updateIcons( paint, horLayout );
371 371
372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0); 372 qDrawShadePanel (paint, x, yy, w, h, mColorGroup, selected , 2, 0);
373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h ); 373 //qDebug("draw rect %d %d %d %d ",x, yy, w, h );
374 if ( ! small ) { 374 if ( ! small ) {
375 x += 3; yy += 3;w -= 6; h-= 5; 375 x += 3; yy += 3;w -= 6; h-= 5;
376 } else { 376 } else {
377 x += 2; yy += 1;w -= 4; h-= 4; 377 x += 2; yy += 1;w -= 4; h-= 4;
378 if ( nfh < 6.01 ) { 378 if ( nfh < 6.01 ) {
379 yy -= 2; 379 yy -= 2;
380 h += 4; 380 h += 4;
381 } 381 }
382 else 382 else
383 if ( nfh < h -2 ) 383 if ( nfh < h -2 )
384 ++yy; 384 ++yy;
385 } 385 }
386 int align; 386 int align;
387#ifndef DESKTOP_VERSION 387#ifndef DESKTOP_VERSION
388 align = ( AlignLeft|WordBreak|AlignTop); 388 align = ( AlignLeft|WordBreak|AlignTop);
389#else 389#else
390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop); 390 align = ( AlignLeft|BreakAnywhere|WordBreak|AlignTop);
391#endif 391#endif
392 if ( addIcon ) { 392 if ( addIcon ) {
393 if ( ! horLayout ) { 393 if ( ! horLayout ) {
394 x += AGENDA_ICON_SIZE+3; 394 x += AGENDA_ICON_SIZE+3;
395 w -= (AGENDA_ICON_SIZE+3); 395 w -= (AGENDA_ICON_SIZE+3);
396 } 396 }
397 else { 397 else {
398 yy+= AGENDA_ICON_SIZE+2; 398 yy+= AGENDA_ICON_SIZE+2;
399 h -=(AGENDA_ICON_SIZE+3); 399 h -=(AGENDA_ICON_SIZE+3);
400 } 400 }
401 } 401 }
402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue(); 402 int colsum = mBackgroundColor.red() + mBackgroundColor.green() + mBackgroundColor.blue();
403 if ( colsum < 250 ) 403 if ( colsum < 250 )
404 paint->setPen ( white); 404 paint->setPen ( white);
405 if ( x < 0 ) { 405 if ( x < 0 ) {
406 w = w+x-3; 406 w = w+x-3;
407 x = 3; 407 x = 3;
408 if ( w > parentWidget()->width() ){ 408 if ( w > parentWidget()->width() ){
409 w = parentWidget()->width() - 6; 409 w = parentWidget()->width() - 6;
410#ifndef DESKTOP_VERSION 410#ifndef DESKTOP_VERSION
411 align = ( AlignHCenter|WordBreak|AlignTop); 411 align = ( AlignHCenter|WordBreak|AlignTop);
412#else 412#else
413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop); 413 align = ( AlignHCenter|BreakAnywhere|WordBreak|AlignTop);
414#endif 414#endif
415 415
416 } 416 }
417 } 417 }
418 QRect dr; 418 QRect dr;
419 if ( w + x > parentWidget()->width() ) 419 if ( w + x > parentWidget()->width() )
420 w = parentWidget()->width()-x; 420 w = parentWidget()->width()-x;
421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr ); 421 paint->drawText ( x, yy, w, h, align, mDisplayedText, -1, &dr );
422 //qDebug("%d %d %d %d ", x, yy, w, h ); 422 //qDebug("%d %d %d %d ", x, yy, w, h );
423 if ( mIncidence->cancelled() ){ 423 if ( mIncidence->cancelled() ){
424 if ( ! small ) { 424 if ( ! small ) {
425 QFontMetrics fm ( paint->font() ); 425 QFontMetrics fm ( paint->font() );
426 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2); 426 paint->drawLine(dr.left(), yy+fm.height()/2, dr.right()-2, yy+fm.height()/2);
427 } 427 }
428 428
429 } 429 }
430 pa.end(); 430 pa.end();
431 431
432} 432}
433void KOAgendaItem::resizePixmap( int w , int h ) 433void KOAgendaItem::resizePixmap( int w , int h )
434{ 434{
435 paintPix()->resize( w, h ); 435 paintPix()->resize( w, h );
436 paintPixSel()->resize( w, h ); 436 paintPixSel()->resize( w, h );
437 437
438} 438}
439QPixmap * KOAgendaItem::paintPix() 439QPixmap * KOAgendaItem::paintPix()
440{ 440{
441 static QPixmap* mPaintPix = 0; 441 static QPixmap* mPaintPix = 0;
442 if ( ! mPaintPix ) 442 if ( ! mPaintPix )
443 mPaintPix = new QPixmap(1,1); 443 mPaintPix = new QPixmap(1,1);
444 return mPaintPix ; 444 return mPaintPix ;
445} 445}
446QPixmap * KOAgendaItem::paintPixAllday() 446QPixmap * KOAgendaItem::paintPixAllday()
447{ 447{
448 static QPixmap* mPaintPixA = 0; 448 static QPixmap* mPaintPixA = 0;
449 if ( ! mPaintPixA ) 449 if ( ! mPaintPixA )
450 mPaintPixA = new QPixmap(1,1); 450 mPaintPixA = new QPixmap(1,1);
451 return mPaintPixA ; 451 return mPaintPixA ;
452} 452}
453QPixmap * KOAgendaItem::paintPixSel() 453QPixmap * KOAgendaItem::paintPixSel()
454{ 454{
455 static QPixmap* mPaintPixSel = 0; 455 static QPixmap* mPaintPixSel = 0;
456 if ( ! mPaintPixSel ) 456 if ( ! mPaintPixSel )
457 mPaintPixSel = new QPixmap(1,1); 457 mPaintPixSel = new QPixmap(1,1);
458 return mPaintPixSel ; 458 return mPaintPixSel ;
459} 459}
460void KOAgendaItem::paintEvent ( QPaintEvent *e ) 460void KOAgendaItem::paintEvent ( QPaintEvent *e )
461{ 461{
462 462
463 if ( globalFlagBlockAgendaItemPaint ) 463 if ( globalFlagBlockAgendaItemPaint )
464 return; 464 return;
465 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 ) 465 if ( globalFlagBlockAgenda > 0 && globalFlagBlockAgenda < 5 )
466 return; 466 return;
467 int yy; 467 int yy;
468 if ( mAllDay ) 468 if ( mAllDay )
469 yy = y(); 469 yy = y();
470 else 470 else
471 yy = mCellYTop * ( height() / cellHeight() ); 471 yy = mCellYTop * ( height() / cellHeight() );
472 int xx = x(); 472 int xx = x();
473 if ( xPaintCoord != xx || yPaintCoord != yy || 473 if ( xPaintCoord != xx || yPaintCoord != yy ||
474 wPaintCoord != width() || hPaintCoord != height()) { 474 wPaintCoord != width() || hPaintCoord != height()) {
475 xPaintCoord= xx; 475 xPaintCoord= xx;
476 yPaintCoord = yy; 476 yPaintCoord = yy;
477 wPaintCoord = width(); 477 wPaintCoord = width();
478 hPaintCoord = height(); 478 hPaintCoord = height();
479 globalFlagBlockAgendaItemUpdate = 0; 479 globalFlagBlockAgendaItemUpdate = 0;
480 paintMe( mSelected ); 480 paintMe( mSelected );
481 //qDebug("calling paintMe "); 481 //qDebug("calling paintMe ");
482 globalFlagBlockAgendaItemUpdate = 1; 482 globalFlagBlockAgendaItemUpdate = 1;
483 } 483 }
484 int rx, ry, rw, rh; 484 int rx, ry, rw, rh;
485 rx = e->rect().x(); 485 rx = e->rect().x();
486 ry = e->rect().y(); 486 ry = e->rect().y();
487 rw = e->rect().width(); 487 rw = e->rect().width();
488 rh = e->rect().height(); 488 rh = e->rect().height();
489 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height()); 489 //qDebug(" paintevent %s %d %d %d %d", mIncidence->summary().latin1(), x(), yy, width(), height());
490 490
491 QPixmap* paintFrom ; 491 QPixmap* paintFrom ;
492 if ( mSelected ) { 492 if ( mSelected ) {
493 paintFrom = paintPixSel(); 493 paintFrom = paintPixSel();
494 } else { 494 } else {
495 if ( mAllDay ) 495 if ( mAllDay )
496 paintFrom = paintPixAllday(); 496 paintFrom = paintPixAllday();
497 else 497 else
498 paintFrom = paintPix(); 498 paintFrom = paintPix();
499 } 499 }
500 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP); 500 bitBlt (this, rx, ry, paintFrom, x()+rx ,yPaintCoord+ry, rw, rh ,CopyROP);
501} 501}
502void KOAgendaItem::computeText() 502void KOAgendaItem::computeText()
503{ 503{
504 504
505 mDisplayedText = mIncidence->summary(); 505 mDisplayedText = mIncidence->summary();
506 if ( (mIncidence->type() == "Todo") ) { 506 if ( (mIncidence->type() == "Todo") ) {
507 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) { 507 if ( static_cast<Todo*>(mIncidence)->hasDueDate() ) {
508 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() ) 508 if ( static_cast<Todo*>(mIncidence)->dtDue().date() < QDate::currentDate() )
509 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")"; 509 mDisplayedText += i18n(" (") +KGlobal::locale()->formatDate((static_cast<Todo*>(mIncidence))->dtDue().date(), true)+")";
510 else if ( !(mIncidence->doesFloat())) 510 else if ( !(mIncidence->doesFloat()))
511 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")"; 511 mDisplayedText += i18n(" (") +KGlobal::locale()->formatTime((static_cast<Todo*>(mIncidence))->dtDue().time())+")";
512 } 512 }
513 } else { 513 } else {
514 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda) 514 if ( !(mIncidence->doesFloat()) && KOPrefs::instance()->mShowTimeInAgenda)
515 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ; 515 mDisplayedText += ": " +KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtStart().time()) + "-" + KGlobal::locale()->formatTime((static_cast<Event*>(mIncidence))->dtEnd().time()) ;
516 516
517 if ( mAllDay ) { 517 if ( mAllDay ) {
518 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) { 518 if ( mIncidence->dtStart().date().addDays(3) < mIncidence->dtEnd().date() ) {
519 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ; 519 mDisplayedText += ": " +KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtStart().date(), true) + " - " + KGlobal::locale()->formatDate((static_cast<Event*>(mIncidence))->dtEnd().date(), true) ;
520 } 520 }
521 } 521 }
522 522
523 } 523 }
524 524
525 if ( !mIncidence->location().isEmpty() ) { 525 if ( !mIncidence->location().isEmpty() ) {
526 if ( mAllDay ) 526 if ( mAllDay )
527 mDisplayedText += " ("; 527 mDisplayedText += " (";
528 else 528 else
529 mDisplayedText += "\n("; 529 mDisplayedText += "\n(";
530 mDisplayedText += mIncidence->location() +")"; 530 mDisplayedText += mIncidence->location() +")";
531 } 531 }
532 532
533 QString tipText = mIncidence->summary(); 533 QString tipText = mIncidence->summary();
534 if ( !mIncidence->doesFloat() ) { 534 if ( !mIncidence->doesFloat() ) {
535 if ( mIncidence->type() == "Event" ) { 535 if ( mIncidence->type() == "Event" ) {
536 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) { 536 if ( (static_cast<Event*>(mIncidence))->isMultiDay() ) {
537 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr(); 537 tipText += "\n"+i18n("From: ")+mIncidence->dtStartStr();
538 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr(); 538 tipText += "\n"+i18n("To: ")+(static_cast<Event*>(mIncidence))->dtEndStr();
539 } 539 }
540 else { 540 else {
541 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr(); 541 tipText += "\n"+i18n("Time: ")+mIncidence->dtStartTimeStr();
542 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr(); 542 tipText += " - "+(static_cast<Event*>(mIncidence))->dtEndTimeStr();
543 } 543 }
544 } 544 }
545 else if ( mIncidence->type() == "Todo" ) { 545 else if ( mIncidence->type() == "Todo" ) {
546 if (mIncidence->hasStartDate()) 546 if (mIncidence->hasStartDate())
547 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr(); 547 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartStr();
548 if (((Todo*)mIncidence)->hasDueDate()) 548 if (((Todo*)mIncidence)->hasDueDate())
549 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr(); 549 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueStr();
550 } 550 }
551 } else if ( mIncidence->type() == "Todo" ) { 551 } else if ( mIncidence->type() == "Todo" ) {
552 if (mIncidence->hasStartDate()) 552 if (mIncidence->hasStartDate())
553 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr(); 553 tipText += "\n"+i18n("Start: ")+ (static_cast<Todo*>(mIncidence))->dtStartDateStr();
554 if (((Todo*)mIncidence)->hasDueDate()) 554 if (((Todo*)mIncidence)->hasDueDate())
555 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr(); 555 tipText += "\n"+i18n("Due: ")+ (static_cast<Todo*>(mIncidence))->dtDueDateStr();
556 } 556 }
557 557
558 if (!mIncidence->location().isEmpty()) { 558 if (!mIncidence->location().isEmpty()) {
559 tipText += "\n"+i18n("Location: ")+mIncidence->location(); 559 tipText += "\n"+i18n("Location: ")+mIncidence->location();
560 } 560 }
561 QToolTip::add(this,tipText,toolTipGroup(),""); 561 QToolTip::add(this,tipText,toolTipGroup(),"");
562 562
563} 563}
564void KOAgendaItem::updateItem() 564void KOAgendaItem::updateItem()
565{ 565{
566 computeText(); 566 computeText();
567 567
568 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y()); 568 //qDebug("KOAgendaItem:: updateItem() %s %d %d ",incidence()->summary().latin1(), x(), y());
569 paintMe( mSelected ); 569 paintMe( mSelected );
570 repaint( false); 570 repaint( false);
571} 571}
572 572
573void KOAgendaItem::resizeEvent ( QResizeEvent *ev ) 573void KOAgendaItem::resizeEvent ( QResizeEvent *ev )
574{ 574{
575 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1()); 575 //qDebug("KOAgendaItem::resizeEvent %s ", mIncidence->summary().latin1());
576 paintMe( mSelected ); 576 paintMe( mSelected );
577 repaint( false ); 577 repaint( false );
578} 578}
579 579
580/* 580/*
581 Return height of item in units of agenda cells 581 Return height of item in units of agenda cells
582*/ 582*/
583int KOAgendaItem::cellHeight() 583int KOAgendaItem::cellHeight()
584{ 584{
585 int ret = mCellYBottom - mCellYTop + 1; 585 int ret = mCellYBottom - mCellYTop + 1;
586 if ( ret <= 0 ) { 586 if ( ret <= 0 ) {
587 ret = 1; 587 ret = 1;
588 mCellYBottom = 0; 588 mCellYBottom = 0;
589 mCellYTop = 0; 589 mCellYTop = 0;
590 } 590 }
591 return ret; 591 return ret;
592} 592}
593 593
594/* 594/*
595 Return height of item in units of agenda cells 595 Return height of item in units of agenda cells
596*/ 596*/
597int KOAgendaItem::cellWidth() 597int KOAgendaItem::cellWidth()
598{ 598{
599 return mCellXWidth - mCellX + 1; 599 return mCellXWidth - mCellX + 1;
600} 600}
601 601
602void KOAgendaItem::setItemDate(QDate qd) 602void KOAgendaItem::setItemDate(QDate qd)
603{ 603{
604 mDate = qd; 604 mDate = qd;
605} 605}
606 606
607void KOAgendaItem::setCellXY(int X, int YTop, int YBottom) 607void KOAgendaItem::setCellXY(int X, int YTop, int YBottom)
608{ 608{
609 mCellX = X; 609 mCellX = X;
610 mCellYTop = YTop; 610 mCellYTop = YTop;
611 mCellYBottom = YBottom; 611 mCellYBottom = YBottom;
612} 612}
613 613
614void KOAgendaItem::setCellXWidth(int xwidth) 614void KOAgendaItem::setCellXWidth(int xwidth)
615{ 615{
616 mCellXWidth = xwidth; 616 mCellXWidth = xwidth;
617} 617}
618 618
619void KOAgendaItem::setCellX(int XLeft, int XRight) 619void KOAgendaItem::setCellX(int XLeft, int XRight)
620{ 620{
621 mCellX = XLeft; 621 mCellX = XLeft;
622 mCellXWidth = XRight; 622 mCellXWidth = XRight;
623} 623}
624 624
625void KOAgendaItem::setCellY(int YTop, int YBottom) 625void KOAgendaItem::setCellY(int YTop, int YBottom)
626{ 626{
627 mCellYTop = YTop; 627 mCellYTop = YTop;
628 mCellYBottom = YBottom; 628 mCellYBottom = YBottom;
629} 629}
630 630
631void KOAgendaItem::setSubCell(int subCell) 631void KOAgendaItem::setSubCell(int subCell)
632{ 632{
633 mSubCell = subCell; 633 mSubCell = subCell;
634} 634}
635 635
636void KOAgendaItem::setSubCells(int subCells) 636void KOAgendaItem::setSubCells(int subCells)
637{ 637{
638 mSubCells = subCells; 638 mSubCells = subCells;
639} 639}
640 640
641void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 641void KOAgendaItem::setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
642 KOAgendaItem *last) 642 KOAgendaItem *last)
643{ 643{
644 mFirstMultiItem = first; 644 mFirstMultiItem = first;
645 mNextMultiItem = next; 645 mNextMultiItem = next;
646 mLastMultiItem = last; 646 mLastMultiItem = last;
647} 647}
648 648
649void KOAgendaItem::startMove() 649void KOAgendaItem::startMove()
650{ 650{
651 mStartCellX = mCellX; 651 mStartCellX = mCellX;
652 mStartCellXWidth = mCellXWidth; 652 mStartCellXWidth = mCellXWidth;
653 mStartCellYTop = mCellYTop; 653 mStartCellYTop = mCellYTop;
654 mStartCellYBottom = mCellYBottom; 654 mStartCellYBottom = mCellYBottom;
655} 655}
656 656
657void KOAgendaItem::resetMove() 657void KOAgendaItem::resetMove()
658{ 658{
659 mCellX = mStartCellX; 659 mCellX = mStartCellX;
660 mCellXWidth = mStartCellXWidth; 660 mCellXWidth = mStartCellXWidth;
661 mCellYTop = mStartCellYTop; 661 mCellYTop = mStartCellYTop;
662 mCellYBottom = mStartCellYBottom; 662 mCellYBottom = mStartCellYBottom;
663} 663}
664 664
665void KOAgendaItem::moveRelative(int dx, int dy) 665void KOAgendaItem::moveRelative(int dx, int dy)
666{ 666{
667 int newX = cellX() + dx; 667 int newX = cellX() + dx;
668 int newXWidth = cellXWidth() + dx; 668 int newXWidth = cellXWidth() + dx;
669 int newYTop = cellYTop() + dy; 669 int newYTop = cellYTop() + dy;
670 int newYBottom = cellYBottom() + dy; 670 int newYBottom = cellYBottom() + dy;
671 setCellXY(newX,newYTop,newYBottom); 671 setCellXY(newX,newYTop,newYBottom);
672 setCellXWidth(newXWidth); 672 setCellXWidth(newXWidth);
673} 673}
674 674
675void KOAgendaItem::expandTop(int dy) 675void KOAgendaItem::expandTop(int dy)
676{ 676{
677 int newYTop = cellYTop() + dy; 677 int newYTop = cellYTop() + dy;
678 int newYBottom = cellYBottom(); 678 int newYBottom = cellYBottom();
679 if (newYTop > newYBottom) newYTop = newYBottom; 679 if (newYTop > newYBottom) newYTop = newYBottom;
680 setCellY(newYTop, newYBottom); 680 setCellY(newYTop, newYBottom);
681} 681}
682 682
683void KOAgendaItem::expandBottom(int dy) 683void KOAgendaItem::expandBottom(int dy)
684{ 684{
685 int newYTop = cellYTop(); 685 int newYTop = cellYTop();
686 int newYBottom = cellYBottom() + dy; 686 int newYBottom = cellYBottom() + dy;
687 if (newYBottom < newYTop) newYBottom = newYTop; 687 if (newYBottom < newYTop) newYBottom = newYTop;
688 setCellY(newYTop, newYBottom); 688 setCellY(newYTop, newYBottom);
689} 689}
690 690
691void KOAgendaItem::expandLeft(int dx) 691void KOAgendaItem::expandLeft(int dx)
692{ 692{
693 int newX = cellX() + dx; 693 int newX = cellX() + dx;
694 int newXWidth = cellXWidth(); 694 int newXWidth = cellXWidth();
695 if (newX > newXWidth) newX = newXWidth; 695 if (newX > newXWidth) newX = newXWidth;
696 setCellX(newX,newXWidth); 696 setCellX(newX,newXWidth);
697} 697}
698 698
699void KOAgendaItem::expandRight(int dx) 699void KOAgendaItem::expandRight(int dx)
700{ 700{
701 int newX = cellX(); 701 int newX = cellX();
702 int newXWidth = cellXWidth() + dx; 702 int newXWidth = cellXWidth() + dx;
703 if (newXWidth < newX) newXWidth = newX; 703 if (newXWidth < newX) newXWidth = newX;
704 setCellX(newX,newXWidth); 704 setCellX(newX,newXWidth);
705} 705}
706 706
707QToolTipGroup *KOAgendaItem::toolTipGroup() 707QToolTipGroup *KOAgendaItem::toolTipGroup()
708{ 708{
709 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); 709 if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0);
710 return mToolTipGroup; 710 return mToolTipGroup;
711} 711}
712 712
713void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e ) 713void KOAgendaItem::dragEnterEvent( QDragEnterEvent *e )
714{ 714{
715#ifndef KORG_NODND 715#ifndef KORG_NODND
716 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) || 716 if ( ICalDrag::canDecode( e ) || VCalDrag::canDecode( e ) ||
717 !QTextDrag::canDecode( e ) ) { 717 !QTextDrag::canDecode( e ) ) {
718 e->ignore(); 718 e->ignore();
719 return; 719 return;
720 } 720 }
721 e->accept(); 721 e->accept();
722#endif 722#endif
723} 723}
724 724
725void KOAgendaItem::dropEvent( QDropEvent *e ) 725void KOAgendaItem::dropEvent( QDropEvent *e )
726{ 726{
727#ifndef KORG_NODND 727#ifndef KORG_NODND
728 QString text; 728 QString text;
729 if(QTextDrag::decode(e,text)) 729 if(QTextDrag::decode(e,text))
730 { 730 {
731 kdDebug() << "Dropped : " << text << endl; 731 kdDebug() << "Dropped : " << text << endl;
732 QStringList emails = QStringList::split(",",text); 732 QStringList emails = QStringList::split(",",text);
733 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 733 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
734 kdDebug() << " Email: " << (*it) << endl; 734 kdDebug() << " Email: " << (*it) << endl;
735 int pos = (*it).find("<"); 735 int pos = (*it).find("<");
736 QString name = (*it).left(pos); 736 QString name = (*it).left(pos);
737 QString email = (*it).mid(pos); 737 QString email = (*it).mid(pos);
738 if (!email.isEmpty()) { 738 if (!email.isEmpty()) {
739 mIncidence->addAttendee(new Attendee(name,email)); 739 mIncidence->addAttendee(new Attendee(name,email));
740 } 740 }
741 } 741 }
742 } 742 }
743#endif 743#endif
744} 744}
745 745
746 746
747QPtrList<KOAgendaItem> KOAgendaItem::conflictItems() 747QPtrList<KOAgendaItem> KOAgendaItem::conflictItems()
748{ 748{
749 return mConflictItems; 749 return mConflictItems;
750} 750}
751 751
752void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci) 752void KOAgendaItem::setConflictItems(QPtrList<KOAgendaItem> ci)
753{ 753{
754 mConflictItems = ci; 754 mConflictItems = ci;
755 KOAgendaItem *item; 755 KOAgendaItem *item;
756 for ( item=mConflictItems.first(); item != 0; 756 for ( item=mConflictItems.first(); item != 0;
757 item=mConflictItems.next() ) { 757 item=mConflictItems.next() ) {
758 item->addConflictItem(this); 758 item->addConflictItem(this);
759 } 759 }
760} 760}
761 761
762void KOAgendaItem::addConflictItem(KOAgendaItem *ci) 762void KOAgendaItem::addConflictItem(KOAgendaItem *ci)
763{ 763{
764 if (mConflictItems.find(ci)<0) 764 if (mConflictItems.find(ci)<0)
765 mConflictItems.append(ci); 765 mConflictItems.append(ci);
766} 766}
767 767
768bool KOAgendaItem::checkLayout() 768bool KOAgendaItem::checkLayout()
769{ 769{
770 if ( !mConflictItems.count() ) 770 if ( !mConflictItems.count() )
771 return true; 771 return true;
772 int max = 0; 772 int max = 0;
773 KOAgendaItem *item; 773 KOAgendaItem *item;
774 for ( item=mConflictItems.first(); item != 0; 774 for ( item=mConflictItems.first(); item != 0;
775 item=mConflictItems.next() ) { 775 item=mConflictItems.next() ) {
776 if ( item->subCells() > max ) 776 if ( item->subCells() > max )
777 max = item->subCells(); 777 max = item->subCells();
778 } 778 }
779 if ( max > subCells() ) { 779 if ( max > subCells() ) {
780 setSubCells( max ); 780 setSubCells( max );
781 return false; 781 return false;
782 } 782 }
783 return true; 783 return true;
784} 784}
diff --git a/korganizer/koagendaitem.h b/korganizer/koagendaitem.h
index b4dba79..53658c0 100644
--- a/korganizer/koagendaitem.h
+++ b/korganizer/koagendaitem.h
@@ -1,162 +1,164 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,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#ifndef KOAGENDAITEM_H 19#ifndef KOAGENDAITEM_H
20#define KOAGENDAITEM_H 20#define KOAGENDAITEM_H
21 21
22#include <qframe.h> 22#include <qframe.h>
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qpixmap.h> 24#include <qpixmap.h>
25#include <qdatetime.h> 25#include <qdatetime.h>
26#include <qpalette.h> 26#include <qpalette.h>
27 27
28#include <libkcal/incidence.h> 28#include <libkcal/incidence.h>
29 29
30class KOAgendaItemWhatsThis;
30class QToolTipGroup; 31class QToolTipGroup;
31class QDragEnterEvent; 32class QDragEnterEvent;
32class QDropEvent; 33class QDropEvent;
33 34
34using namespace KCal; 35using namespace KCal;
35 36
36/* 37/*
37 The KOAgendaItem has to make sure that it receives all mouse events, which are 38 The KOAgendaItem has to make sure that it receives all mouse events, which are
38 to be used for dragging and resizing. That means it has to be installed as 39 to be used for dragging and resizing. That means it has to be installed as
39 eventfiler for its children, if it has children, and it has to pass mouse 40 eventfiler for its children, if it has children, and it has to pass mouse
40 events from the cildren to itself. See eventFilter(). 41 events from the cildren to itself. See eventFilter().
41*/ 42*/
42class KOAgendaItem : public QWidget 43class KOAgendaItem : public QWidget
43{ 44{
44 Q_OBJECT 45 Q_OBJECT
45 public: 46 public:
46 KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent, bool allday, const char *name=0, 47 KOAgendaItem(Incidence *incidence, QDate qd, QWidget *parent, bool allday, const char *name=0,
47 WFlags f=0 ); 48 WFlags f=0 );
48 ~KOAgendaItem(); 49 ~KOAgendaItem();
49 QString getWhatsThisText(); 50 QString getWhatsThisText();
50 void init ( Incidence *incidence, QDate qd ); 51 void init ( Incidence *incidence, QDate qd );
51 int cellX() { return mCellX; } 52 int cellX() { return mCellX; }
52 int cellXWidth() { return mCellXWidth; } 53 int cellXWidth() { return mCellXWidth; }
53 int cellYTop() { return mCellYTop; } 54 int cellYTop() { return mCellYTop; }
54 int cellYBottom() { return mCellYBottom; } 55 int cellYBottom() { return mCellYBottom; }
55 int cellHeight(); 56 int cellHeight();
56 int cellWidth(); 57 int cellWidth();
57 int subCell() { return mSubCell; } 58 int subCell() { return mSubCell; }
58 int subCells() { return mSubCells; } 59 int subCells() { return mSubCells; }
59 60
60 void setCellXY(int X, int YTop, int YBottom); 61 void setCellXY(int X, int YTop, int YBottom);
61 void setCellY(int YTop, int YBottom); 62 void setCellY(int YTop, int YBottom);
62 void setCellX(int XLeft, int XRight); 63 void setCellX(int XLeft, int XRight);
63 void setCellXWidth(int xwidth); 64 void setCellXWidth(int xwidth);
64 void setSubCell(int subCell); 65 void setSubCell(int subCell);
65 void setSubCells(int subCells); 66 void setSubCells(int subCells);
66 67
67 /** Start movement */ 68 /** Start movement */
68 void startMove(); 69 void startMove();
69 /** Reset to original values */ 70 /** Reset to original values */
70 void resetMove(); 71 void resetMove();
71 72
72 void moveRelative(int dx,int dy); 73 void moveRelative(int dx,int dy);
73 void expandTop(int dy); 74 void expandTop(int dy);
74 void expandBottom(int dy); 75 void expandBottom(int dy);
75 void expandLeft(int dx); 76 void expandLeft(int dx);
76 void expandRight(int dx); 77 void expandRight(int dx);
77 int mLastMoveXPos; 78 int mLastMoveXPos;
78 79
79 void setMultiItem(KOAgendaItem *first,KOAgendaItem *next, 80 void setMultiItem(KOAgendaItem *first,KOAgendaItem *next,
80 KOAgendaItem *last); 81 KOAgendaItem *last);
81 KOAgendaItem *firstMultiItem() { return mFirstMultiItem; } 82 KOAgendaItem *firstMultiItem() { return mFirstMultiItem; }
82 KOAgendaItem *nextMultiItem() { return mNextMultiItem; } 83 KOAgendaItem *nextMultiItem() { return mNextMultiItem; }
83 KOAgendaItem *lastMultiItem() { return mLastMultiItem; } 84 KOAgendaItem *lastMultiItem() { return mLastMultiItem; }
84 85
85 Incidence *incidence() const { return mIncidence; } 86 Incidence *incidence() const { return mIncidence; }
86 QDate itemDate() { return mDate; } 87 QDate itemDate() { return mDate; }
87 88
88 /** Update the date of this item's occurence (not in the event) */ 89 /** Update the date of this item's occurence (not in the event) */
89 void setItemDate(QDate qd); 90 void setItemDate(QDate qd);
90 91
91 void setText ( const QString & text ) { mDisplayedText = text; } 92 void setText ( const QString & text ) { mDisplayedText = text; }
92 QString text () { return mDisplayedText; } 93 QString text () { return mDisplayedText; }
93 94
94 virtual bool eventFilter ( QObject *, QEvent * ); 95 virtual bool eventFilter ( QObject *, QEvent * );
95 96
96 static QToolTipGroup *toolTipGroup(); 97 static QToolTipGroup *toolTipGroup();
97 98
98 QPtrList<KOAgendaItem> conflictItems(); 99 QPtrList<KOAgendaItem> conflictItems();
99 void setConflictItems(QPtrList<KOAgendaItem>); 100 void setConflictItems(QPtrList<KOAgendaItem>);
100 void addConflictItem(KOAgendaItem *ci); 101 void addConflictItem(KOAgendaItem *ci);
101 void paintMe( bool, QPainter* painter = 0 ); 102 void paintMe( bool, QPainter* painter = 0 );
102 void repaintMe(); 103 void repaintMe();
103 static void resizePixmap( int, int ); 104 static void resizePixmap( int, int );
104 static QPixmap * paintPix(); 105 static QPixmap * paintPix();
105 static QPixmap * paintPixSel(); 106 static QPixmap * paintPixSel();
106 static QPixmap * paintPixAllday(); 107 static QPixmap * paintPixAllday();
107 void updateItem(); 108 void updateItem();
108 void computeText(); 109 void computeText();
109 void recreateIncidence(); 110 void recreateIncidence();
110 bool checkLayout(); 111 bool checkLayout();
111 public slots: 112 public slots:
112 bool updateIcons( QPainter *, bool ); 113 bool updateIcons( QPainter *, bool );
113 void select(bool=true); 114 void select(bool=true);
114 115
115 protected: 116 protected:
116 void dragEnterEvent(QDragEnterEvent *e); 117 void dragEnterEvent(QDragEnterEvent *e);
117 void dropEvent(QDropEvent *e); 118 void dropEvent(QDropEvent *e);
118 void paintEvent ( QPaintEvent * ); 119 void paintEvent ( QPaintEvent * );
119 void resizeEvent ( QResizeEvent *ev ); 120 void resizeEvent ( QResizeEvent *ev );
120 121
121 private: 122 private:
123 KOAgendaItemWhatsThis* mKOAgendaItemWhatsThis;
122 bool mAllDay; 124 bool mAllDay;
123 int mCellX; 125 int mCellX;
124 int mCellXWidth; 126 int mCellXWidth;
125 int mCellYTop,mCellYBottom; 127 int mCellYTop,mCellYBottom;
126 int mSubCell; // subcell number of this item 128 int mSubCell; // subcell number of this item
127 int mSubCells; // Total number of subcells in cell of this item 129 int mSubCells; // Total number of subcells in cell of this item
128 int xPaintCoord; 130 int xPaintCoord;
129 int yPaintCoord; 131 int yPaintCoord;
130 int wPaintCoord; 132 int wPaintCoord;
131 int hPaintCoord; 133 int hPaintCoord;
132 // Variables to remember start position 134 // Variables to remember start position
133 int mStartCellX; 135 int mStartCellX;
134 int mStartCellXWidth; 136 int mStartCellXWidth;
135 int mStartCellYTop,mStartCellYBottom; 137 int mStartCellYTop,mStartCellYBottom;
136 int mLastMovePos; 138 int mLastMovePos;
137 139
138 // Multi item pointers 140 // Multi item pointers
139 KOAgendaItem *mFirstMultiItem; 141 KOAgendaItem *mFirstMultiItem;
140 KOAgendaItem *mNextMultiItem; 142 KOAgendaItem *mNextMultiItem;
141 KOAgendaItem *mLastMultiItem; 143 KOAgendaItem *mLastMultiItem;
142 144
143 int mFontPixelSize; 145 int mFontPixelSize;
144 Incidence *mIncidence; // corresponding event or todo 146 Incidence *mIncidence; // corresponding event or todo
145 QDate mDate; //date this events occurs (for recurrence) 147 QDate mDate; //date this events occurs (for recurrence)
146 //void showIcon( QLabel*, int ); 148 //void showIcon( QLabel*, int );
147 //QLabel *mTodoIconLabel; 149 //QLabel *mTodoIconLabel;
148 //QLabel *mItemLabel; 150 //QLabel *mItemLabel;
149 //QWidget *mIconBox; 151 //QWidget *mIconBox;
150 //QLabel *mIconAlarm,*mIconRecur,*mIconReadonly; 152 //QLabel *mIconAlarm,*mIconRecur,*mIconReadonly;
151 //QLabel *mIconReply,*mIconGroup,*mIconOrganizer; 153 //QLabel *mIconReply,*mIconGroup,*mIconOrganizer;
152 //QLabel *mIconMoreInfo; 154 //QLabel *mIconMoreInfo;
153 static QToolTipGroup *mToolTipGroup; 155 static QToolTipGroup *mToolTipGroup;
154 156
155 QColor mBackgroundColor; 157 QColor mBackgroundColor;
156 QColorGroup mColorGroup; 158 QColorGroup mColorGroup;
157 QString mDisplayedText; 159 QString mDisplayedText;
158 bool mSelected; 160 bool mSelected;
159 QPtrList<KOAgendaItem> mConflictItems; 161 QPtrList<KOAgendaItem> mConflictItems;
160}; 162};
161 163
162#endif // KOAGENDAITEM_H 164#endif // KOAGENDAITEM_H
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index ae0a051..5133519 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,900 +1,902 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { }; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; };
66 67
67protected: 68protected:
68 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
69 { 70 {
70 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
71 } 72 }
72private: 73private:
73 KODayMatrix * _view; 74 KODayMatrix * _view;
74}; 75};
75 76
76void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
77{ 78{
78 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
79 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
80 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
81 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
82 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
83 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
84 85
85 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
86 87
87// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
88// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
89 90
90 //show holiday names only 91 //show holiday names only
91 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
92 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
93 tip(rct, str); 94 tip(rct, str);
94} 95}
95 96
96 97
97// ============================================================================ 98// ============================================================================
98// K O D A Y M A T R I X 99// K O D A Y M A T R I X
99// ============================================================================ 100// ============================================================================
100 101
101const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
102const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
103 104
104KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
105 : QFrame( parent, name ), mCalendar( 0 ) 106 : QFrame( parent, name ), mCalendar( 0 )
106 107
107#if 0 108#if 0
108KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
109 QFrame(parent, name) 110 QFrame(parent, name)
110#endif 111#endif
111{ 112{
112 new KODaymatrixWhatsThis(this); 113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
113 mPendingUpdateBeforeRepaint = false; 114 mPendingUpdateBeforeRepaint = false;
114 mouseDown = false; 115 mouseDown = false;
115 // initialize dynamic arrays 116 // initialize dynamic arrays
116 bDays.resize ( NUMDAYS ); 117 bDays.resize ( NUMDAYS );
117 days = new QDate[NUMDAYS]; 118 days = new QDate[NUMDAYS];
118 daylbls = new QString[NUMDAYS]; 119 daylbls = new QString[NUMDAYS];
119 events = new int[NUMDAYS]; 120 events = new int[NUMDAYS];
120 mToolTip = new DynamicTip(this); 121 mToolTip = new DynamicTip(this);
121 122
122 // set default values used for drawing the matrix 123 // set default values used for drawing the matrix
123 mDefaultBackColor = palette().active().base(); 124 mDefaultBackColor = palette().active().base();
124 mDefaultTextColor = palette().active().foreground(); 125 mDefaultTextColor = palette().active().foreground();
125 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
126 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
127 mSelectedDaysColor = QColor("white"); 128 mSelectedDaysColor = QColor("white");
128 mTodayMarginWidth = 2; 129 mTodayMarginWidth = 2;
129 mSelEnd = mSelStart = NOSELECTION; 130 mSelEnd = mSelStart = NOSELECTION;
130 131
131 setAcceptDrops(true); 132 setAcceptDrops(true);
132 //setFont( QFont("Arial", 10) ); 133 //setFont( QFont("Arial", 10) );
133 134
134 mUpdateTimer = new QTimer( this ); 135 mUpdateTimer = new QTimer( this );
135 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
136 mRepaintTimer = new QTimer( this ); 137 mRepaintTimer = new QTimer( this );
137 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
138 mDayChanged = false; 139 mDayChanged = false;
139 updateView(); 140 updateView();
140} 141}
141QString KODayMatrix::getWhatsThisText( QPoint p ) 142QString KODayMatrix::getWhatsThisText( QPoint p )
142{ 143{
143 144
144 int tmp = getDayIndexFrom(p.x(), p.y()); 145 int tmp = getDayIndexFrom(p.x(), p.y());
145 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
146 return QString(); 147 return QString();
147 QDate mDate = days[tmp]; 148 QDate mDate = days[tmp];
148 QPtrList<Event> eventlist = mCalendar->events(mDate); 149 QPtrList<Event> eventlist = mCalendar->events(mDate);
149 Event *event; 150 Event *event;
150 QStringList mToolTip; 151 QStringList mToolTip;
151 for(event=eventlist.first();event != 0;event=eventlist.next()) { 152 for(event=eventlist.first();event != 0;event=eventlist.next()) {
152 QString mToolTipText; 153 QString mToolTipText;
153 QString text; 154 QString text;
154 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
155 if (event->isMultiDay()) { 156 if (event->isMultiDay()) {
156 QString prefix = "<->";multiday = 2; 157 QString prefix = "<->";multiday = 2;
157 QString time; 158 QString time;
158 if ( event->doesRecur() ) { 159 if ( event->doesRecur() ) {
159 if ( event->recursOn( mDate) ) { 160 if ( event->recursOn( mDate) ) {
160 prefix ="->" ;multiday = 1; 161 prefix ="->" ;multiday = 1;
161 } 162 }
162 else { 163 else {
163 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
164 if ( event->recursOn( mDate.addDays( -days)) ) { 165 if ( event->recursOn( mDate.addDays( -days)) ) {
165 prefix ="<-" ;multiday = 3; 166 prefix ="<-" ;multiday = 3;
166 } 167 }
167 } 168 }
168 } else { 169 } else {
169 if (mDate == event->dtStart().date()) { 170 if (mDate == event->dtStart().date()) {
170 prefix ="->" ;multiday = 1; 171 prefix ="->" ;multiday = 1;
171 } else if (mDate == event->dtEnd().date()) { 172 } else if (mDate == event->dtEnd().date()) {
172 prefix ="<-" ;multiday = 3; 173 prefix ="<-" ;multiday = 3;
173 } 174 }
174 } 175 }
175 if ( !event->doesFloat() ) { 176 if ( !event->doesFloat() ) {
176 if ( mDate == event->dtStart().date () ) 177 if ( mDate == event->dtStart().date () )
177 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
178 else if ( mDate == event->dtEnd().date () ) 179 else if ( mDate == event->dtEnd().date () )
179 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
180 181
181 } 182 }
182 text = time + event->summary(); 183 text = time + event->summary();
183 mToolTipText += prefix + text; 184 mToolTipText += prefix + text;
184 } else { 185 } else {
185 if (event->doesFloat()) { 186 if (event->doesFloat()) {
186 text = event->summary(); 187 text = event->summary();
187 mToolTipText += text; 188 mToolTipText += text;
188 } 189 }
189 else { 190 else {
190 text = KGlobal::locale()->formatTime(event->dtStart().time()); 191 text = KGlobal::locale()->formatTime(event->dtStart().time());
191 text += " " + event->summary(); 192 text += " " + event->summary();
192 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
193 } 194 }
194 } 195 }
195 mToolTip.append( mToolTipText ); 196 mToolTip.append( mToolTipText );
196 } 197 }
197 mToolTip.sort(); 198 mToolTip.sort();
198 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 199 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
199} 200}
200void KODayMatrix::setCalendar( Calendar *cal ) 201void KODayMatrix::setCalendar( Calendar *cal )
201{ 202{
202 mCalendar = cal; 203 mCalendar = cal;
203 204
204 setAcceptDrops( mCalendar ); 205 setAcceptDrops( mCalendar );
205 206
206 updateEvents(); 207 updateEvents();
207} 208}
208 209
209QColor KODayMatrix::getShadedColor(QColor color) 210QColor KODayMatrix::getShadedColor(QColor color)
210{ 211{
211 QColor shaded; 212 QColor shaded;
212 int h=0; 213 int h=0;
213 int s=0; 214 int s=0;
214 int v=0; 215 int v=0;
215 color.hsv(&h,&s,&v); 216 color.hsv(&h,&s,&v);
216 s = s/4; 217 s = s/4;
217 v = 192+v/4; 218 v = 192+v/4;
218 shaded.setHsv(h,s,v); 219 shaded.setHsv(h,s,v);
219 220
220 return shaded; 221 return shaded;
221} 222}
222 223
223KODayMatrix::~KODayMatrix() 224KODayMatrix::~KODayMatrix()
224{ 225{
226 delete mKODaymatrixWhatsThis;
225 delete [] days; 227 delete [] days;
226 delete [] daylbls; 228 delete [] daylbls;
227 delete [] events; 229 delete [] events;
228 delete mToolTip; 230 delete mToolTip;
229} 231}
230 232
231/* 233/*
232void KODayMatrix::setStartDate(QDate start) 234void KODayMatrix::setStartDate(QDate start)
233{ 235{
234 updateView(start); 236 updateView(start);
235} 237}
236*/ 238*/
237 239
238void KODayMatrix::addSelectedDaysTo(DateList& selDays) 240void KODayMatrix::addSelectedDaysTo(DateList& selDays)
239{ 241{
240 242
241 if (mSelStart == NOSELECTION) { 243 if (mSelStart == NOSELECTION) {
242 return; 244 return;
243 } 245 }
244 246
245 //cope with selection being out of matrix limits at top (< 0) 247 //cope with selection being out of matrix limits at top (< 0)
246 int i0 = mSelStart; 248 int i0 = mSelStart;
247 if (i0 < 0) { 249 if (i0 < 0) {
248 for (int i = i0; i < 0; i++) { 250 for (int i = i0; i < 0; i++) {
249 selDays.append(days[0].addDays(i)); 251 selDays.append(days[0].addDays(i));
250 } 252 }
251 i0 = 0; 253 i0 = 0;
252 } 254 }
253 255
254 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 256 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
255 if (mSelEnd > NUMDAYS-1) { 257 if (mSelEnd > NUMDAYS-1) {
256 for (int i = i0; i <= NUMDAYS-1; i++) { 258 for (int i = i0; i <= NUMDAYS-1; i++) {
257 selDays.append(days[i]); 259 selDays.append(days[i]);
258 } 260 }
259 for (int i = NUMDAYS; i < mSelEnd; i++) { 261 for (int i = NUMDAYS; i < mSelEnd; i++) {
260 selDays.append(days[0].addDays(i)); 262 selDays.append(days[0].addDays(i));
261 } 263 }
262 264
263 // apply normal routine to selection being entirely within matrix limits 265 // apply normal routine to selection being entirely within matrix limits
264 } else { 266 } else {
265 for (int i = i0; i <= mSelEnd; i++) { 267 for (int i = i0; i <= mSelEnd; i++) {
266 selDays.append(days[i]); 268 selDays.append(days[i]);
267 } 269 }
268 } 270 }
269} 271}
270 272
271void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 273void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
272{ 274{
273 mSelStart = startdate.daysTo(start); 275 mSelStart = startdate.daysTo(start);
274 if ( mSelStart < 0 ) 276 if ( mSelStart < 0 )
275 mSelStart = 0; 277 mSelStart = 0;
276 mSelEnd = startdate.daysTo(end); 278 mSelEnd = startdate.daysTo(end);
277 if ( mSelEnd < 0 ) 279 if ( mSelEnd < 0 )
278 clearSelection(); 280 clearSelection();
279} 281}
280void KODayMatrix::clearSelection() 282void KODayMatrix::clearSelection()
281{ 283{
282 mSelEnd = mSelStart = NOSELECTION; 284 mSelEnd = mSelStart = NOSELECTION;
283} 285}
284 286
285 287
286void KODayMatrix::recalculateToday() 288void KODayMatrix::recalculateToday()
287{ 289{
288 today = -1; 290 today = -1;
289 for (int i=0; i<NUMDAYS; i++) { 291 for (int i=0; i<NUMDAYS; i++) {
290 events[i] = 0; 292 events[i] = 0;
291 days[i] = startdate.addDays(i); 293 days[i] = startdate.addDays(i);
292 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 294 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
293 295
294 // if today is in the currently displayed month, hilight today 296 // if today is in the currently displayed month, hilight today
295 if (days[i].year() == QDate::currentDate().year() && 297 if (days[i].year() == QDate::currentDate().year() &&
296 days[i].month() == QDate::currentDate().month() && 298 days[i].month() == QDate::currentDate().month() &&
297 days[i].day() == QDate::currentDate().day()) { 299 days[i].day() == QDate::currentDate().day()) {
298 today = i; 300 today = i;
299 } 301 }
300 } 302 }
301 // qDebug(QString("Today is visible at %1.").arg(today)); 303 // qDebug(QString("Today is visible at %1.").arg(today));
302} 304}
303 305
304void KODayMatrix::updateView() 306void KODayMatrix::updateView()
305{ 307{
306 updateView(startdate); 308 updateView(startdate);
307} 309}
308void KODayMatrix::repaintViewTimed() 310void KODayMatrix::repaintViewTimed()
309{ 311{
310 mRepaintTimer->stop(); 312 mRepaintTimer->stop();
311 repaint(false); 313 repaint(false);
312} 314}
313void KODayMatrix::updateViewTimed() 315void KODayMatrix::updateViewTimed()
314{ 316{
315 mUpdateTimer->stop(); 317 mUpdateTimer->stop();
316 if ( !mCalendar ) { 318 if ( !mCalendar ) {
317 qDebug("NOT CAL "); 319 qDebug("NOT CAL ");
318 return; 320 return;
319 } 321 }
320 //qDebug("KODayMatrix::updateViewTimed "); 322 //qDebug("KODayMatrix::updateViewTimed ");
321 for(int i = 0; i < NUMDAYS; i++) { 323 for(int i = 0; i < NUMDAYS; i++) {
322 // if events are set for the day then remember to draw it bold 324 // if events are set for the day then remember to draw it bold
323 QPtrList<Event> eventlist = mCalendar->events(days[i]); 325 QPtrList<Event> eventlist = mCalendar->events(days[i]);
324 Event *event; 326 Event *event;
325 int numEvents = eventlist.count(); 327 int numEvents = eventlist.count();
326 QString holiStr = ""; 328 QString holiStr = "";
327 bDays.clearBit(i); 329 bDays.clearBit(i);
328 for(event=eventlist.first();event != 0;event=eventlist.next()) { 330 for(event=eventlist.first();event != 0;event=eventlist.next()) {
329 ushort recurType = event->recurrence()->doesRecur(); 331 ushort recurType = event->recurrence()->doesRecur();
330 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 332 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
331 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 333 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
332 numEvents--; 334 numEvents--;
333 } 335 }
334 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { 336 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) {
335 if ( !holiStr.isEmpty() ) 337 if ( !holiStr.isEmpty() )
336 holiStr += "\n"; 338 holiStr += "\n";
337 holiStr += event->summary(); 339 holiStr += event->summary();
338 } 340 }
339 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { 341 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) {
340 if ( !holiStr.isEmpty() ) 342 if ( !holiStr.isEmpty() )
341 holiStr += "\n"; 343 holiStr += "\n";
342 holiStr += event->summary(); 344 holiStr += event->summary();
343 bDays.setBit(i); 345 bDays.setBit(i);
344 } 346 }
345 } 347 }
346 events[i] = numEvents; 348 events[i] = numEvents;
347 //if it is a holy day then draw it red. Sundays are consider holidays, too 349 //if it is a holy day then draw it red. Sundays are consider holidays, too
348 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 350 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
349 !holiStr.isEmpty()) { 351 !holiStr.isEmpty()) {
350 mHolidays[i] = holiStr; 352 mHolidays[i] = holiStr;
351 } else { 353 } else {
352 mHolidays[i] = QString::null; 354 mHolidays[i] = QString::null;
353 } 355 }
354 } 356 }
355 if ( ! mPendingUpdateBeforeRepaint ) 357 if ( ! mPendingUpdateBeforeRepaint )
356 repaint(false); 358 repaint(false);
357} 359}
358void KODayMatrix::updateView(QDate actdate) 360void KODayMatrix::updateView(QDate actdate)
359{ 361{
360 362
361 if ( ! actdate.isValid() ) { 363 if ( ! actdate.isValid() ) {
362 //qDebug("date not valid "); 364 //qDebug("date not valid ");
363 return; 365 return;
364 } 366 }
365 mDayChanged = false; 367 mDayChanged = false;
366 //flag to indicate if the starting day of the matrix has changed by this call 368 //flag to indicate if the starting day of the matrix has changed by this call
367 //mDayChanged = false; 369 //mDayChanged = false;
368 // if a new startdate is to be set then apply Cornelius's calculation 370 // if a new startdate is to be set then apply Cornelius's calculation
369 // of the first day to be shown 371 // of the first day to be shown
370 if (actdate != startdate) { 372 if (actdate != startdate) {
371 // reset index of selection according to shift of starting date from startdate to actdate 373 // reset index of selection according to shift of starting date from startdate to actdate
372 if (mSelStart != NOSELECTION) { 374 if (mSelStart != NOSELECTION) {
373 int tmp = actdate.daysTo(startdate); 375 int tmp = actdate.daysTo(startdate);
374 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 376 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
375 // shift selection if new one would be visible at least partly ! 377 // shift selection if new one would be visible at least partly !
376 378
377 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 379 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
378 // nested if is required for next X display pushed from a different month - correction required 380 // nested if is required for next X display pushed from a different month - correction required
379 // otherwise, for month forward and backward, it must be avoided 381 // otherwise, for month forward and backward, it must be avoided
380 if( mSelStart > NUMDAYS || mSelStart < 0 ) 382 if( mSelStart > NUMDAYS || mSelStart < 0 )
381 mSelStart = mSelStart + tmp; 383 mSelStart = mSelStart + tmp;
382 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 384 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
383 mSelEnd = mSelEnd + tmp; 385 mSelEnd = mSelEnd + tmp;
384 } 386 }
385 } 387 }
386 startdate = actdate; 388 startdate = actdate;
387 mDayChanged = true; 389 mDayChanged = true;
388 recalculateToday(); 390 recalculateToday();
389 } 391 }
390 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 392 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
391 if ( !isVisible() ) { 393 if ( !isVisible() ) {
392 mPendingUpdateBeforeRepaint = true; 394 mPendingUpdateBeforeRepaint = true;
393 } else { 395 } else {
394#ifdef DESKTOP_VERSION 396#ifdef DESKTOP_VERSION
395 //mRepaintTimer->start( 150 ); 397 //mRepaintTimer->start( 150 );
396 mUpdateTimer->start( 150 ); 398 mUpdateTimer->start( 150 );
397#else 399#else
398 mRepaintTimer->start( 350 ); 400 mRepaintTimer->start( 350 );
399 mUpdateTimer->start( 1200 ); 401 mUpdateTimer->start( 1200 );
400#endif 402#endif
401 } 403 }
402} 404}
403void KODayMatrix::updateEvents() 405void KODayMatrix::updateEvents()
404{ 406{
405 if ( !mCalendar ) return; 407 if ( !mCalendar ) return;
406 408
407 for( int i = 0; i < NUMDAYS; i++ ) { 409 for( int i = 0; i < NUMDAYS; i++ ) {
408 // if events are set for the day then remember to draw it bold 410 // if events are set for the day then remember to draw it bold
409 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 411 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
410 int numEvents = eventlist.count(); 412 int numEvents = eventlist.count();
411 Event *event; 413 Event *event;
412 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 414 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
413 ushort recurType = event->doesRecur(); 415 ushort recurType = event->doesRecur();
414 416
415 if ( ( recurType == Recurrence::rDaily && 417 if ( ( recurType == Recurrence::rDaily &&
416 !KOPrefs::instance()->mDailyRecur ) || 418 !KOPrefs::instance()->mDailyRecur ) ||
417 ( recurType == Recurrence::rWeekly && 419 ( recurType == Recurrence::rWeekly &&
418 !KOPrefs::instance()->mWeeklyRecur ) ) { 420 !KOPrefs::instance()->mWeeklyRecur ) ) {
419 numEvents--; 421 numEvents--;
420 } 422 }
421 } 423 }
422 events[ i ] = numEvents; 424 events[ i ] = numEvents;
423 } 425 }
424} 426}
425 427
426const QDate& KODayMatrix::getDate(int offset) 428const QDate& KODayMatrix::getDate(int offset)
427{ 429{
428 if (offset < 0 || offset > NUMDAYS-1) { 430 if (offset < 0 || offset > NUMDAYS-1) {
429 qDebug("Wrong offset2 "); 431 qDebug("Wrong offset2 ");
430 return days[0]; 432 return days[0];
431 } 433 }
432 return days[offset]; 434 return days[offset];
433} 435}
434 436
435QString KODayMatrix::getHolidayLabel(int offset) 437QString KODayMatrix::getHolidayLabel(int offset)
436{ 438{
437 if (offset < 0 || offset > NUMDAYS-1) { 439 if (offset < 0 || offset > NUMDAYS-1) {
438 qDebug("Wrong offset1 "); 440 qDebug("Wrong offset1 ");
439 return 0; 441 return 0;
440 } 442 }
441 return mHolidays[offset]; 443 return mHolidays[offset];
442} 444}
443 445
444int KODayMatrix::getDayIndexFrom(int x, int y) 446int KODayMatrix::getDayIndexFrom(int x, int y)
445{ 447{
446 int colModulo = (width()-2) % 7; 448 int colModulo = (width()-2) % 7;
447 int rowModulo = (height()-2) % 6; 449 int rowModulo = (height()-2) % 6;
448#if 0 450#if 0
449 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 451 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
450 6 - x/daysize.width() : x/daysize.width()); 452 6 - x/daysize.width() : x/daysize.width());
451#endif 453#endif
452 int xVal = (x-colModulo/2-2)/daysize.width(); 454 int xVal = (x-colModulo/2-2)/daysize.width();
453 int yVal = (y-rowModulo/2-2)/daysize.height(); 455 int yVal = (y-rowModulo/2-2)/daysize.height();
454 456
455 457
456 return 7*(yVal) + xVal; 458 return 7*(yVal) + xVal;
457 459
458} 460}
459 461
460// ---------------------------------------------------------------------------- 462// ----------------------------------------------------------------------------
461// M O U S E E V E N T H A N D L I N G 463// M O U S E E V E N T H A N D L I N G
462// ---------------------------------------------------------------------------- 464// ----------------------------------------------------------------------------
463 465
464void KODayMatrix::mousePressEvent (QMouseEvent* e) 466void KODayMatrix::mousePressEvent (QMouseEvent* e)
465{ 467{
466 468
467 if ( e->button() == LeftButton ) 469 if ( e->button() == LeftButton )
468 mouseDown = true; 470 mouseDown = true;
469 mSelStart = getDayIndexFrom(e->x(), e->y()); 471 mSelStart = getDayIndexFrom(e->x(), e->y());
470 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 472 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
471 mSelInit = mSelStart; 473 mSelInit = mSelStart;
472 mSelEnd = mSelStart; 474 mSelEnd = mSelStart;
473 repaint(false); 475 repaint(false);
474} 476}
475 477
476void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 478void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
477{ 479{
478 if ( e->button() == LeftButton ) 480 if ( e->button() == LeftButton )
479 if ( ! mouseDown ) { 481 if ( ! mouseDown ) {
480 return; 482 return;
481 } 483 }
482 else 484 else
483 mouseDown = false; 485 mouseDown = false;
484 int tmp = getDayIndexFrom(e->x(), e->y()); 486 int tmp = getDayIndexFrom(e->x(), e->y());
485 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 487 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
486 488
487 if (mSelInit > tmp) { 489 if (mSelInit > tmp) {
488 mSelEnd = mSelInit; 490 mSelEnd = mSelInit;
489 if (tmp != mSelStart) { 491 if (tmp != mSelStart) {
490 mSelStart = tmp; 492 mSelStart = tmp;
491 repaint(false); 493 repaint(false);
492 } 494 }
493 } else { 495 } else {
494 mSelStart = mSelInit; 496 mSelStart = mSelInit;
495 497
496 //repaint only if selection has changed 498 //repaint only if selection has changed
497 if (tmp != mSelEnd) { 499 if (tmp != mSelEnd) {
498 mSelEnd = tmp; 500 mSelEnd = tmp;
499 repaint(false); 501 repaint(false);
500 } 502 }
501 } 503 }
502 504
503 DateList daylist; 505 DateList daylist;
504 if ( mSelStart < 0 ) 506 if ( mSelStart < 0 )
505 mSelStart = 0; 507 mSelStart = 0;
506 for (int i = mSelStart; i <= mSelEnd; i++) { 508 for (int i = mSelStart; i <= mSelEnd; i++) {
507 daylist.append(days[i]); 509 daylist.append(days[i]);
508 } 510 }
509 emit selected((const DateList)daylist); 511 emit selected((const DateList)daylist);
510 512
511} 513}
512 514
513void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 515void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
514{ 516{
515 if ( ! mouseDown ) { 517 if ( ! mouseDown ) {
516 return; 518 return;
517 } 519 }
518 int tmp = getDayIndexFrom(e->x(), e->y()); 520 int tmp = getDayIndexFrom(e->x(), e->y());
519 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 521 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
520 522
521 if (mSelInit > tmp) { 523 if (mSelInit > tmp) {
522 mSelEnd = mSelInit; 524 mSelEnd = mSelInit;
523 if (tmp != mSelStart) { 525 if (tmp != mSelStart) {
524 mSelStart = tmp; 526 mSelStart = tmp;
525 repaint(false); 527 repaint(false);
526 } 528 }
527 } else { 529 } else {
528 mSelStart = mSelInit; 530 mSelStart = mSelInit;
529 531
530 //repaint only if selection has changed 532 //repaint only if selection has changed
531 if (tmp != mSelEnd) { 533 if (tmp != mSelEnd) {
532 mSelEnd = tmp; 534 mSelEnd = tmp;
533 repaint(false); 535 repaint(false);
534 } 536 }
535 } 537 }
536} 538}
537 539
538// ---------------------------------------------------------------------------- 540// ----------------------------------------------------------------------------
539// D R A G ' N D R O P H A N D L I N G 541// D R A G ' N D R O P H A N D L I N G
540// ---------------------------------------------------------------------------- 542// ----------------------------------------------------------------------------
541 543
542void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 544void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
543{ 545{
544#ifndef KORG_NODND 546#ifndef KORG_NODND
545 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 547 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
546 e->ignore(); 548 e->ignore();
547 return; 549 return;
548 } 550 }
549 551
550 // some visual feedback 552 // some visual feedback
551// oldPalette = palette(); 553// oldPalette = palette();
552// setPalette(my_HilitePalette); 554// setPalette(my_HilitePalette);
553// update(); 555// update();
554#endif 556#endif
555} 557}
556 558
557void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 559void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
558{ 560{
559#ifndef KORG_NODND 561#ifndef KORG_NODND
560 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 562 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
561 e->ignore(); 563 e->ignore();
562 return; 564 return;
563 } 565 }
564 566
565 e->accept(); 567 e->accept();
566#endif 568#endif
567} 569}
568 570
569void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 571void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
570{ 572{
571#ifndef KORG_NODND 573#ifndef KORG_NODND
572// setPalette(oldPalette); 574// setPalette(oldPalette);
573// update(); 575// update();
574#endif 576#endif
575} 577}
576 578
577void KODayMatrix::dropEvent(QDropEvent *e) 579void KODayMatrix::dropEvent(QDropEvent *e)
578{ 580{
579#ifndef KORG_NODND 581#ifndef KORG_NODND
580// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 582// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
581 583
582 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 584 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
583 e->ignore(); 585 e->ignore();
584 return; 586 return;
585 } 587 }
586 588
587 DndFactory factory( mCalendar ); 589 DndFactory factory( mCalendar );
588 Event *event = factory.createDrop(e); 590 Event *event = factory.createDrop(e);
589 591
590 if (event) { 592 if (event) {
591 e->acceptAction(); 593 e->acceptAction();
592 594
593 Event *existingEvent = mCalendar->event(event->uid()); 595 Event *existingEvent = mCalendar->event(event->uid());
594 596
595 if(existingEvent) { 597 if(existingEvent) {
596 // uniquify event 598 // uniquify event
597 event->recreate(); 599 event->recreate();
598/* 600/*
599 KMessageBox::sorry(this, 601 KMessageBox::sorry(this,
600 i18n("Event already exists in this calendar."), 602 i18n("Event already exists in this calendar."),
601 i18n("Drop Event")); 603 i18n("Drop Event"));
602 delete event; 604 delete event;
603 return; 605 return;
604*/ 606*/
605 } 607 }
606// kdDebug() << "Drop new Event" << endl; 608// kdDebug() << "Drop new Event" << endl;
607 // Adjust date 609 // Adjust date
608 QDateTime start = event->dtStart(); 610 QDateTime start = event->dtStart();
609 QDateTime end = event->dtEnd(); 611 QDateTime end = event->dtEnd();
610 int duration = start.daysTo(end); 612 int duration = start.daysTo(end);
611 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 613 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
612 614
613 start.setDate(days[idx]); 615 start.setDate(days[idx]);
614 end.setDate(days[idx].addDays(duration)); 616 end.setDate(days[idx].addDays(duration));
615 617
616 event->setDtStart(start); 618 event->setDtStart(start);
617 event->setDtEnd(end); 619 event->setDtEnd(end);
618 mCalendar->addEvent(event); 620 mCalendar->addEvent(event);
619 621
620 emit eventDropped(event); 622 emit eventDropped(event);
621 } else { 623 } else {
622// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 624// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
623 e->ignore(); 625 e->ignore();
624 } 626 }
625#endif 627#endif
626} 628}
627 629
628// ---------------------------------------------------------------------------- 630// ----------------------------------------------------------------------------
629// P A I N T E V E N T H A N D L I N G 631// P A I N T E V E N T H A N D L I N G
630// ---------------------------------------------------------------------------- 632// ----------------------------------------------------------------------------
631 633
632void KODayMatrix::paintEvent(QPaintEvent * pevent) 634void KODayMatrix::paintEvent(QPaintEvent * pevent)
633{ 635{
634 QRect sz = frameRect(); 636 QRect sz = frameRect();
635 if ( sz.width() <= 0 || sz.height() <= 0 ) 637 if ( sz.width() <= 0 || sz.height() <= 0 )
636 return; 638 return;
637 if ( mPendingUpdateBeforeRepaint ) { 639 if ( mPendingUpdateBeforeRepaint ) {
638 updateViewTimed(); 640 updateViewTimed();
639 mPendingUpdateBeforeRepaint = false; 641 mPendingUpdateBeforeRepaint = false;
640 } 642 }
641 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 643 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
642 myPix.resize(sz.size() ); 644 myPix.resize(sz.size() );
643 } 645 }
644 QPainter p(&myPix); 646 QPainter p(&myPix);
645 p.setFont(font()); 647 p.setFont(font());
646 648
647 649
648 int dheight = daysize.height(); 650 int dheight = daysize.height();
649 int dwidth = daysize.width(); 651 int dwidth = daysize.width();
650 int row,col; 652 int row,col;
651 int selw, selh; 653 int selw, selh;
652 int xyOff = frameWidth(); 654 int xyOff = frameWidth();
653 int colModulo = sz.width() % 7; 655 int colModulo = sz.width() % 7;
654 int rowModulo = sz.height() % 6; 656 int rowModulo = sz.height() % 6;
655 //qDebug("col %d row %d ",colModulo,rowModulo ); 657 //qDebug("col %d row %d ",colModulo,rowModulo );
656 658
657 bool isRTL = KOGlobals::self()->reverseLayout(); 659 bool isRTL = KOGlobals::self()->reverseLayout();
658 660
659 // draw background and topleft frame 661 // draw background and topleft frame
660 p.fillRect(pevent->rect(), mDefaultBackColor); 662 p.fillRect(pevent->rect(), mDefaultBackColor);
661 p.setPen(mDefaultTextColor); 663 p.setPen(mDefaultTextColor);
662 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 664 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
663 int mSelStartT = mSelStart; 665 int mSelStartT = mSelStart;
664 int mSelEndT = mSelEnd; 666 int mSelEndT = mSelEnd;
665 if ( mSelEndT >= NUMDAYS ) 667 if ( mSelEndT >= NUMDAYS )
666 mSelEndT = NUMDAYS-1; 668 mSelEndT = NUMDAYS-1;
667 // draw selected days with highlighted background color 669 // draw selected days with highlighted background color
668 if (mSelStart != NOSELECTION) { 670 if (mSelStart != NOSELECTION) {
669 bool skip = false; 671 bool skip = false;
670 if ( ! mouseDown ) { 672 if ( ! mouseDown ) {
671 int mo = days[20].month(); 673 int mo = days[20].month();
672 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 674 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
673 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 675 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
674 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) { 676 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
675 skip = true; 677 skip = true;
676 } else { 678 } else {
677 if ( days[mSelStartT].month() != mo ) { 679 if ( days[mSelStartT].month() != mo ) {
678 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 680 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
679 mSelStartT += add +1; 681 mSelStartT += add +1;
680 } 682 }
681 if ( days[mSelEndT].month() != mo ) { 683 if ( days[mSelEndT].month() != mo ) {
682 int sub = days[mSelEndT].day(); 684 int sub = days[mSelEndT].day();
683 mSelEndT -= sub ; 685 mSelEndT -= sub ;
684 } 686 }
685 } 687 }
686 } 688 }
687 if ( ! skip ) { 689 if ( ! skip ) {
688 row = mSelStartT/7; 690 row = mSelStartT/7;
689 col = mSelStartT -row*7; 691 col = mSelStartT -row*7;
690 QColor selcol = KOPrefs::instance()->mHighlightColor; 692 QColor selcol = KOPrefs::instance()->mHighlightColor;
691 int addCol = 0; 693 int addCol = 0;
692 int addRow = 0; 694 int addRow = 0;
693 int addRow2 = 0; 695 int addRow2 = 0;
694 int addCol2 = 0; 696 int addCol2 = 0;
695 if (row == mSelEndT/7) { 697 if (row == mSelEndT/7) {
696 if ( rowModulo ) { 698 if ( rowModulo ) {
697 if ( row >= 6 - rowModulo ) 699 if ( row >= 6 - rowModulo )
698 addRow = row - 5 + rowModulo; 700 addRow = row - 5 + rowModulo;
699 } 701 }
700 if ( colModulo ) { 702 if ( colModulo ) {
701 int colt1 = mSelEndT%7; 703 int colt1 = mSelEndT%7;
702 //qDebug("colt1 %d ", colt1 ); 704 //qDebug("colt1 %d ", colt1 );
703 if ( colt1 >= 7 - colModulo ) 705 if ( colt1 >= 7 - colModulo )
704 addCol = colt1 - 7 + colModulo+1; 706 addCol = colt1 - 7 + colModulo+1;
705 int colt = mSelStartT%7; 707 int colt = mSelStartT%7;
706 if ( colt >= 7 - colModulo ) 708 if ( colt >= 7 - colModulo )
707 addCol2 = colt - 7 + colModulo; 709 addCol2 = colt - 7 + colModulo;
708 addCol -= addCol2; 710 addCol -= addCol2;
709 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 711 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
710 } 712 }
711 // Single row selection 713 // Single row selection
712 if ( row == 0) 714 if ( row == 0)
713 addRow = 1; 715 addRow = 1;
714 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 716 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
715 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 717 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
716 } else { 718 } else {
717 // draw first row to the right 719 // draw first row to the right
718 if ( colModulo ) { 720 if ( colModulo ) {
719 if ( col >= 7 - colModulo ) 721 if ( col >= 7 - colModulo )
720 addCol2 = col - 7 + colModulo; 722 addCol2 = col - 7 + colModulo;
721 } 723 }
722 if ( rowModulo ) { 724 if ( rowModulo ) {
723 if ( row >= 6 - rowModulo ) 725 if ( row >= 6 - rowModulo )
724 addRow = row - 5 + rowModulo; 726 addRow = row - 5 + rowModulo;
725 } 727 }
726 if ( row == 0) 728 if ( row == 0)
727 addRow = 1; 729 addRow = 1;
728 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, 730 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo,
729 dheight+1, selcol); 731 dheight+1, selcol);
730 // draw full block till last line 732 // draw full block till last line
731 selh = mSelEndT/7-row; 733 selh = mSelEndT/7-row;
732 addRow = 0; 734 addRow = 0;
733 if ( rowModulo ) { 735 if ( rowModulo ) {
734 if ( mSelEndT/7 >= 6 - rowModulo ) 736 if ( mSelEndT/7 >= 6 - rowModulo )
735 addRow = mSelEndT/7 - 5 + rowModulo; 737 addRow = mSelEndT/7 - 5 + rowModulo;
736 } 738 }
737 if (selh > 1) { 739 if (selh > 1) {
738 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 740 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
739 } 741 }
740 // draw last block from left to mSelEndT 742 // draw last block from left to mSelEndT
741 selw = mSelEndT-7*(mSelEndT/7)+1; 743 selw = mSelEndT-7*(mSelEndT/7)+1;
742 //qDebug("esl %d ",selw ); 744 //qDebug("esl %d ",selw );
743 int add = 0; 745 int add = 0;
744 if ( colModulo ) { 746 if ( colModulo ) {
745 add = 7 - colModulo; 747 add = 7 - colModulo;
746 if ( selw > add ) 748 if ( selw > add )
747 add = selw - add; 749 add = selw - add;
748 else 750 else
749 add = 0; 751 add = 0;
750 } 752 }
751 //qDebug("add %d ", add); 753 //qDebug("add %d ", add);
752 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 754 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
753 selw*dwidth+add, dheight+1, selcol); 755 selw*dwidth+add, dheight+1, selcol);
754 } 756 }
755 } 757 }
756 } 758 }
757 759
758 // iterate over all days in the matrix and draw the day label in appropriate colors 760 // iterate over all days in the matrix and draw the day label in appropriate colors
759 QColor actcol = mDefaultTextColorShaded; 761 QColor actcol = mDefaultTextColorShaded;
760 p.setPen(actcol); 762 p.setPen(actcol);
761 QPen tmppen; 763 QPen tmppen;
762 for(int i = 0; i < NUMDAYS; i++) { 764 for(int i = 0; i < NUMDAYS; i++) {
763 row = i/7; 765 row = i/7;
764 col = isRTL ? 6-(i-row*7) : i-row*7; 766 col = isRTL ? 6-(i-row*7) : i-row*7;
765 767
766 // if it is the first day of a month switch color from normal to shaded and vice versa 768 // if it is the first day of a month switch color from normal to shaded and vice versa
767 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 769 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
768 if (actcol == mDefaultTextColorShaded) { 770 if (actcol == mDefaultTextColorShaded) {
769 actcol = mDefaultTextColor; 771 actcol = mDefaultTextColor;
770 } else { 772 } else {
771 actcol = mDefaultTextColorShaded; 773 actcol = mDefaultTextColorShaded;
772 } 774 }
773 p.setPen(actcol); 775 p.setPen(actcol);
774 } 776 }
775 if (actcol == mDefaultTextColorShaded) { 777 if (actcol == mDefaultTextColorShaded) {
776 if ( ! mouseDown ) { 778 if ( ! mouseDown ) {
777 continue; 779 continue;
778 } 780 }
779 } 781 }
780 //Reset pen color after selected days block 782 //Reset pen color after selected days block
781 if (i == mSelEndT+1) { 783 if (i == mSelEndT+1) {
782 p.setPen(actcol); 784 p.setPen(actcol);
783 } 785 }
784 786
785 // if today then draw rectangle around day 787 // if today then draw rectangle around day
786 if (today == i) { 788 if (today == i) {
787 tmppen = p.pen(); 789 tmppen = p.pen();
788 QPen mTodayPen(p.pen()); 790 QPen mTodayPen(p.pen());
789 if ( daysize.width() < 20 ) 791 if ( daysize.width() < 20 )
790 mTodayPen.setWidth(1); 792 mTodayPen.setWidth(1);
791 else 793 else
792 mTodayPen.setWidth(mTodayMarginWidth); 794 mTodayPen.setWidth(mTodayMarginWidth);
793 //draw red rectangle for holidays 795 //draw red rectangle for holidays
794 if (!mHolidays[i].isNull()) { 796 if (!mHolidays[i].isNull()) {
795 if (actcol == mDefaultTextColor) { 797 if (actcol == mDefaultTextColor) {
796 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 798 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
797 } else { 799 } else {
798 mTodayPen.setColor(mHolidayColorShaded); 800 mTodayPen.setColor(mHolidayColorShaded);
799 } 801 }
800 } 802 }
801 //draw gray rectangle for today if in selection 803 //draw gray rectangle for today if in selection
802 if (i >= mSelStartT && i <= mSelEndT) { 804 if (i >= mSelStartT && i <= mSelEndT) {
803 QColor grey("grey"); 805 QColor grey("grey");
804 mTodayPen.setColor(grey); 806 mTodayPen.setColor(grey);
805 } 807 }
806 p.setPen(mTodayPen); 808 p.setPen(mTodayPen);
807 809
808 810
809 int addCol = 0; 811 int addCol = 0;
810 int addRow = 0; 812 int addRow = 0;
811 if (rowModulo) { 813 if (rowModulo) {
812 if ( row >= 6 - rowModulo ) 814 if ( row >= 6 - rowModulo )
813 addRow = row - 5 + rowModulo; 815 addRow = row - 5 + rowModulo;
814 } 816 }
815 if ( colModulo ) { 817 if ( colModulo ) {
816 if ( col >= 7 - colModulo ) 818 if ( col >= 7 - colModulo )
817 addCol = col - 6 + colModulo-1; 819 addCol = col - 6 + colModulo-1;
818 } 820 }
819 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); 821 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1);
820 p.setPen(tmppen); 822 p.setPen(tmppen);
821 } 823 }
822 824
823 // if any events are on that day then draw it using a bold font 825 // if any events are on that day then draw it using a bold font
824 if (events[i] > 0) { 826 if (events[i] > 0) {
825 QFont myFont = font(); 827 QFont myFont = font();
826 myFont.setBold(true); 828 myFont.setBold(true);
827 p.setFont(myFont); 829 p.setFont(myFont);
828 } 830 }
829 831
830 // if it is a holiday then use the default holiday color 832 // if it is a holiday then use the default holiday color
831 if (!mHolidays[i].isNull()) { 833 if (!mHolidays[i].isNull()) {
832 if ( bDays.testBit(i) ) { 834 if ( bDays.testBit(i) ) {
833 p.setPen(Qt::green); 835 p.setPen(Qt::green);
834 } else { 836 } else {
835 if (actcol == mDefaultTextColor) { 837 if (actcol == mDefaultTextColor) {
836 p.setPen(KOPrefs::instance()->mHolidayColor); 838 p.setPen(KOPrefs::instance()->mHolidayColor);
837 } else { 839 } else {
838 p.setPen(mHolidayColorShaded); 840 p.setPen(mHolidayColorShaded);
839 } 841 }
840 } 842 }
841 } 843 }
842 844
843 // draw selected days with special color 845 // draw selected days with special color
844 // DO NOT specially highlight holidays in selection ! 846 // DO NOT specially highlight holidays in selection !
845 if (i >= mSelStartT && i <= mSelEndT) { 847 if (i >= mSelStartT && i <= mSelEndT) {
846 ;//p.setPen(mSelectedDaysColor); 848 ;//p.setPen(mSelectedDaysColor);
847 } 849 }
848 850
849 int addCol = 0; 851 int addCol = 0;
850 int addRow = 0; 852 int addRow = 0;
851 if ( colModulo ) { 853 if ( colModulo ) {
852 if ( col >= 7 - colModulo ) 854 if ( col >= 7 - colModulo )
853 addCol = col - 7 + colModulo; 855 addCol = col - 7 + colModulo;
854 } 856 }
855 if ( rowModulo ) { 857 if ( rowModulo ) {
856 if ( row >= 6 - rowModulo ) 858 if ( row >= 6 - rowModulo )
857 addRow = row - 5 + rowModulo; 859 addRow = row - 5 + rowModulo;
858 } 860 }
859 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow); 861 //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
860 ++addCol;//++addCol; 862 ++addCol;//++addCol;
861 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight, 863 p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
862 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 864 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
863 865
864 // reset color to actual color 866 // reset color to actual color
865 if (!mHolidays[i].isNull()) { 867 if (!mHolidays[i].isNull()) {
866 p.setPen(actcol); 868 p.setPen(actcol);
867 } 869 }
868 // reset bold font to plain font 870 // reset bold font to plain font
869 if (events[i] > 0) { 871 if (events[i] > 0) {
870 QFont myFont = font(); 872 QFont myFont = font();
871 myFont.setBold(false); 873 myFont.setBold(false);
872 p.setFont(myFont); 874 p.setFont(myFont);
873 } 875 }
874 } 876 }
875 int off = xyOff; 877 int off = xyOff;
876 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP); 878 bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
877 //qDebug("ffffffffff %d ", off); 879 //qDebug("ffffffffff %d ", off);
878} 880}
879 881
880// ---------------------------------------------------------------------------- 882// ----------------------------------------------------------------------------
881// R E SI Z E E V E N T H A N D L I N G 883// R E SI Z E E V E N T H A N D L I N G
882// ---------------------------------------------------------------------------- 884// ----------------------------------------------------------------------------
883 885
884void KODayMatrix::resizeEvent(QResizeEvent *) 886void KODayMatrix::resizeEvent(QResizeEvent *)
885{ 887{
886 QRect sz = frameRect(); 888 QRect sz = frameRect();
887 daysize.setHeight(sz.height()*7 / NUMDAYS); 889 daysize.setHeight(sz.height()*7 / NUMDAYS);
888 daysize.setWidth(sz.width() / 7); 890 daysize.setWidth(sz.width() / 7);
889} 891}
890 892
891QSize KODayMatrix::sizeHint() const 893QSize KODayMatrix::sizeHint() const
892{ 894{
893 895
894 QFontMetrics fm ( font() ); 896 QFontMetrics fm ( font() );
895 int wid = fm.width( "30") *7+3; 897 int wid = fm.width( "30") *7+3;
896 int hei = fm.height() * 6+3; 898 int hei = fm.height() * 6+3;
897 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei); 899 //qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
898 return QSize ( wid, hei ); 900 return QSize ( wid, hei );
899 901
900} 902}
diff --git a/korganizer/kodaymatrix.h b/korganizer/kodaymatrix.h
index f4016b6..10f4b05 100644
--- a/korganizer/kodaymatrix.h
+++ b/korganizer/kodaymatrix.h
@@ -1,322 +1,324 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
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 _KODAYMAT_H 23#ifndef _KODAYMAT_H
24#define _KODAYMAT_H 24#define _KODAYMAT_H
25 25
26#include <libkcal/calendar.h> 26#include <libkcal/calendar.h>
27 27
28#include <qstring.h> 28#include <qstring.h>
29#include <qframe.h> 29#include <qframe.h>
30#include <qcolor.h> 30#include <qcolor.h>
31#include <qpen.h> 31#include <qpen.h>
32#include <qdatetime.h> 32#include <qdatetime.h>
33#include <qtooltip.h> 33#include <qtooltip.h>
34#include <qpixmap.h> 34#include <qpixmap.h>
35#include <qbitarray.h> 35#include <qbitarray.h>
36#include <qmap.h> 36#include <qmap.h>
37 37
38class QDragEnterEvent; 38class QDragEnterEvent;
39class QDragMoveEvent; 39class QDragMoveEvent;
40class QDragLeaveEvent; 40class QDragLeaveEvent;
41class QDropEvent; 41class QDropEvent;
42 42
43class KODayMatrix; 43class KODayMatrix;
44class KODaymatrixWhatsThis;
44 45
45using namespace KCal; 46using namespace KCal;
46 47
47 48
48/** 49/**
49 * small helper class to dynamically show tooltips inside the day matrix. 50 * small helper class to dynamically show tooltips inside the day matrix.
50 * This class asks the day matrix object for a appropriate label which 51 * This class asks the day matrix object for a appropriate label which
51 * is in our special case the name of the holiday or null if this day is no holiday. 52 * is in our special case the name of the holiday or null if this day is no holiday.
52 */ 53 */
53class DynamicTip : public QToolTip 54class DynamicTip : public QToolTip
54{ 55{
55public: 56public:
56 57
57 /** 58 /**
58 * Constructor that expects a KODayMatrix object as parent. 59 * Constructor that expects a KODayMatrix object as parent.
59 * 60 *
60 * @param parent the parent KODayMatrix control. 61 * @param parent the parent KODayMatrix control.
61 */ 62 */
62 DynamicTip(QWidget* parent ); 63 DynamicTip(QWidget* parent );
63 64
64protected: 65protected:
65 66
66 /** 67 /**
67 * Qt's callback to ask the object to provide an approrpiate text for the 68 * Qt's callback to ask the object to provide an approrpiate text for the
68 * tooltip to be shown. 69 * tooltip to be shown.
69 * 70 *
70 * @param pos coordinates of the mouse. 71 * @param pos coordinates of the mouse.
71 */ 72 */
72 void maybeTip( const QPoint & pos); 73 void maybeTip( const QPoint & pos);
73 74
74private: 75private:
75 76
76 /** the parent control this tooltip is designed for. */ 77 /** the parent control this tooltip is designed for. */
77 KODayMatrix* matrix; 78 KODayMatrix* matrix;
78}; 79};
79 80
80/** 81/**
81 * replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed. 82 * replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed.
82 * Cornelius thought this was a waste of memory and a lot of overhead. 83 * Cornelius thought this was a waste of memory and a lot of overhead.
83 * In addition the selection was not very intuitive so I decided to rewrite it using a QFrame 84 * In addition the selection was not very intuitive so I decided to rewrite it using a QFrame
84 * that draws the labels and allows for dragging selection while maintaining nearly full 85 * that draws the labels and allows for dragging selection while maintaining nearly full
85 * compatibility in behaviour with its predecessor. 86 * compatibility in behaviour with its predecessor.
86 * 87 *
87 * The following functionality has been changed: 88 * The following functionality has been changed:
88 * 89 *
89 * o when shifting events in the agenda view from one day to another the day matrix is updated now 90 * o when shifting events in the agenda view from one day to another the day matrix is updated now
90 * o TODO ET dragging an event to the matrix will MOVE not COPY the event to the new date. 91 * o TODO ET dragging an event to the matrix will MOVE not COPY the event to the new date.
91 * o no support for Ctrl+click to create groups of dates 92 * o no support for Ctrl+click to create groups of dates
92 * (This has not really been supported in the predecessor. It was not very intuitive nor was it 93 * (This has not really been supported in the predecessor. It was not very intuitive nor was it
93 * user friendly.) 94 * user friendly.)
94 * This feature has been replaced with dragging a selection on the matrix. The matrix will 95 * This feature has been replaced with dragging a selection on the matrix. The matrix will
95 * automatically choose the appropriate selection (e.g. you are not any longer able to select 96 * automatically choose the appropriate selection (e.g. you are not any longer able to select
96 * two distinct groups of date selections as in the old class) 97 * two distinct groups of date selections as in the old class)
97 * o now that you can select more then a week it can happen that not all selected days are 98 * o now that you can select more then a week it can happen that not all selected days are
98 * displayed in the matrix. However this is preferred to the alternative which would mean to 99 * displayed in the matrix. However this is preferred to the alternative which would mean to
99 * adjust the selection and leave some days undisplayed while scrolling through the months 100 * adjust the selection and leave some days undisplayed while scrolling through the months
100 * 101 *
101 * @short day matrix widget of the KDateNavigator 102 * @short day matrix widget of the KDateNavigator
102 * 103 *
103 * @author Eitzenberger Thomas 104 * @author Eitzenberger Thomas
104 */ 105 */
105class KODayMatrix: public QFrame { 106class KODayMatrix: public QFrame {
106 107
107 Q_OBJECT 108 Q_OBJECT
108 109
109public: 110public:
110 111
111 /** constructor to create a day matrix widget. 112 /** constructor to create a day matrix widget.
112 * 113 *
113 * @param parent widget that is the parent of the day matrix. Normally this should 114 * @param parent widget that is the parent of the day matrix. Normally this should
114 * be a KDateNavigator 115 * be a KDateNavigator
115 * @param calendar instance of a calendar on which all calculations are based 116 * @param calendar instance of a calendar on which all calculations are based
116 * @param date start date of the matrix (is expected to be already fixed). It is 117 * @param date start date of the matrix (is expected to be already fixed). It is
117 * assumed that this date is the first week day to be shown in the matrix. 118 * assumed that this date is the first week day to be shown in the matrix.
118 * @param name name of the widget 119 * @param name name of the widget
119 */ 120 */
120 KODayMatrix( QWidget *parent, const char *name ); 121 KODayMatrix( QWidget *parent, const char *name );
121 //KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name ); 122 //KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name );
122 123
123 /** destructor that deallocates all dynamically allocated private members. 124 /** destructor that deallocates all dynamically allocated private members.
124 */ 125 */
125 ~KODayMatrix(); 126 ~KODayMatrix();
126 127
127 /** updates the day matrix to start with the given date. Does all the necessary 128 /** updates the day matrix to start with the given date. Does all the necessary
128 * checks for holidays or events on a day and stores them for display later on. 129 * checks for holidays or events on a day and stores them for display later on.
129 * Does NOT update the view visually. Call repaint() for this. 130 * Does NOT update the view visually. Call repaint() for this.
130 * 131 *
131 * @param actdate recalculates the day matrix to show NUMDAYS starting from this 132 * @param actdate recalculates the day matrix to show NUMDAYS starting from this
132 * date. 133 * date.
133 */ 134 */
134 void updateView(QDate actdate); 135 void updateView(QDate actdate);
135 void updateEvents(); 136 void updateEvents();
136 137
137 /** returns the QDate object associated with day indexed by the 138 /** returns the QDate object associated with day indexed by the
138 * supplied offset. 139 * supplied offset.
139 */ 140 */
140 const QDate& getDate(int offset); 141 const QDate& getDate(int offset);
141 void setCalendar( Calendar * ); 142 void setCalendar( Calendar * );
142 /** returns the official name of this holy day or 0 if there is no label 143 /** returns the official name of this holy day or 0 if there is no label
143 * for this day. 144 * for this day.
144 */ 145 */
145 QString getHolidayLabel(int offset); 146 QString getHolidayLabel(int offset);
146 147
147 /** adds all actual selected days from mSelStart to mSelEnd to the supplied 148 /** adds all actual selected days from mSelStart to mSelEnd to the supplied
148 * DateList. 149 * DateList.
149 */ 150 */
150 void addSelectedDaysTo(DateList&); 151 void addSelectedDaysTo(DateList&);
151 152
152 /** sets the actual to be displayed selection in the day matrix starting from 153 /** sets the actual to be displayed selection in the day matrix starting from
153 * start and ending with end. Theview must be manually updated by calling 154 * start and ending with end. Theview must be manually updated by calling
154 * repaint. (?) 155 * repaint. (?)
155 */ 156 */
156 void setSelectedDaysFrom(const QDate& start, const QDate& end); 157 void setSelectedDaysFrom(const QDate& start, const QDate& end);
157 void clearSelection(); 158 void clearSelection();
158 159
159 /** Is today visible in the view? Keep this in sync with 160 /** Is today visible in the view? Keep this in sync with
160 * the values today (below) can take. 161 * the values today (below) can take.
161 */ 162 */
162 bool isTodayVisible() const { return today>=0; } ; 163 bool isTodayVisible() const { return today>=0; } ;
163 164
164 /** If today is visible, then we can find out if today is 165 /** If today is visible, then we can find out if today is
165 * near the beginning or the end of the month. 166 * near the beginning or the end of the month.
166 * This is dependent on today remaining the index 167 * This is dependent on today remaining the index
167 * in the array of visible dates and going from 168 * in the array of visible dates and going from
168 * top left (0) to bottom right (41). 169 * top left (0) to bottom right (41).
169 */ 170 */
170 bool isBeginningOfMonth() const { return today<=8; } ; 171 bool isBeginningOfMonth() const { return today<=8; } ;
171 bool isEndOfMonth() const { return today>=27; } ; 172 bool isEndOfMonth() const { return today>=27; } ;
172 QString getWhatsThisText( QPoint ) ; 173 QString getWhatsThisText( QPoint ) ;
173 QSize sizeHint() const; 174 QSize sizeHint() const;
174 QRect frameRect () const { int wid = frameWidth(); return QRect(0+wid,0+wid,width()-wid-wid,height()-wid-wid);} 175 QRect frameRect () const { int wid = frameWidth(); return QRect(0+wid,0+wid,width()-wid-wid,height()-wid-wid);}
175public slots: 176public slots:
176 /** Recalculates all the flags of the days in the matrix like holidays or events 177 /** Recalculates all the flags of the days in the matrix like holidays or events
177 * on a day (Actually calls above method with the actual startdate). 178 * on a day (Actually calls above method with the actual startdate).
178 */ 179 */
179 void updateView(); 180 void updateView();
180 void updateViewTimed(); 181 void updateViewTimed();
181 void repaintViewTimed(); 182 void repaintViewTimed();
182 183
183 /** 184 /**
184 * Calculate which square in the matrix should be 185 * Calculate which square in the matrix should be
185 * hilighted to indicate it's today. 186 * hilighted to indicate it's today.
186 */ 187 */
187 void recalculateToday(); 188 void recalculateToday();
188 189
189/* 190/*
190 void setStartDate(QDate); 191 void setStartDate(QDate);
191*/ 192*/
192 193
193signals: 194signals:
194 195
195 /** emitted if the user selects a block of days with the mouse by dragging a rectangle 196 /** emitted if the user selects a block of days with the mouse by dragging a rectangle
196 * inside the matrix 197 * inside the matrix
197 * 198 *
198 * @param daylist list of days that have been selected by the user 199 * @param daylist list of days that have been selected by the user
199 */ 200 */
200 void selected( const KCal::DateList &daylist ); 201 void selected( const KCal::DateList &daylist );
201 202
202 /** emitted if the user has dropped an event inside the matrix 203 /** emitted if the user has dropped an event inside the matrix
203 * 204 *
204 * @param event the dropped calendar event 205 * @param event the dropped calendar event
205 */ 206 */
206 void eventDropped(Event *event); 207 void eventDropped(Event *event);
207 208
208protected: 209protected:
209 210
210 void paintEvent(QPaintEvent *ev); 211 void paintEvent(QPaintEvent *ev);
211 212
212 void mousePressEvent (QMouseEvent* e); 213 void mousePressEvent (QMouseEvent* e);
213 214
214 void mouseReleaseEvent (QMouseEvent* e); 215 void mouseReleaseEvent (QMouseEvent* e);
215 216
216 void mouseMoveEvent (QMouseEvent* e); 217 void mouseMoveEvent (QMouseEvent* e);
217 218
218 void dragEnterEvent(QDragEnterEvent *); 219 void dragEnterEvent(QDragEnterEvent *);
219 220
220 void dragMoveEvent(QDragMoveEvent *); 221 void dragMoveEvent(QDragMoveEvent *);
221 222
222 void dragLeaveEvent(QDragLeaveEvent *); 223 void dragLeaveEvent(QDragLeaveEvent *);
223 224
224 void dropEvent(QDropEvent *); 225 void dropEvent(QDropEvent *);
225 226
226 void resizeEvent(QResizeEvent *); 227 void resizeEvent(QResizeEvent *);
227 228
228private: 229private:
230 KODaymatrixWhatsThis* mKODaymatrixWhatsThis;
229 bool mouseDown; 231 bool mouseDown;
230 QBitArray bDays; 232 QBitArray bDays;
231 QPixmap myPix; 233 QPixmap myPix;
232 QTimer* mUpdateTimer; 234 QTimer* mUpdateTimer;
233 QTimer* mRepaintTimer; 235 QTimer* mRepaintTimer;
234 bool mDayChanged; 236 bool mDayChanged;
235 bool mPendingUpdateBeforeRepaint; 237 bool mPendingUpdateBeforeRepaint;
236 238
237 /** returns the index of the day located at the matrix's widget (x,y) position. 239 /** returns the index of the day located at the matrix's widget (x,y) position.
238 * 240 *
239 * @param x horizontal coordinate 241 * @param x horizontal coordinate
240 * @param y vertical coordinate 242 * @param y vertical coordinate
241 */ 243 */
242 int getDayIndexFrom(int x, int y); 244 int getDayIndexFrom(int x, int y);
243 245
244 /** calculates a "shaded" color from the supplied color object. 246 /** calculates a "shaded" color from the supplied color object.
245 * (Copied from Cornelius's kdpdatebutton.cpp) 247 * (Copied from Cornelius's kdpdatebutton.cpp)
246 * 248 *
247 * @param color source based on which a shaded color should be calculated. 249 * @param color source based on which a shaded color should be calculated.
248 */ 250 */
249 QColor getShadedColor(QColor color); 251 QColor getShadedColor(QColor color);
250 252
251 /** number of days to be displayed. For now there is no support for any other number then 42. 253 /** number of days to be displayed. For now there is no support for any other number then 42.
252 so change it at your own risk :o) */ 254 so change it at your own risk :o) */
253 static const int NUMDAYS; 255 static const int NUMDAYS;
254 256
255 /** calendar instance to be queried for holidays, events, ... */ 257 /** calendar instance to be queried for holidays, events, ... */
256 Calendar *mCalendar; 258 Calendar *mCalendar;
257 259
258 /** starting date of the matrix */ 260 /** starting date of the matrix */
259 QDate startdate; 261 QDate startdate;
260 262
261 /** array of day labels to optimeize drawing performance. */ 263 /** array of day labels to optimeize drawing performance. */
262 QString *daylbls; 264 QString *daylbls;
263 265
264 /** array of days displayed to reduce memory consumption by 266 /** array of days displayed to reduce memory consumption by
265 subsequently calling QDate::addDays(). */ 267 subsequently calling QDate::addDays(). */
266 QDate *days; 268 QDate *days;
267 269
268 /** array of storing the number of events on a given day. 270 /** array of storing the number of events on a given day.
269 * used for drawing a bold font if there is at least one event on that day. 271 * used for drawing a bold font if there is at least one event on that day.
270 */ 272 */
271 int *events; 273 int *events;
272 274
273 /** stores holiday names of the days shown in the matrix. */ 275 /** stores holiday names of the days shown in the matrix. */
274 QMap<int,QString> mHolidays; 276 QMap<int,QString> mHolidays;
275 277
276 /** indey of today or -1 if today is not visible in the matrix. */ 278 /** indey of today or -1 if today is not visible in the matrix. */
277 int today; 279 int today;
278 280
279 /** index of day where dragged selection was initiated. 281 /** index of day where dragged selection was initiated.
280 used to detect "negative" timely selections */ 282 used to detect "negative" timely selections */
281 int mSelInit; 283 int mSelInit;
282 284
283 /** if mSelStart has this value it indicates that there is no 285 /** if mSelStart has this value it indicates that there is no
284 actual selection in the matrix. */ 286 actual selection in the matrix. */
285 static const int NOSELECTION; 287 static const int NOSELECTION;
286 288
287 /** index of first selected day. */ 289 /** index of first selected day. */
288 int mSelStart; 290 int mSelStart;
289 291
290 /** index of last selected day. */ 292 /** index of last selected day. */
291 int mSelEnd; 293 int mSelEnd;
292 294
293 /** dynamic tooltip to handle mouse dependent tips for each day in the matrix. */ 295 /** dynamic tooltip to handle mouse dependent tips for each day in the matrix. */
294 DynamicTip* mToolTip; 296 DynamicTip* mToolTip;
295 297
296 298
297 /** default background colour of the matrix. */ 299 /** default background colour of the matrix. */
298 QColor mDefaultBackColor; 300 QColor mDefaultBackColor;
299 301
300 /** default text color of the matrix. */ 302 /** default text color of the matrix. */
301 QColor mDefaultTextColor; 303 QColor mDefaultTextColor;
302 304
303 /** default text color for days not in the actual month. */ 305 /** default text color for days not in the actual month. */
304 QColor mDefaultTextColorShaded; 306 QColor mDefaultTextColorShaded;
305 307
306 /** default text color for holidays not in the actual month. */ 308 /** default text color for holidays not in the actual month. */
307 QColor mHolidayColorShaded; 309 QColor mHolidayColorShaded;
308 310
309 /** text color for selected days. */ 311 /** text color for selected days. */
310 QColor mSelectedDaysColor; 312 QColor mSelectedDaysColor;
311 313
312 /** default width of the frame drawn around today if it is visible in the matrix. */ 314 /** default width of the frame drawn around today if it is visible in the matrix. */
313 int mTodayMarginWidth; 315 int mTodayMarginWidth;
314 316
315 /** stores actual size of each day in the widget so that I dont need to ask this data 317 /** stores actual size of each day in the widget so that I dont need to ask this data
316 * on every repaint. 318 * on every repaint.
317 */ 319 */
318 QRect daysize; 320 QRect daysize;
319 321
320}; 322};
321 323
322#endif 324#endif
diff --git a/korganizer/kotodoview.cpp b/korganizer/kotodoview.cpp
index 5e8ea27..2b01c23 100644
--- a/korganizer/kotodoview.cpp
+++ b/korganizer/kotodoview.cpp
@@ -1,1340 +1,1341 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000,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 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qcursor.h> 26#include <qcursor.h>
27#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28 28
29#include <qvbox.h> 29#include <qvbox.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include "koprefs.h" 31#include "koprefs.h"
32#include <klocale.h> 32#include <klocale.h>
33#include <kglobal.h> 33#include <kglobal.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <libkcal/icaldrag.h> 37#include <libkcal/icaldrag.h>
38#include <libkcal/vcaldrag.h> 38#include <libkcal/vcaldrag.h>
39#include <libkcal/calfilter.h> 39#include <libkcal/calfilter.h>
40#include <libkcal/dndfactory.h> 40#include <libkcal/dndfactory.h>
41#include <libkcal/calendarresources.h> 41#include <libkcal/calendarresources.h>
42#include <libkcal/resourcecalendar.h> 42#include <libkcal/resourcecalendar.h>
43#include <kresources/resourceselectdialog.h> 43#include <kresources/resourceselectdialog.h>
44#include <libkcal/kincidenceformatter.h> 44#include <libkcal/kincidenceformatter.h>
45#ifndef DESKTOP_VERSION 45#ifndef DESKTOP_VERSION
46#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
47#else 47#else
48#include <qapplication.h> 48#include <qapplication.h>
49#endif 49#endif
50#ifndef KORG_NOPRINTER 50#ifndef KORG_NOPRINTER
51#include "calprinter.h" 51#include "calprinter.h"
52#endif 52#endif
53#include "docprefs.h" 53#include "docprefs.h"
54 54
55#include "kotodoview.h" 55#include "kotodoview.h"
56using namespace KOrg; 56using namespace KOrg;
57 57
58 58
59class KOTodoViewWhatsThis :public QWhatsThis 59class KOTodoViewWhatsThis :public QWhatsThis
60{ 60{
61public: 61public:
62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { }; 62 KOTodoViewWhatsThis( QWidget *wid, KOTodoView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
63 63
64protected: 64protected:
65 virtual QString text( const QPoint& p) 65 virtual QString text( const QPoint& p)
66 { 66 {
67 return _view->getWhatsThisText(p) ; 67 return _view->getWhatsThisText(p) ;
68 } 68 }
69private: 69private:
70 QWidget* _wid; 70 QWidget* _wid;
71 KOTodoView * _view; 71 KOTodoView * _view;
72}; 72};
73 73
74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent, 74KOTodoListView::KOTodoListView(Calendar *calendar,QWidget *parent,
75 const char *name) : 75 const char *name) :
76 KListView(parent,name) 76 KListView(parent,name)
77{ 77{
78 mName = QString ( name ); 78 mName = QString ( name );
79 mCalendar = calendar; 79 mCalendar = calendar;
80#ifndef DESKTOP_VERSION 80#ifndef DESKTOP_VERSION
81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold ); 81 QPEApplication::setStylusOperation(viewport(), QPEApplication::RightOnHold );
82#endif 82#endif
83 mOldCurrent = 0; 83 mOldCurrent = 0;
84 mMousePressed = false; 84 mMousePressed = false;
85 85
86 setAcceptDrops(true); 86 setAcceptDrops(true);
87 viewport()->setAcceptDrops(true); 87 viewport()->setAcceptDrops(true);
88 int size = 16; 88 int size = 16;
89 if (qApp->desktop()->width() < 300 ) 89 if (qApp->desktop()->width() < 300 )
90 size = 12; 90 size = 12;
91 setTreeStepSize( size + 6 ); 91 setTreeStepSize( size + 6 );
92 92
93} 93}
94 94
95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e) 95void KOTodoListView::contentsDragEnterEvent(QDragEnterEvent *e)
96{ 96{
97#ifndef KORG_NODND 97#ifndef KORG_NODND
98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl; 98// kdDebug() << "KOTodoListView::contentsDragEnterEvent" << endl;
99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 99 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
100 !QTextDrag::canDecode( e ) ) { 100 !QTextDrag::canDecode( e ) ) {
101 e->ignore(); 101 e->ignore();
102 return; 102 return;
103 } 103 }
104 104
105 mOldCurrent = currentItem(); 105 mOldCurrent = currentItem();
106#endif 106#endif
107} 107}
108 108
109 109
110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e) 110void KOTodoListView::contentsDragMoveEvent(QDragMoveEvent *e)
111{ 111{
112#ifndef KORG_NODND 112#ifndef KORG_NODND
113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl; 113// kdDebug() << "KOTodoListView::contentsDragMoveEvent" << endl;
114 114
115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 115 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
116 !QTextDrag::canDecode( e ) ) { 116 !QTextDrag::canDecode( e ) ) {
117 e->ignore(); 117 e->ignore();
118 return; 118 return;
119 } 119 }
120 120
121 e->accept(); 121 e->accept();
122#endif 122#endif
123} 123}
124 124
125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *) 125void KOTodoListView::contentsDragLeaveEvent(QDragLeaveEvent *)
126{ 126{
127#ifndef KORG_NODND 127#ifndef KORG_NODND
128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl; 128// kdDebug() << "KOTodoListView::contentsDragLeaveEvent" << endl;
129 129
130 setCurrentItem(mOldCurrent); 130 setCurrentItem(mOldCurrent);
131 setSelected(mOldCurrent,true); 131 setSelected(mOldCurrent,true);
132#endif 132#endif
133} 133}
134 134
135void KOTodoListView::contentsDropEvent(QDropEvent *e) 135void KOTodoListView::contentsDropEvent(QDropEvent *e)
136{ 136{
137#ifndef KORG_NODND 137#ifndef KORG_NODND
138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl; 138// kdDebug() << "KOTodoListView::contentsDropEvent" << endl;
139 139
140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) && 140 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) &&
141 !QTextDrag::canDecode( e ) ) { 141 !QTextDrag::canDecode( e ) ) {
142 e->ignore(); 142 e->ignore();
143 return; 143 return;
144 } 144 }
145 145
146 DndFactory factory( mCalendar ); 146 DndFactory factory( mCalendar );
147 Todo *todo = factory.createDropTodo(e); 147 Todo *todo = factory.createDropTodo(e);
148 148
149 if (todo) { 149 if (todo) {
150 e->acceptAction(); 150 e->acceptAction();
151 151
152 KOTodoViewItem *destination = 152 KOTodoViewItem *destination =
153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos())); 153 (KOTodoViewItem *)itemAt(contentsToViewport(e->pos()));
154 Todo *destinationEvent = 0; 154 Todo *destinationEvent = 0;
155 if (destination) destinationEvent = destination->todo(); 155 if (destination) destinationEvent = destination->todo();
156 156
157 Todo *existingTodo = mCalendar->todo(todo->uid()); 157 Todo *existingTodo = mCalendar->todo(todo->uid());
158 158
159 if(existingTodo) { 159 if(existingTodo) {
160 Incidence *to = destinationEvent; 160 Incidence *to = destinationEvent;
161 while(to) { 161 while(to) {
162 if (to->uid() == todo->uid()) { 162 if (to->uid() == todo->uid()) {
163 KMessageBox::sorry(this, 163 KMessageBox::sorry(this,
164 i18n("Cannot move To-Do to itself\nor a child of itself"), 164 i18n("Cannot move To-Do to itself\nor a child of itself"),
165 i18n("Drop To-Do")); 165 i18n("Drop To-Do"));
166 delete todo; 166 delete todo;
167 return; 167 return;
168 } 168 }
169 to = to->relatedTo(); 169 to = to->relatedTo();
170 } 170 }
171 internalDrop = true; 171 internalDrop = true;
172 if ( destinationEvent ) 172 if ( destinationEvent )
173 reparentTodoSignal( destinationEvent, existingTodo ); 173 reparentTodoSignal( destinationEvent, existingTodo );
174 else 174 else
175 unparentTodoSignal(existingTodo); 175 unparentTodoSignal(existingTodo);
176 delete todo; 176 delete todo;
177 } else { 177 } else {
178 mCalendar->addTodo(todo); 178 mCalendar->addTodo(todo);
179 emit todoDropped(todo, KOGlobals::EVENTADDED); 179 emit todoDropped(todo, KOGlobals::EVENTADDED);
180 if ( destinationEvent ) 180 if ( destinationEvent )
181 reparentTodoSignal( destinationEvent, todo ); 181 reparentTodoSignal( destinationEvent, todo );
182 } 182 }
183 } 183 }
184 else { 184 else {
185 QString text; 185 QString text;
186 if (QTextDrag::decode(e,text)) { 186 if (QTextDrag::decode(e,text)) {
187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) ); 187 //QListViewItem *qlvi = itemAt( contentsToViewport(e->pos()) );
188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) )); 188 KOTodoViewItem *todoi = static_cast<KOTodoViewItem *>(itemAt( contentsToViewport(e->pos()) ));
189 qDebug("Dropped : " + text); 189 qDebug("Dropped : " + text);
190 QStringList emails = QStringList::split(",",text); 190 QStringList emails = QStringList::split(",",text);
191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) { 191 for(QStringList::ConstIterator it = emails.begin();it!=emails.end();++it) {
192 int pos = (*it).find("<"); 192 int pos = (*it).find("<");
193 QString name = (*it).left(pos); 193 QString name = (*it).left(pos);
194 QString email = (*it).mid(pos); 194 QString email = (*it).mid(pos);
195 if (!email.isEmpty() && todoi) { 195 if (!email.isEmpty() && todoi) {
196 todoi->todo()->addAttendee(new Attendee(name,email)); 196 todoi->todo()->addAttendee(new Attendee(name,email));
197 } 197 }
198 } 198 }
199 } 199 }
200 else { 200 else {
201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable "); 201 qDebug("KOTodoListView::contentsDropEvent(): Todo from drop not decodable ");
202 e->ignore(); 202 e->ignore();
203 } 203 }
204 } 204 }
205#endif 205#endif
206} 206}
207 207
208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e) 208void KOTodoListView::contentsMousePressEvent(QMouseEvent* e)
209{ 209{
210#ifndef KORG_NODND 210#ifndef KORG_NODND
211 QPoint p(contentsToViewport(e->pos())); 211 QPoint p(contentsToViewport(e->pos()));
212 QListViewItem *i = itemAt(p); 212 QListViewItem *i = itemAt(p);
213 mMousePressed = false; 213 mMousePressed = false;
214 if (i) { 214 if (i) {
215 // if the user clicked into the root decoration of the item, don't 215 // if the user clicked into the root decoration of the item, don't
216 // try to start a drag! 216 // try to start a drag!
217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) + 217 if (p.x() > header()->sectionPos(header()->mapToIndex(0)) +
218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) + 218 treeStepSize() * (i->depth() + (rootIsDecorated() ? 1 : 0)) +
219 itemMargin() || 219 itemMargin() ||
220 p.x() < header()->sectionPos(header()->mapToIndex(0))) { 220 p.x() < header()->sectionPos(header()->mapToIndex(0))) {
221 if (e->button()==Qt::LeftButton) { 221 if (e->button()==Qt::LeftButton) {
222 mPressPos = e->pos(); 222 mPressPos = e->pos();
223 mMousePressed = true; 223 mMousePressed = true;
224 } 224 }
225 } 225 }
226 } 226 }
227#endif 227#endif
228 QListView::contentsMousePressEvent(e); 228 QListView::contentsMousePressEvent(e);
229} 229}
230void KOTodoListView::paintEvent(QPaintEvent* e) 230void KOTodoListView::paintEvent(QPaintEvent* e)
231{ 231{
232 emit paintNeeded(); 232 emit paintNeeded();
233 QListView::paintEvent( e); 233 QListView::paintEvent( e);
234} 234}
235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e) 235void KOTodoListView::contentsMouseMoveEvent(QMouseEvent* e)
236{ 236{
237 237
238#ifndef KORG_NODND 238#ifndef KORG_NODND
239 //QListView::contentsMouseMoveEvent(e); 239 //QListView::contentsMouseMoveEvent(e);
240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() > 240 if (mMousePressed && (mPressPos - e->pos()).manhattanLength() >
241 QApplication::startDragDistance()*3) { 241 QApplication::startDragDistance()*3) {
242 mMousePressed = false; 242 mMousePressed = false;
243 QListViewItem *item = itemAt(contentsToViewport(mPressPos)); 243 QListViewItem *item = itemAt(contentsToViewport(mPressPos));
244 if (item) { 244 if (item) {
245 DndFactory factory( mCalendar ); 245 DndFactory factory( mCalendar );
246 ICalDrag *vd = factory.createDrag( 246 ICalDrag *vd = factory.createDrag(
247 ((KOTodoViewItem *)item)->todo(),viewport()); 247 ((KOTodoViewItem *)item)->todo(),viewport());
248 internalDrop = false; 248 internalDrop = false;
249 // we cannot do any senseful here, because the DnD is still broken in Qt 249 // we cannot do any senseful here, because the DnD is still broken in Qt
250 if (vd->drag()) { 250 if (vd->drag()) {
251 if ( !internalDrop ) { 251 if ( !internalDrop ) {
252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() ); 252 //emit deleteTodo( ((KOTodoViewItem *)item)->todo() );
253 qDebug("Dnd: External move: Delete drag source "); 253 qDebug("Dnd: External move: Delete drag source ");
254 } else 254 } else
255 qDebug("Dnd: Internal move "); 255 qDebug("Dnd: Internal move ");
256 256
257 } else { 257 } else {
258 if ( !internalDrop ) { 258 if ( !internalDrop ) {
259 qDebug("Dnd: External Copy"); 259 qDebug("Dnd: External Copy");
260 } else 260 } else
261 qDebug("DnD: Internal copy: Copy pending"); 261 qDebug("DnD: Internal copy: Copy pending");
262 } 262 }
263 } 263 }
264 } 264 }
265#endif 265#endif
266} 266}
267void KOTodoListView::keyPressEvent ( QKeyEvent * e ) 267void KOTodoListView::keyPressEvent ( QKeyEvent * e )
268{ 268{
269 269
270 QListViewItem* cn; 270 QListViewItem* cn;
271 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) { 271 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
272 cn = currentItem(); 272 cn = currentItem();
273 if ( cn ) { 273 if ( cn ) {
274 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 274 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
275 if ( ci ){ 275 if ( ci ){
276 if ( e->state() == ShiftButton ) 276 if ( e->state() == ShiftButton )
277 ci->setOn( false ); 277 ci->setOn( false );
278 else 278 else
279 ci->setOn( true ); 279 ci->setOn( true );
280 cn = cn->itemBelow(); 280 cn = cn->itemBelow();
281 if ( cn ) { 281 if ( cn ) {
282 setCurrentItem ( cn ); 282 setCurrentItem ( cn );
283 ensureItemVisible ( cn ); 283 ensureItemVisible ( cn );
284 } 284 }
285 285
286 } 286 }
287 } 287 }
288 288
289 return; 289 return;
290 } 290 }
291 291
292 // qDebug("KOTodoListView::keyPressEvent "); 292 // qDebug("KOTodoListView::keyPressEvent ");
293 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) { 293 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton || mName != "todolistsmall" ) {
294 switch ( e->key() ) { 294 switch ( e->key() ) {
295 case Qt::Key_Down: 295 case Qt::Key_Down:
296 case Qt::Key_Up: 296 case Qt::Key_Up:
297 QListView::keyPressEvent ( e ); 297 QListView::keyPressEvent ( e );
298 break; 298 break;
299 case Qt::Key_Left: 299 case Qt::Key_Left:
300 case Qt::Key_Right: 300 case Qt::Key_Right:
301 QListView::keyPressEvent ( e ); 301 QListView::keyPressEvent ( e );
302 e->accept(); 302 e->accept();
303 return; 303 return;
304 break; 304 break;
305 default: 305 default:
306 e->ignore(); 306 e->ignore();
307 break; 307 break;
308 } 308 }
309 return; 309 return;
310 } 310 }
311 e->ignore(); 311 e->ignore();
312} 312}
313void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e) 313void KOTodoListView::contentsMouseReleaseEvent(QMouseEvent *e)
314{ 314{
315 QListView::contentsMouseReleaseEvent(e); 315 QListView::contentsMouseReleaseEvent(e);
316 mMousePressed = false; 316 mMousePressed = false;
317} 317}
318 318
319void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e) 319void KOTodoListView::contentsMouseDoubleClickEvent(QMouseEvent *e)
320{ 320{
321 if (!e) return; 321 if (!e) return;
322 322
323 QPoint vp = contentsToViewport(e->pos()); 323 QPoint vp = contentsToViewport(e->pos());
324 324
325 QListViewItem *item = itemAt(vp); 325 QListViewItem *item = itemAt(vp);
326 326
327 emit double_Clicked(item); 327 emit double_Clicked(item);
328 if (!item) return; 328 if (!item) return;
329 329
330 emit doubleClicked(item,vp,0); 330 emit doubleClicked(item,vp,0);
331} 331}
332 332
333///////////////////////////////////////////////////////////////////////////// 333/////////////////////////////////////////////////////////////////////////////
334 334
335KOQuickTodo::KOQuickTodo(QWidget *parent) : 335KOQuickTodo::KOQuickTodo(QWidget *parent) :
336 QLineEdit(parent) 336 QLineEdit(parent)
337{ 337{
338 setText(i18n("Click to add a new Todo")); 338 setText(i18n("Click to add a new Todo"));
339} 339}
340 340
341void KOQuickTodo::focusInEvent(QFocusEvent *ev) 341void KOQuickTodo::focusInEvent(QFocusEvent *ev)
342{ 342{
343 if ( text()==i18n("Click to add a new Todo") ) 343 if ( text()==i18n("Click to add a new Todo") )
344 setText(""); 344 setText("");
345 QLineEdit::focusInEvent(ev); 345 QLineEdit::focusInEvent(ev);
346} 346}
347 347
348void KOQuickTodo::focusOutEvent(QFocusEvent *ev) 348void KOQuickTodo::focusOutEvent(QFocusEvent *ev)
349{ 349{
350 setText(i18n("Click to add a new Todo")); 350 setText(i18n("Click to add a new Todo"));
351 QLineEdit::focusOutEvent(ev); 351 QLineEdit::focusOutEvent(ev);
352} 352}
353 353
354///////////////////////////////////////////////////////////////////////////// 354/////////////////////////////////////////////////////////////////////////////
355 355
356KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) : 356KOTodoView::KOTodoView(Calendar *calendar,QWidget* parent,const char* name) :
357 KOrg::BaseView(calendar,parent,name) 357 KOrg::BaseView(calendar,parent,name)
358{ 358{
359 mPendingUpdateBeforeRepaint = false; 359 mPendingUpdateBeforeRepaint = false;
360 isFlatDisplay = false; 360 isFlatDisplay = false;
361 mNavigator = 0; 361 mNavigator = 0;
362 QBoxLayout *topLayout = new QVBoxLayout(this); 362 QBoxLayout *topLayout = new QVBoxLayout(this);
363 mName = QString ( name ); 363 mName = QString ( name );
364 mBlockUpdate = false; 364 mBlockUpdate = false;
365 mQuickAdd = new KOQuickTodo(this); 365 mQuickAdd = new KOQuickTodo(this);
366 topLayout->addWidget(mQuickAdd); 366 topLayout->addWidget(mQuickAdd);
367 367
368 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide(); 368 if ( !KOPrefs::instance()->mEnableQuickTodo ) mQuickAdd->hide();
369 369
370 mTodoListView = new KOTodoListView(calendar,this, name ); 370 mTodoListView = new KOTodoListView(calendar,this, name );
371 topLayout->addWidget(mTodoListView); 371 topLayout->addWidget(mTodoListView);
372 //mTodoListView->header()->setMaximumHeight(30); 372 //mTodoListView->header()->setMaximumHeight(30);
373 mTodoListView->setRootIsDecorated(true); 373 mTodoListView->setRootIsDecorated(true);
374 mTodoListView->setAllColumnsShowFocus(true); 374 mTodoListView->setAllColumnsShowFocus(true);
375 375
376 mTodoListView->setShowSortIndicator(true); 376 mTodoListView->setShowSortIndicator(true);
377 377
378 mTodoListView->addColumn(i18n("Todo")); 378 mTodoListView->addColumn(i18n("Todo"));
379 mTodoListView->addColumn(i18n("Prio")); 379 mTodoListView->addColumn(i18n("Prio"));
380 mTodoListView->setColumnAlignment(1,AlignHCenter); 380 mTodoListView->setColumnAlignment(1,AlignHCenter);
381 mTodoListView->addColumn(i18n("Complete")); 381 mTodoListView->addColumn(i18n("Complete"));
382 mTodoListView->setColumnAlignment(2,AlignCenter); 382 mTodoListView->setColumnAlignment(2,AlignCenter);
383 383
384 mTodoListView->addColumn(i18n("Due Date")); 384 mTodoListView->addColumn(i18n("Due Date"));
385 mTodoListView->setColumnAlignment(3,AlignLeft); 385 mTodoListView->setColumnAlignment(3,AlignLeft);
386 mTodoListView->addColumn(i18n("Due Time")); 386 mTodoListView->addColumn(i18n("Due Time"));
387 mTodoListView->setColumnAlignment(4,AlignHCenter); 387 mTodoListView->setColumnAlignment(4,AlignHCenter);
388 388
389 mTodoListView->addColumn(i18n("Start Date")); 389 mTodoListView->addColumn(i18n("Start Date"));
390 mTodoListView->setColumnAlignment(5,AlignLeft); 390 mTodoListView->setColumnAlignment(5,AlignLeft);
391 mTodoListView->addColumn(i18n("Start Time")); 391 mTodoListView->addColumn(i18n("Start Time"));
392 mTodoListView->setColumnAlignment(6,AlignHCenter); 392 mTodoListView->setColumnAlignment(6,AlignHCenter);
393 393
394 mTodoListView->addColumn(i18n("Cancelled")); 394 mTodoListView->addColumn(i18n("Cancelled"));
395 mTodoListView->addColumn(i18n("Categories")); 395 mTodoListView->addColumn(i18n("Categories"));
396#if 0 396#if 0
397 mTodoListView->addColumn(i18n("Sort Id")); 397 mTodoListView->addColumn(i18n("Sort Id"));
398 mTodoListView->setColumnAlignment(4,AlignHCenter); 398 mTodoListView->setColumnAlignment(4,AlignHCenter);
399#endif 399#endif
400 400
401 mTodoListView->setMinimumHeight( 60 ); 401 mTodoListView->setMinimumHeight( 60 );
402 mTodoListView->setItemsRenameable( true ); 402 mTodoListView->setItemsRenameable( true );
403 mTodoListView->setRenameable( 0 ); 403 mTodoListView->setRenameable( 0 );
404 mTodoListView->setColumnWidth( 0, 120 ); 404 mTodoListView->setColumnWidth( 0, 120 );
405 mTodoListView->setColumnWidthMode(0, QListView::Manual); 405 mTodoListView->setColumnWidthMode(0, QListView::Manual);
406 mTodoListView->setColumnWidthMode(1, QListView::Manual); 406 mTodoListView->setColumnWidthMode(1, QListView::Manual);
407 mTodoListView->setColumnWidthMode(2, QListView::Manual); 407 mTodoListView->setColumnWidthMode(2, QListView::Manual);
408 mTodoListView->setColumnWidthMode(3, QListView::Manual); 408 mTodoListView->setColumnWidthMode(3, QListView::Manual);
409 mTodoListView->setColumnWidthMode(4, QListView::Manual); 409 mTodoListView->setColumnWidthMode(4, QListView::Manual);
410 mTodoListView->setColumnWidthMode(5, QListView::Manual); 410 mTodoListView->setColumnWidthMode(5, QListView::Manual);
411 mTodoListView->setColumnWidthMode(6, QListView::Manual); 411 mTodoListView->setColumnWidthMode(6, QListView::Manual);
412 mTodoListView->setColumnWidthMode(7, QListView::Manual); 412 mTodoListView->setColumnWidthMode(7, QListView::Manual);
413 mTodoListView->setColumnWidthMode(8, QListView::Manual); 413 mTodoListView->setColumnWidthMode(8, QListView::Manual);
414 414
415 415
416 new KOTodoViewWhatsThis(mTodoListView->viewport(),this); 416 mKOTodoViewWhatsThis = new KOTodoViewWhatsThis(mTodoListView->viewport(),this);
417 417
418 mPriorityPopupMenu = new QPopupMenu(this); 418 mPriorityPopupMenu = new QPopupMenu(this);
419 for (int i = 1; i <= 5; i++) { 419 for (int i = 1; i <= 5; i++) {
420 QString label = QString ("%1").arg (i); 420 QString label = QString ("%1").arg (i);
421 mPriority[mPriorityPopupMenu->insertItem (label)] = i; 421 mPriority[mPriorityPopupMenu->insertItem (label)] = i;
422 } 422 }
423 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int))); 423 connect (mPriorityPopupMenu, SIGNAL(activated (int)), SLOT (setNewPriority(int)));
424 424
425 mPercentageCompletedPopupMenu = new QPopupMenu(this); 425 mPercentageCompletedPopupMenu = new QPopupMenu(this);
426 for (int i = 0; i <= 100; i+=20) { 426 for (int i = 0; i <= 100; i+=20) {
427 QString label = QString ("%1 %").arg (i); 427 QString label = QString ("%1 %").arg (i);
428 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i; 428 mPercentage[mPercentageCompletedPopupMenu->insertItem (label)] = i;
429 } 429 }
430 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int))); 430 connect (mPercentageCompletedPopupMenu, SIGNAL (activated (int)), SLOT (setNewPercentage (int)));
431 431
432 432
433 433
434 mItemPopupMenu = new QPopupMenu(this); 434 mItemPopupMenu = new QPopupMenu(this);
435 mItemPopupMenu->insertItem(i18n("Show..."), this, 435 mItemPopupMenu->insertItem(i18n("Show..."), this,
436 SLOT (showTodo())); 436 SLOT (showTodo()));
437 mItemPopupMenu->insertItem(i18n("Edit..."), this, 437 mItemPopupMenu->insertItem(i18n("Edit..."), this,
438 SLOT (editTodo())); 438 SLOT (editTodo()));
439 mItemPopupMenu->insertItem( i18n("Delete"), this, 439 mItemPopupMenu->insertItem( i18n("Delete"), this,
440 SLOT (deleteTodo())); 440 SLOT (deleteTodo()));
441 mItemPopupMenu->insertItem( i18n("Clone..."), this, 441 mItemPopupMenu->insertItem( i18n("Clone..."), this,
442 SLOT (cloneTodo())); 442 SLOT (cloneTodo()));
443 mItemPopupMenu->insertItem( i18n("Move..."), this, 443 mItemPopupMenu->insertItem( i18n("Move..."), this,
444 SLOT (moveTodo())); 444 SLOT (moveTodo()));
445 mItemPopupMenu->insertItem( i18n("Beam..."), this, 445 mItemPopupMenu->insertItem( i18n("Beam..."), this,
446 SLOT (beamTodo())); 446 SLOT (beamTodo()));
447 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this, 447 mItemPopupMenu->insertItem( i18n("Toggle Cancel"), this,
448 SLOT (cancelTodo())); 448 SLOT (cancelTodo()));
449 mItemPopupMenu->insertSeparator(); 449 mItemPopupMenu->insertSeparator();
450 450
451 mItemPopupMenu->insertItem( i18n("New Todo..."), this, 451 mItemPopupMenu->insertItem( i18n("New Todo..."), this,
452 SLOT (newTodo())); 452 SLOT (newTodo()));
453 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this, 453 mItemPopupMenu->insertItem(i18n("New Sub-Todo..."), this,
454 SLOT (newSubTodo())); 454 SLOT (newSubTodo()));
455 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this, 455 mItemPopupMenu->insertItem(i18n("Unparent Todo"), this,
456 SLOT (unparentTodo()),0,21); 456 SLOT (unparentTodo()),0,21);
457 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this, 457 mItemPopupMenu->insertItem(i18n("Reparent Todo"), this,
458 SLOT (reparentTodo()),0,22); 458 SLOT (reparentTodo()),0,22);
459 mItemPopupMenu->insertSeparator(); 459 mItemPopupMenu->insertSeparator();
460#if 0 460#if 0
461 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"), 461 mItemPopupMenu->insertItem(i18n("Delete completed To-Dos","Purge Completed"),
462 this, SLOT( purgeCompleted() ) ); 462 this, SLOT( purgeCompleted() ) );
463 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"), 463 mItemPopupMenu->insertItem(i18n("toggle completed To-Dos","Show Completed"),
464 this, SLOT( toggleCompleted() ),0, 33 ); 464 this, SLOT( toggleCompleted() ),0, 33 );
465 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 465 mItemPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
466 this, SLOT( toggleQuickTodo() ),0, 34 ); 466 this, SLOT( toggleQuickTodo() ),0, 34 );
467 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 467 mItemPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
468 this, SLOT( toggleRunning() ),0, 35 ); 468 this, SLOT( toggleRunning() ),0, 35 );
469 469
470#endif 470#endif
471 mPopupMenu = new QPopupMenu(this); 471 mPopupMenu = new QPopupMenu(this);
472 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this, 472 mPopupMenu->insertItem(SmallIconSet("todo"), i18n("New Todo..."), this,
473 SLOT (newTodo()),0,1); 473 SLOT (newTodo()),0,1);
474 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"), 474 mPopupMenu->insertItem(i18n("delete completed To-Dos","Purge Completed"),
475 this, SLOT(purgeCompleted()),0,2); 475 this, SLOT(purgeCompleted()),0,2);
476 mPopupMenu->insertItem(i18n("Show Completed"), 476 mPopupMenu->insertItem(i18n("Show Completed"),
477 this, SLOT( toggleCompleted() ),0,3 ); 477 this, SLOT( toggleCompleted() ),0,3 );
478 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"), 478 mPopupMenu->insertItem(i18n("toggle quick todo","Show Quick Todo"),
479 this, SLOT( toggleQuickTodo() ),0,4 ); 479 this, SLOT( toggleQuickTodo() ),0,4 );
480 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"), 480 mPopupMenu->insertItem(i18n("toggle running todo","Hide not Running"),
481 this, SLOT( toggleRunning() ),0,5 ); 481 this, SLOT( toggleRunning() ),0,5 );
482 mPopupMenu->insertItem(i18n(" set all open","Display all opened"), 482 mPopupMenu->insertItem(i18n(" set all open","Display all opened"),
483 this, SLOT( setAllOpen() ),0,6 ); 483 this, SLOT( setAllOpen() ),0,6 );
484 mPopupMenu->insertItem(i18n(" set all close","Display all closed"), 484 mPopupMenu->insertItem(i18n(" set all close","Display all closed"),
485 this, SLOT( setAllClose() ),0,7 ); 485 this, SLOT( setAllClose() ),0,7 );
486 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"), 486 mPopupMenu->insertItem(i18n(" set all flat","Display all flat"),
487 this, SLOT( setAllFlat() ),0,8 ); 487 this, SLOT( setAllFlat() ),0,8 );
488 mDocPrefs = new DocPrefs( name ); 488 mDocPrefs = new DocPrefs( name );
489 489
490 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu ); 490 mItemPopupMenu->insertItem(i18n("Todo View"),mPopupMenu );
491 mPopupMenu->setCheckable( true ); 491 mPopupMenu->setCheckable( true );
492 mItemPopupMenu->setCheckable( true ); 492 mItemPopupMenu->setCheckable( true );
493 493
494 494
495 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 495 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
496 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 496 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
497 497
498 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 498 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
499 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 499 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
500 500
501 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 501 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
502 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 502 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
503 503
504 504
505 // Double clicking conflicts with opening/closing the subtree 505 // Double clicking conflicts with opening/closing the subtree
506 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ), 506 connect( mTodoListView, SIGNAL( doubleClicked( QListViewItem *) ),
507 SLOT( editItem( QListViewItem *) ) ); 507 SLOT( editItem( QListViewItem *) ) );
508 /* 508 /*
509 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *, 509 connect( mTodoListView, SIGNAL( rightButtonClicked ( QListViewItem *,
510 const QPoint &,int ) ), 510 const QPoint &,int ) ),
511 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 511 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
512 */ 512 */
513 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *, 513 connect( mTodoListView, SIGNAL( contextRequest ( QListViewItem *,
514 const QPoint &,int ) ), 514 const QPoint &,int ) ),
515 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) ); 515 SLOT( popupMenu( QListViewItem *, const QPoint & ,int) ) );
516 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ), 516 connect( mTodoListView, SIGNAL( clicked( QListViewItem * ) ),
517 SLOT( itemClicked( QListViewItem * ) ) ); 517 SLOT( itemClicked( QListViewItem * ) ) );
518 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ), 518 connect( mTodoListView, SIGNAL( double_Clicked( QListViewItem * ) ),
519 SLOT( itemDoubleClicked( QListViewItem * ) ) ); 519 SLOT( itemDoubleClicked( QListViewItem * ) ) );
520 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 520 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
521 SLOT( updateView() ) ); 521 SLOT( updateView() ) );
522 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ), 522 connect( mTodoListView, SIGNAL( todoDropped( Todo *, int ) ),
523 SLOT( todoModified(Todo *, int) ) ); 523 SLOT( todoModified(Todo *, int) ) );
524 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ), 524 connect( mTodoListView, SIGNAL( expanded( QListViewItem * ) ),
525 SLOT( itemStateChanged( QListViewItem * ) ) ); 525 SLOT( itemStateChanged( QListViewItem * ) ) );
526 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ), 526 connect( mTodoListView, SIGNAL( collapsed( QListViewItem * ) ),
527 SLOT( itemStateChanged( QListViewItem * ) ) ); 527 SLOT( itemStateChanged( QListViewItem * ) ) );
528 connect( mTodoListView, SIGNAL( paintNeeded() ), 528 connect( mTodoListView, SIGNAL( paintNeeded() ),
529 SLOT( paintNeeded()) ); 529 SLOT( paintNeeded()) );
530 530
531#if 0 531#if 0
532 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)), 532 connect(mTodoListView,SIGNAL(selectionChanged(QListViewItem *)),
533 SLOT(selectionChanged(QListViewItem *))); 533 SLOT(selectionChanged(QListViewItem *)));
534 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)), 534 connect(mTodoListView,SIGNAL(clicked(QListViewItem *)),
535 SLOT(selectionChanged(QListViewItem *))); 535 SLOT(selectionChanged(QListViewItem *)));
536 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)), 536 connect(mTodoListView,SIGNAL(pressed(QListViewItem *)),
537 SLOT(selectionChanged(QListViewItem *))); 537 SLOT(selectionChanged(QListViewItem *)));
538#endif 538#endif
539 539
540 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) )); 540 connect( mTodoListView, SIGNAL(reparentTodoSignal( Todo *,Todo * ) ), SIGNAL(reparentTodoSignal( Todo *,Todo * ) ));
541 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) )); 541 connect( mTodoListView, SIGNAL(unparentTodoSignal(Todo *) ), SIGNAL(unparentTodoSignal(Todo *) ));
542 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) )); 542 connect( mTodoListView, SIGNAL( deleteTodo(Todo *) ), SIGNAL(deleteTodoSignal(Todo *) ));
543 543
544 connect( mTodoListView, SIGNAL(selectionChanged() ), 544 connect( mTodoListView, SIGNAL(selectionChanged() ),
545 SLOT( processSelectionChange() ) ); 545 SLOT( processSelectionChange() ) );
546 connect( mQuickAdd, SIGNAL( returnPressed () ), 546 connect( mQuickAdd, SIGNAL( returnPressed () ),
547 SLOT( addQuickTodo() ) ); 547 SLOT( addQuickTodo() ) );
548 548
549} 549}
550 550
551KOTodoView::~KOTodoView() 551KOTodoView::~KOTodoView()
552{ 552{
553 delete mKOTodoViewWhatsThis;
553 delete mDocPrefs; 554 delete mDocPrefs;
554} 555}
555QString KOTodoView::getWhatsThisText(QPoint p) 556QString KOTodoView::getWhatsThisText(QPoint p)
556{ 557{
557 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p ); 558 KOTodoViewItem* item = ( KOTodoViewItem* ) mTodoListView->itemAt( p );
558 if ( item ) 559 if ( item )
559 return KIncidenceFormatter::instance()->getFormattedText( item->todo(), 560 return KIncidenceFormatter::instance()->getFormattedText( item->todo(),
560 KOPrefs::instance()->mWTshowDetails, 561 KOPrefs::instance()->mWTshowDetails,
561 KOPrefs::instance()->mWTshowCreated, 562 KOPrefs::instance()->mWTshowCreated,
562 KOPrefs::instance()->mWTshowChanged); 563 KOPrefs::instance()->mWTshowChanged);
563 return i18n("That is the todo view" ); 564 return i18n("That is the todo view" );
564 565
565} 566}
566 567
567void KOTodoView::jumpToDate () 568void KOTodoView::jumpToDate ()
568{ 569{
569 // if (mActiveItem) { 570 // if (mActiveItem) {
570// mActiveItem->todo()); 571// mActiveItem->todo());
571// if ( mActiveItem->todo()->hasDueDate() ) 572// if ( mActiveItem->todo()->hasDueDate() )
572// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() ); 573// emit mActiveItem->todo()jumpToTime( mTodo->dtDue().date() );
573} 574}
574void KOTodoView::paintNeeded() 575void KOTodoView::paintNeeded()
575{ 576{
576 if ( mPendingUpdateBeforeRepaint ) { 577 if ( mPendingUpdateBeforeRepaint ) {
577 updateView(); 578 updateView();
578 mPendingUpdateBeforeRepaint = false; 579 mPendingUpdateBeforeRepaint = false;
579 } 580 }
580} 581}
581void KOTodoView::paintEvent(QPaintEvent * pevent) 582void KOTodoView::paintEvent(QPaintEvent * pevent)
582{ 583{
583 if ( mPendingUpdateBeforeRepaint ) { 584 if ( mPendingUpdateBeforeRepaint ) {
584 updateView(); 585 updateView();
585 mPendingUpdateBeforeRepaint = false; 586 mPendingUpdateBeforeRepaint = false;
586 } 587 }
587 KOrg::BaseView::paintEvent( pevent); 588 KOrg::BaseView::paintEvent( pevent);
588} 589}
589 590
590void KOTodoView::updateView() 591void KOTodoView::updateView()
591{ 592{
592 pendingSubtodo = 0; 593 pendingSubtodo = 0;
593 if ( mBlockUpdate ) { 594 if ( mBlockUpdate ) {
594 return; 595 return;
595 } 596 }
596 if ( !isVisible() ) { 597 if ( !isVisible() ) {
597 mPendingUpdateBeforeRepaint = true; 598 mPendingUpdateBeforeRepaint = true;
598 return; 599 return;
599 } 600 }
600 //qDebug("KOTodoView::updateView() %x", this); 601 //qDebug("KOTodoView::updateView() %x", this);
601 if ( isFlatDisplay ) { 602 if ( isFlatDisplay ) {
602 displayAllFlat(); 603 displayAllFlat();
603 return; 604 return;
604 } 605 }
605 //qDebug("update "); 606 //qDebug("update ");
606// kdDebug() << "KOTodoView::updateView()" << endl; 607// kdDebug() << "KOTodoView::updateView()" << endl;
607 QFont fo = KOPrefs::instance()->mTodoViewFont; 608 QFont fo = KOPrefs::instance()->mTodoViewFont;
608 Incidence* oldInc = 0; 609 Incidence* oldInc = 0;
609 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 610 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
610 if (mActiveItem) 611 if (mActiveItem)
611 oldInc = mActiveItem->todo(); 612 oldInc = mActiveItem->todo();
612 613
613 mTodoListView->clear(); 614 mTodoListView->clear();
614 if ( mName == "todolistsmall" ) { 615 if ( mName == "todolistsmall" ) {
615 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) { 616 if ( KOPrefs::instance()->mTodoViewUsesSmallFont ) {
616 int ps = fo.pointSize() -2; 617 int ps = fo.pointSize() -2;
617 if ( ps > 12 ) 618 if ( ps > 12 )
618 ps -= 2; 619 ps -= 2;
619 fo.setPointSize( ps ); 620 fo.setPointSize( ps );
620 } 621 }
621 } 622 }
622 623
623 mTodoListView->setFont( fo ); 624 mTodoListView->setFont( fo );
624 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont ); 625 // QFontMetrics fm ( KOPrefs::instance()->mTodoViewFont );
625 //mTodoListView->header()->setMaximumHeight(fm.height()); 626 //mTodoListView->header()->setMaximumHeight(fm.height());
626 QPtrList<Todo> todoList = calendar()->todos(); 627 QPtrList<Todo> todoList = calendar()->todos();
627 628
628/* 629/*
629 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl; 630 kdDebug() << "KOTodoView::updateView(): Todo List:" << endl;
630 Event *t; 631 Event *t;
631 for(t = todoList.first(); t; t = todoList.next()) { 632 for(t = todoList.first(); t; t = todoList.next()) {
632 kdDebug() << " " << t->getSummary() << endl; 633 kdDebug() << " " << t->getSummary() << endl;
633 634
634 if (t->getRelatedTo()) { 635 if (t->getRelatedTo()) {
635 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl; 636 kdDebug() << " (related to " << t->getRelatedTo()->getSummary() << ")" << endl;
636 } 637 }
637 638
638 QPtrList<Event> l = t->getRelations(); 639 QPtrList<Event> l = t->getRelations();
639 Event *c; 640 Event *c;
640 for(c=l.first();c;c=l.next()) { 641 for(c=l.first();c;c=l.next()) {
641 kdDebug() << " - relation: " << c->getSummary() << endl; 642 kdDebug() << " - relation: " << c->getSummary() << endl;
642 } 643 }
643 } 644 }
644*/ 645*/
645 646
646 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a 647 // Put for each Event a KOTodoViewItem in the list view. Don't rely on a
647 // specific order of events. That means that we have to generate parent items 648 // specific order of events. That means that we have to generate parent items
648 // recursively for proper hierarchical display of Todos. 649 // recursively for proper hierarchical display of Todos.
649 mTodoMap.clear(); 650 mTodoMap.clear();
650 Todo *todo; 651 Todo *todo;
651 todo = todoList.first();// todo; todo = todoList.next()) { 652 todo = todoList.first();// todo; todo = todoList.next()) {
652 while ( todo ) { 653 while ( todo ) {
653 bool next = true; 654 bool next = true;
654 // qDebug("todo %s ", todo->summary().latin1()); 655 // qDebug("todo %s ", todo->summary().latin1());
655 Incidence *incidence = todo->relatedTo(); 656 Incidence *incidence = todo->relatedTo();
656 while ( incidence ) { 657 while ( incidence ) {
657 if ( incidence->type() == "Todo") { 658 if ( incidence->type() == "Todo") {
658 //qDebug("related %s ",incidence->summary().latin1() ); 659 //qDebug("related %s ",incidence->summary().latin1() );
659 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) { 660 if ( !(todoList.contains ( ((Todo* )incidence ) ) )) {
660 //qDebug("related not found "); 661 //qDebug("related not found ");
661 todoList.remove( ); 662 todoList.remove( );
662 todo = todoList.current(); 663 todo = todoList.current();
663 next = false; 664 next = false;
664 incidence = 0; 665 incidence = 0;
665 666
666 } else { 667 } else {
667 //qDebug("related found "); 668 //qDebug("related found ");
668 incidence = incidence->relatedTo(); 669 incidence = incidence->relatedTo();
669 } 670 }
670 } else 671 } else
671 incidence = 0; 672 incidence = 0;
672 } 673 }
673 if ( next ) 674 if ( next )
674 todo = todoList.next(); 675 todo = todoList.next();
675 } 676 }
676// qDebug("again .... "); 677// qDebug("again .... ");
677// for(todo = todoList.first(); todo; todo = todoList.next()) { 678// for(todo = todoList.first(); todo; todo = todoList.next()) {
678 679
679// qDebug("yytodo %s ", todo->summary().latin1()); 680// qDebug("yytodo %s ", todo->summary().latin1());
680// } 681// }
681 //qDebug("for "); 682 //qDebug("for ");
682 for(todo = todoList.first(); todo; todo = todoList.next()) { 683 for(todo = todoList.first(); todo; todo = todoList.next()) {
683 if (!mTodoMap.contains(todo) && checkTodo( todo ) ) 684 if (!mTodoMap.contains(todo) && checkTodo( todo ) )
684 { 685 {
685 insertTodoItem(todo); 686 insertTodoItem(todo);
686 } 687 }
687 } 688 }
688 //qDebug("for end "); 689 //qDebug("for end ");
689 // Restore opened/closed state 690 // Restore opened/closed state
690 mTodoListView->blockSignals( true ); 691 mTodoListView->blockSignals( true );
691 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() ); 692 if( mDocPrefs ) restoreItemState( mTodoListView->firstChild() );
692 mTodoListView->blockSignals( false ); 693 mTodoListView->blockSignals( false );
693 mTodoListView->setFocus(); 694 mTodoListView->setFocus();
694 if ( mTodoListView->firstChild () ) { 695 if ( mTodoListView->firstChild () ) {
695 if ( oldInc ) { 696 if ( oldInc ) {
696 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild (); 697 KOTodoViewItem* item = (KOTodoViewItem*)mTodoListView->firstChild ();
697 while ( item ) { 698 while ( item ) {
698 if ( item->todo() == oldInc ) { 699 if ( item->todo() == oldInc ) {
699 mTodoListView->setCurrentItem( item ); 700 mTodoListView->setCurrentItem( item );
700 mTodoListView->ensureItemVisible( item ); 701 mTodoListView->ensureItemVisible( item );
701 break; 702 break;
702 } 703 }
703 item = (KOTodoViewItem*)item->itemBelow(); 704 item = (KOTodoViewItem*)item->itemBelow();
704 } 705 }
705 if ( ! item ) 706 if ( ! item )
706 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 707 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
707 } else { 708 } else {
708 mTodoListView->setCurrentItem( mTodoListView->firstChild () ); 709 mTodoListView->setCurrentItem( mTodoListView->firstChild () );
709 } 710 }
710 } 711 }
711 processSelectionChange(); 712 processSelectionChange();
712} 713}
713 714
714bool KOTodoView::checkTodo( Todo * todo ) 715bool KOTodoView::checkTodo( Todo * todo )
715{ 716{
716 717
717 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() ) 718 if ( !KOPrefs::instance()->mShowCompletedTodo && todo->isCompleted() )
718 return false; 719 return false;
719 if ( !todo->isCompleted() ) { 720 if ( !todo->isCompleted() ) {
720 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() ) 721 if ( todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
721 return true; 722 return true;
722 } 723 }
723 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) { 724 if ( KOPrefs::instance()->mHideNonStartedTodos && mNavigator ) {
724 if ( todo->hasStartDate() ) 725 if ( todo->hasStartDate() )
725 if ( mNavigator->selectedDates().last() < todo->dtStart().date() ) 726 if ( mNavigator->selectedDates().last() < todo->dtStart().date() )
726 return false; 727 return false;
727 if ( todo->hasDueDate() ) 728 if ( todo->hasDueDate() )
728 if ( mNavigator->selectedDates().first() > todo->dtDue().date() ) 729 if ( mNavigator->selectedDates().first() > todo->dtDue().date() )
729 return false; 730 return false;
730 } 731 }
731 return true; 732 return true;
732} 733}
733 734
734void KOTodoView::restoreItemState( QListViewItem *item ) 735void KOTodoView::restoreItemState( QListViewItem *item )
735{ 736{
736 pendingSubtodo = 0; 737 pendingSubtodo = 0;
737 while( item ) { 738 while( item ) {
738 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 739 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
739 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) ); 740 todoItem->setOpen( mDocPrefs->readBoolEntry( todoItem->todo()->uid() ) );
740 if( item->childCount() > 0 ) restoreItemState( item->firstChild() ); 741 if( item->childCount() > 0 ) restoreItemState( item->firstChild() );
741 item = item->nextSibling(); 742 item = item->nextSibling();
742 } 743 }
743} 744}
744 745
745 746
746QMap<Todo *,KOTodoViewItem *>::ConstIterator 747QMap<Todo *,KOTodoViewItem *>::ConstIterator
747 KOTodoView::insertTodoItem(Todo *todo) 748 KOTodoView::insertTodoItem(Todo *todo)
748{ 749{
749 750
750// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl; 751// kdDebug() << "KOTodoView::insertTodoItem(): " << todo->getSummary() << endl;
751 // TODO: Check, if dynmaic cast is necessary 752 // TODO: Check, if dynmaic cast is necessary
752 753
753 pendingSubtodo = 0; 754 pendingSubtodo = 0;
754 Incidence *incidence = todo->relatedTo(); 755 Incidence *incidence = todo->relatedTo();
755 if (incidence && incidence->type() == "Todo") { 756 if (incidence && incidence->type() == "Todo") {
756 Todo *relatedTodo = static_cast<Todo *>(incidence); 757 Todo *relatedTodo = static_cast<Todo *>(incidence);
757 758
758// kdDebug() << " has Related" << endl; 759// kdDebug() << " has Related" << endl;
759 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 760 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
760 itemIterator = mTodoMap.find(relatedTodo); 761 itemIterator = mTodoMap.find(relatedTodo);
761 if (itemIterator == mTodoMap.end()) { 762 if (itemIterator == mTodoMap.end()) {
762// kdDebug() << " related not yet in list" << endl; 763// kdDebug() << " related not yet in list" << endl;
763 itemIterator = insertTodoItem (relatedTodo); 764 itemIterator = insertTodoItem (relatedTodo);
764 } 765 }
765 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem 766 // isn't this pretty stupid? We give one Todo to the KOTodoViewItem
766 // and one into the map. Sure finding is more easy but why? -zecke 767 // and one into the map. Sure finding is more easy but why? -zecke
767 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this); 768 KOTodoViewItem *todoItem = new KOTodoViewItem(*itemIterator,todo,this);
768 return mTodoMap.insert(todo,todoItem); 769 return mTodoMap.insert(todo,todoItem);
769 } else { 770 } else {
770// kdDebug() << " no Related" << endl; 771// kdDebug() << " no Related" << endl;
771 // see above -zecke 772 // see above -zecke
772 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 773 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
773 return mTodoMap.insert(todo,todoItem); 774 return mTodoMap.insert(todo,todoItem);
774 } 775 }
775} 776}
776 777
777 778
778void KOTodoView::updateConfig() 779void KOTodoView::updateConfig()
779{ 780{
780 updateView(); 781 updateView();
781 mTodoListView->repaintContents(); 782 mTodoListView->repaintContents();
782} 783}
783 784
784QPtrList<Incidence> KOTodoView::selectedIncidences() 785QPtrList<Incidence> KOTodoView::selectedIncidences()
785{ 786{
786 QPtrList<Incidence> selected; 787 QPtrList<Incidence> selected;
787 788
788 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 789 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
789// if (!item) item = mActiveItem; 790// if (!item) item = mActiveItem;
790 if (item) selected.append(item->todo()); 791 if (item) selected.append(item->todo());
791 792
792 return selected; 793 return selected;
793} 794}
794 795
795QPtrList<Todo> KOTodoView::selectedTodos() 796QPtrList<Todo> KOTodoView::selectedTodos()
796{ 797{
797 QPtrList<Todo> selected; 798 QPtrList<Todo> selected;
798 799
799 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem()); 800 KOTodoViewItem *item = (KOTodoViewItem *)(mTodoListView->selectedItem());
800// if (!item) item = mActiveItem; 801// if (!item) item = mActiveItem;
801 if (item) selected.append(item->todo()); 802 if (item) selected.append(item->todo());
802 803
803 return selected; 804 return selected;
804} 805}
805 806
806void KOTodoView::changeEventDisplay(Event *, int) 807void KOTodoView::changeEventDisplay(Event *, int)
807{ 808{
808 updateView(); 809 updateView();
809} 810}
810 811
811void KOTodoView::showDates(const QDate &, const QDate &) 812void KOTodoView::showDates(const QDate &, const QDate &)
812{ 813{
813} 814}
814 815
815void KOTodoView::showEvents(QPtrList<Event>) 816void KOTodoView::showEvents(QPtrList<Event>)
816{ 817{
817 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl; 818 kdDebug() << "KOTodoView::selectEvents(): not yet implemented" << endl;
818} 819}
819 820
820void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd, 821void KOTodoView::printPreview(CalPrinter *calPrinter, const QDate &fd,
821 const QDate &td) 822 const QDate &td)
822{ 823{
823#ifndef KORG_NOPRINTER 824#ifndef KORG_NOPRINTER
824 calPrinter->preview(CalPrinter::Todolist, fd, td); 825 calPrinter->preview(CalPrinter::Todolist, fd, td);
825#endif 826#endif
826} 827}
827 828
828void KOTodoView::editItem(QListViewItem *item ) 829void KOTodoView::editItem(QListViewItem *item )
829{ 830{
830 // qDebug("editItem(QListViewItem *item ) "); 831 // qDebug("editItem(QListViewItem *item ) ");
831 emit editTodoSignal(((KOTodoViewItem *)item)->todo()); 832 emit editTodoSignal(((KOTodoViewItem *)item)->todo());
832} 833}
833 834
834void KOTodoView::showItem(QListViewItem *item,const QPoint &,int) 835void KOTodoView::showItem(QListViewItem *item,const QPoint &,int)
835{ 836{
836 emit showTodoSignal(((KOTodoViewItem *)item)->todo()); 837 emit showTodoSignal(((KOTodoViewItem *)item)->todo());
837} 838}
838 839
839void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column) 840void KOTodoView::popupMenu(QListViewItem *item,const QPoint &p,int column)
840{ 841{
841 pendingSubtodo = 0; 842 pendingSubtodo = 0;
842 mActiveItem = (KOTodoViewItem *)item; 843 mActiveItem = (KOTodoViewItem *)item;
843 if (item) { 844 if (item) {
844 switch (column){ 845 switch (column){
845 case 1: 846 case 1:
846 mPriorityPopupMenu->popup(QCursor::pos ()); break; 847 mPriorityPopupMenu->popup(QCursor::pos ()); break;
847 case 2: 848 case 2:
848 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break; 849 mPercentageCompletedPopupMenu->popup(QCursor::pos ()); break;
849 case 3: 850 case 3:
850 moveTodo(); 851 moveTodo();
851 break; 852 break;
852 case 8: 853 case 8:
853 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break; 854 getCategoryPopupMenu((KOTodoViewItem *)item)->popup(QCursor::pos ()); break;
854 default: 855 default:
855 mItemPopupMenu->popup(QCursor::pos()); 856 mItemPopupMenu->popup(QCursor::pos());
856 } 857 }
857 } else mPopupMenu->popup(QCursor::pos()); 858 } else mPopupMenu->popup(QCursor::pos());
858} 859}
859void KOTodoView::newTodo() 860void KOTodoView::newTodo()
860{ 861{
861 emit newTodoSignal(); 862 emit newTodoSignal();
862} 863}
863 864
864void KOTodoView::newSubTodo() 865void KOTodoView::newSubTodo()
865{ 866{
866 if (mActiveItem) { 867 if (mActiveItem) {
867 emit newSubTodoSignal(mActiveItem->todo()); 868 emit newSubTodoSignal(mActiveItem->todo());
868 } 869 }
869} 870}
870void KOTodoView::unparentTodo() 871void KOTodoView::unparentTodo()
871{ 872{
872 if (mActiveItem) { 873 if (mActiveItem) {
873 emit unparentTodoSignal(mActiveItem->todo()); 874 emit unparentTodoSignal(mActiveItem->todo());
874 } 875 }
875} 876}
876 877
877void KOTodoView::reparentTodo() 878void KOTodoView::reparentTodo()
878{ 879{
879 if (mActiveItem) { 880 if (mActiveItem) {
880 qDebug("KOTodoView::reparentTodo() "); 881 qDebug("KOTodoView::reparentTodo() ");
881 topLevelWidget()->setCaption(i18n("Click on new parent item")); 882 topLevelWidget()->setCaption(i18n("Click on new parent item"));
882 pendingSubtodo = mActiveItem; 883 pendingSubtodo = mActiveItem;
883 } 884 }
884} 885}
885void KOTodoView::editTodo() 886void KOTodoView::editTodo()
886{ 887{
887 if (mActiveItem) { 888 if (mActiveItem) {
888 emit editTodoSignal(mActiveItem->todo()); 889 emit editTodoSignal(mActiveItem->todo());
889 } 890 }
890} 891}
891void KOTodoView::cloneTodo() 892void KOTodoView::cloneTodo()
892{ 893{
893 if (mActiveItem) { 894 if (mActiveItem) {
894 emit cloneTodoSignal((Incidence*)mActiveItem->todo()); 895 emit cloneTodoSignal((Incidence*)mActiveItem->todo());
895 } 896 }
896} 897}
897void KOTodoView::cancelTodo() 898void KOTodoView::cancelTodo()
898{ 899{
899 if (mActiveItem) { 900 if (mActiveItem) {
900 emit cancelTodoSignal((Incidence*)mActiveItem->todo()); 901 emit cancelTodoSignal((Incidence*)mActiveItem->todo());
901 } 902 }
902} 903}
903void KOTodoView::moveTodo() 904void KOTodoView::moveTodo()
904{ 905{
905 if (mActiveItem) { 906 if (mActiveItem) {
906 emit moveTodoSignal((Incidence*)mActiveItem->todo()); 907 emit moveTodoSignal((Incidence*)mActiveItem->todo());
907 } 908 }
908} 909}
909void KOTodoView::beamTodo() 910void KOTodoView::beamTodo()
910{ 911{
911 if (mActiveItem) { 912 if (mActiveItem) {
912 emit beamTodoSignal((Incidence*)mActiveItem->todo()); 913 emit beamTodoSignal((Incidence*)mActiveItem->todo());
913 } 914 }
914} 915}
915 916
916 917
917void KOTodoView::showTodo() 918void KOTodoView::showTodo()
918{ 919{
919 if (mActiveItem) { 920 if (mActiveItem) {
920 emit showTodoSignal(mActiveItem->todo()); 921 emit showTodoSignal(mActiveItem->todo());
921 } 922 }
922} 923}
923 924
924void KOTodoView::deleteTodo() 925void KOTodoView::deleteTodo()
925{ 926{
926 if (mActiveItem) { 927 if (mActiveItem) {
927 emit deleteTodoSignal(mActiveItem->todo()); 928 emit deleteTodoSignal(mActiveItem->todo());
928 } 929 }
929} 930}
930 931
931void KOTodoView::setNewPriority(int index) 932void KOTodoView::setNewPriority(int index)
932{ 933{
933 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 934 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
934 mActiveItem->todo()->setPriority(mPriority[index]); 935 mActiveItem->todo()->setPriority(mPriority[index]);
935 mActiveItem->construct(); 936 mActiveItem->construct();
936 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED); 937 todoModified (mActiveItem->todo(), KOGlobals::PRIORITY_MODIFIED);
937 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 938 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
938 } 939 }
939} 940}
940 941
941void KOTodoView::setNewPercentage(int index) 942void KOTodoView::setNewPercentage(int index)
942{ 943{
943 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 944 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
944 945
945 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) { 946 if ( mPercentage[index] == 100 && !mActiveItem->isOn() ) {
946 mActiveItem->setOn( true ); 947 mActiveItem->setOn( true );
947 return; 948 return;
948 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) { 949 } else if ( mPercentage[index] != 100 && mActiveItem->isOn() ) {
949 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent())); 950 KOTodoViewItem* par = (static_cast<KOTodoViewItem*>(mActiveItem->parent()));
950 if ( par && par->isOn() ) 951 if ( par && par->isOn() )
951 par->setOn( false ); 952 par->setOn( false );
952 } 953 }
953 if (mPercentage[index] == 100) { 954 if (mPercentage[index] == 100) {
954 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime()); 955 mActiveItem->todo()->setCompleted(QDateTime::currentDateTime());
955 } else { 956 } else {
956 mActiveItem->todo()->setCompleted(false); 957 mActiveItem->todo()->setCompleted(false);
957 } 958 }
958 mActiveItem->todo()->setPercentComplete(mPercentage[index]); 959 mActiveItem->todo()->setPercentComplete(mPercentage[index]);
959 mActiveItem->construct(); 960 mActiveItem->construct();
960 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED); 961 todoModified (mActiveItem->todo (), KOGlobals::COMPLETION_MODIFIED);
961 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 962 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
962 } 963 }
963} 964}
964 965
965 966
966QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem) 967QPopupMenu * KOTodoView::getCategoryPopupMenu (KOTodoViewItem *todoItem)
967{ 968{
968 QPopupMenu* tempMenu = new QPopupMenu (this); 969 QPopupMenu* tempMenu = new QPopupMenu (this);
969 QStringList checkedCategories = todoItem->todo()->categories (); 970 QStringList checkedCategories = todoItem->todo()->categories ();
970 971
971 tempMenu->setCheckable (true); 972 tempMenu->setCheckable (true);
972 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin (); 973 for (QStringList::Iterator it = KOPrefs::instance()->mCustomCategories.begin ();
973 it != KOPrefs::instance()->mCustomCategories.end (); 974 it != KOPrefs::instance()->mCustomCategories.end ();
974 ++it) { 975 ++it) {
975 int index = tempMenu->insertItem (*it); 976 int index = tempMenu->insertItem (*it);
976 mCategory[index] = *it; 977 mCategory[index] = *it;
977 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true); 978 if (checkedCategories.find (*it) != checkedCategories.end ()) tempMenu->setItemChecked (index, true);
978 } 979 }
979 980
980 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int))); 981 connect (tempMenu, SIGNAL (activated (int)), SLOT (changedCategories (int)));
981 return tempMenu; 982 return tempMenu;
982 983
983 984
984} 985}
985void KOTodoView::changedCategories(int index) 986void KOTodoView::changedCategories(int index)
986{ 987{
987 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) { 988 if (mActiveItem && !mActiveItem->todo()->isReadOnly ()) {
988 QStringList categories = mActiveItem->todo()->categories (); 989 QStringList categories = mActiveItem->todo()->categories ();
989 QString colcat = categories.first(); 990 QString colcat = categories.first();
990 if (categories.find (mCategory[index]) != categories.end ()) 991 if (categories.find (mCategory[index]) != categories.end ())
991 categories.remove (mCategory[index]); 992 categories.remove (mCategory[index]);
992 else 993 else
993 categories.insert (categories.end(), mCategory[index]); 994 categories.insert (categories.end(), mCategory[index]);
994 categories.sort (); 995 categories.sort ();
995 if ( !colcat.isEmpty() ) { 996 if ( !colcat.isEmpty() ) {
996 if ( categories.find ( colcat ) != categories.end () ) { 997 if ( categories.find ( colcat ) != categories.end () ) {
997 categories.remove( colcat ); 998 categories.remove( colcat );
998 categories.prepend( colcat ); 999 categories.prepend( colcat );
999 } 1000 }
1000 } 1001 }
1001 mActiveItem->todo()->setCategories (categories); 1002 mActiveItem->todo()->setCategories (categories);
1002 mActiveItem->construct(); 1003 mActiveItem->construct();
1003 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 ); 1004 mActiveItem->todo()->setRevision( mActiveItem->todo()->revision()+1 );
1004 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED); 1005 todoModified (mActiveItem->todo (), KOGlobals::CATEGORY_MODIFIED);
1005 } 1006 }
1006} 1007}
1007void KOTodoView::itemDoubleClicked(QListViewItem *item) 1008void KOTodoView::itemDoubleClicked(QListViewItem *item)
1008{ 1009{
1009 if ( pendingSubtodo != 0 ) { 1010 if ( pendingSubtodo != 0 ) {
1010 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1011 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1011 } 1012 }
1012 pendingSubtodo = 0; 1013 pendingSubtodo = 0;
1013 if (!item) { 1014 if (!item) {
1014 newTodo(); 1015 newTodo();
1015 return; 1016 return;
1016 } 1017 }
1017 if ( KOPrefs::instance()->mEditOnDoubleClick ) 1018 if ( KOPrefs::instance()->mEditOnDoubleClick )
1018 editItem( item ); 1019 editItem( item );
1019 else 1020 else
1020 showItem( item , QPoint(), 0 ); 1021 showItem( item , QPoint(), 0 );
1021} 1022}
1022void KOTodoView::itemClicked(QListViewItem *item) 1023void KOTodoView::itemClicked(QListViewItem *item)
1023{ 1024{
1024 1025
1025 if (!item) { 1026 if (!item) {
1026 if ( pendingSubtodo != 0 ) { 1027 if ( pendingSubtodo != 0 ) {
1027 topLevelWidget()->setCaption(i18n("Reparenting aborted!")); 1028 topLevelWidget()->setCaption(i18n("Reparenting aborted!"));
1028 } 1029 }
1029 pendingSubtodo = 0; 1030 pendingSubtodo = 0;
1030 return; 1031 return;
1031 } 1032 }
1032 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1033 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1033 if ( pendingSubtodo != 0 ) { 1034 if ( pendingSubtodo != 0 ) {
1034 bool allowReparent = true; 1035 bool allowReparent = true;
1035 QListViewItem *par = item; 1036 QListViewItem *par = item;
1036 while ( par ) { 1037 while ( par ) {
1037 if ( par == pendingSubtodo ) { 1038 if ( par == pendingSubtodo ) {
1038 allowReparent = false; 1039 allowReparent = false;
1039 break; 1040 break;
1040 } 1041 }
1041 par = par->parent(); 1042 par = par->parent();
1042 } 1043 }
1043 if ( !allowReparent ) { 1044 if ( !allowReparent ) {
1044 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!")); 1045 topLevelWidget()->setCaption(i18n("Recursive reparenting not possible!"));
1045 qDebug("Recursive reparenting not possible "); 1046 qDebug("Recursive reparenting not possible ");
1046 pendingSubtodo = 0; 1047 pendingSubtodo = 0;
1047 } else { 1048 } else {
1048 Todo* newParent = todoItem->todo(); 1049 Todo* newParent = todoItem->todo();
1049 Todo* newSub = pendingSubtodo->todo(); 1050 Todo* newSub = pendingSubtodo->todo();
1050 pendingSubtodo = 0; 1051 pendingSubtodo = 0;
1051 emit reparentTodoSignal( newParent,newSub ); 1052 emit reparentTodoSignal( newParent,newSub );
1052 return; 1053 return;
1053 } 1054 }
1054 } 1055 }
1055#if 0 1056#if 0
1056 // handled by the item itself 1057 // handled by the item itself
1057 bool completed = todoItem->todo()->isCompleted(); // Completed or not? 1058 bool completed = todoItem->todo()->isCompleted(); // Completed or not?
1058 qDebug("com %d ",completed ); 1059 qDebug("com %d ",completed );
1059 qDebug("itemclicked "); 1060 qDebug("itemclicked ");
1060 if (todoItem->isOn()) { 1061 if (todoItem->isOn()) {
1061 qDebug("on "); 1062 qDebug("on ");
1062 if (!completed) { 1063 if (!completed) {
1063 qDebug("set true "); 1064 qDebug("set true ");
1064 todoItem->todo()->setCompleted(QDateTime::currentDateTime()); 1065 todoItem->todo()->setCompleted(QDateTime::currentDateTime());
1065 } 1066 }
1066 } else { 1067 } else {
1067 qDebug("not on "); 1068 qDebug("not on ");
1068 if (completed) { 1069 if (completed) {
1069 qDebug("set false "); 1070 qDebug("set false ");
1070 todoItem->todo()->setCompleted(false); 1071 todoItem->todo()->setCompleted(false);
1071 } 1072 }
1072 } 1073 }
1073#endif 1074#endif
1074} 1075}
1075 1076
1076void KOTodoView::setDocumentId( const QString &id ) 1077void KOTodoView::setDocumentId( const QString &id )
1077{ 1078{
1078 kdDebug() << "KOTodoView::setDocumentId()" << endl; 1079 kdDebug() << "KOTodoView::setDocumentId()" << endl;
1079 1080
1080 mDocPrefs->setDoc( id ); 1081 mDocPrefs->setDoc( id );
1081} 1082}
1082 1083
1083void KOTodoView::itemStateChanged( QListViewItem *item ) 1084void KOTodoView::itemStateChanged( QListViewItem *item )
1084{ 1085{
1085 if (!item) return; 1086 if (!item) return;
1086 1087
1087 KOTodoViewItem *todoItem = (KOTodoViewItem *)item; 1088 KOTodoViewItem *todoItem = (KOTodoViewItem *)item;
1088 1089
1089// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl; 1090// kdDebug() << "KOTodoView::itemStateChanged(): " << todoItem->todo()->summary() << endl;
1090 1091
1091 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() ); 1092 if( mDocPrefs ) mDocPrefs->writeEntry( todoItem->todo()->uid(), todoItem->isOpen() );
1092} 1093}
1093 1094
1094void KOTodoView::saveLayout(KConfig *config, const QString &group) const 1095void KOTodoView::saveLayout(KConfig *config, const QString &group) const
1095{ 1096{
1096 mTodoListView->saveLayout(config,group); 1097 mTodoListView->saveLayout(config,group);
1097} 1098}
1098 1099
1099void KOTodoView::restoreLayout(KConfig *config, const QString &group) 1100void KOTodoView::restoreLayout(KConfig *config, const QString &group)
1100{ 1101{
1101 mTodoListView->restoreLayout(config,group); 1102 mTodoListView->restoreLayout(config,group);
1102} 1103}
1103 1104
1104void KOTodoView::processSelectionChange() 1105void KOTodoView::processSelectionChange()
1105{ 1106{
1106// kdDebug() << "KOTodoView::processSelectionChange()" << endl; 1107// kdDebug() << "KOTodoView::processSelectionChange()" << endl;
1107 1108
1108 KOTodoViewItem *item = 1109 KOTodoViewItem *item =
1109 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() ); 1110 static_cast<KOTodoViewItem *>( mTodoListView->selectedItem() );
1110 1111
1111 if ( !item ) { 1112 if ( !item ) {
1112 emit incidenceSelected( 0 ); 1113 emit incidenceSelected( 0 );
1113 } else { 1114 } else {
1114 emit incidenceSelected( item->todo() ); 1115 emit incidenceSelected( item->todo() );
1115 } 1116 }
1116} 1117}
1117 1118
1118void KOTodoView::modified(bool b) 1119void KOTodoView::modified(bool b)
1119{ 1120{
1120 emit isModified(b); 1121 emit isModified(b);
1121} 1122}
1122void KOTodoView::setTodoModified( Todo* todo ) 1123void KOTodoView::setTodoModified( Todo* todo )
1123{ 1124{
1124 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED ); 1125 todoModified( todo, KOGlobals::UNKNOWN_MODIFIED );
1125} 1126}
1126void KOTodoView::clearSelection() 1127void KOTodoView::clearSelection()
1127{ 1128{
1128 mTodoListView->selectAll( false ); 1129 mTodoListView->selectAll( false );
1129} 1130}
1130void KOTodoView::setAllOpen() 1131void KOTodoView::setAllOpen()
1131{ 1132{
1132 if ( isFlatDisplay ) { 1133 if ( isFlatDisplay ) {
1133 isFlatDisplay = false; 1134 isFlatDisplay = false;
1134 mPopupMenu->setItemChecked( 8,false ); 1135 mPopupMenu->setItemChecked( 8,false );
1135 updateView(); 1136 updateView();
1136 } 1137 }
1137 setOpen(mTodoListView->firstChild(), true); 1138 setOpen(mTodoListView->firstChild(), true);
1138} 1139}
1139void KOTodoView::setAllClose() 1140void KOTodoView::setAllClose()
1140{ 1141{
1141 if ( isFlatDisplay ) { 1142 if ( isFlatDisplay ) {
1142 isFlatDisplay = false; 1143 isFlatDisplay = false;
1143 mPopupMenu->setItemChecked( 8,false ); 1144 mPopupMenu->setItemChecked( 8,false );
1144 updateView(); 1145 updateView();
1145 } 1146 }
1146 setOpen(mTodoListView->firstChild(), false); 1147 setOpen(mTodoListView->firstChild(), false);
1147} 1148}
1148void KOTodoView::setOpen( QListViewItem* item, bool setOpenI) 1149void KOTodoView::setOpen( QListViewItem* item, bool setOpenI)
1149{ 1150{
1150 1151
1151 while ( item ) { 1152 while ( item ) {
1152 setOpen( item->firstChild(), setOpenI ); 1153 setOpen( item->firstChild(), setOpenI );
1153 item->setOpen( setOpenI ); 1154 item->setOpen( setOpenI );
1154 item = item->nextSibling(); 1155 item = item->nextSibling();
1155 } 1156 }
1156} 1157}
1157 1158
1158void KOTodoView::displayAllFlat() 1159void KOTodoView::displayAllFlat()
1159{ 1160{
1160 pendingSubtodo = 0; 1161 pendingSubtodo = 0;
1161 if ( mBlockUpdate ) { 1162 if ( mBlockUpdate ) {
1162 return; 1163 return;
1163 } 1164 }
1164 mPopupMenu->setItemChecked( 8,true ); 1165 mPopupMenu->setItemChecked( 8,true );
1165 isFlatDisplay = true; 1166 isFlatDisplay = true;
1166 QPtrList<Todo> todoList = calendar()->todos(); 1167 QPtrList<Todo> todoList = calendar()->todos();
1167 mTodoMap.clear(); 1168 mTodoMap.clear();
1168 mTodoListView->clear(); 1169 mTodoListView->clear();
1169 Todo *todo; 1170 Todo *todo;
1170 for(todo = todoList.first(); todo; todo = todoList.next()) { 1171 for(todo = todoList.first(); todo; todo = todoList.next()) {
1171 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this); 1172 KOTodoViewItem *todoItem = new KOTodoViewItem(mTodoListView,todo,this);
1172 mTodoMap.insert(todo,todoItem); 1173 mTodoMap.insert(todo,todoItem);
1173 } 1174 }
1174 mTodoListView->setFocus(); 1175 mTodoListView->setFocus();
1175 processSelectionChange(); 1176 processSelectionChange();
1176} 1177}
1177 1178
1178void KOTodoView::setAllFlat() 1179void KOTodoView::setAllFlat()
1179{ 1180{
1180 if ( isFlatDisplay ) { 1181 if ( isFlatDisplay ) {
1181 isFlatDisplay = false; 1182 isFlatDisplay = false;
1182 mPopupMenu->setItemChecked( 8,false ); 1183 mPopupMenu->setItemChecked( 8,false );
1183 updateView(); 1184 updateView();
1184 return; 1185 return;
1185 } 1186 }
1186 displayAllFlat(); 1187 displayAllFlat();
1187} 1188}
1188 1189
1189void KOTodoView::purgeCompleted() 1190void KOTodoView::purgeCompleted()
1190{ 1191{
1191 emit purgeCompletedSignal(); 1192 emit purgeCompletedSignal();
1192} 1193}
1193void KOTodoView::toggleQuickTodo() 1194void KOTodoView::toggleQuickTodo()
1194{ 1195{
1195 if ( mQuickAdd->isVisible() ) { 1196 if ( mQuickAdd->isVisible() ) {
1196 mQuickAdd->hide(); 1197 mQuickAdd->hide();
1197 KOPrefs::instance()->mEnableQuickTodo = false; 1198 KOPrefs::instance()->mEnableQuickTodo = false;
1198 } 1199 }
1199 else { 1200 else {
1200 mQuickAdd->show(); 1201 mQuickAdd->show();
1201 KOPrefs::instance()->mEnableQuickTodo = true; 1202 KOPrefs::instance()->mEnableQuickTodo = true;
1202 } 1203 }
1203 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo); 1204 mPopupMenu->setItemChecked(4,KOPrefs::instance()->mEnableQuickTodo);
1204 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo ); 1205 mItemPopupMenu->setItemChecked( 34 , KOPrefs::instance()->mEnableQuickTodo );
1205} 1206}
1206 1207
1207void KOTodoView::toggleRunning() 1208void KOTodoView::toggleRunning()
1208{ 1209{
1209 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos; 1210 KOPrefs::instance()->mHideNonStartedTodos = !KOPrefs::instance()->mHideNonStartedTodos;
1210 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos); 1211 mPopupMenu->setItemChecked(5,KOPrefs::instance()->mHideNonStartedTodos);
1211 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos ); 1212 mItemPopupMenu->setItemChecked( 35 , KOPrefs::instance()->mHideNonStartedTodos );
1212 updateView(); 1213 updateView();
1213} 1214}
1214 1215
1215void KOTodoView::toggleCompleted() 1216void KOTodoView::toggleCompleted()
1216{ 1217{
1217 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo; 1218 KOPrefs::instance()->mShowCompletedTodo = !KOPrefs::instance()->mShowCompletedTodo;
1218 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo ); 1219 mPopupMenu->setItemChecked( 3,KOPrefs::instance()->mShowCompletedTodo );
1219 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo ); 1220 mItemPopupMenu->setItemChecked( 33 , KOPrefs::instance()->mShowCompletedTodo );
1220 updateView(); 1221 updateView();
1221} 1222}
1222 1223
1223void KOTodoView::addQuickTodo() 1224void KOTodoView::addQuickTodo()
1224{ 1225{
1225 Todo *todo = new Todo(); 1226 Todo *todo = new Todo();
1226 todo->setSummary(mQuickAdd->text()); 1227 todo->setSummary(mQuickAdd->text());
1227 todo->setOrganizer(KOPrefs::instance()->email()); 1228 todo->setOrganizer(KOPrefs::instance()->email());
1228 CalFilter * cf = mCalendar->filter(); 1229 CalFilter * cf = mCalendar->filter();
1229 if ( cf ) { 1230 if ( cf ) {
1230 if ( cf->isEnabled()&& cf->showCategories()) { 1231 if ( cf->isEnabled()&& cf->showCategories()) {
1231 todo->setCategories(cf->categoryList()); 1232 todo->setCategories(cf->categoryList());
1232 } 1233 }
1233 if ( cf->isEnabled() ) 1234 if ( cf->isEnabled() )
1234 todo->setSecrecy( cf->getSecrecy()); 1235 todo->setSecrecy( cf->getSecrecy());
1235 } 1236 }
1236 mCalendar->addTodo(todo); 1237 mCalendar->addTodo(todo);
1237 mQuickAdd->setText(""); 1238 mQuickAdd->setText("");
1238 todoModified (todo, KOGlobals::EVENTADDED ); 1239 todoModified (todo, KOGlobals::EVENTADDED );
1239 updateView(); 1240 updateView();
1240} 1241}
1241void KOTodoView::keyPressEvent ( QKeyEvent * e ) 1242void KOTodoView::keyPressEvent ( QKeyEvent * e )
1242{ 1243{
1243 // e->ignore(); 1244 // e->ignore();
1244 //return; 1245 //return;
1245 //qDebug("KOTodoView::keyPressEvent "); 1246 //qDebug("KOTodoView::keyPressEvent ");
1246 switch ( e->key() ) { 1247 switch ( e->key() ) {
1247 case Qt::Key_Down: 1248 case Qt::Key_Down:
1248 case Qt::Key_Up: 1249 case Qt::Key_Up:
1249 QWidget::keyPressEvent ( e ); 1250 QWidget::keyPressEvent ( e );
1250 break; 1251 break;
1251 1252
1252 case Qt::Key_Q: 1253 case Qt::Key_Q:
1253 toggleQuickTodo(); 1254 toggleQuickTodo();
1254 break; 1255 break;
1255 case Qt::Key_U: 1256 case Qt::Key_U:
1256 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1257 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1257 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1258 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1258 unparentTodo(); 1259 unparentTodo();
1259 e->accept(); 1260 e->accept();
1260 } else 1261 } else
1261 e->ignore(); 1262 e->ignore();
1262 break; 1263 break;
1263 case Qt::Key_S: 1264 case Qt::Key_S:
1264 if ( e->state() == Qt::ControlButton ) { 1265 if ( e->state() == Qt::ControlButton ) {
1265 e->ignore(); 1266 e->ignore();
1266 break; 1267 break;
1267 } 1268 }
1268 if ( e->state() == Qt::ShiftButton ) { 1269 if ( e->state() == Qt::ShiftButton ) {
1269 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1270 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1270 reparentTodo(); 1271 reparentTodo();
1271 e->accept(); 1272 e->accept();
1272 } else 1273 } else
1273 e->ignore(); 1274 e->ignore();
1274 break; 1275 break;
1275 case Qt::Key_P: 1276 case Qt::Key_P:
1276 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { 1277 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) {
1277 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem(); 1278 mActiveItem = (KOTodoViewItem*)mTodoListView->currentItem();
1278 if ( pendingSubtodo ) 1279 if ( pendingSubtodo )
1279 itemClicked(mActiveItem); 1280 itemClicked(mActiveItem);
1280 e->accept(); 1281 e->accept();
1281 } else 1282 } else
1282 e->ignore(); 1283 e->ignore();
1283 break; 1284 break;
1284 case Qt::Key_Escape: 1285 case Qt::Key_Escape:
1285 if ( pendingSubtodo ) { 1286 if ( pendingSubtodo ) {
1286 itemClicked(0); 1287 itemClicked(0);
1287 e->accept(); 1288 e->accept();
1288 } else 1289 } else
1289 e->ignore(); 1290 e->ignore();
1290 break; 1291 break;
1291 default: 1292 default:
1292 e->ignore(); 1293 e->ignore();
1293 } 1294 }
1294 1295
1295 if ( true ) { 1296 if ( true ) {
1296 if ( e->key() == Qt::Key_I ) { 1297 if ( e->key() == Qt::Key_I ) {
1297 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem(); 1298 KOTodoViewItem*cn = (KOTodoViewItem*)mTodoListView->currentItem();
1298 if ( cn ) { 1299 if ( cn ) {
1299 mActiveItem = cn; 1300 mActiveItem = cn;
1300 KOTodoViewItem* ci = (KOTodoViewItem*)( cn ); 1301 KOTodoViewItem* ci = (KOTodoViewItem*)( cn );
1301 if ( ci ){ 1302 if ( ci ){
1302 showTodo(); 1303 showTodo();
1303 cn = (KOTodoViewItem*)cn->itemBelow(); 1304 cn = (KOTodoViewItem*)cn->itemBelow();
1304 if ( cn ) { 1305 if ( cn ) {
1305 mTodoListView->setCurrentItem ( cn ); 1306 mTodoListView->setCurrentItem ( cn );
1306 mTodoListView->ensureItemVisible ( cn ); 1307 mTodoListView->ensureItemVisible ( cn );
1307 } 1308 }
1308 1309
1309 } 1310 }
1310 } 1311 }
1311 e->accept(); 1312 e->accept();
1312 1313
1313 } 1314 }
1314 1315
1315 } 1316 }
1316 1317
1317} 1318}
1318void KOTodoView::updateTodo( Todo * t, int type ) 1319void KOTodoView::updateTodo( Todo * t, int type )
1319{ 1320{
1320 if ( mBlockUpdate) 1321 if ( mBlockUpdate)
1321 return; 1322 return;
1322 1323
1323 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator; 1324 QMap<Todo *,KOTodoViewItem *>::ConstIterator itemIterator;
1324 itemIterator = mTodoMap.find(t); 1325 itemIterator = mTodoMap.find(t);
1325 if (itemIterator != mTodoMap.end()) { 1326 if (itemIterator != mTodoMap.end()) {
1326 (*itemIterator)->construct(); 1327 (*itemIterator)->construct();
1327 } else { 1328 } else {
1328 if ( type == KOGlobals::EVENTADDED ) { 1329 if ( type == KOGlobals::EVENTADDED ) {
1329 insertTodoItem( t ); 1330 insertTodoItem( t );
1330 } 1331 }
1331 } 1332 }
1332 1333
1333} 1334}
1334 1335
1335void KOTodoView::todoModified(Todo * t , int p ) 1336void KOTodoView::todoModified(Todo * t , int p )
1336{ 1337{
1337 mBlockUpdate = true; 1338 mBlockUpdate = true;
1338 emit todoModifiedSignal ( t, p ); 1339 emit todoModifiedSignal ( t, p );
1339 mBlockUpdate = false; 1340 mBlockUpdate = false;
1340} 1341}
diff --git a/korganizer/kotodoview.h b/korganizer/kotodoview.h
index 462f0a6..eab0754 100644
--- a/korganizer/kotodoview.h
+++ b/korganizer/kotodoview.h
@@ -1,255 +1,257 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000, 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000, 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 KOTODOVIEW_H 23#ifndef KOTODOVIEW_H
24#define KOTODOVIEW_H 24#define KOTODOVIEW_H
25 25
26#include <qfont.h> 26#include <qfont.h>
27#include <qfontmetrics.h> 27#include <qfontmetrics.h>
28#include <qlineedit.h> 28#include <qlineedit.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30#include <qstrlist.h> 30#include <qstrlist.h>
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qmap.h> 34#include <qmap.h>
35#include <qlistview.h> 35#include <qlistview.h>
36#include <klistview.h> 36#include <klistview.h>
37 37
38#include <libkcal/calendar.h> 38#include <libkcal/calendar.h>
39#include <libkcal/todo.h> 39#include <libkcal/todo.h>
40 40
41#include <korganizer/baseview.h> 41#include <korganizer/baseview.h>
42 42
43#include "kotodoviewitem.h" 43#include "kotodoviewitem.h"
44#include "koprefs.h" 44#include "koprefs.h"
45#include "koglobals.h" 45#include "koglobals.h"
46#include "datenavigator.h" 46#include "datenavigator.h"
47 47
48class QDragEnterEvent; 48class QDragEnterEvent;
49class QDragMoveEvent; 49class QDragMoveEvent;
50class QDragLeaveEvent; 50class QDragLeaveEvent;
51class QDropEvent; 51class QDropEvent;
52class KOTodoViewWhatsThis;
52 53
53class DocPrefs; 54class DocPrefs;
54 55
55class KOTodoListView : public KListView 56class KOTodoListView : public KListView
56{ 57{
57 Q_OBJECT 58 Q_OBJECT
58 public: 59 public:
59 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0); 60 KOTodoListView(Calendar *,QWidget *parent=0,const char *name=0);
60 virtual ~KOTodoListView() {} 61 virtual ~KOTodoListView() {}
61 62
62 signals: 63 signals:
63 void paintNeeded(); 64 void paintNeeded();
64 void todoDropped(Todo *, int); 65 void todoDropped(Todo *, int);
65 void double_Clicked(QListViewItem *item); 66 void double_Clicked(QListViewItem *item);
66 void reparentTodoSignal( Todo *,Todo * ); 67 void reparentTodoSignal( Todo *,Todo * );
67 void unparentTodoSignal(Todo *); 68 void unparentTodoSignal(Todo *);
68 void deleteTodo( Todo * ); 69 void deleteTodo( Todo * );
69 protected: 70 protected:
70 void contentsDragEnterEvent(QDragEnterEvent *); 71 void contentsDragEnterEvent(QDragEnterEvent *);
71 void contentsDragMoveEvent(QDragMoveEvent *); 72 void contentsDragMoveEvent(QDragMoveEvent *);
72 void contentsDragLeaveEvent(QDragLeaveEvent *); 73 void contentsDragLeaveEvent(QDragLeaveEvent *);
73 void contentsDropEvent(QDropEvent *); 74 void contentsDropEvent(QDropEvent *);
74 75
75 void contentsMousePressEvent(QMouseEvent *); 76 void contentsMousePressEvent(QMouseEvent *);
76 void contentsMouseMoveEvent(QMouseEvent *); 77 void contentsMouseMoveEvent(QMouseEvent *);
77 void contentsMouseReleaseEvent(QMouseEvent *); 78 void contentsMouseReleaseEvent(QMouseEvent *);
78 void contentsMouseDoubleClickEvent(QMouseEvent *); 79 void contentsMouseDoubleClickEvent(QMouseEvent *);
79 80
80 private: 81 private:
81 void paintEvent(QPaintEvent * pevent); 82 void paintEvent(QPaintEvent * pevent);
82 bool internalDrop; 83 bool internalDrop;
83 QString mName; 84 QString mName;
84 Calendar *mCalendar; 85 Calendar *mCalendar;
85 QPoint mPressPos; 86 QPoint mPressPos;
86 bool mMousePressed; 87 bool mMousePressed;
87 QListViewItem *mOldCurrent; 88 QListViewItem *mOldCurrent;
88 void keyPressEvent ( QKeyEvent * ) ; 89 void keyPressEvent ( QKeyEvent * ) ;
89}; 90};
90 91
91 92
92/** 93/**
93 This is the line-edit on top of the todoview for fast addition of new todos 94 This is the line-edit on top of the todoview for fast addition of new todos
94*/ 95*/
95class KOQuickTodo : public QLineEdit 96class KOQuickTodo : public QLineEdit
96{ 97{
97 public: 98 public:
98 KOQuickTodo(QWidget *parent=0); 99 KOQuickTodo(QWidget *parent=0);
99 protected: 100 protected:
100 void focusInEvent(QFocusEvent *ev); 101 void focusInEvent(QFocusEvent *ev);
101 void focusOutEvent(QFocusEvent *ev); 102 void focusOutEvent(QFocusEvent *ev);
102}; 103};
103 104
104 105
105/** 106/**
106 This class provides a multi-column list view of todo events. 107 This class provides a multi-column list view of todo events.
107 108
108 @short multi-column list view of todo events. 109 @short multi-column list view of todo events.
109 @author Cornelius Schumacher <schumacher@kde.org> 110 @author Cornelius Schumacher <schumacher@kde.org>
110*/ 111*/
111class KOTodoView : public KOrg::BaseView 112class KOTodoView : public KOrg::BaseView
112{ 113{
113 Q_OBJECT 114 Q_OBJECT
114 public: 115 public:
115 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 ); 116 KOTodoView(Calendar *, QWidget* parent=0, const char* name=0 );
116 ~KOTodoView(); 117 ~KOTodoView();
117 118
118 QPtrList<Incidence> selectedIncidences(); 119 QPtrList<Incidence> selectedIncidences();
119 QPtrList<Todo> selectedTodos(); 120 QPtrList<Todo> selectedTodos();
120 121
121 DateList selectedDates() 122 DateList selectedDates()
122 {DateList q; 123 {DateList q;
123 return q;} 124 return q;}
124 125
125 /** Return number of shown dates. TodoView does not show dates, */ 126 /** Return number of shown dates. TodoView does not show dates, */
126 int currentDateCount() { return 0; } 127 int currentDateCount() { return 0; }
127 128
128 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td); 129 void printPreview(CalPrinter *calPrinter, const QDate &fd, const QDate &td);
129 130
130 void setDocumentId( const QString & ); 131 void setDocumentId( const QString & );
131 132
132 void saveLayout(KConfig *config, const QString &group) const; 133 void saveLayout(KConfig *config, const QString &group) const;
133 void restoreLayout(KConfig *config, const QString &group); 134 void restoreLayout(KConfig *config, const QString &group);
134 /** Create a popup menu to set categories */ 135 /** Create a popup menu to set categories */
135 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem); 136 QPopupMenu *getCategoryPopupMenu (KOTodoViewItem *todoItem);
136 void setNavigator( DateNavigator* nav ) {mNavigator = nav;} 137 void setNavigator( DateNavigator* nav ) {mNavigator = nav;}
137 QString getWhatsThisText(QPoint p); 138 QString getWhatsThisText(QPoint p);
138 139
139 public slots: 140 public slots:
140 void updateView(); 141 void updateView();
141 void updateConfig(); 142 void updateConfig();
142 143
143 void changeEventDisplay(Event *, int); 144 void changeEventDisplay(Event *, int);
144 145
145 void showDates(const QDate &start, const QDate &end); 146 void showDates(const QDate &start, const QDate &end);
146 void showEvents(QPtrList<Event> eventList); 147 void showEvents(QPtrList<Event> eventList);
147 148
148 void clearSelection(); 149 void clearSelection();
149 void jumpToDate (); 150 void jumpToDate ();
150 151
151 void editItem(QListViewItem *item); 152 void editItem(QListViewItem *item);
152 void showItem(QListViewItem *item,const QPoint &,int); 153 void showItem(QListViewItem *item,const QPoint &,int);
153 void popupMenu(QListViewItem *item,const QPoint &,int); 154 void popupMenu(QListViewItem *item,const QPoint &,int);
154 void newTodo(); 155 void newTodo();
155 void newSubTodo(); 156 void newSubTodo();
156 void unparentTodo(); 157 void unparentTodo();
157 void reparentTodo(); 158 void reparentTodo();
158 void showTodo(); 159 void showTodo();
159 void editTodo(); 160 void editTodo();
160 void cloneTodo(); 161 void cloneTodo();
161 void cancelTodo(); 162 void cancelTodo();
162 void moveTodo(); 163 void moveTodo();
163 void beamTodo(); 164 void beamTodo();
164 void deleteTodo(); 165 void deleteTodo();
165 166
166 void setNewPriority(int); 167 void setNewPriority(int);
167 void setNewPercentage(int); 168 void setNewPercentage(int);
168 void changedCategories(int); 169 void changedCategories(int);
169 170
170 void setAllOpen(); 171 void setAllOpen();
171 void setAllClose(); 172 void setAllClose();
172 void setAllFlat(); 173 void setAllFlat();
173 void displayAllFlat(); 174 void displayAllFlat();
174 175
175 void purgeCompleted(); 176 void purgeCompleted();
176 void toggleCompleted(); 177 void toggleCompleted();
177 void toggleRunning(); 178 void toggleRunning();
178 void toggleQuickTodo(); 179 void toggleQuickTodo();
179 void updateTodo( Todo *, int ); 180 void updateTodo( Todo *, int );
180 181
181 void itemClicked(QListViewItem *); 182 void itemClicked(QListViewItem *);
182 void itemStateChanged(QListViewItem *); 183 void itemStateChanged(QListViewItem *);
183 void modified(bool); 184 void modified(bool);
184 void itemDoubleClicked(QListViewItem *item); 185 void itemDoubleClicked(QListViewItem *item);
185 186
186 signals: 187 signals:
187 void newTodoSignal(); 188 void newTodoSignal();
188 void newSubTodoSignal(Todo *); 189 void newSubTodoSignal(Todo *);
189 void unparentTodoSignal(Todo *); 190 void unparentTodoSignal(Todo *);
190 void reparentTodoSignal( Todo *,Todo * ); 191 void reparentTodoSignal( Todo *,Todo * );
191 void showTodoSignal(Todo *); 192 void showTodoSignal(Todo *);
192 193
193 void editTodoSignal(Todo *); 194 void editTodoSignal(Todo *);
194 void deleteTodoSignal(Todo *); 195 void deleteTodoSignal(Todo *);
195 void todoModifiedSignal (Todo *, int); 196 void todoModifiedSignal (Todo *, int);
196 197
197 void isModified(bool); 198 void isModified(bool);
198 void cloneTodoSignal( Incidence * ); 199 void cloneTodoSignal( Incidence * );
199 void cancelTodoSignal( Incidence * ); 200 void cancelTodoSignal( Incidence * );
200 void moveTodoSignal( Incidence * ); 201 void moveTodoSignal( Incidence * );
201 void beamTodoSignal( Incidence * ); 202 void beamTodoSignal( Incidence * );
202 void purgeCompletedSignal(); 203 void purgeCompletedSignal();
203 204
204 protected slots: 205 protected slots:
205 void paintNeeded(); 206 void paintNeeded();
206 void processSelectionChange(); 207 void processSelectionChange();
207 void addQuickTodo(); 208 void addQuickTodo();
208 void setTodoModified( Todo* ); 209 void setTodoModified( Todo* );
209 void todoModified(Todo *, int ); 210 void todoModified(Todo *, int );
210 211
211 private: 212 private:
212 /* 213 /*
213 * the TodoEditor approach is rather unscaling in the long 214 * the TodoEditor approach is rather unscaling in the long
214 * run. 215 * run.
215 * Korganizer keeps it in memory and we need to update 216 * Korganizer keeps it in memory and we need to update
216 * 1. make KOTodoViewItem a QObject again? 217 * 1. make KOTodoViewItem a QObject again?
217 * 2. add a public method for setting one todo modified? 218 * 2. add a public method for setting one todo modified?
218 * 3. add a private method for setting a todo modified + friend here? 219 * 3. add a private method for setting a todo modified + friend here?
219 * -- zecke 2002-07-08 220 * -- zecke 2002-07-08
220 */ 221 */
222 KOTodoViewWhatsThis* mKOTodoViewWhatsThis;
221 friend class KOTodoListView; 223 friend class KOTodoListView;
222 void paintEvent(QPaintEvent * pevent); 224 void paintEvent(QPaintEvent * pevent);
223 bool mPendingUpdateBeforeRepaint; 225 bool mPendingUpdateBeforeRepaint;
224 friend class KOTodoViewItem; 226 friend class KOTodoViewItem;
225 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo); 227 QMap<Todo *,KOTodoViewItem *>::ConstIterator insertTodoItem(Todo *todo);
226 void restoreItemState( QListViewItem * ); 228 void restoreItemState( QListViewItem * );
227 229
228 bool checkTodo( Todo * ); 230 bool checkTodo( Todo * );
229 bool isFlatDisplay; 231 bool isFlatDisplay;
230 void setOpen( QListViewItem*, bool setOpen); 232 void setOpen( QListViewItem*, bool setOpen);
231 KOTodoListView *mTodoListView; 233 KOTodoListView *mTodoListView;
232 QPopupMenu *mItemPopupMenu; 234 QPopupMenu *mItemPopupMenu;
233 QPopupMenu *mPopupMenu; 235 QPopupMenu *mPopupMenu;
234 QPopupMenu *mPriorityPopupMenu; 236 QPopupMenu *mPriorityPopupMenu;
235 QPopupMenu *mPercentageCompletedPopupMenu; 237 QPopupMenu *mPercentageCompletedPopupMenu;
236 QPopupMenu *mCategoryPopupMenu; 238 QPopupMenu *mCategoryPopupMenu;
237 239
238 QMap<int, int> mPercentage; 240 QMap<int, int> mPercentage;
239 QMap<int, int> mPriority; 241 QMap<int, int> mPriority;
240 QMap<int, QString> mCategory; 242 QMap<int, QString> mCategory;
241 KOTodoViewItem *mActiveItem; 243 KOTodoViewItem *mActiveItem;
242 244
243 QMap<Todo *,KOTodoViewItem *> mTodoMap; 245 QMap<Todo *,KOTodoViewItem *> mTodoMap;
244 QString mName; 246 QString mName;
245 247
246 DocPrefs *mDocPrefs; 248 DocPrefs *mDocPrefs;
247 QString mCurrentDoc; 249 QString mCurrentDoc;
248 KOQuickTodo *mQuickAdd; 250 KOQuickTodo *mQuickAdd;
249 bool mBlockUpdate; 251 bool mBlockUpdate;
250 void keyPressEvent ( QKeyEvent * ) ; 252 void keyPressEvent ( QKeyEvent * ) ;
251 KOTodoViewItem * pendingSubtodo; 253 KOTodoViewItem * pendingSubtodo;
252 DateNavigator* mNavigator; 254 DateNavigator* mNavigator;
253}; 255};
254 256
255#endif 257#endif