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

tdemdi

  • tdemdi
tdemdichildfrmcaption.cpp
1//----------------------------------------------------------------------------
2// filename : tdemdichildfrmcaption.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//
13// copyright : (C) 1999-2003 by Szymon Stefanek (stefanek@tin.it)
14// and
15// Falk Brettschneider
16// email : falkbr@kdevelop.org (Falk Brettschneider)
17//----------------------------------------------------------------------------
18//
19//----------------------------------------------------------------------------
20//
21// This program is free software; you can redistribute it and/or modify
22// it under the terms of the GNU Library General Public License as
23// published by the Free Software Foundation; either version 2 of the
24// License, or (at your option) any later version.
25//
26//----------------------------------------------------------------------------
27
28#include "tdemdichildfrmcaption.h"
29#include "tdemdichildfrmcaption.moc"
30
31#include <tqpainter.h>
32#include <tqapplication.h>
33#include <tqcursor.h>
34#include <tqtoolbutton.h>
35#include <tqpopupmenu.h>
36
37#include "tdemdidefines.h"
38#include "tdemdichildfrm.h"
39#include "tdemdichildarea.h"
40#include "tdemdimainfrm.h"
41#include <tdelocale.h>
42#include <iostream>
43
44#ifdef TQ_WS_WIN
45//TODO: one day gradient can be added for win98/winnt5+
46// ask system properties on windows
47#ifndef SPI_GETGRADIENTCAPTIONS
48# define SPI_GETGRADIENTCAPTIONS 0x1008
49#endif
50#ifndef COLOR_GRADIENTACTIVECAPTION
51# define COLOR_GRADIENTACTIVECAPTION 27
52#endif
53#ifndef COLOR_GRADIENTINACTIVECAPTION
54# define COLOR_GRADIENTINACTIVECAPTION 28
55#endif
56#endif
57//#endif
58
60// Class : KMdiChildFrmCaption
61// Purpose : An MDI label that draws the title
62//
63//
65
66//============== KMdiChildFrmCaption =============//
67
68KMdiChildFrmCaption::KMdiChildFrmCaption( KMdiChildFrm *parent )
69 : TQWidget( parent, "tdemdi_childfrmcaption" )
70{
71 m_szCaption = i18n( "Unnamed" );
72 m_bActive = false;
73 m_pParent = parent;
74 setBackgroundMode( NoBackground );
75 setFocusPolicy( TQWidget::NoFocus );
76 m_bChildInDrag = false;
77}
78
79//============== ~KMdiChildFrmCaption =============//
80
81KMdiChildFrmCaption::~KMdiChildFrmCaption()
82{}
83
84//============= mousePressEvent ==============//
85
86void KMdiChildFrmCaption::mousePressEvent( TQMouseEvent *e )
87{
88 if ( e->button() == TQt::LeftButton )
89 {
90 setMouseTracking( false );
91 if ( KMdiMainFrm::frameDecorOfAttachedViews() != KMdi::Win95Look )
92 {
93 TQApplication::setOverrideCursor( TQt::sizeAllCursor, true );
94 }
95 m_pParent->m_bDragging = true;
96 m_offset = mapToParent( e->pos() );
97 }
98 else if ( e->button() == TQt::RightButton )
99 {
100 m_pParent->systemMenu()->popup( mapToGlobal( e->pos() ) );
101 }
102}
103
104//============= mouseReleaseEvent ============//
105
106void KMdiChildFrmCaption::mouseReleaseEvent( TQMouseEvent *e )
107{
108 if ( e->button() == TQt::LeftButton )
109 {
110 if ( KMdiMainFrm::frameDecorOfAttachedViews() != KMdi::Win95Look )
111 TQApplication::restoreOverrideCursor();
112
113 releaseMouse();
114 if ( m_pParent->m_bDragging )
115 {
116 m_pParent->m_bDragging = false;
117 if ( m_bChildInDrag )
118 {
119 //notify child view
120 KMdiChildFrmDragEndEvent ue( e );
121 if ( m_pParent->m_pClient != 0L )
122 TQApplication::sendEvent( m_pParent->m_pClient, &ue );
123
124 m_bChildInDrag = false;
125 }
126 }
127 }
128}
129
130//============== mouseMoveEvent =============//
131void KMdiChildFrmCaption::mouseMoveEvent( TQMouseEvent *e )
132{
133 if ( !m_pParent->m_bDragging )
134 return ;
135
136 if ( !m_bChildInDrag )
137 {
138 //notify child view
139 KMdiChildFrmDragBeginEvent ue( e );
140 if ( m_pParent->m_pClient != 0L )
141 TQApplication::sendEvent( m_pParent->m_pClient, &ue );
142
143 m_bChildInDrag = true;
144 }
145
146 TQPoint relMousePosInChildArea = m_pParent->m_pManager->mapFromGlobal( e->globalPos() );
147
148 // mouse out of child area? stop child frame dragging
149 if ( !m_pParent->m_pManager->rect().contains( relMousePosInChildArea ) )
150 {
151 if ( relMousePosInChildArea.x() < 0 )
152 relMousePosInChildArea.rx() = 0;
153
154 if ( relMousePosInChildArea.y() < 0 )
155 relMousePosInChildArea.ry() = 0;
156
157 if ( relMousePosInChildArea.x() > m_pParent->m_pManager->width() )
158 relMousePosInChildArea.rx() = m_pParent->m_pManager->width();
159
160 if ( relMousePosInChildArea.y() > m_pParent->m_pManager->height() )
161 relMousePosInChildArea.ry() = m_pParent->m_pManager->height();
162 }
163 TQPoint mousePosInChildArea = relMousePosInChildArea - m_offset;
164
165 // set new child frame position
166 parentWidget() ->move( mousePosInChildArea );
167}
168
169//=============== setActive ===============//
170
171void KMdiChildFrmCaption::setActive( bool bActive )
172{
173 if ( m_bActive == bActive )
174 return ;
175
176 // Ensure the icon's pixmap has the correct bg color
177 m_pParent->m_pWinIcon->setBackgroundColor( bActive ?
178 m_pParent->m_pManager->m_captionActiveBackColor :
179 m_pParent->m_pManager->m_captionInactiveBackColor );
180 m_pParent->m_pUnixIcon->setBackgroundColor( bActive ?
181 m_pParent->m_pManager->m_captionActiveBackColor :
182 m_pParent->m_pManager->m_captionInactiveBackColor );
183
184 m_bActive = bActive;
185 repaint( false );
186}
187
188//=============== setCaption ===============//
189
190void KMdiChildFrmCaption::setCaption( const TQString& text )
191{
192 m_szCaption = text;
193 repaint( false );
194}
195
196//============== heightHint ===============//
197
198int KMdiChildFrmCaption::heightHint()
199{
200 int hint = m_pParent->m_pManager->m_captionFontLineSpacing + 3;
201 if ( KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::Win95Look )
202 {
203 if ( hint < 18 )
204 hint = 18;
205 }
206 else if ( KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDE1Look )
207 {
208 if ( hint < 20 )
209 hint = 20;
210 }
211 else if ( KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDELook )
212 {
213 if ( hint < 16 )
214 hint = 16;
215 }
216 else
217 { // kde2laptop look
218 hint -= 4;
219 if ( hint < 14 )
220 hint = 14;
221 }
222 return hint;
223}
224
225//=============== paintEvent ==============//
226
227void KMdiChildFrmCaption::paintEvent( TQPaintEvent * )
228{
229 TQPainter p( this );
230 TQRect r = rect();
231 p.setFont( m_pParent->m_pManager->m_captionFont );
232
233 if ( m_bActive )
234 {
235 p.fillRect( r, m_pParent->m_pManager->m_captionActiveBackColor );
236 p.setPen( m_pParent->m_pManager->m_captionActiveForeColor );
237 }
238 else
239 {
240 p.fillRect( r, m_pParent->m_pManager->m_captionInactiveBackColor );
241 p.setPen( m_pParent->m_pManager->m_captionInactiveForeColor );
242 }
243
244 //Shift the text after the icon
245 if ( KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::Win95Look )
246 r.setLeft( r.left() + m_pParent->icon() ->width() + 3 );
247 else if ( KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDE1Look )
248 r.setLeft( r.left() + 22 );
249 else if ( KMdiMainFrm::frameDecorOfAttachedViews() == KMdi::KDELook )
250 r.setLeft( r.left() + m_pParent->icon() ->width() + 3 );
251 else // kde2laptop look
252 r.setLeft( r.left() + 30 );
253
254 int captionWidthForText = width() - 4 * m_pParent->m_pClose->width() - m_pParent->icon() ->width() - 5;
255 TQString text = abbreviateText( m_szCaption, captionWidthForText );
256 p.drawText( r, AlignVCenter | AlignLeft | SingleLine, text );
257
258}
259
260
261TQString KMdiChildFrmCaption::abbreviateText( TQString origStr, int maxWidth )
262{
263 TQFontMetrics fm = fontMetrics();
264 int actualWidth = fm.width( origStr );
265
266 int realLetterCount = origStr.length();
267 int newLetterCount;
268
269 if ( actualWidth != 0 )
270 newLetterCount = ( maxWidth * realLetterCount ) / actualWidth;
271 else
272 newLetterCount = realLetterCount; // should be 0 anyway
273
274 int w = maxWidth + 1;
275 TQString s = origStr;
276
277 if ( newLetterCount <= 0 )
278 s = "";
279
280 while ( ( w > maxWidth ) && ( newLetterCount >= 1 ) )
281 {
282 if ( newLetterCount < realLetterCount )
283 {
284 if ( newLetterCount > 3 )
285 s = origStr.left( newLetterCount / 2 ) + "..." + origStr.right( newLetterCount / 2 );
286 else
287 {
288 if ( newLetterCount > 1 )
289 s = origStr.left( newLetterCount ) + "..";
290 else
291 s = origStr.left( 1 );
292 }
293 }
294 TQFontMetrics fm = fontMetrics();
295 w = fm.width( s );
296 newLetterCount--;
297 }
298 return s;
299}
300
301//============= mouseDoubleClickEvent ===========//
302
303void KMdiChildFrmCaption::mouseDoubleClickEvent( TQMouseEvent * )
304{
305 m_pParent->maximizePressed();
306}
307
308//============= slot_moveViaSystemMenu ===========//
309
310void KMdiChildFrmCaption::slot_moveViaSystemMenu()
311{
312 setMouseTracking( true );
313 grabMouse();
314
315 if ( KMdiMainFrm::frameDecorOfAttachedViews() != KMdi::Win95Look )
316 TQApplication::setOverrideCursor( TQt::sizeAllCursor, true );
317
318 m_pParent->m_bDragging = true;
319 m_offset = mapFromGlobal( TQCursor::pos() );
320}
KMdiChildArea::m_captionInactiveBackColor
TQColor m_captionInactiveBackColor
The foreground color of inactive MDI childframe window captions.
Definition: tdemdichildarea.h:89
KMdiChildArea::m_captionActiveBackColor
TQColor m_captionActiveBackColor
The foreground color of the active MDI childframe window caption.
Definition: tdemdichildarea.h:79
KMdiChildArea::m_captionInactiveForeColor
TQColor m_captionInactiveForeColor
The background color of inactive MDI childframe window captions.
Definition: tdemdichildarea.h:94
KMdiChildArea::m_captionFont
TQFont m_captionFont
The MDI childframe window caption font.
Definition: tdemdichildarea.h:74
KMdiChildArea::m_captionActiveForeColor
TQColor m_captionActiveForeColor
The background color of the active MDI childframe window captions.
Definition: tdemdichildarea.h:84
KMdiChildFrmCaption::mousePressEvent
virtual void mousePressEvent(TQMouseEvent *)
The same as KMdiChildFrmCaption::slot_moveViaSystemMenu.
Definition: tdemdichildfrmcaption.cpp:86
KMdiChildFrmCaption::abbreviateText
TQString abbreviateText(TQString origStr, int maxWidth)
Computes a new abbreviated string from a given string depending on a given maximum width.
Definition: tdemdichildfrmcaption.cpp:261
KMdiChildFrmCaption::m_bChildInDrag
bool m_bChildInDrag
True if the child knows that it is currently being dragged.
Definition: tdemdichildfrmcaption.h:137
KMdiChildFrmCaption::m_szCaption
TQString m_szCaption
the title string shown in the caption bar
Definition: tdemdichildfrmcaption.h:116
KMdiChildFrmCaption::m_offset
TQPoint m_offset
the position offset related to its parent widget (internally used for translating mouse move position...
Definition: tdemdichildfrmcaption.h:132
KMdiChildFrmCaption::heightHint
int heightHint()
Returns the caption bar height depending on the used font.
Definition: tdemdichildfrmcaption.cpp:198
KMdiChildFrmCaption::mouseReleaseEvent
virtual void mouseReleaseEvent(TQMouseEvent *)
Restore the normal mouse cursor, set the state variable back to 'not moving'.
Definition: tdemdichildfrmcaption.cpp:106
KMdiChildFrmCaption::KMdiChildFrmCaption
KMdiChildFrmCaption(KMdiChildFrm *parent)
Constructor.
Definition: tdemdichildfrmcaption.cpp:68
KMdiChildFrmCaption::setCaption
void setCaption(const TQString &text)
Repaint with a new caption bar title.
Definition: tdemdichildfrmcaption.cpp:190
KMdiChildFrmCaption::setActive
void setActive(bool bActive)
Repaint the caption bar in active background colors.
Definition: tdemdichildfrmcaption.cpp:171
KMdiChildFrmCaption::~KMdiChildFrmCaption
~KMdiChildFrmCaption()
Destructor.
Definition: tdemdichildfrmcaption.cpp:81
KMdiChildFrmCaption::mouseMoveEvent
virtual void mouseMoveEvent(TQMouseEvent *e)
Checks if out of move range of the KMdiChildArea and calls KMdiChildFrm::move.
Definition: tdemdichildfrmcaption.cpp:131
KMdiChildFrmCaption::paintEvent
virtual void paintEvent(TQPaintEvent *e)
Draws the caption bar and its title using the settings.
Definition: tdemdichildfrmcaption.cpp:227
KMdiChildFrmCaption::slot_moveViaSystemMenu
void slot_moveViaSystemMenu()
Grabs the mouse, a move cursor, sets a move indicator variable to true and keeps the global mouse pos...
Definition: tdemdichildfrmcaption.cpp:310
KMdiChildFrmCaption::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(TQMouseEvent *)
Calls maximizePressed of the parent widget ( KMdiChildFrm )
Definition: tdemdichildfrmcaption.cpp:303
KMdiChildFrmCaption::m_bActive
bool m_bActive
state variable indicating whether activated or not activated
Definition: tdemdichildfrmcaption.h:127
KMdiChildFrmCaption::m_pParent
KMdiChildFrm * m_pParent
parent widget
Definition: tdemdichildfrmcaption.h:122
KMdiChildFrmDragBeginEvent
a TQCustomEvent for begin of dragging This special event will be useful, to inform view about child f...
Definition: tdemdichildfrm.h:84
KMdiChildFrmDragEndEvent
a TQCustomEvent for end of dragging This special event will be useful, to inform view about child fra...
Definition: tdemdichildfrm.h:95
KMdiChildFrm
Internal class.
Definition: tdemdichildfrm.h:131
KMdiChildFrm::maximizePressed
void maximizePressed()
Handles a click on the Maximize button.
Definition: tdemdichildfrm.cpp:442
KMdiChildFrm::icon
TQPixmap * icon() const
Returns the child frame icon.
Definition: tdemdichildfrm.cpp:720
KMdiChildFrm::systemMenu
TQPopupMenu * systemMenu() const
Returns the system menu.
Definition: tdemdichildfrm.cpp:1228
KMdiMainFrm::frameDecorOfAttachedViews
static int frameDecorOfAttachedViews()
Definition: tdemdimainfrm.h:465

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.