27 #include <tqkeycode.h>
34 #include <tdelocale.h>
35 #include <tdeglobal.h>
36 #include <tdeglobalsettings.h>
38 #include "koglobals.h"
40 #include "kodaymatrix.h"
42 #include <kcalendarsystem.h>
44 #include "navigatorbar.h"
46 #include "kdatenavigator.h"
48 KDateNavigator::KDateNavigator( TQWidget *parent,
const char *name )
49 : TQFrame( parent, name ), mBaseDate( 1970, 1, 1 )
51 TQGridLayout* topLayout =
new TQGridLayout(
this, 8, 8 );
53 mNavigatorBar =
new NavigatorBar(
this );
54 topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 );
56 connect( mNavigatorBar, TQ_SIGNAL( prevYearClicked() ), TQ_SIGNAL( prevYearClicked() ) );
57 connect( mNavigatorBar, TQ_SIGNAL( prevMonthClicked() ), TQ_SIGNAL( prevMonthClicked() ) );
58 connect( mNavigatorBar, TQ_SIGNAL( nextMonthClicked() ), TQ_SIGNAL( nextMonthClicked() ) );
59 connect( mNavigatorBar, TQ_SIGNAL( nextYearClicked() ), TQ_SIGNAL( nextYearClicked() ) );
60 connect( mNavigatorBar, TQ_SIGNAL( monthSelected(
int ) ), TQ_SIGNAL( monthSelected(
int ) ) );
61 connect( mNavigatorBar, TQ_SIGNAL( yearSelected(
int ) ), TQ_SIGNAL( yearSelected(
int ) ) );
64 TQString generalFont = TDEGlobalSettings::generalFont().family();
67 for( i = 0; i < 7; i++ ) {
68 mHeadings[i] =
new TQLabel(
this );
69 mHeadings[i]->setFont( TQFont( generalFont, 10, TQFont::Bold ) );
70 mHeadings[i]->setAlignment( AlignCenter );
72 topLayout->addWidget( mHeadings[i], 1, i + 1 );
76 for( i = 0; i < 6; i++ ) {
77 mWeeknos[i] =
new TQLabel(
this );
78 mWeeknos[i]->setAlignment( AlignCenter );
79 mWeeknos[i]->setFont( TQFont( generalFont, 10 ) );
80 mWeeknos[i]->installEventFilter(
this );
82 topLayout->addWidget( mWeeknos[i], i + 2, 0 );
85 mDayMatrix =
new KODayMatrix(
this,
"KDateNavigator::dayMatrix" );
87 connect( mDayMatrix, TQ_SIGNAL( selected(
const KCal::DateList & ) ),
88 TQ_SIGNAL( datesSelected(
const KCal::DateList & ) ) );
90 connect( mDayMatrix, TQ_SIGNAL( incidenceDropped(
Incidence *,
const TQDate & ) ),
91 TQ_SIGNAL( incidenceDropped(
Incidence *,
const TQDate & ) ) );
92 connect( mDayMatrix, TQ_SIGNAL( incidenceDroppedMove(
Incidence * ,
const TQDate & ) ),
93 TQ_SIGNAL( incidenceDroppedMove(
Incidence *,
const TQDate & ) ) );
96 topLayout->addMultiCellWidget( mDayMatrix, 2, 7, 1, 7 );
102 KDateNavigator::~KDateNavigator()
106 void KDateNavigator::setCalendar(
Calendar *cal )
108 mDayMatrix->setCalendar( cal );
111 void KDateNavigator::setBaseDate(
const TQDate &date )
113 if ( date != mBaseDate ) {
120 KCal::DateList dates;
121 dates.append( date );
122 mNavigatorBar->selectDates( dates );
125 mDayMatrix->repaint();
129 TQSizePolicy KDateNavigator::sizePolicy ()
const
131 return TQSizePolicy( TQSizePolicy::MinimumExpanding,
132 TQSizePolicy::MinimumExpanding );
135 void KDateNavigator::updateToday()
137 mDayMatrix->recalculateToday();
138 mDayMatrix->repaint();
141 TQDate KDateNavigator::startDate()
const
144 TQDate dayone( mBaseDate.year(), mBaseDate.month(), mBaseDate.day() );
145 int d2 = KOGlobals::self()->calendarSystem()->day( dayone );
147 dayone = dayone.addDays( -d2 + 1 );
150 const KCalendarSystem *calsys = KOGlobals::self()->calendarSystem();
151 int m_fstDayOfWkCalsys = calsys->dayOfWeek( dayone );
152 int weekstart = TDEGlobal::locale()->weekStartDay();
156 int nextLine = m_fstDayOfWkCalsys <= weekstart ? 7 : 0;
159 int index = weekstart - m_fstDayOfWkCalsys - nextLine;
161 dayone = dayone.addDays( index );
166 TQDate KDateNavigator::endDate()
const
168 return startDate().addDays( 6*7 );
171 void KDateNavigator::updateDates()
174 TQDate dayone = startDate();
176 mDayMatrix->updateView( dayone );
178 const KCalendarSystem *calsys = KOGlobals::self()->calendarSystem();
181 for(
int i = 0; i < 6; i++ ) {
183 TQDate dtStart = mDayMatrix->getDate( i * 7 );
184 TQDate dtEnd = mDayMatrix->getDate( ( i + 1 ) * 7 - 1 );
185 int weeknumstart = calsys->weekNumber( dtStart );
186 int weeknumend = calsys->weekNumber( dtEnd );
189 if ( weeknumstart != weeknumend ) {
190 weeknum = i18n(
"start/end week number of line in date picker",
"%1/%2")
191 .arg( weeknumstart ).arg( weeknumend );
193 weeknum.setNum( weeknumstart );
195 mWeeknos[i]->setText( weeknum );
202 void KDateNavigator::updateDayMatrix()
204 mDayMatrix->updateView();
205 mDayMatrix->repaint();
208 void KDateNavigator::setUpdateNeeded()
210 mDayMatrix->setUpdateNeeded();
213 TQDate KDateNavigator::month()
const
215 TQDate firstCell = startDate();
216 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
218 if ( calSys->day( firstCell ) == 1 ) {
221 calSys->setYMD( firstCell, calSys->year( firstCell ), calSys->month( firstCell ), 1 );
222 return calSys->addMonths( firstCell, 1 );
226 void KDateNavigator::updateView()
234 void KDateNavigator::updateConfig()
237 int weekstart = TDEGlobal::locale()->weekStartDay();
238 for(
int i = 0; i < 7; i++ ) {
239 day = weekstart + i <= 7 ? weekstart + i : ( weekstart + i ) % 7;
240 TQString dayName = KOGlobals::self()->calendarSystem()->weekDayName( day,
242 if ( KOPrefs::instance()->mCompactDialogs ) dayName = dayName.left( 1 );
243 mHeadings[i]->setText( dayName );
250 void KDateNavigator::setShowWeekNums(
bool enabled )
252 for(
int i = 0; i < 6; i++ ) {
261 void KDateNavigator::selectDates(
const DateList &dateList )
263 if ( dateList.count() > 0 ) {
264 mSelectedDates = dateList;
268 mDayMatrix->setSelectedDaysFrom( *( dateList.begin() ),
269 *( --dateList.end() ) );
275 void KDateNavigator::wheelEvent( TQWheelEvent *e )
277 if ( e->delta() > 0 ) {
286 bool KDateNavigator::eventFilter( TQObject *o, TQEvent *e )
288 if ( e->type() == TQEvent::MouseButtonPress ) {
290 for( i = 0; i < 6; ++i ) {
291 if ( o == mWeeknos[ i ] ) {
292 TQDate weekstart = mDayMatrix->getDate( i * 7 );
293 emit weekClicked( weekstart );
303 #include "kdatenavigator.moc"
Replacement for kdpdatebuton.cpp that used 42 widgets for the day matrix to be displayed.