15#include <QApplication>
19#include <QFontMetrics>
34 void (&writer)(QTextStream &,
void *),
39 QFile saveFile(filename);
41 if (saveFile.exists())
44 if (saveFile.open(QIODevice::ReadWrite)) {
45 QTextStream textstream(&saveFile);
46 writer(textstream, userPtr);
49 if (saveFile.error() == QFile::NoError)
52 QMessageBox::critical(
nullptr, QObject::tr(
"Error"),
53 QStringLiteral(
"<qt>%1<br/><b>%2</b></qt>")
54 .arg(QObject::tr(
"Error while writing to file."))
55 .arg(QObject::tr(
"Please check that enough disk space is available.")));
58 QMessageBox::critical(
nullptr, QObject::tr(
"Error"),
59 QStringLiteral(
"<qt>%1<br/><b>%2</b></qt>")
60 .arg(QObject::tr(
"The file couldn't be opened for saving."))
61 .arg(QObject::tr(
"Please check permissions etc.")));
71 struct UserData { QString
const & text; } userData{text};
72 static auto const writer =
73 +[](QTextStream & out,
void * textPtr)
74 { out << static_cast<const UserData *>(textPtr)->text; };
79 const QString & heading,
83 if (!heading.isEmpty())
84 labelText += QStringLiteral(
"<b>%1</b>").arg(heading);
86 if (!heading.isEmpty() && !text.isEmpty())
88 QStringLiteral(
"<span style=\"white-space:pre\"> - </span>");
91 labelText += QStringLiteral(
"<small>%1</small>").arg(text);
93 label->setText(labelText);
94 label->setWordWrap(
true);
96 label->setFrameStyle(QFrame::Box | QFrame::Sunken);
99bool inHTMLTag(
const int pos,
const QString & text) {
100 int i1 = text.lastIndexOf(
'<', pos);
101 int i2 = text.lastIndexOf(
'>', pos);
102 int i3 = text.indexOf(
'>', pos);
103 int i4 = text.indexOf(
'<', pos);
109 if ((i3 > 0) && (i4 == -1))
114 return (i1 > i2) && (i3 < i4);
118{
return widget.fontMetrics().horizontalAdvance(QString(mCount,
'M')); }
121 input.replace(
'_',
'-');