1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-24 09:49:42 +01:00

Make SourceTreePopupDialog more consistent.

This commit is contained in:
Teo Mrnjavac 2012-10-13 20:42:50 +02:00
parent 68b6020bdb
commit f6f42c5f33
2 changed files with 62 additions and 19 deletions

View File

@ -18,6 +18,8 @@
#include "SourceTreePopupDialog.h"
#include "utils/TomahawkUtilsGui.h"
#include <QPaintEvent>
#include <QPainter>
#include <QDialogButtonBox>
@ -47,10 +49,20 @@ SourceTreePopupDialog::SourceTreePopupDialog()
setAutoFillBackground( false );
setAttribute( Qt::WA_TranslucentBackground, true );
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
//setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
m_title = new QLabel( this );
QFont titleFont = m_title->font();
titleFont.setBold( true );
m_title->setStyleSheet( "color: rgb( 99, 113, 128 );" );
titleFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 );
m_title->setFont( titleFont );
m_title->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
m_label = new QLabel( this );
m_buttons = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
//TODO: get some nice icons for this
m_buttons->button( QDialogButtonBox::Ok )->setIcon( QIcon() );
m_buttons->button( QDialogButtonBox::Cancel )->setIcon( QIcon() );
@ -59,10 +71,24 @@ SourceTreePopupDialog::SourceTreePopupDialog()
m_layout = new QVBoxLayout;
setLayout( m_layout );
m_layout->setSpacing( 8 );
layout()->addWidget( m_label );
layout()->addWidget( m_buttons );
setContentsMargins( contentsMargins().left() + 2, contentsMargins().top(), contentsMargins().right(), contentsMargins().bottom() );
m_layout->addWidget( m_title );
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_layout->addWidget( m_separatorLine );
m_layout->addWidget( m_label );
m_layout->addWidget( m_buttons );
setContentsMargins( contentsMargins().left() + 12,
contentsMargins().top() + 8,
contentsMargins().right() + 8,
contentsMargins().bottom() + 8 );
m_title->setVisible( false );
m_separatorLine->setVisible( false );
/*
m_buttons->button( QDialogButtonBox::Ok )->setStyleSheet(
@ -84,6 +110,22 @@ SourceTreePopupDialog::SourceTreePopupDialog()
}" );*/
}
void
SourceTreePopupDialog::setTitle( const QString& text )
{
m_title->setText( text.toUpper() );
if ( m_title->text().isEmpty() )
{
m_title->setVisible( false );
m_separatorLine->setVisible( false );
}
else
{
m_title->setVisible( true );
m_separatorLine->setVisible( true );
}
}
void
SourceTreePopupDialog::setMainText( const QString& text )
@ -128,26 +170,20 @@ void
SourceTreePopupDialog::paintEvent( QPaintEvent* event )
{
// Constants for painting
const int leftTriangleWidth = 20;
const int cornerRounding = 8;
const int leftEdgeOffset = offset() - 6;
const int leftTriangleWidth = 12;
const int cornerRounding = 6;
const int leftEdgeOffset = 2 /*margin*/ + leftTriangleWidth / 2;
const QRect brect = rect().adjusted( 2, 3, -2, -3 );
QPainterPath outline;
// Main rect
outline.addRoundedRect( brect.adjusted( leftTriangleWidth / 2, 0, 0, 0 ), cornerRounding, cornerRounding );
// Left triangle top branch
outline.moveTo( brect.left(), brect.top() + brect.height() / 2 );
outline.lineTo( leftEdgeOffset, brect.top() + brect.height() / 2 - leftTriangleWidth / 2 );
// main outline
outline.lineTo( leftEdgeOffset, cornerRounding );
outline.quadTo( QPoint( leftEdgeOffset, brect.top() ), QPoint( leftEdgeOffset + cornerRounding, brect.top() ) );
outline.lineTo( brect.width() - cornerRounding, brect.top() );
outline.quadTo( QPoint( brect.width(), brect.top() ), QPoint( brect.width(), cornerRounding ) );
outline.lineTo( brect.width(), brect.height() - cornerRounding );
outline.quadTo( brect.bottomRight(), QPoint( brect.right() - cornerRounding, brect.height() ) );
outline.lineTo( leftEdgeOffset + cornerRounding, brect.height() );
outline.quadTo( QPoint( leftEdgeOffset, brect.height() ), QPoint( leftEdgeOffset, brect.height() - cornerRounding ) );
// Left triangle bottom branch
outline.lineTo( leftEdgeOffset, brect.top() + brect.height() / 2 + leftTriangleWidth / 2 );
outline.lineTo( brect.left(), brect.top() + brect.height() / 2 );
@ -156,13 +192,18 @@ SourceTreePopupDialog::paintEvent( QPaintEvent* event )
p.setRenderHint( QPainter::Antialiasing );
QPen pen( QColor( "#3F4247" ) );
QPen pen( QColor( 0x8c, 0x8c, 0x8c ) );
pen.setWidth( 2 );
p.setPen( pen );
p.drawPath( outline );
#ifdef Q_OS_MAC
p.setOpacity( 0.93 );
p.fillPath( outline, QColor( "#D6E3F1" ) );
#else
p.setOpacity( 0.96 );
p.fillPath( outline, QColor( "#FFFFFF" ) );
#endif
#ifdef QT_MAC_USE_COCOA
// Work around bug in Qt/Mac Cocoa where opening subsequent popups

View File

@ -44,6 +44,7 @@ public:
int offset() const { return 16; }
void setTitle( const QString& text );
void setMainText( const QString& text );
void setOkButtonText( const QString& text );
void setExtraQuestions( const Tomahawk::PlaylistDeleteQuestions& questions );
@ -69,11 +70,12 @@ private:
QVBoxLayout* m_layout;
QList< QCheckBox* > m_questionCheckboxes;
QString m_text;
bool m_result;
Tomahawk::PlaylistDeleteQuestions m_questions;
QMap< int, bool > m_questionResults;
QLabel* m_title;
QWidget* m_separatorLine;
QLabel* m_label;
QDialogButtonBox* m_buttons;
};