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.

192 lines
6.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. class FileGroupInformationComponent : public Component,
  22. private ListBoxModel,
  23. private ValueTree::Listener
  24. {
  25. public:
  26. FileGroupInformationComponent (const Project::Item& group)
  27. : item (group),
  28. header (item.getName(), Icon (getIcons().openFolder, Colours::transparentBlack))
  29. {
  30. list.setHeaderComponent (new ListBoxHeader ( { "File", "Binary Resource", "Xcode Resource", "Compile" },
  31. { 0.4f, 0.2f, 0.2f, 0.2f } ));
  32. list.setModel (this);
  33. list.setColour (ListBox::backgroundColourId, Colours::transparentBlack);
  34. addAndMakeVisible (list);
  35. list.updateContent();
  36. list.setRowHeight (30);
  37. item.state.addListener (this);
  38. lookAndFeelChanged();
  39. addAndMakeVisible (header);
  40. }
  41. ~FileGroupInformationComponent()
  42. {
  43. item.state.removeListener (this);
  44. }
  45. //==============================================================================
  46. void paint (Graphics& g) override
  47. {
  48. g.setColour (findColour (secondaryBackgroundColourId));
  49. g.fillRect (getLocalBounds().reduced (12, 0));
  50. }
  51. void resized() override
  52. {
  53. auto bounds = getLocalBounds().reduced (12, 0);
  54. header.setBounds (bounds.removeFromTop (40));
  55. list.setBounds (bounds.reduced (10, 4));
  56. }
  57. void parentSizeChanged() override
  58. {
  59. setSize (jmax (550, getParentWidth()), getParentHeight());
  60. }
  61. int getNumRows() override
  62. {
  63. return item.getNumChildren();
  64. }
  65. void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool /*rowIsSelected*/) override
  66. {
  67. g.setColour (findColour (rowNumber % 2 == 0 ? widgetBackgroundColourId
  68. : secondaryWidgetBackgroundColourId));
  69. g.fillRect (0, 0, width, height - 1);
  70. }
  71. Component* refreshComponentForRow (int rowNumber, bool /*isRowSelected*/, Component* existingComponentToUpdate) override
  72. {
  73. ScopedPointer<Component> existing (existingComponentToUpdate);
  74. if (rowNumber < getNumRows())
  75. {
  76. Project::Item child (item.getChild (rowNumber));
  77. if (existingComponentToUpdate == nullptr
  78. || dynamic_cast<FileOptionComponent*> (existing.get())->item != child)
  79. {
  80. existing = nullptr;
  81. existing = new FileOptionComponent (child, dynamic_cast<ListBoxHeader*> (list.getHeaderComponent()));
  82. }
  83. }
  84. return existing.release();
  85. }
  86. //==============================================================================
  87. void valueTreePropertyChanged (ValueTree&, const Identifier&) override { itemChanged(); }
  88. void valueTreeChildAdded (ValueTree&, ValueTree&) override { itemChanged(); }
  89. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override { itemChanged(); }
  90. void valueTreeChildOrderChanged (ValueTree&, int, int) override { itemChanged(); }
  91. void valueTreeParentChanged (ValueTree&) override { itemChanged(); }
  92. private:
  93. Project::Item item;
  94. ListBox list;
  95. ContentViewHeader header;
  96. void itemChanged()
  97. {
  98. list.updateContent();
  99. repaint();
  100. }
  101. //==============================================================================
  102. class FileOptionComponent : public Component
  103. {
  104. public:
  105. FileOptionComponent (const Project::Item& fileItem, ListBoxHeader* listBoxHeader)
  106. : item (fileItem),
  107. header (listBoxHeader)
  108. {
  109. if (item.isFile())
  110. {
  111. addAndMakeVisible (compileButton);
  112. compileButton.getToggleStateValue().referTo (item.getShouldCompileValue());
  113. addAndMakeVisible (binaryResourceButton);
  114. binaryResourceButton.getToggleStateValue().referTo (item.getShouldAddToBinaryResourcesValue());
  115. addAndMakeVisible (xcodeResourceButton);
  116. xcodeResourceButton.getToggleStateValue().referTo (item.getShouldAddToXcodeResourcesValue());
  117. }
  118. }
  119. void paint (Graphics& g) override
  120. {
  121. if (header != nullptr)
  122. {
  123. auto textBounds = getLocalBounds().removeFromLeft (roundToInt (header->getProportionAtIndex (0) * getWidth()));
  124. auto iconBounds = textBounds.removeFromLeft (25);
  125. if (item.isImageFile())
  126. iconBounds.reduce (5, 5);
  127. item.getIcon().withColour (findColour (treeIconColourId)).draw (g, iconBounds.toFloat(), item.isIconCrossedOut());
  128. g.setColour (findColour (widgetTextColourId));
  129. g.drawText (item.getName(), textBounds, Justification::centredLeft);
  130. }
  131. }
  132. void resized() override
  133. {
  134. if (header != nullptr)
  135. {
  136. auto bounds = getLocalBounds();
  137. auto width = getWidth();
  138. bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (0) * width));
  139. binaryResourceButton.setBounds (bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (1) * width)));
  140. xcodeResourceButton.setBounds (bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (2) * width)));
  141. compileButton.setBounds (bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (3) * width)));
  142. }
  143. }
  144. Project::Item item;
  145. private:
  146. ListBoxHeader* header;
  147. ToggleButton compileButton, binaryResourceButton, xcodeResourceButton;
  148. };
  149. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileGroupInformationComponent)
  150. };