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 ()
161 TQString KateSchemaManager::printingSchema ()
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 * )
279 TQVGroupBox *gbTextArea =
new TQVGroupBox(i18n(
"Text Area Background"),
this);
281 b =
new TQHBox (gbTextArea);
283 label =
new TQLabel( i18n(
"Normal text:"), b);
284 label->setAlignment( AlignLeft|AlignVCenter);
287 b =
new TQHBox (gbTextArea);
289 label =
new TQLabel( i18n(
"Selected text:"), b);
290 label->setAlignment( AlignLeft|AlignVCenter);
293 b =
new TQHBox (gbTextArea);
295 label =
new TQLabel( i18n(
"Current line:"), b);
296 label->setAlignment( AlignLeft|AlignVCenter);
300 b =
new TQHBox (gbTextArea);
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, TQ_SIGNAL( activated(
int ) ), TQ_SLOT( slotComboBoxChanged(
int ) ) );
315 blay->addWidget(gbTextArea);
317 TQVGroupBox *gbBorder =
new TQVGroupBox(i18n(
"Additional Elements"),
this);
319 b =
new TQHBox (gbBorder);
321 label =
new TQLabel( i18n(
"Left border background:"), b);
322 label->setAlignment( AlignLeft|AlignVCenter);
325 b =
new TQHBox (gbBorder);
327 label =
new TQLabel( i18n(
"Line numbers:"), b);
328 label->setAlignment( AlignLeft|AlignVCenter);
331 b =
new TQHBox (gbBorder);
333 label =
new TQLabel( i18n(
"Bracket highlight:"), b);
334 label->setAlignment( AlignLeft|AlignVCenter);
337 b =
new TQHBox (gbBorder);
339 label =
new TQLabel( i18n(
"Word wrap markers:"), b);
340 label->setAlignment( AlignLeft|AlignVCenter);
343 b =
new TQHBox (gbBorder);
345 label =
new TQLabel( i18n(
"Tab markers:"), b);
346 label->setAlignment( AlignLeft|AlignVCenter);
349 blay->addWidget(gbBorder);
354 connect(
this, TQ_SIGNAL( changed() ), parent->parentWidget(), TQ_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( 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 & ) ) );
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] = TQt::yellow;
437 mark[3] = TQt::magenta;
439 mark[5] = TQt::green;
443 TDEConfig *config = KateFactory::self()->schemaManager()->schema(newSchema);
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);
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 , 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& ) ) );
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() );
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( 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& ) ) );
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 grid->addWidget( m_fontchooser, 0, 0);
547 connect (
this, TQ_SIGNAL( changed()), parent->parentWidget(), TQ_SLOT (slotChanged()));
551 KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
555 void KateSchemaConfigFontTab::slotFontSelected(
const TQFont &font )
559 m_fonts[m_schema] = font;
564 void KateSchemaConfigFontTab::apply()
566 FontMap::Iterator it;
567 for ( it = m_fonts.begin(); it != m_fonts.end(); ++it )
569 KateFactory::self()->schemaManager()->schema( it.key() )->writeEntry(
"Font", it.data() );
573 void KateSchemaConfigFontTab::schemaChanged(
int newSchema )
576 m_fonts[ m_schema ] = m_fontchooser->font();
578 m_schema = newSchema;
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 & )));
590 KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab( TQWidget *parent,
const char * )
593 m_defaultStyleLists.setAutoDelete(
true);
596 TQGridLayout *grid =
new TQGridLayout(
this, 1, 1 );
598 m_defaultStyles =
new KateStyleListView(
this,
false );
599 grid->addWidget( m_defaultStyles, 0, 0);
601 connect (m_defaultStyles, TQ_SIGNAL (changed()), parent->parentWidget(), TQ_SLOT (slotChanged()));
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 "
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.") );
612 KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab()
616 KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema)
618 if (!m_defaultStyleLists[schema])
620 KateAttributeList *list =
new KateAttributeList ();
621 KateHlManager::self()->getDefaults(schema, *list);
623 m_defaultStyleLists.insert (schema, list);
626 return m_defaultStyleLists[schema];
629 void KateSchemaConfigFontColorTab::schemaChanged (uint schema)
631 m_defaultStyles->clear ();
633 KateAttributeList *l = attributeList (schema);
636 TQPalette p ( m_defaultStyles->palette() );
638 p.setColor( TQColorGroup::Base,
639 KateFactory::self()->schemaManager()->schema(schema)->
640 readColorEntry(
"Color Background", &_c ) );
642 p.setColor( TQColorGroup::Highlight,
643 KateFactory::self()->schemaManager()->schema(schema)->
644 readColorEntry(
"Color Selection", &_c ) );
645 _c = l->at(0)->textColor();
646 p.setColor( TQColorGroup::Text, _c );
647 m_defaultStyles->viewport()->setPalette( p );
650 for (
int i = KateHlManager::self()->defaultStyles() - 1; i >= 0; i-- )
652 new KateStyleListItem( m_defaultStyles, KateHlManager::self()->defaultStyleName(i,
true), l->at( i ) );
656 void KateSchemaConfigFontColorTab::reload ()
658 m_defaultStyles->clear ();
659 m_defaultStyleLists.clear ();
662 void KateSchemaConfigFontColorTab::apply ()
664 for ( TQIntDictIterator<KateAttributeList> it( m_defaultStyleLists ); it.current(); ++it )
665 KateHlManager::self()->setDefaults(it.currentKey(), *(it.current()));
671 KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab( TQWidget *parent,
const char *, KateSchemaConfigFontColorTab *page, uint hl )
679 m_hlDict.setAutoDelete (
true);
684 TQHBox *hbHl =
new TQHBox(
this );
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)) );
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));
698 hlCombo->insertItem(KateHlManager::self()->hlNameTranslated(i));
700 hlCombo->setCurrentItem(0);
703 m_styles =
new KateStyleListView(
this,
true );
704 layout->addWidget (m_styles, 999);
706 hlCombo->setCurrentItem ( hl );
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><SPACE></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.") );
718 connect (m_styles, TQ_SIGNAL (changed()), parent->parentWidget(), TQ_SLOT (slotChanged()));
721 KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
725 void KateSchemaConfigHighlightTab::hlChanged(
int z)
729 schemaChanged (m_schema);
732 void KateSchemaConfigHighlightTab::schemaChanged (uint schema)
736 kdDebug(13030) <<
"NEW SCHEMA: " << m_schema <<
" NEW HL: " << m_hl <<
endl;
740 if (!m_hlDict[m_schema])
742 kdDebug(13030) <<
"NEW SCHEMA, create dict" <<
endl;
744 m_hlDict.insert (schema,
new TQIntDict<KateHlItemDataList>);
745 m_hlDict[m_schema]->setAutoDelete (
true);
748 if (!m_hlDict[m_schema]->
find(m_hl))
752 KateHlItemDataList *list =
new KateHlItemDataList ();
753 KateHlManager::self()->getHl( m_hl )->getKateHlItemDataListCopy (m_schema, *list);
754 m_hlDict[m_schema]->insert (m_hl, list);
757 KateAttributeList *l = m_defaults->attributeList (schema);
763 TQPalette p ( m_styles->palette() );
765 p.setColor( TQColorGroup::Base,
766 KateFactory::self()->schemaManager()->schema(m_schema)->
767 readColorEntry(
"Color Background", &_c ) );
769 p.setColor( TQColorGroup::Highlight,
770 KateFactory::self()->schemaManager()->schema(m_schema)->
771 readColorEntry(
"Color Selection", &_c ) );
772 _c = l->at(0)->textColor();
773 p.setColor( TQColorGroup::Text, _c );
774 m_styles->viewport()->setPalette( p );
776 TQDict<KateStyleListCaption> prefixes;
777 for ( KateHlItemData *itemData = m_hlDict[m_schema]->
find(m_hl)->last();
779 itemData = m_hlDict[m_schema]->find(m_hl)->prev())
781 kdDebug(13030) <<
"insert items " << itemData->name <<
endl;
785 int c = itemData->name.find(
':');
787 TQString prefix = itemData->name.left(c);
788 TQString
name = itemData->name.mid(c+1);
790 KateStyleListCaption *parent = prefixes.find( prefix );
793 parent =
new KateStyleListCaption( m_styles, prefix );
794 parent->setOpen(
true);
795 prefixes.insert( prefix, parent );
797 new KateStyleListItem( parent, name, l->at(itemData->defStyleNum), itemData );
799 new KateStyleListItem( m_styles, itemData->name, l->at(itemData->defStyleNum), itemData );
804 void KateSchemaConfigHighlightTab::reload ()
812 void KateSchemaConfigHighlightTab::apply ()
814 for ( TQIntDictIterator< TQIntDict<KateHlItemDataList> > it( m_hlDict ); it.current(); ++it )
815 for ( TQIntDictIterator< KateHlItemDataList > it2( *it.current() ); it2.current(); ++it2 )
817 KateHlManager::self()->getHl( it2.currentKey() )->setKateHlItemDataList (it.currentKey(), *(it2.current()));
824 KateSchemaConfigPage::KateSchemaConfigPage( TQWidget *parent, KateDocument *doc )
825 : KateConfigPage( parent ),
830 TQHBox *hbHl =
new TQHBox(
this );
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)) );
839 TQPushButton *btnnew =
new TQPushButton( i18n(
"&New..."), hbHl );
840 connect( btnnew, TQ_SIGNAL(clicked()),
this, TQ_SLOT(newSchema()) );
842 btndel =
new TQPushButton( i18n(
"&Delete"), hbHl );
843 connect( btndel, TQ_SIGNAL(clicked()),
this, TQ_SLOT(deleteSchema()) );
845 m_tabWidget =
new TQTabWidget (
this );
847 layout->add (m_tabWidget);
849 connect (m_tabWidget, TQ_SIGNAL (currentChanged (TQWidget *)),
this, TQ_SLOT (newCurrentPage (TQWidget *)));
851 m_colorTab =
new KateSchemaConfigColorTab (m_tabWidget);
852 m_tabWidget->addTab (m_colorTab, i18n(
"Colors"));
854 m_fontTab =
new KateSchemaConfigFontTab (m_tabWidget);
855 m_tabWidget->addTab (m_fontTab, i18n(
"Font"));
857 m_fontColorTab =
new KateSchemaConfigFontColorTab (m_tabWidget);
858 m_tabWidget->addTab (m_fontColorTab, i18n(
"Normal Text Styles"));
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"));
864 hbHl =
new TQHBox(
this );
868 defaultSchemaCombo =
new TQComboBox(
false, hbHl );
869 lHl->setBuddy( defaultSchemaCombo );
872 m_defaultSchema = (doc && doc->activeView()) ? doc->activeView()->renderer()->config()->schema() : KateRendererConfig::global()->schema();
876 connect( defaultSchemaCombo, TQ_SIGNAL(activated(
int)),
877 this, TQ_SLOT(slotChanged()) );
880 KateSchemaConfigPage::~KateSchemaConfigPage ()
883 KateFactory::self()->schemaManager()->update ();
886 void KateSchemaConfigPage::apply()
890 m_fontColorTab->apply ();
891 m_highlightTab->apply ();
894 KateFactory::self()->schemaManager()->schema (0)->sync();
896 KateFactory::self()->schemaManager()->update ();
899 for (
int i = 0; i < KateHlManager::self()->highlights(); ++i)
900 KateHlManager::self()->getHl (i)->clearAttributeArrays ();
903 KateRendererConfig::global()->setSchema (defaultSchemaCombo->currentItem());
904 KateRendererConfig::global()->reloadSchema();
907 KateHlManager::self()->getTDEConfig()->sync ();
910 void KateSchemaConfigPage::reload()
913 KateFactory::self()->schemaManager()->update ();
916 m_fontColorTab->reload ();
920 defaultSchemaCombo->setCurrentItem (KateRendererConfig::global()->schema());
923 schemaCombo->setCurrentItem( m_defaultSchema );
924 schemaChanged( m_defaultSchema );
927 void KateSchemaConfigPage::reset()
932 void KateSchemaConfigPage::defaults()
937 void KateSchemaConfigPage::update ()
940 KateFactory::self()->schemaManager()->update (
false);
942 schemaCombo->clear ();
943 schemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
945 defaultSchemaCombo->clear ();
946 defaultSchemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
948 schemaCombo->setCurrentItem (0);
951 schemaCombo->setEnabled (schemaCombo->count() > 0);
954 void KateSchemaConfigPage::deleteSchema ()
956 int t = schemaCombo->currentItem ();
958 KateFactory::self()->schemaManager()->removeSchema (t);
963 void KateSchemaConfigPage::newSchema ()
965 TQString t =
KInputDialog::getText (i18n(
"Name for New Schema"), i18n (
"Name:"), i18n(
"New Schema"), 0,
this);
967 KateFactory::self()->schemaManager()->addSchema (t);
970 KateFactory::self()->schemaManager()->update (
false);
971 int i = KateFactory::self()->schemaManager()->list ().findIndex (t);
976 schemaCombo->setCurrentItem (i);
981 void KateSchemaConfigPage::schemaChanged (
int schema)
983 btndel->setEnabled( schema > 1 );
985 m_colorTab->schemaChanged( schema );
986 m_fontTab->schemaChanged( schema );
987 m_fontColorTab->schemaChanged (schema);
988 m_highlightTab->schemaChanged (schema);
990 m_lastSchema = schema;
993 void KateSchemaConfigPage::newCurrentPage (TQWidget *w)
995 if (w == m_highlightTab)
996 m_highlightTab->schemaChanged (m_lastSchema);
1001 void KateViewSchemaAction::init()
1006 connect(popupMenu(),TQ_SIGNAL(aboutToShow()),
this,TQ_SLOT(slotAboutToShow()));
1009 void KateViewSchemaAction::updateMenu (KateView *view)
1014 void KateViewSchemaAction::slotAboutToShow()
1016 KateView *view=m_view;
1017 int count = KateFactory::self()->schemaManager()->list().count();
1019 for (
int z=0; z<count; z++)
1021 TQString hlName = KateFactory::self()->schemaManager()->list().operator[](z);
1023 if (names.contains(hlName) < 1)
1026 popupMenu()->insertItem ( hlName,
this, TQ_SLOT(setSchema(
int)), 0, z+1);
1032 popupMenu()->setItemChecked (last,
false);
1033 popupMenu()->setItemChecked (view->renderer()->config()->schema()+1,
true);
1035 last = view->renderer()->config()->schema()+1;
1038 void KateViewSchemaAction::setSchema (
int mode)
1040 KateView *view=m_view;
1043 view->renderer()->config()->setSchema (mode-1);
1048 KateStyleListView::KateStyleListView( TQWidget *parent,
bool showUseDefaults )
1049 : TQListView( parent )
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&)) );
1069 bgcol = KateRendererConfig::global()->backgroundColor();
1070 selcol = KateRendererConfig::global()->selectionColor();
1071 docfont = *KateRendererConfig::global()->font();
1073 viewport()->setPaletteBackgroundColor( bgcol );
1076 void KateStyleListView::showPopupMenu( KateStyleListItem *i,
const TQPoint &globalPos,
bool showtitle )
1078 if ( !
dynamic_cast<KateStyleListItem*
>(i) )
return;
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() );
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() );
1105 m.insertSeparator();
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 );
1117 if ( style->itemSet( KateAttribute::BGColor) || style->itemSet( KateAttribute::SelectedBGColor ) )
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 );
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() );
1131 m.exec( globalPos );
1134 void KateStyleListView::showPopupMenu( TQListViewItem *i,
const TQPoint &pos )
1136 if (
dynamic_cast<KateStyleListItem*
>(i) )
1137 showPopupMenu( (KateStyleListItem*)i, pos,
true );
1140 void KateStyleListView::mSlotPopupHandler(
int z )
1142 ((KateStyleListItem*)currentItem())->changeProperty( (KateStyleListItem::Property)z );
1145 void KateStyleListView::unsetColor(
int c )
1147 ((KateStyleListItem*)currentItem())->unsetColor( c );
1153 void KateStyleListView::slotMousePressed(
int btn, TQListViewItem* i,
const TQPoint& pos,
int c)
1155 if (
dynamic_cast<KateStyleListItem*
>(i) ) {
1156 if ( btn == TQt::LeftButton && c > 0 ) {
1158 ((KateStyleListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - TQPoint( 0, itemRect(i).top() ) );
1166 static const int BoxSize = 16;
1167 static const int ColorBtnWidth = 32;
1169 KateStyleListItem::KateStyleListItem( TQListViewItem *parent,
const TQString & stylename,
1171 : TQListViewItem( parent, stylename ),
1178 KateStyleListItem::KateStyleListItem( TQListView *parent,
const TQString & stylename,
1180 : TQListViewItem( parent, stylename ),
1187 void KateStyleListItem::initStyle()
1195 if (st->isSomethingSet())
1200 void KateStyleListItem::updateStyle()
1206 if ( is->itemSet(KateAttribute::Weight) )
1208 if ( is->weight() != st->weight())
1209 st->setWeight( is->weight() );
1211 else st->clearAttribute( KateAttribute::Weight );
1213 if ( is->itemSet(KateAttribute::Italic) )
1215 if ( is->italic() != st->italic())
1216 st->setItalic( is->italic() );
1218 else st->clearAttribute( KateAttribute::Italic );
1220 if ( is->itemSet(KateAttribute::StrikeOut) )
1222 if ( is->strikeOut() != st->strikeOut())
1224 st->setStrikeOut( is->strikeOut() );
1226 else st->clearAttribute( KateAttribute::StrikeOut );
1228 if ( is->itemSet(KateAttribute::Underline) )
1230 if ( is->underline() != st->underline())
1231 st->setUnderline( is->underline() );
1233 else st->clearAttribute( KateAttribute::Underline );
1235 if ( is->itemSet(KateAttribute::Outline) )
1237 if ( is->outline() != st->outline())
1238 st->setOutline( is->outline() );
1240 else st->clearAttribute( KateAttribute::Outline );
1242 if ( is->itemSet(KateAttribute::TextColor) )
1244 if ( is->textColor() != st->textColor())
1245 st->setTextColor( is->textColor() );
1247 else st->clearAttribute( KateAttribute::TextColor );
1249 if ( is->itemSet(KateAttribute::SelectedTextColor) )
1251 if ( is->selectedTextColor() != st->selectedTextColor())
1252 st->setSelectedTextColor( is->selectedTextColor() );
1254 else st->clearAttribute( KateAttribute::SelectedTextColor);
1256 if ( is->itemSet(KateAttribute::BGColor) )
1258 if ( is->bgColor() != st->bgColor())
1259 st->setBGColor( is->bgColor() );
1261 else st->clearAttribute( KateAttribute::BGColor );
1263 if ( is->itemSet(KateAttribute::SelectedBGColor) )
1265 if ( is->selectedBGColor() != st->selectedBGColor())
1266 st->setSelectedBGColor( is->selectedBGColor() );
1268 else st->clearAttribute( KateAttribute::SelectedBGColor );
1272 bool KateStyleListItem::defStyle() {
return st && st->itemsSet() != ds->itemsSet(); }
1275 bool KateStyleListItem::isDefault() {
return st ? false :
true; }
1277 int KateStyleListItem::width(
const TQFontMetrics & ,
const TQListView * lv,
int col )
const
1279 int m = lv->itemMargin() * 2;
1284 return TQListViewItem::width( TQFontMetrics( ((KateStyleListView*)lv)->docfont), lv, col);
1293 return ColorBtnWidth +m;
1299 void KateStyleListItem::activate(
int column,
const TQPoint &localPos )
1301 TQListView *lv = listView();
1303 for(
int c = 0; c < column-1; c++ )
1304 x += lv->columnWidth( c );
1323 if ( !TQRect( x, 0, w, BoxSize ).contains( localPos ) )
1324 changeProperty( (Property)column );
1327 void KateStyleListItem::changeProperty( Property p )
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 )
1344 ((KateStyleListView*)listView())->emitChanged();
1347 void KateStyleListItem::toggleDefStyle()
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" );
1363 void KateStyleListItem::setColor(
int column )
1367 if ( column == Color)
1369 c = is->textColor();
1370 d = ds->textColor();
1372 else if ( column == SelColor )
1374 c = is->selectedTextColor();
1375 d = is->selectedTextColor();
1377 else if ( column == BgColor )
1382 else if ( column == SelBgColor )
1384 c = is->selectedBGColor();
1385 d = ds->selectedBGColor();
1390 bool def = ! c.isValid();
1400 if ( ds->itemSet(KateAttribute::TextColor) )
1401 is->setTextColor( ds->textColor());
1403 is->clearAttribute(KateAttribute::TextColor);
1406 is->setTextColor( c );
1411 if ( ds->itemSet(KateAttribute::SelectedTextColor) )
1412 is->setSelectedTextColor( ds->selectedTextColor());
1414 is->clearAttribute(KateAttribute::SelectedTextColor);
1417 is->setSelectedTextColor( c );
1422 if ( ds->itemSet(KateAttribute::BGColor) )
1423 is->setBGColor( ds->bgColor());
1425 is->clearAttribute(KateAttribute::BGColor);
1428 is->setBGColor( c );
1433 if ( ds->itemSet(KateAttribute::SelectedBGColor) )
1434 is->setSelectedBGColor( ds->selectedBGColor());
1436 is->clearAttribute(KateAttribute::SelectedBGColor);
1439 is->setSelectedBGColor( c );
1446 void KateStyleListItem::unsetColor(
int c )
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);
1455 void KateStyleListItem::paintCell( TQPainter *p,
const TQColorGroup& ,
int col,
int width,
int align )
1461 TQListView *lv = listView();
1467 TQColorGroup mcg = lv->viewport()->colorGroup();
1470 p->fillRect( 0, 0, width, height(), TQBrush( mcg.base() ) );
1472 int marg = lv->itemMargin();
1480 mcg.setColor(TQColorGroup::Text, is->textColor());
1481 mcg.setColor(TQColorGroup::HighlightedText, is->selectedTextColor());
1484 if ( c.isValid() && is->itemSet(KateAttribute::BGColor) )
1485 mcg.setColor( TQColorGroup::Base, c );
1486 if ( isSelected() && is->itemSet(KateAttribute::SelectedBGColor) )
1488 c = is->selectedBGColor();
1490 mcg.setColor( TQColorGroup::Highlight, c );
1492 TQFont f ( ((KateStyleListView*)lv)->docfont );
1493 p->setFont( is->font(f) );
1497 TQListViewItem::paintCell( p, mcg, col, width, align );
1509 int y = (height() - BoxSize) / 2;
1512 p->setPen( TQPen( mcg.text(), 2 ) );
1514 p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
1516 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
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 ) )
1525 TQPointArray a( 7*2 );
1529 for ( i=0; i<3; i++ ) {
1530 a.setPoint( 2*i, xx, yy );
1531 a.setPoint( 2*i+1, xx, 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 );
1540 p->drawLineSegments( a );
1552 c = is->textColor();
1553 set = is->itemSet(KateAttribute::TextColor);
1555 else if ( col == SelColor )
1557 c = is->selectedTextColor();
1558 set = is->itemSet( KateAttribute::SelectedTextColor);
1560 else if ( col == BgColor )
1562 set = is->itemSet(KateAttribute::BGColor);
1563 c = set ? is->bgColor() : mcg.base();
1565 else if ( col == SelBgColor )
1567 set = is->itemSet(KateAttribute::SelectedBGColor);
1568 c = set ? is->selectedBGColor(): mcg.base();
1573 int y = (height() - BoxSize) / 2;
1575 p->setPen( TQPen( mcg.text(), 2 ) );
1577 p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
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 ) );
1583 p->drawLine( x+marg-1, BoxSize-3, ColorBtnWidth-4, y+1 );
1591 KateStyleListCaption::KateStyleListCaption( TQListView *parent,
const TQString & name )
1592 : TQListViewItem( parent,
name )
1596 void KateStyleListCaption::paintCell( TQPainter *p,
const TQColorGroup& ,
int col,
int width,
int align )
1598 TQListView *lv = listView();
1604 TQColorGroup mcg = lv->viewport()->colorGroup();
1606 TQListViewItem::paintCell( p, mcg, col, width, align );
static int getColor(TQColor &theColor, TQWidget *parent=0L)
static void information(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const TQString &dontShowAgainName=TQString::null, int options=Notify)
The Attribute class incorporates all text decorations supported by Kate.
const char * appName() const
static TDEApplication * kApplication()
TQColor readColorEntry(const TQString &pKey, const TQColor *pDefault=0L) const
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
void setGroup(const TQString &group)
static TQColor baseColor()
static TQColor highlightColor()
static TQFont fixedFont()
static TQColor alternateBackgroundColor()
static TQColor textColor()
const TDEAboutData * aboutData() const
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
TQString name(StdAccel id)
const TDEShortcut & find()
const TDEShortcut & reload()
TQString label(StdAccel id)