/*
    QAD - Qt ADvanced

    Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru

    This program 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 3 of the License, or
    (at your option) any later version.

    This program 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 <http://www.gnu.org/licenses/>.
*/

#ifndef COLORBUTTON_H
#define COLORBUTTON_H

#include "qad_widgets_export.h"

#include <QPushButton>


class QFrame;


class QAD_WIDGETS_EXPORT ColorButton: public QPushButton {
	Q_OBJECT
	Q_PROPERTY(QColor color READ color WRITE setColor)
	Q_PROPERTY(bool useNativeDialog READ useNativeDialog WRITE setUseNativeDialog)
	Q_PROPERTY(bool useAlphaChannel READ useAlphaChannel WRITE setUseAlphaChannel)
	Q_PROPERTY(bool frameOnly READ frameOnly WRITE setFrameOnly)

public:
	explicit ColorButton(QWidget * parent = nullptr);
	~ColorButton() override;

	QColor color() const;
	bool useNativeDialog() const;
	bool useAlphaChannel() const;
	bool frameOnly() const { return frame; }

public slots:
	void setColor(const QColor & col);
	void setUseNativeDialog(bool yes);
	void setUseAlphaChannel(bool yes);
	void setFrameOnly(bool yes);

private slots:
	void clicked();
	void copy();
	void paste();
	void mix();

signals:
	void colorChanged(QColor);

private:
	void mousePressEvent(QMouseEvent * e) override;
	void mouseMoveEvent(QMouseEvent * e) override;
	void resizeEvent(QResizeEvent *) override;
	void dragEnterEvent(QDragEnterEvent * e) override;
	void dropEvent(QDropEvent * e) override;
	void changeEvent(QEvent * e) override;

	QFrame * label;
	QWidget * back;
	QAction *a_copy, *a_paste, *a_mix;
	QPalette pal;
	QPoint pp;
	QMenu * menu;
	int options;
	bool frame;
};

#endif // COLORBUTTON_H
