⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options_widgets.cpp

📁 Linux平台下的内核及程序调试器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   m_hBox = new QHBoxLayout( 6, "hBox" );   m_hBox->addWidget( m_wLabel );   m_hBox->addWidget( m_widg );   m_hBox->setStretchFactor( m_wLabel, 6 );   m_hBox->setStretchFactor( m_widg,   2 );   return m_hBox; }/* class SpWidget: IntSpin --------------------------------------------- */SpWidget::~SpWidget(){   if ( m_intspin ) {      delete m_intspin;      m_intspin = 0;   }}SpWidget::SpWidget( QWidget* parent, Option* vkopt,                     bool mklabel, int num_sections )   : OptionWidget( parent, "sp_widget", vkopt, mklabel ) {   m_intspin = new IntSpin( parent, "int_spin" );   m_widg    = m_intspin;   m_numSections = num_sections;   connect( m_intspin, SIGNAL(valueChanged(const QString&)),             this,    SLOT(spChanged(const QString&)) );   /* not added if the url is empty */   ContextHelp::add( m_widg, m_opt->url() );}void SpWidget::addSection( int min, int max, int defval,                           int step, QString sep_char/*=" : "*/ ){ m_intspin->addSection( min, max, defval, step, sep_char ); }void SpWidget::spChanged( const QString &val ){   m_currentValue = val;   bool edited  = m_currentValue != m_initialValue;   emit valueChanged( edited, this );}void SpWidget::reset(){   if ( m_numSections == 1 ) {      m_intspin->setValue( m_initialValue.toInt(), 0 );   }  else {      QStringList values = QStringList::split( ",", m_initialValue );      for ( unsigned int i=0; i<values.count(); i++ ) {         m_intspin->setValue( values[i].toInt(), i );      }   }}void SpWidget::resetDefault(){    spChanged( m_opt->defValue() );    if ( m_numSections == 1 ) {      m_intspin->setValue( m_opt->defValue().toInt(), 0 );   } else {      QStringList values = QStringList::split( ",", m_opt->defValue() );      for ( unsigned int i=0; i<values.count(); i++ ) {         m_intspin->setValue( values[i].toInt(), i );      }   }}QHBoxLayout * SpWidget::hlayout(){    vk_assert( m_wLabel != 0 );   m_hBox = new QHBoxLayout( 6 );   m_hBox->addWidget( m_wLabel );   m_hBox->addWidget( m_widg );   m_hBox->setStretchFactor( m_wLabel, 10 );   m_hBox->setStretchFactor( m_widg,    1 );   return m_hBox; }/* class LbWidget: QListBox --------------------------------------------    This widget was specifically written to handle suppression files   stuff and nothing else. */static const char* sel_supp_xpm[] = {   "11 11 8 1",   "   c None",   ".  c #024266",   "+  c #5A9AB8",   "@  c #1B5F8E",   "#  c #79B7CD",   "$  c #5A97B5",   "%  c #AEDDE9",   "&  c #8ECADC",   "     .     ",   "  . .+. .  ",   " .+.@#@.+. ",   "  .#$%$#.  ",   " .@$&%&$@. ",   ".+#%%%%%#+.",   " .@$&%&$@. ",   "  .#$%$#.  ",   " .+.@#@.+. ",   "  . .+. .  ",   "     .     "};LbWidget::~LbWidget(){   if ( m_lbox ) {      delete m_lbox;      m_lbox = 0;   }}LbWidget::LbWidget( QWidget *parent, Option * vkopt, bool mklabel )   : OptionWidget( parent, "lb_widget", vkopt, mklabel ) {   m_lbox = new QListBox( parent, "list_box" );   m_widg = m_lbox;   m_lbox->setSelectionMode( QListBox::Single );   m_sep  = vkConfig->sepChar();   /* horrible hack alert! */   vk_assert( m_opt->cfgGroup() == "valgrind");   if (m_opt->cfgKey() == "supps-dirs")      m_mode = LbWidget::LB_SUPPDIRS;   else if (m_opt->cfgKey() == "supps-avail")      m_mode = LbWidget::LB_SUPPAVAIL;   else if (m_opt->cfgKey() == "suppressions")      m_mode = LbWidget::LB_SUPPSEL;   else      vk_assert_never_reached();   lbLoad();   connect( m_lbox, SIGNAL(contextMenuRequested(QListBoxItem*, const QPoint &)),            this,     SLOT(popupMenu(QListBoxItem*, const QPoint &)));   connect( m_lbox, SIGNAL(doubleClicked(QListBoxItem*)),            this,     SLOT(selectItem(QListBoxItem*)));   /* not added if the url is empty */   ContextHelp::add( m_widg, m_opt->url() );}/* load items from m_currentValue to listbox */void LbWidget::lbLoad(){   m_lbox->clear();   QStringList sfiles = QStringList::split( m_sep, m_currentValue );   for ( unsigned int i=0; i<sfiles.count(); i++ ) {      m_lbox->insertItem( sfiles[i] );   }}/* reset lbox to m_currentValue   called from OptionWidget::cancelEdit(), after m_currentValue reset. */void LbWidget::reset(){   lbLoad();   emit listChanged();}/* called from OptionsPage::resetDefaults()   reset to installation defaults */void LbWidget::resetDefault(){   m_currentValue = m_opt->defValue();   lbLoad();   lbChanged();}void LbWidget::setCurrValue( const QString& txt ) {    m_currentValue = txt;   lbLoad();   lbChanged();}/* return all contents concat'd with m_sep  */QString LbWidget::lbText(){   QStringList items;   for ( unsigned int i=0; i<m_lbox->count(); i++ )      items += m_lbox->text( i );   return (items.count() == 0) ? "" : items.join( m_sep );}/* emit signals to indicate widget content has changed */void LbWidget::lbChanged(){   switch( m_mode ) {   case LbWidget::LB_SUPPAVAIL:      /* Never test this widget's editedness - holds a dynamic list */      break;   case LbWidget::LB_SUPPDIRS:   case LbWidget::LB_SUPPSEL: {      bool edited = m_currentValue != m_initialValue;      emit valueChanged( edited, this );      emit listChanged();   } break;   default:      vk_assert_never_reached();      break;   }}/* insert new list item.   only valid mode is LB_SUPPSEL*/void LbWidget::insertItem( const QString& entry ){   switch( m_mode ) {   case LbWidget::LB_SUPPSEL:      m_lbox->insertItem( entry );      m_currentValue = lbText();      lbChanged();      break;   case LbWidget::LB_SUPPDIRS:   case LbWidget::LB_SUPPAVAIL:     default: vk_assert_never_reached(); break;   }}/* double clicked item, or via right-click menu   for a single-entry menu, do the only thing possible   else do nothing*/void LbWidget::selectItem( QListBoxItem* lb_item){   if ( !lb_item )      return;   switch( m_mode ) {   case LbWidget::LB_SUPPDIRS:      break;   case LbWidget::LB_SUPPSEL:      emit itemSelected( lb_item->text() );      m_lbox->removeItem( m_lbox->index( lb_item ) );      m_currentValue = lbText();      lbChanged();      break;   case LbWidget::LB_SUPPAVAIL:      emit itemSelected( lb_item->text() );      /* Not removing item - list recalculated in valgrind opts page */      break;   default: vk_assert_never_reached(); break;   }}/* different menus and stuff for the different modes */void LbWidget::popupMenu( QListBoxItem* lb_item, const QPoint& ){   switch( m_mode ) {   case LbWidget::LB_SUPPDIRS:  popupSuppDirs( lb_item );  break;   case LbWidget::LB_SUPPAVAIL: popupSuppAvail( lb_item ); break;   case LbWidget::LB_SUPPSEL:   popupSuppSel( lb_item );   break;   default: vk_assert_never_reached(); break;   }}void LbWidget::popupSuppSel( QListBoxItem* lb_item ){   vk_assert( m_mode == LbWidget::LB_SUPPSEL );   if ( !lb_item )  /* m_lbox is empty, so nothing to do */      return;   QPopupMenu popMenu( m_lbox );   int DESELECT = popMenu.insertItem( "Deselect File" );   if ( !(lb_item->isSelected() || lb_item->isCurrent()) )      popMenu.setItemEnabled( DESELECT, false );   popMenu.setMouseTracking( true );   int id = popMenu.exec( QCursor::pos() );   if ( id == DESELECT )      selectItem( lb_item );}void LbWidget::popupSuppAvail( QListBoxItem* lb_item ){   vk_assert( m_mode == LbWidget::LB_SUPPAVAIL );   QPopupMenu popMenu( m_lbox );   int SELECT = popMenu.insertItem( QPixmap(sel_supp_xpm), "Select File" );   if ( !lb_item || !(lb_item->isSelected() || lb_item->isCurrent()) )      popMenu.setItemEnabled( SELECT, false );   popMenu.setMouseTracking( true );   int id = popMenu.exec( QCursor::pos() );   if ( id == SELECT )      selectItem( lb_item );}void LbWidget::popupSuppDirs( QListBoxItem* lb_item ){   vk_assert( m_mode == LbWidget::LB_SUPPDIRS );   enum { DIR_RM, DIR_ADD };   QPopupMenu popMenu( m_lbox );   popMenu.insertItem( "Remove Dir", DIR_RM );   popMenu.insertItem( "Add Dir", DIR_ADD );   if ( !lb_item/* empty */ )      popMenu.setItemEnabled( DIR_RM, false );   bool changed = false;   popMenu.setMouseTracking( true );   int id = popMenu.exec( QCursor::pos() );   switch( id ) {   case DIR_RM:      m_lbox->removeItem(  m_lbox->index( lb_item ) );      changed = true;      break;   case DIR_ADD: {      QString startdir = m_currentValue.isEmpty()         ? QDir::currentDirPath()         : QStringList::split( m_sep, m_currentValue ).first();      QString supp_dir = QFileDialog::getExistingDirectory(                             startdir,                             m_lbox, "get_suppression_dir",                             "Choose Suppressions Directory",                              false/*=show files too*/ );      if ( supp_dir.isEmpty() ) /* user clicked Cancel ? */         break;      /* check not a duplicate entry */      if ( m_lbox->findItem( supp_dir, Qt::ExactMatch ) != 0 ) {         vkInfo( m_lbox, "Duplicate Entry",                 "<p>The entry '%s' is already in the list.</p>",                 supp_dir.latin1() );      } else {         m_lbox->insertItem( supp_dir );         changed = true;      }   } break;   default:      break;   }   if ( changed ) {      m_currentValue = lbText();      lbChanged();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -