mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-18 20:04:00 +02:00
Made the SocialWidget look and feel more consistent with other popups.
This commit is contained in:
BIN
data/images/ok.png
Normal file
BIN
data/images/ok.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 511 B |
@@ -162,5 +162,6 @@
|
|||||||
<file>data/images/account-online.png</file>
|
<file>data/images/account-online.png</file>
|
||||||
<file>data/images/cancel.png</file>
|
<file>data/images/cancel.png</file>
|
||||||
<file>data/images/delete.png</file>
|
<file>data/images/delete.png</file>
|
||||||
|
<file>data/images/ok.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
@@ -653,7 +653,7 @@ void
|
|||||||
AudioControls::onSocialButtonClicked()
|
AudioControls::onSocialButtonClicked()
|
||||||
{
|
{
|
||||||
if ( !m_socialWidget.isNull() )
|
if ( !m_socialWidget.isNull() )
|
||||||
return;
|
m_socialWidget.data()->close();
|
||||||
|
|
||||||
m_socialWidget = new SocialWidget( m_parent );
|
m_socialWidget = new SocialWidget( m_parent );
|
||||||
m_socialWidget.data()->setPosition( m_socialWidget.data()->mapFromGlobal( QCursor::pos() ) );
|
m_socialWidget.data()->setPosition( m_socialWidget.data()->mapFromGlobal( QCursor::pos() ) );
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2012, Christian Muehlhaeuser <muesli@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
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -28,28 +29,40 @@
|
|||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
|
|
||||||
#define CORNER_ROUNDNESS 8.0
|
#define CORNER_ROUNDNESS 6.0
|
||||||
#define FADING_DURATION 500
|
#define FADING_DURATION 500
|
||||||
#define OPACITY 0.85
|
#define OPACITY 0.96
|
||||||
|
#define ARROW_HEIGHT 6
|
||||||
|
|
||||||
|
|
||||||
SocialWidget::SocialWidget( QWidget* parent )
|
SocialWidget::SocialWidget( QWidget* parent )
|
||||||
: QWidget( parent ) // this is on purpose!
|
: QWidget( parent ) // this is on purpose!
|
||||||
, ui( new Ui::SocialWidget )
|
, ui( new Ui::SocialWidget )
|
||||||
, m_opacity( 0.00 )
|
|
||||||
, m_parent( parent )
|
, m_parent( parent )
|
||||||
, m_parentRect( parent->rect() )
|
, m_parentRect( parent->rect() )
|
||||||
{
|
{
|
||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
|
setWindowFlags( Qt::FramelessWindowHint );
|
||||||
|
setWindowFlags( Qt::Popup );
|
||||||
|
ui->verticalLayout->setSpacing( 8 );
|
||||||
|
ui->verticalLayout->setMargin( 12 );
|
||||||
|
|
||||||
|
|
||||||
setAttribute( Qt::WA_TranslucentBackground, true );
|
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 );
|
m_timer.setSingleShot( true );
|
||||||
connect( &m_timer, SIGNAL( timeout() ), this, SLOT( hide() ) );
|
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 )->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 );
|
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
|
void
|
||||||
SocialWidget::setPosition( QPoint position )
|
SocialWidget::setPosition( QPoint position )
|
||||||
{
|
{
|
||||||
@@ -107,13 +101,10 @@ SocialWidget::show( int timeoutSecs )
|
|||||||
if ( !isEnabled() )
|
if ( !isEnabled() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" );
|
|
||||||
animation->setDuration( FADING_DURATION );
|
|
||||||
animation->setEndValue( 1.0 );
|
|
||||||
animation->start();
|
|
||||||
|
|
||||||
if( timeoutSecs > 0 )
|
if( timeoutSecs > 0 )
|
||||||
m_timer.start( timeoutSecs * 1000 );
|
m_timer.start( timeoutSecs * 1000 );
|
||||||
|
|
||||||
|
QWidget::show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -123,10 +114,7 @@ SocialWidget::hide()
|
|||||||
if ( !isEnabled() )
|
if ( !isEnabled() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPropertyAnimation* animation = new QPropertyAnimation( this, "opacity" );
|
QWidget::hide();
|
||||||
animation->setDuration( FADING_DURATION );
|
|
||||||
animation->setEndValue( 0.00 );
|
|
||||||
animation->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -136,7 +124,7 @@ SocialWidget::shown() const
|
|||||||
if ( !isEnabled() )
|
if ( !isEnabled() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return m_opacity == OPACITY;
|
return isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -145,47 +133,28 @@ SocialWidget::paintEvent( QPaintEvent* event )
|
|||||||
{
|
{
|
||||||
Q_UNUSED( event );
|
Q_UNUSED( event );
|
||||||
|
|
||||||
QPainter p( this );
|
QPainterPath outline;
|
||||||
|
|
||||||
QRect r = contentsRect();
|
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.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.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 );
|
QWidget::paintEvent( event );
|
||||||
return;
|
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_position += p;
|
||||||
m_parentRect = m_parent->rect();
|
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() )
|
if ( position != pos() )
|
||||||
{
|
{
|
||||||
move( position );
|
move( position );
|
||||||
@@ -290,3 +260,9 @@ SocialWidget::eventFilter( QObject* object, QEvent* event )
|
|||||||
|
|
||||||
return QObject::eventFilter( object, event );
|
return QObject::eventFilter( object, event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SocialWidget::focusOutEvent( QFocusEvent* )
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2012, Christian Muehlhaeuser <muesli@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
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -33,7 +34,6 @@ namespace Ui
|
|||||||
class SocialWidget : public QWidget
|
class SocialWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SocialWidget( QWidget* parent );
|
SocialWidget( QWidget* parent );
|
||||||
@@ -42,13 +42,11 @@ public:
|
|||||||
Tomahawk::query_ptr query() const { return m_query; }
|
Tomahawk::query_ptr query() const { return m_query; }
|
||||||
void setQuery( const Tomahawk::query_ptr& query );
|
void setQuery( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
qreal opacity() const { return m_opacity; }
|
|
||||||
void setOpacity( qreal opacity );
|
|
||||||
|
|
||||||
QPoint position() const { return m_position; }
|
QPoint position() const { return m_position; }
|
||||||
void setPosition( QPoint position );
|
void setPosition( QPoint position );
|
||||||
|
|
||||||
bool shown() const;
|
bool shown() const;
|
||||||
|
void close();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void hidden();
|
void hidden();
|
||||||
@@ -61,6 +59,7 @@ protected:
|
|||||||
// void changeEvent( QEvent* e );
|
// void changeEvent( QEvent* e );
|
||||||
void paintEvent( QPaintEvent* event );
|
void paintEvent( QPaintEvent* event );
|
||||||
bool eventFilter( QObject* object, QEvent* event );
|
bool eventFilter( QObject* object, QEvent* event );
|
||||||
|
void focusOutEvent( QFocusEvent* );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void accept();
|
void accept();
|
||||||
@@ -68,7 +67,6 @@ private slots:
|
|||||||
void onShortLinkReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj );
|
void onShortLinkReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj );
|
||||||
|
|
||||||
void onGeometryUpdate();
|
void onGeometryUpdate();
|
||||||
void close();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int charsAvailable() const;
|
unsigned int charsAvailable() const;
|
||||||
@@ -77,7 +75,6 @@ private:
|
|||||||
|
|
||||||
Tomahawk::query_ptr m_query;
|
Tomahawk::query_ptr m_query;
|
||||||
|
|
||||||
qreal m_opacity;
|
|
||||||
QPoint m_position;
|
QPoint m_position;
|
||||||
|
|
||||||
QWidget* m_parent;
|
QWidget* m_parent;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2012 Leo Franchi <lfranchi@kde.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
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
Reference in New Issue
Block a user