mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Finally, really fix the black borders on popup Windows issue.
For now only on AccountsPopupWidget. Thanks Patrick von Reth for the solution.
This commit is contained in:
@@ -29,14 +29,22 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
#include <QtGui/QX11Info>
|
||||||
|
#include <QBitmap>
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
#include <QBitmap>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, m_widget( 0 )
|
, m_widget( 0 )
|
||||||
, m_arrowOffset( 0 )
|
, m_arrowOffset( 0 )
|
||||||
{
|
{
|
||||||
setWindowFlags( Qt::FramelessWindowHint );
|
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
|
||||||
setWindowFlags( Qt::Popup );
|
|
||||||
//Uncomment this if using a debugger:
|
//Uncomment this if using a debugger:
|
||||||
//setWindowFlags( Qt::Window );
|
//setWindowFlags( Qt::Window );
|
||||||
|
|
||||||
@@ -44,7 +52,6 @@ AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
|||||||
setAttribute( Qt::WA_TranslucentBackground, true );
|
setAttribute( Qt::WA_TranslucentBackground, true );
|
||||||
setAttribute( Qt::WA_NoSystemBackground, true );
|
setAttribute( Qt::WA_NoSystemBackground, true );
|
||||||
|
|
||||||
|
|
||||||
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
||||||
|
|
||||||
m_layout = new QVBoxLayout( this );
|
m_layout = new QVBoxLayout( this );
|
||||||
@@ -59,6 +66,7 @@ AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountsPopupWidget::setWidget( QWidget* widget )
|
AccountsPopupWidget::setWidget( QWidget* widget )
|
||||||
{
|
{
|
||||||
@@ -67,6 +75,7 @@ AccountsPopupWidget::setWidget( QWidget* widget )
|
|||||||
m_widget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
m_widget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountsPopupWidget::anchorAt( const QPoint &p )
|
AccountsPopupWidget::anchorAt( const QPoint &p )
|
||||||
{
|
{
|
||||||
@@ -77,6 +86,7 @@ AccountsPopupWidget::anchorAt( const QPoint &p )
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountsPopupWidget::setArrowOffset( int arrowOffset )
|
AccountsPopupWidget::setArrowOffset( int arrowOffset )
|
||||||
{
|
{
|
||||||
@@ -89,7 +99,9 @@ AccountsPopupWidget::setArrowOffset( int arrowOffset )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountsPopupWidget::paintEvent( QPaintEvent* )
|
|
||||||
|
void
|
||||||
|
AccountsPopupWidget::paintEvent( QPaintEvent* )
|
||||||
{
|
{
|
||||||
// Constants for painting
|
// Constants for painting
|
||||||
const int cornerRadius = TomahawkUtils::POPUP_ROUNDING_RADIUS; //the rounding radius of the widget
|
const int cornerRadius = TomahawkUtils::POPUP_ROUNDING_RADIUS; //the rounding radius of the widget
|
||||||
@@ -109,10 +121,30 @@ void AccountsPopupWidget::paintEvent( QPaintEvent* )
|
|||||||
outline.lineTo( rect().right() - m_arrowOffset, 2 );
|
outline.lineTo( rect().right() - m_arrowOffset, 2 );
|
||||||
outline.lineTo( rect().right() - m_arrowOffset - arrowHeight, brect.top() );
|
outline.lineTo( rect().right() - m_arrowOffset - arrowHeight, brect.top() );
|
||||||
|
|
||||||
QPainter p( this );
|
bool compositingWorks = true;
|
||||||
|
#if defined(Q_WS_WIN) //HACK: Windows refuses to perform compositing so we must fake it
|
||||||
|
compositingWorks = false;
|
||||||
|
#elif defined(Q_WS_X11)
|
||||||
|
if ( !QX11Info::isCompositingManagerRunning() )
|
||||||
|
compositingWorks = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QPainter p;
|
||||||
|
QImage result;
|
||||||
|
if ( compositingWorks )
|
||||||
|
{
|
||||||
|
p.begin( this );
|
||||||
p.setRenderHint( QPainter::Antialiasing );
|
p.setRenderHint( QPainter::Antialiasing );
|
||||||
p.setBackgroundMode( Qt::TransparentMode );
|
p.setBackgroundMode( Qt::TransparentMode );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = QImage( rect().size(), QImage::Format_ARGB32_Premultiplied );
|
||||||
|
p.begin( &result );
|
||||||
|
p.setCompositionMode( QPainter::CompositionMode_Source );
|
||||||
|
p.fillRect(result.rect(), Qt::transparent);
|
||||||
|
p.setCompositionMode( QPainter::CompositionMode_SourceOver );
|
||||||
|
}
|
||||||
|
|
||||||
QPen pen( TomahawkUtils::Colors::BORDER_LINE );
|
QPen pen( TomahawkUtils::Colors::BORDER_LINE );
|
||||||
pen.setWidth( 2 );
|
pen.setWidth( 2 );
|
||||||
@@ -121,6 +153,16 @@ void AccountsPopupWidget::paintEvent( QPaintEvent* )
|
|||||||
|
|
||||||
p.setOpacity( TomahawkUtils::POPUP_OPACITY );
|
p.setOpacity( TomahawkUtils::POPUP_OPACITY );
|
||||||
p.fillPath( outline, TomahawkUtils::Colors::POPUP_BACKGROUND );
|
p.fillPath( outline, TomahawkUtils::Colors::POPUP_BACKGROUND );
|
||||||
|
p.end();
|
||||||
|
|
||||||
|
if ( !compositingWorks )
|
||||||
|
{
|
||||||
|
QPainter finalPainter( this );
|
||||||
|
finalPainter.setRenderHint( QPainter::Antialiasing );
|
||||||
|
finalPainter.setBackgroundMode( Qt::TransparentMode );
|
||||||
|
finalPainter.drawImage( 0, 0, result );
|
||||||
|
setMask( QPixmap::fromImage( result ).mask() );
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef QT_MAC_USE_COCOA
|
#ifdef QT_MAC_USE_COCOA
|
||||||
// Work around bug in Qt/Mac Cocoa where opening subsequent popups
|
// Work around bug in Qt/Mac Cocoa where opening subsequent popups
|
||||||
@@ -130,14 +172,17 @@ void AccountsPopupWidget::paintEvent( QPaintEvent* )
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountsPopupWidget::focusOutEvent( QFocusEvent* )
|
AccountsPopupWidget::focusOutEvent( QFocusEvent* )
|
||||||
{
|
{
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountsPopupWidget::hideEvent( QHideEvent* )
|
AccountsPopupWidget::hideEvent( QHideEvent* )
|
||||||
{
|
{
|
||||||
emit hidden();
|
emit hidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user