summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-03-26 13:09:26 (GMT)
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-03-26 13:09:26 (GMT)
commitc7d39e1335775979d43833d0b7f6c32cef898424 (patch)
treef19716b0a3b29ebf91457586d5323fd6c77f1a23 /src/tools
parent4fb6cae4dd0c6a90008780df606abb8a9e73cb2c (diff)
downloadQt-c7d39e1335775979d43833d0b7f6c32cef898424.zip
Qt-c7d39e1335775979d43833d0b7f6c32cef898424.tar.gz
Qt-c7d39e1335775979d43833d0b7f6c32cef898424.tar.bz2
uic3: -extract: Write XPM-images correctly.
Add magic header '/* XPM */' and turn off wrapping of lines that broke image readers. Add a command line option to activate line-wrapping in case someone exclusively wants to use the extracted images for embedding in code. Also do line-wrapping in case images are embedded into the ui-file. Note: The current versions of MSVC do not seem to have a limitation of line lengths any more. Task-number: QTBUG-9207 Reviewed-by: Jarek Kobus <jkobus@trolltech.com>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/uic/cpp/cppextractimages.cpp2
-rw-r--r--src/tools/uic/cpp/cppwriteicondata.cpp12
-rw-r--r--src/tools/uic/cpp/cppwriteicondata.h3
-rw-r--r--src/tools/uic/option.h2
-rw-r--r--src/tools/uic3/converter.cpp1
-rw-r--r--src/tools/uic3/form.cpp1
-rw-r--r--src/tools/uic3/main.cpp3
-rw-r--r--src/tools/uic3/ui3reader.h3
8 files changed, 20 insertions, 7 deletions
diff --git a/src/tools/uic/cpp/cppextractimages.cpp b/src/tools/uic/cpp/cppextractimages.cpp
index d452168..52c1b9d 100644
--- a/src/tools/uic/cpp/cppextractimages.cpp
+++ b/src/tools/uic/cpp/cppextractimages.cpp
@@ -134,7 +134,7 @@ void ExtractImages::acceptImage(DomImage *image)
QTextStream *imageOut = new QTextStream(&f);
imageOut->setCodec(QTextCodec::codecForName("UTF-8"));
- CPP::WriteIconData::writeImage(*imageOut, QString(), image);
+ CPP::WriteIconData::writeImage(*imageOut, QString(), m_option.limitXPM_LineLength, image);
delete imageOut;
} else {
CPP::WriteIconData::writeImage(f, image);
diff --git a/src/tools/uic/cpp/cppwriteicondata.cpp b/src/tools/uic/cpp/cppwriteicondata.cpp
index 81ef56b..7e4b5c8 100644
--- a/src/tools/uic/cpp/cppwriteicondata.cpp
+++ b/src/tools/uic/cpp/cppwriteicondata.cpp
@@ -114,10 +114,12 @@ void WriteIconData::acceptImages(DomImages *images)
void WriteIconData::acceptImage(DomImage *image)
{
- writeImage(output, option.indent, image);
+ // Limit line length when writing code.
+ writeImage(output, option.indent, true, image);
}
-void WriteIconData::writeImage(QTextStream &output, const QString &indent, DomImage *image)
+void WriteIconData::writeImage(QTextStream &output, const QString &indent,
+ bool limitXPM_LineLength, const DomImage *image)
{
QString img = image->attributeName() + QLatin1String("_data");
QString data = image->elementData()->text();
@@ -133,7 +135,8 @@ void WriteIconData::writeImage(QTextStream &output, const QString &indent, DomIm
int a = 0;
int column = 0;
bool inQuote = false;
- output << indent << "static const char* const " << img << "[] = { \n";
+ output << indent << "/* XPM */\n"
+ << indent << "static const char* const " << img << "[] = { \n";
while (baunzip[a] != '\"')
a++;
for (; a < (int) length; a++) {
@@ -144,7 +147,8 @@ void WriteIconData::writeImage(QTextStream &output, const QString &indent, DomIm
inQuote = !inQuote;
}
- if (column++ >= 511 && inQuote) {
+ column++;
+ if (limitXPM_LineLength && column >= 512 && inQuote) {
output << "\"\n\""; // be nice with MSVC & Co.
column = 1;
}
diff --git a/src/tools/uic/cpp/cppwriteicondata.h b/src/tools/uic/cpp/cppwriteicondata.h
index 40d56bc..42cfab0 100644
--- a/src/tools/uic/cpp/cppwriteicondata.h
+++ b/src/tools/uic/cpp/cppwriteicondata.h
@@ -64,7 +64,8 @@ public:
void acceptImages(DomImages *images);
void acceptImage(DomImage *image);
- static void writeImage(QTextStream &output, const QString &indent, DomImage *image);
+ static void writeImage(QTextStream &output, const QString &indent,
+ bool limitXPM_LineLength, const DomImage *image);
static void writeImage(QIODevice &output, DomImage *image);
private:
diff --git a/src/tools/uic/option.h b/src/tools/uic/option.h
index f1198a0..8556728 100644
--- a/src/tools/uic/option.h
+++ b/src/tools/uic/option.h
@@ -61,6 +61,7 @@ struct Option
unsigned int autoConnection : 1;
unsigned int dependencies : 1;
unsigned int extractImages : 1;
+ unsigned int limitXPM_LineLength : 1;
unsigned int implicitIncludes: 1;
Generator generator;
@@ -85,6 +86,7 @@ struct Option
autoConnection(1),
dependencies(0),
extractImages(0),
+ limitXPM_LineLength(0),
implicitIncludes(1),
generator(CppGenerator),
prefix(QLatin1String("Ui_"))
diff --git a/src/tools/uic3/converter.cpp b/src/tools/uic3/converter.cpp
index e1b4b38..2ee939d 100644
--- a/src/tools/uic3/converter.cpp
+++ b/src/tools/uic3/converter.cpp
@@ -518,6 +518,7 @@ DomUI *Ui3Reader::generateUi4(const QDomElement &widget)
if (m_extractImages) {
Option opt;
opt.extractImages = m_extractImages;
+ opt.limitXPM_LineLength = (m_options & LimitXPM_LineLength) ? 1 : 0;
opt.qrcOutputFile = m_qrcOutputFile;
CPP::ExtractImages(opt).acceptUI(ui);
diff --git a/src/tools/uic3/form.cpp b/src/tools/uic3/form.cpp
index df1314f..9df644a 100644
--- a/src/tools/uic3/form.cpp
+++ b/src/tools/uic3/form.cpp
@@ -256,6 +256,7 @@ void Ui3Reader::createFormDecl(const QDomElement &e)
d.option().headerProtection = false;
d.option().copyrightHeader = false;
d.option().extractImages = m_extractImages;
+ d.option().limitXPM_LineLength = (m_options & LimitXPM_LineLength) ? 1 : 0;
d.option().qrcOutputFile = m_qrcOutputFile;
d.option().implicitIncludes = (m_options & ImplicitIncludes) ? 1 : 0;
if (trmacro.size())
diff --git a/src/tools/uic3/main.cpp b/src/tools/uic3/main.cpp
index 1ebb76a..d7657b1 100644
--- a/src/tools/uic3/main.cpp
+++ b/src/tools/uic3/main.cpp
@@ -149,6 +149,8 @@ int runUic3(int argc, char * argv[])
readerOptions &= ~Ui3Reader::CustomWidgetForwardDeclarations;
} else if (opt == "layout-names") {
readerOptions |= Ui3Reader::PreserveLayoutNames;
+ } else if (opt == "limit-xpm-linelength") {
+ readerOptions |= Ui3Reader::LimitXPM_LineLength;
} else if (opt == "nounload") {
// skip
} else if (opt == "convert") {
@@ -251,6 +253,7 @@ int runUic3(int argc, char * argv[])
"Options:\n"
"\t-o file Write output to file rather than stdout\n"
"\t-extract qrcFile Create resource file and extract embedded images into \"image\" dir\n"
+ "\t-limit-xpm-linelength Limit the line length of XPM files for -extract.\n"
"\t-pch file Add #include \"file\" as the first statement in implementation\n"
"\t-nofwd Omit forward declarations of custom classes\n"
"\t-layout-names Preserve layout names of Qt Designer 3\n"
diff --git a/src/tools/uic3/ui3reader.h b/src/tools/uic3/ui3reader.h
index 144ef05..abe323e 100644
--- a/src/tools/uic3/ui3reader.h
+++ b/src/tools/uic3/ui3reader.h
@@ -68,7 +68,8 @@ typedef QList<QPair<int, Color> > ColorGroup;
class Ui3Reader
{
public:
- enum Options { CustomWidgetForwardDeclarations = 0x1, ImplicitIncludes = 0x2, PreserveLayoutNames = 0x4 };
+ enum Options { CustomWidgetForwardDeclarations = 0x1, ImplicitIncludes = 0x2,
+ PreserveLayoutNames = 0x4, LimitXPM_LineLength = 0x8 };
explicit Ui3Reader(QTextStream &stream, unsigned options);
~Ui3Reader();