-rw-r--r-- | korganizer/navigatorbar.cpp | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/korganizer/navigatorbar.cpp b/korganizer/navigatorbar.cpp index 27d4d17..4a51bba 100644 --- a/korganizer/navigatorbar.cpp +++ b/korganizer/navigatorbar.cpp | |||
@@ -1,244 +1,247 @@ | |||
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 <kglobalsettings.h> | 43 | #include <kglobalsettings.h> |
44 | #include "koprefs.h" | 44 | #include "koprefs.h" |
45 | #ifndef KORG_NOPLUGINS | 45 | #ifndef KORG_NOPLUGINS |
46 | #include "kocore.h" | 46 | #include "kocore.h" |
47 | #endif | 47 | #endif |
48 | 48 | ||
49 | #include <kcalendarsystem.h> | 49 | #include <kcalendarsystem.h> |
50 | 50 | ||
51 | #include "navigatorbar.h" | 51 | #include "navigatorbar.h" |
52 | 52 | ||
53 | NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name ) | 53 | NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *name ) |
54 | : QWidget( parent, name ) | 54 | : QWidget( parent, name ) |
55 | { | 55 | { |
56 | QBoxLayout *topLayout = new QHBoxLayout( this ); | 56 | QBoxLayout *topLayout = new QHBoxLayout( this ); |
57 | 57 | ||
58 | // Set up the control buttons and date label | 58 | // Set up the control buttons and date label |
59 | mCtrlFrame = new QFrame( this ); | 59 | mCtrlFrame = new QFrame( this ); |
60 | mCtrlFrame->setFrameStyle(QFrame::Panel|QFrame::Raised); | 60 | mCtrlFrame->setFrameStyle(QFrame::Panel|QFrame::Raised); |
61 | mCtrlFrame->setLineWidth(1); | 61 | mCtrlFrame->setLineWidth(1); |
62 | 62 | ||
63 | topLayout->addWidget( mCtrlFrame ); | 63 | topLayout->addWidget( mCtrlFrame ); |
64 | 64 | ||
65 | QFont tfont = font(); | 65 | |
66 | if ( QApplication::desktop()->width() >= 480 ) | ||
67 | tfont.setPointSize(tfont.pointSize()+2); | ||
68 | tfont.setBold(true); | ||
69 | 66 | ||
70 | bool isRTL = KOGlobals::self()->reverseLayout(); | 67 | bool isRTL = KOGlobals::self()->reverseLayout(); |
71 | #ifndef DESKTOP_VERSION | 68 | #ifndef DESKTOP_VERSION |
72 | bool isDesktop = false; | 69 | bool isDesktop = false; |
73 | #else | 70 | #else |
74 | bool isDesktop = true; | 71 | bool isDesktop = true; |
75 | #endif | 72 | #endif |
76 | if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 ) | 73 | if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 ) |
77 | isDesktop = true; | 74 | isDesktop = true; |
78 | // Create backward navigation buttons | 75 | // Create backward navigation buttons |
79 | mPrevYear = new QPushButton( mCtrlFrame ); | 76 | mPrevYear = new QPushButton( mCtrlFrame ); |
80 | mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) ); | 77 | mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) ); |
81 | QToolTip::add( mPrevYear, i18n("Previous Year") ); | 78 | QToolTip::add( mPrevYear, i18n("Previous Year") ); |
82 | 79 | ||
83 | mPrevMonth = new QPushButton( mCtrlFrame ); | 80 | mPrevMonth = new QPushButton( mCtrlFrame ); |
84 | mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); | 81 | mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); |
85 | QToolTip::add( mPrevMonth, i18n("Previous Month") ); | 82 | QToolTip::add( mPrevMonth, i18n("Previous Month") ); |
86 | 83 | ||
87 | // Create forward navigation buttons | 84 | // Create forward navigation buttons |
88 | mNextMonth = new QPushButton( mCtrlFrame ); | 85 | mNextMonth = new QPushButton( mCtrlFrame ); |
89 | mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); | 86 | mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); |
90 | QToolTip::add( mNextMonth, i18n("Next Month") ); | 87 | QToolTip::add( mNextMonth, i18n("Next Month") ); |
91 | 88 | ||
92 | mPrevWeek = new QPushButton( mCtrlFrame ); | 89 | mPrevWeek = new QPushButton( mCtrlFrame ); |
93 | mPrevWeek->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); | 90 | mPrevWeek->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); |
94 | QToolTip::add( mPrevWeek, i18n("Previous Week") ); | 91 | QToolTip::add( mPrevWeek, i18n("Previous Week") ); |
95 | 92 | ||
96 | // Create forward navigation buttons | 93 | // Create forward navigation buttons |
97 | mNextWeek = new QPushButton( mCtrlFrame ); | 94 | mNextWeek = new QPushButton( mCtrlFrame ); |
98 | mNextWeek->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); | 95 | mNextWeek->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); |
99 | QToolTip::add( mNextWeek, i18n("Next Week") ); | 96 | QToolTip::add( mNextWeek, i18n("Next Week") ); |
100 | 97 | ||
101 | mNextYear = new QPushButton( mCtrlFrame ); | 98 | mNextYear = new QPushButton( mCtrlFrame ); |
102 | mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") ); | 99 | mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") ); |
103 | QToolTip::add( mNextYear, i18n("Next Year") ); | 100 | QToolTip::add( mNextYear, i18n("Next Year") ); |
104 | mSelectMonth = new QPushButton( mCtrlFrame ); | 101 | mSelectMonth = new QPushButton( mCtrlFrame ); |
105 | // Create month name label | 102 | // Create month name label |
106 | //selectMonth->setFont( tfont ); | 103 | //selectMonth->setFont( tfont ); |
107 | // selectMonth->setAlignment( AlignCenter ); | 104 | // selectMonth->setAlignment( AlignCenter ); |
108 | //mDateLabel = new QLabel( selectMonth ); | 105 | //mDateLabel = new QLabel( selectMonth ); |
109 | //mDateLabel->setFont( tfont ); | 106 | //mDateLabel->setFont( tfont ); |
110 | //mDateLabel->setAlignment( AlignCenter ); | 107 | //mDateLabel->setAlignment( AlignCenter ); |
111 | if ( QString ( name ) == QString("useBigPixmaps") ) { | 108 | if ( QString ( name ) == QString("useBigPixmaps") ) { |
112 | mNextMonth->setFlat( true); | 109 | mNextMonth->setFlat( true); |
113 | mNextWeek->setFlat( true); | 110 | mNextWeek->setFlat( true); |
114 | mNextYear->setFlat( true); | 111 | mNextYear->setFlat( true); |
115 | mSelectMonth->setFlat( true); | 112 | mSelectMonth->setFlat( true); |
116 | mPrevYear->setFlat( true); | 113 | mPrevYear->setFlat( true); |
117 | mPrevMonth->setFlat( true); | 114 | mPrevMonth->setFlat( true); |
118 | mPrevWeek->setFlat( true); | 115 | mPrevWeek->setFlat( true); |
119 | } else { | 116 | } else { |
120 | mPrevWeek->hide(); | 117 | mPrevWeek->hide(); |
121 | mNextWeek->hide(); | 118 | mNextWeek->hide(); |
122 | } | 119 | } |
123 | mSelectMonth->setFont( tfont ); | ||
124 | // Set minimum width to width of widest month name label | ||
125 | int i; | ||
126 | int maxwidth = 0; | ||
127 | QFontMetrics fm ( mSelectMonth->font() ); | ||
128 | int width = fm.width("September '00" ); | ||
129 | // for( i = 1; i <= KOGlobals::self()->calendarSystem()->monthsInYear(date); | ||
130 | // ++i ) { | ||
131 | // //int width = fm.width( KOGlobals::self()->calendarSystem()->monthName(i, | ||
132 | // // KOGlobals::self()->calendarSystem()->year(date) ) + " 2000" ); | ||
133 | // int width = fm.width("September 2000" ); | ||
134 | // if ( width > maxwidth ) maxwidth = width; | ||
135 | // } | ||
136 | maxwidth = width+2; | ||
137 | int size = fm.height()+2; | ||
138 | if ( QApplication::desktop()->width() >= 480 ) { | ||
139 | size += 6; | ||
140 | maxwidth+= 6; | ||
141 | } | ||
142 | 120 | ||
143 | mSelectMonth->setFixedWidth( maxwidth ); | 121 | resetFont( font() ); |
144 | mSelectMonth->setFixedHeight( size ); | 122 | |
145 | mPrevYear->setFixedHeight( size ); | 123 | |
146 | mPrevMonth->setFixedHeight( size ); | ||
147 | mPrevWeek->setFixedHeight( size ); | ||
148 | mNextMonth->setFixedHeight( size ); | ||
149 | mNextWeek->setFixedHeight( size ); | ||
150 | mNextYear->setFixedHeight ( size ); | ||
151 | // set up control frame layout | 124 | // set up control frame layout |
152 | QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 ); | 125 | QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 ); |
153 | ctrlLayout->addWidget( mPrevYear, 3 ); | 126 | ctrlLayout->addWidget( mPrevYear, 3 ); |
154 | ctrlLayout->addWidget( mPrevMonth, 3 ); | 127 | ctrlLayout->addWidget( mPrevMonth, 3 ); |
155 | ctrlLayout->addWidget( mPrevWeek, 3 ); | 128 | ctrlLayout->addWidget( mPrevWeek, 3 ); |
156 | //ctrlLayout->addStretch( 1 ); | 129 | //ctrlLayout->addStretch( 1 ); |
157 | // ctrlLayout->addSpacing( 1 ); | 130 | // ctrlLayout->addSpacing( 1 ); |
158 | // ctrlLayout->addWidget( mDateLabel ); | 131 | // ctrlLayout->addWidget( mDateLabel ); |
159 | ctrlLayout->addWidget( mSelectMonth ); | 132 | ctrlLayout->addWidget( mSelectMonth ); |
160 | // ctrlLayout->addSpacing( 1 ); | 133 | // ctrlLayout->addSpacing( 1 ); |
161 | // ctrlLayout->addStretch( 1 ); | 134 | // ctrlLayout->addStretch( 1 ); |
162 | ctrlLayout->addWidget( mNextWeek, 3 ); | 135 | ctrlLayout->addWidget( mNextWeek, 3 ); |
163 | ctrlLayout->addWidget( mNextMonth, 3 ); | 136 | ctrlLayout->addWidget( mNextMonth, 3 ); |
164 | ctrlLayout->addWidget( mNextYear, 3 ); | 137 | ctrlLayout->addWidget( mNextYear, 3 ); |
165 | 138 | ||
166 | connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) ); | 139 | connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) ); |
167 | connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) ); | 140 | connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) ); |
168 | connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) ); | 141 | connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) ); |
169 | connect( mPrevWeek, SIGNAL( clicked() ), SIGNAL( goPrevWeek() ) ); | 142 | connect( mPrevWeek, SIGNAL( clicked() ), SIGNAL( goPrevWeek() ) ); |
170 | connect( mNextWeek, SIGNAL( clicked() ), SIGNAL( goNextWeek() ) ); | 143 | connect( mNextWeek, SIGNAL( clicked() ), SIGNAL( goNextWeek() ) ); |
171 | connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) ); | 144 | connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) ); |
172 | connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) ); | 145 | connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) ); |
173 | mPrevYear->setFocusPolicy(NoFocus); | 146 | mPrevYear->setFocusPolicy(NoFocus); |
174 | mPrevMonth->setFocusPolicy(NoFocus); | 147 | mPrevMonth->setFocusPolicy(NoFocus); |
175 | mNextMonth->setFocusPolicy(NoFocus); | 148 | mNextMonth->setFocusPolicy(NoFocus); |
176 | mPrevWeek->setFocusPolicy(NoFocus); | 149 | mPrevWeek->setFocusPolicy(NoFocus); |
177 | mNextWeek->setFocusPolicy(NoFocus); | 150 | mNextWeek->setFocusPolicy(NoFocus); |
178 | mNextYear->setFocusPolicy(NoFocus); | 151 | mNextYear->setFocusPolicy(NoFocus); |
179 | mSelectMonth->setFocusPolicy(NoFocus); | 152 | mSelectMonth->setFocusPolicy(NoFocus); |
180 | setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); | 153 | setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); |
181 | 154 | ||
182 | } | 155 | } |
183 | 156 | ||
184 | NavigatorBar::~NavigatorBar() | 157 | NavigatorBar::~NavigatorBar() |
185 | { | 158 | { |
186 | } | 159 | } |
160 | void NavigatorBar::resetFont ( QFont fo ) | ||
161 | { | ||
162 | |||
163 | QFont tfont = fo; | ||
164 | if ( QApplication::desktop()->width() >= 480 ) | ||
165 | tfont.setPointSize(tfont.pointSize()+2); | ||
166 | tfont.setBold(true); | ||
167 | |||
168 | mSelectMonth->setFont( tfont ); | ||
169 | // Set minimum width to width of widest month name label | ||
170 | int i; | ||
171 | int maxwidth = 0; | ||
172 | QFontMetrics fm ( mSelectMonth->font() ); | ||
173 | int width = fm.width("September '00" ); | ||
174 | maxwidth = width+2; | ||
175 | int size = fm.height()+2; | ||
176 | if ( QApplication::desktop()->width() >= 480 ) { | ||
177 | size += 6; | ||
178 | maxwidth+= 6; | ||
179 | } | ||
180 | mSelectMonth->setMinimumWidth( maxwidth ); | ||
181 | mSelectMonth->setFixedHeight( size ); | ||
182 | mPrevYear->setFixedHeight( size ); | ||
183 | mPrevMonth->setFixedHeight( size ); | ||
184 | mPrevWeek->setFixedHeight( size ); | ||
185 | mNextMonth->setFixedHeight( size ); | ||
186 | mNextWeek->setFixedHeight( size ); | ||
187 | mNextYear->setFixedHeight ( size ); | ||
188 | } | ||
189 | |||
187 | void NavigatorBar::showButtons( bool left, bool right ) | 190 | void NavigatorBar::showButtons( bool left, bool right ) |
188 | { | 191 | { |
189 | if ( left ) { | 192 | if ( left ) { |
190 | mPrevYear->show(); | 193 | mPrevYear->show(); |
191 | mPrevMonth->show(); | 194 | mPrevMonth->show(); |
192 | } else { | 195 | } else { |
193 | mPrevYear->hide(); | 196 | mPrevYear->hide(); |
194 | mPrevMonth->hide(); | 197 | mPrevMonth->hide(); |
195 | } | 198 | } |
196 | 199 | ||
197 | if ( right ) { | 200 | if ( right ) { |
198 | mNextYear->show(); | 201 | mNextYear->show(); |
199 | mNextMonth->show(); | 202 | mNextMonth->show(); |
200 | } else { | 203 | } else { |
201 | mNextYear->hide(); | 204 | mNextYear->hide(); |
202 | mNextMonth->hide(); | 205 | mNextMonth->hide(); |
203 | } | 206 | } |
204 | if ( !left && !right ) { | 207 | if ( !left && !right ) { |
205 | mSelectMonth->setMaximumWidth( 1024 ); | 208 | //mSelectMonth->setMaximumWidth( 1024 ); |
206 | mSelectMonth->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); | 209 | mSelectMonth->setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); |
207 | } | 210 | } |
208 | } | 211 | } |
209 | 212 | ||
210 | void NavigatorBar::selectMonth() | 213 | void NavigatorBar::selectMonth() |
211 | { | 214 | { |
212 | 215 | ||
213 | int month; | 216 | int month; |
214 | KPopupFrame* popup = new KPopupFrame(this); | 217 | KPopupFrame* popup = new KPopupFrame(this); |
215 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); | 218 | KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup); |
216 | // ----- | 219 | // ----- |
217 | picker->resize(picker->sizeHint()); | 220 | picker->resize(picker->sizeHint()); |
218 | popup->setMainWidget(picker); | 221 | popup->setMainWidget(picker); |
219 | picker->setFocus(); | 222 | picker->setFocus(); |
220 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); | 223 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); |
221 | if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height())))) | 224 | if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height())))) |
222 | { | 225 | { |
223 | month = picker->getResult(); | 226 | month = picker->getResult(); |
224 | emit monthSelected ( month ); | 227 | emit monthSelected ( month ); |
225 | } else { | 228 | } else { |
226 | KNotifyClient::beep(); | 229 | KNotifyClient::beep(); |
227 | } | 230 | } |
228 | delete popup; | 231 | delete popup; |
229 | } | 232 | } |
230 | void NavigatorBar::selectDates( const KCal::DateList &dateList ) | 233 | void NavigatorBar::selectDates( const KCal::DateList &dateList ) |
231 | { | 234 | { |
232 | if (dateList.count() > 0) { | 235 | if (dateList.count() > 0) { |
233 | QDate date = dateList.first(); | 236 | QDate date = dateList.first(); |
234 | 237 | ||
235 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); | 238 | const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); |
236 | 239 | ||
237 | // compute the label at the top of the navigator | 240 | // compute the label at the top of the navigator |
238 | QString dtstr = i18n(calSys->monthName( date )) + " '" + | 241 | QString dtstr = i18n(calSys->monthName( date )) + " '" + |
239 | QString::number( calSys->year( date ) ).right(2); | 242 | QString::number( calSys->year( date ) ).right(2); |
240 | 243 | ||
241 | mSelectMonth->setText( dtstr ); | 244 | mSelectMonth->setText( dtstr ); |
242 | } | 245 | } |
243 | } | 246 | } |
244 | 247 | ||