swatch_plugin.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "swatch_plugin.hpp"
  23. #include "QtColorWidgets/swatch.hpp"
  24. Swatch_Plugin::Swatch_Plugin(QObject *parent) :
  25. QObject(parent), initialized(false)
  26. {
  27. }
  28. void Swatch_Plugin::initialize(QDesignerFormEditorInterface *)
  29. {
  30. initialized = true;
  31. }
  32. bool Swatch_Plugin::isInitialized() const
  33. {
  34. return initialized;
  35. }
  36. QWidget* Swatch_Plugin::createWidget(QWidget *parent)
  37. {
  38. color_widgets::Swatch *wid = new color_widgets::Swatch(parent);
  39. wid->palette().setColumns(12);
  40. for ( int i = 0; i < 6; i++ )
  41. {
  42. for ( int j = 0; j < wid->palette().columns(); j++ )
  43. {
  44. float f = float(j)/wid->palette().columns();
  45. wid->palette().appendColor(QColor::fromHsvF(i/8.0,1-f,0.5+f/2));
  46. }
  47. }
  48. return wid;
  49. }
  50. QString Swatch_Plugin::name() const
  51. {
  52. return "color_widgets::Swatch";
  53. }
  54. QString Swatch_Plugin::group() const
  55. {
  56. return "Color Widgets";
  57. }
  58. QIcon Swatch_Plugin::icon() const
  59. {
  60. color_widgets::ColorPalette w;
  61. w.setColumns(6);
  62. for ( int i = 0; i < 4; i++ )
  63. {
  64. for ( int j = 0; j < w.columns(); j++ )
  65. {
  66. float f = float(j)/w.columns();
  67. w.appendColor(QColor::fromHsvF(i/5.0,1-f,0.5+f/2));
  68. }
  69. }
  70. return QIcon(w.preview(QSize(64,64)));
  71. }
  72. QString Swatch_Plugin::toolTip() const
  73. {
  74. return "A widget that displays a color palette";
  75. }
  76. QString Swatch_Plugin::whatsThis() const
  77. {
  78. return toolTip();
  79. }
  80. bool Swatch_Plugin::isContainer() const
  81. {
  82. return false;
  83. }
  84. QString Swatch_Plugin::domXml() const
  85. {
  86. return "<ui language=\"c++\">\n"
  87. " <widget class=\"color_widgets::Swatch\" name=\"swatch\">\n"
  88. " </widget>\n"
  89. "</ui>\n";
  90. }
  91. QString Swatch_Plugin::includeFile() const
  92. {
  93. return "QtColorWidgets/swatch.hpp";
  94. }