kate Library API Documentation

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