mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
Apply popup fix on SourceTreePopupDialog as well.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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
|
* 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
|
||||||
@@ -39,10 +40,12 @@
|
|||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
#include <QtGui/QX11Info>
|
#include <QtGui/QX11Info>
|
||||||
|
#include <QBitmap>
|
||||||
#include <libqnetwm/netwm.h>
|
#include <libqnetwm/netwm.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
|
#include <QBitmap>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <windowsx.h>
|
#include <windowsx.h>
|
||||||
#include <shellapi.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
|
} // ns
|
||||||
|
@@ -75,6 +75,8 @@ namespace TomahawkUtils
|
|||||||
|
|
||||||
DLLEXPORT QPixmap addDropShadow( const QPixmap& sourceImage, const QSize& targetSize );
|
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
|
namespace Colors
|
||||||
{
|
{
|
||||||
static const QColor BORDER_LINE = QColor( "#8c8c8c" );
|
static const QColor BORDER_LINE = QColor( "#8c8c8c" );
|
||||||
|
@@ -206,28 +206,18 @@ SourceTreePopupDialog::paintEvent( QPaintEvent* event )
|
|||||||
outline.lineTo( leftEdgeOffset, brect.top() + brect.height() / 2 + leftTriangleWidth / 2 );
|
outline.lineTo( leftEdgeOffset, brect.top() + brect.height() / 2 + leftTriangleWidth / 2 );
|
||||||
outline.lineTo( brect.left(), brect.top() + brect.height() / 2 );
|
outline.lineTo( brect.left(), brect.top() + brect.height() / 2 );
|
||||||
|
|
||||||
QPainter p( this );
|
#ifndef Q_OS_MAC
|
||||||
|
TomahawkUtils::drawCompositedPopup( this,
|
||||||
p.setRenderHint( QPainter::Antialiasing );
|
outline,
|
||||||
|
TomahawkUtils::Colors::BORDER_LINE,
|
||||||
QPen pen( TomahawkUtils::Colors::BORDER_LINE );
|
TomahawkUtils::Colors::POPUP_BACKGROUND,
|
||||||
pen.setWidth( 2 );
|
TomahawkUtils::POPUP_OPACITY );
|
||||||
p.setPen( pen );
|
|
||||||
p.drawPath( outline );
|
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
p.setOpacity( 0.93 );
|
|
||||||
p.fillPath( outline, QColor( "#D6E3F1" ) );
|
|
||||||
#else
|
#else
|
||||||
p.setOpacity( TomahawkUtils::POPUP_OPACITY );
|
TomahawkUtils::drawCompositedPopup( this,
|
||||||
p.fillPath( outline, TomahawkUtils::Colors::POPUP_BACKGROUND );
|
outline,
|
||||||
#endif
|
TomahawkUtils::Colors::BORDER_LINE,
|
||||||
|
QColor( "#D6E3F1" ),
|
||||||
#ifdef QT_MAC_USE_COCOA
|
0.93 );
|
||||||
// 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,14 +29,6 @@
|
|||||||
#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 )
|
||||||
@@ -121,55 +113,11 @@ 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() );
|
||||||
|
|
||||||
bool compositingWorks = true;
|
TomahawkUtils::drawCompositedPopup( this,
|
||||||
#if defined(Q_WS_WIN) //HACK: Windows refuses to perform compositing so we must fake it
|
outline,
|
||||||
compositingWorks = false;
|
TomahawkUtils::Colors::BORDER_LINE,
|
||||||
#elif defined(Q_WS_X11)
|
TomahawkUtils::Colors::POPUP_BACKGROUND,
|
||||||
if ( !QX11Info::isCompositingManagerRunning() )
|
TomahawkUtils::POPUP_OPACITY );
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user