summaryrefslogtreecommitdiff
path: root/src/util/tool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/tool.cpp')
-rw-r--r--src/util/tool.cpp185
1 files changed, 66 insertions, 119 deletions
diff --git a/src/util/tool.cpp b/src/util/tool.cpp
index 8e8bb00..b8ee486 100644
--- a/src/util/tool.cpp
+++ b/src/util/tool.cpp
@@ -2,7 +2,7 @@
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2008 by the BibleTime developers.
+* Copyright 1999-2011 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
@@ -23,29 +23,6 @@
#include "util/dialogutil.h"
-/** Converts HTML text to plain text */
-QString util::tool::htmlToText(const QString& html) {
- QString newText = html;
- // convert some tags we need in code
- newText.replace( QRegExp(" "), "#SPACE#" );
- newText.replace( QRegExp("<br\\s*/?>\\s*"), "<br/>\n" );
- newText.replace( QRegExp("#SPACE#"), " " );
-
- QRegExp re("<.+>");
- re.setMinimal(true);
- newText.replace( re, "" );
- return newText;
-}
-
-/** Converts text to HTML (\n to <br/>) */
-QString util::tool::textToHTML(const QString& text) {
- QString newText = text;
- newText.replace( QRegExp("<br\\s*/?>\n"), "#NEWLINE#" );
- newText.replace( QRegExp("\n"), "<br/>\n" );
- newText.replace( QRegExp("#NEWLINE#"), "<br/>\n");
- return newText;
-}
-
/** Creates the file filename and put text into the file.
*/
bool util::tool::savePlainFile( const QString& filename, const QString& text, const bool& forceOverwrite, QTextCodec* fileCodec) {
@@ -86,45 +63,43 @@ bool util::tool::savePlainFile( const QString& filename, const QString& text, co
}
-/** Returns the icon used for the module given as aparameter. */
-QIcon util::tool::getIconForModule( CSwordModuleInfo* module_info ) {
+QIcon util::tool::getIconForModule(const CSwordModuleInfo *module) {
namespace DU = util::directory;
- return DU::getIcon(getIconNameForModule(module_info));
+ return DU::getIcon(getIconNameForModule(module));
}
-/** Returns the name for the icon used for the module given as aparameter. */
-QString util::tool::getIconNameForModule( CSwordModuleInfo* module_info ) {
+QString util::tool::getIconNameForModule(const CSwordModuleInfo *module) {
//qDebug() << "util::tool::getIconNameForModule";
- if (!module_info) return CResMgr::modules::book::icon_locked;
+ if (!module) return CResMgr::modules::book::icon_locked;
- if (module_info->category() == CSwordModuleInfo::Cult) {
+ if (module->category() == CSwordModuleInfo::Cult) {
return "stop.svg";
}
- switch (module_info->type()) {
+ switch (module->type()) {
case CSwordModuleInfo::Bible:
- if (module_info->isLocked())
+ if (module->isLocked())
return CResMgr::modules::bible::icon_locked;
else
return CResMgr::modules::bible::icon_unlocked;
break;
case CSwordModuleInfo::Lexicon:
- if (module_info->isLocked())
+ if (module->isLocked())
return CResMgr::modules::lexicon::icon_locked;
else
return CResMgr::modules::lexicon::icon_unlocked;
break;
case CSwordModuleInfo::Commentary:
- if (module_info->isLocked())
+ if (module->isLocked())
return CResMgr::modules::commentary::icon_locked;
else
return CResMgr::modules::commentary::icon_unlocked;
break;
case CSwordModuleInfo::GenericBook:
- if (module_info->isLocked())
+ if (module->isLocked())
return CResMgr::modules::book::icon_locked;
else
return CResMgr::modules::book::icon_unlocked;
@@ -132,7 +107,7 @@ QString util::tool::getIconNameForModule( CSwordModuleInfo* module_info ) {
case CSwordModuleInfo::Unknown: //fallback
default:
- if (module_info->isLocked())
+ if (module->isLocked())
return CResMgr::modules::book::icon_locked;
else
return CResMgr::modules::book::icon_unlocked;
@@ -141,17 +116,31 @@ QString util::tool::getIconNameForModule( CSwordModuleInfo* module_info ) {
return CResMgr::modules::book::icon_unlocked;
}
-QLabel* util::tool::explanationLabel(QWidget* parent, const QString& heading, const QString& text ) {
- QString br;
+QLabel* util::tool::explanationLabel(QWidget *parent, const QString &heading, const QString &text) {
+ QLabel *label = new QLabel(parent);
+ initExplanationLabel(label, heading, text);
+ return label;
+}
+
+void util::tool::initExplanationLabel(QLabel *label, const QString &heading, const QString &text) {
+ QString labelText;
+ if (!heading.isEmpty()) {
+ labelText += "<b>";
+ labelText += heading;
+ labelText += "</b>";
+ }
if (!heading.isEmpty() && !text.isEmpty()) {
- br = QString::fromLatin1("<span style='white-space:pre'> - </span>");
+ labelText += "<span style=\"white-space:pre\"> - </span>";
}
- QLabel* label = new QLabel( QString::fromLatin1("<b>%1</b>%2<small>%3</small>").arg(heading).arg(br).arg(text), parent );
-
+ if (!text.isEmpty()) {
+ labelText += "<small>";
+ labelText += text;
+ labelText += "</small>";
+ }
+ label->setText(labelText);
label->setWordWrap(true);
label->setMargin(1);
label->setFrameStyle(QFrame::Box | QFrame::Sunken);
- return label;
}
/** No descriptions */
@@ -176,99 +165,57 @@ bool util::tool::inHTMLTag(int pos, QString & text) {
return false;
}
-QString util::tool::moduleToolTip(CSwordModuleInfo* module) {
- Q_ASSERT(module);
- if (!module) {
- return QString::null;
- }
-
- QString text;
-
- text = QString("<b>%1</b> ").arg( module->name() )
- + ((module->category() == CSwordModuleInfo::Cult) ? QString::fromLatin1("<small><b>%1</b></small><br/>").arg(QObject::tr("Take care, this work contains cult / questionable material!")) : QString::null);
+QString util::tool::remoteModuleToolTip(const CSwordModuleInfo &module,
+ const QString &localVer)
+{
+ QString text = "<p style='white-space:pre'><b>";
+ text += module.name();
+ text += "</b> ";
- text += QString("<small>(") + module->config(CSwordModuleInfo::Description) + QString(")</small><hr>");
-
- text += QObject::tr("Language") + QString(": %1<br/>").arg( module->language()->translatedName() );
-
- if (module->isEncrypted()) {
- text += QObject::tr("Unlock key") + QString(": %1<br/>")
- .arg(!module->config(CSwordModuleInfo::CipherKey).isEmpty() ? module->config(CSwordModuleInfo::CipherKey) : QString("<font COLOR=\"red\">%1</font>").arg(QObject::tr("not set")));
+ if (module.category() == CSwordModuleInfo::Cult) {
+ text += "<small><b>";
+ text += QObject::tr("Take care, this work contains cult / questionable "
+ "material!");
+ text += "</b></small><br/>";
}
- if (module->hasVersion()) {
- text += QObject::tr("Version") + QString(": %1<br/>").arg( module->config(CSwordModuleInfo::ModuleVersion) );
- }
+ text += "<small>(";
+ text += module.config(CSwordModuleInfo::Description);
+ text += ")</small><hr/>";
- QString options;
- unsigned int opts;
- for (opts = CSwordModuleInfo::filterTypesMIN; opts <= CSwordModuleInfo::filterTypesMAX; ++opts) {
- if (module->has( static_cast<CSwordModuleInfo::FilterTypes>(opts) )) {
- if (!options.isEmpty()) {
- options += QString::fromLatin1(", ");
- }
-
- options += CSwordBackend::translatedOptionName(
- static_cast<CSwordModuleInfo::FilterTypes>(opts)
- );
- }
- }
-
- if (!options.isEmpty()) {
- text += QObject::tr("Options") + QString::fromLatin1(": <small>") + options + QString("</small>");
- }
-
- if (text.right(4) == QString::fromLatin1("<br/>")) {
- text = text.left(text.length() - 4);
- }
-
- return text;
-}
-
-QString util::tool::remoteModuleToolTip(CSwordModuleInfo* module, QString localVer) {
- Q_ASSERT(module);
- if (!module) {
- return QString::null;
- }
-
- QString text;
-
- text = QString("<p style='white-space:pre'><b>%1</b> ").arg( module->name() )
- + ((module->category() == CSwordModuleInfo::Cult) ? QString::fromLatin1("<small><b>%1</b></small><br/>").arg(QObject::tr("Take care, this work contains cult / questionable material!")) : QString::null);
-
- text += QString("<small>(") + module->config(CSwordModuleInfo::Description) + QString(")</small><hr/>");
-
- if (module->isEncrypted()) {
- text += QObject::tr("Encrypted - needs unlock key") + QString("<br/>");
+ if (module.isEncrypted()) {
+ text += QObject::tr("Encrypted - needs unlock key");
+ text += "<br/>";
}
if (!localVer.isEmpty()) {
- text += QString("<b>") + QObject::tr("Updated version available!") + QString("</b><br/>");
+ text += "<b>";
+ text += QObject::tr("Updated version available!");
+ text += "</b><br/>";
}
- if (module->hasVersion()) {
- text += QObject::tr("Version") + QString(": %1").arg( module->config(CSwordModuleInfo::ModuleVersion) );
+ if (module.hasVersion()) {
+ text += QObject::tr("Version");
+ text += ": ";
+ text += module.config(CSwordModuleInfo::ModuleVersion);
}
+
// if installed already
if (!localVer.isEmpty()) {
- text += QString(" ") + QObject::tr("Installed version") + QString(": %1").arg(localVer);
- }
- text += QString("<br/>");
-
- text += QString("<small>(") + QObject::tr("Double click for more information") + QString(")</small></p>");
-
-
- if (text.right(4) == QString::fromLatin1("<br/>")) {
- text = text.left(text.length() - 4);
+ text += " ";
+ text += QObject::tr("Installed version");
+ text += ": ";
+ text += localVer;
}
+ text += "<br/><small>(";
+ text += QObject::tr("Double click for more information");
+ text += ")</small></p>";
return text;
}
int util::tool::mWidth(const QWidget* widget, int m) {
- if (widget) {
- return widget->fontMetrics().width(QString().fill('M', m));
- }
- return QApplication::fontMetrics().width(QString().fill('M', m));
+ if (widget) return widget->fontMetrics().width(QString(m, 'M'));
+ return QApplication::fontMetrics().width(QString(m, 'M'));
}