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