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

📄 konfiguratoritems.cpp

📁 LINUX 下, 以 QT/KDE 写的档案管理员
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                     konfiguratoritems.cpp  -  description                             -------------------    copyright            : (C) 2003 by Csaba Karai    e-mail               : krusader@users.sourceforge.net    web site             : http://krusader.sourceforge.net ---------------------------------------------------------------------------  Description ***************************************************************************  A     db   dD d8888b. db    db .d8888.  .d8b.  d8888b. d88888b d8888b.     88 ,8P' 88  `8D 88    88 88'  YP d8' `8b 88  `8D 88'     88  `8D     88,8P   88oobY' 88    88 `8bo.   88ooo88 88   88 88ooooo 88oobY'     88`8b   88`8b   88    88   `Y8b. 88~~~88 88   88 88~~~~~ 88`8b     88 `88. 88 `88. 88b  d88 db   8D 88   88 88  .8D 88.     88 `88.     YP   YD 88   YD ~Y8888P' `8888Y' YP   YP Y8888D' Y88888P 88   YD                                                     H e a d e r    F i l e *************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#include "konfiguratoritems.h"#include "../krusader.h"#include <klocale.h>#include <qpainter.h>#include <qpen.h>#include <qcolordialog.h>#include <kiconloader.h>KonfiguratorExtension::KonfiguratorExtension( QObject *obj, QString cfgClass, QString cfgName, bool rst, int pg) :      QObject(), objectPtr( obj ), applyConnected( false ), setDefaultsConnected( false ),      changed( false ), restartNeeded( rst ), subpage(pg), configClass( cfgClass ), configName( cfgName ){}void KonfiguratorExtension::connectNotify( const char *signal ){  QString signalString    = QString( signal ).replace( " ", "" );  QString applyString     = QString( SIGNAL( applyManually(QObject *,QString, QString) ) ).replace( " ", "" );  QString defaultsString  = QString( SIGNAL( setDefaultsManually(QObject *) ) ).replace( " ", "" );  if( signalString == applyString )    applyConnected = true;  else if ( signalString == defaultsString )    setDefaultsConnected = true;  QObject::connectNotify( signal );}bool KonfiguratorExtension::apply(){  if( !changed )    return false;  if( applyConnected )    emit applyManually( objectPtr, configClass, configName );  else    emit applyAuto( objectPtr, configClass, configName );  setChanged( false );  return restartNeeded;}void KonfiguratorExtension::setDefaults(){  if( setDefaultsConnected )    emit setDefaultsManually( objectPtr );  else    emit setDefaultsAuto( objectPtr );}void KonfiguratorExtension::loadInitialValue(){  emit setInitialValue( objectPtr );}bool KonfiguratorExtension::isChanged(){  return changed;}// KonfiguratorCheckBox class///////////////////////////////KonfiguratorCheckBox::KonfiguratorCheckBox( QString cls, QString name, bool dflt, QString text,    QWidget *parent, const char *widgetName, bool rst, int pg ) : QCheckBox( text, parent, widgetName ),    defaultValue( dflt ){  ext = new KonfiguratorExtension( this, cls, name, rst, pg );  connect( ext, SIGNAL( applyAuto(QObject *,QString, QString) ), this, SLOT( slotApply(QObject *,QString, QString) ) );  connect( ext, SIGNAL( setDefaultsAuto(QObject *) ), this, SLOT( slotSetDefaults(QObject *) ) );  connect( ext, SIGNAL( setInitialValue(QObject *) ), this, SLOT( loadInitialValue() ) );  connect( this, SIGNAL( stateChanged( int ) ), ext, SLOT( setChanged() ) );  loadInitialValue();}KonfiguratorCheckBox::~KonfiguratorCheckBox(){  delete ext;}void KonfiguratorCheckBox::loadInitialValue(){  krConfig->setGroup( ext->getCfgClass() );  setChecked( krConfig->readBoolEntry( ext->getCfgName(), defaultValue ) );  ext->setChanged( false );}void KonfiguratorCheckBox::slotApply(QObject *,QString cls, QString name){  krConfig->setGroup( cls );  krConfig->writeEntry( name, isChecked() );}void KonfiguratorCheckBox::slotSetDefaults(QObject *){  if( isChecked() != defaultValue )    setChecked( defaultValue );}// KonfiguratorSpinBox class///////////////////////////////KonfiguratorSpinBox::KonfiguratorSpinBox( QString cls, QString name, int dflt, int min, int max,    QWidget *parent, const char *widgetName, bool rst, int pg ) : QSpinBox( parent, widgetName ),    defaultValue( dflt ){  ext = new KonfiguratorExtension( this, cls, name, rst, pg );  connect( ext, SIGNAL( applyAuto(QObject *,QString, QString) ), this, SLOT( slotApply(QObject *,QString, QString) ) );  connect( ext, SIGNAL( setDefaultsAuto(QObject *) ), this, SLOT( slotSetDefaults(QObject *) ) );  connect( ext, SIGNAL( setInitialValue(QObject *) ), this, SLOT( loadInitialValue() ) );  connect( this, SIGNAL( valueChanged(int) ), ext, SLOT( setChanged() ) );  setMinValue( min );  setMaxValue( max );  loadInitialValue();}KonfiguratorSpinBox::~KonfiguratorSpinBox(){  delete ext;}void KonfiguratorSpinBox::loadInitialValue(){  krConfig->setGroup( ext->getCfgClass() );  setValue( krConfig->readNumEntry( ext->getCfgName(), defaultValue ) );  ext->setChanged( false );}void KonfiguratorSpinBox::slotApply(QObject *,QString cls, QString name){  krConfig->setGroup( cls );  krConfig->writeEntry( name, value() );}void KonfiguratorSpinBox::slotSetDefaults(QObject *){  if( value() != defaultValue )    setValue( defaultValue );}// KonfiguratorCheckBoxGroup class///////////////////////////////void KonfiguratorCheckBoxGroup::add( KonfiguratorCheckBox *checkBox ){  checkBoxList.append( checkBox );}KonfiguratorCheckBox * KonfiguratorCheckBoxGroup::find( int index ){  return checkBoxList.at( index );}KonfiguratorCheckBox * KonfiguratorCheckBoxGroup::find( QString name ){  KonfiguratorCheckBox *checkBox = checkBoxList.first();  while( checkBox )  {    if( checkBox->extension()->getCfgName() == name )      return checkBox;    checkBox = checkBoxList.next();  }  return 0;}// KonfiguratorRadioButtons class///////////////////////////////KonfiguratorRadioButtons::KonfiguratorRadioButtons( QString cls, QString name,    QString dflt, QWidget *parent, const char *widgetName, bool rst, int pg ) :    QButtonGroup( parent, widgetName ), defaultValue( dflt ){  ext = new KonfiguratorExtension( this, cls, name, rst, pg );  connect( ext, SIGNAL( applyAuto(QObject *,QString, QString) ), this, SLOT( slotApply(QObject *,QString, QString) ) );  connect( ext, SIGNAL( setDefaultsAuto(QObject *) ), this, SLOT( slotSetDefaults(QObject *) ) );  connect( ext, SIGNAL( setInitialValue(QObject *) ), this, SLOT( loadInitialValue() ) );}KonfiguratorRadioButtons::~KonfiguratorRadioButtons(){  delete ext;}void KonfiguratorRadioButtons::addRadioButton( QRadioButton *radioWidget, QString name, QString value ){  radioButtons.append( radioWidget );  radioNames.push_back( name );  radioValues.push_back( value );  connect( radioWidget, SIGNAL( stateChanged(int) ), ext, SLOT( setChanged() ) );}QRadioButton * KonfiguratorRadioButtons::find( int index ){  return radioButtons.at( index );}QRadioButton * KonfiguratorRadioButtons::find( QString name ){  int index = radioNames.findIndex( name );  if( index == -1 )    return 0;  return radioButtons.at( index );}void KonfiguratorRadioButtons::selectButton( QString value ){  int cnt = 0;  QRadioButton *btn  = radioButtons.first();  while( btn )  {    if( value == radioValues[ cnt ] )    {      btn->setChecked( true );      return;    }    btn = radioButtons.next();    cnt++;  }  if( radioButtons.first() )    radioButtons.first()->setChecked( true );}void KonfiguratorRadioButtons::loadInitialValue(){  krConfig->setGroup( ext->getCfgClass() );  QString initValue = krConfig->readEntry( ext->getCfgName(), defaultValue );  selectButton( initValue );  ext->setChanged( false );}void KonfiguratorRadioButtons::slotApply(QObject *,QString cls, QString name){  QRadioButton *btn  = radioButtons.first();  int cnt = 0;  while( btn )  {    if( btn->isChecked() )    {      krConfig->setGroup( cls );      krConfig->writeEntry( name, radioValues[ cnt ] );      break;    }    btn = radioButtons.next();    cnt++;  }}void KonfiguratorRadioButtons::slotSetDefaults(QObject *){  selectButton( defaultValue );}// KonfiguratorEditBox class///////////////////////////////KonfiguratorEditBox::KonfiguratorEditBox( QString cls, QString name, QString dflt,    QWidget *parent, const char *widgetName, bool rst, int pg ) : QLineEdit( parent, widgetName ),    defaultValue( dflt ){  ext = new KonfiguratorExtension( this, cls, name, rst, pg );  connect( ext, SIGNAL( applyAuto(QObject *,QString, QString) ), this, SLOT( slotApply(QObject *,QString, QString) ) );  connect( ext, SIGNAL( setDefaultsAuto(QObject *) ), this, SLOT( slotSetDefaults(QObject *) ) );  connect( ext, SIGNAL( setInitialValue(QObject *) ), this, SLOT( loadInitialValue() ) );  connect( this, SIGNAL( textChanged(const QString &) ), ext, SLOT( setChanged() ) );  loadInitialValue();}KonfiguratorEditBox::~KonfiguratorEditBox(){  delete ext;}void KonfiguratorEditBox::loadInitialValue(){  krConfig->setGroup( ext->getCfgClass() );  setText( krConfig->readEntry( ext->getCfgName(), defaultValue ) );  ext->setChanged( false );}void KonfiguratorEditBox::slotApply(QObject *,QString cls, QString name){  krConfig->setGroup( cls );  krConfig->writeEntry( name, text() );}void KonfiguratorEditBox::slotSetDefaults(QObject *){  if( text() != defaultValue )    setText( defaultValue );}// KonfiguratorURLRequester class///////////////////////////////KonfiguratorURLRequester::KonfiguratorURLRequester( QString cls, QString name, QString dflt,    QWidget *parent, const char *widgetName, bool rst, int pg ) : KURLRequester( parent, widgetName ),    defaultValue( dflt ){  ext = new KonfiguratorExtension( this, cls, name, rst, pg );  connect( ext, SIGNAL( applyAuto(QObject *,QString, QString) ), this, SLOT( slotApply(QObject *,QString, QString) ) );  connect( ext, SIGNAL( setDefaultsAuto(QObject *) ), this, SLOT( slotSetDefaults(QObject *) ) );  connect( ext, SIGNAL( setInitialValue(QObject *) ), this, SLOT( loadInitialValue() ) );  connect( this, SIGNAL( textChanged(const QString &) ), ext, SLOT( setChanged() ) );  button()->setIconSet( SmallIcon( "fileopen" ) );  loadInitialValue();}KonfiguratorURLRequester::~KonfiguratorURLRequester(){  delete ext;}void KonfiguratorURLRequester::loadInitialValue(){  krConfig->setGroup( ext->getCfgClass() );  setURL( krConfig->readEntry( ext->getCfgName(), defaultValue ) );  ext->setChanged( false );}void KonfiguratorURLRequester::slotApply(QObject *,QString cls, QString name){  krConfig->setGroup( cls );  krConfig->writeEntry( name, url() );}void KonfiguratorURLRequester::slotSetDefaults(QObject *){  if( url() != defaultValue )    setURL( defaultValue );}// KonfiguratorFontChooser class///////////////////////////////KonfiguratorFontChooser::KonfiguratorFontChooser( QString cls, QString name, QFont *dflt,  QWidget *parent, const char *widgetName, bool rst, int pg ) : QHBox ( parent, widgetName ),    defaultValue( dflt ){  ext = new KonfiguratorExtension( this, cls, name, rst, pg );  connect( ext, SIGNAL( applyAuto(QObject *,QString, QString) ), this, SLOT( slotApply(QObject *,QString, QString) ) );  connect( ext, SIGNAL( setDefaultsAuto(QObject *) ), this, SLOT( slotSetDefaults(QObject *) ) );  connect( ext, SIGNAL( setInitialValue(QObject *) ), this, SLOT( loadInitialValue() ) );  pLabel = new QLabel( this );  pLabel->setMinimumWidth( 150 );  pToolButton = new QToolButton( this );  connect( pToolButton, SIGNAL( clicked() ), this, SLOT( slotBrowseFont() ) );  pToolButton->setIconSet( SmallIcon( "fileopen" ) );  loadInitialValue();}KonfiguratorFontChooser::~KonfiguratorFontChooser(){  delete ext;}

⌨️ 快捷键说明

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