lib Library API Documentation

timeformatwidget_impl.cc

00001 #include "timedateformatwidget.h"
00002 #include "timeformatwidget_impl.h"
00003 #include "timeformatwidget_impl.moc"
00004 #include <qdatetime.h>
00005 #include <qcombobox.h>
00006 #include <qcheckbox.h>
00007 #include <qlabel.h>
00008 #include <qbuttongroup.h>
00009 #include <qradiobutton.h>
00010 #include <kglobal.h>
00011 #include <klocale.h>
00012 #include <kdebug.h>
00013 #include <qlineedit.h>
00014 #include <knuminput.h>
00015 #include <kovariable.h>
00016 
00017 /*
00018  *  Constructs a TimeFormatWidget which is a child of 'parent', with the
00019  *  name 'name' and widget flags set to 'f'
00020  */
00021 TimeFormatWidget::TimeFormatWidget( QWidget* parent,  const char* name, WFlags fl )
00022     : TimeDateFormatWidgetPrototype( parent, name, fl )
00023 {
00024     setCaption( i18n( "TimeFormat", "This dialog allows you to set the format of the time variable" ) );
00025 
00026     QStringList listTimeFormat = KoVariableTimeFormat::staticTranslatedFormatPropsList();
00027     combo1->insertStringList(listTimeFormat);
00028 
00029     combo2->insertItem( i18n( "Hour" ) );
00030     combo2->insertItem( i18n( "Hour (2 digits)" ) );
00031     combo2->insertItem( i18n( "Minute" ) );
00032     combo2->insertItem( i18n( "Minute (2 digits)" ) );
00033     combo2->insertItem( i18n( "Second" ) );
00034     combo2->insertItem( i18n( "Second (2 digits)" ) );
00035     combo2->insertItem( i18n( "Millisecond (3 digits)" ) );
00036     combo2->insertItem( i18n( "am/pm" ) );
00037     combo2->insertItem( i18n( "AM/PM" ) );
00038     combo2->setCurrentItem( 0 );
00039 
00040     label_correction->setText(i18n("Correct in Minutes"));
00041     connect( CheckBox1, SIGNAL(toggled ( bool )),this,SLOT(slotPersonalizeChanged(bool)));
00042     connect( combo1, SIGNAL(activated ( const QString & )), this, SLOT(slotDefaultValueChanged(const QString &)));
00043     connect( combo1, SIGNAL(textChanged ( const QString & )), this, SLOT(slotDefaultValueChanged(const QString &)));
00044     connect( KIntNumInput1, SIGNAL(valueChanged(int)), this, SLOT( slotOffsetChanged(int)));
00045     slotPersonalizeChanged(false);
00046 }
00047 
00048 /*
00049  *  Destroys the object and frees any allocated resources
00050  */
00051 TimeFormatWidget::~TimeFormatWidget()
00052 {
00053     // no need to delete child widgets, Qt does it all for us
00054 }
00055 
00056 /*
00057  * public slot
00058  */
00059 void TimeFormatWidget::slotDefaultValueChanged(const QString & )
00060 {
00061     updateLabel();
00062 }
00063 
00064 void TimeFormatWidget::slotOffsetChanged(int)
00065 {
00066     updateLabel();
00067 }
00068 
00069 void TimeFormatWidget::slotPersonalizeChanged(bool b)
00070 {
00071     combo2->setEnabled(b);
00072     combo1->setEditable(b);
00073     TextLabel1->setEnabled(b);
00074     updateLabel();
00075 
00076 }
00077 
00078 void TimeFormatWidget::comboActivated()
00079 {
00080     QString string=combo2->currentText();
00081     if(string==i18n("Hour"))
00082         combo1->lineEdit()->insert("h");
00083     else if(string==i18n("Hour (2 digits)"))
00084         combo1->lineEdit()->insert("hh");
00085     else if(string==i18n("Minute"))
00086         combo1->lineEdit()->insert("m");
00087     else if(string==i18n("Minute (2 digits)"))
00088         combo1->lineEdit()->insert("mm");
00089     else if(string==i18n("Second"))
00090         combo1->lineEdit()->insert("s");
00091     else if(string==i18n("Second (2 digits)"))
00092         combo1->lineEdit()->insert("ss");
00093     else if(string==i18n("Millisecond (3 digits)"))
00094         combo1->lineEdit()->insert("zzz");
00095     else if(string==i18n("AM/PM"))
00096         combo1->lineEdit()->insert("AP");
00097     else if(string==i18n("am/pm"))
00098         combo1->lineEdit()->insert("ap");
00099     updateLabel();
00100     combo1->setFocus();
00101 }
00102 
00103 /*
00104  * public slot
00105  */
00106 void TimeFormatWidget::updateLabel()
00107 {
00108     KoVariableTimeFormat format;
00109     format.setFormatProperties( resultString() );
00110 
00111     QTime ct = QTime::currentTime().addSecs(correctValue()); // ### TODO: dialog says correct in *minutes*
00112     label->setText( format.convert( ct ) );
00113 }
00114 
00115 QString TimeFormatWidget::resultString()
00116 {
00117     const QString lookup(combo1->currentText());
00118     const QStringList listTranslated( KoVariableTimeFormat::staticTranslatedFormatPropsList() );
00119     const int index = listTranslated.findIndex(lookup);
00120     if (index==-1)
00121         return (lookup); // Either costum or non-locale
00122 
00123     // We have now a locale format, so we must "translate" it back;
00124 
00125     // Lookup untranslated format
00126     const QStringList listRaw( KoVariableTimeFormat::staticFormatPropsList() );
00127 
00128     QStringList::ConstIterator it( listRaw.at(index) );
00129     Q_ASSERT( it != listRaw.end() );
00130     if ( it != listRaw.end() )
00131         return *it;
00132     kdError(32500) << "Internal error: could not find correcponding time format: " << lookup << endl;
00133     return QString::null; // Something is wrong, give back a default
00134 }
00135 
00136 int TimeFormatWidget::correctValue()
00137 {
00138     return KIntNumInput1->value()*60;
00139 }
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 13:19:28 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2003