1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#include "timedateformatwidget.h"
#include "DateFormatWidget.h"
#include "DateFormatWidget.moc"
#include <qdatetime.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlabel.h>
#include <qbuttongroup.h>
#include <qradiobutton.h>
#include <kglobal.h>
#include <klocale.h>
#include <qlineedit.h>
#include <kdebug.h>
#include <knuminput.h>
#include <KoVariable.h>
/*
* Constructs a DateFormatWidget which is a child of 'parent', with the
* name 'name' and widget flags set to 'fl'
*/
DateFormatWidget::DateFormatWidget( QWidget* parent, const char* name, WFlags fl )
: TimeDateFormatWidgetPrototype( parent, name, fl )
{
setCaption( i18n( "DateFormat", "Format of Date Variable" ) );
QStringList listDateFormat = KoVariableDateFormat::staticTranslatedFormatPropsList();
combo1->insertStringList(listDateFormat);
combo2->insertItem( i18n( "Day"));
combo2->insertItem( i18n( "Day (2 digits)"));
combo2->insertItem( i18n( "Day (abbreviated name)"));
combo2->insertItem( i18n( "Day (long name)"));
combo2->insertItem( i18n( "Month" ) );
combo2->insertItem( i18n( "Month (2 digits)" ) );
combo2->insertItem( i18n( "Month (abbreviated name)" ) );
combo2->insertItem( i18n( "Month (long name)" ) );
combo2->insertItem( i18n( "Month (possessive abbreviated name)" ) );
combo2->insertItem( i18n( "Month (possessive long name)" ) );
combo2->insertItem( i18n( "Year (2 digits)" ) );
combo2->insertItem( i18n( "Year (4 digits)" ) );
combo2->insertItem( i18n( "Hour" ) );
combo2->insertItem( i18n( "Hour (2 digits)" ) );
combo2->insertItem( i18n( "Minute" ) );
combo2->insertItem( i18n( "Minute (2 digits)" ) );
combo2->insertItem( i18n( "Second" ) );
combo2->insertItem( i18n( "Second (2 digits)" ) );
combo2->insertItem( i18n( "Millisecond (3 digits)" ) );
combo2->insertItem( i18n( "am/pm" ) );
combo2->insertItem( i18n( "AM/PM" ) );
combo2->setCurrentItem( 0 );
label_correction->setText(i18n("Correct in Days"));
connect( CheckBox1, SIGNAL(toggled ( bool )),this,SLOT(slotPersonalizeChanged(bool)));
connect( combo1, SIGNAL(activated ( const QString & )), this, SLOT(slotDefaultValueChanged(const QString &)));
connect( combo1, SIGNAL(textChanged ( const QString & )), this, SLOT(slotDefaultValueChanged(const QString &)));
connect( KIntNumInput1, SIGNAL(valueChanged(int)), this, SLOT( slotOffsetChanged(int)));
slotPersonalizeChanged(false);
}
/*
* Destroys the object and frees any allocated resources
*/
DateFormatWidget::~DateFormatWidget()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* public slot
*/
void DateFormatWidget::slotDefaultValueChanged(const QString & )
{
updateLabel();
}
void DateFormatWidget::slotOffsetChanged(int)
{
updateLabel();
}
void DateFormatWidget::slotPersonalizeChanged(bool b)
{
combo2->setEnabled(b);
TextLabel1->setEnabled(b);
combo1->setEditable(b);
updateLabel();
}
void DateFormatWidget::comboActivated()
{
QString string=combo2->currentText();
if(string==i18n( "Day"))
combo1->lineEdit()->insert("d");
else if(string==i18n( "Day (2 digits)"))
combo1->lineEdit()->insert("dd");
else if(string==i18n( "Day (abbreviated name)"))
combo1->lineEdit()->insert("ddd");
else if(string==i18n( "Day (long name)"))
combo1->lineEdit()->insert("dddd");
else if(string==i18n( "Month" ) )
combo1->lineEdit()->insert("M");
else if(string==i18n( "Month (2 digits)" ) )
combo1->lineEdit()->insert("MM");
else if(string==i18n( "Month (abbreviated name)" ) )
combo1->lineEdit()->insert("MMM");
else if(string==i18n( "Month (long name)" ) )
combo1->lineEdit()->insert("MMMM");
else if(string==i18n( "Month (possessive abbreviated name)" ) )
combo1->lineEdit()->insert("PPP");
else if(string==i18n( "Month (possessive long name)" ) )
combo1->lineEdit()->insert("PPPP");
else if(string==i18n( "Year (2 digits)" ) )
combo1->lineEdit()->insert("yy");
else if(string==i18n( "Year (4 digits)" ) )
combo1->lineEdit()->insert("yyyy");
else if(string==i18n("Hour"))
combo1->lineEdit()->insert("h");
else if(string==i18n("Hour (2 digits)"))
combo1->lineEdit()->insert("hh");
else if(string==i18n("Minute"))
combo1->lineEdit()->insert("m");
else if(string==i18n("Minute (2 digits)"))
combo1->lineEdit()->insert("mm");
else if(string==i18n("Second"))
combo1->lineEdit()->insert("s");
else if(string==i18n("Second (2 digits)"))
combo1->lineEdit()->insert("ss");
else if(string==i18n("Millisecond (3 digits)"))
combo1->lineEdit()->insert("zzz");
else if(string==i18n("AM/PM"))
combo1->lineEdit()->insert("AP");
else if(string==i18n("am/pm"))
combo1->lineEdit()->insert("ap");
updateLabel();
combo1->setFocus();
}
/*
* public slot
*/
void DateFormatWidget::updateLabel()
{
KoVariableDateFormat format;
format.setFormatProperties( resultString() );
QDateTime ct = QDateTime::currentDateTime().addDays( correctValue() );
label->setText( format.convert( ct ) );
}
QString DateFormatWidget::resultString()
{
const QString lookup(combo1->currentText());
const QStringList listTranslated( KoVariableDateFormat::staticTranslatedFormatPropsList() );
const int index = listTranslated.findIndex(lookup);
if (index==-1)
return (lookup); // Either costum or non-locale
// We have now a locale format, so we must "translate" it back;
// Lookup untranslated format
const QStringList listRaw( KoVariableDateFormat::staticFormatPropsList() );
QStringList::ConstIterator it( listRaw.at(index) );
Q_ASSERT( it != listRaw.end() );
if ( it != listRaw.end() )
return *it;
kdError(32500) << "Internal error: could not find correcponding date format: " << lookup << endl;
return QString::null; // Something is wrong, give back a default
}
int DateFormatWidget::correctValue()
{
return KIntNumInput1->value();
}
|