selectcolors.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "selectcolors.h"
  17. #include <kcolordialog.h>
  18. #include <QVariant>
  19. #include <QImage>
  20. #include <QPixmap>
  21. #include <QColor>
  22. #include "colorlistitem.h"
  23. void SelectColors::colorList_selectionChanged()
  24. {
  25. bool haveSelectedItem=!!colorList->selectedItem();
  26. removeButton->setEnabled(haveSelectedItem);
  27. editButton->setEnabled(haveSelectedItem);
  28. }
  29. void SelectColors::addButton_clicked()
  30. {
  31. QColor color;
  32. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  33. new ColorListItem(colorList,color);
  34. }
  35. void SelectColors::removeButton_clicked()
  36. {
  37. delete colorList->selectedItem();
  38. }
  39. void SelectColors::editButton_clicked()
  40. {
  41. ColorListItem *item=static_cast<ColorListItem *>(colorList->selectedItem());
  42. if (item) {
  43. QColor color=item->color();
  44. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  45. item->setColor(color);
  46. }
  47. }
  48. /*
  49. * Constructs a SelectColors as a child of 'parent', with the
  50. * name 'name' and widget flags set to 'f'.
  51. *
  52. * The dialog will by default be modeless, unless you set 'modal' to
  53. * true to construct a modal dialog.
  54. */
  55. SelectColors::SelectColors(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  56. : QDialog(parent, name, modal, fl)
  57. {
  58. setupUi(this);
  59. }
  60. /*
  61. * Destroys the object and frees any allocated resources
  62. */
  63. SelectColors::~SelectColors()
  64. {
  65. // no need to delete child widgets, Qt does it all for us
  66. }
  67. /*
  68. * Sets the strings of the subwidgets using the current
  69. * language.
  70. */
  71. void SelectColors::languageChange()
  72. {
  73. retranslateUi(this);
  74. }