home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qheader.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  7KB  |  196 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qheader.h   3.0.0   edited Oct 9 19:14 $
  3. **
  4. ** Definition of QHeader widget class (table header)
  5. **
  6. ** Created : 961105
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the widgets module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QHEADER_H
  39. #define QHEADER_H
  40.  
  41. #ifndef QT_H
  42. #include "qwidget.h"
  43. #include "qstring.h"
  44. #include "qiconset.h" // conversion QPixmap->QIconset
  45. #endif // QT_H
  46.  
  47. #ifndef QT_NO_HEADER
  48.  
  49. class QShowEvent;
  50. class QHeaderData;
  51.  
  52. class Q_EXPORT QHeader : public QWidget
  53. {
  54.     Q_OBJECT
  55.     Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
  56.     Q_PROPERTY( bool tracking READ tracking WRITE setTracking )
  57.     Q_PROPERTY( int count READ count )
  58.     Q_PROPERTY( int offset READ offset WRITE setOffset )
  59.     Q_PROPERTY( bool moving READ isMovingEnabled WRITE setMovingEnabled )
  60.     Q_PROPERTY( bool stretching READ isStretchEnabled WRITE setStretchEnabled )
  61.  
  62. public:
  63.     QHeader( QWidget* parent=0, const char* name=0 );
  64.     QHeader( int, QWidget* parent=0, const char* name=0 );
  65.     ~QHeader();
  66.  
  67.     int        addLabel( const QString &, int size = -1 );
  68.     int        addLabel( const QIconSet&, const QString &, int size = -1 );
  69.     void     removeLabel( int section );
  70.     virtual void setLabel( int, const QString &, int size = -1 );
  71.     virtual void setLabel( int, const QIconSet&, const QString &, int size = -1 );
  72.     QString     label( int section ) const;
  73.     QIconSet*     iconSet( int section ) const;
  74.  
  75.     virtual void setOrientation( Orientation );
  76.     Orientation orientation() const;
  77.     virtual void setTracking( bool enable );
  78.     bool    tracking() const;
  79.  
  80.     virtual void setClickEnabled( bool, int section = -1 );
  81.     virtual void setResizeEnabled( bool, int section = -1 );
  82.     virtual void setMovingEnabled( bool );
  83.     virtual void setStretchEnabled( bool b, int section );
  84.     void setStretchEnabled( bool b ) { setStretchEnabled( b, -1 ); }
  85.     bool isClickEnabled( int section = -1 ) const;
  86.     bool isResizeEnabled( int section = -1 ) const;
  87.     bool isMovingEnabled() const;
  88.     bool isStretchEnabled() const;
  89.     bool isStretchEnabled( int section ) const;
  90.  
  91.     void     resizeSection( int section, int s );
  92.     int        sectionSize( int section ) const;
  93.     int        sectionPos( int section ) const;
  94.     int        sectionAt( int pos ) const;
  95.     int        count() const;
  96.     int headerWidth() const;
  97.     QRect    sectionRect( int section ) const;
  98.  
  99.     virtual void setCellSize( int , int ); // obsolete, do not use
  100.     int        cellSize( int i ) const { return sectionSize( mapToSection(i) ); } // obsolete, do not use
  101.     int        cellPos( int ) const; // obsolete, do not use
  102.     int        cellAt( int pos ) const { return mapToIndex( sectionAt(pos + offset()) ); } // obsolete, do not use
  103.  
  104.     int     offset() const;
  105.  
  106.     QSize    sizeHint() const;
  107.  
  108.     int        mapToSection( int index ) const;
  109.     int        mapToIndex( int section ) const;
  110.     int        mapToLogical( int ) const; // obsolete, do not use
  111.     int        mapToActual( int ) const; // obsolete, do not use
  112.  
  113.     void     moveSection( int section, int toIndex );
  114.     virtual void moveCell( int, int); // obsolete, do not use
  115.  
  116.     void     setSortIndicator( int section, bool increasing = TRUE );
  117.     void adjustHeaderSize() { adjustHeaderSize( -1 ); }
  118.  
  119. public slots:
  120.     void setUpdatesEnabled( bool enable );
  121.     virtual void setOffset( int pos );
  122.  
  123. signals:
  124.     void    clicked( int section );
  125.     void    pressed( int section );
  126.     void    released( int section );
  127.     void    sizeChange( int section, int oldSize, int newSize );
  128.     void    indexChange( int section, int fromIndex, int toIndex );
  129.     void    sectionClicked( int ); // obsolete, do not use
  130.     void    moved( int, int ); // obsolete, do not use
  131.  
  132. protected:
  133.     void    paintEvent( QPaintEvent * );
  134.     void    showEvent( QShowEvent *e );
  135.     void     resizeEvent( QResizeEvent *e );
  136.     QRect    sRect( int index );
  137.  
  138.     virtual void    paintSection( QPainter *p, int index, const QRect& fr);
  139.     virtual void    paintSectionLabel( QPainter* p, int index, const QRect& fr );
  140.  
  141.     void    mousePressEvent( QMouseEvent * );
  142.     void    mouseReleaseEvent( QMouseEvent * );
  143.     void    mouseMoveEvent( QMouseEvent * );
  144.     
  145. private:
  146.     void adjustHeaderSize( int diff );
  147.     void    init( int );
  148.  
  149.     void    paintRect( int p, int s );
  150.     void    markLine( int idx );
  151.     void    unMarkLine( int idx );
  152.     int        pPos( int i ) const;
  153.     int        pSize( int i ) const;
  154.     int        pHeight( int i ) const;
  155.     void    setPHeight( int i, int h );
  156.     int     findLine( int );
  157.     bool reverse() const;
  158.     void calculatePositions( bool onlyVisible = FALSE, int start = 0 );
  159.     void    handleColumnResize(int, int, bool, bool = TRUE );
  160.     void    setSectionSizeAndHeight( int section, int size,
  161.                      const QString& s );
  162.  
  163.     int        offs;
  164.     int        handleIdx;
  165.     int        oldHIdxSize;
  166.     int        moveToIdx;
  167.     enum State { Idle, Sliding, Pressed, Moving, Blocked };
  168.     State    state;
  169.     QCOORD    clickPos;
  170.     bool    trackingIsOn;
  171.     int       cachedIdx; // not used
  172.     int    cachedPos; // not used
  173.     Orientation orient;
  174.  
  175.     QHeaderData *d;
  176.  
  177. private:    // Disabled copy constructor and operator=
  178. #if defined(Q_DISABLE_COPY)
  179.     QHeader( const QHeader & );
  180.     QHeader &operator=( const QHeader & );
  181. #endif
  182. };
  183.  
  184.  
  185. inline QHeader::Orientation QHeader::orientation() const
  186. {
  187.     return orient;
  188. }
  189.  
  190. inline void QHeader::setTracking( bool enable ) { trackingIsOn = enable; }
  191. inline bool QHeader::tracking() const { return trackingIsOn; }
  192.  
  193. #endif // QT_NO_HEADER
  194.  
  195. #endif // QHEADER_H
  196.