File indexing completed on 2024-05-19 04:45:53

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 #ifndef PERCEPTUALSETTINGS_H
0005 #define PERCEPTUALSETTINGS_H
0006 
0007 #include "setting.h"
0008 #include "settings.h"
0009 #include <qcolor.h>
0010 #include <qglobal.h>
0011 #include <qlist.h>
0012 #include <qmetatype.h>
0013 #include <qstring.h>
0014 
0015 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
0016 #include <qtmetamacros.h>
0017 #else
0018 #include <qobjectdefs.h>
0019 #endif
0020 
0021 namespace PerceptualColor
0022 {
0023 
0024 /** @internal
0025  *
0026  * @brief Settings for @ref PerceptualColor.
0027  *
0028  * @warning This object is not thread-safe.
0029  * It must only be used in the main (widget) thread! */
0030 class PerceptualSettings : public Settings
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     /** @brief Data type for color lists.
0036      *
0037      * Has serialization support as required by <tt>QSettings</tt>. */
0038     using ColorList = QList<QColor>;
0039 
0040     virtual ~PerceptualSettings() override;
0041     // Prevent copy and assignment operations to force that only references
0042     // to the instance are possible.
0043     PerceptualSettings(const PerceptualSettings &) = delete;
0044     PerceptualSettings &operator=(const PerceptualSettings &) = delete;
0045 
0046     static PerceptualSettings &instance();
0047 
0048     /** @brief Custom colors of @ref ColorDialog. */
0049     Setting<ColorList> customColors;
0050 
0051     /** @brief History of actually selected (confirmed by Okay button
0052      * respectively Enter key) colors of @ref ColorDialog. */
0053     Setting<ColorList> history;
0054 
0055     /** @brief The currently visible tab of @ref ColorDialog with
0056      * @ref ColorDialog::DialogLayoutDimensions::Collapsed. */
0057     Setting<QString> tab;
0058 
0059     /** @brief The currently visible tab of @ref ColorDialog with
0060      * @ref ColorDialog::DialogLayoutDimensions::Expanded. */
0061     Setting<QString> tabExpanded;
0062 
0063 private:
0064     PerceptualSettings();
0065 
0066     /** @internal @brief Only for unit tests. */
0067     friend class TestPerceptualSettings;
0068 };
0069 
0070 } // namespace PerceptualColor
0071 
0072 Q_DECLARE_METATYPE(PerceptualColor::PerceptualSettings::ColorList)
0073 
0074 #endif // PERCEPTUALSETTINGS_H