• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

kateschema.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License version 2 as published by the Free Software Foundation.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 //BEGIN Includes
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 //END
00069 
00070 
00071 //BEGIN KateSchemaManager
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 // read the types from config file and update the internal list
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 // get the right group
00111 // special handling of the default schemas ;)
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 //END
00188 
00189 //
00190 // DIALOGS !!!
00191 //
00192 
00193 //BEGIN KateSchemaConfigColorTab -- 'Colors' tab
00194 KateSchemaConfigColorTab::KateSchemaConfigColorTab()
00195   : ui(new Ui::SchemaConfigColorTab())
00196 {
00197   m_schema = -1;
00198 
00199   ui->setupUi(this);
00200 
00201   // Markers from kdelibs/interfaces/ktextinterface/markinterface.h
00202   // add the predefined mark types as defined in markinterface.h
00203   ui->combobox->addItem(i18n("Bookmark"));            // markType01
00204   ui->combobox->addItem(i18n("Active Breakpoint"));   // markType02
00205   ui->combobox->addItem(i18n("Reached Breakpoint"));  // markType03
00206   ui->combobox->addItem(i18n("Disabled Breakpoint")); // markType04
00207   ui->combobox->addItem(i18n("Execution"));           // markType05
00208   ui->combobox->addItem(i18n("Warning"));             // markType06
00209   ui->combobox->addItem(i18n("Error"));               // markType07
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   // save curent schema
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   // switch
00251   m_schema = newSchema;
00252 
00253   // first block signals otherwise setColor emits changed
00254   bool blocked = blockSignals(true);
00255 
00256   // If we havent this schema, read in from config file
00257   if ( ! m_schemas.contains( newSchema ) )
00258   {
00259     // fallback defaults
00260     // NOTE keep in sync with KateRendererConfig::setSchemaInternal
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   // using KColorUtils::shade wasn't working really well
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     // same std colors like in KateDocument::markColor
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   // map from 0..reservedMarkersCount()-1 - the same index as in markInterface
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     // TODO - don't save if using defaults, so that changing the color scheme
00349     // lets colors track the new scheme if they haven't been customized
00350     // Although, KColorScheme should handle this eventually...
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   // temporarily block signals because setColor emits changed as well
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 //END KateSchemaConfigColorTab
00399 
00400 //BEGIN FontConfig -- 'Fonts' tab
00401 KateSchemaConfigFontTab::KateSchemaConfigFontTab()
00402 {
00403     // sizemanagment
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 //END FontConfig
00449 
00450 //BEGIN FontColorConfig -- 'Normal Text Styles' tab
00451 KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab()
00452 {
00453   // sizemanagment
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   // set colors
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(); // not quite as much of an assumption ;)
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 //END FontColorConfig
00532 
00533 //BEGIN KateSchemaConfigHighlightTab -- 'Highlighting Text Styles' tab
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   // hl chooser
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   // styles listview
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>&lt;SPACE&gt;</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   // Set listview colors
00621   // We do that now, because we can now get the "normal text" color.
00622   // TODO this reads of the KConfig object, which should be changed when
00623   // the color tab is fixed.
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(); // not quite as much of an assumption ;)
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     // All stylenames have their language mode prefixed, e.g. HTML:Comment
00648     // split them and put them into nice substructures.
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 //END KateSchemaConfigHighlightTab
00694 
00695 //BEGIN KateSchemaConfigPage -- Main dialog page
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   // just reload config from disc
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   // just sync the config
00771   KateGlobal::self()->schemaManager()->schema (0).sync();
00772 
00773   KateGlobal::self()->schemaManager()->update ();
00774 
00775   // clear all attributes
00776   for (int i = 0; i < KateHlManager::self()->highlights(); ++i)
00777     KateHlManager::self()->getHl (i)->clearAttributeArrays();
00778 
00779   // than reload the whole stuff
00780   KateRendererConfig::global()->setSchema (KateGlobal::self()->schemaManager()->name (defaultSchemaCombo->currentIndex()));
00781   KateRendererConfig::global()->reloadSchema();
00782 
00783   // sync the hl config for real
00784   KateHlManager::self()->getKConfig()->sync ();
00785 }
00786 
00787 void KateSchemaConfigPage::reload()
00788 {
00789   // just reload the config from disc
00790   KateGlobal::self()->schemaManager()->update ();
00791 
00792   // special for the highlighting stuff
00793   m_fontColorTab->reload ();
00794 
00795   update ();
00796 
00797   defaultSchemaCombo->setCurrentIndex (KateGlobal::self()->schemaManager()->number (KateRendererConfig::global()->schema()));
00798 
00799   // initialize to the schema in the current document, or default schema
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   // soft update, no load from disk
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   // soft update, no load from disk
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 //END KateSchemaConfigPage
00877 
00878 //BEGIN SCHEMA ACTION -- the 'View->Schema' menu action
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     //FIXME EXCLUSIVE
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 //FIXME
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 //END SCHEMA ACTION
00947 
00948 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal