# kate Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kateconfig.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 2003 Christoph Cullmann <cullmann@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018
    00019 #include "kateconfig.h"
    00020
    00021 #include "katefactory.h"
    00022 #include "katerenderer.h"
    00023 #include "kateview.h"
    00024 #include "katedocument.h"
    00025 #include "katefont.h"
    00026 #include "kateschema.h"
    00027
    00028 #include <math.h>
    00029
    00030 #include <kapplication.h>
    00031 #include <kconfig.h>
    00032 #include <kglobalsettings.h>
    00033 #include <kcharsets.h>
    00034 #include <klocale.h>
    00035 #include <kfinddialog.h>
    00036 #include <kreplacedialog.h>
    00037 #include <kinstance.h>
    00038 #include <kstaticdeleter.h>
    00039
    00040 #include <qpopupmenu.h>
    00041 #include <qtextcodec.h>
    00042
    00043 #include <kdebug.h>
    00044
    00045 //BEGIN KateConfig
    00046 KateConfig::KateConfig ()
    00047  : configSessionNumber (0), configIsRunning (false)
    00048 {
    00049 }
    00050
    00051 KateConfig::~KateConfig ()
    00052 {
    00053 }
    00054
    00055 void KateConfig::configStart ()
    00056 {
    00057   configSessionNumber++;
    00058
    00059   if (configSessionNumber > 1)
    00060     return;
    00061
    00062   configIsRunning = true;
    00063 }
    00064
    00065 void KateConfig::configEnd ()
    00066 {
    00067   if (configSessionNumber == 0)
    00068     return;
    00069
    00070   configSessionNumber--;
    00071
    00072   if (configSessionNumber > 0)
    00073     return;
    00074
    00075   configIsRunning = false;
    00076
    00077   updateConfig ();
    00078 }
    00079 //END
    00080
    00081 //BEGIN KateDocumentConfig
    00082 KateDocumentConfig *KateDocumentConfig::s_global = 0;
    00083 KateViewConfig *KateViewConfig::s_global = 0;
    00084 KateRendererConfig *KateRendererConfig::s_global = 0;
    00085
    00086 KateDocumentConfig::KateDocumentConfig ()
    00087  : m_tabWidth (8),
    00088    m_indentationWidth (2),
    00089    m_wordWrapAt (80),
    00090    m_configFlags (0),
    00091    m_plugins (KateFactory::self()->plugins().count()),
    00092    m_tabWidthSet (true),
    00093    m_indentationWidthSet (true),
    00094    m_indentationModeSet (true),
    00095    m_wordWrapSet (true),
    00096    m_wordWrapAtSet (true),
    00097    m_pageUpDownMovesCursorSet (true),
    00098    m_undoStepsSet (true),
    00099    m_configFlagsSet (0xFFFF),
    00100    m_encodingSet (true),
    00101    m_eolSet (true),
    00102    m_backupFlagsSet (true),
    00103    m_searchDirConfigDepthSet (true),
    00104    m_backupPrefixSet (true),
    00105    m_backupSuffixSet (true),
    00106    m_pluginsSet (m_plugins.size()),
    00107    m_doc (0)
    00108 {
    00109   s_global = this;
    00110
    00111   // init plugin array
    00112   m_plugins.fill (false);
    00113   m_pluginsSet.fill (true);
    00114
    00115   // init with defaults from config or really hardcoded ones
    00116   KConfig *config = kapp->config();
    00117   config->setGroup("Kate Document Defaults");
    00118   readConfig (config);
    00119 }
    00120
    00121 KateDocumentConfig::KateDocumentConfig (KateDocument *doc)
    00122  : m_configFlags (0),
    00123    m_plugins (KateFactory::self()->plugins().count()),
    00124    m_tabWidthSet (false),
    00125    m_indentationWidthSet (false),
    00126    m_indentationModeSet (false),
    00127    m_wordWrapSet (false),
    00128    m_wordWrapAtSet (false),
    00129    m_pageUpDownMovesCursorSet (false),
    00130    m_undoStepsSet (false),
    00131    m_configFlagsSet (0),
    00132    m_encodingSet (false),
    00133    m_eolSet (false),
    00134    m_backupFlagsSet (false),
    00135    m_searchDirConfigDepthSet (false),
    00136    m_backupPrefixSet (false),
    00137    m_backupSuffixSet (false),
    00138    m_pluginsSet (m_plugins.size()),
    00139    m_doc (doc)
    00140 {
    00141   // init plugin array
    00142   m_plugins.fill (false);
    00143   m_pluginsSet.fill (false);
    00144 }
    00145
    00146 KateDocumentConfig::~KateDocumentConfig ()
    00147 {
    00148 }
    00149
    00150 void KateDocumentConfig::readConfig (KConfig *config)
    00151 {
    00152   configStart ();
    00153
    00154   setTabWidth (config->readNumEntry("Tab Width", 8));
    00155
    00156   setIndentationWidth (config->readNumEntry("Indentation Width", 2));
    00157
    00158   setIndentationMode (config->readNumEntry("Indentation Mode", KateDocumentConfig::imNone));
    00159
    00160   setWordWrap (config->readBoolEntry("Word Wrap", false));
    00161   setWordWrapAt (config->readNumEntry("Word Wrap Column", 80));
    00162   setPageUpDownMovesCursor (config->readNumEntry("PageUp/PageDown Moves Cursor", false));
    00163   setUndoSteps(config->readNumEntry("Undo Steps", 0));
    00164
    00165   setConfigFlags (config->readNumEntry("Basic Config Flags", KateDocumentConfig::cfTabIndents
    00166     | KateDocumentConfig::cfKeepIndentProfile
    00167     | KateDocumentConfig::cfWrapCursor
    00168     | KateDocumentConfig::cfShowTabs
    00169     | KateDocumentConfig::cfSmartHome));
    00170
    00171   setEncoding (config->readEntry("Encoding", ""));
    00172
    00173   setEol (config->readNumEntry("End of Line", 0));
    00174
    00175   setBackupFlags (config->readNumEntry("Backup Config Flags", 1));
    00176
    00177   setSearchDirConfigDepth (config->readNumEntry("Search Dir Config Depth", -1));
    00178
    00179   setBackupPrefix (config->readEntry("Backup Prefix", QString ("")));
    00180
    00181   setBackupSuffix (config->readEntry("Backup Suffix", QString ("~")));
    00182
    00183   // plugins
    00184   for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
    00185     setPlugin (i, config->readBoolEntry("KTextEditor Plugin " + (KateFactory::self()->plugins())[i]->library(), false));
    00186
    00187   configEnd ();
    00188 }
    00189
    00190 void KateDocumentConfig::writeConfig (KConfig *config)
    00191 {
    00192   config->writeEntry("Tab Width", tabWidth());
    00193
    00194   config->writeEntry("Indentation Width", indentationWidth());
    00195   config->writeEntry("Indentation Mode", indentationMode());
    00196
    00197   config->writeEntry("Word Wrap", wordWrap());
    00198   config->writeEntry("Word Wrap Column", wordWrapAt());
    00199
    00200   config->writeEntry("PageUp/PageDown Moves Cursor", pageUpDownMovesCursor());
    00201
    00202   config->writeEntry("Undo Steps", undoSteps());
    00203
    00204   config->writeEntry("Basic Config Flags", configFlags());
    00205
    00206   config->writeEntry("Encoding", encoding());
    00207
    00208   config->writeEntry("End of Line", eol());
    00209
    00210   config->writeEntry("Backup Config Flags", backupFlags());
    00211
    00212   config->writeEntry("Search Dir Config Depth", searchDirConfigDepth());
    00213
    00214   config->writeEntry("Backup Prefix", backupPrefix());
    00215
    00216   config->writeEntry("Backup Suffix", backupSuffix());
    00217
    00218   // plugins
    00219   for (uint i=0; i<KateFactory::self()->plugins().count(); i++)
    00220     config->writeEntry("KTextEditor Plugin " + (KateFactory::self()->plugins())[i]->library(), plugin(i));
    00221 }
    00222
    00223 void KateDocumentConfig::updateConfig ()
    00224 {
    00225   if (m_doc)
    00226   {
    00227     m_doc->updateConfig ();
    00228     return;
    00229   }
    00230
    00231   if (isGlobal())
    00232   {
    00233     for (uint z=0; z < KateFactory::self()->documents()->count(); z++)
    00234     {
    00235       KateFactory::self()->documents()->at(z)->updateConfig ();
    00236     }
    00237   }
    00238 }
    00239
    00240 int KateDocumentConfig::tabWidth () const
    00241 {
    00242   if (m_tabWidthSet || isGlobal())
    00243     return m_tabWidth;
    00244
    00245   return s_global->tabWidth();
    00246 }
    00247
    00248 void KateDocumentConfig::setTabWidth (int tabWidth)
    00249 {
    00250   if (tabWidth < 1)
    00251     return;
    00252
    00253   configStart ();
    00254
    00255   m_tabWidthSet = true;
    00256   m_tabWidth = tabWidth;
    00257
    00258   configEnd ();
    00259 }
    00260
    00261 int KateDocumentConfig::indentationWidth () const
    00262 {
    00263   if (m_indentationWidthSet || isGlobal())
    00264     return m_indentationWidth;
    00265
    00266   return s_global->indentationWidth();
    00267 }
    00268
    00269 void KateDocumentConfig::setIndentationWidth (int indentationWidth)
    00270 {
    00271   if (indentationWidth < 1)
    00272     return;
    00273
    00274   configStart ();
    00275
    00276   m_indentationWidthSet = true;
    00277   m_indentationWidth = indentationWidth;
    00278
    00279   configEnd ();
    00280 }
    00281
    00282 uint KateDocumentConfig::indentationMode () const
    00283 {
    00284   if (m_indentationModeSet || isGlobal())
    00285     return m_indentationMode;
    00286
    00287   return s_global->indentationMode();
    00288 }
    00289
    00290 void KateDocumentConfig::setIndentationMode (uint indentationMode)
    00291 {
    00292   configStart ();
    00293
    00294   m_indentationModeSet = true;
    00295   m_indentationMode = indentationMode;
    00296
    00297   configEnd ();
    00298 }
    00299
    00300 bool KateDocumentConfig::wordWrap () const
    00301 {
    00302   if (m_wordWrapSet || isGlobal())
    00303     return m_wordWrap;
    00304
    00305   return s_global->wordWrap();
    00306 }
    00307
    00308 void KateDocumentConfig::setWordWrap (bool on)
    00309 {
    00310   configStart ();
    00311
    00312   m_wordWrapSet = true;
    00313   m_wordWrap = on;
    00314
    00315   configEnd ();
    00316 }
    00317
    00318 unsigned int KateDocumentConfig::wordWrapAt () const
    00319 {
    00320   if (m_wordWrapAtSet || isGlobal())
    00321     return m_wordWrapAt;
    00322
    00323   return s_global->wordWrapAt();
    00324 }
    00325
    00326 void KateDocumentConfig::setWordWrapAt (unsigned int col)
    00327 {
    00328   if (col < 1)
    00329     return;
    00330
    00331   configStart ();
    00332
    00333   m_wordWrapAtSet = true;
    00334   m_wordWrapAt = col;
    00335
    00336   configEnd ();
    00337 }
    00338
    00339 uint KateDocumentConfig::undoSteps () const
    00340 {
    00341   if (m_undoStepsSet || isGlobal())
    00342     return m_undoSteps;
    00343
    00344   return s_global->undoSteps();
    00345 }
    00346
    00347 void KateDocumentConfig::setUndoSteps (uint undoSteps)
    00348 {
    00349   configStart ();
    00350
    00351   m_undoStepsSet = true;
    00352   m_undoSteps = undoSteps;
    00353
    00354   configEnd ();
    00355 }
    00356
    00357 bool KateDocumentConfig::pageUpDownMovesCursor () const
    00358 {
    00359   if (m_pageUpDownMovesCursorSet || isGlobal())
    00360     return m_pageUpDownMovesCursor;
    00361
    00362   return s_global->pageUpDownMovesCursor();
    00363 }
    00364
    00365 void KateDocumentConfig::setPageUpDownMovesCursor (bool on)
    00366 {
    00367   configStart ();
    00368
    00369   m_pageUpDownMovesCursorSet = true;
    00370   m_pageUpDownMovesCursor = on;
    00371
    00372   configEnd ();
    00373 }
    00374
    00375 uint KateDocumentConfig::configFlags () const
    00376 {
    00377   if (isGlobal())
    00378     return m_configFlags;
    00379
    00380   return ((s_global->configFlags() & ~ m_configFlagsSet) | m_configFlags);
    00381 }
    00382
    00383 void KateDocumentConfig::setConfigFlags (KateDocumentConfig::ConfigFlags flag, bool enable)
    00384 {
    00385   configStart ();
    00386
    00387   m_configFlagsSet |= flag;
    00388
    00389   if (enable)
    00390     m_configFlags = m_configFlags | flag;
    00391   else
    00392     m_configFlags = m_configFlags & ~ flag;
    00393
    00394   configEnd ();
    00395 }
    00396
    00397 void KateDocumentConfig::setConfigFlags (uint fullFlags)
    00398 {
    00399   configStart ();
    00400
    00401   m_configFlagsSet = 0xFFFF;
    00402   m_configFlags = fullFlags;
    00403
    00404   configEnd ();
    00405 }
    00406
    00407 const QString &KateDocumentConfig::encoding () const
    00408 {
    00409   if (m_encodingSet || isGlobal())
    00410     return m_encoding;
    00411
    00412   return s_global->encoding();
    00413 }
    00414
    00415 QTextCodec *KateDocumentConfig::codec ()
    00416 {
    00417   if (m_encodingSet || isGlobal())
    00418   {
    00419     if (m_encoding.isEmpty() && isGlobal())
    00420       return KGlobal::charsets()->codecForName (QString::fromLatin1(KGlobal::locale()->encoding()));
    00421     else if (m_encoding.isEmpty())
    00422       return s_global->codec ();
    00423     else
    00424       return KGlobal::charsets()->codecForName (m_encoding);
    00425   }
    00426
    00427   return s_global->codec ();
    00428 }
    00429
    00430 void KateDocumentConfig::setEncoding (const QString &encoding)
    00431 {
    00432   QString enc = encoding;
    00433
    00434   if (!enc.isEmpty())
    00435   {
    00436     bool found = false;
    00437     QTextCodec *codec = KGlobal::charsets()->codecForName (encoding, found);
    00438
    00439     if (!found || !codec)
    00440       return;
    00441
    00442     enc = codec->name();
    00443   }
    00444
    00445   configStart ();
    00446
    00447   if (isGlobal())
    00448     KateDocument::setDefaultEncoding (enc);
    00449
    00450   m_encodingSet = true;
    00451   m_encoding = enc;
    00452
    00453   configEnd ();
    00454 }
    00455
    00456 bool KateDocumentConfig::isSetEncoding () const
    00457 {
    00458   return m_encodingSet;
    00459 }
    00460
    00461 int KateDocumentConfig::eol () const
    00462 {
    00463   if (m_eolSet || isGlobal())
    00464     return m_eol;
    00465
    00466   return s_global->eol();
    00467 }
    00468
    00469 QString KateDocumentConfig::eolString ()
    00470 {
    00471   if (eol() == KateDocumentConfig::eolUnix)
    00472     return QString ("\n");
    00473   else if (eol() == KateDocumentConfig::eolDos)
    00474     return QString ("\r\n");
    00475   else if (eol() == KateDocumentConfig::eolMac)
    00476     return QString ("\r");
    00477
    00478   return QString ("\n");
    00479 }
    00480
    00481 void KateDocumentConfig::setEol (int mode)
    00482 {
    00483   configStart ();
    00484
    00485   m_eolSet = true;
    00486   m_eol = mode;
    00487
    00488   configEnd ();
    00489 }
    00490
    00491 uint KateDocumentConfig::backupFlags () const
    00492 {
    00493   if (m_backupFlagsSet || isGlobal())
    00494     return m_backupFlags;
    00495
    00496   return s_global->backupFlags();
    00497 }
    00498
    00499 void KateDocumentConfig::setBackupFlags (uint flags)
    00500  {
    00501   configStart ();
    00502
    00503   m_backupFlagsSet = true;
    00504   m_backupFlags = flags;
    00505
    00506   configEnd ();
    00507 }
    00508
    00509 const QString &KateDocumentConfig::backupPrefix () const
    00510 {
    00511   if (m_backupPrefixSet || isGlobal())
    00512     return m_backupPrefix;
    00513
    00514   return s_global->backupPrefix();
    00515 }
    00516
    00517 const QString &KateDocumentConfig::backupSuffix () const
    00518 {
    00519   if (m_backupSuffixSet || isGlobal())
    00520     return m_backupSuffix;
    00521
    00522   return s_global->backupSuffix();
    00523 }
    00524
    00525 void KateDocumentConfig::setBackupPrefix (const QString &prefix)
    00526 {
    00527   configStart ();
    00528
    00529   m_backupPrefixSet = true;
    00530   m_backupPrefix = prefix;
    00531
    00532   configEnd ();
    00533 }
    00534
    00535 void KateDocumentConfig::setBackupSuffix (const QString &suffix)
    00536 {
    00537   configStart ();
    00538
    00539   m_backupSuffixSet = true;
    00540   m_backupSuffix = suffix;
    00541
    00542   configEnd ();
    00543 }
    00544
    00545 bool KateDocumentConfig::plugin (uint index) const
    00546 {
    00547   if (index >= m_plugins.size())
    00548     return false;
    00549
    00550   if (m_pluginsSet.at(index) || isGlobal())
    00551     return m_plugins.at(index);
    00552
    00553   return s_global->plugin (index);
    00554 }
    00555
    00556 void KateDocumentConfig::setPlugin (uint index, bool load)
    00557 {
    00558   if (index >= m_plugins.size())
    00559     return;
    00560
    00561   configStart ();
    00562
    00563   m_pluginsSet.setBit(index);
    00564   m_plugins.setBit(index, load);
    00565
    00566   configEnd ();
    00567 }
    00568
    00569 int KateDocumentConfig::searchDirConfigDepth () const
    00570 {
    00571   if (m_searchDirConfigDepthSet || isGlobal())
    00572     return m_searchDirConfigDepth;
    00573
    00574   return s_global->searchDirConfigDepth ();
    00575 }
    00576
    00577 void KateDocumentConfig::setSearchDirConfigDepth (int depth)
    00578 {
    00579   configStart ();
    00580
    00581   m_searchDirConfigDepthSet = true;
    00582   m_searchDirConfigDepth = depth;
    00583
    00584   configEnd ();
    00585 }
    00586
    00587 //END
    00588
    00589 //BEGIN KateViewConfig
    00590 KateViewConfig::KateViewConfig ()
    00591  :
    00592    m_dynWordWrapSet (true),
    00593    m_dynWordWrapIndicatorsSet (true),
    00594    m_dynWordWrapAlignIndentSet (true),
    00595    m_lineNumbersSet (true),
    00596    m_scrollBarMarksSet (true),
    00597    m_iconBarSet (true),
    00598    m_foldingBarSet (true),
    00599    m_bookmarkSortSet (true),
    00600    m_autoCenterLinesSet (true),
    00601    m_searchFlagsSet (true),
    00602    m_cmdLineSet (true),
    00603    m_defaultMarkTypeSet (true),
    00604    m_textToSearchModeSet (true),
    00605    m_view (0)
    00606 {
    00607   s_global = this;
    00608
    00609   // init with defaults from config or really hardcoded ones
    00610   KConfig *config = kapp->config();
    00611   config->setGroup("Kate View Defaults");
    00612   readConfig (config);
    00613 }
    00614
    00615 KateViewConfig::KateViewConfig (KateView *view)
    00616  :
    00617    m_dynWordWrapSet (false),
    00618    m_dynWordWrapIndicatorsSet (false),
    00619    m_dynWordWrapAlignIndentSet (false),
    00620    m_lineNumbersSet (false),
    00621    m_scrollBarMarksSet (false),
    00622    m_iconBarSet (false),
    00623    m_foldingBarSet (false),
    00624    m_bookmarkSortSet (false),
    00625    m_autoCenterLinesSet (false),
    00626    m_searchFlagsSet (false),
    00627    m_cmdLineSet (false),
    00628    m_defaultMarkTypeSet (false),
    00629    m_textToSearchModeSet (false),
    00630    m_view (view)
    00631 {
    00632 }
    00633
    00634 KateViewConfig::~KateViewConfig ()
    00635 {
    00636 }
    00637
    00638 void KateViewConfig::readConfig (KConfig *config)
    00639 {
    00640   configStart ();
    00641
    00642   setDynWordWrap (config->readBoolEntry( "Dynamic Word Wrap", true ));
    00643   setDynWordWrapIndicators (config->readNumEntry( "Dynamic Word Wrap Indicators", 1 ));
    00644   setDynWordWrapAlignIndent (config->readNumEntry( "Dynamic Word Wrap Align Indent", 80 ));
    00645
    00646   setLineNumbers (config->readBoolEntry( "Line Numbers",  false));
    00647
    00648   setScrollBarMarks (config->readBoolEntry( "Scroll Bar Marks",  false));
    00649
    00650   setIconBar (config->readBoolEntry( "Icon Bar", false ));
    00651
    00652   setFoldingBar (config->readBoolEntry( "Folding Bar", true));
    00653
    00654   setBookmarkSort (config->readNumEntry( "Bookmark Menu Sorting", 0 ));
    00655
    00656   setAutoCenterLines (config->readNumEntry( "Auto Center Lines", 0 ));
    00657
    00658   setSearchFlags (config->readNumEntry("Search Config Flags", KFindDialog::FromCursor | KFindDialog::CaseSensitive | KReplaceDialog::PromptOnReplace));
    00659
    00660   setCmdLine (config->readBoolEntry( "Command Line", false));
    00661
    00662   setDefaultMarkType (config->readNumEntry( "Default Mark Type", KTextEditor::MarkInterface::markType01 ));
    00663
    00664   setTextToSearchMode (config->readNumEntry( "Text To Search Mode", KateViewConfig::SelectionWord));
    00665
    00666   configEnd ();
    00667 }
    00668
    00669 void KateViewConfig::writeConfig (KConfig *config)
    00670 {
    00671   config->writeEntry( "Dynamic Word Wrap", dynWordWrap() );
    00672   config->writeEntry( "Dynamic Word Wrap Indicators", dynWordWrapIndicators() );
    00673   config->writeEntry( "Dynamic Word Wrap Align Indent", dynWordWrapAlignIndent() );
    00674
    00675   config->writeEntry( "Line Numbers", lineNumbers() );
    00676
    00677   config->writeEntry( "Scroll Bar Marks", scrollBarMarks() );
    00678
    00679   config->writeEntry( "Icon Bar", iconBar() );
    00680
    00681   config->writeEntry( "Folding Bar", foldingBar() );
    00682
    00683   config->writeEntry( "Bookmark Menu Sorting", bookmarkSort() );
    00684
    00685   config->writeEntry( "Auto Center Lines", autoCenterLines() );
    00686
    00687   config->writeEntry("Search Config Flags", searchFlags());
    00688
    00689   config->writeEntry("Command Line", cmdLine());
    00690
    00691   config->writeEntry("Default Mark Type", defaultMarkType());
    00692
    00693   config->writeEntry("Text To Search Mode", textToSearchMode());
    00694 }
    00695
    00696 void KateViewConfig::updateConfig ()
    00697 {
    00698   if (m_view)
    00699   {
    00700     m_view->updateConfig ();
    00701     return;
    00702   }
    00703
    00704   if (isGlobal())
    00705   {
    00706     for (uint z=0; z < KateFactory::self()->views()->count(); z++)
    00707     {
    00708       KateFactory::self()->views()->at(z)->updateConfig ();
    00709     }
    00710   }
    00711 }
    00712
    00713 bool KateViewConfig::dynWordWrap () const
    00714 {
    00715   if (m_dynWordWrapSet || isGlobal())
    00716     return m_dynWordWrap;
    00717
    00718   return s_global->dynWordWrap();
    00719 }
    00720
    00721 void KateViewConfig::setDynWordWrap (bool wrap)
    00722 {
    00723   configStart ();
    00724
    00725   m_dynWordWrapSet = true;
    00726   m_dynWordWrap = wrap;
    00727
    00728   configEnd ();
    00729 }
    00730
    00731 int KateViewConfig::dynWordWrapIndicators () const
    00732 {
    00733   if (m_dynWordWrapIndicatorsSet || isGlobal())
    00734     return m_dynWordWrapIndicators;
    00735
    00736   return s_global->dynWordWrapIndicators();
    00737 }
    00738
    00739 void KateViewConfig::setDynWordWrapIndicators (int mode)
    00740 {
    00741   configStart ();
    00742
    00743   m_dynWordWrapIndicatorsSet = true;
    00744   m_dynWordWrapIndicators = QMIN(80, QMAX(0, mode));
    00745
    00746   configEnd ();
    00747 }
    00748
    00749 int KateViewConfig::dynWordWrapAlignIndent () const
    00750 {
    00751   if (m_dynWordWrapAlignIndentSet || isGlobal())
    00752     return m_dynWordWrapAlignIndent;
    00753
    00754   return s_global->dynWordWrapAlignIndent();
    00755 }
    00756
    00757 void KateViewConfig::setDynWordWrapAlignIndent (int indent)
    00758 {
    00759   configStart ();
    00760
    00761   m_dynWordWrapAlignIndentSet = true;
    00762   m_dynWordWrapAlignIndent = indent;
    00763
    00764   configEnd ();
    00765 }
    00766
    00767 bool KateViewConfig::lineNumbers () const
    00768 {
    00769   if (m_lineNumbersSet || isGlobal())
    00770     return m_lineNumbers;
    00771
    00772   return s_global->lineNumbers();
    00773 }
    00774
    00775 void KateViewConfig::setLineNumbers (bool on)
    00776 {
    00777   configStart ();
    00778
    00779   m_lineNumbersSet = true;
    00780   m_lineNumbers = on;
    00781
    00782   configEnd ();
    00783 }
    00784
    00785 bool KateViewConfig::scrollBarMarks () const
    00786 {
    00787   if (m_scrollBarMarksSet || isGlobal())
    00788     return m_scrollBarMarks;
    00789
    00790   return s_global->scrollBarMarks();
    00791 }
    00792
    00793 void KateViewConfig::setScrollBarMarks (bool on)
    00794 {
    00795   configStart ();
    00796
    00797   m_scrollBarMarksSet = true;
    00798   m_scrollBarMarks = on;
    00799
    00800   configEnd ();
    00801 }
    00802
    00803 bool KateViewConfig::iconBar () const
    00804 {
    00805   if (m_iconBarSet || isGlobal())
    00806     return m_iconBar;
    00807
    00808   return s_global->iconBar();
    00809 }
    00810
    00811 void KateViewConfig::setIconBar (bool on)
    00812 {
    00813   configStart ();
    00814
    00815   m_iconBarSet = true;
    00816   m_iconBar = on;
    00817
    00818   configEnd ();
    00819 }
    00820
    00821 bool KateViewConfig::foldingBar () const
    00822 {
    00823   if (m_foldingBarSet || isGlobal())
    00824     return m_foldingBar;
    00825
    00826   return s_global->foldingBar();
    00827 }
    00828
    00829 void KateViewConfig::setFoldingBar (bool on)
    00830 {
    00831   configStart ();
    00832
    00833   m_foldingBarSet = true;
    00834   m_foldingBar = on;
    00835
    00836   configEnd ();
    00837 }
    00838
    00839 int KateViewConfig::bookmarkSort () const
    00840 {
    00841   if (m_bookmarkSortSet || isGlobal())
    00842     return m_bookmarkSort;
    00843
    00844   return s_global->bookmarkSort();
    00845 }
    00846
    00847 void KateViewConfig::setBookmarkSort (int mode)
    00848 {
    00849   configStart ();
    00850
    00851   m_bookmarkSortSet = true;
    00852   m_bookmarkSort = mode;
    00853
    00854   configEnd ();
    00855 }
    00856
    00857 int KateViewConfig::autoCenterLines () const
    00858 {
    00859   if (m_autoCenterLinesSet || isGlobal())
    00860     return m_autoCenterLines;
    00861
    00862   return s_global->autoCenterLines();
    00863 }
    00864
    00865 void KateViewConfig::setAutoCenterLines (int lines)
    00866 {
    00867   if (lines < 0)
    00868     return;
    00869
    00870   configStart ();
    00871
    00872   m_autoCenterLinesSet = true;
    00873   m_autoCenterLines = lines;
    00874
    00875   configEnd ();
    00876 }
    00877
    00878 long KateViewConfig::searchFlags () const
    00879 {
    00880   if (m_searchFlagsSet || isGlobal())
    00881     return m_searchFlags;
    00882
    00883   return s_global->searchFlags();
    00884 }
    00885
    00886 void KateViewConfig::setSearchFlags (long flags)
    00887  {
    00888   configStart ();
    00889
    00890   m_searchFlagsSet = true;
    00891   m_searchFlags = flags;
    00892
    00893   configEnd ();
    00894 }
    00895
    00896 bool KateViewConfig::cmdLine () const
    00897 {
    00898   if (m_cmdLineSet || isGlobal())
    00899     return m_cmdLine;
    00900
    00901   return s_global->cmdLine();
    00902 }
    00903
    00904 void KateViewConfig::setCmdLine (bool on)
    00905 {
    00906   configStart ();
    00907
    00908   m_cmdLineSet = true;
    00909   m_cmdLine = on;
    00910
    00911   configEnd ();
    00912 }
    00913
    00914 uint KateViewConfig::defaultMarkType () const
    00915 {
    00916   if (m_defaultMarkTypeSet || isGlobal())
    00917     return m_defaultMarkType;
    00918
    00919   return s_global->defaultMarkType();
    00920 }
    00921
    00922 void KateViewConfig::setDefaultMarkType (uint type)
    00923 {
    00924   configStart ();
    00925
    00926   m_defaultMarkTypeSet = true;
    00927   m_defaultMarkType = type;
    00928
    00929   configEnd ();
    00930 }
    00931
    00932 int KateViewConfig::textToSearchMode () const
    00933 {
    00934   if (m_textToSearchModeSet || isGlobal())
    00935     return m_textToSearchMode;
    00936
    00937   return s_global->textToSearchMode();
    00938 }
    00939
    00940 void KateViewConfig::setTextToSearchMode (int mode)
    00941 {
    00942   configStart ();
    00943
    00944   m_textToSearchModeSet = true;
    00945   m_textToSearchMode = mode;
    00946
    00947   configEnd ();
    00948 }
    00949 //END
    00950
    00951 //BEGIN KateRendererConfig
    00952 KateRendererConfig::KateRendererConfig ()
    00953  :
    00954    m_font (new KateFontStruct ()),
    00955    m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()),
    00956    m_schemaSet (true),
    00957    m_fontSet (true),
    00958    m_wordWrapMarkerSet (true),
    00959    m_backgroundColorSet (true),
    00960    m_selectionColorSet (true),
    00961    m_highlightedLineColorSet (true),
    00962    m_highlightedBracketColorSet (true),
    00963    m_wordWrapMarkerColorSet (true),
    00964    m_tabMarkerColorSet(true),
    00965    m_iconBarColorSet (true),
    00966    m_lineNumberColorSet (true),
    00967    m_lineMarkerColorSet (m_lineMarkerColor.size()),
    00968    m_renderer (0)
    00969 {
    00970   // init bitarray
    00971   m_lineMarkerColorSet.fill (true);
    00972
    00973   s_global = this;
    00974
    00975   // init with defaults from config or really hardcoded ones
    00976   KConfig *config = kapp->config();
    00977   config->setGroup("Kate Renderer Defaults");
    00978   readConfig (config);
    00979 }
    00980
    00981 KateRendererConfig::KateRendererConfig (KateRenderer *renderer)
    00982  : m_font (0),
    00983    m_lineMarkerColor (KTextEditor::MarkInterface::reservedMarkersCount()),
    00984    m_schemaSet (false),
    00985    m_fontSet (false),
    00986    m_wordWrapMarkerSet (false),
    00987    m_backgroundColorSet (false),
    00988    m_selectionColorSet (false),
    00989    m_highlightedLineColorSet (false),
    00990    m_highlightedBracketColorSet (false),
    00991    m_wordWrapMarkerColorSet (false),
    00992    m_tabMarkerColorSet(false),
    00993    m_iconBarColorSet (false),
    00994    m_lineNumberColorSet (false),
    00995    m_lineMarkerColorSet (m_lineMarkerColor.size()),
    00996    m_renderer (renderer)
    00997 {
    00998   // init bitarray
    00999   m_lineMarkerColorSet.fill (false);
    01000 }
    01001
    01002 KateRendererConfig::~KateRendererConfig ()
    01003 {
    01004   delete m_font;
    01005 }
    01006
    01007 void KateRendererConfig::readConfig (KConfig *config)
    01008 {
    01009   configStart ();
    01010
    01011   setSchema (KateFactory::self()->schemaManager()->number (config->readEntry("Schema", KateSchemaManager::normalSchema())));
    01012
    01013   setWordWrapMarker (config->readBoolEntry("Word Wrap Marker", false ));
    01014
    01015   configEnd ();
    01016 }
    01017
    01018 void KateRendererConfig::writeConfig (KConfig *config)
    01019 {
    01020   config->writeEntry ("Schema", KateFactory::self()->schemaManager()->name(schema()));
    01021
    01022   config->writeEntry( "Word Wrap Marker", wordWrapMarker() );
    01023 }
    01024
    01025 void KateRendererConfig::updateConfig ()
    01026 {
    01027   if (m_renderer)
    01028   {
    01029     m_renderer->updateConfig ();
    01030     return;
    01031   }
    01032
    01033   if (isGlobal())
    01034   {
    01035     for (uint z=0; z < KateFactory::self()->renderers()->count(); z++)
    01036     {
    01037       KateFactory::self()->renderers()->at(z)->updateConfig ();
    01038     }
    01039   }
    01040 }
    01041
    01042 uint KateRendererConfig::schema () const
    01043 {
    01044   if (m_schemaSet || isGlobal())
    01045     return m_schema;
    01046
    01047   return s_global->schema();
    01048 }
    01049
    01050 void KateRendererConfig::setSchema (uint schema)
    01051 {
    01052   configStart ();
    01053   m_schemaSet = true;
    01054   m_schema = schema;
    01055   setSchemaInternal( schema );
    01056   configEnd ();
    01057 }
    01058
    01059 void KateRendererConfig::reloadSchema()
    01060 {
    01061   if ( isGlobal() )
    01062     for ( uint z=0; z < KateFactory::self()->renderers()->count(); z++ )
    01063       KateFactory::self()->renderers()->at(z)->config()->reloadSchema();
    01064
    01065   else if ( m_renderer && m_schemaSet )
    01066     setSchemaInternal( m_schema );
    01067 }
    01068
    01069 void KateRendererConfig::setSchemaInternal( int schema )
    01070 {
    01071   m_schemaSet = true;
    01072   m_schema = schema;
    01073
    01074   KConfig *config (KateFactory::self()->schemaManager()->schema(schema));
    01075
    01076   QColor tmp0 (KGlobalSettings::baseColor());
    01077   QColor tmp1 (KGlobalSettings::highlightColor());
    01078   QColor tmp2 (KGlobalSettings::alternateBackgroundColor());
    01079   QColor tmp3 ( "#FFFF99" );
    01080   QColor tmp4 (tmp2.dark());
    01081   QColor tmp5 ( KGlobalSettings::textColor() );
    01082   QColor tmp6 ( "#EAE9E8" );
    01083   QColor tmp7 ( "#000000" );
    01084
    01085   m_backgroundColor = config->readColorEntry("Color Background", &tmp0);
    01086   m_backgroundColorSet = true;
    01087   m_selectionColor = config->readColorEntry("Color Selection", &tmp1);
    01088   m_selectionColorSet = true;
    01089   m_highlightedLineColor  = config->readColorEntry("Color Highlighted Line", &tmp2);
    01090   m_highlightedLineColorSet = true;
    01091   m_highlightedBracketColor = config->readColorEntry("Color Highlighted Bracket", &tmp3);
    01092   m_highlightedBracketColorSet = true;
    01093   m_wordWrapMarkerColor = config->readColorEntry("Color Word Wrap Marker", &tmp4);
    01094   m_wordWrapMarkerColorSet = true;
    01095   m_tabMarkerColor = config->readColorEntry("Color Tab Marker", &tmp5);
    01096   m_tabMarkerColorSet = true;
    01097   m_iconBarColor  = config->readColorEntry("Color Icon Bar", &tmp6);
    01098   m_iconBarColorSet = true;
    01099   m_lineNumberColor = config->readColorEntry("Color Line Number", &tmp7);
    01100   m_lineNumberColorSet = true;
    01101
    01102     // same std colors like in KateDocument::markColor
    01103   QColor mark[7];
    01104   mark[0] = Qt::blue;
    01105   mark[1] = Qt::red;
    01106   mark[2] = Qt::yellow;
    01107   mark[3] = Qt::magenta;
    01108   mark[4] = Qt::gray;
    01109   mark[5] = Qt::green;
    01110   mark[6] = Qt::red;
    01111
    01112   for (int i = 1; i <= KTextEditor::MarkInterface::reservedMarkersCount(); i++) {
    01113     QColor col = config->readColorEntry(QString("Color MarkType%1").arg(i), &mark[i - 1]);
    01114     int index = i-1;
    01115     m_lineMarkerColorSet[index] = true;
    01116     m_lineMarkerColor[index] = col;
    01117   }
    01118
    01119   QFont f (KGlobalSettings::fixedFont());
    01120
    01121   if (!m_fontSet)
    01122   {
    01123     m_fontSet = true;
    01124     m_font = new KateFontStruct ();
    01125   }
    01126
    01127   m_font->setFont(config->readFontEntry("Font", &f));
    01128 }
    01129
    01130 KateFontStruct *KateRendererConfig::fontStruct ()
    01131 {
    01132   if (m_fontSet || isGlobal())
    01133     return m_font;
    01134
    01135   return s_global->fontStruct ();
    01136 }
    01137
    01138 QFont *KateRendererConfig::font()
    01139 {
    01140   return &(fontStruct ()->myFont);
    01141 }
    01142
    01143 KateFontMetrics *KateRendererConfig::fontMetrics()
    01144 {
    01145   return &(fontStruct ()->myFontMetrics);
    01146 }
    01147
    01148 void KateRendererConfig::setFont(const QFont &font)
    01149 {
    01150   configStart ();
    01151
    01152   if (!m_fontSet)
    01153   {
    01154     m_fontSet = true;
    01155     m_font = new KateFontStruct ();
    01156   }
    01157
    01158   m_font->setFont(font);
    01159
    01160   configEnd ();
    01161 }
    01162
    01163 bool KateRendererConfig::wordWrapMarker () const
    01164 {
    01165   if (m_wordWrapMarkerSet || isGlobal())
    01166     return m_wordWrapMarker;
    01167
    01168   return s_global->wordWrapMarker();
    01169 }
    01170
    01171 void KateRendererConfig::setWordWrapMarker (bool on)
    01172 {
    01173   configStart ();
    01174
    01175   m_wordWrapMarkerSet = true;
    01176   m_wordWrapMarker = on;
    01177
    01178   configEnd ();
    01179 }
    01180
    01181 const QColor& KateRendererConfig::backgroundColor() const
    01182 {
    01183   if (m_backgroundColorSet || isGlobal())
    01184     return m_backgroundColor;
    01185
    01186   return s_global->backgroundColor();
    01187 }
    01188
    01189 void KateRendererConfig::setBackgroundColor (const QColor &col)
    01190 {
    01191   configStart ();
    01192
    01193   m_backgroundColorSet = true;
    01194   m_backgroundColor = col;
    01195
    01196   configEnd ();
    01197 }
    01198
    01199 const QColor& KateRendererConfig::selectionColor() const
    01200 {
    01201   if (m_selectionColorSet || isGlobal())
    01202     return m_selectionColor;
    01203
    01204   return s_global->selectionColor();
    01205 }
    01206
    01207 void KateRendererConfig::setSelectionColor (const QColor &col)
    01208 {
    01209   configStart ();
    01210
    01211   m_selectionColorSet = true;
    01212   m_selectionColor = col;
    01213
    01214   configEnd ();
    01215 }
    01216
    01217 const QColor& KateRendererConfig::highlightedLineColor() const
    01218 {
    01219   if (m_highlightedLineColorSet || isGlobal())
    01220     return m_highlightedLineColor;
    01221
    01222   return s_global->highlightedLineColor();
    01223 }
    01224
    01225 void KateRendererConfig::setHighlightedLineColor (const QColor &col)
    01226 {
    01227   configStart ();
    01228
    01229   m_highlightedLineColorSet = true;
    01230   m_highlightedLineColor = col;
    01231
    01232   configEnd ();
    01233 }
    01234
    01235 const QColor& KateRendererConfig::lineMarkerColor(KTextEditor::MarkInterface::MarkTypes type) const
    01236 {
    01237   int index = 0;
    01238   if (type > 0) { while((type >> index++) ^ 1) {} }
    01239   index -= 1;
    01240
    01241   if ( index < 0 || index >= KTextEditor::MarkInterface::reservedMarkersCount() )
    01242     return QColor();
    01243
    01244   if (m_lineMarkerColorSet[index] || isGlobal())
    01245     return m_lineMarkerColor[index];
    01246
    01247   return s_global->lineMarkerColor( type );
    01248 }
    01249
    01250 void KateRendererConfig::setLineMarkerColor (const QColor &col, KTextEditor::MarkInterface::MarkTypes type)
    01251 {
    01252   int index = static_cast<int>( log(static_cast<double>(type)) / log(2.0) );
    01253   Q_ASSERT( index >= 0 && index < KTextEditor::MarkInterface::reservedMarkersCount() );
    01254   configStart ();
    01255
    01256   m_lineMarkerColorSet[index] = true;
    01257   m_lineMarkerColor[index] = col;
    01258
    01259   configEnd ();
    01260 }
    01261
    01262 const QColor& KateRendererConfig::highlightedBracketColor() const
    01263 {
    01264   if (m_highlightedBracketColorSet || isGlobal())
    01265     return m_highlightedBracketColor;
    01266
    01267   return s_global->highlightedBracketColor();
    01268 }
    01269
    01270 void KateRendererConfig::setHighlightedBracketColor (const QColor &col)
    01271 {
    01272   configStart ();
    01273
    01274   m_highlightedBracketColorSet = true;
    01275   m_highlightedBracketColor = col;
    01276
    01277   configEnd ();
    01278 }
    01279
    01280 const QColor& KateRendererConfig::wordWrapMarkerColor() const
    01281 {
    01282   if (m_wordWrapMarkerColorSet || isGlobal())
    01283     return m_wordWrapMarkerColor;
    01284
    01285   return s_global->wordWrapMarkerColor();
    01286 }
    01287
    01288 void KateRendererConfig::setWordWrapMarkerColor (const QColor &col)
    01289 {
    01290   configStart ();
    01291
    01292   m_wordWrapMarkerColorSet = true;
    01293   m_wordWrapMarkerColor = col;
    01294
    01295   configEnd ();
    01296 }
    01297
    01298 const QColor& KateRendererConfig::tabMarkerColor() const
    01299 {
    01300   if (m_tabMarkerColorSet || isGlobal())
    01301     return m_tabMarkerColor;
    01302
    01303   return s_global->tabMarkerColor();
    01304 }
    01305
    01306 void KateRendererConfig::setTabMarkerColor (const QColor &col)
    01307 {
    01308   configStart ();
    01309
    01310   m_tabMarkerColorSet = true;
    01311   m_tabMarkerColor = col;
    01312
    01313   configEnd ();
    01314 }
    01315
    01316 const QColor& KateRendererConfig::iconBarColor() const
    01317 {
    01318   if (m_iconBarColorSet || isGlobal())
    01319     return m_iconBarColor;
    01320
    01321   return s_global->iconBarColor();
    01322 }
    01323
    01324 void KateRendererConfig::setIconBarColor (const QColor &col)
    01325 {
    01326   configStart ();
    01327
    01328   m_iconBarColorSet = true;
    01329   m_iconBarColor = col;
    01330
    01331   configEnd ();
    01332 }
    01333
    01334 const QColor& KateRendererConfig::lineNumberColor() const
    01335 {
    01336   if (m_lineNumberColorSet || isGlobal())
    01337     return m_lineNumberColor;
    01338
    01339   return s_global->lineNumberColor();
    01340 }
    01341
    01342 void KateRendererConfig::setLineNumberColor (const QColor &col)
    01343 {
    01344   configStart ();
    01345
    01346   m_lineNumberColorSet = true;
    01347   m_lineNumberColor = col;
    01348
    01349   configEnd ();
    01350 }
    01351 //END
    01352
    01353 // kate: space-indent on; indent-width 2; replace-tabs on;

This file is part of the documentation for kate Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:36:30 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003