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.

194 lines
7.0KB

  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(), { 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. std::unique_ptr<Component> existing (existingComponentToUpdate);
  74. if (rowNumber < getNumRows())
  75. {
  76. auto child = item.getChild (rowNumber);
  77. if (existingComponentToUpdate == nullptr
  78. || dynamic_cast<FileOptionComponent*> (existing.get())->item != child)
  79. {
  80. existing.reset();
  81. existing.reset (new FileOptionComponent (child, dynamic_cast<ListBoxHeader*> (list.getHeaderComponent())));
  82. }
  83. }
  84. return existing.release();
  85. }
  86. String getGroupPath() const { return item.getFile().getFullPathName(); }
  87. //==============================================================================
  88. void valueTreePropertyChanged (ValueTree&, const Identifier&) override { itemChanged(); }
  89. void valueTreeChildAdded (ValueTree&, ValueTree&) override { itemChanged(); }
  90. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override { itemChanged(); }
  91. void valueTreeChildOrderChanged (ValueTree&, int, int) override { itemChanged(); }
  92. void valueTreeParentChanged (ValueTree&) override { itemChanged(); }
  93. private:
  94. Project::Item item;
  95. ListBox list;
  96. ContentViewHeader header;
  97. void itemChanged()
  98. {
  99. list.updateContent();
  100. repaint();
  101. }
  102. //==============================================================================
  103. class FileOptionComponent : public Component
  104. {
  105. public:
  106. FileOptionComponent (const Project::Item& fileItem, ListBoxHeader* listBoxHeader)
  107. : item (fileItem),
  108. header (listBoxHeader)
  109. {
  110. if (item.isFile())
  111. {
  112. addAndMakeVisible (compileButton);
  113. compileButton.getToggleStateValue().referTo (item.getShouldCompileValue());
  114. addAndMakeVisible (binaryResourceButton);
  115. binaryResourceButton.getToggleStateValue().referTo (item.getShouldAddToBinaryResourcesValue());
  116. addAndMakeVisible (xcodeResourceButton);
  117. xcodeResourceButton.getToggleStateValue().referTo (item.getShouldAddToXcodeResourcesValue());
  118. }
  119. }
  120. void paint (Graphics& g) override
  121. {
  122. if (header != nullptr)
  123. {
  124. auto textBounds = getLocalBounds().removeFromLeft (roundToInt (header->getProportionAtIndex (0) * getWidth()));
  125. auto iconBounds = textBounds.removeFromLeft (25);
  126. if (item.isImageFile())
  127. iconBounds.reduce (5, 5);
  128. item.getIcon().withColour (findColour (treeIconColourId)).draw (g, iconBounds.toFloat(), item.isIconCrossedOut());
  129. g.setColour (findColour (widgetTextColourId));
  130. g.drawText (item.getName(), textBounds, Justification::centredLeft);
  131. }
  132. }
  133. void resized() override
  134. {
  135. if (header != nullptr)
  136. {
  137. auto bounds = getLocalBounds();
  138. auto width = getWidth();
  139. bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (0) * width));
  140. binaryResourceButton.setBounds (bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (1) * width)));
  141. xcodeResourceButton.setBounds (bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (2) * width)));
  142. compileButton.setBounds (bounds.removeFromLeft (roundToInt (header->getProportionAtIndex (3) * width)));
  143. }
  144. }
  145. Project::Item item;
  146. private:
  147. ListBoxHeader* header;
  148. ToggleButton compileButton, binaryResourceButton, xcodeResourceButton;
  149. };
  150. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileGroupInformationComponent)
  151. };