File indexing completed on 2025-01-19 03:51:07

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2005-02-14
0007  * Description : a widget to insert a text over an image.
0008  *
0009  * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_EDITOR_INSERT_TEXT_WIDGET_H
0017 #define DIGIKAM_EDITOR_INSERT_TEXT_WIDGET_H
0018 
0019 // Qt includes
0020 
0021 #include <QColor>
0022 #include <QFont>
0023 #include <QImage>
0024 #include <QMouseEvent>
0025 #include <QPaintEvent>
0026 #include <QPixmap>
0027 #include <QRect>
0028 #include <QResizeEvent>
0029 #include <QSize>
0030 #include <QString>
0031 #include <QWidget>
0032 #include <QUrl>
0033 
0034 // Local includes
0035 
0036 #include "dimg.h"
0037 #include "imageiface.h"
0038 
0039 using namespace Digikam;
0040 
0041 namespace DigikamEditorInsertTextToolPlugin
0042 {
0043 
0044 class InsertTextWidget : public QWidget
0045 {
0046     Q_OBJECT
0047 
0048 public:
0049 
0050     enum Action
0051     {
0052         ALIGN_LEFT = 0,
0053         ALIGN_RIGHT,
0054         ALIGN_CENTER,
0055         ALIGN_BLOCK,
0056         BORDER_TEXT,
0057         TRANSPARENT_TEXT
0058     };
0059 
0060     enum TextRotation
0061     {
0062         ROTATION_NONE = 0,
0063         ROTATION_90,
0064         ROTATION_180,
0065         ROTATION_270
0066     };
0067 
0068     enum BorderMode
0069     {
0070         BORDER_NONE = 0,
0071         BORDER_SUPPORT,
0072         BORDER_NORMAL
0073     };
0074 
0075 public:
0076 
0077     explicit InsertTextWidget(int w, int h, QWidget* const parent = nullptr);
0078     ~InsertTextWidget() override;
0079 
0080     ImageIface* imageIface() const;
0081     DImg        makeInsertText();
0082 
0083     /** Set background color for pixmap
0084      */
0085     void   setBackgroundColor(const QColor& bg);
0086 
0087     void   setText(const QString& text, const QFont& font, const QColor& color, int opacity,
0088                    int alignMode, bool border, bool transparent, int rotation);
0089 
0090     void   resetEdit();
0091 
0092     void  setPositionHint(const QRect& hint);
0093     QRect getPositionHint() const;
0094 
0095 protected:
0096 
0097     void paintEvent(QPaintEvent*)           override;
0098     void resizeEvent(QResizeEvent*)         override;
0099     void mousePressEvent(QMouseEvent*)      override;
0100     void mouseReleaseEvent(QMouseEvent*)    override;
0101     void mouseMoveEvent(QMouseEvent*)       override;
0102 
0103     void makePixmap();
0104     QRect composeImage(DImg* const image, QPainter* const destPainter,
0105                        int x, int y,
0106                        QFont font, float pointSize, int textRotation, QColor textColor,
0107                        int textOpacity, int alignMode, const QString& textString,
0108                        bool transparentBackground, QColor backgroundColor,
0109                        BorderMode borderMode, int borderWidth, int spacing, float fontScale = 1.0f);
0110 
0111 private:
0112 
0113     class Private;
0114     Private* const d;
0115 };
0116 
0117 } // namespace DigikamEditorInsertTextToolPlugin
0118 
0119 #endif // DIGIKAM_EDITOR_INSERT_TEXT_WIDGET_H