diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/demo/textdrawing | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/demo/textdrawing')
29 files changed, 1309 insertions, 0 deletions
diff --git a/examples/demo/textdrawing/bidi.txt b/examples/demo/textdrawing/bidi.txt new file mode 100644 index 000000000..7674ab0f0 --- /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 Binary files differnew file mode 100644 index 000000000..2f931cb2e --- /dev/null +++ b/examples/demo/textdrawing/editcopy.png diff --git a/examples/demo/textdrawing/editcut.png b/examples/demo/textdrawing/editcut.png Binary files differnew file mode 100644 index 000000000..54c8e1440 --- /dev/null +++ b/examples/demo/textdrawing/editcut.png diff --git a/examples/demo/textdrawing/editdelete.png b/examples/demo/textdrawing/editdelete.png Binary files differnew file mode 100644 index 000000000..9f0491ddc --- /dev/null +++ b/examples/demo/textdrawing/editdelete.png diff --git a/examples/demo/textdrawing/editlower.png b/examples/demo/textdrawing/editlower.png Binary files differnew file mode 100644 index 000000000..50605f276 --- /dev/null +++ b/examples/demo/textdrawing/editlower.png diff --git a/examples/demo/textdrawing/editpaste.png b/examples/demo/textdrawing/editpaste.png Binary files differnew file mode 100644 index 000000000..b1b7f8537 --- /dev/null +++ b/examples/demo/textdrawing/editpaste.png diff --git a/examples/demo/textdrawing/editraise.png b/examples/demo/textdrawing/editraise.png Binary files differnew file mode 100644 index 000000000..f15725170 --- /dev/null +++ b/examples/demo/textdrawing/editraise.png diff --git a/examples/demo/textdrawing/example.html b/examples/demo/textdrawing/example.html new file mode 100644 index 000000000..211838dac --- /dev/null +++ b/examples/demo/textdrawing/example.html @@ -0,0 +1,340 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> +<title>TQt Toolkit - TQLabel Class</title><style type="text/css"><!-- +h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; } +a:link { color: #004faf; text-decoration: none } +a:visited { color: #672967; text-decoration: none }body { background: white; color: black; } +--></style> +</head><body bgcolor="#ffffff"> + +<h1 align=center>TQLabel Class Reference</h1><br clear="all"> +<p> +The TQLabel widget provides a static information display +<a href="#details">More...</a> +<p> +<code>#include <<a href="qlabel-h.html">qlabel.h</a>></code> +<p> +Inherits <a href="qframe.html">TQFrame</a>. +<p><a href="qlabel-members.html">List of all member functions.</a> +<h2>Public Members</h2> +<ul> +<li><div class="fn"><a href="#39107d"><b>TQLabel</b></a>(QWidget*parent, constchar*name=0, WFlagsf=0)</div> +<li><div class="fn"><a href="#2bafbb"><b>TQLabel</b></a>(constQString&text, TQWidget*parent, constchar*name=0, WFlagsf=0)</div> +<li><div class="fn"><a href="#5514c7"><b>TQLabel</b></a>(QWidget*buddy, constQString&, TQWidget*parent, constchar*name=0, WFlagsf=0)</div> +<li><div class="fn"><a href="#9958af"><b>~TQLabel</b></a>()</div> +<li><div class="fn">TQString<a href="#72cf09"><b>text</b></a>()const</div> +<li><div class="fn">TQPixmap*<a href="#101ecb"><b>pixmap</b></a>()const</div> +<li><div class="fn">TQMovie*<a href="#7dcdfe"><b>movie</b></a>()const</div> +<li><div class="fn">TextFormat<a href="#0b92ed"><b>textFormat</b></a>()const</div> +<li><div class="fn">void<a href="#5de3f9"><b>setTextFormat</b></a>(TextFormat)</div> +<li><div class="fn">int<a href="#2fcaa3"><b>alignment</b></a>()const</div> +<li><div class="fn">virtualvoid<a href="#1f406e"><b>setAlignment</b></a>(int)</div> +<li><div class="fn">int<a href="#e3c907"><b>indent</b></a>()const</div> +<li><div class="fn">void<a href="#ed9b8b"><b>setIndent</b></a>(int)</div> +<li><div class="fn">boolautoResize()const<em>(obsolete)</em></div> +<li><div class="fn">virtualvoidsetAutoResize(bool)<em>(obsolete)</em></div> +<li><div class="fn">bool<a href="#7e1f73"><b>hasScaledContents</b></a>()const</div> +<li><div class="fn">void<a href="#e9e3cf"><b>setScaledContents</b></a>(bool)</div> +<li><div class="fn">virtualvoid<a href="#191701"><b>setBuddy</b></a>(QWidget*)</div> +<li><div class="fn">TQWidget*<a href="#123954"><b>buddy</b></a>()const</div> +</ul> +<h2>Public Slots</h2> +<ul> +<li><div class="fn">virtualvoid<a href="#dffb43"><b>setText</b></a>(constQString&)</div> +<li><div class="fn">virtualvoid<a href="#f3f301"><b>setPixmap</b></a>(constQPixmap&)</div> +<li><div class="fn">virtualvoid<a href="#60de9f"><b>setMovie</b></a>(constQMovie&)</div> +<li><div class="fn">virtualvoid<a href="#301e3c"><b>setNum</b></a>(int)</div> +<li><div class="fn">virtualvoid<a href="#1a8f6a"><b>setNum</b></a>(double)</div> +<li><div class="fn">void<a href="#be73f3"><b>clear</b></a>()</div> +</ul> +<h2>Protected Members</h2> +<ul> +<li><div class="fn">virtualvoid<a href="#fac264"><b>drawContents</b></a>(QPainter*)</div> +<li><div class="fn">virtualvoid<a href="#479dd2"><b>drawContentsMask</b></a>(QPainter*)</div> +</ul> +<h2>Properties</h2> +<table border=1 cellpadding=3 cellspacing=0> +<tr><th>Type<th>Name<th>READ<th>WRITE<th>Options +<tr><td>TQString<td>text<td>text<td>setText<td> +<tr><td>TextFormat<td>textFormat<td>textFormat<td>setTextFormat<td> +<tr><td>TQPixmap<td>pixmap<td>pixmap<td>setPixmap<td> +<tr><td>bool<td>scaledContents<td>hasScaledContents<td>setScaledContents<td> +<tr><td>Alignment<td>alignment<td>alignment<td>setAlignment<td> +<tr><td>int<td>indent<td>indent<td>setIndent<td> +</table> +<p> +<hr><h2><a name="details"></a>Detailed Description</h2> +The TQLabel widget provides a static information display +<p> +TQLabel 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. +<p>A TQLabel can contain any of the following content types: +<ul> +<li> A plain text: set by passing a <a href="qstring.html">TQString</a> to <a href="#dffb43">setText</a>(). +<li> A rich text: set by passing a TQString that contains a rich text to setText(). +<li> A pixmap: set by passing a <a href="qpixmap.html">TQPixmap</a> to <a href="#f3f301">setPixmap</a>(). +<li> A movie: set by passing a <a href="qmovie.html">TQMovie</a> to <a href="#60de9f">setMovie</a>(). +<li> A number: set by passing an <em>int</em> or a <em>double</em> to <a href="#1a8f6a">setNum</a>(), which converts the number to plain text. +<li> Nothing: The same as an empty plain text. This is the default. Set by <a href="#be73f3">clear</a>(). +</ul> +<p>When the content is changed using any of these functions, any +previous content is cleared. +<p>The look of a TQLabel can be tuned in several ways. All the settings +of <a href="qframe.html">TQFrame</a> are available for specifying a widget frame. The +positioning of the content within the TQLabel widget area can be +tuned with <a href="#1f406e">setAlignment</a>() and <a href="#ed9b8b">setIndent</a>(). 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): +<p><pre> <a href="qlabel.html">TQLabel</a> *label = new <a href="qlabel.html">TQLabel</a>; + label-><a href="qframe.html#c0d758">setFrameStyle</a>( TQFrame::Panel | TQFrame::Sunken ); + label-><a href="#dffb43">setText</a>( "first line\nsecond line" ); + label-><a href="#1f406e">setAlignment</a>( AlignBottom | AlignRight ); +</pre> +<p>A TQLabel is often used as a label for another, interactive +widget. For this use, TQLabel provides a handy mechanism for adding +an accelerator key (see <a href="qaccel.html">TQAccel</a>) that will set the keyboard focus to +the other widget (called the TQLabel's "buddy"). Example: +<p><pre> <a href="qlineedit.html">TQLineEdit</a>* phoneEdit = new <a href="qlineedit.html">TQLineEdit</a>( this, "phoneEdit" ); + <a href="qlabel.html">TQLabel</a>* phoneLabel = new <a href="qlabel.html">TQLabel</a>( phoneEdit, "&Phone:", this, "phoneLabel" ); +</pre> +<p>In this example, keyboard focus is transferred to the label's buddy +(the <a href="qlineedit.html">TQLineEdit</a>) when the user presses <dfn>Alt-P.</dfn> You can also +use the <a href="#191701">setBuddy</a>() function to accomplish the same. +<p> +<p>See also <a href="qlineedit.html">TQLineEdit</a>, <a href="qtextview.html">TQTextView</a>, <a href="qpixmap.html">TQPixmap</a>, <a href="qmovie.html">TQMovie</a> and <a href="guibooks.html#fowler">GUI Design Handbook: Label</a> +<p>Examples: + <a href="cursor-cursor-cpp.html#TQLabel">cursor/cursor.cpp</a> + <a href="layout-layout-cpp.html#TQLabel">layout/layout.cpp</a> + <a href="popup-popup-cpp.html#TQLabel">popup/popup.cpp</a> + <a href="menu-menu-cpp.html#TQLabel">menu/menu.cpp</a> + <a href="progress-progress-cpp.html#TQLabel">progress/progress.cpp</a> + <a href="qmag-qmag-cpp.html#TQLabel">qmag/qmag.cpp</a> + <a href="movies-main-cpp.html#TQLabel">movies/main.cpp</a> + <a href="customlayout-main-cpp.html#TQLabel">customlayout/main.cpp</a> + +<hr><h2>Member Function Documentation</h2> +<h3 class="fn"><a name="5514c7"></a>TQLabel::TQLabel(<a href="qwidget.html">TQWidget</a>*buddy, const<a href="qstring.html">TQString</a>&text, <a href="qwidget.html">TQWidget</a>*parent, constchar*name=0, WFlagsf=0)</h3> +<p>Constructs a label with a text and a buddy. +<p>The <em>text</em> is set with <a href="#dffb43">setText</a>(). The <em>buddy</em> is set with <a href="#191701">setBuddy</a>(). +<p>The <em>parent, name</em> and <em>f</em> arguments are passed to the <a href="qframe.html">TQFrame</a> +constructor. +<p>See also <a href="#dffb43">setText</a>(), <a href="#191701">setBuddy</a>(), <a href="#1f406e">setAlignment</a>(), <a href="qframe.html#c0d758">setFrameStyle</a>() and <a href="#ed9b8b">setIndent</a>(). +<h3 class="fn"><a name="39107d"></a>TQLabel::TQLabel(<a href="qwidget.html">TQWidget</a>*parent, constchar*name=0, WFlagsf=0)</h3> +<p>Constructs an empty label. +<p>The <em>parent, name</em> and <em>f</em> arguments are passed to the <a href="qframe.html">TQFrame</a> +constructor. +<p>See also <a href="#1f406e">setAlignment</a>(), <a href="qframe.html#c0d758">setFrameStyle</a>() and <a href="#ed9b8b">setIndent</a>(). +<h3 class="fn"><a name="2bafbb"></a>TQLabel::TQLabel(const<a href="qstring.html">TQString</a>&text, <a href="qwidget.html">TQWidget</a>*parent, constchar*name=0, WFlagsf=0)</h3> +<p>Constructs a label with a text. The <em>text</em> is set with <a href="#dffb43">setText</a>(). +<p>The <em>parent, name</em> and <em>f</em> arguments are passed to the <a href="qframe.html">TQFrame</a> +constructor. +<p>See also <a href="#dffb43">setText</a>(), <a href="#1f406e">setAlignment</a>(), <a href="qframe.html#c0d758">setFrameStyle</a>() and <a href="#ed9b8b">setIndent</a>(). +<h3 class="fn"><a name="9958af"></a>TQLabel::~TQLabel()</h3> +<p>Destructs the label. +<h3 class="fn">int<a name="2fcaa3"></a>TQLabel::alignment()const</h3> +<p>Returns the alignment setting. +<p>See also <a href="#1f406e">setAlignment</a>(). +<h3 class="fn">bool<a name="75b2a1"></a>TQLabel::autoResize()const</h3> +<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of TQt. We strongly advise against using it in new code.<p> +<p>Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing +is disabled. +<p>Auto-resizing is disabled by default. +<p>See also <a href="#c0e104">setAutoResize</a>(). +<h3 class="fn"><a href="qwidget.html">TQWidget</a>*<a name="123954"></a>TQLabel::buddy()const</h3> +<p>Returns the buddy of this label, or 0 if no buddy is currently set. +<p>See also <a href="#191701">setBuddy</a>(). +<h3 class="fn">void<a name="be73f3"></a>TQLabel::clear() <code>[slot]</code></h3> +<p>Clears any label contents. Equivalent with <a href="#dffb43">setText</a>( "" ). +<h3 class="fn">void<a name="fac264"></a>TQLabel::drawContents(<a href="qpainter.html">TQPainter</a>*p) <code>[virtualprotected]</code></h3> +<p>Draws the label contents using the painter <em>p.</em> +<p>Reimplemented from <a href="qframe.html#99e687">TQFrame.</a> +<h3 class="fn">void<a name="479dd2"></a>TQLabel::drawContentsMask(<a href="qpainter.html">TQPainter</a>*p) <code>[virtualprotected]</code></h3> +<p>Draws the label contents mask using the painter <em>p.</em> +Used only in transparent mode. +<p>See also <a href="qwidget.html#c7a335">TQWidget::setAutoMask</a>();. +<p>Reimplemented from <a href="qframe.html#4cbf11">TQFrame.</a> +<h3 class="fn">void<a name="0435a2"></a>TQLabel::fontChange(const<a href="qfont.html">TQFont</a>&) <code>[virtualprotected]</code></h3> +<p>Reimplemented for internal reasons; the API is not affected. +<p>Reimplemented from <a href="qwidget.html#570a8f">TQWidget.</a> +<h3 class="fn">bool<a name="7e1f73"></a>TQLabel::hasScaledContents()const</h3> +<p>Returns whether the label will scale its contents to fill all +available space. +<p>See also <a href="#e9e3cf">setScaledContents</a>(). +<h3 class="fn">int<a name="dae451"></a>TQLabel::heightForWidth(intw)const <code>[virtual]</code></h3> +<p>Reimplemented for internal reasons; the API is not affected. +<p>Reimplemented from <a href="qwidget.html#2e8476">TQWidget.</a> +<h3 class="fn">int<a name="e3c907"></a>TQLabel::indent()const</h3> +<p>Returns the indent of the label. +<p>See also <a href="#ed9b8b">setIndent</a>(). +<h3 class="fn"><a href="qsize.html">TQSize</a><a name="53c8c7"></a>TQLabel::minimumSizeHint()const <code>[virtual]</code></h3> +<p>Reimplemented for internal reasons; the API is not affected. +<p>Reimplemented from <a href="qwidget.html#3f0fc2">TQWidget.</a> +<h3 class="fn"><a href="qmovie.html">TQMovie</a>*<a name="7dcdfe"></a>TQLabel::movie()const</h3> +<p>If the label contains a movie, returns a pointer to it. Otherwise, +returns 0. +<p>See also <a href="#60de9f">setMovie</a>(). +<h3 class="fn"><a href="qpixmap.html">TQPixmap</a>*<a name="101ecb"></a>TQLabel::pixmap()const</h3> +<p>If the label contains a pixmap, returns a pointer to it. Otherwise, +returns 0. +<p>See also <a href="#f3f301">setPixmap</a>(). +<h3 class="fn">void<a name="3cb6e7"></a>TQLabel::resizeEvent(<a href="qresizeevent.html">TQResizeEvent</a>*e) <code>[virtualprotected]</code></h3> +<p>Reimplemented for internal reasons; the API is not affected. +<p>Reimplemented from <a href="qwidget.html#28c156">TQWidget.</a> +<h3 class="fn">void<a name="1f406e"></a>TQLabel::setAlignment(intalignment) <code>[virtual]</code></h3> +<p>Sets the alignment of the label contents. +<p>The <em>alignment</em> must be a bitwise OR of <a href="qt.html#AlignmentFlags">TQt::AlignmentFlags</a> +values. The <code>WordBreak, ExpandTabs, SingleLine</code> and <code>ShowPrefix</code> flags apply only if the label contains a plain text, and +are otherwise ignored. The <code>DontClip</code> flag is always ignored. +<p>If the label has a buddy, the <code>ShowPrefix</code> flag is forced to TRUE. +<p>The default alignment is <code>AlignLeft | AlignVCenter | +ExpandTabs</code> if the label doesn't have a buddy and +<code>AlignLeft | AlignVCenter | ExpandTabs | ShowPrefix </code> if +the label has a buddy. +<p>See also <a href="qt.html#AlignmentFlags">TQt::AlignmentFlags</a>, <a href="#2fcaa3">alignment</a>(), <a href="#191701">setBuddy</a>() and <a href="#dffb43">setText</a>(). +<p>Examples: + <a href="cursor-cursor-cpp.html#setAlignment">cursor/cursor.cpp</a> + <a href="layout-layout-cpp.html#setAlignment">layout/layout.cpp</a> + <a href="popup-popup-cpp.html#setAlignment">popup/popup.cpp</a> + <a href="qmag-qmag-cpp.html#setAlignment">qmag/qmag.cpp</a> + <a href="customlayout-main-cpp.html#setAlignment">customlayout/main.cpp</a> +<h3 class="fn">void<a name="1b6d73"></a>TQLabel::setAutoMask(boolb) <code>[virtual]</code></h3> +<p>Reimplemented for internal reasons; the API is not affected. +<p>Reimplemented from <a href="qwidget.html#c7a335">TQWidget.</a> +<h3 class="fn">void<a name="c0e104"></a>TQLabel::setAutoResize(boolenable) <code>[virtual]</code></h3> +<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of TQt. We strongly advise against using it in new code.<p> +Enables auto-resizing if <em>enable</em> is TRUE, or disables it if <em>enable</em> is FALSE. +<p>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 TQLabel widgets that are not managed by +a <a href="qlayout.html">TQLayout</a> (e.g. top-level widgets). +<p>Auto-resizing is disabled by default. +<p>See also <a href="#75b2a1">autoResize</a>(), <a href="qwidget.html#ab3108">adjustSize</a>() and <a href="#614dd5">sizeHint</a>(). +<h3 class="fn">void<a name="191701"></a>TQLabel::setBuddy(<a href="qwidget.html">TQWidget</a>*buddy) <code>[virtual]</code></h3> +<p>Sets the buddy of this label to <em>buddy.</em> +<p>When the user presses the accelerator key indicated by this label, +the keyboard focus is transferred to the label's buddy widget. +<p>The buddy mechanism is only available for TQLabels 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 <code>ShowPrefix</code> +alignment flag is turned on; see <a href="#1f406e">setAlignment</a>()). +<p>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: +<p><pre> <a href="qlineedit.html">TQLineEdit</a> *nameEd = new <a href="qlineedit.html">TQLineEdit</a>( this ); + <a href="qlabel.html">TQLabel</a> *nameLb = new <a href="qlabel.html">TQLabel</a>( "&Name:", this ); + nameLb-><a href="#191701">setBuddy</a>( nameEd ); + <a href="qlineedit.html">TQLineEdit</a> *phoneEd = new <a href="qlineedit.html">TQLineEdit</a>( this ); + <a href="qlabel.html">TQLabel</a> *phoneLb = new <a href="qlabel.html">TQLabel</a>( "&Phone:", this ); + phoneLb-><a href="#191701">setBuddy</a>( phoneEd ); + // ( layout setup not shown ) +</pre> +<p>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. +<p>To unset a previously set buddy, call this function with <em>buddy</em> +set to 0. +<p>See also <a href="#123954">buddy</a>(), <a href="#dffb43">setText</a>(), <a href="qaccel.html">TQAccel</a> and <a href="#1f406e">setAlignment</a>(). +<p>Examples: + <a href="layout-layout-cpp.html#setBuddy">layout/layout.cpp</a> +<h3 class="fn">void<a name="ed9b8b"></a>TQLabel::setIndent(intindent)</h3> +<p>Sets the indent of the label to <em>indent</em> pixels. +<p>The indent applies to the left edge if <a href="#2fcaa3">alignment</a>() is <code>AlignLeft,</code> +to the right edge if alignment() is <code>AlignRight,</code> to the top edge +if alignment() is <code>AlignTop,</code> and to to the bottom edge if +alignment() is <code>AlignBottom.</code> +<p>If <em>indent</em> is negative, or if no indent has been set, the label +computes the effective indent as follows: If <a href="qframe.html#e0ccef">frameWidth</a>() 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 <a href="qwidget.html#3a7237">font</a>(). +<p>If <em>indent</em> is non-negative, the effective indent is <em>indent</em> +pixels. +<p>See also <a href="#e3c907">indent</a>(), <a href="#1f406e">setAlignment</a>(), <a href="qframe.html#e0ccef">frameWidth</a>() and <a href="qwidget.html#3a7237">font</a>(). +<p>Examples: + <a href="movies-main-cpp.html#setIndent">movies/main.cpp</a> +<h3 class="fn">void<a name="60de9f"></a>TQLabel::setMovie(const<a href="qmovie.html">TQMovie</a>&movie) <code>[virtualslot]</code></h3> +<p>Sets the label contents to <em>movie.</em> Any previous content is cleared. +<p>The buddy accelerator, if any, is disabled. +<p>The label resizes itself if auto-resizing is enabled. +<p>See also <a href="#7dcdfe">movie</a>() and <a href="#191701">setBuddy</a>(). +<h3 class="fn">void<a name="1a8f6a"></a>TQLabel::setNum(doublenum) <code>[virtualslot]</code></h3> +<p>Sets the label contents to a plain text containing the printed value +of <em>num.</em> Does nothing if this is equal to the current contents of +the label. Any previous content is cleared. +<p>The buddy accelerator, if any, is disabled. +<p>The label resizes itself if auto-resizing is enabled. +<p>See also <a href="#dffb43">setText</a>(), <a href="qstring.html#01d80b">TQString::setNum</a>() and <a href="#191701">setBuddy</a>(). +<h3 class="fn">void<a name="301e3c"></a>TQLabel::setNum(intnum) <code>[virtualslot]</code></h3> +<p>Sets the label contents to a plain text containing the printed value +of <em>num.</em> Does nothing if this is equal to the current contents of +the label. Any previous content is cleared. +<p>The buddy accelerator, if any, is disabled. +<p>The label resizes itself if auto-resizing is enabled. +<p>See also <a href="#dffb43">setText</a>(), <a href="qstring.html#01d80b">TQString::setNum</a>() and <a href="#191701">setBuddy</a>(). +<h3 class="fn">void<a name="f3f301"></a>TQLabel::setPixmap(const<a href="qpixmap.html">TQPixmap</a>&pixmap) <code>[virtualslot]</code></h3> +<p>Sets the label contents to <em>pixmap.</em> Any previous content is cleared. +<p>The buddy accelerator, if any, is disabled. +<p>The label resizes itself if auto-resizing is enabled. +<p>See also <a href="#101ecb">pixmap</a>() and <a href="#191701">setBuddy</a>(). +<h3 class="fn">void<a name="e9e3cf"></a>TQLabel::setScaledContents(boolenable)</h3> +<p>When called with <em>enable</em> == TRUE, and the label shows a pixmap, +it will scale the pixmap to fill available space. +<p>See also <a href="#7e1f73">hasScaledContents</a>(). +<h3 class="fn">void<a name="dffb43"></a>TQLabel::setText(const<a href="qstring.html">TQString</a>&text) <code>[virtualslot]</code></h3> +<p>Sets the label contents to <em>text,</em> or does nothing if <em>text</em> is +equal to the current contents of the label. Any previous content is +cleared. +<p><em>text</em> will be interpreted either as a plain text or as a rich +text, depending on the text format setting; see <a href="#5de3f9">setTextFormat</a>(). The +default setting is <code>AutoText,</code> i.e. TQLabel will try to auto-detect +the format of <em>text.</em> +<p>If <em>text</em> is interpreted as a plain text, and a buddy has been set, +the buddy accelerator key is updated from the new text. +<p>The label resizes itself if auto-resizing is enabled. +<p>Note that Qlabel is well suited to display small rich text documents +only. For large documents, use <a href="qtextview.html">TQTextView</a> instead. It will flicker +less on resize and can also provide a scrollbar if necessary. +<p>See also <a href="#72cf09">text</a>(), <a href="#5de3f9">setTextFormat</a>(), <a href="#191701">setBuddy</a>() and <a href="#1f406e">setAlignment</a>(). +<p>Examples: + <a href="cursor-cursor-cpp.html#setText">cursor/cursor.cpp</a> + <a href="layout-layout-cpp.html#setText">layout/layout.cpp</a> + <a href="popup-popup-cpp.html#setText">popup/popup.cpp</a> + <a href="qmag-qmag-cpp.html#setText">qmag/qmag.cpp</a> + <a href="customlayout-main-cpp.html#setText">customlayout/main.cpp</a> +<h3 class="fn">void<a name="5de3f9"></a>TQLabel::setTextFormat(<a href="qt.html#TextFormat">TQt::TextFormat</a>format)</h3> +<p>Sets the text format to <em>format.</em> See the <a href="qt.html#TextFormat">TQt::TextFormat</a> enum for +an explanation of the possible options. +<p>The default format is <code>AutoText.</code> +<p>See also <a href="#0b92ed">textFormat</a>() and <a href="#dffb43">setText</a>(). +<h3 class="fn"><a href="qsize.html">TQSize</a><a name="614dd5"></a>TQLabel::sizeHint()const <code>[virtual]</code></h3> +<p>Reimplemented for internal reasons; the API is not affected. +<p>Examples: + <a href="layout-layout-cpp.html#sizeHint">layout/layout.cpp</a> +<p>Reimplemented from <a href="qwidget.html#290bcd">TQWidget.</a> +<h3 class="fn"><a href="qsizepolicy.html">TQSizePolicy</a><a name="26e1d9"></a>TQLabel::sizePolicy()const <code>[virtual]</code></h3> +<p>Reimplemented for internal reasons; the API is not affected. +<p>Reimplemented from <a href="qwidget.html#2d5d13">TQWidget.</a> +<h3 class="fn"><a href="qstring.html">TQString</a><a name="72cf09"></a>TQLabel::text()const</h3> +<p>Returns the label text. If the content is a plain or a rich text, +this is the string that was passed to <a href="#dffb43">setText</a>(). Otherwise, it is an +empty/null string. +<p>See also <a href="#dffb43">setText</a>(), <a href="#1a8f6a">setNum</a>() and <a href="#be73f3">clear</a>(). +<h3 class="fn">TQt::TextFormat<a name="0b92ed"></a>TQLabel::textFormat()const</h3> +<p>Returns the current text format. +<p>See also <a href="#5de3f9">setTextFormat</a>(). +<hr><p> +Search the documentation, FAQ, qt-interest archive and more (uses +<a href="http://www.trolltech.com">www.trolltech.com</a>):<br> +<form method=post action="http://www.trolltech.com/search.cgi"> +<input type=hidden name="version" value="3.0.0-snapshot"><nobr> +<input size="50" name="search"><input type=submit value="Search"> +</nobr></form><hr><p> +This file is part of the <a href="index.html">TQt toolkit</a>, +copyright © 1995-2006 +<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center"> +<table width="100%" cellspacing="0" border="0"><tr> +<td>Copyright 2006 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a> +<td align="right"><div align="right">TQt version 3.0.0-snapshot</div> +</table></div></address></body></html> diff --git a/examples/demo/textdrawing/filenew.png b/examples/demo/textdrawing/filenew.png Binary files differnew file mode 100644 index 000000000..be963bf86 --- /dev/null +++ b/examples/demo/textdrawing/filenew.png diff --git a/examples/demo/textdrawing/fileopen.png b/examples/demo/textdrawing/fileopen.png Binary files differnew file mode 100644 index 000000000..6077b815f --- /dev/null +++ b/examples/demo/textdrawing/fileopen.png diff --git a/examples/demo/textdrawing/filesave.png b/examples/demo/textdrawing/filesave.png Binary files differnew file mode 100644 index 000000000..a1cb03dd0 --- /dev/null +++ b/examples/demo/textdrawing/filesave.png diff --git a/examples/demo/textdrawing/help.png b/examples/demo/textdrawing/help.png Binary files differnew file mode 100644 index 000000000..2ab2c25d7 --- /dev/null +++ b/examples/demo/textdrawing/help.png diff --git a/examples/demo/textdrawing/helpwindow.cpp b/examples/demo/textdrawing/helpwindow.cpp new file mode 100644 index 000000000..de353df7d --- /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 TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "helpwindow.h" +#include <qstatusbar.h> +#include <qpixmap.h> +#include <qpopupmenu.h> +#include <qmenubar.h> +#include <qtoolbar.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 <qfile.h> +#include <qdatastream.h> +#include <qprinter.h> +#include <qsimplerichtext.h> +#include <qpainter.h> +#include <qpaintdevicemetrics.h> + +#include <ctype.h> + +HelpWindow::HelpWindow( const TQString& home_, const TQString& _path, + TQWidget* parent, const char *name ) + : TQMainWindow( parent, name, WDestructiveClose ), + pathCombo( 0 ), selectedURL() +{ + readHistory(); + readBookmarks(); + + browser = new TQTextBrowser( this ); + browser->mimeSourceFactory()->setFilePath( _path ); + browser->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + connect( browser, SIGNAL( textChanged() ), + this, SLOT( textChanged() ) ); + + setCentralWidget( browser ); + + if ( !home_.isEmpty() ) + browser->setSource( home_ ); + + connect( browser, SIGNAL( highlighted( const TQString&) ), + statusBar(), SLOT( message( const TQString&)) ); + + resize( 640,700 ); + + TQPopupMenu* file = new TQPopupMenu( 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. + TQIconSet icon_back( TQPixmap("textdrawing/previous.png") ); + TQIconSet icon_forward( TQPixmap("textdrawing/next.png") ); + TQIconSet icon_home( TQPixmap("textdrawing/home.png") ); + + TQPopupMenu* go = new TQPopupMenu( 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 TQPopupMenu( this ); + TQStringList::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 TQPopupMenu( this ); + bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); + bookm->insertSeparator(); + + TQStringList::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 ) ) ); + + + TQToolBar* toolbar = new TQToolBar( this ); + addToolBar( toolbar, "Toolbar"); + TQToolButton* button; + + button = new TQToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar ); + connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); + button->setEnabled( FALSE ); + button = new TQToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar ); + connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); + button->setEnabled( FALSE ); + button = new TQToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar ); + + toolbar->addSeparator(); + + pathCombo = new TQComboBox( TRUE, toolbar ); + connect( pathCombo, SIGNAL( activated( const TQString & ) ), + this, SLOT( pathSelected( const TQString & ) ) ); + 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 = TQString::null; + } +} + +HelpWindow::~HelpWindow() +{ + history.clear(); + TQMap<int, TQString>::Iterator it = mHistory.begin(); + for ( ; it != mHistory.end(); ++it ) + history.append( *it ); + + TQFile f( TQDir::currentDirPath() + "/.history" ); + f.open( IO_WriteOnly ); + TQDataStream s( &f ); + s << history; + f.close(); + + bookmarks.clear(); + TQMap<int, TQString>::Iterator it2 = mBookmarks.begin(); + for ( ; it2 != mBookmarks.end(); ++it2 ) + bookmarks.append( *it2 ); + + TQFile f2( TQDir::currentDirPath() + "/.bookmarks" ); + f2.open( IO_WriteOnly ); + TQDataStream s2( &f2 ); + s2 << bookmarks; + f2.close(); +} + +void HelpWindow::about() +{ + TQMessageBox::about( this, "HelpViewer Example", + "<p>This example implements a simple HTML help viewer " + "using TQt's rich text capabilities</p>" + "<p>It's just about 100 lines of C++ code, so don't expect too much :-)</p>" + ); +} + + +void HelpWindow::aboutTQt() +{ + TQMessageBox::aboutTQt( this, "TQBrowser" ); +} + +void HelpWindow::openFile() +{ +#ifndef QT_NO_FILEDIALOG + TQString fn = TQFileDialog::getOpenFileName( TQString::null, TQString::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 + TQPrinter printer; + printer.setFullPage(TRUE); + if ( printer.setup() ) { + TQPainter p( &printer ); + TQPaintDeviceMetrics metrics(p.device()); + int dpix = metrics.logicalDpiX(); + int dpiy = metrics.logicalDpiY(); + const int margin = 72; // pt + TQRect body(margin*dpix/72, margin*dpiy/72, + metrics.width()-margin*dpix/72*2, + metrics.height()-margin*dpiy/72*2 ); + TQFont font("times", 10); + TQStringList filePaths = browser->mimeSourceFactory()->filePath(); + TQString file; + TQStringList::Iterator it = filePaths.begin(); + for ( ; it != filePaths.end(); ++it ) { + file = TQUrl( *it, TQUrl( browser->source() ).path() ).path(); + if ( TQFile::exists( file ) ) + break; + else + file = TQString::null; + } + if ( file.isEmpty() ) + return; + TQFile f( file ); + if ( !f.open( IO_ReadOnly ) ) + return; + TQTextStream ts( &f ); + TQSimpleRichText richText( ts.read(), font, browser->context(), browser->styleSheet(), + browser->mimeSourceFactory(), body.height() ); + richText.setWidth( &p, body.width() ); + TQRect 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( TQString::number(page) ), + view.bottom() + p.fontMetrics().ascent() + 5, TQString::number(page) ); + if ( view.top() >= richText.height() ) + break; + printer.newPage(); + page++; + } while (TRUE); + } +#endif +} + +void HelpWindow::pathSelected( const TQString &_path ) +{ + browser->setSource( _path ); + TQMap<int, TQString>::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 ( TQFile::exists( TQDir::currentDirPath() + "/.history" ) ) { + TQFile f( TQDir::currentDirPath() + "/.history" ); + f.open( IO_ReadOnly ); + TQDataStream s( &f ); + s >> history; + f.close(); + while ( history.count() > 20 ) + history.remove( history.begin() ); + } +} + +void HelpWindow::readBookmarks() +{ + if ( TQFile::exists( TQDir::currentDirPath() + "/.bookmarks" ) ) { + TQFile f( TQDir::currentDirPath() + "/.bookmarks" ); + f.open( IO_ReadOnly ); + TQDataStream 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 000000000..0115da9fc --- /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 TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef HELPWINDOW_H +#define HELPWINDOW_H + +#include <qmainwindow.h> +#include <qtextbrowser.h> +#include <qstringlist.h> +#include <qmap.h> +#include <qdir.h> + +class TQComboBox; +class TQPopupMenu; + +class HelpWindow : public TQMainWindow +{ + Q_OBJECT +public: + HelpWindow( const TQString& home_, const TQString& path, TQWidget* parent = 0, const char *name=0 ); + ~HelpWindow(); + +private slots: + void setBackwardAvailable( bool ); + void setForwardAvailable( bool ); + + void textChanged(); + void about(); + void aboutTQt(); + void openFile(); + void newWindow(); + void print(); + + void pathSelected( const TQString & ); + void histChosen( int ); + void bookmChosen( int ); + void addBookmark(); + +private: + void readHistory(); + void readBookmarks(); + + TQTextBrowser* browser; + TQComboBox *pathCombo; + int backwardId, forwardId; + TQString selectedURL; + TQStringList history, bookmarks; + TQMap<int, TQString> mHistory, mBookmarks; + TQPopupMenu *hist, *bookm; + +}; + + + + + +#endif + diff --git a/examples/demo/textdrawing/home.png b/examples/demo/textdrawing/home.png Binary files differnew file mode 100644 index 000000000..aa150a32c --- /dev/null +++ b/examples/demo/textdrawing/home.png diff --git a/examples/demo/textdrawing/next.png b/examples/demo/textdrawing/next.png Binary files differnew file mode 100644 index 000000000..4b29ff454 --- /dev/null +++ b/examples/demo/textdrawing/next.png diff --git a/examples/demo/textdrawing/previous.png b/examples/demo/textdrawing/previous.png Binary files differnew file mode 100644 index 000000000..4e3556c8d --- /dev/null +++ b/examples/demo/textdrawing/previous.png diff --git a/examples/demo/textdrawing/print.png b/examples/demo/textdrawing/print.png Binary files differnew file mode 100644 index 000000000..57e3e532f --- /dev/null +++ b/examples/demo/textdrawing/print.png diff --git a/examples/demo/textdrawing/redo.png b/examples/demo/textdrawing/redo.png Binary files differnew file mode 100644 index 000000000..bae07d3eb --- /dev/null +++ b/examples/demo/textdrawing/redo.png diff --git a/examples/demo/textdrawing/textbold.png b/examples/demo/textdrawing/textbold.png Binary files differnew file mode 100644 index 000000000..7b5be472a --- /dev/null +++ b/examples/demo/textdrawing/textbold.png diff --git a/examples/demo/textdrawing/textcenter.png b/examples/demo/textdrawing/textcenter.png Binary files differnew file mode 100644 index 000000000..5c68b09ce --- /dev/null +++ b/examples/demo/textdrawing/textcenter.png diff --git a/examples/demo/textdrawing/textedit.cpp b/examples/demo/textdrawing/textedit.cpp new file mode 100644 index 000000000..57949a7a7 --- /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 TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "textedit.h" + +#include <qtextedit.h> +#include <qaction.h> +#include <qmenubar.h> +#include <qpopupmenu.h> +#include <qtoolbar.h> +#include <qtabwidget.h> +#include <qapplication.h> +#include <qfontdatabase.h> +#include <qcombobox.h> +#include <qlineedit.h> +#include <qfileinfo.h> +#include <qfile.h> +#include <qfiledialog.h> +#include <qprinter.h> +#include <qpaintdevicemetrics.h> +#include <qsimplerichtext.h> +#include <qcolordialog.h> +#include <qpainter.h> + +TextEdit::TextEdit( TQWidget *parent, const char *name ) + : TQMainWindow( parent, name, 0 ) +{ + setupFileActions(); + setupEditActions(); + setupTextActions(); + + tabWidget = new TQTabWidget( this ); + connect( tabWidget, SIGNAL( currentChanged( TQWidget * ) ), + this, SLOT( editorChanged( TQWidget * ) ) ); + setCentralWidget( tabWidget ); +} + +void TextEdit::setupFileActions() +{ + TQToolBar *tb = new TQToolBar( this ); + TQPopupMenu *menu = new TQPopupMenu( this ); + menuBar()->insertItem( tr( "&File" ), menu ); + + TQAction *a; + a = new TQAction( tr( "New" ), TQPixmap( "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 TQAction( tr( "Open" ), TQPixmap( "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 TQAction( tr( "Save" ), TQPixmap( "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 TQAction( tr( "Save As" ), TQPixmap(), tr( "Save &As..." ), 0, this, "fileSaveAs" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileSaveAs() ) ); + a->addTo( menu ); + menu->insertSeparator(); + a = new TQAction( tr( "Print" ), TQPixmap( "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 TQAction( tr( "Close" ), TQPixmap(), tr( "&Close" ), 0, this, "fileClose" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) ); + a->addTo( menu ); +} + +void TextEdit::setupEditActions() +{ + TQToolBar *tb = new TQToolBar( this ); + TQPopupMenu *menu = new TQPopupMenu( this ); + menuBar()->insertItem( tr( "&Edit" ), menu ); + + TQAction *a; + a = new TQAction( tr( "Undo" ), TQPixmap( "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 TQAction( tr( "Redo" ), TQPixmap( "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 TQAction( tr( "Cut" ), TQPixmap( "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 TQAction( tr( "Copy" ), TQPixmap( "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 TQAction( tr( "Paste" ), TQPixmap( "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() +{ + TQToolBar *tb = new TQToolBar( this ); + TQPopupMenu *menu = new TQPopupMenu( this ); + menuBar()->insertItem( tr( "For&mat" ), menu ); + + comboStyle = new TQComboBox( 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 TQComboBox( TRUE, tb ); + TQFontDatabase db; + comboFont->insertStringList( db.families() ); + connect( comboFont, SIGNAL( activated( const TQString & ) ), + this, SLOT( textFamily( const TQString & ) ) ); + comboFont->lineEdit()->setText( TQApplication::font().family() ); + + comboSize = new TQComboBox( TRUE, tb ); + TQValueList<int> sizes = db.standardSizes(); + TQValueList<int>::Iterator it = sizes.begin(); + for ( ; it != sizes.end(); ++it ) + comboSize->insertItem( TQString::number( *it ) ); + connect( comboSize, SIGNAL( activated( const TQString & ) ), + this, SLOT( textSize( const TQString & ) ) ); + comboSize->lineEdit()->setText( TQString::number( TQApplication::font().pointSize() ) ); + + actionTextBold = new TQAction( tr( "Bold" ), TQPixmap( "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 TQAction( tr( "Italic" ), TQPixmap( "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 TQAction( tr( "Underline" ), TQPixmap( "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(); + + TQActionGroup *grp = new TQActionGroup( this ); + grp->setExclusive( TRUE ); + connect( grp, SIGNAL( selected( TQAction* ) ), this, SLOT( textAlign( TQAction* ) ) ); + + actionAlignLeft = new TQAction( tr( "Left" ), TQPixmap( "textdrawing/textleft.png" ), tr( "&Left" ), CTRL + Key_L, grp, "textLeft" ); + actionAlignLeft->addTo( tb ); + actionAlignLeft->addTo( menu ); + actionAlignLeft->setToggleAction( TRUE ); + actionAlignCenter = new TQAction( tr( "Center" ), TQPixmap( "textdrawing/textcenter.png" ), tr( "C&enter" ), CTRL + Key_M, grp, "textCenter" ); + actionAlignCenter->addTo( tb ); + actionAlignCenter->addTo( menu ); + actionAlignCenter->setToggleAction( TRUE ); + actionAlignRight = new TQAction( tr( "Right" ), TQPixmap( "textdrawing/textright.png" ), tr( "&Right" ), CTRL + Key_R, grp, "textRight" ); + actionAlignRight->addTo( tb ); + actionAlignRight->addTo( menu ); + actionAlignRight->setToggleAction( TRUE ); + actionAlignJustify = new TQAction( tr( "Justify" ), TQPixmap( "textdrawing/textjustify.png" ), tr( "&Justify" ), CTRL + Key_J, grp, "textjustify" ); + actionAlignJustify->addTo( tb ); + actionAlignJustify->addTo( menu ); + actionAlignJustify->setToggleAction( TRUE ); + + menu->insertSeparator(); + + TQPixmap pix( 16, 16 ); + pix.fill( black ); + actionTextColor = new TQAction( 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 TQString &f ) +{ + if ( !TQFile::exists( f ) ) + return; + TQTextEdit *edit = new TQTextEdit( tabWidget ); + doConnections( edit ); + tabWidget->addTab( edit, TQFileInfo( f ).fileName() ); + + TQFile fl( f ); + fl.open( IO_ReadOnly ); + TQByteArray array = fl.readAll(); + array.resize( array.size() +1 ); + array[ (int)array.size() - 1 ] = '\0'; + TQString text = ( f.find( "bidi.txt" ) != -1 ? TQString::fromUtf8( array.data() ) : TQString::fromLatin1( array.data() ) ); + edit->setText( text ); + + edit->viewport()->setFocus(); + edit->setTextFormat( TQt::RichText ); +} + +TQTextEdit *TextEdit::currentEditor() const +{ + if ( tabWidget->currentPage() && + tabWidget->currentPage()->inherits( "TQTextEdit" ) ) + return (TQTextEdit*)tabWidget->currentPage(); + return 0; +} + +void TextEdit::doConnections( TQTextEdit *e ) +{ + connect( e, SIGNAL( currentFontChanged( const TQFont & ) ), + this, SLOT( fontChanged( const TQFont & ) ) ); + connect( e, SIGNAL( currentColorChanged( const TQColor & ) ), + this, SLOT( colorChanged( const TQColor & ) ) ); + connect( e, SIGNAL( currentAlignmentChanged( int ) ), + this, SLOT( alignmentChanged( int ) ) ); +} + +void TextEdit::fileNew() +{ + TQTextEdit *edit = new TQTextEdit( tabWidget ); + doConnections( edit ); + tabWidget->addTab( edit, tr( "noname" ) ); + tabWidget->showPage( edit ); + edit->viewport()->setFocus(); +} + +void TextEdit::fileOpen() +{ + TQString fn = TQFileDialog::getOpenFileName( TQString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) + load( fn ); +} + +void TextEdit::fileSave() +{ + if ( !currentEditor() ) + return; + TQString fn; + if ( filenames.find( currentEditor() ) == filenames.end() ) { + fileSaveAs(); + } else { + TQFile file( *filenames.find( currentEditor() ) ); + if ( !file.open( IO_WriteOnly ) ) + return; + TQTextStream ts( &file ); + ts << currentEditor()->text(); + } +} + +void TextEdit::fileSaveAs() +{ + if ( !currentEditor() ) + return; + TQString fn = TQFileDialog::getSaveFileName( TQString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) { + filenames.replace( currentEditor(), fn ); + fileSave(); + tabWidget->setTabLabel( currentEditor(), TQFileInfo( fn ).fileName() ); + } +} + +void TextEdit::filePrint() +{ + if ( !currentEditor() ) + return; +#ifndef QT_NO_PRINTER + TQPrinter printer; + printer.setFullPage(TRUE); + TQPaintDeviceMetrics screen( this ); + printer.setResolution( screen.logicalDpiY() ); + if ( printer.setup( this ) ) { + TQPainter p( &printer ); + TQPaintDeviceMetrics metrics( p.device() ); + int dpix = metrics.logicalDpiX(); + int dpiy = metrics.logicalDpiY(); + const int margin = 72; // pt + TQRect body( margin * dpix / 72, margin * dpiy / 72, + metrics.width() - margin * dpix / 72 * 2, + metrics.height() - margin * dpiy / 72 * 2 ); + TQFont font( "times", 10 ); + TQSimpleRichText richText( currentEditor()->text(), font, currentEditor()->context(), currentEditor()->styleSheet(), + currentEditor()->mimeSourceFactory(), body.height() ); + richText.setWidth( &p, body.width() ); + TQRect 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( TQString::number( page ) ), + view.bottom() + p.fontMetrics().ascent() + 5, TQString::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->tquit(); +} + +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 TQString &f ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setFamily( f ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textSize( const TQString &p ) +{ + if ( !currentEditor() ) + return; + currentEditor()->setPointSize( p.toInt() ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textStyle( int i ) +{ + if ( !currentEditor() ) + return; + if ( i == 0 ) + currentEditor()->setParagType( TQStyleSheetItem::DisplayBlock, TQStyleSheetItem::ListDisc ); + else if ( i == 1 ) + currentEditor()->setParagType( TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListDisc ); + else if ( i == 2 ) + currentEditor()->setParagType( TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListCircle ); + else if ( i == 3 ) + currentEditor()->setParagType( TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListSquare ); + else if ( i == 4 ) + currentEditor()->setParagType( TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListDecimal ); + else if ( i == 5 ) + currentEditor()->setParagType( TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListLowerAlpha ); + else if ( i == 6 ) + currentEditor()->setParagType( TQStyleSheetItem::DisplayListItem, TQStyleSheetItem::ListUpperAlpha ); + currentEditor()->viewport()->setFocus(); +} + +void TextEdit::textColor() +{ + if ( !currentEditor() ) + return; + TQColor col = TQColorDialog::getColor( currentEditor()->color(), this ); + if ( !col.isValid() ) + return; + currentEditor()->setColor( col ); + TQPixmap pix( 16, 16 ); + pix.fill( col ); + actionTextColor->setIconSet( pix ); +} + +void TextEdit::textAlign( TQAction *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 TQFont &f ) +{ + comboFont->lineEdit()->setText( f.family() ); + comboSize->lineEdit()->setText( TQString::number( f.pointSize() ) ); + actionTextBold->setOn( f.bold() ); + actionTextItalic->setOn( f.italic() ); + actionTextUnderline->setOn( f.underline() ); +} + +void TextEdit::colorChanged( const TQColor &c ) +{ + TQPixmap 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( TQWidget * ) +{ + 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 000000000..38c9c5b2d --- /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 TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef TEXTEDIT_H +#define TEXTEDIT_H + +#include <qmainwindow.h> +#include <qmap.h> + +class TQAction; +class TQComboBox; +class TQTabWidget; +class TQTextEdit; + +class TextEdit : public TQMainWindow +{ + Q_OBJECT + +public: + TextEdit( TQWidget *parent = 0, const char *name = 0 ); + + TQTextEdit *currentEditor() const; + void load( const TQString &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 TQString &f ); + void textSize( const TQString &p ); + void textStyle( int s ); + void textColor(); + void textAlign( TQAction *a ); + + void fontChanged( const TQFont &f ); + void colorChanged( const TQColor &c ); + void alignmentChanged( int a ); + void editorChanged( TQWidget * ); + + +private: + void setupFileActions(); + void setupEditActions(); + void setupTextActions(); + void doConnections( TQTextEdit *e ); + + TQAction *actionTextBold, + *actionTextUnderline, + *actionTextItalic, + *actionTextColor, + *actionAlignLeft, + *actionAlignCenter, + *actionAlignRight, + *actionAlignJustify; + TQComboBox *comboStyle, + *comboFont, + *comboSize; + TQTabWidget *tabWidget; + TQMap<TQTextEdit*, TQString> filenames; + +}; + + +#endif diff --git a/examples/demo/textdrawing/textitalic.png b/examples/demo/textdrawing/textitalic.png Binary files differnew file mode 100644 index 000000000..68e2b44ce --- /dev/null +++ b/examples/demo/textdrawing/textitalic.png diff --git a/examples/demo/textdrawing/textjustify.png b/examples/demo/textdrawing/textjustify.png Binary files differnew file mode 100644 index 000000000..1c6e5b952 --- /dev/null +++ b/examples/demo/textdrawing/textjustify.png diff --git a/examples/demo/textdrawing/textleft.png b/examples/demo/textdrawing/textleft.png Binary files differnew file mode 100644 index 000000000..30b05019e --- /dev/null +++ b/examples/demo/textdrawing/textleft.png diff --git a/examples/demo/textdrawing/textright.png b/examples/demo/textdrawing/textright.png Binary files differnew file mode 100644 index 000000000..73f1cad5d --- /dev/null +++ b/examples/demo/textdrawing/textright.png diff --git a/examples/demo/textdrawing/textunderline.png b/examples/demo/textdrawing/textunderline.png Binary files differnew file mode 100644 index 000000000..3477ccb33 --- /dev/null +++ b/examples/demo/textdrawing/textunderline.png diff --git a/examples/demo/textdrawing/undo.png b/examples/demo/textdrawing/undo.png Binary files differnew file mode 100644 index 000000000..d5b6c1634 --- /dev/null +++ b/examples/demo/textdrawing/undo.png |