File indexing completed on 2024-05-12 03:48:19

0001 /*
0002     File                 : Background.h
0003     Project              : LabPlot
0004     Description          : Background
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2022 Alexander Semke <alexander.semke@web.de>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef BACKGROUND_H
0011 #define BACKGROUND_H
0012 
0013 #include "backend/core/AbstractAspect.h"
0014 #include "backend/lib/macros.h"
0015 
0016 class BackgroundPrivate;
0017 class KConfigGroup;
0018 
0019 class Background : public AbstractAspect {
0020     Q_OBJECT
0021 
0022 public:
0023     enum class Position { No, Above, Below, ZeroBaseline, Left, Right };
0024     enum class Type { Color, Image, Pattern };
0025     enum class ColorStyle {
0026         SingleColor,
0027         HorizontalLinearGradient,
0028         VerticalLinearGradient,
0029         TopLeftDiagonalLinearGradient,
0030         BottomLeftDiagonalLinearGradient,
0031         RadialGradient
0032     };
0033     enum class ImageStyle { ScaledCropped, Scaled, ScaledAspectRatio, Centered, Tiled, CenterTiled };
0034 
0035     explicit Background(const QString& name);
0036     ~Background() override;
0037 
0038     void setPrefix(const QString&);
0039     const QString& prefix() const;
0040     void init(const KConfigGroup&);
0041 
0042     void save(QXmlStreamWriter*) const override;
0043     bool load(XmlStreamReader*, bool preview) override;
0044     void loadThemeConfig(const KConfigGroup&);
0045     void loadThemeConfig(const KConfigGroup&, const QColor&);
0046     void saveThemeConfig(KConfigGroup&) const;
0047 
0048     BASIC_D_ACCESSOR_DECL(bool, enabledAvailable, EnabledAvailable)
0049     BASIC_D_ACCESSOR_DECL(bool, positionAvailable, PositionAvailable)
0050 
0051     BASIC_D_ACCESSOR_DECL(bool, enabled, Enabled)
0052     BASIC_D_ACCESSOR_DECL(Position, position, Position)
0053     BASIC_D_ACCESSOR_DECL(Type, type, Type)
0054     BASIC_D_ACCESSOR_DECL(ColorStyle, colorStyle, ColorStyle)
0055     BASIC_D_ACCESSOR_DECL(ImageStyle, imageStyle, ImageStyle)
0056     BASIC_D_ACCESSOR_DECL(Qt::BrushStyle, brushStyle, BrushStyle)
0057     CLASS_D_ACCESSOR_DECL(QColor, firstColor, FirstColor)
0058     CLASS_D_ACCESSOR_DECL(QColor, secondColor, SecondColor)
0059     CLASS_D_ACCESSOR_DECL(QString, fileName, FileName)
0060     BASIC_D_ACCESSOR_DECL(double, opacity, Opacity)
0061 
0062     typedef BackgroundPrivate Private;
0063 
0064 protected:
0065     BackgroundPrivate* const d_ptr;
0066 
0067 private:
0068     Q_DECLARE_PRIVATE(Background)
0069 
0070 Q_SIGNALS:
0071     void enabledChanged(bool);
0072     void positionChanged(Position);
0073     void typeChanged(Type);
0074     void colorStyleChanged(ColorStyle);
0075     void imageStyleChanged(ImageStyle);
0076     void brushStyleChanged(Qt::BrushStyle);
0077     void firstColorChanged(const QColor&);
0078     void secondColorChanged(const QColor&);
0079     void fileNameChanged(const QString&);
0080     void opacityChanged(float);
0081 
0082     void updatePositionRequested();
0083     void updateRequested();
0084 };
0085 
0086 #endif