annotate Source/GUI/MappingListItem.cpp @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 85577160a0d4
children
rev   line source
andrewm@0 1 /*
andrewm@0 2 ==============================================================================
andrewm@0 3
andrewm@0 4 This is an automatically generated GUI class created by the Introjucer!
andrewm@0 5
andrewm@0 6 Be careful when adding custom code to these files, as only the code within
andrewm@0 7 the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
andrewm@0 8 and re-saved.
andrewm@0 9
andrewm@0 10 Created with Introjucer version: 3.1.0
andrewm@0 11
andrewm@0 12 ------------------------------------------------------------------------------
andrewm@0 13
andrewm@0 14 The Introjucer is part of the JUCE library - "Jules' Utility Class Extensions"
andrewm@0 15 Copyright 2004-13 by Raw Material Software Ltd.
andrewm@0 16
andrewm@0 17 ==============================================================================
andrewm@0 18 */
andrewm@0 19
andrewm@0 20 //[Headers] You can add your own extra header files here...
andrewm@0 21 #ifndef TOUCHKEYS_NO_GUI
andrewm@0 22 #include "MappingListComponent.h"
andrewm@41 23 #include "MappingExtendedEditorWindow.h"
andrewm@0 24 //[/Headers]
andrewm@0 25
andrewm@0 26 #include "MappingListItem.h"
andrewm@0 27
andrewm@0 28
andrewm@0 29 //[MiscUserDefs] You can add your own user definitions and misc code here...
andrewm@0 30 //[/MiscUserDefs]
andrewm@0 31
andrewm@0 32 //==============================================================================
andrewm@0 33 MappingListItem::MappingListItem (MappingListComponent& listComponent)
andrewm@0 34 : factory_(0), listComponent_(listComponent)
andrewm@0 35 {
andrewm@0 36 addAndMakeVisible (bypassToggleButton = new ToggleButton ("Bypass toggle button"));
andrewm@0 37 bypassToggleButton->setButtonText ("Bypass");
andrewm@0 38 bypassToggleButton->addListener (this);
andrewm@0 39
andrewm@0 40 addAndMakeVisible (showDetailsButton = new TextButton ("Show details button"));
andrewm@0 41 showDetailsButton->setButtonText ("Details...");
andrewm@0 42 showDetailsButton->addListener (this);
andrewm@0 43
andrewm@0 44 addAndMakeVisible (mappingTypeLabel = new Label ("mapping type label",
andrewm@0 45 "MappingType"));
andrewm@0 46 mappingTypeLabel->setFont (Font (18.00f, Font::plain));
andrewm@0 47 mappingTypeLabel->setJustificationType (Justification::centred);
andrewm@0 48 mappingTypeLabel->setEditable (false, false, false);
andrewm@0 49 mappingTypeLabel->setColour (TextEditor::textColourId, Colours::black);
andrewm@0 50 mappingTypeLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@0 51
andrewm@0 52 addAndMakeVisible (mappingShortEditorComponent = new MappingEditorComponent());
andrewm@0 53 mappingShortEditorComponent->setName ("mapping short editor component");
andrewm@0 54
andrewm@0 55 addAndMakeVisible (noSettingsLabel = new Label ("no settings label",
andrewm@0 56 "(no settings)"));
andrewm@0 57 noSettingsLabel->setFont (Font (15.00f, Font::plain));
andrewm@0 58 noSettingsLabel->setJustificationType (Justification::centred);
andrewm@0 59 noSettingsLabel->setEditable (false, false, false);
andrewm@0 60 noSettingsLabel->setColour (TextEditor::textColourId, Colours::black);
andrewm@0 61 noSettingsLabel->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
andrewm@0 62
andrewm@0 63 addAndMakeVisible (deleteButton = new TextButton ("delete button"));
andrewm@0 64 deleteButton->setButtonText ("Delete...");
andrewm@0 65 deleteButton->addListener (this);
andrewm@0 66
andrewm@0 67
andrewm@0 68 //[UserPreSize]
andrewm@0 69 //[/UserPreSize]
andrewm@0 70
andrewm@0 71 setSize (544, 72);
andrewm@0 72
andrewm@0 73
andrewm@0 74 //[Constructor] You can add your own custom stuff here..
andrewm@0 75 //[/Constructor]
andrewm@0 76 }
andrewm@0 77
andrewm@0 78 MappingListItem::~MappingListItem()
andrewm@0 79 {
andrewm@0 80 //[Destructor_pre]. You can add your own custom destruction code here..
andrewm@0 81 //[/Destructor_pre]
andrewm@0 82
andrewm@0 83 bypassToggleButton = nullptr;
andrewm@0 84 showDetailsButton = nullptr;
andrewm@0 85 mappingTypeLabel = nullptr;
andrewm@0 86 mappingShortEditorComponent = nullptr;
andrewm@0 87 noSettingsLabel = nullptr;
andrewm@0 88 deleteButton = nullptr;
andrewm@0 89
andrewm@0 90
andrewm@0 91 //[Destructor]. You can add your own custom destruction code here..
andrewm@0 92 //[/Destructor]
andrewm@0 93 }
andrewm@0 94
andrewm@0 95 //==============================================================================
andrewm@0 96 void MappingListItem::paint (Graphics& g)
andrewm@0 97 {
andrewm@0 98 //[UserPrePaint] Add your own custom painting code here..
andrewm@0 99 //[/UserPrePaint]
andrewm@0 100
andrewm@0 101 g.fillAll (Colours::white);
andrewm@0 102
andrewm@0 103 g.setColour (Colour (0xffa52a60));
andrewm@0 104 g.fillPath (internalPath1);
andrewm@0 105 g.setColour (Colours::black);
andrewm@0 106 g.strokePath (internalPath1, PathStrokeType (1.000f));
andrewm@0 107
andrewm@0 108 g.setColour (Colour (0xffa52a94));
andrewm@0 109 g.fillPath (internalPath2);
andrewm@0 110 g.setColour (Colours::black);
andrewm@0 111 g.strokePath (internalPath2, PathStrokeType (0.500f));
andrewm@0 112
andrewm@0 113 //[UserPaint] Add your own custom painting code here..
andrewm@0 114 /*MappingListComponent *parent = static_cast<MappingListComponent*>(getParentComponent());
andrewm@0 115 if(parent->isComponentSelected(this)) {
andrewm@0 116 g.setColour (Colours::lightblue);
andrewm@0 117 g.drawRect (0, 0, 544, 72, 5);
andrewm@0 118 }*/
andrewm@0 119 //[/UserPaint]
andrewm@0 120 }
andrewm@0 121
andrewm@0 122 void MappingListItem::resized()
andrewm@0 123 {
andrewm@0 124 bypassToggleButton->setBounds (24, 44, 72, 24);
andrewm@0 125 showDetailsButton->setBounds (456, 8, 80, 24);
andrewm@0 126 mappingTypeLabel->setBounds (8, 4, 104, 40);
andrewm@0 127 mappingShortEditorComponent->setBounds (120, 0, 328, 71);
andrewm@0 128 noSettingsLabel->setBounds (208, 24, 150, 24);
andrewm@0 129 deleteButton->setBounds (456, 44, 80, 20);
andrewm@0 130 internalPath1.clear();
andrewm@0 131 internalPath1.startNewSubPath (544.0f, 72.0f);
andrewm@0 132 internalPath1.lineTo (0.0f, 72.0f);
andrewm@0 133 internalPath1.closeSubPath();
andrewm@0 134
andrewm@0 135 internalPath2.clear();
andrewm@0 136 internalPath2.startNewSubPath (119.0f, 16.0f);
andrewm@0 137 internalPath2.lineTo (119.0f, 56.0f);
andrewm@0 138 internalPath2.closeSubPath();
andrewm@0 139
andrewm@0 140 //[UserResized] Add your own custom resize handling here..
andrewm@0 141 //[/UserResized]
andrewm@0 142 }
andrewm@0 143
andrewm@0 144 void MappingListItem::buttonClicked (Button* buttonThatWasClicked)
andrewm@0 145 {
andrewm@0 146 //[UserbuttonClicked_Pre]
andrewm@0 147 if(factory_ == 0)
andrewm@0 148 return;
andrewm@0 149 //[/UserbuttonClicked_Pre]
andrewm@0 150
andrewm@0 151 if (buttonThatWasClicked == bypassToggleButton)
andrewm@0 152 {
andrewm@0 153 //[UserButtonCode_bypassToggleButton] -- add your button handler code here..
andrewm@0 154 bool bypass = bypassToggleButton->getToggleState();
andrewm@0 155 factory_->setBypassed(bypass);
andrewm@0 156 //[/UserButtonCode_bypassToggleButton]
andrewm@0 157 }
andrewm@0 158 else if (buttonThatWasClicked == showDetailsButton)
andrewm@0 159 {
andrewm@0 160 //[UserButtonCode_showDetailsButton] -- add your button handler code here..
andrewm@41 161 // Create an extended editor window
andrewm@41 162 MappingExtendedEditorWindow *window = listComponent_.extendedEditorWindowForFactory(factory_);
andrewm@41 163 if(window != 0) {
andrewm@41 164 window->setVisible(true);
andrewm@41 165 window->toFront(true);
andrewm@41 166 }
andrewm@41 167 else if(factory_->hasExtendedEditor())
andrewm@41 168 listComponent_.openExtendedEditorWindow(factory_);
andrewm@0 169 //[/UserButtonCode_showDetailsButton]
andrewm@0 170 }
andrewm@0 171 else if (buttonThatWasClicked == deleteButton)
andrewm@0 172 {
andrewm@0 173 //[UserButtonCode_deleteButton] -- add your button handler code here..
andrewm@0 174 // Display an alert to confirm the user wants to delete this mapping
andrewm@0 175 AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
andrewm@0 176 "Delete mapping",
andrewm@0 177 "Are you sure you want to delete this mapping?",
andrewm@0 178 String::empty,
andrewm@0 179 String::empty,
andrewm@0 180 0,
andrewm@0 181 ModalCallbackFunction::forComponent (alertBoxResultChosen, this));
andrewm@0 182 //[/UserButtonCode_deleteButton]
andrewm@0 183 }
andrewm@0 184
andrewm@0 185 //[UserbuttonClicked_Post]
andrewm@0 186 //[/UserbuttonClicked_Post]
andrewm@0 187 }
andrewm@0 188
andrewm@0 189
andrewm@0 190
andrewm@0 191 //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
andrewm@0 192
andrewm@0 193 // Called when user clicks a result in the alert box to confirm deletion
andrewm@0 194 void MappingListItem::alertBoxResultChosen(int result, MappingListItem *item)
andrewm@0 195 {
andrewm@0 196 if(result != 0) {
andrewm@0 197 item->deleteMapping();
andrewm@0 198 }
andrewm@0 199 }
andrewm@0 200
andrewm@0 201 // Delete this mapping factory
andrewm@0 202 void MappingListItem::deleteMapping()
andrewm@0 203 {
andrewm@0 204 listComponent_.deleteMapping(factory_);
andrewm@0 205 }
andrewm@0 206
andrewm@0 207 // Set the mapping factory and create any editor components it uses
andrewm@0 208 void MappingListItem::setMappingFactory(MappingFactory *factory)
andrewm@0 209 {
andrewm@0 210 factory_ = factory;
andrewm@0 211
andrewm@0 212 if(factory_->hasBasicEditor()) {
andrewm@0 213 // Has a short editor: make one and add it to the window, using the same bounds
andrewm@0 214 // as before
andrewm@20 215 const juce::Rectangle<int>& bounds = mappingShortEditorComponent->getBounds();
andrewm@0 216 mappingShortEditorComponent = factory_->createBasicEditor();
andrewm@0 217 addAndMakeVisible(mappingShortEditorComponent);
andrewm@0 218 mappingShortEditorComponent->setBounds(bounds);
andrewm@0 219 noSettingsLabel->setVisible(false);
andrewm@0 220 }
andrewm@0 221 else {
andrewm@0 222 noSettingsLabel->setVisible(true);
andrewm@0 223 mappingShortEditorComponent->setVisible(false);
andrewm@0 224 }
andrewm@0 225
andrewm@0 226 if(factory_->hasExtendedEditor()) {
andrewm@0 227 showDetailsButton->setEnabled(true);
andrewm@0 228 }
andrewm@0 229 else {
andrewm@0 230 showDetailsButton->setEnabled(false);
andrewm@0 231 }
andrewm@0 232
andrewm@0 233 synchronize();
andrewm@0 234 }
andrewm@0 235
andrewm@0 236 void MappingListItem::synchronize()
andrewm@0 237 {
andrewm@0 238 if(factory_ == 0)
andrewm@0 239 return;
andrewm@0 240
andrewm@0 241 // Update the label and the bypass button
andrewm@0 242 mappingTypeLabel->setText(factory_->factoryTypeName().c_str(), dontSendNotification);
andrewm@0 243 if(factory_->bypassed() != MappingFactory::kBypassOff)
andrewm@0 244 bypassToggleButton->setToggleState(true, dontSendNotification);
andrewm@0 245 else
andrewm@0 246 bypassToggleButton->setToggleState(false, dontSendNotification);
andrewm@0 247
andrewm@0 248 // Update the short and long components if present
andrewm@0 249 if(mappingShortEditorComponent != 0)
andrewm@0 250 mappingShortEditorComponent->synchronize();
andrewm@0 251 }
andrewm@0 252 //[/MiscUserCode]
andrewm@0 253
andrewm@0 254
andrewm@0 255 //==============================================================================
andrewm@0 256 #if 0
andrewm@0 257 /* -- Introjucer information section --
andrewm@0 258
andrewm@0 259 This is where the Introjucer stores the metadata that describe this GUI layout, so
andrewm@0 260 make changes in here at your peril!
andrewm@0 261
andrewm@0 262 BEGIN_JUCER_METADATA
andrewm@0 263
andrewm@0 264 <JUCER_COMPONENT documentType="Component" className="MappingListItem" componentName=""
andrewm@0 265 parentClasses="public Component" constructorParams="MappingListComponent&amp; listComponent"
andrewm@0 266 variableInitialisers="factory_(0), listComponent_(listComponent)"
andrewm@0 267 snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
andrewm@0 268 fixedSize="1" initialWidth="544" initialHeight="72">
andrewm@0 269 <BACKGROUND backgroundColour="ffffffff">
andrewm@0 270 <PATH pos="0 0 100 100" fill="solid: ffa52a60" hasStroke="1" stroke="1, mitered, butt"
andrewm@0 271 strokeColour="solid: ff000000" nonZeroWinding="1">s 544 72 l 0 72 x</PATH>
andrewm@0 272 <PATH pos="0 0 100 100" fill="solid: ffa52a94" hasStroke="1" stroke="0.5, mitered, butt"
andrewm@0 273 strokeColour="solid: ff000000" nonZeroWinding="1">s 119 16 l 119 56 x</PATH>
andrewm@0 274 </BACKGROUND>
andrewm@0 275 <TOGGLEBUTTON name="Bypass toggle button" id="cfe71c39a64f4704" memberName="bypassToggleButton"
andrewm@0 276 virtualName="" explicitFocusOrder="0" pos="24 44 72 24" buttonText="Bypass"
andrewm@0 277 connectedEdges="0" needsCallback="1" radioGroupId="0" state="0"/>
andrewm@0 278 <TEXTBUTTON name="Show details button" id="17ac5d15223ada90" memberName="showDetailsButton"
andrewm@0 279 virtualName="" explicitFocusOrder="0" pos="456 8 80 24" buttonText="Details..."
andrewm@0 280 connectedEdges="0" needsCallback="1" radioGroupId="0"/>
andrewm@0 281 <LABEL name="mapping type label" id="58b75e1d781dd4c6" memberName="mappingTypeLabel"
andrewm@0 282 virtualName="" explicitFocusOrder="0" pos="8 4 104 40" edTextCol="ff000000"
andrewm@0 283 edBkgCol="0" labelText="MappingType" editableSingleClick="0"
andrewm@0 284 editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
andrewm@0 285 fontsize="18" bold="0" italic="0" justification="36"/>
andrewm@0 286 <GENERICCOMPONENT name="mapping short editor component" id="8cbc2e53072fcaa7" memberName="mappingShortEditorComponent"
andrewm@0 287 virtualName="" explicitFocusOrder="0" pos="120 0 328 71" class="MappingEditorComponent"
andrewm@0 288 params=""/>
andrewm@0 289 <LABEL name="no settings label" id="a8fb2694ebf4280b" memberName="noSettingsLabel"
andrewm@0 290 virtualName="" explicitFocusOrder="0" pos="208 24 150 24" edTextCol="ff000000"
andrewm@0 291 edBkgCol="0" labelText="(no settings)" editableSingleClick="0"
andrewm@0 292 editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
andrewm@0 293 fontsize="15" bold="0" italic="0" justification="36"/>
andrewm@0 294 <TEXTBUTTON name="delete button" id="fced502f19d4fe5b" memberName="deleteButton"
andrewm@0 295 virtualName="" explicitFocusOrder="0" pos="456 44 80 20" buttonText="Delete..."
andrewm@0 296 connectedEdges="0" needsCallback="1" radioGroupId="0"/>
andrewm@0 297 </JUCER_COMPONENT>
andrewm@0 298
andrewm@0 299 END_JUCER_METADATA
andrewm@0 300 */
andrewm@0 301 #endif
andrewm@0 302
andrewm@0 303
andrewm@0 304 //[EndFile] You can add extra defines here...
andrewm@0 305 #endif // TOUCHKEYS_NO_GUI
andrewm@0 306 //[/EndFile]