mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-20 07:52:30 +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:
parent
12b0efdf8f
commit
2b18cca7c5
@ -29,14 +29,22 @@
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QVBoxLayout>
|
||||
#ifdef Q_WS_X11
|
||||
#include <QtGui/QX11Info>
|
||||
#include <QBitmap>
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QBitmap>
|
||||
#endif
|
||||
|
||||
|
||||
AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, m_widget( 0 )
|
||||
, m_arrowOffset( 0 )
|
||||
{
|
||||
setWindowFlags( Qt::FramelessWindowHint );
|
||||
setWindowFlags( Qt::Popup );
|
||||
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
|
||||
|
||||
//Uncomment this if using a debugger:
|
||||
//setWindowFlags( Qt::Window );
|
||||
|
||||
@ -44,7 +52,6 @@ AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
||||
setAttribute( Qt::WA_TranslucentBackground, true );
|
||||
setAttribute( Qt::WA_NoSystemBackground, true );
|
||||
|
||||
|
||||
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
||||
|
||||
m_layout = new QVBoxLayout( this );
|
||||
@ -59,6 +66,7 @@ AccountsPopupWidget::AccountsPopupWidget( QWidget* parent )
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountsPopupWidget::setWidget( QWidget* widget )
|
||||
{
|
||||
@ -67,6 +75,7 @@ AccountsPopupWidget::setWidget( QWidget* widget )
|
||||
m_widget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountsPopupWidget::anchorAt( const QPoint &p )
|
||||
{
|
||||
@ -77,6 +86,7 @@ AccountsPopupWidget::anchorAt( const QPoint &p )
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountsPopupWidget::setArrowOffset( int arrowOffset )
|
||||
{
|
||||
@ -89,7 +99,9 @@ AccountsPopupWidget::setArrowOffset( int arrowOffset )
|
||||
}
|
||||
}
|
||||
|
||||
void AccountsPopupWidget::paintEvent( QPaintEvent* )
|
||||
|
||||
void
|
||||
AccountsPopupWidget::paintEvent( QPaintEvent* )
|
||||
{
|
||||
// Constants for painting
|
||||
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 - 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
|
||||
|
||||
p.setRenderHint( QPainter::Antialiasing );
|
||||
p.setBackgroundMode( Qt::TransparentMode );
|
||||
QPainter p;
|
||||
QImage result;
|
||||
if ( compositingWorks )
|
||||
{
|
||||
p.begin( this );
|
||||
p.setRenderHint( QPainter::Antialiasing );
|
||||
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 );
|
||||
pen.setWidth( 2 );
|
||||
@ -121,6 +153,16 @@ void AccountsPopupWidget::paintEvent( QPaintEvent* )
|
||||
|
||||
p.setOpacity( TomahawkUtils::POPUP_OPACITY );
|
||||
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
|
||||
// Work around bug in Qt/Mac Cocoa where opening subsequent popups
|
||||
@ -130,14 +172,17 @@ void AccountsPopupWidget::paintEvent( QPaintEvent* )
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountsPopupWidget::focusOutEvent( QFocusEvent* )
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountsPopupWidget::hideEvent( QHideEvent* )
|
||||
{
|
||||
emit hidden();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user