diff options
Diffstat (limited to 'kxkb/pixmap.cpp')
-rw-r--r-- | kxkb/pixmap.cpp | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/kxkb/pixmap.cpp b/kxkb/pixmap.cpp index 830625ca8..012350143 100644 --- a/kxkb/pixmap.cpp +++ b/kxkb/pixmap.cpp @@ -1,9 +1,11 @@ +#include <tqapplication.h> #include <tqimage.h> #include <tqbitmap.h> #include <tqfont.h> #include <tqpainter.h> #include <tqregexp.h> #include <tqdict.h> +#include <tqdrawutil.h> #include <kstandarddirs.h> #include <tdeglobalsettings.h> @@ -35,17 +37,18 @@ const TQPixmap& LayoutIconManager::find(const TQString& code_, int pixmapStyle, m_labelShadow = m_kxkbConfig->m_labelShadow; m_shColor = m_kxkbConfig->m_colorShadow; m_bgTransparent = m_kxkbConfig->m_bgTransparent; + m_fitToBox = m_kxkbConfig->m_fitToBox; + m_dimFlag = m_kxkbConfig->m_dimFlag && m_showFlag && m_showLabel; + m_bevel = m_kxkbConfig->m_bevel && !m_bgTransparent && pixmapStyle == PIXMAP_STYLE_INDICATOR; // 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; @@ -58,7 +61,7 @@ const TQPixmap& LayoutIconManager::find(const TQString& code_, int pixmapStyle, } // Label only mode is always 'fit to box' - if( m_showLabel && !m_showFlag ) + if (m_showLabel && !m_showFlag) m_fitToBox = true; TQPixmap* pm = NULL; @@ -74,57 +77,81 @@ const TQPixmap& LayoutIconManager::find(const TQString& code_, int pixmapStyle, TQString displayName(displayName_); - if( displayName.isEmpty() ) { + if (displayName.isEmpty()) { displayName = KxkbConfig::getDefaultDisplayName(code_); } - if( displayName.length() > 3 ) + if (displayName.length() > 3) displayName = displayName.left(3); const TQString pixmapKey( - TQString( m_showFlag ? "f" : "" ) + TQString( m_showLabel ? "l" : "" ) + TQString( m_labelShadow ? "s" : "" ) + "." + + TQString(m_showFlag ? "f" : "") + TQString(m_showLabel ? "l" : "") + TQString(m_labelShadow ? "s" : "") + "." + + TQString(m_fitToBox ? "F" : "") + TQString(m_dimFlag ? "D" : "") + TQString(m_bevel ? "B" : "") + "." + m_labelFont.key() + "." + ( m_bgTransparent ? "x" : m_bgColor.name() ) + "." + m_fgColor.name() + "." + m_shColor.name() + '.' + code_ + "." + displayName ); // Only use cache for indicator - if( pixmapStyle == PIXMAP_STYLE_INDICATOR ) { + if (pixmapStyle == PIXMAP_STYLE_INDICATOR) { pm = m_pixmapCache[pixmapKey]; - if( pm ) + if (pm) return *pm; } - // Need to create new pixmap - pm = new TQPixmap(); + pm = new TQPixmap(FLAG_MAX_DIM, FLAG_MAX_DIM); - if( m_fitToBox ) // Resize to box size - pm->resize(FLAG_MAX_DIM, FLAG_MAX_DIM); + TQRect r = pm->rect(); + TQPainter p_(pm); - if( m_showFlag ) { - TQString countryCode = getCountryFromLayoutName( code_ ); + if (m_showFlag) { + TQString countryCode = getCountryFromLayoutName(code_); TQString flag = locate("locale", flagTemplate.arg(countryCode)); - if( flag.isEmpty() ) { + 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); + TQPixmap fp(flag); + + if (m_dimFlag) // only dim for label + { + dimPixmap(fp); + } + + if (!m_fitToBox) { + r = TQRect((FLAG_MAX_DIM - fp.width()) / 2, (FLAG_MAX_DIM - fp.height()) / 2, fp.width(), fp.height()); + } + + TQRect fr(r); // flag rect might be smaller to accomodate the bevel + if (m_bevel) + { + fr.setX(fr.x() + 1); + fr.setY(fr.y() + 1); + fr.setWidth(fr.width() - 1); + fr.setHeight(fr.height() - 1); } - if( m_showLabel ) // only dim for label - dimPixmap( *pm ); + p_.drawPixmap(fr, fp); + + // If we don't stretch the flag, we need to apply a mask to it + if (!m_fitToBox) + { + TQPixmap fpmask(FLAG_MAX_DIM, FLAG_MAX_DIM); + TQPainter fpmaskp(&fpmask); + fpmask.fill(TQt::white); + fpmaskp.fillRect(r, TQt::black); + TQBitmap fpmask_; + fpmask_ = fpmask; + pm->setMask((TQBitmap)fpmask_); + } } } else { pm->fill(m_bgColor); } - if( m_showLabel ) { + if (m_showLabel) { TQPainter p(pm); p.setFont(m_labelFont); - if( m_labelShadow ) { + if (m_labelShadow) { p.setPen(m_shColor); p.drawText(1, 1, pm->width(), pm->height(), TQt::AlignCenter, displayName); } @@ -153,8 +180,14 @@ const TQPixmap& LayoutIconManager::find(const TQString& code_, int pixmapStyle, } } + if (m_bevel) + { + TQPainter p_(pm); + qDrawShadePanel(&p_, r.x(), r.y(), r.width(), r.height(), tqApp->palette().active(), false, 1, nullptr); + } + - if( pixmapStyle == PIXMAP_STYLE_INDICATOR ) + if (pixmapStyle == PIXMAP_STYLE_INDICATOR) m_pixmapCache.insert(pixmapKey, pm); return *pm; |