File indexing completed on 2024-04-28 17:06:07

0001 /*
0002     SPDX-FileCopyrightText: 2004 Csaba Karai <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef KGCOLORS_H
0009 #define KGCOLORS_H
0010 
0011 // QtCore
0012 #include <QList>
0013 // QtWidgets
0014 #include <QGridLayout>
0015 #include <QLabel>
0016 #include <QPushButton>
0017 #include <QStackedWidget>
0018 
0019 #include "../GUI/krtreewidget.h"
0020 #include "konfiguratorpage.h"
0021 
0022 class KgColors : public KonfiguratorPage
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit KgColors(bool first, QWidget *parent = nullptr);
0028 
0029     bool apply() override;
0030 
0031 public slots:
0032     void slotDisable();
0033     void slotForegroundChanged();
0034     void slotBackgroundChanged();
0035     void slotAltBackgroundChanged();
0036     void slotActiveChanged();
0037     void slotMarkedBackgroundChanged();
0038     void slotInactiveForegroundChanged();
0039     void slotInactiveBackgroundChanged();
0040     void slotInactiveAltBackgroundChanged();
0041     void slotInactiveMarkedBackgroundChanged();
0042     void generatePreview();
0043 
0044 protected slots:
0045     void slotImportColors();
0046     void slotExportColors();
0047 
0048 private:
0049     class PreviewItem;
0050 
0051     int addColorSelector(const QString &cfgName,
0052                          QString name,
0053                          QColor defaultValue,
0054                          const QString &dfltName = QString(),
0055                          ADDITIONAL_COLOR *addColor = nullptr,
0056                          int addColNum = 0);
0057     KonfiguratorColorChooser *getColorSelector(const QString &name);
0058     QLabel *getSelectorLabel(const QString &name);
0059     void serialize(class QDataStream &);
0060     void deserialize(class QDataStream &);
0061     void serializeItem(class QDataStream &, const char *name);
0062     void setColorWithDimming(PreviewItem *item, QColor foreground, QColor background, bool dimmed);
0063 
0064 private:
0065     QWidget *colorsGrp;
0066     QGridLayout *colorsGrid;
0067     int offset;
0068     int endOfActiveColors;
0069     int endOfPanelColors;
0070     int activeTabIdx, inactiveTabIdx;
0071 #ifdef SYNCHRONIZER_ENABLED
0072     int synchronizerTabIdx;
0073 #endif
0074     int otherTabIdx;
0075 
0076     QGroupBox *previewGrp;
0077     QGridLayout *previewGrid;
0078     QTabWidget *colorTabWidget;
0079 
0080     QStackedWidget *inactiveColorStack;
0081     QWidget *normalInactiveWidget;
0082     QWidget *dimmedInactiveWidget;
0083     KonfiguratorSpinBox *dimFactor;
0084 
0085     KonfiguratorCheckBoxGroup *generals;
0086 
0087     QList<QLabel *> labelList;
0088     QList<KonfiguratorColorChooser *> itemList;
0089     QList<QString> itemNames;
0090 
0091     KrTreeWidget *preview;
0092     QPushButton *importBtn, *exportBtn;
0093 
0094     class PreviewItem : public QTreeWidgetItem
0095     {
0096     private:
0097         QColor defaultBackground;
0098         QColor defaultForeground;
0099         QString label;
0100 
0101     public:
0102         PreviewItem(QTreeWidget *parent, const QString &name)
0103         {
0104             setText(0, name);
0105             defaultBackground = QColor(255, 255, 255);
0106             defaultForeground = QColor(0, 0, 0);
0107             label = name;
0108             parent->insertTopLevelItem(0, this);
0109         }
0110 
0111         void setColor(const QColor &foregnd, const QColor &backgnd)
0112         {
0113             defaultForeground = foregnd;
0114             defaultBackground = backgnd;
0115 
0116             QBrush textColor(foregnd);
0117             QBrush baseColor(backgnd);
0118 
0119             for (int i = 0; i != columnCount(); i++) {
0120                 if (backgnd.isValid())
0121                     setBackground(i, baseColor);
0122                 if (foregnd.isValid())
0123                     setForeground(i, textColor);
0124             }
0125         }
0126 
0127         QString text()
0128         {
0129             return label;
0130         }
0131     };
0132 };
0133 #endif /* __KGCOLORS_H__ */