Changeset 59 in projects for punch-card-project/trunk/punch-card-editor/src/text/editordock.cc
- Timestamp:
- Jan 22, 2010, 7:44:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
punch-card-project/trunk/punch-card-editor/src/text/editordock.cc
r58 r59 7 7 #include <QComboBox> 8 8 #include <QPushButton> 9 #include <QFileDialog> 10 #include <QMessageBox> 9 11 10 12 using namespace QPunchCard; … … 67 69 } 68 70 71 const Codec* Text::EditorDock::getCodec() const { 72 return editor->codec; 73 } 74 75 QString Text::EditorDock::getText() const { 76 return editor->toPlainText(); 77 } 78 69 79 void Text::EditorDock::setCodec(QString by_name) { 70 80 // QSharedPointer: Durch Assignment wird das alte Objekt geloescht :-) … … 74 84 } 75 85 86 bool Text::EditorDock::exportTextAs() { 87 // show a funny `export text as` dialog 88 QString new_filename = QFileDialog::getSaveFileName(main, 89 tr("Export Card Text (%1)").arg(getCodec()->getName()), 90 filename.isEmpty() ? QDir::homePath() : QFileInfo(filename).absolutePath(), 91 tr("Plain Text File (*.txt);;Any File (*)")); 92 if(new_filename.isEmpty()) 93 return false; 94 95 // save filename and go on exporting normally 96 this->filename = new_filename; 97 this->exportText(); 98 } 99 100 bool Text::EditorDock::exportText() { 101 if(this->filename.isEmpty()) { 102 return exportTextAs(); 103 } 104 105 QFile file(this->filename); 106 // everything in one line ;-) 107 if(!file.open( QIODevice::WriteOnly | QIODevice::Text ) || 108 (file.write( this->getText().toAscii() ) == -1) ) { 109 QMessageBox::critical(main, tr("Could not export to file"), 110 tr("Plain text export to file %1 failed: %2").arg(filename).arg(file.errorString())); 111 return false; 112 } else { 113 main->statusBar()->showMessage(tr("Successfully exported card text as %1 to %2 ").arg(getCodec()->getName()).arg(filename), 5000); 114 return true; 115 } 116 } 117 76 118 void Text::EditorDock::showTextConverterDialog() { 77 qDebug("Text Converter Dialog... PENDING");119 QMessageBox::information(main, tr("Pending work"), tr("Well... the Text Converter Dialog hasn't been done yet...")); 78 120 }
Note: See TracChangeset
for help on using the changeset viewer.