author | zautrix <zautrix> | 2005-04-14 17:48:58 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-14 17:48:58 (UTC) |
commit | bbdca90c599aaea557d31552c6bc33fc15e397cd (patch) (unidiff) | |
tree | e41b5eb16239664d2217e5436db61610099b60ef /libkdepim | |
parent | 5ea16ef9058a21016402dd5affc0a7f82857e606 (diff) | |
download | kdepimpi-bbdca90c599aaea557d31552c6bc33fc15e397cd.zip kdepimpi-bbdca90c599aaea557d31552c6bc33fc15e397cd.tar.gz kdepimpi-bbdca90c599aaea557d31552c6bc33fc15e397cd.tar.bz2 |
today added
-rw-r--r-- | libkdepim/kdateedit.cpp | 9 | ||||
-rw-r--r-- | libkdepim/kdateedit.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp index 3d9e690..bf38479 100644 --- a/libkdepim/kdateedit.cpp +++ b/libkdepim/kdateedit.cpp | |||
@@ -23,160 +23,169 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include <qapplication.h> | 25 | #include <qapplication.h> |
26 | #include <qevent.h> | 26 | #include <qevent.h> |
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qpixmap.h> | 28 | #include <qpixmap.h> |
29 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
30 | 30 | ||
31 | #include <kdatepicker.h> | 31 | #include <kdatepicker.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kglobal.h> | 33 | #include <kglobal.h> |
34 | #include <kiconloader.h> | 34 | #include <kiconloader.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | #include <kmessagebox.h> | 36 | #include <kmessagebox.h> |
37 | #include <knotifyclient.h> | 37 | #include <knotifyclient.h> |
38 | #include <qpalette.h> | 38 | #include <qpalette.h> |
39 | 39 | ||
40 | #include "kdateedit.h" | 40 | #include "kdateedit.h" |
41 | //#include "kdateedit.moc" | 41 | //#include "kdateedit.moc" |
42 | 42 | ||
43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) | 43 | KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) |
44 | : QHBox(parent, name) | 44 | : QHBox(parent, name) |
45 | { | 45 | { |
46 | dateFormShort = true; | 46 | dateFormShort = true; |
47 | withoutDp = withoutDP; | 47 | withoutDp = withoutDP; |
48 | mDateEdit = new QLineEdit(this); | 48 | mDateEdit = new QLineEdit(this); |
49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); | 49 | mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); |
50 | setFocusProxy(mDateEdit); | 50 | setFocusProxy(mDateEdit); |
51 | mDateEdit->installEventFilter(this); | 51 | mDateEdit->installEventFilter(this); |
52 | 52 | ||
53 | // Highlight Background and Textcolor | 53 | // Highlight Background and Textcolor |
54 | QPalette palette = QWidget::palette(); | 54 | QPalette palette = QWidget::palette(); |
55 | unsigned char red, green, blue; | 55 | unsigned char red, green, blue; |
56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; | 56 | red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; |
57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; | 57 | green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; |
58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; | 58 | blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; |
59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); | 59 | palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); |
60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); | 60 | palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); |
61 | mDateEdit->setPalette( palette ); | 61 | mDateEdit->setPalette( palette ); |
62 | 62 | ||
63 | if ( withoutDP ) { | 63 | if ( withoutDP ) { |
64 | mDateFrame = 0; | 64 | mDateFrame = 0; |
65 | mDateButton = 0; | 65 | mDateButton = 0; |
66 | mDatePicker = 0; | 66 | mDatePicker = 0; |
67 | } else { | 67 | } else { |
68 | QPixmap pixmap = SmallIcon("smallcal"); | 68 | QPixmap pixmap = SmallIcon("smallcal"); |
69 | mDateButton = new QPushButton(this); | 69 | mDateButton = new QPushButton(this); |
70 | mDateButton->setPixmap(pixmap); | 70 | mDateButton->setPixmap(pixmap); |
71 | QPixmap pixmap2 = SmallIcon("today_small"); | ||
72 | QPushButton* nowButton = new QPushButton(this); | ||
73 | nowButton->setPixmap(pixmap2); | ||
71 | 74 | ||
72 | mDateFrame = new QVBox(0,0,WType_Popup); | 75 | mDateFrame = new QVBox(0,0,WType_Popup); |
73 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 76 | // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
74 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 77 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
75 | mDateFrame->setLineWidth(3); | 78 | mDateFrame->setLineWidth(3); |
76 | mDateFrame->hide(); | 79 | mDateFrame->hide(); |
77 | 80 | ||
78 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); | 81 | mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); |
79 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); | 82 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); |
80 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); | 83 | connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); |
81 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); | 84 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); |
82 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); | 85 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); |
83 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); | 86 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); |
84 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); | 87 | connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); |
88 | connect(nowButton,SIGNAL(clicked()),SLOT(goToNow())); | ||
85 | mDateButton->setFocusPolicy( QWidget::NoFocus ); | 89 | mDateButton->setFocusPolicy( QWidget::NoFocus ); |
86 | mDateButton->setAutoDefault( false ); | 90 | mDateButton->setAutoDefault( false ); |
87 | //mDateFrame->resize( 400, 300 ); | 91 | //mDateFrame->resize( 400, 300 ); |
88 | 92 | ||
89 | } | 93 | } |
90 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); | 94 | connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); |
91 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), | 95 | connect(mDateEdit,SIGNAL(textChanged(const QString &)), |
92 | SLOT(textChanged(const QString &))); | 96 | SLOT(textChanged(const QString &))); |
93 | 97 | ||
94 | // Create the keyword list. This will be used to match against when the user | 98 | // Create the keyword list. This will be used to match against when the user |
95 | // enters information. | 99 | // enters information. |
96 | mKeywordMap[i18n("tomorrow")] = 1; | 100 | mKeywordMap[i18n("tomorrow")] = 1; |
97 | mKeywordMap[i18n("today")] = 0; | 101 | mKeywordMap[i18n("today")] = 0; |
98 | mKeywordMap[i18n("yesterday")] = -1; | 102 | mKeywordMap[i18n("yesterday")] = -1; |
99 | 103 | ||
100 | /* | 104 | /* |
101 | * This loop uses some math tricks to figure out the offset in days | 105 | * This loop uses some math tricks to figure out the offset in days |
102 | * to the next date the given day of the week occurs. There | 106 | * to the next date the given day of the week occurs. There |
103 | * are two cases, that the new day is >= the current day, which means | 107 | * are two cases, that the new day is >= the current day, which means |
104 | * the new day has not occured yet or that the new day < the current day, | 108 | * the new day has not occured yet or that the new day < the current day, |
105 | * which means the new day is already passed (so we need to find the | 109 | * which means the new day is already passed (so we need to find the |
106 | * day in the next week). | 110 | * day in the next week). |
107 | */ | 111 | */ |
108 | QString dayName; | 112 | QString dayName; |
109 | int currentDay = QDate::currentDate().dayOfWeek(); | 113 | int currentDay = QDate::currentDate().dayOfWeek(); |
110 | for (int i = 1; i <= 7; ++i) | 114 | for (int i = 1; i <= 7; ++i) |
111 | { | 115 | { |
112 | dayName = KGlobal::locale()->weekDayName(i).lower(); | 116 | dayName = KGlobal::locale()->weekDayName(i).lower(); |
113 | if (i >= currentDay) | 117 | if (i >= currentDay) |
114 | mKeywordMap[dayName] = i - currentDay; | 118 | mKeywordMap[dayName] = i - currentDay; |
115 | else | 119 | else |
116 | mKeywordMap[dayName] = 7 - currentDay + i; | 120 | mKeywordMap[dayName] = 7 - currentDay + i; |
117 | } | 121 | } |
118 | 122 | ||
119 | mTextChanged = false; | 123 | mTextChanged = false; |
120 | mHandleInvalid = false; | 124 | mHandleInvalid = false; |
121 | // QWidget::setTabOrder( mDateEdit, mDateButton ); | 125 | // QWidget::setTabOrder( mDateEdit, mDateButton ); |
122 | } | 126 | } |
123 | 127 | ||
124 | KDateEdit::~KDateEdit() | 128 | KDateEdit::~KDateEdit() |
125 | { | 129 | { |
126 | delete mDateFrame; | 130 | delete mDateFrame; |
127 | } | 131 | } |
128 | void KDateEdit::clear() | 132 | void KDateEdit::clear() |
129 | { | 133 | { |
130 | bool b = mDateEdit->signalsBlocked(); | 134 | bool b = mDateEdit->signalsBlocked(); |
131 | mDateEdit->blockSignals(true); | 135 | mDateEdit->blockSignals(true); |
132 | mDateEdit->setText(""); | 136 | mDateEdit->setText(""); |
133 | mDateEdit->blockSignals(b); | 137 | mDateEdit->blockSignals(b); |
134 | } | 138 | } |
139 | void KDateEdit::goToNow() | ||
140 | { | ||
141 | setDate(QDate::currentDate() ); | ||
142 | emit setTimeTo( QTime::currentTime() ); | ||
143 | } | ||
135 | void KDateEdit::setDate(QDate newDate) | 144 | void KDateEdit::setDate(QDate newDate) |
136 | { | 145 | { |
137 | if (!newDate.isValid() && !mHandleInvalid) | 146 | if (!newDate.isValid() && !mHandleInvalid) |
138 | return; | 147 | return; |
139 | if ( readDate() == newDate ) | 148 | if ( readDate() == newDate ) |
140 | return; | 149 | return; |
141 | QString dateString = ""; | 150 | QString dateString = ""; |
142 | if(newDate.isValid()) | 151 | if(newDate.isValid()) |
143 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); | 152 | dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); |
144 | 153 | ||
145 | mTextChanged = false; | 154 | mTextChanged = false; |
146 | 155 | ||
147 | // We do not want to generate a signal here, since we explicity setting | 156 | // We do not want to generate a signal here, since we explicity setting |
148 | // the date | 157 | // the date |
149 | bool b = mDateEdit->signalsBlocked(); | 158 | bool b = mDateEdit->signalsBlocked(); |
150 | mDateEdit->blockSignals(true); | 159 | mDateEdit->blockSignals(true); |
151 | mDateEdit->setText(dateString); | 160 | mDateEdit->setText(dateString); |
152 | mDateEdit->blockSignals(b); | 161 | mDateEdit->blockSignals(b); |
153 | } | 162 | } |
154 | 163 | ||
155 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) | 164 | void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) |
156 | { | 165 | { |
157 | QString dateForm = dateFormShort ? | 166 | QString dateForm = dateFormShort ? |
158 | KGlobal::locale()->dateFormatShort() : | 167 | KGlobal::locale()->dateFormatShort() : |
159 | KGlobal::locale()->dateFormat(); | 168 | KGlobal::locale()->dateFormat(); |
160 | 169 | ||
161 | int begin = dateForm.find("%"); | 170 | int begin = dateForm.find("%"); |
162 | int space = 0; | 171 | int space = 0; |
163 | int allStrLength = 0; | 172 | int allStrLength = 0; |
164 | int strLength = 0; | 173 | int strLength = 0; |
165 | int repeat = 0; | 174 | int repeat = 0; |
166 | 175 | ||
167 | // witch? Day, Month or Year switch? | 176 | // witch? Day, Month or Year switch? |
168 | while(1){ | 177 | while(1){ |
169 | switch ( dateForm.at(begin + 1).latin1() ) | 178 | switch ( dateForm.at(begin + 1).latin1() ) |
170 | { | 179 | { |
171 | case 'd':// 16 (month day) | 180 | case 'd':// 16 (month day) |
172 | strLength = 2; //Ok | 181 | strLength = 2; //Ok |
173 | break; | 182 | break; |
174 | case 'm':// 01 (month) | 183 | case 'm':// 01 (month) |
175 | strLength = 2; //Ok | 184 | strLength = 2; //Ok |
176 | break; | 185 | break; |
177 | case 'a':// Mon (Weekday) | 186 | case 'a':// Mon (Weekday) |
178 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); | 187 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); |
179 | break; | 188 | break; |
180 | case 'A':// Monday (Weekday) | 189 | case 'A':// Monday (Weekday) |
181 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); | 190 | strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); |
182 | break; | 191 | break; |
diff --git a/libkdepim/kdateedit.h b/libkdepim/kdateedit.h index cf3b90a..2d8c452 100644 --- a/libkdepim/kdateedit.h +++ b/libkdepim/kdateedit.h | |||
@@ -42,100 +42,102 @@ class KDateValidator; | |||
42 | * and the push button will display a 'popup' style date picker. | 42 | * and the push button will display a 'popup' style date picker. |
43 | * | 43 | * |
44 | * This widget also supports advanced features like allowing the user | 44 | * This widget also supports advanced features like allowing the user |
45 | * to type in the day name to get the date. The following keywords | 45 | * to type in the day name to get the date. The following keywords |
46 | * are supported (in the native language): tomorrow, yesturday, today, | 46 | * are supported (in the native language): tomorrow, yesturday, today, |
47 | * monday, tuesday, wednesday, thursday, friday, saturday, sunday. | 47 | * monday, tuesday, wednesday, thursday, friday, saturday, sunday. |
48 | * | 48 | * |
49 | * @author Cornelius Schumacher <schumacher@kde.org> | 49 | * @author Cornelius Schumacher <schumacher@kde.org> |
50 | * @author Mike Pilone <mpilone@slac.com> | 50 | * @author Mike Pilone <mpilone@slac.com> |
51 | */ | 51 | */ |
52 | class KDateEdit : public QHBox | 52 | class KDateEdit : public QHBox |
53 | { | 53 | { |
54 | Q_OBJECT | 54 | Q_OBJECT |
55 | public: | 55 | public: |
56 | KDateEdit(QWidget *parent=0, const char *name=0, bool withoutDP = false ); | 56 | KDateEdit(QWidget *parent=0, const char *name=0, bool withoutDP = false ); |
57 | virtual ~KDateEdit(); | 57 | virtual ~KDateEdit(); |
58 | 58 | ||
59 | /** @return True if the date in the text edit is valid, | 59 | /** @return True if the date in the text edit is valid, |
60 | * false otherwise. This will not modify the display of the date, | 60 | * false otherwise. This will not modify the display of the date, |
61 | * but only check for validity. | 61 | * but only check for validity. |
62 | */ | 62 | */ |
63 | bool inputIsValid(); | 63 | bool inputIsValid(); |
64 | 64 | ||
65 | /** @return The date entered. This will not | 65 | /** @return The date entered. This will not |
66 | * modify the display of the date, but only return it. | 66 | * modify the display of the date, but only return it. |
67 | */ | 67 | */ |
68 | QDate date() const; | 68 | QDate date() const; |
69 | 69 | ||
70 | /** @param handleInvalid If true the date edit accepts invalid dates | 70 | /** @param handleInvalid If true the date edit accepts invalid dates |
71 | * and displays them as the empty ("") string. It also returns an invalid date. | 71 | * and displays them as the empty ("") string. It also returns an invalid date. |
72 | * If false (default) invalid dates are not accepted and instead the date | 72 | * If false (default) invalid dates are not accepted and instead the date |
73 | * of today will be returned. | 73 | * of today will be returned. |
74 | */ | 74 | */ |
75 | void setHandleInvalid(bool handleInvalid); | 75 | void setHandleInvalid(bool handleInvalid); |
76 | 76 | ||
77 | /** Checks for a focus out event. The display of the date is updated | 77 | /** Checks for a focus out event. The display of the date is updated |
78 | * to display the proper date when the focus leaves. | 78 | * to display the proper date when the focus leaves. |
79 | */ | 79 | */ |
80 | virtual bool eventFilter(QObject *o, QEvent *e); | 80 | virtual bool eventFilter(QObject *o, QEvent *e); |
81 | void toggleDateFormat(); | 81 | void toggleDateFormat(); |
82 | void clear(); | 82 | void clear(); |
83 | signals: | 83 | signals: |
84 | /** This signal is emitted whenever the user modifies the date. This | 84 | /** This signal is emitted whenever the user modifies the date. This |
85 | * may not get emitted until the user presses enter in the line edit or | 85 | * may not get emitted until the user presses enter in the line edit or |
86 | * focus leaves the widget (ie: the user confirms their selection). | 86 | * focus leaves the widget (ie: the user confirms their selection). |
87 | */ | 87 | */ |
88 | void dateChanged(QDate); | 88 | void dateChanged(QDate); |
89 | void returnPressed(); | 89 | void returnPressed(); |
90 | void setTimeTo( QTime ); | ||
90 | public slots: | 91 | public slots: |
91 | /** Sets the date. | 92 | /** Sets the date. |
92 | * | 93 | * |
93 | * @param date The new date to display. This date must be valid or | 94 | * @param date The new date to display. This date must be valid or |
94 | * it will not be displayed. | 95 | * it will not be displayed. |
95 | */ | 96 | */ |
96 | void setDate(QDate date); | 97 | void setDate(QDate date); |
97 | // set Date with key_up key_down to relation of cursor Position | 98 | // set Date with key_up key_down to relation of cursor Position |
98 | // and set selection from begin to end of single date | 99 | // and set selection from begin to end of single date |
99 | void setDate(QDate, int *cpos, const int, const bool); | 100 | void setDate(QDate, int *cpos, const int, const bool); |
100 | 101 | ||
101 | /** Sets the date edit to be enabled or disabled (grayed out) | 102 | /** Sets the date edit to be enabled or disabled (grayed out) |
102 | * | 103 | * |
103 | * @param on Enabled if true, disabled if false | 104 | * @param on Enabled if true, disabled if false |
104 | */ | 105 | */ |
105 | void setEnabled(bool on); | 106 | void setEnabled(bool on); |
106 | 107 | ||
107 | protected slots: | 108 | protected slots: |
108 | void toggleDatePicker(); | 109 | void toggleDatePicker(); |
109 | void lineEnterPressed(); | 110 | void lineEnterPressed(); |
110 | void textChanged(const QString &); | 111 | void textChanged(const QString &); |
112 | void goToNow(); | ||
111 | 113 | ||
112 | private: | 114 | private: |
113 | /** Reads the text from the line edit. If the text is a keyword, the | 115 | /** Reads the text from the line edit. If the text is a keyword, the |
114 | * word will be translated to a date. If the text is not a keyword, the | 116 | * word will be translated to a date. If the text is not a keyword, the |
115 | * text will be interpreted as a date. | 117 | * text will be interpreted as a date. |
116 | */ | 118 | */ |
117 | QDate readDate() const; | 119 | QDate readDate() const; |
118 | 120 | ||
119 | /** Maps the text that the user can enter to the offset in days from | 121 | /** Maps the text that the user can enter to the offset in days from |
120 | * today. For example, the text 'tomorrow' is mapped to +1. | 122 | * today. For example, the text 'tomorrow' is mapped to +1. |
121 | */ | 123 | */ |
122 | QMap<QString, int> mKeywordMap; | 124 | QMap<QString, int> mKeywordMap; |
123 | bool mTextChanged; | 125 | bool mTextChanged; |
124 | bool mHandleInvalid; | 126 | bool mHandleInvalid; |
125 | 127 | ||
126 | QPushButton *mDateButton; | 128 | QPushButton *mDateButton; |
127 | QLineEdit *mDateEdit; | 129 | QLineEdit *mDateEdit; |
128 | KDatePicker *mDatePicker; | 130 | KDatePicker *mDatePicker; |
129 | QVBox *mDateFrame; | 131 | QVBox *mDateFrame; |
130 | int maxDay; | 132 | int maxDay; |
131 | bool withoutDp; | 133 | bool withoutDp; |
132 | 134 | ||
133 | protected: | 135 | protected: |
134 | virtual void keyPressEvent(QKeyEvent *qke); | 136 | virtual void keyPressEvent(QKeyEvent *qke); |
135 | void setSelect ( int, int ); | 137 | void setSelect ( int, int ); |
136 | bool dateFormShort; | 138 | bool dateFormShort; |
137 | char lengthMonthName; | 139 | char lengthMonthName; |
138 | 140 | ||
139 | }; | 141 | }; |
140 | 142 | ||
141 | #endif | 143 | #endif |