Subscriptions.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. ==============================================================================
  3. This is an automatically generated GUI class created by the Introjucer!
  4. Be careful when adding custom code to these files, as only the code within
  5. the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  6. and re-saved.
  7. Created with Introjucer version: 3.1.0
  8. ------------------------------------------------------------------------------
  9. The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
  10. Copyright 2004-13 by Raw Material Software Ltd.
  11. ==============================================================================
  12. */
  13. //[Headers] You can add your own extra header files here...
  14. #include "Constants.h"
  15. //[/Headers]
  16. #include "Subscriptions.h"
  17. //[MiscUserDefs] You can add your own user definitions and misc code here...
  18. //[/MiscUserDefs]
  19. //==============================================================================
  20. Subscription::Subscription (ValueTree config_store)
  21. : configStore(config_store)
  22. {
  23. addAndMakeVisible (removeButton = new TextButton ("removeButton"));
  24. removeButton->setButtonText (TRANS("X"));
  25. removeButton->addListener (this);
  26. removeButton->setColour (TextButton::buttonColourId, Colour (0xff400000));
  27. removeButton->setColour (TextButton::buttonOnColourId, Colours::maroon);
  28. removeButton->setColour (TextButton::textColourOnId, Colours::red);
  29. removeButton->setColour (TextButton::textColourOffId, Colours::red);
  30. addAndMakeVisible (userLabel = new Label ("userLabel",
  31. TRANS("label text")));
  32. userLabel->setFont (Font (15.00f, Font::plain));
  33. userLabel->setJustificationType (Justification::centredLeft);
  34. userLabel->setEditable (false, false, false);
  35. userLabel->setColour (Label::textColourId, Colours::grey);
  36. userLabel->setColour (TextEditor::textColourId, Colours::black);
  37. userLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
  38. //[UserPreSize]
  39. //[/UserPreSize]
  40. setSize (132, 16);
  41. //[Constructor] You can add your own custom stuff here..
  42. setSize(GUI::SUBSCRIPTION_W , GUI::SUBSCRIPTION_H) ;
  43. userLabel->setText(String(config_store.getType()) , juce::dontSendNotification) ;
  44. this->configStore = config_store ;
  45. //[/Constructor]
  46. }
  47. Subscription::~Subscription()
  48. {
  49. //[Destructor_pre]. You can add your own custom destruction code here..
  50. //[/Destructor_pre]
  51. removeButton = nullptr;
  52. userLabel = nullptr;
  53. //[Destructor]. You can add your own custom destruction code here..
  54. //[/Destructor]
  55. }
  56. //==============================================================================
  57. void Subscription::paint (Graphics& g)
  58. {
  59. //[UserPrePaint] Add your own custom painting code here..
  60. //[/UserPrePaint]
  61. g.setColour (Colours::black);
  62. g.fillRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), 16.0f, 10.000f);
  63. g.setColour (Colours::white);
  64. g.drawRoundedRectangle (0.0f, 0.0f, static_cast<float> (getWidth() - 0), 16.0f, 10.000f, 1.000f);
  65. //[UserPaint] Add your own custom painting code here..
  66. //[/UserPaint]
  67. }
  68. void Subscription::resized()
  69. {
  70. removeButton->setBounds (0, 0, 15, 16);
  71. userLabel->setBounds (16, 0, getWidth() - 16, 16);
  72. //[UserResized] Add your own custom resize handling here..
  73. //[/UserResized]
  74. }
  75. void Subscription::buttonClicked (Button* buttonThatWasClicked)
  76. {
  77. //[UserbuttonClicked_Pre]
  78. //[/UserbuttonClicked_Pre]
  79. if (buttonThatWasClicked == removeButton)
  80. {
  81. //[UserButtonCode_removeButton] -- add your button handler code here..
  82. // destroy storage for this subscription (configures NJClient asynchronously)
  83. this->configStore.getParent().removeChild(this->configStore , nullptr) ;
  84. // destroy this GUI component
  85. ((Subscriptions*)this->getParentComponent())->removeSubscription(this) ;
  86. //[/UserButtonCode_removeButton]
  87. }
  88. //[UserbuttonClicked_Post]
  89. //[/UserbuttonClicked_Post]
  90. }
  91. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  92. Subscriptions::Subscriptions(ValueTree config_store)
  93. {
  94. for (int user_n = 0 ; user_n < config_store.getNumChildren() ; ++user_n)
  95. addAndMakeVisible(new Subscription(config_store.getChild(user_n))) ;
  96. setSize(GUI::SUBSCRIPTIONS_W , computeHeight()) ;
  97. }
  98. Subscriptions::~Subscriptions() { deleteAllChildren() ; }
  99. void Subscriptions::resized()
  100. {
  101. bool is_scrollbar_visible = getHeight() > GUI::SUBSCRIPTIONS_H ;
  102. int subscriptions_w = (is_scrollbar_visible)?
  103. GUI::SUBSCRIPTIONS_W - GUI::CONFIG_SCROLLBAR_W - GUI::PAD :
  104. GUI::SUBSCRIPTIONS_W ;
  105. int user_x = 0 ;
  106. int user_y = 0 ;
  107. // resize and arrange user entries
  108. for (int user_n = 0 ; user_n < getNumChildComponents() ; ++user_n)
  109. {
  110. Component* subscription = getChildComponent(user_n) ;
  111. subscription->setSize( subscriptions_w , GUI::SUBSCRIPTION_H) ;
  112. subscription->setTopLeftPosition(user_x , user_y) ;
  113. user_y += GUI::SUBSCRIPTION_H + GUI::PAD ;
  114. }
  115. }
  116. int Subscriptions::computeHeight()
  117. {
  118. return GUI::PAD + (getNumChildComponents() * (GUI::SUBSCRIPTION_H + GUI::PAD)) ;
  119. }
  120. void Subscriptions::removeSubscription(Subscription* a_subscription)
  121. {
  122. delete a_subscription ; setSize(GUI::SUBSCRIPTIONS_W , computeHeight()) ;
  123. }
  124. //[/MiscUserCode]
  125. //==============================================================================
  126. #if 0
  127. /* -- Introjucer information section --
  128. This is where the Introjucer stores the metadata that describe this GUI layout, so
  129. make changes in here at your peril!
  130. BEGIN_JUCER_METADATA
  131. <JUCER_COMPONENT documentType="Component" className="Subscription" componentName=""
  132. parentClasses="public Component" constructorParams="ValueTree config_store"
  133. variableInitialisers="configStore(config_store)" snapPixels="8"
  134. snapActive="1" snapShown="1" overlayOpacity="0.330" fixedSize="1"
  135. initialWidth="132" initialHeight="16">
  136. <BACKGROUND backgroundColour="0">
  137. <ROUNDRECT pos="0 0 0M 16" cornerSize="10" fill="solid: ff000000" hasStroke="1"
  138. stroke="1, mitered, butt" strokeColour="solid: ffffffff"/>
  139. </BACKGROUND>
  140. <TEXTBUTTON name="removeButton" id="5ea28eb29c334aeb" memberName="removeButton"
  141. virtualName="" explicitFocusOrder="0" pos="0 0 15 16" bgColOff="ff400000"
  142. bgColOn="ff800000" textCol="ffff0000" textColOn="ffff0000" buttonText="X"
  143. connectedEdges="0" needsCallback="1" radioGroupId="0"/>
  144. <LABEL name="userLabel" id="4316b113334d5ced" memberName="userLabel"
  145. virtualName="" explicitFocusOrder="0" pos="16 0 16M 16" textCol="ff808080"
  146. edTextCol="ff000000" edBkgCol="0" labelText="label text" editableSingleClick="0"
  147. editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
  148. fontsize="15" bold="0" italic="0" justification="33"/>
  149. </JUCER_COMPONENT>
  150. END_JUCER_METADATA
  151. */
  152. #endif
  153. //[EndFile] You can add extra defines here...
  154. //[/EndFile]