[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [PATCH] Custom formats in date/time dialogs
From:       Nicolas Goutte <nicolasg () snafu ! de>
Date:       2003-09-18 21:24:09
[Download RAW message or body]

The attached patch is for koffice/lib/kotext.

It allows again to make custom format in the date or time dialogs. (Problem 
was that combobox was used as a list and not as an editable combobox.)

This patch does *not* correct the fact that the time dialog tells that the 
correction is minute but that the code makes it in seconds.

Have a nice day!
["patch_kotext_combo.diff" (text/x-diff)]

Index: dateformatwidget_impl.cc
===================================================================
RCS file: /home/kde/koffice/lib/kotext/dateformatwidget_impl.cc,v
retrieving revision 1.17
diff -u -r1.17 dateformatwidget_impl.cc
--- dateformatwidget_impl.cc	18 Sep 2003 18:51:43 -0000	1.17
+++ dateformatwidget_impl.cc	18 Sep 2003 21:18:31 -0000
@@ -54,6 +54,7 @@
 
     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);
 }
@@ -152,14 +153,22 @@
 
 QString DateFormatWidget::resultString()
 {
+    QString lookup(combo1->currentText());
+    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
-    QStringList listDateFormat = KoVariableDateFormat::staticFormatPropsList();
+    QStringList listRaw( KoVariableDateFormat::staticFormatPropsList() );
 
-    QStringList::Iterator it = listDateFormat.at(combo1->currentItem());
-    Q_ASSERT( it != listDateFormat.end() );
-    if ( it != listDateFormat.end() )
+    QStringList::ConstIterator it( listRaw.at(index) );
+    Q_ASSERT( it != listRaw.end() );
+    if ( it != listRaw.end() )
         return *it;
-    return QString::null;
+    return "yyyy-MM-dd"; // Something is wrong, give back a default
 }
 
 int DateFormatWidget::correctValue()
Index: timeformatwidget_impl.cc
===================================================================
RCS file: /home/kde/koffice/lib/kotext/timeformatwidget_impl.cc,v
retrieving revision 1.19
diff -u -r1.19 timeformatwidget_impl.cc
--- timeformatwidget_impl.cc	21 May 2003 21:34:16 -0000	1.19
+++ timeformatwidget_impl.cc	18 Sep 2003 21:18:31 -0000
@@ -39,6 +39,7 @@
     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);
 }
@@ -106,20 +107,28 @@
     KoVariableTimeFormat format;
     format.setFormatProperties( resultString() );
 
-    QTime ct = QTime::currentTime().addSecs(correctValue());
+    QTime ct = QTime::currentTime().addSecs(correctValue()); // ### TODO: dialog \
says correct in *minutes*  label->setText( format.convert( ct ) );
 }
 
 QString TimeFormatWidget::resultString()
 {
+    QString lookup(combo1->currentText());
+    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
-    QStringList listTimeFormat = KoVariableTimeFormat::staticFormatPropsList();
+    QStringList listRaw( KoVariableTimeFormat::staticFormatPropsList() );
 
-    QStringList::Iterator it = listTimeFormat.at(combo1->currentItem());
-    Q_ASSERT( it != listTimeFormat.end() );
-    if ( it != listTimeFormat.end() )
+    QStringList::ConstIterator it( listRaw.at(index) );
+    Q_ASSERT( it != listRaw.end() );
+    if ( it != listRaw.end() )
         return *it;
-    return QString::null;
+    return "hh:mm:ss.zzz"; // Something is wrong, give back a default
 }
 
 int TimeFormatWidget::correctValue()



_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic