summaryrefslogtreecommitdiffabout
path: root/korganizer/kdatenavigator.cpp
Unidiff
Diffstat (limited to 'korganizer/kdatenavigator.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/kdatenavigator.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp
index ab9a40f..b097dc1 100644
--- a/korganizer/kdatenavigator.cpp
+++ b/korganizer/kdatenavigator.cpp
@@ -22,219 +22,220 @@
22*/ 22*/
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qkeycode.h> 25#include <qkeycode.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qtimer.h> 27#include <qtimer.h>
28#include <qframe.h> 28#include <qframe.h>
29#include <qlabel.h> 29#include <qlabel.h>
30#include <qapplication.h> 30#include <qapplication.h>
31 31
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <kglobal.h> 34#include <kglobal.h>
35 35
36#include "koglobals.h" 36#include "koglobals.h"
37#include "koprefs.h" 37#include "koprefs.h"
38#ifndef KORG_NOPLUGINS 38#ifndef KORG_NOPLUGINS
39#include "kocore.h" 39#include "kocore.h"
40#endif 40#endif
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#include "navigatorbar.h" 44#include "navigatorbar.h"
45 45
46#include "kdatenavigator.h" 46#include "kdatenavigator.h"
47 47
48KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) 48KDateNavigator::KDateNavigator( QWidget *parent, const char *name )
49 : QFrame(parent, name), 49 : QFrame(parent, name),
50 updateTimer(0L) 50 updateTimer(0L)
51{ 51{
52 setFrameStyle(QFrame::NoFrame); 52 setFrameStyle(QFrame::NoFrame);
53 QDate startDate = QDate::currentDate(); 53 QDate startDate = QDate::currentDate();
54 QGridLayout *topLayout = new QGridLayout(this,8,8); 54 QGridLayout *topLayout = new QGridLayout(this,8,8);
55 55
56 if (! startDate.isValid()) { 56 if (! startDate.isValid()) {
57 qDebug("KDateNavigator::invalid startdate "); 57 qDebug("KDateNavigator::invalid startdate ");
58 startDate = QDate::currentDate(); 58 startDate = QDate::currentDate();
59 } 59 }
60 mMonthSignalOffset = 0; 60 mMonthSignalOffset = 0;
61 mSelectedDates.append(startDate); 61 mSelectedDates.append(startDate);
62 m_MthYr = startDate; 62 m_MthYr = startDate;
63 m_bShowWeekNums = true; 63 m_bShowWeekNums = true;
64 64
65 setFont( KOPrefs::instance()->mDateNavigatorFont ); 65 setFont( KOPrefs::instance()->mDateNavigatorFont );
66 mNavigatorBar = new NavigatorBar( startDate, this ); 66 mNavigatorBar = new NavigatorBar( startDate, this );
67 topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); 67 topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 );
68 //mNavigatorBar->resize( 1,1); 68 //mNavigatorBar->resize( 1,1);
69 connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 69 connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
70 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 70 connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
71 connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 71 connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
72 connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 72 connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
73 connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); 73 connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) );
74 74
75 // get the day of the week on the first day 75 // get the day of the week on the first day
76 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); 76 QDate dayone(m_MthYr.year(), m_MthYr.month(), 1);
77 m_fstDayOfWk = dayone.dayOfWeek(); 77 m_fstDayOfWk = dayone.dayOfWeek();
78 78
79 int i; 79 int i;
80 80
81 // Set up the heading fields. 81 // Set up the heading fields.
82 for( i = 0; i < 7; i++ ) { 82 for( i = 0; i < 7; i++ ) {
83 headings[i] = new QLabel("",this); 83 headings[i] = new QLabel("",this);
84 //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); 84 //headings[i]->setFont(QFont("Arial", 10, QFont::Bold));
85 headings[i]->setAlignment(AlignCenter); 85 headings[i]->setAlignment(AlignCenter);
86 86
87 topLayout->addWidget(headings[i],1,i+1); 87 topLayout->addWidget(headings[i],1,i+1);
88 } 88 }
89 89
90 // Create the weeknumber labels 90 // Create the weeknumber labels
91 for( i = 0; i < 6; i++ ) { 91 for( i = 0; i < 6; i++ ) {
92 weeknos[i] = new QLabel(this); 92 weeknos[i] = new QLabel(this);
93 weeknos[i]->setAlignment(AlignCenter); 93 weeknos[i]->setAlignment(AlignCenter);
94 //weeknos[i]->setFont(QFont("Arial", 10)); 94 //weeknos[i]->setFont(QFont("Arial", 10));
95 if(!m_bShowWeekNums) { 95 if(!m_bShowWeekNums) {
96 weeknos[i]->hide(); 96 weeknos[i]->hide();
97 } 97 }
98 weeknos[i]->installEventFilter(this); 98 weeknos[i]->installEventFilter(this);
99 99
100 topLayout->addWidget(weeknos[i],i+2,0); 100 topLayout->addWidget(weeknos[i],i+2,0);
101 } 101 }
102 102
103 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); 103 daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix");
104 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); 104 daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken);
105 daymatrix->setLineWidth(1); 105 daymatrix->setLineWidth(1);
106 106
107 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), 107 connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ),
108 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 108 SIGNAL( datesSelected( const KCal::DateList & ) ) );
109 109
110 connect( daymatrix, SIGNAL( eventDropped( Event * ) ), 110 connect( daymatrix, SIGNAL( eventDropped( Event * ) ),
111 SIGNAL( eventDropped( Event * ) ) ); 111 SIGNAL( eventDropped( Event * ) ) );
112 112
113 topLayout->addMultiCellWidget(daymatrix,2,7,1,7); 113 topLayout->addMultiCellWidget(daymatrix,2,7,1,7);
114 114
115 // read settings from configuration file. 115 // read settings from configuration file.
116 updateConfig(); 116 updateConfig();
117 enableRollover(FollowMonth); 117 enableRollover(FollowMonth);
118 //setFixedSize ( sizeHint() ); 118 mySizeHint = sizeHint();
119} 119}
120void KDateNavigator::slotMonthSelected( int m ) 120void KDateNavigator::slotMonthSelected( int m )
121{ 121{
122 if ( m_MthYr.month() <= mMonthSignalOffset) 122 if ( m_MthYr.month() <= mMonthSignalOffset)
123 m += 12; 123 m += 12;
124 int mo = m - mMonthSignalOffset; 124 int mo = m - mMonthSignalOffset;
125 emit monthSelected( m - mMonthSignalOffset ); 125 emit monthSelected( m - mMonthSignalOffset );
126 126
127} 127}
128void KDateNavigator::setCalendar( Calendar *cal ) 128void KDateNavigator::setCalendar( Calendar *cal )
129{ 129{
130 daymatrix->setCalendar( cal ); 130 daymatrix->setCalendar( cal );
131} 131}
132 132
133void KDateNavigator::setBaseDate( const QDate &date ) 133void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true
134{ 134{
135 m_MthYr = date; 135 m_MthYr = date;
136 136
137 updateDates(); 137 updateDates();
138 updateView(); 138 updateView();
139 139
140 KCal::DateList dates; 140 KCal::DateList dates;
141 dates.append( date ); 141 dates.append( date );
142 mNavigatorBar->selectDates( dates ); 142 mNavigatorBar->selectDates( dates );
143 143
144 daymatrix->clearSelection(); 144 daymatrix->clearSelection();
145 if ( doRepaint )
145 daymatrix->repaint(); 146 daymatrix->repaint();
146} 147}
147 148
148void KDateNavigator::enableRollover(RolloverType r) 149void KDateNavigator::enableRollover(RolloverType r)
149{ 150{
150 switch(r) 151 switch(r)
151 { 152 {
152 case None : 153 case None :
153 if (updateTimer) 154 if (updateTimer)
154 { 155 {
155 updateTimer->stop(); 156 updateTimer->stop();
156 delete updateTimer; 157 delete updateTimer;
157 updateTimer=0L; 158 updateTimer=0L;
158 } 159 }
159 break; 160 break;
160 case FollowDay : 161 case FollowDay :
161 case FollowMonth : 162 case FollowMonth :
162 if (!updateTimer) 163 if (!updateTimer)
163 { 164 {
164 updateTimer = new QTimer(this); 165 updateTimer = new QTimer(this);
165 QObject::connect(updateTimer,SIGNAL(timeout()), 166 QObject::connect(updateTimer,SIGNAL(timeout()),
166 this,SLOT(possiblyPastMidnight())); 167 this,SLOT(possiblyPastMidnight()));
167 } 168 }
168 updateTimer->start(0,true); 169 updateTimer->start(0,true);
169 lastDayChecked = QDate::currentDate(); 170 lastDayChecked = QDate::currentDate();
170 } 171 }
171 updateRollover=r; 172 updateRollover=r;
172} 173}
173 174
174 175
175KDateNavigator::~KDateNavigator() 176KDateNavigator::~KDateNavigator()
176{ 177{
177} 178}
178 179
179 180
180void KDateNavigator::passedMidnight() 181void KDateNavigator::passedMidnight()
181{ 182{
182 QDate today = QDate::currentDate(); 183 QDate today = QDate::currentDate();
183 bool emitMonth = false; 184 bool emitMonth = false;
184 185
185 if (today.month() != lastDayChecked.month()) 186 if (today.month() != lastDayChecked.month())
186 { 187 {
187 if (updateRollover==FollowMonth && 188 if (updateRollover==FollowMonth &&
188 daymatrix->isEndOfMonth()) { 189 daymatrix->isEndOfMonth()) {
189 goNextMonth(); 190 goNextMonth();
190 emitMonth=true; 191 emitMonth=true;
191 } 192 }
192 } 193 }
193 daymatrix->recalculateToday(); 194 daymatrix->recalculateToday();
194 daymatrix->repaint(); 195 daymatrix->repaint();
195 emit dayPassed(today); 196 emit dayPassed(today);
196 if (emitMonth) { emit monthPassed(today); } 197 if (emitMonth) { emit monthPassed(today); }
197} 198}
198 199
199/* slot */ void KDateNavigator::possiblyPastMidnight() 200/* slot */ void KDateNavigator::possiblyPastMidnight()
200{ 201{
201 if (lastDayChecked!=QDate::currentDate()) 202 if (lastDayChecked!=QDate::currentDate())
202 { 203 {
203 passedMidnight(); 204 passedMidnight();
204 lastDayChecked=QDate::currentDate(); 205 lastDayChecked=QDate::currentDate();
205 } 206 }
206 // Set the timer to go off 1 second after midnight 207 // Set the timer to go off 1 second after midnight
207 // or after 8 minutes, whichever comes first. 208 // or after 8 minutes, whichever comes first.
208 if (updateTimer) 209 if (updateTimer)
209 { 210 {
210 QTime now = QTime::currentTime(); 211 QTime now = QTime::currentTime();
211 QTime midnight = QTime(23,59,59); 212 QTime midnight = QTime(23,59,59);
212 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); 213 int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000);
213 214
214 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) 215 // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait))
215 //.arg(now.toString()).arg(midnight.toString())); 216 //.arg(now.toString()).arg(midnight.toString()));
216 217
217 updateTimer->stop(); 218 updateTimer->stop();
218 updateTimer->start(msecsWait,true); 219 updateTimer->start(msecsWait,true);
219 } 220 }
220} 221}
221 222
222void KDateNavigator::updateDates() 223void KDateNavigator::updateDates()
223{ 224{
224 // Find the first day of the week of the current month. 225 // Find the first day of the week of the current month.
225 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); 226 //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr );
226 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); 227 QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() );
227 int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); 228 int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
228 //int di = d1 - d2 + 1; 229 //int di = d1 - d2 + 1;
229 dayone = dayone.addDays( -d2 + 1 ); 230 dayone = dayone.addDays( -d2 + 1 );
230 231
231 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); 232 int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone );
232 233
233 // If month begins on Monday and Monday is first day of week, 234 // If month begins on Monday and Monday is first day of week,
234 // month should begin on second line. Sunday doesn't have this problem. 235 // month should begin on second line. Sunday doesn't have this problem.
235 int nextLine = ( ( m_fstDayOfWkCalsys == 1) && 236 int nextLine = ( ( m_fstDayOfWkCalsys == 1) &&
236 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; 237 ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0;
237 238
238 // update the matrix dates 239 // update the matrix dates
239 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; 240 int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine;
240 241