summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Unidiff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index df606d0..c32a2a4 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -18,143 +18,141 @@
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;}; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { ;};
66 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { qDebug("DELETE KODaymatrixWhatsThis "); };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 ) 106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 )
107 107
108#if 0 108
109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
110 QFrame(parent, name)
111#endif
112{ 109{
110 mLastView = -1;
113 oldW = 0; 111 oldW = 0;
114 oldH = 0; 112 oldH = 0;
115 myPix.resize( 150, 120 ); 113 myPix.resize( 150, 120 );
116 mRedrawNeeded = true; 114 mRedrawNeeded = true;
117 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 115 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
118 mPendingUpdateBeforeRepaint = false; 116 mPendingUpdateBeforeRepaint = false;
119 mouseDown = false; 117 mouseDown = false;
120 // initialize dynamic arrays 118 // initialize dynamic arrays
121 bDays.resize ( NUMDAYS ); 119 bDays.resize ( NUMDAYS );
122 pDays.resize ( NUMDAYS ); 120 pDays.resize ( NUMDAYS );
123 hDays.resize ( NUMDAYS ); 121 hDays.resize ( NUMDAYS );
124 eDays.resize ( NUMDAYS ); 122 eDays.resize ( NUMDAYS );
125 days = new QDate[NUMDAYS]; 123 days = new QDate[NUMDAYS];
126 daylbls = new QString[NUMDAYS]; 124 daylbls = new QString[NUMDAYS];
127 //events = new int[NUMDAYS]; 125 //events = new int[NUMDAYS];
128 mToolTip = new DynamicTip(this); 126 mToolTip = new DynamicTip(this);
129 127
130 // set default values used for drawing the matrix 128 // set default values used for drawing the matrix
131 mDefaultBackColor = palette().active().base(); 129 mDefaultBackColor = palette().active().base();
132 mDefaultTextColor = palette().active().foreground(); 130 mDefaultTextColor = palette().active().foreground();
133 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 131 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
134 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 132 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
135 mSelectedDaysColor = QColor("white"); 133 mSelectedDaysColor = QColor("white");
136 mTodayMarginWidth = 2; 134 mTodayMarginWidth = 2;
137 mSelEnd = mSelStart = NOSELECTION; 135 mSelEnd = mSelStart = NOSELECTION;
138 136
139 setAcceptDrops(true); 137 setAcceptDrops(true);
140 //setFont( QFont("Arial", 10) ); 138 //setFont( QFont("Arial", 10) );
141 139
142 mUpdateTimer = new QTimer( this ); 140 mUpdateTimer = new QTimer( this );
143 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 141 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
144 mRepaintTimer = new QTimer( this ); 142 mRepaintTimer = new QTimer( this );
145 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 143 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
146 mDayChanged = false; 144 mDayChanged = false;
147 updateView(); 145 updateView();
148} 146}
149QString KODayMatrix::getWhatsThisText( QPoint p ) 147QString KODayMatrix::getWhatsThisText( QPoint p )
150{ 148{
151 149
152 int tmp = getDayIndexFrom(p.x(), p.y()); 150 int tmp = getDayIndexFrom(p.x(), p.y());
153 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 151 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
154 return QString(); 152 return QString();
155 QDate mDate = days[tmp]; 153 QDate mDate = days[tmp];
156 QPtrList<Event> eventlist = mCalendar->events(mDate); 154 QPtrList<Event> eventlist = mCalendar->events(mDate);
157 Event *event; 155 Event *event;
158 QStringList mToolTip; 156 QStringList mToolTip;
159 for(event=eventlist.first();event != 0;event=eventlist.next()) { 157 for(event=eventlist.first();event != 0;event=eventlist.next()) {
160 QString mToolTipText; 158 QString mToolTipText;
@@ -199,96 +197,102 @@ QString KODayMatrix::getWhatsThisText( QPoint p )
199 text += " " + event->summary(); 197 text += " " + event->summary();
200 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 198 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
201 } 199 }
202 } 200 }
203 if ( !event->location().isEmpty() ) 201 if ( !event->location().isEmpty() )
204 mToolTipText += " (" + event->location() + ")"; 202 mToolTipText += " (" + event->location() + ")";
205#if QT_VERSION >= 0x030000 203#if QT_VERSION >= 0x030000
206 mToolTipText.replace( '<' , "&lt;" ); 204 mToolTipText.replace( '<' , "&lt;" );
207 mToolTipText.replace( '>' , "&gt;" ); 205 mToolTipText.replace( '>' , "&gt;" );
208#else 206#else
209 if ( mToolTipText.find ('<') >= 0 ) { 207 if ( mToolTipText.find ('<') >= 0 ) {
210 mToolTipText.replace( QRegExp("<") , "&lt;" ); 208 mToolTipText.replace( QRegExp("<") , "&lt;" );
211 } 209 }
212 if ( mToolTipText.find ('>') >= 0 ) { 210 if ( mToolTipText.find ('>') >= 0 ) {
213 mToolTipText.replace( QRegExp(">") , "&gt;" ); 211 mToolTipText.replace( QRegExp(">") , "&gt;" );
214 } 212 }
215#endif 213#endif
216 //qDebug("TTT: %s ", mToolTipText.latin1()); 214 //qDebug("TTT: %s ", mToolTipText.latin1());
217 mToolTip.append( mToolTipText ); 215 mToolTip.append( mToolTipText );
218 } 216 }
219 mToolTip.sort(); 217 mToolTip.sort();
220 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 218 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
221} 219}
222void KODayMatrix::setCalendar( Calendar *cal ) 220void KODayMatrix::setCalendar( Calendar *cal )
223{ 221{
224 mCalendar = cal; 222 mCalendar = cal;
225 223
226 setAcceptDrops( mCalendar ); 224 setAcceptDrops( mCalendar );
227 225
228 updateEvents(); 226 updateEvents();
229} 227}
230 228
231QColor KODayMatrix::getShadedColor(QColor color) 229QColor KODayMatrix::getShadedColor(QColor color)
232{ 230{
233 QColor shaded; 231 QColor shaded;
234 int h=0; 232 int h=0;
235 int s=0; 233 int s=0;
236 int v=0; 234 int v=0;
237 color.hsv(&h,&s,&v); 235 color.hsv(&h,&s,&v);
238 s = s/4; 236 s = s/4;
239 v = 192+v/4; 237 v = 192+v/4;
240 shaded.setHsv(h,s,v); 238 shaded.setHsv(h,s,v);
241 239
242 return shaded; 240 return shaded;
243} 241}
244 242
245KODayMatrix::~KODayMatrix() 243KODayMatrix::~KODayMatrix()
246{ 244{
245#if QT_VERSION >= 0x030000
246
247#else
248 delete mKODaymatrixWhatsThis;
249#endif
250
247 // delete mKODaymatrixWhatsThis; 251 // delete mKODaymatrixWhatsThis;
248 delete [] days; 252 delete [] days;
249 delete [] daylbls; 253 delete [] daylbls;
250 //delete [] events; 254 //delete [] events;
251 delete mToolTip; 255 delete mToolTip;
252} 256}
253 257
254/* 258/*
255void KODayMatrix::setStartDate(QDate start) 259void KODayMatrix::setStartDate(QDate start)
256{ 260{
257 updateView(start); 261 updateView(start);
258} 262}
259*/ 263*/
260 264
261void KODayMatrix::addSelectedDaysTo(DateList& selDays) 265void KODayMatrix::addSelectedDaysTo(DateList& selDays)
262{ 266{
263 267
264 if (mSelStart == NOSELECTION) { 268 if (mSelStart == NOSELECTION) {
265 return; 269 return;
266 } 270 }
267 271
268 //cope with selection being out of matrix limits at top (< 0) 272 //cope with selection being out of matrix limits at top (< 0)
269 int i0 = mSelStart; 273 int i0 = mSelStart;
270 if (i0 < 0) { 274 if (i0 < 0) {
271 for (int i = i0; i < 0; i++) { 275 for (int i = i0; i < 0; i++) {
272 selDays.append(days[0].addDays(i)); 276 selDays.append(days[0].addDays(i));
273 } 277 }
274 i0 = 0; 278 i0 = 0;
275 } 279 }
276 280
277 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 281 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
278 if (mSelEnd > NUMDAYS-1) { 282 if (mSelEnd > NUMDAYS-1) {
279 for (int i = i0; i <= NUMDAYS-1; i++) { 283 for (int i = i0; i <= NUMDAYS-1; i++) {
280 selDays.append(days[i]); 284 selDays.append(days[i]);
281 } 285 }
282 for (int i = NUMDAYS; i < mSelEnd; i++) { 286 for (int i = NUMDAYS; i < mSelEnd; i++) {
283 selDays.append(days[0].addDays(i)); 287 selDays.append(days[0].addDays(i));
284 } 288 }
285 289
286 // apply normal routine to selection being entirely within matrix limits 290 // apply normal routine to selection being entirely within matrix limits
287 } else { 291 } else {
288 for (int i = i0; i <= mSelEnd; i++) { 292 for (int i = i0; i <= mSelEnd; i++) {
289 selDays.append(days[i]); 293 selDays.append(days[i]);
290 } 294 }
291 } 295 }
292} 296}
293 297
294bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 298bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)