File indexing completed on 2024-05-12 17:12:40

0001 /***************************************************************************
0002  *  Copyright (C) 2009 by Renaud Guezennec                             *
0003  *   https://rolisteam.org/contact                   *
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 VCOLORSELECTOR_H
0022 #define VCOLORSELECTOR_H
0023 
0024 #include <QColor>
0025 #include <QFrame>
0026 #include <QPushButton>
0027 #include <QWidget>
0028 
0029 //#include "types.h"
0030 #include "rwidgets/rwidgets_global.h"
0031 #include "vcolortablechooser.h"
0032 
0033 class PreferencesManager;
0034 /**
0035  * @brief shows selected color and detect any event such as click or doubleclick
0036  */
0037 class RWIDGET_EXPORT VColorLabel : public QAbstractButton
0038 {
0039     Q_OBJECT
0040 public:
0041     /**
0042      * @brief default constructor
0043      */
0044     explicit VColorLabel(QWidget* parent= nullptr);
0045     int heightForWidth(int width) const;
0046 
0047 signals:
0048     /**
0049      * @brief send off the current color
0050      */
0051     void clickedColor(const QColor& p);
0052     /**
0053      * @brief is emitted when users doubleclick on it.
0054      */
0055     void doubledclicked();
0056 
0057 protected:
0058     /**
0059      * @brief redefine the drawing of the widget to show a colof filled square
0060      */
0061     void paintEvent(QPaintEvent* event);
0062 
0063     virtual void resizeEvent(QResizeEvent* event);
0064 
0065     /**
0066      * @brief redefine the mousePressEvent behaviour to emit clickedColor signal
0067      */
0068     virtual void mousePressEvent(QMouseEvent* ev);
0069     /**
0070      * @brief redefine mouseDoubleClickEvent to emit the doubledclicked signal
0071      */
0072     virtual void mouseDoubleClickEvent(QMouseEvent* event);
0073 };
0074 /**
0075  * @brief custom pushbutton to display a pixmap as background
0076  * @todo Should be moved into stand alone files (h and cpp) and put them in the widget directory
0077  *
0078  */
0079 class RWIDGET_EXPORT BackgroundButton : public QPushButton
0080 {
0081     Q_OBJECT
0082 public:
0083     /**
0084      * @brief constructor with arguments
0085      * @param pixmap
0086      */
0087     BackgroundButton(QPixmap* p, QWidget* parent= nullptr);
0088 
0089 protected:
0090     /**
0091      * @brief draw the button
0092      */
0093     virtual void paintEvent(QPaintEvent* event);
0094 
0095 private:
0096     /**
0097      * @brief stores the background picture
0098      */
0099     QPixmap* m_background;
0100 };
0101 
0102 /**
0103  * @brief custom widget to display many color squares, click select the color.
0104  */
0105 class RWIDGET_EXPORT VColorSelector : public QWidget
0106 {
0107     Q_OBJECT
0108 public:
0109     /**
0110      * @brief Constructor compliant with QWidget constructor
0111      */
0112     explicit VColorSelector(QWidget* parent= nullptr);
0113     /**
0114      * @brief define the current color
0115      * @param new color
0116      */
0117     void setCurrentColor(const QColor& color);
0118     /**
0119      * @brief accessor to the current color
0120      * @return current color
0121      */
0122     QColor& currentColor();
0123 
0124 signals:
0125     /**
0126      * @brief emitted when color changed
0127      */
0128     void currentColorChanged(QColor&);
0129 
0130 private slots:
0131     /**
0132      * @brief select the color as current
0133      * @param new color
0134      * @todo Duplicate with the setter ?
0135      */
0136     void selectColor(const QColor& color);
0137     /**
0138      * @brief open the color selector dialog box
0139      */
0140     void VColorSelectorDialog();
0141 
0142 private:
0143     /**
0144      * @brief current colorlabel
0145      */
0146     VColorLabel* m_currentColorLabel;
0147     /**
0148      * @brief current color
0149      */
0150     QColor m_currentColor;
0151 
0152     /**
0153      * pointer to the unique instance of preference manager.
0154      */
0155     PreferencesManager* m_options;
0156     /**
0157      * @brief m_colorTableChooser
0158      */
0159     ColorTableChooser* m_colorTableChooser;
0160 };
0161 
0162 #endif