TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kateschema.cpp 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
  3. Copyright (C) 2002, 2003 Anders Lund <anders.lund@lund.tdcadsl.dk>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License version 2 as published by the Free Software Foundation.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. //BEGIN Includes
  17. #include "kateschema.h"
  18. #include "kateschema.moc"
  19. #include "kateconfig.h"
  20. #include "katedocument.h"
  21. #include "katefactory.h"
  22. #include "kateview.h"
  23. #include "katerenderer.h"
  24. #include <tdelocale.h>
  25. #include <kdialogbase.h>
  26. #include <kcolorbutton.h>
  27. #include <kcombobox.h>
  28. #include <kinputdialog.h>
  29. #include <tdefontdialog.h>
  30. #include <kdebug.h>
  31. #include <kiconloader.h>
  32. #include <tdemessagebox.h>
  33. #include <tdepopupmenu.h>
  34. #include <kcolordialog.h>
  35. #include <tdeapplication.h>
  36. #include <tdeaboutdata.h>
  37. #include <tdetexteditor/markinterface.h>
  38. #include <tqbuttongroup.h>
  39. #include <tqcheckbox.h>
  40. #include <tqptrcollection.h>
  41. #include <tqdialog.h>
  42. #include <tqgrid.h>
  43. #include <tqgroupbox.h>
  44. #include <tqlabel.h>
  45. #include <tqtextcodec.h>
  46. #include <tqlayout.h>
  47. #include <tqlineedit.h>
  48. #include <tqheader.h>
  49. #include <tqlistbox.h>
  50. #include <tqhbox.h>
  51. #include <tqpainter.h>
  52. #include <tqobjectlist.h>
  53. #include <tqpixmap.h>
  54. #include <tqpushbutton.h>
  55. #include <tqradiobutton.h>
  56. #include <tqspinbox.h>
  57. #include <tqstringlist.h>
  58. #include <tqtabwidget.h>
  59. #include <tqvbox.h>
  60. #include <tqvgroupbox.h>
  61. #include <tqwhatsthis.h>
  62. //END
  63. //BEGIN KateStyleListViewItem decl
  64. /*
  65. TQListViewItem subclass to display/edit a style, bold/italic is check boxes,
  66. normal and selected colors are boxes, which will display a color chooser when
  67. activated.
  68. The context name for the style will be drawn using the editor default font and
  69. the chosen colors.
  70. This widget id designed to handle the default as well as the individual hl style
  71. lists.
  72. This widget is designed to work with the KateStyleListView class exclusively.
  73. Added by anders, jan 23 2002.
  74. */
  75. class KateStyleListItem : public TQListViewItem
  76. {
  77. public:
  78. KateStyleListItem( TQListViewItem *parent=0, const TQString & stylename=0,
  79. class KateAttribute* defaultstyle=0, class KateHlItemData *data=0 );
  80. KateStyleListItem( TQListView *parent, const TQString & stylename=0,
  81. class KateAttribute* defaultstyle=0, class KateHlItemData *data=0 );
  82. ~KateStyleListItem() { if (st) delete is; };
  83. /* mainly for readability */
  84. enum Property { ContextName, Bold, Italic, Underline, Strikeout, Color, SelColor, BgColor, SelBgColor, UseDefStyle };
  85. /* initializes the style from the default and the hldata */
  86. void initStyle();
  87. /* updates the hldata's style */
  88. void updateStyle();
  89. /* reimp */
  90. virtual int width ( const TQFontMetrics & fm, const TQListView * lv, int c ) const;
  91. /* calls changeProperty() if it makes sense considering pos. */
  92. void activate( int column, const TQPoint &localPos );
  93. /* For bool fields, toggles them, for color fields, display a color chooser */
  94. void changeProperty( Property p );
  95. /** unset a color.
  96. * c is 100 (BGColor) or 101 (SelectedBGColor) for now.
  97. */
  98. void unsetColor( int c );
  99. /* style context name */
  100. TQString contextName() { return text(0); };
  101. /* only true for a hl mode item using it's default style */
  102. bool defStyle();
  103. /* true for default styles */
  104. bool isDefault();
  105. /* whichever style is active (st for hl mode styles not using
  106. the default style, ds otherwise) */
  107. class KateAttribute* style() { return is; };
  108. protected:
  109. /* reimp */
  110. void paintCell(TQPainter *p, const TQColorGroup& cg, int col, int width, int align);
  111. private:
  112. /* private methods to change properties */
  113. void toggleDefStyle();
  114. void setColor( int );
  115. /* helper function to copy the default style into the KateHlItemData,
  116. when a property is changed and we are using default style. */
  117. class KateAttribute *is, // the style currently in use
  118. *ds; // default style for hl mode contexts and default styles
  119. class KateHlItemData *st; // itemdata for hl mode contexts
  120. };
  121. //END
  122. //BEGIN KateStyleListCaption decl
  123. /*
  124. This is a simple subclass for drawing the language names in a nice treeview
  125. with the styles. It is needed because we do not like to mess with the default
  126. palette of the containing ListView. Only the paintCell method is overwritten
  127. to use our own palette (that is set on the viewport rather than on the listview
  128. itself).
  129. */
  130. class KateStyleListCaption : public TQListViewItem
  131. {
  132. public:
  133. KateStyleListCaption( TQListView *parent, const TQString & name );
  134. ~KateStyleListCaption() {};
  135. protected:
  136. void paintCell(TQPainter *p, const TQColorGroup& cg, int col, int width, int align);
  137. };
  138. //END
  139. //BEGIN KateSchemaManager
  140. TQString KateSchemaManager::normalSchema ()
  141. {
  142. return TDEApplication::kApplication()->aboutData()->appName () + TQString (" - Normal");
  143. }
  144. TQString KateSchemaManager::printingSchema ()
  145. {
  146. return TDEApplication::kApplication()->aboutData()->appName () + TQString (" - Printing");
  147. }
  148. KateSchemaManager::KateSchemaManager ()
  149. : m_config ("kateschemarc", false, false)
  150. {
  151. update ();
  152. }
  153. KateSchemaManager::~KateSchemaManager ()
  154. {
  155. }
  156. //
  157. // read the types from config file and update the internal list
  158. //
  159. void KateSchemaManager::update (bool readfromfile)
  160. {
  161. if (readfromfile)
  162. m_config.reparseConfiguration ();
  163. m_schemas = m_config.groupList();
  164. m_schemas.sort ();
  165. m_schemas.remove (printingSchema());
  166. m_schemas.remove (normalSchema());
  167. m_schemas.prepend (printingSchema());
  168. m_schemas.prepend (normalSchema());
  169. }
  170. //
  171. // get the right group
  172. // special handling of the default schemas ;)
  173. //
  174. TDEConfig *KateSchemaManager::schema (uint number)
  175. {
  176. if ((number>1) && (number < m_schemas.count()))
  177. m_config.setGroup (m_schemas[number]);
  178. else if (number == 1)
  179. m_config.setGroup (printingSchema());
  180. else
  181. m_config.setGroup (normalSchema());
  182. return &m_config;
  183. }
  184. void KateSchemaManager::addSchema (const TQString &t)
  185. {
  186. m_config.setGroup (t);
  187. m_config.writeEntry("Color Background", TDEGlobalSettings::baseColor());
  188. update (false);
  189. }
  190. void KateSchemaManager::removeSchema (uint number)
  191. {
  192. if (number >= m_schemas.count())
  193. return;
  194. if (number < 2)
  195. return;
  196. m_config.deleteGroup (name (number));
  197. update (false);
  198. }
  199. bool KateSchemaManager::validSchema (uint number)
  200. {
  201. if (number < m_schemas.count())
  202. return true;
  203. return false;
  204. }
  205. uint KateSchemaManager::number (const TQString &name)
  206. {
  207. if (name == normalSchema())
  208. return 0;
  209. if (name == printingSchema())
  210. return 1;
  211. int i;
  212. if ((i = m_schemas.findIndex(name)) > -1)
  213. return i;
  214. return 0;
  215. }
  216. TQString KateSchemaManager::name (uint number)
  217. {
  218. if ((number>1) && (number < m_schemas.count()))
  219. return m_schemas[number];
  220. else if (number == 1)
  221. return printingSchema();
  222. return normalSchema();
  223. }
  224. //END
  225. //
  226. // DIALOGS !!!
  227. //
  228. //BEGIN KateSchemaConfigColorTab -- 'Colors' tab
  229. KateSchemaConfigColorTab::KateSchemaConfigColorTab( TQWidget *parent, const char * )
  230. : TQWidget (parent)
  231. {
  232. m_schema = -1;
  233. TQHBox *b;
  234. TQLabel *label;
  235. TQVBoxLayout *blay=new TQVBoxLayout(this, 0, KDialog::spacingHint());
  236. TQVGroupBox *gbTextArea = new TQVGroupBox(i18n("Text Area Background"), this);
  237. b = new TQHBox (gbTextArea);
  238. b->setSpacing(KDialog::spacingHint());
  239. label = new TQLabel( i18n("Normal text:"), b);
  240. label->setAlignment( AlignLeft|AlignVCenter);
  241. m_back = new KColorButton(b);
  242. b = new TQHBox (gbTextArea);
  243. b->setSpacing(KDialog::spacingHint());
  244. label = new TQLabel( i18n("Selected text:"), b);
  245. label->setAlignment( AlignLeft|AlignVCenter);
  246. m_selected = new KColorButton(b);
  247. b = new TQHBox (gbTextArea);
  248. b->setSpacing(KDialog::spacingHint());
  249. label = new TQLabel( i18n("Current line:"), b);
  250. label->setAlignment( AlignLeft|AlignVCenter);
  251. m_current = new KColorButton(b);
  252. // Markers from tdelibs/interfaces/ktextinterface/markinterface.h
  253. b = new TQHBox (gbTextArea);
  254. b->setSpacing(KDialog::spacingHint());
  255. m_combobox = new KComboBox(b, "color_combo_box");
  256. // add the predefined mark types as defined in markinterface.h
  257. m_combobox->insertItem(i18n("Bookmark")); // markType01
  258. m_combobox->insertItem(i18n("Active Breakpoint")); // markType02
  259. m_combobox->insertItem(i18n("Reached Breakpoint")); // markType03
  260. m_combobox->insertItem(i18n("Disabled Breakpoint")); // markType04
  261. m_combobox->insertItem(i18n("Execution")); // markType05
  262. m_combobox->insertItem(i18n("Warning")); // markType06
  263. m_combobox->insertItem(i18n("Error")); // markType07
  264. m_combobox->setCurrentItem(0);
  265. m_markers = new KColorButton(b, "marker_color_button");
  266. connect( m_combobox, TQT_SIGNAL( activated( int ) ), TQT_SLOT( slotComboBoxChanged( int ) ) );
  267. blay->addWidget(gbTextArea);
  268. TQVGroupBox *gbBorder = new TQVGroupBox(i18n("Additional Elements"), this);
  269. b = new TQHBox (gbBorder);
  270. b->setSpacing(KDialog::spacingHint());
  271. label = new TQLabel( i18n("Left border background:"), b);
  272. label->setAlignment( AlignLeft|AlignVCenter);
  273. m_iconborder = new KColorButton(b);
  274. b = new TQHBox (gbBorder);
  275. b->setSpacing(KDialog::spacingHint());
  276. label = new TQLabel( i18n("Line numbers:"), b);
  277. label->setAlignment( AlignLeft|AlignVCenter);
  278. m_linenumber = new KColorButton(b);
  279. b = new TQHBox (gbBorder);
  280. b->setSpacing(KDialog::spacingHint());
  281. label = new TQLabel( i18n("Bracket highlight:"), b);
  282. label->setAlignment( AlignLeft|AlignVCenter);
  283. m_bracket = new KColorButton(b);
  284. b = new TQHBox (gbBorder);
  285. b->setSpacing(KDialog::spacingHint());
  286. label = new TQLabel( i18n("Word wrap markers:"), b);
  287. label->setAlignment( AlignLeft|AlignVCenter);
  288. m_wwmarker = new KColorButton(b);
  289. b = new TQHBox (gbBorder);
  290. b->setSpacing(KDialog::spacingHint());
  291. label = new TQLabel( i18n("Tab markers:"), b);
  292. label->setAlignment( AlignLeft|AlignVCenter);
  293. m_tmarker = new KColorButton(b);
  294. blay->addWidget(gbBorder);
  295. blay->addStretch();
  296. // connect signal changed(); changed is emitted by a ColorButton change!
  297. connect( this, TQT_SIGNAL( changed() ), parent->parentWidget(), TQT_SLOT( slotChanged() ) );
  298. // TQWhatsThis help
  299. TQWhatsThis::add(m_back, i18n("<p>Sets the background color of the editing area.</p>"));
  300. TQWhatsThis::add(m_selected, i18n("<p>Sets the background color of the selection.</p>"
  301. "<p>To set the text color for selected text, use the \"<b>Configure "
  302. "Highlighting</b>\" dialog.</p>"));
  303. TQWhatsThis::add(m_markers, i18n("<p>Sets the background color of the selected "
  304. "marker type.</p><p><b>Note</b>: The marker color is displayed lightly because "
  305. "of transparency.</p>"));
  306. TQWhatsThis::add(m_combobox, i18n("<p>Select the marker type you want to change.</p>"));
  307. TQWhatsThis::add(m_current, i18n("<p>Sets the background color of the currently "
  308. "active line, which means the line where your cursor is positioned.</p>"));
  309. TQWhatsThis::add( m_linenumber, i18n(
  310. "<p>This color will be used to draw the line numbers (if enabled) and the "
  311. "lines in the code-folding pane.</p>" ) );
  312. TQWhatsThis::add(m_bracket, i18n("<p>Sets the bracket matching color. This means, "
  313. "if you place the cursor e.g. at a <b>(</b>, the matching <b>)</b> will "
  314. "be highlighted with this color.</p>"));
  315. TQWhatsThis::add(m_wwmarker, i18n(
  316. "<p>Sets the color of Word Wrap-related markers:</p>"
  317. "<dl><dt>Static Word Wrap</dt><dd>A vertical line which shows the column where "
  318. "text is going to be wrapped</dd>"
  319. "<dt>Dynamic Word Wrap</dt><dd>An arrow shown to the left of "
  320. "visually-wrapped lines</dd></dl>"));
  321. TQWhatsThis::add(m_tmarker, i18n(
  322. "<p>Sets the color of the tabulator marks:</p>"));
  323. }
  324. KateSchemaConfigColorTab::~KateSchemaConfigColorTab()
  325. {
  326. }
  327. void KateSchemaConfigColorTab::schemaChanged ( int newSchema )
  328. {
  329. // save curent schema
  330. if ( m_schema > -1 )
  331. {
  332. m_schemas[ m_schema ].back = m_back->color();
  333. m_schemas[ m_schema ].selected = m_selected->color();
  334. m_schemas[ m_schema ].current = m_current->color();
  335. m_schemas[ m_schema ].bracket = m_bracket->color();
  336. m_schemas[ m_schema ].wwmarker = m_wwmarker->color();
  337. m_schemas[ m_schema ].iconborder = m_iconborder->color();
  338. m_schemas[ m_schema ].tmarker = m_tmarker->color();
  339. m_schemas[ m_schema ].linenumber = m_linenumber->color();
  340. }
  341. if ( newSchema == m_schema ) return;
  342. // switch
  343. m_schema = newSchema;
  344. // first disconnect all signals otherwise setColor emits changed
  345. m_back ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  346. m_selected ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  347. m_current ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  348. m_bracket ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  349. m_wwmarker ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  350. m_iconborder->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  351. m_tmarker ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  352. m_markers ->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  353. m_linenumber->disconnect( TQT_SIGNAL( changed( const TQColor & ) ) );
  354. // If we havent this schema, read in from config file
  355. if ( ! m_schemas.contains( newSchema ) )
  356. {
  357. // fallback defaults
  358. TQColor tmp0 (TDEGlobalSettings::baseColor());
  359. TQColor tmp1 (TDEGlobalSettings::highlightColor());
  360. TQColor tmp2 (TDEGlobalSettings::alternateBackgroundColor());
  361. TQColor tmp3 ( "#FFFF99" );
  362. TQColor tmp4 (tmp2.dark());
  363. TQColor tmp5 ( TDEGlobalSettings::textColor() );
  364. TQColor tmp6 ( "#EAE9E8" );
  365. TQColor tmp7 ( "#000000" );
  366. // same std colors like in KateDocument::markColor
  367. TQValueVector <TQColor> mark(KTextEditor::MarkInterface::reservedMarkersCount());
  368. Q_ASSERT(mark.size() > 6);
  369. mark[0] = Qt::blue;
  370. mark[1] = Qt::red;
  371. mark[2] = Qt::yellow;
  372. mark[3] = Qt::magenta;
  373. mark[4] = Qt::gray;
  374. mark[5] = Qt::green;
  375. mark[6] = Qt::red;
  376. SchemaColors c;
  377. TDEConfig *config = KateFactory::self()->schemaManager()->schema(newSchema);
  378. c.back= config->readColorEntry("Color Background", &tmp0);
  379. c.selected = config->readColorEntry("Color Selection", &tmp1);
  380. c.current = config->readColorEntry("Color Highlighted Line", &tmp2);
  381. c.bracket = config->readColorEntry("Color Highlighted Bracket", &tmp3);
  382. c.wwmarker = config->readColorEntry("Color Word Wrap Marker", &tmp4);
  383. c.tmarker = config->readColorEntry("Color Tab Marker", &tmp5);
  384. c.iconborder = config->readColorEntry("Color Icon Bar", &tmp6);
  385. c.linenumber = config->readColorEntry("Color Line Number", &tmp7);
  386. for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
  387. c.markerColors[i] = config->readColorEntry( TQString("Color MarkType%1").arg(i+1), &mark[i] );
  388. m_schemas[ newSchema ] = c;
  389. }
  390. m_back->setColor( m_schemas[ newSchema ].back);
  391. m_selected->setColor( m_schemas [ newSchema ].selected );
  392. m_current->setColor( m_schemas [ newSchema ].current );
  393. m_bracket->setColor( m_schemas [ newSchema ].bracket );
  394. m_wwmarker->setColor( m_schemas [ newSchema ].wwmarker );
  395. m_tmarker->setColor( m_schemas [ newSchema ].tmarker );
  396. m_iconborder->setColor( m_schemas [ newSchema ].iconborder );
  397. m_linenumber->setColor( m_schemas [ newSchema ].linenumber );
  398. // map from 0..reservedMarkersCount()-1 - the same index as in markInterface
  399. for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
  400. {
  401. TQPixmap pix(16, 16);
  402. pix.fill( m_schemas [ newSchema ].markerColors[i]);
  403. m_combobox->changeItem(pix, m_combobox->text(i), i);
  404. }
  405. m_markers->setColor( m_schemas [ newSchema ].markerColors[ m_combobox->currentItem() ] );
  406. connect( m_back , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  407. connect( m_selected , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  408. connect( m_current , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  409. connect( m_bracket , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  410. connect( m_wwmarker , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  411. connect( m_iconborder, TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  412. connect( m_tmarker , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  413. connect( m_linenumber, TQT_SIGNAL( changed( const TQColor& ) ), TQT_SIGNAL( changed() ) );
  414. connect( m_markers , TQT_SIGNAL( changed( const TQColor& ) ), TQT_SLOT( slotMarkerColorChanged( const TQColor& ) ) );
  415. }
  416. void KateSchemaConfigColorTab::apply ()
  417. {
  418. schemaChanged( m_schema );
  419. TQMap<int,SchemaColors>::Iterator it;
  420. for ( it = m_schemas.begin(); it != m_schemas.end(); ++it )
  421. {
  422. kdDebug(13030)<<"APPLY scheme = "<<it.key()<<endl;
  423. TDEConfig *config = KateFactory::self()->schemaManager()->schema( it.key() );
  424. kdDebug(13030)<<"Using config group "<<config->group()<<endl;
  425. SchemaColors c = it.data();
  426. config->writeEntry("Color Background", c.back);
  427. config->writeEntry("Color Selection", c.selected);
  428. config->writeEntry("Color Highlighted Line", c.current);
  429. config->writeEntry("Color Highlighted Bracket", c.bracket);
  430. config->writeEntry("Color Word Wrap Marker", c.wwmarker);
  431. config->writeEntry("Color Tab Marker", c.tmarker);
  432. config->writeEntry("Color Icon Bar", c.iconborder);
  433. config->writeEntry("Color Line Number", c.linenumber);
  434. for (int i = 0; i < KTextEditor::MarkInterface::reservedMarkersCount(); i++)
  435. {
  436. config->writeEntry(TQString("Color MarkType%1").arg(i + 1), c.markerColors[i]);
  437. }
  438. }
  439. }
  440. void KateSchemaConfigColorTab::slotMarkerColorChanged( const TQColor& color)
  441. {
  442. int index = m_combobox->currentItem();
  443. m_schemas[ m_schema ].markerColors[ index ] = color;
  444. TQPixmap pix(16, 16);
  445. pix.fill(color);
  446. m_combobox->changeItem(pix, m_combobox->text(index), index);
  447. emit changed();
  448. }
  449. void KateSchemaConfigColorTab::slotComboBoxChanged(int index)
  450. {
  451. // temporarily disconnect the changed-signal because setColor emits changed as well
  452. m_markers->disconnect( TQT_SIGNAL( changed( const TQColor& ) ) );
  453. m_markers->setColor( m_schemas[m_schema].markerColors[index] );
  454. connect( m_markers, TQT_SIGNAL( changed( const TQColor& ) ), TQT_SLOT( slotMarkerColorChanged( const TQColor& ) ) );
  455. }
  456. //END KateSchemaConfigColorTab
  457. //BEGIN FontConfig -- 'Fonts' tab
  458. KateSchemaConfigFontTab::KateSchemaConfigFontTab( TQWidget *parent, const char * )
  459. : TQWidget (parent)
  460. {
  461. // sizemanagment
  462. TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
  463. m_fontchooser = new TDEFontChooser ( this, 0L, false, TQStringList(), false );
  464. m_fontchooser->enableColumn(TDEFontChooser::StyleList, false);
  465. grid->addWidget( m_fontchooser, 0, 0);
  466. connect (this, TQT_SIGNAL( changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
  467. m_schema = -1;
  468. }
  469. KateSchemaConfigFontTab::~KateSchemaConfigFontTab()
  470. {
  471. }
  472. void KateSchemaConfigFontTab::slotFontSelected( const TQFont &font )
  473. {
  474. if ( m_schema > -1 )
  475. {
  476. m_fonts[m_schema] = font;
  477. emit changed();
  478. }
  479. }
  480. void KateSchemaConfigFontTab::apply()
  481. {
  482. FontMap::Iterator it;
  483. for ( it = m_fonts.begin(); it != m_fonts.end(); ++it )
  484. {
  485. KateFactory::self()->schemaManager()->schema( it.key() )->writeEntry( "Font", it.data() );
  486. }
  487. }
  488. void KateSchemaConfigFontTab::schemaChanged( int newSchema )
  489. {
  490. if ( m_schema > -1 )
  491. m_fonts[ m_schema ] = m_fontchooser->font();
  492. m_schema = newSchema;
  493. TQFont f (TDEGlobalSettings::fixedFont());
  494. m_fontchooser->disconnect ( this );
  495. m_fontchooser->setFont ( KateFactory::self()->schemaManager()->schema( newSchema )->readFontEntry("Font", &f) );
  496. m_fonts[ newSchema ] = m_fontchooser->font();
  497. connect (m_fontchooser, TQT_SIGNAL (fontSelected( const TQFont & )), this, TQT_SLOT (slotFontSelected( const TQFont & )));
  498. }
  499. //END FontConfig
  500. //BEGIN FontColorConfig -- 'Normal Text Styles' tab
  501. KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab( TQWidget *parent, const char * )
  502. : TQWidget (parent)
  503. {
  504. m_defaultStyleLists.setAutoDelete(true);
  505. // sizemanagment
  506. TQGridLayout *grid = new TQGridLayout( this, 1, 1 );
  507. m_defaultStyles = new KateStyleListView( this, false );
  508. grid->addWidget( m_defaultStyles, 0, 0);
  509. connect (m_defaultStyles, TQT_SIGNAL (changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
  510. TQWhatsThis::add( m_defaultStyles, i18n(
  511. "This list displays the default styles for the current schema and "
  512. "offers the means to edit them. The style name reflects the current "
  513. "style settings."
  514. "<p>To edit the colors, click the colored squares, or select the color "
  515. "to edit from the popup menu.<p>You can unset the Background and Selected "
  516. "Background colors from the popup menu when appropriate.") );
  517. }
  518. KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab()
  519. {
  520. }
  521. KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema)
  522. {
  523. if (!m_defaultStyleLists[schema])
  524. {
  525. KateAttributeList *list = new KateAttributeList ();
  526. KateHlManager::self()->getDefaults(schema, *list);
  527. m_defaultStyleLists.insert (schema, list);
  528. }
  529. return m_defaultStyleLists[schema];
  530. }
  531. void KateSchemaConfigFontColorTab::schemaChanged (uint schema)
  532. {
  533. m_defaultStyles->clear ();
  534. KateAttributeList *l = attributeList (schema);
  535. // set colors
  536. TQPalette p ( m_defaultStyles->palette() );
  537. TQColor _c ( TDEGlobalSettings::baseColor() );
  538. p.setColor( TQColorGroup::Base,
  539. KateFactory::self()->schemaManager()->schema(schema)->
  540. readColorEntry( "Color Background", &_c ) );
  541. _c = TDEGlobalSettings::highlightColor();
  542. p.setColor( TQColorGroup::Highlight,
  543. KateFactory::self()->schemaManager()->schema(schema)->
  544. readColorEntry( "Color Selection", &_c ) );
  545. _c = l->at(0)->textColor(); // not quite as much of an assumption ;)
  546. p.setColor( TQColorGroup::Text, _c );
  547. m_defaultStyles->viewport()->setPalette( p );
  548. // insert the default styles backwards to get them in the right order
  549. for ( int i = KateHlManager::self()->defaultStyles() - 1; i >= 0; i-- )
  550. {
  551. new KateStyleListItem( m_defaultStyles, KateHlManager::self()->defaultStyleName(i, true), l->at( i ) );
  552. }
  553. }
  554. void KateSchemaConfigFontColorTab::reload ()
  555. {
  556. m_defaultStyles->clear ();
  557. m_defaultStyleLists.clear ();
  558. }
  559. void KateSchemaConfigFontColorTab::apply ()
  560. {
  561. for ( TQIntDictIterator<KateAttributeList> it( m_defaultStyleLists ); it.current(); ++it )
  562. KateHlManager::self()->setDefaults(it.currentKey(), *(it.current()));
  563. }
  564. //END FontColorConfig
  565. //BEGIN KateSchemaConfigHighlightTab -- 'Highlighting Text Styles' tab
  566. KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab( TQWidget *parent, const char *, KateSchemaConfigFontColorTab *page, uint hl )
  567. : TQWidget (parent)
  568. {
  569. m_defaults = page;
  570. m_schema = 0;
  571. m_hl = 0;
  572. m_hlDict.setAutoDelete (true);
  573. TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
  574. // hl chooser
  575. TQHBox *hbHl = new TQHBox( this );
  576. layout->add (hbHl);
  577. hbHl->setSpacing( KDialog::spacingHint() );
  578. TQLabel *lHl = new TQLabel( i18n("H&ighlight:"), hbHl );
  579. hlCombo = new TQComboBox( false, hbHl );
  580. lHl->setBuddy( hlCombo );
  581. connect( hlCombo, TQT_SIGNAL(activated(int)),
  582. this, TQT_SLOT(hlChanged(int)) );
  583. for( int i = 0; i < KateHlManager::self()->highlights(); i++) {
  584. if (KateHlManager::self()->hlSection(i).length() > 0)
  585. hlCombo->insertItem(KateHlManager::self()->hlSection(i) + TQString ("/") + KateHlManager::self()->hlNameTranslated(i));
  586. else
  587. hlCombo->insertItem(KateHlManager::self()->hlNameTranslated(i));
  588. }
  589. hlCombo->setCurrentItem(0);
  590. // styles listview
  591. m_styles = new KateStyleListView( this, true );
  592. layout->addWidget (m_styles, 999);
  593. hlCombo->setCurrentItem ( hl );
  594. hlChanged ( hl );
  595. TQWhatsThis::add( m_styles, i18n(
  596. "This list displays the contexts of the current syntax highlight mode and "
  597. "offers the means to edit them. The context name reflects the current "
  598. "style settings.<p>To edit using the keyboard, press "
  599. "<strong>&lt;SPACE&gt;</strong> and choose a property from the popup menu."
  600. "<p>To edit the colors, click the colored squares, or select the color "
  601. "to edit from the popup menu.<p>You can unset the Background and Selected "
  602. "Background colors from the context menu when appropriate.") );
  603. connect (m_styles, TQT_SIGNAL (changed()), parent->parentWidget(), TQT_SLOT (slotChanged()));
  604. }
  605. KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab()
  606. {
  607. }
  608. void KateSchemaConfigHighlightTab::hlChanged(int z)
  609. {
  610. m_hl = z;
  611. schemaChanged (m_schema);
  612. }
  613. void KateSchemaConfigHighlightTab::schemaChanged (uint schema)
  614. {
  615. m_schema = schema;
  616. kdDebug(13030) << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl << endl;
  617. m_styles->clear ();
  618. if (!m_hlDict[m_schema])
  619. {
  620. kdDebug(13030) << "NEW SCHEMA, create dict" << endl;
  621. m_hlDict.insert (schema, new TQIntDict<KateHlItemDataList>);
  622. m_hlDict[m_schema]->setAutoDelete (true);
  623. }
  624. if (!m_hlDict[m_schema]->find(m_hl))
  625. {
  626. kdDebug(13030) << "NEW HL, create list" << endl;
  627. KateHlItemDataList *list = new KateHlItemDataList ();
  628. KateHlManager::self()->getHl( m_hl )->getKateHlItemDataListCopy (m_schema, *list);
  629. m_hlDict[m_schema]->insert (m_hl, list);
  630. }
  631. KateAttributeList *l = m_defaults->attributeList (schema);
  632. // Set listview colors
  633. // We do that now, because we can now get the "normal text" color.
  634. // TODO this reads of the TDEConfig object, which should be changed when
  635. // the color tab is fixed.
  636. TQPalette p ( m_styles->palette() );
  637. TQColor _c ( TDEGlobalSettings::baseColor() );
  638. p.setColor( TQColorGroup::Base,
  639. KateFactory::self()->schemaManager()->schema(m_schema)->
  640. readColorEntry( "Color Background", &_c ) );
  641. _c = TDEGlobalSettings::highlightColor();
  642. p.setColor( TQColorGroup::Highlight,
  643. KateFactory::self()->schemaManager()->schema(m_schema)->
  644. readColorEntry( "Color Selection", &_c ) );
  645. _c = l->at(0)->textColor(); // not quite as much of an assumption ;)
  646. p.setColor( TQColorGroup::Text, _c );
  647. m_styles->viewport()->setPalette( p );
  648. TQDict<KateStyleListCaption> prefixes;
  649. for ( KateHlItemData *itemData = m_hlDict[m_schema]->find(m_hl)->last();
  650. itemData != 0L;
  651. itemData = m_hlDict[m_schema]->find(m_hl)->prev())
  652. {
  653. kdDebug(13030) << "insert items " << itemData->name << endl;
  654. // All stylenames have their language mode prefixed, e.g. HTML:Comment
  655. // split them and put them into nice substructures.
  656. int c = itemData->name.find(':');
  657. if ( c > 0 ) {
  658. TQString prefix = itemData->name.left(c);
  659. TQString name = itemData->name.mid(c+1);
  660. KateStyleListCaption *parent = prefixes.find( prefix );
  661. if ( ! parent )
  662. {
  663. parent = new KateStyleListCaption( m_styles, prefix );
  664. parent->setOpen(true);
  665. prefixes.insert( prefix, parent );
  666. }
  667. new KateStyleListItem( parent, name, l->at(itemData->defStyleNum), itemData );
  668. } else {
  669. new KateStyleListItem( m_styles, itemData->name, l->at(itemData->defStyleNum), itemData );
  670. }
  671. }
  672. }
  673. void KateSchemaConfigHighlightTab::reload ()
  674. {
  675. m_styles->clear ();
  676. m_hlDict.clear ();
  677. hlChanged (0);
  678. }
  679. void KateSchemaConfigHighlightTab::apply ()
  680. {
  681. for ( TQIntDictIterator< TQIntDict<KateHlItemDataList> > it( m_hlDict ); it.current(); ++it )
  682. for ( TQIntDictIterator< KateHlItemDataList > it2( *it.current() ); it2.current(); ++it2 )
  683. {
  684. KateHlManager::self()->getHl( it2.currentKey() )->setKateHlItemDataList (it.currentKey(), *(it2.current()));
  685. }
  686. }
  687. //END KateSchemaConfigHighlightTab
  688. //BEGIN KateSchemaConfigPage -- Main dialog page
  689. KateSchemaConfigPage::KateSchemaConfigPage( TQWidget *parent, KateDocument *doc )
  690. : KateConfigPage( parent ),
  691. m_lastSchema (-1)
  692. {
  693. TQVBoxLayout *layout = new TQVBoxLayout(this, 0, KDialog::spacingHint() );
  694. TQHBox *hbHl = new TQHBox( this );
  695. layout->add (hbHl);
  696. hbHl->setSpacing( KDialog::spacingHint() );
  697. TQLabel *lHl = new TQLabel( i18n("&Schema:"), hbHl );
  698. schemaCombo = new TQComboBox( false, hbHl );
  699. lHl->setBuddy( schemaCombo );
  700. connect( schemaCombo, TQT_SIGNAL(activated(int)),
  701. this, TQT_SLOT(schemaChanged(int)) );
  702. TQPushButton *btnnew = new TQPushButton( i18n("&New..."), hbHl );
  703. connect( btnnew, TQT_SIGNAL(clicked()), this, TQT_SLOT(newSchema()) );
  704. btndel = new TQPushButton( i18n("&Delete"), hbHl );
  705. connect( btndel, TQT_SIGNAL(clicked()), this, TQT_SLOT(deleteSchema()) );
  706. m_tabWidget = new TQTabWidget ( this );
  707. m_tabWidget->setMargin (KDialog::marginHint());
  708. layout->add (m_tabWidget);
  709. connect (m_tabWidget, TQT_SIGNAL (currentChanged (TQWidget *)), this, TQT_SLOT (newCurrentPage (TQWidget *)));
  710. m_colorTab = new KateSchemaConfigColorTab (m_tabWidget);
  711. m_tabWidget->addTab (m_colorTab, i18n("Colors"));
  712. m_fontTab = new KateSchemaConfigFontTab (m_tabWidget);
  713. m_tabWidget->addTab (m_fontTab, i18n("Font"));
  714. m_fontColorTab = new KateSchemaConfigFontColorTab (m_tabWidget);
  715. m_tabWidget->addTab (m_fontColorTab, i18n("Normal Text Styles"));
  716. uint hl = doc ? doc->hlMode() : 0;
  717. m_highlightTab = new KateSchemaConfigHighlightTab (m_tabWidget, "", m_fontColorTab, hl );
  718. m_tabWidget->addTab (m_highlightTab, i18n("Highlighting Text Styles"));
  719. hbHl = new TQHBox( this );
  720. layout->add (hbHl);
  721. hbHl->setSpacing( KDialog::spacingHint() );
  722. lHl = new TQLabel( i18n("&Default schema for %1:").arg(TDEApplication::kApplication()->aboutData()->programName ()), hbHl );
  723. defaultSchemaCombo = new TQComboBox( false, hbHl );
  724. lHl->setBuddy( defaultSchemaCombo );
  725. m_defaultSchema = (doc && doc->activeView()) ? doc->activeView()->renderer()->config()->schema() : KateRendererConfig::global()->schema();
  726. reload();
  727. connect( defaultSchemaCombo, TQT_SIGNAL(activated(int)),
  728. this, TQT_SLOT(slotChanged()) );
  729. }
  730. KateSchemaConfigPage::~KateSchemaConfigPage ()
  731. {
  732. // just reload config from disc
  733. KateFactory::self()->schemaManager()->update ();
  734. }
  735. void KateSchemaConfigPage::apply()
  736. {
  737. m_colorTab->apply();
  738. m_fontTab->apply();
  739. m_fontColorTab->apply ();
  740. m_highlightTab->apply ();
  741. // just sync the config
  742. KateFactory::self()->schemaManager()->schema (0)->sync();
  743. KateFactory::self()->schemaManager()->update ();
  744. // clear all attributes
  745. for (int i = 0; i < KateHlManager::self()->highlights(); ++i)
  746. KateHlManager::self()->getHl (i)->clearAttributeArrays ();
  747. // than reload the whole stuff
  748. KateRendererConfig::global()->setSchema (defaultSchemaCombo->currentItem());
  749. KateRendererConfig::global()->reloadSchema();
  750. // sync the hl config for real
  751. KateHlManager::self()->getTDEConfig()->sync ();
  752. }
  753. void KateSchemaConfigPage::reload()
  754. {
  755. // just reload the config from disc
  756. KateFactory::self()->schemaManager()->update ();
  757. // special for the highlighting stuff
  758. m_fontColorTab->reload ();
  759. update ();
  760. defaultSchemaCombo->setCurrentItem (KateRendererConfig::global()->schema());
  761. // initialize to the schema in the current document, or default schema
  762. schemaCombo->setCurrentItem( m_defaultSchema );
  763. schemaChanged( m_defaultSchema );
  764. }
  765. void KateSchemaConfigPage::reset()
  766. {
  767. reload ();
  768. }
  769. void KateSchemaConfigPage::defaults()
  770. {
  771. reload ();
  772. }
  773. void KateSchemaConfigPage::update ()
  774. {
  775. // soft update, no load from disk
  776. KateFactory::self()->schemaManager()->update (false);
  777. schemaCombo->clear ();
  778. schemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
  779. defaultSchemaCombo->clear ();
  780. defaultSchemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ());
  781. schemaCombo->setCurrentItem (0);
  782. schemaChanged (0);
  783. schemaCombo->setEnabled (schemaCombo->count() > 0);
  784. }
  785. void KateSchemaConfigPage::deleteSchema ()
  786. {
  787. int t = schemaCombo->currentItem ();
  788. KateFactory::self()->schemaManager()->removeSchema (t);
  789. update ();
  790. }
  791. void KateSchemaConfigPage::newSchema ()
  792. {
  793. TQString t = KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:"), i18n("New Schema"), 0, this);
  794. KateFactory::self()->schemaManager()->addSchema (t);
  795. // soft update, no load from disk
  796. KateFactory::self()->schemaManager()->update (false);
  797. int i = KateFactory::self()->schemaManager()->list ().findIndex (t);
  798. update ();
  799. if (i > -1)
  800. {
  801. schemaCombo->setCurrentItem (i);
  802. schemaChanged (i);
  803. }
  804. }
  805. void KateSchemaConfigPage::schemaChanged (int schema)
  806. {
  807. btndel->setEnabled( schema > 1 );
  808. m_colorTab->schemaChanged( schema );
  809. m_fontTab->schemaChanged( schema );
  810. m_fontColorTab->schemaChanged (schema);
  811. m_highlightTab->schemaChanged (schema);
  812. m_lastSchema = schema;
  813. }
  814. void KateSchemaConfigPage::newCurrentPage (TQWidget *w)
  815. {
  816. if (w == m_highlightTab)
  817. m_highlightTab->schemaChanged (m_lastSchema);
  818. }
  819. //END KateSchemaConfigPage
  820. //BEGIN SCHEMA ACTION -- the 'View->Schema' menu action
  821. void KateViewSchemaAction::init()
  822. {
  823. m_view = 0;
  824. last = 0;
  825. connect(popupMenu(),TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(slotAboutToShow()));
  826. }
  827. void KateViewSchemaAction::updateMenu (KateView *view)
  828. {
  829. m_view = view;
  830. }
  831. void KateViewSchemaAction::slotAboutToShow()
  832. {
  833. KateView *view=m_view;
  834. int count = KateFactory::self()->schemaManager()->list().count();
  835. for (int z=0; z<count; z++)
  836. {
  837. TQString hlName = KateFactory::self()->schemaManager()->list().operator[](z);
  838. if (names.contains(hlName) < 1)
  839. {
  840. names << hlName;
  841. popupMenu()->insertItem ( hlName, this, TQT_SLOT(setSchema(int)), 0, z+1);
  842. }
  843. }
  844. if (!view) return;
  845. popupMenu()->setItemChecked (last, false);
  846. popupMenu()->setItemChecked (view->renderer()->config()->schema()+1, true);
  847. last = view->renderer()->config()->schema()+1;
  848. }
  849. void KateViewSchemaAction::setSchema (int mode)
  850. {
  851. KateView *view=m_view;
  852. if (view)
  853. view->renderer()->config()->setSchema (mode-1);
  854. }
  855. //END SCHEMA ACTION
  856. //BEGIN KateStyleListView
  857. KateStyleListView::KateStyleListView( TQWidget *parent, bool showUseDefaults )
  858. : TQListView( parent )
  859. {
  860. setSorting( -1 ); // disable sorting, let the styles appear in their defined order
  861. addColumn( i18n("Context") );
  862. addColumn( SmallIconSet("text_bold"), TQString::null );
  863. addColumn( SmallIconSet("text_italic"), TQString::null );
  864. addColumn( SmallIconSet("text_under"), TQString::null );
  865. addColumn( SmallIconSet("text_strike"), TQString::null );
  866. addColumn( i18n("Normal") );
  867. addColumn( i18n("Selected") );
  868. addColumn( i18n("Background") );
  869. addColumn( i18n("Background Selected") );
  870. if ( showUseDefaults )
  871. addColumn( i18n("Use Default Style") );
  872. connect( this, TQT_SIGNAL(mouseButtonPressed(int, TQListViewItem*, const TQPoint&, int)),
  873. this, TQT_SLOT(slotMousePressed(int, TQListViewItem*, const TQPoint&, int)) );
  874. connect( this, TQT_SIGNAL(contextMenuRequested(TQListViewItem*,const TQPoint&, int)),
  875. this, TQT_SLOT(showPopupMenu(TQListViewItem*, const TQPoint&)) );
  876. // grap the bg color, selected color and default font
  877. normalcol = TDEGlobalSettings::textColor();
  878. bgcol = KateRendererConfig::global()->backgroundColor();
  879. selcol = KateRendererConfig::global()->selectionColor();
  880. docfont = *KateRendererConfig::global()->font();
  881. viewport()->setPaletteBackgroundColor( bgcol );
  882. }
  883. void KateStyleListView::showPopupMenu( KateStyleListItem *i, const TQPoint &globalPos, bool showtitle )
  884. {
  885. if ( !dynamic_cast<KateStyleListItem*>(i) ) return;
  886. TDEPopupMenu m( this );
  887. KateAttribute *is = i->style();
  888. int id;
  889. // the title is used, because the menu obscures the context name when
  890. // displayed on behalf of spacePressed().
  891. TQPixmap cl(16,16);
  892. cl.fill( i->style()->textColor() );
  893. TQPixmap scl(16,16);
  894. scl.fill( i->style()->selectedTextColor() );
  895. TQPixmap bgcl(16,16);
  896. bgcl.fill( i->style()->itemSet(KateAttribute::BGColor) ? i->style()->bgColor() : viewport()->colorGroup().base() );
  897. TQPixmap sbgcl(16,16);
  898. sbgcl.fill( i->style()->itemSet(KateAttribute::SelectedBGColor) ? i->style()->selectedBGColor() : viewport()->colorGroup().base() );
  899. if ( showtitle )
  900. m.insertTitle( i->contextName(), KateStyleListItem::ContextName );
  901. id = m.insertItem( i18n("&Bold"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Bold );
  902. m.setItemChecked( id, is->bold() );
  903. id = m.insertItem( i18n("&Italic"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Italic );
  904. m.setItemChecked( id, is->italic() );
  905. id = m.insertItem( i18n("&Underline"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Underline );
  906. m.setItemChecked( id, is->underline() );
  907. id = m.insertItem( i18n("S&trikeout"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Strikeout );
  908. m.setItemChecked( id, is->strikeOut() );
  909. m.insertSeparator();
  910. m.insertItem( TQIconSet(cl), i18n("Normal &Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Color );
  911. m.insertItem( TQIconSet(scl), i18n("&Selected Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelColor );
  912. m.insertItem( TQIconSet(bgcl), i18n("&Background Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::BgColor );
  913. m.insertItem( TQIconSet(sbgcl), i18n("S&elected Background Color..."), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelBgColor );
  914. // Unset [some] colors. I could show one only if that button was clicked, but that
  915. // would disable setting this with the keyboard (how many aren't doing just
  916. // that every day? ;)
  917. // ANY ideas for doing this in a nicer way will be warmly wellcomed.
  918. KateAttribute *style = i->style();
  919. if ( style->itemSet( KateAttribute::BGColor) || style->itemSet( KateAttribute::SelectedBGColor ) )
  920. {
  921. m.insertSeparator();
  922. if ( style->itemSet( KateAttribute::BGColor) )
  923. m.insertItem( i18n("Unset Background Color"), this, TQT_SLOT(unsetColor(int)), 0, 100 );
  924. if ( style->itemSet( KateAttribute::SelectedBGColor ) )
  925. m.insertItem( i18n("Unset Selected Background Color"), this, TQT_SLOT(unsetColor(int)), 0, 101 );
  926. }
  927. if ( ! i->isDefault() && ! i->defStyle() ) {
  928. m.insertSeparator();
  929. id = m.insertItem( i18n("Use &Default Style"), this, TQT_SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::UseDefStyle );
  930. m.setItemChecked( id, i->defStyle() );
  931. }
  932. m.exec( globalPos );
  933. }
  934. void KateStyleListView::showPopupMenu( TQListViewItem *i, const TQPoint &pos )
  935. {
  936. if ( dynamic_cast<KateStyleListItem*>(i) )
  937. showPopupMenu( (KateStyleListItem*)i, pos, true );
  938. }
  939. void KateStyleListView::mSlotPopupHandler( int z )
  940. {
  941. ((KateStyleListItem*)currentItem())->changeProperty( (KateStyleListItem::Property)z );
  942. }
  943. void KateStyleListView::unsetColor( int c )
  944. {
  945. ((KateStyleListItem*)currentItem())->unsetColor( c );
  946. emitChanged();
  947. }
  948. // Because TQListViewItem::activatePos() is going to become deprecated,
  949. // and also because this attempt offers more control, I connect mousePressed to this.
  950. void KateStyleListView::slotMousePressed(int btn, TQListViewItem* i, const TQPoint& pos, int c)
  951. {
  952. if ( dynamic_cast<KateStyleListItem*>(i) ) {
  953. if ( btn == Qt::LeftButton && c > 0 ) {
  954. // map pos to item/column and call KateStyleListItem::activate(col, pos)
  955. ((KateStyleListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - TQPoint( 0, itemRect(i).top() ) );
  956. }
  957. }
  958. }
  959. //END
  960. //BEGIN KateStyleListItem
  961. static const int BoxSize = 16;
  962. static const int ColorBtnWidth = 32;
  963. KateStyleListItem::KateStyleListItem( TQListViewItem *parent, const TQString & stylename,
  964. KateAttribute *style, KateHlItemData *data )
  965. : TQListViewItem( parent, stylename ),
  966. ds( style ),
  967. st( data )
  968. {
  969. initStyle();
  970. }
  971. KateStyleListItem::KateStyleListItem( TQListView *parent, const TQString & stylename,
  972. KateAttribute *style, KateHlItemData *data )
  973. : TQListViewItem( parent, stylename ),
  974. ds( style ),
  975. st( data )
  976. {
  977. initStyle();
  978. }
  979. void KateStyleListItem::initStyle()
  980. {
  981. if (!st)
  982. is = ds;
  983. else
  984. {
  985. is = new KateAttribute (*ds);
  986. if (st->isSomethingSet())
  987. *is += *st;
  988. }
  989. }
  990. void KateStyleListItem::updateStyle()
  991. {
  992. // nothing there, not update it, will crash
  993. if (!st)
  994. return;
  995. if ( is->itemSet(KateAttribute::Weight) )
  996. {
  997. if ( is->weight() != st->weight())
  998. st->setWeight( is->weight() );
  999. }
  1000. else st->clearAttribute( KateAttribute::Weight );
  1001. if ( is->itemSet(KateAttribute::Italic) )
  1002. {
  1003. if ( is->italic() != st->italic())
  1004. st->setItalic( is->italic() );
  1005. }
  1006. else st->clearAttribute( KateAttribute::Italic );
  1007. if ( is->itemSet(KateAttribute::StrikeOut) )
  1008. {
  1009. if ( is->strikeOut() != st->strikeOut())
  1010. st->setStrikeOut( is->strikeOut() );
  1011. }
  1012. else st->clearAttribute( KateAttribute::StrikeOut );
  1013. if ( is->itemSet(KateAttribute::Underline) )
  1014. {
  1015. if ( is->underline() != st->underline())
  1016. st->setUnderline( is->underline() );
  1017. }
  1018. else st->clearAttribute( KateAttribute::Underline );
  1019. if ( is->itemSet(KateAttribute::Outline) )
  1020. {
  1021. if ( is->outline() != st->outline())
  1022. st->setOutline( is->outline() );
  1023. }
  1024. else st->clearAttribute( KateAttribute::Outline );
  1025. if ( is->itemSet(KateAttribute::TextColor) )
  1026. {
  1027. if ( is->textColor() != st->textColor())
  1028. st->setTextColor( is->textColor() );
  1029. }
  1030. else st->clearAttribute( KateAttribute::TextColor );
  1031. if ( is->itemSet(KateAttribute::SelectedTextColor) )
  1032. {
  1033. if ( is->selectedTextColor() != st->selectedTextColor())
  1034. st->setSelectedTextColor( is->selectedTextColor() );
  1035. }
  1036. else st->clearAttribute( KateAttribute::SelectedTextColor);
  1037. if ( is->itemSet(KateAttribute::BGColor) )
  1038. {
  1039. if ( is->bgColor() != st->bgColor())
  1040. st->setBGColor( is->bgColor() );
  1041. }
  1042. else st->clearAttribute( KateAttribute::BGColor );
  1043. if ( is->itemSet(KateAttribute::SelectedBGColor) )
  1044. {
  1045. if ( is->selectedBGColor() != st->selectedBGColor())
  1046. st->setSelectedBGColor( is->selectedBGColor() );
  1047. }
  1048. else st->clearAttribute( KateAttribute::SelectedBGColor );
  1049. }
  1050. /* only true for a hl mode item using it's default style */
  1051. bool KateStyleListItem::defStyle() { return st && st->itemsSet() != ds->itemsSet(); }
  1052. /* true for default styles */
  1053. bool KateStyleListItem::isDefault() { return st ? false : true; }
  1054. int KateStyleListItem::width( const TQFontMetrics & /*fm*/, const TQListView * lv, int col ) const
  1055. {
  1056. int m = lv->itemMargin() * 2;
  1057. switch ( col ) {
  1058. case ContextName:
  1059. // FIXME: width for name column should reflect bold/italic
  1060. // (relevant for non-fixed fonts only - nessecary?)
  1061. return TQListViewItem::width( TQFontMetrics( ((KateStyleListView*)lv)->docfont), lv, col);
  1062. case Bold:
  1063. case Italic:
  1064. case UseDefStyle:
  1065. return BoxSize + m;
  1066. case Color:
  1067. case SelColor:
  1068. case BgColor:
  1069. case SelBgColor:
  1070. return ColorBtnWidth +m;
  1071. default:
  1072. return 0;
  1073. }
  1074. }
  1075. void KateStyleListItem::activate( int column, const TQPoint &localPos )
  1076. {
  1077. TQListView *lv = listView();
  1078. int x = 0;
  1079. for( int c = 0; c < column-1; c++ )
  1080. x += lv->columnWidth( c );
  1081. int w;
  1082. switch( column ) {
  1083. case Bold:
  1084. case Italic:
  1085. case Underline:
  1086. case Strikeout:
  1087. case UseDefStyle:
  1088. w = BoxSize;
  1089. break;
  1090. case Color:
  1091. case SelColor:
  1092. case BgColor:
  1093. case SelBgColor:
  1094. w = ColorBtnWidth;
  1095. break;
  1096. default:
  1097. return;
  1098. }
  1099. if ( !TQRect( x, 0, w, BoxSize ).contains( localPos ) )
  1100. changeProperty( (Property)column );
  1101. }
  1102. void KateStyleListItem::changeProperty( Property p )
  1103. {
  1104. if ( p == Bold )
  1105. is->setBold( ! is->bold() );
  1106. else if ( p == Italic )
  1107. is->setItalic( ! is->italic() );
  1108. else if ( p == Underline )
  1109. is->setUnderline( ! is->underline() );
  1110. else if ( p == Strikeout )
  1111. is->setStrikeOut( ! is->strikeOut() );
  1112. else if ( p == UseDefStyle )
  1113. toggleDefStyle();
  1114. else
  1115. setColor( p );
  1116. updateStyle ();
  1117. ((KateStyleListView*)listView())->emitChanged();
  1118. }
  1119. void KateStyleListItem::toggleDefStyle()
  1120. {
  1121. if ( *is == *ds ) {
  1122. KMessageBox::information( listView(),
  1123. i18n("\"Use Default Style\" will be automatically unset when you change any style properties."),
  1124. i18n("Kate Styles"),
  1125. "Kate hl config use defaults" );
  1126. }
  1127. else {
  1128. delete is;
  1129. is = new KateAttribute( *ds );
  1130. updateStyle();
  1131. repaint();
  1132. }
  1133. }
  1134. void KateStyleListItem::setColor( int column )
  1135. {
  1136. TQColor c; // use this
  1137. TQColor d; // default color
  1138. if ( column == Color)
  1139. {
  1140. c = is->textColor();
  1141. d = ds->textColor();
  1142. }
  1143. else if ( column == SelColor )
  1144. {
  1145. c = is->selectedTextColor();
  1146. d = is->selectedTextColor();
  1147. }
  1148. else if ( column == BgColor )
  1149. {
  1150. c = is->bgColor();
  1151. d = ds->bgColor();
  1152. }
  1153. else if ( column == SelBgColor )
  1154. {
  1155. c = is->selectedBGColor();
  1156. d = ds->selectedBGColor();
  1157. }
  1158. if ( KColorDialog::getColor( c, d, listView() ) != TQDialog::Accepted) return;
  1159. bool def = ! c.isValid();
  1160. // if set default, and the attrib is set in the default style use it
  1161. // else if set default, unset it
  1162. // else set the selected color
  1163. switch (column)
  1164. {
  1165. case Color:
  1166. if ( def )
  1167. {
  1168. if ( ds->itemSet(KateAttribute::TextColor) )
  1169. is->setTextColor( ds->textColor());
  1170. else
  1171. is->clearAttribute(KateAttribute::TextColor);
  1172. }
  1173. else
  1174. is->setTextColor( c );
  1175. break;
  1176. case SelColor:
  1177. if ( def )
  1178. {
  1179. if ( ds->itemSet(KateAttribute::SelectedTextColor) )
  1180. is->setSelectedTextColor( ds->selectedTextColor());
  1181. else
  1182. is->clearAttribute(KateAttribute::SelectedTextColor);
  1183. }
  1184. else
  1185. is->setSelectedTextColor( c );
  1186. break;
  1187. case BgColor:
  1188. if ( def )
  1189. {
  1190. if ( ds->itemSet(KateAttribute::BGColor) )
  1191. is->setBGColor( ds->bgColor());
  1192. else
  1193. is->clearAttribute(KateAttribute::BGColor);
  1194. }
  1195. else
  1196. is->setBGColor( c );
  1197. break;
  1198. case SelBgColor:
  1199. if ( def )
  1200. {
  1201. if ( ds->itemSet(KateAttribute::SelectedBGColor) )
  1202. is->setSelectedBGColor( ds->selectedBGColor());
  1203. else
  1204. is->clearAttribute(KateAttribute::SelectedBGColor);
  1205. }
  1206. else
  1207. is->setSelectedBGColor( c );
  1208. break;
  1209. }
  1210. repaint();
  1211. }
  1212. void KateStyleListItem::unsetColor( int c )
  1213. {
  1214. if ( c == 100 && is->itemSet(KateAttribute::BGColor) )
  1215. is->clearAttribute(KateAttribute::BGColor);
  1216. else if ( c == 101 && is->itemSet(KateAttribute::SelectedBGColor) )
  1217. is->clearAttribute(KateAttribute::SelectedBGColor);
  1218. updateStyle();
  1219. }
  1220. void KateStyleListItem::paintCell( TQPainter *p, const TQColorGroup& /*cg*/, int col, int width, int align )
  1221. {
  1222. if ( !p )
  1223. return;
  1224. TQListView *lv = listView();
  1225. if ( !lv )
  1226. return;
  1227. Q_ASSERT( lv ); //###
  1228. // use a private color group and set the text/highlighted text colors
  1229. TQColorGroup mcg = lv->viewport()->colorGroup();
  1230. if ( col ) // col 0 is drawn by the superclass method
  1231. p->fillRect( 0, 0, width, height(), TQBrush( mcg.base() ) );
  1232. int marg = lv->itemMargin();
  1233. TQColor c;
  1234. switch ( col )
  1235. {
  1236. case ContextName:
  1237. {
  1238. mcg.setColor(TQColorGroup::Text, is->textColor());
  1239. mcg.setColor(TQColorGroup::HighlightedText, is->selectedTextColor());
  1240. // text background color
  1241. c = is->bgColor();
  1242. if ( c.isValid() && is->itemSet(KateAttribute::BGColor) )
  1243. mcg.setColor( TQColorGroup::Base, c );
  1244. if ( isSelected() && is->itemSet(KateAttribute::SelectedBGColor) )
  1245. {
  1246. c = is->selectedBGColor();
  1247. if ( c.isValid() )
  1248. mcg.setColor( TQColorGroup::Highlight, c );
  1249. }
  1250. TQFont f ( ((KateStyleListView*)lv)->docfont );
  1251. p->setFont( is->font(f) );
  1252. // FIXME - repainting when text is cropped, and the column is enlarged is buggy.
  1253. // Maybe I need painting the string myself :(
  1254. // (wilbert) it depends on the font used
  1255. TQListViewItem::paintCell( p, mcg, col, width, align );
  1256. }
  1257. break;
  1258. case Bold:
  1259. case Italic:
  1260. case Underline:
  1261. case Strikeout:
  1262. case UseDefStyle:
  1263. {
  1264. // Bold/Italic/use default checkboxes
  1265. // code allmost identical to QCheckListItem
  1266. int x = 0;
  1267. int y = (height() - BoxSize) / 2;
  1268. if ( isEnabled() )
  1269. p->setPen( TQPen( mcg.text(), 2 ) );
  1270. else
  1271. p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
  1272. p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 );
  1273. x++;
  1274. y++;
  1275. if ( (col == Bold && is->bold()) ||
  1276. (col == Italic && is->italic()) ||
  1277. (col == Underline && is->underline()) ||
  1278. (col == Strikeout && is->strikeOut()) ||
  1279. (col == UseDefStyle && *is == *ds ) )
  1280. {
  1281. TQPointArray a( 7*2 );
  1282. int i, xx, yy;
  1283. xx = x+1+marg;
  1284. yy = y+5;
  1285. for ( i=0; i<3; i++ ) {
  1286. a.setPoint( 2*i, xx, yy );
  1287. a.setPoint( 2*i+1, xx, yy+2 );
  1288. xx++; yy++;
  1289. }
  1290. yy -= 2;
  1291. for ( i=3; i<7; i++ ) {
  1292. a.setPoint( 2*i, xx, yy );
  1293. a.setPoint( 2*i+1, xx, yy+2 );
  1294. xx++; yy--;
  1295. }
  1296. p->drawLineSegments( a );
  1297. }
  1298. }
  1299. break;
  1300. case Color:
  1301. case SelColor:
  1302. case BgColor:
  1303. case SelBgColor:
  1304. {
  1305. bool set( false );
  1306. if ( col == Color)
  1307. {
  1308. c = is->textColor();
  1309. set = is->itemSet(KateAttribute::TextColor);
  1310. }
  1311. else if ( col == SelColor )
  1312. {
  1313. c = is->selectedTextColor();
  1314. set = is->itemSet( KateAttribute::SelectedTextColor);
  1315. }
  1316. else if ( col == BgColor )
  1317. {
  1318. set = is->itemSet(KateAttribute::BGColor);
  1319. c = set ? is->bgColor() : mcg.base();
  1320. }
  1321. else if ( col == SelBgColor )
  1322. {
  1323. set = is->itemSet(KateAttribute::SelectedBGColor);
  1324. c = set ? is->selectedBGColor(): mcg.base();
  1325. }
  1326. // color "buttons"
  1327. int x = 0;
  1328. int y = (height() - BoxSize) / 2;
  1329. if ( isEnabled() )
  1330. p->setPen( TQPen( mcg.text(), 2 ) );
  1331. else
  1332. p->setPen( TQPen( lv->palette().color( TQPalette::Disabled, TQColorGroup::Text ), 2 ) );
  1333. p->drawRect( x+marg, y+2, ColorBtnWidth-4, BoxSize-4 );
  1334. p->fillRect( x+marg+1,y+3,ColorBtnWidth-7,BoxSize-7,TQBrush( c ) );
  1335. // if this item is unset, draw a diagonal line over the button
  1336. if ( ! set )
  1337. p->drawLine( x+marg-1, BoxSize-3, ColorBtnWidth-4, y+1 );
  1338. }
  1339. //case default: // no warning...
  1340. }
  1341. }
  1342. //END
  1343. //BEGIN KateStyleListCaption
  1344. KateStyleListCaption::KateStyleListCaption( TQListView *parent, const TQString & name )
  1345. : TQListViewItem( parent, name )
  1346. {
  1347. }
  1348. void KateStyleListCaption::paintCell( TQPainter *p, const TQColorGroup& /*cg*/, int col, int width, int align )
  1349. {
  1350. TQListView *lv = listView();
  1351. if ( !lv )
  1352. return;
  1353. Q_ASSERT( lv ); //###
  1354. // use the same colorgroup as the other items in the viewport
  1355. TQColorGroup mcg = lv->viewport()->colorGroup();
  1356. TQListViewItem::paintCell( p, mcg, col, width, align );
  1357. }
  1358. //END
  1359. // kate: space-indent on; indent-width 2; replace-tabs on;