src/tools/uic/cpp/cppwriteicondata.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   112     TreeWalker::acceptImages(images);
   112     TreeWalker::acceptImages(images);
   113 }
   113 }
   114 
   114 
   115 void WriteIconData::acceptImage(DomImage *image)
   115 void WriteIconData::acceptImage(DomImage *image)
   116 {
   116 {
   117     writeImage(output, option.indent, image);
   117     // Limit line length when writing code.
       
   118     writeImage(output, option.indent, true, image);
   118 }
   119 }
   119 
   120 
   120 void WriteIconData::writeImage(QTextStream &output, const QString &indent, DomImage *image)
   121 void WriteIconData::writeImage(QTextStream &output, const QString &indent,
       
   122                                bool limitXPM_LineLength, const DomImage *image)
   121 {
   123 {
   122     QString img = image->attributeName() + QLatin1String("_data");
   124     QString img = image->attributeName() + QLatin1String("_data");
   123     QString data = image->elementData()->text();
   125     QString data = image->elementData()->text();
   124     QString fmt = image->elementData()->attributeFormat();
   126     QString fmt = image->elementData()->attributeFormat();
   125     int size = image->elementData()->attributeLength();
   127     int size = image->elementData()->attributeLength();
   131         // shouldn't we test the initial 'length' against the
   133         // shouldn't we test the initial 'length' against the
   132         // resulting 'length' to catch corrupt UIC files?
   134         // resulting 'length' to catch corrupt UIC files?
   133         int a = 0;
   135         int a = 0;
   134         int column = 0;
   136         int column = 0;
   135         bool inQuote = false;
   137         bool inQuote = false;
   136         output << indent << "static const char* const " << img << "[] = { \n";
   138         output << indent << "/* XPM */\n"
       
   139                << indent << "static const char* const " << img << "[] = { \n";
   137         while (baunzip[a] != '\"')
   140         while (baunzip[a] != '\"')
   138             a++;
   141             a++;
   139         for (; a < (int) length; a++) {
   142         for (; a < (int) length; a++) {
   140             output << baunzip[a];
   143             output << baunzip[a];
   141             if (baunzip[a] == '\n') {
   144             if (baunzip[a] == '\n') {
   142                 column = 0;
   145                 column = 0;
   143             } else if (baunzip[a] == '"') {
   146             } else if (baunzip[a] == '"') {
   144                 inQuote = !inQuote;
   147                 inQuote = !inQuote;
   145             }
   148             }
   146 
   149 
   147             if (column++ >= 511 && inQuote) {
   150             column++;
       
   151             if (limitXPM_LineLength && column >= 512 && inQuote) {
   148                 output << "\"\n\""; // be nice with MSVC & Co.
   152                 output << "\"\n\""; // be nice with MSVC & Co.
   149                 column = 1;
   153                 column = 1;
   150             }
   154             }
   151         }
   155         }
   152 
   156