[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/kdm/kfrontend
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2006-09-30 19:54:15
Message-ID: 1159646055.379570.26702.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 590775 by ossi:

factor out attribute parsers into own source


 M  +2 -0      CMakeLists.txt  
 M  +8 -154    themer/kdmitem.cpp  
 M  +2 -13     themer/kdmitem.h  
 A             themer/parse.cpp   [License: GPL (v2+)]
 A             themer/parse.h   [License: GPL (v2+)]


--- trunk/KDE/kdebase/workspace/kdm/kfrontend/CMakeLists.txt #590774:590775
@@ -25,6 +25,8 @@
 	themer/kdmlabel.h
 	themer/kdmlayout.cpp
 	themer/kdmlayout.h
+	themer/parse.cpp
+	themer/parse.h
 )
 set(kdm_greet_SRCS
 	kdm_greet.c
--- trunk/KDE/kdebase/workspace/kdm/kfrontend/themer/kdmitem.cpp #590774:590775
@@ -80,14 +80,14 @@
 		QString tagName = el.tagName(), attr;
 
 		if (tagName == "pos") {
-			parseAttribute( el.attribute( "x", QString() ), geom.pos.x );
-			parseAttribute( el.attribute( "y", QString() ), geom.pos.y );
-			parseAttribute( el.attribute( "width", QString() ), geom.size.x );
-			parseAttribute( el.attribute( "height", QString() ), geom.size.y );
-			parseAttribute( el.attribute( "min-width", QString() ), geom.minSize.x );
-			parseAttribute( el.attribute( "min-height", QString() ), geom.minSize.y );
-			parseAttribute( el.attribute( "max-width", QString() ), geom.maxSize.x );
-			parseAttribute( el.attribute( "max-height", QString() ), geom.maxSize.y );
+			parseSize( el.attribute( "x", QString() ), geom.pos.x );
+			parseSize( el.attribute( "y", QString() ), geom.pos.y );
+			parseSize( el.attribute( "width", QString() ), geom.size.x );
+			parseSize( el.attribute( "height", QString() ), geom.size.y );
+			parseSize( el.attribute( "min-width", QString() ), geom.minSize.x );
+			parseSize( el.attribute( "min-height", QString() ), geom.minSize.y );
+			parseSize( el.attribute( "max-width", QString() ), geom.maxSize.x );
+			parseSize( el.attribute( "max-height", QString() ), geom.maxSize.y );
 			geom.anchor = el.attribute( "anchor", "nw" );
 			QString exp = el.attribute( "expand", "false" ).toLower();
 			bool ok;
@@ -525,152 +525,6 @@
 }
 
 void
-KdmItem::parseAttribute( const QString &s, DataPoint &pt )
-{
-	if (s.isEmpty())
-		return;
-
-	int p;
-	if (s == "box") {	// box value
-		pt.type = DTbox;
-		pt.val = 0;
-	} else if (s == "scale") {
-		pt.type = DTscale;
-		pt.val = 0;
-	} else if ((p = s.indexOf( '%' )) >= 0) {	// percent value
-		pt.type = DTpercent;
-		QString sCopy = s;
-		sCopy.remove( p, 1 );
-		pt.levels = 0;
-		while ((p = sCopy.indexOf( '^' )) >= 0) {
-			sCopy.remove( p, 1 );
-			pt.levels++;
-		}
-		sCopy.replace( ',', '.' );
-		pt.val = (int)sCopy.toDouble();
-	} else {		// int value
-		pt.type = DTpixel;
-		QString sCopy = s;
-		if (sCopy.at( 0 ) == '-') {
-			sCopy.remove( 0, 1 );
-			pt.type = DTnpixel;
-		}
-		sCopy.replace( ',', '.' );
-		pt.val = (int)sCopy.toDouble();
-	}
-}
-
-
-static QString
-getword( QString &rs )
-{
-	int splitAt = rs.lastIndexOf( ' ' ) + 1;
-	QString s( rs.mid( splitAt ) );
-	rs.truncate( splitAt - 1 );
-	return s;
-}
-
-void
-KdmItem::parseFont( const QString &is, QFont &font )
-{
-	QString rs( is.simplified() );
-	QString s( getword( rs ) );
-	bool ok;
-	if (s.endsWith( "px" )) {
-		int ps = s.left( s.length() - 2 ).toInt( &ok );
-		if (ok) {
-			font.setPixelSize( ps );
-			s = getword( rs );
-		}
-	} else {
-		double ps = s.toDouble( &ok );
-		if (ok) {
-			font.setPointSizeF( ps );
-			s = getword( rs );
-		}
-	}
-	forever {
-		QString ss( s.toLower() );
-		if (ss == "oblique")
-			font.setStyle( QFont::StyleOblique );
-		else if (ss == "italic")
-			font.setStyle( QFont::StyleItalic );
-		else if (ss == "ultra-light")
-			font.setWeight( 13 );
-		else if (ss == "light")
-			font.setWeight( QFont::Light );
-		else if (ss == "medium")
-			font.setWeight( 50 );
-		else if (ss == "semi-bold")
-			font.setWeight( QFont::DemiBold );
-		else if (ss == "bold")
-			font.setWeight( QFont::Bold );
-		else if (ss == "ultra-bold")
-			font.setWeight( QFont::Black );
-		else if (ss == "heavy")
-			font.setWeight( 99 );
-		else if (ss == "ultra-condensed")
-			font.setStretch( QFont::UltraCondensed );
-		else if (ss == "extra-condensed")
-			font.setStretch( QFont::ExtraCondensed );
-		else if (ss == "condensed")
-			font.setStretch( QFont::Condensed );
-		else if (ss == "semi-condensed")
-			font.setStretch( QFont::SemiCondensed );
-		else if (ss == "semi-expanded")
-			font.setStretch( QFont::SemiExpanded );
-		else if (ss == "expanded")
-			font.setStretch( QFont::Expanded );
-		else if (ss == "extra-expanded")
-			font.setStretch( QFont::ExtraExpanded );
-		else if (ss == "ultra-expanded")
-			font.setStretch( QFont::UltraExpanded );
-		else if (ss == "normal" || // no-op
-		         ss == "small-caps" || // this and following ignored
-		         ss == "not-rotated" || ss == "south" || ss == "upside-down" ||
-		         ss == "north" ||
-		         ss == "rotated-left" || ss == "east" ||
-		         ss == "rotated-right" || ss == "west")
-		{
-		} else
-			break;
-		s = getword( rs );
-	}
-	if (!rs.isEmpty())
-		rs.append( ' ' ).append( s );
-	else
-		rs = s;
-	QStringList ffs = rs.split( QRegExp( " ?, ?" ), QString::SkipEmptyParts );
-	if (!ffs.isEmpty()) {
-		foreach (QString ff, ffs) {
-			font.setFamily( ff );
-			if (font.exactMatch())
-				return;
-		}
-		font.setFamily( ffs.first() );
-	}
-}
-
-void
-KdmItem::parseColor( const QString &s, const QString &a, QColor &color )
-{
-	if (!s.length() || s.at( 0 ) != '#')
-		return;
-	bool ok;
-	QString sCopy = s;
-	uint hexColor = sCopy.remove( 0, 1 ).toUInt( &ok, 16 );
-	if (ok) {
-		if (sCopy.length() == 8)
-			color.setRgba( hexColor );
-		else {
-			color.setRgb( hexColor );
-			if (!a.isNull())
-				color.setAlpha( int(a.toFloat() * 255) );
-		}
-	}
-}
-
-void
 KdmItem::setBoxLayout( const QDomNode &node )
 {
 	if (!boxManager)
--- trunk/KDE/kdebase/workspace/kdm/kfrontend/themer/kdmitem.h #590774:590775
@@ -22,6 +22,8 @@
 #ifndef KDMITEM_H
 #define KDMITEM_H
 
+#include "parse.h"
+
 #include <QObject>
 #include <QStack>
 #include <QRect>
@@ -217,11 +219,6 @@
 	bool isButton;
 
 	// This struct is filled in by KdmItem base class
-	enum DataType { DTnone, DTpixel, DTnpixel, DTpercent, DTbox, DTscale };
-	struct DataPoint {
-		int val, levels;
-		DataType type;
-	};
 	struct DataPair {
 		DataPoint x, y;
 	};
@@ -248,14 +245,6 @@
 
 	void activateBuddy();
 
-	/* For internal use ONLY
-	 * Parse type and value of an attribute (pos tag), a font or a
-	 * color.
-	 */
-	void parseAttribute( const QString &, DataPoint & );
-	void parseFont( const QString &, QFont & );
-	void parseColor( const QString &col, const QString &a, QColor & );
-
 	QString itemType, id;
 	QList<KdmItem *> m_children;
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic