|
@@ -23,6 +23,9 @@
|
|
|
#include <QWebPage>
|
|
|
#include <QtDebug>
|
|
|
|
|
|
+#define XMLAutoFormatting
|
|
|
+//#define ImgTypePrint
|
|
|
+
|
|
|
//---------------------------------------------------------------------------
|
|
|
// FbSaveDialog
|
|
|
//---------------------------------------------------------------------------
|
|
@@ -42,7 +45,7 @@ FbSaveDialog::FbSaveDialog(QWidget *parent, const QString &caption, const QStrin
|
|
|
void FbSaveDialog::init()
|
|
|
{
|
|
|
QMap<QString, QString> codecMap;
|
|
|
- foreach (int mib, QTextCodec::availableMibs()) {
|
|
|
+ for (const int &mib: QTextCodec::availableMibs()) {
|
|
|
QTextCodec *codec = QTextCodec::codecForMib(mib);
|
|
|
|
|
|
QString sortKey = codec->name().toUpper();
|
|
@@ -71,7 +74,7 @@ void FbSaveDialog::init()
|
|
|
setNameFilters(filters);
|
|
|
|
|
|
combo = new QComboBox(this);
|
|
|
- foreach (QString codec, codecMap) {
|
|
|
+ for (const QString &codec: codecMap) {
|
|
|
combo->addItem(codec);
|
|
|
}
|
|
|
combo->setCurrentIndex(0);
|
|
@@ -86,7 +89,7 @@ void FbSaveDialog::init()
|
|
|
|
|
|
QString FbSaveDialog::fileName() const
|
|
|
{
|
|
|
- foreach (QString filename, selectedFiles()) {
|
|
|
+ for (const QString &filename: selectedFiles()) {
|
|
|
return filename;
|
|
|
}
|
|
|
return QString();
|
|
@@ -147,6 +150,9 @@ FbSaveWriter::FbSaveWriter(FbTextEdit &view, QByteArray *array)
|
|
|
if (QWebFrame * frame = m_view.page()->mainFrame()) {
|
|
|
m_style = frame->findFirstElement("html>head>style#origin").toPlainText();
|
|
|
}
|
|
|
+#ifdef XMLAutoFormatting
|
|
|
+ setAutoFormatting(true);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
FbSaveWriter::FbSaveWriter(FbTextEdit &view, QIODevice *device)
|
|
@@ -156,6 +162,9 @@ FbSaveWriter::FbSaveWriter(FbTextEdit &view, QIODevice *device)
|
|
|
, m_anchor(0)
|
|
|
, m_focus(0)
|
|
|
{
|
|
|
+#ifdef XMLAutoFormatting
|
|
|
+ setAutoFormatting(true);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
FbSaveWriter::FbSaveWriter(FbTextEdit &view, QString *string)
|
|
@@ -165,6 +174,9 @@ FbSaveWriter::FbSaveWriter(FbTextEdit &view, QString *string)
|
|
|
, m_anchor(0)
|
|
|
, m_focus(0)
|
|
|
{
|
|
|
+#ifdef XMLAutoFormatting
|
|
|
+ setAutoFormatting(true);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
void FbSaveWriter::writeComment(const QString &ch)
|
|
@@ -185,21 +197,29 @@ void FbSaveWriter::writeStartDocument()
|
|
|
|
|
|
void FbSaveWriter::writeStartElement(const QString &name, int level)
|
|
|
{
|
|
|
+#ifndef XMLAutoFormatting
|
|
|
+ Q_UNUSED(level)
|
|
|
if (level) writeLineEnd();
|
|
|
- for (int i = 1; i < level; i++) writeCharacters(" ");
|
|
|
+ for (int i = 1; i < level; ++i) writeCharacters(" ");
|
|
|
+#endif
|
|
|
QXmlStreamWriter::writeStartElement(name);
|
|
|
}
|
|
|
|
|
|
void FbSaveWriter::writeEndElement(int level)
|
|
|
{
|
|
|
+#ifndef XMLAutoFormatting
|
|
|
+ Q_UNUSED(level)
|
|
|
if (level) writeLineEnd();
|
|
|
- for (int i = 1; i < level; i++) writeCharacters(" ");
|
|
|
+ for (int i = 1; i < level; ++i) writeCharacters(" ");
|
|
|
+#endif
|
|
|
QXmlStreamWriter::writeEndElement();
|
|
|
}
|
|
|
|
|
|
void FbSaveWriter::writeLineEnd()
|
|
|
{
|
|
|
+#ifndef XMLAutoFormatting
|
|
|
writeCharacters("\n");
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
QByteArray FbSaveWriter::downloadFile(const QUrl &url)
|
|
@@ -255,8 +275,9 @@ void FbSaveWriter::writeStyle()
|
|
|
writeCharacters(postfix);
|
|
|
|
|
|
QStringList list = m_style.split("}", QString::SkipEmptyParts);
|
|
|
- foreach (const QString &str, list) {
|
|
|
- QString line = str.simplified();
|
|
|
+ QString line;
|
|
|
+ for (const QString &str: list) {
|
|
|
+ line = str.simplified();
|
|
|
if (line.isEmpty()) continue;
|
|
|
writeCharacters(" " + line + "}" + postfix);
|
|
|
}
|
|
@@ -299,6 +320,9 @@ void FbSaveWriter::writeContentType(const QString &name, QByteArray &data)
|
|
|
QBuffer buffer(&data);
|
|
|
buffer.open(QIODevice::ReadOnly);
|
|
|
QString type = QImageReader::imageFormat(&buffer);
|
|
|
+#ifdef ImgTypePrint
|
|
|
+ qCritical()<<"Img type: "<< type;
|
|
|
+#endif
|
|
|
if (type.isEmpty()) {
|
|
|
qCritical() << QObject::tr("Unknown image format: %1").arg(name);
|
|
|
return;
|
|
@@ -365,7 +389,7 @@ FbSaveHandler::TextHandler::TextHandler(TextHandler *parent, const QString &name
|
|
|
void FbSaveHandler::TextHandler::writeAtts(const QXmlAttributes &atts)
|
|
|
{
|
|
|
int count = atts.count();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
+ for (int i = 0; i < count; ++i) {
|
|
|
QString name = atts.qName(i);
|
|
|
QString value = atts.value(i);
|
|
|
if (m_tag == "image") {
|
|
@@ -470,7 +494,7 @@ FbSaveHandler::ParagHandler::ParagHandler(TextHandler *parent, const QString &na
|
|
|
, m_empty(true)
|
|
|
{
|
|
|
int count = atts.count();
|
|
|
- for (int i = 0; i < count; i++) {
|
|
|
+ for (int i = 0; i < count; ++i) {
|
|
|
QString qName = atts.qName(i);
|
|
|
QString value = atts.value(i);
|
|
|
if (qName == "fb:class") {
|