File indexing completed on 2024-05-19 05:42:06
0001 // ct_lvtgclr_colormanagement.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef INCLUDED_CT_LVTCLR_COLORMANAGEMENT_H 0021 #define INCLUDED_CT_LVTCLR_COLORMANAGEMENT_H 0022 0023 #include <lvtclr_export.h> 0024 0025 #include <memory> 0026 0027 #include <QColor> 0028 #include <QObject> 0029 0030 namespace Codethink::lvtclr { 0031 0032 // ===================== 0033 // class ColorManagement 0034 // ===================== 0035 0036 class LVTCLR_EXPORT ColorManagement : public QObject 0037 // Class that helps managing the ColorSchemes for the visual graph 0038 { 0039 Q_OBJECT 0040 public: 0041 ColorManagement(bool doConnectSignals = true); 0042 // Constructor 0043 ~ColorManagement() override; 0044 // Destructor 0045 0046 // MANIPULATORS 0047 void setBaseColor(const QColor& color); 0048 // Sets the base color for the palette generation 0049 0050 void setColorFor(const std::string& id, const QColor& color); 0051 // Sets the color for a particular id 0052 0053 QColor getColorFor(const std::string& id); 0054 // Returns the stored color value for the id, or generates a new one if it does not exist. 0055 0056 Qt::BrushStyle fillPattern(const std::string& id); 0057 0058 Q_SIGNAL void requestNewColor(); 0059 // signals the nodes that they should request a new color. 0060 0061 Q_SLOT void colorBlindChanged(); 0062 // connected to the Settings, and triggered when the information about colorblindness changes. 0063 0064 protected: 0065 [[nodiscard]] virtual bool isColorBlindModeActive() const; 0066 [[nodiscard]] virtual bool isUsingColorBlindFill() const; 0067 0068 void resetCaches(); 0069 0070 private: 0071 [[nodiscard]] QColor generateUniqueColor(const std::string& id) const; 0072 [[nodiscard]] QColor generateColorblindColor() const; 0073 0074 struct Private; 0075 std::unique_ptr<Private> d; 0076 }; 0077 0078 } // end namespace Codethink::lvtclr 0079 0080 #endif