|
| 1 | +/** \ingroup gui |
| 2 | + * \class QgsColorWidget |
| 3 | + * A base class for interactive color widgets. Widgets can either allow setting a single component of |
| 4 | + * a color (eg the red or green components), or an entire color. The QgsColorWidget also keeps track of |
| 5 | + * any explicitely set hue for the color, so that this information is not lost when the widget is |
| 6 | + * set to a color with an ambiguous hue (eg black or white shades). |
| 7 | + * \note Added in version 2.5 |
| 8 | + */ |
| 9 | + |
| 10 | +class QgsColorWidget : QWidget |
| 11 | +{ |
| 12 | +%TypeHeaderCode |
| 13 | +#include <qgscolorwidgets.h> |
| 14 | +%End |
| 15 | + |
| 16 | + public: |
| 17 | + |
| 18 | + /*! Specifies the color component which the widget alters |
| 19 | + */ |
| 20 | + enum ColorComponent |
| 21 | + { |
| 22 | + Multiple = 0, /*!< widget alters multiple color components */ |
| 23 | + Red, /*!< red component of color */ |
| 24 | + Green, /*!< green component of color */ |
| 25 | + Blue, /*!< blue component of color */ |
| 26 | + Hue, /*!< hue component of color (based on HSV model) */ |
| 27 | + Saturation, /*!< saturation component of color (based on HSV model) */ |
| 28 | + Value, /*!< value component of color (based on HSV model) */ |
| 29 | + Alpha /*!< alpha component (opacity) of color */ |
| 30 | + }; |
| 31 | + |
| 32 | + /**Construct a new color widget. |
| 33 | + * @param parent parent QWidget for the widget |
| 34 | + * @param component color component the widget alters |
| 35 | + */ |
| 36 | + QgsColorWidget( QWidget* parent /TransferThis/ = 0, const ColorComponent component = Multiple ); |
| 37 | + |
| 38 | + virtual ~QgsColorWidget(); |
| 39 | + |
| 40 | + /**Returns the current color for the widget |
| 41 | + * @returns current widget color |
| 42 | + * @see setColor |
| 43 | + */ |
| 44 | + QColor color() const; |
| 45 | + |
| 46 | + /**Returns the color component which the widget controls |
| 47 | + * @returns color component for widget |
| 48 | + * @see setComponent |
| 49 | + */ |
| 50 | + ColorComponent component() const; |
| 51 | + |
| 52 | + /**Returns the current value of the widget's color component |
| 53 | + * @returns value of color component, or -1 if widget has multiple components or an invalid color |
| 54 | + * set |
| 55 | + * @see setComponentValue |
| 56 | + * @see component |
| 57 | + */ |
| 58 | + int componentValue() const; |
| 59 | + |
| 60 | + public slots: |
| 61 | + |
| 62 | + /**Sets the color for the widget |
| 63 | + * @param color widget color |
| 64 | + * @see color |
| 65 | + */ |
| 66 | + virtual void setColor( const QColor color ); |
| 67 | + |
| 68 | + /**Sets the color component which the widget controls |
| 69 | + * @param component color component for widget |
| 70 | + * @see component |
| 71 | + */ |
| 72 | + virtual void setComponent( const ColorComponent component ); |
| 73 | + |
| 74 | + /**Alters the widget's color by setting the value for the widget's color component |
| 75 | + * @param value value for widget's color component. This value is automatically |
| 76 | + * clipped to the range of valid values for the color component. |
| 77 | + * @see componentValue |
| 78 | + * @see setComponent |
| 79 | + * @note this method has no effect if the widget is set to the QgsColorWidget::Multiple |
| 80 | + * component |
| 81 | + */ |
| 82 | + virtual void setComponentValue( const int value ); |
| 83 | + |
| 84 | + signals: |
| 85 | + |
| 86 | + /**Emitted when the widget's color changes |
| 87 | + * @param color new widget color |
| 88 | + */ |
| 89 | + void colorChanged( const QColor color ); |
| 90 | + |
| 91 | + protected: |
| 92 | + |
| 93 | + /**Returns the range of valid values for the color widget's component |
| 94 | + * @returns maximum value allowed for color component, or -1 if widget has multiple components |
| 95 | + */ |
| 96 | + int componentRange() const; |
| 97 | + |
| 98 | + /**Returns the range of valid values a color component |
| 99 | + * @returns maximum value allowed for color component |
| 100 | + */ |
| 101 | + int componentRange( const ColorComponent component ) const; |
| 102 | + |
| 103 | + /**Returns the value of a component of the widget's current color. This method correctly |
| 104 | + * handles hue values when the color has an ambiguous hue (eg black or white shades) |
| 105 | + * @param component color component to return |
| 106 | + * @returns value of color component, or -1 if widget has an invalid color set |
| 107 | + * @see hue |
| 108 | + */ |
| 109 | + int componentValue( const ColorComponent component ) const; |
| 110 | + |
| 111 | + /**Returns the hue for the widget. This may differ from the hue for the QColor returned by color(), |
| 112 | + * as QColor returns a hue of -1 if the color's hue is ambiguous (eg, if the saturation is zero). |
| 113 | + * @returns explicitly set hue for widget |
| 114 | + */ |
| 115 | + int hue() const; |
| 116 | + |
| 117 | + /**Alters a color by modifiying the value of a specific color component |
| 118 | + * @param color color to alter |
| 119 | + * @param component color component to alter |
| 120 | + * @param newValue new value of color component. Values are automatically clipped to a |
| 121 | + * valid range for the color component. |
| 122 | + */ |
| 123 | + void alterColor( QColor& color, const QgsColorWidget::ColorComponent component, const int newValue ) const; |
| 124 | + |
| 125 | + /**Generates a checkboard pattern pixmap for use as a background to transparent colors |
| 126 | + * @returns checkerboard pixmap |
| 127 | + */ |
| 128 | + static const QPixmap& transparentBackground(); |
| 129 | + |
| 130 | +}; |
| 131 | + |
| 132 | + |
| 133 | +/** \ingroup gui |
| 134 | + * \class QgsColorWheel |
| 135 | + * A color wheel widget. This widget consists of an outer ring which allows for hue selection, and an |
| 136 | + * inner rotating triangle which allows for saturation and value selection. |
| 137 | + * \note Added in version 2.5 |
| 138 | + */ |
| 139 | + |
| 140 | +class QgsColorWheel : QgsColorWidget |
| 141 | +{ |
| 142 | +%TypeHeaderCode |
| 143 | +#include <qgscolorwidgets.h> |
| 144 | +%End |
| 145 | + |
| 146 | + public: |
| 147 | + |
| 148 | + /**Constructs a new color wheel widget. |
| 149 | + * @param parent parent QWidget for the widget |
| 150 | + */ |
| 151 | + QgsColorWheel( QWidget* parent /TransferThis/ = 0 ); |
| 152 | + |
| 153 | + virtual ~QgsColorWheel(); |
| 154 | + |
| 155 | + void paintEvent( QPaintEvent* event ); |
| 156 | + |
| 157 | + public slots: |
| 158 | + |
| 159 | + virtual void setColor( const QColor color ); |
| 160 | + |
| 161 | + protected: |
| 162 | + |
| 163 | + virtual void resizeEvent( QResizeEvent *event ); |
| 164 | + virtual void mouseMoveEvent( QMouseEvent *event ); |
| 165 | + virtual void mousePressEvent( QMouseEvent *event ); |
| 166 | + virtual void mouseReleaseEvent( QMouseEvent *event ); |
| 167 | + |
| 168 | +}; |
| 169 | + |
| 170 | + |
| 171 | +/** \ingroup gui |
| 172 | + * \class QgsColorBox |
| 173 | + * A color box widget. This widget consists of a two dimensional rectangle filled with color |
| 174 | + * variations, where a different color component varies along both the horizontal and vertical |
| 175 | + * axis. |
| 176 | + * \note Added in version 2.5 |
| 177 | + */ |
| 178 | + |
| 179 | +class QgsColorBox : QgsColorWidget |
| 180 | +{ |
| 181 | +%TypeHeaderCode |
| 182 | +#include <qgscolorwidgets.h> |
| 183 | +%End |
| 184 | + |
| 185 | + public: |
| 186 | + |
| 187 | + /**Construct a new color box widget. |
| 188 | + * @param parent parent QWidget for the widget |
| 189 | + * @param component constant color component for the widget. The color components |
| 190 | + * which vary along the horizontal and vertical axis are automatically assigned |
| 191 | + * based on this constant color component. |
| 192 | + */ |
| 193 | + QgsColorBox( QWidget* parent /TransferThis/ = 0, const ColorComponent component = Value ); |
| 194 | + |
| 195 | + virtual ~QgsColorBox(); |
| 196 | + |
| 197 | + virtual QSize sizeHint() const; |
| 198 | + void paintEvent( QPaintEvent* event ); |
| 199 | + |
| 200 | + virtual void setComponent( const ColorComponent component ); |
| 201 | + |
| 202 | + public slots: |
| 203 | + |
| 204 | + virtual void setColor( const QColor color ); |
| 205 | + |
| 206 | + protected: |
| 207 | + |
| 208 | + virtual void resizeEvent( QResizeEvent *event ); |
| 209 | + virtual void mouseMoveEvent( QMouseEvent *event ); |
| 210 | + virtual void mousePressEvent( QMouseEvent *event ); |
| 211 | +}; |
| 212 | + |
| 213 | + |
| 214 | +/** \ingroup gui |
| 215 | + * \class QgsColorRampWidget |
| 216 | + * A color ramp widget. This widget consists of an interactive box filled with a color which varies along |
| 217 | + * its length by a single color component (eg, varying saturation from 0 to 100%). |
| 218 | + * \note Added in version 2.5 |
| 219 | + */ |
| 220 | + |
| 221 | +class QgsColorRampWidget : QgsColorWidget |
| 222 | +{ |
| 223 | +%TypeHeaderCode |
| 224 | +#include <qgscolorwidgets.h> |
| 225 | +%End |
| 226 | + |
| 227 | + public: |
| 228 | + |
| 229 | + /*! Specifies the orientation of a color ramp |
| 230 | + */ |
| 231 | + enum Orientation |
| 232 | + { |
| 233 | + Horizontal, /*!< horizontal ramp */ |
| 234 | + Vertical /*!< vertical ramp */ |
| 235 | + }; |
| 236 | + |
| 237 | + /**Construct a new color ramp widget. |
| 238 | + * @param parent parent QWidget for the widget |
| 239 | + * @param component color component which varies along the ramp |
| 240 | + * @param orientation orientation for widget |
| 241 | + */ |
| 242 | + QgsColorRampWidget( QWidget* parent /TransferThis/ = 0, |
| 243 | + const ColorComponent component = QgsColorWidget::Red, |
| 244 | + const Orientation orientation = QgsColorRampWidget::Horizontal ); |
| 245 | + |
| 246 | + virtual ~QgsColorRampWidget(); |
| 247 | + |
| 248 | + virtual QSize sizeHint() const; |
| 249 | + void paintEvent( QPaintEvent* event ); |
| 250 | + |
| 251 | + /**Sets the orientation for the color ramp |
| 252 | + * @param orientation new orientation for the ramp |
| 253 | + * @see orientation |
| 254 | + */ |
| 255 | + void setOrientation( const Orientation orientation ); |
| 256 | + |
| 257 | + /**Fetches the orientation for the color ramp |
| 258 | + * @returns orientation for the ramp |
| 259 | + * @see setOrientation |
| 260 | + */ |
| 261 | + Orientation orientation() const; |
| 262 | + |
| 263 | + /**Sets the margin between the edge of the widget and the ramp |
| 264 | + * @param margin margin around the ramp |
| 265 | + * @see interiorMargin |
| 266 | + */ |
| 267 | + void setInteriorMargin( const int margin ); |
| 268 | + |
| 269 | + /**Fetches the margin between the edge of the widget and the ramp |
| 270 | + * @returns margin around the ramp |
| 271 | + * @see setInteriorMargin |
| 272 | + */ |
| 273 | + int interiorMargin() const; |
| 274 | + |
| 275 | + /**Sets whether the ramp should be drawn within a frame |
| 276 | + * @param showFrame set to true to draw a frame around the ramp |
| 277 | + * @see showFrame |
| 278 | + */ |
| 279 | + void setShowFrame( const bool showFrame ); |
| 280 | + |
| 281 | + /**Fetches whether the ramp is drawn within a frame |
| 282 | + * @returns true if a frame is drawn around the ramp |
| 283 | + * @see setShowFrame |
| 284 | + */ |
| 285 | + bool showFrame() const; |
| 286 | + |
| 287 | + /**Sets the size for drawing the triangular markers on the ramp |
| 288 | + * @param markerSize marker size in pixels |
| 289 | + */ |
| 290 | + void setMarkerSize( const int markerSize ); |
| 291 | + |
| 292 | + signals: |
| 293 | + |
| 294 | + /**Emitted when the widget's color component value changes |
| 295 | + * @param value new value of color component |
| 296 | + */ |
| 297 | + void valueChanged( const int value ); |
| 298 | + |
| 299 | + protected: |
| 300 | + |
| 301 | + virtual void mouseMoveEvent( QMouseEvent *event ); |
| 302 | + virtual void mousePressEvent( QMouseEvent *event ); |
| 303 | + virtual void keyPressEvent( QKeyEvent * event ); |
| 304 | +}; |
| 305 | + |
| 306 | + |
| 307 | +/** \ingroup gui |
| 308 | + * \class QgsColorSliderWidget |
| 309 | + * A composite horizontal color ramp widget and associated spinbox for manual value entry. |
| 310 | + * \note Added in version 2.5 |
| 311 | + */ |
| 312 | + |
| 313 | +class QgsColorSliderWidget : QgsColorWidget |
| 314 | +{ |
| 315 | +%TypeHeaderCode |
| 316 | +#include <qgscolorwidgets.h> |
| 317 | +%End |
| 318 | + |
| 319 | + public: |
| 320 | + |
| 321 | + /**Construct a new color slider widget. |
| 322 | + * @param parent parent QWidget for the widget |
| 323 | + * @param component color component which is controlled by the slider |
| 324 | + */ |
| 325 | + QgsColorSliderWidget( QWidget* parent /TransferThis/ = 0, const ColorComponent component = QgsColorWidget::Red ); |
| 326 | + |
| 327 | + virtual ~QgsColorSliderWidget(); |
| 328 | + |
| 329 | + virtual void setComponent( const ColorComponent component ); |
| 330 | + virtual void setComponentValue( const int value ); |
| 331 | + virtual void setColor( const QColor color ); |
| 332 | + |
| 333 | +}; |
| 334 | + |
| 335 | + |
| 336 | +/** \ingroup gui |
| 337 | + * \class QgsColorTextWidget |
| 338 | + * A line edit widget which displays colors as text and accepts string representations |
| 339 | + * of colors. |
| 340 | + * \note Added in version 2.5 |
| 341 | + */ |
| 342 | + |
| 343 | +class QgsColorTextWidget : QgsColorWidget |
| 344 | +{ |
| 345 | +%TypeHeaderCode |
| 346 | +#include <qgscolorwidgets.h> |
| 347 | +%End |
| 348 | + |
| 349 | + public: |
| 350 | + |
| 351 | + /**Construct a new color line edit widget. |
| 352 | + * @param parent parent QWidget for the widget |
| 353 | + */ |
| 354 | + QgsColorTextWidget( QWidget* parent /TransferThis/ = 0 ); |
| 355 | + |
| 356 | + virtual ~QgsColorTextWidget(); |
| 357 | + |
| 358 | + virtual void setColor( const QColor color ); |
| 359 | + |
| 360 | + protected: |
| 361 | + void resizeEvent( QResizeEvent * event ); |
| 362 | + |
| 363 | +}; |
| 364 | + |
| 365 | + |
| 366 | +/** \ingroup gui |
| 367 | + * \class QgsColorPreviewWidget |
| 368 | + * A preview box which displays one or two colors as swatches. |
| 369 | + * \note Added in version 2.5 |
| 370 | + */ |
| 371 | + |
| 372 | +class QgsColorPreviewWidget : QgsColorWidget |
| 373 | +{ |
| 374 | +%TypeHeaderCode |
| 375 | +#include <qgscolorwidgets.h> |
| 376 | +%End |
| 377 | + |
| 378 | + public: |
| 379 | + |
| 380 | + /**Construct a new color preview widget. |
| 381 | + * @param parent parent QWidget for the widget |
| 382 | + */ |
| 383 | + QgsColorPreviewWidget( QWidget* parent /TransferThis/ = 0 ); |
| 384 | + |
| 385 | + virtual ~QgsColorPreviewWidget(); |
| 386 | + |
| 387 | + void paintEvent( QPaintEvent* event ); |
| 388 | + |
| 389 | + /**Returns the secondary color for the widget |
| 390 | + * @returns secondary widget color, or an invalid color if the widget |
| 391 | + * has no secondary color |
| 392 | + * @see color |
| 393 | + * @see setColor2 |
| 394 | + */ |
| 395 | + QColor color2() const; |
| 396 | + |
| 397 | + public slots: |
| 398 | + |
| 399 | + /**Sets the second color for the widget |
| 400 | + * @param color secondary widget color. Set to an invalid color to prevent |
| 401 | + * drawing of a secondary color |
| 402 | + * @see setColor |
| 403 | + * @see color2 |
| 404 | + */ |
| 405 | + virtual void setColor2( const QColor& color ); |
| 406 | + |
| 407 | +}; |
0 commit comments