Logo Search packages:      
Sourcecode: ktechlab version File versions  Download package

QWidget * ItemInterface::configWidget (  )  [virtual]

Returns a configuration widget for the component for insertion into te ItemEditTB.

Parameters:
showAdvanced Whether advanced data should be shown

Definition at line 229 of file iteminterface.cpp.

References connectMapWidget(), ColorCombo::setColor(), and DoubleSpinBox::value().

{
      if ( !p_itemGroup || !p_itemGroup->activeItem() || !m_pActiveItemEditorToolBar )
            return 0l;
      
      VariantDataMap *variantMap = p_itemGroup->activeItem()->variantMap();
      
      QWidget * parent = m_pActiveItemEditorToolBar;
      
      // Create new widget with the toolbar or dialog as the parent
      QWidget * configWidget = new QWidget( parent, "tbConfigWidget" );
      configWidget->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding, 1, 1 ) );
      
      QHBoxLayout * configLayout = new QHBoxLayout( configWidget );
//    configLayout->setAutoAdd( true );
      configLayout->setSpacing( 6 );
      
//    configLayout->addItem( new QSpacerItem( 0, 0,  QSizePolicy::Expanding, QSizePolicy::Fixed ) );
      
      const VariantDataMap::iterator vaEnd = variantMap->end();
      for ( VariantDataMap::iterator vait = variantMap->begin(); vait != vaEnd; ++vait )
      {
            if ( vait.data()->isHidden() || vait.data()->isAdvanced() )
                  continue;
            
            const Variant::Type::Value type = vait.data()->type();
            
            // common to all types apart from bool
            QString toolbarCaption = vait.data()->toolbarCaption();
            if ( type != Variant::Type::Bool && !toolbarCaption.isEmpty() )
                  configLayout->addWidget( new QLabel( toolbarCaption, configWidget ) );
            
            QWidget * editWidget = 0l; // Should be set to the created widget
            
            switch( type )
            {
                  case Variant::Type::Port:
                  case Variant::Type::Pin:
                  case Variant::Type::VarName:
                  case Variant::Type::Combo:
                  case Variant::Type::Select:
                  case Variant::Type::KeyPad:
                  case Variant::Type::SevenSegment:
                  {
                        QString value = vait.data()->value().toString();
                        if ( !value.isEmpty() && !vait.data()->allowed().contains(value) )
                              vait.data()->appendAllowed(value);
                        
                        const QStringList allowed = vait.data()->allowed();
                        
                        KComboBox * box = new KComboBox(configWidget);
                        
                        box->insertStringList(allowed);
                        box->setCurrentItem(value);
                        
                        if ( type == Variant::Type::VarName || type == Variant::Type::Combo )
                              box->setEditable( true );
                        
                        m_stringComboBoxMap[vait.key()] = box;
                        connectMapWidget( box, SIGNAL(textChanged(const QString &)));
                        connectMapWidget( box, SIGNAL(activated(const QString &)));
                              
                        editWidget = box;
                        break;
                  }
                  case Variant::Type::FileName:
                  {
                        QString value = vait.data()->value().toString();
                        if ( !vait.data()->allowed().contains(value) )
                              vait.data()->appendAllowed(value);
                        
                        const QStringList allowed = vait.data()->allowed();
                        
                        KURLComboRequester * urlreq = new KURLComboRequester( configWidget );
                        urlreq->setFilter( vait.data()->filter() );
                        connectMapWidget( urlreq, SIGNAL(urlSelected(const QString &)) );
                        m_stringURLReqMap[vait.key()] = urlreq;
                        
                        KComboBox * box = urlreq->comboBox();
                        box->insertStringList(allowed);
                        box->setEditable( true );
                        
                        // Note this has to be called after inserting the allowed list
                        urlreq->setURL( vait.data()->value().toString() );
                        
                        // Generally we only want a file name once the user has finished typing out the full file name.
                        connectMapWidget( box, SIGNAL(returnPressed(const QString &)));
                        connectMapWidget( box, SIGNAL(activated(const QString &)));
                        
                        editWidget = urlreq;
                        break;
                  }
                  case Variant::Type::String:
                  {
                        KLineEdit * edit = new KLineEdit( configWidget );
                        
                        edit->setText( vait.data()->value().toString() );
                        connectMapWidget(edit,SIGNAL(textChanged(const QString &)));
                        m_stringLineEditMap[vait.key()] = edit;
                        editWidget = edit;
                        break;
                  }
                  case Variant::Type::Int:
                  {
                        KIntSpinBox *spin = new KIntSpinBox( (int)vait.data()->minValue(), (int)vait.data()->maxValue(), 1, vait.data()->value().toInt(), 10, configWidget );
                        
                        connectMapWidget( spin, SIGNAL(valueChanged(int)) );
                        m_intSpinBoxMap[vait.key()] = spin;
                        editWidget = spin;
                        break;
                  }
                  case Variant::Type::Double:
                  {
                        DoubleSpinBox *spin = new DoubleSpinBox( vait.data()->minValue(), vait.data()->maxValue(), vait.data()->minAbsValue(), vait.data()->value().toDouble(), vait.data()->unit(), configWidget );
                        
                        connectMapWidget( spin, SIGNAL(valueChanged(double)));
                        m_doubleSpinBoxMap[vait.key()] = spin;
                        editWidget = spin;
                        break;
                  }
                  case Variant::Type::Color:
                  {
                        QColor value = vait.data()->value().toColor();
                        
                        ColorCombo * colorBox = new ColorCombo( (ColorCombo::ColorScheme)vait.data()->colorScheme(), configWidget );
                        
                        colorBox->setColor( value );
                        connectMapWidget( colorBox, SIGNAL(activated(const QColor &)));
                        m_colorComboMap[vait.key()] = colorBox;
                        
                        editWidget = colorBox;
                        break;
                  }
                  case Variant::Type::Bool:
                  {
                        const bool value = vait.data()->value().toBool();
                        QCheckBox * box = new QCheckBox( vait.data()->toolbarCaption(), configWidget );
                        
                        box->setChecked(value);
                        connectMapWidget( box, SIGNAL(toggled(bool)));
                        m_boolCheckMap[vait.key()] = box;
                        editWidget = box;
                        break;
                  }
                  case Variant::Type::Raw:
                  case Variant::Type::PenStyle:
                  case Variant::Type::PenCapStyle:
                  case Variant::Type::Multiline:
                  case Variant::Type::None:
                  {
                        // Do nothing, as these data types are not handled in the toolbar
                        break;
                  }
            }
            
            if ( !editWidget )
                  continue;
            
            // In the case of the toolbar, we don't want it too high
            if ( editWidget->height() > parent->height()-2 )
                  editWidget->setMaximumHeight( parent->height()-2 );
            
            switch ( type )
            {
                  case Variant::Type::VarName:
                  case Variant::Type::Combo:
                  case Variant::Type::String:
                  {
                        QSizePolicy p( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed, 1, 1 );
                  
                        editWidget->setSizePolicy( p );
                        editWidget->setMaximumWidth( 250 );
                        break;
                  }
                  
                  case Variant::Type::FileName:
                  case Variant::Type::Port:
                  case Variant::Type::Pin:
                  case Variant::Type::Select:
                  case Variant::Type::KeyPad:
                  case Variant::Type::SevenSegment:
                  case Variant::Type::Int:
                  case Variant::Type::Double:
                  case Variant::Type::Color:
                  case Variant::Type::Bool:
                  case Variant::Type::Raw:
                  case Variant::Type::PenStyle:
                  case Variant::Type::PenCapStyle:
                  case Variant::Type::Multiline:
                  case Variant::Type::None:
                        break;
            }
            
            configLayout->addWidget( editWidget );
      }
      
      configLayout->addItem( new QSpacerItem( 0, 0,  QSizePolicy::Expanding, QSizePolicy::Fixed ) );
      
      return configWidget;
}


Generated by  Doxygen 1.6.0   Back to index