NDEVR
API Documentation
QTImageEditor.h
1#include "DLLInfo.h"
2#include <NDEVR/Buffer.h>
3#include <NDEVR/String.h>
4#include <NDEVR/Time.h>
5#include <NDEVR/TranslatedString.h>
6#include <QWidget>
7#pragma once
8namespace Ui
9{
10 class QTImageEditorUI;
11}
12namespace NDEVR
13{
14 class Button;
16 class QCustomSlider;
17 class QCustomLineEdit;
18 class QCustomComboBox;
19 class QCustomTextEdit;
24 class DESIGN_WIDGETS_API QTImageEditorView : public QWidget
25 {
26 Q_OBJECT
27 public:
31 enum class ResizeMode
32 {
34 , e_top_left
35 , e_stretch
36 };
37
40 enum class EditMode
41 {
42 e_freehand
43 , e_draw_line
44 , e_draw_rect
45 , e_draw_circle
46 //, e_draw_polygon
47 //, e_draw_curve
48 , e_erase
49 , e_draw_text
50 , e_crop
52 };
53
57 QTImageEditorView(QWidget* parent = nullptr);
62 void setPenColor(const QColor& color);
67 void setPenWidth(fltp08 width);
72 void setFillColor(const QColor& color) { m_fill_color = color; };
77 bool isModified() const { return modified; }
82 QColor penColor() const { return m_pen_color; }
87 int penWidth() const { return m_pen_width; }
92 void setImage(QImage image);
97 QImage image() const { return m_image; }
104 void resizeImage(const QSize& new_size, ResizeMode resize_mode, bool lock_aspect_ratio);
109 void setEditMode(EditMode edit_mode);
119 fltp08 scale() const { return m_scale; }
124 QSize sizeHint() const override;
129 QImage undoImage() const { return m_undo_image; };
134 void setFont(const QFont& font);
143 void mousePressLocation(QPointF end_point);
148 void mouseReleaseLocation(QPointF end_point);
153 void updateCursorLocation(QPointF end_point);
158 bool isEditing() const;
167 EditMode editMode() const { return m_edit_mode; };
168 public slots:
177 signals:
182 protected:
186 void drawText();
191 void mousePressEvent(QMouseEvent* event) override;
196 void mouseMoveEvent(QMouseEvent* event) override;
201 void mouseReleaseEvent(QMouseEvent* event) override;
206 void paintEvent(QPaintEvent* event) override;
211 void resizeEvent(QResizeEvent* event) override;
212 private:
216 void paintBackgroundImage();
224 void resizeImage(QImage* image, QSize new_size, ResizeMode resize_mode, bool lock_aspect_ratio);
225 private:
226 bool modified = false;
227 bool m_editing = false;
228 QCustomTextEdit* m_draw_text;
229 fltp08 m_pen_width = 1.0;
230 fltp08 m_scale = 1.0;
231 QColor m_pen_color = QColor(0, 0, 0);
232 QColor m_fill_color = QColor(0, 0, 0, 0);
233 QImage m_image;
234 QImage m_undo_image;
235 QImage m_background_image;
236 QPointF m_last_point;
237 Buffer<QPointF> m_last_scaled_points;
238 EditMode m_edit_mode;
239 };
240
243 class DESIGN_WIDGETS_API QTImageEditor : public QWidget
244 {
245 Q_OBJECT
246 public:
251 QTImageEditor(QWidget* parent = nullptr);
255 virtual ~QTImageEditor();
261 void setImage(const TranslatedString title, const StringView& image);
266 void refreshToImage(const StringView& image);
271 QSize sizeHint() const override;
276 QSize minimumSizeHint() const override;
285 void setVertical(bool vertical);
290 void showEvent(QShowEvent* event) override;
295 virtual void keyReleaseEvent(QKeyEvent* event) override;
300 void mousePressLocation(const Vector<2, fltp08>& end_point);
320 const StringView imageID() const { return m_resource; }
325 bool isEditing() const;
335 protected slots:
348 signals:
353 private:
357 void updateValues();
361 void updateScale();
365 void init();
369 void undo();
373 void redo();
378 void rotate(bool rotate_right);
383 void mirror(bool mirror_vert);
388 QImage pushToUndoStack();
389 private:
390 TranslatedString m_title;
391 Time m_image_update_time;
392 ImageEditApplicationManager* m_image_application_manager;
393 String m_resource;
395 Ui::QTImageEditorUI* ui;
396 Buffer<QImage> m_undo_stack;
397 Buffer<QImage> m_redo_stack;
398 QTimer* m_update_check_timer;
399 };
400}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core widget that allows the user to click one of many button types.
Definition Button.h:68
A button that pops up a ColorChooserDialog and changes background color based on the color chosen.
Finds any acceptable Image editors (MS Paint, GIMP Photoshop, etc) and allows them to be used as edit...
A compact way to present a list of options to the user.
A line edit allows users to enter and edit a single line of plain text with useful editing functions,...
The slider is the classic widget for controlling a bounded value.
A widget that is used to edit and display both plain and rich text in a multi-lined format.
A widget that provides a canvas for viewing and editing images with drawing tools.
bool isEditing() const
Returns whether a drawing or text editing operation is currently in progress.
void setFont(const QFont &font)
Sets the font used for text drawing mode.
void finishText()
Finishes and commits the current text editing operation.
void mouseMoveEvent(QMouseEvent *event) override
Handles mouse move events for drawing.
void clearSelection()
Clears the current selection or crop region.
void setImage(QImage image)
Sets the image to be displayed and edited.
bool isModified() const
Returns whether the image has been modified since the last save.
void drawText()
Renders text onto the image from the active text edit widget.
void editedSignal()
Emitted when the image has been edited.
void resizeImage(const QSize &new_size, ResizeMode resize_mode, bool lock_aspect_ratio)
Resizes the image to the given size using the specified mode.
QColor penColor() const
Returns the current pen color.
void resizeEvent(QResizeEvent *event) override
Handles resize events to update the background image.
QTImageEditorView(QWidget *parent=nullptr)
Constructs a QTImageEditorView widget.
void paintEvent(QPaintEvent *event) override
Paints the editor view including the image and any active drawing overlays.
void setScale(fltp08 scale)
Sets the display scale factor for the image.
void mouseReleaseEvent(QMouseEvent *event) override
Handles mouse release events for drawing.
ResizeMode
Describes how an image is positioned when resized.
void mousePressEvent(QMouseEvent *event) override
Handles mouse press events for drawing.
void checkTextEdit()
Checks if the text edit widget needs to be committed or dismissed.
void setEditMode(EditMode edit_mode)
Sets the active editing mode (drawing tool).
EditMode editMode() const
Returns the current edit mode.
int penWidth() const
Returns the current pen width.
void setPenWidth(fltp08 width)
Sets the pen width used for drawing operations.
QImage undoImage() const
Returns the image state before the last edit, for undo purposes.
QSize sizeHint() const override
Returns the recommended size for this widget.
void setFillColor(const QColor &color)
Sets the fill color used for shape drawing operations.
EditMode
The active drawing or editing tool for the image editor.
@ e_size
Sentinel value representing the number of edit modes.
void clearImage()
Clears the image to a blank state.
void setPenColor(const QColor &color)
Sets the pen color used for drawing operations.
fltp08 scale() const
Returns the current display scale factor.
void mousePressLocation(QPointF end_point)
Handles a mouse press at the given image-space location.
QImage image() const
Returns the current image being edited.
void updateCursorLocation(QPointF end_point)
Updates the cursor position during a drag operation.
void mouseReleaseLocation(QPointF end_point)
Handles a mouse release at the given image-space location.
void setOptimalScale()
Calculates and applies the optimal scale to fit the image in the view.
QTImageEditor(QWidget *parent=nullptr)
Constructs a QTImageEditor widget.
QSize sizeHint() const override
Returns the recommended size for this widget.
void colorsEdited()
Slot called when pen or fill colors have been changed by the user.
bool isEditing() const
Returns whether a drawing or text editing operation is currently in progress.
void mouseReleaseLocation(const Vector< 2, fltp08 > &end_point)
Handles a mouse release at the given normalized location.
const StringView imageID() const
Returns the resource identifier of the currently loaded image.
void setImage(const TranslatedString title, const StringView &image)
Sets the image to edit from a resource identifier.
void sizeChangedSlot()
Slot called when the image size has changed.
virtual void keyReleaseEvent(QKeyEvent *event) override
Handles key release events for shortcuts such as undo and redo.
QTImageEditorView * imageView() const
Returns the underlying image editor view widget.
void editedSignal()
Emitted when the image has been edited.
void showEvent(QShowEvent *event) override
Handles the show event to initialize the editor view.
void pushUpdate()
Pushes the current image state as a saved update to the resource system.
void editedSlot()
Slot called when the image has been edited, to update undo state.
QSize minimumSizeHint() const override
Returns the minimum recommended size for this widget.
void setEditMode(QTImageEditorView::EditMode mode)
Sets the active editing mode for the image editor view.
virtual ~QTImageEditor()
Destroys this QTImageEditor widget.
void refreshToImage(const StringView &image)
Reloads the image from the given resource identifier, discarding unsaved changes.
void setVertical(bool vertical)
Sets the layout orientation of the editor toolbar.
void mousePressLocation(const Vector< 2, fltp08 > &end_point)
Handles a mouse press at the given normalized location.
void updateCursorLocation(const Vector< 2, fltp08 > &end_point)
Updates the cursor position during a drag operation.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:62
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
@ e_center
Center text both horizontally and vertically.
Definition Font.h:327
double fltp08
Defines an alias representing an 8 byte floating-point number.
@ e_size
Number of entries in this enum; used for iteration.
Definition GPSPoint.h:26
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408