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.

157 lines
4.9KB

  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.getNode().addListener (this);
  28. }
  29. GroupInformationComponent::~GroupInformationComponent()
  30. {
  31. item.getNode().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()->drawWithin (g, Rectangle<float> (2.0f, 2.0f, x - 4.0f, getHeight() - 4.0f),
  86. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
  87. g.setColour (Colours::black);
  88. g.setFont (getHeight() * 0.6f);
  89. const int x2 = compileButton.isVisible() ? compileButton.getX() - 4
  90. : getWidth() - 4;
  91. g.drawText (item.getName().toString(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  92. g.setColour (Colours::lightgrey);
  93. g.fillRect (0, getHeight() - 1, getWidth(), 1);
  94. }
  95. void resized()
  96. {
  97. int w = 180;
  98. resourceButton.setBounds (getWidth() - w, 1, w, getHeight() - 2);
  99. w = 100;
  100. compileButton.setBounds (resourceButton.getX() - w, 1, w, getHeight() - 2);
  101. }
  102. Project::Item item;
  103. private:
  104. ToggleButton compileButton, resourceButton;
  105. };
  106. Component* GroupInformationComponent::refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate)
  107. {
  108. if (rowNumber < getNumRows())
  109. {
  110. Project::Item child (item.getChild (rowNumber));
  111. if (existingComponentToUpdate == nullptr
  112. || dynamic_cast <FileOptionComponent*> (existingComponentToUpdate)->item != child)
  113. {
  114. delete existingComponentToUpdate;
  115. existingComponentToUpdate = new FileOptionComponent (child);
  116. }
  117. }
  118. else
  119. {
  120. deleteAndZero (existingComponentToUpdate);
  121. }
  122. return existingComponentToUpdate;
  123. }