00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kateschema.h"
00022 #include "kateschema.moc"
00023
00024 #include "kateconfig.h"
00025 #include "katedocument.h"
00026 #include "kateglobal.h"
00027 #include "kateview.h"
00028 #include "katerenderer.h"
00029 #include "kateextendedattribute.h"
00030 #include "katestyletreewidget.h"
00031
00032 #include "ui_schemaconfigcolortab.h"
00033
00034 #include <kcolorscheme.h>
00035 #include <kcolorutils.h>
00036 #include <klocale.h>
00037 #include <kdialog.h>
00038 #include <kcolorbutton.h>
00039 #include <kcombobox.h>
00040 #include <kinputdialog.h>
00041 #include <kfontdialog.h>
00042 #include <kdebug.h>
00043 #include <kiconloader.h>
00044 #include <kmessagebox.h>
00045 #include <kmenu.h>
00046 #include <kcolordialog.h>
00047 #include <kapplication.h>
00048 #include <kaboutdata.h>
00049 #include <ktexteditor/markinterface.h>
00050 #include <khbox.h>
00051
00052 #include <QtGui/QCheckBox>
00053 #include <QtGui/QDialog>
00054 #include <QtGui/QLabel>
00055 #include <QtCore/QTextCodec>
00056 #include <QtGui/QLayout>
00057 #include <QtGui/QLineEdit>
00058 #include <QtGui/QPainter>
00059 #include <QtCore/QObject>
00060 #include <QtGui/QPixmap>
00061 #include <QtGui/QPushButton>
00062 #include <QtGui/QRadioButton>
00063 #include <QtGui/QSpinBox>
00064 #include <QtCore/QStringList>
00065 #include <QtGui/QTabWidget>
00066 #include <QtGui/QPolygon>
00067 #include <QtGui/QGroupBox>
00068 #include <QtGui/QTreeWidget>
00069
00070
00071
00072
00073 QString KateSchemaManager::normalSchema ()
00074 {
00075 return KGlobal::mainComponent().aboutData()->appName () + QString (" - Normal");
00076 }
00077
00078 QString KateSchemaManager::printingSchema ()
00079 {
00080 return KGlobal::mainComponent().aboutData()->appName () + QString (" - Printing");
00081 }
00082
00083 KateSchemaManager::KateSchemaManager ()
00084 : m_config ("kateschemarc", KConfig::NoGlobals)
00085 {
00086 update ();
00087 }
00088
00089 KateSchemaManager::~KateSchemaManager ()
00090 {
00091 }
00092
00093
00094
00095
00096 void KateSchemaManager::update (bool readfromfile)
00097 {
00098 if (readfromfile)
00099 m_config.reparseConfiguration ();
00100
00101 m_schemas = m_config.groupList();
00102 m_schemas.sort ();
00103
00104 m_schemas.removeAll (printingSchema());
00105 m_schemas.removeAll (normalSchema());
00106 m_schemas.prepend (printingSchema());
00107 m_schemas.prepend (normalSchema());
00108 }
00109
00110
00111
00112
00113
00114 KConfigGroup KateSchemaManager::schema (uint number)
00115 {
00116 if ((number>1) && (number < (uint)m_schemas.count()))
00117 return m_config.group (m_schemas[number]);
00118 else if (number == 1)
00119 return m_config.group (printingSchema());
00120 else
00121 return m_config.group (normalSchema());
00122 }
00123
00124 void KateSchemaManager::addSchema (const QString &t)
00125 {
00126 m_config.group(t).writeEntry("Color Background", KColorScheme(QPalette::Active, KColorScheme::View).background().color());
00127
00128 update (false);
00129 }
00130
00131 void KateSchemaManager::removeSchema (uint number)
00132 {
00133 if (number >= (uint)m_schemas.count())
00134 return;
00135
00136 if (number < 2)
00137 return;
00138
00139 m_config.deleteGroup (name (number));
00140
00141 update (false);
00142 }
00143
00144 bool KateSchemaManager::validSchema (uint number)
00145 {
00146 if (number < (uint)m_schemas.count())
00147 return true;
00148
00149 return false;
00150 }
00151
00152 bool KateSchemaManager::validSchema (const QString &name)
00153 {
00154 if (name == normalSchema() || name == printingSchema())
00155 return true;
00156
00157 for (int i = 0; i < m_schemas.size(); ++i)
00158 if (m_schemas[i] == name)
00159 return true;
00160
00161 return false;
00162 }
00163
00164 uint KateSchemaManager::number (const QString &name)
00165 {
00166 if (name == normalSchema())
00167 return 0;
00168
00169 if (name == printingSchema())
00170 return 1;
00171
00172 int i;
00173 if ((i = m_schemas.indexOf(name)) > -1)
00174 return i;
00175
00176 return 0;
00177 }
00178
00179 QString KateSchemaManager::name (uint number)
00180 {
00181 if ((number>1) && (number < (uint)m_schemas.count()))
00182 return m_schemas[number];
00183 else if (number == 1)
00184 return printingSchema();
00185
00186 return normalSchema();
00187 }
00188
00189
00190
00191
00192
00193
00194
00195 KateSchemaConfigColorTab::KateSchemaConfigColorTab()
00196 : ui(new Ui::SchemaConfigColorTab())
00197 {
00198 m_schema = -1;
00199
00200 ui->setupUi(this);
00201
00202
00203
00204 ui->combobox->addItem(i18n("Bookmark"));
00205 ui->combobox->addItem(i18n("Active Breakpoint"));
00206 ui->combobox->addItem(i18n("Reached Breakpoint"));
00207 ui->combobox->addItem(i18n("Disabled Breakpoint"));
00208 ui->combobox->addItem(i18n("Execution"));
00209 ui->combobox->addItem(i18n("Warning"));
00210 ui->combobox->addItem(i18n("Error"));
00211 ui->combobox->addItem(i18n("Template Background"));
00212 ui->combobox->addItem(i18n("Template Editable Placeholder"));
00213 ui->combobox->addItem(i18n("Template Focused Editable Placeholder"));
00214 ui->combobox->addItem(i18n("Template Not Editable Placeholder"));
00215 ui->combobox->setCurrentIndex(0);
00216
00217 connect( ui->combobox , SIGNAL( activated( int ) ) , SLOT( slotComboBoxChanged( int ) ) );
00218 connect( ui->back , SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00219 connect( ui->selected , SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00220 connect( ui->current , SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00221 connect( ui->bracket , SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00222 connect( ui->wwmarker , SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00223 connect( ui->iconborder, SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00224 connect( ui->tmarker , SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00225 connect( ui->linenumber, SIGNAL( changed( const QColor& ) ), SIGNAL( changed() ) );
00226 connect( ui->markers , SIGNAL( changed( const QColor& ) ), SLOT( slotMarkerColorChanged( const QColor& ) ) );
00227 }
00228
00229 KateSchemaConfigColorTab::~KateSchemaConfigColorTab()
00230 {
00231 delete ui;
00232 }
00233
00234 void KateSchemaConfigColorTab::schemaChanged ( int newSchema )
00235 {
00236
00237 if ( m_schema > -1 )
00238 {
00239 m_schemas[ m_schema ].back = ui->back->color();
00240 m_schemas[ m_schema ].selected = ui->selected->color();
00241 m_schemas[ m_schema ].current = ui->current->color();
00242 m_schemas[ m_schema ].bracket = ui->bracket->color();
00243 m_schemas[ m_schema ].wwmarker = ui->wwmarker->color();
00244 m_schemas[ m_schema ].iconborder = ui->iconborder->color();
00245 m_schemas[ m_schema ].tmarker = ui->tmarker->color();
00246 m_schemas[ m_schema ].linenumber = ui->linenumber->color();
00247 }
00248
00249 if ( newSchema == m_schema ) return;
00250
00251
00252 m_schema = newSchema;
00253
00254
00255 bool blocked = blockSignals(true);
00256
00257
00258 if ( ! m_schemas.contains( newSchema ) )
00259 {
00260
00261
00262 KColorScheme schemeView(QPalette::Active, KColorScheme::View);
00263 KColorScheme schemeWindow(QPalette::Active, KColorScheme::Window);
00264 KColorScheme schemeSelection(QPalette::Active, KColorScheme::Selection);
00265 QColor tmp0( schemeView.background().color() );
00266 QColor tmp1( schemeSelection.background().color() );
00267 QColor tmp2( schemeView.background(KColorScheme::AlternateBackground).color() );
00268
00269 qreal bgLuma = KColorUtils::luma( tmp0 );
00270 QColor tmp3( KColorUtils::tint(tmp0, schemeView.decoration(KColorScheme::HoverColor).color()) );
00271 QColor tmp4( KColorUtils::shade( tmp0, bgLuma > 0.3 ? -0.15 : 0.03 ) );
00272 QColor tmp5( KColorUtils::shade( tmp0, bgLuma > 0.7 ? -0.35 : 0.3 ) );
00273 QColor tmp6( schemeWindow.background().color() );
00274 QColor tmp7( schemeWindow.foreground().color() );
00275
00276
00277 QVector <QColor> mark(KTextEditor::MarkInterface::reservedMarkersCount());
00278 Q_ASSERT(mark.size() > 6);
00279 mark[0] = Qt::blue;
00280 mark[1] = Qt::red;
00281 mark[2] = Qt::yellow;
00282 mark[3] = Qt::magenta;
00283 mark[4] = Qt::gray;
00284 mark[5] = Qt::green;
00285 mark[6] = Qt::red;
00286
00287 SchemaColors c;
00288 KConfigGroup config = KateGlobal::self()->schemaManager()->schema(newSchema);
00289
00290 c.back= config.readEntry("Color Background", tmp0);
00291 c.selected = config.readEntry("Color Selection", tmp1);
00292 c.current = config.readEntry("Color Highlighted Line", tmp2);
00293 c.bracket = config.readEntry("Color Highlighted Bracket", tmp3);
00294 c.wwmarker = config.readEntry("Color Word Wrap Marker", tmp4);
00295 c.tmarker = config.readEntry("Color Tab Marker", tmp5);
00296 c.iconborder = config.readEntry("Color Icon Bar", tmp6);
00297 c.linenumber = config.readEntry("Color Line Number", tmp7);
00298
00299 for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
00300 c.markerColors[i] = config.readEntry( QString("Color MarkType%1").arg(i+1), mark[i] );
00301
00302 c.templateColors[0] = config.readEntry(QString("Color Template Background"),QColor(0xcc,0xcc,0xcc));
00303 c.templateColors[1] = config.readEntry(QString("Color Template Editable Placeholder"),QColor(0xcc,0xff,0xcc));
00304 c.templateColors[2] = config.readEntry(QString("Color Template Focused Editable Placeholder"),QColor(0x66,0xff,0x66));
00305 c.templateColors[3] = config.readEntry(QString("Color Template Not Editable Placeholder"),QColor(0xff,0xcc,0xcc));
00306
00307 m_schemas[ newSchema ] = c;
00308 }
00309
00310 ui->back->setColor( m_schemas[ newSchema ].back);
00311 ui->selected->setColor( m_schemas [ newSchema ].selected );
00312 ui->current->setColor( m_schemas [ newSchema ].current );
00313 ui->bracket->setColor( m_schemas [ newSchema ].bracket );
00314 ui->wwmarker->setColor( m_schemas [ newSchema ].wwmarker );
00315 ui->tmarker->setColor( m_schemas [ newSchema ].tmarker );
00316 ui->iconborder->setColor( m_schemas [ newSchema ].iconborder );
00317 ui->linenumber->setColor( m_schemas [ newSchema ].linenumber );
00318
00319
00320 for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
00321 {
00322 QPixmap pix(16, 16);
00323 pix.fill( m_schemas [ newSchema ].markerColors[i]);
00324 ui->combobox->setItemIcon(i, QIcon(pix));
00325 }
00326 for (int i = 0; i < 4; i++)
00327 {
00328 QPixmap pix(16, 16);
00329 pix.fill( m_schemas [ newSchema ].templateColors[i]);
00330 ui->combobox->setItemIcon(i+KTextEditor::MarkInterface::reservedMarkersCount(), QIcon(pix));
00331 }
00332
00333 ui->markers->setColor( m_schemas [ newSchema ].markerColors[ ui->combobox->currentIndex() ] );
00334
00335 blockSignals(blocked);
00336 }
00337
00338 void KateSchemaConfigColorTab::apply ()
00339 {
00340 schemaChanged( m_schema );
00341 QMap<int,SchemaColors>::Iterator it;
00342 for ( it = m_schemas.begin(); it != m_schemas.end(); ++it )
00343 {
00344 kDebug(13030)<<"APPLY scheme = "<<it.key();
00345 KConfigGroup config = KateGlobal::self()->schemaManager()->schema( it.key() );
00346 kDebug(13030)<<"Using config group "<<config.name();
00347 SchemaColors c = it.value();
00348
00349
00350
00351
00352 config.writeEntry("Color Background", c.back);
00353 config.writeEntry("Color Selection", c.selected);
00354 config.writeEntry("Color Highlighted Line", c.current);
00355 config.writeEntry("Color Highlighted Bracket", c.bracket);
00356 config.writeEntry("Color Word Wrap Marker", c.wwmarker);
00357 config.writeEntry("Color Tab Marker", c.tmarker);
00358 config.writeEntry("Color Icon Bar", c.iconborder);
00359 config.writeEntry("Color Line Number", c.linenumber);
00360
00361 for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
00362 {
00363 config.writeEntry(QString("Color MarkType%1").arg(i + 1), c.markerColors[i]);
00364 }
00365
00366 config.writeEntry(QString("Color Template Background"),c.templateColors[0]);
00367 config.writeEntry(QString("Color Template Editable Placeholder"),c.templateColors[1]);
00368 config.writeEntry(QString("Color Template Focused Editable Placeholder"),c.templateColors[2]);
00369 config.writeEntry(QString("Color Template Not Editable Placeholder"),c.templateColors[3]);
00370
00371 }
00372 }
00373
00374 void KateSchemaConfigColorTab::slotMarkerColorChanged( const QColor& color)
00375 {
00376 int index = ui->combobox->currentIndex();
00377 if (index<7)
00378 m_schemas[ m_schema ].markerColors[ index ] = color;
00379 else
00380 m_schemas[m_schema].templateColors[index-7] = color;
00381 QPixmap pix(16, 16);
00382 pix.fill(color);
00383 ui->combobox->setItemIcon(index, QIcon(pix));
00384
00385 emit changed();
00386 }
00387
00388 void KateSchemaConfigColorTab::slotComboBoxChanged(int index)
00389 {
00390
00391 bool blocked = ui->markers->blockSignals(true);
00392 if (index<7)
00393 ui->markers->setColor( m_schemas[m_schema].markerColors[index] );
00394 else
00395 ui->markers->setColor( m_schemas[m_schema].templateColors[index-7] );
00396 ui->markers->blockSignals(blocked);
00397 }
00398
00399
00400
00401
00402 KateSchemaConfigFontTab::KateSchemaConfigFontTab()
00403 {
00404
00405 QGridLayout *grid = new QGridLayout( this );
00406
00407 m_fontchooser = new KFontChooser ( this, false, QStringList(), false );
00408 grid->addWidget( m_fontchooser, 0, 0);
00409
00410 m_schema = -1;
00411 }
00412
00413 KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
00414 {
00415 }
00416
00417 void KateSchemaConfigFontTab::slotFontSelected( const QFont &font )
00418 {
00419 if ( m_schema > -1 )
00420 {
00421 m_fonts[m_schema] = font;
00422 emit changed();
00423 }
00424 }
00425
00426 void KateSchemaConfigFontTab::apply()
00427 {
00428 FontMap::Iterator it;
00429 for ( it = m_fonts.begin(); it != m_fonts.end(); ++it )
00430 {
00431 KateGlobal::self()->schemaManager()->schema( it.key() ).writeEntry( "Font", it.value() );
00432 }
00433 }
00434
00435 void KateSchemaConfigFontTab::schemaChanged( int newSchema )
00436 {
00437 if ( m_schema > -1 )
00438 m_fonts[ m_schema ] = m_fontchooser->font();
00439
00440 m_schema = newSchema;
00441
00442 QFont f (KGlobalSettings::fixedFont());
00443
00444 m_fontchooser->disconnect ( this );
00445 m_fontchooser->setFont ( KateGlobal::self()->schemaManager()->schema( newSchema ).readEntry("Font", f) );
00446 m_fonts[ newSchema ] = m_fontchooser->font();
00447 connect (m_fontchooser, SIGNAL (fontSelected( const QFont & )), this, SLOT (slotFontSelected( const QFont & )));
00448 }
00449
00450
00451
00452 KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab()
00453 {
00454
00455 QGridLayout *grid = new QGridLayout( this );
00456
00457 m_defaultStyles = new KateStyleTreeWidget( this );
00458 m_defaultStyles->setRootIsDecorated(false);
00459 connect(m_defaultStyles, SIGNAL(changed()), this, SIGNAL(changed()));
00460 grid->addWidget( m_defaultStyles, 0, 0);
00461
00462 m_defaultStyles->setWhatsThis(i18n(
00463 "<p>This list displays the default styles for the current schema and "
00464 "offers the means to edit them. The style name reflects the current "
00465 "style settings.</p>"
00466 "<p>To edit the colors, click the colored squares, or select the color "
00467 "to edit from the popup menu.</p><p>You can unset the Background and Selected "
00468 "Background colors from the popup menu when appropriate.</p>") );
00469 }
00470
00471 KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab()
00472 {
00473 qDeleteAll(m_defaultStyleLists);
00474 }
00475
00476 KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema)
00477 {
00478 if (!m_defaultStyleLists.contains(schema))
00479 {
00480 KateAttributeList *list = new KateAttributeList ();
00481 KateHlManager::self()->getDefaults(KateGlobal::self()->schemaManager()->name (schema), *list);
00482
00483 m_defaultStyleLists.insert (schema, list);
00484 }
00485
00486 return m_defaultStyleLists[schema];
00487 }
00488
00489 void KateSchemaConfigFontColorTab::schemaChanged (uint schema)
00490 {
00491 m_defaultStyles->clear ();
00492
00493 KateAttributeList *l = attributeList (schema);
00494
00495
00496 QPalette p ( m_defaultStyles->palette() );
00497 KColorScheme s ( QPalette::Active, KColorScheme::View );
00498 QColor _c ( s.background().color() );
00499 p.setColor( QPalette::Base,
00500 KateGlobal::self()->schemaManager()->schema(schema).
00501 readEntry( "Color Background", _c ) );
00502 _c = KColorScheme(QPalette::Active, KColorScheme::Selection).background().color();
00503 p.setColor( QPalette::Highlight,
00504 KateGlobal::self()->schemaManager()->schema(schema).
00505 readEntry( "Color Selection", _c ) );
00506 _c = l->at(0)->foreground().color();
00507 p.setColor( QPalette::Text, _c );
00508 m_defaultStyles->viewport()->setPalette( p );
00509
00510 for ( uint i = 0; i < KateHlManager::self()->defaultStyles(); i++ )
00511 {
00512 m_defaultStyles->addItem( KateHlManager::self()->defaultStyleName(i, true), l->at( i ) );
00513 }
00514 }
00515
00516 void KateSchemaConfigFontColorTab::reload ()
00517 {
00518 m_defaultStyles->clear ();
00519 qDeleteAll(m_defaultStyleLists);
00520 m_defaultStyleLists.clear ();
00521 }
00522
00523 void KateSchemaConfigFontColorTab::apply ()
00524 {
00525 QHashIterator<int,KateAttributeList*> it = m_defaultStyleLists;
00526 while (it.hasNext()) {
00527 it.next();
00528 KateHlManager::self()->setDefaults(KateGlobal::self()->schemaManager()->name (it.key()), *it.value());
00529 }
00530 }
00531
00532
00533
00534
00535 KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab(KateSchemaConfigFontColorTab *page, uint hl )
00536 {
00537 m_defaults = page;
00538
00539 m_schema = 0;
00540 m_hl = 0;
00541
00542 QVBoxLayout *layout = new QVBoxLayout(this);
00543 layout->setMargin(0);
00544 layout->setSpacing(KDialog::spacingHint());
00545
00546
00547 KHBox *hbHl = new KHBox( this );
00548 layout->addWidget (hbHl);
00549
00550 hbHl->setSpacing( KDialog::spacingHint() );
00551 QLabel *lHl = new QLabel( i18n("H&ighlight:"), hbHl );
00552 hlCombo = new QComboBox( hbHl );
00553 hlCombo->setEditable( false );
00554 lHl->setBuddy( hlCombo );
00555 connect( hlCombo, SIGNAL(activated(int)),
00556 this, SLOT(hlChanged(int)) );
00557
00558 for( int i = 0; i < KateHlManager::self()->highlights(); i++) {
00559 if (KateHlManager::self()->hlSection(i).length() > 0)
00560 hlCombo->addItem(KateHlManager::self()->hlSection(i) + QString ("/") + KateHlManager::self()->hlNameTranslated(i));
00561 else
00562 hlCombo->addItem(KateHlManager::self()->hlNameTranslated(i));
00563 }
00564 hlCombo->setCurrentIndex(0);
00565
00566
00567 m_styles = new KateStyleTreeWidget( this, true );
00568 connect(m_styles, SIGNAL(changed()), this, SIGNAL(changed()));
00569 layout->addWidget (m_styles, 999);
00570
00571 hlCombo->setCurrentIndex ( hl );
00572 hlChanged ( hl );
00573
00574 m_styles->setWhatsThis(i18n(
00575 "<p>This list displays the contexts of the current syntax highlight mode and "
00576 "offers the means to edit them. The context name reflects the current "
00577 "style settings.</p><p>To edit using the keyboard, press "
00578 "<strong><SPACE></strong> and choose a property from the popup menu.</p>"
00579 "<p>To edit the colors, click the colored squares, or select the color "
00580 "to edit from the popup menu.</p><p>You can unset the Background and Selected "
00581 "Background colors from the context menu when appropriate.</p>") );
00582 }
00583
00584 KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
00585 {
00586 }
00587
00588 void KateSchemaConfigHighlightTab::hlChanged(int z)
00589 {
00590 m_hl = z;
00591
00592 schemaChanged (m_schema);
00593 }
00594
00595 void KateSchemaConfigHighlightTab::schemaChanged (int schema)
00596 {
00597 m_schema = schema;
00598
00599 kDebug(13030) << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl;
00600
00601 m_styles->clear ();
00602
00603 if (!m_hlDict.contains(m_schema))
00604 {
00605 kDebug(13030) << "NEW SCHEMA, create dict";
00606
00607 m_hlDict.insert (schema, QHash<int, QList<KateExtendedAttribute::Ptr> >());
00608 }
00609
00610 if (!m_hlDict[m_schema].contains(m_hl))
00611 {
00612 kDebug(13030) << "NEW HL, create list";
00613
00614 QList<KateExtendedAttribute::Ptr> list;
00615 KateHlManager::self()->getHl( m_hl )->getKateExtendedAttributeListCopy(KateGlobal::self()->schemaManager()->name (m_schema), list);
00616 m_hlDict[m_schema].insert (m_hl, list);
00617 }
00618
00619 KateAttributeList *l = m_defaults->attributeList (schema);
00620
00621
00622
00623
00624
00625 QPalette p ( m_styles->palette() );
00626 KColorScheme s ( QPalette::Active, KColorScheme::View );
00627 QColor _c ( s.background().color() );
00628 p.setColor( QPalette::Base,
00629 KateGlobal::self()->schemaManager()->schema(m_schema).
00630 readEntry( "Color Background", _c ) );
00631 _c = KColorScheme(QPalette::Active, KColorScheme::Selection).background().color();
00632 p.setColor( QPalette::Highlight,
00633 KateGlobal::self()->schemaManager()->schema(m_schema).
00634 readEntry( "Color Selection", _c ) );
00635 _c = l->at(0)->foreground().color();
00636 p.setColor( QPalette::Text, _c );
00637 m_styles->viewport()->setPalette( p );
00638
00639 QHash<QString, QTreeWidgetItem*> prefixes;
00640 QList<KateExtendedAttribute::Ptr>::ConstIterator it = m_hlDict[m_schema][m_hl].begin();
00641 while (it != m_hlDict[m_schema][m_hl].end())
00642 {
00643 KateExtendedAttribute::Ptr itemData = *it;
00644 Q_ASSERT(itemData);
00645
00646 kDebug(13030) << "insert items " << itemData->name();
00647
00648
00649
00650 int c = itemData->name().indexOf(':');
00651 if ( c > 0 ) {
00652 QString prefix = itemData->name().left(c);
00653 QString name = itemData->name().mid(c+1);
00654
00655 QTreeWidgetItem *parent = prefixes[prefix];
00656 if ( ! parent )
00657 {
00658 parent = new QTreeWidgetItem( m_styles, QStringList() << prefix );
00659 m_styles->expandItem(parent);
00660 prefixes.insert( prefix, parent );
00661 }
00662 m_styles->addItem( parent, name, l->at(itemData->defaultStyleIndex()), itemData );
00663 } else {
00664 m_styles->addItem( itemData->name(), l->at(itemData->defaultStyleIndex()), itemData );
00665 }
00666 ++it;
00667 }
00668
00669 m_styles->resizeColumns();
00670 }
00671
00672 void KateSchemaConfigHighlightTab::reload ()
00673 {
00674 m_styles->clear ();
00675
00676 m_hlDict.clear ();
00677
00678 hlChanged (0);
00679 }
00680
00681 void KateSchemaConfigHighlightTab::apply ()
00682 {
00683 QMutableHashIterator<int, QHash<int, QList<KateExtendedAttribute::Ptr> > > it = m_hlDict;
00684 while (it.hasNext()) {
00685 it.next();
00686 QMutableHashIterator<int, QList<KateExtendedAttribute::Ptr> > it2 = it.value();
00687 while (it2.hasNext()) {
00688 it2.next();
00689 KateHlManager::self()->getHl( it2.key() )->setKateExtendedAttributeList (it.key(), it2.value());
00690 }
00691 }
00692 }
00693
00694
00695
00696
00697 KateSchemaConfigPage::KateSchemaConfigPage( QWidget *parent, KateDocument * )
00698 : KateConfigPage( parent ),
00699 m_lastSchema (-1)
00700 {
00701 QVBoxLayout *layout = new QVBoxLayout(this);
00702 layout->setMargin(0);
00703 layout->setSpacing(KDialog::spacingHint());
00704
00705 KHBox *hbHl = new KHBox( this );
00706 layout->addWidget(hbHl);
00707 hbHl->setSpacing( KDialog::spacingHint() );
00708 QLabel *lHl = new QLabel( i18n("&Schema:"), hbHl );
00709 schemaCombo = new QComboBox( hbHl );
00710 schemaCombo->setEditable( false );
00711 lHl->setBuddy( schemaCombo );
00712 connect( schemaCombo, SIGNAL(activated(int)),
00713 this, SLOT(schemaChanged(int)) );
00714
00715 QPushButton *btnnew = new QPushButton( i18n("&New..."), hbHl );
00716 connect( btnnew, SIGNAL(clicked()), this, SLOT(newSchema()) );
00717
00718 btndel = new QPushButton( i18n("&Delete"), hbHl );
00719 connect( btndel, SIGNAL(clicked()), this, SLOT(deleteSchema()) );
00720
00721 m_tabWidget = new QTabWidget ( this );
00722 layout->addWidget (m_tabWidget);
00723
00724 connect (m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT (newCurrentPage(int)));
00725
00726 m_colorTab = new KateSchemaConfigColorTab();
00727 m_tabWidget->addTab (m_colorTab, i18n("Colors"));
00728 connect(m_colorTab, SIGNAL(changed()), SLOT(slotChanged()));
00729
00730 m_fontTab = new KateSchemaConfigFontTab();
00731 m_tabWidget->addTab (m_fontTab, i18n("Font"));
00732 connect(m_fontTab, SIGNAL(changed()), SLOT(slotChanged()));
00733
00734 m_fontColorTab = new KateSchemaConfigFontColorTab();
00735 m_tabWidget->addTab (m_fontColorTab, i18n("Normal Text Styles"));
00736 connect(m_fontColorTab, SIGNAL(changed()), SLOT(slotChanged()));
00737
00738 m_highlightTab = new KateSchemaConfigHighlightTab(m_fontColorTab, 0 );
00739 m_tabWidget->addTab(m_highlightTab, i18n("Highlighting Text Styles"));
00740 connect(m_highlightTab, SIGNAL(changed()), SLOT(slotChanged()));
00741
00742 hbHl = new KHBox( this );
00743 layout->addWidget (hbHl);
00744 hbHl->setSpacing( KDialog::spacingHint() );
00745 lHl = new QLabel( i18n("&Default schema for %1:", KGlobal::mainComponent().aboutData()->programName ()), hbHl );
00746 defaultSchemaCombo = new QComboBox( hbHl );
00747 defaultSchemaCombo->setEditable( false );
00748 lHl->setBuddy( defaultSchemaCombo );
00749
00750 m_defaultSchema = KateGlobal::self()->schemaManager()->number (KateRendererConfig::global()->schema());
00751
00752 reload();
00753
00754 connect( defaultSchemaCombo, SIGNAL(activated(int)),
00755 this, SLOT(slotChanged()) );
00756 }
00757
00758 KateSchemaConfigPage::~KateSchemaConfigPage ()
00759 {
00760
00761 KateGlobal::self()->schemaManager()->update ();
00762 }
00763
00764 void KateSchemaConfigPage::apply()
00765 {
00766 m_colorTab->apply();
00767 m_fontTab->apply();
00768 m_fontColorTab->apply ();
00769 m_highlightTab->apply ();
00770
00771
00772 KateGlobal::self()->schemaManager()->schema (0).sync();
00773
00774 KateGlobal::self()->schemaManager()->update ();
00775
00776
00777 for (int i = 0; i < KateHlManager::self()->highlights(); ++i)
00778 KateHlManager::self()->getHl (i)->clearAttributeArrays();
00779
00780
00781 KateRendererConfig::global()->setSchema (KateGlobal::self()->schemaManager()->name (defaultSchemaCombo->currentIndex()));
00782 KateRendererConfig::global()->reloadSchema();
00783
00784
00785 KateHlManager::self()->getKConfig()->sync ();
00786 }
00787
00788 void KateSchemaConfigPage::reload()
00789 {
00790
00791 KateGlobal::self()->schemaManager()->update ();
00792
00793
00794 m_fontColorTab->reload ();
00795
00796 update ();
00797
00798 defaultSchemaCombo->setCurrentIndex (KateGlobal::self()->schemaManager()->number (KateRendererConfig::global()->schema()));
00799
00800
00801 schemaCombo->setCurrentIndex( m_defaultSchema );
00802 schemaChanged( m_defaultSchema );
00803 }
00804
00805 void KateSchemaConfigPage::reset()
00806 {
00807 reload ();
00808 }
00809
00810 void KateSchemaConfigPage::defaults()
00811 {
00812 reload ();
00813 }
00814
00815 void KateSchemaConfigPage::update ()
00816 {
00817
00818 KateGlobal::self()->schemaManager()->update (false);
00819
00820 schemaCombo->clear ();
00821 schemaCombo->addItems (KateGlobal::self()->schemaManager()->list ());
00822
00823 defaultSchemaCombo->clear ();
00824 defaultSchemaCombo->addItems (KateGlobal::self()->schemaManager()->list ());
00825
00826 schemaCombo->setCurrentIndex (0);
00827 schemaChanged (0);
00828
00829 schemaCombo->setEnabled (schemaCombo->count() > 0);
00830 }
00831
00832 void KateSchemaConfigPage::deleteSchema ()
00833 {
00834 int t = schemaCombo->currentIndex ();
00835
00836 KateGlobal::self()->schemaManager()->removeSchema (t);
00837
00838 update ();
00839 }
00840
00841 void KateSchemaConfigPage::newSchema ()
00842 {
00843 QString t = KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:"), i18n("New Schema"), 0, this);
00844
00845 KateGlobal::self()->schemaManager()->addSchema (t);
00846
00847
00848 KateGlobal::self()->schemaManager()->update (false);
00849 int i = KateGlobal::self()->schemaManager()->list ().indexOf (t);
00850
00851 update ();
00852 if (i > -1)
00853 {
00854 schemaCombo->setCurrentIndex (i);
00855 schemaChanged (i);
00856 }
00857 }
00858
00859 void KateSchemaConfigPage::schemaChanged (int schema)
00860 {
00861 btndel->setEnabled( schema > 1 );
00862
00863 m_colorTab->schemaChanged( schema );
00864 m_fontTab->schemaChanged( schema );
00865 m_fontColorTab->schemaChanged (schema);
00866 m_highlightTab->schemaChanged (schema);
00867
00868 m_lastSchema = schema;
00869 }
00870
00871 void KateSchemaConfigPage::newCurrentPage (int index)
00872 {
00873 QWidget *w = m_tabWidget->widget(index);
00874 if (w == m_highlightTab)
00875 m_highlightTab->schemaChanged (m_lastSchema);
00876 }
00877
00878
00879
00880 void KateViewSchemaAction::init()
00881 {
00882 m_group=0;
00883 m_view = 0;
00884 last = 0;
00885
00886 connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
00887 }
00888
00889 void KateViewSchemaAction::updateMenu (KateView *view)
00890 {
00891 m_view = view;
00892 }
00893
00894 void KateViewSchemaAction::slotAboutToShow()
00895 {
00896 KateView *view=m_view;
00897 int count = KateGlobal::self()->schemaManager()->list().count();
00898
00899 if (!m_group) {
00900 m_group=new QActionGroup(menu());
00901 m_group->setExclusive(true);
00902
00903 }
00904
00905 for (int z=0; z<count; z++)
00906 {
00907 QString hlName = KateGlobal::self()->schemaManager()->list().operator[](z);
00908
00909 if (!names.contains(hlName))
00910 {
00911 names << hlName;
00912 QAction *a=menu()->addAction ( hlName, this, SLOT(setSchema()));
00913 a->setData(hlName);
00914 a->setCheckable(true);
00915 a->setActionGroup(m_group);
00916
00917 }
00918 }
00919
00920 if (!view) return;
00921
00922 QString id=view->renderer()->config()->schema();
00923 foreach(QAction *a,menu()->actions()) {
00924 a->setChecked(a->data().toString()==id);
00925
00926 }
00927
00928 #if 0
00929 popupMenu()->setItemChecked (last, false);
00930 popupMenu()->setItemChecked (view->renderer()->config()->schema()+1, true);
00931
00932 last = view->renderer()->config()->schema()+1;
00933 #endif
00934 }
00935
00936 void KateViewSchemaAction::setSchema () {
00937 QAction *action = qobject_cast<QAction*>(sender());
00938
00939 if (!action) return;
00940 QString mode=action->data().toString();
00941
00942 KateView *view=m_view;
00943
00944 if (view)
00945 view->renderer()->config()->setSchema (mode);
00946 }
00947
00948
00949