2
* This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com>
4
* This file is licensed by the GPL version 2. Works owned by the
5
* Transmission project are granted a special exemption to clause 2(b)
6
* so that the bulk of its code can remain under the MIT license.
7
* This exemption does not extend to derived works not owned by
8
* the Transmission project.
15
#include <QApplication>
18
#include <QFontMetrics>
20
#include <QModelIndex>
23
#include <QPixmapCache>
24
#include <QStyleOptionProgressBarV2>
27
#include "torrent-delegate-min.h"
28
#include "torrent-model.h"
30
#include "qticonloader.h"
41
**** +---------+-----------------------------------------------+
42
**** | Icon | Title shortStatusString |
43
**** | Icon | [ Progressbar.......................... ] |
44
**** +-------- +-----------------------------------------------+
49
TorrentDelegateMin :: sizeHint( const QStyleOptionViewItem& option, const Torrent& tor ) const
51
const QStyle* style( QApplication::style( ) );
52
static const int iconSize( style->pixelMetric( QStyle :: PM_SmallIconSize ) );
54
QFont nameFont( option.font );
55
const QFontMetrics nameFM( nameFont );
56
const QString nameStr( tor.name( ) );
57
const QSize nameSize( nameFM.size( 0, nameStr ) );
59
QFont statusFont( option.font );
60
statusFont.setPointSize( int( option.font.pointSize( ) * 0.85 ) );
61
const QFontMetrics statusFM( statusFont );
62
const QString statusStr( shortStatusString( tor ) );
63
const QSize statusSize( statusFM.size( 0, statusStr ) );
65
const QSize m( margin( *style ) );
67
return QSize( m.width() + iconSize + GUI_PAD + nameSize.width() + GUI_PAD + statusSize.width() + m.width(),
68
m.height() + nameSize.height() + LINE_SPACING + BAR_HEIGHT + m.height() );
72
TorrentDelegateMin :: drawTorrent( QPainter * painter, const QStyleOptionViewItem& option, const Torrent& tor ) const
74
const bool isPaused( tor.isPaused( ) );
75
const QStyle * style( QApplication::style( ) );
76
static const int iconSize( style->pixelMetric( QStyle :: PM_SmallIconSize ) );
78
QFont nameFont( option.font );
79
const QFontMetrics nameFM( nameFont );
80
const QString nameStr( tor.name( ) );
81
const QSize nameSize( nameFM.size( 0, nameStr ) );
83
QFont statusFont( option.font );
84
statusFont.setPointSize( int( option.font.pointSize( ) * 0.85 ) );
85
const QFontMetrics statusFM( statusFont );
86
const QString statusStr( shortStatusString( tor ) );
87
const QSize statusSize( statusFM.size( 0, statusStr ) );
91
if (option.state & QStyle::State_Selected) {
92
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
93
? QPalette::Normal : QPalette::Disabled;
94
if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
95
cg = QPalette::Inactive;
97
painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
101
if( isPaused || !(option.state & QStyle::State_Enabled ) ) im = QIcon::Disabled;
102
else if( option.state & QStyle::State_Selected ) im = QIcon::Selected;
103
else im = QIcon::Normal;
106
if( isPaused ) qs = QIcon::Off;
109
QPalette::ColorGroup cg = QPalette::Normal;
110
if( isPaused || !(option.state & QStyle::State_Enabled ) ) cg = QPalette::Disabled;
111
if( cg == QPalette::Normal && !(option.state & QStyle::State_Active ) ) cg = QPalette::Inactive;
113
QPalette::ColorRole cr;
114
if( option.state & QStyle::State_Selected ) cr = QPalette::HighlightedText;
115
else cr = QPalette::Text;
118
const QSize m( margin( *style ) );
119
QRect fillArea( option.rect );
120
fillArea.adjust( m.width(), m.height(), -m.width(), -m.height() );
121
const QRect iconArea( fillArea.x( ),
122
fillArea.y( ) + ( fillArea.height( ) - iconSize ) / 2,
125
const QRect statusArea( fillArea.width( ) - statusSize.width( ),
126
fillArea.top( ) + ((nameSize.height()-statusSize.height())/2),
128
statusSize.height( ) );
129
const QRect nameArea( iconArea.x( ) + iconArea.width( ) + GUI_PAD,
131
fillArea.width( ) - statusArea.width( ) - (GUI_PAD*2) - iconArea.width( ),
132
nameSize.height( ) );
133
const QRect barArea( nameArea.left( ),
135
statusArea.right( ) - nameArea.left( ),
139
if( tor.hasError( ) )
140
painter->setPen( QColor( "red" ) );
142
painter->setPen( option.palette.color( cg, cr ) );
143
tor.getMimeTypeIcon().paint( painter, iconArea, Qt::AlignCenter, im, qs );
144
painter->setFont( nameFont );
145
painter->drawText( nameArea, 0, nameFM.elidedText( nameStr, Qt::ElideRight, nameArea.width( ) ) );
146
painter->setFont( statusFont );
147
painter->drawText( statusArea, 0, statusStr );
148
myProgressBarStyle->rect = barArea;
149
myProgressBarStyle->direction = option.direction;
150
myProgressBarStyle->palette = option.palette;
151
myProgressBarStyle->palette.setCurrentColorGroup( QPalette::Disabled );
152
myProgressBarStyle->state = QStyle::State_Off;
153
myProgressBarStyle->progress = int(myProgressBarStyle->minimum + ((tor.percentDone() * (myProgressBarStyle->maximum - myProgressBarStyle->minimum))));
154
style->drawControl( QStyle::CE_ProgressBar, myProgressBarStyle, painter );