playground/libs/popupdropper/libpud

Jeff Mitchell mitchell at kde.org
Wed May 6 19:06:20 CEST 2009


SVN commit 964450 by mitchell:

Add TextProtection.  This allows text that is too big to be either multi-line-wrapped (but haven't figured out how to make the vertical centering happy yet) or scales the font size down (which is the default).  You can toggle this to MultiLine or off by using setTextProtection( PopupDropperItem::MutiLine/ScaleFont/NoProtection );

This fixes a sprint TODO item for 2.1; I will copy these over to the Amarok tree after trying to figure out how to make multi-line splitting vertically centered.

CCMAIL: amarok-devel at kde.org


 M  +30 -1     PopupDropperItem.cpp  
 M  +5 -0      PopupDropperItem.h  
 M  +1 -0      PopupDropperItem_p.h  


--- trunk/playground/libs/popupdropper/libpud/PopupDropperItem.cpp #964449:964450
@@ -60,6 +60,7 @@
     , textOffset( 30 )
     , hoverIndicatorShowStyle( PopupDropperItem::Never )
     , orientation( PopupDropperItem::Left )
+    , textProtection( PopupDropperItem::ScaleFont )
     , pd( 0 )
     , q( parent )
     {
@@ -207,6 +208,17 @@
     fullUpdate();
 }
 
+PopupDropperItem::TextProtection PopupDropperItem::textProtection() const
+{
+    return d->textProtection;
+}
+
+void PopupDropperItem::setTextProtection( const TextProtection textProtection )
+{
+    d->textProtection = textProtection;
+    fullUpdate();
+}
+
 QString PopupDropperItem::text() const
 {
     return d->text;
@@ -239,6 +251,7 @@
     d->font = font;
     if( d->textItem )
         d->textItem->setFont( font );
+    reposTextItem();
 }
 
 QColor PopupDropperItem::baseTextColor() const
@@ -438,7 +451,7 @@
 {
     if( !d->textItem || !d->borderRectItem )
         return;
-    
+ 
     d->textItem->setFont( d->font );
 
     qreal item_vert_center = ( d->borderRectItem->sceneBoundingRect().height() / 2 ) + d->borderRectItem->pos().y();
@@ -468,6 +481,22 @@
                 : d->borderRectItem->sceneBoundingRect().width() - offsetPos - d->textItem->sceneBoundingRect().width()
             )
         , item_vert_center - ( d->textItem->sceneBoundingRect().height() / 2 ) ); 
+
+    if( d->textProtection == PopupDropperItem::ScaleFont )
+    {
+        QFontMetrics fm( d->textItem->font() );
+        qreal desiredWidth = d->borderRectItem->sceneBoundingRect().width() - offsetPos;
+        while( fm.width( d->textItem->toPlainText() ) > desiredWidth ||
+               fm.height() > d->textItem->boundingRect().height() )
+        {
+            QFont font = d->textItem->font();
+            font.setPointSize( font.pointSize() - 1 );
+            d->textItem->setFont( font );
+            fm = QFontMetrics( font );
+        }
+    }
+    else if( d->textProtection == PopupDropperItem::MultiLine )
+        d->textItem->setTextWidth( d->borderRectItem->sceneBoundingRect().width() - offsetPos );
 }
 
 void PopupDropperItem::reposHoverFillRects()
--- trunk/playground/libs/popupdropper/libpud/PopupDropperItem.h #964449:964450
@@ -39,6 +39,7 @@
 
     Q_PROPERTY( HoverIndicatorShowStyle hoverIndicatorShowStyle READ hoverIndicatorShowStyle WRITE setHoverIndicatorShowStyle )
     Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
+    Q_PROPERTY( TextProtection textProtection READ textProtection WRITE setTextProtection )
     Q_PROPERTY( PopupDropperAction* action READ action WRITE setAction )
     Q_PROPERTY( QString text READ text WRITE setText )
     Q_PROPERTY( QFont font READ font WRITE setFont )
@@ -69,6 +70,8 @@
     Q_ENUMS( HoverIndicatorShowStyle )
     enum Orientation { Left, Right };
     Q_ENUMS( Orientation )
+    enum TextProtection { NoProtection, MultiLine, ScaleFont };
+    Q_ENUMS( TextProtection )
 
     PopupDropperItem( QGraphicsItem *parent = 0 );
     explicit PopupDropperItem( const QString &file, QGraphicsItem *parent = 0 );
@@ -83,6 +86,8 @@
     void setHoverIndicatorShowStyle( HoverIndicatorShowStyle hover );
     Orientation orientation() const;
     void setOrientation( Orientation orientation );
+    TextProtection textProtection() const;
+    void setTextProtection( TextProtection protection );
 
     QString text() const;
     void setText( const QString &text );
--- trunk/playground/libs/popupdropper/libpud/PopupDropperItem_p.h #964449:964450
@@ -66,6 +66,7 @@
     int textOffset;
     PopupDropperItem::HoverIndicatorShowStyle hoverIndicatorShowStyle;
     PopupDropperItem::Orientation orientation;
+    PopupDropperItem::TextProtection textProtection;
     PopupDropper* pd;
 
 private:


More information about the Amarok-devel mailing list