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

« back to all changes in this revision

Viewing changes to src/libtomahawk/playlist/FlexibleHeader.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
 *   Copyright 2012,      Teo Mrnjavac <teo@kde.org>
 
5
 *
 
6
 *   Tomahawk is free software: you can redistribute it and/or modify
 
7
 *   it under the terms of the GNU General Public License as published by
 
8
 *   the Free Software Foundation, either version 3 of the License, or
 
9
 *   (at your option) any later version.
 
10
 *
 
11
 *   Tomahawk is distributed in the hope that it will be useful,
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
 *   GNU General Public License for more details.
 
15
 *
 
16
 *   You should have received a copy of the GNU General Public License
 
17
 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "FlexibleHeader.h"
 
21
 
 
22
#include <QBoxLayout>
 
23
#include <QLabel>
 
24
#include <QPixmap>
 
25
#include <QCheckBox>
 
26
#include <QPaintEvent>
 
27
#include <QPainter>
 
28
#include <QRadioButton>
 
29
 
 
30
#include "playlist/FlexibleView.h"
 
31
#include "ViewManager.h"
 
32
#include "thirdparty/Qocoa/qsearchfield.h"
 
33
#include "utils/Closure.h"
 
34
#include "utils/TomahawkUtilsGui.h"
 
35
#include "utils/Logger.h"
 
36
#include "widgets/QueryLabel.h"
 
37
#include "Source.h"
 
38
 
 
39
using namespace Tomahawk;
 
40
 
 
41
 
 
42
FlexibleHeader::FlexibleHeader( FlexibleView* parent )
 
43
    : BasicHeader( parent )
 
44
    , m_parent( parent )
 
45
{
 
46
    QFile f( RESPATH "stylesheets/topbar-radiobuttons.css" );
 
47
    f.open( QFile::ReadOnly );
 
48
    QString css = QString::fromAscii( f.readAll() );
 
49
    f.close();
 
50
 
 
51
    QHBoxLayout* outerModeLayout = new QHBoxLayout;
 
52
    m_verticalLayout->addLayout( outerModeLayout );
 
53
    outerModeLayout->addSpacing( 156 );
 
54
    outerModeLayout->addStretch();
 
55
 
 
56
    QWidget* modeWidget = new QWidget( this );
 
57
    QHBoxLayout* modeLayout = new QHBoxLayout;
 
58
    modeWidget->setLayout( modeLayout );
 
59
    modeWidget->setStyleSheet( css );
 
60
 
 
61
    m_radioNormal = new QRadioButton( modeWidget );
 
62
    m_radioDetailed = new QRadioButton( modeWidget );
 
63
    m_radioCloud = new QRadioButton( modeWidget );
 
64
    //for the CSS:
 
65
    m_radioNormal->setObjectName( "radioNormal" );
 
66
    m_radioCloud->setObjectName( "radioCloud" );
 
67
 
 
68
    m_radioNormal->setFocusPolicy( Qt::NoFocus );
 
69
    m_radioDetailed->setFocusPolicy( Qt::NoFocus );
 
70
    m_radioCloud->setFocusPolicy( Qt::NoFocus );
 
71
 
 
72
    modeLayout->addWidget( m_radioNormal );
 
73
    modeLayout->addWidget( m_radioDetailed );
 
74
    modeLayout->addWidget( m_radioCloud );
 
75
 
 
76
    modeWidget->setFixedSize( 87, 30 );
 
77
 
 
78
    m_radioNormal->setChecked( true );
 
79
 
 
80
    outerModeLayout->addWidget( modeWidget );
 
81
    outerModeLayout->addStretch();
 
82
 
 
83
    m_filterField = new QSearchField( this );
 
84
    m_filterField->setPlaceholderText( tr( "Filter..." ) );
 
85
    m_filterField->setFixedWidth( 220 );
 
86
    m_mainLayout->addWidget( m_filterField );
 
87
 
 
88
    TomahawkUtils::unmarginLayout( outerModeLayout );
 
89
    TomahawkUtils::unmarginLayout( modeLayout );
 
90
 
 
91
    connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
 
92
    connect( m_filterField, SIGNAL( textChanged( QString ) ), SLOT( onFilterEdited() ) );
 
93
 
 
94
    NewClosure( m_radioNormal,   SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Flat )->setAutoDelete( false );
 
95
    NewClosure( m_radioDetailed, SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Detailed )->setAutoDelete( false );
 
96
    NewClosure( m_radioCloud,    SIGNAL( clicked() ), const_cast< FlexibleView* >( parent ), SLOT( setCurrentMode( FlexibleViewMode ) ), FlexibleView::Grid )->setAutoDelete( false );
 
97
}
 
98
 
 
99
 
 
100
FlexibleHeader::~FlexibleHeader()
 
101
{
 
102
}
 
103
 
 
104
 
 
105
void
 
106
FlexibleHeader::setFilter( const QString& filter )
 
107
{
 
108
    m_filterField->setText( filter );
 
109
}
 
110
 
 
111
 
 
112
void
 
113
FlexibleHeader::onFilterEdited()
 
114
{
 
115
    m_filter = m_filterField->text();
 
116
 
 
117
    m_filterTimer.stop();
 
118
    m_filterTimer.setInterval( 280 );
 
119
    m_filterTimer.setSingleShot( true );
 
120
    m_filterTimer.start();
 
121
}
 
122
 
 
123
 
 
124
void
 
125
FlexibleHeader::applyFilter()
 
126
{
 
127
    emit filterTextChanged( m_filterField->text() );
 
128
}
 
129
 
 
130
 
 
131
void
 
132
FlexibleHeader::changeEvent( QEvent* e )
 
133
{
 
134
    QWidget::changeEvent( e );
 
135
    switch ( e->type() )
 
136
    {
 
137
        case QEvent::LanguageChange:
 
138
//            ui->retranslateUi( this );
 
139
            break;
 
140
 
 
141
        default:
 
142
            break;
 
143
    }
 
144
}
 
145