author | zautrix <zautrix> | 2005-03-18 10:44:44 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-18 10:44:44 (UTC) |
commit | 414cb038cbe353f2fdb90969bc2531b687acc85f (patch) (unidiff) | |
tree | 178c9da0d3a711a90beef435d32dcce50c53bdae | |
parent | e972244f2a0581496301c7aa12e0498b34b48479 (diff) | |
download | kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.zip kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.tar.gz kdepimpi-414cb038cbe353f2fdb90969bc2531b687acc85f.tar.bz2 |
print fix
-rw-r--r-- | korganizer/calprintbase.cpp | 20 | ||||
-rw-r--r-- | korganizer/koagenda.cpp | 2 | ||||
-rw-r--r-- | libkdepim/kpimglobalprefs.cpp | 2 |
3 files changed, 9 insertions, 15 deletions
diff --git a/korganizer/calprintbase.cpp b/korganizer/calprintbase.cpp index f66fddc..7b7d54c 100644 --- a/korganizer/calprintbase.cpp +++ b/korganizer/calprintbase.cpp | |||
@@ -1,1312 +1,1306 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2003 Reinhold Kainhofer <reinhold@kainhofer.com> | 5 | Copyright (c) 2003 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 <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qptrlist.h> | 30 | #include <qptrlist.h> |
31 | #include <qintdict.h> | 31 | #include <qintdict.h> |
32 | #include <qfontmetrics.h> | 32 | #include <qfontmetrics.h> |
33 | 33 | ||
34 | #include <kglobal.h> | 34 | #include <kglobal.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | #include <kdebug.h> | 36 | #include <kdebug.h> |
37 | #include <kconfig.h> | 37 | #include <kconfig.h> |
38 | #include <kcalendarsystem.h> | 38 | #include <kcalendarsystem.h> |
39 | #include <kprinter.h> | 39 | #include <kprinter.h> |
40 | 40 | ||
41 | #include <libkcal/todo.h> | 41 | #include <libkcal/todo.h> |
42 | #include <libkcal/event.h> | 42 | #include <libkcal/event.h> |
43 | #include <libkcal/calendar.h> | 43 | #include <libkcal/calendar.h> |
44 | 44 | ||
45 | #include "koprefs.h" | 45 | #include "koprefs.h" |
46 | #include "koglobals.h" | 46 | #include "koglobals.h" |
47 | #ifndef KORG_NOPLUGINS | 47 | #ifndef KORG_NOPLUGINS |
48 | #include "kocore.h" | 48 | #include "kocore.h" |
49 | #endif | 49 | #endif |
50 | #include "cellitem.h" | 50 | #include "cellitem.h" |
51 | 51 | ||
52 | #include "calprintbase.h" | 52 | #include "calprintbase.h" |
53 | 53 | ||
54 | #ifndef KORG_NOPRINTER | 54 | #ifndef KORG_NOPRINTER |
55 | //#include "calprintbase.moc" | 55 | //#include "calprintbase.moc" |
56 | 56 | ||
57 | int CalPrintBase::mHeaderHeight=90; | 57 | int CalPrintBase::mHeaderHeight=90; |
58 | int CalPrintBase::mSubHeaderHeight=20; | 58 | int CalPrintBase::mSubHeaderHeight=20; |
59 | int CalPrintBase::mMargin=36; | 59 | int CalPrintBase::mMargin=36; |
60 | 60 | ||
61 | 61 | ||
62 | 62 | ||
63 | class CalPrintBase::TodoParentStart | 63 | class CalPrintBase::TodoParentStart |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | TodoParentStart( QRect pt = QRect(), bool page = true ) | 66 | TodoParentStart( QRect pt = QRect(), bool page = true ) |
67 | : mRect( pt ), mSamePage( page ) {} | 67 | : mRect( pt ), mSamePage( page ) {} |
68 | 68 | ||
69 | QRect mRect; | 69 | QRect mRect; |
70 | bool mSamePage; | 70 | bool mSamePage; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | class PrintCellItem : public KOrg::CellItem | 73 | class PrintCellItem : public KOrg::CellItem |
74 | { | 74 | { |
75 | public: | 75 | public: |
76 | PrintCellItem( Event *event, const QDate &day ) | 76 | PrintCellItem( Event *event, const QDate &day ) |
77 | : mEvent( event ), mDay( day ) | 77 | : mEvent( event ), mDay( day ) |
78 | { | 78 | { |
79 | } | 79 | } |
80 | 80 | ||
81 | Event *event() const { return mEvent; } | 81 | Event *event() const { return mEvent; } |
82 | 82 | ||
83 | QString label() const { return mEvent->summary(); } | 83 | QString label() const { return mEvent->summary(); } |
84 | 84 | ||
85 | bool overlaps( KOrg::CellItem *o ) const | 85 | bool overlaps( KOrg::CellItem *o ) const |
86 | { | 86 | { |
87 | PrintCellItem *other = static_cast<PrintCellItem *>( o ); | 87 | PrintCellItem *other = static_cast<PrintCellItem *>( o ); |
88 | 88 | ||
89 | QDateTime start = event()->dtStart(); | 89 | QDateTime start = event()->dtStart(); |
90 | QDateTime end = event()->dtEnd(); | 90 | QDateTime end = event()->dtEnd(); |
91 | if ( event()->doesRecur() ) { | 91 | if ( event()->doesRecur() ) { |
92 | start.setDate( mDay ); | 92 | start.setDate( mDay ); |
93 | end.setDate( mDay ); | 93 | end.setDate( mDay ); |
94 | } | 94 | } |
95 | QDateTime otherStart = other->event()->dtStart(); | 95 | QDateTime otherStart = other->event()->dtStart(); |
96 | QDateTime otherEnd = other->event()->dtEnd(); | 96 | QDateTime otherEnd = other->event()->dtEnd(); |
97 | if ( other->event()->doesRecur() ) { | 97 | if ( other->event()->doesRecur() ) { |
98 | otherStart.setDate( mDay ); | 98 | otherStart.setDate( mDay ); |
99 | otherEnd.setDate( mDay ); | 99 | otherEnd.setDate( mDay ); |
100 | } | 100 | } |
101 | 101 | ||
102 | #if 0 | 102 | #if 0 |
103 | kdDebug() << "PrintCellItem::overlaps() " << event()->summary() | 103 | kdDebug() << "PrintCellItem::overlaps() " << event()->summary() |
104 | << " <-> " << other->event()->summary() << endl; | 104 | << " <-> " << other->event()->summary() << endl; |
105 | kdDebug() << " start : " << start.toString() << endl; | 105 | kdDebug() << " start : " << start.toString() << endl; |
106 | kdDebug() << " end : " << end.toString() << endl; | 106 | kdDebug() << " end : " << end.toString() << endl; |
107 | kdDebug() << " otherStart: " << otherStart.toString() << endl; | 107 | kdDebug() << " otherStart: " << otherStart.toString() << endl; |
108 | kdDebug() << " otherEnd : " << otherEnd.toString() << endl; | 108 | kdDebug() << " otherEnd : " << otherEnd.toString() << endl; |
109 | #endif | 109 | #endif |
110 | 110 | ||
111 | return !( otherStart >= end || otherEnd <= start ); | 111 | return !( otherStart >= end || otherEnd <= start ); |
112 | } | 112 | } |
113 | 113 | ||
114 | private: | 114 | private: |
115 | Event *mEvent; | 115 | Event *mEvent; |
116 | QDate mDay; | 116 | QDate mDay; |
117 | }; | 117 | }; |
118 | 118 | ||
119 | void setCategoryColors( QPainter &p, Incidence *incidence) | 119 | void setCategoryColors( QPainter &p, Incidence *incidence) |
120 | { | 120 | { |
121 | QColor bgColor; | 121 | QColor bgColor; |
122 | QStringList categories = incidence->categories(); | 122 | QStringList categories = incidence->categories(); |
123 | QString cat = categories.first(); | 123 | QString cat = categories.first(); |
124 | if (cat.isEmpty()) | 124 | if (cat.isEmpty()) |
125 | bgColor = KOPrefs::instance()->mEventColor; | 125 | bgColor = KOPrefs::instance()->mEventColor; |
126 | else | 126 | else |
127 | bgColor = *(KOPrefs::instance()->categoryColor(cat)); | 127 | bgColor = *(KOPrefs::instance()->categoryColor(cat)); |
128 | QColor textColor = Qt::black;//getTextColor(bgColor); | 128 | QColor textColor = Qt::black;//getTextColor(bgColor); |
129 | p.setPen( textColor ); | 129 | p.setPen( textColor ); |
130 | p.setBrush( bgColor ); | 130 | p.setBrush( bgColor ); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | 134 | ||
135 | CalPrintBase::CalPrintBase( KPrinter *printer, Calendar *cal, KConfig *cfg ) | 135 | CalPrintBase::CalPrintBase( KPrinter *printer, Calendar *cal, KConfig *cfg ) |
136 | : QObject(), mPrinter( printer ), mCalendar( cal ), mConfig( cfg ) | 136 | : QObject(), mPrinter( printer ), mCalendar( cal ), mConfig( cfg ) |
137 | { | 137 | { |
138 | } | 138 | } |
139 | 139 | ||
140 | CalPrintBase::~CalPrintBase() | 140 | CalPrintBase::~CalPrintBase() |
141 | { | 141 | { |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | 145 | ||
146 | QWidget *CalPrintBase::configWidget( QWidget *w ) | 146 | QWidget *CalPrintBase::configWidget( QWidget *w ) |
147 | { | 147 | { |
148 | QFrame *wdg = new QFrame( w ); | 148 | QFrame *wdg = new QFrame( w ); |
149 | QVBoxLayout *layout = new QVBoxLayout( wdg ); | 149 | QVBoxLayout *layout = new QVBoxLayout( wdg ); |
150 | 150 | ||
151 | QLabel *title = new QLabel( description(), wdg ); | 151 | QLabel *title = new QLabel( description(), wdg ); |
152 | QFont titleFont( title->font() ); | 152 | QFont titleFont( title->font() ); |
153 | titleFont.setPointSize( 20 ); | 153 | titleFont.setPointSize( 20 ); |
154 | titleFont.setBold( true ); | 154 | titleFont.setBold( true ); |
155 | title->setFont( titleFont ); | 155 | title->setFont( titleFont ); |
156 | 156 | ||
157 | layout->addWidget( title ); | 157 | layout->addWidget( title ); |
158 | layout->addWidget( new QLabel( longDescription(), wdg ) ); | 158 | layout->addWidget( new QLabel( longDescription(), wdg ) ); |
159 | layout->addSpacing( 20 ); | 159 | layout->addSpacing( 20 ); |
160 | layout->addWidget( new QLabel( i18n("This printing style does not " | 160 | layout->addWidget( new QLabel( i18n("This printing style does not " |
161 | "have any configuration options."), | 161 | "have any configuration options."), |
162 | wdg ) ); | 162 | wdg ) ); |
163 | layout->addStretch(); | 163 | layout->addStretch(); |
164 | return wdg; | 164 | return wdg; |
165 | } | 165 | } |
166 | #include <qapplication.h> | 166 | #include <qapplication.h> |
167 | void CalPrintBase::doPrint() | 167 | void CalPrintBase::doPrint() |
168 | { | 168 | { |
169 | QPainter p; | 169 | QPainter p; |
170 | 170 | ||
171 | mPrinter->setColorMode( (mUseColors)?(KPrinter::Color):(KPrinter::GrayScale)); | 171 | mPrinter->setColorMode( (mUseColors)?(KPrinter::Color):(KPrinter::GrayScale)); |
172 | //#define DUMMY_PRINTER | 172 | //#define DUMMY_PRINTER |
173 | #ifdef DUMMY_PRINTER | 173 | #ifdef DUMMY_PRINTER |
174 | 174 | ||
175 | static QWidget* dummy = 0; | 175 | static QWidget* dummy = 0; |
176 | if ( ! dummy ) | 176 | if ( ! dummy ) |
177 | dummy = new QWidget( ); | 177 | dummy = new QWidget( ); |
178 | else { | 178 | else { |
179 | delete dummy; | 179 | delete dummy; |
180 | dummy = new QWidget( ); | 180 | dummy = new QWidget( ); |
181 | 181 | ||
182 | } | 182 | } |
183 | dummy->resize( 1024, 1024 ); | 183 | dummy->resize( 1024, 1024 ); |
184 | dummy->repaint(); | 184 | dummy->repaint(); |
185 | dummy->show(); | 185 | dummy->show(); |
186 | dummy->raise(); | 186 | dummy->raise(); |
187 | dummy->setBackgroundColor( Qt::white); | 187 | dummy->setBackgroundColor( Qt::white); |
188 | qApp->processEvents(); | 188 | qApp->processEvents(); |
189 | p.begin(dummy); | 189 | p.begin(dummy); |
190 | #else | 190 | #else |
191 | p.begin(mPrinter); | 191 | p.begin(mPrinter); |
192 | #endif | 192 | #endif |
193 | // the painter initially begins at 72 dpi per the Qt docs. | 193 | // the painter initially begins at 72 dpi per the Qt docs. |
194 | // we want half-inch margins. | 194 | // we want half-inch margins. |
195 | p.setViewport(mMargin, mMargin, | 195 | p.setViewport(mMargin, mMargin, |
196 | p.viewport().width()-mMargin, | 196 | p.viewport().width()-mMargin, |
197 | p.viewport().height()-mMargin); | 197 | p.viewport().height()-mMargin); |
198 | int pageWidth = p.viewport().width(); | 198 | int pageWidth = p.viewport().width(); |
199 | int pageHeight = p.viewport().height(); | 199 | int pageHeight = p.viewport().height(); |
200 | 200 | ||
201 | print(p, pageWidth, pageHeight); | 201 | print(p, pageWidth, pageHeight); |
202 | 202 | ||
203 | p.end(); | 203 | p.end(); |
204 | } | 204 | } |
205 | 205 | ||
206 | void CalPrintBase::doLoadConfig() | 206 | void CalPrintBase::doLoadConfig() |
207 | { | 207 | { |
208 | if ( mConfig ) { | 208 | if ( mConfig ) { |
209 | mConfig->setGroup(description()); | 209 | mConfig->setGroup(description()); |
210 | //KConfigGroupSaver saver( mConfig, description() ); | 210 | //KConfigGroupSaver saver( mConfig, description() ); |
211 | mConfig->sync(); | 211 | mConfig->sync(); |
212 | QDateTime currDate( QDate::currentDate() ); | 212 | QDateTime currDate( QDate::currentDate() ); |
213 | mFromDate = mConfig->readDateTimeEntry( "FromDate", &currDate ).date(); | 213 | mFromDate = mConfig->readDateTimeEntry( "FromDate", &currDate ).date(); |
214 | mToDate = mConfig->readDateTimeEntry( "ToDate" ).date(); | 214 | mToDate = mConfig->readDateTimeEntry( "ToDate" ).date(); |
215 | mUseColors = mConfig->readBoolEntry( "UseColors", false ); | 215 | mUseColors = mConfig->readBoolEntry( "UseColors", false ); |
216 | loadConfig(); | 216 | loadConfig(); |
217 | } else { | 217 | } else { |
218 | qDebug("no config in CalPrintBase::doLoadConfig "); | 218 | qDebug("no config in CalPrintBase::doLoadConfig "); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | void CalPrintBase::doSaveConfig() | 222 | void CalPrintBase::doSaveConfig() |
223 | { | 223 | { |
224 | if ( mConfig ) { | 224 | if ( mConfig ) { |
225 | mConfig->setGroup(description()); | 225 | mConfig->setGroup(description()); |
226 | // KConfigGroupSaver saver( mConfig, description() ); | 226 | // KConfigGroupSaver saver( mConfig, description() ); |
227 | saveConfig(); | 227 | saveConfig(); |
228 | mConfig->writeEntry( "FromDate", QDateTime( mFromDate ) ); | 228 | mConfig->writeEntry( "FromDate", QDateTime( mFromDate ) ); |
229 | mConfig->writeEntry( "ToDate", QDateTime( mToDate ) ); | 229 | mConfig->writeEntry( "ToDate", QDateTime( mToDate ) ); |
230 | mConfig->writeEntry( "UseColors", mUseColors ); | 230 | mConfig->writeEntry( "UseColors", mUseColors ); |
231 | mConfig->sync(); | 231 | mConfig->sync(); |
232 | } else { | 232 | } else { |
233 | qDebug("no config in CalPrintBase::doSveConfig "); | 233 | qDebug("no config in CalPrintBase::doSveConfig "); |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | /////////////////////////////////////////////////////////////////////////////// | 237 | /////////////////////////////////////////////////////////////////////////////// |
238 | 238 | ||
239 | void CalPrintBase::drawHeader( QPainter &p, QString title, | 239 | void CalPrintBase::drawHeader( QPainter &p, QString title, |
240 | const QDate &month1, const QDate &month2, | 240 | const QDate &month1, const QDate &month2, |
241 | int x, int y, int width, int height ) | 241 | int x, int y, int width, int height ) |
242 | { | 242 | { |
243 | p.drawRect(x, y, width, height); | 243 | p.drawRect(x, y, width, height); |
244 | // p.fillRect( x+1, y+1, | 244 | // p.fillRect( x+1, y+1, |
245 | // width-2,height-2, | 245 | // width-2,height-2, |
246 | // QBrush(Dense7Pattern) ); | 246 | // QBrush(Dense7Pattern) ); |
247 | 247 | ||
248 | QString myOwner(mCalendar->getOwner()); | 248 | QString myOwner(mCalendar->getOwner()); |
249 | 249 | ||
250 | int right=x+width; | 250 | int right=x+width; |
251 | 251 | ||
252 | // print previous month for month view, print current for todo, day and week | 252 | // print previous month for month view, print current for todo, day and week |
253 | int smallMonthWidth=width/4-10; | 253 | int smallMonthWidth=width/4-10; |
254 | if (smallMonthWidth>100) smallMonthWidth=100; | 254 | if (smallMonthWidth>100) smallMonthWidth=100; |
255 | if (month2.isValid()) { | 255 | if (month2.isValid()) { |
256 | right -= (10+smallMonthWidth); | 256 | right -= (10+smallMonthWidth); |
257 | drawSmallMonth(p, QDate(month2.year(), month2.month(), 1), | 257 | drawSmallMonth(p, QDate(month2.year(), month2.month(), 1), |
258 | right, y+2, smallMonthWidth, height-4); | 258 | right, y+2, smallMonthWidth, height-4); |
259 | right-=10; | 259 | right-=10; |
260 | } | 260 | } |
261 | if (month1.isValid()) { | 261 | if (month1.isValid()) { |
262 | right -= (10+smallMonthWidth); | 262 | right -= (10+smallMonthWidth); |
263 | drawSmallMonth(p, QDate(month1.year(), month1.month(), 1), | 263 | drawSmallMonth(p, QDate(month1.year(), month1.month(), 1), |
264 | right, y+2, smallMonthWidth, height-4); | 264 | right, y+2, smallMonthWidth, height-4); |
265 | right-=10; | 265 | right-=10; |
266 | } | 266 | } |
267 | 267 | ||
268 | // Print the titles... | 268 | // Print the titles... |
269 | QFont font("helvetica", 18, QFont::Bold); | 269 | QFont font("helvetica", 18, QFont::Bold); |
270 | p.setFont(font); | 270 | p.setFont(font); |
271 | QRect textRect( x+5, y+5, right-10-x, height-10 ); | 271 | QRect textRect( x+5, y+5, right-10-x, height-10 ); |
272 | p.drawText( textRect, Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak, title ); | 272 | p.drawText( textRect, Qt::AlignLeft | Qt::AlignTop | Qt::WordBreak, title ); |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | void CalPrintBase::drawSmallMonth(QPainter &p, const QDate &qd, | 276 | void CalPrintBase::drawSmallMonth(QPainter &p, const QDate &qd, |
277 | int x, int y, int width, int height) | 277 | int x, int y, int width, int height) |
278 | { | 278 | { |
279 | bool firstCol = true; | 279 | bool firstCol = true; |
280 | QDate monthDate(QDate(qd.year(), qd.month(), 1)); | 280 | QDate monthDate(QDate(qd.year(), qd.month(), 1)); |
281 | QDate monthDate2; | 281 | QDate monthDate2; |
282 | int month = monthDate.month(); | 282 | int month = monthDate.month(); |
283 | 283 | ||
284 | // draw the title | 284 | // draw the title |
285 | p.setFont(QFont("helvetica", 7, QFont::Bold)); | 285 | p.setFont(QFont("helvetica", 7, QFont::Bold)); |
286 | // int lineSpacing = p.fontMetrics().lineSpacing(); | 286 | // int lineSpacing = p.fontMetrics().lineSpacing(); |
287 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); | 287 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); |
288 | p.drawText(x, y, width, height/4, AlignCenter, calSys->monthName( qd ) ); | 288 | p.drawText(x, y, width, height/4, AlignCenter, calSys->monthName( qd ) ); |
289 | 289 | ||
290 | int cellWidth = width/7; | 290 | int cellWidth = width/7; |
291 | int cellHeight = height/8; | 291 | int cellHeight = height/8; |
292 | QString tmpStr; | 292 | QString tmpStr; |
293 | 293 | ||
294 | // correct begin of week | 294 | // correct begin of week |
295 | int weekdayCol = weekdayColumn( qd.dayOfWeek() ); | 295 | int weekdayCol = weekdayColumn( qd.dayOfWeek() ); |
296 | monthDate2 = monthDate.addDays(-weekdayCol); | 296 | monthDate2 = monthDate.addDays(-weekdayCol); |
297 | 297 | ||
298 | // draw days of week | 298 | // draw days of week |
299 | p.setFont(QFont("helvetica", 7, QFont::Bold)); | 299 | p.setFont(QFont("helvetica", 7, QFont::Bold)); |
300 | for (int col = 0; col < 7; col++) { | 300 | for (int col = 0; col < 7; col++) { |
301 | // tmpStr.sprintf("%c",(const char*)monthDate2.dayName(monthDate2.dayOfWeek())); | 301 | // tmpStr.sprintf("%c",(const char*)monthDate2.dayName(monthDate2.dayOfWeek())); |
302 | tmpStr=calSys->weekDayName( monthDate2 )[0].upper(); | 302 | tmpStr=calSys->weekDayName( monthDate2 )[0].upper(); |
303 | p.drawText(x+col*cellWidth, y+height/4, cellWidth, cellHeight, | 303 | p.drawText(x+col*cellWidth, y+height/4, cellWidth, cellHeight, |
304 | AlignCenter, tmpStr); | 304 | AlignCenter, tmpStr); |
305 | monthDate2 = monthDate2.addDays(1); | 305 | monthDate2 = monthDate2.addDays(1); |
306 | } | 306 | } |
307 | 307 | ||
308 | // draw separator line | 308 | // draw separator line |
309 | p.drawLine(x, y+height/4+cellHeight, x+width, y+height/4+cellHeight); | 309 | p.drawLine(x, y+height/4+cellHeight, x+width, y+height/4+cellHeight); |
310 | 310 | ||
311 | for (int row = 0; row < 5; row++) { | 311 | for (int row = 0; row < 5; row++) { |
312 | for (int col = 0; col < 7; col++) { | 312 | for (int col = 0; col < 7; col++) { |
313 | if (monthDate.month() != month) | 313 | if (monthDate.month() != month) |
314 | break; | 314 | break; |
315 | if (firstCol) { | 315 | if (firstCol) { |
316 | firstCol = true; | 316 | firstCol = true; |
317 | col = weekdayColumn( monthDate.dayOfWeek() ); | 317 | col = weekdayColumn( monthDate.dayOfWeek() ); |
318 | } | 318 | } |
319 | p.drawText( x+col*cellWidth, | 319 | p.drawText( x+col*cellWidth, |
320 | y+height/4+cellHeight+(row*cellHeight), | 320 | y+height/4+cellHeight+(row*cellHeight), |
321 | cellWidth, cellHeight, AlignCenter, | 321 | cellWidth, cellHeight, AlignCenter, |
322 | tmpStr.setNum(monthDate.day()) ); | 322 | tmpStr.setNum(monthDate.day()) ); |
323 | monthDate = monthDate.addDays(1); | 323 | monthDate = monthDate.addDays(1); |
324 | } | 324 | } |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | 328 | ||
329 | /////////////////////////////////////////////////////////////////////////////// | 329 | /////////////////////////////////////////////////////////////////////////////// |
330 | 330 | ||
331 | /* | 331 | /* |
332 | * This routine draws a header box over the main part of the calendar | 332 | * This routine draws a header box over the main part of the calendar |
333 | * containing the days of the week. | 333 | * containing the days of the week. |
334 | */ | 334 | */ |
335 | void CalPrintBase::drawDaysOfWeek(QPainter &p, | 335 | void CalPrintBase::drawDaysOfWeek(QPainter &p, |
336 | const QDate &fromDate, const QDate &toDate, | 336 | const QDate &fromDate, const QDate &toDate, |
337 | int x, int y, int width, int height) | 337 | int x, int y, int width, int height) |
338 | { | 338 | { |
339 | int cellWidth = width/(fromDate.daysTo( toDate )+1); | 339 | int cellWidth = width/(fromDate.daysTo( toDate )+1); |
340 | int currx=x; | 340 | int currx=x; |
341 | QDate cellDate(fromDate); | 341 | QDate cellDate(fromDate); |
342 | 342 | ||
343 | while (cellDate<=toDate) { | 343 | while (cellDate<=toDate) { |
344 | drawDaysOfWeekBox(p, cellDate, currx, y, cellWidth, height); | 344 | drawDaysOfWeekBox(p, cellDate, currx, y, cellWidth, height); |
345 | currx+=cellWidth; | 345 | currx+=cellWidth; |
346 | cellDate = cellDate.addDays(1); | 346 | cellDate = cellDate.addDays(1); |
347 | } | 347 | } |
348 | } | 348 | } |
349 | 349 | ||
350 | 350 | ||
351 | void CalPrintBase::drawDaysOfWeekBox(QPainter &p, const QDate &qd, | 351 | void CalPrintBase::drawDaysOfWeekBox(QPainter &p, const QDate &qd, |
352 | int x, int y, int width, int height) | 352 | int x, int y, int width, int height) |
353 | { | 353 | { |
354 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); | 354 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); |
355 | 355 | ||
356 | p.setFont( QFont( "helvetica", 10, QFont::Bold ) ); | 356 | p.setFont( QFont( "helvetica", 10, QFont::Bold ) ); |
357 | p.drawRect( x, y, width, height ); | 357 | p.drawRect( x, y, width, height ); |
358 | // p.fillRect( x+1, y+1, | 358 | // p.fillRect( x+1, y+1, |
359 | // width-2, height-2, | 359 | // width-2, height-2, |
360 | // QBrush( Dense7Pattern ) ); | 360 | // QBrush( Dense7Pattern ) ); |
361 | p.drawText( x+5, y, width-10, height, AlignCenter | AlignVCenter, | 361 | p.drawText( x+5, y, width-10, height, AlignCenter | AlignVCenter, |
362 | calSys->weekDayName( qd ) ); | 362 | calSys->weekDayName( qd ) ); |
363 | } | 363 | } |
364 | 364 | ||
365 | 365 | ||
366 | void CalPrintBase::drawTimeLine(QPainter &p, | 366 | void CalPrintBase::drawTimeLine(QPainter &p, |
367 | const QTime &fromTime, const QTime &toTime, | 367 | const QTime &fromTime, const QTime &toTime, |
368 | int x, int y, int width, int height) | 368 | int x, int y, int width, int height) |
369 | { | 369 | { |
370 | p.drawRect(x, y, width, height); | 370 | p.drawRect(x, y, width, height); |
371 | 371 | ||
372 | int totalsecs=fromTime.secsTo(toTime); | 372 | int totalsecs=fromTime.secsTo(toTime); |
373 | float minlen=(float)height*60./(float)totalsecs; | 373 | float minlen=(float)height*60./(float)totalsecs; |
374 | float cellHeight=(60.*(float)minlen); | 374 | float cellHeight=(60.*(float)minlen); |
375 | float currY=y; | 375 | float currY=y; |
376 | 376 | ||
377 | QTime curTime( fromTime ); | 377 | QTime curTime( fromTime ); |
378 | QTime endTime( toTime ); | 378 | QTime endTime( toTime ); |
379 | if ( fromTime.minute() > 30 ) | 379 | if ( fromTime.minute() > 30 ) |
380 | curTime = QTime( fromTime.hour()+1, 0, 0 ); | 380 | curTime = QTime( fromTime.hour()+1, 0, 0 ); |
381 | else if ( fromTime.minute() > 0 ) { | 381 | else if ( fromTime.minute() > 0 ) { |
382 | curTime = QTime( fromTime.hour(), 30, 0 ); | 382 | curTime = QTime( fromTime.hour(), 30, 0 ); |
383 | float yy = currY + minlen*(float)fromTime.secsTo( curTime )/60.; | 383 | float yy = currY + minlen*(float)fromTime.secsTo( curTime )/60.; |
384 | p.drawLine( x+width/2, (int)yy, x+width, (int)yy ); | 384 | p.drawLine( x+width/2, (int)yy, x+width, (int)yy ); |
385 | curTime = QTime( fromTime.hour()+1, 0, 0 ); | 385 | curTime = QTime( fromTime.hour()+1, 0, 0 ); |
386 | } | 386 | } |
387 | currY += ( fromTime.secsTo(curTime)*minlen/60 ); | 387 | currY += ( fromTime.secsTo(curTime)*minlen/60 ); |
388 | 388 | ||
389 | while ( curTime < endTime ) { | 389 | while ( curTime < endTime ) { |
390 | p.drawLine( x, (int)currY, x+width, (int)currY ); | 390 | p.drawLine( x, (int)currY, x+width, (int)currY ); |
391 | int newY=(int)(currY+cellHeight/2.); | 391 | int newY=(int)(currY+cellHeight/2.); |
392 | QString numStr; | 392 | QString numStr; |
393 | if (newY < y+height) { | 393 | if (newY < y+height) { |
394 | p.drawLine(x+width/2, (int)newY, x+width, (int)newY); | 394 | p.drawLine(x+width/2, (int)newY, x+width, (int)newY); |
395 | // draw the time: | 395 | // draw the time: |
396 | if ( !KGlobal::locale()->use12Clock() ) { | 396 | if ( !KGlobal::locale()->use12Clock() ) { |
397 | numStr.setNum(curTime.hour()); | 397 | numStr.setNum(curTime.hour()); |
398 | if (cellHeight > 30) { | 398 | if (cellHeight > 30) { |
399 | p.setFont(QFont("helvetica", 16, QFont::Bold)); | 399 | p.setFont(QFont("helvetica", 16, QFont::Bold)); |
400 | } else { | 400 | } else { |
401 | p.setFont(QFont("helvetica", 12, QFont::Bold)); | 401 | p.setFont(QFont("helvetica", 12, QFont::Bold)); |
402 | } | 402 | } |
403 | p.drawText(x+2, (int)currY+2, width/2-2, (int)cellHeight, | 403 | p.drawText(x+2, (int)currY+2, width/2-2, (int)cellHeight, |
404 | AlignTop|AlignRight, numStr); | 404 | AlignTop|AlignRight, numStr); |
405 | p.setFont(QFont("helvetica", 10, QFont::Normal)); | 405 | p.setFont(QFont("helvetica", 10, QFont::Normal)); |
406 | p.drawText(x+width/2, (int)currY+2, width/2+2, (int)(cellHeight/2)-3, | 406 | p.drawText(x+width/2, (int)currY+2, width/2+2, (int)(cellHeight/2)-3, |
407 | AlignTop | AlignLeft, "00"); | 407 | AlignTop | AlignLeft, "00"); |
408 | } else { | 408 | } else { |
409 | QTime time( curTime.hour(), 0 ); | 409 | QTime time( curTime.hour(), 0 ); |
410 | numStr = KGlobal::locale()->formatTime( time ); | 410 | numStr = KGlobal::locale()->formatTime( time ); |
411 | p.setFont(QFont("helvetica", 14, QFont::Bold)); | 411 | p.setFont(QFont("helvetica", 14, QFont::Bold)); |
412 | p.drawText(x+2, (int)currY+2, width-4, (int)cellHeight/2-3, | 412 | p.drawText(x+2, (int)currY+2, width-4, (int)cellHeight/2-3, |
413 | AlignTop|AlignLeft, numStr); | 413 | AlignTop|AlignLeft, numStr); |
414 | } | 414 | } |
415 | currY+=cellHeight; | 415 | currY+=cellHeight; |
416 | } // enough space for half-hour line and time | 416 | } // enough space for half-hour line and time |
417 | if (curTime.secsTo(endTime)>3600) | 417 | if (curTime.secsTo(endTime)>3600) |
418 | curTime=curTime.addSecs(3600); | 418 | curTime=curTime.addSecs(3600); |
419 | else curTime=endTime; | 419 | else curTime=endTime; |
420 | } // currTime<endTime | 420 | } // currTime<endTime |
421 | } | 421 | } |
422 | 422 | ||
423 | 423 | ||
424 | /////////////////////////////////////////////////////////////////////////////// | 424 | /////////////////////////////////////////////////////////////////////////////// |
425 | 425 | ||
426 | /** prints the all-day box for the agenda print view. if expandable is set, | 426 | /** prints the all-day box for the agenda print view. if expandable is set, |
427 | height is the cell height of a single cell, and the returned height will | 427 | height is the cell height of a single cell, and the returned height will |
428 | be the total height used for the all-day events. If !expandable, only one | 428 | be the total height used for the all-day events. If !expandable, only one |
429 | cell will be used, and multiple events are concatenated using ", ". | 429 | cell will be used, and multiple events are concatenated using ", ". |
430 | */ | 430 | */ |
431 | void CalPrintBase::drawAllDayBox(QPainter &p, Event::List &eventList, | 431 | void CalPrintBase::drawAllDayBox(QPainter &p, Event::List &eventList, |
432 | const QDate &qd, bool expandable, | 432 | const QDate &qd, bool expandable, |
433 | int x, int y, int width, int &height) | 433 | int x, int y, int width, int &height) |
434 | { | 434 | { |
435 | Event::List::Iterator it, itold; | 435 | Event::List::Iterator it, itold; |
436 | 436 | ||
437 | int offset=y; | 437 | int offset=y; |
438 | 438 | ||
439 | //p.setBrush(QBrush(Dense7Pattern)); | 439 | //p.setBrush(QBrush(Dense7Pattern)); |
440 | QPen oldPen(p.pen()); | 440 | QPen oldPen(p.pen()); |
441 | QColor oldBgColor(p.backgroundColor()); | 441 | QColor oldBgColor(p.backgroundColor()); |
442 | QBrush oldBrush(p.brush()); | 442 | QBrush oldBrush(p.brush()); |
443 | QString multiDayStr; | 443 | QString multiDayStr; |
444 | 444 | ||
445 | it = eventList.begin(); | 445 | it = eventList.begin(); |
446 | #ifndef KORG_NOPLUGINS | 446 | #ifndef KORG_NOPLUGINS |
447 | QString hstring(KOCore::self()->holiday(qd)); | 447 | QString hstring(KOCore::self()->holiday(qd)); |
448 | if (!hstring.isEmpty()) { | 448 | if (!hstring.isEmpty()) { |
449 | Event*holiday=new Event(); | 449 | Event*holiday=new Event(); |
450 | holiday->setDtStart(qd); | 450 | holiday->setDtStart(qd); |
451 | holiday->setDtEnd(qd); | 451 | holiday->setDtEnd(qd); |
452 | holiday->setFloats(true); | 452 | holiday->setFloats(true); |
453 | holiday->setCategories(i18n("Holiday")); | 453 | holiday->setCategories(i18n("Holiday")); |
454 | eventList.prepend(holiday); | 454 | eventList.prepend(holiday); |
455 | } | 455 | } |
456 | #endif | 456 | #endif |
457 | Event *currEvent = 0; | 457 | Event *currEvent = 0; |
458 | // First, print all floating events | 458 | // First, print all floating events |
459 | while( it!=eventList.end() ) { | 459 | while( it!=eventList.end() ) { |
460 | currEvent=*it; | 460 | currEvent=*it; |
461 | itold=it; | 461 | itold=it; |
462 | ++it; | 462 | ++it; |
463 | if ( currEvent->doesFloat() ) { | 463 | if ( currEvent->doesFloat() ) { |
464 | // set the colors according to the categories | 464 | // set the colors according to the categories |
465 | QString text = currEvent->summary() ; | 465 | QString text = currEvent->summary() ; |
466 | if ( ! currEvent->location().isEmpty() ) | 466 | if ( ! currEvent->location().isEmpty() ) |
467 | text += " ("+currEvent->location()+")"; | 467 | text += " ("+currEvent->location()+")"; |
468 | if (expandable) { | 468 | if (expandable) { |
469 | if (mUseColors) | 469 | if (mUseColors) |
470 | setCategoryColors(p, currEvent); | 470 | setCategoryColors(p, currEvent); |
471 | 471 | ||
472 | p.drawRect( x, offset, width, height ); | 472 | p.drawRect( x, offset, width, height ); |
473 | 473 | ||
474 | p.drawText( x+5, offset+5, width-10, height-10, | 474 | p.drawText( x+5, offset+5, width-10, height-10, |
475 | AlignCenter | AlignVCenter | AlignJustify | WordBreak, | 475 | AlignCenter | AlignVCenter | AlignJustify | WordBreak, |
476 | text ); | 476 | text ); |
477 | // reset the colors | 477 | // reset the colors |
478 | p.setBrush( oldBrush ); | 478 | p.setBrush( oldBrush ); |
479 | p.setPen( oldPen ); | 479 | p.setPen( oldPen ); |
480 | p.setBackgroundColor(oldBgColor); | 480 | p.setBackgroundColor(oldBgColor); |
481 | 481 | ||
482 | offset += height; | 482 | offset += height; |
483 | } else { | 483 | } else { |
484 | //if (!multiDayStr.isEmpty()) multiDayStr+=", "; | 484 | //if (!multiDayStr.isEmpty()) multiDayStr+=", "; |
485 | multiDayStr += text+"\n"; | 485 | multiDayStr += text+"\n"; |
486 | } | 486 | } |
487 | eventList.remove( itold ); | 487 | eventList.remove( itold ); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
491 | if (!expandable) { | 491 | if (!expandable) { |
492 | p.drawRect(x, offset, width, height); | 492 | p.drawRect(x, offset, width, height); |
493 | if (!multiDayStr.isEmpty()) { | 493 | if (!multiDayStr.isEmpty()) { |
494 | // p.fillRect(x+1, offset+1, width-2, height-2, QBrush(Dense5Pattern) ); | 494 | // p.fillRect(x+1, offset+1, width-2, height-2, QBrush(Dense5Pattern) ); |
495 | p.drawText( x+5, offset+5, width-10, height-10, | 495 | p.drawText( x+5, offset+5, width-10, height-10, |
496 | AlignLeft | AlignTop | AlignJustify , | 496 | AlignLeft | AlignTop | AlignJustify , |
497 | multiDayStr); | 497 | multiDayStr); |
498 | } | 498 | } |
499 | } else { | 499 | } else { |
500 | height=offset-y; | 500 | height=offset-y; |
501 | } | 501 | } |
502 | } | 502 | } |
503 | 503 | ||
504 | 504 | ||
505 | void CalPrintBase::drawAgendaDayBox( QPainter &p, Event::List &events, | 505 | void CalPrintBase::drawAgendaDayBox( QPainter &p, Event::List &events, |
506 | const QDate &qd, bool expandable, | 506 | const QDate &qd, bool expandable, |
507 | QTime &fromTime, QTime &toTime, | 507 | QTime &fromTime, QTime &toTime, |
508 | int x, int y, int width, int height ) | 508 | int x, int y, int width, int height ) |
509 | { | 509 | { |
510 | p.drawRect( x, y, width, height ); | 510 | p.drawRect( x, y, width, height ); |
511 | 511 | ||
512 | Event *event; | 512 | Event *event; |
513 | 513 | ||
514 | if ( expandable ) { | 514 | if ( expandable ) { |
515 | // Adapt start/end times to include complete events | 515 | // Adapt start/end times to include complete events |
516 | Event::List::ConstIterator it; | 516 | Event::List::ConstIterator it; |
517 | for ( it = events.begin(); it != events.end(); ++it ) { | 517 | for ( it = events.begin(); it != events.end(); ++it ) { |
518 | event = *it; | 518 | event = *it; |
519 | if ( event->dtStart().time() < fromTime ) | 519 | if ( event->dtStart().time() < fromTime ) |
520 | fromTime = event->dtStart().time(); | 520 | fromTime = event->dtStart().time(); |
521 | if ( event->dtEnd().time() > toTime ) | 521 | if ( event->dtEnd().time() > toTime ) |
522 | toTime = event->dtEnd().time(); | 522 | toTime = event->dtEnd().time(); |
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | // Show at least one hour | 526 | // Show at least one hour |
527 | if ( fromTime.secsTo( toTime ) < 3600 ) { | 527 | if ( fromTime.secsTo( toTime ) < 3600 ) { |
528 | fromTime = QTime( fromTime.hour(), 0, 0 ); | 528 | fromTime = QTime( fromTime.hour(), 0, 0 ); |
529 | toTime = fromTime.addSecs( 3600 ); | 529 | toTime = fromTime.addSecs( 3600 ); |
530 | } | 530 | } |
531 | 531 | ||
532 | // calculate the height of a cell and of a minute | 532 | // calculate the height of a cell and of a minute |
533 | int totalsecs = fromTime.secsTo( toTime ); | 533 | int totalsecs = fromTime.secsTo( toTime ); |
534 | float minlen = height * 60. / totalsecs; | 534 | float minlen = height * 60. / totalsecs; |
535 | float cellHeight = 60. * minlen; | 535 | float cellHeight = 60. * minlen; |
536 | float currY = y; | 536 | float currY = y; |
537 | 537 | ||
538 | // print grid: | 538 | // print grid: |
539 | QTime curTime( QTime( fromTime.hour(), 0, 0 ) ); | 539 | QTime curTime( QTime( fromTime.hour(), 0, 0 ) ); |
540 | currY += fromTime.secsTo( curTime ) * minlen / 60; | 540 | currY += fromTime.secsTo( curTime ) * minlen / 60; |
541 | 541 | ||
542 | while ( curTime < toTime && curTime.isValid() ) { | 542 | while ( curTime < toTime && curTime.isValid() ) { |
543 | if ( currY > y ) p.drawLine( x, int( currY ), x + width, int( currY ) ); | 543 | if ( currY > y ) p.drawLine( x, int( currY ), x + width, int( currY ) ); |
544 | currY += cellHeight / 2; | 544 | currY += cellHeight / 2; |
545 | if ( ( currY > y ) && ( currY < y + height ) ) { | 545 | if ( ( currY > y ) && ( currY < y + height ) ) { |
546 | QPen oldPen( p.pen() ); | 546 | QPen oldPen( p.pen() ); |
547 | p.setPen( QColor( 192, 192, 192 ) ); | 547 | p.setPen( QColor( 192, 192, 192 ) ); |
548 | p.drawLine( x, int( currY ), x + width, int( currY ) ); | 548 | p.drawLine( x, int( currY ), x + width, int( currY ) ); |
549 | p.setPen( oldPen ); | 549 | p.setPen( oldPen ); |
550 | } // enough space for half-hour line | 550 | } // enough space for half-hour line |
551 | if ( curTime.secsTo( toTime ) > 3600 ) | 551 | if ( curTime.secsTo( toTime ) > 3600 ) |
552 | curTime = curTime.addSecs( 3600 ); | 552 | curTime = curTime.addSecs( 3600 ); |
553 | else curTime = toTime; | 553 | else curTime = toTime; |
554 | currY += cellHeight / 2; | 554 | currY += cellHeight / 2; |
555 | } | 555 | } |
556 | 556 | ||
557 | QDateTime startPrintDate = QDateTime( qd, fromTime ); | 557 | QDateTime startPrintDate = QDateTime( qd, fromTime ); |
558 | QDateTime endPrintDate = QDateTime( qd, toTime ); | 558 | QDateTime endPrintDate = QDateTime( qd, toTime ); |
559 | 559 | ||
560 | // Calculate horizontal positions and widths of events taking into account | 560 | // Calculate horizontal positions and widths of events taking into account |
561 | // overlapping events | 561 | // overlapping events |
562 | 562 | ||
563 | QPtrList<KOrg::CellItem> cells; | 563 | QPtrList<KOrg::CellItem> cells; |
564 | cells.setAutoDelete( true ); | 564 | cells.setAutoDelete( true ); |
565 | 565 | ||
566 | Event::List::ConstIterator itEvents; | 566 | Event::List::ConstIterator itEvents; |
567 | for( itEvents = events.begin(); itEvents != events.end(); ++itEvents ) { | 567 | for( itEvents = events.begin(); itEvents != events.end(); ++itEvents ) { |
568 | cells.append( new PrintCellItem( *itEvents, qd ) ); | 568 | cells.append( new PrintCellItem( *itEvents, qd ) ); |
569 | } | 569 | } |
570 | 570 | ||
571 | QPtrListIterator<KOrg::CellItem> it1( cells ); | 571 | QPtrListIterator<KOrg::CellItem> it1( cells ); |
572 | for( it1.toFirst(); it1.current(); ++it1 ) { | 572 | for( it1.toFirst(); it1.current(); ++it1 ) { |
573 | KOrg::CellItem *placeItem = it1.current(); | 573 | KOrg::CellItem *placeItem = it1.current(); |
574 | 574 | ||
575 | KOrg::CellItem::placeItem( cells, placeItem ); | 575 | KOrg::CellItem::placeItem( cells, placeItem ); |
576 | } | 576 | } |
577 | 577 | ||
578 | QPen oldPen = p.pen(); | 578 | QPen oldPen = p.pen(); |
579 | QColor oldBgColor = p.backgroundColor(); | 579 | QColor oldBgColor = p.backgroundColor(); |
580 | QBrush oldBrush = p.brush(); | 580 | QBrush oldBrush = p.brush(); |
581 | 581 | ||
582 | p.setFont( QFont( "helvetica", 10 ) ); | 582 | p.setFont( QFont( "helvetica", 10 ) ); |
583 | //p.setBrush( QBrush( Dense7Pattern ) ); | 583 | //p.setBrush( QBrush( Dense7Pattern ) ); |
584 | 584 | ||
585 | for( it1.toFirst(); it1.current(); ++it1 ) { | 585 | for( it1.toFirst(); it1.current(); ++it1 ) { |
586 | PrintCellItem *placeItem = static_cast<PrintCellItem *>( it1.current() ); | 586 | PrintCellItem *placeItem = static_cast<PrintCellItem *>( it1.current() ); |
587 | 587 | ||
588 | drawAgendaItem( placeItem, p, qd, startPrintDate, endPrintDate, minlen, x, | 588 | drawAgendaItem( placeItem, p, qd, startPrintDate, endPrintDate, minlen, x, |
589 | y, width ); | 589 | y, width ); |
590 | 590 | ||
591 | p.setBrush( oldBrush ); | 591 | p.setBrush( oldBrush ); |
592 | p.setPen( oldPen ); | 592 | p.setPen( oldPen ); |
593 | p.setBackgroundColor( oldBgColor ); | 593 | p.setBackgroundColor( oldBgColor ); |
594 | } | 594 | } |
595 | 595 | ||
596 | p.setBrush( QBrush( NoBrush ) ); | 596 | p.setBrush( QBrush( NoBrush ) ); |
597 | } | 597 | } |
598 | 598 | ||
599 | 599 | ||
600 | void CalPrintBase::drawAgendaItem( PrintCellItem *item, QPainter &p, | 600 | void CalPrintBase::drawAgendaItem( PrintCellItem *item, QPainter &p, |
601 | const QDate &qd, | 601 | const QDate &qd, |
602 | const QDateTime &startPrintDate, | 602 | const QDateTime &startPrintDate, |
603 | const QDateTime &endPrintDate, | 603 | const QDateTime &endPrintDate, |
604 | float minlen, int x, int y, int width ) | 604 | float minlen, int x, int y, int width ) |
605 | { | 605 | { |
606 | Event *event = item->event(); | 606 | Event *event = item->event(); |
607 | 607 | ||
608 | // set the colors according to the categories | 608 | // set the colors according to the categories |
609 | if ( mUseColors ) setCategoryColors( p, event ); | 609 | if ( mUseColors ) setCategoryColors( p, event ); |
610 | else p.setBrush( Qt::white ); | 610 | else p.setBrush( Qt::white ); |
611 | // start/end of print area for event | 611 | // start/end of print area for event |
612 | QDateTime startTime = event->dtStart(); | 612 | QDateTime startTime = event->dtStart(); |
613 | QDateTime endTime = event->dtEnd(); | 613 | QDateTime endTime = event->dtEnd(); |
614 | if ( event->doesRecur() ) { | 614 | if ( event->doesRecur() ) { |
615 | startTime.setDate( qd ); | 615 | startTime.setDate( qd ); |
616 | endTime.setDate( qd ); | 616 | endTime.setDate( qd ); |
617 | } | 617 | } |
618 | if ( ( startTime < endPrintDate && endTime > startPrintDate ) || | 618 | if ( ( startTime < endPrintDate && endTime > startPrintDate ) || |
619 | ( endTime > startPrintDate && startTime < endPrintDate ) ) { | 619 | ( endTime > startPrintDate && startTime < endPrintDate ) ) { |
620 | if ( startTime < startPrintDate ) startTime = startPrintDate; | 620 | if ( startTime < startPrintDate ) startTime = startPrintDate; |
621 | if ( endTime > endPrintDate ) endTime = endPrintDate; | 621 | if ( endTime > endPrintDate ) endTime = endPrintDate; |
622 | int eventLength = int( startTime.secsTo( endTime ) / 60. * minlen ); | 622 | int eventLength = int( startTime.secsTo( endTime ) / 60. * minlen ); |
623 | int currentyPos = int( y + startPrintDate.secsTo( startTime ) * | 623 | int currentyPos = int( y + startPrintDate.secsTo( startTime ) * |
624 | minlen / 60. ); | 624 | minlen / 60. ); |
625 | int currentWidth = width / item->subCells(); | 625 | int currentWidth = width / item->subCells(); |
626 | int currentX = x + item->subCell() * currentWidth; | 626 | int currentX = x + item->subCell() * currentWidth; |
627 | QString text = KGlobal::locale()->formatTime(event->dtStart().time())+ | 627 | QString text = KGlobal::locale()->formatTime(event->dtStart().time())+ |
628 | "-"+KGlobal::locale()->formatTime(event->dtEnd().time())+ | 628 | "-"+KGlobal::locale()->formatTime(event->dtEnd().time())+ |
629 | " "+event->summary(); | 629 | " "+event->summary(); |
630 | if ( !event->location().isEmpty() ) | 630 | if ( !event->location().isEmpty() ) |
631 | text += " (" +event->location()+")"; | 631 | text += " (" +event->location()+")"; |
632 | // p.save(); | 632 | // p.save(); |
633 | QPen pe = p.pen(); | 633 | QPen pe = p.pen(); |
634 | pe.setWidth( 2 ); | 634 | pe.setWidth( 2 ); |
635 | p.setPen( pe ); | 635 | p.setPen( pe ); |
636 | p.drawRect( currentX, currentyPos+1, currentWidth+1, eventLength+1 ); | 636 | p.drawRect( currentX, currentyPos+1, currentWidth+1, eventLength+1 ); |
637 | p.drawText( currentX+3, currentyPos+2, currentWidth-5, eventLength-3, | 637 | p.drawText( currentX+3, currentyPos+2, currentWidth-5, eventLength-3, |
638 | AlignLeft | AlignTop | AlignJustify | WordBreak, | 638 | AlignLeft | AlignTop | AlignJustify | WordBreak, |
639 | text); | 639 | text); |
640 | // p.restore(); | 640 | // p.restore(); |
641 | } | 641 | } |
642 | } | 642 | } |
643 | 643 | ||
644 | void CalPrintBase::drawDayBox(QPainter &p, const QDate &qd, | 644 | void CalPrintBase::drawDayBox(QPainter &p, const QDate &qd, |
645 | int x, int y, int width, int height, | 645 | int x, int y, int width, int height, |
646 | bool fullDate) | 646 | bool fullDate) |
647 | { | 647 | { |
648 | QString dayNumStr; | 648 | QString dayNumStr; |
649 | QString ampm; | 649 | QString ampm; |
650 | const KLocale*local = KGlobal::locale(); | 650 | const KLocale*local = KGlobal::locale(); |
651 | 651 | ||
652 | 652 | ||
653 | // This has to be localized | 653 | // This has to be localized |
654 | if (fullDate) { | 654 | if (fullDate) { |
655 | /*int index; | 655 | dayNumStr = local->formatDate(qd); |
656 | dayNumStr= qd.toString(); | ||
657 | index = dayNumStr.find(' '); | ||
658 | dayNumStr.remove(0, index); | ||
659 | index = dayNumStr.findRev(' '); | ||
660 | dayNumStr.truncate(index);*/ | ||
661 | |||
662 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); | ||
663 | dayNumStr = i18n("weekday month date", "%1 %2 %3") | ||
664 | .arg( calSys->weekDayName( qd ) ) | ||
665 | .arg( calSys->monthName( qd ) ) | ||
666 | .arg( qd.day() ); | ||
667 | // dayNumStr = local->formatDate(qd); | ||
668 | } else { | 656 | } else { |
669 | dayNumStr = QString::number( qd.day() ); | 657 | dayNumStr = QString::number( qd.day() ); |
670 | } | 658 | } |
671 | 659 | ||
672 | p.eraseRect( x, y, width, height ); | 660 | p.eraseRect( x, y, width, height ); |
673 | p.drawRect( x, y, width, height ); | 661 | p.drawRect( x, y, width, height ); |
674 | // p.fillRect( x+1, y+1, width-2,height, QBrush(Dense7Pattern) ); | 662 | // p.fillRect( x+1, y+1, width-2,height, QBrush(Dense7Pattern) ); |
675 | p.drawRect( x, y, width, mSubHeaderHeight ); | 663 | p.drawRect( x, y, width, mSubHeaderHeight ); |
676 | //p.fillRect( x+1, y+1, width-2, mSubHeaderHeight-2, QBrush(Dense7Pattern) ); | 664 | //p.fillRect( x+1, y+1, width-2, mSubHeaderHeight-2, QBrush(Dense7Pattern) ); |
677 | QString hstring; | 665 | QString hstring; |
678 | #ifndef KORG_NOPLUGINS | 666 | #ifndef KORG_NOPLUGINS |
679 | hstring=KOCore::self()->holiday(qd); | 667 | hstring=KOCore::self()->holiday(qd); |
680 | #endif | 668 | #endif |
681 | 669 | ||
682 | if (!hstring.isEmpty()) { | 670 | if (!hstring.isEmpty()) { |
683 | p.setFont( QFont( "helvetica", 8, QFont::Bold, true ) ); | 671 | p.setFont( QFont( "helvetica", 8, QFont::Bold, true ) ); |
684 | 672 | ||
685 | p.drawText( x+5, y, width-25, mSubHeaderHeight, AlignLeft | AlignVCenter, | 673 | p.drawText( x+5, y, width-25, mSubHeaderHeight, AlignLeft | AlignVCenter, |
686 | hstring ); | 674 | hstring ); |
687 | } | 675 | } |
688 | p.setFont(QFont("helvetica", 10, QFont::Bold)); | 676 | p.setFont(QFont("helvetica", 10, QFont::Bold)); |
677 | if ( fullDate) { | ||
678 | // use short date format, if long date is too long | ||
679 | QFontMetrics fm ( p.font() ); | ||
680 | if ( fm.width( dayNumStr ) > width -10 ) | ||
681 | dayNumStr = local->formatDate(qd, true); | ||
682 | } | ||
689 | p.drawText(x+5, y, width-10, mSubHeaderHeight, AlignRight | AlignVCenter, | 683 | p.drawText(x+5, y, width-10, mSubHeaderHeight, AlignRight | AlignVCenter, |
690 | dayNumStr); | 684 | dayNumStr); |
691 | Event::List eventList; | 685 | Event::List eventList; |
692 | eventList.fill( mCalendar->events( qd, true )); | 686 | eventList.fill( mCalendar->events( qd, true )); |
693 | Todo::List todos; | 687 | Todo::List todos; |
694 | todos.fill( mCalendar->todos( qd )); | 688 | todos.fill( mCalendar->todos( qd )); |
695 | QString outStr; | 689 | QString outStr; |
696 | p.setFont( QFont( "helvetica", 8 ) ); | 690 | p.setFont( QFont( "helvetica", 8 ) ); |
697 | int lineSpacing = p.fontMetrics().lineSpacing(); | 691 | int lineSpacing = p.fontMetrics().lineSpacing(); |
698 | 692 | ||
699 | int textY=mSubHeaderHeight+3; // gives the relative y-coord of the next printed entry | 693 | int textY=mSubHeaderHeight+3; // gives the relative y-coord of the next printed entry |
700 | Event::List::ConstIterator it; | 694 | Event::List::ConstIterator it; |
701 | int entryCount = eventList.count() +todos.count(); | 695 | int entryCount = eventList.count() +todos.count(); |
702 | if ( p.fontMetrics().lineSpacing()* entryCount > height-textY ) { | 696 | if ( p.fontMetrics().lineSpacing()* entryCount > height-textY ) { |
703 | if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY ) { | 697 | if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY ) { |
704 | p.setFont( QFont( "helvetica", 7 ) ); | 698 | p.setFont( QFont( "helvetica", 7 ) ); |
705 | if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY ) | 699 | if ( (p.fontMetrics().lineSpacing()-1) * entryCount > height-textY ) |
706 | p.setFont( QFont( "helvetica", 6 ) ); | 700 | p.setFont( QFont( "helvetica", 6 ) ); |
707 | } | 701 | } |
708 | lineSpacing = p.fontMetrics().lineSpacing()-1; | 702 | lineSpacing = p.fontMetrics().lineSpacing()-1; |
709 | } | 703 | } |
710 | // qDebug("fm %d %d %d ",p.fontMetrics().height(), eventList.count() , height-textY ); | 704 | // qDebug("fm %d %d %d ",p.fontMetrics().height(), eventList.count() , height-textY ); |
711 | for( it = eventList.begin(); it != eventList.end() && textY<height; ++it ) { | 705 | for( it = eventList.begin(); it != eventList.end() && textY<height; ++it ) { |
712 | Event *currEvent = *it; | 706 | Event *currEvent = *it; |
713 | if (currEvent->doesFloat() || currEvent->isMultiDay()) | 707 | if (currEvent->doesFloat() || currEvent->isMultiDay()) |
714 | outStr = currEvent->summary(); | 708 | outStr = currEvent->summary(); |
715 | 709 | ||
716 | else { | 710 | else { |
717 | if ( fullDate ) { | 711 | if ( fullDate ) { |
718 | outStr = KGlobal::locale()->formatTime( currEvent->dtStart().time())+ | 712 | outStr = KGlobal::locale()->formatTime( currEvent->dtStart().time())+ |
719 | "-"+KGlobal::locale()->formatTime( currEvent->dtEnd().time())+ | 713 | "-"+KGlobal::locale()->formatTime( currEvent->dtEnd().time())+ |
720 | " "+ currEvent->summary(); | 714 | " "+ currEvent->summary(); |
721 | if ( ! currEvent->location().isEmpty() ) | 715 | if ( ! currEvent->location().isEmpty() ) |
722 | outStr += " (" + currEvent->location()+")"; | 716 | outStr += " (" + currEvent->location()+")"; |
723 | } else { | 717 | } else { |
724 | QTime t1 = currEvent->dtStart().time(); | 718 | QTime t1 = currEvent->dtStart().time(); |
725 | 719 | ||
726 | outStr = local->formatTime(t1); | 720 | outStr = local->formatTime(t1); |
727 | outStr += " " + currEvent->summary(); | 721 | outStr += " " + currEvent->summary(); |
728 | } | 722 | } |
729 | 723 | ||
730 | } // doesFloat | 724 | } // doesFloat |
731 | 725 | ||
732 | p.drawText(x+5, y+textY, width-10, lineSpacing, | 726 | p.drawText(x+5, y+textY, width-10, lineSpacing, |
733 | AlignLeft|AlignBottom, outStr); | 727 | AlignLeft|AlignBottom, outStr); |
734 | textY+=lineSpacing; | 728 | textY+=lineSpacing; |
735 | } | 729 | } |
736 | 730 | ||
737 | if ( textY<height ) { | 731 | if ( textY<height ) { |
738 | 732 | ||
739 | Todo::List::ConstIterator it2; | 733 | Todo::List::ConstIterator it2; |
740 | for( it2 = todos.begin(); it2 != todos.end() && textY<height; ++it2 ) { | 734 | for( it2 = todos.begin(); it2 != todos.end() && textY<height; ++it2 ) { |
741 | Todo *todo = *it2; | 735 | Todo *todo = *it2; |
742 | QString text; | 736 | QString text; |
743 | if (todo->hasDueDate()) { | 737 | if (todo->hasDueDate()) { |
744 | if (!todo->doesFloat()) { | 738 | if (!todo->doesFloat()) { |
745 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); | 739 | text += KGlobal::locale()->formatTime(todo->dtDue().time()); |
746 | text += " "; | 740 | text += " "; |
747 | } | 741 | } |
748 | } | 742 | } |
749 | text += i18n("To-Do: %1").arg(todo->summary()); | 743 | text += i18n("To-Do: %1").arg(todo->summary()); |
750 | 744 | ||
751 | p.drawText(x+5, y+textY, width-10, lineSpacing, | 745 | p.drawText(x+5, y+textY, width-10, lineSpacing, |
752 | AlignLeft|AlignBottom, text); | 746 | AlignLeft|AlignBottom, text); |
753 | textY+=lineSpacing; | 747 | textY+=lineSpacing; |
754 | } | 748 | } |
755 | } | 749 | } |
756 | } | 750 | } |
757 | 751 | ||
758 | 752 | ||
759 | /////////////////////////////////////////////////////////////////////////////// | 753 | /////////////////////////////////////////////////////////////////////////////// |
760 | 754 | ||
761 | void CalPrintBase::drawWeek(QPainter &p, const QDate &qd, | 755 | void CalPrintBase::drawWeek(QPainter &p, const QDate &qd, |
762 | int x, int y, int width, int height) | 756 | int x, int y, int width, int height) |
763 | { | 757 | { |
764 | QDate weekDate = qd; | 758 | QDate weekDate = qd; |
765 | bool portrait = ( mPrinter->orientation() == KPrinter::Portrait ); | 759 | bool portrait = ( mPrinter->orientation() == KPrinter::Portrait ); |
766 | int cellWidth, cellHeight; | 760 | int cellWidth, cellHeight; |
767 | int vcells; | 761 | int vcells; |
768 | if (portrait) { | 762 | if (portrait) { |
769 | cellWidth = width/2; | 763 | cellWidth = width/2; |
770 | vcells=3; | 764 | vcells=3; |
771 | } else { | 765 | } else { |
772 | cellWidth = width/6; | 766 | cellWidth = width/6; |
773 | vcells=1; | 767 | vcells=1; |
774 | } | 768 | } |
775 | cellHeight = height/vcells; | 769 | cellHeight = height/vcells; |
776 | 770 | ||
777 | // correct begin of week | 771 | // correct begin of week |
778 | int weekdayCol = weekdayColumn( qd.dayOfWeek() ); | 772 | int weekdayCol = weekdayColumn( qd.dayOfWeek() ); |
779 | weekDate = qd.addDays( -weekdayCol ); | 773 | weekDate = qd.addDays( -weekdayCol ); |
780 | 774 | ||
781 | for (int i = 0; i < 7; i++, weekDate = weekDate.addDays(1)) { | 775 | for (int i = 0; i < 7; i++, weekDate = weekDate.addDays(1)) { |
782 | if (i<5) { | 776 | if (i<5) { |
783 | drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells), | 777 | drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells), |
784 | cellWidth, cellHeight, true); | 778 | cellWidth, cellHeight, true); |
785 | } else if (i==5) { | 779 | } else if (i==5) { |
786 | drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells), | 780 | drawDayBox(p, weekDate, x+cellWidth*(int)(i/vcells), y+cellHeight*(i%vcells), |
787 | cellWidth, cellHeight/2, true); | 781 | cellWidth, cellHeight/2, true); |
788 | } else if (i==6) { | 782 | } else if (i==6) { |
789 | drawDayBox(p, weekDate, x+cellWidth*(int)((i-1)/vcells), | 783 | drawDayBox(p, weekDate, x+cellWidth*(int)((i-1)/vcells), |
790 | y+cellHeight*((i-1)%vcells)+cellHeight/2, cellWidth, cellHeight/2, true); | 784 | y+cellHeight*((i-1)%vcells)+cellHeight/2, cellWidth, cellHeight/2, true); |
791 | } | 785 | } |
792 | } // for i through all weekdays | 786 | } // for i through all weekdays |
793 | } | 787 | } |
794 | 788 | ||
795 | 789 | ||
796 | void CalPrintBase::drawTimeTable(QPainter &p, | 790 | void CalPrintBase::drawTimeTable(QPainter &p, |
797 | const QDate &fromDate, const QDate &toDate, | 791 | const QDate &fromDate, const QDate &toDate, |
798 | QTime &fromTime, QTime &toTime, | 792 | QTime &fromTime, QTime &toTime, |
799 | int x, int y, int width, int height) | 793 | int x, int y, int width, int height) |
800 | { | 794 | { |
801 | // timeline is 1.5 hours: | 795 | // timeline is 1.5 hours: |
802 | int alldayHeight = (int)( 3600.*height/(fromTime.secsTo(toTime)+3600.) ); | 796 | int alldayHeight = (int)( 3600.*height/(fromTime.secsTo(toTime)+3600.) ); |
803 | int timelineWidth = 60; | 797 | int timelineWidth = 60; |
804 | int cellWidth = (int)( (width-timelineWidth)/(fromDate.daysTo(toDate)+1) ); | 798 | int cellWidth = (int)( (width-timelineWidth)/(fromDate.daysTo(toDate)+1) ); |
805 | int currY=y; | 799 | int currY=y; |
806 | int currX=x; | 800 | int currX=x; |
807 | 801 | ||
808 | drawDaysOfWeek( p, fromDate, toDate, x+timelineWidth, currY, width-timelineWidth, mSubHeaderHeight); | 802 | drawDaysOfWeek( p, fromDate, toDate, x+timelineWidth, currY, width-timelineWidth, mSubHeaderHeight); |
809 | currY+=mSubHeaderHeight; | 803 | currY+=mSubHeaderHeight; |
810 | drawTimeLine( p, fromTime, toTime, x, currY+alldayHeight, | 804 | drawTimeLine( p, fromTime, toTime, x, currY+alldayHeight, |
811 | timelineWidth, height-mSubHeaderHeight-alldayHeight ); | 805 | timelineWidth, height-mSubHeaderHeight-alldayHeight ); |
812 | 806 | ||
813 | currX=x+timelineWidth; | 807 | currX=x+timelineWidth; |
814 | // draw each day | 808 | // draw each day |
815 | QDate curDate(fromDate); | 809 | QDate curDate(fromDate); |
816 | while (curDate<=toDate) {Event::List eventList; | 810 | while (curDate<=toDate) {Event::List eventList; |
817 | eventList.fill( mCalendar->events(curDate, true)); | 811 | eventList.fill( mCalendar->events(curDate, true)); |
818 | drawAllDayBox( p, eventList, curDate, false, currX, currY, cellWidth, alldayHeight); | 812 | drawAllDayBox( p, eventList, curDate, false, currX, currY, cellWidth, alldayHeight); |
819 | drawAgendaDayBox( p, eventList, curDate, false, fromTime, toTime, currX, | 813 | drawAgendaDayBox( p, eventList, curDate, false, fromTime, toTime, currX, |
820 | currY+alldayHeight, cellWidth, height-mSubHeaderHeight-alldayHeight ); | 814 | currY+alldayHeight, cellWidth, height-mSubHeaderHeight-alldayHeight ); |
821 | currX+=cellWidth; | 815 | currX+=cellWidth; |
822 | curDate=curDate.addDays(1); | 816 | curDate=curDate.addDays(1); |
823 | } | 817 | } |
824 | 818 | ||
825 | } | 819 | } |
826 | 820 | ||
827 | 821 | ||
828 | /////////////////////////////////////////////////////////////////////////////// | 822 | /////////////////////////////////////////////////////////////////////////////// |
829 | 823 | ||
830 | void CalPrintBase::drawMonth(QPainter &p, const QDate &qd, bool weeknumbers, | 824 | void CalPrintBase::drawMonth(QPainter &p, const QDate &qd, bool weeknumbers, |
831 | int x, int y, int width, int height) | 825 | int x, int y, int width, int height) |
832 | { | 826 | { |
833 | 827 | ||
834 | int yoffset = mSubHeaderHeight; | 828 | int yoffset = mSubHeaderHeight; |
835 | int xoffset = 0; | 829 | int xoffset = 0; |
836 | 830 | ||
837 | QDate monthDate(QDate(qd.year(), qd.month(), 1)); | 831 | QDate monthDate(QDate(qd.year(), qd.month(), 1)); |
838 | QDate monthFirst(monthDate); | 832 | QDate monthFirst(monthDate); |
839 | QDate monthLast(monthDate.addMonths(1).addDays(-1)); | 833 | QDate monthLast(monthDate.addMonths(1).addDays(-1)); |
840 | 834 | ||
841 | 835 | ||
842 | int weekdayCol = weekdayColumn( monthDate.dayOfWeek() ); | 836 | int weekdayCol = weekdayColumn( monthDate.dayOfWeek() ); |
843 | monthDate = monthDate.addDays(-weekdayCol); | 837 | monthDate = monthDate.addDays(-weekdayCol); |
844 | 838 | ||
845 | int rows=(weekdayCol + qd.daysInMonth() - 1)/7 +1; | 839 | int rows=(weekdayCol + qd.daysInMonth() - 1)/7 +1; |
846 | int cellHeight = (height-yoffset) / rows; | 840 | int cellHeight = (height-yoffset) / rows; |
847 | 841 | ||
848 | if (weeknumbers) { | 842 | if (weeknumbers) { |
849 | QFont oldFont(p.font()); | 843 | QFont oldFont(p.font()); |
850 | QFont newFont(p.font()); | 844 | QFont newFont(p.font()); |
851 | newFont.setPointSize(7); | 845 | newFont.setPointSize(7); |
852 | p.setFont(newFont); | 846 | p.setFont(newFont); |
853 | xoffset += 18; | 847 | xoffset += 18; |
854 | QDate weekDate(monthDate); | 848 | QDate weekDate(monthDate); |
855 | for (int row = 0; row<rows; row++) { | 849 | for (int row = 0; row<rows; row++) { |
856 | int calWeek = weekDate.weekNumber(); | 850 | int calWeek = weekDate.weekNumber(); |
857 | QRect rc(x, y+yoffset+cellHeight*row, xoffset-1, cellHeight); | 851 | QRect rc(x, y+yoffset+cellHeight*row, xoffset-1, cellHeight); |
858 | p.drawText( rc, AlignRight|AlignVCenter, QString::number(calWeek) ); | 852 | p.drawText( rc, AlignRight|AlignVCenter, QString::number(calWeek) ); |
859 | weekDate = weekDate.addDays(7); | 853 | weekDate = weekDate.addDays(7); |
860 | } | 854 | } |
861 | p.setFont(oldFont); | 855 | p.setFont(oldFont); |
862 | } | 856 | } |
863 | 857 | ||
864 | drawDaysOfWeek( p, monthDate, monthDate.addDays(6), x+xoffset, y, width-xoffset, mSubHeaderHeight ); | 858 | drawDaysOfWeek( p, monthDate, monthDate.addDays(6), x+xoffset, y, width-xoffset, mSubHeaderHeight ); |
865 | int cellWidth = (width-xoffset) / 7; | 859 | int cellWidth = (width-xoffset) / 7; |
866 | 860 | ||
867 | QColor back = p.backgroundColor(); | 861 | QColor back = p.backgroundColor(); |
868 | bool darkbg = false; | 862 | bool darkbg = false; |
869 | for (int row = 0; row < rows; row++) { | 863 | for (int row = 0; row < rows; row++) { |
870 | for (int col = 0; col < 7; col++) { | 864 | for (int col = 0; col < 7; col++) { |
871 | // show days from previous/next month with a grayed background | 865 | // show days from previous/next month with a grayed background |
872 | if ( (monthDate < monthFirst) || (monthDate > monthLast) ) { | 866 | if ( (monthDate < monthFirst) || (monthDate > monthLast) ) { |
873 | p.setBackgroundColor( QColor( 240, 240, 240) ); | 867 | p.setBackgroundColor( QColor( 240, 240, 240) ); |
874 | darkbg = true; | 868 | darkbg = true; |
875 | } | 869 | } |
876 | drawDayBox(p, monthDate, x+xoffset+col*cellWidth, y+yoffset+row*cellHeight, cellWidth, cellHeight); | 870 | drawDayBox(p, monthDate, x+xoffset+col*cellWidth, y+yoffset+row*cellHeight, cellWidth, cellHeight); |
877 | if ( darkbg ) { | 871 | if ( darkbg ) { |
878 | p.setBackgroundColor( back ); | 872 | p.setBackgroundColor( back ); |
879 | darkbg = false; | 873 | darkbg = false; |
880 | } | 874 | } |
881 | monthDate = monthDate.addDays(1); | 875 | monthDate = monthDate.addDays(1); |
882 | } | 876 | } |
883 | } | 877 | } |
884 | } | 878 | } |
885 | 879 | ||
886 | 880 | ||
887 | /////////////////////////////////////////////////////////////////////////////// | 881 | /////////////////////////////////////////////////////////////////////////////// |
888 | 882 | ||
889 | void CalPrintBase::drawTodo( bool completed, int &count, Todo * item, QPainter &p, bool connectSubTodos, | 883 | void CalPrintBase::drawTodo( bool completed, int &count, Todo * item, QPainter &p, bool connectSubTodos, |
890 | bool desc, int pospriority, int possummary, int posDueDt, int level, | 884 | bool desc, int pospriority, int possummary, int posDueDt, int level, |
891 | int x, int &y, int width, int &height, int pageHeight, | 885 | int x, int &y, int width, int &height, int pageHeight, |
892 | TodoParentStart *r ) | 886 | TodoParentStart *r ) |
893 | { | 887 | { |
894 | if ( !completed && item->isCompleted() ) | 888 | if ( !completed && item->isCompleted() ) |
895 | return; | 889 | return; |
896 | QString outStr; | 890 | QString outStr; |
897 | // int fontHeight = 10; | 891 | // int fontHeight = 10; |
898 | const KLocale *local = KGlobal::locale(); | 892 | const KLocale *local = KGlobal::locale(); |
899 | int priority=item->priority(); | 893 | int priority=item->priority(); |
900 | int posdue=posDueDt; | 894 | int posdue=posDueDt; |
901 | if (posdue<0) posdue=x+width; | 895 | if (posdue<0) posdue=x+width; |
902 | QRect rect; | 896 | QRect rect; |
903 | TodoParentStart startpt; | 897 | TodoParentStart startpt; |
904 | // This list keeps all starting points of the parent todos so the connection | 898 | // This list keeps all starting points of the parent todos so the connection |
905 | // lines of the tree can easily be drawn (needed if a new page is started) | 899 | // lines of the tree can easily be drawn (needed if a new page is started) |
906 | static QPtrList<TodoParentStart> startPoints; | 900 | static QPtrList<TodoParentStart> startPoints; |
907 | if (level<1) { | 901 | if (level<1) { |
908 | startPoints.clear(); | 902 | startPoints.clear(); |
909 | } | 903 | } |
910 | 904 | ||
911 | // size of item | 905 | // size of item |
912 | outStr=item->summary(); | 906 | outStr=item->summary(); |
913 | if ( ! item->location().isEmpty() ) | 907 | if ( ! item->location().isEmpty() ) |
914 | outStr += " ("+item->location()+")"; | 908 | outStr += " ("+item->location()+")"; |
915 | if ( item->hasDueDate() && posDueDt>=0 ) { | 909 | if ( item->hasDueDate() && posDueDt>=0 ) { |
916 | outStr += " [" +local->formatDate(item->dtDue().date(),true)+"]"; | 910 | outStr += " [" +local->formatDate(item->dtDue().date(),true)+"]"; |
917 | } | 911 | } |
918 | int left = possummary+(level*10); | 912 | int left = possummary+(level*10); |
919 | rect = p.boundingRect(left, y, (posdue-left-5),-1, WordBreak, outStr); | 913 | rect = p.boundingRect(left, y, (posdue-left-5),-1, WordBreak, outStr); |
920 | //qDebug("bottom1 %d ", rect.bottom() ); | 914 | //qDebug("bottom1 %d ", rect.bottom() ); |
921 | if ( !item->description().isEmpty() && desc ) { | 915 | if ( !item->description().isEmpty() && desc ) { |
922 | outStr = item->description(); | 916 | outStr = item->description(); |
923 | rect = p.boundingRect( left+20, rect.bottom()+5, width-(left+10-x), -1, | 917 | rect = p.boundingRect( left+20, rect.bottom()+5, width-(left+10-x), -1, |
924 | WordBreak, outStr ); | 918 | WordBreak, outStr ); |
925 | } | 919 | } |
926 | //qDebug("bottom2 %d y+h %d y %d ph %d", rect.bottom(), y+height, y , pageHeight ); | 920 | //qDebug("bottom2 %d y+h %d y %d ph %d", rect.bottom(), y+height, y , pageHeight ); |
927 | // if too big make new page | 921 | // if too big make new page |
928 | if ( rect.bottom() > y+height) { | 922 | if ( rect.bottom() > y+height) { |
929 | // first draw the connection lines from parent todos: | 923 | // first draw the connection lines from parent todos: |
930 | if (level > 0 && connectSubTodos) { | 924 | if (level > 0 && connectSubTodos) { |
931 | TodoParentStart *rct; | 925 | TodoParentStart *rct; |
932 | for ( rct = startPoints.first(); rct; rct = startPoints.next() ) { | 926 | for ( rct = startPoints.first(); rct; rct = startPoints.next() ) { |
933 | int start; | 927 | int start; |
934 | int center = rct->mRect.left() + (rct->mRect.width()/2); | 928 | int center = rct->mRect.left() + (rct->mRect.width()/2); |
935 | int to = p.viewport().bottom(); | 929 | int to = p.viewport().bottom(); |
936 | 930 | ||
937 | // draw either from start point of parent or from top of the page | 931 | // draw either from start point of parent or from top of the page |
938 | if (rct->mSamePage) | 932 | if (rct->mSamePage) |
939 | start = rct->mRect.bottom() + 1; | 933 | start = rct->mRect.bottom() + 1; |
940 | else | 934 | else |
941 | start = p.viewport().top(); | 935 | start = p.viewport().top(); |
942 | p.moveTo( center, start ); | 936 | p.moveTo( center, start ); |
943 | p.lineTo( center, to ); | 937 | p.lineTo( center, to ); |
944 | rct->mSamePage=false; | 938 | rct->mSamePage=false; |
945 | } | 939 | } |
946 | } | 940 | } |
947 | y=0; | 941 | y=0; |
948 | height=pageHeight-y; | 942 | height=pageHeight-y; |
949 | mPrinter->newPage(); | 943 | mPrinter->newPage(); |
950 | } | 944 | } |
951 | 945 | ||
952 | // If this is a sub-item, r will not be 0, and we want the LH side of the priority line up | 946 | // If this is a sub-item, r will not be 0, and we want the LH side of the priority line up |
953 | //to the RH side of the parent item's priority | 947 | //to the RH side of the parent item's priority |
954 | if (r && pospriority >= 0 ) { | 948 | if (r && pospriority >= 0 ) { |
955 | pospriority = r->mRect.right() + 1; | 949 | pospriority = r->mRect.right() + 1; |
956 | } | 950 | } |
957 | 951 | ||
958 | // Priority | 952 | // Priority |
959 | outStr.setNum(priority); | 953 | outStr.setNum(priority); |
960 | rect = p.boundingRect(pospriority, y + 10, 5, -1, AlignCenter, outStr); | 954 | rect = p.boundingRect(pospriority, y + 10, 5, -1, AlignCenter, outStr); |
961 | // Make it a more reasonable size | 955 | // Make it a more reasonable size |
962 | rect.setWidth(19); | 956 | rect.setWidth(19); |
963 | rect.setHeight(19); | 957 | rect.setHeight(19); |
964 | if ( priority > 0 && pospriority>=0 ) { | 958 | if ( priority > 0 && pospriority>=0 ) { |
965 | p.drawText(rect, AlignCenter, outStr); | 959 | p.drawText(rect, AlignCenter, outStr); |
966 | p.drawRect(rect); | 960 | p.drawRect(rect); |
967 | // cross out the rectangle for completed items | 961 | // cross out the rectangle for completed items |
968 | if ( item->isCompleted() ) { | 962 | if ( item->isCompleted() ) { |
969 | p.drawLine( rect.topLeft(), rect.bottomRight() ); | 963 | p.drawLine( rect.topLeft(), rect.bottomRight() ); |
970 | p.drawLine( rect.topRight(), rect.bottomLeft() ); | 964 | p.drawLine( rect.topRight(), rect.bottomLeft() ); |
971 | } else if (item->cancelled() ) { | 965 | } else if (item->cancelled() ) { |
972 | QPen pen = p.pen(); | 966 | QPen pen = p.pen(); |
973 | p.setPen ( QPen ( black, 2) ); | 967 | p.setPen ( QPen ( black, 2) ); |
974 | p.drawLine( rect.left()+2,rect.top()+rect.height()/2, rect.right()-2, +rect.top()+rect.height()/2 ); | 968 | p.drawLine( rect.left()+2,rect.top()+rect.height()/2, rect.right()-2, +rect.top()+rect.height()/2 ); |
975 | p.setPen( pen ); | 969 | p.setPen( pen ); |
976 | } | 970 | } |
977 | } | 971 | } |
978 | startpt.mRect = rect; //save for later | 972 | startpt.mRect = rect; //save for later |
979 | 973 | ||
980 | // Connect the dots | 974 | // Connect the dots |
981 | if (level > 0 && connectSubTodos) { | 975 | if (level > 0 && connectSubTodos) { |
982 | int bottom; | 976 | int bottom; |
983 | int center( r->mRect.left() + (r->mRect.width()/2)+1 ); | 977 | int center( r->mRect.left() + (r->mRect.width()/2)+1 ); |
984 | if (r->mSamePage ) | 978 | if (r->mSamePage ) |
985 | bottom = r->mRect.bottom();//lutz + 1; | 979 | bottom = r->mRect.bottom();//lutz + 1; |
986 | else | 980 | else |
987 | bottom = 0; | 981 | bottom = 0; |
988 | int to( rect.top() + (rect.height()/2)+1 ); | 982 | int to( rect.top() + (rect.height()/2)+1 ); |
989 | int endx( rect.left() ); | 983 | int endx( rect.left() ); |
990 | p.moveTo(center, bottom); | 984 | p.moveTo(center, bottom); |
991 | p.lineTo(center, to); | 985 | p.lineTo(center, to); |
992 | p.lineTo(endx, to); | 986 | p.lineTo(endx, to); |
993 | } | 987 | } |
994 | 988 | ||
995 | // if completed, use strike out font | 989 | // if completed, use strike out font |
996 | // LR does not work - font is underlined, not striked out | 990 | // LR does not work - font is underlined, not striked out |
997 | //QFont ft=p.font(); | 991 | //QFont ft=p.font(); |
998 | //ft.setStrikeOut( item->isCompleted() ); | 992 | //ft.setStrikeOut( item->isCompleted() ); |
999 | //p.setFont( ft ); | 993 | //p.setFont( ft ); |
1000 | // summary | 994 | // summary |
1001 | outStr=item->summary(); | 995 | outStr=item->summary(); |
1002 | if ( ! item->location().isEmpty() ) | 996 | if ( ! item->location().isEmpty() ) |
1003 | outStr += " ("+item->location()+")"; | 997 | outStr += " ("+item->location()+")"; |
1004 | if ( item->hasDueDate() && posDueDt>=0 ) { | 998 | if ( item->hasDueDate() && posDueDt>=0 ) { |
1005 | outStr += " [" +item->dtDueStr(true)+"]"; | 999 | outStr += " [" +item->dtDueStr(true)+"]"; |
1006 | } | 1000 | } |
1007 | rect = p.boundingRect( left, rect.top(), (posdue-(left + rect.width() + 5)), | 1001 | rect = p.boundingRect( left, rect.top(), (posdue-(left + rect.width() + 5)), |
1008 | -1, WordBreak, outStr); | 1002 | -1, WordBreak, outStr); |
1009 | QRect newrect; | 1003 | QRect newrect; |
1010 | p.drawText( rect, WordBreak, outStr, -1, &newrect ); | 1004 | p.drawText( rect, WordBreak, outStr, -1, &newrect ); |
1011 | //ft.setStrikeOut(false); | 1005 | //ft.setStrikeOut(false); |
1012 | // p.setFont(ft); | 1006 | // p.setFont(ft); |
1013 | 1007 | ||
1014 | // due | 1008 | // due |
1015 | // if ( item->hasDueDate() && posDueDt>=0 ) { | 1009 | // if ( item->hasDueDate() && posDueDt>=0 ) { |
1016 | // outStr = local->formatDate(item->dtDue().date(),true); | 1010 | // outStr = local->formatDate(item->dtDue().date(),true); |
1017 | // rect = p.boundingRect(posdue, y, x+width, -1, AlignTop|AlignLeft, outStr); | 1011 | // rect = p.boundingRect(posdue, y, x+width, -1, AlignTop|AlignLeft, outStr); |
1018 | // p.drawText(rect, AlignTop|AlignLeft, outStr); | 1012 | // p.drawText(rect, AlignTop|AlignLeft, outStr); |
1019 | // } | 1013 | // } |
1020 | 1014 | ||
1021 | if ( !item->description().isEmpty() && desc ) { | 1015 | if ( !item->description().isEmpty() && desc ) { |
1022 | y=newrect.bottom() + 5; | 1016 | y=newrect.bottom() + 5; |
1023 | outStr = item->description(); | 1017 | outStr = item->description(); |
1024 | rect = p.boundingRect( left+20, y, x+width-(left+10), -1, | 1018 | rect = p.boundingRect( left+20, y, x+width-(left+10), -1, |
1025 | WordBreak, outStr ); | 1019 | WordBreak, outStr ); |
1026 | p.drawText( rect, WordBreak, outStr, -1, &newrect ); | 1020 | p.drawText( rect, WordBreak, outStr, -1, &newrect ); |
1027 | } | 1021 | } |
1028 | 1022 | ||
1029 | // Set the new line position | 1023 | // Set the new line position |
1030 | y=newrect.bottom() + 10; //set the line position | 1024 | y=newrect.bottom() + 10; //set the line position |
1031 | 1025 | ||
1032 | // If the item has subitems, we need to call ourselves recursively | 1026 | // If the item has subitems, we need to call ourselves recursively |
1033 | Incidence::List l;l.fill( item->relations()); | 1027 | Incidence::List l;l.fill( item->relations()); |
1034 | Incidence::List::ConstIterator it; | 1028 | Incidence::List::ConstIterator it; |
1035 | startPoints.append( &startpt ); | 1029 | startPoints.append( &startpt ); |
1036 | for( it = l.begin(); it != l.end(); ++it ) { | 1030 | for( it = l.begin(); it != l.end(); ++it ) { |
1037 | count++; | 1031 | count++; |
1038 | drawTodo( completed, count, static_cast<Todo *>( *it ), p, connectSubTodos, | 1032 | drawTodo( completed, count, static_cast<Todo *>( *it ), p, connectSubTodos, |
1039 | desc, pospriority, possummary, posDueDt, level+1, | 1033 | desc, pospriority, possummary, posDueDt, level+1, |
1040 | x, y, width, height, pageHeight, &startpt); | 1034 | x, y, width, height, pageHeight, &startpt); |
1041 | } | 1035 | } |
1042 | startPoints.remove(&startpt); | 1036 | startPoints.remove(&startpt); |
1043 | } | 1037 | } |
1044 | 1038 | ||
1045 | int CalPrintBase::weekdayColumn( int weekday ) | 1039 | int CalPrintBase::weekdayColumn( int weekday ) |
1046 | { | 1040 | { |
1047 | return ( weekday + 7 - KGlobal::locale()->weekStartDay() ) % 7; | 1041 | return ( weekday + 7 - KGlobal::locale()->weekStartDay() ) % 7; |
1048 | } | 1042 | } |
1049 | 1043 | ||
1050 | void CalPrintBase::drawSplitWeek( QPainter &p, const QDate &fd, | 1044 | void CalPrintBase::drawSplitWeek( QPainter &p, const QDate &fd, |
1051 | const QDate &td ) | 1045 | const QDate &td ) |
1052 | { | 1046 | { |
1053 | QDate curDay, fromDay, toDay, curWeek, fromWeek, toWeek; | 1047 | QDate curDay, fromDay, toDay, curWeek, fromWeek, toWeek; |
1054 | 1048 | ||
1055 | mPrinter->setOrientation(KPrinter::Portrait); | 1049 | mPrinter->setOrientation(KPrinter::Portrait); |
1056 | 1050 | ||
1057 | int minus = 0; | 1051 | int minus = 0; |
1058 | if (KGlobal::locale()->weekStartsMonday()) { | 1052 | if (KGlobal::locale()->weekStartsMonday()) { |
1059 | // correct to monday | 1053 | // correct to monday |
1060 | fromWeek = fd.addDays(-(fd.dayOfWeek()-1)); | 1054 | fromWeek = fd.addDays(-(fd.dayOfWeek()-1)); |
1061 | // correct to sunday | 1055 | // correct to sunday |
1062 | toWeek = td.addDays(7-fd.dayOfWeek()); | 1056 | toWeek = td.addDays(7-fd.dayOfWeek()); |
1063 | minus = 1; | 1057 | minus = 1; |
1064 | } else { | 1058 | } else { |
1065 | // correct to sunday | 1059 | // correct to sunday |
1066 | fromWeek = fd.addDays(-(fd.dayOfWeek()%7)); | 1060 | fromWeek = fd.addDays(-(fd.dayOfWeek()%7)); |
1067 | // correct to saturday | 1061 | // correct to saturday |
1068 | toWeek = td.addDays(6-td.dayOfWeek()); | 1062 | toWeek = td.addDays(6-td.dayOfWeek()); |
1069 | } | 1063 | } |
1070 | 1064 | ||
1071 | fromDay = fd; | 1065 | fromDay = fd; |
1072 | curDay = fd; | 1066 | curDay = fd; |
1073 | toDay = td; | 1067 | toDay = td; |
1074 | p.setFont( QFont("Helvetica") ); | 1068 | p.setFont( QFont("Helvetica") ); |
1075 | // the painter initially begins at 72 dpi per the Qt docs. | 1069 | // the painter initially begins at 72 dpi per the Qt docs. |
1076 | int pageWidth = p.viewport().width(); | 1070 | int pageWidth = p.viewport().width(); |
1077 | int pageHeight = p.viewport().height(); | 1071 | int pageHeight = p.viewport().height(); |
1078 | int margin=0; | 1072 | int margin=0; |
1079 | mHeaderHeight = 110; | 1073 | mHeaderHeight = 110; |
1080 | mSubHeaderHeight = 20; | 1074 | mSubHeaderHeight = 20; |
1081 | 1075 | ||
1082 | p.setViewport(margin, margin, | 1076 | p.setViewport(margin, margin, |
1083 | p.viewport().width()-margin, | 1077 | p.viewport().width()-margin, |
1084 | p.viewport().height()-margin); | 1078 | p.viewport().height()-margin); |
1085 | 1079 | ||
1086 | curWeek = fromWeek.addDays(6); | 1080 | curWeek = fromWeek.addDays(6); |
1087 | 1081 | ||
1088 | int columnWidth = int( pageWidth / 4.5 ); | 1082 | int columnWidth = int( pageWidth / 4.5 ); |
1089 | 1083 | ||
1090 | do { | 1084 | do { |
1091 | 1085 | ||
1092 | // if ( (curDay.dayOfWeek()-1)%7 < 3 ) | 1086 | // if ( (curDay.dayOfWeek()-1)%7 < 3 ) |
1093 | switch((curDay.dayOfWeek()-minus)%7){ | 1087 | switch((curDay.dayOfWeek()-minus)%7){ |
1094 | case 0: | 1088 | case 0: |
1095 | drawSplitTimes( p, pageWidth, columnWidth, pageHeight ); | 1089 | drawSplitTimes( p, pageWidth, columnWidth, pageHeight ); |
1096 | drawSplitDay( p, curDay, columnWidth, pageHeight, | 1090 | drawSplitDay( p, curDay, columnWidth, pageHeight, |
1097 | int( columnWidth * 0.5 ) ); | 1091 | int( columnWidth * 0.5 ) ); |
1098 | break; | 1092 | break; |
1099 | case 1: | 1093 | case 1: |
1100 | drawSplitDay( p, curDay, columnWidth, pageHeight, | 1094 | drawSplitDay( p, curDay, columnWidth, pageHeight, |
1101 | int( columnWidth * 1.5 ) ); | 1095 | int( columnWidth * 1.5 ) ); |
1102 | break; | 1096 | break; |
1103 | case 2: | 1097 | case 2: |
1104 | drawSplitDay( p, curDay, columnWidth, pageHeight, | 1098 | drawSplitDay( p, curDay, columnWidth, pageHeight, |
1105 | int( columnWidth * 2.5 ) ); | 1099 | int( columnWidth * 2.5 ) ); |
1106 | break; | 1100 | break; |
1107 | case 3: | 1101 | case 3: |
1108 | drawSplitDay( p, curDay, columnWidth, pageHeight, | 1102 | drawSplitDay( p, curDay, columnWidth, pageHeight, |
1109 | int( columnWidth * 3.5 ) ); | 1103 | int( columnWidth * 3.5 ) ); |
1110 | mPrinter->newPage(); | 1104 | mPrinter->newPage(); |
1111 | break; | 1105 | break; |
1112 | case 4: | 1106 | case 4: |
1113 | drawSplitTimes( p, int( pageWidth * ( 3.5/ 4.5 ) ), columnWidth, | 1107 | drawSplitTimes( p, int( pageWidth * ( 3.5/ 4.5 ) ), columnWidth, |
1114 | pageHeight ); | 1108 | pageHeight ); |
1115 | drawSplitDay( p, curDay, columnWidth, pageHeight, | 1109 | drawSplitDay( p, curDay, columnWidth, pageHeight, |
1116 | int( columnWidth * 0.5 ) ); | 1110 | int( columnWidth * 0.5 ) ); |
1117 | drawSplitHeaderRight( p, curWeek.addDays( -6 ), curWeek, | 1111 | drawSplitHeaderRight( p, curWeek.addDays( -6 ), curWeek, |
1118 | curWeek, pageWidth, mHeaderHeight ); | 1112 | curWeek, pageWidth, mHeaderHeight ); |
1119 | break; | 1113 | break; |
1120 | case 5: | 1114 | case 5: |
1121 | drawSplitDay( p, curDay, columnWidth, pageHeight, | 1115 | drawSplitDay( p, curDay, columnWidth, pageHeight, |
1122 | int( columnWidth * 1.5 ) ); | 1116 | int( columnWidth * 1.5 ) ); |
1123 | break; | 1117 | break; |
1124 | case 6: | 1118 | case 6: |
1125 | drawSplitDay( p, curDay, columnWidth, pageHeight, | 1119 | drawSplitDay( p, curDay, columnWidth, pageHeight, |
1126 | int( columnWidth * 2.5 ) ); | 1120 | int( columnWidth * 2.5 ) ); |
1127 | if ( curDay < toDay ) | 1121 | if ( curDay < toDay ) |
1128 | mPrinter->newPage(); | 1122 | mPrinter->newPage(); |
1129 | curWeek = curWeek.addDays( 7 ); | 1123 | curWeek = curWeek.addDays( 7 ); |
1130 | break; | 1124 | break; |
1131 | } | 1125 | } |
1132 | curDay = curDay.addDays(1); | 1126 | curDay = curDay.addDays(1); |
1133 | 1127 | ||
1134 | } while (curDay <= toDay); | 1128 | } while (curDay <= toDay); |
1135 | 1129 | ||
1136 | } | 1130 | } |
1137 | 1131 | ||
1138 | void CalPrintBase::drawSplitHeaderRight( QPainter &p, const QDate &fd, | 1132 | void CalPrintBase::drawSplitHeaderRight( QPainter &p, const QDate &fd, |
1139 | const QDate &td, | 1133 | const QDate &td, |
1140 | const QDate &, | 1134 | const QDate &, |
1141 | int width, int ) | 1135 | int width, int ) |
1142 | { | 1136 | { |
1143 | int tempStore = mSubHeaderHeight; | 1137 | int tempStore = mSubHeaderHeight; |
1144 | mSubHeaderHeight+= mSubHeaderHeight; | 1138 | mSubHeaderHeight+= mSubHeaderHeight; |
1145 | KLocale *local = KGlobal::locale(); | 1139 | KLocale *local = KGlobal::locale(); |
1146 | QFont font("helvetica", 18, QFont::Bold); | 1140 | QFont font("helvetica", 18, QFont::Bold); |
1147 | QPen penA( black,0); | 1141 | QPen penA( black,0); |
1148 | QPen penB( black,3); | 1142 | QPen penB( black,3); |
1149 | p.setFont(font); | 1143 | p.setFont(font); |
1150 | int lineSpacing = p.fontMetrics().lineSpacing(); | 1144 | int lineSpacing = p.fontMetrics().lineSpacing(); |
1151 | QString title; | 1145 | QString title; |
1152 | QString myOwner(mCalendar->getOwner()); | 1146 | QString myOwner(mCalendar->getOwner()); |
1153 | if ( fd.month() == td.month() ) { | 1147 | if ( fd.month() == td.month() ) { |
1154 | title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' ' | 1148 | title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' ' |
1155 | + '-' + ' ' + QString::number(td.day()); | 1149 | + '-' + ' ' + QString::number(td.day()); |
1156 | } else { | 1150 | } else { |
1157 | title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' ' | 1151 | title = local->monthName(fd.month(), false) + ' ' + QString::number(fd.day()) + ' ' |
1158 | + '-' + ' ' + local->monthName(td.month(), false) + ' ' + QString::number(td.day()); | 1152 | + '-' + ' ' + local->monthName(td.month(), false) + ' ' + QString::number(td.day()); |
1159 | } | 1153 | } |
1160 | 1154 | ||
1161 | // Grrrrrrr! why can't I set the font to a serif font?!?!? | 1155 | // Grrrrrrr! why can't I set the font to a serif font?!?!? |
1162 | QFont serifFont("Helvetica", 30); | 1156 | QFont serifFont("Helvetica", 30); |
1163 | // serifFont.setFamily("Serif"); | 1157 | // serifFont.setFamily("Serif"); |
1164 | // serifFont.setWeight(87); | 1158 | // serifFont.setWeight(87); |
1165 | // serifFont.setItalic(true); | 1159 | // serifFont.setItalic(true); |
1166 | p.setFont(serifFont); | 1160 | p.setFont(serifFont); |
1167 | QFontInfo info(p.font()); | 1161 | QFontInfo info(p.font()); |
1168 | 1162 | ||
1169 | lineSpacing = p.fontMetrics().lineSpacing(); | 1163 | lineSpacing = p.fontMetrics().lineSpacing(); |
1170 | p.drawText(0, lineSpacing * 0, width, lineSpacing, AlignRight |AlignTop, title ); | 1164 | p.drawText(0, lineSpacing * 0, width, lineSpacing, AlignRight |AlignTop, title ); |
1171 | 1165 | ||
1172 | title.truncate(0); | 1166 | title.truncate(0); |
1173 | 1167 | ||
1174 | p.setPen(penB ); | 1168 | p.setPen(penB ); |
1175 | p.drawLine(200, lineSpacing * 1, width, lineSpacing * 1); | 1169 | p.drawLine(200, lineSpacing * 1, width, lineSpacing * 1); |
1176 | p.setPen(penA ); | 1170 | p.setPen(penA ); |
1177 | 1171 | ||
1178 | p.setFont(QFont("Helvetica", 20, QFont::Bold, TRUE)); | 1172 | p.setFont(QFont("Helvetica", 20, QFont::Bold, TRUE)); |
1179 | title += QString::number(fd.year()); | 1173 | title += QString::number(fd.year()); |
1180 | p.drawText(0, lineSpacing * 1, width, lineSpacing, AlignRight |AlignTop, title ); | 1174 | p.drawText(0, lineSpacing * 1, width, lineSpacing, AlignRight |AlignTop, title ); |
1181 | mSubHeaderHeight = tempStore ; | 1175 | mSubHeaderHeight = tempStore ; |
1182 | } | 1176 | } |
1183 | 1177 | ||
1184 | void CalPrintBase::drawSplitDay( QPainter &p, const QDate &qd, int width, | 1178 | void CalPrintBase::drawSplitDay( QPainter &p, const QDate &qd, int width, |
1185 | int height, int offsetLeft ) | 1179 | int height, int offsetLeft ) |
1186 | { | 1180 | { |
1187 | int tempStore = mSubHeaderHeight; | 1181 | int tempStore = mSubHeaderHeight; |
1188 | mSubHeaderHeight+= mSubHeaderHeight; | 1182 | mSubHeaderHeight+= mSubHeaderHeight; |
1189 | int startHour = KOPrefs::instance()->mDayBegins; | 1183 | int startHour = KOPrefs::instance()->mDayBegins; |
1190 | int endHour = 20; | 1184 | int endHour = 20; |
1191 | int offset = mHeaderHeight + mSubHeaderHeight + 10; | 1185 | int offset = mHeaderHeight + mSubHeaderHeight + 10; |
1192 | Event::List eventList; eventList.fill( mCalendar->events( qd, true )); | 1186 | Event::List eventList; eventList.fill( mCalendar->events( qd, true )); |
1193 | Event::List::Iterator it; | 1187 | Event::List::Iterator it; |
1194 | Event *currEvent; | 1188 | Event *currEvent; |
1195 | KLocale *local = KGlobal::locale(); | 1189 | KLocale *local = KGlobal::locale(); |
1196 | QString dayName; | 1190 | QString dayName; |
1197 | 1191 | ||
1198 | dayName = local->weekDayName(qd.dayOfWeek()) + ' ' + ' ' + QString::number(qd.day()); | 1192 | dayName = local->weekDayName(qd.dayOfWeek()) + ' ' + ' ' + QString::number(qd.day()); |
1199 | //p.setBrush(QBrush(black)); | 1193 | //p.setBrush(QBrush(black)); |
1200 | // width+1 to make sure there's a continuous, black bar across the top. | 1194 | // width+1 to make sure there's a continuous, black bar across the top. |
1201 | p.setPen( QPen(Qt::black,2)); | 1195 | p.setPen( QPen(Qt::black,2)); |
1202 | p.drawRect(offsetLeft, mHeaderHeight + 5, width +1, mSubHeaderHeight); | 1196 | p.drawRect(offsetLeft, mHeaderHeight + 5, width +1, mSubHeaderHeight); |
1203 | p.setPen( Qt::black); | 1197 | p.setPen( Qt::black); |
1204 | p.setFont(QFont("helvetica", 12, QFont::Bold, true)); | 1198 | p.setFont(QFont("helvetica", 12, QFont::Bold, true)); |
1205 | p.drawText(offsetLeft, mHeaderHeight + 5, | 1199 | p.drawText(offsetLeft, mHeaderHeight + 5, |
1206 | width, mSubHeaderHeight, AlignHCenter | AlignVCenter, | 1200 | width, mSubHeaderHeight, AlignHCenter | AlignVCenter, |
1207 | dayName); | 1201 | dayName); |
1208 | 1202 | ||
1209 | p.setPen( QPen(Qt::black,2)); | 1203 | p.setPen( QPen(Qt::black,2)); |
1210 | p.setFont(QFont("helvetica", 12)); | 1204 | p.setFont(QFont("helvetica", 12)); |
1211 | p.setBrush(Qt::white); | 1205 | p.setBrush(Qt::white); |
1212 | it = eventList.begin(); | 1206 | it = eventList.begin(); |
1213 | int allDays = 0; | 1207 | int allDays = 0; |
1214 | /* | 1208 | /* |
1215 | while( it != eventList.end() ) { | 1209 | while( it != eventList.end() ) { |
1216 | Event *currEvent = *it; | 1210 | Event *currEvent = *it; |
1217 | if ( currEvent->doesFloat() ) { | 1211 | if ( currEvent->doesFloat() ) { |
1218 | p.drawRect( offsetLeft, offset, width, 35 ); | 1212 | p.drawRect( offsetLeft, offset, width, 35 ); |
1219 | p.drawText( offsetLeft + 5, offset + 10, width - 10, 30, | 1213 | p.drawText( offsetLeft + 5, offset + 10, width - 10, 30, |
1220 | AlignLeft | AlignTop, currEvent->summary() ); | 1214 | AlignLeft | AlignTop, currEvent->summary() ); |
1221 | offset += 40; | 1215 | offset += 40; |
1222 | allDays++; | 1216 | allDays++; |
1223 | it = eventList.remove( it ); | 1217 | it = eventList.remove( it ); |
1224 | } else { | 1218 | } else { |
1225 | ++it; | 1219 | ++it; |
1226 | } | 1220 | } |
1227 | } | 1221 | } |
1228 | */ | 1222 | */ |
1229 | //p.setBrush(QBrush()); | 1223 | //p.setBrush(QBrush()); |
1230 | int tmpEnd; | 1224 | int tmpEnd; |
1231 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 1225 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
1232 | Event *currEvent = *it; | 1226 | Event *currEvent = *it; |
1233 | tmpEnd = currEvent->dtEnd().time().hour(); | 1227 | tmpEnd = currEvent->dtEnd().time().hour(); |
1234 | if (currEvent->dtEnd().time().minute() > 0) | 1228 | if (currEvent->dtEnd().time().minute() > 0) |
1235 | tmpEnd++; | 1229 | tmpEnd++; |
1236 | if (tmpEnd > endHour) | 1230 | if (tmpEnd > endHour) |
1237 | endHour = tmpEnd; | 1231 | endHour = tmpEnd; |
1238 | } | 1232 | } |
1239 | int hours = endHour - startHour; | 1233 | int hours = endHour - startHour; |
1240 | int cellHeight = (height-offset) / hours; // hour increments. | 1234 | int cellHeight = (height-offset) / hours; // hour increments. |
1241 | 1235 | ||
1242 | p.setFont(QFont("helvetica", 12)); | 1236 | p.setFont(QFont("helvetica", 12)); |
1243 | //p.setBrush(QBrush(Dense7Pattern)); | 1237 | //p.setBrush(QBrush(Dense7Pattern)); |
1244 | p.setBrush(Qt::white); | 1238 | p.setBrush(Qt::white); |
1245 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { | 1239 | for ( it = eventList.begin(); it != eventList.end(); ++it ) { |
1246 | Event *currEvent = *it; | 1240 | Event *currEvent = *it; |
1247 | int startTime = currEvent->dtStart().time().hour(); | 1241 | int startTime = currEvent->dtStart().time().hour(); |
1248 | int endTime = currEvent->dtEnd().time().hour(); | 1242 | int endTime = currEvent->dtEnd().time().hour(); |
1249 | float minuteInc = cellHeight / 60.0; | 1243 | float minuteInc = cellHeight / 60.0; |
1250 | if ((startTime >= startHour) && (endTime <= (startHour + hours))) { | 1244 | if ((startTime >= startHour) && (endTime <= (startHour + hours))) { |
1251 | startTime -= startHour; | 1245 | startTime -= startHour; |
1252 | int startMinuteOff = (int) (minuteInc * | 1246 | int startMinuteOff = (int) (minuteInc * |
1253 | currEvent->dtStart().time().minute()); | 1247 | currEvent->dtStart().time().minute()); |
1254 | QString text = currEvent->summary() ; | 1248 | QString text = currEvent->summary() ; |
1255 | if ( ! currEvent->location().isEmpty() ) | 1249 | if ( ! currEvent->location().isEmpty() ) |
1256 | text += "\n("+currEvent->location()+")"; | 1250 | text += "\n("+currEvent->location()+")"; |
1257 | int endMinuteOff = (int) (minuteInc * currEvent->dtEnd().time().minute()); | 1251 | int endMinuteOff = (int) (minuteInc * currEvent->dtEnd().time().minute()); |
1258 | int cheight = (int) (minuteInc * | 1252 | int cheight = (int) (minuteInc * |
1259 | currEvent->dtStart().secsTo(currEvent->dtEnd()) / 60 ); | 1253 | currEvent->dtStart().secsTo(currEvent->dtEnd()) / 60 ); |
1260 | p.drawRect(offsetLeft+2, 1+offset+startMinuteOff+startTime*cellHeight, | 1254 | p.drawRect(offsetLeft+2, 1+offset+startMinuteOff+startTime*cellHeight, |
1261 | width-4, cheight); | 1255 | width-4, cheight); |
1262 | p.drawText(offsetLeft+12, offset+startMinuteOff+startTime*cellHeight+5, width-24, | 1256 | p.drawText(offsetLeft+12, offset+startMinuteOff+startTime*cellHeight+5, width-24, |
1263 | cheight-10, AlignHCenter | AlignTop, text); | 1257 | cheight-10, AlignHCenter | AlignTop, text); |
1264 | } | 1258 | } |
1265 | } | 1259 | } |
1266 | p.setBrush(QBrush(NoBrush)); | 1260 | p.setBrush(QBrush(NoBrush)); |
1267 | mSubHeaderHeight = tempStore ; | 1261 | mSubHeaderHeight = tempStore ; |
1268 | } | 1262 | } |
1269 | 1263 | ||
1270 | void CalPrintBase::drawSplitTimes( QPainter &p, int width, int timeWidth, | 1264 | void CalPrintBase::drawSplitTimes( QPainter &p, int width, int timeWidth, |
1271 | int height ) | 1265 | int height ) |
1272 | { | 1266 | { |
1273 | int tempStore = mSubHeaderHeight; | 1267 | int tempStore = mSubHeaderHeight; |
1274 | mSubHeaderHeight+= mSubHeaderHeight; | 1268 | mSubHeaderHeight+= mSubHeaderHeight; |
1275 | int startHour = KOPrefs::instance()->mDayBegins; | 1269 | int startHour = KOPrefs::instance()->mDayBegins; |
1276 | int endHour = 20; | 1270 | int endHour = 20; |
1277 | int offset = mHeaderHeight + mSubHeaderHeight + 10; | 1271 | int offset = mHeaderHeight + mSubHeaderHeight + 10; |
1278 | int hours = endHour - startHour; | 1272 | int hours = endHour - startHour; |
1279 | int cellHeight = (height-offset) / hours; // hour increments. | 1273 | int cellHeight = (height-offset) / hours; // hour increments. |
1280 | 1274 | ||
1281 | QString numStr; | 1275 | QString numStr; |
1282 | for (int i = 0; i < hours; i++) { | 1276 | for (int i = 0; i < hours; i++) { |
1283 | p.setPen(QPen(black,1)); | 1277 | p.setPen(QPen(black,1)); |
1284 | p.drawLine(0, offset+i*cellHeight, width, offset+i*cellHeight); | 1278 | p.drawLine(0, offset+i*cellHeight, width, offset+i*cellHeight); |
1285 | p.setPen(QPen(gray,0)); | 1279 | p.setPen(QPen(gray,0)); |
1286 | p.drawLine(37, offset+i*cellHeight+(cellHeight/2), | 1280 | p.drawLine(37, offset+i*cellHeight+(cellHeight/2), |
1287 | width, offset+i*cellHeight+(cellHeight/2)); | 1281 | width, offset+i*cellHeight+(cellHeight/2)); |
1288 | p.setPen(QPen(black,0)); | 1282 | p.setPen(QPen(black,0)); |
1289 | 1283 | ||
1290 | if ( !KGlobal::locale()->use12Clock() ) { | 1284 | if ( !KGlobal::locale()->use12Clock() ) { |
1291 | numStr.setNum(i+startHour); | 1285 | numStr.setNum(i+startHour); |
1292 | if (cellHeight > 40) { | 1286 | if (cellHeight > 40) { |
1293 | p.setFont(QFont("helvetica", 16, QFont::Bold)); | 1287 | p.setFont(QFont("helvetica", 16, QFont::Bold)); |
1294 | } else { | 1288 | } else { |
1295 | p.setFont(QFont("helvetica", 14, QFont::Bold)); | 1289 | p.setFont(QFont("helvetica", 14, QFont::Bold)); |
1296 | } | 1290 | } |
1297 | p.drawText(0, offset+i*cellHeight, 33, cellHeight/2, | 1291 | p.drawText(0, offset+i*cellHeight, 33, cellHeight/2, |
1298 | AlignTop|AlignRight, numStr); | 1292 | AlignTop|AlignRight, numStr); |
1299 | p.setFont(QFont("helvetica", 12, QFont::Bold)); | 1293 | p.setFont(QFont("helvetica", 12, QFont::Bold)); |
1300 | p.drawText(37, offset+i*cellHeight, 45, cellHeight/2, | 1294 | p.drawText(37, offset+i*cellHeight, 45, cellHeight/2, |
1301 | AlignTop | AlignLeft, "00"); | 1295 | AlignTop | AlignLeft, "00"); |
1302 | } else { | 1296 | } else { |
1303 | QTime time( i + startHour, 0 ); | 1297 | QTime time( i + startHour, 0 ); |
1304 | numStr = KGlobal::locale()->formatTime( time ); | 1298 | numStr = KGlobal::locale()->formatTime( time ); |
1305 | p.setFont(QFont("helvetica", 12, QFont::Bold)); | 1299 | p.setFont(QFont("helvetica", 12, QFont::Bold)); |
1306 | p.drawText(4, offset+i*cellHeight, 70, cellHeight/2, | 1300 | p.drawText(4, offset+i*cellHeight, 70, cellHeight/2, |
1307 | AlignTop|AlignLeft, numStr); | 1301 | AlignTop|AlignLeft, numStr); |
1308 | } | 1302 | } |
1309 | } mSubHeaderHeight = tempStore ; | 1303 | } mSubHeaderHeight = tempStore ; |
1310 | } | 1304 | } |
1311 | 1305 | ||
1312 | #endif | 1306 | #endif |
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index e8b7c94..8c2996b 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp | |||
@@ -1,2056 +1,2056 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | Marcus Bains line. | 5 | Marcus Bains line. |
6 | Copyright (c) 2001 Ali Rahimi | 6 | Copyright (c) 2001 Ali Rahimi |
7 | 7 | ||
8 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | 11 | (at your option) any later version. |
12 | 12 | ||
13 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. | 16 | GNU General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | 19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 | 21 | ||
22 | As a special exception, permission is given to link this program | 22 | As a special exception, permission is given to link this program |
23 | with any edition of Qt, and distribute the resulting executable, | 23 | with any edition of Qt, and distribute the resulting executable, |
24 | without including the source code for Qt in the source distribution. | 24 | without including the source code for Qt in the source distribution. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #define protected public | 28 | #define protected public |
29 | #include <qwidget.h> | 29 | #include <qwidget.h> |
30 | #undef protected | 30 | #undef protected |
31 | #endif | 31 | #endif |
32 | #include <qintdict.h> | 32 | #include <qintdict.h> |
33 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
34 | #include <qapplication.h> | 34 | #include <qapplication.h> |
35 | #include <qpopupmenu.h> | 35 | #include <qpopupmenu.h> |
36 | #include <qcursor.h> | 36 | #include <qcursor.h> |
37 | #include <qpainter.h> | 37 | #include <qpainter.h> |
38 | 38 | ||
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | #include <kiconloader.h> | 41 | #include <kiconloader.h> |
42 | #include <kglobal.h> | 42 | #include <kglobal.h> |
43 | 43 | ||
44 | #include "koagendaitem.h" | 44 | #include "koagendaitem.h" |
45 | #include "koprefs.h" | 45 | #include "koprefs.h" |
46 | #include "koglobals.h" | 46 | #include "koglobals.h" |
47 | 47 | ||
48 | #include "koagenda.h" | 48 | #include "koagenda.h" |
49 | 49 | ||
50 | #include <libkcal/event.h> | 50 | #include <libkcal/event.h> |
51 | #include <libkcal/todo.h> | 51 | #include <libkcal/todo.h> |
52 | 52 | ||
53 | #ifndef DESKTOP_VERSION | 53 | #ifndef DESKTOP_VERSION |
54 | #include <qpe/qpeapplication.h> | 54 | #include <qpe/qpeapplication.h> |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | //extern bool globalFlagBlockPainting; | 57 | //extern bool globalFlagBlockPainting; |
58 | extern int globalFlagBlockAgenda; | 58 | extern int globalFlagBlockAgenda; |
59 | extern int globalFlagBlockAgendaItemPaint; | 59 | extern int globalFlagBlockAgendaItemPaint; |
60 | extern int globalFlagBlockAgendaItemUpdate; | 60 | extern int globalFlagBlockAgendaItemUpdate; |
61 | extern int globalFlagBlockStartup; | 61 | extern int globalFlagBlockStartup; |
62 | 62 | ||
63 | //////////////////////////////////////////////////////////////////////////// | 63 | //////////////////////////////////////////////////////////////////////////// |
64 | MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) | 64 | MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) |
65 | : QFrame(_agenda->viewport(),name), agenda(_agenda) | 65 | : QFrame(_agenda->viewport(),name), agenda(_agenda) |
66 | { | 66 | { |
67 | setLineWidth(0); | 67 | setLineWidth(0); |
68 | setMargin(0); | 68 | setMargin(0); |
69 | setBackgroundColor(Qt::red); | 69 | setBackgroundColor(Qt::red); |
70 | minutes = new QTimer(this); | 70 | minutes = new QTimer(this); |
71 | connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); | 71 | connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); |
72 | minutes->start(0, true); | 72 | minutes->start(0, true); |
73 | 73 | ||
74 | mTimeBox = new QLabel(this); | 74 | mTimeBox = new QLabel(this); |
75 | mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); | 75 | mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); |
76 | QPalette pal = mTimeBox->palette(); | 76 | QPalette pal = mTimeBox->palette(); |
77 | pal.setColor(QColorGroup::Foreground, Qt::red); | 77 | pal.setColor(QColorGroup::Foreground, Qt::red); |
78 | mTimeBox->setPalette(pal); | 78 | mTimeBox->setPalette(pal); |
79 | //mTimeBox->setAutoMask(true); | 79 | //mTimeBox->setAutoMask(true); |
80 | 80 | ||
81 | agenda->addChild(mTimeBox); | 81 | agenda->addChild(mTimeBox); |
82 | 82 | ||
83 | oldToday = -1; | 83 | oldToday = -1; |
84 | } | 84 | } |
85 | 85 | ||
86 | MarcusBains::~MarcusBains() | 86 | MarcusBains::~MarcusBains() |
87 | { | 87 | { |
88 | delete minutes; | 88 | delete minutes; |
89 | } | 89 | } |
90 | 90 | ||
91 | int MarcusBains::todayColumn() | 91 | int MarcusBains::todayColumn() |
92 | { | 92 | { |
93 | QDate currentDate = QDate::currentDate(); | 93 | QDate currentDate = QDate::currentDate(); |
94 | 94 | ||
95 | DateList dateList = agenda->dateList(); | 95 | DateList dateList = agenda->dateList(); |
96 | DateList::ConstIterator it; | 96 | DateList::ConstIterator it; |
97 | int col = 0; | 97 | int col = 0; |
98 | for(it = dateList.begin(); it != dateList.end(); ++it) { | 98 | for(it = dateList.begin(); it != dateList.end(); ++it) { |
99 | if((*it) == currentDate) | 99 | if((*it) == currentDate) |
100 | return KOGlobals::self()->reverseLayout() ? | 100 | return KOGlobals::self()->reverseLayout() ? |
101 | agenda->columns() - 1 - col : col; | 101 | agenda->columns() - 1 - col : col; |
102 | ++col; | 102 | ++col; |
103 | } | 103 | } |
104 | 104 | ||
105 | return -1; | 105 | return -1; |
106 | } | 106 | } |
107 | void MarcusBains::updateLoc() | 107 | void MarcusBains::updateLoc() |
108 | { | 108 | { |
109 | updateLocation(); | 109 | updateLocation(); |
110 | } | 110 | } |
111 | void MarcusBains::updateLocation(bool recalculate) | 111 | void MarcusBains::updateLocation(bool recalculate) |
112 | { | 112 | { |
113 | 113 | ||
114 | QTime tim = QTime::currentTime(); | 114 | QTime tim = QTime::currentTime(); |
115 | //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); | 115 | //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); |
116 | if((tim.hour() == 0) && (oldTime.hour()==23)) | 116 | if((tim.hour() == 0) && (oldTime.hour()==23)) |
117 | recalculate = true; | 117 | recalculate = true; |
118 | 118 | ||
119 | int mins = tim.hour()*60 + tim.minute(); | 119 | int mins = tim.hour()*60 + tim.minute(); |
120 | int minutesPerCell = 24 * 60 / agenda->rows(); | 120 | int minutesPerCell = 24 * 60 / agenda->rows(); |
121 | int y = mins*agenda->gridSpacingY()/minutesPerCell; | 121 | int y = mins*agenda->gridSpacingY()/minutesPerCell; |
122 | int today = recalculate ? todayColumn() : oldToday; | 122 | int today = recalculate ? todayColumn() : oldToday; |
123 | int x = agenda->gridSpacingX()*today; | 123 | int x = agenda->gridSpacingX()*today; |
124 | bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); | 124 | bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); |
125 | 125 | ||
126 | oldTime = tim; | 126 | oldTime = tim; |
127 | oldToday = today; | 127 | oldToday = today; |
128 | 128 | ||
129 | if(disabled || (today<0)) { | 129 | if(disabled || (today<0)) { |
130 | hide(); mTimeBox->hide(); | 130 | hide(); mTimeBox->hide(); |
131 | return; | 131 | return; |
132 | } else { | 132 | } else { |
133 | show(); mTimeBox->show(); | 133 | show(); mTimeBox->show(); |
134 | } | 134 | } |
135 | 135 | ||
136 | if(recalculate) | 136 | if(recalculate) |
137 | setFixedSize(agenda->gridSpacingX(),1); | 137 | setFixedSize(agenda->gridSpacingX(),1); |
138 | agenda->moveChild(this, x, y); | 138 | agenda->moveChild(this, x, y); |
139 | raise(); | 139 | raise(); |
140 | 140 | ||
141 | if(recalculate) | 141 | if(recalculate) |
142 | //mTimeBox->setFont(QFont("helvetica",10)); | 142 | //mTimeBox->setFont(QFont("helvetica",10)); |
143 | mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); | 143 | mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); |
144 | 144 | ||
145 | mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); | 145 | mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); |
146 | mTimeBox->adjustSize(); | 146 | mTimeBox->adjustSize(); |
147 | // the -2 below is there because there is a bug in this program | 147 | // the -2 below is there because there is a bug in this program |
148 | // somewhere, where the last column of this widget is a few pixels | 148 | // somewhere, where the last column of this widget is a few pixels |
149 | // narrower than the other columns. | 149 | // narrower than the other columns. |
150 | int offs = (today==agenda->columns()-1) ? -4 : 0; | 150 | int offs = (today==agenda->columns()-1) ? -4 : 0; |
151 | agenda->moveChild(mTimeBox, | 151 | agenda->moveChild(mTimeBox, |
152 | x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, | 152 | x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, |
153 | y-mTimeBox->height()); | 153 | y-mTimeBox->height()); |
154 | 154 | ||
155 | mTimeBox->raise(); | 155 | mTimeBox->raise(); |
156 | //mTimeBox->setAutoMask(true); | 156 | //mTimeBox->setAutoMask(true); |
157 | minutes->start(5000,true); | 157 | minutes->start(5000,true); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | //////////////////////////////////////////////////////////////////////////// | 161 | //////////////////////////////////////////////////////////////////////////// |
162 | 162 | ||
163 | 163 | ||
164 | /* | 164 | /* |
165 | Create an agenda widget with rows rows and columns columns. | 165 | Create an agenda widget with rows rows and columns columns. |
166 | */ | 166 | */ |
167 | KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, | 167 | KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, |
168 | const char *name,WFlags f) : | 168 | const char *name,WFlags f) : |
169 | QScrollView(parent,name,f) | 169 | QScrollView(parent,name,f) |
170 | { | 170 | { |
171 | 171 | ||
172 | 172 | ||
173 | mColumns = columns; | 173 | mColumns = columns; |
174 | mRows = rows; | 174 | mRows = rows; |
175 | mGridSpacingY = rowSize; | 175 | mGridSpacingY = rowSize; |
176 | mAllDayMode = false; | 176 | mAllDayMode = false; |
177 | #ifndef DESKTOP_VERSION | 177 | #ifndef DESKTOP_VERSION |
178 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 178 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
179 | #endif | 179 | #endif |
180 | mHolidayMask = 0; | 180 | mHolidayMask = 0; |
181 | init(); | 181 | init(); |
182 | } | 182 | } |
183 | 183 | ||
184 | /* | 184 | /* |
185 | Create an agenda widget with columns columns and one row. This is used for | 185 | Create an agenda widget with columns columns and one row. This is used for |
186 | all-day events. | 186 | all-day events. |
187 | */ | 187 | */ |
188 | KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : | 188 | KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : |
189 | QScrollView(parent,name,f) | 189 | QScrollView(parent,name,f) |
190 | { | 190 | { |
191 | blockResize = false; | 191 | blockResize = false; |
192 | mColumns = columns; | 192 | mColumns = columns; |
193 | mRows = 1; | 193 | mRows = 1; |
194 | //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); | 194 | //qDebug("aaaaaaaaaaaaaaaaaaldays %d ", KOPrefs::instance()->mAllDaySize); |
195 | mGridSpacingY = KOPrefs::instance()->mAllDaySize; | 195 | mGridSpacingY = KOPrefs::instance()->mAllDaySize; |
196 | mAllDayMode = true; | 196 | mAllDayMode = true; |
197 | #ifndef DESKTOP_VERSION | 197 | #ifndef DESKTOP_VERSION |
198 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 198 | QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
199 | #endif | 199 | #endif |
200 | mHolidayMask = 0; | 200 | mHolidayMask = 0; |
201 | init(); | 201 | init(); |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
205 | KOAgenda::~KOAgenda() | 205 | KOAgenda::~KOAgenda() |
206 | { | 206 | { |
207 | if(mMarcusBains) delete mMarcusBains; | 207 | if(mMarcusBains) delete mMarcusBains; |
208 | 208 | ||
209 | } | 209 | } |
210 | 210 | ||
211 | Incidence *KOAgenda::selectedIncidence() const | 211 | Incidence *KOAgenda::selectedIncidence() const |
212 | { | 212 | { |
213 | return (mSelectedItem ? mSelectedItem->incidence() : 0); | 213 | return (mSelectedItem ? mSelectedItem->incidence() : 0); |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | QDate KOAgenda::selectedIncidenceDate() const | 217 | QDate KOAgenda::selectedIncidenceDate() const |
218 | { | 218 | { |
219 | return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); | 219 | return (mSelectedItem ? mSelectedItem->itemDate() : QDate()); |
220 | } | 220 | } |
221 | 221 | ||
222 | 222 | ||
223 | void KOAgenda::init() | 223 | void KOAgenda::init() |
224 | { | 224 | { |
225 | mNewItemPopup = new QPopupMenu( this ); | 225 | mNewItemPopup = new QPopupMenu( this ); |
226 | connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); | 226 | connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); |
227 | QString pathString = ""; | 227 | QString pathString = ""; |
228 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { | 228 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { |
229 | if ( QApplication::desktop()->width() < 480 ) | 229 | if ( QApplication::desktop()->width() < 480 ) |
230 | pathString += "icons16/"; | 230 | pathString += "icons16/"; |
231 | } else | 231 | } else |
232 | pathString += "iconsmini/"; | 232 | pathString += "iconsmini/"; |
233 | 233 | ||
234 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); | 234 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); |
235 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); | 235 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); |
236 | mNewItemPopup->insertSeparator ( ); | 236 | mNewItemPopup->insertSeparator ( ); |
237 | mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); | 237 | mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); |
238 | mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); | 238 | mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); |
239 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); | 239 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); |
240 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); | 240 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); |
241 | mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); | 241 | mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("Next month"),6 ); |
242 | mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); | 242 | mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); |
243 | #ifndef _WIN32_ | 243 | #ifndef _WIN32_ |
244 | int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase | 244 | int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase |
245 | viewport()->setWFlags ( wflags); | 245 | viewport()->setWFlags ( wflags); |
246 | #endif | 246 | #endif |
247 | mGridSpacingX = 80; | 247 | mGridSpacingX = 80; |
248 | mResizeBorderWidth = 8; | 248 | mResizeBorderWidth = 8; |
249 | mScrollBorderWidth = 8; | 249 | mScrollBorderWidth = 8; |
250 | mScrollDelay = 30; | 250 | mScrollDelay = 30; |
251 | mScrollOffset = 10; | 251 | mScrollOffset = 10; |
252 | mPaintPixmap.resize( 20,20); | 252 | mPaintPixmap.resize( 20,20); |
253 | //enableClipper(true); | 253 | //enableClipper(true); |
254 | 254 | ||
255 | // Grab key strokes for keyboard navigation of agenda. Seems to have no | 255 | // Grab key strokes for keyboard navigation of agenda. Seems to have no |
256 | // effect. Has to be fixed. | 256 | // effect. Has to be fixed. |
257 | setFocusPolicy(WheelFocus); | 257 | setFocusPolicy(WheelFocus); |
258 | 258 | ||
259 | connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); | 259 | connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); |
260 | connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); | 260 | connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); |
261 | connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); | 261 | connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); |
262 | 262 | ||
263 | mStartCellX = 0; | 263 | mStartCellX = 0; |
264 | mStartCellY = 0; | 264 | mStartCellY = 0; |
265 | mCurrentCellX = 0; | 265 | mCurrentCellX = 0; |
266 | mCurrentCellY = 0; | 266 | mCurrentCellY = 0; |
267 | 267 | ||
268 | mSelectionCellX = 0; | 268 | mSelectionCellX = 0; |
269 | mSelectionYTop = 0; | 269 | mSelectionYTop = 0; |
270 | mSelectionHeight = 0; | 270 | mSelectionHeight = 0; |
271 | 271 | ||
272 | mOldLowerScrollValue = -1; | 272 | mOldLowerScrollValue = -1; |
273 | mOldUpperScrollValue = -1; | 273 | mOldUpperScrollValue = -1; |
274 | 274 | ||
275 | mClickedItem = 0; | 275 | mClickedItem = 0; |
276 | 276 | ||
277 | mActionItem = 0; | 277 | mActionItem = 0; |
278 | mActionType = NOP; | 278 | mActionType = NOP; |
279 | mItemMoved = false; | 279 | mItemMoved = false; |
280 | 280 | ||
281 | mSelectedItem = 0; | 281 | mSelectedItem = 0; |
282 | 282 | ||
283 | // mItems.setAutoDelete(true); | 283 | // mItems.setAutoDelete(true); |
284 | 284 | ||
285 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); | 285 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); |
286 | 286 | ||
287 | viewport()->update(); | 287 | viewport()->update(); |
288 | 288 | ||
289 | setMinimumSize(30, 1); | 289 | setMinimumSize(30, 1); |
290 | // setMaximumHeight(mGridSpacingY * mRows + 5); | 290 | // setMaximumHeight(mGridSpacingY * mRows + 5); |
291 | 291 | ||
292 | // Disable horizontal scrollbar. This is a hack. The geometry should be | 292 | // Disable horizontal scrollbar. This is a hack. The geometry should be |
293 | // controlled in a way that the contents horizontally always fits. Then it is | 293 | // controlled in a way that the contents horizontally always fits. Then it is |
294 | // not necessary to turn off the scrollbar. | 294 | // not necessary to turn off the scrollbar. |
295 | setHScrollBarMode(AlwaysOff); | 295 | setHScrollBarMode(AlwaysOff); |
296 | if ( ! mAllDayMode ) | 296 | if ( ! mAllDayMode ) |
297 | setVScrollBarMode(AlwaysOn); | 297 | setVScrollBarMode(AlwaysOn); |
298 | else | 298 | else |
299 | setVScrollBarMode(AlwaysOff); | 299 | setVScrollBarMode(AlwaysOff); |
300 | 300 | ||
301 | setStartHour(KOPrefs::instance()->mDayBegins); | 301 | setStartHour(KOPrefs::instance()->mDayBegins); |
302 | 302 | ||
303 | calculateWorkingHours(); | 303 | calculateWorkingHours(); |
304 | 304 | ||
305 | connect(verticalScrollBar(),SIGNAL(valueChanged(int)), | 305 | connect(verticalScrollBar(),SIGNAL(valueChanged(int)), |
306 | SLOT(checkScrollBoundaries(int))); | 306 | SLOT(checkScrollBoundaries(int))); |
307 | 307 | ||
308 | // Create the Marcus Bains line. | 308 | // Create the Marcus Bains line. |
309 | if(mAllDayMode) | 309 | if(mAllDayMode) |
310 | mMarcusBains = 0; | 310 | mMarcusBains = 0; |
311 | else { | 311 | else { |
312 | mMarcusBains = new MarcusBains(this); | 312 | mMarcusBains = new MarcusBains(this); |
313 | addChild(mMarcusBains); | 313 | addChild(mMarcusBains); |
314 | } | 314 | } |
315 | } | 315 | } |
316 | 316 | ||
317 | void KOAgenda::clear() | 317 | void KOAgenda::clear() |
318 | { | 318 | { |
319 | KOAgendaItem *item; | 319 | KOAgendaItem *item; |
320 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 320 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
321 | mUnusedItems.append( item ); | 321 | mUnusedItems.append( item ); |
322 | //item->hide(); | 322 | //item->hide(); |
323 | } | 323 | } |
324 | mItems.clear(); | 324 | mItems.clear(); |
325 | mSelectedItem = 0; | 325 | mSelectedItem = 0; |
326 | clearSelection(); | 326 | clearSelection(); |
327 | } | 327 | } |
328 | 328 | ||
329 | void KOAgenda::clearSelection() | 329 | void KOAgenda::clearSelection() |
330 | { | 330 | { |
331 | mSelectionCellX = 0; | 331 | mSelectionCellX = 0; |
332 | mSelectionYTop = 0; | 332 | mSelectionYTop = 0; |
333 | mSelectionHeight = 0; | 333 | mSelectionHeight = 0; |
334 | } | 334 | } |
335 | 335 | ||
336 | void KOAgenda::marcus_bains() | 336 | void KOAgenda::marcus_bains() |
337 | { | 337 | { |
338 | if(mMarcusBains) mMarcusBains->updateLocation(true); | 338 | if(mMarcusBains) mMarcusBains->updateLocation(true); |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
342 | void KOAgenda::changeColumns(int columns) | 342 | void KOAgenda::changeColumns(int columns) |
343 | { | 343 | { |
344 | if (columns == 0) { | 344 | if (columns == 0) { |
345 | kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; | 345 | kdDebug() << "KOAgenda::changeColumns() called with argument 0" << endl; |
346 | return; | 346 | return; |
347 | } | 347 | } |
348 | 348 | ||
349 | clear(); | 349 | clear(); |
350 | 350 | ||
351 | mColumns = columns; | 351 | mColumns = columns; |
352 | // setMinimumSize(mColumns * 10, mGridSpacingY + 1); | 352 | // setMinimumSize(mColumns * 10, mGridSpacingY + 1); |
353 | // init(); | 353 | // init(); |
354 | // update(); | 354 | // update(); |
355 | //qDebug("KOAgenda::changeColumns "); | 355 | //qDebug("KOAgenda::changeColumns "); |
356 | computeSizes(); | 356 | computeSizes(); |
357 | // QResizeEvent event( size(), size() ); | 357 | // QResizeEvent event( size(), size() ); |
358 | 358 | ||
359 | //QApplication::sendEvent( this, &event ); | 359 | //QApplication::sendEvent( this, &event ); |
360 | } | 360 | } |
361 | 361 | ||
362 | /* | 362 | /* |
363 | This is the eventFilter function, which gets all events from the KOAgendaItems | 363 | This is the eventFilter function, which gets all events from the KOAgendaItems |
364 | contained in the agenda. It has to handle moving and resizing for all items. | 364 | contained in the agenda. It has to handle moving and resizing for all items. |
365 | */ | 365 | */ |
366 | bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) | 366 | bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) |
367 | { | 367 | { |
368 | // kdDebug() << "KOAgenda::eventFilter" << endl; | 368 | // kdDebug() << "KOAgenda::eventFilter" << endl; |
369 | switch(event->type()) { | 369 | switch(event->type()) { |
370 | case QEvent::MouseButtonPress: | 370 | case QEvent::MouseButtonPress: |
371 | case QEvent::MouseButtonDblClick: | 371 | case QEvent::MouseButtonDblClick: |
372 | case QEvent::MouseButtonRelease: | 372 | case QEvent::MouseButtonRelease: |
373 | case QEvent::MouseMove: | 373 | case QEvent::MouseMove: |
374 | return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); | 374 | return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); |
375 | 375 | ||
376 | case (QEvent::Leave): | 376 | case (QEvent::Leave): |
377 | if (!mActionItem) | 377 | if (!mActionItem) |
378 | setCursor(arrowCursor); | 378 | setCursor(arrowCursor); |
379 | return true; | 379 | return true; |
380 | 380 | ||
381 | default: | 381 | default: |
382 | return QScrollView::eventFilter(object,event); | 382 | return QScrollView::eventFilter(object,event); |
383 | } | 383 | } |
384 | } | 384 | } |
385 | 385 | ||
386 | 386 | ||
387 | bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) | 387 | bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) |
388 | { | 388 | { |
389 | //qDebug("KOAgenda::eventFilter_mous "); | 389 | //qDebug("KOAgenda::eventFilter_mous "); |
390 | QPoint viewportPos; | 390 | QPoint viewportPos; |
391 | if (object != viewport()) { | 391 | if (object != viewport()) { |
392 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); | 392 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); |
393 | } else { | 393 | } else { |
394 | viewportPos = me->pos(); | 394 | viewportPos = me->pos(); |
395 | } | 395 | } |
396 | static int startX = 0; | 396 | static int startX = 0; |
397 | static int startY = 0; | 397 | static int startY = 0; |
398 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); | 398 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); |
399 | static bool blockMoving = true; | 399 | static bool blockMoving = true; |
400 | static bool leftMouseDown = false; | 400 | static bool leftMouseDown = false; |
401 | static bool rightMouseDown = false; | 401 | static bool rightMouseDown = false; |
402 | switch (me->type()) { | 402 | switch (me->type()) { |
403 | case QEvent::MouseButtonPress: | 403 | case QEvent::MouseButtonPress: |
404 | if (me->button() == LeftButton) | 404 | if (me->button() == LeftButton) |
405 | leftMouseDown = true; | 405 | leftMouseDown = true; |
406 | else if (me->button() == RightButton) | 406 | else if (me->button() == RightButton) |
407 | rightMouseDown = true; | 407 | rightMouseDown = true; |
408 | blockMoving = true; | 408 | blockMoving = true; |
409 | startX = viewportPos.x(); | 409 | startX = viewportPos.x(); |
410 | startY = viewportPos.y(); | 410 | startY = viewportPos.y(); |
411 | if (object != viewport()) { | 411 | if (object != viewport()) { |
412 | if (me->button() == RightButton) { | 412 | if (me->button() == RightButton) { |
413 | mClickedItem = (KOAgendaItem *)object; | 413 | mClickedItem = (KOAgendaItem *)object; |
414 | if (mClickedItem) { | 414 | if (mClickedItem) { |
415 | selectItem(mClickedItem); | 415 | selectItem(mClickedItem); |
416 | } | 416 | } |
417 | } else if (me->button() == LeftButton) { | 417 | } else if (me->button() == LeftButton) { |
418 | mActionItem = (KOAgendaItem *)object; | 418 | mActionItem = (KOAgendaItem *)object; |
419 | if (mActionItem) { | 419 | if (mActionItem) { |
420 | if ( mSelectionHeight > 0 ) { | 420 | if ( mSelectionHeight > 0 ) { |
421 | int selectionCellX = mSelectionCellX * mGridSpacingX; | 421 | int selectionCellX = mSelectionCellX * mGridSpacingX; |
422 | int selectionYTop = mSelectionYTop; | 422 | int selectionYTop = mSelectionYTop; |
423 | int gridSpacingX = mGridSpacingX; | 423 | int gridSpacingX = mGridSpacingX; |
424 | int selectionHeight = mSelectionHeight; | 424 | int selectionHeight = mSelectionHeight; |
425 | clearSelection(); | 425 | clearSelection(); |
426 | repaintContents( selectionCellX, selectionYTop, | 426 | repaintContents( selectionCellX, selectionYTop, |
427 | gridSpacingX, selectionHeight,false ); | 427 | gridSpacingX, selectionHeight,false ); |
428 | } | 428 | } |
429 | selectItem(mActionItem); | 429 | selectItem(mActionItem); |
430 | Incidence *incidence = mActionItem->incidence(); | 430 | Incidence *incidence = mActionItem->incidence(); |
431 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { | 431 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { |
432 | mActionItem = 0; | 432 | mActionItem = 0; |
433 | } else { | 433 | } else { |
434 | startItemAction(viewportPos); | 434 | startItemAction(viewportPos); |
435 | } | 435 | } |
436 | } | 436 | } |
437 | } | 437 | } |
438 | } else { // ---------- viewport() | 438 | } else { // ---------- viewport() |
439 | selectItem(0); | 439 | selectItem(0); |
440 | mActionItem = 0; | 440 | mActionItem = 0; |
441 | if (me->button() == LeftButton ) { | 441 | if (me->button() == LeftButton ) { |
442 | setCursor(arrowCursor); | 442 | setCursor(arrowCursor); |
443 | startSelectAction(viewportPos); | 443 | startSelectAction(viewportPos); |
444 | } | 444 | } |
445 | } | 445 | } |
446 | break; | 446 | break; |
447 | 447 | ||
448 | case QEvent::MouseButtonRelease: | 448 | case QEvent::MouseButtonRelease: |
449 | if (object != viewport()) { | 449 | if (object != viewport()) { |
450 | if (me->button() == RightButton) { | 450 | if (me->button() == RightButton) { |
451 | if ( blockMoving ) { | 451 | if ( blockMoving ) { |
452 | mClickedItem = (KOAgendaItem *)object; | 452 | mClickedItem = (KOAgendaItem *)object; |
453 | if (mActionItem ) { | 453 | if (mActionItem ) { |
454 | endItemAction(); | 454 | endItemAction(); |
455 | } | 455 | } |
456 | leftMouseDown = false; // no more leftMouse computation | 456 | leftMouseDown = false; // no more leftMouse computation |
457 | if (mClickedItem) { | 457 | if (mClickedItem) { |
458 | selectItem(mClickedItem); | 458 | selectItem(mClickedItem); |
459 | emit showIncidencePopupSignal(mClickedItem->incidence()); | 459 | emit showIncidencePopupSignal(mClickedItem->incidence()); |
460 | } | 460 | } |
461 | } | 461 | } |
462 | } else if (me->button() == LeftButton && leftMouseDown) { | 462 | } else if (me->button() == LeftButton && leftMouseDown) { |
463 | if (mActionItem) { | 463 | if (mActionItem) { |
464 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 464 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
465 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); | 465 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); |
466 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { | 466 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { |
467 | mScrollUpTimer.stop(); | 467 | mScrollUpTimer.stop(); |
468 | mScrollDownTimer.stop(); | 468 | mScrollDownTimer.stop(); |
469 | mActionItem->resetMove(); | 469 | mActionItem->resetMove(); |
470 | placeSubCells( mActionItem ); | 470 | placeSubCells( mActionItem ); |
471 | // emit startDragSignal( mActionItem->incidence() ); | 471 | // emit startDragSignal( mActionItem->incidence() ); |
472 | setCursor( arrowCursor ); | 472 | setCursor( arrowCursor ); |
473 | mActionItem = 0; | 473 | mActionItem = 0; |
474 | mActionType = NOP; | 474 | mActionType = NOP; |
475 | mItemMoved = 0; | 475 | mItemMoved = 0; |
476 | return true; | 476 | return true; |
477 | } | 477 | } |
478 | endItemAction(); | 478 | endItemAction(); |
479 | } | 479 | } |
480 | } | 480 | } |
481 | 481 | ||
482 | } else { // ---------- viewport() | 482 | } else { // ---------- viewport() |
483 | if (me->button() == RightButton) { //right click | 483 | if (me->button() == RightButton) { //right click |
484 | if ( blockMoving ) { // we did mot moved the mouse much - popup menu | 484 | if ( blockMoving ) { // we did mot moved the mouse much - popup menu |
485 | if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action | 485 | if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action |
486 | endSelectAction( false ); // do not emit new event signal | 486 | endSelectAction( false ); // do not emit new event signal |
487 | leftMouseDown = false; // no more leftMouse computation | 487 | leftMouseDown = false; // no more leftMouse computation |
488 | } | 488 | } |
489 | int x,y; | 489 | int x,y; |
490 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 490 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
491 | int gx,gy; | 491 | int gx,gy; |
492 | contentsToGrid(x,y,gx,gy); | 492 | contentsToGrid(x,y,gx,gy); |
493 | mCurrentCellX = gx; | 493 | mCurrentCellX = gx; |
494 | mCurrentCellY = gy; | 494 | mCurrentCellY = gy; |
495 | mStartCellX = gx; | 495 | mStartCellX = gx; |
496 | mStartCellY = gy; | 496 | mStartCellY = gy; |
497 | mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); | 497 | mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); |
498 | } | 498 | } |
499 | } | 499 | } |
500 | else if (me->button() == LeftButton && leftMouseDown ) { //left click | 500 | else if (me->button() == LeftButton && leftMouseDown ) { //left click |
501 | endSelectAction( true ); // emit new event signal | 501 | endSelectAction( true ); // emit new event signal |
502 | } | 502 | } |
503 | } | 503 | } |
504 | if (me->button() == LeftButton) | 504 | if (me->button() == LeftButton) |
505 | leftMouseDown = false; | 505 | leftMouseDown = false; |
506 | else if (me->button() == RightButton) | 506 | else if (me->button() == RightButton) |
507 | rightMouseDown = false; | 507 | rightMouseDown = false; |
508 | break; | 508 | break; |
509 | 509 | ||
510 | case QEvent::MouseMove: | 510 | case QEvent::MouseMove: |
511 | if ( !rightMouseDown && !leftMouseDown ) | 511 | if ( !rightMouseDown && !leftMouseDown ) |
512 | return true; | 512 | return true; |
513 | if ( blockMoving ) { | 513 | if ( blockMoving ) { |
514 | int dX, dY; | 514 | int dX, dY; |
515 | dX = startX - viewportPos.x(); | 515 | dX = startX - viewportPos.x(); |
516 | if ( dX < 0 ) | 516 | if ( dX < 0 ) |
517 | dX = -dX; | 517 | dX = -dX; |
518 | dY = viewportPos.y() - startY; | 518 | dY = viewportPos.y() - startY; |
519 | if ( dY < 0 ) | 519 | if ( dY < 0 ) |
520 | dY = -dY; | 520 | dY = -dY; |
521 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); | 521 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); |
522 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 522 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
523 | blockMoving = false; | 523 | blockMoving = false; |
524 | } | 524 | } |
525 | } | 525 | } |
526 | if (object != viewport()) { | 526 | if (object != viewport()) { |
527 | KOAgendaItem *moveItem = (KOAgendaItem *)object; | 527 | KOAgendaItem *moveItem = (KOAgendaItem *)object; |
528 | if (!moveItem->incidence()->isReadOnly() ) { | 528 | if (!moveItem->incidence()->isReadOnly() ) { |
529 | if (!mActionItem) | 529 | if (!mActionItem) |
530 | setNoActionCursor(moveItem,viewportPos); | 530 | setNoActionCursor(moveItem,viewportPos); |
531 | else { | 531 | else { |
532 | if ( !blockMoving ) | 532 | if ( !blockMoving ) |
533 | performItemAction(viewportPos); | 533 | performItemAction(viewportPos); |
534 | } | 534 | } |
535 | } | 535 | } |
536 | } else { // ---------- viewport() | 536 | } else { // ---------- viewport() |
537 | if ( mActionType == SELECT ) { | 537 | if ( mActionType == SELECT ) { |
538 | performSelectAction( viewportPos ); | 538 | performSelectAction( viewportPos ); |
539 | } | 539 | } |
540 | } | 540 | } |
541 | break; | 541 | break; |
542 | 542 | ||
543 | case QEvent::MouseButtonDblClick: | 543 | case QEvent::MouseButtonDblClick: |
544 | if (object == viewport()) { | 544 | if (object == viewport()) { |
545 | selectItem(0); | 545 | selectItem(0); |
546 | int x,y; | 546 | int x,y; |
547 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 547 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
548 | int gx,gy; | 548 | int gx,gy; |
549 | contentsToGrid(x,y,gx,gy); | 549 | contentsToGrid(x,y,gx,gy); |
550 | emit newEventSignal(gx,gy); | 550 | emit newEventSignal(gx,gy); |
551 | } else { | 551 | } else { |
552 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; | 552 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; |
553 | selectItem(doubleClickedItem); | 553 | selectItem(doubleClickedItem); |
554 | if ( KOPrefs::instance()->mEditOnDoubleClick ) | 554 | if ( KOPrefs::instance()->mEditOnDoubleClick ) |
555 | emit editIncidenceSignal(doubleClickedItem->incidence()); | 555 | emit editIncidenceSignal(doubleClickedItem->incidence()); |
556 | else | 556 | else |
557 | emit showIncidenceSignal(doubleClickedItem->incidence()); | 557 | emit showIncidenceSignal(doubleClickedItem->incidence()); |
558 | } | 558 | } |
559 | break; | 559 | break; |
560 | 560 | ||
561 | default: | 561 | default: |
562 | break; | 562 | break; |
563 | } | 563 | } |
564 | return true; | 564 | return true; |
565 | } | 565 | } |
566 | 566 | ||
567 | void KOAgenda::newItem( int item ) | 567 | void KOAgenda::newItem( int item ) |
568 | { | 568 | { |
569 | if ( item == 1 ) { //new event | 569 | if ( item == 1 ) { //new event |
570 | newEventSignal(mStartCellX ,mStartCellY ); | 570 | newEventSignal(mStartCellX ,mStartCellY ); |
571 | } else | 571 | } else |
572 | if ( item == 2 ) { //new event | 572 | if ( item == 2 ) { //new event |
573 | newTodoSignal(mStartCellX ,mStartCellY ); | 573 | newTodoSignal(mStartCellX ,mStartCellY ); |
574 | } else | 574 | } else |
575 | { | 575 | { |
576 | QDate day = mSelectedDates[mStartCellX]; | 576 | QDate day = mSelectedDates[mStartCellX]; |
577 | emit showDateView( item, day ); | 577 | emit showDateView( item, day ); |
578 | // 3Day view | 578 | // 3Day view |
579 | // 4Week view | 579 | // 4Week view |
580 | // 5Month view | 580 | // 5Month view |
581 | // 6Journal view | 581 | // 6Journal view |
582 | } | 582 | } |
583 | } | 583 | } |
584 | void KOAgenda::startSelectAction(QPoint viewportPos) | 584 | void KOAgenda::startSelectAction(QPoint viewportPos) |
585 | { | 585 | { |
586 | //emit newStartSelectSignal(); | 586 | //emit newStartSelectSignal(); |
587 | 587 | ||
588 | mActionType = SELECT; | 588 | mActionType = SELECT; |
589 | 589 | ||
590 | int x,y; | 590 | int x,y; |
591 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 591 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
592 | int gx,gy; | 592 | int gx,gy; |
593 | contentsToGrid(x,y,gx,gy); | 593 | contentsToGrid(x,y,gx,gy); |
594 | 594 | ||
595 | mStartCellX = gx; | 595 | mStartCellX = gx; |
596 | mStartCellY = gy; | 596 | mStartCellY = gy; |
597 | mCurrentCellX = gx; | 597 | mCurrentCellX = gx; |
598 | mCurrentCellY = gy; | 598 | mCurrentCellY = gy; |
599 | 599 | ||
600 | // Store coordinates of old selection | 600 | // Store coordinates of old selection |
601 | int selectionX = mSelectionCellX * mGridSpacingX; | 601 | int selectionX = mSelectionCellX * mGridSpacingX; |
602 | int selectionYTop = mSelectionYTop; | 602 | int selectionYTop = mSelectionYTop; |
603 | int selectionHeight = mSelectionHeight; | 603 | int selectionHeight = mSelectionHeight; |
604 | 604 | ||
605 | // Store new selection | 605 | // Store new selection |
606 | mSelectionCellX = gx; | 606 | mSelectionCellX = gx; |
607 | mSelectionYTop = gy * mGridSpacingY; | 607 | mSelectionYTop = gy * mGridSpacingY; |
608 | mSelectionHeight = mGridSpacingY; | 608 | mSelectionHeight = mGridSpacingY; |
609 | 609 | ||
610 | // Clear old selection | 610 | // Clear old selection |
611 | repaintContents( selectionX, selectionYTop, | 611 | repaintContents( selectionX, selectionYTop, |
612 | mGridSpacingX, selectionHeight,false ); | 612 | mGridSpacingX, selectionHeight,false ); |
613 | 613 | ||
614 | // Paint new selection | 614 | // Paint new selection |
615 | // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, | 615 | // repaintContents( mSelectionCellX * mGridSpacingX, mSelectionYTop, |
616 | // mGridSpacingX, mSelectionHeight ); | 616 | // mGridSpacingX, mSelectionHeight ); |
617 | } | 617 | } |
618 | 618 | ||
619 | void KOAgenda::performSelectAction(QPoint viewportPos) | 619 | void KOAgenda::performSelectAction(QPoint viewportPos) |
620 | { | 620 | { |
621 | int x,y; | 621 | int x,y; |
622 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 622 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
623 | int gx,gy; | 623 | int gx,gy; |
624 | contentsToGrid(x,y,gx,gy); | 624 | contentsToGrid(x,y,gx,gy); |
625 | 625 | ||
626 | QPoint clipperPos = clipper()-> | 626 | QPoint clipperPos = clipper()-> |
627 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 627 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
628 | 628 | ||
629 | // Scroll if cursor was moved to upper or lower end of agenda. | 629 | // Scroll if cursor was moved to upper or lower end of agenda. |
630 | if (clipperPos.y() < mScrollBorderWidth) { | 630 | if (clipperPos.y() < mScrollBorderWidth) { |
631 | mScrollUpTimer.start(mScrollDelay); | 631 | mScrollUpTimer.start(mScrollDelay); |
632 | } else if (visibleHeight() - clipperPos.y() < | 632 | } else if (visibleHeight() - clipperPos.y() < |
633 | mScrollBorderWidth) { | 633 | mScrollBorderWidth) { |
634 | mScrollDownTimer.start(mScrollDelay); | 634 | mScrollDownTimer.start(mScrollDelay); |
635 | } else { | 635 | } else { |
636 | mScrollUpTimer.stop(); | 636 | mScrollUpTimer.stop(); |
637 | mScrollDownTimer.stop(); | 637 | mScrollDownTimer.stop(); |
638 | } | 638 | } |
639 | 639 | ||
640 | if ( gy > mCurrentCellY ) { | 640 | if ( gy > mCurrentCellY ) { |
641 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; | 641 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; |
642 | 642 | ||
643 | #if 0 | 643 | #if 0 |
644 | // FIXME: Repaint only the newly selected region | 644 | // FIXME: Repaint only the newly selected region |
645 | repaintContents( mSelectionCellX * mGridSpacingX, | 645 | repaintContents( mSelectionCellX * mGridSpacingX, |
646 | mCurrentCellY + mGridSpacingY, | 646 | mCurrentCellY + mGridSpacingY, |
647 | mGridSpacingX, | 647 | mGridSpacingX, |
648 | mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); | 648 | mSelectionHeight - ( gy - mCurrentCellY - 1 ) * mGridSpacingY ); |
649 | #else | 649 | #else |
650 | repaintContents( (KOGlobals::self()->reverseLayout() ? | 650 | repaintContents( (KOGlobals::self()->reverseLayout() ? |
651 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * | 651 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * |
652 | mGridSpacingX, mSelectionYTop, | 652 | mGridSpacingX, mSelectionYTop, |
653 | mGridSpacingX, mSelectionHeight , false); | 653 | mGridSpacingX, mSelectionHeight , false); |
654 | #endif | 654 | #endif |
655 | 655 | ||
656 | mCurrentCellY = gy; | 656 | mCurrentCellY = gy; |
657 | } else if ( gy < mCurrentCellY ) { | 657 | } else if ( gy < mCurrentCellY ) { |
658 | if ( gy >= mStartCellY ) { | 658 | if ( gy >= mStartCellY ) { |
659 | int selectionHeight = mSelectionHeight; | 659 | int selectionHeight = mSelectionHeight; |
660 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; | 660 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; |
661 | 661 | ||
662 | repaintContents( (KOGlobals::self()->reverseLayout() ? | 662 | repaintContents( (KOGlobals::self()->reverseLayout() ? |
663 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * | 663 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * |
664 | mGridSpacingX, mSelectionYTop, | 664 | mGridSpacingX, mSelectionYTop, |
665 | mGridSpacingX, selectionHeight,false ); | 665 | mGridSpacingX, selectionHeight,false ); |
666 | 666 | ||
667 | mCurrentCellY = gy; | 667 | mCurrentCellY = gy; |
668 | } else { | 668 | } else { |
669 | } | 669 | } |
670 | } | 670 | } |
671 | } | 671 | } |
672 | 672 | ||
673 | void KOAgenda::endSelectAction( bool emitNewEvent ) | 673 | void KOAgenda::endSelectAction( bool emitNewEvent ) |
674 | { | 674 | { |
675 | mActionType = NOP; | 675 | mActionType = NOP; |
676 | mScrollUpTimer.stop(); | 676 | mScrollUpTimer.stop(); |
677 | mScrollDownTimer.stop(); | 677 | mScrollDownTimer.stop(); |
678 | 678 | ||
679 | emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); | 679 | emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); |
680 | if ( emitNewEvent && mStartCellY < mCurrentCellY ) { | 680 | if ( emitNewEvent && mStartCellY < mCurrentCellY ) { |
681 | qDebug("ew event signal "); | 681 | qDebug("ew event signal "); |
682 | emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); | 682 | emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); |
683 | } | 683 | } |
684 | } | 684 | } |
685 | 685 | ||
686 | void KOAgenda::startItemAction(QPoint viewportPos) | 686 | void KOAgenda::startItemAction(QPoint viewportPos) |
687 | { | 687 | { |
688 | int x,y; | 688 | int x,y; |
689 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 689 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
690 | int gx,gy; | 690 | int gx,gy; |
691 | contentsToGrid(x,y,gx,gy); | 691 | contentsToGrid(x,y,gx,gy); |
692 | 692 | ||
693 | mStartCellX = gx; | 693 | mStartCellX = gx; |
694 | mStartCellY = gy; | 694 | mStartCellY = gy; |
695 | mCurrentCellX = gx; | 695 | mCurrentCellX = gx; |
696 | mCurrentCellY = gy; | 696 | mCurrentCellY = gy; |
697 | 697 | ||
698 | if (mAllDayMode) { | 698 | if (mAllDayMode) { |
699 | int gridDistanceX = (x - gx * mGridSpacingX); | 699 | int gridDistanceX = (x - gx * mGridSpacingX); |
700 | if (gridDistanceX < mResizeBorderWidth && | 700 | if (gridDistanceX < mResizeBorderWidth && |
701 | mActionItem->cellX() == mCurrentCellX) { | 701 | mActionItem->cellX() == mCurrentCellX) { |
702 | mActionType = RESIZELEFT; | 702 | mActionType = RESIZELEFT; |
703 | setCursor(sizeHorCursor); | 703 | setCursor(sizeHorCursor); |
704 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && | 704 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && |
705 | mActionItem->cellXWidth() == mCurrentCellX) { | 705 | mActionItem->cellXWidth() == mCurrentCellX) { |
706 | mActionType = RESIZERIGHT; | 706 | mActionType = RESIZERIGHT; |
707 | setCursor(sizeHorCursor); | 707 | setCursor(sizeHorCursor); |
708 | } else { | 708 | } else { |
709 | mActionType = MOVE; | 709 | mActionType = MOVE; |
710 | mActionItem->startMove(); | 710 | mActionItem->startMove(); |
711 | setCursor(sizeAllCursor); | 711 | setCursor(sizeAllCursor); |
712 | } | 712 | } |
713 | } else { | 713 | } else { |
714 | int gridDistanceY = (y - gy * mGridSpacingY); | 714 | int gridDistanceY = (y - gy * mGridSpacingY); |
715 | bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); | 715 | bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); |
716 | if (allowResize && gridDistanceY < mResizeBorderWidth && | 716 | if (allowResize && gridDistanceY < mResizeBorderWidth && |
717 | mActionItem->cellYTop() == mCurrentCellY && | 717 | mActionItem->cellYTop() == mCurrentCellY && |
718 | !mActionItem->firstMultiItem()) { | 718 | !mActionItem->firstMultiItem()) { |
719 | mActionType = RESIZETOP; | 719 | mActionType = RESIZETOP; |
720 | setCursor(sizeVerCursor); | 720 | setCursor(sizeVerCursor); |
721 | } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && | 721 | } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && |
722 | mActionItem->cellYBottom() == mCurrentCellY && | 722 | mActionItem->cellYBottom() == mCurrentCellY && |
723 | !mActionItem->lastMultiItem()) { | 723 | !mActionItem->lastMultiItem()) { |
724 | mActionType = RESIZEBOTTOM; | 724 | mActionType = RESIZEBOTTOM; |
725 | setCursor(sizeVerCursor); | 725 | setCursor(sizeVerCursor); |
726 | } else { | 726 | } else { |
727 | mActionType = MOVE; | 727 | mActionType = MOVE; |
728 | mActionItem->startMove(); | 728 | mActionItem->startMove(); |
729 | setCursor(sizeAllCursor); | 729 | setCursor(sizeAllCursor); |
730 | } | 730 | } |
731 | } | 731 | } |
732 | } | 732 | } |
733 | 733 | ||
734 | void KOAgenda::performItemAction(QPoint viewportPos) | 734 | void KOAgenda::performItemAction(QPoint viewportPos) |
735 | { | 735 | { |
736 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; | 736 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; |
737 | // QPoint point = viewport()->mapToGlobal(viewportPos); | 737 | // QPoint point = viewport()->mapToGlobal(viewportPos); |
738 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; | 738 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; |
739 | // point = clipper()->mapFromGlobal(point); | 739 | // point = clipper()->mapFromGlobal(point); |
740 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; | 740 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; |
741 | // kdDebug() << "visible height: " << visibleHeight() << endl; | 741 | // kdDebug() << "visible height: " << visibleHeight() << endl; |
742 | int x,y; | 742 | int x,y; |
743 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 743 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
744 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; | 744 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; |
745 | int gx,gy; | 745 | int gx,gy; |
746 | contentsToGrid(x,y,gx,gy); | 746 | contentsToGrid(x,y,gx,gy); |
747 | QPoint clipperPos = clipper()-> | 747 | QPoint clipperPos = clipper()-> |
748 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 748 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
749 | 749 | ||
750 | // Cursor left active agenda area. | 750 | // Cursor left active agenda area. |
751 | // This starts a drag. | 751 | // This starts a drag. |
752 | if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ | 752 | if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ |
753 | clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { | 753 | clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { |
754 | if ( mActionType == MOVE ) { | 754 | if ( mActionType == MOVE ) { |
755 | mScrollUpTimer.stop(); | 755 | mScrollUpTimer.stop(); |
756 | mScrollDownTimer.stop(); | 756 | mScrollDownTimer.stop(); |
757 | mActionItem->resetMove(); | 757 | mActionItem->resetMove(); |
758 | placeSubCells( mActionItem ); | 758 | placeSubCells( mActionItem ); |
759 | // emit startDragSignal( mActionItem->incidence() ); | 759 | // emit startDragSignal( mActionItem->incidence() ); |
760 | setCursor( arrowCursor ); | 760 | setCursor( arrowCursor ); |
761 | mActionItem = 0; | 761 | mActionItem = 0; |
762 | mActionType = NOP; | 762 | mActionType = NOP; |
763 | mItemMoved = 0; | 763 | mItemMoved = 0; |
764 | return; | 764 | return; |
765 | } | 765 | } |
766 | } else { | 766 | } else { |
767 | switch ( mActionType ) { | 767 | switch ( mActionType ) { |
768 | case MOVE: | 768 | case MOVE: |
769 | setCursor( sizeAllCursor ); | 769 | setCursor( sizeAllCursor ); |
770 | break; | 770 | break; |
771 | case RESIZETOP: | 771 | case RESIZETOP: |
772 | case RESIZEBOTTOM: | 772 | case RESIZEBOTTOM: |
773 | setCursor( sizeVerCursor ); | 773 | setCursor( sizeVerCursor ); |
774 | break; | 774 | break; |
775 | case RESIZELEFT: | 775 | case RESIZELEFT: |
776 | case RESIZERIGHT: | 776 | case RESIZERIGHT: |
777 | setCursor( sizeHorCursor ); | 777 | setCursor( sizeHorCursor ); |
778 | break; | 778 | break; |
779 | default: | 779 | default: |
780 | setCursor( arrowCursor ); | 780 | setCursor( arrowCursor ); |
781 | } | 781 | } |
782 | } | 782 | } |
783 | 783 | ||
784 | // Scroll if item was moved to upper or lower end of agenda. | 784 | // Scroll if item was moved to upper or lower end of agenda. |
785 | if (clipperPos.y() < mScrollBorderWidth) { | 785 | if (clipperPos.y() < mScrollBorderWidth) { |
786 | mScrollUpTimer.start(mScrollDelay); | 786 | mScrollUpTimer.start(mScrollDelay); |
787 | } else if (visibleHeight() - clipperPos.y() < | 787 | } else if (visibleHeight() - clipperPos.y() < |
788 | mScrollBorderWidth) { | 788 | mScrollBorderWidth) { |
789 | mScrollDownTimer.start(mScrollDelay); | 789 | mScrollDownTimer.start(mScrollDelay); |
790 | } else { | 790 | } else { |
791 | mScrollUpTimer.stop(); | 791 | mScrollUpTimer.stop(); |
792 | mScrollDownTimer.stop(); | 792 | mScrollDownTimer.stop(); |
793 | } | 793 | } |
794 | 794 | ||
795 | // Move or resize item if necessary | 795 | // Move or resize item if necessary |
796 | if (mCurrentCellX != gx || mCurrentCellY != gy) { | 796 | if (mCurrentCellX != gx || mCurrentCellY != gy) { |
797 | mItemMoved = true; | 797 | mItemMoved = true; |
798 | mActionItem->raise(); | 798 | mActionItem->raise(); |
799 | if (mActionType == MOVE) { | 799 | if (mActionType == MOVE) { |
800 | // Move all items belonging to a multi item | 800 | // Move all items belonging to a multi item |
801 | KOAgendaItem *moveItem = mActionItem->firstMultiItem(); | 801 | KOAgendaItem *moveItem = mActionItem->firstMultiItem(); |
802 | bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); | 802 | bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); |
803 | if (!moveItem) moveItem = mActionItem; | 803 | if (!moveItem) moveItem = mActionItem; |
804 | while (moveItem) { | 804 | while (moveItem) { |
805 | int dy; | 805 | int dy; |
806 | if (isMultiItem) dy = 0; | 806 | if (isMultiItem) dy = 0; |
807 | else dy = gy - mCurrentCellY; | 807 | else dy = gy - mCurrentCellY; |
808 | moveItem->moveRelative(gx - mCurrentCellX,dy); | 808 | moveItem->moveRelative(gx - mCurrentCellX,dy); |
809 | int x,y; | 809 | int x,y; |
810 | gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); | 810 | gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); |
811 | moveItem->resize(mGridSpacingX * moveItem->cellWidth(), | 811 | moveItem->resize(mGridSpacingX * moveItem->cellWidth(), |
812 | mGridSpacingY * moveItem->cellHeight()); | 812 | mGridSpacingY * moveItem->cellHeight()); |
813 | moveChild(moveItem,x,y); | 813 | moveChild(moveItem,x,y); |
814 | moveItem = moveItem->nextMultiItem(); | 814 | moveItem = moveItem->nextMultiItem(); |
815 | } | 815 | } |
816 | } else if (mActionType == RESIZETOP) { | 816 | } else if (mActionType == RESIZETOP) { |
817 | if (mCurrentCellY <= mActionItem->cellYBottom()) { | 817 | if (mCurrentCellY <= mActionItem->cellYBottom()) { |
818 | mActionItem->expandTop(gy - mCurrentCellY); | 818 | mActionItem->expandTop(gy - mCurrentCellY); |
819 | mActionItem->resize(mActionItem->width(), | 819 | mActionItem->resize(mActionItem->width(), |
820 | mGridSpacingY * mActionItem->cellHeight()); | 820 | mGridSpacingY * mActionItem->cellHeight()); |
821 | int x,y; | 821 | int x,y; |
822 | gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); | 822 | gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); |
823 | //moveChild(mActionItem,childX(mActionItem),y); | 823 | //moveChild(mActionItem,childX(mActionItem),y); |
824 | QScrollView::moveChild( mActionItem,childX(mActionItem),y ); | 824 | QScrollView::moveChild( mActionItem,childX(mActionItem),y ); |
825 | } | 825 | } |
826 | } else if (mActionType == RESIZEBOTTOM) { | 826 | } else if (mActionType == RESIZEBOTTOM) { |
827 | if (mCurrentCellY >= mActionItem->cellYTop()) { | 827 | if (mCurrentCellY >= mActionItem->cellYTop()) { |
828 | mActionItem->expandBottom(gy - mCurrentCellY); | 828 | mActionItem->expandBottom(gy - mCurrentCellY); |
829 | mActionItem->resize(mActionItem->width(), | 829 | mActionItem->resize(mActionItem->width(), |
830 | mGridSpacingY * mActionItem->cellHeight()); | 830 | mGridSpacingY * mActionItem->cellHeight()); |
831 | } | 831 | } |
832 | } else if (mActionType == RESIZELEFT) { | 832 | } else if (mActionType == RESIZELEFT) { |
833 | if (mCurrentCellX <= mActionItem->cellXWidth()) { | 833 | if (mCurrentCellX <= mActionItem->cellXWidth()) { |
834 | mActionItem->expandLeft(gx - mCurrentCellX); | 834 | mActionItem->expandLeft(gx - mCurrentCellX); |
835 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), | 835 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), |
836 | mActionItem->height()); | 836 | mActionItem->height()); |
837 | int x,y; | 837 | int x,y; |
838 | gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); | 838 | gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); |
839 | moveChild(mActionItem,x,childY(mActionItem)); | 839 | moveChild(mActionItem,x,childY(mActionItem)); |
840 | } | 840 | } |
841 | } else if (mActionType == RESIZERIGHT) { | 841 | } else if (mActionType == RESIZERIGHT) { |
842 | if (mCurrentCellX >= mActionItem->cellX()) { | 842 | if (mCurrentCellX >= mActionItem->cellX()) { |
843 | mActionItem->expandRight(gx - mCurrentCellX); | 843 | mActionItem->expandRight(gx - mCurrentCellX); |
844 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), | 844 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), |
845 | mActionItem->height()); | 845 | mActionItem->height()); |
846 | } | 846 | } |
847 | } | 847 | } |
848 | mCurrentCellX = gx; | 848 | mCurrentCellX = gx; |
849 | mCurrentCellY = gy; | 849 | mCurrentCellY = gy; |
850 | } | 850 | } |
851 | } | 851 | } |
852 | 852 | ||
853 | void KOAgenda::endItemAction() | 853 | void KOAgenda::endItemAction() |
854 | { | 854 | { |
855 | 855 | ||
856 | if ( mItemMoved ) { | 856 | if ( mItemMoved ) { |
857 | KOAgendaItem *placeItem = mActionItem->firstMultiItem(); | 857 | KOAgendaItem *placeItem = mActionItem->firstMultiItem(); |
858 | if ( !placeItem ) { | 858 | if ( !placeItem ) { |
859 | placeItem = mActionItem; | 859 | placeItem = mActionItem; |
860 | } | 860 | } |
861 | if ( placeItem->incidence()->recurrence()->doesRecur() ) { | 861 | if ( placeItem->incidence()->recurrence()->doesRecur() ) { |
862 | Incidence* oldInc = placeItem->incidence(); | 862 | Incidence* oldInc = placeItem->incidence(); |
863 | placeItem->recreateIncidence(); | 863 | placeItem->recreateIncidence(); |
864 | emit addToCalSignal(placeItem->incidence(), oldInc ); | 864 | emit addToCalSignal(placeItem->incidence(), oldInc ); |
865 | } | 865 | } |
866 | int type = mActionType; | 866 | int type = mActionType; |
867 | if ( mAllDayMode ) | 867 | if ( mAllDayMode ) |
868 | type = -1; | 868 | type = -1; |
869 | KOAgendaItem *modifiedItem = placeItem; | 869 | KOAgendaItem *modifiedItem = placeItem; |
870 | //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); | 870 | //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); |
871 | QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); | 871 | QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); |
872 | KOAgendaItem *item; | 872 | KOAgendaItem *item; |
873 | 873 | ||
874 | if ( placeItem->incidence()->type() == "Todo" ) { | 874 | if ( placeItem->incidence()->type() == "Todo" ) { |
875 | mSelectedItem = 0; | 875 | mSelectedItem = 0; |
876 | //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); | 876 | //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); |
877 | modifiedItem->mLastMoveXPos = mCurrentCellX; | 877 | modifiedItem->mLastMoveXPos = mCurrentCellX; |
878 | emit itemModified( modifiedItem, mActionType ); | 878 | emit itemModified( modifiedItem, mActionType ); |
879 | } | 879 | } |
880 | else { | 880 | else { |
881 | #if 0 | 881 | #if 0 |
882 | for ( item=oldconflictItems.first(); item != 0; | 882 | for ( item=oldconflictItems.first(); item != 0; |
883 | item=oldconflictItems.next() ) { | 883 | item=oldconflictItems.next() ) { |
884 | placeSubCells(item); | 884 | placeSubCells(item); |
885 | } | 885 | } |
886 | while ( placeItem ) { | 886 | while ( placeItem ) { |
887 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); | 887 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); |
888 | placeSubCells( placeItem ); | 888 | placeSubCells( placeItem ); |
889 | placeItem = placeItem->nextMultiItem(); | 889 | placeItem = placeItem->nextMultiItem(); |
890 | } | 890 | } |
891 | #endif | 891 | #endif |
892 | 892 | ||
893 | globalFlagBlockAgendaItemPaint = 1; | 893 | globalFlagBlockAgendaItemPaint = 1; |
894 | for ( item=oldconflictItems.first(); item != 0; | 894 | for ( item=oldconflictItems.first(); item != 0; |
895 | item=oldconflictItems.next() ) { | 895 | item=oldconflictItems.next() ) { |
896 | placeSubCells(item); | 896 | placeSubCells(item); |
897 | } | 897 | } |
898 | while ( placeItem ) { | 898 | while ( placeItem ) { |
899 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); | 899 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); |
900 | oldconflictItems = placeItem->conflictItems(); | 900 | oldconflictItems = placeItem->conflictItems(); |
901 | for ( item=oldconflictItems.first(); item != 0; | 901 | for ( item=oldconflictItems.first(); item != 0; |
902 | item=oldconflictItems.next() ) { | 902 | item=oldconflictItems.next() ) { |
903 | placeSubCells(item); | 903 | placeSubCells(item); |
904 | } | 904 | } |
905 | placeSubCells( placeItem ); | 905 | placeSubCells( placeItem ); |
906 | placeItem = placeItem->nextMultiItem(); | 906 | placeItem = placeItem->nextMultiItem(); |
907 | } | 907 | } |
908 | globalFlagBlockAgendaItemPaint = 0; | 908 | globalFlagBlockAgendaItemPaint = 0; |
909 | for ( item=oldconflictItems.first(); item != 0; | 909 | for ( item=oldconflictItems.first(); item != 0; |
910 | item=oldconflictItems.next() ) { | 910 | item=oldconflictItems.next() ) { |
911 | globalFlagBlockAgendaItemUpdate = 0; | 911 | globalFlagBlockAgendaItemUpdate = 0; |
912 | item->repaintMe(); | 912 | item->repaintMe(); |
913 | globalFlagBlockAgendaItemUpdate = 1; | 913 | globalFlagBlockAgendaItemUpdate = 1; |
914 | item->repaint( false ); | 914 | item->repaint( false ); |
915 | } | 915 | } |
916 | placeItem = modifiedItem; | 916 | placeItem = modifiedItem; |
917 | 917 | ||
918 | while ( placeItem ) { | 918 | while ( placeItem ) { |
919 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); | 919 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); |
920 | globalFlagBlockAgendaItemUpdate = 0; | 920 | globalFlagBlockAgendaItemUpdate = 0; |
921 | placeItem->repaintMe(); | 921 | placeItem->repaintMe(); |
922 | globalFlagBlockAgendaItemUpdate = 1; | 922 | globalFlagBlockAgendaItemUpdate = 1; |
923 | placeItem->repaint(false); | 923 | placeItem->repaint(false); |
924 | placeItem = placeItem->nextMultiItem(); | 924 | placeItem = placeItem->nextMultiItem(); |
925 | } | 925 | } |
926 | emit itemModified( modifiedItem, mActionType ); | 926 | emit itemModified( modifiedItem, mActionType ); |
927 | 927 | ||
928 | 928 | ||
929 | placeItem = modifiedItem; | 929 | placeItem = modifiedItem; |
930 | while ( placeItem ) { | 930 | while ( placeItem ) { |
931 | oldconflictItems = placeItem->conflictItems(); | 931 | oldconflictItems = placeItem->conflictItems(); |
932 | for ( item=oldconflictItems.first(); item != 0; | 932 | for ( item=oldconflictItems.first(); item != 0; |
933 | item=oldconflictItems.next() ) { | 933 | item=oldconflictItems.next() ) { |
934 | placeSubCells(item); | 934 | placeSubCells(item); |
935 | } | 935 | } |
936 | placeSubCells( placeItem ); | 936 | placeSubCells( placeItem ); |
937 | placeItem = placeItem->nextMultiItem(); | 937 | placeItem = placeItem->nextMultiItem(); |
938 | 938 | ||
939 | } | 939 | } |
940 | placeItem = modifiedItem; | 940 | placeItem = modifiedItem; |
941 | while ( placeItem ) { | 941 | while ( placeItem ) { |
942 | oldconflictItems = placeItem->conflictItems(); | 942 | oldconflictItems = placeItem->conflictItems(); |
943 | for ( item=oldconflictItems.first(); item != 0; | 943 | for ( item=oldconflictItems.first(); item != 0; |
944 | item=oldconflictItems.next() ) { | 944 | item=oldconflictItems.next() ) { |
945 | globalFlagBlockAgendaItemUpdate = 0; | 945 | globalFlagBlockAgendaItemUpdate = 0; |
946 | item->repaintMe(); | 946 | item->repaintMe(); |
947 | globalFlagBlockAgendaItemUpdate = 1; | 947 | globalFlagBlockAgendaItemUpdate = 1; |
948 | item->repaint(false); | 948 | item->repaint(false); |
949 | } | 949 | } |
950 | placeItem = placeItem->nextMultiItem(); | 950 | placeItem = placeItem->nextMultiItem(); |
951 | } | 951 | } |
952 | /* | 952 | /* |
953 | 953 | ||
954 | oldconflictItems = modifiedItem->conflictItems(); | 954 | oldconflictItems = modifiedItem->conflictItems(); |
955 | for ( item=oldconflictItems.first(); item != 0; | 955 | for ( item=oldconflictItems.first(); item != 0; |
956 | item=oldconflictItems.next() ) { | 956 | item=oldconflictItems.next() ) { |
957 | globalFlagBlockAgendaItemUpdate = 0; | 957 | globalFlagBlockAgendaItemUpdate = 0; |
958 | item->paintMe(false); | 958 | item->paintMe(false); |
959 | globalFlagBlockAgendaItemUpdate = 1; | 959 | globalFlagBlockAgendaItemUpdate = 1; |
960 | item->repaint(false); | 960 | item->repaint(false); |
961 | } | 961 | } |
962 | */ | 962 | */ |
963 | 963 | ||
964 | 964 | ||
965 | } | 965 | } |
966 | 966 | ||
967 | } | 967 | } |
968 | 968 | ||
969 | mScrollUpTimer.stop(); | 969 | mScrollUpTimer.stop(); |
970 | mScrollDownTimer.stop(); | 970 | mScrollDownTimer.stop(); |
971 | setCursor( arrowCursor ); | 971 | setCursor( arrowCursor ); |
972 | mActionItem = 0; | 972 | mActionItem = 0; |
973 | mActionType = NOP; | 973 | mActionType = NOP; |
974 | mItemMoved = 0; | 974 | mItemMoved = 0; |
975 | 975 | ||
976 | } | 976 | } |
977 | 977 | ||
978 | void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) | 978 | void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) |
979 | { | 979 | { |
980 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; | 980 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; |
981 | // QPoint point = viewport()->mapToGlobal(viewportPos); | 981 | // QPoint point = viewport()->mapToGlobal(viewportPos); |
982 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; | 982 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; |
983 | // point = clipper()->mapFromGlobal(point); | 983 | // point = clipper()->mapFromGlobal(point); |
984 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; | 984 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; |
985 | 985 | ||
986 | int x,y; | 986 | int x,y; |
987 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 987 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
988 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; | 988 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; |
989 | int gx,gy; | 989 | int gx,gy; |
990 | contentsToGrid(x,y,gx,gy); | 990 | contentsToGrid(x,y,gx,gy); |
991 | 991 | ||
992 | // Change cursor to resize cursor if appropriate | 992 | // Change cursor to resize cursor if appropriate |
993 | if (mAllDayMode) { | 993 | if (mAllDayMode) { |
994 | int gridDistanceX = (x - gx * mGridSpacingX); | 994 | int gridDistanceX = (x - gx * mGridSpacingX); |
995 | if (gridDistanceX < mResizeBorderWidth && | 995 | if (gridDistanceX < mResizeBorderWidth && |
996 | moveItem->cellX() == gx) { | 996 | moveItem->cellX() == gx) { |
997 | setCursor(sizeHorCursor); | 997 | setCursor(sizeHorCursor); |
998 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && | 998 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && |
999 | moveItem->cellXWidth() == gx) { | 999 | moveItem->cellXWidth() == gx) { |
1000 | setCursor(sizeHorCursor); | 1000 | setCursor(sizeHorCursor); |
1001 | } else { | 1001 | } else { |
1002 | setCursor(arrowCursor); | 1002 | setCursor(arrowCursor); |
1003 | } | 1003 | } |
1004 | } else { | 1004 | } else { |
1005 | int gridDistanceY = (y - gy * mGridSpacingY); | 1005 | int gridDistanceY = (y - gy * mGridSpacingY); |
1006 | if (gridDistanceY < mResizeBorderWidth && | 1006 | if (gridDistanceY < mResizeBorderWidth && |
1007 | moveItem->cellYTop() == gy && | 1007 | moveItem->cellYTop() == gy && |
1008 | !moveItem->firstMultiItem()) { | 1008 | !moveItem->firstMultiItem()) { |
1009 | setCursor(sizeVerCursor); | 1009 | setCursor(sizeVerCursor); |
1010 | } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && | 1010 | } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && |
1011 | moveItem->cellYBottom() == gy && | 1011 | moveItem->cellYBottom() == gy && |
1012 | !moveItem->lastMultiItem()) { | 1012 | !moveItem->lastMultiItem()) { |
1013 | setCursor(sizeVerCursor); | 1013 | setCursor(sizeVerCursor); |
1014 | } else { | 1014 | } else { |
1015 | setCursor(arrowCursor); | 1015 | setCursor(arrowCursor); |
1016 | } | 1016 | } |
1017 | } | 1017 | } |
1018 | } | 1018 | } |
1019 | 1019 | ||
1020 | 1020 | ||
1021 | /* | 1021 | /* |
1022 | Place item in cell and take care that multiple items using the same cell do | 1022 | Place item in cell and take care that multiple items using the same cell do |
1023 | not overlap. This method is not yet optimal. It doesn´t use the maximum space | 1023 | not overlap. This method is not yet optimal. It doesn´t use the maximum space |
1024 | it can get in all cases. | 1024 | it can get in all cases. |
1025 | At the moment the method has a bug: When an item is placed only the sub cell | 1025 | At the moment the method has a bug: When an item is placed only the sub cell |
1026 | widths of the items are changed, which are within the Y region the item to | 1026 | widths of the items are changed, which are within the Y region the item to |
1027 | place spans. When the sub cell width change of one of this items affects a | 1027 | place spans. When the sub cell width change of one of this items affects a |
1028 | cell, where other items are, which do not overlap in Y with the item to place, | 1028 | cell, where other items are, which do not overlap in Y with the item to place, |
1029 | the display gets corrupted, although the corruption looks quite nice. | 1029 | the display gets corrupted, although the corruption looks quite nice. |
1030 | */ | 1030 | */ |
1031 | void KOAgenda::placeSubCells(KOAgendaItem *placeItem) | 1031 | void KOAgenda::placeSubCells(KOAgendaItem *placeItem) |
1032 | { | 1032 | { |
1033 | 1033 | ||
1034 | QPtrList<KOAgendaItem> conflictItems; | 1034 | QPtrList<KOAgendaItem> conflictItems; |
1035 | int maxSubCells = 0; | 1035 | int maxSubCells = 0; |
1036 | QIntDict<KOAgendaItem> subCellDict(5); | 1036 | QIntDict<KOAgendaItem> subCellDict(5); |
1037 | 1037 | ||
1038 | KOAgendaItem *item; | 1038 | KOAgendaItem *item; |
1039 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1039 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1040 | if (item != placeItem) { | 1040 | if (item != placeItem) { |
1041 | if (placeItem->cellX() <= item->cellXWidth() && | 1041 | if (placeItem->cellX() <= item->cellXWidth() && |
1042 | placeItem->cellXWidth() >= item->cellX()) { | 1042 | placeItem->cellXWidth() >= item->cellX()) { |
1043 | if ((placeItem->cellYTop() <= item->cellYBottom()) && | 1043 | if ((placeItem->cellYTop() <= item->cellYBottom()) && |
1044 | (placeItem->cellYBottom() >= item->cellYTop())) { | 1044 | (placeItem->cellYBottom() >= item->cellYTop())) { |
1045 | conflictItems.append(item); | 1045 | conflictItems.append(item); |
1046 | if (item->subCells() > maxSubCells) | 1046 | if (item->subCells() > maxSubCells) |
1047 | maxSubCells = item->subCells(); | 1047 | maxSubCells = item->subCells(); |
1048 | subCellDict.insert(item->subCell(),item); | 1048 | subCellDict.insert(item->subCell(),item); |
1049 | } | 1049 | } |
1050 | } | 1050 | } |
1051 | } | 1051 | } |
1052 | } | 1052 | } |
1053 | 1053 | ||
1054 | if (conflictItems.count() > 0) { | 1054 | if (conflictItems.count() > 0) { |
1055 | // Look for unused sub cell and insert item | 1055 | // Look for unused sub cell and insert item |
1056 | int i; | 1056 | int i; |
1057 | for(i=0;i<maxSubCells;++i) { | 1057 | for(i=0;i<maxSubCells;++i) { |
1058 | if (!subCellDict.find(i)) { | 1058 | if (!subCellDict.find(i)) { |
1059 | placeItem->setSubCell(i); | 1059 | placeItem->setSubCell(i); |
1060 | break; | 1060 | break; |
1061 | } | 1061 | } |
1062 | } | 1062 | } |
1063 | if (i == maxSubCells) { | 1063 | if (i == maxSubCells) { |
1064 | placeItem->setSubCell(maxSubCells); | 1064 | placeItem->setSubCell(maxSubCells); |
1065 | maxSubCells++; // add new item to number of sub cells | 1065 | maxSubCells++; // add new item to number of sub cells |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | // Prepare for sub cell geometry adjustment | 1068 | // Prepare for sub cell geometry adjustment |
1069 | int newSubCellWidth; | 1069 | int newSubCellWidth; |
1070 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; | 1070 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; |
1071 | else newSubCellWidth = mGridSpacingX / maxSubCells; | 1071 | else newSubCellWidth = mGridSpacingX / maxSubCells; |
1072 | conflictItems.append(placeItem); | 1072 | conflictItems.append(placeItem); |
1073 | 1073 | ||
1074 | 1074 | ||
1075 | // Adjust sub cell geometry of all direct conflict items | 1075 | // Adjust sub cell geometry of all direct conflict items |
1076 | for ( item=conflictItems.first(); item != 0; | 1076 | for ( item=conflictItems.first(); item != 0; |
1077 | item=conflictItems.next() ) { | 1077 | item=conflictItems.next() ) { |
1078 | item->setSubCells(maxSubCells); | 1078 | item->setSubCells(maxSubCells); |
1079 | if (mAllDayMode) { | 1079 | if (mAllDayMode) { |
1080 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); | 1080 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); |
1081 | } else { | 1081 | } else { |
1082 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); | 1082 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); |
1083 | } | 1083 | } |
1084 | int x,y; | 1084 | int x,y; |
1085 | gridToContents(item->cellX(),item->cellYTop(),x,y); | 1085 | gridToContents(item->cellX(),item->cellYTop(),x,y); |
1086 | if (mAllDayMode) { | 1086 | if (mAllDayMode) { |
1087 | y += item->subCell() * newSubCellWidth; | 1087 | y += item->subCell() * newSubCellWidth; |
1088 | } else { | 1088 | } else { |
1089 | x += item->subCell() * newSubCellWidth; | 1089 | x += item->subCell() * newSubCellWidth; |
1090 | } | 1090 | } |
1091 | moveChild(item,x,y); | 1091 | moveChild(item,x,y); |
1092 | // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); | 1092 | // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); |
1093 | //item->updateItem(); | 1093 | //item->updateItem(); |
1094 | } | 1094 | } |
1095 | // Adjust sub cell geometry of all conflict items of all conflict items | 1095 | // Adjust sub cell geometry of all conflict items of all conflict items |
1096 | for ( item=conflictItems.first(); item != 0; | 1096 | for ( item=conflictItems.first(); item != 0; |
1097 | item=conflictItems.next() ) { | 1097 | item=conflictItems.next() ) { |
1098 | if ( placeItem != item ) { | 1098 | if ( placeItem != item ) { |
1099 | KOAgendaItem *item2; | 1099 | KOAgendaItem *item2; |
1100 | QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); | 1100 | QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); |
1101 | for ( item2=conflictItems2.first(); item2 != 0; | 1101 | for ( item2=conflictItems2.first(); item2 != 0; |
1102 | item2=conflictItems2.next() ) { | 1102 | item2=conflictItems2.next() ) { |
1103 | if ( item2->subCells() != maxSubCells) { | 1103 | if ( item2->subCells() != maxSubCells) { |
1104 | item2->setSubCells(maxSubCells); | 1104 | item2->setSubCells(maxSubCells); |
1105 | if (mAllDayMode) { | 1105 | if (mAllDayMode) { |
1106 | item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); | 1106 | item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); |
1107 | } else { | 1107 | } else { |
1108 | item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); | 1108 | item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); |
1109 | } | 1109 | } |
1110 | int x,y; | 1110 | int x,y; |
1111 | gridToContents(item2->cellX(),item2->cellYTop(),x,y); | 1111 | gridToContents(item2->cellX(),item2->cellYTop(),x,y); |
1112 | if (mAllDayMode) { | 1112 | if (mAllDayMode) { |
1113 | y += item2->subCell() * newSubCellWidth; | 1113 | y += item2->subCell() * newSubCellWidth; |
1114 | } else { | 1114 | } else { |
1115 | x += item2->subCell() * newSubCellWidth; | 1115 | x += item2->subCell() * newSubCellWidth; |
1116 | } | 1116 | } |
1117 | moveChild(item2,x,y); | 1117 | moveChild(item2,x,y); |
1118 | //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); | 1118 | //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); |
1119 | } | 1119 | } |
1120 | } | 1120 | } |
1121 | } | 1121 | } |
1122 | } | 1122 | } |
1123 | } else { | 1123 | } else { |
1124 | placeItem->setSubCell(0); | 1124 | placeItem->setSubCell(0); |
1125 | placeItem->setSubCells(1); | 1125 | placeItem->setSubCells(1); |
1126 | if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); | 1126 | if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); |
1127 | else placeItem->resize(mGridSpacingX,placeItem->height()); | 1127 | else placeItem->resize(mGridSpacingX,placeItem->height()); |
1128 | int x,y; | 1128 | int x,y; |
1129 | gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); | 1129 | gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); |
1130 | moveChild(placeItem,x,y); | 1130 | moveChild(placeItem,x,y); |
1131 | } | 1131 | } |
1132 | placeItem->setConflictItems(conflictItems); | 1132 | placeItem->setConflictItems(conflictItems); |
1133 | // for ( item=conflictItems.first(); item != 0; | 1133 | // for ( item=conflictItems.first(); item != 0; |
1134 | // item=conflictItems.next() ) { | 1134 | // item=conflictItems.next() ) { |
1135 | // //item->updateItem(); | 1135 | // //item->updateItem(); |
1136 | // //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); | 1136 | // //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); |
1137 | // } | 1137 | // } |
1138 | // placeItem->updateItem(); | 1138 | // placeItem->updateItem(); |
1139 | } | 1139 | } |
1140 | 1140 | ||
1141 | void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 1141 | void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |
1142 | { | 1142 | { |
1143 | if ( globalFlagBlockAgenda ) | 1143 | if ( globalFlagBlockAgenda ) |
1144 | return; | 1144 | return; |
1145 | //qDebug("KOAgenda::drawContents "); | 1145 | //qDebug("KOAgenda::drawContents "); |
1146 | if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) | 1146 | if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) |
1147 | ;//drawContentsToPainter(); | 1147 | ;//drawContentsToPainter(); |
1148 | 1148 | ||
1149 | QPaintDevice* pd = p->device(); | 1149 | QPaintDevice* pd = p->device(); |
1150 | p->end(); | 1150 | p->end(); |
1151 | int vx, vy; | 1151 | int vx, vy; |
1152 | int selectionX = KOGlobals::self()->reverseLayout() ? | 1152 | int selectionX = KOGlobals::self()->reverseLayout() ? |
1153 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : | 1153 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : |
1154 | mSelectionCellX * mGridSpacingX; | 1154 | mSelectionCellX * mGridSpacingX; |
1155 | contentsToViewport ( cx, cy, vx,vy); | 1155 | contentsToViewport ( cx, cy, vx,vy); |
1156 | // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; | 1156 | // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; |
1157 | if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) | 1157 | if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) |
1158 | bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); | 1158 | bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); |
1159 | 1159 | ||
1160 | if ( mSelectionHeight > 0 ) { | 1160 | if ( mSelectionHeight > 0 ) { |
1161 | //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); | 1161 | //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); |
1162 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && | 1162 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && |
1163 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { | 1163 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { |
1164 | contentsToViewport ( selectionX, mSelectionYTop, vx,vy); | 1164 | contentsToViewport ( selectionX, mSelectionYTop, vx,vy); |
1165 | bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); | 1165 | bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); |
1166 | } | 1166 | } |
1167 | } | 1167 | } |
1168 | //qDebug("btbl "); | 1168 | //qDebug("btbl "); |
1169 | p->begin( pd ); | 1169 | p->begin( pd ); |
1170 | //qDebug("end "); | 1170 | //qDebug("end "); |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | void KOAgenda::finishUpdate() | 1173 | void KOAgenda::finishUpdate() |
1174 | { | 1174 | { |
1175 | 1175 | ||
1176 | KOAgendaItem *item; | 1176 | KOAgendaItem *item; |
1177 | globalFlagBlockAgendaItemPaint = 1; | 1177 | globalFlagBlockAgendaItemPaint = 1; |
1178 | // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems | 1178 | // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems |
1179 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1179 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1180 | if ( !item->checkLayout() ) { | 1180 | if ( !item->checkLayout() ) { |
1181 | //qDebug(" conflictitem found "); | 1181 | //qDebug(" conflictitem found "); |
1182 | int newSubCellWidth; | 1182 | int newSubCellWidth; |
1183 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); | 1183 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); |
1184 | else newSubCellWidth = mGridSpacingX / item->subCells(); | 1184 | else newSubCellWidth = mGridSpacingX / item->subCells(); |
1185 | 1185 | ||
1186 | if (mAllDayMode) { | 1186 | if (mAllDayMode) { |
1187 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); | 1187 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); |
1188 | } else { | 1188 | } else { |
1189 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); | 1189 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); |
1190 | } | 1190 | } |
1191 | int x,y; | 1191 | int x,y; |
1192 | gridToContents(item->cellX(),item->cellYTop(),x,y); | 1192 | gridToContents(item->cellX(),item->cellYTop(),x,y); |
1193 | if (mAllDayMode) { | 1193 | if (mAllDayMode) { |
1194 | y += item->subCell() * newSubCellWidth; | 1194 | y += item->subCell() * newSubCellWidth; |
1195 | } else { | 1195 | } else { |
1196 | x += item->subCell() * newSubCellWidth; | 1196 | x += item->subCell() * newSubCellWidth; |
1197 | } | 1197 | } |
1198 | moveChild(item,x,y); | 1198 | moveChild(item,x,y); |
1199 | } | 1199 | } |
1200 | } | 1200 | } |
1201 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1201 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1202 | if ( !item->isVisible() ) | 1202 | if ( !item->isVisible() ) |
1203 | item->show(); | 1203 | item->show(); |
1204 | 1204 | ||
1205 | } | 1205 | } |
1206 | globalFlagBlockAgendaItemUpdate = 0; | 1206 | globalFlagBlockAgendaItemUpdate = 0; |
1207 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1207 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1208 | item->repaintMe( ); | 1208 | item->repaintMe( ); |
1209 | } | 1209 | } |
1210 | globalFlagBlockAgendaItemUpdate = 1; | 1210 | globalFlagBlockAgendaItemUpdate = 1; |
1211 | qApp->processEvents(); | 1211 | qApp->processEvents(); |
1212 | globalFlagBlockAgendaItemPaint = 0; | 1212 | globalFlagBlockAgendaItemPaint = 0; |
1213 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1213 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1214 | item->repaint( false ); | 1214 | item->repaint( false ); |
1215 | } | 1215 | } |
1216 | 1216 | ||
1217 | } | 1217 | } |
1218 | 1218 | ||
1219 | /* | 1219 | /* |
1220 | Draw grid in the background of the agenda. | 1220 | Draw grid in the background of the agenda. |
1221 | */ | 1221 | */ |
1222 | void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) | 1222 | void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) |
1223 | { | 1223 | { |
1224 | 1224 | ||
1225 | 1225 | ||
1226 | if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) | 1226 | if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) |
1227 | return; | 1227 | return; |
1228 | if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) | 1228 | if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) |
1229 | return; | 1229 | return; |
1230 | int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); | 1230 | int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); |
1231 | if ( ch < 1 ) | 1231 | if ( ch < 1 ) |
1232 | ch = 1; | 1232 | ch = 1; |
1233 | if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { | 1233 | if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { |
1234 | mPaintPixmap.resize( contentsWidth()+42, ch ); | 1234 | mPaintPixmap.resize( contentsWidth()+42, ch ); |
1235 | } | 1235 | } |
1236 | mCurPixWid = contentsWidth(); | 1236 | mCurPixWid = contentsWidth(); |
1237 | mCurPixHei = ch; | 1237 | mCurPixHei = ch; |
1238 | if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { | 1238 | if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { |
1239 | mHighlightPixmap.resize( mGridSpacingX-1, ch ); | 1239 | mHighlightPixmap.resize( mGridSpacingX-1, ch ); |
1240 | mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); | 1240 | mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); |
1241 | } | 1241 | } |
1242 | mPixPainter.begin( &mPaintPixmap) ; | 1242 | mPixPainter.begin( &mPaintPixmap) ; |
1243 | //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); | 1243 | //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); |
1244 | QPainter * p ; | 1244 | QPainter * p ; |
1245 | if (paint == 0) { | 1245 | if (paint == 0) { |
1246 | mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); | 1246 | mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); |
1247 | p = &mPixPainter; | 1247 | p = &mPixPainter; |
1248 | } | 1248 | } |
1249 | else | 1249 | else |
1250 | p = paint ; | 1250 | p = paint ; |
1251 | // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); | 1251 | // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); |
1252 | 1252 | ||
1253 | //--cx;++cw; | 1253 | //--cx;++cw; |
1254 | int lGridSpacingY = mGridSpacingY*2; | 1254 | int lGridSpacingY = mGridSpacingY*2; |
1255 | int selDay; | 1255 | int selDay; |
1256 | if ( !backgroundOnly ) | 1256 | if ( !backgroundOnly ) |
1257 | for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) | 1257 | for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) |
1258 | { | 1258 | { |
1259 | if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { | 1259 | if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { |
1260 | int x1 = cx; | 1260 | int x1 = cx; |
1261 | int y1 = 0; | 1261 | int y1 = 0; |
1262 | if (y1 < cy) y1 = cy; | 1262 | if (y1 < cy) y1 = cy; |
1263 | int x2 = cx+cw-1; | 1263 | int x2 = cx+cw-1; |
1264 | int y2 = contentsHeight(); | 1264 | int y2 = contentsHeight(); |
1265 | if (y2 > cy+ch-1) y2=cy+ch-1; | 1265 | if (y2 > cy+ch-1) y2=cy+ch-1; |
1266 | if (x2 >= x1 && y2 >= y1) { | 1266 | if (x2 >= x1 && y2 >= y1) { |
1267 | int gxStart = selDay; | 1267 | int gxStart = selDay; |
1268 | int gxEnd = gxStart ; | 1268 | int gxEnd = gxStart ; |
1269 | int xStart = KOGlobals::self()->reverseLayout() ? | 1269 | int xStart = KOGlobals::self()->reverseLayout() ? |
1270 | (mColumns - 1 - gxStart)*mGridSpacingX : | 1270 | (mColumns - 1 - gxStart)*mGridSpacingX : |
1271 | gxStart*mGridSpacingX; | 1271 | gxStart*mGridSpacingX; |
1272 | if (xStart < x1) xStart = x1; | 1272 | if (xStart < x1) xStart = x1; |
1273 | int xEnd = KOGlobals::self()->reverseLayout() ? | 1273 | int xEnd = KOGlobals::self()->reverseLayout() ? |
1274 | (mColumns - gxStart)*mGridSpacingX-1 : | 1274 | (mColumns - gxStart)*mGridSpacingX-1 : |
1275 | (gxStart+1)*mGridSpacingX-1; | 1275 | (gxStart+1)*mGridSpacingX-1; |
1276 | if (xEnd > x2) xEnd = x2; | 1276 | if (xEnd > x2) xEnd = x2; |
1277 | if ( KOPrefs::instance()->mUseHighlightLightColor ) | 1277 | if ( KOPrefs::instance()->mUseHighlightLightColor ) |
1278 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1278 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1279 | KOPrefs::instance()->mAgendaBgColor.light()); | 1279 | KOPrefs::instance()->mAgendaBgColor.light()); |
1280 | else | 1280 | else |
1281 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1281 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1282 | KOPrefs::instance()->mAgendaBgColor.dark()); | 1282 | KOPrefs::instance()->mAgendaBgColor.dark()); |
1283 | 1283 | ||
1284 | } | 1284 | } |
1285 | } | 1285 | } |
1286 | } | 1286 | } |
1287 | // Highlight working hours | 1287 | // Highlight working hours |
1288 | 1288 | ||
1289 | if ( !backgroundOnly ) | 1289 | if ( !backgroundOnly ) |
1290 | if (mWorkingHoursEnable) { | 1290 | if (mWorkingHoursEnable) { |
1291 | int x1 = cx; | 1291 | int x1 = cx; |
1292 | int y1 = mWorkingHoursYTop; | 1292 | int y1 = mWorkingHoursYTop; |
1293 | if (y1 < cy) y1 = cy; | 1293 | if (y1 < cy) y1 = cy; |
1294 | int x2 = cx+cw-1; | 1294 | int x2 = cx+cw-1; |
1295 | // int x2 = mGridSpacingX * 5 - 1; | 1295 | // int x2 = mGridSpacingX * 5 - 1; |
1296 | // if (x2 > cx+cw-1) x2 = cx + cw - 1; | 1296 | // if (x2 > cx+cw-1) x2 = cx + cw - 1; |
1297 | int y2 = mWorkingHoursYBottom; | 1297 | int y2 = mWorkingHoursYBottom; |
1298 | if (y2 > cy+ch-1) y2=cy+ch-1; | 1298 | if (y2 > cy+ch-1) y2=cy+ch-1; |
1299 | 1299 | ||
1300 | if (x2 >= x1 && y2 >= y1) { | 1300 | if (x2 >= x1 && y2 >= y1) { |
1301 | // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); | 1301 | // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); |
1302 | int gxStart = x1/mGridSpacingX; | 1302 | int gxStart = x1/mGridSpacingX; |
1303 | int gxEnd = x2/mGridSpacingX; | 1303 | int gxEnd = x2/mGridSpacingX; |
1304 | while(gxStart <= gxEnd) { | 1304 | while(gxStart <= gxEnd) { |
1305 | if (gxStart < int(mHolidayMask->count()) && | 1305 | if (gxStart < int(mHolidayMask->count()) && |
1306 | !mHolidayMask->at(gxStart)) { | 1306 | !mHolidayMask->at(gxStart)) { |
1307 | int xStart = KOGlobals::self()->reverseLayout() ? | 1307 | int xStart = KOGlobals::self()->reverseLayout() ? |
1308 | (mColumns - 1 - gxStart)*mGridSpacingX : | 1308 | (mColumns - 1 - gxStart)*mGridSpacingX : |
1309 | gxStart*mGridSpacingX; | 1309 | gxStart*mGridSpacingX; |
1310 | if (xStart < x1) xStart = x1; | 1310 | if (xStart < x1) xStart = x1; |
1311 | int xEnd = KOGlobals::self()->reverseLayout() ? | 1311 | int xEnd = KOGlobals::self()->reverseLayout() ? |
1312 | (mColumns - gxStart)*mGridSpacingX-1 : | 1312 | (mColumns - gxStart)*mGridSpacingX-1 : |
1313 | (gxStart+1)*mGridSpacingX-1; | 1313 | (gxStart+1)*mGridSpacingX-1; |
1314 | if (xEnd > x2) xEnd = x2; | 1314 | if (xEnd > x2) xEnd = x2; |
1315 | if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { | 1315 | if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { |
1316 | if ( KOPrefs::instance()->mUseHighlightLightColor ) | 1316 | if ( KOPrefs::instance()->mUseHighlightLightColor ) |
1317 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1317 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1318 | KOPrefs::instance()->mWorkingHoursColor.light()); | 1318 | KOPrefs::instance()->mWorkingHoursColor.light()); |
1319 | else | 1319 | else |
1320 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1320 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1321 | KOPrefs::instance()->mWorkingHoursColor.dark()); | 1321 | KOPrefs::instance()->mWorkingHoursColor.dark()); |
1322 | } else { | 1322 | } else { |
1323 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1323 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1324 | KOPrefs::instance()->mWorkingHoursColor); | 1324 | KOPrefs::instance()->mWorkingHoursColor); |
1325 | } | 1325 | } |
1326 | } | 1326 | } |
1327 | ++gxStart; | 1327 | ++gxStart; |
1328 | } | 1328 | } |
1329 | } | 1329 | } |
1330 | } | 1330 | } |
1331 | /* | 1331 | /* |
1332 | int selectionX = KOGlobals::self()->reverseLayout() ? | 1332 | int selectionX = KOGlobals::self()->reverseLayout() ? |
1333 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : | 1333 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : |
1334 | mSelectionCellX * mGridSpacingX; | 1334 | mSelectionCellX * mGridSpacingX; |
1335 | 1335 | ||
1336 | // Draw selection | 1336 | // Draw selection |
1337 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && | 1337 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && |
1338 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { | 1338 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { |
1339 | // TODO: paint only part within cx,cy,cw,ch | 1339 | // TODO: paint only part within cx,cy,cw,ch |
1340 | p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, | 1340 | p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, |
1341 | mSelectionHeight, KOPrefs::instance()->mHighlightColor ); | 1341 | mSelectionHeight, KOPrefs::instance()->mHighlightColor ); |
1342 | } | 1342 | } |
1343 | */ | 1343 | */ |
1344 | // Draw vertical lines of grid | 1344 | // Draw vertical lines of grid |
1345 | 1345 | ||
1346 | int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; | 1346 | int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; |
1347 | if ( mGridSpacingX > 0 ) { | 1347 | if ( mGridSpacingX > 0 ) { |
1348 | while (x < cx + cw) { | 1348 | while (x < cx + cw) { |
1349 | p->drawLine(x,cy,x,cy+ch); | 1349 | p->drawLine(x,cy,x,cy+ch); |
1350 | x+=mGridSpacingX; | 1350 | x+=mGridSpacingX; |
1351 | } | 1351 | } |
1352 | } | 1352 | } |
1353 | // Draw horizontal lines of grid | 1353 | // Draw horizontal lines of grid |
1354 | int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; | 1354 | int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; |
1355 | if ( lGridSpacingY > 0 ) { | 1355 | if ( lGridSpacingY > 0 ) { |
1356 | while (y < cy + ch) { | 1356 | while (y < cy + ch) { |
1357 | p->setPen( SolidLine ); | 1357 | p->setPen( SolidLine ); |
1358 | p->drawLine(cx,y,cx+cw,y); | 1358 | p->drawLine(cx,y,cx+cw,y); |
1359 | y+=lGridSpacingY; | 1359 | y+=lGridSpacingY; |
1360 | p->setPen( DotLine ); | 1360 | p->setPen( DotLine ); |
1361 | p->drawLine(cx,y,cx+cw,y); | 1361 | p->drawLine(cx,y,cx+cw,y); |
1362 | y+=lGridSpacingY; | 1362 | y+=lGridSpacingY; |
1363 | } | 1363 | } |
1364 | p->setPen( SolidLine ); | 1364 | p->setPen( SolidLine ); |
1365 | } | 1365 | } |
1366 | mPixPainter.end() ; | 1366 | mPixPainter.end() ; |
1367 | } | 1367 | } |
1368 | 1368 | ||
1369 | /* | 1369 | /* |
1370 | Convert srcollview contents coordinates to agenda grid coordinates. | 1370 | Convert srcollview contents coordinates to agenda grid coordinates. |
1371 | */ | 1371 | */ |
1372 | void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) | 1372 | void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) |
1373 | { | 1373 | { |
1374 | gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : | 1374 | gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : |
1375 | x/mGridSpacingX; | 1375 | x/mGridSpacingX; |
1376 | gy = y/mGridSpacingY; | 1376 | gy = y/mGridSpacingY; |
1377 | } | 1377 | } |
1378 | 1378 | ||
1379 | /* | 1379 | /* |
1380 | Convert agenda grid coordinates to scrollview contents coordinates. | 1380 | Convert agenda grid coordinates to scrollview contents coordinates. |
1381 | */ | 1381 | */ |
1382 | void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) | 1382 | void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) |
1383 | { | 1383 | { |
1384 | x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: | 1384 | x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: |
1385 | gx*mGridSpacingX; | 1385 | gx*mGridSpacingX; |
1386 | y = gy*mGridSpacingY; | 1386 | y = gy*mGridSpacingY; |
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | 1389 | ||
1390 | /* | 1390 | /* |
1391 | Return Y coordinate corresponding to time. Coordinates are rounded to fit into | 1391 | Return Y coordinate corresponding to time. Coordinates are rounded to fit into |
1392 | the grid. | 1392 | the grid. |
1393 | */ | 1393 | */ |
1394 | int KOAgenda::timeToY(const QTime &time) | 1394 | int KOAgenda::timeToY(const QTime &time) |
1395 | { | 1395 | { |
1396 | int minutesPerCell = 24 * 60 / mRows; | 1396 | int minutesPerCell = 24 * 60 / mRows; |
1397 | int timeMinutes = time.hour() * 60 + time.minute(); | 1397 | int timeMinutes = time.hour() * 60 + time.minute(); |
1398 | int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; | 1398 | int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; |
1399 | return Y; | 1399 | return Y; |
1400 | } | 1400 | } |
1401 | 1401 | ||
1402 | 1402 | ||
1403 | /* | 1403 | /* |
1404 | Return time corresponding to cell y coordinate. Coordinates are rounded to | 1404 | Return time corresponding to cell y coordinate. Coordinates are rounded to |
1405 | fit into the grid. | 1405 | fit into the grid. |
1406 | */ | 1406 | */ |
1407 | QTime KOAgenda::gyToTime(int gy) | 1407 | QTime KOAgenda::gyToTime(int gy) |
1408 | { | 1408 | { |
1409 | 1409 | ||
1410 | int secondsPerCell = 24 * 60 * 60/ mRows; | 1410 | int secondsPerCell = 24 * 60 * 60/ mRows; |
1411 | 1411 | ||
1412 | int timeSeconds = secondsPerCell * gy; | 1412 | int timeSeconds = secondsPerCell * gy; |
1413 | 1413 | ||
1414 | QTime time( 0, 0, 0 ); | 1414 | QTime time( 0, 0, 0 ); |
1415 | if ( timeSeconds < 24 * 60 * 60 ) { | 1415 | if ( timeSeconds < 24 * 60 * 60 ) { |
1416 | time = time.addSecs(timeSeconds); | 1416 | time = time.addSecs(timeSeconds); |
1417 | } else { | 1417 | } else { |
1418 | time.setHMS( 23, 59, 59 ); | 1418 | time.setHMS( 23, 59, 59 ); |
1419 | } | 1419 | } |
1420 | 1420 | ||
1421 | return time; | 1421 | return time; |
1422 | } | 1422 | } |
1423 | 1423 | ||
1424 | void KOAgenda::setStartHour(int startHour) | 1424 | void KOAgenda::setStartHour(int startHour) |
1425 | { | 1425 | { |
1426 | int startCell = startHour * mRows / 24; | 1426 | int startCell = startHour * mRows / 24; |
1427 | setContentsPos(0,startCell * gridSpacingY()); | 1427 | setContentsPos(0,startCell * gridSpacingY()); |
1428 | } | 1428 | } |
1429 | void KOAgenda::hideUnused() | 1429 | void KOAgenda::hideUnused() |
1430 | { | 1430 | { |
1431 | // experimental only | 1431 | // experimental only |
1432 | // return; | 1432 | // return; |
1433 | KOAgendaItem *item; | 1433 | KOAgendaItem *item; |
1434 | for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { | 1434 | for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { |
1435 | item->hide(); | 1435 | item->hide(); |
1436 | } | 1436 | } |
1437 | } | 1437 | } |
1438 | 1438 | ||
1439 | 1439 | ||
1440 | KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) | 1440 | KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) |
1441 | { | 1441 | { |
1442 | 1442 | ||
1443 | KOAgendaItem *fi; | 1443 | KOAgendaItem *fi; |
1444 | for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { | 1444 | for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { |
1445 | if ( fi->incidence() == event ) { | 1445 | if ( fi->incidence() == event ) { |
1446 | mUnusedItems.remove(); | 1446 | mUnusedItems.remove(); |
1447 | fi->init( event, qd ); | 1447 | fi->init( event, qd ); |
1448 | return fi; | 1448 | return fi; |
1449 | } | 1449 | } |
1450 | } | 1450 | } |
1451 | fi=mUnusedItems.first(); | 1451 | fi=mUnusedItems.first(); |
1452 | if ( fi ) { | 1452 | if ( fi ) { |
1453 | mUnusedItems.remove(); | 1453 | mUnusedItems.remove(); |
1454 | fi->init( event, qd ); | 1454 | fi->init( event, qd ); |
1455 | return fi; | 1455 | return fi; |
1456 | } | 1456 | } |
1457 | // qDebug("new KOAgendaItem "); | 1457 | // qDebug("new KOAgendaItem "); |
1458 | 1458 | ||
1459 | KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); | 1459 | KOAgendaItem* agendaItem = new KOAgendaItem( event, qd, view, mAllDayMode ); |
1460 | agendaItem->installEventFilter(this); | 1460 | agendaItem->installEventFilter(this); |
1461 | addChild(agendaItem,0,0); | 1461 | addChild(agendaItem,0,0); |
1462 | return agendaItem; | 1462 | return agendaItem; |
1463 | } | 1463 | } |
1464 | KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) | 1464 | KOAgendaItem * KOAgenda::getItemForTodo ( Todo * todo ) |
1465 | { | 1465 | { |
1466 | KOAgendaItem *item; | 1466 | KOAgendaItem *item; |
1467 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1467 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1468 | if ( item->incidence() == todo ) { | 1468 | if ( item->incidence() == todo ) { |
1469 | mItems.remove(); | 1469 | mItems.remove(); |
1470 | return item; | 1470 | return item; |
1471 | } | 1471 | } |
1472 | } | 1472 | } |
1473 | return 0; | 1473 | return 0; |
1474 | } | 1474 | } |
1475 | 1475 | ||
1476 | 1476 | ||
1477 | void KOAgenda::updateTodo( Todo * todo, int days, bool remove) | 1477 | void KOAgenda::updateTodo( Todo * todo, int days, bool remove) |
1478 | { | 1478 | { |
1479 | // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| | 1479 | // ( todo->hasCompletedDate() && todo->completed().date() == currentDate )|| |
1480 | KOAgendaItem *item; | 1480 | KOAgendaItem *item; |
1481 | item = getItemForTodo ( todo ); | 1481 | item = getItemForTodo ( todo ); |
1482 | //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); | 1482 | //qDebug("KOAgenda::updateTodo %d %d %d %d", this, todo, days, remove); |
1483 | if ( item ) { | 1483 | if ( item ) { |
1484 | blockSignals( true ); | 1484 | blockSignals( true ); |
1485 | //qDebug("item found "); | 1485 | //qDebug("item found "); |
1486 | item->hide(); | 1486 | item->hide(); |
1487 | item->setCellX(-2, -1 ); | 1487 | item->setCellX(-2, -1 ); |
1488 | item->select(false); | 1488 | item->select(false); |
1489 | mUnusedItems.append( item ); | 1489 | mUnusedItems.append( item ); |
1490 | mItems.remove( item ); | 1490 | mItems.remove( item ); |
1491 | QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); | 1491 | QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); |
1492 | KOAgendaItem *itemit; | 1492 | KOAgendaItem *itemit; |
1493 | //globalFlagBlockAgendaItemPaint = 1; | 1493 | //globalFlagBlockAgendaItemPaint = 1; |
1494 | for ( itemit=oldconflictItems.first(); itemit != 0; | 1494 | for ( itemit=oldconflictItems.first(); itemit != 0; |
1495 | itemit=oldconflictItems.next() ) { | 1495 | itemit=oldconflictItems.next() ) { |
1496 | if ( itemit != item ) | 1496 | if ( itemit != item ) |
1497 | placeSubCells(itemit); | 1497 | placeSubCells(itemit); |
1498 | } | 1498 | } |
1499 | qApp->processEvents(); | 1499 | qApp->processEvents(); |
1500 | //globalFlagBlockAgendaItemPaint = 0; | 1500 | //globalFlagBlockAgendaItemPaint = 0; |
1501 | for ( itemit=oldconflictItems.first(); itemit != 0; | 1501 | for ( itemit=oldconflictItems.first(); itemit != 0; |
1502 | itemit=oldconflictItems.next() ) { | 1502 | itemit=oldconflictItems.next() ) { |
1503 | globalFlagBlockAgendaItemUpdate = 0; | 1503 | globalFlagBlockAgendaItemUpdate = 0; |
1504 | if ( itemit != item ) | 1504 | if ( itemit != item ) |
1505 | itemit->repaintMe(); | 1505 | itemit->repaintMe(); |
1506 | globalFlagBlockAgendaItemUpdate = 1; | 1506 | globalFlagBlockAgendaItemUpdate = 1; |
1507 | itemit->repaint(); | 1507 | itemit->repaint(); |
1508 | } | 1508 | } |
1509 | blockSignals( false ); | 1509 | blockSignals( false ); |
1510 | } | 1510 | } |
1511 | if ( remove ) { | 1511 | if ( remove ) { |
1512 | //qDebug("remove****************************************** "); | 1512 | //qDebug("remove****************************************** "); |
1513 | return; | 1513 | return; |
1514 | } | 1514 | } |
1515 | //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); | 1515 | //qDebug("updateTodo+++++++++++++++++++++++++++++++++++++ "); |
1516 | bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); | 1516 | bool overdue = (!todo->isCompleted()) && (todo->dtDue() < QDate::currentDate())&& ( KOPrefs::instance()->mShowTodoInAgenda ); |
1517 | QDate currentDate; | 1517 | QDate currentDate; |
1518 | QDateTime dt; | 1518 | QDateTime dt; |
1519 | if ( todo->hasCompletedDate() ) | 1519 | if ( todo->hasCompletedDate() ) |
1520 | dt = todo->completed(); | 1520 | dt = todo->completed(); |
1521 | else | 1521 | else |
1522 | dt = todo->dtDue(); | 1522 | dt = todo->dtDue(); |
1523 | if ( overdue ) { | 1523 | if ( overdue ) { |
1524 | currentDate = QDate::currentDate(); | 1524 | currentDate = QDate::currentDate(); |
1525 | days += todo->dtDue().date().daysTo( currentDate ); | 1525 | days += todo->dtDue().date().daysTo( currentDate ); |
1526 | } | 1526 | } |
1527 | else | 1527 | else |
1528 | currentDate = dt.date(); | 1528 | currentDate = dt.date(); |
1529 | 1529 | ||
1530 | if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { | 1530 | if (( todo->doesFloat() || overdue) && !todo->hasCompletedDate() ) { |
1531 | if ( ! mAllDayMode ) return; | 1531 | if ( ! mAllDayMode ) return; |
1532 | // aldayagenda | 1532 | // aldayagenda |
1533 | globalFlagBlockAgendaItemPaint = 1; | 1533 | globalFlagBlockAgendaItemPaint = 1; |
1534 | item = insertAllDayItem(todo, currentDate,days, days); | 1534 | item = insertAllDayItem(todo, currentDate,days, days); |
1535 | item->show(); | 1535 | item->show(); |
1536 | 1536 | ||
1537 | } | 1537 | } |
1538 | else { | 1538 | else { |
1539 | if ( mAllDayMode ) return; | 1539 | if ( mAllDayMode ) return; |
1540 | // mAgenda | 1540 | // mAgenda |
1541 | globalFlagBlockAgendaItemPaint = 1; | 1541 | globalFlagBlockAgendaItemPaint = 1; |
1542 | int endY = timeToY(dt.time()) - 1; | 1542 | int endY = timeToY(dt.time()) - 1; |
1543 | int hi = 12/KOPrefs::instance()->mHourSize; | 1543 | int hi = 12/KOPrefs::instance()->mHourSize; |
1544 | int startY = endY - 1-hi; | 1544 | int startY = endY - 1-hi; |
1545 | item = insertItem(todo,currentDate,days,startY,endY); | 1545 | item = insertItem(todo,currentDate,days,startY,endY); |
1546 | item->show(); | 1546 | item->show(); |
1547 | } | 1547 | } |
1548 | qApp->processEvents(); | 1548 | qApp->processEvents(); |
1549 | globalFlagBlockAgendaItemPaint = 0; | 1549 | globalFlagBlockAgendaItemPaint = 0; |
1550 | QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); | 1550 | QPtrList<KOAgendaItem> oldconflictItems = item->conflictItems(); |
1551 | KOAgendaItem *itemit; | 1551 | KOAgendaItem *itemit; |
1552 | for ( itemit=oldconflictItems.first(); itemit != 0; | 1552 | for ( itemit=oldconflictItems.first(); itemit != 0; |
1553 | itemit=oldconflictItems.next() ) { | 1553 | itemit=oldconflictItems.next() ) { |
1554 | globalFlagBlockAgendaItemUpdate = 0; | 1554 | globalFlagBlockAgendaItemUpdate = 0; |
1555 | itemit->repaintMe(); | 1555 | itemit->repaintMe(); |
1556 | globalFlagBlockAgendaItemUpdate = 1; | 1556 | globalFlagBlockAgendaItemUpdate = 1; |
1557 | itemit->repaint(); | 1557 | itemit->repaint(); |
1558 | } | 1558 | } |
1559 | globalFlagBlockAgendaItemUpdate = 0; | 1559 | globalFlagBlockAgendaItemUpdate = 0; |
1560 | item->repaintMe(); | 1560 | item->repaintMe(); |
1561 | globalFlagBlockAgendaItemUpdate = 1; | 1561 | globalFlagBlockAgendaItemUpdate = 1; |
1562 | item->repaint(); | 1562 | item->repaint(); |
1563 | } | 1563 | } |
1564 | /* | 1564 | /* |
1565 | Insert KOAgendaItem into agenda. | 1565 | Insert KOAgendaItem into agenda. |
1566 | */ | 1566 | */ |
1567 | KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) | 1567 | KOAgendaItem *KOAgenda::insertItem (Incidence *event,QDate qd,int X,int YTop,int YBottom) |
1568 | { | 1568 | { |
1569 | //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl; | 1569 | //kdDebug() << "KOAgenda::insertItem:" << event->summary() << "-" << qd.toString() << " ;top, bottom:" << YTop << "," << YBottom << endl; |
1570 | 1570 | ||
1571 | if (mAllDayMode) { | 1571 | if (mAllDayMode) { |
1572 | kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl; | 1572 | kdDebug() << "KOAgenda: calling insertItem in all-day mode is illegal." << endl; |
1573 | return 0; | 1573 | return 0; |
1574 | } | 1574 | } |
1575 | 1575 | ||
1576 | KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); | 1576 | KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); |
1577 | //agendaItem->setFrameStyle(WinPanel|Raised); | 1577 | //agendaItem->setFrameStyle(WinPanel|Raised); |
1578 | 1578 | ||
1579 | int YSize = YBottom - YTop + 1; | 1579 | int YSize = YBottom - YTop + 1; |
1580 | if (YSize < 0) { | 1580 | if (YSize < 0) { |
1581 | kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl; | 1581 | kdDebug() << "KOAgenda::insertItem(): Text: " << agendaItem->text() << " YSize<0" << endl; |
1582 | YSize = 1; | 1582 | YSize = 1; |
1583 | } | 1583 | } |
1584 | int iheight = mGridSpacingY * YSize; | 1584 | int iheight = mGridSpacingY * YSize; |
1585 | 1585 | ||
1586 | agendaItem->resize(mGridSpacingX,iheight ); | 1586 | agendaItem->resize(mGridSpacingX,iheight ); |
1587 | agendaItem->setCellXY(X,YTop,YBottom); | 1587 | agendaItem->setCellXY(X,YTop,YBottom); |
1588 | agendaItem->setCellXWidth(X); | 1588 | agendaItem->setCellXWidth(X); |
1589 | 1589 | ||
1590 | //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); | 1590 | //addChild(agendaItem,X*mGridSpacingX,YTop*mGridSpacingY); |
1591 | mItems.append(agendaItem); | 1591 | mItems.append(agendaItem); |
1592 | 1592 | ||
1593 | placeSubCells(agendaItem); | 1593 | placeSubCells(agendaItem); |
1594 | 1594 | ||
1595 | //agendaItem->show(); | 1595 | //agendaItem->show(); |
1596 | 1596 | ||
1597 | marcus_bains(); | 1597 | marcus_bains(); |
1598 | 1598 | ||
1599 | return agendaItem; | 1599 | return agendaItem; |
1600 | } | 1600 | } |
1601 | 1601 | ||
1602 | 1602 | ||
1603 | /* | 1603 | /* |
1604 | Insert all-day KOAgendaItem into agenda. | 1604 | Insert all-day KOAgendaItem into agenda. |
1605 | */ | 1605 | */ |
1606 | KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) | 1606 | KOAgendaItem *KOAgenda::insertAllDayItem (Incidence *event,QDate qd,int XBegin,int XEnd) |
1607 | { | 1607 | { |
1608 | if (!mAllDayMode) { | 1608 | if (!mAllDayMode) { |
1609 | return 0; | 1609 | return 0; |
1610 | } | 1610 | } |
1611 | 1611 | ||
1612 | KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); | 1612 | KOAgendaItem *agendaItem = getNewItem(event,qd,viewport()); |
1613 | 1613 | ||
1614 | agendaItem->setCellXY(XBegin,0,0); | 1614 | agendaItem->setCellXY(XBegin,0,0); |
1615 | agendaItem->setCellXWidth(XEnd); | 1615 | agendaItem->setCellXWidth(XEnd); |
1616 | agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); | 1616 | agendaItem->resize(mGridSpacingX * agendaItem->cellWidth(),mGridSpacingY); |
1617 | 1617 | ||
1618 | //addChild(agendaItem,XBegin*mGridSpacingX,0); | 1618 | //addChild(agendaItem,XBegin*mGridSpacingX,0); |
1619 | mItems.append(agendaItem); | 1619 | mItems.append(agendaItem); |
1620 | 1620 | ||
1621 | placeSubCells(agendaItem); | 1621 | placeSubCells(agendaItem); |
1622 | 1622 | ||
1623 | //agendaItem->show(); | 1623 | //agendaItem->show(); |
1624 | 1624 | ||
1625 | return agendaItem; | 1625 | return agendaItem; |
1626 | } | 1626 | } |
1627 | 1627 | ||
1628 | 1628 | ||
1629 | void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, | 1629 | void KOAgenda::insertMultiItem (Event *event,QDate qd,int XBegin,int XEnd, |
1630 | int YTop,int YBottom) | 1630 | int YTop,int YBottom) |
1631 | { | 1631 | { |
1632 | if (mAllDayMode) { | 1632 | if (mAllDayMode) { |
1633 | ; | 1633 | ; |
1634 | return; | 1634 | return; |
1635 | } | 1635 | } |
1636 | 1636 | ||
1637 | int cellX,cellYTop,cellYBottom; | 1637 | int cellX,cellYTop,cellYBottom; |
1638 | QString newtext; | 1638 | QString newtext; |
1639 | int width = XEnd - XBegin + 1; | 1639 | int width = XEnd - XBegin + 1; |
1640 | int count = 0; | 1640 | int count = 0; |
1641 | KOAgendaItem *current = 0; | 1641 | KOAgendaItem *current = 0; |
1642 | QPtrList<KOAgendaItem> multiItems; | 1642 | QPtrList<KOAgendaItem> multiItems; |
1643 | for (cellX = XBegin;cellX <= XEnd;++cellX) { | 1643 | for (cellX = XBegin;cellX <= XEnd;++cellX) { |
1644 | if (cellX == XBegin) cellYTop = YTop; | 1644 | if (cellX == XBegin) cellYTop = YTop; |
1645 | else cellYTop = 0; | 1645 | else cellYTop = 0; |
1646 | if (cellX == XEnd) cellYBottom = YBottom; | 1646 | if (cellX == XEnd) cellYBottom = YBottom; |
1647 | else cellYBottom = rows() - 1; | 1647 | else cellYBottom = rows() - 1; |
1648 | newtext = QString("(%1/%2): ").arg(++count).arg(width); | 1648 | newtext = QString("(%1/%2): ").arg(++count).arg(width); |
1649 | newtext.append(event->summary()); | 1649 | newtext.append(event->summary()); |
1650 | current = insertItem(event,qd,cellX,cellYTop,cellYBottom); | 1650 | current = insertItem(event,qd,cellX,cellYTop,cellYBottom); |
1651 | current->setText(newtext); | 1651 | current->setText(newtext); |
1652 | multiItems.append(current); | 1652 | multiItems.append(current); |
1653 | } | 1653 | } |
1654 | 1654 | ||
1655 | KOAgendaItem *next = 0; | 1655 | KOAgendaItem *next = 0; |
1656 | KOAgendaItem *last = multiItems.last(); | 1656 | KOAgendaItem *last = multiItems.last(); |
1657 | KOAgendaItem *first = multiItems.first(); | 1657 | KOAgendaItem *first = multiItems.first(); |
1658 | KOAgendaItem *setFirst,*setLast; | 1658 | KOAgendaItem *setFirst,*setLast; |
1659 | current = first; | 1659 | current = first; |
1660 | while (current) { | 1660 | while (current) { |
1661 | next = multiItems.next(); | 1661 | next = multiItems.next(); |
1662 | if (current == first) setFirst = 0; | 1662 | if (current == first) setFirst = 0; |
1663 | else setFirst = first; | 1663 | else setFirst = first; |
1664 | if (current == last) setLast = 0; | 1664 | if (current == last) setLast = 0; |
1665 | else setLast = last; | 1665 | else setLast = last; |
1666 | 1666 | ||
1667 | current->setMultiItem(setFirst,next,setLast); | 1667 | current->setMultiItem(setFirst,next,setLast); |
1668 | current = next; | 1668 | current = next; |
1669 | } | 1669 | } |
1670 | 1670 | ||
1671 | marcus_bains(); | 1671 | marcus_bains(); |
1672 | } | 1672 | } |
1673 | 1673 | ||
1674 | 1674 | ||
1675 | //QSizePolicy KOAgenda::sizePolicy() const | 1675 | //QSizePolicy KOAgenda::sizePolicy() const |
1676 | //{ | 1676 | //{ |
1677 | // Thought this would make the all-day event agenda minimum size and the | 1677 | // Thought this would make the all-day event agenda minimum size and the |
1678 | // normal agenda take the remaining space. But it doesn´t work. The QSplitter | 1678 | // normal agenda take the remaining space. But it doesn´t work. The QSplitter |
1679 | // don´t seem to think that an Expanding widget needs more space than a | 1679 | // don´t seem to think that an Expanding widget needs more space than a |
1680 | // Preferred one. | 1680 | // Preferred one. |
1681 | // But it doesn´t hurt, so it stays. | 1681 | // But it doesn´t hurt, so it stays. |
1682 | // if (mAllDayMode) { | 1682 | // if (mAllDayMode) { |
1683 | // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); | 1683 | // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); |
1684 | // } else { | 1684 | // } else { |
1685 | // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); | 1685 | // return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); |
1686 | // } | 1686 | // } |
1687 | //} | 1687 | //} |
1688 | void KOAgenda::finishResize ( ) | 1688 | void KOAgenda::finishResize ( ) |
1689 | { | 1689 | { |
1690 | //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); | 1690 | //qDebug("finishResize+++++++++++++++++++++++++++++++ ( ) "); |
1691 | if ( globalFlagBlockAgenda == 0 ) { | 1691 | if ( globalFlagBlockAgenda == 0 ) { |
1692 | finishUpdate(); | 1692 | finishUpdate(); |
1693 | //qDebug("finishUpdate() called "); | 1693 | //qDebug("finishUpdate() called "); |
1694 | } | 1694 | } |
1695 | } | 1695 | } |
1696 | /* | 1696 | /* |
1697 | Overridden from QScrollView to provide proper resizing of KOAgendaItems. | 1697 | Overridden from QScrollView to provide proper resizing of KOAgendaItems. |
1698 | */ | 1698 | */ |
1699 | void KOAgenda::resizeEvent ( QResizeEvent *ev ) | 1699 | void KOAgenda::resizeEvent ( QResizeEvent *ev ) |
1700 | { | 1700 | { |
1701 | 1701 | ||
1702 | mResizeTimer.start( 150 , true ); | 1702 | mResizeTimer.start( 150 , true ); |
1703 | computeSizes(); | 1703 | computeSizes(); |
1704 | return; | 1704 | return; |
1705 | 1705 | ||
1706 | } | 1706 | } |
1707 | void KOAgenda::computeSizes() | 1707 | void KOAgenda::computeSizes() |
1708 | { | 1708 | { |
1709 | if ( globalFlagBlockStartup ) | 1709 | if ( globalFlagBlockStartup ) |
1710 | return; | 1710 | return; |
1711 | 1711 | ||
1712 | if (mAllDayMode) { | 1712 | if (mAllDayMode) { |
1713 | mGridSpacingX = (width()-3) / mColumns; | 1713 | mGridSpacingX = (width()-3) / mColumns; |
1714 | mGridSpacingY = height() - 2 * frameWidth() - 1; | 1714 | mGridSpacingY = height() - 2 * frameWidth() - 1; |
1715 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); | 1715 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY + 1); |
1716 | // mGridSpacingY = height(); | 1716 | // mGridSpacingY = height(); |
1717 | // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); | 1717 | // resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); |
1718 | 1718 | ||
1719 | KOAgendaItem *item; | 1719 | KOAgendaItem *item; |
1720 | int subCellWidth; | 1720 | int subCellWidth; |
1721 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1721 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1722 | subCellWidth = mGridSpacingY / item->subCells(); | 1722 | subCellWidth = mGridSpacingY / item->subCells(); |
1723 | item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); | 1723 | item->resize(mGridSpacingX * item->cellWidth(),subCellWidth); |
1724 | moveChild(item,KOGlobals::self()->reverseLayout() ? | 1724 | moveChild(item,KOGlobals::self()->reverseLayout() ? |
1725 | (mColumns - 1 - item->cellX()) * mGridSpacingX : | 1725 | (mColumns - 1 - item->cellX()) * mGridSpacingX : |
1726 | item->cellX() * mGridSpacingX, | 1726 | item->cellX() * mGridSpacingX, |
1727 | item->subCell() * subCellWidth); | 1727 | item->subCell() * subCellWidth); |
1728 | } | 1728 | } |
1729 | KOPrefs::instance()->mAllDaySize = mGridSpacingY; | 1729 | KOPrefs::instance()->mAllDaySize = mGridSpacingY; |
1730 | } else { | 1730 | } else { |
1731 | mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns; | 1731 | mGridSpacingX = (width() - verticalScrollBar()->width()-3)/mColumns; |
1732 | if (height() > mGridSpacingY * mRows + 1 ) { | 1732 | if (height() > mGridSpacingY * mRows + 1 ) { |
1733 | KOPrefs::instance()->mHourSize = ((height())/mRows)+1; | 1733 | KOPrefs::instance()->mHourSize = ((height())/mRows)+1; |
1734 | mGridSpacingY = KOPrefs::instance()->mHourSize ; | 1734 | mGridSpacingY = KOPrefs::instance()->mHourSize ; |
1735 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); | 1735 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); |
1736 | emit resizedSignal(); | 1736 | emit resizedSignal(); |
1737 | } else | 1737 | } else |
1738 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); | 1738 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); |
1739 | KOAgendaItem *item; | 1739 | KOAgendaItem *item; |
1740 | int subCellWidth; | 1740 | int subCellWidth; |
1741 | 1741 | ||
1742 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1742 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1743 | subCellWidth = mGridSpacingX / item->subCells(); | 1743 | subCellWidth = mGridSpacingX / item->subCells(); |
1744 | item->resize(subCellWidth,item->height()); | 1744 | item->resize(subCellWidth,item->height()); |
1745 | moveChild(item,(KOGlobals::self()->reverseLayout() ? | 1745 | moveChild(item,(KOGlobals::self()->reverseLayout() ? |
1746 | (mColumns - 1 - item->cellX()) * mGridSpacingX : | 1746 | (mColumns - 1 - item->cellX()) * mGridSpacingX : |
1747 | item->cellX() * mGridSpacingX) + | 1747 | item->cellX() * mGridSpacingX) + |
1748 | item->subCell() * subCellWidth,childY(item)); | 1748 | item->subCell() * subCellWidth,childY(item)); |
1749 | } | 1749 | } |
1750 | } | 1750 | } |
1751 | int cw = contentsWidth(); | 1751 | int cw = contentsWidth(); |
1752 | int ch = contentsHeight(); | 1752 | int ch = contentsHeight(); |
1753 | if ( mAllDayMode ) { | 1753 | if ( mAllDayMode ) { |
1754 | QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); | 1754 | QPixmap* paintPixAll = KOAgendaItem::paintPixAllday(); |
1755 | if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) | 1755 | if ( (paintPixAll->width() < cw || paintPixAll->height() < ch) && cw > 0 && ch > 0 ) |
1756 | paintPixAll->resize( cw, ch ); | 1756 | paintPixAll->resize( cw, ch ); |
1757 | } else { | 1757 | } else { |
1758 | QPixmap* paintPix = KOAgendaItem::paintPix(); | 1758 | QPixmap* paintPix = KOAgendaItem::paintPix(); |
1759 | if ( paintPix->width() < cw || paintPix->height() < ch ) | 1759 | if ( paintPix->width() < cw || paintPix->height() < ch ) |
1760 | KOAgendaItem::resizePixmap( cw , ch ); | 1760 | KOAgendaItem::resizePixmap( cw , ch ); |
1761 | } | 1761 | } |
1762 | 1762 | ||
1763 | checkScrollBoundaries(); | 1763 | checkScrollBoundaries(); |
1764 | marcus_bains(); | 1764 | marcus_bains(); |
1765 | drawContentsToPainter(); | 1765 | drawContentsToPainter(); |
1766 | viewport()->repaint(false); | 1766 | viewport()->repaint(false); |
1767 | } | 1767 | } |
1768 | 1768 | ||
1769 | void KOAgenda::scrollUp() | 1769 | void KOAgenda::scrollUp() |
1770 | { | 1770 | { |
1771 | scrollBy(0,-mScrollOffset); | 1771 | scrollBy(0,-mScrollOffset); |
1772 | } | 1772 | } |
1773 | 1773 | ||
1774 | 1774 | ||
1775 | void KOAgenda::scrollDown() | 1775 | void KOAgenda::scrollDown() |
1776 | { | 1776 | { |
1777 | scrollBy(0,mScrollOffset); | 1777 | scrollBy(0,mScrollOffset); |
1778 | } | 1778 | } |
1779 | 1779 | ||
1780 | void KOAgenda::popupAlarm() | 1780 | void KOAgenda::popupAlarm() |
1781 | { | 1781 | { |
1782 | if (!mClickedItem) { | 1782 | if (!mClickedItem) { |
1783 | qDebug("KOAgenda::popupAlarm() called without having a clicked item "); | 1783 | qDebug("KOAgenda::popupAlarm() called without having a clicked item "); |
1784 | return; | 1784 | return; |
1785 | } | 1785 | } |
1786 | // TODO: deal correctly with multiple alarms | 1786 | // TODO: deal correctly with multiple alarms |
1787 | Alarm* alarm; | 1787 | Alarm* alarm; |
1788 | QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); | 1788 | QPtrList<Alarm> list(mClickedItem->incidence()->alarms()); |
1789 | for(alarm=list.first();alarm;alarm=list.next()) { | 1789 | for(alarm=list.first();alarm;alarm=list.next()) { |
1790 | alarm->toggleAlarm(); | 1790 | alarm->toggleAlarm(); |
1791 | } | 1791 | } |
1792 | emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); | 1792 | emit itemModified( mClickedItem , KOGlobals::EVENTEDITED ); |
1793 | mClickedItem->paintMe( true ); | 1793 | mClickedItem->paintMe( true ); |
1794 | mClickedItem->repaint( false ); | 1794 | mClickedItem->repaint( false ); |
1795 | } | 1795 | } |
1796 | 1796 | ||
1797 | /* | 1797 | /* |
1798 | Calculates the minimum width | 1798 | Calculates the minimum width |
1799 | */ | 1799 | */ |
1800 | int KOAgenda::minimumWidth() const | 1800 | int KOAgenda::minimumWidth() const |
1801 | { | 1801 | { |
1802 | // TODO:: develop a way to dynamically determine the minimum width | 1802 | // TODO:: develop a way to dynamically determine the minimum width |
1803 | int min = 100; | 1803 | int min = 100; |
1804 | 1804 | ||
1805 | return min; | 1805 | return min; |
1806 | } | 1806 | } |
1807 | 1807 | ||
1808 | void KOAgenda::updateConfig() | 1808 | void KOAgenda::updateConfig() |
1809 | { | 1809 | { |
1810 | if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) | 1810 | if ( viewport()->backgroundColor() != KOPrefs::instance()->mAgendaBgColor) |
1811 | viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); | 1811 | viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor); |
1812 | if ( mAllDayMode ) { | 1812 | if ( mAllDayMode ) { |
1813 | mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; | 1813 | mGridSpacingY = height() - 1 ;// KOPrefs::instance()->mAllDaySize; |
1814 | //mGridSpacingY = KOPrefs::instance()->mAllDaySize; | 1814 | //mGridSpacingY = KOPrefs::instance()->mAllDaySize; |
1815 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); | 1815 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY+1 ); |
1816 | // setMaximumHeight( mGridSpacingY+1 ); | 1816 | // setMaximumHeight( mGridSpacingY+1 ); |
1817 | viewport()->repaint( false ); | 1817 | viewport()->repaint( false ); |
1818 | //setFixedHeight( mGridSpacingY+1 ); | 1818 | //setFixedHeight( mGridSpacingY+1 ); |
1819 | //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); | 1819 | //qDebug("KOPrefs:aaaaa:instance()->mAllDaySize %d ", KOPrefs::instance()->mAllDaySize); |
1820 | } | 1820 | } |
1821 | else { | 1821 | else { |
1822 | mGridSpacingY = KOPrefs::instance()->mHourSize; | 1822 | mGridSpacingY = KOPrefs::instance()->mHourSize; |
1823 | calculateWorkingHours(); | 1823 | calculateWorkingHours(); |
1824 | marcus_bains(); | 1824 | marcus_bains(); |
1825 | } | 1825 | } |
1826 | } | 1826 | } |
1827 | 1827 | ||
1828 | void KOAgenda::checkScrollBoundaries() | 1828 | void KOAgenda::checkScrollBoundaries() |
1829 | { | 1829 | { |
1830 | // Invalidate old values to force update | 1830 | // Invalidate old values to force update |
1831 | mOldLowerScrollValue = -1; | 1831 | mOldLowerScrollValue = -1; |
1832 | mOldUpperScrollValue = -1; | 1832 | mOldUpperScrollValue = -1; |
1833 | 1833 | ||
1834 | checkScrollBoundaries(verticalScrollBar()->value()); | 1834 | checkScrollBoundaries(verticalScrollBar()->value()); |
1835 | } | 1835 | } |
1836 | 1836 | ||
1837 | void KOAgenda::checkScrollBoundaries(int v) | 1837 | void KOAgenda::checkScrollBoundaries(int v) |
1838 | { | 1838 | { |
1839 | if ( mGridSpacingY == 0 ) | 1839 | if ( mGridSpacingY == 0 ) |
1840 | return; | 1840 | return; |
1841 | int yMin = v/mGridSpacingY; | 1841 | int yMin = v/mGridSpacingY; |
1842 | int yMax = (v+visibleHeight())/mGridSpacingY; | 1842 | int yMax = (v+visibleHeight())/mGridSpacingY; |
1843 | 1843 | ||
1844 | // kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; | 1844 | // kdDebug() << "--- yMin: " << yMin << " yMax: " << yMax << endl; |
1845 | 1845 | ||
1846 | if (yMin != mOldLowerScrollValue) { | 1846 | if (yMin != mOldLowerScrollValue) { |
1847 | mOldLowerScrollValue = yMin; | 1847 | mOldLowerScrollValue = yMin; |
1848 | emit lowerYChanged(yMin); | 1848 | emit lowerYChanged(yMin); |
1849 | } | 1849 | } |
1850 | if (yMax != mOldUpperScrollValue) { | 1850 | if (yMax != mOldUpperScrollValue) { |
1851 | mOldUpperScrollValue = yMax; | 1851 | mOldUpperScrollValue = yMax; |
1852 | emit upperYChanged(yMax); | 1852 | emit upperYChanged(yMax); |
1853 | } | 1853 | } |
1854 | } | 1854 | } |
1855 | 1855 | ||
1856 | void KOAgenda::deselectItem() | 1856 | void KOAgenda::deselectItem() |
1857 | { | 1857 | { |
1858 | if (mSelectedItem.isNull()) return; | 1858 | if (mSelectedItem.isNull()) return; |
1859 | mSelectedItem->select(false); | 1859 | mSelectedItem->select(false); |
1860 | mSelectedItem = 0; | 1860 | mSelectedItem = 0; |
1861 | } | 1861 | } |
1862 | 1862 | ||
1863 | void KOAgenda::selectItem(KOAgendaItem *item) | 1863 | void KOAgenda::selectItem(KOAgendaItem *item) |
1864 | { | 1864 | { |
1865 | if ((KOAgendaItem *)mSelectedItem == item) return; | 1865 | if ((KOAgendaItem *)mSelectedItem == item) return; |
1866 | deselectItem(); | 1866 | deselectItem(); |
1867 | if (item == 0) { | 1867 | if (item == 0) { |
1868 | emit incidenceSelected( 0 ); | 1868 | emit incidenceSelected( 0 ); |
1869 | return; | 1869 | return; |
1870 | } | 1870 | } |
1871 | mSelectedItem = item; | 1871 | mSelectedItem = item; |
1872 | mSelectedItem->select(); | 1872 | mSelectedItem->select(); |
1873 | emit incidenceSelected( mSelectedItem->incidence() ); | 1873 | emit incidenceSelected( mSelectedItem->incidence() ); |
1874 | } | 1874 | } |
1875 | 1875 | ||
1876 | // This function seems never be called. | 1876 | // This function seems never be called. |
1877 | void KOAgenda::keyPressEvent( QKeyEvent *kev ) | 1877 | void KOAgenda::keyPressEvent( QKeyEvent *kev ) |
1878 | { | 1878 | { |
1879 | switch(kev->key()) { | 1879 | switch(kev->key()) { |
1880 | case Key_PageDown: | 1880 | case Key_PageDown: |
1881 | verticalScrollBar()->addPage(); | 1881 | verticalScrollBar()->addPage(); |
1882 | break; | 1882 | break; |
1883 | case Key_PageUp: | 1883 | case Key_PageUp: |
1884 | verticalScrollBar()->subtractPage(); | 1884 | verticalScrollBar()->subtractPage(); |
1885 | break; | 1885 | break; |
1886 | case Key_Down: | 1886 | case Key_Down: |
1887 | verticalScrollBar()->addLine(); | 1887 | verticalScrollBar()->addLine(); |
1888 | break; | 1888 | break; |
1889 | case Key_Up: | 1889 | case Key_Up: |
1890 | verticalScrollBar()->subtractLine(); | 1890 | verticalScrollBar()->subtractLine(); |
1891 | break; | 1891 | break; |
1892 | default: | 1892 | default: |
1893 | ; | 1893 | ; |
1894 | } | 1894 | } |
1895 | } | 1895 | } |
1896 | 1896 | ||
1897 | void KOAgenda::calculateWorkingHours() | 1897 | void KOAgenda::calculateWorkingHours() |
1898 | { | 1898 | { |
1899 | // mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; | 1899 | // mWorkingHoursEnable = KOPrefs::instance()->mEnableWorkingHours; |
1900 | mWorkingHoursEnable = !mAllDayMode; | 1900 | mWorkingHoursEnable = !mAllDayMode; |
1901 | 1901 | ||
1902 | mWorkingHoursYTop = mGridSpacingY * | 1902 | mWorkingHoursYTop = mGridSpacingY * |
1903 | KOPrefs::instance()->mWorkingHoursStart * 4; | 1903 | KOPrefs::instance()->mWorkingHoursStart * 4; |
1904 | mWorkingHoursYBottom = mGridSpacingY * | 1904 | mWorkingHoursYBottom = mGridSpacingY * |
1905 | KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; | 1905 | KOPrefs::instance()->mWorkingHoursEnd * 4 - 1; |
1906 | } | 1906 | } |
1907 | 1907 | ||
1908 | 1908 | ||
1909 | DateList KOAgenda::dateList() const | 1909 | DateList KOAgenda::dateList() const |
1910 | { | 1910 | { |
1911 | return mSelectedDates; | 1911 | return mSelectedDates; |
1912 | } | 1912 | } |
1913 | 1913 | ||
1914 | void KOAgenda::setDateList(const DateList &selectedDates) | 1914 | void KOAgenda::setDateList(const DateList &selectedDates) |
1915 | { | 1915 | { |
1916 | mSelectedDates = selectedDates; | 1916 | mSelectedDates = selectedDates; |
1917 | marcus_bains(); | 1917 | marcus_bains(); |
1918 | } | 1918 | } |
1919 | 1919 | ||
1920 | void KOAgenda::setHolidayMask(QMemArray<bool> *mask) | 1920 | void KOAgenda::setHolidayMask(QMemArray<bool> *mask) |
1921 | { | 1921 | { |
1922 | mHolidayMask = mask; | 1922 | mHolidayMask = mask; |
1923 | 1923 | ||
1924 | /* | 1924 | /* |
1925 | kdDebug() << "HolidayMask: "; | 1925 | kdDebug() << "HolidayMask: "; |
1926 | for(uint i=0;i<mask->count();++i) { | 1926 | for(uint i=0;i<mask->count();++i) { |
1927 | kdDebug() << (mask->at(i) ? "*" : "o"); | 1927 | kdDebug() << (mask->at(i) ? "*" : "o"); |
1928 | } | 1928 | } |
1929 | kdDebug() << endl; | 1929 | kdDebug() << endl; |
1930 | */ | 1930 | */ |
1931 | } | 1931 | } |
1932 | 1932 | ||
1933 | void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) | 1933 | void KOAgenda::contentsMousePressEvent ( QMouseEvent *event ) |
1934 | { | 1934 | { |
1935 | 1935 | ||
1936 | QScrollView::contentsMousePressEvent(event); | 1936 | QScrollView::contentsMousePressEvent(event); |
1937 | } | 1937 | } |
1938 | 1938 | ||
1939 | void KOAgenda::storePosition() | 1939 | void KOAgenda::storePosition() |
1940 | { | 1940 | { |
1941 | //mContentPosition | 1941 | //mContentPosition |
1942 | int max = mGridSpacingY*4*24; | 1942 | int max = mGridSpacingY*4*24; |
1943 | if ( contentsY() < 5 && max > viewport()->height()*3/2 ) | 1943 | if ( contentsY() < 5 && max > viewport()->height()*3/2 ) |
1944 | mContentPosition = 0; | 1944 | mContentPosition = 0; |
1945 | else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) | 1945 | else if ( contentsY() + viewport()->height() > max - 5 && max > viewport()->height()*3/2) |
1946 | mContentPosition = -1.0; | 1946 | mContentPosition = -1.0; |
1947 | else | 1947 | else |
1948 | mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); | 1948 | mContentPosition = ((float) max)/ ((float)(contentsY()+ ( viewport()->height()/2))); |
1949 | //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); | 1949 | //qDebug("mContentPosition %f %d %d %d",mContentPosition , max, contentsY() ,viewport()->height()); |
1950 | 1950 | ||
1951 | } | 1951 | } |
1952 | void KOAgenda::restorePosition() | 1952 | void KOAgenda::restorePosition() |
1953 | { | 1953 | { |
1954 | int posY; | 1954 | int posY; |
1955 | int max = mGridSpacingY*4*24; | 1955 | int max = mGridSpacingY*4*24; |
1956 | if ( mContentPosition < 0 ) | 1956 | if ( mContentPosition < 0 ) |
1957 | posY = max-viewport()->height(); | 1957 | posY = max-viewport()->height(); |
1958 | else | 1958 | else |
1959 | if ( mContentPosition == 0 ) | 1959 | if ( mContentPosition == 0 ) |
1960 | posY = 0; | 1960 | posY = 0; |
1961 | else | 1961 | else |
1962 | posY = (max/mContentPosition)-(viewport()->height()/2); | 1962 | posY = (max/mContentPosition)-(viewport()->height()/2); |
1963 | setContentsPos (0, posY ); | 1963 | setContentsPos (0, posY ); |
1964 | //qDebug("posY %d hei %d", posY, max); | 1964 | //qDebug("posY %d hei %d", posY, max); |
1965 | 1965 | ||
1966 | } | 1966 | } |
1967 | void KOAgenda::moveChild( QWidget *w, int x , int y ) | 1967 | void KOAgenda::moveChild( QWidget *w, int x , int y ) |
1968 | { | 1968 | { |
1969 | ++x; | 1969 | ++x; |
1970 | QScrollView::moveChild( w, x , y ); | 1970 | QScrollView::moveChild( w, x , y ); |
1971 | } | 1971 | } |
1972 | #include <qmessagebox.h> | 1972 | #include <qmessagebox.h> |
1973 | #ifdef DESKTOP_VERSION | 1973 | #ifdef DESKTOP_VERSION |
1974 | #include <qprinter.h> | 1974 | #include <qprinter.h> |
1975 | #include <qpainter.h> | 1975 | #include <qpainter.h> |
1976 | #include <qpaintdevicemetrics.h> | 1976 | #include <qpaintdevicemetrics.h> |
1977 | 1977 | ||
1978 | #endif | 1978 | #endif |
1979 | void KOAgenda::printSelection() | 1979 | void KOAgenda::printSelection() |
1980 | { | 1980 | { |
1981 | #ifdef DESKTOP_VERSION | 1981 | #ifdef DESKTOP_VERSION |
1982 | if ( mStartCellY == mCurrentCellY ) { | 1982 | if ( mStartCellY == mCurrentCellY ) { |
1983 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 1983 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
1984 | i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "), | 1984 | i18n("Nothing selected!\n\nThis prints the full width of the Agenda view as you see it!\n\nTo determine the vertical range of the printing, please select\na vertical range (with the left mouse button down) in one column. "), |
1985 | i18n("OK"), 0, 0, | 1985 | i18n("OK"), 0, 0, |
1986 | 0, 1 ); | 1986 | 0, 1 ); |
1987 | return; | 1987 | return; |
1988 | } | 1988 | } |
1989 | 1989 | ||
1990 | float dx, dy; | 1990 | float dx, dy; |
1991 | int x,y,w,h; | 1991 | int x,y,w,h; |
1992 | x= 0; | 1992 | x= 0; |
1993 | w= contentsWidth()+2; | 1993 | w= contentsWidth()+2; |
1994 | // h= contentsHeight(); | 1994 | // h= contentsHeight(); |
1995 | y = mGridSpacingY*mStartCellY; | 1995 | y = mGridSpacingY*mStartCellY; |
1996 | h = mGridSpacingY*(mCurrentCellY+1)-y+2; | 1996 | h = mGridSpacingY*(mCurrentCellY+1)-y+2; |
1997 | 1997 | ||
1998 | //return; | 1998 | //return; |
1999 | QPrinter* printer = new QPrinter(); | 1999 | QPrinter* printer = new QPrinter(); |
2000 | if ( !printer->setup()) { | 2000 | if ( !printer->setup()) { |
2001 | delete printer; | 2001 | delete printer; |
2002 | return; | 2002 | return; |
2003 | } | 2003 | } |
2004 | QPainter p( printer ); | 2004 | QPainter p( printer ); |
2005 | QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); | 2005 | QPaintDeviceMetrics m = QPaintDeviceMetrics ( printer ); |
2006 | QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); | 2006 | QString date = i18n("Date range: ")+KGlobal::locale()->formatDate( mSelectedDates.first() )+" - "+KGlobal::locale()->formatDate( mSelectedDates.last() ); |
2007 | date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); | 2007 | //date += " --- printing time: " + KGlobal::locale()->formatDateTime(QDateTime::currentDateTime(), true ); |
2008 | int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); | 2008 | int hei = p.boundingRect(0,0, 5, 5, Qt::AlignLeft, date ).height(); |
2009 | // p.drawText( 0, 0, date ); | 2009 | // p.drawText( 0, 0, date ); |
2010 | int offset = m.width()/8; | 2010 | int offset = m.width()/8; |
2011 | // compute the scale | 2011 | // compute the scale |
2012 | dx = ((float) m.width()-offset) / (float)w; | 2012 | dx = ((float) m.width()-offset) / (float)w; |
2013 | dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; | 2013 | dy = (float)(m.height() - ( 2 * hei )-offset ) / (float)h; |
2014 | float scale; | 2014 | float scale; |
2015 | // scale to fit the width or height of the paper | 2015 | // scale to fit the width or height of the paper |
2016 | if ( dx < dy ) | 2016 | if ( dx < dy ) |
2017 | scale = dx; | 2017 | scale = dx; |
2018 | else | 2018 | else |
2019 | scale = dy; | 2019 | scale = dy; |
2020 | // set the scale | 2020 | // set the scale |
2021 | p.drawText( offset* scale, offset* scale*3/4, date ); | 2021 | p.drawText( offset* scale, offset* scale*3/4, date ); |
2022 | 2022 | ||
2023 | int selDay; | 2023 | int selDay; |
2024 | float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); | 2024 | float widOffset = ((float) m.width()-offset) / ((float)(mSelectedDates.count())); |
2025 | float startX = 1; | 2025 | float startX = 1; |
2026 | for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) | 2026 | for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) |
2027 | { | 2027 | { |
2028 | QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); | 2028 | QString text = KGlobal::locale()->formatDate( mSelectedDates[selDay],true ); |
2029 | p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); | 2029 | p.setClipRect(offset* scale+startX , 0, widOffset-4, offset* scale+(2*hei* scale) ); |
2030 | p.drawText( offset* scale+startX, (offset+hei)* scale, text ); | 2030 | p.drawText( offset* scale+startX, (offset+hei)* scale, text ); |
2031 | startX += widOffset; | 2031 | startX += widOffset; |
2032 | 2032 | ||
2033 | } | 2033 | } |
2034 | p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); | 2034 | p.translate( offset* scale,offset* scale+ (-y * scale)+(2*hei* scale)); |
2035 | p.scale( scale, scale ); | 2035 | p.scale( scale, scale ); |
2036 | p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); | 2036 | p.setClipRect( offset* scale, offset* scale+(2*hei* scale), w*scale, h*scale ); |
2037 | // now printing with y offset: 2 hei | 2037 | // now printing with y offset: 2 hei |
2038 | // p.translate( 0, -y*scale); | 2038 | // p.translate( 0, -y*scale); |
2039 | 2039 | ||
2040 | drawContentsToPainter(&p, true ); | 2040 | drawContentsToPainter(&p, true ); |
2041 | globalFlagBlockAgendaItemUpdate = false; | 2041 | globalFlagBlockAgendaItemUpdate = false; |
2042 | KOAgendaItem *item; | 2042 | KOAgendaItem *item; |
2043 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 2043 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
2044 | item->select(false); | 2044 | item->select(false); |
2045 | item->paintMe( false, &p ); | 2045 | item->paintMe( false, &p ); |
2046 | } | 2046 | } |
2047 | globalFlagBlockAgendaItemUpdate = true; | 2047 | globalFlagBlockAgendaItemUpdate = true; |
2048 | p.end(); | 2048 | p.end(); |
2049 | delete printer; | 2049 | delete printer; |
2050 | #else | 2050 | #else |
2051 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), | 2051 | int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), |
2052 | i18n("Not supported \non PDA!\n"), | 2052 | i18n("Not supported \non PDA!\n"), |
2053 | i18n("OK"), 0, 0, | 2053 | i18n("OK"), 0, 0, |
2054 | 0, 1 ); | 2054 | 0, 1 ); |
2055 | #endif | 2055 | #endif |
2056 | } | 2056 | } |
diff --git a/libkdepim/kpimglobalprefs.cpp b/libkdepim/kpimglobalprefs.cpp index ac7d205..a09b278 100644 --- a/libkdepim/kpimglobalprefs.cpp +++ b/libkdepim/kpimglobalprefs.cpp | |||
@@ -1,211 +1,211 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2002 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 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <kglobal.h> | 31 | #include <kglobal.h> |
32 | #include <kconfig.h> | 32 | #include <kconfig.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | #include <kdebug.h> | 34 | #include <kdebug.h> |
35 | #include <kglobalsettings.h> | 35 | #include <kglobalsettings.h> |
36 | #include <kstaticdeleter.h> | 36 | #include <kstaticdeleter.h> |
37 | 37 | ||
38 | #include <qregexp.h> | 38 | #include <qregexp.h> |
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <stdlib.h> | 40 | #include <stdlib.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qapplication.h> | 42 | #include <qapplication.h> |
43 | #include "kpimglobalprefs.h" | 43 | #include "kpimglobalprefs.h" |
44 | 44 | ||
45 | KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0; | 45 | KPimGlobalPrefs *KPimGlobalPrefs::sInstance = 0; |
46 | static KStaticDeleter<KPimGlobalPrefs> staticDeleterGP; | 46 | static KStaticDeleter<KPimGlobalPrefs> staticDeleterGP; |
47 | 47 | ||
48 | 48 | ||
49 | KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) | 49 | KPimGlobalPrefs::KPimGlobalPrefs( const QString &name ) |
50 | : KPrefs("microkdeglobalrc") | 50 | : KPrefs("microkdeglobalrc") |
51 | { | 51 | { |
52 | mLocaleDict = 0; | 52 | mLocaleDict = 0; |
53 | KPrefs::setCurrentGroup("Fonts"); | 53 | KPrefs::setCurrentGroup("Fonts"); |
54 | addItemFont("ApplicationFont",&mApplicationFont,KGlobalSettings::generalFont() ); | 54 | addItemFont("ApplicationFont",&mApplicationFont,KGlobalSettings::generalFont() ); |
55 | KPrefs::setCurrentGroup("Locale"); | 55 | KPrefs::setCurrentGroup("Locale"); |
56 | addItemInt("PreferredLanguage",&mPreferredLanguage,0); | 56 | addItemInt("PreferredLanguage",&mPreferredLanguage,0); |
57 | addItemInt("PreferredTime",&mPreferredTime,0); | 57 | addItemInt("PreferredTime",&mPreferredTime,0); |
58 | addItemInt("PreferredDate",&mPreferredDate,0); | 58 | addItemInt("PreferredDate",&mPreferredDate,0); |
59 | addItemBool("WeekStartsOnSunday",&mWeekStartsOnSunday,false); | 59 | addItemBool("WeekStartsOnSunday",&mWeekStartsOnSunday,false); |
60 | addItemString("UserDateFormatLong", &mUserDateFormatLong, "%A %d %b %y"); | 60 | addItemString("UserDateFormatLong", &mUserDateFormatLong, "%AK %d. %b %y"); |
61 | addItemString("UserDateFormatShort", &mUserDateFormatShort, "%aK %d.%m.%y"); | 61 | addItemString("UserDateFormatShort", &mUserDateFormatShort, "%aK %d.%m.%y"); |
62 | 62 | ||
63 | KPrefs::setCurrentGroup("Time & Date"); | 63 | KPrefs::setCurrentGroup("Time & Date"); |
64 | 64 | ||
65 | addItemString("TimeZoneName",&mTimeZoneId, ("+01:00 Europe/Oslo(CET)") ); | 65 | addItemString("TimeZoneName",&mTimeZoneId, ("+01:00 Europe/Oslo(CET)") ); |
66 | addItemBool("UseDaylightsaving",&mUseDaylightsaving,true); | 66 | addItemBool("UseDaylightsaving",&mUseDaylightsaving,true); |
67 | addItemBool("TimeZoneAdd30min",&mTimeZoneAdd30min,false); | 67 | addItemBool("TimeZoneAdd30min",&mTimeZoneAdd30min,false); |
68 | addItemInt("DaylightsavingStart",&mDaylightsavingStart,90); | 68 | addItemInt("DaylightsavingStart",&mDaylightsavingStart,90); |
69 | addItemInt("DaylightsavingEnd",&mDaylightsavingEnd,304); | 69 | addItemInt("DaylightsavingEnd",&mDaylightsavingEnd,304); |
70 | 70 | ||
71 | KPrefs::setCurrentGroup( "ExternalApplications" ); | 71 | KPrefs::setCurrentGroup( "ExternalApplications" ); |
72 | 72 | ||
73 | addItemInt( "EmailChannelType", &mEmailClient, OMPI_EMC ); | 73 | addItemInt( "EmailChannelType", &mEmailClient, OMPI_EMC ); |
74 | addItemString( "EmailChannel", &mEmailOtherChannel, "" ); | 74 | addItemString( "EmailChannel", &mEmailOtherChannel, "" ); |
75 | addItemString( "EmailChannelMessage", &mEmailOtherMessage, "" ); | 75 | addItemString( "EmailChannelMessage", &mEmailOtherMessage, "" ); |
76 | addItemString( "EmailChannelParameters", &mEmailOtherMessageParameters, "" ); | 76 | addItemString( "EmailChannelParameters", &mEmailOtherMessageParameters, "" ); |
77 | addItemString( "EmailChannelMessage2", &mEmailOtherMessage2, "" ); | 77 | addItemString( "EmailChannelMessage2", &mEmailOtherMessage2, "" ); |
78 | addItemString( "EmailChannelParameters2", &mEmailOtherMessageParameters2, "" ); | 78 | addItemString( "EmailChannelParameters2", &mEmailOtherMessageParameters2, "" ); |
79 | 79 | ||
80 | addItemInt( "PhoneChannelType", &mPhoneClient, KPPI_PHC ); | 80 | addItemInt( "PhoneChannelType", &mPhoneClient, KPPI_PHC ); |
81 | addItemString( "PhoneChannel", &mPhoneOtherChannel, "" ); | 81 | addItemString( "PhoneChannel", &mPhoneOtherChannel, "" ); |
82 | addItemString( "PhoneChannelMessage", &mPhoneOtherMessage, "" ); | 82 | addItemString( "PhoneChannelMessage", &mPhoneOtherMessage, "" ); |
83 | addItemString( "PhoneChannelParameters", &mPhoneOtherMessageParameters, "" ); | 83 | addItemString( "PhoneChannelParameters", &mPhoneOtherMessageParameters, "" ); |
84 | 84 | ||
85 | addItemInt( "FaxChannelType", &mFaxClient, NONE_FAC ); | 85 | addItemInt( "FaxChannelType", &mFaxClient, NONE_FAC ); |
86 | addItemString( "FaxChannel", &mFaxOtherChannel, "" ); | 86 | addItemString( "FaxChannel", &mFaxOtherChannel, "" ); |
87 | addItemString( "FaxChannelMessage", &mFaxOtherMessage, "" ); | 87 | addItemString( "FaxChannelMessage", &mFaxOtherMessage, "" ); |
88 | addItemString( "FaxChannelParameters", &mFaxOtherMessageParameters, "" ); | 88 | addItemString( "FaxChannelParameters", &mFaxOtherMessageParameters, "" ); |
89 | 89 | ||
90 | addItemInt( "SMSChannelType", &mSMSClient, NONE_SMC ); | 90 | addItemInt( "SMSChannelType", &mSMSClient, NONE_SMC ); |
91 | addItemString( "SMSChannel", &mSMSOtherChannel, "" ); | 91 | addItemString( "SMSChannel", &mSMSOtherChannel, "" ); |
92 | addItemString( "SMSChannelMessage", &mSMSOtherMessage, "" ); | 92 | addItemString( "SMSChannelMessage", &mSMSOtherMessage, "" ); |
93 | addItemString( "SMSChannelParameters", &mSMSOtherMessageParameters, "" ); | 93 | addItemString( "SMSChannelParameters", &mSMSOtherMessageParameters, "" ); |
94 | 94 | ||
95 | addItemInt( "PagerChannelType", &mPagerClient, NONE_PAC ); | 95 | addItemInt( "PagerChannelType", &mPagerClient, NONE_PAC ); |
96 | addItemString( "PagerChannel", &mPagerOtherChannel, "" ); | 96 | addItemString( "PagerChannel", &mPagerOtherChannel, "" ); |
97 | addItemString( "PagerChannelMessage", &mPagerOtherMessage, "" ); | 97 | addItemString( "PagerChannelMessage", &mPagerOtherMessage, "" ); |
98 | addItemString( "PagerChannelParameters", &mPagerOtherMessageParameters, "" ); | 98 | addItemString( "PagerChannelParameters", &mPagerOtherMessageParameters, "" ); |
99 | 99 | ||
100 | addItemInt( "SIPChannelType", &mSipClient, KPPI_SIC ); | 100 | addItemInt( "SIPChannelType", &mSipClient, KPPI_SIC ); |
101 | addItemString( "SIPChannel", &mSipOtherChannel, "" ); | 101 | addItemString( "SIPChannel", &mSipOtherChannel, "" ); |
102 | addItemString( "SIPChannelMessage", &mSipOtherMessage, "" ); | 102 | addItemString( "SIPChannelMessage", &mSipOtherMessage, "" ); |
103 | addItemString( "SIPChannelParameters", &mSipOtherMessageParameters, "" ); | 103 | addItemString( "SIPChannelParameters", &mSipOtherMessageParameters, "" ); |
104 | 104 | ||
105 | KPrefs::setCurrentGroup( "PhoneAccess" ); | 105 | KPrefs::setCurrentGroup( "PhoneAccess" ); |
106 | addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm"); | 106 | addItemString("Ex2PhoneDevice",&mEx2PhoneDevice,"/dev/ircomm"); |
107 | addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda"); | 107 | addItemString("Ex2PhoneConnection",&mEx2PhoneConnection,"irda"); |
108 | addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i"); | 108 | addItemString("Ex2PhoneModel",&mEx2PhoneModel,"6310i"); |
109 | 109 | ||
110 | } | 110 | } |
111 | 111 | ||
112 | void KPimGlobalPrefs::setGlobalConfig() | 112 | void KPimGlobalPrefs::setGlobalConfig() |
113 | { | 113 | { |
114 | if ( mLocaleDict == 0 ) { | 114 | if ( mLocaleDict == 0 ) { |
115 | QString fileName ; | 115 | QString fileName ; |
116 | QString name = KGlobal::getAppName() +"/"; | 116 | QString name = KGlobal::getAppName() +"/"; |
117 | #ifndef DESKTOP_VERSION | 117 | #ifndef DESKTOP_VERSION |
118 | fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/"+name; | 118 | fileName= QString(getenv("QPEDIR"))+"/pics/kdepim/"+name; |
119 | #else | 119 | #else |
120 | fileName = qApp->applicationDirPath () + "/kdepim/"+ name; | 120 | fileName = qApp->applicationDirPath () + "/kdepim/"+ name; |
121 | #endif | 121 | #endif |
122 | mLocaleDict = 0; | 122 | mLocaleDict = 0; |
123 | if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) { | 123 | if ( mPreferredLanguage > 0 && mPreferredLanguage < 5 ) { |
124 | 124 | ||
125 | if ( mPreferredLanguage == 1 ) | 125 | if ( mPreferredLanguage == 1 ) |
126 | fileName = fileName+"germantranslation.txt"; | 126 | fileName = fileName+"germantranslation.txt"; |
127 | else if ( mPreferredLanguage == 4 ) | 127 | else if ( mPreferredLanguage == 4 ) |
128 | fileName = fileName+"usertranslation.txt"; | 128 | fileName = fileName+"usertranslation.txt"; |
129 | else if ( mPreferredLanguage == 2 ) | 129 | else if ( mPreferredLanguage == 2 ) |
130 | fileName = fileName+"frenchtranslation.txt"; | 130 | fileName = fileName+"frenchtranslation.txt"; |
131 | else if ( mPreferredLanguage == 3 ) | 131 | else if ( mPreferredLanguage == 3 ) |
132 | fileName = fileName+"italiantranslation.txt"; | 132 | fileName = fileName+"italiantranslation.txt"; |
133 | QFile file( fileName ); | 133 | QFile file( fileName ); |
134 | if (file.open( IO_ReadOnly ) ) { | 134 | if (file.open( IO_ReadOnly ) ) { |
135 | QTextStream ts( &file ); | 135 | QTextStream ts( &file ); |
136 | ts.setEncoding( QTextStream::Latin1 ); | 136 | ts.setEncoding( QTextStream::Latin1 ); |
137 | //ts.setCodec( QTextCodec::latin1 ); | 137 | //ts.setCodec( QTextCodec::latin1 ); |
138 | QString text = ts.read(); | 138 | QString text = ts.read(); |
139 | file.close(); | 139 | file.close(); |
140 | text.replace( QRegExp("\\\\n"), "\n" ); | 140 | text.replace( QRegExp("\\\\n"), "\n" ); |
141 | QString line; | 141 | QString line; |
142 | QString we; | 142 | QString we; |
143 | QString wt; | 143 | QString wt; |
144 | int br = 0; | 144 | int br = 0; |
145 | int nbr; | 145 | int nbr; |
146 | nbr = text.find ( "},", br ); | 146 | nbr = text.find ( "},", br ); |
147 | line = text.mid( br, nbr - br ); | 147 | line = text.mid( br, nbr - br ); |
148 | br = nbr+1; | 148 | br = nbr+1; |
149 | int se, ee, st, et; | 149 | int se, ee, st, et; |
150 | mLocaleDict = new QDict<QString>; | 150 | mLocaleDict = new QDict<QString>; |
151 | mLocaleDict->setAutoDelete( true ); | 151 | mLocaleDict->setAutoDelete( true ); |
152 | QString end = "{ \"\",\"\" }"; | 152 | QString end = "{ \"\",\"\" }"; |
153 | while ( (line != end) && (br > 1) ) { | 153 | while ( (line != end) && (br > 1) ) { |
154 | //qDebug("%d *%s* ", br, line.latin1()); | 154 | //qDebug("%d *%s* ", br, line.latin1()); |
155 | se = line.find("\"")+1; | 155 | se = line.find("\"")+1; |
156 | et = line.findRev("\"",-1); | 156 | et = line.findRev("\"",-1); |
157 | ee = line.find("\",\""); | 157 | ee = line.find("\",\""); |
158 | st = ee+3; | 158 | st = ee+3; |
159 | we = line.mid( se, ee-se ); | 159 | we = line.mid( se, ee-se ); |
160 | if ( mPreferredLanguage == 4 ) | 160 | if ( mPreferredLanguage == 4 ) |
161 | wt = QString::fromUtf8(line.mid( st, et-st ).latin1()); | 161 | wt = QString::fromUtf8(line.mid( st, et-st ).latin1()); |
162 | else | 162 | else |
163 | wt = line.mid( st, et-st ); | 163 | wt = line.mid( st, et-st ); |
164 | //qDebug("*%s* *%s* ", we.latin1(), wt.latin1()); | 164 | //qDebug("*%s* *%s* ", we.latin1(), wt.latin1()); |
165 | mLocaleDict->insert( we, new QString (wt) ); | 165 | mLocaleDict->insert( we, new QString (wt) ); |
166 | nbr = text.find ( "}", br ); | 166 | nbr = text.find ( "}", br ); |
167 | line = text.mid( br, nbr - br ); | 167 | line = text.mid( br, nbr - br ); |
168 | br = nbr+1; | 168 | br = nbr+1; |
169 | } | 169 | } |
170 | //qDebug("end *%s* ", end.latin1()); | 170 | //qDebug("end *%s* ", end.latin1()); |
171 | 171 | ||
172 | setLocaleDict( mLocaleDict ); | 172 | setLocaleDict( mLocaleDict ); |
173 | } else { | 173 | } else { |
174 | qDebug("KO: Cannot find translation file %s",fileName.latin1() ); | 174 | qDebug("KO: Cannot find translation file %s",fileName.latin1() ); |
175 | } | 175 | } |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | KGlobal::locale()->setHore24Format( !mPreferredTime ); | 179 | KGlobal::locale()->setHore24Format( !mPreferredTime ); |
180 | KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); | 180 | KGlobal::locale()->setWeekStartMonday( !mWeekStartsOnSunday ); |
181 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)mPreferredDate ); | 181 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)mPreferredDate ); |
182 | KGlobal::locale()->setLanguage( mPreferredLanguage ); | 182 | KGlobal::locale()->setLanguage( mPreferredLanguage ); |
183 | QString dummy = mUserDateFormatLong; | 183 | QString dummy = mUserDateFormatLong; |
184 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); | 184 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); |
185 | dummy = mUserDateFormatShort; | 185 | dummy = mUserDateFormatShort; |
186 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); | 186 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); |
187 | KGlobal::locale()->setDaylightSaving( mUseDaylightsaving, | 187 | KGlobal::locale()->setDaylightSaving( mUseDaylightsaving, |
188 | mDaylightsavingStart, | 188 | mDaylightsavingStart, |
189 | mDaylightsavingEnd ); | 189 | mDaylightsavingEnd ); |
190 | KGlobal::locale()->setTimezone( mTimeZoneId, mTimeZoneAdd30min ); | 190 | KGlobal::locale()->setTimezone( mTimeZoneId, mTimeZoneAdd30min ); |
191 | 191 | ||
192 | } | 192 | } |
193 | KPimGlobalPrefs::~KPimGlobalPrefs() | 193 | KPimGlobalPrefs::~KPimGlobalPrefs() |
194 | { | 194 | { |
195 | if (sInstance == this) | 195 | if (sInstance == this) |
196 | sInstance = staticDeleterGP.setObject(0); | 196 | sInstance = staticDeleterGP.setObject(0); |
197 | else | 197 | else |
198 | qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?"); | 198 | qDebug("Whats this? Error in KPimGlobalPrefs::~KPimGlobalPrefs() ?"); |
199 | if ( mLocaleDict ) | 199 | if ( mLocaleDict ) |
200 | delete mLocaleDict; | 200 | delete mLocaleDict; |
201 | } | 201 | } |
202 | 202 | ||
203 | KPimGlobalPrefs *KPimGlobalPrefs::instance() | 203 | KPimGlobalPrefs *KPimGlobalPrefs::instance() |
204 | { | 204 | { |
205 | if ( !sInstance ) { | 205 | if ( !sInstance ) { |
206 | sInstance = staticDeleterGP.setObject( new KPimGlobalPrefs() ); | 206 | sInstance = staticDeleterGP.setObject( new KPimGlobalPrefs() ); |
207 | sInstance->readConfig(); | 207 | sInstance->readConfig(); |
208 | } | 208 | } |
209 | 209 | ||
210 | return sInstance; | 210 | return sInstance; |
211 | } | 211 | } |