1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-16 19:14:06 +02:00

Made the SocialWidget look and feel more consistent with other popups.

This commit is contained in:
Teo Mrnjavac
2012-10-15 17:27:48 +02:00
parent d547dfd336
commit cf6d1c32c4
6 changed files with 49 additions and 74 deletions

BIN
data/images/ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

View File

@@ -162,5 +162,6 @@
<file>data/images/account-online.png</file>
<file>data/images/cancel.png</file>
<file>data/images/delete.png</file>
<file>data/images/ok.png</file>
</qresource>
</RCC>

View File

@@ -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() ) );

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* 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();
}

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2012, Teo Mrnjavac <teo@kde.org>
*
* 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;

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2012 Leo Franchi <lfranchi@kde.org>
* Copyright 2012 Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by