News

Develop for the Nokia N900 and Maemo 5 OS!

Learn how to program the next-generation smartphone-come-internet tablet, the Nokia N900…

Nokia_N900

Set up the main window with the menus and other contents:

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setupFileMenu();
setupHelpMenu();
setupEditor();
setCentralWidget(editor);
setWindowTitle(tr(“CodeEditor”));
}

Set the application’s about menu:

void MainWindow::about()
{
QMessageBox::about(this, tr(“About CodeEditor”),
tr(“<p>CodeEditor is a C/C++ Source code file editor.</p>”));
}
Set up the action for New File creation:
void MainWindow::newFile()
{
editor->clear();
}

Set up the action for File Open:
void MainWindow::openFile(const QString &path)
{
QString fileName = path;

Search for C/C++/header files with wildcards *.c, *.cpp and *.h:
if (fileName.isNull())
fileName = QFileDialog::getOpenFileName(this,
tr(“Open File”), “”, “C/C++ Files (*.cpp *.c *.h)”);

if (!fileName.isEmpty()) {
QFile file(fileName);
if (file.open(QFile::ReadOnly | QFile::Text))
editor->setPlainText(file.readAll());
}
}

Set up the editor interface:

void MainWindow::setupEditor()
{
QFont font;

Set up the editor font:

font.setFamily(“Courier”);
font.setFixedPitch(true);
font.setPointSize(10);
editor = new QTextEdit;
editor->setFont(font);

Create an instance of codeColor:

highlighter = new codeColor(editor->document());

×