~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/widgets/QueryLabel.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 
4
 *
 
5
 *   Tomahawk is free software: you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU General Public License as published by
 
7
 *   the Free Software Foundation, either version 3 of the License, or
 
8
 *   (at your option) any later version.
 
9
 *
 
10
 *   Tomahawk is distributed in the hope that it will be useful,
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
 *   GNU General Public License for more details.
 
14
 *
 
15
 *   You should have received a copy of the GNU General Public License
 
16
 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include "QueryLabel.h"
 
20
 
 
21
#include <QApplication>
 
22
#include <QEvent>
 
23
#include <QFontMetrics>
 
24
#include <QMouseEvent>
 
25
#include <QPainter>
 
26
 
 
27
#include "Artist.h"
 
28
#include "Album.h"
 
29
#include "Query.h"
 
30
#include "ContextMenu.h"
 
31
#include "utils/TomahawkUtilsGui.h"
 
32
#include "utils/Logger.h"
 
33
#include "ViewManager.h"
 
34
#include "Source.h"
 
35
 
 
36
#define BOXMARGIN 2
 
37
#define DASH "  -  "
 
38
 
 
39
using namespace Tomahawk;
 
40
 
 
41
 
 
42
QueryLabel::QueryLabel( QWidget* parent, Qt::WindowFlags flags )
 
43
    : QFrame( parent, flags )
 
44
    , m_type( Complete )
 
45
{
 
46
    init();
 
47
}
 
48
 
 
49
 
 
50
QueryLabel::QueryLabel( DisplayType type, QWidget* parent, Qt::WindowFlags flags )
 
51
    : QFrame( parent, flags )
 
52
    , m_type( type )
 
53
{
 
54
    init();
 
55
}
 
56
 
 
57
 
 
58
QueryLabel::QueryLabel( const Tomahawk::result_ptr& result, DisplayType type, QWidget* parent, Qt::WindowFlags flags )
 
59
    : QFrame( parent, flags )
 
60
    , m_type( type )
 
61
    , m_result( result )
 
62
{
 
63
    init();
 
64
}
 
65
 
 
66
 
 
67
QueryLabel::QueryLabel( const Tomahawk::query_ptr& query, DisplayType type, QWidget* parent, Qt::WindowFlags flags )
 
68
    : QFrame( parent, flags )
 
69
    , m_type( type )
 
70
    , m_query( query )
 
71
{
 
72
    init();
 
73
}
 
74
 
 
75
 
 
76
QueryLabel::~QueryLabel()
 
77
{
 
78
}
 
79
 
 
80
 
 
81
void
 
82
QueryLabel::init()
 
83
{
 
84
    m_contextMenu = new ContextMenu( this );
 
85
    m_contextMenu->setSupportedActions( ContextMenu::ActionQueue | ContextMenu::ActionCopyLink | ContextMenu::ActionStopAfter | ContextMenu::ActionLove | ContextMenu::ActionPage );
 
86
 
 
87
    m_hoverType = None;
 
88
    setContentsMargins( 0, 0, 0, 0 );
 
89
    setMouseTracking( true );
 
90
 
 
91
    m_useCustomPen = false;
 
92
    m_align = Qt::AlignLeft | Qt::AlignVCenter;
 
93
    m_mode = Qt::ElideMiddle;
 
94
 
 
95
    m_jumpLinkVisible = false;
 
96
}
 
97
 
 
98
 
 
99
QString
 
100
QueryLabel::text() const
 
101
{
 
102
    QString text;
 
103
 
 
104
    if ( m_result.isNull() && m_query.isNull() && m_artist.isNull() && m_album.isNull() )
 
105
        return m_text;
 
106
 
 
107
    if ( !m_result.isNull() )
 
108
    {
 
109
        if ( m_type & Artist )
 
110
        {
 
111
            text += m_result->artist()->name();
 
112
        }
 
113
        if ( m_type & Album && !m_result->album()->name().isEmpty() )
 
114
        {
 
115
            smartAppend( text, m_result->album()->name() );
 
116
        }
 
117
        if ( m_type & Track )
 
118
        {
 
119
            smartAppend( text, m_result->track() );
 
120
        }
 
121
    }
 
122
    else if ( !m_query.isNull() )
 
123
    {
 
124
        if ( m_type & Artist )
 
125
        {
 
126
            text += m_query->artist();
 
127
        }
 
128
        if ( m_type & Album && !m_query->album().isEmpty() )
 
129
        {
 
130
            smartAppend( text, m_query->album() );
 
131
        }
 
132
        if ( m_type & Track )
 
133
        {
 
134
            smartAppend( text, m_query->track() );
 
135
        }
 
136
    }
 
137
    else if ( !m_artist.isNull() )
 
138
    {
 
139
        text += m_artist->name();
 
140
    }
 
141
    else if ( !m_album.isNull() )
 
142
    {
 
143
        text += m_album->name();
 
144
    }
 
145
 
 
146
    return text;
 
147
}
 
148
 
 
149
 
 
150
QString
 
151
QueryLabel::track() const
 
152
{
 
153
    if ( m_result.isNull() && m_query.isNull() )
 
154
        return QString();
 
155
 
 
156
    if ( !m_result.isNull() )
 
157
        return m_result->track();
 
158
    else
 
159
        return m_query->track();
 
160
}
 
161
 
 
162
 
 
163
void
 
164
QueryLabel::setText( const QString& text )
 
165
{
 
166
    setContentsMargins( m_textMargins );
 
167
 
 
168
    m_result.clear();
 
169
    m_query.clear();
 
170
    m_artist.clear();
 
171
    m_album.clear();
 
172
    m_text = text;
 
173
 
 
174
    updateLabel();
 
175
 
 
176
    emit textChanged( m_text );
 
177
    emit resultChanged( m_result );
 
178
}
 
179
 
 
180
 
 
181
void
 
182
QueryLabel::onResultChanged()
 
183
{
 
184
    m_query = m_result->toQuery();
 
185
    m_artist = m_result->artist();
 
186
    m_album = m_result->album();
 
187
 
 
188
    updateLabel();
 
189
 
 
190
    emit textChanged( text() );
 
191
}
 
192
 
 
193
 
 
194
void
 
195
QueryLabel::setResult( const Tomahawk::result_ptr& result )
 
196
{
 
197
    if ( result.isNull() )
 
198
        return;
 
199
 
 
200
    if ( !m_text.isEmpty() && contentsMargins().left() != 0 ) // FIXME: hacky
 
201
        m_textMargins = contentsMargins();
 
202
 
 
203
    setContentsMargins( BOXMARGIN * 2, BOXMARGIN / 2, BOXMARGIN * 2, BOXMARGIN / 2);
 
204
 
 
205
    if ( m_result.isNull() || m_result.data() != result.data() )
 
206
    {
 
207
        m_result = result;
 
208
        connect( m_result.data(), SIGNAL( updated() ), SLOT( onResultChanged() ) );
 
209
 
 
210
        onResultChanged();
 
211
        emit resultChanged( m_result );
 
212
    }
 
213
}
 
214
 
 
215
 
 
216
void
 
217
QueryLabel::setQuery( const Tomahawk::query_ptr& query )
 
218
{
 
219
    if ( query.isNull() )
 
220
        return;
 
221
 
 
222
    setContentsMargins( BOXMARGIN * 2, BOXMARGIN / 2, BOXMARGIN * 2, BOXMARGIN / 2 );
 
223
 
 
224
    if ( m_query.isNull() || m_query.data() != query.data() )
 
225
    {
 
226
        m_query = query;
 
227
        m_artist = Artist::get( query->artist() );
 
228
        m_album = Album::get( m_artist, query->album() );
 
229
        m_result.clear();
 
230
 
 
231
        updateLabel();
 
232
 
 
233
        emit textChanged( text() );
 
234
        emit queryChanged( m_query );
 
235
    }
 
236
}
 
237
 
 
238
 
 
239
void
 
240
QueryLabel::setArtist( const artist_ptr& artist )
 
241
{
 
242
    m_artist = artist;
 
243
 
 
244
    updateLabel();
 
245
    emit textChanged( text() );
 
246
}
 
247
 
 
248
 
 
249
void
 
250
QueryLabel::setAlbum( const album_ptr& album )
 
251
{
 
252
    m_album = album;
 
253
 
 
254
    updateLabel();
 
255
    emit textChanged( text() );
 
256
}
 
257
 
 
258
 
 
259
void
 
260
QueryLabel::setJumpLinkVisible( bool visible )
 
261
{
 
262
    m_jumpLinkVisible = visible;
 
263
    repaint();
 
264
}
 
265
 
 
266
 
 
267
Qt::Alignment
 
268
QueryLabel::alignment() const
 
269
{
 
270
    return m_align;
 
271
}
 
272
 
 
273
 
 
274
void
 
275
QueryLabel::setAlignment( Qt::Alignment alignment )
 
276
{
 
277
    if ( m_align != alignment )
 
278
    {
 
279
        m_align = alignment;
 
280
        update(); // no geometry change, repaint is sufficient
 
281
    }
 
282
}
 
283
 
 
284
 
 
285
void
 
286
QueryLabel::setTextPen( const QPen & pen )
 
287
{
 
288
    m_useCustomPen = true;
 
289
    m_textPen = pen;
 
290
}
 
291
 
 
292
 
 
293
QPen
 
294
QueryLabel::textPen() const
 
295
{
 
296
    return m_textPen;
 
297
}
 
298
 
 
299
 
 
300
Qt::TextElideMode
 
301
QueryLabel::elideMode() const
 
302
{
 
303
    return m_mode;
 
304
}
 
305
 
 
306
 
 
307
void
 
308
QueryLabel::setElideMode( Qt::TextElideMode mode )
 
309
{
 
310
    if ( m_mode != mode )
 
311
    {
 
312
        m_mode = mode;
 
313
        updateLabel();
 
314
    }
 
315
}
 
316
 
 
317
 
 
318
void
 
319
QueryLabel::updateLabel()
 
320
{
 
321
    m_hoverArea = QRect();
 
322
    m_hoverType = None;
 
323
 
 
324
    updateGeometry();
 
325
    update();
 
326
}
 
327
 
 
328
 
 
329
void
 
330
QueryLabel::setExtraContentsMargins( int left, int top, int right, int bottom )
 
331
{
 
332
    QMargins margins = contentsMargins();
 
333
    margins.setLeft( margins.left() + left );
 
334
    margins.setTop( margins.top() + top );
 
335
    margins.setRight( margins.right() + right );
 
336
    margins.setBottom( margins.bottom() + bottom );
 
337
    setContentsMargins( margins );
 
338
}
 
339
 
 
340
 
 
341
QSize
 
342
QueryLabel::sizeHint() const
 
343
{
 
344
    const QFontMetrics& fm = fontMetrics();
 
345
    QSize size( fm.width( text() ) + contentsMargins().left() * 2, fm.height() + contentsMargins().top() * 2 );
 
346
    return size;
 
347
}
 
348
 
 
349
 
 
350
QSize
 
351
QueryLabel::minimumSizeHint() const
 
352
{
 
353
    switch ( m_mode )
 
354
    {
 
355
        case Qt::ElideNone:
 
356
            return sizeHint();
 
357
 
 
358
        default:
 
359
        {
 
360
            const QFontMetrics& fm = fontMetrics();
 
361
            QSize size( fm.width( "..." ), fm.height() + contentsMargins().top() * 2  );
 
362
            return size;
 
363
        }
 
364
    }
 
365
}
 
366
 
 
367
 
 
368
void
 
369
QueryLabel::paintEvent( QPaintEvent* event )
 
370
{
 
371
    QFrame::paintEvent( event );
 
372
    QPainter p( this );
 
373
    QRect r = contentsRect();
 
374
    QString s = text();
 
375
    const QFontMetrics& fm = fontMetrics();
 
376
    const QString elidedText = fm.elidedText( s, m_mode, r.width() );
 
377
 
 
378
    p.save();
 
379
    p.setRenderHint( QPainter::Antialiasing );
 
380
 
 
381
    if ( m_hoverArea.width() )
 
382
    {
 
383
        if ( elidedText != s )
 
384
        {
 
385
            m_hoverArea.setLeft( 0 );
 
386
            m_hoverArea.setRight( fm.width( elidedText ) + contentsMargins().left() * 2 );
 
387
            m_hoverType = Track;
 
388
        }
 
389
 
 
390
        TomahawkUtils::drawQueryBackground( &p, m_hoverArea );
 
391
    }
 
392
 
 
393
    if ( elidedText != s || ( m_result.isNull() && m_query.isNull() && m_artist.isNull() && m_album.isNull() ) )
 
394
    {
 
395
        if ( m_hoverArea.width() )
 
396
        {
 
397
            p.setBrush( TomahawkUtils::Colors::SELECTION_BACKGROUND );
 
398
            p.setPen( TomahawkUtils::Colors::SELECTION_FOREGROUND );
 
399
        }
 
400
        else
 
401
        {
 
402
            p.setBrush( palette().window() );
 
403
            p.setPen( palette().color( foregroundRole() ) );
 
404
        }
 
405
 
 
406
        p.drawText( r, m_align, elidedText );
 
407
    }
 
408
    else
 
409
    {
 
410
        int dashX = fm.width( DASH );
 
411
        int artistX = m_type & Artist ? fm.width( artist()->name() ) : 0;
 
412
        int albumX = m_type & Album ? fm.width( album()->name() ) : 0;
 
413
        int trackX = m_type & Track ? fm.width( track() ) : 0;
 
414
 
 
415
        if ( m_useCustomPen )
 
416
            p.setPen( m_textPen );
 
417
 
 
418
        if ( m_type & Artist )
 
419
        {
 
420
            p.setBrush( palette().window() );
 
421
            if ( !m_useCustomPen )
 
422
                p.setPen( palette().color( foregroundRole() ) );
 
423
 
 
424
            if ( m_hoverType == Artist )
 
425
            {
 
426
                p.setPen( palette().highlightedText().color() );
 
427
                p.setBrush( palette().highlight() );
 
428
            }
 
429
 
 
430
            p.drawText( r, m_align, artist()->name() );
 
431
            r.adjust( artistX, 0, 0, 0 );
 
432
        }
 
433
        if ( m_type & Album && !album()->name().isEmpty() )
 
434
        {
 
435
            p.setBrush( palette().window() );
 
436
            if ( !m_useCustomPen )
 
437
                p.setPen( palette().color( foregroundRole() ) );
 
438
 
 
439
            if ( m_type & Artist )
 
440
            {
 
441
                p.drawText( r, m_align, DASH );
 
442
                r.adjust( dashX, 0, 0, 0 );
 
443
            }
 
444
            if ( m_hoverType == Album )
 
445
            {
 
446
                p.setPen( palette().highlightedText().color() );
 
447
                p.setBrush( palette().highlight() );
 
448
            }
 
449
 
 
450
            p.drawText( r, m_align, album()->name() );
 
451
            r.adjust( albumX, 0, 0, 0 );
 
452
        }
 
453
        if ( m_type & Track )
 
454
        {
 
455
            p.setBrush( palette().window() );
 
456
            if ( !m_useCustomPen )
 
457
                p.setPen( palette().color( foregroundRole() ) );
 
458
 
 
459
            if ( m_type & Artist || ( m_type & Album && !album()->name().isEmpty() ) )
 
460
            {
 
461
                p.drawText( r, m_align, DASH );
 
462
                r.adjust( dashX, 0, 0, 0 );
 
463
            }
 
464
            if ( m_hoverType == Track )
 
465
            {
 
466
                p.setPen( palette().highlightedText().color() );
 
467
                p.setBrush( palette().highlight() );
 
468
            }
 
469
 
 
470
            p.drawText( r, m_align, track() );
 
471
            r.adjust( trackX, 0, 0, 0 );
 
472
        }
 
473
 
 
474
        if ( m_jumpLinkVisible )
 
475
        {
 
476
            r.adjust( 6, 0, 0, 0 );
 
477
            r.setWidth( r.height() );
 
478
            p.drawPixmap( r, TomahawkUtils::defaultPixmap( TomahawkUtils::JumpLink, TomahawkUtils::Original, r.size() ) );
 
479
        }
 
480
    }
 
481
 
 
482
    p.restore();
 
483
}
 
484
 
 
485
 
 
486
void
 
487
QueryLabel::changeEvent( QEvent* event )
 
488
{
 
489
    QFrame::changeEvent( event );
 
490
    switch ( event->type() )
 
491
    {
 
492
        case QEvent::FontChange:
 
493
        case QEvent::ApplicationFontChange:
 
494
            updateLabel();
 
495
            break;
 
496
 
 
497
        default:
 
498
            break;
 
499
    }
 
500
}
 
501
 
 
502
 
 
503
void
 
504
QueryLabel::contextMenuEvent( QContextMenuEvent* event )
 
505
{
 
506
    m_contextMenu->clear();
 
507
 
 
508
    switch( m_hoverType )
 
509
    {
 
510
        case Artist:
 
511
        {
 
512
            m_contextMenu->setArtist( artist() );
 
513
            break;
 
514
        }
 
515
        case Album:
 
516
        {
 
517
            m_contextMenu->setAlbum( album() );
 
518
            break;
 
519
        }
 
520
 
 
521
        default:
 
522
            m_contextMenu->setQuery( m_query );
 
523
    }
 
524
 
 
525
    m_contextMenu->exec( event->globalPos() );
 
526
}
 
527
 
 
528
 
 
529
void
 
530
QueryLabel::mousePressEvent( QMouseEvent* event )
 
531
{
 
532
    QFrame::mousePressEvent( event );
 
533
    m_time.restart();
 
534
    m_dragPos = event->pos();
 
535
}
 
536
 
 
537
 
 
538
void
 
539
QueryLabel::mouseReleaseEvent( QMouseEvent* event )
 
540
{
 
541
    QFrame::mouseReleaseEvent( event );
 
542
 
 
543
    m_dragPos = QPoint();
 
544
    if ( m_time.elapsed() < qApp->doubleClickInterval() )
 
545
    {
 
546
        switch( m_hoverType )
 
547
        {
 
548
            case Artist:
 
549
                emit clickedArtist();
 
550
                break;
 
551
            case Album:
 
552
                emit clickedAlbum();
 
553
                break;
 
554
            case Track:
 
555
                emit clickedTrack();
 
556
                break;
 
557
 
 
558
            case Complete:
 
559
                ViewManager::instance()->showCurrentTrack();
 
560
                break;
 
561
 
 
562
            default:
 
563
                emit clicked();
 
564
        }
 
565
    }
 
566
}
 
567
 
 
568
 
 
569
void
 
570
QueryLabel::mouseMoveEvent( QMouseEvent* event )
 
571
{
 
572
    QFrame::mouseMoveEvent( event );
 
573
    int x = event->x();
 
574
 
 
575
    if ( event->buttons() & Qt::LeftButton &&
 
576
       ( m_dragPos - event->pos() ).manhattanLength() >= QApplication::startDragDistance() )
 
577
    {
 
578
        startDrag();
 
579
        leaveEvent( 0 );
 
580
        return;
 
581
    }
 
582
 
 
583
    if ( m_query.isNull() && m_result.isNull() && m_artist.isNull() && m_album.isNull() )
 
584
    {
 
585
        m_hoverArea = QRect();
 
586
        m_hoverType = None;
 
587
        return;
 
588
    }
 
589
 
 
590
    QFontMetrics fm = fontMetrics();
 
591
 
 
592
    int dashX = fm.width( DASH );
 
593
    int artistX = m_type & Artist ? fm.width( artist()->name() ) : 0;
 
594
    int albumX = m_type & Album ? fm.width( album()->name() ) : 0;
 
595
    int trackX = m_type & Track ? fm.width( track() ) : 0;
 
596
 
 
597
    if ( m_type & Track )
 
598
    {
 
599
        trackX += contentsMargins().left();
 
600
    }
 
601
    if ( m_type & Album && !album()->name().isEmpty() )
 
602
    {
 
603
        trackX += albumX + dashX;
 
604
        albumX += contentsMargins().left();
 
605
    }
 
606
    if ( m_type & Artist )
 
607
    {
 
608
        albumX += artistX + dashX;
 
609
        trackX += artistX + dashX;
 
610
        artistX += contentsMargins().left();
 
611
    }
 
612
 
 
613
    QRect hoverArea;
 
614
    m_hoverType = None;
 
615
 
 
616
    if ( m_align & Qt::AlignLeft )
 
617
    {
 
618
        if ( m_type & Artist && x < artistX )
 
619
        {
 
620
            m_hoverType = Artist;
 
621
            hoverArea.setLeft( 0 );
 
622
            hoverArea.setRight( artistX + contentsMargins().left() - 1 );
 
623
        }
 
624
        else if ( m_type & Album && !album()->name().isEmpty() && x < albumX && x > artistX )
 
625
        {
 
626
            m_hoverType = Album;
 
627
            int spacing = ( m_type & Artist ) ? dashX : 0;
 
628
            hoverArea.setLeft( artistX + spacing - contentsMargins().left() );
 
629
            hoverArea.setRight( albumX + contentsMargins().left() - 1 );
 
630
        }
 
631
        else if ( m_type & Track && x < trackX && x > albumX )
 
632
        {
 
633
            m_hoverType = Track;
 
634
            int spacing = ( m_type & Album && !album()->name().isEmpty() ) ? dashX : 0;
 
635
            hoverArea.setLeft( albumX + spacing );
 
636
            hoverArea.setRight( trackX + contentsMargins().left() - 1 );
 
637
        }
 
638
        else if ( m_jumpLinkVisible && x < trackX + 6 + fm.height() && x > trackX + 6 )
 
639
        {
 
640
            m_hoverType = Complete;
 
641
        }
 
642
    }
 
643
    else
 
644
    {
 
645
        hoverArea.setLeft( 0 );
 
646
        hoverArea.setRight( width() - 1 );
 
647
 
 
648
        if ( m_type & Artist )
 
649
            m_hoverType = Artist;
 
650
        else if ( m_type & Album )
 
651
            m_hoverType = Album;
 
652
        else if ( m_type & Track )
 
653
            m_hoverType = Track;
 
654
    }
 
655
 
 
656
    if ( hoverArea.width() )
 
657
    {
 
658
        hoverArea.setY( 1 );
 
659
        hoverArea.setHeight( height() - 2 );
 
660
    }
 
661
 
 
662
    if ( m_hoverType != None )
 
663
        setCursor( Qt::PointingHandCursor );
 
664
    else
 
665
        setCursor( Qt::ArrowCursor );
 
666
 
 
667
    if ( hoverArea != m_hoverArea )
 
668
    {
 
669
        m_hoverArea = hoverArea;
 
670
        repaint();
 
671
    }
 
672
}
 
673
 
 
674
 
 
675
void
 
676
QueryLabel::leaveEvent( QEvent* event )
 
677
{
 
678
    Q_UNUSED( event );
 
679
    m_hoverArea = QRect();
 
680
    m_hoverType = None;
 
681
    repaint();
 
682
}
 
683
 
 
684
 
 
685
void
 
686
QueryLabel::startDrag()
 
687
{
 
688
    if ( m_query.isNull() && m_album.isNull() && m_artist.isNull() )
 
689
        return;
 
690
 
 
691
    QDrag *drag = new QDrag( this );
 
692
    QByteArray data;
 
693
    QDataStream dataStream( &data, QIODevice::WriteOnly );
 
694
    QMimeData* mimeData = new QMimeData();
 
695
    mimeData->setText( text() );
 
696
 
 
697
    switch( m_hoverType )
 
698
    {
 
699
            case Artist:
 
700
            {
 
701
                dataStream << artist()->name();
 
702
                mimeData->setData( "application/tomahawk.metadata.artist", data );
 
703
                drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeArtist ) );
 
704
                break;
 
705
            }
 
706
            case Album:
 
707
            {
 
708
                dataStream << artist()->name();
 
709
                dataStream << album()->name();
 
710
                mimeData->setData( "application/tomahawk.metadata.album", data );
 
711
                drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeAlbum ) );
 
712
                break;
 
713
            }
 
714
 
 
715
            default:
 
716
            {
 
717
                dataStream << qlonglong( &m_query );
 
718
                mimeData->setData( "application/tomahawk.query.list", data );
 
719
                drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeTrack ) );
 
720
                break;
 
721
            }
 
722
    }
 
723
 
 
724
    drag->setMimeData( mimeData );
 
725
 
 
726
//    QPoint hotSpot = event->pos() - child->pos();
 
727
//    drag->setHotSpot( hotSpot );
 
728
 
 
729
    drag->exec( Qt::CopyAction );
 
730
}
 
731
 
 
732
 
 
733
QString
 
734
QueryLabel::smartAppend( QString& text, const QString& appendage ) const
 
735
{
 
736
    QString s;
 
737
    if ( !text.isEmpty() )
 
738
        s = DASH;
 
739
 
 
740
    text += s + appendage;
 
741
    return text;
 
742
}