Public Member Functions

PreferencesPanel Class Reference

A component with a set of buttons at the top for changing between pages of preferences. More...

Inherits Component.

List of all members.

Public Member Functions

 PreferencesPanel ()
 Creates an empty panel.
 ~PreferencesPanel ()
 Destructor.
void addSettingsPage (const String &pageTitle, const Drawable *normalIcon, const Drawable *overIcon, const Drawable *downIcon)
 Creates a page using a set of drawables to define the page's icon.
void addSettingsPage (const String &pageTitle, const void *imageData, int imageDataSize)
 Creates a page using a set of drawables to define the page's icon.
void showInDialogBox (const String &dialogTitle, int dialogWidth, int dialogHeight, const Colour &backgroundColour=Colours::white)
 Utility method to display this panel in a DialogWindow.
virtual ComponentcreateComponentForPage (const String &pageName)=0
 Subclasses must override this to return a component for each preferences page.
void setCurrentPage (const String &pageName)
 Changes the current page being displayed.
int getButtonSize () const noexcept
 Returns the size of the buttons shown along the top.
void setButtonSize (int newSize)
 Changes the size of the buttons shown along the top.
void resized ()
 Called when this component's size has been changed.
void paint (Graphics &g)
 Components can override this method to draw their content.
void buttonClicked (Button *button)

Detailed Description

A component with a set of buttons at the top for changing between pages of preferences.

This is just a handy way of writing a Mac-style preferences panel where you have a row of buttons along the top for the different preference categories, each button having an icon above its name. Clicking these will show an appropriate prefs page below it.

You can either put one of these inside your own component, or just use the showInDialogBox() method to show it in a window and run it modally.

To use it, just add a set of named pages with the addSettingsPage() method, and implement the createComponentForPage() method to create suitable components for each of these pages.


Constructor & Destructor Documentation

PreferencesPanel::PreferencesPanel (  )

Creates an empty panel.

Use addSettingsPage() to add some pages to it in your constructor.

PreferencesPanel::~PreferencesPanel (  )

Destructor.


Member Function Documentation

void PreferencesPanel::addSettingsPage ( const String pageTitle,
const Drawable normalIcon,
const Drawable overIcon,
const Drawable downIcon 
)

Creates a page using a set of drawables to define the page's icon.

Note that the other version of this method is much easier if you're using an image instead of a custom drawable.

Parameters:
pageTitlethe name of this preferences page - you'll need to make sure your createComponentForPage() method creates a suitable component when it is passed this name
normalIconthe drawable to display in the page's button normally
overIconthe drawable to display in the page's button when the mouse is over
downIconthe drawable to display in the page's button when the button is down
See also:
DrawableButton
void PreferencesPanel::addSettingsPage ( const String pageTitle,
const void *  imageData,
int  imageDataSize 
)

Creates a page using a set of drawables to define the page's icon.

The other version of this method gives you more control over the icon, but this one is much easier if you're just loading it from a file.

Parameters:
pageTitlethe name of this preferences page - you'll need to make sure your createComponentForPage() method creates a suitable component when it is passed this name
imageDataa block of data containing an image file, e.g. a jpeg, png or gif. For this to look good, you'll probably want to use a nice transparent png file.
imageDataSizethe size of the image data, in bytes
void PreferencesPanel::showInDialogBox ( const String dialogTitle,
int  dialogWidth,
int  dialogHeight,
const Colour backgroundColour = Colours::white 
)

Utility method to display this panel in a DialogWindow.

Calling this will create a DialogWindow containing this panel with the given size and title, and will run it modally, returning when the user closes the dialog box.

virtual Component* PreferencesPanel::createComponentForPage ( const String pageName ) [pure virtual]

Subclasses must override this to return a component for each preferences page.

The subclass should return a pointer to a new component representing the named page, which the panel will then display.

The panel will delete the component later when the user goes to another page or deletes the panel.

void PreferencesPanel::setCurrentPage ( const String pageName )

Changes the current page being displayed.

int PreferencesPanel::getButtonSize (  ) const

Returns the size of the buttons shown along the top.

void PreferencesPanel::setButtonSize ( int  newSize )

Changes the size of the buttons shown along the top.

void PreferencesPanel::resized (  ) [virtual]

Called when this component's size has been changed.

A component can implement this method to do things such as laying out its child components when its width or height changes.

The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).

If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.

See also:
moved, setSize

Reimplemented from Component.

void PreferencesPanel::paint ( Graphics g ) [virtual]

Components can override this method to draw their content.

The paint() method gets called when a region of a component needs redrawing, either because the component's repaint() method has been called, or because something has happened on the screen that means a section of a window needs to be redrawn.

Any child components will draw themselves over whatever this method draws. If you need to paint over the top of your child components, you can also implement the paintOverChildren() method to do this.

If you want to cause a component to redraw itself, this is done asynchronously - calling the repaint() method marks a region of the component as "dirty", and the paint() method will automatically be called sometime later, by the message thread, to paint any bits that need refreshing. In Juce (and almost all modern UI frameworks), you never redraw something synchronously.

You should never need to call this method directly - to take a snapshot of the component you could use createComponentSnapshot() or paintEntireComponent().

Parameters:
gthe graphics context that must be used to do the drawing operations.
See also:
repaint, paintOverChildren, Graphics

Reimplemented from Component.

void PreferencesPanel::buttonClicked ( Button button )

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines