~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kate/app/katemdi.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2005 Christoph Cullmann <cullmann@kde.org>
3
 
   Copyright (C) 2002, 2003 Joseph Wenninger <jowenn@kde.org>
4
 
 
5
 
   This library is free software; you can redistribute it and/or
6
 
   modify it under the terms of the GNU Library General Public
7
 
   License as published by the Free Software Foundation; either
8
 
   version 2 of the License, or (at your option) any later version.
9
 
 
10
 
   This library is distributed in the hope that it will be useful,
11
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
   Library General Public License for more details.
14
 
 
15
 
   You should have received a copy of the GNU Library General Public License
16
 
   along with this library; see the file COPYING.LIB.  If not, write to
17
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 
   Boston, MA 02110-1301, USA.
19
 
*/
20
 
 
21
 
#ifndef __KATE_MDI_H__
22
 
#define __KATE_MDI_H__
23
 
 
24
 
#include <kparts/mainwindow.h>
25
 
 
26
 
#include <kmultitabbar.h>
27
 
#include <kxmlguiclient.h>
28
 
#include <kaction.h>
29
 
 
30
 
#include <qdict.h>
31
 
#include <qintdict.h>
32
 
#include <qmap.h>
33
 
#include <qsplitter.h>
34
 
#include <qpixmap.h>
35
 
#include <qptrlist.h>
36
 
 
37
 
namespace KateMDI {
38
 
 
39
 
 
40
 
/** This class is needed because QSplitter cant return an index for a widget. */
41
 
class Splitter : public QSplitter
42
 
{
43
 
  Q_OBJECT
44
 
 
45
 
  public:
46
 
    Splitter(Orientation o, QWidget* parent=0, const char* name=0);
47
 
    ~Splitter();
48
 
 
49
 
    /** Since there is supposed to be only 2 childs of a katesplitter,
50
 
     * any child other than the last is the first.
51
 
     * This method uses QSplitter::idAfter(widget) which
52
 
     * returns 0 if there is no widget after this one.
53
 
     * This results in an error if widget is not a child
54
 
     * in this splitter */
55
 
    bool isLastChild(QWidget* w) const;
56
 
 
57
 
    int idAfter ( QWidget * w ) const;
58
 
};
59
 
 
60
 
class ToggleToolViewAction : public KToggleAction
61
 
{
62
 
  Q_OBJECT
63
 
 
64
 
  public:
65
 
    ToggleToolViewAction ( const QString& text, const KShortcut& cut,
66
 
                           class ToolView *tv, QObject* parent = 0, const char* name = 0 );
67
 
 
68
 
    virtual ~ToggleToolViewAction();
69
 
 
70
 
  protected slots:
71
 
    void slotToggled(bool);
72
 
    void visibleChanged(bool);
73
 
 
74
 
  private:
75
 
    ToolView *m_tv;
76
 
};
77
 
 
78
 
class GUIClient : public QObject, public KXMLGUIClient
79
 
{
80
 
  Q_OBJECT
81
 
 
82
 
  public:
83
 
    GUIClient ( class MainWindow *mw );
84
 
    virtual ~GUIClient();
85
 
 
86
 
    void registerToolView (ToolView *tv);
87
 
    void unregisterToolView (ToolView *tv);
88
 
    void updateSidebarsVisibleAction();
89
 
 
90
 
  private slots:
91
 
    void clientAdded( KXMLGUIClient *client );
92
 
    void updateActions();
93
 
 
94
 
  private:
95
 
    MainWindow *m_mw;
96
 
    KToggleAction *m_showSidebarsAction;
97
 
    QPtrList<KAction> m_toolViewActions;
98
 
    QMap<ToolView*, KAction*> m_toolToAction;
99
 
    KActionMenu *m_toolMenu;
100
 
};
101
 
 
102
 
class ToolView : public QVBox
103
 
{
104
 
  Q_OBJECT
105
 
 
106
 
  friend class Sidebar;
107
 
  friend class MainWindow;
108
 
  friend class GUIClient;
109
 
  friend class ToggleToolViewAction;
110
 
 
111
 
  protected:
112
 
    /**
113
 
     * ToolView
114
 
     * Objects of this clas represent a toolview in the mainwindow
115
 
     * you should only add one widget as child to this toolview, it will
116
 
     * be automatically set to be the focus proxy of the toolview
117
 
     * @param mainwin main window for this toolview
118
 
     * @param sidebar sidebar of this toolview
119
 
     * @param parent parent widget, e.g. the splitter of one of the sidebars
120
 
     */
121
 
    ToolView (class MainWindow *mainwin, class Sidebar *sidebar, QWidget *parent);
122
 
 
123
 
  public:
124
 
    /**
125
 
     * destuct me, this is allowed for all, will care itself that the toolview is removed
126
 
     * from the mainwindow and sidebar
127
 
     */
128
 
    virtual ~ToolView ();
129
 
 
130
 
  signals:
131
 
    /**
132
 
     * toolview hidden or shown
133
 
     * @param bool is this toolview made visible?
134
 
     */
135
 
    void visibleChanged (bool visible);
136
 
 
137
 
  /**
138
 
   * some internal methodes needed by the main window and the sidebars
139
 
   */
140
 
  protected:
141
 
    MainWindow *mainWindow () { return m_mainWin; }
142
 
 
143
 
    Sidebar *sidebar () { return m_sidebar; }
144
 
 
145
 
    void setVisible (bool vis);
146
 
 
147
 
  public:
148
 
    bool visible () const;
149
 
 
150
 
  protected:
151
 
    void childEvent ( QChildEvent *ev );
152
 
 
153
 
  private:
154
 
    MainWindow *m_mainWin;
155
 
    Sidebar *m_sidebar;
156
 
 
157
 
    /**
158
 
     * unique id
159
 
     */
160
 
    QString id;
161
 
 
162
 
    /**
163
 
     * is visible in sidebar
164
 
     */
165
 
    bool m_visible;
166
 
 
167
 
    /**
168
 
     * is this view persistent?
169
 
     */
170
 
    bool persistent;
171
 
 
172
 
    QPixmap icon;
173
 
    QString text;
174
 
};
175
 
 
176
 
class Sidebar : public KMultiTabBar
177
 
{
178
 
  Q_OBJECT
179
 
 
180
 
  public:
181
 
    Sidebar (KMultiTabBar::KMultiTabBarPosition pos, class MainWindow *mainwin, QWidget *parent);
182
 
    virtual ~Sidebar ();
183
 
 
184
 
    void setSplitter (Splitter *sp);
185
 
 
186
 
  public:
187
 
    ToolView *addWidget (const QPixmap &icon, const QString &text, ToolView *widget);
188
 
    bool removeWidget (ToolView *widget);
189
 
 
190
 
    bool showWidget (ToolView *widget);
191
 
    bool hideWidget (ToolView *widget);
192
 
 
193
 
    void setLastSize (int s) { m_lastSize = s; }
194
 
    int lastSize () const { return m_lastSize; }
195
 
    void updateLastSize ();
196
 
 
197
 
    bool splitterVisible () const { return m_ownSplit->isVisible(); }
198
 
 
199
 
    void restoreSession ();
200
 
 
201
 
     /**
202
 
     * restore the current session config from given object, use current group
203
 
     * @param config config object to use
204
 
     */
205
 
    void restoreSession (KConfig *config);
206
 
 
207
 
     /**
208
 
     * save the current session config to given object, use current group
209
 
     * @param config config object to use
210
 
     */
211
 
    void saveSession (KConfig *config);
212
 
 
213
 
  public slots:
214
 
    // reimplemented, to block a show() call if we have no children or if
215
 
    // all sidebars are forced hidden.
216
 
    virtual void show();
217
 
 
218
 
  private slots:
219
 
    void tabClicked(int);
220
 
 
221
 
  protected:
222
 
    bool eventFilter(QObject *obj, QEvent *ev);
223
 
 
224
 
  private slots:
225
 
    void buttonPopupActivate (int id);
226
 
 
227
 
  private:
228
 
    MainWindow *m_mainWin;
229
 
 
230
 
    KMultiTabBar::KMultiTabBarPosition m_pos;
231
 
    Splitter *m_splitter;
232
 
    KMultiTabBar *m_tabBar;
233
 
    Splitter *m_ownSplit;
234
 
 
235
 
    QIntDict<ToolView> m_idToWidget;
236
 
    QMap<ToolView*, int> m_widgetToId;
237
 
 
238
 
    /**
239
 
     * list of all toolviews around in this sidebar
240
 
     */
241
 
    QValueList<ToolView*> m_toolviews;
242
 
 
243
 
    int m_lastSize;
244
 
 
245
 
    int m_popupButton;
246
 
};
247
 
 
248
 
class MainWindow : public KParts::MainWindow
249
 
{
250
 
  Q_OBJECT
251
 
 
252
 
  friend class ToolView;
253
 
 
254
 
  //
255
 
  // Constructor area
256
 
  //
257
 
  public:
258
 
    /**
259
 
     * Constructor
260
 
     */
261
 
    MainWindow (QWidget* parentWidget = 0, const char* name = 0);
262
 
 
263
 
    /**
264
 
     * Destructor
265
 
     */
266
 
    virtual ~MainWindow ();
267
 
 
268
 
  //
269
 
  // public interfaces
270
 
  //
271
 
  public:
272
 
    /**
273
 
     * central widget ;)
274
 
     * use this as parent for your content
275
 
     * this widget will get focus if a toolview is hidden
276
 
     * @return central widget
277
 
     */
278
 
    QWidget *centralWidget () const;
279
 
 
280
 
    /**
281
 
     * add a given widget to the given sidebar if possible, name is very important
282
 
     * @param identifier unique identifier for this toolview
283
 
     * @param pos position for the toolview, if we are in session restore, this is only a preference
284
 
     * @param icon icon to use for the toolview
285
 
     * @param text text to use in addition to icon
286
 
     * @return created toolview on success or 0
287
 
     */
288
 
    ToolView *createToolView (const QString &identifier, KMultiTabBar::KMultiTabBarPosition pos, const QPixmap &icon, const QString &text);
289
 
 
290
 
    /**
291
 
     * give you handle to toolview for the given name, 0 if no toolview around
292
 
     * @param identifier toolview name
293
 
     * @return toolview if existing, else 0
294
 
     */
295
 
    ToolView *toolView (const QString &identifier) const;
296
 
 
297
 
    /**
298
 
     * set the toolview's tabbar style.
299
 
     * @param style the tabbar style.
300
 
     */
301
 
    void setToolViewStyle (KMultiTabBar::KMultiTabBarStyle style);
302
 
 
303
 
    /**
304
 
     * get the toolview's tabbar style. Call this before @p startRestore(),
305
 
     * otherwise you overwrite the usersettings.
306
 
     * @return toolview's tabbar style
307
 
     */
308
 
    KMultiTabBar::KMultiTabBarStyle toolViewStyle () const;
309
 
 
310
 
    /**
311
 
     * get the sidebars' visibility.
312
 
     * @return false, if the sidebars' visibility is forced hidden, otherwise true
313
 
     */
314
 
    bool sidebarsVisible() const;
315
 
 
316
 
  public slots:
317
 
    /**
318
 
     * set the sidebars' visibility to @p visible. If false, the sidebars
319
 
     * are @e always hidden. Usually you do not have to call this because
320
 
     * the user can set this in the menu.
321
 
     * @param visible sidebars visibility
322
 
     */
323
 
    void setSidebarsVisible( bool visible );
324
 
 
325
 
  protected:
326
 
    /**
327
 
     * called by toolview destructor
328
 
     * @param widget toolview which is destroyed
329
 
     */
330
 
    void toolViewDeleted (ToolView *widget);
331
 
 
332
 
  /**
333
 
   * modifiers for existing toolviews
334
 
   */
335
 
  public:
336
 
    /**
337
 
     * move a toolview around
338
 
     * @param widget toolview to move
339
 
     * @param pos position to move too, during session restore, only preference
340
 
     * @return success
341
 
     */
342
 
    bool moveToolView (ToolView *widget, KMultiTabBar::KMultiTabBarPosition pos);
343
 
 
344
 
    /**
345
 
     * show given toolview, discarded while session restore
346
 
     * @param widget toolview to show
347
 
     * @return success
348
 
     */
349
 
    bool showToolView (ToolView *widget);
350
 
 
351
 
    /**
352
 
     * hide given toolview, discarded while session restore
353
 
     * @param widget toolview to hide
354
 
     * @return success
355
 
     */
356
 
    bool hideToolView (ToolView *widget);
357
 
 
358
 
  /**
359
 
   * session saving and restore stuff
360
 
   */
361
 
  public:
362
 
    /**
363
 
     * start the restore
364
 
     * @param config config object to use
365
 
     * @param group config group to use
366
 
     */
367
 
    void startRestore (KConfig *config, const QString &group);
368
 
 
369
 
    /**
370
 
     * finish the restore
371
 
     */
372
 
    void finishRestore ();
373
 
 
374
 
    /**
375
 
     * save the current session config to given object and group
376
 
     * @param config config object to use
377
 
     * @param group config group to use
378
 
     */
379
 
    void saveSession (KConfig *config, const QString &group);
380
 
 
381
 
  /**
382
 
   * internal data ;)
383
 
   */
384
 
  private:
385
 
    /**
386
 
     * map identifiers to widgets
387
 
     */
388
 
    QDict<ToolView> m_idToWidget;
389
 
 
390
 
    /**
391
 
     * list of all toolviews around
392
 
     */
393
 
    QValueList<ToolView*> m_toolviews;
394
 
 
395
 
    /**
396
 
     * widget, which is the central part of the
397
 
     * main window ;)
398
 
     */
399
 
    QWidget *m_centralWidget;
400
 
 
401
 
    /**
402
 
     * horizontal splitter
403
 
     */
404
 
    Splitter *m_hSplitter;
405
 
 
406
 
    /**
407
 
     * vertical splitter
408
 
     */
409
 
    Splitter *m_vSplitter;
410
 
 
411
 
    /**
412
 
     * sidebars for the four sides
413
 
     */
414
 
    Sidebar *m_sidebars[4];
415
 
 
416
 
    /**
417
 
     * sidebars state.
418
 
     */
419
 
    bool m_sidebarsVisible;
420
 
 
421
 
    /**
422
 
     * config object for session restore, only valid between
423
 
     * start and finish restore calls
424
 
     */
425
 
    KConfig *m_restoreConfig;
426
 
 
427
 
    /**
428
 
     * restore group
429
 
     */
430
 
    QString m_restoreGroup;
431
 
 
432
 
    /**
433
 
     * out guiclient
434
 
     */
435
 
    GUIClient *m_guiClient;
436
 
};
437
 
 
438
 
}
439
 
 
440
 
#endif
441
 
 
442
 
// kate: space-indent on; indent-width 2;