Changeset ca3d2a30fa in tspsg for src/mainwindow.cpp
- Timestamp:
- Apr 25, 2010, 10:09:26 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 20015b41e7
- Parents:
- 9cda6e0f5d
- git-author:
- Oleksii Serdiuk <contacts@…> (04/25/10 22:09:26)
- git-committer:
- Oleksii Serdiuk <contacts@…> (06/29/12 19:41:31)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mainwindow.cpp
r9cda6e0f5d rca3d2a30fa 218 218 } 219 219 #endif 220 if (selectedFile.endsWith(".htm", Qt::CaseInsensitive) || selectedFile.endsWith(".html", Qt::CaseInsensitive)) { 221 QFile file(selectedFile); 222 if (!file.open(QFile::WriteOnly)) { 223 QApplication::restoreOverrideCursor(); 224 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file.errorString())); 225 return; 226 } 227 QFileInfo fi(selectedFile); 228 QString html = solutionText->document()->toHtml("UTF-8"), 229 img = fi.completeBaseName() + ".svg"; 230 html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"%4\"").arg(img).arg(graph.width() + 1).arg(graph.height() + 1).arg(tr("Solution Graph"))); 231 // Saving solution text as HTML 232 QTextStream ts(&file); 233 ts.setCodec(QTextCodec::codecForName("UTF-8")); 234 ts << html; 235 file.close(); 236 // Saving solution graph as SVG 237 QSvgGenerator svg; 238 svg.setFileName(fi.path() + "/" + img); 239 svg.setTitle(tr("Solution Graph")); 240 QPainter p; 241 p.begin(&svg); 242 graph.play(&p); 243 p.end(); 244 245 // Qt < 4.5 has no QTextDocumentWriter class 220 246 #if QT_VERSION >= 0x040500 247 } else { 221 248 QTextDocumentWriter dw(selectedFile); 222 if (!(selectedFile.endsWith(".htm",Qt::CaseInsensitive) || selectedFile.endsWith(".html",Qt::CaseInsensitive) || selectedFile.endsWith(".odt",Qt::CaseInsensitive) || selectedFile.endsWith(".txt",Qt::CaseInsensitive))) 223 dw.setFormat("plaintext"); 224 if (!dw.write(solutionText->document())) 225 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString())); 226 #else // QT_VERSION >= 0x040500 227 // Qt < 4.5 has no QTextDocumentWriter class 228 QFile file(selectedFile); 229 if (!file.open(QFile::WriteOnly)) { 230 QApplication::restoreOverrideCursor(); 231 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file->errorString())); 232 return; 233 } 234 QTextStream ts(&file); 235 ts.setCodec(QTextCodec::codecForName("UTF-8")); 236 ts << solutionText->document()->toHtml("UTF-8"); 237 file.close(); 249 if (!selectedFile.endsWith(".odt",Qt::CaseInsensitive)) 250 dw.setFormat("plaintext"); 251 if (!dw.write(solutionText->document())) 252 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString())); 238 253 #endif // QT_VERSION >= 0x040500 254 } 239 255 QApplication::restoreOverrideCursor(); 240 256 }
Note: See TracChangeset
for help on using the changeset viewer.