File indexing completed on 2024-05-12 04:44:36
0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com> 0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT 0003 0004 #ifndef SWATCHBOOK_P_H 0005 #define SWATCHBOOK_P_H 0006 0007 // Include the header of the public class of this private implementation. 0008 // #include "swatchbook.h" 0009 0010 #include "constpropagatingrawpointer.h" 0011 #include "helper.h" 0012 #include "helperqttypes.h" 0013 #include <qcolor.h> 0014 #include <qglobal.h> 0015 #include <qnamespace.h> 0016 #include <qobject.h> 0017 #include <qpoint.h> 0018 #include <qsharedpointer.h> 0019 #include <qsize.h> 0020 #include <qstring.h> 0021 #include <qstyleoption.h> 0022 0023 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0024 #include <qtmetamacros.h> 0025 #else 0026 #include <qobjectdefs.h> 0027 #endif 0028 0029 namespace PerceptualColor 0030 { 0031 class SwatchBook; 0032 class RgbColorSpace; 0033 0034 /** @internal 0035 * 0036 * @brief Private implementation within the <em>Pointer to 0037 * implementation</em> idiom */ 0038 class SwatchBookPrivate final : public QObject 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 explicit SwatchBookPrivate(SwatchBook *backLink, const Array2D<QColor> &swatches, Qt::Orientations wideSpacing); 0044 /** @brief Default destructor 0045 * 0046 * The destructor is non-<tt>virtual</tt> because 0047 * the class as a whole is <tt>final</tt>. */ 0048 ~SwatchBookPrivate() noexcept override = default; 0049 0050 [[nodiscard]] QSize colorPatchesSizeWithMargin() const; 0051 [[nodiscard]] int horizontalPatchSpacing() const; 0052 void initStyleOption(QStyleOptionFrame *option) const; 0053 [[nodiscard]] int normalPatchSpacing() const; 0054 [[nodiscard]] QPoint offset(const QStyleOptionFrame &styleOptionFrame) const; 0055 [[nodiscard]] QSize patchSizeInner() const; 0056 [[nodiscard]] QSize patchSizeOuter() const; 0057 void retranslateUi(); 0058 void selectSwatch(QListSizeType newCurrentColomn, QListSizeType newCurrentRow); 0059 [[nodiscard]] int verticalPatchSpacing() const; 0060 [[nodiscard]] int widePatchSpacing() const; 0061 0062 /** @brief Internal storage for property @ref SwatchBook::currentColor 0063 * 0064 * QColor automatically initializes with an invalid color, just like it 0065 * should be for the property @ref SwatchBook::currentColor, so no 0066 * need to initialize here explicitly. */ 0067 QColor m_currentColor; 0068 /** @brief Pointer to the RgbColorSpace object. */ 0069 QSharedPointer<PerceptualColor::RgbColorSpace> m_rgbColorSpace; 0070 /** @brief Selected column. 0071 * 0072 * If one of the swatches in the book is selected, this is 0073 * the index of the column. 0074 * Otherwise, its <tt>-1</tt>. */ 0075 QListSizeType m_selectedColumn = -1; 0076 /** @brief Selected row. 0077 * 0078 * If one of the swatches in the book is selected, this is 0079 * the index of the row. 0080 * Otherwise, its <tt>-1</tt>. */ 0081 QListSizeType m_selectedRow = -1; 0082 /** @brief The selection mark to use, or an empty string if no 0083 * selection mark is available. 0084 * 0085 * The selection mark is drawn above the patch that is currently selected. 0086 * 0087 * This variable contains the localized selection mark string (if all its 0088 * characters are) available in the default font of this widget. An 0089 * empty string otherwise. 0090 * 0091 * The value is set by @ref retranslateUi(). */ 0092 QString m_selectionMark; 0093 /** @brief The colors of the swatches. 0094 * 0095 * This is a two-dimensional array. At the first level the 0096 * basic color (red, green…). At the second level, a particular 0097 * tint/shade of this basic color. 0098 * 0099 * @sa @ref m_selectedColumn 0100 * @sa @ref m_selectedRow */ 0101 const Array2D<QColor> m_swatches; 0102 /** @brief List of axis where @ref widePatchSpacing should be used. */ 0103 const Qt::Orientations m_wideSpacing; 0104 0105 private: 0106 Q_DISABLE_COPY(SwatchBookPrivate) 0107 0108 /** @brief Pointer to the object from which <em>this</em> object 0109 * is the private implementation. */ 0110 ConstPropagatingRawPointer<SwatchBook> q_pointer; 0111 }; 0112 0113 } // namespace PerceptualColor 0114 0115 #endif // SWATCHBOOK_P_H