From 5533019a65ba36cb1d68c7660c552244ab84a004 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sat, 20 Oct 2012 23:28:13 +0200 Subject: [PATCH] Moved some colors and constants for popup widgets to TomahawkUtilsGui. There are probably better ways to do this. Suggestions are welcome. This aims to make it easier to keep the popup dialogs consistent even though the code gets a little more verbose. --- src/SocialWidget.cpp | 12 +++++------- src/libtomahawk/utils/ProxyStyle.cpp | 3 ++- src/libtomahawk/utils/TomahawkUtilsGui.h | 10 ++++++++++ src/libtomahawk/widgets/SourceTreePopupDialog.cpp | 13 +++++++------ src/sourcetree/SourceDelegate.cpp | 8 ++++---- src/widgets/AccountListWidget.cpp | 5 +++-- src/widgets/AccountWidget.cpp | 2 +- src/widgets/AccountsPopupWidget.cpp | 10 ++++++---- src/widgets/AccountsToolButton.cpp | 3 ++- 9 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/SocialWidget.cpp b/src/SocialWidget.cpp index e334c5a3a..39f73f938 100644 --- a/src/SocialWidget.cpp +++ b/src/SocialWidget.cpp @@ -29,8 +29,6 @@ #include "utils/Logger.h" #include "Source.h" -#define CORNER_ROUNDNESS 6.0 -#define OPACITY 0.96 #define ARROW_HEIGHT 6 @@ -68,7 +66,7 @@ SocialWidget::SocialWidget( QWidget* parent ) ui->buttonBox->button( QDialogButtonBox::Ok )->setIcon( QIcon( RESPATH "images/ok.png" ) ); ui->buttonBox->button( QDialogButtonBox::Cancel )->setIcon( QIcon( RESPATH "images/cancel.png" ) ); - ui->textEdit->setStyleSheet( "border: 1px solid #8c8c8c;" ); + ui->textEdit->setStyleSheet( "border: 1px solid " + TomahawkUtils::Colors::BORDER_LINE.name() ); m_parent->installEventFilter( this ); @@ -142,7 +140,7 @@ SocialWidget::paintEvent( QPaintEvent* event ) QPainterPath outline; QRect r = contentsRect(); - outline.addRoundedRect( r, CORNER_ROUNDNESS, CORNER_ROUNDNESS ); + outline.addRoundedRect( r, TomahawkUtils::POPUP_ROUNDING_RADIUS, TomahawkUtils::POPUP_ROUNDING_RADIUS ); outline.moveTo( r.right() - ARROW_HEIGHT * 2, r.bottom()+1 ); outline.lineTo( r.right() - ARROW_HEIGHT * 3, r.bottom()+1 + ARROW_HEIGHT ); outline.lineTo( r.right() - ARROW_HEIGHT * 4, r.bottom()+1 ); @@ -151,13 +149,13 @@ SocialWidget::paintEvent( QPaintEvent* event ) p.setRenderHint( QPainter::Antialiasing ); p.setBackgroundMode( Qt::TransparentMode ); - QPen pen( QColor( 0x8c, 0x8c, 0x8c ) ); + QPen pen( TomahawkUtils::Colors::BORDER_LINE ); pen.setWidth( 2 ); p.setPen( pen ); p.drawPath( outline ); - p.setOpacity( OPACITY ); - p.fillPath( outline, QColor( "#FFFFFF" ) ); + p.setOpacity( TomahawkUtils::POPUP_OPACITY ); + p.fillPath( outline, TomahawkUtils::Colors::POPUP_BACKGROUND ); QWidget::paintEvent( event ); return; diff --git a/src/libtomahawk/utils/ProxyStyle.cpp b/src/libtomahawk/utils/ProxyStyle.cpp index bb96bd5ae..5180a2f67 100644 --- a/src/libtomahawk/utils/ProxyStyle.cpp +++ b/src/libtomahawk/utils/ProxyStyle.cpp @@ -25,6 +25,7 @@ #include #include "utils/Logger.h" +#include "utils/TomahawkUtilsGui.h" #define ARROW_WIDTH 7 #define ARROW_HEIGHT 7 @@ -88,7 +89,7 @@ ProxyStyle::drawControl( ControlElement ce, const QStyleOption* opt, QPainter* p const QSplitter* splitter = qobject_cast< const QSplitter* >( w ); if ( !splitter->sizes().contains( 0 ) ) { - p->setPen( QColor( 0x8c, 0x8c, 0x8c ) ); + p->setPen( TomahawkUtils::Colors::BORDER_LINE ); // We must special-case this because of the AnimatedSplitterHandle which has a // SizeHint of 0,0. if( splitter->orientation() == Qt::Vertical ) diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.h b/src/libtomahawk/utils/TomahawkUtilsGui.h index 4d69538b0..205ff867a 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.h +++ b/src/libtomahawk/utils/TomahawkUtilsGui.h @@ -73,6 +73,16 @@ namespace TomahawkUtils DLLEXPORT QPixmap createTiledPixmap( int width, int height, const QImage& src ); DLLEXPORT QPixmap addDropShadow( const QPixmap& sourceImage, const QSize& targetSize ); + + namespace Colors + { + static const QColor BORDER_LINE = QColor( "#8c8c8c" ); + static const QColor POPUP_BACKGROUND = QColor( "#ffffff" ); + static const QColor GROUP_HEADER = QColor( "#637180" ); + } + + static const int POPUP_ROUNDING_RADIUS = 6; + static const float POPUP_OPACITY = 0.96; } #endif // TOMAHAWKUTILSGUI_H diff --git a/src/libtomahawk/widgets/SourceTreePopupDialog.cpp b/src/libtomahawk/widgets/SourceTreePopupDialog.cpp index 10ea1e10d..e83908585 100644 --- a/src/libtomahawk/widgets/SourceTreePopupDialog.cpp +++ b/src/libtomahawk/widgets/SourceTreePopupDialog.cpp @@ -56,7 +56,7 @@ SourceTreePopupDialog::SourceTreePopupDialog() m_title = new QLabel( this ); QFont titleFont = m_title->font(); titleFont.setBold( true ); - m_title->setStyleSheet( "color: rgb( 99, 113, 128 );" ); + m_title->setStyleSheet( "color: " + TomahawkUtils::Colors::GROUP_HEADER.name() ); titleFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 ); m_title->setFont( titleFont ); m_title->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); @@ -81,7 +81,8 @@ SourceTreePopupDialog::SourceTreePopupDialog() m_separatorLine = new QWidget( this ); m_separatorLine->setFixedHeight( 1 ); m_separatorLine->setContentsMargins( 0, 0, 0, 0 ); - m_separatorLine->setStyleSheet( "QWidget { border-top: 1px solid black; }" ); + m_separatorLine->setStyleSheet( "QWidget { border-top: 1px solid " + + TomahawkUtils::Colors::BORDER_LINE.name() + "; }" ); m_layout->addWidget( m_separatorLine ); m_layout->addWidget( m_label ); m_layout->addWidget( m_buttons ); @@ -174,7 +175,7 @@ SourceTreePopupDialog::paintEvent( QPaintEvent* event ) { // Constants for painting const int leftTriangleWidth = 12; - const int cornerRounding = 6; + const int cornerRounding = TomahawkUtils::POPUP_ROUNDING_RADIUS; const int leftEdgeOffset = 2 /*margin*/ + leftTriangleWidth / 2; const QRect brect = rect().adjusted( 2, 3, -2, -3 ); @@ -195,7 +196,7 @@ SourceTreePopupDialog::paintEvent( QPaintEvent* event ) p.setRenderHint( QPainter::Antialiasing ); - QPen pen( QColor( 0x8c, 0x8c, 0x8c ) ); + QPen pen( TomahawkUtils::Colors::BORDER_LINE ); pen.setWidth( 2 ); p.setPen( pen ); p.drawPath( outline ); @@ -204,8 +205,8 @@ SourceTreePopupDialog::paintEvent( QPaintEvent* event ) p.setOpacity( 0.93 ); p.fillPath( outline, QColor( "#D6E3F1" ) ); #else - p.setOpacity( 0.96 ); - p.fillPath( outline, QColor( "#FFFFFF" ) ); + p.setOpacity( TomahawkUtils::POPUP_OPACITY ); + p.fillPath( outline, TomahawkUtils::Colors::POPUP_BACKGROUND ); #endif #ifdef QT_MAC_USE_COCOA diff --git a/src/sourcetree/SourceDelegate.cpp b/src/sourcetree/SourceDelegate.cpp index 60dbcde01..198f65de1 100644 --- a/src/sourcetree/SourceDelegate.cpp +++ b/src/sourcetree/SourceDelegate.cpp @@ -294,7 +294,7 @@ SourceDelegate::paintCategory( QPainter* painter, const QStyleOptionViewItem& op painter->setPen( Qt::white ); painter->drawText( option.rect.translated( 4, 1 ), index.data().toString().toUpper(), to ); - painter->setPen( QColor( 99, 113, 128 ) ); + painter->setPen( TomahawkUtils::Colors::GROUP_HEADER ); painter->drawText( option.rect.translated( 4, 0 ), index.data().toString().toUpper(), to ); if ( option.state & QStyle::State_MouseOver ) @@ -311,7 +311,7 @@ SourceDelegate::paintCategory( QPainter* painter, const QStyleOptionViewItem& op // draw close icon painter->setPen( Qt::white ); painter->drawText( option.rect.translated( -4, 1 ), text, to ); - painter->setPen( QColor( 99, 113, 128 ) ); + painter->setPen( TomahawkUtils::Colors::GROUP_HEADER ); painter->drawText( option.rect.translated( -4, 0 ), text, to ); } @@ -338,7 +338,7 @@ SourceDelegate::paintGroup( QPainter* painter, const QStyleOptionViewItem& optio painter->setPen( Qt::white ); painter->drawText( option.rect.translated( 4, 1 ), index.data().toString().toUpper(), to ); - painter->setPen( QColor( 99, 113, 128 ) ); + painter->setPen( TomahawkUtils::Colors::GROUP_HEADER ); painter->drawText( option.rect.translated( 4, 0 ), index.data().toString().toUpper(), to ); if ( option.state & QStyle::State_MouseOver ) @@ -353,7 +353,7 @@ SourceDelegate::paintGroup( QPainter* painter, const QStyleOptionViewItem& optio // draw close icon painter->setPen( Qt::white ); painter->drawText( option.rect.translated( -4, 1 ), text, to ); - painter->setPen( QColor( 99, 113, 128 ) ); + painter->setPen( TomahawkUtils::Colors::GROUP_HEADER ); painter->drawText( option.rect.translated( -4, 0 ), text, to ); } diff --git a/src/widgets/AccountListWidget.cpp b/src/widgets/AccountListWidget.cpp index 7ef09a106..811a8ad02 100644 --- a/src/widgets/AccountListWidget.cpp +++ b/src/widgets/AccountListWidget.cpp @@ -52,14 +52,15 @@ AccountListWidget::AccountListWidget( AccountModelFactoryProxy* model, QWidget* QWidget* separatorLine = new QWidget( this ); separatorLine->setFixedHeight( 1 ); separatorLine->setContentsMargins( 0, 0, 0, 0 ); - separatorLine->setStyleSheet( "QWidget { border-top: 1px solid rgb( 140, 140, 140 ); }" ); //from ProxyStyle + separatorLine->setStyleSheet( "QWidget { border-top: 1px solid " + + TomahawkUtils::Colors::BORDER_LINE.name() + "; }" ); //from ProxyStyle mainLayout->insertWidget( 0, separatorLine ); mainLayout->addSpacing( 6 ); QLabel *connectionsLabel = new QLabel( tr( "Connections" ).toUpper(), this ); QFont clFont = connectionsLabel->font(); clFont.setBold( true ); - connectionsLabel->setStyleSheet( "color: rgb( 99, 113, 128 );" ); + connectionsLabel->setStyleSheet( "color: " + TomahawkUtils::Colors::GROUP_HEADER.name() ); clFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 ); connectionsLabel->setFont( clFont ); connectionsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); diff --git a/src/widgets/AccountWidget.cpp b/src/widgets/AccountWidget.cpp index e3e2b3df1..bab5b98bc 100644 --- a/src/widgets/AccountWidget.cpp +++ b/src/widgets/AccountWidget.cpp @@ -97,7 +97,7 @@ AccountWidget::AccountWidget( QWidget* parent ) m_inviteContainer = new UnstyledFrame( this ); vLayout->addWidget( m_inviteContainer, 1, 0 ); - m_inviteContainer->setFrameColor( QColor( 0x8c, 0x8c, 0x8c ) ); //from ProxyStyle + m_inviteContainer->setFrameColor( TomahawkUtils::Colors::BORDER_LINE ); m_inviteContainer->setMinimumWidth( m_inviteContainer->logicalDpiX() * 2 ); m_inviteContainer->setContentsMargins( 1, 1, 1, 2 ); m_inviteContainer->setAttribute( Qt::WA_TranslucentBackground, false ); diff --git a/src/widgets/AccountsPopupWidget.cpp b/src/widgets/AccountsPopupWidget.cpp index c3b7e1200..43a68b2e0 100644 --- a/src/widgets/AccountsPopupWidget.cpp +++ b/src/widgets/AccountsPopupWidget.cpp @@ -19,6 +19,8 @@ #include "AccountsPopupWidget.h" +#include "utils/TomahawkUtilsGui.h" + #include #include #include @@ -88,7 +90,7 @@ AccountsPopupWidget::setArrowOffset( int arrowOffset ) void AccountsPopupWidget::paintEvent( QPaintEvent* ) { // Constants for painting - const int cornerRadius = 6; //the rounding radius of the widget + const int cornerRadius = TomahawkUtils::POPUP_ROUNDING_RADIUS; //the rounding radius of the widget const int arrowHeight = 6; //m_arrowOffset is the distance between the far right boundary and the x value of the arrow head. @@ -110,13 +112,13 @@ void AccountsPopupWidget::paintEvent( QPaintEvent* ) p.setRenderHint( QPainter::Antialiasing ); p.setBackgroundMode( Qt::TransparentMode ); - QPen pen( QColor( 0x8c, 0x8c, 0x8c ) ); + QPen pen( TomahawkUtils::Colors::BORDER_LINE ); pen.setWidth( 2 ); p.setPen( pen ); p.drawPath( outline ); - p.setOpacity( 0.96 ); - p.fillPath( outline, QColor( "#FFFFFF" ) ); + p.setOpacity( TomahawkUtils::POPUP_OPACITY ); + p.fillPath( outline, TomahawkUtils::Colors::POPUP_BACKGROUND ); #ifdef QT_MAC_USE_COCOA // Work around bug in Qt/Mac Cocoa where opening subsequent popups diff --git a/src/widgets/AccountsToolButton.cpp b/src/widgets/AccountsToolButton.cpp index c43a04301..93cb28954 100644 --- a/src/widgets/AccountsToolButton.cpp +++ b/src/widgets/AccountsToolButton.cpp @@ -77,7 +77,8 @@ AccountsToolButton::AccountsToolButton( QWidget* parent ) QWidget *separatorLine = new QWidget( w ); separatorLine->setFixedHeight( 1 ); separatorLine->setContentsMargins( 0, 0, 0, 0 ); - separatorLine->setStyleSheet( "QWidget { border-top: 1px solid rgb( 140, 140, 140 ); }" ); //from ProxyStyle + separatorLine->setStyleSheet( "QWidget { border-top: 1px solid " + + TomahawkUtils::Colors::BORDER_LINE.name() + "; }" ); //from ProxyStyle wMainLayout->addWidget( separatorLine ); wMainLayout->addSpacing( 6 );