From cf6d1c32c4430532f4e41305ec5a3a63366c25b6 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 15 Oct 2012 17:27:48 +0200 Subject: [PATCH] Made the SocialWidget look and feel more consistent with other popups. --- data/images/ok.png | Bin 0 -> 511 bytes resources.qrc | 1 + src/AudioControls.cpp | 2 +- src/SocialWidget.cpp | 110 +++++++----------- src/SocialWidget.h | 9 +- .../widgets/SourceTreePopupDialog.cpp | 1 + 6 files changed, 49 insertions(+), 74 deletions(-) create mode 100644 data/images/ok.png diff --git a/data/images/ok.png b/data/images/ok.png new file mode 100644 index 0000000000000000000000000000000000000000..df9deed575310c9a97e8efbc3b82d381a3d6e1d4 GIT binary patch literal 511 zcmV>fM1J%AHvrH z{B{I<2pYP6#OXGGx#zFqYOM#uYM*9 zej1w@{CN}{mNNJTjyJt@7mi_ghrAi})<0+ppTej1Wox*Dy&ZDjWboh8j`!a>E447M z>aDa)Zr5}n?_Lu)JT6>X#gc!=Y9TvcmsYPvI-}fyDsHv&CJSeen!+nxQXi}BfA|ER zX5TlZmAhw}>tJ9DAJx0G&`UV!^?K69L>}jQZ2tc?q=Xdzu=W_ zc7gvAuwoD5T?YgA`wg!&j`#Q>RsBVJf=7D^`2!@5+A8l@{|W#A002ovPDHLkV1koe B+06g| literal 0 HcmV?d00001 diff --git a/resources.qrc b/resources.qrc index 599a9f556..e87df1901 100644 --- a/resources.qrc +++ b/resources.qrc @@ -162,5 +162,6 @@ data/images/account-online.png data/images/cancel.png data/images/delete.png + data/images/ok.png diff --git a/src/AudioControls.cpp b/src/AudioControls.cpp index 0404e8deb..b86207df1 100644 --- a/src/AudioControls.cpp +++ b/src/AudioControls.cpp @@ -653,7 +653,7 @@ void AudioControls::onSocialButtonClicked() { if ( !m_socialWidget.isNull() ) - return; + m_socialWidget.data()->close(); m_socialWidget = new SocialWidget( m_parent ); m_socialWidget.data()->setPosition( m_socialWidget.data()->mapFromGlobal( QCursor::pos() ) ); diff --git a/src/SocialWidget.cpp b/src/SocialWidget.cpp index 734394cba..294e2ec8b 100644 --- a/src/SocialWidget.cpp +++ b/src/SocialWidget.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2012, Christian Muehlhaeuser + * Copyright 2012, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,28 +29,40 @@ #include "utils/Logger.h" #include "Source.h" -#define CORNER_ROUNDNESS 8.0 +#define CORNER_ROUNDNESS 6.0 #define FADING_DURATION 500 -#define OPACITY 0.85 +#define OPACITY 0.96 +#define ARROW_HEIGHT 6 SocialWidget::SocialWidget( QWidget* parent ) : QWidget( parent ) // this is on purpose! , ui( new Ui::SocialWidget ) - , m_opacity( 0.00 ) , m_parent( parent ) , m_parentRect( parent->rect() ) { ui->setupUi( this ); + setWindowFlags( Qt::FramelessWindowHint ); + setWindowFlags( Qt::Popup ); + ui->verticalLayout->setSpacing( 8 ); + ui->verticalLayout->setMargin( 12 ); + setAttribute( Qt::WA_TranslucentBackground, true ); - setOpacity( m_opacity ); + + setContentsMargins( contentsMargins().left() + 2, contentsMargins().top() + 2, + contentsMargins().right() + 2, contentsMargins().bottom() + 2 + ARROW_HEIGHT ); m_timer.setSingleShot( true ); connect( &m_timer, SIGNAL( timeout() ), this, SLOT( hide() ) ); - ui->charsLeftLabel->setForegroundRole( QPalette::BrightText ); + ui->charsLeftLabel->setForegroundRole( QPalette::Text ); + ui->charsLeftLabel->setStyleSheet( "text: black" ); ui->buttonBox->button( QDialogButtonBox::Ok )->setText( tr( "Tweet" ) ); + 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 #000000;" ); m_parent->installEventFilter( this ); @@ -74,25 +87,6 @@ SocialWidget::~SocialWidget() } -void -SocialWidget::setOpacity( qreal opacity ) -{ - m_opacity = opacity; - - if ( m_opacity == 0.00 && !isHidden() ) - { - QWidget::hide(); - emit hidden(); - } - else if ( m_opacity > 0.00 && isHidden() ) - { - QWidget::show(); - } - - repaint(); -} - - void SocialWidget::setPosition( QPoint position ) { @@ -107,13 +101,10 @@ SocialWidget::show( int timeoutSecs ) if ( !isEnabled() ) return; - QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" ); - animation->setDuration( FADING_DURATION ); - animation->setEndValue( 1.0 ); - animation->start(); - if( timeoutSecs > 0 ) m_timer.start( timeoutSecs * 1000 ); + + QWidget::show(); } @@ -123,10 +114,7 @@ SocialWidget::hide() if ( !isEnabled() ) return; - QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" ); - animation->setDuration( FADING_DURATION ); - animation->setEndValue( 0.00 ); - animation->start(); + QWidget::hide(); } @@ -136,7 +124,7 @@ SocialWidget::shown() const if ( !isEnabled() ) return false; - return m_opacity == OPACITY; + return isVisible(); } @@ -145,47 +133,28 @@ SocialWidget::paintEvent( QPaintEvent* event ) { Q_UNUSED( event ); - QPainter p( this ); + QPainterPath outline; + QRect r = contentsRect(); + outline.addRoundedRect( r, CORNER_ROUNDNESS, CORNER_ROUNDNESS ); + 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 ); - p.setBackgroundMode( Qt::TransparentMode ); + QPainter p( this ); p.setRenderHint( QPainter::Antialiasing ); - p.setOpacity( m_opacity ); + p.setBackgroundMode( Qt::TransparentMode ); - QPen pen( palette().dark().color(), .5 ); + QPen pen( QColor( 0x8c, 0x8c, 0x8c ) ); + pen.setWidth( 2 ); p.setPen( pen ); - p.setBrush( QColor( 30, 30, 30, 255.0 * OPACITY ) ); + p.drawPath( outline ); - p.drawRoundedRect( r, CORNER_ROUNDNESS, CORNER_ROUNDNESS ); + p.setOpacity( OPACITY ); + p.fillPath( outline, QColor( "#FFFFFF" ) ); QWidget::paintEvent( event ); return; - - QTextOption to( Qt::AlignCenter ); - to.setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere ); - - QFont f( font() ); - f.setPointSize( TomahawkUtils::defaultFontSize() + 7 ); - f.setBold( true ); - - QRectF textRect = r.adjusted( 8, 8, -8, -8 ); - qreal availHeight = textRect.height(); - - QFontMetricsF fm( f ); - qreal textHeight = fm.boundingRect( textRect, Qt::AlignCenter | Qt::TextWordWrap, "SocialWidget" ).height(); - while( textHeight > availHeight ) - { - if( f.pointSize() <= 4 ) // don't try harder - break; - - f.setPointSize( f.pointSize() - 1 ); - fm = QFontMetricsF( f ); - textHeight = fm.boundingRect( textRect, Qt::AlignCenter | Qt::TextWordWrap, "SocialWidget" ).height(); - } - - p.setFont( f ); - p.setPen( palette().highlightedText().color() ); - p.drawText( r.adjusted( 8, 8, -8, -8 ), "SocialWidget", to ); } @@ -272,7 +241,8 @@ SocialWidget::onGeometryUpdate() m_position += p; m_parentRect = m_parent->rect(); - QPoint position( m_position - QPoint( size().width(), size().height() ) ); + QPoint position( m_position - QPoint( size().width(), size().height() ) + + QPoint( ARROW_HEIGHT * 3, -ARROW_HEIGHT/2 ) ); if ( position != pos() ) { move( position ); @@ -290,3 +260,9 @@ SocialWidget::eventFilter( QObject* object, QEvent* event ) return QObject::eventFilter( object, event ); } + +void +SocialWidget::focusOutEvent( QFocusEvent* ) +{ + close(); +} diff --git a/src/SocialWidget.h b/src/SocialWidget.h index ec4230d5b..17f2d6488 100644 --- a/src/SocialWidget.h +++ b/src/SocialWidget.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2012, Christian Muehlhaeuser + * Copyright 2012, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,7 +34,6 @@ namespace Ui class SocialWidget : public QWidget { Q_OBJECT -Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) public: SocialWidget( QWidget* parent ); @@ -42,13 +42,11 @@ public: Tomahawk::query_ptr query() const { return m_query; } void setQuery( const Tomahawk::query_ptr& query ); - qreal opacity() const { return m_opacity; } - void setOpacity( qreal opacity ); - QPoint position() const { return m_position; } void setPosition( QPoint position ); bool shown() const; + void close(); signals: void hidden(); @@ -61,6 +59,7 @@ protected: // void changeEvent( QEvent* e ); void paintEvent( QPaintEvent* event ); bool eventFilter( QObject* object, QEvent* event ); + void focusOutEvent( QFocusEvent* ); private slots: void accept(); @@ -68,7 +67,6 @@ private slots: void onShortLinkReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj ); void onGeometryUpdate(); - void close(); private: unsigned int charsAvailable() const; @@ -77,7 +75,6 @@ private: Tomahawk::query_ptr m_query; - qreal m_opacity; QPoint m_position; QWidget* m_parent; diff --git a/src/libtomahawk/widgets/SourceTreePopupDialog.cpp b/src/libtomahawk/widgets/SourceTreePopupDialog.cpp index 81224190b..10ea1e10d 100644 --- a/src/libtomahawk/widgets/SourceTreePopupDialog.cpp +++ b/src/libtomahawk/widgets/SourceTreePopupDialog.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2012 Leo Franchi + * Copyright 2012 Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by