00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kateschema.h"
00021 #include "kateschema.moc"
00022
00023 #include "kateconfig.h"
00024 #include "katefactory.h"
00025 #include "kateview.h"
00026 #include "katerenderer.h"
00027
00028 #include <klocale.h>
00029 #include <kdialog.h>
00030 #include <kcolorbutton.h>
00031 #include <kcombobox.h>
00032 #include <kinputdialog.h>
00033 #include <kfontdialog.h>
00034 #include <kdebug.h>
00035 #include <kiconloader.h>
00036 #include <kmessagebox.h>
00037 #include <kpopupmenu.h>
00038 #include <kcolordialog.h>
00039 #include <kapplication.h>
00040 #include <kaboutdata.h>
00041
00042 #include <qbuttongroup.h>
00043 #include <qcheckbox.h>
00044 #include <qptrcollection.h>
00045 #include <qdialog.h>
00046 #include <qgrid.h>
00047 #include <qgroupbox.h>
00048 #include <qlabel.h>
00049 #include <qtextcodec.h>
00050 #include <qlayout.h>
00051 #include <qlineedit.h>
00052 #include <qheader.h>
00053 #include <qlistbox.h>
00054 #include <qhbox.h>
00055 #include <qpainter.h>
00056 #include <qobjectlist.h>
00057 #include <qpushbutton.h>
00058 #include <qradiobutton.h>
00059 #include <qspinbox.h>
00060 #include <qstringlist.h>
00061 #include <qtabwidget.h>
00062 #include <qvbox.h>
00063 #include <qvgroupbox.h>
00064 #include <qwhatsthis.h>
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 class KateStyleListItem : public QListViewItem
00078 {
00079 public:
00080 KateStyleListItem( QListView *parent=0, const QString & stylename=0,
00081 class KateAttribute* defaultstyle=0, class ItemData *data=0 );
00082 ~KateStyleListItem() { if (st) delete is; };
00083
00084
00085 enum Property { ContextName, Bold, Italic, Underline, Strikeout, Color, SelColor, BgColor, SelBgColor, UseDefStyle };
00086
00087
00088 void updateStyle();
00089
00090 virtual int width ( const QFontMetrics & fm, const QListView * lv, int c ) const;
00091
00092 void activate( int column, const QPoint &localPos );
00093
00094 void changeProperty( Property p );
00095
00096 QString contextName() { return text(0); };
00097
00098 bool defStyle();
00099
00100 bool isDefault();
00101
00102
00103 class KateAttribute* style() { return is; };
00104
00105 protected:
00106
00107 void paintCell(QPainter *p, const QColorGroup& cg, int col, int width, int align);
00108
00109 private:
00110
00111 void toggleDefStyle();
00112 void setColor( int );
00113
00114
00115 void setCustStyle();
00116
00117 class KateAttribute *is,
00118 *ds;
00119 class ItemData *st;
00120 };
00121
00122 QString KateSchemaManager::normalSchema ()
00123 {
00124 return KApplication::kApplication()->aboutData()->appName () + QString (" - Normal");
00125 }
00126
00127 QString KateSchemaManager::printingSchema ()
00128 {
00129 return KApplication::kApplication()->aboutData()->appName () + QString (" - Printing");
00130 }
00131
00132 KateSchemaManager::KateSchemaManager ()
00133 : m_config ("kateschemarc", false, false)
00134 {
00135 update ();
00136 }
00137
00138 KateSchemaManager::~KateSchemaManager ()
00139 {
00140 }
00141
00142
00143
00144
00145 void KateSchemaManager::update (bool readfromfile)
00146 {
00147 if (readfromfile)
00148 m_config.reparseConfiguration ();
00149
00150 m_schemas = m_config.groupList();
00151 m_schemas.sort ();
00152
00153 m_schemas.remove (printingSchema());
00154 m_schemas.remove (normalSchema());
00155 m_schemas.prepend (printingSchema());
00156 m_schemas.prepend (normalSchema());
00157 }
00158
00159
00160
00161
00162
00163 KConfig *KateSchemaManager::schema (uint number)
00164 {
00165 if ((number>1) && (number < m_schemas.count()))
00166 m_config.setGroup (m_schemas[number]);
00167 else if (number == 1)
00168 m_config.setGroup (printingSchema());
00169 else
00170 m_config.setGroup (normalSchema());
00171
00172 return &m_config;
00173 }
00174
00175 void KateSchemaManager::addSchema (const QString &t)
00176 {
00177 m_config.setGroup (t);
00178 m_config.writeEntry("Color Background", KGlobalSettings::baseColor());
00179
00180 update (false);
00181 }
00182
00183 void KateSchemaManager::removeSchema (uint number)
00184 {
00185 if (number >= m_schemas.count())
00186 return;
00187
00188 if (number < 2)
00189 return;
00190
00191 m_config.deleteGroup (name (number));
00192
00193 update (false);
00194 }
00195
00196 bool KateSchemaManager::validSchema (uint number)
00197 {
00198 if (number < m_schemas.count())
00199 return true;
00200
00201 return false;
00202 }
00203
00204 uint KateSchemaManager::number (const QString &name)
00205 {
00206 if (name == normalSchema())
00207 return 0;
00208
00209 if (name == printingSchema())
00210 return 1;
00211
00212 int i;
00213 if ((i = m_schemas.findIndex(name)) > -1)
00214 return i;
00215
00216 return 0;
00217 }
00218
00219 QString KateSchemaManager::name (uint number)
00220 {
00221 if ((number>1) && (number < m_schemas.count()))
00222 return m_schemas[number];
00223 else if (number == 1)
00224 return printingSchema();
00225
00226 return normalSchema();
00227 }
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 KateSchemaConfigColorTab::KateSchemaConfigColorTab( QWidget *parent, const char * )
00238 : QWidget (parent)
00239 {
00240 QHBox *b;
00241 QLabel *label;
00242
00243 QVBoxLayout *blay=new QVBoxLayout(this, 0, KDialog::spacingHint());
00244
00245 QVGroupBox *gbTextArea = new QVGroupBox(i18n("Text Area Background"), this);
00246
00247 b = new QHBox (gbTextArea);
00248 label = new QLabel( i18n("Normal text:"), b);
00249 label->setAlignment( AlignLeft|AlignVCenter);
00250 m_back = new KColorButton(b);
00251 connect( m_back, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) );
00252
00253 b = new QHBox (gbTextArea);
00254 label = new QLabel( i18n("Selected text:"), b);
00255 label->setAlignment( AlignLeft|AlignVCenter);
00256 m_selected = new KColorButton(b);
00257 connect( m_selected, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) );
00258
00259 b = new QHBox (gbTextArea);
00260 label = new QLabel( i18n("Current line:"), b);
00261 label->setAlignment( AlignLeft|AlignVCenter);
00262 m_current = new KColorButton(b);
00263 connect( m_current, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) );
00264
00265 blay->addWidget(gbTextArea);
00266
00267 QVGroupBox *gbBorder = new QVGroupBox(i18n("Additional Elements"), this);
00268
00269 b = new QHBox (gbBorder);
00270 label = new QLabel( i18n("Left border background:"), b);
00271 label->setAlignment( AlignLeft|AlignVCenter);
00272 m_iconborder = new KColorButton(b);
00273 connect( m_iconborder, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) );
00274
00275 b = new QHBox (gbBorder);
00276 label = new QLabel( i18n("Bracket highlight:"), b);
00277 label->setAlignment( AlignLeft|AlignVCenter);
00278 m_bracket = new KColorButton(b);
00279 connect( m_bracket, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) );
00280
00281 b = new QHBox (gbBorder);
00282 label = new QLabel( i18n("Word wrap markers:"), b);
00283 label->setAlignment( AlignLeft|AlignVCenter);
00284 m_wwmarker = new KColorButton(b);
00285 connect( m_wwmarker, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) );
00286
00287 b = new QHBox (gbBorder);
00288 label = new QLabel( i18n("Tab markers:"), b);
00289 label->setAlignment( AlignLeft|AlignVCenter);
00290 m_tmarker = new KColorButton(b);
00291 connect( m_tmarker, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) );
00292
00293 blay->addWidget(gbBorder);
00294
00295 blay->addStretch();
00296
00297
00298 QWhatsThis::add(m_back, i18n("<p>Sets the background color of the editing area.</p>"));
00299 QWhatsThis::add(m_selected, i18n("<p>Sets the background color of the selection.</p>"
00300 "<p>To set the text color for selected text, use the \"<b>Configure "
00301 "Highlighting</b>\" dialog.</p>"));
00302 QWhatsThis::add(m_current, i18n("<p>Sets the background color of the currently "
00303 "active line, which means the line where your cursor is positioned.</p>"));
00304 QWhatsThis::add(m_bracket, i18n("<p>Sets the bracket matching color. This means, "
00305 "if you place the cursor e.g. at a <b>(</b>, the matching <b>)</b> will "
00306 "be highlighted with this color.</p>"));
00307 QWhatsThis::add(m_wwmarker, i18n(
00308 "<p>Sets the color of Word Wrap-related markers:</p>"
00309 "<dl><dt>Static Word Wrap</dt><dd>A vertical line which shows the column where "
00310 "text is going to be wrapped</dd>"
00311 "<dt>Dynamic Word Wrap</dt><dd>An arrow shown to the left of "
00312 "visually-wrapped lines</dd></dl>"));
00313 QWhatsThis::add(m_tmarker, i18n(
00314 "<p>Sets the color of the tabulator marks:</p>"));
00315 }
00316
00317 KateSchemaConfigColorTab::~KateSchemaConfigColorTab()
00318 {
00319 }
00320
00321 void KateSchemaConfigColorTab::readConfig (KConfig *config)
00322 {
00323 QColor tmp0 (KGlobalSettings::baseColor());
00324 QColor tmp1 (KGlobalSettings::highlightColor());
00325 QColor tmp2 (KGlobalSettings::alternateBackgroundColor());
00326 QColor tmp3 ( "#FFFF99" );
00327 QColor tmp4 (tmp2.dark());
00328 QColor tmp5 ( KGlobalSettings::textColor() );
00329 QColor tmp6 ( "#EAE9E8" );
00330
00331 m_back->setColor(config->readColorEntry("Color Background", &tmp0));
00332 m_selected->setColor(config->readColorEntry("Color Selection", &tmp1));
00333 m_current->setColor(config->readColorEntry("Color Highlighted Line", &tmp2));
00334 m_bracket->setColor(config->readColorEntry("Color Highlighted Bracket", &tmp3));
00335 m_wwmarker->setColor(config->readColorEntry("Color Word Wrap Marker", &tmp4));
00336 m_tmarker->setColor(config->readColorEntry("Color Tab Marker", &tmp5));
00337 m_iconborder->setColor(config->readColorEntry("Color Icon Bar", &tmp6));
00338 }
00339
00340 void KateSchemaConfigColorTab::writeConfig (KConfig *config)
00341 {
00342 config->writeEntry("Color Background", m_back->color());
00343 config->writeEntry("Color Selection", m_selected->color());
00344 config->writeEntry("Color Highlighted Line", m_current->color());
00345 config->writeEntry("Color Highlighted Bracket", m_bracket->color());
00346 config->writeEntry("Color Word Wrap Marker", m_wwmarker->color());
00347 config->writeEntry("Color Tab Marker", m_tmarker->color());
00348 config->writeEntry("Color Icon Bar", m_iconborder->color());
00349 }
00350
00351
00352
00353
00354 KateSchemaConfigFontTab::KateSchemaConfigFontTab( QWidget *parent, const char * )
00355 : QWidget (parent)
00356 {
00357
00358 QGridLayout *grid = new QGridLayout( this, 1, 1 );
00359
00360 m_fontchooser = new KFontChooser ( this, 0L, false, QStringList(), false );
00361 m_fontchooser->enableColumn(KFontChooser::StyleList, false);
00362 grid->addWidget( m_fontchooser, 0, 0);
00363
00364 connect (m_fontchooser, SIGNAL (fontSelected( const QFont & )), this, SLOT (slotFontSelected( const QFont & )));
00365 connect (m_fontchooser, SIGNAL (fontSelected( const QFont & )), parent->parentWidget(), SLOT (slotChanged()));
00366 }
00367
00368 KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
00369 {
00370 }
00371
00372 void KateSchemaConfigFontTab::slotFontSelected( const QFont &font )
00373 {
00374 myFont = font;
00375 }
00376
00377 void KateSchemaConfigFontTab::readConfig (KConfig *config)
00378 {
00379 QFont f (KGlobalSettings::fixedFont());
00380
00381 m_fontchooser->setFont (config->readFontEntry("Font", &f));
00382 }
00383
00384 void KateSchemaConfigFontTab::writeConfig (KConfig *config)
00385 {
00386 config->writeEntry("Font", myFont);
00387 }
00388
00389
00390
00391
00392 KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab( QWidget *parent, const char * )
00393 : QWidget (parent)
00394 {
00395 m_defaultStyleLists.setAutoDelete(true);
00396
00397
00398 QGridLayout *grid = new QGridLayout( this, 1, 1 );
00399
00400 m_defaultStyles = new KateStyleListView( this, false );
00401 grid->addWidget( m_defaultStyles, 0, 0);
00402
00403 connect (m_defaultStyles, SIGNAL (changed()), parent->parentWidget(), SLOT (slotChanged()));
00404 }
00405
00406 KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab()
00407 {
00408 }
00409
00410 KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema)
00411 {
00412 if (!m_defaultStyleLists[schema])
00413 {
00414 KateAttributeList *list = new KateAttributeList ();
00415 HlManager::self()->getDefaults(schema, *list);
00416
00417 m_defaultStyleLists.insert (schema, list);
00418 }
00419
00420 return m_defaultStyleLists[schema];
00421 }
00422
00423 void KateSchemaConfigFontColorTab::schemaChanged (uint schema)
00424 {
00425 m_defaultStyles->clear ();
00426
00427 KateAttributeList *l = attributeList (schema);
00428
00429
00430 QPalette p ( m_defaultStyles->palette() );
00431 QColor _c ( KGlobalSettings::baseColor() );
00432 p.setColor( QPalette::Normal, QColorGroup::Base,
00433 KateFactory::self()->schemaManager()->schema(schema)->
00434 readColorEntry( "Color Background", &_c ) );
00435 _c = KGlobalSettings::highlightColor();
00436 p.setColor( QPalette::Normal, QColorGroup::Highlight,
00437 KateFactory::self()->schemaManager()->schema(schema)->
00438 readColorEntry( "Color Selection", &_c ) );
00439 _c = l->at(0)->textColor();
00440 p.setColor( QPalette::Normal, QColorGroup::Text, _c );
00441 m_defaultStyles->viewport()->setPalette( p );
00442
00443 for ( uint i = 0; i < HlManager::self()->defaultStyles(); i++ )
00444 {
00445 m_defaultStyles->insertItem( new KateStyleListItem( m_defaultStyles, HlManager::self()->defaultStyleName(i),
00446 l->at( i ) ) );
00447 }
00448 }
00449
00450 void KateSchemaConfigFontColorTab::reload ()
00451 {
00452 m_defaultStyles->clear ();
00453 m_defaultStyleLists.clear ();
00454 }
00455
00456 void KateSchemaConfigFontColorTab::apply ()
00457 {
00458 for ( QIntDictIterator<KateAttributeList> it( m_defaultStyleLists ); it.current(); ++it )
00459 HlManager::self()->setDefaults(it.currentKey(), *(it.current()));
00460 }
00461
00462
00463
00464
00465 KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab( QWidget *parent, const char *, KateSchemaConfigFontColorTab *page )
00466 : QWidget (parent)
00467 {
00468 m_defaults = page;
00469
00470 m_schema = 0;
00471 m_hl = 0;
00472
00473 m_hlDict.setAutoDelete (true);
00474
00475 QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() );
00476
00477
00478 QHBox *hbHl = new QHBox( this );
00479 layout->add (hbHl);
00480
00481 hbHl->setSpacing( KDialog::spacingHint() );
00482 QLabel *lHl = new QLabel( i18n("H&ighlight:"), hbHl );
00483 hlCombo = new QComboBox( false, hbHl );
00484 lHl->setBuddy( hlCombo );
00485 connect( hlCombo, SIGNAL(activated(int)),
00486 this, SLOT(hlChanged(int)) );
00487
00488 for( int i = 0; i < HlManager::self()->highlights(); i++) {
00489 if (HlManager::self()->hlSection(i).length() > 0)
00490 hlCombo->insertItem(HlManager::self()->hlSection(i) + QString ("/") + HlManager::self()->hlName(i));
00491 else
00492 hlCombo->insertItem(HlManager::self()->hlName(i));
00493 }
00494 hlCombo->setCurrentItem(0);
00495
00496
00497 m_styles = new KateStyleListView( this, true );
00498 layout->addWidget (m_styles, 999);
00499
00500 hlCombo->setCurrentItem ( 0 );
00501 hlChanged ( 0 );
00502
00503 QWhatsThis::add( m_styles, i18n("This list displays the contexts of the current syntax highlight mode and offers the means to edit them. The context name reflects the current style settings.<p>To edit using the keyboard, press <strong><SPACE></strong> and choose a property from the popup menu.<p>To edit the colors, click the colored squares, or select the color to edit from the popup menu.") );
00504
00505 connect (m_styles, SIGNAL (changed()), parent->parentWidget(), SLOT (slotChanged()));
00506 }
00507
00508 KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
00509 {
00510 }
00511
00512 void KateSchemaConfigHighlightTab::hlChanged(int z)
00513 {
00514 m_hl = z;
00515
00516 schemaChanged (m_schema);
00517 }
00518
00519 void KateSchemaConfigHighlightTab::schemaChanged (uint schema)
00520 {
00521 m_schema = schema;
00522
00523 kdDebug () << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl << endl;
00524
00525 m_styles->clear ();
00526
00527 if (!m_hlDict[m_schema])
00528 {
00529 kdDebug () << "NEW SCHEMA, create dict" << endl;
00530
00531 m_hlDict.insert (schema, new QIntDict<ItemDataList>);
00532 m_hlDict[m_schema]->setAutoDelete (true);
00533 }
00534
00535 if (!m_hlDict[m_schema]->find(m_hl))
00536 {
00537 kdDebug () << "NEW HL, create list" << endl;
00538
00539 ItemDataList *list = new ItemDataList ();
00540 HlManager::self()->getHl( m_hl )->getItemDataListCopy (m_schema, *list);
00541 m_hlDict[m_schema]->insert (m_hl, list);
00542 }
00543
00544 KateAttributeList *l = m_defaults->attributeList (schema);
00545
00546
00547
00548
00549
00550 QPalette p ( m_styles->palette() );
00551 QColor _c ( KGlobalSettings::baseColor() );
00552 p.setColor( QPalette::Normal, QColorGroup::Base,
00553 KateFactory::self()->schemaManager()->schema(m_schema)->
00554 readColorEntry( "Color Background", &_c ) );
00555 _c = KGlobalSettings::highlightColor();
00556 p.setColor( QPalette::Normal, QColorGroup::Highlight,
00557 KateFactory::self()->schemaManager()->schema(m_schema)->
00558 readColorEntry( "Color Selection", &_c ) );
00559
00560 _c = m_hlDict[m_schema]->find(m_hl)->first()->textColor();
00561 if ( ! _c.isValid() )
00562 _c = l->at(0)->textColor();
00563 p.setColor( QPalette::Normal, QColorGroup::Text, _c );
00564 m_styles->viewport()->setPalette( p );
00565
00566
00567 for ( ItemData *itemData = m_hlDict[m_schema]->find(m_hl)->first();
00568 itemData != 0L;
00569 itemData = m_hlDict[m_schema]->find(m_hl)->next())
00570 {
00571 kdDebug () << "insert items " << itemData->name << endl;
00572
00573 m_styles->insertItem( new KateStyleListItem( m_styles, itemData->name,
00574 l->at(itemData->defStyleNum), itemData ) );
00575
00576 }
00577 }
00578
00579 void KateSchemaConfigHighlightTab::reload ()
00580 {
00581 m_styles->clear ();
00582 m_hlDict.clear ();
00583
00584 hlChanged (0);
00585 }
00586
00587 void KateSchemaConfigHighlightTab::apply ()
00588 {
00589 for ( QIntDictIterator< QIntDict<ItemDataList> > it( m_hlDict ); it.current(); ++it )
00590 for ( QIntDictIterator< ItemDataList > it2( *it.current() ); it2.current(); ++it2 )
00591 HlManager::self()->getHl( it2.currentKey() )->setItemDataList (it.currentKey(), *(it2.current()));
00592 }
00593
00594
00595
00596 KateSchemaConfigPage::KateSchemaConfigPage( QWidget *parent )
00597 : KateConfigPage( parent ),
00598 m_lastSchema (-1)
00599 {
00600 QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() );
00601
00602 QHBox *hbHl = new QHBox( this );
00603 layout->add (hbHl);
00604 hbHl->setSpacing( KDialog::spacingHint() );
00605 QLabel *lHl = new QLabel( i18n("&Schema:"), hbHl );
00606 schemaCombo = new QComboBox( false, hbHl );
00607 lHl->setBuddy( schemaCombo );
00608 connect( schemaCombo, SIGNAL(activated(int)),
00609 this, SLOT(schemaChanged(int)) );
00610
00611 btndel = new QPushButton( i18n("&Delete"), hbHl );
00612 connect( btndel, SIGNAL(clicked()), this, SLOT(deleteSchema()) );
00613
00614 QPushButton *btnnew = new QPushButton( i18n("&New..."), hbHl );
00615 connect( btnnew, SIGNAL(clicked()), this, SLOT(newSchema()) );
00616
00617 m_tabWidget = new QTabWidget ( this );
00618 m_tabWidget->setMargin (KDialog::marginHint());
00619 layout->add (m_tabWidget);
00620
00621 connect (m_tabWidget, SIGNAL (currentChanged (QWidget *)), this, SLOT (newCurrentPage (QWidget *)));
00622
00623 m_colorTab = new KateSchemaConfigColorTab (m_tabWidget);
00624 m_tabWidget->addTab (m_colorTab, i18n("Colors"));
00625
00626 m_fontTab = new KateSchemaConfigFontTab (m_tabWidget);
00627 m_tabWidget->addTab (m_fontTab, i18n("Font"));
00628
00629 m_fontColorTab = new KateSchemaConfigFontColorTab (m_tabWidget);
00630 m_tabWidget->addTab (m_fontColorTab, i18n("Normal Text Styles"));
00631
00632 m_highlightTab = new KateSchemaConfigHighlightTab (m_tabWidget, "", m_fontColorTab);
00633 m_tabWidget->addTab (m_highlightTab, i18n("Highlighting Text Styles"));
00634
00635 hbHl = new QHBox( this );
00636 layout->add (hbHl);
00637 hbHl->setSpacing( KDialog::spacingHint() );
00638 lHl = new QLabel( i18n("&Default schema for %1:").arg(KApplication::kApplication()->aboutData()->programName ()), hbHl );
00639 defaultSchemaCombo = new QComboBox( false, hbHl );
00640 lHl->setBuddy( defaultSchemaCombo );
00641
00642 reload();
00643
00644 connect( defaultSchemaCombo, SIGNAL(activated(int)),
00645 this, SLOT(slotChanged()) );
00646 }
00647
00648 KateSchemaConfigPage::~KateSchemaConfigPage ()
00649 {
00650
00651 KateFactory::self()->schemaManager()->update ();
00652 }
00653
00654 void KateSchemaConfigPage::apply()
00655 {
00656 if (m_lastSchema > -1)
00657 {
00658 m_colorTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema));
00659 m_fontTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema));
00660 }
00661
00662
00663 KateFactory::self()->schemaManager()->schema (0)->sync();
00664 KateFactory::self()->schemaManager()->update ();
00665
00666 KateRendererConfig::global()->setSchema (defaultSchemaCombo->currentItem());
00667
00668
00669 m_fontColorTab->apply ();
00670 m_highlightTab->apply ();
00671
00672
00673 HlManager::self()->getKConfig()->sync ();
00674 }
00675
00676 void KateSchemaConfigPage::reload()
00677 {
00678
00679 KateFactory::self()->schemaManager()->update ();
00680
00681
00682 m_fontColorTab->reload ();
00683
00684 update ();
00685
00686 defaultSchemaCombo->setCurrentItem (KateRendererConfig::global()->schema());
00687 }
00688
00689 void KateSchemaConfigPage::reset()
00690 {
00691 reload ();
00692 }
00693
00694 void KateSchemaConfigPage::defaults()
00695 {
00696 reload ();
00697 }
00698
00699 void KateSchemaConfigPage::update ()
00700 {
00701
00702 KateFactory::self()->schemaManager()->update (false);
00703
00704 schemaCombo->clear ();
00705 schemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
00706
00707 defaultSchemaCombo->clear ();
00708 defaultSchemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
00709
00710 schemaCombo->setCurrentItem (0);
00711 schemaChanged (0);
00712
00713 schemaCombo->setEnabled (schemaCombo->count() > 0);
00714 }
00715
00716 void KateSchemaConfigPage::deleteSchema ()
00717 {
00718 int t = schemaCombo->currentItem ();
00719
00720 KateFactory::self()->schemaManager()->removeSchema (t);
00721
00722 update ();
00723 }
00724
00725 void KateSchemaConfigPage::newSchema ()
00726 {
00727 QString t = KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:"), i18n("New Schema"), 0, this);
00728
00729 KateFactory::self()->schemaManager()->addSchema (t);
00730
00731
00732 KateFactory::self()->schemaManager()->update (false);
00733 int i = KateFactory::self()->schemaManager()->list ().findIndex (t);
00734
00735 update ();
00736 if (i > -1)
00737 {
00738 schemaCombo->setCurrentItem (i);
00739 schemaChanged (i);
00740 }
00741 }
00742
00743 void KateSchemaConfigPage::schemaChanged (int schema)
00744 {
00745 if (schema < 2)
00746 {
00747 btndel->setEnabled (false);
00748 }
00749 else
00750 {
00751 btndel->setEnabled (true);
00752 }
00753
00754 if (m_lastSchema > -1)
00755 {
00756 m_colorTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema));
00757 m_fontTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema));
00758 }
00759
00760 m_colorTab->readConfig (KateFactory::self()->schemaManager()->schema(schema));
00761 m_fontTab->readConfig (KateFactory::self()->schemaManager()->schema(schema));
00762 m_fontColorTab->schemaChanged (schema);
00763 m_highlightTab->schemaChanged (schema);
00764
00765 m_lastSchema = schema;
00766 }
00767
00768 void KateSchemaConfigPage::newCurrentPage (QWidget *w)
00769 {
00770 if (w == m_highlightTab)
00771 m_highlightTab->schemaChanged (m_lastSchema);
00772 }
00773
00774
00775 void KateViewSchemaAction::init()
00776 {
00777 m_view = 0;
00778 last = 0;
00779
00780 connect(popupMenu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
00781 }
00782
00783 void KateViewSchemaAction::updateMenu (KateView *view)
00784 {
00785 m_view = view;
00786 }
00787
00788 void KateViewSchemaAction::slotAboutToShow()
00789 {
00790 KateView *view=m_view;
00791 int count = KateFactory::self()->schemaManager()->list().count();
00792
00793 for (int z=0; z<count; z++)
00794 {
00795 QString hlName = KateFactory::self()->schemaManager()->list().operator[](z);
00796
00797 if (names.contains(hlName) < 1)
00798 {
00799 names << hlName;
00800 popupMenu()->insertItem ( hlName, this, SLOT(setSchema(int)), 0, z+1);
00801 }
00802 }
00803
00804 if (!view) return;
00805
00806 popupMenu()->setItemChecked (last, false);
00807 popupMenu()->setItemChecked (view->renderer()->config()->schema()+1, true);
00808
00809 last = view->renderer()->config()->schema()+1;
00810 }
00811
00812 void KateViewSchemaAction::setSchema (int mode)
00813 {
00814 KateView *view=m_view;
00815
00816 if (view)
00817 view->renderer()->config()->setSchema (mode-1);
00818 }
00819
00820
00821
00822 KateStyleListView::KateStyleListView( QWidget *parent, bool showUseDefaults )
00823 : QListView( parent )
00824 {
00825 addColumn( i18n("Context") );
00826 addColumn( SmallIconSet("text_bold"), QString::null );
00827 addColumn( SmallIconSet("text_italic"), QString::null );
00828 addColumn( SmallIconSet("text_under"), QString::null );
00829 addColumn( SmallIconSet("text_strike"), QString::null );
00830 addColumn( i18n("Normal") );
00831 addColumn( i18n("Selected") );
00832 addColumn( i18n("Background") );
00833 addColumn( i18n("Background Selected") );
00834 if ( showUseDefaults )
00835 addColumn( i18n("Use Default Style") );
00836 connect( this, SIGNAL(mouseButtonPressed(int, QListViewItem*, const QPoint&, int)),
00837 this, SLOT(slotMousePressed(int, QListViewItem*, const QPoint&, int)) );
00838 connect( this, SIGNAL(spacePressed(QListViewItem*)),
00839 this, SLOT(showPopupMenu(QListViewItem*)) );
00840
00841 normalcol = KGlobalSettings::textColor();
00842 bgcol = *KateRendererConfig::global()->backgroundColor();
00843 selcol = *KateRendererConfig::global()->selectionColor();
00844 docfont = *KateRendererConfig::global()->font();
00845
00846 viewport()->setPaletteBackgroundColor( bgcol );
00847 }
00848
00849 void KateStyleListView::showPopupMenu( KateStyleListItem *i, const QPoint &globalPos, bool showtitle )
00850 {
00851 KPopupMenu m( this );
00852 KateAttribute *is = i->style();
00853 int id;
00854
00855
00856 QPixmap cl(16,16);
00857 cl.fill( i->style()->textColor() );
00858 QPixmap scl(16,16);
00859 scl.fill( i->style()->selectedTextColor() );
00860 if ( showtitle )
00861 m.insertTitle( i->contextName(), KateStyleListItem::ContextName );
00862 id = m.insertItem( i18n("&Bold"), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Bold );
00863 m.setItemChecked( id, is->bold() );
00864 id = m.insertItem( i18n("&Italic"), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Italic );
00865 m.setItemChecked( id, is->italic() );
00866 m.insertItem( QIconSet(cl), i18n("Normal &Color..."), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Color );
00867 m.insertItem( QIconSet(scl), i18n("&Selected Color..."), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelColor );
00868 if ( ! i->isDefault() ) {
00869 id = m.insertItem( i18n("Use &Default Style"), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::UseDefStyle );
00870 m.setItemChecked( id, i->defStyle() );
00871 }
00872 m.exec( globalPos );
00873 }
00874
00875 void KateStyleListView::showPopupMenu( QListViewItem *i )
00876 {
00877 showPopupMenu( (KateStyleListItem*)i, viewport()->mapToGlobal(itemRect(i).topLeft()), true );
00878 }
00879
00880 void KateStyleListView::mSlotPopupHandler( int z )
00881 {
00882 ((KateStyleListItem*)currentItem())->changeProperty( (KateStyleListItem::Property)z );
00883 }
00884
00885
00886
00887 void KateStyleListView::slotMousePressed(int btn, QListViewItem* i, const QPoint& pos, int c)
00888 {
00889 if ( i ) {
00890 if ( btn == Qt::RightButton ) {
00891 showPopupMenu( (KateStyleListItem*)i, pos );
00892 }
00893 else if ( btn == Qt::LeftButton && c > 0 ) {
00894
00895 ((KateStyleListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - QPoint( 0, itemRect(i).top() ) );
00896 }
00897 }
00898 }
00899
00900
00901
00902
00903 static const int BoxSize = 16;
00904 static const int ColorBtnWidth = 32;
00905
00906 KateStyleListItem::KateStyleListItem( QListView *parent, const QString & stylename,
00907 KateAttribute *style, ItemData *data )
00908 : QListViewItem( parent, stylename ),
00909 ds( style ),
00910 st( data )
00911 {
00912 if (!st)
00913 is = ds;
00914 else
00915 {
00916 is = new KateAttribute (*style);
00917
00918 if (data->isSomethingSet())
00919 *is += *data;
00920 }
00921 }
00922
00923 void KateStyleListItem::updateStyle()
00924 {
00925
00926 if (!st)
00927 return;
00928
00929 if ( is->itemSet(KateAttribute::Weight) )
00930 {
00931 if ( is->weight() != st->weight())
00932 st->setWeight( is->weight() );
00933 }
00934
00935 if ( is->itemSet(KateAttribute::Italic) )
00936 {
00937 if ( is->italic() != st->italic())
00938 st->setItalic( is->italic() );
00939 }
00940
00941 if ( is->itemSet(KateAttribute::StrikeOut) )
00942 {
00943 if ( is->strikeOut() != st->strikeOut())
00944
00945 st->setStrikeOut( is->strikeOut() );
00946 }
00947
00948 if ( is->itemSet(KateAttribute::Underline) )
00949 {
00950 if ( is->underline() != st->underline())
00951 st->setUnderline( is->underline() );
00952 }
00953
00954 if ( is->itemSet(KateAttribute::Outline) )
00955 {
00956 if ( is->outline() != st->outline())
00957 st->setOutline( is->outline() );
00958 }
00959
00960 if ( is->itemSet(KateAttribute::TextColor) )
00961 {
00962 if ( is->textColor() != st->textColor())
00963 st->setTextColor( is->textColor() );
00964 }
00965
00966 if ( is->itemSet(KateAttribute::SelectedTextColor) )
00967 {
00968 if ( is->selectedTextColor() != st->selectedTextColor())
00969 st->setSelectedTextColor( is->selectedTextColor() );
00970 }
00971
00972 if ( is->itemSet(KateAttribute::BGColor) )
00973 {
00974 if ( is->bgColor() != st->bgColor())
00975 st->setBGColor( is->bgColor() );
00976 }
00977
00978 if ( is->itemSet(KateAttribute::SelectedBGColor) )
00979 {
00980 if ( is->selectedBGColor() != st->selectedBGColor())
00981 st->setSelectedBGColor( is->selectedBGColor() );
00982 }
00983
00984
00985 }
00986
00987
00988 bool KateStyleListItem::defStyle() { return st && st->isSomethingSet(); }
00989
00990
00991 bool KateStyleListItem::isDefault() { return st ? false : true; }
00992
00993 int KateStyleListItem::width( const QFontMetrics & , const QListView * lv, int col ) const
00994 {
00995 int m = lv->itemMargin() * 2;
00996 switch ( col ) {
00997 case ContextName:
00998
00999
01000 return QFontMetrics( ((KateStyleListView*)lv)->docfont).width( text(0) ) + m;
01001 case Bold:
01002 case Italic:
01003 case UseDefStyle:
01004 return BoxSize + m;
01005 case Color:
01006 case SelColor:
01007 case BgColor:
01008 case SelBgColor:
01009 return ColorBtnWidth +m;
01010 default:
01011 return 0;
01012 }
01013 }
01014
01015 void KateStyleListItem::activate( int column, const QPoint &localPos )
01016 {
01017 QListView *lv = listView();
01018 int x = 0;
01019 for( int c = 0; c < column-1; c++ )
01020 x += lv->columnWidth( c );
01021 int w;
01022 switch( column ) {
01023 case Bold:
01024 case Italic:
01025 case Underline:
01026 case Strikeout:
01027 case UseDefStyle:
01028 w = BoxSize;
01029 break;
01030 case Color:
01031 case SelColor:
01032 case BgColor:
01033 case SelBgColor:
01034 w = ColorBtnWidth;
01035 break;
01036 default:
01037 return;
01038 }
01039 if ( !QRect( x, 0, w, BoxSize ).contains( localPos ) )
01040 changeProperty( (Property)column );
01041 }
01042
01043 void KateStyleListItem::changeProperty( Property p )
01044 {
01045 if ( p == Bold )
01046 is->setBold( ! is->bold() );
01047 else if ( p == Italic )
01048 is->setItalic( ! is->italic() );
01049 else if ( p == Underline )
01050 is->setUnderline( ! is->underline() );
01051 else if ( p == Strikeout )
01052 is->setStrikeOut( ! is->strikeOut() );
01053 else if ( p == UseDefStyle )
01054 toggleDefStyle();
01055 else
01056 setColor( p );
01057
01058 updateStyle ();
01059
01060 ((KateStyleListView*)listView())->emitChanged();
01061 }
01062
01063 void KateStyleListItem::toggleDefStyle()
01064 {
01065 if ( *is == *ds ) {
01066 KMessageBox::information( listView(),
01067 i18n("\"Use Default Style\" will be automatically unset when you change any style properties."),
01068 i18n("Kate Styles"),
01069 "Kate hl config use defaults" );
01070 }
01071 else {
01072 delete is;
01073 is = new KateAttribute( *ds );
01074 repaint();
01075 }
01076 }
01077
01078 void KateStyleListItem::setColor( int column )
01079 {
01080 QColor c;
01081 if ( column == Color) c = is->textColor();
01082 else if ( column == SelColor ) c = is->selectedTextColor();
01083 else if ( column == BgColor ) c = is->bgColor();
01084 else if ( column == SelBgColor ) c = is->selectedBGColor();
01085
01086 if ( KColorDialog::getColor( c, listView() ) != QDialog::Accepted) return;
01087
01088
01089
01090 if ( column == Color) is->setTextColor( c );
01091 else if ( column == SelColor ) is->setSelectedTextColor( c );
01092 else if ( column == BgColor ) is->setBGColor( c );
01093 else if ( column == SelBgColor ) is->setSelectedBGColor( c );
01094
01095 repaint();
01096 }
01097
01098 void KateStyleListItem::setCustStyle()
01099 {
01100
01101
01102
01103 }
01104
01105 void KateStyleListItem::paintCell( QPainter *p, const QColorGroup& , int col, int width, int align )
01106 {
01107
01108 if ( !p )
01109 return;
01110
01111 QListView *lv = listView();
01112 if ( !lv )
01113 return;
01114 Q_ASSERT( lv );
01115
01116 p->fillRect( 0, 0, width, height(), QBrush( ((KateStyleListView*)lv)->bgcol ) );
01117
01118
01119 QColorGroup mcg = lv->viewport()->colorGroup();
01120
01121 if ( col )
01122 p->fillRect( 0, 0, width, height(), QBrush( mcg.base() ) );
01123
01124
01125 int marg = lv->itemMargin();
01126
01127 QColor c;
01128
01129 switch ( col )
01130 {
01131 case ContextName:
01132 {
01133 mcg.setColor(QColorGroup::Text, is->textColor());
01134 mcg.setColor(QColorGroup::HighlightedText, is->selectedTextColor());
01135
01136 c = is->bgColor();
01137 if ( c.isValid() )
01138 mcg.setColor( QColorGroup::Base, c );
01139 if ( isSelected() )
01140 {
01141 c = is->selectedBGColor();
01142 if ( c.isValid() )
01143 mcg.setColor( QColorGroup::Highlight, c );
01144 }
01145 QFont f ( ((KateStyleListView*)lv)->docfont );
01146 p->setFont( is->font(f) );
01147
01148
01149 QListViewItem::paintCell( p, mcg, col, width, align );
01150 }
01151 break;
01152 case Bold:
01153 case Italic:
01154 case Underline:
01155 case Strikeout:
01156 case UseDefStyle:
01157 {
01158
01159
01160 int x = 0;
01161 if ( align == AlignCenter ) {
01162 QFontMetrics fm( lv->font() );
01163 x = (width - BoxSize - fm.width(text(0)))/2;
01164 }
01165 int y = (height() - BoxSize) / 2;
01166
01167 if ( isEnabled() )
01168 p->setPen( QPen( mcg.text(), 2 ) );
01169 else
01170 p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ), 2 ) );
01171
01172
01173
01174
01175
01176
01177
01178
01179 p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
01180 x++;
01181 y++;
01182 if ( (col == Bold && is->bold()) ||
01183 (col == Italic && is->italic()) ||
01184 (col == Underline && is->underline()) ||
01185 (col == Strikeout && is->strikeOut()) ||
01186 (col == UseDefStyle && *is == *ds ) )
01187 {
01188 QPointArray a( 7*2 );
01189 int i, xx, yy;
01190 xx = x+1+marg;
01191 yy = y+5;
01192 for ( i=0; i<3; i++ ) {
01193 a.setPoint( 2*i, xx, yy );
01194 a.setPoint( 2*i+1, xx, yy+2 );
01195 xx++; yy++;
01196 }
01197 yy -= 2;
01198 for ( i=3; i<7; i++ ) {
01199 a.setPoint( 2*i, xx, yy );
01200 a.setPoint( 2*i+1, xx, yy+2 );
01201 xx++; yy--;
01202 }
01203 p->drawLineSegments( a );
01204 }
01205 }
01206 break;
01207 case Color:
01208 case SelColor:
01209 case BgColor:
01210 case SelBgColor:
01211 {
01212 if ( col == Color) c = is->textColor();
01213 else if ( col == SelColor ) c = is->selectedTextColor();
01214 else if ( col == BgColor ) c = is->itemSet(KateAttribute::BGColor) ? is->bgColor() : mcg.base();
01215 else if ( col == SelBgColor ) c = is->itemSet(KateAttribute::SelectedBGColor) ? is->selectedBGColor(): mcg.base();
01216
01217 int x = 0;
01218 int y = (height() - BoxSize) / 2;
01219 if ( isEnabled() )
01220 p->setPen( QPen( mcg.text(), 2 ) );
01221 else
01222 p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ), 2 ) );
01223
01224 p->drawRect( x+marg, y+2, ColorBtnWidth-4, BoxSize-4 );
01225 p->fillRect( x+marg+1,y+3,ColorBtnWidth-7,BoxSize-7,QBrush( c ) );
01226 }
01227
01228 }
01229 }
01230
01231
01232