KWWidgets
vtkKWColorSwatchesWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWColorSwatchesWidget.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWColorSwatchesWidget - a color swatches widget.
15 // .SECTION Description
16 // This class displays a list of color swatches.
17 // Different color swatches collections can be created independently.
18 // .SECTION See Also
19 // vtkKWColorPickerWidget
20 
21 #ifndef __vtkKWColorSwatchesWidget_h
22 #define __vtkKWColorSwatchesWidget_h
23 
24 #include "vtkKWCompositeWidget.h"
25 
26 class vtkKWColorSwatchesWidgetInternals;
27 class vtkKWFrameSet;
29 
31 {
32 public:
33  static vtkKWColorSwatchesWidget* New();
35  void PrintSelf(ostream& os, vtkIndent indent);
36 
37  // Description:
38  // Add a swatches collection (the name can not be empty)
39  // Return unique ID (>= 0) of the collection, or -1 on error.
40  virtual int AddCollection(const char *name);
41 
42  // Description:
43  // Remove a swatches collection given its ID, or all collections
44  // Return 1 on success, 0 otherwise
45  virtual int RemoveCollection(int collection_id);
46  virtual void RemoveAllCollections();
47 
48  // Description:
49  // Get the unique ID of a swatches collection given its name
50  // Return -1 on error.
51  virtual int GetCollectionId(const char *name);
52 
53  // Description:
54  // Add a swatch to a collection, given the unique ID of the collection,
55  // the name of the swatch (can be empty) and its RGB value.
56  // Return 1 on success, 0 on error.
57  virtual int AddRGBSwatch(
58  int collection_id, const char *name, double rgb[3]);
59  virtual int AddRGBSwatch(
60  int collection_id, const char *name, double r, double g, double b);
61 
62  // Description:
63  // Set/Get the swatches representation.
64  //BTX
65  enum
66  {
67  RepresentationFrames = 0,
68  RepresentationList = 1
69  };
70  //ETX
71  virtual void SetSwatchesRepresentation(int);
72  vtkGetMacro(SwatchesRepresentation, int);
73  virtual void SetSwatchesRepresentationToFrames();
74  virtual void SetSwatchesRepresentationToList();
75 
76  // Description:
77  // Set/Get the swatch size in pixels.
78  // Only relevant if SwatchesRepresentation is RepresentationFrames.
79  vtkGetMacro(SwatchSize, int);
80  virtual void SetSwatchSize(int);
81 
82  // Description:
83  // Set/Get the maximum number of swatches packed horizontally (per row).
84  // Only relevant if SwatchesRepresentation is RepresentationFrames.
85  virtual void SetMaximumNumberOfSwatchesPerRow(int);
86  virtual int GetMaximumNumberOfSwatchesPerRow();
87 
88  // Description:
89  // Set/Get the padding between each swatch.
90  // Only relevant if SwatchesRepresentation is RepresentationFrames.
91  virtual void SetSwatchesPadding(int);
92  virtual int GetSwatchesPadding();
93 
94  // Description:
95  // Get the internal color swatches preset list
96  virtual vtkKWColorPresetSelector* GetSwatchesColorPresetSelector();
97 
98  // Description:
99  // Create the default collections
100  virtual void AddDefaultCollections();
101 
102  // Description:
103  // Specifies a command to associate with the widget. This command is
104  // invoked when a swatch is selected.
105  // The 'object' argument is the object that will have the method called on
106  // it. The 'method' argument is the name of the method to be called and any
107  // arguments in string form. If the object is NULL, the method is still
108  // evaluated as a simple command.
109  // The following parameters are also passed to the command:
110  // - swatch rgb value: double r, double g, double b
111  virtual void SetSwatchSelectedCommand(vtkObject *object, const char *method);
112 
113  // Description:
114  // Callbacks. Internal, do not use.
115  virtual void SwatchSelectedCallback(double r, double g, double b);
116  virtual void CollectionSelectedCallback(const char*);
117  virtual void PopulateCollectionsCallback();
118  virtual void PopulateSwatchesCallback();
119  virtual void SwatchesColorPresetApplyCallback(int id);
120 
121  // Description:
122  // Update the "enable" state of the object and its internal parts.
123  // Depending on different Ivars (this->Enabled, the application's
124  // Limited Edition Mode, etc.), the "enable" state of the object is updated
125  // and propagated to its internal parts/subwidgets. This will, for example,
126  // enable/disable parts of the widget UI, enable/disable the visibility
127  // of 3D widgets, etc.
128  virtual void UpdateEnableState();
129 
130 protected:
133 
134  // Description:
135  // Create the widget.
136  virtual void CreateWidget();
137 
138  // Description:
139  // Callbacks. Internal, do not use.
140  char *SwatchSelectedCommand;
141  virtual void InvokeSwatchSelectedCommand(double r, double g, double b);
142 
143  // Description:
144  // Populate the swatches frame and collectio combo
145  virtual void PopulateCollections();
146  virtual void PopulateSwatches();
147  virtual void PopulateSwatchesAsFrames();
148  virtual void PopulateSwatchesAsList();
149  virtual void SchedulePopulateCollections();
150  virtual void SchedulePopulateSwatches();
151 
152  // Description:
153  // Pack
154  virtual void Pack();
155 
156  int SwatchSize;
157  int SwatchesRepresentation;
158  vtkKWColorSwatchesWidgetInternals *Internals;
159 
160 private:
161  vtkKWColorSwatchesWidget(const vtkKWColorSwatchesWidget&); // Not implemented
162  void operator=(const vtkKWColorSwatchesWidget&); // Not Implemented
163 };
164 
165 #endif
166