summaryrefslogtreecommitdiffstats
path: root/kate/part/kateschema.h
blob: cf503be68886185005fd908e484bc6360c74c0a5 (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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/* This file is part of the KDE libraries
   Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
   Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __KATE_SCHEMA_H__
#define __KATE_SCHEMA_H__

#include "katehighlight.h"
#include "katedialogs.h"

#include <tqstringlist.h>
#include <tqintdict.h>
#include <tqmap.h>
#include <tqlistview.h>
#include <tqfont.h>

#include <tdeconfig.h>
#include <tdeaction.h>

class KateView;
class KateStyleListItem;
class KateStyleListCaption;

class KColorButton;

class TQPopupMenu;
class KComboBox;

class KateSchemaManager
{
  public:
    KateSchemaManager ();
    ~KateSchemaManager ();

    /**
     * Schema Config changed, update all renderers
     */
    void update (bool readfromfile = true);

    /**
     * return tdeconfig with right group set or set to Normal if not there
     */
    TDEConfig *schema (uint number);

    void addSchema (const TQString &t);

    void removeSchema (uint number);

    /**
     * is this schema valid ? (does it exist ?)
     */
    bool validSchema (uint number);

    /**
     * if not found, defaults to 0
     */
    uint number (const TQString &name);

    /**
     * group names in the end, no i18n involved
     */
    TQString name (uint number);

    /**
     * Don't modify, list with the names of the schemas (i18n name for the default ones)
     */
    const TQStringList &list () { return m_schemas; }

    static TQString normalSchema ();
    static TQString printingSchema ();

  private:
    TDEConfig m_config;
    TQStringList m_schemas;
};


class KateViewSchemaAction : public TDEActionMenu
{
  Q_OBJECT

  public:
    KateViewSchemaAction(const TQString& text, TQObject* parent = 0, const char* name = 0)
       : TDEActionMenu(text, parent, name) { init(); };

    ~KateViewSchemaAction(){;};

    void updateMenu (KateView *view);

  private:
    void init();

    TQGuardedPtr<KateView> m_view;
    TQStringList names;
    int last;

  public  slots:
    void slotAboutToShow();

  private slots:
    void setSchema (int mode);
};

//
// DIALOGS
//

/*
    TQListView that automatically adds columns for KateStyleListItems and provides a
    popup menu and a slot to edit a style using the keyboard.
    Added by anders, jan 23 2002.
*/
class KateStyleListView : public TQListView
{
  Q_OBJECT

  friend class KateStyleListItem;

  public:
    KateStyleListView( TQWidget *parent=0, bool showUseDefaults=false);
    ~KateStyleListView() {};
    /* Display a popupmenu for item i at the specified global position, eventually with a title,
       promoting the context name of that item */
    void showPopupMenu( KateStyleListItem *i, const TQPoint &globalPos, bool showtitle=false );
    void emitChanged() { emit changed(); };

    void setBgCol( const TQColor &c ) { bgcol = c; }
    void setSelCol( const TQColor &c ) { selcol = c; }
    void setNormalCol( const TQColor &c ) { normalcol = c; }

  private slots:
    /* Display a popupmenu for item i at item position */
    void showPopupMenu( TQListViewItem *i, const TQPoint &globalPos );
    /* call item to change a property, or display a menu */
    void slotMousePressed( int, TQListViewItem*, const TQPoint&, int );
    /* asks item to change the property in q */
    void mSlotPopupHandler( int z );
    void unsetColor( int );

  signals:
    void changed();

  private:
    TQColor bgcol, selcol, normalcol;
    TQFont docfont;
};

class KateSchemaConfigColorTab : public TQWidget
{
  Q_OBJECT

  public:
    KateSchemaConfigColorTab( TQWidget *parent = 0, const char *name = 0 );
    ~KateSchemaConfigColorTab();

  private:
    KColorButton *m_back;
    KColorButton *m_selected;
    KColorButton *m_current;
    KColorButton *m_bracket;
    KColorButton *m_wwmarker;
    KColorButton *m_iconborder;
    KColorButton *m_tmarker;
    KColorButton *m_linenumber;

    KColorButton *m_markers;           // bg color for current selected marker
    KComboBox* m_combobox;             // switch marker type

    // Class for storing the properties on 1 schema.
    class SchemaColors {
      public:
        TQColor back, selected, current, bracket, wwmarker, iconborder, tmarker, linenumber;
        TQMap<int, TQColor> markerColors;  // stores all markerColors
    };

    // schemaid=data, created when a schema is entered
    TQMap<int,SchemaColors> m_schemas;
    // current schema
    int m_schema;

  public slots:
    void apply();
    void schemaChanged( int newSchema );

  signals:
    void changed(); // connected to parentWidget()->parentWidget() TQT_SLOT(slotChanged)

  protected slots:
    void slotMarkerColorChanged(const TQColor&);
    void slotComboBoxChanged(int index);
};

typedef TQMap<int,TQFont> FontMap; // ### remove it

class KateSchemaConfigFontTab : public TQWidget
{
  Q_OBJECT

  public:
    KateSchemaConfigFontTab( TQWidget *parent = 0, const char *name = 0 );
    ~KateSchemaConfigFontTab();

  public:
    void readConfig (TDEConfig *config);

  public slots:
    void apply();
    void schemaChanged( int newSchema );

  signals:
    void changed(); // connected to parentWidget()->parentWidget() TQT_SLOT(slotChanged)

  private:
    class TDEFontChooser *m_fontchooser;
    FontMap m_fonts;
    int m_schema;

  private slots:
    void slotFontSelected( const TQFont &font );
};

class KateSchemaConfigFontColorTab : public TQWidget
{
  Q_OBJECT

  public:
    KateSchemaConfigFontColorTab( TQWidget *parent = 0, const char *name = 0 );
    ~KateSchemaConfigFontColorTab();

  public:
    void schemaChanged (uint schema);
    void reload ();
    void apply ();

    KateAttributeList *attributeList (uint schema);

  private:
    KateStyleListView *m_defaultStyles;
    TQIntDict<KateAttributeList> m_defaultStyleLists;
};

class KateSchemaConfigHighlightTab : public TQWidget
{
  Q_OBJECT

  public:
    KateSchemaConfigHighlightTab( TQWidget *parent = 0, const char *name = 0, KateSchemaConfigFontColorTab *page = 0, uint hl = 0 );
    ~KateSchemaConfigHighlightTab();

  public:
    void schemaChanged (uint schema);
    void reload ();
    void apply ();

  protected slots:
    void hlChanged(int z);

  private:
    KateSchemaConfigFontColorTab *m_defaults;

    TQComboBox *hlCombo;
    KateStyleListView *m_styles;

    uint m_schema;
    int m_hl;

    TQIntDict< TQIntDict<KateHlItemDataList> > m_hlDict;
};

class KateSchemaConfigPage : public KateConfigPage
{
  Q_OBJECT

  public:
    KateSchemaConfigPage ( TQWidget *parent, class KateDocument *doc=0 );
    ~KateSchemaConfigPage ();

  public slots:
    void apply();
    void reload();
    void reset();
    void defaults();

  private slots:
    void update ();
    void deleteSchema ();
    void newSchema ();
    void schemaChanged (int schema);

    void newCurrentPage (TQWidget *w);

  private:
    int m_lastSchema;
    int m_defaultSchema;

    class TQTabWidget *m_tabWidget;
    class TQPushButton *btndel;
    class TQComboBox *defaultSchemaCombo;
    class TQComboBox *schemaCombo;
    KateSchemaConfigColorTab *m_colorTab;
    KateSchemaConfigFontTab *m_fontTab;
    KateSchemaConfigFontColorTab *m_fontColorTab;
    KateSchemaConfigHighlightTab *m_highlightTab;
};

#endif