1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-14 04:51:53 +02:00

Apply popup fix on SourceTreePopupDialog as well.

This commit is contained in:
Teo Mrnjavac 2012-12-05 17:31:40 +01:00
parent 2b18cca7c5
commit e7b0ba71e7
4 changed files with 80 additions and 78 deletions

View File

@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, 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
@ -39,10 +40,12 @@
#ifdef Q_WS_X11
#include <QtGui/QX11Info>
#include <QBitmap>
#include <libqnetwm/netwm.h>
#endif
#ifdef Q_WS_WIN
#include <QBitmap>
#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
@ -851,4 +854,63 @@ addDropShadow( const QPixmap& source, const QSize& targetSize )
}
void
drawCompositedPopup( QWidget* widget,
const QPainterPath& outline,
const QColor& lineColor,
const QBrush& backgroundBrush,
qreal opacity )
{
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( widget );
p.setRenderHint( QPainter::Antialiasing );
p.setBackgroundMode( Qt::TransparentMode );
}
else
{
result = QImage( widget->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( lineColor );
pen.setWidth( 2 );
p.setPen( pen );
p.drawPath( outline );
p.setOpacity( opacity );
p.fillPath( outline, backgroundBrush );
p.end();
if ( !compositingWorks )
{
QPainter finalPainter( widget );
finalPainter.setRenderHint( QPainter::Antialiasing );
finalPainter.setBackgroundMode( Qt::TransparentMode );
finalPainter.drawImage( 0, 0, result );
widget->setMask( QPixmap::fromImage( result ).mask() );
}
#ifdef QT_MAC_USE_COCOA
// Work around bug in Qt/Mac Cocoa where opening subsequent popups
// would incorrectly calculate the background due to it not being
// invalidated.
SourceTreePopupHelper::clearBackground( this );
#endif
}
} // ns

View File

@ -75,6 +75,8 @@ namespace TomahawkUtils
DLLEXPORT QPixmap addDropShadow( const QPixmap& sourceImage, const QSize& targetSize );
DLLEXPORT void drawCompositedPopup( QWidget* widget, const QPainterPath& outline, const QColor& lineColor, const QBrush& backgroundBrush, qreal opacity );
namespace Colors
{
static const QColor BORDER_LINE = QColor( "#8c8c8c" );

View File

@ -206,28 +206,18 @@ SourceTreePopupDialog::paintEvent( QPaintEvent* event )
outline.lineTo( leftEdgeOffset, brect.top() + brect.height() / 2 + leftTriangleWidth / 2 );
outline.lineTo( brect.left(), brect.top() + brect.height() / 2 );
QPainter p( this );
p.setRenderHint( QPainter::Antialiasing );
QPen pen( TomahawkUtils::Colors::BORDER_LINE );
pen.setWidth( 2 );
p.setPen( pen );
p.drawPath( outline );
#ifdef Q_OS_MAC
p.setOpacity( 0.93 );
p.fillPath( outline, QColor( "#D6E3F1" ) );
#ifndef Q_OS_MAC
TomahawkUtils::drawCompositedPopup( this,
outline,
TomahawkUtils::Colors::BORDER_LINE,
TomahawkUtils::Colors::POPUP_BACKGROUND,
TomahawkUtils::POPUP_OPACITY );
#else
p.setOpacity( TomahawkUtils::POPUP_OPACITY );
p.fillPath( outline, TomahawkUtils::Colors::POPUP_BACKGROUND );
#endif
#ifdef QT_MAC_USE_COCOA
// Work around bug in Qt/Mac Cocoa where opening subsequent popups
// would incorrectly calculate the background due to it not being
// invalidated.
SourceTreePopupHelper::clearBackground( this );
TomahawkUtils::drawCompositedPopup( this,
outline,
TomahawkUtils::Colors::BORDER_LINE,
QColor( "#D6E3F1" ),
0.93 );
#endif
}

View File

@ -29,14 +29,6 @@
#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 )
@ -121,55 +113,11 @@ AccountsPopupWidget::paintEvent( QPaintEvent* )
outline.lineTo( rect().right() - m_arrowOffset, 2 );
outline.lineTo( rect().right() - m_arrowOffset - arrowHeight, brect.top() );
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.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 );
p.setPen( pen );
p.drawPath( outline );
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
// would incorrectly calculate the background due to it not being
// invalidated.
SourceTreePopupHelper::clearBackground( this );
#endif
TomahawkUtils::drawCompositedPopup( this,
outline,
TomahawkUtils::Colors::BORDER_LINE,
TomahawkUtils::Colors::POPUP_BACKGROUND,
TomahawkUtils::POPUP_OPACITY );
}