5 #include <QApplication>
8 QY2Styler *QY2Styler::_self = 0;
10 QY2Styler::QY2Styler( QObject *parent )
16 void QY2Styler::setStyleSheet( const QString &filename )
18 QFile file( themeDir() + filename );
19 if ( file.open( QIODevice::ReadOnly ) )
21 QString content = file.readAll();
22 processUrls( content );
23 //qApp->setStyleSheet( content );
27 void QY2Styler::processUrls(QString &text)
30 QStringList lines = text.split( '\n' );
31 QRegExp urlx( ": *url\\((.*)\\)" );
32 QRegExp backgroundx( "^ */\\* *Background: *([^ ]*) *([^ ]*) *\\*/$" );
33 for ( QStringList::const_iterator it = lines.begin(); it != lines.end(); ++it )
36 if ( urlx.indexIn( line ) >= 0 )
37 line.replace( urlx, ": url(" + themeDir() + urlx.cap( 1 ) + ")");
39 if ( backgroundx.exactMatch( line ) )
40 _backgroundFn[backgroundx.cap( 1 )] = themeDir() + backgroundx.cap( 2 );
47 QString QY2Styler::themeDir() const
49 return THEMEDIR "/openSUSE/wizard/";
52 void QY2Styler::registerWidget( QWidget *widget )
55 widget->installEventFilter( this );
58 bool QY2Styler::eventFilter( QObject * obj, QEvent * ev )
60 if ( ev->type() != QEvent::Resize )
61 return QObject::eventFilter( obj, ev );
63 QString name = obj->objectName();
65 qDebug( "eventFilter %s", qPrintable( name ) );
67 if ( !_backgroundFn.contains( name ) )
68 return QObject::eventFilter( obj, ev );
70 QWidget *wid = qobject_cast<QWidget*>( obj );
71 if ( !_backgroundPx.contains( name ) )
73 QString back = _backgroundFn[ name ];
74 _backgroundPx[ name ] = QImage( back );
75 wid->setAutoFillBackground( true );
76 qDebug( "loading %s for %s", qPrintable( back ), qPrintable( name ) );
79 QPixmap img = QPixmap::fromImage( _backgroundPx[name].scaled( wid->contentsRect().width(), wid->contentsRect().height() ) );
80 QPalette p = wid->palette();
81 p.setBrush(QPalette::Window, img );
84 return QObject::eventFilter( obj, ev );
87 #include "QY2Styler.moc"