File indexing completed on 2024-10-06 04:26:03

0001 /*
0002     SPDX-FileCopyrightText: 2006-2008 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-FileCopyrightText: 2010 Michal Malek <michalm@jabster.pl>
0004     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "k3bthemedheader.h"
0009 #include "k3bthememanager.h"
0010 #include "k3bapplication.h"
0011 #include "k3btitlelabel.h"
0012 
0013 #include <QApplication>
0014 #include <QHBoxLayout>
0015 #include <QLabel>
0016 
0017 
0018 K3b::ThemedHeader::ThemedHeader( QWidget* parent )
0019     : QFrame( parent )
0020 {
0021     init();
0022 }
0023 
0024 
0025 K3b::ThemedHeader::ThemedHeader( const QString& title, const QString& subtitle, QWidget* parent )
0026     : QFrame( parent )
0027 {
0028     setTitle( title );
0029     setSubTitle( subtitle );
0030 
0031     init();
0032 }
0033 
0034 
0035 K3b::ThemedHeader::~ThemedHeader()
0036 {
0037 }
0038 
0039 
0040 void K3b::ThemedHeader::setTitle( const QString& title, const QString& subtitle )
0041 {
0042     m_titleLabel->setTitle( title, subtitle );
0043 }
0044 
0045 
0046 void K3b::ThemedHeader::setSubTitle( const QString& subtitle )
0047 {
0048     m_titleLabel->setSubTitle( subtitle );
0049 }
0050 
0051 
0052 void K3b::ThemedHeader::setLeftPixmap( K3b::Theme::PixmapType p )
0053 {
0054     m_leftPix = p;
0055     slotThemeChanged();
0056 }
0057 
0058 
0059 void K3b::ThemedHeader::setRightPixmap( K3b::Theme::PixmapType p )
0060 {
0061     m_rightPix = p;
0062     slotThemeChanged();
0063 }
0064 
0065 
0066 void K3b::ThemedHeader::setAlignment( Qt::Alignment alignment )
0067 {
0068     m_titleLabel->setAlignment( alignment );
0069 }
0070 
0071 
0072 void K3b::ThemedHeader::init()
0073 {
0074     // Hardcode layout direction to LTR to prevent
0075     // switching places of our left/right pixmaps.
0076     // Usually our themes aren't designed for this
0077     setLayoutDirection( Qt::LeftToRight );
0078     setFrameShape( QFrame::StyledPanel );
0079     setFrameShadow( QFrame::Sunken );
0080     setLineWidth( 1 );
0081     //setMargin( 1 );
0082 
0083     m_leftLabel = new QLabel( this );
0084     m_leftLabel->setScaledContents( false );
0085     m_leftLabel->setAutoFillBackground( true );
0086 
0087     m_titleLabel = new K3b::TitleLabel( this );
0088     // Bring back default layout direction for label
0089     m_titleLabel->setLayoutDirection( QApplication::layoutDirection() );
0090 
0091     m_rightLabel = new QLabel( this );
0092     m_rightLabel->setScaledContents( false );
0093     m_rightLabel->setAutoFillBackground( true );
0094 
0095     QHBoxLayout* layout = new QHBoxLayout( this );
0096     layout->setContentsMargins(0, 0, 0, 0);
0097     layout->setSpacing( 0 );
0098     layout->addWidget( m_leftLabel );
0099     layout->addWidget( m_titleLabel );
0100     layout->setStretchFactor( m_titleLabel, 1 );
0101     layout->addWidget( m_rightLabel );
0102 
0103     m_leftPix = K3b::Theme::DIALOG_LEFT;
0104     m_rightPix = K3b::Theme::DIALOG_RIGHT;
0105 
0106     slotThemeChanged();
0107 
0108     connect( k3bappcore->themeManager(), SIGNAL(themeChanged()),
0109              this, SLOT(slotThemeChanged()) );
0110 }
0111 
0112 
0113 bool K3b::ThemedHeader::event( QEvent *event )
0114 {
0115     if( event->type() == QEvent::StyleChange ) {
0116         slotThemeChanged();
0117     }
0118     return QFrame::event( event );
0119 }
0120 
0121 
0122 void K3b::ThemedHeader::slotThemeChanged()
0123 {
0124     if( K3b::Theme* theme = k3bappcore->themeManager()->currentTheme() ) {
0125         m_leftLabel->setPalette( theme->palette() );
0126         m_leftLabel->setPixmap( theme->pixmap( m_leftPix ) );
0127 
0128         m_rightLabel->setPalette( theme->palette() );
0129         m_rightLabel->setPixmap( theme->pixmap( m_rightPix ) );
0130 
0131         m_titleLabel->setPalette( theme->palette() );
0132     }
0133 }
0134 
0135 #include "moc_k3bthemedheader.cpp"