KOffice – TDE office suite
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.

339 lines
12KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2003 Peter Simonsson <psn@linux.se>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  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. #include "kiviooptionsdialog.h"
  17. #include "kivio_view.h"
  18. #include "kivio_doc.h"
  19. #include "kivio_page.h"
  20. #include "kivioglobal.h"
  21. #include "kivio_grid_data.h"
  22. #include "kivio_canvas.h"
  23. #include "kivio_settings.h"
  24. #include "kivio_config.h"
  25. #include <tdelocale.h>
  26. #include <KoApplication.h>
  27. #include <kiconloader.h>
  28. #include <kpushbutton.h>
  29. #include <KoPageLayoutDia.h>
  30. #include <kurlrequester.h>
  31. #include <kcolorbutton.h>
  32. #include <KoUnitWidgets.h>
  33. #include <tdeglobal.h>
  34. #include <kdebug.h>
  35. #include <tdefontdialog.h>
  36. #include <tqlabel.h>
  37. #include <tqbuttongroup.h>
  38. #include <tqgroupbox.h>
  39. #include <tqcombobox.h>
  40. #include <tqcheckbox.h>
  41. #include <tqradiobutton.h>
  42. #include <tqlayout.h>
  43. #include <tqtabwidget.h>
  44. // GuidesListViewItem::GuidesListViewItem(TQListView* parent, KivioGuideLineData *gd, KoUnit::Unit u)
  45. // : TDEListViewItem(parent), m_data(gd)
  46. // {
  47. // setPixmap(0, BarIcon(m_data->orientation() == Qt::Vertical ?
  48. // "guides_vertical":"guides_horizontal"));
  49. // TQString s = TDEGlobal::_locale->formatNumber(KoUnit::toUserValue(m_data->position(), u), 2);
  50. // s += " " + KoUnit::unitName(u);
  51. // setText(1, s);
  52. // }
  53. //
  54. // GuidesListViewItem::~GuidesListViewItem()
  55. // {
  56. // delete m_data;
  57. // }
  58. //
  59. // void GuidesListViewItem::setUnit(KoUnit::Unit u)
  60. // {
  61. // TQString s = TDEGlobal::_locale->formatNumber(KoUnit::toUserValue(m_data->position(), u), 2);
  62. // s += " " + KoUnit::unitName(u);
  63. // setText(1, s);
  64. // }
  65. //
  66. // void GuidesListViewItem::setPosition(double p, KoUnit::Unit u)
  67. // {
  68. // m_data->setPosition(KoUnit::fromUserValue(p, u));
  69. // TQString s = TDEGlobal::_locale->formatNumber(p, 2);
  70. // s += " " + KoUnit::unitName(u);
  71. // setText(1, s);
  72. // }
  73. //
  74. // void GuidesListViewItem::setOrientation(Qt::Orientation o)
  75. // {
  76. // m_data->setOrientation(o);
  77. // setPixmap(0, BarIcon(m_data->orientation() == Qt::Vertical ?
  78. // "guides_vertical":"guides_horizontal"));
  79. // }
  80. /*****************************************************************************/
  81. KivioOptionsDialog::KivioOptionsDialog(KivioView* parent, const char* name)
  82. : KDialogBase(IconList, i18n("Settings"), Ok|Cancel|Apply|Default, Ok, parent, name)
  83. {
  84. initPage();
  85. initGrid();
  86. unitChanged(parent->doc()->unit());
  87. }
  88. void KivioOptionsDialog::initPage()
  89. {
  90. TQFrame* page = addPage(i18n("Page"), i18n("Page Settings"),
  91. kapp->iconLoader()->loadIcon(""application-x-zerosize", TDEIcon::Toolbar, 32));
  92. m_pageIndex = pageIndex(page);
  93. KivioView* view = static_cast<KivioView*>(TQT_TQWIDGET(parent()));
  94. KoUnit::Unit unit = KoUnit::unit(Kivio::Config::unit());
  95. m_layout = Kivio::Config::defaultPageLayout();
  96. m_font = Kivio::Config::font();
  97. TQLabel* unitLbl = new TQLabel(i18n("Default &units:"), page);
  98. m_unitCombo = new TQComboBox(page);
  99. m_unitCombo->insertStringList(KoUnit::listOfUnitName());
  100. m_unitCombo->setCurrentItem(unit);
  101. unitLbl->setBuddy(m_unitCombo);
  102. TQLabel* layoutLbl = new TQLabel(i18n("Default layout:"), page);
  103. m_layoutTxtLbl = new TQLabel(page);
  104. m_layoutTxtLbl->setFrameStyle(TQFrame::LineEditPanel | TQFrame::Sunken);
  105. m_layoutTxtLbl->setSizePolicy(TQSizePolicy(
  106. TQSizePolicy::Minimum, TQSizePolicy::Fixed));
  107. setLayoutText(m_layout);
  108. KPushButton* layoutBtn = new KPushButton(i18n("Change..."), page);
  109. layoutBtn->setSizePolicy(TQSizePolicy(
  110. TQSizePolicy::Fixed, TQSizePolicy::Fixed));
  111. TQLabel* fontLbl = new TQLabel(i18n("Default font:"), page);
  112. m_fontTxtLbl = new TQLabel(page);
  113. m_fontTxtLbl->setFrameStyle(TQFrame::LineEditPanel | TQFrame::Sunken);
  114. m_fontTxtLbl->setSizePolicy(TQSizePolicy(
  115. TQSizePolicy::Minimum, TQSizePolicy::Fixed));
  116. setFontText(m_font);
  117. KPushButton* fontBtn = new KPushButton(i18n("Change..."), page);
  118. layoutBtn->setSizePolicy(TQSizePolicy(
  119. TQSizePolicy::Fixed, TQSizePolicy::Fixed));
  120. m_marginsChBox = new TQCheckBox(i18n("Show page &margins"), page);
  121. m_marginsChBox->setChecked(view->isShowPageMargins());
  122. m_rulersChBox = new TQCheckBox(i18n("Show page &rulers"), page);
  123. m_rulersChBox->setChecked(view->isShowRulers());
  124. TQGridLayout* gl = new TQGridLayout(page);
  125. gl->setSpacing(KDialog::spacingHint());
  126. gl->addWidget(unitLbl, 0, 0);
  127. gl->addMultiCellWidget(m_unitCombo, 0, 0, 1, 2);
  128. gl->addWidget(layoutLbl, 1, 0);
  129. gl->addWidget(m_layoutTxtLbl, 1, 1);
  130. gl->addWidget(layoutBtn, 1, 2);
  131. gl->addWidget(fontLbl, 2, 0);
  132. gl->addWidget(m_fontTxtLbl, 2, 1);
  133. gl->addWidget(fontBtn, 2, 2);
  134. gl->addMultiCellWidget(m_marginsChBox, 3, 3, 0, 2);
  135. gl->addMultiCellWidget(m_rulersChBox, 4, 4, 0, 2);
  136. gl->addMultiCell(new TQSpacerItem(0, 0), 5, 5, 0, 2);
  137. connect(layoutBtn, TQT_SIGNAL(clicked()), TQT_SLOT(pageLayoutDlg()));
  138. connect(fontBtn, TQT_SIGNAL(clicked()), TQT_SLOT(fontDlg()));
  139. connect(m_unitCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(unitChanged(int)));
  140. }
  141. void KivioOptionsDialog::initGrid()
  142. {
  143. TQFrame* page = addPage(i18n("Grid"), i18n("Grid Settings"), BarIcon( "grid", TDEIcon::SizeMedium ));
  144. m_gridIndex = pageIndex(page);
  145. KoUnit::Unit unit = static_cast<KivioView*>(TQT_TQWIDGET(parent()))->doc()->unit();
  146. KivioGridData d = static_cast<KivioView*>(TQT_TQWIDGET(parent()))->doc()->grid();
  147. double pgw = m_layout.ptWidth;
  148. double pgh = m_layout.ptHeight;
  149. double fw = Kivio::Config::gridXSpacing();
  150. double fh = Kivio::Config::gridYSpacing();
  151. double sw = Kivio::Config::gridXSnap();
  152. double sh = Kivio::Config::gridYSnap();
  153. m_gridChBox = new TQCheckBox(i18n("Show &grid"), page);
  154. m_gridChBox->setChecked(Kivio::Config::showGrid());
  155. m_snapChBox = new TQCheckBox(i18n("Snap to g&rid"), page);
  156. m_snapChBox->setChecked(Kivio::Config::snapGrid());
  157. TQLabel* gridColorLbl = new TQLabel(i18n("Grid &color:"), page);
  158. m_gridColorBtn = new KColorButton(Kivio::Config::gridColor(), page);
  159. gridColorLbl->setBuddy(m_gridColorBtn);
  160. TQGroupBox* spacingGrp = new TQGroupBox(2, Qt::Horizontal, i18n("Spacing"), page);
  161. TQLabel* spaceHorizLbl = new TQLabel(i18n("&Horizontal:"), spacingGrp);
  162. m_spaceHorizUSpin = new KoUnitDoubleSpinBox(spacingGrp, 0.0, pgw, 0.1,
  163. fw, unit);
  164. spaceHorizLbl->setBuddy(m_spaceHorizUSpin);
  165. TQLabel* spaceVertLbl = new TQLabel(i18n("&Vertical:"), spacingGrp);
  166. m_spaceVertUSpin = new KoUnitDoubleSpinBox(spacingGrp, 0.0, pgh, 0.1,
  167. fh, unit);
  168. spaceVertLbl->setBuddy(m_spaceVertUSpin);
  169. TQGroupBox* snapGrp = new TQGroupBox(2, Qt::Horizontal, i18n("Snap Distance"), page);
  170. TQLabel* snapHorizLbl = new TQLabel(i18n("H&orizontal:"), snapGrp);
  171. m_snapHorizUSpin = new KoUnitDoubleSpinBox(snapGrp, 0.0, fw, 0.1,
  172. sw, unit);
  173. snapHorizLbl->setBuddy(m_snapHorizUSpin);
  174. TQLabel* snapVertLbl = new TQLabel(i18n("V&ertical:"), snapGrp);
  175. m_snapVertUSpin = new KoUnitDoubleSpinBox(snapGrp, 0.0, fh, 0.1,
  176. sh, unit);
  177. snapVertLbl->setBuddy(m_snapVertUSpin);
  178. TQGridLayout* gl = new TQGridLayout(page);
  179. gl->setSpacing(KDialog::spacingHint());
  180. gl->addMultiCellWidget(m_gridChBox, 0, 0, 0, 2);
  181. gl->addMultiCellWidget(m_snapChBox, 1, 1, 0, 2);
  182. gl->addWidget(gridColorLbl, 2, 0);
  183. gl->addWidget(m_gridColorBtn, 2, 1);
  184. gl->addItem(new TQSpacerItem(0, 0), 2, 2);
  185. gl->addMultiCellWidget(spacingGrp, 3, 3, 0, 2);
  186. gl->addMultiCellWidget(snapGrp, 4, 4, 0, 2);
  187. gl->addMultiCell(new TQSpacerItem(0, 0), 5, 5, 0, 2);
  188. connect(m_spaceHorizUSpin, TQT_SIGNAL(valueChanged(double)), TQT_SLOT(setMaxHorizSnap(double)));
  189. connect(m_spaceVertUSpin, TQT_SIGNAL(valueChanged(double)), TQT_SLOT(setMaxVertSnap(double)));
  190. }
  191. void KivioOptionsDialog::applyPage()
  192. {
  193. KivioView* view = static_cast<KivioView*>(TQT_TQWIDGET(parent()));
  194. view->doc()->setUnit(static_cast<KoUnit::Unit>(m_unitCombo->currentItem()));
  195. Kivio::Config::setUnit(KoUnit::unitName(view->doc()->unit()));
  196. Kivio::Config::setDefaultPageLayout(m_layout);
  197. Kivio::Config::setFont(m_font);
  198. view->doc()->setDefaultFont(m_font);
  199. view->togglePageMargins(m_marginsChBox->isChecked());
  200. view->toggleShowRulers(m_rulersChBox->isChecked());
  201. }
  202. void KivioOptionsDialog::applyGrid()
  203. {
  204. KivioGridData d;
  205. Kivio::Config::setGridXSpacing(m_spaceHorizUSpin->value());
  206. Kivio::Config::setGridYSpacing(m_spaceVertUSpin->value());
  207. Kivio::Config::setGridXSnap(m_snapHorizUSpin->value());
  208. Kivio::Config::setGridYSnap(m_snapVertUSpin->value());
  209. Kivio::Config::setShowGrid(m_gridChBox->isChecked());
  210. Kivio::Config::setSnapGrid(m_snapChBox->isChecked());
  211. Kivio::Config::setGridColor(m_gridColorBtn->color());
  212. KivioView* view = static_cast<KivioView*>(TQT_TQWIDGET(parent()));
  213. view->doc()->updateView(0);
  214. }
  215. void KivioOptionsDialog::defaultPage()
  216. {
  217. m_layout = Kivio::Config::defaultPageLayout();
  218. m_font = Kivio::Config::font();
  219. m_unitCombo->setCurrentItem(KoUnit::unit(Kivio::Config::unit()));
  220. unitChanged(m_unitCombo->currentItem());
  221. setLayoutText(m_layout);
  222. setFontText(m_font);
  223. m_marginsChBox->setChecked(true);
  224. m_rulersChBox->setChecked(true);
  225. }
  226. void KivioOptionsDialog::defaultGrid()
  227. {
  228. m_spaceHorizUSpin->changeValue(Kivio::Config::gridXSpacing());
  229. m_spaceVertUSpin->changeValue(Kivio::Config::gridYSpacing());
  230. m_snapHorizUSpin->changeValue(Kivio::Config::gridXSnap());
  231. m_snapVertUSpin->changeValue(Kivio::Config::gridYSnap());
  232. m_gridChBox->setChecked(Kivio::Config::showGrid());
  233. m_snapChBox->setChecked(Kivio::Config::snapGrid());
  234. m_gridColorBtn->setColor(Kivio::Config::gridColor());
  235. }
  236. void KivioOptionsDialog::setLayoutText(const KoPageLayout& l)
  237. {
  238. KoUnit::Unit unit = static_cast<KoUnit::Unit>(m_unitCombo->currentItem());
  239. TQString txt = i18n("Format: %1, Width: %2 %4, Height: %3 %5").arg(
  240. KoPageFormat::formatString(l.format)).arg(KoUnit::toUserValue(l.ptWidth, unit))
  241. .arg(KoUnit::toUserValue(l.ptHeight, unit)).arg(KoUnit::unitName(unit)).arg(
  242. KoUnit::unitName(unit));
  243. m_layoutTxtLbl->setText(txt);
  244. }
  245. void KivioOptionsDialog::pageLayoutDlg()
  246. {
  247. KoHeadFoot headfoot;
  248. int tabs = FORMAT_AND_BORDERS | DISABLE_UNIT;
  249. KoUnit::Unit unit = static_cast<KoUnit::Unit>(m_unitCombo->currentItem());
  250. if(KoPageLayoutDia::pageLayout(m_layout, headfoot, tabs, unit))
  251. {
  252. setLayoutText(m_layout);
  253. }
  254. }
  255. void KivioOptionsDialog::unitChanged(int u)
  256. {
  257. KoUnit::Unit unit = static_cast<KoUnit::Unit>(u);
  258. setLayoutText(m_layout);
  259. m_snapHorizUSpin->setUnit(unit);
  260. m_snapVertUSpin->setUnit(unit);
  261. m_spaceHorizUSpin->setUnit(unit);
  262. m_spaceVertUSpin->setUnit(unit);
  263. }
  264. void KivioOptionsDialog::slotOk()
  265. {
  266. slotApply();
  267. accept();
  268. }
  269. void KivioOptionsDialog::slotApply()
  270. {
  271. applyPage();
  272. applyGrid();
  273. Kivio::Config::self()->writeConfig();
  274. }
  275. void KivioOptionsDialog::slotDefault()
  276. {
  277. bool defaults = Kivio::Config::self()->useDefaults(true);
  278. defaultPage();
  279. defaultGrid();
  280. Kivio::Config::self()->useDefaults(defaults);
  281. }
  282. void KivioOptionsDialog::setMaxHorizSnap(double v)
  283. {
  284. KoUnit::Unit unit = static_cast<KoUnit::Unit>(m_unitCombo->currentItem());
  285. m_snapHorizUSpin->setMaxValue(KoUnit::fromUserValue(v, unit));
  286. }
  287. void KivioOptionsDialog::setMaxVertSnap(double v)
  288. {
  289. KoUnit::Unit unit = static_cast<KoUnit::Unit>(m_unitCombo->currentItem());
  290. m_snapVertUSpin->setMaxValue(KoUnit::fromUserValue(v, unit));
  291. }
  292. void KivioOptionsDialog::setFontText(const TQFont& f)
  293. {
  294. TQString txt = f.family() + " " + TQString::number(f.pointSize());
  295. m_fontTxtLbl->setText(txt);
  296. }
  297. void KivioOptionsDialog::fontDlg()
  298. {
  299. if(TDEFontDialog::getFont(m_font, false, this) == TQDialog::Accepted) {
  300. setFontText(m_font);
  301. }
  302. }
  303. #include "kiviooptionsdialog.moc"