/***************************************************************************
 *   Copyright 2007-2008 Wouter Haffmans <cheetah@simply-life.net>         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as        *
 *   published by the Free Software Foundation; either version 2 of        *
 *   the License or (at your option) version 3 or any later version        *
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 *   defined in Section 14 of version 3 of the license.                    *
 *                                                                         *
 *   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 General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 ***************************************************************************/

#ifndef SIMPLEWIDTHPICK_H
#define SIMPLEWIDTHPICK_H

#include <QWidget>

class QTimer;

/**
 * A simple color pick class. A signal is emitted whenever the mouse enters
 * this widget. Its set color will then be sent along with it.
 */
class SimpleWidthPick: public QWidget
{
    Q_OBJECT
    Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth)
    Q_PROPERTY(QColor color READ color WRITE setColor)
    Q_PROPERTY(
        QColor backgroundColor
        READ backgroundColor
        WRITE setBackgroundColor
    )
    Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
    Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth)

public:
    /**
     * Constructor.
     * @param lineWidth The line width of the pick. Defaults to 1.
     * @param parent The parent widget. Defaults to NULL.
     */
    explicit SimpleWidthPick(int lineWidth = 1, QWidget *parent = 0);

    /**
     * Destructor.
     */
    ~SimpleWidthPick();

    /**
     * Retrieve the line width.
     */
    int     lineWidth() const;

    /**
     * Retrieve the current line color.
     */
    QColor  color() const;

    /**
     * Retrieve the current background color.
     */
    QColor  backgroundColor() const;

    /**
     * Retrieve the color of the widget's border.
     */
    QColor  borderColor() const;

    /**
     * Retrieve the width of the widget's border.
     */
    int     borderWidth() const;

    /**
     * Retrieve the default size hint.
     */
    QSize sizeHint() const;

    /**
     * Retrieve the default minimum size hint.
     */
    QSize minimumSizeHint() const;

public slots:
    /**
     * Set the line width.
     * @param lineWidth The new line wirdth.
     */
    void    setLineWidth(int lineWidth);

    /**
     * Set the line color.
     * @param color The new line color.
     */
    void    setColor(QColor color);

    /**
     * Set the background color.
     * @param backgroundColor The new background color.
     */
    void    setBackgroundColor(QColor color);

    /**
     * Set the widget's border color.
     * @param borderColor The new border color.
     */
    void    setBorderColor(QColor borderColor);

    /**
     * Set the widget's border width.
     * @param borderWidth The new border width.
     */
    void    setBorderWidth(int borderWidth);

signals:
    /**
     * This signal is emitted whenever the width is picked. It carries the width
     * as parameter.
     * @param lineWidth The picked line width
     */
    void    picked(int lineWidth);

protected:
    /**
     * Reimplementation of QWidget's enterEvent. Occurs when the mouse enters
     * the widget, and will start a timer which will delay trigger the picked()
     * signal.
     * @param event The enter event
     */
    void    enterEvent(QEvent *event);

    /**
     * Reimplementation of QWidget's leaveEvent. Occurs when the mouse exits
     * the widget, and will cause a running picker timer to stop.
     * @param event The enter event
     */
    void    leaveEvent(QEvent *event);

    /**
     * Reimplementation of QWidget's paintEvent.
     * @param event The paint event
     */
    void    paintEvent(QPaintEvent *event);

private slots:
    /**
     * Emits the picked() signal with the set color.
     */
    void    emitPicked();

private:
    int     m_lineWidth;
    QColor  m_color;
    QColor  m_backgroundColor;
    QColor  m_borderColor;
    int     m_borderWidth;
    QTimer *m_pickTimer;
};

#endif
