summaryrefslogtreecommitdiffstats
path: root/src/newui/buttonbar.h
blob: 8b94f777d5978c82bcb7a19b46a141b7b17c5838 (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
105
106
107
108
109
110
111
112
113
/***************************************************************************
 *   Copyright (C) 2004 by Alexander Dymo                                  *
 *   adymo@kdevelop.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#ifndef IDEALBUTTONBAR_H
#define IDEALBUTTONBAR_H

#include <tqwidget.h>
#include <tqvaluelist.h>

#include "comdefs.h"

#include <tqlayout.h>

namespace Ideal {

class Button;
class ButtonBar;

/**@short A tqlayout for a ButtonBar class.

Overrides minimumSize method to allow shrinking button bar buttons.*/
class ButtonLayout: public TQBoxLayout{
public:
    ButtonLayout(ButtonBar *parent, Direction d, int margin = 0, int spacing = -1, const char * name = 0);

    virtual TQSize minimumSize() const;

private:
    ButtonBar *m_buttonBar;
};

/**
@short A bar with tool buttons.

Looks like a toolbar but has another behaviour. It is suitable for
placing on the left(right, bottom, top) corners of a window as a bar with slider.
*/
class ButtonBar : public TQWidget {
    Q_OBJECT
  TQ_OBJECT
public:
    ButtonBar(Place place, ButtonMode mode = IconsAndText,
        TQWidget *parent = 0, const char *name = 0);
    virtual ~ButtonBar();

    /**Adds a button to the bar.*/
    virtual void addButton(Button *button);
    /**Removes a button from the bar and deletes the button.*/
    virtual void removeButton(Button *button);

    /**Sets the mode.*/
    void setMode(ButtonMode mode);
    /**@returns the mode.*/
    ButtonMode mode() const;

    /**@returns the place.*/
    Place place() const;

    bool autoResize() const;
    void setAutoResize(bool b);

    /**Shrinks the button bar so all buttons are visible. Shrinking is done by
    reducing the amount of text shown on buttons. Button icon size is a minimum size
    of a button. If a button does not have an icon, it displays "...".*/
    virtual void shrink(int preferredDimension, int actualDimension);
    virtual void deshrink(int preferredDimension, int actualDimension);
    /**Restores the size of button bar buttons.*/
    virtual void unshrink();

    Button *firstButton();
    Button *nextTo(Button *button);
    Button *prevTo(Button *button);

protected:
    virtual void resizeEvent ( TQResizeEvent *ev );

    int originalDimension();

private:
    void fixDimensions();
    void setButtonsPlace(Ideal::Place place);

    typedef TQValueList<Button*> ButtonList;
    ButtonList m_buttons;

    ButtonMode m_mode;
    Place m_place;

    ButtonLayout *l;

    bool m_shrinked;
    bool m_autoResize;
};

}

#endif