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.

147 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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::valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged)
  50. {
  51. list.updateContent();
  52. }
  53. void GroupInformationComponent::valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged)
  54. {
  55. list.updateContent();
  56. }
  57. //==============================================================================
  58. class FileOptionComponent : public Component
  59. {
  60. public:
  61. FileOptionComponent (const Project::Item& item_)
  62. : item (item_),
  63. compileButton ("Compile"),
  64. resourceButton ("Add to Binary Resources")
  65. {
  66. if (item.isFile())
  67. {
  68. addAndMakeVisible (&compileButton);
  69. compileButton.getToggleStateValue().referTo (item.getShouldCompileValue());
  70. addAndMakeVisible (&resourceButton);
  71. resourceButton.getToggleStateValue().referTo (item.getShouldAddToResourceValue());
  72. }
  73. }
  74. void paint (Graphics& g)
  75. {
  76. int x = getHeight() + 6;
  77. g.drawImageWithin (item.getIcon(), 2, 2, x - 4, getHeight() - 4,
  78. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  79. false);
  80. g.setColour (Colours::black);
  81. g.setFont (getHeight() * 0.6f);
  82. const int x2 = compileButton.isVisible() ? compileButton.getX() - 4
  83. : getWidth() - 4;
  84. g.drawText (item.getName().toString(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  85. g.setColour (Colours::lightgrey);
  86. g.fillRect (0, getHeight() - 1, getWidth(), 1);
  87. }
  88. void resized()
  89. {
  90. int w = 180;
  91. resourceButton.setBounds (getWidth() - w, 1, w, getHeight() - 2);
  92. w = 100;
  93. compileButton.setBounds (resourceButton.getX() - w, 1, w, getHeight() - 2);
  94. }
  95. Project::Item item;
  96. private:
  97. ToggleButton compileButton, resourceButton;
  98. };
  99. Component* GroupInformationComponent::refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate)
  100. {
  101. if (rowNumber < getNumRows())
  102. {
  103. Project::Item child (item.getChild (rowNumber));
  104. if (existingComponentToUpdate == 0
  105. || dynamic_cast <FileOptionComponent*> (existingComponentToUpdate)->item != child)
  106. {
  107. delete existingComponentToUpdate;
  108. existingComponentToUpdate = new FileOptionComponent (child);
  109. }
  110. }
  111. else
  112. {
  113. deleteAndZero (existingComponentToUpdate);
  114. }
  115. return existingComponentToUpdate;
  116. }