26 #include <tqtooltip.h>
27 #include <tqpushbutton.h>
30 #include <tqpopupmenu.h>
34 #include <tdelocale.h>
35 #include <tdeglobal.h>
36 #include <kiconloader.h>
38 #include "koglobals.h"
41 #include <kcalendarsystem.h>
43 #include "navigatorbar.h"
45 ActiveLabel::ActiveLabel( TQWidget *parent,
const char *name )
46 : TQLabel( parent, name )
50 void ActiveLabel::mouseReleaseEvent( TQMouseEvent * )
56 NavigatorBar::NavigatorBar( TQWidget *parent,
const char *name )
57 : TQWidget( parent, name ), mHasMinWidth( false )
59 TQFont tfont = font();
60 tfont.setPointSize( 10 );
61 tfont.setBold(
false );
64 TQSpacerItem *frontSpacer =
new TQSpacerItem( 50, 1, TQSizePolicy::Expanding );
65 TQSpacerItem *endSpacer =
new TQSpacerItem( 50, 1, TQSizePolicy::Expanding );
67 bool isRTL = KOGlobals::self()->reverseLayout();
71 pix = KOGlobals::self()->smallIcon( isRTL ?
"2rightarrow" :
"2leftarrow" );
72 mPrevYear =
new TQPushButton(
this );
73 mPrevYear->setPixmap( pix );
74 mPrevYear->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
75 TQToolTip::add( mPrevYear, i18n(
"Previous year" ) );
77 pix = KOGlobals::self()->smallIcon( isRTL ?
"1rightarrow" :
"1leftarrow");
78 mPrevMonth =
new TQPushButton(
this );
79 mPrevMonth->setPixmap( pix );
80 mPrevMonth->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
81 TQToolTip::add( mPrevMonth, i18n(
"Previous month" ) );
84 pix = KOGlobals::self()->smallIcon( isRTL ?
"1leftarrow" :
"1rightarrow");
85 mNextMonth =
new TQPushButton(
this );
86 mNextMonth->setPixmap( pix );
87 mNextMonth->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
88 TQToolTip::add( mNextMonth, i18n(
"Next month" ) );
90 pix = KOGlobals::self()->smallIcon( isRTL ?
"2leftarrow" :
"2rightarrow");
91 mNextYear =
new TQPushButton(
this );
92 mNextYear->setPixmap( pix );
93 mNextYear->setSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed );
94 TQToolTip::add( mNextYear, i18n(
"Next year" ) );
97 mMonth =
new ActiveLabel(
this );
98 mMonth->setFont( tfont );
99 mMonth->setAlignment( AlignCenter );
100 mMonth->setMinimumHeight( mPrevYear->sizeHint().height() );
101 TQToolTip::add( mMonth, i18n(
"Select a month" ) );
104 mYear =
new ActiveLabel(
this );
105 mYear->setFont( tfont );
106 mYear->setAlignment( AlignCenter );
107 mYear->setMinimumHeight( mPrevYear->sizeHint().height() );
108 TQToolTip::add( mYear, i18n(
"Select a year" ) );
111 TQHBoxLayout *ctrlLayout =
new TQHBoxLayout(
this );
112 ctrlLayout->addWidget( mPrevYear );
113 ctrlLayout->addWidget( mPrevMonth );
114 ctrlLayout->addItem( frontSpacer );
115 ctrlLayout->addWidget( mMonth );
116 ctrlLayout->addWidget( mYear );
117 ctrlLayout->addItem( endSpacer );
118 ctrlLayout->addWidget( mNextMonth );
119 ctrlLayout->addWidget( mNextYear );
121 connect( mPrevYear, TQ_SIGNAL( clicked() ), TQ_SIGNAL( prevYearClicked() ) );
122 connect( mPrevMonth, TQ_SIGNAL( clicked() ), TQ_SIGNAL( prevMonthClicked() ) );
123 connect( mNextMonth, TQ_SIGNAL( clicked() ), TQ_SIGNAL( nextMonthClicked() ) );
124 connect( mNextYear, TQ_SIGNAL( clicked() ), TQ_SIGNAL( nextYearClicked() ) );
125 connect( mMonth, TQ_SIGNAL( clicked() ), TQ_SLOT( selectMonthFromMenu() ) );
126 connect( mYear, TQ_SIGNAL( clicked() ), TQ_SLOT( selectYearFromMenu() ) );
129 NavigatorBar::~NavigatorBar()
133 void NavigatorBar::showButtons(
bool left,
bool right )
153 void NavigatorBar::selectDates(
const KCal::DateList &dateList )
155 if ( dateList.count() > 0 ) {
156 mDate = dateList.first();
158 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
164 for( i = 1; i <= calSys->monthsInYear( mDate ); ++i ) {
165 int w = TQFontMetrics( mMonth->font() ).
166 width( TQString(
"%1" ).
167 arg( calSys->monthName( i, calSys->year( mDate ) ) ) );
168 if ( w > maxwidth ) {
172 mMonth->setMinimumWidth( maxwidth );
177 mMonth->setText( i18n(
"monthname",
"%1" ).arg( calSys->monthName( mDate ) ) );
178 mYear->setText( i18n(
"4 digit year",
"%1" ).arg( calSys->yearString( mDate,
false ) ) );
182 void NavigatorBar::selectMonthFromMenu()
185 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
187 int i, month, months = calSys->monthsInYear( mDate );
189 TQPopupMenu *popup =
new TQPopupMenu( mMonth );
191 for ( i = 1; i <= months; i++ )
192 popup->insertItem( calSys->monthName( i, calSys->year( mDate ) ), i );
194 popup->setActiveItem( calSys->month( mDate ) - 1 );
195 popup->setMinimumWidth( mMonth->width() );
197 if ( ( month = popup->exec( mMonth->mapToGlobal( TQPoint( 0, 0 ) ),
198 calSys->month( mDate ) - 1 ) ) == -1 ) {
203 emit monthSelected( month );
208 void NavigatorBar::selectYearFromMenu()
210 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
212 int year = calSys->year( mDate );
214 int minYear = year - ( years / 3 );
216 TQPopupMenu *popup =
new TQPopupMenu( mYear );
220 for (
int i=0; i < years; i++ ) {
221 popup->insertItem( yearStr.setNum( y ), i );
224 popup->setActiveItem( year - minYear );
226 if ( ( year = popup->exec( mYear->mapToGlobal( TQPoint( 0, 0 ) ),
227 year - minYear ) ) == -1 ) {
232 emit yearSelected( year + minYear );
237 #include "navigatorbar.moc"