summaryrefslogtreecommitdiffabout
path: root/korganizer/navigatorbar.cpp
Unidiff
Diffstat (limited to 'korganizer/navigatorbar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/navigatorbar.cpp199
1 files changed, 199 insertions, 0 deletions
diff --git a/korganizer/navigatorbar.cpp b/korganizer/navigatorbar.cpp
new file mode 100644
index 0000000..1052a99
--- a/dev/null
+++ b/korganizer/navigatorbar.cpp
@@ -0,0 +1,199 @@
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
23*/
24
25#include <qstring.h>
26#include <qtooltip.h>
27#include <qpushbutton.h>
28#include <qlayout.h>
29#include <qframe.h>
30#include <qlabel.h>
31#include <qapplication.h>
32
33#include <kdebug.h>
34#include <klocale.h>
35#include <kglobal.h>
36#include <kiconloader.h>
37#include "libkdepim/kdatepicker.h"
38#include <knotifyclient.h>
39#include "kdatetbl.h"
40
41#include "koglobals.h"
42#include "koprefs.h"
43#ifndef KORG_NOPLUGINS
44#include "kocore.h"
45#endif
46
47#include <kcalendarsystem.h>
48
49#include "navigatorbar.h"
50
51NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name )
52 : QWidget( parent, name )
53{
54 QBoxLayout *topLayout = new QHBoxLayout( this );
55
56 // Set up the control buttons and date label
57 mCtrlFrame = new QFrame( this );
58 mCtrlFrame->setFrameStyle(QFrame::Panel|QFrame::Raised);
59 mCtrlFrame->setLineWidth(1);
60
61 topLayout->addWidget( mCtrlFrame );
62
63 QFont tfont = font();
64 if ( QApplication::desktop()->width() >= 480 )
65 tfont.setPointSize(tfont.pointSize()+2);
66 tfont.setBold(true);
67
68 bool isRTL = KOGlobals::self()->reverseLayout();
69#ifndef DESKTOP_VERSION
70 bool isDesktop = false;
71#else
72 bool isDesktop = true;
73#endif
74 if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 )
75 isDesktop = true;
76 // Create backward navigation buttons
77 mPrevYear = new QPushButton( mCtrlFrame );
78 mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) );
79 QToolTip::add( mPrevYear, i18n("Previous Year") );
80
81 mPrevMonth = new QPushButton( mCtrlFrame );
82 mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") );
83 QToolTip::add( mPrevMonth, i18n("Previous Month") );
84
85 // Create forward navigation buttons
86 mNextMonth = new QPushButton( mCtrlFrame );
87 mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") );
88 QToolTip::add( mNextMonth, i18n("Next Month") );
89
90 mNextYear = new QPushButton( mCtrlFrame );
91 mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") );
92 QToolTip::add( mNextYear, i18n("Next Year") );
93 mSelectMonth = new QPushButton( mCtrlFrame );
94 // Create month name label
95 //selectMonth->setFont( tfont );
96 // selectMonth->setAlignment( AlignCenter );
97 //mDateLabel = new QLabel( selectMonth );
98 //mDateLabel->setFont( tfont );
99 //mDateLabel->setAlignment( AlignCenter );
100 if ( QString ( name ) == QString("useBigPixmaps") ) {
101 mNextMonth->setFlat( true);
102 mNextYear->setFlat( true);
103 mSelectMonth->setFlat( true);
104 mPrevYear->setFlat( true);
105 mPrevMonth->setFlat( true);
106 }
107 mSelectMonth->setFont( tfont );
108 // Set minimum width to width of widest month name label
109 int i;
110 int maxwidth = 0;
111 QFontMetrics fm ( mSelectMonth->font() );
112 int width = fm.width("September '00" );
113// for( i = 1; i <= KOGlobals::self()->calendarSystem()->monthsInYear(date);
114// ++i ) {
115// //int width = fm.width( KOGlobals::self()->calendarSystem()->monthName(i,
116// // KOGlobals::self()->calendarSystem()->year(date) ) + " 2000" );
117// int width = fm.width("September 2000" );
118// if ( width > maxwidth ) maxwidth = width;
119// }
120 maxwidth = width+2;
121 int size = fm.height()+2;
122 if ( QApplication::desktop()->width() >= 480 ) {
123 size += 6;
124 maxwidth+= 6;
125 }
126 mSelectMonth->setFixedWidth( maxwidth );
127 mSelectMonth->setFixedHeight( size );
128 mPrevYear->setFixedHeight( size );
129 mPrevMonth->setFixedHeight( size );
130 mNextMonth->setFixedHeight( size );
131 mNextYear->setFixedHeight ( size );
132 // set up control frame layout
133 QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 );
134 ctrlLayout->addWidget( mPrevYear, 3 );
135 ctrlLayout->addWidget( mPrevMonth, 3 );
136 //ctrlLayout->addStretch( 1 );
137 // ctrlLayout->addSpacing( 1 );
138 // ctrlLayout->addWidget( mDateLabel );
139 ctrlLayout->addWidget( mSelectMonth );
140 // ctrlLayout->addSpacing( 1 );
141 // ctrlLayout->addStretch( 1 );
142 ctrlLayout->addWidget( mNextMonth, 3 );
143 ctrlLayout->addWidget( mNextYear, 3 );
144
145 connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) );
146 connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) );
147 connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) );
148 connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) );
149 connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) );
150 mPrevYear->setFocusPolicy(NoFocus);
151 mPrevMonth->setFocusPolicy(NoFocus);
152 mNextMonth->setFocusPolicy(NoFocus);
153 mNextYear->setFocusPolicy(NoFocus);
154 mSelectMonth->setFocusPolicy(NoFocus);
155}
156
157NavigatorBar::~NavigatorBar()
158{
159}
160
161void NavigatorBar::selectMonth()
162{
163
164 int month;
165 KPopupFrame* popup = new KPopupFrame(this);
166 int size = 12;
167 if ( QApplication::desktop()->width() >= 480 )
168 size = 18;
169 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(size, popup);
170 // -----
171 picker->resize(picker->sizeHint());
172 popup->setMainWidget(picker);
173 picker->setFocus();
174 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
175 if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height()))))
176 {
177 month = picker->getResult();
178 emit monthSelected ( month );
179 } else {
180 KNotifyClient::beep();
181 }
182 delete popup;
183}
184void NavigatorBar::selectDates( const KCal::DateList &dateList )
185{
186 if (dateList.count() > 0) {
187 QDate date = dateList.first();
188
189 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
190
191 // compute the label at the top of the navigator
192 QString dtstr = i18n(calSys->monthName( date )) + " '" +
193 QString::number( calSys->year( date ) ).right(2);
194
195 mSelectMonth->setText( dtstr );
196 }
197}
198
199#include "navigatorbar.moc"