diff options
author | Mavridis Philippe <mavridisf@gmail.com> | 2021-05-01 15:14:43 +0300 |
---|---|---|
committer | Mavridis Philippe <mavridisf@gmail.com> | 2021-05-16 16:02:45 +0300 |
commit | 63b5e825b82b0f6936a97865d1907c5998f302af (patch) | |
tree | 6396d5da047f12b3575700d041f8dc8ccf06e173 /kxkb/pixmap.cpp | |
parent | 3419424baa9c910ba9b9ef7dbc7017451867fcdc (diff) | |
download | tdebase-63b5e825b82b0f6936a97865d1907c5998f302af.tar.gz tdebase-63b5e825b82b0f6936a97865d1907c5998f302af.zip |
Added customization options for Kxkb
Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>
Diffstat (limited to 'kxkb/pixmap.cpp')
-rw-r--r-- | kxkb/pixmap.cpp | 168 |
1 files changed, 105 insertions, 63 deletions
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 <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 ) { @@ -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; } |