• 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*/
83class 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*/
144class 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
156TQString KateSchemaManager::normalSchema ()
157{
158 return tdeApp->aboutData()->appName () + TQString (" - Normal");
159}
160
161TQString KateSchemaManager::printingSchema ()
162{
163 return tdeApp->aboutData()->appName () + TQString (" - Printing");
164}
165
166KateSchemaManager::KateSchemaManager ()
167 : m_config ("kateschemarc", false, false)
168{
169 update ();
170}
171
172KateSchemaManager::~KateSchemaManager ()
173{
174}
175
176//
177// read the types from config file and update the internal list
178//
179void 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//
197TDEConfig *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
209void 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
217void 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
230bool KateSchemaManager::validSchema (uint number)
231{
232 if (number < m_schemas.count())
233 return true;
234
235 return false;
236}
237
238uint 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
253TQString 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
269KateSchemaConfigColorTab::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, TQ_SIGNAL( activated( int ) ), TQ_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, TQ_SIGNAL( changed() ), parent->parentWidget(), TQ_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
383KateSchemaConfigColorTab::~KateSchemaConfigColorTab()
384{
385}
386
387void 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( TQ_SIGNAL( changed( const TQColor & ) ) );
409 m_selected ->disconnect( TQ_SIGNAL( changed( const TQColor & ) ) );
410 m_current ->disconnect( TQ_SIGNAL( changed( const TQColor & ) ) );
411 m_bracket ->disconnect( TQ_SIGNAL( changed( const TQColor & ) ) );
412 m_wwmarker ->disconnect( TQ_SIGNAL( changed( const TQColor & ) ) );
413 m_iconborder->disconnect( TQ_SIGNAL( changed( const TQColor & ) ) );
414 m_tmarker ->disconnect( TQ_SIGNAL( changed( const TQColor & ) ) );
415 m_markers ->disconnect( TQ_SIGNAL( changed( const TQColor & ) ) );
416 m_linenumber->disconnect( TQ_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] = TQt::blue;
435 mark[1] = TQt::red;
436 mark[2] = TQt::yellow;
437 mark[3] = TQt::magenta;
438 mark[4] = TQt::gray;
439 mark[5] = TQt::green;
440 mark[6] = TQt::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 , TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
479 connect( m_selected , TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
480 connect( m_current , TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
481 connect( m_bracket , TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
482 connect( m_wwmarker , TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
483 connect( m_iconborder, TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
484 connect( m_tmarker , TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
485 connect( m_linenumber, TQ_SIGNAL( changed( const TQColor& ) ), TQ_SIGNAL( changed() ) );
486 connect( m_markers , TQ_SIGNAL( changed( const TQColor& ) ), TQ_SLOT( slotMarkerColorChanged( const TQColor& ) ) );
487}
488
489void 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
516void 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
527void KateSchemaConfigColorTab::slotComboBoxChanged(int index)
528{
529 // temporarily disconnect the changed-signal because setColor emits changed as well
530 m_markers->disconnect( TQ_SIGNAL( changed( const TQColor& ) ) );
531 m_markers->setColor( m_schemas[m_schema].markerColors[index] );
532 connect( m_markers, TQ_SIGNAL( changed( const TQColor& ) ), TQ_SLOT( slotMarkerColorChanged( const TQColor& ) ) );
533}
534
535//END KateSchemaConfigColorTab
536
537//BEGIN FontConfig -- 'Fonts' tab
538KateSchemaConfigFontTab::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 grid->addWidget( m_fontchooser, 0, 0);
546
547 connect (this, TQ_SIGNAL( changed()), parent->parentWidget(), TQ_SLOT (slotChanged()));
548 m_schema = -1;
549}
550
551KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
552{
553}
554
555void KateSchemaConfigFontTab::slotFontSelected( const TQFont &font )
556{
557 if ( m_schema > -1 )
558 {
559 m_fonts[m_schema] = font;
560 emit changed();
561 }
562}
563
564void KateSchemaConfigFontTab::apply()
565{
566 FontMap::Iterator it;
567 for ( it = m_fonts.begin(); it != m_fonts.end(); ++it )
568 {
569 KateFactory::self()->schemaManager()->schema( it.key() )->writeEntry( "Font", it.data() );
570 }
571}
572
573void KateSchemaConfigFontTab::schemaChanged( int newSchema )
574{
575 if ( m_schema > -1 )
576 m_fonts[ m_schema ] = m_fontchooser->font();
577
578 m_schema = newSchema;
579
580 TQFont f (TDEGlobalSettings::fixedFont());
581
582 m_fontchooser->disconnect ( this );
583 m_fontchooser->setFont ( KateFactory::self()->schemaManager()->schema( newSchema )->readFontEntry("Font", &f) );
584 m_fonts[ newSchema ] = m_fontchooser->font();
585 connect (m_fontchooser, TQ_SIGNAL (fontSelected( const TQFont & )), this, TQ_SLOT (slotFontSelected( const TQFont & )));
586}
587//END FontConfig
588
589//BEGIN FontColorConfig -- 'Normal Text Styles' tab
590KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab( TQWidget *parent, const char * )
591 : TQWidget (parent)
592{
593 m_defaultStyleLists.setAutoDelete(true);
594
595 // sizemanagment
596 TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
597
598 m_defaultStyles = new KateStyleListView( this, false );
599 grid->addWidget( m_defaultStyles, 0, 0);
600
601 connect (m_defaultStyles, TQ_SIGNAL (changed()), parent->parentWidget(), TQ_SLOT (slotChanged()));
602
603 TQWhatsThis::add( m_defaultStyles, i18n(
604 "This list displays the default styles for the current schema and "
605 "offers the means to edit them. The style name reflects the current "
606 "style settings."
607 "<p>To edit the colors, click the colored squares, or select the color "
608 "to edit from the popup menu.<p>You can unset the Background and Selected "
609 "Background colors from the popup menu when appropriate.") );
610}
611
612KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab()
613{
614}
615
616KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema)
617{
618 if (!m_defaultStyleLists[schema])
619 {
620 KateAttributeList *list = new KateAttributeList ();
621 KateHlManager::self()->getDefaults(schema, *list);
622
623 m_defaultStyleLists.insert (schema, list);
624 }
625
626 return m_defaultStyleLists[schema];
627}
628
629void KateSchemaConfigFontColorTab::schemaChanged (uint schema)
630{
631 m_defaultStyles->clear ();
632
633 KateAttributeList *l = attributeList (schema);
634
635 // set colors
636 TQPalette p ( m_defaultStyles->palette() );
637 TQColor _c ( TDEGlobalSettings::baseColor() );
638 p.setColor( TQColorGroup::Base,
639 KateFactory::self()->schemaManager()->schema(schema)->
640 readColorEntry( "Color Background", &_c ) );
641 _c = TDEGlobalSettings::highlightColor();
642 p.setColor( TQColorGroup::Highlight,
643 KateFactory::self()->schemaManager()->schema(schema)->
644 readColorEntry( "Color Selection", &_c ) );
645 _c = l->at(0)->textColor(); // not quite as much of an assumption ;)
646 p.setColor( TQColorGroup::Text, _c );
647 m_defaultStyles->viewport()->setPalette( p );
648
649 // insert the default styles backwards to get them in the right order
650 for ( int i = KateHlManager::self()->defaultStyles() - 1; i >= 0; i-- )
651 {
652 new KateStyleListItem( m_defaultStyles, KateHlManager::self()->defaultStyleName(i, true), l->at( i ) );
653 }
654}
655
656void KateSchemaConfigFontColorTab::reload ()
657{
658 m_defaultStyles->clear ();
659 m_defaultStyleLists.clear ();
660}
661
662void KateSchemaConfigFontColorTab::apply ()
663{
664 for ( TQIntDictIterator<KateAttributeList> it( m_defaultStyleLists ); it.current(); ++it )
665 KateHlManager::self()->setDefaults(it.currentKey(), *(it.current()));
666}
667
668//END FontColorConfig
669
670//BEGIN KateSchemaConfigHighlightTab -- 'Highlighting Text Styles' tab
671KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab( TQWidget *parent, const char *, KateSchemaConfigFontColorTab *page, uint hl )
672 : TQWidget (parent)
673{
674 m_defaults = page;
675
676 m_schema = 0;
677 m_hl = 0;
678
679 m_hlDict.setAutoDelete (true);
680
681 TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
682
683 // hl chooser
684 TQHBox *hbHl = new TQHBox( this );
685 layout->add (hbHl);
686
687 hbHl->setSpacing( KDialog::spacingHint() );
688 TQLabel *lHl = new TQLabel( i18n("H&ighlight:"), hbHl );
689 hlCombo = new TQComboBox( false, hbHl );
690 lHl->setBuddy( hlCombo );
691 connect( hlCombo, TQ_SIGNAL(activated(int)),
692 this, TQ_SLOT(hlChanged(int)) );
693
694 for( int i = 0; i < KateHlManager::self()->highlights(); i++) {
695 if (KateHlManager::self()->hlSection(i).length() > 0)
696 hlCombo->insertItem(KateHlManager::self()->hlSection(i) + TQString ("/") + KateHlManager::self()->hlNameTranslated(i));
697 else
698 hlCombo->insertItem(KateHlManager::self()->hlNameTranslated(i));
699 }
700 hlCombo->setCurrentItem(0);
701
702 // styles listview
703 m_styles = new KateStyleListView( this, true );
704 layout->addWidget (m_styles, 999);
705
706 hlCombo->setCurrentItem ( hl );
707 hlChanged ( hl );
708
709 TQWhatsThis::add( m_styles, i18n(
710 "This list displays the contexts of the current syntax highlight mode and "
711 "offers the means to edit them. The context name reflects the current "
712 "style settings.<p>To edit using the keyboard, press "
713 "<strong>&lt;SPACE&gt;</strong> and choose a property from the popup menu."
714 "<p>To edit the colors, click the colored squares, or select the color "
715 "to edit from the popup menu.<p>You can unset the Background and Selected "
716 "Background colors from the context menu when appropriate.") );
717
718 connect (m_styles, TQ_SIGNAL (changed()), parent->parentWidget(), TQ_SLOT (slotChanged()));
719}
720
721KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
722{
723}
724
725void KateSchemaConfigHighlightTab::hlChanged(int z)
726{
727 m_hl = z;
728
729 schemaChanged (m_schema);
730}
731
732void KateSchemaConfigHighlightTab::schemaChanged (uint schema)
733{
734 m_schema = schema;
735
736 kdDebug(13030) << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl << endl;
737
738 m_styles->clear ();
739
740 if (!m_hlDict[m_schema])
741 {
742 kdDebug(13030) << "NEW SCHEMA, create dict" << endl;
743
744 m_hlDict.insert (schema, new TQIntDict<KateHlItemDataList>);
745 m_hlDict[m_schema]->setAutoDelete (true);
746 }
747
748 if (!m_hlDict[m_schema]->find(m_hl))
749 {
750 kdDebug(13030) << "NEW HL, create list" << endl;
751
752 KateHlItemDataList *list = new KateHlItemDataList ();
753 KateHlManager::self()->getHl( m_hl )->getKateHlItemDataListCopy (m_schema, *list);
754 m_hlDict[m_schema]->insert (m_hl, list);
755 }
756
757 KateAttributeList *l = m_defaults->attributeList (schema);
758
759 // Set listview colors
760 // We do that now, because we can now get the "normal text" color.
761 // TODO this reads of the TDEConfig object, which should be changed when
762 // the color tab is fixed.
763 TQPalette p ( m_styles->palette() );
764 TQColor _c ( TDEGlobalSettings::baseColor() );
765 p.setColor( TQColorGroup::Base,
766 KateFactory::self()->schemaManager()->schema(m_schema)->
767 readColorEntry( "Color Background", &_c ) );
768 _c = TDEGlobalSettings::highlightColor();
769 p.setColor( TQColorGroup::Highlight,
770 KateFactory::self()->schemaManager()->schema(m_schema)->
771 readColorEntry( "Color Selection", &_c ) );
772 _c = l->at(0)->textColor(); // not quite as much of an assumption ;)
773 p.setColor( TQColorGroup::Text, _c );
774 m_styles->viewport()->setPalette( p );
775
776 TQDict<KateStyleListCaption> prefixes;
777 for ( KateHlItemData *itemData = m_hlDict[m_schema]->find(m_hl)->last();
778 itemData != 0L;
779 itemData = m_hlDict[m_schema]->find(m_hl)->prev())
780 {
781 kdDebug(13030) << "insert items " << itemData->name << endl;
782
783 // All stylenames have their language mode prefixed, e.g. HTML:Comment
784 // split them and put them into nice substructures.
785 int c = itemData->name.find(':');
786 if ( c > 0 ) {
787 TQString prefix = itemData->name.left(c);
788 TQString name = itemData->name.mid(c+1);
789
790 KateStyleListCaption *parent = prefixes.find( prefix );
791 if ( ! parent )
792 {
793 parent = new KateStyleListCaption( m_styles, prefix );
794 parent->setOpen(true);
795 prefixes.insert( prefix, parent );
796 }
797 new KateStyleListItem( parent, name, l->at(itemData->defStyleNum), itemData );
798 } else {
799 new KateStyleListItem( m_styles, itemData->name, l->at(itemData->defStyleNum), itemData );
800 }
801 }
802}
803
804void KateSchemaConfigHighlightTab::reload ()
805{
806 m_styles->clear ();
807 m_hlDict.clear ();
808
809 hlChanged (0);
810}
811
812void KateSchemaConfigHighlightTab::apply ()
813{
814 for ( TQIntDictIterator< TQIntDict<KateHlItemDataList> > it( m_hlDict ); it.current(); ++it )
815 for ( TQIntDictIterator< KateHlItemDataList > it2( *it.current() ); it2.current(); ++it2 )
816 {
817 KateHlManager::self()->getHl( it2.currentKey() )->setKateHlItemDataList (it.currentKey(), *(it2.current()));
818 }
819}
820
821//END KateSchemaConfigHighlightTab
822
823//BEGIN KateSchemaConfigPage -- Main dialog page
824KateSchemaConfigPage::KateSchemaConfigPage( TQWidget *parent, KateDocument *doc )
825 : KateConfigPage( parent ),
826 m_lastSchema (-1)
827{
828 TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
829
830 TQHBox *hbHl = new TQHBox( this );
831 layout->add (hbHl);
832 hbHl->setSpacing( KDialog::spacingHint() );
833 TQLabel *lHl = new TQLabel( i18n("&Schema:"), hbHl );
834 schemaCombo = new TQComboBox( false, hbHl );
835 lHl->setBuddy( schemaCombo );
836 connect( schemaCombo, TQ_SIGNAL(activated(int)),
837 this, TQ_SLOT(schemaChanged(int)) );
838
839 TQPushButton *btnnew = new TQPushButton( i18n("&New..."), hbHl );
840 connect( btnnew, TQ_SIGNAL(clicked()), this, TQ_SLOT(newSchema()) );
841
842 btndel = new TQPushButton( i18n("&Delete"), hbHl );
843 connect( btndel, TQ_SIGNAL(clicked()), this, TQ_SLOT(deleteSchema()) );
844
845 m_tabWidget = new TQTabWidget ( this );
846 m_tabWidget->setMargin (KDialog::marginHint());
847 layout->add (m_tabWidget);
848
849 connect (m_tabWidget, TQ_SIGNAL (currentChanged (TQWidget *)), this, TQ_SLOT (newCurrentPage (TQWidget *)));
850
851 m_colorTab = new KateSchemaConfigColorTab (m_tabWidget);
852 m_tabWidget->addTab (m_colorTab, i18n("Colors"));
853
854 m_fontTab = new KateSchemaConfigFontTab (m_tabWidget);
855 m_tabWidget->addTab (m_fontTab, i18n("Font"));
856
857 m_fontColorTab = new KateSchemaConfigFontColorTab (m_tabWidget);
858 m_tabWidget->addTab (m_fontColorTab, i18n("Normal Text Styles"));
859
860 uint hl = doc ? doc->hlMode() : 0;
861 m_highlightTab = new KateSchemaConfigHighlightTab (m_tabWidget, "", m_fontColorTab, hl );
862 m_tabWidget->addTab (m_highlightTab, i18n("Highlighting Text Styles"));
863
864 hbHl = new TQHBox( this );
865 layout->add (hbHl);
866 hbHl->setSpacing( KDialog::spacingHint() );
867 lHl = new TQLabel( i18n("&Default schema for %1:").arg(tdeApp->aboutData()->programName ()), hbHl );
868 defaultSchemaCombo = new TQComboBox( false, hbHl );
869 lHl->setBuddy( defaultSchemaCombo );
870
871
872 m_defaultSchema = (doc && doc->activeView()) ? doc->activeView()->renderer()->config()->schema() : KateRendererConfig::global()->schema();
873
874 reload();
875
876 connect( defaultSchemaCombo, TQ_SIGNAL(activated(int)),
877 this, TQ_SLOT(slotChanged()) );
878}
879
880KateSchemaConfigPage::~KateSchemaConfigPage ()
881{
882 // just reload config from disc
883 KateFactory::self()->schemaManager()->update ();
884}
885
886void KateSchemaConfigPage::apply()
887{
888 m_colorTab->apply();
889 m_fontTab->apply();
890 m_fontColorTab->apply ();
891 m_highlightTab->apply ();
892
893 // just sync the config
894 KateFactory::self()->schemaManager()->schema (0)->sync();
895
896 KateFactory::self()->schemaManager()->update ();
897
898 // clear all attributes
899 for (int i = 0; i < KateHlManager::self()->highlights(); ++i)
900 KateHlManager::self()->getHl (i)->clearAttributeArrays ();
901
902 // than reload the whole stuff
903 KateRendererConfig::global()->setSchema (defaultSchemaCombo->currentItem());
904 KateRendererConfig::global()->reloadSchema();
905
906 // sync the hl config for real
907 KateHlManager::self()->getTDEConfig()->sync ();
908}
909
910void KateSchemaConfigPage::reload()
911{
912 // just reload the config from disc
913 KateFactory::self()->schemaManager()->update ();
914
915 // special for the highlighting stuff
916 m_fontColorTab->reload ();
917
918 update ();
919
920 defaultSchemaCombo->setCurrentItem (KateRendererConfig::global()->schema());
921
922 // initialize to the schema in the current document, or default schema
923 schemaCombo->setCurrentItem( m_defaultSchema );
924 schemaChanged( m_defaultSchema );
925}
926
927void KateSchemaConfigPage::reset()
928{
929 reload ();
930}
931
932void KateSchemaConfigPage::defaults()
933{
934 reload ();
935}
936
937void KateSchemaConfigPage::update ()
938{
939 // soft update, no load from disk
940 KateFactory::self()->schemaManager()->update (false);
941
942 schemaCombo->clear ();
943 schemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
944
945 defaultSchemaCombo->clear ();
946 defaultSchemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
947
948 schemaCombo->setCurrentItem (0);
949 schemaChanged (0);
950
951 schemaCombo->setEnabled (schemaCombo->count() > 0);
952}
953
954void KateSchemaConfigPage::deleteSchema ()
955{
956 int t = schemaCombo->currentItem ();
957
958 KateFactory::self()->schemaManager()->removeSchema (t);
959
960 update ();
961}
962
963void KateSchemaConfigPage::newSchema ()
964{
965 TQString t = KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:"), i18n("New Schema"), 0, this);
966
967 KateFactory::self()->schemaManager()->addSchema (t);
968
969 // soft update, no load from disk
970 KateFactory::self()->schemaManager()->update (false);
971 int i = KateFactory::self()->schemaManager()->list ().findIndex (t);
972
973 update ();
974 if (i > -1)
975 {
976 schemaCombo->setCurrentItem (i);
977 schemaChanged (i);
978 }
979}
980
981void KateSchemaConfigPage::schemaChanged (int schema)
982{
983 btndel->setEnabled( schema > 1 );
984
985 m_colorTab->schemaChanged( schema );
986 m_fontTab->schemaChanged( schema );
987 m_fontColorTab->schemaChanged (schema);
988 m_highlightTab->schemaChanged (schema);
989
990 m_lastSchema = schema;
991}
992
993void KateSchemaConfigPage::newCurrentPage (TQWidget *w)
994{
995 if (w == m_highlightTab)
996 m_highlightTab->schemaChanged (m_lastSchema);
997}
998//END KateSchemaConfigPage
999
1000//BEGIN SCHEMA ACTION -- the 'View->Schema' menu action
1001void KateViewSchemaAction::init()
1002{
1003 m_view = 0;
1004 last = 0;
1005
1006 connect(popupMenu(),TQ_SIGNAL(aboutToShow()),this,TQ_SLOT(slotAboutToShow()));
1007}
1008
1009void KateViewSchemaAction::updateMenu (KateView *view)
1010{
1011 m_view = view;
1012}
1013
1014void KateViewSchemaAction::slotAboutToShow()
1015{
1016 KateView *view=m_view;
1017 int count = KateFactory::self()->schemaManager()->list().count();
1018
1019 for (int z=0; z<count; z++)
1020 {
1021 TQString hlName = KateFactory::self()->schemaManager()->list().operator[](z);
1022
1023 if (names.contains(hlName) < 1)
1024 {
1025 names << hlName;
1026 popupMenu()->insertItem ( hlName, this, TQ_SLOT(setSchema(int)), 0, z+1);
1027 }
1028 }
1029
1030 if (!view) return;
1031
1032 popupMenu()->setItemChecked (last, false);
1033 popupMenu()->setItemChecked (view->renderer()->config()->schema()+1, true);
1034
1035 last = view->renderer()->config()->schema()+1;
1036}
1037
1038void KateViewSchemaAction::setSchema (int mode)
1039{
1040 KateView *view=m_view;
1041
1042 if (view)
1043 view->renderer()->config()->setSchema (mode-1);
1044}
1045//END SCHEMA ACTION
1046
1047//BEGIN KateStyleListView
1048KateStyleListView::KateStyleListView( TQWidget *parent, bool showUseDefaults )
1049 : TQListView( parent )
1050{
1051 setSorting( -1 ); // disable sorting, let the styles appear in their defined order
1052 addColumn( i18n("Context") );
1053 addColumn( SmallIconSet("format-text-bold"), TQString::null );
1054 addColumn( SmallIconSet("format-text-italic"), TQString::null );
1055 addColumn( SmallIconSet("format-text-underline"), TQString::null );
1056 addColumn( SmallIconSet("format-text-strikethrough"), TQString::null );
1057 addColumn( i18n("Normal") );
1058 addColumn( i18n("Selected") );
1059 addColumn( i18n("Background") );
1060 addColumn( i18n("Background Selected") );
1061 if ( showUseDefaults )
1062 addColumn( i18n("Use Default Style") );
1063 connect( this, TQ_SIGNAL(mouseButtonPressed(int, TQListViewItem*, const TQPoint&, int)),
1064 this, TQ_SLOT(slotMousePressed(int, TQListViewItem*, const TQPoint&, int)) );
1065 connect( this, TQ_SIGNAL(contextMenuRequested(TQListViewItem*,const TQPoint&, int)),
1066 this, TQ_SLOT(showPopupMenu(TQListViewItem*, const TQPoint&)) );
1067 // grap the bg color, selected color and default font
1068 normalcol = TDEGlobalSettings::textColor();
1069 bgcol = KateRendererConfig::global()->backgroundColor();
1070 selcol = KateRendererConfig::global()->selectionColor();
1071 docfont = *KateRendererConfig::global()->font();
1072
1073 viewport()->setPaletteBackgroundColor( bgcol );
1074}
1075
1076void KateStyleListView::showPopupMenu( KateStyleListItem *i, const TQPoint &globalPos, bool showtitle )
1077{
1078 if ( !dynamic_cast<KateStyleListItem*>(i) ) return;
1079
1080 TDEPopupMenu m( this );
1081 KateAttribute *is = i->style();
1082 int id;
1083 // the title is used, because the menu obscures the context name when
1084 // displayed on behalf of spacePressed().
1085 TQPixmap cl(16,16);
1086 cl.fill( i->style()->textColor() );
1087 TQPixmap scl(16,16);
1088 scl.fill( i->style()->selectedTextColor() );
1089 TQPixmap bgcl(16,16);
1090 bgcl.fill( i->style()->itemSet(KateAttribute::BGColor) ? i->style()->bgColor() : viewport()->colorGroup().base() );
1091 TQPixmap sbgcl(16,16);
1092 sbgcl.fill( i->style()->itemSet(KateAttribute::SelectedBGColor) ? i->style()->selectedBGColor() : viewport()->colorGroup().base() );
1093
1094 if ( showtitle )
1095 m.insertTitle( i->contextName(), KateStyleListItem::ContextName );
1096 id = m.insertItem( i18n("&Bold"), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Bold );
1097 m.setItemChecked( id, is->bold() );
1098 id = m.insertItem( i18n("&Italic"), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Italic );
1099 m.setItemChecked( id, is->italic() );
1100 id = m.insertItem( i18n("&Underline"), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Underline );
1101 m.setItemChecked( id, is->underline() );
1102 id = m.insertItem( i18n("S&trikeout"), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Strikeout );
1103 m.setItemChecked( id, is->strikeOut() );
1104
1105 m.insertSeparator();
1106
1107 m.insertItem( TQIconSet(cl), i18n("Normal &Color..."), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Color );
1108 m.insertItem( TQIconSet(scl), i18n("&Selected Color..."), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelColor );
1109 m.insertItem( TQIconSet(bgcl), i18n("&Background Color..."), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::BgColor );
1110 m.insertItem( TQIconSet(sbgcl), i18n("S&elected Background Color..."), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelBgColor );
1111
1112 // Unset [some] colors. I could show one only if that button was clicked, but that
1113 // would disable setting this with the keyboard (how many aren't doing just
1114 // that every day? ;)
1115 // ANY ideas for doing this in a nicer way will be warmly wellcomed.
1116 KateAttribute *style = i->style();
1117 if ( style->itemSet( KateAttribute::BGColor) || style->itemSet( KateAttribute::SelectedBGColor ) )
1118 {
1119 m.insertSeparator();
1120 if ( style->itemSet( KateAttribute::BGColor) )
1121 m.insertItem( i18n("Unset Background Color"), this, TQ_SLOT(unsetColor(int)), 0, 100 );
1122 if ( style->itemSet( KateAttribute::SelectedBGColor ) )
1123 m.insertItem( i18n("Unset Selected Background Color"), this, TQ_SLOT(unsetColor(int)), 0, 101 );
1124 }
1125
1126 if ( ! i->isDefault() && ! i->defStyle() ) {
1127 m.insertSeparator();
1128 id = m.insertItem( i18n("Use &Default Style"), this, TQ_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::UseDefStyle );
1129 m.setItemChecked( id, i->defStyle() );
1130 }
1131 m.exec( globalPos );
1132}
1133
1134void KateStyleListView::showPopupMenu( TQListViewItem *i, const TQPoint &pos )
1135{
1136 if ( dynamic_cast<KateStyleListItem*>(i) )
1137 showPopupMenu( (KateStyleListItem*)i, pos, true );
1138}
1139
1140void KateStyleListView::mSlotPopupHandler( int z )
1141{
1142 ((KateStyleListItem*)currentItem())->changeProperty( (KateStyleListItem::Property)z );
1143}
1144
1145void KateStyleListView::unsetColor( int c )
1146{
1147 ((KateStyleListItem*)currentItem())->unsetColor( c );
1148 emitChanged();
1149}
1150
1151// Because TQListViewItem::activatePos() is going to become deprecated,
1152// and also because this attempt offers more control, I connect mousePressed to this.
1153void KateStyleListView::slotMousePressed(int btn, TQListViewItem* i, const TQPoint& pos, int c)
1154{
1155 if ( dynamic_cast<KateStyleListItem*>(i) ) {
1156 if ( btn == TQt::LeftButton && c > 0 ) {
1157 // map pos to item/column and call KateStyleListItem::activate(col, pos)
1158 ((KateStyleListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - TQPoint( 0, itemRect(i).top() ) );
1159 }
1160 }
1161}
1162
1163//END
1164
1165//BEGIN KateStyleListItem
1166static const int BoxSize = 16;
1167static const int ColorBtnWidth = 32;
1168
1169KateStyleListItem::KateStyleListItem( TQListViewItem *parent, const TQString & stylename,
1170 KateAttribute *style, KateHlItemData *data )
1171 : TQListViewItem( parent, stylename ),
1172 ds( style ),
1173 st( data )
1174{
1175 initStyle();
1176}
1177
1178KateStyleListItem::KateStyleListItem( TQListView *parent, const TQString & stylename,
1179 KateAttribute *style, KateHlItemData *data )
1180 : TQListViewItem( parent, stylename ),
1181 ds( style ),
1182 st( data )
1183{
1184 initStyle();
1185}
1186
1187void KateStyleListItem::initStyle()
1188{
1189 if (!st)
1190 is = ds;
1191 else
1192 {
1193 is = new KateAttribute (*ds);
1194
1195 if (st->isSomethingSet())
1196 *is += *st;
1197 }
1198}
1199
1200void KateStyleListItem::updateStyle()
1201{
1202 // nothing there, not update it, will crash
1203 if (!st)
1204 return;
1205
1206 if ( is->itemSet(KateAttribute::Weight) )
1207 {
1208 if ( is->weight() != st->weight())
1209 st->setWeight( is->weight() );
1210 }
1211 else st->clearAttribute( KateAttribute::Weight );
1212
1213 if ( is->itemSet(KateAttribute::Italic) )
1214 {
1215 if ( is->italic() != st->italic())
1216 st->setItalic( is->italic() );
1217 }
1218 else st->clearAttribute( KateAttribute::Italic );
1219
1220 if ( is->itemSet(KateAttribute::StrikeOut) )
1221 {
1222 if ( is->strikeOut() != st->strikeOut())
1223
1224 st->setStrikeOut( is->strikeOut() );
1225 }
1226 else st->clearAttribute( KateAttribute::StrikeOut );
1227
1228 if ( is->itemSet(KateAttribute::Underline) )
1229 {
1230 if ( is->underline() != st->underline())
1231 st->setUnderline( is->underline() );
1232 }
1233 else st->clearAttribute( KateAttribute::Underline );
1234
1235 if ( is->itemSet(KateAttribute::Outline) )
1236 {
1237 if ( is->outline() != st->outline())
1238 st->setOutline( is->outline() );
1239 }
1240 else st->clearAttribute( KateAttribute::Outline );
1241
1242 if ( is->itemSet(KateAttribute::TextColor) )
1243 {
1244 if ( is->textColor() != st->textColor())
1245 st->setTextColor( is->textColor() );
1246 }
1247 else st->clearAttribute( KateAttribute::TextColor );
1248
1249 if ( is->itemSet(KateAttribute::SelectedTextColor) )
1250 {
1251 if ( is->selectedTextColor() != st->selectedTextColor())
1252 st->setSelectedTextColor( is->selectedTextColor() );
1253 }
1254 else st->clearAttribute( KateAttribute::SelectedTextColor);
1255
1256 if ( is->itemSet(KateAttribute::BGColor) )
1257 {
1258 if ( is->bgColor() != st->bgColor())
1259 st->setBGColor( is->bgColor() );
1260 }
1261 else st->clearAttribute( KateAttribute::BGColor );
1262
1263 if ( is->itemSet(KateAttribute::SelectedBGColor) )
1264 {
1265 if ( is->selectedBGColor() != st->selectedBGColor())
1266 st->setSelectedBGColor( is->selectedBGColor() );
1267 }
1268 else st->clearAttribute( KateAttribute::SelectedBGColor );
1269}
1270
1271/* only true for a hl mode item using it's default style */
1272bool KateStyleListItem::defStyle() { return st && st->itemsSet() != ds->itemsSet(); }
1273
1274/* true for default styles */
1275bool KateStyleListItem::isDefault() { return st ? false : true; }
1276
1277int KateStyleListItem::width( const TQFontMetrics & /*fm*/, const TQListView * lv, int col ) const
1278{
1279 int m = lv->itemMargin() * 2;
1280 switch ( col ) {
1281 case ContextName:
1282 // FIXME: width for name column should reflect bold/italic
1283 // (relevant for non-fixed fonts only - nessecary?)
1284 return TQListViewItem::width( TQFontMetrics( ((KateStyleListView*)lv)->docfont), lv, col);
1285 case Bold:
1286 case Italic:
1287 case UseDefStyle:
1288 return BoxSize + m;
1289 case Color:
1290 case SelColor:
1291 case BgColor:
1292 case SelBgColor:
1293 return ColorBtnWidth +m;
1294 default:
1295 return 0;
1296 }
1297}
1298
1299void KateStyleListItem::activate( int column, const TQPoint &localPos )
1300{
1301 TQListView *lv = listView();
1302 int x = 0;
1303 for( int c = 0; c < column-1; c++ )
1304 x += lv->columnWidth( c );
1305 int w;
1306 switch( column ) {
1307 case Bold:
1308 case Italic:
1309 case Underline:
1310 case Strikeout:
1311 case UseDefStyle:
1312 w = BoxSize;
1313 break;
1314 case Color:
1315 case SelColor:
1316 case BgColor:
1317 case SelBgColor:
1318 w = ColorBtnWidth;
1319 break;
1320 default:
1321 return;
1322 }
1323 if ( !TQRect( x, 0, w, BoxSize ).contains( localPos ) )
1324 changeProperty( (Property)column );
1325}
1326
1327void KateStyleListItem::changeProperty( Property p )
1328{
1329 if ( p == Bold )
1330 is->setBold( ! is->bold() );
1331 else if ( p == Italic )
1332 is->setItalic( ! is->italic() );
1333 else if ( p == Underline )
1334 is->setUnderline( ! is->underline() );
1335 else if ( p == Strikeout )
1336 is->setStrikeOut( ! is->strikeOut() );
1337 else if ( p == UseDefStyle )
1338 toggleDefStyle();
1339 else
1340 setColor( p );
1341
1342 updateStyle ();
1343
1344 ((KateStyleListView*)listView())->emitChanged();
1345}
1346
1347void KateStyleListItem::toggleDefStyle()
1348{
1349 if ( *is == *ds ) {
1350 KMessageBox::information( listView(),
1351 i18n("\"Use Default Style\" will be automatically unset when you change any style properties."),
1352 i18n("Kate Styles"),
1353 "Kate hl config use defaults" );
1354 }
1355 else {
1356 delete is;
1357 is = new KateAttribute( *ds );
1358 updateStyle();
1359 repaint();
1360 }
1361}
1362
1363void KateStyleListItem::setColor( int column )
1364{
1365 TQColor c; // use this
1366 TQColor d; // default color
1367 if ( column == Color)
1368 {
1369 c = is->textColor();
1370 d = ds->textColor();
1371 }
1372 else if ( column == SelColor )
1373 {
1374 c = is->selectedTextColor();
1375 d = is->selectedTextColor();
1376 }
1377 else if ( column == BgColor )
1378 {
1379 c = is->bgColor();
1380 d = ds->bgColor();
1381 }
1382 else if ( column == SelBgColor )
1383 {
1384 c = is->selectedBGColor();
1385 d = ds->selectedBGColor();
1386 }
1387
1388 if ( KColorDialog::getColor( c, d, listView() ) != TQDialog::Accepted) return;
1389
1390 bool def = ! c.isValid();
1391
1392 // if set default, and the attrib is set in the default style use it
1393 // else if set default, unset it
1394 // else set the selected color
1395 switch (column)
1396 {
1397 case Color:
1398 if ( def )
1399 {
1400 if ( ds->itemSet(KateAttribute::TextColor) )
1401 is->setTextColor( ds->textColor());
1402 else
1403 is->clearAttribute(KateAttribute::TextColor);
1404 }
1405 else
1406 is->setTextColor( c );
1407 break;
1408 case SelColor:
1409 if ( def )
1410 {
1411 if ( ds->itemSet(KateAttribute::SelectedTextColor) )
1412 is->setSelectedTextColor( ds->selectedTextColor());
1413 else
1414 is->clearAttribute(KateAttribute::SelectedTextColor);
1415 }
1416 else
1417 is->setSelectedTextColor( c );
1418 break;
1419 case BgColor:
1420 if ( def )
1421 {
1422 if ( ds->itemSet(KateAttribute::BGColor) )
1423 is->setBGColor( ds->bgColor());
1424 else
1425 is->clearAttribute(KateAttribute::BGColor);
1426 }
1427 else
1428 is->setBGColor( c );
1429 break;
1430 case SelBgColor:
1431 if ( def )
1432 {
1433 if ( ds->itemSet(KateAttribute::SelectedBGColor) )
1434 is->setSelectedBGColor( ds->selectedBGColor());
1435 else
1436 is->clearAttribute(KateAttribute::SelectedBGColor);
1437 }
1438 else
1439 is->setSelectedBGColor( c );
1440 break;
1441 }
1442
1443 repaint();
1444}
1445
1446void KateStyleListItem::unsetColor( int c )
1447{
1448 if ( c == 100 && is->itemSet(KateAttribute::BGColor) )
1449 is->clearAttribute(KateAttribute::BGColor);
1450 else if ( c == 101 && is->itemSet(KateAttribute::SelectedBGColor) )
1451 is->clearAttribute(KateAttribute::SelectedBGColor);
1452 updateStyle();
1453}
1454
1455void KateStyleListItem::paintCell( TQPainter *p, const TQColorGroup& /*cg*/, int col, int width, int align )
1456{
1457
1458 if ( !p )
1459 return;
1460
1461 TQListView *lv = listView();
1462 if ( !lv )
1463 return;
1464 Q_ASSERT( lv ); //###
1465
1466 // use a private color group and set the text/highlighted text colors
1467 TQColorGroup mcg = lv->viewport()->colorGroup();
1468
1469 if ( col ) // col 0 is drawn by the superclass method
1470 p->fillRect( 0, 0, width, height(), TQBrush( mcg.base() ) );
1471
1472 int marg = lv->itemMargin();
1473
1474 TQColor c;
1475
1476 switch ( col )
1477 {
1478 case ContextName:
1479 {
1480 mcg.setColor(TQColorGroup::Text, is->textColor());
1481 mcg.setColor(TQColorGroup::HighlightedText, is->selectedTextColor());
1482 // text background color
1483 c = is->bgColor();
1484 if ( c.isValid() && is->itemSet(KateAttribute::BGColor) )
1485 mcg.setColor( TQColorGroup::Base, c );
1486 if ( isSelected() && is->itemSet(KateAttribute::SelectedBGColor) )
1487 {
1488 c = is->selectedBGColor();
1489 if ( c.isValid() )
1490 mcg.setColor( TQColorGroup::Highlight, c );
1491 }
1492 TQFont f ( ((KateStyleListView*)lv)->docfont );
1493 p->setFont( is->font(f) );
1494 // FIXME - repainting when text is cropped, and the column is enlarged is buggy.
1495 // Maybe I need painting the string myself :(
1496 // (wilbert) it depends on the font used
1497 TQListViewItem::paintCell( p, mcg, col, width, align );
1498 }
1499 break;
1500 case Bold:
1501 case Italic:
1502 case Underline:
1503 case Strikeout:
1504 case UseDefStyle:
1505 {
1506 // Bold/Italic/use default checkboxes
1507 // code allmost identical to QCheckListItem
1508 int x = 0;
1509 int y = (height() - BoxSize) / 2;
1510
1511 if ( isEnabled() )
1512 p->setPen( TQPen( mcg.text(), 2 ) );
1513 else
1514 p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
1515
1516 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
1517 x++;
1518 y++;
1519 if ( (col == Bold && is->bold()) ||
1520 (col == Italic && is->italic()) ||
1521 (col == Underline && is->underline()) ||
1522 (col == Strikeout && is->strikeOut()) ||
1523 (col == UseDefStyle && *is == *ds ) )
1524 {
1525 TQPointArray a( 7*2 );
1526 int i, xx, yy;
1527 xx = x+1+marg;
1528 yy = y+5;
1529 for ( i=0; i<3; i++ ) {
1530 a.setPoint( 2*i, xx, yy );
1531 a.setPoint( 2*i+1, xx, yy+2 );
1532 xx++; yy++;
1533 }
1534 yy -= 2;
1535 for ( i=3; i<7; i++ ) {
1536 a.setPoint( 2*i, xx, yy );
1537 a.setPoint( 2*i+1, xx, yy+2 );
1538 xx++; yy--;
1539 }
1540 p->drawLineSegments( a );
1541 }
1542 }
1543 break;
1544 case Color:
1545 case SelColor:
1546 case BgColor:
1547 case SelBgColor:
1548 {
1549 bool set( false );
1550 if ( col == Color)
1551 {
1552 c = is->textColor();
1553 set = is->itemSet(KateAttribute::TextColor);
1554 }
1555 else if ( col == SelColor )
1556 {
1557 c = is->selectedTextColor();
1558 set = is->itemSet( KateAttribute::SelectedTextColor);
1559 }
1560 else if ( col == BgColor )
1561 {
1562 set = is->itemSet(KateAttribute::BGColor);
1563 c = set ? is->bgColor() : mcg.base();
1564 }
1565 else if ( col == SelBgColor )
1566 {
1567 set = is->itemSet(KateAttribute::SelectedBGColor);
1568 c = set ? is->selectedBGColor(): mcg.base();
1569 }
1570
1571 // color "buttons"
1572 int x = 0;
1573 int y = (height() - BoxSize) / 2;
1574 if ( isEnabled() )
1575 p->setPen( TQPen( mcg.text(), 2 ) );
1576 else
1577 p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
1578
1579 p->drawRect( x+marg, y+2, ColorBtnWidth-4, BoxSize-4 );
1580 p->fillRect( x+marg+1,y+3,ColorBtnWidth-7,BoxSize-7,TQBrush( c ) );
1581 // if this item is unset, draw a diagonal line over the button
1582 if ( ! set )
1583 p->drawLine( x+marg-1, BoxSize-3, ColorBtnWidth-4, y+1 );
1584 }
1585 //case default: // no warning...
1586 }
1587}
1588//END
1589
1590//BEGIN KateStyleListCaption
1591KateStyleListCaption::KateStyleListCaption( TQListView *parent, const TQString & name )
1592 : TQListViewItem( parent, name )
1593{
1594}
1595
1596void KateStyleListCaption::paintCell( TQPainter *p, const TQColorGroup& /*cg*/, int col, int width, int align )
1597{
1598 TQListView *lv = listView();
1599 if ( !lv )
1600 return;
1601 Q_ASSERT( lv ); //###
1602
1603 // use the same colorgroup as the other items in the viewport
1604 TQColorGroup mcg = lv->viewport()->colorGroup();
1605
1606 TQListViewItem::paintCell( p, mcg, col, width, align );
1607}
1608//END
KColorButton
KColorDialog::getColor
static int getColor(TQColor &theColor, TQWidget *parent=0L)
KComboBox
KDialog::marginHint
static int marginHint()
KDialog::spacingHint
static int spacingHint()
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)
KMessageBox::information
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
KateAttribute
The Attribute class incorporates all text decorations supported by Kate.
Definition: kateattribute.h:33
TDEConfigBase::readColorEntry
TQColor readColorEntry(const TQString &pKey, const TQColor *pDefault=0L) const
TDEConfigBase::group
TQString group() const
TDEConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TDEConfigBase::setGroup
void setGroup(const TQString &group)
TDEConfig
TDEFontChooser
TDEGlobalSettings::baseColor
static TQColor baseColor()
TDEGlobalSettings::highlightColor
static TQColor highlightColor()
TDEGlobalSettings::fixedFont
static TQFont fixedFont()
TDEGlobalSettings::alternateBackgroundColor
static TQColor alternateBackgroundColor()
TDEGlobalSettings::textColor
static TQColor textColor()
TDEPopupMenu
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
TDEStdAccel::name
TQString name(StdAccel id)
TDEStdAccel::find
const TDEShortcut & find()
TDEStdAccel::reload
const TDEShortcut & reload()
TDEStdAccel::label
TQString label(StdAccel id)
tdelocale.h

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.9.4
This website is maintained by Timothy Pearson.