reworked the hack to be more generic and less specific
authorcoolo <coolo@e0cc52ee-31ee-0310-8b87-e83c4596d67c>
Sun, 9 Dec 2007 10:16:38 +0000 (10:16 +0000)
committercoolo <coolo@e0cc52ee-31ee-0310-8b87-e83c4596d67c>
Sun, 9 Dec 2007 10:16:38 +0000 (10:16 +0000)
to Qt3 internals

git-svn-id: http://svn.opensuse.org/svn/yast/trunk/qt4@42856 e0cc52ee-31ee-0310-8b87-e83c4596d67c

src/YQCheckBoxFrame.cc
src/YQCheckBoxFrame.h

index 7e8a5aa..3353502 100644 (file)
@@ -44,6 +44,8 @@ YQCheckBoxFrame::YQCheckBoxFrame( YWidget *           parent,
     QGroupBox::setTitle( fromUTF8( label ) );
     QGroupBox::setCheckable( true );
 
+    connect( this, SIGNAL( toggled( bool ) ),
+             SLOT( stateChanged( bool ) ) );
     setValue( checked );
 }
 
@@ -88,13 +90,49 @@ void YQCheckBoxFrame::setEnabled( bool enabled )
 
 void YQCheckBoxFrame::stateChanged( bool newState )
 {
-    y2debug( "new state: %d", newState );
     handleChildrenEnablement( newState );
 
     if ( notify() )
        YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
 }
 
+bool YQCheckBoxFrame::event(QEvent *e)
+{
+    /* now on to something very fishy. The purpose of this widget
+     * is for whatever reason to provide a checkbox with a groupbox
+     * without the children having any connection to it.
+     *
+     * So we use this trick to undo everything the base class did
+     */
+    QHash<QWidget*, bool> widgetState;
+
+    QObjectList childList = children();
+    for (int i = 0; i < childList.size(); ++i)
+    {
+        QObject *o = childList.at(i);
+        if (o->isWidgetType())
+        {
+            QWidget *w = static_cast<QWidget *>(o);
+            widgetState[w] = w->isEnabled();
+        }
+    }
+
+    bool ret = QGroupBox::event( e );
+
+    childList = children();
+    for (int i = 0; i < childList.size(); ++i)
+    {
+        QObject *o = childList.at(i);
+        if (o->isWidgetType())
+        {
+            QWidget *w = static_cast<QWidget *>(o);
+            if ( widgetState.contains( w ) )
+                w->setEnabled( widgetState[w] );
+        }
+    }
+
+    return ret;
+}
 
 void YQCheckBoxFrame::childEvent( QChildEvent * )
 {
@@ -127,11 +165,7 @@ YQCheckBoxFrame::setSize( int newWidth, int newHeight )
 
 int YQCheckBoxFrame::preferredWidth()
 {
-    int preferredWidth;
-    int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
-
-    preferredWidth = max( childPreferredWidth,
-                         (10 + fontMetrics().width( title() ) ) );
+    int preferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
     int left, top, right, bottom;
     getContentsMargins( &left, &top, &right, &bottom );
 
index d953cdf..bf6146e 100644 (file)
@@ -113,6 +113,7 @@ protected:
      **/
     virtual void childEvent( QChildEvent * );
 
+    virtual bool event(QEvent *e);
 
     //
     // Data members