1 /************************************************************************** 2 * Otter Browser: Web browser controlled by the user, not vice-versa. 3 * Copyright (C) 2013 - 2018 Michal Dutkiewicz aka Emdek <michal@emdek.pl> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 **************************************************************************/ 19 20 #ifndef OTTER_CONFIGURATIONCONTENTSWIDGET_H 21 #define OTTER_CONFIGURATIONCONTENTSWIDGET_H 22 23 #include "../../../ui/ContentsWidget.h" 24 #include "../../../ui/ItemDelegate.h" 25 26 #include <QtGui/QStandardItemModel> 27 28 namespace Otter 29 { 30 31 namespace Ui 32 { 33 class ConfigurationContentsWidget; 34 } 35 36 class Window; 37 38 class ConfigurationOptionDelegate final : public ItemDelegate 39 { 40 public: 41 explicit ConfigurationOptionDelegate(QObject *parent); 42 43 void setEditorData(QWidget *editor, const QModelIndex &index) const override; 44 void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; 45 QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 46 47 protected: 48 void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override; 49 }; 50 51 class ConfigurationContentsWidget final : public ContentsWidget 52 { 53 Q_OBJECT 54 55 public: 56 enum DataRole 57 { 58 IdentifierRole = Qt::UserRole, 59 NameRole, 60 IsModifiedRole, 61 RequiresRestartRole 62 }; 63 64 explicit ConfigurationContentsWidget(const QVariantMap ¶meters, Window *window, QWidget *parent); 65 ~ConfigurationContentsWidget(); 66 67 void print(QPrinter *printer) override; 68 QString getTitle() const override; 69 QLatin1String getType() const override; 70 QUrl getUrl() const override; 71 QIcon getIcon() const override; 72 bool eventFilter(QObject *object, QEvent *event) override; 73 74 public slots: 75 void triggerAction(int identifier, const QVariantMap ¶meters = {}, ActionsManager::TriggerType trigger = ActionsManager::UnknownTrigger) override; 76 77 protected: 78 void closeEvent(QCloseEvent *event) override; 79 void changeEvent(QEvent *event) override; 80 void saveAll(bool reset); 81 82 protected slots: 83 void copyOptionName(); 84 void copyOptionValue(); 85 void resetOption(); 86 void saveOption(); 87 void handleOptionChanged(int identifier, const QVariant &value); 88 void handleCurrentIndexChanged(const QModelIndex ¤tIndex, const QModelIndex &previousIndex); 89 void handleIndexClicked(const QModelIndex &index); 90 void showContextMenu(const QPoint &position); 91 void updateActions(); 92 93 private: 94 QStandardItemModel *m_model; 95 Ui::ConfigurationContentsWidget *m_ui; 96 }; 97 98 } 99 100 #endif 101