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

List:       kde-commits
Subject:    Re: extragear/multimedia/amarok/src/widgets
From:       "Dan Meltzer" <parallelgrapefruit () gmail ! com>
Date:       2008-12-03 23:10:16
Message-ID: 46059ce10812031510j7f083604jaaf787c866812ab2 () mail ! gmail ! com
[Download RAW message or body]

On Wed, Dec 3, 2008 at 5:46 PM, Teo Mrnjavac <teo.mrnjavac@gmail.com> wrote:

> SVN commit 892274 by mrnjavac:
>
> Removed the infoText QLabel from FilenameLayoutWidget and replaced it with
> reimplementing paintEvent.
> Removed obsolete debug messages.

QStrings should be allocated on the stack, not the heap.  This would make
the new code more standard (and thus, readable)

>
>
>
>  M  +31 -16    FilenameLayoutWidget.cpp
>  M  +4 -1      FilenameLayoutWidget.h
>
>
> --- trunk/extragear/multimedia/amarok/src/widgets/FilenameLayoutWidget.cpp
> #892273:892274
> @@ -29,6 +29,7 @@
>  #include <QDragEnterEvent>
>  #include <QDropEvent>
>  #include <QMimeData>
> +#include <QPainter>
>
>
>  FilenameLayoutWidget::FilenameLayoutWidget( QWidget *parent )
> @@ -40,12 +41,8 @@
>     m_layout = new QHBoxLayout;
>     m_layout->setSpacing( 0 );    //this should be coherent when using
> separators
>     setLayout( m_layout );
> -    m_infoText = new QLabel( this );
> -    m_infoText->setText( i18n( "<div align=center><i>Drag tokens here to
> define a filename scheme.</i></div>" ) ); //TODO: when we are out of string
> freeze remove the html from i18n
> -    m_infoText->setFixedSize( 300, 30 ); //FIXME this is rubbish, need to
> have it automatically fill the parent size
> -                                         //No, this is not rubbish as it's
> not a good idea to use the same layout that's used for the tokens.
> -                                         //You can say it needs a better
> implementation but there's a reason I handled it like this.
> -    m_infoText->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
> +    m_infoText = new QString();
> +    switchBackText( true );
>     m_layout->setContentsMargins( 1, 1, 1, 1 );
>  }
>
> @@ -55,12 +52,9 @@
>  void
>  FilenameLayoutWidget::addToken( const QString &text, int index )   //SLOT
>  {
> -    DEBUG_BLOCK
>     if( !m_tokenCount )
> -        m_infoText->hide();
> +        switchBackText( false );
>
> -    debug() << "Adding token: " << text;
> -
>     m_tokenCount++;
>     Token *token = new Token( text, this );
>
> @@ -236,7 +230,7 @@
>         m_tokenCount--;
>
>         if( !m_tokenCount )
> -            m_infoText->show();
> +            switchBackText( true );
>
>         generateParsableScheme();
>         emit schemeChanged();
> @@ -267,7 +261,7 @@
>
>     if( !m_tokenCount )
>     {
> -        m_infoText->show();
> +        switchBackText( true );
>     }
>
>     drag->exec(Qt::MoveAction | Qt::CopyAction, Qt:: CopyAction);
> @@ -336,8 +330,6 @@
>  {
>     DEBUG_BLOCK
>
> -    debug() << "infering scheme: " << s;
> -
>     removeAllTokens();
>     for( int i = 0; i < s.size(); )
>     {
> @@ -438,8 +430,31 @@
>         delete child;
>     }
>     m_tokenCount = 0;
> -    m_infoText->show();
> -    debug()<<"Removed all tokens";
> +    switchBackText( true );
> +    repaint();
>     emit schemeChanged();
>  }
>
> +void
> +FilenameLayoutWidget::switchBackText( bool on )
> +{
> +    if( on )
> +    {
> +        *m_infoText = i18n( "<div align=center><i>Drag tokens here to
> define a filename scheme.</i></div>" );
> +        //TODO: when we are out of string freeze remove the html from i18n
> +        //now a workaround to avoid breaking string freeze.
> +        m_infoText->remove( 0, 21 );
> +        m_infoText->remove( m_infoText->length() - 10, 10 );
> +    }
> +    else
> +        m_infoText->clear();
> +    repaint();
> +}
> +
> +void
> +FilenameLayoutWidget::paintEvent( QPaintEvent *event )
> +{
> +    QPainter p(this);
> +    p.drawText( rect(), Qt::AlignCenter, *m_infoText );
> +    QFrame::paintEvent( event );
> +}
> --- trunk/extragear/multimedia/amarok/src/widgets/FilenameLayoutWidget.h
> #892273:892274
> @@ -23,6 +23,7 @@
>  #include <QFrame>
>  #include <QHBoxLayout>
>  #include <QLabel>
> +#include <QPaintEvent>
>
>  // Handles the graphical representation of the target filename as a bar
> that contains tokens.
>  class FilenameLayoutWidget : public QFrame
> @@ -34,6 +35,7 @@
>
>         unsigned int getTokenCount() const;
>         QString getParsableScheme() const;
> +        void paintEvent( QPaintEvent *event );
>
>     protected:
>         void mouseMoveEvent( QMouseEvent *event );
> @@ -54,8 +56,9 @@
>         void insertOverChild( Token *childUnder, QString &textFromMimeData,
> QDropEvent *event );
>         void generateParsableScheme();
>         void removeAllTokens();
> +        void switchBackText( bool show );
>
> -        QLabel *m_infoText;        // text in the back of the empty
> FilenameLayoutWidget
> +        QString *m_infoText;        // text in the back of the empty
> FilenameLayoutWidget
>         QHBoxLayout *m_layout;          // main layout that holds the
> tokens
>
>         QPoint  m_startPos;             // needed for initiating the drag
>

[Attachment #3 (text/html)]

<br><br><div class="gmail_quote">On Wed, Dec 3, 2008 at 5:46 PM, Teo Mrnjavac <span \
dir="ltr">&lt;<a href="mailto:teo.mrnjavac@gmail.com">teo.mrnjavac@gmail.com</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex;"> SVN commit 892274 by mrnjavac:<br>
<br>
Removed the infoText QLabel from FilenameLayoutWidget and replaced it with \
reimplementing paintEvent.<br> Removed obsolete debug \
messages.</blockquote><div></div><div>QStrings should be allocated on the stack, not \
the heap. &nbsp;This would make the new code more standard (and thus, \
readable)&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex;"> <br>
<br>
<br>
&nbsp;M &nbsp;+31 -16 &nbsp; &nbsp;FilenameLayoutWidget.cpp<br>
&nbsp;M &nbsp;+4 -1 &nbsp; &nbsp; &nbsp;FilenameLayoutWidget.h<br>
<br>
<br>
--- trunk/extragear/multimedia/amarok/src/widgets/FilenameLayoutWidget.cpp \
#892273:892274<br> @@ -29,6 +29,7 @@<br>
&nbsp;#include &lt;QDragEnterEvent&gt;<br>
&nbsp;#include &lt;QDropEvent&gt;<br>
&nbsp;#include &lt;QMimeData&gt;<br>
+#include &lt;QPainter&gt;<br>
<br>
<br>
&nbsp;FilenameLayoutWidget::FilenameLayoutWidget( QWidget *parent )<br>
@@ -40,12 +41,8 @@<br>
 &nbsp; &nbsp; m_layout = new QHBoxLayout;<br>
 &nbsp; &nbsp; m_layout-&gt;setSpacing( 0 ); &nbsp; &nbsp;//this should be coherent \
when using separators<br>  &nbsp; &nbsp; setLayout( m_layout );<br>
- &nbsp; &nbsp;m_infoText = new QLabel( this );<br>
- &nbsp; &nbsp;m_infoText-&gt;setText( i18n( &quot;&lt;div \
align=center&gt;&lt;i&gt;Drag tokens here to define a filename \
scheme.&lt;/i&gt;&lt;/div&gt;&quot; ) ); //TODO: when we are out of string freeze \
remove the html from i18n<br>

- &nbsp; &nbsp;m_infoText-&gt;setFixedSize( 300, 30 ); //FIXME this is rubbish, need \
                to have it automatically fill the parent size<br>
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //No, this is not rubbish as \
                it&#39;s not a good idea to use the same layout that&#39;s used for \
                the tokens.<br>
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //You can say it needs a \
                better implementation but there&#39;s a reason I handled it like \
                this.<br>
- &nbsp; &nbsp;m_infoText-&gt;setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed \
);<br> + &nbsp; &nbsp;m_infoText = new QString();<br>
+ &nbsp; &nbsp;switchBackText( true );<br>
 &nbsp; &nbsp; m_layout-&gt;setContentsMargins( 1, 1, 1, 1 );<br>
&nbsp;}<br>
<br>
@@ -55,12 +52,9 @@<br>
&nbsp;void<br>
&nbsp;FilenameLayoutWidget::addToken( const QString &amp;text, int index ) &nbsp; \
//SLOT<br> &nbsp;{<br>
- &nbsp; &nbsp;DEBUG_BLOCK<br>
 &nbsp; &nbsp; if( !m_tokenCount )<br>
- &nbsp; &nbsp; &nbsp; &nbsp;m_infoText-&gt;hide();<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;switchBackText( false );<br>
<br>
- &nbsp; &nbsp;debug() &lt;&lt; &quot;Adding token: &quot; &lt;&lt; text;<br>
-<br>
 &nbsp; &nbsp; m_tokenCount++;<br>
 &nbsp; &nbsp; Token *token = new Token( text, this );<br>
<br>
@@ -236,7 +230,7 @@<br>
 &nbsp; &nbsp; &nbsp; &nbsp; m_tokenCount--;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; if( !m_tokenCount )<br>
- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m_infoText-&gt;show();<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;switchBackText( true );<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; generateParsableScheme();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; emit schemeChanged();<br>
@@ -267,7 +261,7 @@<br>
<br>
 &nbsp; &nbsp; if( !m_tokenCount )<br>
 &nbsp; &nbsp; {<br>
- &nbsp; &nbsp; &nbsp; &nbsp;m_infoText-&gt;show();<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;switchBackText( true );<br>
 &nbsp; &nbsp; }<br>
<br>
 &nbsp; &nbsp; drag-&gt;exec(Qt::MoveAction | Qt::CopyAction, Qt:: CopyAction);<br>
@@ -336,8 +330,6 @@<br>
&nbsp;{<br>
 &nbsp; &nbsp; DEBUG_BLOCK<br>
<br>
- &nbsp; &nbsp;debug() &lt;&lt; &quot;infering scheme: &quot; &lt;&lt; s;<br>
-<br>
 &nbsp; &nbsp; removeAllTokens();<br>
 &nbsp; &nbsp; for( int i = 0; i &lt; s.size(); )<br>
 &nbsp; &nbsp; {<br>
@@ -438,8 +430,31 @@<br>
 &nbsp; &nbsp; &nbsp; &nbsp; delete child;<br>
 &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; m_tokenCount = 0;<br>
- &nbsp; &nbsp;m_infoText-&gt;show();<br>
- &nbsp; &nbsp;debug()&lt;&lt;&quot;Removed all tokens&quot;;<br>
+ &nbsp; &nbsp;switchBackText( true );<br>
+ &nbsp; &nbsp;repaint();<br>
 &nbsp; &nbsp; emit schemeChanged();<br>
&nbsp;}<br>
<br>
+void<br>
+FilenameLayoutWidget::switchBackText( bool on )<br>
+{<br>
+ &nbsp; &nbsp;if( on )<br>
+ &nbsp; &nbsp;{<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;*m_infoText = i18n( &quot;&lt;div \
align=center&gt;&lt;i&gt;Drag tokens here to define a filename \
scheme.&lt;/i&gt;&lt;/div&gt;&quot; );<br> + &nbsp; &nbsp; &nbsp; &nbsp;//TODO: when \
we are out of string freeze remove the html from i18n<br> + &nbsp; &nbsp; &nbsp; \
&nbsp;//now a workaround to avoid breaking string freeze.<br> + &nbsp; &nbsp; &nbsp; \
&nbsp;m_infoText-&gt;remove( 0, 21 );<br> + &nbsp; &nbsp; &nbsp; \
&nbsp;m_infoText-&gt;remove( m_infoText-&gt;length() - 10, 10 );<br> + &nbsp; \
&nbsp;}<br> + &nbsp; &nbsp;else<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;m_infoText-&gt;clear();<br>
+ &nbsp; &nbsp;repaint();<br>
+}<br>
+<br>
+void<br>
+FilenameLayoutWidget::paintEvent( QPaintEvent *event )<br>
+{<br>
+ &nbsp; &nbsp;QPainter p(this);<br>
+ &nbsp; &nbsp;p.drawText( rect(), Qt::AlignCenter, *m_infoText );<br>
+ &nbsp; &nbsp;QFrame::paintEvent( event );<br>
+}<br>
--- trunk/extragear/multimedia/amarok/src/widgets/FilenameLayoutWidget.h \
#892273:892274<br> @@ -23,6 +23,7 @@<br>
&nbsp;#include &lt;QFrame&gt;<br>
&nbsp;#include &lt;QHBoxLayout&gt;<br>
&nbsp;#include &lt;QLabel&gt;<br>
+#include &lt;QPaintEvent&gt;<br>
<br>
&nbsp;// Handles the graphical representation of the target filename as a bar that \
contains tokens.<br> &nbsp;class FilenameLayoutWidget : public QFrame<br>
@@ -34,6 +35,7 @@<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; unsigned int getTokenCount() const;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; QString getParsableScheme() const;<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;void paintEvent( QPaintEvent *event );<br>
<br>
 &nbsp; &nbsp; protected:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; void mouseMoveEvent( QMouseEvent *event );<br>
@@ -54,8 +56,9 @@<br>
 &nbsp; &nbsp; &nbsp; &nbsp; void insertOverChild( Token *childUnder, QString \
&amp;textFromMimeData, QDropEvent *event );<br>  &nbsp; &nbsp; &nbsp; &nbsp; void \
generateParsableScheme();<br>  &nbsp; &nbsp; &nbsp; &nbsp; void \
removeAllTokens();<br> + &nbsp; &nbsp; &nbsp; &nbsp;void switchBackText( bool show \
);<br> <br>
- &nbsp; &nbsp; &nbsp; &nbsp;QLabel *m_infoText; &nbsp; &nbsp; &nbsp; &nbsp;// text \
in the back of the empty FilenameLayoutWidget<br> + &nbsp; &nbsp; &nbsp; \
&nbsp;QString *m_infoText; &nbsp; &nbsp; &nbsp; &nbsp;// text in the back of the \
empty FilenameLayoutWidget<br>  &nbsp; &nbsp; &nbsp; &nbsp; QHBoxLayout *m_layout; \
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// main layout that holds the tokens<br> <br>
 &nbsp; &nbsp; &nbsp; &nbsp; QPoint &nbsp;m_startPos; &nbsp; &nbsp; &nbsp; &nbsp; \
&nbsp; &nbsp; // needed for initiating the drag<br> </blockquote></div><br>



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

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