Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+108
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* @RDE_HEADER@
|
||||
* graphicsview widget to resize qpixmaps/qimages with mouse drag and mwheel
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Jens Heilmann, SLTE, 2020-10-14
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lts_widgets_export.h"
|
||||
#include <QGraphicsView>
|
||||
|
||||
namespace LtsWidgets
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The ImageCropper class provides a graphicsview widget to crop images with mouse drag and mwheel scroll.
|
||||
* avatar() returns a pixmap of the current view (the cropped image).
|
||||
*/
|
||||
class LTSWIDGETS_EXPORT LtsImageCropper : public QGraphicsView
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QPixmap pixMap READ pixmap WRITE setPixmap)
|
||||
Q_PROPERTY(double multiplier READ multiplier WRITE setMultiplier)
|
||||
Q_PROPERTY(double maxZoom READ maxZoom WRITE setMaxZoom)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief ImageCropper
|
||||
* @param parent
|
||||
* @param size specifies the size of the graphicsview widget, aswell as the size of the cropped image.
|
||||
* @param image to crop
|
||||
*/
|
||||
LtsImageCropper(QWidget *parent = nullptr, const QSize &size = {} , const QPixmap &pixmap = {});
|
||||
~LtsImageCropper();
|
||||
|
||||
/**
|
||||
* @brief setter for image
|
||||
* @param image
|
||||
*/
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
|
||||
/**
|
||||
* @brief setter for image
|
||||
* @param image
|
||||
*/
|
||||
void setImage(const QImage &image);
|
||||
|
||||
/**
|
||||
* @brief set the zoom mutliplier for mwheel scaling e.g. 1.03.
|
||||
* @param multiplier
|
||||
*/
|
||||
void setMultiplier(double multiplier);
|
||||
|
||||
/**
|
||||
* @brief set the maximum zoom in scale e.g. 2.0 = 200% zoom in.
|
||||
* @param maxZoom
|
||||
*/
|
||||
void setMaxZoom(double maxZoom) { m_maxScale = maxZoom; }
|
||||
|
||||
/**
|
||||
* @brief returns the current graphicsview view as a pixmap.
|
||||
* @return qpixmap
|
||||
*/
|
||||
QPixmap pixmap() { return grab(); }
|
||||
|
||||
/**
|
||||
* @brief returns the current graphicsview view as qimage.
|
||||
* @return qimage
|
||||
*/
|
||||
QImage image();
|
||||
|
||||
/**
|
||||
* @brief returns the current multiplier
|
||||
* @return double
|
||||
*/
|
||||
double multiplier() const { return m_multiplier; }
|
||||
|
||||
/**
|
||||
* @brief returns the current max zoom value
|
||||
* @return double
|
||||
*/
|
||||
double maxZoom() const { return m_maxScale; }
|
||||
|
||||
private:
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
QGraphicsPixmapItem *m_pixmapItem = nullptr;
|
||||
|
||||
double m_currentZoom;
|
||||
double m_minScale;
|
||||
double m_maxScale;
|
||||
double m_stepScale;
|
||||
double m_multiplier;
|
||||
|
||||
void calculateScaleStep();
|
||||
|
||||
protected:
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
};
|
||||
|
||||
} // namespace LtsWidgets
|
||||
Reference in new issue
Block a user