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

Pattern search for various C/C++ code elements:

keywordPatterns << “\bchar\b” << “\bclass\b” << “\bconst\b”
<< “\bdouble\b” << “\benum\b” << “\bexplicit\b”
<< “\bfriend\b” << “\binline\b” << “\bint\b”
<< “\blong\b” << “\bnamespace\b” << “\boperator\b”
<< “\bprivate\b” << “\bprotected\b” << “\bpublic\b”
<< “\bshort\b” << “\bsignals\b” << “\bsigned\b”
<< “\bslots\b” << “\bstatic\b” << “\bstruct\b”
<< “\btemplate\b” << “\btypedef\b” << “\btypename\b”
<< “\bunion\b” << “\bunsigned\b” << “\bvirtual\b”
<< “\bvoid\b” << “\bvolatile\b”;
foreach (const QString &pattern, keywordPatterns) {
rule.pattern = QRegExp(pattern);
rule.format = keywordFormat;
highlightingRules.append(rule);
}
classFormat.setFontWeight(QFont::Bold);
classFormat.setForeground(Qt::darkMagenta);
rule.pattern = QRegExp(“\bQ[A-Za-z]+\b”);
rule.format = classFormat;
highlightingRules.append(rule);
singleLineCommentFormat.setForeground(Qt::red);
rule.pattern = QRegExp(“//[^n]*”);
rule.format = singleLineCommentFormat;
highlightingRules.append(rule);
multiLineCommentFormat.setForeground(Qt::red);
quotationFormat.setForeground(Qt::darkGreen);
rule.pattern = QRegExp(“”.*””);
rule.format = quotationFormat;
highlightingRules.append(rule);
functionFormat.setFontItalic(true);
functionFormat.setForeground(Qt::blue);
rule.pattern = QRegExp(“\b[A-Za-z0-9_]+(?=\()”);
rule.format = functionFormat;
highlightingRules.append(rule);
commentStartExpression = QRegExp(“/\*”);
commentEndExpression = QRegExp(“\*/”);
}

7. mainwindow.h/mainwindow.cpp

mainwindow.h
This sets up the definition for various slots which will be activated when the corresponding signal is emitted from the application UI. It also defines functions for setting up various application menus.

#include <QMainWindow>
#include “codeColor.h”
class QTextEdit;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
public slots:
void about();
void newFile();
void openFile(const QString &path = QString());
private:
void setupEditor();
void setupFileMenu();
void setupHelpMenu();
QTextEdit *editor;
codeColor *highlighter;
};
mainwindow.cpp
#include <QtGui>
#include “mainwindow.h”

×