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

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • widgets
genericcalendarwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  genericcalendarwidget.cpp - K Desktop Planetarium
3  -------------------
4  begin : Mon Jun 28 2010
5  copyright : (C) 2010 by Akarsh Simha
6  email : akarshsimha@gmail.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "genericcalendarwidget.h"
19 
20 #include <KNotification>
21 #include <KCalendarSystem>
22 
23 #include <kdebug.h>
24 
25 GenericCalendarWidget::GenericCalendarWidget( KDateTable &datetable, QWidget *parent ) : QWidget( parent ), m_DateTable( datetable ) {
26 
27  setupUi( this );
28 
29  m_DateTable.setParent( DateTableFrame ); // Put the date table in the QFrame that's meant to hold it
30 
31  // Set icons for the front / back buttons
32 
33  previousYear->setAutoRaise( true );
34  nextYear->setAutoRaise( true );
35  previousMonth->setAutoRaise( true );
36  nextMonth->setAutoRaise( true );
37  if ( QApplication::isRightToLeft() ) {
38  nextYear->setIcon( KIcon( QLatin1String( "arrow-left-double" ) ) );
39  previousYear->setIcon( KIcon( QLatin1String( "arrow-right-double" ) ) );
40  nextMonth->setIcon( KIcon( QLatin1String( "arrow-left" ) ) );
41  previousMonth->setIcon( KIcon( QLatin1String( "arrow-right" ) ) );
42  } else {
43  nextYear->setIcon( KIcon( QLatin1String( "arrow-right-double" ) ) );
44  previousYear->setIcon( KIcon( QLatin1String( "arrow-left-double" ) ) );
45  nextMonth->setIcon( KIcon( QLatin1String( "arrow-right" ) ) );
46  previousMonth->setIcon( KIcon( QLatin1String( "arrow-left" ) ) );
47  }
48 
49  // Connects
50  connect( &m_DateTable, SIGNAL( dateChanged( const QDate& ) ), SLOT( dateChangedSlot( const QDate& ) ) );
51  connect( nextMonth, SIGNAL( clicked() ), SLOT( nextMonthClicked() ) );
52  connect( previousMonth, SIGNAL( clicked() ), SLOT( previousMonthClicked() ) );
53  connect( nextYear, SIGNAL( clicked() ), SLOT( nextYearClicked() ) );
54  connect( previousYear, SIGNAL( clicked() ), SLOT( previousYearClicked() ) );
55  connect( selectMonth, SIGNAL( activated( int ) ), SLOT( monthChanged( int ) ) );
56  connect( selectYear, SIGNAL( valueChanged( int ) ), SLOT( yearChanged( int ) ) );
57 
58  m_DateTable.setCalendar(); // Set global calendar
59 
60  populateMonthNames();
61 
62  // kDebug() << calendar()->monthName( date(), KCalendarSystem::LongName );
63 
64  selectMonth->setCurrentIndex( date().month() - 1 );
65  selectYear->setValue( date().year() );
66  m_Date = date();
67 
68  show();
69 
70 }
71 
72 const QDate &GenericCalendarWidget::date() const {
73  return m_DateTable.date();
74 }
75 
76 const KCalendarSystem *GenericCalendarWidget::calendar() const {
77  return m_DateTable.calendar();
78 }
79 
80 void GenericCalendarWidget::populateMonthNames() {
81  // Populate the combobox with month names -- can change by year / calendar type
82  selectMonth->clear();
83  for ( int m = 1; m <= calendar()->monthsInYear( date() ); m++ ) {
84  selectMonth->addItem( calendar()->monthName( m, calendar()->year( date() ) ) );
85  }
86 }
87 
88 void GenericCalendarWidget::dateChangedSlot( const QDate &date_ ) {
89  // populateMonthNames(); // Not required for global calendar
90 
91  if( m_Date != date_ ) {
92  // To avoid an infinite loop, we update the year spin box / month combo box only when the date has actually changed.
93  selectMonth->setCurrentIndex( date().month() - 1 );
94  selectYear->setValue( date().year() );
95  m_Date = date_;
96  }
97 
98  kDebug() << "Date = " << m_Date;
99 
100  emit( dateChanged( date_ ) );
101 }
102 
103 void GenericCalendarWidget::nextMonthClicked()
104 {
105  if ( ! setDate( calendar()->addMonths( date(), 1 ) ) ) {
106  KNotification::beep();
107  }
108  m_DateTable.setFocus();
109 }
110 
111 void GenericCalendarWidget::previousMonthClicked()
112 {
113  kDebug() << "Previous month clicked!";
114  if ( ! setDate( calendar()->addMonths( date(), -1 ) ) ) {
115  KNotification::beep();
116  }
117  m_DateTable.setFocus();
118 }
119 
120 void GenericCalendarWidget::nextYearClicked()
121 {
122  if ( ! setDate( calendar()->addYears( date(), 1 ) ) ) {
123  KNotification::beep();
124  }
125  m_DateTable.setFocus();
126 }
127 
128 void GenericCalendarWidget::previousYearClicked()
129 {
130  if ( ! setDate( calendar()->addYears( date(), -1 ) ) ) {
131  KNotification::beep();
132  }
133  m_DateTable.setFocus();
134 }
135 
136 void GenericCalendarWidget::yearChanged( int year ) {
137  if ( ! setYear( year ) ) {
138  KNotification::beep();
139  }
140  m_DateTable.setFocus();
141 }
142 
143 void GenericCalendarWidget::monthChanged( int month ) {
144  kDebug() << "Month = " << month;
145  if ( ! setMonth( month + 1 ) ) {
146  KNotification::beep();
147  }
148  m_DateTable.setFocus();
149 }
150 
151 bool GenericCalendarWidget::setYear( int year ) {
152  return setDate( QDate( year, date().month(), date().day() ) );
153 }
154 
155 bool GenericCalendarWidget::setMonth( int month ) {
156  return setDate( QDate( date().year(), month, date().day() ) );
157 }
158 
159 bool GenericCalendarWidget::setDate( int date_ ) {
160  return setDate( QDate( date().year(), date().month(), date_ ) );
161 }
162 
163 bool GenericCalendarWidget::setDate( const QDate &date_ ) {
164  if( date_ == date() )
165  return true;
166  return m_DateTable.setDate( date_ );
167 }
KDateTable
QWidget
GenericCalendarWidget::setYear
bool setYear(int year)
Set the year.
Definition: genericcalendarwidget.cpp:151
GenericCalendarWidget::date
const QDate & date() const
Returns the selected date.
Definition: genericcalendarwidget.cpp:72
GenericCalendarWidget::setDate
bool setDate(int date_)
Set the selected day of month.
Definition: genericcalendarwidget.cpp:159
GenericCalendarWidget::dateChanged
void dateChanged(const QDate &date_)
Emitted when the date has been changed.
GenericCalendarWidget::GenericCalendarWidget
GenericCalendarWidget(KDateTable &dateTable, QWidget *parent=0)
Constructor.
Definition: genericcalendarwidget.cpp:25
GenericCalendarWidget::setMonth
bool setMonth(int month)
Set the month.
Definition: genericcalendarwidget.cpp:155
genericcalendarwidget.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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