1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2005-02-14 7 * Description : a widget to insert a text over an image. 8 * 9 * Copyright (C) 2005-2021 by Gilles Caulier <caulier dot gilles at gmail dot com> 10 * Copyright (C) 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 11 * 12 * This program is free software; you can redistribute it 13 * and/or modify it under the terms of the GNU General 14 * Public License as published by the Free Software Foundation; 15 * either version 2, or (at your option) 16 * any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * ============================================================ */ 24 25 #ifndef DIGIKAM_EDITOR_INSERT_TEXT_WIDGET_H 26 #define DIGIKAM_EDITOR_INSERT_TEXT_WIDGET_H 27 28 // Qt includes 29 30 #include <QColor> 31 #include <QFont> 32 #include <QImage> 33 #include <QMouseEvent> 34 #include <QPaintEvent> 35 #include <QPixmap> 36 #include <QRect> 37 #include <QResizeEvent> 38 #include <QSize> 39 #include <QString> 40 #include <QWidget> 41 #include <QUrl> 42 43 // Local includes 44 45 #include "dimg.h" 46 #include "imageiface.h" 47 48 using namespace Digikam; 49 50 namespace DigikamEditorInsertTextToolPlugin 51 { 52 53 class InsertTextWidget : public QWidget 54 { 55 Q_OBJECT 56 57 public: 58 59 enum Action 60 { 61 ALIGN_LEFT = 0, 62 ALIGN_RIGHT, 63 ALIGN_CENTER, 64 ALIGN_BLOCK, 65 BORDER_TEXT, 66 TRANSPARENT_TEXT 67 }; 68 69 enum TextRotation 70 { 71 ROTATION_NONE = 0, 72 ROTATION_90, 73 ROTATION_180, 74 ROTATION_270 75 }; 76 77 enum BorderMode 78 { 79 BORDER_NONE = 0, 80 BORDER_SUPPORT, 81 BORDER_NORMAL 82 }; 83 84 public: 85 86 explicit InsertTextWidget(int w, int h, QWidget* const parent = nullptr); 87 ~InsertTextWidget() override; 88 89 ImageIface* imageIface() const; 90 DImg makeInsertText(); 91 92 /** Set background color for pixmap 93 */ 94 void setBackgroundColor(const QColor& bg); 95 96 void setText(const QString& text, const QFont& font, const QColor& color, int opacity, 97 int alignMode, bool border, bool transparent, int rotation); 98 99 void resetEdit(); 100 101 void setPositionHint(const QRect& hint); 102 QRect getPositionHint() const; 103 104 protected: 105 106 void paintEvent(QPaintEvent*) override; 107 void resizeEvent(QResizeEvent*) override; 108 void mousePressEvent(QMouseEvent*) override; 109 void mouseReleaseEvent(QMouseEvent*) override; 110 void mouseMoveEvent(QMouseEvent*) override; 111 112 void makePixmap(); 113 QRect composeImage(DImg* const image, QPainter* const destPainter, 114 int x, int y, 115 QFont font, float pointSize, int textRotation, QColor textColor, 116 int textOpacity, int alignMode, const QString& textString, 117 bool transparentBackground, QColor backgroundColor, 118 BorderMode borderMode, int borderWidth, int spacing, float fontScale = 1.0f); 119 120 private: 121 122 class Private; 123 Private* const d; 124 }; 125 126 } // namespace DigikamEditorInsertTextToolPlugin 127 128 #endif // DIGIKAM_EDITOR_INSERT_TEXT_WIDGET_H 129