File indexing completed on 2024-04-28 05:35:26
0001 /* 0002 SPDX-FileCopyrightText: 2008 Dmitry Suzdalev <dimsuz@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QTreeWidget> 0009 0010 /** 0011 * Custom tree widget class to make KConfigDialog properly 0012 * highlight Apply button when some action is changed. 0013 * We achieve this by adding custom type handling to KConfigDialogManager 0014 * and by adding a somewhat dummy config entry which gets changed whenever 0015 * some action is changed in treewidget. 0016 * KConfigDialog watches this entry for changes and highlights Apply when needed 0017 * 0018 * @see KConfigDialogManager 0019 */ 0020 class ActionsTreeWidget : public QTreeWidget 0021 { 0022 Q_OBJECT 0023 0024 // this property is int instead of (more logical) bool, because we need a custom handling of 0025 // "default state" and because of our custom use of this property: 0026 // 0027 // We indicate that changes were made to this widget by changing this int value. 0028 // We use it as "if this value is *CHANGED SOMEHOW*, this means that some changes were made to action list", 0029 // If we'd make this property bool, KConfigDialog would highlight "Defaults" button whenever 0030 // this property becomes false, but this is not the way we use this property. 0031 // So we change it from 0 to 1 periodically when something changes. Both 0, 1 values indicate 0032 // change. 0033 // 0034 // We set it to default only when resetModifiedState() is called, i.e. when Apply btn is being 0035 // clicked 0036 // 0037 // Hope this explains it. 0038 // Yeah, this class is a trick :) If there's a better way to properly 0039 // update KConfigDialog buttons whenever "some change occurs to QTreeWidget", let me know (dimsuz) 0040 Q_PROPERTY(int actionsChanged READ actionsChanged WRITE setActionsChanged USER true) 0041 0042 public: 0043 explicit ActionsTreeWidget(QWidget *parent = nullptr); 0044 0045 void setActionsChanged(int); 0046 int actionsChanged() const; 0047 0048 void resetModifiedState(); 0049 0050 Q_SIGNALS: 0051 void changed(); 0052 0053 private Q_SLOTS: 0054 void onItemChanged(); 0055 0056 private: 0057 int m_actionsChanged; 0058 bool m_modified; 0059 };