21 #include "kateschema.h"
22 #include "kateschema.moc"
24 #include "kateconfig.h"
25 #include "katedocument.h"
26 #include "katefactory.h"
28 #include "katerenderer.h"
31 #include <kdialogbase.h>
32 #include <kcolorbutton.h>
33 #include <kcombobox.h>
34 #include <kinputdialog.h>
35 #include <tdefontdialog.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>
45 #include <tqbuttongroup.h>
46 #include <tqcheckbox.h>
47 #include <tqptrcollection.h>
50 #include <tqgroupbox.h>
52 #include <tqtextcodec.h>
54 #include <tqlineedit.h>
56 #include <tqlistbox.h>
58 #include <tqpainter.h>
59 #include <tqobjectlist.h>
61 #include <tqpushbutton.h>
62 #include <tqradiobutton.h>
63 #include <tqspinbox.h>
64 #include <tqstringlist.h>
65 #include <tqtabwidget.h>
67 #include <tqvgroupbox.h>
68 #include <tqwhatsthis.h>
83 class KateStyleListItem :
public TQListViewItem
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; };
93 enum Property { ContextName, Bold, Italic, Underline, Strikeout, Color, SelColor, BgColor, SelBgColor, UseDefStyle };
100 virtual int width (
const TQFontMetrics & fm,
const TQListView * lv,
int c )
const;
102 void activate(
int column,
const TQPoint &localPos );
104 void changeProperty( Property p );
108 void unsetColor(
int c );
110 TQString contextName() {
return text(0); };
121 void paintCell(TQPainter *p,
const TQColorGroup& cg,
int col,
int width,
int align);
125 void toggleDefStyle();
126 void setColor(
int );
132 class KateHlItemData *st;
144 class KateStyleListCaption :
public TQListViewItem
147 KateStyleListCaption( TQListView *parent,
const TQString & name );
148 ~KateStyleListCaption() {};
151 void paintCell(TQPainter *p,
const TQColorGroup& cg,
int col,
int width,
int align);
156 TQString KateSchemaManager::normalSchema ()
158 return TDEApplication::kApplication()->aboutData()->appName () + TQString (
" - Normal");
161 TQString KateSchemaManager::printingSchema ()
163 return TDEApplication::kApplication()->aboutData()->appName () + TQString (
" - Printing");
166 KateSchemaManager::KateSchemaManager ()
167 : m_config (
"kateschemarc", false, false)
172 KateSchemaManager::~KateSchemaManager ()
179 void KateSchemaManager::update (
bool readfromfile)
182 m_config.reparseConfiguration ();
184 m_schemas = m_config.groupList();
187 m_schemas.remove (printingSchema());
188 m_schemas.remove (normalSchema());
189 m_schemas.prepend (printingSchema());
190 m_schemas.prepend (normalSchema());
197 TDEConfig *KateSchemaManager::schema (uint number)
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());
204 m_config.setGroup (normalSchema());
209 void KateSchemaManager::addSchema (
const TQString &t)
211 m_config.setGroup (t);
217 void KateSchemaManager::removeSchema (uint number)
219 if (number >= m_schemas.count())
225 m_config.deleteGroup (name (number));
230 bool KateSchemaManager::validSchema (uint number)
232 if (number < m_schemas.count())
238 uint KateSchemaManager::number (
const TQString &name)
240 if (name == normalSchema())
243 if (name == printingSchema())
247 if ((i = m_schemas.findIndex(name)) > -1)
253 TQString KateSchemaManager::name (uint number)
255 if ((number>1) && (number < m_schemas.count()))
256 return m_schemas[number];
257 else if (number == 1)
258 return printingSchema();
260 return normalSchema();
269 KateSchemaConfigColorTab::KateSchemaConfigColorTab( TQWidget *parent,
const char * )
277 TQVBoxLayout *blay=
new TQVBoxLayout(
this, 0, KDialog::spacingHint());
279 TQVGroupBox *gbTextArea =
new TQVGroupBox(i18n(
"Text Area Background"),
this);
281 b =
new TQHBox (gbTextArea);
282 b->setSpacing(KDialog::spacingHint());
283 label =
new TQLabel( i18n(
"Normal text:"), b);
284 label->setAlignment( AlignLeft|AlignVCenter);
287 b =
new TQHBox (gbTextArea);
288 b->setSpacing(KDialog::spacingHint());
289 label =
new TQLabel( i18n(
"Selected text:"), b);
290 label->setAlignment( AlignLeft|AlignVCenter);
293 b =
new TQHBox (gbTextArea);
294 b->setSpacing(KDialog::spacingHint());
295 label =
new TQLabel( i18n(
"Current line:"), b);
296 label->setAlignment( AlignLeft|AlignVCenter);
300 b =
new TQHBox (gbTextArea);
301 b->setSpacing(KDialog::spacingHint());
302 m_combobox =
new KComboBox(b,
"color_combo_box");
304 m_combobox->insertItem(i18n(
"Bookmark"));
305 m_combobox->insertItem(i18n(
"Active Breakpoint"));
306 m_combobox->insertItem(i18n(
"Reached Breakpoint"));
307 m_combobox->insertItem(i18n(
"Disabled Breakpoint"));
308 m_combobox->insertItem(i18n(
"Execution"));
309 m_combobox->insertItem(i18n(
"Warning"));
310 m_combobox->insertItem(i18n(
"Error"));
311 m_combobox->setCurrentItem(0);
313 connect( m_combobox, TQT_SIGNAL( activated(
int ) ), TQT_SLOT( slotComboBoxChanged(
int ) ) );
315 blay->addWidget(gbTextArea);
317 TQVGroupBox *gbBorder =
new TQVGroupBox(i18n(
"Additional Elements"),
this);
319 b =
new TQHBox (gbBorder);
320 b->setSpacing(KDialog::spacingHint());
321 label =
new TQLabel( i18n(
"Left border background:"), b);
322 label->setAlignment( AlignLeft|AlignVCenter);
325 b =
new TQHBox (gbBorder);
326 b->setSpacing(KDialog::spacingHint());
327 label =
new TQLabel( i18n(
"Line numbers:"), b);
328 label->setAlignment( AlignLeft|AlignVCenter);
331 b =
new TQHBox (gbBorder);
332 b->setSpacing(KDialog::spacingHint());
333 label =
new TQLabel( i18n(
"Bracket highlight:"), b);
334 label->setAlignment( AlignLeft|AlignVCenter);
337 b =
new TQHBox (gbBorder);
338 b->setSpacing(KDialog::spacingHint());
339 label =
new TQLabel( i18n(
"Word wrap markers:"), b);
340 label->setAlignment( AlignLeft|AlignVCenter);
343 b =
new TQHBox (gbBorder);
344 b->setSpacing(KDialog::spacingHint());
345 label =
new TQLabel( i18n(
"Tab markers:"), b);
346 label->setAlignment( AlignLeft|AlignVCenter);
349 blay->addWidget(gbBorder);
354 connect(
this, TQT_SIGNAL( changed() ), parent->parentWidget(), TQT_SLOT( slotChanged() ) );
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>"));
383 KateSchemaConfigColorTab::~KateSchemaConfigColorTab()
387 void KateSchemaConfigColorTab::schemaChanged (
int newSchema )
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();
402 if ( newSchema == m_schema )
return;
405 m_schema = newSchema;
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 & ) ) );
419 if ( ! m_schemas.contains( newSchema ) )
425 TQColor tmp3 (
"#FFFF99" );
426 TQColor tmp4 (tmp2.dark());
428 TQColor tmp6 (
"#EAE9E8" );
429 TQColor tmp7 (
"#000000" );
432 TQValueVector <TQColor> mark(KTextEditor::MarkInterface::reservedMarkersCount());
433 Q_ASSERT(mark.size() > 6);
436 mark[2] = Qt::yellow;
437 mark[3] = Qt::magenta;
443 TDEConfig *config = KateFactory::self()->schemaManager()->schema(newSchema);
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);
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] );
457 m_schemas[ newSchema ] = c;
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 );
470 for (
int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
472 TQPixmap pix(16, 16);
473 pix.fill( m_schemas [ newSchema ].markerColors[i]);
474 m_combobox->changeItem(pix, m_combobox->text(i), i);
476 m_markers->setColor( m_schemas [ newSchema ].markerColors[ m_combobox->currentItem() ] );
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& ) ) );
489 void KateSchemaConfigColorTab::apply ()
491 schemaChanged( m_schema );
492 TQMap<int,SchemaColors>::Iterator it;
493 for ( it = m_schemas.begin(); it != m_schemas.end(); ++it )
496 TDEConfig *config = KateFactory::self()->schemaManager()->schema( it.key() );
497 kdDebug(13030)<<
"Using config group "<<config->group()<<
endl;
498 SchemaColors c = it.data();
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);
509 for (
int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
511 config->writeEntry(TQString(
"Color MarkType%1").arg(i + 1), c.markerColors[i]);
516 void KateSchemaConfigColorTab::slotMarkerColorChanged(
const TQColor& color)
518 int index = m_combobox->currentItem();
519 m_schemas[ m_schema ].markerColors[ index ] = color;
520 TQPixmap pix(16, 16);
522 m_combobox->changeItem(pix, m_combobox->text(index), index);
527 void KateSchemaConfigColorTab::slotComboBoxChanged(
int index)
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& ) ) );
538 KateSchemaConfigFontTab::KateSchemaConfigFontTab( TQWidget *parent,
const char * )
542 TQGridLayout *grid =
new TQGridLayout(
this, 1, 1 );
544 m_fontchooser =
new TDEFontChooser (
this, 0L,
false, TQStringList(),
false );
545 m_fontchooser->enableColumn(TDEFontChooser::StyleList,
false);
546 grid->addWidget( m_fontchooser, 0, 0);
548 connect (
this, TQT_SIGNAL( changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
552 KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
556 void KateSchemaConfigFontTab::slotFontSelected(
const TQFont &font )
560 m_fonts[m_schema] = font;
565 void KateSchemaConfigFontTab::apply()
567 FontMap::Iterator it;
568 for ( it = m_fonts.begin(); it != m_fonts.end(); ++it )
570 KateFactory::self()->schemaManager()->schema( it.key() )->writeEntry(
"Font", it.data() );
574 void KateSchemaConfigFontTab::schemaChanged(
int newSchema )
577 m_fonts[ m_schema ] = m_fontchooser->font();
579 m_schema = newSchema;
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 & )));
591 KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab( TQWidget *parent,
const char * )
594 m_defaultStyleLists.setAutoDelete(
true);
597 TQGridLayout *grid =
new TQGridLayout(
this, 1, 1 );
599 m_defaultStyles =
new KateStyleListView(
this,
false );
600 grid->addWidget( m_defaultStyles, 0, 0);
602 connect (m_defaultStyles, TQT_SIGNAL (changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
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 "
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.") );
613 KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab()
617 KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema)
619 if (!m_defaultStyleLists[schema])
621 KateAttributeList *list =
new KateAttributeList ();
622 KateHlManager::self()->getDefaults(schema, *list);
624 m_defaultStyleLists.insert (schema, list);
627 return m_defaultStyleLists[schema];
630 void KateSchemaConfigFontColorTab::schemaChanged (uint schema)
632 m_defaultStyles->clear ();
634 KateAttributeList *l = attributeList (schema);
637 TQPalette p ( m_defaultStyles->palette() );
639 p.setColor( TQColorGroup::Base,
640 KateFactory::self()->schemaManager()->schema(schema)->
641 readColorEntry(
"Color Background", &_c ) );
643 p.setColor( TQColorGroup::Highlight,
644 KateFactory::self()->schemaManager()->schema(schema)->
645 readColorEntry(
"Color Selection", &_c ) );
646 _c = l->at(0)->textColor();
647 p.setColor( TQColorGroup::Text, _c );
648 m_defaultStyles->viewport()->setPalette( p );
651 for (
int i = KateHlManager::self()->defaultStyles() - 1; i >= 0; i-- )
653 new KateStyleListItem( m_defaultStyles, KateHlManager::self()->defaultStyleName(i,
true), l->at( i ) );
657 void KateSchemaConfigFontColorTab::reload ()
659 m_defaultStyles->clear ();
660 m_defaultStyleLists.clear ();
663 void KateSchemaConfigFontColorTab::apply ()
665 for ( TQIntDictIterator<KateAttributeList> it( m_defaultStyleLists ); it.current(); ++it )
666 KateHlManager::self()->setDefaults(it.currentKey(), *(it.current()));
672 KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab( TQWidget *parent,
const char *, KateSchemaConfigFontColorTab *page, uint hl )
680 m_hlDict.setAutoDelete (
true);
682 TQVBoxLayout *layout =
new TQVBoxLayout(
this, 0, KDialog::spacingHint() );
685 TQHBox *hbHl =
new TQHBox(
this );
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)) );
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));
699 hlCombo->insertItem(KateHlManager::self()->hlNameTranslated(i));
701 hlCombo->setCurrentItem(0);
704 m_styles =
new KateStyleListView(
this,
true );
705 layout->addWidget (m_styles, 999);
707 hlCombo->setCurrentItem ( hl );
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><SPACE></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.") );
719 connect (m_styles, TQT_SIGNAL (changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
722 KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
726 void KateSchemaConfigHighlightTab::hlChanged(
int z)
730 schemaChanged (m_schema);
733 void KateSchemaConfigHighlightTab::schemaChanged (uint schema)
737 kdDebug(13030) <<
"NEW SCHEMA: " << m_schema <<
" NEW HL: " << m_hl <<
endl;
741 if (!m_hlDict[m_schema])
743 kdDebug(13030) <<
"NEW SCHEMA, create dict" <<
endl;
745 m_hlDict.insert (schema,
new TQIntDict<KateHlItemDataList>);
746 m_hlDict[m_schema]->setAutoDelete (
true);
749 if (!m_hlDict[m_schema]->
find(m_hl))
753 KateHlItemDataList *list =
new KateHlItemDataList ();
754 KateHlManager::self()->getHl( m_hl )->getKateHlItemDataListCopy (m_schema, *list);
755 m_hlDict[m_schema]->insert (m_hl, list);
758 KateAttributeList *l = m_defaults->attributeList (schema);
764 TQPalette p ( m_styles->palette() );
766 p.setColor( TQColorGroup::Base,
767 KateFactory::self()->schemaManager()->schema(m_schema)->
768 readColorEntry(
"Color Background", &_c ) );
770 p.setColor( TQColorGroup::Highlight,
771 KateFactory::self()->schemaManager()->schema(m_schema)->
772 readColorEntry(
"Color Selection", &_c ) );
773 _c = l->at(0)->textColor();
774 p.setColor( TQColorGroup::Text, _c );
775 m_styles->viewport()->setPalette( p );
777 TQDict<KateStyleListCaption> prefixes;
778 for ( KateHlItemData *itemData = m_hlDict[m_schema]->
find(m_hl)->last();
780 itemData = m_hlDict[m_schema]->find(m_hl)->prev())
782 kdDebug(13030) <<
"insert items " << itemData->name <<
endl;
786 int c = itemData->name.find(
':');
788 TQString prefix = itemData->name.left(c);
789 TQString name = itemData->name.mid(c+1);
791 KateStyleListCaption *parent = prefixes.find( prefix );
794 parent =
new KateStyleListCaption( m_styles, prefix );
795 parent->setOpen(
true);
796 prefixes.insert( prefix, parent );
798 new KateStyleListItem( parent, name, l->at(itemData->defStyleNum), itemData );
800 new KateStyleListItem( m_styles, itemData->name, l->at(itemData->defStyleNum), itemData );
805 void KateSchemaConfigHighlightTab::reload ()
813 void KateSchemaConfigHighlightTab::apply ()
815 for ( TQIntDictIterator< TQIntDict<KateHlItemDataList> > it( m_hlDict ); it.current(); ++it )
816 for ( TQIntDictIterator< KateHlItemDataList > it2( *it.current() ); it2.current(); ++it2 )
818 KateHlManager::self()->getHl( it2.currentKey() )->setKateHlItemDataList (it.currentKey(), *(it2.current()));
825 KateSchemaConfigPage::KateSchemaConfigPage( TQWidget *parent, KateDocument *doc )
826 : KateConfigPage( parent ),
829 TQVBoxLayout *layout =
new TQVBoxLayout(
this, 0, KDialog::spacingHint() );
831 TQHBox *hbHl =
new TQHBox(
this );
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)) );
840 TQPushButton *btnnew =
new TQPushButton( i18n(
"&New..."), hbHl );
841 connect( btnnew, TQT_SIGNAL(clicked()),
this, TQT_SLOT(newSchema()) );
843 btndel =
new TQPushButton( i18n(
"&Delete"), hbHl );
844 connect( btndel, TQT_SIGNAL(clicked()),
this, TQT_SLOT(deleteSchema()) );
846 m_tabWidget =
new TQTabWidget (
this );
847 m_tabWidget->setMargin (KDialog::marginHint());
848 layout->add (m_tabWidget);
850 connect (m_tabWidget, TQT_SIGNAL (currentChanged (TQWidget *)),
this, TQT_SLOT (newCurrentPage (TQWidget *)));
852 m_colorTab =
new KateSchemaConfigColorTab (m_tabWidget);
853 m_tabWidget->addTab (m_colorTab, i18n(
"Colors"));
855 m_fontTab =
new KateSchemaConfigFontTab (m_tabWidget);
856 m_tabWidget->addTab (m_fontTab, i18n(
"Font"));
858 m_fontColorTab =
new KateSchemaConfigFontColorTab (m_tabWidget);
859 m_tabWidget->addTab (m_fontColorTab, i18n(
"Normal Text Styles"));
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"));
865 hbHl =
new TQHBox(
this );
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 );
873 m_defaultSchema = (doc && doc->activeView()) ? doc->activeView()->renderer()->config()->schema() : KateRendererConfig::global()->schema();
877 connect( defaultSchemaCombo, TQT_SIGNAL(activated(
int)),
878 this, TQT_SLOT(slotChanged()) );
881 KateSchemaConfigPage::~KateSchemaConfigPage ()
884 KateFactory::self()->schemaManager()->update ();
887 void KateSchemaConfigPage::apply()
891 m_fontColorTab->apply ();
892 m_highlightTab->apply ();
895 KateFactory::self()->schemaManager()->schema (0)->sync();
897 KateFactory::self()->schemaManager()->update ();
900 for (
int i = 0; i < KateHlManager::self()->highlights(); ++i)
901 KateHlManager::self()->getHl (i)->clearAttributeArrays ();
904 KateRendererConfig::global()->setSchema (defaultSchemaCombo->currentItem());
905 KateRendererConfig::global()->reloadSchema();
908 KateHlManager::self()->getTDEConfig()->sync ();
911 void KateSchemaConfigPage::reload()
914 KateFactory::self()->schemaManager()->update ();
917 m_fontColorTab->reload ();
921 defaultSchemaCombo->setCurrentItem (KateRendererConfig::global()->schema());
924 schemaCombo->setCurrentItem( m_defaultSchema );
925 schemaChanged( m_defaultSchema );
928 void KateSchemaConfigPage::reset()
933 void KateSchemaConfigPage::defaults()
938 void KateSchemaConfigPage::update ()
941 KateFactory::self()->schemaManager()->update (
false);
943 schemaCombo->clear ();
944 schemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
946 defaultSchemaCombo->clear ();
947 defaultSchemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
949 schemaCombo->setCurrentItem (0);
952 schemaCombo->setEnabled (schemaCombo->count() > 0);
955 void KateSchemaConfigPage::deleteSchema ()
957 int t = schemaCombo->currentItem ();
959 KateFactory::self()->schemaManager()->removeSchema (t);
964 void KateSchemaConfigPage::newSchema ()
966 TQString t =
KInputDialog::getText (i18n(
"Name for New Schema"), i18n (
"Name:"), i18n(
"New Schema"), 0,
this);
968 KateFactory::self()->schemaManager()->addSchema (t);
971 KateFactory::self()->schemaManager()->update (
false);
972 int i = KateFactory::self()->schemaManager()->list ().findIndex (t);
977 schemaCombo->setCurrentItem (i);
982 void KateSchemaConfigPage::schemaChanged (
int schema)
984 btndel->setEnabled( schema > 1 );
986 m_colorTab->schemaChanged( schema );
987 m_fontTab->schemaChanged( schema );
988 m_fontColorTab->schemaChanged (schema);
989 m_highlightTab->schemaChanged (schema);
991 m_lastSchema = schema;
994 void KateSchemaConfigPage::newCurrentPage (TQWidget *w)
996 if (w == m_highlightTab)
997 m_highlightTab->schemaChanged (m_lastSchema);
1002 void KateViewSchemaAction::init()
1007 connect(popupMenu(),TQT_SIGNAL(aboutToShow()),
this,TQT_SLOT(slotAboutToShow()));
1010 void KateViewSchemaAction::updateMenu (KateView *view)
1015 void KateViewSchemaAction::slotAboutToShow()
1017 KateView *view=m_view;
1018 int count = KateFactory::self()->schemaManager()->list().count();
1020 for (
int z=0; z<count; z++)
1022 TQString hlName = KateFactory::self()->schemaManager()->list().operator[](z);
1024 if (names.contains(hlName) < 1)
1027 popupMenu()->insertItem ( hlName,
this, TQT_SLOT(setSchema(
int)), 0, z+1);
1033 popupMenu()->setItemChecked (last,
false);
1034 popupMenu()->setItemChecked (view->renderer()->config()->schema()+1,
true);
1036 last = view->renderer()->config()->schema()+1;
1039 void KateViewSchemaAction::setSchema (
int mode)
1041 KateView *view=m_view;
1044 view->renderer()->config()->setSchema (mode-1);
1049 KateStyleListView::KateStyleListView( TQWidget *parent,
bool showUseDefaults )
1050 : TQListView( parent )
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&)) );
1070 bgcol = KateRendererConfig::global()->backgroundColor();
1071 selcol = KateRendererConfig::global()->selectionColor();
1072 docfont = *KateRendererConfig::global()->font();
1074 viewport()->setPaletteBackgroundColor( bgcol );
1077 void KateStyleListView::showPopupMenu( KateStyleListItem *i,
const TQPoint &globalPos,
bool showtitle )
1079 if ( !dynamic_cast<KateStyleListItem*>(i) )
return;
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() );
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() );
1106 m.insertSeparator();
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 );
1118 if ( style->itemSet( KateAttribute::BGColor) || style->itemSet( KateAttribute::SelectedBGColor ) )
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 );
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() );
1132 m.exec( globalPos );
1135 void KateStyleListView::showPopupMenu( TQListViewItem *i,
const TQPoint &pos )
1137 if ( dynamic_cast<KateStyleListItem*>(i) )
1138 showPopupMenu( (KateStyleListItem*)i, pos,
true );
1141 void KateStyleListView::mSlotPopupHandler(
int z )
1143 ((KateStyleListItem*)currentItem())->changeProperty( (KateStyleListItem::Property)z );
1146 void KateStyleListView::unsetColor(
int c )
1148 ((KateStyleListItem*)currentItem())->unsetColor( c );
1154 void KateStyleListView::slotMousePressed(
int btn, TQListViewItem* i,
const TQPoint& pos,
int c)
1156 if ( dynamic_cast<KateStyleListItem*>(i) ) {
1157 if ( btn == Qt::LeftButton && c > 0 ) {
1159 ((KateStyleListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - TQPoint( 0, itemRect(i).top() ) );
1167 static const int BoxSize = 16;
1168 static const int ColorBtnWidth = 32;
1170 KateStyleListItem::KateStyleListItem( TQListViewItem *parent,
const TQString & stylename,
1172 : TQListViewItem( parent, stylename ),
1179 KateStyleListItem::KateStyleListItem( TQListView *parent,
const TQString & stylename,
1181 : TQListViewItem( parent, stylename ),
1188 void KateStyleListItem::initStyle()
1196 if (st->isSomethingSet())
1201 void KateStyleListItem::updateStyle()
1207 if ( is->itemSet(KateAttribute::Weight) )
1209 if ( is->weight() != st->weight())
1210 st->setWeight( is->weight() );
1212 else st->clearAttribute( KateAttribute::Weight );
1214 if ( is->itemSet(KateAttribute::Italic) )
1216 if ( is->italic() != st->italic())
1217 st->setItalic( is->italic() );
1219 else st->clearAttribute( KateAttribute::Italic );
1221 if ( is->itemSet(KateAttribute::StrikeOut) )
1223 if ( is->strikeOut() != st->strikeOut())
1225 st->setStrikeOut( is->strikeOut() );
1227 else st->clearAttribute( KateAttribute::StrikeOut );
1229 if ( is->itemSet(KateAttribute::Underline) )
1231 if ( is->underline() != st->underline())
1232 st->setUnderline( is->underline() );
1234 else st->clearAttribute( KateAttribute::Underline );
1236 if ( is->itemSet(KateAttribute::Outline) )
1238 if ( is->outline() != st->outline())
1239 st->setOutline( is->outline() );
1241 else st->clearAttribute( KateAttribute::Outline );
1243 if ( is->itemSet(KateAttribute::TextColor) )
1245 if ( is->textColor() != st->textColor())
1246 st->setTextColor( is->textColor() );
1248 else st->clearAttribute( KateAttribute::TextColor );
1250 if ( is->itemSet(KateAttribute::SelectedTextColor) )
1252 if ( is->selectedTextColor() != st->selectedTextColor())
1253 st->setSelectedTextColor( is->selectedTextColor() );
1255 else st->clearAttribute( KateAttribute::SelectedTextColor);
1257 if ( is->itemSet(KateAttribute::BGColor) )
1259 if ( is->bgColor() != st->bgColor())
1260 st->setBGColor( is->bgColor() );
1262 else st->clearAttribute( KateAttribute::BGColor );
1264 if ( is->itemSet(KateAttribute::SelectedBGColor) )
1266 if ( is->selectedBGColor() != st->selectedBGColor())
1267 st->setSelectedBGColor( is->selectedBGColor() );
1269 else st->clearAttribute( KateAttribute::SelectedBGColor );
1273 bool KateStyleListItem::defStyle() {
return st && st->itemsSet() != ds->itemsSet(); }
1276 bool KateStyleListItem::isDefault() {
return st ?
false :
true; }
1278 int KateStyleListItem::width(
const TQFontMetrics & ,
const TQListView * lv,
int col )
const
1280 int m = lv->itemMargin() * 2;
1285 return TQListViewItem::width( TQFontMetrics( ((KateStyleListView*)lv)->docfont), lv, col);
1294 return ColorBtnWidth +m;
1300 void KateStyleListItem::activate(
int column,
const TQPoint &localPos )
1302 TQListView *lv = listView();
1304 for(
int c = 0; c < column-1; c++ )
1305 x += lv->columnWidth( c );
1324 if ( !TQRect( x, 0, w, BoxSize ).contains( localPos ) )
1325 changeProperty( (Property)column );
1328 void KateStyleListItem::changeProperty( Property p )
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 )
1345 ((KateStyleListView*)listView())->emitChanged();
1348 void KateStyleListItem::toggleDefStyle()
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" );
1364 void KateStyleListItem::setColor(
int column )
1368 if ( column == Color)
1370 c = is->textColor();
1371 d = ds->textColor();
1373 else if ( column == SelColor )
1375 c = is->selectedTextColor();
1376 d = is->selectedTextColor();
1378 else if ( column == BgColor )
1383 else if ( column == SelBgColor )
1385 c = is->selectedBGColor();
1386 d = ds->selectedBGColor();
1391 bool def = ! c.isValid();
1401 if ( ds->itemSet(KateAttribute::TextColor) )
1402 is->setTextColor( ds->textColor());
1404 is->clearAttribute(KateAttribute::TextColor);
1407 is->setTextColor( c );
1412 if ( ds->itemSet(KateAttribute::SelectedTextColor) )
1413 is->setSelectedTextColor( ds->selectedTextColor());
1415 is->clearAttribute(KateAttribute::SelectedTextColor);
1418 is->setSelectedTextColor( c );
1423 if ( ds->itemSet(KateAttribute::BGColor) )
1424 is->setBGColor( ds->bgColor());
1426 is->clearAttribute(KateAttribute::BGColor);
1429 is->setBGColor( c );
1434 if ( ds->itemSet(KateAttribute::SelectedBGColor) )
1435 is->setSelectedBGColor( ds->selectedBGColor());
1437 is->clearAttribute(KateAttribute::SelectedBGColor);
1440 is->setSelectedBGColor( c );
1447 void KateStyleListItem::unsetColor(
int c )
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);
1456 void KateStyleListItem::paintCell( TQPainter *p,
const TQColorGroup& ,
int col,
int width,
int align )
1462 TQListView *lv = listView();
1468 TQColorGroup mcg = lv->viewport()->colorGroup();
1471 p->fillRect( 0, 0, width, height(), TQBrush( mcg.base() ) );
1473 int marg = lv->itemMargin();
1481 mcg.setColor(TQColorGroup::Text, is->textColor());
1482 mcg.setColor(TQColorGroup::HighlightedText, is->selectedTextColor());
1485 if ( c.isValid() && is->itemSet(KateAttribute::BGColor) )
1486 mcg.setColor( TQColorGroup::Base, c );
1487 if ( isSelected() && is->itemSet(KateAttribute::SelectedBGColor) )
1489 c = is->selectedBGColor();
1491 mcg.setColor( TQColorGroup::Highlight, c );
1493 TQFont f ( ((KateStyleListView*)lv)->docfont );
1494 p->setFont( is->font(f) );
1498 TQListViewItem::paintCell( p, mcg, col, width, align );
1510 int y = (height() - BoxSize) / 2;
1513 p->setPen( TQPen( mcg.text(), 2 ) );
1515 p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
1517 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
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 ) )
1526 TQPointArray a( 7*2 );
1530 for ( i=0; i<3; i++ ) {
1531 a.setPoint( 2*i, xx, yy );
1532 a.setPoint( 2*i+1, xx, 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 );
1541 p->drawLineSegments( a );
1553 c = is->textColor();
1554 set = is->itemSet(KateAttribute::TextColor);
1556 else if ( col == SelColor )
1558 c = is->selectedTextColor();
1559 set = is->itemSet( KateAttribute::SelectedTextColor);
1561 else if ( col == BgColor )
1563 set = is->itemSet(KateAttribute::BGColor);
1564 c = set ? is->bgColor() : mcg.base();
1566 else if ( col == SelBgColor )
1568 set = is->itemSet(KateAttribute::SelectedBGColor);
1569 c = set ? is->selectedBGColor(): mcg.base();
1574 int y = (height() - BoxSize) / 2;
1576 p->setPen( TQPen( mcg.text(), 2 ) );
1578 p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
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 ) );
1584 p->drawLine( x+marg-1, BoxSize-3, ColorBtnWidth-4, y+1 );
1592 KateStyleListCaption::KateStyleListCaption( TQListView *parent,
const TQString & name )
1593 : TQListViewItem( parent, name )
1597 void KateStyleListCaption::paintCell( TQPainter *p,
const TQColorGroup& ,
int col,
int width,
int align )
1599 TQListView *lv = listView();
1605 TQColorGroup mcg = lv->viewport()->colorGroup();
1607 TQListViewItem::paintCell( p, mcg, col, width, align );
The Attribute class incorporates all text decorations supported by Kate.
static TQColor baseColor()
static int getColor(TQColor &theColor, TQWidget *parent=0L)
kdbgstream kdDebug(int area=0)
static TQColor highlightColor()
static TQColor textColor()
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
const TDEShortcut & find()
static TQFont fixedFont()
kndbgstream & endl(kndbgstream &s)
TQString label(StdAccel id)
const TDEShortcut & reload()
static TQColor alternateBackgroundColor()