From 664e37abfe5c796c1279b8295fb030f126b0a7d8 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 30 Nov 2011 11:36:13 -0600 Subject: Initial import of qscintilla from 2007 --- example/License.txt | 20 ++++ example/README | 12 +++ example/application.cpp | 271 ++++++++++++++++++++++++++++++++++++++++++++++++ example/application.h | 48 +++++++++ example/application.pro | 10 ++ example/fileopen.xpm | 22 ++++ example/fileprint.xpm | 24 +++++ example/filesave.xpm | 22 ++++ example/main.cpp | 21 ++++ 9 files changed, 450 insertions(+) create mode 100755 example/License.txt create mode 100644 example/README create mode 100644 example/application.cpp create mode 100644 example/application.h create mode 100644 example/application.pro create mode 100644 example/fileopen.xpm create mode 100644 example/fileprint.xpm create mode 100644 example/filesave.xpm create mode 100644 example/main.cpp (limited to 'example') diff --git a/example/License.txt b/example/License.txt new file mode 100755 index 0000000..cbe25b2 --- /dev/null +++ b/example/License.txt @@ -0,0 +1,20 @@ +License for Scintilla and SciTE + +Copyright 1998-2003 by Neil Hodgson + +All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation. + +NEIL HODGSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS, IN NO EVENT SHALL NEIL HODGSON BE LIABLE FOR ANY +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE +OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/example/README b/example/README new file mode 100644 index 0000000..6ffa2ea --- /dev/null +++ b/example/README @@ -0,0 +1,12 @@ +QSCINTILLA EXAMPLE + +This directory contains a port of the standard application example included +with Qt that uses QScintilla rather than QTextEdit. + +To build the example on all platforms, make sure QScintilla is installed and +then run: + + qmake application + make + +On Windows you may need to run "nmake" rather than "make". diff --git a/example/application.cpp b/example/application.cpp new file mode 100644 index 0000000..a4cca36 --- /dev/null +++ b/example/application.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +** $Id: application.cpp,v 1.1 2004/09/18 17:31:23 phil Exp $ +** +** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "application.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "filesave.xpm" +#include "fileopen.xpm" +#include "fileprint.xpm" + +ApplicationWindow::ApplicationWindow() + : QMainWindow( 0, "example application main window", WDestructiveClose | WGroupLeader ) +{ + printer = new QextScintillaPrinter( QPrinter::HighResolution ); + QPixmap openIcon, saveIcon, printIcon; + + QToolBar * fileTools = new QToolBar( this, "file operations" ); + fileTools->setLabel( "File Operations" ); + + openIcon = QPixmap( fileopen ); + QToolButton * fileOpen + = new QToolButton( openIcon, "Open File", QString::null, + this, SLOT(choose()), fileTools, "open file" ); + + saveIcon = QPixmap( filesave ); + QToolButton * fileSave + = new QToolButton( saveIcon, "Save File", QString::null, + this, SLOT(save()), fileTools, "save file" ); + + printIcon = QPixmap( fileprint ); + QToolButton * filePrint + = new QToolButton( printIcon, "Print File", QString::null, + this, SLOT(print()), fileTools, "print file" ); + + + (void)QWhatsThis::whatsThisButton( fileTools ); + + const char * fileOpenText = "

" + "Click this button to open a new file.
" + "You can also select the Open command " + "from the File menu.

"; + + QWhatsThis::add( fileOpen, fileOpenText ); + + QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", openIcon ); + + const char * fileSaveText = "

Click this button to save the file you " + "are editing. You will be prompted for a file name.\n" + "You can also select the Save command " + "from the File menu.

"; + + QWhatsThis::add( fileSave, fileSaveText ); + + const char * filePrintText = "Click this button to print the file you " + "are editing.\n" + "You can also select the Print command " + "from the File menu."; + + QWhatsThis::add( filePrint, filePrintText ); + + + QPopupMenu * file = new QPopupMenu( this ); + menuBar()->insertItem( "&File", file ); + + + file->insertItem( "&New", this, SLOT(newDoc()), CTRL+Key_N ); + + int id; + id = file->insertItem( openIcon, "&Open...", + this, SLOT(choose()), CTRL+Key_O ); + file->setWhatsThis( id, fileOpenText ); + + id = file->insertItem( saveIcon, "&Save", + this, SLOT(save()), CTRL+Key_S ); + file->setWhatsThis( id, fileSaveText ); + + id = file->insertItem( "Save &As...", this, SLOT(saveAs()) ); + file->setWhatsThis( id, fileSaveText ); + + file->insertSeparator(); + + id = file->insertItem( printIcon, "&Print...", + this, SLOT(print()), CTRL+Key_P ); + file->setWhatsThis( id, filePrintText ); + + file->insertSeparator(); + + file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_W ); + + file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); + + menuBar()->insertSeparator(); + + QPopupMenu * help = new QPopupMenu( this ); + menuBar()->insertItem( "&Help", help ); + + help->insertItem( "&About", this, SLOT(about()), Key_F1 ); + help->insertItem( "About &Qt", this, SLOT(aboutQt()) ); + help->insertSeparator(); + help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 ); + + e = new QextScintilla( this, "editor" ); + e->setFocus(); + setCentralWidget( e ); + statusBar()->message( "Ready", 2000 ); + + resize( 450, 600 ); +} + + +ApplicationWindow::~ApplicationWindow() +{ + delete printer; +} + + + +void ApplicationWindow::newDoc() +{ + ApplicationWindow *ed = new ApplicationWindow; + ed->setCaption("QScintilla Example - Application"); + ed->show(); +} + +void ApplicationWindow::choose() +{ + QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, + this); + if ( !fn.isEmpty() ) + load( fn ); + else + statusBar()->message( "Loading aborted", 2000 ); +} + + +void ApplicationWindow::load( const QString &fileName ) +{ + QFile f( fileName ); + if ( !f.open( IO_ReadOnly ) ) + return; + + QTextStream ts( &f ); + e->setText( ts.read() ); + e->setModified( FALSE ); + setCaption( fileName ); + statusBar()->message( "Loaded document " + fileName, 2000 ); +} + + +void ApplicationWindow::save() +{ + if ( filename.isEmpty() ) { + saveAs(); + return; + } + + QString text = e->text(); + QFile f( filename ); + if ( !f.open( IO_WriteOnly ) ) { + statusBar()->message( QString("Could not write to %1").arg(filename), + 2000 ); + return; + } + + QTextStream t( &f ); + t << text; + f.close(); + + e->setModified( FALSE ); + + setCaption( filename ); + + statusBar()->message( QString( "File %1 saved" ).arg( filename ), 2000 ); +} + + +void ApplicationWindow::saveAs() +{ + QString fn = QFileDialog::getSaveFileName( QString::null, QString::null, + this ); + if ( !fn.isEmpty() ) { + filename = fn; + save(); + } else { + statusBar()->message( "Saving aborted", 2000 ); + } +} + + +void ApplicationWindow::print() +{ + printer->setFullPage( TRUE ); + if ( printer->setup(this) ) { // printer dialog + statusBar()->message( "Printing..." ); + + if (printer->printRange( e )) + statusBar()->message( "Printing completed", 2000 ); + else + statusBar()->message( "Error while printing", 2000 ); + } else { + statusBar()->message( "Printing aborted", 2000 ); + } +} + +void ApplicationWindow::closeEvent( QCloseEvent* ce ) +{ + if ( !e->isModified() ) { + ce->accept(); + return; + } + + switch( QMessageBox::information( this, "QScintilla Application Example", + "Do you want to save the changes" + " to the document?", + "Yes", "No", "Cancel", + 0, 1 ) ) { + case 0: + save(); + ce->accept(); + break; + case 1: + ce->accept(); + break; + case 2: + default: // just for sanity + ce->ignore(); + break; + } +} + + +void ApplicationWindow::about() +{ + QMessageBox::about( this, "QScintilla Application Example", + "This example demonstrates a simple use of " + "QextScintilla and QextScintillaPrinter."); +} + + +void ApplicationWindow::aboutQt() +{ + QMessageBox::aboutQt( this, "QScintilla Application Example" ); +} diff --git a/example/application.h b/example/application.h new file mode 100644 index 0000000..6f48d41 --- /dev/null +++ b/example/application.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** $Id: application.h,v 1.1 2004/09/18 17:31:23 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef APPLICATION_H +#define APPLICATION_H + +#include + +class QextScintilla; +class QextScintillaPrinter; + +class ApplicationWindow: public QMainWindow +{ + Q_OBJECT + +public: + ApplicationWindow(); + ~ApplicationWindow(); + +protected: + void closeEvent( QCloseEvent* ); + +private slots: + void newDoc(); + void choose(); + void load( const QString &fileName ); + void save(); + void saveAs(); + void print(); + + void about(); + void aboutQt(); + +private: + QextScintillaPrinter *printer; + QextScintilla *e; + QString filename; +}; + + +#endif diff --git a/example/application.pro b/example/application.pro new file mode 100644 index 0000000..160beaa --- /dev/null +++ b/example/application.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = application + +CONFIG += qt warn_on release + +LIBS += -lqscintilla + +HEADERS = application.h +SOURCES = application.cpp \ + main.cpp diff --git a/example/fileopen.xpm b/example/fileopen.xpm new file mode 100644 index 0000000..880417e --- /dev/null +++ b/example/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; diff --git a/example/fileprint.xpm b/example/fileprint.xpm new file mode 100644 index 0000000..6ada912 --- /dev/null +++ b/example/fileprint.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static const char *fileprint[] = { +" 16 14 6 1", +". c #000000", +"# c #848284", +"a c #c6c3c6", +"b c #ffff00", +"c c #ffffff", +"d c None", +"ddddd.........dd", +"dddd.cccccccc.dd", +"dddd.c.....c.ddd", +"ddd.cccccccc.ddd", +"ddd.c.....c....d", +"dd.cccccccc.a.a.", +"d..........a.a..", +".aaaaaaaaaa.a.a.", +".............aa.", +".aaaaaa###aa.a.d", +".aaaaaabbbaa...d", +".............a.d", +"d.aaaaaaaaa.a.dd", +"dd...........ddd" +}; diff --git a/example/filesave.xpm b/example/filesave.xpm new file mode 100644 index 0000000..bd6870f --- /dev/null +++ b/example/filesave.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *filesave[] = { +" 14 14 4 1", +". c #040404", +"# c #808304", +"a c #bfc2bf", +"b c None", +"..............", +".#.aaaaaaaa.a.", +".#.aaaaaaaa...", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".##........##.", +".############.", +".##.........#.", +".##......aa.#.", +".##......aa.#.", +".##......aa.#.", +"b............." +}; diff --git a/example/main.cpp b/example/main.cpp new file mode 100644 index 0000000..3c2722c --- /dev/null +++ b/example/main.cpp @@ -0,0 +1,21 @@ +/**************************************************************************** +** $Id: main.cpp,v 1.1 2004/09/18 17:31:23 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include +#include "application.h" + +int main( int argc, char ** argv ) { + QApplication a( argc, argv ); + ApplicationWindow *mw = new ApplicationWindow(); + mw->setCaption( "QScintilla Example - Application" ); + mw->show(); + a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); + return a.exec(); +} -- cgit v1.2.1