summaryrefslogtreecommitdiffstats
path: root/kdeui/kstatusbar.h
blob: 5f2b6a869de87b6f36998cb96f7e25b0fd58b465 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* This file is part of the KDE libraries
   Copyright (C) 1997 Mark Donohoe (donohoe@kde.org)
   Copyright (C) 1997, 1998 1998 Sven Radej (sven@lisa.exp.univie.ac.at)

   This library 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 library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __KSTATUSBAR_H__
#define __KSTATUSBAR_H__

#include <tqstatusbar.h>
#include <tqintdict.h>
#include <tqlabel.h>
#include <kdelibs_export.h>

class KStatusBar;

/**
 *  Internal label class for use in KStatusBar
 *  @internal
 */
class KDEUI_EXPORT KStatusBarLabel : public TQLabel
{
  Q_OBJECT

public:


  KStatusBarLabel( const TQString& text, int _id, KStatusBar* parent = 0L, const char *name=0L );
  ~KStatusBarLabel () {}

protected:

  void mousePressEvent (TQMouseEvent* _event);
  void mouseReleaseEvent (TQMouseEvent* _event);

private:

  int id;

signals:

  void itemPressed (int id);
  void itemReleased (int id);
};

/**
 *  @short %KDE statusbar widget
 *
 *  Display status messages.
 *
 *  You can insert text labels or custom widgets. Their geometry is managed
 *  internally. KStatusBar resizes itself, but positioning is left to
 *  KMainWindow (or to you, if you don't use KMainWindow ).
 *
 *  A special type of item is a message which is a temporary text-message
 *  displayed on top of other items in full-width. Messages are visible for
 *  specified time, or until you call the slot TQStatusBar::clear(). See
 *  TQStatusBar::message for details.
 *
 *  It is useful to connect the KActionCollection signals to the
 *  TQStatusBar::message slots.
 *
 *  KStatusBar inherits TQStatusBar, you can freely use all QStatusBar
 *  methods.
 *
 *  Empty text items are not visible. They will become visible when you change
 *  (add) text.
 *
 *  @author Mark Donohoe (donohoe@kde.org) Maintained by Sven Radej <radej@kde.org>

 *  @see KActionCollection
 */
class KDEUI_EXPORT KStatusBar : public TQStatusBar
{
  Q_OBJECT

public:
  /**
   * @deprecated
   * WARNING: This enum is only for backward compatibility and it may be removed.
   * No method here uses it.
   */
  enum BarStatus{ Toggle, Show, Hide };

  /**
   *  Constructs a status bar. @p parent is usually KMainWindow.
   */
  KStatusBar( TQWidget* parent = 0L, const char* name = 0L );

  /**
   *  Destructor.
   *
   *  Deletes all internal objects.
   */
  ~KStatusBar();

  /**
   *  Inserts a text label into the status bar.
   *  Parameters @p stretch and  @p permanent are passed to
   * TQStatusBar::addWidget .
   *
   *  If @p permanent is true, then item will be placed on the far right of
   *  the statusbar and will never be hidden by TQStatusBar::message.
   *
   *  @param text The label's text string.
   *  @param id id of item
   *  @param stretch stretch passed to TQStatusBar::addWidget
   *  @param permanent is item permanent or not (passed to TQStatusBar::addWidget )
   *
   *  @see QStatusbar::addWidget
   *
   */
  void insertItem(const TQString& text, int id, int stretch=0, bool permanent=false );

  /**
   *  Inserts a fixed width text label into status bar. The width will be set
   *  according to @p text, but will remain fixed even if you change text.
   *  You can change fixed width by calling setItemFixed.
   *
   *  @param text The label's text string
   *  @param id id of item
   *  @param permanent permanent flag passed to TQStatusBar::addWidget
   */
  inline void insertFixedItem(const TQString& text, int id, bool permanent=false)
               { insertItem(text, id, 0, permanent); setItemFixed(id); }

  /**
   *  Removes an item.
   *
   * @param id The item to remove.
   */
  void removeItem( int id );

  /**
   *  @since 3.2
   *
   *  Returns true if an item with @p id exists already in KStatusBar,
   *  otherwise returns false.
   *
   *  @param id id of the item
   */
  bool hasItem( int id ) const;

  /**
   * Changes the text in a status bar field.
   *
   * The item will be resized to fit the text. If you change text to be empty,
   * item will not be visible (untill you add some text).
   *
   * @param text The label's text string
   * @param id The id of item.
   */
  void changeItem( const TQString& text, int id );

  /**
   * Sets the alignment of item @p id. By default all fields are aligned
   * @p AlignHCenter | @p AlignVCenter. See TQLabel::setAlignment for details.
   *
  */
  void setItemAlignment(int id, int align);

  /**
   * Sets item @p id to have fixed width. This cannot be undone, but you can
   * always set new fixed width.
   *
   * @param id id of item
   * @param width fixed width in pixels. Default -1 is to adapt to text width.
   */
  void setItemFixed(int id, int width=-1);

signals:

  /**
   *  Emitted when mouse is pressed over item @p id.
   *
   *  Connect to this signal if you want to respond to mouse press events.
   *
   */
  void pressed( int );

  /**
   *  Emitted when mouse is released over item @p id.
   *
   *  Connect to this signal if you want to respond to mouse release events (clicks).
   */
  void released( int );

private:
  TQIntDict<KStatusBarLabel> items;
  class KStatusBarPrivate* d;
};

#endif // __KSTATUSBAR_H__