Author: coolo Date: Thu Apr 17 14:43:37 2008 New Revision: 46790 URL: http://svn.opensuse.org/viewcvs/yast?rev=46790&view=rev Log: as ycp programmers like to hardcode colors, we need a way to make color=red themeable - done Modified: trunk/qt/src/YQRichText.cc trunk/qt/src/YQRichText.h Modified: trunk/qt/src/YQRichText.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQRichText.cc?rev=46790&r1=46789&r2=46790&view=diff ============================================================================== --- trunk/qt/src/YQRichText.cc (original) +++ trunk/qt/src/YQRichText.cc Thu Apr 17 14:43:37 2008 @@ -22,6 +22,7 @@ #include <QColorGroup> #include <QScrollBar> #include <QRegExp> +#include <QDebug> #include <QKeyEvent> #include <QVBoxLayout> @@ -33,10 +34,12 @@ #include "YQDialog.h" #include "YQRichText.h" +static const char *colors[] = { "red", 0}; YQRichText::YQRichText( YWidget * parent, const string & text, bool plainTextMode ) : QFrame( (QWidget *) parent->widgetRep() ) , YRichText( parent, text, plainTextMode ) + , _colors_specified( 0 ) { QVBoxLayout* layout = new QVBoxLayout( this ); layout->setSpacing( 0 ); @@ -58,7 +61,19 @@ } else { - _textBrowser->document()->setDefaultStyleSheet( QY2Styler::self()->textStyle() ); + QString style = "\n" + QY2Styler::self()->textStyle(); + size_t ccolors = sizeof( colors ) / sizeof( char* ) - 1; + yuiDebug() << "colors " << ccolors << endl; + _colors_specified = new bool[ccolors]; + for ( size_t i = 0; i < ccolors; ++i ) + { + _colors_specified[i] = false; + char buffer[20]; + sprintf( buffer, "\n.%s ", colors[i] ); + if ( style.contains( buffer ) ) + _colors_specified[i] = true; + } + _textBrowser->document()->setDefaultStyleSheet( style ); } setValue( text ); @@ -78,8 +93,6 @@ void YQRichText::setValue( const string & newText ) { - yuiMilestone() << newText << endl; - if ( _textBrowser->horizontalScrollBar() ) _textBrowser->horizontalScrollBar()->setValue(0); @@ -90,8 +103,14 @@ if ( ! plainTextMode() ) { - text.replace( "&product;", fromUTF8( YUI::app()->productName() ) ); - _textBrowser->setHtml( text ); + for ( int counter = 0; colors[counter]; counter++ ) + { + if ( !_colors_specified[counter] ) continue; + text.replace( QString( "color=%1" ).arg( colors[counter] ), QString( "class=\"%1\"" ).arg( colors[counter] ) ); + text.replace( QString( "color=\"%1\"" ).arg( colors[counter] ), QString( "class=\"%1\"" ).arg( colors[counter] )); + } + text.replace( "&product;", fromUTF8( YUI::app()->productName() ) ); + _textBrowser->setHtml( text ); } else { Modified: trunk/qt/src/YQRichText.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQRichText.h?rev=46790&r1=46789&r2=46790&view=diff ============================================================================== --- trunk/qt/src/YQRichText.h (original) +++ trunk/qt/src/YQRichText.h Thu Apr 17 14:43:37 2008 @@ -128,6 +128,13 @@ protected: YQTextBrowser * _textBrowser; + +private: + /** + * to avoid big suprises, we remember if the stylesheet specified a + * color before we replace color= with class= + **/ + bool *_colors_specified; }; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org