File indexing completed on 2024-04-21 03:41:44

0001 /*
0002     SPDX-FileCopyrightText: 2007 Carsten Niehaus <cniehaus@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef LEGENDWIDGET_H
0008 #define LEGENDWIDGET_H
0009 
0010 #include <QLabel>
0011 
0012 #include "kalziumelementproperty.h"
0013 
0014 class LegendItem;
0015 
0016 /**
0017  * @author Carsten Niehaus
0018  *
0019  * The LegendWidget displays the explanations of what the user is currently
0020  * seeing in the table
0021  */
0022 class LegendWidget : public QWidget
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit LegendWidget(QWidget *parent);
0028 
0029     ~LegendWidget() override;
0030 
0031     void LockWidget();
0032     void UnLockWidget();
0033 
0034 Q_SIGNALS:
0035     void elementMatched(int element);
0036     void resetElementMatch();
0037 
0038 public Q_SLOTS:
0039     void updateContent();
0040 
0041     void setDockArea(Qt::DockWidgetArea newDockArea);
0042 
0043     /// is triggered when a LegenItem is Hoovered.
0044     void legendItemAction(QColor color);
0045 
0046 private:
0047     bool isElementMatch(int element, QColor &color);
0048 
0049     bool m_update;
0050 
0051     QPixmap m_pixmap;
0052 
0053     QList<LegendItem *> m_legendItemList;
0054 
0055     Qt::DockWidgetArea m_dockArea;
0056 
0057     void updateLegendItemLayout(const QList<legendPair> &list);
0058 };
0059 
0060 /**
0061  * A LegendItem is displayed as one small rectangle which represents the
0062  * color in the table with a short explanation for it.
0063  *
0064  * @author Carsten Niehaus
0065  */
0066 class LegendItem : public QLabel
0067 {
0068     Q_OBJECT
0069 
0070 public:
0071     LegendItem(const QPair<QString, QColor> &pair, LegendWidget *parent = nullptr);
0072     ~LegendItem() override = default;
0073 
0074 Q_SIGNALS:
0075     void legenItemHoovered(QColor color);
0076 
0077 private:
0078     QColor legendItemColor;
0079 
0080 protected:
0081 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0082     void enterEvent(QEnterEvent *event) override;
0083 #else
0084     void enterEvent(QEvent *event) override;
0085 #endif
0086     void leaveEvent(QEvent *event) override;
0087 };
0088 
0089 #endif // LEGENDWIDGET_H