• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
navigatorbar.cpp
Go to the documentation of this file.
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 along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "navigatorbar.h"
26 #include "koglobals.h"
27 
28 #include <KCalendarSystem>
29 #include <KIconLoader>
30 
31 #include <QHBoxLayout>
32 #include <QMenu>
33 #include <QToolButton>
34 
35 NavigatorBar::NavigatorBar( QWidget *parent ) : QWidget( parent )
36 {
37  QFont tfont = font();
38  tfont.setPointSize( 10 );
39  tfont.setBold( false );
40 
41  bool isRTL = KOGlobals::self()->reverseLayout();
42 
43  mPrevYear = createNavigationButton(
44  isRTL ? QLatin1String("arrow-right-double") : QLatin1String("arrow-left-double"),
45  i18n( "Scroll backward to the previous year" ),
46  i18n( "Click this button to scroll the display to the "
47  "same approximate day of the previous year" ) );
48 
49  mPrevMonth = createNavigationButton(
50  isRTL ? QLatin1String("arrow-right") : QLatin1String("arrow-left"),
51  i18n( "Scroll backward to the previous month" ),
52  i18n( "Click this button to scroll the display to the "
53  "same approximate date of the previous month" ) );
54 
55  mNextMonth = createNavigationButton(
56  isRTL ?QLatin1String( "arrow-left") : QLatin1String("arrow-right"),
57  i18n( "Scroll forward to the next month" ),
58  i18n( "Click this button to scroll the display to the "
59  "same approximate date of the next month" ) );
60 
61  mNextYear = createNavigationButton(
62  isRTL ? QLatin1String("arrow-left-double") : QLatin1String("arrow-right-double"),
63  i18n( "Scroll forward to the next year" ),
64  i18n( "Click this button to scroll the display to the "
65  "same approximate day of the next year" ) );
66 
67  // Create month name button
68  mMonth = new QToolButton( this );
69  mMonth->setPopupMode( QToolButton::InstantPopup );
70  mMonth->setAutoRaise( true );
71  mMonth->setFont( tfont );
72  mMonth->setToolTip( i18n( "Select a month" ) );
73 
74  // Create year button
75  mYear = new QToolButton( this );
76  mYear->setPopupMode( QToolButton::InstantPopup );
77  mYear->setAutoRaise( true );
78  mYear->setFont( tfont );
79  mYear->setToolTip( i18n( "Select a year" ) );
80 
81  // set up control frame layout
82  QHBoxLayout *ctrlLayout = new QHBoxLayout( this );
83  ctrlLayout->setMargin( 0 );
84  ctrlLayout->addWidget( mPrevYear );
85  ctrlLayout->addWidget( mPrevMonth );
86  ctrlLayout->addStretch();
87  ctrlLayout->addWidget( mMonth );
88  ctrlLayout->addWidget( mYear );
89  ctrlLayout->addStretch();
90  ctrlLayout->addWidget( mNextMonth );
91  ctrlLayout->addWidget( mNextYear );
92 
93  connect( mPrevYear, SIGNAL(clicked()), SIGNAL(prevYearClicked()) );
94  connect( mPrevMonth, SIGNAL(clicked()), SIGNAL(prevMonthClicked()) );
95  connect( mNextMonth, SIGNAL(clicked()), SIGNAL(nextMonthClicked()) );
96  connect( mNextYear, SIGNAL(clicked()), SIGNAL(nextYearClicked()) );
97  connect( mMonth, SIGNAL(clicked()), SLOT(selectMonthFromMenu()) );
98  connect( mYear, SIGNAL(clicked()), SLOT(selectYearFromMenu()) );
99 }
100 
101 NavigatorBar::~NavigatorBar()
102 {
103 }
104 
105 void NavigatorBar::showButtons( bool left, bool right )
106 {
107  if ( left ) {
108  mPrevYear->show();
109  mPrevMonth->show();
110  } else {
111  mPrevYear->hide();
112  mPrevMonth->hide();
113  }
114 
115  if ( right ) {
116  mNextYear->show();
117  mNextMonth->show();
118  } else {
119  mNextYear->hide();
120  mNextMonth->hide();
121  }
122 }
123 
124 void NavigatorBar::selectDates( const KCalCore::DateList &dateList )
125 {
126  if ( dateList.count() > 0 ) {
127  mDate = dateList.first();
128 
129  const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
130 
131  // set the label text at the top of the navigator
132  mMonth->setText( i18nc( "monthname", "%1", calSys->monthName( mDate ) ) );
133  mYear->setText( i18nc( "4 digit year", "%1",
134  calSys->formatDate( mDate, KLocale::Year, KLocale::LongNumber ) ) );
135  }
136 }
137 
138 void NavigatorBar::selectMonthFromMenu()
139 {
140  // every year can have different month names (in some calendar systems)
141  const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
142 
143  int month = calSys->month( mDate );
144  int year = calSys->year( mDate );
145  int months = calSys->monthsInYear( mDate );
146 
147  QMenu *menu = new QMenu( mMonth );
148  QList<QAction *>act;
149 
150  QAction *activateAction = 0;
151  for ( int i=1; i <= months; ++i ) {
152  QAction *monthAction = menu->addAction( calSys->monthName( i, year ) );
153  act.append( monthAction );
154  if ( i == month ) {
155  activateAction = monthAction;
156  }
157  }
158  if ( activateAction ) {
159  menu->setActiveAction( activateAction );
160  }
161  month = 0;
162  QAction *selectedAct = menu->exec( mMonth->mapToGlobal( QPoint( 0, 0 ) ) );
163  if ( selectedAct && ( selectedAct != activateAction ) ) {
164  for ( int i=0; i < months; ++i ) {
165  if ( act[i] == selectedAct ) {
166  month = i + 1;
167  }
168  }
169  }
170  qDeleteAll( act );
171  act.clear();
172  delete menu;
173 
174  if ( month > 0 ) {
175  emit monthSelected( month );
176  }
177 }
178 
179 void NavigatorBar::selectYearFromMenu()
180 {
181  const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
182 
183  int year = calSys->year( mDate );
184  int years = 11; // odd number (show a few years ago -> a few years from now)
185  int minYear = year - ( years / 3 );
186 
187  QMenu *menu = new QMenu( mYear );
188  QList<QAction *>act;
189 
190  QString yearStr;
191  QAction *activateAction = 0;
192  int y = minYear;
193  for ( int i=0; i < years; ++i ) {
194  QAction *yearAction = menu->addAction( yearStr.setNum( y ) );
195  act.append( yearAction );
196  if ( y == year ) {
197  activateAction = yearAction;
198  }
199  y++;
200  }
201  if ( activateAction ) {
202  menu->setActiveAction( activateAction );
203  }
204  year = 0;
205  QAction *selectedAct = menu->exec( mYear->mapToGlobal( QPoint( 0, 0 ) ) );
206  if ( selectedAct && ( selectedAct != activateAction ) ) {
207  int y = minYear;
208  for ( int i=0; i < years; ++i ) {
209  if ( act[i] == selectedAct ) {
210  year = y;
211  }
212  y++;
213  }
214  }
215  qDeleteAll( act );
216  act.clear();
217  delete menu;
218 
219  if ( year > 0 ) {
220  emit yearSelected( year );
221  }
222 }
223 
224 QToolButton *NavigatorBar::createNavigationButton( const QString &icon,
225  const QString &toolTip,
226  const QString &whatsThis )
227 {
228  QToolButton *button = new QToolButton( this );
229 
230  button->setIcon(
231  KIconLoader::global()->loadIcon( icon, KIconLoader::Desktop, KIconLoader::SizeSmall ) );
232  button->setIconSize( QSize( KIconLoader::SizeSmall, KIconLoader::SizeSmall ) );
233  button->setToolButtonStyle( Qt::ToolButtonIconOnly );
234  button->setAutoRaise( true );
235  button->setToolTip( toolTip );
236  button->setWhatsThis( whatsThis );
237 
238  return button;
239 }
240 
241 #include "navigatorbar.moc"
koglobals.h
navigatorbar.h
NavigatorBar::yearSelected
void yearSelected(int year)
QWidget
NavigatorBar::prevYearClicked
void prevYearClicked()
NavigatorBar::NavigatorBar
NavigatorBar(QWidget *parent=0)
Definition: navigatorbar.cpp:35
NavigatorBar::selectDates
void selectDates(const KCalCore::DateList &)
Definition: navigatorbar.cpp:124
NavigatorBar::createNavigationButton
QToolButton * createNavigationButton(const QString &icon, const QString &toolTip, const QString &whatsThis)
Definition: navigatorbar.cpp:224
KOGlobals::calendarSystem
const KCalendarSystem * calendarSystem() const
Definition: koglobals.cpp:65
KOGlobals::self
static KOGlobals * self()
Definition: koglobals.cpp:43
QMenu
KOGlobals::reverseLayout
static bool reverseLayout()
Definition: koglobals.cpp:70
NavigatorBar::showButtons
void showButtons(bool left, bool right)
Definition: navigatorbar.cpp:105
NavigatorBar::nextYearClicked
void nextYearClicked()
NavigatorBar::prevMonthClicked
void prevMonthClicked()
NavigatorBar::monthSelected
void monthSelected(int month)
NavigatorBar::~NavigatorBar
~NavigatorBar()
Definition: navigatorbar.cpp:101
NavigatorBar::nextMonthClicked
void nextMonthClicked()
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

Skip menu "korganizer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal