Browse Source

Allow the Amarok OSD to use true transparency if it is available

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/amarok@1247185 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 11 years ago
parent
commit
6963d8ef73
  1. 1
      amarok/src/Options5.ui
  2. 41
      amarok/src/Options5.ui.h
  3. 4
      amarok/src/app.cpp
  4. 49
      amarok/src/osd.cpp
  5. 4
      amarok/src/osd.h

1
amarok/src/Options5.ui

@ -517,6 +517,7 @@
<Q_SLOTS>
<slot access="protected">slotPositionChanged()</slot>
<slot access="protected">useCustomColorsToggled( bool on )</slot>
<slot access="protected">useFakeTransparencyToggled( bool on )</slot>
</Q_SLOTS>
<functions>
<function access="private" specifier="non virtual">init()</function>

41
amarok/src/Options5.ui.h

@ -25,6 +25,7 @@ email : fh@ez.no
#include "amarokconfig.h"
#include <klocale.h>
#include <kapplication.h>
#include "qstringx.h"
#include <tqtooltip.h>
@ -41,20 +42,22 @@ void Options5::init()
for( int i = 0; i < numScreens; i++ )
kcfg_OsdScreen->insertItem( TQString::number( i ) );
connect( kcfg_OsdDrawShadow, TQT_SIGNAL( toggled(bool) ),
m_pOSDPreview, TQT_SLOT( setDrawShadow(bool) ) );
connect( kcfg_OsdTextColor, TQT_SIGNAL( changed(const TQColor&) ),
m_pOSDPreview, TQT_SLOT( setTextColor(const TQColor&) ) );
connect( kcfg_OsdUseCustomColors, TQT_SIGNAL( toggled(bool) ),
this, TQT_SLOT( useCustomColorsToggled(bool) ) );
connect( kcfg_OsdBackgroundColor, TQT_SIGNAL( changed(const TQColor&) ),
m_pOSDPreview, TQT_SLOT( setBackgroundColor(const TQColor&) ) );
connect( kcfg_OsdFont, TQT_SIGNAL( fontSelected(const TQFont&) ),
m_pOSDPreview, TQT_SLOT( setFont(const TQFont&) ) );
connect( kcfg_OsdScreen, TQT_SIGNAL( activated(int) ),
m_pOSDPreview, TQT_SLOT( setScreen(int) ) );
connect( kcfg_OsdEnabled, TQT_SIGNAL( toggled(bool) ),
m_pOSDPreview, TQT_SLOT( setShown(bool) ) );
connect( kcfg_OsdDrawShadow, TQT_SIGNAL( toggled(bool) ),
m_pOSDPreview, TQT_SLOT( setDrawShadow(bool) ) );
connect( kcfg_OsdTextColor, TQT_SIGNAL( changed(const TQColor&) ),
m_pOSDPreview, TQT_SLOT( setTextColor(const TQColor&) ) );
connect( kcfg_OsdUseCustomColors, TQT_SIGNAL( toggled(bool) ),
this, TQT_SLOT( useCustomColorsToggled(bool) ) );
connect( kcfg_OsdUseFakeTranslucency, TQT_SIGNAL( toggled(bool) ),
this, TQT_SLOT( useFakeTransparencyToggled(bool) ) );
connect( kcfg_OsdBackgroundColor, TQT_SIGNAL( changed(const TQColor&) ),
m_pOSDPreview, TQT_SLOT( setBackgroundColor(const TQColor&) ) );
connect( kcfg_OsdFont, TQT_SIGNAL( fontSelected(const TQFont&) ),
m_pOSDPreview, TQT_SLOT( setFont(const TQFont&) ) );
connect( kcfg_OsdScreen, TQT_SIGNAL( activated(int) ),
m_pOSDPreview, TQT_SLOT( setScreen(int) ) );
connect( kcfg_OsdEnabled, TQT_SIGNAL( toggled(bool) ),
m_pOSDPreview, TQT_SLOT( setShown(bool) ) );
Amarok::QStringx text = i18n(
"<h3>Tags Displayed in OSD</h3>"
@ -113,6 +116,7 @@ void
Options5::showEvent( TQShowEvent* )
{
useCustomColorsToggled( kcfg_OsdUseCustomColors->isChecked() );
useFakeTransparencyToggled( kcfg_OsdUseFakeTranslucency->isChecked() );
m_pOSDPreview->setFont( kcfg_OsdFont->font() );
m_pOSDPreview->setScreen( kcfg_OsdScreen->currentItem() );
@ -124,3 +128,12 @@ Options5::useCustomColorsToggled( bool on )
{
m_pOSDPreview->setUseCustomColors( on, kcfg_OsdTextColor->color(), kcfg_OsdBackgroundColor->color() );
}
void
Options5::useFakeTransparencyToggled( bool on )
{
if (kapp->isX11CompositionAvailable())
m_pOSDPreview->setTranslucency( on );
else
m_pOSDPreview->setTranslucency( false );
}

4
amarok/src/app.cpp

@ -120,12 +120,12 @@ appleEventProcessor(const AppleEvent *ae, AppleEvent *, long /*handlerRefCon*/)
LIBAMAROK_EXPORT KAboutData aboutData( "amarok",
I18N_NOOP( "Amarok" ), APP_VERSION,
I18N_NOOP( "The audio player for KDE" ), KAboutData::License_GPL,
I18N_NOOP( "(C) 2002-2003, Mark Kretschmann\n(C) 2003-2007, The Amarok Development Squad" ),
I18N_NOOP( "(C) 2002-2003, Mark Kretschmann\n(C) 2003-2007, The Amarok Development Squad\n(C) 2007-2011, The Trinity Desktop Project" ),
I18N_NOOP( "IRC:\nirc.freenode.net - #amarok, #amarok.de, #amarok.es\n\nFeedback:\namarok@kde.org\n\n(Build Date: " __DATE__ ")" ),
( "http://amarok.kde.org" ) );
App::App()
: KApplication()
: KApplication(KApplication::openX11RGBADisplay())
, m_pPlayerWindow( 0 ) //will be created in applySettings()
{
DEBUG_BLOCK

49
amarok/src/osd.cpp

@ -139,7 +139,7 @@ OSDWidget::show() //virtual
newGeometry.width(), newGeometry.height() ));
else if( m_translucency )
else if (( m_translucency ) && (!kapp->isX11CompositionAvailable()))
{
const TQRect unite = oldGeometry.unite( newGeometry );
KPixmap pix = TQPixmap(TQPixmap::grabWindow( qt_xrootwin(), unite.x(), unite.y(), unite.width(), unite.height() ));
@ -158,7 +158,7 @@ OSDWidget::show() //virtual
render( M, newGeometry.size() );
setGeometry( newGeometry );
TQWidget::show();
bitBlt( this, 0, 0, &m_buffer );
paintMe();
if( m_duration ) //duration 0 -> stay forever
m_timer->start( m_duration, true ); //calls hide()
@ -308,7 +308,7 @@ OSDWidget::render( const uint M, const TQSize &size )
m_buffer.resize( rect.size() );
TQPainter p( &m_buffer );
if( m_translucency )
if (( m_translucency ) && (!kapp->isX11CompositionAvailable()))
{
KPixmap background( m_screenshot );
KPixmapEffect::fade( background, 0.80, backgroundColor() );
@ -386,7 +386,7 @@ OSDWidget::render( const uint M, const TQSize &size )
pixmapGradient.setMask( mask );
}
if( m_translucency )
if (( m_translucency ) && (!kapp->isX11CompositionAvailable()))
{
KPixmap background( m_screenshot );
KPixmapEffect::fade( background, 0.80, backgroundColor() );
@ -487,6 +487,45 @@ OSDWidget::render( const uint M, const TQSize &size )
p.end();
}
void
OSDWidget::paintMe()
{
if ((m_translucency) && (kapp->isX11CompositionAvailable())) {
// We have true composition support, so make the OSD truly transparent
TQImage blendedImage = m_buffer.convertToImage();
blendedImage = blendedImage.convertDepth(32);
blendedImage.setAlphaBuffer(true);
int w = blendedImage.width();
int h = blendedImage.height();
for (int y = 0; y < h; ++y) {
TQRgb *ls = (TQRgb *)blendedImage.scanLine( y );
for (int x = 0; x < w; ++x) {
TQRgb l = ls[x];
//int desired_alpha = 127;
int desired_alpha = 204;
float alpha_adjust = (desired_alpha/256.0);
int r = int( tqRed( l ) * alpha_adjust );
int g = int( tqGreen( l ) * alpha_adjust );
int b = int( tqBlue( l ) * alpha_adjust );
int a = int( desired_alpha );
ls[x] = tqRgba( r, g, b, a );
}
}
// Finally, paint it
TQPainter p1;
p1.begin( this );
blendedImage.setAlphaBuffer(false);
p1.drawImage( 0, 0, blendedImage );
p1.end();
}
else {
bitBlt( this, 0, 0, &m_buffer );
}
}
bool
OSDWidget::event( TQEvent *e )
{
@ -497,7 +536,7 @@ OSDWidget::event( TQEvent *e )
unsetColors(); //use new palette's colours
return true;
case TQEvent::Paint:
bitBlt( this, 0, 0, &m_buffer );
paintMe();
return true;
default:
return TQWidget::event( e );

4
amarok/src/osd.h

@ -26,7 +26,7 @@
class OSDWidget : public TQWidget
{
Q_OBJECT
TQ_OBJECT
TQ_OBJECT
public:
enum Alignment { Left, Middle, Center, Right };
@ -81,6 +81,8 @@ class OSDWidget : public TQWidget
bool useMoodbar( void );
void paintMe();
/** distance from screen edge */
static const int MARGIN = 15;

Loading…
Cancel
Save