From bd0f3345a938b35ce6a12f6150373b0955b8dd12 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 10 Jul 2011 15:24:15 -0500 Subject: Add Qt3 development HEAD version --- examples/demo/textdrawing/bidi.txt | 6 + examples/demo/textdrawing/editcopy.png | Bin 0 -> 485 bytes examples/demo/textdrawing/editcut.png | Bin 0 -> 537 bytes examples/demo/textdrawing/editdelete.png | Bin 0 -> 833 bytes examples/demo/textdrawing/editlower.png | Bin 0 -> 609 bytes examples/demo/textdrawing/editpaste.png | Bin 0 -> 907 bytes examples/demo/textdrawing/editraise.png | Bin 0 -> 614 bytes examples/demo/textdrawing/example.html | 340 ++++++++++++++++++++ examples/demo/textdrawing/filenew.png | Bin 0 -> 386 bytes examples/demo/textdrawing/fileopen.png | Bin 0 -> 1323 bytes examples/demo/textdrawing/filesave.png | Bin 0 -> 514 bytes examples/demo/textdrawing/help.png | Bin 0 -> 1561 bytes examples/demo/textdrawing/helpwindow.cpp | 337 ++++++++++++++++++++ examples/demo/textdrawing/helpwindow.h | 64 ++++ examples/demo/textdrawing/home.png | Bin 0 -> 1081 bytes examples/demo/textdrawing/next.png | Bin 0 -> 541 bytes examples/demo/textdrawing/previous.png | Bin 0 -> 542 bytes examples/demo/textdrawing/print.png | Bin 0 -> 742 bytes examples/demo/textdrawing/redo.png | Bin 0 -> 816 bytes examples/demo/textdrawing/textbold.png | Bin 0 -> 494 bytes examples/demo/textdrawing/textcenter.png | Bin 0 -> 429 bytes examples/demo/textdrawing/textedit.cpp | 477 ++++++++++++++++++++++++++++ examples/demo/textdrawing/textedit.h | 85 +++++ examples/demo/textdrawing/textitalic.png | Bin 0 -> 442 bytes examples/demo/textdrawing/textjustify.png | Bin 0 -> 408 bytes examples/demo/textdrawing/textleft.png | Bin 0 -> 409 bytes examples/demo/textdrawing/textright.png | Bin 0 -> 408 bytes examples/demo/textdrawing/textunderline.png | Bin 0 -> 471 bytes examples/demo/textdrawing/undo.png | Bin 0 -> 800 bytes 29 files changed, 1309 insertions(+) create mode 100644 examples/demo/textdrawing/bidi.txt create mode 100644 examples/demo/textdrawing/editcopy.png create mode 100644 examples/demo/textdrawing/editcut.png create mode 100644 examples/demo/textdrawing/editdelete.png create mode 100644 examples/demo/textdrawing/editlower.png create mode 100644 examples/demo/textdrawing/editpaste.png create mode 100644 examples/demo/textdrawing/editraise.png create mode 100644 examples/demo/textdrawing/example.html create mode 100644 examples/demo/textdrawing/filenew.png create mode 100644 examples/demo/textdrawing/fileopen.png create mode 100644 examples/demo/textdrawing/filesave.png create mode 100644 examples/demo/textdrawing/help.png create mode 100644 examples/demo/textdrawing/helpwindow.cpp create mode 100644 examples/demo/textdrawing/helpwindow.h create mode 100644 examples/demo/textdrawing/home.png create mode 100644 examples/demo/textdrawing/next.png create mode 100644 examples/demo/textdrawing/previous.png create mode 100644 examples/demo/textdrawing/print.png create mode 100644 examples/demo/textdrawing/redo.png create mode 100644 examples/demo/textdrawing/textbold.png create mode 100644 examples/demo/textdrawing/textcenter.png create mode 100644 examples/demo/textdrawing/textedit.cpp create mode 100644 examples/demo/textdrawing/textedit.h create mode 100644 examples/demo/textdrawing/textitalic.png create mode 100644 examples/demo/textdrawing/textjustify.png create mode 100644 examples/demo/textdrawing/textleft.png create mode 100644 examples/demo/textdrawing/textright.png create mode 100644 examples/demo/textdrawing/textunderline.png create mode 100644 examples/demo/textdrawing/undo.png (limited to 'examples/demo/textdrawing') diff --git a/examples/demo/textdrawing/bidi.txt b/examples/demo/textdrawing/bidi.txt new file mode 100644 index 0000000..7674ab0 --- /dev/null +++ b/examples/demo/textdrawing/bidi.txt @@ -0,0 +1,6 @@ +This page contains text in many languages, advertising the Tenth International Unicode Conference. The page is encoded using Unicode UTF-8 and to view it you need a Unicode-capable browser. If you don't have access to such a browser, you may want to visit the individual Web pages, each containing the text in a single language. The text on these Web pages was provided by volunteer translators (see the Credits page). If you would like to offer a language we don't yet have, or have a comment about one of the existing pages, please mail us. + +אירופה, תוכנה והאינטרנט: Unicode יוצא לשוק העולמי הירשמו כעת לכנס Unicode הבינלאומי העשירי, שייערך בין התאריכים 12־10 במרץ 1997, במיינץ שבגרמניה. בכנס ישתתפו מומחים מכל ענפי התעשייה בנושא האינטרנט העולמי וה־Unicode, בהתאמה לשוק הבינלאומי והמקומי, ביישום Unicode במערכות הפעלה וביישומים, בגופנים, בפריסת טקסט ובמחשוב רב־לשוני. some english inbetween כאשר העולם רוצה לדבר, הוא מדבר ב־Unicode + +أوروبا, برمجيات الحاسوب + انترنيت : some english تصبح عالميا مع يونيكود more english تسجّل الآن لحضور المؤتمر الدولي العاشر ليونيكود, الذي سيعقد في 10-12 آذار 1997 بمدينة ماينتس, ألمانيا. وسيجمع المؤتمر بين خبراء من كافة قطاعات الصناعة على الشبكة العالمية انترنيت ويونيكود, حيث ستتم, على الصعيدين الدولي والمحلي على حد سواء مناقشة سبل استخدام يونكود في النظم القائمة وفيما يخص التطبيقات الحاسوبية, الخطوط, تصميم النصوص والحوسبة متعددة اللغات. english عندما يريد العالم أن يتكلّم, فهو يتحدّث بلغة يونيكود. english... + diff --git a/examples/demo/textdrawing/editcopy.png b/examples/demo/textdrawing/editcopy.png new file mode 100644 index 0000000..2f931cb Binary files /dev/null and b/examples/demo/textdrawing/editcopy.png differ diff --git a/examples/demo/textdrawing/editcut.png b/examples/demo/textdrawing/editcut.png new file mode 100644 index 0000000..54c8e14 Binary files /dev/null and b/examples/demo/textdrawing/editcut.png differ diff --git a/examples/demo/textdrawing/editdelete.png b/examples/demo/textdrawing/editdelete.png new file mode 100644 index 0000000..9f0491d Binary files /dev/null and b/examples/demo/textdrawing/editdelete.png differ diff --git a/examples/demo/textdrawing/editlower.png b/examples/demo/textdrawing/editlower.png new file mode 100644 index 0000000..50605f2 Binary files /dev/null and b/examples/demo/textdrawing/editlower.png differ diff --git a/examples/demo/textdrawing/editpaste.png b/examples/demo/textdrawing/editpaste.png new file mode 100644 index 0000000..b1b7f85 Binary files /dev/null and b/examples/demo/textdrawing/editpaste.png differ diff --git a/examples/demo/textdrawing/editraise.png b/examples/demo/textdrawing/editraise.png new file mode 100644 index 0000000..f157251 Binary files /dev/null and b/examples/demo/textdrawing/editraise.png differ diff --git a/examples/demo/textdrawing/example.html b/examples/demo/textdrawing/example.html new file mode 100644 index 0000000..b538002 --- /dev/null +++ b/examples/demo/textdrawing/example.html @@ -0,0 +1,340 @@ + +Qt Toolkit - QLabel Class + + +

QLabel Class Reference


+

+The QLabel widget provides a static information display +More... +

+#include <qlabel.h> +

+Inherits QFrame. +

List of all member functions. +

Public Members

+ +

Public Slots

+ +

Protected Members

+ +

Properties

+ +
TypeNameREADWRITEOptions +
QStringtexttextsetText  +
TextFormattextFormattextFormatsetTextFormat  +
QPixmappixmappixmapsetPixmap  +
boolscaledContentshasScaledContentssetScaledContents  +
AlignmentalignmentalignmentsetAlignment  +
intindentindentsetIndent  +
+

+


Detailed Description

+The QLabel widget provides a static information display +

+QLabel is used for displaying information in the form of text or +image to the user. No user interaction functionality is +provided. The visual appearance of the label can be configured in +various ways, and it can be used for specifying a focus accelerator +key for another widget. +

A QLabel can contain any of the following content types: +

+

When the content is changed using any of these functions, any +previous content is cleared. +

The look of a QLabel can be tuned in several ways. All the settings +of QFrame are available for specifying a widget frame. The +positioning of the content within the QLabel widget area can be +tuned with setAlignment() and setIndent(). For example, this code +sets up a sunken panel with a two-line text in the bottom right +corner (both lines being flush with the right side of the label): +

    QLabel *label = new QLabel;
+    label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
+    label->setText( "first line\nsecond line" );
+    label->setAlignment( AlignBottom | AlignRight );
+
+

A QLabel is often used as a label for another, interactive +widget. For this use, QLabel provides a handy mechanism for adding +an accelerator key (see QAccel) that will set the keyboard focus to +the other widget (called the QLabel's "buddy"). Example: +

     QLineEdit* phoneEdit = new QLineEdit( this, "phoneEdit" );
+     QLabel* phoneLabel = new QLabel( phoneEdit, "&Phone:", this, "phoneLabel" );
+
+

In this example, keyboard focus is transferred to the label's buddy +(the QLineEdit) when the user presses Alt-P. You can also +use the setBuddy() function to accomplish the same. +

+

See also QLineEdit, QTextView, QPixmap, QMovie and GUI Design Handbook: Label +

Examples: + cursor/cursor.cpp + layout/layout.cpp + popup/popup.cpp + menu/menu.cpp + progress/progress.cpp + qmag/qmag.cpp + movies/main.cpp + customlayout/main.cpp + +


Member Function Documentation

+

QLabel::QLabel(QWidget*buddy, constQString&text, QWidget*parent, constchar*name=0, WFlagsf=0)

+

Constructs a label with a text and a buddy. +

The text is set with setText(). The buddy is set with setBuddy(). +

The parent, name and f arguments are passed to the QFrame +constructor. +

See also setText(), setBuddy(), setAlignment(), setFrameStyle() and setIndent(). +

QLabel::QLabel(QWidget*parent, constchar*name=0, WFlagsf=0)

+

Constructs an empty label. +

The parent, name and f arguments are passed to the QFrame +constructor. +

See also setAlignment(), setFrameStyle() and setIndent(). +

QLabel::QLabel(constQString&text, QWidget*parent, constchar*name=0, WFlagsf=0)

+

Constructs a label with a text. The text is set with setText(). +

The parent, name and f arguments are passed to the QFrame +constructor. +

See also setText(), setAlignment(), setFrameStyle() and setIndent(). +

QLabel::~QLabel()

+

Destructs the label. +

intQLabel::alignment()const

+

Returns the alignment setting. +

See also setAlignment(). +

boolQLabel::autoResize()const

+

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

+

Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing +is disabled. +

Auto-resizing is disabled by default. +

See also setAutoResize(). +

QWidget*QLabel::buddy()const

+

Returns the buddy of this label, or 0 if no buddy is currently set. +

See also setBuddy(). +

voidQLabel::clear() [slot]

+

Clears any label contents. Equivalent with setText( "" ). +

voidQLabel::drawContents(QPainter*p) [virtualprotected]

+

Draws the label contents using the painter p. +

Reimplemented from QFrame. +

voidQLabel::drawContentsMask(QPainter*p) [virtualprotected]

+

Draws the label contents mask using the painter p. +Used only in transparent mode. +

See also QWidget::setAutoMask();. +

Reimplemented from QFrame. +

voidQLabel::fontChange(constQFont&) [virtualprotected]

+

Reimplemented for internal reasons; the API is not affected. +

Reimplemented from QWidget. +

boolQLabel::hasScaledContents()const

+

Returns whether the label will scale its contents to fill all +available space. +

See also setScaledContents(). +

intQLabel::heightForWidth(intw)const [virtual]

+

Reimplemented for internal reasons; the API is not affected. +

Reimplemented from QWidget. +

intQLabel::indent()const

+

Returns the indent of the label. +

See also setIndent(). +

QSizeQLabel::minimumSizeHint()const [virtual]

+

Reimplemented for internal reasons; the API is not affected. +

Reimplemented from QWidget. +

QMovie*QLabel::movie()const

+

If the label contains a movie, returns a pointer to it. Otherwise, +returns 0. +

See also setMovie(). +

QPixmap*QLabel::pixmap()const

+

If the label contains a pixmap, returns a pointer to it. Otherwise, +returns 0. +

See also setPixmap(). +

voidQLabel::resizeEvent(QResizeEvent*e) [virtualprotected]

+

Reimplemented for internal reasons; the API is not affected. +

Reimplemented from QWidget. +

voidQLabel::setAlignment(intalignment) [virtual]

+

Sets the alignment of the label contents. +

The alignment must be a bitwise OR of Qt::AlignmentFlags +values. The WordBreak, ExpandTabs, SingleLine and ShowPrefix flags apply only if the label contains a plain text, and +are otherwise ignored. The DontClip flag is always ignored. +

If the label has a buddy, the ShowPrefix flag is forced to TRUE. +

The default alignment is AlignLeft | AlignVCenter | +ExpandTabs if the label doesn't have a buddy and +AlignLeft | AlignVCenter | ExpandTabs | ShowPrefix if +the label has a buddy. +

See also Qt::AlignmentFlags, alignment(), setBuddy() and setText(). +

Examples: + cursor/cursor.cpp + layout/layout.cpp + popup/popup.cpp + qmag/qmag.cpp + customlayout/main.cpp +

voidQLabel::setAutoMask(boolb) [virtual]

+

Reimplemented for internal reasons; the API is not affected. +

Reimplemented from QWidget. +

voidQLabel::setAutoResize(boolenable) [virtual]

+

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

+Enables auto-resizing if enable is TRUE, or disables it if enable is FALSE. +

When auto-resizing is enabled, the label will resize itself to fit +the contents whenever the contents change. The top left corner is +not moved. This is useful for QLabel widgets that are not managed by +a QLayout (e.g. top-level widgets). +

Auto-resizing is disabled by default. +

See also autoResize(), adjustSize() and sizeHint(). +

voidQLabel::setBuddy(QWidget*buddy) [virtual]

+

Sets the buddy of this label to buddy. +

When the user presses the accelerator key indicated by this label, +the keyboard focus is transferred to the label's buddy widget. +

The buddy mechanism is only available for QLabels that contain a +plain text in which one letter is prefixed with '&'. It is this +letter that is set as the accelerator key. The letter is displayed +underlined, and the '&' is not displayed (i.e. the ShowPrefix +alignment flag is turned on; see setAlignment()). +

In a dialog, you might create two data entry widgets and a label for +each, and set up the geometry layout so each label is just to the +left of its data entry widget (its "buddy"), somewhat like this: +

    QLineEdit *nameEd  = new QLineEdit( this );
+    QLabel    *nameLb  = new QLabel( "&Name:", this );
+    nameLb->setBuddy( nameEd );
+    QLineEdit *phoneEd = new QLineEdit( this );
+    QLabel    *phoneLb = new QLabel( "&Phone:", this );
+    phoneLb->setBuddy( phoneEd );
+    // ( layout setup not shown )
+
+

With the code above, the focus jumps to the Name field when the user +presses Alt-N, and to the Phone field when the user presses Alt-P. +

To unset a previously set buddy, call this function with buddy +set to 0. +

See also buddy(), setText(), QAccel and setAlignment(). +

Examples: + layout/layout.cpp +

voidQLabel::setIndent(intindent)

+

Sets the indent of the label to indent pixels. +

The indent applies to the left edge if alignment() is AlignLeft, +to the right edge if alignment() is AlignRight, to the top edge +if alignment() is AlignTop, and to to the bottom edge if +alignment() is AlignBottom. +

If indent is negative, or if no indent has been set, the label +computes the effective indent as follows: If frameWidth() is 0, the +effective indent becomes 0. If frameWidth() is greater than 0, the +effective indent becomes half the width of the "x" character of the +widget's current font(). +

If indent is non-negative, the effective indent is indent +pixels. +

See also indent(), setAlignment(), frameWidth() and font(). +

Examples: + movies/main.cpp +

voidQLabel::setMovie(constQMovie&movie) [virtualslot]

+

Sets the label contents to movie. Any previous content is cleared. +

The buddy accelerator, if any, is disabled. +

The label resizes itself if auto-resizing is enabled. +

See also movie() and setBuddy(). +

voidQLabel::setNum(doublenum) [virtualslot]

+

Sets the label contents to a plain text containing the printed value +of num. Does nothing if this is equal to the current contents of +the label. Any previous content is cleared. +

The buddy accelerator, if any, is disabled. +

The label resizes itself if auto-resizing is enabled. +

See also setText(), QString::setNum() and setBuddy(). +

voidQLabel::setNum(intnum) [virtualslot]

+

Sets the label contents to a plain text containing the printed value +of num. Does nothing if this is equal to the current contents of +the label. Any previous content is cleared. +

The buddy accelerator, if any, is disabled. +

The label resizes itself if auto-resizing is enabled. +

See also setText(), QString::setNum() and setBuddy(). +

voidQLabel::setPixmap(constQPixmap&pixmap) [virtualslot]

+

Sets the label contents to pixmap. Any previous content is cleared. +

The buddy accelerator, if any, is disabled. +

The label resizes itself if auto-resizing is enabled. +

See also pixmap() and setBuddy(). +

voidQLabel::setScaledContents(boolenable)

+

When called with enable == TRUE, and the label shows a pixmap, +it will scale the pixmap to fill available space. +

See also hasScaledContents(). +

voidQLabel::setText(constQString&text) [virtualslot]

+

Sets the label contents to text, or does nothing if text is +equal to the current contents of the label. Any previous content is +cleared. +

text will be interpreted either as a plain text or as a rich +text, depending on the text format setting; see setTextFormat(). The +default setting is AutoText, i.e. QLabel will try to auto-detect +the format of text. +

If text is interpreted as a plain text, and a buddy has been set, +the buddy accelerator key is updated from the new text. +

The label resizes itself if auto-resizing is enabled. +

Note that Qlabel is well suited to display small rich text documents +only. For large documents, use QTextView instead. It will flicker +less on resize and can also provide a scrollbar if necessary. +

See also text(), setTextFormat(), setBuddy() and setAlignment(). +

Examples: + cursor/cursor.cpp + layout/layout.cpp + popup/popup.cpp + qmag/qmag.cpp + customlayout/main.cpp +

voidQLabel::setTextFormat(Qt::TextFormatformat)

+

Sets the text format to format. See the Qt::TextFormat enum for +an explanation of the possible options. +

The default format is AutoText. +

See also textFormat() and setText(). +

QSizeQLabel::sizeHint()const [virtual]

+

Reimplemented for internal reasons; the API is not affected. +

Examples: + layout/layout.cpp +

Reimplemented from QWidget. +

QSizePolicyQLabel::sizePolicy()const [virtual]

+

Reimplemented for internal reasons; the API is not affected. +

Reimplemented from QWidget. +

QStringQLabel::text()const

+

Returns the label text. If the content is a plain or a rich text, +this is the string that was passed to setText(). Otherwise, it is an +empty/null string. +

See also setText(), setNum() and clear(). +

Qt::TextFormatQLabel::textFormat()const

+

Returns the current text format. +

See also setTextFormat(). +


+Search the documentation, FAQ, qt-interest archive and more (uses +www.trolltech.com):
+

+ + +

+This file is part of the Qt toolkit, +copyright © 1995-2006 +Trolltech, all rights reserved.


+ +
Copyright 2006 TrolltechTrademarks +
Qt version 3.0.0-snapshot
+
diff --git a/examples/demo/textdrawing/filenew.png b/examples/demo/textdrawing/filenew.png new file mode 100644 index 0000000..be963bf Binary files /dev/null and b/examples/demo/textdrawing/filenew.png differ diff --git a/examples/demo/textdrawing/fileopen.png b/examples/demo/textdrawing/fileopen.png new file mode 100644 index 0000000..6077b81 Binary files /dev/null and b/examples/demo/textdrawing/fileopen.png differ diff --git a/examples/demo/textdrawing/filesave.png b/examples/demo/textdrawing/filesave.png new file mode 100644 index 0000000..a1cb03d Binary files /dev/null and b/examples/demo/textdrawing/filesave.png differ diff --git a/examples/demo/textdrawing/help.png b/examples/demo/textdrawing/help.png new file mode 100644 index 0000000..2ab2c25 Binary files /dev/null and b/examples/demo/textdrawing/help.png differ diff --git a/examples/demo/textdrawing/helpwindow.cpp b/examples/demo/textdrawing/helpwindow.cpp new file mode 100644 index 0000000..9fa0e7b --- /dev/null +++ b/examples/demo/textdrawing/helpwindow.cpp @@ -0,0 +1,337 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +HelpWindow::HelpWindow( const QString& home_, const QString& _path, + QWidget* parent, const char *name ) + : QMainWindow( 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( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N ); + file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O ); + file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P ); + + // The same three icons are used twice each. + QIconSet icon_back( QPixmap("textdrawing/previous.png") ); + QIconSet icon_forward( QPixmap("textdrawing/next.png") ); + QIconSet icon_home( QPixmap("textdrawing/home.png") ); + + QPopupMenu* go = new QPopupMenu( this ); + backwardId = go->insertItem( icon_back, + tr("&Backward"), browser, SLOT( backward() ), + ALT | Key_Left ); + forwardId = go->insertItem( icon_forward, + tr("&Forward"), browser, SLOT( forward() ), + ALT | Key_Right ); + go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) ); + + 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()->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::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::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", + "

This example implements a simple HTML help viewer " + "using Qt's rich text capabilities

" + "

It's just about 100 lines of C++ code, so don't expect too much :-)

" + ); +} + + +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(); +} + +void HelpWindow::print() +{ +#ifndef QT_NO_PRINTER + QPrinter printer; + printer.setFullPage(TRUE); + if ( printer.setup() ) { + QPainter p( &printer ); + QPaintDeviceMetrics metrics(p.device()); + int dpix = metrics.logicalDpiX(); + int dpiy = metrics.logicalDpiY(); + const int margin = 72; // pt + QRect body(margin*dpix/72, margin*dpiy/72, + metrics.width()-margin*dpix/72*2, + metrics.height()-margin*dpiy/72*2 ); + QFont font("times", 10); + QStringList filePaths = browser->mimeSourceFactory()->filePath(); + QString file; + QStringList::Iterator it = filePaths.begin(); + for ( ; it != filePaths.end(); ++it ) { + file = QUrl( *it, QUrl( browser->source() ).path() ).path(); + if ( QFile::exists( file ) ) + break; + else + file = QString::null; + } + if ( file.isEmpty() ) + return; + QFile f( file ); + if ( !f.open( IO_ReadOnly ) ) + return; + QTextStream ts( &f ); + QSimpleRichText richText( ts.read(), 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); + } +#endif +} + +void HelpWindow::pathSelected( const QString &_path ) +{ + browser->setSource( _path ); + QMap::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(); +} diff --git a/examples/demo/textdrawing/helpwindow.h b/examples/demo/textdrawing/helpwindow.h new file mode 100644 index 0000000..3427ad9 --- /dev/null +++ b/examples/demo/textdrawing/helpwindow.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. 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 +#include +#include +#include +#include + +class QComboBox; +class QPopupMenu; + +class HelpWindow : public QMainWindow +{ + 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 mHistory, mBookmarks; + QPopupMenu *hist, *bookm; + +}; + + + + + +#endif + diff --git a/examples/demo/textdrawing/home.png b/examples/demo/textdrawing/home.png new file mode 100644 index 0000000..aa150a3 Binary files /dev/null and b/examples/demo/textdrawing/home.png differ diff --git a/examples/demo/textdrawing/next.png b/examples/demo/textdrawing/next.png new file mode 100644 index 0000000..4b29ff4 Binary files /dev/null and b/examples/demo/textdrawing/next.png differ diff --git a/examples/demo/textdrawing/previous.png b/examples/demo/textdrawing/previous.png new file mode 100644 index 0000000..4e3556c Binary files /dev/null and b/examples/demo/textdrawing/previous.png differ diff --git a/examples/demo/textdrawing/print.png b/examples/demo/textdrawing/print.png new file mode 100644 index 0000000..57e3e53 Binary files /dev/null and b/examples/demo/textdrawing/print.png differ diff --git a/examples/demo/textdrawing/redo.png b/examples/demo/textdrawing/redo.png new file mode 100644 index 0000000..bae07d3 Binary files /dev/null and b/examples/demo/textdrawing/redo.png differ diff --git a/examples/demo/textdrawing/textbold.png b/examples/demo/textdrawing/textbold.png new file mode 100644 index 0000000..7b5be47 Binary files /dev/null and b/examples/demo/textdrawing/textbold.png differ diff --git a/examples/demo/textdrawing/textcenter.png b/examples/demo/textdrawing/textcenter.png new file mode 100644 index 0000000..5c68b09 Binary files /dev/null and b/examples/demo/textdrawing/textcenter.png differ diff --git a/examples/demo/textdrawing/textedit.cpp b/examples/demo/textdrawing/textedit.cpp new file mode 100644 index 0000000..9aebf54 --- /dev/null +++ b/examples/demo/textdrawing/textedit.cpp @@ -0,0 +1,477 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. 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 "textedit.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +TextEdit::TextEdit( QWidget *parent, const char *name ) + : QMainWindow( parent, name, 0 ) +{ + setupFileActions(); + setupEditActions(); + setupTextActions(); + + tabWidget = new QTabWidget( this ); + connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), + this, SLOT( editorChanged( QWidget * ) ) ); + setCentralWidget( tabWidget ); +} + +void TextEdit::setupFileActions() +{ + QToolBar *tb = new QToolBar( this ); + QPopupMenu *menu = new QPopupMenu( this ); + menuBar()->insertItem( tr( "&File" ), menu ); + + QAction *a; + a = new QAction( tr( "New" ), QPixmap( "textdrawing/filenew.png" ), tr( "&New..." ), CTRL + Key_N, this, "fileNew" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new QAction( tr( "Open" ), QPixmap( "textdrawing/fileopen.png" ), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); + a->addTo( tb ); + a->addTo( menu ); + menu->insertSeparator(); + a = new QAction( tr( "Save" ), QPixmap( "textdrawing/filesave.png" ), tr( "&Save..." ), CTRL + Key_S, this, "fileSave" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileSave() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new QAction( tr( "Save As" ), QPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) ); + a->addTo( menu ); + menu->insertSeparator(); + a = new QAction( tr( "Print" ), QPixmap( "textdrawing/print.png" ), tr( "&Print..." ), CTRL + Key_P, this, "filePrint" ); + connect( a, SIGNAL( activated() ), this, SLOT( filePrint() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new QAction( tr( "Close" ), QPixmap(), tr( "&Close" ), 0, this, "fileClose" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) ); + a->addTo( menu ); +} + +void TextEdit::setupEditActions() +{ + QToolBar *tb = new QToolBar( this ); + QPopupMenu *menu = new QPopupMenu( this ); + menuBar()->insertItem( tr( "&Edit" ), menu ); + + QAction *a; + a = new QAction( tr( "Undo" ), QPixmap( "textdrawing/undo.png" ), tr( "&Undo" ), CTRL + Key_Z, this, "editUndo" ); + connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new QAction( tr( "Redo" ), QPixmap( "textdrawing/redo.png" ), tr( "&Redo" ), CTRL + Key_Y, this, "editRedo" ); + connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); + a->addTo( tb ); + a->addTo( menu ); + menu->insertSeparator(); + a = new QAction( tr( "Cut" ), QPixmap( "textdrawing/editcut.png" ), tr( "&Cut" ), CTRL + Key_X, this, "editCut" ); + connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new QAction( tr( "Copy" ), QPixmap( "textdrawing/editcopy.png" ), tr( "C&opy" ), CTRL + Key_C, this, "editCopy" ); + connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); + a->addTo( tb ); + a->addTo( menu ); + a = new QAction( tr( "Paste" ), QPixmap( "textdrawing/editpaste.png" ), tr( "&Paste" ), CTRL + Key_V, this, "editPaste" ); + connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); + a->addTo( tb ); + a->addTo( menu ); +} + +void TextEdit::setupTextActions() +{ + QToolBar *tb = new QToolBar( this ); + QPopupMenu *menu = new QPopupMenu( this ); + menuBar()->insertItem( tr( "For&mat" ), menu ); + + comboStyle = new QComboBox( FALSE, tb ); + comboStyle->insertItem( tr("Standard") ); + comboStyle->insertItem( tr("Bullet List (Disc)") ); + comboStyle->insertItem( tr("Bullet List (Circle)") ); + comboStyle->insertItem( tr("Bullet List (Square)") ); + comboStyle->insertItem( tr("Ordered List (Decimal)") ); + comboStyle->insertItem( tr("Ordered List (Alpha lower)") ); + comboStyle->insertItem( tr("Ordered List (Alpha upper)") ); + connect( comboStyle, SIGNAL( activated( int ) ), + this, SLOT( textStyle( int ) ) ); + + comboFont = new QComboBox( TRUE, tb ); + QFontDatabase db; + comboFont->insertStringList( db.families() ); + connect( comboFont, SIGNAL( activated( const QString & ) ), + this, SLOT( textFamily( const QString & ) ) ); + comboFont->lineEdit()->setText( QApplication::font().family() ); + + comboSize = new QComboBox( TRUE, tb ); + QValueList sizes = db.standardSizes(); + QValueList::Iterator it = sizes.begin(); + for ( ; it != sizes.end(); ++it ) + comboSize->insertItem( QString::number( *it ) ); + connect( comboSize, SIGNAL( activated( const QString & ) ), + this, SLOT( textSize( const QString & ) ) ); + comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); + + actionTextBold = new QAction( tr( "Bold" ), QPixmap( "textdrawing/textbold.png" ), tr( "&Bold" ), CTRL + Key_B, this, "textBold" ); + connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); + actionTextBold->addTo( tb ); + actionTextBold->addTo( menu ); + actionTextBold->setToggleAction( TRUE ); + actionTextItalic = new QAction( tr( "Italic" ), QPixmap( "textdrawing/textitalic.png" ), tr( "&Italic" ), CTRL + Key_I, this, "textItalic" ); + connect( actionTextItalic, SIGNAL( activated() ), this, SLOT( textItalic() ) ); + actionTextItalic->addTo( tb ); + actionTextItalic->addTo( menu ); + actionTextItalic->setToggleAction( TRUE ); + actionTextUnderline = new QAction( tr( "Underline" ), QPixmap( "textdrawing/textunderline.png" ), tr( "&Underline" ), CTRL + Key_U, this, "textUnderline" ); + connect( actionTextUnderline, SIGNAL( activated() ), this, SLOT( textUnderline() ) ); + actionTextUnderline->addTo( tb ); + actionTextUnderline->addTo( menu ); + actionTextUnderline->setToggleAction( TRUE ); + menu->insertSeparator(); + + QActionGroup *grp = new QActionGroup( this ); + grp->setExclusive( TRUE ); + connect( grp, SIGNAL( selected( QAction* ) ), this, SLOT( textAlign( QAction* ) ) ); + + actionAlignLeft = new QAction( tr( "Left" ), QPixmap( "textdrawing/textleft.png" ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" ); + actionAlignLeft->addTo( tb ); + actionAlignLeft->addTo( menu ); + actionAlignLeft->setToggleAction( TRUE ); + actionAlignCenter = new QAction( tr( "Center" ), QPixmap( "textdrawing/textcenter.png" ), tr( "C&enter" ), CTRL + Key_M, grp, "textCenter" ); + actionAlignCenter->addTo( tb ); + actionAlignCenter->addTo( menu ); + actionAlignCenter->setToggleAction( TRUE ); + actionAlignRight = new QAction( tr( "Right" ), QPixmap( "textdrawing/textright.png" ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" ); + actionAlignRight->addTo( tb ); + actionAlignRight->addTo( menu ); + actionAlignRight->setToggleAction( TRUE ); + actionAlignJustify = new QAction( tr( "Justify" ), QPixmap( "textdrawing/textjustify.png" ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" ); + actionAlignJustify->addTo( tb ); + actionAlignJustify->addTo( menu ); + actionAlignJustify->setToggleAction( TRUE ); + + menu->insertSeparator(); + + QPixmap pix( 16, 16 ); + pix.fill( black ); + actionTextColor = new QAction( tr( "Color" ), pix, tr( "&Color..." ), 0, this, "textColor" ); + connect( actionTextColor, SIGNAL( activated() ), this, SLOT( textColor() ) ); + actionTextColor->addTo( tb ); + actionTextColor->addTo( menu ); +} + +void TextEdit::load( const QString &f ) +{ + if ( !QFile::exists( f ) ) + return; + QTextEdit *edit = new QTextEdit( tabWidget ); + doConnections( edit ); + tabWidget->addTab( edit, QFileInfo( f ).fileName() ); + + QFile fl( f ); + fl.open( IO_ReadOnly ); + QByteArray array = fl.readAll(); + array.resize( array.size() +1 ); + array[ (int)array.size() - 1 ] = '\0'; + QString text = ( f.find( "bidi.txt" ) != -1 ? QString::fromUtf8( array.data() ) : QString::fromLatin1( array.data() ) ); + edit->setText( text ); + + edit->viewport()->setFocus(); + edit->setTextFormat( Qt::RichText ); +} + +QTextEdit *TextEdit::currentEditor() const +{ + if ( tabWidget->currentPage() && + tabWidget->currentPage()->inherits( "QTextEdit" ) ) + return (QTextEdit*)tabWidget->currentPage(); + return 0; +} + +void TextEdit::doConnections( QTextEdit *e ) +{ + connect( e, SIGNAL( currentFontChanged( const QFont & ) ), + this, SLOT( fontChanged( const QFont & ) ) ); + connect( e, SIGNAL( currentColorChanged( const QColor & ) ), + this, SLOT( colorChanged( const QColor & ) ) ); + connect( e, SIGNAL( currentAlignmentChanged( int ) ), + this, SLOT( alignmentChanged( int ) ) ); +} + +void TextEdit::fileNew() +{ + QTextEdit *edit = new QTextEdit( tabWidget ); + doConnections( edit ); + tabWidget->addTab( edit, tr( "noname" ) ); + tabWidget->showPage( edit ); + edit->viewport()->setFocus(); +} + +void TextEdit::fileOpen() +{ + QString fn = QFileDialog::getOpenFileName( QString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) + load( fn ); +} + +void TextEdit::fileSave() +{ + if ( !currentEditor() ) + return; + QString fn; + if ( filenames.find( currentEditor() ) == filenames.end() ) { + fileSaveAs(); + } else { + QFile file( *filenames.find( currentEditor() ) ); + if ( !file.open( IO_WriteOnly ) ) + return; + QTextStream ts( &file ); + ts << currentEditor()->text(); + } +} + +void TextEdit::fileSaveAs() +{ + if ( !currentEditor() ) + return; + QString fn = QFileDialog::getSaveFileName( QString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) { + filenames.replace( currentEditor(), fn ); + fileSave(); + tabWidget->setTabLabel( currentEditor(), QFileInfo( fn ).fileName() ); + } +} + +void TextEdit::filePrint() +{ + if ( !currentEditor() ) + return; +#ifndef QT_NO_PRINTER + QPrinter printer; + printer.setFullPage(TRUE); + QPaintDeviceMetrics screen( this ); + printer.setResolution( screen.logicalDpiY() ); + if ( printer.setup( this ) ) { + QPainter p( &printer ); + QPaintDeviceMetrics metrics( p.device() ); + int dpix = metrics.logicalDpiX(); + int dpiy = metrics.logicalDpiY(); + const int margin = 72; // pt + QRect body( margin * dpix / 72, margin * dpiy / 72, + metrics.width() - margin * dpix / 72 * 2, + metrics.height() - margin * dpiy / 72 * 2 ); + QFont font( "times", 10 ); + QSimpleRichText richText( currentEditor()->text(), font, currentEditor()->context(), currentEditor()->styleSheet(), + currentEditor()->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); + } +#endif +} + +void TextEdit::fileClose() +{ + delete currentEditor(); + if ( currentEditor() ) + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::fileExit() +{ + qApp->quit(); +} + +void TextEdit::editUndo() +{ + if ( !currentEditor() ) + return; + currentEditor()->undo(); +} + +void TextEdit::editRedo() +{ + if ( !currentEditor() ) + return; + currentEditor()->redo(); +} + +void TextEdit::editCut() +{ + if ( !currentEditor() ) + return; + currentEditor()->cut(); +} + +void TextEdit::editCopy() +{ + if ( !currentEditor() ) + return; + currentEditor()->copy(); +} + +void TextEdit::editPaste() +{ + if ( !currentEditor() ) + return; + currentEditor()->paste(); +} + +void TextEdit::textBold() +{ + if ( !currentEditor() ) + return; + currentEditor()->setBold( actionTextBold->isOn() ); +} + +void TextEdit::textUnderline() +{ + if ( !currentEditor() ) + return; + currentEditor()->setUnderline( actionTextUnderline->isOn() ); +} + +void TextEdit::textItalic() +{ + if ( !currentEditor() ) + return; + currentEditor()->setItalic( actionTextItalic->isOn() ); +} + +void TextEdit::textFamily( const QString &f ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setFamily( f ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textSize( const QString &p ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setPointSize( p.toInt() ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textStyle( int i ) +{ + if ( !currentEditor() ) + return; + if ( i == 0 ) + currentEditor()->setParagType( QStyleSheetItem::DisplayBlock, QStyleSheetItem::ListDisc ); + else if ( i == 1 ) + currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDisc ); + else if ( i == 2 ) + currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListCircle ); + else if ( i == 3 ) + currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListSquare ); + else if ( i == 4 ) + currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListDecimal ); + else if ( i == 5 ) + currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListLowerAlpha ); + else if ( i == 6 ) + currentEditor()->setParagType( QStyleSheetItem::DisplayListItem, QStyleSheetItem::ListUpperAlpha ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textColor() +{ + if ( !currentEditor() ) + return; + QColor col = QColorDialog::getColor( currentEditor()->color(), this ); + if ( !col.isValid() ) + return; + currentEditor()->setColor( col ); + QPixmap pix( 16, 16 ); + pix.fill( col ); + actionTextColor->setIconSet( pix ); +} + +void TextEdit::textAlign( QAction *a ) +{ + if ( !currentEditor() ) + return; + if ( a == actionAlignLeft ) + currentEditor()->setAlignment( AlignLeft ); + else if ( a == actionAlignCenter ) + currentEditor()->setAlignment( AlignHCenter ); + else if ( a == actionAlignRight ) + currentEditor()->setAlignment( AlignRight ); + else if ( a == actionAlignJustify ) + currentEditor()->setAlignment( AlignJustify ); +} + +void TextEdit::fontChanged( const QFont &f ) +{ + comboFont->lineEdit()->setText( f.family() ); + comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); + actionTextBold->setOn( f.bold() ); + actionTextItalic->setOn( f.italic() ); + actionTextUnderline->setOn( f.underline() ); +} + +void TextEdit::colorChanged( const QColor &c ) +{ + QPixmap pix( 16, 16 ); + pix.fill( c ); + actionTextColor->setIconSet( pix ); +} + +void TextEdit::alignmentChanged( int a ) +{ + if ( ( a == AlignAuto ) || ( a & AlignLeft )) + actionAlignLeft->setOn( TRUE ); + else if ( ( a & AlignHCenter ) ) + actionAlignCenter->setOn( TRUE ); + else if ( ( a & AlignRight ) ) + actionAlignRight->setOn( TRUE ); + else if ( ( a & AlignJustify ) ) + actionAlignJustify->setOn( TRUE ); +} + +void TextEdit::editorChanged( QWidget * ) +{ + if ( !currentEditor() ) + return; + fontChanged( currentEditor()->font() ); + colorChanged( currentEditor()->color() ); + alignmentChanged( currentEditor()->alignment() ); +} diff --git a/examples/demo/textdrawing/textedit.h b/examples/demo/textdrawing/textedit.h new file mode 100644 index 0000000..b1c3d95 --- /dev/null +++ b/examples/demo/textdrawing/textedit.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. 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 TEXTEDIT_H +#define TEXTEDIT_H + +#include +#include + +class QAction; +class QComboBox; +class QTabWidget; +class QTextEdit; + +class TextEdit : public QMainWindow +{ + Q_OBJECT + +public: + TextEdit( QWidget *parent = 0, const char *name = 0 ); + + QTextEdit *currentEditor() const; + void load( const QString &f ); + + +public slots: + void fileNew(); + void fileOpen(); + void fileSave(); + void fileSaveAs(); + void filePrint(); + void fileClose(); + void fileExit(); + + void editUndo(); + void editRedo(); + void editCut(); + void editCopy(); + void editPaste(); + + void textBold(); + void textUnderline(); + void textItalic(); + void textFamily( const QString &f ); + void textSize( const QString &p ); + void textStyle( int s ); + void textColor(); + void textAlign( QAction *a ); + + void fontChanged( const QFont &f ); + void colorChanged( const QColor &c ); + void alignmentChanged( int a ); + void editorChanged( QWidget * ); + + +private: + void setupFileActions(); + void setupEditActions(); + void setupTextActions(); + void doConnections( QTextEdit *e ); + + QAction *actionTextBold, + *actionTextUnderline, + *actionTextItalic, + *actionTextColor, + *actionAlignLeft, + *actionAlignCenter, + *actionAlignRight, + *actionAlignJustify; + QComboBox *comboStyle, + *comboFont, + *comboSize; + QTabWidget *tabWidget; + QMap filenames; + +}; + + +#endif diff --git a/examples/demo/textdrawing/textitalic.png b/examples/demo/textdrawing/textitalic.png new file mode 100644 index 0000000..68e2b44 Binary files /dev/null and b/examples/demo/textdrawing/textitalic.png differ diff --git a/examples/demo/textdrawing/textjustify.png b/examples/demo/textdrawing/textjustify.png new file mode 100644 index 0000000..1c6e5b9 Binary files /dev/null and b/examples/demo/textdrawing/textjustify.png differ diff --git a/examples/demo/textdrawing/textleft.png b/examples/demo/textdrawing/textleft.png new file mode 100644 index 0000000..30b0501 Binary files /dev/null and b/examples/demo/textdrawing/textleft.png differ diff --git a/examples/demo/textdrawing/textright.png b/examples/demo/textdrawing/textright.png new file mode 100644 index 0000000..73f1cad Binary files /dev/null and b/examples/demo/textdrawing/textright.png differ diff --git a/examples/demo/textdrawing/textunderline.png b/examples/demo/textdrawing/textunderline.png new file mode 100644 index 0000000..3477ccb Binary files /dev/null and b/examples/demo/textdrawing/textunderline.png differ diff --git a/examples/demo/textdrawing/undo.png b/examples/demo/textdrawing/undo.png new file mode 100644 index 0000000..d5b6c16 Binary files /dev/null and b/examples/demo/textdrawing/undo.png differ -- cgit v1.2.3