summaryrefslogtreecommitdiffstats
path: root/examples/customlayout/border.h
blob: 240f9859a7a087027ed8fdda7a56c7f5fe32a3ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/****************************************************************************
**
** Definition of simple flow layout for custom layout example
**
** Created : 979899
**
** Copyright (C) 1997-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef BORDER_H
#define BORDER_H

#include <tqlayout.h>
#include <tqptrlist.h>

class BorderWidgetItem : public TQWidgetItem
{
public:
    BorderWidgetItem( TQWidget *w )
	: TQWidgetItem( w )
    {}

    void setGeometry( const TQRect &r )
    { widget()->setGeometry( r ); }

};

class BorderLayout : public TQLayout
{
public:
    enum Position {
	West = 0,
	North,
	South,
	East,
	Center
    };

    struct BorderLayoutStruct
    {
	BorderLayoutStruct( TQLayoutItem *i, Position p ) {
	    item = i;
	    pos = p;
	}

	TQLayoutItem *item;
	Position pos;
    };

    enum SizeType {
	Minimum = 0,
	SizeHint
    };

    BorderLayout( TQWidget *parent, int border = 0, int autoBorder = -1,
		  const char *name = 0 )
	: TQLayout( parent, border, autoBorder, name ), cached( 0, 0 ), mcached( 0, 0 ),
	  sizeDirty( TRUE ), msizeDirty( TRUE )
    {}

    BorderLayout( TQLayout* parent, int autoBorder = -1, const char *name = 0 )
	: TQLayout( parent, autoBorder, name  ), cached( 0, 0 ), mcached( 0, 0 ),
	  sizeDirty( TRUE ), msizeDirty( TRUE )
    {}

    BorderLayout( int autoBorder = -1, const char *name = 0 )
	: TQLayout( autoBorder, name ), cached( 0, 0 ), mcached( 0, 0 ),
	  sizeDirty( TRUE ), msizeDirty( TRUE )
    {}

    ~BorderLayout();

    void addItem( TQLayoutItem *item );

    void addWidget( TQWidget *widget, Position pos );
    void add( TQLayoutItem *item, Position pos );

    bool hasHeightForWidth() const;

    TQSize sizeHint() const;
    TQSize minimumSize() const;

    TQLayoutIterator iterator();

    TQSizePolicy::ExpandData expanding() const;

protected:
    void setGeometry( const TQRect &rect );

private:
    void doLayout( const TQRect &rect, bool testonly = FALSE );
    void calcSize( SizeType st );

    TQPtrList<BorderLayoutStruct> list;
    TQSize cached, mcached;
    bool sizeDirty, msizeDirty;

};

#endif