//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/View/Overlay/IRectangularOverlay.h
//! @brief     Defines class IRectangularOverlay.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_GUI_VIEW_OVERLAY_IRECTANGULAROVERLAY_H
#define BORNAGAIN_GUI_VIEW_OVERLAY_IRECTANGULAROVERLAY_H

#include "GUI/View/Overlay/IMaskOverlay.h"
#include "GUI/View/Overlay/SizeHandleElement.h"
#include <QMap>

//! Base view for all rectangular-like masks.

class IRectangularOverlay : public IMaskOverlay {
    Q_OBJECT
public:
    explicit IRectangularOverlay(ColorMap* plot);

private slots:
    void onSizeHandleElementRequest(bool going_to_resize);

protected:
    void update_view() override;

    virtual void update_position() = 0;
    virtual QRectF mask_rectangle() = 0;

    //... Item properties to scene coordinates
    virtual qreal width() const = 0;
    virtual qreal height() const = 0;

    QRectF m_mask_rect; //!< mask rectangle in scene coordinates
    //!< coordinates of corner opposite to the grip corner at the moment it first clicked
    //!< in scene coordinates
    QPointF m_resize_opposite_origin;
    SizeHandleElement* m_active_handle_element;

    virtual bool is_true_mask() const { return true; } // overridden in ROIOverlay

private:
    QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
    void update_bounding_rect();

    QMap<SizeHandleElement::EHandleLocation, SizeHandleElement*> m_resize_handles;
};

#endif // BORNAGAIN_GUI_VIEW_OVERLAY_IRECTANGULAROVERLAY_H
