toolsdlg.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2006-2007 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "toolsdlg.h"
  17. #include <QVariant>
  18. #include <QImage>
  19. #include <QPixmap>
  20. #include <k3listview.h>
  21. #include "ktigcc.h"
  22. #include "toolprops.h"
  23. void ToolsDialog::init()
  24. {
  25. tempTools=tools;
  26. listView->clear();
  27. listView->setSorting(-1);
  28. Tools::iterator it;
  29. for(it=tempTools.begin(); it!=tempTools.end(); ++it)
  30. new K3ListViewItem(listView,listView->lastItem(),(*it).title,
  31. (*it).commandLine,(*it).workingDirectory,
  32. (*it).runInTerminal?"Yes":"No");
  33. }
  34. void ToolsDialog::addButton_clicked()
  35. {
  36. toolIndex=-1;
  37. ToolProperties toolProperties;
  38. toolProperties.exec();
  39. if (toolProperties.result()==QDialog::Accepted) {
  40. Tool &newTool=tempTools.last();
  41. new K3ListViewItem(listView,listView->lastItem(),newTool.title,
  42. newTool.commandLine,newTool.workingDirectory,
  43. newTool.runInTerminal?"Yes":"No");
  44. } else listView_selectionChanged(); // set the real toolIndex again
  45. }
  46. void ToolsDialog::editButton_clicked()
  47. {
  48. ToolProperties toolProperties;
  49. toolProperties.exec();
  50. if (toolProperties.result()==QDialog::Accepted) {
  51. Tool &newTool=tempTools[toolIndex];
  52. Q3ListViewItem *toolItem=listView->selectedItem();
  53. toolItem->setText(0,newTool.title);
  54. toolItem->setText(1,newTool.commandLine);
  55. toolItem->setText(2,newTool.workingDirectory);
  56. toolItem->setText(3,newTool.runInTerminal?"Yes":"No");
  57. }
  58. }
  59. void ToolsDialog::removeButton_clicked()
  60. {
  61. tempTools.erase(&tempTools[toolIndex]);
  62. delete listView->selectedItem();
  63. }
  64. void ToolsDialog::listView_selectionChanged()
  65. {
  66. toolIndex=listView->itemIndex(listView->selectedItem());
  67. editButton->setEnabled(toolIndex>=0);
  68. removeButton->setEnabled(toolIndex>=0);
  69. }
  70. void ToolsDialog::accept()
  71. {
  72. tools=tempTools;
  73. QDialog::accept();
  74. }
  75. /*
  76. * Constructs a ToolsDialog as a child of 'parent', with the
  77. * name 'name' and widget flags set to 'f'.
  78. *
  79. * The dialog will by default be modeless, unless you set 'modal' to
  80. * true to construct a modal dialog.
  81. */
  82. ToolsDialog::ToolsDialog(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  83. : QDialog(parent, name, modal, fl)
  84. {
  85. setupUi(this);
  86. init();
  87. }
  88. /*
  89. * Destroys the object and frees any allocated resources
  90. */
  91. ToolsDialog::~ToolsDialog()
  92. {
  93. // no need to delete child widgets, Qt does it all for us
  94. }
  95. /*
  96. * Sets the strings of the subwidgets using the current
  97. * language.
  98. */
  99. void ToolsDialog::languageChange()
  100. {
  101. retranslateUi(this);
  102. }