From 6f57abfc9cd3acf1d648aee696947ac9216adb71 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 9 Sep 2024 14:57:42 +0900 Subject: Rename remaining ntq[s-z]* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/widgets/ntqsplashscreen.h | 80 --- src/widgets/ntqsplitter.h | 225 ------- src/widgets/qsplashscreen.cpp | 271 -------- src/widgets/qsplitter.cpp | 1372 --------------------------------------- src/widgets/qt_widgets.pri | 12 +- src/widgets/tqdialogbuttons.cpp | 2 +- src/widgets/tqdockarea.cpp | 2 +- src/widgets/tqdockarea.h | 2 +- src/widgets/tqdockwindow.h | 2 +- src/widgets/tqlistview.cpp | 2 +- src/widgets/tqsplashscreen.cpp | 271 ++++++++ src/widgets/tqsplashscreen.h | 80 +++ src/widgets/tqsplitter.cpp | 1372 +++++++++++++++++++++++++++++++++++++++ src/widgets/tqsplitter.h | 225 +++++++ src/widgets/tqwhatsthis.cpp | 2 +- 15 files changed, 1960 insertions(+), 1960 deletions(-) delete mode 100644 src/widgets/ntqsplashscreen.h delete mode 100644 src/widgets/ntqsplitter.h delete mode 100644 src/widgets/qsplashscreen.cpp delete mode 100644 src/widgets/qsplitter.cpp create mode 100644 src/widgets/tqsplashscreen.cpp create mode 100644 src/widgets/tqsplashscreen.h create mode 100644 src/widgets/tqsplitter.cpp create mode 100644 src/widgets/tqsplitter.h (limited to 'src/widgets') diff --git a/src/widgets/ntqsplashscreen.h b/src/widgets/ntqsplashscreen.h deleted file mode 100644 index 99b625f9f..000000000 --- a/src/widgets/ntqsplashscreen.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Definition of TQSplashScreen 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 TQSPLASHSCREEN_H -#define TQSPLASHSCREEN_H - -#ifndef QT_H -#include "tqpixmap.h" -#include "tqwidget.h" -#endif // QT_H - -#ifndef TQT_NO_SPLASHSCREEN -class TQSplashScreenPrivate; - -class TQ_EXPORT TQSplashScreen : public TQWidget -{ - TQ_OBJECT -public: - TQSplashScreen( const TQPixmap &pixmap = TQPixmap(), WFlags f = 0 ); - virtual ~TQSplashScreen(); - - void setPixmap( const TQPixmap &pixmap ); - TQPixmap* pixmap() const; - void finish( TQWidget *w ); - void repaint(); - -public slots: - void message( const TQString &str, int flags = AlignLeft, - const TQColor &color = black ); - void clear(); - -signals: - void messageChanged( const TQString &str ); - -protected: - virtual void drawContents( TQPainter *painter ); - void mousePressEvent( TQMouseEvent * ); - -private: - void drawContents(); - - TQSplashScreenPrivate *d; -}; -#endif //TQT_NO_SPLASHSCREEN -#endif diff --git a/src/widgets/ntqsplitter.h b/src/widgets/ntqsplitter.h deleted file mode 100644 index bd8aef13e..000000000 --- a/src/widgets/ntqsplitter.h +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** -** -** Definition of TQSplitter class -** -** Created : 980105 -** -** 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 TQSPLITTER_H -#define TQSPLITTER_H - -#ifndef QT_H -#include "tqframe.h" -#include "tqvaluelist.h" -#endif // QT_H - -#ifndef TQT_NO_SPLITTER - -#define QT_QSPLITTER_DEFAULT 2 - -class TQSplitterHandle; -class TQSplitterPrivate; -class TQSplitterLayoutStruct; -class TQTextStream; - -class TQSplitterPrivate -{ -public: - TQSplitterPrivate() - : opaque( FALSE ), firstShow( TRUE ), childrenCollapsible( TRUE ), - handleWidth( 0 ) { } - - TQPtrList list; - bool opaque; - bool firstShow; - bool childrenCollapsible; - int handleWidth; -}; - -class TQ_EXPORT TQSplitterLayoutStruct : public TQt -{ -public: - TQCOORD sizer; - uint isHandle; - uint collapsible; - uint resizeMode; - TQWidget *wid; - - TQSplitterLayoutStruct() - : sizer( -1 ), collapsible( QT_QSPLITTER_DEFAULT ) { } - TQCOORD getSizer( Orientation orient ); -}; - -class TQ_EXPORT TQSplitter : public TQFrame -{ - TQ_OBJECT - TQ_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) - TQ_PROPERTY( bool opaqueResize READ opaqueResize WRITE setOpaqueResize ) - TQ_PROPERTY( int handleWidth READ handleWidth WRITE setHandleWidth ) - TQ_PROPERTY( bool childrenCollapsible READ childrenCollapsible WRITE setChildrenCollapsible ) - -public: - // ### TQt 4.0: remove Auto from public API - enum ResizeMode { Stretch, KeepSize, FollowSizeHint, Auto }; - - TQSplitter( TQWidget* parent = 0, const char* name = 0 ); - TQSplitter( Orientation, TQWidget* parent = 0, const char* name = 0 ); - ~TQSplitter(); - - virtual void setOrientation( Orientation ); - Orientation orientation() const { return orient; } - - // ### TQt 4.0: make setChildrenCollapsible() and setCollapsible() virtual - - void setChildrenCollapsible( bool ); - bool childrenCollapsible() const; - - void setCollapsible( TQWidget *w, bool ); - virtual void setResizeMode( TQWidget *w, ResizeMode ); - virtual void setOpaqueResize( bool = TRUE ); - bool opaqueResize() const; - - void moveToFirst( TQWidget * ); - void moveToLast( TQWidget * ); - - void refresh() { recalc( TRUE ); } - TQSize sizeHint() const; - TQSize minimumSizeHint() const; - - TQValueList sizes() const; - void setSizes( TQValueList ); - - int handleWidth() const; - void setHandleWidth( int ); - -protected: - void childEvent( TQChildEvent * ); - - bool event( TQEvent * ); - void resizeEvent( TQResizeEvent * ); - - int idAfter( TQWidget* ) const; - - void moveSplitter( TQCOORD pos, int id ); - virtual void drawSplitter( TQPainter*, TQCOORD x, TQCOORD y, - TQCOORD w, TQCOORD h ); - void styleChange( TQStyle& ); - int adjustPos( int, int ); - virtual void setRubberband( int ); - void getRange( int id, int *, int * ); - -public: //private: - enum { DefaultResizeMode = 3 }; - - void init(); - void recalc( bool update = FALSE ); - void doResize(); - void storeSizes(); - void getRange( int id, int *, int *, int *, int * ); - void addContribution( int, int *, int *, bool ); - int adjustPos( int, int, int *, int *, int *, int * ); - bool collapsible( TQSplitterLayoutStruct * ); - void processChildEvents(); - TQSplitterLayoutStruct *findWidget( TQWidget * ); - TQSplitterLayoutStruct *addWidget( TQWidget *, bool prepend = FALSE ); - void recalcId(); - void doMove( bool backwards, int pos, int id, int delta, bool upLeft, - bool mayCollapse ); - void setGeo( TQWidget *w, int pos, int size, bool splitterMoved ); - int findWidgetJustBeforeOrJustAfter( int id, int delta, int &collapsibleSize ); - void updateHandles(); - - inline TQCOORD pick( const TQPoint &p ) const - { return orient == Horizontal ? p.x() : p.y(); } - inline TQCOORD pick( const TQSize &s ) const - { return orient == Horizontal ? s.width() : s.height(); } - - inline TQCOORD trans( const TQPoint &p ) const - { return orient == Vertical ? p.x() : p.y(); } - inline TQCOORD trans( const TQSize &s ) const - { return orient == Vertical ? s.width() : s.height(); } - - TQSplitterPrivate *d; - - Orientation orient; - friend class TQSplitterHandle; - friend class TQTextStream; - -private: -#if defined(TQ_DISABLE_COPY) - TQSplitter( const TQSplitter & ); - TQSplitter& operator=( const TQSplitter & ); -#endif -}; - -#ifndef TQT_NO_TEXTSTREAM -TQ_EXPORT TQTextStream& operator<<( TQTextStream&, const TQSplitter& ); -TQ_EXPORT TQTextStream& operator>>( TQTextStream&, TQSplitter& ); -#endif - -class TQ_EXPORT TQSplitterHandle : public TQWidget -{ - TQ_OBJECT -public: - TQSplitterHandle( Orientation o, - TQSplitter *parent, const char* name=0 ); - void setOrientation( Orientation o ); - Orientation orientation() const { return orient; } - - bool opaque() const { return s->opaqueResize(); } - - TQSize sizeHint() const; - - int id() const { return myId; } // d->list.at(id())->wid == this - void setId( int i ) { myId = i; } - -protected: - void paintEvent( TQPaintEvent * ); - void mouseMoveEvent( TQMouseEvent * ); - void mousePressEvent( TQMouseEvent * ); - void mouseReleaseEvent( TQMouseEvent * ); - -public: // private: - Orientation orient; - bool opaq; - int myId; - - TQSplitter *s; -}; - -#endif // TQT_NO_SPLITTER - -#endif // TQSPLITTER_H diff --git a/src/widgets/qsplashscreen.cpp b/src/widgets/qsplashscreen.cpp deleted file mode 100644 index b4ed5241e..000000000 --- a/src/widgets/qsplashscreen.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/**************************************************************************** -** -** Definition of TQSplashScreen 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 "ntqsplashscreen.h" - -#ifndef TQT_NO_SPLASHSCREEN - -#include "ntqapplication.h" -#include "tqpainter.h" -#include "tqpixmap.h" - -class TQSplashScreenPrivate -{ -public: - TQPixmap pixmap; - TQString currStatus; - TQColor currColor; - int currAlign; -}; - -/*! - \class TQSplashScreen ntqsplashscreen.h - \brief The TQSplashScreen widget provides a splash screen that can - be shown during application startup. - - \ingroup misc - \mainclass - - A splash screen is a widget that is usually displayed when an - application is being started. Splash screens are often used for - applications that have long start up times (e.g. database or - networking applications that take time to establish connections) to - provide the user with feedback that the application is loading. - - The splash screen appears centered on the screen. It may be useful to add - the \c WStyle_StaysOnTop if you desire to keep above all the windows in the - GUI. - - Some X11 window managers do not support the "stays on top" flag. A - solution is to set up a timer that periodically calls raise() on - the splash screen to simulate the "stays on top" effect. - - The most common usage is to show a splash screen before the main - widget is displayed on the screen. This is illustrated in the - following code snippet. - - \code - int main( int argc, char **argv ) - { - TQApplication app( argc, argv ); - TQPixmap pixmap( "splash.png" ); - TQSplashScreen *splash = new TQSplashScreen( pixmap ); - splash->show(); - TQMainWindow *mainWin = new TQMainWindow; - ... - app.setMainWidget( mainWin ); - mainWin->show(); - splash->finish( mainWin ); - delete splash; - return app.exec(); - } - \endcode - - It is sometimes useful to update the splash screen with messages, - for example, announcing connections established or modules loaded - as the application starts up. TQSplashScreen supports this with the - message() function. If you wish to do your own drawing you can - get a pointer to the pixmap used in the splash screen with pixmap(). - Alternatively, you can subclass TQSplashScreen and reimplement - drawContents(). - - The user can hide the splash screen by clicking on it with the - mouse. Since the splash screen is typically displayed before the - event loop has started running, it is necessary to periodically - call TQApplication::processEvents() to receive the mouse clicks. - - \code - TQPixmap pixmap( "splash.png" ); - TQSplashScreen *splash = new TQSplashScreen( pixmap ); - splash->show(); - ... // Loading some items - splash->message( "Loaded modules" ); - tqApp->processEvents(); - ... // Establishing connections - splash->message( "Established connections" ); - tqApp->processEvents(); - \endcode - -*/ - -/*! - Construct a splash screen that will display the \a pixmap. - - There should be no need to set the widget flags, \a f, except - perhaps \c WDestructiveClose or \c WStyle_StaysOnTop. -*/ -TQSplashScreen::TQSplashScreen( const TQPixmap &pixmap, WFlags f ) - : TQWidget( 0, 0, WStyle_Customize | WStyle_Splash | f ) -{ - d = new TQSplashScreenPrivate(); - d->pixmap = pixmap; - setPixmap( d->pixmap ); // Does an implicit repaint -} - -/*! - Destructor. -*/ -TQSplashScreen::~TQSplashScreen() -{ - delete d; -} - -/*! - \reimp -*/ -void TQSplashScreen::mousePressEvent( TQMouseEvent * ) -{ - hide(); -} - -/*! - This overrides TQWidget::repaint(). It differs from the standard - repaint function in that it also calls TQApplication::flush() to - ensure the updates are displayed, even when there is no event loop - present. -*/ -void TQSplashScreen::repaint() -{ - drawContents(); - TQWidget::repaint(); - TQApplication::flush(); -} - -/*! - \fn TQSplashScreen::messageChanged( const TQString &message ) - - This signal is emitted when the message on the splash screen - changes. \a message is the new message and is a null-string - when the message has been removed. - - \sa message(), clear() -*/ - - - -/*! - Draws the \a message text onto the splash screen with color \a - color and aligns the text according to the flags in \a alignment. - - \sa TQt::AlignmentFlags clear() -*/ -void TQSplashScreen::message( const TQString &message, int alignment, - const TQColor &color ) -{ - d->currStatus = message; - d->currAlign = alignment; - d->currColor = color; - emit messageChanged( d->currStatus ); - repaint(); -} - -/*! - Removes the message being displayed on the splash screen - - \sa message() - */ -void TQSplashScreen::clear() -{ - d->currStatus = TQString::null; - emit messageChanged( d->currStatus ); - repaint(); -} - -/*! - Makes the splash screen wait until the widget \a mainWin is displayed - before calling close() on itself. -*/ -void TQSplashScreen::finish( TQWidget *mainWin ) -{ - if ( mainWin ) { -#if defined(TQ_WS_X11) - extern void tqt_wait_for_window_manager( TQWidget *mainWin ); - tqt_wait_for_window_manager( mainWin ); -#endif - } - close(); -} - -/*! - Sets the pixmap that will be used as the splash screen's image to - \a pixmap. -*/ -void TQSplashScreen::setPixmap( const TQPixmap &pixmap ) -{ - d->pixmap = pixmap; - TQRect r(0, 0, d->pixmap.size().width(), d->pixmap.size().height()); - resize( d->pixmap.size() ); - move( TQApplication::desktop()->screenGeometry().center() - r.center() ); - repaint(); -} - -/*! - Returns the pixmap that is used in the splash screen. The image - does not have any of the text drawn by message() calls. -*/ -TQPixmap* TQSplashScreen::pixmap() const -{ - return &( d->pixmap ); -} - -/*! - \internal -*/ -void TQSplashScreen::drawContents() -{ - TQPixmap textPix = d->pixmap; - TQPainter painter( &textPix, this ); - drawContents( &painter ); - setErasePixmap( textPix ); -} - -/*! - Draw the contents of the splash screen using painter \a painter. - The default implementation draws the message passed by message(). - Reimplement this function if you want to do your own drawing on - the splash screen. -*/ -void TQSplashScreen::drawContents( TQPainter *painter ) -{ - painter->setPen( d->currColor ); - TQRect r = rect(); - r.setRect( r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10 ); - painter->drawText( r, d->currAlign, d->currStatus ); -} - -#endif //TQT_NO_SPLASHSCREEN diff --git a/src/widgets/qsplitter.cpp b/src/widgets/qsplitter.cpp deleted file mode 100644 index 1e6699806..000000000 --- a/src/widgets/qsplitter.cpp +++ /dev/null @@ -1,1372 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQSplitter class -** -** Created : 980105 -** -** 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 "ntqsplitter.h" -#ifndef TQT_NO_SPLITTER - -#include "tqlayout.h" -#include "../kernel/tqlayoutengine_p.h" -#include "ntqapplication.h" -#include "tqbitmap.h" -#include "tqdrawutil.h" -#include "tqmemarray.h" -#include "tqobjectlist.h" -#include "tqpainter.h" -#include "tqptrlist.h" -#include "tqstyle.h" - -const uint Default = QT_QSPLITTER_DEFAULT; - -static int mouseOffset; -static int opaqueOldPos = -1; // this assumes that there's only one mouse - -static TQPoint toggle( TQWidget *w, TQPoint pos ) -{ - TQSize minS = qSmartMinSize( w ); - return -pos - TQPoint( minS.width(), minS.height() ); -} - -static bool isCollapsed( TQWidget *w ) -{ - return w->x() < 0 || w->y() < 0; -} - -static TQPoint topLeft( TQWidget *w ) -{ - if ( isCollapsed(w) ) { - return toggle( w, w->pos() ); - } else { - return w->pos(); - } -} - -static TQPoint bottomRight( TQWidget *w ) -{ - if ( isCollapsed(w) ) { - return toggle( w, w->pos() ) - TQPoint( 1, 1 ); - } else { - return w->geometry().bottomRight(); - } -} - -TQSplitterHandle::TQSplitterHandle( Orientation o, TQSplitter *parent, - const char * name ) - : TQWidget( parent, name ) -{ - s = parent; - setOrientation( o ); -} - -TQSize TQSplitterHandle::sizeHint() const -{ - int hw = s->handleWidth(); - return parentWidget()->style().sizeFromContents( TQStyle::CT_Splitter, s, - TQSize(hw, hw) ) - .expandedTo( TQApplication::globalStrut() ); -} - -void TQSplitterHandle::setOrientation( Orientation o ) -{ - orient = o; -#ifndef TQT_NO_CURSOR - setCursor( o == TQSplitter::Horizontal ? splitHCursor : splitVCursor ); -#endif -} - -void TQSplitterHandle::mouseMoveEvent( TQMouseEvent *e ) -{ - if ( !(e->state()&LeftButton) ) - return; - TQCOORD pos = s->pick( parentWidget()->mapFromGlobal(e->globalPos()) ) - - mouseOffset; - if ( opaque() ) { - s->moveSplitter( pos, id() ); - } else { - s->setRubberband( s->adjustPos(pos, id()) ); - } -} - -void TQSplitterHandle::mousePressEvent( TQMouseEvent *e ) -{ - if ( e->button() == LeftButton ) - mouseOffset = s->pick( e->pos() ); -} - -void TQSplitterHandle::mouseReleaseEvent( TQMouseEvent *e ) -{ - if ( !opaque() && e->button() == LeftButton ) { - TQCOORD pos = s->pick( parentWidget()->mapFromGlobal(e->globalPos()) ) - - mouseOffset; - s->setRubberband( -1 ); - s->moveSplitter( pos, id() ); - } -} - -void TQSplitterHandle::paintEvent( TQPaintEvent * ) -{ - TQStyle::SFlags flags = (orientation() == Horizontal ? TQStyle::Style_Horizontal : 0); - if (hasMouse()) { - flags |= TQStyle::Style_MouseOver; - } - - TQPainter p( this ); - parentWidget()->style().drawPrimitive( TQStyle::PE_Splitter, &p, rect(), - colorGroup(), - flags ); -} - -TQCOORD TQSplitterLayoutStruct::getSizer( Orientation orient ) -{ - if ( sizer == -1 ) { - TQSize s = wid->sizeHint(); - if ( !s.isValid() || wid->testWState(WState_Resized) ) - s = wid->size(); - sizer = ( orient == Horizontal ) ? s.width() : s.height(); - } - return sizer; -} - -/*! - \class TQSplitter - \brief The TQSplitter class implements a splitter widget. - - \ingroup organizers - \mainclass - - A splitter lets the user control the size of child widgets by - dragging the boundary between the children. Any number of widgets - may be controlled by a single splitter. - - To show a TQListBox, a TQListView and a TQTextEdit side by side: - \code - TQSplitter *split = new TQSplitter( parent ); - TQListBox *lb = new TQListBox( split ); - TQListView *lv = new TQListView( split ); - TQTextEdit *ed = new TQTextEdit( split ); - \endcode - - TQSplitter lays out its children horizontally (side by side); you - can use setOrientation(TQSplitter::Vertical) to lay out the - children vertically. - - By default, all widgets can be as large or as small as the user - wishes, between the \l minimumSizeHint() (or \l minimumSize()) - and \l maximumSize() of the widgets. Use setResizeMode() to - specify that a widget should keep its size when the splitter is - resized, or set the stretch component of the \l sizePolicy. - - Although TQSplitter normally resizes the children only at the end - of a resize operation, if you call setOpaqueResize(TRUE) the - widgets are resized as often as possible. - - The initial distribution of size between the widgets is determined - by the initial size of each widget. You can also use setSizes() to - set the sizes of all the widgets. The function sizes() returns the - sizes set by the user. - - If you hide() a child its space will be distributed among the - other children. It will be reinstated when you show() it again. It - is also possible to reorder the widgets within the splitter using - moveToFirst() and moveToLast(). - - - - \sa TQTabBar -*/ - - -/*! - Constructs a horizontal splitter with the \a parent and \a name - arguments being passed on to the TQFrame constructor. -*/ - -TQSplitter::TQSplitter( TQWidget *parent, const char *name ) - : TQFrame( parent, name, WPaintUnclipped ) -{ - orient = Horizontal; - init(); -} - - -/*! - Constructs a splitter with orientation \a o with the \a parent and - \a name arguments being passed on to the TQFrame constructor. -*/ - -TQSplitter::TQSplitter( Orientation o, TQWidget *parent, const char *name ) - : TQFrame( parent, name, WPaintUnclipped ) -{ - orient = o; - init(); -} - - -/*! - Destroys the splitter and any children. -*/ - -TQSplitter::~TQSplitter() -{ - delete d; -} - - -void TQSplitter::init() -{ - d = new TQSplitterPrivate; - d->list.setAutoDelete( TRUE ); - TQSizePolicy sp( TQSizePolicy::Expanding, TQSizePolicy::Preferred ); - if ( orient == Vertical ) - sp.transpose(); - setSizePolicy( sp ); - clearWState( WState_OwnSizePolicy ); -} - -/*! - \fn void TQSplitter::refresh() - - Updates the splitter's state. You should not need to call this - function. -*/ - - -/*! - \property TQSplitter::orientation - \brief the orientation of the splitter - - By default the orientation is horizontal (the widgets are side by - side). The possible orientations are \c Horizontal and - \c Vertical. -*/ - -void TQSplitter::setOrientation( Orientation o ) -{ - if ( orient == o ) - return; - - if ( !testWState( WState_OwnSizePolicy ) ) { - TQSizePolicy sp = sizePolicy(); - sp.transpose(); - setSizePolicy( sp ); - clearWState( WState_OwnSizePolicy ); - } - - orient = o; - - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( s->isHandle ) - ((TQSplitterHandle*)s->wid)->setOrientation( o ); - s = d->list.next(); - } - recalc( isVisible() ); -} - -/*! - \property TQSplitter::childrenCollapsible - \brief whether child widgets can be resized down to size 0 by the user - - By default, children are collapsible. It is possible to enable - and disable the collapsing of individual children; see - setCollapsible(). -*/ - -void TQSplitter::setChildrenCollapsible( bool collapse ) -{ - d->childrenCollapsible = collapse; -} - -bool TQSplitter::childrenCollapsible() const -{ - return d->childrenCollapsible; -} - -/*! - Sets whether the child widget \a w is collapsible to \a collapse. - - By default, children are collapsible, meaning that the user can - resize them down to size 0, even if they have a non-zero - minimumSize() or minimumSizeHint(). This behavior can be changed - on a per-widget basis by calling this function, or globally for - all the widgets in the splitter by setting the \l - childrenCollapsible property. - - \sa childrenCollapsible -*/ - -void TQSplitter::setCollapsible( TQWidget *w, bool collapse ) -{ - findWidget( w )->collapsible = collapse ? 1 : 0; -} - -/*! - \reimp -*/ -void TQSplitter::resizeEvent( TQResizeEvent * ) -{ - doResize(); -} - -TQSplitterLayoutStruct *TQSplitter::findWidget( TQWidget *w ) -{ - processChildEvents(); - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( s->wid == w ) - return s; - s = d->list.next(); - } - return addWidget( w ); -} - -/* - Inserts the widget \a w at the end (or at the beginning if \a - prepend is TRUE) of the splitter's list of widgets. - - It is the responsibility of the caller to make sure that \a w is - not already in the splitter and to call recalcId() if needed. (If - \a prepend is TRUE, then recalcId() is very probably needed.) -*/ - -TQSplitterLayoutStruct *TQSplitter::addWidget( TQWidget *w, bool prepend ) -{ - TQSplitterLayoutStruct *s; - TQSplitterHandle *newHandle = 0; - if ( d->list.count() > 0 ) { - s = new TQSplitterLayoutStruct; - s->resizeMode = KeepSize; - TQString tmp = "qt_splithandle_"; - tmp += w->name(); - newHandle = new TQSplitterHandle( orientation(), this, tmp ); - s->wid = newHandle; - newHandle->setId( d->list.count() ); - s->isHandle = TRUE; - s->sizer = pick( newHandle->sizeHint() ); - if ( prepend ) - d->list.prepend( s ); - else - d->list.append( s ); - } - s = new TQSplitterLayoutStruct; - s->resizeMode = DefaultResizeMode; - s->wid = w; - s->isHandle = FALSE; - if ( prepend ) - d->list.prepend( s ); - else - d->list.append( s ); - if ( newHandle && isVisible() ) - newHandle->show(); // will trigger sending of post events - return s; -} - - -/*! - Tells the splitter that the child widget described by \a c has - been inserted or removed. -*/ - -void TQSplitter::childEvent( TQChildEvent *c ) -{ - if ( c->type() == TQEvent::ChildInserted ) { - if ( !c->child()->isWidgetType() ) - return; - - if ( ((TQWidget*)c->child())->testWFlags( WType_TopLevel ) ) - return; - - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( s->wid == c->child() ) - return; - s = d->list.next(); - } - addWidget( (TQWidget*)c->child() ); - recalc( isVisible() ); - } else if ( c->type() == TQEvent::ChildRemoved ) { - TQSplitterLayoutStruct *prev = 0; - if ( d->list.count() > 1 ) - prev = d->list.at( 1 ); // yes, this is correct - TQSplitterLayoutStruct *curr = d->list.first(); - while ( curr ) { - if ( curr->wid == c->child() ) { - d->list.removeRef( curr ); - if ( prev && prev->isHandle ) { - TQWidget *w = prev->wid; - d->list.removeRef( prev ); - delete w; // will call childEvent() - } - recalcId(); - doResize(); - return; - } - prev = curr; - curr = d->list.next(); - } - } -} - - -/*! - Displays a rubber band at position \a p. If \a p is negative, the - rubber band is removed. -*/ - -void TQSplitter::setRubberband( int p ) -{ - TQPainter paint( this ); - paint.setPen( gray ); - paint.setBrush( gray ); - paint.setRasterOp( XorROP ); - TQRect r = contentsRect(); - const int rBord = 3; // customizable? - int hw = handleWidth(); - if ( orient == Horizontal ) { - if ( opaqueOldPos >= 0 ) - paint.drawRect( opaqueOldPos + hw / 2 - rBord, r.y(), - 2 * rBord, r.height() ); - if ( p >= 0 ) - paint.drawRect( p + hw / 2 - rBord, r.y(), 2 * rBord, r.height() ); - } else { - if ( opaqueOldPos >= 0 ) - paint.drawRect( r.x(), opaqueOldPos + hw / 2 - rBord, - r.width(), 2 * rBord ); - if ( p >= 0 ) - paint.drawRect( r.x(), p + hw / 2 - rBord, r.width(), 2 * rBord ); - } - opaqueOldPos = p; -} - - -/*! - \reimp -*/ - -bool TQSplitter::event( TQEvent *e ) -{ - switch ( e->type() ) { - case TQEvent::Show: - if ( !d->firstShow ) - break; - d->firstShow = FALSE; - // fall through - case TQEvent::LayoutHint: - recalc( isVisible() ); - break; - default: - ; - } - return TQWidget::event( e ); -} - - -/*! - \obsolete - - Draws the splitter handle in the rectangle described by \a x, \a y, - \a w, \a h using painter \a p. - \sa TQStyle::drawPrimitive() -*/ - -// ### Remove this in 4.0 - -void TQSplitter::drawSplitter( TQPainter *p, - TQCOORD x, TQCOORD y, TQCOORD w, TQCOORD h ) -{ - style().drawPrimitive(TQStyle::PE_Splitter, p, TQRect(x, y, w, h), colorGroup(), - (orientation() == Horizontal ? - TQStyle::Style_Horizontal : 0)); -} - - -/*! - Returns the ID of the widget to the right of or below the widget - \a w, or 0 if there is no such widget (i.e. it is either not in - this TQSplitter or \a w is at the end). -*/ - -int TQSplitter::idAfter( TQWidget* w ) const -{ - TQSplitterLayoutStruct *s = d->list.first(); - bool seen_w = FALSE; - while ( s ) { - if ( s->isHandle && seen_w ) - return d->list.at(); - if ( !s->isHandle && s->wid == w ) - seen_w = TRUE; - s = d->list.next(); - } - return 0; -} - - -/*! - Moves the left/top edge of the splitter handle with ID \a id as - close as possible to position \a p, which is the distance from the - left (or top) edge of the widget. - - For Arabic, Hebrew and other right-to-left languages the layout is - reversed. \a p is then the distance from the right (or top) edge - of the widget. - - \sa idAfter() -*/ -void TQSplitter::moveSplitter( TQCOORD p, int id ) -{ - TQSplitterLayoutStruct *s = d->list.at( id ); - int farMin; - int min; - int max; - int farMax; - - p = adjustPos( p, id, &farMin, &min, &max, &farMax ); - int oldP = pick( s->wid->pos() ); - - if ( TQApplication::reverseLayout() && orient == Horizontal ) { - int q = p + s->wid->width(); - doMove( FALSE, q, id - 1, -1, (q > oldP), (p > max) ); - doMove( TRUE, q, id, -1, (q > oldP), (p < min) ); - } else { - doMove( FALSE, p, id, +1, (p < oldP), (p > max) ); - doMove( TRUE, p, id - 1, +1, (p < oldP), (p < min) ); - } - storeSizes(); -} - - -void TQSplitter::setGeo( TQWidget *w, int p, int s, bool splitterMoved ) -{ - TQRect r; - if ( orient == Horizontal ) { - if ( TQApplication::reverseLayout() && orient == Horizontal - && !splitterMoved ) - p = contentsRect().width() - p - s; - r.setRect( p, contentsRect().y(), s, contentsRect().height() ); - } else { - r.setRect( contentsRect().x(), p, contentsRect().width(), s ); - } - - /* - Hide the child widget, but without calling hide() so that the - splitter handle is still shown. - */ - if ( !w->isHidden() && s <= 0 && pick(qSmartMinSize(w)) > 0 ) - r.moveTopLeft( toggle(w, r.topLeft()) ); - w->setGeometry( r ); -} - - -void TQSplitter::doMove( bool backwards, int pos, int id, int delta, bool upLeft, - bool mayCollapse ) -{ - if ( id < 0 || id >= (int) d->list.count() ) - return; - - TQSplitterLayoutStruct *s = d->list.at( id ); - TQWidget *w = s->wid; - - int nextId = backwards ? id - delta : id + delta; - - if ( w->isHidden() ) { - doMove( backwards, pos, nextId, delta, upLeft, TRUE ); - } else { - if ( s->isHandle ) { - int dd = s->getSizer( orient ); - int nextPos = backwards ? pos - dd : pos + dd; - int left = backwards ? pos - dd : pos; - setGeo( w, left, dd, TRUE ); - doMove( backwards, nextPos, nextId, delta, upLeft, mayCollapse ); - } else { - int dd = backwards ? pos - pick( topLeft(w) ) - : pick( bottomRight(w) ) - pos + 1; - if ( dd > 0 || (!isCollapsed(w) && !mayCollapse) ) { - dd = TQMAX( pick(qSmartMinSize(w)), - TQMIN(dd, pick(w->maximumSize())) ); - } else { - dd = 0; - } - setGeo( w, backwards ? pos - dd : pos, dd, TRUE ); - doMove( backwards, backwards ? pos - dd : pos + dd, nextId, delta, - upLeft, TRUE ); - } - } -} - -int TQSplitter::findWidgetJustBeforeOrJustAfter( int id, int delta, int &collapsibleSize ) -{ - id += delta; - do { - TQWidget *w = d->list.at( id )->wid; - if ( !w->isHidden() ) { - if ( collapsible(d->list.at(id)) ) - collapsibleSize = pick( qSmartMinSize(w) ); - return id; - } - id += 2 * delta; // go to previous (or next) widget, skip the handle - } while ( id >= 0 && id < (int)d->list.count() ); - - return -1; -} - -void TQSplitter::getRange( int id, int *farMin, int *min, int *max, int *farMax ) -{ - int n = d->list.count(); - if ( id <= 0 || id >= n - 1 ) - return; - - int collapsibleSizeBefore = 0; - int idJustBefore = findWidgetJustBeforeOrJustAfter( id, -1, collapsibleSizeBefore ); - - int collapsibleSizeAfter = 0; - int idJustAfter = findWidgetJustBeforeOrJustAfter( id, +1, collapsibleSizeAfter ); - - int minBefore = 0; - int minAfter = 0; - int maxBefore = 0; - int maxAfter = 0; - int i; - - for ( i = 0; i < id; i++ ) - addContribution( i, &minBefore, &maxBefore, i == idJustBefore ); - for ( i = id; i < n; i++ ) - addContribution( i, &minAfter, &maxAfter, i == idJustAfter ); - - TQRect r = contentsRect(); - int farMinVal; - int minVal; - int maxVal; - int farMaxVal; - - int smartMinBefore = TQMAX( minBefore, pick(r.size()) - maxAfter ); - int smartMaxBefore = TQMIN( maxBefore, pick(r.size()) - minAfter ); - - if ( orient == Vertical || !TQApplication::reverseLayout() ) { - minVal = pick( r.topLeft() ) + smartMinBefore; - maxVal = pick( r.topLeft() ) + smartMaxBefore; - - farMinVal = minVal; - if ( minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter ) - farMinVal -= collapsibleSizeBefore; - farMaxVal = maxVal; - if ( pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore ) - farMaxVal += collapsibleSizeAfter; - } else { - int hw = handleWidth(); - minVal = r.width() - smartMaxBefore - hw; - maxVal = r.width() - smartMinBefore - hw; - - farMinVal = minVal; - if ( pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore ) - farMinVal -= collapsibleSizeAfter; - farMaxVal = maxVal; - if ( minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter ) - farMaxVal += collapsibleSizeBefore; - } - - if ( farMin ) - *farMin = farMinVal; - if ( min ) - *min = minVal; - if ( max ) - *max = maxVal; - if ( farMax ) - *farMax = farMaxVal; -} - -/*! - Returns the valid range of the splitter with ID \a id in \a *min - and \a *max if \a min and \a max are not 0. - - \sa idAfter() -*/ - -void TQSplitter::getRange( int id, int *min, int *max ) -{ - getRange( id, min, 0, 0, max ); -} - - -/*! - Returns the closest legal position to \a pos of the widget with ID - \a id. - - \sa idAfter() -*/ - -int TQSplitter::adjustPos( int pos, int id ) -{ - int x, i, n, u; - return adjustPos( pos, id, &u, &n, &i, &x ); -} - -int TQSplitter::adjustPos( int pos, int id, int *farMin, int *min, int *max, - int *farMax ) -{ - const int Threshold = 40; - - getRange( id, farMin, min, max, farMax ); - - if ( pos >= *min ) { - if ( pos <= *max ) { - return pos; - } else { - int delta = pos - *max; - int width = *farMax - *max; - - if ( delta > width / 2 && delta >= TQMIN(Threshold, width) ) { - return *farMax; - } else { - return *max; - } - } - } else { - int delta = *min - pos; - int width = *min - *farMin; - - if ( delta > width / 2 && delta >= TQMIN(Threshold, width) ) { - return *farMin; - } else { - return *min; - } - } -} - -bool TQSplitter::collapsible( TQSplitterLayoutStruct *s ) -{ - if (pick(qSmartMinSize(s->wid)) == 1) - return FALSE; - if ( s->collapsible != Default ) { - return (bool) s->collapsible; - } else { - return d->childrenCollapsible; - } -} - -void TQSplitter::doResize() -{ - TQRect r = contentsRect(); - int n = d->list.count(); - TQMemArray a( n ); - - for ( int pass = 0; pass < 2; pass++ ) { - int numAutoWithStretch = 0; - int numAutoWithoutStretch = 0; - - for ( int i = 0; i < n; i++ ) { - a[i].init(); - TQSplitterLayoutStruct *s = d->list.at( i ); - if ( s->wid->isHidden() || isCollapsed(s->wid) ) { - a[i].maximumSize = 0; - } else if ( s->isHandle ) { - a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; - a[i].empty = FALSE; - } else { - int mode = s->resizeMode; - int stretch = 1; - - if ( mode == DefaultResizeMode ) { - TQSizePolicy p = s->wid->sizePolicy(); - int sizePolicyStretch = - pick( TQSize(p.horStretch(), p.verStretch()) ); - if ( sizePolicyStretch > 0 ) { - mode = Stretch; - stretch = sizePolicyStretch; - numAutoWithStretch++; - } else { - /* - Do things differently on the second pass, - if there's one. A second pass is necessary - if it was found out during the first pass - that all DefaultResizeMode items are - KeepSize items. In that case, we make them - all Stretch items instead, for a more TQt - 3.0-compatible behavior. - */ - mode = ( pass == 0 ) ? KeepSize : Stretch; - numAutoWithoutStretch++; - } - } - - a[i].minimumSize = pick( qSmartMinSize(s->wid) ); - a[i].maximumSize = pick( s->wid->maximumSize() ); - a[i].empty = FALSE; - - if ( mode == Stretch ) { - if ( s->getSizer(orient) > 1 ) - stretch *= s->getSizer( orient ); - // TQMIN(): ad hoc work-around for layout engine limitation - a[i].stretch = TQMIN( stretch, 8192 ); - a[i].sizeHint = a[i].minimumSize; - } else if ( mode == KeepSize ) { - a[i].sizeHint = s->getSizer( orient ); - } else { // mode == FollowSizeHint - a[i].sizeHint = pick( s->wid->sizeHint() ); - } - } - } - - // a second pass would yield the same results - if ( numAutoWithStretch > 0 || numAutoWithoutStretch == 0 ) - break; - } - - qGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); - - for ( int i = 0; i < n; i++ ) { - TQSplitterLayoutStruct *s = d->list.at(i); - setGeo( s->wid, a[i].pos, a[i].size, FALSE ); - } -} - -void TQSplitter::recalc( bool update ) -{ - int fi = 2 * frameWidth(); - int maxl = fi; - int minl = fi; - int maxt = TQWIDGETSIZE_MAX; - int mint = fi; - int n = d->list.count(); - bool first = TRUE; - - /* - Splitter handles before the first visible widget or right - before a hidden widget must be hidden. - */ - for ( int i = 0; i < n; i++ ) { - TQSplitterLayoutStruct *s = d->list.at( i ); - if ( !s->isHandle ) { - TQSplitterLayoutStruct *p = 0; - if ( i > 0 ) - p = d->list.at( i - 1 ); - - // may trigger new recalc - if ( p && p->isHandle ) - p->wid->setHidden( first || s->wid->isHidden() ); - - if ( !s->wid->isHidden() ) - first = FALSE; - } - } - - bool empty = TRUE; - for ( int j = 0; j < n; j++ ) { - TQSplitterLayoutStruct *s = d->list.at( j ); - if ( !s->wid->isHidden() ) { - empty = FALSE; - if ( s->isHandle ) { - minl += s->getSizer( orient ); - maxl += s->getSizer( orient ); - } else { - TQSize minS = qSmartMinSize( s->wid ); - minl += pick( minS ); - maxl += pick( s->wid->maximumSize() ); - mint = TQMAX( mint, trans(minS) ); - int tm = trans( s->wid->maximumSize() ); - if ( tm > 0 ) - maxt = TQMIN( maxt, tm ); - } - } - } - if ( empty ) { - if ( ::tqt_cast(parentWidget()) ) { - // nested splitters; be nice - maxl = maxt = 0; - } else { - // TQSplitter with no children yet - maxl = TQWIDGETSIZE_MAX; - } - } else { - maxl = TQMIN( maxl, TQWIDGETSIZE_MAX ); - } - if ( maxt < mint ) - maxt = mint; - - if ( orient == Horizontal ) { - setMaximumSize( maxl, maxt ); - setMinimumSize( minl, mint ); - } else { - setMaximumSize( maxt, maxl ); - setMinimumSize( mint, minl ); - } - if ( update ) - doResize(); - else - d->firstShow = TRUE; -} - -/*! - \enum TQSplitter::ResizeMode - - This enum type describes how TQSplitter will resize each of its - child widgets. - - \value Auto The widget will be resized according to the stretch - factors set in its sizePolicy(). - - \value Stretch The widget will be resized when the splitter - itself is resized. - - \value KeepSize TQSplitter will try to keep the widget's size - unchanged. - - \value FollowSizeHint TQSplitter will resize the widget when the - widget's size hint changes. -*/ - -/*! - Sets resize mode of widget \a w to \a mode. (The default is \c - Auto.) -*/ - -void TQSplitter::setResizeMode( TQWidget *w, ResizeMode mode ) -{ - findWidget( w )->resizeMode = mode; -} - - -/*! - \property TQSplitter::opaqueResize - \brief whether resizing is opaque - - Opaque resizing is off by default. -*/ - -bool TQSplitter::opaqueResize() const -{ - return d->opaque; -} - - -void TQSplitter::setOpaqueResize( bool on ) -{ - d->opaque = on; -} - - -/*! - Moves widget \a w to the leftmost/top position. -*/ - -void TQSplitter::moveToFirst( TQWidget *w ) -{ - processChildEvents(); - bool found = FALSE; - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( s->wid == w ) { - found = TRUE; - TQSplitterLayoutStruct *p = d->list.prev(); - if ( p ) { // not already at first place - d->list.take(); // take p - d->list.take(); // take s - d->list.prepend( p ); - d->list.prepend( s ); - } - break; - } - s = d->list.next(); - } - if ( !found ) - addWidget( w, TRUE ); - recalcId(); -} - - -/*! - Moves widget \a w to the rightmost/bottom position. -*/ - -void TQSplitter::moveToLast( TQWidget *w ) -{ - processChildEvents(); - bool found = FALSE; - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( s->wid == w ) { - found = TRUE; - d->list.take(); // take s - TQSplitterLayoutStruct *p = d->list.current(); - if ( p ) { // the splitter handle after s - d->list.take(); // take p - d->list.append( p ); - } - d->list.append( s ); - break; - } - s = d->list.next(); - } - if ( !found ) - addWidget( w ); - recalcId(); -} - - -void TQSplitter::recalcId() -{ - int n = d->list.count(); - for ( int i = 0; i < n; i++ ) { - TQSplitterLayoutStruct *s = d->list.at( i ); - if ( s->isHandle ) - ((TQSplitterHandle*)s->wid)->setId( i ); - } -} - - -/*! - \reimp -*/ -TQSize TQSplitter::sizeHint() const -{ - constPolish(); - int l = 0; - int t = 0; - if ( children() ) { - const TQObjectList * c = children(); - TQObjectListIt it( *c ); - TQObject * o; - - while( (o = it.current()) != 0 ) { - ++it; - if ( o->isWidgetType() && !((TQWidget*)o)->isHidden() ) { - TQSize s = ((TQWidget*)o)->sizeHint(); - if ( s.isValid() ) { - l += pick( s ); - t = TQMAX( t, trans( s ) ); - } - } - } - } - return orientation() == Horizontal ? TQSize( l, t ) : TQSize( t, l ); -} - - -/*! - \reimp -*/ - -TQSize TQSplitter::minimumSizeHint() const -{ - constPolish(); - int l = 0; - int t = 0; - if ( children() ) { - const TQObjectList * c = children(); - TQObjectListIt it( *c ); - TQObject * o; - - while ( (o = it.current()) != 0 ) { - ++it; - if ( o->isWidgetType() && !((TQWidget*)o)->isHidden() ) { - TQSize s = qSmartMinSize( (TQWidget*)o ); - if ( s.isValid() ) { - l += pick( s ); - t = TQMAX( t, trans( s ) ); - } - } - } - } - return orientation() == Horizontal ? TQSize( l, t ) : TQSize( t, l ); -} - - -void TQSplitter::storeSizes() -{ - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( !s->isHandle ) - s->sizer = pick( s->wid->size() ); - s = d->list.next(); - } -} - - -void TQSplitter::addContribution( int id, int *min, int *max, - bool mayCollapse ) -{ - TQSplitterLayoutStruct *s = d->list.at( id ); - if ( !s->wid->isHidden() ) { - if ( s->isHandle ) { - *min += s->getSizer( orient ); - *max += s->getSizer( orient ); - } else { - if ( mayCollapse || !isCollapsed(s->wid) ) - *min += pick( qSmartMinSize(s->wid) ); - *max += pick( s->wid->maximumSize() ); - } - } -} - - -/*! - Returns a list of the size parameters of all the widgets in this - splitter. - - If the splitter's orientation is horizontal, the list is a list of - widget widths; if the orientation is vertical, the list is a list - of widget heights. - - Giving the values to another splitter's setSizes() function will - produce a splitter with the same layout as this one. - - Note that if you want to iterate over the list, you should iterate - over a copy, e.g. - \code - TQValueList list = mySplitter.sizes(); - TQValueList::Iterator it = list.begin(); - while( it != list.end() ) { - myProcessing( *it ); - ++it; - } - \endcode - - \sa setSizes() -*/ - -TQValueList TQSplitter::sizes() const -{ - if ( !testWState(WState_Polished) ) - constPolish(); - - TQValueList list; - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( !s->isHandle ) - list.append( isCollapsed(s->wid) ? 0 : pick(s->wid->size())); - s = d->list.next(); - } - return list; -} - -/*! - Sets the size parameters to the values given in the \a list. If - the splitter is horizontal, the values set the widths of each - widget going from left to right. If the splitter is vertical, the - values set the heights of each widget going from top to bottom. - Extra values in the \a list are ignored. - - If \a list contains too few values, the result is undefined but - the program will still be well-behaved. - - Note that the values in \a list should be the height/width that - the widgets should be resized to. - - \sa sizes() -*/ - -void TQSplitter::setSizes( TQValueList list ) -{ - processChildEvents(); - TQValueList::Iterator it = list.begin(); - TQSplitterLayoutStruct *s = d->list.first(); - while ( s && it != list.end() ) { - if ( !s->isHandle ) { - s->sizer = TQMAX( *it, 0 ); - int smartMinSize = pick( qSmartMinSize(s->wid) ); - // Make sure that we reset the collapsed state. - if ( s->sizer == 0 ) { - if ( collapsible(s) && smartMinSize > 0 ) { - s->wid->move( -1, -1 ); - } else { - s->sizer = smartMinSize; - s->wid->move( 0, 0 ); - } - } else { - if ( s->sizer < smartMinSize ) - s->sizer = smartMinSize; - s->wid->move( 0, 0 ); - } - ++it; - } - s = d->list.next(); - } - doResize(); -} - -/*! - \property TQSplitter::handleWidth - \brief the width of the splitter handle -*/ - -int TQSplitter::handleWidth() const -{ - if ( d->handleWidth > 0 ) { - return d->handleWidth; - } else { - return style().pixelMetric( TQStyle::PM_SplitterWidth, this ); - } -} - -void TQSplitter::setHandleWidth( int width ) -{ - d->handleWidth = width; - updateHandles(); -} - -/*! - Processes all posted child events, ensuring that the internal state of - the splitter is kept consistent. -*/ - -void TQSplitter::processChildEvents() -{ - TQApplication::sendPostedEvents( this, TQEvent::ChildInserted ); -} - -/*! - \reimp -*/ - -void TQSplitter::styleChange( TQStyle& old ) -{ - updateHandles(); - TQFrame::styleChange( old ); -} - -void TQSplitter::updateHandles() -{ - int hw = handleWidth(); - TQSplitterLayoutStruct *s = d->list.first(); - while ( s ) { - if ( s->isHandle ) - s->sizer = hw; - s = d->list.next(); - } - recalc( isVisible() ); -} - -#ifndef TQT_NO_TEXTSTREAM -/*! - \relates TQSplitter - - Writes the sizes and the hidden state of the widgets in the - splitter \a splitter to the text stream \a ts. - - \sa operator>>(), sizes(), TQWidget::isHidden() -*/ - -TQTextStream& operator<<( TQTextStream& ts, const TQSplitter& splitter ) -{ - TQSplitterLayoutStruct *s = splitter.d->list.first(); - bool first = TRUE; - ts << "["; - - while ( s != 0 ) { - if ( !s->isHandle ) { - if ( !first ) - ts << ","; - - if ( s->wid->isHidden() ) { - ts << "H"; - } else if ( isCollapsed(s->wid) ) { - ts << 0; - } else { - ts << s->getSizer( splitter.orientation() ); - } - first = FALSE; - } - s = splitter.d->list.next(); - } - ts << "]" << endl; - return ts; -} - -/*! - \relates TQSplitter - - Reads the sizes and the hidden state of the widgets in the - splitter \a splitter from the text stream \a ts. The sizes must - have been previously written by the operator<<() function. - - \sa operator<<(), setSizes(), TQWidget::hide() -*/ - -TQTextStream& operator>>( TQTextStream& ts, TQSplitter& splitter ) -{ -#undef SKIP_SPACES -#define SKIP_SPACES() \ - while ( line[i].isSpace() ) \ - i++ - - splitter.processChildEvents(); - TQSplitterLayoutStruct *s = splitter.d->list.first(); - TQString line = ts.readLine(); - int i = 0; - - SKIP_SPACES(); - if ( line[i] == '[' ) { - i++; - SKIP_SPACES(); - while ( line[i] != ']' ) { - while ( s != 0 && s->isHandle ) - s = splitter.d->list.next(); - if ( s == 0 ) - break; - - if ( line[i].upper() == 'H' ) { - s->wid->hide(); - i++; - } else { - s->wid->show(); - int dim = 0; - while ( line[i].digitValue() >= 0 ) { - dim *= 10; - dim += line[i].digitValue(); - i++; - } - s->sizer = dim; - if ( dim == 0 ) - splitter.setGeo( s->wid, 0, 0, FALSE ); - } - SKIP_SPACES(); - if ( line[i] == ',' ) { - i++; - } else { - break; - } - SKIP_SPACES(); - s = splitter.d->list.next(); - } - } - splitter.doResize(); - return ts; -} -#endif - -#endif diff --git a/src/widgets/qt_widgets.pri b/src/widgets/qt_widgets.pri index 4d124e940..9cb2f4b55 100644 --- a/src/widgets/qt_widgets.pri +++ b/src/widgets/qt_widgets.pri @@ -38,9 +38,9 @@ widgets { $$WIDGETS_H/tqscrollbar.h \ $$WIDGETS_H/tqscrollview.h \ $$WIDGETS_H/tqslider.h \ - $$WIDGETS_H/ntqsplashscreen.h \ + $$WIDGETS_H/tqsplashscreen.h \ $$WIDGETS_H/tqspinbox.h \ - $$WIDGETS_H/ntqsplitter.h \ + $$WIDGETS_H/tqsplitter.h \ $$WIDGETS_H/tqstatusbar.h \ $$WIDGETS_H/tqtabbar.h \ $$WIDGETS_H/tqsyntaxhighlighter.h \ @@ -100,10 +100,10 @@ widgets { $$WIDGETS_CPP/tqscrollbar.cpp \ $$WIDGETS_CPP/tqscrollview.cpp \ $$WIDGETS_CPP/tqslider.cpp \ - $$WIDGETS_CPP/qsplashscreen.cpp \ + $$WIDGETS_CPP/tqsplashscreen.cpp \ $$WIDGETS_CPP/tqspinbox.cpp \ $$WIDGETS_CPP/tqspinwidget.cpp \ - $$WIDGETS_CPP/qsplitter.cpp \ + $$WIDGETS_CPP/tqsplitter.cpp \ $$WIDGETS_CPP/tqstatusbar.cpp \ $$WIDGETS_CPP/tqsyntaxhighlighter.cpp \ $$WIDGETS_CPP/tqtabbar.cpp \ @@ -134,8 +134,8 @@ wince-* { HEADERS += $$WIDGETS_H/ce/qcemainwindow.h SOURCES -= $$WIDGETS_CPP/tqsyntaxhighlighter.cpp \ - $$WIDGETS_CPP/qsplashscreen.cpp + $$WIDGETS_CPP/tqsplashscreen.cpp HEADERS -= $$WIDGETS_H/tqsyntaxhighlighter.h \ - $$WIDGETS_H/ntqsplashscreen.h + $$WIDGETS_H/tqsplashscreen.h } diff --git a/src/widgets/tqdialogbuttons.cpp b/src/widgets/tqdialogbuttons.cpp index cbc791ebb..12015bceb 100644 --- a/src/widgets/tqdialogbuttons.cpp +++ b/src/widgets/tqdialogbuttons.cpp @@ -43,7 +43,7 @@ #include #include #include -#include +#include #ifndef TQT_NO_DIALOG #include #endif // TQT_NO_DIALOG diff --git a/src/widgets/tqdockarea.cpp b/src/widgets/tqdockarea.cpp index b3133cfb5..0f14a33a7 100644 --- a/src/widgets/tqdockarea.cpp +++ b/src/widgets/tqdockarea.cpp @@ -41,7 +41,7 @@ #include "tqdockarea.h" #ifndef TQT_NO_MAINWINDOW -#include "ntqsplitter.h" +#include "tqsplitter.h" #include "tqlayout.h" #include "tqptrvector.h" #include "ntqapplication.h" diff --git a/src/widgets/tqdockarea.h b/src/widgets/tqdockarea.h index ff97e2a8f..a0a319a45 100644 --- a/src/widgets/tqdockarea.h +++ b/src/widgets/tqdockarea.h @@ -185,7 +185,7 @@ TQ_EXPORT TQTextStream &operator>>( TQTextStream &, TQDockArea & ); #endif #define Q_DEFINED_QDOCKAREA -#include "ntqwinexport.h" +#include "tqwinexport.h" #endif #endif //TQT_NO_MAINWINDOW diff --git a/src/widgets/tqdockwindow.h b/src/widgets/tqdockwindow.h index ad5fa47e7..896b8709f 100644 --- a/src/widgets/tqdockwindow.h +++ b/src/widgets/tqdockwindow.h @@ -231,7 +231,7 @@ inline TQDockArea *TQDockWindow::area() const } #define Q_DEFINED_QDOCKWINDOW -#include "ntqwinexport.h" +#include "tqwinexport.h" #endif #endif // TQDOCKWINDOW_H diff --git a/src/widgets/tqlistview.cpp b/src/widgets/tqlistview.cpp index 084fcf203..54473b6c5 100644 --- a/src/widgets/tqlistview.cpp +++ b/src/widgets/tqlistview.cpp @@ -56,7 +56,7 @@ #include "tqcleanuphandler.h" #include "tqpixmapcache.h" #include "tqpopupmenu.h" -#include "ntqtl.h" +#include "tqtl.h" #include "tqdragobject.h" #include "tqlineedit.h" #include "tqvbox.h" diff --git a/src/widgets/tqsplashscreen.cpp b/src/widgets/tqsplashscreen.cpp new file mode 100644 index 000000000..78aa19869 --- /dev/null +++ b/src/widgets/tqsplashscreen.cpp @@ -0,0 +1,271 @@ +/**************************************************************************** +** +** Definition of TQSplashScreen 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 "tqsplashscreen.h" + +#ifndef TQT_NO_SPLASHSCREEN + +#include "ntqapplication.h" +#include "tqpainter.h" +#include "tqpixmap.h" + +class TQSplashScreenPrivate +{ +public: + TQPixmap pixmap; + TQString currStatus; + TQColor currColor; + int currAlign; +}; + +/*! + \class TQSplashScreen tqsplashscreen.h + \brief The TQSplashScreen widget provides a splash screen that can + be shown during application startup. + + \ingroup misc + \mainclass + + A splash screen is a widget that is usually displayed when an + application is being started. Splash screens are often used for + applications that have long start up times (e.g. database or + networking applications that take time to establish connections) to + provide the user with feedback that the application is loading. + + The splash screen appears centered on the screen. It may be useful to add + the \c WStyle_StaysOnTop if you desire to keep above all the windows in the + GUI. + + Some X11 window managers do not support the "stays on top" flag. A + solution is to set up a timer that periodically calls raise() on + the splash screen to simulate the "stays on top" effect. + + The most common usage is to show a splash screen before the main + widget is displayed on the screen. This is illustrated in the + following code snippet. + + \code + int main( int argc, char **argv ) + { + TQApplication app( argc, argv ); + TQPixmap pixmap( "splash.png" ); + TQSplashScreen *splash = new TQSplashScreen( pixmap ); + splash->show(); + TQMainWindow *mainWin = new TQMainWindow; + ... + app.setMainWidget( mainWin ); + mainWin->show(); + splash->finish( mainWin ); + delete splash; + return app.exec(); + } + \endcode + + It is sometimes useful to update the splash screen with messages, + for example, announcing connections established or modules loaded + as the application starts up. TQSplashScreen supports this with the + message() function. If you wish to do your own drawing you can + get a pointer to the pixmap used in the splash screen with pixmap(). + Alternatively, you can subclass TQSplashScreen and reimplement + drawContents(). + + The user can hide the splash screen by clicking on it with the + mouse. Since the splash screen is typically displayed before the + event loop has started running, it is necessary to periodically + call TQApplication::processEvents() to receive the mouse clicks. + + \code + TQPixmap pixmap( "splash.png" ); + TQSplashScreen *splash = new TQSplashScreen( pixmap ); + splash->show(); + ... // Loading some items + splash->message( "Loaded modules" ); + tqApp->processEvents(); + ... // Establishing connections + splash->message( "Established connections" ); + tqApp->processEvents(); + \endcode + +*/ + +/*! + Construct a splash screen that will display the \a pixmap. + + There should be no need to set the widget flags, \a f, except + perhaps \c WDestructiveClose or \c WStyle_StaysOnTop. +*/ +TQSplashScreen::TQSplashScreen( const TQPixmap &pixmap, WFlags f ) + : TQWidget( 0, 0, WStyle_Customize | WStyle_Splash | f ) +{ + d = new TQSplashScreenPrivate(); + d->pixmap = pixmap; + setPixmap( d->pixmap ); // Does an implicit repaint +} + +/*! + Destructor. +*/ +TQSplashScreen::~TQSplashScreen() +{ + delete d; +} + +/*! + \reimp +*/ +void TQSplashScreen::mousePressEvent( TQMouseEvent * ) +{ + hide(); +} + +/*! + This overrides TQWidget::repaint(). It differs from the standard + repaint function in that it also calls TQApplication::flush() to + ensure the updates are displayed, even when there is no event loop + present. +*/ +void TQSplashScreen::repaint() +{ + drawContents(); + TQWidget::repaint(); + TQApplication::flush(); +} + +/*! + \fn TQSplashScreen::messageChanged( const TQString &message ) + + This signal is emitted when the message on the splash screen + changes. \a message is the new message and is a null-string + when the message has been removed. + + \sa message(), clear() +*/ + + + +/*! + Draws the \a message text onto the splash screen with color \a + color and aligns the text according to the flags in \a alignment. + + \sa TQt::AlignmentFlags clear() +*/ +void TQSplashScreen::message( const TQString &message, int alignment, + const TQColor &color ) +{ + d->currStatus = message; + d->currAlign = alignment; + d->currColor = color; + emit messageChanged( d->currStatus ); + repaint(); +} + +/*! + Removes the message being displayed on the splash screen + + \sa message() + */ +void TQSplashScreen::clear() +{ + d->currStatus = TQString::null; + emit messageChanged( d->currStatus ); + repaint(); +} + +/*! + Makes the splash screen wait until the widget \a mainWin is displayed + before calling close() on itself. +*/ +void TQSplashScreen::finish( TQWidget *mainWin ) +{ + if ( mainWin ) { +#if defined(TQ_WS_X11) + extern void tqt_wait_for_window_manager( TQWidget *mainWin ); + tqt_wait_for_window_manager( mainWin ); +#endif + } + close(); +} + +/*! + Sets the pixmap that will be used as the splash screen's image to + \a pixmap. +*/ +void TQSplashScreen::setPixmap( const TQPixmap &pixmap ) +{ + d->pixmap = pixmap; + TQRect r(0, 0, d->pixmap.size().width(), d->pixmap.size().height()); + resize( d->pixmap.size() ); + move( TQApplication::desktop()->screenGeometry().center() - r.center() ); + repaint(); +} + +/*! + Returns the pixmap that is used in the splash screen. The image + does not have any of the text drawn by message() calls. +*/ +TQPixmap* TQSplashScreen::pixmap() const +{ + return &( d->pixmap ); +} + +/*! + \internal +*/ +void TQSplashScreen::drawContents() +{ + TQPixmap textPix = d->pixmap; + TQPainter painter( &textPix, this ); + drawContents( &painter ); + setErasePixmap( textPix ); +} + +/*! + Draw the contents of the splash screen using painter \a painter. + The default implementation draws the message passed by message(). + Reimplement this function if you want to do your own drawing on + the splash screen. +*/ +void TQSplashScreen::drawContents( TQPainter *painter ) +{ + painter->setPen( d->currColor ); + TQRect r = rect(); + r.setRect( r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10 ); + painter->drawText( r, d->currAlign, d->currStatus ); +} + +#endif //TQT_NO_SPLASHSCREEN diff --git a/src/widgets/tqsplashscreen.h b/src/widgets/tqsplashscreen.h new file mode 100644 index 000000000..99b625f9f --- /dev/null +++ b/src/widgets/tqsplashscreen.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Definition of TQSplashScreen 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 TQSPLASHSCREEN_H +#define TQSPLASHSCREEN_H + +#ifndef QT_H +#include "tqpixmap.h" +#include "tqwidget.h" +#endif // QT_H + +#ifndef TQT_NO_SPLASHSCREEN +class TQSplashScreenPrivate; + +class TQ_EXPORT TQSplashScreen : public TQWidget +{ + TQ_OBJECT +public: + TQSplashScreen( const TQPixmap &pixmap = TQPixmap(), WFlags f = 0 ); + virtual ~TQSplashScreen(); + + void setPixmap( const TQPixmap &pixmap ); + TQPixmap* pixmap() const; + void finish( TQWidget *w ); + void repaint(); + +public slots: + void message( const TQString &str, int flags = AlignLeft, + const TQColor &color = black ); + void clear(); + +signals: + void messageChanged( const TQString &str ); + +protected: + virtual void drawContents( TQPainter *painter ); + void mousePressEvent( TQMouseEvent * ); + +private: + void drawContents(); + + TQSplashScreenPrivate *d; +}; +#endif //TQT_NO_SPLASHSCREEN +#endif diff --git a/src/widgets/tqsplitter.cpp b/src/widgets/tqsplitter.cpp new file mode 100644 index 000000000..e9de06731 --- /dev/null +++ b/src/widgets/tqsplitter.cpp @@ -0,0 +1,1372 @@ +/**************************************************************************** +** +** Implementation of TQSplitter class +** +** Created : 980105 +** +** 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 "tqsplitter.h" +#ifndef TQT_NO_SPLITTER + +#include "tqlayout.h" +#include "../kernel/tqlayoutengine_p.h" +#include "ntqapplication.h" +#include "tqbitmap.h" +#include "tqdrawutil.h" +#include "tqmemarray.h" +#include "tqobjectlist.h" +#include "tqpainter.h" +#include "tqptrlist.h" +#include "tqstyle.h" + +const uint Default = QT_QSPLITTER_DEFAULT; + +static int mouseOffset; +static int opaqueOldPos = -1; // this assumes that there's only one mouse + +static TQPoint toggle( TQWidget *w, TQPoint pos ) +{ + TQSize minS = qSmartMinSize( w ); + return -pos - TQPoint( minS.width(), minS.height() ); +} + +static bool isCollapsed( TQWidget *w ) +{ + return w->x() < 0 || w->y() < 0; +} + +static TQPoint topLeft( TQWidget *w ) +{ + if ( isCollapsed(w) ) { + return toggle( w, w->pos() ); + } else { + return w->pos(); + } +} + +static TQPoint bottomRight( TQWidget *w ) +{ + if ( isCollapsed(w) ) { + return toggle( w, w->pos() ) - TQPoint( 1, 1 ); + } else { + return w->geometry().bottomRight(); + } +} + +TQSplitterHandle::TQSplitterHandle( Orientation o, TQSplitter *parent, + const char * name ) + : TQWidget( parent, name ) +{ + s = parent; + setOrientation( o ); +} + +TQSize TQSplitterHandle::sizeHint() const +{ + int hw = s->handleWidth(); + return parentWidget()->style().sizeFromContents( TQStyle::CT_Splitter, s, + TQSize(hw, hw) ) + .expandedTo( TQApplication::globalStrut() ); +} + +void TQSplitterHandle::setOrientation( Orientation o ) +{ + orient = o; +#ifndef TQT_NO_CURSOR + setCursor( o == TQSplitter::Horizontal ? splitHCursor : splitVCursor ); +#endif +} + +void TQSplitterHandle::mouseMoveEvent( TQMouseEvent *e ) +{ + if ( !(e->state()&LeftButton) ) + return; + TQCOORD pos = s->pick( parentWidget()->mapFromGlobal(e->globalPos()) ) + - mouseOffset; + if ( opaque() ) { + s->moveSplitter( pos, id() ); + } else { + s->setRubberband( s->adjustPos(pos, id()) ); + } +} + +void TQSplitterHandle::mousePressEvent( TQMouseEvent *e ) +{ + if ( e->button() == LeftButton ) + mouseOffset = s->pick( e->pos() ); +} + +void TQSplitterHandle::mouseReleaseEvent( TQMouseEvent *e ) +{ + if ( !opaque() && e->button() == LeftButton ) { + TQCOORD pos = s->pick( parentWidget()->mapFromGlobal(e->globalPos()) ) + - mouseOffset; + s->setRubberband( -1 ); + s->moveSplitter( pos, id() ); + } +} + +void TQSplitterHandle::paintEvent( TQPaintEvent * ) +{ + TQStyle::SFlags flags = (orientation() == Horizontal ? TQStyle::Style_Horizontal : 0); + if (hasMouse()) { + flags |= TQStyle::Style_MouseOver; + } + + TQPainter p( this ); + parentWidget()->style().drawPrimitive( TQStyle::PE_Splitter, &p, rect(), + colorGroup(), + flags ); +} + +TQCOORD TQSplitterLayoutStruct::getSizer( Orientation orient ) +{ + if ( sizer == -1 ) { + TQSize s = wid->sizeHint(); + if ( !s.isValid() || wid->testWState(WState_Resized) ) + s = wid->size(); + sizer = ( orient == Horizontal ) ? s.width() : s.height(); + } + return sizer; +} + +/*! + \class TQSplitter + \brief The TQSplitter class implements a splitter widget. + + \ingroup organizers + \mainclass + + A splitter lets the user control the size of child widgets by + dragging the boundary between the children. Any number of widgets + may be controlled by a single splitter. + + To show a TQListBox, a TQListView and a TQTextEdit side by side: + \code + TQSplitter *split = new TQSplitter( parent ); + TQListBox *lb = new TQListBox( split ); + TQListView *lv = new TQListView( split ); + TQTextEdit *ed = new TQTextEdit( split ); + \endcode + + TQSplitter lays out its children horizontally (side by side); you + can use setOrientation(TQSplitter::Vertical) to lay out the + children vertically. + + By default, all widgets can be as large or as small as the user + wishes, between the \l minimumSizeHint() (or \l minimumSize()) + and \l maximumSize() of the widgets. Use setResizeMode() to + specify that a widget should keep its size when the splitter is + resized, or set the stretch component of the \l sizePolicy. + + Although TQSplitter normally resizes the children only at the end + of a resize operation, if you call setOpaqueResize(TRUE) the + widgets are resized as often as possible. + + The initial distribution of size between the widgets is determined + by the initial size of each widget. You can also use setSizes() to + set the sizes of all the widgets. The function sizes() returns the + sizes set by the user. + + If you hide() a child its space will be distributed among the + other children. It will be reinstated when you show() it again. It + is also possible to reorder the widgets within the splitter using + moveToFirst() and moveToLast(). + + + + \sa TQTabBar +*/ + + +/*! + Constructs a horizontal splitter with the \a parent and \a name + arguments being passed on to the TQFrame constructor. +*/ + +TQSplitter::TQSplitter( TQWidget *parent, const char *name ) + : TQFrame( parent, name, WPaintUnclipped ) +{ + orient = Horizontal; + init(); +} + + +/*! + Constructs a splitter with orientation \a o with the \a parent and + \a name arguments being passed on to the TQFrame constructor. +*/ + +TQSplitter::TQSplitter( Orientation o, TQWidget *parent, const char *name ) + : TQFrame( parent, name, WPaintUnclipped ) +{ + orient = o; + init(); +} + + +/*! + Destroys the splitter and any children. +*/ + +TQSplitter::~TQSplitter() +{ + delete d; +} + + +void TQSplitter::init() +{ + d = new TQSplitterPrivate; + d->list.setAutoDelete( TRUE ); + TQSizePolicy sp( TQSizePolicy::Expanding, TQSizePolicy::Preferred ); + if ( orient == Vertical ) + sp.transpose(); + setSizePolicy( sp ); + clearWState( WState_OwnSizePolicy ); +} + +/*! + \fn void TQSplitter::refresh() + + Updates the splitter's state. You should not need to call this + function. +*/ + + +/*! + \property TQSplitter::orientation + \brief the orientation of the splitter + + By default the orientation is horizontal (the widgets are side by + side). The possible orientations are \c Horizontal and + \c Vertical. +*/ + +void TQSplitter::setOrientation( Orientation o ) +{ + if ( orient == o ) + return; + + if ( !testWState( WState_OwnSizePolicy ) ) { + TQSizePolicy sp = sizePolicy(); + sp.transpose(); + setSizePolicy( sp ); + clearWState( WState_OwnSizePolicy ); + } + + orient = o; + + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( s->isHandle ) + ((TQSplitterHandle*)s->wid)->setOrientation( o ); + s = d->list.next(); + } + recalc( isVisible() ); +} + +/*! + \property TQSplitter::childrenCollapsible + \brief whether child widgets can be resized down to size 0 by the user + + By default, children are collapsible. It is possible to enable + and disable the collapsing of individual children; see + setCollapsible(). +*/ + +void TQSplitter::setChildrenCollapsible( bool collapse ) +{ + d->childrenCollapsible = collapse; +} + +bool TQSplitter::childrenCollapsible() const +{ + return d->childrenCollapsible; +} + +/*! + Sets whether the child widget \a w is collapsible to \a collapse. + + By default, children are collapsible, meaning that the user can + resize them down to size 0, even if they have a non-zero + minimumSize() or minimumSizeHint(). This behavior can be changed + on a per-widget basis by calling this function, or globally for + all the widgets in the splitter by setting the \l + childrenCollapsible property. + + \sa childrenCollapsible +*/ + +void TQSplitter::setCollapsible( TQWidget *w, bool collapse ) +{ + findWidget( w )->collapsible = collapse ? 1 : 0; +} + +/*! + \reimp +*/ +void TQSplitter::resizeEvent( TQResizeEvent * ) +{ + doResize(); +} + +TQSplitterLayoutStruct *TQSplitter::findWidget( TQWidget *w ) +{ + processChildEvents(); + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( s->wid == w ) + return s; + s = d->list.next(); + } + return addWidget( w ); +} + +/* + Inserts the widget \a w at the end (or at the beginning if \a + prepend is TRUE) of the splitter's list of widgets. + + It is the responsibility of the caller to make sure that \a w is + not already in the splitter and to call recalcId() if needed. (If + \a prepend is TRUE, then recalcId() is very probably needed.) +*/ + +TQSplitterLayoutStruct *TQSplitter::addWidget( TQWidget *w, bool prepend ) +{ + TQSplitterLayoutStruct *s; + TQSplitterHandle *newHandle = 0; + if ( d->list.count() > 0 ) { + s = new TQSplitterLayoutStruct; + s->resizeMode = KeepSize; + TQString tmp = "qt_splithandle_"; + tmp += w->name(); + newHandle = new TQSplitterHandle( orientation(), this, tmp ); + s->wid = newHandle; + newHandle->setId( d->list.count() ); + s->isHandle = TRUE; + s->sizer = pick( newHandle->sizeHint() ); + if ( prepend ) + d->list.prepend( s ); + else + d->list.append( s ); + } + s = new TQSplitterLayoutStruct; + s->resizeMode = DefaultResizeMode; + s->wid = w; + s->isHandle = FALSE; + if ( prepend ) + d->list.prepend( s ); + else + d->list.append( s ); + if ( newHandle && isVisible() ) + newHandle->show(); // will trigger sending of post events + return s; +} + + +/*! + Tells the splitter that the child widget described by \a c has + been inserted or removed. +*/ + +void TQSplitter::childEvent( TQChildEvent *c ) +{ + if ( c->type() == TQEvent::ChildInserted ) { + if ( !c->child()->isWidgetType() ) + return; + + if ( ((TQWidget*)c->child())->testWFlags( WType_TopLevel ) ) + return; + + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( s->wid == c->child() ) + return; + s = d->list.next(); + } + addWidget( (TQWidget*)c->child() ); + recalc( isVisible() ); + } else if ( c->type() == TQEvent::ChildRemoved ) { + TQSplitterLayoutStruct *prev = 0; + if ( d->list.count() > 1 ) + prev = d->list.at( 1 ); // yes, this is correct + TQSplitterLayoutStruct *curr = d->list.first(); + while ( curr ) { + if ( curr->wid == c->child() ) { + d->list.removeRef( curr ); + if ( prev && prev->isHandle ) { + TQWidget *w = prev->wid; + d->list.removeRef( prev ); + delete w; // will call childEvent() + } + recalcId(); + doResize(); + return; + } + prev = curr; + curr = d->list.next(); + } + } +} + + +/*! + Displays a rubber band at position \a p. If \a p is negative, the + rubber band is removed. +*/ + +void TQSplitter::setRubberband( int p ) +{ + TQPainter paint( this ); + paint.setPen( gray ); + paint.setBrush( gray ); + paint.setRasterOp( XorROP ); + TQRect r = contentsRect(); + const int rBord = 3; // customizable? + int hw = handleWidth(); + if ( orient == Horizontal ) { + if ( opaqueOldPos >= 0 ) + paint.drawRect( opaqueOldPos + hw / 2 - rBord, r.y(), + 2 * rBord, r.height() ); + if ( p >= 0 ) + paint.drawRect( p + hw / 2 - rBord, r.y(), 2 * rBord, r.height() ); + } else { + if ( opaqueOldPos >= 0 ) + paint.drawRect( r.x(), opaqueOldPos + hw / 2 - rBord, + r.width(), 2 * rBord ); + if ( p >= 0 ) + paint.drawRect( r.x(), p + hw / 2 - rBord, r.width(), 2 * rBord ); + } + opaqueOldPos = p; +} + + +/*! + \reimp +*/ + +bool TQSplitter::event( TQEvent *e ) +{ + switch ( e->type() ) { + case TQEvent::Show: + if ( !d->firstShow ) + break; + d->firstShow = FALSE; + // fall through + case TQEvent::LayoutHint: + recalc( isVisible() ); + break; + default: + ; + } + return TQWidget::event( e ); +} + + +/*! + \obsolete + + Draws the splitter handle in the rectangle described by \a x, \a y, + \a w, \a h using painter \a p. + \sa TQStyle::drawPrimitive() +*/ + +// ### Remove this in 4.0 + +void TQSplitter::drawSplitter( TQPainter *p, + TQCOORD x, TQCOORD y, TQCOORD w, TQCOORD h ) +{ + style().drawPrimitive(TQStyle::PE_Splitter, p, TQRect(x, y, w, h), colorGroup(), + (orientation() == Horizontal ? + TQStyle::Style_Horizontal : 0)); +} + + +/*! + Returns the ID of the widget to the right of or below the widget + \a w, or 0 if there is no such widget (i.e. it is either not in + this TQSplitter or \a w is at the end). +*/ + +int TQSplitter::idAfter( TQWidget* w ) const +{ + TQSplitterLayoutStruct *s = d->list.first(); + bool seen_w = FALSE; + while ( s ) { + if ( s->isHandle && seen_w ) + return d->list.at(); + if ( !s->isHandle && s->wid == w ) + seen_w = TRUE; + s = d->list.next(); + } + return 0; +} + + +/*! + Moves the left/top edge of the splitter handle with ID \a id as + close as possible to position \a p, which is the distance from the + left (or top) edge of the widget. + + For Arabic, Hebrew and other right-to-left languages the layout is + reversed. \a p is then the distance from the right (or top) edge + of the widget. + + \sa idAfter() +*/ +void TQSplitter::moveSplitter( TQCOORD p, int id ) +{ + TQSplitterLayoutStruct *s = d->list.at( id ); + int farMin; + int min; + int max; + int farMax; + + p = adjustPos( p, id, &farMin, &min, &max, &farMax ); + int oldP = pick( s->wid->pos() ); + + if ( TQApplication::reverseLayout() && orient == Horizontal ) { + int q = p + s->wid->width(); + doMove( FALSE, q, id - 1, -1, (q > oldP), (p > max) ); + doMove( TRUE, q, id, -1, (q > oldP), (p < min) ); + } else { + doMove( FALSE, p, id, +1, (p < oldP), (p > max) ); + doMove( TRUE, p, id - 1, +1, (p < oldP), (p < min) ); + } + storeSizes(); +} + + +void TQSplitter::setGeo( TQWidget *w, int p, int s, bool splitterMoved ) +{ + TQRect r; + if ( orient == Horizontal ) { + if ( TQApplication::reverseLayout() && orient == Horizontal + && !splitterMoved ) + p = contentsRect().width() - p - s; + r.setRect( p, contentsRect().y(), s, contentsRect().height() ); + } else { + r.setRect( contentsRect().x(), p, contentsRect().width(), s ); + } + + /* + Hide the child widget, but without calling hide() so that the + splitter handle is still shown. + */ + if ( !w->isHidden() && s <= 0 && pick(qSmartMinSize(w)) > 0 ) + r.moveTopLeft( toggle(w, r.topLeft()) ); + w->setGeometry( r ); +} + + +void TQSplitter::doMove( bool backwards, int pos, int id, int delta, bool upLeft, + bool mayCollapse ) +{ + if ( id < 0 || id >= (int) d->list.count() ) + return; + + TQSplitterLayoutStruct *s = d->list.at( id ); + TQWidget *w = s->wid; + + int nextId = backwards ? id - delta : id + delta; + + if ( w->isHidden() ) { + doMove( backwards, pos, nextId, delta, upLeft, TRUE ); + } else { + if ( s->isHandle ) { + int dd = s->getSizer( orient ); + int nextPos = backwards ? pos - dd : pos + dd; + int left = backwards ? pos - dd : pos; + setGeo( w, left, dd, TRUE ); + doMove( backwards, nextPos, nextId, delta, upLeft, mayCollapse ); + } else { + int dd = backwards ? pos - pick( topLeft(w) ) + : pick( bottomRight(w) ) - pos + 1; + if ( dd > 0 || (!isCollapsed(w) && !mayCollapse) ) { + dd = TQMAX( pick(qSmartMinSize(w)), + TQMIN(dd, pick(w->maximumSize())) ); + } else { + dd = 0; + } + setGeo( w, backwards ? pos - dd : pos, dd, TRUE ); + doMove( backwards, backwards ? pos - dd : pos + dd, nextId, delta, + upLeft, TRUE ); + } + } +} + +int TQSplitter::findWidgetJustBeforeOrJustAfter( int id, int delta, int &collapsibleSize ) +{ + id += delta; + do { + TQWidget *w = d->list.at( id )->wid; + if ( !w->isHidden() ) { + if ( collapsible(d->list.at(id)) ) + collapsibleSize = pick( qSmartMinSize(w) ); + return id; + } + id += 2 * delta; // go to previous (or next) widget, skip the handle + } while ( id >= 0 && id < (int)d->list.count() ); + + return -1; +} + +void TQSplitter::getRange( int id, int *farMin, int *min, int *max, int *farMax ) +{ + int n = d->list.count(); + if ( id <= 0 || id >= n - 1 ) + return; + + int collapsibleSizeBefore = 0; + int idJustBefore = findWidgetJustBeforeOrJustAfter( id, -1, collapsibleSizeBefore ); + + int collapsibleSizeAfter = 0; + int idJustAfter = findWidgetJustBeforeOrJustAfter( id, +1, collapsibleSizeAfter ); + + int minBefore = 0; + int minAfter = 0; + int maxBefore = 0; + int maxAfter = 0; + int i; + + for ( i = 0; i < id; i++ ) + addContribution( i, &minBefore, &maxBefore, i == idJustBefore ); + for ( i = id; i < n; i++ ) + addContribution( i, &minAfter, &maxAfter, i == idJustAfter ); + + TQRect r = contentsRect(); + int farMinVal; + int minVal; + int maxVal; + int farMaxVal; + + int smartMinBefore = TQMAX( minBefore, pick(r.size()) - maxAfter ); + int smartMaxBefore = TQMIN( maxBefore, pick(r.size()) - minAfter ); + + if ( orient == Vertical || !TQApplication::reverseLayout() ) { + minVal = pick( r.topLeft() ) + smartMinBefore; + maxVal = pick( r.topLeft() ) + smartMaxBefore; + + farMinVal = minVal; + if ( minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter ) + farMinVal -= collapsibleSizeBefore; + farMaxVal = maxVal; + if ( pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore ) + farMaxVal += collapsibleSizeAfter; + } else { + int hw = handleWidth(); + minVal = r.width() - smartMaxBefore - hw; + maxVal = r.width() - smartMinBefore - hw; + + farMinVal = minVal; + if ( pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore ) + farMinVal -= collapsibleSizeAfter; + farMaxVal = maxVal; + if ( minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter ) + farMaxVal += collapsibleSizeBefore; + } + + if ( farMin ) + *farMin = farMinVal; + if ( min ) + *min = minVal; + if ( max ) + *max = maxVal; + if ( farMax ) + *farMax = farMaxVal; +} + +/*! + Returns the valid range of the splitter with ID \a id in \a *min + and \a *max if \a min and \a max are not 0. + + \sa idAfter() +*/ + +void TQSplitter::getRange( int id, int *min, int *max ) +{ + getRange( id, min, 0, 0, max ); +} + + +/*! + Returns the closest legal position to \a pos of the widget with ID + \a id. + + \sa idAfter() +*/ + +int TQSplitter::adjustPos( int pos, int id ) +{ + int x, i, n, u; + return adjustPos( pos, id, &u, &n, &i, &x ); +} + +int TQSplitter::adjustPos( int pos, int id, int *farMin, int *min, int *max, + int *farMax ) +{ + const int Threshold = 40; + + getRange( id, farMin, min, max, farMax ); + + if ( pos >= *min ) { + if ( pos <= *max ) { + return pos; + } else { + int delta = pos - *max; + int width = *farMax - *max; + + if ( delta > width / 2 && delta >= TQMIN(Threshold, width) ) { + return *farMax; + } else { + return *max; + } + } + } else { + int delta = *min - pos; + int width = *min - *farMin; + + if ( delta > width / 2 && delta >= TQMIN(Threshold, width) ) { + return *farMin; + } else { + return *min; + } + } +} + +bool TQSplitter::collapsible( TQSplitterLayoutStruct *s ) +{ + if (pick(qSmartMinSize(s->wid)) == 1) + return FALSE; + if ( s->collapsible != Default ) { + return (bool) s->collapsible; + } else { + return d->childrenCollapsible; + } +} + +void TQSplitter::doResize() +{ + TQRect r = contentsRect(); + int n = d->list.count(); + TQMemArray a( n ); + + for ( int pass = 0; pass < 2; pass++ ) { + int numAutoWithStretch = 0; + int numAutoWithoutStretch = 0; + + for ( int i = 0; i < n; i++ ) { + a[i].init(); + TQSplitterLayoutStruct *s = d->list.at( i ); + if ( s->wid->isHidden() || isCollapsed(s->wid) ) { + a[i].maximumSize = 0; + } else if ( s->isHandle ) { + a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; + a[i].empty = FALSE; + } else { + int mode = s->resizeMode; + int stretch = 1; + + if ( mode == DefaultResizeMode ) { + TQSizePolicy p = s->wid->sizePolicy(); + int sizePolicyStretch = + pick( TQSize(p.horStretch(), p.verStretch()) ); + if ( sizePolicyStretch > 0 ) { + mode = Stretch; + stretch = sizePolicyStretch; + numAutoWithStretch++; + } else { + /* + Do things differently on the second pass, + if there's one. A second pass is necessary + if it was found out during the first pass + that all DefaultResizeMode items are + KeepSize items. In that case, we make them + all Stretch items instead, for a more TQt + 3.0-compatible behavior. + */ + mode = ( pass == 0 ) ? KeepSize : Stretch; + numAutoWithoutStretch++; + } + } + + a[i].minimumSize = pick( qSmartMinSize(s->wid) ); + a[i].maximumSize = pick( s->wid->maximumSize() ); + a[i].empty = FALSE; + + if ( mode == Stretch ) { + if ( s->getSizer(orient) > 1 ) + stretch *= s->getSizer( orient ); + // TQMIN(): ad hoc work-around for layout engine limitation + a[i].stretch = TQMIN( stretch, 8192 ); + a[i].sizeHint = a[i].minimumSize; + } else if ( mode == KeepSize ) { + a[i].sizeHint = s->getSizer( orient ); + } else { // mode == FollowSizeHint + a[i].sizeHint = pick( s->wid->sizeHint() ); + } + } + } + + // a second pass would yield the same results + if ( numAutoWithStretch > 0 || numAutoWithoutStretch == 0 ) + break; + } + + qGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); + + for ( int i = 0; i < n; i++ ) { + TQSplitterLayoutStruct *s = d->list.at(i); + setGeo( s->wid, a[i].pos, a[i].size, FALSE ); + } +} + +void TQSplitter::recalc( bool update ) +{ + int fi = 2 * frameWidth(); + int maxl = fi; + int minl = fi; + int maxt = TQWIDGETSIZE_MAX; + int mint = fi; + int n = d->list.count(); + bool first = TRUE; + + /* + Splitter handles before the first visible widget or right + before a hidden widget must be hidden. + */ + for ( int i = 0; i < n; i++ ) { + TQSplitterLayoutStruct *s = d->list.at( i ); + if ( !s->isHandle ) { + TQSplitterLayoutStruct *p = 0; + if ( i > 0 ) + p = d->list.at( i - 1 ); + + // may trigger new recalc + if ( p && p->isHandle ) + p->wid->setHidden( first || s->wid->isHidden() ); + + if ( !s->wid->isHidden() ) + first = FALSE; + } + } + + bool empty = TRUE; + for ( int j = 0; j < n; j++ ) { + TQSplitterLayoutStruct *s = d->list.at( j ); + if ( !s->wid->isHidden() ) { + empty = FALSE; + if ( s->isHandle ) { + minl += s->getSizer( orient ); + maxl += s->getSizer( orient ); + } else { + TQSize minS = qSmartMinSize( s->wid ); + minl += pick( minS ); + maxl += pick( s->wid->maximumSize() ); + mint = TQMAX( mint, trans(minS) ); + int tm = trans( s->wid->maximumSize() ); + if ( tm > 0 ) + maxt = TQMIN( maxt, tm ); + } + } + } + if ( empty ) { + if ( ::tqt_cast(parentWidget()) ) { + // nested splitters; be nice + maxl = maxt = 0; + } else { + // TQSplitter with no children yet + maxl = TQWIDGETSIZE_MAX; + } + } else { + maxl = TQMIN( maxl, TQWIDGETSIZE_MAX ); + } + if ( maxt < mint ) + maxt = mint; + + if ( orient == Horizontal ) { + setMaximumSize( maxl, maxt ); + setMinimumSize( minl, mint ); + } else { + setMaximumSize( maxt, maxl ); + setMinimumSize( mint, minl ); + } + if ( update ) + doResize(); + else + d->firstShow = TRUE; +} + +/*! + \enum TQSplitter::ResizeMode + + This enum type describes how TQSplitter will resize each of its + child widgets. + + \value Auto The widget will be resized according to the stretch + factors set in its sizePolicy(). + + \value Stretch The widget will be resized when the splitter + itself is resized. + + \value KeepSize TQSplitter will try to keep the widget's size + unchanged. + + \value FollowSizeHint TQSplitter will resize the widget when the + widget's size hint changes. +*/ + +/*! + Sets resize mode of widget \a w to \a mode. (The default is \c + Auto.) +*/ + +void TQSplitter::setResizeMode( TQWidget *w, ResizeMode mode ) +{ + findWidget( w )->resizeMode = mode; +} + + +/*! + \property TQSplitter::opaqueResize + \brief whether resizing is opaque + + Opaque resizing is off by default. +*/ + +bool TQSplitter::opaqueResize() const +{ + return d->opaque; +} + + +void TQSplitter::setOpaqueResize( bool on ) +{ + d->opaque = on; +} + + +/*! + Moves widget \a w to the leftmost/top position. +*/ + +void TQSplitter::moveToFirst( TQWidget *w ) +{ + processChildEvents(); + bool found = FALSE; + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( s->wid == w ) { + found = TRUE; + TQSplitterLayoutStruct *p = d->list.prev(); + if ( p ) { // not already at first place + d->list.take(); // take p + d->list.take(); // take s + d->list.prepend( p ); + d->list.prepend( s ); + } + break; + } + s = d->list.next(); + } + if ( !found ) + addWidget( w, TRUE ); + recalcId(); +} + + +/*! + Moves widget \a w to the rightmost/bottom position. +*/ + +void TQSplitter::moveToLast( TQWidget *w ) +{ + processChildEvents(); + bool found = FALSE; + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( s->wid == w ) { + found = TRUE; + d->list.take(); // take s + TQSplitterLayoutStruct *p = d->list.current(); + if ( p ) { // the splitter handle after s + d->list.take(); // take p + d->list.append( p ); + } + d->list.append( s ); + break; + } + s = d->list.next(); + } + if ( !found ) + addWidget( w ); + recalcId(); +} + + +void TQSplitter::recalcId() +{ + int n = d->list.count(); + for ( int i = 0; i < n; i++ ) { + TQSplitterLayoutStruct *s = d->list.at( i ); + if ( s->isHandle ) + ((TQSplitterHandle*)s->wid)->setId( i ); + } +} + + +/*! + \reimp +*/ +TQSize TQSplitter::sizeHint() const +{ + constPolish(); + int l = 0; + int t = 0; + if ( children() ) { + const TQObjectList * c = children(); + TQObjectListIt it( *c ); + TQObject * o; + + while( (o = it.current()) != 0 ) { + ++it; + if ( o->isWidgetType() && !((TQWidget*)o)->isHidden() ) { + TQSize s = ((TQWidget*)o)->sizeHint(); + if ( s.isValid() ) { + l += pick( s ); + t = TQMAX( t, trans( s ) ); + } + } + } + } + return orientation() == Horizontal ? TQSize( l, t ) : TQSize( t, l ); +} + + +/*! + \reimp +*/ + +TQSize TQSplitter::minimumSizeHint() const +{ + constPolish(); + int l = 0; + int t = 0; + if ( children() ) { + const TQObjectList * c = children(); + TQObjectListIt it( *c ); + TQObject * o; + + while ( (o = it.current()) != 0 ) { + ++it; + if ( o->isWidgetType() && !((TQWidget*)o)->isHidden() ) { + TQSize s = qSmartMinSize( (TQWidget*)o ); + if ( s.isValid() ) { + l += pick( s ); + t = TQMAX( t, trans( s ) ); + } + } + } + } + return orientation() == Horizontal ? TQSize( l, t ) : TQSize( t, l ); +} + + +void TQSplitter::storeSizes() +{ + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( !s->isHandle ) + s->sizer = pick( s->wid->size() ); + s = d->list.next(); + } +} + + +void TQSplitter::addContribution( int id, int *min, int *max, + bool mayCollapse ) +{ + TQSplitterLayoutStruct *s = d->list.at( id ); + if ( !s->wid->isHidden() ) { + if ( s->isHandle ) { + *min += s->getSizer( orient ); + *max += s->getSizer( orient ); + } else { + if ( mayCollapse || !isCollapsed(s->wid) ) + *min += pick( qSmartMinSize(s->wid) ); + *max += pick( s->wid->maximumSize() ); + } + } +} + + +/*! + Returns a list of the size parameters of all the widgets in this + splitter. + + If the splitter's orientation is horizontal, the list is a list of + widget widths; if the orientation is vertical, the list is a list + of widget heights. + + Giving the values to another splitter's setSizes() function will + produce a splitter with the same layout as this one. + + Note that if you want to iterate over the list, you should iterate + over a copy, e.g. + \code + TQValueList list = mySplitter.sizes(); + TQValueList::Iterator it = list.begin(); + while( it != list.end() ) { + myProcessing( *it ); + ++it; + } + \endcode + + \sa setSizes() +*/ + +TQValueList TQSplitter::sizes() const +{ + if ( !testWState(WState_Polished) ) + constPolish(); + + TQValueList list; + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( !s->isHandle ) + list.append( isCollapsed(s->wid) ? 0 : pick(s->wid->size())); + s = d->list.next(); + } + return list; +} + +/*! + Sets the size parameters to the values given in the \a list. If + the splitter is horizontal, the values set the widths of each + widget going from left to right. If the splitter is vertical, the + values set the heights of each widget going from top to bottom. + Extra values in the \a list are ignored. + + If \a list contains too few values, the result is undefined but + the program will still be well-behaved. + + Note that the values in \a list should be the height/width that + the widgets should be resized to. + + \sa sizes() +*/ + +void TQSplitter::setSizes( TQValueList list ) +{ + processChildEvents(); + TQValueList::Iterator it = list.begin(); + TQSplitterLayoutStruct *s = d->list.first(); + while ( s && it != list.end() ) { + if ( !s->isHandle ) { + s->sizer = TQMAX( *it, 0 ); + int smartMinSize = pick( qSmartMinSize(s->wid) ); + // Make sure that we reset the collapsed state. + if ( s->sizer == 0 ) { + if ( collapsible(s) && smartMinSize > 0 ) { + s->wid->move( -1, -1 ); + } else { + s->sizer = smartMinSize; + s->wid->move( 0, 0 ); + } + } else { + if ( s->sizer < smartMinSize ) + s->sizer = smartMinSize; + s->wid->move( 0, 0 ); + } + ++it; + } + s = d->list.next(); + } + doResize(); +} + +/*! + \property TQSplitter::handleWidth + \brief the width of the splitter handle +*/ + +int TQSplitter::handleWidth() const +{ + if ( d->handleWidth > 0 ) { + return d->handleWidth; + } else { + return style().pixelMetric( TQStyle::PM_SplitterWidth, this ); + } +} + +void TQSplitter::setHandleWidth( int width ) +{ + d->handleWidth = width; + updateHandles(); +} + +/*! + Processes all posted child events, ensuring that the internal state of + the splitter is kept consistent. +*/ + +void TQSplitter::processChildEvents() +{ + TQApplication::sendPostedEvents( this, TQEvent::ChildInserted ); +} + +/*! + \reimp +*/ + +void TQSplitter::styleChange( TQStyle& old ) +{ + updateHandles(); + TQFrame::styleChange( old ); +} + +void TQSplitter::updateHandles() +{ + int hw = handleWidth(); + TQSplitterLayoutStruct *s = d->list.first(); + while ( s ) { + if ( s->isHandle ) + s->sizer = hw; + s = d->list.next(); + } + recalc( isVisible() ); +} + +#ifndef TQT_NO_TEXTSTREAM +/*! + \relates TQSplitter + + Writes the sizes and the hidden state of the widgets in the + splitter \a splitter to the text stream \a ts. + + \sa operator>>(), sizes(), TQWidget::isHidden() +*/ + +TQTextStream& operator<<( TQTextStream& ts, const TQSplitter& splitter ) +{ + TQSplitterLayoutStruct *s = splitter.d->list.first(); + bool first = TRUE; + ts << "["; + + while ( s != 0 ) { + if ( !s->isHandle ) { + if ( !first ) + ts << ","; + + if ( s->wid->isHidden() ) { + ts << "H"; + } else if ( isCollapsed(s->wid) ) { + ts << 0; + } else { + ts << s->getSizer( splitter.orientation() ); + } + first = FALSE; + } + s = splitter.d->list.next(); + } + ts << "]" << endl; + return ts; +} + +/*! + \relates TQSplitter + + Reads the sizes and the hidden state of the widgets in the + splitter \a splitter from the text stream \a ts. The sizes must + have been previously written by the operator<<() function. + + \sa operator<<(), setSizes(), TQWidget::hide() +*/ + +TQTextStream& operator>>( TQTextStream& ts, TQSplitter& splitter ) +{ +#undef SKIP_SPACES +#define SKIP_SPACES() \ + while ( line[i].isSpace() ) \ + i++ + + splitter.processChildEvents(); + TQSplitterLayoutStruct *s = splitter.d->list.first(); + TQString line = ts.readLine(); + int i = 0; + + SKIP_SPACES(); + if ( line[i] == '[' ) { + i++; + SKIP_SPACES(); + while ( line[i] != ']' ) { + while ( s != 0 && s->isHandle ) + s = splitter.d->list.next(); + if ( s == 0 ) + break; + + if ( line[i].upper() == 'H' ) { + s->wid->hide(); + i++; + } else { + s->wid->show(); + int dim = 0; + while ( line[i].digitValue() >= 0 ) { + dim *= 10; + dim += line[i].digitValue(); + i++; + } + s->sizer = dim; + if ( dim == 0 ) + splitter.setGeo( s->wid, 0, 0, FALSE ); + } + SKIP_SPACES(); + if ( line[i] == ',' ) { + i++; + } else { + break; + } + SKIP_SPACES(); + s = splitter.d->list.next(); + } + } + splitter.doResize(); + return ts; +} +#endif + +#endif diff --git a/src/widgets/tqsplitter.h b/src/widgets/tqsplitter.h new file mode 100644 index 000000000..bd8aef13e --- /dev/null +++ b/src/widgets/tqsplitter.h @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Definition of TQSplitter class +** +** Created : 980105 +** +** 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 TQSPLITTER_H +#define TQSPLITTER_H + +#ifndef QT_H +#include "tqframe.h" +#include "tqvaluelist.h" +#endif // QT_H + +#ifndef TQT_NO_SPLITTER + +#define QT_QSPLITTER_DEFAULT 2 + +class TQSplitterHandle; +class TQSplitterPrivate; +class TQSplitterLayoutStruct; +class TQTextStream; + +class TQSplitterPrivate +{ +public: + TQSplitterPrivate() + : opaque( FALSE ), firstShow( TRUE ), childrenCollapsible( TRUE ), + handleWidth( 0 ) { } + + TQPtrList list; + bool opaque; + bool firstShow; + bool childrenCollapsible; + int handleWidth; +}; + +class TQ_EXPORT TQSplitterLayoutStruct : public TQt +{ +public: + TQCOORD sizer; + uint isHandle; + uint collapsible; + uint resizeMode; + TQWidget *wid; + + TQSplitterLayoutStruct() + : sizer( -1 ), collapsible( QT_QSPLITTER_DEFAULT ) { } + TQCOORD getSizer( Orientation orient ); +}; + +class TQ_EXPORT TQSplitter : public TQFrame +{ + TQ_OBJECT + TQ_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) + TQ_PROPERTY( bool opaqueResize READ opaqueResize WRITE setOpaqueResize ) + TQ_PROPERTY( int handleWidth READ handleWidth WRITE setHandleWidth ) + TQ_PROPERTY( bool childrenCollapsible READ childrenCollapsible WRITE setChildrenCollapsible ) + +public: + // ### TQt 4.0: remove Auto from public API + enum ResizeMode { Stretch, KeepSize, FollowSizeHint, Auto }; + + TQSplitter( TQWidget* parent = 0, const char* name = 0 ); + TQSplitter( Orientation, TQWidget* parent = 0, const char* name = 0 ); + ~TQSplitter(); + + virtual void setOrientation( Orientation ); + Orientation orientation() const { return orient; } + + // ### TQt 4.0: make setChildrenCollapsible() and setCollapsible() virtual + + void setChildrenCollapsible( bool ); + bool childrenCollapsible() const; + + void setCollapsible( TQWidget *w, bool ); + virtual void setResizeMode( TQWidget *w, ResizeMode ); + virtual void setOpaqueResize( bool = TRUE ); + bool opaqueResize() const; + + void moveToFirst( TQWidget * ); + void moveToLast( TQWidget * ); + + void refresh() { recalc( TRUE ); } + TQSize sizeHint() const; + TQSize minimumSizeHint() const; + + TQValueList sizes() const; + void setSizes( TQValueList ); + + int handleWidth() const; + void setHandleWidth( int ); + +protected: + void childEvent( TQChildEvent * ); + + bool event( TQEvent * ); + void resizeEvent( TQResizeEvent * ); + + int idAfter( TQWidget* ) const; + + void moveSplitter( TQCOORD pos, int id ); + virtual void drawSplitter( TQPainter*, TQCOORD x, TQCOORD y, + TQCOORD w, TQCOORD h ); + void styleChange( TQStyle& ); + int adjustPos( int, int ); + virtual void setRubberband( int ); + void getRange( int id, int *, int * ); + +public: //private: + enum { DefaultResizeMode = 3 }; + + void init(); + void recalc( bool update = FALSE ); + void doResize(); + void storeSizes(); + void getRange( int id, int *, int *, int *, int * ); + void addContribution( int, int *, int *, bool ); + int adjustPos( int, int, int *, int *, int *, int * ); + bool collapsible( TQSplitterLayoutStruct * ); + void processChildEvents(); + TQSplitterLayoutStruct *findWidget( TQWidget * ); + TQSplitterLayoutStruct *addWidget( TQWidget *, bool prepend = FALSE ); + void recalcId(); + void doMove( bool backwards, int pos, int id, int delta, bool upLeft, + bool mayCollapse ); + void setGeo( TQWidget *w, int pos, int size, bool splitterMoved ); + int findWidgetJustBeforeOrJustAfter( int id, int delta, int &collapsibleSize ); + void updateHandles(); + + inline TQCOORD pick( const TQPoint &p ) const + { return orient == Horizontal ? p.x() : p.y(); } + inline TQCOORD pick( const TQSize &s ) const + { return orient == Horizontal ? s.width() : s.height(); } + + inline TQCOORD trans( const TQPoint &p ) const + { return orient == Vertical ? p.x() : p.y(); } + inline TQCOORD trans( const TQSize &s ) const + { return orient == Vertical ? s.width() : s.height(); } + + TQSplitterPrivate *d; + + Orientation orient; + friend class TQSplitterHandle; + friend class TQTextStream; + +private: +#if defined(TQ_DISABLE_COPY) + TQSplitter( const TQSplitter & ); + TQSplitter& operator=( const TQSplitter & ); +#endif +}; + +#ifndef TQT_NO_TEXTSTREAM +TQ_EXPORT TQTextStream& operator<<( TQTextStream&, const TQSplitter& ); +TQ_EXPORT TQTextStream& operator>>( TQTextStream&, TQSplitter& ); +#endif + +class TQ_EXPORT TQSplitterHandle : public TQWidget +{ + TQ_OBJECT +public: + TQSplitterHandle( Orientation o, + TQSplitter *parent, const char* name=0 ); + void setOrientation( Orientation o ); + Orientation orientation() const { return orient; } + + bool opaque() const { return s->opaqueResize(); } + + TQSize sizeHint() const; + + int id() const { return myId; } // d->list.at(id())->wid == this + void setId( int i ) { myId = i; } + +protected: + void paintEvent( TQPaintEvent * ); + void mouseMoveEvent( TQMouseEvent * ); + void mousePressEvent( TQMouseEvent * ); + void mouseReleaseEvent( TQMouseEvent * ); + +public: // private: + Orientation orient; + bool opaq; + int myId; + + TQSplitter *s; +}; + +#endif // TQT_NO_SPLITTER + +#endif // TQSPLITTER_H diff --git a/src/widgets/tqwhatsthis.cpp b/src/widgets/tqwhatsthis.cpp index 242016454..4b38a43d5 100644 --- a/src/widgets/tqwhatsthis.cpp +++ b/src/widgets/tqwhatsthis.cpp @@ -45,7 +45,7 @@ #include "tqtimer.h" #include "tqptrdict.h" #include "tqtoolbutton.h" -#include "ntqshared.h" +#include "tqshared.h" #include "tqcursor.h" #include "tqbitmap.h" #include "tqtooltip.h" -- cgit v1.2.1