qcalendarwidget.h
上传用户:detong
上传日期:2022-06-22
资源大小:20675k
文件大小:7k
源码类别:

系统编程

开发平台:

Unix_Linux

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  4. ** Contact: Qt Software Information (qt-info@nokia.com)
  5. **
  6. ** This file is part of the QtGui module of the Qt Toolkit.
  7. **
  8. ** Commercial Usage
  9. ** Licensees holding valid Qt Commercial licenses may use this file in
  10. ** accordance with the Qt Commercial License Agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and Nokia.
  13. **
  14. **
  15. ** GNU General Public License Usage
  16. ** Alternatively, this file may be used under the terms of the GNU
  17. ** General Public License versions 2.0 or 3.0 as published by the Free
  18. ** Software Foundation and appearing in the file LICENSE.GPL included in
  19. ** the packaging of this file.  Please review the following information
  20. ** to ensure GNU General Public Licensing requirements will be met:
  21. ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
  22. ** http://www.gnu.org/copyleft/gpl.html.  In addition, as a special
  23. ** exception, Nokia gives you certain additional rights. These rights
  24. ** are described in the Nokia Qt GPL Exception version 1.3, included in
  25. ** the file GPL_EXCEPTION.txt in this package.
  26. **
  27. ** Qt for Windows(R) Licensees
  28. ** As a special exception, Nokia, as the sole copyright holder for Qt
  29. ** Designer, grants users of the Qt/Eclipse Integration plug-in the
  30. ** right for the Qt/Eclipse Integration to link to functionality
  31. ** provided by Qt Designer and its related libraries.
  32. **
  33. ** If you are unsure which license is appropriate for your use, please
  34. ** contact the sales department at qt-sales@nokia.com.
  35. **
  36. ****************************************************************************/
  37. #ifndef QCALENDARWIDGET_H
  38. #define QCALENDARWIDGET_H
  39. #include <QtGui/qwidget.h>
  40. #include <QtCore/qdatetime.h>
  41. QT_BEGIN_HEADER
  42. QT_BEGIN_NAMESPACE
  43. QT_MODULE(Gui)
  44. #ifndef QT_NO_CALENDARWIDGET
  45. class QDate;
  46. class QTextCharFormat;
  47. class QCalendarWidgetPrivate;
  48. class Q_GUI_EXPORT QCalendarWidget : public QWidget
  49. {
  50.     Q_OBJECT
  51.     Q_ENUMS(Qt::DayOfWeek)
  52.     Q_ENUMS(HorizontalHeaderFormat)
  53.     Q_ENUMS(VerticalHeaderFormat)
  54.     Q_ENUMS(SelectionMode)
  55.     Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate)
  56.     Q_PROPERTY(QDate minimumDate READ minimumDate WRITE setMinimumDate)
  57.     Q_PROPERTY(QDate maximumDate READ maximumDate WRITE setMaximumDate)
  58.     Q_PROPERTY(Qt::DayOfWeek firstDayOfWeek READ firstDayOfWeek WRITE setFirstDayOfWeek)
  59.     Q_PROPERTY(bool gridVisible READ isGridVisible WRITE setGridVisible)
  60.     Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
  61.     Q_PROPERTY(HorizontalHeaderFormat horizontalHeaderFormat READ horizontalHeaderFormat WRITE setHorizontalHeaderFormat)
  62.     Q_PROPERTY(VerticalHeaderFormat verticalHeaderFormat READ verticalHeaderFormat WRITE setVerticalHeaderFormat)
  63.     Q_PROPERTY(bool headerVisible READ isHeaderVisible WRITE setHeaderVisible STORED false DESIGNABLE false) // obsolete
  64.     Q_PROPERTY(bool navigationBarVisible READ isNavigationBarVisible WRITE setNavigationBarVisible)
  65.     Q_PROPERTY(bool dateEditEnabled READ isDateEditEnabled WRITE setDateEditEnabled)
  66.     Q_PROPERTY(int dateEditAcceptDelay READ dateEditAcceptDelay WRITE setDateEditAcceptDelay)
  67. public:
  68.     enum HorizontalHeaderFormat {
  69.         NoHorizontalHeader,
  70.         SingleLetterDayNames,
  71.         ShortDayNames,
  72.         LongDayNames
  73.     };
  74.     enum VerticalHeaderFormat {
  75.         NoVerticalHeader,
  76.         ISOWeekNumbers
  77.     };
  78.     enum SelectionMode {
  79.         NoSelection,
  80.         SingleSelection
  81.     };
  82.     explicit QCalendarWidget(QWidget *parent = 0);
  83.     ~QCalendarWidget();
  84.     virtual QSize sizeHint() const;
  85.     virtual QSize minimumSizeHint() const;
  86.     QDate selectedDate() const;
  87.     int yearShown() const;
  88.     int monthShown() const;
  89.     QDate minimumDate() const;
  90.     void setMinimumDate(const QDate &date);
  91.     QDate maximumDate() const;
  92.     void setMaximumDate(const QDate &date);
  93.     Qt::DayOfWeek firstDayOfWeek() const;
  94.     void setFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
  95.     // ### Qt 5: eliminate these two
  96.     bool isHeaderVisible() const;
  97.     void setHeaderVisible(bool show); 
  98.     inline bool isNavigationBarVisible() const { return isHeaderVisible(); }
  99.     bool isGridVisible() const;
  100.     SelectionMode selectionMode() const;
  101.     void setSelectionMode(SelectionMode mode);
  102.     HorizontalHeaderFormat horizontalHeaderFormat() const;
  103.     void setHorizontalHeaderFormat(HorizontalHeaderFormat format);
  104.     VerticalHeaderFormat verticalHeaderFormat() const;
  105.     void setVerticalHeaderFormat(VerticalHeaderFormat format);
  106.     QTextCharFormat headerTextFormat() const;
  107.     void setHeaderTextFormat(const QTextCharFormat &format);
  108.     QTextCharFormat weekdayTextFormat(Qt::DayOfWeek dayOfWeek) const;
  109.     void setWeekdayTextFormat(Qt::DayOfWeek dayOfWeek, const QTextCharFormat &format);
  110.     QMap<QDate, QTextCharFormat> dateTextFormat() const;
  111.     QTextCharFormat dateTextFormat(const QDate &date) const;
  112.     void setDateTextFormat(const QDate &date, const QTextCharFormat &format);
  113.     bool isDateEditEnabled() const;
  114.     void setDateEditEnabled(bool enable);
  115.     int dateEditAcceptDelay() const;
  116.     void setDateEditAcceptDelay(int delay);
  117. protected:
  118.     bool event(QEvent *event);
  119.     void mousePressEvent(QMouseEvent *event);
  120.     void resizeEvent(QResizeEvent * event);
  121.     void keyPressEvent(QKeyEvent * event);
  122.     virtual void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const;
  123.     void updateCell(const QDate &date);
  124.     void updateCells();
  125. public Q_SLOTS:
  126.     void setSelectedDate(const QDate &date);
  127.     void setDateRange(const QDate &min, const QDate &max);
  128.     void setCurrentPage(int year, int month);
  129.     void setGridVisible(bool show);
  130.     void setNavigationBarVisible(bool visible);
  131.     void showNextMonth();
  132.     void showPreviousMonth();
  133.     void showNextYear();
  134.     void showPreviousYear();
  135.     void showSelectedDate();
  136.     void showToday();
  137. Q_SIGNALS:
  138.     void selectionChanged();
  139.     void clicked(const QDate &date);
  140.     void activated(const QDate &date);
  141.     void currentPageChanged(int year, int month);
  142. private:
  143.     Q_DECLARE_PRIVATE(QCalendarWidget)
  144.     Q_DISABLE_COPY(QCalendarWidget)
  145.     Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date))
  146.     Q_PRIVATE_SLOT(d_func(), void _q_slotChangeDate(const QDate &date, bool changeMonth))
  147.     Q_PRIVATE_SLOT(d_func(), void _q_editingFinished())
  148.     Q_PRIVATE_SLOT(d_func(), void _q_prevMonthClicked())
  149.     Q_PRIVATE_SLOT(d_func(), void _q_nextMonthClicked())
  150.     Q_PRIVATE_SLOT(d_func(), void _q_yearEditingFinished())
  151.     Q_PRIVATE_SLOT(d_func(), void _q_yearClicked())
  152.     Q_PRIVATE_SLOT(d_func(), void _q_monthChanged(QAction *act))
  153. };
  154. #endif // QT_NO_CALENDARWIDGET
  155. QT_END_NAMESPACE
  156. QT_END_HEADER
  157. #endif // QCALENDARWIDGET_H