Sophie

Sophie

distrib > Mandriva > 2006.0 > i586 > media > main-src > by-pkgid > a6bc312ce50b5c8d0c51736e58ac32bc > files > 312

kdebase-3.4.2-55mdk.src.rpm

--- ./kicker/buttons/kbutton.cpp.add_text_to_kmenu	2005-03-08 18:42:12.000000000 +0100
+++ ./kicker/buttons/kbutton.cpp	2005-03-08 18:42:12.000000000 +0100
@@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 
 #include "kbutton.h"
 #include "kbutton.moc"
+#include <kconfig.h>
 
 #if defined(HAVE_XTEST)
 #   define XK_MISCELLANY
@@ -47,8 +48,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 KButton::KButton( QWidget* parent )
     : PanelPopupButton( parent, "KButton" )
 {
-    QToolTip::add(this, i18n("Click here to browse and start applications"));
-    setTitle(i18n("K Menu"));
+    KConfig* config = KGlobal::config();
+    config->setGroup("KMenu");
+    setHasText( config->readBoolEntry("kmenutext", true));
+
+	QToolTip::add(this, i18n("Click here to browse and start applications"));
+    setTitle(i18n("Menu"));
 
     setPopup( Kicker::kicker()->KMenu() );
     Kicker::kicker()->setKButton( this );
--- ./kicker/buttons/panelbuttonbase.cpp.add_text_to_kmenu	2005-02-18 10:26:08.000000000 +0100
+++ ./kicker/buttons/panelbuttonbase.cpp	2005-03-09 15:46:59.441236176 +0100
@@ -41,6 +41,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 #include "panelbuttonbase.h"
 #include "panelbuttonbase.moc"
 #include "kicker.h"
+#include <qfontmetrics.h>
+#include <klocale.h>
 
 namespace {
     ZoomButton* zoomButton = 0;
@@ -56,6 +58,7 @@ PanelButtonBase::PanelButtonBase(QWidget
   , _changeCursorOverItem(true)
   , _hasAcceptedDrag(false)
   , _hasAnimation(true)
+  , _hasText( false )
   , _tile(QString::null)
   , _iconName(QString::null)
   , _movie(0L)
@@ -63,13 +66,17 @@ PanelButtonBase::PanelButtonBase(QWidget
   , _popupDirection(::dUp)
   , _orientation(Horizontal)
   , _size((KIcon::StdSizes)-1), _zoom_size((KIcon::StdSizes)-1)
+  , sizeTextInit( false )
 {
     _tileColor = QColor();
     calculateIconSizes();
 
     slotSettingsChanged(KApplication::SETTINGS_MOUSE);
     connect(kapp, SIGNAL(settingsChanged(int)), SLOT(slotSettingsChanged(int)));
-    kapp->addKipcEventMask(KIPC::SettingsChanged);
+
+	connect( kapp, SIGNAL(  kdisplayFontChanged() ), SLOT( slotRecalculateTextSize() ) );
+	kapp->addKipcEventMask(KIPC::FontChanged);
+
 
     setAcceptDrops(true);
 }
@@ -449,10 +456,91 @@ void PanelButtonBase::drawButtonLabel(QP
 
     const QPixmap& icon = labelIcon();
     if (!icon.isNull()
-     && !(zoomButton && zoomButton->isWatching(this))) {
-	int x = (width()  - icon.width() )/2;
-	int y = (height() - icon.height())/2;
-	p->drawPixmap(x, y, icon);
+        && !(zoomButton && zoomButton->isWatching(this))) {
+        if ( !_hasText )
+        {
+            int x = (width()  - icon.width() )/2;
+            int y = (height() - icon.height())/2;
+            p->drawPixmap(x, y, icon);
+        }
+        else
+        {
+            ContainerArea* area = Panel::the()->containerArea();
+            if ( area->position() == ::Left || area->position() == ::Right )
+            {
+                if( sizeText().width() > Panel::the()->containerArea()->width() )
+                {
+                    int x = (width()  - icon.width() )/2;
+                    int y = (height() - icon.height())/2;
+                    p->drawPixmap(x, y, icon);
+
+                }
+                else
+                {
+                    if ( QApplication::reverseLayout() )
+                    {
+                        int x = (width()  - icon.width() );
+                        int y = 0;
+                        if ( sizeText().height()>icon.height() )
+                            y = (height() - sizeText().height())/2;
+                        else
+                            y = (height() - icon.height())/2;
+                        p->drawPixmap(x, y, icon);
+                        QFont tmpFont( KGlobalSettings::generalFont() );
+                        tmpFont.setBold( true );
+                        p->setFont( tmpFont );
+                        p->drawText( x -3 - sizeText().width(), y + height()/2, _title );
+                    }
+                    else
+                    {
+                        int x = (width()  - icon.width() )/2;
+                        int y = 0;
+                        if ( sizeText().height()>icon.height() )
+                            y = (height() - sizeText().height())/2;
+                        else
+                            y = (height() - icon.height())/2;
+                        p->drawPixmap(x, y, icon);
+                        QFont tmpFont( KGlobalSettings::generalFont() );
+                        tmpFont.setBold( true );
+                        p->setFont( tmpFont );
+                        p->drawText( (  width()  - sizeText().width() )/2, y + height()/2, _title );
+                    }
+                }
+            }
+            else
+            {
+                if ( QApplication::reverseLayout() )
+                {
+
+                    int x = (width()  - icon.width()  );
+                    int y = 0;
+                    if ( sizeText().height()>icon.height() )
+                        y = (height() - sizeText().height())/2;
+                    else
+                        y = (height() - icon.height())/2;
+                    p->drawPixmap(x, y, icon);
+                    QFont tmpFont( KGlobalSettings::generalFont() );
+                    tmpFont.setBold( true );
+                    p->setFont( tmpFont );
+                    p->drawText( x - 3-sizeText().width(), y + height()/2, _title );
+                }
+                else
+                {
+
+                    int x = (width()  - icon.width()  )/2;
+                    int y = 0;
+                    if ( sizeText().height()>icon.height() )
+                        y = (height() - sizeText().height())/2;
+                    else
+                        y = (height() - icon.height())/2;
+                    p->drawPixmap(x, y, icon);
+                    QFont tmpFont( KGlobalSettings::generalFont() );
+                    tmpFont.setBold( true );
+                    p->setFont( tmpFont );
+                    p->drawText( (  width()  - sizeText().width() )/2 , y+ icon.height(), _title );
+                }
+            }
+        }
     }
 
     if (_drawArrow) {
@@ -545,3 +633,32 @@ QImage loadTile(const QString& tile, con
 
     return tileImg;
 }
+
+QSize PanelButtonBase::sizeText()
+{
+  if (  sizeTextInit )
+        return textSize;
+    return calculateTextSize();
+}
+
+void PanelButtonBase::slotRecalculateTextSize()
+{
+    calculateTextSize(); update();
+}
+
+QSize PanelButtonBase::calculateTextSize()
+{
+    if ( !_hasText )
+        textSize = QSize( -20 , 0);
+    else
+    {
+        QFont tmpFont( KGlobalSettings::generalFont() );
+        tmpFont.setBold( true );
+        QFontMetrics fontm( tmpFont);
+        textSize = QSize( fontm.width( _title ), fontm.height() );
+	}
+    sizeTextInit = true;
+    return textSize;
+}
+
+
--- ./kicker/buttons/panelbuttonbase.h.add_text_to_kmenu	2005-02-18 10:26:08.000000000 +0100
+++ ./kicker/buttons/panelbuttonbase.h	2005-03-09 15:43:56.694963868 +0100
@@ -46,7 +46,9 @@ public:
     virtual void configure();
 
     bool isValid() const { return _valid; };
-    void setTile(const QString&, const QColor& color = QColor());
+	void setHasText( bool _b ) { _hasText =_b ;}
+	bool hasText() const { return _hasText;}
+	void setTile(const QString&, const QColor& color = QColor());
     void setIcon(const QString&);
     void setIconURL(const KURL& url);
     void setTitle(const QString&);
@@ -64,6 +66,7 @@ public:
     static void setZoomEnabled(bool b);
     void setBackground();
 
+	virtual QSize sizeText();
     bool conserveSpace() const;
     int maxButtonDim() const;
     int maxIconDim() const;
@@ -81,6 +84,7 @@ public slots:
 
 protected slots:
     void slotSettingsChanged(int);
+	void slotRecalculateTextSize();
 
 protected:
     virtual void resizeEvent(QResizeEvent*);
@@ -100,6 +104,7 @@ protected:
     void loadIcons();
     bool calculateIconSizes();
 
+	QSize calculateTextSize();
     bool _valid;
     QPixmap _icon;
 
@@ -110,6 +115,7 @@ private:
     bool _changeCursorOverItem;
     bool _hasAcceptedDrag;
     bool _hasAnimation;
+	bool _hasText;
     QString _tile;
     QString _title;
     QString _iconName;
@@ -125,6 +131,8 @@ private:
     int _size;
     int _zoom_size;
     QColor _tileColor;
+	QSize textSize;
+	bool sizeTextInit;
 };
 
 QImage loadTile(const QString& name, const QSize&,
--- kicker/core/container_button.cpp.fix_kmenu_text	2005-02-18 10:26:08.000000000 +0100
+++ kicker/core/container_button.cpp	2005-03-11 10:08:47.137435213 +0100
@@ -71,21 +71,31 @@ bool ButtonContainer::isValid() const
 
 // Buttons Shouldn't be square when larger than a certain size.
 int ButtonContainer::widthForHeight(int height) const
-{   if (isValid()) {
-        int val=_button->preferredDimension(height);
+{   
+	if (isValid()) {
+        int val = 0;
+        if ( _button->hasText() )
+            val=QMAX( _button->sizeText().width(),_button->preferredDimension(height) )+10;
+        else
+            val=_button->preferredDimension(height);
         //kdDebug() << "ButtonContainer::widthForHeight("<<height<<"):" << val << endl<<flush;
-        return val;
-    }
+        return val;    
+	}
     //kdDebug() << "ButtonContainer::widthForHeight -  NO VALID BUTTON!"<< endl<<flush;
     return height;
 }
 
 int ButtonContainer::heightForWidth(int width)  const
-{   if (isValid()) {
-        int val=_button->preferredDimension(width);
+{   
+	if (isValid()) {
+        int val = 0;
+        if ( _button->hasText() )
+            val=QMAX( _button->sizeText().height(),_button->preferredDimension(width ) )+10;
+        else
+            val=_button->preferredDimension(width);
         //kdDebug() << "ButtonContainer::heightForWidth("<<width<<"):" << val << endl<<flush;
-        return val;
-    }
+        return val;    
+	}
     //kdDebug() << "ButtonContainer::heightForWidth() - NO VALID BUTTON!"<< endl<<flush;
     return width;
 }
@@ -234,16 +244,28 @@ KMenuButtonContainer::KMenuButtonContain
 
 int KMenuButtonContainer::widthForHeight( int height ) const
 {
+	int val = ButtonContainer::widthForHeight(height);
     if ( height < 32 )
-        return height + 10;
+	{
+        if ( val > 32 )
+				return val;
+		else
+        	return height + 10;
+	}
     else
         return ButtonContainer::widthForHeight(height);
 }
 
 int KMenuButtonContainer::heightForWidth( int width ) const
 {
-    if ( width < 32 )
-        return width + 10;
+   int val = ButtonContainer::heightForWidth(width);
+   if ( width < 32 )
+    {
+        if ( val > 32 )
+            return val;
+        else
+            return width + 10;
+    }		   
     else
         return ButtonContainer::heightForWidth(width);
 }