/*
 * actionlineedit.h - QLineEdit widget with buttons on right side
 * Copyright (C) 2009  Sergey Ilinykh
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

#ifndef ACTIONLINEEDIT_H
#define ACTIONLINEEDIT_H

#include <QAbstractButton>
#include <QAction>
#include <QLineEdit>
#include <QList>

class ActionLineEditButton : public QAbstractButton {
    Q_OBJECT

public:
    constexpr static auto IconScaleFactor = 0.6;

    ActionLineEditButton(QWidget *parent);
    void     setDefaultAction(QAction *);
    QAction *defaultAction();
    void     setPopup(QWidget *);

public slots:
    void updateFromAction(); // FIXME private
    void showPopup();

protected:
    void  paintEvent(QPaintEvent *event);
    QSize sizeHint() const;

private:
    QAction *action_;
    QWidget *popup_;
};

class ActionLineEdit : public QLineEdit {
    Q_OBJECT
    Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle)
    Q_ENUMS(Qt::ToolButtonStyle)

public:
    ActionLineEdit(QWidget *parent);
    ActionLineEditButton *widgetForAction(QAction *action);
    void                  actionEvent(QActionEvent *event);
    Qt::ToolButtonStyle   toolButtonStyle() const { return toolButtonStyle_; }
    void                  setToolButtonStyle(const Qt::ToolButtonStyle newStyle) { toolButtonStyle_ = newStyle; }

protected:
    // reimplemented
    void contextMenuEvent(QContextMenuEvent *e);

private:
    Qt::ToolButtonStyle toolButtonStyle_;
};

#endif // ACTIONLINEEDIT_H
