summaryrefslogtreecommitdiffstats
path: root/src/newui/button.h
blob: 86e7dbedd414c4c8b279fc3a5139bccec34deeaf (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
/***************************************************************************
 *   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 IDEALBUTTON_H
#define IDEALBUTTON_H

#include <tqpushbutton.h>
#include <tqiconset.h>

#include "comdefs.h"

class KAction;

namespace Ideal {

class ButtonBar;

/**
@short A button to place onto the ButtonBar

A TQPushButton derivative with a size of a TQToolBar. Button can be rotated
(placed onto different places in ideal mode).
*/
class Button : public TQPushButton {
    Q_OBJECT
public:
    Button(ButtonBar *parent, const TQString text, const TQIconSet &icon = TQIconSet(),
        const TQString &description = TQString::null);

    /**Sets the description used as a tooltip.*/
    void setDescription(const TQString &description);
    /**Returns the description.*/
    TQString description() const;

    /**Sets the place of a button.*/
    void setPlace(Ideal::Place place);
    /**Sets the mode of a button.*/
    void setMode(Ideal::ButtonMode mode);

    TQSize sizeHint() const;
    TQSize sizeHint(const TQString &text) const;

    /**Updates size of a widget. Used after squeezing button's text.*/
    void updateSize();

    /**Returns the real (i.e. not squeezed) text of a button.*/
    TQString realText() const;
    TQString realTextWithoutAccel() const;
    void setRealText(const TQString &text);

protected:
    ButtonMode mode();

    virtual void drawButton(TQPainter *p);
    virtual void drawButtonLabel(TQPainter *p);

    virtual void contextMenuEvent(TQContextMenuEvent *e);

protected slots:
    void assignAccel();
    void clearAccel();

signals:
    void contextMenu(TQPopupMenu*);

private:
    virtual ~Button();

    void fixDimensions(Place oldPlace);

    void enableIconSet();
    void disableIconSet();
    void enableText();
    void disableText();

    ButtonBar *m_buttonBar;

    TQString m_description;
    Place m_place;

    TQString m_realText;
    TQIconSet m_realIconSet;

    KAction *m_assignAccelAction;
    KAction *m_clearAccelAction;

friend class ButtonBar;
};

}

#endif