diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kotext/TimeFormatWidget.cpp | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kotext/TimeFormatWidget.cpp')
-rw-r--r-- | lib/kotext/TimeFormatWidget.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/lib/kotext/TimeFormatWidget.cpp b/lib/kotext/TimeFormatWidget.cpp new file mode 100644 index 00000000..7479131d --- /dev/null +++ b/lib/kotext/TimeFormatWidget.cpp @@ -0,0 +1,139 @@ +#include "timedateformatwidget.h" +#include "TimeFormatWidget.h" +#include "TimeFormatWidget.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 <kdebug.h> +#include <qlineedit.h> +#include <knuminput.h> +#include <KoVariable.h> + +/* + * Constructs a TimeFormatWidget which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + */ +TimeFormatWidget::TimeFormatWidget( QWidget* parent, const char* name, WFlags fl ) + : TimeDateFormatWidgetPrototype( parent, name, fl ) +{ + setCaption( i18n( "TimeFormat", "This Dialog Allows You to Set the Format of the Time Variable" ) ); + + QStringList listTimeFormat = KoVariableTimeFormat::staticTranslatedFormatPropsList(); + combo1->insertStringList(listTimeFormat); + + 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 Minutes")); + 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 + */ +TimeFormatWidget::~TimeFormatWidget() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * public slot + */ +void TimeFormatWidget::slotDefaultValueChanged(const QString & ) +{ + updateLabel(); +} + +void TimeFormatWidget::slotOffsetChanged(int) +{ + updateLabel(); +} + +void TimeFormatWidget::slotPersonalizeChanged(bool b) +{ + combo2->setEnabled(b); + combo1->setEditable(b); + TextLabel1->setEnabled(b); + updateLabel(); + +} + +void TimeFormatWidget::comboActivated() +{ + QString string=combo2->currentText(); + 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 TimeFormatWidget::updateLabel() +{ + KoVariableTimeFormat format; + format.setFormatProperties( resultString() ); + + QTime ct = QTime::currentTime().addSecs(correctValue()); // ### TODO: dialog says correct in *minutes* + label->setText( format.convert( ct ) ); +} + +QString TimeFormatWidget::resultString() +{ + const QString lookup(combo1->currentText()); + const QStringList listTranslated( KoVariableTimeFormat::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( KoVariableTimeFormat::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 time format: " << lookup << endl; + return QString::null; // Something is wrong, give back a default +} + +int TimeFormatWidget::correctValue() +{ + return KIntNumInput1->value()*60; +} |