File indexing completed on 2024-04-28 03:59:11

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2004 Antonio Larrosa <larrosa@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KPIXMAPREGIONSELECTORDIALOG_H
0009 #define KPIXMAPREGIONSELECTORDIALOG_H
0010 
0011 #include <QDialog>
0012 #include <memory>
0013 
0014 #include <kwidgetsaddons_export.h>
0015 
0016 class KPixmapRegionSelectorWidget;
0017 
0018 class QImage;
0019 
0020 /**
0021  * @class KPixmapRegionSelectorDialog kpixmapregionselectordialog.h KPixmapRegionSelectorDialog
0022  *
0023  * A dialog that uses a KPixmapRegionSelectorWidget to allow the user
0024  * to select a region of an image. If you want to use special features
0025  * like forcing the selected area to have a fixed aspect ratio, you can use
0026  * pixmapRegionSelectorWidget() to get the pointer to the
0027  * KPixmapRegionSelectorWidget object and set the desired options there.
0028  *
0029  * There are some convenience methods that allow to easily show a dialog
0030  * for the user to select a region of an image, and just care about the selected
0031  * image.
0032  *
0033  * \image html kpixmapregionselectordialog.png "KPixmapRegionSelectorDialog"
0034  *
0035  * @author Antonio Larrosa <larrosa@kde.org>
0036  */
0037 class KWIDGETSADDONS_EXPORT KPixmapRegionSelectorDialog : public QDialog
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     /**
0043      * The constructor of an empty KPixmapRegionSelectorDialog, you have to call
0044      * later the setPixmap method of the KPixmapRegionSelectorWidget widget of
0045      * the new object.
0046      */
0047     explicit KPixmapRegionSelectorDialog(QWidget *parent = nullptr);
0048 
0049     /**
0050      * The destructor of the dialog
0051      */
0052     ~KPixmapRegionSelectorDialog() override;
0053 
0054     /**
0055      * @returns the KPixmapRegionSelectorWidget widget so that additional
0056      * parameters can be set by using it.
0057      */
0058     KPixmapRegionSelectorWidget *pixmapRegionSelectorWidget() const;
0059 
0060     /**
0061      * Creates a modal dialog, lets the user to select a region of the @p pixmap
0062      * and returns when the dialog is closed.
0063      *
0064      * @returns the selected rectangle, or an invalid rectangle if the user
0065      * pressed the Cancel button.
0066      */
0067     static QRect getSelectedRegion(const QPixmap &pixmap, QWidget *parent = nullptr);
0068 
0069     /**
0070      * Creates a modal dialog, lets the user to select a region of the @p pixmap
0071      * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight
0072      * and returns when the dialog is closed.
0073      *
0074      * @returns the selected rectangle, or an invalid rectangle if the user
0075      * pressed the Cancel button.
0076      */
0077     static QRect getSelectedRegion(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent = nullptr);
0078 
0079     /**
0080      * Creates a modal dialog, lets the user to select a region of the @p pixmap
0081      * and returns when the dialog is closed.
0082      *
0083      * @returns the selected image, or an invalid image if the user
0084      * pressed the Cancel button.
0085      */
0086     static QImage getSelectedImage(const QPixmap &pixmap, QWidget *parent = nullptr);
0087 
0088     /**
0089      * Creates a modal dialog, lets the user to select a region of the @p pixmap
0090      * with the same aspect ratio than @p aspectRatioWidth x @p aspectRatioHeight
0091      * and returns when the dialog is closed.
0092      *
0093      * @returns the selected image, or an invalid image if the user
0094      * pressed the Cancel button.
0095      */
0096     static QImage getSelectedImage(const QPixmap &pixmap, int aspectRatioWidth, int aspectRatioHeight, QWidget *parent = nullptr);
0097 
0098     /**
0099      * @since 4.4.3
0100      * Adjusts the size of the KPixmapRegionSelectorWidget to not overflow the screen size
0101      */
0102     void adjustRegionSelectorWidgetSizeToFitScreen();
0103 
0104 private:
0105     std::unique_ptr<class KPixmapRegionSelectorDialogPrivate> const d;
0106 
0107     Q_DISABLE_COPY(KPixmapRegionSelectorDialog)
0108 };
0109 
0110 #endif