settingsdialog.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*****************************************************************************
  2. * settingsdialog.cpp - QStarDict, a StarDict clone written with using Qt *
  3. * Copyright (C) 2008 Alexander Rodin *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License along *
  16. * with this program; if not, write to the Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  18. *****************************************************************************/
  19. #include "settingsdialog.h"
  20. #include <QFileDialog>
  21. #include "stardict.h"
  22. SettingsDialog::SettingsDialog(StarDict *plugin, QWidget *parent)
  23. : QDialog(parent),
  24. m_plugin(plugin)
  25. {
  26. setupUi(this);
  27. reformatListsBox->setChecked(m_plugin->m_reformatLists);
  28. expandAbbreviationsBox->setChecked(m_plugin->m_expandAbbreviations);
  29. dictDirsList->addItems(m_plugin->m_dictDirs);
  30. connect(this, SIGNAL(accepted()), SLOT(apply()));
  31. }
  32. void SettingsDialog::on_addDictDirButton_clicked()
  33. {
  34. QString dirName = QFileDialog::getExistingDirectory(this, tr("Select dictionaries directory"));
  35. if (! dirName.isEmpty())
  36. {
  37. dictDirsList->addItem(dirName);
  38. }
  39. }
  40. void SettingsDialog::on_removeDictDirButton_clicked()
  41. {
  42. delete dictDirsList->takeItem(dictDirsList->currentRow());
  43. }
  44. void SettingsDialog::on_moveUpDictDirButton_clicked()
  45. {
  46. if (dictDirsList->currentRow() > 0)
  47. {
  48. dictDirsList->insertItem(dictDirsList->currentRow(),
  49. dictDirsList->takeItem(dictDirsList->currentRow()));
  50. dictDirsList->setCurrentRow(dictDirsList->currentRow() - 1);
  51. }
  52. }
  53. void SettingsDialog::on_moveDownDictDirButton_clicked()
  54. {
  55. if (dictDirsList->currentRow() < dictDirsList->count() - 1)
  56. dictDirsList->insertItem(dictDirsList->currentRow(),
  57. dictDirsList->takeItem(dictDirsList->currentRow() + 1));
  58. }
  59. void SettingsDialog::apply()
  60. {
  61. m_plugin->m_reformatLists = reformatListsBox->isChecked();
  62. m_plugin->m_expandAbbreviations = expandAbbreviationsBox->isChecked();
  63. m_plugin->m_dictDirs.clear();
  64. for (int i = 0; i < dictDirsList->count(); ++i)
  65. m_plugin->m_dictDirs << dictDirsList->item(i)->text();
  66. }
  67. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc