color_palette_widget_plugin.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**
  2. * \file
  3. *
  4. * \author Mattia Basaglia
  5. *
  6. * \copyright Copyright (C) 2013-2020 Mattia Basaglia
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "color_palette_widget_plugin.hpp"
  23. #include "QtColorWidgets/color_palette_widget.hpp"
  24. ColorPaletteWidget_Plugin::ColorPaletteWidget_Plugin(QObject *parent) :
  25. QObject(parent), initialized(false)
  26. {
  27. }
  28. void ColorPaletteWidget_Plugin::initialize(QDesignerFormEditorInterface *)
  29. {
  30. initialized = true;
  31. }
  32. bool ColorPaletteWidget_Plugin::isInitialized() const
  33. {
  34. return initialized;
  35. }
  36. QWidget* ColorPaletteWidget_Plugin::createWidget(QWidget *parent)
  37. {
  38. color_widgets::ColorPaletteWidget *wid = new color_widgets::ColorPaletteWidget(parent);
  39. color_widgets::ColorPalette palette1;
  40. color_widgets::ColorPalette palette2;
  41. int columns = 12;
  42. palette1.setName("Palette 1");
  43. palette2.setName("Palette 2");
  44. palette1.setColumns(columns);
  45. palette2.setColumns(columns);
  46. for ( int i = 0; i < 6; i++ )
  47. {
  48. for ( int j = 0; j < columns; j++ )
  49. {
  50. float f = float(j)/columns;
  51. palette1.appendColor(QColor::fromHsvF(i/8.0,1-f,0.5+f/2));
  52. palette2.appendColor(QColor::fromHsvF(i/8.0,1-f,1-f));
  53. }
  54. }
  55. color_widgets::ColorPaletteModel *model = new color_widgets::ColorPaletteModel;
  56. model->setParent(wid);
  57. model->addPalette(palette1, false);
  58. model->addPalette(palette2, false);
  59. wid->setModel(model);
  60. return wid;
  61. }
  62. QString ColorPaletteWidget_Plugin::name() const
  63. {
  64. return "color_widgets::ColorPaletteWidget";
  65. }
  66. QString ColorPaletteWidget_Plugin::group() const
  67. {
  68. return "Color Widgets";
  69. }
  70. QIcon ColorPaletteWidget_Plugin::icon() const
  71. {
  72. color_widgets::ColorPalette w;
  73. w.setColumns(6);
  74. for ( int i = 0; i < 4; i++ )
  75. {
  76. for ( int j = 0; j < w.columns(); j++ )
  77. {
  78. float f = float(j)/w.columns();
  79. w.appendColor(QColor::fromHsvF(i/5.0,1-f,0.5+f/2));
  80. }
  81. }
  82. return QIcon(w.preview(QSize(64,64)));
  83. }
  84. QString ColorPaletteWidget_Plugin::toolTip() const
  85. {
  86. return "A widget that displays a color palette";
  87. }
  88. QString ColorPaletteWidget_Plugin::whatsThis() const
  89. {
  90. return toolTip();
  91. }
  92. bool ColorPaletteWidget_Plugin::isContainer() const
  93. {
  94. return false;
  95. }
  96. QString ColorPaletteWidget_Plugin::domXml() const
  97. {
  98. return "<ui language=\"c++\">\n"
  99. " <widget class=\"color_widgets::ColorPaletteWidget\" name=\"palette_widget\">\n"
  100. " </widget>\n"
  101. "</ui>\n";
  102. }
  103. QString ColorPaletteWidget_Plugin::includeFile() const
  104. {
  105. return "QtColorWidgets/color_palette_widget.hpp";
  106. }