1
//----------------------------------------------------------------------------
2
// filename : kmdichildview.h
3
//----------------------------------------------------------------------------
4
// Project : KDE MDI extension
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
// */2000 by Lars Beikirch (Lars.Beikirch@gmx.net)
14
// 02/2001 by Eva Brucherseifer (eva@rt.e-technik.tu-darmstadt.de)
15
// 01/2003 by Jens Zurheide (jens.zurheide@gmx.de)
17
// copyright : (C) 1999-2003 by Falk Brettschneider
19
// Szymon Stefanek (stefanek@tin.it)
20
// email : falkbr@kdevelop.org (Falk Brettschneider)
21
//----------------------------------------------------------------------------
23
//----------------------------------------------------------------------------
25
// This program is free software; you can redistribute it and/or modify
26
// it under the terms of the GNU Library General Public License as
27
// published by the Free Software Foundation; either version 2 of the
28
// License, or (at your option) any later version.
30
//----------------------------------------------------------------------------
31
#ifndef _KMDI_CHILD_VIEW_H_
32
#define _KMDI_CHILD_VIEW_H_
37
#include <qapplication.h>
38
#include <qdatetime.h>
40
#include "kmdichildfrm.h"
42
class KMdiChildViewPrivate;
45
* @short Base class for all your special view windows.
47
* Base class for all MDI view widgets. KMdi stores additional information in this class
48
* to handle the attach/detach mechanism and such things.
50
* All such windows 'lives' attached to a KMdiChildFrm widget
51
* managed by KMdiChildArea, or detached (managed by the window manager.)
52
* So remember that the KMdiChildView::parent pointer may change, and may be 0L, too.
54
* There are 2 possibilities for you to put your widgets under MDI control:
56
* Either you inherit all the views from KMdiChildView:
58
* class MyMdiWidget : public KMdiChildView
62
* mainframe->addWindow(w, flags);
65
* or you wrap them by a KMdiChildView somehow like this:
68
* void DocViewMan::addKMdiFrame(QWidget* pNewView, bool bShow, const QPixmap& icon)
70
* // cover it by a KMdi childview and add that MDI system
71
* KMdiChildView* pMDICover = new KMdiChildView( pNewView->caption());
72
* pMDICover->setIcon(icon);
73
* m_MDICoverList.append( pMDICover);
74
* QBoxLayout* pLayout = new QHBoxLayout( pMDICover, 0, -1, "layout");
75
* pNewView->reparent( pMDICover, QPoint(0,0));
76
* pLayout->addWidget( pNewView);
77
* pMDICover->setName( pNewView->name());
79
* QString shortName = pNewView->caption();
80
* int length = shortName.length();
81
* shortName = shortName.right(length - (shortName.findRev('/') +1));
82
* pMDICover->setTabCaption( shortName);
83
* pMDICover->setCaption(pNewView->caption());
85
* // fake a viewActivated to update the currentEditView/currentBrowserView pointers _before_ adding to MDI control
86
* slot_viewActivated( pMDICover);
88
* // take it under MDI mainframe control (note: this triggers also a setFocus())
91
* flags = KMdi::StandardAdd;
96
* // set the accelerators for Toplevel MDI mode (each toplevel window needs its own accels
97
* connect( m_pParent, SIGNAL(childViewIsDetachedNow(QWidget*)), this, SLOT(initKeyAccel(QWidget*)) );
99
* m_pParent->addWindow( pMDICover, flags);
100
* // correct the default settings of KMdi ('cause we haven't a tab order for subwidget focuses)
101
* pMDICover->setFirstFocusableChildWidget(0L);
102
* pMDICover->setLastFocusableChildWidget(0L);
108
class KMDI_EXPORT KMdiChildView : public QWidget
110
friend class KMdiMainFrm;
111
friend class KMdiChildFrm;
117
* See KMdiChildView::caption
121
* See KMdiChildView::tabCaption
123
QString m_sTabCaption;
125
* See KMdiChildView::focusedChildWidget
127
QWidget* m_focusedChildWidget;
129
* See KMdiChildView::setFirstFocusableChildWidget
131
QWidget* m_firstFocusableChildWidget;
133
* See KMdiChildView::setLastFocusableChildWidget
135
QWidget* m_lastFocusableChildWidget;
137
* Every child view window has an temporary ID in the Window menu of the main frame.
141
* Holds a temporary information about if the MDI view state has changed but is not processed yet (pending state).
142
* For example it could be that a 'maximize' is pending, if this variable is true.
147
* Holds the time when this view was activated (not only displayed) for the last time.
153
* Internally used as indicator whether this KMdiChildView is treated as document view or as tool view.
157
* Internally used by KMdiMainFrm to store a temporary information that the method
158
* activate() is unnecessary and that it can by escaped.
159
* This saves from unnecessary calls when activate is called directly.
161
bool m_bInterruptActivation;
163
* Internally used to prevent cycles between KMdiMainFrm::activateView() and KMdiChildView::activate().
165
bool m_bMainframesActivateViewIsPending;
169
bool m_bFocusInEventIsPending;
176
KMdiChildView( const QString& caption, QWidget* parentWidget = 0L, const char* name = 0L, WFlags f=0);
179
* sets "Unnamed" as default caption
181
KMdiChildView( QWidget* parentWidget = 0L, const char* name = 0L, WFlags f=0);
187
* This method does the same as focusInEvent(). That's why it is a replacement for the setFocus() call. It makes
188
* sense if you for instance want to focus (I mean raise and activate) this view although the real focus is
189
* in another toplevel widget. focusInEvent() will never get called in that case and your setFocus() call for this
190
* widget would fail without any effect.
191
* Use this method with caution, it always raises the view and pushes the taskbar button. Also when the focus is
192
* still on another MDI view in the same toplevel window where this is located!
196
* Memorizes the first focusable child widget of this widget
198
void setFirstFocusableChildWidget(QWidget*);
200
* Memorizes the last focusable child widget of this widget
202
void setLastFocusableChildWidget(QWidget*);
204
* Returns the current focused child widget of this widget
206
QWidget* focusedChildWidget();
208
* Returns true if the MDI view is a child window within the MDI mainframe widget
209
* or false if the MDI view is in toplevel mode
211
bool isAttached() const { return (mdiParent() != 0L); };
213
* Returns the caption of the child window (different from the caption on the button in the taskbar)
215
const QString& caption() const { return m_szCaption; };
217
* Returns the caption of the button on the taskbar
219
const QString& tabCaption() const { return m_sTabCaption; };
221
* Sets the window caption string...
222
* Calls updateButton on the taskbar button if it has been set.
224
virtual void setCaption(const QString& szCaption);
226
* Sets the caption of the button referring to this window
228
virtual void setTabCaption(const QString& caption);
230
* Sets the caption of both the window and the button on the taskbar
232
virtual void setMDICaption(const QString &caption);
234
* Returns the KMdiChildFrm parent widget (or 0 if the window is not attached)
236
KMdiChildFrm *mdiParent() const;
238
* Tells if the window is minimized when attached to the Mdi manager,
239
* or if it is VISIBLE when 'floating'.
241
bool isMinimized() const;
243
* Tells if the window is minimized when attached to the Mdi manager,
244
* otherwise returns false.
246
bool isMaximized() const;
248
* Returns the geometry of this MDI child window as QWidget::geometry() does.
250
QRect internalGeometry() const;
252
* Sets the geometry of the client area of this MDI child window. The
253
* top left position of the argument is the position of the top left point
254
* of the client area in its parent coordinates and the arguments width
255
* and height is the width and height of the client area. Please note: This
256
* differs from the behavior of QWidget::setGeometry()!
258
void setInternalGeometry(const QRect& newGeomety);
260
* Returns the frame geometry of this window or of the parent if there is any...
262
QRect externalGeometry() const;
264
* Sets the geometry of the frame of this MDI child window. The top left
265
* position of the argument is the position of the top left point of the
266
* frame in its parent coordinates and the arguments width and height is
267
* the width and height of the widget frame. Please note: This differs
268
* from the behavior of QWidget::setGeometry()!
270
void setExternalGeometry(const QRect& newGeomety);
272
* You should override this function in the derived class.
274
virtual QPixmap* myIconPtr();
276
* Minimizes this window when it is attached to the Mdi manager.
277
* Otherwise has no effect
279
virtual void minimize(bool bAnimate);
281
* Maximizes this window when it is attached to the Mdi manager.
282
* Otherwise has no effect
284
virtual void maximize(bool bAnimate);
286
* Returns the geometry that will be restored by calling restore().
288
QRect restoreGeometry();
290
* Sets the geometry that will be restored by calling restore().
292
void setRestoreGeometry(const QRect& newRestGeo);
294
* Switches interposing in event loop of all current child widgets off.
296
void removeEventFilterForAllChildren();
298
* Internally used for setting an ID for the 'Window' menu entry
300
void setWindowMenuID( int id);
302
* Sets the minimum size of the widget to w by h pixels.
303
* It extends it base clase method in a way that the minimum size of
304
* its childframe (if there is one) will be set, additionally.
306
virtual void setMinimumSize ( int minw, int minh );
308
* Sets the maximum size of the widget to w by h pixels.
309
* It extends it base clase method in a way that the maximum size of
310
* its childframe (if there is one) will be set, additionally.
312
virtual void setMaximumSize ( int maxw, int maxh );
314
* Returns if this is added as MDI tool-view
316
inline bool isToolView() const { return m_bToolView; };
318
* Remember the current time
320
inline void updateTimeStamp() {
321
m_time.setDate( QDate::currentDate() );
322
m_time.setTime( QTime::currentTime() );
325
* Recall a previously remembered time, i.e. the value of m_time
327
inline const QDateTime& getTimeStamp() const { return m_time; }
331
* Attaches this window to the Mdi manager.
332
* It calls the KMdiMainFrm attachWindow function , so if you have a pointer
333
* to this KMdiMainFrm you'll be faster calling that function.
336
virtual void attach();
338
* Detaches this window from the Mdi manager.
339
* It calls the KMdiMainFrm detachWindow function , so if you have a pointer
340
* to this KMdiMainFrm you'll be faster calling that function.
343
virtual void detach();
345
* Mimimizes the MDI view. If attached, the covering childframe widget is minimized (only a mini widget
346
* showing the caption bar and the system buttons will remain visible). If detached, it will use the
347
* minimize of the underlying system ( QWidget::showMinimized ).
349
virtual void minimize();
351
* Maximizes the MDI view. If attached, this widget will fill the whole MDI view area widget. The system buttons
352
* move to the main menubar (if set by KMdiMainFrm::setMenuForSDIModeSysButtons ).
353
* If detached, it will use the minimize of the underlying system ( QWidget::showMaximized ).
355
virtual void maximize();
357
* Restores this window to its normal size. Also known as 'normalize'.
359
virtual void restore();
361
* Internally called, if KMdiMainFrm::attach is called.
362
* Actually, only the caption of the covering childframe is set.
364
virtual void youAreAttached(KMdiChildFrm *lpC);
366
* Internally called, if KMdiMainFrm::detach is called.
367
* Some things for going toplevel will be done here.
369
virtual void youAreDetached();
371
* Called if someone click on the "Window" menu item for this child frame window
373
virtual void slot_clickedInWindowMenu();
375
* Called if someone click on the "Dock/Undock..." menu item for this child frame window
377
virtual void slot_clickedInDockMenu();
379
* Calls QWidget::show but also for it's parent widget if attached
383
* Calls QWidget::hide() or it's parent widget hide() if attached
387
* Calls QWidget::raise() or it's parent widget raise() if attached
389
virtual void raise();
391
* Overridden from its base class method. Emits a signal KMdiChildView::isMinimizedNow , additionally.
392
* Note that this method is not used by an external windows manager call on system minimizing.
394
virtual void showMinimized();
396
* Overridden from its base class method. Emits a signal KMdiChildView::isMaximizedNow , additionally.
397
* Note that this method is not used by an external windows manager call on system maximizing.
399
virtual void showMaximized();
401
* Overridden from its base class method. Emits a signal KMdiChildView::isRestoredNow , additionally.
402
* Note that this method is not used by an external windows manager call on system normalizing.
404
virtual void showNormal();
408
* Ignores the event and calls KMdiMainFrm::childWindowCloseRequest instead. This is because the
409
* mainframe has control over the views. Therefore the MDI view has to request the mainframe for a close.
411
virtual void closeEvent(QCloseEvent *e);
413
* It only catches QEvent::KeyPress events there. If a Qt::Key_Tab is pressed, the internal MDI focus
414
* handling is called. That means if the last focusable child widget of this is called, it will jump to the
415
* first focusable child widget of this.
416
* See KMdiChildView::setFirstFocusableChildWidget and KMdiChildView::lastFirstFocusableChildWidget
418
virtual bool eventFilter(QObject *obj, QEvent *e);
420
* If attached, the childframe will be activated and the MDI taskbar button will be pressed. Additionally, the
421
* memorized old focused child widget of this is focused again.
422
* Sends the focusInEventOccurs signal before changing the focus and the
423
* gotFocus signal after changing the focus.
425
virtual void focusInEvent(QFocusEvent *e);
427
* Send the lostFocus signal
429
virtual void focusOutEvent(QFocusEvent *e);
431
* Internally used for the minimize/maximize/restore mechanism when in attach mode.
433
virtual void resizeEvent(QResizeEvent *e);
435
void trackIconAndCaptionChanges(QWidget *view);
438
void slot_childDestroyed();
442
* Internally used by KMdiChildView::attach to send it as command to the mainframe.
444
void attachWindow( KMdiChildView*,bool);
446
* Internally used by KMdiChildView::detach to send it as command to the mainframe.
448
void detachWindow( KMdiChildView*,bool);
450
* Is sent when this MDI child view is going to receive focus (before actually changing the focus).
451
* Internally used to send information to the mainframe that this MDI child view is focused.
452
* See KMdiChildView::focusInEvent
454
void focusInEventOccurs( KMdiChildView*);
456
* Is sent when this MDI child has received the focus (after actually changing the focus).
457
* See KMdiChildView::focusInEvent
459
void gotFocus( KMdiChildView*);
461
* Is sent when this MDI child was set to the activate view of all MDI views (after actually changing the focus).
462
* See KMdiChildView::activate
464
void activated( KMdiChildView*);
465
/** Is sent when this MDI child view has lost the focus (after actually changing the focus).
466
* See KMdiChildView::focusOutEvent
468
void lostFocus( KMdiChildView*);
469
/** Is sent when this MDI child view was deactivated (after actually changing the focus).
470
* See KMdiChildView::focusOutEvent
472
void deactivated( KMdiChildView*);
474
* Internally used to send information to the mainframe that this MDI child view wants to be closed.
475
* See KMdiChildView::closeEvent and KMdiMainFrm::closeWindow
477
void childWindowCloseRequest( KMdiChildView*);
479
* Emitted when the window caption is changed via KMdiChildView::setCaption or KMdiChildView::setMDICaption
481
void windowCaptionChanged( const QString&);
483
* Emitted when the window caption is changed via KMdiChildView::setTabCaption or KMdiChildView::setMDICaption
485
void tabCaptionChanged( const QString&);
487
* Internally used to send information to the mainframe that this MDI view is maximized now.
488
* Usually, the mainframe switches system buttons.
490
void mdiParentNowMaximized(bool);
492
* Is automatically emitted when slot_clickedInWindowMenu is called
494
void clickedInWindowMenu(int);
496
* Is automatically emitted when slot_clickedInDockMenu is called
498
void clickedInDockMenu(int);
500
* Signals this has been maximized
502
void isMaximizedNow();
504
* Signals this has been minimized
506
void isMinimizedNow();
508
* Signals this has been restored (normalized)
510
void isRestoredNow();
512
* Signals this has been attached
514
void isAttachedNow();
516
* Signals this has been detached
518
void isDetachedNow();
520
void iconUpdated(QWidget*,QPixmap);
521
void captionUpdated(QWidget*,const QString&);
525
KMdiChildViewPrivate *d;
526
QWidget *m_trackChanges;
529
inline KMdiChildFrm *KMdiChildView::mdiParent() const
531
QWidget* pw = parentWidget();
533
if( pw->inherits("KMdiChildFrm"))
534
return (KMdiChildFrm *)pw;
538
#endif //_KMDICHILDVIEW_H_
540
// kate: space-indent on; indent-width 2; replace-tabs on;