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