Added customization options for Kxkb

Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
pull/202/head
Mavridis Philippe 3 years ago
parent bbdeb170a4
commit eff93621da
No known key found for this signature in database
GPG Key ID: F8D2D7E2F989A494

@ -14,6 +14,8 @@
#include <tqbuttongroup.h>
#include <tqspinbox.h>
#include <tdefontrequester.h>
#include <kcolorbutton.h>
#include <kkeydialog.h>
#include <tdeglobal.h>
#include <tdeconfig.h>
@ -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()));
@ -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:
@ -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<LayoutUnit> 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 ) {
@ -720,7 +751,7 @@ void LayoutConfig::loadRules()
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;

@ -466,6 +466,214 @@
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TQButtonGroup" row="1" column="0">
<property name="name">
<cstring>grpStyle</cstring>
</property>
<property name="title">
<string>Indicator Style</string>
</property>
<property name="exclusive">
<bool>true</bool>
</property>
<property name="whatsThis" stdset="0">
<string>Here you can choose the way your keyboard layout indicator will look.</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TQRadioButton">
<property name="name">
<cstring>radFlagLabel</cstring>
</property>
<property name="text">
<string>&amp;Both Flag and Label</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="TQRadioButton">
<property name="name">
<cstring>radFlagOnly</cstring>
</property>
<property name="text">
<string>&amp;Flag Only</string>
</property>
</widget>
<widget class="TQRadioButton">
<property name="name">
<cstring>radLabelOnly</cstring>
</property>
<property name="text">
<string>&amp;Label Only</string>
</property>
</widget>
</vbox>
</widget>
<widget class="TQButtonGroup" row="1" column="1">
<property name="name">
<cstring>grpLabel</cstring>
</property>
<property name="title">
<string>Label Style</string>
</property>
<property name="whatsThis" stdset="0">
<string>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.</string>
</property>
<grid>
<widget class="TQRadioButton" row="0" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>radLabelUseTheme</cstring>
</property>
<property name="text">
<string>Use &amp;theme colors</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<widget class="TQRadioButton" row="1" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>radLabelUseCustom</cstring>
</property>
<property name="text">
<string>Use c&amp;ustom colors</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<spacer row="2" column="0">
<property name="name">
<cstring>spacer2</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Fixed</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="TQLabel" row="2" column="1">
<property name="name">
<cstring>labelBgColor</cstring>
</property>
<property name="text">
<string>Background color:</string>
</property>
<property name="whatsThis" stdset="0">
<string>This color will be used as the indicator's background unless the indicator was set to display a flag.</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="KColorButton" row="2" column="2">
<property name="name">
<cstring>bgColor</cstring>
</property>
<property name="whatsThis" stdset="0">
<string>This color will be used as the indicator's background unless the indicator was set to display a flag.</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<spacer row="3" column="0">
<property name="name">
<cstring>spacer2</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Fixed</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="TQLabel" row="3" column="1">
<property name="name">
<cstring>labelFgColor</cstring>
</property>
<property name="text">
<string>Text color:</string>
</property>
<property name="whatsThis" stdset="0">
<string>This color will be used to draw the language label on the indicator.</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="KColorButton" row="3" column="2">
<property name="name">
<cstring>fgColor</cstring>
</property>
<property name="whatsThis" stdset="0">
<string>This color will be used to draw the language label on the indicator.</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="KSeparator" row="4" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>separator1</cstring>
</property>
</widget>
<widget class="TQLabel" row="5" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>labelFontRequester</cstring>
</property>
<property name="text">
<string>Label font:</string>
</property>
<property name="whatsThis" stdset="0">
<string>This is the font which will be used by the layout indicator to draw the label.</string>
</property>
</widget>
<widget class="TDEFontRequester" row="5" column="2">
<property name="name">
<cstring>labelFont</cstring>
</property>
</widget>
<widget class="TQCheckBox" row="6" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>chkLabelShadow</cstring>
</property>
<property name="text">
<string>Enable shadow</string>
</property>
<property name="whatsThis" stdset="0">
<string>Draw a drop shadow behind the language label. In some cases this option can improve readability.</string>
</property>
</widget>
<widget class="KColorButton" row="6" column="2">
<property name="name">
<cstring>shColor</cstring>
</property>
<property name="whatsThis" stdset="0">
<string>The drop shadow behind the language label will be of this color.</string>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</grid>
</widget>
<widget class="TQButtonGroup" row="2" column="0">
<property name="name">
<cstring>grpSwitching</cstring>
@ -512,20 +720,6 @@
</widget>
</vbox>
</widget>
<widget class="TQCheckBox" row="1" column="0" rowspan="1" colspan="2">
<property name="name">
<cstring>chkShowFlag</cstring>
</property>
<property name="text">
<string>Show country flag</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="whatsThis" stdset="0">
<string>Shows country flag on background of layout name in tray icon</string>
</property>
</widget>
<widget class="TQGroupBox" row="2" column="1">
<property name="name">
<cstring>grpBoxStickySwitching</cstring>
@ -537,7 +731,7 @@
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="TQCheckBox" row="0" column="0" rowspan="1" colspan="2">
<widget class="TQCheckBox" row="0" column="0" rowspan="1" colspan="3">
<property name="name">
<cstring>chkEnableSticky</cstring>
</property>
@ -548,7 +742,24 @@
<string>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.</string>
</property>
</widget>
<widget class="TQLabel" row="1" column="0">
<spacer row="1" column="0">
<property name="name">
<cstring>spacer2</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Fixed</enum>
</property>
<property name="sizeHint">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget class="TQLabel" row="1" column="1">
<property name="name">
<cstring>textLabel1_5</cstring>
</property>
@ -562,7 +773,7 @@
<cstring>spinBox1</cstring>
</property>
</widget>
<widget class="TQSpinBox" row="1" column="1">
<widget class="TQSpinBox" row="1" column="2">
<property name="name">
<cstring>spinStickyDepth</cstring>
</property>
@ -575,6 +786,14 @@
<property name="minValue">
<number>2</number>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</grid>
</widget>
@ -698,6 +917,36 @@
<receiver>textLabel1_5</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>radLabelUseCustom</sender>
<signal>toggled(bool)</signal>
<receiver>bgColor</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>radLabelUseCustom</sender>
<signal>toggled(bool)</signal>
<receiver>fgColor</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>radLabelUseCustom</sender>
<signal>toggled(bool)</signal>
<receiver>labelBgColor</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>radLabelUseCustom</sender>
<signal>toggled(bool)</signal>
<receiver>labelFgColor</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>chkLabelShadow</sender>
<signal>toggled(bool)</signal>
<receiver>shColor</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>chkEnable</sender>
<signal>toggled(bool)</signal>
@ -708,6 +957,9 @@
<includes>
<include location="local" impldecl="in implementation">kiconloader.h</include>
<include location="local" impldecl="in implementation">kdialogbase.h</include>
<include location="local" impldecl="in implementation">kcolorbutton.h</include>
<include location="local" impldecl="in implementation">kseparator.h</include>
<include location="local" impldecl="in implementation">tdefontrequester.h</include>
</includes>
<pixmapfunction>SmallIcon</pixmapfunction>
<layoutdefaults spacing="6" margin="11"/>

@ -127,6 +127,14 @@ 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");
@ -216,7 +224,16 @@ 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]);

@ -14,6 +14,8 @@
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqcolor.h>
#include <tqfont.h>
#include <tqptrqueue.h>
#include <tqmap.h>
@ -94,12 +96,20 @@ public:
bool m_useKxkb;
bool m_showSingle;
bool m_showFlag;
bool m_showLabel;
bool m_enableXkbOptions;
bool m_resetOldOptions;
SwitchingPolicy m_switchingPolicy;
bool m_stickySwitching;
int m_stickySwitchingDepth;
bool m_useThemeColors;
TQColor m_colorBackground;
TQColor m_colorLabel;
TQFont m_labelFont;
bool m_labelShadow;
TQColor m_colorShadow;
TQString m_model;
TQString m_options;
TQValueList<LayoutUnit> m_layouts;

@ -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<LayoutUnit>& layouts, const XkbRules& rules)
{
// TDEPopupMenu* menu = contextMenu();
TQPopupMenu* menu = contextMenu;
TDEPopupMenu* menu = contextMenu;
// TQPopupMenu* menu = contextMenu;
// int index = menu->indexOf(0);
m_descriptionMap.clear();
@ -90,7 +90,7 @@ void KxkbLabelController::initLayoutList(const TQValueList<LayoutUnit>& layouts,
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]));

@ -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<LayoutUnit>& 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;

@ -6,16 +6,15 @@
#include <tqdict.h>
#include <kstandarddirs.h>
#include <tdeglobalsettings.h>
#include <tdelocale.h>
#include <kdebug.h>
#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 ) {
@ -59,54 +94,61 @@ LayoutIcon::findPixmap(const TQString& code_, bool showFlag, const TQString& dis
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;
}

@ -6,26 +6,42 @@
#include <tqdict.h>
#include <tqstring.h>
#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<TQPixmap> 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<TQPixmap> 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 B

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 B

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 B

After

Width:  |  Height:  |  Size: 99 B

Loading…
Cancel
Save