-#include <qapp.h>
-#include <qmenubar.h>
-#include <qpopmenu.h>
-#include <qlabel.h>
-#include <qlistbox.h>
-#include <qfile.h>
-#include <qfiledlg.h>
-#include <qfontmet.h>
-#include <qtooltip.h>
-#include <qfont.h>
-#include <qpixmap.h>
-#include <qmsgbox.h>
-#include <stdio.h>
-#include <stdlib.h>
#include <unistd.h>
-#include <qscrbar.h>
-#include <qpainter.h>
-#include <qcolor.h>
-#include <qpoint.h>
-#include <qtstream.h>
-#include <qchkbox.h>
-#include <qkeycode.h>
+#include <QtCore/QTextStream>
+#include <QtGui/QApplication>
+#include <QtGui/QMenuBar>
+#include <QtGui/QFileDialog>
+#include <QtGui/QColor>
+#include <QtGui/QPalette>
+#include <QtGui/QCloseEvent>
+#include <QtGui/QTextDocument>
+#include <QtGui/QMainWindow>
+#include <QtGui/QStatusBar>
+#include <QtGui/QCheckBox>
+#include <QtGui/QVBoxLayout>
#include "editor.h"
* @param parent Parent widget of this widget. If set, this widget becomes a
* child window inside parent. If not set this widget becomes a
* top level window. Default: NULL
- * @param name If set, name is sent to the Qobject constructor, so widget is
+ * @param name @deprecated If set, name is sent to the Qobject constructor, so widget is
* identifiable (e.g. in Qt Designer)
*/
My_Edit::My_Edit(QWidget *parent, const char *name)
- : QMultiLineEdit(parent, name)
+ : QTextEdit(parent)
{
parent = NULL;
name = NULL;
*/
void My_Edit::keyPressEvent(QKeyEvent *ev)
{
- QMultiLineEdit::keyPressEvent(ev);
+ QTextEdit::keyPressEvent(ev);
emit cursorMove();
}
* @param name If set, name is sent to the Qobject constructor, so widget is
* identifiable (e.g. in Qt Designer)
*/
-Editor::Editor(char *hdir,QWidget * parent , const char * name)
- : QWidget(parent, name)
+Editor::Editor(char *hdir, QWidget * parent)
+ : QMainWindow(parent)
{
- QFont f1("Helvetica", 10, QFont::Bold);
-
strcpy(HomeDir, hdir);
- strcpy(find_text, "");
+ find_text = "";
sensitive = FALSE;
- m = new QMenuBar(this, "menu");
- m->setFont(f1);
- QPopupMenu * file = new QPopupMenu();
- QPopupMenu * comp = new QPopupMenu();
- QPopupMenu * loglan = new QPopupMenu();
- QPopupMenu *medit = new QPopupMenu();
-
- file->setFont(f1);
- comp->setFont(f1);
- loglan->setFont(f1);
- medit->setFont(f1);
- CHECK_PTR(file);
- CHECK_PTR(comp);
- m->insertItem("&File ", file);
- m->insertItem("&Edit", medit);
- m->insertItem("&Compile", this,SLOT(cmp()));
+ QMenu * file = NULL;
+/* QMenu * comp = new QMenu();*/
+/* QMenu * loglan = new QMenu();*/
+ QMenu * medit = NULL;
+ QAction* action = NULL;
+
+ file = menuBar()->addMenu("&File");
+ medit = menuBar()->addMenu("&Edit");
+
+ action = menuBar()->addAction("&Compile", this, SLOT(cmp()));
/* m->insertItem( "&LOGLAN ", loglan );*/
- m->insertItem("&Properties", this, SLOT(props()));
- file->insertItem("New ", this, SLOT(create()), CTRL + Key_N);
- file->insertItem("Open ", this, SLOT(load()), CTRL + Key_O);
- file->insertItem("Save ", this, SLOT(save()),CTRL + Key_S);
- file->insertItem("Save as", this, SLOT(save_as()),CTRL + Key_A);
- file->insertSeparator();
- file->insertItem("Quit ", qApp, SLOT(quit()));
+ action = menuBar()->addAction("&Properties", this, SLOT(props()));
+
+ file->addAction("New", this, SLOT(create()), QKeySequence(Qt::CTRL + Qt::Key_N));
+ file->addAction("Open", this, SLOT(load()), QKeySequence(Qt::CTRL + Qt::Key_O));
+ file->addAction("Save", this, SLOT(save()), QKeySequence(Qt::CTRL + Qt::Key_S));
+ file->addAction("Save as", this, SLOT(save_as()), QKeySequence(Qt::CTRL + Qt::Key_A));
+ file->addSeparator();
+ file->addAction("Quit ", this, SLOT(close()));
/* comp->insertItem("Compile ", this, SLOT(cmp()), CTRL + Key_C);*/
/* comp->insertItem("Gen ", this, SLOT(gen()), CTRL + Key_G);*/
/* loglan->insertItem( "Program structure", this, SLOT(log_prog()));*/
/* loglan->insertItem( "Unit structure", this, SLOT(log_unit()));*/
- e = new My_Edit( this, "editor" );
- connect(e,SIGNAL(cursorMove()),this,SLOT(updateline()));
- medit->insertItem("Copy ",e,SLOT(copy()),CTRL + Key_Insert);
- medit->insertItem("Paste ",e,SLOT(paste()), SHIFT + Key_Insert);
- medit->insertItem("Cut ",e,SLOT(cut()), CTRL + Key_Delete);
- medit->insertItem("Clear All ",e,SLOT(clear()));
- medit->insertSeparator();
- medit->insertItem("Find ",this,SLOT(findText()), CTRL + Key_F);
- medit->insertItem("Find Next ",this,SLOT(find_next()),CTRL + Key_L);
-
- msg = new QMultiLineEdit( this, "messages" );
+ e = new My_Edit(this, "editor");
+ connect(e, SIGNAL(cursorMove()), this, SLOT(updateline()));
+ medit->addAction("Copy", e, SLOT(copy()), QKeySequence(Qt::CTRL + Qt::Key_Insert));
+ medit->addAction("Paste", e, SLOT(paste()), QKeySequence(Qt::SHIFT + Qt::Key_Insert));
+ medit->addAction("Cut", e, SLOT(cut()), QKeySequence(Qt::CTRL + Qt::Key_Delete));
+ medit->addAction("Clear All", e, SLOT(clear()));
+ medit->addSeparator();
+ medit->addAction("Find", this, SLOT(findText()), QKeySequence(Qt::CTRL + Qt::Key_F));
+ medit->addAction("Find Next", this, SLOT(find_next()), QKeySequence(Qt::CTRL + Qt::Key_L));
+
+ msg = new QTextEdit(this);
msg->setReadOnly(TRUE);
- compiler_path.sprintf("%s/%s",HomeDir,"compile/logcomp");
- gen_path.sprintf("%s/%s",HomeDir,"compile/gen");
- file_path.sprintf("%s",HomeDir);
- QFont f2("Times", 14, QFont::Bold);
- e->setFont(f1);
+ QVBoxLayout * layout = new QVBoxLayout();
+ layout->setContentsMargins (3, 0, 3, 0);
+ layout->addWidget(e);
+ layout->addWidget(msg);
+ QWidget *window = new QWidget();
+ window->setLayout(layout);
+ setCentralWidget(window);
+
+ compiler_path.sprintf("%s/%s", HomeDir, "compile/logcomp");
+ gen_path.sprintf("%s/%s", HomeDir, "compile/gen");
+ file_path.sprintf("%s", HomeDir);
+
QColor col(200, 200, 200);
- QColorGroup grp(black, col, col.light(), col.dark(), col.dark(), black, col);
-
- msg->setPalette(QPalette(grp, grp, grp));
- position = new QLabel(this);
- position->setFont(f2);
- position->setFrameStyle(QFrame::NoFrame);
- position->setAutoResize(TRUE);
- resize(400, 300);
+ QPalette grp(Qt::black, col, col.lighter(), col.darker(), col.darker(), Qt::black, col);
+
+ msg->setPalette(grp);
+
+ position = new QLabel();
+ statusBar()->addPermanentWidget(position);
}
/**
int cx;
int cy;
- e->getCursorPosition(&cx, &cy);
- sprintf(pom," %d:%d ", cx, cy);
+ cx = e->textCursor().blockNumber();
+ cy = e->textCursor().columnNumber();
+ sprintf(pom,"%d:%d ", cx, cy);
position->setText(pom);
}
*/
void Editor::resizeEvent(QResizeEvent *event)
{
+/*
+TODO: Remove entire method?
if (e && m) {
e->setGeometry(0, m->height(), width(),
3 * (int)((height() - m->height()) / 4));
position->width(),
position->height());
}
+*/
}
/**
*/
void Editor::load()
{
- QString fn = QFileDialog::getOpenFileName(file_path.data(), "*.log");
+ QString fn = QFileDialog::getOpenFileName(this, "Load file", file_path, "*.log");
if (!fn.isEmpty())
- load(fn);
+ load(fn.toAscii().data());
}
/**
fname.sprintf("%s", fileName);
QFile f(fileName);
- if (!f.open(IO_ReadOnly))
+ if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
return;
+/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
e->setAutoUpdate(FALSE);
+*/
e->clear();
QTextStream t(&f);
- while (!t.eof()) {
+ while (!t.atEnd()) {
QString s = t.readLine();
e->append(s);
}
f.close();
+/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
e->setAutoUpdate(TRUE);
+*/
e->repaint();
- setCaption(fileName);
+ setWindowTitle(fileName);
}
/**
void Editor::save()
{
if (fname.isEmpty()) {
- QString fn = QFileDialog::getSaveFileName(file_path.data(),
- "*.log");
+ QString fn = QFileDialog::getSaveFileName(this, "Save file",
+ file_path, "*.log");
if (!fn.isEmpty()) {
- fname.sprintf("%s",fn.data());
- save( fn );
+ fname.sprintf("%s", fn.toAscii().data());
+ save(fn.toAscii().data());
}
} else {
- save(fname);
+ save(fname.toAscii().data());
}
- setCaption(fname);
+ setWindowTitle(fname);
}
/**
*/
void Editor::save_as()
{
- QString fn = QFileDialog::getSaveFileName(file_path.data(), "*.log");
+ QString fn = QFileDialog::getSaveFileName(this, "Save file as",
+ file_path, "*.log");
if (!fn.isEmpty()) {
- fname.sprintf("%s", fn.data());
- save(fn);
+ fname.sprintf("%s", fn.toAscii().data());
+ save(fn.toAscii().data());
}
- setCaption(fname);
+ setWindowTitle(fname);
}
/**
void Editor::save(const char *fileName)
{
QFile f(fileName);
- if (!f.open(IO_WriteOnly))
+ if (!f.open(QIODevice::WriteOnly | QIODevice::Text))
return;
f.reset();
- f.writeBlock(e->text().data(), e->text().length());
+ f.write(e->toPlainText().toAscii().data(), e->toPlainText().length());
f.close();
}
void Editor::compile(int mode)
{
char cmd[255];
-
+/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
msg->setAutoUpdate(FALSE);
+*/
msg->setReadOnly(FALSE);
msg->clear();
msg->repaint();
/*i = fname.find('.');*/
/* if (i>=0) {*/
- QString fn = fname.data();
-
/* fn.truncate(i);*/
switch(mode) {
case COMP_MODE:
- sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
- fname.data());
+ sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
+ fname.toAscii().data());
break;
case GEN_MODE:
- sprintf(cmd, "%s %s > comp_data!", gen_path.data(), fn.data());
+ sprintf(cmd, "%s %s > comp_data!", gen_path.toAscii().data(),
+ fname.toAscii().data());
break;
case ALL_MODE:
- sprintf(cmd, "%s %s > comp_data!", compiler_path.data(),
- fn.data());
+ sprintf(cmd, "%s %s > comp_data!", compiler_path.toAscii().data(),
+ fname.toAscii().data());
system(cmd);
- sprintf(cmd, "%s %s >> comp_data!", gen_path.data(), fn.data());
+ sprintf(cmd, "%s %s >> comp_data!", gen_path.toAscii().data(),
+ fname.toAscii().data());
break;
}
system(cmd);
QFile f("comp_data!");
- if (!f.open(IO_ReadOnly))
+ if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream t(&f);
- while (!t.eof()) {
+ while (!t.atEnd()) {
QString s = t.readLine();
msg->append(s);
}
f.close();
+
msg->setReadOnly(TRUE);
+
+/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
msg->setAutoUpdate(TRUE);
+*/
msg->repaint();
unlink("comp_data!");
/*}*/
*/
void Editor::props()
{
- QDialog dlg(this, "Properties", TRUE);
+ QDialog dlg(this, Qt::Dialog);
QLineEdit *files;
- files = new QLineEdit(&dlg, "f_path");
+ files = new QLineEdit(&dlg);
files->setGeometry(130, 20, 250, 30);
- files->setText(file_path.data());
+ files->setText(file_path);
files->setMaxLength(32767);
files->setEchoMode(QLineEdit::Normal);
files->setFrame(TRUE);
QLabel *tmpQLabel;
- tmpQLabel = new QLabel(&dlg, "Label_1");
+ tmpQLabel = new QLabel("Path to files:", &dlg);
tmpQLabel->setGeometry(10, 20, 100, 30);
- tmpQLabel->setText("Path to files:");
- tmpQLabel->setAlignment(289);
+ tmpQLabel->setAlignment(Qt::AlignLeft);
tmpQLabel->setMargin(-1);
- tmpQLabel = new QLabel(&dlg, "Label_2");
+ tmpQLabel = new QLabel("Path to compiler:", &dlg);
tmpQLabel->setGeometry(10, 60, 100, 30);
- tmpQLabel->setText("Path to compiler:");
- tmpQLabel->setAlignment(289);
+ tmpQLabel->setAlignment(Qt::AlignLeft);
tmpQLabel->setMargin(-1);
/*
*/
QLineEdit *compp;
- compp = new QLineEdit(&dlg, "l_path");
+ compp = new QLineEdit(compiler_path, &dlg);
compp->setGeometry(130, 60, 250, 30);
- compp->setText(compiler_path.data());
compp->setMaxLength(32767);
compp->setEchoMode(QLineEdit::Normal);
compp->setFrame(TRUE);
*/
QPushButton* tmpQPushButton;
- tmpQPushButton = new QPushButton(&dlg, "OkBtn");
+ tmpQPushButton = new QPushButton("Ok", &dlg);
tmpQPushButton->setGeometry(90, 100, 70, 30);
- tmpQPushButton->setText("Ok");
tmpQPushButton->setAutoRepeat(FALSE);
+/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
tmpQPushButton->setAutoResize(FALSE);
+*/
connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(accept()));
- tmpQPushButton = new QPushButton(&dlg, "CancelBtn");
+ tmpQPushButton = new QPushButton("Cancel", &dlg);
tmpQPushButton->setGeometry(180, 100, 70, 30);
- tmpQPushButton->setText("Cancel");
tmpQPushButton->setAutoRepeat(FALSE);
+/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
tmpQPushButton->setAutoResize(FALSE);
+*/
connect(tmpQPushButton,SIGNAL(clicked()), &dlg, SLOT(reject()));
dlg.resize(400, 140);
if (dlg.exec()) {
- compiler_path.sprintf("%s", compp->text().ascii());
+ compiler_path.sprintf("%s", compp->text().toAscii().data());
/* gen_path.sprintf("%s",genp->text()); */
- file_path.sprintf("%s",files->text().ascii());
+ file_path.sprintf("%s", files->text().toAscii().data());
};
}
*/
void Editor::log_unit()
{
+ /*
+ Code commented during Qt4 migration.
+ Code is not used, so there is no rush with this...
+ */
+ /*
QString txt;
- QDialog dlg(this, "unit", TRUE);
+ QDialog dlg(this, Qt::Dialog);
int cx, cy, i;
char uname[255];
uname, lst.text(lst.currentItem()).ascii(), uname);
e->insertAt(txt, cx, cy);
}
+ */
}
/**
*/
void Editor::log_prog()
{
+ /*
+ Code commented during Qt4 migration.
+ Code is not used, so there is no rush with this...
+ */
+ /*
QString txt;
QDialog dlg(this, "unit", TRUE);
int cx, cy;
txt.sprintf("PROGRAM %s\n\nBEGIN\n\nEND ", uname);
e->insertAt(txt, cx, cy);
}
+ */
}
/**
*/
void Editor::findText()
{
- QDialog dlg(this, "", TRUE);
+ QDialog dlg(this, Qt::Dialog);
QString *txt;
int res, line, pom;
QLineEdit *tmpQLineEdit;
- tmpQLineEdit = new QLineEdit(&dlg, "LineEdit_1");
+ tmpQLineEdit = new QLineEdit("", &dlg);
tmpQLineEdit->setGeometry(60, 10, 180, 30);
- tmpQLineEdit->setText("");
QLabel *tmpQLabel;
- tmpQLabel = new QLabel(&dlg, "Label_1");
+ tmpQLabel = new QLabel(&dlg);
tmpQLabel->setGeometry(10, 10, 50, 30);
- QFont font("helvetica", 12, 75, 0);
- font.setStyleHint((QFont::StyleHint)0);
- //font.setCharSet((QFont::CharSet)0);
- tmpQLabel->setFont(font);
-
tmpQLabel->setText("Text:");
QCheckBox *tmpQRadioButton;
- tmpQRadioButton = new QCheckBox(&dlg, "RadioButton_1");
+ tmpQRadioButton = new QCheckBox("Case sensitive", &dlg);
tmpQRadioButton->setGeometry(70, 50, 150, 30);
- tmpQRadioButton->setText("Case sensitive");
tmpQRadioButton->setAutoRepeat(FALSE);
+
+/*TODO: Does not exists in Qt4. Use layout and set the size policy (https://qt-project.org/forums/viewthread/2112)
tmpQRadioButton->setAutoResize(FALSE);
+*/
QPushButton *okbtn, *cbtn;
- okbtn = new QPushButton(&dlg, "PushButton_1");
+ okbtn = new QPushButton("Find", &dlg);
okbtn->setGeometry(260, 10, 100, 30);
- okbtn->setText("Find");
okbtn->setDefault(TRUE);
connect(okbtn,SIGNAL(clicked()), &dlg, SLOT(accept()));
- cbtn = new QPushButton(&dlg, "PushButton_2");
+ cbtn = new QPushButton("Close", &dlg);
cbtn->setGeometry(260, 50, 100, 30);
- cbtn->setText("Close");
connect(cbtn, SIGNAL(clicked()), &dlg, SLOT(reject()));
dlg.resize(380, 90);
if (dlg.exec()) {
- e->getCursorPosition(&pom, &res);
sensitive = tmpQRadioButton->isChecked();
- for (line = pom + 1; line < e->numLines(); line++) {
- txt = new QString(e->textLine(line));
- if (tmpQRadioButton->isChecked())
- res = txt->find(tmpQLineEdit->text(), 0, TRUE);
- else
- res = txt->find(tmpQLineEdit->text(), 0, FALSE);
-
- delete txt;
- if (res >= 0) {
- e->setCursorPosition(line, 1);
- strcpy(find_text, tmpQLineEdit->text());
- break;
- }
+ find_text = tmpQLineEdit->text();
+
+ QTextDocument::FindFlags flags = 0;
+
+ if (sensitive) {
+ flags |= QTextDocument::FindCaseSensitively;
}
+ e->find(find_text, flags);
}
}
*/
void Editor::find_next()
{
- int pom,res,line;
- QString *txt;
-
- e->getCursorPosition(&pom, &res);
- for(line = pom + 1; line < e->numLines(); line++) {
- txt = new QString(e->textLine(line));
- if (sensitive)
- res=txt->find(find_text, 0, TRUE);
- else
- res=txt->find(find_text, 0, FALSE);
-
- delete txt;
- if (res >= 0) {
- e->setCursorPosition(line, 1);
- break;
+ if (!find_text.isEmpty()) {
+ QTextDocument::FindFlags flags = 0;
+
+ if (sensitive) {
+ flags |= QTextDocument::FindCaseSensitively;
}
+ e->find(find_text, flags);
}
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- //app.setStyle(WindowsStyle);
- editor = new Editor(argv[1]);
- app.setMainWidget(editor);
+ editor = new Editor(argv[1], NULL);
editor->resize(600, 400);
editor->show();
return app.exec();