/*
 * Xournal++
 *
 * A link element
 *
 * @author Xournal++ Team
 * https://github.com/xournalpp/xournalpp
 *
 * @license GNU GPLv2 or later
 */

#pragma once

#include <string>

#include <pango/pango-layout.h>  // for Layout
#include <pango/pango.h>         // for Pango

#include "util/raii/GObjectSPtr.h"  // For GObjectSPtr

#include "Element.h"  // for Element
#include "Font.h"     // for XojFont
#include "TextAlignment.h"

class Element;
class ObjectInputStream;
class ObjectOutputStream;

class Link: public Element {
public:
    Link();
    ~Link() override = default;

public:
    void setText(std::string text);
    std::string getText() const;

    void setTextPos(double x, double y);

    void setUrl(std::string url);
    std::string getUrl() const;

    void setFont(const XojFont& font);
    XojFont& getFont();
    const XojFont& getFont() const;

    void setAlignment(TextAlignment alignment);
    TextAlignment getAlignment() const;

    xoj::util::GObjectSPtr<PangoLayout> createPangoLayout() const;

public:
    /**
     * @override (required)
     */
    void scale(double x0, double y0, double fx, double fy, double rotation, bool restoreLineWidth) override;
    void rotate(double x0, double y0, double th) override;
    ElementPtr clone() const override;

    /**
     * @override (optional)
     */
    void serialize(ObjectOutputStream& out) const override;
    void readSerialized(ObjectInputStream& in) override;
    bool rescaleOnlyAspectRatio() const override;
    bool rescaleWithMirror() const override;

    static constexpr double PADDING = 2.0;  // space around text including painted border

protected:
    void calcSize() const override;

private:
    XojFont font;
    std::string text;
    std::string url;
    TextAlignment alignment = TextAlignment::LEFT;
};
