From aa0726b20f398264f0a2abc60215be044b106f9c Mon Sep 17 00:00:00 2001 From: tpearson Date: Tue, 17 May 2011 08:20:48 +0000 Subject: TQt4 port basket This enables compilation under both Qt3 and Qt4 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/basket@1232416 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/tools.cpp | 234 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 117 insertions(+), 117 deletions(-) (limited to 'src/tools.cpp') diff --git a/src/tools.cpp b/src/tools.cpp index 9acbda7..2d3cce7 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -19,24 +19,24 @@ ***************************************************************************/ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "tools.h" -QMemArray StopWatch::starts; -QMemArray StopWatch::totals; -QMemArray StopWatch::counts; +TQMemArray StopWatch::starts; +TQMemArray StopWatch::totals; +TQMemArray StopWatch::counts; void StopWatch::start(uint id) { @@ -49,46 +49,46 @@ void StopWatch::start(uint id) } starts.resize(id + 1); } - starts[id] = QTime::currentTime(); + starts[id] = TQTime::currentTime(); } void StopWatch::check(uint id) { if (id >= starts.size()) return; - double time = starts[id].msecsTo(QTime::currentTime()) / 1000.0; + double time = starts[id].msecsTo(TQTime::currentTime()) / 1000.0; totals[id] += time; counts[id]++; kdDebug() << k_funcinfo << "Timer_" << id << ": " << time << " s [" << counts[id] << " times, total: " << totals[id] << " s, average: " << totals[id] / counts[id] << " s]" << endl; } -QString Tools::textToHTML(const QString &text) +TQString Tools::textToHTML(const TQString &text) { if (text.isEmpty()) return "

"; if (/*text.isEmpty() ||*/ text == " " || text == " ") return "

 

"; - // convertFromPlainText() replace "\n\n" by "

\n

": we don't want that - QString htmlString = QStyleSheet::convertFromPlainText(text, QStyleSheetItem::WhiteSpaceNormal); - return htmlString.replace("

\n", "
\n
\n").replace("\n

", "\n"); // Don't replace first and last tags + // convertFromPlainText() tqreplace "\n\n" by "

\n

": we don't want that + TQString htmlString = TQStyleSheet::convertFromPlainText(text, TQStyleSheetItem::WhiteSpaceNormal); + return htmlString.tqreplace("

\n", "
\n
\n").tqreplace("\n

", "\n"); // Don't replace first and last tags } -QString Tools::textToHTMLWithoutP(const QString &text) +TQString Tools::textToHTMLWithoutP(const TQString &text) { // textToHTML(text) return "

HTMLizedText

". We remove the strating "

" and ending

" - QString HTMLizedText = textToHTML(text); + TQString HTMLizedText = textToHTML(text); return HTMLizedText.mid(3, HTMLizedText.length() - 3 - 4); } -QString Tools::htmlToParagraph(const QString &html) +TQString Tools::htmlToParagraph(const TQString &html) { - QString result = html; + TQString result = html; bool startedBySpan = false; // Remove the start tag, all the and the start // Because can contain style="..." parameter, we transform it to - int pos = result.find("\n", each tag can be separated by space characters (%s) // "

" can be omitted (eg. if the HTML doesn't contain paragraph but tables), as well as "" (optinal) - pos = result.find(QRegExp("(?:(?:

[\\s\\n\\r\\t]*)*[\\s\\n\\r\\t]*)*", false)); // Case unsensitive + pos = result.tqfind(TQRegExp("(?:(?:

[\\s\\n\\r\\t]*)*[\\s\\n\\r\\t]*)*", false)); // Case unsensitive if (pos != -1) result = result.left(pos); if (startedBySpan) result += "
"; - return result.replace("

", "

").replace("

", ""); + return result.tqreplace("

", "

").tqreplace("

", ""); } // The following is adapted from KStringHanlder::tagURLs // The adaptation lies in the change to urlEx // Thanks to Richard Heck -QString Tools::tagURLs(const QString &text) +TQString Tools::tagURLs(const TQString &text) { - QRegExp urlEx("(www\\.(?!\\.)|([a-zA-z]+)://)[\\d\\w\\./,:_~\\?=&;#@\\-\\+\\%\\$]+[\\d\\w/]"); + TQRegExp urlEx("(www\\.(?!\\.)|([a-zA-z]+)://)[\\d\\w\\./,:_~\\?=&;#@\\-\\+\\%\\$]+[\\d\\w/]"); - QString richText(text); + TQString richText(text); int urlPos = 0; int urlLen; while ((urlPos = urlEx.search(richText, urlPos)) >= 0) { urlLen = urlEx.matchedLength(); - QString href = richText.mid(urlPos, urlLen); - // Qt doesn't support (?<=pattern) so we do it here + TQString href = richText.mid(urlPos, urlLen); + // TQt doesn't support (?<=pattern) so we do it here if ((urlPos > 0) && richText[urlPos-1].isLetterOrNumber()) { urlPos++; continue; } - QString anchor = "" + href + ""; - richText.replace(urlPos, urlLen, anchor); + TQString anchor = "" + href + ""; + richText.tqreplace(urlPos, urlLen, anchor); urlPos += anchor.length(); } return richText; } -QString Tools::htmlToText(const QString &html) +TQString Tools::htmlToText(const TQString &html) { - QString text = htmlToParagraph(html); + TQString text = htmlToParagraph(html); text.remove("\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("", "\n"); - text.replace("

", " "); - text.replace("","\n"); - text.replace("","\n"); - text.replace("","\n"); - text.replace("", "\n"); - text.replace("", " "); - text.replace("", " "); - text.replace("
", "\n"); - text.replace("
","\n"); + text.tqreplace("", "\n"); + text.tqreplace("", "\n"); + text.tqreplace("", "\n"); + text.tqreplace("", "\n"); + text.tqreplace("", "\n"); + text.tqreplace("", "\n"); + text.tqreplace("", "\n"); + text.tqreplace("", "\n"); + text.tqreplace("
", "\n"); + text.tqreplace("
", " "); + text.tqreplace("","\n"); + text.tqreplace("","\n"); + text.tqreplace("","\n"); + text.tqreplace("", "\n"); + text.tqreplace("", " "); + text.tqreplace("", " "); + text.tqreplace("
", "\n"); + text.tqreplace("
","\n"); // FIXME: Format tags better, if possible // TODO: Replace é and co. by theire equivalent! // To manage tags: int pos = 0; int pos2; - QString tag, tag3; + TQString tag, tag3; // To manage lists: int deep = 0; // The deep of the current line in imbriqued lists - QValueStack ul; // true if current list is a
    one, false if it's an
      one - QValueStack lines; // The line number if it is an
        list + TQValueStack ul; // true if current list is a
          one, false if it's an
            one + TQValueStack lines; // The line number if it is an
              list // We're removing every other tags, or replace them in the case of li: - while ( (pos = text.find("<"), pos) != -1 ) { + while ( (pos = text.tqfind("<"), pos) != -1 ) { // What is the current tag? tag = text.mid(pos + 1, 2); tag3 = text.mid(pos + 1, 3); @@ -184,21 +184,21 @@ QString Tools::htmlToText(const QString &html) lines.pop(); } // Where the tag closes? - pos2 = text.find(">"); + pos2 = text.tqfind(">"); if (pos2 != -1) { // Remove the tag: text.remove(pos, pos2 - pos + 1); // And replace li with "* ", "x. "... without forbidding to indent that: if (tag == "li") { // How many spaces before the line (indentation): - QString spaces = ""; + TQString spaces = ""; for (int i = 1; i < deep; i++) spaces += " "; // The bullet or number of the line: - QString bullet = "* "; + TQString bullet = "* "; if (ul.top() == false) { lines.push(lines.pop() + 1); - bullet = QString::number(lines.top()) + ". "; + bullet = TQString::number(lines.top()) + ". "; } // Insertion: text.insert(pos, spaces + bullet); @@ -209,36 +209,36 @@ QString Tools::htmlToText(const QString &html) ++pos; } - text.replace(">", ">"); - text.replace("<", "<"); - text.replace(""", "\""); - text.replace(" ", " "); - text.replace("&", "&"); // CONVERT IN LAST!! + text.tqreplace(">", ">"); + text.tqreplace("<", "<"); + text.tqreplace(""", "\""); + text.tqreplace(" ", " "); + text.tqreplace("&", "&"); // CONVERT IN LAST!! return text; } -QString Tools::cssFontDefinition(const QFont &font, bool onlyFontFamily) +TQString Tools::cssFontDefinition(const TQFont &font, bool onlyFontFamily) { // The font definition: - QString definition = QString(font.italic() ? "italic " : "") + - QString(font.bold() ? "bold " : "") + - QString::number(QFontInfo(font).pixelSize()) + "px "; + TQString definition = TQString(font.italic() ? "italic " : "") + + TQString(font.bold() ? "bold " : "") + + TQString::number(TQFontInfo(font).pixelSize()) + "px "; // Then, try to match the font name with a standard CSS font family: - QString genericFont = ""; - if (definition.contains("serif", false) || definition.contains("roman", false)) + TQString genericFont = ""; + if (definition.tqcontains("serif", false) || definition.tqcontains("roman", false)) genericFont = "serif"; // No "else if" because "sans serif" must be counted as "sans". So, the order between "serif" and "sans" is important - if (definition.contains("sans", false) || definition.contains("arial", false) || definition.contains("helvetica", false)) + if (definition.tqcontains("sans", false) || definition.tqcontains("arial", false) || definition.tqcontains("helvetica", false)) genericFont = "sans-serif"; - if (definition.contains("mono", false) || definition.contains("courier", false) || - definition.contains("typewriter", false) || definition.contains("console", false) || - definition.contains("terminal", false) || definition.contains("news", false)) + if (definition.tqcontains("mono", false) || definition.tqcontains("courier", false) || + definition.tqcontains("typewriter", false) || definition.tqcontains("console", false) || + definition.tqcontains("terminal", false) || definition.tqcontains("news", false)) genericFont = "monospace"; // Eventually add the generic font family to the definition: - QString fontDefinition = "\"" + font.family() + "\""; + TQString fontDefinition = "\"" + font.family() + "\""; if (!genericFont.isEmpty()) fontDefinition += ", " + genericFont; @@ -248,7 +248,7 @@ QString Tools::cssFontDefinition(const QFont &font, bool onlyFontFamily) return definition + fontDefinition; } -QString Tools::stripEndWhiteSpaces(const QString &string) +TQString Tools::stripEndWhiteSpaces(const TQString &string) { uint length = string.length(); uint i; @@ -263,7 +263,7 @@ QString Tools::stripEndWhiteSpaces(const QString &string) -bool Tools::isWebColor(const QColor &color) +bool Tools::isWebColor(const TQColor &color) { int r = color.red(); // The 216 web colors are those colors whose RGB (Red, Green, Blue) int g = color.green(); // values are all in the set (0, 51, 102, 153, 204, 255). @@ -277,25 +277,25 @@ bool Tools::isWebColor(const QColor &color) b == 153 || b == 204 || b == 255 ) ); } -QColor Tools::mixColor(const QColor &color1, const QColor &color2) +TQColor Tools::mixColor(const TQColor &color1, const TQColor &color2) { - QColor mixedColor; + TQColor mixedColor; mixedColor.setRgb( (color1.red() + color2.red()) / 2, (color1.green() + color2.green()) / 2, (color1.blue() + color2.blue()) / 2 ); return mixedColor; } -bool Tools::tooDark(const QColor &color) +bool Tools::tooDark(const TQColor &color) { int dontCare, value; - color.getHsv(/*hue:*/dontCare, /*saturation:*/dontCare, value); + color.getHsv(/*hue:*/&dontCare, /*saturation:*/&dontCare, &value); return value < 175; } // TODO: Use it for all indentPixmap() -QPixmap Tools::normalizePixmap(const QPixmap &pixmap, int width, int height) +TQPixmap Tools::normalizePixmap(const TQPixmap &pixmap, int width, int height) { if (height <= 0) height = width; @@ -306,7 +306,7 @@ QPixmap Tools::normalizePixmap(const QPixmap &pixmap, int width, int height) return pixmap; } -QPixmap Tools::indentPixmap(const QPixmap &source, int depth, int deltaX) +TQPixmap Tools::indentPixmap(const TQPixmap &source, int depth, int deltaX) { // Verify if it is possible: if (depth <= 0 || source.isNull()) @@ -318,8 +318,8 @@ QPixmap Tools::indentPixmap(const QPixmap &source, int depth, int deltaX) int indent = depth * deltaX; // Create the images: - QImage resultImage(indent + source.width(), source.height(), 32); - QImage sourceImage = source.convertToImage(); + TQImage resultImage(indent + source.width(), source.height(), 32); + TQImage sourceImage = source.convertToImage(); resultImage.setAlphaBuffer(true); // Clear the indent part (the left part) by making it fully transparent: @@ -327,7 +327,7 @@ QPixmap Tools::indentPixmap(const QPixmap &source, int depth, int deltaX) for (int row = 0; row < resultImage.height(); ++row) { for (int column = 0; column < resultImage.width(); ++column) { p = (uint *)resultImage.scanLine(row) + column; - *p = 0; // qRgba(0, 0, 0, 0) + *p = 0; // tqRgba(0, 0, 0, 0) } } @@ -342,49 +342,49 @@ QPixmap Tools::indentPixmap(const QPixmap &source, int depth, int deltaX) } // And return the result: - QPixmap result; + TQPixmap result; result.convertFromImage(resultImage); return result; } #include -void Tools::deleteRecursively(const QString &folderOrFile) +void Tools::deleteRecursively(const TQString &folderOrFile) { if (folderOrFile.isEmpty()) return; - QFileInfo fileInfo(folderOrFile); + TQFileInfo fileInfo(folderOrFile); if (fileInfo.isDir()) { // Delete the child files: - QDir dir(folderOrFile, QString::null, QDir::Name | QDir::IgnoreCase, QDir::All | QDir::Hidden); - QStringList list = dir.entryList(); - for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) + TQDir dir(folderOrFile, TQString(), TQDir::Name | TQDir::IgnoreCase, TQDir::All | TQDir::Hidden); + TQStringList list = dir.entryList(); + for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) if ( *it != "." && *it != ".." ) deleteRecursively(folderOrFile + "/" + *it); // And then delete the folder: dir.rmdir(folderOrFile); } else // Delete the file: - QFile::remove(folderOrFile); + TQFile::remove(folderOrFile); } -QString Tools::fileNameForNewFile(const QString &wantedName, const QString &destFolder) +TQString Tools::fileNameForNewFile(const TQString &wantedName, const TQString &destFolder) { - QString fileName = wantedName; - QString fullName = destFolder + fileName; - QString extension = ""; + TQString fileName = wantedName; + TQString fullName = destFolder + fileName; + TQString extension = ""; int number = 2; - QDir dir; + TQDir dir; // First check if the file do not exists yet (simplier and more often case) - dir = QDir(fullName); + dir = TQDir(fullName); if ( ! dir.exists(fullName) ) return fileName; // Find the file extension, if it exists : Split fileName in fileName and extension // Example : fileName == "note5-3.txt" => fileName = "note5-3" and extension = ".txt" - int extIndex = fileName.findRev('.'); + int extIndex = fileName.tqfindRev('.'); if (extIndex != -1 && extIndex != int(fileName.length()-1)) { // Extension found and fileName do not ends with '.' ! extension = fileName.mid(extIndex); fileName.truncate(extIndex); @@ -392,7 +392,7 @@ QString Tools::fileNameForNewFile(const QString &wantedName, const QString &dest // Find the file number, if it exists : Split fileName in fileName and number // Example : fileName == "note5-3" => fileName = "note5" and number = 3 - int extNumber = fileName.findRev('-'); + int extNumber = fileName.tqfindRev('-'); if (extNumber != -1 && extNumber != int(fileName.length()-1)) { // Number found and fileName do not ends with '-' ! bool isANumber; int theNumber = fileName.mid(extNumber + 1).toInt(&isANumber); @@ -402,11 +402,11 @@ QString Tools::fileNameForNewFile(const QString &wantedName, const QString &dest } // else : } // else fileName = fileName and number = 2 (because if the file already exists, the genereated name is at last the 2nd) - QString finalName; + TQString finalName; for (/*int number = 2*/; ; ++number) { // TODO: FIXME: If overflow ??? - finalName = fileName + "-" + QString::number(number) + extension; + finalName = fileName + "-" + TQString::number(number) + extension; fullName = destFolder + finalName; - dir = QDir(fullName); + dir = TQDir(fullName); if ( ! dir.exists(fullName) ) break; } @@ -416,28 +416,28 @@ QString Tools::fileNameForNewFile(const QString &wantedName, const QString &dest // TODO: Move it from NoteFactory -/*QString NoteFactory::iconForURL(const KURL &url) +/*TQString NoteFactory::iconForURL(const KURL &url) { - QString icon = KMimeType::iconForURL(url.url()); + TQString icon = KMimeType::iconForURL(url.url()); if ( url.protocol() == "mailto" ) icon = "message"; return icon; }*/ -bool Tools::isAFileCut(QMimeSource *source) +bool Tools::isAFileCut(TQMimeSource *source) { if (source->provides("application/x-kde-cutselection")) { - QByteArray array = source->encodedData("application/x-kde-cutselection"); - return !array.isEmpty() && QCString(array.data(), array.size() + 1).at(0) == '1'; + TQByteArray array = source->tqencodedData("application/x-kde-cutselection"); + return !array.isEmpty() && TQCString(array.data(), array.size() + 1).at(0) == '1'; } else return false; } -void Tools::printChildren(QObject* parent) +void Tools::printChildren(TQObject* tqparent) { - const QObjectList* objs = parent->children(); - QObjectListIt it(*objs); - QObject *obj; + const TQObjectList objs = tqparent->childrenListObject(); + TQObjectListIt it(objs); + TQObject *obj; while((obj = it.current())!= 0){ ++it; -- cgit v1.2.1