summaryrefslogtreecommitdiffabout
path: root/libkdepim
authorzautrix <zautrix>2005-02-21 13:34:06 (UTC)
committer zautrix <zautrix>2005-02-21 13:34:06 (UTC)
commitce261d6197d319d67f7b275813449f36ce42a730 (patch) (unidiff)
tree6221eef1d00a918127377883eaf76f8162db6772 /libkdepim
parentb4ebc9c227f986369fe9b0193158f3893a29df08 (diff)
downloadkdepimpi-ce261d6197d319d67f7b275813449f36ce42a730.zip
kdepimpi-ce261d6197d319d67f7b275813449f36ce42a730.tar.gz
kdepimpi-ce261d6197d319d67f7b275813449f36ce42a730.tar.bz2
default button fixes
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdateedit.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp
index 946fc0d..3d9e690 100644
--- a/libkdepim/kdateedit.cpp
+++ b/libkdepim/kdateedit.cpp
@@ -1,213 +1,214 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 3
4 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
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
43KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) 43KDateEdit::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 71
72 mDateFrame = new QVBox(0,0,WType_Popup); 72 mDateFrame = new QVBox(0,0,WType_Popup);
73 // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); 73 // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
74 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); 74 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
75 mDateFrame->setLineWidth(3); 75 mDateFrame->setLineWidth(3);
76 mDateFrame->hide(); 76 mDateFrame->hide();
77 77
78 mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); 78 mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate());
79 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); 79 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate)));
80 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); 80 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate)));
81 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); 81 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate)));
82 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); 82 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate)));
83 connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); 83 connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide()));
84 connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); 84 connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker()));
85 mDateButton->setFocusPolicy( QWidget::NoFocus ); 85 mDateButton->setFocusPolicy( QWidget::NoFocus );
86 mDateButton->setAutoDefault( false );
86 //mDateFrame->resize( 400, 300 ); 87 //mDateFrame->resize( 400, 300 );
87 88
88 } 89 }
89 connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); 90 connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed()));
90 connect(mDateEdit,SIGNAL(textChanged(const QString &)), 91 connect(mDateEdit,SIGNAL(textChanged(const QString &)),
91 SLOT(textChanged(const QString &))); 92 SLOT(textChanged(const QString &)));
92 93
93 // Create the keyword list. This will be used to match against when the user 94 // Create the keyword list. This will be used to match against when the user
94 // enters information. 95 // enters information.
95 mKeywordMap[i18n("tomorrow")] = 1; 96 mKeywordMap[i18n("tomorrow")] = 1;
96 mKeywordMap[i18n("today")] = 0; 97 mKeywordMap[i18n("today")] = 0;
97 mKeywordMap[i18n("yesterday")] = -1; 98 mKeywordMap[i18n("yesterday")] = -1;
98 99
99 /* 100 /*
100 * This loop uses some math tricks to figure out the offset in days 101 * This loop uses some math tricks to figure out the offset in days
101 * to the next date the given day of the week occurs. There 102 * to the next date the given day of the week occurs. There
102 * are two cases, that the new day is >= the current day, which means 103 * are two cases, that the new day is >= the current day, which means
103 * the new day has not occured yet or that the new day < the current day, 104 * the new day has not occured yet or that the new day < the current day,
104 * which means the new day is already passed (so we need to find the 105 * which means the new day is already passed (so we need to find the
105 * day in the next week). 106 * day in the next week).
106 */ 107 */
107 QString dayName; 108 QString dayName;
108 int currentDay = QDate::currentDate().dayOfWeek(); 109 int currentDay = QDate::currentDate().dayOfWeek();
109 for (int i = 1; i <= 7; ++i) 110 for (int i = 1; i <= 7; ++i)
110 { 111 {
111 dayName = KGlobal::locale()->weekDayName(i).lower(); 112 dayName = KGlobal::locale()->weekDayName(i).lower();
112 if (i >= currentDay) 113 if (i >= currentDay)
113 mKeywordMap[dayName] = i - currentDay; 114 mKeywordMap[dayName] = i - currentDay;
114 else 115 else
115 mKeywordMap[dayName] = 7 - currentDay + i; 116 mKeywordMap[dayName] = 7 - currentDay + i;
116 } 117 }
117 118
118 mTextChanged = false; 119 mTextChanged = false;
119 mHandleInvalid = false; 120 mHandleInvalid = false;
120 // QWidget::setTabOrder( mDateEdit, mDateButton ); 121 // QWidget::setTabOrder( mDateEdit, mDateButton );
121} 122}
122 123
123KDateEdit::~KDateEdit() 124KDateEdit::~KDateEdit()
124{ 125{
125 delete mDateFrame; 126 delete mDateFrame;
126} 127}
127void KDateEdit::clear() 128void KDateEdit::clear()
128{ 129{
129 bool b = mDateEdit->signalsBlocked(); 130 bool b = mDateEdit->signalsBlocked();
130 mDateEdit->blockSignals(true); 131 mDateEdit->blockSignals(true);
131 mDateEdit->setText(""); 132 mDateEdit->setText("");
132 mDateEdit->blockSignals(b); 133 mDateEdit->blockSignals(b);
133} 134}
134void KDateEdit::setDate(QDate newDate) 135void KDateEdit::setDate(QDate newDate)
135{ 136{
136 if (!newDate.isValid() && !mHandleInvalid) 137 if (!newDate.isValid() && !mHandleInvalid)
137 return; 138 return;
138 if ( readDate() == newDate ) 139 if ( readDate() == newDate )
139 return; 140 return;
140 QString dateString = ""; 141 QString dateString = "";
141 if(newDate.isValid()) 142 if(newDate.isValid())
142 dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); 143 dateString = KGlobal::locale()->formatDate( newDate, dateFormShort );
143 144
144 mTextChanged = false; 145 mTextChanged = false;
145 146
146 // We do not want to generate a signal here, since we explicity setting 147 // We do not want to generate a signal here, since we explicity setting
147 // the date 148 // the date
148 bool b = mDateEdit->signalsBlocked(); 149 bool b = mDateEdit->signalsBlocked();
149 mDateEdit->blockSignals(true); 150 mDateEdit->blockSignals(true);
150 mDateEdit->setText(dateString); 151 mDateEdit->setText(dateString);
151 mDateEdit->blockSignals(b); 152 mDateEdit->blockSignals(b);
152} 153}
153 154
154void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) 155void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort)
155{ 156{
156 QString dateForm = dateFormShort ? 157 QString dateForm = dateFormShort ?
157 KGlobal::locale()->dateFormatShort() : 158 KGlobal::locale()->dateFormatShort() :
158 KGlobal::locale()->dateFormat(); 159 KGlobal::locale()->dateFormat();
159 160
160 int begin = dateForm.find("%"); 161 int begin = dateForm.find("%");
161 int space = 0; 162 int space = 0;
162 int allStrLength = 0; 163 int allStrLength = 0;
163 int strLength = 0; 164 int strLength = 0;
164 int repeat = 0; 165 int repeat = 0;
165 166
166 // witch? Day, Month or Year switch? 167 // witch? Day, Month or Year switch?
167 while(1){ 168 while(1){
168 switch ( dateForm.at(begin + 1).latin1() ) 169 switch ( dateForm.at(begin + 1).latin1() )
169 { 170 {
170 case 'd':// 16 (month day) 171 case 'd':// 16 (month day)
171 strLength = 2; //Ok 172 strLength = 2; //Ok
172 break; 173 break;
173 case 'm':// 01 (month) 174 case 'm':// 01 (month)
174 strLength = 2; //Ok 175 strLength = 2; //Ok
175 break; 176 break;
176 case 'a':// Mon (Weekday) 177 case 'a':// Mon (Weekday)
177 strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); 178 strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length();
178 break; 179 break;
179 case 'A':// Monday (Weekday) 180 case 'A':// Monday (Weekday)
180 strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); 181 strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length();
181 break; 182 break;
182 case 'b':// Jan (monthName) 183 case 'b':// Jan (monthName)
183 strLength = KGlobal::locale()->monthName(date.month(), true).length(); 184 strLength = KGlobal::locale()->monthName(date.month(), true).length();
184 break; 185 break;
185 case 'B':// January (monthName) 186 case 'B':// January (monthName)
186 strLength = KGlobal::locale()->monthName(date.month(), false).length(); 187 strLength = KGlobal::locale()->monthName(date.month(), false).length();
187 break; 188 break;
188 case 'y':// 04 (year short) 189 case 'y':// 04 (year short)
189 strLength = 2; //Ok 190 strLength = 2; //Ok
190 break; 191 break;
191 case 'Y':// 2004 (year) 192 case 'Y':// 2004 (year)
192 strLength = 4; //Ok 193 strLength = 4; //Ok
193 break; 194 break;
194 default: 195 default:
195 break; 196 break;
196 } 197 }
197 space = begin - (repeat++ * 2); 198 space = begin - (repeat++ * 2);
198 // all select? then dayswitch 199 // all select? then dayswitch
199 if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) && 200 if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) &&
200 ( (dateForm.at(begin + 1).latin1() == 'd') || 201 ( (dateForm.at(begin + 1).latin1() == 'd') ||
201 (dateForm.at(begin + 1).latin1() == 'a') || 202 (dateForm.at(begin + 1).latin1() == 'a') ||
202 (dateForm.at(begin + 1).latin1() == 'A') ) ) { 203 (dateForm.at(begin + 1).latin1() == 'A') ) ) {
203 break; 204 break;
204 } 205 }
205 // mDateEdit-StringPos == CursorPosition(cpos) then break and set date 206 // mDateEdit-StringPos == CursorPosition(cpos) then break and set date
206 if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) { 207 if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) {
207 break; 208 break;
208 } 209 }
209 allStrLength += strLength; 210 allStrLength += strLength;
210 begin = dateForm.find("%", begin +1); 211 begin = dateForm.find("%", begin +1);
211 } 212 }
212 213
213 // set date 214 // set date