File: filetypesview.h

package info (click to toggle)
kde-cli-tools 4%3A5.27.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,968 kB
  • sloc: cpp: 4,773; sh: 37; makefile: 7
file content (93 lines) | stat: -rw-r--r-- 2,274 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*  This file is part of the KDE project
    SPDX-FileCopyrightText: 2000-2008 David Faure <faure@kde.org>
    SPDX-FileCopyrightText: 2008 Urs Wolfer <uwolfer @ kde.org>

    SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/

#ifndef FILETYPESVIEW_H
#define FILETYPESVIEW_H

#include <QLabel>
#include <QList>
#include <QMap>
#include <QStackedWidget>

#include <KCModule>
#include <KSharedConfig>

#include "typeslistitem.h"

class QTreeWidget;
class QTreeWidgetItem;
class QPushButton;
class KLineEdit;
class FileTypeDetails;
class FileGroupDetails;

class FileTypesView : public KCModule
{
    Q_OBJECT
public:
    FileTypesView(QWidget *parent, const QVariantList &args);
    ~FileTypesView() override;

    void load() override;
    void save() override;
    void defaults() override;

protected Q_SLOTS:
    void addType();
    void removeType();
    void updateDisplay(QTreeWidgetItem *);
    void slotDoubleClicked(QTreeWidgetItem *);
    void slotFilter(const QString &patternFilter);
    void setDirty(bool state);

    void slotDatabaseChanged();
    void slotEmbedMajor(const QString &major, bool &embed);

private:
    void readFileTypes();
    void updateRemoveButton(TypesListItem *item);

private:
    QTreeWidget *typesLV;
    QPushButton *m_removeTypeB;

    QStackedWidget *m_widgetStack;
    FileTypeDetails *m_details;
    FileGroupDetails *m_groupDetails;
    QLabel *m_emptyWidget;

    KLineEdit *patternFilterLE;
    QStringList removedList;
    bool m_dirty;
    bool m_removeButtonSaysRevert;
    QMap<QString, TypesListItem *> m_majorMap; // groups
    QList<TypesListItem *> m_itemList;

    KSharedConfig::Ptr m_fileTypesConfig;
};

// helper class for loading the icon on request instead of preloading lots of probably
// unused icons which takes quite a lot of time
class TypesListTreeWidget : public QTreeWidget
{
    Q_OBJECT
public:
    explicit TypesListTreeWidget(QWidget *parent)
        : QTreeWidget(parent)
    {
    }

protected:
    void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
    {
        static_cast<TypesListItem *>(itemFromIndex(index))->loadIcon();

        QTreeWidget::drawRow(painter, option, index);
    }
};

#endif