1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00
JUCE/modules/juce_gui_extra/misc/juce_KeyMappingEditorComponent.h
2024-04-16 11:39:35 +01:00

142 lines
5.8 KiB
C++

/*
==============================================================================
This file is part of the JUCE framework.
Copyright (c) Raw Material Software Limited
JUCE is an open source framework subject to commercial or open source
licensing.
By downloading, installing, or using the JUCE framework, or combining the
JUCE framework with any other source code, object code, content or any other
copyrightable work, you agree to the terms of the JUCE End User Licence
Agreement, and all incorporated terms including the JUCE Privacy Policy and
the JUCE Website Terms of Service, as applicable, which will bind you. If you
do not agree to the terms of these agreements, we will not license the JUCE
framework to you, and you must discontinue the installation or download
process and cease use of the JUCE framework.
JUCE End User Licence Agreement: https://juce.com/legal/juce-8-licence/
JUCE Privacy Policy: https://juce.com/juce-privacy-policy
JUCE Website Terms of Service: https://juce.com/juce-website-terms-of-service/
Or:
You may also use this code under the terms of the AGPLv3:
https://www.gnu.org/licenses/agpl-3.0.en.html
THE JUCE FRAMEWORK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL
WARRANTIES, WHETHER EXPRESSED OR IMPLIED, INCLUDING WARRANTY OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
/**
A component to allow editing of the keymaps stored by a KeyPressMappingSet
object.
@see KeyPressMappingSet
@tags{GUI}
*/
class JUCE_API KeyMappingEditorComponent : public Component
{
public:
//==============================================================================
/** Creates a KeyMappingEditorComponent.
@param mappingSet this is the set of mappings to display and edit. Make sure the
mappings object is not deleted before this component!
@param showResetToDefaultButton if true, then at the bottom of the list, the
component will include a 'reset to defaults' button.
*/
KeyMappingEditorComponent (KeyPressMappingSet& mappingSet,
bool showResetToDefaultButton);
/** Destructor. */
~KeyMappingEditorComponent() override;
//==============================================================================
/** Sets up the colours to use for parts of the component.
@param mainBackground colour to use for most of the background
@param textColour colour to use for the text
*/
void setColours (Colour mainBackground,
Colour textColour);
/** Returns the KeyPressMappingSet that this component is acting upon. */
KeyPressMappingSet& getMappings() const noexcept { return mappings; }
/** Returns the ApplicationCommandManager that this component is connected to. */
ApplicationCommandManager& getCommandManager() const noexcept { return mappings.getCommandManager(); }
//==============================================================================
/** Can be overridden if some commands need to be excluded from the list.
By default this will use the KeyPressMappingSet's shouldCommandBeVisibleInEditor()
method to decide what to return, but you can override it to handle special cases.
*/
virtual bool shouldCommandBeIncluded (CommandID commandID);
/** Can be overridden to indicate that some commands are shown as read-only.
By default this will use the KeyPressMappingSet's shouldCommandBeReadOnlyInEditor()
method to decide what to return, but you can override it to handle special cases.
*/
virtual bool isCommandReadOnly (CommandID commandID);
/** This can be overridden to let you change the format of the string used
to describe a keypress.
This is handy if you're using non-standard KeyPress objects, e.g. for custom
keys that are triggered by something else externally. If you override the
method, be sure to let the base class's method handle keys you're not
interested in.
*/
virtual String getDescriptionForKeyPress (const KeyPress& key);
//==============================================================================
/** A set of colour IDs to use to change the colour of various aspects of the editor.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
backgroundColourId = 0x100ad00, /**< The background colour to fill the editor background. */
textColourId = 0x100ad01, /**< The colour for the text. */
};
//==============================================================================
/** @internal */
void parentHierarchyChanged() override;
/** @internal */
void resized() override;
private:
//==============================================================================
KeyPressMappingSet& mappings;
TreeView tree;
TextButton resetButton;
class TopLevelItem;
class ChangeKeyButton;
class MappingItem;
class CategoryItem;
class ItemComponent;
std::unique_ptr<TopLevelItem> treeItem;
ScopedMessageBox messageBox;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (KeyMappingEditorComponent)
};
} // namespace juce