qwt_dyngrid_layout.h 2.29 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_DYNGRID_LAYOUT_H
#define QWT_DYNGRID_LAYOUT_H

Bryant's avatar
Bryant committed
13
#include "qwt_global.h"
pixhawk's avatar
pixhawk committed
14 15 16 17 18 19 20
#include <qlayout.h>
#include <qsize.h>
#include <qlist.h>

/*!
  \brief The QwtDynGridLayout class lays out widgets in a grid,
         adjusting the number of columns and rows to the current size.
21 22 23

  QwtDynGridLayout takes the space it gets, divides it up into rows and
  columns, and puts each of the widgets it manages into the correct cell(s).
Bryant's avatar
Bryant committed
24
  It lays out as many number of columns as possible (limited by maxColumns()).
pixhawk's avatar
pixhawk committed
25 26 27 28 29 30
*/

class QWT_EXPORT QwtDynGridLayout : public QLayout
{
    Q_OBJECT
public:
Bryant's avatar
Bryant committed
31 32
    explicit QwtDynGridLayout( QWidget *, int margin = 0, int space = -1 );
    explicit QwtDynGridLayout( int space = -1 );
pixhawk's avatar
pixhawk committed
33 34 35 36 37

    virtual ~QwtDynGridLayout();

    virtual void invalidate();

Bryant's avatar
Bryant committed
38 39
    void setMaxColumns( uint maxCols );
    uint maxColumns() const;
pixhawk's avatar
pixhawk committed
40

41
    uint numRows () const;
Bryant's avatar
Bryant committed
42
    uint numColumns () const;
pixhawk's avatar
pixhawk committed
43

Bryant's avatar
Bryant committed
44
    virtual void addItem( QLayoutItem * );
pixhawk's avatar
pixhawk committed
45 46 47 48 49

    virtual QLayoutItem *itemAt( int index ) const;
    virtual QLayoutItem *takeAt( int index );
    virtual int count() const;

Bryant's avatar
Bryant committed
50
    void setExpandingDirections( Qt::Orientations );
pixhawk's avatar
pixhawk committed
51
    virtual Qt::Orientations expandingDirections() const;
Bryant's avatar
Bryant committed
52
    QList<QRect> layoutItems( const QRect &, uint numCols ) const;
pixhawk's avatar
pixhawk committed
53 54 55

    virtual int maxItemWidth() const;

Bryant's avatar
Bryant committed
56
    virtual void setGeometry( const QRect &rect );
pixhawk's avatar
pixhawk committed
57 58

    virtual bool hasHeightForWidth() const;
Bryant's avatar
Bryant committed
59
    virtual int heightForWidth( int ) const;
pixhawk's avatar
pixhawk committed
60 61 62 63 64 65

    virtual QSize sizeHint() const;

    virtual bool isEmpty() const;
    uint itemCount() const;

Bryant's avatar
Bryant committed
66
    virtual uint columnsForWidth( int width ) const;
pixhawk's avatar
pixhawk committed
67 68 69

protected:

Bryant's avatar
Bryant committed
70 71 72 73
    void layoutGrid( uint numCols,
        QVector<int>& rowHeight, QVector<int>& colWidth ) const;
    void stretchGrid( const QRect &rect, uint numCols,
        QVector<int>& rowHeight, QVector<int>& colWidth ) const;
pixhawk's avatar
pixhawk committed
74 75 76

private:
    void init();
Bryant's avatar
Bryant committed
77
    int maxRowWidth( int numCols ) const;
pixhawk's avatar
pixhawk committed
78

79
    class PrivateData;
pixhawk's avatar
pixhawk committed
80 81 82 83
    PrivateData *d_data;
};

#endif