lib

TimeFormatWidget.cpp
1#include "timedateformatwidget.h"
2#include "TimeFormatWidget.h"
3#include "TimeFormatWidget.moc"
4#include <tqdatetime.h>
5#include <tqcombobox.h>
6#include <tqcheckbox.h>
7#include <tqlabel.h>
8#include <tqbuttongroup.h>
9#include <tqradiobutton.h>
10#include <tdeglobal.h>
11#include <tdelocale.h>
12#include <kdebug.h>
13#include <tqlineedit.h>
14#include <knuminput.h>
15#include <KoVariable.h>
16
17/*
18 * Constructs a TimeFormatWidget which is a child of 'parent', with the
19 * name 'name' and widget flags set to 'f'
20 */
21TimeFormatWidget::TimeFormatWidget( TQWidget* parent, const char* name, WFlags fl )
22 : TimeDateFormatWidgetPrototype( parent, name, fl )
23{
24 setCaption( i18n( "TimeFormat", "This Dialog Allows You to Set the Format of the Time Variable" ) );
25
26 TQStringList listTimeFormat = KoVariableTimeFormat::staticTranslatedFormatPropsList();
27 combo1->insertStringList(listTimeFormat);
28
29 combo2->insertItem( i18n( "Hour" ) );
30 combo2->insertItem( i18n( "Hour (2 digits)" ) );
31 combo2->insertItem( i18n( "Minute" ) );
32 combo2->insertItem( i18n( "Minute (2 digits)" ) );
33 combo2->insertItem( i18n( "Second" ) );
34 combo2->insertItem( i18n( "Second (2 digits)" ) );
35 combo2->insertItem( i18n( "Millisecond (3 digits)" ) );
36 combo2->insertItem( i18n( "am/pm" ) );
37 combo2->insertItem( i18n( "AM/PM" ) );
38 combo2->setCurrentItem( 0 );
39
40 label_correction->setText(i18n("Correct in Minutes"));
41 connect( CheckBox1, TQ_SIGNAL(toggled ( bool )),this,TQ_SLOT(slotPersonalizeChanged(bool)));
42 connect( combo1, TQ_SIGNAL(activated ( const TQString & )), this, TQ_SLOT(slotDefaultValueChanged(const TQString &)));
43 connect( combo1, TQ_SIGNAL(textChanged ( const TQString & )), this, TQ_SLOT(slotDefaultValueChanged(const TQString &)));
44 connect( KIntNumInput1, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT( slotOffsetChanged(int)));
45 slotPersonalizeChanged(false);
46}
47
48/*
49 * Destroys the object and frees any allocated resources
50 */
51TimeFormatWidget::~TimeFormatWidget()
52{
53 // no need to delete child widgets, TQt does it all for us
54}
55
56/*
57 * public slot
58 */
59void TimeFormatWidget::slotDefaultValueChanged(const TQString & )
60{
61 updateLabel();
62}
63
64void TimeFormatWidget::slotOffsetChanged(int)
65{
66 updateLabel();
67}
68
69void TimeFormatWidget::slotPersonalizeChanged(bool b)
70{
71 combo2->setEnabled(b);
72 combo1->setEditable(b);
73 TextLabel1->setEnabled(b);
74 updateLabel();
75
76}
77
78void TimeFormatWidget::comboActivated()
79{
80 TQString string=combo2->currentText();
81 if(string==i18n("Hour"))
82 combo1->lineEdit()->insert("h");
83 else if(string==i18n("Hour (2 digits)"))
84 combo1->lineEdit()->insert("hh");
85 else if(string==i18n("Minute"))
86 combo1->lineEdit()->insert("m");
87 else if(string==i18n("Minute (2 digits)"))
88 combo1->lineEdit()->insert("mm");
89 else if(string==i18n("Second"))
90 combo1->lineEdit()->insert("s");
91 else if(string==i18n("Second (2 digits)"))
92 combo1->lineEdit()->insert("ss");
93 else if(string==i18n("Millisecond (3 digits)"))
94 combo1->lineEdit()->insert("zzz");
95 else if(string==i18n("AM/PM"))
96 combo1->lineEdit()->insert("AP");
97 else if(string==i18n("am/pm"))
98 combo1->lineEdit()->insert("ap");
99 updateLabel();
100 combo1->setFocus();
101}
102
103/*
104 * public slot
105 */
106void TimeFormatWidget::updateLabel()
107{
109 format.setFormatProperties( resultString() );
110
111 TQTime ct = TQTime::currentTime().addSecs(correctValue()); // ### TODO: dialog says correct in *minutes*
112 label->setText( format.convert( ct ) );
113}
114
115TQString TimeFormatWidget::resultString()
116{
117 const TQString lookup(combo1->currentText());
118 const TQStringList listTranslated( KoVariableTimeFormat::staticTranslatedFormatPropsList() );
119 const int index = listTranslated.findIndex(lookup);
120 if (index==-1)
121 return (lookup); // Either costum or non-locale
122
123 // We have now a locale format, so we must "translate" it back;
124
125 // Lookup untranslated format
126 const TQStringList listRaw( KoVariableTimeFormat::staticFormatPropsList() );
127
128 TQStringList::ConstIterator it( listRaw.at(index) );
129 Q_ASSERT( it != listRaw.end() );
130 if ( it != listRaw.end() )
131 return *it;
132 kdError(32500) << "Internal error: could not find correcponding time format: " << lookup << endl;
133 return TQString(); // Something is wrong, give back a default
134}
135
136int TimeFormatWidget::correctValue()
137{
138 return KIntNumInput1->value()*60;
139}
Implementation of the "time" formats.
Definition KoVariable.h:202
virtual void setFormatProperties(const TQString &props)
Set the format string (e.g. hh:mm:ss)
Definition KoVariable.h:211
virtual TQString convert(const TQVariant &data) const
Use this format to convert a piece of data into a string.
const char * name(StdAction id)