File indexing completed on 2024-06-16 04:16:24

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Mathias Wein <lynx.mw+kde@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #ifndef WGCOLORPREVIEWTOOLTIP_H
0008 #define WGCOLORPREVIEWTOOLTIP_H
0009 
0010 #include <QIcon>
0011 #include <QWidget>
0012 
0013 /* Code based on KisColorPreviewPopup in kis_color_selector_base.cpp
0014  * from Advanced Color Selector.
0015  * Copyright (c) 2010 Adam Celarek <kdedev at xibo dot at> */
0016 
0017 class WGColorPreviewToolTip : public QWidget
0018 {
0019     Q_OBJECT
0020 public:
0021     explicit WGColorPreviewToolTip(QWidget *parent = nullptr);
0022 
0023     void show(const QWidget *focus = nullptr)
0024     {
0025         updatePosition(focus);
0026         QWidget::show();
0027     }
0028 
0029     void updatePosition(const QWidget *focus);
0030 
0031     void setCurrentColor(const QColor& color)
0032     {
0033         m_color = color;
0034         update();
0035     }
0036 
0037     void setPreviousColor(const QColor& color)
0038     {
0039         m_previousColor = color;
0040         update();
0041     }
0042 
0043     void setLastUsedColor(const QColor& color)
0044     {
0045         m_lastUsedColor = color;
0046         update();
0047     }
0048     static qreal estimateBrightness(QColor col);
0049 
0050 protected:
0051     void paintEvent(QPaintEvent *e) override;
0052 
0053 private:
0054     QColor m_color;
0055     QColor m_previousColor;
0056     QColor m_lastUsedColor;
0057     QIcon m_brushIcon;
0058 };
0059 
0060 #endif // WGCOLORPREVIEWTOOLTIP_H