From 0e787fb7f5b56b4fe87cd8ada64ae740bbca87bc Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 24 Jul 2024 19:37:05 +0900 Subject: Rename text class nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/widgets/ntqlabel.h | 174 ----- src/widgets/ntqsyntaxhighlighter.h | 81 --- src/widgets/ntqwhatsthis.h | 81 --- src/widgets/qlabel.cpp | 1191 ----------------------------------- src/widgets/qlineedit.cpp | 2 +- src/widgets/qsyntaxhighlighter.cpp | 221 ------- src/widgets/qsyntaxhighlighter_p.h | 97 --- src/widgets/qt_widgets.pri | 18 +- src/widgets/qtitlebar_p.h | 2 +- src/widgets/qwhatsthis.cpp | 1001 ----------------------------- src/widgets/tqaction.cpp | 2 +- src/widgets/tqlabel.cpp | 1191 +++++++++++++++++++++++++++++++++++ src/widgets/tqlabel.h | 174 +++++ src/widgets/tqmainwindow.cpp | 2 +- src/widgets/tqpopupmenu.cpp | 8 +- src/widgets/tqsyntaxhighlighter.cpp | 221 +++++++ src/widgets/tqsyntaxhighlighter.h | 81 +++ src/widgets/tqsyntaxhighlighter_p.h | 97 +++ src/widgets/tqtextbrowser.cpp | 2 +- src/widgets/tqtextedit.cpp | 2 +- src/widgets/tqtooltip.cpp | 2 +- src/widgets/tqwhatsthis.cpp | 1001 +++++++++++++++++++++++++++++ src/widgets/tqwhatsthis.h | 81 +++ 23 files changed, 2866 insertions(+), 2866 deletions(-) delete mode 100644 src/widgets/ntqlabel.h delete mode 100644 src/widgets/ntqsyntaxhighlighter.h delete mode 100644 src/widgets/ntqwhatsthis.h delete mode 100644 src/widgets/qlabel.cpp delete mode 100644 src/widgets/qsyntaxhighlighter.cpp delete mode 100644 src/widgets/qsyntaxhighlighter_p.h delete mode 100644 src/widgets/qwhatsthis.cpp create mode 100644 src/widgets/tqlabel.cpp create mode 100644 src/widgets/tqlabel.h create mode 100644 src/widgets/tqsyntaxhighlighter.cpp create mode 100644 src/widgets/tqsyntaxhighlighter.h create mode 100644 src/widgets/tqsyntaxhighlighter_p.h create mode 100644 src/widgets/tqwhatsthis.cpp create mode 100644 src/widgets/tqwhatsthis.h (limited to 'src/widgets') diff --git a/src/widgets/ntqlabel.h b/src/widgets/ntqlabel.h deleted file mode 100644 index f8d728807..000000000 --- a/src/widgets/ntqlabel.h +++ /dev/null @@ -1,174 +0,0 @@ -/********************************************************************** -** -** Definition of TQLabel widget class -** -** Created : 941215 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQLABEL_H -#define TQLABEL_H - -#ifndef QT_H -#include "ntqframe.h" -#endif // QT_H - -#ifndef TQT_NO_LABEL - -class TQSimpleRichText; -class TQLabelPrivate; - -class TQ_EXPORT TQLabel : public TQFrame -{ - TQ_OBJECT - TQ_PROPERTY( TQString text READ text WRITE setText ) - TQ_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat ) - TQ_PROPERTY( TQPixmap pixmap READ pixmap WRITE setPixmap ) - TQ_PROPERTY( bool scaledContents READ hasScaledContents WRITE setScaledContents ) - TQ_PROPERTY( Alignment alignment READ alignment WRITE setAlignment ) - TQ_PROPERTY( int indent READ indent WRITE setIndent ) - TQ_OVERRIDE( BackgroundMode backgroundMode DESIGNABLE true) - -public: - TQLabel( TQWidget *parent, const char* name=0, WFlags f=0 ); - TQLabel( const TQString &text, TQWidget *parent, const char* name=0, - WFlags f=0 ); - TQLabel( TQWidget *buddy, const TQString &, - TQWidget *parent, const char* name=0, WFlags f=0 ); - ~TQLabel(); - - TQString text() const { return ltext; } - TQPixmap *pixmap() const { return lpixmap; } -#ifndef TQT_NO_PICTURE - TQPicture *picture() const { return lpicture; } -#endif -#ifndef TQT_NO_MOVIE - TQMovie *movie() const; -#endif - - TextFormat textFormat() const; - void setTextFormat( TextFormat ); - - int alignment() const { return align; } - virtual void setAlignment( int ); - int indent() const { return extraMargin; } - void setIndent( int ); - - bool autoResize() const { return autoresize; } - virtual void setAutoResize( bool ); -#ifndef TQT_NO_IMAGE_SMOOTHSCALE - bool hasScaledContents() const; - void setScaledContents( bool ); -#endif - TQSize sizeHint() const; - TQSize minimumSizeHint() const; -#ifndef TQT_NO_ACCEL - virtual void setBuddy( TQWidget * ); - TQWidget *buddy() const; -#endif - int heightForWidth(int) const; - - void setFont( const TQFont &f ); - -public slots: - virtual void setText( const TQString &); - virtual void setPixmap( const TQPixmap & ); -#ifndef TQT_NO_PICTURE - virtual void setPicture( const TQPicture & ); -#endif -#ifndef TQT_NO_MOVIE - virtual void setMovie( const TQMovie & ); -#endif - virtual void setNum( int ); - virtual void setNum( double ); - void clear(); - -protected: - void drawContents( TQPainter * ); - void fontChange( const TQFont & ); - void resizeEvent( TQResizeEvent* ); - -private slots: -#ifndef TQT_NO_ACCEL - void acceleratorSlot(); - void buddyDied(); -#endif -#ifndef TQT_NO_MOVIE - void movieUpdated(const TQRect&); - void movieResized(const TQSize&); -#endif - -private: - void init(); - void clearContents(); - void updateLabel( TQSize oldSizeHint ); - TQSize sizeForWidth( int w ) const; - TQString ltext; - TQPixmap *lpixmap; -#ifndef TQT_NO_PICTURE - TQPicture *lpicture; -#endif -#ifndef TQT_NO_MOVIE - TQMovie * lmovie; -#endif -#ifndef TQT_NO_ACCEL - TQWidget * lbuddy; -#endif - ushort align; - short extraMargin; - uint autoresize:1; - uint scaledcontents :1; - TextFormat textformat; -#ifndef TQT_NO_RICHTEXT - TQSimpleRichText* doc; -#endif -#ifndef TQT_NO_ACCEL - TQAccel * accel; -#endif - TQLabelPrivate* d; - - friend class TQTipLabel; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQLabel( const TQLabel & ); - TQLabel &operator=( const TQLabel & ); -#endif -}; - - -#endif // TQT_NO_LABEL - -#endif // TQLABEL_H diff --git a/src/widgets/ntqsyntaxhighlighter.h b/src/widgets/ntqsyntaxhighlighter.h deleted file mode 100644 index 81556553e..000000000 --- a/src/widgets/ntqsyntaxhighlighter.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Definition of the TQSyntaxHighlighter class -** -** Created : 022407 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQSYNTAXHIGHLIGHTER_H -#define TQSYNTAXHIGHLIGHTER_H - -#ifndef QT_H -#include "tqfont.h" -#include "tqcolor.h" -#include "tqstring.h" -#endif // QT_H - -class TQTextEdit; -class TQSyntaxHighlighterInternal; -class TQSyntaxHighlighterPrivate; -class TQTextParagraph; - -class TQ_EXPORT TQSyntaxHighlighter : public TQt -{ - friend class TQSyntaxHighlighterInternal; - -public: - TQSyntaxHighlighter( TQTextEdit *textEdit ); - virtual ~TQSyntaxHighlighter(); - - virtual int highlightParagraph( const TQString &text, int endStateOfLastPara ) = 0; - - void setFormat( int start, int count, const TQFont &font, const TQColor &color ); - void setFormat( int start, int count, const TQColor &color ); - void setFormat( int start, int count, const TQFont &font ); - TQTextEdit *textEdit() const { return edit; } - - void rehighlight(); - - int currentParagraph() const; - -private: - TQTextParagraph *para; - TQTextEdit *edit; - TQSyntaxHighlighterPrivate *d; - -}; - -#endif diff --git a/src/widgets/ntqwhatsthis.h b/src/widgets/ntqwhatsthis.h deleted file mode 100644 index 66b4b3c90..000000000 --- a/src/widgets/ntqwhatsthis.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Definition of TQWhatsThis class -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQWHATSTHIS_H -#define TQWHATSTHIS_H - -#ifndef QT_H -#include "tqobject.h" -#endif // QT_H - -#ifndef TQT_NO_WHATSTHIS - -#include "ntqcursor.h" - -class TQToolButton; -class TQPopupMenu; -class TQStyleSheet; - -class TQ_EXPORT TQWhatsThis: public TQt -{ -public: - TQWhatsThis( TQWidget *); - virtual ~TQWhatsThis(); - - virtual TQString text( const TQPoint & ); - virtual bool clicked( const TQString& href ); - - // the common static functions - static void setFont( const TQFont &font ); - - static void add( TQWidget *, const TQString &); - static void remove( TQWidget * ); - static TQString textFor( TQWidget *, const TQPoint & pos = TQPoint(), bool includeParents = FALSE ); - - static TQToolButton * whatsThisButton( TQWidget * parent ); - - static void enterWhatsThisMode(); - static bool inWhatsThisMode(); - static void leaveWhatsThisMode( const TQString& = TQString::null, const TQPoint& pos = TQCursor::pos(), TQWidget* w = 0 ); - - static void display( const TQString& text, const TQPoint& pos = TQCursor::pos(), TQWidget* w = 0 ); -}; - -#endif // TQT_NO_WHATSTHIS - -#endif // TQWHATSTHIS_H diff --git a/src/widgets/qlabel.cpp b/src/widgets/qlabel.cpp deleted file mode 100644 index 7f2c5cbae..000000000 --- a/src/widgets/qlabel.cpp +++ /dev/null @@ -1,1191 +0,0 @@ -/********************************************************************** -** -** Implementation of TQLabel widget class -** -** Created : 941215 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqlabel.h" -#ifndef TQT_NO_LABEL -#include "tqpainter.h" -#include "ntqdrawutil.h" -#include "ntqaccel.h" -#include "tqmovie.h" -#include "tqimage.h" -#include "tqbitmap.h" -#include "tqpicture.h" -#include "ntqapplication.h" -#include "ntqsimplerichtext.h" -#include "tqstylesheet.h" -#include "tqstyle.h" - -class TQLabelPrivate -{ -public: - TQLabelPrivate() - :img(0), pix(0), valid_hints( -1 ) - {} - TQImage* img; // for scaled contents - TQPixmap* pix; // for scaled contents - TQSize sh; - TQSize msh; - int valid_hints; // stores the frameWidth() for the stored size hint, -1 otherwise -}; - - -/*! - \class TQLabel ntqlabel.h - \brief The TQLabel widget provides a text or image display. - - \ingroup basic - \ingroup text - \mainclass - - TQLabel is used for displaying text or an image. 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 TQLabel can contain any of the following content types: - \table - \header \i Content \i Setting - \row \i Plain text - \i Pass a TQString to setText(). - \row \i Rich text - \i Pass a TQString that contains rich text to setText(). - \row \i A pixmap - \i Pass a TQPixmap to setPixmap(). - \row \i A movie - \i Pass a TQMovie to setMovie(). - \row \i A number - \i Pass an \e int or a \e double to setNum(), which converts - the number to plain text. - \row \i Nothing - \i The same as an empty plain text. This is the default. Set - by clear(). - \endtable - - When the content is changed using any of these functions, any - previous content is cleared. - - The look of a TQLabel can be tuned in several ways. All the - settings of TQFrame are available for specifying a widget frame. - The positioning of the content within the TQLabel 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): - \code - TQLabel *label = new TQLabel( this ); - label->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); - label->setText( "first line\nsecond line" ); - label->setAlignment( AlignBottom | AlignRight ); - \endcode - - A TQLabel is often used as a label for an interactive widget. For - this use TQLabel provides a useful mechanism for adding an - accelerator key (see TQAccel) that will set the keyboard focus to - the other widget (called the TQLabel's "buddy"). For example: - \code - TQLineEdit* phoneEdit = new TQLineEdit( this, "phoneEdit" ); - TQLabel* phoneLabel = new TQLabel( phoneEdit, "&Phone:", this, "phoneLabel" ); - \endcode - - In this example, keyboard focus is transferred to the label's - buddy (the TQLineEdit) when the user presses Alt+P. You can - also use the setBuddy() function to accomplish the same thing. - - - - \sa TQLineEdit, TQTextEdit, TQPixmap, TQMovie, - \link guibooks.html#fowler GUI Design Handbook: Label\endlink -*/ - -/*! - \fn TQPicture * TQLabel::picture() const - - Returns the label's picture or 0 if the label doesn't have a - picture. -*/ - - -/*! - Constructs an empty label. - - The \a parent, \a name and widget flag \a f, arguments are passed - to the TQFrame constructor. - - \sa setAlignment(), setFrameStyle(), setIndent() -*/ - -TQLabel::TQLabel( TQWidget *parent, const char *name, WFlags f ) - : TQFrame( parent, name, f | WMouseNoMask ) -{ - init(); -} - - -/*! - Constructs a label that displays the text, \a text. - - The \a parent, \a name and widget flag \a f, arguments are passed - to the TQFrame constructor. - - \sa setText(), setAlignment(), setFrameStyle(), setIndent() -*/ - -TQLabel::TQLabel( const TQString &text, TQWidget *parent, const char *name, - WFlags f ) - : TQFrame( parent, name, f | WMouseNoMask ) -{ - init(); - setText( text ); -} - - -/*! - Constructs a label that displays the text \a text. The label has a - buddy widget, \a buddy. - - If the \a text contains an underlined letter (a letter preceded by - an ampersand, \&), and the text is in plain text format, when the - user presses Alt+ the underlined letter, focus is passed to the - buddy widget. - - The \a parent, \a name and widget flag, \a f, arguments are passed - to the TQFrame constructor. - - \sa setText(), setBuddy(), setAlignment(), setFrameStyle(), - setIndent() -*/ -TQLabel::TQLabel( TQWidget *buddy, const TQString &text, - TQWidget *parent, const char *name, WFlags f ) - : TQFrame( parent, name, f | WMouseNoMask ) -{ - init(); -#ifndef TQT_NO_ACCEL - setBuddy( buddy ); -#endif - setText( text ); -} - -/*! - Destroys the label. -*/ - -TQLabel::~TQLabel() -{ - clearContents(); - delete d; -} - - -void TQLabel::init() -{ - lpixmap = 0; -#ifndef TQT_NO_MOVIE - lmovie = 0; -#endif -#ifndef TQT_NO_ACCEL - lbuddy = 0; - accel = 0; -#endif - lpixmap = 0; -#ifndef TQT_NO_PICTURE - lpicture = 0; -#endif - align = AlignAuto | AlignVCenter | ExpandTabs; - extraMargin = -1; - autoresize = FALSE; - scaledcontents = FALSE; - textformat = TQt::AutoText; -#ifndef TQT_NO_RICHTEXT - doc = 0; -#endif - - setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred ) ); - d = new TQLabelPrivate; -} - - -/*! - \property TQLabel::text - \brief the label's text - - If no text has been set this will return an empty string. Setting - the text clears any previous content, unless they are the same. - - The 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 \c AutoText, i.e. TQLabel will try to - auto-detect the format of the text set. - - If the 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, i.e. those small documents that get their document - specific settings (font, text color, link color) from the label's - palette and font properties. For large documents, use TQTextEdit - in read-only mode instead. TQTextEdit will flicker less on resize - and can also provide a scrollbar when necessary. - - \sa text, setTextFormat(), setBuddy(), alignment -*/ - -void TQLabel::setText( const TQString &text ) -{ - if ( ltext == text ) - return; - TQSize osh = sizeHint(); -#ifndef TQT_NO_RICHTEXT - bool hadRichtext = doc != 0; -#endif - clearContents(); - ltext = text; -#ifndef TQT_NO_RICHTEXT - bool useRichText = (textformat == RichText || - ( ( textformat == AutoText ) && TQStyleSheet::mightBeRichText(ltext) ) ); -#else - bool useRichText = TRUE; -#endif -#ifndef TQT_NO_ACCEL - // ### Setting accelerators for rich text labels will not work. - // Eg. >Hello will return ALT+G which is clearly - // not intended. - if ( !useRichText ) { - int p = TQAccel::shortcutKey( ltext ); - if ( p ) { - if ( !accel ) - accel = new TQAccel( this, "accel label accel" ); - accel->connectItem( accel->insertItem( p ), - this, TQ_SLOT(acceleratorSlot()) ); - } - } -#endif -#ifndef TQT_NO_RICHTEXT - if ( useRichText ) { - if ( !hadRichtext ) - align |= WordBreak; - TQString t = ltext; - if ( align & AlignRight ) - t.prepend( "
"); - else if ( align & AlignHCenter ) - t.prepend( "
"); - if ( (align & WordBreak) == 0 ) - t.prepend( "" ); - doc = new TQSimpleRichText( t, font() ); - } -#endif - - updateLabel( osh ); -} - - -/*! - Clears any label contents. Equivalent to setText( "" ). -*/ - -void TQLabel::clear() -{ - setText( TQString::fromLatin1("") ); -} - -/*! - \property TQLabel::pixmap - \brief the label's pixmap - - If no pixmap has been set this will return an invalid pixmap. - - Setting the pixmap clears any previous content, and resizes the - label if \l TQLabel::autoResize() is TRUE. The buddy accelerator, - if any, is disabled. -*/ -void TQLabel::setPixmap( const TQPixmap &pixmap ) -{ - TQSize osh = sizeHint(); - - if ( !lpixmap || lpixmap->serialNumber() != pixmap.serialNumber() ) { - clearContents(); - lpixmap = new TQPixmap( pixmap ); - } - - if ( lpixmap->depth() == 1 && !lpixmap->mask() ) - lpixmap->setMask( *((TQBitmap *)lpixmap) ); - - updateLabel( osh ); -} - -#ifndef TQT_NO_PICTURE -/*! - Sets the label contents to \a picture. Any previous content is - cleared. - - The buddy accelerator, if any, is disabled. - - \sa picture(), setBuddy() -*/ - -void TQLabel::setPicture( const TQPicture &picture ) -{ - TQSize osh = sizeHint(); - clearContents(); - lpicture = new TQPicture( picture ); - - updateLabel( osh ); -} -#endif // TQT_NO_PICTURE - -/*! - Sets the label contents to plain text containing the textual - representation of integer \a num. Any previous content is cleared. - Does nothing if the integer's string representation is the same as - the current contents of the label. - - The buddy accelerator, if any, is disabled. - - The label resizes itself if auto-resizing is enabled. - - \sa setText(), TQString::setNum(), setBuddy() -*/ - -void TQLabel::setNum( int num ) -{ - TQString str; - str.setNum( num ); - setText( str ); -} - -/*! - \overload - - Sets the label contents to plain text containing the textual - representation of double \a num. Any previous content is cleared. - Does nothing if the double's string representation is the same as - the current contents of the label. - - The buddy accelerator, if any, is disabled. - - The label resizes itself if auto-resizing is enabled. - - \sa setText(), TQString::setNum(), setBuddy() -*/ - -void TQLabel::setNum( double num ) -{ - TQString str; - str.setNum( num ); - setText( str ); -} - -/*! - \property TQLabel::alignment - \brief the alignment of the label's contents - - The alignment is a bitwise OR of \c TQt::AlignmentFlags and \c - TQt::TextFlags values. The \c ExpandTabs, \c SingleLine and \c - ShowPrefix flags apply only if the label contains plain text; - otherwise they are ignored. The \c DontClip flag is always - ignored. \c WordBreak applies to both rich text and plain text - labels. The \c BreakAnywhere flag is not supported in TQLabel. - - If the label has a buddy, the \c ShowPrefix flag is forced to - TRUE. - - The default alignment is \c{AlignAuto | AlignVCenter | ExpandTabs} - if the label doesn't have a buddy and \c{AlignAuto | AlignVCenter - | ExpandTabs | ShowPrefix} if the label has a buddy. If the label - contains rich text, additionally \c WordBreak is turned on. - - \sa TQt::AlignmentFlags, alignment, setBuddy(), text -*/ - -void TQLabel::setAlignment( int alignment ) -{ - if ( alignment == align ) - return; - TQSize osh = sizeHint(); -#ifndef TQT_NO_ACCEL - if ( lbuddy ) - align = alignment | ShowPrefix; - else -#endif - align = alignment; - -#ifndef TQT_NO_RICHTEXT - TQString t = ltext; - if ( !t.isNull() ) { - ltext = TQString::null; - setText( t ); - } -#endif - - updateLabel( osh ); -} - - -/*! - \property TQLabel::indent - \brief the label's text indent in pixels - - If a label displays text, the indent applies to the left edge if - alignment() is \c AlignLeft, to the right edge if alignment() is - \c AlignRight, to the top edge if alignment() is \c AlignTop, and - to to the bottom edge if alignment() is \c 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(). - - \sa alignment, frameWidth(), font() -*/ - -void TQLabel::setIndent( int indent ) -{ - extraMargin = indent; - updateLabel( TQSize( -1, -1 ) ); -} - - -/*! - \fn bool TQLabel::autoResize() const - - \obsolete - - Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing - is disabled. - - Auto-resizing is disabled by default. - - \sa setAutoResize() -*/ - -/*! \obsolete - Enables auto-resizing if \a enable is TRUE, or disables it if \a - 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 TQLabel widgets that are not managed by - a TQLayout (e.g., top-level widgets). - - Auto-resizing is disabled by default. - - \sa autoResize(), adjustSize(), sizeHint() -*/ - -void TQLabel::setAutoResize( bool enable ) -{ - if ( (bool)autoresize != enable ) { - autoresize = enable; - if ( autoresize ) - adjustSize(); // calls resize which repaints - } -} - - - -/*! - Returns the size that will be used if the width of the label is \a - w. If \a w is -1, the sizeHint() is returned. -*/ - -TQSize TQLabel::sizeForWidth( int w ) const -{ - TQRect br; - TQPixmap *pix = pixmap(); -#ifndef TQT_NO_PICTURE - TQPicture *pic = picture(); -#else - const int pic = 0; -#endif -#ifndef TQT_NO_MOVIE - TQMovie *mov = movie(); -#else - const int mov = 0; -#endif - int hextra = 2 * frameWidth(); - int vextra = hextra; - TQFontMetrics fm( fontMetrics() ); - int xw = fm.width( 'x' ); - if ( !mov && !pix && !pic ) { - int m = indent(); - if ( m < 0 && hextra ) // no indent, but we do have a frame - m = xw / 2 - margin(); - if ( m >= 0 ) { - int horizAlign = TQApplication::horizontalAlignment( align ); - if ( (horizAlign & AlignLeft) || (horizAlign & AlignRight ) ) - hextra += m; - if ( (align & AlignTop) || (align & AlignBottom ) ) - vextra += m; - } - } - - if ( pix ) - br = pix->rect(); -#ifndef TQT_NO_PICTURE - else if ( pic ) - br = pic->boundingRect(); -#endif -#ifndef TQT_NO_MOVIE - else if ( mov ) - br = mov->framePixmap().rect(); -#endif -#ifndef TQT_NO_RICHTEXT - else if ( doc ) { - int oldW = doc->width(); - if ( align & WordBreak ) { - if ( w < 0 ) - doc->adjustSize(); - else - doc->setWidth( w-hextra ); - } - br = TQRect( 0, 0, doc->widthUsed(), doc->height() ); - doc->setWidth( oldW ); - } -#endif - else { - bool tryWidth = (w < 0) && (align & WordBreak); - if ( tryWidth ) - w = xw * 80; - else if ( w < 0 ) - w = 2000; - w -= hextra; - br = fm.boundingRect( 0, 0, w ,2000, alignment(), text() ); - if ( tryWidth && br.height() < 4*fm.lineSpacing() && br.width() > w/2 ) - br = fm.boundingRect( 0, 0, w/2, 2000, alignment(), text() ); - if ( tryWidth && br.height() < 2*fm.lineSpacing() && br.width() > w/4 ) - br = fm.boundingRect( 0, 0, w/4, 2000, alignment(), text() ); - } - int wid = br.width() + hextra; - int hei = br.height() + vextra; - - return TQSize( wid, hei ); -} - - -/*! - \reimp -*/ - -int TQLabel::heightForWidth( int w ) const -{ - if ( -#ifndef TQT_NO_RICHTEXT - doc || -#endif - (align & WordBreak) ) - return sizeForWidth( w ).height(); - return TQWidget::heightForWidth( w ); -} - - - -/*!\reimp -*/ -TQSize TQLabel::sizeHint() const -{ - if ( d->valid_hints != frameWidth() ) - (void) TQLabel::minimumSizeHint(); - return d->sh; -} - -/*! - \reimp -*/ - -TQSize TQLabel::minimumSizeHint() const -{ - if ( d->valid_hints == frameWidth() ) - return d->msh; - - constPolish(); - d->valid_hints = frameWidth(); - d->sh = sizeForWidth( -1 ); - TQSize sz( -1, -1 ); - - if ( -#ifndef TQT_NO_RICHTEXT - !doc && -#endif - (align & WordBreak) == 0 ) { - sz = d->sh; - } else { - // think about caching these for performance - sz.rwidth() = sizeForWidth( 0 ).width(); - sz.rheight() = sizeForWidth(TQWIDGETSIZE_MAX).height(); - if ( d->sh.height() < sz.height() ) - sz.rheight() = d->sh.height(); - } - if ( sizePolicy().horData() == TQSizePolicy::Ignored ) - sz.rwidth() = -1; - if ( sizePolicy().verData() == TQSizePolicy::Ignored ) - sz.rheight() = -1; - d->msh = sz; - return sz; -} - -/*! - \reimp -*/ -void TQLabel::resizeEvent( TQResizeEvent* e ) -{ - TQFrame::resizeEvent( e ); - -#ifdef TQT_NO_RICHTEXT - static const bool doc = FALSE; -#endif - - // optimize for standard labels - if ( frameShape() == NoFrame && (align & WordBreak) == 0 && !doc && - ( e->oldSize().width() >= e->size().width() && (align & AlignLeft ) == AlignLeft ) - && ( e->oldSize().height() >= e->size().height() && (align & AlignTop ) == AlignTop ) ) { - setWFlags( WResizeNoErase ); - return; - } - - clearWFlags( WResizeNoErase ); - TQRect cr = contentsRect(); - if ( !lpixmap || !cr.isValid() || - // masked pixmaps can only reduce flicker when being top/left - // aligned and when we do not perform scaled contents - ( lpixmap->hasAlpha() && ( scaledcontents || ( ( align & (AlignLeft|AlignTop) ) != (AlignLeft|AlignTop) ) ) ) ) - return; - - setWFlags( WResizeNoErase ); - - if ( !scaledcontents ) { - // don't we all love TQFrame? Reduce pixmap flicker - TQRegion reg = TQRect( TQPoint(0, 0), e->size() ); - reg = reg.subtract( cr ); - int x = cr.x(); - int y = cr.y(); - int w = lpixmap->width(); - int h = lpixmap->height(); - if ( (align & TQt::AlignVCenter) == TQt::AlignVCenter ) - y += cr.height()/2 - h/2; - else if ( (align & TQt::AlignBottom) == TQt::AlignBottom) - y += cr.height() - h; - if ( (align & TQt::AlignRight) == TQt::AlignRight ) - x += cr.width() - w; - else if ( (align & TQt::AlignHCenter) == TQt::AlignHCenter ) - x += cr.width()/2 - w/2; - if ( x > cr.x() ) - reg = reg.unite( TQRect( cr.x(), cr.y(), x - cr.x(), cr.height() ) ); - if ( y > cr.y() ) - reg = reg.unite( TQRect( cr.x(), cr.y(), cr.width(), y - cr.y() ) ); - - if ( x + w < cr.right() ) - reg = reg.unite( TQRect( x + w, cr.y(), cr.right() - x - w, cr.height() ) ); - if ( y + h < cr.bottom() ) - reg = reg.unite( TQRect( cr.x(), y + h, cr.width(), cr.bottom() - y - h ) ); - - erase( reg ); - } -} - - -/*! - Draws the label contents using the painter \a p. -*/ - -void TQLabel::drawContents( TQPainter *p ) -{ - TQRect cr = contentsRect(); - - TQPixmap *pix = pixmap(); -#ifndef TQT_NO_PICTURE - TQPicture *pic = picture(); -#else - const int pic = 0; -#endif -#ifndef TQT_NO_MOVIE - TQMovie *mov = movie(); -#else - const int mov = 0; -#endif - - if ( !mov && !pix && !pic ) { - int m = indent(); - if ( m < 0 && frameWidth() ) // no indent, but we do have a frame - m = fontMetrics().width('x') / 2 - margin(); - if ( m > 0 ) { - int hAlign = TQApplication::horizontalAlignment( align ); - if ( hAlign & AlignLeft ) - cr.setLeft( cr.left() + m ); - if ( hAlign & AlignRight ) - cr.setRight( cr.right() - m ); - if ( align & AlignTop ) - cr.setTop( cr.top() + m ); - if ( align & AlignBottom ) - cr.setBottom( cr.bottom() - m ); - } - } - -#ifndef TQT_NO_MOVIE - if ( mov ) { - // ### should add movie to qDrawItem - TQRect r = style().itemRect( p, cr, align, isEnabled(), &(mov->framePixmap()), - TQString::null ); - // ### could resize movie frame at this point - p->drawPixmap(r.x(), r.y(), mov->framePixmap() ); - } - else -#endif -#ifndef TQT_NO_RICHTEXT - if ( doc ) { - doc->setWidth(p, cr.width() ); - int rh = doc->height(); - int yo = 0; - if ( align & AlignVCenter ) - yo = (cr.height()-rh)/2; - else if ( align & AlignBottom ) - yo = cr.height()-rh; - if (! isEnabled() && - style().styleHint(TQStyle::SH_EtchDisabledText, this)) { - TQColorGroup cg = colorGroup(); - cg.setColor( TQColorGroup::Text, cg.light() ); - doc->draw(p, cr.x()+1, cr.y()+yo+1, cr, cg, 0); - } - - // TQSimpleRichText always draws with TQColorGroup::Text as with - // background mode PaletteBase. TQLabel typically has - // background mode PaletteBackground, so we create a temporary - // color group with the text color adjusted. - TQColorGroup cg = colorGroup(); - if ( backgroundMode() != PaletteBase && isEnabled() ) - cg.setColor( TQColorGroup::Text, paletteForegroundColor() ); - - doc->draw(p, cr.x(), cr.y()+yo, cr, cg, 0); - } else -#endif -#ifndef TQT_NO_PICTURE - if ( pic ) { - TQRect br = pic->boundingRect(); - int rw = br.width(); - int rh = br.height(); - if ( scaledcontents ) { - p->save(); - p->translate( cr.x(), cr.y() ); -#ifndef TQT_NO_TRANSFORMATIONS - p->scale( (double)cr.width()/rw, (double)cr.height()/rh ); -#endif - p->drawPicture( -br.x(), -br.y(), *pic ); - p->restore(); - } else { - int xo = 0; - int yo = 0; - if ( align & AlignVCenter ) - yo = (cr.height()-rh)/2; - else if ( align & AlignBottom ) - yo = cr.height()-rh; - if ( align & AlignRight ) - xo = cr.width()-rw; - else if ( align & AlignHCenter ) - xo = (cr.width()-rw)/2; - p->drawPicture( cr.x()+xo-br.x(), cr.y()+yo-br.y(), *pic ); - } - } else -#endif - { -#ifndef TQT_NO_IMAGE_SMOOTHSCALE - if ( scaledcontents && pix ) { - if ( !d->img ) - d->img = new TQImage( lpixmap->convertToImage() ); - - if ( !d->pix ) - d->pix = new TQPixmap; - if ( d->pix->size() != cr.size() ) - d->pix->convertFromImage( d->img->smoothScale( cr.width(), cr.height() ) ); - pix = d->pix; - } -#endif - int alignment = align; - if ((align & ShowPrefix) && ((!style().styleHint(TQStyle::SH_UnderlineAccelerator, this)) || ((style().styleHint(TQStyle::SH_HideUnderlineAcceleratorWhenAltUp, this)) && (!style().acceleratorsShown())))) { - alignment |= NoAccel; - } - // ordinary text or pixmap label - style().drawItem( p, cr, alignment, colorGroup(), isEnabled(), - pix, ltext ); - } -} - - -/*! - Updates the label, but not the frame. -*/ - -void TQLabel::updateLabel( TQSize oldSizeHint ) -{ - d->valid_hints = -1; - TQSizePolicy policy = sizePolicy(); - bool wordBreak = align & WordBreak; - policy.setHeightForWidth( wordBreak ); - if ( policy != sizePolicy() ) - setSizePolicy( policy ); - if ( sizeHint() != oldSizeHint ) - updateGeometry(); - if ( autoresize ) { - adjustSize(); - update( contentsRect() ); - } else { - update( contentsRect() ); - } -} - - -/*! - \internal - - Internal slot, used to set focus for accelerator labels. -*/ -#ifndef TQT_NO_ACCEL -void TQLabel::acceleratorSlot() -{ - if ( !lbuddy ) - return; - TQWidget * w = lbuddy; - while ( w->focusProxy() ) - w = w->focusProxy(); - if ( !w->hasFocus() && - w->isEnabled() && - w->isVisible() && - w->focusPolicy() != NoFocus ) { - TQFocusEvent::setReason( TQFocusEvent::Shortcut ); - w->setFocus(); - TQFocusEvent::resetReason(); - } -} -#endif - -/*! - \internal - - Internal slot, used to clean up if the buddy widget dies. -*/ -#ifndef TQT_NO_ACCEL -void TQLabel::buddyDied() // I can't remember if I cried. -{ - lbuddy = 0; -} - -/*! - Sets this label's buddy to \a 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 TQLabels that contain - plain text in which one letter is prefixed with an ampersand, \&. - This letter is set as the accelerator key. The letter is displayed - underlined, and the '\&' is not displayed (i.e. the \c 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"), for example: - \code - TQLineEdit *nameEd = new TQLineEdit( this ); - TQLabel *nameLb = new TQLabel( "&Name:", this ); - nameLb->setBuddy( nameEd ); - TQLineEdit *phoneEd = new TQLineEdit( this ); - TQLabel *phoneLb = new TQLabel( "&Phone:", this ); - phoneLb->setBuddy( phoneEd ); - // ( layout setup not shown ) - \endcode - - 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 \a buddy - set to 0. - - \sa buddy(), setText(), TQAccel, setAlignment() -*/ - -void TQLabel::setBuddy( TQWidget *buddy ) -{ - if ( buddy ) - setAlignment( alignment() | ShowPrefix ); - else - setAlignment( alignment() & ~ShowPrefix ); - - if ( lbuddy ) - disconnect( lbuddy, TQ_SIGNAL(destroyed()), this, TQ_SLOT(buddyDied()) ); - - lbuddy = buddy; - - if ( !lbuddy ) - return; -#ifndef TQT_NO_RICHTEXT - if ( !( textformat == RichText || (textformat == AutoText && - TQStyleSheet::mightBeRichText(ltext) ) ) ) -#endif - { - int p = TQAccel::shortcutKey( ltext ); - if ( p ) { - if ( !accel ) - accel = new TQAccel( this, "accel label accel" ); - accel->connectItem( accel->insertItem( p ), - this, TQ_SLOT(acceleratorSlot()) ); - } - } - - connect( lbuddy, TQ_SIGNAL(destroyed()), this, TQ_SLOT(buddyDied()) ); -} - - -/*! - Returns this label's buddy, or 0 if no buddy is currently set. - - \sa setBuddy() -*/ - -TQWidget * TQLabel::buddy() const -{ - return lbuddy; -} -#endif //TQT_NO_ACCEL - - -#ifndef TQT_NO_MOVIE -void TQLabel::movieUpdated(const TQRect& rect) -{ - TQMovie *mov = movie(); - if ( mov && !mov->isNull() ) { - TQRect r = contentsRect(); - r = style().itemRect( 0, r, align, isEnabled(), &(mov->framePixmap()), - TQString::null ); - r.moveBy(rect.x(), rect.y()); - r.setWidth(TQMIN(r.width(), rect.width())); - r.setHeight(TQMIN(r.height(), rect.height())); - repaint( r, mov->framePixmap().mask() != 0 ); - } -} - -void TQLabel::movieResized( const TQSize& size ) -{ - d->valid_hints = -1; - if ( autoresize ) - adjustSize(); - movieUpdated( TQRect( TQPoint(0,0), size ) ); - updateGeometry(); -} - -/*! - Sets the label contents to \a movie. Any previous content is - cleared. - - The buddy accelerator, if any, is disabled. - - The label resizes itself if auto-resizing is enabled. - - \sa movie(), setBuddy() -*/ - -void TQLabel::setMovie( const TQMovie& movie ) -{ - TQSize osh = sizeHint(); - clearContents(); - - lmovie = new TQMovie( movie ); - lmovie->connectResize(this, TQ_SLOT(movieResized(const TQSize&))); - lmovie->connectUpdate(this, TQ_SLOT(movieUpdated(const TQRect&))); - - if ( !lmovie->running() ) // Assume that if the movie is running, - updateLabel( osh ); // resize/update signals will come soon enough -} - -#endif // TQT_NO_MOVIE - -/*! - \internal - - Clears any contents, without updating/repainting the label. -*/ - -void TQLabel::clearContents() -{ -#ifndef TQT_NO_RICHTEXT - delete doc; - doc = 0; -#endif - - delete lpixmap; - lpixmap = 0; -#ifndef TQT_NO_PICTURE - delete lpicture; - lpicture = 0; -#endif - delete d->img; - d->img = 0; - delete d->pix; - d->pix = 0; - - ltext = TQString::null; -#ifndef TQT_NO_ACCEL - if ( accel ) - accel->clear(); -#endif -#ifndef TQT_NO_MOVIE - if ( lmovie ) { - lmovie->disconnectResize(this, TQ_SLOT(movieResized(const TQSize&))); - lmovie->disconnectUpdate(this, TQ_SLOT(movieUpdated(const TQRect&))); - delete lmovie; - lmovie = 0; - } -#endif -} - - -#ifndef TQT_NO_MOVIE - -/*! - Returns a pointer to the label's movie, or 0 if no movie has been - set. - - \sa setMovie() -*/ - -TQMovie* TQLabel::movie() const -{ - return lmovie; -} - -#endif // TQT_NO_MOVIE - -/*! - \property TQLabel::backgroundMode - \brief the label's background mode - - Get this property with backgroundMode(). - - \sa TQWidget::setBackgroundMode() -*/ - -/*! - \property TQLabel::textFormat - \brief the label's text format - - See the \c TQt::TextFormat enum for an explanation of the possible - options. - - The default format is \c AutoText. - - \sa text -*/ - -TQt::TextFormat TQLabel::textFormat() const -{ - return textformat; -} - -void TQLabel::setTextFormat( TQt::TextFormat format ) -{ - if ( format != textformat ) { - textformat = format; - TQString t = ltext; - if ( !t.isNull() ) { - ltext = TQString::null; - setText( t ); - } - } -} - -/*! - \reimp -*/ - -void TQLabel::fontChange( const TQFont & ) -{ - if ( !ltext.isEmpty() ) { -#ifndef TQT_NO_RICHTEXT - if ( doc ) - doc->setDefaultFont( font() ); -#endif - updateLabel( TQSize( -1, -1 ) ); - } -} - -#ifndef TQT_NO_IMAGE_SMOOTHSCALE -/*! - \property TQLabel::scaledContents - \brief whether the label will scale its contents to fill all - available space. - - When enabled and the label shows a pixmap, it will scale the - pixmap to fill the available space. - - This property's default is FALSE. - - \sa setScaledContents() -*/ -bool TQLabel::hasScaledContents() const -{ - return scaledcontents; -} - -void TQLabel::setScaledContents( bool enable ) -{ - if ( (bool)scaledcontents == enable ) - return; - scaledcontents = enable; - if ( !enable ) { - delete d->img; - d->img = 0; - delete d->pix; - d->pix = 0; - } - update( contentsRect() ); -} - -#endif // TQT_NO_IMAGE_SMOOTHSCALE - -/*! - Sets the font used on the TQLabel to font \a f. -*/ - -void TQLabel::setFont( const TQFont &f ) -{ - TQFrame::setFont( f ); -} - -#endif // TQT_NO_LABEL diff --git a/src/widgets/qlineedit.cpp b/src/widgets/qlineedit.cpp index 75570cc09..d37c43539 100644 --- a/src/widgets/qlineedit.cpp +++ b/src/widgets/qlineedit.cpp @@ -59,7 +59,7 @@ #include "tqstringlist.h" #include "ntqguardedptr.h" #include "tqstyle.h" -#include "ntqwhatsthis.h" +#include "tqwhatsthis.h" #include "../kernel/qinternal_p.h" #include "private/tqtextlayout_p.h" #include "tqvaluevector.h" diff --git a/src/widgets/qsyntaxhighlighter.cpp b/src/widgets/qsyntaxhighlighter.cpp deleted file mode 100644 index d9fececf1..000000000 --- a/src/widgets/qsyntaxhighlighter.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/**************************************************************************** -** -** Implementation of the TQSyntaxHighlighter class -** -** Created : 990101 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqsyntaxhighlighter.h" -#include "private/qsyntaxhighlighter_p.h" - -#ifndef TQT_NO_SYNTAXHIGHLIGHTER -#include "../kernel/qrichtext_p.h" -#include "tqtextedit.h" -#include "tqtimer.h" - -/*! - \class TQSyntaxHighlighter ntqsyntaxhighlighter.h - \brief The TQSyntaxHighlighter class is a base class for - implementing TQTextEdit syntax highlighters. - - \ingroup basic - \ingroup text - - A syntax highligher automatically highlights parts of the text in - a TQTextEdit. Syntax highlighters are often used when the user is - entering text in a specific format (for example, source code) and - help the user to read the text and identify syntax errors. - - To provide your own syntax highlighting for TQTextEdit, you must - subclass TQSyntaxHighlighter and reimplement highlightParagraph(). - - When you create an instance of your TQSyntaxHighlighter subclass, - pass it the TQTextEdit that you want the syntax highlighting to be - applied to. After this your highlightParagraph() function will be - called automatically whenever necessary. Use your - highlightParagraph() function to apply formatting (e.g. setting - the font and color) to the text that is passed to it. -*/ - -/*! - Constructs the TQSyntaxHighlighter and installs it on \a textEdit. - - It is the caller's responsibility to delete the - TQSyntaxHighlighter when it is no longer needed. -*/ - -TQSyntaxHighlighter::TQSyntaxHighlighter( TQTextEdit *textEdit ) - : para( 0 ), edit( textEdit ), d( new TQSyntaxHighlighterPrivate ) -{ - textEdit->document()->setPreProcessor( new TQSyntaxHighlighterInternal( this ) ); - textEdit->document()->invalidate(); - TQTimer::singleShot( 0, textEdit->viewport(), TQ_SLOT( update() ) ); -} - -/*! - Destructor. Uninstalls this syntax highlighter from the textEdit() -*/ - -TQSyntaxHighlighter::~TQSyntaxHighlighter() -{ - delete d; - textEdit()->document()->setPreProcessor( 0 ); -} - -/*! - \fn int TQSyntaxHighlighter::highlightParagraph( const TQString &text, int endStateOfLastPara ) - - This function is called when necessary by the rich text engine, - i.e. on paragraphs which have changed. - - In your reimplementation you should parse the paragraph's \a text - and call setFormat() as often as necessary to apply any font and - color changes that you require. Your function must return a value - which indicates the paragraph's end state: see below. - - Some syntaxes can have constructs that span paragraphs. For - example, a C++ syntax highlighter should be able to cope with - \c{/}\c{*...*}\c{/} comments that span paragraphs. To deal - with these cases it is necessary to know the end state of the - previous paragraph (e.g. "in comment"). - - If your syntax does not have paragraph spanning constructs, simply - ignore the \a endStateOfLastPara parameter and always return 0. - - Whenever highlightParagraph() is called it is passed a value for - \a endStateOfLastPara. For the very first paragraph this value is - always -2. For any other paragraph the value is the value returned - by the most recent highlightParagraph() call that applied to the - preceding paragraph. - - The value you return is up to you. We recommend only returning 0 - (to signify that this paragraph's syntax highlighting does not - affect the following paragraph), or a positive integer (to signify - that this paragraph has ended in the middle of a paragraph - spanning construct). - - To find out which paragraph is highlighted, call - currentParagraph(). - - For example, if you're writing a simple C++ syntax highlighter, - you might designate 1 to signify "in comment". For a paragraph - that ended in the middle of a comment you'd return 1, and for - other paragraphs you'd return 0. In your parsing code if \a - endStateOfLastPara was 1, you would highlight the text as a C++ - comment until you reached the closing \c{*}\c{/}. -*/ - -/*! - This function is applied to the syntax highlighter's current - paragraph (the text of which is passed to the highlightParagraph() - function). - - The specified \a font and \a color are applied to the text from - position \a start for \a count characters. (If \a count is 0, - nothing is done.) -*/ - -void TQSyntaxHighlighter::setFormat( int start, int count, const TQFont &font, const TQColor &color ) -{ - if ( !para || count <= 0 ) - return; - TQTextFormat *f = 0; - f = para->document()->formatCollection()->format( font, color ); - para->setFormat( start, count, f ); - f->removeRef(); -} - -/*! \overload */ - -void TQSyntaxHighlighter::setFormat( int start, int count, const TQColor &color ) -{ - if ( !para || count <= 0 ) - return; - TQTextFormat *f = 0; - TQFont fnt = textEdit()->TQWidget::font(); - f = para->document()->formatCollection()->format( fnt, color ); - para->setFormat( start, count, f ); - f->removeRef(); -} - -/*! \overload */ - -void TQSyntaxHighlighter::setFormat( int start, int count, const TQFont &font ) -{ - if ( !para || count <= 0 ) - return; - TQTextFormat *f = 0; - TQColor c = textEdit()->viewport()->paletteForegroundColor(); - f = para->document()->formatCollection()->format( font, c ); - para->setFormat( start, count, f ); - f->removeRef(); -} - -/*! - \fn TQTextEdit *TQSyntaxHighlighter::textEdit() const - - Returns the TQTextEdit on which this syntax highlighter is - installed -*/ - -/*! Redoes the highlighting of the whole document. -*/ - -void TQSyntaxHighlighter::rehighlight() -{ - TQTextParagraph *s = edit->document()->firstParagraph(); - while ( s ) { - s->invalidate( 0 ); - s->state = -1; - s->needPreProcess = TRUE; - s = s->next(); - } - edit->repaintContents( FALSE ); -} - -/*! - Returns the id of the paragraph which is highlighted, or -1 of no - paragraph is currently highlighted. - - Usually this function is called from within highlightParagraph(). -*/ - -int TQSyntaxHighlighter::currentParagraph() const -{ - return d->currentParagraph; -} - -#endif diff --git a/src/widgets/qsyntaxhighlighter_p.h b/src/widgets/qsyntaxhighlighter_p.h deleted file mode 100644 index 156cc9321..000000000 --- a/src/widgets/qsyntaxhighlighter_p.h +++ /dev/null @@ -1,97 +0,0 @@ -/**************************************************************************** -** -** Definition of the internal TQSyntaxHighlighterInternal class -** -** Created : 031111 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQSYNTAXHIGHLIGHTER_P_H -#define TQSYNTAXHIGHLIGHTER_P_H - -#ifndef TQT_NO_SYNTAXHIGHLIGHTER -#include "ntqsyntaxhighlighter.h" -#include "private/qrichtext_p.h" - -class TQSyntaxHighlighterPrivate -{ -public: - TQSyntaxHighlighterPrivate() : - currentParagraph( -1 ) - {} - - int currentParagraph; -}; - -class TQSyntaxHighlighterInternal : public TQTextPreProcessor -{ -public: - TQSyntaxHighlighterInternal( TQSyntaxHighlighter *h ) : highlighter( h ) {} - void process( TQTextDocument *doc, TQTextParagraph *p, int, bool invalidate ) { - if ( p->prev() && p->prev()->endState() == -1 ) - process( doc, p->prev(), 0, FALSE ); - - highlighter->para = p; - TQString text = p->string()->toString(); - int endState = p->prev() ? p->prev()->endState() : -2; - int oldEndState = p->endState(); - highlighter->d->currentParagraph = p->paragId(); - p->setEndState( highlighter->highlightParagraph( text, endState ) ); - highlighter->d->currentParagraph = -1; - highlighter->para = 0; - - p->setFirstPreProcess( FALSE ); - TQTextParagraph *op = p; - p = p->next(); - if ( (!!oldEndState || !!op->endState()) && oldEndState != op->endState() && - invalidate && p && !p->firstPreProcess() && p->endState() != -1 ) { - while ( p ) { - if ( p->endState() == -1 ) - return; - p->setEndState( -1 ); - p = p->next(); - } - } - } - TQTextFormat *format( int ) { return 0; } - -private: - TQSyntaxHighlighter *highlighter; - - friend class TQTextEdit; -}; - -#endif // TQT_NO_SYNTAXHIGHLIGHTER -#endif // TQSYNTAXHIGHLIGHTER_P_H diff --git a/src/widgets/qt_widgets.pri b/src/widgets/qt_widgets.pri index 38ef25ca9..876cc428c 100644 --- a/src/widgets/qt_widgets.pri +++ b/src/widgets/qt_widgets.pri @@ -21,7 +21,7 @@ widgets { $$WIDGETS_H/ntqhgroupbox.h \ $$WIDGETS_H/ntqhbox.h \ $$WIDGETS_H/tqiconview.h \ - $$WIDGETS_H/ntqlabel.h \ + $$WIDGETS_H/tqlabel.h \ $$WIDGETS_H/ntqlcdnumber.h \ $$WIDGETS_H/ntqlineedit.h \ $$WIDGETS_H/ntqlistbox.h \ @@ -43,8 +43,8 @@ widgets { $$WIDGETS_H/ntqsplitter.h \ $$WIDGETS_H/tqstatusbar.h \ $$WIDGETS_H/ntqtabbar.h \ - $$WIDGETS_H/ntqsyntaxhighlighter.h \ - $$WIDGETS_P/qsyntaxhighlighter_p.h \ + $$WIDGETS_H/tqsyntaxhighlighter.h \ + $$WIDGETS_P/tqsyntaxhighlighter_p.h \ $$WIDGETS_H/ntqtabwidget.h \ $$WIDGETS_P/qtitlebar_p.h \ $$WIDGETS_H/tqtoolbar.h \ @@ -55,7 +55,7 @@ widgets { $$WIDGETS_H/ntqvbox.h \ $$WIDGETS_H/ntqvbuttongroup.h \ $$WIDGETS_H/ntqvgroupbox.h \ - $$WIDGETS_H/ntqwhatsthis.h \ + $$WIDGETS_H/tqwhatsthis.h \ $$WIDGETS_H/tqwidgetstack.h \ $$WIDGETS_H/tqaction.h \ $$WIDGETS_H/tqdatetimeedit.h \ @@ -83,7 +83,7 @@ widgets { $$WIDGETS_CPP/qhgroupbox.cpp \ $$WIDGETS_CPP/qhbox.cpp \ $$WIDGETS_CPP/tqiconview.cpp \ - $$WIDGETS_CPP/qlabel.cpp \ + $$WIDGETS_CPP/tqlabel.cpp \ $$WIDGETS_CPP/qlcdnumber.cpp \ $$WIDGETS_CPP/qlineedit.cpp \ $$WIDGETS_CPP/qlistbox.cpp \ @@ -105,7 +105,7 @@ widgets { $$WIDGETS_CPP/qspinwidget.cpp \ $$WIDGETS_CPP/qsplitter.cpp \ $$WIDGETS_CPP/tqstatusbar.cpp \ - $$WIDGETS_CPP/qsyntaxhighlighter.cpp \ + $$WIDGETS_CPP/tqsyntaxhighlighter.cpp \ $$WIDGETS_CPP/qtabbar.cpp \ $$WIDGETS_CPP/qtabwidget.cpp \ $$WIDGETS_CPP/qtitlebar.cpp \ @@ -117,7 +117,7 @@ widgets { $$WIDGETS_CPP/qvbox.cpp \ $$WIDGETS_CPP/qvbuttongroup.cpp \ $$WIDGETS_CPP/qvgroupbox.cpp \ - $$WIDGETS_CPP/qwhatsthis.cpp \ + $$WIDGETS_CPP/tqwhatsthis.cpp \ $$WIDGETS_CPP/tqwidgetstack.cpp \ $$WIDGETS_CPP/tqaction.cpp \ $$WIDGETS_CPP/tqdatetimeedit.cpp \ @@ -133,9 +133,9 @@ wince-* { SOURCES += $$WIDGETS_CPP/ce/qcemainwindow.cpp HEADERS += $$WIDGETS_H/ce/qcemainwindow.h - SOURCES -= $$WIDGETS_CPP/qsyntaxhighlighter.cpp \ + SOURCES -= $$WIDGETS_CPP/tqsyntaxhighlighter.cpp \ $$WIDGETS_CPP/qsplashscreen.cpp - HEADERS -= $$WIDGETS_H/ntqsyntaxhighlighter.h \ + HEADERS -= $$WIDGETS_H/tqsyntaxhighlighter.h \ $$WIDGETS_H/ntqsplashscreen.h } diff --git a/src/widgets/qtitlebar_p.h b/src/widgets/qtitlebar_p.h index b933658dd..ae9fd6b15 100644 --- a/src/widgets/qtitlebar_p.h +++ b/src/widgets/qtitlebar_p.h @@ -57,7 +57,7 @@ #ifndef QT_H #include "ntqbutton.h" -#include "ntqlabel.h" +#include "tqlabel.h" #endif // QT_H #if !defined(TQT_NO_TITLEBAR) diff --git a/src/widgets/qwhatsthis.cpp b/src/widgets/qwhatsthis.cpp deleted file mode 100644 index 65df04e7b..000000000 --- a/src/widgets/qwhatsthis.cpp +++ /dev/null @@ -1,1001 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQWhatsThis class -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the widgets module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqwhatsthis.h" -#ifndef TQT_NO_WHATSTHIS -#include "ntqapplication.h" -#include "tqpaintdevicemetrics.h" -#include "tqpixmap.h" -#include "tqpainter.h" -#include "tqtimer.h" -#include "tqptrdict.h" -#include "tqtoolbutton.h" -#include "ntqshared.h" -#include "ntqcursor.h" -#include "tqbitmap.h" -#include "tqtooltip.h" -#include "ntqsimplerichtext.h" -#include "tqstylesheet.h" -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif -#if defined(TQ_WS_WIN) -#include "qt_windows.h" -#ifndef SPI_GETDROPSHADOW -#define SPI_GETDROPSHADOW 0x1024 -#endif -#endif - -/*! - \class TQWhatsThis ntqwhatsthis.h - \brief The TQWhatsThis class provides a simple description of any - widget, i.e. answering the question "What's this?". - - \ingroup helpsystem - \mainclass - - "What's this?" help is part of an application's online help system - that provides users with information about functionality, usage, - background etc., in various levels of detail from short tool tips - to full text browsing help windows. - - TQWhatsThis provides a single window with an explanatory text that - pops up when the user asks "What's this?". The default way to do - this is to focus the relevant widget and press Shift+F1. The help - text appears immediately; it goes away as soon as the user does - something else. - - (Note that if there is an accelerator for Shift+F1, this mechanism - will not work.) - - To add "What's this?" text to a widget you simply call - TQWhatsThis::add() for the widget. For example, to assign text to a - menu item, call TQMenuData::setWhatsThis(); for a global - accelerator key, call TQAccel::setWhatsThis() and If you're using - actions, use TQAction::setWhatsThis(). - - The text can be either rich text or plain text. If you specify a - rich text formatted string, it will be rendered using the default - stylesheet. This makes it possible to embed images. See - TQStyleSheet::defaultSheet() for details. - - \quotefile action/application.cpp - \skipto fileOpenText - \printuntil setWhatsThis - - An alternative way to enter "What's this?" mode is to use the - ready-made tool bar tool button from - TQWhatsThis::whatsThisButton(). By invoking this context help - button (in the picture below the first one from the right) the - user switches into "What's this?" mode. If they now click on a - widget the appropriate help text is shown. The mode is left when - help is given or when the user presses Esc. - - \img whatsthis.png - - If you are using TQMainWindow you can also use the - TQMainWindow::whatsThis() slot to invoke the mode from a menu item. - - For more control you can create a dedicated TQWhatsThis object for - a special widget. By subclassing and reimplementing - TQWhatsThis::text() it is possible to have different help texts, - depending on the position of the mouse click. By reimplementing - TQWhatsThis::clicked() it is possible to have hyperlinks inside the - help texts. - - If you wish to control the "What's this?" behavior of a widget - manually see TQWidget::customWhatsThis(). - - The What's This object can be removed using TQWhatsThis::remove(), - although this is rarely necessary because it is automatically - removed when the widget is destroyed. - - \sa TQToolTip -*/ - -// a special button -class TQWhatsThisButton: public TQToolButton -{ - TQ_OBJECT - -public: - TQWhatsThisButton( TQWidget * parent, const char * name ); - ~TQWhatsThisButton(); - -public slots: - void mouseReleased(); - -}; - - -class TQWhatsThat : public TQWidget -{ - TQ_OBJECT -public: - TQWhatsThat( TQWidget* w, const TQString& txt, TQWidget* parent, const char* name ); - ~TQWhatsThat() ; - -public slots: - void hide(); - inline void widgetDestroyed() { widget = 0; } - -protected: - void mousePressEvent( TQMouseEvent* ); - void mouseReleaseEvent( TQMouseEvent* ); - void mouseMoveEvent( TQMouseEvent* ); - void keyPressEvent( TQKeyEvent* ); - void paintEvent( TQPaintEvent* ); - -private: - TQString text; -#ifndef TQT_NO_RICHTEXT - TQSimpleRichText* doc; -#endif - TQString anchor; - bool pressed; - TQWidget* widget; -}; - - -class TQWhatsThisPrivate: public TQObject -{ - TQ_OBJECT -public: - - // an item for storing texts - struct WhatsThisItem: public TQShared - { - WhatsThisItem(): TQShared() { whatsthis = 0; } - ~WhatsThisItem(); - TQString s; - TQWhatsThis* whatsthis; - }; - - // the (these days pretty small) state machine - enum State { Inactive, Waiting }; - - TQWhatsThisPrivate(); - ~TQWhatsThisPrivate(); - - bool eventFilter( TQObject *, TQEvent * ); - - WhatsThisItem* newItem( TQWidget * widget ); - void add( TQWidget * widget, TQWhatsThis* special ); - void add( TQWidget * widget, const TQString& text ); - - // say it. - void say( TQWidget *, const TQString&, const TQPoint& ); - - // setup and teardown - static void setUpWhatsThis(); - - void enterWhatsThisMode(); - void leaveWhatsThisMode(); - - // variables - TQWhatsThat * whatsThat; - TQPtrDict * dict; - TQPtrDict * tlw; - TQPtrDict * buttons; - State state; - -private slots: - void cleanupWidget() - { - const TQObject* o = sender(); - if ( o->isWidgetType() ) // sanity - TQWhatsThis::remove((TQWidget*)o); - } - -}; - -// static, but static the less-typing way -static TQWhatsThisPrivate * wt = 0; - -// shadowWidth not const, for XP drop-shadow-fu turns it to 0 -static int shadowWidth = 6; // also used as '5' and '6' and even '8' below -const int vMargin = 8; -const int hMargin = 12; - -// Lets TQPopupMenu destroy the TQWhatsThat. -void qWhatsThisBDH() -{ - if ( wt && wt->whatsThat ) - wt->whatsThat->hide(); -} - - -TQWhatsThat::TQWhatsThat( TQWidget* w, const TQString& txt, TQWidget* parent, const char* name ) - : TQWidget( parent, name, WType_Popup ), text( txt ), pressed( FALSE ), widget( w ) -{ - - setBackgroundMode( NoBackground ); - setPalette( TQToolTip::palette() ); - setMouseTracking( TRUE ); -#ifndef TQT_NO_CURSOR - setCursor( arrowCursor ); -#endif - - if ( widget ) - connect( widget, TQ_SIGNAL( destroyed() ), this, TQ_SLOT( widgetDestroyed() ) ); - - - TQRect r; -#ifndef TQT_NO_RICHTEXT - doc = 0; - if ( TQStyleSheet::mightBeRichText( text ) ) { - TQFont f = TQApplication::font( this ); - doc = new TQSimpleRichText( text, f ); - doc->adjustSize(); - r.setRect( 0, 0, doc->width(), doc->height() ); - } - else -#endif - { - int sw = TQApplication::desktop()->width() / 3; - if ( sw < 200 ) - sw = 200; - else if ( sw > 300 ) - sw = 300; - - r = fontMetrics().boundingRect( 0, 0, sw, 1000, - AlignAuto + AlignTop + WordBreak + ExpandTabs, - text ); - } -#if defined(TQ_WS_WIN) - if ( (qWinVersion()&WV_NT_based) > WV_2000 ) { - BOOL shadow; - SystemParametersInfo( SPI_GETDROPSHADOW, 0, &shadow, 0 ); - shadowWidth = shadow ? 0 : 6; - } -#endif - resize( r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth ); -} - -TQWhatsThat::~TQWhatsThat() -{ - if ( wt && wt->whatsThat == this ) - wt->whatsThat = 0; -#ifndef TQT_NO_RICHTEXT - if ( doc ) - delete doc; -#endif -} - -void TQWhatsThat::hide() -{ - TQWidget::hide(); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ContextHelpEnd ); -#endif -} - -void TQWhatsThat::mousePressEvent( TQMouseEvent* e ) -{ - pressed = TRUE; - if ( e->button() == LeftButton && rect().contains( e->pos() ) ) { -#ifndef TQT_NO_RICHTEXT - if ( doc ) - anchor = doc->anchorAt( e->pos() - TQPoint( hMargin, vMargin) ); -#endif - return; - } - hide(); -} - -void TQWhatsThat::mouseReleaseEvent( TQMouseEvent* e ) -{ - if ( !pressed ) - return; -#ifndef TQT_NO_RICHTEXT - if ( e->button() == LeftButton && doc && rect().contains( e->pos() ) ) { - TQString a = doc->anchorAt( e->pos() - TQPoint( hMargin, vMargin ) ); - TQString href; - if ( anchor == a ) - href = a; - anchor = TQString::null; - if ( widget && wt && wt->dict ) { - TQWhatsThisPrivate::WhatsThisItem * i = wt->dict->find( widget ); - if ( i && i->whatsthis && !i->whatsthis->clicked( href ) ) - return; - } - } -#endif - hide(); -} - -void TQWhatsThat::mouseMoveEvent( TQMouseEvent* e) -{ -#ifndef TQT_NO_RICHTEXT -#ifndef TQT_NO_CURSOR - if ( !doc ) - return; - TQString a = doc->anchorAt( e->pos() - TQPoint( hMargin, vMargin ) ); - if ( !a.isEmpty() ) - setCursor( pointingHandCursor ); - else - setCursor( arrowCursor ); -#endif -#endif -} - - -void TQWhatsThat::keyPressEvent( TQKeyEvent* ) -{ - hide(); -} - - - -void TQWhatsThat::paintEvent( TQPaintEvent* ) -{ - bool drawShadow = TRUE; -#if defined(TQ_WS_WIN) - if ( (qWinVersion()&WV_NT_based) > WV_2000 ) { - BOOL shadow; - SystemParametersInfo( SPI_GETDROPSHADOW, 0, &shadow, 0 ); - drawShadow = !shadow; - } -#elif defined(TQ_WS_MACX) - drawShadow = FALSE; //never draw it on OS X we get it for free -#endif - - TQRect r = rect(); - if ( drawShadow ) - r.addCoords( 0, 0, -shadowWidth, -shadowWidth ); - TQPainter p( this); - p.setPen( colorGroup().foreground() ); - p.drawRect( r ); - p.setPen( colorGroup().mid() ); - p.setBrush( colorGroup().brush( TQColorGroup::Background ) ); - int w = r.width(); - int h = r.height(); - p.drawRect( 1, 1, w-2, h-2 ); - if ( drawShadow ) { - p.setPen( colorGroup().shadow() ); - p.drawPoint( w + 5, 6 ); - p.drawLine( w + 3, 6, w + 5, 8 ); - p.drawLine( w + 1, 6, w + 5, 10 ); - int i; - for( i=7; i < h; i += 2 ) - p.drawLine( w, i, w + 5, i + 5 ); - for( i = w - i + h; i > 6; i -= 2 ) - p.drawLine( i, h, i + 5, h + 5 ); - for( ; i > 0 ; i -= 2 ) - p.drawLine( 6, h + 6 - i, i + 5, h + 5 ); - } - p.setPen( colorGroup().foreground() ); - r.addCoords( hMargin, vMargin, -hMargin, -vMargin ); - -#ifndef TQT_NO_RICHTEXT - if ( doc ) { - doc->draw( &p, r.x(), r.y(), r, colorGroup(), 0 ); - } - else -#endif - { - p.drawText( r, AlignAuto + AlignTop + WordBreak + ExpandTabs, text ); - } -} - -// the item -TQWhatsThisPrivate::WhatsThisItem::~WhatsThisItem() -{ - if ( count ) - tqFatal( "TQWhatsThis: Internal error (%d)", count ); - delete whatsthis; -} - - -static const char * const button_image[] = { -"16 16 3 1", -" c None", -"o c #000000", -"a c #000080", -"o aaaaa ", -"oo aaa aaa ", -"ooo aaa aaa", -"oooo aa aa", -"ooooo aa aa", -"oooooo a aaa", -"ooooooo aaa ", -"oooooooo aaa ", -"ooooooooo aaa ", -"ooooo aaa ", -"oo ooo ", -"o ooo aaa ", -" ooo aaa ", -" ooo ", -" ooo ", -" ooo "}; - -// the button class -TQWhatsThisButton::TQWhatsThisButton( TQWidget * parent, const char * name ) - : TQToolButton( parent, name ) -{ - TQPixmap p( (const char**)button_image ); - setPixmap( p ); - setToggleButton( TRUE ); - setAutoRaise( TRUE ); - setFocusPolicy( NoFocus ); - setTextLabel( tr( "What's this?" ) ); - wt->buttons->insert( (void *)this, this ); - connect( this, TQ_SIGNAL( released() ), - this, TQ_SLOT( mouseReleased() ) ); -} - - -TQWhatsThisButton::~TQWhatsThisButton() -{ - if ( wt && wt->buttons ) - wt->buttons->take( (void *)this ); -} - - -void TQWhatsThisButton::mouseReleased() -{ - if ( wt->state == TQWhatsThisPrivate::Inactive && isOn() ) { - TQWhatsThisPrivate::setUpWhatsThis(); -#ifndef TQT_NO_CURSOR - TQApplication::setOverrideCursor( whatsThisCursor, FALSE ); -#endif - wt->state = TQWhatsThisPrivate::Waiting; - tqApp->installEventFilter( wt ); - } -} - -static void qWhatsThisPrivateCleanup() -{ - if( wt ) { - delete wt; - wt = 0; - } -} - -// the what's this manager class -TQWhatsThisPrivate::TQWhatsThisPrivate() - : TQObject( 0, "global what's this object" ) -{ - whatsThat = 0; - dict = new TQPtrDict; - tlw = new TQPtrDict; - wt = this; - buttons = new TQPtrDict; - state = Inactive; -} - -TQWhatsThisPrivate::~TQWhatsThisPrivate() -{ -#ifndef TQT_NO_CURSOR - if ( state == Waiting && tqApp ) - TQApplication::restoreOverrideCursor(); -#endif - // the two straight-and-simple dicts - delete tlw; - delete buttons; - - // then delete the complex one. - TQPtrDictIterator it( *dict ); - WhatsThisItem * i; - TQWidget * w; - while( (i=it.current()) != 0 ) { - w = (TQWidget *)it.currentKey(); - ++it; - dict->take( w ); - if ( i->deref() ) - delete i; - } - delete dict; - if ( whatsThat && !whatsThat->parentWidget() ) { - delete whatsThat; - } - // and finally lose wt - wt = 0; -} - -bool TQWhatsThisPrivate::eventFilter( TQObject * o, TQEvent * e ) -{ - switch( state ) { - case Waiting: - if ( e->type() == TQEvent::MouseButtonPress && o->isWidgetType() ) { - TQWidget * w = (TQWidget *) o; - if ( ( (TQMouseEvent*)e)->button() == RightButton ) - return FALSE; // ignore RMB - if ( w->customWhatsThis() ) - return FALSE; - TQWhatsThisPrivate::WhatsThisItem * i = 0; - TQMouseEvent* me = (TQMouseEvent*) e; - TQPoint p = me->pos(); - while( w && !i ) { - i = dict->find( w ); - if ( !i ) { - p += w->pos(); - w = w->parentWidget( TRUE ); - } - } - leaveWhatsThisMode(); - if (!i ) { -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ContextHelpEnd ); -#endif - return TRUE; - } - if ( i->whatsthis ) - say( w, i->whatsthis->text( p ), me->globalPos() ); - else - say( w, i->s, me->globalPos() ); - return TRUE; - } else if ( e->type() == TQEvent::MouseButtonRelease ) { - if ( ( (TQMouseEvent*)e)->button() == RightButton ) - return FALSE; // ignore RMB - return !o->isWidgetType() || !((TQWidget*)o)->customWhatsThis(); - } else if ( e->type() == TQEvent::MouseMove ) { - return !o->isWidgetType() || !((TQWidget*)o)->customWhatsThis(); - } else if ( e->type() == TQEvent::KeyPress ) { - TQKeyEvent* kev = (TQKeyEvent*)e; - - if ( kev->key() == TQt::Key_Escape ) { - leaveWhatsThisMode(); - return TRUE; - } else if ( o->isWidgetType() && ((TQWidget*)o)->customWhatsThis() ) { - return FALSE; - } else if ( kev->key() == Key_Menu || - ( kev->key() == Key_F10 && - kev->state() == ShiftButton ) ) { - // we don't react to these keys, they are used for context menus - return FALSE; - } else if ( kev->state() == kev->stateAfter() && - kev->key() != Key_Meta ) { // not a modifier key - leaveWhatsThisMode(); - } - } else if ( e->type() == TQEvent::MouseButtonDblClick ) { - return TRUE; - } - break; - case Inactive: - if ( e->type() == TQEvent::Accel && - ((TQKeyEvent *)e)->key() == Key_F1 && - o->isWidgetType() && - ((TQKeyEvent *)e)->state() == ShiftButton ) { - TQWidget * w = ((TQWidget *)o)->focusWidget(); - if ( !w ) - break; - TQString s = TQWhatsThis::textFor( w, TQPoint(0,0), TRUE ); - if ( !s.isNull() ) { - say ( w, s, w->mapToGlobal( w->rect().center() ) ); - ((TQKeyEvent *)e)->accept(); - return TRUE; - } - } - break; - } - return FALSE; -} - - - -void TQWhatsThisPrivate::setUpWhatsThis() -{ - if ( !wt ) { - wt = new TQWhatsThisPrivate(); - - // It is necessary to use a post routine, because - // the destructor deletes pixmaps and other stuff that - // needs a working X connection under X11. - tqAddPostRoutine( qWhatsThisPrivateCleanup ); - } -} - - -void TQWhatsThisPrivate::enterWhatsThisMode() -{ -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ContextHelpStart ); -#endif -} - - -void TQWhatsThisPrivate::leaveWhatsThisMode() -{ - if ( state == Waiting ) { - TQPtrDictIterator it( *(wt->buttons) ); - TQWhatsThisButton * b; - while( (b=it.current()) != 0 ) { - ++it; - b->setOn( FALSE ); - } -#ifndef TQT_NO_CURSOR - TQApplication::restoreOverrideCursor(); -#endif - state = Inactive; - tqApp->removeEventFilter( this ); - } -} - - - -void TQWhatsThisPrivate::say( TQWidget * widget, const TQString &text, const TQPoint& ppos) -{ - if ( text.isEmpty() ) - return; - // make a fresh widget, and set it up - delete whatsThat; - whatsThat = new TQWhatsThat( - widget, text, -#if defined(TQ_WS_X11) - TQApplication::desktop()->screen( widget ? - widget->x11Screen() : - TQCursor::x11Screen() ), -#else - 0, -#endif - "automatic what's this? widget" ); - - - // okay, now to find a suitable location - - int scr = ( widget ? - TQApplication::desktop()->screenNumber( widget ) : -#if defined(TQ_WS_X11) - TQCursor::x11Screen() -#else - TQApplication::desktop()->screenNumber( ppos ) -#endif // TQ_WS_X11 - ); - TQRect screen = TQApplication::desktop()->screenGeometry( scr ); - - int x; - int w = whatsThat->width(); - int h = whatsThat->height(); - int sx = screen.x(); - int sy = screen.y(); - - // first try locating the widget immediately above/below, - // with nice alignment if possible. - TQPoint pos; - if ( widget ) - pos = widget->mapToGlobal( TQPoint( 0,0 ) ); - - if ( widget && w > widget->width() + 16 ) - x = pos.x() + widget->width()/2 - w/2; - else - x = ppos.x() - w/2; - - // squeeze it in if that would result in part of what's this - // being only partially visible - if ( x + w + shadowWidth > sx+screen.width() ) - x = (widget? (TQMIN(screen.width(), - pos.x() + widget->width()) - ) : screen.width() ) - - w; - - if ( x < sx ) - x = sx; - - int y; - if ( widget && h > widget->height() + 16 ) { - y = pos.y() + widget->height() + 2; // below, two pixels spacing - // what's this is above or below, wherever there's most space - if ( y + h + 10 > sy+screen.height() ) - y = pos.y() + 2 - shadowWidth - h; // above, overlap - } - y = ppos.y() + 2; - - // squeeze it in if that would result in part of what's this - // being only partially visible - if ( y + h + shadowWidth > sy+screen.height() ) - y = ( widget ? (TQMIN(screen.height(), - pos.y() + widget->height()) - ) : screen.height() ) - - h; - if ( y < sy ) - y = sy; - - whatsThat->move( x, y ); - whatsThat->show(); -} - -TQWhatsThisPrivate::WhatsThisItem* TQWhatsThisPrivate::newItem( TQWidget * widget ) -{ - WhatsThisItem * i = dict->find( (void *)widget ); - if ( i ) - TQWhatsThis::remove( widget ); - i = new WhatsThisItem; - dict->insert( (void *)widget, i ); - TQWidget * t = widget->topLevelWidget(); - if ( !tlw->find( (void *)t ) ) { - tlw->insert( (void *)t, t ); - t->installEventFilter( this ); - } - connect( widget, TQ_SIGNAL(destroyed()), this, TQ_SLOT(cleanupWidget()) ); - return i; -} - -void TQWhatsThisPrivate::add( TQWidget * widget, TQWhatsThis* special ) -{ - newItem( widget )->whatsthis = special; -} - -void TQWhatsThisPrivate::add( TQWidget * widget, const TQString &text ) -{ - newItem( widget )->s = text; -} - - -// and finally the What's This class itself - -/*! - Adds \a text as "What's this" help for \a widget. If the text is - rich text formatted (i.e. it contains markup) it will be rendered - with the default stylesheet TQStyleSheet::defaultSheet(). - - The text is destroyed if the widget is later destroyed, so it need - not be explicitly removed. - - \sa remove() -*/ -void TQWhatsThis::add( TQWidget * widget, const TQString &text ) -{ - if ( text.isEmpty() ) - return; // pointless - TQWhatsThisPrivate::setUpWhatsThis(); - wt->add(widget,text); -} - - -/*! - Removes the "What's this?" help associated with the \a widget. - This happens automatically if the widget is destroyed. - - \sa add() -*/ -void TQWhatsThis::remove( TQWidget * widget ) -{ - TQWhatsThisPrivate::setUpWhatsThis(); - TQWhatsThisPrivate::WhatsThisItem * i = wt->dict->find( (void *)widget ); - if ( !i ) - return; - - wt->dict->take( (void *)widget ); - - i->deref(); - if ( !i->count ) - delete i; -} - - -/*! - Returns the what's this text for widget \a w or TQString::null if - there is no "What's this?" help for the widget. \a pos contains - the mouse position; this is useful, for example, if you've - subclassed to make the text that is displayed position dependent. - - If \a includeParents is TRUE, parent widgets are taken into - consideration as well when looking for what's this help text. - - \sa add() -*/ -TQString TQWhatsThis::textFor( TQWidget * w, const TQPoint& pos, bool includeParents ) -{ - TQWhatsThisPrivate::setUpWhatsThis(); - TQWhatsThisPrivate::WhatsThisItem * i = 0; - TQPoint p = pos; - while( w && !i ) { - i = wt->dict->find( w ); - if ( !includeParents ) - break; - if ( !i ) { - p += w->pos(); - w = w->parentWidget( TRUE ); - } - } - if (!i) - return TQString::null; - if ( i->whatsthis ) - return i->whatsthis->text( p ); - return i->s; -} - - -/*! - Creates a TQToolButton preconfigured to enter "What's this?" mode - when clicked. You will often use this with a tool bar as \a - parent: - \code - (void) TQWhatsThis::whatsThisButton( my_help_tool_bar ); - \endcode -*/ -TQToolButton * TQWhatsThis::whatsThisButton( TQWidget * parent ) -{ - TQWhatsThisPrivate::setUpWhatsThis(); - return new TQWhatsThisButton( parent, - "automatic what's this? button" ); -} - -/*! - Constructs a dynamic "What's this?" object for \a widget. The - object is deleted when the \a widget is destroyed. - - When the widget is queried by the user the text() function of this - TQWhatsThis will be called to provide the appropriate text, rather - than using the text assigned by add(). -*/ -TQWhatsThis::TQWhatsThis( TQWidget * widget) -{ - TQWhatsThisPrivate::setUpWhatsThis(); - wt->add(widget,this); -} - - -/*! - Destroys the object and frees any allocated resources. -*/ -TQWhatsThis::~TQWhatsThis() -{ -} - - -/*! - This virtual function returns the text for position \e p in the - widget that this "What's this?" object documents. If there is no - "What's this?" text for the position, TQString::null is returned. - - The default implementation returns TQString::null. -*/ -TQString TQWhatsThis::text( const TQPoint & ) -{ - return TQString::null; -} - -/*! - \fn bool TQWhatsThis::clicked( const TQString& href ) - - This virtual function is called when the user clicks inside the - "What's this?" window. \a href is the link the user clicked on, or - TQString::null if there was no link. - - If the function returns TRUE (the default), the "What's this?" - window is closed, otherwise it remains visible. - - The default implementation ignores \a href and returns TRUE. -*/ -bool TQWhatsThis::clicked( const TQString& ) -{ - return TRUE; -} - - -/*! - Enters "What's this?" mode and returns immediately. - - TQt will install a special cursor and take over mouse input until - the user clicks somewhere. It then shows any help available and - ends "What's this?" mode. Finally, TQt removes the special cursor - and help window and then restores ordinary event processing, at - which point the left mouse button is no longer pressed. - - The user can also use the Esc key to leave "What's this?" mode. - - \sa inWhatsThisMode(), leaveWhatsThisMode() -*/ - -void TQWhatsThis::enterWhatsThisMode() -{ - TQWhatsThisPrivate::setUpWhatsThis(); - if ( wt->state == TQWhatsThisPrivate::Inactive ) { - wt->enterWhatsThisMode(); -#ifndef TQT_NO_CURSOR - TQApplication::setOverrideCursor( whatsThisCursor, FALSE ); -#endif - wt->state = TQWhatsThisPrivate::Waiting; - tqApp->installEventFilter( wt ); - } -} - - -/*! - Returns TRUE if the application is in "What's this?" mode; - otherwise returns FALSE. - - \sa enterWhatsThisMode(), leaveWhatsThisMode() -*/ -bool TQWhatsThis::inWhatsThisMode() -{ - if (!wt) - return FALSE; - return wt->state == TQWhatsThisPrivate::Waiting; -} - - -/*! - Leaves "What's this?" question mode. - - This function is used internally by widgets that support - TQWidget::customWhatsThis(); applications do not usually call it. - An example of such a widget is TQPopupMenu: menus still work - normally in "What's this?" mode but also provide help texts for - individual menu items. - - If \a text is not TQString::null, a "What's this?" help window is - displayed at the global screen position \a pos. If widget \a w is - not 0 and has its own dedicated TQWhatsThis object, this object - will receive clicked() messages when the user clicks on hyperlinks - inside the help text. - - \sa inWhatsThisMode(), enterWhatsThisMode(), TQWhatsThis::clicked() -*/ -void TQWhatsThis::leaveWhatsThisMode( const TQString& text, const TQPoint& pos, TQWidget* w ) -{ - if ( !inWhatsThisMode() ) - return; - - wt->leaveWhatsThisMode(); - if ( !text.isNull() ) - wt->say( w, text, pos ); -} - -/*! - Display \a text in a help window at the global screen position \a - pos. - - If widget \a w is not 0 and has its own dedicated TQWhatsThis - object, this object will receive clicked() messages when the user - clicks on hyperlinks inside the help text. - - \sa TQWhatsThis::clicked() -*/ -void TQWhatsThis::display( const TQString& text, const TQPoint& pos, TQWidget* w ) -{ - if ( inWhatsThisMode() ) { - leaveWhatsThisMode( text, pos, w ); - return; - } - TQWhatsThisPrivate::setUpWhatsThis(); - wt->say( w, text, pos ); -} - -/*! - Sets the font for all "What's this?" helps to \a font. -*/ -void TQWhatsThis::setFont( const TQFont &font ) -{ - TQApplication::setFont( font, TRUE, "TQWhatsThat" ); -} - -#include "qwhatsthis.moc" -#endif diff --git a/src/widgets/tqaction.cpp b/src/widgets/tqaction.cpp index 6bf1a50f8..31d308420 100644 --- a/src/widgets/tqaction.cpp +++ b/src/widgets/tqaction.cpp @@ -47,7 +47,7 @@ #include "tqtoolbutton.h" #include "ntqcombobox.h" #include "tqtooltip.h" -#include "ntqwhatsthis.h" +#include "tqwhatsthis.h" #include "tqstatusbar.h" #include "tqobjectlist.h" diff --git a/src/widgets/tqlabel.cpp b/src/widgets/tqlabel.cpp new file mode 100644 index 000000000..7f9d858bb --- /dev/null +++ b/src/widgets/tqlabel.cpp @@ -0,0 +1,1191 @@ +/********************************************************************** +** +** Implementation of TQLabel widget class +** +** Created : 941215 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqlabel.h" +#ifndef TQT_NO_LABEL +#include "tqpainter.h" +#include "ntqdrawutil.h" +#include "ntqaccel.h" +#include "tqmovie.h" +#include "tqimage.h" +#include "tqbitmap.h" +#include "tqpicture.h" +#include "ntqapplication.h" +#include "tqsimplerichtext.h" +#include "tqstylesheet.h" +#include "tqstyle.h" + +class TQLabelPrivate +{ +public: + TQLabelPrivate() + :img(0), pix(0), valid_hints( -1 ) + {} + TQImage* img; // for scaled contents + TQPixmap* pix; // for scaled contents + TQSize sh; + TQSize msh; + int valid_hints; // stores the frameWidth() for the stored size hint, -1 otherwise +}; + + +/*! + \class TQLabel tqlabel.h + \brief The TQLabel widget provides a text or image display. + + \ingroup basic + \ingroup text + \mainclass + + TQLabel is used for displaying text or an image. 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 TQLabel can contain any of the following content types: + \table + \header \i Content \i Setting + \row \i Plain text + \i Pass a TQString to setText(). + \row \i Rich text + \i Pass a TQString that contains rich text to setText(). + \row \i A pixmap + \i Pass a TQPixmap to setPixmap(). + \row \i A movie + \i Pass a TQMovie to setMovie(). + \row \i A number + \i Pass an \e int or a \e double to setNum(), which converts + the number to plain text. + \row \i Nothing + \i The same as an empty plain text. This is the default. Set + by clear(). + \endtable + + When the content is changed using any of these functions, any + previous content is cleared. + + The look of a TQLabel can be tuned in several ways. All the + settings of TQFrame are available for specifying a widget frame. + The positioning of the content within the TQLabel 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): + \code + TQLabel *label = new TQLabel( this ); + label->setFrameStyle( TQFrame::Panel | TQFrame::Sunken ); + label->setText( "first line\nsecond line" ); + label->setAlignment( AlignBottom | AlignRight ); + \endcode + + A TQLabel is often used as a label for an interactive widget. For + this use TQLabel provides a useful mechanism for adding an + accelerator key (see TQAccel) that will set the keyboard focus to + the other widget (called the TQLabel's "buddy"). For example: + \code + TQLineEdit* phoneEdit = new TQLineEdit( this, "phoneEdit" ); + TQLabel* phoneLabel = new TQLabel( phoneEdit, "&Phone:", this, "phoneLabel" ); + \endcode + + In this example, keyboard focus is transferred to the label's + buddy (the TQLineEdit) when the user presses Alt+P. You can + also use the setBuddy() function to accomplish the same thing. + + + + \sa TQLineEdit, TQTextEdit, TQPixmap, TQMovie, + \link guibooks.html#fowler GUI Design Handbook: Label\endlink +*/ + +/*! + \fn TQPicture * TQLabel::picture() const + + Returns the label's picture or 0 if the label doesn't have a + picture. +*/ + + +/*! + Constructs an empty label. + + The \a parent, \a name and widget flag \a f, arguments are passed + to the TQFrame constructor. + + \sa setAlignment(), setFrameStyle(), setIndent() +*/ + +TQLabel::TQLabel( TQWidget *parent, const char *name, WFlags f ) + : TQFrame( parent, name, f | WMouseNoMask ) +{ + init(); +} + + +/*! + Constructs a label that displays the text, \a text. + + The \a parent, \a name and widget flag \a f, arguments are passed + to the TQFrame constructor. + + \sa setText(), setAlignment(), setFrameStyle(), setIndent() +*/ + +TQLabel::TQLabel( const TQString &text, TQWidget *parent, const char *name, + WFlags f ) + : TQFrame( parent, name, f | WMouseNoMask ) +{ + init(); + setText( text ); +} + + +/*! + Constructs a label that displays the text \a text. The label has a + buddy widget, \a buddy. + + If the \a text contains an underlined letter (a letter preceded by + an ampersand, \&), and the text is in plain text format, when the + user presses Alt+ the underlined letter, focus is passed to the + buddy widget. + + The \a parent, \a name and widget flag, \a f, arguments are passed + to the TQFrame constructor. + + \sa setText(), setBuddy(), setAlignment(), setFrameStyle(), + setIndent() +*/ +TQLabel::TQLabel( TQWidget *buddy, const TQString &text, + TQWidget *parent, const char *name, WFlags f ) + : TQFrame( parent, name, f | WMouseNoMask ) +{ + init(); +#ifndef TQT_NO_ACCEL + setBuddy( buddy ); +#endif + setText( text ); +} + +/*! + Destroys the label. +*/ + +TQLabel::~TQLabel() +{ + clearContents(); + delete d; +} + + +void TQLabel::init() +{ + lpixmap = 0; +#ifndef TQT_NO_MOVIE + lmovie = 0; +#endif +#ifndef TQT_NO_ACCEL + lbuddy = 0; + accel = 0; +#endif + lpixmap = 0; +#ifndef TQT_NO_PICTURE + lpicture = 0; +#endif + align = AlignAuto | AlignVCenter | ExpandTabs; + extraMargin = -1; + autoresize = FALSE; + scaledcontents = FALSE; + textformat = TQt::AutoText; +#ifndef TQT_NO_RICHTEXT + doc = 0; +#endif + + setSizePolicy( TQSizePolicy( TQSizePolicy::Preferred, TQSizePolicy::Preferred ) ); + d = new TQLabelPrivate; +} + + +/*! + \property TQLabel::text + \brief the label's text + + If no text has been set this will return an empty string. Setting + the text clears any previous content, unless they are the same. + + The 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 \c AutoText, i.e. TQLabel will try to + auto-detect the format of the text set. + + If the 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 TQLabel is well-suited to display small rich text + documents, i.e. those small documents that get their document + specific settings (font, text color, link color) from the label's + palette and font properties. For large documents, use TQTextEdit + in read-only mode instead. TQTextEdit will flicker less on resize + and can also provide a scrollbar when necessary. + + \sa text, setTextFormat(), setBuddy(), alignment +*/ + +void TQLabel::setText( const TQString &text ) +{ + if ( ltext == text ) + return; + TQSize osh = sizeHint(); +#ifndef TQT_NO_RICHTEXT + bool hadRichtext = doc != 0; +#endif + clearContents(); + ltext = text; +#ifndef TQT_NO_RICHTEXT + bool useRichText = (textformat == RichText || + ( ( textformat == AutoText ) && TQStyleSheet::mightBeRichText(ltext) ) ); +#else + bool useRichText = TRUE; +#endif +#ifndef TQT_NO_ACCEL + // ### Setting accelerators for rich text labels will not work. + // Eg. >Hello will return ALT+G which is clearly + // not intended. + if ( !useRichText ) { + int p = TQAccel::shortcutKey( ltext ); + if ( p ) { + if ( !accel ) + accel = new TQAccel( this, "accel label accel" ); + accel->connectItem( accel->insertItem( p ), + this, TQ_SLOT(acceleratorSlot()) ); + } + } +#endif +#ifndef TQT_NO_RICHTEXT + if ( useRichText ) { + if ( !hadRichtext ) + align |= WordBreak; + TQString t = ltext; + if ( align & AlignRight ) + t.prepend( "
"); + else if ( align & AlignHCenter ) + t.prepend( "
"); + if ( (align & WordBreak) == 0 ) + t.prepend( "" ); + doc = new TQSimpleRichText( t, font() ); + } +#endif + + updateLabel( osh ); +} + + +/*! + Clears any label contents. Equivalent to setText( "" ). +*/ + +void TQLabel::clear() +{ + setText( TQString::fromLatin1("") ); +} + +/*! + \property TQLabel::pixmap + \brief the label's pixmap + + If no pixmap has been set this will return an invalid pixmap. + + Setting the pixmap clears any previous content, and resizes the + label if \l TQLabel::autoResize() is TRUE. The buddy accelerator, + if any, is disabled. +*/ +void TQLabel::setPixmap( const TQPixmap &pixmap ) +{ + TQSize osh = sizeHint(); + + if ( !lpixmap || lpixmap->serialNumber() != pixmap.serialNumber() ) { + clearContents(); + lpixmap = new TQPixmap( pixmap ); + } + + if ( lpixmap->depth() == 1 && !lpixmap->mask() ) + lpixmap->setMask( *((TQBitmap *)lpixmap) ); + + updateLabel( osh ); +} + +#ifndef TQT_NO_PICTURE +/*! + Sets the label contents to \a picture. Any previous content is + cleared. + + The buddy accelerator, if any, is disabled. + + \sa picture(), setBuddy() +*/ + +void TQLabel::setPicture( const TQPicture &picture ) +{ + TQSize osh = sizeHint(); + clearContents(); + lpicture = new TQPicture( picture ); + + updateLabel( osh ); +} +#endif // TQT_NO_PICTURE + +/*! + Sets the label contents to plain text containing the textual + representation of integer \a num. Any previous content is cleared. + Does nothing if the integer's string representation is the same as + the current contents of the label. + + The buddy accelerator, if any, is disabled. + + The label resizes itself if auto-resizing is enabled. + + \sa setText(), TQString::setNum(), setBuddy() +*/ + +void TQLabel::setNum( int num ) +{ + TQString str; + str.setNum( num ); + setText( str ); +} + +/*! + \overload + + Sets the label contents to plain text containing the textual + representation of double \a num. Any previous content is cleared. + Does nothing if the double's string representation is the same as + the current contents of the label. + + The buddy accelerator, if any, is disabled. + + The label resizes itself if auto-resizing is enabled. + + \sa setText(), TQString::setNum(), setBuddy() +*/ + +void TQLabel::setNum( double num ) +{ + TQString str; + str.setNum( num ); + setText( str ); +} + +/*! + \property TQLabel::alignment + \brief the alignment of the label's contents + + The alignment is a bitwise OR of \c TQt::AlignmentFlags and \c + TQt::TextFlags values. The \c ExpandTabs, \c SingleLine and \c + ShowPrefix flags apply only if the label contains plain text; + otherwise they are ignored. The \c DontClip flag is always + ignored. \c WordBreak applies to both rich text and plain text + labels. The \c BreakAnywhere flag is not supported in TQLabel. + + If the label has a buddy, the \c ShowPrefix flag is forced to + TRUE. + + The default alignment is \c{AlignAuto | AlignVCenter | ExpandTabs} + if the label doesn't have a buddy and \c{AlignAuto | AlignVCenter + | ExpandTabs | ShowPrefix} if the label has a buddy. If the label + contains rich text, additionally \c WordBreak is turned on. + + \sa TQt::AlignmentFlags, alignment, setBuddy(), text +*/ + +void TQLabel::setAlignment( int alignment ) +{ + if ( alignment == align ) + return; + TQSize osh = sizeHint(); +#ifndef TQT_NO_ACCEL + if ( lbuddy ) + align = alignment | ShowPrefix; + else +#endif + align = alignment; + +#ifndef TQT_NO_RICHTEXT + TQString t = ltext; + if ( !t.isNull() ) { + ltext = TQString::null; + setText( t ); + } +#endif + + updateLabel( osh ); +} + + +/*! + \property TQLabel::indent + \brief the label's text indent in pixels + + If a label displays text, the indent applies to the left edge if + alignment() is \c AlignLeft, to the right edge if alignment() is + \c AlignRight, to the top edge if alignment() is \c AlignTop, and + to to the bottom edge if alignment() is \c 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(). + + \sa alignment, frameWidth(), font() +*/ + +void TQLabel::setIndent( int indent ) +{ + extraMargin = indent; + updateLabel( TQSize( -1, -1 ) ); +} + + +/*! + \fn bool TQLabel::autoResize() const + + \obsolete + + Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing + is disabled. + + Auto-resizing is disabled by default. + + \sa setAutoResize() +*/ + +/*! \obsolete + Enables auto-resizing if \a enable is TRUE, or disables it if \a + 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 TQLabel widgets that are not managed by + a TQLayout (e.g., top-level widgets). + + Auto-resizing is disabled by default. + + \sa autoResize(), adjustSize(), sizeHint() +*/ + +void TQLabel::setAutoResize( bool enable ) +{ + if ( (bool)autoresize != enable ) { + autoresize = enable; + if ( autoresize ) + adjustSize(); // calls resize which repaints + } +} + + + +/*! + Returns the size that will be used if the width of the label is \a + w. If \a w is -1, the sizeHint() is returned. +*/ + +TQSize TQLabel::sizeForWidth( int w ) const +{ + TQRect br; + TQPixmap *pix = pixmap(); +#ifndef TQT_NO_PICTURE + TQPicture *pic = picture(); +#else + const int pic = 0; +#endif +#ifndef TQT_NO_MOVIE + TQMovie *mov = movie(); +#else + const int mov = 0; +#endif + int hextra = 2 * frameWidth(); + int vextra = hextra; + TQFontMetrics fm( fontMetrics() ); + int xw = fm.width( 'x' ); + if ( !mov && !pix && !pic ) { + int m = indent(); + if ( m < 0 && hextra ) // no indent, but we do have a frame + m = xw / 2 - margin(); + if ( m >= 0 ) { + int horizAlign = TQApplication::horizontalAlignment( align ); + if ( (horizAlign & AlignLeft) || (horizAlign & AlignRight ) ) + hextra += m; + if ( (align & AlignTop) || (align & AlignBottom ) ) + vextra += m; + } + } + + if ( pix ) + br = pix->rect(); +#ifndef TQT_NO_PICTURE + else if ( pic ) + br = pic->boundingRect(); +#endif +#ifndef TQT_NO_MOVIE + else if ( mov ) + br = mov->framePixmap().rect(); +#endif +#ifndef TQT_NO_RICHTEXT + else if ( doc ) { + int oldW = doc->width(); + if ( align & WordBreak ) { + if ( w < 0 ) + doc->adjustSize(); + else + doc->setWidth( w-hextra ); + } + br = TQRect( 0, 0, doc->widthUsed(), doc->height() ); + doc->setWidth( oldW ); + } +#endif + else { + bool tryWidth = (w < 0) && (align & WordBreak); + if ( tryWidth ) + w = xw * 80; + else if ( w < 0 ) + w = 2000; + w -= hextra; + br = fm.boundingRect( 0, 0, w ,2000, alignment(), text() ); + if ( tryWidth && br.height() < 4*fm.lineSpacing() && br.width() > w/2 ) + br = fm.boundingRect( 0, 0, w/2, 2000, alignment(), text() ); + if ( tryWidth && br.height() < 2*fm.lineSpacing() && br.width() > w/4 ) + br = fm.boundingRect( 0, 0, w/4, 2000, alignment(), text() ); + } + int wid = br.width() + hextra; + int hei = br.height() + vextra; + + return TQSize( wid, hei ); +} + + +/*! + \reimp +*/ + +int TQLabel::heightForWidth( int w ) const +{ + if ( +#ifndef TQT_NO_RICHTEXT + doc || +#endif + (align & WordBreak) ) + return sizeForWidth( w ).height(); + return TQWidget::heightForWidth( w ); +} + + + +/*!\reimp +*/ +TQSize TQLabel::sizeHint() const +{ + if ( d->valid_hints != frameWidth() ) + (void) TQLabel::minimumSizeHint(); + return d->sh; +} + +/*! + \reimp +*/ + +TQSize TQLabel::minimumSizeHint() const +{ + if ( d->valid_hints == frameWidth() ) + return d->msh; + + constPolish(); + d->valid_hints = frameWidth(); + d->sh = sizeForWidth( -1 ); + TQSize sz( -1, -1 ); + + if ( +#ifndef TQT_NO_RICHTEXT + !doc && +#endif + (align & WordBreak) == 0 ) { + sz = d->sh; + } else { + // think about caching these for performance + sz.rwidth() = sizeForWidth( 0 ).width(); + sz.rheight() = sizeForWidth(TQWIDGETSIZE_MAX).height(); + if ( d->sh.height() < sz.height() ) + sz.rheight() = d->sh.height(); + } + if ( sizePolicy().horData() == TQSizePolicy::Ignored ) + sz.rwidth() = -1; + if ( sizePolicy().verData() == TQSizePolicy::Ignored ) + sz.rheight() = -1; + d->msh = sz; + return sz; +} + +/*! + \reimp +*/ +void TQLabel::resizeEvent( TQResizeEvent* e ) +{ + TQFrame::resizeEvent( e ); + +#ifdef TQT_NO_RICHTEXT + static const bool doc = FALSE; +#endif + + // optimize for standard labels + if ( frameShape() == NoFrame && (align & WordBreak) == 0 && !doc && + ( e->oldSize().width() >= e->size().width() && (align & AlignLeft ) == AlignLeft ) + && ( e->oldSize().height() >= e->size().height() && (align & AlignTop ) == AlignTop ) ) { + setWFlags( WResizeNoErase ); + return; + } + + clearWFlags( WResizeNoErase ); + TQRect cr = contentsRect(); + if ( !lpixmap || !cr.isValid() || + // masked pixmaps can only reduce flicker when being top/left + // aligned and when we do not perform scaled contents + ( lpixmap->hasAlpha() && ( scaledcontents || ( ( align & (AlignLeft|AlignTop) ) != (AlignLeft|AlignTop) ) ) ) ) + return; + + setWFlags( WResizeNoErase ); + + if ( !scaledcontents ) { + // don't we all love TQFrame? Reduce pixmap flicker + TQRegion reg = TQRect( TQPoint(0, 0), e->size() ); + reg = reg.subtract( cr ); + int x = cr.x(); + int y = cr.y(); + int w = lpixmap->width(); + int h = lpixmap->height(); + if ( (align & TQt::AlignVCenter) == TQt::AlignVCenter ) + y += cr.height()/2 - h/2; + else if ( (align & TQt::AlignBottom) == TQt::AlignBottom) + y += cr.height() - h; + if ( (align & TQt::AlignRight) == TQt::AlignRight ) + x += cr.width() - w; + else if ( (align & TQt::AlignHCenter) == TQt::AlignHCenter ) + x += cr.width()/2 - w/2; + if ( x > cr.x() ) + reg = reg.unite( TQRect( cr.x(), cr.y(), x - cr.x(), cr.height() ) ); + if ( y > cr.y() ) + reg = reg.unite( TQRect( cr.x(), cr.y(), cr.width(), y - cr.y() ) ); + + if ( x + w < cr.right() ) + reg = reg.unite( TQRect( x + w, cr.y(), cr.right() - x - w, cr.height() ) ); + if ( y + h < cr.bottom() ) + reg = reg.unite( TQRect( cr.x(), y + h, cr.width(), cr.bottom() - y - h ) ); + + erase( reg ); + } +} + + +/*! + Draws the label contents using the painter \a p. +*/ + +void TQLabel::drawContents( TQPainter *p ) +{ + TQRect cr = contentsRect(); + + TQPixmap *pix = pixmap(); +#ifndef TQT_NO_PICTURE + TQPicture *pic = picture(); +#else + const int pic = 0; +#endif +#ifndef TQT_NO_MOVIE + TQMovie *mov = movie(); +#else + const int mov = 0; +#endif + + if ( !mov && !pix && !pic ) { + int m = indent(); + if ( m < 0 && frameWidth() ) // no indent, but we do have a frame + m = fontMetrics().width('x') / 2 - margin(); + if ( m > 0 ) { + int hAlign = TQApplication::horizontalAlignment( align ); + if ( hAlign & AlignLeft ) + cr.setLeft( cr.left() + m ); + if ( hAlign & AlignRight ) + cr.setRight( cr.right() - m ); + if ( align & AlignTop ) + cr.setTop( cr.top() + m ); + if ( align & AlignBottom ) + cr.setBottom( cr.bottom() - m ); + } + } + +#ifndef TQT_NO_MOVIE + if ( mov ) { + // ### should add movie to qDrawItem + TQRect r = style().itemRect( p, cr, align, isEnabled(), &(mov->framePixmap()), + TQString::null ); + // ### could resize movie frame at this point + p->drawPixmap(r.x(), r.y(), mov->framePixmap() ); + } + else +#endif +#ifndef TQT_NO_RICHTEXT + if ( doc ) { + doc->setWidth(p, cr.width() ); + int rh = doc->height(); + int yo = 0; + if ( align & AlignVCenter ) + yo = (cr.height()-rh)/2; + else if ( align & AlignBottom ) + yo = cr.height()-rh; + if (! isEnabled() && + style().styleHint(TQStyle::SH_EtchDisabledText, this)) { + TQColorGroup cg = colorGroup(); + cg.setColor( TQColorGroup::Text, cg.light() ); + doc->draw(p, cr.x()+1, cr.y()+yo+1, cr, cg, 0); + } + + // TQSimpleRichText always draws with TQColorGroup::Text as with + // background mode PaletteBase. TQLabel typically has + // background mode PaletteBackground, so we create a temporary + // color group with the text color adjusted. + TQColorGroup cg = colorGroup(); + if ( backgroundMode() != PaletteBase && isEnabled() ) + cg.setColor( TQColorGroup::Text, paletteForegroundColor() ); + + doc->draw(p, cr.x(), cr.y()+yo, cr, cg, 0); + } else +#endif +#ifndef TQT_NO_PICTURE + if ( pic ) { + TQRect br = pic->boundingRect(); + int rw = br.width(); + int rh = br.height(); + if ( scaledcontents ) { + p->save(); + p->translate( cr.x(), cr.y() ); +#ifndef TQT_NO_TRANSFORMATIONS + p->scale( (double)cr.width()/rw, (double)cr.height()/rh ); +#endif + p->drawPicture( -br.x(), -br.y(), *pic ); + p->restore(); + } else { + int xo = 0; + int yo = 0; + if ( align & AlignVCenter ) + yo = (cr.height()-rh)/2; + else if ( align & AlignBottom ) + yo = cr.height()-rh; + if ( align & AlignRight ) + xo = cr.width()-rw; + else if ( align & AlignHCenter ) + xo = (cr.width()-rw)/2; + p->drawPicture( cr.x()+xo-br.x(), cr.y()+yo-br.y(), *pic ); + } + } else +#endif + { +#ifndef TQT_NO_IMAGE_SMOOTHSCALE + if ( scaledcontents && pix ) { + if ( !d->img ) + d->img = new TQImage( lpixmap->convertToImage() ); + + if ( !d->pix ) + d->pix = new TQPixmap; + if ( d->pix->size() != cr.size() ) + d->pix->convertFromImage( d->img->smoothScale( cr.width(), cr.height() ) ); + pix = d->pix; + } +#endif + int alignment = align; + if ((align & ShowPrefix) && ((!style().styleHint(TQStyle::SH_UnderlineAccelerator, this)) || ((style().styleHint(TQStyle::SH_HideUnderlineAcceleratorWhenAltUp, this)) && (!style().acceleratorsShown())))) { + alignment |= NoAccel; + } + // ordinary text or pixmap label + style().drawItem( p, cr, alignment, colorGroup(), isEnabled(), + pix, ltext ); + } +} + + +/*! + Updates the label, but not the frame. +*/ + +void TQLabel::updateLabel( TQSize oldSizeHint ) +{ + d->valid_hints = -1; + TQSizePolicy policy = sizePolicy(); + bool wordBreak = align & WordBreak; + policy.setHeightForWidth( wordBreak ); + if ( policy != sizePolicy() ) + setSizePolicy( policy ); + if ( sizeHint() != oldSizeHint ) + updateGeometry(); + if ( autoresize ) { + adjustSize(); + update( contentsRect() ); + } else { + update( contentsRect() ); + } +} + + +/*! + \internal + + Internal slot, used to set focus for accelerator labels. +*/ +#ifndef TQT_NO_ACCEL +void TQLabel::acceleratorSlot() +{ + if ( !lbuddy ) + return; + TQWidget * w = lbuddy; + while ( w->focusProxy() ) + w = w->focusProxy(); + if ( !w->hasFocus() && + w->isEnabled() && + w->isVisible() && + w->focusPolicy() != NoFocus ) { + TQFocusEvent::setReason( TQFocusEvent::Shortcut ); + w->setFocus(); + TQFocusEvent::resetReason(); + } +} +#endif + +/*! + \internal + + Internal slot, used to clean up if the buddy widget dies. +*/ +#ifndef TQT_NO_ACCEL +void TQLabel::buddyDied() // I can't remember if I cried. +{ + lbuddy = 0; +} + +/*! + Sets this label's buddy to \a 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 TQLabels that contain + plain text in which one letter is prefixed with an ampersand, \&. + This letter is set as the accelerator key. The letter is displayed + underlined, and the '\&' is not displayed (i.e. the \c 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"), for example: + \code + TQLineEdit *nameEd = new TQLineEdit( this ); + TQLabel *nameLb = new TQLabel( "&Name:", this ); + nameLb->setBuddy( nameEd ); + TQLineEdit *phoneEd = new TQLineEdit( this ); + TQLabel *phoneLb = new TQLabel( "&Phone:", this ); + phoneLb->setBuddy( phoneEd ); + // ( layout setup not shown ) + \endcode + + 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 \a buddy + set to 0. + + \sa buddy(), setText(), TQAccel, setAlignment() +*/ + +void TQLabel::setBuddy( TQWidget *buddy ) +{ + if ( buddy ) + setAlignment( alignment() | ShowPrefix ); + else + setAlignment( alignment() & ~ShowPrefix ); + + if ( lbuddy ) + disconnect( lbuddy, TQ_SIGNAL(destroyed()), this, TQ_SLOT(buddyDied()) ); + + lbuddy = buddy; + + if ( !lbuddy ) + return; +#ifndef TQT_NO_RICHTEXT + if ( !( textformat == RichText || (textformat == AutoText && + TQStyleSheet::mightBeRichText(ltext) ) ) ) +#endif + { + int p = TQAccel::shortcutKey( ltext ); + if ( p ) { + if ( !accel ) + accel = new TQAccel( this, "accel label accel" ); + accel->connectItem( accel->insertItem( p ), + this, TQ_SLOT(acceleratorSlot()) ); + } + } + + connect( lbuddy, TQ_SIGNAL(destroyed()), this, TQ_SLOT(buddyDied()) ); +} + + +/*! + Returns this label's buddy, or 0 if no buddy is currently set. + + \sa setBuddy() +*/ + +TQWidget * TQLabel::buddy() const +{ + return lbuddy; +} +#endif //TQT_NO_ACCEL + + +#ifndef TQT_NO_MOVIE +void TQLabel::movieUpdated(const TQRect& rect) +{ + TQMovie *mov = movie(); + if ( mov && !mov->isNull() ) { + TQRect r = contentsRect(); + r = style().itemRect( 0, r, align, isEnabled(), &(mov->framePixmap()), + TQString::null ); + r.moveBy(rect.x(), rect.y()); + r.setWidth(TQMIN(r.width(), rect.width())); + r.setHeight(TQMIN(r.height(), rect.height())); + repaint( r, mov->framePixmap().mask() != 0 ); + } +} + +void TQLabel::movieResized( const TQSize& size ) +{ + d->valid_hints = -1; + if ( autoresize ) + adjustSize(); + movieUpdated( TQRect( TQPoint(0,0), size ) ); + updateGeometry(); +} + +/*! + Sets the label contents to \a movie. Any previous content is + cleared. + + The buddy accelerator, if any, is disabled. + + The label resizes itself if auto-resizing is enabled. + + \sa movie(), setBuddy() +*/ + +void TQLabel::setMovie( const TQMovie& movie ) +{ + TQSize osh = sizeHint(); + clearContents(); + + lmovie = new TQMovie( movie ); + lmovie->connectResize(this, TQ_SLOT(movieResized(const TQSize&))); + lmovie->connectUpdate(this, TQ_SLOT(movieUpdated(const TQRect&))); + + if ( !lmovie->running() ) // Assume that if the movie is running, + updateLabel( osh ); // resize/update signals will come soon enough +} + +#endif // TQT_NO_MOVIE + +/*! + \internal + + Clears any contents, without updating/repainting the label. +*/ + +void TQLabel::clearContents() +{ +#ifndef TQT_NO_RICHTEXT + delete doc; + doc = 0; +#endif + + delete lpixmap; + lpixmap = 0; +#ifndef TQT_NO_PICTURE + delete lpicture; + lpicture = 0; +#endif + delete d->img; + d->img = 0; + delete d->pix; + d->pix = 0; + + ltext = TQString::null; +#ifndef TQT_NO_ACCEL + if ( accel ) + accel->clear(); +#endif +#ifndef TQT_NO_MOVIE + if ( lmovie ) { + lmovie->disconnectResize(this, TQ_SLOT(movieResized(const TQSize&))); + lmovie->disconnectUpdate(this, TQ_SLOT(movieUpdated(const TQRect&))); + delete lmovie; + lmovie = 0; + } +#endif +} + + +#ifndef TQT_NO_MOVIE + +/*! + Returns a pointer to the label's movie, or 0 if no movie has been + set. + + \sa setMovie() +*/ + +TQMovie* TQLabel::movie() const +{ + return lmovie; +} + +#endif // TQT_NO_MOVIE + +/*! + \property TQLabel::backgroundMode + \brief the label's background mode + + Get this property with backgroundMode(). + + \sa TQWidget::setBackgroundMode() +*/ + +/*! + \property TQLabel::textFormat + \brief the label's text format + + See the \c TQt::TextFormat enum for an explanation of the possible + options. + + The default format is \c AutoText. + + \sa text +*/ + +TQt::TextFormat TQLabel::textFormat() const +{ + return textformat; +} + +void TQLabel::setTextFormat( TQt::TextFormat format ) +{ + if ( format != textformat ) { + textformat = format; + TQString t = ltext; + if ( !t.isNull() ) { + ltext = TQString::null; + setText( t ); + } + } +} + +/*! + \reimp +*/ + +void TQLabel::fontChange( const TQFont & ) +{ + if ( !ltext.isEmpty() ) { +#ifndef TQT_NO_RICHTEXT + if ( doc ) + doc->setDefaultFont( font() ); +#endif + updateLabel( TQSize( -1, -1 ) ); + } +} + +#ifndef TQT_NO_IMAGE_SMOOTHSCALE +/*! + \property TQLabel::scaledContents + \brief whether the label will scale its contents to fill all + available space. + + When enabled and the label shows a pixmap, it will scale the + pixmap to fill the available space. + + This property's default is FALSE. + + \sa setScaledContents() +*/ +bool TQLabel::hasScaledContents() const +{ + return scaledcontents; +} + +void TQLabel::setScaledContents( bool enable ) +{ + if ( (bool)scaledcontents == enable ) + return; + scaledcontents = enable; + if ( !enable ) { + delete d->img; + d->img = 0; + delete d->pix; + d->pix = 0; + } + update( contentsRect() ); +} + +#endif // TQT_NO_IMAGE_SMOOTHSCALE + +/*! + Sets the font used on the TQLabel to font \a f. +*/ + +void TQLabel::setFont( const TQFont &f ) +{ + TQFrame::setFont( f ); +} + +#endif // TQT_NO_LABEL diff --git a/src/widgets/tqlabel.h b/src/widgets/tqlabel.h new file mode 100644 index 000000000..f8d728807 --- /dev/null +++ b/src/widgets/tqlabel.h @@ -0,0 +1,174 @@ +/********************************************************************** +** +** Definition of TQLabel widget class +** +** Created : 941215 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQLABEL_H +#define TQLABEL_H + +#ifndef QT_H +#include "ntqframe.h" +#endif // QT_H + +#ifndef TQT_NO_LABEL + +class TQSimpleRichText; +class TQLabelPrivate; + +class TQ_EXPORT TQLabel : public TQFrame +{ + TQ_OBJECT + TQ_PROPERTY( TQString text READ text WRITE setText ) + TQ_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat ) + TQ_PROPERTY( TQPixmap pixmap READ pixmap WRITE setPixmap ) + TQ_PROPERTY( bool scaledContents READ hasScaledContents WRITE setScaledContents ) + TQ_PROPERTY( Alignment alignment READ alignment WRITE setAlignment ) + TQ_PROPERTY( int indent READ indent WRITE setIndent ) + TQ_OVERRIDE( BackgroundMode backgroundMode DESIGNABLE true) + +public: + TQLabel( TQWidget *parent, const char* name=0, WFlags f=0 ); + TQLabel( const TQString &text, TQWidget *parent, const char* name=0, + WFlags f=0 ); + TQLabel( TQWidget *buddy, const TQString &, + TQWidget *parent, const char* name=0, WFlags f=0 ); + ~TQLabel(); + + TQString text() const { return ltext; } + TQPixmap *pixmap() const { return lpixmap; } +#ifndef TQT_NO_PICTURE + TQPicture *picture() const { return lpicture; } +#endif +#ifndef TQT_NO_MOVIE + TQMovie *movie() const; +#endif + + TextFormat textFormat() const; + void setTextFormat( TextFormat ); + + int alignment() const { return align; } + virtual void setAlignment( int ); + int indent() const { return extraMargin; } + void setIndent( int ); + + bool autoResize() const { return autoresize; } + virtual void setAutoResize( bool ); +#ifndef TQT_NO_IMAGE_SMOOTHSCALE + bool hasScaledContents() const; + void setScaledContents( bool ); +#endif + TQSize sizeHint() const; + TQSize minimumSizeHint() const; +#ifndef TQT_NO_ACCEL + virtual void setBuddy( TQWidget * ); + TQWidget *buddy() const; +#endif + int heightForWidth(int) const; + + void setFont( const TQFont &f ); + +public slots: + virtual void setText( const TQString &); + virtual void setPixmap( const TQPixmap & ); +#ifndef TQT_NO_PICTURE + virtual void setPicture( const TQPicture & ); +#endif +#ifndef TQT_NO_MOVIE + virtual void setMovie( const TQMovie & ); +#endif + virtual void setNum( int ); + virtual void setNum( double ); + void clear(); + +protected: + void drawContents( TQPainter * ); + void fontChange( const TQFont & ); + void resizeEvent( TQResizeEvent* ); + +private slots: +#ifndef TQT_NO_ACCEL + void acceleratorSlot(); + void buddyDied(); +#endif +#ifndef TQT_NO_MOVIE + void movieUpdated(const TQRect&); + void movieResized(const TQSize&); +#endif + +private: + void init(); + void clearContents(); + void updateLabel( TQSize oldSizeHint ); + TQSize sizeForWidth( int w ) const; + TQString ltext; + TQPixmap *lpixmap; +#ifndef TQT_NO_PICTURE + TQPicture *lpicture; +#endif +#ifndef TQT_NO_MOVIE + TQMovie * lmovie; +#endif +#ifndef TQT_NO_ACCEL + TQWidget * lbuddy; +#endif + ushort align; + short extraMargin; + uint autoresize:1; + uint scaledcontents :1; + TextFormat textformat; +#ifndef TQT_NO_RICHTEXT + TQSimpleRichText* doc; +#endif +#ifndef TQT_NO_ACCEL + TQAccel * accel; +#endif + TQLabelPrivate* d; + + friend class TQTipLabel; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQLabel( const TQLabel & ); + TQLabel &operator=( const TQLabel & ); +#endif +}; + + +#endif // TQT_NO_LABEL + +#endif // TQLABEL_H diff --git a/src/widgets/tqmainwindow.cpp b/src/widgets/tqmainwindow.cpp index 071a330ff..7b66839db 100644 --- a/src/widgets/tqmainwindow.cpp +++ b/src/widgets/tqmainwindow.cpp @@ -57,7 +57,7 @@ #include "ntqscrollview.h" #include "tqtooltip.h" #include "tqdatetime.h" -#include "ntqwhatsthis.h" +#include "tqwhatsthis.h" #include "tqbitmap.h" #include "ntqdockarea.h" #include "tqstringlist.h" diff --git a/src/widgets/tqpopupmenu.cpp b/src/widgets/tqpopupmenu.cpp index 09961bf03..26aa7f9cc 100644 --- a/src/widgets/tqpopupmenu.cpp +++ b/src/widgets/tqpopupmenu.cpp @@ -48,7 +48,7 @@ #include "tqpixmap.h" #include "tqpixmapcache.h" #include "tqtimer.h" -#include "ntqwhatsthis.h" +#include "tqwhatsthis.h" #include "tqobjectlist.h" #include "ntqguardedptr.h" #include "qeffects_p.h" @@ -124,7 +124,7 @@ static void popupSubMenuLater( int msec, TQPopupMenu * receiver ) { static bool preventAnimation = FALSE; #ifndef TQT_NO_WHATSTHIS -extern void qWhatsThisBDH(); +extern void tqWhatsThisBDH(); static TQMenuItem* whatsThisItem = 0; #endif @@ -816,7 +816,7 @@ void TQPopupMenu::hideAllPopups() #ifndef TQT_NO_WHATSTHIS if (whatsThisItem) { - qWhatsThisBDH(); + tqWhatsThisBDH(); whatsThisItem = 0; } #endif @@ -2570,7 +2570,7 @@ void TQPopupMenu::setActiveItem( int i ) hilitSig( mi->id() ); #ifndef TQT_NO_WHATSTHIS if (whatsThisItem && whatsThisItem != mi) { - qWhatsThisBDH(); + tqWhatsThisBDH(); } whatsThisItem = mi; #endif diff --git a/src/widgets/tqsyntaxhighlighter.cpp b/src/widgets/tqsyntaxhighlighter.cpp new file mode 100644 index 000000000..223f7930c --- /dev/null +++ b/src/widgets/tqsyntaxhighlighter.cpp @@ -0,0 +1,221 @@ +/**************************************************************************** +** +** Implementation of the TQSyntaxHighlighter class +** +** Created : 990101 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqsyntaxhighlighter.h" +#include "private/tqsyntaxhighlighter_p.h" + +#ifndef TQT_NO_SYNTAXHIGHLIGHTER +#include "../kernel/qrichtext_p.h" +#include "tqtextedit.h" +#include "tqtimer.h" + +/*! + \class TQSyntaxHighlighter tqsyntaxhighlighter.h + \brief The TQSyntaxHighlighter class is a base class for + implementing TQTextEdit syntax highlighters. + + \ingroup basic + \ingroup text + + A syntax highligher automatically highlights parts of the text in + a TQTextEdit. Syntax highlighters are often used when the user is + entering text in a specific format (for example, source code) and + help the user to read the text and identify syntax errors. + + To provide your own syntax highlighting for TQTextEdit, you must + subclass TQSyntaxHighlighter and reimplement highlightParagraph(). + + When you create an instance of your TQSyntaxHighlighter subclass, + pass it the TQTextEdit that you want the syntax highlighting to be + applied to. After this your highlightParagraph() function will be + called automatically whenever necessary. Use your + highlightParagraph() function to apply formatting (e.g. setting + the font and color) to the text that is passed to it. +*/ + +/*! + Constructs the TQSyntaxHighlighter and installs it on \a textEdit. + + It is the caller's responsibility to delete the + TQSyntaxHighlighter when it is no longer needed. +*/ + +TQSyntaxHighlighter::TQSyntaxHighlighter( TQTextEdit *textEdit ) + : para( 0 ), edit( textEdit ), d( new TQSyntaxHighlighterPrivate ) +{ + textEdit->document()->setPreProcessor( new TQSyntaxHighlighterInternal( this ) ); + textEdit->document()->invalidate(); + TQTimer::singleShot( 0, textEdit->viewport(), TQ_SLOT( update() ) ); +} + +/*! + Destructor. Uninstalls this syntax highlighter from the textEdit() +*/ + +TQSyntaxHighlighter::~TQSyntaxHighlighter() +{ + delete d; + textEdit()->document()->setPreProcessor( 0 ); +} + +/*! + \fn int TQSyntaxHighlighter::highlightParagraph( const TQString &text, int endStateOfLastPara ) + + This function is called when necessary by the rich text engine, + i.e. on paragraphs which have changed. + + In your reimplementation you should parse the paragraph's \a text + and call setFormat() as often as necessary to apply any font and + color changes that you require. Your function must return a value + which indicates the paragraph's end state: see below. + + Some syntaxes can have constructs that span paragraphs. For + example, a C++ syntax highlighter should be able to cope with + \c{/}\c{*...*}\c{/} comments that span paragraphs. To deal + with these cases it is necessary to know the end state of the + previous paragraph (e.g. "in comment"). + + If your syntax does not have paragraph spanning constructs, simply + ignore the \a endStateOfLastPara parameter and always return 0. + + Whenever highlightParagraph() is called it is passed a value for + \a endStateOfLastPara. For the very first paragraph this value is + always -2. For any other paragraph the value is the value returned + by the most recent highlightParagraph() call that applied to the + preceding paragraph. + + The value you return is up to you. We recommend only returning 0 + (to signify that this paragraph's syntax highlighting does not + affect the following paragraph), or a positive integer (to signify + that this paragraph has ended in the middle of a paragraph + spanning construct). + + To find out which paragraph is highlighted, call + currentParagraph(). + + For example, if you're writing a simple C++ syntax highlighter, + you might designate 1 to signify "in comment". For a paragraph + that ended in the middle of a comment you'd return 1, and for + other paragraphs you'd return 0. In your parsing code if \a + endStateOfLastPara was 1, you would highlight the text as a C++ + comment until you reached the closing \c{*}\c{/}. +*/ + +/*! + This function is applied to the syntax highlighter's current + paragraph (the text of which is passed to the highlightParagraph() + function). + + The specified \a font and \a color are applied to the text from + position \a start for \a count characters. (If \a count is 0, + nothing is done.) +*/ + +void TQSyntaxHighlighter::setFormat( int start, int count, const TQFont &font, const TQColor &color ) +{ + if ( !para || count <= 0 ) + return; + TQTextFormat *f = 0; + f = para->document()->formatCollection()->format( font, color ); + para->setFormat( start, count, f ); + f->removeRef(); +} + +/*! \overload */ + +void TQSyntaxHighlighter::setFormat( int start, int count, const TQColor &color ) +{ + if ( !para || count <= 0 ) + return; + TQTextFormat *f = 0; + TQFont fnt = textEdit()->TQWidget::font(); + f = para->document()->formatCollection()->format( fnt, color ); + para->setFormat( start, count, f ); + f->removeRef(); +} + +/*! \overload */ + +void TQSyntaxHighlighter::setFormat( int start, int count, const TQFont &font ) +{ + if ( !para || count <= 0 ) + return; + TQTextFormat *f = 0; + TQColor c = textEdit()->viewport()->paletteForegroundColor(); + f = para->document()->formatCollection()->format( font, c ); + para->setFormat( start, count, f ); + f->removeRef(); +} + +/*! + \fn TQTextEdit *TQSyntaxHighlighter::textEdit() const + + Returns the TQTextEdit on which this syntax highlighter is + installed +*/ + +/*! Redoes the highlighting of the whole document. +*/ + +void TQSyntaxHighlighter::rehighlight() +{ + TQTextParagraph *s = edit->document()->firstParagraph(); + while ( s ) { + s->invalidate( 0 ); + s->state = -1; + s->needPreProcess = TRUE; + s = s->next(); + } + edit->repaintContents( FALSE ); +} + +/*! + Returns the id of the paragraph which is highlighted, or -1 of no + paragraph is currently highlighted. + + Usually this function is called from within highlightParagraph(). +*/ + +int TQSyntaxHighlighter::currentParagraph() const +{ + return d->currentParagraph; +} + +#endif diff --git a/src/widgets/tqsyntaxhighlighter.h b/src/widgets/tqsyntaxhighlighter.h new file mode 100644 index 000000000..81556553e --- /dev/null +++ b/src/widgets/tqsyntaxhighlighter.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Definition of the TQSyntaxHighlighter class +** +** Created : 022407 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQSYNTAXHIGHLIGHTER_H +#define TQSYNTAXHIGHLIGHTER_H + +#ifndef QT_H +#include "tqfont.h" +#include "tqcolor.h" +#include "tqstring.h" +#endif // QT_H + +class TQTextEdit; +class TQSyntaxHighlighterInternal; +class TQSyntaxHighlighterPrivate; +class TQTextParagraph; + +class TQ_EXPORT TQSyntaxHighlighter : public TQt +{ + friend class TQSyntaxHighlighterInternal; + +public: + TQSyntaxHighlighter( TQTextEdit *textEdit ); + virtual ~TQSyntaxHighlighter(); + + virtual int highlightParagraph( const TQString &text, int endStateOfLastPara ) = 0; + + void setFormat( int start, int count, const TQFont &font, const TQColor &color ); + void setFormat( int start, int count, const TQColor &color ); + void setFormat( int start, int count, const TQFont &font ); + TQTextEdit *textEdit() const { return edit; } + + void rehighlight(); + + int currentParagraph() const; + +private: + TQTextParagraph *para; + TQTextEdit *edit; + TQSyntaxHighlighterPrivate *d; + +}; + +#endif diff --git a/src/widgets/tqsyntaxhighlighter_p.h b/src/widgets/tqsyntaxhighlighter_p.h new file mode 100644 index 000000000..c4d7deabf --- /dev/null +++ b/src/widgets/tqsyntaxhighlighter_p.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Definition of the internal TQSyntaxHighlighterInternal class +** +** Created : 031111 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQSYNTAXHIGHLIGHTER_P_H +#define TQSYNTAXHIGHLIGHTER_P_H + +#ifndef TQT_NO_SYNTAXHIGHLIGHTER +#include "tqsyntaxhighlighter.h" +#include "private/qrichtext_p.h" + +class TQSyntaxHighlighterPrivate +{ +public: + TQSyntaxHighlighterPrivate() : + currentParagraph( -1 ) + {} + + int currentParagraph; +}; + +class TQSyntaxHighlighterInternal : public TQTextPreProcessor +{ +public: + TQSyntaxHighlighterInternal( TQSyntaxHighlighter *h ) : highlighter( h ) {} + void process( TQTextDocument *doc, TQTextParagraph *p, int, bool invalidate ) { + if ( p->prev() && p->prev()->endState() == -1 ) + process( doc, p->prev(), 0, FALSE ); + + highlighter->para = p; + TQString text = p->string()->toString(); + int endState = p->prev() ? p->prev()->endState() : -2; + int oldEndState = p->endState(); + highlighter->d->currentParagraph = p->paragId(); + p->setEndState( highlighter->highlightParagraph( text, endState ) ); + highlighter->d->currentParagraph = -1; + highlighter->para = 0; + + p->setFirstPreProcess( FALSE ); + TQTextParagraph *op = p; + p = p->next(); + if ( (!!oldEndState || !!op->endState()) && oldEndState != op->endState() && + invalidate && p && !p->firstPreProcess() && p->endState() != -1 ) { + while ( p ) { + if ( p->endState() == -1 ) + return; + p->setEndState( -1 ); + p = p->next(); + } + } + } + TQTextFormat *format( int ) { return 0; } + +private: + TQSyntaxHighlighter *highlighter; + + friend class TQTextEdit; +}; + +#endif // TQT_NO_SYNTAXHIGHLIGHTER +#endif // TQSYNTAXHIGHLIGHTER_P_H diff --git a/src/widgets/tqtextbrowser.cpp b/src/widgets/tqtextbrowser.cpp index fd4bced0a..1409a20ff 100644 --- a/src/widgets/tqtextbrowser.cpp +++ b/src/widgets/tqtextbrowser.cpp @@ -54,7 +54,7 @@ #include "tqbitmap.h" #include "tqtimer.h" #include "tqimage.h" -#include "ntqsimplerichtext.h" +#include "tqsimplerichtext.h" #include "tqdragobject.h" #include "tqurl.h" #include "ntqcursor.h" diff --git a/src/widgets/tqtextedit.cpp b/src/widgets/tqtextedit.cpp index a0887cb5d..9ef0752a7 100644 --- a/src/widgets/tqtextedit.cpp +++ b/src/widgets/tqtextedit.cpp @@ -75,7 +75,7 @@ #include "ntqmetaobject.h" #include "tqtextbrowser.h" #include -#include "private/qsyntaxhighlighter_p.h" +#include "private/tqsyntaxhighlighter_p.h" #include #ifndef TQT_NO_ACCEL diff --git a/src/widgets/tqtooltip.cpp b/src/widgets/tqtooltip.cpp index 6a048f5e1..7a9166452 100644 --- a/src/widgets/tqtooltip.cpp +++ b/src/widgets/tqtooltip.cpp @@ -38,7 +38,7 @@ #include "tqtooltip.h" #ifndef TQT_NO_TOOLTIP -#include "ntqlabel.h" +#include "tqlabel.h" #include "tqptrdict.h" #include "ntqapplication.h" #include "ntqguardedptr.h" diff --git a/src/widgets/tqwhatsthis.cpp b/src/widgets/tqwhatsthis.cpp new file mode 100644 index 000000000..1328c49ea --- /dev/null +++ b/src/widgets/tqwhatsthis.cpp @@ -0,0 +1,1001 @@ +/**************************************************************************** +** +** Implementation of TQWhatsThis class +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqwhatsthis.h" +#ifndef TQT_NO_WHATSTHIS +#include "ntqapplication.h" +#include "tqpaintdevicemetrics.h" +#include "tqpixmap.h" +#include "tqpainter.h" +#include "tqtimer.h" +#include "tqptrdict.h" +#include "tqtoolbutton.h" +#include "ntqshared.h" +#include "ntqcursor.h" +#include "tqbitmap.h" +#include "tqtooltip.h" +#include "tqsimplerichtext.h" +#include "tqstylesheet.h" +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif +#if defined(TQ_WS_WIN) +#include "qt_windows.h" +#ifndef SPI_GETDROPSHADOW +#define SPI_GETDROPSHADOW 0x1024 +#endif +#endif + +/*! + \class TQWhatsThis tqwhatsthis.h + \brief The TQWhatsThis class provides a simple description of any + widget, i.e. answering the question "What's this?". + + \ingroup helpsystem + \mainclass + + "What's this?" help is part of an application's online help system + that provides users with information about functionality, usage, + background etc., in various levels of detail from short tool tips + to full text browsing help windows. + + TQWhatsThis provides a single window with an explanatory text that + pops up when the user asks "What's this?". The default way to do + this is to focus the relevant widget and press Shift+F1. The help + text appears immediately; it goes away as soon as the user does + something else. + + (Note that if there is an accelerator for Shift+F1, this mechanism + will not work.) + + To add "What's this?" text to a widget you simply call + TQWhatsThis::add() for the widget. For example, to assign text to a + menu item, call TQMenuData::setWhatsThis(); for a global + accelerator key, call TQAccel::setWhatsThis() and If you're using + actions, use TQAction::setWhatsThis(). + + The text can be either rich text or plain text. If you specify a + rich text formatted string, it will be rendered using the default + stylesheet. This makes it possible to embed images. See + TQStyleSheet::defaultSheet() for details. + + \quotefile action/application.cpp + \skipto fileOpenText + \printuntil setWhatsThis + + An alternative way to enter "What's this?" mode is to use the + ready-made tool bar tool button from + TQWhatsThis::whatsThisButton(). By invoking this context help + button (in the picture below the first one from the right) the + user switches into "What's this?" mode. If they now click on a + widget the appropriate help text is shown. The mode is left when + help is given or when the user presses Esc. + + \img whatsthis.png + + If you are using TQMainWindow you can also use the + TQMainWindow::whatsThis() slot to invoke the mode from a menu item. + + For more control you can create a dedicated TQWhatsThis object for + a special widget. By subclassing and reimplementing + TQWhatsThis::text() it is possible to have different help texts, + depending on the position of the mouse click. By reimplementing + TQWhatsThis::clicked() it is possible to have hyperlinks inside the + help texts. + + If you wish to control the "What's this?" behavior of a widget + manually see TQWidget::customWhatsThis(). + + The What's This object can be removed using TQWhatsThis::remove(), + although this is rarely necessary because it is automatically + removed when the widget is destroyed. + + \sa TQToolTip +*/ + +// a special button +class TQWhatsThisButton: public TQToolButton +{ + TQ_OBJECT + +public: + TQWhatsThisButton( TQWidget * parent, const char * name ); + ~TQWhatsThisButton(); + +public slots: + void mouseReleased(); + +}; + + +class TQWhatsThat : public TQWidget +{ + TQ_OBJECT +public: + TQWhatsThat( TQWidget* w, const TQString& txt, TQWidget* parent, const char* name ); + ~TQWhatsThat() ; + +public slots: + void hide(); + inline void widgetDestroyed() { widget = 0; } + +protected: + void mousePressEvent( TQMouseEvent* ); + void mouseReleaseEvent( TQMouseEvent* ); + void mouseMoveEvent( TQMouseEvent* ); + void keyPressEvent( TQKeyEvent* ); + void paintEvent( TQPaintEvent* ); + +private: + TQString text; +#ifndef TQT_NO_RICHTEXT + TQSimpleRichText* doc; +#endif + TQString anchor; + bool pressed; + TQWidget* widget; +}; + + +class TQWhatsThisPrivate: public TQObject +{ + TQ_OBJECT +public: + + // an item for storing texts + struct WhatsThisItem: public TQShared + { + WhatsThisItem(): TQShared() { whatsthis = 0; } + ~WhatsThisItem(); + TQString s; + TQWhatsThis* whatsthis; + }; + + // the (these days pretty small) state machine + enum State { Inactive, Waiting }; + + TQWhatsThisPrivate(); + ~TQWhatsThisPrivate(); + + bool eventFilter( TQObject *, TQEvent * ); + + WhatsThisItem* newItem( TQWidget * widget ); + void add( TQWidget * widget, TQWhatsThis* special ); + void add( TQWidget * widget, const TQString& text ); + + // say it. + void say( TQWidget *, const TQString&, const TQPoint& ); + + // setup and teardown + static void setUpWhatsThis(); + + void enterWhatsThisMode(); + void leaveWhatsThisMode(); + + // variables + TQWhatsThat * whatsThat; + TQPtrDict * dict; + TQPtrDict * tlw; + TQPtrDict * buttons; + State state; + +private slots: + void cleanupWidget() + { + const TQObject* o = sender(); + if ( o->isWidgetType() ) // sanity + TQWhatsThis::remove((TQWidget*)o); + } + +}; + +// static, but static the less-typing way +static TQWhatsThisPrivate * wt = 0; + +// shadowWidth not const, for XP drop-shadow-fu turns it to 0 +static int shadowWidth = 6; // also used as '5' and '6' and even '8' below +const int vMargin = 8; +const int hMargin = 12; + +// Lets TQPopupMenu destroy the TQWhatsThat. +void tqWhatsThisBDH() +{ + if ( wt && wt->whatsThat ) + wt->whatsThat->hide(); +} + + +TQWhatsThat::TQWhatsThat( TQWidget* w, const TQString& txt, TQWidget* parent, const char* name ) + : TQWidget( parent, name, WType_Popup ), text( txt ), pressed( FALSE ), widget( w ) +{ + + setBackgroundMode( NoBackground ); + setPalette( TQToolTip::palette() ); + setMouseTracking( TRUE ); +#ifndef TQT_NO_CURSOR + setCursor( arrowCursor ); +#endif + + if ( widget ) + connect( widget, TQ_SIGNAL( destroyed() ), this, TQ_SLOT( widgetDestroyed() ) ); + + + TQRect r; +#ifndef TQT_NO_RICHTEXT + doc = 0; + if ( TQStyleSheet::mightBeRichText( text ) ) { + TQFont f = TQApplication::font( this ); + doc = new TQSimpleRichText( text, f ); + doc->adjustSize(); + r.setRect( 0, 0, doc->width(), doc->height() ); + } + else +#endif + { + int sw = TQApplication::desktop()->width() / 3; + if ( sw < 200 ) + sw = 200; + else if ( sw > 300 ) + sw = 300; + + r = fontMetrics().boundingRect( 0, 0, sw, 1000, + AlignAuto + AlignTop + WordBreak + ExpandTabs, + text ); + } +#if defined(TQ_WS_WIN) + if ( (qWinVersion()&WV_NT_based) > WV_2000 ) { + BOOL shadow; + SystemParametersInfo( SPI_GETDROPSHADOW, 0, &shadow, 0 ); + shadowWidth = shadow ? 0 : 6; + } +#endif + resize( r.width() + 2*hMargin + shadowWidth, r.height() + 2*vMargin + shadowWidth ); +} + +TQWhatsThat::~TQWhatsThat() +{ + if ( wt && wt->whatsThat == this ) + wt->whatsThat = 0; +#ifndef TQT_NO_RICHTEXT + if ( doc ) + delete doc; +#endif +} + +void TQWhatsThat::hide() +{ + TQWidget::hide(); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ContextHelpEnd ); +#endif +} + +void TQWhatsThat::mousePressEvent( TQMouseEvent* e ) +{ + pressed = TRUE; + if ( e->button() == LeftButton && rect().contains( e->pos() ) ) { +#ifndef TQT_NO_RICHTEXT + if ( doc ) + anchor = doc->anchorAt( e->pos() - TQPoint( hMargin, vMargin) ); +#endif + return; + } + hide(); +} + +void TQWhatsThat::mouseReleaseEvent( TQMouseEvent* e ) +{ + if ( !pressed ) + return; +#ifndef TQT_NO_RICHTEXT + if ( e->button() == LeftButton && doc && rect().contains( e->pos() ) ) { + TQString a = doc->anchorAt( e->pos() - TQPoint( hMargin, vMargin ) ); + TQString href; + if ( anchor == a ) + href = a; + anchor = TQString::null; + if ( widget && wt && wt->dict ) { + TQWhatsThisPrivate::WhatsThisItem * i = wt->dict->find( widget ); + if ( i && i->whatsthis && !i->whatsthis->clicked( href ) ) + return; + } + } +#endif + hide(); +} + +void TQWhatsThat::mouseMoveEvent( TQMouseEvent* e) +{ +#ifndef TQT_NO_RICHTEXT +#ifndef TQT_NO_CURSOR + if ( !doc ) + return; + TQString a = doc->anchorAt( e->pos() - TQPoint( hMargin, vMargin ) ); + if ( !a.isEmpty() ) + setCursor( pointingHandCursor ); + else + setCursor( arrowCursor ); +#endif +#endif +} + + +void TQWhatsThat::keyPressEvent( TQKeyEvent* ) +{ + hide(); +} + + + +void TQWhatsThat::paintEvent( TQPaintEvent* ) +{ + bool drawShadow = TRUE; +#if defined(TQ_WS_WIN) + if ( (qWinVersion()&WV_NT_based) > WV_2000 ) { + BOOL shadow; + SystemParametersInfo( SPI_GETDROPSHADOW, 0, &shadow, 0 ); + drawShadow = !shadow; + } +#elif defined(TQ_WS_MACX) + drawShadow = FALSE; //never draw it on OS X we get it for free +#endif + + TQRect r = rect(); + if ( drawShadow ) + r.addCoords( 0, 0, -shadowWidth, -shadowWidth ); + TQPainter p( this); + p.setPen( colorGroup().foreground() ); + p.drawRect( r ); + p.setPen( colorGroup().mid() ); + p.setBrush( colorGroup().brush( TQColorGroup::Background ) ); + int w = r.width(); + int h = r.height(); + p.drawRect( 1, 1, w-2, h-2 ); + if ( drawShadow ) { + p.setPen( colorGroup().shadow() ); + p.drawPoint( w + 5, 6 ); + p.drawLine( w + 3, 6, w + 5, 8 ); + p.drawLine( w + 1, 6, w + 5, 10 ); + int i; + for( i=7; i < h; i += 2 ) + p.drawLine( w, i, w + 5, i + 5 ); + for( i = w - i + h; i > 6; i -= 2 ) + p.drawLine( i, h, i + 5, h + 5 ); + for( ; i > 0 ; i -= 2 ) + p.drawLine( 6, h + 6 - i, i + 5, h + 5 ); + } + p.setPen( colorGroup().foreground() ); + r.addCoords( hMargin, vMargin, -hMargin, -vMargin ); + +#ifndef TQT_NO_RICHTEXT + if ( doc ) { + doc->draw( &p, r.x(), r.y(), r, colorGroup(), 0 ); + } + else +#endif + { + p.drawText( r, AlignAuto + AlignTop + WordBreak + ExpandTabs, text ); + } +} + +// the item +TQWhatsThisPrivate::WhatsThisItem::~WhatsThisItem() +{ + if ( count ) + tqFatal( "TQWhatsThis: Internal error (%d)", count ); + delete whatsthis; +} + + +static const char * const button_image[] = { +"16 16 3 1", +" c None", +"o c #000000", +"a c #000080", +"o aaaaa ", +"oo aaa aaa ", +"ooo aaa aaa", +"oooo aa aa", +"ooooo aa aa", +"oooooo a aaa", +"ooooooo aaa ", +"oooooooo aaa ", +"ooooooooo aaa ", +"ooooo aaa ", +"oo ooo ", +"o ooo aaa ", +" ooo aaa ", +" ooo ", +" ooo ", +" ooo "}; + +// the button class +TQWhatsThisButton::TQWhatsThisButton( TQWidget * parent, const char * name ) + : TQToolButton( parent, name ) +{ + TQPixmap p( (const char**)button_image ); + setPixmap( p ); + setToggleButton( TRUE ); + setAutoRaise( TRUE ); + setFocusPolicy( NoFocus ); + setTextLabel( tr( "What's this?" ) ); + wt->buttons->insert( (void *)this, this ); + connect( this, TQ_SIGNAL( released() ), + this, TQ_SLOT( mouseReleased() ) ); +} + + +TQWhatsThisButton::~TQWhatsThisButton() +{ + if ( wt && wt->buttons ) + wt->buttons->take( (void *)this ); +} + + +void TQWhatsThisButton::mouseReleased() +{ + if ( wt->state == TQWhatsThisPrivate::Inactive && isOn() ) { + TQWhatsThisPrivate::setUpWhatsThis(); +#ifndef TQT_NO_CURSOR + TQApplication::setOverrideCursor( whatsThisCursor, FALSE ); +#endif + wt->state = TQWhatsThisPrivate::Waiting; + tqApp->installEventFilter( wt ); + } +} + +static void tqWhatsThisPrivateCleanup() +{ + if( wt ) { + delete wt; + wt = 0; + } +} + +// the what's this manager class +TQWhatsThisPrivate::TQWhatsThisPrivate() + : TQObject( 0, "global what's this object" ) +{ + whatsThat = 0; + dict = new TQPtrDict; + tlw = new TQPtrDict; + wt = this; + buttons = new TQPtrDict; + state = Inactive; +} + +TQWhatsThisPrivate::~TQWhatsThisPrivate() +{ +#ifndef TQT_NO_CURSOR + if ( state == Waiting && tqApp ) + TQApplication::restoreOverrideCursor(); +#endif + // the two straight-and-simple dicts + delete tlw; + delete buttons; + + // then delete the complex one. + TQPtrDictIterator it( *dict ); + WhatsThisItem * i; + TQWidget * w; + while( (i=it.current()) != 0 ) { + w = (TQWidget *)it.currentKey(); + ++it; + dict->take( w ); + if ( i->deref() ) + delete i; + } + delete dict; + if ( whatsThat && !whatsThat->parentWidget() ) { + delete whatsThat; + } + // and finally lose wt + wt = 0; +} + +bool TQWhatsThisPrivate::eventFilter( TQObject * o, TQEvent * e ) +{ + switch( state ) { + case Waiting: + if ( e->type() == TQEvent::MouseButtonPress && o->isWidgetType() ) { + TQWidget * w = (TQWidget *) o; + if ( ( (TQMouseEvent*)e)->button() == RightButton ) + return FALSE; // ignore RMB + if ( w->customWhatsThis() ) + return FALSE; + TQWhatsThisPrivate::WhatsThisItem * i = 0; + TQMouseEvent* me = (TQMouseEvent*) e; + TQPoint p = me->pos(); + while( w && !i ) { + i = dict->find( w ); + if ( !i ) { + p += w->pos(); + w = w->parentWidget( TRUE ); + } + } + leaveWhatsThisMode(); + if (!i ) { +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ContextHelpEnd ); +#endif + return TRUE; + } + if ( i->whatsthis ) + say( w, i->whatsthis->text( p ), me->globalPos() ); + else + say( w, i->s, me->globalPos() ); + return TRUE; + } else if ( e->type() == TQEvent::MouseButtonRelease ) { + if ( ( (TQMouseEvent*)e)->button() == RightButton ) + return FALSE; // ignore RMB + return !o->isWidgetType() || !((TQWidget*)o)->customWhatsThis(); + } else if ( e->type() == TQEvent::MouseMove ) { + return !o->isWidgetType() || !((TQWidget*)o)->customWhatsThis(); + } else if ( e->type() == TQEvent::KeyPress ) { + TQKeyEvent* kev = (TQKeyEvent*)e; + + if ( kev->key() == TQt::Key_Escape ) { + leaveWhatsThisMode(); + return TRUE; + } else if ( o->isWidgetType() && ((TQWidget*)o)->customWhatsThis() ) { + return FALSE; + } else if ( kev->key() == Key_Menu || + ( kev->key() == Key_F10 && + kev->state() == ShiftButton ) ) { + // we don't react to these keys, they are used for context menus + return FALSE; + } else if ( kev->state() == kev->stateAfter() && + kev->key() != Key_Meta ) { // not a modifier key + leaveWhatsThisMode(); + } + } else if ( e->type() == TQEvent::MouseButtonDblClick ) { + return TRUE; + } + break; + case Inactive: + if ( e->type() == TQEvent::Accel && + ((TQKeyEvent *)e)->key() == Key_F1 && + o->isWidgetType() && + ((TQKeyEvent *)e)->state() == ShiftButton ) { + TQWidget * w = ((TQWidget *)o)->focusWidget(); + if ( !w ) + break; + TQString s = TQWhatsThis::textFor( w, TQPoint(0,0), TRUE ); + if ( !s.isNull() ) { + say ( w, s, w->mapToGlobal( w->rect().center() ) ); + ((TQKeyEvent *)e)->accept(); + return TRUE; + } + } + break; + } + return FALSE; +} + + + +void TQWhatsThisPrivate::setUpWhatsThis() +{ + if ( !wt ) { + wt = new TQWhatsThisPrivate(); + + // It is necessary to use a post routine, because + // the destructor deletes pixmaps and other stuff that + // needs a working X connection under X11. + tqAddPostRoutine( tqWhatsThisPrivateCleanup ); + } +} + + +void TQWhatsThisPrivate::enterWhatsThisMode() +{ +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ContextHelpStart ); +#endif +} + + +void TQWhatsThisPrivate::leaveWhatsThisMode() +{ + if ( state == Waiting ) { + TQPtrDictIterator it( *(wt->buttons) ); + TQWhatsThisButton * b; + while( (b=it.current()) != 0 ) { + ++it; + b->setOn( FALSE ); + } +#ifndef TQT_NO_CURSOR + TQApplication::restoreOverrideCursor(); +#endif + state = Inactive; + tqApp->removeEventFilter( this ); + } +} + + + +void TQWhatsThisPrivate::say( TQWidget * widget, const TQString &text, const TQPoint& ppos) +{ + if ( text.isEmpty() ) + return; + // make a fresh widget, and set it up + delete whatsThat; + whatsThat = new TQWhatsThat( + widget, text, +#if defined(TQ_WS_X11) + TQApplication::desktop()->screen( widget ? + widget->x11Screen() : + TQCursor::x11Screen() ), +#else + 0, +#endif + "automatic what's this? widget" ); + + + // okay, now to find a suitable location + + int scr = ( widget ? + TQApplication::desktop()->screenNumber( widget ) : +#if defined(TQ_WS_X11) + TQCursor::x11Screen() +#else + TQApplication::desktop()->screenNumber( ppos ) +#endif // TQ_WS_X11 + ); + TQRect screen = TQApplication::desktop()->screenGeometry( scr ); + + int x; + int w = whatsThat->width(); + int h = whatsThat->height(); + int sx = screen.x(); + int sy = screen.y(); + + // first try locating the widget immediately above/below, + // with nice alignment if possible. + TQPoint pos; + if ( widget ) + pos = widget->mapToGlobal( TQPoint( 0,0 ) ); + + if ( widget && w > widget->width() + 16 ) + x = pos.x() + widget->width()/2 - w/2; + else + x = ppos.x() - w/2; + + // squeeze it in if that would result in part of what's this + // being only partially visible + if ( x + w + shadowWidth > sx+screen.width() ) + x = (widget? (TQMIN(screen.width(), + pos.x() + widget->width()) + ) : screen.width() ) + - w; + + if ( x < sx ) + x = sx; + + int y; + if ( widget && h > widget->height() + 16 ) { + y = pos.y() + widget->height() + 2; // below, two pixels spacing + // what's this is above or below, wherever there's most space + if ( y + h + 10 > sy+screen.height() ) + y = pos.y() + 2 - shadowWidth - h; // above, overlap + } + y = ppos.y() + 2; + + // squeeze it in if that would result in part of what's this + // being only partially visible + if ( y + h + shadowWidth > sy+screen.height() ) + y = ( widget ? (TQMIN(screen.height(), + pos.y() + widget->height()) + ) : screen.height() ) + - h; + if ( y < sy ) + y = sy; + + whatsThat->move( x, y ); + whatsThat->show(); +} + +TQWhatsThisPrivate::WhatsThisItem* TQWhatsThisPrivate::newItem( TQWidget * widget ) +{ + WhatsThisItem * i = dict->find( (void *)widget ); + if ( i ) + TQWhatsThis::remove( widget ); + i = new WhatsThisItem; + dict->insert( (void *)widget, i ); + TQWidget * t = widget->topLevelWidget(); + if ( !tlw->find( (void *)t ) ) { + tlw->insert( (void *)t, t ); + t->installEventFilter( this ); + } + connect( widget, TQ_SIGNAL(destroyed()), this, TQ_SLOT(cleanupWidget()) ); + return i; +} + +void TQWhatsThisPrivate::add( TQWidget * widget, TQWhatsThis* special ) +{ + newItem( widget )->whatsthis = special; +} + +void TQWhatsThisPrivate::add( TQWidget * widget, const TQString &text ) +{ + newItem( widget )->s = text; +} + + +// and finally the What's This class itself + +/*! + Adds \a text as "What's this" help for \a widget. If the text is + rich text formatted (i.e. it contains markup) it will be rendered + with the default stylesheet TQStyleSheet::defaultSheet(). + + The text is destroyed if the widget is later destroyed, so it need + not be explicitly removed. + + \sa remove() +*/ +void TQWhatsThis::add( TQWidget * widget, const TQString &text ) +{ + if ( text.isEmpty() ) + return; // pointless + TQWhatsThisPrivate::setUpWhatsThis(); + wt->add(widget,text); +} + + +/*! + Removes the "What's this?" help associated with the \a widget. + This happens automatically if the widget is destroyed. + + \sa add() +*/ +void TQWhatsThis::remove( TQWidget * widget ) +{ + TQWhatsThisPrivate::setUpWhatsThis(); + TQWhatsThisPrivate::WhatsThisItem * i = wt->dict->find( (void *)widget ); + if ( !i ) + return; + + wt->dict->take( (void *)widget ); + + i->deref(); + if ( !i->count ) + delete i; +} + + +/*! + Returns the what's this text for widget \a w or TQString::null if + there is no "What's this?" help for the widget. \a pos contains + the mouse position; this is useful, for example, if you've + subclassed to make the text that is displayed position dependent. + + If \a includeParents is TRUE, parent widgets are taken into + consideration as well when looking for what's this help text. + + \sa add() +*/ +TQString TQWhatsThis::textFor( TQWidget * w, const TQPoint& pos, bool includeParents ) +{ + TQWhatsThisPrivate::setUpWhatsThis(); + TQWhatsThisPrivate::WhatsThisItem * i = 0; + TQPoint p = pos; + while( w && !i ) { + i = wt->dict->find( w ); + if ( !includeParents ) + break; + if ( !i ) { + p += w->pos(); + w = w->parentWidget( TRUE ); + } + } + if (!i) + return TQString::null; + if ( i->whatsthis ) + return i->whatsthis->text( p ); + return i->s; +} + + +/*! + Creates a TQToolButton preconfigured to enter "What's this?" mode + when clicked. You will often use this with a tool bar as \a + parent: + \code + (void) TQWhatsThis::whatsThisButton( my_help_tool_bar ); + \endcode +*/ +TQToolButton * TQWhatsThis::whatsThisButton( TQWidget * parent ) +{ + TQWhatsThisPrivate::setUpWhatsThis(); + return new TQWhatsThisButton( parent, + "automatic what's this? button" ); +} + +/*! + Constructs a dynamic "What's this?" object for \a widget. The + object is deleted when the \a widget is destroyed. + + When the widget is queried by the user the text() function of this + TQWhatsThis will be called to provide the appropriate text, rather + than using the text assigned by add(). +*/ +TQWhatsThis::TQWhatsThis( TQWidget * widget) +{ + TQWhatsThisPrivate::setUpWhatsThis(); + wt->add(widget,this); +} + + +/*! + Destroys the object and frees any allocated resources. +*/ +TQWhatsThis::~TQWhatsThis() +{ +} + + +/*! + This virtual function returns the text for position \e p in the + widget that this "What's this?" object documents. If there is no + "What's this?" text for the position, TQString::null is returned. + + The default implementation returns TQString::null. +*/ +TQString TQWhatsThis::text( const TQPoint & ) +{ + return TQString::null; +} + +/*! + \fn bool TQWhatsThis::clicked( const TQString& href ) + + This virtual function is called when the user clicks inside the + "What's this?" window. \a href is the link the user clicked on, or + TQString::null if there was no link. + + If the function returns TRUE (the default), the "What's this?" + window is closed, otherwise it remains visible. + + The default implementation ignores \a href and returns TRUE. +*/ +bool TQWhatsThis::clicked( const TQString& ) +{ + return TRUE; +} + + +/*! + Enters "What's this?" mode and returns immediately. + + TQt will install a special cursor and take over mouse input until + the user clicks somewhere. It then shows any help available and + ends "What's this?" mode. Finally, TQt removes the special cursor + and help window and then restores ordinary event processing, at + which point the left mouse button is no longer pressed. + + The user can also use the Esc key to leave "What's this?" mode. + + \sa inWhatsThisMode(), leaveWhatsThisMode() +*/ + +void TQWhatsThis::enterWhatsThisMode() +{ + TQWhatsThisPrivate::setUpWhatsThis(); + if ( wt->state == TQWhatsThisPrivate::Inactive ) { + wt->enterWhatsThisMode(); +#ifndef TQT_NO_CURSOR + TQApplication::setOverrideCursor( whatsThisCursor, FALSE ); +#endif + wt->state = TQWhatsThisPrivate::Waiting; + tqApp->installEventFilter( wt ); + } +} + + +/*! + Returns TRUE if the application is in "What's this?" mode; + otherwise returns FALSE. + + \sa enterWhatsThisMode(), leaveWhatsThisMode() +*/ +bool TQWhatsThis::inWhatsThisMode() +{ + if (!wt) + return FALSE; + return wt->state == TQWhatsThisPrivate::Waiting; +} + + +/*! + Leaves "What's this?" question mode. + + This function is used internally by widgets that support + TQWidget::customWhatsThis(); applications do not usually call it. + An example of such a widget is TQPopupMenu: menus still work + normally in "What's this?" mode but also provide help texts for + individual menu items. + + If \a text is not TQString::null, a "What's this?" help window is + displayed at the global screen position \a pos. If widget \a w is + not 0 and has its own dedicated TQWhatsThis object, this object + will receive clicked() messages when the user clicks on hyperlinks + inside the help text. + + \sa inWhatsThisMode(), enterWhatsThisMode(), TQWhatsThis::clicked() +*/ +void TQWhatsThis::leaveWhatsThisMode( const TQString& text, const TQPoint& pos, TQWidget* w ) +{ + if ( !inWhatsThisMode() ) + return; + + wt->leaveWhatsThisMode(); + if ( !text.isNull() ) + wt->say( w, text, pos ); +} + +/*! + Display \a text in a help window at the global screen position \a + pos. + + If widget \a w is not 0 and has its own dedicated TQWhatsThis + object, this object will receive clicked() messages when the user + clicks on hyperlinks inside the help text. + + \sa TQWhatsThis::clicked() +*/ +void TQWhatsThis::display( const TQString& text, const TQPoint& pos, TQWidget* w ) +{ + if ( inWhatsThisMode() ) { + leaveWhatsThisMode( text, pos, w ); + return; + } + TQWhatsThisPrivate::setUpWhatsThis(); + wt->say( w, text, pos ); +} + +/*! + Sets the font for all "What's this?" helps to \a font. +*/ +void TQWhatsThis::setFont( const TQFont &font ) +{ + TQApplication::setFont( font, TRUE, "TQWhatsThat" ); +} + +#include "tqwhatsthis.moc" +#endif diff --git a/src/widgets/tqwhatsthis.h b/src/widgets/tqwhatsthis.h new file mode 100644 index 000000000..66b4b3c90 --- /dev/null +++ b/src/widgets/tqwhatsthis.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Definition of TQWhatsThis class +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the widgets module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQWHATSTHIS_H +#define TQWHATSTHIS_H + +#ifndef QT_H +#include "tqobject.h" +#endif // QT_H + +#ifndef TQT_NO_WHATSTHIS + +#include "ntqcursor.h" + +class TQToolButton; +class TQPopupMenu; +class TQStyleSheet; + +class TQ_EXPORT TQWhatsThis: public TQt +{ +public: + TQWhatsThis( TQWidget *); + virtual ~TQWhatsThis(); + + virtual TQString text( const TQPoint & ); + virtual bool clicked( const TQString& href ); + + // the common static functions + static void setFont( const TQFont &font ); + + static void add( TQWidget *, const TQString &); + static void remove( TQWidget * ); + static TQString textFor( TQWidget *, const TQPoint & pos = TQPoint(), bool includeParents = FALSE ); + + static TQToolButton * whatsThisButton( TQWidget * parent ); + + static void enterWhatsThisMode(); + static bool inWhatsThisMode(); + static void leaveWhatsThisMode( const TQString& = TQString::null, const TQPoint& pos = TQCursor::pos(), TQWidget* w = 0 ); + + static void display( const TQString& text, const TQPoint& pos = TQCursor::pos(), TQWidget* w = 0 ); +}; + +#endif // TQT_NO_WHATSTHIS + +#endif // TQWHATSTHIS_H -- cgit v1.2.3