summaryrefslogtreecommitdiffstats
path: root/src/tools.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools.cpp')
-rw-r--r--src/tools.cpp234
1 files changed, 117 insertions, 117 deletions
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 <kdebug.h>
-#include <qstring.h>
-#include <qpixmap.h>
-#include <qimage.h>
-#include <qstylesheet.h>
-#include <qregexp.h>
-#include <qvaluestack.h>
-#include <qfileinfo.h>
-#include <qdir.h>
-#include <qmime.h>
-#include <qfont.h>
-#include <qfontinfo.h>
-#include <qobjectlist.h>
+#include <tqstring.h>
+#include <tqpixmap.h>
+#include <tqimage.h>
+#include <tqstylesheet.h>
+#include <tqregexp.h>
+#include <tqvaluestack.h>
+#include <tqfileinfo.h>
+#include <tqdir.h>
+#include <tqmime.h>
+#include <tqfont.h>
+#include <tqfontinfo.h>
+#include <tqobjectlist.h>
#include "tools.h"
-QMemArray<QTime> StopWatch::starts;
-QMemArray<double> StopWatch::totals;
-QMemArray<uint> StopWatch::counts;
+TQMemArray<TQTime> StopWatch::starts;
+TQMemArray<double> StopWatch::totals;
+TQMemArray<uint> 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 "<p></p>";
if (/*text.isEmpty() ||*/ text == " " || text == "&nbsp;")
return "<p>&nbsp;</p>";
- // convertFromPlainText() replace "\n\n" by "</p>\n<p>": we don't want that
- QString htmlString = QStyleSheet::convertFromPlainText(text, QStyleSheetItem::WhiteSpaceNormal);
- return htmlString.replace("</p>\n", "<br>\n<br>\n").replace("\n<p>", "\n"); // Don't replace first and last tags
+ // convertFromPlainText() tqreplace "\n\n" by "</p>\n<p>": we don't want that
+ TQString htmlString = TQStyleSheet::convertFromPlainText(text, TQStyleSheetItem::WhiteSpaceNormal);
+ return htmlString.tqreplace("</p>\n", "<br>\n<br>\n").tqreplace("\n<p>", "\n"); // Don't replace first and last tags
}
-QString Tools::textToHTMLWithoutP(const QString &text)
+TQString Tools::textToHTMLWithoutP(const TQString &text)
{
// textToHTML(text) return "<p>HTMLizedText</p>". We remove the strating "<p>" and ending </p>"
- 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 <html> start tag, all the <head> and the <body> start
// Because <body> can contain style="..." parameter, we transform it to <span>
- int pos = result.find("<body");
+ int pos = result.tqfind("<body");
if (pos != -1) {
result = "<span" + result.mid(pos + 5);
startedBySpan = true;
@@ -96,76 +96,76 @@ QString Tools::htmlToParagraph(const QString &html)
// Remove the ending "</p>\n</body></html>", each tag can be separated by space characters (%s)
// "</p>" can be omitted (eg. if the HTML doesn't contain paragraph but tables), as well as "</body>" (optinal)
- pos = result.find(QRegExp("(?:(?:</p>[\\s\\n\\r\\t]*)*</body>[\\s\\n\\r\\t]*)*</html>", false)); // Case unsensitive
+ pos = result.tqfind(TQRegExp("(?:(?:</p>[\\s\\n\\r\\t]*)*</body>[\\s\\n\\r\\t]*)*</html>", false)); // Case unsensitive
if (pos != -1)
result = result.left(pos);
if (startedBySpan)
result += "</span>";
- return result.replace("</p>", "<br><br>").replace("<p>", "");
+ return result.tqreplace("</p>", "<br><br>").tqreplace("<p>", "");
}
// 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 = "<a href=\"" + href + "\">" + href + "</a>";
- richText.replace(urlPos, urlLen, anchor);
+ TQString anchor = "<a href=\"" + href + "\">" + href + "</a>";
+ 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("</h1>", "\n");
- text.replace("</h2>", "\n");
- text.replace("</h3>", "\n");
- text.replace("</h4>", "\n");
- text.replace("</h5>", "\n");
- text.replace("</h6>", "\n");
- text.replace("</li>", "\n");
- text.replace("</dt>", "\n");
- text.replace("</dd>", "\n");
- text.replace("<dd>", " ");
- text.replace("</div>","\n");
- text.replace("</blockquote>","\n");
- text.replace("</caption>","\n");
- text.replace("</tr>", "\n");
- text.replace("</th>", " ");
- text.replace("</td>", " ");
- text.replace("<br>", "\n");
- text.replace("<br />","\n");
+ text.tqreplace("</h1>", "\n");
+ text.tqreplace("</h2>", "\n");
+ text.tqreplace("</h3>", "\n");
+ text.tqreplace("</h4>", "\n");
+ text.tqreplace("</h5>", "\n");
+ text.tqreplace("</h6>", "\n");
+ text.tqreplace("</li>", "\n");
+ text.tqreplace("</dt>", "\n");
+ text.tqreplace("</dd>", "\n");
+ text.tqreplace("<dd>", " ");
+ text.tqreplace("</div>","\n");
+ text.tqreplace("</blockquote>","\n");
+ text.tqreplace("</caption>","\n");
+ text.tqreplace("</tr>", "\n");
+ text.tqreplace("</th>", " ");
+ text.tqreplace("</td>", " ");
+ text.tqreplace("<br>", "\n");
+ text.tqreplace("<br />","\n");
// FIXME: Format <table> tags better, if possible
// TODO: Replace &eacute; 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<bool> ul; // true if current list is a <ul> one, false if it's an <ol> one
- QValueStack<int> lines; // The line number if it is an <ol> list
+ TQValueStack<bool> ul; // true if current list is a <ul> one, false if it's an <ol> one
+ TQValueStack<int> lines; // The line number if it is an <ol> 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("&gt;", ">");
- text.replace("&lt;", "<");
- text.replace("&quot;", "\"");
- text.replace("&nbsp;", " ");
- text.replace("&amp;", "&"); // CONVERT IN LAST!!
+ text.tqreplace("&gt;", ">");
+ text.tqreplace("&lt;", "<");
+ text.tqreplace("&quot;", "\"");
+ text.tqreplace("&nbsp;", " ");
+ text.tqreplace("&amp;", "&"); // 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 <iostream>
-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;