24 #include <qtextedit.h>
28 #include <qpushbutton.h>
30 #include <qtextstream.h>
31 #include <qmessagebox.h>
32 #include <qtoolbutton.h>
34 #include <qfiledialog.h>
42 setCaption(
"Qucs Editor " PACKAGE_VERSION
" - " + tr(
"File: "));
44 QVBoxLayout *v =
new QVBoxLayout(
this);
46 QHBox *h =
new QHBox(
this);
49 QToolButton *ButtLoad =
new QToolButton(h);
52 connect(ButtLoad, SIGNAL(clicked()), SLOT(slotLoad()));
54 QToolButton *ButtSave =
new QToolButton(h);
57 connect(ButtSave, SIGNAL(clicked()), SLOT(slotSave()));
58 ButtSave->setDisabled(readOnly);
60 h->setStretchFactor(
new QWidget(h),5);
61 PosText =
new QLabel(tr(
"Line: %1 - Column: %2").
arg(1).
arg(1), h);
62 h->setStretchFactor(
new QWidget(h),5);
64 QPushButton *ButtAbout =
new QPushButton(tr(
"About"),h);
65 connect(ButtAbout, SIGNAL(clicked()), SLOT(slotAbout()));
67 QPushButton *ButtOK =
new QPushButton(tr(
"Quit"),h);
68 connect(ButtOK, SIGNAL(clicked()), SLOT(slotQuit()));
72 QFont fedit = QFont(
"Courier New");
74 fedit.setStyleHint(QFont::Courier);
75 fedit.setFixedPitch(
true);
77 text =
new QTextEdit(
this);
78 text->setTextFormat(Qt::PlainText);
79 text->setReadOnly(readOnly);
80 text->setWordWrap(QTextEdit::NoWrap);
81 text->setMinimumSize(300,200);
83 text->setCurrentFont(fedit);
85 connect(text, SIGNAL(cursorPositionChanged(
int,
int)),
86 SLOT(slotPrintCursorPosition(
int,
int)));
97 void QucsEdit::slotPrintCursorPosition(
int Para,
int Pos)
99 PosText->setText(tr(
"Line: %1 - Column: %2").
arg(Para+1).
arg(Pos+1));
103 void QucsEdit::slotAbout()
105 QMessageBox::about(
this, tr(
"About..."),
106 "QucsEdit Version " PACKAGE_VERSION+
107 tr(
"\nVery simple text editor for Qucs\n")+
108 tr(
"Copyright (C) 2004, 2005 by Michael Margraf\n")+
109 "\nThis is free software; see the source for copying conditions."
110 "\nThere is NO warranty; not even for MERCHANTABILITY or "
111 "\nFITNESS FOR A PARTICULAR PURPOSE.");
115 void QucsEdit::slotLoad()
119 QString
s = QFileDialog::getOpenFileName(
120 lastDir.isEmpty() ? QString(
".") : lastDir,
121 "*", this,
"", tr(
"Enter a Filename"));
122 if(s.isEmpty())
return;
124 if(!closeFile())
return;
129 void QucsEdit::slotSave()
131 if(FileName.isEmpty()) {
132 FileName = QFileDialog::getSaveFileName(
".", QString::null,
133 this,
"", tr(
"Enter a Document Name"));
134 if(FileName.isEmpty())
return;
137 QFile file(FileName);
138 if(!file.open(IO_WriteOnly)) {
139 QMessageBox::critical(
this, tr(
"Error"),
140 tr(
"Cannot write file: ")+FileName);
144 QTextStream stream(&file);
145 stream << text->text();
146 text->setModified(
false);
151 void QucsEdit::slotQuit()
153 if(!closeFile())
return;
166 void QucsEdit::closeEvent(QCloseEvent*)
172 bool QucsEdit::loadFile(
const QString& Name)
174 if(Name.isEmpty())
return false;
176 if(!file.open(IO_ReadOnly)) {
177 QMessageBox::critical(
this, tr(
"Error"),
178 tr(
"Cannot read file: ")+Name);
182 QTextStream stream(&file);
183 text->setText(stream.read());
189 setCaption(
"Qucs Editor " PACKAGE_VERSION
" - " + tr(
"File: ")+FileName);
195 bool QucsEdit::closeFile()
197 if(text->isModified()) {
198 switch(QMessageBox::warning(
this,tr(
"Closing document"),
199 tr(
"The text contains unsaved changes!\n")+
200 tr(
"Do you want to save the changes?"),
201 tr(
"&Save"), tr(
"&Discard"), tr(
"&Cancel"), 0, 2)) {
203 if(FileName.isEmpty())
return false;
205 case 2:
return false;