Cope with global color scheme changes in the page number entry.

CCMAIL:wstephenson@kde.org
This commit is contained in:
Eike Hein 2013-02-13 13:52:42 +01:00
parent a3b3545cab
commit d865f4d733
2 changed files with 22 additions and 6 deletions

View file

@ -466,6 +466,8 @@ PagesEdit::PagesEdit( MiniBar * parent )
// send a focus out event
QFocusEvent fe( QEvent::FocusOut );
QApplication::sendEvent( this, &fe );
connect( KGlobalSettings::self(), SIGNAL(appearanceChanged()), this, SLOT(updatePalette()) );
}
void PagesEdit::setText( const QString & newText )
@ -502,6 +504,18 @@ void PagesEdit::setText( const QString & newText )
}
}
void PagesEdit::updatePalette()
{
QPalette pal;
if ( hasFocus() )
pal.setColor( QPalette::Active, QPalette::Base, QApplication::palette().color( QPalette::Active, QPalette::Base ) );
else
pal.setColor( QPalette::Base, QApplication::palette().color( QPalette::Base ).dark( 102 ) );
setPalette( pal );
}
void PagesEdit::focusInEvent( QFocusEvent * e )
{
// select all text
@ -509,9 +523,7 @@ void PagesEdit::focusInEvent( QFocusEvent * e )
if ( e->reason() == Qt::MouseFocusReason )
m_eatClick = true;
// change background color to the default 'edit' color
QPalette pal = palette();
pal.setColor( QPalette::Active, QPalette::Base, QApplication::palette().color( QPalette::Active, QPalette::Base ) );
setPalette( pal );
updatePalette();
// call default handler
KLineEdit::focusInEvent( e );
}
@ -519,9 +531,7 @@ void PagesEdit::focusInEvent( QFocusEvent * e )
void PagesEdit::focusOutEvent( QFocusEvent * e )
{
// change background color to a dark tone
QPalette pal = palette();
pal.setColor( QPalette::Base, QApplication::palette().color( QPalette::Base ).dark( 102 ) );
setPalette( pal );
updatePalette();
// call default handler
KLineEdit::focusOutEvent( e );
}

View file

@ -28,6 +28,8 @@ class QLabel;
// [private widget] lineEdit for entering/validating page numbers
class PagesEdit : public KLineEdit
{
Q_OBJECT
public:
PagesEdit( MiniBar * parent );
void setText( const QString & );
@ -38,9 +40,13 @@ class PagesEdit : public KLineEdit
void mousePressEvent( QMouseEvent * e );
void wheelEvent( QWheelEvent * e );
private slots:
void updatePalette();
private:
MiniBar * m_miniBar;
bool m_eatClick;
bool m_focus;
};
class PageNumberEdit : public PagesEdit