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