The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "jucer_GroupInformationComponent.h"
  19. //==============================================================================
  20. GroupInformationComponent::GroupInformationComponent (const Project::Item& item_)
  21. : item (item_)
  22. {
  23. list.setModel (this);
  24. addAndMakeVisible (&list);
  25. list.updateContent();
  26. list.setRowHeight (20);
  27. item.state.addListener (this);
  28. }
  29. GroupInformationComponent::~GroupInformationComponent()
  30. {
  31. item.state.removeListener (this);
  32. }
  33. void GroupInformationComponent::resized()
  34. {
  35. list.setSize (getWidth(), getHeight());
  36. }
  37. int GroupInformationComponent::getNumRows()
  38. {
  39. return item.getNumChildren();
  40. }
  41. void GroupInformationComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  42. {
  43. }
  44. //==============================================================================
  45. void GroupInformationComponent::valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const Identifier& property)
  46. {
  47. list.updateContent();
  48. }
  49. void GroupInformationComponent::valueTreeChildAdded (ValueTree&, ValueTree&)
  50. {
  51. list.updateContent();
  52. }
  53. void GroupInformationComponent::valueTreeChildRemoved (ValueTree&, ValueTree&)
  54. {
  55. list.updateContent();
  56. }
  57. void GroupInformationComponent::valueTreeChildOrderChanged (ValueTree&)
  58. {
  59. list.updateContent();
  60. }
  61. void GroupInformationComponent::valueTreeParentChanged (ValueTree&)
  62. {
  63. list.updateContent();
  64. }
  65. //==============================================================================
  66. class FileOptionComponent : public Component
  67. {
  68. public:
  69. FileOptionComponent (const Project::Item& item_)
  70. : item (item_),
  71. compileButton ("Compile"),
  72. resourceButton ("Add to Binary Resources")
  73. {
  74. if (item.isFile())
  75. {
  76. addAndMakeVisible (&compileButton);
  77. compileButton.getToggleStateValue().referTo (item.getShouldCompileValue());
  78. addAndMakeVisible (&resourceButton);
  79. resourceButton.getToggleStateValue().referTo (item.getShouldAddToResourceValue());
  80. }
  81. }
  82. void paint (Graphics& g)
  83. {
  84. int x = getHeight() + 6;
  85. item.getIcon().draw (g, Rectangle<float> (2.0f, 2.0f, x - 4.0f, getHeight() - 4.0f));
  86. g.setColour (Colours::black);
  87. g.setFont (getHeight() * 0.6f);
  88. const int x2 = compileButton.isVisible() ? compileButton.getX() - 4
  89. : getWidth() - 4;
  90. g.drawText (item.getName(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  91. g.setColour (Colours::lightgrey);
  92. g.fillRect (0, getHeight() - 1, getWidth(), 1);
  93. }
  94. void resized()
  95. {
  96. int w = 180;
  97. resourceButton.setBounds (getWidth() - w, 1, w, getHeight() - 2);
  98. w = 100;
  99. compileButton.setBounds (resourceButton.getX() - w, 1, w, getHeight() - 2);
  100. }
  101. Project::Item item;
  102. private:
  103. ToggleButton compileButton, resourceButton;
  104. };
  105. Component* GroupInformationComponent::refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate)
  106. {
  107. if (rowNumber < getNumRows())
  108. {
  109. Project::Item child (item.getChild (rowNumber));
  110. if (existingComponentToUpdate == nullptr
  111. || dynamic_cast <FileOptionComponent*> (existingComponentToUpdate)->item != child)
  112. {
  113. delete existingComponentToUpdate;
  114. existingComponentToUpdate = new FileOptionComponent (child);
  115. }
  116. }
  117. else
  118. {
  119. deleteAndZero (existingComponentToUpdate);
  120. }
  121. return existingComponentToUpdate;
  122. }