qcalendarwidget.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QCALENDARWIDGET_H
00043 #define QCALENDARWIDGET_H
00044 
00045 #include <QtGui/qwidget.h>
00046 #include <QtCore/qdatetime.h>
00047 
00048 QT_BEGIN_HEADER
00049 
00050 QT_BEGIN_NAMESPACE
00051 
00052 QT_MODULE(Gui)
00053 
00054 #ifndef QT_NO_CALENDARWIDGET
00055 
00056 class QDate;
00057 class QTextCharFormat;
00058 class QCalendarWidgetPrivate;
00059 
00060 class Q_GUI_EXPORT QCalendarWidget : public QWidget
00061 {
00062     Q_OBJECT
00063     Q_ENUMS(Qt::DayOfWeek)
00064     Q_ENUMS(HorizontalHeaderFormat)
00065     Q_ENUMS(VerticalHeaderFormat)
00066     Q_ENUMS(SelectionMode)
00067     Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate)
00068     Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate)
00069     Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate)
00070     Q_PROPERTY(Qt::DayOfWeek firstDayOfWeek READ firstDayOfWeek WRITE setFirstDayOfWeek)
00071     Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
00072     Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
00073     Q_PROPERTY(HorizontalHeaderFormat horizontalHeaderFormat READ horizontalHeaderFormat WRITE setHorizontalHeaderFormat)
00074     Q_PROPERTY(VerticalHeaderFormat verticalHeaderFormat READ verticalHeaderFormat WRITE setVerticalHeaderFormat)
00075     Q_PROPERTY(bool headerVisible READ isHeaderVisible WRITE setHeaderVisible STORED false DESIGNABLE false) // obsolete
00076     Q_PROPERTY(bool navigationBarVisible READ isNavigationBarVisible WRITE setNavigationBarVisible)
00077     Q_PROPERTY(bool dateEditEnabled READ isDateEditEnabled WRITE setDateEditEnabled)
00078     Q_PROPERTY(int dateEditAcceptDelay READ dateEditAcceptDelay WRITE setDateEditAcceptDelay)
00079 
00080 public:
00081     enum HorizontalHeaderFormat {
00082         NoHorizontalHeader,
00083         SingleLetterDayNames,
00084         ShortDayNames,
00085         LongDayNames
00086     };
00087 
00088     enum VerticalHeaderFormat {
00089         NoVerticalHeader,
00090         ISOWeekNumbers
00091     };
00092 
00093     enum SelectionMode {
00094         NoSelection,
00095         SingleSelection
00096     };
00097 
00098     explicit QCalendarWidget(QWidget *parent = 0);
00099     ~QCalendarWidget();
00100 
00101     virtual QSize sizeHint() const;
00102     virtual QSize minimumSizeHint() const;
00103 
00104     QDate selectedDate() const;
00105 
00106     int yearShown() const;
00107     int monthShown() const;
00108 
00109     QDate minimumDate() const;
00110     void setMinimumDate(const QDate &date);
00111 
00112     QDate maximumDate() const;
00113     void setMaximumDate(const QDate &date);
00114 
00115     Qt::DayOfWeek firstDayOfWeek() const;
00116     void setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
00117 
00118     // ### Qt 5: eliminate these two
00119     bool isHeaderVisible() const;
00120     void setHeaderVisible(bool show); 
00121 
00122     inline bool isNavigationBarVisible() const { return isHeaderVisible(); }
00123 
00124     bool isGridVisible() const;
00125 
00126     SelectionMode selectionMode() const;
00127     void setSelectionMode(SelectionMode mode);
00128 
00129     HorizontalHeaderFormat horizontalHeaderFormat() const;
00130     void setHorizontalHeaderFormat(HorizontalHeaderFormat format);
00131 
00132     VerticalHeaderFormat verticalHeaderFormat() const;
00133     void setVerticalHeaderFormat(VerticalHeaderFormat format);
00134 
00135     QTextCharFormat headerTextFormat() const;
00136     void setHeaderTextFormat(const QTextCharFormat &format);
00137 
00138     QTextCharFormat weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const;
00139     void setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format);
00140 
00141     QMap<QDate, QTextCharFormat> dateTextFormat() const;
00142     QTextCharFormat dateTextFormat(const QDate &date) const;
00143     void setDateTextFormat(const QDate &date, const QTextCharFormat &format);
00144 
00145     bool isDateEditEnabled() const;
00146     void setDateEditEnabled(bool enable);
00147 
00148     int dateEditAcceptDelay() const;
00149     void setDateEditAcceptDelay(int delay);
00150 
00151 protected:
00152     bool event(QEvent *event);
00153     bool eventFilter(QObject *watched, QEvent *event);
00154     void mousePressEvent(QMouseEvent *event);
00155     void resizeEvent(QResizeEvent * event);
00156     void keyPressEvent(QKeyEvent * event);
00157 
00158     virtual void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const;
00159     void updateCell(const QDate &date);
00160     void updateCells();
00161 
00162 public Q_SLOTS:
00163     void setSelectedDate(const QDate &date);
00164     void setDateRange(const QDate &min, const QDate &max);
00165     void setCurrentPage(int year, int month);
00166     void setGridVisible(bool show);
00167     void setNavigationBarVisible(bool visible);
00168     void showNextMonth();
00169     void showPreviousMonth();
00170     void showNextYear();
00171     void showPreviousYear();
00172     void showSelectedDate();
00173     void showToday();
00174 
00175 Q_SIGNALS:
00176     void selectionChanged();
00177     void clicked(const QDate &date);
00178     void activated(const QDate &date);
00179     void currentPageChanged(int year, int month);
00180 
00181 private:
00182     Q_DECLARE_PRIVATE(QCalendarWidget)
00183     Q_DISABLE_COPY(QCalendarWidget)
00184 
00185     Q_PRIVATE_SLOT(d_func(), void _q_slotShowDate(const QDate &date))
00186     Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date))
00187     Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date, bool changeMonth))
00188     Q_PRIVATE_SLOT(d_func(), void _q_editingFinished())
00189     Q_PRIVATE_SLOT(d_func(), void _q_prevMonthClicked())
00190     Q_PRIVATE_SLOT(d_func(), void _q_nextMonthClicked())
00191     Q_PRIVATE_SLOT(d_func(), void _q_yearEditingFinished())
00192     Q_PRIVATE_SLOT(d_func(), void _q_yearClicked())
00193     Q_PRIVATE_SLOT(d_func(), void _q_monthChanged(QAction *act))
00194 
00195 };
00196 
00197 #endif // QT_NO_CALENDARWIDGET
00198 
00199 QT_END_NAMESPACE
00200 
00201 QT_END_HEADER
00202 
00203 #endif // QCALENDARWIDGET_H
00204