-rw-r--r-- | korganizer/koagenda.cpp | 1 | ||||
-rw-r--r-- | korganizer/koagendaview.cpp | 3 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 2 |
3 files changed, 4 insertions, 2 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index de964da..b5d52d2 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp | |||
@@ -6,768 +6,769 @@ | |||
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 | mTimeBox = new QLabel(this); | 73 | mTimeBox = new QLabel(this); |
74 | mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); | 74 | mTimeBox->setAlignment(Qt::AlignRight | Qt::AlignBottom); |
75 | QPalette pal = mTimeBox->palette(); | 75 | QPalette pal = mTimeBox->palette(); |
76 | pal.setColor(QColorGroup::Foreground, Qt::red); | 76 | pal.setColor(QColorGroup::Foreground, Qt::red); |
77 | mTimeBox->setPalette(pal); | 77 | mTimeBox->setPalette(pal); |
78 | //mTimeBox->setAutoMask(true); | 78 | //mTimeBox->setAutoMask(true); |
79 | 79 | ||
80 | agenda->addChild(mTimeBox); | 80 | agenda->addChild(mTimeBox); |
81 | 81 | ||
82 | oldToday = -1; | 82 | oldToday = -1; |
83 | } | 83 | } |
84 | 84 | ||
85 | MarcusBains::~MarcusBains() | 85 | MarcusBains::~MarcusBains() |
86 | { | 86 | { |
87 | delete minutes; | 87 | delete minutes; |
88 | } | 88 | } |
89 | 89 | ||
90 | int MarcusBains::todayColumn() | 90 | int MarcusBains::todayColumn() |
91 | { | 91 | { |
92 | QDate currentDate = QDate::currentDate(); | 92 | QDate currentDate = QDate::currentDate(); |
93 | 93 | ||
94 | DateList dateList = agenda->dateList(); | 94 | DateList dateList = agenda->dateList(); |
95 | DateList::ConstIterator it; | 95 | DateList::ConstIterator it; |
96 | int col = 0; | 96 | int col = 0; |
97 | for(it = dateList.begin(); it != dateList.end(); ++it) { | 97 | for(it = dateList.begin(); it != dateList.end(); ++it) { |
98 | if((*it) == currentDate) | 98 | if((*it) == currentDate) |
99 | return KOGlobals::self()->reverseLayout() ? | 99 | return KOGlobals::self()->reverseLayout() ? |
100 | agenda->columns() - 1 - col : col; | 100 | agenda->columns() - 1 - col : col; |
101 | ++col; | 101 | ++col; |
102 | } | 102 | } |
103 | 103 | ||
104 | return -1; | 104 | return -1; |
105 | } | 105 | } |
106 | void MarcusBains::updateLoc() | 106 | void MarcusBains::updateLoc() |
107 | { | 107 | { |
108 | updateLocation(); | 108 | updateLocation(); |
109 | } | 109 | } |
110 | void MarcusBains::updateLocation(bool recalculate) | 110 | void MarcusBains::updateLocation(bool recalculate) |
111 | { | 111 | { |
112 | 112 | ||
113 | QTime tim = QTime::currentTime(); | 113 | QTime tim = QTime::currentTime(); |
114 | //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); | 114 | //qDebug(" MarcusBains::updateLocation %s ", tim.toString().latin1()); |
115 | if((tim.hour() == 0) && (oldTime.hour()==23)) | 115 | if((tim.hour() == 0) && (oldTime.hour()==23)) |
116 | recalculate = true; | 116 | recalculate = true; |
117 | 117 | ||
118 | int mins = tim.hour()*60 + tim.minute(); | 118 | int mins = tim.hour()*60 + tim.minute(); |
119 | int minutesPerCell = 24 * 60 / agenda->rows(); | 119 | int minutesPerCell = 24 * 60 / agenda->rows(); |
120 | int y = mins*agenda->gridSpacingY()/minutesPerCell; | 120 | int y = mins*agenda->gridSpacingY()/minutesPerCell; |
121 | int today = recalculate ? todayColumn() : oldToday; | 121 | int today = recalculate ? todayColumn() : oldToday; |
122 | int x = agenda->gridSpacingX()*today; | 122 | int x = agenda->gridSpacingX()*today; |
123 | bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); | 123 | bool disabled = !(KOPrefs::instance()->mMarcusBainsEnabled); |
124 | 124 | ||
125 | oldTime = tim; | 125 | oldTime = tim; |
126 | oldToday = today; | 126 | oldToday = today; |
127 | 127 | ||
128 | if(disabled || (today<0)) { | 128 | if(disabled || (today<0)) { |
129 | hide(); mTimeBox->hide(); | 129 | hide(); mTimeBox->hide(); |
130 | return; | 130 | return; |
131 | } else { | 131 | } else { |
132 | show(); mTimeBox->show(); | 132 | show(); mTimeBox->show(); |
133 | } | 133 | } |
134 | 134 | ||
135 | if(recalculate) | 135 | if(recalculate) |
136 | setFixedSize(agenda->gridSpacingX(),1); | 136 | setFixedSize(agenda->gridSpacingX(),1); |
137 | agenda->moveChild(this, x, y); | 137 | agenda->moveChild(this, x, y); |
138 | raise(); | 138 | raise(); |
139 | 139 | ||
140 | if(recalculate) | 140 | if(recalculate) |
141 | //mTimeBox->setFont(QFont("helvetica",10)); | 141 | //mTimeBox->setFont(QFont("helvetica",10)); |
142 | mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); | 142 | mTimeBox->setFont(KOPrefs::instance()->mMarcusBainsFont); |
143 | 143 | ||
144 | mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); | 144 | mTimeBox->setText(KGlobal::locale()->formatTime(tim, KOPrefs::instance()->mMarcusBainsShowSeconds)); |
145 | mTimeBox->adjustSize(); | 145 | mTimeBox->adjustSize(); |
146 | // the -2 below is there because there is a bug in this program | 146 | // the -2 below is there because there is a bug in this program |
147 | // somewhere, where the last column of this widget is a few pixels | 147 | // somewhere, where the last column of this widget is a few pixels |
148 | // narrower than the other columns. | 148 | // narrower than the other columns. |
149 | int offs = (today==agenda->columns()-1) ? -4 : 0; | 149 | int offs = (today==agenda->columns()-1) ? -4 : 0; |
150 | agenda->moveChild(mTimeBox, | 150 | agenda->moveChild(mTimeBox, |
151 | x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, | 151 | x+agenda->gridSpacingX()-mTimeBox->width()+offs-1, |
152 | y-mTimeBox->height()); | 152 | y-mTimeBox->height()); |
153 | 153 | ||
154 | mTimeBox->raise(); | 154 | mTimeBox->raise(); |
155 | //mTimeBox->setAutoMask(true); | 155 | //mTimeBox->setAutoMask(true); |
156 | minutes->start(5000,true); | 156 | minutes->start(5000,true); |
157 | } | 157 | } |
158 | 158 | ||
159 | 159 | ||
160 | //////////////////////////////////////////////////////////////////////////// | 160 | //////////////////////////////////////////////////////////////////////////// |
161 | 161 | ||
162 | 162 | ||
163 | /* | 163 | /* |
164 | Create an agenda widget with rows rows and columns columns. | 164 | Create an agenda widget with rows rows and columns columns. |
165 | */ | 165 | */ |
166 | KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, | 166 | KOAgenda::KOAgenda(int columns,int rows,int rowSize,QWidget *parent, |
167 | const char *name,WFlags f) : | 167 | const char *name,WFlags f) : |
168 | QScrollView(parent,name,f) | 168 | QScrollView(parent,name,f) |
169 | { | 169 | { |
170 | 170 | ||
171 | mAllAgendaPopup = 0; | 171 | mAllAgendaPopup = 0; |
172 | mColumns = columns; | 172 | mColumns = columns; |
173 | mRows = rows; | 173 | mRows = rows; |
174 | mGridSpacingY = rowSize; | 174 | mGridSpacingY = rowSize; |
175 | mAllDayMode = false; | 175 | mAllDayMode = false; |
176 | #ifndef DESKTOP_VERSION | 176 | #ifndef DESKTOP_VERSION |
177 | //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); | 177 | //QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); |
178 | #endif | 178 | #endif |
179 | mHolidayMask = 0; | 179 | mHolidayMask = 0; |
180 | init(); | 180 | init(); |
181 | } | 181 | } |
182 | 182 | ||
183 | /* | 183 | /* |
184 | Create an agenda widget with columns columns and one row. This is used for | 184 | Create an agenda widget with columns columns and one row. This is used for |
185 | all-day events. | 185 | all-day events. |
186 | */ | 186 | */ |
187 | KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : | 187 | KOAgenda::KOAgenda(int columns,QWidget *parent,const char *name,WFlags f) : |
188 | QScrollView(parent,name,f) | 188 | QScrollView(parent,name,f) |
189 | { | 189 | { |
190 | mAllAgendaPopup = 0; | 190 | mAllAgendaPopup = 0; |
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 | mPopupTimer = new QTimer(this); | 225 | mPopupTimer = new QTimer(this); |
226 | connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); | 226 | connect(mPopupTimer , SIGNAL(timeout()), this, SLOT(popupMenu())); |
227 | 227 | ||
228 | mNewItemPopup = new QPopupMenu( this ); | 228 | mNewItemPopup = new QPopupMenu( this ); |
229 | connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); | 229 | connect ( mNewItemPopup, SIGNAL (activated ( int ) ), this, SLOT ( newItem(int)) ); |
230 | QString pathString = ""; | 230 | QString pathString = ""; |
231 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { | 231 | if ( !KOPrefs::instance()->mToolBarMiniIcons ) { |
232 | if ( QApplication::desktop()->width() < 480 ) | 232 | if ( QApplication::desktop()->width() < 480 ) |
233 | pathString += "icons16/"; | 233 | pathString += "icons16/"; |
234 | } else | 234 | } else |
235 | pathString += "iconsmini/"; | 235 | pathString += "iconsmini/"; |
236 | 236 | ||
237 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); | 237 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newevent" ), i18n("New Event..."), 1 ); |
238 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); | 238 | mNewItemPopup->insertItem ( SmallIcon( pathString +"newtodo" ), i18n("New Todo..."),2 ); |
239 | mNewItemPopup->insertSeparator ( ); | 239 | mNewItemPopup->insertSeparator ( ); |
240 | mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); | 240 | mNewItemPopup->insertItem ( SmallIcon( pathString +"day" ), i18n("Day view"),3 ); |
241 | mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); | 241 | mNewItemPopup->insertItem ( SmallIcon( pathString +"xdays" ), i18n("Next days"),8 ); |
242 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); | 242 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next week"),4 ); |
243 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); | 243 | mNewItemPopup->insertItem ( SmallIcon( pathString +"week" ), i18n("Next two weeks"),5 ); |
244 | mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 ); | 244 | mNewItemPopup->insertItem ( SmallIcon( pathString +"month" ), i18n("This month"),6 ); |
245 | mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); | 245 | mNewItemPopup->insertItem ( SmallIcon( pathString +"journal" ), i18n("Journal view"),7 ); |
246 | #ifndef _WIN32_ | 246 | #ifndef _WIN32_ |
247 | int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase | 247 | int wflags = viewport()-> getWFlags() |WRepaintNoErase;//WResizeNoErase |
248 | viewport()->setWFlags ( wflags); | 248 | viewport()->setWFlags ( wflags); |
249 | #endif | 249 | #endif |
250 | mGridSpacingX = 80; | 250 | mGridSpacingX = 80; |
251 | mResizeBorderWidth = 8; | 251 | mResizeBorderWidth = 8; |
252 | mScrollBorderWidth = 8; | 252 | mScrollBorderWidth = 8; |
253 | mScrollDelay = 30; | 253 | mScrollDelay = 30; |
254 | mScrollOffset = 10; | 254 | mScrollOffset = 10; |
255 | mPaintPixmap.resize( 20,20); | 255 | mPaintPixmap.resize( 20,20); |
256 | //enableClipper(true); | 256 | //enableClipper(true); |
257 | 257 | ||
258 | // Grab key strokes for keyboard navigation of agenda. Seems to have no | 258 | // Grab key strokes for keyboard navigation of agenda. Seems to have no |
259 | // effect. Has to be fixed. | 259 | // effect. Has to be fixed. |
260 | setFocusPolicy(WheelFocus); | 260 | setFocusPolicy(WheelFocus); |
261 | 261 | ||
262 | connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); | 262 | connect(&mScrollUpTimer,SIGNAL(timeout()),SLOT(scrollUp())); |
263 | connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); | 263 | connect(&mScrollDownTimer,SIGNAL(timeout()),SLOT(scrollDown())); |
264 | connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); | 264 | connect(&mResizeTimer,SIGNAL(timeout()),SLOT(finishResize())); |
265 | 265 | ||
266 | mStartCellX = 0; | 266 | mStartCellX = 0; |
267 | mStartCellY = 0; | 267 | mStartCellY = 0; |
268 | mCurrentCellX = 0; | 268 | mCurrentCellX = 0; |
269 | mCurrentCellY = 0; | 269 | mCurrentCellY = 0; |
270 | 270 | ||
271 | mSelectionCellX = 0; | 271 | mSelectionCellX = 0; |
272 | mSelectionYTop = 0; | 272 | mSelectionYTop = 0; |
273 | mSelectionHeight = 0; | 273 | mSelectionHeight = 0; |
274 | 274 | ||
275 | mOldLowerScrollValue = -1; | 275 | mOldLowerScrollValue = -1; |
276 | mOldUpperScrollValue = -1; | 276 | mOldUpperScrollValue = -1; |
277 | 277 | ||
278 | mClickedItem = 0; | 278 | mClickedItem = 0; |
279 | 279 | ||
280 | mActionItem = 0; | 280 | mActionItem = 0; |
281 | mActionType = NOP; | 281 | mActionType = NOP; |
282 | mItemMoved = false; | 282 | mItemMoved = false; |
283 | 283 | ||
284 | mSelectedItem = 0; | 284 | mSelectedItem = 0; |
285 | 285 | ||
286 | // mItems.setAutoDelete(true); | 286 | // mItems.setAutoDelete(true); |
287 | 287 | ||
288 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); | 288 | resizeContents( mGridSpacingX * mColumns + 1 , mGridSpacingY * mRows + 1 ); |
289 | 289 | ||
290 | viewport()->update(); | 290 | viewport()->update(); |
291 | 291 | ||
292 | setMinimumSize(30, 1); | 292 | setMinimumSize(30, 1); |
293 | // setMaximumHeight(mGridSpacingY * mRows + 5); | 293 | // setMaximumHeight(mGridSpacingY * mRows + 5); |
294 | 294 | ||
295 | // Disable horizontal scrollbar. This is a hack. The geometry should be | 295 | // Disable horizontal scrollbar. This is a hack. The geometry should be |
296 | // controlled in a way that the contents horizontally always fits. Then it is | 296 | // controlled in a way that the contents horizontally always fits. Then it is |
297 | // not necessary to turn off the scrollbar. | 297 | // not necessary to turn off the scrollbar. |
298 | setHScrollBarMode(AlwaysOff); | 298 | setHScrollBarMode(AlwaysOff); |
299 | if ( ! mAllDayMode ) | 299 | if ( ! mAllDayMode ) |
300 | setVScrollBarMode(AlwaysOn); | 300 | setVScrollBarMode(AlwaysOn); |
301 | else | 301 | else |
302 | setVScrollBarMode(AlwaysOff); | 302 | setVScrollBarMode(AlwaysOff); |
303 | 303 | ||
304 | setStartHour(KOPrefs::instance()->mDayBegins); | 304 | setStartHour(KOPrefs::instance()->mDayBegins); |
305 | 305 | ||
306 | calculateWorkingHours(); | 306 | calculateWorkingHours(); |
307 | 307 | ||
308 | connect(verticalScrollBar(),SIGNAL(valueChanged(int)), | 308 | connect(verticalScrollBar(),SIGNAL(valueChanged(int)), |
309 | SLOT(checkScrollBoundaries(int))); | 309 | SLOT(checkScrollBoundaries(int))); |
310 | 310 | ||
311 | // Create the Marcus Bains line. | 311 | // Create the Marcus Bains line. |
312 | if(mAllDayMode) | 312 | if(mAllDayMode) |
313 | mMarcusBains = 0; | 313 | mMarcusBains = 0; |
314 | else { | 314 | else { |
315 | mMarcusBains = new MarcusBains(this); | 315 | mMarcusBains = new MarcusBains(this); |
316 | addChild(mMarcusBains); | 316 | addChild(mMarcusBains); |
317 | } | 317 | } |
318 | mPopupKind = 0; | 318 | mPopupKind = 0; |
319 | mPopupItem = 0; | 319 | mPopupItem = 0; |
320 | } | 320 | } |
321 | 321 | ||
322 | void KOAgenda::clear() | 322 | void KOAgenda::clear() |
323 | { | 323 | { |
324 | KOAgendaItem *item; | 324 | KOAgendaItem *item; |
325 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 325 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
326 | mUnusedItems.append( item ); | 326 | mUnusedItems.append( item ); |
327 | //item->hide(); | 327 | //item->hide(); |
328 | } | 328 | } |
329 | mItems.clear(); | 329 | mItems.clear(); |
330 | mSelectedItem = 0; | 330 | mSelectedItem = 0; |
331 | clearSelection(); | 331 | clearSelection(); |
332 | } | 332 | } |
333 | 333 | ||
334 | void KOAgenda::clearSelection() | 334 | void KOAgenda::clearSelection() |
335 | { | 335 | { |
336 | mSelectionCellX = 0; | 336 | mSelectionCellX = 0; |
337 | mSelectionYTop = 0; | 337 | mSelectionYTop = 0; |
338 | mSelectionHeight = 0; | 338 | mSelectionHeight = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | void KOAgenda::marcus_bains() | 341 | void KOAgenda::marcus_bains() |
342 | { | 342 | { |
343 | if(mMarcusBains) mMarcusBains->updateLocation(true); | 343 | if(mMarcusBains) mMarcusBains->updateLocation(true); |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | void KOAgenda::changeColumns(int columns) | 347 | void KOAgenda::changeColumns(int columns) |
348 | { | 348 | { |
349 | if (columns == 0) { | 349 | if (columns == 0) { |
350 | qDebug("KOAgenda::changeColumns() called with argument 0 "); | 350 | qDebug("KOAgenda::changeColumns() called with argument 0 "); |
351 | return; | 351 | return; |
352 | } | 352 | } |
353 | clear(); | 353 | clear(); |
354 | mColumns = columns; | 354 | mColumns = columns; |
355 | computeSizes(); | 355 | computeSizes(); |
356 | } | 356 | } |
357 | 357 | ||
358 | /* | 358 | /* |
359 | This is the eventFilter function, which gets all events from the KOAgendaItems | 359 | This is the eventFilter function, which gets all events from the KOAgendaItems |
360 | contained in the agenda. It has to handle moving and resizing for all items. | 360 | contained in the agenda. It has to handle moving and resizing for all items. |
361 | */ | 361 | */ |
362 | bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) | 362 | bool KOAgenda::eventFilter ( QObject *object, QEvent *event ) |
363 | { | 363 | { |
364 | // kdDebug() << "KOAgenda::eventFilter" << endl; | 364 | // kdDebug() << "KOAgenda::eventFilter" << endl; |
365 | switch(event->type()) { | 365 | switch(event->type()) { |
366 | case QEvent::MouseButtonPress: | 366 | case QEvent::MouseButtonPress: |
367 | case QEvent::MouseButtonDblClick: | 367 | case QEvent::MouseButtonDblClick: |
368 | case QEvent::MouseButtonRelease: | 368 | case QEvent::MouseButtonRelease: |
369 | case QEvent::MouseMove: | 369 | case QEvent::MouseMove: |
370 | return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); | 370 | return eventFilter_mouse(object, static_cast<QMouseEvent *>(event)); |
371 | 371 | ||
372 | case (QEvent::Leave): | 372 | case (QEvent::Leave): |
373 | if (!mActionItem) | 373 | if (!mActionItem) |
374 | setCursor(arrowCursor); | 374 | setCursor(arrowCursor); |
375 | return true; | 375 | return true; |
376 | 376 | ||
377 | default: | 377 | default: |
378 | return QScrollView::eventFilter(object,event); | 378 | return QScrollView::eventFilter(object,event); |
379 | } | 379 | } |
380 | } | 380 | } |
381 | void KOAgenda::popupMenu() | 381 | void KOAgenda::popupMenu() |
382 | { | 382 | { |
383 | mPopupTimer->stop(); | 383 | mPopupTimer->stop(); |
384 | if ( mPopupKind == 1 ) { | 384 | if ( mPopupKind == 1 ) { |
385 | if (mActionItem ) { | 385 | if (mActionItem ) { |
386 | endItemAction(); | 386 | endItemAction(); |
387 | } | 387 | } |
388 | mLeftMouseDown = false; // no more leftMouse computation | 388 | mLeftMouseDown = false; // no more leftMouse computation |
389 | if (mPopupItem) { | 389 | if (mPopupItem) { |
390 | //mClickedItem = mPopupItem; | ||
390 | selectItem(mPopupItem); | 391 | selectItem(mPopupItem); |
391 | if ( mAllAgendaPopup ) | 392 | if ( mAllAgendaPopup ) |
392 | mAllAgendaPopup->installEventFilter( this ); | 393 | mAllAgendaPopup->installEventFilter( this ); |
393 | emit showIncidencePopupSignal(mPopupItem->incidence()); | 394 | emit showIncidencePopupSignal(mPopupItem->incidence()); |
394 | 395 | ||
395 | } | 396 | } |
396 | } else if ( mPopupKind == 2 ) { | 397 | } else if ( mPopupKind == 2 ) { |
397 | if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action | 398 | if ( mLeftMouseDown ) { // we have a simulated right click - clear left mouse action |
398 | endSelectAction( false ); // do not emit new event signal | 399 | endSelectAction( false ); // do not emit new event signal |
399 | mLeftMouseDown = false; // no more leftMouse computation | 400 | mLeftMouseDown = false; // no more leftMouse computation |
400 | } | 401 | } |
401 | mNewItemPopup->installEventFilter( this ); | 402 | mNewItemPopup->installEventFilter( this ); |
402 | mNewItemPopup->popup( mPopupPos); | 403 | mNewItemPopup->popup( mPopupPos); |
403 | 404 | ||
404 | } | 405 | } |
405 | mLeftMouseDown = false; | 406 | mLeftMouseDown = false; |
406 | mPopupItem = 0; | 407 | mPopupItem = 0; |
407 | mPopupKind = 0; | 408 | mPopupKind = 0; |
408 | } | 409 | } |
409 | 410 | ||
410 | bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) | 411 | bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) |
411 | { | 412 | { |
412 | static int startX = 0; | 413 | static int startX = 0; |
413 | static int startY = 0; | 414 | static int startY = 0; |
414 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); | 415 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); |
415 | static bool blockMoving = true; | 416 | static bool blockMoving = true; |
416 | 417 | ||
417 | //qDebug("KOAgenda::eventFilter_mous "); | 418 | //qDebug("KOAgenda::eventFilter_mous "); |
418 | if ( object == mNewItemPopup ) { | 419 | if ( object == mNewItemPopup ) { |
419 | //qDebug("mNewItemPopup "); | 420 | //qDebug("mNewItemPopup "); |
420 | if ( me->type() == QEvent::MouseButtonRelease ) { | 421 | if ( me->type() == QEvent::MouseButtonRelease ) { |
421 | mNewItemPopup->removeEventFilter( this ); | 422 | mNewItemPopup->removeEventFilter( this ); |
422 | int dX = me->globalPos().x() - mPopupPos.x();; | 423 | int dX = me->globalPos().x() - mPopupPos.x();; |
423 | if ( dX < 0 ) | 424 | if ( dX < 0 ) |
424 | dX = -dX; | 425 | dX = -dX; |
425 | int dY = me->globalPos().y() - mPopupPos.y(); | 426 | int dY = me->globalPos().y() - mPopupPos.y(); |
426 | if ( dY < 0 ) | 427 | if ( dY < 0 ) |
427 | dY = -dY; | 428 | dY = -dY; |
428 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 429 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
429 | mNewItemPopup->hide(); | 430 | mNewItemPopup->hide(); |
430 | } | 431 | } |
431 | } | 432 | } |
432 | return true; | 433 | return true; |
433 | } | 434 | } |
434 | if ( object == mAllAgendaPopup ) { | 435 | if ( object == mAllAgendaPopup ) { |
435 | //qDebug(" mAllAgendaPopup "); | 436 | //qDebug(" mAllAgendaPopup "); |
436 | if ( me->type() == QEvent::MouseButtonRelease ) { | 437 | if ( me->type() == QEvent::MouseButtonRelease ) { |
437 | mAllAgendaPopup->removeEventFilter( this ); | 438 | mAllAgendaPopup->removeEventFilter( this ); |
438 | int dX = me->globalPos().x() - mPopupPos.x();; | 439 | int dX = me->globalPos().x() - mPopupPos.x();; |
439 | if ( dX < 0 ) | 440 | if ( dX < 0 ) |
440 | dX = -dX; | 441 | dX = -dX; |
441 | int dY = me->globalPos().y() - mPopupPos.y(); | 442 | int dY = me->globalPos().y() - mPopupPos.y(); |
442 | if ( dY < 0 ) | 443 | if ( dY < 0 ) |
443 | dY = -dY; | 444 | dY = -dY; |
444 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 445 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
445 | mAllAgendaPopup->hide(); | 446 | mAllAgendaPopup->hide(); |
446 | } | 447 | } |
447 | } | 448 | } |
448 | return true; | 449 | return true; |
449 | } | 450 | } |
450 | QPoint viewportPos; | 451 | QPoint viewportPos; |
451 | if (object != viewport()) { | 452 | if (object != viewport()) { |
452 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); | 453 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); |
453 | } else { | 454 | } else { |
454 | viewportPos = me->pos(); | 455 | viewportPos = me->pos(); |
455 | } | 456 | } |
456 | 457 | ||
457 | switch (me->type()) { | 458 | switch (me->type()) { |
458 | case QEvent::MouseButtonPress: | 459 | case QEvent::MouseButtonPress: |
459 | if (me->button() == LeftButton) { | 460 | if (me->button() == LeftButton) { |
460 | mPopupTimer->start( 600 ); | 461 | mPopupTimer->start( 600 ); |
461 | mLeftMouseDown = true; | 462 | mLeftMouseDown = true; |
462 | } | 463 | } |
463 | blockMoving = true; | 464 | blockMoving = true; |
464 | startX = viewportPos.x(); | 465 | startX = viewportPos.x(); |
465 | startY = viewportPos.y(); | 466 | startY = viewportPos.y(); |
466 | mPopupPos = me->globalPos(); | 467 | mPopupPos = me->globalPos(); |
467 | if (object != viewport()) { | 468 | if (object != viewport()) { |
468 | mPopupItem = (KOAgendaItem *)object; | 469 | mPopupItem = (KOAgendaItem *)object; |
469 | mPopupKind = 1; | 470 | mPopupKind = 1; |
470 | if (me->button() == RightButton) { | 471 | if (me->button() == RightButton) { |
471 | popupMenu(); | 472 | popupMenu(); |
472 | } else if (me->button() == LeftButton) { | 473 | } else if (me->button() == LeftButton) { |
473 | mActionItem = (KOAgendaItem *)object; | 474 | mActionItem = (KOAgendaItem *)object; |
474 | if (mActionItem) { | 475 | if (mActionItem) { |
475 | if ( mSelectionHeight > 0 ) { | 476 | if ( mSelectionHeight > 0 ) { |
476 | int selectionCellX = mSelectionCellX * mGridSpacingX; | 477 | int selectionCellX = mSelectionCellX * mGridSpacingX; |
477 | int selectionYTop = mSelectionYTop; | 478 | int selectionYTop = mSelectionYTop; |
478 | int gridSpacingX = mGridSpacingX; | 479 | int gridSpacingX = mGridSpacingX; |
479 | int selectionHeight = mSelectionHeight; | 480 | int selectionHeight = mSelectionHeight; |
480 | clearSelection(); | 481 | clearSelection(); |
481 | repaintContents( selectionCellX, selectionYTop, | 482 | repaintContents( selectionCellX, selectionYTop, |
482 | gridSpacingX, selectionHeight,false ); | 483 | gridSpacingX, selectionHeight,false ); |
483 | } | 484 | } |
484 | selectItem(mActionItem); | 485 | selectItem(mActionItem); |
485 | Incidence *incidence = mActionItem->incidence(); | 486 | Incidence *incidence = mActionItem->incidence(); |
486 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { | 487 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { |
487 | mActionItem = 0; | 488 | mActionItem = 0; |
488 | } else { | 489 | } else { |
489 | startItemAction(viewportPos); | 490 | startItemAction(viewportPos); |
490 | } | 491 | } |
491 | } | 492 | } |
492 | } | 493 | } |
493 | } else { // ---------- viewport() | 494 | } else { // ---------- viewport() |
494 | mPopupItem = 0; | 495 | mPopupItem = 0; |
495 | mPopupKind = 2; | 496 | mPopupKind = 2; |
496 | selectItem(0); | 497 | selectItem(0); |
497 | mActionItem = 0; | 498 | mActionItem = 0; |
498 | if (me->button() == RightButton) { | 499 | if (me->button() == RightButton) { |
499 | int x,y; | 500 | int x,y; |
500 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 501 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
501 | int gx,gy; | 502 | int gx,gy; |
502 | contentsToGrid(x,y,gx,gy); | 503 | contentsToGrid(x,y,gx,gy); |
503 | mCurrentCellX = gx; | 504 | mCurrentCellX = gx; |
504 | mCurrentCellY = gy; | 505 | mCurrentCellY = gy; |
505 | mStartCellX = gx; | 506 | mStartCellX = gx; |
506 | mStartCellY = gy; | 507 | mStartCellY = gy; |
507 | popupMenu(); | 508 | popupMenu(); |
508 | } else if (me->button() == LeftButton) { | 509 | } else if (me->button() == LeftButton) { |
509 | setCursor(arrowCursor); | 510 | setCursor(arrowCursor); |
510 | startSelectAction(viewportPos); | 511 | startSelectAction(viewportPos); |
511 | } | 512 | } |
512 | } | 513 | } |
513 | break; | 514 | break; |
514 | 515 | ||
515 | case QEvent::MouseButtonRelease: | 516 | case QEvent::MouseButtonRelease: |
516 | if (me->button() == LeftButton ) { | 517 | if (me->button() == LeftButton ) { |
517 | mPopupTimer->stop(); | 518 | mPopupTimer->stop(); |
518 | } | 519 | } |
519 | if (object != viewport()) { | 520 | if (object != viewport()) { |
520 | if (me->button() == LeftButton && mLeftMouseDown) { | 521 | if (me->button() == LeftButton && mLeftMouseDown) { |
521 | if (mActionItem) { | 522 | if (mActionItem) { |
522 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 523 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
523 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); | 524 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); |
524 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { | 525 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { |
525 | mScrollUpTimer.stop(); | 526 | mScrollUpTimer.stop(); |
526 | mScrollDownTimer.stop(); | 527 | mScrollDownTimer.stop(); |
527 | mActionItem->resetMove(); | 528 | mActionItem->resetMove(); |
528 | placeSubCells( mActionItem ); | 529 | placeSubCells( mActionItem ); |
529 | // emit startDragSignal( mActionItem->incidence() ); | 530 | // emit startDragSignal( mActionItem->incidence() ); |
530 | setCursor( arrowCursor ); | 531 | setCursor( arrowCursor ); |
531 | mActionItem = 0; | 532 | mActionItem = 0; |
532 | mActionType = NOP; | 533 | mActionType = NOP; |
533 | mItemMoved = 0; | 534 | mItemMoved = 0; |
534 | mLeftMouseDown = false; | 535 | mLeftMouseDown = false; |
535 | return true; | 536 | return true; |
536 | } | 537 | } |
537 | endItemAction(); | 538 | endItemAction(); |
538 | } | 539 | } |
539 | } | 540 | } |
540 | 541 | ||
541 | } else { // ---------- viewport() | 542 | } else { // ---------- viewport() |
542 | if (me->button() == LeftButton && mLeftMouseDown ) { //left click | 543 | if (me->button() == LeftButton && mLeftMouseDown ) { //left click |
543 | endSelectAction( true ); // emit new event signal | 544 | endSelectAction( true ); // emit new event signal |
544 | } | 545 | } |
545 | } | 546 | } |
546 | if (me->button() == LeftButton) | 547 | if (me->button() == LeftButton) |
547 | mLeftMouseDown = false; | 548 | mLeftMouseDown = false; |
548 | 549 | ||
549 | break; | 550 | break; |
550 | 551 | ||
551 | case QEvent::MouseMove: | 552 | case QEvent::MouseMove: |
552 | //qDebug("mm "); | 553 | //qDebug("mm "); |
553 | if ( !mLeftMouseDown ) | 554 | if ( !mLeftMouseDown ) |
554 | return false; | 555 | return false; |
555 | if ( blockMoving ) { | 556 | if ( blockMoving ) { |
556 | int dX, dY; | 557 | int dX, dY; |
557 | dX = startX - viewportPos.x(); | 558 | dX = startX - viewportPos.x(); |
558 | if ( dX < 0 ) | 559 | if ( dX < 0 ) |
559 | dX = -dX; | 560 | dX = -dX; |
560 | dY = viewportPos.y() - startY; | 561 | dY = viewportPos.y() - startY; |
561 | if ( dY < 0 ) | 562 | if ( dY < 0 ) |
562 | dY = -dY; | 563 | dY = -dY; |
563 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); | 564 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); |
564 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 565 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
565 | blockMoving = false; | 566 | blockMoving = false; |
566 | } | 567 | } |
567 | } | 568 | } |
568 | if ( ! blockMoving ) | 569 | if ( ! blockMoving ) |
569 | mPopupTimer->stop(); | 570 | mPopupTimer->stop(); |
570 | if (object != viewport()) { | 571 | if (object != viewport()) { |
571 | KOAgendaItem *moveItem = (KOAgendaItem *)object; | 572 | KOAgendaItem *moveItem = (KOAgendaItem *)object; |
572 | if (!moveItem->incidence()->isReadOnly() ) { | 573 | if (!moveItem->incidence()->isReadOnly() ) { |
573 | if (!mActionItem) | 574 | if (!mActionItem) |
574 | setNoActionCursor(moveItem,viewportPos); | 575 | setNoActionCursor(moveItem,viewportPos); |
575 | else { | 576 | else { |
576 | if ( !blockMoving ) | 577 | if ( !blockMoving ) |
577 | performItemAction(viewportPos); | 578 | performItemAction(viewportPos); |
578 | } | 579 | } |
579 | } | 580 | } |
580 | } else { // ---------- viewport() | 581 | } else { // ---------- viewport() |
581 | mPopupPos = viewport()->mapToGlobal( me->pos() ); | 582 | mPopupPos = viewport()->mapToGlobal( me->pos() ); |
582 | if ( mActionType == SELECT ) { | 583 | if ( mActionType == SELECT ) { |
583 | performSelectAction( viewportPos ); | 584 | performSelectAction( viewportPos ); |
584 | } | 585 | } |
585 | } | 586 | } |
586 | break; | 587 | break; |
587 | 588 | ||
588 | case QEvent::MouseButtonDblClick: | 589 | case QEvent::MouseButtonDblClick: |
589 | mPopupTimer->stop(); | 590 | mPopupTimer->stop(); |
590 | if (object == viewport()) { | 591 | if (object == viewport()) { |
591 | selectItem(0); | 592 | selectItem(0); |
592 | int x,y; | 593 | int x,y; |
593 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 594 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
594 | int gx,gy; | 595 | int gx,gy; |
595 | contentsToGrid(x,y,gx,gy); | 596 | contentsToGrid(x,y,gx,gy); |
596 | emit newEventSignal(gx,gy); | 597 | emit newEventSignal(gx,gy); |
597 | } else { | 598 | } else { |
598 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; | 599 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; |
599 | selectItem(doubleClickedItem); | 600 | selectItem(doubleClickedItem); |
600 | if ( KOPrefs::instance()->mEditOnDoubleClick ) | 601 | if ( KOPrefs::instance()->mEditOnDoubleClick ) |
601 | emit editIncidenceSignal(doubleClickedItem->incidence()); | 602 | emit editIncidenceSignal(doubleClickedItem->incidence()); |
602 | else | 603 | else |
603 | emit showIncidenceSignal(doubleClickedItem->incidence()); | 604 | emit showIncidenceSignal(doubleClickedItem->incidence()); |
604 | } | 605 | } |
605 | break; | 606 | break; |
606 | 607 | ||
607 | default: | 608 | default: |
608 | break; | 609 | break; |
609 | } | 610 | } |
610 | return true; | 611 | return true; |
611 | #if 0 | 612 | #if 0 |
612 | //qDebug("KOAgenda::eventFilter_mous "); | 613 | //qDebug("KOAgenda::eventFilter_mous "); |
613 | QPoint viewportPos; | 614 | QPoint viewportPos; |
614 | if (object != viewport()) { | 615 | if (object != viewport()) { |
615 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); | 616 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); |
616 | } else { | 617 | } else { |
617 | viewportPos = me->pos(); | 618 | viewportPos = me->pos(); |
618 | } | 619 | } |
619 | static int startX = 0; | 620 | static int startX = 0; |
620 | static int startY = 0; | 621 | static int startY = 0; |
621 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); | 622 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); |
622 | static bool blockMoving = true; | 623 | static bool blockMoving = true; |
623 | static bool leftMouseDown = false; | 624 | static bool leftMouseDown = false; |
624 | bool rightButtonPressed = false; | 625 | bool rightButtonPressed = false; |
625 | switch (me->type()) { | 626 | switch (me->type()) { |
626 | case QEvent::MouseButtonPress: | 627 | case QEvent::MouseButtonPress: |
627 | if (me->button() == LeftButton) { | 628 | if (me->button() == LeftButton) { |
628 | leftMouseDown = true; | 629 | leftMouseDown = true; |
629 | } | 630 | } |
630 | else if (me->button() == RightButton) { | 631 | else if (me->button() == RightButton) { |
631 | leftMouseDown = false; | 632 | leftMouseDown = false; |
632 | } | 633 | } |
633 | blockMoving = true; | 634 | blockMoving = true; |
634 | startX = viewportPos.x(); | 635 | startX = viewportPos.x(); |
635 | startY = viewportPos.y(); | 636 | startY = viewportPos.y(); |
636 | if (object != viewport()) { // item clicked ************** | 637 | if (object != viewport()) { // item clicked ************** |
637 | if (me->button() == RightButton) { | 638 | if (me->button() == RightButton) { |
638 | leftMouseDown = false; | 639 | leftMouseDown = false; |
639 | mClickedItem = (KOAgendaItem *)object; | 640 | mClickedItem = (KOAgendaItem *)object; |
640 | if (mActionItem ) { | 641 | if (mActionItem ) { |
641 | endItemAction(); | 642 | endItemAction(); |
642 | } | 643 | } |
643 | if (mClickedItem) { | 644 | if (mClickedItem) { |
644 | selectItem(mClickedItem); | 645 | selectItem(mClickedItem); |
645 | emit showIncidencePopupSignal(mClickedItem->incidence()); | 646 | emit showIncidencePopupSignal(mClickedItem->incidence()); |
646 | } | 647 | } |
647 | return true; | 648 | return true; |
648 | } else if (me->button() == LeftButton) { | 649 | } else if (me->button() == LeftButton) { |
649 | mActionItem = (KOAgendaItem *)object; | 650 | mActionItem = (KOAgendaItem *)object; |
650 | if (mActionItem) { | 651 | if (mActionItem) { |
651 | if ( mSelectionHeight > 0 ) { | 652 | if ( mSelectionHeight > 0 ) { |
652 | int selectionCellX = mSelectionCellX * mGridSpacingX; | 653 | int selectionCellX = mSelectionCellX * mGridSpacingX; |
653 | int selectionYTop = mSelectionYTop; | 654 | int selectionYTop = mSelectionYTop; |
654 | int gridSpacingX = mGridSpacingX; | 655 | int gridSpacingX = mGridSpacingX; |
655 | int selectionHeight = mSelectionHeight; | 656 | int selectionHeight = mSelectionHeight; |
656 | clearSelection(); | 657 | clearSelection(); |
657 | repaintContents( selectionCellX, selectionYTop, | 658 | repaintContents( selectionCellX, selectionYTop, |
658 | gridSpacingX, selectionHeight,false ); | 659 | gridSpacingX, selectionHeight,false ); |
659 | } | 660 | } |
660 | selectItem(mActionItem); | 661 | selectItem(mActionItem); |
661 | Incidence *incidence = mActionItem->incidence(); | 662 | Incidence *incidence = mActionItem->incidence(); |
662 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { | 663 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { |
663 | mActionItem = 0; | 664 | mActionItem = 0; |
664 | } else { | 665 | } else { |
665 | startItemAction(viewportPos); | 666 | startItemAction(viewportPos); |
666 | } | 667 | } |
667 | } | 668 | } |
668 | } | 669 | } |
669 | } else { // ---------- viewport() | 670 | } else { // ---------- viewport() |
670 | selectItem(0); | 671 | selectItem(0); |
671 | mActionItem = 0; | 672 | mActionItem = 0; |
672 | if (me->button() == LeftButton ) { | 673 | if (me->button() == LeftButton ) { |
673 | setCursor(arrowCursor); | 674 | setCursor(arrowCursor); |
674 | startSelectAction(viewportPos); | 675 | startSelectAction(viewportPos); |
675 | } else if (me->button() == RightButton ) { | 676 | } else if (me->button() == RightButton ) { |
676 | setCursor(arrowCursor); | 677 | setCursor(arrowCursor); |
677 | if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action | 678 | if ( leftMouseDown ) { // we have a simulated right click - clear left mouse action |
678 | endSelectAction( false ); // do not emit new event signal | 679 | endSelectAction( false ); // do not emit new event signal |
679 | leftMouseDown = false; // no more leftMouse computation | 680 | leftMouseDown = false; // no more leftMouse computation |
680 | } | 681 | } |
681 | int x,y; | 682 | int x,y; |
682 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 683 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
683 | int gx,gy; | 684 | int gx,gy; |
684 | contentsToGrid(x,y,gx,gy); | 685 | contentsToGrid(x,y,gx,gy); |
685 | mCurrentCellX = gx; | 686 | mCurrentCellX = gx; |
686 | mCurrentCellY = gy; | 687 | mCurrentCellY = gy; |
687 | mStartCellX = gx; | 688 | mStartCellX = gx; |
688 | mStartCellY = gy; | 689 | mStartCellY = gy; |
689 | mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); | 690 | mNewItemPopup->popup( viewport()->mapToGlobal( me->pos() ) ); |
690 | } | 691 | } |
691 | } | 692 | } |
692 | break; | 693 | break; |
693 | 694 | ||
694 | case QEvent::MouseButtonRelease: | 695 | case QEvent::MouseButtonRelease: |
695 | 696 | ||
696 | if (object != viewport()) { | 697 | if (object != viewport()) { |
697 | if (me->button() == LeftButton && leftMouseDown) { | 698 | if (me->button() == LeftButton && leftMouseDown) { |
698 | if (mActionItem) { | 699 | if (mActionItem) { |
699 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 700 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
700 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); | 701 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); |
701 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { | 702 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { |
702 | mScrollUpTimer.stop(); | 703 | mScrollUpTimer.stop(); |
703 | mScrollDownTimer.stop(); | 704 | mScrollDownTimer.stop(); |
704 | mActionItem->resetMove(); | 705 | mActionItem->resetMove(); |
705 | placeSubCells( mActionItem ); | 706 | placeSubCells( mActionItem ); |
706 | // emit startDragSignal( mActionItem->incidence() ); | 707 | // emit startDragSignal( mActionItem->incidence() ); |
707 | setCursor( arrowCursor ); | 708 | setCursor( arrowCursor ); |
708 | mActionItem = 0; | 709 | mActionItem = 0; |
709 | mActionType = NOP; | 710 | mActionType = NOP; |
710 | mItemMoved = 0; | 711 | mItemMoved = 0; |
711 | leftMouseDown = false; | 712 | leftMouseDown = false; |
712 | return true; | 713 | return true; |
713 | } | 714 | } |
714 | endItemAction(); | 715 | endItemAction(); |
715 | } | 716 | } |
716 | } | 717 | } |
717 | 718 | ||
718 | } else { // ---------- viewport() | 719 | } else { // ---------- viewport() |
719 | if (me->button() == LeftButton && leftMouseDown ) { //left click | 720 | if (me->button() == LeftButton && leftMouseDown ) { //left click |
720 | endSelectAction( true ); // emit new event signal | 721 | endSelectAction( true ); // emit new event signal |
721 | } | 722 | } |
722 | } | 723 | } |
723 | if (me->button() == LeftButton) | 724 | if (me->button() == LeftButton) |
724 | leftMouseDown = false; | 725 | leftMouseDown = false; |
725 | 726 | ||
726 | break; | 727 | break; |
727 | 728 | ||
728 | case QEvent::MouseMove: | 729 | case QEvent::MouseMove: |
729 | if ( !leftMouseDown ) | 730 | if ( !leftMouseDown ) |
730 | return true; | 731 | return true; |
731 | if ( blockMoving ) { | 732 | if ( blockMoving ) { |
732 | int dX, dY; | 733 | int dX, dY; |
733 | dX = startX - viewportPos.x(); | 734 | dX = startX - viewportPos.x(); |
734 | if ( dX < 0 ) | 735 | if ( dX < 0 ) |
735 | dX = -dX; | 736 | dX = -dX; |
736 | dY = viewportPos.y() - startY; | 737 | dY = viewportPos.y() - startY; |
737 | if ( dY < 0 ) | 738 | if ( dY < 0 ) |
738 | dY = -dY; | 739 | dY = -dY; |
739 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); | 740 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); |
740 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 741 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
741 | blockMoving = false; | 742 | blockMoving = false; |
742 | } | 743 | } |
743 | } | 744 | } |
744 | if (object != viewport()) { | 745 | if (object != viewport()) { |
745 | KOAgendaItem *moveItem = (KOAgendaItem *)object; | 746 | KOAgendaItem *moveItem = (KOAgendaItem *)object; |
746 | if (!moveItem->incidence()->isReadOnly() ) { | 747 | if (!moveItem->incidence()->isReadOnly() ) { |
747 | if (!mActionItem) | 748 | if (!mActionItem) |
748 | setNoActionCursor(moveItem,viewportPos); | 749 | setNoActionCursor(moveItem,viewportPos); |
749 | else { | 750 | else { |
750 | if ( !blockMoving ) | 751 | if ( !blockMoving ) |
751 | performItemAction(viewportPos); | 752 | performItemAction(viewportPos); |
752 | } | 753 | } |
753 | } | 754 | } |
754 | } else { // ---------- viewport() | 755 | } else { // ---------- viewport() |
755 | if ( mActionType == SELECT ) { | 756 | if ( mActionType == SELECT ) { |
756 | performSelectAction( viewportPos ); | 757 | performSelectAction( viewportPos ); |
757 | } | 758 | } |
758 | } | 759 | } |
759 | break; | 760 | break; |
760 | 761 | ||
761 | case QEvent::MouseButtonDblClick: | 762 | case QEvent::MouseButtonDblClick: |
762 | blockMoving = false; | 763 | blockMoving = false; |
763 | leftMouseDown = false; | 764 | leftMouseDown = false; |
764 | if (object == viewport()) { | 765 | if (object == viewport()) { |
765 | selectItem(0); | 766 | selectItem(0); |
766 | int x,y; | 767 | int x,y; |
767 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 768 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
768 | int gx,gy; | 769 | int gx,gy; |
769 | contentsToGrid(x,y,gx,gy); | 770 | contentsToGrid(x,y,gx,gy); |
770 | emit newEventSignal(gx,gy); | 771 | emit newEventSignal(gx,gy); |
771 | } else { | 772 | } else { |
772 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; | 773 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; |
773 | selectItem(doubleClickedItem); | 774 | selectItem(doubleClickedItem); |
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index 6d1e6d5..20a5b74 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp | |||
@@ -83,773 +83,774 @@ TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : | |||
83 | { | 83 | { |
84 | myPix.resize( 1, 1 ); | 84 | myPix.resize( 1, 1 ); |
85 | mRows = rows; | 85 | mRows = rows; |
86 | 86 | ||
87 | mRedrawNeeded = true; | 87 | mRedrawNeeded = true; |
88 | setMinimumHeight( 20 ); | 88 | setMinimumHeight( 20 ); |
89 | mCellHeight = KOPrefs::instance()->mHourSize*4; | 89 | mCellHeight = KOPrefs::instance()->mHourSize*4; |
90 | 90 | ||
91 | enableClipper(true); | 91 | enableClipper(true); |
92 | 92 | ||
93 | setHScrollBarMode(AlwaysOff); | 93 | setHScrollBarMode(AlwaysOff); |
94 | setVScrollBarMode(AlwaysOff); | 94 | setVScrollBarMode(AlwaysOff); |
95 | 95 | ||
96 | resizeContents(50,mRows * mCellHeight); | 96 | resizeContents(50,mRows * mCellHeight); |
97 | 97 | ||
98 | viewport()->setBackgroundMode( PaletteBackground ); | 98 | viewport()->setBackgroundMode( PaletteBackground ); |
99 | } | 99 | } |
100 | 100 | ||
101 | void TimeLabels::setCellHeight(int height) | 101 | void TimeLabels::setCellHeight(int height) |
102 | { | 102 | { |
103 | mCellHeight = height; | 103 | mCellHeight = height; |
104 | } | 104 | } |
105 | 105 | ||
106 | /* | 106 | /* |
107 | Optimization so that only the "dirty" portion of the scroll view | 107 | Optimization so that only the "dirty" portion of the scroll view |
108 | is redrawn. Unfortunately, this is not called by default paintEvent() method. | 108 | is redrawn. Unfortunately, this is not called by default paintEvent() method. |
109 | */ | 109 | */ |
110 | void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) | 110 | void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) |
111 | { | 111 | { |
112 | 112 | ||
113 | cx = contentsX() + frameWidth()*2; | 113 | cx = contentsX() + frameWidth()*2; |
114 | cw = contentsWidth() ; | 114 | cw = contentsWidth() ; |
115 | // end of workaround | 115 | // end of workaround |
116 | 116 | ||
117 | int cell = ((int)(cy/mCellHeight)); | 117 | int cell = ((int)(cy/mCellHeight)); |
118 | int y = cell * mCellHeight; | 118 | int y = cell * mCellHeight; |
119 | QFontMetrics fm = fontMetrics(); | 119 | QFontMetrics fm = fontMetrics(); |
120 | QString hour; | 120 | QString hour; |
121 | QString suffix = "am"; | 121 | QString suffix = "am"; |
122 | int timeHeight = fm.ascent(); | 122 | int timeHeight = fm.ascent(); |
123 | QFont nFont = font(); | 123 | QFont nFont = font(); |
124 | p->setFont( font()); | 124 | p->setFont( font()); |
125 | 125 | ||
126 | if (!KGlobal::locale()->use12Clock()) { | 126 | if (!KGlobal::locale()->use12Clock()) { |
127 | suffix = "00"; | 127 | suffix = "00"; |
128 | } else | 128 | } else |
129 | if (cell > 11) suffix = "pm"; | 129 | if (cell > 11) suffix = "pm"; |
130 | 130 | ||
131 | if ( timeHeight > mCellHeight ) { | 131 | if ( timeHeight > mCellHeight ) { |
132 | timeHeight = mCellHeight-1; | 132 | timeHeight = mCellHeight-1; |
133 | int pointS = nFont.pointSize(); | 133 | int pointS = nFont.pointSize(); |
134 | while ( pointS > 4 ) { | 134 | while ( pointS > 4 ) { |
135 | nFont.setPointSize( pointS ); | 135 | nFont.setPointSize( pointS ); |
136 | fm = QFontMetrics( nFont ); | 136 | fm = QFontMetrics( nFont ); |
137 | if ( fm.ascent() < mCellHeight ) | 137 | if ( fm.ascent() < mCellHeight ) |
138 | break; | 138 | break; |
139 | -- pointS; | 139 | -- pointS; |
140 | } | 140 | } |
141 | fm = QFontMetrics( nFont ); | 141 | fm = QFontMetrics( nFont ); |
142 | timeHeight = fm.ascent(); | 142 | timeHeight = fm.ascent(); |
143 | } | 143 | } |
144 | //timeHeight -= (timeHeight/4-2); | 144 | //timeHeight -= (timeHeight/4-2); |
145 | QFont sFont = nFont; | 145 | QFont sFont = nFont; |
146 | sFont.setPointSize( sFont.pointSize()/2 ); | 146 | sFont.setPointSize( sFont.pointSize()/2 ); |
147 | QFontMetrics fmS( sFont ); | 147 | QFontMetrics fmS( sFont ); |
148 | int sHei = fmS.ascent() ; | 148 | int sHei = fmS.ascent() ; |
149 | //sHei -= (sHei/4-2); | 149 | //sHei -= (sHei/4-2); |
150 | int startW = mMiniWidth - frameWidth()-2 ; | 150 | int startW = mMiniWidth - frameWidth()-2 ; |
151 | int tw2 = fmS.width(suffix); | 151 | int tw2 = fmS.width(suffix); |
152 | timeHeight = (timeHeight-1) /2 -1; | 152 | timeHeight = (timeHeight-1) /2 -1; |
153 | //testline | 153 | //testline |
154 | //p->drawLine(0,0,0,contentsHeight()); | 154 | //p->drawLine(0,0,0,contentsHeight()); |
155 | while (y < cy + ch+mCellHeight) { | 155 | while (y < cy + ch+mCellHeight) { |
156 | p->drawLine(startW-tw2+1 ,y,cw+2,y); | 156 | p->drawLine(startW-tw2+1 ,y,cw+2,y); |
157 | hour.setNum(cell); | 157 | hour.setNum(cell); |
158 | // handle 24h and am/pm time formats | 158 | // handle 24h and am/pm time formats |
159 | if (KGlobal::locale()->use12Clock()) { | 159 | if (KGlobal::locale()->use12Clock()) { |
160 | if (cell == 12) suffix = "pm"; | 160 | if (cell == 12) suffix = "pm"; |
161 | if (cell == 0) hour.setNum(12); | 161 | if (cell == 0) hour.setNum(12); |
162 | if (cell > 12) hour.setNum(cell - 12); | 162 | if (cell > 12) hour.setNum(cell - 12); |
163 | } | 163 | } |
164 | 164 | ||
165 | // center and draw the time label | 165 | // center and draw the time label |
166 | int timeWidth = fm.width(hour); | 166 | int timeWidth = fm.width(hour); |
167 | int offset = startW - timeWidth - tw2 -1 ; | 167 | int offset = startW - timeWidth - tw2 -1 ; |
168 | p->setFont( nFont ); | 168 | p->setFont( nFont ); |
169 | p->drawText( offset, y+ timeHeight, hour); | 169 | p->drawText( offset, y+ timeHeight, hour); |
170 | p->setFont( sFont ); | 170 | p->setFont( sFont ); |
171 | offset = startW - tw2; | 171 | offset = startW - tw2; |
172 | p->drawText( offset, y -1, suffix); | 172 | p->drawText( offset, y -1, suffix); |
173 | 173 | ||
174 | // increment indices | 174 | // increment indices |
175 | y += mCellHeight; | 175 | y += mCellHeight; |
176 | cell++; | 176 | cell++; |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | 180 | ||
181 | 181 | ||
182 | } | 182 | } |
183 | 183 | ||
184 | /** | 184 | /** |
185 | Calculates the minimum width. | 185 | Calculates the minimum width. |
186 | */ | 186 | */ |
187 | int TimeLabels::minimumWidth() const | 187 | int TimeLabels::minimumWidth() const |
188 | { | 188 | { |
189 | return mMiniWidth; | 189 | return mMiniWidth; |
190 | } | 190 | } |
191 | 191 | ||
192 | /** updates widget's internal state */ | 192 | /** updates widget's internal state */ |
193 | void TimeLabels::updateConfig() | 193 | void TimeLabels::updateConfig() |
194 | { | 194 | { |
195 | mRedrawNeeded = true; | 195 | mRedrawNeeded = true; |
196 | // set the font | 196 | // set the font |
197 | // config->setGroup("Fonts"); | 197 | // config->setGroup("Fonts"); |
198 | // QFont font = config->readFontEntry("TimeBar Font"); | 198 | // QFont font = config->readFontEntry("TimeBar Font"); |
199 | setFont(KOPrefs::instance()->mTimeBarFont); | 199 | setFont(KOPrefs::instance()->mTimeBarFont); |
200 | QString test = "20"; | 200 | QString test = "20"; |
201 | if (KGlobal::locale()->use12Clock()) | 201 | if (KGlobal::locale()->use12Clock()) |
202 | test = "12"; | 202 | test = "12"; |
203 | mMiniWidth = fontMetrics().width(test); | 203 | mMiniWidth = fontMetrics().width(test); |
204 | if (KGlobal::locale()->use12Clock()) | 204 | if (KGlobal::locale()->use12Clock()) |
205 | test = "pm"; | 205 | test = "pm"; |
206 | else { | 206 | else { |
207 | test = "00"; | 207 | test = "00"; |
208 | } | 208 | } |
209 | QFont sFont = font(); | 209 | QFont sFont = font(); |
210 | sFont.setPointSize( sFont.pointSize()/2 ); | 210 | sFont.setPointSize( sFont.pointSize()/2 ); |
211 | QFontMetrics fmS( sFont ); | 211 | QFontMetrics fmS( sFont ); |
212 | mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ; | 212 | mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ; |
213 | // update geometry restrictions based on new settings | 213 | // update geometry restrictions based on new settings |
214 | setFixedWidth( mMiniWidth ); | 214 | setFixedWidth( mMiniWidth ); |
215 | 215 | ||
216 | // update HourSize | 216 | // update HourSize |
217 | mCellHeight = KOPrefs::instance()->mHourSize*4; | 217 | mCellHeight = KOPrefs::instance()->mHourSize*4; |
218 | resizeContents(mMiniWidth,mRows * mCellHeight+1); | 218 | resizeContents(mMiniWidth,mRows * mCellHeight+1); |
219 | } | 219 | } |
220 | 220 | ||
221 | /** update time label positions */ | 221 | /** update time label positions */ |
222 | void TimeLabels::positionChanged() | 222 | void TimeLabels::positionChanged() |
223 | { | 223 | { |
224 | int adjustment = mAgenda->contentsY(); | 224 | int adjustment = mAgenda->contentsY(); |
225 | setContentsPos(0, adjustment); | 225 | setContentsPos(0, adjustment); |
226 | } | 226 | } |
227 | 227 | ||
228 | /** */ | 228 | /** */ |
229 | void TimeLabels::setAgenda(KOAgenda* agenda) | 229 | void TimeLabels::setAgenda(KOAgenda* agenda) |
230 | { | 230 | { |
231 | mAgenda = agenda; | 231 | mAgenda = agenda; |
232 | } | 232 | } |
233 | 233 | ||
234 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) | 234 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) |
235 | { | 235 | { |
236 | mMouseDownY = e->pos().y(); | 236 | mMouseDownY = e->pos().y(); |
237 | mOrgCap = topLevelWidget()->caption(); | 237 | mOrgCap = topLevelWidget()->caption(); |
238 | } | 238 | } |
239 | 239 | ||
240 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) | 240 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) |
241 | { | 241 | { |
242 | int diff = mMouseDownY - e->pos().y(); | 242 | int diff = mMouseDownY - e->pos().y(); |
243 | if ( diff < 10 && diff > -10 ) | 243 | if ( diff < 10 && diff > -10 ) |
244 | return; | 244 | return; |
245 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; | 245 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; |
246 | if ( tSize < 4 ) | 246 | if ( tSize < 4 ) |
247 | tSize = 4; | 247 | tSize = 4; |
248 | if ( tSize > 22 ) | 248 | if ( tSize > 22 ) |
249 | tSize = 22; | 249 | tSize = 22; |
250 | tSize = (tSize-2)/2; | 250 | tSize = (tSize-2)/2; |
251 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); | 251 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); |
252 | 252 | ||
253 | } | 253 | } |
254 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) | 254 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) |
255 | { | 255 | { |
256 | topLevelWidget()->setCaption( mOrgCap ); | 256 | topLevelWidget()->setCaption( mOrgCap ); |
257 | int diff = mMouseDownY - e->pos().y(); | 257 | int diff = mMouseDownY - e->pos().y(); |
258 | if ( diff < 10 && diff > -10 ) | 258 | if ( diff < 10 && diff > -10 ) |
259 | return; | 259 | return; |
260 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); | 260 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); |
261 | if ( tSize < 4 ) | 261 | if ( tSize < 4 ) |
262 | tSize = 4; | 262 | tSize = 4; |
263 | if ( tSize > 22 ) | 263 | if ( tSize > 22 ) |
264 | tSize = 22; | 264 | tSize = 22; |
265 | tSize = (tSize/2)*2; | 265 | tSize = (tSize/2)*2; |
266 | if ( tSize == KOPrefs::instance()->mHourSize ) | 266 | if ( tSize == KOPrefs::instance()->mHourSize ) |
267 | return; | 267 | return; |
268 | KOPrefs::instance()->mHourSize = tSize; | 268 | KOPrefs::instance()->mHourSize = tSize; |
269 | emit scaleChanged(); | 269 | emit scaleChanged(); |
270 | } | 270 | } |
271 | 271 | ||
272 | /** This is called in response to repaint() */ | 272 | /** This is called in response to repaint() */ |
273 | void TimeLabels::paintEvent(QPaintEvent*) | 273 | void TimeLabels::paintEvent(QPaintEvent*) |
274 | { | 274 | { |
275 | 275 | ||
276 | // kdDebug() << "paintevent..." << endl; | 276 | // kdDebug() << "paintevent..." << endl; |
277 | // this is another hack! | 277 | // this is another hack! |
278 | // QPainter painter(this); | 278 | // QPainter painter(this); |
279 | //QString c | 279 | //QString c |
280 | repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); | 280 | repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); |
281 | } | 281 | } |
282 | 282 | ||
283 | //////////////////////////////////////////////////////////////////////////// | 283 | //////////////////////////////////////////////////////////////////////////// |
284 | 284 | ||
285 | EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) | 285 | EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) |
286 | : QFrame(parent,name) | 286 | : QFrame(parent,name) |
287 | { | 287 | { |
288 | mColumns = 1; | 288 | mColumns = 1; |
289 | mTopBox = 0; | 289 | mTopBox = 0; |
290 | mLocation = loc; | 290 | mLocation = loc; |
291 | mTopLayout = 0; | 291 | mTopLayout = 0; |
292 | mPaintWidget = 0; | 292 | mPaintWidget = 0; |
293 | mXOffset = 0; | 293 | mXOffset = 0; |
294 | if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); | 294 | if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); |
295 | else mPixmap = SmallIcon("1downarrow"); | 295 | else mPixmap = SmallIcon("1downarrow"); |
296 | mEnabled.resize(mColumns); | 296 | mEnabled.resize(mColumns); |
297 | mEnabled.fill( false ); | 297 | mEnabled.fill( false ); |
298 | setMinimumHeight(mPixmap.height()); | 298 | setMinimumHeight(mPixmap.height()); |
299 | } | 299 | } |
300 | 300 | ||
301 | EventIndicator::~EventIndicator() | 301 | EventIndicator::~EventIndicator() |
302 | { | 302 | { |
303 | } | 303 | } |
304 | 304 | ||
305 | void EventIndicator::drawContents(QPainter *p) | 305 | void EventIndicator::drawContents(QPainter *p) |
306 | { | 306 | { |
307 | 307 | ||
308 | // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; | 308 | // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; |
309 | KDGanttSplitterHandle* han = 0; | 309 | KDGanttSplitterHandle* han = 0; |
310 | if ( mPaintWidget ) | 310 | if ( mPaintWidget ) |
311 | han = mPaintWidget->firstHandle(); | 311 | han = mPaintWidget->firstHandle(); |
312 | if ( ! han ) { | 312 | if ( ! han ) { |
313 | int i; | 313 | int i; |
314 | for(i=0;i<mColumns;++i) { | 314 | for(i=0;i<mColumns;++i) { |
315 | if (mEnabled[i]) { | 315 | if (mEnabled[i]) { |
316 | int cellWidth = contentsRect().right()/mColumns; | 316 | int cellWidth = contentsRect().right()/mColumns; |
317 | int xOffset = KOGlobals::self()->reverseLayout() ? | 317 | int xOffset = KOGlobals::self()->reverseLayout() ? |
318 | (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : | 318 | (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : |
319 | i*cellWidth + (cellWidth -mPixmap.width()) /2; | 319 | i*cellWidth + (cellWidth -mPixmap.width()) /2; |
320 | p->drawPixmap(QPoint(1+xOffset,0),mPixmap); | 320 | p->drawPixmap(QPoint(1+xOffset,0),mPixmap); |
321 | } | 321 | } |
322 | } | 322 | } |
323 | } else { | 323 | } else { |
324 | han->repaint(); | 324 | han->repaint(); |
325 | //mPaintWidget->setBackgroundColor( red ); | 325 | //mPaintWidget->setBackgroundColor( red ); |
326 | 326 | ||
327 | QPainter pa( han ); | 327 | QPainter pa( han ); |
328 | int i; | 328 | int i; |
329 | bool setColor = false; | 329 | bool setColor = false; |
330 | for(i=0;i<mColumns;++i) { | 330 | for(i=0;i<mColumns;++i) { |
331 | if (mEnabled[i]) { | 331 | if (mEnabled[i]) { |
332 | setColor = true; | 332 | setColor = true; |
333 | 333 | ||
334 | int cellWidth = contentsRect().right()/mColumns; | 334 | int cellWidth = contentsRect().right()/mColumns; |
335 | int xOffset = KOGlobals::self()->reverseLayout() ? | 335 | int xOffset = KOGlobals::self()->reverseLayout() ? |
336 | (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : | 336 | (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : |
337 | i*cellWidth + cellWidth/2 -mPixmap.width()/2; | 337 | i*cellWidth + cellWidth/2 -mPixmap.width()/2; |
338 | pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); | 338 | pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); |
339 | //qDebug("222draw pix %d ",xOffset ); | 339 | //qDebug("222draw pix %d ",xOffset ); |
340 | 340 | ||
341 | } | 341 | } |
342 | 342 | ||
343 | } | 343 | } |
344 | pa.end(); | 344 | pa.end(); |
345 | 345 | ||
346 | } | 346 | } |
347 | } | 347 | } |
348 | 348 | ||
349 | void EventIndicator::setXOffset( int x ) | 349 | void EventIndicator::setXOffset( int x ) |
350 | { | 350 | { |
351 | mXOffset = x; | 351 | mXOffset = x; |
352 | } | 352 | } |
353 | void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) | 353 | void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) |
354 | { | 354 | { |
355 | mPaintWidget = w; | 355 | mPaintWidget = w; |
356 | setMaximumHeight(0); | 356 | setMaximumHeight(0); |
357 | setMinimumHeight(0); | 357 | setMinimumHeight(0); |
358 | } | 358 | } |
359 | void EventIndicator::changeColumns(int columns) | 359 | void EventIndicator::changeColumns(int columns) |
360 | { | 360 | { |
361 | mColumns = columns; | 361 | mColumns = columns; |
362 | mEnabled.resize(mColumns); | 362 | mEnabled.resize(mColumns); |
363 | 363 | ||
364 | update(); | 364 | update(); |
365 | } | 365 | } |
366 | 366 | ||
367 | void EventIndicator::enableColumn(int column, bool enable) | 367 | void EventIndicator::enableColumn(int column, bool enable) |
368 | { | 368 | { |
369 | mEnabled[column] = enable; | 369 | mEnabled[column] = enable; |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | //////////////////////////////////////////////////////////////////////////// | 373 | //////////////////////////////////////////////////////////////////////////// |
374 | //////////////////////////////////////////////////////////////////////////// | 374 | //////////////////////////////////////////////////////////////////////////// |
375 | //////////////////////////////////////////////////////////////////////////// | 375 | //////////////////////////////////////////////////////////////////////////// |
376 | 376 | ||
377 | KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : | 377 | KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : |
378 | KOEventView (cal,parent,name) | 378 | KOEventView (cal,parent,name) |
379 | { | 379 | { |
380 | mBlockUpdating = true; | 380 | mBlockUpdating = true; |
381 | mStartHour = 8; | 381 | mStartHour = 8; |
382 | mSelectedDates.append(QDate::currentDate()); | 382 | mSelectedDates.append(QDate::currentDate()); |
383 | 383 | ||
384 | mLayoutDayLabels = 0; | 384 | mLayoutDayLabels = 0; |
385 | mDayLabelsFrame = 0; | 385 | mDayLabelsFrame = 0; |
386 | mDayLabels = 0; | 386 | mDayLabels = 0; |
387 | bool isRTL = KOGlobals::self()->reverseLayout(); | 387 | bool isRTL = KOGlobals::self()->reverseLayout(); |
388 | QPixmap expandPix; | 388 | QPixmap expandPix; |
389 | if ( KOPrefs::instance()->mVerticalScreen ) { | 389 | if ( KOPrefs::instance()->mVerticalScreen ) { |
390 | expandPix = SmallIcon( "1updownarrow" ); | 390 | expandPix = SmallIcon( "1updownarrow" ); |
391 | } else { | 391 | } else { |
392 | expandPix = SmallIcon("1leftrightarrow" ); | 392 | expandPix = SmallIcon("1leftrightarrow" ); |
393 | } | 393 | } |
394 | 394 | ||
395 | QBoxLayout *topLayout = new QVBoxLayout(this); | 395 | QBoxLayout *topLayout = new QVBoxLayout(this); |
396 | 396 | ||
397 | // Create day name labels for agenda columns | 397 | // Create day name labels for agenda columns |
398 | // Create agenda splitter | 398 | // Create agenda splitter |
399 | 399 | ||
400 | mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 400 | mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
401 | mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); | 401 | mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); |
402 | topLayout->addWidget( mSplitterAgenda ); | 402 | topLayout->addWidget( mSplitterAgenda ); |
403 | mAllDayFrame = new QHBox(mSplitterAgenda); | 403 | mAllDayFrame = new QHBox(mSplitterAgenda); |
404 | mAllDayFrame->setFocusPolicy(NoFocus); | 404 | mAllDayFrame->setFocusPolicy(NoFocus); |
405 | QWidget *agendaFrame = new QWidget(mSplitterAgenda); | 405 | QWidget *agendaFrame = new QWidget(mSplitterAgenda); |
406 | agendaFrame->setFocusPolicy(NoFocus); | 406 | agendaFrame->setFocusPolicy(NoFocus); |
407 | 407 | ||
408 | // Create all-day agenda widget | 408 | // Create all-day agenda widget |
409 | mDummyAllDayLeft = new QVBox( mAllDayFrame ); | 409 | mDummyAllDayLeft = new QVBox( mAllDayFrame ); |
410 | 410 | ||
411 | mExpandButton = new QPushButton(mDummyAllDayLeft); | 411 | mExpandButton = new QPushButton(mDummyAllDayLeft); |
412 | mExpandButton->setPixmap( expandPix ); | 412 | mExpandButton->setPixmap( expandPix ); |
413 | int widebut = mExpandButton->sizeHint().width()+4; | 413 | int widebut = mExpandButton->sizeHint().width()+4; |
414 | int heibut = mExpandButton->sizeHint().height()+4; | 414 | int heibut = mExpandButton->sizeHint().height()+4; |
415 | if ( heibut > widebut ) | 415 | if ( heibut > widebut ) |
416 | widebut = heibut ; | 416 | widebut = heibut ; |
417 | 417 | ||
418 | //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, | 418 | //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, |
419 | // QSizePolicy::Fixed ) ); | 419 | // QSizePolicy::Fixed ) ); |
420 | mExpandButton->setFixedSize( widebut, widebut); | 420 | mExpandButton->setFixedSize( widebut, widebut); |
421 | connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); | 421 | connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); |
422 | mExpandButton->setFocusPolicy(NoFocus); | 422 | mExpandButton->setFocusPolicy(NoFocus); |
423 | mAllDayAgenda = new KOAgenda(1,mAllDayFrame); | 423 | mAllDayAgenda = new KOAgenda(1,mAllDayFrame); |
424 | mAllDayAgenda->setFocusPolicy(NoFocus); | 424 | mAllDayAgenda->setFocusPolicy(NoFocus); |
425 | QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); | 425 | QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); |
426 | 426 | ||
427 | // Create event context menu for all day agenda | 427 | // Create event context menu for all day agenda |
428 | //mAllDayAgendaPopup = eventPopup(); | 428 | //mAllDayAgendaPopup = eventPopup(); |
429 | 429 | ||
430 | // Create agenda frame | 430 | // Create agenda frame |
431 | QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); | 431 | QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); |
432 | // QHBox *agendaFrame = new QHBox(splitterAgenda); | 432 | // QHBox *agendaFrame = new QHBox(splitterAgenda); |
433 | 433 | ||
434 | // create event indicator bars | 434 | // create event indicator bars |
435 | mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); | 435 | mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); |
436 | #ifndef DESKTOP_VERSION | 436 | #ifndef DESKTOP_VERSION |
437 | // FIX | 437 | // FIX |
438 | mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); | 438 | mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); |
439 | #endif | 439 | #endif |
440 | mDayLabelsFrame = new QHBox(agendaFrame); | 440 | mDayLabelsFrame = new QHBox(agendaFrame); |
441 | //topLayout->addWidget(mDayLabelsFrame); | 441 | //topLayout->addWidget(mDayLabelsFrame); |
442 | mDayLabels = new QFrame (mDayLabelsFrame); | 442 | mDayLabels = new QFrame (mDayLabelsFrame); |
443 | mLayoutDayLabels = new QHBoxLayout(mDayLabels); | 443 | mLayoutDayLabels = new QHBoxLayout(mDayLabels); |
444 | agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); | 444 | agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); |
445 | agendaLayout->addWidget(mEventIndicatorTop,1,1); | 445 | agendaLayout->addWidget(mEventIndicatorTop,1,1); |
446 | 446 | ||
447 | mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, | 447 | mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, |
448 | agendaFrame); | 448 | agendaFrame); |
449 | agendaLayout->addWidget(mEventIndicatorBottom,3,1); | 449 | agendaLayout->addWidget(mEventIndicatorBottom,3,1); |
450 | QWidget *dummyAgendaRight = new QWidget(agendaFrame); | 450 | QWidget *dummyAgendaRight = new QWidget(agendaFrame); |
451 | agendaLayout->addWidget(dummyAgendaRight,1,2); | 451 | agendaLayout->addWidget(dummyAgendaRight,1,2); |
452 | 452 | ||
453 | // Create time labels | 453 | // Create time labels |
454 | mTimeLabels = new TimeLabels(24,agendaFrame); | 454 | mTimeLabels = new TimeLabels(24,agendaFrame); |
455 | agendaLayout->addWidget(mTimeLabels,2,0); | 455 | agendaLayout->addWidget(mTimeLabels,2,0); |
456 | connect(mTimeLabels,SIGNAL( scaleChanged()), | 456 | connect(mTimeLabels,SIGNAL( scaleChanged()), |
457 | this,SLOT(updateConfig())); | 457 | this,SLOT(updateConfig())); |
458 | 458 | ||
459 | // Create agenda | 459 | // Create agenda |
460 | mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); | 460 | mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); |
461 | agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); | 461 | agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); |
462 | agendaLayout->setColStretch(1,1); | 462 | agendaLayout->setColStretch(1,1); |
463 | mAgenda->setFocusPolicy(NoFocus); | 463 | mAgenda->setFocusPolicy(NoFocus); |
464 | // Create event context menu for agenda | 464 | // Create event context menu for agenda |
465 | mAllAgendaPopup = eventPopup(); | 465 | mAllAgendaPopup = eventPopup(); |
466 | 466 | ||
467 | #if 0 | ||
467 | mAllAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), | 468 | mAllAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), |
468 | i18n("Toggle Alarm"),mAgenda, | 469 | i18n("Toggle Alarm"),mAgenda, |
469 | SLOT(popupAlarm()),true); | 470 | SLOT(popupAlarm()),true); |
470 | 471 | ||
471 | 472 | #endif | |
472 | connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), | 473 | connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), |
473 | mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); | 474 | mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); |
474 | 475 | ||
475 | connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), | 476 | connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), |
476 | mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); | 477 | mAllAgendaPopup,SLOT(showIncidencePopup(Incidence *))); |
477 | mAgenda->setPopup( mAllAgendaPopup ); | 478 | mAgenda->setPopup( mAllAgendaPopup ); |
478 | mAllDayAgenda->setPopup( mAllAgendaPopup ); | 479 | mAllDayAgenda->setPopup( mAllAgendaPopup ); |
479 | // make connections between dependent widgets | 480 | // make connections between dependent widgets |
480 | mTimeLabels->setAgenda(mAgenda); | 481 | mTimeLabels->setAgenda(mAgenda); |
481 | 482 | ||
482 | // Update widgets to reflect user preferences | 483 | // Update widgets to reflect user preferences |
483 | // updateConfig(); | 484 | // updateConfig(); |
484 | 485 | ||
485 | // createDayLabels(); | 486 | // createDayLabels(); |
486 | 487 | ||
487 | // these blank widgets make the All Day Event box line up with the agenda | 488 | // these blank widgets make the All Day Event box line up with the agenda |
488 | dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); | 489 | dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); |
489 | dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); | 490 | dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); |
490 | mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); | 491 | mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); |
491 | 492 | ||
492 | // Scrolling | 493 | // Scrolling |
493 | connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), | 494 | connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), |
494 | mTimeLabels, SLOT(positionChanged())); | 495 | mTimeLabels, SLOT(positionChanged())); |
495 | connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), | 496 | connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), |
496 | SLOT(setContentsPos(int))); | 497 | SLOT(setContentsPos(int))); |
497 | 498 | ||
498 | connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); | 499 | connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); |
499 | connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); | 500 | connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); |
500 | 501 | ||
501 | // Create/Show/Edit/Delete Event | 502 | // Create/Show/Edit/Delete Event |
502 | connect(mAgenda,SIGNAL(newEventSignal(int,int)), | 503 | connect(mAgenda,SIGNAL(newEventSignal(int,int)), |
503 | SLOT(newEvent(int,int))); | 504 | SLOT(newEvent(int,int))); |
504 | connect(mAgenda,SIGNAL(newTodoSignal(int,int)), | 505 | connect(mAgenda,SIGNAL(newTodoSignal(int,int)), |
505 | SLOT(newTodo(int,int))); | 506 | SLOT(newTodo(int,int))); |
506 | connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), | 507 | connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), |
507 | SLOT(newEvent(int,int,int,int))); | 508 | SLOT(newEvent(int,int,int,int))); |
508 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), | 509 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), |
509 | SLOT(newEventAllDay(int,int))); | 510 | SLOT(newEventAllDay(int,int))); |
510 | connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), | 511 | connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), |
511 | SLOT(newTodoAllDay(int,int))); | 512 | SLOT(newTodoAllDay(int,int))); |
512 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), | 513 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), |
513 | SLOT(newEventAllDay(int,int))); | 514 | SLOT(newEventAllDay(int,int))); |
514 | connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), | 515 | connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), |
515 | SLOT(newTimeSpanSelected(int,int,int,int))); | 516 | SLOT(newTimeSpanSelected(int,int,int,int))); |
516 | connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), | 517 | connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), |
517 | SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); | 518 | SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); |
518 | connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); | 519 | connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); |
519 | connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); | 520 | connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); |
520 | 521 | ||
521 | connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), | 522 | connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), |
522 | SIGNAL(editIncidenceSignal(Incidence *))); | 523 | SIGNAL(editIncidenceSignal(Incidence *))); |
523 | connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), | 524 | connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), |
524 | SIGNAL(editIncidenceSignal(Incidence *))); | 525 | SIGNAL(editIncidenceSignal(Incidence *))); |
525 | connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), | 526 | connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), |
526 | SIGNAL(showIncidenceSignal(Incidence *))); | 527 | SIGNAL(showIncidenceSignal(Incidence *))); |
527 | connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), | 528 | connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), |
528 | SIGNAL(showIncidenceSignal(Incidence *))); | 529 | SIGNAL(showIncidenceSignal(Incidence *))); |
529 | connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), | 530 | connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), |
530 | SIGNAL(deleteIncidenceSignal(Incidence *))); | 531 | SIGNAL(deleteIncidenceSignal(Incidence *))); |
531 | connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), | 532 | connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), |
532 | SIGNAL(deleteIncidenceSignal(Incidence *))); | 533 | SIGNAL(deleteIncidenceSignal(Incidence *))); |
533 | 534 | ||
534 | connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), | 535 | connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), |
535 | SLOT(updateEventDates(KOAgendaItem *, int ))); | 536 | SLOT(updateEventDates(KOAgendaItem *, int ))); |
536 | connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), | 537 | connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), |
537 | SLOT(updateEventDates(KOAgendaItem *, int))); | 538 | SLOT(updateEventDates(KOAgendaItem *, int))); |
538 | 539 | ||
539 | // event indicator update | 540 | // event indicator update |
540 | connect(mAgenda,SIGNAL(lowerYChanged(int)), | 541 | connect(mAgenda,SIGNAL(lowerYChanged(int)), |
541 | SLOT(updateEventIndicatorTop(int))); | 542 | SLOT(updateEventIndicatorTop(int))); |
542 | connect(mAgenda,SIGNAL(upperYChanged(int)), | 543 | connect(mAgenda,SIGNAL(upperYChanged(int)), |
543 | SLOT(updateEventIndicatorBottom(int))); | 544 | SLOT(updateEventIndicatorBottom(int))); |
544 | // drag signals | 545 | // drag signals |
545 | /* | 546 | /* |
546 | connect(mAgenda,SIGNAL(startDragSignal(Event *)), | 547 | connect(mAgenda,SIGNAL(startDragSignal(Event *)), |
547 | SLOT(startDrag(Event *))); | 548 | SLOT(startDrag(Event *))); |
548 | connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), | 549 | connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), |
549 | SLOT(startDrag(Event *))); | 550 | SLOT(startDrag(Event *))); |
550 | */ | 551 | */ |
551 | // synchronize selections | 552 | // synchronize selections |
552 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 553 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
553 | mAllDayAgenda, SLOT( deselectItem() ) ); | 554 | mAllDayAgenda, SLOT( deselectItem() ) ); |
554 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 555 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
555 | mAgenda, SLOT( deselectItem() ) ); | 556 | mAgenda, SLOT( deselectItem() ) ); |
556 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 557 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
557 | SIGNAL( incidenceSelected( Incidence * ) ) ); | 558 | SIGNAL( incidenceSelected( Incidence * ) ) ); |
558 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 559 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
559 | SIGNAL( incidenceSelected( Incidence * ) ) ); | 560 | SIGNAL( incidenceSelected( Incidence * ) ) ); |
560 | connect( mAgenda, SIGNAL( resizedSignal() ), | 561 | connect( mAgenda, SIGNAL( resizedSignal() ), |
561 | SLOT( updateConfig( ) ) ); | 562 | SLOT( updateConfig( ) ) ); |
562 | connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), | 563 | connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), |
563 | SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); | 564 | SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); |
564 | connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), | 565 | connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), |
565 | SLOT( addToCalSlot(Incidence * , Incidence *) ) ); | 566 | SLOT( addToCalSlot(Incidence * , Incidence *) ) ); |
566 | // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); | 567 | // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); |
567 | //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); | 568 | //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); |
568 | 569 | ||
569 | 570 | ||
570 | } | 571 | } |
571 | 572 | ||
572 | void KOAgendaView::toggleAllDay() | 573 | void KOAgendaView::toggleAllDay() |
573 | { | 574 | { |
574 | if ( mSplitterAgenda->firstHandle() ) | 575 | if ( mSplitterAgenda->firstHandle() ) |
575 | mSplitterAgenda->firstHandle()->toggle(); | 576 | mSplitterAgenda->firstHandle()->toggle(); |
576 | } | 577 | } |
577 | void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) | 578 | void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) |
578 | { | 579 | { |
579 | calendar()->addIncidence( inc ); | 580 | calendar()->addIncidence( inc ); |
580 | 581 | ||
581 | if ( incOld ) { | 582 | if ( incOld ) { |
582 | if ( incOld->type() == "Todo" ) | 583 | if ( incOld->type() == "Todo" ) |
583 | emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); | 584 | emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); |
584 | else | 585 | else |
585 | emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); | 586 | emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); |
586 | } | 587 | } |
587 | 588 | ||
588 | } | 589 | } |
589 | 590 | ||
590 | KOAgendaView::~KOAgendaView() | 591 | KOAgendaView::~KOAgendaView() |
591 | { | 592 | { |
592 | delete mAllAgendaPopup; | 593 | delete mAllAgendaPopup; |
593 | //delete mAllDayAgendaPopup; | 594 | //delete mAllDayAgendaPopup; |
594 | delete KOAgendaItem::paintPix(); | 595 | delete KOAgendaItem::paintPix(); |
595 | delete KOAgendaItem::paintPixSel(); | 596 | delete KOAgendaItem::paintPixSel(); |
596 | } | 597 | } |
597 | void KOAgendaView::resizeEvent( QResizeEvent* e ) | 598 | void KOAgendaView::resizeEvent( QResizeEvent* e ) |
598 | { | 599 | { |
599 | //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); | 600 | //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); |
600 | bool uc = false; | 601 | bool uc = false; |
601 | int ow = e->oldSize().width(); | 602 | int ow = e->oldSize().width(); |
602 | int oh = e->oldSize().height(); | 603 | int oh = e->oldSize().height(); |
603 | int w = e->size().width(); | 604 | int w = e->size().width(); |
604 | int h = e->size().height(); | 605 | int h = e->size().height(); |
605 | if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { | 606 | if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { |
606 | if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) | 607 | if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) |
607 | uc = true; | 608 | uc = true; |
608 | //qDebug("view changed %d %d %d %d ", ow, oh , w , h); | 609 | //qDebug("view changed %d %d %d %d ", ow, oh , w , h); |
609 | } | 610 | } |
610 | mUpcomingWidth = e->size().width() ; | 611 | mUpcomingWidth = e->size().width() ; |
611 | if ( mBlockUpdating || uc ) { | 612 | if ( mBlockUpdating || uc ) { |
612 | mBlockUpdating = false; | 613 | mBlockUpdating = false; |
613 | //mAgenda->setMinimumSize(800 , 600 ); | 614 | //mAgenda->setMinimumSize(800 , 600 ); |
614 | //qDebug("mAgenda->resize+++++++++++++++ "); | 615 | //qDebug("mAgenda->resize+++++++++++++++ "); |
615 | updateConfig(); | 616 | updateConfig(); |
616 | //qDebug("KOAgendaView::Updating now possible "); | 617 | //qDebug("KOAgendaView::Updating now possible "); |
617 | } else | 618 | } else |
618 | createDayLabels(); | 619 | createDayLabels(); |
619 | //qDebug("resizeEvent end "); | 620 | //qDebug("resizeEvent end "); |
620 | 621 | ||
621 | } | 622 | } |
622 | void KOAgendaView::slotDaylabelClicked( int num ) | 623 | void KOAgendaView::slotDaylabelClicked( int num ) |
623 | { | 624 | { |
624 | 625 | ||
625 | QDate firstDate = mSelectedDates.first(); | 626 | QDate firstDate = mSelectedDates.first(); |
626 | if ( num == -1 ) | 627 | if ( num == -1 ) |
627 | emit showDateView( 6, firstDate ); | 628 | emit showDateView( 6, firstDate ); |
628 | else if (num >= 0 ) { | 629 | else if (num >= 0 ) { |
629 | if ( mSelectedDates.count() == 1) | 630 | if ( mSelectedDates.count() == 1) |
630 | emit showDateView( 9, firstDate.addDays( num ) ); | 631 | emit showDateView( 9, firstDate.addDays( num ) ); |
631 | else | 632 | else |
632 | emit showDateView( 3, firstDate.addDays( num ) ); | 633 | emit showDateView( 3, firstDate.addDays( num ) ); |
633 | } | 634 | } |
634 | else | 635 | else |
635 | showDateView( 10, firstDate.addDays(1) ); | 636 | showDateView( 10, firstDate.addDays(1) ); |
636 | } | 637 | } |
637 | 638 | ||
638 | KOAgendaButton* KOAgendaView::getNewDaylabel() | 639 | KOAgendaButton* KOAgendaView::getNewDaylabel() |
639 | { | 640 | { |
640 | 641 | ||
641 | KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); | 642 | KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); |
642 | connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); | 643 | connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); |
643 | mDayLabelsList.append( dayLabel ); | 644 | mDayLabelsList.append( dayLabel ); |
644 | mLayoutDayLabels->addWidget(dayLabel); | 645 | mLayoutDayLabels->addWidget(dayLabel); |
645 | return dayLabel ; | 646 | return dayLabel ; |
646 | } | 647 | } |
647 | 648 | ||
648 | void KOAgendaView::createDayLabels() | 649 | void KOAgendaView::createDayLabels() |
649 | { | 650 | { |
650 | 651 | ||
651 | if ( mBlockUpdating || globalFlagBlockLabel == 1) { | 652 | if ( mBlockUpdating || globalFlagBlockLabel == 1) { |
652 | // qDebug(" KOAgendaView::createDayLabels() blocked "); | 653 | // qDebug(" KOAgendaView::createDayLabels() blocked "); |
653 | return; | 654 | return; |
654 | 655 | ||
655 | } | 656 | } |
656 | int newHight; | 657 | int newHight; |
657 | if ( !mSelectedDates.count()) | 658 | if ( !mSelectedDates.count()) |
658 | return; | 659 | return; |
659 | 660 | ||
660 | // ### Before deleting and recreating we could check if mSelectedDates changed... | 661 | // ### Before deleting and recreating we could check if mSelectedDates changed... |
661 | // It would remove some flickering and gain speed (since this is called by | 662 | // It would remove some flickering and gain speed (since this is called by |
662 | // each updateView() call) | 663 | // each updateView() call) |
663 | 664 | ||
664 | int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; | 665 | int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; |
665 | mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); | 666 | mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); |
666 | if ( maxWid < 20 ) | 667 | if ( maxWid < 20 ) |
667 | maxWid = 20; | 668 | maxWid = 20; |
668 | 669 | ||
669 | QFont dlf = KOPrefs::instance()->mTimeLabelsFont; | 670 | QFont dlf = KOPrefs::instance()->mTimeLabelsFont; |
670 | QFontMetrics fm ( dlf ); | 671 | QFontMetrics fm ( dlf ); |
671 | int selCount = mSelectedDates.count(); | 672 | int selCount = mSelectedDates.count(); |
672 | int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1; | 673 | int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1; |
673 | QString dayTest = "Mon 20"; | 674 | QString dayTest = "Mon 20"; |
674 | //QString dayTest = "Mon 20"; | 675 | //QString dayTest = "Mon 20"; |
675 | int wid = fm.width( dayTest ); | 676 | int wid = fm.width( dayTest ); |
676 | //maxWid -= ( selCount * 3 ); //working for QLabels | 677 | //maxWid -= ( selCount * 3 ); //working for QLabels |
677 | if ( QApplication::desktop()->width() <= 320 ) | 678 | if ( QApplication::desktop()->width() <= 320 ) |
678 | maxWid -= ( selCount * 3 ); //working for QPushButton | 679 | maxWid -= ( selCount * 3 ); //working for QPushButton |
679 | else | 680 | else |
680 | maxWid -= ( selCount * 3 ); //working for QPushButton | 681 | maxWid -= ( selCount * 3 ); //working for QPushButton |
681 | if ( maxWid < 0 ) | 682 | if ( maxWid < 0 ) |
682 | maxWid = 20; | 683 | maxWid = 20; |
683 | int needWid = wid * selCount; | 684 | int needWid = wid * selCount; |
684 | //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); | 685 | //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); |
685 | //if ( needWid > maxWid ) | 686 | //if ( needWid > maxWid ) |
686 | // qDebug("DAYLABELS TOOOOOOO BIG "); | 687 | // qDebug("DAYLABELS TOOOOOOO BIG "); |
687 | while ( needWid > maxWid ) { | 688 | while ( needWid > maxWid ) { |
688 | dayTest = dayTest.left( dayTest.length() - 1 ); | 689 | dayTest = dayTest.left( dayTest.length() - 1 ); |
689 | wid = fm.width( dayTest ); | 690 | wid = fm.width( dayTest ); |
690 | needWid = wid * selCount; | 691 | needWid = wid * selCount; |
691 | } | 692 | } |
692 | int maxLen = dayTest.length(); | 693 | int maxLen = dayTest.length(); |
693 | int fontPoint = dlf.pointSize(); | 694 | int fontPoint = dlf.pointSize(); |
694 | if ( maxLen < 2 ) { | 695 | if ( maxLen < 2 ) { |
695 | int fontPoint = dlf.pointSize(); | 696 | int fontPoint = dlf.pointSize(); |
696 | while ( fontPoint > 4 ) { | 697 | while ( fontPoint > 4 ) { |
697 | --fontPoint; | 698 | --fontPoint; |
698 | dlf.setPointSize( fontPoint ); | 699 | dlf.setPointSize( fontPoint ); |
699 | QFontMetrics f( dlf ); | 700 | QFontMetrics f( dlf ); |
700 | wid = f.width( "30" ); | 701 | wid = f.width( "30" ); |
701 | needWid = wid * selCount; | 702 | needWid = wid * selCount; |
702 | if ( needWid < maxWid ) | 703 | if ( needWid < maxWid ) |
703 | break; | 704 | break; |
704 | } | 705 | } |
705 | maxLen = 2; | 706 | maxLen = 2; |
706 | } | 707 | } |
707 | //qDebug("Max len %d ", dayTest.length() ); | 708 | //qDebug("Max len %d ", dayTest.length() ); |
708 | 709 | ||
709 | QFontMetrics tempF( dlf ); | 710 | QFontMetrics tempF( dlf ); |
710 | newHight = tempF.height(); | 711 | newHight = tempF.height(); |
711 | mDayLabels->setFont( dlf ); | 712 | mDayLabels->setFont( dlf ); |
712 | // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; | 713 | // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; |
713 | // mLayoutDayLabels->addSpacing(mTimeLabels->width()); | 714 | // mLayoutDayLabels->addSpacing(mTimeLabels->width()); |
714 | //mLayoutDayLabels->addSpacing( 2 ); | 715 | //mLayoutDayLabels->addSpacing( 2 ); |
715 | // QFont lFont = dlf; | 716 | // QFont lFont = dlf; |
716 | bool appendLabels = false; | 717 | bool appendLabels = false; |
717 | KOAgendaButton *dayLabel; | 718 | KOAgendaButton *dayLabel; |
718 | dayLabel = mDayLabelsList.first(); | 719 | dayLabel = mDayLabelsList.first(); |
719 | if ( !dayLabel ) { | 720 | if ( !dayLabel ) { |
720 | appendLabels = true; | 721 | appendLabels = true; |
721 | dayLabel = getNewDaylabel(); | 722 | dayLabel = getNewDaylabel(); |
722 | } | 723 | } |
723 | dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); | 724 | dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); |
724 | dayLabel->setFont( dlf ); | 725 | dayLabel->setFont( dlf ); |
725 | dayLabel->setNum( -1 ); | 726 | dayLabel->setNum( -1 ); |
726 | //dayLabel->setAlignment(QLabel::AlignHCenter); | 727 | //dayLabel->setAlignment(QLabel::AlignHCenter); |
727 | #if 0 | 728 | #if 0 |
728 | if ( QApplication::desktop()->width() <= 320 ) | 729 | if ( QApplication::desktop()->width() <= 320 ) |
729 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ).left(2) ); | 730 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ).left(2) ); |
730 | else | 731 | else |
731 | #endif | 732 | #endif |
732 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); | 733 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); |
733 | dayLabel->show(); | 734 | dayLabel->show(); |
734 | DateList::ConstIterator dit; | 735 | DateList::ConstIterator dit; |
735 | bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); | 736 | bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); |
736 | int counter = -1; | 737 | int counter = -1; |
737 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { | 738 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { |
738 | ++counter; | 739 | ++counter; |
739 | QDate date = *dit; | 740 | QDate date = *dit; |
740 | // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); | 741 | // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); |
741 | if ( ! appendLabels ) { | 742 | if ( ! appendLabels ) { |
742 | dayLabel = mDayLabelsList.next(); | 743 | dayLabel = mDayLabelsList.next(); |
743 | if ( !dayLabel ) | 744 | if ( !dayLabel ) |
744 | appendLabels = true; | 745 | appendLabels = true; |
745 | } | 746 | } |
746 | if ( appendLabels ) { | 747 | if ( appendLabels ) { |
747 | dayLabel = getNewDaylabel(); | 748 | dayLabel = getNewDaylabel(); |
748 | } | 749 | } |
749 | dayLabel->setMinimumWidth( 1 ); | 750 | dayLabel->setMinimumWidth( 1 ); |
750 | dayLabel->setMaximumWidth( 10240 ); | 751 | dayLabel->setMaximumWidth( 10240 ); |
751 | dayLabel->setFont( dlf ); | 752 | dayLabel->setFont( dlf ); |
752 | dayLabel->show(); | 753 | dayLabel->show(); |
753 | dayLabel->setAutoRepeat( false ); | 754 | dayLabel->setAutoRepeat( false ); |
754 | dayLabel->setNum( counter ); | 755 | dayLabel->setNum( counter ); |
755 | QString str; | 756 | QString str; |
756 | int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); | 757 | int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); |
757 | QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); | 758 | QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); |
758 | switch ( maxLen ) { | 759 | switch ( maxLen ) { |
759 | case 2: | 760 | case 2: |
760 | str = QString::number( date.day() ); | 761 | str = QString::number( date.day() ); |
761 | break; | 762 | break; |
762 | 763 | ||
763 | case 3: | 764 | case 3: |
764 | str = dayName.left( 1 ) +QString::number( date.day()); | 765 | str = dayName.left( 1 ) +QString::number( date.day()); |
765 | 766 | ||
766 | break; | 767 | break; |
767 | case 4: | 768 | case 4: |
768 | str = dayName.left( 1 ) + " " +QString::number( date.day()); | 769 | str = dayName.left( 1 ) + " " +QString::number( date.day()); |
769 | 770 | ||
770 | break; | 771 | break; |
771 | case 5: | 772 | case 5: |
772 | str = dayName.left( 2 ) + " " +QString::number( date.day()); | 773 | str = dayName.left( 2 ) + " " +QString::number( date.day()); |
773 | 774 | ||
774 | break; | 775 | break; |
775 | case 6: | 776 | case 6: |
776 | str = dayName.left( 3 ) + " " +QString::number( date.day()); | 777 | str = dayName.left( 3 ) + " " +QString::number( date.day()); |
777 | break; | 778 | break; |
778 | 779 | ||
779 | default: | 780 | default: |
780 | break; | 781 | break; |
781 | } | 782 | } |
782 | if ( oneday ) { | 783 | if ( oneday ) { |
783 | QString addString; | 784 | QString addString; |
784 | if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) | 785 | if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) |
785 | addString = i18n("Today"); | 786 | addString = i18n("Today"); |
786 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) | 787 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) |
787 | addString = i18n("Tomorrow"); | 788 | addString = i18n("Tomorrow"); |
788 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) | 789 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) |
789 | addString = i18n("Yesterday"); | 790 | addString = i18n("Yesterday"); |
790 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) | 791 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) |
791 | addString = i18n("Day before yesterday"); | 792 | addString = i18n("Day before yesterday"); |
792 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) | 793 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) |
793 | addString = i18n("Day after tomorrow"); | 794 | addString = i18n("Day after tomorrow"); |
794 | if ( !addString.isEmpty() ) { | 795 | if ( !addString.isEmpty() ) { |
795 | str = addString+", " + str; | 796 | str = addString+", " + str; |
796 | } else { | 797 | } else { |
797 | str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); | 798 | str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); |
798 | } | 799 | } |
799 | } | 800 | } |
800 | dayLabel->setText(str); | 801 | dayLabel->setText(str); |
801 | //dayLabel->setAlignment(QLabel::AlignHCenter); | 802 | //dayLabel->setAlignment(QLabel::AlignHCenter); |
802 | if (date == QDate::currentDate()) { | 803 | if (date == QDate::currentDate()) { |
803 | QFont bFont = dlf; | 804 | QFont bFont = dlf; |
804 | bFont.setBold( true ); | 805 | bFont.setBold( true ); |
805 | dayLabel->setFont(bFont); | 806 | dayLabel->setFont(bFont); |
806 | } | 807 | } |
807 | //dayLayout->addWidget(dayLabel); | 808 | //dayLayout->addWidget(dayLabel); |
808 | 809 | ||
809 | #ifndef KORG_NOPLUGINS | 810 | #ifndef KORG_NOPLUGINS |
810 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); | 811 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); |
811 | CalendarDecoration *it; | 812 | CalendarDecoration *it; |
812 | for(it = cds.first(); it; it = cds.next()) { | 813 | for(it = cds.first(); it; it = cds.next()) { |
813 | QString text = it->shortText( date ); | 814 | QString text = it->shortText( date ); |
814 | if ( !text.isEmpty() ) { | 815 | if ( !text.isEmpty() ) { |
815 | QLabel *label = new QLabel(text,mDayLabels); | 816 | QLabel *label = new QLabel(text,mDayLabels); |
816 | label->setAlignment(AlignCenter); | 817 | label->setAlignment(AlignCenter); |
817 | dayLayout->addWidget(label); | 818 | dayLayout->addWidget(label); |
818 | } | 819 | } |
819 | } | 820 | } |
820 | 821 | ||
821 | for(it = cds.first(); it; it = cds.next()) { | 822 | for(it = cds.first(); it; it = cds.next()) { |
822 | QWidget *wid = it->smallWidget(mDayLabels,date); | 823 | QWidget *wid = it->smallWidget(mDayLabels,date); |
823 | if ( wid ) { | 824 | if ( wid ) { |
824 | // wid->setHeight(20); | 825 | // wid->setHeight(20); |
825 | dayLayout->addWidget(wid); | 826 | dayLayout->addWidget(wid); |
826 | } | 827 | } |
827 | } | 828 | } |
828 | #endif | 829 | #endif |
829 | } | 830 | } |
830 | if ( ! appendLabels ) { | 831 | if ( ! appendLabels ) { |
831 | dayLabel = mDayLabelsList.next(); | 832 | dayLabel = mDayLabelsList.next(); |
832 | if ( !dayLabel ) | 833 | if ( !dayLabel ) |
833 | appendLabels = true; | 834 | appendLabels = true; |
834 | } | 835 | } |
835 | if ( appendLabels ) { | 836 | if ( appendLabels ) { |
836 | dayLabel = getNewDaylabel(); | 837 | dayLabel = getNewDaylabel(); |
837 | } | 838 | } |
838 | //dayLabel->hide();//test only | 839 | //dayLabel->hide();//test only |
839 | 840 | ||
840 | dayLabel->setText(">"); | 841 | dayLabel->setText(">"); |
841 | dayLabel->setFont( dlf ); | 842 | dayLabel->setFont( dlf ); |
842 | dayLabel->setAutoRepeat( true ); | 843 | dayLabel->setAutoRepeat( true ); |
843 | dayLabel->show(); | 844 | dayLabel->show(); |
844 | dayLabel->setNum( -2 ); | 845 | dayLabel->setNum( -2 ); |
845 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo ); | 846 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo ); |
846 | 847 | ||
847 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); | 848 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); |
848 | if ( !appendLabels ) { | 849 | if ( !appendLabels ) { |
849 | dayLabel = mDayLabelsList.next(); | 850 | dayLabel = mDayLabelsList.next(); |
850 | while ( dayLabel ) { | 851 | while ( dayLabel ) { |
851 | //qDebug("!dayLabel %d",dayLabel ); | 852 | //qDebug("!dayLabel %d",dayLabel ); |
852 | dayLabel->hide(); | 853 | dayLabel->hide(); |
853 | dayLabel = mDayLabelsList.next(); | 854 | dayLabel = mDayLabelsList.next(); |
854 | } | 855 | } |
855 | } | 856 | } |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 5c889c3..00a43e5 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,726 +1,726 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 101 | { |
102 | QString cat; | 102 | QString cat; |
103 | bool isBirthday = true; | 103 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 105 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 106 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 108 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | if ( mUndoIncidence ) delete mUndoIncidence; | 155 | if ( mUndoIncidence ) delete mUndoIncidence; |
156 | mUndoIncidence = event->clone(); | 156 | mUndoIncidence = event->clone(); |
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | if ( mUndoIncidence ) delete mUndoIncidence; | 204 | if ( mUndoIncidence ) delete mUndoIncidence; |
205 | removeRelations( todo ); | 205 | removeRelations( todo ); |
206 | mUndoIncidence = todo->clone(); | 206 | mUndoIncidence = todo->clone(); |
207 | 207 | ||
208 | if ( mTodoList.removeRef( todo ) ) { | 208 | if ( mTodoList.removeRef( todo ) ) { |
209 | setModified( true ); | 209 | setModified( true ); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | QPtrList<Todo> CalendarLocal::rawTodos() | 213 | QPtrList<Todo> CalendarLocal::rawTodos() |
214 | { | 214 | { |
215 | return mTodoList; | 215 | return mTodoList; |
216 | } | 216 | } |
217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
218 | { | 218 | { |
219 | Todo *todo; | 219 | Todo *todo; |
220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
221 | if ( todo->getID( syncProf ) == id ) return todo; | 221 | if ( todo->getID( syncProf ) == id ) return todo; |
222 | } | 222 | } |
223 | 223 | ||
224 | return 0; | 224 | return 0; |
225 | } | 225 | } |
226 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 226 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
227 | { | 227 | { |
228 | QPtrList<Incidence> all = rawIncidences() ; | 228 | QPtrList<Incidence> all = rawIncidences() ; |
229 | Incidence *inc; | 229 | Incidence *inc; |
230 | for ( inc = all.first(); inc; inc = all.next() ) { | 230 | for ( inc = all.first(); inc; inc = all.next() ) { |
231 | inc->removeID( syncProfile ); | 231 | inc->removeID( syncProfile ); |
232 | } | 232 | } |
233 | if ( syncProfile.isEmpty() ) { | 233 | if ( syncProfile.isEmpty() ) { |
234 | QPtrList<Event> el; | 234 | QPtrList<Event> el; |
235 | Event *todo; | 235 | Event *todo; |
236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
238 | el.append( todo ); | 238 | el.append( todo ); |
239 | } | 239 | } |
240 | for ( todo = el.first(); todo; todo = el.next() ) { | 240 | for ( todo = el.first(); todo; todo = el.next() ) { |
241 | deleteIncidence ( todo ); | 241 | deleteIncidence ( todo ); |
242 | } | 242 | } |
243 | } else { | 243 | } else { |
244 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 244 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
245 | if ( lse ) | 245 | if ( lse ) |
246 | deleteIncidence ( lse ); | 246 | deleteIncidence ( lse ); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 249 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
250 | { | 250 | { |
251 | QPtrList<Event> el; | 251 | QPtrList<Event> el; |
252 | Event *todo; | 252 | Event *todo; |
253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 253 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 254 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
255 | if ( todo->summary().left(3) == "E: " ) | 255 | if ( todo->summary().left(3) == "E: " ) |
256 | el.append( todo ); | 256 | el.append( todo ); |
257 | } | 257 | } |
258 | 258 | ||
259 | return el; | 259 | return el; |
260 | 260 | ||
261 | } | 261 | } |
262 | Event *CalendarLocal::event( QString syncProf, QString id ) | 262 | Event *CalendarLocal::event( QString syncProf, QString id ) |
263 | { | 263 | { |
264 | Event *todo; | 264 | Event *todo; |
265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 265 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
266 | if ( todo->getID( syncProf ) == id ) return todo; | 266 | if ( todo->getID( syncProf ) == id ) return todo; |
267 | } | 267 | } |
268 | 268 | ||
269 | return 0; | 269 | return 0; |
270 | } | 270 | } |
271 | Todo *CalendarLocal::todo( const QString &uid ) | 271 | Todo *CalendarLocal::todo( const QString &uid ) |
272 | { | 272 | { |
273 | Todo *todo; | 273 | Todo *todo; |
274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 274 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
275 | if ( todo->uid() == uid ) return todo; | 275 | if ( todo->uid() == uid ) return todo; |
276 | } | 276 | } |
277 | 277 | ||
278 | return 0; | 278 | return 0; |
279 | } | 279 | } |
280 | QString CalendarLocal::nextSummary() const | 280 | QString CalendarLocal::nextSummary() const |
281 | { | 281 | { |
282 | return mNextSummary; | 282 | return mNextSummary; |
283 | } | 283 | } |
284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 284 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
285 | { | 285 | { |
286 | return mNextAlarmEventDateTime; | 286 | return mNextAlarmEventDateTime; |
287 | } | 287 | } |
288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 288 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
289 | { | 289 | { |
290 | //mNextAlarmIncidence | 290 | //mNextAlarmIncidence |
291 | //mNextAlarmDateTime | 291 | //mNextAlarmDateTime |
292 | //return mNextSummary; | 292 | //return mNextSummary; |
293 | //return mNextAlarmEventDateTime; | 293 | //return mNextAlarmEventDateTime; |
294 | bool newNextAlarm = false; | 294 | bool newNextAlarm = false; |
295 | bool computeNextAlarm = false; | 295 | bool computeNextAlarm = false; |
296 | bool ok; | 296 | bool ok; |
297 | int offset; | 297 | int offset; |
298 | QDateTime nextA; | 298 | QDateTime nextA; |
299 | // QString nextSum; | 299 | // QString nextSum; |
300 | //QDateTime nextEvent; | 300 | //QDateTime nextEvent; |
301 | mNextAlarmEventDateTime = QDateTime(); | ||
302 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 301 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
303 | computeNextAlarm = true; | 302 | computeNextAlarm = true; |
304 | } else { | 303 | } else { |
305 | if ( ! deleted ) { | 304 | if ( ! deleted ) { |
306 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 305 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
307 | if ( ok ) { | 306 | if ( ok ) { |
308 | if ( nextA < mNextAlarmDateTime ) { | 307 | if ( nextA < mNextAlarmDateTime ) { |
309 | deRegisterAlarm(); | 308 | deRegisterAlarm(); |
310 | mNextAlarmDateTime = nextA; | 309 | mNextAlarmDateTime = nextA; |
311 | mNextSummary = incidence->summary(); | 310 | mNextSummary = incidence->summary(); |
312 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 311 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
313 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 312 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
314 | newNextAlarm = true; | 313 | newNextAlarm = true; |
315 | mNextAlarmIncidence = incidence; | 314 | mNextAlarmIncidence = incidence; |
316 | } else { | 315 | } else { |
317 | if ( incidence == mNextAlarmIncidence ) { | 316 | if ( incidence == mNextAlarmIncidence ) { |
318 | computeNextAlarm = true; | 317 | computeNextAlarm = true; |
319 | } | 318 | } |
320 | } | 319 | } |
321 | } else { | 320 | } else { |
322 | if ( mNextAlarmIncidence == incidence ) { | 321 | if ( mNextAlarmIncidence == incidence ) { |
323 | computeNextAlarm = true; | 322 | computeNextAlarm = true; |
324 | } | 323 | } |
325 | } | 324 | } |
326 | } else { // deleted | 325 | } else { // deleted |
327 | if ( incidence == mNextAlarmIncidence ) { | 326 | if ( incidence == mNextAlarmIncidence ) { |
328 | computeNextAlarm = true; | 327 | computeNextAlarm = true; |
329 | } | 328 | } |
330 | } | 329 | } |
331 | } | 330 | } |
332 | if ( computeNextAlarm ) { | 331 | if ( computeNextAlarm ) { |
333 | deRegisterAlarm(); | 332 | deRegisterAlarm(); |
334 | nextA = nextAlarm( 1000 ); | 333 | nextA = nextAlarm( 1000 ); |
335 | if (! mNextAlarmIncidence ) { | 334 | if (! mNextAlarmIncidence ) { |
336 | return; | 335 | return; |
337 | } | 336 | } |
338 | newNextAlarm = true; | 337 | newNextAlarm = true; |
339 | } | 338 | } |
340 | if ( newNextAlarm ) | 339 | if ( newNextAlarm ) |
341 | registerAlarm(); | 340 | registerAlarm(); |
342 | } | 341 | } |
343 | QString CalendarLocal:: getAlarmNotification() | 342 | QString CalendarLocal:: getAlarmNotification() |
344 | { | 343 | { |
345 | QString ret; | 344 | QString ret; |
346 | // this should not happen | 345 | // this should not happen |
347 | if (! mNextAlarmIncidence ) | 346 | if (! mNextAlarmIncidence ) |
348 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 347 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
349 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 348 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
350 | if ( alarm->type() == Alarm::Procedure ) { | 349 | if ( alarm->type() == Alarm::Procedure ) { |
351 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 350 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
352 | } else { | 351 | } else { |
353 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 352 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
354 | } | 353 | } |
355 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 354 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
356 | if ( mNextSummary.length() > 25 ) | 355 | if ( mNextSummary.length() > 25 ) |
357 | ret += "\n" + mNextSummary.mid(25, 25 ); | 356 | ret += "\n" + mNextSummary.mid(25, 25 ); |
358 | ret+= "\n"+mNextAlarmEventDateTimeString; | 357 | ret+= "\n"+mNextAlarmEventDateTimeString; |
359 | return ret; | 358 | return ret; |
360 | } | 359 | } |
361 | void CalendarLocal::registerAlarm() | 360 | void CalendarLocal::registerAlarm() |
362 | { | 361 | { |
363 | mLastAlarmNotificationString = getAlarmNotification(); | 362 | mLastAlarmNotificationString = getAlarmNotification(); |
364 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 363 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
365 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 364 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
366 | // #ifndef DESKTOP_VERSION | 365 | // #ifndef DESKTOP_VERSION |
367 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 366 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
368 | // #endif | 367 | // #endif |
369 | } | 368 | } |
370 | void CalendarLocal::deRegisterAlarm() | 369 | void CalendarLocal::deRegisterAlarm() |
371 | { | 370 | { |
372 | if ( mLastAlarmNotificationString.isNull() ) | 371 | if ( mLastAlarmNotificationString.isNull() ) |
373 | return; | 372 | return; |
374 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 373 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
375 | 374 | ||
376 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 375 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
376 | mNextAlarmEventDateTime = QDateTime(); | ||
377 | // #ifndef DESKTOP_VERSION | 377 | // #ifndef DESKTOP_VERSION |
378 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 378 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
379 | // #endif | 379 | // #endif |
380 | } | 380 | } |
381 | 381 | ||
382 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 382 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
383 | { | 383 | { |
384 | QPtrList<Todo> todos; | 384 | QPtrList<Todo> todos; |
385 | 385 | ||
386 | Todo *todo; | 386 | Todo *todo; |
387 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 387 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
388 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 388 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
389 | todos.append( todo ); | 389 | todos.append( todo ); |
390 | } | 390 | } |
391 | } | 391 | } |
392 | 392 | ||
393 | filter()->apply( &todos ); | 393 | filter()->apply( &todos ); |
394 | return todos; | 394 | return todos; |
395 | } | 395 | } |
396 | void CalendarLocal::reInitAlarmSettings() | 396 | void CalendarLocal::reInitAlarmSettings() |
397 | { | 397 | { |
398 | if ( !mNextAlarmIncidence ) { | 398 | if ( !mNextAlarmIncidence ) { |
399 | nextAlarm( 1000 ); | 399 | nextAlarm( 1000 ); |
400 | } | 400 | } |
401 | deRegisterAlarm(); | 401 | deRegisterAlarm(); |
402 | mNextAlarmIncidence = 0; | 402 | mNextAlarmIncidence = 0; |
403 | checkAlarmForIncidence( 0, false ); | 403 | checkAlarmForIncidence( 0, false ); |
404 | 404 | ||
405 | } | 405 | } |
406 | 406 | ||
407 | 407 | ||
408 | 408 | ||
409 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 409 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
410 | { | 410 | { |
411 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 411 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
412 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 412 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
413 | QDateTime next; | 413 | QDateTime next; |
414 | Event *e; | 414 | Event *e; |
415 | bool ok; | 415 | bool ok; |
416 | bool found = false; | 416 | bool found = false; |
417 | int offset; | 417 | int offset; |
418 | mNextAlarmIncidence = 0; | 418 | mNextAlarmIncidence = 0; |
419 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 419 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
420 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 420 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
421 | if ( ok ) { | 421 | if ( ok ) { |
422 | if ( next < nextA ) { | 422 | if ( next < nextA ) { |
423 | nextA = next; | 423 | nextA = next; |
424 | found = true; | 424 | found = true; |
425 | mNextSummary = e->summary(); | 425 | mNextSummary = e->summary(); |
426 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 426 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
427 | mNextAlarmIncidence = (Incidence *) e; | 427 | mNextAlarmIncidence = (Incidence *) e; |
428 | } | 428 | } |
429 | } | 429 | } |
430 | } | 430 | } |
431 | Todo *t; | 431 | Todo *t; |
432 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 432 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
433 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 433 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
434 | if ( ok ) { | 434 | if ( ok ) { |
435 | if ( next < nextA ) { | 435 | if ( next < nextA ) { |
436 | nextA = next; | 436 | nextA = next; |
437 | found = true; | 437 | found = true; |
438 | mNextSummary = t->summary(); | 438 | mNextSummary = t->summary(); |
439 | mNextAlarmEventDateTime = next.addSecs(offset ); | 439 | mNextAlarmEventDateTime = next.addSecs(offset ); |
440 | mNextAlarmIncidence = (Incidence *) t; | 440 | mNextAlarmIncidence = (Incidence *) t; |
441 | } | 441 | } |
442 | } | 442 | } |
443 | } | 443 | } |
444 | if ( mNextAlarmIncidence ) { | 444 | if ( mNextAlarmIncidence ) { |
445 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 445 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
446 | mNextAlarmDateTime = nextA; | 446 | mNextAlarmDateTime = nextA; |
447 | } | 447 | } |
448 | return nextA; | 448 | return nextA; |
449 | } | 449 | } |
450 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 450 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
451 | { | 451 | { |
452 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 452 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
453 | } | 453 | } |
454 | 454 | ||
455 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 455 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
456 | { | 456 | { |
457 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 457 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
458 | << to.toString() << ")\n"; | 458 | << to.toString() << ")\n"; |
459 | 459 | ||
460 | Alarm::List alarms; | 460 | Alarm::List alarms; |
461 | 461 | ||
462 | Event *e; | 462 | Event *e; |
463 | 463 | ||
464 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 464 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
465 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 465 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
466 | else appendAlarms( alarms, e, from, to ); | 466 | else appendAlarms( alarms, e, from, to ); |
467 | } | 467 | } |
468 | 468 | ||
469 | Todo *t; | 469 | Todo *t; |
470 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 470 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
471 | appendAlarms( alarms, t, from, to ); | 471 | appendAlarms( alarms, t, from, to ); |
472 | } | 472 | } |
473 | 473 | ||
474 | return alarms; | 474 | return alarms; |
475 | } | 475 | } |
476 | 476 | ||
477 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 477 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
478 | const QDateTime &from, const QDateTime &to ) | 478 | const QDateTime &from, const QDateTime &to ) |
479 | { | 479 | { |
480 | QPtrList<Alarm> alarmList = incidence->alarms(); | 480 | QPtrList<Alarm> alarmList = incidence->alarms(); |
481 | Alarm *alarm; | 481 | Alarm *alarm; |
482 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 482 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
483 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 483 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
484 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 484 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
485 | if ( alarm->enabled() ) { | 485 | if ( alarm->enabled() ) { |
486 | if ( alarm->time() >= from && alarm->time() <= to ) { | 486 | if ( alarm->time() >= from && alarm->time() <= to ) { |
487 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 487 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
488 | << "': " << alarm->time().toString() << endl; | 488 | << "': " << alarm->time().toString() << endl; |
489 | alarms.append( alarm ); | 489 | alarms.append( alarm ); |
490 | } | 490 | } |
491 | } | 491 | } |
492 | } | 492 | } |
493 | } | 493 | } |
494 | 494 | ||
495 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 495 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
496 | Incidence *incidence, | 496 | Incidence *incidence, |
497 | const QDateTime &from, | 497 | const QDateTime &from, |
498 | const QDateTime &to ) | 498 | const QDateTime &to ) |
499 | { | 499 | { |
500 | 500 | ||
501 | QPtrList<Alarm> alarmList = incidence->alarms(); | 501 | QPtrList<Alarm> alarmList = incidence->alarms(); |
502 | Alarm *alarm; | 502 | Alarm *alarm; |
503 | QDateTime qdt; | 503 | QDateTime qdt; |
504 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 504 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
505 | if (incidence->recursOn(from.date())) { | 505 | if (incidence->recursOn(from.date())) { |
506 | qdt.setTime(alarm->time().time()); | 506 | qdt.setTime(alarm->time().time()); |
507 | qdt.setDate(from.date()); | 507 | qdt.setDate(from.date()); |
508 | } | 508 | } |
509 | else qdt = alarm->time(); | 509 | else qdt = alarm->time(); |
510 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 510 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
511 | if ( alarm->enabled() ) { | 511 | if ( alarm->enabled() ) { |
512 | if ( qdt >= from && qdt <= to ) { | 512 | if ( qdt >= from && qdt <= to ) { |
513 | alarms.append( alarm ); | 513 | alarms.append( alarm ); |
514 | } | 514 | } |
515 | } | 515 | } |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | 519 | ||
520 | /****************************** PROTECTED METHODS ****************************/ | 520 | /****************************** PROTECTED METHODS ****************************/ |
521 | 521 | ||
522 | // after changes are made to an event, this should be called. | 522 | // after changes are made to an event, this should be called. |
523 | void CalendarLocal::update( IncidenceBase *incidence ) | 523 | void CalendarLocal::update( IncidenceBase *incidence ) |
524 | { | 524 | { |
525 | incidence->setSyncStatus( Event::SYNCMOD ); | 525 | incidence->setSyncStatus( Event::SYNCMOD ); |
526 | incidence->setLastModified( QDateTime::currentDateTime() ); | 526 | incidence->setLastModified( QDateTime::currentDateTime() ); |
527 | // we should probably update the revision number here, | 527 | // we should probably update the revision number here, |
528 | // or internally in the Event itself when certain things change. | 528 | // or internally in the Event itself when certain things change. |
529 | // need to verify with ical documentation. | 529 | // need to verify with ical documentation. |
530 | 530 | ||
531 | setModified( true ); | 531 | setModified( true ); |
532 | } | 532 | } |
533 | 533 | ||
534 | void CalendarLocal::insertEvent( Event *event ) | 534 | void CalendarLocal::insertEvent( Event *event ) |
535 | { | 535 | { |
536 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 536 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
537 | } | 537 | } |
538 | 538 | ||
539 | 539 | ||
540 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 540 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
541 | { | 541 | { |
542 | QPtrList<Event> eventList; | 542 | QPtrList<Event> eventList; |
543 | 543 | ||
544 | Event *event; | 544 | Event *event; |
545 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 545 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
546 | if ( event->doesRecur() ) { | 546 | if ( event->doesRecur() ) { |
547 | if ( event->isMultiDay() ) { | 547 | if ( event->isMultiDay() ) { |
548 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 548 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
549 | int i; | 549 | int i; |
550 | for ( i = 0; i <= extraDays; i++ ) { | 550 | for ( i = 0; i <= extraDays; i++ ) { |
551 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 551 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
552 | eventList.append( event ); | 552 | eventList.append( event ); |
553 | break; | 553 | break; |
554 | } | 554 | } |
555 | } | 555 | } |
556 | } else { | 556 | } else { |
557 | if ( event->recursOn( qd ) ) | 557 | if ( event->recursOn( qd ) ) |
558 | eventList.append( event ); | 558 | eventList.append( event ); |
559 | } | 559 | } |
560 | } else { | 560 | } else { |
561 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 561 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
562 | eventList.append( event ); | 562 | eventList.append( event ); |
563 | } | 563 | } |
564 | } | 564 | } |
565 | } | 565 | } |
566 | 566 | ||
567 | if ( !sorted ) { | 567 | if ( !sorted ) { |
568 | return eventList; | 568 | return eventList; |
569 | } | 569 | } |
570 | 570 | ||
571 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 571 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
572 | // now, we have to sort it based on dtStart.time() | 572 | // now, we have to sort it based on dtStart.time() |
573 | QPtrList<Event> eventListSorted; | 573 | QPtrList<Event> eventListSorted; |
574 | Event *sortEvent; | 574 | Event *sortEvent; |
575 | for ( event = eventList.first(); event; event = eventList.next() ) { | 575 | for ( event = eventList.first(); event; event = eventList.next() ) { |
576 | sortEvent = eventListSorted.first(); | 576 | sortEvent = eventListSorted.first(); |
577 | int i = 0; | 577 | int i = 0; |
578 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 578 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
579 | { | 579 | { |
580 | i++; | 580 | i++; |
581 | sortEvent = eventListSorted.next(); | 581 | sortEvent = eventListSorted.next(); |
582 | } | 582 | } |
583 | eventListSorted.insert( i, event ); | 583 | eventListSorted.insert( i, event ); |
584 | } | 584 | } |
585 | return eventListSorted; | 585 | return eventListSorted; |
586 | } | 586 | } |
587 | 587 | ||
588 | 588 | ||
589 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 589 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
590 | bool inclusive ) | 590 | bool inclusive ) |
591 | { | 591 | { |
592 | Event *event = 0; | 592 | Event *event = 0; |
593 | 593 | ||
594 | QPtrList<Event> eventList; | 594 | QPtrList<Event> eventList; |
595 | 595 | ||
596 | // Get non-recurring events | 596 | // Get non-recurring events |
597 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 597 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
598 | if ( event->doesRecur() ) { | 598 | if ( event->doesRecur() ) { |
599 | QDate rStart = event->dtStart().date(); | 599 | QDate rStart = event->dtStart().date(); |
600 | bool found = false; | 600 | bool found = false; |
601 | if ( inclusive ) { | 601 | if ( inclusive ) { |
602 | if ( rStart >= start && rStart <= end ) { | 602 | if ( rStart >= start && rStart <= end ) { |
603 | // Start date of event is in range. Now check for end date. | 603 | // Start date of event is in range. Now check for end date. |
604 | // if duration is negative, event recurs forever, so do not include it. | 604 | // if duration is negative, event recurs forever, so do not include it. |
605 | if ( event->recurrence()->duration() == 0 ) { // End date set | 605 | if ( event->recurrence()->duration() == 0 ) { // End date set |
606 | QDate rEnd = event->recurrence()->endDate(); | 606 | QDate rEnd = event->recurrence()->endDate(); |
607 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 607 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
608 | found = true; | 608 | found = true; |
609 | } | 609 | } |
610 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 610 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
611 | // TODO: Calculate end date from duration. Should be done in Event | 611 | // TODO: Calculate end date from duration. Should be done in Event |
612 | // For now exclude all events with a duration. | 612 | // For now exclude all events with a duration. |
613 | } | 613 | } |
614 | } | 614 | } |
615 | } else { | 615 | } else { |
616 | bool founOne; | 616 | bool founOne; |
617 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 617 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
618 | if ( founOne ) { | 618 | if ( founOne ) { |
619 | if ( next <= end ) { | 619 | if ( next <= end ) { |
620 | found = true; | 620 | found = true; |
621 | } | 621 | } |
622 | } | 622 | } |
623 | 623 | ||
624 | /* | 624 | /* |
625 | // crap !!! | 625 | // crap !!! |
626 | if ( rStart <= end ) { // Start date not after range | 626 | if ( rStart <= end ) { // Start date not after range |
627 | if ( rStart >= start ) { // Start date within range | 627 | if ( rStart >= start ) { // Start date within range |
628 | found = true; | 628 | found = true; |
629 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 629 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
630 | found = true; | 630 | found = true; |
631 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 631 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
632 | QDate rEnd = event->recurrence()->endDate(); | 632 | QDate rEnd = event->recurrence()->endDate(); |
633 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 633 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
634 | found = true; | 634 | found = true; |
635 | } | 635 | } |
636 | } else { // Duration set | 636 | } else { // Duration set |
637 | // TODO: Calculate end date from duration. Should be done in Event | 637 | // TODO: Calculate end date from duration. Should be done in Event |
638 | // For now include all events with a duration. | 638 | // For now include all events with a duration. |
639 | found = true; | 639 | found = true; |
640 | } | 640 | } |
641 | } | 641 | } |
642 | */ | 642 | */ |
643 | 643 | ||
644 | } | 644 | } |
645 | 645 | ||
646 | if ( found ) eventList.append( event ); | 646 | if ( found ) eventList.append( event ); |
647 | } else { | 647 | } else { |
648 | QDate s = event->dtStart().date(); | 648 | QDate s = event->dtStart().date(); |
649 | QDate e = event->dtEnd().date(); | 649 | QDate e = event->dtEnd().date(); |
650 | 650 | ||
651 | if ( inclusive ) { | 651 | if ( inclusive ) { |
652 | if ( s >= start && e <= end ) { | 652 | if ( s >= start && e <= end ) { |
653 | eventList.append( event ); | 653 | eventList.append( event ); |
654 | } | 654 | } |
655 | } else { | 655 | } else { |
656 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 656 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
657 | eventList.append( event ); | 657 | eventList.append( event ); |
658 | } | 658 | } |
659 | } | 659 | } |
660 | } | 660 | } |
661 | } | 661 | } |
662 | 662 | ||
663 | return eventList; | 663 | return eventList; |
664 | } | 664 | } |
665 | 665 | ||
666 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 666 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
667 | { | 667 | { |
668 | return rawEventsForDate( qdt.date() ); | 668 | return rawEventsForDate( qdt.date() ); |
669 | } | 669 | } |
670 | 670 | ||
671 | QPtrList<Event> CalendarLocal::rawEvents() | 671 | QPtrList<Event> CalendarLocal::rawEvents() |
672 | { | 672 | { |
673 | return mEventList; | 673 | return mEventList; |
674 | } | 674 | } |
675 | 675 | ||
676 | bool CalendarLocal::addJournal(Journal *journal) | 676 | bool CalendarLocal::addJournal(Journal *journal) |
677 | { | 677 | { |
678 | if ( journal->dtStart().isValid()) | 678 | if ( journal->dtStart().isValid()) |
679 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 679 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
680 | else | 680 | else |
681 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 681 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
682 | 682 | ||
683 | mJournalList.append(journal); | 683 | mJournalList.append(journal); |
684 | 684 | ||
685 | journal->registerObserver( this ); | 685 | journal->registerObserver( this ); |
686 | 686 | ||
687 | setModified( true ); | 687 | setModified( true ); |
688 | 688 | ||
689 | return true; | 689 | return true; |
690 | } | 690 | } |
691 | 691 | ||
692 | void CalendarLocal::deleteJournal( Journal *journal ) | 692 | void CalendarLocal::deleteJournal( Journal *journal ) |
693 | { | 693 | { |
694 | if ( mUndoIncidence ) delete mUndoIncidence; | 694 | if ( mUndoIncidence ) delete mUndoIncidence; |
695 | mUndoIncidence = journal->clone(); | 695 | mUndoIncidence = journal->clone(); |
696 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 696 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
697 | if ( mJournalList.removeRef(journal) ) { | 697 | if ( mJournalList.removeRef(journal) ) { |
698 | setModified( true ); | 698 | setModified( true ); |
699 | } | 699 | } |
700 | } | 700 | } |
701 | 701 | ||
702 | Journal *CalendarLocal::journal( const QDate &date ) | 702 | Journal *CalendarLocal::journal( const QDate &date ) |
703 | { | 703 | { |
704 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 704 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
705 | 705 | ||
706 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 706 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
707 | if ( it->dtStart().date() == date ) | 707 | if ( it->dtStart().date() == date ) |
708 | return it; | 708 | return it; |
709 | 709 | ||
710 | return 0; | 710 | return 0; |
711 | } | 711 | } |
712 | 712 | ||
713 | Journal *CalendarLocal::journal( const QString &uid ) | 713 | Journal *CalendarLocal::journal( const QString &uid ) |
714 | { | 714 | { |
715 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 715 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
716 | if ( it->uid() == uid ) | 716 | if ( it->uid() == uid ) |
717 | return it; | 717 | return it; |
718 | 718 | ||
719 | return 0; | 719 | return 0; |
720 | } | 720 | } |
721 | 721 | ||
722 | QPtrList<Journal> CalendarLocal::journals() | 722 | QPtrList<Journal> CalendarLocal::journals() |
723 | { | 723 | { |
724 | return mJournalList; | 724 | return mJournalList; |
725 | } | 725 | } |
726 | 726 | ||