From fef846914f8db6dc117e206ef913d519bf6bb33e Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 29 Jul 2024 12:43:23 +0900 Subject: Rename basic widget nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/canvas/tqcanvas.h | 2 +- src/dialogs/ntqdialog.h | 141 -- src/dialogs/ntqerrormessage.h | 2 +- src/dialogs/ntqinputdialog.h | 4 +- src/dialogs/ntqmessagebox.h | 2 +- src/dialogs/ntqprintdialog.h | 2 +- src/dialogs/ntqprogressdialog.h | 2 +- src/dialogs/ntqtabdialog.h | 2 +- src/dialogs/ntqwizard.h | 2 +- src/dialogs/qdialog.cpp | 1180 ---------------- src/dialogs/qerrormessage.cpp | 4 +- src/dialogs/qinputdialog.cpp | 8 +- src/dialogs/qmessagebox.cpp | 2 +- src/dialogs/qprintdialog.cpp | 10 +- src/dialogs/qprogressdialog.cpp | 2 +- src/dialogs/qt_dialogs.pri | 4 +- src/dialogs/qtabdialog.cpp | 2 +- src/dialogs/qwizard.cpp | 2 +- src/dialogs/tqcolordialog.cpp | 4 +- src/dialogs/tqcolordialog.h | 2 +- src/dialogs/tqdialog.cpp | 1180 ++++++++++++++++ src/dialogs/tqdialog.h | 141 ++ src/dialogs/tqfiledialog.cpp | 8 +- src/dialogs/tqfiledialog.h | 2 +- src/dialogs/tqfontdialog.cpp | 8 +- src/dialogs/tqfontdialog.h | 2 +- src/kernel/ntqt.h | 26 +- src/kernel/tqstyle.cpp | 2 +- src/kernel/tqwidget_x11.cpp | 2 +- src/libqt.map | 2 +- src/sql/tqeditorfactory.cpp | 6 +- src/sql/tqsqleditorfactory.cpp | 6 +- src/styles/qcommonstyle.cpp | 18 +- src/styles/qinterlacestyle.cpp | 4 +- src/styles/qmotifplusstyle.cpp | 16 +- src/styles/qmotifstyle.cpp | 8 +- src/styles/qplatinumstyle.cpp | 8 +- src/styles/qsgistyle.cpp | 10 +- src/styles/qwindowsstyle.cpp | 8 +- src/table/ntqtable.h | 2 +- src/table/qtable.cpp | 8 +- src/tools/qfeatures.txt | 4 +- src/widgets/ntqcheckbox.h | 96 -- src/widgets/ntqcombobox.h | 206 --- src/widgets/ntqdial.h | 153 -- src/widgets/ntqgridview.h | 2 +- src/widgets/ntqlcdnumber.h | 146 -- src/widgets/ntqlineedit.h | 218 --- src/widgets/ntqlistbox.h | 2 +- src/widgets/ntqlistview.h | 2 +- src/widgets/ntqpushbutton.h | 149 -- src/widgets/ntqradiobutton.h | 91 -- src/widgets/ntqscrollbar.h | 197 --- src/widgets/ntqscrollview.h | 269 ---- src/widgets/ntqslider.h | 199 --- src/widgets/ntqspinbox.h | 172 --- src/widgets/qbutton.cpp | 4 +- src/widgets/qbuttongroup.cpp | 2 +- src/widgets/qcheckbox.cpp | 364 ----- src/widgets/qcombobox.cpp | 2338 ------------------------------- src/widgets/qdial.cpp | 976 ------------- src/widgets/qdialogbuttons.cpp | 462 ------- src/widgets/qdialogbuttons_p.h | 119 -- src/widgets/qeffects.cpp | 2 +- src/widgets/qeffects_p.h | 2 +- src/widgets/qgroupbox.cpp | 4 +- src/widgets/qlcdnumber.cpp | 1170 ---------------- src/widgets/qlineedit.cpp | 2922 --------------------------------------- src/widgets/qlistview.cpp | 2 +- src/widgets/qmultilineedit.cpp | 2 +- src/widgets/qpushbutton.cpp | 762 ---------- src/widgets/qradiobutton.cpp | 358 ----- src/widgets/qscrollbar.cpp | 1074 -------------- src/widgets/qscrollview.cpp | 2847 -------------------------------------- src/widgets/qslider.cpp | 924 ------------- src/widgets/qspinbox.cpp | 1116 --------------- src/widgets/qspinwidget.cpp | 467 ------- src/widgets/qt_widgets.pri | 50 +- src/widgets/tqaction.cpp | 2 +- src/widgets/tqcheckbox.cpp | 364 +++++ src/widgets/tqcheckbox.h | 96 ++ src/widgets/tqcombobox.cpp | 2338 +++++++++++++++++++++++++++++++ src/widgets/tqcombobox.h | 206 +++ src/widgets/tqdial.cpp | 976 +++++++++++++ src/widgets/tqdial.h | 153 ++ src/widgets/tqdialogbuttons.cpp | 462 +++++++ src/widgets/tqdialogbuttons_p.h | 119 ++ src/widgets/tqiconview.h | 2 +- src/widgets/tqlcdnumber.cpp | 1170 ++++++++++++++++ src/widgets/tqlcdnumber.h | 146 ++ src/widgets/tqlineedit.cpp | 2922 +++++++++++++++++++++++++++++++++++++++ src/widgets/tqlineedit.h | 218 +++ src/widgets/tqmainwindow.cpp | 2 +- src/widgets/tqpushbutton.cpp | 762 ++++++++++ src/widgets/tqpushbutton.h | 149 ++ src/widgets/tqradiobutton.cpp | 358 +++++ src/widgets/tqradiobutton.h | 91 ++ src/widgets/tqscrollbar.cpp | 1074 ++++++++++++++ src/widgets/tqscrollbar.h | 197 +++ src/widgets/tqscrollview.cpp | 2847 ++++++++++++++++++++++++++++++++++++++ src/widgets/tqscrollview.h | 269 ++++ src/widgets/tqslider.cpp | 924 +++++++++++++ src/widgets/tqslider.h | 199 +++ src/widgets/tqspinbox.cpp | 1116 +++++++++++++++ src/widgets/tqspinbox.h | 172 +++ src/widgets/tqspinwidget.cpp | 467 +++++++ src/widgets/tqtextedit.h | 2 +- src/widgets/tqtoolbar.cpp | 2 +- src/widgets/tqtoolbox.cpp | 2 +- src/workspace/tqworkspace.cpp | 2 +- 110 files changed, 19264 insertions(+), 19264 deletions(-) delete mode 100644 src/dialogs/ntqdialog.h delete mode 100644 src/dialogs/qdialog.cpp create mode 100644 src/dialogs/tqdialog.cpp create mode 100644 src/dialogs/tqdialog.h delete mode 100644 src/widgets/ntqcheckbox.h delete mode 100644 src/widgets/ntqcombobox.h delete mode 100644 src/widgets/ntqdial.h delete mode 100644 src/widgets/ntqlcdnumber.h delete mode 100644 src/widgets/ntqlineedit.h delete mode 100644 src/widgets/ntqpushbutton.h delete mode 100644 src/widgets/ntqradiobutton.h delete mode 100644 src/widgets/ntqscrollbar.h delete mode 100644 src/widgets/ntqscrollview.h delete mode 100644 src/widgets/ntqslider.h delete mode 100644 src/widgets/ntqspinbox.h delete mode 100644 src/widgets/qcheckbox.cpp delete mode 100644 src/widgets/qcombobox.cpp delete mode 100644 src/widgets/qdial.cpp delete mode 100644 src/widgets/qdialogbuttons.cpp delete mode 100644 src/widgets/qdialogbuttons_p.h delete mode 100644 src/widgets/qlcdnumber.cpp delete mode 100644 src/widgets/qlineedit.cpp delete mode 100644 src/widgets/qpushbutton.cpp delete mode 100644 src/widgets/qradiobutton.cpp delete mode 100644 src/widgets/qscrollbar.cpp delete mode 100644 src/widgets/qscrollview.cpp delete mode 100644 src/widgets/qslider.cpp delete mode 100644 src/widgets/qspinbox.cpp delete mode 100644 src/widgets/qspinwidget.cpp create mode 100644 src/widgets/tqcheckbox.cpp create mode 100644 src/widgets/tqcheckbox.h create mode 100644 src/widgets/tqcombobox.cpp create mode 100644 src/widgets/tqcombobox.h create mode 100644 src/widgets/tqdial.cpp create mode 100644 src/widgets/tqdial.h create mode 100644 src/widgets/tqdialogbuttons.cpp create mode 100644 src/widgets/tqdialogbuttons_p.h create mode 100644 src/widgets/tqlcdnumber.cpp create mode 100644 src/widgets/tqlcdnumber.h create mode 100644 src/widgets/tqlineedit.cpp create mode 100644 src/widgets/tqlineedit.h create mode 100644 src/widgets/tqpushbutton.cpp create mode 100644 src/widgets/tqpushbutton.h create mode 100644 src/widgets/tqradiobutton.cpp create mode 100644 src/widgets/tqradiobutton.h create mode 100644 src/widgets/tqscrollbar.cpp create mode 100644 src/widgets/tqscrollbar.h create mode 100644 src/widgets/tqscrollview.cpp create mode 100644 src/widgets/tqscrollview.h create mode 100644 src/widgets/tqslider.cpp create mode 100644 src/widgets/tqslider.h create mode 100644 src/widgets/tqspinbox.cpp create mode 100644 src/widgets/tqspinbox.h create mode 100644 src/widgets/tqspinwidget.cpp (limited to 'src') diff --git a/src/canvas/tqcanvas.h b/src/canvas/tqcanvas.h index e6dbb685f..c8c8fe18d 100644 --- a/src/canvas/tqcanvas.h +++ b/src/canvas/tqcanvas.h @@ -42,7 +42,7 @@ #define TQCANVAS_H #ifndef QT_H -#include "ntqscrollview.h" +#include "tqscrollview.h" #include "tqpixmap.h" #include "tqptrlist.h" #include "tqbrush.h" diff --git a/src/dialogs/ntqdialog.h b/src/dialogs/ntqdialog.h deleted file mode 100644 index e1d82c179..000000000 --- a/src/dialogs/ntqdialog.h +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** -** Definition of TQDialog class -** -** Created : 950502 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs 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 TQDIALOG_H -#define TQDIALOG_H - -#ifndef QT_H -#include "tqwidget.h" -#endif // QT_H -#ifndef TQT_NO_DIALOG -#if 0 -TQ_OBJECT -#endif - -class TQPushButton; -class TQDialogPrivate; - -class TQ_EXPORT TQDialog : public TQWidget -{ -friend class TQPushButton; - TQ_OBJECT - TQ_PROPERTY( bool sizeGripEnabled READ isSizeGripEnabled WRITE setSizeGripEnabled ) - TQ_PROPERTY( bool modal READ isModal WRITE setModal ) - -public: - Q_EXPLICIT TQDialog( TQWidget* parent=0, const char* name=0, bool modal=FALSE, - WFlags f=0 ); - ~TQDialog(); - - enum DialogCode { Rejected, Accepted }; - - int result() const { return rescode; } - - void show(); - void hide(); - void move( int x, int y ); - void move( const TQPoint &p ); - void resize( int w, int h ); - void resize( const TQSize & ); - void setGeometry( int x, int y, int w, int h ); - void setGeometry( const TQRect & ); - - void setOrientation( Orientation orientation ); - Orientation orientation() const; - - void setExtension( TQWidget* extension ); - TQWidget* extension() const; - - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - - void setSizeGripEnabled( bool ); - bool isSizeGripEnabled() const; - - void setModal( bool modal ); - bool isModal() const; -#ifdef Q_OS_TEMP - bool event( TQEvent * ); -#endif - -public slots: - int exec(); - -protected slots: - virtual void done( int ); - virtual void accept(); - virtual void reject(); - - void showExtension( bool ); - -protected: - void setResult( int r ) { rescode = r; } - void keyPressEvent( TQKeyEvent * ); - void closeEvent( TQCloseEvent * ); - void resizeEvent( TQResizeEvent * ); - void contextMenuEvent( TQContextMenuEvent * ); - bool eventFilter( TQObject *, TQEvent * ); - void adjustPosition( TQWidget*); - -private: - void setDefault( TQPushButton * ); - void setMainDefault( TQPushButton * ); - void hideDefault(); -#ifdef Q_OS_TEMP - void hideSpecial(); -#endif - - int rescode; - uint did_move : 1; - uint has_relpos : 1; - uint did_resize : 1; - uint in_loop: 1; - void adjustPositionInternal( TQWidget*, bool useRelPos = FALSE ); - TQDialogPrivate* d; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQDialog( const TQDialog & ); - TQDialog &operator=( const TQDialog & ); -#endif -}; - -#endif // TQT_NO_DIALOG -#endif // TQDIALOG_H diff --git a/src/dialogs/ntqerrormessage.h b/src/dialogs/ntqerrormessage.h index 6c776d2d5..21e12a488 100644 --- a/src/dialogs/ntqerrormessage.h +++ b/src/dialogs/ntqerrormessage.h @@ -42,7 +42,7 @@ #define TQERRORMESSAGE_H #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #endif // QT_H #ifndef TQT_NO_ERRORMESSAGE diff --git a/src/dialogs/ntqinputdialog.h b/src/dialogs/ntqinputdialog.h index 32ba9c2ba..67434b3ae 100644 --- a/src/dialogs/ntqinputdialog.h +++ b/src/dialogs/ntqinputdialog.h @@ -42,9 +42,9 @@ #define TQINPUTDIALOG_H #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #include "tqstring.h" -#include "ntqlineedit.h" +#include "tqlineedit.h" #endif // QT_H #ifndef TQT_NO_INPUTDIALOG diff --git a/src/dialogs/ntqmessagebox.h b/src/dialogs/ntqmessagebox.h index b4fc27d8f..abaf25761 100644 --- a/src/dialogs/ntqmessagebox.h +++ b/src/dialogs/ntqmessagebox.h @@ -42,7 +42,7 @@ #define TQMESSAGEBOX_H #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #endif // QT_H #ifndef TQT_NO_MESSAGEBOX diff --git a/src/dialogs/ntqprintdialog.h b/src/dialogs/ntqprintdialog.h index c578e0ff3..29824416a 100644 --- a/src/dialogs/ntqprintdialog.h +++ b/src/dialogs/ntqprintdialog.h @@ -42,7 +42,7 @@ #define TQPRINTDIALOG_H #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #endif // QT_H #ifndef TQT_NO_PRINTDIALOG diff --git a/src/dialogs/ntqprogressdialog.h b/src/dialogs/ntqprogressdialog.h index dc32aa390..af20f615b 100644 --- a/src/dialogs/ntqprogressdialog.h +++ b/src/dialogs/ntqprogressdialog.h @@ -42,7 +42,7 @@ #define TQPROGRESSDIALOG_H #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #include "tqlabel.h" // ### remove or keep for users' convenience? #include "ntqprogressbar.h" // ### remove or keep for users' convenience? #endif // QT_H diff --git a/src/dialogs/ntqtabdialog.h b/src/dialogs/ntqtabdialog.h index 7547b2f58..61e4287c6 100644 --- a/src/dialogs/ntqtabdialog.h +++ b/src/dialogs/ntqtabdialog.h @@ -42,7 +42,7 @@ #define TQTABDIALOG_H #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #include "tqiconset.h" #endif // QT_H diff --git a/src/dialogs/ntqwizard.h b/src/dialogs/ntqwizard.h index b09e90202..c680e2860 100644 --- a/src/dialogs/ntqwizard.h +++ b/src/dialogs/ntqwizard.h @@ -43,7 +43,7 @@ #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #endif // QT_H #ifndef TQT_NO_WIZARD diff --git a/src/dialogs/qdialog.cpp b/src/dialogs/qdialog.cpp deleted file mode 100644 index 9f1f624a9..000000000 --- a/src/dialogs/qdialog.cpp +++ /dev/null @@ -1,1180 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQDialog class -** -** Created : 950502 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs 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 "ntqdialog.h" - -#ifndef TQT_NO_DIALOG - -#include "ntqpushbutton.h" -#include "ntqfocusdata.h" -#include "ntqapplication.h" -#include "tqobjectlist.h" -#include "tqwidgetlist.h" -#include "ntqlayout.h" -#include "tqsizegrip.h" -#include "tqwhatsthis.h" -#include "tqpopupmenu.h" -#include "ntqcursor.h" -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif -#if defined( Q_OS_TEMP ) -#include "qt_windows.h" -#endif - -/*! - \class TQDialog - \brief The TQDialog class is the base class of dialog windows. - - \ingroup dialogs - \ingroup abstractwidgets - \mainclass - - A dialog window is a top-level window mostly used for short-term - tasks and brief communications with the user. TQDialogs may be - modal or modeless. TQDialogs support \link #extensibility - extensibility\endlink and can provide a \link #return return - value\endlink. They can have \link #default default - buttons\endlink. TQDialogs can also have a TQSizeGrip in their - lower-right corner, using setSizeGripEnabled(). - - Note that TQDialog uses the parent widget slightly differently from - other classes in TQt. A dialog is always a top-level widget, but if - it has a parent, its default location is centered on top of the - parent's top-level widget (if it is not top-level itself). It will - also share the parent's taskbar entry. - - \target modal - \section1 Modal Dialogs - - A modal dialog is a dialog that blocks input to other - visible windows in the same application. Users must finish - interacting with the dialog and close it before they can access - any other window in the application. Dialogs that are used to - request a file name from the user or that are used to set - application preferences are usually modal. - - The most common way to display a modal dialog is to call its - exec() function. When the user closes the dialog, exec() will - provide a useful \link #return return value\endlink. Typically we - connect a default button, e.g. "OK", to the accept() slot and a - "Cancel" button to the reject() slot, to get the dialog to close - and return the appropriate value. Alternatively you can connect to - the done() slot, passing it \c Accepted or \c Rejected. - - An alternative is to call setModal(TRUE), then show(). Unlike - exec(), show() returns control to the caller immediately. Calling - setModal(TRUE) is especially useful for progress dialogs, where - the user must have the ability to interact with the dialog, e.g. - to cancel a long running operation. If you use show() and - setModal(TRUE) together you must call - TQApplication::processEvents() periodically during processing to - enable the user to interact with the dialog. (See \l - TQProgressDialog.) - - \target modeless - \section1 Modeless Dialogs - - A modeless dialog is a dialog that operates - independently of other windows in the same application. Find and - replace dialogs in word-processors are often modeless to allow the - user to interact with both the application's main window and with - the dialog. - - Modeless dialogs are displayed using show(), which returns control - to the caller immediately. - - \target default - \section1 Default button - - A dialog's \e default button is the button that's pressed when the - user presses Enter (Return). This button is used to signify that - the user accepts the dialog's settings and wants to close the - dialog. Use TQPushButton::setDefault(), TQPushButton::isDefault() - and TQPushButton::autoDefault() to set and control the dialog's - default button. - - \target escapekey - \section1 Escape Key - - If the user presses the Esc key in a dialog, TQDialog::reject() - will be called. This will cause the window to close: the \link - TQCloseEvent closeEvent \endlink cannot be \link - TQCloseEvent::ignore() ignored \endlink. - - \target extensibility - \section1 Extensibility - - Extensibility is the ability to show the dialog in two ways: a - partial dialog that shows the most commonly used options, and a - full dialog that shows all the options. Typically an extensible - dialog will initially appear as a partial dialog, but with a - "More" toggle button. If the user presses the "More" button down, - the full dialog will appear. The extension widget will be resized - to its sizeHint(). If orientation is \c Horizontal the extension - widget's height() will be expanded to the height() of the dialog. - If the orientation is \c Vertical the extension widget's width() - will be expanded to the width() of the dialog. Extensibility is - controlled with setExtension(), setOrientation() and - showExtension(). - - \target return - \section1 Return value (modal dialogs) - - Modal dialogs are often used in situations where a return value is - required, e.g. to indicate whether the user pressed "OK" or - "Cancel". A dialog can be closed by calling the accept() or the - reject() slots, and exec() will return \c Accepted or \c Rejected - as appropriate. The exec() call returns the result of the dialog. - The result is also available from result() if the dialog has not - been destroyed. If the \c WDestructiveClose flag is set, the - dialog is deleted after exec() returns. - - \target examples - \section1 Examples - - A modal dialog. - - \quotefile network/networkprotocol/view.cpp - \skipto TQFileDialog *dlg - \printuntil return - - A modeless dialog. After the show() call, control returns to the main - event loop. - \quotefile life/main.cpp - \skipto argv - \printuntil TQApplication - \skipto scale - \printline - \skipto LifeDialog - \printuntil show - \skipto exec - \printuntil } - - \sa TQTabDialog TQWidget TQProgressDialog - \link guibooks.html#fowler GUI Design Handbook: Dialogs, Standard\endlink -*/ - -/*! \enum TQDialog::DialogCode - - The value returned by a modal dialog. - - \value Accepted - \value Rejected - -*/ - -/*! - \property TQDialog::sizeGripEnabled - \brief whether the size grip is enabled - - A TQSizeGrip is placed in the bottom right corner of the dialog when this - property is enabled. By default, the size grip is disabled. -*/ - -class TQDialogPrivate : public TQt -{ -public: - - TQDialogPrivate() - : mainDef(0), orientation(Horizontal),extension(0), doShowExtension(FALSE) -#ifndef TQT_NO_SIZEGRIP - ,resizer(0) -#endif - { - } - - TQPushButton* mainDef; - Orientation orientation; - TQWidget* extension; - bool doShowExtension; - TQSize size, min, max; -#ifndef TQT_NO_SIZEGRIP - TQSizeGrip* resizer; -#endif - TQPoint lastRMBPress; - TQPoint relPos; // relative position to the main window -}; - -/*! - Constructs a dialog called \a name, with parent \a parent. - - A dialog is always a top-level widget, but if it has a parent, its - default location is centered on top of the parent. It will also - share the parent's taskbar entry. - - The widget flags \a f are passed on to the TQWidget constructor. - If, for example, you don't want a What's This button in the titlebar - of the dialog, pass WStyle_Customize | WStyle_NormalBorder | - WStyle_Title | WStyle_SysMenu in \a f. - - \warning In TQt 3.2, the \a modal flag is obsolete. There is now a - setModal() function that can be used for obtaining a modal behavior - when calling show(). This is rarely needed, because modal dialogs - are usually invoked using exec(), which ignores the \a modal flag. - - \sa TQWidget::setWFlags() TQt::WidgetFlags -*/ - -TQDialog::TQDialog( TQWidget *parent, const char *name, bool modal, WFlags f ) - : TQWidget( parent, name, - (modal ? (f|WShowModal) : f) | WType_Dialog ), - rescode(0), did_move(0), has_relpos(0), did_resize(0), in_loop(0) -{ - d = new TQDialogPrivate; -} - -/*! - Destroys the TQDialog, deleting all its children. -*/ - -TQDialog::~TQDialog() -{ - // Need to hide() here, as our (to-be) overridden hide() - // will not be called in ~TQWidget. - hide(); - delete d; -} - -/*! - \internal - This function is called by the push button \a pushButton when it - becomes the default button. If \a pushButton is 0, the dialogs - default default button becomes the default button. This is what a - push button calls when it loses focus. -*/ - -void TQDialog::setDefault( TQPushButton *pushButton ) -{ -#ifndef TQT_NO_PUSHBUTTON - TQObjectList *list = queryList( "TQPushButton" ); - Q_ASSERT(list); - TQObjectListIt it( *list ); - TQPushButton *pb; - bool hasMain = FALSE; - while ( (pb = (TQPushButton*)it.current()) ) { - ++it; - if ( pb->topLevelWidget() != this ) - continue; - if ( pb == d->mainDef ) - hasMain = TRUE; - if ( pb != pushButton ) - pb->setDefault( FALSE ); - } - if (!pushButton && hasMain) - d->mainDef->setDefault( TRUE ); - if (!hasMain) - d->mainDef = pushButton; - delete list; -#endif -} - -/*! - \internal - This function sets the default default pushbutton to \a pushButton. - This function is called by TQPushButton::setDefault(). -*/ -void TQDialog::setMainDefault( TQPushButton *pushButton ) -{ -#ifndef TQT_NO_PUSHBUTTON - d->mainDef = 0; - setDefault(pushButton); -#endif -} - -/*! - \internal - Hides the default button indicator. Called when non auto-default - push button get focus. - */ -void TQDialog::hideDefault() -{ -#ifndef TQT_NO_PUSHBUTTON - TQObjectList *list = queryList( "TQPushButton" ); - TQObjectListIt it( *list ); - TQPushButton *pb; - while ( (pb = (TQPushButton*)it.current()) ) { - ++it; - pb->setDefault( FALSE ); - } - delete list; -#endif -} - -#ifdef Q_OS_TEMP -/*! - \internal - Hides special buttons which are rather shown in the titlebar - on WinCE, to conserve screen space. -*/ -# include "ntqmessagebox.h" -extern const char * mb_texts[]; // Defined in qmessagebox.cpp -void TQDialog::hideSpecial() -{ - // "OK" buttons are hidden, and (Ok) shown on titlebar - // "Cancel" buttons are hidden, and (X) shown on titlebar - // "Help" buttons are hidden, and (?) shown on titlebar - bool showOK = FALSE, - showX = FALSE, - showQ = FALSE; - TQObjectList *list = queryList( "TQPushButton" ); - TQObjectListIt it( *list ); - TQPushButton *pb; - while ( (pb = (TQPushButton*)it.current()) ) { - if ( !showOK && - pb->text() == tqApp->translate( "TQMessageBox", mb_texts[TQMessageBox::Ok] ) ) { - pb->hide(); - showOK = TRUE; - } else if ( !showX && - pb->text() == tqApp->translate( "TQMessageBox", mb_texts[TQMessageBox::Cancel] ) ) { - pb->hide(); - showX = TRUE; - } else if ( !showQ && - pb->text() == tqApp->tr("Help") ) { - pb->hide(); - showQ = TRUE; - } - ++it; - } - delete list; - if ( showOK || showQ ) { - DWORD ext = GetWindowLong( winId(), GWL_EXSTYLE ); - ext |= showOK ? WS_EX_CAPTIONOKBTN : 0; - ext |= showQ ? WS_EX_CONTEXTHELP: 0; - SetWindowLong( winId(), GWL_EXSTYLE, ext ); - } - if ( !showX ) { - DWORD ext = GetWindowLong( winId(), GWL_STYLE ); - ext &= ~WS_SYSMENU; - SetWindowLong( winId(), GWL_STYLE, ext ); - } -} -#endif - -/*! - \fn int TQDialog::result() const - - Returns the modal dialog's result code, \c Accepted or \c Rejected. - - Do not call this function if the dialog was constructed with the \c - WDestructiveClose flag. -*/ - -/*! - \fn void TQDialog::setResult( int i ) - - Sets the modal dialog's result code to \a i. -*/ - - -/*! - Shows the dialog as a \link #modal modal \endlink dialog, - blocking until the user closes it. The function returns a \l - DialogCode result. - - Users cannot interact with any other window in the same - application until they close the dialog. - - \sa show(), result() -*/ - -int TQDialog::exec() -{ - if ( in_loop ) { - tqWarning( "TQDialog::exec: Recursive call detected" ); - return -1; - } - - bool destructiveClose = testWFlags( WDestructiveClose ); - clearWFlags( WDestructiveClose ); - - bool wasShowModal = testWFlags( WShowModal ); - setWFlags( WShowModal ); - setResult( 0 ); - - show(); - - in_loop = TRUE; - tqApp->enter_loop(); - - if ( !wasShowModal ) - clearWFlags( WShowModal ); - - int res = result(); - - if ( destructiveClose ) - delete this; - - return res; -} - - -/*! Closes the dialog and sets its result code to \a r. If this dialog - is shown with exec(), done() causes the local event loop to finish, - and exec() to return \a r. - - As with TQWidget::close(), done() deletes the dialog if the \c - WDestructiveClose flag is set. If the dialog is the application's - main widget, the application terminates. If the dialog is the - last window closed, the TQApplication::lastWindowClosed() signal is - emitted. - - \sa accept(), reject(), TQApplication::mainWidget(), TQApplication::quit() -*/ - -void TQDialog::done( int r ) -{ - hide(); - setResult( r ); - - // emulate TQWidget::close() - bool isMain = tqApp->mainWidget() == this; - bool checkLastWindowClosed = isTopLevel() && !isPopup(); - if ( checkLastWindowClosed - && tqApp->receivers(TQ_SIGNAL(lastWindowClosed())) ) { - /* if there is no non-withdrawn top level window left (except - the desktop, popups, or dialogs with parents), we emit the - lastWindowClosed signal */ - TQWidgetList *list = tqApp->topLevelWidgets(); - TQWidget *widget = list->first(); - while ( widget ) { - if ( !widget->isHidden() - && !widget->isDesktop() - && !widget->isPopup() - && (!widget->isDialog() || !widget->parentWidget())) - break; - widget = list->next(); - } - delete list; - if ( widget == 0 ) - emit tqApp->lastWindowClosed(); - } - if ( isMain ) - tqApp->quit(); - else if ( testWFlags(WDestructiveClose) ) { - clearWFlags(WDestructiveClose); - deleteLater(); - } -} - -/*! - Hides the modal dialog and sets the result code to \c Accepted. - - \sa reject() done() -*/ - -void TQDialog::accept() -{ - done( Accepted ); -} - -/*! - Hides the modal dialog and sets the result code to \c Rejected. - - \sa accept() done() -*/ - -void TQDialog::reject() -{ - done( Rejected ); -} - -/*! \reimp */ -bool TQDialog::eventFilter( TQObject *o, TQEvent *e ) -{ - return TQWidget::eventFilter( o, e ); -} - -/***************************************************************************** - Event handlers - *****************************************************************************/ - -/*! \reimp */ -void TQDialog::contextMenuEvent( TQContextMenuEvent *e ) -{ -#if !defined(TQT_NO_WHATSTHIS) && !defined(TQT_NO_POPUPMENU) - TQWidget* w = childAt( e->pos(), TRUE ); - if ( !w ) - return; - TQString s; - while ( s.isEmpty() && w ) { - s = TQWhatsThis::textFor( w, e->pos(), FALSE ); - if ( s.isEmpty() ) - w = w->parentWidget(TRUE); - } - if ( !s.isEmpty() ) { - TQPopupMenu p(0,"qt_whats_this_menu"); - p.insertItem( tr("What's This?"), 42 ); - if ( p.exec( e->globalPos() ) >= 42 ) - TQWhatsThis::display( s, w->mapToGlobal( w->rect().center() ), w ); - } -#endif -} - -/*! \reimp */ -void TQDialog::keyPressEvent( TQKeyEvent *e ) -{ - // Calls reject() if Escape is pressed. Simulates a button - // click for the default button if Enter is pressed. Move focus - // for the arrow keys. Ignore the rest. -#ifdef Q_OS_MAC - if(e->state() == ControlButton && e->key() == Key_Period) { - reject(); - } else -#endif - if ( e->state() == 0 || ( e->state() & Keypad && e->key() == Key_Enter ) ) { - switch ( e->key() ) { - case Key_Enter: - case Key_Return: { -#ifndef TQT_NO_PUSHBUTTON - TQObjectList *list = queryList( "TQPushButton" ); - TQObjectListIt it( *list ); - TQPushButton *pb; - while ( (pb = (TQPushButton*)it.current()) ) { - if ( pb->isDefault() && pb->isVisible() ) { - delete list; - if ( pb->isEnabled() ) { - emit pb->clicked(); - } - return; - } - ++it; - } - delete list; -#endif - } - break; - case Key_Escape: - reject(); - break; - case Key_Up: - case Key_Left: - if ( focusWidget() && - ( focusWidget()->focusPolicy() == TQWidget::StrongFocus || - focusWidget()->focusPolicy() == TQWidget::WheelFocus ) ) { - e->ignore(); - break; - } - // call ours, since c++ blocks us from calling the one - // belonging to focusWidget(). - TQFocusEvent::setReason(TQFocusEvent::Backtab); - focusNextPrevChild( FALSE ); - TQFocusEvent::resetReason(); - break; - case Key_Down: - case Key_Right: - if ( focusWidget() && - ( focusWidget()->focusPolicy() == TQWidget::StrongFocus || - focusWidget()->focusPolicy() == TQWidget::WheelFocus ) ) { - e->ignore(); - break; - } - TQFocusEvent::setReason(TQFocusEvent::Tab); - focusNextPrevChild( TRUE ); - TQFocusEvent::resetReason(); - break; - default: - e->ignore(); - return; - } - } else { - e->ignore(); - } -} - -/*! \reimp */ -void TQDialog::closeEvent( TQCloseEvent *e ) -{ -#ifndef TQT_NO_WHATSTHIS - if ( isModal() && TQWhatsThis::inWhatsThisMode() ) - TQWhatsThis::leaveWhatsThisMode(); -#endif - if ( isShown() ) - reject(); - if ( isHidden() ) - e->accept(); -} - -#ifdef Q_OS_TEMP -/*! \internal - \reimp -*/ -bool TQDialog::event( TQEvent *e ) -{ - switch ( e->type() ) { - case TQEvent::OkRequest: - case TQEvent::HelpRequest: - { - TQString bName = - (e->type() == TQEvent::OkRequest) - ? tqApp->translate( "TQMessageBox", mb_texts[TQMessageBox::Ok] ) - : tqApp->tr( "Help" ); - - TQObjectList *list = queryList( "TQPushButton" ); - TQObjectListIt it( *list ); - TQPushButton *pb; - while ( (pb = (TQPushButton*)it.current()) ) { - if ( pb->text() == bName ) { - delete list; - if ( pb->isEnabled() ) - emit pb->clicked(); - return pb->isEnabled(); - } - ++it; - } - delete list; - } - } - return TQWidget::event( e ); -} -#endif - - -/***************************************************************************** - Geometry management. - *****************************************************************************/ - -#if defined(TQ_WS_X11) -extern "C" { int XSetTransientForHint( Display *, unsigned long, unsigned long ); } -#include -#undef FocusIn -// defined in qapplication_x11.cpp -extern Atom qt_net_wm_full_placement; -extern bool qt_net_supports(Atom atom); -#endif // TQ_WS_X11 - -/*! - Shows the dialog as a \link #modeless modeless \endlink dialog. - Control returns immediately to the calling code. - - The dialog will be modal or modeless according to the value - of the \l modal property. - - \sa exec(), modal -*/ - -void TQDialog::show() -{ - if ( testWState(WState_Visible) ) - return; - - uint state = windowState(); - - if ( !did_resize ) - adjustSize(); - if( !qt_net_supports( qt_net_wm_full_placement )) { - if ( has_relpos && !did_move ) { - adjustPositionInternal( parentWidget(), TRUE ); - } else if ( !did_move ) { - adjustPositionInternal( parentWidget() ); - } - } - - if (windowState() != state) - setWindowState(state); - -#if defined(TQ_WS_X11) - if (!parentWidget() && testWFlags(WShowModal) - && tqApp->mainWidget() && tqApp->mainWidget()->isVisible() - && !tqApp->mainWidget()->isMinimized()) { - // make sure the transient for hint is set properly for modal dialogs - x11SetWindowTransient( tqApp->mainWidget()); - } -#endif // TQ_WS_X11 - -#ifdef Q_OS_TEMP - hideSpecial(); -#endif - - TQWidget::show(); - showExtension( d->doShowExtension ); -#ifndef TQT_NO_PUSHBUTTON - TQWidget *fw = focusWidget(); - TQFocusData *fd = focusData(); - - /* - The following block is to handle a special case, and does not - really follow propper logic in concern of autoDefault and TAB - order. However, it's here to ease usage for the users. If a - dialog has a default TQPushButton, and first widget in the TAB - order also is a TQPushButton, then we give focus to the main - default TQPushButton. This simplifies code for the developers, - and actually catches most cases... If not, then they simply - have to use [widget*]->setFocus() themselves... - */ - if ( !fw || fw->focusPolicy() == NoFocus ) { - fd->home(); // Skip main form - TQWidget *first = fd->next(); // Get first main widget - if ( d->mainDef && - first != d->mainDef && - ::tqt_cast(first) ) - d->mainDef->setFocus(); - } - - if ( !d->mainDef && isTopLevel() ) { - if ( !fw || fw->focusPolicy() == NoFocus ) { - focusNextPrevChild( TRUE ); - fw = focusWidget(); - } - if ( fw ) { - fd = focusData(); - TQWidget *home = fd->home(); - TQWidget *candidate = home; - Q_ASSERT( candidate == fw ); - do { - TQPushButton *pb = ::tqt_cast(candidate); - if ( pb && pb->autoDefault() ) { - pb->setDefault( TRUE ); - break; - } - candidate = fd->next(); - } while ( candidate != home ); - } - } - if ( fw ) { - TQFocusEvent e( TQEvent::FocusIn ); - TQFocusEvent::setReason( TQFocusEvent::Tab ); - TQApplication::sendEvent( fw, &e ); - TQFocusEvent::resetReason(); - } - -#endif -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::DialogStart ); -#endif -} - -/*! \internal */ -void TQDialog::adjustPosition( TQWidget* w) -{ - adjustPositionInternal( w ); -} - - -void TQDialog::adjustPositionInternal( TQWidget*w, bool useRelPos) -{ - /* need to make sure these events are already sent to be sure - our information below is correct --sam */ - TQApplication::sendPostedEvents( this, TQEvent::LayoutHint ); - TQApplication::sendPostedEvents( this, TQEvent::Resize ); - - // processing the events might call polish(), which is a nice place - // to restore geometries, so return if the dialog has been positioned - if ( did_move || has_relpos ) - return; - - TQPoint p( 0, 0 ); - int extraw = 0, extrah = 0, scrn = 0; - if ( w ) - w = w->topLevelWidget(); - TQRect desk; - if ( w ) { - // Use mapToGlobal rather than geometry() in case w might - // be embedded in another application - scrn = TQApplication::desktop()->screenNumber( w->mapToGlobal( TQPoint(0,0) ) ); - } else if ( TQApplication::desktop()->isVirtualDesktop() ) { - scrn = TQApplication::desktop()->screenNumber( TQCursor::pos() ); - } else { - scrn = TQApplication::desktop()->screenNumber( this ); - } - desk = TQApplication::desktop()->availableGeometry( scrn ); - - TQWidgetList *list = TQApplication::topLevelWidgets(); - TQWidgetListIt it( *list ); - while ( (extraw == 0 || extrah == 0) && - it.current() != 0 ) { - int framew, frameh; - TQWidget * current = it.current(); - ++it; - if ( ! current->isVisible() ) - continue; - - framew = current->geometry().x() - current->x(); - frameh = current->geometry().y() - current->y(); - - extraw = TQMAX( extraw, framew ); - extrah = TQMAX( extrah, frameh ); - } - delete list; - - // sanity check for decoration frames. With embedding, we - // might get extraordinary values - if ( extraw == 0 || extrah == 0 || extraw >= 10 || extrah >= 40 ) { - extrah = 40; - extraw = 10; - } - - if ( useRelPos && w ) { - p = w->pos() + d->relPos; - } else { -#ifndef Q_OS_TEMP - if ( w ) { - // Use mapToGlobal rather than geometry() in case w might - // be embedded in another application - TQPoint pp = w->mapToGlobal( TQPoint(0,0) ); - p = TQPoint( pp.x() + w->width()/2, - pp.y() + w->height()/ 2 ); - } else { - // p = middle of the desktop - p = TQPoint( desk.x() + desk.width()/2, desk.y() + desk.height()/2 ); - } -#else - p = TQPoint( desk.x() + desk.width()/2, desk.y() + desk.height()/2 ); -#endif - - // p = origin of this - p = TQPoint( p.x()-width()/2 - extraw, - p.y()-height()/2 - extrah ); - } - - - if ( p.x() + extraw + width() > desk.x() + desk.width() ) - p.setX( desk.x() + desk.width() - width() - extraw ); - if ( p.x() < desk.x() ) - p.setX( desk.x() ); - - if ( p.y() + extrah + height() > desk.y() + desk.height() ) - p.setY( desk.y() + desk.height() - height() - extrah ); - if ( p.y() < desk.y() ) - p.setY( desk.y() ); - - move( p ); - did_move = !useRelPos; -} - - -/*! \reimp */ -void TQDialog::hide() -{ - if ( isHidden() ) - return; - -#if defined(QT_ACCESSIBILITY_SUPPORT) - if ( isVisible() ) - TQAccessible::updateAccessibility( this, 0, TQAccessible::DialogEnd ); -#endif - - if ( parentWidget() && !did_move ) { - d->relPos = pos() - parentWidget()->topLevelWidget()->pos(); - has_relpos = 1; - } - - // Reimplemented to exit a modal when the dialog is hidden. - TQWidget::hide(); - if ( in_loop ) { - in_loop = FALSE; - tqApp->exit_loop(); - } -} - - -/***************************************************************************** - Detects any widget geometry changes done by the user. - *****************************************************************************/ - -/*! \reimp */ - -void TQDialog::move( int x, int y ) -{ - did_move = TRUE; - TQWidget::move( x, y ); -} - -/*! \reimp */ - -void TQDialog::move( const TQPoint &p ) -{ - did_move = TRUE; - TQWidget::move( p ); -} - -/*! \reimp */ - -void TQDialog::resize( int w, int h ) -{ - did_resize = TRUE; - TQWidget::resize( w, h ); -} - -/*! \reimp */ - -void TQDialog::resize( const TQSize &s ) -{ - did_resize = TRUE; - TQWidget::resize( s ); -} - -/*! \reimp */ - -void TQDialog::setGeometry( int x, int y, int w, int h ) -{ - did_move = TRUE; - did_resize = TRUE; - TQWidget::setGeometry( x, y, w, h ); -} - -/*! \reimp */ - -void TQDialog::setGeometry( const TQRect &r ) -{ - did_move = TRUE; - did_resize = TRUE; - TQWidget::setGeometry( r ); -} - - -/*! - If \a orientation is \c Horizontal, the extension will be displayed - to the right of the dialog's main area. If \a orientation is \c - Vertical, the extension will be displayed below the dialog's main - area. - - \sa orientation(), setExtension() -*/ -void TQDialog::setOrientation( Orientation orientation ) -{ - d->orientation = orientation; -} - -/*! - Returns the dialog's extension orientation. - - \sa setOrientation() -*/ -TQt::Orientation TQDialog::orientation() const -{ - return d->orientation; -} - -/*! - Sets the widget, \a extension, to be the dialog's extension, - deleting any previous extension. The dialog takes ownership of the - extension. Note that if 0 is passed any existing extension will be - deleted. - - This function must only be called while the dialog is hidden. - - \sa showExtension(), setOrientation(), extension() - */ -void TQDialog::setExtension( TQWidget* extension ) -{ - delete d->extension; - d->extension = extension; - - if ( !extension ) - return; - - if ( extension->parentWidget() != this ) - extension->reparent( this, TQPoint(0,0) ); - extension->hide(); -} - -/*! - Returns the dialog's extension or 0 if no extension has been - defined. - - \sa setExtension() - */ -TQWidget* TQDialog::extension() const -{ - return d->extension; -} - - -/*! - If \a showIt is TRUE, the dialog's extension is shown; otherwise the - extension is hidden. - - This slot is usually connected to the \l TQButton::toggled() signal - of a TQPushButton. - - A dialog with a visible extension is not resizeable. - - \sa show(), setExtension(), setOrientation() - */ -void TQDialog::showExtension( bool showIt ) -{ - d->doShowExtension = showIt; - if ( !d->extension ) - return; - if ( !testWState(WState_Visible) ) - return; - if ( d->extension->isVisible() == showIt ) - return; - - if ( showIt ) { - d->size = size(); - d->min = minimumSize(); - d->max = maximumSize(); -#ifndef TQT_NO_LAYOUT - if ( layout() ) - layout()->setEnabled( FALSE ); -#endif - TQSize s( d->extension->sizeHint() - .expandedTo( d->extension->minimumSize() ) - .boundedTo( d->extension->maximumSize() ) ); - if ( d->orientation == Horizontal ) { - int h = TQMAX( height(), s.height() ); - d->extension->setGeometry( width(), 0, s.width(), h ); - setFixedSize( width() + s.width(), h ); - } else { - int w = TQMAX( width(), s.width() ); - d->extension->setGeometry( 0, height(), w, s.height() ); - setFixedSize( w, height() + s.height() ); - } - d->extension->show(); - } else { - d->extension->hide(); - // workaround for CDE window manager that won't shrink with (-1,-1) - setMinimumSize( d->min.expandedTo( TQSize( 1, 1 ) ) ); - setMaximumSize( d->max ); - resize( d->size ); -#ifndef TQT_NO_LAYOUT - if ( layout() ) - layout()->setEnabled( TRUE ); -#endif - } -} - - -/*! \reimp */ -TQSize TQDialog::sizeHint() const -{ - if ( d->extension ) { - if ( d->orientation == Horizontal ) - return TQSize( TQWidget::sizeHint().width(), - TQMAX( TQWidget::sizeHint().height(),d->extension->sizeHint().height() ) ); - else - return TQSize( TQMAX( TQWidget::sizeHint().width(), d->extension->sizeHint().width() ), - TQWidget::sizeHint().height() ); - } - - return TQWidget::sizeHint(); -} - - -/*! \reimp */ -TQSize TQDialog::minimumSizeHint() const -{ - if ( d->extension ) { - if (d->orientation == Horizontal ) - return TQSize( TQWidget::minimumSizeHint().width(), - TQMAX( TQWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height() ) ); - else - return TQSize( TQMAX( TQWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width() ), - TQWidget::minimumSizeHint().height() ); - } - - return TQWidget::minimumSizeHint(); -} - -/*! \property TQDialog::modal - \brief whether show() should pop up the dialog as modal or modeless - - By default, this property is false and show() pops up the dialog as - modeless. - - exec() ignores the value of this property and always pops up the - dialog as modal. - - \sa show(), exec() -*/ - -void TQDialog::setModal( bool modal ) -{ - if ( modal ) - setWFlags( WShowModal ); - else - clearWFlags( WShowModal ); -} - -bool TQDialog::isModal() const -{ - return testWFlags( WShowModal ) != 0; -} - -bool TQDialog::isSizeGripEnabled() const -{ -#ifndef TQT_NO_SIZEGRIP - return !!d->resizer; -#else - return FALSE; -#endif -} - - -void TQDialog::setSizeGripEnabled(bool enabled) -{ -#ifndef TQT_NO_SIZEGRIP - if ( !enabled != !d->resizer ) { - if ( enabled ) { - d->resizer = new TQSizeGrip( this, "TQDialog::resizer" ); - // adjustSize() processes all events, which is suboptimal - d->resizer->resize( d->resizer->sizeHint() ); - if ( TQApplication::reverseLayout() ) - d->resizer->move( rect().bottomLeft() -d->resizer->rect().bottomLeft() ); - else - d->resizer->move( rect().bottomRight() -d->resizer->rect().bottomRight() ); - d->resizer->raise(); - d->resizer->show(); - } else { - delete d->resizer; - d->resizer = 0; - } - } -#endif //TQT_NO_SIZEGRIP -} - - - -/*! \reimp */ -void TQDialog::resizeEvent( TQResizeEvent * ) -{ -#ifndef TQT_NO_SIZEGRIP - if ( d->resizer ) { - if ( TQApplication::reverseLayout() ) - d->resizer->move( rect().bottomLeft() -d->resizer->rect().bottomLeft() ); - else - d->resizer->move( rect().bottomRight() -d->resizer->rect().bottomRight() ); - } -#endif -} - -#endif // TQT_NO_DIALOG diff --git a/src/dialogs/qerrormessage.cpp b/src/dialogs/qerrormessage.cpp index 5d21cf717..2580d9e90 100644 --- a/src/dialogs/qerrormessage.cpp +++ b/src/dialogs/qerrormessage.cpp @@ -43,12 +43,12 @@ #ifndef TQT_NO_ERRORMESSAGE #include "ntqapplication.h" -#include "ntqcheckbox.h" +#include "tqcheckbox.h" #include "tqdict.h" #include "tqlabel.h" #include "ntqlayout.h" #include "ntqmessagebox.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "tqstringlist.h" #include "tqstylesheet.h" #include "tqtextview.h" diff --git a/src/dialogs/qinputdialog.cpp b/src/dialogs/qinputdialog.cpp index 6e8e7627c..6b16af01d 100644 --- a/src/dialogs/qinputdialog.cpp +++ b/src/dialogs/qinputdialog.cpp @@ -44,10 +44,10 @@ #include "ntqlayout.h" #include "tqlabel.h" -#include "ntqlineedit.h" -#include "ntqpushbutton.h" -#include "ntqspinbox.h" -#include "ntqcombobox.h" +#include "tqlineedit.h" +#include "tqpushbutton.h" +#include "tqspinbox.h" +#include "tqcombobox.h" #include "tqwidgetstack.h" #include "ntqvalidator.h" #include "ntqapplication.h" diff --git a/src/dialogs/qmessagebox.cpp b/src/dialogs/qmessagebox.cpp index a80a26886..836470eb4 100644 --- a/src/dialogs/qmessagebox.cpp +++ b/src/dialogs/qmessagebox.cpp @@ -44,7 +44,7 @@ #include "ntqaccel.h" #include "tqlabel.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "tqimage.h" #include "ntqapplication.h" #include "tqstyle.h" diff --git a/src/dialogs/qprintdialog.cpp b/src/dialogs/qprintdialog.cpp index 0fc6f6935..fee5a49b7 100644 --- a/src/dialogs/qprintdialog.cpp +++ b/src/dialogs/qprintdialog.cpp @@ -45,17 +45,17 @@ #include "tqfiledialog.h" #include "tqfile.h" #include "tqtextstream.h" -#include "ntqcombobox.h" +#include "tqcombobox.h" #include "ntqframe.h" #include "tqlabel.h" -#include "ntqlineedit.h" -#include "ntqpushbutton.h" +#include "tqlineedit.h" +#include "tqpushbutton.h" #include "tqprinter.h" #include "ntqlistview.h" #include "ntqlayout.h" #include "ntqbuttongroup.h" -#include "ntqradiobutton.h" -#include "ntqspinbox.h" +#include "tqradiobutton.h" +#include "tqspinbox.h" #include "ntqapplication.h" #include "ntqheader.h" #include "tqstyle.h" diff --git a/src/dialogs/qprogressdialog.cpp b/src/dialogs/qprogressdialog.cpp index 0527f17d2..9c74a906e 100644 --- a/src/dialogs/qprogressdialog.cpp +++ b/src/dialogs/qprogressdialog.cpp @@ -48,7 +48,7 @@ #include "tqdatetime.h" #include "ntqapplication.h" #include "tqstyle.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "ntqcursor.h" #include "tqtimer.h" #include diff --git a/src/dialogs/qt_dialogs.pri b/src/dialogs/qt_dialogs.pri index 669dd70a4..e5c17042a 100644 --- a/src/dialogs/qt_dialogs.pri +++ b/src/dialogs/qt_dialogs.pri @@ -4,7 +4,7 @@ dialogs { DIALOGS_P = dialogs HEADERS += $$DIALOGS_H/tqcolordialog.h \ - $$DIALOGS_H/ntqdialog.h \ + $$DIALOGS_H/tqdialog.h \ $$DIALOGS_H/ntqerrormessage.h \ $$DIALOGS_H/tqfiledialog.h \ $$DIALOGS_H/tqfontdialog.h \ @@ -20,7 +20,7 @@ dialogs { unix:HEADERS += $$DIALOGS_H/ntqprintdialog.h SOURCES += $$DIALOGS_CPP/tqcolordialog.cpp \ - $$DIALOGS_CPP/qdialog.cpp \ + $$DIALOGS_CPP/tqdialog.cpp \ $$DIALOGS_CPP/qerrormessage.cpp \ $$DIALOGS_CPP/tqfiledialog.cpp \ $$DIALOGS_CPP/tqfontdialog.cpp \ diff --git a/src/dialogs/qtabdialog.cpp b/src/dialogs/qtabdialog.cpp index 1a5b1799e..db439d93f 100644 --- a/src/dialogs/qtabdialog.cpp +++ b/src/dialogs/qtabdialog.cpp @@ -45,7 +45,7 @@ #include "tqobjectlist.h" #include "ntqtabbar.h" #include "ntqtabwidget.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "tqpainter.h" #include "tqpixmap.h" #include "ntqapplication.h" diff --git a/src/dialogs/qwizard.cpp b/src/dialogs/qwizard.cpp index 6669a4e7a..ef3b4e8f4 100644 --- a/src/dialogs/qwizard.cpp +++ b/src/dialogs/qwizard.cpp @@ -43,7 +43,7 @@ #ifndef TQT_NO_WIZARD #include "ntqlayout.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "ntqcursor.h" #include "tqlabel.h" #include "tqwidgetstack.h" diff --git a/src/dialogs/tqcolordialog.cpp b/src/dialogs/tqcolordialog.cpp index 19e08c61a..95b7145c8 100644 --- a/src/dialogs/tqcolordialog.cpp +++ b/src/dialogs/tqcolordialog.cpp @@ -45,8 +45,8 @@ #include "tqpainter.h" #include "ntqlayout.h" #include "tqlabel.h" -#include "ntqpushbutton.h" -#include "ntqlineedit.h" +#include "tqpushbutton.h" +#include "tqlineedit.h" #include "tqimage.h" #include "tqpixmap.h" #include "ntqdrawutil.h" diff --git a/src/dialogs/tqcolordialog.h b/src/dialogs/tqcolordialog.h index 0941a020d..580f82ca0 100644 --- a/src/dialogs/tqcolordialog.h +++ b/src/dialogs/tqcolordialog.h @@ -42,7 +42,7 @@ #define TQCOLORDIALOG_H #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #endif // QT_H #ifndef TQT_NO_COLORDIALOG diff --git a/src/dialogs/tqdialog.cpp b/src/dialogs/tqdialog.cpp new file mode 100644 index 000000000..f3f05ae50 --- /dev/null +++ b/src/dialogs/tqdialog.cpp @@ -0,0 +1,1180 @@ +/**************************************************************************** +** +** Implementation of TQDialog class +** +** Created : 950502 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs 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 "tqdialog.h" + +#ifndef TQT_NO_DIALOG + +#include "tqpushbutton.h" +#include "ntqfocusdata.h" +#include "ntqapplication.h" +#include "tqobjectlist.h" +#include "tqwidgetlist.h" +#include "ntqlayout.h" +#include "tqsizegrip.h" +#include "tqwhatsthis.h" +#include "tqpopupmenu.h" +#include "ntqcursor.h" +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif +#if defined( Q_OS_TEMP ) +#include "qt_windows.h" +#endif + +/*! + \class TQDialog + \brief The TQDialog class is the base class of dialog windows. + + \ingroup dialogs + \ingroup abstractwidgets + \mainclass + + A dialog window is a top-level window mostly used for short-term + tasks and brief communications with the user. TQDialogs may be + modal or modeless. TQDialogs support \link #extensibility + extensibility\endlink and can provide a \link #return return + value\endlink. They can have \link #default default + buttons\endlink. TQDialogs can also have a TQSizeGrip in their + lower-right corner, using setSizeGripEnabled(). + + Note that TQDialog uses the parent widget slightly differently from + other classes in TQt. A dialog is always a top-level widget, but if + it has a parent, its default location is centered on top of the + parent's top-level widget (if it is not top-level itself). It will + also share the parent's taskbar entry. + + \target modal + \section1 Modal Dialogs + + A modal dialog is a dialog that blocks input to other + visible windows in the same application. Users must finish + interacting with the dialog and close it before they can access + any other window in the application. Dialogs that are used to + request a file name from the user or that are used to set + application preferences are usually modal. + + The most common way to display a modal dialog is to call its + exec() function. When the user closes the dialog, exec() will + provide a useful \link #return return value\endlink. Typically we + connect a default button, e.g. "OK", to the accept() slot and a + "Cancel" button to the reject() slot, to get the dialog to close + and return the appropriate value. Alternatively you can connect to + the done() slot, passing it \c Accepted or \c Rejected. + + An alternative is to call setModal(TRUE), then show(). Unlike + exec(), show() returns control to the caller immediately. Calling + setModal(TRUE) is especially useful for progress dialogs, where + the user must have the ability to interact with the dialog, e.g. + to cancel a long running operation. If you use show() and + setModal(TRUE) together you must call + TQApplication::processEvents() periodically during processing to + enable the user to interact with the dialog. (See \l + TQProgressDialog.) + + \target modeless + \section1 Modeless Dialogs + + A modeless dialog is a dialog that operates + independently of other windows in the same application. Find and + replace dialogs in word-processors are often modeless to allow the + user to interact with both the application's main window and with + the dialog. + + Modeless dialogs are displayed using show(), which returns control + to the caller immediately. + + \target default + \section1 Default button + + A dialog's \e default button is the button that's pressed when the + user presses Enter (Return). This button is used to signify that + the user accepts the dialog's settings and wants to close the + dialog. Use TQPushButton::setDefault(), TQPushButton::isDefault() + and TQPushButton::autoDefault() to set and control the dialog's + default button. + + \target escapekey + \section1 Escape Key + + If the user presses the Esc key in a dialog, TQDialog::reject() + will be called. This will cause the window to close: the \link + TQCloseEvent closeEvent \endlink cannot be \link + TQCloseEvent::ignore() ignored \endlink. + + \target extensibility + \section1 Extensibility + + Extensibility is the ability to show the dialog in two ways: a + partial dialog that shows the most commonly used options, and a + full dialog that shows all the options. Typically an extensible + dialog will initially appear as a partial dialog, but with a + "More" toggle button. If the user presses the "More" button down, + the full dialog will appear. The extension widget will be resized + to its sizeHint(). If orientation is \c Horizontal the extension + widget's height() will be expanded to the height() of the dialog. + If the orientation is \c Vertical the extension widget's width() + will be expanded to the width() of the dialog. Extensibility is + controlled with setExtension(), setOrientation() and + showExtension(). + + \target return + \section1 Return value (modal dialogs) + + Modal dialogs are often used in situations where a return value is + required, e.g. to indicate whether the user pressed "OK" or + "Cancel". A dialog can be closed by calling the accept() or the + reject() slots, and exec() will return \c Accepted or \c Rejected + as appropriate. The exec() call returns the result of the dialog. + The result is also available from result() if the dialog has not + been destroyed. If the \c WDestructiveClose flag is set, the + dialog is deleted after exec() returns. + + \target examples + \section1 Examples + + A modal dialog. + + \quotefile network/networkprotocol/view.cpp + \skipto TQFileDialog *dlg + \printuntil return + + A modeless dialog. After the show() call, control returns to the main + event loop. + \quotefile life/main.cpp + \skipto argv + \printuntil TQApplication + \skipto scale + \printline + \skipto LifeDialog + \printuntil show + \skipto exec + \printuntil } + + \sa TQTabDialog TQWidget TQProgressDialog + \link guibooks.html#fowler GUI Design Handbook: Dialogs, Standard\endlink +*/ + +/*! \enum TQDialog::DialogCode + + The value returned by a modal dialog. + + \value Accepted + \value Rejected + +*/ + +/*! + \property TQDialog::sizeGripEnabled + \brief whether the size grip is enabled + + A TQSizeGrip is placed in the bottom right corner of the dialog when this + property is enabled. By default, the size grip is disabled. +*/ + +class TQDialogPrivate : public TQt +{ +public: + + TQDialogPrivate() + : mainDef(0), orientation(Horizontal),extension(0), doShowExtension(FALSE) +#ifndef TQT_NO_SIZEGRIP + ,resizer(0) +#endif + { + } + + TQPushButton* mainDef; + Orientation orientation; + TQWidget* extension; + bool doShowExtension; + TQSize size, min, max; +#ifndef TQT_NO_SIZEGRIP + TQSizeGrip* resizer; +#endif + TQPoint lastRMBPress; + TQPoint relPos; // relative position to the main window +}; + +/*! + Constructs a dialog called \a name, with parent \a parent. + + A dialog is always a top-level widget, but if it has a parent, its + default location is centered on top of the parent. It will also + share the parent's taskbar entry. + + The widget flags \a f are passed on to the TQWidget constructor. + If, for example, you don't want a What's This button in the titlebar + of the dialog, pass WStyle_Customize | WStyle_NormalBorder | + WStyle_Title | WStyle_SysMenu in \a f. + + \warning In TQt 3.2, the \a modal flag is obsolete. There is now a + setModal() function that can be used for obtaining a modal behavior + when calling show(). This is rarely needed, because modal dialogs + are usually invoked using exec(), which ignores the \a modal flag. + + \sa TQWidget::setWFlags() TQt::WidgetFlags +*/ + +TQDialog::TQDialog( TQWidget *parent, const char *name, bool modal, WFlags f ) + : TQWidget( parent, name, + (modal ? (f|WShowModal) : f) | WType_Dialog ), + rescode(0), did_move(0), has_relpos(0), did_resize(0), in_loop(0) +{ + d = new TQDialogPrivate; +} + +/*! + Destroys the TQDialog, deleting all its children. +*/ + +TQDialog::~TQDialog() +{ + // Need to hide() here, as our (to-be) overridden hide() + // will not be called in ~TQWidget. + hide(); + delete d; +} + +/*! + \internal + This function is called by the push button \a pushButton when it + becomes the default button. If \a pushButton is 0, the dialogs + default default button becomes the default button. This is what a + push button calls when it loses focus. +*/ + +void TQDialog::setDefault( TQPushButton *pushButton ) +{ +#ifndef TQT_NO_PUSHBUTTON + TQObjectList *list = queryList( "TQPushButton" ); + Q_ASSERT(list); + TQObjectListIt it( *list ); + TQPushButton *pb; + bool hasMain = FALSE; + while ( (pb = (TQPushButton*)it.current()) ) { + ++it; + if ( pb->topLevelWidget() != this ) + continue; + if ( pb == d->mainDef ) + hasMain = TRUE; + if ( pb != pushButton ) + pb->setDefault( FALSE ); + } + if (!pushButton && hasMain) + d->mainDef->setDefault( TRUE ); + if (!hasMain) + d->mainDef = pushButton; + delete list; +#endif +} + +/*! + \internal + This function sets the default default pushbutton to \a pushButton. + This function is called by TQPushButton::setDefault(). +*/ +void TQDialog::setMainDefault( TQPushButton *pushButton ) +{ +#ifndef TQT_NO_PUSHBUTTON + d->mainDef = 0; + setDefault(pushButton); +#endif +} + +/*! + \internal + Hides the default button indicator. Called when non auto-default + push button get focus. + */ +void TQDialog::hideDefault() +{ +#ifndef TQT_NO_PUSHBUTTON + TQObjectList *list = queryList( "TQPushButton" ); + TQObjectListIt it( *list ); + TQPushButton *pb; + while ( (pb = (TQPushButton*)it.current()) ) { + ++it; + pb->setDefault( FALSE ); + } + delete list; +#endif +} + +#ifdef Q_OS_TEMP +/*! + \internal + Hides special buttons which are rather shown in the titlebar + on WinCE, to conserve screen space. +*/ +# include "ntqmessagebox.h" +extern const char * mb_texts[]; // Defined in qmessagebox.cpp +void TQDialog::hideSpecial() +{ + // "OK" buttons are hidden, and (Ok) shown on titlebar + // "Cancel" buttons are hidden, and (X) shown on titlebar + // "Help" buttons are hidden, and (?) shown on titlebar + bool showOK = FALSE, + showX = FALSE, + showQ = FALSE; + TQObjectList *list = queryList( "TQPushButton" ); + TQObjectListIt it( *list ); + TQPushButton *pb; + while ( (pb = (TQPushButton*)it.current()) ) { + if ( !showOK && + pb->text() == tqApp->translate( "TQMessageBox", mb_texts[TQMessageBox::Ok] ) ) { + pb->hide(); + showOK = TRUE; + } else if ( !showX && + pb->text() == tqApp->translate( "TQMessageBox", mb_texts[TQMessageBox::Cancel] ) ) { + pb->hide(); + showX = TRUE; + } else if ( !showQ && + pb->text() == tqApp->tr("Help") ) { + pb->hide(); + showQ = TRUE; + } + ++it; + } + delete list; + if ( showOK || showQ ) { + DWORD ext = GetWindowLong( winId(), GWL_EXSTYLE ); + ext |= showOK ? WS_EX_CAPTIONOKBTN : 0; + ext |= showQ ? WS_EX_CONTEXTHELP: 0; + SetWindowLong( winId(), GWL_EXSTYLE, ext ); + } + if ( !showX ) { + DWORD ext = GetWindowLong( winId(), GWL_STYLE ); + ext &= ~WS_SYSMENU; + SetWindowLong( winId(), GWL_STYLE, ext ); + } +} +#endif + +/*! + \fn int TQDialog::result() const + + Returns the modal dialog's result code, \c Accepted or \c Rejected. + + Do not call this function if the dialog was constructed with the \c + WDestructiveClose flag. +*/ + +/*! + \fn void TQDialog::setResult( int i ) + + Sets the modal dialog's result code to \a i. +*/ + + +/*! + Shows the dialog as a \link #modal modal \endlink dialog, + blocking until the user closes it. The function returns a \l + DialogCode result. + + Users cannot interact with any other window in the same + application until they close the dialog. + + \sa show(), result() +*/ + +int TQDialog::exec() +{ + if ( in_loop ) { + tqWarning( "TQDialog::exec: Recursive call detected" ); + return -1; + } + + bool destructiveClose = testWFlags( WDestructiveClose ); + clearWFlags( WDestructiveClose ); + + bool wasShowModal = testWFlags( WShowModal ); + setWFlags( WShowModal ); + setResult( 0 ); + + show(); + + in_loop = TRUE; + tqApp->enter_loop(); + + if ( !wasShowModal ) + clearWFlags( WShowModal ); + + int res = result(); + + if ( destructiveClose ) + delete this; + + return res; +} + + +/*! Closes the dialog and sets its result code to \a r. If this dialog + is shown with exec(), done() causes the local event loop to finish, + and exec() to return \a r. + + As with TQWidget::close(), done() deletes the dialog if the \c + WDestructiveClose flag is set. If the dialog is the application's + main widget, the application terminates. If the dialog is the + last window closed, the TQApplication::lastWindowClosed() signal is + emitted. + + \sa accept(), reject(), TQApplication::mainWidget(), TQApplication::quit() +*/ + +void TQDialog::done( int r ) +{ + hide(); + setResult( r ); + + // emulate TQWidget::close() + bool isMain = tqApp->mainWidget() == this; + bool checkLastWindowClosed = isTopLevel() && !isPopup(); + if ( checkLastWindowClosed + && tqApp->receivers(TQ_SIGNAL(lastWindowClosed())) ) { + /* if there is no non-withdrawn top level window left (except + the desktop, popups, or dialogs with parents), we emit the + lastWindowClosed signal */ + TQWidgetList *list = tqApp->topLevelWidgets(); + TQWidget *widget = list->first(); + while ( widget ) { + if ( !widget->isHidden() + && !widget->isDesktop() + && !widget->isPopup() + && (!widget->isDialog() || !widget->parentWidget())) + break; + widget = list->next(); + } + delete list; + if ( widget == 0 ) + emit tqApp->lastWindowClosed(); + } + if ( isMain ) + tqApp->quit(); + else if ( testWFlags(WDestructiveClose) ) { + clearWFlags(WDestructiveClose); + deleteLater(); + } +} + +/*! + Hides the modal dialog and sets the result code to \c Accepted. + + \sa reject() done() +*/ + +void TQDialog::accept() +{ + done( Accepted ); +} + +/*! + Hides the modal dialog and sets the result code to \c Rejected. + + \sa accept() done() +*/ + +void TQDialog::reject() +{ + done( Rejected ); +} + +/*! \reimp */ +bool TQDialog::eventFilter( TQObject *o, TQEvent *e ) +{ + return TQWidget::eventFilter( o, e ); +} + +/***************************************************************************** + Event handlers + *****************************************************************************/ + +/*! \reimp */ +void TQDialog::contextMenuEvent( TQContextMenuEvent *e ) +{ +#if !defined(TQT_NO_WHATSTHIS) && !defined(TQT_NO_POPUPMENU) + TQWidget* w = childAt( e->pos(), TRUE ); + if ( !w ) + return; + TQString s; + while ( s.isEmpty() && w ) { + s = TQWhatsThis::textFor( w, e->pos(), FALSE ); + if ( s.isEmpty() ) + w = w->parentWidget(TRUE); + } + if ( !s.isEmpty() ) { + TQPopupMenu p(0,"qt_whats_this_menu"); + p.insertItem( tr("What's This?"), 42 ); + if ( p.exec( e->globalPos() ) >= 42 ) + TQWhatsThis::display( s, w->mapToGlobal( w->rect().center() ), w ); + } +#endif +} + +/*! \reimp */ +void TQDialog::keyPressEvent( TQKeyEvent *e ) +{ + // Calls reject() if Escape is pressed. Simulates a button + // click for the default button if Enter is pressed. Move focus + // for the arrow keys. Ignore the rest. +#ifdef Q_OS_MAC + if(e->state() == ControlButton && e->key() == Key_Period) { + reject(); + } else +#endif + if ( e->state() == 0 || ( e->state() & Keypad && e->key() == Key_Enter ) ) { + switch ( e->key() ) { + case Key_Enter: + case Key_Return: { +#ifndef TQT_NO_PUSHBUTTON + TQObjectList *list = queryList( "TQPushButton" ); + TQObjectListIt it( *list ); + TQPushButton *pb; + while ( (pb = (TQPushButton*)it.current()) ) { + if ( pb->isDefault() && pb->isVisible() ) { + delete list; + if ( pb->isEnabled() ) { + emit pb->clicked(); + } + return; + } + ++it; + } + delete list; +#endif + } + break; + case Key_Escape: + reject(); + break; + case Key_Up: + case Key_Left: + if ( focusWidget() && + ( focusWidget()->focusPolicy() == TQWidget::StrongFocus || + focusWidget()->focusPolicy() == TQWidget::WheelFocus ) ) { + e->ignore(); + break; + } + // call ours, since c++ blocks us from calling the one + // belonging to focusWidget(). + TQFocusEvent::setReason(TQFocusEvent::Backtab); + focusNextPrevChild( FALSE ); + TQFocusEvent::resetReason(); + break; + case Key_Down: + case Key_Right: + if ( focusWidget() && + ( focusWidget()->focusPolicy() == TQWidget::StrongFocus || + focusWidget()->focusPolicy() == TQWidget::WheelFocus ) ) { + e->ignore(); + break; + } + TQFocusEvent::setReason(TQFocusEvent::Tab); + focusNextPrevChild( TRUE ); + TQFocusEvent::resetReason(); + break; + default: + e->ignore(); + return; + } + } else { + e->ignore(); + } +} + +/*! \reimp */ +void TQDialog::closeEvent( TQCloseEvent *e ) +{ +#ifndef TQT_NO_WHATSTHIS + if ( isModal() && TQWhatsThis::inWhatsThisMode() ) + TQWhatsThis::leaveWhatsThisMode(); +#endif + if ( isShown() ) + reject(); + if ( isHidden() ) + e->accept(); +} + +#ifdef Q_OS_TEMP +/*! \internal + \reimp +*/ +bool TQDialog::event( TQEvent *e ) +{ + switch ( e->type() ) { + case TQEvent::OkRequest: + case TQEvent::HelpRequest: + { + TQString bName = + (e->type() == TQEvent::OkRequest) + ? tqApp->translate( "TQMessageBox", mb_texts[TQMessageBox::Ok] ) + : tqApp->tr( "Help" ); + + TQObjectList *list = queryList( "TQPushButton" ); + TQObjectListIt it( *list ); + TQPushButton *pb; + while ( (pb = (TQPushButton*)it.current()) ) { + if ( pb->text() == bName ) { + delete list; + if ( pb->isEnabled() ) + emit pb->clicked(); + return pb->isEnabled(); + } + ++it; + } + delete list; + } + } + return TQWidget::event( e ); +} +#endif + + +/***************************************************************************** + Geometry management. + *****************************************************************************/ + +#if defined(TQ_WS_X11) +extern "C" { int XSetTransientForHint( Display *, unsigned long, unsigned long ); } +#include +#undef FocusIn +// defined in qapplication_x11.cpp +extern Atom qt_net_wm_full_placement; +extern bool qt_net_supports(Atom atom); +#endif // TQ_WS_X11 + +/*! + Shows the dialog as a \link #modeless modeless \endlink dialog. + Control returns immediately to the calling code. + + The dialog will be modal or modeless according to the value + of the \l modal property. + + \sa exec(), modal +*/ + +void TQDialog::show() +{ + if ( testWState(WState_Visible) ) + return; + + uint state = windowState(); + + if ( !did_resize ) + adjustSize(); + if( !qt_net_supports( qt_net_wm_full_placement )) { + if ( has_relpos && !did_move ) { + adjustPositionInternal( parentWidget(), TRUE ); + } else if ( !did_move ) { + adjustPositionInternal( parentWidget() ); + } + } + + if (windowState() != state) + setWindowState(state); + +#if defined(TQ_WS_X11) + if (!parentWidget() && testWFlags(WShowModal) + && tqApp->mainWidget() && tqApp->mainWidget()->isVisible() + && !tqApp->mainWidget()->isMinimized()) { + // make sure the transient for hint is set properly for modal dialogs + x11SetWindowTransient( tqApp->mainWidget()); + } +#endif // TQ_WS_X11 + +#ifdef Q_OS_TEMP + hideSpecial(); +#endif + + TQWidget::show(); + showExtension( d->doShowExtension ); +#ifndef TQT_NO_PUSHBUTTON + TQWidget *fw = focusWidget(); + TQFocusData *fd = focusData(); + + /* + The following block is to handle a special case, and does not + really follow propper logic in concern of autoDefault and TAB + order. However, it's here to ease usage for the users. If a + dialog has a default TQPushButton, and first widget in the TAB + order also is a TQPushButton, then we give focus to the main + default TQPushButton. This simplifies code for the developers, + and actually catches most cases... If not, then they simply + have to use [widget*]->setFocus() themselves... + */ + if ( !fw || fw->focusPolicy() == NoFocus ) { + fd->home(); // Skip main form + TQWidget *first = fd->next(); // Get first main widget + if ( d->mainDef && + first != d->mainDef && + ::tqt_cast(first) ) + d->mainDef->setFocus(); + } + + if ( !d->mainDef && isTopLevel() ) { + if ( !fw || fw->focusPolicy() == NoFocus ) { + focusNextPrevChild( TRUE ); + fw = focusWidget(); + } + if ( fw ) { + fd = focusData(); + TQWidget *home = fd->home(); + TQWidget *candidate = home; + Q_ASSERT( candidate == fw ); + do { + TQPushButton *pb = ::tqt_cast(candidate); + if ( pb && pb->autoDefault() ) { + pb->setDefault( TRUE ); + break; + } + candidate = fd->next(); + } while ( candidate != home ); + } + } + if ( fw ) { + TQFocusEvent e( TQEvent::FocusIn ); + TQFocusEvent::setReason( TQFocusEvent::Tab ); + TQApplication::sendEvent( fw, &e ); + TQFocusEvent::resetReason(); + } + +#endif +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::DialogStart ); +#endif +} + +/*! \internal */ +void TQDialog::adjustPosition( TQWidget* w) +{ + adjustPositionInternal( w ); +} + + +void TQDialog::adjustPositionInternal( TQWidget*w, bool useRelPos) +{ + /* need to make sure these events are already sent to be sure + our information below is correct --sam */ + TQApplication::sendPostedEvents( this, TQEvent::LayoutHint ); + TQApplication::sendPostedEvents( this, TQEvent::Resize ); + + // processing the events might call polish(), which is a nice place + // to restore geometries, so return if the dialog has been positioned + if ( did_move || has_relpos ) + return; + + TQPoint p( 0, 0 ); + int extraw = 0, extrah = 0, scrn = 0; + if ( w ) + w = w->topLevelWidget(); + TQRect desk; + if ( w ) { + // Use mapToGlobal rather than geometry() in case w might + // be embedded in another application + scrn = TQApplication::desktop()->screenNumber( w->mapToGlobal( TQPoint(0,0) ) ); + } else if ( TQApplication::desktop()->isVirtualDesktop() ) { + scrn = TQApplication::desktop()->screenNumber( TQCursor::pos() ); + } else { + scrn = TQApplication::desktop()->screenNumber( this ); + } + desk = TQApplication::desktop()->availableGeometry( scrn ); + + TQWidgetList *list = TQApplication::topLevelWidgets(); + TQWidgetListIt it( *list ); + while ( (extraw == 0 || extrah == 0) && + it.current() != 0 ) { + int framew, frameh; + TQWidget * current = it.current(); + ++it; + if ( ! current->isVisible() ) + continue; + + framew = current->geometry().x() - current->x(); + frameh = current->geometry().y() - current->y(); + + extraw = TQMAX( extraw, framew ); + extrah = TQMAX( extrah, frameh ); + } + delete list; + + // sanity check for decoration frames. With embedding, we + // might get extraordinary values + if ( extraw == 0 || extrah == 0 || extraw >= 10 || extrah >= 40 ) { + extrah = 40; + extraw = 10; + } + + if ( useRelPos && w ) { + p = w->pos() + d->relPos; + } else { +#ifndef Q_OS_TEMP + if ( w ) { + // Use mapToGlobal rather than geometry() in case w might + // be embedded in another application + TQPoint pp = w->mapToGlobal( TQPoint(0,0) ); + p = TQPoint( pp.x() + w->width()/2, + pp.y() + w->height()/ 2 ); + } else { + // p = middle of the desktop + p = TQPoint( desk.x() + desk.width()/2, desk.y() + desk.height()/2 ); + } +#else + p = TQPoint( desk.x() + desk.width()/2, desk.y() + desk.height()/2 ); +#endif + + // p = origin of this + p = TQPoint( p.x()-width()/2 - extraw, + p.y()-height()/2 - extrah ); + } + + + if ( p.x() + extraw + width() > desk.x() + desk.width() ) + p.setX( desk.x() + desk.width() - width() - extraw ); + if ( p.x() < desk.x() ) + p.setX( desk.x() ); + + if ( p.y() + extrah + height() > desk.y() + desk.height() ) + p.setY( desk.y() + desk.height() - height() - extrah ); + if ( p.y() < desk.y() ) + p.setY( desk.y() ); + + move( p ); + did_move = !useRelPos; +} + + +/*! \reimp */ +void TQDialog::hide() +{ + if ( isHidden() ) + return; + +#if defined(QT_ACCESSIBILITY_SUPPORT) + if ( isVisible() ) + TQAccessible::updateAccessibility( this, 0, TQAccessible::DialogEnd ); +#endif + + if ( parentWidget() && !did_move ) { + d->relPos = pos() - parentWidget()->topLevelWidget()->pos(); + has_relpos = 1; + } + + // Reimplemented to exit a modal when the dialog is hidden. + TQWidget::hide(); + if ( in_loop ) { + in_loop = FALSE; + tqApp->exit_loop(); + } +} + + +/***************************************************************************** + Detects any widget geometry changes done by the user. + *****************************************************************************/ + +/*! \reimp */ + +void TQDialog::move( int x, int y ) +{ + did_move = TRUE; + TQWidget::move( x, y ); +} + +/*! \reimp */ + +void TQDialog::move( const TQPoint &p ) +{ + did_move = TRUE; + TQWidget::move( p ); +} + +/*! \reimp */ + +void TQDialog::resize( int w, int h ) +{ + did_resize = TRUE; + TQWidget::resize( w, h ); +} + +/*! \reimp */ + +void TQDialog::resize( const TQSize &s ) +{ + did_resize = TRUE; + TQWidget::resize( s ); +} + +/*! \reimp */ + +void TQDialog::setGeometry( int x, int y, int w, int h ) +{ + did_move = TRUE; + did_resize = TRUE; + TQWidget::setGeometry( x, y, w, h ); +} + +/*! \reimp */ + +void TQDialog::setGeometry( const TQRect &r ) +{ + did_move = TRUE; + did_resize = TRUE; + TQWidget::setGeometry( r ); +} + + +/*! + If \a orientation is \c Horizontal, the extension will be displayed + to the right of the dialog's main area. If \a orientation is \c + Vertical, the extension will be displayed below the dialog's main + area. + + \sa orientation(), setExtension() +*/ +void TQDialog::setOrientation( Orientation orientation ) +{ + d->orientation = orientation; +} + +/*! + Returns the dialog's extension orientation. + + \sa setOrientation() +*/ +TQt::Orientation TQDialog::orientation() const +{ + return d->orientation; +} + +/*! + Sets the widget, \a extension, to be the dialog's extension, + deleting any previous extension. The dialog takes ownership of the + extension. Note that if 0 is passed any existing extension will be + deleted. + + This function must only be called while the dialog is hidden. + + \sa showExtension(), setOrientation(), extension() + */ +void TQDialog::setExtension( TQWidget* extension ) +{ + delete d->extension; + d->extension = extension; + + if ( !extension ) + return; + + if ( extension->parentWidget() != this ) + extension->reparent( this, TQPoint(0,0) ); + extension->hide(); +} + +/*! + Returns the dialog's extension or 0 if no extension has been + defined. + + \sa setExtension() + */ +TQWidget* TQDialog::extension() const +{ + return d->extension; +} + + +/*! + If \a showIt is TRUE, the dialog's extension is shown; otherwise the + extension is hidden. + + This slot is usually connected to the \l TQButton::toggled() signal + of a TQPushButton. + + A dialog with a visible extension is not resizeable. + + \sa show(), setExtension(), setOrientation() + */ +void TQDialog::showExtension( bool showIt ) +{ + d->doShowExtension = showIt; + if ( !d->extension ) + return; + if ( !testWState(WState_Visible) ) + return; + if ( d->extension->isVisible() == showIt ) + return; + + if ( showIt ) { + d->size = size(); + d->min = minimumSize(); + d->max = maximumSize(); +#ifndef TQT_NO_LAYOUT + if ( layout() ) + layout()->setEnabled( FALSE ); +#endif + TQSize s( d->extension->sizeHint() + .expandedTo( d->extension->minimumSize() ) + .boundedTo( d->extension->maximumSize() ) ); + if ( d->orientation == Horizontal ) { + int h = TQMAX( height(), s.height() ); + d->extension->setGeometry( width(), 0, s.width(), h ); + setFixedSize( width() + s.width(), h ); + } else { + int w = TQMAX( width(), s.width() ); + d->extension->setGeometry( 0, height(), w, s.height() ); + setFixedSize( w, height() + s.height() ); + } + d->extension->show(); + } else { + d->extension->hide(); + // workaround for CDE window manager that won't shrink with (-1,-1) + setMinimumSize( d->min.expandedTo( TQSize( 1, 1 ) ) ); + setMaximumSize( d->max ); + resize( d->size ); +#ifndef TQT_NO_LAYOUT + if ( layout() ) + layout()->setEnabled( TRUE ); +#endif + } +} + + +/*! \reimp */ +TQSize TQDialog::sizeHint() const +{ + if ( d->extension ) { + if ( d->orientation == Horizontal ) + return TQSize( TQWidget::sizeHint().width(), + TQMAX( TQWidget::sizeHint().height(),d->extension->sizeHint().height() ) ); + else + return TQSize( TQMAX( TQWidget::sizeHint().width(), d->extension->sizeHint().width() ), + TQWidget::sizeHint().height() ); + } + + return TQWidget::sizeHint(); +} + + +/*! \reimp */ +TQSize TQDialog::minimumSizeHint() const +{ + if ( d->extension ) { + if (d->orientation == Horizontal ) + return TQSize( TQWidget::minimumSizeHint().width(), + TQMAX( TQWidget::minimumSizeHint().height(), d->extension->minimumSizeHint().height() ) ); + else + return TQSize( TQMAX( TQWidget::minimumSizeHint().width(), d->extension->minimumSizeHint().width() ), + TQWidget::minimumSizeHint().height() ); + } + + return TQWidget::minimumSizeHint(); +} + +/*! \property TQDialog::modal + \brief whether show() should pop up the dialog as modal or modeless + + By default, this property is false and show() pops up the dialog as + modeless. + + exec() ignores the value of this property and always pops up the + dialog as modal. + + \sa show(), exec() +*/ + +void TQDialog::setModal( bool modal ) +{ + if ( modal ) + setWFlags( WShowModal ); + else + clearWFlags( WShowModal ); +} + +bool TQDialog::isModal() const +{ + return testWFlags( WShowModal ) != 0; +} + +bool TQDialog::isSizeGripEnabled() const +{ +#ifndef TQT_NO_SIZEGRIP + return !!d->resizer; +#else + return FALSE; +#endif +} + + +void TQDialog::setSizeGripEnabled(bool enabled) +{ +#ifndef TQT_NO_SIZEGRIP + if ( !enabled != !d->resizer ) { + if ( enabled ) { + d->resizer = new TQSizeGrip( this, "TQDialog::resizer" ); + // adjustSize() processes all events, which is suboptimal + d->resizer->resize( d->resizer->sizeHint() ); + if ( TQApplication::reverseLayout() ) + d->resizer->move( rect().bottomLeft() -d->resizer->rect().bottomLeft() ); + else + d->resizer->move( rect().bottomRight() -d->resizer->rect().bottomRight() ); + d->resizer->raise(); + d->resizer->show(); + } else { + delete d->resizer; + d->resizer = 0; + } + } +#endif //TQT_NO_SIZEGRIP +} + + + +/*! \reimp */ +void TQDialog::resizeEvent( TQResizeEvent * ) +{ +#ifndef TQT_NO_SIZEGRIP + if ( d->resizer ) { + if ( TQApplication::reverseLayout() ) + d->resizer->move( rect().bottomLeft() -d->resizer->rect().bottomLeft() ); + else + d->resizer->move( rect().bottomRight() -d->resizer->rect().bottomRight() ); + } +#endif +} + +#endif // TQT_NO_DIALOG diff --git a/src/dialogs/tqdialog.h b/src/dialogs/tqdialog.h new file mode 100644 index 000000000..e1d82c179 --- /dev/null +++ b/src/dialogs/tqdialog.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Definition of TQDialog class +** +** Created : 950502 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs 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 TQDIALOG_H +#define TQDIALOG_H + +#ifndef QT_H +#include "tqwidget.h" +#endif // QT_H +#ifndef TQT_NO_DIALOG +#if 0 +TQ_OBJECT +#endif + +class TQPushButton; +class TQDialogPrivate; + +class TQ_EXPORT TQDialog : public TQWidget +{ +friend class TQPushButton; + TQ_OBJECT + TQ_PROPERTY( bool sizeGripEnabled READ isSizeGripEnabled WRITE setSizeGripEnabled ) + TQ_PROPERTY( bool modal READ isModal WRITE setModal ) + +public: + Q_EXPLICIT TQDialog( TQWidget* parent=0, const char* name=0, bool modal=FALSE, + WFlags f=0 ); + ~TQDialog(); + + enum DialogCode { Rejected, Accepted }; + + int result() const { return rescode; } + + void show(); + void hide(); + void move( int x, int y ); + void move( const TQPoint &p ); + void resize( int w, int h ); + void resize( const TQSize & ); + void setGeometry( int x, int y, int w, int h ); + void setGeometry( const TQRect & ); + + void setOrientation( Orientation orientation ); + Orientation orientation() const; + + void setExtension( TQWidget* extension ); + TQWidget* extension() const; + + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + + void setSizeGripEnabled( bool ); + bool isSizeGripEnabled() const; + + void setModal( bool modal ); + bool isModal() const; +#ifdef Q_OS_TEMP + bool event( TQEvent * ); +#endif + +public slots: + int exec(); + +protected slots: + virtual void done( int ); + virtual void accept(); + virtual void reject(); + + void showExtension( bool ); + +protected: + void setResult( int r ) { rescode = r; } + void keyPressEvent( TQKeyEvent * ); + void closeEvent( TQCloseEvent * ); + void resizeEvent( TQResizeEvent * ); + void contextMenuEvent( TQContextMenuEvent * ); + bool eventFilter( TQObject *, TQEvent * ); + void adjustPosition( TQWidget*); + +private: + void setDefault( TQPushButton * ); + void setMainDefault( TQPushButton * ); + void hideDefault(); +#ifdef Q_OS_TEMP + void hideSpecial(); +#endif + + int rescode; + uint did_move : 1; + uint has_relpos : 1; + uint did_resize : 1; + uint in_loop: 1; + void adjustPositionInternal( TQWidget*, bool useRelPos = FALSE ); + TQDialogPrivate* d; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQDialog( const TQDialog & ); + TQDialog &operator=( const TQDialog & ); +#endif +}; + +#endif // TQT_NO_DIALOG +#endif // TQDIALOG_H diff --git a/src/dialogs/tqfiledialog.cpp b/src/dialogs/tqfiledialog.cpp index 5ed1ff6be..27ec5d130 100644 --- a/src/dialogs/tqfiledialog.cpp +++ b/src/dialogs/tqfiledialog.cpp @@ -58,9 +58,9 @@ #include "ntqapplication.h" #include "tqbitmap.h" #include "ntqbuttongroup.h" -#include "ntqcheckbox.h" +#include "tqcheckbox.h" #include "ntqcleanuphandler.h" -#include "ntqcombobox.h" +#include "tqcombobox.h" #include "tqcstring.h" #include "ntqcursor.h" #include "tqdragobject.h" @@ -71,7 +71,7 @@ #include "tqlabel.h" #include "ntqlayout.h" #include "ntqlibrary.h" -#include "ntqlineedit.h" +#include "tqlineedit.h" #include "ntqlistbox.h" #include "ntqlistview.h" #include "tqmap.h" @@ -83,7 +83,7 @@ #include "tqpopupmenu.h" #include "ntqprogressbar.h" #include "tqptrvector.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "tqregexp.h" #include "ntqsplitter.h" #include "tqstrlist.h" diff --git a/src/dialogs/tqfiledialog.h b/src/dialogs/tqfiledialog.h index b57be85a9..23cd5476e 100644 --- a/src/dialogs/tqfiledialog.h +++ b/src/dialogs/tqfiledialog.h @@ -56,7 +56,7 @@ class TQFileDialogTQFileListView; #ifndef QT_H #include "tqdir.h" -#include "ntqdialog.h" +#include "tqdialog.h" #include "tqurloperator.h" #include "tqurlinfo.h" #endif // QT_H diff --git a/src/dialogs/tqfontdialog.cpp b/src/dialogs/tqfontdialog.cpp index c9b5daef0..e13083b3a 100644 --- a/src/dialogs/tqfontdialog.cpp +++ b/src/dialogs/tqfontdialog.cpp @@ -44,11 +44,11 @@ #include "tqfontdialog.h" -#include "ntqlineedit.h" +#include "tqlineedit.h" #include "ntqlistbox.h" -#include "ntqpushbutton.h" -#include "ntqcheckbox.h" -#include "ntqcombobox.h" +#include "tqpushbutton.h" +#include "tqcheckbox.h" +#include "tqcombobox.h" #include "ntqlayout.h" #include "ntqvgroupbox.h" #include "ntqhgroupbox.h" diff --git a/src/dialogs/tqfontdialog.h b/src/dialogs/tqfontdialog.h index 2c7d3f9d4..1a3b007d5 100644 --- a/src/dialogs/tqfontdialog.h +++ b/src/dialogs/tqfontdialog.h @@ -56,7 +56,7 @@ // #ifndef QT_H -#include "ntqdialog.h" +#include "tqdialog.h" #include "tqfont.h" #endif // QT_H diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index 11305209b..b8e8dca73 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -77,9 +77,9 @@ #include "tqfileinfo.h" #include "tqurlinfo.h" #include "tqwidgetlist.h" -#include +#include #include "ntqgroupbox.h" -#include "ntqdialog.h" +#include "tqdialog.h" #include #include "ntqdockwindow.h" #include "ntqcommonstyle.h" @@ -107,7 +107,7 @@ #include "tqbuffer.h" #include "tqimage.h" #include -#include "ntqlineedit.h" +#include "tqlineedit.h" #include #include "tqintdict.h" #include "ntqmotifstyle.h" @@ -118,11 +118,11 @@ #include #include "tqlabel.h" #include "ntqlayout.h" -#include +#include #include #include -#include "ntqscrollbar.h" -#include "ntqscrollview.h" +#include "tqscrollbar.h" +#include "tqscrollview.h" #include "tqdir.h" #include "ntqwindowsstyle.h" #include "ntqconnection.h" @@ -169,9 +169,9 @@ #include #include #include "tqstylesheet.h" -#include -#include -#include +#include +#include +#include #include #include "tqregexp.h" #include @@ -193,12 +193,12 @@ #include #include #include -#include +#include #include #include #include #include -#include +#include #include #include #include "tqsqlerror.h" @@ -264,7 +264,7 @@ #include #include #include -#include +#include #include #include #include @@ -300,7 +300,7 @@ #include "private/tqdir_p.h" #include "private/tqsettings_p.h" #include "private/tqsqlextension_p.h" -#include "private/qdialogbuttons_p.h" +#include "private/tqdialogbuttons_p.h" #include "private/tqwidgetinterface_p.h" #include "private/tqwidgetresizehandler_p.h" #include "private/qlibrary_p.h" diff --git a/src/kernel/tqstyle.cpp b/src/kernel/tqstyle.cpp index 9bf8c4509..cca9ef651 100644 --- a/src/kernel/tqstyle.cpp +++ b/src/kernel/tqstyle.cpp @@ -48,7 +48,7 @@ #include "ntqlayout.h" #include "ntqlistview.h" #include "tqpopupmenu.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "tqobjectlist.h" #include "tqwidgetlist.h" diff --git a/src/kernel/tqwidget_x11.cpp b/src/kernel/tqwidget_x11.cpp index 4e07dd115..1d137e943 100644 --- a/src/kernel/tqwidget_x11.cpp +++ b/src/kernel/tqwidget_x11.cpp @@ -3055,7 +3055,7 @@ void TQWidget::destroyInputContext() /*! This function is called when text widgets need to be neutral state to - execute text operations properly. See qlineedit.cpp and tqtextedit.cpp as + execute text operations properly. See tqlineedit.cpp and tqtextedit.cpp as example. Ordinary reset that along with changing focus to another widget, diff --git a/src/libqt.map b/src/libqt.map index 9965ec963..42e353c76 100644 --- a/src/libqt.map +++ b/src/libqt.map @@ -30,7 +30,7 @@ QRollEffect::*; QSharedDoubleBufferCleaner::*; QSmSocketReceiver::*; - QSpinBoxValidator::*; + TQSpinBoxValidator::*; QSplitterHandle::*; TQSqlRecordShared::*; QSVChildRec::*; diff --git a/src/sql/tqeditorfactory.cpp b/src/sql/tqeditorfactory.cpp index 00f625b55..76fa71996 100644 --- a/src/sql/tqeditorfactory.cpp +++ b/src/sql/tqeditorfactory.cpp @@ -40,9 +40,9 @@ #include "ntqcleanuphandler.h" #include "tqlabel.h" -#include "ntqlineedit.h" -#include "ntqspinbox.h" -#include "ntqcombobox.h" +#include "tqlineedit.h" +#include "tqspinbox.h" +#include "tqcombobox.h" #include "tqeditorfactory.h" #include "tqdatetimeedit.h" diff --git a/src/sql/tqsqleditorfactory.cpp b/src/sql/tqsqleditorfactory.cpp index cf4944ae4..31d9108f2 100644 --- a/src/sql/tqsqleditorfactory.cpp +++ b/src/sql/tqsqleditorfactory.cpp @@ -45,9 +45,9 @@ #include "tqsqlfield.h" #include "ntqcleanuphandler.h" #include "tqlabel.h" -#include "ntqlineedit.h" -#include "ntqspinbox.h" -#include "ntqcombobox.h" +#include "tqlineedit.h" +#include "tqspinbox.h" +#include "tqcombobox.h" #include "tqdatetimeedit.h" /*! diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp index 5f16b5b0e..7b6e475f3 100644 --- a/src/styles/qcommonstyle.cpp +++ b/src/styles/qcommonstyle.cpp @@ -48,27 +48,27 @@ #include "tqpainter.h" #include "ntqdrawutil.h" #include "tqpixmap.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "ntqtabbar.h" #include "ntqtabwidget.h" -#include "ntqlineedit.h" -#include "ntqscrollbar.h" +#include "tqlineedit.h" +#include "tqscrollbar.h" #include "tqtoolbutton.h" #include "tqtoolbar.h" -#include "ntqcombobox.h" +#include "tqcombobox.h" #include "ntqdockarea.h" #include "ntqheader.h" -#include "ntqspinbox.h" +#include "tqspinbox.h" #include "ntqrangecontrol.h" #include "ntqgroupbox.h" -#include "ntqslider.h" +#include "tqslider.h" #include "ntqlistview.h" -#include "ntqcheckbox.h" -#include "ntqradiobutton.h" +#include "tqcheckbox.h" +#include "tqradiobutton.h" #include "tqbitmap.h" #include "ntqprogressbar.h" #include "ntqlistbox.h" -#include "private/qdialogbuttons_p.h" +#include "private/tqdialogbuttons_p.h" #include #include #include "../widgets/qtitlebar_p.h" diff --git a/src/styles/qinterlacestyle.cpp b/src/styles/qinterlacestyle.cpp index 43917bd27..7f4838c80 100644 --- a/src/styles/qinterlacestyle.cpp +++ b/src/styles/qinterlacestyle.cpp @@ -50,10 +50,10 @@ #include "tqpalette.h" // for now #include "tqwidget.h" #include "tqlabel.h" -#include "ntqpushbutton.h" +#include "tqpushbutton.h" #include "tqwidget.h" #include "ntqrangecontrol.h" -#include "ntqscrollbar.h" +#include "tqscrollbar.h" #include "ntqlistbox.h" #include diff --git a/src/styles/qmotifplusstyle.cpp b/src/styles/qmotifplusstyle.cpp index 4b0da7c8b..d37419b2e 100644 --- a/src/styles/qmotifplusstyle.cpp +++ b/src/styles/qmotifplusstyle.cpp @@ -47,15 +47,15 @@ #include "tqpainter.h" #include "tqpalette.h" #include "ntqframe.h" -#include "ntqpushbutton.h" -#include "ntqcheckbox.h" -#include "ntqradiobutton.h" -#include "ntqcombobox.h" -#include "ntqlineedit.h" -#include "ntqspinbox.h" -#include "ntqslider.h" +#include "tqpushbutton.h" +#include "tqcheckbox.h" +#include "tqradiobutton.h" +#include "tqcombobox.h" +#include "tqlineedit.h" +#include "tqspinbox.h" +#include "tqslider.h" #include "ntqdrawutil.h" -#include "ntqscrollbar.h" +#include "tqscrollbar.h" #include "ntqtabbar.h" #include "tqtoolbar.h" #include "ntqguardedptr.h" diff --git a/src/styles/qmotifstyle.cpp b/src/styles/qmotifstyle.cpp index 87d310127..55ff6666a 100644 --- a/src/styles/qmotifstyle.cpp +++ b/src/styles/qmotifstyle.cpp @@ -49,14 +49,14 @@ #include "tqpixmap.h" #include "tqpalette.h" #include "tqwidget.h" -#include "ntqpushbutton.h" -#include "ntqscrollbar.h" +#include "tqpushbutton.h" +#include "tqscrollbar.h" #include "ntqtabbar.h" #include "ntqtabwidget.h" #include "ntqlistview.h" #include "ntqsplitter.h" -#include "ntqslider.h" -#include "ntqcombobox.h" +#include "tqslider.h" +#include "tqcombobox.h" #include "ntqdockwindow.h" #include "ntqdockarea.h" #include "ntqprogressbar.h" diff --git a/src/styles/qplatinumstyle.cpp b/src/styles/qplatinumstyle.cpp index ee2823a26..721a480a7 100644 --- a/src/styles/qplatinumstyle.cpp +++ b/src/styles/qplatinumstyle.cpp @@ -43,14 +43,14 @@ #if !defined(TQT_NO_STYLE_PLATINUM) || defined(QT_PLUGIN) #include "ntqapplication.h" -#include "ntqcombobox.h" +#include "tqcombobox.h" #include "ntqdrawutil.h" #include "tqpainter.h" #include "tqpalette.h" #include "tqpixmap.h" -#include "ntqpushbutton.h" -#include "ntqscrollbar.h" -#include "ntqslider.h" +#include "tqpushbutton.h" +#include "tqscrollbar.h" +#include "tqslider.h" #include /*! diff --git a/src/styles/qsgistyle.cpp b/src/styles/qsgistyle.cpp index ef4a6183d..a69ef63b6 100644 --- a/src/styles/qsgistyle.cpp +++ b/src/styles/qsgistyle.cpp @@ -50,13 +50,13 @@ #include "tqpixmap.h" #include "tqpalette.h" #include "tqwidget.h" -#include "ntqpushbutton.h" -#include "ntqscrollbar.h" -#include "ntqcombobox.h" -#include "ntqslider.h" +#include "tqpushbutton.h" +#include "tqscrollbar.h" +#include "tqcombobox.h" +#include "tqslider.h" #include "tqtextedit.h" #include "tqtoolbar.h" -#include "ntqlineedit.h" +#include "tqlineedit.h" #include "tqmenubar.h" #include diff --git a/src/styles/qwindowsstyle.cpp b/src/styles/qwindowsstyle.cpp index 27437724f..23754f786 100644 --- a/src/styles/qwindowsstyle.cpp +++ b/src/styles/qwindowsstyle.cpp @@ -50,13 +50,13 @@ #include "tqwidget.h" #include "tqlabel.h" #include "tqimage.h" -#include "ntqpushbutton.h" -#include "ntqcombobox.h" +#include "tqpushbutton.h" +#include "tqcombobox.h" #include "ntqlistbox.h" #include "tqwidget.h" #include "ntqrangecontrol.h" -#include "ntqscrollbar.h" -#include "ntqslider.h" +#include "tqscrollbar.h" +#include "tqslider.h" #include "ntqtabwidget.h" #include "ntqtabbar.h" #include "ntqlistview.h" diff --git a/src/table/ntqtable.h b/src/table/ntqtable.h index dc2c2c0b8..baeb8bd82 100644 --- a/src/table/ntqtable.h +++ b/src/table/ntqtable.h @@ -42,7 +42,7 @@ #define TQTABLE_H #ifndef QT_H -#include "ntqscrollview.h" +#include "tqscrollview.h" #include "tqpixmap.h" #include "tqptrvector.h" #include "ntqheader.h" diff --git a/src/table/qtable.cpp b/src/table/qtable.cpp index ef4cffc19..d83827a92 100644 --- a/src/table/qtable.cpp +++ b/src/table/qtable.cpp @@ -49,14 +49,14 @@ #ifndef TQT_NO_TABLE #include -#include +#include #include #include #include #include #include -#include -#include +#include +#include #include #include #include @@ -1695,7 +1695,7 @@ TQSize TQCheckTableItem::sizeHint() const 1, although row and column numbers within TQTable begin at 0.) If you want to use mouse tracking call setMouseTracking( TRUE ) on - the \e viewport; (see \link ntqscrollview.html#allviews + the \e viewport; (see \link tqscrollview.html#allviews TQScrollView\endlink). \img qtableitems.png Table Items diff --git a/src/tools/qfeatures.txt b/src/tools/qfeatures.txt index 89917cbec..c13fc7bd2 100644 --- a/src/tools/qfeatures.txt +++ b/src/tools/qfeatures.txt @@ -904,7 +904,7 @@ SeeAlso: ??? Feature: LCDNUMBER Section: Widgets Requires: FRAME -Name: QLCDNumber +Name: TQLCDNumber SeeAlso: ??? Feature: ACTION @@ -916,7 +916,7 @@ SeeAlso: ??? Feature: COMBOBOX Section: Widgets Requires: LISTBOX LINEEDIT POPUPMENU -Name: QComboBox +Name: TQComboBox SeeAlso: ??? Feature: LISTVIEW diff --git a/src/widgets/ntqcheckbox.h b/src/widgets/ntqcheckbox.h deleted file mode 100644 index 4a63e4b4a..000000000 --- a/src/widgets/ntqcheckbox.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Definition of TQCheckBox class -** -** Created : 940222 -** -** 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 TQCHECKBOX_H -#define TQCHECKBOX_H - -#ifndef QT_H -#include "ntqbutton.h" -#endif // QT_H - -#ifndef TQT_NO_CHECKBOX - -class TQ_EXPORT TQCheckBox : public TQButton -{ - TQ_OBJECT - TQ_PROPERTY( bool checked READ isChecked WRITE setChecked ) - TQ_PROPERTY( bool tristate READ isTristate WRITE setTristate ) - TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) - -public: - TQCheckBox( TQWidget *parent, const char* name=0 ); - TQCheckBox( const TQString &text, TQWidget *parent, const char* name=0 ); - - bool isChecked() const; - - void setNoChange(); - - void setTristate(bool y=TRUE); - bool isTristate() const; - - TQSize sizeHint() const; - -public slots: - void setChecked( bool check ); - -protected: - void resizeEvent( TQResizeEvent* ); - void drawButton( TQPainter * ); - void drawButtonLabel( TQPainter * ); - void updateMask(); - bool hitButton( const TQPoint &pos ) const; -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQCheckBox( const TQCheckBox & ); - TQCheckBox &operator=( const TQCheckBox & ); -#endif -}; - - -inline bool TQCheckBox::isChecked() const -{ return isOn(); } - -inline void TQCheckBox::setChecked( bool check ) -{ setOn( check ); } - - -#endif // TQT_NO_CHECKBOX - -#endif // TQCHECKBOX_H diff --git a/src/widgets/ntqcombobox.h b/src/widgets/ntqcombobox.h deleted file mode 100644 index 296148549..000000000 --- a/src/widgets/ntqcombobox.h +++ /dev/null @@ -1,206 +0,0 @@ -/********************************************************************** -** -** Definition of TQComboBox class -** -** Created : 950426 -** -** 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 TQCOMBOBOX_H -#define TQCOMBOBOX_H - -#ifndef QT_H -#include "tqwidget.h" -#endif // QT_H - -#ifndef TQT_NO_COMBOBOX - - -class TQStrList; -class TQStringList; -class TQLineEdit; -class TQValidator; -class TQListBox; -class TQComboBoxData; -class TQWheelEvent; - -class TQ_EXPORT TQComboBox : public TQWidget -{ - TQ_OBJECT - TQ_ENUMS( Policy ) - TQ_PROPERTY( bool editable READ editable WRITE setEditable ) - TQ_PROPERTY( int count READ count ) - TQ_PROPERTY( TQString currentText READ currentText WRITE setCurrentText DESIGNABLE false ) - TQ_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem ) - TQ_PROPERTY( bool autoResize READ autoResize WRITE setAutoResize DESIGNABLE false ) - TQ_PROPERTY( int sizeLimit READ sizeLimit WRITE setSizeLimit ) - TQ_PROPERTY( int maxCount READ maxCount WRITE setMaxCount ) - TQ_PROPERTY( Policy insertionPolicy READ insertionPolicy WRITE setInsertionPolicy ) - TQ_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion ) - TQ_PROPERTY( bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled ) - TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) - -public: - TQComboBox( TQWidget* parent=0, const char* name=0 ); - TQComboBox( bool rw, TQWidget* parent=0, const char* name=0 ); - ~TQComboBox(); - - int count() const; - - void insertStringList( const TQStringList &, int index=-1 ); - void insertStrList( const TQStrList &, int index=-1 ); - void insertStrList( const TQStrList *, int index=-1 ); - void insertStrList( const char **, int numStrings=-1, int index=-1); - - void insertItem( const TQString &text, int index=-1 ); - void insertItem( const TQPixmap &pixmap, int index=-1 ); - void insertItem( const TQPixmap &pixmap, const TQString &text, int index=-1 ); - - void removeItem( int index ); - - int currentItem() const; - virtual void setCurrentItem( int index ); - - TQString currentText() const; - virtual void setCurrentText( const TQString& ); - - TQString text( int index ) const; - const TQPixmap *pixmap( int index ) const; - - void changeItem( const TQString &text, int index ); - void changeItem( const TQPixmap &pixmap, int index ); - void changeItem( const TQPixmap &pixmap, const TQString &text, int index ); - - bool autoResize() const; - virtual void setAutoResize( bool ); - TQSize sizeHint() const; - - void setPalette( const TQPalette & ); - void setFont( const TQFont & ); - void setEnabled( bool ); - - virtual void setSizeLimit( int ); - int sizeLimit() const; - - virtual void setMaxCount( int ); - int maxCount() const; - - enum Policy { NoInsertion, AtTop, AtCurrent, AtBottom, - AfterCurrent, BeforeCurrent }; - - virtual void setInsertionPolicy( Policy policy ); - Policy insertionPolicy() const; - - virtual void setValidator( const TQValidator * ); - const TQValidator * validator() const; - - virtual void setListBox( TQListBox * ); - TQListBox * listBox() const; - - virtual void setLineEdit( TQLineEdit *edit ); - TQLineEdit* lineEdit() const; - - virtual void setAutoCompletion( bool ); - bool autoCompletion() const; - - bool eventFilter( TQObject *object, TQEvent *event ); - - void setDuplicatesEnabled( bool enable ); - bool duplicatesEnabled() const; - - bool editable() const; - void setEditable( bool ); - - virtual void popup(); - - void hide(); - -public slots: - void clear(); - void clearValidator(); - void clearEdit(); - virtual void setEditText( const TQString &); - -signals: - void activated( int index ); - void highlighted( int index ); - void activated( const TQString &); - void highlighted( const TQString &); - void textChanged( const TQString &); - -private slots: - void internalActivate( int ); - void internalHighlight( int ); - void internalClickTimeout(); - void returnPressed(); - -protected: - void paintEvent( TQPaintEvent * ); - void resizeEvent( TQResizeEvent * ); - void mousePressEvent( TQMouseEvent * ); - void mouseMoveEvent( TQMouseEvent * ); - void mouseReleaseEvent( TQMouseEvent * ); - void mouseDoubleClickEvent( TQMouseEvent * ); - void keyPressEvent( TQKeyEvent *e ); - void focusInEvent( TQFocusEvent *e ); - void focusOutEvent( TQFocusEvent *e ); -#ifndef TQT_NO_WHEELEVENT - void wheelEvent( TQWheelEvent *e ); -#endif - void styleChange( TQStyle& ); - - void updateMask(); - -private: - void setUpListBox(); - void setUpLineEdit(); - void popDownListBox(); - void reIndex(); - void currentChanged(); - int completionIndex( const TQString &, int ) const; - - TQComboBoxData *d; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQComboBox( const TQComboBox & ); - TQComboBox &operator=( const TQComboBox & ); -#endif -}; - - -#endif // TQT_NO_COMBOBOX - -#endif // TQCOMBOBOX_H diff --git a/src/widgets/ntqdial.h b/src/widgets/ntqdial.h deleted file mode 100644 index 7baf98e53..000000000 --- a/src/widgets/ntqdial.h +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** Definition of the dial widget -** -** Created : 990104 -** -** Copyright (C) 1999-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 TQDIAL_H -#define TQDIAL_H - -#ifndef QT_H -#include "tqwidget.h" -#include "ntqrangecontrol.h" -#endif // QT_H - -#ifndef TQT_NO_DIAL - -class TQDialPrivate; - -class TQ_EXPORT TQDial: public TQWidget, public TQRangeControl -{ - TQ_OBJECT - TQ_PROPERTY( bool tracking READ tracking WRITE setTracking ) - TQ_PROPERTY( bool wrapping READ wrapping WRITE setWrapping ) - TQ_PROPERTY( int notchSize READ notchSize ) - TQ_PROPERTY( double notchTarget READ notchTarget WRITE setNotchTarget ) - TQ_PROPERTY( bool notchesVisible READ notchesVisible WRITE setNotchesVisible ) - TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) - TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) - TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) - TQ_PROPERTY( int pageStep READ pageStep WRITE setPageStep ) - TQ_PROPERTY( int value READ value WRITE setValue ) - -public: - TQDial( TQWidget* parent=0, const char* name=0, WFlags f = 0 ); - TQDial( int minValue, int maxValue, int pageStep, int value, - TQWidget* parent=0, const char* name=0 ); - ~TQDial(); - - bool tracking() const; - - bool wrapping() const; - - int notchSize() const; - - virtual void setNotchTarget( double ); - double notchTarget() const; - - bool notchesVisible() const; - - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - - int minValue() const; - int maxValue() const; - void setMinValue( int ); - void setMaxValue( int ); - int lineStep() const; - int pageStep() const; - void setLineStep( int ); - void setPageStep( int ); - int value() const; - -public slots: - virtual void setValue( int ); - void addLine(); - void subtractLine(); - void addPage(); - void subtractPage(); - virtual void setNotchesVisible( bool b ); - virtual void setWrapping( bool on ); - virtual void setTracking( bool enable ); - -signals: - void valueChanged( int value ); - void dialPressed(); - void dialMoved( int value ); - void dialReleased(); - -protected: - void resizeEvent( TQResizeEvent * ); - void paintEvent( TQPaintEvent * ); - - void keyPressEvent( TQKeyEvent * ); - void mousePressEvent( TQMouseEvent * ); - void mouseReleaseEvent( TQMouseEvent * ); - void mouseMoveEvent( TQMouseEvent * ); -#ifndef TQT_NO_WHEELEVENT - void wheelEvent( TQWheelEvent * ); -#endif - void focusInEvent( TQFocusEvent * ); - void focusOutEvent( TQFocusEvent * ); - - void valueChange(); - void rangeChange(); - - virtual void repaintScreen( const TQRect *cr = 0 ); - -private: - TQDialPrivate * d; - - int valueFromPoint( const TQPoint & ) const; - double angle( const TQPoint &, const TQPoint & ) const; - TQPointArray calcArrow( double &a ) const; - TQRect calcDial() const; - int calcBigLineSize() const; - void calcLines(); - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQDial( const TQDial & ); - TQDial &operator=( const TQDial & ); -#endif - -}; - -#endif // TQT_NO_DIAL - -#endif diff --git a/src/widgets/ntqgridview.h b/src/widgets/ntqgridview.h index 6a8a3c182..1ec47a823 100644 --- a/src/widgets/ntqgridview.h +++ b/src/widgets/ntqgridview.h @@ -42,7 +42,7 @@ #define TQGRIDVIEW_H #ifndef QT_H -#include "ntqscrollview.h" +#include "tqscrollview.h" #endif // QT_H #ifndef TQT_NO_GRIDVIEW diff --git a/src/widgets/ntqlcdnumber.h b/src/widgets/ntqlcdnumber.h deleted file mode 100644 index e74de7cb6..000000000 --- a/src/widgets/ntqlcdnumber.h +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Definition of TQLCDNumber class -** -** Created : 940518 -** -** 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 TQLCDNUMBER_H -#define TQLCDNUMBER_H - -#ifndef QT_H -#include "ntqframe.h" -#include "tqbitarray.h" -#endif // QT_H - -#ifndef TQT_NO_LCDNUMBER - - -class TQLCDNumberPrivate; - -class TQ_EXPORT TQLCDNumber : public TQFrame // LCD number widget -{ - TQ_OBJECT - TQ_ENUMS( Mode SegmentStyle ) - TQ_PROPERTY( bool smallDecimalPoint READ smallDecimalPoint WRITE setSmallDecimalPoint ) - TQ_PROPERTY( int numDigits READ numDigits WRITE setNumDigits ) - TQ_PROPERTY( Mode mode READ mode WRITE setMode ) - TQ_PROPERTY( SegmentStyle segmentStyle READ segmentStyle WRITE setSegmentStyle ) - TQ_PROPERTY( double value READ value WRITE display ) - TQ_PROPERTY( int intValue READ intValue WRITE display ) - -public: - TQLCDNumber( TQWidget* parent=0, const char* name=0 ); - TQLCDNumber( uint numDigits, TQWidget* parent=0, const char* name=0 ); - ~TQLCDNumber(); - - enum Mode { Hex, Dec, Oct, Bin, HEX = Hex, DEC = Dec, OCT = Oct, - BIN = Bin }; - enum SegmentStyle { Outline, Filled, Flat }; - - bool smallDecimalPoint() const; - - int numDigits() const; - virtual void setNumDigits( int nDigits ); - - bool checkOverflow( double num ) const; - bool checkOverflow( int num ) const; - - Mode mode() const; - virtual void setMode( Mode ); - - SegmentStyle segmentStyle() const; - virtual void setSegmentStyle( SegmentStyle ); - - double value() const; - int intValue() const; - - TQSize sizeHint() const; - -public slots: - void display( const TQString &str ); - void display( int num ); - void display( double num ); - virtual void setHexMode(); - virtual void setDecMode(); - virtual void setOctMode(); - virtual void setBinMode(); - virtual void setSmallDecimalPoint( bool ); - -signals: - void overflow(); - -protected: - void drawContents( TQPainter * ); - -private: - void init(); - void internalDisplay( const TQString &); - void internalSetString( const TQString& s ); - void drawString( const TQString& s, TQPainter &, TQBitArray * = 0, - bool = TRUE ); - //void drawString( const TQString &, TQPainter &, TQBitArray * = 0 ) const; - void drawDigit( const TQPoint &, TQPainter &, int, char, - char = ' ' ); - void drawSegment( const TQPoint &, char, TQPainter &, int, bool = FALSE ); - - int ndigits; - double val; - uint base : 2; - uint smallPoint : 1; - uint fill : 1; - uint shadow : 1; - TQString digitStr; - TQBitArray points; - TQLCDNumberPrivate * d; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQLCDNumber( const TQLCDNumber & ); - TQLCDNumber &operator=( const TQLCDNumber & ); -#endif -}; - -inline bool TQLCDNumber::smallDecimalPoint() const -{ return (bool)smallPoint; } - -inline int TQLCDNumber::numDigits() const -{ return ndigits; } - - -#endif // TQT_NO_LCDNUMBER - -#endif // TQLCDNUMBER_H diff --git a/src/widgets/ntqlineedit.h b/src/widgets/ntqlineedit.h deleted file mode 100644 index f5bf18c68..000000000 --- a/src/widgets/ntqlineedit.h +++ /dev/null @@ -1,218 +0,0 @@ -/********************************************************************** -** -** Definition of TQLineEdit widget class -** -** Created : 941011 -** -** 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 TQLINEEDIT_H -#define TQLINEEDIT_H - -struct TQLineEditPrivate; - -class TQValidator; -class TQPopupMenu; - -#ifndef QT_H -#include "ntqframe.h" -#include "tqstring.h" -#endif // QT_H - -#ifndef TQT_NO_LINEEDIT - -class TQTextParagraph; -class TQTextCursor; - -class TQ_EXPORT TQLineEdit : public TQFrame -{ - TQ_OBJECT - TQ_ENUMS( EchoMode ) - TQ_PROPERTY( TQString text READ text WRITE setText ) - TQ_PROPERTY( int maxLength READ maxLength WRITE setMaxLength ) - TQ_PROPERTY( bool frame READ frame WRITE setFrame ) - TQ_PROPERTY( EchoMode echoMode READ echoMode WRITE setEchoMode ) - TQ_PROPERTY( TQString displayText READ displayText ) - TQ_PROPERTY( int cursorPosition READ cursorPosition WRITE setCursorPosition ) - TQ_PROPERTY( Alignment alignment READ alignment WRITE setAlignment ) - TQ_PROPERTY( bool edited READ edited WRITE setEdited DESIGNABLE false ) - TQ_PROPERTY( bool modified READ isModified ) - TQ_PROPERTY( bool hasSelectedText READ hasSelectedText ) - TQ_PROPERTY( TQString selectedText READ selectedText ) - TQ_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled ) - TQ_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly ) - TQ_PROPERTY( bool undoAvailable READ isUndoAvailable ) - TQ_PROPERTY( bool redoAvailable READ isRedoAvailable ) - TQ_PROPERTY( TQString inputMask READ inputMask WRITE setInputMask ) - TQ_PROPERTY( bool acceptableInput READ hasAcceptableInput ) - -public: - TQLineEdit( TQWidget* parent, const char* name=0 ); - TQLineEdit( const TQString &, TQWidget* parent, const char* name=0 ); - TQLineEdit( const TQString &, const TQString &, TQWidget* parent, const char* name=0 ); - ~TQLineEdit(); - - TQString text() const; - - TQString displayText() const; - - int maxLength() const; - - bool frame() const; - - enum EchoMode { Normal, NoEcho, Password, PasswordThreeStars }; - EchoMode echoMode() const; - - bool isReadOnly() const; - - const TQValidator * validator() const; - - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - - int cursorPosition() const; - bool validateAndSet( const TQString &, int, int, int ); // obsolete - - int alignment() const; - - void cursorForward( bool mark, int steps = 1 ); - void cursorBackward( bool mark, int steps = 1 ); - void cursorWordForward( bool mark ); - void cursorWordBackward( bool mark ); - void backspace(); - void del(); - void home( bool mark ); - void end( bool mark ); - - bool isModified() const; - void clearModified(); - - bool edited() const; // obsolete, use isModified() - void setEdited( bool ); // obsolete, use clearModified() - - bool hasSelectedText() const; - TQString selectedText() const; - int selectionStart() const; - - bool isUndoAvailable() const; - bool isRedoAvailable() const; - - bool dragEnabled() const; - - TQString inputMask() const; - void setInputMask( const TQString &inputMask ); - bool hasAcceptableInput() const; - -public slots: - virtual void setText( const TQString &); - virtual void selectAll(); - virtual void deselect(); - virtual void clearValidator(); - virtual void insert( const TQString &); - virtual void clear(); - virtual void undo(); - virtual void redo(); - virtual void setMaxLength( int ); - virtual void setFrame( bool ); - virtual void setEchoMode( EchoMode ); - virtual void setReadOnly( bool ); - virtual void setValidator( const TQValidator * ); - virtual void setFont( const TQFont & ); - virtual void setPalette( const TQPalette & ); - virtual void setSelection( int, int ); - virtual void setCursorPosition( int ); - virtual void setAlignment( int flag ); -#ifndef TQT_NO_CLIPBOARD - virtual void cut(); - virtual void copy() const; - virtual void paste(); -#endif - virtual void setDragEnabled( bool b ); - -signals: - void textChanged( const TQString &); - void returnPressed(); - void lostFocus(); - void selectionChanged(); - -protected: - bool event( TQEvent * ); - void mousePressEvent( TQMouseEvent * ); - void mouseMoveEvent( TQMouseEvent * ); - void mouseReleaseEvent( TQMouseEvent * ); - void mouseDoubleClickEvent( TQMouseEvent * ); - void keyPressEvent( TQKeyEvent * ); - void imStartEvent( TQIMEvent * ); - void imComposeEvent( TQIMEvent * ); - void imEndEvent( TQIMEvent * ); - void focusInEvent( TQFocusEvent * ); - void focusOutEvent( TQFocusEvent * ); - void resizeEvent( TQResizeEvent * ); - void drawContents( TQPainter * ); -#ifndef TQT_NO_DRAGANDDROP - void dragEnterEvent( TQDragEnterEvent * ); - void dragMoveEvent( TQDragMoveEvent *e ); - void dragLeaveEvent( TQDragLeaveEvent *e ); - void dropEvent( TQDropEvent * ); -#endif - void contextMenuEvent( TQContextMenuEvent * ); - bool sendMouseEventToInputContext( TQMouseEvent *e ); - virtual TQPopupMenu *createPopupMenu(); - void windowActivationChange( bool ); - -private slots: - void clipboardChanged(); - -public: - void setPasswordChar( TQChar c ); // internal obsolete - TQChar passwordChar() const; // obsolete internal - int characterAt( int, TQChar* ) const; // obsolete - bool getSelection( int *, int * ); // obsolete - -private: - friend struct TQLineEditPrivate; - TQLineEditPrivate * d; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQLineEdit( const TQLineEdit & ); - TQLineEdit &operator=( const TQLineEdit & ); -#endif -}; - - -#endif // TQT_NO_LINEEDIT - -#endif // TQLINEEDIT_H diff --git a/src/widgets/ntqlistbox.h b/src/widgets/ntqlistbox.h index 39a9b75de..cfc2b7682 100644 --- a/src/widgets/ntqlistbox.h +++ b/src/widgets/ntqlistbox.h @@ -42,7 +42,7 @@ #define TQLISTBOX_H #ifndef QT_H -#include "ntqscrollview.h" +#include "tqscrollview.h" #include "tqpixmap.h" #endif // QT_H diff --git a/src/widgets/ntqlistview.h b/src/widgets/ntqlistview.h index b46513372..45eb89a8e 100644 --- a/src/widgets/ntqlistview.h +++ b/src/widgets/ntqlistview.h @@ -42,7 +42,7 @@ #define TQLISTVIEW_H #ifndef QT_H -#include "ntqscrollview.h" +#include "tqscrollview.h" #endif // QT_H #ifndef TQT_NO_LISTVIEW diff --git a/src/widgets/ntqpushbutton.h b/src/widgets/ntqpushbutton.h deleted file mode 100644 index 13b76e9fe..000000000 --- a/src/widgets/ntqpushbutton.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Definition of TQPushButton class -** -** Created : 940221 -** -** 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 TQPUSHBUTTON_H -#define TQPUSHBUTTON_H - -#ifndef QT_H -#include "ntqbutton.h" -#include "tqiconset.h" -#endif // QT_H - -#ifndef TQT_NO_PUSHBUTTON -class TQPushButtonPrivate; -class TQPopupMenu; - -class TQ_EXPORT TQPushButton : public TQButton -{ - TQ_OBJECT - - TQ_PROPERTY( bool autoDefault READ autoDefault WRITE setAutoDefault ) - TQ_PROPERTY( bool default READ isDefault WRITE setDefault ) - TQ_PROPERTY( bool menuButton READ isMenuButton DESIGNABLE false ) - TQ_PROPERTY( TQIconSet iconSet READ iconSet WRITE setIconSet ) - TQ_OVERRIDE( bool toggleButton WRITE setToggleButton ) - TQ_OVERRIDE( bool on WRITE setOn ) - TQ_PROPERTY( bool flat READ isFlat WRITE setFlat ) - TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) - -public: - TQPushButton( TQWidget *parent, const char* name=0 ); - TQPushButton( const TQString &text, TQWidget *parent, const char* name=0 ); -#ifndef TQT_NO_ICONSET - TQPushButton( const TQIconSet& icon, const TQString &text, TQWidget *parent, const char* name=0 ); -#endif - ~TQPushButton(); - - TQSize sizeHint() const; - - void move( int x, int y ); - void move( const TQPoint &p ); - void resize( int w, int h ); - void resize( const TQSize & ); - void setGeometry( int x, int y, int w, int h ); - - void setGeometry( const TQRect & ); - - void setToggleButton( bool ); - - bool autoDefault() const { return autoDefButton; } - virtual void setAutoDefault( bool autoDef ); - bool isDefault() const { return defButton; } - virtual void setDefault( bool def ); - - virtual void setIsMenuButton( bool enable ) { // obsolete functions - if ( (bool)hasMenuArrow == enable ) - return; - hasMenuArrow = enable ? 1 : 0; - update(); - updateGeometry(); - } - bool isMenuButton() const { return hasMenuArrow; } - -#ifndef TQT_NO_POPUPMENU - void setPopup( TQPopupMenu* popup ); - TQPopupMenu* popup() const; -#endif -#ifndef TQT_NO_ICONSET - void setIconSet( const TQIconSet& ); - TQIconSet* iconSet() const; -#endif - void setFlat( bool ); - bool isFlat() const; - -public slots: - virtual void setOn( bool ); - -protected: - void drawButton( TQPainter * ); - void drawButtonLabel( TQPainter * ); - void focusInEvent( TQFocusEvent * ); - void focusOutEvent( TQFocusEvent * ); - void resizeEvent( TQResizeEvent * ); - void updateMask(); -private slots: -#ifndef TQT_NO_POPUPMENU - void popupPressed(); -#endif -private: - void init(); - - uint autoDefButton : 1; - uint defButton : 1; - uint flt : 1; - uint reserved : 1; // UNUSED - uint lastEnabled : 1; // UNUSED - uint hasMenuArrow : 1; - - TQPushButtonPrivate* d; - - friend class TQDialog; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQPushButton( const TQPushButton & ); - TQPushButton &operator=( const TQPushButton & ); -#endif -}; - - -#endif // TQT_NO_PUSHBUTTON - -#endif // TQPUSHBUTTON_H diff --git a/src/widgets/ntqradiobutton.h b/src/widgets/ntqradiobutton.h deleted file mode 100644 index 1c7c0ae34..000000000 --- a/src/widgets/ntqradiobutton.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Definition of TQRadioButton class -** -** Created : 940222 -** -** 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 TQRADIOBUTTON_H -#define TQRADIOBUTTON_H - -#ifndef QT_H -#include "ntqbutton.h" -#endif // QT_H - -#ifndef TQT_NO_RADIOBUTTON - -class TQ_EXPORT TQRadioButton : public TQButton -{ - TQ_OBJECT - TQ_PROPERTY( bool checked READ isChecked WRITE setChecked ) - TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) - -public: - TQRadioButton( TQWidget *parent, const char* name=0 ); - TQRadioButton( const TQString &text, TQWidget *parent, const char* name=0 ); - - bool isChecked() const; - - TQSize sizeHint() const; - -public slots: - virtual void setChecked( bool check ); - -protected: - bool hitButton( const TQPoint & ) const; - void drawButton( TQPainter * ); - void drawButtonLabel( TQPainter * ); - void updateMask(); - - void resizeEvent( TQResizeEvent* ); - -private: - void init(); - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQRadioButton( const TQRadioButton & ); - TQRadioButton &operator=( const TQRadioButton & ); -#endif -}; - - -inline bool TQRadioButton::isChecked() const -{ return isOn(); } - -#endif // TQT_NO_RADIOBUTTON - -#endif // TQRADIOBUTTON_H diff --git a/src/widgets/ntqscrollbar.h b/src/widgets/ntqscrollbar.h deleted file mode 100644 index 6a298c96f..000000000 --- a/src/widgets/ntqscrollbar.h +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -** -** Definition of TQScrollBar class -** -** Created : 940427 -** -** 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 TQSCROLLBAR_H -#define TQSCROLLBAR_H - -class TQTimer; - -#ifndef QT_H -#include "tqwidget.h" -#include "ntqrangecontrol.h" -#endif // QT_H - -#ifndef TQT_NO_SCROLLBAR - -class TQ_EXPORT TQScrollBar : public TQWidget, public TQRangeControl -{ - TQ_OBJECT - TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) - TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) - TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) - TQ_PROPERTY( int pageStep READ pageStep WRITE setPageStep ) - TQ_PROPERTY( int value READ value WRITE setValue ) - TQ_PROPERTY( bool tracking READ tracking WRITE setTracking ) - TQ_PROPERTY( bool draggingSlider READ draggingSlider ) - TQ_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) - -public: - TQScrollBar( TQWidget *parent, const char* name = 0 ); - TQScrollBar( Orientation, TQWidget *parent, const char* name = 0 ); - TQScrollBar( int minValue, int maxValue, int lineStep, int pageStep, - int value, Orientation, TQWidget *parent, const char* name = 0 ); - ~TQScrollBar(); - - virtual void setOrientation( Orientation ); - Orientation orientation() const; - virtual void setTracking( bool enable ); - bool tracking() const; - bool draggingSlider() const; - - virtual void setPalette( const TQPalette & ); - virtual TQSize sizeHint() const; - virtual void setSizePolicy( TQSizePolicy sp ); - void setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw = FALSE ); - - int minValue() const; - int maxValue() const; - void setMinValue( int ); - void setMaxValue( int ); - int lineStep() const; - int pageStep() const; - void setLineStep( int ); - void setPageStep( int ); - int value() const; - - int sliderStart() const; - TQRect sliderRect() const; - -public slots: - void setValue( int ); - -signals: - void valueChanged( int value ); - void sliderPressed(); - void sliderMoved( int value ); - void sliderReleased(); - void nextLine(); - void prevLine(); - void nextPage(); - void prevPage(); - -protected: -#ifndef TQT_NO_WHEELEVENT - void wheelEvent( TQWheelEvent * ); -#endif - void keyPressEvent( TQKeyEvent * ); - void resizeEvent( TQResizeEvent * ); - void paintEvent( TQPaintEvent * ); - - void mousePressEvent( TQMouseEvent * ); - void mouseReleaseEvent( TQMouseEvent * ); - void mouseMoveEvent( TQMouseEvent * ); - void contextMenuEvent( TQContextMenuEvent * ); - void hideEvent( TQHideEvent* ); - - void valueChange(); - void stepChange(); - void rangeChange(); - - void styleChange( TQStyle& ); - -private slots: - void doAutoRepeat(); - -private: - void init(); - void positionSliderFromValue(); - int calculateValueFromSlider() const; - - void startAutoRepeat(); - void stopAutoRepeat(); - - int rangeValueToSliderPos( int val ) const; - int sliderPosToRangeValue( int val ) const; - - void action( int control ); - - void drawControls( uint controls, uint activeControl ) const; - void drawControls( uint controls, uint activeControl, - TQPainter *p ) const; - - uint pressedControl; - bool track; - bool clickedAt; - Orientation orient; - - int slidePrevVal; - TQCOORD sliderPos; - TQCOORD clickOffset; - - TQTimer * repeater; - void * d; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQScrollBar( const TQScrollBar & ); - TQScrollBar &operator=( const TQScrollBar & ); -#endif -}; - - -inline void TQScrollBar::setTracking( bool t ) -{ - track = t; -} - -inline bool TQScrollBar::tracking() const -{ - return track; -} - -inline TQScrollBar::Orientation TQScrollBar::orientation() const -{ - return orient; -} - -inline int TQScrollBar::sliderStart() const -{ - return sliderPos; -} - -inline void TQScrollBar::setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw ) -{ - TQWidget::setSizePolicy( hor, ver, hfw ); -} - - -#endif // TQT_NO_SCROLLBAR - -#endif // TQSCROLLBAR_H diff --git a/src/widgets/ntqscrollview.h b/src/widgets/ntqscrollview.h deleted file mode 100644 index c9dcc8846..000000000 --- a/src/widgets/ntqscrollview.h +++ /dev/null @@ -1,269 +0,0 @@ -/**************************************************************************** -** -** Definition of TQScrollView class -** -** Created : 970523 -** -** 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 TQSCROLLVIEW_H -#define TQSCROLLVIEW_H - -#ifndef QT_H -#include "ntqframe.h" -#include "ntqscrollbar.h" -#endif // QT_H - -#ifndef TQT_NO_SCROLLVIEW - -class TQScrollViewData; - -class TQ_EXPORT TQScrollView : public TQFrame -{ - TQ_OBJECT - TQ_ENUMS( ResizePolicy ScrollBarMode ) - TQ_PROPERTY( ResizePolicy resizePolicy READ resizePolicy WRITE setResizePolicy ) - TQ_PROPERTY( ScrollBarMode vScrollBarMode READ vScrollBarMode WRITE setVScrollBarMode ) - TQ_PROPERTY( ScrollBarMode hScrollBarMode READ hScrollBarMode WRITE setHScrollBarMode ) - TQ_PROPERTY( int visibleWidth READ visibleWidth ) - TQ_PROPERTY( int visibleHeight READ visibleHeight ) - TQ_PROPERTY( int contentsWidth READ contentsWidth ) - TQ_PROPERTY( int contentsHeight READ contentsHeight ) - TQ_PROPERTY( int contentsX READ contentsX ) - TQ_PROPERTY( int contentsY READ contentsY ) -#ifndef TQT_NO_DRAGANDDROP - TQ_PROPERTY( bool dragAutoScroll READ dragAutoScroll WRITE setDragAutoScroll ) -#endif - -public: - TQScrollView(TQWidget* parent=0, const char* name=0, WFlags f=0); - ~TQScrollView(); - - enum ResizePolicy { Default, Manual, AutoOne, AutoOneFit }; - virtual void setResizePolicy( ResizePolicy ); - ResizePolicy resizePolicy() const; - - void styleChange( TQStyle & ); - void removeChild(TQWidget* child); - virtual void addChild( TQWidget* child, int x=0, int y=0 ); - virtual void moveChild( TQWidget* child, int x, int y ); - int childX(TQWidget* child); - int childY(TQWidget* child); - bool childIsVisible(TQWidget* child) { return child->isVisible(); } // obsolete functions - void showChild(TQWidget* child, bool yes=TRUE) { - if ( yes ) - child->show(); - else - child->hide(); - } - - enum ScrollBarMode { Auto, AlwaysOff, AlwaysOn }; - - ScrollBarMode vScrollBarMode() const; - virtual void setVScrollBarMode( ScrollBarMode ); - - ScrollBarMode hScrollBarMode() const; - virtual void setHScrollBarMode( ScrollBarMode ); - - TQWidget* cornerWidget() const; - virtual void setCornerWidget(TQWidget*); - - // ### 4.0: Consider providing a factory function for scrollbars - // (e.g. make the two following functions virtual) - TQScrollBar* horizontalScrollBar() const; - TQScrollBar* verticalScrollBar() const; - TQWidget* viewport() const; - TQWidget* clipper() const; - - int visibleWidth() const; - int visibleHeight() const; - - int contentsWidth() const; - int contentsHeight() const; - int contentsX() const; - int contentsY() const; - - void resize( int w, int h ); - void resize( const TQSize& ); - void show(); - - void updateContents( int x, int y, int w, int h ); - void updateContents( const TQRect& r ); - void updateContents(); - void repaintContents( int x, int y, int w, int h, bool erase=TRUE ); - void repaintContents( const TQRect& r, bool erase=TRUE ); - void repaintContents( bool erase=TRUE ); - void contentsToViewport( int x, int y, int& vx, int& vy ) const; - void viewportToContents( int vx, int vy, int& x, int& y ) const; - TQPoint contentsToViewport( const TQPoint& ) const; - TQPoint viewportToContents( const TQPoint& ) const; - void enableClipper( bool y ); - - void setStaticBackground( bool y ); - bool hasStaticBackground() const; - - TQSize viewportSize( int, int ) const; - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - - void removeChild(TQObject* child); - - bool isHorizontalSliderPressed(); - bool isVerticalSliderPressed(); - -#ifndef TQT_NO_DRAGANDDROP - virtual void setDragAutoScroll( bool b ); - bool dragAutoScroll() const; -#endif - -signals: - void contentsMoving(int x, int y); - void horizontalSliderPressed(); - void horizontalSliderReleased(); - void verticalSliderPressed(); - void verticalSliderReleased(); - -public slots: - virtual void resizeContents( int w, int h ); - void scrollBy( int dx, int dy ); - virtual void setContentsPos( int x, int y ); - void ensureVisible(int x, int y); - void ensureVisible(int x, int y, int xmargin, int ymargin); - void center(int x, int y); - void center(int x, int y, float xmargin, float ymargin); - - void updateScrollBars(); // ### virtual in 4.0 - void setEnabled( bool enable ); - -protected: - virtual void drawContents(TQPainter*, int cx, int cy, int cw, int ch); - virtual void drawContentsOffset(TQPainter*, int ox, int oy, - int cx, int cy, int cw, int ch); - - - virtual void contentsMousePressEvent( TQMouseEvent* ); - virtual void contentsMouseReleaseEvent( TQMouseEvent* ); - virtual void contentsMouseDoubleClickEvent( TQMouseEvent* ); - virtual void contentsMouseMoveEvent( TQMouseEvent* ); -#ifndef TQT_NO_DRAGANDDROP - virtual void contentsDragEnterEvent( TQDragEnterEvent * ); - virtual void contentsDragMoveEvent( TQDragMoveEvent * ); - virtual void contentsDragLeaveEvent( TQDragLeaveEvent * ); - virtual void contentsDropEvent( TQDropEvent * ); -#endif -#ifndef TQT_NO_WHEELEVENT - virtual void contentsWheelEvent( TQWheelEvent * ); -#endif - virtual void contentsContextMenuEvent( TQContextMenuEvent * ); - - - virtual void viewportPaintEvent( TQPaintEvent* ); - virtual void viewportResizeEvent( TQResizeEvent* ); - virtual void viewportMousePressEvent( TQMouseEvent* ); - virtual void viewportMouseReleaseEvent( TQMouseEvent* ); - virtual void viewportMouseDoubleClickEvent( TQMouseEvent* ); - virtual void viewportMouseMoveEvent( TQMouseEvent* ); -#ifndef TQT_NO_DRAGANDDROP - virtual void viewportDragEnterEvent( TQDragEnterEvent * ); - virtual void viewportDragMoveEvent( TQDragMoveEvent * ); - virtual void viewportDragLeaveEvent( TQDragLeaveEvent * ); - virtual void viewportDropEvent( TQDropEvent * ); -#endif -#ifndef TQT_NO_WHEELEVENT - virtual void viewportWheelEvent( TQWheelEvent * ); -#endif - virtual void viewportContextMenuEvent( TQContextMenuEvent * ); - - void frameChanged(); - - virtual void setMargins(int left, int top, int right, int bottom); - int leftMargin() const; - int topMargin() const; - int rightMargin() const; - int bottomMargin() const; - - bool focusNextPrevChild( bool next ); - - virtual void setHBarGeometry(TQScrollBar& hbar, int x, int y, int w, int h); - virtual void setVBarGeometry(TQScrollBar& vbar, int x, int y, int w, int h); - - void resizeEvent(TQResizeEvent*); - void mousePressEvent( TQMouseEvent * ); - void mouseReleaseEvent( TQMouseEvent * ); - void mouseDoubleClickEvent( TQMouseEvent * ); - void mouseMoveEvent( TQMouseEvent * ); -#ifndef TQT_NO_WHEELEVENT - void wheelEvent( TQWheelEvent * ); -#endif - void contextMenuEvent( TQContextMenuEvent * ); - bool eventFilter( TQObject *, TQEvent *e ); - - void setCachedSizeHint( const TQSize &sh ) const; - TQSize cachedSizeHint() const; - void fontChange( const TQFont & ); - -private: - void drawContents( TQPainter* ); - void moveContents(int x, int y); - - TQScrollViewData* d; - -private slots: - void hslide(int); - void vslide(int); - void hbarIsPressed(); - void hbarIsReleased(); - void vbarIsPressed(); - void vbarIsReleased(); -#ifndef TQT_NO_DRAGANDDROP - void doDragAutoScroll(); - void startDragAutoScroll(); - void stopDragAutoScroll(); -#endif - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQScrollView( const TQScrollView & ); - TQScrollView &operator=( const TQScrollView & ); -#endif - void changeFrameRect(const TQRect&); - -public: - void disableSizeHintCaching(); - -}; - -#endif // TQT_NO_SCROLLVIEW - -#endif // TQSCROLLVIEW_H diff --git a/src/widgets/ntqslider.h b/src/widgets/ntqslider.h deleted file mode 100644 index af60245e3..000000000 --- a/src/widgets/ntqslider.h +++ /dev/null @@ -1,199 +0,0 @@ -/**************************************************************************** -** -** Definition of TQSlider class -** -** Created : 961019 -** -** 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 TQSLIDER_H -#define TQSLIDER_H - -#ifndef QT_H -#include "tqwidget.h" -#include "ntqrangecontrol.h" -#endif // QT_H - -#ifndef TQT_NO_SLIDER - -struct TQSliderPrivate; - -class TQTimer; - -class TQ_EXPORT TQSlider : public TQWidget, public TQRangeControl -{ - TQ_OBJECT - TQ_ENUMS( TickSetting ) - TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) - TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) - TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) - TQ_PROPERTY( int pageStep READ pageStep WRITE setPageStep ) - TQ_PROPERTY( int value READ value WRITE setValue ) - TQ_PROPERTY( bool tracking READ tracking WRITE setTracking ) - TQ_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) - TQ_PROPERTY( TickSetting tickmarks READ tickmarks WRITE setTickmarks ) - TQ_PROPERTY( int tickInterval READ tickInterval WRITE setTickInterval ) - -public: - enum TickSetting { NoMarks = 0, Above = 1, Left = Above, - Below = 2, Right = Below, Both = 3 }; - - TQSlider( TQWidget *parent, const char* name = 0 ); - TQSlider( Orientation, TQWidget *parent, const char* name = 0 ); - TQSlider( int minValue, int maxValue, int pageStep, int value, Orientation, - TQWidget *parent, const char* name = 0 ); - ~TQSlider(); - - virtual void setOrientation( Orientation ); - Orientation orientation() const; - virtual void setTracking( bool enable ); - bool tracking() const; - virtual void setPalette( const TQPalette & ); - - int sliderStart() const; - TQRect sliderRect() const; - TQSize sizeHint() const; - void setSizePolicy( TQSizePolicy sp ); - void setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw = FALSE ); - - TQSizePolicy sizePolicy() const; - TQSize minimumSizeHint() const; - - virtual void setTickmarks( TickSetting ); - TickSetting tickmarks() const { return ticks; } - - virtual void setTickInterval( int ); - int tickInterval() const { return tickInt; } - - int minValue() const; - int maxValue() const; - void setMinValue( int ); - void setMaxValue( int ); - int lineStep() const; - int pageStep() const; - void setLineStep( int ); - void setPageStep( int ); - int value() const; - -public slots: - virtual void setValue( int ); - void addStep(); - void subtractStep(); - void addLine(); - void subtractLine(); - -signals: - void valueChanged( int value ); - void sliderPressed(); - void sliderMoved( int value ); - void sliderReleased(); - -protected: - void resizeEvent( TQResizeEvent * ); - void paintEvent( TQPaintEvent * ); - - void keyPressEvent( TQKeyEvent * ); - void mousePressEvent( TQMouseEvent * ); - void mouseReleaseEvent( TQMouseEvent * ); - void mouseMoveEvent( TQMouseEvent * ); -#ifndef TQT_NO_WHEELEVENT - void wheelEvent( TQWheelEvent * ); -#endif - void focusInEvent( TQFocusEvent *e ); - void focusOutEvent( TQFocusEvent *e ); - - void styleChange( TQStyle& ); - - void valueChange(); - void rangeChange(); - -private slots: - void repeatTimeout(); - -private: - enum State { Idle, Dragging, TimingUp, TimingDown }; - - void init(); - int positionFromValue( int ) const; - int valueFromPosition( int ) const; - void moveSlider( int ); - void reallyMoveSlider( int ); - void resetState(); - int available() const; - int goodPart( const TQPoint& ) const; - void initTicks(); - - TQSliderPrivate *d; - TQTimer *timer; - TQCOORD sliderPos; - int sliderVal; - TQCOORD clickOffset; - State state; - bool track; - TQCOORD tickOffset; - TickSetting ticks; - int tickInt; - Orientation orient; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQSlider( const TQSlider & ); - TQSlider &operator=( const TQSlider & ); -#endif -}; - -inline bool TQSlider::tracking() const -{ - return track; -} - -inline TQSlider::Orientation TQSlider::orientation() const -{ - return orient; -} - -inline int TQSlider::sliderStart() const -{ - return sliderPos; -} - -inline void TQSlider::setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw ) -{ - TQWidget::setSizePolicy( hor, ver, hfw ); -} - -#endif // TQT_NO_SLIDER - -#endif // TQSLIDER_H diff --git a/src/widgets/ntqspinbox.h b/src/widgets/ntqspinbox.h deleted file mode 100644 index 345857c74..000000000 --- a/src/widgets/ntqspinbox.h +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** -** -** Definition of TQSpinBox widget class -** -** Created : 970101 -** -** 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 TQSPINBOX_H -#define TQSPINBOX_H - -#ifndef QT_H -#include "tqwidget.h" -#include "ntqrangecontrol.h" -#endif // QT_H - -#ifndef TQT_NO_SPINBOX - -class TQLineEdit; -class TQValidator; -class TQSpinBoxPrivate; - -class TQ_EXPORT TQSpinBox: public TQWidget, public TQRangeControl -{ - TQ_OBJECT - TQ_ENUMS( ButtonSymbols ) - TQ_PROPERTY( TQString text READ text ) - TQ_PROPERTY( TQString prefix READ prefix WRITE setPrefix ) - TQ_PROPERTY( TQString suffix READ suffix WRITE setSuffix ) - TQ_PROPERTY( TQString cleanText READ cleanText ) - TQ_PROPERTY( TQString specialValueText READ specialValueText WRITE setSpecialValueText ) - TQ_PROPERTY( bool wrapping READ wrapping WRITE setWrapping ) - TQ_PROPERTY( ButtonSymbols buttonSymbols READ buttonSymbols WRITE setButtonSymbols ) - TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) - TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) - TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) - TQ_PROPERTY( int value READ value WRITE setValue ) - -public: - TQSpinBox( TQWidget* parent=0, const char* name=0 ); - TQSpinBox( int minValue, int maxValue, int step = 1, - TQWidget* parent=0, const char* name=0 ); - ~TQSpinBox(); - - TQString text() const; - - virtual TQString prefix() const; - virtual TQString suffix() const; - virtual TQString cleanText() const; - - virtual void setSpecialValueText( const TQString &text ); - TQString specialValueText() const; - - virtual void setWrapping( bool on ); - bool wrapping() const; - - enum ButtonSymbols { UpDownArrows, PlusMinus }; - virtual void setButtonSymbols( ButtonSymbols ); - ButtonSymbols buttonSymbols() const; - - virtual void setValidator( const TQValidator* v ); - const TQValidator * validator() const; - - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - - int minValue() const; - int maxValue() const; - void setMinValue( int ); - void setMaxValue( int ); - int lineStep() const; - void setLineStep( int ); - int value() const; - - TQRect upRect() const; - TQRect downRect() const; - -public slots: - virtual void setValue( int value ); - virtual void setPrefix( const TQString &text ); - virtual void setSuffix( const TQString &text ); - virtual void stepUp(); - virtual void stepDown(); - virtual void setEnabled( bool enabled ); - virtual void selectAll(); - -signals: - void valueChanged( int value ); - void valueChanged( const TQString &valueText ); - -protected: - virtual TQString mapValueToText( int value ); - virtual int mapTextToValue( bool* ok ); - TQString currentValueText(); - - virtual void updateDisplay(); - virtual void interpretText(); - - TQLineEdit* editor() const; - - virtual void valueChange(); - virtual void rangeChange(); - - bool eventFilter( TQObject* obj, TQEvent* ev ); - void resizeEvent( TQResizeEvent* ev ); -#ifndef TQT_NO_WHEELEVENT - void wheelEvent( TQWheelEvent * ); -#endif - void leaveEvent( TQEvent* ); - - void styleChange( TQStyle& ); - -protected slots: - void textChanged(); - -private: - void initSpinBox(); - TQSpinBoxPrivate* d; - TQLineEdit* vi; - TQValidator* validate; - TQString pfix; - TQString sfix; - TQString specText; - - uint wrap : 1; - uint edited : 1; - - void arrangeWidgets(); - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQSpinBox( const TQSpinBox& ); - TQSpinBox& operator=( const TQSpinBox& ); -#endif - -}; - -#endif // TQT_NO_SPINBOX - -#endif // TQSPINBOX_H diff --git a/src/widgets/qbutton.cpp b/src/widgets/qbutton.cpp index 31fbe6349..8446c7f46 100644 --- a/src/widgets/qbutton.cpp +++ b/src/widgets/qbutton.cpp @@ -47,8 +47,8 @@ #include "ntqaccel.h" #include "tqpixmapcache.h" #include "ntqapplication.h" -#include "ntqpushbutton.h" -#include "ntqradiobutton.h" +#include "tqpushbutton.h" +#include "tqradiobutton.h" #include "ntqguardedptr.h" #include "../kernel/qinternal_p.h" diff --git a/src/widgets/qbuttongroup.cpp b/src/widgets/qbuttongroup.cpp index c1a708b80..08c1919a7 100644 --- a/src/widgets/qbuttongroup.cpp +++ b/src/widgets/qbuttongroup.cpp @@ -43,7 +43,7 @@ #include "ntqbutton.h" #include "tqptrlist.h" #include "ntqapplication.h" -#include "ntqradiobutton.h" +#include "tqradiobutton.h" diff --git a/src/widgets/qcheckbox.cpp b/src/widgets/qcheckbox.cpp deleted file mode 100644 index 4e4d913ba..000000000 --- a/src/widgets/qcheckbox.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQCheckBox class -** -** Created : 940222 -** -** 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 "ntqcheckbox.h" -#ifndef TQT_NO_CHECKBOX -#include "tqpainter.h" -#include "ntqdrawutil.h" -#include "tqpixmap.h" -#include "tqpixmapcache.h" -#include "tqbitmap.h" -#include "tqtextstream.h" -#include "ntqapplication.h" -#include "tqstyle.h" - -/*! - \class TQCheckBox ntqcheckbox.h - \brief The TQCheckBox widget provides a checkbox with a text label. - - \ingroup basic - \mainclass - - TQCheckBox and TQRadioButton are both option buttons. That is, they - can be switched on (checked) or off (unchecked). The classes - differ in how the choices for the user are restricted. Radio - buttons define a "one of many" choice, whereas checkboxes provide - "many of many" choices. - - A TQButtonGroup can be used to group check buttons visually. - - Whenever a checkbox is checked or cleared it emits the signal - toggled(). Connect to this signal if you want to trigger an action - each time the checkbox changes state. You can use isChecked() to - query whether or not a checkbox is checked. - - \warning The toggled() signal can not be trusted for tristate - checkboxes. - - In addition to the usual checked and unchecked states, TQCheckBox - optionally provides a third state to indicate "no change". This - is useful whenever you need to give the user the option of neither - checking nor unchecking a checkbox. If you need this third state, - enable it with setTristate() and use state() to query the current - toggle state. When a tristate checkbox changes state, it emits the - stateChanged() signal. - - Just like TQPushButton, a checkbox can display text or a pixmap. - The text can be set in the constructor or with setText(); the - pixmap is set with setPixmap(). - - \important text(), setText(), text(), pixmap(), setPixmap(), - accel(), setAccel(), isToggleButton(), setDown(), isDown(), - isOn(), state(), autoRepeat(), isExclusiveToggle(), group(), - setAutoRepeat(), toggle(), pressed(), released(), clicked(), - toggled(), state() stateChanged() - - - - \sa TQButton TQRadioButton - \link guibooks.html#fowler Fowler: Check Box \endlink -*/ - -/*! - \property TQCheckBox::checked - \brief whether the checkbox is checked - - The default is unchecked, i.e. FALSE. -*/ - -/*! - \property TQCheckBox::autoMask - \brief whether the checkbox is automatically masked - - \sa TQWidget::setAutoMask() -*/ - -/*! - \property TQCheckBox::tristate - \brief whether the checkbox is a tri-state checkbox - - The default is two-state, i.e. tri-state is FALSE. -*/ - -/*! - Constructs a checkbox with no text. - - The \a parent and \a name arguments are sent to the TQWidget - constructor. -*/ - -TQCheckBox::TQCheckBox( TQWidget *parent, const char *name ) - : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) -{ - setToggleButton( TRUE ); - setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); -} - -/*! - Constructs a checkbox with text \a text. - - The \a parent and \a name arguments are sent to the TQWidget - constructor. -*/ - -TQCheckBox::TQCheckBox( const TQString &text, TQWidget *parent, const char *name ) - : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) -{ - setText( text ); - setToggleButton( TRUE ); - setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); -} - -/*! - Sets the checkbox to the "no change" state. - - \sa setTristate() -*/ -void TQCheckBox::setNoChange() -{ - setTristate(TRUE); - setState( NoChange ); -} - -void TQCheckBox::setTristate(bool y) -{ - setToggleType( y ? Tristate : Toggle ); -} - -bool TQCheckBox::isTristate() const -{ - return toggleType() == Tristate; -} - - -/*!\reimp -*/ -TQSize TQCheckBox::sizeHint() const -{ - // NB: TQRadioButton::sizeHint() is similar - constPolish(); - - TQPainter p(this); - TQSize sz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, - pixmap(), text()).size(); - - return (style().sizeFromContents(TQStyle::CT_CheckBox, this, sz). - expandedTo(TQApplication::globalStrut())); -} - - -/*!\reimp -*/ - -void TQCheckBox::drawButton( TQPainter *paint ) -{ - TQPainter *p = paint; - TQRect irect = TQStyle::visualRect( style().subRect(TQStyle::SR_CheckBoxIndicator, this), this ); - const TQColorGroup &cg = colorGroup(); - -#if !defined( TQT_NO_TEXTSTREAM ) && !defined( TQ_WS_MACX ) -# define SAVE_CHECKBOX_PIXMAPS -#endif -#if defined(SAVE_CHECKBOX_PIXMAPS) - TQString pmkey; // pixmap key - int kf = 0; - if ( isDown() ) - kf |= 1; - if ( isEnabled() ) - kf |= 2; - if ( hasFocus() ) - kf |= 4; // active vs. normal colorgroup - if( isActiveWindow() ) - kf |= 8; - if ( hasMouse() ) - kf |= 16; - - kf |= state() << 5; - TQTextOStream os(&pmkey); - os << "$qt_check_" << style().className() << "_" - << palette().serialNumber() << "_" << irect.width() << "x" << irect.height() << "_" << kf; - TQPixmap *pm = TQPixmapCache::find( pmkey ); - if ( pm ) { // pixmap exists - p->drawPixmap( irect.topLeft(), *pm ); - drawButtonLabel( p ); - return; - } - bool use_pm = TRUE; - TQPainter pmpaint; - int wx = 0, wy = 0; - if ( use_pm ) { - pm = new TQPixmap( irect.size() ); // create new pixmap - TQ_CHECK_PTR( pm ); - pm->fill( cg.background() ); - TQPainter::redirect(this, pm); - pmpaint.begin(this); - p = &pmpaint; // draw in pixmap - wx = irect.x(); // save x,y coords - wy = irect.y(); - irect.moveTopLeft(TQPoint(0, 0)); - p->setBackgroundColor( cg.background() ); - } -#endif - - TQStyle::SFlags flags = TQStyle::Style_Default; - if ( isEnabled() ) - flags |= TQStyle::Style_Enabled; - if ( hasFocus() ) - flags |= TQStyle::Style_HasFocus; - if ( isDown() ) - flags |= TQStyle::Style_Down; - if ( hasMouse() ) - flags |= TQStyle::Style_MouseOver; - if ( state() == TQButton::On ) - flags |= TQStyle::Style_On; - else if ( state() == TQButton::Off ) - flags |= TQStyle::Style_Off; - else if ( state() == TQButton::NoChange ) - flags |= TQStyle::Style_NoChange; - - style().drawControl(TQStyle::CE_CheckBox, p, this, irect, cg, flags); - -#if defined(SAVE_CHECKBOX_PIXMAPS) - if ( use_pm ) { - pmpaint.end(); - TQPainter::redirect( this, 0 ); - if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) { - TQBitmap bm( pm->size() ); - bm.fill( color0 ); - pmpaint.begin( &bm ); - style().drawControlMask(TQStyle::CE_CheckBox, &pmpaint, this, irect); - pmpaint.end(); - pm->setMask( bm ); - } - p = paint; // draw in default device - p->drawPixmap( wx, wy, *pm ); - if (!TQPixmapCache::insert(pmkey, pm) ) // save in cache - delete pm; - } -#endif - - drawButtonLabel( paint ); -} - - -/*!\reimp -*/ -void TQCheckBox::drawButtonLabel( TQPainter *p ) -{ - TQRect r = - TQStyle::visualRect( style().subRect(TQStyle::SR_CheckBoxContents, this), this ); - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (isDown()) - flags |= TQStyle::Style_Down; - if (state() == TQButton::On) - flags |= TQStyle::Style_On; - else if (state() == TQButton::Off) - flags |= TQStyle::Style_Off; - else if (state() == TQButton::NoChange) - flags |= TQStyle::Style_NoChange; - - style().drawControl(TQStyle::CE_CheckBoxLabel, p, this, r, colorGroup(), flags); -} - -/*! - \reimp -*/ -void TQCheckBox::resizeEvent( TQResizeEvent *e ) -{ - TQButton::resizeEvent(e); - if ( isVisible() ) { - TQPainter p(this); - TQSize isz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, - pixmap(), text()).size(); - TQSize wsz = (style().sizeFromContents(TQStyle::CT_CheckBox, this, isz). - expandedTo(TQApplication::globalStrut())); - - update(wsz.width(), isz.width(), 0, wsz.height()); - } - if (autoMask()) - updateMask(); -} - -/*! - \reimp -*/ -void TQCheckBox::updateMask() -{ - TQRect irect = - TQStyle::visualRect( style().subRect(TQStyle::SR_CheckBoxIndicator, this), this ); - - TQBitmap bm(width(), height()); - bm.fill(color0); - - TQPainter p( &bm, this ); - style().drawControlMask(TQStyle::CE_CheckBox, &p, this, irect); - if ( ! text().isNull() || ( pixmap() && ! pixmap()->isNull() ) ) { - TQRect crect = - TQStyle::visualRect( style().subRect( TQStyle::SR_CheckBoxContents, - this ), this ); - TQRect frect = - TQStyle::visualRect( style().subRect( TQStyle::SR_CheckBoxFocusRect, - this ), this ); - TQRect label(crect.unite(frect)); - p.fillRect(label, color1); - } - p.end(); - - setMask(bm); -} - -/*!\reimp*/ -bool TQCheckBox::hitButton( const TQPoint &pos ) const -{ - TQRect r = TQStyle::visualRect( style().subRect( TQStyle::SR_CheckBoxFocusRect, this ), this ); - if ( tqApp->reverseLayout() ) { - r.setRight( width() ); - } else { - r.setLeft( 0 ); - } - return r.contains( pos ); -} - -#endif diff --git a/src/widgets/qcombobox.cpp b/src/widgets/qcombobox.cpp deleted file mode 100644 index a491e7ca6..000000000 --- a/src/widgets/qcombobox.cpp +++ /dev/null @@ -1,2338 +0,0 @@ -/********************************************************************** -** -** Implementation of TQComboBox widget class -** -** Created : 940426 -** -** 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 "ntqcombobox.h" -#ifndef TQT_NO_COMBOBOX -#include "tqpopupmenu.h" -#include "ntqlistbox.h" -#include "tqpainter.h" -#include "ntqdrawutil.h" -#include "tqstrlist.h" -#include "tqpixmap.h" -#include "tqtimer.h" -#include "ntqapplication.h" -#include "ntqlineedit.h" -#include "tqbitmap.h" -#include "qeffects_p.h" -#include "tqstringlist.h" -#include "ntqcombobox.h" -#include "tqstyle.h" -#include -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif - -/*! - \class TQComboBox ntqcombobox.h - \brief The TQComboBox widget is a combined button and popup list. - - \ingroup basic - \mainclass - - A combobox is a selection widget which displays the current item - and can pop up a list of items. A combobox may be editable in - which case the user can enter arbitrary strings. - - Comboboxes provide a means of showing the user's current choice - out of a list of options in a way that takes up the minimum amount - of screen space. - - TQComboBox supports three different display styles: Aqua/Motif 1.x, - Motif 2.0 and Windows. In Motif 1.x, a combobox was called - XmOptionMenu. In Motif 2.0, OSF introduced an improved combobox - and named that XmComboBox. TQComboBox provides both. - - TQComboBox provides two different constructors. The simplest - constructor creates an "old-style" combobox in Motif (or Aqua) - style: - \code - TQComboBox *c = new TQComboBox( this, "read-only combobox" ); - \endcode - - The other constructor creates a new-style combobox in Motif style, - and can create both read-only and editable comboboxes: - \code - TQComboBox *c1 = new TQComboBox( FALSE, this, "read-only combobox" ); - TQComboBox *c2 = new TQComboBox( TRUE, this, "editable combobox" ); - \endcode - - New-style comboboxes use a list box in both Motif and Windows - styles, and both the content size and the on-screen size of the - list box can be limited with sizeLimit() and setMaxCount() - respectively. Old-style comboboxes use a popup in Aqua and Motif - style, and that popup will happily grow larger than the desktop if - you put enough data into it. - - The two constructors create identical-looking comboboxes in - Windows style. - - Comboboxes can contain pixmaps as well as strings; the - insertItem() and changeItem() functions are suitably overloaded. - For editable comboboxes, the function clearEdit() is provided, - to clear the displayed string without changing the combobox's - contents. - - A combobox emits two signals, activated() and highlighted(), when - a new item has been activated (selected) or highlighted (made - current). Both signals exist in two versions, one with a \c - TQString argument and one with an \c int argument. If the user - highlights or activates a pixmap, only the \c int signals are - emitted. Whenever the text of an editable combobox is changed the - textChanged() signal is emitted. - - When the user enters a new string in an editable combobox, the - widget may or may not insert it, and it can insert it in several - locations. The default policy is is \c AtBottom but you can change - this using setInsertionPolicy(). - - It is possible to constrain the input to an editable combobox - using TQValidator; see setValidator(). By default, any input is - accepted. - - If the combobox is not editable then it has a default - focusPolicy() of \c TabFocus, i.e. it will not grab focus if - clicked. This differs from both Windows and Motif. If the combobox - is editable then it has a default focusPolicy() of \c StrongFocus, - i.e. it will grab focus if clicked. - - A combobox can be populated using the insert functions, - insertStringList() and insertItem() for example. Items can be - changed with changeItem(). An item can be removed with - removeItem() and all items can be removed with clear(). The text - of the current item is returned by currentText(), and the text of - a numbered item is returned with text(). The current item can be - set with setCurrentItem() or setCurrentText(). The number of items - in the combobox is returned by count(); the maximum number of - items can be set with setMaxCount(). You can allow editing using - setEditable(). For editable comboboxes you can set auto-completion - using setAutoCompletion() and whether or not the user can add - duplicates is set with setDuplicatesEnabled(). - - (Motif 1, read-only)
- (Motif 2, editable)
- (Motif 2, read-only)
- (Windows style) - - Depending on the style, TQComboBox will use a TQListBox or a - TQPopupMenu to display the list of items. See setListBox() for - more information. - - \sa TQLineEdit TQListBox TQSpinBox TQRadioButton TQButtonGroup - \link guibooks.html#fowler GUI Design Handbook: Combo Box,\endlink - \link guibooks.html#fowler GUI Design Handbook: Drop-Down List Box.\endlink -*/ - - -/*! - \enum TQComboBox::Policy - - This enum specifies what the TQComboBox should do when a new string - is entered by the user. - - \value NoInsertion the string will not be inserted into the - combobox. - - \value AtTop insert the string as the first item in the combobox. - - \value AtCurrent replace the previously selected item with the - string the user has entered. - - \value AtBottom insert the string as the last item in the - combobox. - - \value AfterCurrent insert the string after the previously - selected item. - - \value BeforeCurrent insert the string before the previously - selected item. - - activated() is always emitted when the string is entered. - - If inserting the new string would cause the combobox to breach its - content size limit, the item at the other end of the list is - deleted. The definition of "other end" is - implementation-dependent. -*/ - - -/*! - \fn void TQComboBox::activated( int index ) - - This signal is emitted when a new item has been activated - (selected). The \a index is the position of the item in the - combobox. - - This signal is not emitted if the item is changed - programmatically, e.g. using setCurrentItem(). -*/ - -/*! - \overload void TQComboBox::activated( const TQString &string ) - - This signal is emitted when a new item has been activated - (selected). \a string is the selected string. - - You can also use the activated(int) signal, but be aware that its - argument is meaningful only for selected strings, not for user - entered strings. -*/ - -/*! - \fn void TQComboBox::highlighted( int index ) - - This signal is emitted when a new item has been set to be the - current item. The \a index is the position of the item in the - combobox. - - This signal is not emitted if the item is changed - programmatically, e.g. using setCurrentItem(). -*/ - -/*! - \overload void TQComboBox::highlighted( const TQString &string ) - - This signal is emitted when a new item has been set to be the - current item. \a string is the item's text. - - You can also use the highlighted(int) signal. -*/ - -/*! - \fn void TQComboBox::textChanged( const TQString &string ) - - This signal is used for editable comboboxes. It is emitted - whenever the contents of the text entry field changes. \a string - contains the new text. -*/ - -/*! - \property TQComboBox::autoCompletion - \brief whether auto-completion is enabled - - This property can only be set for editable comboboxes, for - non-editable comboboxes it has no effect. It is FALSE by default. -*/ - -/*! - \property TQComboBox::autoMask - \brief whether the combobox is automatically masked - - \sa TQWidget::setAutoMask() -*/ - -/*! \property TQComboBox::autoResize - \brief whether auto resize is enabled - \obsolete - - If this property is set to TRUE then the combobox will resize itself - whenever its contents change. The default is FALSE. -*/ - -/*! - \property TQComboBox::count - \brief the number of items in the combobox -*/ - -/*! - \property TQComboBox::currentItem - \brief the index of the current item in the combobox - - Note that the activated() and highlighted() signals are only - emitted when the user changes the current item, not when it is - changed programmatically. -*/ - -/*! - \property TQComboBox::currentText - \brief the text of the combobox's current item -*/ - -/*! - \property TQComboBox::duplicatesEnabled - \brief whether duplicates are allowed - - If the combobox is editable and the user enters some text in the - combobox's lineedit and presses Enter (and the insertionPolicy() - is not \c NoInsertion), then what happens is this: - \list - \i If the text is not already in the list, the text is inserted. - \i If the text is in the list and this property is TRUE (the - default), the text is inserted. - \i If the text is in the list and this property is FALSE, the text - is \e not inserted; instead the item which has matching text becomes - the current item. - \endlist - - This property only affects user-interaction. You can use - insertItem() to insert duplicates if you wish regardless of this - setting. -*/ - -/*! - \property TQComboBox::editable - \brief whether the combobox is editable - - This property's default is FALSE. Note that the combobox will be - cleared if this property is set to TRUE for a 1.x Motif style - combobox. To avoid this, use setEditable() before inserting any - items. Also note that the 1.x version of Motif didn't have any - editable comboboxes, so the combobox will change it's appearance - to a 2.0 style Motif combobox is it is set to be editable. -*/ - -/*! - \property TQComboBox::insertionPolicy - \brief the position of the items inserted by the user - - The default insertion policy is \c AtBottom. See \l Policy. -*/ - -/*! - \property TQComboBox::maxCount - \brief the maximum number of items allowed in the combobox -*/ - -/*! - \property TQComboBox::sizeLimit - \brief the maximum on-screen size of the combobox. - - This property is ignored for both Motif 1.x style and non-editable - comboboxes in Mac style. The default limit is ten - lines. If the number of items in the combobox is or grows larger - than lines, a scrollbar is added. -*/ - -class TQComboBoxPopup : public TQPopupMenu -{ -public: - TQComboBoxPopup( TQWidget *parent=0, const char *name=0 ) - : TQPopupMenu( parent, name ) - { - } - - int itemHeight( int index ) - { - return TQPopupMenu::itemHeight( index ); - } -}; - -static inline TQString escapedComboString(const TQString &str) -{ - TQString stringToReturn = str; - return stringToReturn.replace('&', "&&"); -} - -class TQComboBoxPopupItem : public TQCustomMenuItem -{ - TQListBoxItem *li; - TQSize sc; // Size cache optimization -public: - TQComboBoxPopupItem(TQListBoxItem *i) : TQCustomMenuItem(), li(i), sc(0, 0) { } - virtual bool fullSpan() const { return TRUE; } - virtual void paint( TQPainter*, const TQColorGroup&, bool, bool, int, int, int, int); - virtual TQSize sizeHint() { if (sc.isNull()) sc = TQSize(li->width(li->listBox()), TQMAX(25, li->height(li->listBox()))); return sc; } -}; -void TQComboBoxPopupItem::paint( TQPainter* p, const TQColorGroup&, bool, - bool, int x, int y, int, int) -{ - p->save(); - p->translate(x, y + ((sizeHint().height() / 2) - (li->height(li->listBox()) / 2))); - li->paint(p); - p->restore(); -} - - -class TQComboBoxData -{ -public: - TQComboBoxData( TQComboBox *cb ): ed( 0 ), usingLBox( FALSE ), pop( 0 ), lBox( 0 ), combo( cb ) - { - duplicatesEnabled = TRUE; - cb->setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); - } - - inline bool usingListBox() { return usingLBox; } - inline TQListBox * listBox() { return lBox; } - inline TQComboBoxPopup * popup() { return pop; } - void updateLinedGeometry(); - void setListBox( TQListBox *l ); - void setPopupMenu( TQComboBoxPopup * pm, bool isPopup=TRUE ); - - int current; - int maxCount; - int sizeLimit; - TQComboBox::Policy p; - bool autoresize; - bool poppedUp; - bool mouseWasInsidePopup; - bool arrowPressed; - bool arrowDown; - bool discardNextMousePress; - bool shortClick; - bool useCompletion; - bool completeNow; - int completeAt; - bool duplicatesEnabled; - int fullHeight, currHeight; - - TQLineEdit * ed; // /bin/ed rules! - TQTimer *completionTimer; - - TQSize sizeHint; - -private: - bool usingLBox; - TQComboBoxPopup *pop; - TQListBox *lBox; - TQComboBox *combo; - -}; - -void TQComboBoxData::updateLinedGeometry() -{ - if ( !ed || !combo ) - return; - TQRect r = TQStyle::visualRect( combo->style().querySubControlMetrics(TQStyle::CC_ComboBox, combo, - TQStyle::SC_ComboBoxEditField), combo ); - - const TQPixmap *pix = current < combo->count() ? combo->pixmap( current ) : 0; - if ( pix && pix->width() < r.width() ) - r.setLeft( r.left() + pix->width() + 4 ); - if ( r != ed->geometry() ) - ed->setGeometry( r ); -} - -void TQComboBoxData::setListBox( TQListBox *l ) -{ - lBox = l; - usingLBox = TRUE; - l->setMouseTracking( TRUE ); -#ifdef TQ_WS_X11 - l->x11SetWindowType( TQWidget::X11WindowTypeCombo ); - l->x11SetWindowTransient( combo->topLevelWidget()); -#endif -} - -void TQComboBoxData::setPopupMenu( TQComboBoxPopup * pm, bool isPopup ) -{ - pop = pm; - if(isPopup) - usingLBox = FALSE; -#ifdef TQ_WS_X11 - if( pm ) { - pm->x11SetWindowType( TQWidget::X11WindowTypeCombo ); - pm->x11SetWindowTransient( combo->topLevelWidget()); - } -#endif -} - -static inline bool checkInsertIndex( const char *method, const char * name, - int count, int *index) -{ - bool range_err = (*index > count); -#if defined(QT_CHECK_RANGE) - if ( range_err ) - tqWarning( "TQComboBox::%s: (%s) Index %d out of range", - method, name ? name : "", *index ); -#else - Q_UNUSED( method ) - Q_UNUSED( name ) -#endif - if ( *index < 0 ) // append - *index = count; - return !range_err; -} - - -static inline bool checkIndex( const char *method, const char * name, - int count, int index ) -{ - bool range_err = (index >= count); -#if defined(QT_CHECK_RANGE) - if ( range_err ) - tqWarning( "TQComboBox::%s: (%s) Index %i out of range", - method, name ? name : "", index ); -#else - Q_UNUSED( method ) - Q_UNUSED( name ) -#endif - return !range_err; -} - - - -/*! - Constructs a combobox widget with parent \a parent called \a name. - - This constructor creates a popup list if the program uses Motif - (or Aqua) look and feel; this is compatible with Motif 1.x and - Aqua. - - Note: If you use this constructor to create your TQComboBox, then - the pixmap() function will always return 0. To workaround this, - use the other constructor. - -*/ - - - -TQComboBox::TQComboBox( TQWidget *parent, const char *name ) - : TQWidget( parent, name, WNoAutoErase ) -{ - d = new TQComboBoxData( this ); - if ( style().styleHint(TQStyle::SH_ComboBox_Popup, this) || - style().styleHint(TQStyle::SH_GUIStyle) == TQt::MotifStyle ) { - d->setPopupMenu( new TQComboBoxPopup( this, "in-combo" ) ); - d->popup()->setFont( font() ); - connect( d->popup(), TQ_SIGNAL(activated(int)), - TQ_SLOT(internalActivate(int)) ); - connect( d->popup(), TQ_SIGNAL(highlighted(int)), - TQ_SLOT(internalHighlight(int)) ); - } else { - setUpListBox(); - } - d->ed = 0; - d->current = 0; - d->maxCount = INT_MAX; - d->sizeLimit = 10; - d->p = AtBottom; - d->autoresize = FALSE; - d->poppedUp = FALSE; - d->arrowDown = FALSE; - d->arrowPressed = FALSE; - d->discardNextMousePress = FALSE; - d->shortClick = FALSE; - d->useCompletion = FALSE; - d->completeAt = 0; - d->completeNow = FALSE; - d->completionTimer = new TQTimer( this ); - - setFocusPolicy( TabFocus ); - setBackgroundMode( PaletteButton ); -} - - -/*! - Constructs a combobox with a maximum size and either Motif 2.0 or - Windows look and feel. - - The input field can be edited if \a rw is TRUE, otherwise the user - may only choose one of the items in the combobox. - - The \a parent and \a name arguments are passed on to the TQWidget - constructor. -*/ - - -TQComboBox::TQComboBox( bool rw, TQWidget *parent, const char *name ) - : TQWidget( parent, name, WNoAutoErase ) -{ - d = new TQComboBoxData( this ); - setUpListBox(); - - if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) - d->popup()->setItemChecked(d->current, FALSE); - d->current = 0; - d->maxCount = INT_MAX; - setSizeLimit(10); - d->p = AtBottom; - d->autoresize = FALSE; - d->poppedUp = FALSE; - d->arrowDown = FALSE; - d->discardNextMousePress = FALSE; - d->shortClick = FALSE; - d->useCompletion = FALSE; - d->completeAt = 0; - d->completeNow = FALSE; - d->completionTimer = new TQTimer( this ); - - setFocusPolicy( StrongFocus ); - - d->ed = 0; - if ( rw ) - setUpLineEdit(); - setBackgroundMode( PaletteButton, PaletteBase ); -} - - - -/*! - Destroys the combobox. -*/ - -TQComboBox::~TQComboBox() -{ - delete d; -} - -void TQComboBox::setDuplicatesEnabled( bool enable ) -{ - d->duplicatesEnabled = enable; -} - -bool TQComboBox::duplicatesEnabled() const -{ - return d->duplicatesEnabled; -} - -int TQComboBox::count() const -{ - if ( d->usingListBox() ) - return d->listBox()->count(); - else - return d->popup()->count(); -} - - -/*! - \overload - - Inserts the \a list of strings at position \a index in the - combobox. - - This is only for compatibility since it does not support Unicode - strings. See insertStringList(). -*/ - -void TQComboBox::insertStrList( const TQStrList &list, int index ) -{ - insertStrList( &list, index ); -} - -/*! - \overload - - Inserts the \a list of strings at position \a index in the - combobox. - - This is only for compatibility since it does not support Unicode - strings. See insertStringList(). -*/ - -void TQComboBox::insertStrList( const TQStrList *list, int index ) -{ - if ( !list ) { -#if defined(QT_CHECK_NULL) - Q_ASSERT( list != 0 ); -#endif - return; - } - TQStrListIterator it( *list ); - const char* tmp; - if ( index < 0 ) - index = count(); - while ( (tmp=it.current()) ) { - ++it; - if ( d->usingListBox() ) - d->listBox()->insertItem( TQString::fromLatin1(tmp), index ); - else - d->popup()->insertItem( escapedComboString(TQString::fromLatin1(tmp)), index, index ); - if ( index++ == d->current && d->current < count() ) { - if ( d->ed ) { - d->ed->setText( text( d->current ) ); - d->updateLinedGeometry(); - } else - update(); - currentChanged(); - } - } - if ( index != count() ) - reIndex(); -} - -/*! - Inserts the \a list of strings at position \a index in the - combobox. -*/ - -void TQComboBox::insertStringList( const TQStringList &list, int index ) -{ - TQStringList::ConstIterator it = list.begin(); - if ( index < 0 ) - index = count(); - while ( it != list.end() ) { - if ( d->usingListBox() ) - d->listBox()->insertItem( *it, index ); - else - d->popup()->insertItem( escapedComboString(*it), index, index ); - if ( index++ == d->current && d->current < count() ) { - if ( d->ed ) { - d->ed->setText( text( d->current ) ); - d->updateLinedGeometry(); - } else - update(); - currentChanged(); - } - ++it; - } - if ( index != count() ) - reIndex(); -} - -/*! - Inserts the array of char * \a strings at position \a index in the - combobox. - - The \a numStrings argument is the number of strings. If \a - numStrings is -1 (default), the \a strings array must be - terminated with 0. - - Example: - \code - static const char* items[] = { "red", "green", "blue", 0 }; - combo->insertStrList( items ); - \endcode - - \sa insertStringList() -*/ - -void TQComboBox::insertStrList( const char **strings, int numStrings, int index) -{ - if ( !strings ) { -#if defined(QT_CHECK_NULL) - Q_ASSERT( strings != 0 ); -#endif - return; - } - if ( index < 0 ) - index = count(); - int i = 0; - while ( (numStrings<0 && strings[i]!=0) || iusingListBox() ) - d->listBox()->insertItem( TQString::fromLatin1(strings[i]), index ); - else - d->popup()->insertItem( escapedComboString(TQString::fromLatin1(strings[i])), index, index ); - i++; - if ( index++ == d->current && d->current < count() ) { - if ( d->ed ) { - d->ed->setText( text( d->current ) ); - d->updateLinedGeometry(); - } else - update(); - currentChanged(); - } - } - if ( index != count() ) - reIndex(); -} - - -/*! - Inserts a text item with text \a t, at position \a index. The item - will be appended if \a index is negative. -*/ - -void TQComboBox::insertItem( const TQString &t, int index ) -{ - int cnt = count(); - if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) ) - return; - if ( d->usingListBox() ) - d->listBox()->insertItem( t, index ); - else - d->popup()->insertItem( escapedComboString(t), index, index ); - if ( index != cnt ) - reIndex(); - if ( index == d->current && d->current < count() ) { - if ( d->ed ) { - d->ed->setText( text( d->current ) ); - d->updateLinedGeometry(); - } else - update(); - } - if ( index == d->current ) - currentChanged(); -} - -/*! - \overload - - Inserts a \a pixmap item at position \a index. The item will be - appended if \a index is negative. -*/ - -void TQComboBox::insertItem( const TQPixmap &pixmap, int index ) -{ - int cnt = count(); - if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) ) - return; - if ( d->usingListBox() ) - d->listBox()->insertItem( pixmap, index ); - else - d->popup()->insertItem( pixmap, index, index ); - if ( index != cnt ) - reIndex(); - if ( index == d->current && d->current < count() ) { - if ( d->ed ) { - d->ed->setText( text( d->current ) ); - d->updateLinedGeometry(); - } else - update(); - } - if ( index == d->current ) - currentChanged(); -} - -/*! - \overload - - Inserts a \a pixmap item with additional text \a text at position - \a index. The item will be appended if \a index is negative. -*/ - -void TQComboBox::insertItem( const TQPixmap &pixmap, const TQString& text, int index ) -{ - int cnt = count(); - if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) ) - return; - if ( d->usingListBox() ) - d->listBox()->insertItem( pixmap, text, index ); - else - d->popup()->insertItem( pixmap, escapedComboString(text), index, index ); - if ( index != cnt ) - reIndex(); - if ( index == d->current && d->current < count() ) { - if ( d->ed ) { - d->ed->setText( this->text( d->current ) ); - d->updateLinedGeometry(); - } else - update(); - } - if ( index == d->current ) - currentChanged(); -} - - -/*! - Removes the item at position \a index. -*/ - -void TQComboBox::removeItem( int index ) -{ - int cnt = count(); - if ( !checkIndex( "removeItem", name(), cnt, index ) ) - return; - if ( d->usingListBox() ) { - if ( style().styleHint(TQStyle::SH_ComboBox_Popup, this) && d->popup() ) - d->popup()->removeItemAt( index ); - d->listBox()->removeItem( index ); - } else { - d->popup()->removeItemAt( index ); - } - if ( index != cnt-1 ) - reIndex(); - if ( index == d->current ) { - if ( d->ed ) { - TQString s = TQString::fromLatin1(""); - if (d->current < cnt - 1) - s = text( d->current ); - d->ed->setText( s ); - d->updateLinedGeometry(); - } - else { - if ( d->usingListBox() ) { - d->current = d->listBox()->currentItem(); - } else { - if (d->current > count()-1 && d->current > 0) - d->current--; - } - update(); - } - currentChanged(); - } - else { - if ( !d->ed ) { - if (d->current < cnt - 1) - setCurrentItem( d->current ); - else - setCurrentItem( d->current - 1 ); - } - } - -} - - -/*! - Removes all combobox items. -*/ - -void TQComboBox::clear() -{ - if ( d->usingListBox() ) { - if ( style().styleHint(TQStyle::SH_ComboBox_Popup, this) && d->popup() ) - d->popup()->clear(); - d->listBox()->resize( 0, 0 ); - d->listBox()->clear(); - } else { - d->popup()->clear(); - } - - if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) - d->popup()->setItemChecked(d->current, FALSE); - d->current = 0; - if ( d->ed ) { - d->ed->setText( TQString::fromLatin1("") ); - d->updateLinedGeometry(); - } - currentChanged(); -} - - -TQString TQComboBox::currentText() const -{ - if ( d->ed ) - return d->ed->text(); - else if ( d->current < count() ) - return text( currentItem() ); - else - return TQString::null; -} - -void TQComboBox::setCurrentText( const TQString& txt ) -{ - int i; - for ( i = 0; i < count(); i++) - if ( text( i ) == txt ) - break; - if ( i < count() ) - setCurrentItem( i ); - else if ( d->ed ) - d->ed->setText( txt ); - else - changeItem( txt, currentItem() ); -} - - -/*! - Returns the text item at position \a index, or TQString::null if - the item is not a string. - - \sa currentText() -*/ - -TQString TQComboBox::text( int index ) const -{ - if ( !checkIndex( "text", name(), count(), index ) ) - return TQString::null; - if ( d->usingListBox() ) { - return d->listBox()->text( index ); - } else { - TQString retText = d->popup()->text(index); - retText.replace("&&", "&"); - return retText; - } -} - -/*! - Returns the pixmap item at position \a index, or 0 if the item is - not a pixmap. -*/ - -const TQPixmap *TQComboBox::pixmap( int index ) const -{ - if ( !checkIndex( "pixmap", name(), count(), index ) ) - return 0; - if ( d->usingListBox() ) - return d->listBox()->pixmap( index ); - else - return d->popup()->pixmap( index ); -} - -/*! - Replaces the item at position \a index with the text \a t. -*/ - -void TQComboBox::changeItem( const TQString &t, int index ) -{ - if ( !checkIndex( "changeItem", name(), count(), index ) ) - return; - if ( d->usingListBox() ) - d->listBox()->changeItem( t, index ); - else - d->popup()->changeItem( t, index ); - if ( index == d->current ) { - if ( d->ed ) { - d->ed->setText( text( d->current ) ); - d->updateLinedGeometry(); - } else - update(); - } -} - -/*! - \overload - - Replaces the item at position \a index with the pixmap \a im, - unless the combobox is editable. - - \sa insertItem() -*/ - -void TQComboBox::changeItem( const TQPixmap &im, int index ) -{ - if ( !checkIndex( "changeItem", name(), count(), index ) ) - return; - if ( d->usingListBox() ) - d->listBox()->changeItem( im, index ); - else - d->popup()->changeItem( im, index ); - if ( index == d->current ) - update(); -} - -/*! - \overload - - Replaces the item at position \a index with the pixmap \a im and - the text \a t. - - \sa insertItem() -*/ - -void TQComboBox::changeItem( const TQPixmap &im, const TQString &t, int index ) -{ - if ( !checkIndex( "changeItem", name(), count(), index ) ) - return; - if ( d->usingListBox() ) - d->listBox()->changeItem( im, t, index ); - else - d->popup()->changeItem( im, t, index ); - if ( index == d->current ) - update(); -} - - -int TQComboBox::currentItem() const -{ - return d->current; -} - -void TQComboBox::setCurrentItem( int index ) -{ - if ( index == d->current && !d->ed ) { - return; - } - if ( !checkIndex( "setCurrentItem", name(), count(), index ) ) { - return; - } - - if ( d->usingListBox() && !( listBox()->item(index) && listBox()->item(index)->isSelectable() ) ) - return; - - if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) - d->popup()->setItemChecked(d->current, FALSE); - d->current = index; - d->completeAt = 0; - if ( d->ed ) { - d->ed->setText( text( index ) ); - d->updateLinedGeometry(); - } - // ### We want to keep ListBox's currentItem in sync, even if NOT popuped... - if ( d->usingListBox() && d->listBox() ) { - d->listBox()->setCurrentItem( index ); - } else { - internalHighlight( index ); - // internalActivate( index ); ### this leads to weird behavior, as in 3.0.1 - } - - currentChanged(); -} - -bool TQComboBox::autoResize() const -{ - return d->autoresize; -} - -void TQComboBox::setAutoResize( bool enable ) -{ - if ( (bool)d->autoresize != enable ) { - d->autoresize = enable; - if ( enable ) - adjustSize(); - } -} - - -/*! - \reimp - - This implementation caches the size hint to avoid resizing when - the contents change dynamically. To invalidate the cached value - call setFont(). -*/ -TQSize TQComboBox::sizeHint() const -{ - if ( isVisible() && d->sizeHint.isValid() ) - return d->sizeHint; - - constPolish(); - int i, w; - TQFontMetrics fm = fontMetrics(); - - int maxW = count() ? 18 : 7 * fm.width(TQChar('x')) + 18; - int maxH = TQMAX( fm.lineSpacing(), 14 ) + 2; - - if ( !d->usingListBox() ) { - w = d->popup()->sizeHint().width() - 2* d->popup()->frameWidth(); - if ( w > maxW ) - maxW = w; - } else { - for( i = 0; i < count(); i++ ) { - w = d->listBox()->item( i )->width( d->listBox() ); - if ( w > maxW ) - maxW = w; - } - } - - d->sizeHint = (style().sizeFromContents(TQStyle::CT_ComboBox, this, - TQSize(maxW, maxH)). - expandedTo(TQApplication::globalStrut())); - - return d->sizeHint; -} - - -/*! - \internal - Receives activated signals from an internal popup list and emits - the activated() signal. -*/ - -void TQComboBox::internalActivate( int index ) -{ - if ( d->current != index ) { - if ( !d->usingListBox() || listBox()->item( index )->isSelectable() ) { - if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) - d->popup()->setItemChecked(d->current, FALSE); - d->current = index; - currentChanged(); - } - } - if ( d->usingListBox() ) - popDownListBox(); - else - d->popup()->removeEventFilter( this ); - d->poppedUp = FALSE; - - TQString t( text( index ) ); - if ( d->ed ) { - d->ed->setText( t ); - d->updateLinedGeometry(); - } - emit activated( index ); - emit activated( t ); -} - -/*! - \internal - Receives highlighted signals from an internal popup list and emits - the highlighted() signal. -*/ - -void TQComboBox::internalHighlight( int index ) -{ - emit highlighted( index ); - TQString t = text( index ); - if ( !t.isNull() ) - emit highlighted( t ); -} - -/*! - \internal - Receives timeouts after a click. Used to decide if a Motif style - popup should stay up or not after a click. -*/ -void TQComboBox::internalClickTimeout() -{ - d->shortClick = FALSE; -} - -/*! - Sets the palette for both the combobox button and the combobox - popup list to \a palette. -*/ - -void TQComboBox::setPalette( const TQPalette &palette ) -{ - TQWidget::setPalette( palette ); - if ( d->listBox() ) - d->listBox()->setPalette( palette ); - if ( d->popup() ) - d->popup()->setPalette( palette ); -} - -/*! - Sets the font for both the combobox button and the combobox popup - list to \a font. -*/ - -void TQComboBox::setFont( const TQFont &font ) -{ - d->sizeHint = TQSize(); // invalidate size hint - TQWidget::setFont( font ); - if ( d->usingListBox() ) - d->listBox()->setFont( font ); - else - d->popup()->setFont( font ); - if (d->ed) - d->ed->setFont( font ); - if ( d->autoresize ) - adjustSize(); -} - - -/*!\reimp -*/ - -void TQComboBox::resizeEvent( TQResizeEvent * e ) -{ - if ( d->ed ) - d->updateLinedGeometry(); - if ( d->listBox() ) - d->listBox()->resize( width(), d->listBox()->height() ); - TQWidget::resizeEvent( e ); -} - -/*!\reimp -*/ - -void TQComboBox::paintEvent( TQPaintEvent * ) -{ - TQPainter p( this ); - const TQColorGroup & g = colorGroup(); - p.setPen(g.text()); - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (hasMouse()) - flags |= TQStyle::Style_MouseOver; - - if ( width() < 5 || height() < 5 ) { - qDrawShadePanel( &p, rect(), g, FALSE, 2, - &g.brush( TQColorGroup::Button ) ); - return; - } - - bool reverse = TQApplication::reverseLayout(); - if ( !d->usingListBox() && - style().styleHint(TQStyle::SH_GUIStyle) == TQt::MotifStyle) { // motif 1.x style - int dist, buttonH, buttonW; - dist = 8; - buttonH = 7; - buttonW = 11; - int xPos; - int x0; - int w = width() - dist - buttonW - 1; - if ( reverse ) { - xPos = dist + 1; - x0 = xPos + 4; - } else { - xPos = w; - x0 = 4; - } - qDrawShadePanel( &p, rect(), g, FALSE, - style().pixelMetric(TQStyle::PM_DefaultFrameWidth, this), - &g.brush( TQColorGroup::Button ) ); - qDrawShadePanel( &p, xPos, (height() - buttonH)/2, - buttonW, buttonH, g, FALSE, - style().pixelMetric(TQStyle::PM_DefaultFrameWidth, this) ); - TQRect clip( x0, 2, w - 2 - 4 - 5, height() - 4 ); - TQString str = d->popup()->text( this->d->current ); - if ( !str.isNull() ) { - p.drawText( clip, AlignCenter | SingleLine, str ); - } - - TQPixmap *pix = d->popup()->pixmap( this->d->current ); - TQIconSet *iconSet = d->popup()->iconSet( this->d->current ); - if (pix || iconSet) { - TQPixmap pm = ( pix ? *pix : iconSet->pixmap() ); - p.setClipRect( clip ); - p.drawPixmap( 4, (height()-pm.height())/2, pm ); - p.setClipping( FALSE ); - } - - if ( hasFocus() ) - p.drawRect( xPos - 5, 4, width() - xPos + 1 , height() - 8 ); - } else if(!d->usingListBox()) { - style().drawComplexControl( TQStyle::CC_ComboBox, &p, this, rect(), g, - flags, (uint)TQStyle::SC_All, - (d->arrowDown ? - TQStyle::SC_ComboBoxArrow : - TQStyle::SC_None )); - - TQRect re = style().querySubControlMetrics( TQStyle::CC_ComboBox, this, - TQStyle::SC_ComboBoxEditField ); - re = TQStyle::visualRect(re, this); - p.setClipRect( re ); - - TQString str = d->popup()->text( this->d->current ); - TQPixmap *pix = d->popup()->pixmap( this->d->current ); - if ( !str.isNull() ) { - p.save(); - p.setFont(font()); - TQFontMetrics fm(font()); - int x = re.x(), y = re.y() + fm.ascent(); - if( pix ) - x += pix->width() + 5; - p.drawText( x, y, str ); - p.restore(); - } - if ( pix ) { - p.fillRect( re.x(), re.y(), pix->width() + 4, re.height(), - colorGroup().brush( TQColorGroup::Base ) ); - p.drawPixmap( re.x() + 2, re.y() + - ( re.height() - pix->height() ) / 2, *pix ); - } - } else { - style().drawComplexControl( TQStyle::CC_ComboBox, &p, this, rect(), g, - flags, (uint)TQStyle::SC_All, - (d->arrowDown ? - TQStyle::SC_ComboBoxArrow : - TQStyle::SC_None )); - - TQRect re = style().querySubControlMetrics( TQStyle::CC_ComboBox, this, - TQStyle::SC_ComboBoxEditField ); - re = TQStyle::visualRect(re, this); - p.setClipRect( re ); - - if ( !d->ed ) { - TQListBoxItem * item = d->listBox()->item( d->current ); - if ( item ) { - int itemh = item->height( d->listBox() ); - p.translate( re.x(), re.y() + (re.height() - itemh)/2 ); - item->paint( &p ); - } - } else if ( d->listBox() && d->listBox()->item( d->current ) ) { - TQListBoxItem * item = d->listBox()->item( d->current ); - const TQPixmap *pix = item->pixmap(); - if ( pix ) { - p.fillRect( re.x(), re.y(), pix->width() + 4, re.height(), - colorGroup().brush( TQColorGroup::Base ) ); - p.drawPixmap( re.x() + 2, re.y() + - ( re.height() - pix->height() ) / 2, *pix ); - } - } - p.setClipping( FALSE ); - } -} - - -/*!\reimp -*/ - -void TQComboBox::mousePressEvent( TQMouseEvent *e ) -{ - if ( e->button() != LeftButton ) - return; - if ( d->discardNextMousePress ) { - d->discardNextMousePress = FALSE; - return; - } - TQRect arrowRect = style().querySubControlMetrics( TQStyle::CC_ComboBox, this, - TQStyle::SC_ComboBoxArrow); - arrowRect = TQStyle::visualRect(arrowRect, this); - - // Correction for motif style, where arrow is smaller - // and thus has a rect that doesn't fit the button. - arrowRect.setHeight( TQMAX( height() - (2 * arrowRect.y()), arrowRect.height() ) ); - - if ( count() && ( !editable() || arrowRect.contains( e->pos() ) ) ) { - d->arrowPressed = FALSE; - - if ( d->usingListBox() ) { - listBox()->blockSignals( TRUE ); - tqApp->sendEvent( listBox(), e ); // trigger the listbox's autoscroll - listBox()->setCurrentItem(d->current); - listBox()->blockSignals( FALSE ); - popup(); - if ( arrowRect.contains( e->pos() ) ) { - d->arrowPressed = TRUE; - d->arrowDown = TRUE; - repaint( FALSE ); - } - } else { - popup(); - } - TQTimer::singleShot( 200, this, TQ_SLOT(internalClickTimeout())); - d->shortClick = TRUE; - } -} - -/*!\reimp -*/ - -void TQComboBox::mouseMoveEvent( TQMouseEvent * ) -{ -} - -/*!\reimp -*/ - -void TQComboBox::mouseReleaseEvent( TQMouseEvent * ) -{ -} - -/*!\reimp -*/ - -void TQComboBox::mouseDoubleClickEvent( TQMouseEvent *e ) -{ - mousePressEvent( e ); -} - - -/*!\reimp -*/ - -void TQComboBox::keyPressEvent( TQKeyEvent *e ) -{ - int c = currentItem(); - if ( ( e->key() == Key_F4 && e->state() == 0 ) || - ( e->key() == Key_Down && (e->state() & AltButton) ) || - ( !d->ed && e->key() == Key_Space ) ) { - if ( count() ) { - if ( !d->usingListBox() ) - d->popup()->setActiveItem( this->d->current ); - popup(); - } - return; - } else if ( d->usingListBox() && e->key() == Key_Up ) { - if ( c > 0 ) - setCurrentItem( c-1 ); - } else if ( d->usingListBox() && e->key() == Key_Down ) { - if ( ++c < count() ) - setCurrentItem( c ); - } else if ( d->usingListBox() && e->key() == Key_Home && ( !d->ed || !d->ed->hasFocus() ) ) { - setCurrentItem( 0 ); - } else if ( d->usingListBox() && e->key() == Key_End && ( !d->ed || !d->ed->hasFocus() ) ) { - setCurrentItem( count()-1 ); - } else if ( !d->ed && e->ascii() >= 32 && !e->text().isEmpty() ) { - if ( !d->completionTimer->isActive() ) { - d->completeAt = 0; - c = completionIndex( e->text(), ++c ); - if ( c >= 0 ) { - setCurrentItem( c ); - d->completeAt = e->text().length(); - } - } else { - d->completionTimer->stop(); - TQString ct = currentText().left( d->completeAt ) + e->text(); - c = completionIndex( ct, c ); - if ( c < 0 && d->completeAt > 0 ) { - c = completionIndex( e->text(), 0 ); - ct = e->text(); - } - d->completeAt = 0; - if ( c >= 0 ) { - setCurrentItem( c ); - d->completeAt = ct.length(); - } - } - d->completionTimer->start( 400, TRUE ); - } else { - e->ignore(); - return; - } - - c = currentItem(); - if ( count() && !text( c ).isNull() ) - emit activated( text( c ) ); - emit activated( c ); -} - - -/*!\reimp -*/ - -void TQComboBox::focusInEvent( TQFocusEvent * e ) -{ - TQWidget::focusInEvent( e ); - d->completeNow = FALSE; - d->completeAt = 0; -} - -/*!\reimp -*/ - -void TQComboBox::focusOutEvent( TQFocusEvent * e ) -{ - TQWidget::focusOutEvent( e ); - d->completeNow = FALSE; - d->completeAt = 0; -} - -/*!\reimp -*/ -#ifndef TQT_NO_WHEELEVENT -void TQComboBox::wheelEvent( TQWheelEvent *e ) -{ - if ( d->poppedUp ) { - if ( d->usingListBox() ) { - TQApplication::sendEvent( d->listBox(), e ); - } - } else { - if ( e->delta() > 0 ) { - int c = currentItem(); - if ( c > 0 ) { - setCurrentItem( c-1 ); - emit activated( currentItem() ); - emit activated( currentText() ); - } - } else { - int c = currentItem(); - if ( ++c < count() ) { - setCurrentItem( c ); - emit activated( currentItem() ); - emit activated( currentText() ); - } - } - e->accept(); - } -} -#endif - -/*! - \internal - Calculates the listbox height needed to contain all items, or as - many as the list box is supposed to contain. -*/ -static int listHeight( TQListBox *l, int sl ) -{ - if ( l->count() > 0 ) - return TQMIN( l->count(), (uint)sl) * l->item( 0 )->height(l); - else - return l->sizeHint().height(); -} - - -/*! - Pops up the combobox popup list. - - If the list is empty, no items appear. -*/ - -void TQComboBox::popup() -{ - if ( !count() || d->poppedUp ) - return; - - if( !d->usingListBox() || style().styleHint(TQStyle::SH_ComboBox_Popup, this) ) { - if(d->usingListBox()) { - if(!d->popup()) { - TQComboBoxPopup *p = new TQComboBoxPopup( this, "in-combo" ); - d->setPopupMenu( p, FALSE ); - p->setFont( font() ); - connect( p, TQ_SIGNAL(activated(int)), TQ_SLOT(internalActivate(int)) ); - connect( p, TQ_SIGNAL(highlighted(int)), TQ_SLOT(internalHighlight(int)) ); - } - d->popup()->clear(); - for(unsigned int i = 0; i < d->listBox()->count(); i++) { - TQListBoxItem *item = d->listBox()->item(i); - if(item->rtti() == TQListBoxText::RTTI) { - d->popup()->insertItem(escapedComboString(item->text()), i, i); - } else if(item->rtti() == TQListBoxPixmap::RTTI) { - if(item->pixmap()) - d->popup()->insertItem(TQIconSet(*item->pixmap()), escapedComboString(item->text()), i, i); - else - d->popup()->insertItem(escapedComboString(item->text()), i, i); - } else { - d->popup()->insertItem(new TQComboBoxPopupItem(item), i, i); - } - } - } - d->popup()->installEventFilter( this ); - if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) - d->popup()->setItemChecked(this->d->current, TRUE); - d->popup()->popup( mapToGlobal( TQPoint(0,0) ), this->d->current ); - update(); - } else { - // Send all listbox events to eventFilter(): - TQListBox* lb = d->listBox(); - lb->triggerUpdate( TRUE ); - lb->installEventFilter( this ); - d->mouseWasInsidePopup = FALSE; - int w = lb->variableWidth() ? lb->sizeHint().width() : width(); - int h = listHeight( lb, d->sizeLimit ) + 2; - TQRect screen = TQApplication::desktop()->availableGeometry( this ); - - int sx = screen.x(); // screen pos - int sy = screen.y(); - int sw = screen.width(); // screen width - int sh = screen.height(); // screen height - TQPoint pos = mapToGlobal( TQPoint(0,height()) ); - // ## Similar code is in TQPopupMenu - int x = pos.x(); - int y = pos.y(); - - // the complete widget must be visible - if ( x + w > sx + sw ) - x = sx+sw - w; - if ( x < sx ) - x = sx; - if (y + h > sy+sh && y - h - height() >= 0 ) - y = y - h - height(); - - TQRect rect = - style().querySubControlMetrics( TQStyle::CC_ComboBox, this, - TQStyle::SC_ComboBoxListBoxPopup, - TQStyleOption( x, y, w, h ) ); - // work around older styles that don't implement the combobox - // listbox popup subcontrol - if ( rect.isNull() ) - rect.setRect( x, y, w, h ); - lb->setGeometry( rect ); - - lb->raise(); - bool block = lb->signalsBlocked(); - lb->blockSignals( TRUE ); - TQListBoxItem* currentLBItem = 0; - if ( editable() && currentText() != text( currentItem() ) ) - currentLBItem = lb->findItem( currentText() ); - - currentLBItem = currentLBItem ? currentLBItem : lb->item( d->current ); - - lb->setCurrentItem( currentLBItem ); - lb->setContentsPos( lb->contentsX(), - lb->viewportToContents( lb->itemRect( currentLBItem ).topLeft() ).y() ); - - // set the current item to also be the selected item if it isn't already - if ( currentLBItem && currentLBItem->isSelectable() && !currentLBItem->isSelected() ) - lb->setSelected( currentLBItem, TRUE ); - lb->blockSignals( block ); - lb->setVScrollBarMode(TQScrollView::Auto); - -#ifndef TQT_NO_EFFECTS - if ( TQApplication::isEffectEnabled( UI_AnimateCombo ) ) { - if ( lb->y() < mapToGlobal(TQPoint(0,0)).y() ) - qScrollEffect( lb, TQEffects::UpScroll ); - else - qScrollEffect( lb ); - } else -#endif - lb->show(); - } - d->poppedUp = TRUE; -} - - -/*! - \reimp -*/ -void TQComboBox::updateMask() -{ - TQBitmap bm( size() ); - bm.fill( color0 ); - - { - TQPainter p( &bm, this ); - style().drawComplexControlMask(TQStyle::CC_ComboBox, &p, this, rect()); - } - - setMask( bm ); -} - -/*! - \internal - Pops down (removes) the combobox popup list box. -*/ -void TQComboBox::popDownListBox() -{ - Q_ASSERT( d->usingListBox() ); - d->listBox()->removeEventFilter( this ); - d->listBox()->viewport()->removeEventFilter( this ); - d->listBox()->hide(); - d->listBox()->setCurrentItem( d->current ); - if ( d->arrowDown ) { - d->arrowDown = FALSE; - repaint( FALSE ); - } - d->poppedUp = FALSE; - - update(); -} - - -/*! - \internal - Re-indexes the identifiers in the popup list. -*/ - -void TQComboBox::reIndex() -{ - if ( !d->usingListBox() ) { - int cnt = count(); - while ( cnt-- ) - d->popup()->setId( cnt, cnt ); - } -} - -/*! - \internal - Repaints the combobox. -*/ - -void TQComboBox::currentChanged() -{ - if ( d->autoresize ) - adjustSize(); - update(); - -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif -} - -/*! \reimp - - \internal - - The event filter steals events from the popup or listbox when they - are popped up. It makes the popup stay up after a short click in - motif style. In windows style it toggles the arrow button of the - combobox field, and activates an item and takes down the listbox - when the mouse button is released. -*/ - -bool TQComboBox::eventFilter( TQObject *object, TQEvent *event ) -{ - if ( !event ) - return TRUE; - else if ( object == d->ed ) { - if ( event->type() == TQEvent::KeyPress ) { - bool isAccepted = ( (TQKeyEvent*)event )->isAccepted(); - keyPressEvent( (TQKeyEvent *)event ); - if ( ((TQKeyEvent *)event)->isAccepted() ) { - d->completeNow = FALSE; - return TRUE; - } else if ( ((TQKeyEvent *)event)->key() != Key_End ) { - d->completeNow = TRUE; - d->completeAt = d->ed->cursorPosition(); - } - if ( isAccepted ) - ( (TQKeyEvent*)event )->accept(); - else - ( (TQKeyEvent*)event )->ignore(); - } else if ( event->type() == TQEvent::KeyRelease ) { - keyReleaseEvent( (TQKeyEvent *)event ); - return ((TQKeyEvent *)event)->isAccepted(); - } else if ( event->type() == TQEvent::FocusIn ) { - focusInEvent( (TQFocusEvent *)event ); - } else if ( event->type() == TQEvent::FocusOut ) { - focusOutEvent( (TQFocusEvent *)event ); - } else if ( d->useCompletion && d->completeNow ) { - d->completeNow = FALSE; - if ( !d->ed->text().isNull() && - d->ed->cursorPosition() > d->completeAt && - d->ed->cursorPosition() == (int)d->ed->text().length() ) { - TQString ct( d->ed->text() ); - int i = completionIndex( ct, currentItem() ); - if ( i > -1 ) { - TQString it = text( i ); - d->ed->validateAndSet( it, ct.length(), - ct.length(), it.length() ); - d->current = i; - // ### sets current item without emitting signals. This is to - // make sure the right item is current if you change current with - // wheel/up/down. While typing current is not valid anyway. Fix properly - // in 4.0. - } - } - } - } else if ( d->usingListBox() && ( object == d->listBox() || - object == d->listBox()->viewport() )) { - TQMouseEvent *e = (TQMouseEvent*)event; - switch( event->type() ) { - case TQEvent::MouseMove: - if ( !d->mouseWasInsidePopup ) { - TQPoint pos = e->pos(); - if ( d->listBox()->rect().contains( pos ) ) - d->mouseWasInsidePopup = TRUE; - // Check if arrow button should toggle - if ( d->arrowPressed ) { - TQPoint comboPos; - comboPos = mapFromGlobal( d->listBox()->mapToGlobal(pos) ); - TQRect arrowRect = - style().querySubControlMetrics( TQStyle::CC_ComboBox, this, - TQStyle::SC_ComboBoxArrow); - arrowRect = TQStyle::visualRect(arrowRect, this); - if ( arrowRect.contains( comboPos ) ) { - if ( !d->arrowDown ) { - d->arrowDown = TRUE; - repaint( FALSE ); - } - } else { - if ( d->arrowDown ) { - d->arrowDown = FALSE; - repaint( FALSE ); - } - } - } - } else if ((e->state() & ( RightButton | LeftButton | MidButton ) ) == 0 && - style().styleHint(TQStyle::SH_ComboBox_ListMouseTracking, this)) { - TQWidget *mouseW = TQApplication::widgetAt( e->globalPos(), TRUE ); - if ( mouseW == d->listBox()->viewport() ) { //### - TQMouseEvent m( TQEvent::MouseMove, e->pos(), e->globalPos(), - LeftButton, LeftButton ); - TQApplication::sendEvent( object, &m ); //### Evil - return TRUE; - } - } - - break; - case TQEvent::MouseButtonRelease: - if ( d->listBox()->rect().contains( e->pos() ) ) { - TQMouseEvent tmp( TQEvent::MouseButtonDblClick, - e->pos(), e->button(), e->state() ) ; - // will hide popup - TQApplication::sendEvent( object, &tmp ); - return TRUE; - } else { - if ( d->mouseWasInsidePopup ) { - popDownListBox(); - } else { - d->arrowPressed = FALSE; - if ( d->arrowDown ) { - d->arrowDown = FALSE; - repaint( FALSE ); - } - } - } - break; - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseButtonPress: - if ( !d->listBox()->rect().contains( e->pos() ) ) { - TQPoint globalPos = d->listBox()->mapToGlobal(e->pos()); - if ( TQApplication::widgetAt( globalPos, TRUE ) == this ) { - d->discardNextMousePress = TRUE; - // avoid popping up again - } - popDownListBox(); - return TRUE; - } - break; - case TQEvent::KeyPress: - switch( ((TQKeyEvent *)event)->key() ) { - case Key_Up: - case Key_Down: - if ( !(((TQKeyEvent *)event)->state() & AltButton) ) - break; - case Key_F4: - case Key_Escape: - if ( d->poppedUp ) { - popDownListBox(); - return TRUE; - } - break; - case Key_Enter: - case Key_Return: - // work around TQDialog's enter handling - return FALSE; - default: - break; - } - break; - case TQEvent::Hide: - popDownListBox(); - break; - default: - break; - } - } else if ( (!d->usingListBox() || style().styleHint(TQStyle::SH_ComboBox_Popup, this)) && - object == d->popup() ) { - TQMouseEvent *e = (TQMouseEvent*)event; - switch ( event->type() ) { - case TQEvent::MouseButtonRelease: - if ( d->shortClick ) { - TQMouseEvent tmp( TQEvent::MouseMove, - e->pos(), e->button(), e->state() ) ; - // highlight item, but don't pop down: - TQApplication::sendEvent( object, &tmp ); - return TRUE; - } - break; - case TQEvent::MouseButtonDblClick: - case TQEvent::MouseButtonPress: - if ( !d->popup()->rect().contains( e->pos() ) ) { - d->poppedUp = FALSE; - d->arrowDown = FALSE; - // remove filter, event will take down popup: - d->popup()->removeEventFilter( this ); - // ### uglehack! - // call internalHighlight so the highlighed signal - // will be emitted at least as often as necessary. - // it may be called more often than necessary - internalHighlight( d->current ); - } - break; - case TQEvent::Hide: - d->poppedUp = FALSE; - break; - default: - break; - } - } - return TQWidget::eventFilter( object, event ); -} - - -/*! - Returns the index of the first item \e after \a startingAt of - which \a prefix is a case-insensitive prefix. Returns -1 if no - items start with \a prefix. -*/ - -int TQComboBox::completionIndex( const TQString & prefix, - int startingAt = 0 ) const -{ - int start = startingAt; - if ( start < 0 || start >= count() ) - start = 0; - if ( start >= count() ) - return -1; - TQString match = prefix.lower(); - if ( match.length() < 1 ) - return start; - - TQString current; - int i = start; - do { - current = text( i ).lower(); - if ( current.startsWith( match ) ) - return i; - i++; - if ( i == count() ) - i = 0; - } while ( i != start ); - return -1; -} - - -int TQComboBox::sizeLimit() const -{ - return d ? d->sizeLimit : INT_MAX; -} - -void TQComboBox::setSizeLimit( int lines ) -{ - d->sizeLimit = lines; -} - - -int TQComboBox::maxCount() const -{ - return d ? d->maxCount : INT_MAX; -} - -void TQComboBox::setMaxCount( int count ) -{ - int l = this->count(); - while( --l > count ) - removeItem( l ); - d->maxCount = count; -} - -TQComboBox::Policy TQComboBox::insertionPolicy() const -{ - return d->p; -} - -void TQComboBox::setInsertionPolicy( Policy policy ) -{ - d->p = policy; -} - - - -/*! - Internal slot to keep the line editor up to date. -*/ - -void TQComboBox::returnPressed() -{ - TQString s( d->ed->text() ); - - if ( s.isEmpty() ) - return; - - int c = 0; - bool doInsert = TRUE; - if ( !d->duplicatesEnabled ) { - for ( int i = 0; i < count(); ++i ) { - if ( s == text( i ) ) { - doInsert = FALSE; - c = i; - break; - } - } - } - - if ( doInsert ) { - if ( insertionPolicy() != NoInsertion ) { - int cnt = count(); - while ( cnt >= d->maxCount ) { - removeItem( --cnt ); - } - } - - switch ( insertionPolicy() ) { - case AtCurrent: - if (count() == 0) - insertItem(s); - else if ( s != text( currentItem() ) ) - changeItem( s, currentItem() ); - emit activated( currentItem() ); - emit activated( s ); - return; - case NoInsertion: - emit activated( s ); - return; - case AtTop: - c = 0; - break; - case AtBottom: - c = count(); - break; - case BeforeCurrent: - c = currentItem(); - break; - case AfterCurrent: - c = count() == 0 ? 0 : currentItem() + 1; - break; - } - insertItem( s, c ); - } - - setCurrentItem( c ); - emit activated( c ); - emit activated( s ); -} - - -/*! \reimp -*/ - -void TQComboBox::setEnabled( bool enable ) -{ - if ( !enable ) { - if ( d->usingListBox() ) { - popDownListBox(); - } else { - d->popup()->removeEventFilter( this ); - d->popup()->close(); - d->poppedUp = FALSE; - } - } - TQWidget::setEnabled( enable ); -} - - - -/*! - Applies the validator \a v to the combobox so that only text which - is valid according to \a v is accepted. - - This function does nothing if the combobox is not editable. - - \sa validator() clearValidator() TQValidator -*/ - -void TQComboBox::setValidator( const TQValidator * v ) -{ - if ( d && d->ed ) - d->ed->setValidator( v ); -} - - -/*! - Returns the validator which constrains editing for this combobox - if there is one; otherwise returns 0. - - \sa setValidator() clearValidator() TQValidator -*/ - -const TQValidator * TQComboBox::validator() const -{ - return d && d->ed ? d->ed->validator() : 0; -} - - -/*! - This slot is equivalent to setValidator( 0 ). -*/ - -void TQComboBox::clearValidator() -{ - if ( d && d->ed ) - d->ed->setValidator( 0 ); -} - - -/*! - Sets the combobox to use \a newListBox instead of the current list - box or popup. As a side effect, it clears the combobox of its - current contents. - - \warning TQComboBox assumes that newListBox->text(n) returns - non-null for 0 \<= n \< newListbox->count(). This assumption is - necessary because of the line edit in TQComboBox. -*/ - -void TQComboBox::setListBox( TQListBox * newListBox ) -{ - clear(); - - if ( d->usingListBox() ) { - delete d->listBox(); - } else { - delete d->popup(); - d->setPopupMenu(0, FALSE); - } - - newListBox->reparent( this, WType_Popup, TQPoint(0,0), FALSE ); - d->setListBox( newListBox ); - d->listBox()->setFont( font() ); - d->listBox()->setPalette( palette() ); - d->listBox()->setVScrollBarMode(TQScrollView::AlwaysOff); - d->listBox()->setHScrollBarMode(TQScrollView::AlwaysOff); - d->listBox()->setFrameStyle( TQFrame::Box | TQFrame::Plain ); - d->listBox()->setLineWidth( 1 ); - d->listBox()->resize( 100, 10 ); - - connect( d->listBox(), TQ_SIGNAL(selected(int)), - TQ_SLOT(internalActivate(int)) ); - connect( d->listBox(), TQ_SIGNAL(highlighted(int)), - TQ_SLOT(internalHighlight(int))); -} - - -/*! - Returns the current list box, or 0 if there is no list box. - (TQComboBox can use TQPopupMenu instead of TQListBox.) Provided to - match setListBox(). - - \sa setListBox() -*/ - -TQListBox * TQComboBox::listBox() const -{ - return d && d->usingListBox() ? d->listBox() : 0; -} - -/*! - Returns the line edit, or 0 if there is no line edit. - - Only editable listboxes have a line editor. -*/ -TQLineEdit* TQComboBox::lineEdit() const -{ - return d->ed; -} - - - -/*! - Clears the line edit without changing the combobox's contents. - Does nothing if the combobox isn't editable. - - This is particularly useful when using a combobox as a line edit - with history. For example you can connect the combobox's - activated() signal to clearEdit() in order to present the user - with a new, empty line as soon as Enter is pressed. - - \sa setEditText() -*/ - -void TQComboBox::clearEdit() -{ - if ( d && d->ed ) - d->ed->clear(); -} - - -/*! - Sets the text in the line edit to \a newText without changing the - combobox's contents. Does nothing if the combobox isn't editable. - - This is useful e.g. for providing a good starting point for the - user's editing and entering the change in the combobox only when - the user presses Enter. - - \sa clearEdit() insertItem() -*/ - -void TQComboBox::setEditText( const TQString &newText ) -{ - if ( d && d->ed ) { - d->updateLinedGeometry(); - d->ed->setText( newText ); - } -} - -void TQComboBox::setAutoCompletion( bool enable ) -{ - d->useCompletion = enable; - d->completeNow = FALSE; -} - - -bool TQComboBox::autoCompletion() const -{ - return d->useCompletion; -} - -/*!\reimp - */ -void TQComboBox::styleChange( TQStyle& s ) -{ - d->sizeHint = TQSize(); // invalidate size hint... - if ( d->ed ) - d->updateLinedGeometry(); - TQWidget::styleChange( s ); -} - -bool TQComboBox::editable() const -{ - return d->ed != 0; -} - -void TQComboBox::setEditable( bool y ) -{ - if ( y == editable() ) - return; - if ( y ) { - if ( !d->usingListBox() ) - setUpListBox(); - setUpLineEdit(); - d->ed->show(); - if ( currentItem() ) - setEditText( currentText() ); - } else { - delete d->ed; - d->ed = 0; - } - - setFocusPolicy( StrongFocus ); - updateGeometry(); - update(); -} - - -void TQComboBox::setUpListBox() -{ - d->setListBox( new TQListBox( this, "in-combo", WType_Popup ) ); - d->listBox()->setFont( font() ); - d->listBox()->setPalette( palette() ); - d->listBox()->setVScrollBarMode( TQListBox::AlwaysOff ); - d->listBox()->setHScrollBarMode( TQListBox::AlwaysOff ); - d->listBox()->setFrameStyle( TQFrame::Box | TQFrame::Plain ); - d->listBox()->setLineWidth( 1 ); - d->listBox()->resize( 100, 10 ); - - connect( d->listBox(), TQ_SIGNAL(selected(int)), - TQ_SLOT(internalActivate(int)) ); - connect( d->listBox(), TQ_SIGNAL(highlighted(int)), - TQ_SLOT(internalHighlight(int))); -} - - -void TQComboBox::setUpLineEdit() -{ - if ( !d->ed ) - setLineEdit( new TQLineEdit( this, "combo edit" ) ); -} - -/*! - Sets the line edit to use \a edit instead of the current line edit. -*/ - -void TQComboBox::setLineEdit( TQLineEdit *edit ) -{ - if ( !edit ) { -#if defined(QT_CHECK_NULL) - Q_ASSERT( edit != 0 ); -#endif - return; - } - - edit->setText( currentText() ); - delete d->ed; - d->ed = edit; - - if ( edit->parent() != this ) - edit->reparent( this, TQPoint(0,0), FALSE ); - - connect (edit, TQ_SIGNAL( textChanged(const TQString&) ), - this, TQ_SIGNAL( textChanged(const TQString&) ) ); - connect( edit, TQ_SIGNAL(returnPressed()), TQ_SLOT(returnPressed()) ); - - edit->setFrame( FALSE ); - d->updateLinedGeometry(); - edit->installEventFilter( this ); - setFocusProxy( edit ); - setFocusPolicy( StrongFocus ); - setInputMethodEnabled( TRUE ); - - if ( !d->usingListBox() ) - setUpListBox(); - - if ( isVisible() ) - edit->show(); - - updateGeometry(); - update(); -} - -/*! - \reimp -*/ -void TQComboBox::hide() -{ - TQWidget::hide(); - - if (listBox()) - listBox()->hide(); - else if (d->popup()) - d->popup()->hide(); -} - -#endif // TQT_NO_COMBOBOX diff --git a/src/widgets/qdial.cpp b/src/widgets/qdial.cpp deleted file mode 100644 index f11218bf3..000000000 --- a/src/widgets/qdial.cpp +++ /dev/null @@ -1,976 +0,0 @@ -/**************************************************************************** -** -** Implementation of the dial widget -** -** Created : 979899 -** -** 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 "ntqdial.h" - -#ifndef TQT_NO_DIAL - -#include "tqpainter.h" -#include "tqpointarray.h" -#include "tqcolor.h" -#include "ntqapplication.h" -#include "tqregion.h" -#include "tqbitmap.h" -#include "tqstyle.h" -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif - -#include // sin(), cos(), atan() -//### Forutsetter linking med math lib - Jfr kommentar i tqpainter_x11.cpp! - -static const double m_pi = 3.14159265358979323846; -static const double rad_factor = 180.0 / m_pi; - - -class TQDialPrivate -{ -public: - TQDialPrivate() - { - wrapping = FALSE; - tracking = TRUE; - doNotEmit = FALSE; - target = 3.7; - mousePressed = FALSE; - } - - bool wrapping; - bool tracking; - bool doNotEmit; - double target; - TQRect eraseArea; - bool eraseAreaValid; - bool showNotches; - bool onlyOutside; - bool mousePressed; - - TQPointArray lines; -}; - - -/*! - \class TQDial ntqdial.h - - \brief The TQDial class provides a rounded range control (like a speedometer or potentiometer). - - \ingroup basic - \mainclass - - TQDial is used when the user needs to control a value within a - program-definable range, and the range either wraps around - (typically, 0..359 degrees) or the dialog layout needs a square - widget. - - Both API- and UI-wise, the dial is very similar to a \link TQSlider - slider. \endlink Indeed, when wrapping() is FALSE (the default) - there is no real difference between a slider and a dial. They - have the same signals, slots and member functions, all of which do - the same things. Which one you use depends only on your taste - and on the application. - - The dial initially emits valueChanged() signals continuously while - the slider is being moved; you can make it emit the signal less - often by calling setTracking(FALSE). dialMoved() is emitted - continuously even when tracking() is FALSE. - - The slider also emits dialPressed() and dialReleased() signals - when the mouse button is pressed and released. But note that the - dial's value can change without these signals being emitted; the - keyboard and wheel can be used to change the value. - - Unlike the slider, TQDial attempts to draw a "nice" number of - notches rather than one per lineStep(). If possible, the number - of notches drawn is one per lineStep(), but if there aren't enough - pixels to draw every one, TQDial will draw every second, third - etc., notch. notchSize() returns the number of units per notch, - hopefully a multiple of lineStep(); setNotchTarget() sets the - target distance between neighbouring notches in pixels. The - default is 3.75 pixels. - - Like the slider, the dial makes the TQRangeControl functions - setValue(), addLine(), subtractLine(), addPage() and - subtractPage() available as slots. - - The dial's keyboard interface is fairly simple: The left/up and - right/down arrow keys move by lineStep(), page up and page down by - pageStep() and Home and End to minValue() and maxValue(). - - - - \sa TQScrollBar TQSpinBox - \link guibooks.html#fowler GUI Design Handbook: Slider\endlink -*/ - - - - -/*! - Constructs a dial called \a name with parent \a parent. \a f is - propagated to the TQWidget constructor. It has the default range of - a TQRangeControl. -*/ - -TQDial::TQDial( TQWidget *parent, const char *name, WFlags f ) - : TQWidget( parent, name, f | WNoAutoErase ), TQRangeControl() -{ - d = new TQDialPrivate; - d->eraseAreaValid = FALSE; - d->showNotches = FALSE; - d->onlyOutside = FALSE; - setFocusPolicy( TQWidget::WheelFocus ); -} - - - -/*! - Constructs a dial called \a name with parent \a parent. The dial's - value can never be smaller than \a minValue or greater than \a - maxValue. Its page step size is \a pageStep, and its initial value - is \a value. - - \a value is forced to be within the legal range. -*/ - -TQDial::TQDial( int minValue, int maxValue, int pageStep, int value, - TQWidget *parent, const char *name ) - : TQWidget( parent, name, WNoAutoErase ), - TQRangeControl( minValue, maxValue, 1, pageStep, value ) -{ - d = new TQDialPrivate; - d->eraseAreaValid = FALSE; - d->showNotches = FALSE; - d->onlyOutside = FALSE; - setFocusPolicy( TQWidget::WheelFocus ); -} - -/*! - Destroys the dial. -*/ -TQDial::~TQDial() -{ - delete d; -} - - -void TQDial::setTracking( bool enable ) -{ - d->tracking = enable; -} - - -/*! - \property TQDial::tracking - \brief whether tracking is enabled - - If TRUE (the default), tracking is enabled. This means that the - arrow can be moved using the mouse; otherwise the arrow cannot be - moved with the mouse. -*/ - -bool TQDial::tracking() const -{ - return d ? d->tracking : TRUE; -} - -void TQDial::setValue( int newValue ) -{ // ### set doNotEmit? Matthias? - TQRangeControl::setValue( newValue ); -} - - -/*! - Increments the dial's value() by one lineStep(). -*/ - -void TQDial::addLine() -{ - TQRangeControl::addLine(); -} - - -/*! - Decrements the dial's value() by one lineStep(). -*/ - -void TQDial::subtractLine() -{ - TQRangeControl::subtractLine(); -} - - -/*! \reimp */ - -void TQDial::resizeEvent( TQResizeEvent * e ) -{ - d->lines.resize( 0 ); - TQWidget::resizeEvent( e ); -} - - -/*! - \reimp -*/ - -void TQDial::paintEvent( TQPaintEvent * e ) -{ - repaintScreen( &e->rect() ); -} - -/*! - Paints the dial using clip region \a cr. -*/ - -void TQDial::repaintScreen( const TQRect *cr ) -{ - TQPainter p; - p.begin( this ); - - bool resetClipping = FALSE; - - // calculate clip-region for erasing background - if ( cr ) { - p.setClipRect( *cr ); - } else if ( !d->onlyOutside && d->eraseAreaValid ) { - TQRegion reg = d->eraseArea; - double a; - reg = reg.subtract( calcArrow( a ) ); - p.setClipRegion( reg ); - resetClipping = TRUE; - } - - TQRect br( calcDial() ); - p.setPen( NoPen ); - // if ( style() == MotifStyle ) - // p.setBrush( colorGroup().brush( TQColorGroup::Mid ) ); - // else { - TQBrush b; - if ( colorGroup().brush( TQColorGroup::Light ).pixmap() ) - b = TQBrush( colorGroup().brush( TQColorGroup::Light ) ); - else - b = TQBrush( colorGroup().light(), Dense4Pattern ); - p.setBrush( b ); - p.setBackgroundMode( OpaqueMode ); - // } - - TQRect te = br; - te.setWidth(te.width()+2); - te.setHeight(te.height()+2); - // erase background of dial - if ( !d->onlyOutside ) { - p.drawEllipse( te ); - } - - // erase remaining space around the dial - TQRegion remaining( 0, 0, width(), height() ); - remaining = remaining.subtract( TQRegion( te, TQRegion::Ellipse ) ); - if ( p.hasClipping() ) - remaining = remaining.intersect( p.clipRegion() ); - erase(remaining); - - if ( resetClipping ) { - if ( cr ) - p.setClipRect( *cr ); - else - p.setClipRect( TQRect( 0, 0, width(), height() ) ); - } - - // draw notches - if ( d->showNotches ) { - calcLines(); - p.setPen( colorGroup().foreground() ); - p.drawLineSegments( d->lines ); - } - - // calculate and paint arrow - p.setPen( TQPen( colorGroup().dark() ) ); - p.drawArc( te, 60 * 16, 180 * 16 ); - p.setPen( TQPen( colorGroup().light() ) ); - p.drawArc( te, 240 * 16, 180 * 16 ); - - double a; - TQPointArray arrow( calcArrow( a ) ); - TQRect ea( arrow.boundingRect() ); - d->eraseArea = ea; - d->eraseAreaValid = TRUE; - - p.setPen( NoPen ); - p.setBrush( colorGroup().brush( TQColorGroup::Button ) ); - if ( !d->onlyOutside ) - p.drawPolygon( arrow ); - - a = angle( TQPoint( width() / 2, height() / 2 ), arrow[ 0 ] ); - p.setBrush( TQt::NoBrush ); - - // that's still a hack... - if ( a <= 0 || a > 200 ) { - p.setPen( colorGroup().light() ); - p.drawLine( arrow[ 2 ], arrow[ 0 ] ); - p.drawLine( arrow[ 1 ], arrow[ 2 ] ); - p.setPen( colorGroup().dark() ); - p.drawLine( arrow[ 0 ], arrow[ 1 ] ); - } else if ( a > 0 && a < 45 ) { - p.setPen( colorGroup().light() ); - p.drawLine( arrow[ 2 ], arrow[ 0 ] ); - p.setPen( colorGroup().dark() ); - p.drawLine( arrow[ 1 ], arrow[ 2 ] ); - p.drawLine( arrow[ 0 ], arrow[ 1 ] ); - } else if ( a >= 45 && a < 135 ) { - p.setPen( colorGroup().dark() ); - p.drawLine( arrow[ 2 ], arrow[ 0 ] ); - p.drawLine( arrow[ 1 ], arrow[ 2 ] ); - p.setPen( colorGroup().light() ); - p.drawLine( arrow[ 0 ], arrow[ 1 ] ); - } else if ( a >= 135 && a < 200 ) { - p.setPen( colorGroup().dark() ); - p.drawLine( arrow[ 2 ], arrow[ 0 ] ); - p.setPen( colorGroup().light() ); - p.drawLine( arrow[ 0 ], arrow[ 1 ] ); - p.drawLine( arrow[ 1 ], arrow[ 2 ] ); - } - - // draw focus rect around the dial - if ( hasFocus() ) { - p.setClipping( FALSE ); - br.setWidth( br.width() + 2 ); - br.setHeight( br.height() + 2 ); - if ( d->showNotches ) { - int r = TQMIN( width(), height() ) / 2; - br.moveBy( -r / 6, - r / 6 ); - br.setWidth( br.width() + r / 3 ); - br.setHeight( br.height() + r / 3 ); - } - // strange, but else we get redraw errors on Windows - p.end(); - p.begin( this ); - p.save(); - p.setPen( TQPen( colorGroup().background() ) ); - p.setBrush( NoBrush ); - p.drawRect( br ); - p.restore(); - style().drawPrimitive( TQStyle::PE_FocusRect, &p, br, colorGroup()); - } - p.end(); -} - - -/*! - \reimp -*/ - -void TQDial::keyPressEvent( TQKeyEvent * e ) -{ - switch ( e->key() ) { - case Key_Left: case Key_Down: - subtractLine(); - break; - case Key_Right: case Key_Up: - addLine(); - break; - case Key_Prior: - subtractPage(); - break; - case Key_Next: - addPage(); - break; - case Key_Home: - setValue( minValue() ); - break; - case Key_End: - setValue( maxValue() ); - break; - default: - e->ignore(); - break; - } -} - - -/*! - \reimp -*/ - -void TQDial::mousePressEvent( TQMouseEvent * e ) -{ - d->mousePressed = TRUE; - setValue( valueFromPoint( e->pos() ) ); - emit dialPressed(); -} - - -/*! - \reimp -*/ - -void TQDial::mouseReleaseEvent( TQMouseEvent * e ) -{ - d->mousePressed = FALSE; - setValue( valueFromPoint( e->pos() ) ); - emit dialReleased(); -} - - -/*! - \reimp -*/ - -void TQDial::mouseMoveEvent( TQMouseEvent * e ) -{ - if ( !d->mousePressed ) - return; - if ( !d->tracking || (e->state() & LeftButton) == 0 ) - return; - d->doNotEmit = TRUE; - setValue( valueFromPoint( e->pos() ) ); - emit dialMoved( value() ); - d->doNotEmit = FALSE; -} - - -/*! - \reimp -*/ -#ifndef TQT_NO_WHEELEVENT -void TQDial::wheelEvent( TQWheelEvent *e ) -{ - setValue( value() - e->delta() / 120 ); -} -#endif - -/*! - \reimp -*/ - -void TQDial::focusInEvent( TQFocusEvent * ) -{ - d->onlyOutside = TRUE; - repaintScreen(); - d->onlyOutside = FALSE; -} - - -/*! - \reimp -*/ - -void TQDial::focusOutEvent( TQFocusEvent * ) -{ - d->onlyOutside = TRUE; - repaintScreen(); - d->onlyOutside = FALSE; -} - -/*! - Reimplemented to ensure the display is correct and to emit the - valueChanged(int) signal when appropriate. -*/ - -void TQDial::valueChange() -{ - d->lines.resize( 0 ); - repaintScreen(); - if ( d->tracking || !d->doNotEmit ) { - emit valueChanged( value() ); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif - } -} - - -/*! - Reimplemented to ensure tick-marks are consistent with the new range. -*/ - -void TQDial::rangeChange() -{ - d->lines.resize( 0 ); - repaintScreen(); -} - - -/*! - \internal -*/ - -int TQDial::valueFromPoint( const TQPoint & p ) const -{ - double yy = (double)height()/2.0 - p.y(); - double xx = (double)p.x() - width()/2.0; - double a = (xx || yy) ? atan2(yy, xx) : 0; - - if ( a < m_pi/-2 ) - a = a + m_pi*2; - - int dist = 0; - int minv = minValue(), maxv = maxValue(); - - if ( minValue() < 0 ) { - dist = -minValue(); - minv = 0; - maxv = maxValue() + dist; - } - - int r = maxv - minv; - int v; - if ( d->wrapping ) - v = (int)(0.5 + minv + r*(m_pi*3/2-a)/(2*m_pi)); - else - v = (int)(0.5 + minv + r*(m_pi*4/3-a)/(m_pi*10/6)); - - if ( dist > 0 ) - v -= dist; - - return bound( v ); -} - - -/*! - \internal -*/ - -double TQDial::angle( const TQPoint &p1, const TQPoint &p2 ) const -{ - double _angle = 0.0; - - if ( p1.x() == p2.x() ) { - if ( p1.y() < p2.y() ) - _angle = 270.0; - else - _angle = 90.0; - } else { - double x1, x2, y1, y2; - - if ( p1.x() <= p2.x() ) { - x1 = p1.x(); y1 = p1.y(); - x2 = p2.x(); y2 = p2.y(); - } else { - x2 = p1.x(); y2 = p1.y(); - x1 = p2.x(); y1 = p2.y(); - } - - double m = -( y2 - y1 ) / ( x2 - x1 ); - _angle = atan( m ) * rad_factor; - - if ( p1.x() < p2.x() ) - _angle = 180.0 - _angle; - else - _angle = -_angle; - } - - return _angle; -} - -void TQDial::setWrapping( bool enable ) -{ - if ( d->wrapping == enable ) - return; - d->lines.resize( 0 ); - d->wrapping = enable; - d->eraseAreaValid = FALSE; - repaintScreen(); -} - - -/*! - \property TQDial::wrapping - \brief whether wrapping is enabled - - If TRUE, wrapping is enabled. This means that the arrow can be - turned around 360°. Otherwise there is some space at the bottom of - the dial which is skipped by the arrow. - - This property's default is FALSE. -*/ - -bool TQDial::wrapping() const -{ - return d->wrapping; -} - - -/*! - \property TQDial::notchSize - \brief the current notch size - - The notch size is in range control units, not pixels, and if - possible it is a multiple of lineStep() that results in an - on-screen notch size near notchTarget(). - - \sa notchTarget() lineStep() -*/ - -int TQDial::notchSize() const -{ - // radius of the arc - int r = TQMIN( width(), height() )/2; - // length of the whole arc - int l = (int)(r*(d->wrapping ? 6 : 5)*m_pi/6); - // length of the arc from minValue() to minValue()+pageStep() - if ( maxValue() > minValue()+pageStep() ) - l = (int)(0.5 + l * pageStep() / (maxValue()-minValue())); - // length of a lineStep() arc - l = l * lineStep() / pageStep(); - if ( l < 1 ) - l = 1; - // how many times lineStep can be draw in d->target pixels - l = (int)(0.5 + d->target / l); - // we want notchSize() to be a non-zero multiple of lineStep() - if ( !l ) - l = 1; - return lineStep() * l; -} - -void TQDial::setNotchTarget( double target ) -{ - d->lines.resize( 0 ); - d->target = target; - d->eraseAreaValid = FALSE; - d->onlyOutside = TRUE; - repaintScreen(); - d->onlyOutside = FALSE; -} - - -/*! - \property TQDial::notchTarget - \brief the target number of pixels between notches - - The notch target is the number of pixels TQDial attempts to put - between each notch. - - The actual size may differ from the target size. -*/ - -double TQDial::notchTarget() const -{ - return d->target; -} - - -/*! - Increments the dial's value() by one pageStep() of steps. -*/ - -void TQDial::addPage() -{ - TQRangeControl::addPage(); -} - - -/*! - Decrements the dial's value() by one pageStep() of steps. -*/ - -void TQDial::subtractPage() -{ - TQRangeControl::subtractPage(); -} - - -/*! - \fn void TQDial::valueChanged( int value ) - - This signal is emitted whenever the dial's \a value changes. The - frequency of this signal is influenced by setTracking(). -*/ - -/*! - \fn void TQDial::dialPressed() - - This signal is emitted when the user begins mouse interaction with - the dial. - - \sa dialReleased() -*/ - -/*! - \fn void TQDial::dialMoved( int value ) - - This signal is emitted whenever the dial \a value changes. The - frequency of this signal is \e not influenced by setTracking(). - - \sa valueChanged() -*/ - -/*! - \fn void TQDial::dialReleased() - - This signal is emitted when the user ends mouse interaction with - the dial. - - \sa dialPressed() -*/ - -void TQDial::setNotchesVisible( bool b ) -{ - d->showNotches = b; - d->eraseAreaValid = FALSE; - d->onlyOutside = TRUE; - repaintScreen(); - d->onlyOutside = FALSE; -} - -/*! - \property TQDial::notchesVisible - \brief whether the notches are shown - - If TRUE, the notches are shown. If FALSE (the default) notches are - not shown. -*/ -bool TQDial::notchesVisible() const -{ - return d->showNotches; -} - -/*! - \reimp -*/ - -TQSize TQDial::minimumSizeHint() const -{ - return TQSize( 50, 50 ); -} - -/*! - \reimp -*/ - -TQSize TQDial::sizeHint() const -{ - return TQSize( 100, 100 ).expandedTo( TQApplication::globalStrut() ); -} - - - -/*! - \internal -*/ - -TQPointArray TQDial::calcArrow( double &a ) const -{ - int r = TQMIN( width(), height() ) / 2; - if ( maxValue() == minValue() ) - a = m_pi / 2; - else if ( d->wrapping ) - a = m_pi * 3 / 2 - ( value() - minValue() ) * 2 * m_pi / ( maxValue() - minValue() ); - else - a = ( m_pi * 8 - ( value() - minValue() ) * 10 * m_pi / ( maxValue() - minValue() ) ) / 6; - - int xc = width() / 2; - int yc = height() / 2; - - int len = r - calcBigLineSize() - 5; - if ( len < 5 ) - len = 5; - int back = len / 4; - if ( back < 1 ) - back = 1; - - TQPointArray arrow( 3 ); - arrow[0] = TQPoint( (int)( 0.5 + xc + len * cos(a) ), - (int)( 0.5 + yc -len * sin( a ) ) ); - arrow[1] = TQPoint( (int)( 0.5 + xc + back * cos( a + m_pi * 5 / 6 ) ), - (int)( 0.5 + yc - back * sin( a + m_pi * 5 / 6 ) ) ); - arrow[2] = TQPoint( (int)( 0.5 + xc + back * cos( a - m_pi * 5 / 6 ) ), - (int)( 0.5 + yc - back * sin( a - m_pi * 5 / 6 ) ) ); - return arrow; -} - -/*! - \internal -*/ - -TQRect TQDial::calcDial() const -{ - double r = TQMIN( width(), height() ) / 2.0; - double d_ = r / 6.0; - double dx = d_ + ( width() - 2 * r ) / 2.0 + 1; - double dy = d_ + ( height() - 2 * r ) / 2.0 + 1; - return TQRect( int(dx), int(dy), - int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2) ); -} - -/*! - \internal -*/ - -int TQDial::calcBigLineSize() const -{ - int r = TQMIN( width(), height() ) / 2; - int bigLineSize = r / 6; - if ( bigLineSize < 4 ) - bigLineSize = 4; - if ( bigLineSize > r / 2 ) - bigLineSize = r / 2; - return bigLineSize; -} - -/*! - \internal -*/ - -void TQDial::calcLines() -{ - if ( !d->lines.size() ) { - double r = TQMIN( width(), height() ) / 2.0; - int bigLineSize = calcBigLineSize(); - double xc = width() / 2.0; - double yc = height() / 2.0; - int ns = notchSize(); - int notches = ( maxValue() + ns - 1 - minValue() ) / ns; - d->lines.resize( 2 + 2 * notches ); - int smallLineSize = bigLineSize / 2; - int i; - for( i = 0; i <= notches; i++ ) { - double angle = d->wrapping - ? m_pi * 3 / 2 - i * 2 * m_pi / notches - : (m_pi * 8 - i * 10 * m_pi / notches) / 6; - - double s = sin( angle ); // sin/cos aren't defined as const... - double c = cos( angle ); - if ( i == 0 || ( ((ns * i ) % pageStep() ) == 0 ) ) { - d->lines[2*i] = TQPoint( (int)( xc + ( r - bigLineSize ) * c ), - (int)( yc - ( r - bigLineSize ) * s ) ); - d->lines[2*i+1] = TQPoint( (int)( xc + r * c ), - (int)( yc - r * s ) ); - } else { - d->lines[2*i] = TQPoint( (int)( xc + ( r - 1 - smallLineSize ) * c ), - (int)( yc - ( r - 1 - smallLineSize ) * s ) ); - d->lines[2*i+1] = TQPoint( (int)( xc + ( r - 1 ) * c ), - (int)( yc -( r - 1 ) * s ) ); - } - } - } -} - -/*! - \property TQDial::minValue - \brief the current minimum value - - When setting this property, the \l TQDial::maxValue is adjusted if - necessary to ensure that the range remains valid. - - \sa setRange() -*/ -int TQDial::minValue() const -{ - return TQRangeControl::minValue(); -} - -/*! - \property TQDial::maxValue - \brief the current maximum value - - When setting this property, the \l TQDial::minValue is adjusted if - necessary to ensure that the range remains valid. - - \sa setRange() -*/ -int TQDial::maxValue() const -{ - return TQRangeControl::maxValue(); -} - -void TQDial::setMinValue( int minVal ) -{ - TQRangeControl::setMinValue( minVal ); -} - -void TQDial::setMaxValue( int maxVal ) -{ - TQRangeControl::setMaxValue( maxVal ); -} - -/*! - \property TQDial::lineStep - \brief the current line step - - setLineStep() calls the virtual stepChange() function if the new - line step is different from the previous setting. - - \sa TQRangeControl::setSteps() pageStep setRange() -*/ - -int TQDial::lineStep() const -{ - return TQRangeControl::lineStep(); -} - -/*! - \property TQDial::pageStep - \brief the current page step - - setPageStep() calls the virtual stepChange() function if the new - page step is different from the previous setting. - - \sa stepChange() -*/ -int TQDial::pageStep() const -{ - return TQRangeControl::pageStep(); -} - -void TQDial::setLineStep( int i ) -{ - setSteps( i, pageStep() ); -} - -void TQDial::setPageStep( int i ) -{ - setSteps( lineStep(), i ); -} - -/*! - \property TQDial::value - \brief the current dial value - - This is guaranteed to be within the range - \l{TQDial::minValue}..\l{TQDial::maxValue}. - - \sa minValue maxValue -*/ - -int TQDial::value() const -{ - return TQRangeControl::value(); -} - -#endif // QT_FEATURE_DIAL diff --git a/src/widgets/qdialogbuttons.cpp b/src/widgets/qdialogbuttons.cpp deleted file mode 100644 index d75a16f96..000000000 --- a/src/widgets/qdialogbuttons.cpp +++ /dev/null @@ -1,462 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQDialogButtons class -** -** Copyright (C) 2005-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 "qdialogbuttons_p.h" -#ifndef TQT_NO_DIALOGBUTTONS - -#include -#include -#include -#include -#include -#ifndef TQT_NO_DIALOG -#include -#endif // TQT_NO_DIALOG -#include -#include -#include - -struct TQDialogButtonsPrivate -{ - TQMap text; - TQMap buttons; - TQGuardedPtr custom; - TQ_UINT32 enabled, visible; - TQDialogButtons::Button def; - TQt::Orientation orient; - bool questionMode; -}; - -#ifndef TQT_NO_DIALOG -TQDialogButtons::TQDialogButtons(TQDialog *parent, bool autoConnect, TQ_UINT32 buttons, - Orientation orient, const char *name ) : TQWidget(parent, name) -{ - init(buttons, orient); - if(parent && autoConnect) { - TQObject::connect(this, TQ_SIGNAL(acceptClicked()), parent, TQ_SLOT(accept())); - TQObject::connect(this, TQ_SIGNAL(rejectClicked()), parent, TQ_SLOT(reject())); - } -} -#endif // TQT_NO_DIALOG - -TQDialogButtons::TQDialogButtons(TQWidget *parent, TQ_UINT32 buttons, - Orientation orient, const char *name ) : TQWidget(parent, name) -{ - init(buttons, orient); -} - -void -TQDialogButtons::init(TQ_UINT32 buttons, Orientation orient) -{ - if(buttons == All) { - tqWarning("TQDialogButtons: cannot specify All by itself!"); - buttons = None; - } - d = new TQDialogButtonsPrivate; - d->questionMode = FALSE; - d->orient = orient; - d->def = (Button)style().styleHint(TQStyle::SH_DialogButtons_DefaultButton, this); - d->enabled = d->visible = buttons; -} - -TQDialogButtons::~TQDialogButtons() -{ - delete (TQWidget *)d->custom; - delete d; -} - -void -TQDialogButtons::setQuestionMode(bool b) -{ - d->questionMode = b; -} - -bool -TQDialogButtons::questionMode() const -{ - return d->questionMode; -} - -void -TQDialogButtons::setButtonEnabled(Button button, bool enabled) -{ - if(enabled) - d->enabled |= button; - else - d->enabled ^= button; - if(d->buttons.contains(button)) - d->buttons[button]->setEnabled(enabled); -} - -bool -TQDialogButtons::isButtonEnabled(Button button) const -{ - return ((int)(d->enabled & button)) == button; -} - -void -TQDialogButtons::setButtonVisible(Button button, bool visible) -{ - if(visible) { - if(d->buttons.contains(button)) - d->buttons[button]->show(); - d->visible |= button; - } else { - if(d->buttons.contains(button)) - d->buttons[button]->hide(); - d->visible ^= button; - } - layoutButtons(); -} - -bool -TQDialogButtons::isButtonVisible(Button button) const -{ - return ((int)(d->visible & button)) == button; -} - -TQ_UINT32 -TQDialogButtons::visibleButtons() const -{ - return d->visible; -} - -void -TQDialogButtons::addWidget(TQWidget *w) -{ - TQBoxLayout *lay = NULL; - if(!d->custom) { - d->custom = new TQWidget(this, "dialog_custom_area"); - if(orientation() == Horizontal) - lay = new TQHBoxLayout(d->custom); - else - lay = new TQVBoxLayout(d->custom); - layoutButtons(); - } else { - lay = (TQBoxLayout*)d->custom->layout(); - } - if(w->parent() != d->custom) - w->reparent(d->custom, 0, TQPoint(0, 0), TRUE); - lay->addWidget(w); -} - -void -TQDialogButtons::setDefaultButton(Button button) -{ - if(!((int)(d->visible & button) == button)) { - tqWarning("TQDialogButtons: Button '%d' is not visible (so cannot be default)", button); - return; - } - if(d->def != button) { -#ifndef TQT_NO_PROPERTIES - if(d->buttons.contains(d->def)) - d->buttons[d->def]->setProperty("default", TQVariant(false)); -#endif - d->def = button; -#ifndef TQT_NO_PROPERTIES - if(d->buttons.contains(d->def)) - d->buttons[d->def]->setProperty("default", TQVariant(false)); -#endif - } -} - -TQDialogButtons::Button -TQDialogButtons::defaultButton() const -{ - return d->def; -} - -void -TQDialogButtons::setButtonText(Button button, const TQString &str) -{ - d->text[button] = str; -#ifndef TQT_NO_PROPERTIES - if(d->buttons.contains(button)) - d->buttons[button]->setProperty("text", TQVariant(str)); -#endif - layoutButtons(); -} - -TQString -TQDialogButtons::buttonText(Button b) const -{ - if(d->text.contains(b)) - return d->text[b]; - return TQString(); //null if it is default.. -} - -void -TQDialogButtons::setOrientation(Orientation orient) -{ - if(d->orient != orient) { - d->orient = orient; - if(d->custom && d->custom->layout()) - ((TQBoxLayout*)d->custom->layout())->setDirection(orient == Horizontal ? TQBoxLayout::LeftToRight : - TQBoxLayout::TopToBottom); - layoutButtons(); - } -} - -TQt::Orientation -TQDialogButtons::orientation() const -{ - return d->orient; -} - -TQWidget * -TQDialogButtons::createButton(Button b) -{ - TQPushButton *ret = new TQPushButton(this, "qdialog_button"); - TQObject::connect(ret, TQ_SIGNAL(clicked()), this, TQ_SLOT(handleClicked())); - if(d->text.contains(b)) { - ret->setText(d->text[b]); - } else { - switch(b) { - case All: { - TQString txt = buttonText(defaultButton()); - if(txt.isNull()) { - if(defaultButton() == Accept) { - if(questionMode()) - txt = tr("Yes to All"); - else - txt = tr("OK to All"); - } else { - if(questionMode()) - txt = tr("No to All"); - else - txt = tr("Cancel All"); - } - } else { - txt += tr(" to All"); //ick, I can't really do this!! - } - ret->setText(txt); - break; } - case Accept: - if(questionMode()) - ret->setText(tr("Yes")); - else - ret->setText(tr("OK")); - break; - case Reject: - if(questionMode()) - ret->setText(tr("No")); - else - ret->setText(tr("Cancel")); - break; - case Apply: - ret->setText(tr("Apply")); - break; - case Ignore: - ret->setText(tr("Ignore")); - break; - case Retry: - ret->setText(tr("Retry")); - break; - case Abort: - ret->setText(tr("Abort")); - break; - case Help: - ret->setText(tr("Help")); - break; - default: - break; - } - } - return ret; -} - -void -TQDialogButtons::handleClicked() -{ - const TQObject *s = sender(); - if(!s) - return; - - for(TQMapIterator it = d->buttons.begin(); it != d->buttons.end(); ++it) { - if(it.data() == s) { - emit clicked((TQDialogButtons::Button)it.key()); - switch(it.key()) { - case Retry: - emit retryClicked(); - break; - case Ignore: - emit ignoreClicked(); - break; - case Abort: - emit abortClicked(); - break; - case All: - emit allClicked(); - break; - case Accept: - emit acceptClicked(); - break; - case Reject: - emit rejectClicked(); - break; - case Apply: - emit applyClicked(); - break; - case Help: - emit helpClicked(); - break; - default: - break; - } - return; - } - } -} - -void -TQDialogButtons::resizeEvent(TQResizeEvent *) -{ - layoutButtons(); -} - -void -TQDialogButtons::showEvent(TQShowEvent *) -{ - layoutButtons(); -} - -void -TQDialogButtons::styleChanged(TQStyle &old) -{ - layoutButtons(); - TQWidget::styleChange(old); -} - -void -TQDialogButtons::layoutButtons() -{ - if(!isVisible()) //nah.. - return; - - TQStyle::SubRect rects[] = { - TQStyle::SR_DialogButtonAccept, TQStyle::SR_DialogButtonReject, - TQStyle::SR_DialogButtonApply, TQStyle::SR_DialogButtonHelp, - TQStyle::SR_DialogButtonCustom, TQStyle::SR_DialogButtonAll, - TQStyle::SR_DialogButtonRetry, TQStyle::SR_DialogButtonIgnore, - TQStyle::SR_DialogButtonAbort }; - for(unsigned int i = 0; i < (sizeof(rects) / sizeof(rects[0])); i++) { - TQWidget *w = NULL; - if(rects[i] == TQStyle::SR_DialogButtonCustom) { - w = d->custom; - } else { - Button b = None; - if(rects[i] == TQStyle::SR_DialogButtonApply) - b = Apply; - else if(rects[i] == TQStyle::SR_DialogButtonAll) - b = All; - else if(rects[i] == TQStyle::SR_DialogButtonAccept) - b = Accept; - else if(rects[i] == TQStyle::SR_DialogButtonReject) - b = Reject; - else if(rects[i] == TQStyle::SR_DialogButtonHelp) - b = Help; - else if(rects[i] == TQStyle::SR_DialogButtonRetry) - b = Retry; - else if(rects[i] == TQStyle::SR_DialogButtonAbort) - b = Abort; - else if(rects[i] == TQStyle::SR_DialogButtonIgnore) - b = Ignore; - if(b != None) { - if(d->buttons.contains(b)) { - w = d->buttons[b]; - if(!(d->visible & b)) { - w->hide(); - continue; - } - } else if(d->visible & b) { - w = createButton(b); - d->buttons.insert(b, w); - } else { - continue; - } - if(w) { - if(b == d->def) { - w->setFocus(); -#ifndef TQT_NO_PROPERTIES - w->setProperty("default", TQVariant(true)); -#endif - } - w->setEnabled(d->enabled & b); - } - } - } - if(w) { - w->show(); - w->setGeometry(style().subRect(rects[i], this)); - } - } -} - -TQSize -TQDialogButtons::sizeHint() const -{ - constPolish(); - TQSize s; - if(d->custom) - s = d->custom->sizeHint(); - return (style().sizeFromContents(TQStyle::CT_DialogButtons, this, s. - expandedTo(TQApplication::globalStrut()))); -} - -TQSize -TQDialogButtons::sizeHint(TQDialogButtons::Button button) const -{ - TQWidget *w = NULL; - if(d->visible & button) { - if(!d->buttons.contains(button)) { - TQDialogButtons *that = (TQDialogButtons*)this; //ick, constness.. - w = that->createButton(button); - that->d->buttons.insert(button, w); - } else { - w = d->buttons[button]; - } - } - return w->sizeHint(); -} - -TQSize -TQDialogButtons::minimumSizeHint() const -{ - return sizeHint(); -} -#endif diff --git a/src/widgets/qdialogbuttons_p.h b/src/widgets/qdialogbuttons_p.h deleted file mode 100644 index a5667245f..000000000 --- a/src/widgets/qdialogbuttons_p.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** Definition of TQDialogButtons class. -** -** Copyright (C) 2005-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 TQDIALOGBUTTONS_P_H -#define TQDIALOGBUTTONS_P_H - -#ifndef QT_H -#ifndef QT_H -#include "tqwidget.h" -#endif // QT_H -#endif - -#ifndef TQT_NO_DIALOGBUTTONS -struct TQDialogButtonsPrivate; - -class -TQDialogButtons : public TQWidget -{ - TQ_OBJECT -public: - enum Button { None=0, Accept=0x01, Reject=0x02, Help=0x04, Apply=0x08, All=0x10, Abort=0x20, Retry=0x40, Ignore=0x80 }; -#ifndef TQT_NO_DIALOG - TQDialogButtons(TQDialog *parent, bool autoConnect = TRUE, TQ_UINT32 buttons = Accept | Reject, - Orientation orient = Horizontal, const char *name = NULL); -#endif // TQT_NO_DIALOG - TQDialogButtons(TQWidget *parent, TQ_UINT32 buttons = Accept | Reject, - Orientation orient = Horizontal, const char *name = NULL); - ~TQDialogButtons(); - - void setQuestionMode(bool); - bool questionMode() const; - - void setButtonEnabled(Button button, bool enabled); - bool isButtonEnabled(Button) const; - - inline void showButton(Button b) { setButtonVisible(b, TRUE) ; } - inline void hideButton(Button b) { setButtonVisible(b, FALSE); } - virtual void setButtonVisible(Button, bool visible); - bool isButtonVisible(Button) const; - TQ_UINT32 visibleButtons() const; - - void addWidget(TQWidget *); - - virtual void setDefaultButton(Button); - Button defaultButton() const; - - virtual void setButtonText(Button, const TQString &); - TQString buttonText(Button) const; - - void setOrientation(Orientation); - Orientation orientation() const; - - virtual TQSize sizeHint(Button) const; - TQSize minimumSizeHint() const; - TQSize sizeHint() const; - -protected: - void layoutButtons(); - virtual TQWidget *createButton(Button); - - void showEvent(TQShowEvent *); - void resizeEvent(TQResizeEvent *); - void styleChanged(TQStyle &); - -private slots: - void handleClicked(); - -signals: - void clicked(Button); - void acceptClicked(); - void rejectClicked(); - void helpClicked(); - void applyClicked(); - void allClicked(); - void retryClicked(); - void ignoreClicked(); - void abortClicked(); - -private: - TQDialogButtonsPrivate *d; - void init(TQ_UINT32, Orientation); -}; -#endif //TQT_NO_DIALOGBUTTONS -#endif //TQDIALOGBUTTONS_P_H diff --git a/src/widgets/qeffects.cpp b/src/widgets/qeffects.cpp index 6f9176175..b98de479f 100644 --- a/src/widgets/qeffects.cpp +++ b/src/widgets/qeffects.cpp @@ -47,7 +47,7 @@ #include "tqtimer.h" #include "tqdatetime.h" #include "ntqguardedptr.h" -#include "ntqscrollview.h" +#include "tqscrollview.h" /* Internal class to get access to protected TQWidget-members diff --git a/src/widgets/qeffects_p.h b/src/widgets/qeffects_p.h index dad8fce9f..d3beb3055 100644 --- a/src/widgets/qeffects_p.h +++ b/src/widgets/qeffects_p.h @@ -47,7 +47,7 @@ // ------------- // // This file is not part of the TQt API. It exists for the convenience -// of qeffects.cpp, qcombobox.cpp, tqpopupmenu.cpp and tqtooltip.cpp. +// of qeffects.cpp, tqcombobox.cpp, tqpopupmenu.cpp and tqtooltip.cpp. // This header file may change from version to version without notice, // or even be removed. // diff --git a/src/widgets/qgroupbox.cpp b/src/widgets/qgroupbox.cpp index 5145a5698..f37b5f6d7 100644 --- a/src/widgets/qgroupbox.cpp +++ b/src/widgets/qgroupbox.cpp @@ -44,13 +44,13 @@ #include "tqpainter.h" #include "tqbitmap.h" #include "ntqaccel.h" -#include "ntqradiobutton.h" +#include "tqradiobutton.h" #include "ntqfocusdata.h" #include "tqobjectlist.h" #include "ntqdrawutil.h" #include "ntqapplication.h" #include "tqstyle.h" -#include "ntqcheckbox.h" +#include "tqcheckbox.h" #include "ntqbuttongroup.h" #if defined(QT_ACCESSIBILITY_SUPPORT) #include "ntqaccessible.h" diff --git a/src/widgets/qlcdnumber.cpp b/src/widgets/qlcdnumber.cpp deleted file mode 100644 index 246804f45..000000000 --- a/src/widgets/qlcdnumber.cpp +++ /dev/null @@ -1,1170 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQLCDNumber class -** -** Created : 940518 -** -** 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 "ntqlcdnumber.h" -#ifndef TQT_NO_LCDNUMBER -#include "tqbitarray.h" -#include "tqpainter.h" - - -/*! - \class TQLCDNumber ntqlcdnumber.h - - \brief The TQLCDNumber widget displays a number with LCD-like digits. - - \ingroup basic - \mainclass - - It can display a number in just about any size. It can display - decimal, hexadecimal, octal or binary numbers. It is easy to - connect to data sources using the display() slot, which is - overloaded to take any of five argument types. - - There are also slots to change the base with setMode() and the - decimal point with setSmallDecimalPoint(). - - TQLCDNumber emits the overflow() signal when it is asked to display - something beyond its range. The range is set by setNumDigits(), - but setSmallDecimalPoint() also influences it. If the display is - set to hexadecimal, octal or binary, the integer equivalent of the - value is displayed. - - These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S, - 6, 7, 8, 9/g, minus, decimal point, A, B, C, D, E, F, h, H, L, o, - P, r, u, U, Y, colon, degree sign (which is specified as single - quote in the string) and space. TQLCDNumber substitutes spaces for - illegal characters. - - It is not possible to retrieve the contents of a TQLCDNumber - object, although you can retrieve the numeric value with value(). - If you really need the text, we recommend that you connect the - signals that feed the display() slot to another slot as well and - store the value there. - - Incidentally, TQLCDNumber is the very oldest part of TQt, tracing - back to a BASIC program on the \link - http://www.nvg.ntnu.no/sinclair/computers/zxspectrum/zxspectrum.htm - Sinclair Spectrum\endlink. - - - - \sa TQLabel, TQFrame -*/ - -/*! - \enum TQLCDNumber::Mode - - This type determines how numbers are shown. - - \value Hex Hexadecimal - \value Dec Decimal - \value Oct Octal - \value Bin Binary - - If the display is set to hexadecimal, octal or binary, the integer - equivalent of the value is displayed. -*/ - -/*! - \enum TQLCDNumber::SegmentStyle - - This type determines the visual appearance of the TQLCDNumber - widget. - - \value Outline gives raised segments filled with the background brush. - \value Filled gives raised segments filled with the foreground brush. - \value Flat gives flat segments filled with the foreground brush. -*/ - - - -/*! - \fn void TQLCDNumber::overflow() - - This signal is emitted whenever the TQLCDNumber is asked to display - a too-large number or a too-long string. - - It is never emitted by setNumDigits(). -*/ - - -static TQString int2string( int num, int base, int ndigits, bool *oflow ) -{ - TQString s; - bool negative; - if ( num < 0 ) { - negative = TRUE; - num = -num; - } else { - negative = FALSE; - } - switch( base ) { - case TQLCDNumber::HEX: - s.sprintf( "%*x", ndigits, num ); - break; - case TQLCDNumber::DEC: - s.sprintf( "%*i", ndigits, num ); - break; - case TQLCDNumber::OCT: - s.sprintf( "%*o", ndigits, num ); - break; - case TQLCDNumber::BIN: - { - char buf[42]; - char *p = &buf[41]; - uint n = num; - int len = 0; - *p = '\0'; - do { - *--p = (char)((n&1)+'0'); - n >>= 1; - len++; - } while ( n != 0 ); - len = ndigits - len; - if ( len > 0 ) - s.fill( ' ', len ); - s += TQString::fromLatin1(p); - } - break; - } - if ( negative ) { - for ( int i=0; i<(int)s.length(); i++ ) { - if ( s[i] != ' ' ) { - if ( i != 0 ) { - s[i-1] = '-'; - } else { - s.insert( 0, '-' ); - } - break; - } - } - } - if ( oflow ) - *oflow = (int)s.length() > ndigits; - return s; -} - - -static TQString double2string( double num, int base, int ndigits, bool *oflow ) -{ - TQString s; - if ( base != TQLCDNumber::DEC ) { - bool of = num >= 2147483648.0 || num < -2147483648.0; - if ( of ) { // oops, integer overflow - if ( oflow ) - *oflow = TRUE; - return s; - } - s = int2string( (int)num, base, ndigits, 0 ); - } else { // decimal base - int nd = ndigits; - do { - s.sprintf( "%*.*g", ndigits, nd, num ); - int i = s.find('e'); - if ( i > 0 && s[i+1]=='+' ) { - s[i] = ' '; - s[i+1] = 'e'; - } - } while (nd-- && (int)s.length() > ndigits); - } - if ( oflow ) - *oflow = (int)s.length() > ndigits; - return s; -} - - -static const char *getSegments( char ch ) // gets list of segments for ch -{ - static const char segments[30][8] = - { { 0, 1, 2, 4, 5, 6,99, 0}, // 0 0 / O - { 2, 5,99, 0, 0, 0, 0, 0}, // 1 1 - { 0, 2, 3, 4, 6,99, 0, 0}, // 2 2 - { 0, 2, 3, 5, 6,99, 0, 0}, // 3 3 - { 1, 2, 3, 5,99, 0, 0, 0}, // 4 4 - { 0, 1, 3, 5, 6,99, 0, 0}, // 5 5 / S - { 0, 1, 3, 4, 5, 6,99, 0}, // 6 6 - { 0, 2, 5,99, 0, 0, 0, 0}, // 7 7 - { 0, 1, 2, 3, 4, 5, 6,99}, // 8 8 - { 0, 1, 2, 3, 5, 6,99, 0}, // 9 9 / g - { 3,99, 0, 0, 0, 0, 0, 0}, // 10 - - { 7,99, 0, 0, 0, 0, 0, 0}, // 11 . - { 0, 1, 2, 3, 4, 5,99, 0}, // 12 A - { 1, 3, 4, 5, 6,99, 0, 0}, // 13 B - { 0, 1, 4, 6,99, 0, 0, 0}, // 14 C - { 2, 3, 4, 5, 6,99, 0, 0}, // 15 D - { 0, 1, 3, 4, 6,99, 0, 0}, // 16 E - { 0, 1, 3, 4,99, 0, 0, 0}, // 17 F - { 1, 3, 4, 5,99, 0, 0, 0}, // 18 h - { 1, 2, 3, 4, 5,99, 0, 0}, // 19 H - { 1, 4, 6,99, 0, 0, 0, 0}, // 20 L - { 3, 4, 5, 6,99, 0, 0, 0}, // 21 o - { 0, 1, 2, 3, 4,99, 0, 0}, // 22 P - { 3, 4,99, 0, 0, 0, 0, 0}, // 23 r - { 4, 5, 6,99, 0, 0, 0, 0}, // 24 u - { 1, 2, 4, 5, 6,99, 0, 0}, // 25 U - { 1, 2, 3, 5, 6,99, 0, 0}, // 26 Y - { 8, 9,99, 0, 0, 0, 0, 0}, // 27 : - { 0, 1, 2, 3,99, 0, 0, 0}, // 28 ' - {99, 0, 0, 0, 0, 0, 0, 0} }; // 29 empty - - if (ch >= '0' && ch <= '9') - return segments[ch - '0']; - if (ch >= 'A' && ch <= 'F') - return segments[ch - 'A' + 12]; - if (ch >= 'a' && ch <= 'f') - return segments[ch - 'a' + 12]; - - int n; - switch ( ch ) { - case '-': - n = 10; break; - case 'O': - n = 0; break; - case 'g': - n = 9; break; - case '.': - n = 11; break; - case 'h': - n = 18; break; - case 'H': - n = 19; break; - case 'l': - case 'L': - n = 20; break; - case 'o': - n = 21; break; - case 'p': - case 'P': - n = 22; break; - case 'r': - case 'R': - n = 23; break; - case 's': - case 'S': - n = 5; break; - case 'u': - n = 24; break; - case 'U': - n = 25; break; - case 'y': - case 'Y': - n = 26; break; - case ':': - n = 27; break; - case '\'': - n = 28; break; - default: - n = 29; break; - } - return segments[n]; -} - - -/*! - Constructs an LCD number, sets the number of digits to 5, the base - to decimal, the decimal point mode to 'small' and the frame style - to a raised box. The segmentStyle() is set to \c Outline. - - The \a parent and \a name arguments are passed to the TQFrame - constructor. - - \sa setNumDigits(), setSmallDecimalPoint() -*/ - -TQLCDNumber::TQLCDNumber( TQWidget *parent, const char *name ) - : TQFrame( parent, name ) -{ - ndigits = 5; - init(); -} - - -/*! - Constructs an LCD number, sets the number of digits to \a - numDigits, the base to decimal, the decimal point mode to 'small' - and the frame style to a raised box. The segmentStyle() is set to - \c Outline. - - The \a parent and \a name arguments are passed to the TQFrame - constructor. - - \sa setNumDigits(), setSmallDecimalPoint() -*/ - -TQLCDNumber::TQLCDNumber( uint numDigits, TQWidget *parent, const char *name ) - : TQFrame( parent, name ) -{ - ndigits = numDigits; - init(); -} - -/*! - \internal -*/ - -void TQLCDNumber::init() -{ - setFrameStyle( TQFrame::Box | TQFrame::Raised ); - val = 0; - base = DEC; - smallPoint = FALSE; - setNumDigits( ndigits ); - setSegmentStyle( Outline ); - d = 0; - setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) ); -} - -/*! - Destroys the LCD number. -*/ - -TQLCDNumber::~TQLCDNumber() -{ -} - - -/*! - \property TQLCDNumber::numDigits - \brief the current number of digits displayed - - Corresponds to the current number of digits. If \l - TQLCDNumber::smallDecimalPoint is FALSE, the decimal point occupies - one digit position. - - \sa numDigits, smallDecimalPoint -*/ - -void TQLCDNumber::setNumDigits( int numDigits ) -{ - if ( numDigits > 99 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQLCDNumber::setNumDigits: (%s) Max 99 digits allowed", - name( "unnamed" ) ); -#endif - numDigits = 99; - } - if (numDigits < 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQLCDNumber::setNumDigits: (%s) Min 0 digits allowed", - name( "unnamed" ) ); -#endif - numDigits = 0; - } - if ( digitStr.isNull() ) { // from constructor - ndigits = numDigits; - digitStr.fill( ' ', ndigits ); - points.fill( 0, ndigits ); - digitStr[ndigits - 1] = '0'; // "0" is the default number - } else { - bool doDisplay = ndigits == 0; - if ( numDigits == ndigits ) // no change - return; - int i; - int dif; - if ( numDigits > ndigits ) { // expand - dif = numDigits - ndigits; - TQString buf; - buf.fill( ' ', dif ); - digitStr.insert( 0, buf ); - points.resize( numDigits ); - for ( i=numDigits-1; i>=dif; i-- ) - points.setBit( i, points.testBit(i-dif) ); - for ( i=0; i=0; i-- ) { - buffer[ndigits - 1 - index + i] = buffer[i]; - newPoints.setBit( ndigits - 1 - index + i, - newPoints.testBit(i) ); - } - for( i=0; i xSegLen ? xSegLen : ySegLen; - int xAdvance = segLen*( 5 + digitSpace )/5; - int xOffset = ( width() - ndigits*xAdvance + segLen/5 )/2; - int yOffset = ( height() - segLen*2 )/2; - - for ( int i=0; itestBit(i) ? '.' : ' '; - if ( newString ) { - char oldPoint = points.testBit(i) ? '.' : ' '; - drawDigit( pos, p, segLen, newPoint, oldPoint ); - } else { - drawDigit( pos, p, segLen, newPoint ); - } - } - } - if ( newString ) { - digitStr = s; - if ( (int)digitStr.length() > ndigits ) - digitStr.truncate( ndigits ); - if ( newPoints ) - points = *newPoints; - } -} - - -/*! - \internal -*/ - -void TQLCDNumber::drawDigit( const TQPoint &pos, TQPainter &p, int segLen, - char newCh, char oldCh ) -{ -// Draws and/or erases segments to change display of a single digit -// from oldCh to newCh - - char updates[18][2]; // can hold 2 times number of segments, only - // first 9 used if segment table is correct - int nErases; - int nUpdates; - const char *segs; - int i,j; - - const char erase = 0; - const char draw = 1; - const char leaveAlone = 2; - - segs = getSegments(oldCh); - for ( nErases=0; segs[nErases] != 99; nErases++ ) { - updates[nErases][0] = erase; // get segments to erase to - updates[nErases][1] = segs[nErases]; // remove old char - } - nUpdates = nErases; - segs = getSegments(newCh); - for(i = 0 ; segs[i] != 99 ; i++) { - for ( j=0; j -#endif -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif - -#ifndef TQT_NO_ACCEL -#include "ntqkeysequence.h" -#define ACCEL_KEY(k) "\t" + TQString(TQKeySequence( TQt::CTRL | TQt::Key_ ## k )) -#else -#define ACCEL_KEY(k) "\t" + TQString("Ctrl+" #k) -#endif - -#if defined(Q_OS_LINUX) -#define LINUX_MEMLOCK_LIMIT_BYTES 16384 -#define LINUX_MEMLOCK_LIMIT_CHARACTERS LINUX_MEMLOCK_LIMIT_BYTES/sizeof(TQChar) -#endif - -#define innerMargin 1 - -struct TQLineEditPrivate : public TQt -{ - TQLineEditPrivate( TQLineEdit *q ) - : q(q), cursor(0), cursorTimer(0), tripleClickTimer(0), frame(1), - cursorVisible(0), separator(0), readOnly(0), modified(0), - direction(TQChar::DirON), dragEnabled(1), alignment(0), - echoMode(0), textDirty(0), selDirty(0), validInput(1), - ascent(0), maxLength(32767), menuId(0), - hscroll(0), validator(0), maskData(0), - undoState(0), selstart(0), selend(0), - imstart(0), imend(0), imselstart(0), imselend(0) -#ifndef TQT_NO_DRAGANDDROP - ,dndTimer(0) -#endif - {} - void init( const TQString&); - - TQLineEdit *q; - TQString text; - int cursor; - int cursorTimer; - TQPoint tripleClick; - int tripleClickTimer; - uint frame : 1; - uint cursorVisible : 1; - uint separator : 1; - uint readOnly : 1; - uint modified : 1; - uint direction : 5; - uint dragEnabled : 1; - uint alignment : 3; - uint echoMode : 2; - uint textDirty : 1; - uint selDirty : 1; - uint validInput : 1; - int ascent; - int maxLength; - int menuId; - int hscroll; - TQChar passwordChar; // obsolete - - void finishChange( int validateFromState = -1, bool setModified = TRUE ); - - const TQValidator* validator; - struct MaskInputData { - enum Casemode { NoCaseMode, Upper, Lower }; - TQChar maskChar; // either the separator char or the inputmask - bool separator; - Casemode caseMode; - }; - TQString inputMask; - TQChar blank; - MaskInputData *maskData; - inline int nextMaskBlank( int pos ) { - int c = findInMask( pos, TRUE, FALSE ); - separator |= ( c != pos ); - return ( c != -1 ? c : maxLength ); - } - inline int prevMaskBlank( int pos ) { - int c = findInMask( pos, FALSE, FALSE ); - separator |= ( c != pos ); - return ( c != -1 ? c : 0 ); - } - - void setCursorVisible( bool visible ); - - - // undo/redo handling - enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection }; - struct Command { - inline Command(){} - inline Command( CommandType type, int pos, TQChar c ) - :type(type),c(c),pos(pos){} - uint type : 4; - TQChar c; - int pos; - }; - int undoState; - TQValueVector history; - void addCommand( const Command& cmd ); - void insert( const TQString& s ); - void del( bool wasBackspace = FALSE ); - void remove( int pos ); - - inline void separate() { separator = TRUE; } - inline void undo( int until = -1 ) { - if ( !isUndoAvailable() ) - return; - deselect(); - while ( undoState && undoState > until ) { - Command& cmd = history[--undoState]; - switch ( cmd.type ) { - case Insert: - text.remove( cmd.pos, 1); - cursor = cmd.pos; - break; - case Remove: - case RemoveSelection: - text.insert( cmd.pos, cmd.c ); - cursor = cmd.pos + 1; - break; - case Delete: - case DeleteSelection: - text.insert( cmd.pos, cmd.c ); - cursor = cmd.pos; - break; - case Separator: - continue; - } - if ( until < 0 && undoState ) { - Command& next = history[undoState-1]; - if ( next.type != cmd.type && next.type < RemoveSelection - && !( cmd.type >= RemoveSelection && next.type != Separator ) ) - break; - } - } - modified = ( undoState != 0 ); - textDirty = TRUE; - } - inline void redo() { - if ( !isRedoAvailable() ) - return; - deselect(); - while ( undoState < (int)history.size() ) { - Command& cmd = history[undoState++]; - switch ( cmd.type ) { - case Insert: - text.insert( cmd.pos, cmd.c ); - cursor = cmd.pos + 1; - break; - case Remove: - case Delete: - case RemoveSelection: - case DeleteSelection: - text.remove( cmd.pos, 1 ); - cursor = cmd.pos; - break; - case Separator: - continue; - } - if ( undoState < (int)history.size() ) { - Command& next = history[undoState]; - if ( next.type != cmd.type && cmd.type < RemoveSelection - && !( next.type >= RemoveSelection && cmd.type != Separator ) ) - break; - } - } - textDirty = TRUE; - } - inline bool isUndoAvailable() const { return !readOnly && undoState; } - inline bool isRedoAvailable() const { return !readOnly && undoState < (int)history.size(); } - - // bidi - inline bool isRightToLeft() const { return direction==TQChar::DirON?text.isRightToLeft():(direction==TQChar::DirR); } - - // selection - int selstart, selend; - inline bool allSelected() const { return !text.isEmpty() && selstart == 0 && selend == (int)text.length(); } - inline bool hasSelectedText() const { return !text.isEmpty() && selend > selstart; } - inline void deselect() { selDirty |= (selend > selstart); selstart = selend = 0; } - void removeSelectedText(); -#ifndef TQT_NO_CLIPBOARD - void copy( bool clipboard = TRUE ) const; -#endif - inline bool inSelection( int x ) const - { if ( selstart >= selend ) return FALSE; - int pos = xToPos( x, TQTextItem::OnCharacters ); return pos >= selstart && pos < selend; } - - // masking - void parseInputMask( const TQString &maskFields ); - bool isValidInput( TQChar key, TQChar mask ) const; - TQString maskString( uint pos, const TQString &str, bool clear = FALSE ) const; - TQString clearString( uint pos, uint len ) const; - TQString stripString( const TQString &str ) const; - int findInMask( int pos, bool forward, bool findSeparator, TQChar searchChar = TQChar() ) const; - - // input methods - int imstart, imend, imselstart, imselend; - bool composeMode() const { return preeditLength(); } - bool hasIMSelection() const { return imSelectionLength(); } - int preeditLength() const { return ( imend - imstart ); } - int imSelectionLength() const { return ( imselend - imselstart ); } - - // complex text layout - TQTextLayout textLayout; - void updateTextLayout(); - void moveCursor( int pos, bool mark = FALSE ); - void setText( const TQString& txt ); - int xToPosInternal( int x, TQTextItem::CursorPosition ) const; - int xToPos( int x, TQTextItem::CursorPosition = TQTextItem::BetweenCharacters ) const; - inline int visualAlignment() const { return alignment ? alignment : int( isRightToLeft() ? AlignRight : AlignLeft ); } - TQRect cursorRect() const; - void updateMicroFocusHint(); - -#ifndef TQT_NO_DRAGANDDROP - // drag and drop - TQPoint dndPos; - int dndTimer; - bool drag(); -#endif -}; - - -/*! - \class TQLineEdit - \brief The TQLineEdit widget is a one-line text editor. - - \ingroup basic - \mainclass - - A line edit allows the user to enter and edit a single line of - plain text with a useful collection of editing functions, - including undo and redo, cut and paste, and drag and drop. - - By changing the echoMode() of a line edit, it can also be used as - a "write-only" field, for inputs such as passwords. - - The length of the text can be constrained to maxLength(). The text - can be arbitrarily constrained using a validator() or an - inputMask(), or both. - - A related class is TQTextEdit which allows multi-line, rich-text - editing. - - You can change the text with setText() or insert(). The text is - retrieved with text(); the displayed text (which may be different, - see \l{EchoMode}) is retrieved with displayText(). Text can be - selected with setSelection() or selectAll(), and the selection can - be cut(), copy()ied and paste()d. The text can be aligned with - setAlignment(). - - When the text changes the textChanged() signal is emitted; when - the Return or Enter key is pressed the returnPressed() signal is - emitted. Note that if there is a validator set on the line edit, - the returnPressed() signal will only be emitted if the validator - returns \c Acceptable. - - By default, TQLineEdits have a frame as specified by the Windows - and Motif style guides; you can turn it off by calling - setFrame(FALSE). - - The default key bindings are described below. The line edit also - provides a context menu (usually invoked by a right mouse click) - that presents some of these editing options. - \target desc - \table - \header \i Keypress \i Action - \row \i Left Arrow \i Moves the cursor one character to the left. - \row \i Shift+Left Arrow \i Moves and selects text one character to the left. - \row \i Right Arrow \i Moves the cursor one character to the right. - \row \i Shift+Right Arrow \i Moves and selects text one character to the right. - \row \i Home \i Moves the cursor to the beginning of the line. - \row \i End \i Moves the cursor to the end of the line. - \row \i Backspace \i Deletes the character to the left of the cursor. - \row \i Ctrl+Backspace \i Deletes the word to the left of the cursor. - \row \i Delete \i Deletes the character to the right of the cursor. - \row \i Ctrl+Delete \i Deletes the word to the right of the cursor. - \row \i Ctrl+A \i Moves the cursor to the beginning of the line. - \row \i Ctrl+B \i Moves the cursor one character to the left. - \row \i Ctrl+C \i Copies the selected text to the clipboard. - (Windows also supports Ctrl+Insert for this operation.) - \row \i Ctrl+D \i Deletes the character to the right of the cursor. - \row \i Ctrl+E \i Moves the cursor to the end of the line. - \row \i Ctrl+F \i Moves the cursor one character to the right. - \row \i Ctrl+H \i Deletes the character to the left of the cursor. - \row \i Ctrl+K \i Deletes to the end of the line. - \row \i Ctrl+V \i Pastes the clipboard text into line edit. - (Windows also supports Shift+Insert for this operation.) - \row \i Ctrl+X \i Deletes the selected text and copies it to the clipboard. - (Windows also supports Shift+Delete for this operation.) - \row \i Ctrl+Z \i Undoes the last operation. - \row \i Ctrl+Y \i Redoes the last undone operation. - \endtable - - Any other key sequence that represents a valid character, will - cause the character to be inserted into the line edit. - - - - \sa TQTextEdit TQLabel TQComboBox - \link guibooks.html#fowler GUI Design Handbook: Field, Entry\endlink -*/ - - -/*! - \fn void TQLineEdit::textChanged( const TQString& ) - - This signal is emitted whenever the text changes. The argument is - the new text. -*/ - -/*! - \fn void TQLineEdit::selectionChanged() - - This signal is emitted whenever the selection changes. - - \sa hasSelectedText(), selectedText() -*/ - -/*! - \fn void TQLineEdit::lostFocus() - - This signal is emitted when the line edit has lost focus. - - \sa hasFocus(), TQWidget::focusInEvent(), TQWidget::focusOutEvent() -*/ - - - -/*! - Constructs a line edit with no text. - - The maximum text length is set to 32767 characters. - - The \a parent and \a name arguments are sent to the TQWidget constructor. - - \sa setText(), setMaxLength() -*/ - -TQLineEdit::TQLineEdit( TQWidget* parent, const char* name ) - : TQFrame( parent, name, WNoAutoErase ), d(new TQLineEditPrivate( this )) -{ - d->init( TQString::null ); -} - -/*! - Constructs a line edit containing the text \a contents. - - The cursor position is set to the end of the line and the maximum - text length to 32767 characters. - - The \a parent and \a name arguments are sent to the TQWidget - constructor. - - \sa text(), setMaxLength() -*/ - -TQLineEdit::TQLineEdit( const TQString& contents, TQWidget* parent, const char* name ) - : TQFrame( parent, name, WNoAutoErase ), d(new TQLineEditPrivate( this )) -{ - d->init( contents ); -} - -/*! - Constructs a line edit with an input \a inputMask and the text \a - contents. - - The cursor position is set to the end of the line and the maximum - text length is set to the length of the mask (the number of mask - characters and separators). - - The \a parent and \a name arguments are sent to the TQWidget - constructor. - - \sa setMask() text() -*/ -TQLineEdit::TQLineEdit( const TQString& contents, const TQString &inputMask, TQWidget* parent, const char* name ) - : TQFrame( parent, name, WNoAutoErase ), d(new TQLineEditPrivate( this )) -{ - d->parseInputMask( inputMask ); - if ( d->maskData ) { - TQString ms = d->maskString( 0, contents ); - d->init( ms + d->clearString( ms.length(), d->maxLength - ms.length() ) ); - d->cursor = d->nextMaskBlank( ms.length() ); - } else { - d->init( contents ); - } -} - -/*! - Destroys the line edit. -*/ - -TQLineEdit::~TQLineEdit() -{ - if ((d->echoMode == NoEcho) || (d->echoMode == Password) || (d->echoMode == PasswordThreeStars)) { - d->text.fill(TQChar(0)); -#if defined(Q_OS_LINUX) - munlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); -#endif - } - delete [] d->maskData; - delete d; -} - - -/*! - \property TQLineEdit::text - \brief the line edit's text - - Note that setting this property clears the selection, clears the - undo/redo history, moves the cursor to the end of the line and - resets the \c modified property to FALSE. The text is not - validated when inserted with setText(). - - The text is truncated to maxLength() length. - - \sa insert() -*/ -TQString TQLineEdit::text() const -{ - TQString res = d->text; - if ( d->maskData ) - res = d->stripString( d->text ); - return ( res.isNull() ? TQString::fromLatin1("") : res ); -} - -void TQLineEdit::setText( const TQString& text) -{ - resetInputContext(); - d->setText( text ); - d->modified = FALSE; - d->finishChange( -1, FALSE ); -} - - -/*! - \property TQLineEdit::displayText - \brief the displayed text - - If \c EchoMode is \c Normal this returns the same as text(); if - \c EchoMode is \c Password it returns a string of asterisks - text().length() characters long, e.g. "******"; if \c EchoMode is - \c NoEcho returns an empty string, "". - - \sa setEchoMode() text() EchoMode -*/ - -TQString TQLineEdit::displayText() const -{ - if ( d->echoMode == NoEcho ) { - return TQString::fromLatin1(""); - } - TQString res = d->text; - if ( d->echoMode == Password ) { - res.fill( passwordChar() ); - } - else if ( d->echoMode == PasswordThreeStars ) { - res.fill( passwordChar(), res.length()*3 ); - } - return ( res.isNull() ? TQString::fromLatin1("") : res ); -} - - -/*! - \property TQLineEdit::maxLength - \brief the maximum permitted length of the text - - If the text is too long, it is truncated at the limit. - - If truncation occurs any selected text will be unselected, the - cursor position is set to 0 and the first part of the string is - shown. - - If the line edit has an input mask, the mask defines the maximum - string length. - - \sa inputMask -*/ - -int TQLineEdit::maxLength() const -{ - return d->maxLength; -} - -void TQLineEdit::setMaxLength( int maxLength ) -{ - if ( d->maskData ) - return; - d->maxLength = maxLength; - setText( d->text ); -} - - - -/*! - \property TQLineEdit::frame - \brief whether the line edit draws itself with a frame - - If enabled (the default) the line edit draws itself inside a - two-pixel frame, otherwise the line edit draws itself without any - frame. -*/ -bool TQLineEdit::frame() const -{ - return frameShape() != NoFrame; -} - - -void TQLineEdit::setFrame( bool enable ) -{ - setFrameStyle( enable ? ( LineEditPanel | Sunken ) : NoFrame ); -} - - -/*! - \enum TQLineEdit::EchoMode - - This enum type describes how a line edit should display its - contents. - - \value Normal Display characters as they are entered. This is the - default. - \value NoEcho Do not display anything. This may be appropriate - for passwords where even the length of the - password should be kept secret. - \value Password Display asterisks instead of the characters - actually entered. - - \sa setEchoMode() echoMode() -*/ - - -/*! - \property TQLineEdit::echoMode - \brief the line edit's echo mode - - The initial setting is \c Normal, but TQLineEdit also supports \c - NoEcho and \c Password modes. - - The widget's display and the ability to copy or drag the text is - affected by this setting. - - \sa EchoMode displayText() -*/ - -TQLineEdit::EchoMode TQLineEdit::echoMode() const -{ - return (EchoMode) d->echoMode; -} - -void TQLineEdit::setEchoMode( EchoMode mode ) -{ - if (mode == (EchoMode)d->echoMode) { - return; - } -#if defined(Q_OS_LINUX) - if (((mode == NoEcho) || (mode == Password) || (mode == PasswordThreeStars)) && ((EchoMode)d->echoMode == Normal)) { - if ((uint)d->maxLength > (LINUX_MEMLOCK_LIMIT_CHARACTERS-1)) { - d->maxLength = LINUX_MEMLOCK_LIMIT_CHARACTERS-1; - } - d->text.reserve(LINUX_MEMLOCK_LIMIT_CHARACTERS); - mlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); - d->text.setSecurityUnPaged(true); - } - else { - d->text.setSecurityUnPaged(false); - munlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); - } -#endif - d->echoMode = mode; - d->updateTextLayout(); - setInputMethodEnabled( ( mode == Normal ) || ( mode == Password) ); - update(); -} - - - -/*! - Returns a pointer to the current input validator, or 0 if no - validator has been set. - - \sa setValidator() -*/ - -const TQValidator * TQLineEdit::validator() const -{ - return d->validator; -} - -/*! - Sets this line edit to only accept input that the validator, \a v, - will accept. This allows you to place any arbitrary constraints on - the text which may be entered. - - If \a v == 0, setValidator() removes the current input validator. - The initial setting is to have no input validator (i.e. any input - is accepted up to maxLength()). - - \sa validator() TQIntValidator TQDoubleValidator TQRegExpValidator -*/ - -void TQLineEdit::setValidator( const TQValidator *v ) -{ - if ( d->validator ) - disconnect( (TQObject*)d->validator, TQ_SIGNAL( destroyed() ), - this, TQ_SLOT( clearValidator() ) ); - d->validator = v; - if ( d->validator ) - connect( (TQObject*)d->validator, TQ_SIGNAL( destroyed() ), - this, TQ_SLOT( clearValidator() ) ); -} - - - -/*! - Returns a recommended size for the widget. - - The width returned, in pixels, is usually enough for about 15 to - 20 characters. -*/ - -TQSize TQLineEdit::sizeHint() const -{ - constPolish(); - TQFontMetrics fm( font() ); - int h = TQMAX(fm.lineSpacing(), 14) + 2*innerMargin; - int w = fm.width( 'x' ) * 17; // "some" - int m = frameWidth() * 2; - return (style().sizeFromContents(TQStyle::CT_LineEdit, this, - TQSize( w + m, h + m ). - expandedTo(TQApplication::globalStrut()))); -} - - -/*! - Returns a minimum size for the line edit. - - The width returned is enough for at least one character. -*/ - -TQSize TQLineEdit::minimumSizeHint() const -{ - constPolish(); - TQFontMetrics fm = fontMetrics(); - int h = fm.height() + TQMAX( 2*innerMargin, fm.leading() ); - int w = fm.maxWidth(); - int m = frameWidth() * 2; - return TQSize( w + m, h + m ); -} - - -/*! - \property TQLineEdit::cursorPosition - \brief the current cursor position for this line edit - - Setting the cursor position causes a repaint when appropriate. -*/ - -int TQLineEdit::cursorPosition() const -{ - return d->cursor; -} - - -void TQLineEdit::setCursorPosition( int pos ) -{ - if (pos < 0) - pos = 0; - - if ( pos <= (int) d->text.length() ) - d->moveCursor( pos ); -} - - -/*! \obsolete Use setText(), setCursorPosition() and setSelection() instead. -*/ - -bool TQLineEdit::validateAndSet( const TQString &newText, int newPos, - int newMarkAnchor, int newMarkDrag ) -{ - int priorState = d->undoState; - d->selstart = 0; - d->selend = d->text.length(); - d->removeSelectedText(); - d->insert( newText ); - d->finishChange( priorState ); - if ( d->undoState > priorState ) { - d->cursor = newPos; - d->selstart = TQMIN( newMarkAnchor, newMarkDrag ); - d->selend = TQMAX( newMarkAnchor, newMarkDrag ); - d->updateMicroFocusHint(); - update(); - return TRUE; - } - return FALSE; -} - - -/*! - \property TQLineEdit::alignment - \brief the alignment of the line edit - - Possible Values are \c TQt::AlignAuto, \c TQt::AlignLeft, \c - TQt::AlignRight and \c TQt::AlignHCenter. - - Attempting to set the alignment to an illegal flag combination - does nothing. - - \sa TQt::AlignmentFlags -*/ - -int TQLineEdit::alignment() const -{ - return d->alignment; -} - -void TQLineEdit::setAlignment( int flag ) -{ - d->alignment = flag & 0x7; - update(); -} - - -/*! - Moves the cursor forward \a steps characters. If \a mark is TRUE - each character moved over is added to the selection; if \a mark is - FALSE the selection is cleared. - - \sa cursorBackward() -*/ - -void TQLineEdit::cursorForward( bool mark, int steps ) -{ - int cursor = d->cursor; - if ( steps > 0 ) { - while( steps-- ) - cursor = d->textLayout.nextCursorPosition( cursor ); - } else if ( steps < 0 ) { - while ( steps++ ) - cursor = d->textLayout.previousCursorPosition( cursor ); - } - d->moveCursor( cursor, mark ); -} - - -/*! - Moves the cursor back \a steps characters. If \a mark is TRUE each - character moved over is added to the selection; if \a mark is - FALSE the selection is cleared. - - \sa cursorForward() -*/ -void TQLineEdit::cursorBackward( bool mark, int steps ) -{ - cursorForward( mark, -steps ); -} - -/*! - Moves the cursor one word forward. If \a mark is TRUE, the word is - also selected. - - \sa cursorWordBackward() -*/ -void TQLineEdit::cursorWordForward( bool mark ) -{ - d->moveCursor( d->textLayout.nextCursorPosition(d->cursor, TQTextLayout::SkipWords), mark ); -} - -/*! - Moves the cursor one word backward. If \a mark is TRUE, the word - is also selected. - - \sa cursorWordForward() -*/ - -void TQLineEdit::cursorWordBackward( bool mark ) -{ - d->moveCursor( d->textLayout.previousCursorPosition(d->cursor, TQTextLayout::SkipWords), mark ); -} - - -/*! - If no text is selected, deletes the character to the left of the - text cursor and moves the cursor one position to the left. If any - text is selected, the cursor is moved to the beginning of the - selected text and the selected text is deleted. - - \sa del() -*/ -void TQLineEdit::backspace() -{ - int priorState = d->undoState; - if ( d->hasSelectedText() ) { - d->removeSelectedText(); - } else if ( d->cursor ) { - --d->cursor; - if ( d->maskData ) - d->cursor = d->prevMaskBlank( d->cursor ); - d->del( TRUE ); - } - d->finishChange( priorState ); -} - -/*! - If no text is selected, deletes the character to the right of the - text cursor. If any text is selected, the cursor is moved to the - beginning of the selected text and the selected text is deleted. - - \sa backspace() -*/ - -void TQLineEdit::del() -{ - int priorState = d->undoState; - if ( d->hasSelectedText() ) { - d->removeSelectedText(); - } else { - int n = d->textLayout.nextCursorPosition( d->cursor ) - d->cursor; - while ( n-- ) - d->del(); - } - d->finishChange( priorState ); -} - -/*! - Moves the text cursor to the beginning of the line unless it is - already there. If \a mark is TRUE, text is selected towards the - first position; otherwise, any selected text is unselected if the - cursor is moved. - - \sa end() -*/ - -void TQLineEdit::home( bool mark ) -{ - d->moveCursor( 0, mark ); -} - -/*! - Moves the text cursor to the end of the line unless it is already - there. If \a mark is TRUE, text is selected towards the last - position; otherwise, any selected text is unselected if the cursor - is moved. - - \sa home() -*/ - -void TQLineEdit::end( bool mark ) -{ - d->moveCursor( d->text.length(), mark ); -} - - -/*! - \property TQLineEdit::modified - \brief whether the line edit's contents has been modified by the user - - The modified flag is never read by TQLineEdit; it has a default value - of FALSE and is changed to TRUE whenever the user changes the line - edit's contents. - - This is useful for things that need to provide a default value but - do not start out knowing what the default should be (perhaps it - depends on other fields on the form). Start the line edit without - the best default, and when the default is known, if modified() - returns FALSE (the user hasn't entered any text), insert the - default value. - - Calling clearModified() or setText() resets the modified flag to - FALSE. -*/ - -bool TQLineEdit::isModified() const -{ - return d->modified; -} - -/*! - Resets the modified flag to FALSE. - - \sa isModified() -*/ -void TQLineEdit::clearModified() -{ - d->modified = FALSE; - d->history.clear(); - d->undoState = 0; -} - -/*! - \obsolete - \property TQLineEdit::edited - \brief whether the line edit has been edited. Use modified instead. -*/ -bool TQLineEdit::edited() const { return d->modified; } -void TQLineEdit::setEdited( bool on ) { d->modified = on; } - -/*! - \property TQLineEdit::hasSelectedText - \brief whether there is any text selected - - hasSelectedText() returns TRUE if some or all of the text has been - selected by the user; otherwise returns FALSE. - - \sa selectedText() -*/ - - -bool TQLineEdit::hasSelectedText() const -{ - return d->hasSelectedText(); -} - -/*! - \property TQLineEdit::selectedText - \brief the selected text - - If there is no selected text this property's value is - TQString::null. - - \sa hasSelectedText() -*/ - -TQString TQLineEdit::selectedText() const -{ - if ( d->hasSelectedText() ) - return d->text.mid( d->selstart, d->selend - d->selstart ); - return TQString::null; -} - -/*! - selectionStart() returns the index of the first selected character in the - line edit or -1 if no text is selected. - - \sa selectedText() -*/ - -int TQLineEdit::selectionStart() const -{ - return d->hasSelectedText() ? d->selstart : -1; -} - -/*! \obsolete use selectedText(), selectionStart() */ -bool TQLineEdit::getSelection( int *start, int *end ) -{ - if ( d->hasSelectedText() && start && end ) { - *start = d->selstart; - *end = d->selend; - return TRUE; - } - return FALSE; -} - - -/*! - Selects text from position \a start and for \a length characters. - - Note that this function sets the cursor's position to the end of - the selection regardless of its current position. - - \sa deselect() selectAll() getSelection() cursorForward() cursorBackward() -*/ - -void TQLineEdit::setSelection( int start, int length ) -{ - if ( start < 0 || start > (int)d->text.length() || length < 0 ) { - d->selstart = d->selend = 0; - } else { - d->selstart = start; - d->selend = TQMIN( start + length, (int)d->text.length() ); - d->cursor = d->selend; - } - update(); -} - - -/*! - \property TQLineEdit::undoAvailable - \brief whether undo is available -*/ - -bool TQLineEdit::isUndoAvailable() const -{ - return d->isUndoAvailable(); -} - -/*! - \property TQLineEdit::redoAvailable - \brief whether redo is available -*/ - -bool TQLineEdit::isRedoAvailable() const -{ - return d->isRedoAvailable(); -} - -/*! - \property TQLineEdit::dragEnabled - \brief whether the lineedit starts a drag if the user presses and - moves the mouse on some selected text -*/ - -bool TQLineEdit::dragEnabled() const -{ - return d->dragEnabled; -} - -void TQLineEdit::setDragEnabled( bool b ) -{ - d->dragEnabled = b; -} - -/*! - \property TQLineEdit::acceptableInput - \brief whether the input satisfies the inputMask and the - validator. - - \sa setInputMask(), setValidator() -*/ -bool TQLineEdit::hasAcceptableInput() const -{ -#ifndef TQT_NO_VALIDATOR - TQString text = d->text; - int cursor = d->cursor; - if ( d->validator && d->validator->validate( text, cursor ) != TQValidator::Acceptable ) - return FALSE; -#endif - - if ( !d->maskData ) - return TRUE; - - if ( d->text.length() != (uint)d->maxLength ) - return FALSE; - - for ( uint i=0; i < (uint)d->maxLength; i++) { - if ( d->maskData[i].separator ) { - if ( d->text[(int)i] != d->maskData[i].maskChar ) - return FALSE; - } else { - if ( !d->isValidInput( d->text[(int)i], d->maskData[i].maskChar ) ) - return FALSE; - } - } - return TRUE; -} - - -/*! - \property TQLineEdit::inputMask - \brief The validation input mask - - If no mask is set, inputMask() returns TQString::null. - - Sets the TQLineEdit's validation mask. Validators can be used - instead of, or in conjunction with masks; see setValidator(). - - Unset the mask and return to normal TQLineEdit operation by passing - an empty string ("") or just calling setInputMask() with no - arguments. - - The mask format understands these mask characters: - \table - \header \i Character \i Meaning - \row \i \c A \i ASCII alphabetic character required. A-Z, a-z. - \row \i \c a \i ASCII alphabetic character permitted but not required. - \row \i \c N \i ASCII alphanumeric character required. A-Z, a-z, 0-9. - \row \i \c n \i ASCII alphanumeric character permitted but not required. - \row \i \c X \i Any character required. - \row \i \c x \i Any character permitted but not required. - \row \i \c 9 \i ASCII digit required. 0-9. - \row \i \c 0 \i ASCII digit permitted but not required. - \row \i \c D \i ASCII digit required. 1-9. - \row \i \c d \i ASCII digit permitted but not required (1-9). - \row \i \c # \i ASCII digit or plus/minus sign permitted but not required. - \row \i \c > \i All following alphabetic characters are uppercased. - \row \i \c < \i All following alphabetic characters are lowercased. - \row \i \c ! \i Switch off case conversion. - \row \i \\ \i Use \\ to escape the special - characters listed above to use them as - separators. - \endtable - - The mask consists of a string of mask characters and separators, - optionally followed by a semi-colon and the character used for - blanks: the blank characters are always removed from the text - after editing. The default blank character is space. - - Examples: - \table - \header \i Mask \i Notes - \row \i \c 000.000.000.000;_ \i IP address; blanks are \c{_}. - \row \i \c 0000-00-00 \i ISO Date; blanks are \c space - \row \i \c >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# \i License number; - blanks are \c - and all (alphabetic) characters are converted to - uppercase. - \endtable - - To get range control (e.g. for an IP address) use masks together - with \link setValidator() validators\endlink. - - \sa maxLength -*/ -TQString TQLineEdit::inputMask() const -{ - return ( d->maskData ? d->inputMask + ';' + d->blank : TQString::null ); -} - -void TQLineEdit::setInputMask( const TQString &inputMask ) -{ - d->parseInputMask( inputMask ); - if ( d->maskData ) - d->moveCursor( d->nextMaskBlank( 0 ) ); -} - -/*! - Selects all the text (i.e. highlights it) and moves the cursor to - the end. This is useful when a default value has been inserted - because if the user types before clicking on the widget, the - selected text will be deleted. - - \sa setSelection() deselect() -*/ - -void TQLineEdit::selectAll() -{ - d->selstart = d->selend = d->cursor = 0; - d->moveCursor( d->text.length(), TRUE ); -} - -/*! - Deselects any selected text. - - \sa setSelection() selectAll() -*/ - -void TQLineEdit::deselect() -{ - d->deselect(); - d->finishChange(); -} - - -/*! - This slot is equivalent to setValidator(0). -*/ - -void TQLineEdit::clearValidator() -{ - setValidator( 0 ); -} - -/*! - Deletes any selected text, inserts \a newText, and validates the - result. If it is valid, it sets it as the new contents of the line - edit. -*/ -void TQLineEdit::insert( const TQString &newText ) -{ -// q->resetInputContext(); //#### FIX ME IN QT - int priorState = d->undoState; - d->removeSelectedText(); - d->insert( newText ); - d->finishChange( priorState ); -} - -/*! - Clears the contents of the line edit. -*/ -void TQLineEdit::clear() -{ - int priorState = d->undoState; - resetInputContext(); - d->selstart = 0; - d->selend = d->text.length(); - d->removeSelectedText(); - d->separate(); - d->finishChange( priorState ); -} - -/*! - Undoes the last operation if undo is \link - TQLineEdit::undoAvailable available\endlink. Deselects any current - selection, and updates the selection start to the current cursor - position. -*/ -void TQLineEdit::undo() -{ - resetInputContext(); - d->undo(); - d->finishChange( -1, FALSE ); -} - -/*! - Redoes the last operation if redo is \link - TQLineEdit::redoAvailable available\endlink. -*/ -void TQLineEdit::redo() -{ - resetInputContext(); - d->redo(); - d->finishChange(); -} - - -/*! - \property TQLineEdit::readOnly - \brief whether the line edit is read only. - - In read-only mode, the user can still copy the text to the - clipboard or drag-and-drop the text (if echoMode() is \c Normal), - but cannot edit it. - - TQLineEdit does not show a cursor in read-only mode. - - \sa setEnabled() -*/ - -bool TQLineEdit::isReadOnly() const -{ - return d->readOnly; -} - -void TQLineEdit::setReadOnly( bool enable ) -{ - d->readOnly = enable; -#ifndef TQT_NO_CURSOR - setCursor( enable ? arrowCursor : ibeamCursor ); -#endif - update(); -} - - -#ifndef TQT_NO_CLIPBOARD -/*! - Copies the selected text to the clipboard and deletes it, if there - is any, and if echoMode() is \c Normal. - - If the current validator disallows deleting the selected text, - cut() will copy without deleting. - - \sa copy() paste() setValidator() -*/ - -void TQLineEdit::cut() -{ - if ( hasSelectedText() ) { - copy(); - del(); - } -} - - -/*! - Copies the selected text to the clipboard, if there is any, and if - echoMode() is \c Normal. - - \sa cut() paste() -*/ - -void TQLineEdit::copy() const -{ - d->copy(); -} - -/*! - Inserts the clipboard's text at the cursor position, deleting any - selected text, providing the line edit is not \link - TQLineEdit::readOnly read-only\endlink. - - If the end result would not be acceptable to the current - \link setValidator() validator\endlink, nothing happens. - - \sa copy() cut() -*/ - -void TQLineEdit::paste() -{ - insert( TQApplication::clipboard()->text( TQClipboard::Clipboard ) ); -} - -void TQLineEditPrivate::copy( bool clipboard ) const -{ - TQString t = q->selectedText(); - if ( !t.isEmpty() && echoMode == TQLineEdit::Normal ) { - q->disconnect( TQApplication::clipboard(), TQ_SIGNAL(selectionChanged()), q, 0); - TQApplication::clipboard()->setText( t, clipboard ? TQClipboard::Clipboard : TQClipboard::Selection ); - q->connect( TQApplication::clipboard(), TQ_SIGNAL(selectionChanged()), - q, TQ_SLOT(clipboardChanged()) ); - } -} - -#endif // !TQT_NO_CLIPBOARD - -/*!\reimp -*/ - -void TQLineEdit::resizeEvent( TQResizeEvent *e ) -{ - TQFrame::resizeEvent( e ); -} - -/*! \reimp -*/ -bool TQLineEdit::event( TQEvent * e ) -{ - if ( e->type() == TQEvent::AccelOverride && !d->readOnly ) { - TQKeyEvent* ke = (TQKeyEvent*) e; - if ( ke->state() == NoButton || ke->state() == ShiftButton - || ke->state() == Keypad ) { - if ( ke->key() < Key_Escape ) { - ke->accept(); - } else { - switch ( ke->key() ) { - case Key_Delete: - case Key_Home: - case Key_End: - case Key_Backspace: - case Key_Left: - case Key_Right: - ke->accept(); - default: - break; - } - } - } else if ( ke->state() & ControlButton ) { - switch ( ke->key() ) { -// Those are too frequently used for application functionality -/* case Key_A: - case Key_B: - case Key_D: - case Key_E: - case Key_F: - case Key_H: - case Key_K: -*/ - case Key_C: - case Key_V: - case Key_X: - case Key_Y: - case Key_Z: - case Key_Left: - case Key_Right: -#if defined (TQ_WS_WIN) - case Key_Insert: - case Key_Delete: -#endif - ke->accept(); - default: - break; - } - } - } else if ( e->type() == TQEvent::Timer ) { - // should be timerEvent, is here for binary compatibility - int timerId = ((TQTimerEvent*)e)->timerId(); - if ( timerId == d->cursorTimer ) { - if(!hasSelectedText() || style().styleHint( TQStyle::SH_BlinkCursorWhenTextSelected )) - d->setCursorVisible( !d->cursorVisible ); -#ifndef TQT_NO_DRAGANDDROP - } else if ( timerId == d->dndTimer ) { - if( !d->drag() ) - return TRUE; -#endif - } else if ( timerId == d->tripleClickTimer ) { - killTimer( d->tripleClickTimer ); - d->tripleClickTimer = 0; - } - } - return TQWidget::event( e ); -} - -/*! \reimp -*/ -void TQLineEdit::mousePressEvent( TQMouseEvent* e ) -{ - if ( sendMouseEventToInputContext( e ) ) - return; - if ( e->button() == RightButton ) - return; - if ( d->tripleClickTimer && ( e->pos() - d->tripleClick ).manhattanLength() < - TQApplication::startDragDistance() ) { - selectAll(); - return; - } - bool mark = e->state() & ShiftButton; - int cursor = d->xToPos( e->pos().x() ); -#ifndef TQT_NO_DRAGANDDROP - if ( !mark && d->dragEnabled && d->echoMode == Normal && - e->button() == LeftButton && d->inSelection( e->pos().x() ) ) { - d->cursor = cursor; - d->updateMicroFocusHint(); - update(); - d->dndPos = e->pos(); - if ( !d->dndTimer ) - d->dndTimer = startTimer( TQApplication::startDragTime() ); - } else -#endif - { - d->moveCursor( cursor, mark ); - } -} - -/*! \reimp -*/ -void TQLineEdit::mouseMoveEvent( TQMouseEvent * e ) -{ - if ( sendMouseEventToInputContext( e ) ) - return; -#ifndef TQT_NO_CURSOR - if ( ( e->state() & MouseButtonMask ) == 0 ) { - if ( !d->readOnly && d->dragEnabled -#ifndef TQT_NO_WHATSTHIS - && !TQWhatsThis::inWhatsThisMode() -#endif - ) - setCursor( ( d->inSelection( e->pos().x() ) ? arrowCursor : ibeamCursor ) ); - } -#endif - - if ( e->state() & LeftButton ) { -#ifndef TQT_NO_DRAGANDDROP - if ( d->dndTimer ) { - if ( ( d->dndPos - e->pos() ).manhattanLength() > TQApplication::startDragDistance() ) - d->drag(); - } else -#endif - { - d->moveCursor( d->xToPos( e->pos().x() ), TRUE ); - } - } -} - -/*! \reimp -*/ -void TQLineEdit::mouseReleaseEvent( TQMouseEvent* e ) -{ - if ( sendMouseEventToInputContext( e ) ) - return; -#ifndef TQT_NO_DRAGANDDROP - if ( e->button() == LeftButton ) { - if ( d->dndTimer ) { - killTimer( d->dndTimer ); - d->dndTimer = 0; - deselect(); - return; - } - } -#endif -#ifndef TQT_NO_CLIPBOARD - if (TQApplication::clipboard()->supportsSelection() ) { - if ( e->button() == LeftButton ) { - d->copy( FALSE ); - } else if ( !d->readOnly && e->button() == MidButton ) { - d->deselect(); - insert( TQApplication::clipboard()->text( TQClipboard::Selection ) ); - } - } -#endif -} - -/*! \reimp -*/ -void TQLineEdit::mouseDoubleClickEvent( TQMouseEvent* e ) -{ - if ( sendMouseEventToInputContext( e ) ) - return; - if ( e->button() == TQt::LeftButton ) { - deselect(); - d->cursor = d->xToPos( e->pos().x() ); - d->cursor = d->textLayout.previousCursorPosition( d->cursor, TQTextLayout::SkipWords ); - // ## text layout should support end of words. - int end = d->textLayout.nextCursorPosition( d->cursor, TQTextLayout::SkipWords ); - while ( end > d->cursor && d->text[end-1].isSpace() ) - --end; - d->moveCursor( end, TRUE ); - d->tripleClickTimer = startTimer( TQApplication::doubleClickInterval() ); - d->tripleClick = e->pos(); - } -} - -/*! - \fn void TQLineEdit::returnPressed() - - This signal is emitted when the Return or Enter key is pressed. - Note that if there is a validator() or inputMask() set on the line - edit, the returnPressed() signal will only be emitted if the input - follows the inputMask() and the validator() returns \c Acceptable. -*/ - -/*! - Converts key press event \a e into a line edit action. - - If Return or Enter is pressed and the current text is valid (or - can be \link TQValidator::fixup() made valid\endlink by the - validator), the signal returnPressed() is emitted. - - The default key bindings are listed in the \link #desc detailed - description.\endlink -*/ - -void TQLineEdit::keyPressEvent( TQKeyEvent * e ) -{ - d->setCursorVisible( TRUE ); - if ( e->key() == Key_Enter || e->key() == Key_Return ) { - const TQValidator * v = d->validator; - if ( hasAcceptableInput() ) { - emit returnPressed(); - } -#ifndef TQT_NO_VALIDATOR - else if ( v && v->validate( d->text, d->cursor ) != TQValidator::Acceptable ) { - TQString vstr = d->text; - v->fixup( vstr ); - if ( vstr != d->text ) { - setText( vstr ); - if ( hasAcceptableInput() ) - emit returnPressed(); - } - } -#endif - e->ignore(); - return; - } - if ( !d->readOnly ) { - TQString t = e->text(); - if ( !t.isEmpty() && (!e->ascii() || e->ascii()>=32) && - e->key() != Key_Delete && - e->key() != Key_Backspace ) { -#ifdef TQ_WS_X11 - extern bool tqt_hebrew_keyboard_hack; - if ( tqt_hebrew_keyboard_hack ) { - // the X11 keyboard layout is broken and does not reverse - // braces correctly. This is a hack to get halfway correct - // behaviour - if ( d->isRightToLeft() ) { - TQChar *c = (TQChar *)t.unicode(); - int l = t.length(); - while( l-- ) { - if ( c->mirrored() ) - *c = c->mirroredChar(); - c++; - } - } - } -#endif - insert( t ); - return; - } - } - bool unknown = FALSE; - if ( e->state() & ControlButton ) { - switch ( e->key() ) { - case Key_A: -#if defined(TQ_WS_X11) - home( e->state() & ShiftButton ); -#else - selectAll(); -#endif - break; - case Key_B: - cursorForward( e->state() & ShiftButton, -1 ); - break; -#ifndef TQT_NO_CLIPBOARD - case Key_C: - copy(); - break; -#endif - case Key_D: - if ( !d->readOnly ) { - del(); - } - break; - case Key_E: - end( e->state() & ShiftButton ); - break; - case Key_F: - cursorForward( e->state() & ShiftButton, 1 ); - break; - case Key_H: - if ( !d->readOnly ) { - backspace(); - } - break; - case Key_K: - if ( !d->readOnly ) { - int priorState = d->undoState; - d->deselect(); - while ( d->cursor < (int) d->text.length() ) - d->del(); - d->finishChange( priorState ); - } - break; -#if defined(TQ_WS_X11) - case Key_U: - if ( !d->readOnly ) - clear(); - break; -#endif -#ifndef TQT_NO_CLIPBOARD - case Key_V: - if ( !d->readOnly ) - paste(); - break; - case Key_X: - if ( !d->readOnly && d->hasSelectedText() && echoMode() == Normal ) { - copy(); - del(); - } - break; -#if defined (TQ_WS_WIN) - case Key_Insert: - copy(); - break; -#endif -#endif - case Key_Delete: - if ( !d->readOnly ) { - cursorWordForward( TRUE ); - del(); - } - break; - case Key_Backspace: - if ( !d->readOnly ) { - cursorWordBackward( TRUE ); - del(); - } - break; - case Key_Right: - case Key_Left: - if ( d->isRightToLeft() == (e->key() == Key_Right) ) { - if (( echoMode() == Normal ) || ( echoMode() == Password )) - cursorWordBackward( e->state() & ShiftButton ); - else - home( e->state() & ShiftButton ); - } else { - if (( echoMode() == Normal ) || ( echoMode() == Password )) - cursorWordForward( e->state() & ShiftButton ); - else - end( e->state() & ShiftButton ); - } - break; - case Key_Z: - if ( !d->readOnly ) { - if(e->state() & ShiftButton) - redo(); - else - undo(); - } - break; - case Key_Y: - if ( !d->readOnly ) - redo(); - break; - default: - unknown = TRUE; - } - } else { // ### check for *no* modifier - switch ( e->key() ) { - case Key_Shift: - // ### TODO - break; - case Key_Left: - case Key_Right: { - int step = (d->isRightToLeft() == (e->key() == Key_Right)) ? -1 : 1; - cursorForward( e->state() & ShiftButton, step ); - } - break; - case Key_Backspace: - if ( !d->readOnly ) { - backspace(); - } - break; - case Key_Home: -#ifdef TQ_WS_MACX - case Key_Up: -#endif - home( e->state() & ShiftButton ); - break; - case Key_End: -#ifdef TQ_WS_MACX - case Key_Down: -#endif - end( e->state() & ShiftButton ); - break; - case Key_Delete: - if ( !d->readOnly ) { -#if defined (TQ_WS_WIN) - if ( e->state() & ShiftButton ) { - cut(); - break; - } -#endif - del(); - } - break; -#if defined (TQ_WS_WIN) - case Key_Insert: - if ( !d->readOnly && e->state() & ShiftButton ) - paste(); - else - unknown = TRUE; - break; -#endif - case Key_F14: // Undo key on Sun keyboards - if ( !d->readOnly ) - undo(); - break; -#ifndef TQT_NO_CLIPBOARD - case Key_F16: // Copy key on Sun keyboards - copy(); - break; - case Key_F18: // Paste key on Sun keyboards - if ( !d->readOnly ) - paste(); - break; - case Key_F20: // Cut key on Sun keyboards - if ( !d->readOnly && hasSelectedText() && echoMode() == Normal ) { - copy(); - del(); - } - break; -#endif - default: - unknown = TRUE; - } - } - if ( e->key() == Key_Direction_L || e->key() == Key_Direction_R ) { - d->direction = (e->key() == Key_Direction_L) ? TQChar::DirL : TQChar::DirR; - d->updateTextLayout(); - update(); - } - - if ( unknown ) - e->ignore(); -} - - -/*! - This function is not intended as polymorphic usage. Just a shared code - fragment that calls TQWidget::sendMouseEventToInputContext() easily for this - class. - */ -bool TQLineEdit::sendMouseEventToInputContext( TQMouseEvent *e ) -{ -#ifndef TQT_NO_IM - if ( d->composeMode() ) { - int cursor = d->xToPosInternal( e->pos().x(), TQTextItem::OnCharacters ); - int mousePos = cursor - d->imstart; - if ( mousePos >= 0 && mousePos < d->preeditLength() ) { - TQWidget::sendMouseEventToInputContext( mousePos, e->type(), - e->button(), e->state() ); - } else if ( e->type() != TQEvent::MouseMove ) { - // send button events on out of preedit - TQWidget::sendMouseEventToInputContext( -1, e->type(), - e->button(), e->state() ); - } - return TRUE; - } -#endif - return FALSE; -} - - -/*! \reimp - */ -void TQLineEdit::imStartEvent( TQIMEvent *e ) -{ - if ( d->readOnly ) { - e->ignore(); - return; - } - d->removeSelectedText(); - d->updateMicroFocusHint(); - d->imstart = d->imend = d->imselstart = d->imselend = d->cursor; -} - -/*! \reimp - */ -void TQLineEdit::imComposeEvent( TQIMEvent *e ) -{ - if ( d->readOnly ) { - e->ignore(); - return; - } - d->text.replace( d->imstart, d->imend - d->imstart, e->text() ); - d->imend = d->imstart + e->text().length(); - d->imselstart = d->imstart + e->cursorPos(); - d->imselend = d->imselstart + e->selectionLength(); - d->cursor = d->imstart + e->cursorPos(); - d->updateTextLayout(); - d->updateMicroFocusHint(); - update(); -} - -/*! \reimp - */ -void TQLineEdit::imEndEvent( TQIMEvent *e ) -{ - if ( d->readOnly) { - e->ignore(); - return; - } - d->text.remove( d->imstart, d->imend - d->imstart ); - d->cursor = d->imselstart = d->imselend = d->imend = d->imstart; - d->textDirty = TRUE; - insert( e->text() ); -} - -/*!\reimp -*/ - -void TQLineEdit::focusInEvent( TQFocusEvent* ) -{ - if ( TQFocusEvent::reason() == TQFocusEvent::Tab || - TQFocusEvent::reason() == TQFocusEvent::Backtab || - TQFocusEvent::reason() == TQFocusEvent::Shortcut ) - d->maskData ? d->moveCursor( d->nextMaskBlank( 0 ) ) : selectAll(); - if ( !d->cursorTimer ) { - int cft = TQApplication::cursorFlashTime(); - d->cursorTimer = cft ? startTimer( cft/2 ) : -1; - } - if( !hasSelectedText() || style().styleHint( TQStyle::SH_BlinkCursorWhenTextSelected ) ) - d->setCursorVisible( TRUE ); - if ( d->hasIMSelection() ) - d->cursor = d->imselstart; - d->updateMicroFocusHint(); -} - -/*!\reimp -*/ - -void TQLineEdit::focusOutEvent( TQFocusEvent* ) -{ - if ( TQFocusEvent::reason() != TQFocusEvent::ActiveWindow && - TQFocusEvent::reason() != TQFocusEvent::Popup ) - deselect(); - d->setCursorVisible( FALSE ); - if ( d->cursorTimer > 0 ) - killTimer( d->cursorTimer ); - d->cursorTimer = 0; - if (TQFocusEvent::reason() != TQFocusEvent::Popup) - emit lostFocus(); -} - -/*!\reimp -*/ -void TQLineEdit::drawContents( TQPainter *p ) -{ - const TQColorGroup& cg = colorGroup(); - TQRect cr = contentsRect(); - TQFontMetrics fm = fontMetrics(); - TQRect lineRect( cr.x() + innerMargin, cr.y() + (cr.height() - fm.height() + 1) / 2, - cr.width() - 2*innerMargin, fm.height() ); - TQBrush bg = TQBrush( paletteBackgroundColor() ); - if ( paletteBackgroundPixmap() ) - bg = TQBrush( cg.background(), *paletteBackgroundPixmap() ); - else if ( !isEnabled() ) - bg = cg.brush( TQColorGroup::Background ); - TQPoint brushOrigin = p->brushOrigin(); - p->save(); - p->setClipRegion( TQRegion(cr) - lineRect ); - p->setBrushOrigin(brushOrigin - backgroundOffset()); - p->fillRect( cr, bg ); - p->restore(); - TQSharedDoubleBuffer buffer( p, lineRect.x(), lineRect.y(), - lineRect.width(), lineRect.height(), - hasFocus() ? TQSharedDoubleBuffer::Force : 0 ); - p = buffer.painter(); - brushOrigin = p->brushOrigin(); - p->setBrushOrigin(brushOrigin - backgroundOffset()); - p->fillRect( lineRect, bg ); - p->setBrushOrigin(brushOrigin); - - // locate cursor position - int cix = 0; - TQTextItem ci = d->textLayout.findItem( d->cursor ); - if ( ci.isValid() ) { - if ( d->cursor != (int)d->text.length() && d->cursor == ci.from() + ci.length() - && ci.isRightToLeft() != d->isRightToLeft() ) - ci = d->textLayout.findItem( d->cursor + 1 ); - cix = ci.x() + ci.cursorToX( d->cursor - ci.from() ); - } - - // horizontal scrolling - int minLB = TQMAX( 0, -fm.minLeftBearing() ); - int minRB = TQMAX( 0, -fm.minRightBearing() ); - int widthUsed = d->textLayout.widthUsed() + 1 + minRB; - if ( (minLB + widthUsed) <= lineRect.width() ) { - switch ( d->visualAlignment() ) { - case AlignRight: - d->hscroll = widthUsed - lineRect.width() + 1; - break; - case AlignHCenter: - d->hscroll = ( widthUsed - lineRect.width() ) / 2; - break; - default: - d->hscroll = 0; - break; - } - d->hscroll -= minLB; - } else if ( cix - d->hscroll >= lineRect.width() ) { - d->hscroll = cix - lineRect.width() + 1; - } else if ( cix - d->hscroll < 0 ) { - d->hscroll = cix; - } else if ( widthUsed - d->hscroll < lineRect.width() ) { - d->hscroll = widthUsed - lineRect.width() + 1; - } else if (d->hscroll < 0) { - d->hscroll = 0; - } - // This updateMicroFocusHint() is corresponding to update() at - // IMCompose event. Although the function is invoked from various - // other points, some situations such as "candidate selection on - // AlignHCenter'ed text" need this invocation because - // updateMicroFocusHint() requires updated contentsRect(), and - // there are no other chances in such situation that invoke the - // function. - d->updateMicroFocusHint(); - // the y offset is there to keep the baseline constant in case we have script changes in the text. - TQPoint topLeft = lineRect.topLeft() - TQPoint(d->hscroll, d->ascent-fm.ascent()); - - // draw text, selections and cursors - p->setPen( cg.text() ); - bool supressCursor = d->readOnly, hasRightToLeft = d->isRightToLeft(); - int textflags = 0; - if ( font().underline() ) - textflags |= TQt::Underline; - if ( font().strikeOut() ) - textflags |= TQt::StrikeOut; - if ( font().overline() ) - textflags |= TQt::Overline; - - for ( int i = 0; i < d->textLayout.numItems(); i++ ) { - TQTextItem ti = d->textLayout.itemAt( i ); - hasRightToLeft |= ti.isRightToLeft(); - int tix = topLeft.x() + ti.x(); - int first = ti.from(); - int last = ti.from() + ti.length() - 1; - - // text and selection - if ( d->selstart < d->selend && (last >= d->selstart && first < d->selend ) ) { - TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->selstart - first, 0 ) ), - lineRect.top() ), - TQPoint( tix + ti.cursorToX( TQMIN( d->selend - first, last - first + 1 ) ) - 1, - lineRect.bottom() ) ).normalize(); - p->save(); - p->setClipRegion( TQRegion( lineRect ) - highlight, TQPainter::CoordPainter ); - p->drawTextItem( topLeft, ti, textflags ); - p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); - p->fillRect( highlight, cg.highlight() ); - p->setPen( cg.highlightedText() ); - p->drawTextItem( topLeft, ti, textflags ); - p->restore(); - } else { - p->drawTextItem( topLeft, ti, textflags ); - } - - // input method edit area - if ( d->composeMode() && (last >= d->imstart && first < d->imend ) ) { - TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->imstart - first, 0 ) ), lineRect.top() ), - TQPoint( tix + ti.cursorToX( TQMIN( d->imend - first, last - first + 1 ) )-1, lineRect.bottom() ) ).normalize(); - p->save(); - p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); - - int h1, s1, v1, h2, s2, v2; - cg.color( TQColorGroup::Base ).hsv( &h1, &s1, &v1 ); - cg.color( TQColorGroup::Background ).hsv( &h2, &s2, &v2 ); - TQColor imCol; - imCol.setHsv( h1, s1, ( v1 + v2 ) / 2 ); - p->fillRect( highlight, imCol ); - p->drawTextItem( topLeft, ti, textflags ); - // draw preedit's underline - if (d->imend - d->imstart > 0) { - p->setPen( cg.text() ); - p->drawLine( highlight.bottomLeft(), highlight.bottomRight() ); - } - p->restore(); - } - - // input method selection - if ( d->hasIMSelection() && (last >= d->imselstart && first < d->imselend ) ) { - TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->imselstart - first, 0 ) ), lineRect.top() ), - TQPoint( tix + ti.cursorToX( TQMIN( d->imselend - first, last - first + 1 ) )-1, lineRect.bottom() ) ).normalize(); - p->save(); - p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); - p->fillRect( highlight, cg.text() ); - p->setPen( paletteBackgroundColor() ); - p->drawTextItem( topLeft, ti, textflags ); - p->restore(); - supressCursor = TRUE; - } - - // overwrite cursor - if ( d->cursorVisible && d->maskData && - d->selend <= d->selstart && (last >= d->cursor && first <= d->cursor ) ) { - TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->cursor - first, 0 ) ), lineRect.top() ), - TQPoint( tix + ti.cursorToX( TQMIN( d->cursor + 1 - first, last - first + 1 ) )-1, lineRect.bottom() ) ).normalize(); - p->save(); - p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); - p->fillRect( highlight, cg.text() ); - p->setPen( paletteBackgroundColor() ); - p->drawTextItem( topLeft, ti, textflags ); - p->restore(); - supressCursor = TRUE; - } - } - - // draw cursor - // - // Asian users regard IM selection text as cursor on candidate - // selection phase of input method, so ordinary cursor should be - // invisible if IM selection text exists. - if ( d->cursorVisible && !supressCursor && !d->hasIMSelection() && (d->echoMode != PasswordThreeStars) ) { - TQPoint from( topLeft.x() + cix, lineRect.top() ); - TQPoint to = from + TQPoint( 0, lineRect.height() ); - p->drawLine( from, to ); - if ( hasRightToLeft ) { - bool rtl = ci.isValid() ? ci.isRightToLeft() : TRUE; - to = from + TQPoint( (rtl ? -2 : 2), 2 ); - p->drawLine( from, to ); - from.ry() += 4; - p->drawLine( from, to ); - } - } - buffer.end(); -} - - -#ifndef TQT_NO_DRAGANDDROP -/*!\reimp -*/ -void TQLineEdit::dragMoveEvent( TQDragMoveEvent *e ) -{ - if ( !d->readOnly && TQTextDrag::canDecode(e) ) { - e->acceptAction(); - d->cursor = d->xToPos( e->pos().x() ); - d->cursorVisible = TRUE; - update(); - } -} - -/*!\reimp */ -void TQLineEdit::dragEnterEvent( TQDragEnterEvent * e ) -{ - TQLineEdit::dragMoveEvent( e ); -} - -/*!\reimp */ -void TQLineEdit::dragLeaveEvent( TQDragLeaveEvent *) -{ - if ( d->cursorVisible ) { - d->cursorVisible = FALSE; - update(); - } -} - -/*!\reimp */ -void TQLineEdit::dropEvent( TQDropEvent* e ) -{ - TQString str; - // try text/plain - TQCString plain = "plain"; - bool decoded = TQTextDrag::decode(e, str, plain); - // otherwise we'll accept any kind of text (like text/uri-list) - if (! decoded) - decoded = TQTextDrag::decode(e, str); - - if ( decoded && !d->readOnly ) { - if ( e->source() == this && e->action() == TQDropEvent::Copy ) - deselect(); - d->cursor =d->xToPos( e->pos().x() ); - int selStart = d->cursor; - int oldSelStart = d->selstart; - int oldSelEnd = d->selend; - d->cursorVisible = FALSE; - e->acceptAction(); - insert( str ); - if ( e->source() == this ) { - if ( e->action() == TQDropEvent::Move ) { - if ( selStart > oldSelStart && selStart <= oldSelEnd ) - setSelection( oldSelStart, str.length() ); - else if ( selStart > oldSelEnd ) - setSelection( selStart - str.length(), str.length() ); - else - setSelection( selStart, str.length() ); - } else { - setSelection( selStart, str.length() ); - } - } - } else { - e->ignore(); - update(); - } -} - -bool TQLineEditPrivate::drag() -{ - q->killTimer( dndTimer ); - dndTimer = 0; - TQTextDrag *tdo = new TQTextDrag( q->selectedText(), q ); - - TQGuardedPtr gptr = q; - bool r = tdo->drag(); - if ( !gptr ) - return FALSE; - - // ### fix the check TQDragObject::target() != q in TQt4 (should not be needed) - if ( r && !readOnly && TQDragObject::target() != q ) { - int priorState = undoState; - removeSelectedText(); - finishChange( priorState ); - } -#ifndef TQT_NO_CURSOR - q->setCursor( readOnly ? arrowCursor : ibeamCursor ); -#endif - return TRUE; -} - -#endif // TQT_NO_DRAGANDDROP - -enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; - -/*!\reimp -*/ -void TQLineEdit::contextMenuEvent( TQContextMenuEvent * e ) -{ -#ifndef TQT_NO_POPUPMENU -#ifndef TQT_NO_IM - if ( d->composeMode() ) - return; -#endif - d->separate(); - TQPopupMenu *menu = createPopupMenu(); - if (!menu) - return; - TQGuardedPtr popup = menu; - TQGuardedPtr that = this; - TQPoint pos = e->reason() == TQContextMenuEvent::Mouse ? e->globalPos() : - mapToGlobal( TQPoint(e->pos().x(), 0) ) + TQPoint( width() / 2, height() / 2 ); - int r = popup->exec( pos ); - delete (TQPopupMenu*)popup; - if ( that && d->menuId ) { - switch ( d->menuId - r ) { - case IdClear: clear(); break; - case IdSelectAll: selectAll(); break; - case IdUndo: undo(); break; - case IdRedo: redo(); break; -#ifndef TQT_NO_CLIPBOARD - case IdCut: cut(); break; - case IdCopy: copy(); break; - case IdPaste: paste(); break; -#endif - default: - ; // nothing selected or lineedit destroyed. Be careful. - } - } -#endif //TQT_NO_POPUPMENU -} - -/*! - This function is called to create the popup menu which is shown - when the user clicks on the line edit with the right mouse button. - If you want to create a custom popup menu, reimplement this - function and return the popup menu you create. The popup menu's - ownership is transferred to the caller. -*/ - -TQPopupMenu *TQLineEdit::createPopupMenu() -{ -#ifndef TQT_NO_POPUPMENU - TQPopupMenu *popup = new TQPopupMenu( this, "qt_edit_menu" ); - int id = d->menuId = popup->insertItem( tr( "&Undo" ) + ACCEL_KEY( Z ) ); - popup->insertItem( tr( "&Redo" ) + ACCEL_KEY( Y ) ); - popup->insertSeparator(); - popup->insertItem( tr( "Cu&t" ) + ACCEL_KEY( X ) ); - popup->insertItem( tr( "&Copy" ) + ACCEL_KEY( C ) ); - popup->insertItem( tr( "&Paste" ) + ACCEL_KEY( V ) ); - popup->insertItem( tr( "Clear" ) ); - popup->insertSeparator(); - popup->insertItem( tr( "Select All" ) -#ifndef TQ_WS_X11 - + ACCEL_KEY( A ) -#endif - ); - -#ifndef TQT_NO_IM - TQInputContext *qic = getInputContext(); - if ( qic ) - qic->addMenusTo( popup ); -#endif - - popup->setItemEnabled( id - IdUndo, d->isUndoAvailable() ); - popup->setItemEnabled( id - IdRedo, d->isRedoAvailable() ); -#ifndef TQT_NO_CLIPBOARD - popup->setItemEnabled( id - IdCut, !d->readOnly && d->hasSelectedText() ); - popup->setItemEnabled( id - IdCopy, d->hasSelectedText() ); - popup->setItemEnabled( id - IdPaste, !d->readOnly && !TQApplication::clipboard()->text().isEmpty() ); -#else - popup->setItemVisible( id - IdCut, FALSE ); - popup->setItemVisible( id - IdCopy, FALSE ); - popup->setItemVisible( id - IdPaste, FALSE ); -#endif - popup->setItemEnabled( id - IdClear, !d->readOnly && !d->text.isEmpty() ); - popup->setItemEnabled( id - IdSelectAll, !d->text.isEmpty() && !d->allSelected() ); - return popup; -#else - return 0; -#endif -} - -/*! \reimp */ -void TQLineEdit::windowActivationChange( bool b ) -{ - //### remove me with WHighlightSelection attribute - if ( palette().active() != palette().inactive() ) - update(); - TQWidget::windowActivationChange( b ); -} - -/*! \reimp */ - -void TQLineEdit::setPalette( const TQPalette & p ) -{ - //### remove me with WHighlightSelection attribute - TQWidget::setPalette( p ); - update(); -} - -/*! \reimp */ -void TQLineEdit::setFont( const TQFont & f ) -{ - TQWidget::setFont( f ); - d->updateTextLayout(); -} - -/*! \obsolete -*/ -int TQLineEdit::characterAt( int xpos, TQChar *chr ) const -{ - int pos = d->xToPos( xpos + contentsRect().x() - d->hscroll + innerMargin ); - if ( chr && pos < (int) d->text.length() ) - *chr = d->text.at( pos ); - return pos; -} - -/*! - \internal - - Sets the password character to \a c. - - \sa passwordChar() -*/ - -void TQLineEdit::setPasswordChar( TQChar c ) -{ - d->passwordChar = c; -} - -/*! - \internal - - Returns the password character. - - \sa setPasswordChar() -*/ -TQChar TQLineEdit::passwordChar() const -{ - return ( d->passwordChar.isNull() ? TQChar( style().styleHint( TQStyle::SH_LineEdit_PasswordCharacter, this ) ) : d->passwordChar ); -} - -void TQLineEdit::clipboardChanged() -{ -} - -void TQLineEditPrivate::init( const TQString& txt ) -{ -#ifndef TQT_NO_CURSOR - q->setCursor( readOnly ? arrowCursor : ibeamCursor ); -#endif - q->setFocusPolicy( TQWidget::StrongFocus ); - q->setInputMethodEnabled( TRUE ); - // Specifies that this widget can use more, but is able to survive on - // less, horizontal space; and is fixed vertically. - q->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) ); - q->setBackgroundMode( PaletteBase ); - q->setKeyCompression( TRUE ); - q->setMouseTracking( TRUE ); - q->setAcceptDrops( TRUE ); - q->setFrame( TRUE ); - text = txt; - updateTextLayout(); - cursor = text.length(); -} - -void TQLineEditPrivate::updateTextLayout() -{ - // replace all non-printable characters with spaces (to avoid - // drawing boxes when using fonts that don't have glyphs for such - // characters) - const TQString &displayText = q->displayText(); - TQString str(displayText.unicode(), displayText.length()); - TQChar* uc = (TQChar*)str.unicode(); - for (int i = 0; i < (int)str.length(); ++i) { - if (! uc[i].isPrint()) - uc[i] = TQChar(0x0020); - } - textLayout.setText( str, q->font() ); - textLayout.setDirection((TQChar::Direction)direction); - textLayout.beginLayout(TQTextLayout::SingleLine); - textLayout.beginLine( INT_MAX ); - while ( !textLayout.atEnd() ) - textLayout.addCurrentItem(); - ascent = 0; - textLayout.endLine(0, 0, TQt::AlignLeft|TQt::SingleLine, &ascent); -} - -int TQLineEditPrivate::xToPosInternal( int x, TQTextItem::CursorPosition betweenOrOn ) const -{ - x-= q->contentsRect().x() - hscroll + innerMargin; - for ( int i = 0; i < textLayout.numItems(); ++i ) { - TQTextItem ti = textLayout.itemAt( i ); - TQRect tir = ti.rect(); - if ( x >= tir.left() && x <= tir.right() ) - return ti.xToCursor( x - tir.x(), betweenOrOn ) + ti.from(); - } - return x < 0 ? -1 : text.length(); -} - -int TQLineEditPrivate::xToPos( int x, TQTextItem::CursorPosition betweenOrOn ) const -{ - int pos = xToPosInternal( x, betweenOrOn ); - return ( pos < 0 ) ? 0 : pos; -} - - -TQRect TQLineEditPrivate::cursorRect() const -{ - TQRect cr = q->contentsRect(); - int cix = cr.x() - hscroll + innerMargin; - TQTextItem ci = textLayout.findItem( cursor ); - if ( ci.isValid() ) { - if ( cursor != (int)text.length() && cursor == ci.from() + ci.length() - && ci.isRightToLeft() != isRightToLeft() ) - ci = textLayout.findItem( cursor + 1 ); - cix += ci.x() + ci.cursorToX( cursor - ci.from() ); - } - int ch = q->fontMetrics().height(); - return TQRect( cix-4, cr.y() + ( cr.height() - ch + 1) / 2, 8, ch + 1 ); -} - -void TQLineEditPrivate::updateMicroFocusHint() -{ - // To reduce redundant microfocus update notification, we remember - // the old rect and update the microfocus if actual update is - // required. The rect o is intentionally static because some - // notifyee requires the microfocus information as global update - // rather than per notifyee update to place shared widget around - // microfocus. - static TQRect o; - if ( q->hasFocus() ) { - TQRect r = cursorRect(); - if ( o != r ) { - o = r; - q->setMicroFocusHint( r.x(), r.y(), r.width(), r.height() ); - } - } -} - -void TQLineEditPrivate::moveCursor( int pos, bool mark ) -{ - if ( pos != cursor ) - separate(); - if ( maskData && pos > cursor ) - pos = nextMaskBlank( pos ); - else if ( maskData && pos < cursor ) - pos = prevMaskBlank( pos ); - bool fullUpdate = mark || hasSelectedText(); - if ( mark ) { - int anchor; - if ( selend > selstart && cursor == selstart ) - anchor = selend; - else if ( selend > selstart && cursor == selend ) - anchor = selstart; - else - anchor = cursor; - selstart = TQMIN( anchor, pos ); - selend = TQMAX( anchor, pos ); - } else { - deselect(); - } - if ( fullUpdate ) { - cursor = pos; - q->update(); - } else { - setCursorVisible( FALSE ); - cursor = pos; - setCursorVisible( TRUE ); - } - updateMicroFocusHint(); - if ( mark && !q->style().styleHint( TQStyle::SH_BlinkCursorWhenTextSelected ) ) - setCursorVisible( FALSE ); - if ( mark || selDirty ) { - selDirty = FALSE; - emit q->selectionChanged(); - } -} - -void TQLineEditPrivate::finishChange( int validateFromState, bool setModified ) -{ - bool lineDirty = selDirty; - if ( textDirty ) { - // do validation - bool wasValidInput = validInput; - validInput = TRUE; -#ifndef TQT_NO_VALIDATOR - if ( validator && validateFromState >= 0 ) { - TQString textCopy = text; - int cursorCopy = cursor; - validInput = ( validator->validate( textCopy, cursorCopy ) != TQValidator::Invalid ); - if ( validInput ) { - if ( text != textCopy ) { - q->setText( textCopy ); - cursor = cursorCopy; - return; - } - cursor = cursorCopy; - } - } -#endif - if ( validateFromState >= 0 && wasValidInput && !validInput ) { - undo( validateFromState ); - history.resize( undoState ); - validInput = TRUE; - textDirty = setModified = FALSE; - } - updateTextLayout(); - updateMicroFocusHint(); - lineDirty |= textDirty; - if ( setModified ) - modified = TRUE; - if ( textDirty ) { - textDirty = FALSE; - emit q->textChanged( maskData ? stripString(text) : text ); - } -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( q, 0, TQAccessible::ValueChanged ); -#endif - } - if ( selDirty ) { - selDirty = FALSE; - emit q->selectionChanged(); - } - if ( lineDirty || !setModified ) - q->update(); -} - -void TQLineEditPrivate::setText( const TQString& txt ) -{ - deselect(); - TQString oldText = text; - if ( maskData ) { - text = maskString( 0, txt, TRUE ); - text += clearString( text.length(), maxLength - text.length() ); - } else { - text = txt.isEmpty() ? txt : txt.left( maxLength ); - } - history.clear(); - undoState = 0; - cursor = text.length(); - textDirty = ( oldText != text ); -} - - -void TQLineEditPrivate::setCursorVisible( bool visible ) -{ - if ( (bool)cursorVisible == visible ) - return; - if ( cursorTimer ) - cursorVisible = visible; - TQRect r = cursorRect(); - if ( maskData || !q->contentsRect().contains( r ) ) - q->update(); - else - q->update( r ); -} - -void TQLineEditPrivate::addCommand( const Command& cmd ) -{ - if ( separator && undoState && history[undoState-1].type != Separator ) { - history.resize( undoState + 2 ); - history[undoState++] = Command( Separator, 0, 0 ); - } else { - history.resize( undoState + 1); - } - separator = FALSE; - history[ undoState++ ] = cmd; -} - -void TQLineEditPrivate::insert( const TQString& s ) -{ - if ( maskData ) { - TQString ms = maskString( cursor, s ); - for ( int i = 0; i < (int) ms.length(); ++i ) { - addCommand ( Command( DeleteSelection, cursor+i, text.at(cursor+i) ) ); - addCommand( Command( Insert, cursor+i, ms.at(i) ) ); - } - text.replace( cursor, ms.length(), ms ); - cursor += ms.length(); - cursor = nextMaskBlank( cursor ); - } else { - int remaining = maxLength - text.length(); - text.insert( cursor, s.left(remaining) ); - for ( int i = 0; i < (int) s.left(remaining).length(); ++i ) - addCommand( Command( Insert, cursor++, s.at(i) ) ); - } - textDirty = TRUE; -} - -void TQLineEditPrivate::del( bool wasBackspace ) -{ - if ( cursor < (int) text.length() ) { - addCommand ( Command( (CommandType)((maskData?2:0)+(wasBackspace?Remove:Delete)), cursor, text.at(cursor) ) ); - if ( maskData ) { - text.replace( cursor, 1, clearString( cursor, 1 ) ); - addCommand( Command( Insert, cursor, text.at( cursor ) ) ); - } else { - text.remove( cursor, 1 ); - } - textDirty = TRUE; - } -} - -void TQLineEditPrivate::removeSelectedText() -{ - if ( selstart < selend && selend <= (int) text.length() ) { - separate(); - int i ; - if ( selstart <= cursor && cursor < selend ) { - // cursor is within the selection. Split up the commands - // to be able to restore the correct cursor position - for ( i = cursor; i >= selstart; --i ) - addCommand ( Command( DeleteSelection, i, text.at(i) ) ); - for ( i = selend - 1; i > cursor; --i ) - addCommand ( Command( DeleteSelection, i - cursor + selstart - 1, text.at(i) ) ); - } else { - for ( i = selend-1; i >= selstart; --i ) - addCommand ( Command( RemoveSelection, i, text.at(i) ) ); - } - if ( maskData ) { - text.replace( selstart, selend - selstart, clearString( selstart, selend - selstart ) ); - for ( int i = 0; i < selend - selstart; ++i ) - addCommand( Command( Insert, selstart + i, text.at( selstart + i ) ) ); - } else { - text.remove( selstart, selend - selstart ); - } - if ( cursor > selstart ) - cursor -= TQMIN( cursor, selend ) - selstart; - deselect(); - textDirty = TRUE; - } -} - -void TQLineEditPrivate::parseInputMask( const TQString &maskFields ) -{ - if ( maskFields.isEmpty() || maskFields.section( ';', 0, 0 ).isEmpty() ) { - if ( maskData ) { - delete [] maskData; - maskData = 0; - maxLength = 32767; - q->setText( TQString::null ); - } - return; - } - - inputMask = maskFields.section( ';', 0, 0 ); - blank = maskFields.section( ';', 1, 1 ).at(0); - if ( blank.isNull() ) - blank = ' '; - - // calculate maxLength / maskData length - maxLength = 0; - TQChar c = 0; - uint i; - for ( i=0; i 0 && inputMask.at( i-1 ) == '\\' ) { - maxLength++; - continue; - } - if ( c != '\\' && c != '!' && - c != '<' && c != '>' && - c != '{' && c != '}' && - c != '[' && c != ']' ) - maxLength++; - } - - delete [] maskData; - maskData = new MaskInputData[ maxLength ]; - - MaskInputData::Casemode m = MaskInputData::NoCaseMode; - c = 0; - bool s; - bool escape = FALSE; - int index = 0; - for ( i = 0; i < inputMask.length(); i++ ) { - c = inputMask.at(i); - if ( escape ) { - s = TRUE; - maskData[ index ].maskChar = c; - maskData[ index ].separator = s; - maskData[ index ].caseMode = m; - index++; - escape = FALSE; - } else if ( c == '<' || c == '>' || c == '!') { - switch ( c ) { - case '<': - m = MaskInputData::Lower; - break; - case '>': - m = MaskInputData::Upper; - break; - case '!': - m = MaskInputData::NoCaseMode; - break; - } - } else if ( c != '{' && c != '}' && c != '[' && c != ']' ) { - switch ( c ) { - case 'A': - case 'a': - case 'N': - case 'n': - case 'X': - case 'x': - case '9': - case '0': - case 'D': - case 'd': - case '#': - s = FALSE; - break; - case '\\': - escape = TRUE; - default: - s = TRUE; - break; - } - - if ( !escape ) { - maskData[ index ].maskChar = c; - maskData[ index ].separator = s; - maskData[ index ].caseMode = m; - index++; - } - } - } - q->setText( TQString::null ); -} - - -/* checks if the key is valid compared to the inputMask */ -bool TQLineEditPrivate::isValidInput( TQChar key, TQChar mask ) const -{ - switch ( mask ) { - case 'A': - if ( key.isLetter() && key != blank ) - return TRUE; - break; - case 'a': - if ( key.isLetter() || key == blank ) - return TRUE; - break; - case 'N': - if ( key.isLetterOrNumber() && key != blank ) - return TRUE; - break; - case 'n': - if ( key.isLetterOrNumber() || key == blank ) - return TRUE; - break; - case 'X': - if ( key.isPrint() && key != blank ) - return TRUE; - break; - case 'x': - if ( key.isPrint() || key == blank ) - return TRUE; - break; - case '9': - if ( key.isNumber() && key != blank ) - return TRUE; - break; - case '0': - if ( key.isNumber() || key == blank ) - return TRUE; - break; - case 'D': - if ( key.isNumber() && key.digitValue() > 0 && key != blank ) - return TRUE; - break; - case 'd': - if ( (key.isNumber() && key.digitValue() > 0) || key == blank ) - return TRUE; - break; - case '#': - if ( key.isNumber() || key == '+' || key == '-' || key == blank ) - return TRUE; - break; - default: - break; - } - return FALSE; -} - -/* - Applies the inputMask on \a str starting from position \a pos in the mask. \a clear - specifies from where characters should be gotten when a separator is met in \a str - TRUE means - that blanks will be used, FALSE that previous input is used. - Calling this when no inputMask is set is undefined. -*/ -TQString TQLineEditPrivate::maskString( uint pos, const TQString &str, bool clear) const -{ - if ( pos >= (uint)maxLength ) - return TQString::fromLatin1(""); - - TQString fill; - fill = clear ? clearString( 0, maxLength ) : text; - - uint strIndex = 0; - TQString s = TQString::fromLatin1(""); - int i = pos; - while ( i < maxLength ) { - if ( strIndex < str.length() ) { - if ( maskData[ i ].separator ) { - s += maskData[ i ].maskChar; - if ( str[(int)strIndex] == maskData[ i ].maskChar ) - strIndex++; - ++i; - } else { - if ( isValidInput( str[(int)strIndex], maskData[ i ].maskChar ) ) { - switch ( maskData[ i ].caseMode ) { - case MaskInputData::Upper: - s += str[(int)strIndex].upper(); - break; - case MaskInputData::Lower: - s += str[(int)strIndex].lower(); - break; - default: - s += str[(int)strIndex]; - } - ++i; - } else { - // search for separator first - int n = findInMask( i, TRUE, TRUE, str[(int)strIndex] ); - if ( n != -1 ) { - if ( str.length() != 1 || i == 0 || (i > 0 && (!maskData[i-1].separator || maskData[i-1].maskChar != str[(int)strIndex])) ) { - s += fill.mid( i, n-i+1 ); - i = n + 1; // update i to find + 1 - } - } else { - // search for valid blank if not - n = findInMask( i, TRUE, FALSE, str[(int)strIndex] ); - if ( n != -1 ) { - s += fill.mid( i, n-i ); - switch ( maskData[ n ].caseMode ) { - case MaskInputData::Upper: - s += str[(int)strIndex].upper(); - break; - case MaskInputData::Lower: - s += str[(int)strIndex].lower(); - break; - default: - s += str[(int)strIndex]; - } - i = n + 1; // updates i to find + 1 - } - } - } - strIndex++; - } - } else - break; - } - - return s; -} - - - -/* - Returns a "cleared" string with only separators and blank chars. - Calling this when no inputMask is set is undefined. -*/ -TQString TQLineEditPrivate::clearString( uint pos, uint len ) const -{ - if ( pos >= (uint)maxLength ) - return TQString::null; - - TQString s; - int end = TQMIN( (uint)maxLength, pos + len ); - for ( int i=pos; i= maxLength || pos < 0 ) - return -1; - - int end = forward ? maxLength : -1; - int step = forward ? 1 : -1; - int i = pos; - - while ( i != end ) { - if ( findSeparator ) { - if ( maskData[ i ].separator && maskData[ i ].maskChar == searchChar ) - return i; - } else { - if ( !maskData[ i ].separator ) { - if ( searchChar.isNull() ) - return i; - else if ( isValidInput( searchChar, maskData[ i ].maskChar ) ) - return i; - } - } - i += step; - } - return -1; -} - - -#endif // TQT_NO_LINEEDIT diff --git a/src/widgets/qlistview.cpp b/src/widgets/qlistview.cpp index 5ee18d929..5c00bca11 100644 --- a/src/widgets/qlistview.cpp +++ b/src/widgets/qlistview.cpp @@ -58,7 +58,7 @@ #include "tqpopupmenu.h" #include "ntqtl.h" #include "tqdragobject.h" -#include "ntqlineedit.h" +#include "tqlineedit.h" #include "ntqvbox.h" #include "tqtooltip.h" #include "tqstyle.h" diff --git a/src/widgets/qmultilineedit.cpp b/src/widgets/qmultilineedit.cpp index 85254a314..bd8ffd8cd 100644 --- a/src/widgets/qmultilineedit.cpp +++ b/src/widgets/qmultilineedit.cpp @@ -41,7 +41,7 @@ #include "ntqmultilineedit.h" #ifndef TQT_NO_MULTILINEEDIT #include "tqpainter.h" -#include "ntqscrollbar.h" +#include "tqscrollbar.h" #include "ntqcursor.h" #include "tqclipboard.h" #include "tqpixmap.h" diff --git a/src/widgets/qpushbutton.cpp b/src/widgets/qpushbutton.cpp deleted file mode 100644 index 37cbccd9d..000000000 --- a/src/widgets/qpushbutton.cpp +++ /dev/null @@ -1,762 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQPushButton class -** -** Created : 940221 -** -** 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 "ntqpushbutton.h" -#ifndef TQT_NO_PUSHBUTTON -#include "ntqdialog.h" -#include "tqfontmetrics.h" -#include "tqpainter.h" -#include "ntqdrawutil.h" -#include "tqpixmap.h" -#include "tqbitmap.h" -#include "tqpopupmenu.h" -#include "ntqguardedptr.h" -#include "ntqapplication.h" -#include "tqtoolbar.h" -#include "tqstyle.h" -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif - -/*! - \class TQPushButton ntqpushbutton.h - \brief The TQPushButton widget provides a command button. - - \ingroup basic - \mainclass - - The push button, or command button, is perhaps the most commonly - used widget in any graphical user interface. Push (click) a button - to command the computer to perform some action, or to answer a - question. Typical buttons are OK, Apply, Cancel, Close, Yes, No - and Help. - - A command button is rectangular and typically displays a text - label describing its action. An underlined character in the label - (signified by preceding it with an ampersand in the text) - indicates an accelerator key, e.g. - \code - TQPushButton *pb = new TQPushButton( "&Download", this ); - \endcode - In this example the accelerator is \e{Alt+D}, and the label text - will be displayed as Download. - - Push buttons can display a textual label or a pixmap, and - optionally a small icon. These can be set using the constructors - and changed later using setText(), setPixmap() and setIconSet(). - If the button is disabled the appearance of the text or pixmap and - iconset will be manipulated with respect to the GUI style to make - the button look "disabled". - - A push button emits the signal clicked() when it is activated by - the mouse, the Spacebar or by a keyboard accelerator. Connect to - this signal to perform the button's action. Push buttons also - provide less commonly used signals, for example, pressed() and - released(). - - Command buttons in dialogs are by default auto-default buttons, - i.e. they become the default push button automatically when they - receive the keyboard input focus. A default button is a push - button that is activated when the user presses the Enter or Return - key in a dialog. You can change this with setAutoDefault(). Note - that auto-default buttons reserve a little extra space which is - necessary to draw a default-button indicator. If you do not want - this space around your buttons, call setAutoDefault(FALSE). - - Being so central, the button widget has grown to accommodate a - great many variations in the past decade. The Microsoft style - guide now shows about ten different states of Windows push buttons - and the text implies that there are dozens more when all the - combinations of features are taken into consideration. - - The most important modes or states are: - \list - \i Available or not (grayed out, disabled). - \i Standard push button, toggling push button or menu button. - \i On or off (only for toggling push buttons). - \i Default or normal. The default button in a dialog can generally - be "clicked" using the Enter or Return key. - \i Auto-repeat or not. - \i Pressed down or not. - \endlist - - As a general rule, use a push button when the application or - dialog window performs an action when the user clicks on it (such - as Apply, Cancel, Close and Help) \e and when the widget is - supposed to have a wide, rectangular shape with a text label. - Small, typically square buttons that change the state of the - window rather than performing an action (such as the buttons in - the top-right corner of the TQFileDialog) are not command buttons, - but tool buttons. TQt provides a special class (TQToolButton) for - these buttons. - - If you need toggle behavior (see setToggleButton()) or a button - that auto-repeats the activation signal when being pushed down - like the arrows in a scroll bar (see setAutoRepeat()), a command - button is probably not what you want. When in doubt, use a tool - button. - - A variation of a command button is a menu button. These provide - not just one command, but several, since when they are clicked - they pop up a menu of options. Use the method setPopup() to - associate a popup menu with a push button. - - Other classes of buttons are option buttons (see TQRadioButton) and - check boxes (see TQCheckBox). - - - - In TQt, the TQButton abstract base class provides most of the modes - and other API, and TQPushButton provides GUI logic. See TQButton for - more information about the API. - - \important text, setText, text, pixmap, setPixmap, accel, setAccel, - isToggleButton, setDown, isDown, isOn, state, autoRepeat, - isExclusiveToggle, group, setAutoRepeat, toggle, pressed, released, - clicked, toggled, state stateChanged - - \sa TQToolButton, TQRadioButton TQCheckBox - \link guibooks.html#fowler GUI Design Handbook: Push Button\endlink -*/ - -/*! - \property TQPushButton::autoDefault - \brief whether the push button is the auto default button - - If this property is set to TRUE then the push button is the auto - default button in a dialog. - - In some GUI styles a default button is drawn with an extra frame - around it, up to 3 pixels or more. TQt automatically keeps this - space free around auto-default buttons, i.e. auto-default buttons - may have a slightly larger size hint. - - This property's default is TRUE for buttons that have a TQDialog - parent; otherwise it defaults to FALSE. - - See the \l default property for details of how \l default and - auto-default interact. -*/ - -/*! - \property TQPushButton::autoMask - \brief whether the button is automatically masked - - \sa TQWidget::setAutoMask() -*/ - -/*! - \property TQPushButton::default - \brief whether the push button is the default button - - If this property is set to TRUE then the push button will be - pressed if the user presses the Enter (or Return) key in a dialog. - - Regardless of focus, if the user presses Enter: If there is a - default button the default button is pressed; otherwise, if - there are one or more \l autoDefault buttons the first \l autoDefault - button that is next in the tab order is pressed. If there are no - default or \l autoDefault buttons only pressing Space on a button - with focus, mouse clicking, or using an accelerator will press a - button. - - In a dialog, only one push button at a time can be the default - button. This button is then displayed with an additional frame - (depending on the GUI style). - - The default button behavior is provided only in dialogs. Buttons - can always be clicked from the keyboard by pressing Enter (or - Return) or the Spacebar when the button has focus. - - This property's default is FALSE. -*/ - -/*! - \property TQPushButton::flat - \brief whether the border is disabled - - This property's default is FALSE. -*/ - -/*! - \property TQPushButton::iconSet - \brief the icon set on the push button - - This property will return 0 if the push button has no iconset. -*/ - -/*! - \property TQPushButton::on - \brief whether the push button is toggled - - This property should only be set for toggle push buttons. The - default value is FALSE. - - \sa isOn(), toggle(), toggled(), isToggleButton() -*/ - -/*! - \property TQPushButton::toggleButton - \brief whether the button is a toggle button - - Toggle buttons have an on/off state similar to \link TQCheckBox - check boxes. \endlink A push button is initially not a toggle - button. - - \sa setOn(), toggle(), isToggleButton() toggled() -*/ - -/*! \property TQPushButton::menuButton - \brief whether the push button has a menu button on it - \obsolete - - If this property is set to TRUE, then a down arrow is drawn on the push - button to indicate that a menu will pop up if the user clicks on the - arrow. -*/ - -class TQPushButtonPrivate -{ -public: - TQPushButtonPrivate() - :iconset( 0 ) - {} - ~TQPushButtonPrivate() - { -#ifndef TQT_NO_ICONSET - delete iconset; -#endif - } -#ifndef TQT_NO_POPUPMENU - TQGuardedPtr popup; -#endif - TQIconSet* iconset; -}; - - -/*! - Constructs a push button with no text. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. -*/ - -TQPushButton::TQPushButton( TQWidget *parent, const char *name ) - : TQButton( parent, name ) -{ - init(); -} - -/*! - Constructs a push button called \a name with the parent \a parent - and the text \a text. -*/ - -TQPushButton::TQPushButton( const TQString &text, TQWidget *parent, - const char *name ) - : TQButton( parent, name ) -{ - init(); - setText( text ); -} - - -/*! - Constructs a push button with an \a icon and a \a text. - - Note that you can also pass a TQPixmap object as an icon (thanks to - the implicit type conversion provided by C++). - - The \a parent and \a name arguments are sent to the TQWidget - constructor. -*/ -#ifndef TQT_NO_ICONSET -TQPushButton::TQPushButton( const TQIconSet& icon, const TQString &text, - TQWidget *parent, const char *name ) - : TQButton( parent, name ) -{ - init(); - setText( text ); - setIconSet( icon ); -} -#endif - - -/*! - Destroys the push button. -*/ -TQPushButton::~TQPushButton() -{ - delete d; -} - -void TQPushButton::init() -{ - d = 0; - defButton = FALSE; - lastEnabled = FALSE; - hasMenuArrow = FALSE; - flt = FALSE; -#ifndef TQT_NO_DIALOG - autoDefButton = ::tqt_cast(topLevelWidget()) != 0; -#else - autoDefButton = FALSE; -#endif - setBackgroundMode( PaletteButton ); - setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); -} - - -/* - Makes the push button a toggle button if \a enable is TRUE or a normal - push button if \a enable is FALSE. - - Toggle buttons have an on/off state similar to \link TQCheckBox check - boxes. \endlink A push button is initially not a toggle button. - - \sa setOn(), toggle(), isToggleButton() toggled() -*/ - -void TQPushButton::setToggleButton( bool enable ) -{ - TQButton::setToggleButton( enable ); -} - - -/* - Switches a toggle button on if \a enable is TRUE or off if \a enable is - FALSE. - \sa isOn(), toggle(), toggled(), isToggleButton() -*/ - -void TQPushButton::setOn( bool enable ) -{ - if ( !isToggleButton() ) - return; - TQButton::setOn( enable ); -} - -void TQPushButton::setAutoDefault( bool enable ) -{ - if ( (bool)autoDefButton == enable ) - return; - autoDefButton = enable; - update(); - updateGeometry(); -} - - -void TQPushButton::setDefault( bool enable ) -{ - if ( (bool)defButton == enable ) - return; // no change - defButton = enable; -#ifndef TQT_NO_DIALOG - if ( defButton && ::tqt_cast(topLevelWidget()) ) - ((TQDialog*)topLevelWidget())->setMainDefault( this ); -#endif - update(); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::StateChanged ); -#endif -} - - -/*! - \reimp -*/ -TQSize TQPushButton::sizeHint() const -{ - constPolish(); - - int w = 0, h = 0; - - // calculate contents size... -#ifndef TQT_NO_ICONSET - if ( iconSet() && !iconSet()->isNull() ) { - int iw = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).width() + 4; - int ih = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).height(); - w += iw; - h = TQMAX( h, ih ); - } -#endif - if ( isMenuButton() ) - w += style().pixelMetric(TQStyle::PM_MenuButtonIndicator, this); - - if ( pixmap() ) { - TQPixmap *pm = (TQPixmap *)pixmap(); - w += pm->width(); - h += pm->height(); - } else { - TQString s( text() ); - bool empty = s.isEmpty(); - if ( empty ) - s = TQString::fromLatin1("XXXX"); - TQFontMetrics fm = fontMetrics(); - TQSize sz = fm.size( ShowPrefix, s ); - if(!empty || !w) - w += sz.width(); - if(!empty || !h) - h = TQMAX(h, sz.height()); - } - - return (style().sizeFromContents(TQStyle::CT_PushButton, this, TQSize(w, h)). - expandedTo(TQApplication::globalStrut())); -} - - -/*! - \reimp -*/ -void TQPushButton::move( int x, int y ) -{ - TQWidget::move( x, y ); -} - -/*! - \reimp -*/ -void TQPushButton::move( const TQPoint &p ) -{ - move( p.x(), p.y() ); -} - -/*! - \reimp -*/ -void TQPushButton::resize( int w, int h ) -{ - TQWidget::resize( w, h ); -} - -/*! - \reimp -*/ -void TQPushButton::resize( const TQSize &s ) -{ - resize( s.width(), s.height() ); -} - -/*! - \reimp -*/ -void TQPushButton::setGeometry( int x, int y, int w, int h ) -{ - TQWidget::setGeometry( x, y, w, h ); -} - -/*! - \reimp -*/ -void TQPushButton::setGeometry( const TQRect &r ) -{ - TQWidget::setGeometry( r ); -} - -/*! - \reimp - */ -void TQPushButton::resizeEvent( TQResizeEvent * ) -{ - if ( autoMask() ) - updateMask(); -} - -/*! - \reimp -*/ -void TQPushButton::drawButton( TQPainter *paint ) -{ - int diw = 0; - if ( isDefault() || autoDefault() ) { - diw = style().pixelMetric(TQStyle::PM_ButtonDefaultIndicator, this); - - if ( diw > 0 ) { - if (backgroundMode() == X11ParentRelative) { - erase( 0, 0, width(), diw ); - erase( 0, 0, diw, height() ); - erase( 0, height() - diw, width(), diw ); - erase( width() - diw, 0, diw, height() ); - } else if ( parentWidget() && parentWidget()->backgroundPixmap() ){ - // pseudo tranparency - paint->drawTiledPixmap( 0, 0, width(), diw, - *parentWidget()->backgroundPixmap(), - x(), y() ); - paint->drawTiledPixmap( 0, 0, diw, height(), - *parentWidget()->backgroundPixmap(), - x(), y() ); - paint->drawTiledPixmap( 0, height()-diw, width(), diw, - *parentWidget()->backgroundPixmap(), - x(), y()+height() ); - paint->drawTiledPixmap( width()-diw, 0, diw, height(), - *parentWidget()->backgroundPixmap(), - x()+width(), y() ); - } else { - paint->fillRect( 0, 0, width(), diw, - colorGroup().brush(TQColorGroup::Background) ); - paint->fillRect( 0, 0, diw, height(), - colorGroup().brush(TQColorGroup::Background) ); - paint->fillRect( 0, height()-diw, width(), diw, - colorGroup().brush(TQColorGroup::Background) ); - paint->fillRect( width()-diw, 0, diw, height(), - colorGroup().brush(TQColorGroup::Background) ); - } - - } - } - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (isDown()) - flags |= TQStyle::Style_Down; - if (isOn()) - flags |= TQStyle::Style_On; - if (! isFlat() && ! isDown()) - flags |= TQStyle::Style_Raised; - if (isDefault()) - flags |= TQStyle::Style_ButtonDefault; - if (hasMouse()) - flags |= TQStyle::Style_MouseOver; - - style().drawControl(TQStyle::CE_PushButton, paint, this, rect(), colorGroup(), flags); - drawButtonLabel( paint ); - - lastEnabled = isEnabled(); -} - - -/*! - \reimp -*/ -void TQPushButton::drawButtonLabel( TQPainter *paint ) -{ - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (isDown()) - flags |= TQStyle::Style_Down; - if (isOn()) - flags |= TQStyle::Style_On; - if (! isFlat() && ! isDown()) - flags |= TQStyle::Style_Raised; - if (isDefault()) - flags |= TQStyle::Style_ButtonDefault; - - style().drawControl(TQStyle::CE_PushButtonLabel, paint, this, - style().subRect(TQStyle::SR_PushButtonContents, this), - colorGroup(), flags); -} - - -/*! - \reimp - */ -void TQPushButton::updateMask() -{ - TQBitmap bm( size() ); - bm.fill( color0 ); - - { - TQPainter p( &bm, this ); - style().drawControlMask(TQStyle::CE_PushButton, &p, this, rect()); - } - - setMask( bm ); -} - -/*! - \reimp -*/ -void TQPushButton::focusInEvent( TQFocusEvent *e ) -{ - if (autoDefButton && !defButton) { - defButton = TRUE; -#ifndef TQT_NO_DIALOG - if ( defButton && ::tqt_cast(topLevelWidget()) ) - ((TQDialog*)topLevelWidget())->setDefault( this ); -#endif - } - TQButton::focusInEvent( e ); -} - -/*! - \reimp -*/ -void TQPushButton::focusOutEvent( TQFocusEvent *e ) -{ -#ifndef TQT_NO_DIALOG - if ( defButton && autoDefButton ) { - if ( ::tqt_cast(topLevelWidget()) ) - ((TQDialog*)topLevelWidget())->setDefault( 0 ); - } -#endif - - TQButton::focusOutEvent( e ); -#ifndef TQT_NO_POPUPMENU - if ( popup() && popup()->isVisible() ) // restore pressed status - setDown( TRUE ); -#endif -} - - -#ifndef TQT_NO_POPUPMENU -/*! - Associates the popup menu \a popup with this push button. This - turns the button into a menu button. - - Ownership of the popup menu is \e not transferred to the push - button. - - \sa popup() -*/ -void TQPushButton::setPopup( TQPopupMenu* popup ) -{ - if ( !d ) - d = new TQPushButtonPrivate; - if ( popup && !d->popup ) - connect( this, TQ_SIGNAL( pressed() ), this, TQ_SLOT( popupPressed() ) ); - - d->popup = popup; - setIsMenuButton( popup != 0 ); -} -#endif //TQT_NO_POPUPMENU -#ifndef TQT_NO_ICONSET -void TQPushButton::setIconSet( const TQIconSet& icon ) -{ - if ( !d ) - d = new TQPushButtonPrivate; - if ( !icon.isNull() ) { - if ( d->iconset ) - *d->iconset = icon; - else - d->iconset = new TQIconSet( icon ); - } else if ( d->iconset) { - delete d->iconset; - d->iconset = 0; - } - - update(); - updateGeometry(); -} - - -TQIconSet* TQPushButton::iconSet() const -{ - return d ? d->iconset : 0; -} -#endif // TQT_NO_ICONSET -#ifndef TQT_NO_POPUPMENU -/*! - Returns the button's associated popup menu or 0 if no popup menu - has been set. - - \sa setPopup() -*/ -TQPopupMenu* TQPushButton::popup() const -{ - return d ? (TQPopupMenu*)d->popup : 0; -} - -void TQPushButton::popupPressed() -{ - TQPopupMenu* popup = d ? (TQPopupMenu*) d->popup : 0; - TQGuardedPtr that = this; - if ( isDown() && popup ) { - bool horizontal = TRUE; - bool topLeft = TRUE; // ### always TRUE -#ifndef TQT_NO_TOOLBAR - TQToolBar *tb = ::tqt_cast(parentWidget()); - if ( tb && tb->orientation() == Vertical ) - horizontal = FALSE; -#endif - if ( horizontal ) { - if ( topLeft ) { - if ( mapToGlobal( TQPoint( 0, rect().bottom() ) ).y() + popup->sizeHint().height() <= tqApp->desktop()->height() ) - popup->exec( mapToGlobal( rect().bottomLeft() ) ); - else - popup->exec( mapToGlobal( rect().topLeft() - TQPoint( 0, popup->sizeHint().height() ) ) ); - } else { - TQSize sz( popup->sizeHint() ); - TQPoint p = mapToGlobal( rect().topLeft() ); - p.ry() -= sz.height(); - popup->exec( p ); - } - } else { - if ( topLeft ) { - if ( mapToGlobal( TQPoint( rect().right(), 0 ) ).x() + popup->sizeHint().width() <= tqApp->desktop()->width() ) - popup->exec( mapToGlobal( rect().topRight() ) ); - else - popup->exec( mapToGlobal( rect().topLeft() - TQPoint( popup->sizeHint().width(), 0 ) ) ); - } else { - TQSize sz( popup->sizeHint() ); - TQPoint p = mapToGlobal( rect().topLeft() ); - p.rx() -= sz.width(); - popup->exec( p ); - } - } - if (that) - setDown( FALSE ); - } -} -#endif - -void TQPushButton::setFlat( bool f ) -{ - flt = f; - update(); -} - -bool TQPushButton::isFlat() const -{ - return flt; -} - -/*! - \obsolete - \fn virtual void TQPushButton::setIsMenuButton( bool enable ) -*/ - -#endif diff --git a/src/widgets/qradiobutton.cpp b/src/widgets/qradiobutton.cpp deleted file mode 100644 index dead844e5..000000000 --- a/src/widgets/qradiobutton.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQRadioButton class -** -** Created : 940222 -** -** 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 "ntqradiobutton.h" -#ifndef TQT_NO_RADIOBUTTON -#include "ntqbuttongroup.h" -#include "tqpainter.h" -#include "ntqdrawutil.h" -#include "tqpixmap.h" -#include "tqpixmapcache.h" -#include "tqbitmap.h" -#include "tqtextstream.h" -#include "ntqapplication.h" -#include "tqstyle.h" - -/*! - \class TQRadioButton ntqradiobutton.h - \brief The TQRadioButton widget provides a radio button with a text or pixmap label. - - \ingroup basic - \mainclass - - TQRadioButton and TQCheckBox are both option buttons. That is, they - can be switched on (checked) or off (unchecked). The classes - differ in how the choices for the user are restricted. Check boxes - define "many of many" choices, whereas radio buttons provide a - "one of many" choice. In a group of radio buttons only one radio - button at a time can be checked; if the user selects another - button, the previously selected button is switched off. - - The easiest way to implement a "one of many" choice is simply to - put the radio buttons into TQButtonGroup. - - Whenever a button is switched on or off it emits the signal - toggled(). Connect to this signal if you want to trigger an action - each time the button changes state. Otherwise, use isChecked() to - see if a particular button is selected. - - Just like TQPushButton, a radio button can display text or a - pixmap. The text can be set in the constructor or with setText(); - the pixmap is set with setPixmap(). - - - - \important text, setText, text, pixmap, setPixmap, accel, setAccel, isToggleButton, setDown, isDown, isOn, state, autoRepeat, isExclusiveToggle, group, setAutoRepeat, toggle, pressed, released, clicked, toggled, state stateChanged - - \sa TQPushButton TQToolButton - \link guibooks.html#fowler GUI Design Handbook: Radio Button\endlink -*/ - -/*! - \property TQRadioButton::checked \brief Whether the radio button is - checked - - This property will not effect any other radio buttons unless they - have been placed in the same TQButtonGroup. The default value is - FALSE (unchecked). -*/ - -/*! - \property TQRadioButton::autoMask \brief whether the radio button - is automatically masked - - \sa TQWidget::setAutoMask() -*/ - -/*! - Constructs a radio button with no text. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. -*/ - -TQRadioButton::TQRadioButton( TQWidget *parent, const char *name ) - : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) -{ - init(); -} - -/*! - Constructs a radio button with the text \a text. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. -*/ - -TQRadioButton::TQRadioButton( const TQString &text, TQWidget *parent, - const char *name ) - : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) -{ - init(); - setText( text ); -} - - -/* - Initializes the radio button. -*/ - -void TQRadioButton::init() -{ - setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); - setToggleButton( TRUE ); -#ifndef TQT_NO_BUTTONGROUP - TQButtonGroup *bgrp = ::tqt_cast(parentWidget()); - if ( bgrp ) - bgrp->setRadioButtonExclusive( TRUE ); -#endif -} - -void TQRadioButton::setChecked( bool check ) -{ - setOn( check ); -} - - - - -/*! - \reimp -*/ -TQSize TQRadioButton::sizeHint() const -{ - // Any more complex, and we will use style().itemRect() - // NB: TQCheckBox::sizeHint() is similar - constPolish(); - - TQPainter p(this); - TQSize sz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, - pixmap(), text()).size(); - - return (style().sizeFromContents(TQStyle::CT_RadioButton, this, sz). - expandedTo(TQApplication::globalStrut())); -} - - -/*! - \reimp -*/ -bool TQRadioButton::hitButton( const TQPoint &pos ) const -{ - TQRect r = - TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonFocusRect, - this ), this ); - if ( tqApp->reverseLayout() ) { - r.setRight( width() ); - } else { - r.setLeft( 0 ); - } - return r.contains( pos ); -} - - -/*! - \reimp -*/ -void TQRadioButton::drawButton( TQPainter *paint ) -{ - TQPainter *p = paint; - TQRect irect = TQStyle::visualRect( style().subRect(TQStyle::SR_RadioButtonIndicator, this), this ); - const TQColorGroup &cg = colorGroup(); - -#if !defined( TQT_NO_TEXTSTREAM ) && !defined( TQ_WS_MACX ) -# define SAVE_RADIOBUTTON_PIXMAPS -#endif -#if defined(SAVE_RADIOBUTTON_PIXMAPS) - TQString pmkey; // pixmap key - int kf = 0; - if ( isDown() ) - kf |= 1; - if ( isOn() ) - kf |= 2; - if ( isEnabled() ) - kf |= 4; - if( isActiveWindow() ) - kf |= 8; - if ( hasMouse() ) - kf |= 16; - if ( hasFocus() ) - kf |= 32; - - TQTextOStream os(&pmkey); - os << "$qt_radio_" << style().className() << "_" - << palette().serialNumber() << "_" << irect.width() << "x" << irect.height() << "_" << kf; - TQPixmap *pm = TQPixmapCache::find( pmkey ); - if ( pm ) { // pixmap exists - drawButtonLabel( p ); - p->drawPixmap( irect.topLeft(), *pm ); - return; - } - bool use_pm = TRUE; - TQPainter pmpaint; - int wx, wy; - if ( use_pm ) { - pm = new TQPixmap( irect.size() ); // create new pixmap - TQ_CHECK_PTR( pm ); - pm->fill(paletteBackgroundColor()); - TQPainter::redirect(this, pm); - pmpaint.begin(this); - p = &pmpaint; // draw in pixmap - wx = irect.x(); // save x,y coords - wy = irect.y(); - irect.moveTopLeft(TQPoint(0, 0)); - p->setBackgroundColor(paletteBackgroundColor()); - } -#endif - - TQStyle::SFlags flags = TQStyle::Style_Default; - if ( isEnabled() ) - flags |= TQStyle::Style_Enabled; - if ( hasFocus() ) - flags |= TQStyle::Style_HasFocus; - if ( isDown() ) - flags |= TQStyle::Style_Down; - if ( hasMouse() ) - flags |= TQStyle::Style_MouseOver; - if ( state() == TQButton::On ) - flags |= TQStyle::Style_On; - else if ( state() == TQButton::Off ) - flags |= TQStyle::Style_Off; - - style().drawControl(TQStyle::CE_RadioButton, p, this, irect, cg, flags); - -#if defined(SAVE_RADIOBUTTON_PIXMAPS) - if ( use_pm ) { - pmpaint.end(); - TQPainter::redirect(this, NULL); - if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) { - TQBitmap bm( pm->size() ); - bm.fill( color0 ); - pmpaint.begin( &bm ); - style().drawControlMask(TQStyle::CE_RadioButton, &pmpaint, this, irect); - pmpaint.end(); - pm->setMask( bm ); - } - p = paint; // draw in default device - p->drawPixmap( wx, wy, *pm ); - if (!TQPixmapCache::insert(pmkey, pm) ) // save in cache - delete pm; - } -#endif - - drawButtonLabel( p ); -} - - - -/*! - \reimp -*/ -void TQRadioButton::drawButtonLabel( TQPainter *p ) -{ - TQRect r = - TQStyle::visualRect( style().subRect(TQStyle::SR_RadioButtonContents, - this), this ); - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (isDown()) - flags |= TQStyle::Style_Down; - if (state() == TQButton::On) - flags |= TQStyle::Style_On; - else if (state() == TQButton::Off) - flags |= TQStyle::Style_Off; - - style().drawControl(TQStyle::CE_RadioButtonLabel, p, this, r, colorGroup(), flags); -} - - -/*! - \reimp -*/ -void TQRadioButton::resizeEvent( TQResizeEvent* e ) -{ - TQButton::resizeEvent(e); - if ( isVisible() ) { - TQPainter p(this); - TQSize isz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, - pixmap(), text()).size(); - TQSize wsz = (style().sizeFromContents(TQStyle::CT_RadioButton, this, isz). - expandedTo(TQApplication::globalStrut())); - - update(wsz.width(), isz.width(), 0, wsz.height()); - } - if (autoMask()) - updateMask(); -} - -/*! - \reimp -*/ -void TQRadioButton::updateMask() -{ - TQRect irect = - TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonIndicator, - this ), this ); - - TQBitmap bm(width(), height()); - bm.fill(color0); - - TQPainter p( &bm, this ); - style().drawControlMask(TQStyle::CE_RadioButton, &p, this, irect); - if ( ! text().isNull() || ( pixmap() && ! pixmap()->isNull() ) ) { - TQRect crect = - TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonContents, - this ), this ); - TQRect frect = - TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonFocusRect, - this ), this ); - TQRect label(crect.unite(frect)); - p.fillRect(label, color1); - } - p.end(); - - setMask(bm); -} - -#endif diff --git a/src/widgets/qscrollbar.cpp b/src/widgets/qscrollbar.cpp deleted file mode 100644 index 2b350c30a..000000000 --- a/src/widgets/qscrollbar.cpp +++ /dev/null @@ -1,1074 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQScrollBar class -** -** Created : 940427 -** -** 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 "ntqscrollbar.h" -#ifndef TQT_NO_SCROLLBAR -#include "tqpainter.h" -#include "tqbitmap.h" -#include "ntqapplication.h" -#include "tqtimer.h" -#include "tqstyle.h" -#ifndef TQT_NO_CURSOR -#include -#endif -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif -#include - -/*! - \class TQScrollBar - \brief The TQScrollBar widget provides a vertical or horizontal scroll bar. - - \ingroup basic - - A scroll bar allows the user to control a value within a - program-definable range and gives users a visible indication of - the current value of a \link TQRangeControl range control \endlink. - - Scroll bars include four separate controls: - - \list - - \i The \e line-up and \e line-down controls are little buttons - which the user can use to move one "line" up or down. The meaning - of line is configurable. In editors and list boxes it means one - line of text; in an image viewer it might mean 20 pixels. - - \i The \e slider is the handle that indicates the current value of - the scroll bar, which the user can drag to change the value. This - part of the scroll bar is sometimes called the "thumb". - - \i The \e page-up/page-down control is the area on which the - slider slides (the scroll bar's background). Clicking here moves - the scroll bar towards the click. The meaning of "page" is also - configurable: in editors and list boxes it means as many lines as - there is space for in the widget. - - \endlist - - TQScrollBar has very few of its own functions; it mostly relies on - TQRangeControl. The most useful functions are setValue() to set the - scroll bar directly to some value; addPage(), addLine(), - subtractPage(), and subtractLine() to simulate the effects of - clicking (useful for accelerator keys); setSteps() to define the - values of pageStep() and lineStep(); and setRange() to set the - minValue() and maxValue() of the scroll bar. TQScrollBar has a - convenience constructor with which you can set most of these - properties. - - Some GUI styles (for example, the Windows and Motif styles - provided with TQt), also use the pageStep() value to calculate the - size of the slider. - - In addition to the access functions from TQRangeControl, TQScrollBar - provides a comprehensive set of signals: - \table - \header \i Signal \i Emitted when - \row \i \l valueChanged() - \i the scroll bar's value has changed. The tracking() - determines whether this signal is emitted during user - interaction. - \row \i \l sliderPressed() - \i the user starts to drag the slider. - \row \i \l sliderMoved() - \i the user drags the slider. - \row \i \l sliderReleased() - \i the user releases the slider. - \row \i \l nextLine() - \i the scroll bar has moved one line down or right. Line is - defined in TQRangeControl. - \row \i \l prevLine() - \i the scroll bar has moved one line up or left. - \row \i \l nextPage() - \i the scroll bar has moved one page down or right. - \row \i \l prevPage() - \i the scroll bar has moved one page up or left. - \endtable - - TQScrollBar only provides integer ranges. Note that although - TQScrollBar handles very large numbers, scroll bars on current - screens cannot usefully control ranges above about 100,000 pixels. - Beyond that, it becomes difficult for the user to control the - scroll bar using either the keyboard or the mouse. - - A scroll bar can be controlled by the keyboard, but it has a - default focusPolicy() of \c NoFocus. Use setFocusPolicy() to - enable keyboard focus. See keyPressEvent() for a list of key - bindings. - - If you need to add scroll bars to an interface, consider using the - TQScrollView class, which encapsulates the common uses for scroll - bars. - - - - \sa TQSlider TQSpinBox TQScrollView - \link guibooks.html#fowler GUI Design Handbook: Scroll Bar\endlink -*/ - - -/*! - \fn void TQScrollBar::valueChanged( int value ) - - This signal is emitted when the scroll bar value has changed, with - the new scroll bar \a value as an argument. -*/ - -/*! - \fn void TQScrollBar::sliderPressed() - - This signal is emitted when the user presses the slider with the - mouse. -*/ - -/*! - \fn void TQScrollBar::sliderMoved( int value ) - - This signal is emitted when the slider is dragged by the user, with - the new scroll bar \a value as an argument. - - This signal is emitted even when tracking is turned off. - - \sa tracking() valueChanged() nextLine() prevLine() nextPage() - prevPage() -*/ - -/*! - \fn void TQScrollBar::sliderReleased() - - This signal is emitted when the user releases the slider with the - mouse. -*/ - -/*! - \fn void TQScrollBar::nextLine() - - This signal is emitted when the scroll bar scrolls one line down - or right. -*/ - -/*! - \fn void TQScrollBar::prevLine() - - This signal is emitted when the scroll bar scrolls one line up or - left. -*/ - -/*! - \fn void TQScrollBar::nextPage() - - This signal is emitted when the scroll bar scrolls one page down - or right. -*/ - -/*! - \fn void TQScrollBar::prevPage() - - This signal is emitted when the scroll bar scrolls one page up or - left. -*/ - - - -static const int thresholdTime = 500; -static const int repeatTime = 50; - -#define HORIZONTAL (orientation() == Horizontal) -#define VERTICAL !HORIZONTAL -#define MOTIF_BORDER 2 -#define SLIDER_MIN 9 - - -/*! - Constructs a vertical scroll bar. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. - - The \c minValue defaults to 0, the \c maxValue to 99, with a \c - lineStep size of 1 and a \c pageStep size of 10, and an initial - \c value of 0. -*/ - -TQScrollBar::TQScrollBar( TQWidget *parent, const char *name ) - : TQWidget( parent, name ), orient( Vertical ) -{ - init(); -} - -/*! - Constructs a scroll bar. - - The \a orientation must be \c TQt::Vertical or \c TQt::Horizontal. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. - - The \c minValue defaults to 0, the \c maxValue to 99, with a \c - lineStep size of 1 and a \c pageStep size of 10, and an initial - \c value of 0. -*/ - -TQScrollBar::TQScrollBar( Orientation orientation, TQWidget *parent, - const char *name ) - : TQWidget( parent, name ), orient( orientation ) -{ - init(); -} - -/*! - Constructs a scroll bar whose value can never be smaller than \a - minValue or greater than \a maxValue, whose line step size is \a - lineStep and page step size is \a pageStep and whose value is - initially \a value (which is guaranteed to be in range using - bound()). - - If \a orientation is \c Vertical the scroll bar is vertical and if - it is \c Horizontal the scroll bar is horizontal. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. -*/ - -TQScrollBar::TQScrollBar( int minValue, int maxValue, int lineStep, int pageStep, - int value, Orientation orientation, - TQWidget *parent, const char *name ) - : TQWidget( parent, name ), - TQRangeControl( minValue, maxValue, lineStep, pageStep, value ), - orient( orientation ) -{ - init(); -} - -/*! - Destructor. -*/ -TQScrollBar::~TQScrollBar() -{ -} - -void TQScrollBar::init() -{ - track = TRUE; - sliderPos = 0; - pressedControl = TQStyle::SC_None; - clickedAt = FALSE; - setFocusPolicy( NoFocus ); - - repeater = 0; - - setBackgroundMode((TQt::BackgroundMode) - style().styleHint(TQStyle::SH_ScrollBar_BackgroundMode)); - - TQSizePolicy sp( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); - if ( orient == Vertical ) - sp.transpose(); - setSizePolicy( sp ); - clearWState( WState_OwnSizePolicy ); -} - - -/*! - \property TQScrollBar::orientation - \brief the orientation of the scroll bar - - The orientation must be \l TQt::Vertical (the default) or \l - TQt::Horizontal. -*/ - -void TQScrollBar::setOrientation( Orientation orientation ) -{ - if ( orientation == orient ) - return; - if ( !testWState( WState_OwnSizePolicy ) ) { - TQSizePolicy sp = sizePolicy(); - sp.transpose(); - setSizePolicy( sp ); - clearWState( WState_OwnSizePolicy ); - } - - orient = orientation; - - positionSliderFromValue(); - update(); - updateGeometry(); -} - -/*! - \property TQScrollBar::tracking - \brief whether scroll bar tracking is enabled - - If tracking is enabled (the default), the scroll bar emits the - valueChanged() signal while the slider is being dragged. If - tracking is disabled, the scroll bar emits the valueChanged() - signal only when the user releases the mouse button after moving - the slider. -*/ - - -/*! - \property TQScrollBar::draggingSlider - \brief whether the user has clicked the mouse on the slider and is currently dragging it -*/ - -bool TQScrollBar::draggingSlider() const -{ - return pressedControl == TQStyle::SC_ScrollBarSlider; -} - - -/*! - Reimplements the virtual function TQWidget::setPalette(). - - Sets the background color to the mid color for Motif style scroll - bars using palette \a p. -*/ - -void TQScrollBar::setPalette( const TQPalette &p ) -{ - TQWidget::setPalette( p ); - setBackgroundMode((TQt::BackgroundMode) - style().styleHint(TQStyle::SH_ScrollBar_BackgroundMode)); -} - - -/*! \reimp */ -TQSize TQScrollBar::sizeHint() const -{ - constPolish(); - int sbextent = style().pixelMetric(TQStyle::PM_ScrollBarExtent, this); - - if ( orient == Horizontal ) { - return TQSize( 30, sbextent ); - } else { - return TQSize( sbextent, 30 ); - } -} - -/*! \fn void TQScrollBar::setSizePolicy( TQSizePolicy::SizeType, TQSizePolicy::SizeType, bool ) - \reimp -*/ - -/*! \reimp */ -void TQScrollBar::setSizePolicy( TQSizePolicy sp ) -{ - //## remove 4.0 - TQWidget::setSizePolicy( sp ); -} - -/*! - \internal - Implements the virtual TQRangeControl function. -*/ - -void TQScrollBar::valueChange() -{ - int tmp = sliderPos; - positionSliderFromValue(); - if ( tmp != sliderPos && isVisible() ) - drawControls(TQStyle::SC_ScrollBarAddPage | - TQStyle::SC_ScrollBarSubPage | - TQStyle::SC_ScrollBarSlider, - pressedControl ); - emit valueChanged(value()); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif -} - -/*! - \internal - Implements the virtual TQRangeControl function. -*/ - -void TQScrollBar::stepChange() -{ - rangeChange(); -} - -/*! - \internal - Implements the virtual TQRangeControl function. -*/ - -void TQScrollBar::rangeChange() -{ - positionSliderFromValue(); - - if ( isVisible() ) - drawControls(TQStyle::SC_ScrollBarAddLine | - TQStyle::SC_ScrollBarSubLine | - TQStyle::SC_ScrollBarAddPage | - TQStyle::SC_ScrollBarSubPage | - TQStyle::SC_ScrollBarFirst | - TQStyle::SC_ScrollBarLast | - TQStyle::SC_ScrollBarSlider, - pressedControl ); -} - - -/*! - Handles timer events for the scroll bar. -*/ - -void TQScrollBar::doAutoRepeat() -{ - bool sendRepeat = clickedAt; -#if !defined( TQT_NO_CURSOR ) && !defined( TQT_NO_STYLE ) - if(sendRepeat && (pressedControl == TQStyle::SC_ScrollBarAddPage || - pressedControl == TQStyle::SC_ScrollBarSubPage) && - style().styleHint(TQStyle::SH_ScrollBar_StopMouseOverSlider, this) && - style().querySubControl(TQStyle::CC_ScrollBar, this, - mapFromGlobal(TQCursor::pos()) ) == TQStyle::SC_ScrollBarSlider) - sendRepeat = FALSE; -#endif - if ( sendRepeat ){ - if ( repeater ) - repeater->changeInterval( repeatTime ); - action( (TQStyle::SubControl) pressedControl ); - TQApplication::syncX(); - } else { - stopAutoRepeat(); - } -} - - -/*! - Starts the auto-repeat logic. Some time after this function is - called, the auto-repeat starts taking effect and from then on - repeats until stopAutoRepeat() is called. -*/ - -void TQScrollBar::startAutoRepeat() -{ - if ( !repeater ) { - repeater = new TQTimer( this, "auto-repeat timer" ); - connect( repeater, TQ_SIGNAL(timeout()), - this, TQ_SLOT(doAutoRepeat()) ); - } - repeater->start( thresholdTime, FALSE ); -} - - -/*! - Stops the auto-repeat logic. -*/ - -void TQScrollBar::stopAutoRepeat() -{ - delete repeater; - repeater = 0; -} - - -/*! - \reimp -*/ -#ifndef TQT_NO_WHEELEVENT -void TQScrollBar::wheelEvent( TQWheelEvent *e ) -{ - static float offset = 0; - static TQScrollBar* offset_owner = 0; - if (offset_owner != this){ - offset_owner = this; - offset = 0; - } - if ( e->orientation() != orient && !rect().contains(e->pos()) ) - return; - e->accept(); - int step = TQMIN( TQApplication::wheelScrollLines()*lineStep(), - pageStep() ); - if ( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) ) - step = pageStep(); - offset += -e->delta()*step/120; - if (TQABS(offset)<1) - return; - setValue( value() + int(offset) ); - offset -= int(offset); -} -#endif - -/*! - \reimp -*/ -void TQScrollBar::keyPressEvent( TQKeyEvent *e ) -{ - // \list - // \i Left/Right move a horizontal scrollbar by one line. - // \i Up/Down move a vertical scrollbar by one line. - // \i PageUp moves up one page. - // \i PageDown moves down one page. - // \i Home moves to the start (minValue()). - // \i End moves to the end (maxValue()). - // \endlist - - // Note that unless you call setFocusPolicy(), the default NoFocus - // will apply and the user will not be able to use the keyboard to - // interact with the scrollbar. - switch ( e->key() ) { - case Key_Left: - if ( orient == Horizontal ) - subtractLine(); - break; - case Key_Right: - if ( orient == Horizontal ) - addLine(); - break; - case Key_Up: - if ( orient == Vertical ) - subtractLine(); - break; - case Key_Down: - if ( orient == Vertical ) - addLine(); - break; - case Key_PageUp: - subtractPage(); - break; - case Key_PageDown: - addPage(); - break; - case Key_Home: - setValue( minValue() ); - break; - case Key_End: - setValue( maxValue() ); - break; - default: - e->ignore(); - break; - } -} - - -/*! - \reimp -*/ -void TQScrollBar::resizeEvent( TQResizeEvent * ) -{ - positionSliderFromValue(); -} - - -/*! - \reimp -*/ -void TQScrollBar::paintEvent( TQPaintEvent * ) -{ - TQPainter p( this ); - drawControls(TQStyle::SC_ScrollBarAddLine | - TQStyle::SC_ScrollBarSubLine | - TQStyle::SC_ScrollBarAddPage | - TQStyle::SC_ScrollBarSubPage | - TQStyle::SC_ScrollBarFirst | - TQStyle::SC_ScrollBarLast | - TQStyle::SC_ScrollBarSlider, - pressedControl, &p ); -} - -static TQCOORD sliderStartPos = 0; - -/*! - \reimp - */ -void TQScrollBar::contextMenuEvent( TQContextMenuEvent *e ) -{ - if(clickedAt) - e->consume(); - else - e->ignore(); -} - -/*! - \reimp -*/ -void TQScrollBar::mousePressEvent( TQMouseEvent *e ) -{ - bool midButtonAbsPos = - style().styleHint(TQStyle::SH_ScrollBar_MiddleClickAbsolutePosition, - this); - - if ( !(e->button() == LeftButton || - (midButtonAbsPos && e->button() == MidButton) ) ) - return; - - if ( maxValue() == minValue() ) // nothing to be done - return; - - if ( e->state() & MouseButtonMask ) // another button was already pressed - return; - - clickedAt = TRUE; - pressedControl = style().querySubControl(TQStyle::CC_ScrollBar, this, e->pos() ); - - if ( (pressedControl == TQStyle::SC_ScrollBarAddPage || - pressedControl == TQStyle::SC_ScrollBarSubPage || - pressedControl == TQStyle::SC_ScrollBarSlider ) && - ((midButtonAbsPos && e->button() == MidButton) || - (style().styleHint(TQStyle::SH_ScrollBar_LeftClickAbsolutePosition) && e->button() == LeftButton)) ) { - - TQRect sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarSlider ), - gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarGroove ); - int sliderMin, sliderMax, sliderLength; - sliderMin = sliderMax = sliderLength = 0; - if (HORIZONTAL) { - sliderMin = gr.x(); - sliderMax = sliderMin + gr.width(); - sliderLength = sr.width(); - } else { - sliderMin = gr.y(); - sliderMax = sliderMin + gr.height(); - sliderLength = sr.height(); - } - - int newSliderPos = (HORIZONTAL ? e->pos().x() : e->pos().y()) - - sliderLength/2; - newSliderPos = TQMIN( newSliderPos, sliderMax - sliderLength ); - newSliderPos = TQMAX( newSliderPos, sliderMin ); - setValue( sliderPosToRangeValue(newSliderPos) ); - sliderPos = newSliderPos; - pressedControl = TQStyle::SC_ScrollBarSlider; - } - - if ( pressedControl == TQStyle::SC_ScrollBarSlider ) { - clickOffset = (TQCOORD)( (HORIZONTAL ? e->pos().x() : e->pos().y()) - - sliderPos ); - slidePrevVal = value(); - sliderStartPos = sliderPos; - drawControls( pressedControl, pressedControl ); - emit sliderPressed(); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ScrollingStart ); -#endif - } else if ( pressedControl != TQStyle::SC_None ) { - drawControls( pressedControl, pressedControl ); - action( (TQStyle::SubControl) pressedControl ); - startAutoRepeat(); - } -} - - -/*! - \reimp -*/ -void TQScrollBar::mouseReleaseEvent( TQMouseEvent *e ) -{ - if ( !clickedAt ) - return; - - if ( e->stateAfter() & MouseButtonMask ) // some other button is still pressed - return; - - TQStyle::SubControl tmp = (TQStyle::SubControl) pressedControl; - clickedAt = FALSE; - stopAutoRepeat(); - mouseMoveEvent( e ); // Might have moved since last mouse move event. - pressedControl = TQStyle::SC_None; - - if (tmp == TQStyle::SC_ScrollBarSlider) { - directSetValue( calculateValueFromSlider() ); - emit sliderReleased(); - if ( value() != prevValue() ) { - emit valueChanged( value() ); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif - } -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ScrollingEnd ); -#endif - } - drawControls( tmp, pressedControl ); - if ( e->button() == MidButton ) - repaint( FALSE ); -} - - -/*! - \reimp -*/ -void TQScrollBar::mouseMoveEvent( TQMouseEvent *e ) -{ - if ( !isVisible() ) { - clickedAt = FALSE; - return; - } - - bool mcab = style().styleHint(TQStyle::SH_ScrollBar_MiddleClickAbsolutePosition, - this); - if ( ! clickedAt || ! (e->state() & LeftButton || - ((e->state() & MidButton) && mcab))) - return; - - int newSliderPos; - if ( pressedControl == TQStyle::SC_ScrollBarSlider ) { - TQRect gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarGroove ), - sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarSlider ); - int sliderMin, sliderMax, sliderLength; - - if (HORIZONTAL) { - sliderLength = sr.width(); - sliderMin = gr.x(); - sliderMax = gr.right() - sliderLength + 1; - } else { - sliderLength = sr.height(); - sliderMin = gr.y(); - sliderMax = gr.bottom() - sliderLength + 1; - } - - TQRect r = rect(); - int m = style().pixelMetric(TQStyle::PM_MaximumDragDistance, this); - if ( m >= 0 ) { - if ( orientation() == Horizontal ) - r.setRect( r.x() - m, r.y() - 2*m, r.width() + 2*m, r.height() + 4*m ); - else - r.setRect( r.x() - 2*m, r.y() - m, r.width() + 4*m, r.height() + 2*m ); - if (! r.contains( e->pos())) - newSliderPos = sliderStartPos; - else - newSliderPos = (HORIZONTAL ? e->pos().x() : - e->pos().y()) -clickOffset; - } else - newSliderPos = (HORIZONTAL ? e->pos().x() : - e->pos().y()) -clickOffset; - - if ( newSliderPos < sliderMin ) - newSliderPos = sliderMin; - else if ( newSliderPos > sliderMax ) - newSliderPos = sliderMax; - int newVal = sliderPosToRangeValue(newSliderPos); - if ( newVal != slidePrevVal ) - emit sliderMoved( newVal ); - if ( track && newVal != value() ) { - directSetValue( newVal ); // Set directly, painting done below - emit valueChanged( value() ); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif - } - slidePrevVal = newVal; - sliderPos = (TQCOORD)newSliderPos; - drawControls( TQStyle::SC_ScrollBarAddPage | - TQStyle::SC_ScrollBarSlider | - TQStyle::SC_ScrollBarSubPage, - pressedControl ); - } else if (! style().styleHint(TQStyle::SH_ScrollBar_ScrollWhenPointerLeavesControl)) { - // stop scrolling when the mouse pointer leaves a control - // similar to push buttons - if ( pressedControl != (uint)style().querySubControl(TQStyle::CC_ScrollBar, this, e->pos() ) ) { - drawControls( pressedControl, TQStyle::SC_None ); - stopAutoRepeat(); - } else if ( !repeater ) { - drawControls( pressedControl, pressedControl ); - action( (TQStyle::SubControl) pressedControl ); - startAutoRepeat(); - } - } -} - - -/*! - \fn int TQScrollBar::sliderStart() const - - Returns the pixel position where the scroll bar slider starts. - - This is equivalent to sliderRect().y() for vertical scroll bars or - sliderRect().x() for horizontal scroll bars. -*/ - -/*! - Returns the scroll bar slider rectangle. - - \sa sliderStart() -*/ - -TQRect TQScrollBar::sliderRect() const -{ - return style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarSlider ); -} - -void TQScrollBar::positionSliderFromValue() -{ - sliderPos = (TQCOORD)rangeValueToSliderPos( value() ); -} - -int TQScrollBar::calculateValueFromSlider() const -{ - return sliderPosToRangeValue( sliderPos ); -} - -int TQScrollBar::rangeValueToSliderPos( int v ) const -{ - TQRect gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarGroove ); - TQRect sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarSlider ); - int sliderMin, sliderMax, sliderLength; - - if (HORIZONTAL) { - sliderLength = sr.width(); - sliderMin = gr.x(); - sliderMax = gr.right() - sliderLength + 1; - } else { - sliderLength = sr.height(); - sliderMin = gr.y(); - sliderMax = gr.bottom() - sliderLength + 1; - } - - return positionFromValue( v, sliderMax-sliderMin ) + sliderMin; -} - -int TQScrollBar::sliderPosToRangeValue( int pos ) const -{ - TQRect gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarGroove ); - TQRect sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, - TQStyle::SC_ScrollBarSlider ); - int sliderMin, sliderMax, sliderLength; - - if (HORIZONTAL) { - sliderLength = sr.width(); - sliderMin = gr.x(); - sliderMax = gr.right() - sliderLength + 1; - } else { - sliderLength = sr.height(); - sliderMin = gr.y(); - sliderMax = gr.bottom() - sliderLength + 1; - } - - return valueFromPosition( pos - sliderMin, sliderMax - sliderMin ); -} - - -void TQScrollBar::action( int control ) -{ - switch( control ) { - case TQStyle::SC_ScrollBarAddLine: - addLine(); - emit nextLine(); - break; - case TQStyle::SC_ScrollBarSubLine: - subtractLine(); - emit prevLine(); - break; - case TQStyle::SC_ScrollBarAddPage: - addPage(); - emit nextPage(); - break; - case TQStyle::SC_ScrollBarSubPage: - subtractPage(); - emit prevPage(); - break; - case TQStyle::SC_ScrollBarFirst: - setValue( minValue() ); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif - emit valueChanged( minValue() ); - break; - case TQStyle::SC_ScrollBarLast: - setValue( maxValue() ); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif - emit valueChanged( maxValue() ); - break; - default: - break; - } -} - - -void TQScrollBar::drawControls( uint controls, uint activeControl ) const -{ - TQPainter p ( this ); - drawControls( controls, activeControl, &p ); -} - - -void TQScrollBar::drawControls( uint controls, uint activeControl, - TQPainter *p ) const -{ - if ( !isUpdatesEnabled() ) - return; - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (hasMouse()) - flags |= TQStyle::Style_MouseOver; - if ( orientation() == Horizontal ) - flags |= TQStyle::Style_Horizontal; - - style().drawComplexControl(TQStyle::CC_ScrollBar, p, this, rect(), colorGroup(), - flags, (TQStyle::SubControl) controls, - (TQStyle::SubControl) activeControl ); -} - -/*! - \reimp -*/ -void TQScrollBar::styleChange( TQStyle& old ) -{ - positionSliderFromValue(); - setBackgroundMode((TQt::BackgroundMode) - style().styleHint(TQStyle::SH_ScrollBar_BackgroundMode)); - TQWidget::styleChange( old ); -} - -/*! - \property TQScrollBar::minValue - \brief the scroll bar's minimum value - - When setting this property, the \l TQScrollBar::maxValue is - adjusted if necessary to ensure that the range remains valid. - - \sa setRange() -*/ -int TQScrollBar::minValue() const -{ - return TQRangeControl::minValue(); -} - -void TQScrollBar::setMinValue( int minVal ) -{ - TQRangeControl::setMinValue( minVal ); -} - -/*! - \property TQScrollBar::maxValue - \brief the scroll bar's maximum value - - When setting this property, the \l TQScrollBar::minValue is - adjusted if necessary to ensure that the range remains valid. - - \sa setRange() -*/ -int TQScrollBar::maxValue() const -{ - return TQRangeControl::maxValue(); -} - -void TQScrollBar::setMaxValue( int maxVal ) -{ - TQRangeControl::setMaxValue( maxVal ); -} - -/*! - \property TQScrollBar::lineStep - \brief the line step - - When setting lineStep, the virtual stepChange() function will be - called if the new line step is different from the previous - setting. - - \sa setSteps() TQRangeControl::pageStep() setRange() -*/ - -int TQScrollBar::lineStep() const -{ - return TQRangeControl::lineStep(); -} - -/*! - \property TQScrollBar::pageStep - \brief the page step - - When setting pageStep, the virtual stepChange() function will be - called if the new page step is different from the previous - setting. - - \sa TQRangeControl::setSteps() setLineStep() setRange() -*/ - -int TQScrollBar::pageStep() const -{ - return TQRangeControl::pageStep(); -} - -void TQScrollBar::setLineStep( int i ) -{ - setSteps( i, pageStep() ); -} - -void TQScrollBar::setPageStep( int i ) -{ - setSteps( lineStep(), i ); -} - -/*! - \property TQScrollBar::value - \brief the scroll bar's value - - \sa TQRangeControl::value() prevValue() -*/ - -int TQScrollBar::value() const -{ - return TQRangeControl::value(); -} - -void TQScrollBar::setValue( int i ) -{ - TQRangeControl::setValue( i ); -} - - -/*! - This function is called when the scrollbar is hidden. -*/ -void TQScrollBar::hideEvent( TQHideEvent* ) -{ - pressedControl = TQStyle::SC_None; - clickedAt = FALSE; -} - - -#undef ADD_LINE_ACTIVE -#undef SUB_LINE_ACTIVE -#endif diff --git a/src/widgets/qscrollview.cpp b/src/widgets/qscrollview.cpp deleted file mode 100644 index 9c3bc060b..000000000 --- a/src/widgets/qscrollview.cpp +++ /dev/null @@ -1,2847 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQScrollView class -** -** Created : 950524 -** -** 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 "tqwidget.h" -#ifndef TQT_NO_SCROLLVIEW -#include "ntqscrollbar.h" -#include "tqobjectlist.h" -#include "tqpainter.h" -#include "tqpixmap.h" -#include "ntqcursor.h" -#include "ntqfocusdata.h" -#include "ntqscrollview.h" -#include "tqptrdict.h" -#include "ntqapplication.h" -#include "tqtimer.h" -#include "tqstyle.h" -#include "ntqlistview.h" -#ifdef TQ_WS_MAC -# include "qt_mac.h" -#endif - -static const int coord_limit = 4000; -static const int autoscroll_margin = 16; -static const int initialScrollTime = 30; -static const int initialScrollAccel = 5; - -struct TQSVChildRec { - TQSVChildRec(TQWidget* c, int xx, int yy) : - child(c), - x(xx), y(yy) - { - } - - void hideOrShow(TQScrollView* sv, TQWidget* clipped_viewport); - void moveTo(TQScrollView* sv, int xx, int yy, TQWidget* clipped_viewport) - { - if ( x != xx || y != yy ) { - x = xx; - y = yy; - hideOrShow(sv,clipped_viewport); - } - } - TQWidget* child; - int x, y; -}; - -void TQSVChildRec::hideOrShow(TQScrollView* sv, TQWidget* clipped_viewport) -{ - if ( clipped_viewport ) { - if ( x+child->width() < sv->contentsX()+clipped_viewport->x() - || x > sv->contentsX()+clipped_viewport->width() - || y+child->height() < sv->contentsY()+clipped_viewport->y() - || y > sv->contentsY()+clipped_viewport->height() ) { - child->move(clipped_viewport->width(), - clipped_viewport->height()); - } else { - child->move(x-sv->contentsX()-clipped_viewport->x(), - y-sv->contentsY()-clipped_viewport->y()); - } - } else { - child->move(x-sv->contentsX(), y-sv->contentsY()); - } -} - -class TQViewportWidget : public TQWidget -{ - TQ_OBJECT - -public: - TQViewportWidget( TQScrollView* parent=0, const char* name=0, WFlags f = 0 ) - : TQWidget( parent, name, f ) {} -}; - -class TQClipperWidget : public TQWidget -{ - TQ_OBJECT - -public: - TQClipperWidget( TQWidget * parent=0, const char * name=0, WFlags f=0 ) - : TQWidget ( parent,name,f) {} -}; - -#include "qscrollview.moc" - -class TQScrollViewData { -public: - TQScrollViewData(TQScrollView* parent, int vpwflags) : - hbar( new TQScrollBar( TQScrollBar::Horizontal, parent, "qt_hbar" ) ), - vbar( new TQScrollBar( TQScrollBar::Vertical, parent, "qt_vbar" ) ), - viewport( new TQViewportWidget( parent, "qt_viewport", vpwflags ) ), - clipped_viewport( 0 ), - flags( vpwflags ), - vx( 0 ), vy( 0 ), vwidth( 1 ), vheight( 1 ), -#ifndef TQT_NO_DRAGANDDROP - autoscroll_timer( parent, "scrollview autoscroll timer" ), - drag_autoscroll( TRUE ), -#endif - scrollbar_timer( parent, "scrollview scrollbar timer" ), - inresize( FALSE ), use_cached_size_hint( TRUE ) - { - l_marg = r_marg = t_marg = b_marg = 0; - viewport->polish(); - viewport->setBackgroundMode( TQWidget::PaletteDark ); - viewport->setBackgroundOrigin( TQWidget::WidgetOrigin ); - vMode = TQScrollView::Auto; - hMode = TQScrollView::Auto; - corner = 0; - defaultCorner = new TQWidget( parent, "qt_default_corner" ); - defaultCorner->hide(); - vbar->setSteps( 20, 1/*set later*/ ); - hbar->setSteps( 20, 1/*set later*/ ); - policy = TQScrollView::Default; - signal_choke = FALSE; - static_bg = FALSE; - fake_scroll = FALSE; - hbarPressed = FALSE; - vbarPressed = FALSE; - } - ~TQScrollViewData(); - - TQSVChildRec* rec(TQWidget* w) { return childDict.find(w); } - TQSVChildRec* ancestorRec(TQWidget* w); - TQSVChildRec* addChildRec(TQWidget* w, int x, int y ) - { - TQSVChildRec *r = new TQSVChildRec(w,x,y); - children.append(r); - childDict.insert(w, r); - return r; - } - void deleteChildRec(TQSVChildRec* r) - { - childDict.remove(r->child); - children.removeRef(r); - delete r; - } - - void hideOrShowAll(TQScrollView* sv, bool isScroll = FALSE ); - void moveAllBy(int dx, int dy); - bool anyVisibleChildren(); - void autoMove(TQScrollView* sv); - void autoResize(TQScrollView* sv); - void autoResizeHint(TQScrollView* sv); - void viewportResized( int w, int h ); - - TQScrollBar* hbar; - TQScrollBar* vbar; - bool hbarPressed; - bool vbarPressed; - TQViewportWidget* viewport; - TQClipperWidget* clipped_viewport; - int flags; - TQPtrList children; - TQPtrDict childDict; - TQWidget* corner, *defaultCorner; - int vx, vy, vwidth, vheight; // for drawContents-style usage - int l_marg, r_marg, t_marg, b_marg; - TQScrollView::ResizePolicy policy; - TQScrollView::ScrollBarMode vMode; - TQScrollView::ScrollBarMode hMode; -#ifndef TQT_NO_DRAGANDDROP - TQPoint cpDragStart; - TQTimer autoscroll_timer; - int autoscroll_time; - int autoscroll_accel; - bool drag_autoscroll; -#endif - TQTimer scrollbar_timer; - - uint static_bg : 1; - uint fake_scroll : 1; - - // This variable allows ensureVisible to move the contents then - // update both the sliders. Otherwise, updating the sliders would - // cause two image scrolls, creating ugly flashing. - // - uint signal_choke : 1; - - // This variables indicates in updateScrollBars() that we are - // in a resizeEvent() and thus don't want to flash scrollbars - uint inresize : 1; - uint use_cached_size_hint : 1; - TQSize cachedSizeHint; - - inline int contentsX() const { return -vx; } - inline int contentsY() const { return -vy; } - inline int contentsWidth() const { return vwidth; } -}; - -inline TQScrollViewData::~TQScrollViewData() -{ - children.setAutoDelete( TRUE ); -} - -TQSVChildRec* TQScrollViewData::ancestorRec(TQWidget* w) -{ - if ( clipped_viewport ) { - while (w->parentWidget() != clipped_viewport) { - w = w->parentWidget(); - if (!w) return 0; - } - } else { - while (w->parentWidget() != viewport) { - w = w->parentWidget(); - if (!w) return 0; - } - } - return rec(w); -} - -void TQScrollViewData::hideOrShowAll(TQScrollView* sv, bool isScroll ) -{ - if ( !clipped_viewport ) - return; - if ( clipped_viewport->x() <= 0 - && clipped_viewport->y() <= 0 - && clipped_viewport->width()+clipped_viewport->x() >= - viewport->width() - && clipped_viewport->height()+clipped_viewport->y() >= - viewport->height() ) { - // clipped_viewport still covers viewport - if( static_bg ) - clipped_viewport->repaint( TRUE ); - else if ( ( !isScroll && !clipped_viewport->testWFlags( TQt::WStaticContents) ) - || static_bg ) - TQApplication::postEvent( clipped_viewport, - new TQPaintEvent( clipped_viewport->clipRegion(), - !clipped_viewport->testWFlags(TQt::WResizeNoErase) ) ); - } else { - // Re-center - int nx = ( viewport->width() - clipped_viewport->width() ) / 2; - int ny = ( viewport->height() - clipped_viewport->height() ) / 2; - clipped_viewport->move(nx,ny); - clipped_viewport->update(); - } - for (TQSVChildRec *r = children.first(); r; r=children.next()) { - r->hideOrShow(sv, clipped_viewport); - } -} - -void TQScrollViewData::moveAllBy(int dx, int dy) -{ - if ( clipped_viewport && !static_bg ) { - clipped_viewport->move( clipped_viewport->x()+dx, - clipped_viewport->y()+dy ); - } else { - for (TQSVChildRec *r = children.first(); r; r=children.next()) { - r->child->move(r->child->x()+dx,r->child->y()+dy); - } - if ( static_bg ) - viewport->repaint( TRUE ); - } -} - -bool TQScrollViewData::anyVisibleChildren() -{ - for (TQSVChildRec *r = children.first(); r; r=children.next()) { - if (r->child->isVisible()) return TRUE; - } - return FALSE; -} - -void TQScrollViewData::autoMove(TQScrollView* sv) -{ - if ( policy == TQScrollView::AutoOne ) { - TQSVChildRec* r = children.first(); - if (r) - sv->setContentsPos(-r->child->x(),-r->child->y()); - } -} - -void TQScrollViewData::autoResize(TQScrollView* sv) -{ - if ( policy == TQScrollView::AutoOne ) { - TQSVChildRec* r = children.first(); - if (r) - sv->resizeContents(r->child->width(),r->child->height()); - } -} - -void TQScrollViewData::autoResizeHint(TQScrollView* sv) -{ - if ( policy == TQScrollView::AutoOne ) { - TQSVChildRec* r = children.first(); - if (r) { - TQSize s = r->child->sizeHint(); - if ( s.isValid() ) - r->child->resize(s); - } - } else if ( policy == TQScrollView::AutoOneFit ) { - TQSVChildRec* r = children.first(); - if (r) { - TQSize sh = r->child->sizeHint(); - sh = sh.boundedTo( r->child->maximumSize() ); - sv->resizeContents( sh.width(), sh.height() ); - } - } -} - -void TQScrollViewData::viewportResized( int w, int h ) -{ - if ( policy == TQScrollView::AutoOneFit ) { - TQSVChildRec* r = children.first(); - if (r) { - TQSize sh = r->child->sizeHint(); - sh = sh.boundedTo( r->child->maximumSize() ); - r->child->resize( TQMAX(w,sh.width()), TQMAX(h,sh.height()) ); - } - - } -} - - -/*! - \class TQScrollView ntqscrollview.h - \brief The TQScrollView widget provides a scrolling area with on-demand scroll bars. - - \ingroup abstractwidgets - \mainclass - - The TQScrollView is a large canvas - potentially larger than the - coordinate system normally supported by the underlying window - system. This is important because it is quite easy to go beyond - these limitations (e.g. many web pages are more than 32000 pixels - high). Additionally, the TQScrollView can have TQWidgets positioned - on it that scroll around with the drawn content. These sub-widgets - can also have positions outside the normal coordinate range (but - they are still limited in size). - - To provide content for the widget, inherit from TQScrollView, - reimplement drawContents() and use resizeContents() to set the - size of the viewed area. Use addChild() and moveChild() to - position widgets on the view. - - To use TQScrollView effectively it is important to understand its - widget structure in the three styles of use: a single large child - widget, a large panning area with some widgets and a large panning - area with many widgets. - - \section1 Using One Big Widget - - \img qscrollview-vp2.png - - The first, simplest usage of TQScrollView (depicted above), is - appropriate for scrolling areas that are never more than about - 4000 pixels in either dimension (this is about the maximum - reliable size on X11 servers). In this usage, you just make one - large child in the TQScrollView. The child should be a child of the - viewport() of the scrollview and be added with addChild(): - \code - TQScrollView* sv = new TQScrollView(...); - TQVBox* big_box = new TQVBox(sv->viewport()); - sv->addChild(big_box); - \endcode - You can go on to add arbitrary child widgets to the single child - in the scrollview as you would with any widget: - \code - TQLabel* child1 = new TQLabel("CHILD", big_box); - TQLabel* child2 = new TQLabel("CHILD", big_box); - TQLabel* child3 = new TQLabel("CHILD", big_box); - ... - \endcode - - Here the TQScrollView has four children: the viewport(), the - verticalScrollBar(), the horizontalScrollBar() and a small - cornerWidget(). The viewport() has one child: the big TQVBox. The - TQVBox has the three TQLabel objects as child widgets. When the view - is scrolled, the TQVBox is moved; its children move with it as - child widgets normally do. - - \section1 Using a Very Big View with Some Widgets - - \img qscrollview-vp.png - - The second usage of TQScrollView (depicted above) is appropriate - when few, if any, widgets are on a very large scrolling area that - is potentially larger than 4000 pixels in either dimension. In - this usage you call resizeContents() to set the size of the area - and reimplement drawContents() to paint the contents. You may also - add some widgets by making them children of the viewport() and - adding them with addChild() (this is the same as the process for - the single large widget in the previous example): - \code - TQScrollView* sv = new TQScrollView(...); - TQLabel* child1 = new TQLabel("CHILD", sv->viewport()); - sv->addChild(child1); - TQLabel* child2 = new TQLabel("CHILD", sv->viewport()); - sv->addChild(child2); - TQLabel* child3 = new TQLabel("CHILD", sv->viewport()); - sv->addChild(child3); - \endcode - Here, the TQScrollView has the same four children: the viewport(), - the verticalScrollBar(), the horizontalScrollBar() and a small - cornerWidget(). The viewport() has the three TQLabel objects as - child widgets. When the view is scrolled, the scrollview moves the - child widgets individually. - - \section1 Using a Very Big View with Many Widgets - - \target enableclipper - \img qscrollview-cl.png - - The final usage of TQScrollView (depicted above) is appropriate - when many widgets are on a very large scrolling area that is - potentially larger than 4000 pixels in either dimension. In this - usage you call resizeContents() to set the size of the area and - reimplement drawContents() to paint the contents. You then call - enableClipper(TRUE) and add widgets, again by making them children - of the viewport(), and adding them with addChild(): - \code - TQScrollView* sv = new TQScrollView(...); - sv->enableClipper(TRUE); - TQLabel* child1 = new TQLabel("CHILD", sv->viewport()); - sv->addChild(child1); - TQLabel* child2 = new TQLabel("CHILD", sv->viewport()); - sv->addChild(child2); - TQLabel* child3 = new TQLabel("CHILD", sv->viewport()); - sv->addChild(child3); - \endcode - - Here, the TQScrollView has four children: the clipper() (not the - viewport() this time), the verticalScrollBar(), the - horizontalScrollBar() and a small cornerWidget(). The clipper() - has one child: the viewport(). The viewport() has the same three - labels as child widgets. When the view is scrolled the viewport() - is moved; its children move with it as child widgets normally do. - - \target allviews - \section1 Details Relevant for All Views - - Normally you will use the first or third method if you want any - child widgets in the view. - - Note that the widget you see in the scrolled area is the - viewport() widget, not the TQScrollView itself. So to turn mouse - tracking on, for example, use viewport()->setMouseTracking(TRUE). - - To enable drag-and-drop, you would setAcceptDrops(TRUE) on the - TQScrollView (because drag-and-drop events propagate to the - parent). But to work out the logical position in the view, you - would need to map the drop co-ordinate from being relative to the - TQScrollView to being relative to the contents; use the function - viewportToContents() for this. - - To handle mouse events on the scrolling area, subclass scrollview - as you would subclass other widgets, but rather than - reimplementing mousePressEvent(), reimplement - contentsMousePressEvent() instead. The contents specific event - handlers provide translated events in the coordinate system of the - scrollview. If you reimplement mousePressEvent(), you'll get - called only when part of the TQScrollView is clicked: and the only - such part is the "corner" (if you don't set a cornerWidget()) and - the frame; everything else is covered up by the viewport, clipper - or scroll bars. - - When you construct a TQScrollView, some of the widget flags apply - to the viewport() instead of being sent to the TQWidget constructor - for the TQScrollView. This applies to \c WNoAutoErase, \c - WStaticContents, and \c WPaintClever. See \l TQt::WidgetFlags for - documentation about these flags. Here are some examples: - - \list - - \i An image-manipulation widget would use \c - WNoAutoErase|WStaticContents because the widget draws all pixels - itself, and when its size increases, it only needs a paint event - for the new part because the old part remains unchanged. - - \i A scrolling game widget in which the background scrolls as the - characters move might use \c WNoAutoErase (in addition to \c - WStaticContents) so that the window system background does not - flash in and out during scrolling. - - \i A word processing widget might use \c WNoAutoErase and repaint - itself line by line to get a less-flickery resizing. If the widget - is in a mode in which no text justification can take place, it - might use \c WStaticContents too, so that it would only get a - repaint for the newly visible parts. - - \endlist - - Child widgets may be moved using addChild() or moveChild(). Use - childX() and childY() to get the position of a child widget. - - A widget may be placed in the corner between the vertical and - horizontal scrollbars with setCornerWidget(). You can get access - to the scrollbars using horizontalScrollBar() and - verticalScrollBar(), and to the viewport with viewport(). The - scroll view can be scrolled using scrollBy(), ensureVisible(), - setContentsPos() or center(). - - The visible area is given by visibleWidth() and visibleHeight(), - and the contents area by contentsWidth() and contentsHeight(). The - contents may be repainted using one of the repaintContents() or - updateContents() functions. - - Coordinate conversion is provided by contentsToViewport() and - viewportToContents(). - - The contentsMoving() signal is emitted just before the contents - are moved to a new position. - - \warning TQScrollView currently does not erase the background when - resized, i.e. you must always clear the background manually in - scrollview subclasses. This will change in a future version of TQt - and we recommend specifying the WNoAutoErase flag explicitly. - - -*/ - - -/*! - \enum TQScrollView::ResizePolicy - - This enum type is used to control a TQScrollView's reaction to - resize events. - - \value Default the TQScrollView selects one of the other settings - automatically when it has to. In this version of TQt, TQScrollView - changes to \c Manual if you resize the contents with - resizeContents() and to \c AutoOne if a child is added. - - \value Manual the contents stays the size set by resizeContents(). - - \value AutoOne if there is only one child widget the contents stays - the size of that widget. Otherwise the behavior is undefined. - - \value AutoOneFit if there is only one child widget the contents stays - the size of that widget's sizeHint(). If the scrollview is resized - larger than the child's sizeHint(), the child will be resized to - fit. If there is more than one child, the behavior is undefined. - -*/ -//#### The widget will be resized to its sizeHint() when a LayoutHint event -//#### is received - -/*! - Constructs a TQScrollView called \a name with parent \a parent and - widget flags \a f. - - The widget flags \c WStaticContents, \c WNoAutoErase and \c - WPaintClever are propagated to the viewport() widget. The other - widget flags are propagated to the parent constructor as usual. -*/ - -TQScrollView::TQScrollView( TQWidget *parent, const char *name, WFlags f ) : - TQFrame( parent, name, f & (~WStaticContents) & (~WResizeNoErase) ) -{ - WFlags flags = WResizeNoErase | (f&WPaintClever) | (f&WRepaintNoErase) | (f&WStaticContents); - d = new TQScrollViewData( this, flags ); - -#ifndef TQT_NO_DRAGANDDROP - connect( &d->autoscroll_timer, TQ_SIGNAL( timeout() ), - this, TQ_SLOT( doDragAutoScroll() ) ); -#endif - - connect( d->hbar, TQ_SIGNAL( valueChanged(int) ), - this, TQ_SLOT( hslide(int) ) ); - connect( d->vbar, TQ_SIGNAL( valueChanged(int) ), - this, TQ_SLOT( vslide(int) ) ); - - connect( d->hbar, TQ_SIGNAL(sliderPressed()), this, TQ_SLOT(hbarIsPressed()) ); - connect( d->hbar, TQ_SIGNAL(sliderReleased()), this, TQ_SLOT(hbarIsReleased()) ); - connect( d->vbar, TQ_SIGNAL(sliderPressed()), this, TQ_SLOT(vbarIsPressed()) ); - connect( d->vbar, TQ_SIGNAL(sliderReleased()), this, TQ_SLOT(vbarIsReleased()) ); - - - d->viewport->installEventFilter( this ); - - connect( &d->scrollbar_timer, TQ_SIGNAL( timeout() ), - this, TQ_SLOT( updateScrollBars() ) ); - - setFrameStyle( TQFrame::StyledPanel | TQFrame::Sunken ); - setLineWidth( style().pixelMetric(TQStyle::PM_DefaultFrameWidth, this) ); - setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) ); -} - - -/*! - Destroys the TQScrollView. Any children added with addChild() will - be deleted. -*/ -TQScrollView::~TQScrollView() -{ - // Be careful not to get all those useless events... - if ( d->clipped_viewport ) - d->clipped_viewport->removeEventFilter( this ); - else - d->viewport->removeEventFilter( this ); - - // order is important - // ~TQWidget may cause a WM_ERASEBKGND on Windows - delete d->vbar; - d->vbar = 0; - delete d->hbar; - d->hbar = 0; - delete d->viewport; - d->viewport = 0; - delete d; - d = 0; -} - -/*! - \fn void TQScrollView::horizontalSliderPressed() - - This signal is emitted whenever the user presses the horizontal slider. -*/ -/*! - \fn void TQScrollView::horizontalSliderReleased() - - This signal is emitted whenever the user releases the horizontal slider. -*/ -/*! - \fn void TQScrollView::verticalSliderPressed() - - This signal is emitted whenever the user presses the vertical slider. -*/ -/*! - \fn void TQScrollView::verticalSliderReleased() - - This signal is emitted whenever the user releases the vertical slider. -*/ -void TQScrollView::hbarIsPressed() -{ - d->hbarPressed = TRUE; - emit( horizontalSliderPressed() ); -} - -void TQScrollView::hbarIsReleased() -{ - d->hbarPressed = FALSE; - emit( horizontalSliderReleased() ); -} - -/*! - Returns TRUE if horizontal slider is pressed by user; otherwise returns FALSE. -*/ -bool TQScrollView::isHorizontalSliderPressed() -{ - return d->hbarPressed; -} - -void TQScrollView::vbarIsPressed() -{ - d->vbarPressed = TRUE; - emit( verticalSliderPressed() ); -} - -void TQScrollView::vbarIsReleased() -{ - d->vbarPressed = FALSE; - emit( verticalSliderReleased() ); -} - -/*! - Returns TRUE if vertical slider is pressed by user; otherwise returns FALSE. -*/ -bool TQScrollView::isVerticalSliderPressed() -{ - return d->vbarPressed; -} - -/*! - \reimp -*/ -void TQScrollView::styleChange( TQStyle& old ) -{ - TQWidget::styleChange( old ); - updateScrollBars(); - d->cachedSizeHint = TQSize(); -} - -/*! - \reimp -*/ -void TQScrollView::fontChange( const TQFont &old ) -{ - TQWidget::fontChange( old ); - updateScrollBars(); - d->cachedSizeHint = TQSize(); -} - -void TQScrollView::hslide( int pos ) -{ - if ( !d->signal_choke ) { - moveContents( -pos, -d->contentsY() ); - TQApplication::syncX(); - } -} - -void TQScrollView::vslide( int pos ) -{ - if ( !d->signal_choke ) { - moveContents( -d->contentsX(), -pos ); - TQApplication::syncX(); - } -} - -/*! - Called when the horizontal scroll bar geometry changes. This is - provided as a protected function so that subclasses can do - interesting things such as providing extra buttons in some of the - space normally used by the scroll bars. - - The default implementation simply gives all the space to \a hbar. - The new geometry is given by \a x, \a y, \a w and \a h. - - \sa setVBarGeometry() -*/ -void TQScrollView::setHBarGeometry(TQScrollBar& hbar, - int x, int y, int w, int h) -{ - hbar.setGeometry( x, y, w, h ); -} - -/*! - Called when the vertical scroll bar geometry changes. This is - provided as a protected function so that subclasses can do - interesting things such as providing extra buttons in some of the - space normally used by the scroll bars. - - The default implementation simply gives all the space to \a vbar. - The new geometry is given by \a x, \a y, \a w and \a h. - - \sa setHBarGeometry() -*/ -void TQScrollView::setVBarGeometry( TQScrollBar& vbar, - int x, int y, int w, int h) -{ - vbar.setGeometry( x, y, w, h ); -} - - -/*! - Returns the viewport size for size (\a x, \a y). - - The viewport size depends on \a (x, y) (the size of the contents), - the size of this widget and the modes of the horizontal and - vertical scroll bars. - - This function permits widgets that can trade vertical and - horizontal space for each other to control scroll bar appearance - better. For example, a word processor or web browser can control - the width of the right margin accurately, whether or not there - needs to be a vertical scroll bar. -*/ - -TQSize TQScrollView::viewportSize( int x, int y ) const -{ - int fw = frameWidth(); - int lmarg = fw+d->l_marg; - int rmarg = fw+d->r_marg; - int tmarg = fw+d->t_marg; - int bmarg = fw+d->b_marg; - - int w = width(); - int h = height(); - - bool needh, needv; - bool showh, showv; - int hsbExt = horizontalScrollBar()->sizeHint().height(); - int vsbExt = verticalScrollBar()->sizeHint().width(); - - if ( d->policy != AutoOne || d->anyVisibleChildren() ) { - // Do we definitely need the scrollbar? - needh = w-lmarg-rmarg < x; - needv = h-tmarg-bmarg < y; - - // Do we intend to show the scrollbar? - if (d->hMode == AlwaysOn) - showh = TRUE; - else if (d->hMode == AlwaysOff) - showh = FALSE; - else - showh = needh; - - if (d->vMode == AlwaysOn) - showv = TRUE; - else if (d->vMode == AlwaysOff) - showv = FALSE; - else - showv = needv; - - // Given other scrollbar will be shown, NOW do we need one? - if ( showh && h-vsbExt-tmarg-bmarg < y ) { - if (d->vMode == Auto) - showv=TRUE; - } - if ( showv && w-hsbExt-lmarg-rmarg < x ) { - if (d->hMode == Auto) - showh=TRUE; - } - } else { - // Scrollbars not needed, only show scrollbar that are always on. - showh = d->hMode == AlwaysOn; - showv = d->vMode == AlwaysOn; - } - - return TQSize( w-lmarg-rmarg - (showv ? vsbExt : 0), - h-tmarg-bmarg - (showh ? hsbExt : 0) ); -} - - -/*! - Updates scroll bars: all possibilities are considered. You should - never need to call this in your code. -*/ -void TQScrollView::updateScrollBars() -{ - if(!horizontalScrollBar() && !verticalScrollBar()) - return; - - // I support this should use viewportSize()... but it needs - // so many of the temporary variables from viewportSize. hm. - int fw = frameWidth(); - int lmarg = fw+d->l_marg; - int rmarg = fw+d->r_marg; - int tmarg = fw+d->t_marg; - int bmarg = fw+d->b_marg; - - int w = width(); - int h = height(); - - int portw, porth; - - bool needh; - bool needv; - bool showh; - bool showv; - bool showc = FALSE; - - int hsbExt = horizontalScrollBar()->sizeHint().height(); - int vsbExt = verticalScrollBar()->sizeHint().width(); - - TQSize oldVisibleSize( visibleWidth(), visibleHeight() ); - - if ( d->policy != AutoOne || d->anyVisibleChildren() ) { - // Do we definitely need the scrollbar? - needh = w-lmarg-rmarg < d->contentsWidth(); - if ( d->inresize ) - needh = !horizontalScrollBar()->isHidden(); - needv = h-tmarg-bmarg < contentsHeight(); - - // Do we intend to show the scrollbar? - if (d->hMode == AlwaysOn) - showh = TRUE; - else if (d->hMode == AlwaysOff) - showh = FALSE; - else - showh = needh; - - if (d->vMode == AlwaysOn) - showv = TRUE; - else if (d->vMode == AlwaysOff) - showv = FALSE; - else - showv = needv; - -#ifdef TQ_WS_MAC - bool mac_need_scroll = FALSE; - if(!parentWidget()) { - mac_need_scroll = TRUE; - } else { - TQWidget *tlw = topLevelWidget(); - TQPoint tlw_br = TQPoint(tlw->width(), tlw->height()), - my_br = posInWindow(this) + TQPoint(w, h); - if(my_br.x() >= tlw_br.x() - 3 && my_br.y() >= tlw_br.y() - 3) - mac_need_scroll = TRUE; - } - if(mac_need_scroll) { - WindowAttributes attr; - GetWindowAttributes((WindowPtr)handle(), &attr); - mac_need_scroll = (attr & kWindowResizableAttribute); - } - if(mac_need_scroll) { - showc = TRUE; - if(d->vMode == Auto) - showv = TRUE; - if(d->hMode == Auto) - showh = TRUE; - } -#endif - - // Given other scrollbar will be shown, NOW do we need one? - if ( showh && h-vsbExt-tmarg-bmarg < contentsHeight() ) { - needv=TRUE; - if (d->vMode == Auto) - showv=TRUE; - } - if ( showv && !d->inresize && w-hsbExt-lmarg-rmarg < d->contentsWidth() ) { - needh=TRUE; - if (d->hMode == Auto) - showh=TRUE; - } - } else { - // Scrollbars not needed, only show scrollbar that are always on. - needh = needv = FALSE; - showh = d->hMode == AlwaysOn; - showv = d->vMode == AlwaysOn; - } - - bool sc = d->signal_choke; - d->signal_choke=TRUE; - - // Hide unneeded scrollbar, calculate viewport size - if ( showh ) { - porth=h-hsbExt-tmarg-bmarg; - } else { - if (!needh) - d->hbar->setValue(0); - d->hbar->hide(); - porth=h-tmarg-bmarg; - } - if ( showv ) { - portw=w-vsbExt-lmarg-rmarg; - } else { - if (!needv) - d->vbar->setValue(0); - d->vbar->hide(); - portw=w-lmarg-rmarg; - } - - // Configure scrollbars that we will show - if ( needv ) { - d->vbar->setRange( 0, contentsHeight()-porth ); - d->vbar->setSteps( TQScrollView::d->vbar->lineStep(), porth ); - } else { - d->vbar->setRange( 0, 0 ); - } - if ( needh ) { - d->hbar->setRange( 0, TQMAX(0, d->contentsWidth()-portw) ); - d->hbar->setSteps( TQScrollView::d->hbar->lineStep(), portw ); - } else { - d->hbar->setRange( 0, 0 ); - } - - // Position the scrollbars, viewport and corner widget. - int bottom; - bool reverse = TQApplication::reverseLayout(); - int xoffset = ( reverse && (showv || cornerWidget() )) ? vsbExt : 0; - int xpos = reverse ? 0 : w - vsbExt; - bool frameContentsOnly = - style().styleHint(TQStyle::SH_ScrollView_FrameOnlyAroundContents); - - if( ! frameContentsOnly ) { - if ( reverse ) - xpos += fw; - else - xpos -= fw; - } - if ( showh ) { - int right = ( showc || showv || cornerWidget() ) ? w-vsbExt : w; - if ( ! frameContentsOnly ) - setHBarGeometry( *d->hbar, fw + xoffset, h-hsbExt-fw, - right-fw-fw, hsbExt ); - else - setHBarGeometry( *d->hbar, 0 + xoffset, h-hsbExt, right, - hsbExt ); - bottom=h-hsbExt; - } else { - bottom=h; - } - if ( showv ) { - clipper()->setGeometry( lmarg + xoffset, tmarg, - w-vsbExt-lmarg-rmarg, - bottom-tmarg-bmarg ); - d->viewportResized( w-vsbExt-lmarg-rmarg, bottom-tmarg-bmarg ); - if ( ! frameContentsOnly ) - changeFrameRect(TQRect(0, 0, w, h) ); - else - changeFrameRect(TQRect(xoffset, 0, w-vsbExt, bottom)); - if (showc || cornerWidget()) { - if ( ! frameContentsOnly ) - setVBarGeometry( *d->vbar, xpos, - fw, vsbExt, - h-hsbExt-fw-fw ); - else - setVBarGeometry( *d->vbar, xpos, 0, - vsbExt, - h-hsbExt ); - } - else { - if ( ! frameContentsOnly ) - setVBarGeometry( *d->vbar, xpos, - fw, vsbExt, - bottom-fw-fw ); - else - setVBarGeometry( *d->vbar, xpos, 0, - vsbExt, bottom ); - } - } else { - if ( ! frameContentsOnly ) - changeFrameRect(TQRect(0, 0, w, h)); - else - changeFrameRect(TQRect(0, 0, w, bottom)); - clipper()->setGeometry( lmarg, tmarg, - w-lmarg-rmarg, bottom-tmarg-bmarg ); - d->viewportResized( w-lmarg-rmarg, bottom-tmarg-bmarg ); - } - - TQWidget *corner = d->corner; - if ( !d->corner ) - corner = d->defaultCorner; - if ( ! frameContentsOnly ) - corner->setGeometry( xpos, - h-hsbExt-fw, - vsbExt, - hsbExt ); - else - corner->setGeometry( xpos, - h-hsbExt, - vsbExt, - hsbExt ); - - d->signal_choke=sc; - - if ( d->contentsX()+visibleWidth() > d->contentsWidth() ) { - int x; -#if 0 - if ( reverse ) - x =TQMIN(0,d->contentsWidth()-visibleWidth()); - else -#endif - x =TQMAX(0,d->contentsWidth()-visibleWidth()); - d->hbar->setValue(x); - // Do it even if it is recursive - moveContents( -x, -d->contentsY() ); - } - if ( d->contentsY()+visibleHeight() > contentsHeight() ) { - int y=TQMAX(0,contentsHeight()-visibleHeight()); - d->vbar->setValue(y); - // Do it even if it is recursive - moveContents( -d->contentsX(), -y ); - } - - // Finally, show the scroll bars - if ( showh && ( d->hbar->isHidden() || !d->hbar->isVisible() ) ) - d->hbar->show(); - if ( showv && ( d->vbar->isHidden() || !d->vbar->isVisible() ) ) - d->vbar->show(); - - d->signal_choke=TRUE; - d->vbar->setValue( d->contentsY() ); - d->hbar->setValue( d->contentsX() ); - d->signal_choke=FALSE; - - TQSize newVisibleSize( visibleWidth(), visibleHeight() ); - if ( d->clipped_viewport && oldVisibleSize != newVisibleSize ) { - TQResizeEvent e( newVisibleSize, oldVisibleSize ); - viewportResizeEvent( &e ); - } -} - - -/*! - \reimp -*/ -void TQScrollView::show() -{ - if ( isVisible() ) - return; - TQWidget::show(); - updateScrollBars(); - d->hideOrShowAll(this); -} - -/*! - \reimp - */ -void TQScrollView::resize( int w, int h ) -{ - TQWidget::resize( w, h ); -} - -/*! - \reimp -*/ -void TQScrollView::resize( const TQSize& s ) -{ - resize( s.width(), s.height() ); -} - -/*! - \reimp -*/ -void TQScrollView::resizeEvent( TQResizeEvent* event ) -{ - TQFrame::resizeEvent( event ); - -#if 0 - if ( TQApplication::reverseLayout() ) { - d->fake_scroll = TRUE; - scrollBy( -event->size().width() + event->oldSize().width(), 0 ); - d->fake_scroll = FALSE; - } -#endif - - bool inresize = d->inresize; - d->inresize = TRUE; - updateScrollBars(); - d->inresize = inresize; - d->scrollbar_timer.start( 0, TRUE ); - - d->hideOrShowAll(this); -} - - - -/*! - \reimp -*/ -void TQScrollView::mousePressEvent( TQMouseEvent * e) //#### remove for 4.0 -{ - e->ignore(); -} - -/*! - \reimp -*/ -void TQScrollView::mouseReleaseEvent( TQMouseEvent *e ) //#### remove for 4.0 -{ - e->ignore(); -} - - -/*! - \reimp -*/ -void TQScrollView::mouseDoubleClickEvent( TQMouseEvent *e ) //#### remove for 4.0 -{ - e->ignore(); -} - -/*! - \reimp -*/ -void TQScrollView::mouseMoveEvent( TQMouseEvent *e ) //#### remove for 4.0 -{ - e->ignore(); -} - -/*! - \reimp -*/ -#ifndef TQT_NO_WHEELEVENT -void TQScrollView::wheelEvent( TQWheelEvent *e ) -{ - TQWheelEvent ce( viewport()->mapFromGlobal( e->globalPos() ), - e->globalPos(), e->delta(), e->state(), e->orientation()); - viewportWheelEvent(&ce); - if ( !ce.isAccepted() ) { - if ( e->orientation() == Horizontal && horizontalScrollBar() && horizontalScrollBar()->isEnabled() ) - TQApplication::sendEvent( horizontalScrollBar(), e); - else if (e->orientation() == Vertical && verticalScrollBar() && verticalScrollBar()->isEnabled() ) - TQApplication::sendEvent( verticalScrollBar(), e); - } else { - e->accept(); - } -} -#endif - -/*! - \reimp -*/ -void TQScrollView::contextMenuEvent( TQContextMenuEvent *e ) -{ - if ( e->reason() != TQContextMenuEvent::Keyboard ) { - e->ignore(); - return; - } - - TQContextMenuEvent ce( e->reason(), viewport()->mapFromGlobal( e->globalPos() ), - e->globalPos(), e->state() ); - viewportContextMenuEvent( &ce ); - if ( ce.isAccepted() ) - e->accept(); - else - e->ignore(); -} - -TQScrollView::ScrollBarMode TQScrollView::vScrollBarMode() const -{ - return d->vMode; -} - - -/*! - \enum TQScrollView::ScrollBarMode - - This enum type describes the various modes of TQScrollView's scroll - bars. - - \value Auto TQScrollView shows a scroll bar when the content is - too large to fit and not otherwise. This is the default. - - \value AlwaysOff TQScrollView never shows a scroll bar. - - \value AlwaysOn TQScrollView always shows a scroll bar. - - (The modes for the horizontal and vertical scroll bars are - independent.) -*/ - - -/*! - \property TQScrollView::vScrollBarMode - \brief the mode for the vertical scroll bar - - The default mode is \c TQScrollView::Auto. - - \sa hScrollBarMode -*/ -void TQScrollView::setVScrollBarMode( ScrollBarMode mode ) -{ - if (d->vMode != mode) { - d->vMode = mode; - updateScrollBars(); - } -} - - -/*! - \property TQScrollView::hScrollBarMode - \brief the mode for the horizontal scroll bar - - The default mode is \c TQScrollView::Auto. - - \sa vScrollBarMode -*/ -TQScrollView::ScrollBarMode TQScrollView::hScrollBarMode() const -{ - return d->hMode; -} - -void TQScrollView::setHScrollBarMode( ScrollBarMode mode ) -{ - if (d->hMode != mode) { - d->hMode = mode; - updateScrollBars(); - } -} - - -/*! - Returns the widget in the corner between the two scroll bars. - - By default, no corner widget is present. -*/ -TQWidget* TQScrollView::cornerWidget() const -{ - return d->corner; -} - -/*! - Sets the widget in the \a corner between the two scroll bars. - - You will probably also want to set at least one of the scroll bar - modes to \c AlwaysOn. - - Passing 0 shows no widget in the corner. - - Any previous \a corner widget is hidden. - - You may call setCornerWidget() with the same widget at different - times. - - All widgets set here will be deleted by the TQScrollView when it is - destroyed unless you separately reparent the widget after setting - some other corner widget (or 0). - - Any \e newly set widget should have no current parent. - - By default, no corner widget is present. - - \sa setVScrollBarMode(), setHScrollBarMode() -*/ -void TQScrollView::setCornerWidget(TQWidget* corner) -{ - TQWidget* oldcorner = d->corner; - if (oldcorner != corner) { - if (oldcorner) oldcorner->hide(); - d->corner = corner; - - if ( corner && corner->parentWidget() != this ) { - // #### No clean way to get current WFlags - corner->reparent( this, (((TQScrollView*)corner))->getWFlags(), - TQPoint(0,0), FALSE ); - } - - updateScrollBars(); - if ( corner ) corner->show(); - } -} - - -void TQScrollView::setResizePolicy( ResizePolicy r ) -{ - d->policy = r; -} - -/*! - \property TQScrollView::resizePolicy - \brief the resize policy - - The default is \c Default. - - \sa ResizePolicy -*/ -TQScrollView::ResizePolicy TQScrollView::resizePolicy() const -{ - return d->policy; -} - -/*! - \reimp -*/ -void TQScrollView::setEnabled( bool enable ) -{ - TQFrame::setEnabled( enable ); -} - -/*! - Removes the \a child widget from the scrolled area. Note that this - happens automatically if the \a child is deleted. -*/ -void TQScrollView::removeChild(TQWidget* child) -{ - if ( !d || !child ) // First check in case we are destructing - return; - - TQSVChildRec *r = d->rec(child); - if ( r ) d->deleteChildRec( r ); -} - -/*! - \reimp -*/ -void TQScrollView::removeChild(TQObject* child) -{ - TQFrame::removeChild(child); -} - -/*! - Inserts the widget, \a child, into the scrolled area positioned at - (\a x, \a y). The position defaults to (0, 0). If the child is - already in the view, it is just moved. - - You may want to call enableClipper(TRUE) if you add a large number - of widgets. -*/ -void TQScrollView::addChild(TQWidget* child, int x, int y) -{ - if ( !child ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQScrollView::addChild(): Cannot add null child" ); -#endif - return; - } - child->polish(); - child->setBackgroundOrigin(WidgetOrigin); - - if ( child->parentWidget() == viewport() ) { - // May already be there - TQSVChildRec *r = d->rec(child); - if (r) { - r->moveTo(this,x,y,d->clipped_viewport); - if ( d->policy > Manual ) { - d->autoResizeHint(this); - d->autoResize(this); // #### better to just deal with this one widget! - } - return; - } - } - - if ( d->children.isEmpty() && d->policy != Manual ) { - if ( d->policy == Default ) - setResizePolicy( AutoOne ); - child->installEventFilter( this ); - } else if ( d->policy == AutoOne ) { - child->removeEventFilter( this ); //#### ????? - setResizePolicy( Manual ); - } - if ( child->parentWidget() != viewport() ) { - child->reparent( viewport(), 0, TQPoint(0,0), FALSE ); - } - d->addChildRec(child,x,y)->hideOrShow(this, d->clipped_viewport); - - if ( d->policy > Manual ) { - d->autoResizeHint(this); - d->autoResize(this); // #### better to just deal with this one widget! - } -} - -/*! - Repositions the \a child widget to (\a x, \a y). This function is - the same as addChild(). -*/ -void TQScrollView::moveChild(TQWidget* child, int x, int y) -{ - addChild(child,x,y); -} - -/*! - Returns the X position of the given \a child widget. Use this - rather than TQWidget::x() for widgets added to the view. - - This function returns 0 if \a child has not been added to the view. -*/ -int TQScrollView::childX(TQWidget* child) -{ - TQSVChildRec *r = d->rec(child); - return r ? r->x : 0; -} - -/*! - Returns the Y position of the given \a child widget. Use this - rather than TQWidget::y() for widgets added to the view. - - This function returns 0 if \a child has not been added to the view. -*/ -int TQScrollView::childY(TQWidget* child) -{ - TQSVChildRec *r = d->rec(child); - return r ? r->y : 0; -} - -/*! \fn bool TQScrollView::childIsVisible(TQWidget*) - \obsolete - - Returns TRUE if \a child is visible. This is equivalent - to child->isVisible(). -*/ - -/*! \fn void TQScrollView::showChild(TQWidget* child, bool y) - \obsolete - - Sets the visibility of \a child. Equivalent to - TQWidget::show() or TQWidget::hide(). -*/ - -/*! - This event filter ensures the scroll bars are updated when a - single contents widget is resized, shown, hidden or destroyed; it - passes mouse events to the TQScrollView. The event is in \a e and - the object is in \a obj. -*/ - -bool TQScrollView::eventFilter( TQObject *obj, TQEvent *e ) -{ - if ( !d ) - return FALSE; // we are destructing - if ( obj == d->viewport || obj == d->clipped_viewport ) { - switch ( e->type() ) { - /* Forward many events to viewport...() functions */ - case TQEvent::Paint: - viewportPaintEvent( (TQPaintEvent*)e ); - break; - case TQEvent::Resize: - if ( !d->clipped_viewport ) - viewportResizeEvent( (TQResizeEvent *)e ); - break; - case TQEvent::MouseButtonPress: - viewportMousePressEvent( (TQMouseEvent*)e ); - if ( ((TQMouseEvent*)e)->isAccepted() ) - return TRUE; - break; - case TQEvent::MouseButtonRelease: - viewportMouseReleaseEvent( (TQMouseEvent*)e ); - if ( ((TQMouseEvent*)e)->isAccepted() ) - return TRUE; - break; - case TQEvent::MouseButtonDblClick: - viewportMouseDoubleClickEvent( (TQMouseEvent*)e ); - if ( ((TQMouseEvent*)e)->isAccepted() ) - return TRUE; - break; - case TQEvent::MouseMove: - viewportMouseMoveEvent( (TQMouseEvent*)e ); - if ( ((TQMouseEvent*)e)->isAccepted() ) - return TRUE; - break; -#ifndef TQT_NO_DRAGANDDROP - case TQEvent::DragEnter: - viewportDragEnterEvent( (TQDragEnterEvent*)e ); - break; - case TQEvent::DragMove: { - if ( d->drag_autoscroll ) { - TQPoint vp = ((TQDragMoveEvent*) e)->pos(); - TQRect inside_margin( autoscroll_margin, autoscroll_margin, - visibleWidth() - autoscroll_margin * 2, - visibleHeight() - autoscroll_margin * 2 ); - if ( !inside_margin.contains( vp ) ) { - startDragAutoScroll(); - // Keep sending move events - ( (TQDragMoveEvent*)e )->accept( TQRect(0,0,0,0) ); - } - } - viewportDragMoveEvent( (TQDragMoveEvent*)e ); - } break; - case TQEvent::DragLeave: - stopDragAutoScroll(); - viewportDragLeaveEvent( (TQDragLeaveEvent*)e ); - break; - case TQEvent::Drop: - stopDragAutoScroll(); - viewportDropEvent( (TQDropEvent*)e ); - break; -#endif // TQT_NO_DRAGANDDROP - case TQEvent::ContextMenu: - viewportContextMenuEvent( (TQContextMenuEvent*)e ); - if ( ((TQContextMenuEvent*)e)->isAccepted() ) - return TRUE; - break; - case TQEvent::ChildRemoved: - removeChild((TQWidget*)((TQChildEvent*)e)->child()); - break; - case TQEvent::LayoutHint: - d->autoResizeHint(this); - break; - case TQEvent::WindowActivate: - case TQEvent::WindowDeactivate: - return TRUE; - default: - break; - } - } else if ( d && d->rec((TQWidget*)obj) ) { // must be a child - if ( e->type() == TQEvent::Resize ) - d->autoResize(this); - else if ( e->type() == TQEvent::Move ) - d->autoMove(this); - } - return TQFrame::eventFilter( obj, e ); // always continue with standard event processing -} - -/*! - This event handler is called whenever the TQScrollView receives a - mousePressEvent(): the press position in \a e is translated to be a point - on the contents. -*/ -void TQScrollView::contentsMousePressEvent( TQMouseEvent* e ) -{ - e->ignore(); -} - -/*! - This event handler is called whenever the TQScrollView receives a - mouseReleaseEvent(): the release position in \a e is translated to be a - point on the contents. -*/ -void TQScrollView::contentsMouseReleaseEvent( TQMouseEvent* e ) -{ - e->ignore(); -} - -/*! - This event handler is called whenever the TQScrollView receives a - mouseDoubleClickEvent(): the click position in \a e is translated to be a - point on the contents. - - The default implementation generates a normal mouse press event. -*/ -void TQScrollView::contentsMouseDoubleClickEvent( TQMouseEvent* e ) -{ - contentsMousePressEvent(e); // try mouse press event -} - -/*! - This event handler is called whenever the TQScrollView receives a - mouseMoveEvent(): the mouse position in \a e is translated to be a point - on the contents. -*/ -void TQScrollView::contentsMouseMoveEvent( TQMouseEvent* e ) -{ - e->ignore(); -} - -#ifndef TQT_NO_DRAGANDDROP - -/*! - This event handler is called whenever the TQScrollView receives a - dragEnterEvent(): the drag position is translated to be a point - on the contents. -*/ -void TQScrollView::contentsDragEnterEvent( TQDragEnterEvent * ) -{ -} - -/*! - This event handler is called whenever the TQScrollView receives a - dragMoveEvent(): the drag position is translated to be a point on - the contents. -*/ -void TQScrollView::contentsDragMoveEvent( TQDragMoveEvent * ) -{ -} - -/*! - This event handler is called whenever the TQScrollView receives a - dragLeaveEvent(): the drag position is translated to be a point - on the contents. -*/ -void TQScrollView::contentsDragLeaveEvent( TQDragLeaveEvent * ) -{ -} - -/*! - This event handler is called whenever the TQScrollView receives a - dropEvent(): the drop position is translated to be a point on the - contents. -*/ -void TQScrollView::contentsDropEvent( TQDropEvent * ) -{ -} - -#endif // TQT_NO_DRAGANDDROP - -/*! - This event handler is called whenever the TQScrollView receives a - wheelEvent() in \a{e}: the mouse position is translated to be a - point on the contents. -*/ -#ifndef TQT_NO_WHEELEVENT -void TQScrollView::contentsWheelEvent( TQWheelEvent * e ) -{ - e->ignore(); -} -#endif -/*! - This event handler is called whenever the TQScrollView receives a - contextMenuEvent() in \a{e}: the mouse position is translated to - be a point on the contents. -*/ -void TQScrollView::contentsContextMenuEvent( TQContextMenuEvent *e ) -{ - e->ignore(); -} - -/*! - This is a low-level painting routine that draws the viewport - contents. Reimplement this if drawContents() is too high-level - (for example, if you don't want to open a TQPainter on the - viewport). The paint event is passed in \a pe. -*/ -void TQScrollView::viewportPaintEvent( TQPaintEvent* pe ) -{ - TQWidget* vp = viewport(); - - TQPainter p(vp); - TQRect r = pe->rect(); - - if ( d->clipped_viewport ) { - TQRect rr( - -d->clipped_viewport->x(), -d->clipped_viewport->y(), - d->viewport->width(), d->viewport->height() - ); - r &= rr; - if ( r.isValid() ) { - int ex = r.x() + d->clipped_viewport->x() + d->contentsX(); - int ey = r.y() + d->clipped_viewport->y() + d->contentsY(); - int ew = r.width(); - int eh = r.height(); - drawContentsOffset(&p, - d->contentsX()+d->clipped_viewport->x(), - d->contentsY()+d->clipped_viewport->y(), - ex, ey, ew, eh); - } - } else { - r &= d->viewport->rect(); - int ex = r.x() + d->contentsX(); - int ey = r.y() + d->contentsY(); - int ew = r.width(); - int eh = r.height(); - drawContentsOffset(&p, d->contentsX(), d->contentsY(), ex, ey, ew, eh); - } -} - - -/*! - To provide simple processing of events on the contents, this - function receives all resize events sent to the viewport. - - \sa TQWidget::resizeEvent() -*/ -void TQScrollView::viewportResizeEvent( TQResizeEvent* ) -{ -} - -/*! \internal - - To provide simple processing of events on the contents, this - function receives all mouse press events sent to the viewport, - translates the event and calls contentsMousePressEvent(). - - \sa contentsMousePressEvent(), TQWidget::mousePressEvent() -*/ -void TQScrollView::viewportMousePressEvent( TQMouseEvent* e ) -{ - TQMouseEvent ce(e->type(), viewportToContents(e->pos()), - e->globalPos(), e->button(), e->state()); - contentsMousePressEvent(&ce); - if ( !ce.isAccepted() ) - e->ignore(); -} - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all mouse release events sent to the viewport, translates - the event and calls contentsMouseReleaseEvent(). - - \sa TQWidget::mouseReleaseEvent() -*/ -void TQScrollView::viewportMouseReleaseEvent( TQMouseEvent* e ) -{ - TQMouseEvent ce(e->type(), viewportToContents(e->pos()), - e->globalPos(), e->button(), e->state()); - contentsMouseReleaseEvent(&ce); - if ( !ce.isAccepted() ) - e->ignore(); -} - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all mouse double click events sent to the viewport, - translates the event and calls contentsMouseDoubleClickEvent(). - - \sa TQWidget::mouseDoubleClickEvent() -*/ -void TQScrollView::viewportMouseDoubleClickEvent( TQMouseEvent* e ) -{ - TQMouseEvent ce(e->type(), viewportToContents(e->pos()), - e->globalPos(), e->button(), e->state()); - contentsMouseDoubleClickEvent(&ce); - if ( !ce.isAccepted() ) - e->ignore(); -} - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all mouse move events sent to the viewport, translates the - event and calls contentsMouseMoveEvent(). - - \sa TQWidget::mouseMoveEvent() -*/ -void TQScrollView::viewportMouseMoveEvent( TQMouseEvent* e ) -{ - TQMouseEvent ce(e->type(), viewportToContents(e->pos()), - e->globalPos(), e->button(), e->state()); - contentsMouseMoveEvent(&ce); - if ( !ce.isAccepted() ) - e->ignore(); -} - -#ifndef TQT_NO_DRAGANDDROP - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all drag enter events sent to the viewport, translates the - event and calls contentsDragEnterEvent(). - - \sa TQWidget::dragEnterEvent() -*/ -void TQScrollView::viewportDragEnterEvent( TQDragEnterEvent* e ) -{ - e->setPoint(viewportToContents(e->pos())); - contentsDragEnterEvent(e); - e->setPoint(contentsToViewport(e->pos())); -} - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all drag move events sent to the viewport, translates the - event and calls contentsDragMoveEvent(). - - \sa TQWidget::dragMoveEvent() -*/ -void TQScrollView::viewportDragMoveEvent( TQDragMoveEvent* e ) -{ - e->setPoint(viewportToContents(e->pos())); - contentsDragMoveEvent(e); - e->setPoint(contentsToViewport(e->pos())); -} - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all drag leave events sent to the viewport and calls - contentsDragLeaveEvent(). - - \sa TQWidget::dragLeaveEvent() -*/ -void TQScrollView::viewportDragLeaveEvent( TQDragLeaveEvent* e ) -{ - contentsDragLeaveEvent(e); -} - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all drop events sent to the viewport, translates the event - and calls contentsDropEvent(). - - \sa TQWidget::dropEvent() -*/ -void TQScrollView::viewportDropEvent( TQDropEvent* e ) -{ - e->setPoint(viewportToContents(e->pos())); - contentsDropEvent(e); - e->setPoint(contentsToViewport(e->pos())); -} - -#endif // TQT_NO_DRAGANDDROP - -/*!\internal - - To provide simple processing of events on the contents, this function - receives all wheel events sent to the viewport, translates the - event and calls contentsWheelEvent(). - - \sa TQWidget::wheelEvent() -*/ -#ifndef TQT_NO_WHEELEVENT -void TQScrollView::viewportWheelEvent( TQWheelEvent* e ) -{ - /* - Different than standard mouse events, because wheel events might - be sent to the focus widget if the widget-under-mouse doesn't want - the event itself. - */ - TQWheelEvent ce( viewportToContents(e->pos()), - e->globalPos(), e->delta(), e->state(), e->orientation()); - contentsWheelEvent(&ce); - if ( ce.isAccepted() ) - e->accept(); - else - e->ignore(); -} -#endif - -/*! \internal - - To provide simple processing of events on the contents, this function - receives all context menu events sent to the viewport, translates the - event and calls contentsContextMenuEvent(). -*/ -void TQScrollView::viewportContextMenuEvent( TQContextMenuEvent *e ) -{ - TQContextMenuEvent ce(e->reason(), viewportToContents(e->pos()), e->globalPos(), e->state() ); - contentsContextMenuEvent( &ce ); - if ( ce.isAccepted() ) - e->accept(); - else - e->ignore(); -} - -/*! - Returns the component horizontal scroll bar. It is made available - to allow accelerators, autoscrolling, etc. - - It should not be used for other purposes. - - This function never returns 0. -*/ -TQScrollBar* TQScrollView::horizontalScrollBar() const -{ - return d->hbar; -} - -/*! - Returns the component vertical scroll bar. It is made available to - allow accelerators, autoscrolling, etc. - - It should not be used for other purposes. - - This function never returns 0. -*/ -TQScrollBar* TQScrollView::verticalScrollBar() const { - return d->vbar; -} - - -/*! - Scrolls the content so that the point \a (x, y) is visible with at - least 50-pixel margins (if possible, otherwise centered). -*/ -void TQScrollView::ensureVisible( int x, int y ) -{ - ensureVisible(x, y, 50, 50); -} - -/*! - \overload - - Scrolls the content so that the point \a (x, y) is visible with at - least the \a xmargin and \a ymargin margins (if possible, - otherwise centered). -*/ -void TQScrollView::ensureVisible( int x, int y, int xmargin, int ymargin ) -{ - int pw=visibleWidth(); - int ph=visibleHeight(); - - int cx=-d->contentsX(); - int cy=-d->contentsY(); - int cw=d->contentsWidth(); - int ch=contentsHeight(); - - if ( pw < xmargin*2 ) - xmargin=pw/2; - if ( ph < ymargin*2 ) - ymargin=ph/2; - - if ( cw <= pw ) { - xmargin=0; - cx=0; - } - if ( ch <= ph ) { - ymargin=0; - cy=0; - } - - if ( x < -cx+xmargin ) - cx = -x+xmargin; - else if ( x >= -cx+pw-xmargin ) - cx = -x+pw-xmargin; - - if ( y < -cy+ymargin ) - cy = -y+ymargin; - else if ( y >= -cy+ph-ymargin ) - cy = -y+ph-ymargin; - - if ( cx > 0 ) - cx=0; - else if ( cx < pw-cw && cw>pw ) - cx=pw-cw; - - if ( cy > 0 ) - cy=0; - else if ( cy < ph-ch && ch>ph ) - cy=ph-ch; - - setContentsPos( -cx, -cy ); -} - -/*! - Scrolls the content so that the point \a (x, y) is in the top-left - corner. -*/ -void TQScrollView::setContentsPos( int x, int y ) -{ -#if 0 - // bounds checking... - if ( TQApplication::reverseLayout() ) - if ( x > d->contentsWidth() - visibleWidth() ) x = d->contentsWidth() - visibleWidth(); - else -#endif - if ( x < 0 ) x = 0; - if ( y < 0 ) y = 0; - // Choke signal handling while we update BOTH sliders. - d->signal_choke=TRUE; - moveContents( -x, -y ); - d->vbar->setValue( y ); - d->hbar->setValue( x ); - d->signal_choke=FALSE; -} - -/*! - Scrolls the content by \a dx to the left and \a dy upwards. -*/ -void TQScrollView::scrollBy( int dx, int dy ) -{ - setContentsPos( TQMAX( d->contentsX()+dx, 0 ), TQMAX( d->contentsY()+dy, 0 ) ); -} - -/*! - Scrolls the content so that the point \a (x, y) is in the center - of visible area. -*/ -void TQScrollView::center( int x, int y ) -{ - ensureVisible( x, y, 32000, 32000 ); -} - -/*! - \overload - - Scrolls the content so that the point \a (x, y) is visible with - the \a xmargin and \a ymargin margins (as fractions of visible - the area). - - For example: - \list - \i Margin 0.0 allows (x, y) to be on the edge of the visible area. - \i Margin 0.5 ensures that (x, y) is in middle 50% of the visible area. - \i Margin 1.0 ensures that (x, y) is in the center of the the visible area. - \endlist -*/ -void TQScrollView::center( int x, int y, float xmargin, float ymargin ) -{ - int pw=visibleWidth(); - int ph=visibleHeight(); - ensureVisible( x, y, int( xmargin/2.0*pw+0.5 ), int( ymargin/2.0*ph+0.5 ) ); -} - - -/*! - \fn void TQScrollView::contentsMoving(int x, int y) - - This signal is emitted just before the contents are moved to - position \a (x, y). - - \sa contentsX(), contentsY() -*/ - -/*! - Moves the contents by \a (x, y). -*/ -void TQScrollView::moveContents(int x, int y) -{ - if ( -x+visibleWidth() > d->contentsWidth() ) -#if 0 - if( TQApplication::reverseLayout() ) - x=TQMAX(0,-d->contentsWidth()+visibleWidth()); - else -#endif - x=TQMIN(0,-d->contentsWidth()+visibleWidth()); - if ( -y+visibleHeight() > contentsHeight() ) - y=TQMIN(0,-contentsHeight()+visibleHeight()); - - int dx = x - d->vx; - int dy = y - d->vy; - - if (!dx && !dy) - return; // Nothing to do - - emit contentsMoving( -x, -y ); - - d->vx = x; - d->vy = y; - - if ( d->clipped_viewport || d->static_bg ) { - // Cheap move (usually) - d->moveAllBy(dx,dy); - } else if ( /*dx && dy ||*/ - ( TQABS(dy) * 5 > visibleHeight() * 4 ) || - ( TQABS(dx) * 5 > visibleWidth() * 4 ) - ) - { - // Big move - if ( viewport()->isUpdatesEnabled() ) - viewport()->update(); - d->moveAllBy(dx,dy); - } else if ( !d->fake_scroll || d->contentsWidth() > visibleWidth() ) { - // Small move - clipper()->scroll(dx,dy); - } - d->hideOrShowAll(this, TRUE ); -} - -/*! - \property TQScrollView::contentsX - \brief the X coordinate of the contents that are at the left edge of - the viewport. -*/ -int TQScrollView::contentsX() const -{ - return d->contentsX(); -} - -/*! - \property TQScrollView::contentsY - \brief the Y coordinate of the contents that are at the top edge of - the viewport. -*/ -int TQScrollView::contentsY() const -{ - return d->contentsY(); -} - -/*! - \property TQScrollView::contentsWidth - \brief the width of the contents area -*/ -int TQScrollView::contentsWidth() const -{ - return d->contentsWidth(); -} - -/*! - \property TQScrollView::contentsHeight - \brief the height of the contents area -*/ -int TQScrollView::contentsHeight() const -{ - return d->vheight; -} - -/*! - Sets the size of the contents area to \a w pixels wide and \a h - pixels high and updates the viewport accordingly. -*/ -void TQScrollView::resizeContents( int w, int h ) -{ - int ow = d->vwidth; - int oh = d->vheight; - d->vwidth = w; - d->vheight = h; - - d->scrollbar_timer.start( 0, TRUE ); - - if ( d->children.isEmpty() && d->policy == Default ) - setResizePolicy( Manual ); - - if ( ow > w ) { - // Swap - int t=w; - w=ow; - ow=t; - } - // Refresh area ow..w - if ( ow < visibleWidth() && w >= 0 ) { - if ( ow < 0 ) - ow = 0; - if ( w > visibleWidth() ) - w = visibleWidth(); - clipper()->update( d->contentsX()+ow, 0, w-ow, visibleHeight() ); - } - - if ( oh > h ) { - // Swap - int t=h; - h=oh; - oh=t; - } - // Refresh area oh..h - if ( oh < visibleHeight() && h >= 0 ) { - if ( oh < 0 ) - oh = 0; - if ( h > visibleHeight() ) - h = visibleHeight(); - clipper()->update( 0, d->contentsY()+oh, visibleWidth(), h-oh); - } -} - -/*! - Calls update() on a rectangle defined by \a x, \a y, \a w, \a h, - translated appropriately. If the rectangle is not visible, nothing - is repainted. - - \sa repaintContents() -*/ -void TQScrollView::updateContents( int x, int y, int w, int h ) -{ - if ( testWState(WState_Visible|WState_BlockUpdates) != WState_Visible ) - return; - - TQWidget* vp = viewport(); - - // Translate - x -= d->contentsX(); - y -= d->contentsY(); - - // Clip to TQCOORD space - if ( x < 0 ) { - w += x; - x = 0; - } - if ( y < 0 ) { - h += y; - y = 0; - } - - if ( w < 0 || h < 0 ) - return; - if ( x > visibleWidth() || y > visibleHeight() ) - return; - - if ( w > visibleWidth() ) - w = visibleWidth(); - if ( h > visibleHeight() ) - h = visibleHeight(); - - if ( d->clipped_viewport ) { - // Translate clipper() to viewport() - x -= d->clipped_viewport->x(); - y -= d->clipped_viewport->y(); - } - - vp->update( x, y, w, h ); -} - -/*! - \overload - - Updates the contents in rectangle \a r -*/ -void TQScrollView::updateContents( const TQRect& r ) -{ - updateContents(r.x(), r.y(), r.width(), r.height()); -} - -/*! - \overload -*/ -void TQScrollView::updateContents() -{ - updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() ); -} - -/*! - \overload - - Repaints the contents of rectangle \a r. If \a erase is TRUE the - background is cleared using the background color. -*/ -void TQScrollView::repaintContents( const TQRect& r, bool erase ) -{ - repaintContents(r.x(), r.y(), r.width(), r.height(), erase); -} - - -/*! - \overload - - Repaints the contents. If \a erase is TRUE the background is - cleared using the background color. -*/ -void TQScrollView::repaintContents( bool erase ) -{ - repaintContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight(), erase ); -} - - -/*! - Calls repaint() on a rectangle defined by \a x, \a y, \a w, \a h, - translated appropriately. If the rectangle is not visible, nothing - is repainted. If \a erase is TRUE the background is cleared using - the background color. - - \sa updateContents() -*/ -void TQScrollView::repaintContents( int x, int y, int w, int h, bool erase ) -{ - if ( testWState(WState_Visible|WState_BlockUpdates) != WState_Visible ) - return; - - TQWidget* vp = viewport(); - - // Translate logical to clipper() - x -= d->contentsX(); - y -= d->contentsY(); - - // Clip to TQCOORD space - if ( x < 0 ) { - w += x; - x = 0; - } - if ( y < 0 ) { - h += y; - y = 0; - } - - if ( w < 0 || h < 0 ) - return; - if ( w > visibleWidth() ) - w = visibleWidth(); - if ( h > visibleHeight() ) - h = visibleHeight(); - - if ( d->clipped_viewport ) { - // Translate clipper() to viewport() - x -= d->clipped_viewport->x(); - y -= d->clipped_viewport->y(); - } - - vp->repaint( x, y, w, h, erase ); -} - - -/*! - For backward-compatibility only. It is easier to use - drawContents(TQPainter*,int,int,int,int). - - The default implementation translates the painter appropriately - and calls drawContents(TQPainter*,int,int,int,int). See - drawContents() for an explanation of the parameters \a p, \a - offsetx, \a offsety, \a clipx, \a clipy, \a clipw and \a cliph. -*/ -void TQScrollView::drawContentsOffset(TQPainter* p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph) -{ - p->translate(-offsetx,-offsety); - drawContents(p, clipx, clipy, clipw, cliph); -} - -/*! - \fn void TQScrollView::drawContents(TQPainter* p, int clipx, int clipy, int clipw, int cliph) - - Reimplement this function if you are viewing a drawing area rather - than a widget. - - The function should draw the rectangle (\a clipx, \a clipy, \a - clipw, \a cliph) of the contents using painter \a p. The clip - rectangle is in the scrollview's coordinates. - - For example: - \code - { - // Fill a 40000 by 50000 rectangle at (100000,150000) - - // Calculate the coordinates... - int x1 = 100000, y1 = 150000; - int x2 = x1+40000-1, y2 = y1+50000-1; - - // Clip the coordinates so X/Windows will not have problems... - if (x1 < clipx) x1=clipx; - if (y1 < clipy) y1=clipy; - if (x2 > clipx+clipw-1) x2=clipx+clipw-1; - if (y2 > clipy+cliph-1) y2=clipy+cliph-1; - - // Paint using the small coordinates... - if ( x2 >= x1 && y2 >= y1 ) - p->fillRect(x1, y1, x2-x1+1, y2-y1+1, red); - } - \endcode - - The clip rectangle and translation of the painter \a p is already - set appropriately. -*/ -void TQScrollView::drawContents(TQPainter*, int, int, int, int) -{ -} - - -/*! - \reimp -*/ -void TQScrollView::frameChanged() -{ - // slight ugle-hack - the listview header needs readjusting when - // changing the frame - if (TQListView *lv = ::tqt_cast(this)) - lv->triggerUpdate(); - TQFrame::frameChanged(); - updateScrollBars(); -} - - -/*! - Returns the viewport widget of the scrollview. This is the widget - containing the contents widget or which is the drawing area. -*/ -TQWidget* TQScrollView::viewport() const -{ - if ( d->clipped_viewport ) - return d->clipped_viewport; - return d->viewport; -} - -/*! - Returns the clipper widget. Contents in the scrollview are - ultimately clipped to be inside the clipper widget. - - You should not need to use this function. - - \sa visibleWidth(), visibleHeight() -*/ -TQWidget* TQScrollView::clipper() const -{ - return d->viewport; -} - -/*! - \property TQScrollView::visibleWidth - \brief the horizontal amount of the content that is visible -*/ -int TQScrollView::visibleWidth() const -{ - return clipper()->width(); -} - -/*! - \property TQScrollView::visibleHeight - \brief the vertical amount of the content that is visible -*/ -int TQScrollView::visibleHeight() const -{ - return clipper()->height(); -} - - -void TQScrollView::changeFrameRect(const TQRect& r) -{ - TQRect oldr = frameRect(); - if (oldr != r) { - TQRect cr = contentsRect(); - TQRegion fr( frameRect() ); - fr = fr.subtract( contentsRect() ); - setFrameRect( r ); - if ( isVisible() ) { - cr = cr.intersect( contentsRect() ); - fr = fr.unite( frameRect() ); - fr = fr.subtract( cr ); - if ( !fr.isEmpty() ) - TQApplication::postEvent( this, new TQPaintEvent( fr, FALSE ) ); - } - } -} - - -/*! - Sets the margins around the scrolling area to \a left, \a top, \a - right and \a bottom. This is useful for applications such as - spreadsheets with "locked" rows and columns. The marginal space is - \e inside the frameRect() and is left blank; reimplement - drawFrame() or put widgets in the unused area. - - By default all margins are zero. - - \sa frameChanged() -*/ -void TQScrollView::setMargins(int left, int top, int right, int bottom) -{ - if ( left == d->l_marg && - top == d->t_marg && - right == d->r_marg && - bottom == d->b_marg ) - return; - - d->l_marg = left; - d->t_marg = top; - d->r_marg = right; - d->b_marg = bottom; - updateScrollBars(); -} - - -/*! - Returns the left margin. - - \sa setMargins() -*/ -int TQScrollView::leftMargin() const -{ - return d->l_marg; -} - - -/*! - Returns the top margin. - - \sa setMargins() -*/ -int TQScrollView::topMargin() const -{ - return d->t_marg; -} - - -/*! - Returns the right margin. - - \sa setMargins() -*/ -int TQScrollView::rightMargin() const -{ - return d->r_marg; -} - - -/*! - Returns the bottom margin. - - \sa setMargins() -*/ -int TQScrollView::bottomMargin() const -{ - return d->b_marg; -} - -/*! - \reimp -*/ -bool TQScrollView::focusNextPrevChild( bool next ) -{ - // Makes sure that the new focus widget is on-screen, if - // necessary by scrolling the scroll view. - - // first set things up for the scan - TQFocusData *f = focusData(); - TQWidget *startingPoint = f->home(); - TQWidget *candidate = 0; - TQWidget *w = next ? f->next() : f->prev(); - TQSVChildRec *r; - extern bool tqt_tab_all_widgets; - uint focus_flag = tqt_tab_all_widgets ? TabFocus : StrongFocus; - - // then scan for a possible focus widget candidate - while( !candidate && w != startingPoint ) { - if ( w != startingPoint && - (w->focusPolicy() & focus_flag) == focus_flag - && w->isEnabled() &&!w->focusProxy() && w->isVisible() ) - candidate = w; - w = next ? f->next() : f->prev(); - } - - // if we could not find one, maybe super or parentWidget() can? - if ( !candidate ) - return TQFrame::focusNextPrevChild( next ); - - // we've found one. - r = d->ancestorRec( candidate ); - if ( r && ( r->child == candidate || - candidate->isVisibleTo( r->child ) ) ) { - TQPoint cp = r->child->mapToGlobal(TQPoint(0,0)); - TQPoint cr = candidate->mapToGlobal(TQPoint(0,0)) - cp; - ensureVisible( r->x+cr.x()+candidate->width()/2, - r->y+cr.y()+candidate->height()/2, - candidate->width()/2, - candidate->height()/2 ); - } - - candidate->setFocus(); - return TRUE; -} - - - -/*! - When a large numbers of child widgets are in a scrollview, - especially if they are close together, the scrolling performance - can suffer greatly. If \a y is TRUE the scrollview will use an - extra widget to group child widgets. - - Note that you may only call enableClipper() prior to adding - widgets. - - For a full discussion, see this class's \link #enableclipper - detailed description\endlink. -*/ -void TQScrollView::enableClipper(bool y) -{ - if ( !d->clipped_viewport == !y ) - return; - if ( d->children.count() ) - tqFatal("May only call TQScrollView::enableClipper() before adding widgets"); - if ( y ) { - d->clipped_viewport = new TQClipperWidget(clipper(), "qt_clipped_viewport", d->flags); - d->clipped_viewport->setGeometry(-coord_limit/2,-coord_limit/2, - coord_limit,coord_limit); - d->clipped_viewport->setBackgroundMode( d->viewport->backgroundMode() ); - d->viewport->setBackgroundMode(NoBackground); // no exposures for this - d->viewport->removeEventFilter( this ); - d->clipped_viewport->installEventFilter( this ); - d->clipped_viewport->show(); - } else { - delete d->clipped_viewport; - d->clipped_viewport = 0; - } -} - -/*! - Sets the scrollview to have a static background if \a y is TRUE, - or a scrolling background if \a y is FALSE. By default, the - background is scrolling. - - Be aware that this mode is quite slow, as a full repaint of the - visible area has to be triggered on every contents move. - - \sa hasStaticBackground() -*/ -void TQScrollView::setStaticBackground(bool y) -{ - d->static_bg = y; -} - -/*! - Returns TRUE if TQScrollView uses a static background; otherwise - returns FALSE. - - \sa setStaticBackground() -*/ -bool TQScrollView::hasStaticBackground() const -{ - return d->static_bg; -} - -/*! - \overload - - Returns the point \a p translated to a point on the viewport() - widget. -*/ -TQPoint TQScrollView::contentsToViewport( const TQPoint& p ) const -{ - if ( d->clipped_viewport ) { - return TQPoint( p.x() - d->contentsX() - d->clipped_viewport->x(), - p.y() - d->contentsY() - d->clipped_viewport->y() ); - } else { - return TQPoint( p.x() - d->contentsX(), - p.y() - d->contentsY() ); - } -} - -/*! - \overload - - Returns the point on the viewport \a vp translated to a point in - the contents. -*/ -TQPoint TQScrollView::viewportToContents( const TQPoint& vp ) const -{ - if ( d->clipped_viewport ) { - return TQPoint( vp.x() + d->contentsX() + d->clipped_viewport->x(), - vp.y() + d->contentsY() + d->clipped_viewport->y() ); - } else { - return TQPoint( vp.x() + d->contentsX(), - vp.y() + d->contentsY() ); - } -} - - -/*! - Translates a point (\a x, \a y) in the contents to a point (\a vx, - \a vy) on the viewport() widget. -*/ -void TQScrollView::contentsToViewport( int x, int y, int& vx, int& vy ) const -{ - const TQPoint v = contentsToViewport(TQPoint(x,y)); - vx = v.x(); - vy = v.y(); -} - -/*! - Translates a point (\a vx, \a vy) on the viewport() widget to a - point (\a x, \a y) in the contents. -*/ -void TQScrollView::viewportToContents( int vx, int vy, int& x, int& y ) const -{ - const TQPoint c = viewportToContents(TQPoint(vx,vy)); - x = c.x(); - y = c.y(); -} - -/*! - \reimp -*/ -TQSize TQScrollView::sizeHint() const -{ - if ( d->use_cached_size_hint && d->cachedSizeHint.isValid() ) - return d->cachedSizeHint; - - constPolish(); - int f = 2 * frameWidth(); - int h = fontMetrics().height(); - TQSize sz( f, f ); - if ( d->policy > Manual ) { - TQSVChildRec *r = d->children.first(); - if ( r ) { - TQSize cs = r->child->sizeHint(); - if ( cs.isValid() ) - sz += cs.boundedTo( r->child->maximumSize() ); - else - sz += r->child->size(); - } - } else { - sz += TQSize( d->contentsWidth(), contentsHeight() ); - } - if (d->vMode == AlwaysOn) - sz.setWidth(sz.width() + d->vbar->sizeHint().width()); - if (d->hMode == AlwaysOn) - sz.setHeight(sz.height() + d->hbar->sizeHint().height()); - return sz.expandedTo( TQSize(12 * h, 8 * h) ) - .boundedTo( TQSize(36 * h, 24 * h) ); -} - - -/*! - \reimp -*/ -TQSize TQScrollView::minimumSizeHint() const -{ - int h = fontMetrics().height(); - if ( h < 10 ) - h = 10; - int f = 2 * frameWidth(); - return TQSize( (6 * h) + f, (4 * h) + f ); -} - - -/*! - \reimp - - (Implemented to get rid of a compiler warning.) -*/ -void TQScrollView::drawContents( TQPainter * ) -{ -} - -#ifndef TQT_NO_DRAGANDDROP - -/*! - \internal -*/ -void TQScrollView::startDragAutoScroll() -{ - if ( !d->autoscroll_timer.isActive() ) { - d->autoscroll_time = initialScrollTime; - d->autoscroll_accel = initialScrollAccel; - d->autoscroll_timer.start( d->autoscroll_time ); - } -} - - -/*! - \internal -*/ -void TQScrollView::stopDragAutoScroll() -{ - d->autoscroll_timer.stop(); -} - - -/*! - \internal -*/ -void TQScrollView::doDragAutoScroll() -{ - TQPoint p = d->viewport->mapFromGlobal( TQCursor::pos() ); - - if ( d->autoscroll_accel-- <= 0 && d->autoscroll_time ) { - d->autoscroll_accel = initialScrollAccel; - d->autoscroll_time--; - d->autoscroll_timer.start( d->autoscroll_time ); - } - int l = TQMAX( 1, ( initialScrollTime- d->autoscroll_time ) ); - - int dx = 0, dy = 0; - if ( p.y() < autoscroll_margin ) { - dy = -l; - } else if ( p.y() > visibleHeight() - autoscroll_margin ) { - dy = +l; - } - if ( p.x() < autoscroll_margin ) { - dx = -l; - } else if ( p.x() > visibleWidth() - autoscroll_margin ) { - dx = +l; - } - if ( dx || dy ) { - scrollBy(dx,dy); - } else { - stopDragAutoScroll(); - } -} - - -/*! - \property TQScrollView::dragAutoScroll - \brief whether autoscrolling in drag move events is enabled - - If this property is set to TRUE (the default), the TQScrollView - automatically scrolls the contents in drag move events if the user - moves the cursor close to a border of the view. Of course this - works only if the viewport accepts drops. Specifying FALSE - disables this autoscroll feature. - - \warning Enabling this property might not be enough to - effectively turn on autoscrolling. If you put a custom widget in - the TQScrollView, you might need to call TQDragEvent::ignore() on - the event in the dragEnterEvent() and dragMoveEvent() - reimplementations. -*/ - -void TQScrollView::setDragAutoScroll( bool b ) -{ - d->drag_autoscroll = b; -} - -bool TQScrollView::dragAutoScroll() const -{ - return d->drag_autoscroll; -} - -#endif // TQT_NO_DRAGANDDROP - -/*!\internal - */ -void TQScrollView::setCachedSizeHint( const TQSize &sh ) const -{ - if ( isVisible() && !d->cachedSizeHint.isValid() ) - d->cachedSizeHint = sh; -} - -/*!\internal - */ -void TQScrollView::disableSizeHintCaching() -{ - d->use_cached_size_hint = FALSE; -} - -/*!\internal - */ -TQSize TQScrollView::cachedSizeHint() const -{ - return d->use_cached_size_hint ? d->cachedSizeHint : TQSize(); -} - -#endif // TQT_NO_SCROLLVIEW diff --git a/src/widgets/qslider.cpp b/src/widgets/qslider.cpp deleted file mode 100644 index df7555031..000000000 --- a/src/widgets/qslider.cpp +++ /dev/null @@ -1,924 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQSlider class -** -** Created : 961019 -** -** 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 "ntqslider.h" -#ifndef TQT_NO_SLIDER -#include "tqpainter.h" -#include "ntqdrawutil.h" -#include "tqtimer.h" -#include "tqbitmap.h" -#include "ntqapplication.h" -#include "tqstyle.h" -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif - -static const int thresholdTime = 300; -static const int repeatTime = 100; - -struct TQSliderPrivate -{ - // ### move these to TQSlider in TQt 4.0 - int sliderStartVal; - TQSliderPrivate() : sliderStartVal( 0 ) { } -}; - - -/*! - \class TQSlider - \brief The TQSlider widget provides a vertical or horizontal slider. - - \ingroup basic - \mainclass - - The slider is the classic widget for controlling a bounded value. - It lets the user move a slider along a horizontal or vertical - groove and translates the slider's position into an integer value - within the legal range. - - TQSlider inherits TQRangeControl, which provides the "integer" side - of the slider. setRange() and value() are likely to be used by - practically all slider users; see the \l TQRangeControl - documentation for information about the many other functions that - class provides. - - The main functions offered by the slider itself are tickmark and - orientation control; you can use setTickmarks() to indicate where - you want the tickmarks to be, setTickInterval() to indicate how - many of them you want and setOrientation() to indicate whether the - slider is to be horizontal or vertical. - - A slider accepts focus on Tab and uses the mouse wheel and a - suitable keyboard interface. - - - - \important setRange - - \sa TQScrollBar TQSpinBox - \link guibooks.html#fowler GUI Design Handbook: Slider\endlink -*/ - - -/*! - \enum TQSlider::TickSetting - - This enum specifies where the tickmarks are to be drawn relative - to the slider's groove and the handle the user moves. - - \value NoMarks do not draw any tickmarks. - \value Both draw tickmarks on both sides of the groove. - \value Above draw tickmarks above the (horizontal) slider - \value Below draw tickmarks below the (horizontal) slider - \value Left draw tickmarks to the left of the (vertical) slider - \value Right draw tickmarks to the right of the (vertical) slider -*/ - - -/*! - Constructs a vertical slider. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. -*/ - -TQSlider::TQSlider( TQWidget *parent, const char *name ) - : TQWidget( parent, name ) -{ - orient = Vertical; - init(); -} - -/*! - Constructs a slider. - - The \a orientation must be \l TQt::Vertical or \l TQt::Horizontal. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. -*/ - -TQSlider::TQSlider( Orientation orientation, TQWidget *parent, const char *name ) - : TQWidget( parent, name ) -{ - orient = orientation; - init(); -} - -/*! - Constructs a slider whose value can never be smaller than \a - minValue or greater than \a maxValue, whose page step size is \a - pageStep and whose value is initially \a value (which is - guaranteed to be in range using bound()). - - If \a orientation is \c TQt::Vertical the slider is vertical and if it - is \c TQt::Horizontal the slider is horizontal. - - The \a parent and \a name arguments are sent on to the TQWidget - constructor. -*/ - -TQSlider::TQSlider( int minValue, int maxValue, int pageStep, - int value, Orientation orientation, - TQWidget *parent, const char *name ) - : TQWidget( parent, name ), - TQRangeControl( minValue, maxValue, 1, pageStep, value ) -{ - orient = orientation; - init(); - sliderVal = value; -} - -/*! - Destructor. -*/ -TQSlider::~TQSlider() -{ - delete d; -} - -void TQSlider::init() -{ - d = new TQSliderPrivate; - timer = 0; - sliderPos = 0; - sliderVal = 0; - clickOffset = 0; - state = Idle; - track = TRUE; - ticks = NoMarks; - tickInt = 0; - setFocusPolicy( TabFocus ); - initTicks(); - - TQSizePolicy sp( TQSizePolicy::Expanding, TQSizePolicy::Fixed ); - if ( orient == Vertical ) - sp.transpose(); - setSizePolicy( sp ); - clearWState( WState_OwnSizePolicy ); -} - - -/* - Does what's needed when someone changes the tickmark status. -*/ - -void TQSlider::initTicks() -{ - tickOffset = style().pixelMetric( TQStyle::PM_SliderTickmarkOffset, this ); -} - - -/*! - \property TQSlider::tracking - \brief whether slider tracking is enabled - - If tracking is enabled (the default), the slider emits the - valueChanged() signal whenever the slider is being dragged. If - tracking is disabled, the slider emits the valueChanged() signal - when the user releases the mouse button (unless the value happens - to be the same as before). -*/ - -void TQSlider::setTracking( bool enable ) -{ - track = enable; -} - - -/*! - \fn void TQSlider::valueChanged( int value ) - - This signal is emitted when the slider value is changed, with the - new slider \a value as its argument. -*/ - -/*! - \fn void TQSlider::sliderPressed() - - This signal is emitted when the user presses the slider with the - mouse. -*/ - -/*! - \fn void TQSlider::sliderMoved( int value ) - - This signal is emitted when the slider is dragged, with the new - slider \a value as its argument. -*/ - -/*! - \fn void TQSlider::sliderReleased() - - This signal is emitted when the user releases the slider with the mouse. -*/ - -/* - Calculates slider position corresponding to value \a v. -*/ - -int TQSlider::positionFromValue( int v ) const -{ - int a = available(); - int x = TQRangeControl::positionFromValue( v, a ); - if ( orient == Horizontal && TQApplication::reverseLayout() ) - x = a - x; - return x; -} - -/* - Returns the available space in which the slider can move. -*/ - -int TQSlider::available() const -{ - return style().pixelMetric( TQStyle::PM_SliderSpaceAvailable, this ); -} - -/* - Calculates a value corresponding to slider position \a p. -*/ - -int TQSlider::valueFromPosition( int p ) const -{ - int a = available(); - int x = TQRangeControl::valueFromPosition( p, a ); - if ( orient == Horizontal && TQApplication::reverseLayout() ) - x = maxValue() + minValue() - x; - return x; -} - -/*! - Implements the virtual TQRangeControl function. -*/ - -void TQSlider::rangeChange() -{ - int newPos = positionFromValue( value() ); - if ( newPos != sliderPos ) { - reallyMoveSlider( newPos ); - } -} - -/*! - Implements the virtual TQRangeControl function. -*/ - -void TQSlider::valueChange() -{ - if ( sliderVal != value() ) { - int newPos = positionFromValue( value() ); - sliderVal = value(); - reallyMoveSlider( newPos ); - } - emit valueChanged(value()); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif -} - - -/*! - \reimp -*/ -void TQSlider::resizeEvent( TQResizeEvent * ) -{ - rangeChange(); - initTicks(); -} - - -/*! - Reimplements the virtual function TQWidget::setPalette(). - - Sets the background color to the mid color for Motif style sliders - using palette \a p. -*/ - -void TQSlider::setPalette( const TQPalette &p ) -{ - TQWidget::setPalette( p ); -} - - - -/*! - \property TQSlider::orientation - \brief the slider's orientation - - The orientation must be \l TQt::Vertical (the default) or \l - TQt::Horizontal. -*/ - -void TQSlider::setOrientation( Orientation orientation ) -{ - if ( orientation == orient ) - return; - - if ( !testWState( WState_OwnSizePolicy ) ) { - TQSizePolicy sp = sizePolicy(); - sp.transpose(); - setSizePolicy( sp ); - clearWState( WState_OwnSizePolicy ); - } - - orient = orientation; - - rangeChange(); - update(); -} - -/*! - \fn int TQSlider::sliderStart() const - - Returns the start position of the slider. -*/ - - -/*! - Returns the slider handle rectangle. (This is the visual marker - that the user can move.) -*/ - -TQRect TQSlider::sliderRect() const -{ - return style().querySubControlMetrics( TQStyle::CC_Slider, this, - TQStyle::SC_SliderHandle ); -} - -/* - Performs the actual moving of the slider. -*/ - -void TQSlider::reallyMoveSlider( int newPos ) -{ - TQRegion oldR(sliderRect()); - sliderPos = newPos; - TQRegion newR(sliderRect()); - - /* just the one repaint if no background */ - if (backgroundMode() == NoBackground) - repaint(newR | oldR, FALSE); - else { - repaint(oldR.subtract(newR)); - repaint(newR, FALSE); - } -} - - -/*! - \reimp -*/ -void TQSlider::paintEvent( TQPaintEvent * ) -{ - TQPainter p( this ); - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (hasMouse()) - flags |= TQStyle::Style_MouseOver; - - TQStyle::SCFlags sub = TQStyle::SC_SliderGroove | TQStyle::SC_SliderHandle; - if ( tickmarks() != NoMarks ) { - sub |= TQStyle::SC_SliderTickmarks; - } - - style().drawComplexControl( TQStyle::CC_Slider, &p, this, rect(), colorGroup(), - flags, sub, state == Dragging ? TQStyle::SC_SliderHandle : TQStyle::SC_None ); -} - - -/*! - \reimp -*/ -void TQSlider::mousePressEvent( TQMouseEvent *e ) -{ - int slideLength = style().pixelMetric( TQStyle::PM_SliderLength, this ); - resetState(); - d->sliderStartVal = sliderVal; - TQRect r = sliderRect(); - - if ( e->button() == RightButton ) - return; - - if ( r.contains( e->pos() ) ) { - state = Dragging; - clickOffset = (TQCOORD)( goodPart( e->pos() ) - sliderPos ); - emit sliderPressed(); - } else if ( e->button() == MidButton ) { - int pos = goodPart( e->pos() ); - moveSlider( pos - slideLength / 2 ); - state = Dragging; - clickOffset = slideLength / 2; - } else if ( ( orient == Horizontal && e->pos().x() < r.left() ) //### goodPart - || ( orient == Vertical && e->pos().y() < r.top() ) ) { - if ( orient == Horizontal && TQApplication::reverseLayout() ) { - state = TimingUp; - addPage(); - } else { - state = TimingDown; - subtractPage(); - } - if ( !timer ) - timer = new TQTimer( this ); - connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(repeatTimeout()) ); - timer->start( thresholdTime, TRUE ); - } else if ( ( orient == Horizontal && e->pos().x() > r.right() ) //### goodPart - || ( orient == Vertical && e->pos().y() > r.bottom() ) ) { - if ( orient == Horizontal && TQApplication::reverseLayout() ) { - state = TimingDown; - subtractPage(); - } else { - state = TimingUp; - addPage(); - } - if ( !timer ) - timer = new TQTimer( this ); - connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(repeatTimeout()) ); - timer->start( thresholdTime, TRUE ); - } - update( sliderRect() ); -} - -/*! - \reimp -*/ -void TQSlider::mouseMoveEvent( TQMouseEvent *e ) -{ - if ( state != Dragging ) - return; - - TQRect r = rect(); - int m = style().pixelMetric( TQStyle::PM_MaximumDragDistance, - this ); - if ( m >= 0 ) { - if ( orientation() == Horizontal ) - r.setRect( r.x() - m, r.y() - 2*m/3, - r.width() + 2*m, r.height() + 3*m ); - else - r.setRect( r.x() - 2*m/3, r.y() - m, - r.width() + 3*m, r.height() + 2*m ); - if ( !r.contains( e->pos() ) ) { - moveSlider( positionFromValue(d->sliderStartVal) ); - return; - } - } - - int pos = goodPart( e->pos() ); - moveSlider( pos - clickOffset ); -} - -/*! - \reimp -*/ -#ifndef TQT_NO_WHEELEVENT -void TQSlider::wheelEvent( TQWheelEvent * e ) -{ - if ( e->orientation() != orientation() && !rect().contains(e->pos()) ) - return; - - static float offset = 0; - static TQSlider* offset_owner = 0; - if (offset_owner != this){ - offset_owner = this; - offset = 0; - } - offset += -e->delta()*TQMAX(pageStep(),lineStep())/120; - if (TQABS(offset)<1) - return; - setValue( value() + int(offset) ); - offset -= int(offset); - e->accept(); -} -#endif - -/*! - \reimp -*/ -void TQSlider::mouseReleaseEvent( TQMouseEvent * ) -{ - resetState(); - update( sliderRect() ); -} - -/*! - \reimp -*/ -void TQSlider::focusInEvent( TQFocusEvent * e) -{ - TQWidget::focusInEvent( e ); -} - -/*! - \reimp -*/ -void TQSlider::focusOutEvent( TQFocusEvent * e ) -{ - TQWidget::focusOutEvent( e ); -} - -/*! - Moves the left (or top) edge of the slider to position \a pos. The - slider is actually moved to the step position nearest the given \a - pos. -*/ - -void TQSlider::moveSlider( int pos ) -{ - int a = available(); - int newPos = TQMIN( a, TQMAX( 0, pos ) ); - int newVal = valueFromPosition( newPos ); - if (style().styleHint(TQStyle::SH_Slider_SnapToValue, this)) - newPos = positionFromValue( newVal ); - if ( sliderPos != newPos ) - reallyMoveSlider( newPos ); - if ( sliderVal != newVal ) { - sliderVal = newVal; - emit sliderMoved( sliderVal ); - } - if ( tracking() && sliderVal != value() ) - setValue( sliderVal ); - -} - - -/* - Resets all state information and stops the timer. -*/ - -void TQSlider::resetState() -{ - if ( timer ) { - timer->stop(); - timer->disconnect(); - } - switch ( state ) { - case TimingUp: - case TimingDown: - break; - case Dragging: { - setValue( valueFromPosition( sliderPos ) ); - emit sliderReleased(); - break; - } - case Idle: - break; - default: - tqWarning("TQSlider: (%s) in wrong state", name( "unnamed" ) ); - } - state = Idle; -} - - -/*! - \reimp -*/ -void TQSlider::keyPressEvent( TQKeyEvent *e ) -{ - bool sloppy = bool(style().styleHint(TQStyle::SH_Slider_SloppyKeyEvents, this)); - switch ( e->key() ) { - case Key_Left: - if ( sloppy || orient == Horizontal ) { - if (TQApplication::reverseLayout()) - addLine(); - else - subtractLine(); - } - break; - case Key_Right: - if ( sloppy || orient == Horizontal ) { - if (TQApplication::reverseLayout()) - subtractLine(); - else - addLine(); - } - break; - case Key_Up: - if ( sloppy || orient == Vertical ) - subtractLine(); - break; - case Key_Down: - if ( sloppy || orient == Vertical ) - addLine(); - break; - case Key_Prior: - subtractPage(); - break; - case Key_Next: - addPage(); - break; - case Key_Home: - setValue( minValue() ); - break; - case Key_End: - setValue( maxValue() ); - break; - default: - e->ignore(); - return; - } -} - -void TQSlider::setValue( int value ) -{ - TQRangeControl::setValue( value ); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif -} - - -/*! \reimp -*/ - -void TQSlider::addLine() -{ - TQRangeControl::addLine(); -} - -/*! \reimp -*/ - -void TQSlider::subtractLine() -{ - TQRangeControl::subtractLine(); -} - -/*! - Moves the slider one pageStep() up or right. -*/ - -void TQSlider::addStep() -{ - addPage(); -} - - -/*! - Moves the slider one pageStep() down or left. -*/ - -void TQSlider::subtractStep() -{ - subtractPage(); -} - - -/* - Waits for autorepeat. -*/ - -void TQSlider::repeatTimeout() -{ - Q_ASSERT( timer ); - timer->disconnect(); - if ( state == TimingDown ) - connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(subtractStep()) ); - else if ( state == TimingUp ) - connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(addStep()) ); - timer->start( repeatTime, FALSE ); -} - - -/* - Returns the relevant dimension of \a p. -*/ - -int TQSlider::goodPart( const TQPoint &p ) const -{ - return (orient == Horizontal) ? p.x() : p.y(); -} - -/*! - \reimp -*/ -TQSize TQSlider::sizeHint() const -{ - constPolish(); - const int length = 84, tickSpace = 5; - int thick = style().pixelMetric( TQStyle::PM_SliderThickness, this ); - if ( ticks & Above ) - thick += tickSpace; - if ( ticks & Below ) - thick += tickSpace; - int w = thick, h = length; - if ( orient == Horizontal ) { - w = length; - h = thick; - } - return (style().sizeFromContents(TQStyle::CT_Slider, this, - TQSize(w, h)).expandedTo(TQApplication::globalStrut())); -} - - - -/*! - \reimp -*/ - -TQSize TQSlider::minimumSizeHint() const -{ - TQSize s = sizeHint(); - int length = style().pixelMetric(TQStyle::PM_SliderLength, this); - if ( orient == Horizontal ) - s.setWidth( length ); - else - s.setHeight( length ); - - return s; -} - -/*! \fn void TQSlider::setSizePolicy( TQSizePolicy::SizeType, TQSizePolicy::SizeType, bool ) - \reimp -*/ - -/*! \reimp */ -void TQSlider::setSizePolicy( TQSizePolicy sp ) -{ - // ## remove 4.0 - TQWidget::setSizePolicy( sp ); -} - -/*! \reimp */ -TQSizePolicy TQSlider::sizePolicy() const -{ - // ### 4.0 remove this reimplementation - return TQWidget::sizePolicy(); -} - -/*! - \property TQSlider::tickmarks - \brief the tickmark settings for this slider - - The valid values are in \l{TQSlider::TickSetting}. The default is - \c NoMarks. - - \sa tickInterval -*/ - -void TQSlider::setTickmarks( TickSetting s ) -{ - ticks = s; - initTicks(); - update(); -} - - -/*! - \property TQSlider::tickInterval - \brief the interval between tickmarks - - This is a value interval, not a pixel interval. If it is 0, the - slider will choose between lineStep() and pageStep(). The initial - value of tickInterval is 0. - - \sa TQRangeControl::lineStep(), TQRangeControl::pageStep() -*/ - -void TQSlider::setTickInterval( int i ) -{ - tickInt = TQMAX( 0, i ); - update(); -} - - -/*! - \reimp -*/ -void TQSlider::styleChange( TQStyle& old ) -{ - TQWidget::styleChange( old ); -} - -/*! - \property TQSlider::minValue - \brief the current minimum value of the slider - - When setting this property, the \l TQSlider::maxValue is adjusted, - if necessary, to ensure that the range remains valid. - - \sa setRange() -*/ -int TQSlider::minValue() const -{ - return TQRangeControl::minValue(); -} - -/*! - \property TQSlider::maxValue - \brief the current maximum value of the slider - - When setting this property, the \l TQSlider::minValue is adjusted, - if necessary, to ensure that the range remains valid. - - \sa setRange() -*/ -int TQSlider::maxValue() const -{ - return TQRangeControl::maxValue(); -} - -void TQSlider::setMinValue( int minVal ) -{ - TQRangeControl::setMinValue( minVal ); -} - -void TQSlider::setMaxValue( int maxVal ) -{ - TQRangeControl::setMaxValue( maxVal ); -} - -/*! - \property TQSlider::lineStep - \brief the current line step - - When setting lineStep, the virtual stepChange() function will be - called if the new line step is different from the previous - setting. - - \sa setSteps() TQRangeControl::pageStep() setRange() -*/ -int TQSlider::lineStep() const -{ - return TQRangeControl::lineStep(); -} - -/*! - \property TQSlider::pageStep - \brief the current page step - - When setting pageStep, the virtual stepChange() function will be - called if the new page step is different from the previous - setting. - - \sa TQRangeControl::setSteps() setLineStep() setRange() -*/ - -int TQSlider::pageStep() const -{ - return TQRangeControl::pageStep(); -} - -void TQSlider::setLineStep( int i ) -{ - setSteps( i, pageStep() ); -} - -void TQSlider::setPageStep( int i ) -{ - setSteps( lineStep(), i ); -} - -/*! - \property TQSlider::value - \brief the current slider value - - \sa TQRangeControl::value() prevValue() -*/ - -int TQSlider::value() const -{ - return TQRangeControl::value(); -} - -#endif diff --git a/src/widgets/qspinbox.cpp b/src/widgets/qspinbox.cpp deleted file mode 100644 index d6d85beef..000000000 --- a/src/widgets/qspinbox.cpp +++ /dev/null @@ -1,1116 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQSpinBox widget class -** -** Created : 970101 -** -** 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 "ntqspinbox.h" -#ifndef TQT_NO_SPINBOX - -#include "ntqcursor.h" -#include "ntqpushbutton.h" -#include "tqpainter.h" -#include "tqbitmap.h" -#include "ntqlineedit.h" -#include "ntqvalidator.h" -#include "tqpixmapcache.h" -#include "ntqapplication.h" -#include "tqstyle.h" -#if defined(QT_ACCESSIBILITY_SUPPORT) -#include "ntqaccessible.h" -#endif - -static bool sumOutOfRange(int current, int add) -{ - if (add > 0 && INT_MAX - add < current) { - return true; - } - if (add < 0 && INT_MIN - add > current) { - return true; - } - return false; -} - -class TQSpinBoxPrivate -{ -public: - TQSpinBoxPrivate() {} - TQSpinWidget* controls; - uint selreq : 1; -}; - -class TQSpinBoxValidator : public TQIntValidator -{ -public: - TQSpinBoxValidator( TQSpinBox *sb, const char *name ) - : TQIntValidator( sb, name ), spinBox( sb ) { } - - virtual State validate( TQString& str, int& pos ) const; - -private: - TQSpinBox *spinBox; -}; - -TQValidator::State TQSpinBoxValidator::validate( TQString& str, int& pos ) const -{ - TQString pref = spinBox->prefix(); - TQString suff = spinBox->suffix(); - TQString suffStriped = suff.stripWhiteSpace(); - uint overhead = pref.length() + suff.length(); - State state = Invalid; - - ((TQIntValidator *) this)->setRange( spinBox->minValue(), - spinBox->maxValue() ); - if ( overhead == 0 ) { - state = TQIntValidator::validate( str, pos ); - } else { - bool stripedVersion = FALSE; - if ( str.length() >= overhead && str.startsWith(pref) - && (str.endsWith(suff) - || (stripedVersion = str.endsWith(suffStriped))) ) { - if ( stripedVersion ) - overhead = pref.length() + suffStriped.length(); - TQString core = str.mid( pref.length(), str.length() - overhead ); - int corePos = pos - pref.length(); - state = TQIntValidator::validate( core, corePos ); - pos = corePos + pref.length(); - str.replace( pref.length(), str.length() - overhead, core ); - } else { - state = TQIntValidator::validate( str, pos ); - if ( state == Invalid ) { - // stripWhiteSpace(), cf. TQSpinBox::interpretText() - TQString special = spinBox->specialValueText().stripWhiteSpace(); - TQString candidate = str.stripWhiteSpace(); - - if ( special.startsWith(candidate) ) { - if ( candidate.length() == special.length() ) { - state = Acceptable; - } else { - state = Intermediate; - } - } - } - } - } - return state; -} - -/*! - \class TQSpinBox - \brief The TQSpinBox class provides a spin box widget (spin button). - - \ingroup basic - \mainclass - - TQSpinBox allows the user to choose a value either by clicking the - up/down buttons to increase/decrease the value currently displayed - or by typing the value directly into the spin box. If the value is - entered directly into the spin box, Enter (or Return) must be - pressed to apply the new value. The value is usually an integer. - - Every time the value changes TQSpinBox emits the valueChanged() - signal. The current value can be fetched with value() and set - with setValue(). - - The spin box keeps the value within a numeric range, and to - multiples of the lineStep() size (see TQRangeControl for details). - Clicking the up/down buttons or using the keyboard accelerator's - up and down arrows will increase or decrease the current value in - steps of size lineStep(). The minimum and maximum value and the - step size can be set using one of the constructors, and can be - changed later with setMinValue(), setMaxValue() and setLineStep(). - - Most spin boxes are directional, but TQSpinBox can also operate as - a circular spin box, i.e. if the range is 0-99 and the current - value is 99, clicking "up" will give 0. Use setWrapping() if you - want circular behavior. - - The displayed value can be prepended and appended with arbitrary - strings indicating, for example, currency or the unit of - measurement. See setPrefix() and setSuffix(). The text in the spin - box is retrieved with text() (which includes any prefix() and - suffix()), or with cleanText() (which has no prefix(), no suffix() - and no leading or trailing whitespace). currentValueText() returns - the spin box's current value as text. - - Normally the spin box displays up and down arrows in the buttons. - You can use setButtonSymbols() to change the display to show - + and - symbols if you prefer. In either case the up - and down arrow keys work as expected. - - It is often desirable to give the user a special (often default) - choice in addition to the range of numeric values. See - setSpecialValueText() for how to do this with TQSpinBox. - - The default \l TQWidget::focusPolicy() is StrongFocus. - - If using prefix(), suffix() and specialValueText() don't provide - enough control, you can ignore them and subclass TQSpinBox instead. - - TQSpinBox can easily be subclassed to allow the user to input - things other than an integer value as long as the allowed input - can be mapped to a range of integers. This can be done by - overriding the virtual functions mapValueToText() and - mapTextToValue(), and setting another suitable validator using - setValidator(). - - For example, these functions could be changed so that the user - provided values from 0.0 to 10.0, or -1 to signify 'Auto', while - the range of integers used inside the program would be -1 to 100: - - \code - class MySpinBox : public TQSpinBox - { - TQ_OBJECT - public: - ... - - TQString mapValueToText( int value ) - { - if ( value == -1 ) // special case - return TQString( "Auto" ); - - return TQString( "%1.%2" ) // 0.0 to 10.0 - .arg( value / 10 ).arg( value % 10 ); - } - - int mapTextToValue( bool *ok ) - { - if ( text() == "Auto" ) // special case - return -1; - - return (int) ( 10 * text().toFloat() ); // 0 to 100 - } - }; - \endcode - - - - \sa TQScrollBar TQSlider - \link guibooks.html#fowler GUI Design Handbook: Spin Box \endlink -*/ - - -/*! - Constructs a spin box with the default TQRangeControl range and - step values. It is called \a name and has parent \a parent. - - \sa minValue(), maxValue(), setRange(), lineStep(), setSteps() -*/ - -TQSpinBox::TQSpinBox( TQWidget * parent , const char *name ) - : TQWidget( parent, name, WNoAutoErase ), - TQRangeControl() -{ - initSpinBox(); -} - - -/*! - Constructs a spin box that allows values from \a minValue to \a - maxValue inclusive, with step amount \a step. The value is - initially set to \a minValue. - - The spin box is called \a name and has parent \a parent. - - \sa minValue(), maxValue(), setRange(), lineStep(), setSteps() -*/ - -TQSpinBox::TQSpinBox( int minValue, int maxValue, int step, TQWidget* parent, - const char* name ) - : TQWidget( parent, name, WNoAutoErase ), - TQRangeControl( minValue, maxValue, step, step, minValue ) -{ - initSpinBox(); -} - -/* - \internal Initialization. -*/ - -void TQSpinBox::initSpinBox() -{ - d = new TQSpinBoxPrivate; - - d->controls = new TQSpinWidget( this, "controls" ); - connect( d->controls, TQ_SIGNAL( stepUpPressed() ), TQ_SLOT( stepUp() ) ); - connect( d->controls, TQ_SIGNAL( stepDownPressed() ), TQ_SLOT( stepDown() ) ); - - wrap = FALSE; - edited = FALSE; - d->selreq = FALSE; - - validate = new TQSpinBoxValidator( this, "validator" ); - vi = new TQLineEdit( this, "qt_spinbox_edit" ); - d->controls->setEditWidget( vi ); - vi->setValidator( validate ); - vi->installEventFilter( this ); - vi->setFrame( FALSE ); - setFocusProxy( vi ); - - setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); - setBackgroundMode( PaletteBackground, PaletteBase ); - - updateDisplay(); - - connect( vi, TQ_SIGNAL(textChanged(const TQString&)), TQ_SLOT(textChanged()) ); -} - -/*! - Destroys the spin box, freeing all memory and other resources. -*/ - -TQSpinBox::~TQSpinBox() -{ - delete d; -} - - -/*! - \property TQSpinBox::text - \brief the spin box's text, including any prefix() and suffix() - - There is no default text. - - \sa value() -*/ - -TQString TQSpinBox::text() const -{ - return vi->text(); -} - - - -/*! - \property TQSpinBox::cleanText - \brief the spin box's text with no prefix(), suffix() or leading - or trailing whitespace. - - \sa text, prefix, suffix -*/ - -TQString TQSpinBox::cleanText() const -{ - TQString s = TQString(text()).stripWhiteSpace(); - if ( !prefix().isEmpty() ) { - TQString px = TQString(prefix()).stripWhiteSpace(); - int len = px.length(); - if ( len && s.left(len) == px ) // Remove _only_ if it is the prefix - s.remove( (uint)0, len ); - } - if ( !suffix().isEmpty() ) { - TQString sx = TQString(suffix()).stripWhiteSpace(); - int len = sx.length(); - if ( len && s.right(len) == sx ) // Remove _only_ if it is the suffix - s.truncate( s.length() - len ); - } - return s.stripWhiteSpace(); -} - - -/*! - \property TQSpinBox::specialValueText - \brief the special-value text - - If set, the spin box will display this text instead of a numeric - value whenever the current value is equal to minVal(). Typical use - is to indicate that this choice has a special (default) meaning. - - For example, if your spin box allows the user to choose the margin - width in a print dialog and your application is able to - automatically choose a good margin width, you can set up the spin - box like this: - \code - TQSpinBox marginBox( -1, 20, 1, parent, "marginBox" ); - marginBox->setSuffix( " mm" ); - marginBox->setSpecialValueText( "Auto" ); - \endcode - The user will then be able to choose a margin width from 0-20 - millimeters or select "Auto" to leave it to the application to - choose. Your code must then interpret the spin box value of -1 as - the user requesting automatic margin width. - - All values are displayed with the prefix() and suffix() (if set), - \e except for the special value, which only shows the special - value text. - - To turn off the special-value text display, call this function - with an empty string. The default is no special-value text, i.e. - the numeric value is shown as usual. - - If no special-value text is set, specialValueText() returns - TQString::null. -*/ - -void TQSpinBox::setSpecialValueText( const TQString &text ) -{ - specText = text; - updateDisplay(); -} - - -TQString TQSpinBox::specialValueText() const -{ - if ( specText.isEmpty() ) - return TQString::null; - else - return specText; -} - - -/*! - \property TQSpinBox::prefix - \brief the spin box's prefix - - The prefix is prepended to the start of the displayed value. - Typical use is to display a unit of measurement or a currency - symbol. For example: - - \code - sb->setPrefix( "$" ); - \endcode - - To turn off the prefix display, set this property to an empty - string. The default is no prefix. The prefix is not displayed for - the minValue() if specialValueText() is not empty. - - If no prefix is set, prefix() returns TQString::null. - - \sa suffix() -*/ - -void TQSpinBox::setPrefix( const TQString &text ) -{ - pfix = text; - updateDisplay(); -} - - -TQString TQSpinBox::prefix() const -{ - if ( pfix.isEmpty() ) - return TQString::null; - else - return pfix; -} - - -/*! - \property TQSpinBox::suffix - \brief the suffix of the spin box - - The suffix is appended to the end of the displayed value. Typical - use is to display a unit of measurement or a currency symbol. For - example: - - \code - sb->setSuffix( " km" ); - \endcode - - To turn off the suffix display, set this property to an empty - string. The default is no suffix. The suffix is not displayed for - the minValue() if specialValueText() is not empty. - - If no suffix is set, suffix() returns a TQString::null. - - \sa prefix() -*/ - -void TQSpinBox::setSuffix( const TQString &text ) -{ - sfix = text; - updateDisplay(); -} - -TQString TQSpinBox::suffix() const -{ - if ( sfix.isEmpty() ) - return TQString::null; - else - return sfix; -} - - -/*! - \property TQSpinBox::wrapping - \brief whether it is possible to step the value from the highest - value to the lowest value and vice versa - - By default, wrapping is turned off. - - If you have a range of 0..100 and wrapping is off when the user - reaches 100 and presses the Up Arrow nothing will happen; but if - wrapping is on the value will change from 100 to 0, then to 1, - etc. When wrapping is on, navigating past the highest value takes - you to the lowest and vice versa. - - \sa minValue, maxValue, setRange() -*/ - -void TQSpinBox::setWrapping( bool on ) -{ - wrap = on; - updateDisplay(); -} - -bool TQSpinBox::wrapping() const -{ - return wrap; -} - -/*! - \reimp -*/ -TQSize TQSpinBox::sizeHint() const -{ - constPolish(); - TQSize sz = vi->sizeHint(); - int h = sz.height(); - TQFontMetrics fm( font() ); - int w = 35; - int wx = fm.width( ' ' )*2; - TQString s; - s = prefix() + ( (TQSpinBox*)this )->mapValueToText( minValue() ) + suffix(); - w = TQMAX( w, fm.width( s ) + wx); - s = prefix() + ( (TQSpinBox*)this )->mapValueToText( maxValue() ) + suffix(); - w = TQMAX(w, fm.width( s ) + wx ); - if ( !specialValueText().isEmpty() ) { - s = specialValueText(); - w = TQMAX( w, fm.width( s ) + wx ); - } - return style().sizeFromContents(TQStyle::CT_SpinBox, this, - TQSize( w + d->controls->downRect().width(), - h + style().pixelMetric( TQStyle::PM_DefaultFrameWidth ) * 2). - expandedTo( TQApplication::globalStrut() )); -} - - -/*! - \reimp -*/ -TQSize TQSpinBox::minimumSizeHint() const -{ - int w = vi->minimumSizeHint().width() + d->controls->downRect().width(); - int h = TQMAX( vi->minimumSizeHint().height(), d->controls->minimumSizeHint().height() ); - return TQSize( w, h ); -} - -// Does the layout of the lineedit and the buttons - -void TQSpinBox::arrangeWidgets() -{ - d->controls->arrange(); -} - -/*! - \property TQSpinBox::value - \brief the value of the spin box - - \sa TQRangeControl::setValue() -*/ - -void TQSpinBox::setValue( int value ) -{ - edited = FALSE; // we ignore anything entered and not yet interpreted - TQRangeControl::setValue( value ); - updateDisplay(); -} - -int TQSpinBox::value() const -{ - TQSpinBox * that = (TQSpinBox *) this; - if ( edited ) { - that->edited = FALSE; // avoid recursion - that->interpretText(); - } - return TQRangeControl::value(); -} - - -/*! - Increases the spin box's value by one lineStep(), wrapping as - necessary if wrapping() is TRUE. This is the same as clicking on - the pointing-up button and can be used for keyboard accelerators, - for example. - - \sa stepDown(), addLine(), lineStep(), setSteps(), setValue(), value() -*/ - -void TQSpinBox::stepUp() -{ - if ( edited ) - interpretText(); - if ( wrapping() && ( value()+lineStep() > maxValue() || sumOutOfRange(value(), lineStep() ) ) ) { - setValue( minValue() ); - } else { - addLine(); - } -} - - -/*! - Decreases the spin box's value one lineStep(), wrapping as - necessary if wrapping() is TRUE. This is the same as clicking on - the pointing-down button and can be used for keyboard - accelerators, for example. - - \sa stepUp(), subtractLine(), lineStep(), setSteps(), setValue(), value() -*/ - -void TQSpinBox::stepDown() -{ - if ( edited ) - interpretText(); - if ( wrapping() && ( value()-lineStep() < minValue() || sumOutOfRange(value(), -lineStep() ) ) ) { - setValue( maxValue() ); - } else { - subtractLine(); - } -} - - -/*! - \fn void TQSpinBox::valueChanged( int value ) - - This signal is emitted every time the value of the spin box - changes; the new value is passed in \a value. This signal will be - emitted as a result of a call to setValue(), or because the user - changed the value by using a keyboard accelerator or mouse click, - etc. - - Note that the valueChanged() signal is emitted \e every time, not - just for the "last" step; i.e. if the user clicks "up" three - times, this signal is emitted three times. - - \sa value() -*/ - - -/*! - \fn void TQSpinBox::valueChanged( const TQString& valueText ) - - \overload - - This signal is emitted whenever the valueChanged( int ) signal is - emitted, i.e. every time the value of the spin box changes - (whatever the cause, e.g. by setValue(), by a keyboard - accelerator, by mouse clicks, etc.). - - The \a valueText parameter is the same string that is displayed in - the edit field of the spin box. - - \sa value() prefix() suffix() specialValueText() -*/ - - - -/*! - Intercepts and handles the events coming to the embedded TQLineEdit - that have special meaning for the TQSpinBox. The object is passed - as \a o and the event is passed as \a ev. -*/ - -bool TQSpinBox::eventFilter( TQObject* o, TQEvent* ev ) -{ - if (o != vi) - return TQWidget::eventFilter(o,ev); - - if ( ev->type() == TQEvent::KeyPress ) { - TQKeyEvent* k = (TQKeyEvent*)ev; - - bool retval = FALSE; // workaround for MSVC++ optimization bug - if( (k->key() == Key_Tab) || (k->key() == Key_BackTab) ){ - if ( k->state() & TQt::ControlButton ) - return FALSE; - if ( edited ) - interpretText(); - tqApp->sendEvent( this, ev ); - retval = TRUE; - } if ( k->key() == Key_Up ) { - stepUp(); - retval = TRUE; - } else if ( k->key() == Key_Down ) { - stepDown(); - retval = TRUE; - } else if ( k->key() == Key_Enter || k->key() == Key_Return ) { - interpretText(); - return FALSE; - } - if ( retval ) - return retval; - } else if ( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Hide ) { - if ( edited ) { - interpretText(); - } - return FALSE; - } - return FALSE; -} - -/*! - \reimp - */ -void TQSpinBox::setEnabled( bool enabled ) -{ - TQWidget::setEnabled( enabled ); - updateDisplay(); -} - -/*! - \reimp -*/ -void TQSpinBox::leaveEvent( TQEvent* ) -{ -} - - -/*! - \reimp -*/ -void TQSpinBox::resizeEvent( TQResizeEvent* ) -{ - d->controls->resize( width(), height() ); -} - -/*! - \reimp -*/ -#ifndef TQT_NO_WHEELEVENT -void TQSpinBox::wheelEvent( TQWheelEvent * e ) -{ - e->accept(); - static float offset = 0; - static TQSpinBox* offset_owner = 0; - if (offset_owner != this) { - offset_owner = this; - offset = 0; - } - offset += -e->delta()/120; - if (TQABS(offset) < 1) - return; - int ioff = int(offset); - int i; - for (i=0; i 0 ? stepDown() : stepUp(); - offset -= ioff; -} -#endif - -/*! - This virtual function is called by TQRangeControl whenever the - value has changed. The TQSpinBox reimplementation updates the - display and emits the valueChanged() signals; if you need - additional processing, either reimplement this or connect to one - of the valueChanged() signals. -*/ - -void TQSpinBox::valueChange() -{ - d->selreq = hasFocus(); - updateDisplay(); - d->selreq = FALSE; - emit valueChanged( value() ); - emit valueChanged( currentValueText() ); -#if defined(QT_ACCESSIBILITY_SUPPORT) - TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); -#endif -} - - -/*! - This virtual function is called by TQRangeControl whenever the - range has changed. It adjusts the default validator and updates - the display; if you need additional processing, you can - reimplement this function. -*/ - -void TQSpinBox::rangeChange() -{ - updateDisplay(); -} - - -/*! - Sets the validator to \a v. The validator controls what keyboard - input is accepted when the user is editing in the value field. The - default is to use a suitable TQIntValidator. - - Use setValidator(0) to turn off input validation (entered input - will still be kept within the spin box's range). -*/ - -void TQSpinBox::setValidator( const TQValidator* v ) -{ - if ( vi ) - vi->setValidator( v ); -} - - -/*! - Returns the validator that constrains editing for this spin box if - there is any; otherwise returns 0. - - \sa setValidator() TQValidator -*/ - -const TQValidator * TQSpinBox::validator() const -{ - return vi ? vi->validator() : 0; -} - -/*! - Updates the contents of the embedded TQLineEdit to reflect the - current value using mapValueToText(). Also enables/disables the - up/down push buttons accordingly. - - \sa mapValueToText() -*/ -void TQSpinBox::updateDisplay() -{ - vi->setUpdatesEnabled( FALSE ); - vi->setText( currentValueText() ); - if ( d->selreq && isVisible() && ( hasFocus() || vi->hasFocus() ) ) { - selectAll(); - } else { - if ( !suffix().isEmpty() && vi->text().endsWith(suffix()) ) - vi->setCursorPosition( vi->text().length() - suffix().length() ); - } - vi->setUpdatesEnabled( TRUE ); - vi->repaint( FALSE ); // immediate repaint needed for some reason - edited = FALSE; - - bool upEnabled = isEnabled() && ( wrapping() || value() < maxValue() ); - bool downEnabled = isEnabled() && ( wrapping() || value() > minValue() ); - - d->controls->setUpEnabled( upEnabled ); - d->controls->setDownEnabled( downEnabled ); - vi->setEnabled( isEnabled() ); - repaint( FALSE ); -} - - -/*! - TQSpinBox calls this after the user has manually edited the - contents of the spin box (i.e. by typing in the embedded - TQLineEdit, rather than using the up/down buttons/keys). - - The default implementation of this function interprets the new - text using mapTextToValue(). If mapTextToValue() is successful, it - changes the spin box's value; if not, the value is left unchanged. - - \sa editor() -*/ - -void TQSpinBox::interpretText() -{ - bool ok = TRUE; - bool done = FALSE; - int newVal = 0; - if ( !specialValueText().isEmpty() ) { - TQString s = text().stripWhiteSpace(); - TQString t = specialValueText().stripWhiteSpace(); - if ( s == t ) { - newVal = minValue(); - done = TRUE; - } - } - if ( !done ) - newVal = mapTextToValue( &ok ); - if ( ok ) - setValue( newVal ); - updateDisplay(); // sometimes redundant -} - - -/*! - Returns the geometry of the "up" button. -*/ - -TQRect TQSpinBox::upRect() const -{ - return d->controls->upRect(); -} - - -/*! - Returns the geometry of the "down" button. -*/ - -TQRect TQSpinBox::downRect() const -{ - return d->controls->downRect(); -} - - -/*! - Returns a pointer to the embedded TQLineEdit. -*/ - -TQLineEdit* TQSpinBox::editor() const -{ - return vi; -} - - -/*! - This slot is called whenever the user edits the spin box's text. -*/ - -void TQSpinBox::textChanged() -{ - edited = TRUE; // this flag is cleared in updateDisplay() -} - - -/*! - This virtual function is used by the spin box whenever it needs to - display value \a v. The default implementation returns a string - containing \a v printed in the standard way. Reimplementations may - return anything. (See the example in the detailed description.) - - Note that TQt does not call this function for specialValueText() - and that neither prefix() nor suffix() are included in the return - value. - - If you reimplement this, you may also need to reimplement - mapTextToValue(). - - \sa updateDisplay(), mapTextToValue() -*/ - -TQString TQSpinBox::mapValueToText( int v ) -{ - TQString s; - s.setNum( v ); - return s; -} - - -/*! - This virtual function is used by the spin box whenever it needs to - interpret text entered by the user as a value. The text is - available as text() and as cleanText(), and this function must - parse it if possible. If \a ok is not 0: if it parses the text - successfully, \a *ok is set to TRUE; otherwise \a *ok is set to - FALSE. - - Subclasses that need to display spin box values in a non-numeric - way need to reimplement this function. - - Note that TQt handles specialValueText() separately; this function - is only concerned with the other values. - - The default implementation tries to interpret the text() as an - integer in the standard way and returns the integer value. - - \sa interpretText(), mapValueToText() -*/ - -int TQSpinBox::mapTextToValue( bool* ok ) -{ - TQString s = text(); - int newVal = s.toInt( ok ); - if ( !(*ok) && !( !prefix() && !suffix() ) ) {// Try removing any pre/suffix - s = cleanText(); - newVal = s.toInt( ok ); - } - return newVal; -} - - -/*! - Returns the full text calculated from the current value, including - any prefix and suffix. If there is special value text and the - value is minValue() the specialValueText() is returned. -*/ - -TQString TQSpinBox::currentValueText() -{ - TQString s; - if ( (value() == minValue()) && !specialValueText().isEmpty() ) { - s = specialValueText(); - } else { - s = prefix(); - s.append( mapValueToText( value() ) ); - s.append( suffix() ); - } - return s; -} - -/*! - \reimp -*/ - -void TQSpinBox::styleChange( TQStyle& old ) -{ - arrangeWidgets(); - TQWidget::styleChange( old ); -} - - -/*! - \enum TQSpinBox::ButtonSymbols - - This enum type determines what the buttons in a spin box show. - - \value UpDownArrows the buttons show little arrows in the classic - style. - - \value PlusMinus the buttons show + and - symbols. - - \sa TQSpinBox::buttonSymbols -*/ - -/*! - \property TQSpinBox::buttonSymbols - - \brief the current button symbol mode - - The possible values can be either \c UpDownArrows or \c PlusMinus. - The default is \c UpDownArrows. - - \sa ButtonSymbols -*/ - -void TQSpinBox::setButtonSymbols( ButtonSymbols newSymbols ) -{ - if ( buttonSymbols() == newSymbols ) - return; - - switch ( newSymbols ) { - case UpDownArrows: - d->controls->setButtonSymbols( TQSpinWidget::UpDownArrows ); - break; - case PlusMinus: - d->controls->setButtonSymbols( TQSpinWidget::PlusMinus ); - break; - } - // repaint( FALSE ); -} - -TQSpinBox::ButtonSymbols TQSpinBox::buttonSymbols() const -{ - switch( d->controls->buttonSymbols() ) { - case TQSpinWidget::UpDownArrows: - return UpDownArrows; - case TQSpinWidget::PlusMinus: - return PlusMinus; - } - return UpDownArrows; -} - -/*! - \property TQSpinBox::minValue - - \brief the minimum value of the spin box - - When setting this property, \l TQSpinBox::maxValue is adjusted, if - necessary, to ensure that the range remains valid. - - \sa setRange() setSpecialValueText() -*/ - -int TQSpinBox::minValue() const -{ - return TQRangeControl::minValue(); -} - -void TQSpinBox::setMinValue( int minVal ) -{ - TQRangeControl::setMinValue( minVal ); -} - -/*! - \property TQSpinBox::maxValue - \brief the maximum value of the spin box - - When setting this property, \l TQSpinBox::minValue is adjusted, if - necessary, to ensure that the range remains valid. - - \sa setRange() setSpecialValueText() -*/ - -int TQSpinBox::maxValue() const -{ - return TQRangeControl::maxValue(); -} - -void TQSpinBox::setMaxValue( int maxVal ) -{ - TQRangeControl::setMaxValue( maxVal ); -} - -/*! - \property TQSpinBox::lineStep - \brief the line step - - When the user uses the arrows to change the spin box's value the - value will be incremented/decremented by the amount of the line - step. - - The setLineStep() function calls the virtual stepChange() function - if the new line step is different from the previous setting. - - \sa TQRangeControl::setSteps() setRange() -*/ - -int TQSpinBox::lineStep() const -{ - return TQRangeControl::lineStep(); -} - -void TQSpinBox::setLineStep( int i ) -{ - setSteps( i, pageStep() ); -} - -/*! - Selects all the text in the spin box's editor. -*/ - -void TQSpinBox::selectAll() -{ - int overhead = prefix().length() + suffix().length(); - if ( !overhead || currentValueText() == specialValueText() ) { - vi->selectAll(); - } else { - vi->setSelection( prefix().length(), vi->text().length() - overhead ); - } -} - -#endif diff --git a/src/widgets/qspinwidget.cpp b/src/widgets/qspinwidget.cpp deleted file mode 100644 index c5b237d41..000000000 --- a/src/widgets/qspinwidget.cpp +++ /dev/null @@ -1,467 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQSpinWidget 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 "ntqrangecontrol.h" - -#ifndef TQT_NO_SPINWIDGET - -#include "tqrect.h" -#include "tqtimer.h" -#include "tqstyle.h" -#include "tqpainter.h" - -class TQSpinWidgetPrivate -{ -public: - TQSpinWidgetPrivate() - : upEnabled( TRUE ), - downEnabled( TRUE ), - theButton( 0 ), - buttonDown( 0 ), - timerUp( 0 ), - bsyms( TQSpinWidget::UpDownArrows ), - ed ( 0 ) {} - uint upEnabled :1; - uint downEnabled :1; - uint theButton :2; - uint buttonDown :2; - uint timerUp : 1; - TQRect up; - TQRect down; - TQTimer auRepTimer; - TQSpinWidget::ButtonSymbols bsyms; - TQWidget *ed; - void startTimer( int msec ) { auRepTimer.start( msec, TRUE ); } - void startTimer( bool up, int msec ) { timerUp = up; startTimer( msec ); } - void stopTimer() { auRepTimer.stop(); } -}; - -/*! - - \class TQSpinWidget qspinwidget.h - \brief The TQSpinWidget class is an internal range control related class. - - \internal - - Constructs an empty range control widget with parent \a parent - called \a name. - -*/ - -TQSpinWidget::TQSpinWidget( TQWidget* parent, const char* name ) - : TQWidget( parent, name ) -{ - d = new TQSpinWidgetPrivate(); - connect( &d->auRepTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( timerDone() ) ); - setFocusPolicy( StrongFocus ); - - arrange(); - updateDisplay(); -} - - -/*! Destroys the object and frees any allocated resources. - -*/ - -TQSpinWidget::~TQSpinWidget() -{ - delete d; -} - -/*! */ -TQWidget * TQSpinWidget::editWidget() -{ - return d->ed; -} - -/*! - Sets the editing widget to \a w. -*/ -void TQSpinWidget::setEditWidget( TQWidget * w ) -{ - if ( w ) { - if (w->parentWidget() != this) - w->reparent( this, TQPoint( 0, 0 ) ); - setFocusProxy( w ); - } - d->ed = w; - arrange(); - updateDisplay(); -} - -/*! \reimp - -*/ - -void TQSpinWidget::mousePressEvent( TQMouseEvent *e ) -{ - if ( e->button() != LeftButton ) { - d->stopTimer(); - d->buttonDown = 0; - d->theButton = 0; - repaint( d->down.unite( d->up ), FALSE ); - return; - } - - uint oldButtonDown = d->buttonDown; - - if ( d->down.contains( e->pos() ) && d->downEnabled ) - d->buttonDown = 1; - else if ( d->up.contains( e->pos() ) && d->upEnabled ) - d->buttonDown = 2; - else - d->buttonDown = 0; - - d->theButton = d->buttonDown; - if ( oldButtonDown != d->buttonDown ) { - if ( !d->buttonDown ) { - repaint( d->down.unite( d->up ), FALSE ); - } else if ( d->buttonDown & 1 ) { - repaint( d->down, FALSE ); - stepDown(); - d->startTimer( FALSE, 300 ); - } else if ( d->buttonDown & 2 ) { - repaint( d->up, FALSE ); - stepUp(); - d->startTimer( TRUE, 300 ); - } - } -} - -/*! - -*/ - -void TQSpinWidget::arrange() -{ - d->up = TQStyle::visualRect( style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, - TQStyle::SC_SpinWidgetUp ), this ); - d->down = TQStyle::visualRect( style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, - TQStyle::SC_SpinWidgetDown ), this ); - if ( d->ed ) { - TQRect r = TQStyle::visualRect( style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, - TQStyle::SC_SpinWidgetEditField ), this ); - d->ed->setGeometry( r ); - } -} - -/*! - -*/ - -void TQSpinWidget::stepUp() -{ - emit stepUpPressed(); -} - -void TQSpinWidget::resizeEvent( TQResizeEvent* ) -{ - arrange(); -} - -/*! - -*/ - -void TQSpinWidget::stepDown() -{ - emit stepDownPressed(); -} - - -void TQSpinWidget::timerDone() -{ - // we use a double timer to make it possible for users to do - // something with 0-timer on valueChanged. - TQTimer::singleShot( 1, this, TQ_SLOT( timerDoneEx() ) ); -} - -void TQSpinWidget::timerDoneEx() -{ - if ( !d->buttonDown ) - return; - if ( d->timerUp ) - stepUp(); - else - stepDown(); - d->startTimer( 100 ); -} - - -void TQSpinWidget::windowActivationChange( bool oldActive ) -{ - //was active, but lost focus - if ( oldActive && d->buttonDown ) { - d->stopTimer(); - d->buttonDown = 0; - d->theButton = 0; - } - TQWidget::windowActivationChange( oldActive ); -} - - - -/*! - The event is passed in \a e. -*/ - -void TQSpinWidget::mouseReleaseEvent( TQMouseEvent *e ) -{ - if ( e->button() != LeftButton ) - return; - - uint oldButtonDown = d->theButton; - d->theButton = 0; - if ( oldButtonDown != d->theButton ) { - if ( oldButtonDown & 1 ) - repaint( d->down, FALSE ); - else if ( oldButtonDown & 2 ) - repaint( d->up, FALSE ); - } - d->stopTimer(); - d->buttonDown = 0; -} - - -/*! - The event is passed in \a e. -*/ - -void TQSpinWidget::mouseMoveEvent( TQMouseEvent *e ) -{ - if ( !(e->state() & LeftButton ) ) - return; - - uint oldButtonDown = d->theButton; - if ( oldButtonDown & 1 && !d->down.contains( e->pos() ) ) { - d->stopTimer(); - d->theButton = 0; - repaint( d->down, FALSE ); - } else if ( oldButtonDown & 2 && !d->up.contains( e->pos() ) ) { - d->stopTimer(); - d->theButton = 0; - repaint( d->up, FALSE ); - } else if ( !oldButtonDown && d->up.contains( e->pos() ) && d->buttonDown & 2 ) { - d->startTimer( 500 ); - d->theButton = 2; - repaint( d->up, FALSE ); - } else if ( !oldButtonDown && d->down.contains( e->pos() ) && d->buttonDown & 1 ) { - d->startTimer( 500 ); - d->theButton = 1; - repaint( d->down, FALSE ); - } -} - - -/*! - The event is passed in \a e. -*/ -#ifndef TQT_NO_WHEELEVENT -void TQSpinWidget::wheelEvent( TQWheelEvent *e ) -{ - e->accept(); - static float offset = 0; - static TQSpinWidget* offset_owner = 0; - if ( offset_owner != this ) { - offset_owner = this; - offset = 0; - } - offset += -e->delta()/120; - if ( TQABS( offset ) < 1 ) - return; - int ioff = int(offset); - int i; - for( i=0; i < TQABS( ioff ); i++ ) - offset > 0 ? stepDown() : stepUp(); - offset -= ioff; -} -#endif - -/*! - -*/ -void TQSpinWidget::paintEvent( TQPaintEvent * ) -{ - TQPainter p( this ); - - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasMouse()) - flags |= TQStyle::Style_MouseOver; - if (hasFocus() || (focusProxy() && focusProxy()->hasFocus())) - flags |= TQStyle::Style_HasFocus; - - TQStyle::SCFlags active; - if ( d->theButton & 1 ) - active = TQStyle::SC_SpinWidgetDown; - else if ( d->theButton & 2 ) - active = TQStyle::SC_SpinWidgetUp; - else - active = TQStyle::SC_None; - - TQRect fr = TQStyle::visualRect( - style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, - TQStyle::SC_SpinWidgetFrame ), this ); - style().drawComplexControl( TQStyle::CC_SpinWidget, &p, this, - fr, colorGroup(), - flags, - (uint)TQStyle::SC_All, - active ); -} - - -/*! - The previous style is passed in \a old. -*/ - -void TQSpinWidget::styleChange( TQStyle& old ) -{ - arrange(); - TQWidget::styleChange( old ); -} - -/*! -*/ - -TQRect TQSpinWidget::upRect() const -{ - return d->up; -} - -/*! -*/ - -TQRect TQSpinWidget::downRect() const -{ - return d->down; -} - -/*! -*/ - -void TQSpinWidget::updateDisplay() -{ - if ( !isEnabled() ) { - d->upEnabled = FALSE; - d->downEnabled = FALSE; - } - if ( d->theButton & 1 && ( d->downEnabled ) == 0 ) { - d->theButton &= ~1; - d->buttonDown &= ~1; - } - - if ( d->theButton & 2 && ( d->upEnabled ) == 0 ) { - d->theButton &= ~2; - d->buttonDown &= ~2; - } - repaint( FALSE ); -} - - -/*! - The previous enabled state is passed in \a old. -*/ - -void TQSpinWidget::enableChanged( bool ) -{ - d->upEnabled = isEnabled(); - d->downEnabled = isEnabled(); - updateDisplay(); -} - - -/*! - Sets up-enabled to \a on. -*/ - -void TQSpinWidget::setUpEnabled( bool on ) -{ - if ( (bool)d->upEnabled != on ) { - d->upEnabled = on; - updateDisplay(); - } -} - -/*! -*/ - -bool TQSpinWidget::isUpEnabled() const -{ - return d->upEnabled; -} - -/*! - Sets down-enabled to \a on. -*/ - -void TQSpinWidget::setDownEnabled( bool on ) -{ - if ( (bool)d->downEnabled != on ) { - d->downEnabled = on; - updateDisplay(); - } -} - -/*! -*/ - -bool TQSpinWidget::isDownEnabled() const -{ - return d->downEnabled; -} - -/*! - Sets the button symbol to \a bs. -*/ - -void TQSpinWidget::setButtonSymbols( ButtonSymbols bs ) -{ - d->bsyms = bs; -} - -/*! -*/ - -TQSpinWidget::ButtonSymbols TQSpinWidget::buttonSymbols() const -{ - return d->bsyms; -} - -#endif diff --git a/src/widgets/qt_widgets.pri b/src/widgets/qt_widgets.pri index 876cc428c..72cfdba84 100644 --- a/src/widgets/qt_widgets.pri +++ b/src/widgets/qt_widgets.pri @@ -5,11 +5,11 @@ widgets { HEADERS += $$WIDGETS_H/ntqbuttongroup.h \ $$WIDGETS_H/ntqbutton.h \ - $$WIDGETS_P/qdialogbuttons_p.h \ - $$WIDGETS_H/ntqcheckbox.h \ - $$WIDGETS_H/ntqcombobox.h \ + $$WIDGETS_P/tqdialogbuttons_p.h \ + $$WIDGETS_H/tqcheckbox.h \ + $$WIDGETS_H/tqcombobox.h \ $$WIDGETS_P/tqwidgetresizehandler_p.h \ - $$WIDGETS_H/ntqdial.h \ + $$WIDGETS_H/tqdial.h \ $$WIDGETS_H/ntqdockarea.h \ $$WIDGETS_H/ntqdockwindow.h \ $$WIDGETS_H/ntqframe.h \ @@ -22,8 +22,8 @@ widgets { $$WIDGETS_H/ntqhbox.h \ $$WIDGETS_H/tqiconview.h \ $$WIDGETS_H/tqlabel.h \ - $$WIDGETS_H/ntqlcdnumber.h \ - $$WIDGETS_H/ntqlineedit.h \ + $$WIDGETS_H/tqlcdnumber.h \ + $$WIDGETS_H/tqlineedit.h \ $$WIDGETS_H/ntqlistbox.h \ $$WIDGETS_H/ntqlistview.h \ $$WIDGETS_H/tqmainwindow.h \ @@ -32,14 +32,14 @@ widgets { $$WIDGETS_H/ntqmultilineedit.h \ $$WIDGETS_H/tqpopupmenu.h \ $$WIDGETS_H/ntqprogressbar.h \ - $$WIDGETS_H/ntqpushbutton.h \ - $$WIDGETS_H/ntqradiobutton.h \ + $$WIDGETS_H/tqpushbutton.h \ + $$WIDGETS_H/tqradiobutton.h \ $$WIDGETS_H/ntqrangecontrol.h \ - $$WIDGETS_H/ntqscrollbar.h \ - $$WIDGETS_H/ntqscrollview.h \ - $$WIDGETS_H/ntqslider.h \ + $$WIDGETS_H/tqscrollbar.h \ + $$WIDGETS_H/tqscrollview.h \ + $$WIDGETS_H/tqslider.h \ $$WIDGETS_H/ntqsplashscreen.h \ - $$WIDGETS_H/ntqspinbox.h \ + $$WIDGETS_H/tqspinbox.h \ $$WIDGETS_H/ntqsplitter.h \ $$WIDGETS_H/tqstatusbar.h \ $$WIDGETS_H/ntqtabbar.h \ @@ -67,11 +67,11 @@ widgets { SOURCES += $$WIDGETS_CPP/qbuttongroup.cpp \ $$WIDGETS_CPP/qbutton.cpp \ - $$WIDGETS_CPP/qdialogbuttons.cpp \ - $$WIDGETS_CPP/qcheckbox.cpp \ - $$WIDGETS_CPP/qcombobox.cpp \ + $$WIDGETS_CPP/tqdialogbuttons.cpp \ + $$WIDGETS_CPP/tqcheckbox.cpp \ + $$WIDGETS_CPP/tqcombobox.cpp \ $$WIDGETS_CPP/tqwidgetresizehandler.cpp \ - $$WIDGETS_CPP/qdial.cpp \ + $$WIDGETS_CPP/tqdial.cpp \ $$WIDGETS_CPP/qdockarea.cpp \ $$WIDGETS_CPP/qdockwindow.cpp \ $$WIDGETS_CPP/qframe.cpp \ @@ -84,8 +84,8 @@ widgets { $$WIDGETS_CPP/qhbox.cpp \ $$WIDGETS_CPP/tqiconview.cpp \ $$WIDGETS_CPP/tqlabel.cpp \ - $$WIDGETS_CPP/qlcdnumber.cpp \ - $$WIDGETS_CPP/qlineedit.cpp \ + $$WIDGETS_CPP/tqlcdnumber.cpp \ + $$WIDGETS_CPP/tqlineedit.cpp \ $$WIDGETS_CPP/qlistbox.cpp \ $$WIDGETS_CPP/qlistview.cpp \ $$WIDGETS_CPP/tqmainwindow.cpp \ @@ -94,15 +94,15 @@ widgets { $$WIDGETS_CPP/qmultilineedit.cpp \ $$WIDGETS_CPP/tqpopupmenu.cpp \ $$WIDGETS_CPP/qprogressbar.cpp \ - $$WIDGETS_CPP/qpushbutton.cpp \ - $$WIDGETS_CPP/qradiobutton.cpp \ + $$WIDGETS_CPP/tqpushbutton.cpp \ + $$WIDGETS_CPP/tqradiobutton.cpp \ $$WIDGETS_CPP/qrangecontrol.cpp \ - $$WIDGETS_CPP/qscrollbar.cpp \ - $$WIDGETS_CPP/qscrollview.cpp \ - $$WIDGETS_CPP/qslider.cpp \ + $$WIDGETS_CPP/tqscrollbar.cpp \ + $$WIDGETS_CPP/tqscrollview.cpp \ + $$WIDGETS_CPP/tqslider.cpp \ $$WIDGETS_CPP/qsplashscreen.cpp \ - $$WIDGETS_CPP/qspinbox.cpp \ - $$WIDGETS_CPP/qspinwidget.cpp \ + $$WIDGETS_CPP/tqspinbox.cpp \ + $$WIDGETS_CPP/tqspinwidget.cpp \ $$WIDGETS_CPP/qsplitter.cpp \ $$WIDGETS_CPP/tqstatusbar.cpp \ $$WIDGETS_CPP/tqsyntaxhighlighter.cpp \ diff --git a/src/widgets/tqaction.cpp b/src/widgets/tqaction.cpp index 31d308420..a7e5c0e58 100644 --- a/src/widgets/tqaction.cpp +++ b/src/widgets/tqaction.cpp @@ -45,7 +45,7 @@ #include "tqpopupmenu.h" #include "ntqaccel.h" #include "tqtoolbutton.h" -#include "ntqcombobox.h" +#include "tqcombobox.h" #include "tqtooltip.h" #include "tqwhatsthis.h" #include "tqstatusbar.h" diff --git a/src/widgets/tqcheckbox.cpp b/src/widgets/tqcheckbox.cpp new file mode 100644 index 000000000..a9cf27d0d --- /dev/null +++ b/src/widgets/tqcheckbox.cpp @@ -0,0 +1,364 @@ +/**************************************************************************** +** +** Implementation of TQCheckBox class +** +** Created : 940222 +** +** 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 "tqcheckbox.h" +#ifndef TQT_NO_CHECKBOX +#include "tqpainter.h" +#include "ntqdrawutil.h" +#include "tqpixmap.h" +#include "tqpixmapcache.h" +#include "tqbitmap.h" +#include "tqtextstream.h" +#include "ntqapplication.h" +#include "tqstyle.h" + +/*! + \class TQCheckBox tqcheckbox.h + \brief The TQCheckBox widget provides a checkbox with a text label. + + \ingroup basic + \mainclass + + TQCheckBox and TQRadioButton are both option buttons. That is, they + can be switched on (checked) or off (unchecked). The classes + differ in how the choices for the user are restricted. Radio + buttons define a "one of many" choice, whereas checkboxes provide + "many of many" choices. + + A TQButtonGroup can be used to group check buttons visually. + + Whenever a checkbox is checked or cleared it emits the signal + toggled(). Connect to this signal if you want to trigger an action + each time the checkbox changes state. You can use isChecked() to + query whether or not a checkbox is checked. + + \warning The toggled() signal can not be trusted for tristate + checkboxes. + + In addition to the usual checked and unchecked states, TQCheckBox + optionally provides a third state to indicate "no change". This + is useful whenever you need to give the user the option of neither + checking nor unchecking a checkbox. If you need this third state, + enable it with setTristate() and use state() to query the current + toggle state. When a tristate checkbox changes state, it emits the + stateChanged() signal. + + Just like TQPushButton, a checkbox can display text or a pixmap. + The text can be set in the constructor or with setText(); the + pixmap is set with setPixmap(). + + \important text(), setText(), text(), pixmap(), setPixmap(), + accel(), setAccel(), isToggleButton(), setDown(), isDown(), + isOn(), state(), autoRepeat(), isExclusiveToggle(), group(), + setAutoRepeat(), toggle(), pressed(), released(), clicked(), + toggled(), state() stateChanged() + + + + \sa TQButton TQRadioButton + \link guibooks.html#fowler Fowler: Check Box \endlink +*/ + +/*! + \property TQCheckBox::checked + \brief whether the checkbox is checked + + The default is unchecked, i.e. FALSE. +*/ + +/*! + \property TQCheckBox::autoMask + \brief whether the checkbox is automatically masked + + \sa TQWidget::setAutoMask() +*/ + +/*! + \property TQCheckBox::tristate + \brief whether the checkbox is a tri-state checkbox + + The default is two-state, i.e. tri-state is FALSE. +*/ + +/*! + Constructs a checkbox with no text. + + The \a parent and \a name arguments are sent to the TQWidget + constructor. +*/ + +TQCheckBox::TQCheckBox( TQWidget *parent, const char *name ) + : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) +{ + setToggleButton( TRUE ); + setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); +} + +/*! + Constructs a checkbox with text \a text. + + The \a parent and \a name arguments are sent to the TQWidget + constructor. +*/ + +TQCheckBox::TQCheckBox( const TQString &text, TQWidget *parent, const char *name ) + : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) +{ + setText( text ); + setToggleButton( TRUE ); + setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); +} + +/*! + Sets the checkbox to the "no change" state. + + \sa setTristate() +*/ +void TQCheckBox::setNoChange() +{ + setTristate(TRUE); + setState( NoChange ); +} + +void TQCheckBox::setTristate(bool y) +{ + setToggleType( y ? Tristate : Toggle ); +} + +bool TQCheckBox::isTristate() const +{ + return toggleType() == Tristate; +} + + +/*!\reimp +*/ +TQSize TQCheckBox::sizeHint() const +{ + // NB: TQRadioButton::sizeHint() is similar + constPolish(); + + TQPainter p(this); + TQSize sz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, + pixmap(), text()).size(); + + return (style().sizeFromContents(TQStyle::CT_CheckBox, this, sz). + expandedTo(TQApplication::globalStrut())); +} + + +/*!\reimp +*/ + +void TQCheckBox::drawButton( TQPainter *paint ) +{ + TQPainter *p = paint; + TQRect irect = TQStyle::visualRect( style().subRect(TQStyle::SR_CheckBoxIndicator, this), this ); + const TQColorGroup &cg = colorGroup(); + +#if !defined( TQT_NO_TEXTSTREAM ) && !defined( TQ_WS_MACX ) +# define SAVE_CHECKBOX_PIXMAPS +#endif +#if defined(SAVE_CHECKBOX_PIXMAPS) + TQString pmkey; // pixmap key + int kf = 0; + if ( isDown() ) + kf |= 1; + if ( isEnabled() ) + kf |= 2; + if ( hasFocus() ) + kf |= 4; // active vs. normal colorgroup + if( isActiveWindow() ) + kf |= 8; + if ( hasMouse() ) + kf |= 16; + + kf |= state() << 5; + TQTextOStream os(&pmkey); + os << "$qt_check_" << style().className() << "_" + << palette().serialNumber() << "_" << irect.width() << "x" << irect.height() << "_" << kf; + TQPixmap *pm = TQPixmapCache::find( pmkey ); + if ( pm ) { // pixmap exists + p->drawPixmap( irect.topLeft(), *pm ); + drawButtonLabel( p ); + return; + } + bool use_pm = TRUE; + TQPainter pmpaint; + int wx = 0, wy = 0; + if ( use_pm ) { + pm = new TQPixmap( irect.size() ); // create new pixmap + TQ_CHECK_PTR( pm ); + pm->fill( cg.background() ); + TQPainter::redirect(this, pm); + pmpaint.begin(this); + p = &pmpaint; // draw in pixmap + wx = irect.x(); // save x,y coords + wy = irect.y(); + irect.moveTopLeft(TQPoint(0, 0)); + p->setBackgroundColor( cg.background() ); + } +#endif + + TQStyle::SFlags flags = TQStyle::Style_Default; + if ( isEnabled() ) + flags |= TQStyle::Style_Enabled; + if ( hasFocus() ) + flags |= TQStyle::Style_HasFocus; + if ( isDown() ) + flags |= TQStyle::Style_Down; + if ( hasMouse() ) + flags |= TQStyle::Style_MouseOver; + if ( state() == TQButton::On ) + flags |= TQStyle::Style_On; + else if ( state() == TQButton::Off ) + flags |= TQStyle::Style_Off; + else if ( state() == TQButton::NoChange ) + flags |= TQStyle::Style_NoChange; + + style().drawControl(TQStyle::CE_CheckBox, p, this, irect, cg, flags); + +#if defined(SAVE_CHECKBOX_PIXMAPS) + if ( use_pm ) { + pmpaint.end(); + TQPainter::redirect( this, 0 ); + if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) { + TQBitmap bm( pm->size() ); + bm.fill( color0 ); + pmpaint.begin( &bm ); + style().drawControlMask(TQStyle::CE_CheckBox, &pmpaint, this, irect); + pmpaint.end(); + pm->setMask( bm ); + } + p = paint; // draw in default device + p->drawPixmap( wx, wy, *pm ); + if (!TQPixmapCache::insert(pmkey, pm) ) // save in cache + delete pm; + } +#endif + + drawButtonLabel( paint ); +} + + +/*!\reimp +*/ +void TQCheckBox::drawButtonLabel( TQPainter *p ) +{ + TQRect r = + TQStyle::visualRect( style().subRect(TQStyle::SR_CheckBoxContents, this), this ); + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasFocus()) + flags |= TQStyle::Style_HasFocus; + if (isDown()) + flags |= TQStyle::Style_Down; + if (state() == TQButton::On) + flags |= TQStyle::Style_On; + else if (state() == TQButton::Off) + flags |= TQStyle::Style_Off; + else if (state() == TQButton::NoChange) + flags |= TQStyle::Style_NoChange; + + style().drawControl(TQStyle::CE_CheckBoxLabel, p, this, r, colorGroup(), flags); +} + +/*! + \reimp +*/ +void TQCheckBox::resizeEvent( TQResizeEvent *e ) +{ + TQButton::resizeEvent(e); + if ( isVisible() ) { + TQPainter p(this); + TQSize isz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, + pixmap(), text()).size(); + TQSize wsz = (style().sizeFromContents(TQStyle::CT_CheckBox, this, isz). + expandedTo(TQApplication::globalStrut())); + + update(wsz.width(), isz.width(), 0, wsz.height()); + } + if (autoMask()) + updateMask(); +} + +/*! + \reimp +*/ +void TQCheckBox::updateMask() +{ + TQRect irect = + TQStyle::visualRect( style().subRect(TQStyle::SR_CheckBoxIndicator, this), this ); + + TQBitmap bm(width(), height()); + bm.fill(color0); + + TQPainter p( &bm, this ); + style().drawControlMask(TQStyle::CE_CheckBox, &p, this, irect); + if ( ! text().isNull() || ( pixmap() && ! pixmap()->isNull() ) ) { + TQRect crect = + TQStyle::visualRect( style().subRect( TQStyle::SR_CheckBoxContents, + this ), this ); + TQRect frect = + TQStyle::visualRect( style().subRect( TQStyle::SR_CheckBoxFocusRect, + this ), this ); + TQRect label(crect.unite(frect)); + p.fillRect(label, color1); + } + p.end(); + + setMask(bm); +} + +/*!\reimp*/ +bool TQCheckBox::hitButton( const TQPoint &pos ) const +{ + TQRect r = TQStyle::visualRect( style().subRect( TQStyle::SR_CheckBoxFocusRect, this ), this ); + if ( tqApp->reverseLayout() ) { + r.setRight( width() ); + } else { + r.setLeft( 0 ); + } + return r.contains( pos ); +} + +#endif diff --git a/src/widgets/tqcheckbox.h b/src/widgets/tqcheckbox.h new file mode 100644 index 000000000..4a63e4b4a --- /dev/null +++ b/src/widgets/tqcheckbox.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Definition of TQCheckBox class +** +** Created : 940222 +** +** 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 TQCHECKBOX_H +#define TQCHECKBOX_H + +#ifndef QT_H +#include "ntqbutton.h" +#endif // QT_H + +#ifndef TQT_NO_CHECKBOX + +class TQ_EXPORT TQCheckBox : public TQButton +{ + TQ_OBJECT + TQ_PROPERTY( bool checked READ isChecked WRITE setChecked ) + TQ_PROPERTY( bool tristate READ isTristate WRITE setTristate ) + TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) + +public: + TQCheckBox( TQWidget *parent, const char* name=0 ); + TQCheckBox( const TQString &text, TQWidget *parent, const char* name=0 ); + + bool isChecked() const; + + void setNoChange(); + + void setTristate(bool y=TRUE); + bool isTristate() const; + + TQSize sizeHint() const; + +public slots: + void setChecked( bool check ); + +protected: + void resizeEvent( TQResizeEvent* ); + void drawButton( TQPainter * ); + void drawButtonLabel( TQPainter * ); + void updateMask(); + bool hitButton( const TQPoint &pos ) const; +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQCheckBox( const TQCheckBox & ); + TQCheckBox &operator=( const TQCheckBox & ); +#endif +}; + + +inline bool TQCheckBox::isChecked() const +{ return isOn(); } + +inline void TQCheckBox::setChecked( bool check ) +{ setOn( check ); } + + +#endif // TQT_NO_CHECKBOX + +#endif // TQCHECKBOX_H diff --git a/src/widgets/tqcombobox.cpp b/src/widgets/tqcombobox.cpp new file mode 100644 index 000000000..9914c4398 --- /dev/null +++ b/src/widgets/tqcombobox.cpp @@ -0,0 +1,2338 @@ +/********************************************************************** +** +** Implementation of TQComboBox widget class +** +** Created : 940426 +** +** 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 "tqcombobox.h" +#ifndef TQT_NO_COMBOBOX +#include "tqpopupmenu.h" +#include "ntqlistbox.h" +#include "tqpainter.h" +#include "ntqdrawutil.h" +#include "tqstrlist.h" +#include "tqpixmap.h" +#include "tqtimer.h" +#include "ntqapplication.h" +#include "tqlineedit.h" +#include "tqbitmap.h" +#include "qeffects_p.h" +#include "tqstringlist.h" +#include "tqcombobox.h" +#include "tqstyle.h" +#include +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif + +/*! + \class TQComboBox tqcombobox.h + \brief The TQComboBox widget is a combined button and popup list. + + \ingroup basic + \mainclass + + A combobox is a selection widget which displays the current item + and can pop up a list of items. A combobox may be editable in + which case the user can enter arbitrary strings. + + Comboboxes provide a means of showing the user's current choice + out of a list of options in a way that takes up the minimum amount + of screen space. + + TQComboBox supports three different display styles: Aqua/Motif 1.x, + Motif 2.0 and Windows. In Motif 1.x, a combobox was called + XmOptionMenu. In Motif 2.0, OSF introduced an improved combobox + and named that XmComboBox. TQComboBox provides both. + + TQComboBox provides two different constructors. The simplest + constructor creates an "old-style" combobox in Motif (or Aqua) + style: + \code + TQComboBox *c = new TQComboBox( this, "read-only combobox" ); + \endcode + + The other constructor creates a new-style combobox in Motif style, + and can create both read-only and editable comboboxes: + \code + TQComboBox *c1 = new TQComboBox( FALSE, this, "read-only combobox" ); + TQComboBox *c2 = new TQComboBox( TRUE, this, "editable combobox" ); + \endcode + + New-style comboboxes use a list box in both Motif and Windows + styles, and both the content size and the on-screen size of the + list box can be limited with sizeLimit() and setMaxCount() + respectively. Old-style comboboxes use a popup in Aqua and Motif + style, and that popup will happily grow larger than the desktop if + you put enough data into it. + + The two constructors create identical-looking comboboxes in + Windows style. + + Comboboxes can contain pixmaps as well as strings; the + insertItem() and changeItem() functions are suitably overloaded. + For editable comboboxes, the function clearEdit() is provided, + to clear the displayed string without changing the combobox's + contents. + + A combobox emits two signals, activated() and highlighted(), when + a new item has been activated (selected) or highlighted (made + current). Both signals exist in two versions, one with a \c + TQString argument and one with an \c int argument. If the user + highlights or activates a pixmap, only the \c int signals are + emitted. Whenever the text of an editable combobox is changed the + textChanged() signal is emitted. + + When the user enters a new string in an editable combobox, the + widget may or may not insert it, and it can insert it in several + locations. The default policy is is \c AtBottom but you can change + this using setInsertionPolicy(). + + It is possible to constrain the input to an editable combobox + using TQValidator; see setValidator(). By default, any input is + accepted. + + If the combobox is not editable then it has a default + focusPolicy() of \c TabFocus, i.e. it will not grab focus if + clicked. This differs from both Windows and Motif. If the combobox + is editable then it has a default focusPolicy() of \c StrongFocus, + i.e. it will grab focus if clicked. + + A combobox can be populated using the insert functions, + insertStringList() and insertItem() for example. Items can be + changed with changeItem(). An item can be removed with + removeItem() and all items can be removed with clear(). The text + of the current item is returned by currentText(), and the text of + a numbered item is returned with text(). The current item can be + set with setCurrentItem() or setCurrentText(). The number of items + in the combobox is returned by count(); the maximum number of + items can be set with setMaxCount(). You can allow editing using + setEditable(). For editable comboboxes you can set auto-completion + using setAutoCompletion() and whether or not the user can add + duplicates is set with setDuplicatesEnabled(). + + (Motif 1, read-only)
+ (Motif 2, editable)
+ (Motif 2, read-only)
+ (Windows style) + + Depending on the style, TQComboBox will use a TQListBox or a + TQPopupMenu to display the list of items. See setListBox() for + more information. + + \sa TQLineEdit TQListBox TQSpinBox TQRadioButton TQButtonGroup + \link guibooks.html#fowler GUI Design Handbook: Combo Box,\endlink + \link guibooks.html#fowler GUI Design Handbook: Drop-Down List Box.\endlink +*/ + + +/*! + \enum TQComboBox::Policy + + This enum specifies what the TQComboBox should do when a new string + is entered by the user. + + \value NoInsertion the string will not be inserted into the + combobox. + + \value AtTop insert the string as the first item in the combobox. + + \value AtCurrent replace the previously selected item with the + string the user has entered. + + \value AtBottom insert the string as the last item in the + combobox. + + \value AfterCurrent insert the string after the previously + selected item. + + \value BeforeCurrent insert the string before the previously + selected item. + + activated() is always emitted when the string is entered. + + If inserting the new string would cause the combobox to breach its + content size limit, the item at the other end of the list is + deleted. The definition of "other end" is + implementation-dependent. +*/ + + +/*! + \fn void TQComboBox::activated( int index ) + + This signal is emitted when a new item has been activated + (selected). The \a index is the position of the item in the + combobox. + + This signal is not emitted if the item is changed + programmatically, e.g. using setCurrentItem(). +*/ + +/*! + \overload void TQComboBox::activated( const TQString &string ) + + This signal is emitted when a new item has been activated + (selected). \a string is the selected string. + + You can also use the activated(int) signal, but be aware that its + argument is meaningful only for selected strings, not for user + entered strings. +*/ + +/*! + \fn void TQComboBox::highlighted( int index ) + + This signal is emitted when a new item has been set to be the + current item. The \a index is the position of the item in the + combobox. + + This signal is not emitted if the item is changed + programmatically, e.g. using setCurrentItem(). +*/ + +/*! + \overload void TQComboBox::highlighted( const TQString &string ) + + This signal is emitted when a new item has been set to be the + current item. \a string is the item's text. + + You can also use the highlighted(int) signal. +*/ + +/*! + \fn void TQComboBox::textChanged( const TQString &string ) + + This signal is used for editable comboboxes. It is emitted + whenever the contents of the text entry field changes. \a string + contains the new text. +*/ + +/*! + \property TQComboBox::autoCompletion + \brief whether auto-completion is enabled + + This property can only be set for editable comboboxes, for + non-editable comboboxes it has no effect. It is FALSE by default. +*/ + +/*! + \property TQComboBox::autoMask + \brief whether the combobox is automatically masked + + \sa TQWidget::setAutoMask() +*/ + +/*! \property TQComboBox::autoResize + \brief whether auto resize is enabled + \obsolete + + If this property is set to TRUE then the combobox will resize itself + whenever its contents change. The default is FALSE. +*/ + +/*! + \property TQComboBox::count + \brief the number of items in the combobox +*/ + +/*! + \property TQComboBox::currentItem + \brief the index of the current item in the combobox + + Note that the activated() and highlighted() signals are only + emitted when the user changes the current item, not when it is + changed programmatically. +*/ + +/*! + \property TQComboBox::currentText + \brief the text of the combobox's current item +*/ + +/*! + \property TQComboBox::duplicatesEnabled + \brief whether duplicates are allowed + + If the combobox is editable and the user enters some text in the + combobox's lineedit and presses Enter (and the insertionPolicy() + is not \c NoInsertion), then what happens is this: + \list + \i If the text is not already in the list, the text is inserted. + \i If the text is in the list and this property is TRUE (the + default), the text is inserted. + \i If the text is in the list and this property is FALSE, the text + is \e not inserted; instead the item which has matching text becomes + the current item. + \endlist + + This property only affects user-interaction. You can use + insertItem() to insert duplicates if you wish regardless of this + setting. +*/ + +/*! + \property TQComboBox::editable + \brief whether the combobox is editable + + This property's default is FALSE. Note that the combobox will be + cleared if this property is set to TRUE for a 1.x Motif style + combobox. To avoid this, use setEditable() before inserting any + items. Also note that the 1.x version of Motif didn't have any + editable comboboxes, so the combobox will change it's appearance + to a 2.0 style Motif combobox is it is set to be editable. +*/ + +/*! + \property TQComboBox::insertionPolicy + \brief the position of the items inserted by the user + + The default insertion policy is \c AtBottom. See \l Policy. +*/ + +/*! + \property TQComboBox::maxCount + \brief the maximum number of items allowed in the combobox +*/ + +/*! + \property TQComboBox::sizeLimit + \brief the maximum on-screen size of the combobox. + + This property is ignored for both Motif 1.x style and non-editable + comboboxes in Mac style. The default limit is ten + lines. If the number of items in the combobox is or grows larger + than lines, a scrollbar is added. +*/ + +class TQComboBoxPopup : public TQPopupMenu +{ +public: + TQComboBoxPopup( TQWidget *parent=0, const char *name=0 ) + : TQPopupMenu( parent, name ) + { + } + + int itemHeight( int index ) + { + return TQPopupMenu::itemHeight( index ); + } +}; + +static inline TQString escapedComboString(const TQString &str) +{ + TQString stringToReturn = str; + return stringToReturn.replace('&', "&&"); +} + +class TQComboBoxPopupItem : public TQCustomMenuItem +{ + TQListBoxItem *li; + TQSize sc; // Size cache optimization +public: + TQComboBoxPopupItem(TQListBoxItem *i) : TQCustomMenuItem(), li(i), sc(0, 0) { } + virtual bool fullSpan() const { return TRUE; } + virtual void paint( TQPainter*, const TQColorGroup&, bool, bool, int, int, int, int); + virtual TQSize sizeHint() { if (sc.isNull()) sc = TQSize(li->width(li->listBox()), TQMAX(25, li->height(li->listBox()))); return sc; } +}; +void TQComboBoxPopupItem::paint( TQPainter* p, const TQColorGroup&, bool, + bool, int x, int y, int, int) +{ + p->save(); + p->translate(x, y + ((sizeHint().height() / 2) - (li->height(li->listBox()) / 2))); + li->paint(p); + p->restore(); +} + + +class TQComboBoxData +{ +public: + TQComboBoxData( TQComboBox *cb ): ed( 0 ), usingLBox( FALSE ), pop( 0 ), lBox( 0 ), combo( cb ) + { + duplicatesEnabled = TRUE; + cb->setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); + } + + inline bool usingListBox() { return usingLBox; } + inline TQListBox * listBox() { return lBox; } + inline TQComboBoxPopup * popup() { return pop; } + void updateLinedGeometry(); + void setListBox( TQListBox *l ); + void setPopupMenu( TQComboBoxPopup * pm, bool isPopup=TRUE ); + + int current; + int maxCount; + int sizeLimit; + TQComboBox::Policy p; + bool autoresize; + bool poppedUp; + bool mouseWasInsidePopup; + bool arrowPressed; + bool arrowDown; + bool discardNextMousePress; + bool shortClick; + bool useCompletion; + bool completeNow; + int completeAt; + bool duplicatesEnabled; + int fullHeight, currHeight; + + TQLineEdit * ed; // /bin/ed rules! + TQTimer *completionTimer; + + TQSize sizeHint; + +private: + bool usingLBox; + TQComboBoxPopup *pop; + TQListBox *lBox; + TQComboBox *combo; + +}; + +void TQComboBoxData::updateLinedGeometry() +{ + if ( !ed || !combo ) + return; + TQRect r = TQStyle::visualRect( combo->style().querySubControlMetrics(TQStyle::CC_ComboBox, combo, + TQStyle::SC_ComboBoxEditField), combo ); + + const TQPixmap *pix = current < combo->count() ? combo->pixmap( current ) : 0; + if ( pix && pix->width() < r.width() ) + r.setLeft( r.left() + pix->width() + 4 ); + if ( r != ed->geometry() ) + ed->setGeometry( r ); +} + +void TQComboBoxData::setListBox( TQListBox *l ) +{ + lBox = l; + usingLBox = TRUE; + l->setMouseTracking( TRUE ); +#ifdef TQ_WS_X11 + l->x11SetWindowType( TQWidget::X11WindowTypeCombo ); + l->x11SetWindowTransient( combo->topLevelWidget()); +#endif +} + +void TQComboBoxData::setPopupMenu( TQComboBoxPopup * pm, bool isPopup ) +{ + pop = pm; + if(isPopup) + usingLBox = FALSE; +#ifdef TQ_WS_X11 + if( pm ) { + pm->x11SetWindowType( TQWidget::X11WindowTypeCombo ); + pm->x11SetWindowTransient( combo->topLevelWidget()); + } +#endif +} + +static inline bool checkInsertIndex( const char *method, const char * name, + int count, int *index) +{ + bool range_err = (*index > count); +#if defined(QT_CHECK_RANGE) + if ( range_err ) + tqWarning( "TQComboBox::%s: (%s) Index %d out of range", + method, name ? name : "", *index ); +#else + Q_UNUSED( method ) + Q_UNUSED( name ) +#endif + if ( *index < 0 ) // append + *index = count; + return !range_err; +} + + +static inline bool checkIndex( const char *method, const char * name, + int count, int index ) +{ + bool range_err = (index >= count); +#if defined(QT_CHECK_RANGE) + if ( range_err ) + tqWarning( "TQComboBox::%s: (%s) Index %i out of range", + method, name ? name : "", index ); +#else + Q_UNUSED( method ) + Q_UNUSED( name ) +#endif + return !range_err; +} + + + +/*! + Constructs a combobox widget with parent \a parent called \a name. + + This constructor creates a popup list if the program uses Motif + (or Aqua) look and feel; this is compatible with Motif 1.x and + Aqua. + + Note: If you use this constructor to create your TQComboBox, then + the pixmap() function will always return 0. To workaround this, + use the other constructor. + +*/ + + + +TQComboBox::TQComboBox( TQWidget *parent, const char *name ) + : TQWidget( parent, name, WNoAutoErase ) +{ + d = new TQComboBoxData( this ); + if ( style().styleHint(TQStyle::SH_ComboBox_Popup, this) || + style().styleHint(TQStyle::SH_GUIStyle) == TQt::MotifStyle ) { + d->setPopupMenu( new TQComboBoxPopup( this, "in-combo" ) ); + d->popup()->setFont( font() ); + connect( d->popup(), TQ_SIGNAL(activated(int)), + TQ_SLOT(internalActivate(int)) ); + connect( d->popup(), TQ_SIGNAL(highlighted(int)), + TQ_SLOT(internalHighlight(int)) ); + } else { + setUpListBox(); + } + d->ed = 0; + d->current = 0; + d->maxCount = INT_MAX; + d->sizeLimit = 10; + d->p = AtBottom; + d->autoresize = FALSE; + d->poppedUp = FALSE; + d->arrowDown = FALSE; + d->arrowPressed = FALSE; + d->discardNextMousePress = FALSE; + d->shortClick = FALSE; + d->useCompletion = FALSE; + d->completeAt = 0; + d->completeNow = FALSE; + d->completionTimer = new TQTimer( this ); + + setFocusPolicy( TabFocus ); + setBackgroundMode( PaletteButton ); +} + + +/*! + Constructs a combobox with a maximum size and either Motif 2.0 or + Windows look and feel. + + The input field can be edited if \a rw is TRUE, otherwise the user + may only choose one of the items in the combobox. + + The \a parent and \a name arguments are passed on to the TQWidget + constructor. +*/ + + +TQComboBox::TQComboBox( bool rw, TQWidget *parent, const char *name ) + : TQWidget( parent, name, WNoAutoErase ) +{ + d = new TQComboBoxData( this ); + setUpListBox(); + + if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) + d->popup()->setItemChecked(d->current, FALSE); + d->current = 0; + d->maxCount = INT_MAX; + setSizeLimit(10); + d->p = AtBottom; + d->autoresize = FALSE; + d->poppedUp = FALSE; + d->arrowDown = FALSE; + d->discardNextMousePress = FALSE; + d->shortClick = FALSE; + d->useCompletion = FALSE; + d->completeAt = 0; + d->completeNow = FALSE; + d->completionTimer = new TQTimer( this ); + + setFocusPolicy( StrongFocus ); + + d->ed = 0; + if ( rw ) + setUpLineEdit(); + setBackgroundMode( PaletteButton, PaletteBase ); +} + + + +/*! + Destroys the combobox. +*/ + +TQComboBox::~TQComboBox() +{ + delete d; +} + +void TQComboBox::setDuplicatesEnabled( bool enable ) +{ + d->duplicatesEnabled = enable; +} + +bool TQComboBox::duplicatesEnabled() const +{ + return d->duplicatesEnabled; +} + +int TQComboBox::count() const +{ + if ( d->usingListBox() ) + return d->listBox()->count(); + else + return d->popup()->count(); +} + + +/*! + \overload + + Inserts the \a list of strings at position \a index in the + combobox. + + This is only for compatibility since it does not support Unicode + strings. See insertStringList(). +*/ + +void TQComboBox::insertStrList( const TQStrList &list, int index ) +{ + insertStrList( &list, index ); +} + +/*! + \overload + + Inserts the \a list of strings at position \a index in the + combobox. + + This is only for compatibility since it does not support Unicode + strings. See insertStringList(). +*/ + +void TQComboBox::insertStrList( const TQStrList *list, int index ) +{ + if ( !list ) { +#if defined(QT_CHECK_NULL) + Q_ASSERT( list != 0 ); +#endif + return; + } + TQStrListIterator it( *list ); + const char* tmp; + if ( index < 0 ) + index = count(); + while ( (tmp=it.current()) ) { + ++it; + if ( d->usingListBox() ) + d->listBox()->insertItem( TQString::fromLatin1(tmp), index ); + else + d->popup()->insertItem( escapedComboString(TQString::fromLatin1(tmp)), index, index ); + if ( index++ == d->current && d->current < count() ) { + if ( d->ed ) { + d->ed->setText( text( d->current ) ); + d->updateLinedGeometry(); + } else + update(); + currentChanged(); + } + } + if ( index != count() ) + reIndex(); +} + +/*! + Inserts the \a list of strings at position \a index in the + combobox. +*/ + +void TQComboBox::insertStringList( const TQStringList &list, int index ) +{ + TQStringList::ConstIterator it = list.begin(); + if ( index < 0 ) + index = count(); + while ( it != list.end() ) { + if ( d->usingListBox() ) + d->listBox()->insertItem( *it, index ); + else + d->popup()->insertItem( escapedComboString(*it), index, index ); + if ( index++ == d->current && d->current < count() ) { + if ( d->ed ) { + d->ed->setText( text( d->current ) ); + d->updateLinedGeometry(); + } else + update(); + currentChanged(); + } + ++it; + } + if ( index != count() ) + reIndex(); +} + +/*! + Inserts the array of char * \a strings at position \a index in the + combobox. + + The \a numStrings argument is the number of strings. If \a + numStrings is -1 (default), the \a strings array must be + terminated with 0. + + Example: + \code + static const char* items[] = { "red", "green", "blue", 0 }; + combo->insertStrList( items ); + \endcode + + \sa insertStringList() +*/ + +void TQComboBox::insertStrList( const char **strings, int numStrings, int index) +{ + if ( !strings ) { +#if defined(QT_CHECK_NULL) + Q_ASSERT( strings != 0 ); +#endif + return; + } + if ( index < 0 ) + index = count(); + int i = 0; + while ( (numStrings<0 && strings[i]!=0) || iusingListBox() ) + d->listBox()->insertItem( TQString::fromLatin1(strings[i]), index ); + else + d->popup()->insertItem( escapedComboString(TQString::fromLatin1(strings[i])), index, index ); + i++; + if ( index++ == d->current && d->current < count() ) { + if ( d->ed ) { + d->ed->setText( text( d->current ) ); + d->updateLinedGeometry(); + } else + update(); + currentChanged(); + } + } + if ( index != count() ) + reIndex(); +} + + +/*! + Inserts a text item with text \a t, at position \a index. The item + will be appended if \a index is negative. +*/ + +void TQComboBox::insertItem( const TQString &t, int index ) +{ + int cnt = count(); + if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) ) + return; + if ( d->usingListBox() ) + d->listBox()->insertItem( t, index ); + else + d->popup()->insertItem( escapedComboString(t), index, index ); + if ( index != cnt ) + reIndex(); + if ( index == d->current && d->current < count() ) { + if ( d->ed ) { + d->ed->setText( text( d->current ) ); + d->updateLinedGeometry(); + } else + update(); + } + if ( index == d->current ) + currentChanged(); +} + +/*! + \overload + + Inserts a \a pixmap item at position \a index. The item will be + appended if \a index is negative. +*/ + +void TQComboBox::insertItem( const TQPixmap &pixmap, int index ) +{ + int cnt = count(); + if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) ) + return; + if ( d->usingListBox() ) + d->listBox()->insertItem( pixmap, index ); + else + d->popup()->insertItem( pixmap, index, index ); + if ( index != cnt ) + reIndex(); + if ( index == d->current && d->current < count() ) { + if ( d->ed ) { + d->ed->setText( text( d->current ) ); + d->updateLinedGeometry(); + } else + update(); + } + if ( index == d->current ) + currentChanged(); +} + +/*! + \overload + + Inserts a \a pixmap item with additional text \a text at position + \a index. The item will be appended if \a index is negative. +*/ + +void TQComboBox::insertItem( const TQPixmap &pixmap, const TQString& text, int index ) +{ + int cnt = count(); + if ( !checkInsertIndex( "insertItem", name(), cnt, &index ) ) + return; + if ( d->usingListBox() ) + d->listBox()->insertItem( pixmap, text, index ); + else + d->popup()->insertItem( pixmap, escapedComboString(text), index, index ); + if ( index != cnt ) + reIndex(); + if ( index == d->current && d->current < count() ) { + if ( d->ed ) { + d->ed->setText( this->text( d->current ) ); + d->updateLinedGeometry(); + } else + update(); + } + if ( index == d->current ) + currentChanged(); +} + + +/*! + Removes the item at position \a index. +*/ + +void TQComboBox::removeItem( int index ) +{ + int cnt = count(); + if ( !checkIndex( "removeItem", name(), cnt, index ) ) + return; + if ( d->usingListBox() ) { + if ( style().styleHint(TQStyle::SH_ComboBox_Popup, this) && d->popup() ) + d->popup()->removeItemAt( index ); + d->listBox()->removeItem( index ); + } else { + d->popup()->removeItemAt( index ); + } + if ( index != cnt-1 ) + reIndex(); + if ( index == d->current ) { + if ( d->ed ) { + TQString s = TQString::fromLatin1(""); + if (d->current < cnt - 1) + s = text( d->current ); + d->ed->setText( s ); + d->updateLinedGeometry(); + } + else { + if ( d->usingListBox() ) { + d->current = d->listBox()->currentItem(); + } else { + if (d->current > count()-1 && d->current > 0) + d->current--; + } + update(); + } + currentChanged(); + } + else { + if ( !d->ed ) { + if (d->current < cnt - 1) + setCurrentItem( d->current ); + else + setCurrentItem( d->current - 1 ); + } + } + +} + + +/*! + Removes all combobox items. +*/ + +void TQComboBox::clear() +{ + if ( d->usingListBox() ) { + if ( style().styleHint(TQStyle::SH_ComboBox_Popup, this) && d->popup() ) + d->popup()->clear(); + d->listBox()->resize( 0, 0 ); + d->listBox()->clear(); + } else { + d->popup()->clear(); + } + + if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) + d->popup()->setItemChecked(d->current, FALSE); + d->current = 0; + if ( d->ed ) { + d->ed->setText( TQString::fromLatin1("") ); + d->updateLinedGeometry(); + } + currentChanged(); +} + + +TQString TQComboBox::currentText() const +{ + if ( d->ed ) + return d->ed->text(); + else if ( d->current < count() ) + return text( currentItem() ); + else + return TQString::null; +} + +void TQComboBox::setCurrentText( const TQString& txt ) +{ + int i; + for ( i = 0; i < count(); i++) + if ( text( i ) == txt ) + break; + if ( i < count() ) + setCurrentItem( i ); + else if ( d->ed ) + d->ed->setText( txt ); + else + changeItem( txt, currentItem() ); +} + + +/*! + Returns the text item at position \a index, or TQString::null if + the item is not a string. + + \sa currentText() +*/ + +TQString TQComboBox::text( int index ) const +{ + if ( !checkIndex( "text", name(), count(), index ) ) + return TQString::null; + if ( d->usingListBox() ) { + return d->listBox()->text( index ); + } else { + TQString retText = d->popup()->text(index); + retText.replace("&&", "&"); + return retText; + } +} + +/*! + Returns the pixmap item at position \a index, or 0 if the item is + not a pixmap. +*/ + +const TQPixmap *TQComboBox::pixmap( int index ) const +{ + if ( !checkIndex( "pixmap", name(), count(), index ) ) + return 0; + if ( d->usingListBox() ) + return d->listBox()->pixmap( index ); + else + return d->popup()->pixmap( index ); +} + +/*! + Replaces the item at position \a index with the text \a t. +*/ + +void TQComboBox::changeItem( const TQString &t, int index ) +{ + if ( !checkIndex( "changeItem", name(), count(), index ) ) + return; + if ( d->usingListBox() ) + d->listBox()->changeItem( t, index ); + else + d->popup()->changeItem( t, index ); + if ( index == d->current ) { + if ( d->ed ) { + d->ed->setText( text( d->current ) ); + d->updateLinedGeometry(); + } else + update(); + } +} + +/*! + \overload + + Replaces the item at position \a index with the pixmap \a im, + unless the combobox is editable. + + \sa insertItem() +*/ + +void TQComboBox::changeItem( const TQPixmap &im, int index ) +{ + if ( !checkIndex( "changeItem", name(), count(), index ) ) + return; + if ( d->usingListBox() ) + d->listBox()->changeItem( im, index ); + else + d->popup()->changeItem( im, index ); + if ( index == d->current ) + update(); +} + +/*! + \overload + + Replaces the item at position \a index with the pixmap \a im and + the text \a t. + + \sa insertItem() +*/ + +void TQComboBox::changeItem( const TQPixmap &im, const TQString &t, int index ) +{ + if ( !checkIndex( "changeItem", name(), count(), index ) ) + return; + if ( d->usingListBox() ) + d->listBox()->changeItem( im, t, index ); + else + d->popup()->changeItem( im, t, index ); + if ( index == d->current ) + update(); +} + + +int TQComboBox::currentItem() const +{ + return d->current; +} + +void TQComboBox::setCurrentItem( int index ) +{ + if ( index == d->current && !d->ed ) { + return; + } + if ( !checkIndex( "setCurrentItem", name(), count(), index ) ) { + return; + } + + if ( d->usingListBox() && !( listBox()->item(index) && listBox()->item(index)->isSelectable() ) ) + return; + + if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) + d->popup()->setItemChecked(d->current, FALSE); + d->current = index; + d->completeAt = 0; + if ( d->ed ) { + d->ed->setText( text( index ) ); + d->updateLinedGeometry(); + } + // ### We want to keep ListBox's currentItem in sync, even if NOT popuped... + if ( d->usingListBox() && d->listBox() ) { + d->listBox()->setCurrentItem( index ); + } else { + internalHighlight( index ); + // internalActivate( index ); ### this leads to weird behavior, as in 3.0.1 + } + + currentChanged(); +} + +bool TQComboBox::autoResize() const +{ + return d->autoresize; +} + +void TQComboBox::setAutoResize( bool enable ) +{ + if ( (bool)d->autoresize != enable ) { + d->autoresize = enable; + if ( enable ) + adjustSize(); + } +} + + +/*! + \reimp + + This implementation caches the size hint to avoid resizing when + the contents change dynamically. To invalidate the cached value + call setFont(). +*/ +TQSize TQComboBox::sizeHint() const +{ + if ( isVisible() && d->sizeHint.isValid() ) + return d->sizeHint; + + constPolish(); + int i, w; + TQFontMetrics fm = fontMetrics(); + + int maxW = count() ? 18 : 7 * fm.width(TQChar('x')) + 18; + int maxH = TQMAX( fm.lineSpacing(), 14 ) + 2; + + if ( !d->usingListBox() ) { + w = d->popup()->sizeHint().width() - 2* d->popup()->frameWidth(); + if ( w > maxW ) + maxW = w; + } else { + for( i = 0; i < count(); i++ ) { + w = d->listBox()->item( i )->width( d->listBox() ); + if ( w > maxW ) + maxW = w; + } + } + + d->sizeHint = (style().sizeFromContents(TQStyle::CT_ComboBox, this, + TQSize(maxW, maxH)). + expandedTo(TQApplication::globalStrut())); + + return d->sizeHint; +} + + +/*! + \internal + Receives activated signals from an internal popup list and emits + the activated() signal. +*/ + +void TQComboBox::internalActivate( int index ) +{ + if ( d->current != index ) { + if ( !d->usingListBox() || listBox()->item( index )->isSelectable() ) { + if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) + d->popup()->setItemChecked(d->current, FALSE); + d->current = index; + currentChanged(); + } + } + if ( d->usingListBox() ) + popDownListBox(); + else + d->popup()->removeEventFilter( this ); + d->poppedUp = FALSE; + + TQString t( text( index ) ); + if ( d->ed ) { + d->ed->setText( t ); + d->updateLinedGeometry(); + } + emit activated( index ); + emit activated( t ); +} + +/*! + \internal + Receives highlighted signals from an internal popup list and emits + the highlighted() signal. +*/ + +void TQComboBox::internalHighlight( int index ) +{ + emit highlighted( index ); + TQString t = text( index ); + if ( !t.isNull() ) + emit highlighted( t ); +} + +/*! + \internal + Receives timeouts after a click. Used to decide if a Motif style + popup should stay up or not after a click. +*/ +void TQComboBox::internalClickTimeout() +{ + d->shortClick = FALSE; +} + +/*! + Sets the palette for both the combobox button and the combobox + popup list to \a palette. +*/ + +void TQComboBox::setPalette( const TQPalette &palette ) +{ + TQWidget::setPalette( palette ); + if ( d->listBox() ) + d->listBox()->setPalette( palette ); + if ( d->popup() ) + d->popup()->setPalette( palette ); +} + +/*! + Sets the font for both the combobox button and the combobox popup + list to \a font. +*/ + +void TQComboBox::setFont( const TQFont &font ) +{ + d->sizeHint = TQSize(); // invalidate size hint + TQWidget::setFont( font ); + if ( d->usingListBox() ) + d->listBox()->setFont( font ); + else + d->popup()->setFont( font ); + if (d->ed) + d->ed->setFont( font ); + if ( d->autoresize ) + adjustSize(); +} + + +/*!\reimp +*/ + +void TQComboBox::resizeEvent( TQResizeEvent * e ) +{ + if ( d->ed ) + d->updateLinedGeometry(); + if ( d->listBox() ) + d->listBox()->resize( width(), d->listBox()->height() ); + TQWidget::resizeEvent( e ); +} + +/*!\reimp +*/ + +void TQComboBox::paintEvent( TQPaintEvent * ) +{ + TQPainter p( this ); + const TQColorGroup & g = colorGroup(); + p.setPen(g.text()); + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasFocus()) + flags |= TQStyle::Style_HasFocus; + if (hasMouse()) + flags |= TQStyle::Style_MouseOver; + + if ( width() < 5 || height() < 5 ) { + qDrawShadePanel( &p, rect(), g, FALSE, 2, + &g.brush( TQColorGroup::Button ) ); + return; + } + + bool reverse = TQApplication::reverseLayout(); + if ( !d->usingListBox() && + style().styleHint(TQStyle::SH_GUIStyle) == TQt::MotifStyle) { // motif 1.x style + int dist, buttonH, buttonW; + dist = 8; + buttonH = 7; + buttonW = 11; + int xPos; + int x0; + int w = width() - dist - buttonW - 1; + if ( reverse ) { + xPos = dist + 1; + x0 = xPos + 4; + } else { + xPos = w; + x0 = 4; + } + qDrawShadePanel( &p, rect(), g, FALSE, + style().pixelMetric(TQStyle::PM_DefaultFrameWidth, this), + &g.brush( TQColorGroup::Button ) ); + qDrawShadePanel( &p, xPos, (height() - buttonH)/2, + buttonW, buttonH, g, FALSE, + style().pixelMetric(TQStyle::PM_DefaultFrameWidth, this) ); + TQRect clip( x0, 2, w - 2 - 4 - 5, height() - 4 ); + TQString str = d->popup()->text( this->d->current ); + if ( !str.isNull() ) { + p.drawText( clip, AlignCenter | SingleLine, str ); + } + + TQPixmap *pix = d->popup()->pixmap( this->d->current ); + TQIconSet *iconSet = d->popup()->iconSet( this->d->current ); + if (pix || iconSet) { + TQPixmap pm = ( pix ? *pix : iconSet->pixmap() ); + p.setClipRect( clip ); + p.drawPixmap( 4, (height()-pm.height())/2, pm ); + p.setClipping( FALSE ); + } + + if ( hasFocus() ) + p.drawRect( xPos - 5, 4, width() - xPos + 1 , height() - 8 ); + } else if(!d->usingListBox()) { + style().drawComplexControl( TQStyle::CC_ComboBox, &p, this, rect(), g, + flags, (uint)TQStyle::SC_All, + (d->arrowDown ? + TQStyle::SC_ComboBoxArrow : + TQStyle::SC_None )); + + TQRect re = style().querySubControlMetrics( TQStyle::CC_ComboBox, this, + TQStyle::SC_ComboBoxEditField ); + re = TQStyle::visualRect(re, this); + p.setClipRect( re ); + + TQString str = d->popup()->text( this->d->current ); + TQPixmap *pix = d->popup()->pixmap( this->d->current ); + if ( !str.isNull() ) { + p.save(); + p.setFont(font()); + TQFontMetrics fm(font()); + int x = re.x(), y = re.y() + fm.ascent(); + if( pix ) + x += pix->width() + 5; + p.drawText( x, y, str ); + p.restore(); + } + if ( pix ) { + p.fillRect( re.x(), re.y(), pix->width() + 4, re.height(), + colorGroup().brush( TQColorGroup::Base ) ); + p.drawPixmap( re.x() + 2, re.y() + + ( re.height() - pix->height() ) / 2, *pix ); + } + } else { + style().drawComplexControl( TQStyle::CC_ComboBox, &p, this, rect(), g, + flags, (uint)TQStyle::SC_All, + (d->arrowDown ? + TQStyle::SC_ComboBoxArrow : + TQStyle::SC_None )); + + TQRect re = style().querySubControlMetrics( TQStyle::CC_ComboBox, this, + TQStyle::SC_ComboBoxEditField ); + re = TQStyle::visualRect(re, this); + p.setClipRect( re ); + + if ( !d->ed ) { + TQListBoxItem * item = d->listBox()->item( d->current ); + if ( item ) { + int itemh = item->height( d->listBox() ); + p.translate( re.x(), re.y() + (re.height() - itemh)/2 ); + item->paint( &p ); + } + } else if ( d->listBox() && d->listBox()->item( d->current ) ) { + TQListBoxItem * item = d->listBox()->item( d->current ); + const TQPixmap *pix = item->pixmap(); + if ( pix ) { + p.fillRect( re.x(), re.y(), pix->width() + 4, re.height(), + colorGroup().brush( TQColorGroup::Base ) ); + p.drawPixmap( re.x() + 2, re.y() + + ( re.height() - pix->height() ) / 2, *pix ); + } + } + p.setClipping( FALSE ); + } +} + + +/*!\reimp +*/ + +void TQComboBox::mousePressEvent( TQMouseEvent *e ) +{ + if ( e->button() != LeftButton ) + return; + if ( d->discardNextMousePress ) { + d->discardNextMousePress = FALSE; + return; + } + TQRect arrowRect = style().querySubControlMetrics( TQStyle::CC_ComboBox, this, + TQStyle::SC_ComboBoxArrow); + arrowRect = TQStyle::visualRect(arrowRect, this); + + // Correction for motif style, where arrow is smaller + // and thus has a rect that doesn't fit the button. + arrowRect.setHeight( TQMAX( height() - (2 * arrowRect.y()), arrowRect.height() ) ); + + if ( count() && ( !editable() || arrowRect.contains( e->pos() ) ) ) { + d->arrowPressed = FALSE; + + if ( d->usingListBox() ) { + listBox()->blockSignals( TRUE ); + tqApp->sendEvent( listBox(), e ); // trigger the listbox's autoscroll + listBox()->setCurrentItem(d->current); + listBox()->blockSignals( FALSE ); + popup(); + if ( arrowRect.contains( e->pos() ) ) { + d->arrowPressed = TRUE; + d->arrowDown = TRUE; + repaint( FALSE ); + } + } else { + popup(); + } + TQTimer::singleShot( 200, this, TQ_SLOT(internalClickTimeout())); + d->shortClick = TRUE; + } +} + +/*!\reimp +*/ + +void TQComboBox::mouseMoveEvent( TQMouseEvent * ) +{ +} + +/*!\reimp +*/ + +void TQComboBox::mouseReleaseEvent( TQMouseEvent * ) +{ +} + +/*!\reimp +*/ + +void TQComboBox::mouseDoubleClickEvent( TQMouseEvent *e ) +{ + mousePressEvent( e ); +} + + +/*!\reimp +*/ + +void TQComboBox::keyPressEvent( TQKeyEvent *e ) +{ + int c = currentItem(); + if ( ( e->key() == Key_F4 && e->state() == 0 ) || + ( e->key() == Key_Down && (e->state() & AltButton) ) || + ( !d->ed && e->key() == Key_Space ) ) { + if ( count() ) { + if ( !d->usingListBox() ) + d->popup()->setActiveItem( this->d->current ); + popup(); + } + return; + } else if ( d->usingListBox() && e->key() == Key_Up ) { + if ( c > 0 ) + setCurrentItem( c-1 ); + } else if ( d->usingListBox() && e->key() == Key_Down ) { + if ( ++c < count() ) + setCurrentItem( c ); + } else if ( d->usingListBox() && e->key() == Key_Home && ( !d->ed || !d->ed->hasFocus() ) ) { + setCurrentItem( 0 ); + } else if ( d->usingListBox() && e->key() == Key_End && ( !d->ed || !d->ed->hasFocus() ) ) { + setCurrentItem( count()-1 ); + } else if ( !d->ed && e->ascii() >= 32 && !e->text().isEmpty() ) { + if ( !d->completionTimer->isActive() ) { + d->completeAt = 0; + c = completionIndex( e->text(), ++c ); + if ( c >= 0 ) { + setCurrentItem( c ); + d->completeAt = e->text().length(); + } + } else { + d->completionTimer->stop(); + TQString ct = currentText().left( d->completeAt ) + e->text(); + c = completionIndex( ct, c ); + if ( c < 0 && d->completeAt > 0 ) { + c = completionIndex( e->text(), 0 ); + ct = e->text(); + } + d->completeAt = 0; + if ( c >= 0 ) { + setCurrentItem( c ); + d->completeAt = ct.length(); + } + } + d->completionTimer->start( 400, TRUE ); + } else { + e->ignore(); + return; + } + + c = currentItem(); + if ( count() && !text( c ).isNull() ) + emit activated( text( c ) ); + emit activated( c ); +} + + +/*!\reimp +*/ + +void TQComboBox::focusInEvent( TQFocusEvent * e ) +{ + TQWidget::focusInEvent( e ); + d->completeNow = FALSE; + d->completeAt = 0; +} + +/*!\reimp +*/ + +void TQComboBox::focusOutEvent( TQFocusEvent * e ) +{ + TQWidget::focusOutEvent( e ); + d->completeNow = FALSE; + d->completeAt = 0; +} + +/*!\reimp +*/ +#ifndef TQT_NO_WHEELEVENT +void TQComboBox::wheelEvent( TQWheelEvent *e ) +{ + if ( d->poppedUp ) { + if ( d->usingListBox() ) { + TQApplication::sendEvent( d->listBox(), e ); + } + } else { + if ( e->delta() > 0 ) { + int c = currentItem(); + if ( c > 0 ) { + setCurrentItem( c-1 ); + emit activated( currentItem() ); + emit activated( currentText() ); + } + } else { + int c = currentItem(); + if ( ++c < count() ) { + setCurrentItem( c ); + emit activated( currentItem() ); + emit activated( currentText() ); + } + } + e->accept(); + } +} +#endif + +/*! + \internal + Calculates the listbox height needed to contain all items, or as + many as the list box is supposed to contain. +*/ +static int listHeight( TQListBox *l, int sl ) +{ + if ( l->count() > 0 ) + return TQMIN( l->count(), (uint)sl) * l->item( 0 )->height(l); + else + return l->sizeHint().height(); +} + + +/*! + Pops up the combobox popup list. + + If the list is empty, no items appear. +*/ + +void TQComboBox::popup() +{ + if ( !count() || d->poppedUp ) + return; + + if( !d->usingListBox() || style().styleHint(TQStyle::SH_ComboBox_Popup, this) ) { + if(d->usingListBox()) { + if(!d->popup()) { + TQComboBoxPopup *p = new TQComboBoxPopup( this, "in-combo" ); + d->setPopupMenu( p, FALSE ); + p->setFont( font() ); + connect( p, TQ_SIGNAL(activated(int)), TQ_SLOT(internalActivate(int)) ); + connect( p, TQ_SIGNAL(highlighted(int)), TQ_SLOT(internalHighlight(int)) ); + } + d->popup()->clear(); + for(unsigned int i = 0; i < d->listBox()->count(); i++) { + TQListBoxItem *item = d->listBox()->item(i); + if(item->rtti() == TQListBoxText::RTTI) { + d->popup()->insertItem(escapedComboString(item->text()), i, i); + } else if(item->rtti() == TQListBoxPixmap::RTTI) { + if(item->pixmap()) + d->popup()->insertItem(TQIconSet(*item->pixmap()), escapedComboString(item->text()), i, i); + else + d->popup()->insertItem(escapedComboString(item->text()), i, i); + } else { + d->popup()->insertItem(new TQComboBoxPopupItem(item), i, i); + } + } + } + d->popup()->installEventFilter( this ); + if(d->popup() && style().styleHint(TQStyle::SH_ComboBox_Popup, this)) + d->popup()->setItemChecked(this->d->current, TRUE); + d->popup()->popup( mapToGlobal( TQPoint(0,0) ), this->d->current ); + update(); + } else { + // Send all listbox events to eventFilter(): + TQListBox* lb = d->listBox(); + lb->triggerUpdate( TRUE ); + lb->installEventFilter( this ); + d->mouseWasInsidePopup = FALSE; + int w = lb->variableWidth() ? lb->sizeHint().width() : width(); + int h = listHeight( lb, d->sizeLimit ) + 2; + TQRect screen = TQApplication::desktop()->availableGeometry( this ); + + int sx = screen.x(); // screen pos + int sy = screen.y(); + int sw = screen.width(); // screen width + int sh = screen.height(); // screen height + TQPoint pos = mapToGlobal( TQPoint(0,height()) ); + // ## Similar code is in TQPopupMenu + int x = pos.x(); + int y = pos.y(); + + // the complete widget must be visible + if ( x + w > sx + sw ) + x = sx+sw - w; + if ( x < sx ) + x = sx; + if (y + h > sy+sh && y - h - height() >= 0 ) + y = y - h - height(); + + TQRect rect = + style().querySubControlMetrics( TQStyle::CC_ComboBox, this, + TQStyle::SC_ComboBoxListBoxPopup, + TQStyleOption( x, y, w, h ) ); + // work around older styles that don't implement the combobox + // listbox popup subcontrol + if ( rect.isNull() ) + rect.setRect( x, y, w, h ); + lb->setGeometry( rect ); + + lb->raise(); + bool block = lb->signalsBlocked(); + lb->blockSignals( TRUE ); + TQListBoxItem* currentLBItem = 0; + if ( editable() && currentText() != text( currentItem() ) ) + currentLBItem = lb->findItem( currentText() ); + + currentLBItem = currentLBItem ? currentLBItem : lb->item( d->current ); + + lb->setCurrentItem( currentLBItem ); + lb->setContentsPos( lb->contentsX(), + lb->viewportToContents( lb->itemRect( currentLBItem ).topLeft() ).y() ); + + // set the current item to also be the selected item if it isn't already + if ( currentLBItem && currentLBItem->isSelectable() && !currentLBItem->isSelected() ) + lb->setSelected( currentLBItem, TRUE ); + lb->blockSignals( block ); + lb->setVScrollBarMode(TQScrollView::Auto); + +#ifndef TQT_NO_EFFECTS + if ( TQApplication::isEffectEnabled( UI_AnimateCombo ) ) { + if ( lb->y() < mapToGlobal(TQPoint(0,0)).y() ) + qScrollEffect( lb, TQEffects::UpScroll ); + else + qScrollEffect( lb ); + } else +#endif + lb->show(); + } + d->poppedUp = TRUE; +} + + +/*! + \reimp +*/ +void TQComboBox::updateMask() +{ + TQBitmap bm( size() ); + bm.fill( color0 ); + + { + TQPainter p( &bm, this ); + style().drawComplexControlMask(TQStyle::CC_ComboBox, &p, this, rect()); + } + + setMask( bm ); +} + +/*! + \internal + Pops down (removes) the combobox popup list box. +*/ +void TQComboBox::popDownListBox() +{ + Q_ASSERT( d->usingListBox() ); + d->listBox()->removeEventFilter( this ); + d->listBox()->viewport()->removeEventFilter( this ); + d->listBox()->hide(); + d->listBox()->setCurrentItem( d->current ); + if ( d->arrowDown ) { + d->arrowDown = FALSE; + repaint( FALSE ); + } + d->poppedUp = FALSE; + + update(); +} + + +/*! + \internal + Re-indexes the identifiers in the popup list. +*/ + +void TQComboBox::reIndex() +{ + if ( !d->usingListBox() ) { + int cnt = count(); + while ( cnt-- ) + d->popup()->setId( cnt, cnt ); + } +} + +/*! + \internal + Repaints the combobox. +*/ + +void TQComboBox::currentChanged() +{ + if ( d->autoresize ) + adjustSize(); + update(); + +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif +} + +/*! \reimp + + \internal + + The event filter steals events from the popup or listbox when they + are popped up. It makes the popup stay up after a short click in + motif style. In windows style it toggles the arrow button of the + combobox field, and activates an item and takes down the listbox + when the mouse button is released. +*/ + +bool TQComboBox::eventFilter( TQObject *object, TQEvent *event ) +{ + if ( !event ) + return TRUE; + else if ( object == d->ed ) { + if ( event->type() == TQEvent::KeyPress ) { + bool isAccepted = ( (TQKeyEvent*)event )->isAccepted(); + keyPressEvent( (TQKeyEvent *)event ); + if ( ((TQKeyEvent *)event)->isAccepted() ) { + d->completeNow = FALSE; + return TRUE; + } else if ( ((TQKeyEvent *)event)->key() != Key_End ) { + d->completeNow = TRUE; + d->completeAt = d->ed->cursorPosition(); + } + if ( isAccepted ) + ( (TQKeyEvent*)event )->accept(); + else + ( (TQKeyEvent*)event )->ignore(); + } else if ( event->type() == TQEvent::KeyRelease ) { + keyReleaseEvent( (TQKeyEvent *)event ); + return ((TQKeyEvent *)event)->isAccepted(); + } else if ( event->type() == TQEvent::FocusIn ) { + focusInEvent( (TQFocusEvent *)event ); + } else if ( event->type() == TQEvent::FocusOut ) { + focusOutEvent( (TQFocusEvent *)event ); + } else if ( d->useCompletion && d->completeNow ) { + d->completeNow = FALSE; + if ( !d->ed->text().isNull() && + d->ed->cursorPosition() > d->completeAt && + d->ed->cursorPosition() == (int)d->ed->text().length() ) { + TQString ct( d->ed->text() ); + int i = completionIndex( ct, currentItem() ); + if ( i > -1 ) { + TQString it = text( i ); + d->ed->validateAndSet( it, ct.length(), + ct.length(), it.length() ); + d->current = i; + // ### sets current item without emitting signals. This is to + // make sure the right item is current if you change current with + // wheel/up/down. While typing current is not valid anyway. Fix properly + // in 4.0. + } + } + } + } else if ( d->usingListBox() && ( object == d->listBox() || + object == d->listBox()->viewport() )) { + TQMouseEvent *e = (TQMouseEvent*)event; + switch( event->type() ) { + case TQEvent::MouseMove: + if ( !d->mouseWasInsidePopup ) { + TQPoint pos = e->pos(); + if ( d->listBox()->rect().contains( pos ) ) + d->mouseWasInsidePopup = TRUE; + // Check if arrow button should toggle + if ( d->arrowPressed ) { + TQPoint comboPos; + comboPos = mapFromGlobal( d->listBox()->mapToGlobal(pos) ); + TQRect arrowRect = + style().querySubControlMetrics( TQStyle::CC_ComboBox, this, + TQStyle::SC_ComboBoxArrow); + arrowRect = TQStyle::visualRect(arrowRect, this); + if ( arrowRect.contains( comboPos ) ) { + if ( !d->arrowDown ) { + d->arrowDown = TRUE; + repaint( FALSE ); + } + } else { + if ( d->arrowDown ) { + d->arrowDown = FALSE; + repaint( FALSE ); + } + } + } + } else if ((e->state() & ( RightButton | LeftButton | MidButton ) ) == 0 && + style().styleHint(TQStyle::SH_ComboBox_ListMouseTracking, this)) { + TQWidget *mouseW = TQApplication::widgetAt( e->globalPos(), TRUE ); + if ( mouseW == d->listBox()->viewport() ) { //### + TQMouseEvent m( TQEvent::MouseMove, e->pos(), e->globalPos(), + LeftButton, LeftButton ); + TQApplication::sendEvent( object, &m ); //### Evil + return TRUE; + } + } + + break; + case TQEvent::MouseButtonRelease: + if ( d->listBox()->rect().contains( e->pos() ) ) { + TQMouseEvent tmp( TQEvent::MouseButtonDblClick, + e->pos(), e->button(), e->state() ) ; + // will hide popup + TQApplication::sendEvent( object, &tmp ); + return TRUE; + } else { + if ( d->mouseWasInsidePopup ) { + popDownListBox(); + } else { + d->arrowPressed = FALSE; + if ( d->arrowDown ) { + d->arrowDown = FALSE; + repaint( FALSE ); + } + } + } + break; + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseButtonPress: + if ( !d->listBox()->rect().contains( e->pos() ) ) { + TQPoint globalPos = d->listBox()->mapToGlobal(e->pos()); + if ( TQApplication::widgetAt( globalPos, TRUE ) == this ) { + d->discardNextMousePress = TRUE; + // avoid popping up again + } + popDownListBox(); + return TRUE; + } + break; + case TQEvent::KeyPress: + switch( ((TQKeyEvent *)event)->key() ) { + case Key_Up: + case Key_Down: + if ( !(((TQKeyEvent *)event)->state() & AltButton) ) + break; + case Key_F4: + case Key_Escape: + if ( d->poppedUp ) { + popDownListBox(); + return TRUE; + } + break; + case Key_Enter: + case Key_Return: + // work around TQDialog's enter handling + return FALSE; + default: + break; + } + break; + case TQEvent::Hide: + popDownListBox(); + break; + default: + break; + } + } else if ( (!d->usingListBox() || style().styleHint(TQStyle::SH_ComboBox_Popup, this)) && + object == d->popup() ) { + TQMouseEvent *e = (TQMouseEvent*)event; + switch ( event->type() ) { + case TQEvent::MouseButtonRelease: + if ( d->shortClick ) { + TQMouseEvent tmp( TQEvent::MouseMove, + e->pos(), e->button(), e->state() ) ; + // highlight item, but don't pop down: + TQApplication::sendEvent( object, &tmp ); + return TRUE; + } + break; + case TQEvent::MouseButtonDblClick: + case TQEvent::MouseButtonPress: + if ( !d->popup()->rect().contains( e->pos() ) ) { + d->poppedUp = FALSE; + d->arrowDown = FALSE; + // remove filter, event will take down popup: + d->popup()->removeEventFilter( this ); + // ### uglehack! + // call internalHighlight so the highlighed signal + // will be emitted at least as often as necessary. + // it may be called more often than necessary + internalHighlight( d->current ); + } + break; + case TQEvent::Hide: + d->poppedUp = FALSE; + break; + default: + break; + } + } + return TQWidget::eventFilter( object, event ); +} + + +/*! + Returns the index of the first item \e after \a startingAt of + which \a prefix is a case-insensitive prefix. Returns -1 if no + items start with \a prefix. +*/ + +int TQComboBox::completionIndex( const TQString & prefix, + int startingAt = 0 ) const +{ + int start = startingAt; + if ( start < 0 || start >= count() ) + start = 0; + if ( start >= count() ) + return -1; + TQString match = prefix.lower(); + if ( match.length() < 1 ) + return start; + + TQString current; + int i = start; + do { + current = text( i ).lower(); + if ( current.startsWith( match ) ) + return i; + i++; + if ( i == count() ) + i = 0; + } while ( i != start ); + return -1; +} + + +int TQComboBox::sizeLimit() const +{ + return d ? d->sizeLimit : INT_MAX; +} + +void TQComboBox::setSizeLimit( int lines ) +{ + d->sizeLimit = lines; +} + + +int TQComboBox::maxCount() const +{ + return d ? d->maxCount : INT_MAX; +} + +void TQComboBox::setMaxCount( int count ) +{ + int l = this->count(); + while( --l > count ) + removeItem( l ); + d->maxCount = count; +} + +TQComboBox::Policy TQComboBox::insertionPolicy() const +{ + return d->p; +} + +void TQComboBox::setInsertionPolicy( Policy policy ) +{ + d->p = policy; +} + + + +/*! + Internal slot to keep the line editor up to date. +*/ + +void TQComboBox::returnPressed() +{ + TQString s( d->ed->text() ); + + if ( s.isEmpty() ) + return; + + int c = 0; + bool doInsert = TRUE; + if ( !d->duplicatesEnabled ) { + for ( int i = 0; i < count(); ++i ) { + if ( s == text( i ) ) { + doInsert = FALSE; + c = i; + break; + } + } + } + + if ( doInsert ) { + if ( insertionPolicy() != NoInsertion ) { + int cnt = count(); + while ( cnt >= d->maxCount ) { + removeItem( --cnt ); + } + } + + switch ( insertionPolicy() ) { + case AtCurrent: + if (count() == 0) + insertItem(s); + else if ( s != text( currentItem() ) ) + changeItem( s, currentItem() ); + emit activated( currentItem() ); + emit activated( s ); + return; + case NoInsertion: + emit activated( s ); + return; + case AtTop: + c = 0; + break; + case AtBottom: + c = count(); + break; + case BeforeCurrent: + c = currentItem(); + break; + case AfterCurrent: + c = count() == 0 ? 0 : currentItem() + 1; + break; + } + insertItem( s, c ); + } + + setCurrentItem( c ); + emit activated( c ); + emit activated( s ); +} + + +/*! \reimp +*/ + +void TQComboBox::setEnabled( bool enable ) +{ + if ( !enable ) { + if ( d->usingListBox() ) { + popDownListBox(); + } else { + d->popup()->removeEventFilter( this ); + d->popup()->close(); + d->poppedUp = FALSE; + } + } + TQWidget::setEnabled( enable ); +} + + + +/*! + Applies the validator \a v to the combobox so that only text which + is valid according to \a v is accepted. + + This function does nothing if the combobox is not editable. + + \sa validator() clearValidator() TQValidator +*/ + +void TQComboBox::setValidator( const TQValidator * v ) +{ + if ( d && d->ed ) + d->ed->setValidator( v ); +} + + +/*! + Returns the validator which constrains editing for this combobox + if there is one; otherwise returns 0. + + \sa setValidator() clearValidator() TQValidator +*/ + +const TQValidator * TQComboBox::validator() const +{ + return d && d->ed ? d->ed->validator() : 0; +} + + +/*! + This slot is equivalent to setValidator( 0 ). +*/ + +void TQComboBox::clearValidator() +{ + if ( d && d->ed ) + d->ed->setValidator( 0 ); +} + + +/*! + Sets the combobox to use \a newListBox instead of the current list + box or popup. As a side effect, it clears the combobox of its + current contents. + + \warning TQComboBox assumes that newListBox->text(n) returns + non-null for 0 \<= n \< newListbox->count(). This assumption is + necessary because of the line edit in TQComboBox. +*/ + +void TQComboBox::setListBox( TQListBox * newListBox ) +{ + clear(); + + if ( d->usingListBox() ) { + delete d->listBox(); + } else { + delete d->popup(); + d->setPopupMenu(0, FALSE); + } + + newListBox->reparent( this, WType_Popup, TQPoint(0,0), FALSE ); + d->setListBox( newListBox ); + d->listBox()->setFont( font() ); + d->listBox()->setPalette( palette() ); + d->listBox()->setVScrollBarMode(TQScrollView::AlwaysOff); + d->listBox()->setHScrollBarMode(TQScrollView::AlwaysOff); + d->listBox()->setFrameStyle( TQFrame::Box | TQFrame::Plain ); + d->listBox()->setLineWidth( 1 ); + d->listBox()->resize( 100, 10 ); + + connect( d->listBox(), TQ_SIGNAL(selected(int)), + TQ_SLOT(internalActivate(int)) ); + connect( d->listBox(), TQ_SIGNAL(highlighted(int)), + TQ_SLOT(internalHighlight(int))); +} + + +/*! + Returns the current list box, or 0 if there is no list box. + (TQComboBox can use TQPopupMenu instead of TQListBox.) Provided to + match setListBox(). + + \sa setListBox() +*/ + +TQListBox * TQComboBox::listBox() const +{ + return d && d->usingListBox() ? d->listBox() : 0; +} + +/*! + Returns the line edit, or 0 if there is no line edit. + + Only editable listboxes have a line editor. +*/ +TQLineEdit* TQComboBox::lineEdit() const +{ + return d->ed; +} + + + +/*! + Clears the line edit without changing the combobox's contents. + Does nothing if the combobox isn't editable. + + This is particularly useful when using a combobox as a line edit + with history. For example you can connect the combobox's + activated() signal to clearEdit() in order to present the user + with a new, empty line as soon as Enter is pressed. + + \sa setEditText() +*/ + +void TQComboBox::clearEdit() +{ + if ( d && d->ed ) + d->ed->clear(); +} + + +/*! + Sets the text in the line edit to \a newText without changing the + combobox's contents. Does nothing if the combobox isn't editable. + + This is useful e.g. for providing a good starting point for the + user's editing and entering the change in the combobox only when + the user presses Enter. + + \sa clearEdit() insertItem() +*/ + +void TQComboBox::setEditText( const TQString &newText ) +{ + if ( d && d->ed ) { + d->updateLinedGeometry(); + d->ed->setText( newText ); + } +} + +void TQComboBox::setAutoCompletion( bool enable ) +{ + d->useCompletion = enable; + d->completeNow = FALSE; +} + + +bool TQComboBox::autoCompletion() const +{ + return d->useCompletion; +} + +/*!\reimp + */ +void TQComboBox::styleChange( TQStyle& s ) +{ + d->sizeHint = TQSize(); // invalidate size hint... + if ( d->ed ) + d->updateLinedGeometry(); + TQWidget::styleChange( s ); +} + +bool TQComboBox::editable() const +{ + return d->ed != 0; +} + +void TQComboBox::setEditable( bool y ) +{ + if ( y == editable() ) + return; + if ( y ) { + if ( !d->usingListBox() ) + setUpListBox(); + setUpLineEdit(); + d->ed->show(); + if ( currentItem() ) + setEditText( currentText() ); + } else { + delete d->ed; + d->ed = 0; + } + + setFocusPolicy( StrongFocus ); + updateGeometry(); + update(); +} + + +void TQComboBox::setUpListBox() +{ + d->setListBox( new TQListBox( this, "in-combo", WType_Popup ) ); + d->listBox()->setFont( font() ); + d->listBox()->setPalette( palette() ); + d->listBox()->setVScrollBarMode( TQListBox::AlwaysOff ); + d->listBox()->setHScrollBarMode( TQListBox::AlwaysOff ); + d->listBox()->setFrameStyle( TQFrame::Box | TQFrame::Plain ); + d->listBox()->setLineWidth( 1 ); + d->listBox()->resize( 100, 10 ); + + connect( d->listBox(), TQ_SIGNAL(selected(int)), + TQ_SLOT(internalActivate(int)) ); + connect( d->listBox(), TQ_SIGNAL(highlighted(int)), + TQ_SLOT(internalHighlight(int))); +} + + +void TQComboBox::setUpLineEdit() +{ + if ( !d->ed ) + setLineEdit( new TQLineEdit( this, "combo edit" ) ); +} + +/*! + Sets the line edit to use \a edit instead of the current line edit. +*/ + +void TQComboBox::setLineEdit( TQLineEdit *edit ) +{ + if ( !edit ) { +#if defined(QT_CHECK_NULL) + Q_ASSERT( edit != 0 ); +#endif + return; + } + + edit->setText( currentText() ); + delete d->ed; + d->ed = edit; + + if ( edit->parent() != this ) + edit->reparent( this, TQPoint(0,0), FALSE ); + + connect (edit, TQ_SIGNAL( textChanged(const TQString&) ), + this, TQ_SIGNAL( textChanged(const TQString&) ) ); + connect( edit, TQ_SIGNAL(returnPressed()), TQ_SLOT(returnPressed()) ); + + edit->setFrame( FALSE ); + d->updateLinedGeometry(); + edit->installEventFilter( this ); + setFocusProxy( edit ); + setFocusPolicy( StrongFocus ); + setInputMethodEnabled( TRUE ); + + if ( !d->usingListBox() ) + setUpListBox(); + + if ( isVisible() ) + edit->show(); + + updateGeometry(); + update(); +} + +/*! + \reimp +*/ +void TQComboBox::hide() +{ + TQWidget::hide(); + + if (listBox()) + listBox()->hide(); + else if (d->popup()) + d->popup()->hide(); +} + +#endif // TQT_NO_COMBOBOX diff --git a/src/widgets/tqcombobox.h b/src/widgets/tqcombobox.h new file mode 100644 index 000000000..296148549 --- /dev/null +++ b/src/widgets/tqcombobox.h @@ -0,0 +1,206 @@ +/********************************************************************** +** +** Definition of TQComboBox class +** +** Created : 950426 +** +** 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 TQCOMBOBOX_H +#define TQCOMBOBOX_H + +#ifndef QT_H +#include "tqwidget.h" +#endif // QT_H + +#ifndef TQT_NO_COMBOBOX + + +class TQStrList; +class TQStringList; +class TQLineEdit; +class TQValidator; +class TQListBox; +class TQComboBoxData; +class TQWheelEvent; + +class TQ_EXPORT TQComboBox : public TQWidget +{ + TQ_OBJECT + TQ_ENUMS( Policy ) + TQ_PROPERTY( bool editable READ editable WRITE setEditable ) + TQ_PROPERTY( int count READ count ) + TQ_PROPERTY( TQString currentText READ currentText WRITE setCurrentText DESIGNABLE false ) + TQ_PROPERTY( int currentItem READ currentItem WRITE setCurrentItem ) + TQ_PROPERTY( bool autoResize READ autoResize WRITE setAutoResize DESIGNABLE false ) + TQ_PROPERTY( int sizeLimit READ sizeLimit WRITE setSizeLimit ) + TQ_PROPERTY( int maxCount READ maxCount WRITE setMaxCount ) + TQ_PROPERTY( Policy insertionPolicy READ insertionPolicy WRITE setInsertionPolicy ) + TQ_PROPERTY( bool autoCompletion READ autoCompletion WRITE setAutoCompletion ) + TQ_PROPERTY( bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled ) + TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) + +public: + TQComboBox( TQWidget* parent=0, const char* name=0 ); + TQComboBox( bool rw, TQWidget* parent=0, const char* name=0 ); + ~TQComboBox(); + + int count() const; + + void insertStringList( const TQStringList &, int index=-1 ); + void insertStrList( const TQStrList &, int index=-1 ); + void insertStrList( const TQStrList *, int index=-1 ); + void insertStrList( const char **, int numStrings=-1, int index=-1); + + void insertItem( const TQString &text, int index=-1 ); + void insertItem( const TQPixmap &pixmap, int index=-1 ); + void insertItem( const TQPixmap &pixmap, const TQString &text, int index=-1 ); + + void removeItem( int index ); + + int currentItem() const; + virtual void setCurrentItem( int index ); + + TQString currentText() const; + virtual void setCurrentText( const TQString& ); + + TQString text( int index ) const; + const TQPixmap *pixmap( int index ) const; + + void changeItem( const TQString &text, int index ); + void changeItem( const TQPixmap &pixmap, int index ); + void changeItem( const TQPixmap &pixmap, const TQString &text, int index ); + + bool autoResize() const; + virtual void setAutoResize( bool ); + TQSize sizeHint() const; + + void setPalette( const TQPalette & ); + void setFont( const TQFont & ); + void setEnabled( bool ); + + virtual void setSizeLimit( int ); + int sizeLimit() const; + + virtual void setMaxCount( int ); + int maxCount() const; + + enum Policy { NoInsertion, AtTop, AtCurrent, AtBottom, + AfterCurrent, BeforeCurrent }; + + virtual void setInsertionPolicy( Policy policy ); + Policy insertionPolicy() const; + + virtual void setValidator( const TQValidator * ); + const TQValidator * validator() const; + + virtual void setListBox( TQListBox * ); + TQListBox * listBox() const; + + virtual void setLineEdit( TQLineEdit *edit ); + TQLineEdit* lineEdit() const; + + virtual void setAutoCompletion( bool ); + bool autoCompletion() const; + + bool eventFilter( TQObject *object, TQEvent *event ); + + void setDuplicatesEnabled( bool enable ); + bool duplicatesEnabled() const; + + bool editable() const; + void setEditable( bool ); + + virtual void popup(); + + void hide(); + +public slots: + void clear(); + void clearValidator(); + void clearEdit(); + virtual void setEditText( const TQString &); + +signals: + void activated( int index ); + void highlighted( int index ); + void activated( const TQString &); + void highlighted( const TQString &); + void textChanged( const TQString &); + +private slots: + void internalActivate( int ); + void internalHighlight( int ); + void internalClickTimeout(); + void returnPressed(); + +protected: + void paintEvent( TQPaintEvent * ); + void resizeEvent( TQResizeEvent * ); + void mousePressEvent( TQMouseEvent * ); + void mouseMoveEvent( TQMouseEvent * ); + void mouseReleaseEvent( TQMouseEvent * ); + void mouseDoubleClickEvent( TQMouseEvent * ); + void keyPressEvent( TQKeyEvent *e ); + void focusInEvent( TQFocusEvent *e ); + void focusOutEvent( TQFocusEvent *e ); +#ifndef TQT_NO_WHEELEVENT + void wheelEvent( TQWheelEvent *e ); +#endif + void styleChange( TQStyle& ); + + void updateMask(); + +private: + void setUpListBox(); + void setUpLineEdit(); + void popDownListBox(); + void reIndex(); + void currentChanged(); + int completionIndex( const TQString &, int ) const; + + TQComboBoxData *d; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQComboBox( const TQComboBox & ); + TQComboBox &operator=( const TQComboBox & ); +#endif +}; + + +#endif // TQT_NO_COMBOBOX + +#endif // TQCOMBOBOX_H diff --git a/src/widgets/tqdial.cpp b/src/widgets/tqdial.cpp new file mode 100644 index 000000000..75793b5c1 --- /dev/null +++ b/src/widgets/tqdial.cpp @@ -0,0 +1,976 @@ +/**************************************************************************** +** +** Implementation of the dial widget +** +** Created : 979899 +** +** 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 "tqdial.h" + +#ifndef TQT_NO_DIAL + +#include "tqpainter.h" +#include "tqpointarray.h" +#include "tqcolor.h" +#include "ntqapplication.h" +#include "tqregion.h" +#include "tqbitmap.h" +#include "tqstyle.h" +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif + +#include // sin(), cos(), atan() +//### Forutsetter linking med math lib - Jfr kommentar i tqpainter_x11.cpp! + +static const double m_pi = 3.14159265358979323846; +static const double rad_factor = 180.0 / m_pi; + + +class TQDialPrivate +{ +public: + TQDialPrivate() + { + wrapping = FALSE; + tracking = TRUE; + doNotEmit = FALSE; + target = 3.7; + mousePressed = FALSE; + } + + bool wrapping; + bool tracking; + bool doNotEmit; + double target; + TQRect eraseArea; + bool eraseAreaValid; + bool showNotches; + bool onlyOutside; + bool mousePressed; + + TQPointArray lines; +}; + + +/*! + \class TQDial tqdial.h + + \brief The TQDial class provides a rounded range control (like a speedometer or potentiometer). + + \ingroup basic + \mainclass + + TQDial is used when the user needs to control a value within a + program-definable range, and the range either wraps around + (typically, 0..359 degrees) or the dialog layout needs a square + widget. + + Both API- and UI-wise, the dial is very similar to a \link TQSlider + slider. \endlink Indeed, when wrapping() is FALSE (the default) + there is no real difference between a slider and a dial. They + have the same signals, slots and member functions, all of which do + the same things. Which one you use depends only on your taste + and on the application. + + The dial initially emits valueChanged() signals continuously while + the slider is being moved; you can make it emit the signal less + often by calling setTracking(FALSE). dialMoved() is emitted + continuously even when tracking() is FALSE. + + The slider also emits dialPressed() and dialReleased() signals + when the mouse button is pressed and released. But note that the + dial's value can change without these signals being emitted; the + keyboard and wheel can be used to change the value. + + Unlike the slider, TQDial attempts to draw a "nice" number of + notches rather than one per lineStep(). If possible, the number + of notches drawn is one per lineStep(), but if there aren't enough + pixels to draw every one, TQDial will draw every second, third + etc., notch. notchSize() returns the number of units per notch, + hopefully a multiple of lineStep(); setNotchTarget() sets the + target distance between neighbouring notches in pixels. The + default is 3.75 pixels. + + Like the slider, the dial makes the TQRangeControl functions + setValue(), addLine(), subtractLine(), addPage() and + subtractPage() available as slots. + + The dial's keyboard interface is fairly simple: The left/up and + right/down arrow keys move by lineStep(), page up and page down by + pageStep() and Home and End to minValue() and maxValue(). + + + + \sa TQScrollBar TQSpinBox + \link guibooks.html#fowler GUI Design Handbook: Slider\endlink +*/ + + + + +/*! + Constructs a dial called \a name with parent \a parent. \a f is + propagated to the TQWidget constructor. It has the default range of + a TQRangeControl. +*/ + +TQDial::TQDial( TQWidget *parent, const char *name, WFlags f ) + : TQWidget( parent, name, f | WNoAutoErase ), TQRangeControl() +{ + d = new TQDialPrivate; + d->eraseAreaValid = FALSE; + d->showNotches = FALSE; + d->onlyOutside = FALSE; + setFocusPolicy( TQWidget::WheelFocus ); +} + + + +/*! + Constructs a dial called \a name with parent \a parent. The dial's + value can never be smaller than \a minValue or greater than \a + maxValue. Its page step size is \a pageStep, and its initial value + is \a value. + + \a value is forced to be within the legal range. +*/ + +TQDial::TQDial( int minValue, int maxValue, int pageStep, int value, + TQWidget *parent, const char *name ) + : TQWidget( parent, name, WNoAutoErase ), + TQRangeControl( minValue, maxValue, 1, pageStep, value ) +{ + d = new TQDialPrivate; + d->eraseAreaValid = FALSE; + d->showNotches = FALSE; + d->onlyOutside = FALSE; + setFocusPolicy( TQWidget::WheelFocus ); +} + +/*! + Destroys the dial. +*/ +TQDial::~TQDial() +{ + delete d; +} + + +void TQDial::setTracking( bool enable ) +{ + d->tracking = enable; +} + + +/*! + \property TQDial::tracking + \brief whether tracking is enabled + + If TRUE (the default), tracking is enabled. This means that the + arrow can be moved using the mouse; otherwise the arrow cannot be + moved with the mouse. +*/ + +bool TQDial::tracking() const +{ + return d ? d->tracking : TRUE; +} + +void TQDial::setValue( int newValue ) +{ // ### set doNotEmit? Matthias? + TQRangeControl::setValue( newValue ); +} + + +/*! + Increments the dial's value() by one lineStep(). +*/ + +void TQDial::addLine() +{ + TQRangeControl::addLine(); +} + + +/*! + Decrements the dial's value() by one lineStep(). +*/ + +void TQDial::subtractLine() +{ + TQRangeControl::subtractLine(); +} + + +/*! \reimp */ + +void TQDial::resizeEvent( TQResizeEvent * e ) +{ + d->lines.resize( 0 ); + TQWidget::resizeEvent( e ); +} + + +/*! + \reimp +*/ + +void TQDial::paintEvent( TQPaintEvent * e ) +{ + repaintScreen( &e->rect() ); +} + +/*! + Paints the dial using clip region \a cr. +*/ + +void TQDial::repaintScreen( const TQRect *cr ) +{ + TQPainter p; + p.begin( this ); + + bool resetClipping = FALSE; + + // calculate clip-region for erasing background + if ( cr ) { + p.setClipRect( *cr ); + } else if ( !d->onlyOutside && d->eraseAreaValid ) { + TQRegion reg = d->eraseArea; + double a; + reg = reg.subtract( calcArrow( a ) ); + p.setClipRegion( reg ); + resetClipping = TRUE; + } + + TQRect br( calcDial() ); + p.setPen( NoPen ); + // if ( style() == MotifStyle ) + // p.setBrush( colorGroup().brush( TQColorGroup::Mid ) ); + // else { + TQBrush b; + if ( colorGroup().brush( TQColorGroup::Light ).pixmap() ) + b = TQBrush( colorGroup().brush( TQColorGroup::Light ) ); + else + b = TQBrush( colorGroup().light(), Dense4Pattern ); + p.setBrush( b ); + p.setBackgroundMode( OpaqueMode ); + // } + + TQRect te = br; + te.setWidth(te.width()+2); + te.setHeight(te.height()+2); + // erase background of dial + if ( !d->onlyOutside ) { + p.drawEllipse( te ); + } + + // erase remaining space around the dial + TQRegion remaining( 0, 0, width(), height() ); + remaining = remaining.subtract( TQRegion( te, TQRegion::Ellipse ) ); + if ( p.hasClipping() ) + remaining = remaining.intersect( p.clipRegion() ); + erase(remaining); + + if ( resetClipping ) { + if ( cr ) + p.setClipRect( *cr ); + else + p.setClipRect( TQRect( 0, 0, width(), height() ) ); + } + + // draw notches + if ( d->showNotches ) { + calcLines(); + p.setPen( colorGroup().foreground() ); + p.drawLineSegments( d->lines ); + } + + // calculate and paint arrow + p.setPen( TQPen( colorGroup().dark() ) ); + p.drawArc( te, 60 * 16, 180 * 16 ); + p.setPen( TQPen( colorGroup().light() ) ); + p.drawArc( te, 240 * 16, 180 * 16 ); + + double a; + TQPointArray arrow( calcArrow( a ) ); + TQRect ea( arrow.boundingRect() ); + d->eraseArea = ea; + d->eraseAreaValid = TRUE; + + p.setPen( NoPen ); + p.setBrush( colorGroup().brush( TQColorGroup::Button ) ); + if ( !d->onlyOutside ) + p.drawPolygon( arrow ); + + a = angle( TQPoint( width() / 2, height() / 2 ), arrow[ 0 ] ); + p.setBrush( TQt::NoBrush ); + + // that's still a hack... + if ( a <= 0 || a > 200 ) { + p.setPen( colorGroup().light() ); + p.drawLine( arrow[ 2 ], arrow[ 0 ] ); + p.drawLine( arrow[ 1 ], arrow[ 2 ] ); + p.setPen( colorGroup().dark() ); + p.drawLine( arrow[ 0 ], arrow[ 1 ] ); + } else if ( a > 0 && a < 45 ) { + p.setPen( colorGroup().light() ); + p.drawLine( arrow[ 2 ], arrow[ 0 ] ); + p.setPen( colorGroup().dark() ); + p.drawLine( arrow[ 1 ], arrow[ 2 ] ); + p.drawLine( arrow[ 0 ], arrow[ 1 ] ); + } else if ( a >= 45 && a < 135 ) { + p.setPen( colorGroup().dark() ); + p.drawLine( arrow[ 2 ], arrow[ 0 ] ); + p.drawLine( arrow[ 1 ], arrow[ 2 ] ); + p.setPen( colorGroup().light() ); + p.drawLine( arrow[ 0 ], arrow[ 1 ] ); + } else if ( a >= 135 && a < 200 ) { + p.setPen( colorGroup().dark() ); + p.drawLine( arrow[ 2 ], arrow[ 0 ] ); + p.setPen( colorGroup().light() ); + p.drawLine( arrow[ 0 ], arrow[ 1 ] ); + p.drawLine( arrow[ 1 ], arrow[ 2 ] ); + } + + // draw focus rect around the dial + if ( hasFocus() ) { + p.setClipping( FALSE ); + br.setWidth( br.width() + 2 ); + br.setHeight( br.height() + 2 ); + if ( d->showNotches ) { + int r = TQMIN( width(), height() ) / 2; + br.moveBy( -r / 6, - r / 6 ); + br.setWidth( br.width() + r / 3 ); + br.setHeight( br.height() + r / 3 ); + } + // strange, but else we get redraw errors on Windows + p.end(); + p.begin( this ); + p.save(); + p.setPen( TQPen( colorGroup().background() ) ); + p.setBrush( NoBrush ); + p.drawRect( br ); + p.restore(); + style().drawPrimitive( TQStyle::PE_FocusRect, &p, br, colorGroup()); + } + p.end(); +} + + +/*! + \reimp +*/ + +void TQDial::keyPressEvent( TQKeyEvent * e ) +{ + switch ( e->key() ) { + case Key_Left: case Key_Down: + subtractLine(); + break; + case Key_Right: case Key_Up: + addLine(); + break; + case Key_Prior: + subtractPage(); + break; + case Key_Next: + addPage(); + break; + case Key_Home: + setValue( minValue() ); + break; + case Key_End: + setValue( maxValue() ); + break; + default: + e->ignore(); + break; + } +} + + +/*! + \reimp +*/ + +void TQDial::mousePressEvent( TQMouseEvent * e ) +{ + d->mousePressed = TRUE; + setValue( valueFromPoint( e->pos() ) ); + emit dialPressed(); +} + + +/*! + \reimp +*/ + +void TQDial::mouseReleaseEvent( TQMouseEvent * e ) +{ + d->mousePressed = FALSE; + setValue( valueFromPoint( e->pos() ) ); + emit dialReleased(); +} + + +/*! + \reimp +*/ + +void TQDial::mouseMoveEvent( TQMouseEvent * e ) +{ + if ( !d->mousePressed ) + return; + if ( !d->tracking || (e->state() & LeftButton) == 0 ) + return; + d->doNotEmit = TRUE; + setValue( valueFromPoint( e->pos() ) ); + emit dialMoved( value() ); + d->doNotEmit = FALSE; +} + + +/*! + \reimp +*/ +#ifndef TQT_NO_WHEELEVENT +void TQDial::wheelEvent( TQWheelEvent *e ) +{ + setValue( value() - e->delta() / 120 ); +} +#endif + +/*! + \reimp +*/ + +void TQDial::focusInEvent( TQFocusEvent * ) +{ + d->onlyOutside = TRUE; + repaintScreen(); + d->onlyOutside = FALSE; +} + + +/*! + \reimp +*/ + +void TQDial::focusOutEvent( TQFocusEvent * ) +{ + d->onlyOutside = TRUE; + repaintScreen(); + d->onlyOutside = FALSE; +} + +/*! + Reimplemented to ensure the display is correct and to emit the + valueChanged(int) signal when appropriate. +*/ + +void TQDial::valueChange() +{ + d->lines.resize( 0 ); + repaintScreen(); + if ( d->tracking || !d->doNotEmit ) { + emit valueChanged( value() ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif + } +} + + +/*! + Reimplemented to ensure tick-marks are consistent with the new range. +*/ + +void TQDial::rangeChange() +{ + d->lines.resize( 0 ); + repaintScreen(); +} + + +/*! + \internal +*/ + +int TQDial::valueFromPoint( const TQPoint & p ) const +{ + double yy = (double)height()/2.0 - p.y(); + double xx = (double)p.x() - width()/2.0; + double a = (xx || yy) ? atan2(yy, xx) : 0; + + if ( a < m_pi/-2 ) + a = a + m_pi*2; + + int dist = 0; + int minv = minValue(), maxv = maxValue(); + + if ( minValue() < 0 ) { + dist = -minValue(); + minv = 0; + maxv = maxValue() + dist; + } + + int r = maxv - minv; + int v; + if ( d->wrapping ) + v = (int)(0.5 + minv + r*(m_pi*3/2-a)/(2*m_pi)); + else + v = (int)(0.5 + minv + r*(m_pi*4/3-a)/(m_pi*10/6)); + + if ( dist > 0 ) + v -= dist; + + return bound( v ); +} + + +/*! + \internal +*/ + +double TQDial::angle( const TQPoint &p1, const TQPoint &p2 ) const +{ + double _angle = 0.0; + + if ( p1.x() == p2.x() ) { + if ( p1.y() < p2.y() ) + _angle = 270.0; + else + _angle = 90.0; + } else { + double x1, x2, y1, y2; + + if ( p1.x() <= p2.x() ) { + x1 = p1.x(); y1 = p1.y(); + x2 = p2.x(); y2 = p2.y(); + } else { + x2 = p1.x(); y2 = p1.y(); + x1 = p2.x(); y1 = p2.y(); + } + + double m = -( y2 - y1 ) / ( x2 - x1 ); + _angle = atan( m ) * rad_factor; + + if ( p1.x() < p2.x() ) + _angle = 180.0 - _angle; + else + _angle = -_angle; + } + + return _angle; +} + +void TQDial::setWrapping( bool enable ) +{ + if ( d->wrapping == enable ) + return; + d->lines.resize( 0 ); + d->wrapping = enable; + d->eraseAreaValid = FALSE; + repaintScreen(); +} + + +/*! + \property TQDial::wrapping + \brief whether wrapping is enabled + + If TRUE, wrapping is enabled. This means that the arrow can be + turned around 360°. Otherwise there is some space at the bottom of + the dial which is skipped by the arrow. + + This property's default is FALSE. +*/ + +bool TQDial::wrapping() const +{ + return d->wrapping; +} + + +/*! + \property TQDial::notchSize + \brief the current notch size + + The notch size is in range control units, not pixels, and if + possible it is a multiple of lineStep() that results in an + on-screen notch size near notchTarget(). + + \sa notchTarget() lineStep() +*/ + +int TQDial::notchSize() const +{ + // radius of the arc + int r = TQMIN( width(), height() )/2; + // length of the whole arc + int l = (int)(r*(d->wrapping ? 6 : 5)*m_pi/6); + // length of the arc from minValue() to minValue()+pageStep() + if ( maxValue() > minValue()+pageStep() ) + l = (int)(0.5 + l * pageStep() / (maxValue()-minValue())); + // length of a lineStep() arc + l = l * lineStep() / pageStep(); + if ( l < 1 ) + l = 1; + // how many times lineStep can be draw in d->target pixels + l = (int)(0.5 + d->target / l); + // we want notchSize() to be a non-zero multiple of lineStep() + if ( !l ) + l = 1; + return lineStep() * l; +} + +void TQDial::setNotchTarget( double target ) +{ + d->lines.resize( 0 ); + d->target = target; + d->eraseAreaValid = FALSE; + d->onlyOutside = TRUE; + repaintScreen(); + d->onlyOutside = FALSE; +} + + +/*! + \property TQDial::notchTarget + \brief the target number of pixels between notches + + The notch target is the number of pixels TQDial attempts to put + between each notch. + + The actual size may differ from the target size. +*/ + +double TQDial::notchTarget() const +{ + return d->target; +} + + +/*! + Increments the dial's value() by one pageStep() of steps. +*/ + +void TQDial::addPage() +{ + TQRangeControl::addPage(); +} + + +/*! + Decrements the dial's value() by one pageStep() of steps. +*/ + +void TQDial::subtractPage() +{ + TQRangeControl::subtractPage(); +} + + +/*! + \fn void TQDial::valueChanged( int value ) + + This signal is emitted whenever the dial's \a value changes. The + frequency of this signal is influenced by setTracking(). +*/ + +/*! + \fn void TQDial::dialPressed() + + This signal is emitted when the user begins mouse interaction with + the dial. + + \sa dialReleased() +*/ + +/*! + \fn void TQDial::dialMoved( int value ) + + This signal is emitted whenever the dial \a value changes. The + frequency of this signal is \e not influenced by setTracking(). + + \sa valueChanged() +*/ + +/*! + \fn void TQDial::dialReleased() + + This signal is emitted when the user ends mouse interaction with + the dial. + + \sa dialPressed() +*/ + +void TQDial::setNotchesVisible( bool b ) +{ + d->showNotches = b; + d->eraseAreaValid = FALSE; + d->onlyOutside = TRUE; + repaintScreen(); + d->onlyOutside = FALSE; +} + +/*! + \property TQDial::notchesVisible + \brief whether the notches are shown + + If TRUE, the notches are shown. If FALSE (the default) notches are + not shown. +*/ +bool TQDial::notchesVisible() const +{ + return d->showNotches; +} + +/*! + \reimp +*/ + +TQSize TQDial::minimumSizeHint() const +{ + return TQSize( 50, 50 ); +} + +/*! + \reimp +*/ + +TQSize TQDial::sizeHint() const +{ + return TQSize( 100, 100 ).expandedTo( TQApplication::globalStrut() ); +} + + + +/*! + \internal +*/ + +TQPointArray TQDial::calcArrow( double &a ) const +{ + int r = TQMIN( width(), height() ) / 2; + if ( maxValue() == minValue() ) + a = m_pi / 2; + else if ( d->wrapping ) + a = m_pi * 3 / 2 - ( value() - minValue() ) * 2 * m_pi / ( maxValue() - minValue() ); + else + a = ( m_pi * 8 - ( value() - minValue() ) * 10 * m_pi / ( maxValue() - minValue() ) ) / 6; + + int xc = width() / 2; + int yc = height() / 2; + + int len = r - calcBigLineSize() - 5; + if ( len < 5 ) + len = 5; + int back = len / 4; + if ( back < 1 ) + back = 1; + + TQPointArray arrow( 3 ); + arrow[0] = TQPoint( (int)( 0.5 + xc + len * cos(a) ), + (int)( 0.5 + yc -len * sin( a ) ) ); + arrow[1] = TQPoint( (int)( 0.5 + xc + back * cos( a + m_pi * 5 / 6 ) ), + (int)( 0.5 + yc - back * sin( a + m_pi * 5 / 6 ) ) ); + arrow[2] = TQPoint( (int)( 0.5 + xc + back * cos( a - m_pi * 5 / 6 ) ), + (int)( 0.5 + yc - back * sin( a - m_pi * 5 / 6 ) ) ); + return arrow; +} + +/*! + \internal +*/ + +TQRect TQDial::calcDial() const +{ + double r = TQMIN( width(), height() ) / 2.0; + double d_ = r / 6.0; + double dx = d_ + ( width() - 2 * r ) / 2.0 + 1; + double dy = d_ + ( height() - 2 * r ) / 2.0 + 1; + return TQRect( int(dx), int(dy), + int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2) ); +} + +/*! + \internal +*/ + +int TQDial::calcBigLineSize() const +{ + int r = TQMIN( width(), height() ) / 2; + int bigLineSize = r / 6; + if ( bigLineSize < 4 ) + bigLineSize = 4; + if ( bigLineSize > r / 2 ) + bigLineSize = r / 2; + return bigLineSize; +} + +/*! + \internal +*/ + +void TQDial::calcLines() +{ + if ( !d->lines.size() ) { + double r = TQMIN( width(), height() ) / 2.0; + int bigLineSize = calcBigLineSize(); + double xc = width() / 2.0; + double yc = height() / 2.0; + int ns = notchSize(); + int notches = ( maxValue() + ns - 1 - minValue() ) / ns; + d->lines.resize( 2 + 2 * notches ); + int smallLineSize = bigLineSize / 2; + int i; + for( i = 0; i <= notches; i++ ) { + double angle = d->wrapping + ? m_pi * 3 / 2 - i * 2 * m_pi / notches + : (m_pi * 8 - i * 10 * m_pi / notches) / 6; + + double s = sin( angle ); // sin/cos aren't defined as const... + double c = cos( angle ); + if ( i == 0 || ( ((ns * i ) % pageStep() ) == 0 ) ) { + d->lines[2*i] = TQPoint( (int)( xc + ( r - bigLineSize ) * c ), + (int)( yc - ( r - bigLineSize ) * s ) ); + d->lines[2*i+1] = TQPoint( (int)( xc + r * c ), + (int)( yc - r * s ) ); + } else { + d->lines[2*i] = TQPoint( (int)( xc + ( r - 1 - smallLineSize ) * c ), + (int)( yc - ( r - 1 - smallLineSize ) * s ) ); + d->lines[2*i+1] = TQPoint( (int)( xc + ( r - 1 ) * c ), + (int)( yc -( r - 1 ) * s ) ); + } + } + } +} + +/*! + \property TQDial::minValue + \brief the current minimum value + + When setting this property, the \l TQDial::maxValue is adjusted if + necessary to ensure that the range remains valid. + + \sa setRange() +*/ +int TQDial::minValue() const +{ + return TQRangeControl::minValue(); +} + +/*! + \property TQDial::maxValue + \brief the current maximum value + + When setting this property, the \l TQDial::minValue is adjusted if + necessary to ensure that the range remains valid. + + \sa setRange() +*/ +int TQDial::maxValue() const +{ + return TQRangeControl::maxValue(); +} + +void TQDial::setMinValue( int minVal ) +{ + TQRangeControl::setMinValue( minVal ); +} + +void TQDial::setMaxValue( int maxVal ) +{ + TQRangeControl::setMaxValue( maxVal ); +} + +/*! + \property TQDial::lineStep + \brief the current line step + + setLineStep() calls the virtual stepChange() function if the new + line step is different from the previous setting. + + \sa TQRangeControl::setSteps() pageStep setRange() +*/ + +int TQDial::lineStep() const +{ + return TQRangeControl::lineStep(); +} + +/*! + \property TQDial::pageStep + \brief the current page step + + setPageStep() calls the virtual stepChange() function if the new + page step is different from the previous setting. + + \sa stepChange() +*/ +int TQDial::pageStep() const +{ + return TQRangeControl::pageStep(); +} + +void TQDial::setLineStep( int i ) +{ + setSteps( i, pageStep() ); +} + +void TQDial::setPageStep( int i ) +{ + setSteps( lineStep(), i ); +} + +/*! + \property TQDial::value + \brief the current dial value + + This is guaranteed to be within the range + \l{TQDial::minValue}..\l{TQDial::maxValue}. + + \sa minValue maxValue +*/ + +int TQDial::value() const +{ + return TQRangeControl::value(); +} + +#endif // QT_FEATURE_DIAL diff --git a/src/widgets/tqdial.h b/src/widgets/tqdial.h new file mode 100644 index 000000000..7baf98e53 --- /dev/null +++ b/src/widgets/tqdial.h @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** Definition of the dial widget +** +** Created : 990104 +** +** Copyright (C) 1999-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 TQDIAL_H +#define TQDIAL_H + +#ifndef QT_H +#include "tqwidget.h" +#include "ntqrangecontrol.h" +#endif // QT_H + +#ifndef TQT_NO_DIAL + +class TQDialPrivate; + +class TQ_EXPORT TQDial: public TQWidget, public TQRangeControl +{ + TQ_OBJECT + TQ_PROPERTY( bool tracking READ tracking WRITE setTracking ) + TQ_PROPERTY( bool wrapping READ wrapping WRITE setWrapping ) + TQ_PROPERTY( int notchSize READ notchSize ) + TQ_PROPERTY( double notchTarget READ notchTarget WRITE setNotchTarget ) + TQ_PROPERTY( bool notchesVisible READ notchesVisible WRITE setNotchesVisible ) + TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) + TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) + TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) + TQ_PROPERTY( int pageStep READ pageStep WRITE setPageStep ) + TQ_PROPERTY( int value READ value WRITE setValue ) + +public: + TQDial( TQWidget* parent=0, const char* name=0, WFlags f = 0 ); + TQDial( int minValue, int maxValue, int pageStep, int value, + TQWidget* parent=0, const char* name=0 ); + ~TQDial(); + + bool tracking() const; + + bool wrapping() const; + + int notchSize() const; + + virtual void setNotchTarget( double ); + double notchTarget() const; + + bool notchesVisible() const; + + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + + int minValue() const; + int maxValue() const; + void setMinValue( int ); + void setMaxValue( int ); + int lineStep() const; + int pageStep() const; + void setLineStep( int ); + void setPageStep( int ); + int value() const; + +public slots: + virtual void setValue( int ); + void addLine(); + void subtractLine(); + void addPage(); + void subtractPage(); + virtual void setNotchesVisible( bool b ); + virtual void setWrapping( bool on ); + virtual void setTracking( bool enable ); + +signals: + void valueChanged( int value ); + void dialPressed(); + void dialMoved( int value ); + void dialReleased(); + +protected: + void resizeEvent( TQResizeEvent * ); + void paintEvent( TQPaintEvent * ); + + void keyPressEvent( TQKeyEvent * ); + void mousePressEvent( TQMouseEvent * ); + void mouseReleaseEvent( TQMouseEvent * ); + void mouseMoveEvent( TQMouseEvent * ); +#ifndef TQT_NO_WHEELEVENT + void wheelEvent( TQWheelEvent * ); +#endif + void focusInEvent( TQFocusEvent * ); + void focusOutEvent( TQFocusEvent * ); + + void valueChange(); + void rangeChange(); + + virtual void repaintScreen( const TQRect *cr = 0 ); + +private: + TQDialPrivate * d; + + int valueFromPoint( const TQPoint & ) const; + double angle( const TQPoint &, const TQPoint & ) const; + TQPointArray calcArrow( double &a ) const; + TQRect calcDial() const; + int calcBigLineSize() const; + void calcLines(); + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQDial( const TQDial & ); + TQDial &operator=( const TQDial & ); +#endif + +}; + +#endif // TQT_NO_DIAL + +#endif diff --git a/src/widgets/tqdialogbuttons.cpp b/src/widgets/tqdialogbuttons.cpp new file mode 100644 index 000000000..b20f70350 --- /dev/null +++ b/src/widgets/tqdialogbuttons.cpp @@ -0,0 +1,462 @@ +/**************************************************************************** +** +** Implementation of TQDialogButtons class +** +** Copyright (C) 2005-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 "tqdialogbuttons_p.h" +#ifndef TQT_NO_DIALOGBUTTONS + +#include +#include +#include +#include +#include +#ifndef TQT_NO_DIALOG +#include +#endif // TQT_NO_DIALOG +#include +#include +#include + +struct TQDialogButtonsPrivate +{ + TQMap text; + TQMap buttons; + TQGuardedPtr custom; + TQ_UINT32 enabled, visible; + TQDialogButtons::Button def; + TQt::Orientation orient; + bool questionMode; +}; + +#ifndef TQT_NO_DIALOG +TQDialogButtons::TQDialogButtons(TQDialog *parent, bool autoConnect, TQ_UINT32 buttons, + Orientation orient, const char *name ) : TQWidget(parent, name) +{ + init(buttons, orient); + if(parent && autoConnect) { + TQObject::connect(this, TQ_SIGNAL(acceptClicked()), parent, TQ_SLOT(accept())); + TQObject::connect(this, TQ_SIGNAL(rejectClicked()), parent, TQ_SLOT(reject())); + } +} +#endif // TQT_NO_DIALOG + +TQDialogButtons::TQDialogButtons(TQWidget *parent, TQ_UINT32 buttons, + Orientation orient, const char *name ) : TQWidget(parent, name) +{ + init(buttons, orient); +} + +void +TQDialogButtons::init(TQ_UINT32 buttons, Orientation orient) +{ + if(buttons == All) { + tqWarning("TQDialogButtons: cannot specify All by itself!"); + buttons = None; + } + d = new TQDialogButtonsPrivate; + d->questionMode = FALSE; + d->orient = orient; + d->def = (Button)style().styleHint(TQStyle::SH_DialogButtons_DefaultButton, this); + d->enabled = d->visible = buttons; +} + +TQDialogButtons::~TQDialogButtons() +{ + delete (TQWidget *)d->custom; + delete d; +} + +void +TQDialogButtons::setQuestionMode(bool b) +{ + d->questionMode = b; +} + +bool +TQDialogButtons::questionMode() const +{ + return d->questionMode; +} + +void +TQDialogButtons::setButtonEnabled(Button button, bool enabled) +{ + if(enabled) + d->enabled |= button; + else + d->enabled ^= button; + if(d->buttons.contains(button)) + d->buttons[button]->setEnabled(enabled); +} + +bool +TQDialogButtons::isButtonEnabled(Button button) const +{ + return ((int)(d->enabled & button)) == button; +} + +void +TQDialogButtons::setButtonVisible(Button button, bool visible) +{ + if(visible) { + if(d->buttons.contains(button)) + d->buttons[button]->show(); + d->visible |= button; + } else { + if(d->buttons.contains(button)) + d->buttons[button]->hide(); + d->visible ^= button; + } + layoutButtons(); +} + +bool +TQDialogButtons::isButtonVisible(Button button) const +{ + return ((int)(d->visible & button)) == button; +} + +TQ_UINT32 +TQDialogButtons::visibleButtons() const +{ + return d->visible; +} + +void +TQDialogButtons::addWidget(TQWidget *w) +{ + TQBoxLayout *lay = NULL; + if(!d->custom) { + d->custom = new TQWidget(this, "dialog_custom_area"); + if(orientation() == Horizontal) + lay = new TQHBoxLayout(d->custom); + else + lay = new TQVBoxLayout(d->custom); + layoutButtons(); + } else { + lay = (TQBoxLayout*)d->custom->layout(); + } + if(w->parent() != d->custom) + w->reparent(d->custom, 0, TQPoint(0, 0), TRUE); + lay->addWidget(w); +} + +void +TQDialogButtons::setDefaultButton(Button button) +{ + if(!((int)(d->visible & button) == button)) { + tqWarning("TQDialogButtons: Button '%d' is not visible (so cannot be default)", button); + return; + } + if(d->def != button) { +#ifndef TQT_NO_PROPERTIES + if(d->buttons.contains(d->def)) + d->buttons[d->def]->setProperty("default", TQVariant(false)); +#endif + d->def = button; +#ifndef TQT_NO_PROPERTIES + if(d->buttons.contains(d->def)) + d->buttons[d->def]->setProperty("default", TQVariant(false)); +#endif + } +} + +TQDialogButtons::Button +TQDialogButtons::defaultButton() const +{ + return d->def; +} + +void +TQDialogButtons::setButtonText(Button button, const TQString &str) +{ + d->text[button] = str; +#ifndef TQT_NO_PROPERTIES + if(d->buttons.contains(button)) + d->buttons[button]->setProperty("text", TQVariant(str)); +#endif + layoutButtons(); +} + +TQString +TQDialogButtons::buttonText(Button b) const +{ + if(d->text.contains(b)) + return d->text[b]; + return TQString(); //null if it is default.. +} + +void +TQDialogButtons::setOrientation(Orientation orient) +{ + if(d->orient != orient) { + d->orient = orient; + if(d->custom && d->custom->layout()) + ((TQBoxLayout*)d->custom->layout())->setDirection(orient == Horizontal ? TQBoxLayout::LeftToRight : + TQBoxLayout::TopToBottom); + layoutButtons(); + } +} + +TQt::Orientation +TQDialogButtons::orientation() const +{ + return d->orient; +} + +TQWidget * +TQDialogButtons::createButton(Button b) +{ + TQPushButton *ret = new TQPushButton(this, "tqdialog_button"); + TQObject::connect(ret, TQ_SIGNAL(clicked()), this, TQ_SLOT(handleClicked())); + if(d->text.contains(b)) { + ret->setText(d->text[b]); + } else { + switch(b) { + case All: { + TQString txt = buttonText(defaultButton()); + if(txt.isNull()) { + if(defaultButton() == Accept) { + if(questionMode()) + txt = tr("Yes to All"); + else + txt = tr("OK to All"); + } else { + if(questionMode()) + txt = tr("No to All"); + else + txt = tr("Cancel All"); + } + } else { + txt += tr(" to All"); //ick, I can't really do this!! + } + ret->setText(txt); + break; } + case Accept: + if(questionMode()) + ret->setText(tr("Yes")); + else + ret->setText(tr("OK")); + break; + case Reject: + if(questionMode()) + ret->setText(tr("No")); + else + ret->setText(tr("Cancel")); + break; + case Apply: + ret->setText(tr("Apply")); + break; + case Ignore: + ret->setText(tr("Ignore")); + break; + case Retry: + ret->setText(tr("Retry")); + break; + case Abort: + ret->setText(tr("Abort")); + break; + case Help: + ret->setText(tr("Help")); + break; + default: + break; + } + } + return ret; +} + +void +TQDialogButtons::handleClicked() +{ + const TQObject *s = sender(); + if(!s) + return; + + for(TQMapIterator it = d->buttons.begin(); it != d->buttons.end(); ++it) { + if(it.data() == s) { + emit clicked((TQDialogButtons::Button)it.key()); + switch(it.key()) { + case Retry: + emit retryClicked(); + break; + case Ignore: + emit ignoreClicked(); + break; + case Abort: + emit abortClicked(); + break; + case All: + emit allClicked(); + break; + case Accept: + emit acceptClicked(); + break; + case Reject: + emit rejectClicked(); + break; + case Apply: + emit applyClicked(); + break; + case Help: + emit helpClicked(); + break; + default: + break; + } + return; + } + } +} + +void +TQDialogButtons::resizeEvent(TQResizeEvent *) +{ + layoutButtons(); +} + +void +TQDialogButtons::showEvent(TQShowEvent *) +{ + layoutButtons(); +} + +void +TQDialogButtons::styleChanged(TQStyle &old) +{ + layoutButtons(); + TQWidget::styleChange(old); +} + +void +TQDialogButtons::layoutButtons() +{ + if(!isVisible()) //nah.. + return; + + TQStyle::SubRect rects[] = { + TQStyle::SR_DialogButtonAccept, TQStyle::SR_DialogButtonReject, + TQStyle::SR_DialogButtonApply, TQStyle::SR_DialogButtonHelp, + TQStyle::SR_DialogButtonCustom, TQStyle::SR_DialogButtonAll, + TQStyle::SR_DialogButtonRetry, TQStyle::SR_DialogButtonIgnore, + TQStyle::SR_DialogButtonAbort }; + for(unsigned int i = 0; i < (sizeof(rects) / sizeof(rects[0])); i++) { + TQWidget *w = NULL; + if(rects[i] == TQStyle::SR_DialogButtonCustom) { + w = d->custom; + } else { + Button b = None; + if(rects[i] == TQStyle::SR_DialogButtonApply) + b = Apply; + else if(rects[i] == TQStyle::SR_DialogButtonAll) + b = All; + else if(rects[i] == TQStyle::SR_DialogButtonAccept) + b = Accept; + else if(rects[i] == TQStyle::SR_DialogButtonReject) + b = Reject; + else if(rects[i] == TQStyle::SR_DialogButtonHelp) + b = Help; + else if(rects[i] == TQStyle::SR_DialogButtonRetry) + b = Retry; + else if(rects[i] == TQStyle::SR_DialogButtonAbort) + b = Abort; + else if(rects[i] == TQStyle::SR_DialogButtonIgnore) + b = Ignore; + if(b != None) { + if(d->buttons.contains(b)) { + w = d->buttons[b]; + if(!(d->visible & b)) { + w->hide(); + continue; + } + } else if(d->visible & b) { + w = createButton(b); + d->buttons.insert(b, w); + } else { + continue; + } + if(w) { + if(b == d->def) { + w->setFocus(); +#ifndef TQT_NO_PROPERTIES + w->setProperty("default", TQVariant(true)); +#endif + } + w->setEnabled(d->enabled & b); + } + } + } + if(w) { + w->show(); + w->setGeometry(style().subRect(rects[i], this)); + } + } +} + +TQSize +TQDialogButtons::sizeHint() const +{ + constPolish(); + TQSize s; + if(d->custom) + s = d->custom->sizeHint(); + return (style().sizeFromContents(TQStyle::CT_DialogButtons, this, s. + expandedTo(TQApplication::globalStrut()))); +} + +TQSize +TQDialogButtons::sizeHint(TQDialogButtons::Button button) const +{ + TQWidget *w = NULL; + if(d->visible & button) { + if(!d->buttons.contains(button)) { + TQDialogButtons *that = (TQDialogButtons*)this; //ick, constness.. + w = that->createButton(button); + that->d->buttons.insert(button, w); + } else { + w = d->buttons[button]; + } + } + return w->sizeHint(); +} + +TQSize +TQDialogButtons::minimumSizeHint() const +{ + return sizeHint(); +} +#endif diff --git a/src/widgets/tqdialogbuttons_p.h b/src/widgets/tqdialogbuttons_p.h new file mode 100644 index 000000000..a5667245f --- /dev/null +++ b/src/widgets/tqdialogbuttons_p.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Definition of TQDialogButtons class. +** +** Copyright (C) 2005-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 TQDIALOGBUTTONS_P_H +#define TQDIALOGBUTTONS_P_H + +#ifndef QT_H +#ifndef QT_H +#include "tqwidget.h" +#endif // QT_H +#endif + +#ifndef TQT_NO_DIALOGBUTTONS +struct TQDialogButtonsPrivate; + +class +TQDialogButtons : public TQWidget +{ + TQ_OBJECT +public: + enum Button { None=0, Accept=0x01, Reject=0x02, Help=0x04, Apply=0x08, All=0x10, Abort=0x20, Retry=0x40, Ignore=0x80 }; +#ifndef TQT_NO_DIALOG + TQDialogButtons(TQDialog *parent, bool autoConnect = TRUE, TQ_UINT32 buttons = Accept | Reject, + Orientation orient = Horizontal, const char *name = NULL); +#endif // TQT_NO_DIALOG + TQDialogButtons(TQWidget *parent, TQ_UINT32 buttons = Accept | Reject, + Orientation orient = Horizontal, const char *name = NULL); + ~TQDialogButtons(); + + void setQuestionMode(bool); + bool questionMode() const; + + void setButtonEnabled(Button button, bool enabled); + bool isButtonEnabled(Button) const; + + inline void showButton(Button b) { setButtonVisible(b, TRUE) ; } + inline void hideButton(Button b) { setButtonVisible(b, FALSE); } + virtual void setButtonVisible(Button, bool visible); + bool isButtonVisible(Button) const; + TQ_UINT32 visibleButtons() const; + + void addWidget(TQWidget *); + + virtual void setDefaultButton(Button); + Button defaultButton() const; + + virtual void setButtonText(Button, const TQString &); + TQString buttonText(Button) const; + + void setOrientation(Orientation); + Orientation orientation() const; + + virtual TQSize sizeHint(Button) const; + TQSize minimumSizeHint() const; + TQSize sizeHint() const; + +protected: + void layoutButtons(); + virtual TQWidget *createButton(Button); + + void showEvent(TQShowEvent *); + void resizeEvent(TQResizeEvent *); + void styleChanged(TQStyle &); + +private slots: + void handleClicked(); + +signals: + void clicked(Button); + void acceptClicked(); + void rejectClicked(); + void helpClicked(); + void applyClicked(); + void allClicked(); + void retryClicked(); + void ignoreClicked(); + void abortClicked(); + +private: + TQDialogButtonsPrivate *d; + void init(TQ_UINT32, Orientation); +}; +#endif //TQT_NO_DIALOGBUTTONS +#endif //TQDIALOGBUTTONS_P_H diff --git a/src/widgets/tqiconview.h b/src/widgets/tqiconview.h index bffaad207..1be94b651 100644 --- a/src/widgets/tqiconview.h +++ b/src/widgets/tqiconview.h @@ -42,7 +42,7 @@ #define TQICONVIEW_H #ifndef QT_H -#include "ntqscrollview.h" +#include "tqscrollview.h" #include "tqstring.h" #include "tqrect.h" #include "tqpoint.h" diff --git a/src/widgets/tqlcdnumber.cpp b/src/widgets/tqlcdnumber.cpp new file mode 100644 index 000000000..e6dbf453c --- /dev/null +++ b/src/widgets/tqlcdnumber.cpp @@ -0,0 +1,1170 @@ +/**************************************************************************** +** +** Implementation of TQLCDNumber class +** +** Created : 940518 +** +** 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 "tqlcdnumber.h" +#ifndef TQT_NO_LCDNUMBER +#include "tqbitarray.h" +#include "tqpainter.h" + + +/*! + \class TQLCDNumber tqlcdnumber.h + + \brief The TQLCDNumber widget displays a number with LCD-like digits. + + \ingroup basic + \mainclass + + It can display a number in just about any size. It can display + decimal, hexadecimal, octal or binary numbers. It is easy to + connect to data sources using the display() slot, which is + overloaded to take any of five argument types. + + There are also slots to change the base with setMode() and the + decimal point with setSmallDecimalPoint(). + + TQLCDNumber emits the overflow() signal when it is asked to display + something beyond its range. The range is set by setNumDigits(), + but setSmallDecimalPoint() also influences it. If the display is + set to hexadecimal, octal or binary, the integer equivalent of the + value is displayed. + + These digits and other symbols can be shown: 0/O, 1, 2, 3, 4, 5/S, + 6, 7, 8, 9/g, minus, decimal point, A, B, C, D, E, F, h, H, L, o, + P, r, u, U, Y, colon, degree sign (which is specified as single + quote in the string) and space. TQLCDNumber substitutes spaces for + illegal characters. + + It is not possible to retrieve the contents of a TQLCDNumber + object, although you can retrieve the numeric value with value(). + If you really need the text, we recommend that you connect the + signals that feed the display() slot to another slot as well and + store the value there. + + Incidentally, TQLCDNumber is the very oldest part of TQt, tracing + back to a BASIC program on the \link + http://www.nvg.ntnu.no/sinclair/computers/zxspectrum/zxspectrum.htm + Sinclair Spectrum\endlink. + + + + \sa TQLabel, TQFrame +*/ + +/*! + \enum TQLCDNumber::Mode + + This type determines how numbers are shown. + + \value Hex Hexadecimal + \value Dec Decimal + \value Oct Octal + \value Bin Binary + + If the display is set to hexadecimal, octal or binary, the integer + equivalent of the value is displayed. +*/ + +/*! + \enum TQLCDNumber::SegmentStyle + + This type determines the visual appearance of the TQLCDNumber + widget. + + \value Outline gives raised segments filled with the background brush. + \value Filled gives raised segments filled with the foreground brush. + \value Flat gives flat segments filled with the foreground brush. +*/ + + + +/*! + \fn void TQLCDNumber::overflow() + + This signal is emitted whenever the TQLCDNumber is asked to display + a too-large number or a too-long string. + + It is never emitted by setNumDigits(). +*/ + + +static TQString int2string( int num, int base, int ndigits, bool *oflow ) +{ + TQString s; + bool negative; + if ( num < 0 ) { + negative = TRUE; + num = -num; + } else { + negative = FALSE; + } + switch( base ) { + case TQLCDNumber::HEX: + s.sprintf( "%*x", ndigits, num ); + break; + case TQLCDNumber::DEC: + s.sprintf( "%*i", ndigits, num ); + break; + case TQLCDNumber::OCT: + s.sprintf( "%*o", ndigits, num ); + break; + case TQLCDNumber::BIN: + { + char buf[42]; + char *p = &buf[41]; + uint n = num; + int len = 0; + *p = '\0'; + do { + *--p = (char)((n&1)+'0'); + n >>= 1; + len++; + } while ( n != 0 ); + len = ndigits - len; + if ( len > 0 ) + s.fill( ' ', len ); + s += TQString::fromLatin1(p); + } + break; + } + if ( negative ) { + for ( int i=0; i<(int)s.length(); i++ ) { + if ( s[i] != ' ' ) { + if ( i != 0 ) { + s[i-1] = '-'; + } else { + s.insert( 0, '-' ); + } + break; + } + } + } + if ( oflow ) + *oflow = (int)s.length() > ndigits; + return s; +} + + +static TQString double2string( double num, int base, int ndigits, bool *oflow ) +{ + TQString s; + if ( base != TQLCDNumber::DEC ) { + bool of = num >= 2147483648.0 || num < -2147483648.0; + if ( of ) { // oops, integer overflow + if ( oflow ) + *oflow = TRUE; + return s; + } + s = int2string( (int)num, base, ndigits, 0 ); + } else { // decimal base + int nd = ndigits; + do { + s.sprintf( "%*.*g", ndigits, nd, num ); + int i = s.find('e'); + if ( i > 0 && s[i+1]=='+' ) { + s[i] = ' '; + s[i+1] = 'e'; + } + } while (nd-- && (int)s.length() > ndigits); + } + if ( oflow ) + *oflow = (int)s.length() > ndigits; + return s; +} + + +static const char *getSegments( char ch ) // gets list of segments for ch +{ + static const char segments[30][8] = + { { 0, 1, 2, 4, 5, 6,99, 0}, // 0 0 / O + { 2, 5,99, 0, 0, 0, 0, 0}, // 1 1 + { 0, 2, 3, 4, 6,99, 0, 0}, // 2 2 + { 0, 2, 3, 5, 6,99, 0, 0}, // 3 3 + { 1, 2, 3, 5,99, 0, 0, 0}, // 4 4 + { 0, 1, 3, 5, 6,99, 0, 0}, // 5 5 / S + { 0, 1, 3, 4, 5, 6,99, 0}, // 6 6 + { 0, 2, 5,99, 0, 0, 0, 0}, // 7 7 + { 0, 1, 2, 3, 4, 5, 6,99}, // 8 8 + { 0, 1, 2, 3, 5, 6,99, 0}, // 9 9 / g + { 3,99, 0, 0, 0, 0, 0, 0}, // 10 - + { 7,99, 0, 0, 0, 0, 0, 0}, // 11 . + { 0, 1, 2, 3, 4, 5,99, 0}, // 12 A + { 1, 3, 4, 5, 6,99, 0, 0}, // 13 B + { 0, 1, 4, 6,99, 0, 0, 0}, // 14 C + { 2, 3, 4, 5, 6,99, 0, 0}, // 15 D + { 0, 1, 3, 4, 6,99, 0, 0}, // 16 E + { 0, 1, 3, 4,99, 0, 0, 0}, // 17 F + { 1, 3, 4, 5,99, 0, 0, 0}, // 18 h + { 1, 2, 3, 4, 5,99, 0, 0}, // 19 H + { 1, 4, 6,99, 0, 0, 0, 0}, // 20 L + { 3, 4, 5, 6,99, 0, 0, 0}, // 21 o + { 0, 1, 2, 3, 4,99, 0, 0}, // 22 P + { 3, 4,99, 0, 0, 0, 0, 0}, // 23 r + { 4, 5, 6,99, 0, 0, 0, 0}, // 24 u + { 1, 2, 4, 5, 6,99, 0, 0}, // 25 U + { 1, 2, 3, 5, 6,99, 0, 0}, // 26 Y + { 8, 9,99, 0, 0, 0, 0, 0}, // 27 : + { 0, 1, 2, 3,99, 0, 0, 0}, // 28 ' + {99, 0, 0, 0, 0, 0, 0, 0} }; // 29 empty + + if (ch >= '0' && ch <= '9') + return segments[ch - '0']; + if (ch >= 'A' && ch <= 'F') + return segments[ch - 'A' + 12]; + if (ch >= 'a' && ch <= 'f') + return segments[ch - 'a' + 12]; + + int n; + switch ( ch ) { + case '-': + n = 10; break; + case 'O': + n = 0; break; + case 'g': + n = 9; break; + case '.': + n = 11; break; + case 'h': + n = 18; break; + case 'H': + n = 19; break; + case 'l': + case 'L': + n = 20; break; + case 'o': + n = 21; break; + case 'p': + case 'P': + n = 22; break; + case 'r': + case 'R': + n = 23; break; + case 's': + case 'S': + n = 5; break; + case 'u': + n = 24; break; + case 'U': + n = 25; break; + case 'y': + case 'Y': + n = 26; break; + case ':': + n = 27; break; + case '\'': + n = 28; break; + default: + n = 29; break; + } + return segments[n]; +} + + +/*! + Constructs an LCD number, sets the number of digits to 5, the base + to decimal, the decimal point mode to 'small' and the frame style + to a raised box. The segmentStyle() is set to \c Outline. + + The \a parent and \a name arguments are passed to the TQFrame + constructor. + + \sa setNumDigits(), setSmallDecimalPoint() +*/ + +TQLCDNumber::TQLCDNumber( TQWidget *parent, const char *name ) + : TQFrame( parent, name ) +{ + ndigits = 5; + init(); +} + + +/*! + Constructs an LCD number, sets the number of digits to \a + numDigits, the base to decimal, the decimal point mode to 'small' + and the frame style to a raised box. The segmentStyle() is set to + \c Outline. + + The \a parent and \a name arguments are passed to the TQFrame + constructor. + + \sa setNumDigits(), setSmallDecimalPoint() +*/ + +TQLCDNumber::TQLCDNumber( uint numDigits, TQWidget *parent, const char *name ) + : TQFrame( parent, name ) +{ + ndigits = numDigits; + init(); +} + +/*! + \internal +*/ + +void TQLCDNumber::init() +{ + setFrameStyle( TQFrame::Box | TQFrame::Raised ); + val = 0; + base = DEC; + smallPoint = FALSE; + setNumDigits( ndigits ); + setSegmentStyle( Outline ); + d = 0; + setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) ); +} + +/*! + Destroys the LCD number. +*/ + +TQLCDNumber::~TQLCDNumber() +{ +} + + +/*! + \property TQLCDNumber::numDigits + \brief the current number of digits displayed + + Corresponds to the current number of digits. If \l + TQLCDNumber::smallDecimalPoint is FALSE, the decimal point occupies + one digit position. + + \sa numDigits, smallDecimalPoint +*/ + +void TQLCDNumber::setNumDigits( int numDigits ) +{ + if ( numDigits > 99 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQLCDNumber::setNumDigits: (%s) Max 99 digits allowed", + name( "unnamed" ) ); +#endif + numDigits = 99; + } + if (numDigits < 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQLCDNumber::setNumDigits: (%s) Min 0 digits allowed", + name( "unnamed" ) ); +#endif + numDigits = 0; + } + if ( digitStr.isNull() ) { // from constructor + ndigits = numDigits; + digitStr.fill( ' ', ndigits ); + points.fill( 0, ndigits ); + digitStr[ndigits - 1] = '0'; // "0" is the default number + } else { + bool doDisplay = ndigits == 0; + if ( numDigits == ndigits ) // no change + return; + int i; + int dif; + if ( numDigits > ndigits ) { // expand + dif = numDigits - ndigits; + TQString buf; + buf.fill( ' ', dif ); + digitStr.insert( 0, buf ); + points.resize( numDigits ); + for ( i=numDigits-1; i>=dif; i-- ) + points.setBit( i, points.testBit(i-dif) ); + for ( i=0; i=0; i-- ) { + buffer[ndigits - 1 - index + i] = buffer[i]; + newPoints.setBit( ndigits - 1 - index + i, + newPoints.testBit(i) ); + } + for( i=0; i xSegLen ? xSegLen : ySegLen; + int xAdvance = segLen*( 5 + digitSpace )/5; + int xOffset = ( width() - ndigits*xAdvance + segLen/5 )/2; + int yOffset = ( height() - segLen*2 )/2; + + for ( int i=0; itestBit(i) ? '.' : ' '; + if ( newString ) { + char oldPoint = points.testBit(i) ? '.' : ' '; + drawDigit( pos, p, segLen, newPoint, oldPoint ); + } else { + drawDigit( pos, p, segLen, newPoint ); + } + } + } + if ( newString ) { + digitStr = s; + if ( (int)digitStr.length() > ndigits ) + digitStr.truncate( ndigits ); + if ( newPoints ) + points = *newPoints; + } +} + + +/*! + \internal +*/ + +void TQLCDNumber::drawDigit( const TQPoint &pos, TQPainter &p, int segLen, + char newCh, char oldCh ) +{ +// Draws and/or erases segments to change display of a single digit +// from oldCh to newCh + + char updates[18][2]; // can hold 2 times number of segments, only + // first 9 used if segment table is correct + int nErases; + int nUpdates; + const char *segs; + int i,j; + + const char erase = 0; + const char draw = 1; + const char leaveAlone = 2; + + segs = getSegments(oldCh); + for ( nErases=0; segs[nErases] != 99; nErases++ ) { + updates[nErases][0] = erase; // get segments to erase to + updates[nErases][1] = segs[nErases]; // remove old char + } + nUpdates = nErases; + segs = getSegments(newCh); + for(i = 0 ; segs[i] != 99 ; i++) { + for ( j=0; j +#endif +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif + +#ifndef TQT_NO_ACCEL +#include "ntqkeysequence.h" +#define ACCEL_KEY(k) "\t" + TQString(TQKeySequence( TQt::CTRL | TQt::Key_ ## k )) +#else +#define ACCEL_KEY(k) "\t" + TQString("Ctrl+" #k) +#endif + +#if defined(Q_OS_LINUX) +#define LINUX_MEMLOCK_LIMIT_BYTES 16384 +#define LINUX_MEMLOCK_LIMIT_CHARACTERS LINUX_MEMLOCK_LIMIT_BYTES/sizeof(TQChar) +#endif + +#define innerMargin 1 + +struct TQLineEditPrivate : public TQt +{ + TQLineEditPrivate( TQLineEdit *q ) + : q(q), cursor(0), cursorTimer(0), tripleClickTimer(0), frame(1), + cursorVisible(0), separator(0), readOnly(0), modified(0), + direction(TQChar::DirON), dragEnabled(1), alignment(0), + echoMode(0), textDirty(0), selDirty(0), validInput(1), + ascent(0), maxLength(32767), menuId(0), + hscroll(0), validator(0), maskData(0), + undoState(0), selstart(0), selend(0), + imstart(0), imend(0), imselstart(0), imselend(0) +#ifndef TQT_NO_DRAGANDDROP + ,dndTimer(0) +#endif + {} + void init( const TQString&); + + TQLineEdit *q; + TQString text; + int cursor; + int cursorTimer; + TQPoint tripleClick; + int tripleClickTimer; + uint frame : 1; + uint cursorVisible : 1; + uint separator : 1; + uint readOnly : 1; + uint modified : 1; + uint direction : 5; + uint dragEnabled : 1; + uint alignment : 3; + uint echoMode : 2; + uint textDirty : 1; + uint selDirty : 1; + uint validInput : 1; + int ascent; + int maxLength; + int menuId; + int hscroll; + TQChar passwordChar; // obsolete + + void finishChange( int validateFromState = -1, bool setModified = TRUE ); + + const TQValidator* validator; + struct MaskInputData { + enum Casemode { NoCaseMode, Upper, Lower }; + TQChar maskChar; // either the separator char or the inputmask + bool separator; + Casemode caseMode; + }; + TQString inputMask; + TQChar blank; + MaskInputData *maskData; + inline int nextMaskBlank( int pos ) { + int c = findInMask( pos, TRUE, FALSE ); + separator |= ( c != pos ); + return ( c != -1 ? c : maxLength ); + } + inline int prevMaskBlank( int pos ) { + int c = findInMask( pos, FALSE, FALSE ); + separator |= ( c != pos ); + return ( c != -1 ? c : 0 ); + } + + void setCursorVisible( bool visible ); + + + // undo/redo handling + enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection }; + struct Command { + inline Command(){} + inline Command( CommandType type, int pos, TQChar c ) + :type(type),c(c),pos(pos){} + uint type : 4; + TQChar c; + int pos; + }; + int undoState; + TQValueVector history; + void addCommand( const Command& cmd ); + void insert( const TQString& s ); + void del( bool wasBackspace = FALSE ); + void remove( int pos ); + + inline void separate() { separator = TRUE; } + inline void undo( int until = -1 ) { + if ( !isUndoAvailable() ) + return; + deselect(); + while ( undoState && undoState > until ) { + Command& cmd = history[--undoState]; + switch ( cmd.type ) { + case Insert: + text.remove( cmd.pos, 1); + cursor = cmd.pos; + break; + case Remove: + case RemoveSelection: + text.insert( cmd.pos, cmd.c ); + cursor = cmd.pos + 1; + break; + case Delete: + case DeleteSelection: + text.insert( cmd.pos, cmd.c ); + cursor = cmd.pos; + break; + case Separator: + continue; + } + if ( until < 0 && undoState ) { + Command& next = history[undoState-1]; + if ( next.type != cmd.type && next.type < RemoveSelection + && !( cmd.type >= RemoveSelection && next.type != Separator ) ) + break; + } + } + modified = ( undoState != 0 ); + textDirty = TRUE; + } + inline void redo() { + if ( !isRedoAvailable() ) + return; + deselect(); + while ( undoState < (int)history.size() ) { + Command& cmd = history[undoState++]; + switch ( cmd.type ) { + case Insert: + text.insert( cmd.pos, cmd.c ); + cursor = cmd.pos + 1; + break; + case Remove: + case Delete: + case RemoveSelection: + case DeleteSelection: + text.remove( cmd.pos, 1 ); + cursor = cmd.pos; + break; + case Separator: + continue; + } + if ( undoState < (int)history.size() ) { + Command& next = history[undoState]; + if ( next.type != cmd.type && cmd.type < RemoveSelection + && !( next.type >= RemoveSelection && cmd.type != Separator ) ) + break; + } + } + textDirty = TRUE; + } + inline bool isUndoAvailable() const { return !readOnly && undoState; } + inline bool isRedoAvailable() const { return !readOnly && undoState < (int)history.size(); } + + // bidi + inline bool isRightToLeft() const { return direction==TQChar::DirON?text.isRightToLeft():(direction==TQChar::DirR); } + + // selection + int selstart, selend; + inline bool allSelected() const { return !text.isEmpty() && selstart == 0 && selend == (int)text.length(); } + inline bool hasSelectedText() const { return !text.isEmpty() && selend > selstart; } + inline void deselect() { selDirty |= (selend > selstart); selstart = selend = 0; } + void removeSelectedText(); +#ifndef TQT_NO_CLIPBOARD + void copy( bool clipboard = TRUE ) const; +#endif + inline bool inSelection( int x ) const + { if ( selstart >= selend ) return FALSE; + int pos = xToPos( x, TQTextItem::OnCharacters ); return pos >= selstart && pos < selend; } + + // masking + void parseInputMask( const TQString &maskFields ); + bool isValidInput( TQChar key, TQChar mask ) const; + TQString maskString( uint pos, const TQString &str, bool clear = FALSE ) const; + TQString clearString( uint pos, uint len ) const; + TQString stripString( const TQString &str ) const; + int findInMask( int pos, bool forward, bool findSeparator, TQChar searchChar = TQChar() ) const; + + // input methods + int imstart, imend, imselstart, imselend; + bool composeMode() const { return preeditLength(); } + bool hasIMSelection() const { return imSelectionLength(); } + int preeditLength() const { return ( imend - imstart ); } + int imSelectionLength() const { return ( imselend - imselstart ); } + + // complex text layout + TQTextLayout textLayout; + void updateTextLayout(); + void moveCursor( int pos, bool mark = FALSE ); + void setText( const TQString& txt ); + int xToPosInternal( int x, TQTextItem::CursorPosition ) const; + int xToPos( int x, TQTextItem::CursorPosition = TQTextItem::BetweenCharacters ) const; + inline int visualAlignment() const { return alignment ? alignment : int( isRightToLeft() ? AlignRight : AlignLeft ); } + TQRect cursorRect() const; + void updateMicroFocusHint(); + +#ifndef TQT_NO_DRAGANDDROP + // drag and drop + TQPoint dndPos; + int dndTimer; + bool drag(); +#endif +}; + + +/*! + \class TQLineEdit + \brief The TQLineEdit widget is a one-line text editor. + + \ingroup basic + \mainclass + + A line edit allows the user to enter and edit a single line of + plain text with a useful collection of editing functions, + including undo and redo, cut and paste, and drag and drop. + + By changing the echoMode() of a line edit, it can also be used as + a "write-only" field, for inputs such as passwords. + + The length of the text can be constrained to maxLength(). The text + can be arbitrarily constrained using a validator() or an + inputMask(), or both. + + A related class is TQTextEdit which allows multi-line, rich-text + editing. + + You can change the text with setText() or insert(). The text is + retrieved with text(); the displayed text (which may be different, + see \l{EchoMode}) is retrieved with displayText(). Text can be + selected with setSelection() or selectAll(), and the selection can + be cut(), copy()ied and paste()d. The text can be aligned with + setAlignment(). + + When the text changes the textChanged() signal is emitted; when + the Return or Enter key is pressed the returnPressed() signal is + emitted. Note that if there is a validator set on the line edit, + the returnPressed() signal will only be emitted if the validator + returns \c Acceptable. + + By default, TQLineEdits have a frame as specified by the Windows + and Motif style guides; you can turn it off by calling + setFrame(FALSE). + + The default key bindings are described below. The line edit also + provides a context menu (usually invoked by a right mouse click) + that presents some of these editing options. + \target desc + \table + \header \i Keypress \i Action + \row \i Left Arrow \i Moves the cursor one character to the left. + \row \i Shift+Left Arrow \i Moves and selects text one character to the left. + \row \i Right Arrow \i Moves the cursor one character to the right. + \row \i Shift+Right Arrow \i Moves and selects text one character to the right. + \row \i Home \i Moves the cursor to the beginning of the line. + \row \i End \i Moves the cursor to the end of the line. + \row \i Backspace \i Deletes the character to the left of the cursor. + \row \i Ctrl+Backspace \i Deletes the word to the left of the cursor. + \row \i Delete \i Deletes the character to the right of the cursor. + \row \i Ctrl+Delete \i Deletes the word to the right of the cursor. + \row \i Ctrl+A \i Moves the cursor to the beginning of the line. + \row \i Ctrl+B \i Moves the cursor one character to the left. + \row \i Ctrl+C \i Copies the selected text to the clipboard. + (Windows also supports Ctrl+Insert for this operation.) + \row \i Ctrl+D \i Deletes the character to the right of the cursor. + \row \i Ctrl+E \i Moves the cursor to the end of the line. + \row \i Ctrl+F \i Moves the cursor one character to the right. + \row \i Ctrl+H \i Deletes the character to the left of the cursor. + \row \i Ctrl+K \i Deletes to the end of the line. + \row \i Ctrl+V \i Pastes the clipboard text into line edit. + (Windows also supports Shift+Insert for this operation.) + \row \i Ctrl+X \i Deletes the selected text and copies it to the clipboard. + (Windows also supports Shift+Delete for this operation.) + \row \i Ctrl+Z \i Undoes the last operation. + \row \i Ctrl+Y \i Redoes the last undone operation. + \endtable + + Any other key sequence that represents a valid character, will + cause the character to be inserted into the line edit. + + + + \sa TQTextEdit TQLabel TQComboBox + \link guibooks.html#fowler GUI Design Handbook: Field, Entry\endlink +*/ + + +/*! + \fn void TQLineEdit::textChanged( const TQString& ) + + This signal is emitted whenever the text changes. The argument is + the new text. +*/ + +/*! + \fn void TQLineEdit::selectionChanged() + + This signal is emitted whenever the selection changes. + + \sa hasSelectedText(), selectedText() +*/ + +/*! + \fn void TQLineEdit::lostFocus() + + This signal is emitted when the line edit has lost focus. + + \sa hasFocus(), TQWidget::focusInEvent(), TQWidget::focusOutEvent() +*/ + + + +/*! + Constructs a line edit with no text. + + The maximum text length is set to 32767 characters. + + The \a parent and \a name arguments are sent to the TQWidget constructor. + + \sa setText(), setMaxLength() +*/ + +TQLineEdit::TQLineEdit( TQWidget* parent, const char* name ) + : TQFrame( parent, name, WNoAutoErase ), d(new TQLineEditPrivate( this )) +{ + d->init( TQString::null ); +} + +/*! + Constructs a line edit containing the text \a contents. + + The cursor position is set to the end of the line and the maximum + text length to 32767 characters. + + The \a parent and \a name arguments are sent to the TQWidget + constructor. + + \sa text(), setMaxLength() +*/ + +TQLineEdit::TQLineEdit( const TQString& contents, TQWidget* parent, const char* name ) + : TQFrame( parent, name, WNoAutoErase ), d(new TQLineEditPrivate( this )) +{ + d->init( contents ); +} + +/*! + Constructs a line edit with an input \a inputMask and the text \a + contents. + + The cursor position is set to the end of the line and the maximum + text length is set to the length of the mask (the number of mask + characters and separators). + + The \a parent and \a name arguments are sent to the TQWidget + constructor. + + \sa setMask() text() +*/ +TQLineEdit::TQLineEdit( const TQString& contents, const TQString &inputMask, TQWidget* parent, const char* name ) + : TQFrame( parent, name, WNoAutoErase ), d(new TQLineEditPrivate( this )) +{ + d->parseInputMask( inputMask ); + if ( d->maskData ) { + TQString ms = d->maskString( 0, contents ); + d->init( ms + d->clearString( ms.length(), d->maxLength - ms.length() ) ); + d->cursor = d->nextMaskBlank( ms.length() ); + } else { + d->init( contents ); + } +} + +/*! + Destroys the line edit. +*/ + +TQLineEdit::~TQLineEdit() +{ + if ((d->echoMode == NoEcho) || (d->echoMode == Password) || (d->echoMode == PasswordThreeStars)) { + d->text.fill(TQChar(0)); +#if defined(Q_OS_LINUX) + munlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); +#endif + } + delete [] d->maskData; + delete d; +} + + +/*! + \property TQLineEdit::text + \brief the line edit's text + + Note that setting this property clears the selection, clears the + undo/redo history, moves the cursor to the end of the line and + resets the \c modified property to FALSE. The text is not + validated when inserted with setText(). + + The text is truncated to maxLength() length. + + \sa insert() +*/ +TQString TQLineEdit::text() const +{ + TQString res = d->text; + if ( d->maskData ) + res = d->stripString( d->text ); + return ( res.isNull() ? TQString::fromLatin1("") : res ); +} + +void TQLineEdit::setText( const TQString& text) +{ + resetInputContext(); + d->setText( text ); + d->modified = FALSE; + d->finishChange( -1, FALSE ); +} + + +/*! + \property TQLineEdit::displayText + \brief the displayed text + + If \c EchoMode is \c Normal this returns the same as text(); if + \c EchoMode is \c Password it returns a string of asterisks + text().length() characters long, e.g. "******"; if \c EchoMode is + \c NoEcho returns an empty string, "". + + \sa setEchoMode() text() EchoMode +*/ + +TQString TQLineEdit::displayText() const +{ + if ( d->echoMode == NoEcho ) { + return TQString::fromLatin1(""); + } + TQString res = d->text; + if ( d->echoMode == Password ) { + res.fill( passwordChar() ); + } + else if ( d->echoMode == PasswordThreeStars ) { + res.fill( passwordChar(), res.length()*3 ); + } + return ( res.isNull() ? TQString::fromLatin1("") : res ); +} + + +/*! + \property TQLineEdit::maxLength + \brief the maximum permitted length of the text + + If the text is too long, it is truncated at the limit. + + If truncation occurs any selected text will be unselected, the + cursor position is set to 0 and the first part of the string is + shown. + + If the line edit has an input mask, the mask defines the maximum + string length. + + \sa inputMask +*/ + +int TQLineEdit::maxLength() const +{ + return d->maxLength; +} + +void TQLineEdit::setMaxLength( int maxLength ) +{ + if ( d->maskData ) + return; + d->maxLength = maxLength; + setText( d->text ); +} + + + +/*! + \property TQLineEdit::frame + \brief whether the line edit draws itself with a frame + + If enabled (the default) the line edit draws itself inside a + two-pixel frame, otherwise the line edit draws itself without any + frame. +*/ +bool TQLineEdit::frame() const +{ + return frameShape() != NoFrame; +} + + +void TQLineEdit::setFrame( bool enable ) +{ + setFrameStyle( enable ? ( LineEditPanel | Sunken ) : NoFrame ); +} + + +/*! + \enum TQLineEdit::EchoMode + + This enum type describes how a line edit should display its + contents. + + \value Normal Display characters as they are entered. This is the + default. + \value NoEcho Do not display anything. This may be appropriate + for passwords where even the length of the + password should be kept secret. + \value Password Display asterisks instead of the characters + actually entered. + + \sa setEchoMode() echoMode() +*/ + + +/*! + \property TQLineEdit::echoMode + \brief the line edit's echo mode + + The initial setting is \c Normal, but TQLineEdit also supports \c + NoEcho and \c Password modes. + + The widget's display and the ability to copy or drag the text is + affected by this setting. + + \sa EchoMode displayText() +*/ + +TQLineEdit::EchoMode TQLineEdit::echoMode() const +{ + return (EchoMode) d->echoMode; +} + +void TQLineEdit::setEchoMode( EchoMode mode ) +{ + if (mode == (EchoMode)d->echoMode) { + return; + } +#if defined(Q_OS_LINUX) + if (((mode == NoEcho) || (mode == Password) || (mode == PasswordThreeStars)) && ((EchoMode)d->echoMode == Normal)) { + if ((uint)d->maxLength > (LINUX_MEMLOCK_LIMIT_CHARACTERS-1)) { + d->maxLength = LINUX_MEMLOCK_LIMIT_CHARACTERS-1; + } + d->text.reserve(LINUX_MEMLOCK_LIMIT_CHARACTERS); + mlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); + d->text.setSecurityUnPaged(true); + } + else { + d->text.setSecurityUnPaged(false); + munlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); + } +#endif + d->echoMode = mode; + d->updateTextLayout(); + setInputMethodEnabled( ( mode == Normal ) || ( mode == Password) ); + update(); +} + + + +/*! + Returns a pointer to the current input validator, or 0 if no + validator has been set. + + \sa setValidator() +*/ + +const TQValidator * TQLineEdit::validator() const +{ + return d->validator; +} + +/*! + Sets this line edit to only accept input that the validator, \a v, + will accept. This allows you to place any arbitrary constraints on + the text which may be entered. + + If \a v == 0, setValidator() removes the current input validator. + The initial setting is to have no input validator (i.e. any input + is accepted up to maxLength()). + + \sa validator() TQIntValidator TQDoubleValidator TQRegExpValidator +*/ + +void TQLineEdit::setValidator( const TQValidator *v ) +{ + if ( d->validator ) + disconnect( (TQObject*)d->validator, TQ_SIGNAL( destroyed() ), + this, TQ_SLOT( clearValidator() ) ); + d->validator = v; + if ( d->validator ) + connect( (TQObject*)d->validator, TQ_SIGNAL( destroyed() ), + this, TQ_SLOT( clearValidator() ) ); +} + + + +/*! + Returns a recommended size for the widget. + + The width returned, in pixels, is usually enough for about 15 to + 20 characters. +*/ + +TQSize TQLineEdit::sizeHint() const +{ + constPolish(); + TQFontMetrics fm( font() ); + int h = TQMAX(fm.lineSpacing(), 14) + 2*innerMargin; + int w = fm.width( 'x' ) * 17; // "some" + int m = frameWidth() * 2; + return (style().sizeFromContents(TQStyle::CT_LineEdit, this, + TQSize( w + m, h + m ). + expandedTo(TQApplication::globalStrut()))); +} + + +/*! + Returns a minimum size for the line edit. + + The width returned is enough for at least one character. +*/ + +TQSize TQLineEdit::minimumSizeHint() const +{ + constPolish(); + TQFontMetrics fm = fontMetrics(); + int h = fm.height() + TQMAX( 2*innerMargin, fm.leading() ); + int w = fm.maxWidth(); + int m = frameWidth() * 2; + return TQSize( w + m, h + m ); +} + + +/*! + \property TQLineEdit::cursorPosition + \brief the current cursor position for this line edit + + Setting the cursor position causes a repaint when appropriate. +*/ + +int TQLineEdit::cursorPosition() const +{ + return d->cursor; +} + + +void TQLineEdit::setCursorPosition( int pos ) +{ + if (pos < 0) + pos = 0; + + if ( pos <= (int) d->text.length() ) + d->moveCursor( pos ); +} + + +/*! \obsolete Use setText(), setCursorPosition() and setSelection() instead. +*/ + +bool TQLineEdit::validateAndSet( const TQString &newText, int newPos, + int newMarkAnchor, int newMarkDrag ) +{ + int priorState = d->undoState; + d->selstart = 0; + d->selend = d->text.length(); + d->removeSelectedText(); + d->insert( newText ); + d->finishChange( priorState ); + if ( d->undoState > priorState ) { + d->cursor = newPos; + d->selstart = TQMIN( newMarkAnchor, newMarkDrag ); + d->selend = TQMAX( newMarkAnchor, newMarkDrag ); + d->updateMicroFocusHint(); + update(); + return TRUE; + } + return FALSE; +} + + +/*! + \property TQLineEdit::alignment + \brief the alignment of the line edit + + Possible Values are \c TQt::AlignAuto, \c TQt::AlignLeft, \c + TQt::AlignRight and \c TQt::AlignHCenter. + + Attempting to set the alignment to an illegal flag combination + does nothing. + + \sa TQt::AlignmentFlags +*/ + +int TQLineEdit::alignment() const +{ + return d->alignment; +} + +void TQLineEdit::setAlignment( int flag ) +{ + d->alignment = flag & 0x7; + update(); +} + + +/*! + Moves the cursor forward \a steps characters. If \a mark is TRUE + each character moved over is added to the selection; if \a mark is + FALSE the selection is cleared. + + \sa cursorBackward() +*/ + +void TQLineEdit::cursorForward( bool mark, int steps ) +{ + int cursor = d->cursor; + if ( steps > 0 ) { + while( steps-- ) + cursor = d->textLayout.nextCursorPosition( cursor ); + } else if ( steps < 0 ) { + while ( steps++ ) + cursor = d->textLayout.previousCursorPosition( cursor ); + } + d->moveCursor( cursor, mark ); +} + + +/*! + Moves the cursor back \a steps characters. If \a mark is TRUE each + character moved over is added to the selection; if \a mark is + FALSE the selection is cleared. + + \sa cursorForward() +*/ +void TQLineEdit::cursorBackward( bool mark, int steps ) +{ + cursorForward( mark, -steps ); +} + +/*! + Moves the cursor one word forward. If \a mark is TRUE, the word is + also selected. + + \sa cursorWordBackward() +*/ +void TQLineEdit::cursorWordForward( bool mark ) +{ + d->moveCursor( d->textLayout.nextCursorPosition(d->cursor, TQTextLayout::SkipWords), mark ); +} + +/*! + Moves the cursor one word backward. If \a mark is TRUE, the word + is also selected. + + \sa cursorWordForward() +*/ + +void TQLineEdit::cursorWordBackward( bool mark ) +{ + d->moveCursor( d->textLayout.previousCursorPosition(d->cursor, TQTextLayout::SkipWords), mark ); +} + + +/*! + If no text is selected, deletes the character to the left of the + text cursor and moves the cursor one position to the left. If any + text is selected, the cursor is moved to the beginning of the + selected text and the selected text is deleted. + + \sa del() +*/ +void TQLineEdit::backspace() +{ + int priorState = d->undoState; + if ( d->hasSelectedText() ) { + d->removeSelectedText(); + } else if ( d->cursor ) { + --d->cursor; + if ( d->maskData ) + d->cursor = d->prevMaskBlank( d->cursor ); + d->del( TRUE ); + } + d->finishChange( priorState ); +} + +/*! + If no text is selected, deletes the character to the right of the + text cursor. If any text is selected, the cursor is moved to the + beginning of the selected text and the selected text is deleted. + + \sa backspace() +*/ + +void TQLineEdit::del() +{ + int priorState = d->undoState; + if ( d->hasSelectedText() ) { + d->removeSelectedText(); + } else { + int n = d->textLayout.nextCursorPosition( d->cursor ) - d->cursor; + while ( n-- ) + d->del(); + } + d->finishChange( priorState ); +} + +/*! + Moves the text cursor to the beginning of the line unless it is + already there. If \a mark is TRUE, text is selected towards the + first position; otherwise, any selected text is unselected if the + cursor is moved. + + \sa end() +*/ + +void TQLineEdit::home( bool mark ) +{ + d->moveCursor( 0, mark ); +} + +/*! + Moves the text cursor to the end of the line unless it is already + there. If \a mark is TRUE, text is selected towards the last + position; otherwise, any selected text is unselected if the cursor + is moved. + + \sa home() +*/ + +void TQLineEdit::end( bool mark ) +{ + d->moveCursor( d->text.length(), mark ); +} + + +/*! + \property TQLineEdit::modified + \brief whether the line edit's contents has been modified by the user + + The modified flag is never read by TQLineEdit; it has a default value + of FALSE and is changed to TRUE whenever the user changes the line + edit's contents. + + This is useful for things that need to provide a default value but + do not start out knowing what the default should be (perhaps it + depends on other fields on the form). Start the line edit without + the best default, and when the default is known, if modified() + returns FALSE (the user hasn't entered any text), insert the + default value. + + Calling clearModified() or setText() resets the modified flag to + FALSE. +*/ + +bool TQLineEdit::isModified() const +{ + return d->modified; +} + +/*! + Resets the modified flag to FALSE. + + \sa isModified() +*/ +void TQLineEdit::clearModified() +{ + d->modified = FALSE; + d->history.clear(); + d->undoState = 0; +} + +/*! + \obsolete + \property TQLineEdit::edited + \brief whether the line edit has been edited. Use modified instead. +*/ +bool TQLineEdit::edited() const { return d->modified; } +void TQLineEdit::setEdited( bool on ) { d->modified = on; } + +/*! + \property TQLineEdit::hasSelectedText + \brief whether there is any text selected + + hasSelectedText() returns TRUE if some or all of the text has been + selected by the user; otherwise returns FALSE. + + \sa selectedText() +*/ + + +bool TQLineEdit::hasSelectedText() const +{ + return d->hasSelectedText(); +} + +/*! + \property TQLineEdit::selectedText + \brief the selected text + + If there is no selected text this property's value is + TQString::null. + + \sa hasSelectedText() +*/ + +TQString TQLineEdit::selectedText() const +{ + if ( d->hasSelectedText() ) + return d->text.mid( d->selstart, d->selend - d->selstart ); + return TQString::null; +} + +/*! + selectionStart() returns the index of the first selected character in the + line edit or -1 if no text is selected. + + \sa selectedText() +*/ + +int TQLineEdit::selectionStart() const +{ + return d->hasSelectedText() ? d->selstart : -1; +} + +/*! \obsolete use selectedText(), selectionStart() */ +bool TQLineEdit::getSelection( int *start, int *end ) +{ + if ( d->hasSelectedText() && start && end ) { + *start = d->selstart; + *end = d->selend; + return TRUE; + } + return FALSE; +} + + +/*! + Selects text from position \a start and for \a length characters. + + Note that this function sets the cursor's position to the end of + the selection regardless of its current position. + + \sa deselect() selectAll() getSelection() cursorForward() cursorBackward() +*/ + +void TQLineEdit::setSelection( int start, int length ) +{ + if ( start < 0 || start > (int)d->text.length() || length < 0 ) { + d->selstart = d->selend = 0; + } else { + d->selstart = start; + d->selend = TQMIN( start + length, (int)d->text.length() ); + d->cursor = d->selend; + } + update(); +} + + +/*! + \property TQLineEdit::undoAvailable + \brief whether undo is available +*/ + +bool TQLineEdit::isUndoAvailable() const +{ + return d->isUndoAvailable(); +} + +/*! + \property TQLineEdit::redoAvailable + \brief whether redo is available +*/ + +bool TQLineEdit::isRedoAvailable() const +{ + return d->isRedoAvailable(); +} + +/*! + \property TQLineEdit::dragEnabled + \brief whether the lineedit starts a drag if the user presses and + moves the mouse on some selected text +*/ + +bool TQLineEdit::dragEnabled() const +{ + return d->dragEnabled; +} + +void TQLineEdit::setDragEnabled( bool b ) +{ + d->dragEnabled = b; +} + +/*! + \property TQLineEdit::acceptableInput + \brief whether the input satisfies the inputMask and the + validator. + + \sa setInputMask(), setValidator() +*/ +bool TQLineEdit::hasAcceptableInput() const +{ +#ifndef TQT_NO_VALIDATOR + TQString text = d->text; + int cursor = d->cursor; + if ( d->validator && d->validator->validate( text, cursor ) != TQValidator::Acceptable ) + return FALSE; +#endif + + if ( !d->maskData ) + return TRUE; + + if ( d->text.length() != (uint)d->maxLength ) + return FALSE; + + for ( uint i=0; i < (uint)d->maxLength; i++) { + if ( d->maskData[i].separator ) { + if ( d->text[(int)i] != d->maskData[i].maskChar ) + return FALSE; + } else { + if ( !d->isValidInput( d->text[(int)i], d->maskData[i].maskChar ) ) + return FALSE; + } + } + return TRUE; +} + + +/*! + \property TQLineEdit::inputMask + \brief The validation input mask + + If no mask is set, inputMask() returns TQString::null. + + Sets the TQLineEdit's validation mask. Validators can be used + instead of, or in conjunction with masks; see setValidator(). + + Unset the mask and return to normal TQLineEdit operation by passing + an empty string ("") or just calling setInputMask() with no + arguments. + + The mask format understands these mask characters: + \table + \header \i Character \i Meaning + \row \i \c A \i ASCII alphabetic character required. A-Z, a-z. + \row \i \c a \i ASCII alphabetic character permitted but not required. + \row \i \c N \i ASCII alphanumeric character required. A-Z, a-z, 0-9. + \row \i \c n \i ASCII alphanumeric character permitted but not required. + \row \i \c X \i Any character required. + \row \i \c x \i Any character permitted but not required. + \row \i \c 9 \i ASCII digit required. 0-9. + \row \i \c 0 \i ASCII digit permitted but not required. + \row \i \c D \i ASCII digit required. 1-9. + \row \i \c d \i ASCII digit permitted but not required (1-9). + \row \i \c # \i ASCII digit or plus/minus sign permitted but not required. + \row \i \c > \i All following alphabetic characters are uppercased. + \row \i \c < \i All following alphabetic characters are lowercased. + \row \i \c ! \i Switch off case conversion. + \row \i \\ \i Use \\ to escape the special + characters listed above to use them as + separators. + \endtable + + The mask consists of a string of mask characters and separators, + optionally followed by a semi-colon and the character used for + blanks: the blank characters are always removed from the text + after editing. The default blank character is space. + + Examples: + \table + \header \i Mask \i Notes + \row \i \c 000.000.000.000;_ \i IP address; blanks are \c{_}. + \row \i \c 0000-00-00 \i ISO Date; blanks are \c space + \row \i \c >AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;# \i License number; + blanks are \c - and all (alphabetic) characters are converted to + uppercase. + \endtable + + To get range control (e.g. for an IP address) use masks together + with \link setValidator() validators\endlink. + + \sa maxLength +*/ +TQString TQLineEdit::inputMask() const +{ + return ( d->maskData ? d->inputMask + ';' + d->blank : TQString::null ); +} + +void TQLineEdit::setInputMask( const TQString &inputMask ) +{ + d->parseInputMask( inputMask ); + if ( d->maskData ) + d->moveCursor( d->nextMaskBlank( 0 ) ); +} + +/*! + Selects all the text (i.e. highlights it) and moves the cursor to + the end. This is useful when a default value has been inserted + because if the user types before clicking on the widget, the + selected text will be deleted. + + \sa setSelection() deselect() +*/ + +void TQLineEdit::selectAll() +{ + d->selstart = d->selend = d->cursor = 0; + d->moveCursor( d->text.length(), TRUE ); +} + +/*! + Deselects any selected text. + + \sa setSelection() selectAll() +*/ + +void TQLineEdit::deselect() +{ + d->deselect(); + d->finishChange(); +} + + +/*! + This slot is equivalent to setValidator(0). +*/ + +void TQLineEdit::clearValidator() +{ + setValidator( 0 ); +} + +/*! + Deletes any selected text, inserts \a newText, and validates the + result. If it is valid, it sets it as the new contents of the line + edit. +*/ +void TQLineEdit::insert( const TQString &newText ) +{ +// q->resetInputContext(); //#### FIX ME IN QT + int priorState = d->undoState; + d->removeSelectedText(); + d->insert( newText ); + d->finishChange( priorState ); +} + +/*! + Clears the contents of the line edit. +*/ +void TQLineEdit::clear() +{ + int priorState = d->undoState; + resetInputContext(); + d->selstart = 0; + d->selend = d->text.length(); + d->removeSelectedText(); + d->separate(); + d->finishChange( priorState ); +} + +/*! + Undoes the last operation if undo is \link + TQLineEdit::undoAvailable available\endlink. Deselects any current + selection, and updates the selection start to the current cursor + position. +*/ +void TQLineEdit::undo() +{ + resetInputContext(); + d->undo(); + d->finishChange( -1, FALSE ); +} + +/*! + Redoes the last operation if redo is \link + TQLineEdit::redoAvailable available\endlink. +*/ +void TQLineEdit::redo() +{ + resetInputContext(); + d->redo(); + d->finishChange(); +} + + +/*! + \property TQLineEdit::readOnly + \brief whether the line edit is read only. + + In read-only mode, the user can still copy the text to the + clipboard or drag-and-drop the text (if echoMode() is \c Normal), + but cannot edit it. + + TQLineEdit does not show a cursor in read-only mode. + + \sa setEnabled() +*/ + +bool TQLineEdit::isReadOnly() const +{ + return d->readOnly; +} + +void TQLineEdit::setReadOnly( bool enable ) +{ + d->readOnly = enable; +#ifndef TQT_NO_CURSOR + setCursor( enable ? arrowCursor : ibeamCursor ); +#endif + update(); +} + + +#ifndef TQT_NO_CLIPBOARD +/*! + Copies the selected text to the clipboard and deletes it, if there + is any, and if echoMode() is \c Normal. + + If the current validator disallows deleting the selected text, + cut() will copy without deleting. + + \sa copy() paste() setValidator() +*/ + +void TQLineEdit::cut() +{ + if ( hasSelectedText() ) { + copy(); + del(); + } +} + + +/*! + Copies the selected text to the clipboard, if there is any, and if + echoMode() is \c Normal. + + \sa cut() paste() +*/ + +void TQLineEdit::copy() const +{ + d->copy(); +} + +/*! + Inserts the clipboard's text at the cursor position, deleting any + selected text, providing the line edit is not \link + TQLineEdit::readOnly read-only\endlink. + + If the end result would not be acceptable to the current + \link setValidator() validator\endlink, nothing happens. + + \sa copy() cut() +*/ + +void TQLineEdit::paste() +{ + insert( TQApplication::clipboard()->text( TQClipboard::Clipboard ) ); +} + +void TQLineEditPrivate::copy( bool clipboard ) const +{ + TQString t = q->selectedText(); + if ( !t.isEmpty() && echoMode == TQLineEdit::Normal ) { + q->disconnect( TQApplication::clipboard(), TQ_SIGNAL(selectionChanged()), q, 0); + TQApplication::clipboard()->setText( t, clipboard ? TQClipboard::Clipboard : TQClipboard::Selection ); + q->connect( TQApplication::clipboard(), TQ_SIGNAL(selectionChanged()), + q, TQ_SLOT(clipboardChanged()) ); + } +} + +#endif // !TQT_NO_CLIPBOARD + +/*!\reimp +*/ + +void TQLineEdit::resizeEvent( TQResizeEvent *e ) +{ + TQFrame::resizeEvent( e ); +} + +/*! \reimp +*/ +bool TQLineEdit::event( TQEvent * e ) +{ + if ( e->type() == TQEvent::AccelOverride && !d->readOnly ) { + TQKeyEvent* ke = (TQKeyEvent*) e; + if ( ke->state() == NoButton || ke->state() == ShiftButton + || ke->state() == Keypad ) { + if ( ke->key() < Key_Escape ) { + ke->accept(); + } else { + switch ( ke->key() ) { + case Key_Delete: + case Key_Home: + case Key_End: + case Key_Backspace: + case Key_Left: + case Key_Right: + ke->accept(); + default: + break; + } + } + } else if ( ke->state() & ControlButton ) { + switch ( ke->key() ) { +// Those are too frequently used for application functionality +/* case Key_A: + case Key_B: + case Key_D: + case Key_E: + case Key_F: + case Key_H: + case Key_K: +*/ + case Key_C: + case Key_V: + case Key_X: + case Key_Y: + case Key_Z: + case Key_Left: + case Key_Right: +#if defined (TQ_WS_WIN) + case Key_Insert: + case Key_Delete: +#endif + ke->accept(); + default: + break; + } + } + } else if ( e->type() == TQEvent::Timer ) { + // should be timerEvent, is here for binary compatibility + int timerId = ((TQTimerEvent*)e)->timerId(); + if ( timerId == d->cursorTimer ) { + if(!hasSelectedText() || style().styleHint( TQStyle::SH_BlinkCursorWhenTextSelected )) + d->setCursorVisible( !d->cursorVisible ); +#ifndef TQT_NO_DRAGANDDROP + } else if ( timerId == d->dndTimer ) { + if( !d->drag() ) + return TRUE; +#endif + } else if ( timerId == d->tripleClickTimer ) { + killTimer( d->tripleClickTimer ); + d->tripleClickTimer = 0; + } + } + return TQWidget::event( e ); +} + +/*! \reimp +*/ +void TQLineEdit::mousePressEvent( TQMouseEvent* e ) +{ + if ( sendMouseEventToInputContext( e ) ) + return; + if ( e->button() == RightButton ) + return; + if ( d->tripleClickTimer && ( e->pos() - d->tripleClick ).manhattanLength() < + TQApplication::startDragDistance() ) { + selectAll(); + return; + } + bool mark = e->state() & ShiftButton; + int cursor = d->xToPos( e->pos().x() ); +#ifndef TQT_NO_DRAGANDDROP + if ( !mark && d->dragEnabled && d->echoMode == Normal && + e->button() == LeftButton && d->inSelection( e->pos().x() ) ) { + d->cursor = cursor; + d->updateMicroFocusHint(); + update(); + d->dndPos = e->pos(); + if ( !d->dndTimer ) + d->dndTimer = startTimer( TQApplication::startDragTime() ); + } else +#endif + { + d->moveCursor( cursor, mark ); + } +} + +/*! \reimp +*/ +void TQLineEdit::mouseMoveEvent( TQMouseEvent * e ) +{ + if ( sendMouseEventToInputContext( e ) ) + return; +#ifndef TQT_NO_CURSOR + if ( ( e->state() & MouseButtonMask ) == 0 ) { + if ( !d->readOnly && d->dragEnabled +#ifndef TQT_NO_WHATSTHIS + && !TQWhatsThis::inWhatsThisMode() +#endif + ) + setCursor( ( d->inSelection( e->pos().x() ) ? arrowCursor : ibeamCursor ) ); + } +#endif + + if ( e->state() & LeftButton ) { +#ifndef TQT_NO_DRAGANDDROP + if ( d->dndTimer ) { + if ( ( d->dndPos - e->pos() ).manhattanLength() > TQApplication::startDragDistance() ) + d->drag(); + } else +#endif + { + d->moveCursor( d->xToPos( e->pos().x() ), TRUE ); + } + } +} + +/*! \reimp +*/ +void TQLineEdit::mouseReleaseEvent( TQMouseEvent* e ) +{ + if ( sendMouseEventToInputContext( e ) ) + return; +#ifndef TQT_NO_DRAGANDDROP + if ( e->button() == LeftButton ) { + if ( d->dndTimer ) { + killTimer( d->dndTimer ); + d->dndTimer = 0; + deselect(); + return; + } + } +#endif +#ifndef TQT_NO_CLIPBOARD + if (TQApplication::clipboard()->supportsSelection() ) { + if ( e->button() == LeftButton ) { + d->copy( FALSE ); + } else if ( !d->readOnly && e->button() == MidButton ) { + d->deselect(); + insert( TQApplication::clipboard()->text( TQClipboard::Selection ) ); + } + } +#endif +} + +/*! \reimp +*/ +void TQLineEdit::mouseDoubleClickEvent( TQMouseEvent* e ) +{ + if ( sendMouseEventToInputContext( e ) ) + return; + if ( e->button() == TQt::LeftButton ) { + deselect(); + d->cursor = d->xToPos( e->pos().x() ); + d->cursor = d->textLayout.previousCursorPosition( d->cursor, TQTextLayout::SkipWords ); + // ## text layout should support end of words. + int end = d->textLayout.nextCursorPosition( d->cursor, TQTextLayout::SkipWords ); + while ( end > d->cursor && d->text[end-1].isSpace() ) + --end; + d->moveCursor( end, TRUE ); + d->tripleClickTimer = startTimer( TQApplication::doubleClickInterval() ); + d->tripleClick = e->pos(); + } +} + +/*! + \fn void TQLineEdit::returnPressed() + + This signal is emitted when the Return or Enter key is pressed. + Note that if there is a validator() or inputMask() set on the line + edit, the returnPressed() signal will only be emitted if the input + follows the inputMask() and the validator() returns \c Acceptable. +*/ + +/*! + Converts key press event \a e into a line edit action. + + If Return or Enter is pressed and the current text is valid (or + can be \link TQValidator::fixup() made valid\endlink by the + validator), the signal returnPressed() is emitted. + + The default key bindings are listed in the \link #desc detailed + description.\endlink +*/ + +void TQLineEdit::keyPressEvent( TQKeyEvent * e ) +{ + d->setCursorVisible( TRUE ); + if ( e->key() == Key_Enter || e->key() == Key_Return ) { + const TQValidator * v = d->validator; + if ( hasAcceptableInput() ) { + emit returnPressed(); + } +#ifndef TQT_NO_VALIDATOR + else if ( v && v->validate( d->text, d->cursor ) != TQValidator::Acceptable ) { + TQString vstr = d->text; + v->fixup( vstr ); + if ( vstr != d->text ) { + setText( vstr ); + if ( hasAcceptableInput() ) + emit returnPressed(); + } + } +#endif + e->ignore(); + return; + } + if ( !d->readOnly ) { + TQString t = e->text(); + if ( !t.isEmpty() && (!e->ascii() || e->ascii()>=32) && + e->key() != Key_Delete && + e->key() != Key_Backspace ) { +#ifdef TQ_WS_X11 + extern bool tqt_hebrew_keyboard_hack; + if ( tqt_hebrew_keyboard_hack ) { + // the X11 keyboard layout is broken and does not reverse + // braces correctly. This is a hack to get halfway correct + // behaviour + if ( d->isRightToLeft() ) { + TQChar *c = (TQChar *)t.unicode(); + int l = t.length(); + while( l-- ) { + if ( c->mirrored() ) + *c = c->mirroredChar(); + c++; + } + } + } +#endif + insert( t ); + return; + } + } + bool unknown = FALSE; + if ( e->state() & ControlButton ) { + switch ( e->key() ) { + case Key_A: +#if defined(TQ_WS_X11) + home( e->state() & ShiftButton ); +#else + selectAll(); +#endif + break; + case Key_B: + cursorForward( e->state() & ShiftButton, -1 ); + break; +#ifndef TQT_NO_CLIPBOARD + case Key_C: + copy(); + break; +#endif + case Key_D: + if ( !d->readOnly ) { + del(); + } + break; + case Key_E: + end( e->state() & ShiftButton ); + break; + case Key_F: + cursorForward( e->state() & ShiftButton, 1 ); + break; + case Key_H: + if ( !d->readOnly ) { + backspace(); + } + break; + case Key_K: + if ( !d->readOnly ) { + int priorState = d->undoState; + d->deselect(); + while ( d->cursor < (int) d->text.length() ) + d->del(); + d->finishChange( priorState ); + } + break; +#if defined(TQ_WS_X11) + case Key_U: + if ( !d->readOnly ) + clear(); + break; +#endif +#ifndef TQT_NO_CLIPBOARD + case Key_V: + if ( !d->readOnly ) + paste(); + break; + case Key_X: + if ( !d->readOnly && d->hasSelectedText() && echoMode() == Normal ) { + copy(); + del(); + } + break; +#if defined (TQ_WS_WIN) + case Key_Insert: + copy(); + break; +#endif +#endif + case Key_Delete: + if ( !d->readOnly ) { + cursorWordForward( TRUE ); + del(); + } + break; + case Key_Backspace: + if ( !d->readOnly ) { + cursorWordBackward( TRUE ); + del(); + } + break; + case Key_Right: + case Key_Left: + if ( d->isRightToLeft() == (e->key() == Key_Right) ) { + if (( echoMode() == Normal ) || ( echoMode() == Password )) + cursorWordBackward( e->state() & ShiftButton ); + else + home( e->state() & ShiftButton ); + } else { + if (( echoMode() == Normal ) || ( echoMode() == Password )) + cursorWordForward( e->state() & ShiftButton ); + else + end( e->state() & ShiftButton ); + } + break; + case Key_Z: + if ( !d->readOnly ) { + if(e->state() & ShiftButton) + redo(); + else + undo(); + } + break; + case Key_Y: + if ( !d->readOnly ) + redo(); + break; + default: + unknown = TRUE; + } + } else { // ### check for *no* modifier + switch ( e->key() ) { + case Key_Shift: + // ### TODO + break; + case Key_Left: + case Key_Right: { + int step = (d->isRightToLeft() == (e->key() == Key_Right)) ? -1 : 1; + cursorForward( e->state() & ShiftButton, step ); + } + break; + case Key_Backspace: + if ( !d->readOnly ) { + backspace(); + } + break; + case Key_Home: +#ifdef TQ_WS_MACX + case Key_Up: +#endif + home( e->state() & ShiftButton ); + break; + case Key_End: +#ifdef TQ_WS_MACX + case Key_Down: +#endif + end( e->state() & ShiftButton ); + break; + case Key_Delete: + if ( !d->readOnly ) { +#if defined (TQ_WS_WIN) + if ( e->state() & ShiftButton ) { + cut(); + break; + } +#endif + del(); + } + break; +#if defined (TQ_WS_WIN) + case Key_Insert: + if ( !d->readOnly && e->state() & ShiftButton ) + paste(); + else + unknown = TRUE; + break; +#endif + case Key_F14: // Undo key on Sun keyboards + if ( !d->readOnly ) + undo(); + break; +#ifndef TQT_NO_CLIPBOARD + case Key_F16: // Copy key on Sun keyboards + copy(); + break; + case Key_F18: // Paste key on Sun keyboards + if ( !d->readOnly ) + paste(); + break; + case Key_F20: // Cut key on Sun keyboards + if ( !d->readOnly && hasSelectedText() && echoMode() == Normal ) { + copy(); + del(); + } + break; +#endif + default: + unknown = TRUE; + } + } + if ( e->key() == Key_Direction_L || e->key() == Key_Direction_R ) { + d->direction = (e->key() == Key_Direction_L) ? TQChar::DirL : TQChar::DirR; + d->updateTextLayout(); + update(); + } + + if ( unknown ) + e->ignore(); +} + + +/*! + This function is not intended as polymorphic usage. Just a shared code + fragment that calls TQWidget::sendMouseEventToInputContext() easily for this + class. + */ +bool TQLineEdit::sendMouseEventToInputContext( TQMouseEvent *e ) +{ +#ifndef TQT_NO_IM + if ( d->composeMode() ) { + int cursor = d->xToPosInternal( e->pos().x(), TQTextItem::OnCharacters ); + int mousePos = cursor - d->imstart; + if ( mousePos >= 0 && mousePos < d->preeditLength() ) { + TQWidget::sendMouseEventToInputContext( mousePos, e->type(), + e->button(), e->state() ); + } else if ( e->type() != TQEvent::MouseMove ) { + // send button events on out of preedit + TQWidget::sendMouseEventToInputContext( -1, e->type(), + e->button(), e->state() ); + } + return TRUE; + } +#endif + return FALSE; +} + + +/*! \reimp + */ +void TQLineEdit::imStartEvent( TQIMEvent *e ) +{ + if ( d->readOnly ) { + e->ignore(); + return; + } + d->removeSelectedText(); + d->updateMicroFocusHint(); + d->imstart = d->imend = d->imselstart = d->imselend = d->cursor; +} + +/*! \reimp + */ +void TQLineEdit::imComposeEvent( TQIMEvent *e ) +{ + if ( d->readOnly ) { + e->ignore(); + return; + } + d->text.replace( d->imstart, d->imend - d->imstart, e->text() ); + d->imend = d->imstart + e->text().length(); + d->imselstart = d->imstart + e->cursorPos(); + d->imselend = d->imselstart + e->selectionLength(); + d->cursor = d->imstart + e->cursorPos(); + d->updateTextLayout(); + d->updateMicroFocusHint(); + update(); +} + +/*! \reimp + */ +void TQLineEdit::imEndEvent( TQIMEvent *e ) +{ + if ( d->readOnly) { + e->ignore(); + return; + } + d->text.remove( d->imstart, d->imend - d->imstart ); + d->cursor = d->imselstart = d->imselend = d->imend = d->imstart; + d->textDirty = TRUE; + insert( e->text() ); +} + +/*!\reimp +*/ + +void TQLineEdit::focusInEvent( TQFocusEvent* ) +{ + if ( TQFocusEvent::reason() == TQFocusEvent::Tab || + TQFocusEvent::reason() == TQFocusEvent::Backtab || + TQFocusEvent::reason() == TQFocusEvent::Shortcut ) + d->maskData ? d->moveCursor( d->nextMaskBlank( 0 ) ) : selectAll(); + if ( !d->cursorTimer ) { + int cft = TQApplication::cursorFlashTime(); + d->cursorTimer = cft ? startTimer( cft/2 ) : -1; + } + if( !hasSelectedText() || style().styleHint( TQStyle::SH_BlinkCursorWhenTextSelected ) ) + d->setCursorVisible( TRUE ); + if ( d->hasIMSelection() ) + d->cursor = d->imselstart; + d->updateMicroFocusHint(); +} + +/*!\reimp +*/ + +void TQLineEdit::focusOutEvent( TQFocusEvent* ) +{ + if ( TQFocusEvent::reason() != TQFocusEvent::ActiveWindow && + TQFocusEvent::reason() != TQFocusEvent::Popup ) + deselect(); + d->setCursorVisible( FALSE ); + if ( d->cursorTimer > 0 ) + killTimer( d->cursorTimer ); + d->cursorTimer = 0; + if (TQFocusEvent::reason() != TQFocusEvent::Popup) + emit lostFocus(); +} + +/*!\reimp +*/ +void TQLineEdit::drawContents( TQPainter *p ) +{ + const TQColorGroup& cg = colorGroup(); + TQRect cr = contentsRect(); + TQFontMetrics fm = fontMetrics(); + TQRect lineRect( cr.x() + innerMargin, cr.y() + (cr.height() - fm.height() + 1) / 2, + cr.width() - 2*innerMargin, fm.height() ); + TQBrush bg = TQBrush( paletteBackgroundColor() ); + if ( paletteBackgroundPixmap() ) + bg = TQBrush( cg.background(), *paletteBackgroundPixmap() ); + else if ( !isEnabled() ) + bg = cg.brush( TQColorGroup::Background ); + TQPoint brushOrigin = p->brushOrigin(); + p->save(); + p->setClipRegion( TQRegion(cr) - lineRect ); + p->setBrushOrigin(brushOrigin - backgroundOffset()); + p->fillRect( cr, bg ); + p->restore(); + TQSharedDoubleBuffer buffer( p, lineRect.x(), lineRect.y(), + lineRect.width(), lineRect.height(), + hasFocus() ? TQSharedDoubleBuffer::Force : 0 ); + p = buffer.painter(); + brushOrigin = p->brushOrigin(); + p->setBrushOrigin(brushOrigin - backgroundOffset()); + p->fillRect( lineRect, bg ); + p->setBrushOrigin(brushOrigin); + + // locate cursor position + int cix = 0; + TQTextItem ci = d->textLayout.findItem( d->cursor ); + if ( ci.isValid() ) { + if ( d->cursor != (int)d->text.length() && d->cursor == ci.from() + ci.length() + && ci.isRightToLeft() != d->isRightToLeft() ) + ci = d->textLayout.findItem( d->cursor + 1 ); + cix = ci.x() + ci.cursorToX( d->cursor - ci.from() ); + } + + // horizontal scrolling + int minLB = TQMAX( 0, -fm.minLeftBearing() ); + int minRB = TQMAX( 0, -fm.minRightBearing() ); + int widthUsed = d->textLayout.widthUsed() + 1 + minRB; + if ( (minLB + widthUsed) <= lineRect.width() ) { + switch ( d->visualAlignment() ) { + case AlignRight: + d->hscroll = widthUsed - lineRect.width() + 1; + break; + case AlignHCenter: + d->hscroll = ( widthUsed - lineRect.width() ) / 2; + break; + default: + d->hscroll = 0; + break; + } + d->hscroll -= minLB; + } else if ( cix - d->hscroll >= lineRect.width() ) { + d->hscroll = cix - lineRect.width() + 1; + } else if ( cix - d->hscroll < 0 ) { + d->hscroll = cix; + } else if ( widthUsed - d->hscroll < lineRect.width() ) { + d->hscroll = widthUsed - lineRect.width() + 1; + } else if (d->hscroll < 0) { + d->hscroll = 0; + } + // This updateMicroFocusHint() is corresponding to update() at + // IMCompose event. Although the function is invoked from various + // other points, some situations such as "candidate selection on + // AlignHCenter'ed text" need this invocation because + // updateMicroFocusHint() requires updated contentsRect(), and + // there are no other chances in such situation that invoke the + // function. + d->updateMicroFocusHint(); + // the y offset is there to keep the baseline constant in case we have script changes in the text. + TQPoint topLeft = lineRect.topLeft() - TQPoint(d->hscroll, d->ascent-fm.ascent()); + + // draw text, selections and cursors + p->setPen( cg.text() ); + bool supressCursor = d->readOnly, hasRightToLeft = d->isRightToLeft(); + int textflags = 0; + if ( font().underline() ) + textflags |= TQt::Underline; + if ( font().strikeOut() ) + textflags |= TQt::StrikeOut; + if ( font().overline() ) + textflags |= TQt::Overline; + + for ( int i = 0; i < d->textLayout.numItems(); i++ ) { + TQTextItem ti = d->textLayout.itemAt( i ); + hasRightToLeft |= ti.isRightToLeft(); + int tix = topLeft.x() + ti.x(); + int first = ti.from(); + int last = ti.from() + ti.length() - 1; + + // text and selection + if ( d->selstart < d->selend && (last >= d->selstart && first < d->selend ) ) { + TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->selstart - first, 0 ) ), + lineRect.top() ), + TQPoint( tix + ti.cursorToX( TQMIN( d->selend - first, last - first + 1 ) ) - 1, + lineRect.bottom() ) ).normalize(); + p->save(); + p->setClipRegion( TQRegion( lineRect ) - highlight, TQPainter::CoordPainter ); + p->drawTextItem( topLeft, ti, textflags ); + p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); + p->fillRect( highlight, cg.highlight() ); + p->setPen( cg.highlightedText() ); + p->drawTextItem( topLeft, ti, textflags ); + p->restore(); + } else { + p->drawTextItem( topLeft, ti, textflags ); + } + + // input method edit area + if ( d->composeMode() && (last >= d->imstart && first < d->imend ) ) { + TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->imstart - first, 0 ) ), lineRect.top() ), + TQPoint( tix + ti.cursorToX( TQMIN( d->imend - first, last - first + 1 ) )-1, lineRect.bottom() ) ).normalize(); + p->save(); + p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); + + int h1, s1, v1, h2, s2, v2; + cg.color( TQColorGroup::Base ).hsv( &h1, &s1, &v1 ); + cg.color( TQColorGroup::Background ).hsv( &h2, &s2, &v2 ); + TQColor imCol; + imCol.setHsv( h1, s1, ( v1 + v2 ) / 2 ); + p->fillRect( highlight, imCol ); + p->drawTextItem( topLeft, ti, textflags ); + // draw preedit's underline + if (d->imend - d->imstart > 0) { + p->setPen( cg.text() ); + p->drawLine( highlight.bottomLeft(), highlight.bottomRight() ); + } + p->restore(); + } + + // input method selection + if ( d->hasIMSelection() && (last >= d->imselstart && first < d->imselend ) ) { + TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->imselstart - first, 0 ) ), lineRect.top() ), + TQPoint( tix + ti.cursorToX( TQMIN( d->imselend - first, last - first + 1 ) )-1, lineRect.bottom() ) ).normalize(); + p->save(); + p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); + p->fillRect( highlight, cg.text() ); + p->setPen( paletteBackgroundColor() ); + p->drawTextItem( topLeft, ti, textflags ); + p->restore(); + supressCursor = TRUE; + } + + // overwrite cursor + if ( d->cursorVisible && d->maskData && + d->selend <= d->selstart && (last >= d->cursor && first <= d->cursor ) ) { + TQRect highlight = TQRect( TQPoint( tix + ti.cursorToX( TQMAX( d->cursor - first, 0 ) ), lineRect.top() ), + TQPoint( tix + ti.cursorToX( TQMIN( d->cursor + 1 - first, last - first + 1 ) )-1, lineRect.bottom() ) ).normalize(); + p->save(); + p->setClipRect( lineRect & highlight, TQPainter::CoordPainter ); + p->fillRect( highlight, cg.text() ); + p->setPen( paletteBackgroundColor() ); + p->drawTextItem( topLeft, ti, textflags ); + p->restore(); + supressCursor = TRUE; + } + } + + // draw cursor + // + // Asian users regard IM selection text as cursor on candidate + // selection phase of input method, so ordinary cursor should be + // invisible if IM selection text exists. + if ( d->cursorVisible && !supressCursor && !d->hasIMSelection() && (d->echoMode != PasswordThreeStars) ) { + TQPoint from( topLeft.x() + cix, lineRect.top() ); + TQPoint to = from + TQPoint( 0, lineRect.height() ); + p->drawLine( from, to ); + if ( hasRightToLeft ) { + bool rtl = ci.isValid() ? ci.isRightToLeft() : TRUE; + to = from + TQPoint( (rtl ? -2 : 2), 2 ); + p->drawLine( from, to ); + from.ry() += 4; + p->drawLine( from, to ); + } + } + buffer.end(); +} + + +#ifndef TQT_NO_DRAGANDDROP +/*!\reimp +*/ +void TQLineEdit::dragMoveEvent( TQDragMoveEvent *e ) +{ + if ( !d->readOnly && TQTextDrag::canDecode(e) ) { + e->acceptAction(); + d->cursor = d->xToPos( e->pos().x() ); + d->cursorVisible = TRUE; + update(); + } +} + +/*!\reimp */ +void TQLineEdit::dragEnterEvent( TQDragEnterEvent * e ) +{ + TQLineEdit::dragMoveEvent( e ); +} + +/*!\reimp */ +void TQLineEdit::dragLeaveEvent( TQDragLeaveEvent *) +{ + if ( d->cursorVisible ) { + d->cursorVisible = FALSE; + update(); + } +} + +/*!\reimp */ +void TQLineEdit::dropEvent( TQDropEvent* e ) +{ + TQString str; + // try text/plain + TQCString plain = "plain"; + bool decoded = TQTextDrag::decode(e, str, plain); + // otherwise we'll accept any kind of text (like text/uri-list) + if (! decoded) + decoded = TQTextDrag::decode(e, str); + + if ( decoded && !d->readOnly ) { + if ( e->source() == this && e->action() == TQDropEvent::Copy ) + deselect(); + d->cursor =d->xToPos( e->pos().x() ); + int selStart = d->cursor; + int oldSelStart = d->selstart; + int oldSelEnd = d->selend; + d->cursorVisible = FALSE; + e->acceptAction(); + insert( str ); + if ( e->source() == this ) { + if ( e->action() == TQDropEvent::Move ) { + if ( selStart > oldSelStart && selStart <= oldSelEnd ) + setSelection( oldSelStart, str.length() ); + else if ( selStart > oldSelEnd ) + setSelection( selStart - str.length(), str.length() ); + else + setSelection( selStart, str.length() ); + } else { + setSelection( selStart, str.length() ); + } + } + } else { + e->ignore(); + update(); + } +} + +bool TQLineEditPrivate::drag() +{ + q->killTimer( dndTimer ); + dndTimer = 0; + TQTextDrag *tdo = new TQTextDrag( q->selectedText(), q ); + + TQGuardedPtr gptr = q; + bool r = tdo->drag(); + if ( !gptr ) + return FALSE; + + // ### fix the check TQDragObject::target() != q in TQt4 (should not be needed) + if ( r && !readOnly && TQDragObject::target() != q ) { + int priorState = undoState; + removeSelectedText(); + finishChange( priorState ); + } +#ifndef TQT_NO_CURSOR + q->setCursor( readOnly ? arrowCursor : ibeamCursor ); +#endif + return TRUE; +} + +#endif // TQT_NO_DRAGANDDROP + +enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; + +/*!\reimp +*/ +void TQLineEdit::contextMenuEvent( TQContextMenuEvent * e ) +{ +#ifndef TQT_NO_POPUPMENU +#ifndef TQT_NO_IM + if ( d->composeMode() ) + return; +#endif + d->separate(); + TQPopupMenu *menu = createPopupMenu(); + if (!menu) + return; + TQGuardedPtr popup = menu; + TQGuardedPtr that = this; + TQPoint pos = e->reason() == TQContextMenuEvent::Mouse ? e->globalPos() : + mapToGlobal( TQPoint(e->pos().x(), 0) ) + TQPoint( width() / 2, height() / 2 ); + int r = popup->exec( pos ); + delete (TQPopupMenu*)popup; + if ( that && d->menuId ) { + switch ( d->menuId - r ) { + case IdClear: clear(); break; + case IdSelectAll: selectAll(); break; + case IdUndo: undo(); break; + case IdRedo: redo(); break; +#ifndef TQT_NO_CLIPBOARD + case IdCut: cut(); break; + case IdCopy: copy(); break; + case IdPaste: paste(); break; +#endif + default: + ; // nothing selected or lineedit destroyed. Be careful. + } + } +#endif //TQT_NO_POPUPMENU +} + +/*! + This function is called to create the popup menu which is shown + when the user clicks on the line edit with the right mouse button. + If you want to create a custom popup menu, reimplement this + function and return the popup menu you create. The popup menu's + ownership is transferred to the caller. +*/ + +TQPopupMenu *TQLineEdit::createPopupMenu() +{ +#ifndef TQT_NO_POPUPMENU + TQPopupMenu *popup = new TQPopupMenu( this, "qt_edit_menu" ); + int id = d->menuId = popup->insertItem( tr( "&Undo" ) + ACCEL_KEY( Z ) ); + popup->insertItem( tr( "&Redo" ) + ACCEL_KEY( Y ) ); + popup->insertSeparator(); + popup->insertItem( tr( "Cu&t" ) + ACCEL_KEY( X ) ); + popup->insertItem( tr( "&Copy" ) + ACCEL_KEY( C ) ); + popup->insertItem( tr( "&Paste" ) + ACCEL_KEY( V ) ); + popup->insertItem( tr( "Clear" ) ); + popup->insertSeparator(); + popup->insertItem( tr( "Select All" ) +#ifndef TQ_WS_X11 + + ACCEL_KEY( A ) +#endif + ); + +#ifndef TQT_NO_IM + TQInputContext *qic = getInputContext(); + if ( qic ) + qic->addMenusTo( popup ); +#endif + + popup->setItemEnabled( id - IdUndo, d->isUndoAvailable() ); + popup->setItemEnabled( id - IdRedo, d->isRedoAvailable() ); +#ifndef TQT_NO_CLIPBOARD + popup->setItemEnabled( id - IdCut, !d->readOnly && d->hasSelectedText() ); + popup->setItemEnabled( id - IdCopy, d->hasSelectedText() ); + popup->setItemEnabled( id - IdPaste, !d->readOnly && !TQApplication::clipboard()->text().isEmpty() ); +#else + popup->setItemVisible( id - IdCut, FALSE ); + popup->setItemVisible( id - IdCopy, FALSE ); + popup->setItemVisible( id - IdPaste, FALSE ); +#endif + popup->setItemEnabled( id - IdClear, !d->readOnly && !d->text.isEmpty() ); + popup->setItemEnabled( id - IdSelectAll, !d->text.isEmpty() && !d->allSelected() ); + return popup; +#else + return 0; +#endif +} + +/*! \reimp */ +void TQLineEdit::windowActivationChange( bool b ) +{ + //### remove me with WHighlightSelection attribute + if ( palette().active() != palette().inactive() ) + update(); + TQWidget::windowActivationChange( b ); +} + +/*! \reimp */ + +void TQLineEdit::setPalette( const TQPalette & p ) +{ + //### remove me with WHighlightSelection attribute + TQWidget::setPalette( p ); + update(); +} + +/*! \reimp */ +void TQLineEdit::setFont( const TQFont & f ) +{ + TQWidget::setFont( f ); + d->updateTextLayout(); +} + +/*! \obsolete +*/ +int TQLineEdit::characterAt( int xpos, TQChar *chr ) const +{ + int pos = d->xToPos( xpos + contentsRect().x() - d->hscroll + innerMargin ); + if ( chr && pos < (int) d->text.length() ) + *chr = d->text.at( pos ); + return pos; +} + +/*! + \internal + + Sets the password character to \a c. + + \sa passwordChar() +*/ + +void TQLineEdit::setPasswordChar( TQChar c ) +{ + d->passwordChar = c; +} + +/*! + \internal + + Returns the password character. + + \sa setPasswordChar() +*/ +TQChar TQLineEdit::passwordChar() const +{ + return ( d->passwordChar.isNull() ? TQChar( style().styleHint( TQStyle::SH_LineEdit_PasswordCharacter, this ) ) : d->passwordChar ); +} + +void TQLineEdit::clipboardChanged() +{ +} + +void TQLineEditPrivate::init( const TQString& txt ) +{ +#ifndef TQT_NO_CURSOR + q->setCursor( readOnly ? arrowCursor : ibeamCursor ); +#endif + q->setFocusPolicy( TQWidget::StrongFocus ); + q->setInputMethodEnabled( TRUE ); + // Specifies that this widget can use more, but is able to survive on + // less, horizontal space; and is fixed vertically. + q->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) ); + q->setBackgroundMode( PaletteBase ); + q->setKeyCompression( TRUE ); + q->setMouseTracking( TRUE ); + q->setAcceptDrops( TRUE ); + q->setFrame( TRUE ); + text = txt; + updateTextLayout(); + cursor = text.length(); +} + +void TQLineEditPrivate::updateTextLayout() +{ + // replace all non-printable characters with spaces (to avoid + // drawing boxes when using fonts that don't have glyphs for such + // characters) + const TQString &displayText = q->displayText(); + TQString str(displayText.unicode(), displayText.length()); + TQChar* uc = (TQChar*)str.unicode(); + for (int i = 0; i < (int)str.length(); ++i) { + if (! uc[i].isPrint()) + uc[i] = TQChar(0x0020); + } + textLayout.setText( str, q->font() ); + textLayout.setDirection((TQChar::Direction)direction); + textLayout.beginLayout(TQTextLayout::SingleLine); + textLayout.beginLine( INT_MAX ); + while ( !textLayout.atEnd() ) + textLayout.addCurrentItem(); + ascent = 0; + textLayout.endLine(0, 0, TQt::AlignLeft|TQt::SingleLine, &ascent); +} + +int TQLineEditPrivate::xToPosInternal( int x, TQTextItem::CursorPosition betweenOrOn ) const +{ + x-= q->contentsRect().x() - hscroll + innerMargin; + for ( int i = 0; i < textLayout.numItems(); ++i ) { + TQTextItem ti = textLayout.itemAt( i ); + TQRect tir = ti.rect(); + if ( x >= tir.left() && x <= tir.right() ) + return ti.xToCursor( x - tir.x(), betweenOrOn ) + ti.from(); + } + return x < 0 ? -1 : text.length(); +} + +int TQLineEditPrivate::xToPos( int x, TQTextItem::CursorPosition betweenOrOn ) const +{ + int pos = xToPosInternal( x, betweenOrOn ); + return ( pos < 0 ) ? 0 : pos; +} + + +TQRect TQLineEditPrivate::cursorRect() const +{ + TQRect cr = q->contentsRect(); + int cix = cr.x() - hscroll + innerMargin; + TQTextItem ci = textLayout.findItem( cursor ); + if ( ci.isValid() ) { + if ( cursor != (int)text.length() && cursor == ci.from() + ci.length() + && ci.isRightToLeft() != isRightToLeft() ) + ci = textLayout.findItem( cursor + 1 ); + cix += ci.x() + ci.cursorToX( cursor - ci.from() ); + } + int ch = q->fontMetrics().height(); + return TQRect( cix-4, cr.y() + ( cr.height() - ch + 1) / 2, 8, ch + 1 ); +} + +void TQLineEditPrivate::updateMicroFocusHint() +{ + // To reduce redundant microfocus update notification, we remember + // the old rect and update the microfocus if actual update is + // required. The rect o is intentionally static because some + // notifyee requires the microfocus information as global update + // rather than per notifyee update to place shared widget around + // microfocus. + static TQRect o; + if ( q->hasFocus() ) { + TQRect r = cursorRect(); + if ( o != r ) { + o = r; + q->setMicroFocusHint( r.x(), r.y(), r.width(), r.height() ); + } + } +} + +void TQLineEditPrivate::moveCursor( int pos, bool mark ) +{ + if ( pos != cursor ) + separate(); + if ( maskData && pos > cursor ) + pos = nextMaskBlank( pos ); + else if ( maskData && pos < cursor ) + pos = prevMaskBlank( pos ); + bool fullUpdate = mark || hasSelectedText(); + if ( mark ) { + int anchor; + if ( selend > selstart && cursor == selstart ) + anchor = selend; + else if ( selend > selstart && cursor == selend ) + anchor = selstart; + else + anchor = cursor; + selstart = TQMIN( anchor, pos ); + selend = TQMAX( anchor, pos ); + } else { + deselect(); + } + if ( fullUpdate ) { + cursor = pos; + q->update(); + } else { + setCursorVisible( FALSE ); + cursor = pos; + setCursorVisible( TRUE ); + } + updateMicroFocusHint(); + if ( mark && !q->style().styleHint( TQStyle::SH_BlinkCursorWhenTextSelected ) ) + setCursorVisible( FALSE ); + if ( mark || selDirty ) { + selDirty = FALSE; + emit q->selectionChanged(); + } +} + +void TQLineEditPrivate::finishChange( int validateFromState, bool setModified ) +{ + bool lineDirty = selDirty; + if ( textDirty ) { + // do validation + bool wasValidInput = validInput; + validInput = TRUE; +#ifndef TQT_NO_VALIDATOR + if ( validator && validateFromState >= 0 ) { + TQString textCopy = text; + int cursorCopy = cursor; + validInput = ( validator->validate( textCopy, cursorCopy ) != TQValidator::Invalid ); + if ( validInput ) { + if ( text != textCopy ) { + q->setText( textCopy ); + cursor = cursorCopy; + return; + } + cursor = cursorCopy; + } + } +#endif + if ( validateFromState >= 0 && wasValidInput && !validInput ) { + undo( validateFromState ); + history.resize( undoState ); + validInput = TRUE; + textDirty = setModified = FALSE; + } + updateTextLayout(); + updateMicroFocusHint(); + lineDirty |= textDirty; + if ( setModified ) + modified = TRUE; + if ( textDirty ) { + textDirty = FALSE; + emit q->textChanged( maskData ? stripString(text) : text ); + } +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( q, 0, TQAccessible::ValueChanged ); +#endif + } + if ( selDirty ) { + selDirty = FALSE; + emit q->selectionChanged(); + } + if ( lineDirty || !setModified ) + q->update(); +} + +void TQLineEditPrivate::setText( const TQString& txt ) +{ + deselect(); + TQString oldText = text; + if ( maskData ) { + text = maskString( 0, txt, TRUE ); + text += clearString( text.length(), maxLength - text.length() ); + } else { + text = txt.isEmpty() ? txt : txt.left( maxLength ); + } + history.clear(); + undoState = 0; + cursor = text.length(); + textDirty = ( oldText != text ); +} + + +void TQLineEditPrivate::setCursorVisible( bool visible ) +{ + if ( (bool)cursorVisible == visible ) + return; + if ( cursorTimer ) + cursorVisible = visible; + TQRect r = cursorRect(); + if ( maskData || !q->contentsRect().contains( r ) ) + q->update(); + else + q->update( r ); +} + +void TQLineEditPrivate::addCommand( const Command& cmd ) +{ + if ( separator && undoState && history[undoState-1].type != Separator ) { + history.resize( undoState + 2 ); + history[undoState++] = Command( Separator, 0, 0 ); + } else { + history.resize( undoState + 1); + } + separator = FALSE; + history[ undoState++ ] = cmd; +} + +void TQLineEditPrivate::insert( const TQString& s ) +{ + if ( maskData ) { + TQString ms = maskString( cursor, s ); + for ( int i = 0; i < (int) ms.length(); ++i ) { + addCommand ( Command( DeleteSelection, cursor+i, text.at(cursor+i) ) ); + addCommand( Command( Insert, cursor+i, ms.at(i) ) ); + } + text.replace( cursor, ms.length(), ms ); + cursor += ms.length(); + cursor = nextMaskBlank( cursor ); + } else { + int remaining = maxLength - text.length(); + text.insert( cursor, s.left(remaining) ); + for ( int i = 0; i < (int) s.left(remaining).length(); ++i ) + addCommand( Command( Insert, cursor++, s.at(i) ) ); + } + textDirty = TRUE; +} + +void TQLineEditPrivate::del( bool wasBackspace ) +{ + if ( cursor < (int) text.length() ) { + addCommand ( Command( (CommandType)((maskData?2:0)+(wasBackspace?Remove:Delete)), cursor, text.at(cursor) ) ); + if ( maskData ) { + text.replace( cursor, 1, clearString( cursor, 1 ) ); + addCommand( Command( Insert, cursor, text.at( cursor ) ) ); + } else { + text.remove( cursor, 1 ); + } + textDirty = TRUE; + } +} + +void TQLineEditPrivate::removeSelectedText() +{ + if ( selstart < selend && selend <= (int) text.length() ) { + separate(); + int i ; + if ( selstart <= cursor && cursor < selend ) { + // cursor is within the selection. Split up the commands + // to be able to restore the correct cursor position + for ( i = cursor; i >= selstart; --i ) + addCommand ( Command( DeleteSelection, i, text.at(i) ) ); + for ( i = selend - 1; i > cursor; --i ) + addCommand ( Command( DeleteSelection, i - cursor + selstart - 1, text.at(i) ) ); + } else { + for ( i = selend-1; i >= selstart; --i ) + addCommand ( Command( RemoveSelection, i, text.at(i) ) ); + } + if ( maskData ) { + text.replace( selstart, selend - selstart, clearString( selstart, selend - selstart ) ); + for ( int i = 0; i < selend - selstart; ++i ) + addCommand( Command( Insert, selstart + i, text.at( selstart + i ) ) ); + } else { + text.remove( selstart, selend - selstart ); + } + if ( cursor > selstart ) + cursor -= TQMIN( cursor, selend ) - selstart; + deselect(); + textDirty = TRUE; + } +} + +void TQLineEditPrivate::parseInputMask( const TQString &maskFields ) +{ + if ( maskFields.isEmpty() || maskFields.section( ';', 0, 0 ).isEmpty() ) { + if ( maskData ) { + delete [] maskData; + maskData = 0; + maxLength = 32767; + q->setText( TQString::null ); + } + return; + } + + inputMask = maskFields.section( ';', 0, 0 ); + blank = maskFields.section( ';', 1, 1 ).at(0); + if ( blank.isNull() ) + blank = ' '; + + // calculate maxLength / maskData length + maxLength = 0; + TQChar c = 0; + uint i; + for ( i=0; i 0 && inputMask.at( i-1 ) == '\\' ) { + maxLength++; + continue; + } + if ( c != '\\' && c != '!' && + c != '<' && c != '>' && + c != '{' && c != '}' && + c != '[' && c != ']' ) + maxLength++; + } + + delete [] maskData; + maskData = new MaskInputData[ maxLength ]; + + MaskInputData::Casemode m = MaskInputData::NoCaseMode; + c = 0; + bool s; + bool escape = FALSE; + int index = 0; + for ( i = 0; i < inputMask.length(); i++ ) { + c = inputMask.at(i); + if ( escape ) { + s = TRUE; + maskData[ index ].maskChar = c; + maskData[ index ].separator = s; + maskData[ index ].caseMode = m; + index++; + escape = FALSE; + } else if ( c == '<' || c == '>' || c == '!') { + switch ( c ) { + case '<': + m = MaskInputData::Lower; + break; + case '>': + m = MaskInputData::Upper; + break; + case '!': + m = MaskInputData::NoCaseMode; + break; + } + } else if ( c != '{' && c != '}' && c != '[' && c != ']' ) { + switch ( c ) { + case 'A': + case 'a': + case 'N': + case 'n': + case 'X': + case 'x': + case '9': + case '0': + case 'D': + case 'd': + case '#': + s = FALSE; + break; + case '\\': + escape = TRUE; + default: + s = TRUE; + break; + } + + if ( !escape ) { + maskData[ index ].maskChar = c; + maskData[ index ].separator = s; + maskData[ index ].caseMode = m; + index++; + } + } + } + q->setText( TQString::null ); +} + + +/* checks if the key is valid compared to the inputMask */ +bool TQLineEditPrivate::isValidInput( TQChar key, TQChar mask ) const +{ + switch ( mask ) { + case 'A': + if ( key.isLetter() && key != blank ) + return TRUE; + break; + case 'a': + if ( key.isLetter() || key == blank ) + return TRUE; + break; + case 'N': + if ( key.isLetterOrNumber() && key != blank ) + return TRUE; + break; + case 'n': + if ( key.isLetterOrNumber() || key == blank ) + return TRUE; + break; + case 'X': + if ( key.isPrint() && key != blank ) + return TRUE; + break; + case 'x': + if ( key.isPrint() || key == blank ) + return TRUE; + break; + case '9': + if ( key.isNumber() && key != blank ) + return TRUE; + break; + case '0': + if ( key.isNumber() || key == blank ) + return TRUE; + break; + case 'D': + if ( key.isNumber() && key.digitValue() > 0 && key != blank ) + return TRUE; + break; + case 'd': + if ( (key.isNumber() && key.digitValue() > 0) || key == blank ) + return TRUE; + break; + case '#': + if ( key.isNumber() || key == '+' || key == '-' || key == blank ) + return TRUE; + break; + default: + break; + } + return FALSE; +} + +/* + Applies the inputMask on \a str starting from position \a pos in the mask. \a clear + specifies from where characters should be gotten when a separator is met in \a str - TRUE means + that blanks will be used, FALSE that previous input is used. + Calling this when no inputMask is set is undefined. +*/ +TQString TQLineEditPrivate::maskString( uint pos, const TQString &str, bool clear) const +{ + if ( pos >= (uint)maxLength ) + return TQString::fromLatin1(""); + + TQString fill; + fill = clear ? clearString( 0, maxLength ) : text; + + uint strIndex = 0; + TQString s = TQString::fromLatin1(""); + int i = pos; + while ( i < maxLength ) { + if ( strIndex < str.length() ) { + if ( maskData[ i ].separator ) { + s += maskData[ i ].maskChar; + if ( str[(int)strIndex] == maskData[ i ].maskChar ) + strIndex++; + ++i; + } else { + if ( isValidInput( str[(int)strIndex], maskData[ i ].maskChar ) ) { + switch ( maskData[ i ].caseMode ) { + case MaskInputData::Upper: + s += str[(int)strIndex].upper(); + break; + case MaskInputData::Lower: + s += str[(int)strIndex].lower(); + break; + default: + s += str[(int)strIndex]; + } + ++i; + } else { + // search for separator first + int n = findInMask( i, TRUE, TRUE, str[(int)strIndex] ); + if ( n != -1 ) { + if ( str.length() != 1 || i == 0 || (i > 0 && (!maskData[i-1].separator || maskData[i-1].maskChar != str[(int)strIndex])) ) { + s += fill.mid( i, n-i+1 ); + i = n + 1; // update i to find + 1 + } + } else { + // search for valid blank if not + n = findInMask( i, TRUE, FALSE, str[(int)strIndex] ); + if ( n != -1 ) { + s += fill.mid( i, n-i ); + switch ( maskData[ n ].caseMode ) { + case MaskInputData::Upper: + s += str[(int)strIndex].upper(); + break; + case MaskInputData::Lower: + s += str[(int)strIndex].lower(); + break; + default: + s += str[(int)strIndex]; + } + i = n + 1; // updates i to find + 1 + } + } + } + strIndex++; + } + } else + break; + } + + return s; +} + + + +/* + Returns a "cleared" string with only separators and blank chars. + Calling this when no inputMask is set is undefined. +*/ +TQString TQLineEditPrivate::clearString( uint pos, uint len ) const +{ + if ( pos >= (uint)maxLength ) + return TQString::null; + + TQString s; + int end = TQMIN( (uint)maxLength, pos + len ); + for ( int i=pos; i= maxLength || pos < 0 ) + return -1; + + int end = forward ? maxLength : -1; + int step = forward ? 1 : -1; + int i = pos; + + while ( i != end ) { + if ( findSeparator ) { + if ( maskData[ i ].separator && maskData[ i ].maskChar == searchChar ) + return i; + } else { + if ( !maskData[ i ].separator ) { + if ( searchChar.isNull() ) + return i; + else if ( isValidInput( searchChar, maskData[ i ].maskChar ) ) + return i; + } + } + i += step; + } + return -1; +} + + +#endif // TQT_NO_LINEEDIT diff --git a/src/widgets/tqlineedit.h b/src/widgets/tqlineedit.h new file mode 100644 index 000000000..f5bf18c68 --- /dev/null +++ b/src/widgets/tqlineedit.h @@ -0,0 +1,218 @@ +/********************************************************************** +** +** Definition of TQLineEdit widget class +** +** Created : 941011 +** +** 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 TQLINEEDIT_H +#define TQLINEEDIT_H + +struct TQLineEditPrivate; + +class TQValidator; +class TQPopupMenu; + +#ifndef QT_H +#include "ntqframe.h" +#include "tqstring.h" +#endif // QT_H + +#ifndef TQT_NO_LINEEDIT + +class TQTextParagraph; +class TQTextCursor; + +class TQ_EXPORT TQLineEdit : public TQFrame +{ + TQ_OBJECT + TQ_ENUMS( EchoMode ) + TQ_PROPERTY( TQString text READ text WRITE setText ) + TQ_PROPERTY( int maxLength READ maxLength WRITE setMaxLength ) + TQ_PROPERTY( bool frame READ frame WRITE setFrame ) + TQ_PROPERTY( EchoMode echoMode READ echoMode WRITE setEchoMode ) + TQ_PROPERTY( TQString displayText READ displayText ) + TQ_PROPERTY( int cursorPosition READ cursorPosition WRITE setCursorPosition ) + TQ_PROPERTY( Alignment alignment READ alignment WRITE setAlignment ) + TQ_PROPERTY( bool edited READ edited WRITE setEdited DESIGNABLE false ) + TQ_PROPERTY( bool modified READ isModified ) + TQ_PROPERTY( bool hasSelectedText READ hasSelectedText ) + TQ_PROPERTY( TQString selectedText READ selectedText ) + TQ_PROPERTY( bool dragEnabled READ dragEnabled WRITE setDragEnabled ) + TQ_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly ) + TQ_PROPERTY( bool undoAvailable READ isUndoAvailable ) + TQ_PROPERTY( bool redoAvailable READ isRedoAvailable ) + TQ_PROPERTY( TQString inputMask READ inputMask WRITE setInputMask ) + TQ_PROPERTY( bool acceptableInput READ hasAcceptableInput ) + +public: + TQLineEdit( TQWidget* parent, const char* name=0 ); + TQLineEdit( const TQString &, TQWidget* parent, const char* name=0 ); + TQLineEdit( const TQString &, const TQString &, TQWidget* parent, const char* name=0 ); + ~TQLineEdit(); + + TQString text() const; + + TQString displayText() const; + + int maxLength() const; + + bool frame() const; + + enum EchoMode { Normal, NoEcho, Password, PasswordThreeStars }; + EchoMode echoMode() const; + + bool isReadOnly() const; + + const TQValidator * validator() const; + + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + + int cursorPosition() const; + bool validateAndSet( const TQString &, int, int, int ); // obsolete + + int alignment() const; + + void cursorForward( bool mark, int steps = 1 ); + void cursorBackward( bool mark, int steps = 1 ); + void cursorWordForward( bool mark ); + void cursorWordBackward( bool mark ); + void backspace(); + void del(); + void home( bool mark ); + void end( bool mark ); + + bool isModified() const; + void clearModified(); + + bool edited() const; // obsolete, use isModified() + void setEdited( bool ); // obsolete, use clearModified() + + bool hasSelectedText() const; + TQString selectedText() const; + int selectionStart() const; + + bool isUndoAvailable() const; + bool isRedoAvailable() const; + + bool dragEnabled() const; + + TQString inputMask() const; + void setInputMask( const TQString &inputMask ); + bool hasAcceptableInput() const; + +public slots: + virtual void setText( const TQString &); + virtual void selectAll(); + virtual void deselect(); + virtual void clearValidator(); + virtual void insert( const TQString &); + virtual void clear(); + virtual void undo(); + virtual void redo(); + virtual void setMaxLength( int ); + virtual void setFrame( bool ); + virtual void setEchoMode( EchoMode ); + virtual void setReadOnly( bool ); + virtual void setValidator( const TQValidator * ); + virtual void setFont( const TQFont & ); + virtual void setPalette( const TQPalette & ); + virtual void setSelection( int, int ); + virtual void setCursorPosition( int ); + virtual void setAlignment( int flag ); +#ifndef TQT_NO_CLIPBOARD + virtual void cut(); + virtual void copy() const; + virtual void paste(); +#endif + virtual void setDragEnabled( bool b ); + +signals: + void textChanged( const TQString &); + void returnPressed(); + void lostFocus(); + void selectionChanged(); + +protected: + bool event( TQEvent * ); + void mousePressEvent( TQMouseEvent * ); + void mouseMoveEvent( TQMouseEvent * ); + void mouseReleaseEvent( TQMouseEvent * ); + void mouseDoubleClickEvent( TQMouseEvent * ); + void keyPressEvent( TQKeyEvent * ); + void imStartEvent( TQIMEvent * ); + void imComposeEvent( TQIMEvent * ); + void imEndEvent( TQIMEvent * ); + void focusInEvent( TQFocusEvent * ); + void focusOutEvent( TQFocusEvent * ); + void resizeEvent( TQResizeEvent * ); + void drawContents( TQPainter * ); +#ifndef TQT_NO_DRAGANDDROP + void dragEnterEvent( TQDragEnterEvent * ); + void dragMoveEvent( TQDragMoveEvent *e ); + void dragLeaveEvent( TQDragLeaveEvent *e ); + void dropEvent( TQDropEvent * ); +#endif + void contextMenuEvent( TQContextMenuEvent * ); + bool sendMouseEventToInputContext( TQMouseEvent *e ); + virtual TQPopupMenu *createPopupMenu(); + void windowActivationChange( bool ); + +private slots: + void clipboardChanged(); + +public: + void setPasswordChar( TQChar c ); // internal obsolete + TQChar passwordChar() const; // obsolete internal + int characterAt( int, TQChar* ) const; // obsolete + bool getSelection( int *, int * ); // obsolete + +private: + friend struct TQLineEditPrivate; + TQLineEditPrivate * d; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQLineEdit( const TQLineEdit & ); + TQLineEdit &operator=( const TQLineEdit & ); +#endif +}; + + +#endif // TQT_NO_LINEEDIT + +#endif // TQLINEEDIT_H diff --git a/src/widgets/tqmainwindow.cpp b/src/widgets/tqmainwindow.cpp index 7b66839db..cda9afcb3 100644 --- a/src/widgets/tqmainwindow.cpp +++ b/src/widgets/tqmainwindow.cpp @@ -54,7 +54,7 @@ #include "tqpopupmenu.h" #include "tqtoolbar.h" #include "tqstatusbar.h" -#include "ntqscrollview.h" +#include "tqscrollview.h" #include "tqtooltip.h" #include "tqdatetime.h" #include "tqwhatsthis.h" diff --git a/src/widgets/tqpushbutton.cpp b/src/widgets/tqpushbutton.cpp new file mode 100644 index 000000000..105bae12a --- /dev/null +++ b/src/widgets/tqpushbutton.cpp @@ -0,0 +1,762 @@ +/**************************************************************************** +** +** Implementation of TQPushButton class +** +** Created : 940221 +** +** 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 "tqpushbutton.h" +#ifndef TQT_NO_PUSHBUTTON +#include "tqdialog.h" +#include "tqfontmetrics.h" +#include "tqpainter.h" +#include "ntqdrawutil.h" +#include "tqpixmap.h" +#include "tqbitmap.h" +#include "tqpopupmenu.h" +#include "ntqguardedptr.h" +#include "ntqapplication.h" +#include "tqtoolbar.h" +#include "tqstyle.h" +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif + +/*! + \class TQPushButton tqpushbutton.h + \brief The TQPushButton widget provides a command button. + + \ingroup basic + \mainclass + + The push button, or command button, is perhaps the most commonly + used widget in any graphical user interface. Push (click) a button + to command the computer to perform some action, or to answer a + question. Typical buttons are OK, Apply, Cancel, Close, Yes, No + and Help. + + A command button is rectangular and typically displays a text + label describing its action. An underlined character in the label + (signified by preceding it with an ampersand in the text) + indicates an accelerator key, e.g. + \code + TQPushButton *pb = new TQPushButton( "&Download", this ); + \endcode + In this example the accelerator is \e{Alt+D}, and the label text + will be displayed as Download. + + Push buttons can display a textual label or a pixmap, and + optionally a small icon. These can be set using the constructors + and changed later using setText(), setPixmap() and setIconSet(). + If the button is disabled the appearance of the text or pixmap and + iconset will be manipulated with respect to the GUI style to make + the button look "disabled". + + A push button emits the signal clicked() when it is activated by + the mouse, the Spacebar or by a keyboard accelerator. Connect to + this signal to perform the button's action. Push buttons also + provide less commonly used signals, for example, pressed() and + released(). + + Command buttons in dialogs are by default auto-default buttons, + i.e. they become the default push button automatically when they + receive the keyboard input focus. A default button is a push + button that is activated when the user presses the Enter or Return + key in a dialog. You can change this with setAutoDefault(). Note + that auto-default buttons reserve a little extra space which is + necessary to draw a default-button indicator. If you do not want + this space around your buttons, call setAutoDefault(FALSE). + + Being so central, the button widget has grown to accommodate a + great many variations in the past decade. The Microsoft style + guide now shows about ten different states of Windows push buttons + and the text implies that there are dozens more when all the + combinations of features are taken into consideration. + + The most important modes or states are: + \list + \i Available or not (grayed out, disabled). + \i Standard push button, toggling push button or menu button. + \i On or off (only for toggling push buttons). + \i Default or normal. The default button in a dialog can generally + be "clicked" using the Enter or Return key. + \i Auto-repeat or not. + \i Pressed down or not. + \endlist + + As a general rule, use a push button when the application or + dialog window performs an action when the user clicks on it (such + as Apply, Cancel, Close and Help) \e and when the widget is + supposed to have a wide, rectangular shape with a text label. + Small, typically square buttons that change the state of the + window rather than performing an action (such as the buttons in + the top-right corner of the TQFileDialog) are not command buttons, + but tool buttons. TQt provides a special class (TQToolButton) for + these buttons. + + If you need toggle behavior (see setToggleButton()) or a button + that auto-repeats the activation signal when being pushed down + like the arrows in a scroll bar (see setAutoRepeat()), a command + button is probably not what you want. When in doubt, use a tool + button. + + A variation of a command button is a menu button. These provide + not just one command, but several, since when they are clicked + they pop up a menu of options. Use the method setPopup() to + associate a popup menu with a push button. + + Other classes of buttons are option buttons (see TQRadioButton) and + check boxes (see TQCheckBox). + + + + In TQt, the TQButton abstract base class provides most of the modes + and other API, and TQPushButton provides GUI logic. See TQButton for + more information about the API. + + \important text, setText, text, pixmap, setPixmap, accel, setAccel, + isToggleButton, setDown, isDown, isOn, state, autoRepeat, + isExclusiveToggle, group, setAutoRepeat, toggle, pressed, released, + clicked, toggled, state stateChanged + + \sa TQToolButton, TQRadioButton TQCheckBox + \link guibooks.html#fowler GUI Design Handbook: Push Button\endlink +*/ + +/*! + \property TQPushButton::autoDefault + \brief whether the push button is the auto default button + + If this property is set to TRUE then the push button is the auto + default button in a dialog. + + In some GUI styles a default button is drawn with an extra frame + around it, up to 3 pixels or more. TQt automatically keeps this + space free around auto-default buttons, i.e. auto-default buttons + may have a slightly larger size hint. + + This property's default is TRUE for buttons that have a TQDialog + parent; otherwise it defaults to FALSE. + + See the \l default property for details of how \l default and + auto-default interact. +*/ + +/*! + \property TQPushButton::autoMask + \brief whether the button is automatically masked + + \sa TQWidget::setAutoMask() +*/ + +/*! + \property TQPushButton::default + \brief whether the push button is the default button + + If this property is set to TRUE then the push button will be + pressed if the user presses the Enter (or Return) key in a dialog. + + Regardless of focus, if the user presses Enter: If there is a + default button the default button is pressed; otherwise, if + there are one or more \l autoDefault buttons the first \l autoDefault + button that is next in the tab order is pressed. If there are no + default or \l autoDefault buttons only pressing Space on a button + with focus, mouse clicking, or using an accelerator will press a + button. + + In a dialog, only one push button at a time can be the default + button. This button is then displayed with an additional frame + (depending on the GUI style). + + The default button behavior is provided only in dialogs. Buttons + can always be clicked from the keyboard by pressing Enter (or + Return) or the Spacebar when the button has focus. + + This property's default is FALSE. +*/ + +/*! + \property TQPushButton::flat + \brief whether the border is disabled + + This property's default is FALSE. +*/ + +/*! + \property TQPushButton::iconSet + \brief the icon set on the push button + + This property will return 0 if the push button has no iconset. +*/ + +/*! + \property TQPushButton::on + \brief whether the push button is toggled + + This property should only be set for toggle push buttons. The + default value is FALSE. + + \sa isOn(), toggle(), toggled(), isToggleButton() +*/ + +/*! + \property TQPushButton::toggleButton + \brief whether the button is a toggle button + + Toggle buttons have an on/off state similar to \link TQCheckBox + check boxes. \endlink A push button is initially not a toggle + button. + + \sa setOn(), toggle(), isToggleButton() toggled() +*/ + +/*! \property TQPushButton::menuButton + \brief whether the push button has a menu button on it + \obsolete + + If this property is set to TRUE, then a down arrow is drawn on the push + button to indicate that a menu will pop up if the user clicks on the + arrow. +*/ + +class TQPushButtonPrivate +{ +public: + TQPushButtonPrivate() + :iconset( 0 ) + {} + ~TQPushButtonPrivate() + { +#ifndef TQT_NO_ICONSET + delete iconset; +#endif + } +#ifndef TQT_NO_POPUPMENU + TQGuardedPtr popup; +#endif + TQIconSet* iconset; +}; + + +/*! + Constructs a push button with no text. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. +*/ + +TQPushButton::TQPushButton( TQWidget *parent, const char *name ) + : TQButton( parent, name ) +{ + init(); +} + +/*! + Constructs a push button called \a name with the parent \a parent + and the text \a text. +*/ + +TQPushButton::TQPushButton( const TQString &text, TQWidget *parent, + const char *name ) + : TQButton( parent, name ) +{ + init(); + setText( text ); +} + + +/*! + Constructs a push button with an \a icon and a \a text. + + Note that you can also pass a TQPixmap object as an icon (thanks to + the implicit type conversion provided by C++). + + The \a parent and \a name arguments are sent to the TQWidget + constructor. +*/ +#ifndef TQT_NO_ICONSET +TQPushButton::TQPushButton( const TQIconSet& icon, const TQString &text, + TQWidget *parent, const char *name ) + : TQButton( parent, name ) +{ + init(); + setText( text ); + setIconSet( icon ); +} +#endif + + +/*! + Destroys the push button. +*/ +TQPushButton::~TQPushButton() +{ + delete d; +} + +void TQPushButton::init() +{ + d = 0; + defButton = FALSE; + lastEnabled = FALSE; + hasMenuArrow = FALSE; + flt = FALSE; +#ifndef TQT_NO_DIALOG + autoDefButton = ::tqt_cast(topLevelWidget()) != 0; +#else + autoDefButton = FALSE; +#endif + setBackgroundMode( PaletteButton ); + setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); +} + + +/* + Makes the push button a toggle button if \a enable is TRUE or a normal + push button if \a enable is FALSE. + + Toggle buttons have an on/off state similar to \link TQCheckBox check + boxes. \endlink A push button is initially not a toggle button. + + \sa setOn(), toggle(), isToggleButton() toggled() +*/ + +void TQPushButton::setToggleButton( bool enable ) +{ + TQButton::setToggleButton( enable ); +} + + +/* + Switches a toggle button on if \a enable is TRUE or off if \a enable is + FALSE. + \sa isOn(), toggle(), toggled(), isToggleButton() +*/ + +void TQPushButton::setOn( bool enable ) +{ + if ( !isToggleButton() ) + return; + TQButton::setOn( enable ); +} + +void TQPushButton::setAutoDefault( bool enable ) +{ + if ( (bool)autoDefButton == enable ) + return; + autoDefButton = enable; + update(); + updateGeometry(); +} + + +void TQPushButton::setDefault( bool enable ) +{ + if ( (bool)defButton == enable ) + return; // no change + defButton = enable; +#ifndef TQT_NO_DIALOG + if ( defButton && ::tqt_cast(topLevelWidget()) ) + ((TQDialog*)topLevelWidget())->setMainDefault( this ); +#endif + update(); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::StateChanged ); +#endif +} + + +/*! + \reimp +*/ +TQSize TQPushButton::sizeHint() const +{ + constPolish(); + + int w = 0, h = 0; + + // calculate contents size... +#ifndef TQT_NO_ICONSET + if ( iconSet() && !iconSet()->isNull() ) { + int iw = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).width() + 4; + int ih = iconSet()->pixmap( TQIconSet::Small, TQIconSet::Normal ).height(); + w += iw; + h = TQMAX( h, ih ); + } +#endif + if ( isMenuButton() ) + w += style().pixelMetric(TQStyle::PM_MenuButtonIndicator, this); + + if ( pixmap() ) { + TQPixmap *pm = (TQPixmap *)pixmap(); + w += pm->width(); + h += pm->height(); + } else { + TQString s( text() ); + bool empty = s.isEmpty(); + if ( empty ) + s = TQString::fromLatin1("XXXX"); + TQFontMetrics fm = fontMetrics(); + TQSize sz = fm.size( ShowPrefix, s ); + if(!empty || !w) + w += sz.width(); + if(!empty || !h) + h = TQMAX(h, sz.height()); + } + + return (style().sizeFromContents(TQStyle::CT_PushButton, this, TQSize(w, h)). + expandedTo(TQApplication::globalStrut())); +} + + +/*! + \reimp +*/ +void TQPushButton::move( int x, int y ) +{ + TQWidget::move( x, y ); +} + +/*! + \reimp +*/ +void TQPushButton::move( const TQPoint &p ) +{ + move( p.x(), p.y() ); +} + +/*! + \reimp +*/ +void TQPushButton::resize( int w, int h ) +{ + TQWidget::resize( w, h ); +} + +/*! + \reimp +*/ +void TQPushButton::resize( const TQSize &s ) +{ + resize( s.width(), s.height() ); +} + +/*! + \reimp +*/ +void TQPushButton::setGeometry( int x, int y, int w, int h ) +{ + TQWidget::setGeometry( x, y, w, h ); +} + +/*! + \reimp +*/ +void TQPushButton::setGeometry( const TQRect &r ) +{ + TQWidget::setGeometry( r ); +} + +/*! + \reimp + */ +void TQPushButton::resizeEvent( TQResizeEvent * ) +{ + if ( autoMask() ) + updateMask(); +} + +/*! + \reimp +*/ +void TQPushButton::drawButton( TQPainter *paint ) +{ + int diw = 0; + if ( isDefault() || autoDefault() ) { + diw = style().pixelMetric(TQStyle::PM_ButtonDefaultIndicator, this); + + if ( diw > 0 ) { + if (backgroundMode() == X11ParentRelative) { + erase( 0, 0, width(), diw ); + erase( 0, 0, diw, height() ); + erase( 0, height() - diw, width(), diw ); + erase( width() - diw, 0, diw, height() ); + } else if ( parentWidget() && parentWidget()->backgroundPixmap() ){ + // pseudo tranparency + paint->drawTiledPixmap( 0, 0, width(), diw, + *parentWidget()->backgroundPixmap(), + x(), y() ); + paint->drawTiledPixmap( 0, 0, diw, height(), + *parentWidget()->backgroundPixmap(), + x(), y() ); + paint->drawTiledPixmap( 0, height()-diw, width(), diw, + *parentWidget()->backgroundPixmap(), + x(), y()+height() ); + paint->drawTiledPixmap( width()-diw, 0, diw, height(), + *parentWidget()->backgroundPixmap(), + x()+width(), y() ); + } else { + paint->fillRect( 0, 0, width(), diw, + colorGroup().brush(TQColorGroup::Background) ); + paint->fillRect( 0, 0, diw, height(), + colorGroup().brush(TQColorGroup::Background) ); + paint->fillRect( 0, height()-diw, width(), diw, + colorGroup().brush(TQColorGroup::Background) ); + paint->fillRect( width()-diw, 0, diw, height(), + colorGroup().brush(TQColorGroup::Background) ); + } + + } + } + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasFocus()) + flags |= TQStyle::Style_HasFocus; + if (isDown()) + flags |= TQStyle::Style_Down; + if (isOn()) + flags |= TQStyle::Style_On; + if (! isFlat() && ! isDown()) + flags |= TQStyle::Style_Raised; + if (isDefault()) + flags |= TQStyle::Style_ButtonDefault; + if (hasMouse()) + flags |= TQStyle::Style_MouseOver; + + style().drawControl(TQStyle::CE_PushButton, paint, this, rect(), colorGroup(), flags); + drawButtonLabel( paint ); + + lastEnabled = isEnabled(); +} + + +/*! + \reimp +*/ +void TQPushButton::drawButtonLabel( TQPainter *paint ) +{ + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasFocus()) + flags |= TQStyle::Style_HasFocus; + if (isDown()) + flags |= TQStyle::Style_Down; + if (isOn()) + flags |= TQStyle::Style_On; + if (! isFlat() && ! isDown()) + flags |= TQStyle::Style_Raised; + if (isDefault()) + flags |= TQStyle::Style_ButtonDefault; + + style().drawControl(TQStyle::CE_PushButtonLabel, paint, this, + style().subRect(TQStyle::SR_PushButtonContents, this), + colorGroup(), flags); +} + + +/*! + \reimp + */ +void TQPushButton::updateMask() +{ + TQBitmap bm( size() ); + bm.fill( color0 ); + + { + TQPainter p( &bm, this ); + style().drawControlMask(TQStyle::CE_PushButton, &p, this, rect()); + } + + setMask( bm ); +} + +/*! + \reimp +*/ +void TQPushButton::focusInEvent( TQFocusEvent *e ) +{ + if (autoDefButton && !defButton) { + defButton = TRUE; +#ifndef TQT_NO_DIALOG + if ( defButton && ::tqt_cast(topLevelWidget()) ) + ((TQDialog*)topLevelWidget())->setDefault( this ); +#endif + } + TQButton::focusInEvent( e ); +} + +/*! + \reimp +*/ +void TQPushButton::focusOutEvent( TQFocusEvent *e ) +{ +#ifndef TQT_NO_DIALOG + if ( defButton && autoDefButton ) { + if ( ::tqt_cast(topLevelWidget()) ) + ((TQDialog*)topLevelWidget())->setDefault( 0 ); + } +#endif + + TQButton::focusOutEvent( e ); +#ifndef TQT_NO_POPUPMENU + if ( popup() && popup()->isVisible() ) // restore pressed status + setDown( TRUE ); +#endif +} + + +#ifndef TQT_NO_POPUPMENU +/*! + Associates the popup menu \a popup with this push button. This + turns the button into a menu button. + + Ownership of the popup menu is \e not transferred to the push + button. + + \sa popup() +*/ +void TQPushButton::setPopup( TQPopupMenu* popup ) +{ + if ( !d ) + d = new TQPushButtonPrivate; + if ( popup && !d->popup ) + connect( this, TQ_SIGNAL( pressed() ), this, TQ_SLOT( popupPressed() ) ); + + d->popup = popup; + setIsMenuButton( popup != 0 ); +} +#endif //TQT_NO_POPUPMENU +#ifndef TQT_NO_ICONSET +void TQPushButton::setIconSet( const TQIconSet& icon ) +{ + if ( !d ) + d = new TQPushButtonPrivate; + if ( !icon.isNull() ) { + if ( d->iconset ) + *d->iconset = icon; + else + d->iconset = new TQIconSet( icon ); + } else if ( d->iconset) { + delete d->iconset; + d->iconset = 0; + } + + update(); + updateGeometry(); +} + + +TQIconSet* TQPushButton::iconSet() const +{ + return d ? d->iconset : 0; +} +#endif // TQT_NO_ICONSET +#ifndef TQT_NO_POPUPMENU +/*! + Returns the button's associated popup menu or 0 if no popup menu + has been set. + + \sa setPopup() +*/ +TQPopupMenu* TQPushButton::popup() const +{ + return d ? (TQPopupMenu*)d->popup : 0; +} + +void TQPushButton::popupPressed() +{ + TQPopupMenu* popup = d ? (TQPopupMenu*) d->popup : 0; + TQGuardedPtr that = this; + if ( isDown() && popup ) { + bool horizontal = TRUE; + bool topLeft = TRUE; // ### always TRUE +#ifndef TQT_NO_TOOLBAR + TQToolBar *tb = ::tqt_cast(parentWidget()); + if ( tb && tb->orientation() == Vertical ) + horizontal = FALSE; +#endif + if ( horizontal ) { + if ( topLeft ) { + if ( mapToGlobal( TQPoint( 0, rect().bottom() ) ).y() + popup->sizeHint().height() <= tqApp->desktop()->height() ) + popup->exec( mapToGlobal( rect().bottomLeft() ) ); + else + popup->exec( mapToGlobal( rect().topLeft() - TQPoint( 0, popup->sizeHint().height() ) ) ); + } else { + TQSize sz( popup->sizeHint() ); + TQPoint p = mapToGlobal( rect().topLeft() ); + p.ry() -= sz.height(); + popup->exec( p ); + } + } else { + if ( topLeft ) { + if ( mapToGlobal( TQPoint( rect().right(), 0 ) ).x() + popup->sizeHint().width() <= tqApp->desktop()->width() ) + popup->exec( mapToGlobal( rect().topRight() ) ); + else + popup->exec( mapToGlobal( rect().topLeft() - TQPoint( popup->sizeHint().width(), 0 ) ) ); + } else { + TQSize sz( popup->sizeHint() ); + TQPoint p = mapToGlobal( rect().topLeft() ); + p.rx() -= sz.width(); + popup->exec( p ); + } + } + if (that) + setDown( FALSE ); + } +} +#endif + +void TQPushButton::setFlat( bool f ) +{ + flt = f; + update(); +} + +bool TQPushButton::isFlat() const +{ + return flt; +} + +/*! + \obsolete + \fn virtual void TQPushButton::setIsMenuButton( bool enable ) +*/ + +#endif diff --git a/src/widgets/tqpushbutton.h b/src/widgets/tqpushbutton.h new file mode 100644 index 000000000..13b76e9fe --- /dev/null +++ b/src/widgets/tqpushbutton.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Definition of TQPushButton class +** +** Created : 940221 +** +** 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 TQPUSHBUTTON_H +#define TQPUSHBUTTON_H + +#ifndef QT_H +#include "ntqbutton.h" +#include "tqiconset.h" +#endif // QT_H + +#ifndef TQT_NO_PUSHBUTTON +class TQPushButtonPrivate; +class TQPopupMenu; + +class TQ_EXPORT TQPushButton : public TQButton +{ + TQ_OBJECT + + TQ_PROPERTY( bool autoDefault READ autoDefault WRITE setAutoDefault ) + TQ_PROPERTY( bool default READ isDefault WRITE setDefault ) + TQ_PROPERTY( bool menuButton READ isMenuButton DESIGNABLE false ) + TQ_PROPERTY( TQIconSet iconSet READ iconSet WRITE setIconSet ) + TQ_OVERRIDE( bool toggleButton WRITE setToggleButton ) + TQ_OVERRIDE( bool on WRITE setOn ) + TQ_PROPERTY( bool flat READ isFlat WRITE setFlat ) + TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) + +public: + TQPushButton( TQWidget *parent, const char* name=0 ); + TQPushButton( const TQString &text, TQWidget *parent, const char* name=0 ); +#ifndef TQT_NO_ICONSET + TQPushButton( const TQIconSet& icon, const TQString &text, TQWidget *parent, const char* name=0 ); +#endif + ~TQPushButton(); + + TQSize sizeHint() const; + + void move( int x, int y ); + void move( const TQPoint &p ); + void resize( int w, int h ); + void resize( const TQSize & ); + void setGeometry( int x, int y, int w, int h ); + + void setGeometry( const TQRect & ); + + void setToggleButton( bool ); + + bool autoDefault() const { return autoDefButton; } + virtual void setAutoDefault( bool autoDef ); + bool isDefault() const { return defButton; } + virtual void setDefault( bool def ); + + virtual void setIsMenuButton( bool enable ) { // obsolete functions + if ( (bool)hasMenuArrow == enable ) + return; + hasMenuArrow = enable ? 1 : 0; + update(); + updateGeometry(); + } + bool isMenuButton() const { return hasMenuArrow; } + +#ifndef TQT_NO_POPUPMENU + void setPopup( TQPopupMenu* popup ); + TQPopupMenu* popup() const; +#endif +#ifndef TQT_NO_ICONSET + void setIconSet( const TQIconSet& ); + TQIconSet* iconSet() const; +#endif + void setFlat( bool ); + bool isFlat() const; + +public slots: + virtual void setOn( bool ); + +protected: + void drawButton( TQPainter * ); + void drawButtonLabel( TQPainter * ); + void focusInEvent( TQFocusEvent * ); + void focusOutEvent( TQFocusEvent * ); + void resizeEvent( TQResizeEvent * ); + void updateMask(); +private slots: +#ifndef TQT_NO_POPUPMENU + void popupPressed(); +#endif +private: + void init(); + + uint autoDefButton : 1; + uint defButton : 1; + uint flt : 1; + uint reserved : 1; // UNUSED + uint lastEnabled : 1; // UNUSED + uint hasMenuArrow : 1; + + TQPushButtonPrivate* d; + + friend class TQDialog; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQPushButton( const TQPushButton & ); + TQPushButton &operator=( const TQPushButton & ); +#endif +}; + + +#endif // TQT_NO_PUSHBUTTON + +#endif // TQPUSHBUTTON_H diff --git a/src/widgets/tqradiobutton.cpp b/src/widgets/tqradiobutton.cpp new file mode 100644 index 000000000..263c17f20 --- /dev/null +++ b/src/widgets/tqradiobutton.cpp @@ -0,0 +1,358 @@ +/**************************************************************************** +** +** Implementation of TQRadioButton class +** +** Created : 940222 +** +** 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 "tqradiobutton.h" +#ifndef TQT_NO_RADIOBUTTON +#include "ntqbuttongroup.h" +#include "tqpainter.h" +#include "ntqdrawutil.h" +#include "tqpixmap.h" +#include "tqpixmapcache.h" +#include "tqbitmap.h" +#include "tqtextstream.h" +#include "ntqapplication.h" +#include "tqstyle.h" + +/*! + \class TQRadioButton tqradiobutton.h + \brief The TQRadioButton widget provides a radio button with a text or pixmap label. + + \ingroup basic + \mainclass + + TQRadioButton and TQCheckBox are both option buttons. That is, they + can be switched on (checked) or off (unchecked). The classes + differ in how the choices for the user are restricted. Check boxes + define "many of many" choices, whereas radio buttons provide a + "one of many" choice. In a group of radio buttons only one radio + button at a time can be checked; if the user selects another + button, the previously selected button is switched off. + + The easiest way to implement a "one of many" choice is simply to + put the radio buttons into TQButtonGroup. + + Whenever a button is switched on or off it emits the signal + toggled(). Connect to this signal if you want to trigger an action + each time the button changes state. Otherwise, use isChecked() to + see if a particular button is selected. + + Just like TQPushButton, a radio button can display text or a + pixmap. The text can be set in the constructor or with setText(); + the pixmap is set with setPixmap(). + + + + \important text, setText, text, pixmap, setPixmap, accel, setAccel, isToggleButton, setDown, isDown, isOn, state, autoRepeat, isExclusiveToggle, group, setAutoRepeat, toggle, pressed, released, clicked, toggled, state stateChanged + + \sa TQPushButton TQToolButton + \link guibooks.html#fowler GUI Design Handbook: Radio Button\endlink +*/ + +/*! + \property TQRadioButton::checked \brief Whether the radio button is + checked + + This property will not effect any other radio buttons unless they + have been placed in the same TQButtonGroup. The default value is + FALSE (unchecked). +*/ + +/*! + \property TQRadioButton::autoMask \brief whether the radio button + is automatically masked + + \sa TQWidget::setAutoMask() +*/ + +/*! + Constructs a radio button with no text. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. +*/ + +TQRadioButton::TQRadioButton( TQWidget *parent, const char *name ) + : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) +{ + init(); +} + +/*! + Constructs a radio button with the text \a text. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. +*/ + +TQRadioButton::TQRadioButton( const TQString &text, TQWidget *parent, + const char *name ) + : TQButton( parent, name, WNoAutoErase | WMouseNoMask ) +{ + init(); + setText( text ); +} + + +/* + Initializes the radio button. +*/ + +void TQRadioButton::init() +{ + setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); + setToggleButton( TRUE ); +#ifndef TQT_NO_BUTTONGROUP + TQButtonGroup *bgrp = ::tqt_cast(parentWidget()); + if ( bgrp ) + bgrp->setRadioButtonExclusive( TRUE ); +#endif +} + +void TQRadioButton::setChecked( bool check ) +{ + setOn( check ); +} + + + + +/*! + \reimp +*/ +TQSize TQRadioButton::sizeHint() const +{ + // Any more complex, and we will use style().itemRect() + // NB: TQCheckBox::sizeHint() is similar + constPolish(); + + TQPainter p(this); + TQSize sz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, + pixmap(), text()).size(); + + return (style().sizeFromContents(TQStyle::CT_RadioButton, this, sz). + expandedTo(TQApplication::globalStrut())); +} + + +/*! + \reimp +*/ +bool TQRadioButton::hitButton( const TQPoint &pos ) const +{ + TQRect r = + TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonFocusRect, + this ), this ); + if ( tqApp->reverseLayout() ) { + r.setRight( width() ); + } else { + r.setLeft( 0 ); + } + return r.contains( pos ); +} + + +/*! + \reimp +*/ +void TQRadioButton::drawButton( TQPainter *paint ) +{ + TQPainter *p = paint; + TQRect irect = TQStyle::visualRect( style().subRect(TQStyle::SR_RadioButtonIndicator, this), this ); + const TQColorGroup &cg = colorGroup(); + +#if !defined( TQT_NO_TEXTSTREAM ) && !defined( TQ_WS_MACX ) +# define SAVE_RADIOBUTTON_PIXMAPS +#endif +#if defined(SAVE_RADIOBUTTON_PIXMAPS) + TQString pmkey; // pixmap key + int kf = 0; + if ( isDown() ) + kf |= 1; + if ( isOn() ) + kf |= 2; + if ( isEnabled() ) + kf |= 4; + if( isActiveWindow() ) + kf |= 8; + if ( hasMouse() ) + kf |= 16; + if ( hasFocus() ) + kf |= 32; + + TQTextOStream os(&pmkey); + os << "$qt_radio_" << style().className() << "_" + << palette().serialNumber() << "_" << irect.width() << "x" << irect.height() << "_" << kf; + TQPixmap *pm = TQPixmapCache::find( pmkey ); + if ( pm ) { // pixmap exists + drawButtonLabel( p ); + p->drawPixmap( irect.topLeft(), *pm ); + return; + } + bool use_pm = TRUE; + TQPainter pmpaint; + int wx, wy; + if ( use_pm ) { + pm = new TQPixmap( irect.size() ); // create new pixmap + TQ_CHECK_PTR( pm ); + pm->fill(paletteBackgroundColor()); + TQPainter::redirect(this, pm); + pmpaint.begin(this); + p = &pmpaint; // draw in pixmap + wx = irect.x(); // save x,y coords + wy = irect.y(); + irect.moveTopLeft(TQPoint(0, 0)); + p->setBackgroundColor(paletteBackgroundColor()); + } +#endif + + TQStyle::SFlags flags = TQStyle::Style_Default; + if ( isEnabled() ) + flags |= TQStyle::Style_Enabled; + if ( hasFocus() ) + flags |= TQStyle::Style_HasFocus; + if ( isDown() ) + flags |= TQStyle::Style_Down; + if ( hasMouse() ) + flags |= TQStyle::Style_MouseOver; + if ( state() == TQButton::On ) + flags |= TQStyle::Style_On; + else if ( state() == TQButton::Off ) + flags |= TQStyle::Style_Off; + + style().drawControl(TQStyle::CE_RadioButton, p, this, irect, cg, flags); + +#if defined(SAVE_RADIOBUTTON_PIXMAPS) + if ( use_pm ) { + pmpaint.end(); + TQPainter::redirect(this, NULL); + if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) { + TQBitmap bm( pm->size() ); + bm.fill( color0 ); + pmpaint.begin( &bm ); + style().drawControlMask(TQStyle::CE_RadioButton, &pmpaint, this, irect); + pmpaint.end(); + pm->setMask( bm ); + } + p = paint; // draw in default device + p->drawPixmap( wx, wy, *pm ); + if (!TQPixmapCache::insert(pmkey, pm) ) // save in cache + delete pm; + } +#endif + + drawButtonLabel( p ); +} + + + +/*! + \reimp +*/ +void TQRadioButton::drawButtonLabel( TQPainter *p ) +{ + TQRect r = + TQStyle::visualRect( style().subRect(TQStyle::SR_RadioButtonContents, + this), this ); + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasFocus()) + flags |= TQStyle::Style_HasFocus; + if (isDown()) + flags |= TQStyle::Style_Down; + if (state() == TQButton::On) + flags |= TQStyle::Style_On; + else if (state() == TQButton::Off) + flags |= TQStyle::Style_Off; + + style().drawControl(TQStyle::CE_RadioButtonLabel, p, this, r, colorGroup(), flags); +} + + +/*! + \reimp +*/ +void TQRadioButton::resizeEvent( TQResizeEvent* e ) +{ + TQButton::resizeEvent(e); + if ( isVisible() ) { + TQPainter p(this); + TQSize isz = style().itemRect(&p, TQRect(0, 0, 1, 1), ShowPrefix, FALSE, + pixmap(), text()).size(); + TQSize wsz = (style().sizeFromContents(TQStyle::CT_RadioButton, this, isz). + expandedTo(TQApplication::globalStrut())); + + update(wsz.width(), isz.width(), 0, wsz.height()); + } + if (autoMask()) + updateMask(); +} + +/*! + \reimp +*/ +void TQRadioButton::updateMask() +{ + TQRect irect = + TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonIndicator, + this ), this ); + + TQBitmap bm(width(), height()); + bm.fill(color0); + + TQPainter p( &bm, this ); + style().drawControlMask(TQStyle::CE_RadioButton, &p, this, irect); + if ( ! text().isNull() || ( pixmap() && ! pixmap()->isNull() ) ) { + TQRect crect = + TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonContents, + this ), this ); + TQRect frect = + TQStyle::visualRect( style().subRect( TQStyle::SR_RadioButtonFocusRect, + this ), this ); + TQRect label(crect.unite(frect)); + p.fillRect(label, color1); + } + p.end(); + + setMask(bm); +} + +#endif diff --git a/src/widgets/tqradiobutton.h b/src/widgets/tqradiobutton.h new file mode 100644 index 000000000..1c7c0ae34 --- /dev/null +++ b/src/widgets/tqradiobutton.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Definition of TQRadioButton class +** +** Created : 940222 +** +** 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 TQRADIOBUTTON_H +#define TQRADIOBUTTON_H + +#ifndef QT_H +#include "ntqbutton.h" +#endif // QT_H + +#ifndef TQT_NO_RADIOBUTTON + +class TQ_EXPORT TQRadioButton : public TQButton +{ + TQ_OBJECT + TQ_PROPERTY( bool checked READ isChecked WRITE setChecked ) + TQ_OVERRIDE( bool autoMask DESIGNABLE true SCRIPTABLE true ) + +public: + TQRadioButton( TQWidget *parent, const char* name=0 ); + TQRadioButton( const TQString &text, TQWidget *parent, const char* name=0 ); + + bool isChecked() const; + + TQSize sizeHint() const; + +public slots: + virtual void setChecked( bool check ); + +protected: + bool hitButton( const TQPoint & ) const; + void drawButton( TQPainter * ); + void drawButtonLabel( TQPainter * ); + void updateMask(); + + void resizeEvent( TQResizeEvent* ); + +private: + void init(); + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQRadioButton( const TQRadioButton & ); + TQRadioButton &operator=( const TQRadioButton & ); +#endif +}; + + +inline bool TQRadioButton::isChecked() const +{ return isOn(); } + +#endif // TQT_NO_RADIOBUTTON + +#endif // TQRADIOBUTTON_H diff --git a/src/widgets/tqscrollbar.cpp b/src/widgets/tqscrollbar.cpp new file mode 100644 index 000000000..383ce44bd --- /dev/null +++ b/src/widgets/tqscrollbar.cpp @@ -0,0 +1,1074 @@ +/**************************************************************************** +** +** Implementation of TQScrollBar class +** +** Created : 940427 +** +** 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 "tqscrollbar.h" +#ifndef TQT_NO_SCROLLBAR +#include "tqpainter.h" +#include "tqbitmap.h" +#include "ntqapplication.h" +#include "tqtimer.h" +#include "tqstyle.h" +#ifndef TQT_NO_CURSOR +#include +#endif +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif +#include + +/*! + \class TQScrollBar + \brief The TQScrollBar widget provides a vertical or horizontal scroll bar. + + \ingroup basic + + A scroll bar allows the user to control a value within a + program-definable range and gives users a visible indication of + the current value of a \link TQRangeControl range control \endlink. + + Scroll bars include four separate controls: + + \list + + \i The \e line-up and \e line-down controls are little buttons + which the user can use to move one "line" up or down. The meaning + of line is configurable. In editors and list boxes it means one + line of text; in an image viewer it might mean 20 pixels. + + \i The \e slider is the handle that indicates the current value of + the scroll bar, which the user can drag to change the value. This + part of the scroll bar is sometimes called the "thumb". + + \i The \e page-up/page-down control is the area on which the + slider slides (the scroll bar's background). Clicking here moves + the scroll bar towards the click. The meaning of "page" is also + configurable: in editors and list boxes it means as many lines as + there is space for in the widget. + + \endlist + + TQScrollBar has very few of its own functions; it mostly relies on + TQRangeControl. The most useful functions are setValue() to set the + scroll bar directly to some value; addPage(), addLine(), + subtractPage(), and subtractLine() to simulate the effects of + clicking (useful for accelerator keys); setSteps() to define the + values of pageStep() and lineStep(); and setRange() to set the + minValue() and maxValue() of the scroll bar. TQScrollBar has a + convenience constructor with which you can set most of these + properties. + + Some GUI styles (for example, the Windows and Motif styles + provided with TQt), also use the pageStep() value to calculate the + size of the slider. + + In addition to the access functions from TQRangeControl, TQScrollBar + provides a comprehensive set of signals: + \table + \header \i Signal \i Emitted when + \row \i \l valueChanged() + \i the scroll bar's value has changed. The tracking() + determines whether this signal is emitted during user + interaction. + \row \i \l sliderPressed() + \i the user starts to drag the slider. + \row \i \l sliderMoved() + \i the user drags the slider. + \row \i \l sliderReleased() + \i the user releases the slider. + \row \i \l nextLine() + \i the scroll bar has moved one line down or right. Line is + defined in TQRangeControl. + \row \i \l prevLine() + \i the scroll bar has moved one line up or left. + \row \i \l nextPage() + \i the scroll bar has moved one page down or right. + \row \i \l prevPage() + \i the scroll bar has moved one page up or left. + \endtable + + TQScrollBar only provides integer ranges. Note that although + TQScrollBar handles very large numbers, scroll bars on current + screens cannot usefully control ranges above about 100,000 pixels. + Beyond that, it becomes difficult for the user to control the + scroll bar using either the keyboard or the mouse. + + A scroll bar can be controlled by the keyboard, but it has a + default focusPolicy() of \c NoFocus. Use setFocusPolicy() to + enable keyboard focus. See keyPressEvent() for a list of key + bindings. + + If you need to add scroll bars to an interface, consider using the + TQScrollView class, which encapsulates the common uses for scroll + bars. + + + + \sa TQSlider TQSpinBox TQScrollView + \link guibooks.html#fowler GUI Design Handbook: Scroll Bar\endlink +*/ + + +/*! + \fn void TQScrollBar::valueChanged( int value ) + + This signal is emitted when the scroll bar value has changed, with + the new scroll bar \a value as an argument. +*/ + +/*! + \fn void TQScrollBar::sliderPressed() + + This signal is emitted when the user presses the slider with the + mouse. +*/ + +/*! + \fn void TQScrollBar::sliderMoved( int value ) + + This signal is emitted when the slider is dragged by the user, with + the new scroll bar \a value as an argument. + + This signal is emitted even when tracking is turned off. + + \sa tracking() valueChanged() nextLine() prevLine() nextPage() + prevPage() +*/ + +/*! + \fn void TQScrollBar::sliderReleased() + + This signal is emitted when the user releases the slider with the + mouse. +*/ + +/*! + \fn void TQScrollBar::nextLine() + + This signal is emitted when the scroll bar scrolls one line down + or right. +*/ + +/*! + \fn void TQScrollBar::prevLine() + + This signal is emitted when the scroll bar scrolls one line up or + left. +*/ + +/*! + \fn void TQScrollBar::nextPage() + + This signal is emitted when the scroll bar scrolls one page down + or right. +*/ + +/*! + \fn void TQScrollBar::prevPage() + + This signal is emitted when the scroll bar scrolls one page up or + left. +*/ + + + +static const int thresholdTime = 500; +static const int repeatTime = 50; + +#define HORIZONTAL (orientation() == Horizontal) +#define VERTICAL !HORIZONTAL +#define MOTIF_BORDER 2 +#define SLIDER_MIN 9 + + +/*! + Constructs a vertical scroll bar. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. + + The \c minValue defaults to 0, the \c maxValue to 99, with a \c + lineStep size of 1 and a \c pageStep size of 10, and an initial + \c value of 0. +*/ + +TQScrollBar::TQScrollBar( TQWidget *parent, const char *name ) + : TQWidget( parent, name ), orient( Vertical ) +{ + init(); +} + +/*! + Constructs a scroll bar. + + The \a orientation must be \c TQt::Vertical or \c TQt::Horizontal. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. + + The \c minValue defaults to 0, the \c maxValue to 99, with a \c + lineStep size of 1 and a \c pageStep size of 10, and an initial + \c value of 0. +*/ + +TQScrollBar::TQScrollBar( Orientation orientation, TQWidget *parent, + const char *name ) + : TQWidget( parent, name ), orient( orientation ) +{ + init(); +} + +/*! + Constructs a scroll bar whose value can never be smaller than \a + minValue or greater than \a maxValue, whose line step size is \a + lineStep and page step size is \a pageStep and whose value is + initially \a value (which is guaranteed to be in range using + bound()). + + If \a orientation is \c Vertical the scroll bar is vertical and if + it is \c Horizontal the scroll bar is horizontal. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. +*/ + +TQScrollBar::TQScrollBar( int minValue, int maxValue, int lineStep, int pageStep, + int value, Orientation orientation, + TQWidget *parent, const char *name ) + : TQWidget( parent, name ), + TQRangeControl( minValue, maxValue, lineStep, pageStep, value ), + orient( orientation ) +{ + init(); +} + +/*! + Destructor. +*/ +TQScrollBar::~TQScrollBar() +{ +} + +void TQScrollBar::init() +{ + track = TRUE; + sliderPos = 0; + pressedControl = TQStyle::SC_None; + clickedAt = FALSE; + setFocusPolicy( NoFocus ); + + repeater = 0; + + setBackgroundMode((TQt::BackgroundMode) + style().styleHint(TQStyle::SH_ScrollBar_BackgroundMode)); + + TQSizePolicy sp( TQSizePolicy::Minimum, TQSizePolicy::Fixed ); + if ( orient == Vertical ) + sp.transpose(); + setSizePolicy( sp ); + clearWState( WState_OwnSizePolicy ); +} + + +/*! + \property TQScrollBar::orientation + \brief the orientation of the scroll bar + + The orientation must be \l TQt::Vertical (the default) or \l + TQt::Horizontal. +*/ + +void TQScrollBar::setOrientation( Orientation orientation ) +{ + if ( orientation == orient ) + return; + if ( !testWState( WState_OwnSizePolicy ) ) { + TQSizePolicy sp = sizePolicy(); + sp.transpose(); + setSizePolicy( sp ); + clearWState( WState_OwnSizePolicy ); + } + + orient = orientation; + + positionSliderFromValue(); + update(); + updateGeometry(); +} + +/*! + \property TQScrollBar::tracking + \brief whether scroll bar tracking is enabled + + If tracking is enabled (the default), the scroll bar emits the + valueChanged() signal while the slider is being dragged. If + tracking is disabled, the scroll bar emits the valueChanged() + signal only when the user releases the mouse button after moving + the slider. +*/ + + +/*! + \property TQScrollBar::draggingSlider + \brief whether the user has clicked the mouse on the slider and is currently dragging it +*/ + +bool TQScrollBar::draggingSlider() const +{ + return pressedControl == TQStyle::SC_ScrollBarSlider; +} + + +/*! + Reimplements the virtual function TQWidget::setPalette(). + + Sets the background color to the mid color for Motif style scroll + bars using palette \a p. +*/ + +void TQScrollBar::setPalette( const TQPalette &p ) +{ + TQWidget::setPalette( p ); + setBackgroundMode((TQt::BackgroundMode) + style().styleHint(TQStyle::SH_ScrollBar_BackgroundMode)); +} + + +/*! \reimp */ +TQSize TQScrollBar::sizeHint() const +{ + constPolish(); + int sbextent = style().pixelMetric(TQStyle::PM_ScrollBarExtent, this); + + if ( orient == Horizontal ) { + return TQSize( 30, sbextent ); + } else { + return TQSize( sbextent, 30 ); + } +} + +/*! \fn void TQScrollBar::setSizePolicy( TQSizePolicy::SizeType, TQSizePolicy::SizeType, bool ) + \reimp +*/ + +/*! \reimp */ +void TQScrollBar::setSizePolicy( TQSizePolicy sp ) +{ + //## remove 4.0 + TQWidget::setSizePolicy( sp ); +} + +/*! + \internal + Implements the virtual TQRangeControl function. +*/ + +void TQScrollBar::valueChange() +{ + int tmp = sliderPos; + positionSliderFromValue(); + if ( tmp != sliderPos && isVisible() ) + drawControls(TQStyle::SC_ScrollBarAddPage | + TQStyle::SC_ScrollBarSubPage | + TQStyle::SC_ScrollBarSlider, + pressedControl ); + emit valueChanged(value()); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif +} + +/*! + \internal + Implements the virtual TQRangeControl function. +*/ + +void TQScrollBar::stepChange() +{ + rangeChange(); +} + +/*! + \internal + Implements the virtual TQRangeControl function. +*/ + +void TQScrollBar::rangeChange() +{ + positionSliderFromValue(); + + if ( isVisible() ) + drawControls(TQStyle::SC_ScrollBarAddLine | + TQStyle::SC_ScrollBarSubLine | + TQStyle::SC_ScrollBarAddPage | + TQStyle::SC_ScrollBarSubPage | + TQStyle::SC_ScrollBarFirst | + TQStyle::SC_ScrollBarLast | + TQStyle::SC_ScrollBarSlider, + pressedControl ); +} + + +/*! + Handles timer events for the scroll bar. +*/ + +void TQScrollBar::doAutoRepeat() +{ + bool sendRepeat = clickedAt; +#if !defined( TQT_NO_CURSOR ) && !defined( TQT_NO_STYLE ) + if(sendRepeat && (pressedControl == TQStyle::SC_ScrollBarAddPage || + pressedControl == TQStyle::SC_ScrollBarSubPage) && + style().styleHint(TQStyle::SH_ScrollBar_StopMouseOverSlider, this) && + style().querySubControl(TQStyle::CC_ScrollBar, this, + mapFromGlobal(TQCursor::pos()) ) == TQStyle::SC_ScrollBarSlider) + sendRepeat = FALSE; +#endif + if ( sendRepeat ){ + if ( repeater ) + repeater->changeInterval( repeatTime ); + action( (TQStyle::SubControl) pressedControl ); + TQApplication::syncX(); + } else { + stopAutoRepeat(); + } +} + + +/*! + Starts the auto-repeat logic. Some time after this function is + called, the auto-repeat starts taking effect and from then on + repeats until stopAutoRepeat() is called. +*/ + +void TQScrollBar::startAutoRepeat() +{ + if ( !repeater ) { + repeater = new TQTimer( this, "auto-repeat timer" ); + connect( repeater, TQ_SIGNAL(timeout()), + this, TQ_SLOT(doAutoRepeat()) ); + } + repeater->start( thresholdTime, FALSE ); +} + + +/*! + Stops the auto-repeat logic. +*/ + +void TQScrollBar::stopAutoRepeat() +{ + delete repeater; + repeater = 0; +} + + +/*! + \reimp +*/ +#ifndef TQT_NO_WHEELEVENT +void TQScrollBar::wheelEvent( TQWheelEvent *e ) +{ + static float offset = 0; + static TQScrollBar* offset_owner = 0; + if (offset_owner != this){ + offset_owner = this; + offset = 0; + } + if ( e->orientation() != orient && !rect().contains(e->pos()) ) + return; + e->accept(); + int step = TQMIN( TQApplication::wheelScrollLines()*lineStep(), + pageStep() ); + if ( ( e->state() & ControlButton ) || ( e->state() & ShiftButton ) ) + step = pageStep(); + offset += -e->delta()*step/120; + if (TQABS(offset)<1) + return; + setValue( value() + int(offset) ); + offset -= int(offset); +} +#endif + +/*! + \reimp +*/ +void TQScrollBar::keyPressEvent( TQKeyEvent *e ) +{ + // \list + // \i Left/Right move a horizontal scrollbar by one line. + // \i Up/Down move a vertical scrollbar by one line. + // \i PageUp moves up one page. + // \i PageDown moves down one page. + // \i Home moves to the start (minValue()). + // \i End moves to the end (maxValue()). + // \endlist + + // Note that unless you call setFocusPolicy(), the default NoFocus + // will apply and the user will not be able to use the keyboard to + // interact with the scrollbar. + switch ( e->key() ) { + case Key_Left: + if ( orient == Horizontal ) + subtractLine(); + break; + case Key_Right: + if ( orient == Horizontal ) + addLine(); + break; + case Key_Up: + if ( orient == Vertical ) + subtractLine(); + break; + case Key_Down: + if ( orient == Vertical ) + addLine(); + break; + case Key_PageUp: + subtractPage(); + break; + case Key_PageDown: + addPage(); + break; + case Key_Home: + setValue( minValue() ); + break; + case Key_End: + setValue( maxValue() ); + break; + default: + e->ignore(); + break; + } +} + + +/*! + \reimp +*/ +void TQScrollBar::resizeEvent( TQResizeEvent * ) +{ + positionSliderFromValue(); +} + + +/*! + \reimp +*/ +void TQScrollBar::paintEvent( TQPaintEvent * ) +{ + TQPainter p( this ); + drawControls(TQStyle::SC_ScrollBarAddLine | + TQStyle::SC_ScrollBarSubLine | + TQStyle::SC_ScrollBarAddPage | + TQStyle::SC_ScrollBarSubPage | + TQStyle::SC_ScrollBarFirst | + TQStyle::SC_ScrollBarLast | + TQStyle::SC_ScrollBarSlider, + pressedControl, &p ); +} + +static TQCOORD sliderStartPos = 0; + +/*! + \reimp + */ +void TQScrollBar::contextMenuEvent( TQContextMenuEvent *e ) +{ + if(clickedAt) + e->consume(); + else + e->ignore(); +} + +/*! + \reimp +*/ +void TQScrollBar::mousePressEvent( TQMouseEvent *e ) +{ + bool midButtonAbsPos = + style().styleHint(TQStyle::SH_ScrollBar_MiddleClickAbsolutePosition, + this); + + if ( !(e->button() == LeftButton || + (midButtonAbsPos && e->button() == MidButton) ) ) + return; + + if ( maxValue() == minValue() ) // nothing to be done + return; + + if ( e->state() & MouseButtonMask ) // another button was already pressed + return; + + clickedAt = TRUE; + pressedControl = style().querySubControl(TQStyle::CC_ScrollBar, this, e->pos() ); + + if ( (pressedControl == TQStyle::SC_ScrollBarAddPage || + pressedControl == TQStyle::SC_ScrollBarSubPage || + pressedControl == TQStyle::SC_ScrollBarSlider ) && + ((midButtonAbsPos && e->button() == MidButton) || + (style().styleHint(TQStyle::SH_ScrollBar_LeftClickAbsolutePosition) && e->button() == LeftButton)) ) { + + TQRect sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarSlider ), + gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarGroove ); + int sliderMin, sliderMax, sliderLength; + sliderMin = sliderMax = sliderLength = 0; + if (HORIZONTAL) { + sliderMin = gr.x(); + sliderMax = sliderMin + gr.width(); + sliderLength = sr.width(); + } else { + sliderMin = gr.y(); + sliderMax = sliderMin + gr.height(); + sliderLength = sr.height(); + } + + int newSliderPos = (HORIZONTAL ? e->pos().x() : e->pos().y()) + - sliderLength/2; + newSliderPos = TQMIN( newSliderPos, sliderMax - sliderLength ); + newSliderPos = TQMAX( newSliderPos, sliderMin ); + setValue( sliderPosToRangeValue(newSliderPos) ); + sliderPos = newSliderPos; + pressedControl = TQStyle::SC_ScrollBarSlider; + } + + if ( pressedControl == TQStyle::SC_ScrollBarSlider ) { + clickOffset = (TQCOORD)( (HORIZONTAL ? e->pos().x() : e->pos().y()) + - sliderPos ); + slidePrevVal = value(); + sliderStartPos = sliderPos; + drawControls( pressedControl, pressedControl ); + emit sliderPressed(); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ScrollingStart ); +#endif + } else if ( pressedControl != TQStyle::SC_None ) { + drawControls( pressedControl, pressedControl ); + action( (TQStyle::SubControl) pressedControl ); + startAutoRepeat(); + } +} + + +/*! + \reimp +*/ +void TQScrollBar::mouseReleaseEvent( TQMouseEvent *e ) +{ + if ( !clickedAt ) + return; + + if ( e->stateAfter() & MouseButtonMask ) // some other button is still pressed + return; + + TQStyle::SubControl tmp = (TQStyle::SubControl) pressedControl; + clickedAt = FALSE; + stopAutoRepeat(); + mouseMoveEvent( e ); // Might have moved since last mouse move event. + pressedControl = TQStyle::SC_None; + + if (tmp == TQStyle::SC_ScrollBarSlider) { + directSetValue( calculateValueFromSlider() ); + emit sliderReleased(); + if ( value() != prevValue() ) { + emit valueChanged( value() ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif + } +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ScrollingEnd ); +#endif + } + drawControls( tmp, pressedControl ); + if ( e->button() == MidButton ) + repaint( FALSE ); +} + + +/*! + \reimp +*/ +void TQScrollBar::mouseMoveEvent( TQMouseEvent *e ) +{ + if ( !isVisible() ) { + clickedAt = FALSE; + return; + } + + bool mcab = style().styleHint(TQStyle::SH_ScrollBar_MiddleClickAbsolutePosition, + this); + if ( ! clickedAt || ! (e->state() & LeftButton || + ((e->state() & MidButton) && mcab))) + return; + + int newSliderPos; + if ( pressedControl == TQStyle::SC_ScrollBarSlider ) { + TQRect gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarGroove ), + sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarSlider ); + int sliderMin, sliderMax, sliderLength; + + if (HORIZONTAL) { + sliderLength = sr.width(); + sliderMin = gr.x(); + sliderMax = gr.right() - sliderLength + 1; + } else { + sliderLength = sr.height(); + sliderMin = gr.y(); + sliderMax = gr.bottom() - sliderLength + 1; + } + + TQRect r = rect(); + int m = style().pixelMetric(TQStyle::PM_MaximumDragDistance, this); + if ( m >= 0 ) { + if ( orientation() == Horizontal ) + r.setRect( r.x() - m, r.y() - 2*m, r.width() + 2*m, r.height() + 4*m ); + else + r.setRect( r.x() - 2*m, r.y() - m, r.width() + 4*m, r.height() + 2*m ); + if (! r.contains( e->pos())) + newSliderPos = sliderStartPos; + else + newSliderPos = (HORIZONTAL ? e->pos().x() : + e->pos().y()) -clickOffset; + } else + newSliderPos = (HORIZONTAL ? e->pos().x() : + e->pos().y()) -clickOffset; + + if ( newSliderPos < sliderMin ) + newSliderPos = sliderMin; + else if ( newSliderPos > sliderMax ) + newSliderPos = sliderMax; + int newVal = sliderPosToRangeValue(newSliderPos); + if ( newVal != slidePrevVal ) + emit sliderMoved( newVal ); + if ( track && newVal != value() ) { + directSetValue( newVal ); // Set directly, painting done below + emit valueChanged( value() ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif + } + slidePrevVal = newVal; + sliderPos = (TQCOORD)newSliderPos; + drawControls( TQStyle::SC_ScrollBarAddPage | + TQStyle::SC_ScrollBarSlider | + TQStyle::SC_ScrollBarSubPage, + pressedControl ); + } else if (! style().styleHint(TQStyle::SH_ScrollBar_ScrollWhenPointerLeavesControl)) { + // stop scrolling when the mouse pointer leaves a control + // similar to push buttons + if ( pressedControl != (uint)style().querySubControl(TQStyle::CC_ScrollBar, this, e->pos() ) ) { + drawControls( pressedControl, TQStyle::SC_None ); + stopAutoRepeat(); + } else if ( !repeater ) { + drawControls( pressedControl, pressedControl ); + action( (TQStyle::SubControl) pressedControl ); + startAutoRepeat(); + } + } +} + + +/*! + \fn int TQScrollBar::sliderStart() const + + Returns the pixel position where the scroll bar slider starts. + + This is equivalent to sliderRect().y() for vertical scroll bars or + sliderRect().x() for horizontal scroll bars. +*/ + +/*! + Returns the scroll bar slider rectangle. + + \sa sliderStart() +*/ + +TQRect TQScrollBar::sliderRect() const +{ + return style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarSlider ); +} + +void TQScrollBar::positionSliderFromValue() +{ + sliderPos = (TQCOORD)rangeValueToSliderPos( value() ); +} + +int TQScrollBar::calculateValueFromSlider() const +{ + return sliderPosToRangeValue( sliderPos ); +} + +int TQScrollBar::rangeValueToSliderPos( int v ) const +{ + TQRect gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarGroove ); + TQRect sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarSlider ); + int sliderMin, sliderMax, sliderLength; + + if (HORIZONTAL) { + sliderLength = sr.width(); + sliderMin = gr.x(); + sliderMax = gr.right() - sliderLength + 1; + } else { + sliderLength = sr.height(); + sliderMin = gr.y(); + sliderMax = gr.bottom() - sliderLength + 1; + } + + return positionFromValue( v, sliderMax-sliderMin ) + sliderMin; +} + +int TQScrollBar::sliderPosToRangeValue( int pos ) const +{ + TQRect gr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarGroove ); + TQRect sr = style().querySubControlMetrics(TQStyle::CC_ScrollBar, this, + TQStyle::SC_ScrollBarSlider ); + int sliderMin, sliderMax, sliderLength; + + if (HORIZONTAL) { + sliderLength = sr.width(); + sliderMin = gr.x(); + sliderMax = gr.right() - sliderLength + 1; + } else { + sliderLength = sr.height(); + sliderMin = gr.y(); + sliderMax = gr.bottom() - sliderLength + 1; + } + + return valueFromPosition( pos - sliderMin, sliderMax - sliderMin ); +} + + +void TQScrollBar::action( int control ) +{ + switch( control ) { + case TQStyle::SC_ScrollBarAddLine: + addLine(); + emit nextLine(); + break; + case TQStyle::SC_ScrollBarSubLine: + subtractLine(); + emit prevLine(); + break; + case TQStyle::SC_ScrollBarAddPage: + addPage(); + emit nextPage(); + break; + case TQStyle::SC_ScrollBarSubPage: + subtractPage(); + emit prevPage(); + break; + case TQStyle::SC_ScrollBarFirst: + setValue( minValue() ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif + emit valueChanged( minValue() ); + break; + case TQStyle::SC_ScrollBarLast: + setValue( maxValue() ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif + emit valueChanged( maxValue() ); + break; + default: + break; + } +} + + +void TQScrollBar::drawControls( uint controls, uint activeControl ) const +{ + TQPainter p ( this ); + drawControls( controls, activeControl, &p ); +} + + +void TQScrollBar::drawControls( uint controls, uint activeControl, + TQPainter *p ) const +{ + if ( !isUpdatesEnabled() ) + return; + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasFocus()) + flags |= TQStyle::Style_HasFocus; + if (hasMouse()) + flags |= TQStyle::Style_MouseOver; + if ( orientation() == Horizontal ) + flags |= TQStyle::Style_Horizontal; + + style().drawComplexControl(TQStyle::CC_ScrollBar, p, this, rect(), colorGroup(), + flags, (TQStyle::SubControl) controls, + (TQStyle::SubControl) activeControl ); +} + +/*! + \reimp +*/ +void TQScrollBar::styleChange( TQStyle& old ) +{ + positionSliderFromValue(); + setBackgroundMode((TQt::BackgroundMode) + style().styleHint(TQStyle::SH_ScrollBar_BackgroundMode)); + TQWidget::styleChange( old ); +} + +/*! + \property TQScrollBar::minValue + \brief the scroll bar's minimum value + + When setting this property, the \l TQScrollBar::maxValue is + adjusted if necessary to ensure that the range remains valid. + + \sa setRange() +*/ +int TQScrollBar::minValue() const +{ + return TQRangeControl::minValue(); +} + +void TQScrollBar::setMinValue( int minVal ) +{ + TQRangeControl::setMinValue( minVal ); +} + +/*! + \property TQScrollBar::maxValue + \brief the scroll bar's maximum value + + When setting this property, the \l TQScrollBar::minValue is + adjusted if necessary to ensure that the range remains valid. + + \sa setRange() +*/ +int TQScrollBar::maxValue() const +{ + return TQRangeControl::maxValue(); +} + +void TQScrollBar::setMaxValue( int maxVal ) +{ + TQRangeControl::setMaxValue( maxVal ); +} + +/*! + \property TQScrollBar::lineStep + \brief the line step + + When setting lineStep, the virtual stepChange() function will be + called if the new line step is different from the previous + setting. + + \sa setSteps() TQRangeControl::pageStep() setRange() +*/ + +int TQScrollBar::lineStep() const +{ + return TQRangeControl::lineStep(); +} + +/*! + \property TQScrollBar::pageStep + \brief the page step + + When setting pageStep, the virtual stepChange() function will be + called if the new page step is different from the previous + setting. + + \sa TQRangeControl::setSteps() setLineStep() setRange() +*/ + +int TQScrollBar::pageStep() const +{ + return TQRangeControl::pageStep(); +} + +void TQScrollBar::setLineStep( int i ) +{ + setSteps( i, pageStep() ); +} + +void TQScrollBar::setPageStep( int i ) +{ + setSteps( lineStep(), i ); +} + +/*! + \property TQScrollBar::value + \brief the scroll bar's value + + \sa TQRangeControl::value() prevValue() +*/ + +int TQScrollBar::value() const +{ + return TQRangeControl::value(); +} + +void TQScrollBar::setValue( int i ) +{ + TQRangeControl::setValue( i ); +} + + +/*! + This function is called when the scrollbar is hidden. +*/ +void TQScrollBar::hideEvent( TQHideEvent* ) +{ + pressedControl = TQStyle::SC_None; + clickedAt = FALSE; +} + + +#undef ADD_LINE_ACTIVE +#undef SUB_LINE_ACTIVE +#endif diff --git a/src/widgets/tqscrollbar.h b/src/widgets/tqscrollbar.h new file mode 100644 index 000000000..6a298c96f --- /dev/null +++ b/src/widgets/tqscrollbar.h @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** Definition of TQScrollBar class +** +** Created : 940427 +** +** 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 TQSCROLLBAR_H +#define TQSCROLLBAR_H + +class TQTimer; + +#ifndef QT_H +#include "tqwidget.h" +#include "ntqrangecontrol.h" +#endif // QT_H + +#ifndef TQT_NO_SCROLLBAR + +class TQ_EXPORT TQScrollBar : public TQWidget, public TQRangeControl +{ + TQ_OBJECT + TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) + TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) + TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) + TQ_PROPERTY( int pageStep READ pageStep WRITE setPageStep ) + TQ_PROPERTY( int value READ value WRITE setValue ) + TQ_PROPERTY( bool tracking READ tracking WRITE setTracking ) + TQ_PROPERTY( bool draggingSlider READ draggingSlider ) + TQ_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) + +public: + TQScrollBar( TQWidget *parent, const char* name = 0 ); + TQScrollBar( Orientation, TQWidget *parent, const char* name = 0 ); + TQScrollBar( int minValue, int maxValue, int lineStep, int pageStep, + int value, Orientation, TQWidget *parent, const char* name = 0 ); + ~TQScrollBar(); + + virtual void setOrientation( Orientation ); + Orientation orientation() const; + virtual void setTracking( bool enable ); + bool tracking() const; + bool draggingSlider() const; + + virtual void setPalette( const TQPalette & ); + virtual TQSize sizeHint() const; + virtual void setSizePolicy( TQSizePolicy sp ); + void setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw = FALSE ); + + int minValue() const; + int maxValue() const; + void setMinValue( int ); + void setMaxValue( int ); + int lineStep() const; + int pageStep() const; + void setLineStep( int ); + void setPageStep( int ); + int value() const; + + int sliderStart() const; + TQRect sliderRect() const; + +public slots: + void setValue( int ); + +signals: + void valueChanged( int value ); + void sliderPressed(); + void sliderMoved( int value ); + void sliderReleased(); + void nextLine(); + void prevLine(); + void nextPage(); + void prevPage(); + +protected: +#ifndef TQT_NO_WHEELEVENT + void wheelEvent( TQWheelEvent * ); +#endif + void keyPressEvent( TQKeyEvent * ); + void resizeEvent( TQResizeEvent * ); + void paintEvent( TQPaintEvent * ); + + void mousePressEvent( TQMouseEvent * ); + void mouseReleaseEvent( TQMouseEvent * ); + void mouseMoveEvent( TQMouseEvent * ); + void contextMenuEvent( TQContextMenuEvent * ); + void hideEvent( TQHideEvent* ); + + void valueChange(); + void stepChange(); + void rangeChange(); + + void styleChange( TQStyle& ); + +private slots: + void doAutoRepeat(); + +private: + void init(); + void positionSliderFromValue(); + int calculateValueFromSlider() const; + + void startAutoRepeat(); + void stopAutoRepeat(); + + int rangeValueToSliderPos( int val ) const; + int sliderPosToRangeValue( int val ) const; + + void action( int control ); + + void drawControls( uint controls, uint activeControl ) const; + void drawControls( uint controls, uint activeControl, + TQPainter *p ) const; + + uint pressedControl; + bool track; + bool clickedAt; + Orientation orient; + + int slidePrevVal; + TQCOORD sliderPos; + TQCOORD clickOffset; + + TQTimer * repeater; + void * d; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQScrollBar( const TQScrollBar & ); + TQScrollBar &operator=( const TQScrollBar & ); +#endif +}; + + +inline void TQScrollBar::setTracking( bool t ) +{ + track = t; +} + +inline bool TQScrollBar::tracking() const +{ + return track; +} + +inline TQScrollBar::Orientation TQScrollBar::orientation() const +{ + return orient; +} + +inline int TQScrollBar::sliderStart() const +{ + return sliderPos; +} + +inline void TQScrollBar::setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw ) +{ + TQWidget::setSizePolicy( hor, ver, hfw ); +} + + +#endif // TQT_NO_SCROLLBAR + +#endif // TQSCROLLBAR_H diff --git a/src/widgets/tqscrollview.cpp b/src/widgets/tqscrollview.cpp new file mode 100644 index 000000000..603110592 --- /dev/null +++ b/src/widgets/tqscrollview.cpp @@ -0,0 +1,2847 @@ +/**************************************************************************** +** +** Implementation of TQScrollView class +** +** Created : 950524 +** +** 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 "tqwidget.h" +#ifndef TQT_NO_SCROLLVIEW +#include "tqscrollbar.h" +#include "tqobjectlist.h" +#include "tqpainter.h" +#include "tqpixmap.h" +#include "ntqcursor.h" +#include "ntqfocusdata.h" +#include "tqscrollview.h" +#include "tqptrdict.h" +#include "ntqapplication.h" +#include "tqtimer.h" +#include "tqstyle.h" +#include "ntqlistview.h" +#ifdef TQ_WS_MAC +# include "qt_mac.h" +#endif + +static const int coord_limit = 4000; +static const int autoscroll_margin = 16; +static const int initialScrollTime = 30; +static const int initialScrollAccel = 5; + +struct TQSVChildRec { + TQSVChildRec(TQWidget* c, int xx, int yy) : + child(c), + x(xx), y(yy) + { + } + + void hideOrShow(TQScrollView* sv, TQWidget* clipped_viewport); + void moveTo(TQScrollView* sv, int xx, int yy, TQWidget* clipped_viewport) + { + if ( x != xx || y != yy ) { + x = xx; + y = yy; + hideOrShow(sv,clipped_viewport); + } + } + TQWidget* child; + int x, y; +}; + +void TQSVChildRec::hideOrShow(TQScrollView* sv, TQWidget* clipped_viewport) +{ + if ( clipped_viewport ) { + if ( x+child->width() < sv->contentsX()+clipped_viewport->x() + || x > sv->contentsX()+clipped_viewport->width() + || y+child->height() < sv->contentsY()+clipped_viewport->y() + || y > sv->contentsY()+clipped_viewport->height() ) { + child->move(clipped_viewport->width(), + clipped_viewport->height()); + } else { + child->move(x-sv->contentsX()-clipped_viewport->x(), + y-sv->contentsY()-clipped_viewport->y()); + } + } else { + child->move(x-sv->contentsX(), y-sv->contentsY()); + } +} + +class TQViewportWidget : public TQWidget +{ + TQ_OBJECT + +public: + TQViewportWidget( TQScrollView* parent=0, const char* name=0, WFlags f = 0 ) + : TQWidget( parent, name, f ) {} +}; + +class TQClipperWidget : public TQWidget +{ + TQ_OBJECT + +public: + TQClipperWidget( TQWidget * parent=0, const char * name=0, WFlags f=0 ) + : TQWidget ( parent,name,f) {} +}; + +#include "tqscrollview.moc" + +class TQScrollViewData { +public: + TQScrollViewData(TQScrollView* parent, int vpwflags) : + hbar( new TQScrollBar( TQScrollBar::Horizontal, parent, "qt_hbar" ) ), + vbar( new TQScrollBar( TQScrollBar::Vertical, parent, "qt_vbar" ) ), + viewport( new TQViewportWidget( parent, "qt_viewport", vpwflags ) ), + clipped_viewport( 0 ), + flags( vpwflags ), + vx( 0 ), vy( 0 ), vwidth( 1 ), vheight( 1 ), +#ifndef TQT_NO_DRAGANDDROP + autoscroll_timer( parent, "scrollview autoscroll timer" ), + drag_autoscroll( TRUE ), +#endif + scrollbar_timer( parent, "scrollview scrollbar timer" ), + inresize( FALSE ), use_cached_size_hint( TRUE ) + { + l_marg = r_marg = t_marg = b_marg = 0; + viewport->polish(); + viewport->setBackgroundMode( TQWidget::PaletteDark ); + viewport->setBackgroundOrigin( TQWidget::WidgetOrigin ); + vMode = TQScrollView::Auto; + hMode = TQScrollView::Auto; + corner = 0; + defaultCorner = new TQWidget( parent, "qt_default_corner" ); + defaultCorner->hide(); + vbar->setSteps( 20, 1/*set later*/ ); + hbar->setSteps( 20, 1/*set later*/ ); + policy = TQScrollView::Default; + signal_choke = FALSE; + static_bg = FALSE; + fake_scroll = FALSE; + hbarPressed = FALSE; + vbarPressed = FALSE; + } + ~TQScrollViewData(); + + TQSVChildRec* rec(TQWidget* w) { return childDict.find(w); } + TQSVChildRec* ancestorRec(TQWidget* w); + TQSVChildRec* addChildRec(TQWidget* w, int x, int y ) + { + TQSVChildRec *r = new TQSVChildRec(w,x,y); + children.append(r); + childDict.insert(w, r); + return r; + } + void deleteChildRec(TQSVChildRec* r) + { + childDict.remove(r->child); + children.removeRef(r); + delete r; + } + + void hideOrShowAll(TQScrollView* sv, bool isScroll = FALSE ); + void moveAllBy(int dx, int dy); + bool anyVisibleChildren(); + void autoMove(TQScrollView* sv); + void autoResize(TQScrollView* sv); + void autoResizeHint(TQScrollView* sv); + void viewportResized( int w, int h ); + + TQScrollBar* hbar; + TQScrollBar* vbar; + bool hbarPressed; + bool vbarPressed; + TQViewportWidget* viewport; + TQClipperWidget* clipped_viewport; + int flags; + TQPtrList children; + TQPtrDict childDict; + TQWidget* corner, *defaultCorner; + int vx, vy, vwidth, vheight; // for drawContents-style usage + int l_marg, r_marg, t_marg, b_marg; + TQScrollView::ResizePolicy policy; + TQScrollView::ScrollBarMode vMode; + TQScrollView::ScrollBarMode hMode; +#ifndef TQT_NO_DRAGANDDROP + TQPoint cpDragStart; + TQTimer autoscroll_timer; + int autoscroll_time; + int autoscroll_accel; + bool drag_autoscroll; +#endif + TQTimer scrollbar_timer; + + uint static_bg : 1; + uint fake_scroll : 1; + + // This variable allows ensureVisible to move the contents then + // update both the sliders. Otherwise, updating the sliders would + // cause two image scrolls, creating ugly flashing. + // + uint signal_choke : 1; + + // This variables indicates in updateScrollBars() that we are + // in a resizeEvent() and thus don't want to flash scrollbars + uint inresize : 1; + uint use_cached_size_hint : 1; + TQSize cachedSizeHint; + + inline int contentsX() const { return -vx; } + inline int contentsY() const { return -vy; } + inline int contentsWidth() const { return vwidth; } +}; + +inline TQScrollViewData::~TQScrollViewData() +{ + children.setAutoDelete( TRUE ); +} + +TQSVChildRec* TQScrollViewData::ancestorRec(TQWidget* w) +{ + if ( clipped_viewport ) { + while (w->parentWidget() != clipped_viewport) { + w = w->parentWidget(); + if (!w) return 0; + } + } else { + while (w->parentWidget() != viewport) { + w = w->parentWidget(); + if (!w) return 0; + } + } + return rec(w); +} + +void TQScrollViewData::hideOrShowAll(TQScrollView* sv, bool isScroll ) +{ + if ( !clipped_viewport ) + return; + if ( clipped_viewport->x() <= 0 + && clipped_viewport->y() <= 0 + && clipped_viewport->width()+clipped_viewport->x() >= + viewport->width() + && clipped_viewport->height()+clipped_viewport->y() >= + viewport->height() ) { + // clipped_viewport still covers viewport + if( static_bg ) + clipped_viewport->repaint( TRUE ); + else if ( ( !isScroll && !clipped_viewport->testWFlags( TQt::WStaticContents) ) + || static_bg ) + TQApplication::postEvent( clipped_viewport, + new TQPaintEvent( clipped_viewport->clipRegion(), + !clipped_viewport->testWFlags(TQt::WResizeNoErase) ) ); + } else { + // Re-center + int nx = ( viewport->width() - clipped_viewport->width() ) / 2; + int ny = ( viewport->height() - clipped_viewport->height() ) / 2; + clipped_viewport->move(nx,ny); + clipped_viewport->update(); + } + for (TQSVChildRec *r = children.first(); r; r=children.next()) { + r->hideOrShow(sv, clipped_viewport); + } +} + +void TQScrollViewData::moveAllBy(int dx, int dy) +{ + if ( clipped_viewport && !static_bg ) { + clipped_viewport->move( clipped_viewport->x()+dx, + clipped_viewport->y()+dy ); + } else { + for (TQSVChildRec *r = children.first(); r; r=children.next()) { + r->child->move(r->child->x()+dx,r->child->y()+dy); + } + if ( static_bg ) + viewport->repaint( TRUE ); + } +} + +bool TQScrollViewData::anyVisibleChildren() +{ + for (TQSVChildRec *r = children.first(); r; r=children.next()) { + if (r->child->isVisible()) return TRUE; + } + return FALSE; +} + +void TQScrollViewData::autoMove(TQScrollView* sv) +{ + if ( policy == TQScrollView::AutoOne ) { + TQSVChildRec* r = children.first(); + if (r) + sv->setContentsPos(-r->child->x(),-r->child->y()); + } +} + +void TQScrollViewData::autoResize(TQScrollView* sv) +{ + if ( policy == TQScrollView::AutoOne ) { + TQSVChildRec* r = children.first(); + if (r) + sv->resizeContents(r->child->width(),r->child->height()); + } +} + +void TQScrollViewData::autoResizeHint(TQScrollView* sv) +{ + if ( policy == TQScrollView::AutoOne ) { + TQSVChildRec* r = children.first(); + if (r) { + TQSize s = r->child->sizeHint(); + if ( s.isValid() ) + r->child->resize(s); + } + } else if ( policy == TQScrollView::AutoOneFit ) { + TQSVChildRec* r = children.first(); + if (r) { + TQSize sh = r->child->sizeHint(); + sh = sh.boundedTo( r->child->maximumSize() ); + sv->resizeContents( sh.width(), sh.height() ); + } + } +} + +void TQScrollViewData::viewportResized( int w, int h ) +{ + if ( policy == TQScrollView::AutoOneFit ) { + TQSVChildRec* r = children.first(); + if (r) { + TQSize sh = r->child->sizeHint(); + sh = sh.boundedTo( r->child->maximumSize() ); + r->child->resize( TQMAX(w,sh.width()), TQMAX(h,sh.height()) ); + } + + } +} + + +/*! + \class TQScrollView tqscrollview.h + \brief The TQScrollView widget provides a scrolling area with on-demand scroll bars. + + \ingroup abstractwidgets + \mainclass + + The TQScrollView is a large canvas - potentially larger than the + coordinate system normally supported by the underlying window + system. This is important because it is quite easy to go beyond + these limitations (e.g. many web pages are more than 32000 pixels + high). Additionally, the TQScrollView can have TQWidgets positioned + on it that scroll around with the drawn content. These sub-widgets + can also have positions outside the normal coordinate range (but + they are still limited in size). + + To provide content for the widget, inherit from TQScrollView, + reimplement drawContents() and use resizeContents() to set the + size of the viewed area. Use addChild() and moveChild() to + position widgets on the view. + + To use TQScrollView effectively it is important to understand its + widget structure in the three styles of use: a single large child + widget, a large panning area with some widgets and a large panning + area with many widgets. + + \section1 Using One Big Widget + + \img tqscrollview-vp2.png + + The first, simplest usage of TQScrollView (depicted above), is + appropriate for scrolling areas that are never more than about + 4000 pixels in either dimension (this is about the maximum + reliable size on X11 servers). In this usage, you just make one + large child in the TQScrollView. The child should be a child of the + viewport() of the scrollview and be added with addChild(): + \code + TQScrollView* sv = new TQScrollView(...); + TQVBox* big_box = new TQVBox(sv->viewport()); + sv->addChild(big_box); + \endcode + You can go on to add arbitrary child widgets to the single child + in the scrollview as you would with any widget: + \code + TQLabel* child1 = new TQLabel("CHILD", big_box); + TQLabel* child2 = new TQLabel("CHILD", big_box); + TQLabel* child3 = new TQLabel("CHILD", big_box); + ... + \endcode + + Here the TQScrollView has four children: the viewport(), the + verticalScrollBar(), the horizontalScrollBar() and a small + cornerWidget(). The viewport() has one child: the big TQVBox. The + TQVBox has the three TQLabel objects as child widgets. When the view + is scrolled, the TQVBox is moved; its children move with it as + child widgets normally do. + + \section1 Using a Very Big View with Some Widgets + + \img tqscrollview-vp.png + + The second usage of TQScrollView (depicted above) is appropriate + when few, if any, widgets are on a very large scrolling area that + is potentially larger than 4000 pixels in either dimension. In + this usage you call resizeContents() to set the size of the area + and reimplement drawContents() to paint the contents. You may also + add some widgets by making them children of the viewport() and + adding them with addChild() (this is the same as the process for + the single large widget in the previous example): + \code + TQScrollView* sv = new TQScrollView(...); + TQLabel* child1 = new TQLabel("CHILD", sv->viewport()); + sv->addChild(child1); + TQLabel* child2 = new TQLabel("CHILD", sv->viewport()); + sv->addChild(child2); + TQLabel* child3 = new TQLabel("CHILD", sv->viewport()); + sv->addChild(child3); + \endcode + Here, the TQScrollView has the same four children: the viewport(), + the verticalScrollBar(), the horizontalScrollBar() and a small + cornerWidget(). The viewport() has the three TQLabel objects as + child widgets. When the view is scrolled, the scrollview moves the + child widgets individually. + + \section1 Using a Very Big View with Many Widgets + + \target enableclipper + \img tqscrollview-cl.png + + The final usage of TQScrollView (depicted above) is appropriate + when many widgets are on a very large scrolling area that is + potentially larger than 4000 pixels in either dimension. In this + usage you call resizeContents() to set the size of the area and + reimplement drawContents() to paint the contents. You then call + enableClipper(TRUE) and add widgets, again by making them children + of the viewport(), and adding them with addChild(): + \code + TQScrollView* sv = new TQScrollView(...); + sv->enableClipper(TRUE); + TQLabel* child1 = new TQLabel("CHILD", sv->viewport()); + sv->addChild(child1); + TQLabel* child2 = new TQLabel("CHILD", sv->viewport()); + sv->addChild(child2); + TQLabel* child3 = new TQLabel("CHILD", sv->viewport()); + sv->addChild(child3); + \endcode + + Here, the TQScrollView has four children: the clipper() (not the + viewport() this time), the verticalScrollBar(), the + horizontalScrollBar() and a small cornerWidget(). The clipper() + has one child: the viewport(). The viewport() has the same three + labels as child widgets. When the view is scrolled the viewport() + is moved; its children move with it as child widgets normally do. + + \target allviews + \section1 Details Relevant for All Views + + Normally you will use the first or third method if you want any + child widgets in the view. + + Note that the widget you see in the scrolled area is the + viewport() widget, not the TQScrollView itself. So to turn mouse + tracking on, for example, use viewport()->setMouseTracking(TRUE). + + To enable drag-and-drop, you would setAcceptDrops(TRUE) on the + TQScrollView (because drag-and-drop events propagate to the + parent). But to work out the logical position in the view, you + would need to map the drop co-ordinate from being relative to the + TQScrollView to being relative to the contents; use the function + viewportToContents() for this. + + To handle mouse events on the scrolling area, subclass scrollview + as you would subclass other widgets, but rather than + reimplementing mousePressEvent(), reimplement + contentsMousePressEvent() instead. The contents specific event + handlers provide translated events in the coordinate system of the + scrollview. If you reimplement mousePressEvent(), you'll get + called only when part of the TQScrollView is clicked: and the only + such part is the "corner" (if you don't set a cornerWidget()) and + the frame; everything else is covered up by the viewport, clipper + or scroll bars. + + When you construct a TQScrollView, some of the widget flags apply + to the viewport() instead of being sent to the TQWidget constructor + for the TQScrollView. This applies to \c WNoAutoErase, \c + WStaticContents, and \c WPaintClever. See \l TQt::WidgetFlags for + documentation about these flags. Here are some examples: + + \list + + \i An image-manipulation widget would use \c + WNoAutoErase|WStaticContents because the widget draws all pixels + itself, and when its size increases, it only needs a paint event + for the new part because the old part remains unchanged. + + \i A scrolling game widget in which the background scrolls as the + characters move might use \c WNoAutoErase (in addition to \c + WStaticContents) so that the window system background does not + flash in and out during scrolling. + + \i A word processing widget might use \c WNoAutoErase and repaint + itself line by line to get a less-flickery resizing. If the widget + is in a mode in which no text justification can take place, it + might use \c WStaticContents too, so that it would only get a + repaint for the newly visible parts. + + \endlist + + Child widgets may be moved using addChild() or moveChild(). Use + childX() and childY() to get the position of a child widget. + + A widget may be placed in the corner between the vertical and + horizontal scrollbars with setCornerWidget(). You can get access + to the scrollbars using horizontalScrollBar() and + verticalScrollBar(), and to the viewport with viewport(). The + scroll view can be scrolled using scrollBy(), ensureVisible(), + setContentsPos() or center(). + + The visible area is given by visibleWidth() and visibleHeight(), + and the contents area by contentsWidth() and contentsHeight(). The + contents may be repainted using one of the repaintContents() or + updateContents() functions. + + Coordinate conversion is provided by contentsToViewport() and + viewportToContents(). + + The contentsMoving() signal is emitted just before the contents + are moved to a new position. + + \warning TQScrollView currently does not erase the background when + resized, i.e. you must always clear the background manually in + scrollview subclasses. This will change in a future version of TQt + and we recommend specifying the WNoAutoErase flag explicitly. + + +*/ + + +/*! + \enum TQScrollView::ResizePolicy + + This enum type is used to control a TQScrollView's reaction to + resize events. + + \value Default the TQScrollView selects one of the other settings + automatically when it has to. In this version of TQt, TQScrollView + changes to \c Manual if you resize the contents with + resizeContents() and to \c AutoOne if a child is added. + + \value Manual the contents stays the size set by resizeContents(). + + \value AutoOne if there is only one child widget the contents stays + the size of that widget. Otherwise the behavior is undefined. + + \value AutoOneFit if there is only one child widget the contents stays + the size of that widget's sizeHint(). If the scrollview is resized + larger than the child's sizeHint(), the child will be resized to + fit. If there is more than one child, the behavior is undefined. + +*/ +//#### The widget will be resized to its sizeHint() when a LayoutHint event +//#### is received + +/*! + Constructs a TQScrollView called \a name with parent \a parent and + widget flags \a f. + + The widget flags \c WStaticContents, \c WNoAutoErase and \c + WPaintClever are propagated to the viewport() widget. The other + widget flags are propagated to the parent constructor as usual. +*/ + +TQScrollView::TQScrollView( TQWidget *parent, const char *name, WFlags f ) : + TQFrame( parent, name, f & (~WStaticContents) & (~WResizeNoErase) ) +{ + WFlags flags = WResizeNoErase | (f&WPaintClever) | (f&WRepaintNoErase) | (f&WStaticContents); + d = new TQScrollViewData( this, flags ); + +#ifndef TQT_NO_DRAGANDDROP + connect( &d->autoscroll_timer, TQ_SIGNAL( timeout() ), + this, TQ_SLOT( doDragAutoScroll() ) ); +#endif + + connect( d->hbar, TQ_SIGNAL( valueChanged(int) ), + this, TQ_SLOT( hslide(int) ) ); + connect( d->vbar, TQ_SIGNAL( valueChanged(int) ), + this, TQ_SLOT( vslide(int) ) ); + + connect( d->hbar, TQ_SIGNAL(sliderPressed()), this, TQ_SLOT(hbarIsPressed()) ); + connect( d->hbar, TQ_SIGNAL(sliderReleased()), this, TQ_SLOT(hbarIsReleased()) ); + connect( d->vbar, TQ_SIGNAL(sliderPressed()), this, TQ_SLOT(vbarIsPressed()) ); + connect( d->vbar, TQ_SIGNAL(sliderReleased()), this, TQ_SLOT(vbarIsReleased()) ); + + + d->viewport->installEventFilter( this ); + + connect( &d->scrollbar_timer, TQ_SIGNAL( timeout() ), + this, TQ_SLOT( updateScrollBars() ) ); + + setFrameStyle( TQFrame::StyledPanel | TQFrame::Sunken ); + setLineWidth( style().pixelMetric(TQStyle::PM_DefaultFrameWidth, this) ); + setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) ); +} + + +/*! + Destroys the TQScrollView. Any children added with addChild() will + be deleted. +*/ +TQScrollView::~TQScrollView() +{ + // Be careful not to get all those useless events... + if ( d->clipped_viewport ) + d->clipped_viewport->removeEventFilter( this ); + else + d->viewport->removeEventFilter( this ); + + // order is important + // ~TQWidget may cause a WM_ERASEBKGND on Windows + delete d->vbar; + d->vbar = 0; + delete d->hbar; + d->hbar = 0; + delete d->viewport; + d->viewport = 0; + delete d; + d = 0; +} + +/*! + \fn void TQScrollView::horizontalSliderPressed() + + This signal is emitted whenever the user presses the horizontal slider. +*/ +/*! + \fn void TQScrollView::horizontalSliderReleased() + + This signal is emitted whenever the user releases the horizontal slider. +*/ +/*! + \fn void TQScrollView::verticalSliderPressed() + + This signal is emitted whenever the user presses the vertical slider. +*/ +/*! + \fn void TQScrollView::verticalSliderReleased() + + This signal is emitted whenever the user releases the vertical slider. +*/ +void TQScrollView::hbarIsPressed() +{ + d->hbarPressed = TRUE; + emit( horizontalSliderPressed() ); +} + +void TQScrollView::hbarIsReleased() +{ + d->hbarPressed = FALSE; + emit( horizontalSliderReleased() ); +} + +/*! + Returns TRUE if horizontal slider is pressed by user; otherwise returns FALSE. +*/ +bool TQScrollView::isHorizontalSliderPressed() +{ + return d->hbarPressed; +} + +void TQScrollView::vbarIsPressed() +{ + d->vbarPressed = TRUE; + emit( verticalSliderPressed() ); +} + +void TQScrollView::vbarIsReleased() +{ + d->vbarPressed = FALSE; + emit( verticalSliderReleased() ); +} + +/*! + Returns TRUE if vertical slider is pressed by user; otherwise returns FALSE. +*/ +bool TQScrollView::isVerticalSliderPressed() +{ + return d->vbarPressed; +} + +/*! + \reimp +*/ +void TQScrollView::styleChange( TQStyle& old ) +{ + TQWidget::styleChange( old ); + updateScrollBars(); + d->cachedSizeHint = TQSize(); +} + +/*! + \reimp +*/ +void TQScrollView::fontChange( const TQFont &old ) +{ + TQWidget::fontChange( old ); + updateScrollBars(); + d->cachedSizeHint = TQSize(); +} + +void TQScrollView::hslide( int pos ) +{ + if ( !d->signal_choke ) { + moveContents( -pos, -d->contentsY() ); + TQApplication::syncX(); + } +} + +void TQScrollView::vslide( int pos ) +{ + if ( !d->signal_choke ) { + moveContents( -d->contentsX(), -pos ); + TQApplication::syncX(); + } +} + +/*! + Called when the horizontal scroll bar geometry changes. This is + provided as a protected function so that subclasses can do + interesting things such as providing extra buttons in some of the + space normally used by the scroll bars. + + The default implementation simply gives all the space to \a hbar. + The new geometry is given by \a x, \a y, \a w and \a h. + + \sa setVBarGeometry() +*/ +void TQScrollView::setHBarGeometry(TQScrollBar& hbar, + int x, int y, int w, int h) +{ + hbar.setGeometry( x, y, w, h ); +} + +/*! + Called when the vertical scroll bar geometry changes. This is + provided as a protected function so that subclasses can do + interesting things such as providing extra buttons in some of the + space normally used by the scroll bars. + + The default implementation simply gives all the space to \a vbar. + The new geometry is given by \a x, \a y, \a w and \a h. + + \sa setHBarGeometry() +*/ +void TQScrollView::setVBarGeometry( TQScrollBar& vbar, + int x, int y, int w, int h) +{ + vbar.setGeometry( x, y, w, h ); +} + + +/*! + Returns the viewport size for size (\a x, \a y). + + The viewport size depends on \a (x, y) (the size of the contents), + the size of this widget and the modes of the horizontal and + vertical scroll bars. + + This function permits widgets that can trade vertical and + horizontal space for each other to control scroll bar appearance + better. For example, a word processor or web browser can control + the width of the right margin accurately, whether or not there + needs to be a vertical scroll bar. +*/ + +TQSize TQScrollView::viewportSize( int x, int y ) const +{ + int fw = frameWidth(); + int lmarg = fw+d->l_marg; + int rmarg = fw+d->r_marg; + int tmarg = fw+d->t_marg; + int bmarg = fw+d->b_marg; + + int w = width(); + int h = height(); + + bool needh, needv; + bool showh, showv; + int hsbExt = horizontalScrollBar()->sizeHint().height(); + int vsbExt = verticalScrollBar()->sizeHint().width(); + + if ( d->policy != AutoOne || d->anyVisibleChildren() ) { + // Do we definitely need the scrollbar? + needh = w-lmarg-rmarg < x; + needv = h-tmarg-bmarg < y; + + // Do we intend to show the scrollbar? + if (d->hMode == AlwaysOn) + showh = TRUE; + else if (d->hMode == AlwaysOff) + showh = FALSE; + else + showh = needh; + + if (d->vMode == AlwaysOn) + showv = TRUE; + else if (d->vMode == AlwaysOff) + showv = FALSE; + else + showv = needv; + + // Given other scrollbar will be shown, NOW do we need one? + if ( showh && h-vsbExt-tmarg-bmarg < y ) { + if (d->vMode == Auto) + showv=TRUE; + } + if ( showv && w-hsbExt-lmarg-rmarg < x ) { + if (d->hMode == Auto) + showh=TRUE; + } + } else { + // Scrollbars not needed, only show scrollbar that are always on. + showh = d->hMode == AlwaysOn; + showv = d->vMode == AlwaysOn; + } + + return TQSize( w-lmarg-rmarg - (showv ? vsbExt : 0), + h-tmarg-bmarg - (showh ? hsbExt : 0) ); +} + + +/*! + Updates scroll bars: all possibilities are considered. You should + never need to call this in your code. +*/ +void TQScrollView::updateScrollBars() +{ + if(!horizontalScrollBar() && !verticalScrollBar()) + return; + + // I support this should use viewportSize()... but it needs + // so many of the temporary variables from viewportSize. hm. + int fw = frameWidth(); + int lmarg = fw+d->l_marg; + int rmarg = fw+d->r_marg; + int tmarg = fw+d->t_marg; + int bmarg = fw+d->b_marg; + + int w = width(); + int h = height(); + + int portw, porth; + + bool needh; + bool needv; + bool showh; + bool showv; + bool showc = FALSE; + + int hsbExt = horizontalScrollBar()->sizeHint().height(); + int vsbExt = verticalScrollBar()->sizeHint().width(); + + TQSize oldVisibleSize( visibleWidth(), visibleHeight() ); + + if ( d->policy != AutoOne || d->anyVisibleChildren() ) { + // Do we definitely need the scrollbar? + needh = w-lmarg-rmarg < d->contentsWidth(); + if ( d->inresize ) + needh = !horizontalScrollBar()->isHidden(); + needv = h-tmarg-bmarg < contentsHeight(); + + // Do we intend to show the scrollbar? + if (d->hMode == AlwaysOn) + showh = TRUE; + else if (d->hMode == AlwaysOff) + showh = FALSE; + else + showh = needh; + + if (d->vMode == AlwaysOn) + showv = TRUE; + else if (d->vMode == AlwaysOff) + showv = FALSE; + else + showv = needv; + +#ifdef TQ_WS_MAC + bool mac_need_scroll = FALSE; + if(!parentWidget()) { + mac_need_scroll = TRUE; + } else { + TQWidget *tlw = topLevelWidget(); + TQPoint tlw_br = TQPoint(tlw->width(), tlw->height()), + my_br = posInWindow(this) + TQPoint(w, h); + if(my_br.x() >= tlw_br.x() - 3 && my_br.y() >= tlw_br.y() - 3) + mac_need_scroll = TRUE; + } + if(mac_need_scroll) { + WindowAttributes attr; + GetWindowAttributes((WindowPtr)handle(), &attr); + mac_need_scroll = (attr & kWindowResizableAttribute); + } + if(mac_need_scroll) { + showc = TRUE; + if(d->vMode == Auto) + showv = TRUE; + if(d->hMode == Auto) + showh = TRUE; + } +#endif + + // Given other scrollbar will be shown, NOW do we need one? + if ( showh && h-vsbExt-tmarg-bmarg < contentsHeight() ) { + needv=TRUE; + if (d->vMode == Auto) + showv=TRUE; + } + if ( showv && !d->inresize && w-hsbExt-lmarg-rmarg < d->contentsWidth() ) { + needh=TRUE; + if (d->hMode == Auto) + showh=TRUE; + } + } else { + // Scrollbars not needed, only show scrollbar that are always on. + needh = needv = FALSE; + showh = d->hMode == AlwaysOn; + showv = d->vMode == AlwaysOn; + } + + bool sc = d->signal_choke; + d->signal_choke=TRUE; + + // Hide unneeded scrollbar, calculate viewport size + if ( showh ) { + porth=h-hsbExt-tmarg-bmarg; + } else { + if (!needh) + d->hbar->setValue(0); + d->hbar->hide(); + porth=h-tmarg-bmarg; + } + if ( showv ) { + portw=w-vsbExt-lmarg-rmarg; + } else { + if (!needv) + d->vbar->setValue(0); + d->vbar->hide(); + portw=w-lmarg-rmarg; + } + + // Configure scrollbars that we will show + if ( needv ) { + d->vbar->setRange( 0, contentsHeight()-porth ); + d->vbar->setSteps( TQScrollView::d->vbar->lineStep(), porth ); + } else { + d->vbar->setRange( 0, 0 ); + } + if ( needh ) { + d->hbar->setRange( 0, TQMAX(0, d->contentsWidth()-portw) ); + d->hbar->setSteps( TQScrollView::d->hbar->lineStep(), portw ); + } else { + d->hbar->setRange( 0, 0 ); + } + + // Position the scrollbars, viewport and corner widget. + int bottom; + bool reverse = TQApplication::reverseLayout(); + int xoffset = ( reverse && (showv || cornerWidget() )) ? vsbExt : 0; + int xpos = reverse ? 0 : w - vsbExt; + bool frameContentsOnly = + style().styleHint(TQStyle::SH_ScrollView_FrameOnlyAroundContents); + + if( ! frameContentsOnly ) { + if ( reverse ) + xpos += fw; + else + xpos -= fw; + } + if ( showh ) { + int right = ( showc || showv || cornerWidget() ) ? w-vsbExt : w; + if ( ! frameContentsOnly ) + setHBarGeometry( *d->hbar, fw + xoffset, h-hsbExt-fw, + right-fw-fw, hsbExt ); + else + setHBarGeometry( *d->hbar, 0 + xoffset, h-hsbExt, right, + hsbExt ); + bottom=h-hsbExt; + } else { + bottom=h; + } + if ( showv ) { + clipper()->setGeometry( lmarg + xoffset, tmarg, + w-vsbExt-lmarg-rmarg, + bottom-tmarg-bmarg ); + d->viewportResized( w-vsbExt-lmarg-rmarg, bottom-tmarg-bmarg ); + if ( ! frameContentsOnly ) + changeFrameRect(TQRect(0, 0, w, h) ); + else + changeFrameRect(TQRect(xoffset, 0, w-vsbExt, bottom)); + if (showc || cornerWidget()) { + if ( ! frameContentsOnly ) + setVBarGeometry( *d->vbar, xpos, + fw, vsbExt, + h-hsbExt-fw-fw ); + else + setVBarGeometry( *d->vbar, xpos, 0, + vsbExt, + h-hsbExt ); + } + else { + if ( ! frameContentsOnly ) + setVBarGeometry( *d->vbar, xpos, + fw, vsbExt, + bottom-fw-fw ); + else + setVBarGeometry( *d->vbar, xpos, 0, + vsbExt, bottom ); + } + } else { + if ( ! frameContentsOnly ) + changeFrameRect(TQRect(0, 0, w, h)); + else + changeFrameRect(TQRect(0, 0, w, bottom)); + clipper()->setGeometry( lmarg, tmarg, + w-lmarg-rmarg, bottom-tmarg-bmarg ); + d->viewportResized( w-lmarg-rmarg, bottom-tmarg-bmarg ); + } + + TQWidget *corner = d->corner; + if ( !d->corner ) + corner = d->defaultCorner; + if ( ! frameContentsOnly ) + corner->setGeometry( xpos, + h-hsbExt-fw, + vsbExt, + hsbExt ); + else + corner->setGeometry( xpos, + h-hsbExt, + vsbExt, + hsbExt ); + + d->signal_choke=sc; + + if ( d->contentsX()+visibleWidth() > d->contentsWidth() ) { + int x; +#if 0 + if ( reverse ) + x =TQMIN(0,d->contentsWidth()-visibleWidth()); + else +#endif + x =TQMAX(0,d->contentsWidth()-visibleWidth()); + d->hbar->setValue(x); + // Do it even if it is recursive + moveContents( -x, -d->contentsY() ); + } + if ( d->contentsY()+visibleHeight() > contentsHeight() ) { + int y=TQMAX(0,contentsHeight()-visibleHeight()); + d->vbar->setValue(y); + // Do it even if it is recursive + moveContents( -d->contentsX(), -y ); + } + + // Finally, show the scroll bars + if ( showh && ( d->hbar->isHidden() || !d->hbar->isVisible() ) ) + d->hbar->show(); + if ( showv && ( d->vbar->isHidden() || !d->vbar->isVisible() ) ) + d->vbar->show(); + + d->signal_choke=TRUE; + d->vbar->setValue( d->contentsY() ); + d->hbar->setValue( d->contentsX() ); + d->signal_choke=FALSE; + + TQSize newVisibleSize( visibleWidth(), visibleHeight() ); + if ( d->clipped_viewport && oldVisibleSize != newVisibleSize ) { + TQResizeEvent e( newVisibleSize, oldVisibleSize ); + viewportResizeEvent( &e ); + } +} + + +/*! + \reimp +*/ +void TQScrollView::show() +{ + if ( isVisible() ) + return; + TQWidget::show(); + updateScrollBars(); + d->hideOrShowAll(this); +} + +/*! + \reimp + */ +void TQScrollView::resize( int w, int h ) +{ + TQWidget::resize( w, h ); +} + +/*! + \reimp +*/ +void TQScrollView::resize( const TQSize& s ) +{ + resize( s.width(), s.height() ); +} + +/*! + \reimp +*/ +void TQScrollView::resizeEvent( TQResizeEvent* event ) +{ + TQFrame::resizeEvent( event ); + +#if 0 + if ( TQApplication::reverseLayout() ) { + d->fake_scroll = TRUE; + scrollBy( -event->size().width() + event->oldSize().width(), 0 ); + d->fake_scroll = FALSE; + } +#endif + + bool inresize = d->inresize; + d->inresize = TRUE; + updateScrollBars(); + d->inresize = inresize; + d->scrollbar_timer.start( 0, TRUE ); + + d->hideOrShowAll(this); +} + + + +/*! + \reimp +*/ +void TQScrollView::mousePressEvent( TQMouseEvent * e) //#### remove for 4.0 +{ + e->ignore(); +} + +/*! + \reimp +*/ +void TQScrollView::mouseReleaseEvent( TQMouseEvent *e ) //#### remove for 4.0 +{ + e->ignore(); +} + + +/*! + \reimp +*/ +void TQScrollView::mouseDoubleClickEvent( TQMouseEvent *e ) //#### remove for 4.0 +{ + e->ignore(); +} + +/*! + \reimp +*/ +void TQScrollView::mouseMoveEvent( TQMouseEvent *e ) //#### remove for 4.0 +{ + e->ignore(); +} + +/*! + \reimp +*/ +#ifndef TQT_NO_WHEELEVENT +void TQScrollView::wheelEvent( TQWheelEvent *e ) +{ + TQWheelEvent ce( viewport()->mapFromGlobal( e->globalPos() ), + e->globalPos(), e->delta(), e->state(), e->orientation()); + viewportWheelEvent(&ce); + if ( !ce.isAccepted() ) { + if ( e->orientation() == Horizontal && horizontalScrollBar() && horizontalScrollBar()->isEnabled() ) + TQApplication::sendEvent( horizontalScrollBar(), e); + else if (e->orientation() == Vertical && verticalScrollBar() && verticalScrollBar()->isEnabled() ) + TQApplication::sendEvent( verticalScrollBar(), e); + } else { + e->accept(); + } +} +#endif + +/*! + \reimp +*/ +void TQScrollView::contextMenuEvent( TQContextMenuEvent *e ) +{ + if ( e->reason() != TQContextMenuEvent::Keyboard ) { + e->ignore(); + return; + } + + TQContextMenuEvent ce( e->reason(), viewport()->mapFromGlobal( e->globalPos() ), + e->globalPos(), e->state() ); + viewportContextMenuEvent( &ce ); + if ( ce.isAccepted() ) + e->accept(); + else + e->ignore(); +} + +TQScrollView::ScrollBarMode TQScrollView::vScrollBarMode() const +{ + return d->vMode; +} + + +/*! + \enum TQScrollView::ScrollBarMode + + This enum type describes the various modes of TQScrollView's scroll + bars. + + \value Auto TQScrollView shows a scroll bar when the content is + too large to fit and not otherwise. This is the default. + + \value AlwaysOff TQScrollView never shows a scroll bar. + + \value AlwaysOn TQScrollView always shows a scroll bar. + + (The modes for the horizontal and vertical scroll bars are + independent.) +*/ + + +/*! + \property TQScrollView::vScrollBarMode + \brief the mode for the vertical scroll bar + + The default mode is \c TQScrollView::Auto. + + \sa hScrollBarMode +*/ +void TQScrollView::setVScrollBarMode( ScrollBarMode mode ) +{ + if (d->vMode != mode) { + d->vMode = mode; + updateScrollBars(); + } +} + + +/*! + \property TQScrollView::hScrollBarMode + \brief the mode for the horizontal scroll bar + + The default mode is \c TQScrollView::Auto. + + \sa vScrollBarMode +*/ +TQScrollView::ScrollBarMode TQScrollView::hScrollBarMode() const +{ + return d->hMode; +} + +void TQScrollView::setHScrollBarMode( ScrollBarMode mode ) +{ + if (d->hMode != mode) { + d->hMode = mode; + updateScrollBars(); + } +} + + +/*! + Returns the widget in the corner between the two scroll bars. + + By default, no corner widget is present. +*/ +TQWidget* TQScrollView::cornerWidget() const +{ + return d->corner; +} + +/*! + Sets the widget in the \a corner between the two scroll bars. + + You will probably also want to set at least one of the scroll bar + modes to \c AlwaysOn. + + Passing 0 shows no widget in the corner. + + Any previous \a corner widget is hidden. + + You may call setCornerWidget() with the same widget at different + times. + + All widgets set here will be deleted by the TQScrollView when it is + destroyed unless you separately reparent the widget after setting + some other corner widget (or 0). + + Any \e newly set widget should have no current parent. + + By default, no corner widget is present. + + \sa setVScrollBarMode(), setHScrollBarMode() +*/ +void TQScrollView::setCornerWidget(TQWidget* corner) +{ + TQWidget* oldcorner = d->corner; + if (oldcorner != corner) { + if (oldcorner) oldcorner->hide(); + d->corner = corner; + + if ( corner && corner->parentWidget() != this ) { + // #### No clean way to get current WFlags + corner->reparent( this, (((TQScrollView*)corner))->getWFlags(), + TQPoint(0,0), FALSE ); + } + + updateScrollBars(); + if ( corner ) corner->show(); + } +} + + +void TQScrollView::setResizePolicy( ResizePolicy r ) +{ + d->policy = r; +} + +/*! + \property TQScrollView::resizePolicy + \brief the resize policy + + The default is \c Default. + + \sa ResizePolicy +*/ +TQScrollView::ResizePolicy TQScrollView::resizePolicy() const +{ + return d->policy; +} + +/*! + \reimp +*/ +void TQScrollView::setEnabled( bool enable ) +{ + TQFrame::setEnabled( enable ); +} + +/*! + Removes the \a child widget from the scrolled area. Note that this + happens automatically if the \a child is deleted. +*/ +void TQScrollView::removeChild(TQWidget* child) +{ + if ( !d || !child ) // First check in case we are destructing + return; + + TQSVChildRec *r = d->rec(child); + if ( r ) d->deleteChildRec( r ); +} + +/*! + \reimp +*/ +void TQScrollView::removeChild(TQObject* child) +{ + TQFrame::removeChild(child); +} + +/*! + Inserts the widget, \a child, into the scrolled area positioned at + (\a x, \a y). The position defaults to (0, 0). If the child is + already in the view, it is just moved. + + You may want to call enableClipper(TRUE) if you add a large number + of widgets. +*/ +void TQScrollView::addChild(TQWidget* child, int x, int y) +{ + if ( !child ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQScrollView::addChild(): Cannot add null child" ); +#endif + return; + } + child->polish(); + child->setBackgroundOrigin(WidgetOrigin); + + if ( child->parentWidget() == viewport() ) { + // May already be there + TQSVChildRec *r = d->rec(child); + if (r) { + r->moveTo(this,x,y,d->clipped_viewport); + if ( d->policy > Manual ) { + d->autoResizeHint(this); + d->autoResize(this); // #### better to just deal with this one widget! + } + return; + } + } + + if ( d->children.isEmpty() && d->policy != Manual ) { + if ( d->policy == Default ) + setResizePolicy( AutoOne ); + child->installEventFilter( this ); + } else if ( d->policy == AutoOne ) { + child->removeEventFilter( this ); //#### ????? + setResizePolicy( Manual ); + } + if ( child->parentWidget() != viewport() ) { + child->reparent( viewport(), 0, TQPoint(0,0), FALSE ); + } + d->addChildRec(child,x,y)->hideOrShow(this, d->clipped_viewport); + + if ( d->policy > Manual ) { + d->autoResizeHint(this); + d->autoResize(this); // #### better to just deal with this one widget! + } +} + +/*! + Repositions the \a child widget to (\a x, \a y). This function is + the same as addChild(). +*/ +void TQScrollView::moveChild(TQWidget* child, int x, int y) +{ + addChild(child,x,y); +} + +/*! + Returns the X position of the given \a child widget. Use this + rather than TQWidget::x() for widgets added to the view. + + This function returns 0 if \a child has not been added to the view. +*/ +int TQScrollView::childX(TQWidget* child) +{ + TQSVChildRec *r = d->rec(child); + return r ? r->x : 0; +} + +/*! + Returns the Y position of the given \a child widget. Use this + rather than TQWidget::y() for widgets added to the view. + + This function returns 0 if \a child has not been added to the view. +*/ +int TQScrollView::childY(TQWidget* child) +{ + TQSVChildRec *r = d->rec(child); + return r ? r->y : 0; +} + +/*! \fn bool TQScrollView::childIsVisible(TQWidget*) + \obsolete + + Returns TRUE if \a child is visible. This is equivalent + to child->isVisible(). +*/ + +/*! \fn void TQScrollView::showChild(TQWidget* child, bool y) + \obsolete + + Sets the visibility of \a child. Equivalent to + TQWidget::show() or TQWidget::hide(). +*/ + +/*! + This event filter ensures the scroll bars are updated when a + single contents widget is resized, shown, hidden or destroyed; it + passes mouse events to the TQScrollView. The event is in \a e and + the object is in \a obj. +*/ + +bool TQScrollView::eventFilter( TQObject *obj, TQEvent *e ) +{ + if ( !d ) + return FALSE; // we are destructing + if ( obj == d->viewport || obj == d->clipped_viewport ) { + switch ( e->type() ) { + /* Forward many events to viewport...() functions */ + case TQEvent::Paint: + viewportPaintEvent( (TQPaintEvent*)e ); + break; + case TQEvent::Resize: + if ( !d->clipped_viewport ) + viewportResizeEvent( (TQResizeEvent *)e ); + break; + case TQEvent::MouseButtonPress: + viewportMousePressEvent( (TQMouseEvent*)e ); + if ( ((TQMouseEvent*)e)->isAccepted() ) + return TRUE; + break; + case TQEvent::MouseButtonRelease: + viewportMouseReleaseEvent( (TQMouseEvent*)e ); + if ( ((TQMouseEvent*)e)->isAccepted() ) + return TRUE; + break; + case TQEvent::MouseButtonDblClick: + viewportMouseDoubleClickEvent( (TQMouseEvent*)e ); + if ( ((TQMouseEvent*)e)->isAccepted() ) + return TRUE; + break; + case TQEvent::MouseMove: + viewportMouseMoveEvent( (TQMouseEvent*)e ); + if ( ((TQMouseEvent*)e)->isAccepted() ) + return TRUE; + break; +#ifndef TQT_NO_DRAGANDDROP + case TQEvent::DragEnter: + viewportDragEnterEvent( (TQDragEnterEvent*)e ); + break; + case TQEvent::DragMove: { + if ( d->drag_autoscroll ) { + TQPoint vp = ((TQDragMoveEvent*) e)->pos(); + TQRect inside_margin( autoscroll_margin, autoscroll_margin, + visibleWidth() - autoscroll_margin * 2, + visibleHeight() - autoscroll_margin * 2 ); + if ( !inside_margin.contains( vp ) ) { + startDragAutoScroll(); + // Keep sending move events + ( (TQDragMoveEvent*)e )->accept( TQRect(0,0,0,0) ); + } + } + viewportDragMoveEvent( (TQDragMoveEvent*)e ); + } break; + case TQEvent::DragLeave: + stopDragAutoScroll(); + viewportDragLeaveEvent( (TQDragLeaveEvent*)e ); + break; + case TQEvent::Drop: + stopDragAutoScroll(); + viewportDropEvent( (TQDropEvent*)e ); + break; +#endif // TQT_NO_DRAGANDDROP + case TQEvent::ContextMenu: + viewportContextMenuEvent( (TQContextMenuEvent*)e ); + if ( ((TQContextMenuEvent*)e)->isAccepted() ) + return TRUE; + break; + case TQEvent::ChildRemoved: + removeChild((TQWidget*)((TQChildEvent*)e)->child()); + break; + case TQEvent::LayoutHint: + d->autoResizeHint(this); + break; + case TQEvent::WindowActivate: + case TQEvent::WindowDeactivate: + return TRUE; + default: + break; + } + } else if ( d && d->rec((TQWidget*)obj) ) { // must be a child + if ( e->type() == TQEvent::Resize ) + d->autoResize(this); + else if ( e->type() == TQEvent::Move ) + d->autoMove(this); + } + return TQFrame::eventFilter( obj, e ); // always continue with standard event processing +} + +/*! + This event handler is called whenever the TQScrollView receives a + mousePressEvent(): the press position in \a e is translated to be a point + on the contents. +*/ +void TQScrollView::contentsMousePressEvent( TQMouseEvent* e ) +{ + e->ignore(); +} + +/*! + This event handler is called whenever the TQScrollView receives a + mouseReleaseEvent(): the release position in \a e is translated to be a + point on the contents. +*/ +void TQScrollView::contentsMouseReleaseEvent( TQMouseEvent* e ) +{ + e->ignore(); +} + +/*! + This event handler is called whenever the TQScrollView receives a + mouseDoubleClickEvent(): the click position in \a e is translated to be a + point on the contents. + + The default implementation generates a normal mouse press event. +*/ +void TQScrollView::contentsMouseDoubleClickEvent( TQMouseEvent* e ) +{ + contentsMousePressEvent(e); // try mouse press event +} + +/*! + This event handler is called whenever the TQScrollView receives a + mouseMoveEvent(): the mouse position in \a e is translated to be a point + on the contents. +*/ +void TQScrollView::contentsMouseMoveEvent( TQMouseEvent* e ) +{ + e->ignore(); +} + +#ifndef TQT_NO_DRAGANDDROP + +/*! + This event handler is called whenever the TQScrollView receives a + dragEnterEvent(): the drag position is translated to be a point + on the contents. +*/ +void TQScrollView::contentsDragEnterEvent( TQDragEnterEvent * ) +{ +} + +/*! + This event handler is called whenever the TQScrollView receives a + dragMoveEvent(): the drag position is translated to be a point on + the contents. +*/ +void TQScrollView::contentsDragMoveEvent( TQDragMoveEvent * ) +{ +} + +/*! + This event handler is called whenever the TQScrollView receives a + dragLeaveEvent(): the drag position is translated to be a point + on the contents. +*/ +void TQScrollView::contentsDragLeaveEvent( TQDragLeaveEvent * ) +{ +} + +/*! + This event handler is called whenever the TQScrollView receives a + dropEvent(): the drop position is translated to be a point on the + contents. +*/ +void TQScrollView::contentsDropEvent( TQDropEvent * ) +{ +} + +#endif // TQT_NO_DRAGANDDROP + +/*! + This event handler is called whenever the TQScrollView receives a + wheelEvent() in \a{e}: the mouse position is translated to be a + point on the contents. +*/ +#ifndef TQT_NO_WHEELEVENT +void TQScrollView::contentsWheelEvent( TQWheelEvent * e ) +{ + e->ignore(); +} +#endif +/*! + This event handler is called whenever the TQScrollView receives a + contextMenuEvent() in \a{e}: the mouse position is translated to + be a point on the contents. +*/ +void TQScrollView::contentsContextMenuEvent( TQContextMenuEvent *e ) +{ + e->ignore(); +} + +/*! + This is a low-level painting routine that draws the viewport + contents. Reimplement this if drawContents() is too high-level + (for example, if you don't want to open a TQPainter on the + viewport). The paint event is passed in \a pe. +*/ +void TQScrollView::viewportPaintEvent( TQPaintEvent* pe ) +{ + TQWidget* vp = viewport(); + + TQPainter p(vp); + TQRect r = pe->rect(); + + if ( d->clipped_viewport ) { + TQRect rr( + -d->clipped_viewport->x(), -d->clipped_viewport->y(), + d->viewport->width(), d->viewport->height() + ); + r &= rr; + if ( r.isValid() ) { + int ex = r.x() + d->clipped_viewport->x() + d->contentsX(); + int ey = r.y() + d->clipped_viewport->y() + d->contentsY(); + int ew = r.width(); + int eh = r.height(); + drawContentsOffset(&p, + d->contentsX()+d->clipped_viewport->x(), + d->contentsY()+d->clipped_viewport->y(), + ex, ey, ew, eh); + } + } else { + r &= d->viewport->rect(); + int ex = r.x() + d->contentsX(); + int ey = r.y() + d->contentsY(); + int ew = r.width(); + int eh = r.height(); + drawContentsOffset(&p, d->contentsX(), d->contentsY(), ex, ey, ew, eh); + } +} + + +/*! + To provide simple processing of events on the contents, this + function receives all resize events sent to the viewport. + + \sa TQWidget::resizeEvent() +*/ +void TQScrollView::viewportResizeEvent( TQResizeEvent* ) +{ +} + +/*! \internal + + To provide simple processing of events on the contents, this + function receives all mouse press events sent to the viewport, + translates the event and calls contentsMousePressEvent(). + + \sa contentsMousePressEvent(), TQWidget::mousePressEvent() +*/ +void TQScrollView::viewportMousePressEvent( TQMouseEvent* e ) +{ + TQMouseEvent ce(e->type(), viewportToContents(e->pos()), + e->globalPos(), e->button(), e->state()); + contentsMousePressEvent(&ce); + if ( !ce.isAccepted() ) + e->ignore(); +} + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all mouse release events sent to the viewport, translates + the event and calls contentsMouseReleaseEvent(). + + \sa TQWidget::mouseReleaseEvent() +*/ +void TQScrollView::viewportMouseReleaseEvent( TQMouseEvent* e ) +{ + TQMouseEvent ce(e->type(), viewportToContents(e->pos()), + e->globalPos(), e->button(), e->state()); + contentsMouseReleaseEvent(&ce); + if ( !ce.isAccepted() ) + e->ignore(); +} + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all mouse double click events sent to the viewport, + translates the event and calls contentsMouseDoubleClickEvent(). + + \sa TQWidget::mouseDoubleClickEvent() +*/ +void TQScrollView::viewportMouseDoubleClickEvent( TQMouseEvent* e ) +{ + TQMouseEvent ce(e->type(), viewportToContents(e->pos()), + e->globalPos(), e->button(), e->state()); + contentsMouseDoubleClickEvent(&ce); + if ( !ce.isAccepted() ) + e->ignore(); +} + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all mouse move events sent to the viewport, translates the + event and calls contentsMouseMoveEvent(). + + \sa TQWidget::mouseMoveEvent() +*/ +void TQScrollView::viewportMouseMoveEvent( TQMouseEvent* e ) +{ + TQMouseEvent ce(e->type(), viewportToContents(e->pos()), + e->globalPos(), e->button(), e->state()); + contentsMouseMoveEvent(&ce); + if ( !ce.isAccepted() ) + e->ignore(); +} + +#ifndef TQT_NO_DRAGANDDROP + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all drag enter events sent to the viewport, translates the + event and calls contentsDragEnterEvent(). + + \sa TQWidget::dragEnterEvent() +*/ +void TQScrollView::viewportDragEnterEvent( TQDragEnterEvent* e ) +{ + e->setPoint(viewportToContents(e->pos())); + contentsDragEnterEvent(e); + e->setPoint(contentsToViewport(e->pos())); +} + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all drag move events sent to the viewport, translates the + event and calls contentsDragMoveEvent(). + + \sa TQWidget::dragMoveEvent() +*/ +void TQScrollView::viewportDragMoveEvent( TQDragMoveEvent* e ) +{ + e->setPoint(viewportToContents(e->pos())); + contentsDragMoveEvent(e); + e->setPoint(contentsToViewport(e->pos())); +} + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all drag leave events sent to the viewport and calls + contentsDragLeaveEvent(). + + \sa TQWidget::dragLeaveEvent() +*/ +void TQScrollView::viewportDragLeaveEvent( TQDragLeaveEvent* e ) +{ + contentsDragLeaveEvent(e); +} + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all drop events sent to the viewport, translates the event + and calls contentsDropEvent(). + + \sa TQWidget::dropEvent() +*/ +void TQScrollView::viewportDropEvent( TQDropEvent* e ) +{ + e->setPoint(viewportToContents(e->pos())); + contentsDropEvent(e); + e->setPoint(contentsToViewport(e->pos())); +} + +#endif // TQT_NO_DRAGANDDROP + +/*!\internal + + To provide simple processing of events on the contents, this function + receives all wheel events sent to the viewport, translates the + event and calls contentsWheelEvent(). + + \sa TQWidget::wheelEvent() +*/ +#ifndef TQT_NO_WHEELEVENT +void TQScrollView::viewportWheelEvent( TQWheelEvent* e ) +{ + /* + Different than standard mouse events, because wheel events might + be sent to the focus widget if the widget-under-mouse doesn't want + the event itself. + */ + TQWheelEvent ce( viewportToContents(e->pos()), + e->globalPos(), e->delta(), e->state(), e->orientation()); + contentsWheelEvent(&ce); + if ( ce.isAccepted() ) + e->accept(); + else + e->ignore(); +} +#endif + +/*! \internal + + To provide simple processing of events on the contents, this function + receives all context menu events sent to the viewport, translates the + event and calls contentsContextMenuEvent(). +*/ +void TQScrollView::viewportContextMenuEvent( TQContextMenuEvent *e ) +{ + TQContextMenuEvent ce(e->reason(), viewportToContents(e->pos()), e->globalPos(), e->state() ); + contentsContextMenuEvent( &ce ); + if ( ce.isAccepted() ) + e->accept(); + else + e->ignore(); +} + +/*! + Returns the component horizontal scroll bar. It is made available + to allow accelerators, autoscrolling, etc. + + It should not be used for other purposes. + + This function never returns 0. +*/ +TQScrollBar* TQScrollView::horizontalScrollBar() const +{ + return d->hbar; +} + +/*! + Returns the component vertical scroll bar. It is made available to + allow accelerators, autoscrolling, etc. + + It should not be used for other purposes. + + This function never returns 0. +*/ +TQScrollBar* TQScrollView::verticalScrollBar() const { + return d->vbar; +} + + +/*! + Scrolls the content so that the point \a (x, y) is visible with at + least 50-pixel margins (if possible, otherwise centered). +*/ +void TQScrollView::ensureVisible( int x, int y ) +{ + ensureVisible(x, y, 50, 50); +} + +/*! + \overload + + Scrolls the content so that the point \a (x, y) is visible with at + least the \a xmargin and \a ymargin margins (if possible, + otherwise centered). +*/ +void TQScrollView::ensureVisible( int x, int y, int xmargin, int ymargin ) +{ + int pw=visibleWidth(); + int ph=visibleHeight(); + + int cx=-d->contentsX(); + int cy=-d->contentsY(); + int cw=d->contentsWidth(); + int ch=contentsHeight(); + + if ( pw < xmargin*2 ) + xmargin=pw/2; + if ( ph < ymargin*2 ) + ymargin=ph/2; + + if ( cw <= pw ) { + xmargin=0; + cx=0; + } + if ( ch <= ph ) { + ymargin=0; + cy=0; + } + + if ( x < -cx+xmargin ) + cx = -x+xmargin; + else if ( x >= -cx+pw-xmargin ) + cx = -x+pw-xmargin; + + if ( y < -cy+ymargin ) + cy = -y+ymargin; + else if ( y >= -cy+ph-ymargin ) + cy = -y+ph-ymargin; + + if ( cx > 0 ) + cx=0; + else if ( cx < pw-cw && cw>pw ) + cx=pw-cw; + + if ( cy > 0 ) + cy=0; + else if ( cy < ph-ch && ch>ph ) + cy=ph-ch; + + setContentsPos( -cx, -cy ); +} + +/*! + Scrolls the content so that the point \a (x, y) is in the top-left + corner. +*/ +void TQScrollView::setContentsPos( int x, int y ) +{ +#if 0 + // bounds checking... + if ( TQApplication::reverseLayout() ) + if ( x > d->contentsWidth() - visibleWidth() ) x = d->contentsWidth() - visibleWidth(); + else +#endif + if ( x < 0 ) x = 0; + if ( y < 0 ) y = 0; + // Choke signal handling while we update BOTH sliders. + d->signal_choke=TRUE; + moveContents( -x, -y ); + d->vbar->setValue( y ); + d->hbar->setValue( x ); + d->signal_choke=FALSE; +} + +/*! + Scrolls the content by \a dx to the left and \a dy upwards. +*/ +void TQScrollView::scrollBy( int dx, int dy ) +{ + setContentsPos( TQMAX( d->contentsX()+dx, 0 ), TQMAX( d->contentsY()+dy, 0 ) ); +} + +/*! + Scrolls the content so that the point \a (x, y) is in the center + of visible area. +*/ +void TQScrollView::center( int x, int y ) +{ + ensureVisible( x, y, 32000, 32000 ); +} + +/*! + \overload + + Scrolls the content so that the point \a (x, y) is visible with + the \a xmargin and \a ymargin margins (as fractions of visible + the area). + + For example: + \list + \i Margin 0.0 allows (x, y) to be on the edge of the visible area. + \i Margin 0.5 ensures that (x, y) is in middle 50% of the visible area. + \i Margin 1.0 ensures that (x, y) is in the center of the the visible area. + \endlist +*/ +void TQScrollView::center( int x, int y, float xmargin, float ymargin ) +{ + int pw=visibleWidth(); + int ph=visibleHeight(); + ensureVisible( x, y, int( xmargin/2.0*pw+0.5 ), int( ymargin/2.0*ph+0.5 ) ); +} + + +/*! + \fn void TQScrollView::contentsMoving(int x, int y) + + This signal is emitted just before the contents are moved to + position \a (x, y). + + \sa contentsX(), contentsY() +*/ + +/*! + Moves the contents by \a (x, y). +*/ +void TQScrollView::moveContents(int x, int y) +{ + if ( -x+visibleWidth() > d->contentsWidth() ) +#if 0 + if( TQApplication::reverseLayout() ) + x=TQMAX(0,-d->contentsWidth()+visibleWidth()); + else +#endif + x=TQMIN(0,-d->contentsWidth()+visibleWidth()); + if ( -y+visibleHeight() > contentsHeight() ) + y=TQMIN(0,-contentsHeight()+visibleHeight()); + + int dx = x - d->vx; + int dy = y - d->vy; + + if (!dx && !dy) + return; // Nothing to do + + emit contentsMoving( -x, -y ); + + d->vx = x; + d->vy = y; + + if ( d->clipped_viewport || d->static_bg ) { + // Cheap move (usually) + d->moveAllBy(dx,dy); + } else if ( /*dx && dy ||*/ + ( TQABS(dy) * 5 > visibleHeight() * 4 ) || + ( TQABS(dx) * 5 > visibleWidth() * 4 ) + ) + { + // Big move + if ( viewport()->isUpdatesEnabled() ) + viewport()->update(); + d->moveAllBy(dx,dy); + } else if ( !d->fake_scroll || d->contentsWidth() > visibleWidth() ) { + // Small move + clipper()->scroll(dx,dy); + } + d->hideOrShowAll(this, TRUE ); +} + +/*! + \property TQScrollView::contentsX + \brief the X coordinate of the contents that are at the left edge of + the viewport. +*/ +int TQScrollView::contentsX() const +{ + return d->contentsX(); +} + +/*! + \property TQScrollView::contentsY + \brief the Y coordinate of the contents that are at the top edge of + the viewport. +*/ +int TQScrollView::contentsY() const +{ + return d->contentsY(); +} + +/*! + \property TQScrollView::contentsWidth + \brief the width of the contents area +*/ +int TQScrollView::contentsWidth() const +{ + return d->contentsWidth(); +} + +/*! + \property TQScrollView::contentsHeight + \brief the height of the contents area +*/ +int TQScrollView::contentsHeight() const +{ + return d->vheight; +} + +/*! + Sets the size of the contents area to \a w pixels wide and \a h + pixels high and updates the viewport accordingly. +*/ +void TQScrollView::resizeContents( int w, int h ) +{ + int ow = d->vwidth; + int oh = d->vheight; + d->vwidth = w; + d->vheight = h; + + d->scrollbar_timer.start( 0, TRUE ); + + if ( d->children.isEmpty() && d->policy == Default ) + setResizePolicy( Manual ); + + if ( ow > w ) { + // Swap + int t=w; + w=ow; + ow=t; + } + // Refresh area ow..w + if ( ow < visibleWidth() && w >= 0 ) { + if ( ow < 0 ) + ow = 0; + if ( w > visibleWidth() ) + w = visibleWidth(); + clipper()->update( d->contentsX()+ow, 0, w-ow, visibleHeight() ); + } + + if ( oh > h ) { + // Swap + int t=h; + h=oh; + oh=t; + } + // Refresh area oh..h + if ( oh < visibleHeight() && h >= 0 ) { + if ( oh < 0 ) + oh = 0; + if ( h > visibleHeight() ) + h = visibleHeight(); + clipper()->update( 0, d->contentsY()+oh, visibleWidth(), h-oh); + } +} + +/*! + Calls update() on a rectangle defined by \a x, \a y, \a w, \a h, + translated appropriately. If the rectangle is not visible, nothing + is repainted. + + \sa repaintContents() +*/ +void TQScrollView::updateContents( int x, int y, int w, int h ) +{ + if ( testWState(WState_Visible|WState_BlockUpdates) != WState_Visible ) + return; + + TQWidget* vp = viewport(); + + // Translate + x -= d->contentsX(); + y -= d->contentsY(); + + // Clip to TQCOORD space + if ( x < 0 ) { + w += x; + x = 0; + } + if ( y < 0 ) { + h += y; + y = 0; + } + + if ( w < 0 || h < 0 ) + return; + if ( x > visibleWidth() || y > visibleHeight() ) + return; + + if ( w > visibleWidth() ) + w = visibleWidth(); + if ( h > visibleHeight() ) + h = visibleHeight(); + + if ( d->clipped_viewport ) { + // Translate clipper() to viewport() + x -= d->clipped_viewport->x(); + y -= d->clipped_viewport->y(); + } + + vp->update( x, y, w, h ); +} + +/*! + \overload + + Updates the contents in rectangle \a r +*/ +void TQScrollView::updateContents( const TQRect& r ) +{ + updateContents(r.x(), r.y(), r.width(), r.height()); +} + +/*! + \overload +*/ +void TQScrollView::updateContents() +{ + updateContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight() ); +} + +/*! + \overload + + Repaints the contents of rectangle \a r. If \a erase is TRUE the + background is cleared using the background color. +*/ +void TQScrollView::repaintContents( const TQRect& r, bool erase ) +{ + repaintContents(r.x(), r.y(), r.width(), r.height(), erase); +} + + +/*! + \overload + + Repaints the contents. If \a erase is TRUE the background is + cleared using the background color. +*/ +void TQScrollView::repaintContents( bool erase ) +{ + repaintContents( d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight(), erase ); +} + + +/*! + Calls repaint() on a rectangle defined by \a x, \a y, \a w, \a h, + translated appropriately. If the rectangle is not visible, nothing + is repainted. If \a erase is TRUE the background is cleared using + the background color. + + \sa updateContents() +*/ +void TQScrollView::repaintContents( int x, int y, int w, int h, bool erase ) +{ + if ( testWState(WState_Visible|WState_BlockUpdates) != WState_Visible ) + return; + + TQWidget* vp = viewport(); + + // Translate logical to clipper() + x -= d->contentsX(); + y -= d->contentsY(); + + // Clip to TQCOORD space + if ( x < 0 ) { + w += x; + x = 0; + } + if ( y < 0 ) { + h += y; + y = 0; + } + + if ( w < 0 || h < 0 ) + return; + if ( w > visibleWidth() ) + w = visibleWidth(); + if ( h > visibleHeight() ) + h = visibleHeight(); + + if ( d->clipped_viewport ) { + // Translate clipper() to viewport() + x -= d->clipped_viewport->x(); + y -= d->clipped_viewport->y(); + } + + vp->repaint( x, y, w, h, erase ); +} + + +/*! + For backward-compatibility only. It is easier to use + drawContents(TQPainter*,int,int,int,int). + + The default implementation translates the painter appropriately + and calls drawContents(TQPainter*,int,int,int,int). See + drawContents() for an explanation of the parameters \a p, \a + offsetx, \a offsety, \a clipx, \a clipy, \a clipw and \a cliph. +*/ +void TQScrollView::drawContentsOffset(TQPainter* p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph) +{ + p->translate(-offsetx,-offsety); + drawContents(p, clipx, clipy, clipw, cliph); +} + +/*! + \fn void TQScrollView::drawContents(TQPainter* p, int clipx, int clipy, int clipw, int cliph) + + Reimplement this function if you are viewing a drawing area rather + than a widget. + + The function should draw the rectangle (\a clipx, \a clipy, \a + clipw, \a cliph) of the contents using painter \a p. The clip + rectangle is in the scrollview's coordinates. + + For example: + \code + { + // Fill a 40000 by 50000 rectangle at (100000,150000) + + // Calculate the coordinates... + int x1 = 100000, y1 = 150000; + int x2 = x1+40000-1, y2 = y1+50000-1; + + // Clip the coordinates so X/Windows will not have problems... + if (x1 < clipx) x1=clipx; + if (y1 < clipy) y1=clipy; + if (x2 > clipx+clipw-1) x2=clipx+clipw-1; + if (y2 > clipy+cliph-1) y2=clipy+cliph-1; + + // Paint using the small coordinates... + if ( x2 >= x1 && y2 >= y1 ) + p->fillRect(x1, y1, x2-x1+1, y2-y1+1, red); + } + \endcode + + The clip rectangle and translation of the painter \a p is already + set appropriately. +*/ +void TQScrollView::drawContents(TQPainter*, int, int, int, int) +{ +} + + +/*! + \reimp +*/ +void TQScrollView::frameChanged() +{ + // slight ugle-hack - the listview header needs readjusting when + // changing the frame + if (TQListView *lv = ::tqt_cast(this)) + lv->triggerUpdate(); + TQFrame::frameChanged(); + updateScrollBars(); +} + + +/*! + Returns the viewport widget of the scrollview. This is the widget + containing the contents widget or which is the drawing area. +*/ +TQWidget* TQScrollView::viewport() const +{ + if ( d->clipped_viewport ) + return d->clipped_viewport; + return d->viewport; +} + +/*! + Returns the clipper widget. Contents in the scrollview are + ultimately clipped to be inside the clipper widget. + + You should not need to use this function. + + \sa visibleWidth(), visibleHeight() +*/ +TQWidget* TQScrollView::clipper() const +{ + return d->viewport; +} + +/*! + \property TQScrollView::visibleWidth + \brief the horizontal amount of the content that is visible +*/ +int TQScrollView::visibleWidth() const +{ + return clipper()->width(); +} + +/*! + \property TQScrollView::visibleHeight + \brief the vertical amount of the content that is visible +*/ +int TQScrollView::visibleHeight() const +{ + return clipper()->height(); +} + + +void TQScrollView::changeFrameRect(const TQRect& r) +{ + TQRect oldr = frameRect(); + if (oldr != r) { + TQRect cr = contentsRect(); + TQRegion fr( frameRect() ); + fr = fr.subtract( contentsRect() ); + setFrameRect( r ); + if ( isVisible() ) { + cr = cr.intersect( contentsRect() ); + fr = fr.unite( frameRect() ); + fr = fr.subtract( cr ); + if ( !fr.isEmpty() ) + TQApplication::postEvent( this, new TQPaintEvent( fr, FALSE ) ); + } + } +} + + +/*! + Sets the margins around the scrolling area to \a left, \a top, \a + right and \a bottom. This is useful for applications such as + spreadsheets with "locked" rows and columns. The marginal space is + \e inside the frameRect() and is left blank; reimplement + drawFrame() or put widgets in the unused area. + + By default all margins are zero. + + \sa frameChanged() +*/ +void TQScrollView::setMargins(int left, int top, int right, int bottom) +{ + if ( left == d->l_marg && + top == d->t_marg && + right == d->r_marg && + bottom == d->b_marg ) + return; + + d->l_marg = left; + d->t_marg = top; + d->r_marg = right; + d->b_marg = bottom; + updateScrollBars(); +} + + +/*! + Returns the left margin. + + \sa setMargins() +*/ +int TQScrollView::leftMargin() const +{ + return d->l_marg; +} + + +/*! + Returns the top margin. + + \sa setMargins() +*/ +int TQScrollView::topMargin() const +{ + return d->t_marg; +} + + +/*! + Returns the right margin. + + \sa setMargins() +*/ +int TQScrollView::rightMargin() const +{ + return d->r_marg; +} + + +/*! + Returns the bottom margin. + + \sa setMargins() +*/ +int TQScrollView::bottomMargin() const +{ + return d->b_marg; +} + +/*! + \reimp +*/ +bool TQScrollView::focusNextPrevChild( bool next ) +{ + // Makes sure that the new focus widget is on-screen, if + // necessary by scrolling the scroll view. + + // first set things up for the scan + TQFocusData *f = focusData(); + TQWidget *startingPoint = f->home(); + TQWidget *candidate = 0; + TQWidget *w = next ? f->next() : f->prev(); + TQSVChildRec *r; + extern bool tqt_tab_all_widgets; + uint focus_flag = tqt_tab_all_widgets ? TabFocus : StrongFocus; + + // then scan for a possible focus widget candidate + while( !candidate && w != startingPoint ) { + if ( w != startingPoint && + (w->focusPolicy() & focus_flag) == focus_flag + && w->isEnabled() &&!w->focusProxy() && w->isVisible() ) + candidate = w; + w = next ? f->next() : f->prev(); + } + + // if we could not find one, maybe super or parentWidget() can? + if ( !candidate ) + return TQFrame::focusNextPrevChild( next ); + + // we've found one. + r = d->ancestorRec( candidate ); + if ( r && ( r->child == candidate || + candidate->isVisibleTo( r->child ) ) ) { + TQPoint cp = r->child->mapToGlobal(TQPoint(0,0)); + TQPoint cr = candidate->mapToGlobal(TQPoint(0,0)) - cp; + ensureVisible( r->x+cr.x()+candidate->width()/2, + r->y+cr.y()+candidate->height()/2, + candidate->width()/2, + candidate->height()/2 ); + } + + candidate->setFocus(); + return TRUE; +} + + + +/*! + When a large numbers of child widgets are in a scrollview, + especially if they are close together, the scrolling performance + can suffer greatly. If \a y is TRUE the scrollview will use an + extra widget to group child widgets. + + Note that you may only call enableClipper() prior to adding + widgets. + + For a full discussion, see this class's \link #enableclipper + detailed description\endlink. +*/ +void TQScrollView::enableClipper(bool y) +{ + if ( !d->clipped_viewport == !y ) + return; + if ( d->children.count() ) + tqFatal("May only call TQScrollView::enableClipper() before adding widgets"); + if ( y ) { + d->clipped_viewport = new TQClipperWidget(clipper(), "qt_clipped_viewport", d->flags); + d->clipped_viewport->setGeometry(-coord_limit/2,-coord_limit/2, + coord_limit,coord_limit); + d->clipped_viewport->setBackgroundMode( d->viewport->backgroundMode() ); + d->viewport->setBackgroundMode(NoBackground); // no exposures for this + d->viewport->removeEventFilter( this ); + d->clipped_viewport->installEventFilter( this ); + d->clipped_viewport->show(); + } else { + delete d->clipped_viewport; + d->clipped_viewport = 0; + } +} + +/*! + Sets the scrollview to have a static background if \a y is TRUE, + or a scrolling background if \a y is FALSE. By default, the + background is scrolling. + + Be aware that this mode is quite slow, as a full repaint of the + visible area has to be triggered on every contents move. + + \sa hasStaticBackground() +*/ +void TQScrollView::setStaticBackground(bool y) +{ + d->static_bg = y; +} + +/*! + Returns TRUE if TQScrollView uses a static background; otherwise + returns FALSE. + + \sa setStaticBackground() +*/ +bool TQScrollView::hasStaticBackground() const +{ + return d->static_bg; +} + +/*! + \overload + + Returns the point \a p translated to a point on the viewport() + widget. +*/ +TQPoint TQScrollView::contentsToViewport( const TQPoint& p ) const +{ + if ( d->clipped_viewport ) { + return TQPoint( p.x() - d->contentsX() - d->clipped_viewport->x(), + p.y() - d->contentsY() - d->clipped_viewport->y() ); + } else { + return TQPoint( p.x() - d->contentsX(), + p.y() - d->contentsY() ); + } +} + +/*! + \overload + + Returns the point on the viewport \a vp translated to a point in + the contents. +*/ +TQPoint TQScrollView::viewportToContents( const TQPoint& vp ) const +{ + if ( d->clipped_viewport ) { + return TQPoint( vp.x() + d->contentsX() + d->clipped_viewport->x(), + vp.y() + d->contentsY() + d->clipped_viewport->y() ); + } else { + return TQPoint( vp.x() + d->contentsX(), + vp.y() + d->contentsY() ); + } +} + + +/*! + Translates a point (\a x, \a y) in the contents to a point (\a vx, + \a vy) on the viewport() widget. +*/ +void TQScrollView::contentsToViewport( int x, int y, int& vx, int& vy ) const +{ + const TQPoint v = contentsToViewport(TQPoint(x,y)); + vx = v.x(); + vy = v.y(); +} + +/*! + Translates a point (\a vx, \a vy) on the viewport() widget to a + point (\a x, \a y) in the contents. +*/ +void TQScrollView::viewportToContents( int vx, int vy, int& x, int& y ) const +{ + const TQPoint c = viewportToContents(TQPoint(vx,vy)); + x = c.x(); + y = c.y(); +} + +/*! + \reimp +*/ +TQSize TQScrollView::sizeHint() const +{ + if ( d->use_cached_size_hint && d->cachedSizeHint.isValid() ) + return d->cachedSizeHint; + + constPolish(); + int f = 2 * frameWidth(); + int h = fontMetrics().height(); + TQSize sz( f, f ); + if ( d->policy > Manual ) { + TQSVChildRec *r = d->children.first(); + if ( r ) { + TQSize cs = r->child->sizeHint(); + if ( cs.isValid() ) + sz += cs.boundedTo( r->child->maximumSize() ); + else + sz += r->child->size(); + } + } else { + sz += TQSize( d->contentsWidth(), contentsHeight() ); + } + if (d->vMode == AlwaysOn) + sz.setWidth(sz.width() + d->vbar->sizeHint().width()); + if (d->hMode == AlwaysOn) + sz.setHeight(sz.height() + d->hbar->sizeHint().height()); + return sz.expandedTo( TQSize(12 * h, 8 * h) ) + .boundedTo( TQSize(36 * h, 24 * h) ); +} + + +/*! + \reimp +*/ +TQSize TQScrollView::minimumSizeHint() const +{ + int h = fontMetrics().height(); + if ( h < 10 ) + h = 10; + int f = 2 * frameWidth(); + return TQSize( (6 * h) + f, (4 * h) + f ); +} + + +/*! + \reimp + + (Implemented to get rid of a compiler warning.) +*/ +void TQScrollView::drawContents( TQPainter * ) +{ +} + +#ifndef TQT_NO_DRAGANDDROP + +/*! + \internal +*/ +void TQScrollView::startDragAutoScroll() +{ + if ( !d->autoscroll_timer.isActive() ) { + d->autoscroll_time = initialScrollTime; + d->autoscroll_accel = initialScrollAccel; + d->autoscroll_timer.start( d->autoscroll_time ); + } +} + + +/*! + \internal +*/ +void TQScrollView::stopDragAutoScroll() +{ + d->autoscroll_timer.stop(); +} + + +/*! + \internal +*/ +void TQScrollView::doDragAutoScroll() +{ + TQPoint p = d->viewport->mapFromGlobal( TQCursor::pos() ); + + if ( d->autoscroll_accel-- <= 0 && d->autoscroll_time ) { + d->autoscroll_accel = initialScrollAccel; + d->autoscroll_time--; + d->autoscroll_timer.start( d->autoscroll_time ); + } + int l = TQMAX( 1, ( initialScrollTime- d->autoscroll_time ) ); + + int dx = 0, dy = 0; + if ( p.y() < autoscroll_margin ) { + dy = -l; + } else if ( p.y() > visibleHeight() - autoscroll_margin ) { + dy = +l; + } + if ( p.x() < autoscroll_margin ) { + dx = -l; + } else if ( p.x() > visibleWidth() - autoscroll_margin ) { + dx = +l; + } + if ( dx || dy ) { + scrollBy(dx,dy); + } else { + stopDragAutoScroll(); + } +} + + +/*! + \property TQScrollView::dragAutoScroll + \brief whether autoscrolling in drag move events is enabled + + If this property is set to TRUE (the default), the TQScrollView + automatically scrolls the contents in drag move events if the user + moves the cursor close to a border of the view. Of course this + works only if the viewport accepts drops. Specifying FALSE + disables this autoscroll feature. + + \warning Enabling this property might not be enough to + effectively turn on autoscrolling. If you put a custom widget in + the TQScrollView, you might need to call TQDragEvent::ignore() on + the event in the dragEnterEvent() and dragMoveEvent() + reimplementations. +*/ + +void TQScrollView::setDragAutoScroll( bool b ) +{ + d->drag_autoscroll = b; +} + +bool TQScrollView::dragAutoScroll() const +{ + return d->drag_autoscroll; +} + +#endif // TQT_NO_DRAGANDDROP + +/*!\internal + */ +void TQScrollView::setCachedSizeHint( const TQSize &sh ) const +{ + if ( isVisible() && !d->cachedSizeHint.isValid() ) + d->cachedSizeHint = sh; +} + +/*!\internal + */ +void TQScrollView::disableSizeHintCaching() +{ + d->use_cached_size_hint = FALSE; +} + +/*!\internal + */ +TQSize TQScrollView::cachedSizeHint() const +{ + return d->use_cached_size_hint ? d->cachedSizeHint : TQSize(); +} + +#endif // TQT_NO_SCROLLVIEW diff --git a/src/widgets/tqscrollview.h b/src/widgets/tqscrollview.h new file mode 100644 index 000000000..21cc37237 --- /dev/null +++ b/src/widgets/tqscrollview.h @@ -0,0 +1,269 @@ +/**************************************************************************** +** +** Definition of TQScrollView class +** +** Created : 970523 +** +** 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 TQSCROLLVIEW_H +#define TQSCROLLVIEW_H + +#ifndef QT_H +#include "ntqframe.h" +#include "tqscrollbar.h" +#endif // QT_H + +#ifndef TQT_NO_SCROLLVIEW + +class TQScrollViewData; + +class TQ_EXPORT TQScrollView : public TQFrame +{ + TQ_OBJECT + TQ_ENUMS( ResizePolicy ScrollBarMode ) + TQ_PROPERTY( ResizePolicy resizePolicy READ resizePolicy WRITE setResizePolicy ) + TQ_PROPERTY( ScrollBarMode vScrollBarMode READ vScrollBarMode WRITE setVScrollBarMode ) + TQ_PROPERTY( ScrollBarMode hScrollBarMode READ hScrollBarMode WRITE setHScrollBarMode ) + TQ_PROPERTY( int visibleWidth READ visibleWidth ) + TQ_PROPERTY( int visibleHeight READ visibleHeight ) + TQ_PROPERTY( int contentsWidth READ contentsWidth ) + TQ_PROPERTY( int contentsHeight READ contentsHeight ) + TQ_PROPERTY( int contentsX READ contentsX ) + TQ_PROPERTY( int contentsY READ contentsY ) +#ifndef TQT_NO_DRAGANDDROP + TQ_PROPERTY( bool dragAutoScroll READ dragAutoScroll WRITE setDragAutoScroll ) +#endif + +public: + TQScrollView(TQWidget* parent=0, const char* name=0, WFlags f=0); + ~TQScrollView(); + + enum ResizePolicy { Default, Manual, AutoOne, AutoOneFit }; + virtual void setResizePolicy( ResizePolicy ); + ResizePolicy resizePolicy() const; + + void styleChange( TQStyle & ); + void removeChild(TQWidget* child); + virtual void addChild( TQWidget* child, int x=0, int y=0 ); + virtual void moveChild( TQWidget* child, int x, int y ); + int childX(TQWidget* child); + int childY(TQWidget* child); + bool childIsVisible(TQWidget* child) { return child->isVisible(); } // obsolete functions + void showChild(TQWidget* child, bool yes=TRUE) { + if ( yes ) + child->show(); + else + child->hide(); + } + + enum ScrollBarMode { Auto, AlwaysOff, AlwaysOn }; + + ScrollBarMode vScrollBarMode() const; + virtual void setVScrollBarMode( ScrollBarMode ); + + ScrollBarMode hScrollBarMode() const; + virtual void setHScrollBarMode( ScrollBarMode ); + + TQWidget* cornerWidget() const; + virtual void setCornerWidget(TQWidget*); + + // ### 4.0: Consider providing a factory function for scrollbars + // (e.g. make the two following functions virtual) + TQScrollBar* horizontalScrollBar() const; + TQScrollBar* verticalScrollBar() const; + TQWidget* viewport() const; + TQWidget* clipper() const; + + int visibleWidth() const; + int visibleHeight() const; + + int contentsWidth() const; + int contentsHeight() const; + int contentsX() const; + int contentsY() const; + + void resize( int w, int h ); + void resize( const TQSize& ); + void show(); + + void updateContents( int x, int y, int w, int h ); + void updateContents( const TQRect& r ); + void updateContents(); + void repaintContents( int x, int y, int w, int h, bool erase=TRUE ); + void repaintContents( const TQRect& r, bool erase=TRUE ); + void repaintContents( bool erase=TRUE ); + void contentsToViewport( int x, int y, int& vx, int& vy ) const; + void viewportToContents( int vx, int vy, int& x, int& y ) const; + TQPoint contentsToViewport( const TQPoint& ) const; + TQPoint viewportToContents( const TQPoint& ) const; + void enableClipper( bool y ); + + void setStaticBackground( bool y ); + bool hasStaticBackground() const; + + TQSize viewportSize( int, int ) const; + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + + void removeChild(TQObject* child); + + bool isHorizontalSliderPressed(); + bool isVerticalSliderPressed(); + +#ifndef TQT_NO_DRAGANDDROP + virtual void setDragAutoScroll( bool b ); + bool dragAutoScroll() const; +#endif + +signals: + void contentsMoving(int x, int y); + void horizontalSliderPressed(); + void horizontalSliderReleased(); + void verticalSliderPressed(); + void verticalSliderReleased(); + +public slots: + virtual void resizeContents( int w, int h ); + void scrollBy( int dx, int dy ); + virtual void setContentsPos( int x, int y ); + void ensureVisible(int x, int y); + void ensureVisible(int x, int y, int xmargin, int ymargin); + void center(int x, int y); + void center(int x, int y, float xmargin, float ymargin); + + void updateScrollBars(); // ### virtual in 4.0 + void setEnabled( bool enable ); + +protected: + virtual void drawContents(TQPainter*, int cx, int cy, int cw, int ch); + virtual void drawContentsOffset(TQPainter*, int ox, int oy, + int cx, int cy, int cw, int ch); + + + virtual void contentsMousePressEvent( TQMouseEvent* ); + virtual void contentsMouseReleaseEvent( TQMouseEvent* ); + virtual void contentsMouseDoubleClickEvent( TQMouseEvent* ); + virtual void contentsMouseMoveEvent( TQMouseEvent* ); +#ifndef TQT_NO_DRAGANDDROP + virtual void contentsDragEnterEvent( TQDragEnterEvent * ); + virtual void contentsDragMoveEvent( TQDragMoveEvent * ); + virtual void contentsDragLeaveEvent( TQDragLeaveEvent * ); + virtual void contentsDropEvent( TQDropEvent * ); +#endif +#ifndef TQT_NO_WHEELEVENT + virtual void contentsWheelEvent( TQWheelEvent * ); +#endif + virtual void contentsContextMenuEvent( TQContextMenuEvent * ); + + + virtual void viewportPaintEvent( TQPaintEvent* ); + virtual void viewportResizeEvent( TQResizeEvent* ); + virtual void viewportMousePressEvent( TQMouseEvent* ); + virtual void viewportMouseReleaseEvent( TQMouseEvent* ); + virtual void viewportMouseDoubleClickEvent( TQMouseEvent* ); + virtual void viewportMouseMoveEvent( TQMouseEvent* ); +#ifndef TQT_NO_DRAGANDDROP + virtual void viewportDragEnterEvent( TQDragEnterEvent * ); + virtual void viewportDragMoveEvent( TQDragMoveEvent * ); + virtual void viewportDragLeaveEvent( TQDragLeaveEvent * ); + virtual void viewportDropEvent( TQDropEvent * ); +#endif +#ifndef TQT_NO_WHEELEVENT + virtual void viewportWheelEvent( TQWheelEvent * ); +#endif + virtual void viewportContextMenuEvent( TQContextMenuEvent * ); + + void frameChanged(); + + virtual void setMargins(int left, int top, int right, int bottom); + int leftMargin() const; + int topMargin() const; + int rightMargin() const; + int bottomMargin() const; + + bool focusNextPrevChild( bool next ); + + virtual void setHBarGeometry(TQScrollBar& hbar, int x, int y, int w, int h); + virtual void setVBarGeometry(TQScrollBar& vbar, int x, int y, int w, int h); + + void resizeEvent(TQResizeEvent*); + void mousePressEvent( TQMouseEvent * ); + void mouseReleaseEvent( TQMouseEvent * ); + void mouseDoubleClickEvent( TQMouseEvent * ); + void mouseMoveEvent( TQMouseEvent * ); +#ifndef TQT_NO_WHEELEVENT + void wheelEvent( TQWheelEvent * ); +#endif + void contextMenuEvent( TQContextMenuEvent * ); + bool eventFilter( TQObject *, TQEvent *e ); + + void setCachedSizeHint( const TQSize &sh ) const; + TQSize cachedSizeHint() const; + void fontChange( const TQFont & ); + +private: + void drawContents( TQPainter* ); + void moveContents(int x, int y); + + TQScrollViewData* d; + +private slots: + void hslide(int); + void vslide(int); + void hbarIsPressed(); + void hbarIsReleased(); + void vbarIsPressed(); + void vbarIsReleased(); +#ifndef TQT_NO_DRAGANDDROP + void doDragAutoScroll(); + void startDragAutoScroll(); + void stopDragAutoScroll(); +#endif + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQScrollView( const TQScrollView & ); + TQScrollView &operator=( const TQScrollView & ); +#endif + void changeFrameRect(const TQRect&); + +public: + void disableSizeHintCaching(); + +}; + +#endif // TQT_NO_SCROLLVIEW + +#endif // TQSCROLLVIEW_H diff --git a/src/widgets/tqslider.cpp b/src/widgets/tqslider.cpp new file mode 100644 index 000000000..98d61b68d --- /dev/null +++ b/src/widgets/tqslider.cpp @@ -0,0 +1,924 @@ +/**************************************************************************** +** +** Implementation of TQSlider class +** +** Created : 961019 +** +** 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 "tqslider.h" +#ifndef TQT_NO_SLIDER +#include "tqpainter.h" +#include "ntqdrawutil.h" +#include "tqtimer.h" +#include "tqbitmap.h" +#include "ntqapplication.h" +#include "tqstyle.h" +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif + +static const int thresholdTime = 300; +static const int repeatTime = 100; + +struct TQSliderPrivate +{ + // ### move these to TQSlider in TQt 4.0 + int sliderStartVal; + TQSliderPrivate() : sliderStartVal( 0 ) { } +}; + + +/*! + \class TQSlider + \brief The TQSlider widget provides a vertical or horizontal slider. + + \ingroup basic + \mainclass + + The slider is the classic widget for controlling a bounded value. + It lets the user move a slider along a horizontal or vertical + groove and translates the slider's position into an integer value + within the legal range. + + TQSlider inherits TQRangeControl, which provides the "integer" side + of the slider. setRange() and value() are likely to be used by + practically all slider users; see the \l TQRangeControl + documentation for information about the many other functions that + class provides. + + The main functions offered by the slider itself are tickmark and + orientation control; you can use setTickmarks() to indicate where + you want the tickmarks to be, setTickInterval() to indicate how + many of them you want and setOrientation() to indicate whether the + slider is to be horizontal or vertical. + + A slider accepts focus on Tab and uses the mouse wheel and a + suitable keyboard interface. + + + + \important setRange + + \sa TQScrollBar TQSpinBox + \link guibooks.html#fowler GUI Design Handbook: Slider\endlink +*/ + + +/*! + \enum TQSlider::TickSetting + + This enum specifies where the tickmarks are to be drawn relative + to the slider's groove and the handle the user moves. + + \value NoMarks do not draw any tickmarks. + \value Both draw tickmarks on both sides of the groove. + \value Above draw tickmarks above the (horizontal) slider + \value Below draw tickmarks below the (horizontal) slider + \value Left draw tickmarks to the left of the (vertical) slider + \value Right draw tickmarks to the right of the (vertical) slider +*/ + + +/*! + Constructs a vertical slider. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. +*/ + +TQSlider::TQSlider( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + orient = Vertical; + init(); +} + +/*! + Constructs a slider. + + The \a orientation must be \l TQt::Vertical or \l TQt::Horizontal. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. +*/ + +TQSlider::TQSlider( Orientation orientation, TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + orient = orientation; + init(); +} + +/*! + Constructs a slider whose value can never be smaller than \a + minValue or greater than \a maxValue, whose page step size is \a + pageStep and whose value is initially \a value (which is + guaranteed to be in range using bound()). + + If \a orientation is \c TQt::Vertical the slider is vertical and if it + is \c TQt::Horizontal the slider is horizontal. + + The \a parent and \a name arguments are sent on to the TQWidget + constructor. +*/ + +TQSlider::TQSlider( int minValue, int maxValue, int pageStep, + int value, Orientation orientation, + TQWidget *parent, const char *name ) + : TQWidget( parent, name ), + TQRangeControl( minValue, maxValue, 1, pageStep, value ) +{ + orient = orientation; + init(); + sliderVal = value; +} + +/*! + Destructor. +*/ +TQSlider::~TQSlider() +{ + delete d; +} + +void TQSlider::init() +{ + d = new TQSliderPrivate; + timer = 0; + sliderPos = 0; + sliderVal = 0; + clickOffset = 0; + state = Idle; + track = TRUE; + ticks = NoMarks; + tickInt = 0; + setFocusPolicy( TabFocus ); + initTicks(); + + TQSizePolicy sp( TQSizePolicy::Expanding, TQSizePolicy::Fixed ); + if ( orient == Vertical ) + sp.transpose(); + setSizePolicy( sp ); + clearWState( WState_OwnSizePolicy ); +} + + +/* + Does what's needed when someone changes the tickmark status. +*/ + +void TQSlider::initTicks() +{ + tickOffset = style().pixelMetric( TQStyle::PM_SliderTickmarkOffset, this ); +} + + +/*! + \property TQSlider::tracking + \brief whether slider tracking is enabled + + If tracking is enabled (the default), the slider emits the + valueChanged() signal whenever the slider is being dragged. If + tracking is disabled, the slider emits the valueChanged() signal + when the user releases the mouse button (unless the value happens + to be the same as before). +*/ + +void TQSlider::setTracking( bool enable ) +{ + track = enable; +} + + +/*! + \fn void TQSlider::valueChanged( int value ) + + This signal is emitted when the slider value is changed, with the + new slider \a value as its argument. +*/ + +/*! + \fn void TQSlider::sliderPressed() + + This signal is emitted when the user presses the slider with the + mouse. +*/ + +/*! + \fn void TQSlider::sliderMoved( int value ) + + This signal is emitted when the slider is dragged, with the new + slider \a value as its argument. +*/ + +/*! + \fn void TQSlider::sliderReleased() + + This signal is emitted when the user releases the slider with the mouse. +*/ + +/* + Calculates slider position corresponding to value \a v. +*/ + +int TQSlider::positionFromValue( int v ) const +{ + int a = available(); + int x = TQRangeControl::positionFromValue( v, a ); + if ( orient == Horizontal && TQApplication::reverseLayout() ) + x = a - x; + return x; +} + +/* + Returns the available space in which the slider can move. +*/ + +int TQSlider::available() const +{ + return style().pixelMetric( TQStyle::PM_SliderSpaceAvailable, this ); +} + +/* + Calculates a value corresponding to slider position \a p. +*/ + +int TQSlider::valueFromPosition( int p ) const +{ + int a = available(); + int x = TQRangeControl::valueFromPosition( p, a ); + if ( orient == Horizontal && TQApplication::reverseLayout() ) + x = maxValue() + minValue() - x; + return x; +} + +/*! + Implements the virtual TQRangeControl function. +*/ + +void TQSlider::rangeChange() +{ + int newPos = positionFromValue( value() ); + if ( newPos != sliderPos ) { + reallyMoveSlider( newPos ); + } +} + +/*! + Implements the virtual TQRangeControl function. +*/ + +void TQSlider::valueChange() +{ + if ( sliderVal != value() ) { + int newPos = positionFromValue( value() ); + sliderVal = value(); + reallyMoveSlider( newPos ); + } + emit valueChanged(value()); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif +} + + +/*! + \reimp +*/ +void TQSlider::resizeEvent( TQResizeEvent * ) +{ + rangeChange(); + initTicks(); +} + + +/*! + Reimplements the virtual function TQWidget::setPalette(). + + Sets the background color to the mid color for Motif style sliders + using palette \a p. +*/ + +void TQSlider::setPalette( const TQPalette &p ) +{ + TQWidget::setPalette( p ); +} + + + +/*! + \property TQSlider::orientation + \brief the slider's orientation + + The orientation must be \l TQt::Vertical (the default) or \l + TQt::Horizontal. +*/ + +void TQSlider::setOrientation( Orientation orientation ) +{ + if ( orientation == orient ) + return; + + if ( !testWState( WState_OwnSizePolicy ) ) { + TQSizePolicy sp = sizePolicy(); + sp.transpose(); + setSizePolicy( sp ); + clearWState( WState_OwnSizePolicy ); + } + + orient = orientation; + + rangeChange(); + update(); +} + +/*! + \fn int TQSlider::sliderStart() const + + Returns the start position of the slider. +*/ + + +/*! + Returns the slider handle rectangle. (This is the visual marker + that the user can move.) +*/ + +TQRect TQSlider::sliderRect() const +{ + return style().querySubControlMetrics( TQStyle::CC_Slider, this, + TQStyle::SC_SliderHandle ); +} + +/* + Performs the actual moving of the slider. +*/ + +void TQSlider::reallyMoveSlider( int newPos ) +{ + TQRegion oldR(sliderRect()); + sliderPos = newPos; + TQRegion newR(sliderRect()); + + /* just the one repaint if no background */ + if (backgroundMode() == NoBackground) + repaint(newR | oldR, FALSE); + else { + repaint(oldR.subtract(newR)); + repaint(newR, FALSE); + } +} + + +/*! + \reimp +*/ +void TQSlider::paintEvent( TQPaintEvent * ) +{ + TQPainter p( this ); + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasFocus()) + flags |= TQStyle::Style_HasFocus; + if (hasMouse()) + flags |= TQStyle::Style_MouseOver; + + TQStyle::SCFlags sub = TQStyle::SC_SliderGroove | TQStyle::SC_SliderHandle; + if ( tickmarks() != NoMarks ) { + sub |= TQStyle::SC_SliderTickmarks; + } + + style().drawComplexControl( TQStyle::CC_Slider, &p, this, rect(), colorGroup(), + flags, sub, state == Dragging ? TQStyle::SC_SliderHandle : TQStyle::SC_None ); +} + + +/*! + \reimp +*/ +void TQSlider::mousePressEvent( TQMouseEvent *e ) +{ + int slideLength = style().pixelMetric( TQStyle::PM_SliderLength, this ); + resetState(); + d->sliderStartVal = sliderVal; + TQRect r = sliderRect(); + + if ( e->button() == RightButton ) + return; + + if ( r.contains( e->pos() ) ) { + state = Dragging; + clickOffset = (TQCOORD)( goodPart( e->pos() ) - sliderPos ); + emit sliderPressed(); + } else if ( e->button() == MidButton ) { + int pos = goodPart( e->pos() ); + moveSlider( pos - slideLength / 2 ); + state = Dragging; + clickOffset = slideLength / 2; + } else if ( ( orient == Horizontal && e->pos().x() < r.left() ) //### goodPart + || ( orient == Vertical && e->pos().y() < r.top() ) ) { + if ( orient == Horizontal && TQApplication::reverseLayout() ) { + state = TimingUp; + addPage(); + } else { + state = TimingDown; + subtractPage(); + } + if ( !timer ) + timer = new TQTimer( this ); + connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(repeatTimeout()) ); + timer->start( thresholdTime, TRUE ); + } else if ( ( orient == Horizontal && e->pos().x() > r.right() ) //### goodPart + || ( orient == Vertical && e->pos().y() > r.bottom() ) ) { + if ( orient == Horizontal && TQApplication::reverseLayout() ) { + state = TimingDown; + subtractPage(); + } else { + state = TimingUp; + addPage(); + } + if ( !timer ) + timer = new TQTimer( this ); + connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(repeatTimeout()) ); + timer->start( thresholdTime, TRUE ); + } + update( sliderRect() ); +} + +/*! + \reimp +*/ +void TQSlider::mouseMoveEvent( TQMouseEvent *e ) +{ + if ( state != Dragging ) + return; + + TQRect r = rect(); + int m = style().pixelMetric( TQStyle::PM_MaximumDragDistance, + this ); + if ( m >= 0 ) { + if ( orientation() == Horizontal ) + r.setRect( r.x() - m, r.y() - 2*m/3, + r.width() + 2*m, r.height() + 3*m ); + else + r.setRect( r.x() - 2*m/3, r.y() - m, + r.width() + 3*m, r.height() + 2*m ); + if ( !r.contains( e->pos() ) ) { + moveSlider( positionFromValue(d->sliderStartVal) ); + return; + } + } + + int pos = goodPart( e->pos() ); + moveSlider( pos - clickOffset ); +} + +/*! + \reimp +*/ +#ifndef TQT_NO_WHEELEVENT +void TQSlider::wheelEvent( TQWheelEvent * e ) +{ + if ( e->orientation() != orientation() && !rect().contains(e->pos()) ) + return; + + static float offset = 0; + static TQSlider* offset_owner = 0; + if (offset_owner != this){ + offset_owner = this; + offset = 0; + } + offset += -e->delta()*TQMAX(pageStep(),lineStep())/120; + if (TQABS(offset)<1) + return; + setValue( value() + int(offset) ); + offset -= int(offset); + e->accept(); +} +#endif + +/*! + \reimp +*/ +void TQSlider::mouseReleaseEvent( TQMouseEvent * ) +{ + resetState(); + update( sliderRect() ); +} + +/*! + \reimp +*/ +void TQSlider::focusInEvent( TQFocusEvent * e) +{ + TQWidget::focusInEvent( e ); +} + +/*! + \reimp +*/ +void TQSlider::focusOutEvent( TQFocusEvent * e ) +{ + TQWidget::focusOutEvent( e ); +} + +/*! + Moves the left (or top) edge of the slider to position \a pos. The + slider is actually moved to the step position nearest the given \a + pos. +*/ + +void TQSlider::moveSlider( int pos ) +{ + int a = available(); + int newPos = TQMIN( a, TQMAX( 0, pos ) ); + int newVal = valueFromPosition( newPos ); + if (style().styleHint(TQStyle::SH_Slider_SnapToValue, this)) + newPos = positionFromValue( newVal ); + if ( sliderPos != newPos ) + reallyMoveSlider( newPos ); + if ( sliderVal != newVal ) { + sliderVal = newVal; + emit sliderMoved( sliderVal ); + } + if ( tracking() && sliderVal != value() ) + setValue( sliderVal ); + +} + + +/* + Resets all state information and stops the timer. +*/ + +void TQSlider::resetState() +{ + if ( timer ) { + timer->stop(); + timer->disconnect(); + } + switch ( state ) { + case TimingUp: + case TimingDown: + break; + case Dragging: { + setValue( valueFromPosition( sliderPos ) ); + emit sliderReleased(); + break; + } + case Idle: + break; + default: + tqWarning("TQSlider: (%s) in wrong state", name( "unnamed" ) ); + } + state = Idle; +} + + +/*! + \reimp +*/ +void TQSlider::keyPressEvent( TQKeyEvent *e ) +{ + bool sloppy = bool(style().styleHint(TQStyle::SH_Slider_SloppyKeyEvents, this)); + switch ( e->key() ) { + case Key_Left: + if ( sloppy || orient == Horizontal ) { + if (TQApplication::reverseLayout()) + addLine(); + else + subtractLine(); + } + break; + case Key_Right: + if ( sloppy || orient == Horizontal ) { + if (TQApplication::reverseLayout()) + subtractLine(); + else + addLine(); + } + break; + case Key_Up: + if ( sloppy || orient == Vertical ) + subtractLine(); + break; + case Key_Down: + if ( sloppy || orient == Vertical ) + addLine(); + break; + case Key_Prior: + subtractPage(); + break; + case Key_Next: + addPage(); + break; + case Key_Home: + setValue( minValue() ); + break; + case Key_End: + setValue( maxValue() ); + break; + default: + e->ignore(); + return; + } +} + +void TQSlider::setValue( int value ) +{ + TQRangeControl::setValue( value ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif +} + + +/*! \reimp +*/ + +void TQSlider::addLine() +{ + TQRangeControl::addLine(); +} + +/*! \reimp +*/ + +void TQSlider::subtractLine() +{ + TQRangeControl::subtractLine(); +} + +/*! + Moves the slider one pageStep() up or right. +*/ + +void TQSlider::addStep() +{ + addPage(); +} + + +/*! + Moves the slider one pageStep() down or left. +*/ + +void TQSlider::subtractStep() +{ + subtractPage(); +} + + +/* + Waits for autorepeat. +*/ + +void TQSlider::repeatTimeout() +{ + Q_ASSERT( timer ); + timer->disconnect(); + if ( state == TimingDown ) + connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(subtractStep()) ); + else if ( state == TimingUp ) + connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(addStep()) ); + timer->start( repeatTime, FALSE ); +} + + +/* + Returns the relevant dimension of \a p. +*/ + +int TQSlider::goodPart( const TQPoint &p ) const +{ + return (orient == Horizontal) ? p.x() : p.y(); +} + +/*! + \reimp +*/ +TQSize TQSlider::sizeHint() const +{ + constPolish(); + const int length = 84, tickSpace = 5; + int thick = style().pixelMetric( TQStyle::PM_SliderThickness, this ); + if ( ticks & Above ) + thick += tickSpace; + if ( ticks & Below ) + thick += tickSpace; + int w = thick, h = length; + if ( orient == Horizontal ) { + w = length; + h = thick; + } + return (style().sizeFromContents(TQStyle::CT_Slider, this, + TQSize(w, h)).expandedTo(TQApplication::globalStrut())); +} + + + +/*! + \reimp +*/ + +TQSize TQSlider::minimumSizeHint() const +{ + TQSize s = sizeHint(); + int length = style().pixelMetric(TQStyle::PM_SliderLength, this); + if ( orient == Horizontal ) + s.setWidth( length ); + else + s.setHeight( length ); + + return s; +} + +/*! \fn void TQSlider::setSizePolicy( TQSizePolicy::SizeType, TQSizePolicy::SizeType, bool ) + \reimp +*/ + +/*! \reimp */ +void TQSlider::setSizePolicy( TQSizePolicy sp ) +{ + // ## remove 4.0 + TQWidget::setSizePolicy( sp ); +} + +/*! \reimp */ +TQSizePolicy TQSlider::sizePolicy() const +{ + // ### 4.0 remove this reimplementation + return TQWidget::sizePolicy(); +} + +/*! + \property TQSlider::tickmarks + \brief the tickmark settings for this slider + + The valid values are in \l{TQSlider::TickSetting}. The default is + \c NoMarks. + + \sa tickInterval +*/ + +void TQSlider::setTickmarks( TickSetting s ) +{ + ticks = s; + initTicks(); + update(); +} + + +/*! + \property TQSlider::tickInterval + \brief the interval between tickmarks + + This is a value interval, not a pixel interval. If it is 0, the + slider will choose between lineStep() and pageStep(). The initial + value of tickInterval is 0. + + \sa TQRangeControl::lineStep(), TQRangeControl::pageStep() +*/ + +void TQSlider::setTickInterval( int i ) +{ + tickInt = TQMAX( 0, i ); + update(); +} + + +/*! + \reimp +*/ +void TQSlider::styleChange( TQStyle& old ) +{ + TQWidget::styleChange( old ); +} + +/*! + \property TQSlider::minValue + \brief the current minimum value of the slider + + When setting this property, the \l TQSlider::maxValue is adjusted, + if necessary, to ensure that the range remains valid. + + \sa setRange() +*/ +int TQSlider::minValue() const +{ + return TQRangeControl::minValue(); +} + +/*! + \property TQSlider::maxValue + \brief the current maximum value of the slider + + When setting this property, the \l TQSlider::minValue is adjusted, + if necessary, to ensure that the range remains valid. + + \sa setRange() +*/ +int TQSlider::maxValue() const +{ + return TQRangeControl::maxValue(); +} + +void TQSlider::setMinValue( int minVal ) +{ + TQRangeControl::setMinValue( minVal ); +} + +void TQSlider::setMaxValue( int maxVal ) +{ + TQRangeControl::setMaxValue( maxVal ); +} + +/*! + \property TQSlider::lineStep + \brief the current line step + + When setting lineStep, the virtual stepChange() function will be + called if the new line step is different from the previous + setting. + + \sa setSteps() TQRangeControl::pageStep() setRange() +*/ +int TQSlider::lineStep() const +{ + return TQRangeControl::lineStep(); +} + +/*! + \property TQSlider::pageStep + \brief the current page step + + When setting pageStep, the virtual stepChange() function will be + called if the new page step is different from the previous + setting. + + \sa TQRangeControl::setSteps() setLineStep() setRange() +*/ + +int TQSlider::pageStep() const +{ + return TQRangeControl::pageStep(); +} + +void TQSlider::setLineStep( int i ) +{ + setSteps( i, pageStep() ); +} + +void TQSlider::setPageStep( int i ) +{ + setSteps( lineStep(), i ); +} + +/*! + \property TQSlider::value + \brief the current slider value + + \sa TQRangeControl::value() prevValue() +*/ + +int TQSlider::value() const +{ + return TQRangeControl::value(); +} + +#endif diff --git a/src/widgets/tqslider.h b/src/widgets/tqslider.h new file mode 100644 index 000000000..af60245e3 --- /dev/null +++ b/src/widgets/tqslider.h @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Definition of TQSlider class +** +** Created : 961019 +** +** 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 TQSLIDER_H +#define TQSLIDER_H + +#ifndef QT_H +#include "tqwidget.h" +#include "ntqrangecontrol.h" +#endif // QT_H + +#ifndef TQT_NO_SLIDER + +struct TQSliderPrivate; + +class TQTimer; + +class TQ_EXPORT TQSlider : public TQWidget, public TQRangeControl +{ + TQ_OBJECT + TQ_ENUMS( TickSetting ) + TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) + TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) + TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) + TQ_PROPERTY( int pageStep READ pageStep WRITE setPageStep ) + TQ_PROPERTY( int value READ value WRITE setValue ) + TQ_PROPERTY( bool tracking READ tracking WRITE setTracking ) + TQ_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) + TQ_PROPERTY( TickSetting tickmarks READ tickmarks WRITE setTickmarks ) + TQ_PROPERTY( int tickInterval READ tickInterval WRITE setTickInterval ) + +public: + enum TickSetting { NoMarks = 0, Above = 1, Left = Above, + Below = 2, Right = Below, Both = 3 }; + + TQSlider( TQWidget *parent, const char* name = 0 ); + TQSlider( Orientation, TQWidget *parent, const char* name = 0 ); + TQSlider( int minValue, int maxValue, int pageStep, int value, Orientation, + TQWidget *parent, const char* name = 0 ); + ~TQSlider(); + + virtual void setOrientation( Orientation ); + Orientation orientation() const; + virtual void setTracking( bool enable ); + bool tracking() const; + virtual void setPalette( const TQPalette & ); + + int sliderStart() const; + TQRect sliderRect() const; + TQSize sizeHint() const; + void setSizePolicy( TQSizePolicy sp ); + void setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw = FALSE ); + + TQSizePolicy sizePolicy() const; + TQSize minimumSizeHint() const; + + virtual void setTickmarks( TickSetting ); + TickSetting tickmarks() const { return ticks; } + + virtual void setTickInterval( int ); + int tickInterval() const { return tickInt; } + + int minValue() const; + int maxValue() const; + void setMinValue( int ); + void setMaxValue( int ); + int lineStep() const; + int pageStep() const; + void setLineStep( int ); + void setPageStep( int ); + int value() const; + +public slots: + virtual void setValue( int ); + void addStep(); + void subtractStep(); + void addLine(); + void subtractLine(); + +signals: + void valueChanged( int value ); + void sliderPressed(); + void sliderMoved( int value ); + void sliderReleased(); + +protected: + void resizeEvent( TQResizeEvent * ); + void paintEvent( TQPaintEvent * ); + + void keyPressEvent( TQKeyEvent * ); + void mousePressEvent( TQMouseEvent * ); + void mouseReleaseEvent( TQMouseEvent * ); + void mouseMoveEvent( TQMouseEvent * ); +#ifndef TQT_NO_WHEELEVENT + void wheelEvent( TQWheelEvent * ); +#endif + void focusInEvent( TQFocusEvent *e ); + void focusOutEvent( TQFocusEvent *e ); + + void styleChange( TQStyle& ); + + void valueChange(); + void rangeChange(); + +private slots: + void repeatTimeout(); + +private: + enum State { Idle, Dragging, TimingUp, TimingDown }; + + void init(); + int positionFromValue( int ) const; + int valueFromPosition( int ) const; + void moveSlider( int ); + void reallyMoveSlider( int ); + void resetState(); + int available() const; + int goodPart( const TQPoint& ) const; + void initTicks(); + + TQSliderPrivate *d; + TQTimer *timer; + TQCOORD sliderPos; + int sliderVal; + TQCOORD clickOffset; + State state; + bool track; + TQCOORD tickOffset; + TickSetting ticks; + int tickInt; + Orientation orient; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQSlider( const TQSlider & ); + TQSlider &operator=( const TQSlider & ); +#endif +}; + +inline bool TQSlider::tracking() const +{ + return track; +} + +inline TQSlider::Orientation TQSlider::orientation() const +{ + return orient; +} + +inline int TQSlider::sliderStart() const +{ + return sliderPos; +} + +inline void TQSlider::setSizePolicy( TQSizePolicy::SizeType hor, TQSizePolicy::SizeType ver, bool hfw ) +{ + TQWidget::setSizePolicy( hor, ver, hfw ); +} + +#endif // TQT_NO_SLIDER + +#endif // TQSLIDER_H diff --git a/src/widgets/tqspinbox.cpp b/src/widgets/tqspinbox.cpp new file mode 100644 index 000000000..ff336035d --- /dev/null +++ b/src/widgets/tqspinbox.cpp @@ -0,0 +1,1116 @@ +/**************************************************************************** +** +** Implementation of TQSpinBox widget class +** +** Created : 970101 +** +** 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 "tqspinbox.h" +#ifndef TQT_NO_SPINBOX + +#include "ntqcursor.h" +#include "tqpushbutton.h" +#include "tqpainter.h" +#include "tqbitmap.h" +#include "tqlineedit.h" +#include "ntqvalidator.h" +#include "tqpixmapcache.h" +#include "ntqapplication.h" +#include "tqstyle.h" +#if defined(QT_ACCESSIBILITY_SUPPORT) +#include "ntqaccessible.h" +#endif + +static bool sumOutOfRange(int current, int add) +{ + if (add > 0 && INT_MAX - add < current) { + return true; + } + if (add < 0 && INT_MIN - add > current) { + return true; + } + return false; +} + +class TQSpinBoxPrivate +{ +public: + TQSpinBoxPrivate() {} + TQSpinWidget* controls; + uint selreq : 1; +}; + +class TQSpinBoxValidator : public TQIntValidator +{ +public: + TQSpinBoxValidator( TQSpinBox *sb, const char *name ) + : TQIntValidator( sb, name ), spinBox( sb ) { } + + virtual State validate( TQString& str, int& pos ) const; + +private: + TQSpinBox *spinBox; +}; + +TQValidator::State TQSpinBoxValidator::validate( TQString& str, int& pos ) const +{ + TQString pref = spinBox->prefix(); + TQString suff = spinBox->suffix(); + TQString suffStriped = suff.stripWhiteSpace(); + uint overhead = pref.length() + suff.length(); + State state = Invalid; + + ((TQIntValidator *) this)->setRange( spinBox->minValue(), + spinBox->maxValue() ); + if ( overhead == 0 ) { + state = TQIntValidator::validate( str, pos ); + } else { + bool stripedVersion = FALSE; + if ( str.length() >= overhead && str.startsWith(pref) + && (str.endsWith(suff) + || (stripedVersion = str.endsWith(suffStriped))) ) { + if ( stripedVersion ) + overhead = pref.length() + suffStriped.length(); + TQString core = str.mid( pref.length(), str.length() - overhead ); + int corePos = pos - pref.length(); + state = TQIntValidator::validate( core, corePos ); + pos = corePos + pref.length(); + str.replace( pref.length(), str.length() - overhead, core ); + } else { + state = TQIntValidator::validate( str, pos ); + if ( state == Invalid ) { + // stripWhiteSpace(), cf. TQSpinBox::interpretText() + TQString special = spinBox->specialValueText().stripWhiteSpace(); + TQString candidate = str.stripWhiteSpace(); + + if ( special.startsWith(candidate) ) { + if ( candidate.length() == special.length() ) { + state = Acceptable; + } else { + state = Intermediate; + } + } + } + } + } + return state; +} + +/*! + \class TQSpinBox + \brief The TQSpinBox class provides a spin box widget (spin button). + + \ingroup basic + \mainclass + + TQSpinBox allows the user to choose a value either by clicking the + up/down buttons to increase/decrease the value currently displayed + or by typing the value directly into the spin box. If the value is + entered directly into the spin box, Enter (or Return) must be + pressed to apply the new value. The value is usually an integer. + + Every time the value changes TQSpinBox emits the valueChanged() + signal. The current value can be fetched with value() and set + with setValue(). + + The spin box keeps the value within a numeric range, and to + multiples of the lineStep() size (see TQRangeControl for details). + Clicking the up/down buttons or using the keyboard accelerator's + up and down arrows will increase or decrease the current value in + steps of size lineStep(). The minimum and maximum value and the + step size can be set using one of the constructors, and can be + changed later with setMinValue(), setMaxValue() and setLineStep(). + + Most spin boxes are directional, but TQSpinBox can also operate as + a circular spin box, i.e. if the range is 0-99 and the current + value is 99, clicking "up" will give 0. Use setWrapping() if you + want circular behavior. + + The displayed value can be prepended and appended with arbitrary + strings indicating, for example, currency or the unit of + measurement. See setPrefix() and setSuffix(). The text in the spin + box is retrieved with text() (which includes any prefix() and + suffix()), or with cleanText() (which has no prefix(), no suffix() + and no leading or trailing whitespace). currentValueText() returns + the spin box's current value as text. + + Normally the spin box displays up and down arrows in the buttons. + You can use setButtonSymbols() to change the display to show + + and - symbols if you prefer. In either case the up + and down arrow keys work as expected. + + It is often desirable to give the user a special (often default) + choice in addition to the range of numeric values. See + setSpecialValueText() for how to do this with TQSpinBox. + + The default \l TQWidget::focusPolicy() is StrongFocus. + + If using prefix(), suffix() and specialValueText() don't provide + enough control, you can ignore them and subclass TQSpinBox instead. + + TQSpinBox can easily be subclassed to allow the user to input + things other than an integer value as long as the allowed input + can be mapped to a range of integers. This can be done by + overriding the virtual functions mapValueToText() and + mapTextToValue(), and setting another suitable validator using + setValidator(). + + For example, these functions could be changed so that the user + provided values from 0.0 to 10.0, or -1 to signify 'Auto', while + the range of integers used inside the program would be -1 to 100: + + \code + class MySpinBox : public TQSpinBox + { + TQ_OBJECT + public: + ... + + TQString mapValueToText( int value ) + { + if ( value == -1 ) // special case + return TQString( "Auto" ); + + return TQString( "%1.%2" ) // 0.0 to 10.0 + .arg( value / 10 ).arg( value % 10 ); + } + + int mapTextToValue( bool *ok ) + { + if ( text() == "Auto" ) // special case + return -1; + + return (int) ( 10 * text().toFloat() ); // 0 to 100 + } + }; + \endcode + + + + \sa TQScrollBar TQSlider + \link guibooks.html#fowler GUI Design Handbook: Spin Box \endlink +*/ + + +/*! + Constructs a spin box with the default TQRangeControl range and + step values. It is called \a name and has parent \a parent. + + \sa minValue(), maxValue(), setRange(), lineStep(), setSteps() +*/ + +TQSpinBox::TQSpinBox( TQWidget * parent , const char *name ) + : TQWidget( parent, name, WNoAutoErase ), + TQRangeControl() +{ + initSpinBox(); +} + + +/*! + Constructs a spin box that allows values from \a minValue to \a + maxValue inclusive, with step amount \a step. The value is + initially set to \a minValue. + + The spin box is called \a name and has parent \a parent. + + \sa minValue(), maxValue(), setRange(), lineStep(), setSteps() +*/ + +TQSpinBox::TQSpinBox( int minValue, int maxValue, int step, TQWidget* parent, + const char* name ) + : TQWidget( parent, name, WNoAutoErase ), + TQRangeControl( minValue, maxValue, step, step, minValue ) +{ + initSpinBox(); +} + +/* + \internal Initialization. +*/ + +void TQSpinBox::initSpinBox() +{ + d = new TQSpinBoxPrivate; + + d->controls = new TQSpinWidget( this, "controls" ); + connect( d->controls, TQ_SIGNAL( stepUpPressed() ), TQ_SLOT( stepUp() ) ); + connect( d->controls, TQ_SIGNAL( stepDownPressed() ), TQ_SLOT( stepDown() ) ); + + wrap = FALSE; + edited = FALSE; + d->selreq = FALSE; + + validate = new TQSpinBoxValidator( this, "validator" ); + vi = new TQLineEdit( this, "qt_spinbox_edit" ); + d->controls->setEditWidget( vi ); + vi->setValidator( validate ); + vi->installEventFilter( this ); + vi->setFrame( FALSE ); + setFocusProxy( vi ); + + setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed ) ); + setBackgroundMode( PaletteBackground, PaletteBase ); + + updateDisplay(); + + connect( vi, TQ_SIGNAL(textChanged(const TQString&)), TQ_SLOT(textChanged()) ); +} + +/*! + Destroys the spin box, freeing all memory and other resources. +*/ + +TQSpinBox::~TQSpinBox() +{ + delete d; +} + + +/*! + \property TQSpinBox::text + \brief the spin box's text, including any prefix() and suffix() + + There is no default text. + + \sa value() +*/ + +TQString TQSpinBox::text() const +{ + return vi->text(); +} + + + +/*! + \property TQSpinBox::cleanText + \brief the spin box's text with no prefix(), suffix() or leading + or trailing whitespace. + + \sa text, prefix, suffix +*/ + +TQString TQSpinBox::cleanText() const +{ + TQString s = TQString(text()).stripWhiteSpace(); + if ( !prefix().isEmpty() ) { + TQString px = TQString(prefix()).stripWhiteSpace(); + int len = px.length(); + if ( len && s.left(len) == px ) // Remove _only_ if it is the prefix + s.remove( (uint)0, len ); + } + if ( !suffix().isEmpty() ) { + TQString sx = TQString(suffix()).stripWhiteSpace(); + int len = sx.length(); + if ( len && s.right(len) == sx ) // Remove _only_ if it is the suffix + s.truncate( s.length() - len ); + } + return s.stripWhiteSpace(); +} + + +/*! + \property TQSpinBox::specialValueText + \brief the special-value text + + If set, the spin box will display this text instead of a numeric + value whenever the current value is equal to minVal(). Typical use + is to indicate that this choice has a special (default) meaning. + + For example, if your spin box allows the user to choose the margin + width in a print dialog and your application is able to + automatically choose a good margin width, you can set up the spin + box like this: + \code + TQSpinBox marginBox( -1, 20, 1, parent, "marginBox" ); + marginBox->setSuffix( " mm" ); + marginBox->setSpecialValueText( "Auto" ); + \endcode + The user will then be able to choose a margin width from 0-20 + millimeters or select "Auto" to leave it to the application to + choose. Your code must then interpret the spin box value of -1 as + the user requesting automatic margin width. + + All values are displayed with the prefix() and suffix() (if set), + \e except for the special value, which only shows the special + value text. + + To turn off the special-value text display, call this function + with an empty string. The default is no special-value text, i.e. + the numeric value is shown as usual. + + If no special-value text is set, specialValueText() returns + TQString::null. +*/ + +void TQSpinBox::setSpecialValueText( const TQString &text ) +{ + specText = text; + updateDisplay(); +} + + +TQString TQSpinBox::specialValueText() const +{ + if ( specText.isEmpty() ) + return TQString::null; + else + return specText; +} + + +/*! + \property TQSpinBox::prefix + \brief the spin box's prefix + + The prefix is prepended to the start of the displayed value. + Typical use is to display a unit of measurement or a currency + symbol. For example: + + \code + sb->setPrefix( "$" ); + \endcode + + To turn off the prefix display, set this property to an empty + string. The default is no prefix. The prefix is not displayed for + the minValue() if specialValueText() is not empty. + + If no prefix is set, prefix() returns TQString::null. + + \sa suffix() +*/ + +void TQSpinBox::setPrefix( const TQString &text ) +{ + pfix = text; + updateDisplay(); +} + + +TQString TQSpinBox::prefix() const +{ + if ( pfix.isEmpty() ) + return TQString::null; + else + return pfix; +} + + +/*! + \property TQSpinBox::suffix + \brief the suffix of the spin box + + The suffix is appended to the end of the displayed value. Typical + use is to display a unit of measurement or a currency symbol. For + example: + + \code + sb->setSuffix( " km" ); + \endcode + + To turn off the suffix display, set this property to an empty + string. The default is no suffix. The suffix is not displayed for + the minValue() if specialValueText() is not empty. + + If no suffix is set, suffix() returns a TQString::null. + + \sa prefix() +*/ + +void TQSpinBox::setSuffix( const TQString &text ) +{ + sfix = text; + updateDisplay(); +} + +TQString TQSpinBox::suffix() const +{ + if ( sfix.isEmpty() ) + return TQString::null; + else + return sfix; +} + + +/*! + \property TQSpinBox::wrapping + \brief whether it is possible to step the value from the highest + value to the lowest value and vice versa + + By default, wrapping is turned off. + + If you have a range of 0..100 and wrapping is off when the user + reaches 100 and presses the Up Arrow nothing will happen; but if + wrapping is on the value will change from 100 to 0, then to 1, + etc. When wrapping is on, navigating past the highest value takes + you to the lowest and vice versa. + + \sa minValue, maxValue, setRange() +*/ + +void TQSpinBox::setWrapping( bool on ) +{ + wrap = on; + updateDisplay(); +} + +bool TQSpinBox::wrapping() const +{ + return wrap; +} + +/*! + \reimp +*/ +TQSize TQSpinBox::sizeHint() const +{ + constPolish(); + TQSize sz = vi->sizeHint(); + int h = sz.height(); + TQFontMetrics fm( font() ); + int w = 35; + int wx = fm.width( ' ' )*2; + TQString s; + s = prefix() + ( (TQSpinBox*)this )->mapValueToText( minValue() ) + suffix(); + w = TQMAX( w, fm.width( s ) + wx); + s = prefix() + ( (TQSpinBox*)this )->mapValueToText( maxValue() ) + suffix(); + w = TQMAX(w, fm.width( s ) + wx ); + if ( !specialValueText().isEmpty() ) { + s = specialValueText(); + w = TQMAX( w, fm.width( s ) + wx ); + } + return style().sizeFromContents(TQStyle::CT_SpinBox, this, + TQSize( w + d->controls->downRect().width(), + h + style().pixelMetric( TQStyle::PM_DefaultFrameWidth ) * 2). + expandedTo( TQApplication::globalStrut() )); +} + + +/*! + \reimp +*/ +TQSize TQSpinBox::minimumSizeHint() const +{ + int w = vi->minimumSizeHint().width() + d->controls->downRect().width(); + int h = TQMAX( vi->minimumSizeHint().height(), d->controls->minimumSizeHint().height() ); + return TQSize( w, h ); +} + +// Does the layout of the lineedit and the buttons + +void TQSpinBox::arrangeWidgets() +{ + d->controls->arrange(); +} + +/*! + \property TQSpinBox::value + \brief the value of the spin box + + \sa TQRangeControl::setValue() +*/ + +void TQSpinBox::setValue( int value ) +{ + edited = FALSE; // we ignore anything entered and not yet interpreted + TQRangeControl::setValue( value ); + updateDisplay(); +} + +int TQSpinBox::value() const +{ + TQSpinBox * that = (TQSpinBox *) this; + if ( edited ) { + that->edited = FALSE; // avoid recursion + that->interpretText(); + } + return TQRangeControl::value(); +} + + +/*! + Increases the spin box's value by one lineStep(), wrapping as + necessary if wrapping() is TRUE. This is the same as clicking on + the pointing-up button and can be used for keyboard accelerators, + for example. + + \sa stepDown(), addLine(), lineStep(), setSteps(), setValue(), value() +*/ + +void TQSpinBox::stepUp() +{ + if ( edited ) + interpretText(); + if ( wrapping() && ( value()+lineStep() > maxValue() || sumOutOfRange(value(), lineStep() ) ) ) { + setValue( minValue() ); + } else { + addLine(); + } +} + + +/*! + Decreases the spin box's value one lineStep(), wrapping as + necessary if wrapping() is TRUE. This is the same as clicking on + the pointing-down button and can be used for keyboard + accelerators, for example. + + \sa stepUp(), subtractLine(), lineStep(), setSteps(), setValue(), value() +*/ + +void TQSpinBox::stepDown() +{ + if ( edited ) + interpretText(); + if ( wrapping() && ( value()-lineStep() < minValue() || sumOutOfRange(value(), -lineStep() ) ) ) { + setValue( maxValue() ); + } else { + subtractLine(); + } +} + + +/*! + \fn void TQSpinBox::valueChanged( int value ) + + This signal is emitted every time the value of the spin box + changes; the new value is passed in \a value. This signal will be + emitted as a result of a call to setValue(), or because the user + changed the value by using a keyboard accelerator or mouse click, + etc. + + Note that the valueChanged() signal is emitted \e every time, not + just for the "last" step; i.e. if the user clicks "up" three + times, this signal is emitted three times. + + \sa value() +*/ + + +/*! + \fn void TQSpinBox::valueChanged( const TQString& valueText ) + + \overload + + This signal is emitted whenever the valueChanged( int ) signal is + emitted, i.e. every time the value of the spin box changes + (whatever the cause, e.g. by setValue(), by a keyboard + accelerator, by mouse clicks, etc.). + + The \a valueText parameter is the same string that is displayed in + the edit field of the spin box. + + \sa value() prefix() suffix() specialValueText() +*/ + + + +/*! + Intercepts and handles the events coming to the embedded TQLineEdit + that have special meaning for the TQSpinBox. The object is passed + as \a o and the event is passed as \a ev. +*/ + +bool TQSpinBox::eventFilter( TQObject* o, TQEvent* ev ) +{ + if (o != vi) + return TQWidget::eventFilter(o,ev); + + if ( ev->type() == TQEvent::KeyPress ) { + TQKeyEvent* k = (TQKeyEvent*)ev; + + bool retval = FALSE; // workaround for MSVC++ optimization bug + if( (k->key() == Key_Tab) || (k->key() == Key_BackTab) ){ + if ( k->state() & TQt::ControlButton ) + return FALSE; + if ( edited ) + interpretText(); + tqApp->sendEvent( this, ev ); + retval = TRUE; + } if ( k->key() == Key_Up ) { + stepUp(); + retval = TRUE; + } else if ( k->key() == Key_Down ) { + stepDown(); + retval = TRUE; + } else if ( k->key() == Key_Enter || k->key() == Key_Return ) { + interpretText(); + return FALSE; + } + if ( retval ) + return retval; + } else if ( ev->type() == TQEvent::FocusOut || ev->type() == TQEvent::Hide ) { + if ( edited ) { + interpretText(); + } + return FALSE; + } + return FALSE; +} + +/*! + \reimp + */ +void TQSpinBox::setEnabled( bool enabled ) +{ + TQWidget::setEnabled( enabled ); + updateDisplay(); +} + +/*! + \reimp +*/ +void TQSpinBox::leaveEvent( TQEvent* ) +{ +} + + +/*! + \reimp +*/ +void TQSpinBox::resizeEvent( TQResizeEvent* ) +{ + d->controls->resize( width(), height() ); +} + +/*! + \reimp +*/ +#ifndef TQT_NO_WHEELEVENT +void TQSpinBox::wheelEvent( TQWheelEvent * e ) +{ + e->accept(); + static float offset = 0; + static TQSpinBox* offset_owner = 0; + if (offset_owner != this) { + offset_owner = this; + offset = 0; + } + offset += -e->delta()/120; + if (TQABS(offset) < 1) + return; + int ioff = int(offset); + int i; + for (i=0; i 0 ? stepDown() : stepUp(); + offset -= ioff; +} +#endif + +/*! + This virtual function is called by TQRangeControl whenever the + value has changed. The TQSpinBox reimplementation updates the + display and emits the valueChanged() signals; if you need + additional processing, either reimplement this or connect to one + of the valueChanged() signals. +*/ + +void TQSpinBox::valueChange() +{ + d->selreq = hasFocus(); + updateDisplay(); + d->selreq = FALSE; + emit valueChanged( value() ); + emit valueChanged( currentValueText() ); +#if defined(QT_ACCESSIBILITY_SUPPORT) + TQAccessible::updateAccessibility( this, 0, TQAccessible::ValueChanged ); +#endif +} + + +/*! + This virtual function is called by TQRangeControl whenever the + range has changed. It adjusts the default validator and updates + the display; if you need additional processing, you can + reimplement this function. +*/ + +void TQSpinBox::rangeChange() +{ + updateDisplay(); +} + + +/*! + Sets the validator to \a v. The validator controls what keyboard + input is accepted when the user is editing in the value field. The + default is to use a suitable TQIntValidator. + + Use setValidator(0) to turn off input validation (entered input + will still be kept within the spin box's range). +*/ + +void TQSpinBox::setValidator( const TQValidator* v ) +{ + if ( vi ) + vi->setValidator( v ); +} + + +/*! + Returns the validator that constrains editing for this spin box if + there is any; otherwise returns 0. + + \sa setValidator() TQValidator +*/ + +const TQValidator * TQSpinBox::validator() const +{ + return vi ? vi->validator() : 0; +} + +/*! + Updates the contents of the embedded TQLineEdit to reflect the + current value using mapValueToText(). Also enables/disables the + up/down push buttons accordingly. + + \sa mapValueToText() +*/ +void TQSpinBox::updateDisplay() +{ + vi->setUpdatesEnabled( FALSE ); + vi->setText( currentValueText() ); + if ( d->selreq && isVisible() && ( hasFocus() || vi->hasFocus() ) ) { + selectAll(); + } else { + if ( !suffix().isEmpty() && vi->text().endsWith(suffix()) ) + vi->setCursorPosition( vi->text().length() - suffix().length() ); + } + vi->setUpdatesEnabled( TRUE ); + vi->repaint( FALSE ); // immediate repaint needed for some reason + edited = FALSE; + + bool upEnabled = isEnabled() && ( wrapping() || value() < maxValue() ); + bool downEnabled = isEnabled() && ( wrapping() || value() > minValue() ); + + d->controls->setUpEnabled( upEnabled ); + d->controls->setDownEnabled( downEnabled ); + vi->setEnabled( isEnabled() ); + repaint( FALSE ); +} + + +/*! + TQSpinBox calls this after the user has manually edited the + contents of the spin box (i.e. by typing in the embedded + TQLineEdit, rather than using the up/down buttons/keys). + + The default implementation of this function interprets the new + text using mapTextToValue(). If mapTextToValue() is successful, it + changes the spin box's value; if not, the value is left unchanged. + + \sa editor() +*/ + +void TQSpinBox::interpretText() +{ + bool ok = TRUE; + bool done = FALSE; + int newVal = 0; + if ( !specialValueText().isEmpty() ) { + TQString s = text().stripWhiteSpace(); + TQString t = specialValueText().stripWhiteSpace(); + if ( s == t ) { + newVal = minValue(); + done = TRUE; + } + } + if ( !done ) + newVal = mapTextToValue( &ok ); + if ( ok ) + setValue( newVal ); + updateDisplay(); // sometimes redundant +} + + +/*! + Returns the geometry of the "up" button. +*/ + +TQRect TQSpinBox::upRect() const +{ + return d->controls->upRect(); +} + + +/*! + Returns the geometry of the "down" button. +*/ + +TQRect TQSpinBox::downRect() const +{ + return d->controls->downRect(); +} + + +/*! + Returns a pointer to the embedded TQLineEdit. +*/ + +TQLineEdit* TQSpinBox::editor() const +{ + return vi; +} + + +/*! + This slot is called whenever the user edits the spin box's text. +*/ + +void TQSpinBox::textChanged() +{ + edited = TRUE; // this flag is cleared in updateDisplay() +} + + +/*! + This virtual function is used by the spin box whenever it needs to + display value \a v. The default implementation returns a string + containing \a v printed in the standard way. Reimplementations may + return anything. (See the example in the detailed description.) + + Note that TQt does not call this function for specialValueText() + and that neither prefix() nor suffix() are included in the return + value. + + If you reimplement this, you may also need to reimplement + mapTextToValue(). + + \sa updateDisplay(), mapTextToValue() +*/ + +TQString TQSpinBox::mapValueToText( int v ) +{ + TQString s; + s.setNum( v ); + return s; +} + + +/*! + This virtual function is used by the spin box whenever it needs to + interpret text entered by the user as a value. The text is + available as text() and as cleanText(), and this function must + parse it if possible. If \a ok is not 0: if it parses the text + successfully, \a *ok is set to TRUE; otherwise \a *ok is set to + FALSE. + + Subclasses that need to display spin box values in a non-numeric + way need to reimplement this function. + + Note that TQt handles specialValueText() separately; this function + is only concerned with the other values. + + The default implementation tries to interpret the text() as an + integer in the standard way and returns the integer value. + + \sa interpretText(), mapValueToText() +*/ + +int TQSpinBox::mapTextToValue( bool* ok ) +{ + TQString s = text(); + int newVal = s.toInt( ok ); + if ( !(*ok) && !( !prefix() && !suffix() ) ) {// Try removing any pre/suffix + s = cleanText(); + newVal = s.toInt( ok ); + } + return newVal; +} + + +/*! + Returns the full text calculated from the current value, including + any prefix and suffix. If there is special value text and the + value is minValue() the specialValueText() is returned. +*/ + +TQString TQSpinBox::currentValueText() +{ + TQString s; + if ( (value() == minValue()) && !specialValueText().isEmpty() ) { + s = specialValueText(); + } else { + s = prefix(); + s.append( mapValueToText( value() ) ); + s.append( suffix() ); + } + return s; +} + +/*! + \reimp +*/ + +void TQSpinBox::styleChange( TQStyle& old ) +{ + arrangeWidgets(); + TQWidget::styleChange( old ); +} + + +/*! + \enum TQSpinBox::ButtonSymbols + + This enum type determines what the buttons in a spin box show. + + \value UpDownArrows the buttons show little arrows in the classic + style. + + \value PlusMinus the buttons show + and - symbols. + + \sa TQSpinBox::buttonSymbols +*/ + +/*! + \property TQSpinBox::buttonSymbols + + \brief the current button symbol mode + + The possible values can be either \c UpDownArrows or \c PlusMinus. + The default is \c UpDownArrows. + + \sa ButtonSymbols +*/ + +void TQSpinBox::setButtonSymbols( ButtonSymbols newSymbols ) +{ + if ( buttonSymbols() == newSymbols ) + return; + + switch ( newSymbols ) { + case UpDownArrows: + d->controls->setButtonSymbols( TQSpinWidget::UpDownArrows ); + break; + case PlusMinus: + d->controls->setButtonSymbols( TQSpinWidget::PlusMinus ); + break; + } + // repaint( FALSE ); +} + +TQSpinBox::ButtonSymbols TQSpinBox::buttonSymbols() const +{ + switch( d->controls->buttonSymbols() ) { + case TQSpinWidget::UpDownArrows: + return UpDownArrows; + case TQSpinWidget::PlusMinus: + return PlusMinus; + } + return UpDownArrows; +} + +/*! + \property TQSpinBox::minValue + + \brief the minimum value of the spin box + + When setting this property, \l TQSpinBox::maxValue is adjusted, if + necessary, to ensure that the range remains valid. + + \sa setRange() setSpecialValueText() +*/ + +int TQSpinBox::minValue() const +{ + return TQRangeControl::minValue(); +} + +void TQSpinBox::setMinValue( int minVal ) +{ + TQRangeControl::setMinValue( minVal ); +} + +/*! + \property TQSpinBox::maxValue + \brief the maximum value of the spin box + + When setting this property, \l TQSpinBox::minValue is adjusted, if + necessary, to ensure that the range remains valid. + + \sa setRange() setSpecialValueText() +*/ + +int TQSpinBox::maxValue() const +{ + return TQRangeControl::maxValue(); +} + +void TQSpinBox::setMaxValue( int maxVal ) +{ + TQRangeControl::setMaxValue( maxVal ); +} + +/*! + \property TQSpinBox::lineStep + \brief the line step + + When the user uses the arrows to change the spin box's value the + value will be incremented/decremented by the amount of the line + step. + + The setLineStep() function calls the virtual stepChange() function + if the new line step is different from the previous setting. + + \sa TQRangeControl::setSteps() setRange() +*/ + +int TQSpinBox::lineStep() const +{ + return TQRangeControl::lineStep(); +} + +void TQSpinBox::setLineStep( int i ) +{ + setSteps( i, pageStep() ); +} + +/*! + Selects all the text in the spin box's editor. +*/ + +void TQSpinBox::selectAll() +{ + int overhead = prefix().length() + suffix().length(); + if ( !overhead || currentValueText() == specialValueText() ) { + vi->selectAll(); + } else { + vi->setSelection( prefix().length(), vi->text().length() - overhead ); + } +} + +#endif diff --git a/src/widgets/tqspinbox.h b/src/widgets/tqspinbox.h new file mode 100644 index 000000000..345857c74 --- /dev/null +++ b/src/widgets/tqspinbox.h @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Definition of TQSpinBox widget class +** +** Created : 970101 +** +** 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 TQSPINBOX_H +#define TQSPINBOX_H + +#ifndef QT_H +#include "tqwidget.h" +#include "ntqrangecontrol.h" +#endif // QT_H + +#ifndef TQT_NO_SPINBOX + +class TQLineEdit; +class TQValidator; +class TQSpinBoxPrivate; + +class TQ_EXPORT TQSpinBox: public TQWidget, public TQRangeControl +{ + TQ_OBJECT + TQ_ENUMS( ButtonSymbols ) + TQ_PROPERTY( TQString text READ text ) + TQ_PROPERTY( TQString prefix READ prefix WRITE setPrefix ) + TQ_PROPERTY( TQString suffix READ suffix WRITE setSuffix ) + TQ_PROPERTY( TQString cleanText READ cleanText ) + TQ_PROPERTY( TQString specialValueText READ specialValueText WRITE setSpecialValueText ) + TQ_PROPERTY( bool wrapping READ wrapping WRITE setWrapping ) + TQ_PROPERTY( ButtonSymbols buttonSymbols READ buttonSymbols WRITE setButtonSymbols ) + TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue ) + TQ_PROPERTY( int minValue READ minValue WRITE setMinValue ) + TQ_PROPERTY( int lineStep READ lineStep WRITE setLineStep ) + TQ_PROPERTY( int value READ value WRITE setValue ) + +public: + TQSpinBox( TQWidget* parent=0, const char* name=0 ); + TQSpinBox( int minValue, int maxValue, int step = 1, + TQWidget* parent=0, const char* name=0 ); + ~TQSpinBox(); + + TQString text() const; + + virtual TQString prefix() const; + virtual TQString suffix() const; + virtual TQString cleanText() const; + + virtual void setSpecialValueText( const TQString &text ); + TQString specialValueText() const; + + virtual void setWrapping( bool on ); + bool wrapping() const; + + enum ButtonSymbols { UpDownArrows, PlusMinus }; + virtual void setButtonSymbols( ButtonSymbols ); + ButtonSymbols buttonSymbols() const; + + virtual void setValidator( const TQValidator* v ); + const TQValidator * validator() const; + + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + + int minValue() const; + int maxValue() const; + void setMinValue( int ); + void setMaxValue( int ); + int lineStep() const; + void setLineStep( int ); + int value() const; + + TQRect upRect() const; + TQRect downRect() const; + +public slots: + virtual void setValue( int value ); + virtual void setPrefix( const TQString &text ); + virtual void setSuffix( const TQString &text ); + virtual void stepUp(); + virtual void stepDown(); + virtual void setEnabled( bool enabled ); + virtual void selectAll(); + +signals: + void valueChanged( int value ); + void valueChanged( const TQString &valueText ); + +protected: + virtual TQString mapValueToText( int value ); + virtual int mapTextToValue( bool* ok ); + TQString currentValueText(); + + virtual void updateDisplay(); + virtual void interpretText(); + + TQLineEdit* editor() const; + + virtual void valueChange(); + virtual void rangeChange(); + + bool eventFilter( TQObject* obj, TQEvent* ev ); + void resizeEvent( TQResizeEvent* ev ); +#ifndef TQT_NO_WHEELEVENT + void wheelEvent( TQWheelEvent * ); +#endif + void leaveEvent( TQEvent* ); + + void styleChange( TQStyle& ); + +protected slots: + void textChanged(); + +private: + void initSpinBox(); + TQSpinBoxPrivate* d; + TQLineEdit* vi; + TQValidator* validate; + TQString pfix; + TQString sfix; + TQString specText; + + uint wrap : 1; + uint edited : 1; + + void arrangeWidgets(); + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQSpinBox( const TQSpinBox& ); + TQSpinBox& operator=( const TQSpinBox& ); +#endif + +}; + +#endif // TQT_NO_SPINBOX + +#endif // TQSPINBOX_H diff --git a/src/widgets/tqspinwidget.cpp b/src/widgets/tqspinwidget.cpp new file mode 100644 index 000000000..a66e90d1d --- /dev/null +++ b/src/widgets/tqspinwidget.cpp @@ -0,0 +1,467 @@ +/**************************************************************************** +** +** Implementation of TQSpinWidget 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 "ntqrangecontrol.h" + +#ifndef TQT_NO_SPINWIDGET + +#include "tqrect.h" +#include "tqtimer.h" +#include "tqstyle.h" +#include "tqpainter.h" + +class TQSpinWidgetPrivate +{ +public: + TQSpinWidgetPrivate() + : upEnabled( TRUE ), + downEnabled( TRUE ), + theButton( 0 ), + buttonDown( 0 ), + timerUp( 0 ), + bsyms( TQSpinWidget::UpDownArrows ), + ed ( 0 ) {} + uint upEnabled :1; + uint downEnabled :1; + uint theButton :2; + uint buttonDown :2; + uint timerUp : 1; + TQRect up; + TQRect down; + TQTimer auRepTimer; + TQSpinWidget::ButtonSymbols bsyms; + TQWidget *ed; + void startTimer( int msec ) { auRepTimer.start( msec, TRUE ); } + void startTimer( bool up, int msec ) { timerUp = up; startTimer( msec ); } + void stopTimer() { auRepTimer.stop(); } +}; + +/*! + + \class TQSpinWidget tqspinwidget.h + \brief The TQSpinWidget class is an internal range control related class. + + \internal + + Constructs an empty range control widget with parent \a parent + called \a name. + +*/ + +TQSpinWidget::TQSpinWidget( TQWidget* parent, const char* name ) + : TQWidget( parent, name ) +{ + d = new TQSpinWidgetPrivate(); + connect( &d->auRepTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( timerDone() ) ); + setFocusPolicy( StrongFocus ); + + arrange(); + updateDisplay(); +} + + +/*! Destroys the object and frees any allocated resources. + +*/ + +TQSpinWidget::~TQSpinWidget() +{ + delete d; +} + +/*! */ +TQWidget * TQSpinWidget::editWidget() +{ + return d->ed; +} + +/*! + Sets the editing widget to \a w. +*/ +void TQSpinWidget::setEditWidget( TQWidget * w ) +{ + if ( w ) { + if (w->parentWidget() != this) + w->reparent( this, TQPoint( 0, 0 ) ); + setFocusProxy( w ); + } + d->ed = w; + arrange(); + updateDisplay(); +} + +/*! \reimp + +*/ + +void TQSpinWidget::mousePressEvent( TQMouseEvent *e ) +{ + if ( e->button() != LeftButton ) { + d->stopTimer(); + d->buttonDown = 0; + d->theButton = 0; + repaint( d->down.unite( d->up ), FALSE ); + return; + } + + uint oldButtonDown = d->buttonDown; + + if ( d->down.contains( e->pos() ) && d->downEnabled ) + d->buttonDown = 1; + else if ( d->up.contains( e->pos() ) && d->upEnabled ) + d->buttonDown = 2; + else + d->buttonDown = 0; + + d->theButton = d->buttonDown; + if ( oldButtonDown != d->buttonDown ) { + if ( !d->buttonDown ) { + repaint( d->down.unite( d->up ), FALSE ); + } else if ( d->buttonDown & 1 ) { + repaint( d->down, FALSE ); + stepDown(); + d->startTimer( FALSE, 300 ); + } else if ( d->buttonDown & 2 ) { + repaint( d->up, FALSE ); + stepUp(); + d->startTimer( TRUE, 300 ); + } + } +} + +/*! + +*/ + +void TQSpinWidget::arrange() +{ + d->up = TQStyle::visualRect( style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, + TQStyle::SC_SpinWidgetUp ), this ); + d->down = TQStyle::visualRect( style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, + TQStyle::SC_SpinWidgetDown ), this ); + if ( d->ed ) { + TQRect r = TQStyle::visualRect( style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, + TQStyle::SC_SpinWidgetEditField ), this ); + d->ed->setGeometry( r ); + } +} + +/*! + +*/ + +void TQSpinWidget::stepUp() +{ + emit stepUpPressed(); +} + +void TQSpinWidget::resizeEvent( TQResizeEvent* ) +{ + arrange(); +} + +/*! + +*/ + +void TQSpinWidget::stepDown() +{ + emit stepDownPressed(); +} + + +void TQSpinWidget::timerDone() +{ + // we use a double timer to make it possible for users to do + // something with 0-timer on valueChanged. + TQTimer::singleShot( 1, this, TQ_SLOT( timerDoneEx() ) ); +} + +void TQSpinWidget::timerDoneEx() +{ + if ( !d->buttonDown ) + return; + if ( d->timerUp ) + stepUp(); + else + stepDown(); + d->startTimer( 100 ); +} + + +void TQSpinWidget::windowActivationChange( bool oldActive ) +{ + //was active, but lost focus + if ( oldActive && d->buttonDown ) { + d->stopTimer(); + d->buttonDown = 0; + d->theButton = 0; + } + TQWidget::windowActivationChange( oldActive ); +} + + + +/*! + The event is passed in \a e. +*/ + +void TQSpinWidget::mouseReleaseEvent( TQMouseEvent *e ) +{ + if ( e->button() != LeftButton ) + return; + + uint oldButtonDown = d->theButton; + d->theButton = 0; + if ( oldButtonDown != d->theButton ) { + if ( oldButtonDown & 1 ) + repaint( d->down, FALSE ); + else if ( oldButtonDown & 2 ) + repaint( d->up, FALSE ); + } + d->stopTimer(); + d->buttonDown = 0; +} + + +/*! + The event is passed in \a e. +*/ + +void TQSpinWidget::mouseMoveEvent( TQMouseEvent *e ) +{ + if ( !(e->state() & LeftButton ) ) + return; + + uint oldButtonDown = d->theButton; + if ( oldButtonDown & 1 && !d->down.contains( e->pos() ) ) { + d->stopTimer(); + d->theButton = 0; + repaint( d->down, FALSE ); + } else if ( oldButtonDown & 2 && !d->up.contains( e->pos() ) ) { + d->stopTimer(); + d->theButton = 0; + repaint( d->up, FALSE ); + } else if ( !oldButtonDown && d->up.contains( e->pos() ) && d->buttonDown & 2 ) { + d->startTimer( 500 ); + d->theButton = 2; + repaint( d->up, FALSE ); + } else if ( !oldButtonDown && d->down.contains( e->pos() ) && d->buttonDown & 1 ) { + d->startTimer( 500 ); + d->theButton = 1; + repaint( d->down, FALSE ); + } +} + + +/*! + The event is passed in \a e. +*/ +#ifndef TQT_NO_WHEELEVENT +void TQSpinWidget::wheelEvent( TQWheelEvent *e ) +{ + e->accept(); + static float offset = 0; + static TQSpinWidget* offset_owner = 0; + if ( offset_owner != this ) { + offset_owner = this; + offset = 0; + } + offset += -e->delta()/120; + if ( TQABS( offset ) < 1 ) + return; + int ioff = int(offset); + int i; + for( i=0; i < TQABS( ioff ); i++ ) + offset > 0 ? stepDown() : stepUp(); + offset -= ioff; +} +#endif + +/*! + +*/ +void TQSpinWidget::paintEvent( TQPaintEvent * ) +{ + TQPainter p( this ); + + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) + flags |= TQStyle::Style_Enabled; + if (hasMouse()) + flags |= TQStyle::Style_MouseOver; + if (hasFocus() || (focusProxy() && focusProxy()->hasFocus())) + flags |= TQStyle::Style_HasFocus; + + TQStyle::SCFlags active; + if ( d->theButton & 1 ) + active = TQStyle::SC_SpinWidgetDown; + else if ( d->theButton & 2 ) + active = TQStyle::SC_SpinWidgetUp; + else + active = TQStyle::SC_None; + + TQRect fr = TQStyle::visualRect( + style().querySubControlMetrics( TQStyle::CC_SpinWidget, this, + TQStyle::SC_SpinWidgetFrame ), this ); + style().drawComplexControl( TQStyle::CC_SpinWidget, &p, this, + fr, colorGroup(), + flags, + (uint)TQStyle::SC_All, + active ); +} + + +/*! + The previous style is passed in \a old. +*/ + +void TQSpinWidget::styleChange( TQStyle& old ) +{ + arrange(); + TQWidget::styleChange( old ); +} + +/*! +*/ + +TQRect TQSpinWidget::upRect() const +{ + return d->up; +} + +/*! +*/ + +TQRect TQSpinWidget::downRect() const +{ + return d->down; +} + +/*! +*/ + +void TQSpinWidget::updateDisplay() +{ + if ( !isEnabled() ) { + d->upEnabled = FALSE; + d->downEnabled = FALSE; + } + if ( d->theButton & 1 && ( d->downEnabled ) == 0 ) { + d->theButton &= ~1; + d->buttonDown &= ~1; + } + + if ( d->theButton & 2 && ( d->upEnabled ) == 0 ) { + d->theButton &= ~2; + d->buttonDown &= ~2; + } + repaint( FALSE ); +} + + +/*! + The previous enabled state is passed in \a old. +*/ + +void TQSpinWidget::enableChanged( bool ) +{ + d->upEnabled = isEnabled(); + d->downEnabled = isEnabled(); + updateDisplay(); +} + + +/*! + Sets up-enabled to \a on. +*/ + +void TQSpinWidget::setUpEnabled( bool on ) +{ + if ( (bool)d->upEnabled != on ) { + d->upEnabled = on; + updateDisplay(); + } +} + +/*! +*/ + +bool TQSpinWidget::isUpEnabled() const +{ + return d->upEnabled; +} + +/*! + Sets down-enabled to \a on. +*/ + +void TQSpinWidget::setDownEnabled( bool on ) +{ + if ( (bool)d->downEnabled != on ) { + d->downEnabled = on; + updateDisplay(); + } +} + +/*! +*/ + +bool TQSpinWidget::isDownEnabled() const +{ + return d->downEnabled; +} + +/*! + Sets the button symbol to \a bs. +*/ + +void TQSpinWidget::setButtonSymbols( ButtonSymbols bs ) +{ + d->bsyms = bs; +} + +/*! +*/ + +TQSpinWidget::ButtonSymbols TQSpinWidget::buttonSymbols() const +{ + return d->bsyms; +} + +#endif diff --git a/src/widgets/tqtextedit.h b/src/widgets/tqtextedit.h index 0b88f8593..f58b91d09 100644 --- a/src/widgets/tqtextedit.h +++ b/src/widgets/tqtextedit.h @@ -42,7 +42,7 @@ #define TQTEXTEDIT_H #ifndef QT_H -#include "ntqscrollview.h" +#include "tqscrollview.h" #include "tqstylesheet.h" #include "tqptrvector.h" #include "tqvaluelist.h" diff --git a/src/widgets/tqtoolbar.cpp b/src/widgets/tqtoolbar.cpp index a94185bec..b8a66fb7a 100644 --- a/src/widgets/tqtoolbar.cpp +++ b/src/widgets/tqtoolbar.cpp @@ -51,7 +51,7 @@ #include "ntqdrawutil.h" #include "tqtoolbutton.h" #include "tqpopupmenu.h" -#include "ntqcombobox.h" +#include "tqcombobox.h" #include "tqtimer.h" #include "tqwidgetlist.h" #include "tqstyle.h" diff --git a/src/widgets/tqtoolbox.cpp b/src/widgets/tqtoolbox.cpp index 7b515b0a7..948acf7d7 100644 --- a/src/widgets/tqtoolbox.cpp +++ b/src/widgets/tqtoolbox.cpp @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/workspace/tqworkspace.cpp b/src/workspace/tqworkspace.cpp index 72319497b..5706ee3e4 100644 --- a/src/workspace/tqworkspace.cpp +++ b/src/workspace/tqworkspace.cpp @@ -59,7 +59,7 @@ #include "tqtooltip.h" #include "tqwmatrix.h" #include "tqimage.h" -#include "ntqscrollbar.h" +#include "tqscrollbar.h" #include "tqstyle.h" #include "tqbitmap.h" -- cgit v1.2.3