Official website for Linux User & Developer
FOLLOW US ON:
Mar
16

Develop for the Nokia N900 and Maemo 5 OS!

by Kunal Deo

Learn how to program the next-generation smartphone-come-internet tablet, the 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”

Pages: 1 2 3 4 5 6 7
  • Tell a Friend
  • Follow our Twitter to find out about all the latest Linux news, reviews, previews, interviews, features and a whole more.

    5 Comments »

    • Ray McConaghy said:

      When I finally run the program (codeColor) I get the following error ( this is, however the latest SDK for Maemo5). Can you help?

      [sbox-FREMANTLE_X86: ~/codeColor] > run-standalone.sh ./codeColor
      codeColor[3820]: GLIB CRITICAL ** Gtk – gtk_widget_set_sensitive: assertion `GTK_IS_WIDGET (widget)’ failed

      Also, I got confused with the article… it asked me to create a directory called …/codeColor… but the prompt in your article showed you running in scratchbox in a directory …/codeEditor ( where did that come from?). I am a newbie so perhaps these are stupid questions!!

      Best regards

    • Ricardo said:

      I’m not able to access this full article, clicking the diferent page numbers or even directly loading the URL in my browsers always redirects to first page.

      Tested with Firefox 3.6.8 and Opera 10.61.

      Bug? Anyone else having the same problem?

    • Sean said:

      Same problem here, can’t get past page 1. Using IE 7 on Vista.

    • florian said:

      will not go past Page 1.
      it would be awesome if someone could fix this.Thanks.

      Florian, using maemo 5 browser

    • Russell Barnes said:

      Fixed – thanks for picking up on it.

    What's your opinion?

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    * Required fields