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

« back to all changes in this revision

Viewing changes to src/libtomahawk/widgets/ComboBox.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 2011, Casey Link <unnamedrambler@gmail.com>
 
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 "ComboBox.h"
 
20
 
 
21
#include "utils/StyleHelper.h"
 
22
#include "utils/TomahawkUtilsGui.h"
 
23
#include "utils/Logger.h"
 
24
 
 
25
#include <QStyle>
 
26
#include <QTextOption>
 
27
#include <QStylePainter>
 
28
#include <QStyleOptionComboBox>
 
29
 
 
30
 
 
31
ComboBox::ComboBox( QWidget* parent )
 
32
    : QComboBox( parent )
 
33
{
 
34
}
 
35
 
 
36
 
 
37
ComboBox::~ComboBox()
 
38
{
 
39
}
 
40
 
 
41
 
 
42
QSize
 
43
ComboBox::sizeHint() const
 
44
{
 
45
    return QComboBox::sizeHint() + QSize( 8, 0 );
 
46
}
 
47
 
 
48
 
 
49
void
 
50
ComboBox::paintEvent( QPaintEvent* )
 
51
{
 
52
    QStylePainter p( this );
 
53
    p.setPen( palette().color( QPalette::Text ) );
 
54
    QStyleOptionComboBox cb;
 
55
    initStyleOption( &cb );
 
56
    QRect r = cb.rect;
 
57
    r.setHeight( TomahawkUtils::defaultFontHeight() + 8 );
 
58
 
 
59
    StyleHelper::horizontalHeader( &p, r );
 
60
 
 
61
    if ( cb.state & QStyle::State_MouseOver )
 
62
    {
 
63
        p.save();
 
64
        QRect highlightRect( r );
 
65
        QSize shrink( 3, 4 );
 
66
        QSize hS( highlightRect.size() );
 
67
        hS -= shrink;
 
68
        highlightRect.setSize( hS );
 
69
        highlightRect.translate( 0, 2 );
 
70
        p.setRenderHint( QPainter::Antialiasing );
 
71
        p.setBrush( StyleHelper::headerHighlightColor() );
 
72
        p.drawRoundedRect( highlightRect, 10.0, 10.0 );
 
73
        p.restore();
 
74
    }
 
75
 
 
76
    p.save();
 
77
    QTextOption to( Qt::AlignVCenter );
 
78
    r.adjust( 8, 0, -8, 0 );
 
79
    p.setPen( Qt::white );
 
80
    p.setBrush( StyleHelper::headerTextColor() );
 
81
    p.drawText( r, cb.currentText, to );
 
82
 
 
83
    bool reverse = cb.direction == Qt::RightToLeft;
 
84
    int menuButtonWidth = 12;
 
85
    int left = !reverse ? r.right() - menuButtonWidth : r.left();
 
86
    int right = !reverse ? r.right() : r.left() + menuButtonWidth;
 
87
    QRect arrowRect( ( left + right ) / 2 + ( reverse ? 6 : -6 ), r.center().y() - 3, 9, 9 ); //FIXME: no consts please
 
88
 
 
89
    QStyleOption arrowOpt = cb;
 
90
    arrowOpt.rect = arrowRect;
 
91
    StyleHelper::drawArrow( QStyle::PE_IndicatorArrowDown, &p, &arrowOpt );
 
92
    p.restore();
 
93
}