From 44ae59c0d9c38e3c4f1080fe813289754d498b02 Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Wed, 12 May 2021 14:42:00 +0300 Subject: Re-set previous layout after changing layout settings. Signed-off-by: Mavridis Philippe --- kxkb/kcmlayout.cpp | 89 ++++++++++++++++++-------- kxkb/pixmap.cpp | 184 ++++++++++++++++++++++++++--------------------------- 2 files changed, 153 insertions(+), 120 deletions(-) diff --git a/kxkb/kcmlayout.cpp b/kxkb/kcmlayout.cpp index def7e1048..682ea10da 100644 --- a/kxkb/kcmlayout.cpp +++ b/kxkb/kcmlayout.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "extension.h" #include "kxkbconfig.h" @@ -197,7 +199,7 @@ void LayoutConfig::initUI() { TQValueList otherLayouts = m_kxkbConfig.m_layouts; widget->listLayoutsDst->clear(); -// to optimize we should have gone from it.end to it.begin + // to optimize we should have gone from it.end to it.begin TQValueList::ConstIterator it; for (it = otherLayouts.begin(); it != otherLayouts.end(); ++it ) { TQListViewItemIterator src_it( widget->listLayoutsSrc ); @@ -223,21 +225,21 @@ void LayoutConfig::initUI() { // display KXKB switching options widget->chkShowSingle->setChecked(m_kxkbConfig.m_showSingle); - bool showFlag = m_kxkbConfig.m_showFlag; - bool showLabel = m_kxkbConfig.m_showLabel; - widget->radFlagLabel->setChecked( showFlag && showLabel ); - widget->radFlagOnly->setChecked( showFlag && !showLabel ); - widget->radLabelOnly->setChecked( !showFlag && showLabel ); + bool showFlag = m_kxkbConfig.m_showFlag; + bool showLabel = m_kxkbConfig.m_showLabel; + widget->radFlagLabel->setChecked( showFlag && showLabel ); + widget->radFlagOnly->setChecked( showFlag && !showLabel ); + widget->radLabelOnly->setChecked( !showFlag && showLabel ); widget->chkEnableOptions->setChecked( m_kxkbConfig.m_enableXkbOptions ); widget->checkResetOld->setChecked(m_kxkbConfig.m_resetOldOptions); - widget->grpLabel->setButton( ( m_kxkbConfig.m_useThemeColors ? 0 : 1 ) ); - widget->bgColor->setColor( m_kxkbConfig.m_colorBackground ); - widget->fgColor->setColor( m_kxkbConfig.m_colorLabel ); - widget->labelFont->setFont( m_kxkbConfig.m_labelFont ); - widget->chkLabelShadow->setChecked( m_kxkbConfig.m_labelShadow ); - widget->shColor->setColor( m_kxkbConfig.m_colorShadow ); + widget->grpLabel->setButton( ( m_kxkbConfig.m_useThemeColors ? 0 : 1 ) ); + widget->bgColor->setColor( m_kxkbConfig.m_colorBackground ); + widget->fgColor->setColor( m_kxkbConfig.m_colorLabel ); + widget->labelFont->setFont( m_kxkbConfig.m_labelFont ); + widget->chkLabelShadow->setChecked( m_kxkbConfig.m_labelShadow ); + widget->shColor->setColor( m_kxkbConfig.m_colorShadow ); switch( m_kxkbConfig.m_switchingPolicy ) { default: @@ -296,14 +298,14 @@ void LayoutConfig::save() m_kxkbConfig.m_enableXkbOptions = widget->chkEnableOptions->isChecked(); m_kxkbConfig.m_resetOldOptions = widget->checkResetOld->isChecked(); - m_kxkbConfig.m_options = createOptionString(); + m_kxkbConfig.m_options = createOptionString(); - m_kxkbConfig.m_useThemeColors = widget->radLabelUseTheme->isChecked(); - m_kxkbConfig.m_colorBackground = widget->bgColor->color(); - m_kxkbConfig.m_colorLabel = widget->fgColor->color(); - m_kxkbConfig.m_labelFont = widget->labelFont->font(); - m_kxkbConfig.m_labelShadow = widget->chkLabelShadow->isChecked(); - m_kxkbConfig.m_colorShadow = widget->shColor->color(); + m_kxkbConfig.m_useThemeColors = widget->radLabelUseTheme->isChecked(); + m_kxkbConfig.m_colorBackground = widget->bgColor->color(); + m_kxkbConfig.m_colorLabel = widget->fgColor->color(); + m_kxkbConfig.m_labelFont = widget->labelFont->font(); + m_kxkbConfig.m_labelShadow = widget->chkLabelShadow->isChecked(); + m_kxkbConfig.m_colorShadow = widget->shColor->color(); TQListViewItem *item = widget->listLayoutsDst->firstChild(); TQValueList layouts; @@ -333,8 +335,8 @@ void LayoutConfig::save() m_kxkbConfig.m_useKxkb = widget->chkEnable->isChecked(); m_kxkbConfig.m_showSingle = widget->chkShowSingle->isChecked(); - m_kxkbConfig.m_showFlag = ( widget->radFlagLabel->isChecked() || widget->radFlagOnly->isChecked() ); - m_kxkbConfig.m_showLabel = ( widget->radFlagLabel->isChecked() || widget->radLabelOnly->isChecked() ); + m_kxkbConfig.m_showFlag = ( widget->radFlagLabel->isChecked() || widget->radFlagOnly->isChecked() ); + m_kxkbConfig.m_showLabel = ( widget->radFlagLabel->isChecked() || widget->radLabelOnly->isChecked() ); int modeId = widget->grpSwitching->id(widget->grpSwitching->selected()); switch( modeId ) { @@ -355,7 +357,38 @@ void LayoutConfig::save() m_kxkbConfig.save(); - kapp->tdeinitExec("kxkb"); + // Get current layout from Kxkb + if (!kapp->dcopClient()->isAttached()) + kapp->dcopClient()->attach(); + + DCOPRef kxkbref("kxkb", "kxkb"); + DCOPReply reply = kxkbref.call( "getCurrentLayout" ); + + TQString currentLayout; + if ( reply.isValid() ) { + reply.get(currentLayout); + } else { + kdDebug() << "Warning: cannot get current layout! (invalid DCOP reply from Kxkb)" << endl; + } + + // Cause Kxkb to reread configuration + kapp->tdeinitExecWait("kxkb"); + + // If previous call was valid, try to change layout + if ( reply.isValid() ) { + DCOPReply successReply = kxkbref.call( "setLayout", currentLayout ); + + if ( successReply.isValid() ) { + bool success; + successReply.get(success); + + if ( ! success ) + kdDebug() << "Warning: restoring previous layout failed!" << endl; + } else { + kdDebug() << "Warning: cannot restore previous layout! (invalid DCOP reply from Kxkb)" << endl; + } + } + emit TDECModule::changed( false ); } @@ -461,12 +494,12 @@ void LayoutConfig::moveDown() void LayoutConfig::variantChanged() { - TQListViewItem* selLayout = widget->listLayoutsDst->selectedItem(); - if( selLayout == NULL ) { - widget->comboVariant->clear(); - widget->comboVariant->setEnabled(false); - return; - } + TQListViewItem* selLayout = widget->listLayoutsDst->selectedItem(); + if( selLayout == NULL ) { + widget->comboVariant->clear(); + widget->comboVariant->setEnabled(false); + return; + } TQString selectedVariant = widget->comboVariant->currentText(); if( selectedVariant == DEFAULT_VARIANT_NAME ) diff --git a/kxkb/pixmap.cpp b/kxkb/pixmap.cpp index 084a6980c..4a3e6aff2 100644 --- a/kxkb/pixmap.cpp +++ b/kxkb/pixmap.cpp @@ -36,44 +36,44 @@ LayoutIcon::LayoutIcon(): const TQPixmap& LayoutIcon::findPixmap(const TQString& code_, int pixmapStyle, const TQString& displayName_) { - m_kxkbConfig.load(KxkbConfig::LOAD_ALL); // (re)load settings - - if (m_kxkbConfig.m_useThemeColors) { // use colors from color scheme - m_bgColor = TDEGlobalSettings::highlightColor(); - m_fgColor = TDEGlobalSettings::highlightedTextColor(); - } else { - m_bgColor = m_kxkbConfig.m_colorBackground; - m_fgColor = m_kxkbConfig.m_colorLabel; - } - - m_labelFont = m_kxkbConfig.m_labelFont; - m_labelShadow = m_kxkbConfig.m_labelShadow; - m_shColor = m_kxkbConfig.m_colorShadow; - - // Decide on how to style the pixmap - switch(pixmapStyle) { - case PIXMAP_STYLE_NORMAL: - m_fitToBox = true; - m_showFlag = true; - m_showLabel = false; - break; - - case PIXMAP_STYLE_INDICATOR: - m_fitToBox = true; - m_showFlag = m_kxkbConfig.m_showFlag; - m_showLabel = m_kxkbConfig.m_showLabel; - break; - - case PIXMAP_STYLE_CONTEXTMENU: - m_fitToBox = false; // causes white color loss - m_showFlag = true; - m_showLabel = false; - break; - } - - // Label only mode is always 'fit to box' - if( m_showLabel && !m_showFlag ) - m_fitToBox = true; + m_kxkbConfig.load(KxkbConfig::LOAD_ALL); // (re)load settings + + if (m_kxkbConfig.m_useThemeColors) { // use colors from color scheme + m_bgColor = TDEGlobalSettings::highlightColor(); + m_fgColor = TDEGlobalSettings::highlightedTextColor(); + } else { + m_bgColor = m_kxkbConfig.m_colorBackground; + m_fgColor = m_kxkbConfig.m_colorLabel; + } + + m_labelFont = m_kxkbConfig.m_labelFont; + m_labelShadow = m_kxkbConfig.m_labelShadow; + m_shColor = m_kxkbConfig.m_colorShadow; + + // Decide on how to style the pixmap + switch(pixmapStyle) { + case PIXMAP_STYLE_NORMAL: + m_fitToBox = true; + m_showFlag = true; + m_showLabel = false; + break; + + case PIXMAP_STYLE_INDICATOR: + m_fitToBox = true; + m_showFlag = m_kxkbConfig.m_showFlag; + m_showLabel = m_kxkbConfig.m_showLabel; + break; + + case PIXMAP_STYLE_CONTEXTMENU: + m_fitToBox = false; // causes white color loss + m_showFlag = true; + m_showLabel = false; + break; + } + + // Label only mode is always 'fit to box' + if( m_showLabel && !m_showFlag ) + m_fitToBox = true; TQPixmap* pm = NULL; @@ -95,60 +95,60 @@ LayoutIcon::findPixmap(const TQString& code_, int pixmapStyle, const TQString& d displayName = displayName.left(3); const TQString pixmapKey( - TQString( m_showFlag ? "f" : "" ) + TQString( m_showLabel ? "l" : "" ) + TQString( m_labelShadow ? "s" : "" ) + "." + - m_labelFont.key() + "." + m_bgColor.name() + "." + m_fgColor.name() + "." + m_shColor.name() + '.' + code_ + "." + displayName - ); - - // Only use cache for indicator - if( pixmapStyle == PIXMAP_STYLE_INDICATOR ) { - pm = m_pixmapCache[pixmapKey]; - if( pm ) - return *pm; - } - - // Need to create new pixmap - pm = new TQPixmap(); - - if( m_fitToBox ) // Resize to box size - pm->resize(FLAG_MAX_DIM, FLAG_MAX_DIM); - - if( m_showFlag ) { - TQString countryCode = getCountryFromLayoutName( code_ ); - TQString flag = locate("locale", flagTemplate.arg(countryCode)); - - if( flag.isEmpty() ) { - pm->fill(m_bgColor); - m_showLabel = true; - } else { - if( m_fitToBox ) { // Resize flag - TQPainter p_(pm); - p_.drawPixmap(TQRect(0, 0, FLAG_MAX_DIM, FLAG_MAX_DIM), flag); - } else { // Show the flag as is - pm->load(flag); - } - - if( m_showLabel ) // only dim for label - dimPixmap( *pm ); - } - } else { - pm->fill(m_bgColor); - } - - if( m_showLabel ) { - TQPainter p(pm); - p.setFont(m_labelFont); - - if( m_labelShadow ) { - p.setPen(m_shColor); - p.drawText(1, 1, pm->width(), pm->height(), Qt::AlignCenter, displayName); - } - - p.setPen(m_fgColor); - p.drawText(0, 0, pm->width(), pm->height(), Qt::AlignCenter, displayName); - } - - if( pixmapStyle == PIXMAP_STYLE_INDICATOR ) - m_pixmapCache.insert(pixmapKey, pm); + TQString( m_showFlag ? "f" : "" ) + TQString( m_showLabel ? "l" : "" ) + TQString( m_labelShadow ? "s" : "" ) + "." + + m_labelFont.key() + "." + m_bgColor.name() + "." + m_fgColor.name() + "." + m_shColor.name() + '.' + code_ + "." + displayName + ); + + // Only use cache for indicator + if( pixmapStyle == PIXMAP_STYLE_INDICATOR ) { + pm = m_pixmapCache[pixmapKey]; + if( pm ) + return *pm; + } + + // Need to create new pixmap + pm = new TQPixmap(); + + if( m_fitToBox ) // Resize to box size + pm->resize(FLAG_MAX_DIM, FLAG_MAX_DIM); + + if( m_showFlag ) { + TQString countryCode = getCountryFromLayoutName( code_ ); + TQString flag = locate("locale", flagTemplate.arg(countryCode)); + + if( flag.isEmpty() ) { + pm->fill(m_bgColor); + m_showLabel = true; + } else { + if( m_fitToBox ) { // Resize flag + TQPainter p_(pm); + p_.drawPixmap(TQRect(0, 0, FLAG_MAX_DIM, FLAG_MAX_DIM), flag); + } else { // Show the flag as is + pm->load(flag); + } + + if( m_showLabel ) // only dim for label + dimPixmap( *pm ); + } + } else { + pm->fill(m_bgColor); + } + + if( m_showLabel ) { + TQPainter p(pm); + p.setFont(m_labelFont); + + if( m_labelShadow ) { + p.setPen(m_shColor); + p.drawText(1, 1, pm->width(), pm->height(), Qt::AlignCenter, displayName); + } + + p.setPen(m_fgColor); + p.drawText(0, 0, pm->width(), pm->height(), Qt::AlignCenter, displayName); + } + + if( pixmapStyle == PIXMAP_STYLE_INDICATOR ) + m_pixmapCache.insert(pixmapKey, pm); return *pm; } -- cgit v1.2.1