KnowIt – tool for managing notes
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.

knowitpref.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /***************************************************************************
  2. knowitpref.cpp - description
  3. -------------------
  4. begin : czw lis 28 2002
  5. copyright : (C) 2002-2004 by Micha� Rudolf
  6. email : mrudolf@tdewebdev.org
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "knowitpref.h"
  17. #include <tqcheckbox.h>
  18. #include <tqcolor.h>
  19. #include <tqtoolbutton.h>
  20. #include <tqspinbox.h>
  21. #include <tqdatetime.h>
  22. #include <tqlayout.h>
  23. #include <tqwhatsthis.h>
  24. #include <tqstring.h>
  25. #include <tqlabel.h>
  26. #include <tqvbox.h>
  27. #include <tdeconfig.h>
  28. #include <kcombobox.h>
  29. #include <kglobal.h>
  30. #include <kiconloader.h>
  31. #include <klocale.h>
  32. #include <tdeversion.h>
  33. #include <kfontdialog.h>
  34. #include <klineedit.h>
  35. #include <kcolorbutton.h>
  36. #include <kdualcolorbutton.h>
  37. void KnowitOptions::save(TDEConfig* config) const
  38. {
  39. config->setGroup("KDE");
  40. config->writeEntry("MultipleInstances", multipleInstances);
  41. config->setGroup("General");
  42. config->writeEntry("Docked", docked);
  43. config->writeEntry("Autosave", autosave);
  44. config->writeEntry("Reopen", reopen);
  45. config->writeEntry("HorizontalSplit", horizontalSplit);
  46. config->writeEntry("UnconditionalSave", unconditionalSave);
  47. config->writeEntry("Backup", backup);
  48. config->writeEntry("DefaultName", defaultName);
  49. config->writeEntry("AlternateTree", alternateTree);
  50. config->writeEntry("AlternateColor", alternateColor);
  51. config->writeEntry("AutoCollapse", autoCollapse);
  52. config->setGroup("Links");
  53. config->writeEntry("First", firstLink);
  54. config->writeEntry("Format", linkFormat);
  55. config->setGroup("Editor");
  56. config->writeEntry("WordWrap", wordwrap);
  57. config->writeEntry("EnterBreakLine", enterBreakLine);
  58. config->writeEntry("TabFocus", tabfocus);
  59. config->writeEntry("CustomColors", customColors);
  60. config->writeEntry("ForeEditColor", foreEditColor);
  61. config->writeEntry("BackEditColor", backEditColor);
  62. config->writeEntry("CustomFont", customFont);
  63. config->writeEntry("FontFamily", fontFamily);
  64. config->writeEntry("FontSize", fontSize);
  65. config->setGroup("Templates");
  66. config->writeEntry("InsertDateFormatString", insertDateFormat);
  67. config->writeEntry("InsertDateColor", insertDateColor);
  68. config->writeEntry("InsertDateBold", insertDateBold);
  69. config->writeEntry("InsertDateItalic", insertDateItalic);
  70. config->writeEntry("InsertDateUnderline", insertDateUnderline);
  71. config->setGroup("Export");
  72. config->writeEntry("Flags", exportFlags);
  73. }
  74. void KnowitOptions::read(TDEConfig* config)
  75. {
  76. config->setGroup("KDE");
  77. multipleInstances = config->readBoolEntry("MultipleInstances", true);
  78. config->setGroup("General");
  79. docked = config->readBoolEntry("Docked", false);
  80. autosave = config->readNumEntry("Autosave", 0);
  81. reopen = config->readBoolEntry("Reopen", true);
  82. horizontalSplit = config->readNumEntry("HorizontalSplit", true);
  83. defaultName = config->readEntry("DefaultName", i18n("New note"));
  84. alternateTree = config->readBoolEntry("AlternateTree", false);
  85. alternateColor = config->readEntry("AlternateColor", TQString("LightYellow"));
  86. autoCollapse = config->readBoolEntry("AutoCollapse", false);
  87. unconditionalSave = config->readBoolEntry("UnconditionalSave", false);
  88. backup = config->readBoolEntry("Backup", true);
  89. config->setGroup("Links");
  90. firstLink = config->readBoolEntry("First", true);
  91. linkFormat = config->readNumEntry("Format", 0);
  92. config->setGroup("Editor");
  93. wordwrap = config->readBoolEntry("WordWrap", true);
  94. enterBreakLine = config->readBoolEntry("EnterBreakLine", true);
  95. tabfocus = config->readBoolEntry("TabFocus", false);
  96. customColors = config->readBoolEntry("CustomColors", false);
  97. foreEditColor = config->readEntry("ForeEditColor", TQString("Black"));
  98. backEditColor = config->readEntry("BackEditColor", TQString("White"));
  99. customFont = config->readBoolEntry("CustomFont", false);
  100. fontFamily = config->readEntry("FontFamily", TQString("Helvetica"));
  101. fontSize = config->readNumEntry("FontSize", 10); // KDE-Default?
  102. config->setGroup("Templates");
  103. insertDateFormat = config->readEntry("InsertDateFormatString", TQString("ddd d MMM yyyy, hh:mm:ss"));
  104. insertDateColor = config->readEntry("InsertDateColor", TQString("Blue"));
  105. insertDateBold = config->readBoolEntry("InsertDateBold", false);
  106. insertDateItalic = config->readBoolEntry("InsertDateItalic", true);
  107. insertDateUnderline = config->readBoolEntry("InsertDateUnderline", false);
  108. config->setGroup("Export");
  109. exportFlags = config->readNumEntry("Flags", 0);
  110. }
  111. KnowitPreferences::KnowitPreferences()
  112. : KDialogBase(IconList, i18n("KnowIt Preferences"), Ok|Cancel, Ok)
  113. {
  114. TQFrame* page;
  115. TQVBoxLayout* layout;
  116. /* first page: General */
  117. page = addPage(i18n("General"), i18n("General options"),
  118. TDEGlobal::iconLoader()->loadIcon(TQString("configure"), KIcon::Toolbar, KIcon::SizeMedium));
  119. layout = new TQVBoxLayout(page, 0, spacingHint());
  120. layout->addWidget(docked = new TQCheckBox(i18n("&Dock in System tray"), page, "Dock"));
  121. layout->addWidget(reopen = new TQCheckBox(i18n("Open &last file on startup"), page, "Reopen"));
  122. TQHBox* autosaveBox = new TQHBox(page);
  123. layout->addWidget(autosaveBox);
  124. new TQLabel(i18n("Autosave:"), autosaveBox);
  125. autosave = new TQSpinBox(0, 120, 5, autosaveBox, "Autosave");
  126. autosave->setPrefix(i18n("every "));
  127. autosave->setSuffix(i18n(" min."));
  128. autosave->setSpecialValueText(i18n("Never"));
  129. TQWhatsThis::add(autosave, i18n("Current file will be automatically saved "
  130. "after the specified interval. Set to <i>never</i> to disable autosave."));
  131. layout->addWidget(unconditionalSave = new TQCheckBox(i18n("Automatically save file on e&xit"),
  132. page, "UnconditionalSave"));
  133. TQWhatsThis::add(unconditionalSave, i18n("Current file will be automatically saved "
  134. "on exit without confirmation."));
  135. layout->addWidget(backup = new TQCheckBox(i18n("Create &backups"),
  136. page, "Backup"));
  137. TQWhatsThis::add(backup, i18n("Create backup of current document before it is saved."));
  138. layout->addWidget(multipleInstances = new TQCheckBox(i18n("Allow &multiple instances of KnowIt"),
  139. page, "Instances"));
  140. TQWhatsThis::add(multipleInstances, i18n("If this option is disabled, only one "
  141. "instance of KnowIt will be allowed. If there is another instance already running, "
  142. "it will be automatically activated instead of running new one."));
  143. layout->addStretch(1);
  144. /* second page: Interface */
  145. page = addPage(i18n("Interface"), i18n("Interface options"),
  146. TDEGlobal::iconLoader()->loadIcon(TQString("misc"), KIcon::Toolbar, KIcon::SizeMedium));
  147. layout = new TQVBoxLayout(page, 0, spacingHint());
  148. layout->addWidget(horizontalSplit = new TQCheckBox(i18n("Split window &horizontally"), page, "Split"));
  149. TQWhatsThis::add(horizontalSplit, i18n("If this option is set, notes tree will "
  150. "be displayed on the left and the editor on the right (this is default).<br>"
  151. "Otherwise notes tree will be displayed at the top and the editor at the bottom."));
  152. TQHBox* defaultNameBox = new TQHBox(page);
  153. layout->addWidget(defaultNameBox);
  154. new TQLabel(i18n("Default note name:"), defaultNameBox);
  155. defaultName = new KLineEdit(defaultNameBox, "DefaultName");
  156. TQWhatsThis::add(defaultName, i18n("Default name for new notes. It would be "
  157. "autoselected, so if you often copy text using mouse selection, you may "
  158. "consider setting default name to none."));
  159. TQHBox* linkBox = new TQHBox(page);
  160. layout->addWidget(linkBox);
  161. new TQLabel(i18n("Link format:"), linkBox);
  162. linkFormat = new KComboBox(linkBox, "LinkFormat");
  163. linkFormat->insertItem(i18n("Description (link)"));
  164. linkFormat->insertItem(i18n("Link (description)"));
  165. linkFormat->insertItem(i18n("Link only"));
  166. linkFormat->insertItem(i18n("Description only"));
  167. TQHBox* alternateBox = new TQHBox(page);
  168. layout->addWidget(alternateBox);
  169. alternateTree = new TQCheckBox(i18n("Alternate colors in tree"), alternateBox, "Alternate");
  170. alternateColor = new KColorButton(TQColor("White"), alternateBox, "AlternateColor");
  171. layout->addWidget(autoCollapse = new TQCheckBox(i18n("Automatically collapse other notes"), page, "AutoCollapse"));
  172. TQWhatsThis::add(autoCollapse, i18n("If this option is set, only current subtree "
  173. "will be visible, other notes will be automatically collapsed."));
  174. layout->addStretch(1);
  175. /* third page: Editor */
  176. page = addPage(i18n("Editor"), i18n("Editor options"),
  177. TDEGlobal::iconLoader()->loadIcon(TQString("edit"), KIcon::Toolbar, KIcon::SizeMedium));
  178. layout = new TQVBoxLayout(page, 0, spacingHint());
  179. layout->addWidget(wordwrap = new TQCheckBox(i18n("Use &word wrap"),
  180. page, "WordWrap"));
  181. layout->addWidget(enterBreakLine = new TQCheckBox(i18n("'Enter' ends current line, not paragraph"),
  182. page, "EnterLineBreak"));
  183. layout->addWidget(tabfocus = new TQCheckBox(i18n("'Tab' in editor changes focus"),
  184. page, "TabFocus"));
  185. #if TDE_VERSION_MAJOR == 3 && TDE_VERSION_MINOR < 1
  186. tabfocus->hide();
  187. #endif
  188. TQHBox* colorBox = new TQHBox(page);
  189. layout->addWidget(colorBox);
  190. customColors = new TQCheckBox(i18n("Use &custom colors"), colorBox, "CustomColors");
  191. editColors = new KDualColorButton(colorBox);
  192. const char fontSizes[] = {4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,24,26,28,32,48,64,0};
  193. TQStringList fontList;
  194. TDEFontChooser::getFontList(fontList, false);
  195. TQHBox* fontBox = new TQHBox(page);
  196. layout->addWidget(fontBox);
  197. customFont = new TQCheckBox(i18n("Use custom font:"), fontBox, "customFont");
  198. fontFamily = new KComboBox(true, fontBox);
  199. fontFamily->insertStringList(fontList);
  200. fontSize = new KComboBox(true, fontBox);
  201. for( int i=0; fontSizes[i] != 0; i++ ){
  202. fontSize->insertItem(TQString(TQString().setNum(fontSizes[i])),i);
  203. }
  204. layout->addStretch(1);
  205. /* fourth page: Templates */
  206. page = addPage(i18n("Templates"), i18n("Templates configuration"),
  207. TDEGlobal::iconLoader()->loadIcon(TQString("wizard"), KIcon::Toolbar, KIcon::SizeMedium));
  208. layout = new TQVBoxLayout(page, 0, spacingHint());
  209. TQWhatsThis::add(page, i18n("<html>\n"
  210. "<p>These expressions may be used: </p>\n"
  211. "<table>\n"
  212. "<tr><th>d</th><td>the day as number without a leading zero (1-31)</td></tr>\n"
  213. "<tr><th>dd</th><td>the day as number with a leading zero (01-31)</td></tr>\n"
  214. "<tr><th>ddd</th><td>the abbreviated localized day name (e.g. 'Mon'..'Sun')</td></tr>\n"
  215. "<tr><th>dddd</th><td>the long localized day name (e.g. 'Monday'..'Sunday')</td></tr>\n"
  216. "<tr><th>M</th><td>the month as number without a leading zero (1-12)</td></tr>\n"
  217. "<tr><th>MM</th><td>the month as number with a leading zero (01-12)</td></tr>\n"
  218. "<tr><th>MMM</th><td>the abbreviated localized month name (e.g. 'Jan'..'Dec')</td></tr>\n"
  219. "<tr><th>MMMM</th><td>the long localized month name (e.g. 'January'..'December')</td></tr>\n"
  220. "<tr><th>yy</th><td>the year as two digit number (00-99)</td></tr>\n"
  221. "<tr><th>yyyy</th><td>the year as four digit number (1752-8000)</td></tr>\n"
  222. "<tr><th>h</th><td>the hour without a leading zero (0..23 or 1..12 if AM/PM display)</td></tr>\n"
  223. "<tr><th>hh</th><td>the hour with a leading zero (00..23 or 01..12 if AM/PM display)</td></tr>\n"
  224. "<tr><th>m</th><td>the minute without a leading zero (0..59)</td></tr>\n"
  225. "<tr><th>mm</th><td>the minute with a leading zero (00..59)</td></tr>\n"
  226. "<tr><th>s</th><td>the second without a leading zero (0..59)</td></tr>\n"
  227. "<tr><th>ss</th><td>the second with a leading zero (00..59)</td></tr>\n"
  228. "<tr><th>AP</th><td>use AM/PM display</td></tr>\n"
  229. "<tr><th>AP</th><td>use am/pm display</td></tr>\n"
  230. "</table></html>"));
  231. TQHBox* topBox = new TQHBox(page);
  232. layout->addWidget(topBox);
  233. TQLabel * label1 = new TQLabel(i18n("Date Format: "), topBox);
  234. label1->setFixedSize(label1->sizeHint());
  235. insertDatePreview = new TQLabel("", topBox);
  236. TQHBox *tmpBox = new TQHBox(page);
  237. layout->addWidget(tmpBox);
  238. insertDateColorButton = new KColorButton(TQColor("Blue"), tmpBox, "InsertDateColorButton");
  239. insertDateFormatEdit = new KLineEdit(tmpBox, "InsertDateFormatEdit");
  240. insertDateItalicButton = new TQToolButton(tmpBox,"InsertDateItalicButton");
  241. insertDateItalicButton->setIconSet(TQIconSet(TDEGlobal::iconLoader()->loadIcon("text_italic", KIcon::Toolbar)));
  242. insertDateItalicButton->setToggleButton(true);
  243. insertDateBoldButton = new TQToolButton(tmpBox,"InsertDateBoldButton");
  244. insertDateBoldButton->setIconSet(TQIconSet(TDEGlobal::iconLoader()->loadIcon("text_bold", KIcon::Toolbar)));
  245. insertDateBoldButton->setToggleButton(true);
  246. insertDateUnderlineButton = new TQToolButton(tmpBox, "InsertDateUnderlineButton");
  247. insertDateUnderlineButton->setIconSet(TQIconSet(TDEGlobal::iconLoader()->loadIcon("text_under", KIcon::Toolbar)));
  248. insertDateUnderlineButton->setToggleButton(true);
  249. insertDateColorButton->setFixedSize(insertDateBoldButton->sizeHint());
  250. insertDateFormatEdit->setMinimumWidth(6*insertDateBoldButton->sizeHint().width());
  251. layout->addStretch(1);
  252. setIconListAllVisible(true);
  253. }
  254. void KnowitPreferences::setOptions(const KnowitOptions& Options)
  255. {
  256. docked->setChecked(Options.docked);
  257. reopen->setChecked(Options.reopen);
  258. autosave->setValue(Options.autosave);
  259. unconditionalSave->setChecked(Options.unconditionalSave);
  260. backup->setChecked(Options.backup);
  261. multipleInstances->setChecked(Options.multipleInstances);
  262. horizontalSplit->setChecked(Options.horizontalSplit);
  263. defaultName->setText(Options.defaultName);
  264. alternateTree->setChecked(Options.alternateTree);
  265. alternateColor->setColor(TQColor(Options.alternateColor));
  266. autoCollapse->setChecked(Options.autoCollapse);
  267. linkFormat->setCurrentItem(Options.linkFormat);
  268. wordwrap->setChecked(Options.wordwrap);
  269. enterBreakLine->setChecked(Options.enterBreakLine);
  270. tabfocus->setChecked(Options.tabfocus);
  271. customColors->setChecked(Options.customColors);
  272. editColors->setForeground(TQColor(Options.foreEditColor));
  273. editColors->setBackground(TQColor(Options.backEditColor));
  274. customFont->setChecked(Options.customFont);
  275. fontFamily->setCurrentText(Options.fontFamily);
  276. fontSize->setCurrentText(TQString().setNum(Options.fontSize));
  277. insertDateFormatEdit->setText(Options.insertDateFormat);
  278. insertDateColorButton->setColor(TQColor(Options.insertDateColor));
  279. insertDateBoldButton->setOn(Options.insertDateBold);
  280. insertDateItalicButton->setOn(Options.insertDateItalic);
  281. insertDateUnderlineButton->setOn(Options.insertDateUnderline);
  282. slotUpdateDatePreview();
  283. connect(insertDateColorButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotUpdateDatePreview()));
  284. connect(insertDateFormatEdit, TQT_SIGNAL(textChanged (const TQString &)), this, TQT_SLOT(slotUpdateDatePreview()));
  285. connect(insertDateItalicButton, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotUpdateDatePreview()));
  286. connect(insertDateBoldButton, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotUpdateDatePreview()));
  287. connect(insertDateUnderlineButton, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotUpdateDatePreview()));
  288. /* non-GUI options */
  289. firstLink = Options.firstLink;
  290. exportFlags = Options.exportFlags;
  291. }
  292. KnowitOptions KnowitPreferences::getOptions() const
  293. {
  294. KnowitOptions Options;
  295. Options.docked = docked->isChecked();
  296. Options.reopen = reopen->isChecked();
  297. Options.autosave = autosave->value();
  298. Options.unconditionalSave = unconditionalSave->isChecked();
  299. Options.multipleInstances = multipleInstances->isChecked();
  300. Options.backup = backup->isChecked();
  301. Options.horizontalSplit = horizontalSplit->isChecked();
  302. Options.defaultName = defaultName->text();
  303. Options.alternateTree = alternateTree->isChecked();
  304. Options.alternateColor = alternateColor->color().name();
  305. Options.autoCollapse = autoCollapse->isChecked();
  306. Options.linkFormat = linkFormat->currentItem();
  307. Options.wordwrap = wordwrap->isChecked();
  308. Options.enterBreakLine = enterBreakLine->isChecked();
  309. Options.tabfocus = tabfocus->isChecked();
  310. Options.customColors = customColors->isChecked();
  311. Options.foreEditColor = editColors->foreground().name();
  312. Options.backEditColor = editColors->background().name();
  313. Options.customFont = customFont->isChecked();
  314. Options.fontFamily = fontFamily->currentText();
  315. Options.fontSize = fontSize->currentText().toInt();
  316. Options.insertDateFormat = insertDateFormatEdit->text();
  317. Options.insertDateColor = insertDateColorButton->color().name();
  318. Options.insertDateBold = insertDateBoldButton->isOn();
  319. Options.insertDateItalic = insertDateItalicButton->isOn();
  320. Options.insertDateUnderline = insertDateUnderlineButton->isOn();
  321. Options.firstLink = firstLink;
  322. Options.exportFlags = exportFlags;
  323. return Options;
  324. }
  325. void KnowitPreferences::slotUpdateDatePreview()
  326. {
  327. TQString str = "<html><p align=\"center\">";
  328. if(insertDateBoldButton->isOn()) str += "<b>";
  329. if(insertDateItalicButton->isOn()) str +="<i>";
  330. if(insertDateUnderlineButton->isOn()) str += "<u>";
  331. str += "<font COLOR=\""+insertDateColorButton->color().name()+"\">";
  332. str += TQString("%1").arg(TQDateTime::currentDateTime().toString(insertDateFormatEdit->text()));
  333. str += "</font>";
  334. if(insertDateUnderlineButton->isOn()) str += "</u>";
  335. if(insertDateItalicButton->isOn()) str +="</i>";
  336. if(insertDateBoldButton->isOn()) str += "</b>";
  337. str += "</p></html>";
  338. insertDatePreview->setPaletteBackgroundColor(TQColor("White"));
  339. insertDatePreview->setText(str);
  340. }