C++ (Qt) QString text1 = lineTextVersion->text(); QString text2 = dictComboBox1->currentText(); if (destFile1.open(QIODevice::WriteOnly | QIODevice::Text)){ QTextStream stream(&destFile1); stream.setCodec("UTF-16LE"); bom ( stream ); stream << text1 + text2 + "\n"; stream.flush(); destFile1.close();}
QTextEdit *textEdit = new QTextEdit();...QString text = textEdit->toPlainText(); // текст без форматированияQString html = textEdit->toHtml(); // думаю, тут и так понятно :D
C++ (Qt)#ifndef MFLDIALOG_HH#define MFLDIALOG_HH #include <QDialog> class QCheckBox;class QComboBox;class QLabel;class QLineEdit;class QPushButton;class QTextEdit; class MainDialog : public QDialog{ Q_OBJECT public: MainDialog(QWidget *parent = 0); signals: void mainNext(const QString &str, Qt::CaseSensitivity cs); void mainPrev(const QString &str, Qt::CaseSensitivity cs); private slots: void mainClicked(); void enableMainButton(const QString &text); private: QLabel *textName; QLineEdit *lineTextName; QLabel *textVersion; QLineEdit *lineTextVersion; QCheckBox *caseCheckBox; QComboBox *texComboBox1; QComboBox *texComboBox2; QTextEdit *atxEdit; QPushButton *mainButton; QPushButton *closeButton;}; #endif // MFLDIALOG_HH
C++ (Qt)#include <QtGui> #include "mfldialog.hh" MainDialog::MainDialog(QWidget *parent) : QDialog(parent){ textName = new QLabel(tr("Name:")); lineTextName = new QLineEdit; textName->setBuddy(lineTextName); textVersion = new QLabel(tr("Version:")); lineTextVersion = new QLineEdit; textVersion->setBuddy(lineTextVersion); atxEdit = new QTextEdit; caseCheckBox = new QCheckBox(tr("Add text")); texComboBox1 = new QComboBox(); texComboBox1->addItem("Abbr1"); texComboBox1->addItem("Abbr2"); texComboBox2 = new QComboBox(); texComboBox2->addItem("Abbr1"); texComboBox2->addItem("Abbr2"); mainButton = new QPushButton(tr("Add")); mainButton->setDefault(true); mainButton->setEnabled(true); closeButton = new QPushButton(tr("Close")); connect(lineTextName, SIGNAL(textChanged(const QString &)), this, SLOT(enabledMainButton(const QString &))); connect(mainButton, SIGNAL(clicked()), this, SLOT(mainClicked())); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *topLeftLayout1 = new QHBoxLayout; topLeftLayout1->addWidget(textName); topLeftLayout1->addWidget(lineTextName); QHBoxLayout *topLeftLayout2 = new QHBoxLayout; topLeftLayout2->addWidget(textVersion); topLeftLayout2->addWidget(lineTextVersion); QHBoxLayout *topLeftLayout3 = new QHBoxLayout; topLeftLayout3->addWidget(texComboBox1); topLeftLayout3->addWidget(texComboBox2); QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addLayout(topLeftLayout1); leftLayout->addLayout(topLeftLayout2); leftLayout->addLayout(topLeftLayout3); leftLayout->addWidget(atxEdit); leftLayout->addWidget(caseCheckBox); QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addWidget(mainButton); rightLayout->addWidget(closeButton); rightLayout->addStretch(); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addLayout(leftLayout); mainLayout->addLayout(rightLayout); setLayout(mainLayout); setWindowTitle(tr("New Text")); setFixedHeight(sizeHint().height());} void MainDialog::mainClicked(){ QString text = lineTextName->text(); QString text2 = lineTextVersion->text(); QString text3 = texComboBox1->currentText(); QString text4 = texComboBox2->currentText(); QString text5 = atxEdit->toPlainText(); QString savePath; savePath = QDir::currentPath(); savePath += "/folder"; QDir dir( savePath ); QString savePat = text3 + "-" + text4 + "_" + text; dir.mkdir(savePat); savePath += "/" + savePat; QDir dir1( savePath ); QString texPath; texPath = text + ".mfl.files"; dir1.mkdir(texPath); QString stylePath; stylePath = savePath + "/" + texPath; QDir dir2( stylePath ); dir2.mkdir( "dir" ); QString destFileName1(savePath + "/" + text + ".mfl"); QFile::copy(":/MyTexionaries.mfl", destFileName1); QFile destFile1(destFileName1); destFile1.setPermissions(destFile1.permissions() | QFile::ReadOther | QFile::WriteOther); QString destFileName2(savePath + "/" + text + "_abrv.mfl"); QFile::copy(":/MyTexionaries_abrv.mfl", destFileName2); QFile destFile2(destFileName2); destFile2.setPermissions(destFile2.permissions() | QFile::ReadOther | QFile::WriteOther); QString destFileName3(savePath + "/" + text + ".atx"); QFile::copy(":/MyTexionaries.atx", destFileName3); QFile destFile3(destFileName3); destFile3.setPermissions(destFile3.permissions() | QFile::ReadOther | QFile::WriteOther); QHash<QString, QString> hash; hash.insert("Abbr1", "Abbreviation1"); hash.insert("Abbr2", "Abbreviation2"); QString fullName1 = hash.value(text3); QString fullName2 = hash.value(text4); if (destFile1.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream stream(&destFile1); stream.setCodec("UTF-16LE"); bom ( stream ); stream << "Name"" + text + "_v" + text2 + " (" + text3 + "-" + text4 + ")\"\n"; stream << fullName1 + "\"\n"; stream << fullName2 + "\"\r\n"; stream << "Test\n\t"; stream << "Test"; stream.flush(); destFile1.close(); } if (destFile2.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream stream(&destFile2); stream.setCodec("UTF-16LE"); bom ( stream ); stream << "Abbreviations for " + text + " (" + text3 + "-" + text4 + ")\"\n"; stream << fullName1 + "\"\n"; stream << fullName1 + "\"\r\n"; stream.flush(); destFile1.close(); } if (destFile3.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream stream(&destFile3); stream.setCodec("UTF-16LE"); bom ( stream ); stream << text5; stream.flush(); destFile1.close(); } } void MainDialog::enableMainButton(const QString &text){ mainButton->setEnabled(!text.isEmpty());}
C++ (Qt)void MainWindow::nameNewText(){ MainDialog *dialog = new MainDialog; dialog->show();}
C++ (Qt)public slots: void on_rescanText_triggered();
C++ (Qt) connect(findButton, SIGNAL(clicked()), this, SLOT(on_rescanText_triggered()));
C++ (Qt)#include "mainwindow.hh"
C++ (Qt)void MainWindow::nameNewText(){ MainDialog *dialog = new MainDialog; dialog->show(); on_rescanText_triggered();}