📄 konfiguratoritems.cpp
字号:
void KonfiguratorFontChooser::loadInitialValue(){ krConfig->setGroup( ext->getCfgClass() ); font = krConfig->readFontEntry( ext->getCfgName(), defaultValue ); ext->setChanged( false ); setFont();}void KonfiguratorFontChooser::setFont(){ pLabel->setFont( font ); pLabel->setText( font.family()+QString(", %1").arg(font.pointSize()) );}void KonfiguratorFontChooser::slotApply(QObject *,QString cls, QString name){ krConfig->setGroup( cls ); krConfig->writeEntry( name, font );}void KonfiguratorFontChooser::slotSetDefaults(QObject *){ font = *defaultValue; ext->setChanged(); setFont();}void KonfiguratorFontChooser::slotBrowseFont(){ int ok=KFontDialog::getFont( font ); if (ok!=1) return; // cancelled by the user ext->setChanged(); setFont();}// KonfiguratorComboBox class///////////////////////////////KonfiguratorComboBox::KonfiguratorComboBox( QString cls, QString name, QString dflt, KONFIGURATOR_NAME_VALUE_PAIR *listIn, int listInLen, QWidget *parent, const char *widgetName, bool rst, bool editable, int pg ) : QComboBox ( parent, widgetName ), defaultValue( dflt ), listLen( listInLen ){ list = new KONFIGURATOR_NAME_VALUE_PAIR[ listInLen ]; for( int i=0; i != listLen; i++ ) { list[i] = listIn[i]; insertItem( list[i].text ); } 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( highlighted(int) ), ext, SLOT( setChanged() ) ); /* Removed because of startup combo failure */ connect( this, SIGNAL( activated(int) ), ext, SLOT( setChanged() ) ); connect( this, SIGNAL( textChanged ( const QString & ) ), ext, SLOT( setChanged() ) ); setEditable( editable ); loadInitialValue();}KonfiguratorComboBox::~KonfiguratorComboBox(){ delete []list; delete ext;}void KonfiguratorComboBox::loadInitialValue(){ krConfig->setGroup( ext->getCfgClass() ); QString select = krConfig->readEntry( ext->getCfgName(), defaultValue ); selectEntry( select ); ext->setChanged( false );}void KonfiguratorComboBox::slotApply(QObject *,QString cls, QString name){ QString text = editable() ? lineEdit()->text() : currentText(); QString value = text; for( int i=0; i != listLen; i++ ) if( list[i].text == text ) { value = list[i].value; break; } krConfig->setGroup( cls ); krConfig->writeEntry( name, value );}void KonfiguratorComboBox::selectEntry( QString entry ){ for( int i=0; i != listLen; i++ ) if( list[i].value == entry ) { setCurrentItem( i ); return; } if( editable() ) lineEdit()->setText( entry ); else setCurrentItem( 0 );}void KonfiguratorComboBox::slotSetDefaults(QObject *){ selectEntry( defaultValue );}// KonfiguratorColorChooser class///////////////////////////////KonfiguratorColorChooser::KonfiguratorColorChooser( QString cls, QString name, QColor dflt, QWidget *parent, const char *widgetName, bool rst, ADDITIONAL_COLOR *addColPtr, int addColNum, int pg ) : QComboBox ( parent, widgetName ), defaultValue( dflt ), disableColorChooser( true ){ 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() ) ); addColor( i18n("Custom color" ), QColor( 255, 255, 255 ) ); addColor( i18n("Default" ), defaultValue ); for( int i=0; i != addColNum; i++ ) { additionalColors.push_back( addColPtr[i] ); addColor( addColPtr[i].name, addColPtr[i].color ); } addColor( i18n("Red" ), Qt::red ); addColor( i18n("Green" ), Qt::green ); addColor( i18n("Blue" ), Qt::blue ); addColor( i18n("Cyan" ), Qt::cyan ); addColor( i18n("Magenta" ), Qt::magenta ); addColor( i18n("Yellow" ), Qt::yellow ); addColor( i18n("Dark Red" ), Qt::darkRed ); addColor( i18n("Dark Green" ), Qt::darkGreen ); addColor( i18n("Dark Blue" ), Qt::darkBlue ); addColor( i18n("Dark Cyan" ), Qt::darkCyan ); addColor( i18n("Dark Magenta" ), Qt::darkMagenta ); addColor( i18n("Dark Yellow" ), Qt::darkYellow ); addColor( i18n("White" ), Qt::white ); addColor( i18n("Light Gray" ), Qt::lightGray ); addColor( i18n("Gray" ), Qt::gray ); addColor( i18n("Dark Gray" ), Qt::darkGray ); addColor( i18n("Black" ), Qt::black ); connect( this, SIGNAL( activated(int) ), this, SLOT( slotCurrentChanged( int ) ) ); loadInitialValue();}KonfiguratorColorChooser::~KonfiguratorColorChooser(){ delete ext;}QPixmap KonfiguratorColorChooser::createPixmap( QColor color ){ QPainter painter; QPen pen; int size = QFontMetrics(font()).height()*3/4; QRect rect( 0, 0, size, size ); QPixmap pixmap( rect.width(), rect.height() ); pen.setColor( Qt::black ); painter.begin( &pixmap ); QBrush brush( color ); painter.fillRect( rect, brush ); painter.setPen( pen ); painter.drawRect( rect ); painter.end(); pixmap.detach(); return pixmap;}void KonfiguratorColorChooser::addColor( QString text, QColor color ){ insertItem( createPixmap(color), text ); palette.push_back( color );}void KonfiguratorColorChooser::loadInitialValue(){ krConfig->setGroup( ext->getCfgClass() ); QString selected = krConfig->readEntry( ext->getCfgName(), "" ); setValue( selected ); ext->setChanged( false );}void KonfiguratorColorChooser::setDefaultColor( QColor dflt ){ defaultValue = dflt; palette[1] = defaultValue; changeItem( createPixmap( defaultValue ), text( 1 ), 1 ); if( currentItem() == 1 ) emit colorChanged();}void KonfiguratorColorChooser::changeAdditionalColor( unsigned int num, QColor color ){ if( num < additionalColors.size() ) { palette[2+num] = color; additionalColors[num].color = color; changeItem( createPixmap( color ), text( 2+num ), 2+num ); if( (unsigned int)currentItem() == 2+num ) emit colorChanged(); }}void KonfiguratorColorChooser::setDefaultText( QString text ){ changeItem( createPixmap( defaultValue ), text, 1 );}void KonfiguratorColorChooser::slotApply(QObject *,QString cls, QString name){ krConfig->setGroup( cls ); krConfig->writeEntry( name, getValue() );}void KonfiguratorColorChooser::setValue( QString value ){ disableColorChooser = true; if( value.isEmpty() ) { setCurrentItem( 1 ); customValue = defaultValue; } else { bool found = false; for( unsigned j=0; j != additionalColors.size(); j++ ) if( additionalColors[j].value == value ) { setCurrentItem( 2 + j ); found = true; break; } if( ! found ) { krConfig->setGroup( ext->getCfgClass() ); krConfig->writeEntry( "TmpColor", value ); QColor color = krConfig->readColorEntry( "TmpColor", &defaultValue ); customValue = color; krConfig->deleteEntry( "TmpColor" ); setCurrentItem( 0 ); for( unsigned i= 2+additionalColors.size(); i != palette.size(); i++ ) if( palette[i] == color ) { setCurrentItem( i ); break; } } } palette[0] = customValue; changeItem( createPixmap( customValue ), text( 0 ), 0 ); ext->setChanged(); emit colorChanged(); disableColorChooser = false;}QString KonfiguratorColorChooser::getValue(){ QColor color = palette[ currentItem() ]; if( currentItem() == 1 ) /* it's the default value? */ return ""; else if( currentItem() >= 2 && (unsigned)currentItem() < 2 + additionalColors.size() ) return additionalColors[ currentItem() - 2 ].value; else return QString( "%1,%2,%3" ).arg( color.red() ).arg( color.green() ).arg( color.blue() );}bool KonfiguratorColorChooser::isValueRGB(){ return !( currentItem() >= 1 && (unsigned)currentItem() < 2 + additionalColors.size() );}void KonfiguratorColorChooser::slotSetDefaults(QObject *){ ext->setChanged(); setCurrentItem( 1 ); emit colorChanged();}void KonfiguratorColorChooser::slotCurrentChanged( int number ){ ext->setChanged(); if( number == 0 && !disableColorChooser ) { QColor color = QColorDialog::getColor ( customValue, this, "ColorDialog" ); if( color.isValid() ) { disableColorChooser = true; customValue = color; palette[0] = customValue; changeItem( createPixmap( customValue ), text( 0 ), 0 ); disableColorChooser = false; } } emit colorChanged();}QColor KonfiguratorColorChooser::getColor(){ return palette[ currentItem() ];}// KonfiguratorListBox class///////////////////////////////KonfiguratorListBox::KonfiguratorListBox( QString cls, QString name, QStringList dflt, QWidget *parent, const char *widgetName, bool rst, int pg ) : QListBox( 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() ) ); loadInitialValue();}KonfiguratorListBox::~KonfiguratorListBox(){ delete ext;}void KonfiguratorListBox::loadInitialValue(){ krConfig->setGroup( ext->getCfgClass() ); setList( krConfig->readListEntry( ext->getCfgName().ascii(), defaultValue ) ); ext->setChanged( false );}void KonfiguratorListBox::slotApply(QObject *,QString cls, QString name){ krConfig->setGroup( cls ); krConfig->writeEntry( name, list() );}void KonfiguratorListBox::slotSetDefaults(QObject *){ if( list() != defaultValue ) { ext->setChanged(); setList( defaultValue ); }}void KonfiguratorListBox::setList( QStringList list ){ clear(); insertStringList( list );}QStringList KonfiguratorListBox::list(){ QStringList lst; for( unsigned i=0; i != count(); i++ ) lst += text( i ); return lst;}void KonfiguratorListBox::addItem( const QString & item ){ if( !list().contains( item ) ) { insertItem( item ); ext->setChanged(); }}void KonfiguratorListBox::removeItem( const QString & item ){ QListBoxItem * listItem = findItem( item ); if( listItem != 0 ) { takeItem( listItem ); ext->setChanged(); }}#include "konfiguratoritems.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -