File indexing completed on 2024-05-12 03:50:09

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0006 //
0007 
0008 
0009 #ifndef MARBLE_GEODATACOLORSTYLE_H
0010 #define MARBLE_GEODATACOLORSTYLE_H
0011 
0012 #include "GeoDataObject.h"
0013 
0014 #include "geodata_export.h"
0015 
0016 class QColor;
0017 
0018 namespace Marble
0019 {
0020 
0021 class GeoDataColorStylePrivate;
0022 
0023 /**
0024  * @short  an abstract base class for various style classes
0025  *
0026  * A GeoDataColorStyle is an abstract class that is the base class for
0027  * a number of different style classes. It provides settings for
0028  * specifying the color and color mode of the extended style classes.
0029  * A GeoDataColorStyle should never be instantiated directly.
0030  *
0031  * The color contains RGBA, (Red, Green, Blue, Alpha).  Color and
0032  * opacity (alpha) values have a range of 0 to 255 (00 to ff). For
0033  * alpha, 00 is fully transparent and ff is fully opaque.  For
0034  * example, if you want to apply a blue color with 50 percent opacity
0035  * to an overlay, you would specify the following:
0036  * 7fff0000, where alpha=0x7f, blue=0xff, green=0x00,
0037  * and red=0x00.
0038  *
0039  * The color mode can either be <b>normal</b> (no effect) or
0040  * <b>random</b>. A value of <b>random</b> applies a random linear scale to
0041  * the base color as follows.
0042  *
0043  * To achieve a truly random selection of colors, specify a base color
0044  * of white (ffffffff). If you specify a single color component (for
0045  * example, a value of ff0000ff for red), random color values for that
0046  * one component (red) will be selected. In this case, the values
0047  * would range from 00 (black) to ff (full red).  If you specify
0048  * values for two or for all three color components, a random linear
0049  * scale is applied to each color component, with results ranging from
0050  * black to the maximum values specified for each component.  The
0051  * opacity of a color comes from the alpha component of color and is
0052  * never randomized.
0053  *
0054  * @see GeoDataIconStyle
0055  * @see GeoDataLabelStyle
0056  * @see GeoDataLineStyle
0057  */
0058 class GEODATA_EXPORT GeoDataColorStyle : public GeoDataObject
0059 {
0060   public:
0061     /// Provides type information for downcasting a GeoData
0062     const char* nodeType() const override;
0063 
0064     /**
0065      * @brief  Set a new color
0066      * @param  value  the new color value
0067      */
0068     void setColor( const QColor &value );
0069     /// Return the color component
0070     QColor color() const;
0071 
0072     /// The color mode
0073     enum ColorMode { Normal, Random };
0074 
0075     /**
0076       * @brief Returns the color that should be painted: Either color() or a randomized
0077       * version of it, depending on the colorMode() setting. Randomization happens once
0078       * per setColor() call, i.e. repeated calls to paintedColor always return the same
0079       * color unless setColor is called in between.
0080       */
0081     QColor paintedColor() const;
0082 
0083     /**
0084      * @brief  Set a new color mode
0085      * @param  colorMode  the new color mode value
0086      */
0087     void setColorMode(ColorMode colorMode);
0088     /// Return the color mode
0089     ColorMode colorMode() const;
0090 
0091 
0092     /**
0093     * assignment operator
0094     * @param other the other colorstyle
0095     */
0096     GeoDataColorStyle& operator=( const GeoDataColorStyle& other );
0097     bool operator==( const GeoDataColorStyle &other ) const;
0098     bool operator!=( const GeoDataColorStyle &other ) const;
0099 
0100     /**
0101      * @brief Serialize the style to a stream
0102      * @param  stream  the stream
0103      */
0104     void pack( QDataStream& stream ) const override;
0105     /**
0106      * @brief  Unserialize the style from a stream
0107      * @param  stream  the stream
0108      */
0109     void unpack( QDataStream& stream ) override;
0110 
0111     GeoDataColorStyle();
0112     GeoDataColorStyle( const GeoDataColorStyle& other );
0113 
0114     ~GeoDataColorStyle() override;
0115 
0116     /**
0117      * @return Returns a foreground color suitable for e.g. text display on top of the given background color
0118      */
0119     static QString contrastColor(const QColor &color);
0120 
0121   private:
0122     GeoDataColorStylePrivate * const d;
0123 };
0124 
0125 }
0126 
0127 #endif