[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [amarok] src: Fix: Width setting playlist layout has wrong maximum value
From:       Ralf Engels <ralf-engels () gmx ! de>
Date:       2015-01-31 8:31:26
Message-ID: E1YHTSg-0007Lz-OM () scm ! kde ! org
[Download RAW message or body]

Git commit 97673e83dcfc348f7a9414aa609136df578dbbf4 by Ralf Engels.
Committed on 30/01/2015 at 13:54.
Pushed by rengels into branch 'master'.

Fix: Width setting playlist layout has wrong maximum value

Clean up a little bit the tokens and dialogs by e.g. getting rid
of the bug eventually.

BUG: 315756

M  +30   -31   src/playlist/layouts/LayoutEditDialog.cpp
M  +10   -4    src/playlist/layouts/LayoutEditDialog.h
M  +1    -5    src/playlist/layouts/LayoutEditWidget.cpp
M  +0    -26   src/widgets/TokenWithLayout.cpp
M  +14   -8    src/widgets/TokenWithLayout.h

http://commits.kde.org/amarok/97673e83dcfc348f7a9414aa609136df578dbbf4

diff --git a/src/playlist/layouts/LayoutEditDialog.cpp \
b/src/playlist/layouts/LayoutEditDialog.cpp index fa4cd94..8f23fd6 100644
--- a/src/playlist/layouts/LayoutEditDialog.cpp
+++ b/src/playlist/layouts/LayoutEditDialog.cpp
@@ -36,7 +36,6 @@
 #include <QStyleOptionFrame>
 #include <QToolButton>
 
-#include <QtDebug>
 
 class HintingLineEdit : public QLineEdit
 {
@@ -106,11 +105,11 @@ LayoutEditDialog::LayoutEditDialog( QWidget *parent ) : \
                QDialog( parent )
     l4->addWidget( m_fitContent = new QRadioButton( i18n( "Fit content" ), this ) );
     m_fitContent->setToolTip( i18n( "Fit the element text" ) );
 #endif
-    l4->addWidget( m_peerWidth = new QRadioButton( i18nc( "automatic width", \
                "Automatic" ), this ) );
-    m_peerWidth->setToolTip( i18n( "Take homogeneous part of the space available to \
all elements with automatic width" ) ); +    l4->addWidget( m_automaticWidth = new \
QRadioButton( i18nc( "automatic width", "Automatic" ), this ) ); +    \
m_automaticWidth->setToolTip( i18n( "Take homogeneous part of the space available to \
all elements with automatic width" ) );  l4->addStretch();
     boxWidget->connect( m_fixedWidth, SIGNAL(toggled(bool)), SLOT(setEnabled(bool)) \
                );
-    connect( m_peerWidth, SIGNAL(toggled(bool)), SLOT(setPeerWidth(bool)) );
+    connect( m_automaticWidth, SIGNAL(toggled(bool)), SLOT(setAutomaticWidth(bool)) \
);  l1->addLayout( l4 );
 
     QHBoxLayout *l5 = new QHBoxLayout( boxWidget );
@@ -192,7 +191,7 @@ LayoutEditDialog::LayoutEditDialog( QWidget *parent ) : QDialog( \
parent )  
 void LayoutEditDialog::apply()
 {
-    if ( !m_token )
+    if( !m_token )
         return;
 
     m_token.data()->setPrefix( m_prefix->text() );
@@ -209,7 +208,7 @@ void LayoutEditDialog::apply()
     m_token.data()->setUnderline( m_underline->isChecked() );
 
     // we do this here to avoid reliance on the connection order (i.e. prevent close \
                before apply)
-    if ( sender() )
+    if( sender() )
         close();
 }
 
@@ -219,18 +218,18 @@ void LayoutEditDialog::close()
     QDialog::close();
 }
 
-void LayoutEditDialog::setPeerWidth( bool peer )
+void LayoutEditDialog::setAutomaticWidth( bool automatic )
 {
-    if ( peer )
+    if( automatic )
     {
         m_previousWidth = m_width->value();
-        m_width->setRange( 0, 100 );
-        m_width->setValue( 0 );
+        m_width->setMinimum( 0 ); // without setting the minumum we can't set the \
value.. +        m_width->setValue( 0 ); // automatic width is represented by width \
== 0  }
     else
     {
         m_width->setValue( m_previousWidth );
-        m_width->setRange( 1, 100 );
+        m_width->setMinimum( 1 ); // set minimum back to 1 since "0" means automatic
     }
 }
 
@@ -248,33 +247,33 @@ void LayoutEditDialog::setToken( TokenWithLayout *t )
         m_suffix->setText( m_token.data()->suffix() );
 
 
+        // Compute the remaining space from the tokens on the same line.
         // this should still not be done here as it makes upward assumptions
         // solution(?) token->element->row->elements
-        if ( m_token.data()->parentWidget() )
+        TokenDropTarget *editWidget = qobject_cast<TokenDropTarget*>( \
m_token.data()->parentWidget() ); +        if( editWidget )
         {
-            if ( TokenDropTarget *editWidget = qobject_cast<TokenDropTarget*>( \
m_token.data()->parentWidget() ) ) +            qreal spareWidth = 100.0;
+            int row = editWidget->row( m_token.data() );
+            if( row > -1 )
             {
-                qreal spareWidth = 100.0;
-                int row = editWidget->row( m_token.data() );
-                if ( row > -1 )
+                QList<Token*> tokens = editWidget->tokensAtRow( row );
+                foreach ( Token *token, tokens )
                 {
-                    QList<Token*> tokens = editWidget->tokensAtRow( row );
-                    foreach ( Token *token, tokens )
-                    {
-                        if ( token == m_token.data() )
-                            continue;
-                        if ( TokenWithLayout *twl = qobject_cast<TokenWithLayout*>( \
                token ) )
-                            spareWidth -= twl->width() * 100.0;
-                    }
+                    if ( token == m_token.data() )
+                        continue;
+
+                    if ( TokenWithLayout *twl = qobject_cast<TokenWithLayout*>( \
token ) ) +                        spareWidth -= twl->width() * 100.0;
                 }
+            }
 
-                int max = qMax( spareWidth, qreal( 0.0 ) );
+            int max = qMax( spareWidth, qreal( 0.0 ) );
 
-                if ( max >= m_token.data()->width() * 100.0 )
-                    m_width->setMaximum( qMax( spareWidth, qreal( 0.0 ) ) );
-                else
-                    m_width->setMaximum( m_token.data()->width() * 100.0 );
-            }
+            if( max >= m_token.data()->width() * 100.0 )
+                m_width->setMaximum( qMax( spareWidth, qreal( 0.0 ) ) );
+            else
+                m_width->setMaximum( m_token.data()->width() * 100.0 );
         }
         m_width->setValue( m_token.data()->width() * 100.0 );
         m_previousWidth = m_width->value();
@@ -282,7 +281,7 @@ void LayoutEditDialog::setToken( TokenWithLayout *t )
         if ( m_token.data()->width() > 0.0 )
             m_fixedWidth->setChecked( true );
         else
-            m_peerWidth->setChecked( true );
+            m_automaticWidth->setChecked( true );
 
         if ( m_token.data()->alignment() & Qt::AlignLeft )
             m_alignLeft->setChecked(true);
diff --git a/src/playlist/layouts/LayoutEditDialog.h \
b/src/playlist/layouts/LayoutEditDialog.h index 9f31ce1..14ae36b 100644
--- a/src/playlist/layouts/LayoutEditDialog.h
+++ b/src/playlist/layouts/LayoutEditDialog.h
@@ -38,15 +38,21 @@ public slots:
     void close();
 private slots:
     void apply();
-    void setPeerWidth( bool peer );
+    void setAutomaticWidth( bool peer );
 private:
     QWeakPointer<TokenWithLayout> m_token;
-    HintingLineEdit *m_prefix, *m_suffix;
+    HintingLineEdit *m_prefix;
+    HintingLineEdit *m_suffix;
     QLabel *m_element;
     QSlider *m_width;
+
+    /** Stores the width that the widget had before switching to automatic width. */
     int m_previousWidth;
-    QToolButton *m_bold, *m_italic, *m_underline,  *m_alignLeft, *m_alignCenter, \
                *m_alignRight;
-    QRadioButton *m_fixedWidth, *m_peerWidth;
+
+    QToolButton *m_bold, *m_italic, *m_underline;
+    QToolButton *m_alignLeft, *m_alignCenter, *m_alignRight;
+    QRadioButton *m_fixedWidth;
+    QRadioButton *m_automaticWidth;
 };
 
 #endif
diff --git a/src/playlist/layouts/LayoutEditWidget.cpp \
b/src/playlist/layouts/LayoutEditWidget.cpp index 0eadaae..1632df2 100644
--- a/src/playlist/layouts/LayoutEditWidget.cpp
+++ b/src/playlist/layouts/LayoutEditWidget.cpp
@@ -125,11 +125,7 @@ Playlist::LayoutItemConfig LayoutEditWidget::config()
         foreach( Token * token, tokens ) {
             if ( TokenWithLayout *twl = dynamic_cast<TokenWithLayout *>( token ) )
             {
-                qreal width = 0.0;
-                if ( twl->widthForced() && twl->width() >= 0.01) {
-                    width = twl->width();
-                }
-                currentRowConfig.addElement( LayoutItemConfigRowElement( \
twl->value(), width, +                currentRowConfig.addElement( \
                LayoutItemConfigRowElement( twl->value(), twl->width(),
                                                                          \
                twl->bold(), twl->italic(), twl->underline(),
                                                                          \
twl->alignment(), twl->prefix(), twl->suffix() ) );  }
diff --git a/src/widgets/TokenWithLayout.cpp b/src/widgets/TokenWithLayout.cpp
index 9275415..72b7521 100644
--- a/src/widgets/TokenWithLayout.cpp
+++ b/src/widgets/TokenWithLayout.cpp
@@ -97,7 +97,6 @@ TokenWithLayout::TokenWithLayout( const QString &text, const \
QString &iconName,  : Token( text, iconName, value, parent  )
     , m_width( 0.0 ), m_wrenchTimer( 0 )
 {
-    m_widthForced = m_width > 0.0;
     m_alignment = Qt::AlignCenter;
     m_bold = false;
     m_italic = false;
@@ -200,24 +199,6 @@ void TokenWithLayout::setAlignment( Qt::Alignment alignment )
     emit changed();
 }
 
-void TokenWithLayout::setAlignLeft( bool b )
-{
-    if (b)
-        setAlignment( Qt::AlignLeft );
-}
-
-void TokenWithLayout::setAlignCenter( bool b )
-{
-    if (b)
-        setAlignment( Qt::AlignCenter );
-}
-
-void TokenWithLayout::setAlignRight( bool b )
-{
-    if (b)
-        setAlignment( Qt::AlignRight );
-}
-
 bool TokenWithLayout::bold() const
 {
     return m_bold;
@@ -260,17 +241,10 @@ void TokenWithLayout::setSuffix( const QString& string )
 void TokenWithLayout::setWidth( int size )
 {
     m_width = qMax( qMin( 1.0, size/100.0 ), 0.0 ) ;
-    if ( m_width > 0.0 )
-        m_widthForced = true;
 
     emit changed();
 }
 
-void TokenWithLayout::setWidthForced( bool on )
-{
-    m_widthForced = on;
-}
-
 qreal TokenWithLayout::width() const
 {
     return m_width;
diff --git a/src/widgets/TokenWithLayout.h b/src/widgets/TokenWithLayout.h
index ffa87fe..7f29fec 100644
--- a/src/widgets/TokenWithLayout.h
+++ b/src/widgets/TokenWithLayout.h
@@ -57,28 +57,35 @@ public:
     ~TokenWithLayout();
 
     Qt::Alignment alignment();
-    void setAlignment( Qt::Alignment alignment );
-
     bool bold() const;
     bool italic() const;
     bool underline() const;
     inline qreal size() const { return width(); }
     qreal width() const;
-    inline bool widthForced() const { return m_widthForced; }
+
+    /** Return true if the width is determined by width(). It's automatic otherwise \
*/ +    inline bool widthForced() const { return m_width > 0.0; }
+
+    /** Returns the text that is added to the front of the value */
     inline QString prefix() const { return m_prefix; }
+
+    /** Returns the text that is added to the back of the value such as "%" */
     inline QString suffix() const { return m_suffix; }
 
 public slots:
-    void setAlignLeft( bool );
-    void setAlignCenter( bool );
-    void setAlignRight( bool );
+    void setAlignment( Qt::Alignment alignment );
     void setBold( bool bold );
     void setItalic( bool italic );
     void setUnderline( bool underline );
     void setPrefix( const QString& );
     void setSuffix( const QString& );
+
+    /** Set the width of the token to a percentage of the whole line.
+     *
+     *  @param width A number from 0 to 100. A width of >0 will
+     *    automatically set "forced" to true.
+     */
     void setWidth( int width );
-    void setWidthForced( bool );
 
 protected:
     virtual void enterEvent(QEvent *);
@@ -95,7 +102,6 @@ private:
     bool m_bold;
     bool m_italic;
     bool m_underline;
-    bool m_widthForced;
     qreal m_width;
     QString m_prefix, m_suffix;
     Wrench *m_wrench;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic