-rw-r--r-- | korganizer/koagenda.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/korganizer/koagenda.cpp b/korganizer/koagenda.cpp index 99009a5..cdeeac5 100644 --- a/korganizer/koagenda.cpp +++ b/korganizer/koagenda.cpp | |||
@@ -1,1527 +1,1528 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | Marcus Bains line. | 5 | Marcus Bains line. |
6 | Copyright (c) 2001 Ali Rahimi | 6 | Copyright (c) 2001 Ali Rahimi |
7 | 7 | ||
8 | This program is free software; you can redistribute it and/or modify | 8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | 9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or | 10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. | 11 | (at your option) any later version. |
12 | 12 | ||
13 | This program is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. | 16 | GNU General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU General Public License | 18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software | 19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 | 21 | ||
22 | As a special exception, permission is given to link this program | 22 | As a special exception, permission is given to link this program |
23 | with any edition of Qt, and distribute the resulting executable, | 23 | with any edition of Qt, and distribute the resulting executable, |
24 | without including the source code for Qt in the source distribution. | 24 | without including the source code for Qt in the source distribution. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #define protected public | 28 | #define protected public |
29 | #include <qwidget.h> | 29 | #include <qwidget.h> |
30 | #undef protected | 30 | #undef protected |
31 | #endif | 31 | #endif |
32 | #include <qintdict.h> | 32 | #include <qintdict.h> |
33 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
34 | #include <qapplication.h> | 34 | #include <qapplication.h> |
35 | #include <qpopupmenu.h> | 35 | #include <qpopupmenu.h> |
36 | #include <qcursor.h> | 36 | #include <qcursor.h> |
37 | #include <qpainter.h> | 37 | #include <qpainter.h> |
38 | 38 | ||
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | #include <kiconloader.h> | 41 | #include <kiconloader.h> |
42 | #include <kglobal.h> | 42 | #include <kglobal.h> |
43 | 43 | ||
44 | #include "koagendaitem.h" | 44 | #include "koagendaitem.h" |
45 | #include "koprefs.h" | 45 | #include "koprefs.h" |
46 | #include "koglobals.h" | 46 | #include "koglobals.h" |
47 | 47 | ||
48 | #include "koagenda.h" | 48 | #include "koagenda.h" |
49 | 49 | ||
50 | #include <libkcal/event.h> | 50 | #include <libkcal/event.h> |
51 | #include <libkcal/todo.h> | 51 | #include <libkcal/todo.h> |
52 | 52 | ||
53 | #ifndef DESKTOP_VERSION | 53 | #ifndef DESKTOP_VERSION |
54 | #include <qpe/qpeapplication.h> | 54 | #include <qpe/qpeapplication.h> |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | //extern bool globalFlagBlockPainting; | 57 | //extern bool globalFlagBlockPainting; |
58 | extern int globalFlagBlockAgenda; | 58 | extern int globalFlagBlockAgenda; |
59 | extern int globalFlagBlockAgendaItemPaint; | 59 | extern int globalFlagBlockAgendaItemPaint; |
60 | extern int globalFlagBlockAgendaItemUpdate; | 60 | extern int globalFlagBlockAgendaItemUpdate; |
61 | extern int globalFlagBlockStartup; | 61 | extern int globalFlagBlockStartup; |
62 | 62 | ||
63 | //////////////////////////////////////////////////////////////////////////// | 63 | //////////////////////////////////////////////////////////////////////////// |
64 | MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) | 64 | MarcusBains::MarcusBains(KOAgenda *_agenda,const char *name) |
65 | : QFrame(_agenda->viewport(),name), agenda(_agenda) | 65 | : QFrame(_agenda->viewport(),name), agenda(_agenda) |
66 | { | 66 | { |
67 | setLineWidth(0); | 67 | setLineWidth(0); |
68 | setMargin(0); | 68 | setMargin(0); |
69 | setBackgroundColor(Qt::red); | 69 | setBackgroundColor(Qt::red); |
70 | minutes = new QTimer(this); | 70 | minutes = new QTimer(this); |
71 | connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); | 71 | connect(minutes, SIGNAL(timeout()), this, SLOT(updateLoc())); |
72 | minutes->start(0, true); | 72 | minutes->start(0, true); |
73 | 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 || mPopupKind == 3 ) { | 384 | if ( mPopupKind == 1 || mPopupKind == 3 ) { |
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 | //mClickedItem = mPopupItem; |
391 | selectItem(mPopupItem); | 391 | selectItem(mPopupItem); |
392 | if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 ) | 392 | if ( mAllAgendaPopup && KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 1 ) |
393 | mAllAgendaPopup->installEventFilter( this ); | 393 | mAllAgendaPopup->installEventFilter( this ); |
394 | emit showIncidencePopupSignal(mPopupItem->incidence()); | 394 | emit showIncidencePopupSignal(mPopupItem->incidence()); |
395 | 395 | ||
396 | } | 396 | } |
397 | } else if ( mPopupKind == 2 || mPopupKind == 4 ) { | 397 | } else if ( mPopupKind == 2 || mPopupKind == 4 ) { |
398 | 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 |
399 | endSelectAction( false ); // do not emit new event signal | 399 | endSelectAction( false ); // do not emit new event signal |
400 | mLeftMouseDown = false; // no more leftMouse computation | 400 | mLeftMouseDown = false; // no more leftMouse computation |
401 | } | 401 | } |
402 | if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 ) | 402 | if ( KOPrefs::instance()->mBlockPopupMenu && mPopupKind == 2 ) |
403 | mNewItemPopup->installEventFilter( this ); | 403 | mNewItemPopup->installEventFilter( this ); |
404 | mNewItemPopup->popup( mPopupPos); | 404 | mNewItemPopup->popup( mPopupPos); |
405 | 405 | ||
406 | } | 406 | } |
407 | mLeftMouseDown = false; | 407 | mLeftMouseDown = false; |
408 | mPopupItem = 0; | 408 | mPopupItem = 0; |
409 | mPopupKind = 0; | 409 | mPopupKind = 0; |
410 | } | 410 | } |
411 | 411 | ||
412 | bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) | 412 | bool KOAgenda::eventFilter_mouse(QObject *object, QMouseEvent *me) |
413 | { | 413 | { |
414 | static int startX = 0; | 414 | static int startX = 0; |
415 | static int startY = 0; | 415 | static int startY = 0; |
416 | static int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 15 : 20 ); | 416 | int blockmoveDist = ( QApplication::desktop()->width() < 480 ? 7 : 9 ); |
417 | static bool blockMoving = true; | 417 | static bool blockMoving = true; |
418 | 418 | ||
419 | //qDebug("KOAgenda::eventFilter_mous "); | 419 | //qDebug("KOAgenda::eventFilter_mous "); |
420 | if ( object == mNewItemPopup ) { | 420 | if ( object == mNewItemPopup ) { |
421 | //qDebug("mNewItemPopup "); | 421 | //qDebug("mNewItemPopup "); |
422 | if ( me->type() == QEvent::MouseButtonRelease ) { | 422 | if ( me->type() == QEvent::MouseButtonRelease ) { |
423 | mNewItemPopup->removeEventFilter( this ); | 423 | mNewItemPopup->removeEventFilter( this ); |
424 | int dX = me->globalPos().x() - mPopupPos.x();; | 424 | int dX = me->globalPos().x() - mPopupPos.x();; |
425 | if ( dX < 0 ) | 425 | if ( dX < 0 ) |
426 | dX = -dX; | 426 | dX = -dX; |
427 | int dY = me->globalPos().y() - mPopupPos.y(); | 427 | int dY = me->globalPos().y() - mPopupPos.y(); |
428 | if ( dY < 0 ) | 428 | if ( dY < 0 ) |
429 | dY = -dY; | 429 | dY = -dY; |
430 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 430 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
431 | mNewItemPopup->hide(); | 431 | mNewItemPopup->hide(); |
432 | } | 432 | } |
433 | } | 433 | } |
434 | return true; | 434 | return true; |
435 | } | 435 | } |
436 | if ( object == mAllAgendaPopup ) { | 436 | if ( object == mAllAgendaPopup ) { |
437 | //qDebug(" mAllAgendaPopup "); | 437 | //qDebug(" mAllAgendaPopup "); |
438 | if ( me->type() == QEvent::MouseButtonRelease ) { | 438 | if ( me->type() == QEvent::MouseButtonRelease ) { |
439 | mAllAgendaPopup->removeEventFilter( this ); | 439 | mAllAgendaPopup->removeEventFilter( this ); |
440 | int dX = me->globalPos().x() - mPopupPos.x();; | 440 | int dX = me->globalPos().x() - mPopupPos.x();; |
441 | if ( dX < 0 ) | 441 | if ( dX < 0 ) |
442 | dX = -dX; | 442 | dX = -dX; |
443 | int dY = me->globalPos().y() - mPopupPos.y(); | 443 | int dY = me->globalPos().y() - mPopupPos.y(); |
444 | if ( dY < 0 ) | 444 | if ( dY < 0 ) |
445 | dY = -dY; | 445 | dY = -dY; |
446 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 446 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
447 | mAllAgendaPopup->hide(); | 447 | mAllAgendaPopup->hide(); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | return true; | 450 | return true; |
451 | } | 451 | } |
452 | QPoint viewportPos; | 452 | QPoint viewportPos; |
453 | if (object != viewport()) { | 453 | if (object != viewport()) { |
454 | blockmoveDist = blockmoveDist*2; | ||
454 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); | 455 | viewportPos = ((QWidget *)object)->mapToParent(me->pos()); |
455 | } else { | 456 | } else { |
456 | viewportPos = me->pos(); | 457 | viewportPos = me->pos(); |
457 | } | 458 | } |
458 | 459 | ||
459 | switch (me->type()) { | 460 | switch (me->type()) { |
460 | case QEvent::MouseButtonPress: | 461 | case QEvent::MouseButtonPress: |
461 | if (me->button() == LeftButton) { | 462 | if (me->button() == LeftButton) { |
462 | mPopupTimer->start( 600 ); | 463 | mPopupTimer->start( 600 ); |
463 | mLeftMouseDown = true; | 464 | mLeftMouseDown = true; |
464 | } | 465 | } |
465 | blockMoving = true; | 466 | blockMoving = true; |
466 | startX = viewportPos.x(); | 467 | startX = viewportPos.x(); |
467 | startY = viewportPos.y(); | 468 | startY = viewportPos.y(); |
468 | mPopupPos = me->globalPos(); | 469 | mPopupPos = me->globalPos(); |
469 | if (object != viewport()) { | 470 | if (object != viewport()) { |
470 | mPopupItem = (KOAgendaItem *)object; | 471 | mPopupItem = (KOAgendaItem *)object; |
471 | mPopupKind = 1; | 472 | mPopupKind = 1; |
472 | if (me->button() == RightButton) { | 473 | if (me->button() == RightButton) { |
473 | mPopupKind = 3; | 474 | mPopupKind = 3; |
474 | popupMenu(); | 475 | popupMenu(); |
475 | } else if (me->button() == LeftButton) { | 476 | } else if (me->button() == LeftButton) { |
476 | mActionItem = (KOAgendaItem *)object; | 477 | mActionItem = (KOAgendaItem *)object; |
477 | if (mActionItem) { | 478 | if (mActionItem) { |
478 | emit signalClearSelection(); | 479 | emit signalClearSelection(); |
479 | slotClearSelection(); | 480 | slotClearSelection(); |
480 | selectItem(mActionItem); | 481 | selectItem(mActionItem); |
481 | Incidence *incidence = mActionItem->incidence(); | 482 | Incidence *incidence = mActionItem->incidence(); |
482 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { | 483 | if ( incidence->isReadOnly() /*|| incidence->recurrence()->doesRecur() */) { |
483 | mActionItem = 0; | 484 | mActionItem = 0; |
484 | } else { | 485 | } else { |
485 | startItemAction(viewportPos); | 486 | startItemAction(viewportPos); |
486 | } | 487 | } |
487 | } | 488 | } |
488 | } | 489 | } |
489 | } else { // ---------- viewport() | 490 | } else { // ---------- viewport() |
490 | mPopupItem = 0; | 491 | mPopupItem = 0; |
491 | mPopupKind = 2; | 492 | mPopupKind = 2; |
492 | selectItem(0); | 493 | selectItem(0); |
493 | mActionItem = 0; | 494 | mActionItem = 0; |
494 | if (me->button() == RightButton) { | 495 | if (me->button() == RightButton) { |
495 | int x,y; | 496 | int x,y; |
496 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 497 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
497 | int gx,gy; | 498 | int gx,gy; |
498 | contentsToGrid(x,y,gx,gy); | 499 | contentsToGrid(x,y,gx,gy); |
499 | mCurrentCellX = gx; | 500 | mCurrentCellX = gx; |
500 | mCurrentCellY = gy; | 501 | mCurrentCellY = gy; |
501 | mStartCellX = gx; | 502 | mStartCellX = gx; |
502 | mStartCellY = gy; | 503 | mStartCellY = gy; |
503 | mPopupKind = 4; | 504 | mPopupKind = 4; |
504 | popupMenu(); | 505 | popupMenu(); |
505 | } else if (me->button() == LeftButton) { | 506 | } else if (me->button() == LeftButton) { |
506 | setCursor(arrowCursor); | 507 | setCursor(arrowCursor); |
507 | startSelectAction(viewportPos); | 508 | startSelectAction(viewportPos); |
508 | } | 509 | } |
509 | } | 510 | } |
510 | break; | 511 | break; |
511 | 512 | ||
512 | case QEvent::MouseButtonRelease: | 513 | case QEvent::MouseButtonRelease: |
513 | if (me->button() == LeftButton ) { | 514 | if (me->button() == LeftButton ) { |
514 | mPopupTimer->stop(); | 515 | mPopupTimer->stop(); |
515 | } | 516 | } |
516 | if (object != viewport()) { | 517 | if (object != viewport()) { |
517 | if (me->button() == LeftButton && mLeftMouseDown) { | 518 | if (me->button() == LeftButton && mLeftMouseDown) { |
518 | if (mActionItem) { | 519 | if (mActionItem) { |
519 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 520 | QPoint clipperPos = clipper()->mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
520 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); | 521 | //qDebug(" %d %d %d ",clipperPos.y(),visibleHeight() , 9 ); |
521 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { | 522 | if ( mActionType == MOVE && (clipperPos.y() > visibleHeight()-2 ||clipperPos.y() < 0 ) ) { |
522 | mScrollUpTimer.stop(); | 523 | mScrollUpTimer.stop(); |
523 | mScrollDownTimer.stop(); | 524 | mScrollDownTimer.stop(); |
524 | mActionItem->resetMove(); | 525 | mActionItem->resetMove(); |
525 | placeSubCells( mActionItem ); | 526 | placeSubCells( mActionItem ); |
526 | // emit startDragSignal( mActionItem->incidence() ); | 527 | // emit startDragSignal( mActionItem->incidence() ); |
527 | setCursor( arrowCursor ); | 528 | setCursor( arrowCursor ); |
528 | mActionItem = 0; | 529 | mActionItem = 0; |
529 | mActionType = NOP; | 530 | mActionType = NOP; |
530 | mItemMoved = 0; | 531 | mItemMoved = 0; |
531 | mLeftMouseDown = false; | 532 | mLeftMouseDown = false; |
532 | return true; | 533 | return true; |
533 | } | 534 | } |
534 | endItemAction(); | 535 | endItemAction(); |
535 | } | 536 | } |
536 | } | 537 | } |
537 | 538 | ||
538 | } else { // ---------- viewport() | 539 | } else { // ---------- viewport() |
539 | if (me->button() == LeftButton && mLeftMouseDown ) { //left click | 540 | if (me->button() == LeftButton && mLeftMouseDown ) { //left click |
540 | endSelectAction( true ); // emit new event signal | 541 | endSelectAction( true ); // emit new event signal |
541 | } | 542 | } |
542 | } | 543 | } |
543 | if (me->button() == LeftButton) | 544 | if (me->button() == LeftButton) |
544 | mLeftMouseDown = false; | 545 | mLeftMouseDown = false; |
545 | 546 | ||
546 | break; | 547 | break; |
547 | 548 | ||
548 | case QEvent::MouseMove: | 549 | case QEvent::MouseMove: |
549 | //qDebug("mm "); | 550 | //qDebug("mm "); |
550 | if ( !mLeftMouseDown ) | 551 | if ( !mLeftMouseDown ) |
551 | return false; | 552 | return false; |
552 | if ( blockMoving ) { | 553 | if ( blockMoving ) { |
553 | int dX, dY; | 554 | int dX, dY; |
554 | dX = startX - viewportPos.x(); | 555 | dX = startX - viewportPos.x(); |
555 | if ( dX < 0 ) | 556 | if ( dX < 0 ) |
556 | dX = -dX; | 557 | dX = -dX; |
557 | dY = viewportPos.y() - startY; | 558 | dY = viewportPos.y() - startY; |
558 | if ( dY < 0 ) | 559 | if ( dY < 0 ) |
559 | dY = -dY; | 560 | dY = -dY; |
560 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); | 561 | //qDebug("%d %d %d ", dX, dY , blockmoveDist ); |
561 | if ( dX > blockmoveDist || dY > blockmoveDist ) { | 562 | if ( dX > blockmoveDist || dY > blockmoveDist ) { |
562 | blockMoving = false; | 563 | blockMoving = false; |
563 | } | 564 | } |
564 | } | 565 | } |
565 | if ( ! blockMoving ) | 566 | if ( ! blockMoving ) |
566 | mPopupTimer->stop(); | 567 | mPopupTimer->stop(); |
567 | if (object != viewport()) { | 568 | if (object != viewport()) { |
568 | KOAgendaItem *moveItem = (KOAgendaItem *)object; | 569 | KOAgendaItem *moveItem = (KOAgendaItem *)object; |
569 | if (!moveItem->incidence()->isReadOnly() ) { | 570 | if (!moveItem->incidence()->isReadOnly() ) { |
570 | if (!mActionItem) | 571 | if (!mActionItem) |
571 | setNoActionCursor(moveItem,viewportPos); | 572 | setNoActionCursor(moveItem,viewportPos); |
572 | else { | 573 | else { |
573 | if ( !blockMoving ) | 574 | if ( !blockMoving ) |
574 | performItemAction(viewportPos); | 575 | performItemAction(viewportPos); |
575 | } | 576 | } |
576 | } | 577 | } |
577 | } else { // ---------- viewport() | 578 | } else { // ---------- viewport() |
578 | mPopupPos = viewport()->mapToGlobal( me->pos() ); | 579 | mPopupPos = viewport()->mapToGlobal( me->pos() ); |
579 | if ( mActionType == SELECT ) { | 580 | if ( mActionType == SELECT ) { |
580 | performSelectAction( viewportPos ); | 581 | performSelectAction( viewportPos ); |
581 | } | 582 | } |
582 | } | 583 | } |
583 | break; | 584 | break; |
584 | 585 | ||
585 | case QEvent::MouseButtonDblClick: | 586 | case QEvent::MouseButtonDblClick: |
586 | mPopupTimer->stop(); | 587 | mPopupTimer->stop(); |
587 | if (object == viewport()) { | 588 | if (object == viewport()) { |
588 | selectItem(0); | 589 | selectItem(0); |
589 | int x,y; | 590 | int x,y; |
590 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 591 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
591 | int gx,gy; | 592 | int gx,gy; |
592 | contentsToGrid(x,y,gx,gy); | 593 | contentsToGrid(x,y,gx,gy); |
593 | emit newEventSignal(gx,gy); | 594 | emit newEventSignal(gx,gy); |
594 | } else { | 595 | } else { |
595 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; | 596 | KOAgendaItem *doubleClickedItem = (KOAgendaItem *)object; |
596 | selectItem(doubleClickedItem); | 597 | selectItem(doubleClickedItem); |
597 | if ( KOPrefs::instance()->mEditOnDoubleClick ) | 598 | if ( KOPrefs::instance()->mEditOnDoubleClick ) |
598 | emit editIncidenceSignal(doubleClickedItem->incidence()); | 599 | emit editIncidenceSignal(doubleClickedItem->incidence()); |
599 | else | 600 | else |
600 | emit showIncidenceSignal(doubleClickedItem->incidence()); | 601 | emit showIncidenceSignal(doubleClickedItem->incidence()); |
601 | } | 602 | } |
602 | break; | 603 | break; |
603 | 604 | ||
604 | default: | 605 | default: |
605 | break; | 606 | break; |
606 | } | 607 | } |
607 | return true; | 608 | return true; |
608 | 609 | ||
609 | } | 610 | } |
610 | 611 | ||
611 | void KOAgenda::newItem( int item ) | 612 | void KOAgenda::newItem( int item ) |
612 | { | 613 | { |
613 | if ( item == 1 ) { //new event | 614 | if ( item == 1 ) { //new event |
614 | newEventSignal(mStartCellX ,mStartCellY ); | 615 | newEventSignal(mStartCellX ,mStartCellY ); |
615 | } else | 616 | } else |
616 | if ( item == 2 ) { //new event | 617 | if ( item == 2 ) { //new event |
617 | newTodoSignal(mStartCellX ,mStartCellY ); | 618 | newTodoSignal(mStartCellX ,mStartCellY ); |
618 | } else | 619 | } else |
619 | { | 620 | { |
620 | emit showDateView( item, mStartCellX ); | 621 | emit showDateView( item, mStartCellX ); |
621 | // 3Day view | 622 | // 3Day view |
622 | // 4Week view | 623 | // 4Week view |
623 | // 5Month view | 624 | // 5Month view |
624 | // 6Journal view | 625 | // 6Journal view |
625 | } | 626 | } |
626 | } | 627 | } |
627 | void KOAgenda::slotClearSelection() | 628 | void KOAgenda::slotClearSelection() |
628 | { | 629 | { |
629 | if (mSelectionHeight) { | 630 | if (mSelectionHeight) { |
630 | int selectionX = mSelectionCellX * mGridSpacingX; | 631 | int selectionX = mSelectionCellX * mGridSpacingX; |
631 | int top = mSelectionYTop - 2 *mGridSpacingY; | 632 | int top = mSelectionYTop - 2 *mGridSpacingY; |
632 | int hei = mSelectionHeight + 4 *mGridSpacingY; | 633 | int hei = mSelectionHeight + 4 *mGridSpacingY; |
633 | clearSelection(); | 634 | clearSelection(); |
634 | repaintContents( selectionX, top, | 635 | repaintContents( selectionX, top, |
635 | mGridSpacingX, hei ,false ); | 636 | mGridSpacingX, hei ,false ); |
636 | } | 637 | } |
637 | 638 | ||
638 | } | 639 | } |
639 | void KOAgenda::startSelectAction(QPoint viewportPos) | 640 | void KOAgenda::startSelectAction(QPoint viewportPos) |
640 | { | 641 | { |
641 | 642 | ||
642 | emit signalClearSelection(); | 643 | emit signalClearSelection(); |
643 | slotClearSelection(); | 644 | slotClearSelection(); |
644 | 645 | ||
645 | mActionType = SELECT; | 646 | mActionType = SELECT; |
646 | 647 | ||
647 | int x,y; | 648 | int x,y; |
648 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 649 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
649 | int gx,gy; | 650 | int gx,gy; |
650 | contentsToGrid(x,y,gx,gy); | 651 | contentsToGrid(x,y,gx,gy); |
651 | 652 | ||
652 | mStartCellX = gx; | 653 | mStartCellX = gx; |
653 | mStartCellY = gy; | 654 | mStartCellY = gy; |
654 | mCurrentCellX = gx; | 655 | mCurrentCellX = gx; |
655 | mCurrentCellY = gy; | 656 | mCurrentCellY = gy; |
656 | 657 | ||
657 | // Store new selection | 658 | // Store new selection |
658 | mSelectionCellX = gx; | 659 | mSelectionCellX = gx; |
659 | mSelectionYTop = gy * mGridSpacingY; | 660 | mSelectionYTop = gy * mGridSpacingY; |
660 | mSelectionHeight = mGridSpacingY; | 661 | mSelectionHeight = mGridSpacingY; |
661 | 662 | ||
662 | // Paint new selection | 663 | // Paint new selection |
663 | repaintContents( mSelectionCellX * mGridSpacingX+1, mSelectionYTop, | 664 | repaintContents( mSelectionCellX * mGridSpacingX+1, mSelectionYTop, |
664 | mGridSpacingX-1, mSelectionHeight ); | 665 | mGridSpacingX-1, mSelectionHeight ); |
665 | } | 666 | } |
666 | 667 | ||
667 | void KOAgenda::performSelectAction(QPoint viewportPos) | 668 | void KOAgenda::performSelectAction(QPoint viewportPos) |
668 | { | 669 | { |
669 | int x,y; | 670 | int x,y; |
670 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 671 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
671 | int gx,gy; | 672 | int gx,gy; |
672 | contentsToGrid(x,y,gx,gy); | 673 | contentsToGrid(x,y,gx,gy); |
673 | 674 | ||
674 | QPoint clipperPos = clipper()-> | 675 | QPoint clipperPos = clipper()-> |
675 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 676 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
676 | 677 | ||
677 | // Scroll if cursor was moved to upper or lower end of agenda. | 678 | // Scroll if cursor was moved to upper or lower end of agenda. |
678 | if (clipperPos.y() < mScrollBorderWidth) { | 679 | if (clipperPos.y() < mScrollBorderWidth) { |
679 | mScrollUpTimer.start(mScrollDelay); | 680 | mScrollUpTimer.start(mScrollDelay); |
680 | } else if (visibleHeight() - clipperPos.y() < | 681 | } else if (visibleHeight() - clipperPos.y() < |
681 | mScrollBorderWidth) { | 682 | mScrollBorderWidth) { |
682 | mScrollDownTimer.start(mScrollDelay); | 683 | mScrollDownTimer.start(mScrollDelay); |
683 | } else { | 684 | } else { |
684 | mScrollUpTimer.stop(); | 685 | mScrollUpTimer.stop(); |
685 | mScrollDownTimer.stop(); | 686 | mScrollDownTimer.stop(); |
686 | } | 687 | } |
687 | 688 | ||
688 | if ( gy > mCurrentCellY ) { | 689 | if ( gy > mCurrentCellY ) { |
689 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; | 690 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; |
690 | 691 | ||
691 | 692 | ||
692 | repaintContents( (KOGlobals::self()->reverseLayout() ? | 693 | repaintContents( (KOGlobals::self()->reverseLayout() ? |
693 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * | 694 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * |
694 | mGridSpacingX, mSelectionYTop, | 695 | mGridSpacingX, mSelectionYTop, |
695 | mGridSpacingX, mSelectionHeight , false); | 696 | mGridSpacingX, mSelectionHeight , false); |
696 | 697 | ||
697 | mCurrentCellY = gy; | 698 | mCurrentCellY = gy; |
698 | } else if ( gy < mCurrentCellY ) { | 699 | } else if ( gy < mCurrentCellY ) { |
699 | if ( gy >= mStartCellY ) { | 700 | if ( gy >= mStartCellY ) { |
700 | int selectionHeight = mSelectionHeight; | 701 | int selectionHeight = mSelectionHeight; |
701 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; | 702 | mSelectionHeight = ( gy + 1 ) * mGridSpacingY - mSelectionYTop; |
702 | 703 | ||
703 | repaintContents( (KOGlobals::self()->reverseLayout() ? | 704 | repaintContents( (KOGlobals::self()->reverseLayout() ? |
704 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * | 705 | mColumns - 1 - mSelectionCellX : mSelectionCellX) * |
705 | mGridSpacingX, mSelectionYTop, | 706 | mGridSpacingX, mSelectionYTop, |
706 | mGridSpacingX, selectionHeight,false ); | 707 | mGridSpacingX, selectionHeight,false ); |
707 | 708 | ||
708 | mCurrentCellY = gy; | 709 | mCurrentCellY = gy; |
709 | } else { | 710 | } else { |
710 | } | 711 | } |
711 | } | 712 | } |
712 | } | 713 | } |
713 | 714 | ||
714 | void KOAgenda::endSelectAction( bool emitNewEvent ) | 715 | void KOAgenda::endSelectAction( bool emitNewEvent ) |
715 | { | 716 | { |
716 | mActionType = NOP; | 717 | mActionType = NOP; |
717 | mScrollUpTimer.stop(); | 718 | mScrollUpTimer.stop(); |
718 | mScrollDownTimer.stop(); | 719 | mScrollDownTimer.stop(); |
719 | 720 | ||
720 | emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); | 721 | emit newTimeSpanSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); |
721 | if ( emitNewEvent && mStartCellY < mCurrentCellY ) { | 722 | if ( emitNewEvent && mStartCellY < mCurrentCellY ) { |
722 | emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); | 723 | emit newEventSignal(mStartCellX,mStartCellY,mCurrentCellX,mCurrentCellY); |
723 | } | 724 | } |
724 | } | 725 | } |
725 | 726 | ||
726 | void KOAgenda::startItemAction(QPoint viewportPos) | 727 | void KOAgenda::startItemAction(QPoint viewportPos) |
727 | { | 728 | { |
728 | int x,y; | 729 | int x,y; |
729 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 730 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
730 | int gx,gy; | 731 | int gx,gy; |
731 | contentsToGrid(x,y,gx,gy); | 732 | contentsToGrid(x,y,gx,gy); |
732 | 733 | ||
733 | mStartCellX = gx; | 734 | mStartCellX = gx; |
734 | mStartCellY = gy; | 735 | mStartCellY = gy; |
735 | mCurrentCellX = gx; | 736 | mCurrentCellX = gx; |
736 | mCurrentCellY = gy; | 737 | mCurrentCellY = gy; |
737 | 738 | ||
738 | if (mAllDayMode) { | 739 | if (mAllDayMode) { |
739 | int gridDistanceX = (x - gx * mGridSpacingX); | 740 | int gridDistanceX = (x - gx * mGridSpacingX); |
740 | if (gridDistanceX < mResizeBorderWidth && | 741 | if (gridDistanceX < mResizeBorderWidth && |
741 | mActionItem->cellX() == mCurrentCellX) { | 742 | mActionItem->cellX() == mCurrentCellX) { |
742 | mActionType = RESIZELEFT; | 743 | mActionType = RESIZELEFT; |
743 | setCursor(sizeHorCursor); | 744 | setCursor(sizeHorCursor); |
744 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && | 745 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && |
745 | mActionItem->cellXWidth() == mCurrentCellX) { | 746 | mActionItem->cellXWidth() == mCurrentCellX) { |
746 | mActionType = RESIZERIGHT; | 747 | mActionType = RESIZERIGHT; |
747 | setCursor(sizeHorCursor); | 748 | setCursor(sizeHorCursor); |
748 | } else { | 749 | } else { |
749 | mActionType = MOVE; | 750 | mActionType = MOVE; |
750 | mActionItem->startMove(); | 751 | mActionItem->startMove(); |
751 | setCursor(sizeAllCursor); | 752 | setCursor(sizeAllCursor); |
752 | } | 753 | } |
753 | } else { | 754 | } else { |
754 | int gridDistanceY = (y - gy * mGridSpacingY); | 755 | int gridDistanceY = (y - gy * mGridSpacingY); |
755 | bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); | 756 | bool allowResize = ( mActionItem->incidence()->type() != "Todo" ); |
756 | if (allowResize && gridDistanceY < mResizeBorderWidth && | 757 | if (allowResize && gridDistanceY < mResizeBorderWidth && |
757 | mActionItem->cellYTop() == mCurrentCellY && | 758 | mActionItem->cellYTop() == mCurrentCellY && |
758 | !mActionItem->firstMultiItem()) { | 759 | !mActionItem->firstMultiItem()) { |
759 | mActionType = RESIZETOP; | 760 | mActionType = RESIZETOP; |
760 | setCursor(sizeVerCursor); | 761 | setCursor(sizeVerCursor); |
761 | } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && | 762 | } else if (allowResize &&(mGridSpacingY - gridDistanceY) < mResizeBorderWidth && |
762 | mActionItem->cellYBottom() == mCurrentCellY && | 763 | mActionItem->cellYBottom() == mCurrentCellY && |
763 | !mActionItem->lastMultiItem()) { | 764 | !mActionItem->lastMultiItem()) { |
764 | mActionType = RESIZEBOTTOM; | 765 | mActionType = RESIZEBOTTOM; |
765 | setCursor(sizeVerCursor); | 766 | setCursor(sizeVerCursor); |
766 | } else { | 767 | } else { |
767 | mActionType = MOVE; | 768 | mActionType = MOVE; |
768 | mActionItem->startMove(); | 769 | mActionItem->startMove(); |
769 | setCursor(sizeAllCursor); | 770 | setCursor(sizeAllCursor); |
770 | } | 771 | } |
771 | } | 772 | } |
772 | } | 773 | } |
773 | 774 | ||
774 | void KOAgenda::performItemAction(QPoint viewportPos) | 775 | void KOAgenda::performItemAction(QPoint viewportPos) |
775 | { | 776 | { |
776 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; | 777 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; |
777 | // QPoint point = viewport()->mapToGlobal(viewportPos); | 778 | // QPoint point = viewport()->mapToGlobal(viewportPos); |
778 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; | 779 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; |
779 | // point = clipper()->mapFromGlobal(point); | 780 | // point = clipper()->mapFromGlobal(point); |
780 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; | 781 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; |
781 | // kdDebug() << "visible height: " << visibleHeight() << endl; | 782 | // kdDebug() << "visible height: " << visibleHeight() << endl; |
782 | int x,y; | 783 | int x,y; |
783 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 784 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
784 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; | 785 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; |
785 | int gx,gy; | 786 | int gx,gy; |
786 | contentsToGrid(x,y,gx,gy); | 787 | contentsToGrid(x,y,gx,gy); |
787 | QPoint clipperPos = clipper()-> | 788 | QPoint clipperPos = clipper()-> |
788 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); | 789 | mapFromGlobal(viewport()->mapToGlobal(viewportPos)); |
789 | 790 | ||
790 | // Cursor left active agenda area. | 791 | // Cursor left active agenda area. |
791 | // This starts a drag. | 792 | // This starts a drag. |
792 | if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ | 793 | if ( /*clipperPos.y() < 0 || clipperPos.y() > visibleHeight() ||*/ |
793 | clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { | 794 | clipperPos.x() < 0 || clipperPos.x() > visibleWidth() ) { |
794 | if ( mActionType == MOVE ) { | 795 | if ( mActionType == MOVE ) { |
795 | mScrollUpTimer.stop(); | 796 | mScrollUpTimer.stop(); |
796 | mScrollDownTimer.stop(); | 797 | mScrollDownTimer.stop(); |
797 | mActionItem->resetMove(); | 798 | mActionItem->resetMove(); |
798 | placeSubCells( mActionItem ); | 799 | placeSubCells( mActionItem ); |
799 | // emit startDragSignal( mActionItem->incidence() ); | 800 | // emit startDragSignal( mActionItem->incidence() ); |
800 | setCursor( arrowCursor ); | 801 | setCursor( arrowCursor ); |
801 | mActionItem = 0; | 802 | mActionItem = 0; |
802 | mActionType = NOP; | 803 | mActionType = NOP; |
803 | mItemMoved = 0; | 804 | mItemMoved = 0; |
804 | return; | 805 | return; |
805 | } | 806 | } |
806 | } else { | 807 | } else { |
807 | switch ( mActionType ) { | 808 | switch ( mActionType ) { |
808 | case MOVE: | 809 | case MOVE: |
809 | setCursor( sizeAllCursor ); | 810 | setCursor( sizeAllCursor ); |
810 | break; | 811 | break; |
811 | case RESIZETOP: | 812 | case RESIZETOP: |
812 | case RESIZEBOTTOM: | 813 | case RESIZEBOTTOM: |
813 | setCursor( sizeVerCursor ); | 814 | setCursor( sizeVerCursor ); |
814 | break; | 815 | break; |
815 | case RESIZELEFT: | 816 | case RESIZELEFT: |
816 | case RESIZERIGHT: | 817 | case RESIZERIGHT: |
817 | setCursor( sizeHorCursor ); | 818 | setCursor( sizeHorCursor ); |
818 | break; | 819 | break; |
819 | default: | 820 | default: |
820 | setCursor( arrowCursor ); | 821 | setCursor( arrowCursor ); |
821 | } | 822 | } |
822 | } | 823 | } |
823 | 824 | ||
824 | // Scroll if item was moved to upper or lower end of agenda. | 825 | // Scroll if item was moved to upper or lower end of agenda. |
825 | if (clipperPos.y() < mScrollBorderWidth) { | 826 | if (clipperPos.y() < mScrollBorderWidth) { |
826 | mScrollUpTimer.start(mScrollDelay); | 827 | mScrollUpTimer.start(mScrollDelay); |
827 | } else if (visibleHeight() - clipperPos.y() < | 828 | } else if (visibleHeight() - clipperPos.y() < |
828 | mScrollBorderWidth) { | 829 | mScrollBorderWidth) { |
829 | mScrollDownTimer.start(mScrollDelay); | 830 | mScrollDownTimer.start(mScrollDelay); |
830 | } else { | 831 | } else { |
831 | mScrollUpTimer.stop(); | 832 | mScrollUpTimer.stop(); |
832 | mScrollDownTimer.stop(); | 833 | mScrollDownTimer.stop(); |
833 | } | 834 | } |
834 | 835 | ||
835 | // Move or resize item if necessary | 836 | // Move or resize item if necessary |
836 | if (mCurrentCellX != gx || mCurrentCellY != gy) { | 837 | if (mCurrentCellX != gx || mCurrentCellY != gy) { |
837 | mItemMoved = true; | 838 | mItemMoved = true; |
838 | mActionItem->raise(); | 839 | mActionItem->raise(); |
839 | if (mActionType == MOVE) { | 840 | if (mActionType == MOVE) { |
840 | // Move all items belonging to a multi item | 841 | // Move all items belonging to a multi item |
841 | KOAgendaItem *moveItem = mActionItem->firstMultiItem(); | 842 | KOAgendaItem *moveItem = mActionItem->firstMultiItem(); |
842 | bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); | 843 | bool isMultiItem = (moveItem || mActionItem->lastMultiItem()); |
843 | if (!moveItem) moveItem = mActionItem; | 844 | if (!moveItem) moveItem = mActionItem; |
844 | while (moveItem) { | 845 | while (moveItem) { |
845 | int dy; | 846 | int dy; |
846 | if (isMultiItem) dy = 0; | 847 | if (isMultiItem) dy = 0; |
847 | else dy = gy - mCurrentCellY; | 848 | else dy = gy - mCurrentCellY; |
848 | moveItem->moveRelative(gx - mCurrentCellX,dy); | 849 | moveItem->moveRelative(gx - mCurrentCellX,dy); |
849 | int x,y; | 850 | int x,y; |
850 | gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); | 851 | gridToContents(moveItem->cellX(),moveItem->cellYTop(),x,y); |
851 | moveItem->resize(mGridSpacingX * moveItem->cellWidth(), | 852 | moveItem->resize(mGridSpacingX * moveItem->cellWidth(), |
852 | mGridSpacingY * moveItem->cellHeight()); | 853 | mGridSpacingY * moveItem->cellHeight()); |
853 | moveChild(moveItem,x,y); | 854 | moveChild(moveItem,x,y); |
854 | moveItem = moveItem->nextMultiItem(); | 855 | moveItem = moveItem->nextMultiItem(); |
855 | } | 856 | } |
856 | } else if (mActionType == RESIZETOP) { | 857 | } else if (mActionType == RESIZETOP) { |
857 | if (mCurrentCellY <= mActionItem->cellYBottom()) { | 858 | if (mCurrentCellY <= mActionItem->cellYBottom()) { |
858 | mActionItem->expandTop(gy - mCurrentCellY); | 859 | mActionItem->expandTop(gy - mCurrentCellY); |
859 | mActionItem->resize(mActionItem->width(), | 860 | mActionItem->resize(mActionItem->width(), |
860 | mGridSpacingY * mActionItem->cellHeight()); | 861 | mGridSpacingY * mActionItem->cellHeight()); |
861 | int x,y; | 862 | int x,y; |
862 | gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); | 863 | gridToContents(mCurrentCellX,mActionItem->cellYTop(),x,y); |
863 | //moveChild(mActionItem,childX(mActionItem),y); | 864 | //moveChild(mActionItem,childX(mActionItem),y); |
864 | QScrollView::moveChild( mActionItem,childX(mActionItem),y ); | 865 | QScrollView::moveChild( mActionItem,childX(mActionItem),y ); |
865 | } | 866 | } |
866 | } else if (mActionType == RESIZEBOTTOM) { | 867 | } else if (mActionType == RESIZEBOTTOM) { |
867 | if (mCurrentCellY >= mActionItem->cellYTop()) { | 868 | if (mCurrentCellY >= mActionItem->cellYTop()) { |
868 | mActionItem->expandBottom(gy - mCurrentCellY); | 869 | mActionItem->expandBottom(gy - mCurrentCellY); |
869 | mActionItem->resize(mActionItem->width(), | 870 | mActionItem->resize(mActionItem->width(), |
870 | mGridSpacingY * mActionItem->cellHeight()); | 871 | mGridSpacingY * mActionItem->cellHeight()); |
871 | } | 872 | } |
872 | } else if (mActionType == RESIZELEFT) { | 873 | } else if (mActionType == RESIZELEFT) { |
873 | if (mCurrentCellX <= mActionItem->cellXWidth()) { | 874 | if (mCurrentCellX <= mActionItem->cellXWidth()) { |
874 | mActionItem->expandLeft(gx - mCurrentCellX); | 875 | mActionItem->expandLeft(gx - mCurrentCellX); |
875 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), | 876 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), |
876 | mActionItem->height()); | 877 | mActionItem->height()); |
877 | int x,y; | 878 | int x,y; |
878 | gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); | 879 | gridToContents(mActionItem->cellX(),mActionItem->cellYTop(),x,y); |
879 | moveChild(mActionItem,x,childY(mActionItem)); | 880 | moveChild(mActionItem,x,childY(mActionItem)); |
880 | } | 881 | } |
881 | } else if (mActionType == RESIZERIGHT) { | 882 | } else if (mActionType == RESIZERIGHT) { |
882 | if (mCurrentCellX >= mActionItem->cellX()) { | 883 | if (mCurrentCellX >= mActionItem->cellX()) { |
883 | mActionItem->expandRight(gx - mCurrentCellX); | 884 | mActionItem->expandRight(gx - mCurrentCellX); |
884 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), | 885 | mActionItem->resize(mGridSpacingX * mActionItem->cellWidth(), |
885 | mActionItem->height()); | 886 | mActionItem->height()); |
886 | } | 887 | } |
887 | } | 888 | } |
888 | mCurrentCellX = gx; | 889 | mCurrentCellX = gx; |
889 | mCurrentCellY = gy; | 890 | mCurrentCellY = gy; |
890 | } | 891 | } |
891 | } | 892 | } |
892 | 893 | ||
893 | void KOAgenda::endItemAction() | 894 | void KOAgenda::endItemAction() |
894 | { | 895 | { |
895 | 896 | ||
896 | if ( mItemMoved ) { | 897 | if ( mItemMoved ) { |
897 | KOAgendaItem *placeItem = mActionItem->firstMultiItem(); | 898 | KOAgendaItem *placeItem = mActionItem->firstMultiItem(); |
898 | if ( !placeItem ) { | 899 | if ( !placeItem ) { |
899 | placeItem = mActionItem; | 900 | placeItem = mActionItem; |
900 | } | 901 | } |
901 | if ( placeItem->incidence()->recurrence()->doesRecur() ) { | 902 | if ( placeItem->incidence()->recurrence()->doesRecur() ) { |
902 | Incidence* oldInc = placeItem->incidence(); | 903 | Incidence* oldInc = placeItem->incidence(); |
903 | placeItem->recreateIncidence(); | 904 | placeItem->recreateIncidence(); |
904 | emit addToCalSignal(placeItem->incidence(), oldInc ); | 905 | emit addToCalSignal(placeItem->incidence(), oldInc ); |
905 | } | 906 | } |
906 | int type = mActionType; | 907 | int type = mActionType; |
907 | if ( mAllDayMode ) | 908 | if ( mAllDayMode ) |
908 | type = -1; | 909 | type = -1; |
909 | KOAgendaItem *modifiedItem = placeItem; | 910 | KOAgendaItem *modifiedItem = placeItem; |
910 | //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); | 911 | //emit itemModified( placeItem, mActionType /*KOGlobals::EVENTEDITED */); |
911 | QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); | 912 | QPtrList<KOAgendaItem> oldconflictItems ;//= placeItem->conflictItems(); |
912 | KOAgendaItem *item; | 913 | KOAgendaItem *item; |
913 | 914 | ||
914 | if ( placeItem->incidence()->type() == "Todo" ) { | 915 | if ( placeItem->incidence()->type() == "Todo" ) { |
915 | mSelectedItem = 0; | 916 | mSelectedItem = 0; |
916 | //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); | 917 | //qDebug("todo %d %d %d ", mCurrentCellX, modifiedItem->cellX() ,modifiedItem->cellXWidth()); |
917 | modifiedItem->mLastMoveXPos = mCurrentCellX; | 918 | modifiedItem->mLastMoveXPos = mCurrentCellX; |
918 | emit itemModified( modifiedItem, mActionType ); | 919 | emit itemModified( modifiedItem, mActionType ); |
919 | } | 920 | } |
920 | else { | 921 | else { |
921 | 922 | ||
922 | 923 | ||
923 | globalFlagBlockAgendaItemPaint = 1; | 924 | globalFlagBlockAgendaItemPaint = 1; |
924 | for ( item=oldconflictItems.first(); item != 0; | 925 | for ( item=oldconflictItems.first(); item != 0; |
925 | item=oldconflictItems.next() ) { | 926 | item=oldconflictItems.next() ) { |
926 | placeSubCells(item); | 927 | placeSubCells(item); |
927 | } | 928 | } |
928 | while ( placeItem ) { | 929 | while ( placeItem ) { |
929 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); | 930 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); |
930 | oldconflictItems = placeItem->conflictItems(); | 931 | oldconflictItems = placeItem->conflictItems(); |
931 | for ( item=oldconflictItems.first(); item != 0; | 932 | for ( item=oldconflictItems.first(); item != 0; |
932 | item=oldconflictItems.next() ) { | 933 | item=oldconflictItems.next() ) { |
933 | placeSubCells(item); | 934 | placeSubCells(item); |
934 | } | 935 | } |
935 | placeSubCells( placeItem ); | 936 | placeSubCells( placeItem ); |
936 | placeItem = placeItem->nextMultiItem(); | 937 | placeItem = placeItem->nextMultiItem(); |
937 | } | 938 | } |
938 | globalFlagBlockAgendaItemPaint = 0; | 939 | globalFlagBlockAgendaItemPaint = 0; |
939 | for ( item=oldconflictItems.first(); item != 0; | 940 | for ( item=oldconflictItems.first(); item != 0; |
940 | item=oldconflictItems.next() ) { | 941 | item=oldconflictItems.next() ) { |
941 | globalFlagBlockAgendaItemUpdate = 0; | 942 | globalFlagBlockAgendaItemUpdate = 0; |
942 | item->repaintMe(); | 943 | item->repaintMe(); |
943 | globalFlagBlockAgendaItemUpdate = 1; | 944 | globalFlagBlockAgendaItemUpdate = 1; |
944 | item->repaint( false ); | 945 | item->repaint( false ); |
945 | } | 946 | } |
946 | placeItem = modifiedItem; | 947 | placeItem = modifiedItem; |
947 | 948 | ||
948 | while ( placeItem ) { | 949 | while ( placeItem ) { |
949 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); | 950 | //qDebug("placeItem %s ", placeItem->incidence()->summary().latin1()); |
950 | globalFlagBlockAgendaItemUpdate = 0; | 951 | globalFlagBlockAgendaItemUpdate = 0; |
951 | placeItem->repaintMe(); | 952 | placeItem->repaintMe(); |
952 | globalFlagBlockAgendaItemUpdate = 1; | 953 | globalFlagBlockAgendaItemUpdate = 1; |
953 | placeItem->repaint(false); | 954 | placeItem->repaint(false); |
954 | placeItem = placeItem->nextMultiItem(); | 955 | placeItem = placeItem->nextMultiItem(); |
955 | } | 956 | } |
956 | emit itemModified( modifiedItem, mActionType ); | 957 | emit itemModified( modifiedItem, mActionType ); |
957 | 958 | ||
958 | 959 | ||
959 | placeItem = modifiedItem; | 960 | placeItem = modifiedItem; |
960 | while ( placeItem ) { | 961 | while ( placeItem ) { |
961 | oldconflictItems = placeItem->conflictItems(); | 962 | oldconflictItems = placeItem->conflictItems(); |
962 | for ( item=oldconflictItems.first(); item != 0; | 963 | for ( item=oldconflictItems.first(); item != 0; |
963 | item=oldconflictItems.next() ) { | 964 | item=oldconflictItems.next() ) { |
964 | placeSubCells(item); | 965 | placeSubCells(item); |
965 | } | 966 | } |
966 | placeSubCells( placeItem ); | 967 | placeSubCells( placeItem ); |
967 | placeItem = placeItem->nextMultiItem(); | 968 | placeItem = placeItem->nextMultiItem(); |
968 | 969 | ||
969 | } | 970 | } |
970 | placeItem = modifiedItem; | 971 | placeItem = modifiedItem; |
971 | while ( placeItem ) { | 972 | while ( placeItem ) { |
972 | oldconflictItems = placeItem->conflictItems(); | 973 | oldconflictItems = placeItem->conflictItems(); |
973 | for ( item=oldconflictItems.first(); item != 0; | 974 | for ( item=oldconflictItems.first(); item != 0; |
974 | item=oldconflictItems.next() ) { | 975 | item=oldconflictItems.next() ) { |
975 | globalFlagBlockAgendaItemUpdate = 0; | 976 | globalFlagBlockAgendaItemUpdate = 0; |
976 | item->repaintMe(); | 977 | item->repaintMe(); |
977 | globalFlagBlockAgendaItemUpdate = 1; | 978 | globalFlagBlockAgendaItemUpdate = 1; |
978 | item->repaint(false); | 979 | item->repaint(false); |
979 | } | 980 | } |
980 | placeItem = placeItem->nextMultiItem(); | 981 | placeItem = placeItem->nextMultiItem(); |
981 | } | 982 | } |
982 | /* | 983 | /* |
983 | 984 | ||
984 | oldconflictItems = modifiedItem->conflictItems(); | 985 | oldconflictItems = modifiedItem->conflictItems(); |
985 | for ( item=oldconflictItems.first(); item != 0; | 986 | for ( item=oldconflictItems.first(); item != 0; |
986 | item=oldconflictItems.next() ) { | 987 | item=oldconflictItems.next() ) { |
987 | globalFlagBlockAgendaItemUpdate = 0; | 988 | globalFlagBlockAgendaItemUpdate = 0; |
988 | item->paintMe(false); | 989 | item->paintMe(false); |
989 | globalFlagBlockAgendaItemUpdate = 1; | 990 | globalFlagBlockAgendaItemUpdate = 1; |
990 | item->repaint(false); | 991 | item->repaint(false); |
991 | } | 992 | } |
992 | */ | 993 | */ |
993 | 994 | ||
994 | 995 | ||
995 | } | 996 | } |
996 | 997 | ||
997 | } | 998 | } |
998 | 999 | ||
999 | mScrollUpTimer.stop(); | 1000 | mScrollUpTimer.stop(); |
1000 | mScrollDownTimer.stop(); | 1001 | mScrollDownTimer.stop(); |
1001 | setCursor( arrowCursor ); | 1002 | setCursor( arrowCursor ); |
1002 | mActionItem = 0; | 1003 | mActionItem = 0; |
1003 | mActionType = NOP; | 1004 | mActionType = NOP; |
1004 | mItemMoved = 0; | 1005 | mItemMoved = 0; |
1005 | 1006 | ||
1006 | } | 1007 | } |
1007 | 1008 | ||
1008 | void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) | 1009 | void KOAgenda::setNoActionCursor(KOAgendaItem *moveItem,QPoint viewportPos) |
1009 | { | 1010 | { |
1010 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; | 1011 | // kdDebug() << "viewportPos: " << viewportPos.x() << "," << viewportPos.y() << endl; |
1011 | // QPoint point = viewport()->mapToGlobal(viewportPos); | 1012 | // QPoint point = viewport()->mapToGlobal(viewportPos); |
1012 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; | 1013 | // kdDebug() << "Global: " << point.x() << "," << point.y() << endl; |
1013 | // point = clipper()->mapFromGlobal(point); | 1014 | // point = clipper()->mapFromGlobal(point); |
1014 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; | 1015 | // kdDebug() << "clipper: " << point.x() << "," << point.y() << endl; |
1015 | 1016 | ||
1016 | int x,y; | 1017 | int x,y; |
1017 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); | 1018 | viewportToContents(viewportPos.x(),viewportPos.y(),x,y); |
1018 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; | 1019 | // kdDebug() << "contents: " << x << "," << y << "\n" << endl; |
1019 | int gx,gy; | 1020 | int gx,gy; |
1020 | contentsToGrid(x,y,gx,gy); | 1021 | contentsToGrid(x,y,gx,gy); |
1021 | 1022 | ||
1022 | // Change cursor to resize cursor if appropriate | 1023 | // Change cursor to resize cursor if appropriate |
1023 | if (mAllDayMode) { | 1024 | if (mAllDayMode) { |
1024 | int gridDistanceX = (x - gx * mGridSpacingX); | 1025 | int gridDistanceX = (x - gx * mGridSpacingX); |
1025 | if (gridDistanceX < mResizeBorderWidth && | 1026 | if (gridDistanceX < mResizeBorderWidth && |
1026 | moveItem->cellX() == gx) { | 1027 | moveItem->cellX() == gx) { |
1027 | setCursor(sizeHorCursor); | 1028 | setCursor(sizeHorCursor); |
1028 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && | 1029 | } else if ((mGridSpacingX - gridDistanceX) < mResizeBorderWidth && |
1029 | moveItem->cellXWidth() == gx) { | 1030 | moveItem->cellXWidth() == gx) { |
1030 | setCursor(sizeHorCursor); | 1031 | setCursor(sizeHorCursor); |
1031 | } else { | 1032 | } else { |
1032 | setCursor(arrowCursor); | 1033 | setCursor(arrowCursor); |
1033 | } | 1034 | } |
1034 | } else { | 1035 | } else { |
1035 | int gridDistanceY = (y - gy * mGridSpacingY); | 1036 | int gridDistanceY = (y - gy * mGridSpacingY); |
1036 | if (gridDistanceY < mResizeBorderWidth && | 1037 | if (gridDistanceY < mResizeBorderWidth && |
1037 | moveItem->cellYTop() == gy && | 1038 | moveItem->cellYTop() == gy && |
1038 | !moveItem->firstMultiItem()) { | 1039 | !moveItem->firstMultiItem()) { |
1039 | setCursor(sizeVerCursor); | 1040 | setCursor(sizeVerCursor); |
1040 | } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && | 1041 | } else if ((mGridSpacingY - gridDistanceY) < mResizeBorderWidth && |
1041 | moveItem->cellYBottom() == gy && | 1042 | moveItem->cellYBottom() == gy && |
1042 | !moveItem->lastMultiItem()) { | 1043 | !moveItem->lastMultiItem()) { |
1043 | setCursor(sizeVerCursor); | 1044 | setCursor(sizeVerCursor); |
1044 | } else { | 1045 | } else { |
1045 | setCursor(arrowCursor); | 1046 | setCursor(arrowCursor); |
1046 | } | 1047 | } |
1047 | } | 1048 | } |
1048 | } | 1049 | } |
1049 | 1050 | ||
1050 | 1051 | ||
1051 | /* | 1052 | /* |
1052 | Place item in cell and take care that multiple items using the same cell do | 1053 | Place item in cell and take care that multiple items using the same cell do |
1053 | not overlap. This method is not yet optimal. It doesn´t use the maximum space | 1054 | not overlap. This method is not yet optimal. It doesn´t use the maximum space |
1054 | it can get in all cases. | 1055 | it can get in all cases. |
1055 | At the moment the method has a bug: When an item is placed only the sub cell | 1056 | At the moment the method has a bug: When an item is placed only the sub cell |
1056 | widths of the items are changed, which are within the Y region the item to | 1057 | widths of the items are changed, which are within the Y region the item to |
1057 | place spans. When the sub cell width change of one of this items affects a | 1058 | place spans. When the sub cell width change of one of this items affects a |
1058 | cell, where other items are, which do not overlap in Y with the item to place, | 1059 | cell, where other items are, which do not overlap in Y with the item to place, |
1059 | the display gets corrupted, although the corruption looks quite nice. | 1060 | the display gets corrupted, although the corruption looks quite nice. |
1060 | */ | 1061 | */ |
1061 | void KOAgenda::placeSubCells(KOAgendaItem *placeItem) | 1062 | void KOAgenda::placeSubCells(KOAgendaItem *placeItem) |
1062 | { | 1063 | { |
1063 | 1064 | ||
1064 | QPtrList<KOAgendaItem> conflictItems; | 1065 | QPtrList<KOAgendaItem> conflictItems; |
1065 | int maxSubCells = 0; | 1066 | int maxSubCells = 0; |
1066 | QIntDict<KOAgendaItem> subCellDict(5); | 1067 | QIntDict<KOAgendaItem> subCellDict(5); |
1067 | 1068 | ||
1068 | KOAgendaItem *item; | 1069 | KOAgendaItem *item; |
1069 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1070 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1070 | if (item != placeItem) { | 1071 | if (item != placeItem) { |
1071 | if (placeItem->cellX() <= item->cellXWidth() && | 1072 | if (placeItem->cellX() <= item->cellXWidth() && |
1072 | placeItem->cellXWidth() >= item->cellX()) { | 1073 | placeItem->cellXWidth() >= item->cellX()) { |
1073 | if ((placeItem->cellYTop() <= item->cellYBottom()) && | 1074 | if ((placeItem->cellYTop() <= item->cellYBottom()) && |
1074 | (placeItem->cellYBottom() >= item->cellYTop())) { | 1075 | (placeItem->cellYBottom() >= item->cellYTop())) { |
1075 | conflictItems.append(item); | 1076 | conflictItems.append(item); |
1076 | if (item->subCells() > maxSubCells) | 1077 | if (item->subCells() > maxSubCells) |
1077 | maxSubCells = item->subCells(); | 1078 | maxSubCells = item->subCells(); |
1078 | subCellDict.insert(item->subCell(),item); | 1079 | subCellDict.insert(item->subCell(),item); |
1079 | } | 1080 | } |
1080 | } | 1081 | } |
1081 | } | 1082 | } |
1082 | } | 1083 | } |
1083 | 1084 | ||
1084 | if (conflictItems.count() > 0) { | 1085 | if (conflictItems.count() > 0) { |
1085 | // Look for unused sub cell and insert item | 1086 | // Look for unused sub cell and insert item |
1086 | int i; | 1087 | int i; |
1087 | for(i=0;i<maxSubCells;++i) { | 1088 | for(i=0;i<maxSubCells;++i) { |
1088 | if (!subCellDict.find(i)) { | 1089 | if (!subCellDict.find(i)) { |
1089 | placeItem->setSubCell(i); | 1090 | placeItem->setSubCell(i); |
1090 | break; | 1091 | break; |
1091 | } | 1092 | } |
1092 | } | 1093 | } |
1093 | if (i == maxSubCells) { | 1094 | if (i == maxSubCells) { |
1094 | placeItem->setSubCell(maxSubCells); | 1095 | placeItem->setSubCell(maxSubCells); |
1095 | maxSubCells++; // add new item to number of sub cells | 1096 | maxSubCells++; // add new item to number of sub cells |
1096 | } | 1097 | } |
1097 | 1098 | ||
1098 | // Prepare for sub cell geometry adjustment | 1099 | // Prepare for sub cell geometry adjustment |
1099 | int newSubCellWidth; | 1100 | int newSubCellWidth; |
1100 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; | 1101 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / maxSubCells; |
1101 | else newSubCellWidth = mGridSpacingX / maxSubCells; | 1102 | else newSubCellWidth = mGridSpacingX / maxSubCells; |
1102 | conflictItems.append(placeItem); | 1103 | conflictItems.append(placeItem); |
1103 | 1104 | ||
1104 | 1105 | ||
1105 | // Adjust sub cell geometry of all direct conflict items | 1106 | // Adjust sub cell geometry of all direct conflict items |
1106 | for ( item=conflictItems.first(); item != 0; | 1107 | for ( item=conflictItems.first(); item != 0; |
1107 | item=conflictItems.next() ) { | 1108 | item=conflictItems.next() ) { |
1108 | item->setSubCells(maxSubCells); | 1109 | item->setSubCells(maxSubCells); |
1109 | if (mAllDayMode) { | 1110 | if (mAllDayMode) { |
1110 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); | 1111 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); |
1111 | } else { | 1112 | } else { |
1112 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); | 1113 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); |
1113 | } | 1114 | } |
1114 | int x,y; | 1115 | int x,y; |
1115 | gridToContents(item->cellX(),item->cellYTop(),x,y); | 1116 | gridToContents(item->cellX(),item->cellYTop(),x,y); |
1116 | if (mAllDayMode) { | 1117 | if (mAllDayMode) { |
1117 | y += item->subCell() * newSubCellWidth; | 1118 | y += item->subCell() * newSubCellWidth; |
1118 | } else { | 1119 | } else { |
1119 | x += item->subCell() * newSubCellWidth; | 1120 | x += item->subCell() * newSubCellWidth; |
1120 | } | 1121 | } |
1121 | moveChild(item,x,y); | 1122 | moveChild(item,x,y); |
1122 | // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); | 1123 | // qDebug("moveChild %s %d %d ", item->incidence()->summary().latin1() ,x,y); |
1123 | //item->updateItem(); | 1124 | //item->updateItem(); |
1124 | } | 1125 | } |
1125 | // Adjust sub cell geometry of all conflict items of all conflict items | 1126 | // Adjust sub cell geometry of all conflict items of all conflict items |
1126 | for ( item=conflictItems.first(); item != 0; | 1127 | for ( item=conflictItems.first(); item != 0; |
1127 | item=conflictItems.next() ) { | 1128 | item=conflictItems.next() ) { |
1128 | if ( placeItem != item ) { | 1129 | if ( placeItem != item ) { |
1129 | KOAgendaItem *item2; | 1130 | KOAgendaItem *item2; |
1130 | QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); | 1131 | QPtrList<KOAgendaItem> conflictItems2 = item->conflictItems(); |
1131 | for ( item2=conflictItems2.first(); item2 != 0; | 1132 | for ( item2=conflictItems2.first(); item2 != 0; |
1132 | item2=conflictItems2.next() ) { | 1133 | item2=conflictItems2.next() ) { |
1133 | if ( item2->subCells() != maxSubCells) { | 1134 | if ( item2->subCells() != maxSubCells) { |
1134 | item2->setSubCells(maxSubCells); | 1135 | item2->setSubCells(maxSubCells); |
1135 | if (mAllDayMode) { | 1136 | if (mAllDayMode) { |
1136 | item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); | 1137 | item2->resize(item2->cellWidth() * mGridSpacingX, newSubCellWidth); |
1137 | } else { | 1138 | } else { |
1138 | item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); | 1139 | item2->resize(newSubCellWidth, item2->cellHeight() * mGridSpacingY); |
1139 | } | 1140 | } |
1140 | int x,y; | 1141 | int x,y; |
1141 | gridToContents(item2->cellX(),item2->cellYTop(),x,y); | 1142 | gridToContents(item2->cellX(),item2->cellYTop(),x,y); |
1142 | if (mAllDayMode) { | 1143 | if (mAllDayMode) { |
1143 | y += item2->subCell() * newSubCellWidth; | 1144 | y += item2->subCell() * newSubCellWidth; |
1144 | } else { | 1145 | } else { |
1145 | x += item2->subCell() * newSubCellWidth; | 1146 | x += item2->subCell() * newSubCellWidth; |
1146 | } | 1147 | } |
1147 | moveChild(item2,x,y); | 1148 | moveChild(item2,x,y); |
1148 | //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); | 1149 | //qDebug("setttttt %d %s",maxSubCells, item2->text().latin1() ); |
1149 | } | 1150 | } |
1150 | } | 1151 | } |
1151 | } | 1152 | } |
1152 | } | 1153 | } |
1153 | } else { | 1154 | } else { |
1154 | placeItem->setSubCell(0); | 1155 | placeItem->setSubCell(0); |
1155 | placeItem->setSubCells(1); | 1156 | placeItem->setSubCells(1); |
1156 | if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); | 1157 | if (mAllDayMode) placeItem->resize(placeItem->width(),mGridSpacingY); |
1157 | else placeItem->resize(mGridSpacingX,placeItem->height()); | 1158 | else placeItem->resize(mGridSpacingX,placeItem->height()); |
1158 | int x,y; | 1159 | int x,y; |
1159 | gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); | 1160 | gridToContents(placeItem->cellX(),placeItem->cellYTop(),x,y); |
1160 | moveChild(placeItem,x,y); | 1161 | moveChild(placeItem,x,y); |
1161 | } | 1162 | } |
1162 | placeItem->setConflictItems(conflictItems); | 1163 | placeItem->setConflictItems(conflictItems); |
1163 | // for ( item=conflictItems.first(); item != 0; | 1164 | // for ( item=conflictItems.first(); item != 0; |
1164 | // item=conflictItems.next() ) { | 1165 | // item=conflictItems.next() ) { |
1165 | // //item->updateItem(); | 1166 | // //item->updateItem(); |
1166 | // //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); | 1167 | // //qDebug("xxx item->updateItem() %s %d %d", item->incidence()->summary().latin1(),item->x(), item->y() ); |
1167 | // } | 1168 | // } |
1168 | // placeItem->updateItem(); | 1169 | // placeItem->updateItem(); |
1169 | } | 1170 | } |
1170 | 1171 | ||
1171 | void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | 1172 | void KOAgenda::drawContents(QPainter* p, int cx, int cy, int cw, int ch) |
1172 | { | 1173 | { |
1173 | if ( globalFlagBlockAgenda ) | 1174 | if ( globalFlagBlockAgenda ) |
1174 | return; | 1175 | return; |
1175 | if ( ! mAllDayMode ) { | 1176 | if ( ! mAllDayMode ) { |
1176 | // currently not working for | 1177 | // currently not working for |
1177 | 1178 | ||
1178 | //qDebug("KOAgenda::drawContents "); | 1179 | //qDebug("KOAgenda::drawContents "); |
1179 | if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) | 1180 | if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) |
1180 | ;//drawContentsToPainter(); | 1181 | ;//drawContentsToPainter(); |
1181 | 1182 | ||
1182 | QPaintDevice* pd = p->device(); | 1183 | QPaintDevice* pd = p->device(); |
1183 | p->end(); | 1184 | p->end(); |
1184 | int vx, vy; | 1185 | int vx, vy; |
1185 | int selectionX = KOGlobals::self()->reverseLayout() ? | 1186 | int selectionX = KOGlobals::self()->reverseLayout() ? |
1186 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : | 1187 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : |
1187 | mSelectionCellX * mGridSpacingX; | 1188 | mSelectionCellX * mGridSpacingX; |
1188 | contentsToViewport ( cx, cy, vx,vy); | 1189 | contentsToViewport ( cx, cy, vx,vy); |
1189 | //qDebug(" %d %d %d %d %d", cx, cy, cw,ch,mGridSpacingX-1) ; | 1190 | //qDebug(" %d %d %d %d %d", cx, cy, cw,ch,mGridSpacingX-1) ; |
1190 | 1191 | ||
1191 | if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) { | 1192 | if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) { |
1192 | if ( mGridSpacingX == cw && mSelectionHeight > 0 && ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && | 1193 | if ( mGridSpacingX == cw && mSelectionHeight > 0 && ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && |
1193 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) ) { | 1194 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) ) { |
1194 | 1195 | ||
1195 | int vxSel, vySel; | 1196 | int vxSel, vySel; |
1196 | contentsToViewport ( selectionX, mSelectionYTop, vxSel,vySel); | 1197 | contentsToViewport ( selectionX, mSelectionYTop, vxSel,vySel); |
1197 | int off = mSelectionHeight; | 1198 | int off = mSelectionHeight; |
1198 | if ( vySel < 0 ) | 1199 | if ( vySel < 0 ) |
1199 | off += vySel; | 1200 | off += vySel; |
1200 | //qDebug("OFF %d %d %d", off,vySel, vy ); | 1201 | //qDebug("OFF %d %d %d", off,vySel, vy ); |
1201 | bitBlt ( pd, vx, vy+off, &mPaintPixmap, cx, cy+off, cw , ch-off ,CopyROP); | 1202 | bitBlt ( pd, vx, vy+off, &mPaintPixmap, cx, cy+off, cw , ch-off ,CopyROP); |
1202 | } else { | 1203 | } else { |
1203 | bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); | 1204 | bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); |
1204 | } | 1205 | } |
1205 | } | 1206 | } |
1206 | if ( mSelectionHeight > 0 ) { | 1207 | if ( mSelectionHeight > 0 ) { |
1207 | //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); | 1208 | //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); |
1208 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && | 1209 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && |
1209 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { | 1210 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { |
1210 | contentsToViewport ( selectionX, mSelectionYTop, vx,vy); | 1211 | contentsToViewport ( selectionX, mSelectionYTop, vx,vy); |
1211 | bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); | 1212 | bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); |
1212 | } | 1213 | } |
1213 | } | 1214 | } |
1214 | p->begin( pd ); | 1215 | p->begin( pd ); |
1215 | } else { | 1216 | } else { |
1216 | 1217 | ||
1217 | if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) | 1218 | if ( mCurPixWid != contentsWidth() || mCurPixHei != contentsHeight() ) |
1218 | ;//drawContentsToPainter(); | 1219 | ;//drawContentsToPainter(); |
1219 | 1220 | ||
1220 | QPaintDevice* pd = p->device(); | 1221 | QPaintDevice* pd = p->device(); |
1221 | p->end(); | 1222 | p->end(); |
1222 | int vx, vy; | 1223 | int vx, vy; |
1223 | int selectionX = KOGlobals::self()->reverseLayout() ? | 1224 | int selectionX = KOGlobals::self()->reverseLayout() ? |
1224 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : | 1225 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : |
1225 | mSelectionCellX * mGridSpacingX; | 1226 | mSelectionCellX * mGridSpacingX; |
1226 | contentsToViewport ( cx, cy, vx,vy); | 1227 | contentsToViewport ( cx, cy, vx,vy); |
1227 | // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; | 1228 | // qDebug(" %d %d %d %d ", cx, cy, cw,ch) ; |
1228 | if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) | 1229 | if ( !(selectionX == cx && cy == mSelectionYTop && cw ==mGridSpacingX && ch == mSelectionHeight ) ) |
1229 | bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); | 1230 | bitBlt ( pd, vx, vy, &mPaintPixmap, cx, cy, cw, ch ,CopyROP); |
1230 | 1231 | ||
1231 | if ( mSelectionHeight > 0 ) { | 1232 | if ( mSelectionHeight > 0 ) { |
1232 | //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); | 1233 | //qDebug("---- %d %d %d %d ", selectionX, mSelectionYTop, mGridSpacingX, mSelectionHeight ); |
1233 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && | 1234 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && |
1234 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { | 1235 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { |
1235 | contentsToViewport ( selectionX, mSelectionYTop, vx,vy); | 1236 | contentsToViewport ( selectionX, mSelectionYTop, vx,vy); |
1236 | bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); | 1237 | bitBlt ( pd, vx+1, vy, &mHighlightPixmap, 0, mSelectionYTop, mGridSpacingX-1, mSelectionHeight ,CopyROP); |
1237 | } | 1238 | } |
1238 | } | 1239 | } |
1239 | p->begin( pd ); | 1240 | p->begin( pd ); |
1240 | } | 1241 | } |
1241 | 1242 | ||
1242 | } | 1243 | } |
1243 | 1244 | ||
1244 | void KOAgenda::finishUpdate() | 1245 | void KOAgenda::finishUpdate() |
1245 | { | 1246 | { |
1246 | 1247 | ||
1247 | KOAgendaItem *item; | 1248 | KOAgendaItem *item; |
1248 | globalFlagBlockAgendaItemPaint = 1; | 1249 | globalFlagBlockAgendaItemPaint = 1; |
1249 | // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems | 1250 | // Adjust sub cell geometry of all conflict items of all conflict items of all conflict items ... of the conflict item with the max number of conflictitems |
1250 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1251 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1251 | if ( !item->checkLayout() ) { | 1252 | if ( !item->checkLayout() ) { |
1252 | //qDebug(" conflictitem found "); | 1253 | //qDebug(" conflictitem found "); |
1253 | int newSubCellWidth; | 1254 | int newSubCellWidth; |
1254 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); | 1255 | if (mAllDayMode) newSubCellWidth = mGridSpacingY / item->subCells(); |
1255 | else newSubCellWidth = mGridSpacingX / item->subCells(); | 1256 | else newSubCellWidth = mGridSpacingX / item->subCells(); |
1256 | 1257 | ||
1257 | if (mAllDayMode) { | 1258 | if (mAllDayMode) { |
1258 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); | 1259 | item->resize(item->cellWidth() * mGridSpacingX, newSubCellWidth); |
1259 | } else { | 1260 | } else { |
1260 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); | 1261 | item->resize(newSubCellWidth, item->cellHeight() * mGridSpacingY); |
1261 | } | 1262 | } |
1262 | int x,y; | 1263 | int x,y; |
1263 | gridToContents(item->cellX(),item->cellYTop(),x,y); | 1264 | gridToContents(item->cellX(),item->cellYTop(),x,y); |
1264 | if (mAllDayMode) { | 1265 | if (mAllDayMode) { |
1265 | y += item->subCell() * newSubCellWidth; | 1266 | y += item->subCell() * newSubCellWidth; |
1266 | } else { | 1267 | } else { |
1267 | x += item->subCell() * newSubCellWidth; | 1268 | x += item->subCell() * newSubCellWidth; |
1268 | } | 1269 | } |
1269 | moveChild(item,x,y); | 1270 | moveChild(item,x,y); |
1270 | } | 1271 | } |
1271 | } | 1272 | } |
1272 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1273 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1273 | if ( !item->isVisible() ) | 1274 | if ( !item->isVisible() ) |
1274 | item->show(); | 1275 | item->show(); |
1275 | 1276 | ||
1276 | } | 1277 | } |
1277 | globalFlagBlockAgendaItemUpdate = 0; | 1278 | globalFlagBlockAgendaItemUpdate = 0; |
1278 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1279 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1279 | item->repaintMe( ); | 1280 | item->repaintMe( ); |
1280 | } | 1281 | } |
1281 | globalFlagBlockAgendaItemUpdate = 1; | 1282 | globalFlagBlockAgendaItemUpdate = 1; |
1282 | qApp->processEvents(); | 1283 | qApp->processEvents(); |
1283 | globalFlagBlockAgendaItemPaint = 0; | 1284 | globalFlagBlockAgendaItemPaint = 0; |
1284 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { | 1285 | for ( item=mItems.first(); item != 0; item=mItems.next() ) { |
1285 | item->repaint( false ); | 1286 | item->repaint( false ); |
1286 | } | 1287 | } |
1287 | 1288 | ||
1288 | } | 1289 | } |
1289 | 1290 | ||
1290 | /* | 1291 | /* |
1291 | Draw grid in the background of the agenda. | 1292 | Draw grid in the background of the agenda. |
1292 | */ | 1293 | */ |
1293 | void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) | 1294 | void KOAgenda::drawContentsToPainter( QPainter* paint, bool backgroundOnly )// int cx, int cy, int cw, int ch) |
1294 | { | 1295 | { |
1295 | 1296 | ||
1296 | 1297 | ||
1297 | if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) | 1298 | if ( ! mGridSpacingX || ! mGridSpacingY ||! mHolidayMask ) |
1298 | return; | 1299 | return; |
1299 | if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) | 1300 | if ( globalFlagBlockAgenda > 1 && globalFlagBlockAgenda < 4 ) |
1300 | return; | 1301 | return; |
1301 | int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); | 1302 | int cx = 0, cy = 0, cw = contentsWidth(), ch = contentsHeight(); |
1302 | if ( ch < 1 ) | 1303 | if ( ch < 1 ) |
1303 | ch = 1; | 1304 | ch = 1; |
1304 | if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { | 1305 | if ( mPaintPixmap.width() < contentsWidth()+42 || mPaintPixmap.height() < ch ) { |
1305 | mPaintPixmap.resize( contentsWidth()+42, ch ); | 1306 | mPaintPixmap.resize( contentsWidth()+42, ch ); |
1306 | } | 1307 | } |
1307 | mCurPixWid = contentsWidth(); | 1308 | mCurPixWid = contentsWidth(); |
1308 | mCurPixHei = ch; | 1309 | mCurPixHei = ch; |
1309 | if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { | 1310 | if ( mHighlightPixmap.width() < mGridSpacingX-1 || mHighlightPixmap.height() < ch ) { |
1310 | mHighlightPixmap.resize( mGridSpacingX-1, ch ); | 1311 | mHighlightPixmap.resize( mGridSpacingX-1, ch ); |
1311 | mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); | 1312 | mHighlightPixmap.fill ( KOPrefs::instance()->mHighlightColor ); |
1312 | } | 1313 | } |
1313 | mPixPainter.begin( &mPaintPixmap) ; | 1314 | mPixPainter.begin( &mPaintPixmap) ; |
1314 | //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); | 1315 | //qDebug("wid %d hei %d ",mPaintPixmap.width(),mPaintPixmap.height() ); |
1315 | QPainter * p ; | 1316 | QPainter * p ; |
1316 | if (paint == 0) { | 1317 | if (paint == 0) { |
1317 | mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); | 1318 | mPaintPixmap.fill(KOPrefs::instance()->mAgendaBgColor); |
1318 | p = &mPixPainter; | 1319 | p = &mPixPainter; |
1319 | } | 1320 | } |
1320 | else | 1321 | else |
1321 | p = paint ; | 1322 | p = paint ; |
1322 | // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); | 1323 | // qDebug("++++++KOAgenda::drawContentsTo Painter %d %d %d %d ", cx, cy, cw, ch); |
1323 | 1324 | ||
1324 | //--cx;++cw; | 1325 | //--cx;++cw; |
1325 | int lGridSpacingY = mGridSpacingY*2; | 1326 | int lGridSpacingY = mGridSpacingY*2; |
1326 | int selDay; | 1327 | int selDay; |
1327 | if ( !backgroundOnly ) | 1328 | if ( !backgroundOnly ) |
1328 | for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) | 1329 | for ( selDay = 0; selDay < mSelectedDates.count(); ++selDay) |
1329 | { | 1330 | { |
1330 | if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { | 1331 | if ( mSelectedDates[selDay] == QDateTime::currentDateTime ().date() && KOPrefs::instance()->mHighlightCurrentDay) { |
1331 | int x1 = cx; | 1332 | int x1 = cx; |
1332 | int y1 = 0; | 1333 | int y1 = 0; |
1333 | if (y1 < cy) y1 = cy; | 1334 | if (y1 < cy) y1 = cy; |
1334 | int x2 = cx+cw-1; | 1335 | int x2 = cx+cw-1; |
1335 | int y2 = contentsHeight(); | 1336 | int y2 = contentsHeight(); |
1336 | if (y2 > cy+ch-1) y2=cy+ch-1; | 1337 | if (y2 > cy+ch-1) y2=cy+ch-1; |
1337 | if (x2 >= x1 && y2 >= y1) { | 1338 | if (x2 >= x1 && y2 >= y1) { |
1338 | int gxStart = selDay; | 1339 | int gxStart = selDay; |
1339 | int gxEnd = gxStart ; | 1340 | int gxEnd = gxStart ; |
1340 | int xStart = KOGlobals::self()->reverseLayout() ? | 1341 | int xStart = KOGlobals::self()->reverseLayout() ? |
1341 | (mColumns - 1 - gxStart)*mGridSpacingX : | 1342 | (mColumns - 1 - gxStart)*mGridSpacingX : |
1342 | gxStart*mGridSpacingX; | 1343 | gxStart*mGridSpacingX; |
1343 | if (xStart < x1) xStart = x1; | 1344 | if (xStart < x1) xStart = x1; |
1344 | int xEnd = KOGlobals::self()->reverseLayout() ? | 1345 | int xEnd = KOGlobals::self()->reverseLayout() ? |
1345 | (mColumns - gxStart)*mGridSpacingX-1 : | 1346 | (mColumns - gxStart)*mGridSpacingX-1 : |
1346 | (gxStart+1)*mGridSpacingX-1; | 1347 | (gxStart+1)*mGridSpacingX-1; |
1347 | if (xEnd > x2) xEnd = x2; | 1348 | if (xEnd > x2) xEnd = x2; |
1348 | if ( KOPrefs::instance()->mUseHighlightLightColor ) | 1349 | if ( KOPrefs::instance()->mUseHighlightLightColor ) |
1349 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1350 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1350 | KOPrefs::instance()->mAgendaBgColor.light()); | 1351 | KOPrefs::instance()->mAgendaBgColor.light()); |
1351 | else | 1352 | else |
1352 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1353 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1353 | KOPrefs::instance()->mAgendaBgColor.dark()); | 1354 | KOPrefs::instance()->mAgendaBgColor.dark()); |
1354 | 1355 | ||
1355 | } | 1356 | } |
1356 | } | 1357 | } |
1357 | } | 1358 | } |
1358 | // Highlight working hours | 1359 | // Highlight working hours |
1359 | 1360 | ||
1360 | if ( !backgroundOnly ) | 1361 | if ( !backgroundOnly ) |
1361 | if (mWorkingHoursEnable) { | 1362 | if (mWorkingHoursEnable) { |
1362 | int x1 = cx; | 1363 | int x1 = cx; |
1363 | int y1 = mWorkingHoursYTop; | 1364 | int y1 = mWorkingHoursYTop; |
1364 | if (y1 < cy) y1 = cy; | 1365 | if (y1 < cy) y1 = cy; |
1365 | int x2 = cx+cw-1; | 1366 | int x2 = cx+cw-1; |
1366 | // int x2 = mGridSpacingX * 5 - 1; | 1367 | // int x2 = mGridSpacingX * 5 - 1; |
1367 | // if (x2 > cx+cw-1) x2 = cx + cw - 1; | 1368 | // if (x2 > cx+cw-1) x2 = cx + cw - 1; |
1368 | int y2 = mWorkingHoursYBottom; | 1369 | int y2 = mWorkingHoursYBottom; |
1369 | if (y2 > cy+ch-1) y2=cy+ch-1; | 1370 | if (y2 > cy+ch-1) y2=cy+ch-1; |
1370 | 1371 | ||
1371 | if (x2 >= x1 && y2 >= y1) { | 1372 | if (x2 >= x1 && y2 >= y1) { |
1372 | // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); | 1373 | // qDebug("x1 %d mGridSpacingX %d ", x1, mGridSpacingX ); |
1373 | int gxStart = x1/mGridSpacingX; | 1374 | int gxStart = x1/mGridSpacingX; |
1374 | int gxEnd = x2/mGridSpacingX; | 1375 | int gxEnd = x2/mGridSpacingX; |
1375 | while(gxStart <= gxEnd) { | 1376 | while(gxStart <= gxEnd) { |
1376 | if (gxStart < int(mHolidayMask->count()) && | 1377 | if (gxStart < int(mHolidayMask->count()) && |
1377 | !mHolidayMask->at(gxStart)) { | 1378 | !mHolidayMask->at(gxStart)) { |
1378 | int xStart = KOGlobals::self()->reverseLayout() ? | 1379 | int xStart = KOGlobals::self()->reverseLayout() ? |
1379 | (mColumns - 1 - gxStart)*mGridSpacingX : | 1380 | (mColumns - 1 - gxStart)*mGridSpacingX : |
1380 | gxStart*mGridSpacingX; | 1381 | gxStart*mGridSpacingX; |
1381 | if (xStart < x1) xStart = x1; | 1382 | if (xStart < x1) xStart = x1; |
1382 | int xEnd = KOGlobals::self()->reverseLayout() ? | 1383 | int xEnd = KOGlobals::self()->reverseLayout() ? |
1383 | (mColumns - gxStart)*mGridSpacingX-1 : | 1384 | (mColumns - gxStart)*mGridSpacingX-1 : |
1384 | (gxStart+1)*mGridSpacingX-1; | 1385 | (gxStart+1)*mGridSpacingX-1; |
1385 | if (xEnd > x2) xEnd = x2; | 1386 | if (xEnd > x2) xEnd = x2; |
1386 | if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { | 1387 | if ( mSelectedDates[gxStart] == QDateTime::currentDateTime ().date()&& KOPrefs::instance()->mHighlightCurrentDay ) { |
1387 | if ( KOPrefs::instance()->mUseHighlightLightColor ) | 1388 | if ( KOPrefs::instance()->mUseHighlightLightColor ) |
1388 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1389 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1389 | KOPrefs::instance()->mWorkingHoursColor.light()); | 1390 | KOPrefs::instance()->mWorkingHoursColor.light()); |
1390 | else | 1391 | else |
1391 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1392 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1392 | KOPrefs::instance()->mWorkingHoursColor.dark()); | 1393 | KOPrefs::instance()->mWorkingHoursColor.dark()); |
1393 | } else { | 1394 | } else { |
1394 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, | 1395 | p->fillRect(xStart,y1,xEnd-xStart+1,y2-y1+1, |
1395 | KOPrefs::instance()->mWorkingHoursColor); | 1396 | KOPrefs::instance()->mWorkingHoursColor); |
1396 | } | 1397 | } |
1397 | } | 1398 | } |
1398 | ++gxStart; | 1399 | ++gxStart; |
1399 | } | 1400 | } |
1400 | } | 1401 | } |
1401 | } | 1402 | } |
1402 | /* | 1403 | /* |
1403 | int selectionX = KOGlobals::self()->reverseLayout() ? | 1404 | int selectionX = KOGlobals::self()->reverseLayout() ? |
1404 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : | 1405 | (mColumns - 1 - mSelectionCellX) * mGridSpacingX : |
1405 | mSelectionCellX * mGridSpacingX; | 1406 | mSelectionCellX * mGridSpacingX; |
1406 | 1407 | ||
1407 | // Draw selection | 1408 | // Draw selection |
1408 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && | 1409 | if ( ( cx + cw ) >= selectionX && cx <= ( selectionX + mGridSpacingX ) && |
1409 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { | 1410 | ( cy + ch ) >= mSelectionYTop && cy <= ( mSelectionYTop + mSelectionHeight ) ) { |
1410 | // TODO: paint only part within cx,cy,cw,ch | 1411 | // TODO: paint only part within cx,cy,cw,ch |
1411 | p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, | 1412 | p->fillRect( selectionX, mSelectionYTop, mGridSpacingX, |
1412 | mSelectionHeight, KOPrefs::instance()->mHighlightColor ); | 1413 | mSelectionHeight, KOPrefs::instance()->mHighlightColor ); |
1413 | } | 1414 | } |
1414 | */ | 1415 | */ |
1415 | // Draw vertical lines of grid | 1416 | // Draw vertical lines of grid |
1416 | 1417 | ||
1417 | int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; | 1418 | int x = ((int)(cx/mGridSpacingX))*mGridSpacingX; |
1418 | if ( mGridSpacingX > 0 ) { | 1419 | if ( mGridSpacingX > 0 ) { |
1419 | while (x < cx + cw) { | 1420 | while (x < cx + cw) { |
1420 | p->drawLine(x,cy,x,cy+ch); | 1421 | p->drawLine(x,cy,x,cy+ch); |
1421 | x+=mGridSpacingX; | 1422 | x+=mGridSpacingX; |
1422 | } | 1423 | } |
1423 | } | 1424 | } |
1424 | // Draw horizontal lines of grid | 1425 | // Draw horizontal lines of grid |
1425 | int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; | 1426 | int y = ((int)(cy/lGridSpacingY))*lGridSpacingY; |
1426 | if ( lGridSpacingY > 0 ) { | 1427 | if ( lGridSpacingY > 0 ) { |
1427 | while (y < cy + ch) { | 1428 | while (y < cy + ch) { |
1428 | p->setPen( SolidLine ); | 1429 | p->setPen( SolidLine ); |
1429 | p->drawLine(cx,y,cx+cw,y); | 1430 | p->drawLine(cx,y,cx+cw,y); |
1430 | y+=lGridSpacingY; | 1431 | y+=lGridSpacingY; |
1431 | p->setPen( DotLine ); | 1432 | p->setPen( DotLine ); |
1432 | p->drawLine(cx,y,cx+cw,y); | 1433 | p->drawLine(cx,y,cx+cw,y); |
1433 | y+=lGridSpacingY; | 1434 | y+=lGridSpacingY; |
1434 | } | 1435 | } |
1435 | p->setPen( SolidLine ); | 1436 | p->setPen( SolidLine ); |
1436 | } | 1437 | } |
1437 | mPixPainter.end() ; | 1438 | mPixPainter.end() ; |
1438 | } | 1439 | } |
1439 | 1440 | ||
1440 | /* | 1441 | /* |
1441 | Convert srcollview contents coordinates to agenda grid coordinates. | 1442 | Convert srcollview contents coordinates to agenda grid coordinates. |
1442 | */ | 1443 | */ |
1443 | void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) | 1444 | void KOAgenda::contentsToGrid (int x, int y, int& gx, int& gy) |
1444 | { | 1445 | { |
1445 | gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : | 1446 | gx = KOGlobals::self()->reverseLayout() ? mColumns - 1 - x/mGridSpacingX : |
1446 | x/mGridSpacingX; | 1447 | x/mGridSpacingX; |
1447 | gy = y/mGridSpacingY; | 1448 | gy = y/mGridSpacingY; |
1448 | } | 1449 | } |
1449 | 1450 | ||
1450 | /* | 1451 | /* |
1451 | Convert agenda grid coordinates to scrollview contents coordinates. | 1452 | Convert agenda grid coordinates to scrollview contents coordinates. |
1452 | */ | 1453 | */ |
1453 | void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) | 1454 | void KOAgenda::gridToContents (int gx, int gy, int& x, int& y) |
1454 | { | 1455 | { |
1455 | x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: | 1456 | x = KOGlobals::self()->reverseLayout() ? (mColumns - 1 - gx)*mGridSpacingX: |
1456 | gx*mGridSpacingX; | 1457 | gx*mGridSpacingX; |
1457 | y = gy*mGridSpacingY; | 1458 | y = gy*mGridSpacingY; |
1458 | } | 1459 | } |
1459 | 1460 | ||
1460 | 1461 | ||
1461 | /* | 1462 | /* |
1462 | Return Y coordinate corresponding to time. Coordinates are rounded to fit into | 1463 | Return Y coordinate corresponding to time. Coordinates are rounded to fit into |
1463 | the grid. | 1464 | the grid. |
1464 | */ | 1465 | */ |
1465 | int KOAgenda::timeToY(const QTime &time) | 1466 | int KOAgenda::timeToY(const QTime &time) |
1466 | { | 1467 | { |
1467 | int minutesPerCell = 24 * 60 / mRows; | 1468 | int minutesPerCell = 24 * 60 / mRows; |
1468 | int timeMinutes = time.hour() * 60 + time.minute(); | 1469 | int timeMinutes = time.hour() * 60 + time.minute(); |
1469 | int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; | 1470 | int Y = (timeMinutes + (minutesPerCell / 2)) / minutesPerCell; |
1470 | return Y; | 1471 | return Y; |
1471 | } | 1472 | } |
1472 | 1473 | ||
1473 | 1474 | ||
1474 | /* | 1475 | /* |
1475 | Return time corresponding to cell y coordinate. Coordinates are rounded to | 1476 | Return time corresponding to cell y coordinate. Coordinates are rounded to |
1476 | fit into the grid. | 1477 | fit into the grid. |
1477 | */ | 1478 | */ |
1478 | QTime KOAgenda::gyToTime(int gy) | 1479 | QTime KOAgenda::gyToTime(int gy) |
1479 | { | 1480 | { |
1480 | 1481 | ||
1481 | int secondsPerCell = 24 * 60 * 60/ mRows; | 1482 | int secondsPerCell = 24 * 60 * 60/ mRows; |
1482 | 1483 | ||
1483 | int timeSeconds = secondsPerCell * gy; | 1484 | int timeSeconds = secondsPerCell * gy; |
1484 | 1485 | ||
1485 | QTime time( 0, 0, 0 ); | 1486 | QTime time( 0, 0, 0 ); |
1486 | if ( timeSeconds < 24 * 60 * 60 ) { | 1487 | if ( timeSeconds < 24 * 60 * 60 ) { |
1487 | time = time.addSecs(timeSeconds); | 1488 | time = time.addSecs(timeSeconds); |
1488 | } else { | 1489 | } else { |
1489 | time.setHMS( 23, 59, 59 ); | 1490 | time.setHMS( 23, 59, 59 ); |
1490 | } | 1491 | } |
1491 | 1492 | ||
1492 | return time; | 1493 | return time; |
1493 | } | 1494 | } |
1494 | 1495 | ||
1495 | void KOAgenda::setStartHour(int startHour) | 1496 | void KOAgenda::setStartHour(int startHour) |
1496 | { | 1497 | { |
1497 | int startCell = startHour * mRows / 24; | 1498 | int startCell = startHour * mRows / 24; |
1498 | setContentsPos(0,startCell * gridSpacingY()); | 1499 | setContentsPos(0,startCell * gridSpacingY()); |
1499 | } | 1500 | } |
1500 | void KOAgenda::hideUnused() | 1501 | void KOAgenda::hideUnused() |
1501 | { | 1502 | { |
1502 | // experimental only | 1503 | // experimental only |
1503 | // return; | 1504 | // return; |
1504 | KOAgendaItem *item; | 1505 | KOAgendaItem *item; |
1505 | for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { | 1506 | for ( item=mUnusedItems.first(); item != 0; item=mUnusedItems.next() ) { |
1506 | item->hide(); | 1507 | item->hide(); |
1507 | } | 1508 | } |
1508 | } | 1509 | } |
1509 | 1510 | ||
1510 | 1511 | ||
1511 | KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) | 1512 | KOAgendaItem *KOAgenda::getNewItem(Incidence * event,QDate qd, QWidget* view) |
1512 | { | 1513 | { |
1513 | 1514 | ||
1514 | KOAgendaItem *fi; | 1515 | KOAgendaItem *fi; |
1515 | for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { | 1516 | for ( fi=mUnusedItems.first(); fi != 0; fi=mUnusedItems.next() ) { |
1516 | if ( fi->incidence() == event ) { | 1517 | if ( fi->incidence() == event ) { |
1517 | mUnusedItems.remove(); | 1518 | mUnusedItems.remove(); |
1518 | fi->init( event, qd ); | 1519 | fi->init( event, qd ); |
1519 | return fi; | 1520 | return fi; |
1520 | } | 1521 | } |
1521 | } | 1522 | } |
1522 | fi=mUnusedItems.first(); | 1523 | fi=mUnusedItems.first(); |
1523 | if ( fi ) { | 1524 | if ( fi ) { |
1524 | mUnusedItems.remove(); | 1525 | mUnusedItems.remove(); |
1525 | fi->init( event, qd ); | 1526 | fi->init( event, qd ); |
1526 | return fi; | 1527 | return fi; |
1527 | } | 1528 | } |