• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
kateschema.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
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 version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 //BEGIN Includes
21 #include "kateschema.h"
22 #include "kateschema.moc"
23 
24 #include "kateconfig.h"
25 #include "katedocument.h"
26 #include "katefactory.h"
27 #include "kateview.h"
28 #include "katerenderer.h"
29 
30 #include <tdelocale.h>
31 #include <kdialogbase.h>
32 #include <kcolorbutton.h>
33 #include <kcombobox.h>
34 #include <kinputdialog.h>
35 #include <tdefontdialog.h>
36 #include <kdebug.h>
37 #include <kiconloader.h>
38 #include <tdemessagebox.h>
39 #include <tdepopupmenu.h>
40 #include <kcolordialog.h>
41 #include <tdeapplication.h>
42 #include <tdeaboutdata.h>
43 #include <tdetexteditor/markinterface.h>
44 
45 #include <tqbuttongroup.h>
46 #include <tqcheckbox.h>
47 #include <tqptrcollection.h>
48 #include <tqdialog.h>
49 #include <tqgrid.h>
50 #include <tqgroupbox.h>
51 #include <tqlabel.h>
52 #include <tqtextcodec.h>
53 #include <tqlayout.h>
54 #include <tqlineedit.h>
55 #include <tqheader.h>
56 #include <tqlistbox.h>
57 #include <tqhbox.h>
58 #include <tqpainter.h>
59 #include <tqobjectlist.h>
60 #include <tqpixmap.h>
61 #include <tqpushbutton.h>
62 #include <tqradiobutton.h>
63 #include <tqspinbox.h>
64 #include <tqstringlist.h>
65 #include <tqtabwidget.h>
66 #include <tqvbox.h>
67 #include <tqvgroupbox.h>
68 #include <tqwhatsthis.h>
69 //END
70 
71 //BEGIN KateStyleListViewItem decl
72 /*
73  TQListViewItem subclass to display/edit a style, bold/italic is check boxes,
74  normal and selected colors are boxes, which will display a color chooser when
75  activated.
76  The context name for the style will be drawn using the editor default font and
77  the chosen colors.
78  This widget id designed to handle the default as well as the individual hl style
79  lists.
80  This widget is designed to work with the KateStyleListView class exclusively.
81  Added by anders, jan 23 2002.
82 */
83 class KateStyleListItem : public TQListViewItem
84 {
85  public:
86  KateStyleListItem( TQListViewItem *parent=0, const TQString & stylename=0,
87  class KateAttribute* defaultstyle=0, class KateHlItemData *data=0 );
88  KateStyleListItem( TQListView *parent, const TQString & stylename=0,
89  class KateAttribute* defaultstyle=0, class KateHlItemData *data=0 );
90  ~KateStyleListItem() { if (st) delete is; };
91 
92  /* mainly for readability */
93  enum Property { ContextName, Bold, Italic, Underline, Strikeout, Color, SelColor, BgColor, SelBgColor, UseDefStyle };
94 
95  /* initializes the style from the default and the hldata */
96  void initStyle();
97  /* updates the hldata's style */
98  void updateStyle();
99  /* reimp */
100  virtual int width ( const TQFontMetrics & fm, const TQListView * lv, int c ) const;
101  /* calls changeProperty() if it makes sense considering pos. */
102  void activate( int column, const TQPoint &localPos );
103  /* For bool fields, toggles them, for color fields, display a color chooser */
104  void changeProperty( Property p );
108  void unsetColor( int c );
109  /* style context name */
110  TQString contextName() { return text(0); };
111  /* only true for a hl mode item using it's default style */
112  bool defStyle();
113  /* true for default styles */
114  bool isDefault();
115  /* whichever style is active (st for hl mode styles not using
116  the default style, ds otherwise) */
117  class KateAttribute* style() { return is; };
118 
119  protected:
120  /* reimp */
121  void paintCell(TQPainter *p, const TQColorGroup& cg, int col, int width, int align);
122 
123  private:
124  /* private methods to change properties */
125  void toggleDefStyle();
126  void setColor( int );
127  /* helper function to copy the default style into the KateHlItemData,
128  when a property is changed and we are using default style. */
129 
130  class KateAttribute *is, // the style currently in use
131  *ds; // default style for hl mode contexts and default styles
132  class KateHlItemData *st; // itemdata for hl mode contexts
133 };
134 //END
135 
136 //BEGIN KateStyleListCaption decl
137 /*
138  This is a simple subclass for drawing the language names in a nice treeview
139  with the styles. It is needed because we do not like to mess with the default
140  palette of the containing ListView. Only the paintCell method is overwritten
141  to use our own palette (that is set on the viewport rather than on the listview
142  itself).
143 */
144 class KateStyleListCaption : public TQListViewItem
145 {
146  public:
147  KateStyleListCaption( TQListView *parent, const TQString & name );
148  ~KateStyleListCaption() {};
149 
150  protected:
151  void paintCell(TQPainter *p, const TQColorGroup& cg, int col, int width, int align);
152 };
153 //END
154 
155 //BEGIN KateSchemaManager
156 TQString KateSchemaManager::normalSchema ()
157 {
158  return TDEApplication::kApplication()->aboutData()->appName () + TQString (" - Normal");
159 }
160 
161 TQString KateSchemaManager::printingSchema ()
162 {
163  return TDEApplication::kApplication()->aboutData()->appName () + TQString (" - Printing");
164 }
165 
166 KateSchemaManager::KateSchemaManager ()
167  : m_config ("kateschemarc", false, false)
168 {
169  update ();
170 }
171 
172 KateSchemaManager::~KateSchemaManager ()
173 {
174 }
175 
176 //
177 // read the types from config file and update the internal list
178 //
179 void KateSchemaManager::update (bool readfromfile)
180 {
181  if (readfromfile)
182  m_config.reparseConfiguration ();
183 
184  m_schemas = m_config.groupList();
185  m_schemas.sort ();
186 
187  m_schemas.remove (printingSchema());
188  m_schemas.remove (normalSchema());
189  m_schemas.prepend (printingSchema());
190  m_schemas.prepend (normalSchema());
191 }
192 
193 //
194 // get the right group
195 // special handling of the default schemas ;)
196 //
197 TDEConfig *KateSchemaManager::schema (uint number)
198 {
199  if ((number>1) && (number < m_schemas.count()))
200  m_config.setGroup (m_schemas[number]);
201  else if (number == 1)
202  m_config.setGroup (printingSchema());
203  else
204  m_config.setGroup (normalSchema());
205 
206  return &m_config;
207 }
208 
209 void KateSchemaManager::addSchema (const TQString &t)
210 {
211  m_config.setGroup (t);
212  m_config.writeEntry("Color Background", TDEGlobalSettings::baseColor());
213 
214  update (false);
215 }
216 
217 void KateSchemaManager::removeSchema (uint number)
218 {
219  if (number >= m_schemas.count())
220  return;
221 
222  if (number < 2)
223  return;
224 
225  m_config.deleteGroup (name (number));
226 
227  update (false);
228 }
229 
230 bool KateSchemaManager::validSchema (uint number)
231 {
232  if (number < m_schemas.count())
233  return true;
234 
235  return false;
236 }
237 
238 uint KateSchemaManager::number (const TQString &name)
239 {
240  if (name == normalSchema())
241  return 0;
242 
243  if (name == printingSchema())
244  return 1;
245 
246  int i;
247  if ((i = m_schemas.findIndex(name)) > -1)
248  return i;
249 
250  return 0;
251 }
252 
253 TQString KateSchemaManager::name (uint number)
254 {
255  if ((number>1) && (number < m_schemas.count()))
256  return m_schemas[number];
257  else if (number == 1)
258  return printingSchema();
259 
260  return normalSchema();
261 }
262 //END
263 
264 //
265 // DIALOGS !!!
266 //
267 
268 //BEGIN KateSchemaConfigColorTab -- 'Colors' tab
269 KateSchemaConfigColorTab::KateSchemaConfigColorTab( TQWidget *parent, const char * )
270  : TQWidget (parent)
271 {
272  m_schema = -1;
273 
274  TQHBox *b;
275  TQLabel *label;
276 
277  TQVBoxLayout *blay=new TQVBoxLayout(this, 0, KDialog::spacingHint());
278 
279  TQVGroupBox *gbTextArea = new TQVGroupBox(i18n("Text Area Background"), this);
280 
281  b = new TQHBox (gbTextArea);
282  b->setSpacing(KDialog::spacingHint());
283  label = new TQLabel( i18n("Normal text:"), b);
284  label->setAlignment( AlignLeft|AlignVCenter);
285  m_back = new KColorButton(b);
286 
287  b = new TQHBox (gbTextArea);
288  b->setSpacing(KDialog::spacingHint());
289  label = new TQLabel( i18n("Selected text:"), b);
290  label->setAlignment( AlignLeft|AlignVCenter);
291  m_selected = new KColorButton(b);
292 
293  b = new TQHBox (gbTextArea);
294  b->setSpacing(KDialog::spacingHint());
295  label = new TQLabel( i18n("Current line:"), b);
296  label->setAlignment( AlignLeft|AlignVCenter);
297  m_current = new KColorButton(b);
298 
299  // Markers from tdelibs/interfaces/ktextinterface/markinterface.h
300  b = new TQHBox (gbTextArea);
301  b->setSpacing(KDialog::spacingHint());
302  m_combobox = new KComboBox(b, "color_combo_box");
303  // add the predefined mark types as defined in markinterface.h
304  m_combobox->insertItem(i18n("Bookmark")); // markType01
305  m_combobox->insertItem(i18n("Active Breakpoint")); // markType02
306  m_combobox->insertItem(i18n("Reached Breakpoint")); // markType03
307  m_combobox->insertItem(i18n("Disabled Breakpoint")); // markType04
308  m_combobox->insertItem(i18n("Execution")); // markType05
309  m_combobox->insertItem(i18n("Warning")); // markType06
310  m_combobox->insertItem(i18n("Error")); // markType07
311  m_combobox->setCurrentItem(0);
312  m_markers = new KColorButton(b, "marker_color_button");
313  connect( m_combobox, TQT_SIGNAL( activated( int ) ), TQT_SLOT( slotComboBoxChanged( int ) ) );
314 
315  blay->addWidget(gbTextArea);
316 
317  TQVGroupBox *gbBorder = new TQVGroupBox(i18n("Additional Elements"), this);
318 
319  b = new TQHBox (gbBorder);
320  b->setSpacing(KDialog::spacingHint());
321  label = new TQLabel( i18n("Left border background:"), b);
322  label->setAlignment( AlignLeft|AlignVCenter);
323  m_iconborder = new KColorButton(b);
324 
325  b = new TQHBox (gbBorder);
326  b->setSpacing(KDialog::spacingHint());
327  label = new TQLabel( i18n("Line numbers:"), b);
328  label->setAlignment( AlignLeft|AlignVCenter);
329  m_linenumber = new KColorButton(b);
330 
331  b = new TQHBox (gbBorder);
332  b->setSpacing(KDialog::spacingHint());
333  label = new TQLabel( i18n("Bracket highlight:"), b);
334  label->setAlignment( AlignLeft|AlignVCenter);
335  m_bracket = new KColorButton(b);
336 
337  b = new TQHBox (gbBorder);
338  b->setSpacing(KDialog::spacingHint());
339  label = new TQLabel( i18n("Word wrap markers:"), b);
340  label->setAlignment( AlignLeft|AlignVCenter);
341  m_wwmarker = new KColorButton(b);
342 
343  b = new TQHBox (gbBorder);
344  b->setSpacing(KDialog::spacingHint());
345  label = new TQLabel( i18n("Tab markers:"), b);
346  label->setAlignment( AlignLeft|AlignVCenter);
347  m_tmarker = new KColorButton(b);
348 
349  blay->addWidget(gbBorder);
350 
351  blay->addStretch();
352 
353  // connect signal changed(); changed is emitted by a ColorButton change!
354  connect( this, TQT_SIGNAL( changed() ), parent->parentWidget(), TQT_SLOT( slotChanged() ) );
355 
356  // TQWhatsThis help
357  TQWhatsThis::add(m_back, i18n("<p>Sets the background color of the editing area.</p>"));
358  TQWhatsThis::add(m_selected, i18n("<p>Sets the background color of the selection.</p>"
359  "<p>To set the text color for selected text, use the \"<b>Configure "
360  "Highlighting</b>\" dialog.</p>"));
361  TQWhatsThis::add(m_markers, i18n("<p>Sets the background color of the selected "
362  "marker type.</p><p><b>Note</b>: The marker color is displayed lightly because "
363  "of transparency.</p>"));
364  TQWhatsThis::add(m_combobox, i18n("<p>Select the marker type you want to change.</p>"));
365  TQWhatsThis::add(m_current, i18n("<p>Sets the background color of the currently "
366  "active line, which means the line where your cursor is positioned.</p>"));
367  TQWhatsThis::add( m_linenumber, i18n(
368  "<p>This color will be used to draw the line numbers (if enabled) and the "
369  "lines in the code-folding pane.</p>" ) );
370  TQWhatsThis::add(m_bracket, i18n("<p>Sets the bracket matching color. This means, "
371  "if you place the cursor e.g. at a <b>(</b>, the matching <b>)</b> will "
372  "be highlighted with this color.</p>"));
373  TQWhatsThis::add(m_wwmarker, i18n(
374  "<p>Sets the color of Word Wrap-related markers:</p>"
375  "<dl><dt>Static Word Wrap</dt><dd>A vertical line which shows the column where "
376  "text is going to be wrapped</dd>"
377  "<dt>Dynamic Word Wrap</dt><dd>An arrow shown to the left of "
378  "visually-wrapped lines</dd></dl>"));
379  TQWhatsThis::add(m_tmarker, i18n(
380  "<p>Sets the color of the tabulator marks:</p>"));
381 }
382 
383 KateSchemaConfigColorTab::~KateSchemaConfigColorTab()
384 {
385 }
386 
387 void KateSchemaConfigColorTab::schemaChanged ( int newSchema )
388 {
389  // save curent schema
390  if ( m_schema > -1 )
391  {
392  m_schemas[ m_schema ].back = m_back->color();
393  m_schemas[ m_schema ].selected = m_selected->color();
394  m_schemas[ m_schema ].current = m_current->color();
395  m_schemas[ m_schema ].bracket = m_bracket->color();
396  m_schemas[ m_schema ].wwmarker = m_wwmarker->color();
397  m_schemas[ m_schema ].iconborder = m_iconborder->color();
398  m_schemas[ m_schema ].tmarker = m_tmarker->color();
399  m_schemas[ m_schema ].linenumber = m_linenumber->color();
400  }
401 
402  if ( newSchema == m_schema ) return;
403 
404  // switch
405  m_schema = newSchema;
406 
407  // first disconnect all signals otherwise setColor emits changed
408  m_back ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
409  m_selected ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
410  m_current ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
411  m_bracket ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
412  m_wwmarker ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
413  m_iconborder->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
414  m_tmarker ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
415  m_markers ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
416  m_linenumber->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
417 
418  // If we havent this schema, read in from config file
419  if ( ! m_schemas.contains( newSchema ) )
420  {
421  // fallback defaults
422  TQColor tmp0 (TDEGlobalSettings::baseColor());
423  TQColor tmp1 (TDEGlobalSettings::highlightColor());
424  TQColor tmp2 (TDEGlobalSettings::alternateBackgroundColor());
425  TQColor tmp3 ( "#FFFF99" );
426  TQColor tmp4 (tmp2.dark());
427  TQColor tmp5 ( TDEGlobalSettings::textColor() );
428  TQColor tmp6 ( "#EAE9E8" );
429  TQColor tmp7 ( "#000000" );
430 
431  // same std colors like in KateDocument::markColor
432  TQValueVector <TQColor> mark(KTextEditor::MarkInterface::reservedMarkersCount());
433  Q_ASSERT(mark.size() > 6);
434  mark[0] = Qt::blue;
435  mark[1] = Qt::red;
436  mark[2] = Qt::yellow;
437  mark[3] = Qt::magenta;
438  mark[4] = Qt::gray;
439  mark[5] = Qt::green;
440  mark[6] = Qt::red;
441 
442  SchemaColors c;
443  TDEConfig *config = KateFactory::self()->schemaManager()->schema(newSchema);
444 
445  c.back= config->readColorEntry("Color Background", &tmp0);
446  c.selected = config->readColorEntry("Color Selection", &tmp1);
447  c.current = config->readColorEntry("Color Highlighted Line", &tmp2);
448  c.bracket = config->readColorEntry("Color Highlighted Bracket", &tmp3);
449  c.wwmarker = config->readColorEntry("Color Word Wrap Marker", &tmp4);
450  c.tmarker = config->readColorEntry("Color Tab Marker", &tmp5);
451  c.iconborder = config->readColorEntry("Color Icon Bar", &tmp6);
452  c.linenumber = config->readColorEntry("Color Line Number", &tmp7);
453 
454  for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
455  c.markerColors[i] = config->readColorEntry( TQString("Color MarkType%1").arg(i+1), &mark[i] );
456 
457  m_schemas[ newSchema ] = c;
458  }
459 
460  m_back->setColor( m_schemas[ newSchema ].back);
461  m_selected->setColor( m_schemas [ newSchema ].selected );
462  m_current->setColor( m_schemas [ newSchema ].current );
463  m_bracket->setColor( m_schemas [ newSchema ].bracket );
464  m_wwmarker->setColor( m_schemas [ newSchema ].wwmarker );
465  m_tmarker->setColor( m_schemas [ newSchema ].tmarker );
466  m_iconborder->setColor( m_schemas [ newSchema ].iconborder );
467  m_linenumber->setColor( m_schemas [ newSchema ].linenumber );
468 
469  // map from 0..reservedMarkersCount()-1 - the same index as in markInterface
470  for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
471  {
472  TQPixmap pix(16, 16);
473  pix.fill( m_schemas [ newSchema ].markerColors[i]);
474  m_combobox->changeItem(pix, m_combobox->text(i), i);
475  }
476  m_markers->setColor( m_schemas [ newSchema ].markerColors[ m_combobox->currentItem() ] );
477 
478  connect( m_back , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
479  connect( m_selected , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
480  connect( m_current , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
481  connect( m_bracket , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
482  connect( m_wwmarker , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
483  connect( m_iconborder, TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
484  connect( m_tmarker , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
485  connect( m_linenumber, TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
486  connect( m_markers , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SLOT( slotMarkerColorChanged( const TQColor& ) ) );
487 }
488 
489 void KateSchemaConfigColorTab::apply ()
490 {
491  schemaChanged( m_schema );
492  TQMap<int,SchemaColors>::Iterator it;
493  for ( it = m_schemas.begin(); it != m_schemas.end(); ++it )
494  {
495  kdDebug(13030)<<"APPLY scheme = "<<it.key()<<endl;
496  TDEConfig *config = KateFactory::self()->schemaManager()->schema( it.key() );
497  kdDebug(13030)<<"Using config group "<<config->group()<<endl;
498  SchemaColors c = it.data();
499 
500  config->writeEntry("Color Background", c.back);
501  config->writeEntry("Color Selection", c.selected);
502  config->writeEntry("Color Highlighted Line", c.current);
503  config->writeEntry("Color Highlighted Bracket", c.bracket);
504  config->writeEntry("Color Word Wrap Marker", c.wwmarker);
505  config->writeEntry("Color Tab Marker", c.tmarker);
506  config->writeEntry("Color Icon Bar", c.iconborder);
507  config->writeEntry("Color Line Number", c.linenumber);
508 
509  for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
510  {
511  config->writeEntry(TQString("Color MarkType%1").arg(i + 1), c.markerColors[i]);
512  }
513  }
514 }
515 
516 void KateSchemaConfigColorTab::slotMarkerColorChanged( const TQColor& color)
517 {
518  int index = m_combobox->currentItem();
519  m_schemas[ m_schema ].markerColors[ index ] = color;
520  TQPixmap pix(16, 16);
521  pix.fill(color);
522  m_combobox->changeItem(pix, m_combobox->text(index), index);
523 
524  emit changed();
525 }
526 
527 void KateSchemaConfigColorTab::slotComboBoxChanged(int index)
528 {
529  // temporarily disconnect the changed-signal because setColor emits changed as well
530  m_markers->disconnect( TQT_SIGNAL( changed( const TQColor& ) ) );
531  m_markers->setColor( m_schemas[m_schema].markerColors[index] );
532  connect( m_markers, TQT_SIGNAL( changed( const TQColor& ) ), TQT_SLOT( slotMarkerColorChanged( const TQColor& ) ) );
533 }
534 
535 //END KateSchemaConfigColorTab
536 
537 //BEGIN FontConfig -- 'Fonts' tab
538 KateSchemaConfigFontTab::KateSchemaConfigFontTab( TQWidget *parent, const char * )
539  : TQWidget (parent)
540 {
541  // sizemanagment
542  TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
543 
544  m_fontchooser = new TDEFontChooser ( this, 0L, false, TQStringList(), false );
545  m_fontchooser->enableColumn(TDEFontChooser::StyleList, false);
546  grid->addWidget( m_fontchooser, 0, 0);
547 
548  connect (this, TQT_SIGNAL( changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
549  m_schema = -1;
550 }
551 
552 KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
553 {
554 }
555 
556 void KateSchemaConfigFontTab::slotFontSelected( const TQFont &font )
557 {
558  if ( m_schema > -1 )
559  {
560  m_fonts[m_schema] = font;
561  emit changed();
562  }
563 }
564 
565 void KateSchemaConfigFontTab::apply()
566 {
567  FontMap::Iterator it;
568  for ( it = m_fonts.begin(); it != m_fonts.end(); ++it )
569  {
570  KateFactory::self()->schemaManager()->schema( it.key() )->writeEntry( "Font", it.data() );
571  }
572 }
573 
574 void KateSchemaConfigFontTab::schemaChanged( int newSchema )
575 {
576  if ( m_schema > -1 )
577  m_fonts[ m_schema ] = m_fontchooser->font();
578 
579  m_schema = newSchema;
580 
581  TQFont f (TDEGlobalSettings::fixedFont());
582 
583  m_fontchooser->disconnect ( this );
584  m_fontchooser->setFont ( KateFactory::self()->schemaManager()->schema( newSchema )->readFontEntry("Font", &f) );
585  m_fonts[ newSchema ] = m_fontchooser->font();
586  connect (m_fontchooser, TQT_SIGNAL (fontSelected( const TQFont & )), this, TQT_SLOT (slotFontSelected( const TQFont & )));
587 }
588 //END FontConfig
589 
590 //BEGIN FontColorConfig -- 'Normal Text Styles' tab
591 KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab( TQWidget *parent, const char * )
592  : TQWidget (parent)
593 {
594  m_defaultStyleLists.setAutoDelete(true);
595 
596  // sizemanagment
597  TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
598 
599  m_defaultStyles = new KateStyleListView( this, false );
600  grid->addWidget( m_defaultStyles, 0, 0);
601 
602  connect (m_defaultStyles, TQT_SIGNAL (changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
603 
604  TQWhatsThis::add( m_defaultStyles, i18n(
605  "This list displays the default styles for the current schema and "
606  "offers the means to edit them. The style name reflects the current "
607  "style settings."
608  "<p>To edit the colors, click the colored squares, or select the color "
609  "to edit from the popup menu.<p>You can unset the Background and Selected "
610  "Background colors from the popup menu when appropriate.") );
611 }
612 
613 KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab()
614 {
615 }
616 
617 KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema)
618 {
619  if (!m_defaultStyleLists[schema])
620  {
621  KateAttributeList *list = new KateAttributeList ();
622  KateHlManager::self()->getDefaults(schema, *list);
623 
624  m_defaultStyleLists.insert (schema, list);
625  }
626 
627  return m_defaultStyleLists[schema];
628 }
629 
630 void KateSchemaConfigFontColorTab::schemaChanged (uint schema)
631 {
632  m_defaultStyles->clear ();
633 
634  KateAttributeList *l = attributeList (schema);
635 
636  // set colors
637  TQPalette p ( m_defaultStyles->palette() );
638  TQColor _c ( TDEGlobalSettings::baseColor() );
639  p.setColor( TQColorGroup::Base,
640  KateFactory::self()->schemaManager()->schema(schema)->
641  readColorEntry( "Color Background", &_c ) );
642  _c = TDEGlobalSettings::highlightColor();
643  p.setColor( TQColorGroup::Highlight,
644  KateFactory::self()->schemaManager()->schema(schema)->
645  readColorEntry( "Color Selection", &_c ) );
646  _c = l->at(0)->textColor(); // not quite as much of an assumption ;)
647  p.setColor( TQColorGroup::Text, _c );
648  m_defaultStyles->viewport()->setPalette( p );
649 
650  // insert the default styles backwards to get them in the right order
651  for ( int i = KateHlManager::self()->defaultStyles() - 1; i >= 0; i-- )
652  {
653  new KateStyleListItem( m_defaultStyles, KateHlManager::self()->defaultStyleName(i, true), l->at( i ) );
654  }
655 }
656 
657 void KateSchemaConfigFontColorTab::reload ()
658 {
659  m_defaultStyles->clear ();
660  m_defaultStyleLists.clear ();
661 }
662 
663 void KateSchemaConfigFontColorTab::apply ()
664 {
665  for ( TQIntDictIterator<KateAttributeList> it( m_defaultStyleLists ); it.current(); ++it )
666  KateHlManager::self()->setDefaults(it.currentKey(), *(it.current()));
667 }
668 
669 //END FontColorConfig
670 
671 //BEGIN KateSchemaConfigHighlightTab -- 'Highlighting Text Styles' tab
672 KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab( TQWidget *parent, const char *, KateSchemaConfigFontColorTab *page, uint hl )
673  : TQWidget (parent)
674 {
675  m_defaults = page;
676 
677  m_schema = 0;
678  m_hl = 0;
679 
680  m_hlDict.setAutoDelete (true);
681 
682  TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
683 
684  // hl chooser
685  TQHBox *hbHl = new TQHBox( this );
686  layout->add (hbHl);
687 
688  hbHl->setSpacing( KDialog::spacingHint() );
689  TQLabel *lHl = new TQLabel( i18n("H&ighlight:"), hbHl );
690  hlCombo = new TQComboBox( false, hbHl );
691  lHl->setBuddy( hlCombo );
692  connect( hlCombo, TQT_SIGNAL(activated(int)),
693  this, TQT_SLOT(hlChanged(int)) );
694 
695  for( int i = 0; i < KateHlManager::self()->highlights(); i++) {
696  if (KateHlManager::self()->hlSection(i).length() > 0)
697  hlCombo->insertItem(KateHlManager::self()->hlSection(i) + TQString ("/") + KateHlManager::self()->hlNameTranslated(i));
698  else
699  hlCombo->insertItem(KateHlManager::self()->hlNameTranslated(i));
700  }
701  hlCombo->setCurrentItem(0);
702 
703  // styles listview
704  m_styles = new KateStyleListView( this, true );
705  layout->addWidget (m_styles, 999);
706 
707  hlCombo->setCurrentItem ( hl );
708  hlChanged ( hl );
709 
710  TQWhatsThis::add( m_styles, i18n(
711  "This list displays the contexts of the current syntax highlight mode and "
712  "offers the means to edit them. The context name reflects the current "
713  "style settings.<p>To edit using the keyboard, press "
714  "<strong>&lt;SPACE&gt;</strong> and choose a property from the popup menu."
715  "<p>To edit the colors, click the colored squares, or select the color "
716  "to edit from the popup menu.<p>You can unset the Background and Selected "
717  "Background colors from the context menu when appropriate.") );
718 
719  connect (m_styles, TQT_SIGNAL (changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
720 }
721 
722 KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
723 {
724 }
725 
726 void KateSchemaConfigHighlightTab::hlChanged(int z)
727 {
728  m_hl = z;
729 
730  schemaChanged (m_schema);
731 }
732 
733 void KateSchemaConfigHighlightTab::schemaChanged (uint schema)
734 {
735  m_schema = schema;
736 
737  kdDebug(13030) << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl << endl;
738 
739  m_styles->clear ();
740 
741  if (!m_hlDict[m_schema])
742  {
743  kdDebug(13030) << "NEW SCHEMA, create dict" << endl;
744 
745  m_hlDict.insert (schema, new TQIntDict<KateHlItemDataList>);
746  m_hlDict[m_schema]->setAutoDelete (true);
747  }
748 
749  if (!m_hlDict[m_schema]->find(m_hl))
750  {
751  kdDebug(13030) << "NEW HL, create list" << endl;
752 
753  KateHlItemDataList *list = new KateHlItemDataList ();
754  KateHlManager::self()->getHl( m_hl )->getKateHlItemDataListCopy (m_schema, *list);
755  m_hlDict[m_schema]->insert (m_hl, list);
756  }
757 
758  KateAttributeList *l = m_defaults->attributeList (schema);
759 
760  // Set listview colors
761  // We do that now, because we can now get the "normal text" color.
762  // TODO this reads of the TDEConfig object, which should be changed when
763  // the color tab is fixed.
764  TQPalette p ( m_styles->palette() );
765  TQColor _c ( TDEGlobalSettings::baseColor() );
766  p.setColor( TQColorGroup::Base,
767  KateFactory::self()->schemaManager()->schema(m_schema)->
768  readColorEntry( "Color Background", &_c ) );
769  _c = TDEGlobalSettings::highlightColor();
770  p.setColor( TQColorGroup::Highlight,
771  KateFactory::self()->schemaManager()->schema(m_schema)->
772  readColorEntry( "Color Selection", &_c ) );
773  _c = l->at(0)->textColor(); // not quite as much of an assumption ;)
774  p.setColor( TQColorGroup::Text, _c );
775  m_styles->viewport()->setPalette( p );
776 
777  TQDict<KateStyleListCaption> prefixes;
778  for ( KateHlItemData *itemData = m_hlDict[m_schema]->find(m_hl)->last();
779  itemData != 0L;
780  itemData = m_hlDict[m_schema]->find(m_hl)->prev())
781  {
782  kdDebug(13030) << "insert items " << itemData->name << endl;
783 
784  // All stylenames have their language mode prefixed, e.g. HTML:Comment
785  // split them and put them into nice substructures.
786  int c = itemData->name.find(':');
787  if ( c > 0 ) {
788  TQString prefix = itemData->name.left(c);
789  TQString name = itemData->name.mid(c+1);
790 
791  KateStyleListCaption *parent = prefixes.find( prefix );
792  if ( ! parent )
793  {
794  parent = new KateStyleListCaption( m_styles, prefix );
795  parent->setOpen(true);
796  prefixes.insert( prefix, parent );
797  }
798  new KateStyleListItem( parent, name, l->at(itemData->defStyleNum), itemData );
799  } else {
800  new KateStyleListItem( m_styles, itemData->name, l->at(itemData->defStyleNum), itemData );
801  }
802  }
803 }
804 
805 void KateSchemaConfigHighlightTab::reload ()
806 {
807  m_styles->clear ();
808  m_hlDict.clear ();
809 
810  hlChanged (0);
811 }
812 
813 void KateSchemaConfigHighlightTab::apply ()
814 {
815  for ( TQIntDictIterator< TQIntDict<KateHlItemDataList> > it( m_hlDict ); it.current(); ++it )
816  for ( TQIntDictIterator< KateHlItemDataList > it2( *it.current() ); it2.current(); ++it2 )
817  {
818  KateHlManager::self()->getHl( it2.currentKey() )->setKateHlItemDataList (it.currentKey(), *(it2.current()));
819  }
820 }
821 
822 //END KateSchemaConfigHighlightTab
823 
824 //BEGIN KateSchemaConfigPage -- Main dialog page
825 KateSchemaConfigPage::KateSchemaConfigPage( TQWidget *parent, KateDocument *doc )
826  : KateConfigPage( parent ),
827  m_lastSchema (-1)
828 {
829  TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
830 
831  TQHBox *hbHl = new TQHBox( this );
832  layout->add (hbHl);
833  hbHl->setSpacing( KDialog::spacingHint() );
834  TQLabel *lHl = new TQLabel( i18n("&Schema:"), hbHl );
835  schemaCombo = new TQComboBox( false, hbHl );
836  lHl->setBuddy( schemaCombo );
837  connect( schemaCombo, TQT_SIGNAL(activated(int)),
838  this, TQT_SLOT(schemaChanged(int)) );
839 
840  TQPushButton *btnnew = new TQPushButton( i18n("&New..."), hbHl );
841  connect( btnnew, TQT_SIGNAL(clicked()), this, TQT_SLOT(newSchema()) );
842 
843  btndel = new TQPushButton( i18n("&Delete"), hbHl );
844  connect( btndel, TQT_SIGNAL(clicked()), this, TQT_SLOT(deleteSchema()) );
845 
846  m_tabWidget = new TQTabWidget ( this );
847  m_tabWidget->setMargin (KDialog::marginHint());
848  layout->add (m_tabWidget);
849 
850  connect (m_tabWidget, TQT_SIGNAL (currentChanged (TQWidget *)), this, TQT_SLOT (newCurrentPage (TQWidget *)));
851 
852  m_colorTab = new KateSchemaConfigColorTab (m_tabWidget);
853  m_tabWidget->addTab (m_colorTab, i18n("Colors"));
854 
855  m_fontTab = new KateSchemaConfigFontTab (m_tabWidget);
856  m_tabWidget->addTab (m_fontTab, i18n("Font"));
857 
858  m_fontColorTab = new KateSchemaConfigFontColorTab (m_tabWidget);
859  m_tabWidget->addTab (m_fontColorTab, i18n("Normal Text Styles"));
860 
861  uint hl = doc ? doc->hlMode() : 0;
862  m_highlightTab = new KateSchemaConfigHighlightTab (m_tabWidget, "", m_fontColorTab, hl );
863  m_tabWidget->addTab (m_highlightTab, i18n("Highlighting Text Styles"));
864 
865  hbHl = new TQHBox( this );
866  layout->add (hbHl);
867  hbHl->setSpacing( KDialog::spacingHint() );
868  lHl = new TQLabel( i18n("&Default schema for %1:").arg(TDEApplication::kApplication()->aboutData()->programName ()), hbHl );
869  defaultSchemaCombo = new TQComboBox( false, hbHl );
870  lHl->setBuddy( defaultSchemaCombo );
871 
872 
873  m_defaultSchema = (doc && doc->activeView()) ? doc->activeView()->renderer()->config()->schema() : KateRendererConfig::global()->schema();
874 
875  reload();
876 
877  connect( defaultSchemaCombo, TQT_SIGNAL(activated(int)),
878  this, TQT_SLOT(slotChanged()) );
879 }
880 
881 KateSchemaConfigPage::~KateSchemaConfigPage ()
882 {
883  // just reload config from disc
884  KateFactory::self()->schemaManager()->update ();
885 }
886 
887 void KateSchemaConfigPage::apply()
888 {
889  m_colorTab->apply();
890  m_fontTab->apply();
891  m_fontColorTab->apply ();
892  m_highlightTab->apply ();
893 
894  // just sync the config
895  KateFactory::self()->schemaManager()->schema (0)->sync();
896 
897  KateFactory::self()->schemaManager()->update ();
898 
899  // clear all attributes
900  for (int i = 0; i < KateHlManager::self()->highlights(); ++i)
901  KateHlManager::self()->getHl (i)->clearAttributeArrays ();
902 
903  // than reload the whole stuff
904  KateRendererConfig::global()->setSchema (defaultSchemaCombo->currentItem());
905  KateRendererConfig::global()->reloadSchema();
906 
907  // sync the hl config for real
908  KateHlManager::self()->getTDEConfig()->sync ();
909 }
910 
911 void KateSchemaConfigPage::reload()
912 {
913  // just reload the config from disc
914  KateFactory::self()->schemaManager()->update ();
915 
916  // special for the highlighting stuff
917  m_fontColorTab->reload ();
918 
919  update ();
920 
921  defaultSchemaCombo->setCurrentItem (KateRendererConfig::global()->schema());
922 
923  // initialize to the schema in the current document, or default schema
924  schemaCombo->setCurrentItem( m_defaultSchema );
925  schemaChanged( m_defaultSchema );
926 }
927 
928 void KateSchemaConfigPage::reset()
929 {
930  reload ();
931 }
932 
933 void KateSchemaConfigPage::defaults()
934 {
935  reload ();
936 }
937 
938 void KateSchemaConfigPage::update ()
939 {
940  // soft update, no load from disk
941  KateFactory::self()->schemaManager()->update (false);
942 
943  schemaCombo->clear ();
944  schemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
945 
946  defaultSchemaCombo->clear ();
947  defaultSchemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
948 
949  schemaCombo->setCurrentItem (0);
950  schemaChanged (0);
951 
952  schemaCombo->setEnabled (schemaCombo->count() > 0);
953 }
954 
955 void KateSchemaConfigPage::deleteSchema ()
956 {
957  int t = schemaCombo->currentItem ();
958 
959  KateFactory::self()->schemaManager()->removeSchema (t);
960 
961  update ();
962 }
963 
964 void KateSchemaConfigPage::newSchema ()
965 {
966  TQString t = KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:"), i18n("New Schema"), 0, this);
967 
968  KateFactory::self()->schemaManager()->addSchema (t);
969 
970  // soft update, no load from disk
971  KateFactory::self()->schemaManager()->update (false);
972  int i = KateFactory::self()->schemaManager()->list ().findIndex (t);
973 
974  update ();
975  if (i > -1)
976  {
977  schemaCombo->setCurrentItem (i);
978  schemaChanged (i);
979  }
980 }
981 
982 void KateSchemaConfigPage::schemaChanged (int schema)
983 {
984  btndel->setEnabled( schema > 1 );
985 
986  m_colorTab->schemaChanged( schema );
987  m_fontTab->schemaChanged( schema );
988  m_fontColorTab->schemaChanged (schema);
989  m_highlightTab->schemaChanged (schema);
990 
991  m_lastSchema = schema;
992 }
993 
994 void KateSchemaConfigPage::newCurrentPage (TQWidget *w)
995 {
996  if (w == m_highlightTab)
997  m_highlightTab->schemaChanged (m_lastSchema);
998 }
999 //END KateSchemaConfigPage
1000 
1001 //BEGIN SCHEMA ACTION -- the 'View->Schema' menu action
1002 void KateViewSchemaAction::init()
1003 {
1004  m_view = 0;
1005  last = 0;
1006 
1007  connect(popupMenu(),TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(slotAboutToShow()));
1008 }
1009 
1010 void KateViewSchemaAction::updateMenu (KateView *view)
1011 {
1012  m_view = view;
1013 }
1014 
1015 void KateViewSchemaAction::slotAboutToShow()
1016 {
1017  KateView *view=m_view;
1018  int count = KateFactory::self()->schemaManager()->list().count();
1019 
1020  for (int z=0; z<count; z++)
1021  {
1022  TQString hlName = KateFactory::self()->schemaManager()->list().operator[](z);
1023 
1024  if (names.contains(hlName) < 1)
1025  {
1026  names << hlName;
1027  popupMenu()->insertItem ( hlName, this, TQT_SLOT(setSchema(int)), 0, z+1);
1028  }
1029  }
1030 
1031  if (!view) return;
1032 
1033  popupMenu()->setItemChecked (last, false);
1034  popupMenu()->setItemChecked (view->renderer()->config()->schema()+1, true);
1035 
1036  last = view->renderer()->config()->schema()+1;
1037 }
1038 
1039 void KateViewSchemaAction::setSchema (int mode)
1040 {
1041  KateView *view=m_view;
1042 
1043  if (view)
1044  view->renderer()->config()->setSchema (mode-1);
1045 }
1046 //END SCHEMA ACTION
1047 
1048 //BEGIN KateStyleListView
1049 KateStyleListView::KateStyleListView( TQWidget *parent, bool showUseDefaults )
1050  : TQListView( parent )
1051 {
1052  setSorting( -1 ); // disable sorting, let the styles appear in their defined order
1053  addColumn( i18n("Context") );
1054  addColumn( SmallIconSet("format-text-bold"), TQString::null );
1055  addColumn( SmallIconSet("format-text-italic"), TQString::null );
1056  addColumn( SmallIconSet("format-text-underline"), TQString::null );
1057  addColumn( SmallIconSet("format-text-strikethrough"), TQString::null );
1058  addColumn( i18n("Normal") );
1059  addColumn( i18n("Selected") );
1060  addColumn( i18n("Background") );
1061  addColumn( i18n("Background Selected") );
1062  if ( showUseDefaults )
1063  addColumn( i18n("Use Default Style") );
1064  connect( this, TQT_SIGNAL(mouseButtonPressed(int, TQListViewItem*, const TQPoint&, int)),
1065  this, TQT_SLOT(slotMousePressed(int, TQListViewItem*, const TQPoint&, int)) );
1066  connect( this, TQT_SIGNAL(contextMenuRequested(TQListViewItem*,const TQPoint&, int)),
1067  this, TQT_SLOT(showPopupMenu(TQListViewItem*, const TQPoint&)) );
1068  // grap the bg color, selected color and default font
1069  normalcol = TDEGlobalSettings::textColor();
1070  bgcol = KateRendererConfig::global()->backgroundColor();
1071  selcol = KateRendererConfig::global()->selectionColor();
1072  docfont = *KateRendererConfig::global()->font();
1073 
1074  viewport()->setPaletteBackgroundColor( bgcol );
1075 }
1076 
1077 void KateStyleListView::showPopupMenu( KateStyleListItem *i, const TQPoint &globalPos, bool showtitle )
1078 {
1079  if ( !dynamic_cast<KateStyleListItem*>(i) ) return;
1080 
1081  TDEPopupMenu m( this );
1082  KateAttribute *is = i->style();
1083  int id;
1084  // the title is used, because the menu obscures the context name when
1085  // displayed on behalf of spacePressed().
1086  TQPixmap cl(16,16);
1087  cl.fill( i->style()->textColor() );
1088  TQPixmap scl(16,16);
1089  scl.fill( i->style()->selectedTextColor() );
1090  TQPixmap bgcl(16,16);
1091  bgcl.fill( i->style()->itemSet(KateAttribute::BGColor) ? i->style()->bgColor() : viewport()->colorGroup().base() );
1092  TQPixmap sbgcl(16,16);
1093  sbgcl.fill( i->style()->itemSet(KateAttribute::SelectedBGColor) ? i->style()->selectedBGColor() : viewport()->colorGroup().base() );
1094 
1095  if ( showtitle )
1096  m.insertTitle( i->contextName(), KateStyleListItem::ContextName );
1097  id = m.insertItem( i18n("&Bold"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Bold );
1098  m.setItemChecked( id, is->bold() );
1099  id = m.insertItem( i18n("&Italic"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Italic );
1100  m.setItemChecked( id, is->italic() );
1101  id = m.insertItem( i18n("&Underline"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Underline );
1102  m.setItemChecked( id, is->underline() );
1103  id = m.insertItem( i18n("S&trikeout"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Strikeout );
1104  m.setItemChecked( id, is->strikeOut() );
1105 
1106  m.insertSeparator();
1107 
1108  m.insertItem( TQIconSet(cl), i18n("Normal &Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Color );
1109  m.insertItem( TQIconSet(scl), i18n("&Selected Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelColor );
1110  m.insertItem( TQIconSet(bgcl), i18n("&Background Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::BgColor );
1111  m.insertItem( TQIconSet(sbgcl), i18n("S&elected Background Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelBgColor );
1112 
1113  // Unset [some] colors. I could show one only if that button was clicked, but that
1114  // would disable setting this with the keyboard (how many aren't doing just
1115  // that every day? ;)
1116  // ANY ideas for doing this in a nicer way will be warmly wellcomed.
1117  KateAttribute *style = i->style();
1118  if ( style->itemSet( KateAttribute::BGColor) || style->itemSet( KateAttribute::SelectedBGColor ) )
1119  {
1120  m.insertSeparator();
1121  if ( style->itemSet( KateAttribute::BGColor) )
1122  m.insertItem( i18n("Unset Background Color"), this, TQT_SLOT(unsetColor(int)), 0, 100 );
1123  if ( style->itemSet( KateAttribute::SelectedBGColor ) )
1124  m.insertItem( i18n("Unset Selected Background Color"), this, TQT_SLOT(unsetColor(int)), 0, 101 );
1125  }
1126 
1127  if ( ! i->isDefault() && ! i->defStyle() ) {
1128  m.insertSeparator();
1129  id = m.insertItem( i18n("Use &Default Style"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::UseDefStyle );
1130  m.setItemChecked( id, i->defStyle() );
1131  }
1132  m.exec( globalPos );
1133 }
1134 
1135 void KateStyleListView::showPopupMenu( TQListViewItem *i, const TQPoint &pos )
1136 {
1137  if ( dynamic_cast<KateStyleListItem*>(i) )
1138  showPopupMenu( (KateStyleListItem*)i, pos, true );
1139 }
1140 
1141 void KateStyleListView::mSlotPopupHandler( int z )
1142 {
1143  ((KateStyleListItem*)currentItem())->changeProperty( (KateStyleListItem::Property)z );
1144 }
1145 
1146 void KateStyleListView::unsetColor( int c )
1147 {
1148  ((KateStyleListItem*)currentItem())->unsetColor( c );
1149  emitChanged();
1150 }
1151 
1152 // Because TQListViewItem::activatePos() is going to become deprecated,
1153 // and also because this attempt offers more control, I connect mousePressed to this.
1154 void KateStyleListView::slotMousePressed(int btn, TQListViewItem* i, const TQPoint& pos, int c)
1155 {
1156  if ( dynamic_cast<KateStyleListItem*>(i) ) {
1157  if ( btn == Qt::LeftButton && c > 0 ) {
1158  // map pos to item/column and call KateStyleListItem::activate(col, pos)
1159  ((KateStyleListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - TQPoint( 0, itemRect(i).top() ) );
1160  }
1161  }
1162 }
1163 
1164 //END
1165 
1166 //BEGIN KateStyleListItem
1167 static const int BoxSize = 16;
1168 static const int ColorBtnWidth = 32;
1169 
1170 KateStyleListItem::KateStyleListItem( TQListViewItem *parent, const TQString & stylename,
1171  KateAttribute *style, KateHlItemData *data )
1172  : TQListViewItem( parent, stylename ),
1173  ds( style ),
1174  st( data )
1175 {
1176  initStyle();
1177 }
1178 
1179 KateStyleListItem::KateStyleListItem( TQListView *parent, const TQString & stylename,
1180  KateAttribute *style, KateHlItemData *data )
1181  : TQListViewItem( parent, stylename ),
1182  ds( style ),
1183  st( data )
1184 {
1185  initStyle();
1186 }
1187 
1188 void KateStyleListItem::initStyle()
1189 {
1190  if (!st)
1191  is = ds;
1192  else
1193  {
1194  is = new KateAttribute (*ds);
1195 
1196  if (st->isSomethingSet())
1197  *is += *st;
1198  }
1199 }
1200 
1201 void KateStyleListItem::updateStyle()
1202 {
1203  // nothing there, not update it, will crash
1204  if (!st)
1205  return;
1206 
1207  if ( is->itemSet(KateAttribute::Weight) )
1208  {
1209  if ( is->weight() != st->weight())
1210  st->setWeight( is->weight() );
1211  }
1212  else st->clearAttribute( KateAttribute::Weight );
1213 
1214  if ( is->itemSet(KateAttribute::Italic) )
1215  {
1216  if ( is->italic() != st->italic())
1217  st->setItalic( is->italic() );
1218  }
1219  else st->clearAttribute( KateAttribute::Italic );
1220 
1221  if ( is->itemSet(KateAttribute::StrikeOut) )
1222  {
1223  if ( is->strikeOut() != st->strikeOut())
1224 
1225  st->setStrikeOut( is->strikeOut() );
1226  }
1227  else st->clearAttribute( KateAttribute::StrikeOut );
1228 
1229  if ( is->itemSet(KateAttribute::Underline) )
1230  {
1231  if ( is->underline() != st->underline())
1232  st->setUnderline( is->underline() );
1233  }
1234  else st->clearAttribute( KateAttribute::Underline );
1235 
1236  if ( is->itemSet(KateAttribute::Outline) )
1237  {
1238  if ( is->outline() != st->outline())
1239  st->setOutline( is->outline() );
1240  }
1241  else st->clearAttribute( KateAttribute::Outline );
1242 
1243  if ( is->itemSet(KateAttribute::TextColor) )
1244  {
1245  if ( is->textColor() != st->textColor())
1246  st->setTextColor( is->textColor() );
1247  }
1248  else st->clearAttribute( KateAttribute::TextColor );
1249 
1250  if ( is->itemSet(KateAttribute::SelectedTextColor) )
1251  {
1252  if ( is->selectedTextColor() != st->selectedTextColor())
1253  st->setSelectedTextColor( is->selectedTextColor() );
1254  }
1255  else st->clearAttribute( KateAttribute::SelectedTextColor);
1256 
1257  if ( is->itemSet(KateAttribute::BGColor) )
1258  {
1259  if ( is->bgColor() != st->bgColor())
1260  st->setBGColor( is->bgColor() );
1261  }
1262  else st->clearAttribute( KateAttribute::BGColor );
1263 
1264  if ( is->itemSet(KateAttribute::SelectedBGColor) )
1265  {
1266  if ( is->selectedBGColor() != st->selectedBGColor())
1267  st->setSelectedBGColor( is->selectedBGColor() );
1268  }
1269  else st->clearAttribute( KateAttribute::SelectedBGColor );
1270 }
1271 
1272 /* only true for a hl mode item using it's default style */
1273 bool KateStyleListItem::defStyle() { return st && st->itemsSet() != ds->itemsSet(); }
1274 
1275 /* true for default styles */
1276 bool KateStyleListItem::isDefault() { return st ? false : true; }
1277 
1278 int KateStyleListItem::width( const TQFontMetrics & /*fm*/, const TQListView * lv, int col ) const
1279 {
1280  int m = lv->itemMargin() * 2;
1281  switch ( col ) {
1282  case ContextName:
1283  // FIXME: width for name column should reflect bold/italic
1284  // (relevant for non-fixed fonts only - nessecary?)
1285  return TQListViewItem::width( TQFontMetrics( ((KateStyleListView*)lv)->docfont), lv, col);
1286  case Bold:
1287  case Italic:
1288  case UseDefStyle:
1289  return BoxSize + m;
1290  case Color:
1291  case SelColor:
1292  case BgColor:
1293  case SelBgColor:
1294  return ColorBtnWidth +m;
1295  default:
1296  return 0;
1297  }
1298 }
1299 
1300 void KateStyleListItem::activate( int column, const TQPoint &localPos )
1301 {
1302  TQListView *lv = listView();
1303  int x = 0;
1304  for( int c = 0; c < column-1; c++ )
1305  x += lv->columnWidth( c );
1306  int w;
1307  switch( column ) {
1308  case Bold:
1309  case Italic:
1310  case Underline:
1311  case Strikeout:
1312  case UseDefStyle:
1313  w = BoxSize;
1314  break;
1315  case Color:
1316  case SelColor:
1317  case BgColor:
1318  case SelBgColor:
1319  w = ColorBtnWidth;
1320  break;
1321  default:
1322  return;
1323  }
1324  if ( !TQRect( x, 0, w, BoxSize ).contains( localPos ) )
1325  changeProperty( (Property)column );
1326 }
1327 
1328 void KateStyleListItem::changeProperty( Property p )
1329 {
1330  if ( p == Bold )
1331  is->setBold( ! is->bold() );
1332  else if ( p == Italic )
1333  is->setItalic( ! is->italic() );
1334  else if ( p == Underline )
1335  is->setUnderline( ! is->underline() );
1336  else if ( p == Strikeout )
1337  is->setStrikeOut( ! is->strikeOut() );
1338  else if ( p == UseDefStyle )
1339  toggleDefStyle();
1340  else
1341  setColor( p );
1342 
1343  updateStyle ();
1344 
1345  ((KateStyleListView*)listView())->emitChanged();
1346 }
1347 
1348 void KateStyleListItem::toggleDefStyle()
1349 {
1350  if ( *is == *ds ) {
1351  KMessageBox::information( listView(),
1352  i18n("\"Use Default Style\" will be automatically unset when you change any style properties."),
1353  i18n("Kate Styles"),
1354  "Kate hl config use defaults" );
1355  }
1356  else {
1357  delete is;
1358  is = new KateAttribute( *ds );
1359  updateStyle();
1360  repaint();
1361  }
1362 }
1363 
1364 void KateStyleListItem::setColor( int column )
1365 {
1366  TQColor c; // use this
1367  TQColor d; // default color
1368  if ( column == Color)
1369  {
1370  c = is->textColor();
1371  d = ds->textColor();
1372  }
1373  else if ( column == SelColor )
1374  {
1375  c = is->selectedTextColor();
1376  d = is->selectedTextColor();
1377  }
1378  else if ( column == BgColor )
1379  {
1380  c = is->bgColor();
1381  d = ds->bgColor();
1382  }
1383  else if ( column == SelBgColor )
1384  {
1385  c = is->selectedBGColor();
1386  d = ds->selectedBGColor();
1387  }
1388 
1389  if ( KColorDialog::getColor( c, d, listView() ) != TQDialog::Accepted) return;
1390 
1391  bool def = ! c.isValid();
1392 
1393  // if set default, and the attrib is set in the default style use it
1394  // else if set default, unset it
1395  // else set the selected color
1396  switch (column)
1397  {
1398  case Color:
1399  if ( def )
1400  {
1401  if ( ds->itemSet(KateAttribute::TextColor) )
1402  is->setTextColor( ds->textColor());
1403  else
1404  is->clearAttribute(KateAttribute::TextColor);
1405  }
1406  else
1407  is->setTextColor( c );
1408  break;
1409  case SelColor:
1410  if ( def )
1411  {
1412  if ( ds->itemSet(KateAttribute::SelectedTextColor) )
1413  is->setSelectedTextColor( ds->selectedTextColor());
1414  else
1415  is->clearAttribute(KateAttribute::SelectedTextColor);
1416  }
1417  else
1418  is->setSelectedTextColor( c );
1419  break;
1420  case BgColor:
1421  if ( def )
1422  {
1423  if ( ds->itemSet(KateAttribute::BGColor) )
1424  is->setBGColor( ds->bgColor());
1425  else
1426  is->clearAttribute(KateAttribute::BGColor);
1427  }
1428  else
1429  is->setBGColor( c );
1430  break;
1431  case SelBgColor:
1432  if ( def )
1433  {
1434  if ( ds->itemSet(KateAttribute::SelectedBGColor) )
1435  is->setSelectedBGColor( ds->selectedBGColor());
1436  else
1437  is->clearAttribute(KateAttribute::SelectedBGColor);
1438  }
1439  else
1440  is->setSelectedBGColor( c );
1441  break;
1442  }
1443 
1444  repaint();
1445 }
1446 
1447 void KateStyleListItem::unsetColor( int c )
1448 {
1449  if ( c == 100 && is->itemSet(KateAttribute::BGColor) )
1450  is->clearAttribute(KateAttribute::BGColor);
1451  else if ( c == 101 && is->itemSet(KateAttribute::SelectedBGColor) )
1452  is->clearAttribute(KateAttribute::SelectedBGColor);
1453  updateStyle();
1454 }
1455 
1456 void KateStyleListItem::paintCell( TQPainter *p, const TQColorGroup& /*cg*/, int col, int width, int align )
1457 {
1458 
1459  if ( !p )
1460  return;
1461 
1462  TQListView *lv = listView();
1463  if ( !lv )
1464  return;
1465  Q_ASSERT( lv ); //###
1466 
1467  // use a private color group and set the text/highlighted text colors
1468  TQColorGroup mcg = lv->viewport()->colorGroup();
1469 
1470  if ( col ) // col 0 is drawn by the superclass method
1471  p->fillRect( 0, 0, width, height(), TQBrush( mcg.base() ) );
1472 
1473  int marg = lv->itemMargin();
1474 
1475  TQColor c;
1476 
1477  switch ( col )
1478  {
1479  case ContextName:
1480  {
1481  mcg.setColor(TQColorGroup::Text, is->textColor());
1482  mcg.setColor(TQColorGroup::HighlightedText, is->selectedTextColor());
1483  // text background color
1484  c = is->bgColor();
1485  if ( c.isValid() && is->itemSet(KateAttribute::BGColor) )
1486  mcg.setColor( TQColorGroup::Base, c );
1487  if ( isSelected() && is->itemSet(KateAttribute::SelectedBGColor) )
1488  {
1489  c = is->selectedBGColor();
1490  if ( c.isValid() )
1491  mcg.setColor( TQColorGroup::Highlight, c );
1492  }
1493  TQFont f ( ((KateStyleListView*)lv)->docfont );
1494  p->setFont( is->font(f) );
1495  // FIXME - repainting when text is cropped, and the column is enlarged is buggy.
1496  // Maybe I need painting the string myself :(
1497  // (wilbert) it depends on the font used
1498  TQListViewItem::paintCell( p, mcg, col, width, align );
1499  }
1500  break;
1501  case Bold:
1502  case Italic:
1503  case Underline:
1504  case Strikeout:
1505  case UseDefStyle:
1506  {
1507  // Bold/Italic/use default checkboxes
1508  // code allmost identical to QCheckListItem
1509  int x = 0;
1510  int y = (height() - BoxSize) / 2;
1511 
1512  if ( isEnabled() )
1513  p->setPen( TQPen( mcg.text(), 2 ) );
1514  else
1515  p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
1516 
1517  p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
1518  x++;
1519  y++;
1520  if ( (col == Bold && is->bold()) ||
1521  (col == Italic && is->italic()) ||
1522  (col == Underline && is->underline()) ||
1523  (col == Strikeout && is->strikeOut()) ||
1524  (col == UseDefStyle && *is == *ds ) )
1525  {
1526  TQPointArray a( 7*2 );
1527  int i, xx, yy;
1528  xx = x+1+marg;
1529  yy = y+5;
1530  for ( i=0; i<3; i++ ) {
1531  a.setPoint( 2*i, xx, yy );
1532  a.setPoint( 2*i+1, xx, yy+2 );
1533  xx++; yy++;
1534  }
1535  yy -= 2;
1536  for ( i=3; i<7; i++ ) {
1537  a.setPoint( 2*i, xx, yy );
1538  a.setPoint( 2*i+1, xx, yy+2 );
1539  xx++; yy--;
1540  }
1541  p->drawLineSegments( a );
1542  }
1543  }
1544  break;
1545  case Color:
1546  case SelColor:
1547  case BgColor:
1548  case SelBgColor:
1549  {
1550  bool set( false );
1551  if ( col == Color)
1552  {
1553  c = is->textColor();
1554  set = is->itemSet(KateAttribute::TextColor);
1555  }
1556  else if ( col == SelColor )
1557  {
1558  c = is->selectedTextColor();
1559  set = is->itemSet( KateAttribute::SelectedTextColor);
1560  }
1561  else if ( col == BgColor )
1562  {
1563  set = is->itemSet(KateAttribute::BGColor);
1564  c = set ? is->bgColor() : mcg.base();
1565  }
1566  else if ( col == SelBgColor )
1567  {
1568  set = is->itemSet(KateAttribute::SelectedBGColor);
1569  c = set ? is->selectedBGColor(): mcg.base();
1570  }
1571 
1572  // color "buttons"
1573  int x = 0;
1574  int y = (height() - BoxSize) / 2;
1575  if ( isEnabled() )
1576  p->setPen( TQPen( mcg.text(), 2 ) );
1577  else
1578  p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
1579 
1580  p->drawRect( x+marg, y+2, ColorBtnWidth-4, BoxSize-4 );
1581  p->fillRect( x+marg+1,y+3,ColorBtnWidth-7,BoxSize-7,TQBrush( c ) );
1582  // if this item is unset, draw a diagonal line over the button
1583  if ( ! set )
1584  p->drawLine( x+marg-1, BoxSize-3, ColorBtnWidth-4, y+1 );
1585  }
1586  //case default: // no warning...
1587  }
1588 }
1589 //END
1590 
1591 //BEGIN KateStyleListCaption
1592 KateStyleListCaption::KateStyleListCaption( TQListView *parent, const TQString & name )
1593  : TQListViewItem( parent, name )
1594 {
1595 }
1596 
1597 void KateStyleListCaption::paintCell( TQPainter *p, const TQColorGroup& /*cg*/, int col, int width, int align )
1598 {
1599  TQListView *lv = listView();
1600  if ( !lv )
1601  return;
1602  Q_ASSERT( lv ); //###
1603 
1604  // use the same colorgroup as the other items in the viewport
1605  TQColorGroup mcg = lv->viewport()->colorGroup();
1606 
1607  TQListViewItem::paintCell( p, mcg, col, width, align );
1608 }
1609 //END
TDEConfig
KateAttribute
The Attribute class incorporates all text decorations supported by Kate.
Definition: kateattribute.h:32
TDEGlobalSettings::baseColor
static TQColor baseColor()
TDEFontChooser
KColorDialog::getColor
static int getColor(TQColor &theColor, TQWidget *parent=0L)
kdDebug
kdbgstream kdDebug(int area=0)
TDEGlobalSettings::highlightColor
static TQColor highlightColor()
tdelocale.h
KInputDialog::getText
static TQString getText(const TQString &caption, const TQString &label, const TQString &value=TQString::null, bool *ok=0, TQWidget *parent=0, const char *name=0, TQValidator *validator=0, const TQString &mask=TQString::null)
TDEGlobalSettings::textColor
static TQColor textColor()
KMessageBox::information
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
TDEStdAccel::find
const TDEShortcut & find()
KColorButton
KComboBox
TDEPopupMenu
TDEGlobalSettings::fixedFont
static TQFont fixedFont()
endl
kndbgstream & endl(kndbgstream &s)
TDEStdAccel::label
TQString label(StdAccel id)
TDEStdAccel::reload
const TDEShortcut & reload()
TDEGlobalSettings::alternateBackgroundColor
static TQColor alternateBackgroundColor()

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.8.8
This website is maintained by Timothy Pearson.