37 #include <QTextDocument>
38 #include <QPushButton>
39 #include <QTextStream>
44 #include <QFileSystemWatcher>
53 mTextDocument(new QTextDocument(this)),
54 mTextEdit(new QTextEdit(this)),
55 mSaveButton(new QPushButton(
"Save", this))
57 this->setToolTip(
"Preview and edit a file");
58 mSyntaxHighlighter = NULL;
59 connect(mSaveButton, SIGNAL(clicked()),
this, SLOT(
saveSlot()));
60 mSaveButton->setEnabled(
false);
62 QHBoxLayout* buttonLayout =
new QHBoxLayout();
63 buttonLayout->addStretch();
64 buttonLayout->setMargin(0);
65 buttonLayout->addWidget(mSaveButton);
67 QVBoxLayout* layout =
new QVBoxLayout(
this);
69 layout->addWidget(mTextEdit);
70 layout->addLayout(buttonLayout);
72 connect(mTextEdit, SIGNAL(textChanged()),
this, SLOT(
textChangedSlot()));
73 mTextEdit->setDocument(mTextDocument);
74 mTextEdit->setLineWrapMode(QTextEdit::NoWrap);
76 this->setSyntaxHighLighter<snw::SyntaxHighlighter>();
84 mSaveButton->setEnabled(mTextDocument->isModified());
89 mSaveButton->setEnabled(
false);
95 QString text = stream.readAll();
98 mTextDocument->setPlainText(text);
99 mTextDocument->setModified(
false);
109 if(!
mCurrentFile->open(QIODevice::WriteOnly | QIODevice::Truncate))
115 mCurrentFile->write(mTextDocument->toPlainText().toLatin1());
118 mTextDocument->setModified(
false);
void reportWarning(QString msg)