1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 13:47:26 +02:00

* Properly calculate ACLJobDelegate's sizeHint, taking current font settings into account.

This commit is contained in:
Christian Muehlhaeuser
2012-12-23 20:28:07 +01:00
parent c0e4b76c8c
commit 491060d5bc
2 changed files with 12 additions and 16 deletions

View File

@@ -19,20 +19,17 @@
#include "AclJobItem.h" #include "AclJobItem.h"
#include "JobStatusModel.h"
#include "utils/TomahawkUtils.h"
#include "utils/TomahawkUtilsGui.h"
#include "infosystem/InfoSystem.h"
#include "utils/Logger.h"
#include <QPixmap> #include <QPixmap>
#include <QPainter> #include <QPainter>
#include <QListView> #include <QListView>
#include <QApplication> #include <QApplication>
#include <QMouseEvent> #include <QMouseEvent>
#include "JobStatusModel.h"
#include "infosystem/InfoSystem.h"
#include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h"
#define ROW_HEIGHT 20
#define ICON_PADDING 1 #define ICON_PADDING 1
#define PADDING 2 #define PADDING 2
@@ -65,7 +62,6 @@ ACLJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget ); QApplication::style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget );
painter->setRenderHint( QPainter::Antialiasing ); painter->setRenderHint( QPainter::Antialiasing );
painter->fillRect( opt.rect, Qt::lightGray ); painter->fillRect( opt.rect, Qt::lightGray );
QString mainText = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() ); QString mainText = QString( tr( "Allow %1 to\nconnect and stream from you?" ) ).arg( item->username() );
@@ -85,11 +81,11 @@ ACLJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
int minPixels = 20; int minPixels = 20;
QString allowBtnText = tr( "Allow Streaming" ); QString allowBtnText = tr( "Allow Streaming" );
int allowBtnWidth = fm.width( allowBtnText ) + 2*PADDING; int allowBtnWidth = fm.width( allowBtnText ) + 2 * PADDING;
allowBtnRect = QRect( opt.rect.left() + thirds - allowBtnWidth/2, opt.rect.bottom() - fm.height() - 4*PADDING, allowBtnWidth + 2*PADDING, fm.height() + 2*PADDING ); allowBtnRect = QRect( opt.rect.left() + thirds - allowBtnWidth / 2, opt.rect.bottom() - fm.height() - 4 * PADDING, allowBtnWidth + 2 * PADDING, fm.height() + 2 * PADDING );
QString denyBtnText = tr( "Deny Access" ); QString denyBtnText = tr( "Deny Access" );
int denyBtnWidth = fm.width( denyBtnText ) + 2*PADDING; int denyBtnWidth = fm.width( denyBtnText ) + 2 * PADDING;
denyBtnRect = QRect( opt.rect.right() - thirds - denyBtnWidth/2, opt.rect.bottom() - fm.height() - 4*PADDING, denyBtnWidth + 2*PADDING, fm.height() + 2*PADDING ); denyBtnRect = QRect( opt.rect.right() - thirds - denyBtnWidth / 2, opt.rect.bottom() - fm.height() - 4 * PADDING, denyBtnWidth + 2 * PADDING, fm.height() + 2 * PADDING );
if ( allowBtnRect.right() >= denyBtnRect.left() ) if ( allowBtnRect.right() >= denyBtnRect.left() )
{ {
@@ -105,10 +101,11 @@ ACLJobDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
m_savedDenyRect = denyBtnRect; m_savedDenyRect = denyBtnRect;
} }
QSize QSize
ACLJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const ACLJobDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{ {
QSize size( QStyledItemDelegate::sizeHint ( option, index ).width(), ROW_HEIGHT * 3 ); QSize size( QStyledItemDelegate::sizeHint( option, index ).width(), ( TomahawkUtils::defaultFontHeight() + 6 ) * 3.5 );
return size; return size;
} }
@@ -117,9 +114,9 @@ void
ACLJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const ACLJobDelegate::drawRoundedButton( QPainter* painter, const QRect& btnRect, bool red ) const
{ {
if ( !red ) if ( !red )
TomahawkUtils::drawRoundedButton( painter, btnRect, QColor(54, 127, 211), QColor(43, 104, 182), QColor(34, 85, 159), QColor(35, 79, 147) ); TomahawkUtils::drawRoundedButton( painter, btnRect, QColor( 54, 127, 211 ), QColor( 43, 104, 182 ), QColor( 34, 85, 159 ), QColor( 35, 79, 147 ) );
else else
TomahawkUtils::drawRoundedButton( painter, btnRect, QColor(206, 63, 63), QColor(170, 52, 52), QColor(150, 50, 50), QColor(130, 40, 40) ); TomahawkUtils::drawRoundedButton( painter, btnRect, QColor( 206, 63, 63 ), QColor( 170, 52, 52 ), QColor( 150, 50, 50 ), QColor( 130, 40, 40 ) );
} }

View File

@@ -88,7 +88,6 @@ JobStatusSortModel::lessThan( const QModelIndex& left, const QModelIndex& right
if ( leftSort == rightSort ) if ( leftSort == rightSort )
return left.data( JobStatusModel::AgeRole ).toUInt() > right.data( JobStatusModel::AgeRole ).toUInt(); return left.data( JobStatusModel::AgeRole ).toUInt() > right.data( JobStatusModel::AgeRole ).toUInt();
return leftSort < rightSort; return leftSort < rightSort;
} }