From eff93621daf43e9a7d3672175a6503a633e9d4a0 Mon Sep 17 00:00:00 2001 From: Mavridis Philippe Date: Sat, 1 May 2021 15:14:43 +0300 Subject: [PATCH] Added customization options for Kxkb Signed-off-by: Mavridis Philippe --- kxkb/kcmlayout.cpp | 115 ++++++++++------ kxkb/kcmlayoutwidget.ui | 286 +++++++++++++++++++++++++++++++++++++--- kxkb/kxkbconfig.cpp | 75 +++++++---- kxkb/kxkbconfig.h | 46 ++++--- kxkb/kxkbtraywindow.cpp | 26 ++-- kxkb/kxkbtraywindow.h | 6 +- kxkb/pixmap.cpp | 168 ++++++++++++++--------- kxkb/pixmap.h | 48 ++++--- l10n/cn/flag.png | Bin 178 -> 104 bytes l10n/gb/flag.png | Bin 240 -> 145 bytes l10n/hr/flag.png | Bin 204 -> 116 bytes l10n/pl/flag.png | Bin 153 -> 99 bytes 12 files changed, 569 insertions(+), 201 deletions(-) diff --git a/kxkb/kcmlayout.cpp b/kxkb/kcmlayout.cpp index a306f0a33..def7e1048 100644 --- a/kxkb/kcmlayout.cpp +++ b/kxkb/kcmlayout.cpp @@ -14,6 +14,8 @@ #include #include +#include +#include #include #include #include @@ -95,7 +97,7 @@ static TQListViewItem* copyLVI(const TQListViewItem* src, TQListView* parent) LayoutConfig::LayoutConfig(TQWidget *parent, const char *name) - : TDECModule(parent, name), + : TDECModule(parent, name), m_rules(NULL) { TQVBoxLayout *main = new TQVBoxLayout(this, 0, KDialog::spacingHint()); @@ -105,7 +107,7 @@ LayoutConfig::LayoutConfig(TQWidget *parent, const char *name) connect( TQT_TQOBJECT(widget->chkEnable), TQT_SIGNAL( toggled( bool )), TQT_TQOBJECT(this), TQT_SLOT(changed())); connect( TQT_TQOBJECT(widget->chkShowSingle), TQT_SIGNAL( toggled( bool )), TQT_TQOBJECT(this), TQT_SLOT(changed())); - connect( TQT_TQOBJECT(widget->chkShowFlag), TQT_SIGNAL( toggled( bool )), TQT_TQOBJECT(this), TQT_SLOT(changed())); + connect( TQT_TQOBJECT(widget->comboModel), TQT_SIGNAL(activated(int)), TQT_TQOBJECT(this), TQT_SLOT(changed())); connect( TQT_TQOBJECT(widget->listLayoutsSrc), TQT_SIGNAL(doubleClicked(TQListViewItem*,const TQPoint&, int)), @@ -130,7 +132,15 @@ LayoutConfig::LayoutConfig(TQWidget *parent, const char *name) connect( widget->btnDown, TQT_SIGNAL(clicked()), TQT_TQOBJECT(this), TQT_SLOT(changed())); connect( widget->btnDown, TQT_SIGNAL(clicked()), TQT_TQOBJECT(this), TQT_SLOT(moveDown())); + connect( widget->grpStyle, TQT_SIGNAL( clicked( int ) ), TQT_SLOT(changed())); connect( widget->grpSwitching, TQT_SIGNAL( clicked( int ) ), TQT_SLOT(changed())); + connect( widget->grpLabel, TQT_SIGNAL( clicked( int ) ), TQT_SLOT(changed())); + + connect( widget->bgColor, TQT_SIGNAL( changed(const TQColor&) ), TQT_TQOBJECT(this), TQT_SLOT(changed())); + connect( widget->fgColor, TQT_SIGNAL( changed(const TQColor&) ), TQT_TQOBJECT(this), TQT_SLOT(changed())); + connect( widget->labelFont, TQT_SIGNAL( fontSelected(const TQFont&) ), TQT_TQOBJECT(this), TQT_SLOT(changed())); + connect( widget->chkLabelShadow, TQT_SIGNAL( toggled( bool ) ), TQT_TQOBJECT(this), TQT_SLOT(changed())); + connect( widget->shColor, TQT_SIGNAL( changed(const TQColor&) ), TQT_TQOBJECT(this), TQT_SLOT(changed())); connect( widget->chkEnableSticky, TQT_SIGNAL(toggled(bool)), TQT_TQOBJECT(this), TQT_SLOT(changed())); connect( widget->spinStickyDepth, TQT_SIGNAL(valueChanged(int)), TQT_TQOBJECT(this), TQT_SLOT(changed())); @@ -148,7 +158,7 @@ LayoutConfig::LayoutConfig(TQWidget *parent, const char *name) widget->listLayoutsDst->setColumnWidthMode(LAYOUT_COLUMN_INCLUDE, TQListView::Manual); widget->listLayoutsDst->setColumnWidth(LAYOUT_COLUMN_INCLUDE, 0); // widget->listLayoutsDst->setColumnWidth(LAYOUT_COLUMN_DISPLAY_NAME, 0); - + widget->listLayoutsDst->setSorting(-1); #if 0 widget->listLayoutsDst->setResizeMode(TQListView::LastColumn); @@ -177,12 +187,12 @@ void LayoutConfig::load() initUI(); } - + void LayoutConfig::initUI() { const char* modelName = m_rules->models()[m_kxkbConfig.m_model]; if( modelName == NULL ) modelName = DEFAULT_MODEL; - + widget->comboModel->setCurrentText(i18n(modelName)); TQValueList otherLayouts = m_kxkbConfig.m_layouts; @@ -192,13 +202,13 @@ void LayoutConfig::initUI() { for (it = otherLayouts.begin(); it != otherLayouts.end(); ++it ) { TQListViewItemIterator src_it( widget->listLayoutsSrc ); LayoutUnit layoutUnit = *it; - + for ( ; src_it.current(); ++src_it ) { TQListViewItem* srcItem = src_it.current(); - + if ( layoutUnit.layout == src_it.current()->text(LAYOUT_COLUMN_MAP) ) { // check if current config knows about this layout TQListViewItem* newItem = copyLVI(srcItem, widget->listLayoutsDst); - + newItem->setText(LAYOUT_COLUMN_VARIANT, layoutUnit.variant); newItem->setText(LAYOUT_COLUMN_INCLUDE, layoutUnit.includeGroup); newItem->setText(LAYOUT_COLUMN_DISPLAY_NAME, layoutUnit.displayName); @@ -212,11 +222,23 @@ void LayoutConfig::initUI() { // display KXKB switching options widget->chkShowSingle->setChecked(m_kxkbConfig.m_showSingle); - widget->chkShowFlag->setChecked(m_kxkbConfig.m_showFlag); + + 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 ); + switch( m_kxkbConfig.m_switchingPolicy ) { default: case SWITCH_POLICY_GLOBAL: @@ -248,7 +270,7 @@ void LayoutConfig::initUI() { TQString optionKey = option.mid(0, option.find(':')); TQString optionName = m_rules->options()[option]; OptionListItem *item = m_optionGroups[i18n(optionKey.latin1())]; - + if (item != NULL) { OptionListItem *child = item->findChildItem( option ); @@ -274,7 +296,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(); TQListViewItem *item = widget->listLayoutsDst->firstChild(); TQValueList layouts; @@ -283,15 +312,15 @@ void LayoutConfig::save() TQString variant = item->text(LAYOUT_COLUMN_VARIANT); TQString includes = item->text(LAYOUT_COLUMN_INCLUDE); TQString displayName = item->text(LAYOUT_COLUMN_DISPLAY_NAME); - + LayoutUnit layoutUnit(layout, variant); layoutUnit.includeGroup = includes; layoutUnit.displayName = displayName; layouts.append( layoutUnit ); - + item = item->nextSibling(); - kdDebug() << "To save: layout " << layoutUnit.toPair() - << ", inc: " << layoutUnit.includeGroup + kdDebug() << "To save: layout " << layoutUnit.toPair() + << ", inc: " << layoutUnit.includeGroup << ", disp: " << layoutUnit.displayName << endl; } m_kxkbConfig.m_layouts = layouts; @@ -303,7 +332,9 @@ void LayoutConfig::save() m_kxkbConfig.m_useKxkb = widget->chkEnable->isChecked(); m_kxkbConfig.m_showSingle = widget->chkShowSingle->isChecked(); - m_kxkbConfig.m_showFlag = widget->chkShowFlag->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 ) { @@ -323,7 +354,7 @@ void LayoutConfig::save() m_kxkbConfig.m_stickySwitchingDepth = widget->spinStickyDepth->value(); m_kxkbConfig.save(); - + kapp->tdeinitExec("kxkb"); emit TDECModule::changed( false ); } @@ -347,11 +378,11 @@ void LayoutConfig::updateStickyLimit() { int layoutsCnt = widget->listLayoutsDst->childCount(); int maxDepth = layoutsCnt - 1; - + if( maxDepth < 2 ) { maxDepth = 2; } - + widget->spinStickyDepth->setMaxValue(maxDepth); /* if( value > maxDepth ) setValue(maxDepth);*/ @@ -366,7 +397,7 @@ void LayoutConfig::add() // Create a copy of the sel widget, as one might add the same layout more // than one time, with different variants. TQListViewItem* toadd = copyLVI(sel, widget->listLayoutsDst); - + // Turn on "Include Latin layout" for new language by default (bnc:204402) toadd->setText(LAYOUT_COLUMN_INCLUDE, "us"); @@ -376,12 +407,12 @@ void LayoutConfig::add() // disabling temporary: does not work reliable in Qt :( // widget->listLayoutsDst->setSelected(sel, true); // layoutSelChanged(sel); - + updateStickyLimit(); changed(); } -void LayoutConfig::remove() +void LayoutConfig::remove() { TQListViewItem* sel = widget->listLayoutsDst->selectedItem(); TQListViewItem* newSel = 0; @@ -456,15 +487,15 @@ void LayoutConfig::displayNameChanged(const TQString& newDisplayName) TQListViewItem* selLayout = widget->listLayoutsDst->selectedItem(); if( selLayout == NULL ) return; - + const LayoutUnit layoutUnitKey = getLayoutUnitKey( selLayout ); LayoutUnit& layoutUnit = *m_kxkbConfig.m_layouts.find(layoutUnitKey); - + TQString oldName = selLayout->text(LAYOUT_COLUMN_DISPLAY_NAME); - + if( oldName.isEmpty() ) oldName = KxkbConfig::getDefaultDisplayName( layoutUnit ); - + if( oldName != newDisplayName ) { kdDebug() << "setting label for " << layoutUnit.toPair() << " : " << newDisplayName << endl; selLayout->setText(LAYOUT_COLUMN_DISPLAY_NAME, newDisplayName); @@ -517,7 +548,7 @@ void LayoutConfig::layoutSelChanged(TQListViewItem *sel) TQString kbdLayout = layoutUnitKey.layout; // TODO: need better algorithm here for determining if needs us group - if ( ! m_rules->isSingleGroup(kbdLayout) + if ( ! m_rules->isSingleGroup(kbdLayout) || kbdLayout.startsWith("us") || kbdLayout.startsWith("en") ) { widget->chkLatin->setEnabled( false ); } @@ -533,11 +564,11 @@ void LayoutConfig::layoutSelChanged(TQListViewItem *sel) TQStringList vars = m_rules->getAvailableVariants(kbdLayout); kdDebug() << "layout " << kbdLayout << " has " << vars.count() << " variants" << endl; - + if( vars.count() > 0 ) { vars.prepend(DEFAULT_VARIANT_NAME); widget->comboVariant->insertStringList(vars); - + TQString variant = sel->text(LAYOUT_COLUMN_VARIANT); if( variant != NULL && variant.isEmpty() == false ) { widget->comboVariant->setCurrentText(variant); @@ -668,7 +699,7 @@ void LayoutConfig::updateLayoutCommand() layoutDisplayName = m_kxkbConfig.getDefaultDisplayName(LayoutUnit(kbdLayout, variant), single); } kdDebug() << "disp: '" << layoutDisplayName << "'" << endl; - + if( !variant.isEmpty() ) { setxkbmap += " -variant "; if( widget->chkLatin->isChecked() ) @@ -676,9 +707,9 @@ void LayoutConfig::updateLayoutCommand() setxkbmap += variant; } } - + widget->editCmdLine->setText(setxkbmap); - + widget->editDisplayName->setEnabled( sel != NULL ); widget->editDisplayName->setText(layoutDisplayName); } @@ -704,7 +735,7 @@ void LayoutConfig::loadRules() ++it; } modelsList.sort(); - + widget->comboModel->clear(); widget->comboModel->insertStringList(modelsList); widget->comboModel->setCurrentItem(0); @@ -713,20 +744,20 @@ void LayoutConfig::loadRules() widget->listLayoutsSrc->clear(); widget->listLayoutsDst->clear(); TQDictIterator it2(m_rules->layouts()); - + while (it2.current()) { TQString layout = it2.currentKey(); TQString layoutName = it2.current(); TQListViewItem *item = new TQListViewItem(widget->listLayoutsSrc); - - item->setPixmap(LAYOUT_COLUMN_FLAG, LayoutIcon::getInstance().findPixmap(layout, true)); + + item->setPixmap(LAYOUT_COLUMN_FLAG, LayoutIcon::getInstance().findPixmap(layout, false)); item->setText(LAYOUT_COLUMN_NAME, i18n(layoutName.latin1())); item->setText(LAYOUT_COLUMN_MAP, layout); ++it2; } widget->listLayoutsSrc->setSorting(LAYOUT_COLUMN_NAME); // from Qt3 TQListView sorts by language - + //TODO: reset options and xkb options } @@ -813,19 +844,19 @@ extern "C" { return new LayoutConfig(parent, "kcmlayout"); } - + KDE_EXPORT TDECModule *create_keyboard(TQWidget *parent, const char *) { return new KeyboardConfig(parent, "kcmlayout"); } - + KDE_EXPORT void init_keyboard() { KeyboardConfig::init_keyboard(); - + KxkbConfig m_kxkbConfig; m_kxkbConfig.load(KxkbConfig::LOAD_INIT_OPTIONS); - + if( m_kxkbConfig.m_useKxkb == true ) { kapp->startServiceByDesktopName("kxkb"); } @@ -916,7 +947,7 @@ extern "C" I18N_NOOP( "Left Alt key changes group" ); I18N_NOOP( "Left Ctrl key changes group" ); I18N_NOOP( "Compose Key" ); - + //these seem to be new in XFree86 4.4.0 I18N_NOOP("Shift with numpad keys works as in MS Windows."); I18N_NOOP("Special keys (Ctrl+Alt+) handled in a server."); diff --git a/kxkb/kcmlayoutwidget.ui b/kxkb/kcmlayoutwidget.ui index 2830c10e9..dc3350a87 100644 --- a/kxkb/kcmlayoutwidget.ui +++ b/kxkb/kcmlayoutwidget.ui @@ -466,6 +466,214 @@ unnamed + + + grpStyle + + + Indicator Style + + + true + + + Here you can choose the way your keyboard layout indicator will look. + + + + unnamed + + + + radFlagLabel + + + &Both Flag and Label + + + true + + + + + radFlagOnly + + + &Flag Only + + + + + radLabelOnly + + + &Label Only + + + + + + + grpLabel + + + Label Style + + + Here you can choose the way the label of your keyboard layout indicator will be displayed. These options are relevant even when labels are disabled, for locales where the flag is missing. + + + + + radLabelUseTheme + + + Use &theme colors + + + false + + + + + radLabelUseCustom + + + Use c&ustom colors + + + false + + + + + spacer2 + + + Horizontal + + + Fixed + + + + 20 + 20 + + + + + + labelBgColor + + + Background color: + + + This color will be used as the indicator's background unless the indicator was set to display a flag. + + + false + + + + + bgColor + + + This color will be used as the indicator's background unless the indicator was set to display a flag. + + + false + + + + + spacer2 + + + Horizontal + + + Fixed + + + + 20 + 20 + + + + + + labelFgColor + + + Text color: + + + This color will be used to draw the language label on the indicator. + + + false + + + + + fgColor + + + This color will be used to draw the language label on the indicator. + + + false + + + + + separator1 + + + + + labelFontRequester + + + Label font: + + + This is the font which will be used by the layout indicator to draw the label. + + + + + labelFont + + + + + chkLabelShadow + + + Enable shadow + + + Draw a drop shadow behind the language label. In some cases this option can improve readability. + + + + + shColor + + + The drop shadow behind the language label will be of this color. + + + false + + + + grpSwitching @@ -512,20 +720,6 @@ - - - chkShowFlag - - - Show country flag - - - true - - - Shows country flag on background of layout name in tray icon - - grpBoxStickySwitching @@ -537,7 +731,7 @@ unnamed - + chkEnableSticky @@ -548,7 +742,24 @@ If you have more than two layouts and turn this option on, switching with the keyboard shortcut or clicking on the kxkb indicator will only cycle through the last few layouts. You can specify the number of layouts to rotate below. You can still access all layouts by right-clicking on the kxkb indicator. - + + + spacer2 + + + Horizontal + + + Fixed + + + + 20 + 20 + + + + textLabel1_5 @@ -562,7 +773,7 @@ spinBox1 - + spinStickyDepth @@ -575,6 +786,14 @@ 2 + + + 7 + 0 + 0 + 0 + + @@ -698,6 +917,36 @@ textLabel1_5 setEnabled(bool) + + radLabelUseCustom + toggled(bool) + bgColor + setEnabled(bool) + + + radLabelUseCustom + toggled(bool) + fgColor + setEnabled(bool) + + + radLabelUseCustom + toggled(bool) + labelBgColor + setEnabled(bool) + + + radLabelUseCustom + toggled(bool) + labelFgColor + setEnabled(bool) + + + chkLabelShadow + toggled(bool) + shColor + setEnabled(bool) + chkEnable toggled(bool) @@ -708,6 +957,9 @@ kiconloader.h kdialogbase.h + kcolorbutton.h + kseparator.h + tdefontrequester.h SmallIcon diff --git a/kxkb/kxkbconfig.cpp b/kxkb/kxkbconfig.cpp index 517f0ccdd..a01fd6a0e 100644 --- a/kxkb/kxkbconfig.cpp +++ b/kxkb/kxkbconfig.cpp @@ -1,7 +1,7 @@ // // C++ Implementation: kxkbconfig // -// Description: +// Description: // // // Author: Andriy Rysin , (C) 2006 @@ -34,11 +34,11 @@ LayoutUnit KxkbConfig::getDefaultLayout() { if( m_layouts.size() == 0 ) return DEFAULT_LAYOUT_UNIT; - + return m_layouts[0]; } -bool KxkbConfig::load(int loadMode) +bool KxkbConfig::load(int loadMode) { TDEConfig *config = new TDEConfig("kxkbrc", true, false); config->setGroup("Layout"); @@ -46,13 +46,13 @@ bool KxkbConfig::load(int loadMode) // Even if the layouts have been disabled we still want to set Xkb options // user can always switch them off now in the "Options" tab m_enableXkbOptions = config->readBoolEntry("EnableXkbOptions", false); - + if( m_enableXkbOptions == true || loadMode == LOAD_ALL ) { m_resetOldOptions = config->readBoolEntry("ResetOldOptions", false); m_options = config->readEntry("Options", ""); kdDebug() << "Xkb options (enabled=" << m_enableXkbOptions << "): " << m_options << endl; } - + m_useKxkb = config->readBoolEntry("Use", false); kdDebug() << "Use kxkb " << m_useKxkb << endl; @@ -62,7 +62,7 @@ bool KxkbConfig::load(int loadMode) m_model = config->readEntry("Model", DEFAULT_MODEL); kdDebug() << "Model: " << m_model << endl; - + TQStringList layoutList; if( config->hasKey("LayoutList") ) { layoutList = config->readListEntry("LayoutList"); @@ -74,7 +74,7 @@ bool KxkbConfig::load(int loadMode) } if( layoutList.count() == 0 ) layoutList.append("us"); - + m_layouts.clear(); for(TQStringList::ConstIterator it = layoutList.begin(); it != layoutList.end() ; ++it) { m_layouts.append( LayoutUnit(*it) ); @@ -82,7 +82,7 @@ bool KxkbConfig::load(int loadMode) } kdDebug() << "Found " << m_layouts.count() << " layouts, default is " << getDefaultLayout().toPair() << endl; - + TQStringList displayNamesList = config->readListEntry("DisplayNames", ','); for(TQStringList::ConstIterator it = displayNamesList.begin(); it != displayNamesList.end() ; ++it) { TQStringList displayNamePair = TQStringList::split(':', *it ); @@ -127,7 +127,15 @@ bool KxkbConfig::load(int loadMode) m_showSingle = config->readBoolEntry("ShowSingle", false); m_showFlag = config->readBoolEntry("ShowFlag", true); - + m_showLabel = config->readBoolEntry("ShowLabel", true); + + m_useThemeColors = config->readBoolEntry("UseThemeColors", false); + m_colorBackground = config->readColorEntry("ColorBackground", new TQColor(TQt::gray)); + m_colorLabel = config->readColorEntry("ColorLabel", new TQColor(TQt::white)); + m_labelFont = config->readFontEntry("LabelFont", new TQFont("sans", 10, TQFont::Bold)); + m_labelShadow = config->readBoolEntry("LabelShadow", true); + m_colorShadow = config->readColorEntry("ColorShadow", new TQColor(TQt::black)); + TQString layoutOwner = config->readEntry("SwitchMode", "Global"); if( layoutOwner == "WinClass" ) { @@ -139,14 +147,14 @@ bool KxkbConfig::load(int loadMode) else /*if( layoutOwner == "Global" )*/ { m_switchingPolicy = SWITCH_POLICY_GLOBAL; } - + if( m_layouts.count() < 2 && m_switchingPolicy != SWITCH_POLICY_GLOBAL ) { kdWarning() << "Layout count is less than 2, using Global switching policy" << endl; m_switchingPolicy = SWITCH_POLICY_GLOBAL; } - + kdDebug() << "Layout owner mode " << layoutOwner << endl; - + m_stickySwitching = config->readBoolEntry("StickySwitching", false); m_stickySwitchingDepth = config->readEntry("StickySwitchingDepth", "2").toInt(); if( m_stickySwitchingDepth < 2 ) @@ -157,7 +165,7 @@ bool KxkbConfig::load(int loadMode) kdWarning() << "Layout count is less than 3, sticky switching will be off" << endl; m_stickySwitching = false; } - else + else if( (int)m_layouts.count() - 1 < m_stickySwitchingDepth ) { kdWarning() << "Sticky switching depth is more than layout count -1, adjusting..." << endl; m_stickySwitchingDepth = m_layouts.count() - 1; @@ -169,7 +177,7 @@ bool KxkbConfig::load(int loadMode) return true; } -void KxkbConfig::save() +void KxkbConfig::save() { TDEConfig *config = new TDEConfig("kxkbrc", false, false); config->setGroup("Layout"); @@ -183,18 +191,18 @@ void KxkbConfig::save() TQStringList layoutList; TQStringList includeList; TQStringList displayNamesList; - + TQValueList::ConstIterator it; for(it = m_layouts.begin(); it != m_layouts.end(); ++it) { const LayoutUnit& layoutUnit = *it; - + layoutList.append( layoutUnit.toPair() ); - + if( layoutUnit.includeGroup.isEmpty() == false ) { TQString incGroupUnit = TQString("%1:%2").arg(layoutUnit.toPair(), layoutUnit.includeGroup); includeList.append( incGroupUnit ); } - + TQString displayName( layoutUnit.displayName ); kdDebug() << " displayName " << layoutUnit.toPair() << " : " << displayName << endl; if( displayName.isEmpty() == false && displayName != layoutUnit.layout ) { @@ -202,13 +210,13 @@ void KxkbConfig::save() displayNamesList.append( displayName ); } } - + config->writeEntry("LayoutList", layoutList); kdDebug() << "Saving Layouts: " << layoutList << endl; - + config->writeEntry("IncludeGroups", includeList); kdDebug() << "Saving includeGroups: " << includeList << endl; - + // if( displayNamesList.empty() == false ) config->writeEntry("DisplayNames", displayNamesList); // else @@ -216,21 +224,30 @@ void KxkbConfig::save() config->writeEntry("Use", m_useKxkb); config->writeEntry("ShowSingle", m_showSingle); + config->writeEntry("ShowFlag", m_showFlag); + config->writeEntry("ShowLabel", m_showLabel); + + config->writeEntry("UseThemeColors", m_useThemeColors); + config->writeEntry("ColorBackground", m_colorBackground); + config->writeEntry("ColorLabel", m_colorLabel); + config->writeEntry("LabelFont", m_labelFont); + config->writeEntry("LabelShadow", m_labelShadow); + config->writeEntry("ColorShadow", m_colorShadow); config->writeEntry("SwitchMode", switchModes[m_switchingPolicy]); - + config->writeEntry("StickySwitching", m_stickySwitching); config->writeEntry("StickySwitchingDepth", m_stickySwitchingDepth); - // remove old options + // remove old options config->deleteEntry("Variants"); config->deleteEntry("Includes"); config->deleteEntry("Encoding"); config->deleteEntry("AdditionalEncodings"); config->deleteEntry("Additional"); config->deleteEntry("Layout"); - + config->sync(); delete config; @@ -252,7 +269,7 @@ void KxkbConfig::setDefaults() m_showFlag = true; m_switchingPolicy = SWITCH_POLICY_GLOBAL; - + m_stickySwitching = false; m_stickySwitchingDepth = 2; } @@ -271,7 +288,7 @@ TQStringList KxkbConfig::getLayoutStringList(/*bool compact*/) TQString KxkbConfig::getDefaultDisplayName(const TQString& code_) { TQString displayName; - + if( code_.length() <= 2 ) { displayName = code_; } @@ -281,13 +298,13 @@ TQString KxkbConfig::getDefaultDisplayName(const TQString& code_) TQString rightCode; if( sepPos != -1 ) rightCode = code_.mid(sepPos+1); - + if( rightCode.length() > 0 ) displayName = leftCode.left(2) + rightCode.left(1).lower(); else displayName = leftCode.left(3); } - + return displayName; } @@ -295,7 +312,7 @@ TQString KxkbConfig::getDefaultDisplayName(const LayoutUnit& layoutUnit, bool si { if( layoutUnit.variant == "" ) return getDefaultDisplayName( layoutUnit.layout ); - + TQString displayName = layoutUnit.layout.left(2); if( single == false ) displayName += layoutUnit.variant.left(1); diff --git a/kxkb/kxkbconfig.h b/kxkb/kxkbconfig.h index 82fe610c9..0f8c981ea 100644 --- a/kxkb/kxkbconfig.h +++ b/kxkb/kxkbconfig.h @@ -1,7 +1,7 @@ // // C++ Interface: kxkbconfig // -// Description: +// Description: // // // Author: Andriy Rysin , (C) 2006 @@ -14,13 +14,15 @@ #include #include +#include +#include #include #include /* Utility classes for per-window/per-application layout implementation */ -enum SwitchingPolicy { +enum SwitchingPolicy { SWITCH_POLICY_GLOBAL = 0, SWITCH_POLICY_WIN_CLASS = 1, SWITCH_POLICY_WINDOW = 2, @@ -29,12 +31,12 @@ enum SwitchingPolicy { -inline TQString createPair(TQString key, TQString value) +inline TQString createPair(TQString key, TQString value) { if( value.isEmpty() ) return key; return TQString("%1(%2)").arg(key, value); -} +} struct LayoutUnit { TQString layout; @@ -42,41 +44,41 @@ struct LayoutUnit { TQString includeGroup; TQString displayName; int defaultGroup; - + LayoutUnit() {} - + LayoutUnit(TQString layout_, TQString variant_): layout(layout_), variant(variant_) {} - + LayoutUnit(TQString pair) { setFromPair( pair ); } - + void setFromPair(const TQString& pair) { layout = parseLayout(pair); variant = parseVariant(pair); } - + TQString toPair() const { return createPair(layout, variant); } - + bool operator<(const LayoutUnit& lu) const { return layout m_layouts; LayoutUnit getDefaultLayout(); - + bool load(int loadMode); void save(); void setDefaults(); - + TQStringList getLayoutStringList(/*bool compact*/); static TQString getDefaultDisplayName(const TQString& code_); static TQString getDefaultDisplayName(const LayoutUnit& layoutUnit, bool single=false); -private: +private: static const TQMap parseIncludesMap(const TQStringList& pairList); }; diff --git a/kxkb/kxkbtraywindow.cpp b/kxkb/kxkbtraywindow.cpp index ec91df670..46b03da15 100644 --- a/kxkb/kxkbtraywindow.cpp +++ b/kxkb/kxkbtraywindow.cpp @@ -1,7 +1,7 @@ // // C++ Implementation: kxkbtraywindow // -// Description: +// Description: // // // Author: Andriy Rysin , (C) 2006 @@ -25,7 +25,7 @@ #include "kxkbconfig.h" -KxkbLabelController::KxkbLabelController(TQLabel* label_, TQPopupMenu* contextMenu_) : +KxkbLabelController::KxkbLabelController(TQLabel* label_, TDEPopupMenu* contextMenu_) : label(label_), contextMenu(contextMenu_), m_menuStartIndex(contextMenu_->count()), @@ -51,7 +51,7 @@ void KxkbLabelController::setPixmap(const TQPixmap& pixmap) void KxkbLabelController::setCurrentLayout(const LayoutUnit& layoutUnit) { setToolTip(m_descriptionMap[layoutUnit.toPair()]); - setPixmap( LayoutIcon::getInstance().findPixmap(layoutUnit.layout, m_showFlag, layoutUnit.displayName) ); + setPixmap( LayoutIcon::getInstance().findPixmap(layoutUnit.layout, PIXMAP_STYLE_INDICATOR, layoutUnit.displayName) ); } @@ -60,14 +60,14 @@ void KxkbLabelController::setError(const TQString& layoutInfo) TQString msg = i18n("Error changing keyboard layout to '%1'").arg(layoutInfo); setToolTip(msg); - label->setPixmap(LayoutIcon::getInstance().findPixmap("error", m_showFlag)); + label->setPixmap(LayoutIcon::getInstance().findPixmap("error", PIXMAP_STYLE_NORMAL)); } void KxkbLabelController::initLayoutList(const TQValueList& layouts, const XkbRules& rules) { -// TDEPopupMenu* menu = contextMenu(); - TQPopupMenu* menu = contextMenu; + TDEPopupMenu* menu = contextMenu; +// TQPopupMenu* menu = contextMenu; // int index = menu->indexOf(0); m_descriptionMap.clear(); @@ -80,30 +80,30 @@ void KxkbLabelController::initLayoutList(const TQValueList& layouts, } /* menu->removeItem(CONFIG_MENU_ID); menu->removeItem(HELP_MENU_ID);*/ - + TDEIconEffect iconeffect; - + int cnt = 0; TQValueList::ConstIterator it; for (it=layouts.begin(); it != layouts.end(); ++it) { const TQString layoutName = (*it).layout; const TQString variantName = (*it).variant; - - const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap(layoutName, m_showFlag, (*it).displayName); + + const TQPixmap& layoutPixmap = LayoutIcon::getInstance().findPixmap(layoutName, PIXMAP_STYLE_CONTEXTMENU, (*it).displayName); const TQPixmap pix = iconeffect.apply(layoutPixmap, TDEIcon::Small, TDEIcon::DefaultState); - + TQString fullName = i18n((rules.layouts()[layoutName])); if( variantName.isEmpty() == false ) fullName += " (" + variantName + ")"; contextMenu->insertItem(pix, fullName, START_MENU_ID + cnt, m_menuStartIndex + cnt); m_descriptionMap.insert((*it).toPair(), fullName); - + cnt++; } m_prevLayoutCount = cnt; - + // if show config, if show help if( menu->indexOf(CONFIG_MENU_ID) == -1 ) { contextMenu->insertSeparator(); diff --git a/kxkb/kxkbtraywindow.h b/kxkb/kxkbtraywindow.h index 38e42db5d..f451f6473 100644 --- a/kxkb/kxkbtraywindow.h +++ b/kxkb/kxkbtraywindow.h @@ -21,7 +21,7 @@ class TQLabel; -class TQPopupMenu; +class TDEPopupMenu; class XkbRules; /* This class is responsible for displaying flag/label for the layout, @@ -35,7 +35,7 @@ class KxkbLabelController: public QObject public: enum { START_MENU_ID = 100, CONFIG_MENU_ID = 130, HELP_MENU_ID = 131 }; - KxkbLabelController(TQLabel *label, TQPopupMenu* contextMenu); + KxkbLabelController(TQLabel *label, TDEPopupMenu* contextMenu); void initLayoutList(const TQValueList& layouts, const XkbRules& rule); void setCurrentLayout(const LayoutUnit& layout); @@ -55,7 +55,7 @@ public: private: TQLabel* label; - TQPopupMenu* contextMenu; + TDEPopupMenu* contextMenu; const int m_menuStartIndex; bool m_showFlag; diff --git a/kxkb/pixmap.cpp b/kxkb/pixmap.cpp index 8752c258a..084a6980c 100644 --- a/kxkb/pixmap.cpp +++ b/kxkb/pixmap.cpp @@ -6,16 +6,15 @@ #include #include +#include #include #include #include "pixmap.h" #include "x11helper.h" -#include "kxkbconfig.h" -static const int FLAG_MAX_WIDTH = 21; -static const int FLAG_MAX_HEIGHT = 14; +static const int FLAG_MAX_DIM = 24; const TQString LayoutIcon::flagTemplate("l10n/%1/flag.png"); const TQString& LayoutIcon::ERROR_CODE("error"); @@ -30,16 +29,52 @@ LayoutIcon& LayoutIcon::getInstance() { } LayoutIcon::LayoutIcon(): - m_pixmapCache(80), - m_labelFont("sans") + m_pixmapCache(80) { - m_labelFont.setPixelSize(10); - m_labelFont.setWeight(TQFont::Bold); } const TQPixmap& -LayoutIcon::findPixmap(const TQString& code_, bool showFlag, const TQString& displayName_) +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; + TQPixmap* pm = NULL; if( code_ == ERROR_CODE ) { @@ -52,61 +87,68 @@ LayoutIcon::findPixmap(const TQString& code_, bool showFlag, const TQString& dis } TQString displayName(displayName_); - + if( displayName.isEmpty() ) { displayName = KxkbConfig::getDefaultDisplayName(code_); } if( displayName.length() > 3 ) displayName = displayName.left(3); - const TQString pixmapKey( showFlag ? code_ + "." + displayName : displayName ); - - pm = m_pixmapCache[pixmapKey]; - if( pm ) - return *pm; - - TQString flag; - if( showFlag ) { - TQString countryCode = getCountryFromLayoutName( code_ ); - flag = locate("locale", flagTemplate.arg(countryCode)); - } - - if( flag.isEmpty() ) { - pm = new TQPixmap(FLAG_MAX_WIDTH, FLAG_MAX_HEIGHT); - pm->fill(Qt::gray); - } - else { - pm = new TQPixmap(flag); - dimPixmap( *pm ); - -#if 0 - if( pm->height() < FLAG_MAX_HEIGHT ) { - TQPixmap* pix = new TQPixmap(FLAG_MAX_WIDTH, FLAG_MAX_HEIGHT); - pix->fill( Qt::lightGray ); -// pix->fill( TQColor(tqRgba(127,127,127,255)) ); -// TQBitmap mask; -// mask.fill(1); -// pix->setMask(mask); - - int dy = (pix->height() - pm->height()) / 2; - copyBlt( pix, 0, dy, pm, 0, 0, -1, -1 ); -// TQPixmap* px = new TQPixmap(21, 14); -// px->convertFromImage(img);*/ - delete pm; - pm = pix; - } -#endif - } - - TQPainter p(pm); - p.setFont(m_labelFont); - - p.setPen(Qt::black); - p.drawText(1, 1, pm->width(), pm->height()-2, Qt::AlignCenter, displayName); - p.setPen(Qt::white); - p.drawText(0, 0, pm->width(), pm->height()-2, Qt::AlignCenter, displayName); - - m_pixmapCache.insert(pixmapKey, pm); + 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); return *pm; } @@ -117,7 +159,7 @@ LayoutIcon::findPixmap(const TQString& code_, bool showFlag, const TQString& dis TQString LayoutIcon::getCountryFromLayoutName(const TQString& layoutName) { TQString flag; - + if( X11Helper::areLayoutsClean() ) { // >= Xorg 6.9.0 if( layoutName == "mkd" ) flag = "mk"; @@ -178,8 +220,8 @@ TQString LayoutIcon::getCountryFromLayoutName(const TQString& layoutName) if( layoutName.endsWith("/jp") ) flag = "jp"; else - if( layoutName == "ml" || layoutName == "dev" || layoutName == "gur" - || layoutName == "guj" || layoutName == "kan" || layoutName == "ori" + if( layoutName == "ml" || layoutName == "dev" || layoutName == "gur" + || layoutName == "guj" || layoutName == "kan" || layoutName == "ori" || layoutName == "tel" || layoutName == "tml" || layoutName == "ben" ) // some Indian languages flag = "in"; else { @@ -189,8 +231,8 @@ TQString LayoutIcon::getCountryFromLayoutName(const TQString& layoutName) if( sepPos != -1 ) rightCode = layoutName.mid(sepPos+1); // kdDebug() << "layout name breakup: " << leftCode << ":" << rightCode << endl; - - if( rightCode.length() == 2 + + if( rightCode.length() == 2 && TQRegExp("[A-Z][A-Z]").exactMatch(rightCode) ) { flag = rightCode.lower(); } @@ -199,7 +241,7 @@ TQString LayoutIcon::getCountryFromLayoutName(const TQString& layoutName) } } } - + return flag; } diff --git a/kxkb/pixmap.h b/kxkb/pixmap.h index 7070d91b2..2fd6c2a3c 100644 --- a/kxkb/pixmap.h +++ b/kxkb/pixmap.h @@ -6,26 +6,42 @@ #include #include +#include "kxkbconfig.h" + +enum PixmapStyle { + PIXMAP_STYLE_NORMAL = 0, + PIXMAP_STYLE_INDICATOR = 1, + PIXMAP_STYLE_CONTEXTMENU = 2 +}; class LayoutIcon { private: - static LayoutIcon* instance; - static const TQString flagTemplate; - - TQDict m_pixmapCache; - TQFont m_labelFont; - - LayoutIcon(); - TQPixmap* createErrorPixmap(); - void dimPixmap(TQPixmap& pixmap); - TQString getCountryFromLayoutName(const TQString& layoutName); - - public: - static const TQString& ERROR_CODE; - - static LayoutIcon& getInstance(); - const TQPixmap& findPixmap(const TQString& code, bool showFlag, const TQString& displayName=""); + static LayoutIcon* instance; + static const TQString flagTemplate; + + KxkbConfig m_kxkbConfig; + bool m_showFlag; + bool m_showLabel; + TQColor m_bgColor; + TQColor m_fgColor; + TQFont m_labelFont; + bool m_labelShadow; + TQColor m_shColor; + bool m_fitToBox; + + TQDict m_pixmapCache; + + LayoutIcon(); + TQPixmap* createErrorPixmap(); + void dimPixmap(TQPixmap& pixmap); + TQString getCountryFromLayoutName(const TQString& layoutName); + +public: + static const TQString& ERROR_CODE; + + static LayoutIcon& getInstance(); + const TQPixmap& findPixmap(const TQString& code, int pixmapStyle, const TQString& displayName=""); }; #endif diff --git a/l10n/cn/flag.png b/l10n/cn/flag.png index dfc481b7e52733bee7107fb9ff15072c350cdce2..b6af69a5b8af88135b5305741dc8f273dba59a0d 100644 GIT binary patch delta 86 zcmdnQm@z>jfRUMjf#KJQqrE_iEx;$l^*;l{|Njg*^0(&zMPxl)978y+Cnqp4sj+bg nuso7d*v63LyF$W;kC%Z#S&QLwwvz4xph5;uS3j3^P6jfzcxQ13v=;16xUuUogV~5bUkky$d9glFz z(KvrL(2|cqf#dc6_@n1vCG>b%G+B8_G+c6GVA)vRD8s9`cR0Z p#EzyzJD4PaQ<} hyLw%A+3}B-eha$JcYd1I!vS<2gQu&X%Q~loCIIIAU@`yz diff --git a/l10n/hr/flag.png b/l10n/hr/flag.png index 6af0f205e8e4307a1d85fe30b75a930f9ebcb1e2..67b6572c437fd2920f83335b4bfb0b2d5c45adf9 100644 GIT binary patch delta 98 zcmX@ZSTaE(hKZShfnjgP{#YQz8Q>G*%D~X@pMl~3|Nrm#``!Qr)jVAsLpZJ{bFeb9 zv&o1wYfOmRn)Pf|D6fN-F1L^3X9)=v$q&p7(__UA4l7+=3Dm*h>FVdQ&MBb@0LO|R ADF6Tf delta 187 zcmXRp!#F{ro`Z>jfzcxQ13v=;16xUuUogV~5bUkky$d9g}$dRwXfaCS$+Nk<4e&^PcM_4btVbGjn#38{@AmP@u`RTk? zKdC1AhqJTK<=STVwkog4K55OgRhzCCNt(WAt?TmFxxe9k`_9#K7x(;q%p?3~_Plkc i_3vogyG=hIH|Op1vni>MD}{k}GkCiCxvXiV|9)o-U3d9M_X0SebZvTmlvQK$!8;-MT+O zLG}_)Usv|?JmNe&7At>t2>^w}JY5_^IHHpSnwZ(xylylVI7mu!GB7j+aew805*H3s O!QkoY=d#Wzp$P!KCmvb=