File indexing completed on 2024-05-12 05:39:45

0001 /***************************************************************************
0002  *     Copyright (C) 2014 by Renaud Guezennec                              *
0003  *     https://rolisteam.org/                                           *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef COLORBUTTON_H
0022 #define COLORBUTTON_H
0023 
0024 #include <QColorDialog>
0025 #include <QPushButton>
0026 
0027 #include <common_widgets/common_widgets_global.h>
0028 
0029 /**
0030  * @brief A button to choose a color.
0031  */
0032 class COMMON_WIDGET_EXPORT ColorButton : public QPushButton
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     /**
0038      * @brief ColorButton
0039      * @param parent
0040      * @param transparency
0041      */
0042     ColorButton(QWidget* parent, bool transparency= false);
0043     /**
0044      * @brief ColorButton
0045      * @param color
0046      * @param parent
0047      */
0048     ColorButton(const QColor& color= QColor("tan"), QWidget* parent= nullptr);
0049     virtual ~ColorButton();
0050     /**
0051      * @brief color
0052      * @return
0053      */
0054     QColor color() const;
0055     /**
0056      * @brief sizeHint
0057      * @return
0058      */
0059     virtual QSize sizeHint() const;
0060     /**
0061      * @brief setTransparency
0062      */
0063     void setTransparency(bool);
0064 
0065 signals:
0066     /**
0067      * @brief colorChanged
0068      * @param color
0069      */
0070     void colorChanged(const QColor& color);
0071 
0072 public slots:
0073     /**
0074      * @brief setColor
0075      * @param color
0076      */
0077     void setColor(const QColor& color);
0078 
0079     void openDialog();
0080 
0081 private:
0082     QColor m_color;
0083     bool m_hasTransparency;
0084     // QColorDialog m_dialog;
0085 };
0086 
0087 #endif