5 #include <QApplication>
9 QY2Styler *QY2Styler::_self = 0;
11 QY2Styler::QY2Styler( QObject *parent )
17 void QY2Styler::setStyleSheet( const QString &filename )
19 QFile file( themeDir() + filename );
20 if ( file.open( QIODevice::ReadOnly ) )
22 QString content = file.readAll();
23 processUrls( content );
24 qApp->setStyleSheet( content );
28 void QY2Styler::processUrls(QString &text)
31 QStringList lines = text.split( '\n' );
32 QRegExp urlx( ": *url\\((.*)\\)" );
33 QRegExp backgroundx( "^ */\\* *Background: *([^ ]*) *([^ ]*) *\\*/$" );
34 for ( QStringList::const_iterator it = lines.begin(); it != lines.end(); ++it )
37 if ( urlx.indexIn( line ) >= 0 )
38 line.replace( urlx, ": url(" + themeDir() + urlx.cap( 1 ) + ")");
40 if ( backgroundx.exactMatch( line ) )
41 _backgroundFn[backgroundx.cap( 1 )] = themeDir() + backgroundx.cap( 2 );
48 QString QY2Styler::themeDir() const
50 return THEMEDIR "/openSUSE/wizard/";
53 void QY2Styler::registerWidget( QWidget *widget )
55 widget->installEventFilter( this );
58 bool QY2Styler::eventFilter( QObject * obj, QEvent * ev )
60 QString name = obj->objectName();
62 if ( ev->type() != QEvent::Resize )
63 return QObject::eventFilter( obj, ev );
65 if ( !_backgroundFn.contains( name ) )
66 return QObject::eventFilter( obj, ev );
68 qDebug( "eventFilter %s %s %d", qPrintable( name ), obj->metaObject()->className(), ev->type() );
70 QWidget *wid = qobject_cast<QWidget*>( obj );
71 if ( !_backgroundPx.contains( name ) )
73 QString back = _backgroundFn[ name ];
74 _backgroundPx[ name ] = QImage( back );
75 qDebug( "loading %s for %s", qPrintable( back ), qPrintable( name ) );
78 wid->setAutoFillBackground( true );
80 QPixmap result( wid->size() );
81 if ( wid->contentsRect() != wid->rect() )
82 result.fill( QColor( 0, 128, 0, 0 ) );
84 QPainter pain( &result );
85 pain.drawImage( wid->contentsRect().topLeft(), _backgroundPx[name].scaled( wid->contentsRect().width(), wid->contentsRect().height() ) );
87 QPalette p = wid->palette();
88 p.setBrush(QPalette::Window, result );
91 return QObject::eventFilter( obj, ev );
94 #include "QY2Styler.moc"