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

📄 options_widgets.cpp

📁 Linux平台下的内核及程序调试器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ----------------------------------------------------------------------  * Implementation of class OptionWidget               options_widgets.cpp * Various widgets used on the 'pages' to control user input * ----------------------------------------------------------------------  * This file is part of Valkyrie, a front-end for Valgrind * Copyright (c) 2000-2006, OpenWorks LLP <info@open-works.co.uk> * This program is released under the terms of the GNU GPL v.2 * See the file LICENSE.GPL for the full license details. */#include <qcursor.h>#include <qpopupmenu.h>#include <qfiledialog.h>#include "options_widgets.h"#include "vk_option.h"#include "vk_utils.h"#include "vk_config.h"#include "vk_messages.h"#include "context_help.h"#include "vk_option.h"       /* for listbox fileCheck() *//* class OptionWidget -------------------------------------------------- */OptionWidget::OptionWidget( QWidget* parent, const char* name,                            Option* vkopt, bool mklabel )   : QObject( parent, name ) {   m_opt    = vkopt;   m_widg   = 0;   m_wLabel = 0;   m_initialValue = vkConfig->rdEntry( m_opt->cfgKey(),                                       m_opt->cfgGroup() );   m_currentValue = m_initialValue;   if ( mklabel ) {      m_wLabel = new QLabel( m_opt->m_shortHelp, parent );      m_wLabel->setMinimumSize( m_wLabel->sizeHint() );      m_wLabel->setAlignment( AlignLeft|AlignVCenter|ExpandTabs );   }}int OptionWidget::id(){ return m_opt->m_key; }QLabel * OptionWidget::label(){ return m_wLabel; }QWidget * OptionWidget::widget(){ return m_widg; }QString OptionWidget::currValue(){ return m_currentValue; }QString OptionWidget::initValue(){ return m_initialValue; }void OptionWidget::saveEdit(){   m_initialValue = m_currentValue;   vkConfig->wrEntry( m_currentValue, m_opt->cfgKey(), m_opt->cfgGroup() );}void OptionWidget::cancelEdit(){   m_currentValue = m_initialValue;   emit valueChanged( false, this );   reset();}void OptionWidget::setEnabled( bool enable ){	if ( m_wLabel != 0 )		m_wLabel->setEnabled( enable );	if ( m_widg != 0 ) {		m_widg->setEnabled( enable );	}}/* default horizontal layout for widgets with labels.   combos, spinboxes and lineedits have their own way of doings things */QHBoxLayout * OptionWidget::hlayout(){   vk_assert( m_wLabel != 0 );   m_hBox = new QHBoxLayout( 6, "hBox" );   m_hBox->addWidget( m_wLabel );   m_hBox->addWidget( m_widg );   return m_hBox; }QVBoxLayout* OptionWidget::vlayout(){   vk_assert( m_wLabel != 0 );   m_vBox = new QVBoxLayout( 6, "vBox" );   m_vBox->addWidget( m_wLabel );   m_vBox->addWidget( m_widg );   return m_vBox;}/* class CkWidget: QCheckBox ------------------------------------------- */CkWidget::~CkWidget() {   if ( m_cbox ) {      delete m_cbox;      m_cbox = 0;   }}CkWidget::CkWidget( QWidget* parent, Option* vkopt, bool mklabel )   : OptionWidget( parent, "ck_widget", vkopt, mklabel ) {    m_cbox = new QCheckBox( m_opt->m_shortHelp, parent, "check_box" );   m_widg = m_cbox;   m_cbox->setChecked( vkConfig->strToBool( m_initialValue ) );   connect( m_cbox, SIGNAL(toggled(bool)),             this,     SLOT(ckChanged(bool)) );   /* not added if the url is empty */   ContextHelp::add( m_widg, m_opt->url() );}void CkWidget::ckChanged( bool on ){   m_currentValue = (on) ? m_opt->m_possValues[0] : m_opt->m_possValues[1];   bool edited = m_currentValue != m_initialValue;   emit valueChanged( edited, this );   /* for dis/enabling associated widgets */   emit changed( on );   emit clicked( m_opt->m_key );}void CkWidget::reset(){ m_cbox->setChecked( vkConfig->strToBool( m_initialValue ) ); }void CkWidget::resetDefault(){   bool on = ( m_opt->defValue() == "1"   || m_opt->defValue() == "on"  ||                m_opt->defValue() == "yes" || m_opt->defValue() == "true" );   setOn( on );}bool CkWidget::isOn(){ return m_cbox->isChecked(); }void CkWidget::setOn( bool on ){ m_cbox->setChecked( on ); }/* class RbWidget: QRadioButton ---------------------------------------- */RbWidget::~RbWidget() {   if ( m_radio ) {      delete m_radio;      m_radio = 0;   }}RbWidget::RbWidget( QWidget* parent, Option* vkopt, bool mklabel )   : OptionWidget( parent, "rb_widget", vkopt, mklabel ) {    m_radio = new QRadioButton( m_opt->m_shortHelp, parent, "radio_button" );   m_widg  = m_radio;   m_radio->setChecked( vkConfig->strToBool( m_initialValue ) );   connect( m_radio, SIGNAL(toggled(bool)),             this, SLOT(rbChanged(bool)) );   /* not added if the url is empty */   ContextHelp::add( m_widg, m_opt->url() );}void RbWidget::rbChanged( bool on ){   m_currentValue = (on) ? m_opt->m_possValues[0] : m_opt->m_possValues[1];   bool edited = m_currentValue != m_initialValue;   emit valueChanged( edited, this );   /* for dis/enabling associated widgets */   emit changed( on );   emit clicked( m_opt->m_key );}void RbWidget::reset(){ m_radio->setChecked( vkConfig->strToBool( m_initialValue ) ); }void RbWidget::resetDefault(){   bool on = ( m_opt->defValue() == "1"   || m_opt->defValue() == "on"  ||                m_opt->defValue() == "yes" || m_opt->defValue() == "true" );   setOn( on );}bool RbWidget::isOn(){ return m_radio->isOn(); }void RbWidget::setOn( bool on ){ m_radio->setChecked( on ); }/* class LeWidget: QLineEdit ------------------------------------------- */LeWidget::~LeWidget(){   if ( m_ledit ) {      delete m_ledit;      m_ledit = 0;   }   if ( m_pb ) {      delete m_pb;      m_pb = 0;   }}LeWidget::LeWidget( QWidget *parent, Option * vkopt, bool mklabel )   : OptionWidget( parent, "le_widget", vkopt, mklabel ) {   m_pb    = 0;   m_ledit = new QLineEdit( parent, "line_edit" );    m_widg  = m_ledit;   m_ledit->setText( m_initialValue );   connect( m_ledit, SIGNAL( textChanged(const QString &) ),            this,      SLOT( leChanged(const QString &) ) );   connect( m_ledit, SIGNAL( returnPressed() ),            this,    SIGNAL( returnPressed() ) );   /* not added if the url is empty */   ContextHelp::add( m_widg, m_opt->url() );}void LeWidget::setCurrValue( const QString& txt ) {    m_ledit->setText( txt );  /* calls leChanged(txt) */   if ( txt.length() > 0 )      m_ledit->setCursorPosition( 0 );}void LeWidget::addCurrValue( const QString& txt ){    if ( m_currentValue.isEmpty() ) {      setCurrValue( txt );   } else {      setCurrValue( m_ledit->text() + "," + txt );    }}void LeWidget::setDisabled( bool disable ){   m_ledit->setDisabled( disable );   if ( m_pb != 0 )      m_pb->setDisabled( disable );}void LeWidget::leChanged( const QString& txt ){   m_currentValue = txt;   bool edited  = m_currentValue != m_initialValue;   emit valueChanged( edited, this );}void LeWidget::reset(){ m_ledit->setText( m_initialValue ); }void LeWidget::resetDefault(){ setCurrValue( m_opt->defValue() ); }QPushButton * LeWidget::button(){ return m_pb; }void LeWidget::setReadOnly( bool ro ){ m_ledit->setReadOnly( ro ); }void LeWidget::addButton( QWidget* parent, const QObject* receiver,                           const char* slot, QString txt/*=QString::null*/,                           bool /*icon=false*/ ){   QString label = !txt.isNull() ? txt : m_opt->m_shortHelp;   m_pb = new QPushButton( label, parent );   int pbht = m_ledit->height() - 8;   m_pb->setMaximumHeight( pbht );   connect( m_pb, SIGNAL(clicked()), receiver, slot );}/* layout for line edits where we want to have a pushbutton with   m_opt->shortHelp as its text, instead of the standard QLabel */QHBoxLayout * LeWidget::hlayout(){   m_hBox = new QHBoxLayout( 6, "le_hBox" );   if ( m_pb != 0 ) {      m_hBox->addWidget( m_pb );   } else {      m_hBox->addWidget( m_wLabel );   }   m_hBox->addWidget( m_widg );   return m_hBox; }/* class CbWidget: QComboBox ------------------------------------------- */CbWidget::~CbWidget(){   if ( m_combo ) {      delete m_combo;      m_combo = 0;   }}CbWidget::CbWidget( QWidget *parent, Option * vkopt, bool mklabel )   : OptionWidget( parent, "cb_widget", vkopt, mklabel ) {   m_currIdx = 0;   m_combo   = new QComboBox( true, parent, "combo_box" );   m_widg    = m_combo;   m_combo->setInsertionPolicy( QComboBox::NoInsertion );   m_combo->setAutoCompletion( true );   m_combo->insertStringList( m_opt->m_possValues );   m_combo->setCurrentItem( m_currIdx );   for ( int i=0; i<m_combo->count(); i++ ) {      if ( m_initialValue == m_combo->text(i) ) {         m_currIdx = i;         break;      }   }   m_combo->setCurrentItem( m_currIdx );   connect( m_combo, SIGNAL( activated(const QString &) ),            this,      SLOT( cbChanged(const QString &) ) );   /* not added if the url is empty */   ContextHelp::add( m_widg, m_opt->url() );}void CbWidget::cbChanged( const QString& txt ){   bool found = false;   for ( int i=0; i<m_combo->count(); ++i ) {      if ( txt == m_combo->text(i) ) {         found = true;         m_combo->setCurrentItem( i );         break;      }   }   if ( !found ) {      /* we didn't find the string the user typed in */      m_combo->setCurrentItem( m_currIdx );   } else {      m_currIdx = m_combo->currentItem();      m_currentValue = m_combo->currentText();      bool edited = m_currentValue != m_initialValue;      emit valueChanged( edited, this );   }}void CbWidget::reset(){ cbChanged( m_initialValue ); }void CbWidget::resetDefault(){ cbChanged( m_opt->defValue() ); }QHBoxLayout * CbWidget::hlayout(){    vk_assert( m_wLabel != 0 );

⌨️ 快捷键说明

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