summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmviewlayoutmanager.h
blob: 80c65e170e861abac35b55094a6c8aee56d8540a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2002 by Luis Carvalho
    email                : lpassos@mail.telepac.pt
    copyright            : (C) 2003 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/

#ifndef PMVIEWLAYOUTMANAGER_H
#define PMVIEWLAYOUTMANAGER_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <tqstring.h>
#include <tqmap.h>
#include <tqvaluelist.h>
#include <kstaticdeleter.h>

#include <kdialogbase.h>

#include "pmdockwidget.h"
#include "pmviewbase.h"

class TDEConfig;
class TQDomElement;
class TQLineEdit;
class PMShell;

/**
 * Class used internally by @ref PMViewLayout
 *
 * This class maintains all the information needed to create a docked view.
 */
class PMViewLayoutEntry
{
public:
   /**
    * Constructor
    */
   PMViewLayoutEntry( );
   /**
    * Copy constructor
    */
   PMViewLayoutEntry( const PMViewLayoutEntry& e );
   /**
    * Destructor
    */
   ~PMViewLayoutEntry( );

   TQString viewType( ) const { return m_viewType; }
   void setViewType( const TQString& vt );

   PMDockWidget::DockPosition dockPosition( ) const { return m_dockPosition; }
   void setDockPosition( PMDockWidget::DockPosition i );

   int columnWidth( ) const { return m_columnWidth; }
   void setColumnWidth( int i );

   int height( ) const { return m_height; }
   void setHeight( int i );

   int floatingHeight( ) const { return m_floatingHeight; }
   void setFloatingHeight( int h ) { m_floatingHeight = h; }

   int floatingWidth( ) const { return m_floatingWidth; }
   void setFloatingWidth( int w ) { m_floatingWidth = w; }

   int floatingPositionX( ) const { return m_floatingPositionX; }
   void setFloatingPositionX( int p ) { m_floatingPositionX = p; }
   int floatingPositionY( ) const { return m_floatingPositionY; }
   void setFloatingPositionY( int p ) { m_floatingPositionY = p; }

   void loadData( TQDomElement& e );
   void saveData( TQDomElement& e ) const;

   PMViewOptions* customOptions( ) const { return m_pCustomOptions; }
   void setCustomOptions( PMViewOptions* o );

   const TQString dockPositionAsString( );
   const TQString viewTypeAsString( );

private:
   TQString m_viewType;
   PMDockWidget::DockPosition m_dockPosition;
   int m_columnWidth;
   int m_height;
   int m_floatingWidth;
   int m_floatingHeight;
   int m_floatingPositionX;
   int m_floatingPositionY;
   PMViewOptions* m_pCustomOptions;
};

/**
 * Class used internally by @ref PMViewLayoutManager
 *
 * This class maintains a named layout. It basically stores all views
 * associated with that layout.
 */
class PMViewLayout
{
public:
   typedef TQValueList< PMViewLayoutEntry >::iterator iterator;
   /**
    * Constructor
    */
   PMViewLayout( );
   /**
    * Copy constructor
    */
   PMViewLayout( const PMViewLayout& vl );
   /**
    * Destructor
    */
   ~PMViewLayout( ) { }

   /**
    * Assignment operator
    */
   PMViewLayout& operator = ( const PMViewLayout& vl );

   TQString name( ) const { return m_name; }

   void loadData( TQDomElement& e );

   void saveData( TQDomElement& e, TQDomDocument& doc ) const;
   /**
    * Destroy all dock widgets in PMShell and create the new ones
    */
   void displayLayout( PMShell* shell );
   /**
    * Sets the name of the layout
    */
   void setName( const TQString& n );
   /**
    *
    * Add a new entry to the layout. By default it adds the entry at the end
    * of the list. If a position is given it adds the entry at the indicated
    * position
    */
   void addEntry( const PMViewLayoutEntry& e, int index = -1 );
   /**
    * Removes the entry at the given position
    */
   void removeEntry( int index );
   /**
    * Returns an iterator to the first entry
    */
   iterator begin( ) { return m_entries.begin( ); }
   /**
    * Returns an iterator to the last entry
    */
   iterator end( ) { return m_entries.end( ); }
   /**
    * Returns an iterator to the n-th entry
    */
   iterator at( int i ) { return m_entries.at( i ); }
   /**
    * Returns the entry at the given position
    */
   PMViewLayoutEntry& operator[]( int index ) { return m_entries[ index ]; }
   /**
    * Normalizes the column width and view heights
    */
   void normalize( );

   /**
    * Extracts the view layout from the current window
    */
   static PMViewLayout extractViewLayout( PMShell* shell );
private:
   static void recursiveExtractColumns(
      TQValueList< TQValueList< PMViewLayoutEntry > >& cols,
      TQValueList< TQValueList< PMViewLayoutEntry > >::iterator cit,
      int width, TQWidget* widget );

   static void recursiveExtractOneColumn(
      TQValueList< PMViewLayoutEntry >& entries,
      TQValueList< PMViewLayoutEntry >::iterator eit,
      int height, TQWidget* widget );

   TQString m_name;
   TQValueList< PMViewLayoutEntry > m_entries;
};

/**
 * Singleton that contains the view layouts available.
 *
 * It interacts with @ref PMShell to create the view layouts.
 * The class maintains a list of layouts as well as the name of the default
 * layout. The layouts are stored in a XML file caled viewlayouts.xml.
 */
class PMViewLayoutManager
{
public:
   /**
    * Destructor
    */
   ~PMViewLayoutManager( );
   /**
    * Returns the manager instance (singleton)
    */
   static PMViewLayoutManager* theManager( );

   /**
    * Returns the list of available view layouts
    */
   TQStringList availableLayouts( );
   /**
    * Sets the default layout
    */
   void setDefaultLayout( const TQString& name );
   /**
    * Returns the default layout
    */
   TQString defaultLayout( ) const { return m_defaultLayout; }
   /**
    * Destroy all dock widgets in PMShell and create the new ones
    */
   void displayLayout( const TQString& name, PMShell* shell );
   /**
    * Displays the layout indicated as default
    */
   void displayDefaultLayout( PMShell* shell );
   /**
    * Loads all layouts from the configuration file
    */
   void loadData( );
   /**
    * Saves the current layout collection to the configuration file
    */
   void saveData( );
   /**
    * Add a new empty layout
    */
   void addLayout( const TQString& name );
   /**
    * Add a new layout
    */
   void addLayout( const PMViewLayout& l ) { m_layouts.append( l ); }
   /**
    * Remove a layout
    */
   void removeLayout( const TQString& name );
   /**
    * Get a known layout
    */
   PMViewLayout* findLayout( const TQString& name );
   /**
    * Returns the list of available layouts
    */
   TQValueList<PMViewLayout> layouts( ) { return m_layouts; }
   /**
    * Sets the list of available layouts
    */
   void setLayouts( const TQValueList<PMViewLayout>& l ) { m_layouts = l; }
   /**
    * Fill the available layouts menu
    */
   void fillPopupMenu( TDEPopupMenu* pMenu );
private:
   /**
    * Constructor
    */
   PMViewLayoutManager( );

   bool m_layoutsLoaded;
   bool m_layoutDisplayed;
   TQString m_defaultLayout;
   TQValueList< PMViewLayout > m_layouts;

   static PMViewLayoutManager* s_pInstance;
   static KStaticDeleter<PMViewLayoutManager> s_staticDeleter;
};


class PMSaveViewLayoutDialog : public KDialogBase
{
   Q_OBJECT
  
public:
   PMSaveViewLayoutDialog( PMShell* parent, const char* name = 0 );
   ~PMSaveViewLayoutDialog( );
protected slots:
   virtual void slotOk( );
   void slotNameChanged( const TQString& );
   void slotNameSelected( const TQString& );
private:
   TQLineEdit* m_pLayoutName;
   PMShell* m_pShell;
};

#endif