filters

ImportHelpers.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Nicolas GOUTTE <goutte@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qstringlist.h>
00021 #include <qregexp.h>
00022 
00023 #include <kdebug.h>
00024 
00025 #include "ImportHelpers.h"
00026 
00027 bool AbiPropsMap::setProperty(const QString& newName, const QString& newValue)
00028 {
00029     replace(newName,AbiProps(newValue));
00030     return true;
00031 }
00032 
00033 // Treat the "props" attribute of AbiWord's tags and split it in separates names and values
00034 void AbiPropsMap::splitAndAddAbiProps(const QString& strProps)
00035 {
00036     if (strProps.isEmpty())
00037         return;
00038     // Split the properties (we do not want empty ones)
00039     QStringList list=QStringList::split(';',strProps,false);
00040     QString name,value;
00041 
00042     QStringList::ConstIterator it;
00043     QStringList::ConstIterator end(list.end());
00044     for (it=list.begin();it!=end;++it)
00045     {
00046         const int result=(*it).find(':');
00047         if (result==-1)
00048         {
00049             name=(*it);
00050             value=QString::null;
00051             kdWarning(30506) << "Property without value: " << name << endl;
00052         }
00053         else
00054         {
00055             name=(*it).left(result);
00056             value=(*it).mid(result+1);
00057         }
00058         // kdDebug(30506) << "========== (Property :" << name.stripWhiteSpace()<< "=" << value.stripWhiteSpace() <<":)"<<endl;
00059         // Now set the property
00060         setProperty(name.stripWhiteSpace(),value.stripWhiteSpace());
00061     }
00062 }
00063 
00064 double ValueWithLengthUnit( const QString& _str, bool* atleast )
00065 {
00066     if ( atleast )
00067         *atleast = false;
00068     
00069     double result;
00070     // We search an unit (defined by a sequence of lower case characters), with possibly a + sign after it
00071     QRegExp unitExp("([a-z]+)\\s*(\\+?)");
00072     const int pos=unitExp.search(_str);
00073     if (pos==-1)
00074     {
00075         bool flag=false;
00076         result=_str.toDouble(&flag);
00077         if (!flag)
00078             kdWarning(30506) << "Unknown value: " << _str << " (ValueWithLengthUnit)" << endl;
00079     }
00080     else
00081     {
00082         const double rawValue=_str.left(pos).toDouble();
00083         const QString strUnit ( unitExp.cap(1) );
00084         if (strUnit=="cm")
00085             result=CentimetresToPoints(rawValue);
00086         else if (strUnit=="in")
00087             result=InchesToPoints(rawValue);
00088         else if (strUnit=="mm")
00089             result=MillimetresToPoints(rawValue);
00090         else if (strUnit=="pt")
00091             result=rawValue;
00092         else if(strUnit=="pi")
00093             result=PicaToPoints(rawValue);
00094         else
00095         {
00096             kdWarning(30506) << "Value " << _str << " has non-supported unit: "
00097                 << strUnit << " (ValueWithLengthUnit)" << endl;
00098             result=rawValue;
00099         }
00100         
00101         if ( atleast )
00102         {
00103             *atleast = ( unitExp.cap(2) == "+" );
00104         }
00105 
00106         // kdDebug(30506) << "Value: " << _str << " Unit: " << strUnit << " Result: " << result << endl;
00107     }
00108     return result;
00109 }
KDE Home | KDE Accessibility Home | Description of Access Keys