diff -u -r kdebase-3.5.6/kicker.orig/kicker/buttons/kbutton.cpp kdebase-3.5.6/kicker/kicker/buttons/kbutton.cpp --- kdebase-3.5.6/kicker.orig/kicker/buttons/kbutton.cpp 2005-09-10 05:25:31.000000000 -0300 +++ kdebase-3.5.6/kicker/kicker/buttons/kbutton.cpp 2007-03-07 09:31:09.000000000 -0300 @@ -26,6 +26,14 @@ #include <klocale.h> #include <kapplication.h> #include <kdebug.h> +#include <kiconloader.h> +#include <qimage.h> +#include <qpixmap.h> +#include <krootpixmap.h> +#include <qcolor.h> +#include <qpainter.h> +#include <qdragobject.h> +#include <kglobalsettings.h> #include "kickerSettings.h" @@ -45,13 +53,21 @@ setPopup(MenuManager::the()->kmenu()); MenuManager::the()->registerKButton(this); - setIcon("kmenu"); + + KConfig* config = KGlobal::config(); + config->setGroup("KMenu"); + QString iconname = config->readEntry( "KMenuIcon", "kmenu" ); + //if( QApplication::reverseLayout() && orientation() == Horizontal ) + // iconname += iconname.append( "-rtl" ); + setIcon( iconname, + config->readBoolEntry( "KMenuButtonScale", true ) ); + setButtonRotation( config->readBoolEntry( "KMenuButtonRotate", false ) ); if (KickerSettings::showKMenuText()) { - setButtonText(KickerSettings::kMenuText()); - setFont(KickerSettings::buttonFont()); - setTextColor(KickerSettings::buttonTextColor()); + setButtonText( KickerSettings::kMenuText() ); + setTextColor( KickerSettings::kMenuTextColor() ); + setTextFont( KickerSettings::kMenuTextFont() ); } } diff -u -r kdebase-3.5.6/kicker.orig/kicker/core/container_button.cpp kdebase-3.5.6/kicker/kicker/core/container_button.cpp --- kdebase-3.5.6/kicker.orig/kicker/core/container_button.cpp 2007-01-15 09:31:29.000000000 -0200 +++ kdebase-3.5.6/kicker/kicker/core/container_button.cpp 2007-03-07 09:31:09.000000000 -0300 @@ -380,10 +380,7 @@ int KMenuButtonContainer::heightForWidth( int width ) const { - if ( width < 32 ) - return width + 10; - else - return ButtonContainer::heightForWidth(width); + return ButtonContainer::heightForWidth(width); } // DesktopButton container diff -u -r kdebase-3.5.6/kicker.orig/libkicker/global.cpp kdebase-3.5.6/kicker/libkicker/global.cpp --- kdebase-3.5.6/kicker.orig/libkicker/global.cpp 2006-03-17 07:17:31.000000000 -0300 +++ kdebase-3.5.6/kicker/libkicker/global.cpp 2007-03-07 09:31:09.000000000 -0300 @@ -156,7 +156,7 @@ int maxButtonDim() { - return (2 * KickerSettings::iconMargin()) + KIcon::SizeLarge; + return (2 * KickerSettings::iconMargin()) + KIcon::SizeHuge; } QString newDesktopFile(const KURL& url) diff -u -r kdebase-3.5.6/kicker.orig/libkicker/kickerSettings.kcfg kdebase-3.5.6/kicker/libkicker/kickerSettings.kcfg --- kdebase-3.5.6/kicker.orig/libkicker/kickerSettings.kcfg 2006-10-07 11:23:10.000000000 -0300 +++ kdebase-3.5.6/kicker/libkicker/kickerSettings.kcfg 2007-03-07 09:31:09.000000000 -0300 @@ -272,8 +272,28 @@ <entry name="KMenuText" key="Text" type="String" > <label>Text to be shown on K Menu Button</label> - <default code="true">i18n("Applications")</default> - </entry> + <default>Applications</default> +</entry> + +<entry name="KMenuTextRelativeXPos" key="TextRelativeXPos" type="UInt" > + <label>Relative horizontal position of text</label> + <default>0</default> +</entry> + +<entry name="KMenuTextRelativeYPos" key="TextRelativeYPos" type="UInt" > + <label>Relative Vertical position of text</label> + <default>0</default> +</entry> + +<entry name="KMenuTextFont" key="TextFont" type="Font" > + <label>Font for the buttons with text.</label> + <default code="true">KGlobalSettings::generalFont()</default> +</entry> + +<entry name="KMenuTextColor" key="TextColor" type="Color" > + <label>Text color for the buttons.</label> + <default code="true">KGlobalSettings::textColor()</default> +</entry> </group> @@ -325,10 +345,10 @@ <default>true</default> </entry> -<entry name="ButtonFont" key="Font" type="Font" > +<entry name="ButtonTextFont" key="TextFont" type="Font" > <label>Font for the buttons with text.</label> <default code="true">KGlobalSettings::generalFont()</default> - </entry> +</entry> <entry name="ButtonTextColor" key="TextColor" type="Color" > <label>Text color for the buttons.</label> diff -u -r kdebase-3.5.6/kicker.orig/libkicker/panelbutton.cpp kdebase-3.5.6/kicker/libkicker/panelbutton.cpp --- kdebase-3.5.6/kicker.orig/libkicker/panelbutton.cpp 2006-07-22 05:15:18.000000000 -0300 +++ kdebase-3.5.6/kicker/libkicker/panelbutton.cpp 2007-03-07 09:33:42.000000000 -0300 @@ -41,6 +41,7 @@ #include <kicontheme.h> #include <kipc.h> #include <kstandarddirs.h> +#include <kiconeffect.h> #include <klocale.h> #include "global.h" @@ -63,17 +64,20 @@ m_highlight(false), m_changeCursorOverItem(true), m_hasAcceptedDrag(false), + m_scaleButton(false), + m_rotateButton(false), m_arrowDirection(KPanelExtension::Bottom), m_popupDirection(KPanelApplet::Up), m_orientation(Horizontal), - m_size((KIcon::StdSizes)-1), - m_fontPercent(0.40) + m_size((KIcon::StdSizes)-1) { KGlobal::locale()->insertCatalogue("libkicker"); calculateIconSize(); setAcceptDrops(true); m_textColor = KGlobalSettings::textColor(); + + m_textFont = KickerSettings::kMenuTextFont(); updateSettings(KApplication::SETTINGS_MOUSE); @@ -264,36 +268,31 @@ // return the dimension that the button wants to be for a given panel dimension (panelDim) int PanelButton::preferredDimension(int panelDim) const { - // determine the upper limit on the size. Normally, this is panelDim, - // but if conserveSpace() is true, we restrict size to comfortably fit the icon - if (KickerSettings::conserveSpace()) - { - int newSize = preferredIconSize(panelDim); - if (newSize > 0) - { - return QMIN(panelDim, newSize + (KDialog::spacingHint() * 2)); - } - } - - return panelDim; + int newSize = panelDim; + + if ( KickerSettings::conserveSpace() ) + { + int preferred = preferredIconSize( panelDim ); + if ( preferred > 0 ) + { + newSize = QMIN( panelDim, preferred + ( KDialog::spacingHint() * 2 ) ); + } + } + + if ( m_rotateButton ) + { + return QMAX( newSize, QMAX( m_icon.width(), m_icon.height() ) ); + } + else + { + return QMAX( newSize, orientation() == Horizontal ? m_icon.width() : m_icon.height() ) ; + } } + int PanelButton::widthForHeight(int height) const { - int rc = preferredDimension(height); - - // we only paint the text when horizontal, so make sure we're horizontal - // before adding the text in here - if (orientation() == Horizontal && !m_buttonText.isEmpty()) - { - QFont f(font()); - f.setPixelSize(KMIN(height, KMAX(int(float(height) * m_fontPercent), 16))); - QFontMetrics fm(f); - - rc += fm.width(m_buttonText) + KMIN(25, KMAX(5, fm.width('m') / 2)); - } - - return rc; + return preferredDimension(height); } int PanelButton::heightForWidth(int width) const @@ -316,11 +315,22 @@ return m_valid; } +void PanelButton::setButtonRotation( bool r ) +{ + m_rotateButton = r; +} + void PanelButton::setTitle(const QString& t) { m_title = t; } +void PanelButton::setIcon(const QString& icon, bool scale ) +{ + m_scaleButton = scale; + setIcon( icon ); +} + void PanelButton::setIcon(const QString& icon) { if (icon == m_iconName) @@ -346,7 +356,7 @@ void PanelButton::setButtonText(const QString& text) { - m_buttonText = text; + m_buttonText = i18n( text.utf8() ); update(); } @@ -365,14 +375,14 @@ return m_textColor; } -void PanelButton::setFontPercent(double p) +void PanelButton::setTextFont(const QFont& f) { - m_fontPercent = p; + m_textFont = f; } -double PanelButton::fontPercent() const +QFont PanelButton::textFont() const { - return m_fontPercent; + return m_textFont; } KPanelExtension::Orientation PanelButton::orientation() const @@ -464,7 +474,6 @@ QPoint p(e->pos() - m_lastLeftMouseButtonPress); if (p.manhattanLength() <= 16) { - // KGlobalSettings::dndEventDelay() is not enough! return; } @@ -544,87 +549,183 @@ QPixmap icon = labelIcon(); bool active = isDown() || isOn(); + //if ( QApplication::reverseLayout() && orientation() == Horizontal ) + //{ + // icon = icon.convertToImage().mirror( true, false ); + //} + if (active) { - icon = icon.convertToImage().smoothScale(icon.width() - 2, - icon.height() - 2); + icon = icon.convertToImage().smoothScale(icon.width() - 2, icon.height() - 2); + } + + int w = width(); + int h = height(); + int y = 0; + int x = (w - icon.width()) / 2; + + if ( ! m_scaleButton ) + { + y = ( h - icon.height() ) / 2; } - if (!m_buttonText.isEmpty() && orientation() == Horizontal) + int relx = KickerSettings::kMenuTextRelativeXPos(); + int rely = KickerSettings::kMenuTextRelativeYPos(); + + if ( !m_buttonText.isEmpty() ) { - int h = height(); - int w = width(); - int y = (h - icon.height())/2; + // We always rotate button when apply text + m_rotateButton = true; + if ( orientation() == Vertical) + { + x = 0; + y = m_scaleButton ? + 0 - icon.height() : + 0 - w + ( ( w - icon.height() ) / 2 ) + 2; + p->rotate( 90 ); + } + p->save(); - QFont f = font(); + + QFont f = m_textFont; + QFontMetrics fm(f); - double fontPercent = m_fontPercent; - if (active) + // Test possible text size to see if fits on bitmap size plus + // possible relx diference. If not reduce font size + if ( orientation() == Horizontal ) { - fontPercent *= .8; + while ( fm.width( m_buttonText, m_buttonText.length() ) > ( w - relx - 8 ) ) + { + if ( ( f.pointSize() -1 ) <= 0 ) + { + break; + } + f.setPointSize( f.pointSize() - 1 ); + fm = QFontMetrics( f ); + } } - f.setPixelSize(KMIN(h, KMAX(int(float(h) * m_fontPercent), 16))); - QFontMetrics fm(f); + else + { + while ( fm.width( m_buttonText, m_buttonText.length() ) > ( h - relx - 8 ) ) + { + if ( ( f.pointSize() -1 ) <= 0 ) + { + break; + } + f.setPointSize( f.pointSize() -1 ); + fm = QFontMetrics( f ); + } + } + p->setFont(f); /* Draw shadowed text */ bool reverse = QApplication::reverseLayout(); QPainter::TextDirection rtl = reverse ? QPainter::RTL : QPainter::LTR; - - if (!reverse && !icon.isNull()) + + if ( !icon.isNull() ) { - /* Draw icon */ - p->drawPixmap(3, y, icon); + if ( !reverse || orientation() == Vertical ) + { + p->drawPixmap(x, y, icon); + } + else + { + p->drawPixmap(w - icon.width(), y, icon); + } } - int tX = reverse ? 3 : icon.width() + KMIN(25, KMAX(5, fm.width('m') / 2)); - int tY = fm.ascent() + ((h - fm.height()) / 2); + int tX = icon.width() + KMIN( 25, KMAX( 5, fm.width( 'm' ) / 2 ) ); + if ( relx > 0 ) + { + tX = orientation() == Vertical ? + ( ( h * relx ) / 100 ) + 2 : + ( ( w * relx ) / 100 ) + 2; + } + int tY = fm.ascent() + ( ( h - fm.height() ) / 2 ); + if ( orientation() == Vertical) + { + tY = m_scaleButton ? + 0 - ( w / 2 ) + ( fm.height() /4 ) : + 0 - ( w - icon.height() ) /2 - ( icon.height() - fm.height() ) / 2 - fm.height()/4; + } + + if ( rely > 0 ) + { + tY = orientation() == Vertical ? + 0 - w + ( w * rely ) /100 + fm.height() / 2: + ( ( h * rely ) /100 ) + fm.height() / 2; + } + QColor shadCol = KickerLib::shadowColor(m_textColor); // get a transparent pixmap QPainter pixPainter; - QPixmap textPixmap(w, h); + QPixmap textPixmap; + + if ( ! m_scaleButton && orientation() == Horizontal ) + { + textPixmap = QPixmap( icon.width(), icon.height() ); + } + else if ( ! m_scaleButton ) + { + textPixmap = QPixmap( icon.height(), icon.width() ); + } + else if ( orientation() == Horizontal ) + { + textPixmap = QPixmap(w, h); + } + else + { + textPixmap = QPixmap(h, w); + } textPixmap.fill(QColor(0,0,0)); textPixmap.setMask(textPixmap.createHeuristicMask(true)); // draw text pixPainter.begin(&textPixmap); - pixPainter.setPen(m_textColor); - pixPainter.setFont(p->font()); // get the font from the root painter - pixPainter.drawText(tX, tY, m_buttonText, -1, rtl); + pixPainter.setPen( m_textColor ); + pixPainter.setFont( f ); // get the font from the root painter + pixPainter.drawText( tX, orientation() == Horizontal ? tY : width() + tY + 1, m_buttonText, -1, rtl); pixPainter.end(); - + if (!s_textShadowEngine) { KShadowSettings* shadset = new KShadowSettings(); shadset->setOffsetX(0); shadset->setOffsetY(0); shadset->setThickness(1); - shadset->setMaxOpacity(96); + shadset->setMaxOpacity(64); s_textShadowEngine = new KShadowEngine(shadset); } // draw shadow QImage img = s_textShadowEngine->makeShadow(textPixmap, shadCol); - p->drawImage(0, 0, img); + p->drawImage( 0, orientation() == Horizontal ? 0 : 0 - w, img); p->save(); - p->setPen(m_textColor); - p->drawText(tX, tY, m_buttonText, -1, rtl); + p->setPen( m_textColor ); + p->setFont( f ); + p->drawText( tX, tY, m_buttonText, -1, rtl); p->restore(); - - if (reverse && !icon.isNull()) - { - p->drawPixmap(w - icon.width() - 3, y, icon); - } - p->restore(); } else if (!icon.isNull()) { - int y = (height() - icon.height()) / 2; - int x = (width() - icon.width()) / 2; + if ( orientation() == Vertical && m_rotateButton ) + { + if ( m_scaleButton ) + { + x = 0; + y = 0 - icon.height(); + } + else + { + y = 0 - ( w / 2 ) - ( icon.height() /2 ) + 1; + } + p->rotate( 90 ); + } p->drawPixmap(x, y, icon); } @@ -700,6 +801,7 @@ { proposed_size = (orientation() == Horizontal) ? height() : width(); } + // determine the upper limit on the size. Normally, this is panelSize, // but if conserve space is requested, the max button size is used instead. @@ -710,7 +812,6 @@ upperLimit = KickerLib::maxButtonDim(); } - //kdDebug()<<endl<<endl<<flush; QValueListConstIterator<int> i = sizes.constBegin(); while (i != sizes.constEnd()) { @@ -721,8 +822,7 @@ sz = *i; // get the largest size under the limit ++i; } - - //kdDebug()<<"Using icon sizes: "<<sz<<" "<<zoom_sz<<endl<<flush; + return sz; } @@ -782,30 +882,72 @@ void PanelButton::loadIcons() { - KIconLoader * ldr = KGlobal::iconLoader(); QString nm = m_iconName; + KIcon::States defaultState = isEnabled() ? KIcon::DefaultState : KIcon::DisabledState; - m_icon = ldr->loadIcon(nm, KIcon::Panel, m_size, defaultState, 0L, true); + + QSize ref = KGlobal::iconLoader()->loadIcon( defaultIcon(), KIcon::Panel, m_size, defaultState).size(); + + QImage img = QImage( KGlobal::iconLoader()->iconPath( nm, KIcon::Panel ) ); + + // Try load default image if bitmap is invalid + if ( img.isNull() ) + img = KGlobal::iconLoader()->loadIcon( defaultIcon(), KIcon::Panel, m_size, defaultState ); + + // again null ? return empty; + if ( img.isNull() ) + return; + + KIconEffect * kfx = new KIconEffect(); + + if ( m_scaleButton ) + { + int h = KMAX( height(), ref.height() ); + int w = KMAX( width(), ref.width() ); + + if ( img.height() == img.width() ) + { + m_icon = img.smoothScale( h, h ); + } + else + { + orientation() == Horizontal ? + m_icon = img.smoothScale( ( img.width() * h ) / img.height(), h ) : + m_icon = img.smoothScale( ( img.width() * w ) / img.height(), w ) ; + } + } + else + { + orientation() == Horizontal ? + m_icon = img.smoothScale( ( img.width() * ref.height() ) / img.height(), ref.height() ) : + m_icon = img.smoothScale( ( img.width() * ref.width() ) / img.height(), ref.width() ) ; + } if (m_icon.isNull()) { nm = defaultIcon(); - m_icon = ldr->loadIcon(nm, KIcon::Panel, m_size, defaultState); + m_icon = KGlobal::iconLoader()->loadIcon(nm, KIcon::Panel, m_size, defaultState); } - + if (!isEnabled()) { m_iconh = m_icon; } else { - m_iconh = ldr->loadIcon(nm, KIcon::Panel, m_size, - KIcon::ActiveState, 0L, true); - } - - m_iconz = ldr->loadIcon(nm, KIcon::Panel, KIcon::SizeHuge, - defaultState, 0L, true ); + m_iconh = kfx->apply( + m_icon, + KIcon::Panel, + KIcon::ActiveState ); + } + + m_iconz = kfx->apply( + QPixmap( KGlobal::iconLoader()->iconPath( nm, KIcon::SizeHuge ) ), + KIcon::Panel, + defaultState ); + + delete kfx; } // (re)calculates the icon sizes and report true if they have changed. diff -u -r kdebase-3.5.6/kicker.orig/libkicker/panelbutton.h kdebase-3.5.6/kicker/libkicker/panelbutton.h --- kdebase-3.5.6/kicker.orig/libkicker/panelbutton.h 2006-01-19 15:01:40.000000000 -0200 +++ kdebase-3.5.6/kicker/libkicker/panelbutton.h 2007-03-07 09:31:09.000000000 -0300 @@ -133,6 +133,13 @@ void setIcon(const QString& icon); /** + * Used to set the icon for this panel button without reescale. + * @param icon the path to the button's icon + * @param scale tell to scale or not button ( default is scale ) + */ + void setIcon(const QString& icon, bool scale); + + /** * @return the button's icon */ QString icon() const; @@ -165,6 +172,23 @@ QColor textColor() const; /** + * Change the button's text label font + * @param f the new text label font + */ + void setTextFont(const QFont& f); + + /** + * @return the button's text label font + */ + QFont textFont() const; + + + /** + * Set button to be rotated on vertical oriented panel + */ + void setButtonRotation( bool r ); + + /** * Change the button's text scale * @param p font scale (in percent) */ @@ -378,8 +402,11 @@ bool m_highlight; bool m_changeCursorOverItem; bool m_hasAcceptedDrag; + bool m_scaleButton; + bool m_rotateButton; QColor m_textColor; QColor m_tileColor; + QFont m_textFont; QString m_buttonText; QString m_tile; QString m_title;