[uim-commit] r409 - trunk/qt/uim-kdehelper/src/pref

kzk at freedesktop.org kzk at freedesktop.org
Sun Jan 30 18:36:46 PST 2005


Author: kzk
Date: 2005-01-30 18:36:44 -0800 (Sun, 30 Jan 2005)
New Revision: 409

Modified:
   trunk/qt/uim-kdehelper/src/pref/customwidgets.cpp
   trunk/qt/uim-kdehelper/src/pref/customwidgets.h
   trunk/qt/uim-kdehelper/src/pref/uim-pref-qt.cpp
Log:
* Implement Callbacks for uim_custom

* qt/uim-kdehelper/src/pref/customwidgets.h
  - (UimCustomItemIface::UimCustomItemIface): register callback
  - (UimCustomItemIface::update_cb): callback
  - (UimCustomItemIface::updateItem): update m_custom variable by
    calling uim_custom_get
  - (UimCustomItemIface::update): pure virtual function to update
    the condition of widget
  - (CustomCheckBox::update): update CustomCheckBox
  - (CustomSpinBox::update): update CustomSpinBox
  - (CustomLineEdit::update): update CustomLineEdit
  - (CustomChoiceCombo::update): update CustomChiceCombo
  - (CustomOrderedListEdit::update): update CustomOrderedListEdit
* qt/uim-kdehelper/src/pref/customwidgets.cpp
  - Ditto

* qt/uim-kdehelper/src/pref/uim-pref-qt.cpp
  - move updation handling to customwidget.cpp


Modified: trunk/qt/uim-kdehelper/src/pref/customwidgets.cpp
===================================================================
--- trunk/qt/uim-kdehelper/src/pref/customwidgets.cpp	2005-01-31 02:30:55 UTC (rev 408)
+++ trunk/qt/uim-kdehelper/src/pref/customwidgets.cpp	2005-01-31 02:36:44 UTC (rev 409)
@@ -40,8 +40,21 @@
 {
     QObject::connect( this, SIGNAL(toggled(bool)),
                       this, SLOT(slotCustomToggled(bool)) );
+
+    update();
 }
 
+void CustomCheckBox::update()
+{    
+    setEnabled( m_custom->is_active );
+
+    if( m_custom->is_active )
+    {
+        setText( _FU8(m_custom->label) );
+        setChecked( m_custom->value->as_bool );
+    }
+}
+
 void CustomCheckBox::slotCustomToggled( bool check )
 {
     Q_ASSERT( m_custom->type == UCustom_Bool );
@@ -56,8 +69,21 @@
 {
     QObject::connect( this, SIGNAL(valueChanged(int)),
                       this, SLOT(slotCustomValueChanged(int)) );
+    update();
 }
 
+void CustomSpinBox::update()
+{
+    setEnabled( m_custom->is_active );
+
+    if( m_custom->is_active )
+    {
+        setValue( m_custom->value->as_int );
+        setMinValue( m_custom->range->as_int.min );
+        setMaxValue( m_custom->range->as_int.max );
+    }
+}
+
 void CustomSpinBox::slotCustomValueChanged( int value )
 {
     Q_ASSERT( m_custom->type == UCustom_Int );
@@ -72,8 +98,20 @@
 {
     QObject::connect( this, SIGNAL(textChanged(const QString&)),
                       this, SLOT(slotCustomTextChanged(const QString&)) );
+
+    update();
 }
 
+void CustomLineEdit::update()
+{
+    setEnabled( m_custom->is_active );
+
+    if( m_custom->is_active )
+    {
+        setText( _FU8(m_custom->value->as_str) );
+    }
+}
+
 void CustomLineEdit::slotCustomTextChanged( const QString &text )
 {
     Q_ASSERT( m_custom->type == UCustom_Str );
@@ -97,8 +135,21 @@
     m_fileButton->setText( "File" );
     QObject::connect( m_fileButton, SIGNAL(clicked()),
                       this, SLOT(slotPathnameButtonClicked()) );
+
+    update();
 }
 
+void CustomPathnameEdit::update()
+{
+    m_lineEdit->setEnabled( m_custom->is_active );
+    m_fileButton->setEnabled( m_custom->is_active );
+
+    if( m_custom->is_active )
+    {
+        m_lineEdit->setText( _FU8(m_custom->value->as_pathname) );
+    }
+}
+
 void CustomPathnameEdit::slotPathnameButtonClicked()
 {
     QFileDialog* fd = new QFileDialog( this, "file dialog" );
@@ -126,8 +177,35 @@
 {
     QObject::connect( this, SIGNAL(highlighted(int)),
                       this, SLOT(slotHighlighted(int)) );
+
+    update();
 }
 
+void CustomChoiceCombo::update()
+{
+    setEnabled( m_custom->is_active );
+
+    if( m_custom->is_active )
+    {
+        char *default_symbol = m_custom->value->as_choice->symbol;
+        int default_index = -1;
+        int index = 0;
+        struct uim_custom_choice **item = m_custom->range->as_choice.valid_items;
+        while( *item )
+        {
+            int count = this->count();
+            insertItem( _FU8((*item)->label), count ); // insert item at last
+            
+            if( QString::compare( default_symbol, (*item)->symbol ) == 0 )
+                default_index = index;
+            
+            index++;
+            item++;
+        }
+        setCurrentItem( default_index );
+    }
+}
+
 void CustomChoiceCombo::slotHighlighted( int index )
 {
     Q_ASSERT( m_custom->type == UCustom_Choice );
@@ -168,8 +246,21 @@
 
     QObject::connect( m_editButton, SIGNAL(clicked()),
                       this, SLOT(slotEditButtonClicked()) );
+
+    update();
 }
 
+void CustomOrderedListEdit::update()
+{
+    m_lineEdit->setEnabled( m_custom->is_active );
+    m_editButton->setEnabled( m_custom->is_active );
+
+    if( m_custom->is_active )
+    {
+        updateText();        
+    }
+}
+
 void CustomOrderedListEdit::initPtrList()
 {
     m_itemList.clear();
@@ -291,7 +382,7 @@
         setCustom( m_custom );
 
         /* reload */
-        updateText();
+        update();
     }
 }
 

Modified: trunk/qt/uim-kdehelper/src/pref/customwidgets.h
===================================================================
--- trunk/qt/uim-kdehelper/src/pref/customwidgets.h	2005-01-31 02:30:55 UTC (rev 408)
+++ trunk/qt/uim-kdehelper/src/pref/customwidgets.h	2005-01-31 02:36:44 UTC (rev 409)
@@ -63,12 +63,27 @@
     UimCustomItemIface( struct uim_custom *c = NULL )
     {
         m_custom = c;
+
+        // callback
+        uim_custom_cb_add( m_custom->symbol, this, UimCustomItemIface::update_cb );
+
+//        update();
     }
     virtual ~UimCustomItemIface()
     {
         if( m_custom ) uim_custom_free( m_custom );
     }
 
+    /* Custom Update Callback */
+    static void update_cb( void *ptr, const char *custom_sym )
+    {
+        UimCustomItemIface *iface = (UimCustomItemIface*)ptr;
+        iface->updateItem( custom_sym );        
+        iface->update();
+    }
+    virtual void update() = 0;
+
+
 protected:
     void setCustom( struct uim_custom *custom )
     {
@@ -78,6 +93,13 @@
         else
             qFatal( "Failed to set value for \"%s\".", custom->symbol );
     }
+    void updateItem( const char *custom_sym )
+    {
+        // remove current custom
+        if( m_custom ) uim_custom_free( m_custom );
+        // set new item
+        m_custom = uim_custom_get( custom_sym );
+    }
 
     virtual void currentCustomValueChanged() = 0;
 
@@ -91,6 +113,7 @@
 
 public:
     CustomCheckBox( struct uim_custom *c, QWidget *parent, const char *name = 0);
+    virtual void update();
 protected slots:
     void slotCustomToggled( bool check );
 protected:
@@ -105,6 +128,7 @@
 
 public:
     CustomSpinBox( struct uim_custom *c, QWidget *parent, const char *name = 0 );
+    virtual void update();
 public slots:
     void slotCustomValueChanged( int value );
 protected:
@@ -119,6 +143,7 @@
 
 public:
     CustomLineEdit( struct uim_custom *c, QWidget *parent, const char *name = 0 );
+    virtual void update();
 public slots:
     void slotCustomTextChanged( const QString &text );
 protected:
@@ -133,8 +158,8 @@
 
 public:
     CustomPathnameEdit( struct uim_custom *c, QWidget *parent, const char *name = 0 );
-    void setText( const QString & str ) { m_lineEdit->setText( str ); }
-
+    virtual void update();
+    
 protected slots:
     void slotPathnameButtonClicked();
     void slotCustomTextChanged( const QString & text );
@@ -153,6 +178,7 @@
 
 public:
     CustomChoiceCombo( struct uim_custom *c, QWidget *parent, const char *name = 0 );
+    virtual void update();
 public slots:
     void slotHighlighted( int index );
 protected:
@@ -167,6 +193,7 @@
 
 public:
     CustomOrderedListEdit( struct uim_custom *c, QWidget *parent, const char *name = 0 );
+    virtual void update();
 public slots:
     void slotEditButtonClicked();
 private:
@@ -188,9 +215,9 @@
 
 public:
     OListEditForm( QWidget *parent = 0, const char *name = 0 );
+    
     void addCheckItem( bool isActive, const QString &str );
     QStringList activeItemLabels() const;
-
 protected slots:
     void upItem();
     void downItem();

Modified: trunk/qt/uim-kdehelper/src/pref/uim-pref-qt.cpp
===================================================================
--- trunk/qt/uim-kdehelper/src/pref/uim-pref-qt.cpp	2005-01-31 02:30:55 UTC (rev 408)
+++ trunk/qt/uim-kdehelper/src/pref/uim-pref-qt.cpp	2005-01-31 02:36:44 UTC (rev 409)
@@ -136,23 +136,23 @@
 {
     char **primary_groups = uim_custom_primary_groups();
     char **grp = NULL;
-    QListViewItem *previousItem = NULL;
     for( grp = primary_groups; *grp; grp++ )
     {
         struct uim_custom_group *group = uim_custom_group_get( *grp );
 
         /* insert item in uim's order */
         QListViewItem *item = NULL;
-        if( previousItem == NULL )
-            item = new QListViewItem( m_groupListView, *grp );
+        QListViewItem *lastItem = m_groupListView->lastItem();
+        if( lastItem )
+            item = new QListViewItem( m_groupListView, lastItem, *grp );
         else
-            item = new QListViewItem( m_groupListView, previousItem, *grp );
+            item = new QListViewItem( m_groupListView, *grp );
 
+
         QWidget *w = createGroupWidget( *grp );
         m_groupWidgetsDict.insert( *grp, w );
         m_groupWidgetStack->addWidget( w );
 
-        previousItem = item;
         uim_custom_group_free( group );
     }
 }
@@ -240,8 +240,6 @@
 void UimPrefDialog::addCustomTypeBool( QVBox *vbox, struct uim_custom *custom )
 {
     CustomCheckBox *checkBox = new CustomCheckBox( custom, vbox );
-    checkBox->setText( _FU8(custom->label) );
-    checkBox->setChecked( custom->value->as_bool );
     QObject::connect( checkBox, SIGNAL(customValueChanged()),
                       this, SLOT(slotCustomValueChanged()) );
 }
@@ -253,9 +251,6 @@
     QLabel *label = new QLabel( _FU8(custom->label), hbox );
     hbox->setStretchFactor( new QWidget( hbox ), 1 );
     CustomSpinBox *spinBox = new CustomSpinBox( custom, hbox );
-    spinBox->setValue( custom->value->as_int );
-    spinBox->setMinValue( custom->range->as_int.min );
-    spinBox->setMaxValue( custom->range->as_int.max );
     label->setBuddy( spinBox );
 
     QObject::connect( spinBox, SIGNAL(customValueChanged()),
@@ -268,7 +263,6 @@
     hbox->setSpacing( 6 );
     QLabel *label = new QLabel( _FU8(custom->label) + ":", hbox );
     CustomLineEdit *lineEdit = new CustomLineEdit( custom, hbox );
-    lineEdit->setText( _FU8(custom->value->as_str) );
     label->setBuddy( lineEdit );
 
     QObject::connect( lineEdit, SIGNAL(customValueChanged()),
@@ -281,7 +275,6 @@
     hbox->setSpacing( 6 );
     QLabel *label = new QLabel( _FU8(custom->label), hbox );
     CustomPathnameEdit *pathnameEdit = new CustomPathnameEdit( custom, hbox );
-    pathnameEdit->setText( _FU8(custom->value->as_pathname) );
     label->setBuddy( pathnameEdit );
 
     QObject::connect( pathnameEdit, SIGNAL(customValueChanged()),
@@ -295,23 +288,6 @@
     QLabel *label = new QLabel( _FU8(custom->label), hbox );
 
     CustomChoiceCombo *choiceCombo = new CustomChoiceCombo( custom, hbox );
-    char *default_symbol = custom->value->as_choice->symbol;
-    int default_index = -1;
-    int index = 0;
-    struct uim_custom_choice **item = custom->range->as_choice.valid_items;
-    while( *item )
-    {
-        int count = choiceCombo->count();
-        choiceCombo->insertItem( _FU8((*item)->label), count ); // insert item at last
-
-        if( QString::compare( default_symbol, (*item)->symbol ) == 0 )
-            default_index = index;
-
-        index++;
-        item++;
-    }
-    choiceCombo->setCurrentItem( default_index );
-
     label->setBuddy( choiceCombo );
 
     QObject::connect( choiceCombo, SIGNAL(customValueChanged()),
@@ -362,6 +338,10 @@
     {
         slotApply();
     }
+    else
+    {
+        m_isValueChanged = false;
+    }
 }
 
 void UimPrefDialog::slotApply()



More information about the Uim-commit mailing list