diff -u -r libs/plasma/widgets/icon.cpp libs/plasma.new/widgets/icon.cpp --- libs/plasma/widgets/icon.cpp 2008-08-28 05:06:55.000000000 -0300 +++ libs/plasma.new/widgets/icon.cpp 2008-10-01 17:07:12.000000000 -0300 @@ -62,12 +62,13 @@ IconPrivate::IconPrivate(Icon *i) : q(i), iconSvg(0), - iconSize(48, 48), + iconSize( 48, 48), states(IconPrivate::NoState), orientation(Qt::Vertical), numDisplayLines(2), invertLayout(false), drawBg(false), + keepProportion(false), action(0) { m_hoverAnimId = -1; @@ -274,6 +275,14 @@ setText(text); } +Icon::Icon(bool keepProportion, QGraphicsItem *parent) + : QGraphicsWidget(parent), + d(new IconPrivate(this)) +{ + init(); + setKeepProportion( keepProportion ); +} + Icon::Icon(const QIcon &icon, const QString &text, QGraphicsItem *parent) : QGraphicsWidget(parent), d(new IconPrivate(this)) @@ -435,10 +444,12 @@ } d->currentSize = size(); + d->setActiveMargins(); //calculate icon size based on the available space qreal iconWidth; + qreal iconHeight; if (d->orientation == Qt::Vertical) { qreal heightAvail; @@ -455,33 +466,64 @@ } //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[IconPrivate::IconMargin].left - + d->horizontalMargin[IconPrivate::IconMargin].right; + } else { + iconWidth = heightAvail - + d->verticalMargin[IconPrivate::IconMargin].top - + d->verticalMargin[IconPrivate::IconMargin].bottom; + } + } + else if( d->iconSvg != NULL ) + { + QSizeF prop = d->iconSize; + prop.scale( d->currentSize.width() - d->horizontalMargin[IconPrivate::IconMargin].left - - d->horizontalMargin[IconPrivate::IconMargin].right; - } else { - iconWidth = heightAvail - - d->verticalMargin[IconPrivate::IconMargin].top - - d->verticalMargin[IconPrivate::IconMargin].bottom; + d->horizontalMargin[IconPrivate::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[IconPrivate::IconMargin].top - + d->verticalMargin[IconPrivate::IconMargin].bottom; iconWidth = d->currentSize.width() - d->horizontalMargin[IconPrivate::IconMargin].left - d->horizontalMargin[IconPrivate::IconMargin].right; - } else { - iconWidth = d->currentSize.height() - - d->verticalMargin[IconPrivate::IconMargin].top - - d->verticalMargin[IconPrivate::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[IconPrivate::IconMargin].left - + d->horizontalMargin[IconPrivate::IconMargin].right; + } else { + iconWidth = d->currentSize.height() - + d->verticalMargin[IconPrivate::IconMargin].top - + d->verticalMargin[IconPrivate::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) { @@ -499,6 +541,12 @@ d->iconSvg->setImagePath(svgFilePath); d->iconSvgElement = elementId; + + if( d->keepProportion ) + { + d->iconSvg->resize(); + d->iconSize = d->iconSvg->elementSize(d->iconSvgElement); + } } void Icon::hoverEffect(bool show) @@ -980,6 +1028,11 @@ resize(sizeFromIconSize(d->iconSize.width())); } +void Icon::setKeepProportion(bool keepProportion) +{ + d->keepProportion = keepProportion; +} + QString Icon::text() const { return d->text; Somente em libs/plasma.new/widgets: icon.cpp~ Somente em libs/plasma.new/widgets: .icon.cpp.swp diff -u -r libs/plasma/widgets/icon.h libs/plasma.new/widgets/icon.h --- libs/plasma/widgets/icon.h 2008-07-03 02:05:35.000000000 -0300 +++ libs/plasma.new/widgets/icon.h 2008-10-01 11:19:13.000000000 -0300 @@ -72,6 +72,13 @@ explicit Icon(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 Icon(bool keepProportion, QGraphicsItem *parent = 0); + + /** * Creates a new Plasma::Icon 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. @@ -96,6 +103,12 @@ void setText(const QString &text); /** + * Set to keep proportion of icon. + * @param keepProportion set if we should keep the proportion. + */ + void setKeepProportion(bool keepProportion); + + /** * 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. Somente em libs/plasma.new/widgets: icon.h~ diff -u -r libs/plasma/widgets/icon_p.h libs/plasma.new/widgets/icon_p.h --- libs/plasma/widgets/icon_p.h 2008-07-03 02:05:35.000000000 -0300 +++ libs/plasma.new/widgets/icon_p.h 2008-10-01 11:22:26.000000000 -0300 @@ -185,6 +185,7 @@ int numDisplayLines; bool invertLayout; bool drawBg; + bool keepProportion; QSizeF currentSize; QPointF clickStartPos; Somente em libs/plasma.new/widgets: icon_p.h~