~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/qextmdi/kmdichildview.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//----------------------------------------------------------------------------
 
2
//    filename             : kmdichildview.h
 
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
//                           */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)
 
16
//
 
17
//    copyright            : (C) 1999-2003 by Falk Brettschneider
 
18
//                                         and
 
19
//                                         Szymon Stefanek (stefanek@tin.it)
 
20
//    email                :  falkbr@kdevelop.org (Falk Brettschneider)
 
21
//----------------------------------------------------------------------------
 
22
//
 
23
//----------------------------------------------------------------------------
 
24
//
 
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.
 
29
//
 
30
//----------------------------------------------------------------------------
 
31
#ifndef _KMDI_CHILD_VIEW_H_
 
32
#define _KMDI_CHILD_VIEW_H_
 
33
 
 
34
#include <qwidget.h>
 
35
#include <qpixmap.h>
 
36
#include <qrect.h>
 
37
#include <qapplication.h>
 
38
#include <qdatetime.h>
 
39
 
 
40
#include "kmdichildfrm.h"
 
41
 
 
42
class KMdiChildViewPrivate;
 
43
 
 
44
/**
 
45
  * @short Base class for all your special view windows.
 
46
  *
 
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.
 
49
  *
 
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.
 
53
  *
 
54
  * There are 2 possibilities for you to put your widgets under MDI control:
 
55
  *
 
56
  * Either you inherit all the views from KMdiChildView:
 
57
  *   \code
 
58
  *   class MyMdiWidget : public KMdiChildView
 
59
  *   { .... };
 
60
  *   ...
 
61
  *   MyMdiWidget w;
 
62
  *   mainframe->addWindow(w, flags);
 
63
  *   \endcode
 
64
  *
 
65
  * or you wrap them by a KMdiChildView somehow like this:
 
66
  *
 
67
  * \code
 
68
  * void DocViewMan::addKMdiFrame(QWidget* pNewView, bool bShow, const QPixmap& icon)
 
69
  * {
 
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());
 
78
  *   // captions
 
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());
 
84
  *
 
85
  *   // fake a viewActivated to update the currentEditView/currentBrowserView pointers _before_ adding to MDI control
 
86
  *   slot_viewActivated( pMDICover);
 
87
  *
 
88
  *   // take it under MDI mainframe control (note: this triggers also a setFocus())
 
89
  *   int flags;
 
90
  *   if (bShow) {
 
91
  *     flags = KMdi::StandardAdd;
 
92
  *   }
 
93
  *   else {
 
94
  *     flags = KMdi::Hide;
 
95
  *   }
 
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*)) );
 
98
  *
 
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);
 
103
  * }
 
104
  * \endcode
 
105
  *
 
106
  */
 
107
 
 
108
class KMDI_EXPORT KMdiChildView : public QWidget
 
109
{
 
110
   friend class KMdiMainFrm;
 
111
   friend class KMdiChildFrm;
 
112
   Q_OBJECT
 
113
 
 
114
// attributes
 
115
protected:
 
116
   /**
 
117
   * See KMdiChildView::caption
 
118
   */
 
119
   QString     m_szCaption;
 
120
   /**
 
121
   * See KMdiChildView::tabCaption
 
122
   */
 
123
   QString     m_sTabCaption;
 
124
   /**
 
125
   * See KMdiChildView::focusedChildWidget
 
126
   */
 
127
   QWidget*    m_focusedChildWidget;
 
128
   /**
 
129
   * See KMdiChildView::setFirstFocusableChildWidget
 
130
   */
 
131
   QWidget*    m_firstFocusableChildWidget;
 
132
   /**
 
133
   * See KMdiChildView::setLastFocusableChildWidget
 
134
   */
 
135
   QWidget*    m_lastFocusableChildWidget;
 
136
   /**
 
137
   * Every child view window has an temporary ID in the Window menu of the main frame.
 
138
   */
 
139
   int         m_windowMenuID;
 
140
   /**
 
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.
 
143
   */
 
144
   bool        m_stateChanged;
 
145
 
 
146
   /**
 
147
   * Holds the time when this view was activated (not only displayed) for the last time.
 
148
   */
 
149
   QDateTime   m_time;
 
150
 
 
151
private:
 
152
   /**
 
153
   * Internally used as indicator whether this KMdiChildView is treated as document view or as tool view.
 
154
   */
 
155
   bool  m_bToolView;
 
156
   /**
 
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.
 
160
   */
 
161
   bool m_bInterruptActivation;
 
162
   /**
 
163
   * Internally used to prevent cycles between KMdiMainFrm::activateView() and KMdiChildView::activate().
 
164
   */
 
165
   bool m_bMainframesActivateViewIsPending;
 
166
   /**
 
167
   *
 
168
   */
 
169
   bool m_bFocusInEventIsPending;
 
170
 
 
171
// methods
 
172
public:
 
173
   /**
 
174
   * Constructor
 
175
   */
 
176
   KMdiChildView( const QString& caption, QWidget* parentWidget = 0L, const char* name = 0L, WFlags f=0);
 
177
   /**
 
178
   * Constructor 
 
179
   * sets "Unnamed" as default caption
 
180
   */
 
181
   KMdiChildView( QWidget* parentWidget = 0L, const char* name = 0L, WFlags f=0);
 
182
   /**
 
183
   * Destructor
 
184
   */
 
185
   ~KMdiChildView();
 
186
   /**
 
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!
 
193
   */
 
194
   void activate();
 
195
   /**
 
196
   * Memorizes the first focusable child widget of this widget
 
197
   */
 
198
   void setFirstFocusableChildWidget(QWidget*);
 
199
   /**
 
200
   * Memorizes the last focusable child widget of this widget
 
201
   */
 
202
   void setLastFocusableChildWidget(QWidget*);
 
203
   /**
 
204
   * Returns the current focused child widget of this widget
 
205
   */
 
206
   QWidget* focusedChildWidget();
 
207
   /**
 
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
 
210
   */
 
211
   bool isAttached() const { return (mdiParent() != 0L); };
 
212
   /**
 
213
   * Returns the caption of the child window (different from the caption on the button in the taskbar)
 
214
   */
 
215
   const QString& caption() const { return m_szCaption; };
 
216
   /**
 
217
   * Returns the caption of the button on the taskbar
 
218
   */
 
219
   const QString& tabCaption() const { return m_sTabCaption; };
 
220
   /**
 
221
   * Sets the window caption string...
 
222
   * Calls updateButton on the taskbar button if it has been set.
 
223
   */
 
224
   virtual void setCaption(const QString& szCaption);
 
225
   /**
 
226
   * Sets the caption of the button referring to this window
 
227
   */
 
228
   virtual void setTabCaption(const QString& caption);
 
229
   /**
 
230
   * Sets the caption of both the window and the button on the taskbar
 
231
   */
 
232
   virtual void setMDICaption(const QString &caption);
 
233
   /**
 
234
   * Returns the KMdiChildFrm parent widget (or 0 if the window is not attached)
 
235
   */
 
236
   KMdiChildFrm *mdiParent() const;
 
237
   /**
 
238
   * Tells if the window is minimized when attached to the Mdi manager,
 
239
   * or if it is VISIBLE when 'floating'.
 
240
   */
 
241
   bool isMinimized() const;
 
242
   /**
 
243
   * Tells if the window is minimized when attached to the Mdi manager,
 
244
   * otherwise returns false.
 
245
   */
 
246
   bool isMaximized() const;
 
247
   /**
 
248
    * Returns the geometry of this MDI child window as QWidget::geometry() does.
 
249
    */
 
250
   QRect internalGeometry() const;
 
251
   /**
 
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()!
 
257
   */
 
258
   void setInternalGeometry(const QRect& newGeomety);
 
259
   /**
 
260
   * Returns the frame geometry of this window or of the parent if there is any...
 
261
   */
 
262
   QRect externalGeometry() const;
 
263
   /**
 
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()!
 
269
   */
 
270
   void setExternalGeometry(const QRect& newGeomety);
 
271
   /**
 
272
   * You should override this function in the derived class.
 
273
   */
 
274
   virtual QPixmap* myIconPtr();
 
275
   /**
 
276
   * Minimizes this window when it is attached to the Mdi manager.
 
277
   * Otherwise has no effect
 
278
   */
 
279
   virtual void minimize(bool bAnimate);
 
280
   /**
 
281
   * Maximizes this window when it is attached to the Mdi manager.
 
282
   * Otherwise has no effect
 
283
   */
 
284
   virtual void maximize(bool bAnimate);
 
285
   /**
 
286
   * Returns the geometry that will be restored by calling restore().
 
287
   */
 
288
   QRect restoreGeometry();
 
289
   /**
 
290
   * Sets the geometry that will be restored by calling restore().
 
291
   */
 
292
   void  setRestoreGeometry(const QRect& newRestGeo);
 
293
   /**
 
294
   * Switches interposing in event loop of all current child widgets off.
 
295
   */
 
296
   void removeEventFilterForAllChildren();
 
297
   /**
 
298
   * Internally used for setting an ID for the 'Window' menu entry
 
299
   */
 
300
   void setWindowMenuID( int id);
 
301
   /**
 
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.
 
305
   */
 
306
   virtual void setMinimumSize ( int minw, int minh );
 
307
   /**
 
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.
 
311
   */
 
312
   virtual void setMaximumSize ( int maxw, int maxh );
 
313
   /**
 
314
   * Returns if this is added as MDI tool-view
 
315
   */
 
316
   inline bool isToolView() const { return m_bToolView; };
 
317
   /**
 
318
   * Remember the current time
 
319
   */
 
320
   inline void updateTimeStamp() {
 
321
      m_time.setDate( QDate::currentDate() );
 
322
      m_time.setTime( QTime::currentTime() );
 
323
   }
 
324
   /**
 
325
   * Recall a previously remembered time, i.e. the value of m_time
 
326
   */
 
327
   inline const QDateTime& getTimeStamp() const { return m_time; }
 
328
 
 
329
public slots:
 
330
   /**
 
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.
 
334
   * Useful as slot.
 
335
   */
 
336
   virtual void attach();
 
337
   /**
 
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.
 
341
   * Useful as slot.
 
342
   */
 
343
   virtual void detach();
 
344
   /**
 
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 ).
 
348
   */
 
349
   virtual void minimize();
 
350
   /**
 
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 ).
 
354
   */
 
355
   virtual void maximize();
 
356
   /**
 
357
   * Restores this window to its normal size. Also known as 'normalize'.
 
358
   */
 
359
   virtual void restore();
 
360
   /**
 
361
   * Internally called, if KMdiMainFrm::attach is called.
 
362
   * Actually, only the caption of the covering childframe is set.
 
363
   */
 
364
   virtual void youAreAttached(KMdiChildFrm *lpC);
 
365
   /**
 
366
   * Internally called, if KMdiMainFrm::detach is called.
 
367
   * Some things for going toplevel will be done here.
 
368
   */
 
369
   virtual void youAreDetached();
 
370
   /**
 
371
   * Called if someone click on the "Window" menu item for this child frame window
 
372
   */
 
373
   virtual void slot_clickedInWindowMenu();
 
374
   /**
 
375
   * Called if someone click on the "Dock/Undock..." menu item for this child frame window
 
376
   */
 
377
   virtual void slot_clickedInDockMenu();
 
378
   /**
 
379
   * Calls QWidget::show but also for it's parent widget if attached
 
380
   */
 
381
   virtual void show();
 
382
   /**
 
383
   * Calls QWidget::hide() or it's parent widget hide() if attached
 
384
   */
 
385
   virtual void hide();
 
386
   /**
 
387
   * Calls QWidget::raise() or it's parent widget raise() if attached
 
388
   */
 
389
   virtual void raise();
 
390
   /**
 
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.
 
393
   */
 
394
   virtual void showMinimized();
 
395
   /**
 
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.
 
398
   */
 
399
   virtual void showMaximized();
 
400
   /**
 
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.
 
403
   */
 
404
   virtual void showNormal();
 
405
 
 
406
protected:
 
407
   /**
 
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.
 
410
    */
 
411
   virtual void closeEvent(QCloseEvent *e);
 
412
   /**
 
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
 
417
   */
 
418
   virtual bool eventFilter(QObject *obj, QEvent *e);
 
419
   /**
 
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.
 
424
   */
 
425
   virtual void focusInEvent(QFocusEvent *e);
 
426
   /**
 
427
   * Send the lostFocus signal
 
428
   */
 
429
   virtual void focusOutEvent(QFocusEvent *e);
 
430
   /**
 
431
   * Internally used for the minimize/maximize/restore mechanism when in attach mode.
 
432
   */
 
433
   virtual void resizeEvent(QResizeEvent *e);
 
434
 
 
435
   void trackIconAndCaptionChanges(QWidget *view);
 
436
 
 
437
protected slots:
 
438
   void slot_childDestroyed();
 
439
 
 
440
signals:
 
441
   /**
 
442
   * Internally used by KMdiChildView::attach to send it as command to the mainframe.
 
443
   */
 
444
   void attachWindow( KMdiChildView*,bool);
 
445
   /**
 
446
   * Internally used by KMdiChildView::detach to send it as command to the mainframe.
 
447
   */
 
448
   void detachWindow( KMdiChildView*,bool);
 
449
   /**
 
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
 
453
   */
 
454
   void focusInEventOccurs( KMdiChildView*);
 
455
   /**
 
456
   * Is sent when this MDI child has received the focus (after actually changing the focus).
 
457
   * See KMdiChildView::focusInEvent
 
458
   */
 
459
   void gotFocus( KMdiChildView*);
 
460
   /**
 
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
 
463
   */
 
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
 
467
    */
 
468
   void lostFocus( KMdiChildView*);
 
469
   /** Is sent when this MDI child view was deactivated (after actually changing the focus).
 
470
    *  See KMdiChildView::focusOutEvent
 
471
    */
 
472
   void deactivated( KMdiChildView*);
 
473
   /**
 
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
 
476
   */
 
477
   void childWindowCloseRequest( KMdiChildView*);
 
478
   /**
 
479
   * Emitted when the window caption is changed via KMdiChildView::setCaption or KMdiChildView::setMDICaption
 
480
   */
 
481
   void windowCaptionChanged( const QString&);
 
482
   /**
 
483
   * Emitted  when the window caption is changed via KMdiChildView::setTabCaption or KMdiChildView::setMDICaption
 
484
   */
 
485
   void tabCaptionChanged( const QString&);
 
486
   /**
 
487
   * Internally used to send information to the mainframe that this MDI view is maximized now.
 
488
   * Usually, the mainframe switches system buttons.
 
489
   */
 
490
   void mdiParentNowMaximized(bool);
 
491
   /**
 
492
   * Is automatically emitted when slot_clickedInWindowMenu is called
 
493
   */
 
494
   void clickedInWindowMenu(int);
 
495
   /**
 
496
   * Is automatically emitted when slot_clickedInDockMenu is called
 
497
   */
 
498
   void clickedInDockMenu(int);
 
499
   /**
 
500
   * Signals this has been maximized
 
501
   */
 
502
   void isMaximizedNow();
 
503
   /**
 
504
   * Signals this has been minimized
 
505
   */
 
506
   void isMinimizedNow();
 
507
   /**
 
508
   * Signals this has been restored (normalized)
 
509
   */
 
510
   void isRestoredNow();
 
511
   /**
 
512
   * Signals this has been attached
 
513
   */
 
514
   void isAttachedNow();
 
515
   /**
 
516
   * Signals this has been detached
 
517
   */
 
518
   void isDetachedNow();
 
519
 
 
520
   void iconUpdated(QWidget*,QPixmap);
 
521
   void captionUpdated(QWidget*,const QString&);
 
522
 
 
523
 
 
524
  private:
 
525
   KMdiChildViewPrivate *d;
 
526
   QWidget *m_trackChanges;
 
527
};
 
528
 
 
529
inline KMdiChildFrm *KMdiChildView::mdiParent() const
 
530
{
 
531
   QWidget* pw = parentWidget();
 
532
   if( pw != 0L)
 
533
      if( pw->inherits("KMdiChildFrm"))
 
534
         return (KMdiChildFrm *)pw;
 
535
   return 0L;
 
536
}
 
537
 
 
538
#endif //_KMDICHILDVIEW_H_
 
539
 
 
540
// kate: space-indent on; indent-width 2; replace-tabs on;