• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdemdi
 

tdemdi

  • tdemdi
tdemditaskbar.cpp
1//----------------------------------------------------------------------------
2// filename : tdemditaskbar.cpp
3//----------------------------------------------------------------------------
4// Project : KDE MDI extension
5//
6// begin : 07/1999 by Szymon Stefanek as part of kvirc
7// (an IRC application)
8// changes : 09/1999 by Falk Brettschneider to create an
9// - 06/2000 stand-alone Qt extension set of
10// classes and a Qt-based library
11// 2000-2003 maintained by the KDevelop project
12// patches : 02/2000 by Massimo Morin (mmorin@schedsys.com)
13//
14// copyright : (C) 1999-2003 by Szymon Stefanek (stefanek@tin.it)
15// and
16// Falk Brettschneider
17// email : falkbr@kdevelop.org (Falk Brettschneider)
18//----------------------------------------------------------------------------
19//
20//----------------------------------------------------------------------------
21//
22// This program is free software; you can redistribute it and/or modify
23// it under the terms of the GNU Library General Public License as
24// published by the Free Software Foundation; either version 2 of the
25// License, or (at your option) any later version.
26//
27//----------------------------------------------------------------------------
28
29#ifdef None
30#undef None
31#endif
32
33#include "tdemditaskbar.h"
34#include "tdemditaskbar.moc"
35
36#include "tdemdimainfrm.h"
37#include "tdemdichildview.h"
38#include "tdemdidefines.h"
39
40#include <tqtooltip.h>
41#include <tqlabel.h>
42#include <tqwidget.h>
43#include <tqstyle.h>
44
45#include <tqnamespace.h>
46
47/*
48 @quickhelp: KMdiTaskBar
49 @widget: Taskbar
50 This window lists the currently open windows.<br>
51 Each button corresponds to a single MDI (child) window.<br>
52 The button is enabled (clickable) when the window is docked , and can be
53 pressed to bring it to the top of the other docked windows.<br>
54 The button text becomes red when new output is shown in the window and it is not the active one.<br>
55*/
56
57//####################################################################
58//
59// KMdiTaskBarButton
60//
61//####################################################################
62KMdiTaskBarButton::KMdiTaskBarButton( KMdiTaskBar *pTaskBar, KMdiChildView *win_ptr )
63 : TQPushButton( pTaskBar ),
64 m_actualText( "" )
65{
66 setToggleButton( true );
67 m_pWindow = win_ptr;
68 TQToolTip::add
69 ( this, win_ptr->caption() );
70 setFocusPolicy( TQWidget::NoFocus );
71}
72
73KMdiTaskBarButton::~KMdiTaskBarButton()
74{}
75
76void KMdiTaskBarButton::mousePressEvent( TQMouseEvent* e )
77{
78 switch ( e->button() )
79 {
80 case TQt::LeftButton:
81 emit leftMouseButtonClicked( m_pWindow );
82 break;
83 case TQt::RightButton:
84 emit rightMouseButtonClicked( m_pWindow );
85 break;
86 default:
87 break;
88 }
89 emit clicked( m_pWindow );
90}
91
93void KMdiTaskBarButton::setNewText( const TQString& s )
94{
95 setText( s );
96 emit buttonTextChanged( 0 );
97}
98
99void KMdiTaskBarButton::setText( const TQString& s )
100{
101 m_actualText = s;
102 TQButton::setText( s );
103}
104
105void KMdiTaskBarButton::fitText( const TQString& origStr, int newWidth )
106{
107 TQButton::setText( m_actualText );
108
109 int actualWidth = sizeHint().width();
110 int realLetterCount = origStr.length();
111 int newLetterCount = ( newWidth * realLetterCount ) / actualWidth;
112 int w = newWidth + 1;
113 TQString s = origStr;
114 while ( ( w > newWidth ) && ( newLetterCount >= 1 ) )
115 {
116 if ( newLetterCount < realLetterCount )
117 {
118 if ( newLetterCount > 3 )
119 s = origStr.left( newLetterCount / 2 ) + "..." + origStr.right( newLetterCount / 2 );
120 else
121 {
122 if ( newLetterCount > 1 )
123 s = origStr.left( newLetterCount ) + "..";
124 else
125 s = origStr.left( 1 );
126 }
127 }
128 TQFontMetrics fm = fontMetrics();
129 w = fm.width( s );
130 newLetterCount--;
131 }
132
133 TQButton::setText( s );
134}
135
136TQString KMdiTaskBarButton::actualText() const
137{
138 return m_actualText;
139}
140
141//####################################################################
142//
143// KMdiTaskBar
144//
145//####################################################################
146
147KMdiTaskBar::KMdiTaskBar( KMdiMainFrm *parent, TQMainWindow::ToolBarDock dock )
148 : TDEToolBar( parent, "KMdiTaskBar", /*honor_style*/ false, /*readConfig*/ true )
149 , m_pCurrentFocusedWindow( 0 )
150 , m_pStretchSpace( 0 )
151 , m_layoutIsPending( false )
152 , m_bSwitchedOn( false )
153{
154 m_pFrm = parent;
155 m_pButtonList = new TQPtrList<KMdiTaskBarButton>;
156 m_pButtonList->setAutoDelete( true );
157 //QT30 setFontPropagation(TQWidget::SameFont);
158 setMinimumWidth( 1 );
159 setFocusPolicy( TQWidget::NoFocus );
160 parent->moveToolBar( this, dock ); //XXX obsolete!
161}
162
163KMdiTaskBar::~KMdiTaskBar()
164{
165 delete m_pButtonList;
166}
167
168KMdiTaskBarButton * KMdiTaskBar::addWinButton( KMdiChildView *win_ptr )
169{
170 if ( m_pStretchSpace )
171 {
172 delete m_pStretchSpace;
173 m_pStretchSpace = 0L;
174 setStretchableWidget( 0L );
175 }
176
177 KMdiTaskBarButton *b = new KMdiTaskBarButton( this, win_ptr );
178 TQObject::connect( b, TQ_SIGNAL( clicked() ), win_ptr, TQ_SLOT( setFocus() ) );
179 TQObject::connect( b, TQ_SIGNAL( clicked( KMdiChildView* ) ), this, TQ_SLOT( setActiveButton( KMdiChildView* ) ) );
180 TQObject::connect( b, TQ_SIGNAL( leftMouseButtonClicked( KMdiChildView* ) ), m_pFrm, TQ_SLOT( activateView( KMdiChildView* ) ) );
181 TQObject::connect( b, TQ_SIGNAL( rightMouseButtonClicked( KMdiChildView* ) ), m_pFrm, TQ_SLOT( taskbarButtonRightClicked( KMdiChildView* ) ) );
182 TQObject::connect( b, TQ_SIGNAL( buttonTextChanged( int ) ), this, TQ_SLOT( layoutTaskBar( int ) ) );
183 m_pButtonList->append( b );
184 b->setToggleButton( true );
185 b->setText( win_ptr->tabCaption() );
186
187 layoutTaskBar();
188
189 m_pStretchSpace = new TQLabel( this, "empty" );
190 m_pStretchSpace->setText( "" );
191 setStretchableWidget( m_pStretchSpace );
192 m_pStretchSpace->show();
193
194 if ( m_bSwitchedOn )
195 {
196 b->show();
197 show();
198 }
199 return b;
200}
201
202void KMdiTaskBar::removeWinButton( KMdiChildView *win_ptr, bool haveToLayoutTaskBar )
203{
204 KMdiTaskBarButton * b = getButton( win_ptr );
205 if ( b )
206 {
207 m_pButtonList->removeRef( b );
208 if ( haveToLayoutTaskBar )
209 layoutTaskBar();
210 }
211 if ( m_pButtonList->count() == 0 )
212 {
213 if ( m_pStretchSpace != 0L )
214 {
215 delete m_pStretchSpace;
216 m_pStretchSpace = 0L;
217 hide();
218 }
219 }
220}
221
222void KMdiTaskBar::switchOn( bool bOn )
223{
224 m_bSwitchedOn = bOn;
225 if ( !bOn )
226 {
227 hide();
228 }
229 else
230 {
231 if ( m_pButtonList->count() > 0 )
232 {
233 show();
234 }
235 else
236 {
237 hide();
238 }
239 }
240}
241
242KMdiTaskBarButton * KMdiTaskBar::getButton( KMdiChildView *win_ptr )
243{
244 for ( KMdiTaskBarButton * b = m_pButtonList->first();b;b = m_pButtonList->next() )
245 {
246 if ( b->m_pWindow == win_ptr )
247 return b;
248 }
249 return 0;
250}
251
252KMdiTaskBarButton * KMdiTaskBar::getNextWindowButton( bool bRight, KMdiChildView *win_ptr )
253{
254 if ( bRight )
255 {
256 for ( KMdiTaskBarButton * b = m_pButtonList->first();b;b = m_pButtonList->next() )
257 {
258 if ( b->m_pWindow == win_ptr )
259 {
260 b = m_pButtonList->next();
261 if ( !b )
262 b = m_pButtonList->first();
263 if ( win_ptr != b->m_pWindow )
264 return b;
265 else
266 return 0;
267 }
268 }
269 }
270 else
271 {
272 for ( KMdiTaskBarButton * b = m_pButtonList->first();b;b = m_pButtonList->next() )
273 {
274 if ( b->m_pWindow == win_ptr )
275 {
276 b = m_pButtonList->prev();
277 if ( !b )
278 b = m_pButtonList->last();
279 if ( win_ptr != b->m_pWindow )
280 return b;
281 else
282 return 0;
283 }
284 }
285 }
286 return 0;
287}
288
289void KMdiTaskBar::setActiveButton( KMdiChildView *win_ptr )
290{
291 KMdiTaskBarButton * newPressedButton = 0L;
292 KMdiTaskBarButton* oldPressedButton = 0L;
293 for ( KMdiTaskBarButton * b = m_pButtonList->first();b;b = m_pButtonList->next() )
294 {
295 if ( b->m_pWindow == win_ptr )
296 newPressedButton = b;
297 if ( b->m_pWindow == m_pCurrentFocusedWindow )
298 oldPressedButton = b;
299 }
300
301 if ( newPressedButton != 0L && newPressedButton != oldPressedButton )
302 {
303 if ( oldPressedButton != 0L )
304 oldPressedButton->toggle(); // switch off
305 newPressedButton->toggle(); // switch on
306 m_pCurrentFocusedWindow = win_ptr;
307 }
308}
309
310void KMdiTaskBar::layoutTaskBar( int taskBarWidth )
311{
312 if ( m_layoutIsPending )
313 return ;
314 m_layoutIsPending = true;
315
316 if ( !taskBarWidth )
317 // no width is given
318 taskBarWidth = width();
319
320 // calculate current width of all taskbar buttons
321 int allButtonsWidth = 0;
322 KMdiTaskBarButton *b = 0;
323 for ( b = m_pButtonList->first();b;b = m_pButtonList->next() )
324 {
325 allButtonsWidth += b->width();
326 }
327
328 // calculate actual width of all taskbar buttons
329 int allButtonsWidthHint = 0;
330 for ( b = m_pButtonList->first();b;b = m_pButtonList->next() )
331 {
332 TQFontMetrics fm = b->fontMetrics();
333 TQString s = b->actualText();
334 TQSize sz = fm.size( ShowPrefix, s );
335 int w = sz.width() + 6;
336 int h = sz.height() + sz.height() / 8 + 10;
337 w += h;
338 allButtonsWidthHint += w;
339 }
340
341 // if there's enough space, use actual width
342 int buttonCount = m_pButtonList->count();
343 int tbHandlePixel;
344 tbHandlePixel = style().pixelMetric( TQStyle::PM_DockWindowHandleExtent, this );
345 int buttonAreaWidth = taskBarWidth - tbHandlePixel - style().pixelMetric( TQStyle::PM_DefaultFrameWidth, this ) - 5;
346 if ( ( ( allButtonsWidthHint ) <= buttonAreaWidth ) || ( width() < parentWidget() ->width() ) )
347 {
348 for ( b = m_pButtonList->first();b;b = m_pButtonList->next() )
349 {
350 b->setText( b->actualText() );
351 if ( b->width() != b->sizeHint().width() )
352 {
353 b->setFixedWidth( b->sizeHint().width() );
354 b->show();
355 }
356 }
357 }
358 else
359 {
360 // too many buttons for actual width
361 int newButtonWidth;
362 if ( buttonCount != 0 )
363 newButtonWidth = buttonAreaWidth / buttonCount;
364 else
365 newButtonWidth = 0;
366 if ( orientation() == TQt::Vertical )
367 newButtonWidth = 80;
368 if ( newButtonWidth > 0 )
369 for ( b = m_pButtonList->first();b;b = m_pButtonList->next() )
370 {
371 b->fitText( b->actualText(), newButtonWidth );
372 if ( b->width() != newButtonWidth )
373 {
374 b->setFixedWidth( newButtonWidth );
375 b->show();
376 }
377 }
378 }
379 m_layoutIsPending = false;
380}
381
382void KMdiTaskBar::resizeEvent( TQResizeEvent* rse )
383{
384 if ( !m_layoutIsPending )
385 {
386 if ( m_pButtonList->count() != 0 )
387 {
388 layoutTaskBar( rse->size().width() );
389 }
390 }
391 TDEToolBar::resizeEvent( rse );
392}
KMdiChildView
Base class for all your special view windows.
Definition: tdemdichildview.h:109
KMdiChildView::tabCaption
const TQString & tabCaption() const
Returns the caption of the button on the taskbar.
Definition: tdemdichildview.h:237
KMdiChildView::caption
const TQString & caption() const
Returns the caption of the child window (different from the caption on the button in the taskbar)
Definition: tdemdichildview.h:232
KMdiMainFrm
Base class for all your special main frames.
Definition: tdemdimainfrm.h:240
KMdiTaskBarButton
Internal class.
Definition: tdemditaskbar.h:52
KMdiTaskBarButton::setText
void setText(const TQString &)
Sets the text and avoids any abbreviation.
Definition: tdemditaskbar.cpp:99
KMdiTaskBarButton::actualText
TQString actualText() const
text() returns the possibly abbreviated text including the dots in it.
Definition: tdemditaskbar.cpp:136
KMdiTaskBarButton::~KMdiTaskBarButton
~KMdiTaskBarButton()
Destructor.
Definition: tdemditaskbar.cpp:73
KMdiTaskBarButton::KMdiTaskBarButton
KMdiTaskBarButton(KMdiTaskBar *pTaskBar, KMdiChildView *win_ptr)
Constructor (sets to toggle button, adds a tooltip (caption) and sets to NoFocus.
Definition: tdemditaskbar.cpp:62
KMdiTaskBarButton::fitText
void fitText(const TQString &, int newWidth)
Given the parameter newWidth this function possibly abbreviates the parameter string and sets a new b...
Definition: tdemditaskbar.cpp:105
KMdiTaskBarButton::mousePressEvent
void mousePressEvent(TQMouseEvent *)
Reimplemented from its base class to catch right and left mouse button clicks.
Definition: tdemditaskbar.cpp:76
KMdiTaskBarButton::buttonTextChanged
void buttonTextChanged(int)
Emitted when the button text has changed.
KMdiTaskBarButton::rightMouseButtonClicked
void rightMouseButtonClicked(KMdiChildView *)
Internally connected with KMdiMainFrm::taskbarButtonRightClicked.
KMdiTaskBarButton::m_pWindow
KMdiChildView * m_pWindow
The according MDI view.
Definition: tdemditaskbar.h:109
KMdiTaskBarButton::setNewText
void setNewText(const TQString &)
A slot version of setText.
Definition: tdemditaskbar.cpp:93
KMdiTaskBarButton::clicked
void clicked(KMdiChildView *)
Emitted when the button has been clicked.
KMdiTaskBarButton::leftMouseButtonClicked
void leftMouseButtonClicked(KMdiChildView *)
Internally connected with KMdiMainFrm::activateView.
KMdiTaskBarButton::m_actualText
TQString m_actualText
Internally we must remember the real text because the button text can be abbreviated.
Definition: tdemditaskbar.h:114
KMdiTaskBar
Internal class.
Definition: tdemditaskbar.h:130
KMdiTaskBar::m_pButtonList
TQPtrList< KMdiTaskBarButton > * m_pButtonList
A list of taskbar buttons.
Definition: tdemditaskbar.h:197
KMdiTaskBar::layoutTaskBar
void layoutTaskBar(int taskBarWidth=0)
Checks if all buttons fits into this.
Definition: tdemditaskbar.cpp:310
KMdiTaskBar::KMdiTaskBar
KMdiTaskBar(KMdiMainFrm *parent, TQMainWindow::ToolBarDock dock)
Constructor (NoFocus, minimum width = 1, an internal TQPtrList of taskbar buttons (autodelete))
Definition: tdemditaskbar.cpp:147
KMdiTaskBar::m_pCurrentFocusedWindow
KMdiChildView * m_pCurrentFocusedWindow
The MDI view belonging to the currently pressed taskbar button.
Definition: tdemditaskbar.h:205
KMdiTaskBar::getNextWindowButton
KMdiTaskBarButton * getNextWindowButton(bool bRight, KMdiChildView *win_ptr)
Returns the neighbor taskbar button of the taskbar button of the MDI view given by parameter bRight s...
Definition: tdemditaskbar.cpp:252
KMdiTaskBar::m_pStretchSpace
TQLabel * m_pStretchSpace
A stretchable widget used as 'space' at the end of a half filled taskbar.
Definition: tdemditaskbar.h:209
KMdiTaskBar::getButton
KMdiTaskBarButton * getButton(KMdiChildView *win_ptr)
Get the button belonging to the MDI view given as parameter.
Definition: tdemditaskbar.cpp:242
KMdiTaskBar::addWinButton
KMdiTaskBarButton * addWinButton(KMdiChildView *win_ptr)
Add a new KMdiTaskBarButton .
Definition: tdemditaskbar.cpp:168
KMdiTaskBar::setActiveButton
void setActiveButton(KMdiChildView *win_ptr)
Pushes the desired taskbar button down (switch on), the old one is released (switched off).
Definition: tdemditaskbar.cpp:289
KMdiTaskBar::~KMdiTaskBar
~KMdiTaskBar()
Destructor (deletes the taskbar button list)
Definition: tdemditaskbar.cpp:163
KMdiTaskBar::resizeEvent
void resizeEvent(TQResizeEvent *)
Reimplemented from its base class to call layoutTaskBar, additionally.
Definition: tdemditaskbar.cpp:382
KMdiTaskBar::switchOn
void switchOn(bool bOn)
Switch it on or off.
Definition: tdemditaskbar.cpp:222
KMdiTaskBar::removeWinButton
void removeWinButton(KMdiChildView *win_ptr, bool haveToLayoutTaskBar=true)
Removes a KMdiTaskBarButton and deletes it.
Definition: tdemditaskbar.cpp:202
KMdiTaskBar::m_pFrm
KMdiMainFrm * m_pFrm
The belonging MDI mainframe (parent widget of this)
Definition: tdemditaskbar.h:201

tdemdi

Skip menu "tdemdi"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdemdi

Skip menu "tdemdi"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdemdi by doxygen 1.9.4
This website is maintained by Timothy Pearson.