summaryrefslogtreecommitdiffstats
path: root/kdeprint/tests
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /kdeprint/tests
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdeprint/tests')
-rw-r--r--kdeprint/tests/Makefile.am15
-rw-r--r--kdeprint/tests/back.xpm105
-rw-r--r--kdeprint/tests/drawdemo.cpp253
-rw-r--r--kdeprint/tests/drawdemo.h30
-rw-r--r--kdeprint/tests/forward.xpm110
-rw-r--r--kdeprint/tests/helpwindow.cpp351
-rw-r--r--kdeprint/tests/helpwindow.h65
-rw-r--r--kdeprint/tests/home.xpm119
-rw-r--r--kdeprint/tests/main.cpp41
-rw-r--r--kdeprint/tests/richpage.cpp85
-rw-r--r--kdeprint/tests/richpage.h24
11 files changed, 1198 insertions, 0 deletions
diff --git a/kdeprint/tests/Makefile.am b/kdeprint/tests/Makefile.am
new file mode 100644
index 000000000..e27cad3db
--- /dev/null
+++ b/kdeprint/tests/Makefile.am
@@ -0,0 +1,15 @@
+INCLUDES = -I$(top_srcdir)/kdeprint -I$(top_srcdir) $(all_includes)
+
+check_PROGRAMS = helpviewer drawdemo
+
+helpviewer_SOURCES = helpwindow.cpp main.cpp richpage.cpp
+helpviewer_METASOURCES = helpwindow.moc
+helpviewer_LDADD = $(top_builddir)/kdeprint/libkdeprint.la
+helpviewer_LDFLAGS = $(all_libraries)
+
+drawdemo_SOURCES = drawdemo.cpp
+drawdemo_METASOURCES = drawdemo.moc
+drawdemo_LDADD = $(top_builddir)/kdeprint/libkdeprint.la
+drawdemo_LDFLAGS = $(all_libraries)
+
+EXTRA_DIST = home.xpm back.xpm forward.xpm
diff --git a/kdeprint/tests/back.xpm b/kdeprint/tests/back.xpm
new file mode 100644
index 000000000..ac57ecd0b
--- /dev/null
+++ b/kdeprint/tests/back.xpm
@@ -0,0 +1,105 @@
+/* XPM */
+static char * back_xpm[] = {
+"16 16 86 1",
+" c None",
+". c #3269D2",
+"+ c #326CD7",
+"@ c #3472E5",
+"# c #5183E0",
+"$ c #5B88DC",
+"% c #3472E4",
+"& c #326BD4",
+"* c #3368CA",
+"= c #326AD3",
+"- c #4980E6",
+"; c #A8C2F5",
+"> c #E4EBF8",
+", c #F2F5FB",
+"' c #EBF0FA",
+") c #B9CCF0",
+"! c #5789E4",
+"~ c #3269CE",
+"{ c #326AD2",
+"] c #6494EC",
+"^ c #D4E0F4",
+"/ c #E1E9F8",
+"( c #ABC1EC",
+"_ c #DCE6F6",
+": c #799FE5",
+"< c #3269CF",
+"[ c #C4D4F1",
+"} c #CDDAF4",
+"| c #FFFFFF",
+"1 c #CBD9F3",
+"2 c #5A8AE3",
+"3 c #3467C4",
+"4 c #90B1EC",
+"5 c #B8CCEE",
+"6 c #EDF2FA",
+"7 c #B7CAEE",
+"8 c #97B3E4",
+"9 c #3873E0",
+"0 c #A1BAE9",
+"a c #A3BCEA",
+"b c #E7EEF9",
+"c c #95B1E6",
+"d c #4987F8",
+"e c #3B80FF",
+"f c #3471E3",
+"g c #4A7FE2",
+"h c #8CACE5",
+"i c #CEDFFF",
+"j c #3676EB",
+"k c #447CE5",
+"l c #6E99E8",
+"m c #B9CEF4",
+"n c #3C81FF",
+"o c #3776EB",
+"p c #3C66B6",
+"q c #3572E4",
+"r c #4686FC",
+"s c #D0E0FE",
+"t c #9DC0FF",
+"u c #6DA1FF",
+"v c #4083FF",
+"w c #4887FC",
+"x c #4888FC",
+"y c #D1E1FE",
+"z c #6CA0FF",
+"A c #4083FE",
+"B c #4486FC",
+"C c #4687FC",
+"D c #4A80E4",
+"E c #6696EE",
+"F c #D8E4FA",
+"G c #3766BE",
+"H c #346ACC",
+"I c #6C94E0",
+"J c #7EA3E6",
+"K c #DEE7F8",
+"L c #3469CB",
+"M c #356ACC",
+"N c #658EDB",
+"O c #8DACE7",
+"P c #8EADE8",
+"Q c #3569CA",
+"R c #3E71CF",
+"S c #5E88D5",
+"T c #6E95DC",
+"U c #3E70CF",
+" ",
+" .+@#$%&* ",
+" =-;>,,')!~ ",
+" {]^//((//_:~ ",
+" <-[}}(||(}}123 ",
+" &455(||655578= ",
+" 90a(||baaacdef ",
+" gh(||||||||iej ",
+" klm|||||||||nop",
+" qrrs||ittttuv% ",
+" &wxxy||znABCw= ",
+" *DEEEF||EEEEDG ",
+" HIJJJKKJJJIL ",
+" MNOPPPPONQ ",
+" 3RSTTSUG ",
+" p "};
diff --git a/kdeprint/tests/drawdemo.cpp b/kdeprint/tests/drawdemo.cpp
new file mode 100644
index 000000000..f399d7d6d
--- /dev/null
+++ b/kdeprint/tests/drawdemo.cpp
@@ -0,0 +1,253 @@
+/****************************************************************************
+** $Id$
+**
+** 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 <qwidget.h>
+#include <qpainter.h>
+#include <kprinter.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+#include <qbuttongroup.h>
+#include <kapplication.h>
+#include <qapplication.h>
+#include <math.h>
+
+
+//
+// This function draws a color wheel.
+// The coordinate system x=(0..500), y=(0..500) spans the paint device.
+//
+
+void drawColorWheel( QPainter *p )
+{
+ QFont f( "times", 18, QFont::Bold );
+ p->setFont( f );
+ p->setPen( Qt::black );
+ p->setWindow( 0, 0, 500, 500 ); // defines coordinate system
+
+ for ( int i=0; i<36; i++ ) { // draws 36 rotated rectangles
+
+ QWMatrix matrix;
+ matrix.translate( 250.0F, 250.0F ); // move to center
+ matrix.shear( 0.0F, 0.3F ); // twist it
+ matrix.rotate( (float)i*10 ); // rotate 0,10,20,.. degrees
+ p->setWorldMatrix( matrix ); // use this world matrix
+
+ QColor c;
+ c.setHsv( i*10, 255, 255 ); // rainbow effect
+ p->setBrush( c ); // solid fill with color c
+ p->drawRect( 70, -10, 80, 10 ); // draw the rectangle
+
+ QString n;
+ n.sprintf( "H=%d", i*10 );
+ p->drawText( 80+70+5, 0, n ); // draw the hue number
+ }
+}
+
+
+//
+// This function draws a few lines of text using different fonts.
+//
+
+void drawFonts( QPainter *p )
+{
+ static const char *fonts[] = { "Helvetica", "Courier", "Times", 0 };
+ static int sizes[] = { 10, 12, 18, 24, 36, 0 };
+ int f = 0;
+ int y = 0;
+ while ( fonts[f] ) {
+ int s = 0;
+ while ( sizes[s] ) {
+ QFont font( fonts[f], sizes[s] );
+ p->setFont( font );
+ QFontMetrics fm = p->fontMetrics();
+ y += fm.ascent();
+ p->drawText( 10, y, "Quartz Glyph Job Vex'd Cwm Finks" );
+ y += fm.descent();
+ s++;
+ }
+ f++;
+ }
+}
+
+
+//
+// This function draws some shapes
+//
+
+void drawShapes( QPainter *p )
+{
+ QBrush b1( Qt::blue );
+ QBrush b2( Qt::green, Qt::Dense6Pattern ); // green 12% fill
+ QBrush b3( Qt::NoBrush ); // void brush
+ QBrush b4( Qt::CrossPattern ); // black cross pattern
+
+ p->setPen( Qt::red );
+ p->setBrush( b1 );
+ p->drawRect( 10, 10, 200, 100 );
+ p->setBrush( b2 );
+ p->drawRoundRect( 10, 150, 200, 100, 20, 20 );
+ p->setBrush( b3 );
+ p->drawEllipse( 250, 10, 200, 100 );
+ p->setBrush( b4 );
+ p->drawPie( 250, 150, 200, 100, 45*16, 90*16 );
+}
+
+
+typedef void (*draw_func)(QPainter*);
+
+struct DrawThing {
+ draw_func f;
+ const char *name;
+};
+
+//
+// You can add your draw function here.
+// Leave the zeros at the end of the array!
+//
+
+DrawThing ourDrawFunctions[] = {
+ { drawColorWheel, "Draw color wheel" },
+ { drawFonts, "Draw fonts" },
+ { drawShapes, "Draw shapes" },
+ { 0, 0 } };
+
+
+#include "drawdemo.h"
+
+//
+// Construct the DrawView with buttons.
+//
+
+DrawView::DrawView()
+{
+ setCaption( "Qt Draw Demo Application" );
+ setBackgroundColor( white );
+
+ // Create a button group to contain all buttons
+ bgroup = new QButtonGroup( this );
+ bgroup->resize( 200, 200 );
+ connect( bgroup, SIGNAL(clicked(int)), SLOT(updateIt(int)) );
+
+ // Calculate the size for the radio buttons
+ int maxwidth = 80;
+ int i;
+ const char *n;
+ QFontMetrics fm = bgroup->fontMetrics();
+ for ( i=0; (n=ourDrawFunctions[i].name) != 0; i++ ) {
+ int w = fm.width( n );
+ maxwidth = QMAX(w,maxwidth);
+ }
+ maxwidth = maxwidth + 20; // add 20 pixels
+
+ for ( i=0; (n=ourDrawFunctions[i].name) != 0; i++ ) {
+ QRadioButton *rb = new QRadioButton( n, bgroup );
+ rb->setGeometry( 10, i*30+10, maxwidth, 30 );
+ if ( i == 0 )
+ rb->setChecked( true );
+ }
+
+ drawindex = 0; // draw first thing
+ maxindex = i;
+
+ maxwidth += 40; // now size of bgroup
+
+ printer = new KPrinter;
+
+ // Create and setup the print button
+ print = new QPushButton( "Print...", bgroup );
+ print->resize( 80, 30 );
+ print->move( maxwidth/2 - print->width()/2, maxindex*30+20 );
+ connect( print, SIGNAL(clicked()), SLOT(printIt()) );
+
+ bgroup->resize( maxwidth, print->y()+print->height()+10 );
+
+ resize( 640,300 );
+}
+
+//
+// Clean up
+//
+DrawView::~DrawView()
+{
+#ifndef QT_NO_PRINTER
+ delete printer;
+#endif
+}
+
+//
+// Called when a radio button is clicked.
+//
+
+void DrawView::updateIt( int index )
+{
+ if ( index < maxindex ) {
+ drawindex = index;
+ update();
+ }
+}
+
+//
+// Calls the drawing function as specified by the radio buttons.
+//
+
+void DrawView::drawIt( QPainter *p )
+{
+ (*ourDrawFunctions[drawindex].f)(p);
+}
+
+//
+// Called when the print button is clicked.
+//
+
+void DrawView::printIt()
+{
+#ifndef QT_NO_PRINTER
+ if ( printer->setup( this ) ) {
+ QPainter paint( printer );
+ drawIt( &paint );
+ }
+#endif
+}
+
+//
+// Called when the widget needs to be updated.
+//
+
+void DrawView::paintEvent( QPaintEvent * )
+{
+ QPainter paint( this );
+ drawIt( &paint );
+}
+
+//
+// Called when the widget has been resized.
+// Moves the button group to the upper right corner
+// of the widget.
+
+void DrawView::resizeEvent( QResizeEvent * )
+{
+ bgroup->move( width()-bgroup->width(), 0 );
+}
+
+
+//
+// Create and display our widget.
+//
+
+#include "drawdemo.moc"
+
+int main( int argc, char **argv )
+{
+ KApplication app( argc, argv, "drawdemo" );
+ DrawView draw;
+ app.setMainWidget( &draw );
+ draw.show();
+ return app.exec();
+}
diff --git a/kdeprint/tests/drawdemo.h b/kdeprint/tests/drawdemo.h
new file mode 100644
index 000000000..81b201d54
--- /dev/null
+++ b/kdeprint/tests/drawdemo.h
@@ -0,0 +1,30 @@
+#ifndef DRAWDEMO_H
+#define DRAWDEMO_H
+
+//
+// DrawView has installable draw routines, just add a function pointer
+// and a text in the table above.
+//
+
+class DrawView : public QWidget
+{
+ Q_OBJECT
+public:
+ DrawView();
+ ~DrawView();
+public slots:
+ void updateIt( int );
+ void printIt();
+protected:
+ void drawIt( QPainter * );
+ void paintEvent( QPaintEvent * );
+ void resizeEvent( QResizeEvent * );
+private:
+ KPrinter *printer;
+ QButtonGroup *bgroup;
+ QPushButton *print;
+ int drawindex;
+ int maxindex;
+};
+
+#endif
diff --git a/kdeprint/tests/forward.xpm b/kdeprint/tests/forward.xpm
new file mode 100644
index 000000000..7eadb1474
--- /dev/null
+++ b/kdeprint/tests/forward.xpm
@@ -0,0 +1,110 @@
+/* XPM */
+static char * forward_xpm[] = {
+"16 16 91 1",
+" c None",
+". c #3269D2",
+"+ c #326CD7",
+"@ c #3472E5",
+"# c #5183E0",
+"$ c #5B88DC",
+"% c #3472E4",
+"& c #326BD4",
+"* c #3368CA",
+"= c #326AD3",
+"- c #4980E6",
+"; c #A8C2F5",
+"> c #E4EBF8",
+", c #F2F5FB",
+"' c #EBF0FA",
+") c #B9CCF0",
+"! c #5789E4",
+"~ c #3269CE",
+"{ c #326AD2",
+"] c #6494EC",
+"^ c #D4E0F4",
+"/ c #E1E9F8",
+"( c #AAC4F4",
+"_ c #DCE6F6",
+": c #799FE5",
+"< c #3269CF",
+"[ c #C4D4F1",
+"} c #CDDAF4",
+"| c #FFFFFF",
+"1 c #A5C1F4",
+"2 c #CBD9F3",
+"3 c #5A8AE3",
+"4 c #3467C4",
+"5 c #90B1EC",
+"6 c #B8CCEE",
+"7 c #ECF1FA",
+"8 c #A0BDF2",
+"9 c #B7CAEE",
+"0 c #97B3E4",
+"a c #3873E0",
+"b c #A1BAE9",
+"c c #94B2EB",
+"d c #85A9EC",
+"e c #D8E4FA",
+"f c #95B4EF",
+"g c #4987F8",
+"h c #3B80FF",
+"i c #3471E3",
+"j c #4A7FE2",
+"k c #8CACE5",
+"l c #6CA0FF",
+"m c #3676EB",
+"n c #447CE5",
+"o c #6E99E8",
+"p c #9EC0FF",
+"q c #3C81FF",
+"r c #3776EB",
+"s c #3C66B6",
+"t c #3572E4",
+"u c #4686FC",
+"v c #73A4FD",
+"w c #A0C2FE",
+"x c #A0C2FF",
+"y c #CEE0FF",
+"z c #3D82FF",
+"A c #4083FF",
+"B c #4887FC",
+"C c #4888FC",
+"D c #4084FF",
+"E c #6DA0FF",
+"F c #D2E2FE",
+"G c #4486FC",
+"H c #4687FC",
+"I c #4A80E4",
+"J c #6696EE",
+"K c #DAE6FA",
+"L c #3766BE",
+"M c #346ACC",
+"N c #6C94E0",
+"O c #7EA3E6",
+"P c #E0E9F9",
+"Q c #3469CB",
+"R c #356ACC",
+"S c #658EDB",
+"T c #8DACE7",
+"U c #8EADE8",
+"V c #3569CA",
+"W c #3E71CF",
+"X c #5E88D5",
+"Y c #6E95DC",
+"Z c #3E70CF",
+" ",
+" .+@#$%&* ",
+" =-;>,,')!~ ",
+" {]^//((//_:~ ",
+" <-[}}}||1}}234 ",
+" &566667||8690= ",
+" abcdddde||fghi ",
+" jke||||||||lhm ",
+" no|||||||||pqrs",
+" tuvwxxpy||yzA% ",
+" &BCCCDE||FGHB= ",
+" *IJJJJ||KJJJIL ",
+" MNOOOPPOOONQ ",
+" RSTUUUUTSV ",
+" 4WXYYXZL ",
+" s "};
diff --git a/kdeprint/tests/helpwindow.cpp b/kdeprint/tests/helpwindow.cpp
new file mode 100644
index 000000000..4fdc6d7a5
--- /dev/null
+++ b/kdeprint/tests/helpwindow.cpp
@@ -0,0 +1,351 @@
+/****************************************************************************
+** $Id$
+**
+** 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 "helpwindow.h"
+#include "richpage.h"
+#include <qstatusbar.h>
+#include <qpixmap.h>
+#include <qpopupmenu.h>
+#include <kmenubar.h>
+#include <ktoolbar.h>
+#include <kstatusbar.h>
+#include <qtoolbutton.h>
+#include <qiconset.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qstylesheet.h>
+#include <qmessagebox.h>
+#include <qfiledialog.h>
+#include <qapplication.h>
+#include <qcombobox.h>
+#include <qevent.h>
+#include <qlineedit.h>
+#include <qobjectlist.h>
+#include <qfileinfo.h>
+#include <qdatastream.h>
+#include <kprinter.h>
+#include <qsimplerichtext.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
+
+#include <ctype.h>
+
+HelpWindow::HelpWindow( const QString& home_, const QString& _path,
+ QWidget* parent, const char *name )
+ : KMainWindow( parent, name, WDestructiveClose ),
+ pathCombo( 0 ), selectedURL()
+{
+ readHistory();
+ readBookmarks();
+
+ browser = new QTextBrowser( this );
+ browser->mimeSourceFactory()->setFilePath( _path );
+ browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
+ connect( browser, SIGNAL( textChanged() ),
+ this, SLOT( textChanged() ) );
+
+ setCentralWidget( browser );
+
+ if ( !home_.isEmpty() )
+ browser->setSource( home_ );
+
+ connect( browser, SIGNAL( highlighted( const QString&) ),
+ statusBar(), SLOT( message( const QString&)) );
+
+ resize( 640,700 );
+
+ QPopupMenu* file = new QPopupMenu( this );
+ file->insertItem( "&New Window", this, SLOT( newWindow() ), ALT | Key_N );
+ file->insertItem( "&Open File", this, SLOT( openFile() ), ALT | Key_O );
+ file->insertItem( "&Print", this, SLOT( print() ), ALT | Key_P );
+ file->insertSeparator();
+ file->insertItem( "&Close", this, SLOT( close() ), ALT | Key_Q );
+ file->insertItem( "E&xit", qApp, SLOT( closeAllWindows() ), ALT | Key_X );
+
+ // The same three icons are used twice each.
+ QIconSet icon_back( QPixmap("back.xpm") );
+ QIconSet icon_forward( QPixmap("forward.xpm") );
+ QIconSet icon_home( QPixmap("home.xpm") );
+
+ QPopupMenu* go = new QPopupMenu( this );
+ backwardId = go->insertItem( icon_back,
+ "&Backward", browser, SLOT( backward() ),
+ ALT | Key_Left );
+ forwardId = go->insertItem( icon_forward,
+ "&Forward", browser, SLOT( forward() ),
+ ALT | Key_Right );
+ go->insertItem( icon_home, "&Home", browser, SLOT( home() ) );
+
+ QPopupMenu* help = new QPopupMenu( this );
+ help->insertItem( "&About ...", this, SLOT( about() ) );
+ help->insertItem( "About &Qt ...", this, SLOT( aboutQt() ) );
+
+ hist = new QPopupMenu( this );
+ QStringList::Iterator it = history.begin();
+ for ( ; it != history.end(); ++it )
+ mHistory[ hist->insertItem( *it ) ] = *it;
+ connect( hist, SIGNAL( activated( int ) ),
+ this, SLOT( histChosen( int ) ) );
+
+ bookm = new QPopupMenu( this );
+ bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) );
+ bookm->insertSeparator();
+
+ QStringList::Iterator it2 = bookmarks.begin();
+ for ( ; it2 != bookmarks.end(); ++it2 )
+ mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
+ connect( bookm, SIGNAL( activated( int ) ),
+ this, SLOT( bookmChosen( int ) ) );
+
+ menuBar()->insertItem( tr("&File"), file );
+ menuBar()->insertItem( tr("&Go"), go );
+ menuBar()->insertItem( tr( "History" ), hist );
+ menuBar()->insertItem( tr( "Bookmarks" ), bookm );
+ menuBar()->insertSeparator();
+ menuBar()->insertItem( tr("&Help"), help );
+
+ menuBar()->setItemEnabled( forwardId, false);
+ menuBar()->setItemEnabled( backwardId, false);
+ connect( browser, SIGNAL( backwardAvailable( bool ) ),
+ this, SLOT( setBackwardAvailable( bool ) ) );
+ connect( browser, SIGNAL( forwardAvailable( bool ) ),
+ this, SLOT( setForwardAvailable( bool ) ) );
+
+
+ QToolBar* toolbar = new QToolBar( this );
+ addToolBar( toolbar, "Toolbar");
+ QToolButton* button;
+
+ button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar );
+ connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
+ button->setEnabled( false );
+ button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar );
+ connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
+ button->setEnabled( false );
+ button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar );
+
+ toolbar->addSeparator();
+
+ pathCombo = new QComboBox( true, toolbar );
+ connect( pathCombo, SIGNAL( activated( const QString & ) ),
+ this, SLOT( pathSelected( const QString & ) ) );
+ toolbar->setStretchableWidget( pathCombo );
+ setRightJustification( true );
+ setDockEnabled( DockLeft, false );
+ setDockEnabled( DockRight, false );
+
+ pathCombo->insertItem( home_ );
+
+ browser->setFocus();
+}
+
+
+void HelpWindow::setBackwardAvailable( bool b)
+{
+ menuBar()->setItemEnabled( backwardId, b);
+}
+
+void HelpWindow::setForwardAvailable( bool b)
+{
+ menuBar()->setItemEnabled( forwardId, b);
+}
+
+
+void HelpWindow::textChanged()
+{
+ if ( browser->documentTitle().isNull() )
+ setCaption( browser->context() );
+ else
+ setCaption( browser->documentTitle() ) ;
+
+ selectedURL = caption();
+ if ( !selectedURL.isEmpty() && pathCombo ) {
+ bool exists = false;
+ int i;
+ for ( i = 0; i < pathCombo->count(); ++i ) {
+ if ( pathCombo->text( i ) == selectedURL ) {
+ exists = true;
+ break;
+ }
+ }
+ if ( !exists ) {
+ pathCombo->insertItem( selectedURL, 0 );
+ pathCombo->setCurrentItem( 0 );
+ mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
+ } else
+ pathCombo->setCurrentItem( i );
+ selectedURL = QString::null;
+ }
+}
+
+HelpWindow::~HelpWindow()
+{
+ history.clear();
+ QMap<int, QString>::Iterator it = mHistory.begin();
+ for ( ; it != mHistory.end(); ++it )
+ history.append( *it );
+
+ QFile f( QDir::currentDirPath() + "/.history" );
+ f.open( IO_WriteOnly );
+ QDataStream s( &f );
+ s << history;
+ f.close();
+
+ bookmarks.clear();
+ QMap<int, QString>::Iterator it2 = mBookmarks.begin();
+ for ( ; it2 != mBookmarks.end(); ++it2 )
+ bookmarks.append( *it2 );
+
+ QFile f2( QDir::currentDirPath() + "/.bookmarks" );
+ f2.open( IO_WriteOnly );
+ QDataStream s2( &f2 );
+ s2 << bookmarks;
+ f2.close();
+}
+
+void HelpWindow::about()
+{
+ QMessageBox::about( this, "HelpViewer Example",
+ "<p>This example implements a simple HTML help viewer "
+ "using Qt's rich text capabilities</p>"
+ "<p>It's just about 100 lines of C++ code, so don't expect too much :-)</p>"
+ );
+}
+
+
+void HelpWindow::aboutQt()
+{
+ QMessageBox::aboutQt( this, "QBrowser" );
+}
+
+void HelpWindow::openFile()
+{
+#ifndef QT_NO_FILEDIALOG
+ QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
+ if ( !fn.isEmpty() )
+ browser->setSource( fn );
+#endif
+}
+
+void HelpWindow::newWindow()
+{
+ ( new HelpWindow(browser->source(), "qbrowser") )->show();
+}
+
+#define KDE_PRINT
+void HelpWindow::print()
+{
+#ifdef KDE_PRINT
+ KPrinter printer;
+#else
+ QPrinter printer;
+#endif
+ printer.setFullPage(true);
+ printer.setDocName("Help Viewer");
+ printer.setDocFileName("my_document");
+#ifdef KDE_PRINT
+ printer.addDialogPage(new RichPage());
+ printer.addStandardPage(KPrinter::FilesPage);
+#endif
+ if ( printer.setup(this) ) {
+ QPainter p( &printer );
+ QPaintDeviceMetrics metrics(p.device());
+ int dpix = metrics.logicalDpiX();
+ int dpiy = metrics.logicalDpiY();
+#ifdef KDE_PRINT
+ const int margin = printer.option("app-rich-margin").toInt(); // pt
+#else
+ const int margin = 72; // pt
+#endif
+ QRect body(margin*dpix/72, margin*dpiy/72,
+ metrics.width()-margin*dpix/72*2,
+ metrics.height()-margin*dpiy/72*2 );
+#ifdef KDE_PRINT
+ QFont font(printer.option("app-rich-fontname"), printer.option("app-rich-fontsize").toInt());
+#else
+ QFont font("times",10);
+#endif
+ QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(),
+ browser->mimeSourceFactory(), body.height() );
+ richText.setWidth( &p, body.width() );
+ QRect view( body );
+ int page = 1;
+ do {
+ richText.draw( &p, body.left(), body.top(), view, colorGroup() );
+ view.moveBy( 0, body.height() );
+ p.translate( 0 , -body.height() );
+ p.setFont( font );
+ p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
+ view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
+ if ( view.top() >= richText.height() )
+ break;
+ printer.newPage();
+ page++;
+ } while (true);
+ }
+}
+
+void HelpWindow::pathSelected( const QString &_path )
+{
+ browser->setSource( _path );
+ QMap<int, QString>::Iterator it = mHistory.begin();
+ bool exists = false;
+ for ( ; it != mHistory.end(); ++it ) {
+ if ( *it == _path ) {
+ exists = true;
+ break;
+ }
+ }
+ if ( !exists )
+ mHistory[ hist->insertItem( _path ) ] = _path;
+}
+
+void HelpWindow::readHistory()
+{
+ if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) {
+ QFile f( QDir::currentDirPath() + "/.history" );
+ f.open( IO_ReadOnly );
+ QDataStream s( &f );
+ s >> history;
+ f.close();
+ while ( history.count() > 20 )
+ history.remove( history.begin() );
+ }
+}
+
+void HelpWindow::readBookmarks()
+{
+ if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) {
+ QFile f( QDir::currentDirPath() + "/.bookmarks" );
+ f.open( IO_ReadOnly );
+ QDataStream s( &f );
+ s >> bookmarks;
+ f.close();
+ }
+}
+
+void HelpWindow::histChosen( int i )
+{
+ if ( mHistory.contains( i ) )
+ browser->setSource( mHistory[ i ] );
+}
+
+void HelpWindow::bookmChosen( int i )
+{
+ if ( mBookmarks.contains( i ) )
+ browser->setSource( mBookmarks[ i ] );
+}
+
+void HelpWindow::addBookmark()
+{
+ mBookmarks[ bookm->insertItem( caption() ) ] = caption();
+}
+
+#include "helpwindow.moc"
diff --git a/kdeprint/tests/helpwindow.h b/kdeprint/tests/helpwindow.h
new file mode 100644
index 000000000..1de9e5e2b
--- /dev/null
+++ b/kdeprint/tests/helpwindow.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+** $Id$
+**
+** 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 HELPWINDOW_H
+#define HELPWINDOW_H
+
+#include <kmainwindow.h>
+#include <qtextbrowser.h>
+#include <qstringlist.h>
+#include <qmap.h>
+#include <qdir.h>
+
+class QComboBox;
+class QPopupMenu;
+
+class HelpWindow : public KMainWindow
+{
+ Q_OBJECT
+public:
+ HelpWindow( const QString& home_, const QString& path, QWidget* parent = 0, const char *name=0 );
+ ~HelpWindow();
+
+private slots:
+ void setBackwardAvailable( bool );
+ void setForwardAvailable( bool );
+
+ void textChanged();
+ void about();
+ void aboutQt();
+ void openFile();
+ void newWindow();
+ void print();
+
+ void pathSelected( const QString & );
+ void histChosen( int );
+ void bookmChosen( int );
+ void addBookmark();
+
+private:
+ void readHistory();
+ void readBookmarks();
+
+ QTextBrowser* browser;
+ QComboBox *pathCombo;
+ int backwardId, forwardId;
+ QString selectedURL;
+ QStringList history, bookmarks;
+ QMap<int, QString> mHistory, mBookmarks;
+ QPopupMenu *hist, *bookm;
+
+};
+
+
+
+
+
+#endif
+
diff --git a/kdeprint/tests/home.xpm b/kdeprint/tests/home.xpm
new file mode 100644
index 000000000..1cb22447f
--- /dev/null
+++ b/kdeprint/tests/home.xpm
@@ -0,0 +1,119 @@
+/* XPM */
+static char * home_xpm[] = {
+"16 16 100 2",
+" c None",
+". c #3269D2",
+"+ c #326CD7",
+"@ c #3472E5",
+"# c #5183E0",
+"$ c #5B88DC",
+"% c #3472E4",
+"& c #326BD4",
+"* c #3368CA",
+"= c #326AD3",
+"- c #4980E6",
+"; c #A8C2F5",
+"> c #E4EBF8",
+", c #F2F5FB",
+"' c #EBF0FA",
+") c #B9CCF0",
+"! c #5789E4",
+"~ c #3269CE",
+"{ c #326AD2",
+"] c #6494EC",
+"^ c #D4E0F4",
+"/ c #E1E9F8",
+"( c #A3BCEA",
+"_ c #DCE6F6",
+": c #799FE5",
+"< c #3269CF",
+"[ c #C4D4F1",
+"} c #CDDAF4",
+"| c #FDFDFE",
+"1 c #DDE6F7",
+"2 c #CBD9F3",
+"3 c #5A8AE3",
+"4 c #3467C4",
+"5 c #90B1EC",
+"6 c #B8CCEE",
+"7 c #D5E1F5",
+"8 c #FFFFFF",
+"9 c #FBFCFE",
+"0 c #CEDCF3",
+"a c #B7CAEE",
+"b c #97B3E4",
+"c c #3873E0",
+"d c #A1BAE9",
+"e c #C9D8F2",
+"f c #FCFDFE",
+"g c #B5C8ED",
+"h c #4987F8",
+"i c #3B80FF",
+"j c #3471E3",
+"k c #4A7FE2",
+"l c #8CACE5",
+"m c #8FADE6",
+"n c #BFD0F0",
+"o c #FAFCFE",
+"p c #79A9FF",
+"q c #3676EB",
+"r c #447CE5",
+"s c #6E99E8",
+"t c #9BB8EF",
+"u c #F5F9FF",
+"v c #6098FF",
+"w c #3776EB",
+"x c #3C66B6",
+"y c #3572E4",
+"z c #4686FC",
+"A c #4E8BFC",
+"B c #5D95FC",
+"C c #C2D7FE",
+"D c #9DC0FF",
+"E c #AAC8FF",
+"F c #5591FF",
+"G c #4586FF",
+"H c #4887FC",
+"I c #4888FC",
+"J c #BAD2FD",
+"K c #3C81FF",
+"L c #A1C2FD",
+"M c #4687FC",
+"N c #4A80E4",
+"O c #6696EE",
+"P c #C6D7F8",
+"Q c #B2CAF6",
+"R c #3766BE",
+"S c #346ACC",
+"T c #6C94E0",
+"U c #7EA3E6",
+"V c #B0C7EF",
+"W c #CEDCF5",
+"X c #C0D2F2",
+"Y c #A6BFED",
+"Z c #3469CB",
+"` c #356ACC",
+" . c #658EDB",
+".. c #8DACE7",
+"+. c #8EADE8",
+"@. c #3569CA",
+"#. c #3E71CF",
+"$. c #5E88D5",
+"%. c #6E95DC",
+"&. c #3E70CF",
+" ",
+" . + @ # $ % & * ",
+" = - ; > , , ' ) ! ~ ",
+" { ] ^ / / ( ( ( / _ : ~ ",
+" < - [ } } ( / | 1 ( } 2 3 4 ",
+" & 5 6 6 ( 7 | 8 9 0 ( a b = ",
+" c d ( ( e | 8 8 8 f g h i j ",
+" k l m n 8 8 8 8 8 8 o p i q ",
+" r s t f 8 8 8 8 8 8 8 u v w x ",
+" y z A B C 8 8 D D 8 E F G % ",
+" & H I I J 8 8 K K 8 L M H = ",
+" * N O O P 8 8 O O 8 Q O N R ",
+" S T U V W X U U W Y T Z ",
+" ` ...+.+.+.+... .@. ",
+" 4 #.$.%.%.$.&.R ",
+" x "};
diff --git a/kdeprint/tests/main.cpp b/kdeprint/tests/main.cpp
new file mode 100644
index 000000000..4db031532
--- /dev/null
+++ b/kdeprint/tests/main.cpp
@@ -0,0 +1,41 @@
+/****************************************************************************
+** $Id$
+**
+** 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 "helpwindow.h"
+#include <kapplication.h>
+#include <qwindowsstyle.h>
+#include <qstylesheet.h>
+#include <stdlib.h>
+
+
+int main( int argc, char ** argv )
+{
+ KApplication a(argc, argv, "helpviewer");
+
+ QString home;
+ if (argc > 1)
+ home = argv[1];
+ else
+ home = QString(getenv("QTDIR")) + "/doc/html/index.html";
+
+
+ HelpWindow *help = new HelpWindow(home, ".", 0, "help viewer");
+
+ if ( QApplication::desktop()->width() > 400
+ && QApplication::desktop()->height() > 500 )
+ help->show();
+ else
+ help->showMaximized();
+
+ QObject::connect( &a, SIGNAL(lastWindowClosed()),
+ &a, SLOT(quit()) );
+
+ return a.exec();
+}
diff --git a/kdeprint/tests/richpage.cpp b/kdeprint/tests/richpage.cpp
new file mode 100644
index 000000000..9b175894b
--- /dev/null
+++ b/kdeprint/tests/richpage.cpp
@@ -0,0 +1,85 @@
+#include "richpage.h"
+
+#include <qlabel.h>
+#include <qspinbox.h>
+#include <qcombobox.h>
+#include <qfontdatabase.h>
+#include <qlayout.h>
+
+RichPage::RichPage(QWidget *parent, const char *name)
+: KPrintDialogPage(parent,name)
+{
+ m_title = "Rich Text Options";
+
+ margin_ = new QSpinBox(this);
+ margin_->setRange(1,999);
+ margin_->setValue(72);
+
+ fontsize_ = new QSpinBox(this);
+ fontsize_->setRange(4,100);
+ fontsize_->setValue(10);
+
+ fontname_ = new QComboBox(this);
+ QFontDatabase db;
+ QStringList fonts = db.families();
+ fontname_->insertStringList(fonts);
+ fontname_->setCurrentItem(fonts.findIndex(QString::fromLatin1("times")));
+ if (fontname_->currentItem() < 0) fontname_->setCurrentItem(0);
+
+ QLabel *l1 = new QLabel("Margin:",this);
+ QLabel *l2 = new QLabel("Font name:",this);
+ QLabel *l3 = new QLabel("Font size:",this);
+
+ QHBoxLayout *s1 = new QHBoxLayout(0, 0, 10);
+ QHBoxLayout *s2 = new QHBoxLayout(0, 0, 10);
+ QVBoxLayout *main_ = new QVBoxLayout(this, 10, 10);
+
+ main_->addLayout(s1,0);
+ main_->addSpacing(20);
+ main_->addLayout(s2,0);
+ main_->addStretch(1);
+
+ s1->addWidget(l1,0);
+ s1->addWidget(margin_,0);
+ s1->addStretch(1);
+
+ s2->addWidget(l2,0);
+ s2->addWidget(fontname_,0);
+ s2->addSpacing(20);
+ s2->addWidget(l3,0);
+ s2->addWidget(fontsize_,0);
+ s2->addStretch(1);
+}
+
+RichPage::~RichPage()
+{
+}
+
+void RichPage::setOptions(const QMap<QString,QString>& opts)
+{
+ QString value;
+
+ value = opts["app-rich-margin"];
+ if (!value.isEmpty())
+ margin_->setValue(value.toInt());
+
+ value = opts["app-rich-fontname"];
+ if (!value.isEmpty())
+ for (int i=0;i<fontname_->count();i++)
+ if (fontname_->text(i) == value)
+ {
+ fontname_->setCurrentItem(i);
+ break;
+ }
+
+ value = opts["app-rich-fontsize"];
+ if (!value.isEmpty())
+ fontsize_->setValue(value.toInt());
+}
+
+void RichPage::getOptions(QMap<QString,QString>& opts, bool)
+{
+ opts["app-rich-margin"] = margin_->text();
+ opts["app-rich-fontname"] = fontname_->currentText();
+ opts["app-rich-fontsize"] = fontsize_->text();
+}
diff --git a/kdeprint/tests/richpage.h b/kdeprint/tests/richpage.h
new file mode 100644
index 000000000..579e52bf2
--- /dev/null
+++ b/kdeprint/tests/richpage.h
@@ -0,0 +1,24 @@
+#ifndef RICHPAGE_H
+#define RICHPAGE_H
+
+#include <kprintdialogpage.h>
+
+class QSpinBox;
+class QComboBox;
+
+class RichPage : public KPrintDialogPage
+{
+public:
+ RichPage(QWidget *parent = 0, const char *name = 0);
+ ~RichPage();
+
+ void setOptions(const QMap<QString,QString>& opts);
+ void getOptions(QMap<QString,QString>& opts, bool incldef = false);
+
+private:
+ QSpinBox *margin_;
+ QComboBox *fontname_;
+ QSpinBox *fontsize_;
+};
+
+#endif