Qt 4.8
qdatetimeedit_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QDATETIMEEDIT_P_H
43 #define QDATETIMEEDIT_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "QtGui/qcombobox.h"
57 #include "QtGui/qcalendarwidget.h"
58 #include "QtGui/qspinbox.h"
59 #include "QtGui/qtoolbutton.h"
60 #include "QtGui/qmenu.h"
61 #include "QtGui/qlabel.h"
62 #include "QtGui/qdatetimeedit.h"
63 #include "QtGui/private/qabstractspinbox_p.h"
64 #include "QtCore/private/qdatetime_p.h"
65 
66 #include "qdebug.h"
67 
68 #ifndef QT_NO_DATETIMEEDIT
69 
71 
72 class QCalendarPopup;
74 {
76 public:
78 
79  void init(const QVariant &var);
80  void readLocaleSettings();
81 
82  void emitSignals(EmitPolicy ep, const QVariant &old);
83  QString textFromValue(const QVariant &f) const;
84  QVariant valueFromText(const QString &f) const;
85  virtual void _q_editorCursorPositionChanged(int oldpos, int newpos);
86  virtual void interpret(EmitPolicy ep);
87  virtual void clearCache() const;
88 
90  bool fixup = false) const;
91  void clearSection(int index);
92  virtual QString displayText() const { return edit->text(); } // this is from QDateTimeParser
93 
94  int absoluteIndex(QDateTimeEdit::Section s, int index) const;
95  int absoluteIndex(const SectionNode &s) const;
96  void updateEdit();
97  QDateTime stepBy(int index, int steps, bool test = false) const;
98  int sectionAt(int pos) const;
99  int closestSection(int index, bool forward) const;
100  int nextPrevSection(int index, bool forward) const;
101  void setSelected(int index, bool forward = false);
102 
103  void updateCache(const QVariant &val, const QString &str) const;
104 
105  void updateTimeSpec();
106  virtual QDateTime getMinimum() const { return minimum.toDateTime(); }
107  virtual QDateTime getMaximum() const { return maximum.toDateTime(); }
108  virtual QLocale locale() const { return q_func()->locale(); }
109  QString valueToText(const QVariant &var) const { return textFromValue(var); }
110  QString getAmPmText(AmPm ap, Case cs) const;
111  int cursorPosition() const { return edit ? edit->cursorPosition() : -1; }
112 
113  virtual QStyle::SubControl newHoverControl(const QPoint &pos);
114  virtual void updateEditFieldGeometry();
115  virtual QVariant getZeroVariant() const;
116  virtual void setRange(const QVariant &min, const QVariant &max);
117 
118  void _q_resetButton();
119  void updateArrow(QStyle::StateFlag state);
120  bool calendarPopupEnabled() const;
121  void syncCalendarWidget();
122 
123  bool isSeparatorKey(const QKeyEvent *k) const;
124 
125  static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s);
127 
128  void initCalendarPopup(QCalendarWidget *cw = 0);
129  void positionCalendarPopup();
130 
131  QDateTimeEdit::Sections sections;
132  mutable bool cacheGuard;
133 
139 
140 #ifdef QT_KEYPAD_NAVIGATION
141  bool focusOnButton;
142 #endif
143 };
144 
145 
146 class QCalendarPopup : public QWidget
147 {
148  Q_OBJECT
149 public:
151  QDate selectedDate() { return verifyCalendarInstance()->selectedDate(); }
152  void setDate(const QDate &date);
153  void setDateRange(const QDate &min, const QDate &max);
154  void setFirstDayOfWeek(Qt::DayOfWeek dow) { verifyCalendarInstance()->setFirstDayOfWeek(dow); }
155  QCalendarWidget *calendarWidget() const { return const_cast<QCalendarPopup*>(this)->verifyCalendarInstance(); }
156  void setCalendarWidget(QCalendarWidget *cw);
157 Q_SIGNALS:
158  void activated(const QDate &date);
159  void newDateSelected(const QDate &newDate);
160  void hidingCalendar(const QDate &oldDate);
161  void resetButton();
162 
163 private Q_SLOTS:
164  void dateSelected(const QDate &date);
165  void dateSelectionChanged();
166 
167 protected:
168  void hideEvent(QHideEvent *);
169  void mousePressEvent(QMouseEvent *e);
170  void mouseReleaseEvent(QMouseEvent *);
171  bool event(QEvent *e);
172 
173 private:
174  QCalendarWidget *verifyCalendarInstance();
175 
179 };
180 
182 
183 #endif // QT_NO_DATETIMEEDIT
184 
185 #endif // QDATETIMEEDIT_P_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QString getAmPmText(AmPm ap, Case cs) const
QCalendarWidget * calendarWidget() const
The QKeyEvent class describes a key event.
Definition: qevent.h:224
virtual void updateEditFieldGeometry()
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual QLocale locale() const
QDateTime validateAndInterpret(QString &input, int &, QValidator::State &state, bool fixup=false) const
EventRef event
QStyle::StateFlag arrowState
QDateTime stepBy(int index, int steps, bool test=false) const
Internal function called by QDateTimeEdit::stepBy().
void setSelected(int index, bool forward=false)
Selects the section s.
void init()
Initialises the QAbstractSpinBoxPrivate object.
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date...
EmitPolicy
void clearSection(int index)
Clears the text of section s.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
QDateTimeEdit::Sections sections
void setFirstDayOfWeek(Qt::DayOfWeek dow)
void updateArrow(QStyle::StateFlag state)
The QDate class provides date functions.
Definition: qdatetime.h:55
virtual QString displayText() const
QString textFromValue(const QVariant &f) const
bool isSeparatorKey(const QKeyEvent *k) const
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
DayOfWeek
Definition: qnamespace.h:1410
static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s)
#define Q_SIGNALS
Definition: qobjectdefs.h:72
int nextPrevSection(int index, bool forward) const
Returns a copy of the section that is before or after current, depending on forward.
The QDateTimeEdit class provides a widget for editing dates and times.
Definition: qdatetimeedit.h:61
void emitSignals(EmitPolicy ep, const QVariant &old)
static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section s)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual QVariant getZeroVariant() const
Convenience function to get a variant of the right type.
void initCalendarPopup(QCalendarWidget *cw=0)
QString text
the line edit&#39;s text
Definition: qlineedit.h:72
virtual void setRange(const QVariant &min, const QVariant &max)
Convenience function to set min/max values.
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
bool calendarPopupEnabled() const
int absoluteIndex(QDateTimeEdit::Section s, int index) const
virtual void interpret(EmitPolicy ep)
Interprets text and emits signals.
virtual void _q_editorCursorPositionChanged(int oldpos, int newpos)
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
virtual QStyle::SubControl newHoverControl(const QPoint &pos)
Returns the hover control at pos.
void updateEdit()
Updates the line edit to reflect the current value of the spin box.
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual QDateTime getMaximum() const
State
This enum type defines the states in which a validated string can exist.
Definition: qvalidator.h:67
virtual void clearCache() const
quint16 index
QObject * parent
Definition: qobject.h:92
QCalendarPopup * monthCalendar
int sectionAt(int pos) const
Returns the section at index index or NoSection if there are no sections there.
QWeakPointer< QCalendarWidget > calendar
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
StateFlag
This enum describes flags that are used when drawing primitive elements.
Definition: qstyle.h:103
QVariant valueFromText(const QString &f) const
This function&#39;s name is slightly confusing; it is not to be confused with QAbstractSpinBox::valueFrom...
int cursorPosition
the current cursor position for this line edit
Definition: qlineedit.h:77
void updateCache(const QVariant &val, const QString &str) const
virtual QDateTime getMinimum() const
QString valueToText(const QVariant &var) const
int closestSection(int index, bool forward) const
Returns the closest section of index index.
int cursorPosition() const