Sophie

Sophie

distrib > Mandriva > 2009.0 > x86_64 > media > main-testing-src > by-pkgid > 69501fee79f575b9818fcbd4bf2bb6c4 > files > 7

kdelibs4-4.2.4-0.2mdv2009.0.src.rpm

--- plasma/widgets/iconwidget.h~	2009-01-06 18:27:53.000000000 +0100
+++ plasma/widgets/iconwidget.h	2009-01-08 00:50:41.000000000 +0100
@@ -76,6 +76,13 @@
     explicit IconWidget(const QString &text, QGraphicsItem *parent = 0);
 
     /**
+    * Convenience constructor to create a Plasma::Icon with original proportion.
+    * @param keepProportion the boolean value to turn on capability
+    * @param parent the QGraphicsItem this icon is parented to.
+    */
+    explicit IconWidget(bool keepProportion, QGraphicsItem *parent = 0);
+
+   /**
     * Creates a new Plasma::IconWidget with text and an icon.
     * @param icon the icon that will be displayed with this icon.
     * @param text the text that will be displayed with this icon.
@@ -83,30 +90,36 @@
     */
     IconWidget(const QIcon &icon, const QString &text, QGraphicsItem *parent = 0);
 
-    /**
+   /**
     * Destroys this Plasma::IconWidget.
     */
     virtual ~IconWidget();
 
-    /**
+   /**
     * Returns the text associated with this icon.
     */
     QString text() const;
+  
+   /**
+    * Set to keep proportion of icon.
+    * @param keepProportion set if we should keep the proportion.
+    */
+    void setKeepProportion(bool keepProportion);
 
-    /**
+   /**
     * Sets the text associated with this icon.
     * @param text the text to associate with this icon.
     */
     void setText(const QString &text);
 
-    /**
+   /**
     * Convenience method to set the svg image to use when given the filepath and name of svg.
     * @param svgFilePath the svg filepath including name of the svg.
     * @param svgIconElement the svg element to use when displaying the svg. Defaults to all of them.
     */
     void setSvg(const QString &svgFilePath, const QString &svgIconElement = QString());
 
-    /**
+   /**
     * Returns the meta text associated with this icon.
     */
     QString infoText() const;
--- plasma/widgets/iconwidget_p.h~	2009-01-06 18:27:53.000000000 +0100
+++ plasma/widgets/iconwidget_p.h	2009-01-08 00:51:53.000000000 +0100
@@ -197,6 +197,7 @@
     int numDisplayLines;
     bool invertLayout;
     bool drawBg;
+    bool keepProportion;
     QSizeF currentSize;
     QPointF clickStartPos;
 
--- plasma/widgets/iconwidget.cpp~	2009-01-06 18:27:53.000000000 +0100
+++ plasma/widgets/iconwidget.cpp	2009-01-08 01:01:44.000000000 +0100
@@ -65,6 +65,7 @@
       numDisplayLines(2),
       invertLayout(false),
       drawBg(false),
+      keepProportion(false),
       action(0),
       activeMargins(0)
 {
@@ -273,6 +274,14 @@
     setText(text);
 }
 
+IconWidget::IconWidget(bool keepProportion, QGraphicsItem *parent)
+    : QGraphicsWidget(parent),
+      d(new IconWidgetPrivate(this))
+{
+    init();
+    setKeepProportion( keepProportion );
+}
+
 IconWidget::IconWidget(const QIcon &icon, const QString &text, QGraphicsItem *parent)
     : QGraphicsWidget(parent),
       d(new IconWidgetPrivate(this))
@@ -448,6 +457,7 @@
 
     //calculate icon size based on the available space
     qreal iconWidth;
+    qreal iconHeight;
 
     if (d->orientation == Qt::Vertical) {
         qreal heightAvail;
@@ -464,33 +474,63 @@
         }
 
         //aspect ratio very "tall"
-        if (d->currentSize.width() < heightAvail) {
-            iconWidth = d->currentSize.width() -
+        if( ! d->keepProportion )
+        {
+            if (d->currentSize.width() < heightAvail) {
+                iconWidth = d->currentSize.width() -
+                            d->horizontalMargin[IconWidgetPrivate::IconMargin].left -
+                            d->horizontalMargin[IconWidgetPrivate::IconMargin].right;
+           } else {
+                iconWidth = heightAvail -
+                            d->verticalMargin[IconWidgetPrivate::IconMargin].top -
+                            d->verticalMargin[IconWidgetPrivate::IconMargin].bottom;
+            }
+        }
+        else if( d->iconSvg != NULL )
+        {
+            QSizeF prop = d->iconSize;
+            prop.scale( d->currentSize.width() -
                         d->horizontalMargin[IconWidgetPrivate::IconMargin].left -
-                        d->horizontalMargin[IconWidgetPrivate::IconMargin].right;
-        } else {
-            iconWidth = heightAvail -
-                        d->verticalMargin[IconWidgetPrivate::IconMargin].top -
-                        d->verticalMargin[IconWidgetPrivate::IconMargin].bottom;
+                        d->horizontalMargin[IconWidgetPrivate::IconMargin].right,
+                        d->iconSvg->size().height(),
+                        Qt::KeepAspectRatio );
+
+            iconWidth = prop.width();
+            iconHeight = prop.height();
         }
     } else {
         //Horizontal layout
         QFontMetricsF fm(font());
 
-        //if there is text resize the icon in order to make room for the text
-        if (d->text.isEmpty() && d->infoText.isEmpty()) {
-            // with no text, we just take up the whole geometry
+        if( d->keepProportion )
+         {
+            iconHeight = d->currentSize.height() -
+                         d->verticalMargin[IconWidgetPrivate::IconMargin].top -
+                         d->verticalMargin[IconWidgetPrivate::IconMargin].bottom;
             iconWidth = d->currentSize.height() -
                         d->horizontalMargin[IconWidgetPrivate::IconMargin].left -
                         d->horizontalMargin[IconWidgetPrivate::IconMargin].right;
-        } else {
-            iconWidth = d->currentSize.height() -
-                        d->verticalMargin[IconWidgetPrivate::IconMargin].top -
-                        d->verticalMargin[IconWidgetPrivate::IconMargin].bottom;
+        }
+        else
+        {
+            //if there is text resize the icon in order to make room for the text
+            if (d->text.isEmpty() && d->infoText.isEmpty()) {
+                // with no text, we just take up the whole geometry
+                iconWidth = d->currentSize.width() -
+                            d->horizontalMargin[IconWidgetPrivate::IconMargin].left -
+                            d->horizontalMargin[IconWidgetPrivate::IconMargin].right;
+            } else {
+                iconWidth = d->currentSize.height() -
+                            d->verticalMargin[IconWidgetPrivate::IconMargin].top -
+                            d->verticalMargin[IconWidgetPrivate::IconMargin].bottom;
+            }
         }
     }
 
-    d->iconSize = QSizeF(iconWidth, iconWidth);
+    if( ! d->keepProportion )
+        d->iconSize = QSizeF(iconWidth, iconWidth);
+    else
+        d->iconSize = QSizeF(iconWidth, iconHeight);
 
     int count = 0;
     foreach (IconAction *iconAction, d->cornerActions) {
@@ -510,6 +550,13 @@
     d->iconSvg->setContainsMultipleImages(!elementId.isNull());
     d->iconSvgElement = elementId;
     d->iconSvgElementChanged = true;
+
+    if( d->keepProportion )
+    {
+        d->iconSvg->resize();
+        d->iconSize = d->iconSvg->elementSize(d->iconSvgElement);
+    }
+
     update();
 }
 
@@ -992,6 +1039,11 @@
     resize(sizeFromIconSize(d->iconSize.width()));
 }
 
+void IconWidget::setKeepProportion(bool keepProportion)
+{
+    d->keepProportion = keepProportion;
+}
+
 QString IconWidget::text() const
 {
     return d->text;