annotate Source/GUI/MappingListItem.cpp @ 16:61e3c9df4674

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