From kde-commits Sun Aug 31 23:45:59 2008 From: Teo Mrnjavac Date: Sun, 31 Aug 2008 23:45:59 +0000 To: kde-commits Subject: extragear/multimedia/amarok/src Message-Id: <1220226359.068562.17816.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=122022637708574 SVN commit 855518 by mrnjavac: Trying to add icons to the Tokens and still wrestling with a nasty crash when dropping on FilenameLayoutWidget. Layout fixes. M +5 -1 collection/sqlcollection/OrganizeCollectionDialog.cpp M +1 -1 dialogs/FilenameLayoutDialog.ui M +15 -6 widgets/FilenameLayoutWidget.cpp M +27 -9 widgets/Token.cpp M +7 -5 widgets/Token.h M +6 -1 widgets/TokenListWidget.cpp --- trunk/extragear/multimedia/amarok/src/collection/sqlcollection/OrganizeCollectionDialog.cpp #855517:855518 @@ -147,6 +147,9 @@ QString OrganizeCollectionDialog::buildDestination( const QString &format, const Meta::TrackPtr &track ) const { + //TODO: handle if track==NULL to avoid bug 169684 + //This could maybe happen with an empty collection, when the TrackList is empty and then m_previewTrack is null. + //FIXME: 169684 bool isCompilation = track->album()->isCompilation(); QMap args; QString artist = track->artist()->name(); @@ -273,7 +276,7 @@ void -OrganizeCollectionDialog::setPreviewTrack( const Meta::TrackPtr track ) +OrganizeCollectionDialog::setPreviewTrack( const Meta::TrackPtr track ) //UNUSED!! I don't know what's this thing doing here but it might be the cause of BR169684 { m_previewTrack = track; } @@ -371,6 +374,7 @@ ui->formatLabel->hide(); ui->formatEdit->hide(); ui->formatHelp->hide(); + filenameLayoutDialog->hide(); widget->resize( widget->minimumSize() ); //TODO: FIX THE LAYOUT WHEN RESIZING vbox->resize( vbox->minimumSize() ); --- trunk/extragear/multimedia/amarok/src/dialogs/FilenameLayoutDialog.ui #855517:855518 @@ -6,7 +6,7 @@ 0 0 642 - 641 + 733 --- trunk/extragear/multimedia/amarok/src/widgets/FilenameLayoutWidget.cpp #855517:855518 @@ -75,9 +75,9 @@ token->show(); - if( token->text() == "" ) + if( token->getString() == "" ) { - token->setText( " " ); + token->setString( " " ); } //testing, remove when done @@ -87,7 +87,7 @@ //debug stuff follows foreach(Token *temp, *tokenList) { - debug() << tokenList->indexOf( temp ) << " .......... " << layout->indexOf( temp ) << " .......... " << temp->text(); + debug() << tokenList->indexOf( temp ) << " .......... " << layout->indexOf( temp ) << " .......... " << temp->getString(); } generateParsableScheme(); emit schemeChanged(); @@ -163,34 +163,43 @@ debug() << "I am dragging from the layout widget"; event->setDropAction( Qt::MoveAction ); } - + debug()<<"everything fine so far, now I'm gonna calculate where to insert the new token"; Token *childUnder = qobject_cast< Token * >( childAt( event->pos() ) ); if( childUnder == 0 ) //if I'm not dropping on an existing token { if( !m_tokenCount ) //if the bar is empty { addToken( textFromMimeData ); + debug()<<">>>>>>>>> EMPTY BAR"; } else //if the bar is not empty and I'm still not dropping on an existing token { QPoint fixedPos = QPoint( event->pos().x(), size().height() / 2 ); //first I lower the y coordinate of the drop, this should handle the drops higher and lower than the tokens + debug()<<">>>>>>>>> CENTERING VERTICALLY"; childUnder = qobject_cast< Token * >( childAt( fixedPos ) ); //and I look for a child (token) on these new coordinates if( childUnder == 0 ) //if there's none, then I'm either at the beginning or at the end of the bar { if( fixedPos.x() < childrenRect().topLeft().x() ) //if I'm dropping before all the tokens { fixedPos = QPoint( fixedPos.x() + 10, fixedPos.y() ); + debug()<<">>>>>>>>> SIMULATING DROP TO THE RIGHT"; + } else //this covers if I'm dropping after all the tokens or in between { fixedPos = QPoint( fixedPos.x() - 10, fixedPos.y() ); + debug()<<">>>>>>>>> SIMULATING DROP TO THE LEFT"; + } childUnder = qobject_cast< Token * >( childAt( fixedPos ) ); insertOverChild( childUnder, textFromMimeData, event ); + debug()<<">>>>>>>>> \\called insertOverChild"; + } else //if I find a token, I'm done { insertOverChild( childUnder, textFromMimeData, event ); + debug()<<">>>>>>>>> \\called insertOverChild"; } } } @@ -242,7 +251,7 @@ return; QByteArray itemData; QDataStream dataStream( &itemData, QIODevice::WriteOnly ); - dataStream << child->text(); // << QPoint( event->pos() - child->rect().topLeft() -child.pos() ); //I may need the QPoint of the start sooner or later + dataStream << child->getString(); // << QPoint( event->pos() - child->rect().topLeft() -child.pos() ); //I may need the QPoint of the start sooner or later QMimeData *mimeData = new QMimeData; mimeData->setData( "application/x-amarok-tag-token", itemData ); QDrag *drag = new QDrag( this ); @@ -275,7 +284,7 @@ m_parsableScheme = ""; foreach( Token *token, *tokenList) { - QString current = token->text(); + QString current = token->getString(); if( current == i18n( "Track" ) ) { m_parsableScheme += "%track"; --- trunk/extragear/multimedia/amarok/src/widgets/Token.cpp #855517:855518 @@ -17,14 +17,30 @@ #include "Token.h" #include "Debug.h" +// Token::Token( QWidget *parent ) +// :QFrame( parent ) +// { +// +// +// } + Token::Token( const QString &string, QWidget *parent ) - : QLabel( parent ) + : QFrame( parent ) { m_myCount = qobject_cast< FilenameLayoutWidget * >( parent )->getTokenCount(); - - setText( string ); - setTokenString( string ); - setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); + + //m_icon = new QPixmap( "placeholder.png"); //TODO: get icons from oxygen guys and handle loading + m_label = new QLabel( this ); + QHBoxLayout *hlayout = new QHBoxLayout( this ); + setLayout( hlayout ); + QLabel *iconContainer = new QLabel( this ); + //m_icon->something to get a pixmap here + //iconContainer->setPixmap( *m_icon ); + hlayout->addWidget( iconContainer ); + hlayout->addWidget( m_label ); + //Token( parent ); + setString( string ); + m_label->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); setStyleSheet( "Token {\ color: palette( Base );\ background-color: qlineargradient( x1: 0,\ @@ -37,20 +53,22 @@ }" ); QFontMetrics metric( font() ); - QSize size = metric.size( Qt::TextSingleLine, text() ); - setMinimumSize( size + QSize( 4, 0 ) ); + QSize size = metric.size( Qt::TextSingleLine, m_label->text() ); + m_label->setMinimumSize( size + QSize( 4, 0 ) ); } //Access for m_tokenString, private. void -Token::setTokenString( const QString &string ) +Token::setString( const QString &string ) { + m_label->setText( string ); m_tokenString = string; + //TODO: code to set icon maybe } //Access for m_tokenString. QString -Token::getTokenString() +Token::getString() { return m_tokenString; } --- trunk/extragear/multimedia/amarok/src/widgets/Token.h #855517:855518 @@ -23,18 +23,20 @@ //Defines a part of a filename, drag&droppable in the FilenameLayoutWidget bar from the TokenListWidget list. class Token - : public QLabel + : public QFrame { Q_OBJECT public: +// explicit Token( QWidget *parent = 0 ); explicit Token( const QString &string, QWidget *parent = 0 ); - QString getTokenString(); - + QString getString(); + void setString(const QString &string ); + private: - void setTokenString(const QString &string ); - unsigned int m_myCount; QString m_tokenString; + QPixmap *m_icon; + QLabel *m_label; }; #endif //TOKEN_H --- trunk/extragear/multimedia/amarok/src/widgets/TokenListWidget.cpp #855517:855518 @@ -43,7 +43,12 @@ { QListWidgetItem *token = itemAt( event->pos() ); debug()<<"Double-clicked, gonna add token!"; - emit onDoubleClick( token->text() ); + if( token == 0 )//is null + { + debug() << "I have NULL as token!"; + } + else + emit onDoubleClick( token->text() ); } //Executed on mouse press, handles start of drag.