File indexing completed on 2024-10-13 04:22:14
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "k3bthemedlabel.h" 0007 #include "k3bapplication.h" 0008 #include <QDebug> 0009 K3b::ThemedLabel::ThemedLabel( QWidget* parent ) 0010 : KSqueezedTextLabel( parent ), 0011 m_themePixmapCode( -1 ) 0012 { 0013 slotThemeChanged(); 0014 setTextElideMode( Qt::ElideRight ); 0015 0016 if (k3bappcore) { 0017 connect( k3bappcore->themeManager(), SIGNAL(themeChanged()), 0018 this, SLOT(slotThemeChanged()) ); 0019 } 0020 } 0021 0022 0023 K3b::ThemedLabel::ThemedLabel( const QString& text, QWidget* parent ) 0024 : KSqueezedTextLabel( text, parent ), 0025 m_themePixmapCode( -1 ) 0026 { 0027 slotThemeChanged(); 0028 setTextElideMode( Qt::ElideRight ); 0029 0030 if (k3bappcore) { 0031 connect( k3bappcore->themeManager(), SIGNAL(themeChanged()), 0032 this, SLOT(slotThemeChanged()) ); 0033 } 0034 } 0035 0036 0037 K3b::ThemedLabel::ThemedLabel( K3b::Theme::PixmapType pix, QWidget* parent ) 0038 : KSqueezedTextLabel( parent ) 0039 { 0040 setThemePixmap( pix ); 0041 setTextElideMode( Qt::ElideRight ); 0042 0043 if (k3bappcore) { 0044 connect( k3bappcore->themeManager(), SIGNAL(themeChanged()), 0045 this, SLOT(slotThemeChanged()) ); 0046 } 0047 } 0048 0049 0050 bool K3b::ThemedLabel::event( QEvent *event ) 0051 { 0052 if( event->type() == QEvent::StyleChange ) { 0053 slotThemeChanged(); 0054 } 0055 return KSqueezedTextLabel::event( event ); 0056 } 0057 0058 0059 void K3b::ThemedLabel::setThemePixmap( K3b::Theme::PixmapType pix ) 0060 { 0061 m_themePixmapCode = pix; 0062 slotThemeChanged(); 0063 } 0064 0065 0066 void K3b::ThemedLabel::slotThemeChanged() 0067 { 0068 setAutoFillBackground( true ); 0069 if (k3bappcore == Q_NULLPTR) 0070 return; 0071 if( K3b::Theme* theme = k3bappcore->themeManager()->currentTheme() ) { 0072 QPalette p = palette(); 0073 p.setColor( backgroundRole(), theme->backgroundColor() ); 0074 p.setColor( foregroundRole(), theme->foregroundColor() ); 0075 setPalette( p ); 0076 if( m_themePixmapCode > -1 ) { 0077 setPixmap( theme->pixmap( (K3b::Theme::PixmapType)m_themePixmapCode ) ); 0078 setScaledContents( false ); 0079 const QPixmap &pix = pixmap(Qt::ReturnByValue); 0080 if ( !pix.isNull() ) { 0081 setFixedSize( pix.size() ); 0082 } 0083 } 0084 } 0085 } 0086 0087 #include "moc_k3bthemedlabel.cpp"