Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/filtermanager/uifiltermanager.py
1 | ''' | 1 | # This script is licensed CC 0 1.0, so that you can learn from it. | ||
---|---|---|---|---|---|
2 | This script is licensed CC 0 1.0, so that you can learn from it. | | |||
3 | 2 | | |||
4 | ------ CC 0 1.0 --------------- | 3 | # ------ CC 0 1.0 --------------- | ||
5 | 4 | | |||
6 | The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. | 5 | # The person who associated a work with this deed has dedicated the | ||
6 | # work to the public domain by waiving all of his or her rights to the | ||||
7 | # work worldwide under copyright law, including all related and | ||||
8 | # neighboring rights, to the extent allowed by law. | ||||
7 | 9 | | |||
8 | You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. | 10 | # You can copy, modify, distribute and perform the work, even for | ||
11 | # commercial purposes, all without asking permission. | ||||
12 | | ||||
13 | # https://creativecommons.org/publicdomain/zero/1.0/legalcode | ||||
9 | 14 | | |||
10 | https://creativecommons.org/publicdomain/zero/1.0/legalcode | | |||
11 | ''' | | |||
12 | from . import filtermanagerdialog | 15 | from . import filtermanagerdialog | ||
13 | from .components import (filtercombobox, filtermanagertreemodel) | 16 | from .components import (filtercombobox, filtermanagertreemodel) | ||
14 | from PyQt5.QtCore import Qt | 17 | from PyQt5.QtCore import Qt | ||
15 | from PyQt5.QtWidgets import (QFormLayout, QAbstractItemView, QDialogButtonBox, | 18 | from PyQt5.QtWidgets import (QFormLayout, QAbstractItemView, QDialogButtonBox, | ||
16 | QVBoxLayout, QFrame, QAbstractScrollArea, QWidget, | 19 | QVBoxLayout, QFrame, QTreeView) | ||
17 | QTreeView) | | |||
18 | import krita | 20 | import krita | ||
19 | 21 | | |||
20 | 22 | | |||
21 | class UIFilterManager(object): | 23 | class UIFilterManager(object): | ||
22 | 24 | | |||
23 | def __init__(self): | 25 | def __init__(self): | ||
24 | self.mainDialog = filtermanagerdialog.FilterManagerDialog() | 26 | self.mainDialog = filtermanagerdialog.FilterManagerDialog() | ||
25 | self.mainLayout = QVBoxLayout(self.mainDialog) | 27 | self.mainLayout = QVBoxLayout(self.mainDialog) | ||
26 | self.formLayout = QFormLayout() | 28 | self.formLayout = QFormLayout() | ||
27 | self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | 29 | self.buttonBox = QDialogButtonBox( | ||
30 | QDialogButtonBox.Ok | QDialogButtonBox.Cancel) | ||||
28 | 31 | | |||
29 | self.kritaInstance = krita.Krita.instance() | 32 | self.kritaInstance = krita.Krita.instance() | ||
30 | self._filters = sorted(self.kritaInstance.filters()) | 33 | self._filters = sorted(self.kritaInstance.filters()) | ||
31 | self._documents = self.kritaInstance.documents() | 34 | self._documents = self.kritaInstance.documents() | ||
32 | self.treeModel = filtermanagertreemodel.FilterManagerTreeModel(self) | 35 | self.treeModel = filtermanagertreemodel.FilterManagerTreeModel(self) | ||
33 | 36 | | |||
34 | self.documentsTreeView = QTreeView() | 37 | self.documentsTreeView = QTreeView() | ||
35 | self.filterComboBox = filtercombobox.FilterComboBox(self) | 38 | self.filterComboBox = filtercombobox.FilterComboBox(self) | ||
36 | 39 | | |||
37 | self.buttonBox.accepted.connect(self.confirmButton) | 40 | self.buttonBox.accepted.connect(self.confirmButton) | ||
38 | self.buttonBox.rejected.connect(self.mainDialog.close) | 41 | self.buttonBox.rejected.connect(self.mainDialog.close) | ||
39 | 42 | | |||
40 | self.documentsTreeView.setSelectionMode(QAbstractItemView.SingleSelection) | 43 | self.documentsTreeView.setSelectionMode( | ||
44 | QAbstractItemView.SingleSelection) | ||||
41 | self.mainDialog.setWindowModality(Qt.NonModal) | 45 | self.mainDialog.setWindowModality(Qt.NonModal) | ||
42 | 46 | | |||
43 | def initialize(self): | 47 | def initialize(self): | ||
44 | self.documentsTreeView.setModel(self.treeModel) | 48 | self.documentsTreeView.setModel(self.treeModel) | ||
45 | self.documentsTreeView.setWindowTitle(i18n("Document Tree Model")) | 49 | self.documentsTreeView.setWindowTitle(i18n("Document Tree Model")) | ||
46 | self.documentsTreeView.resizeColumnToContents(0) | 50 | self.documentsTreeView.resizeColumnToContents(0) | ||
47 | self.documentsTreeView.resizeColumnToContents(1) | 51 | self.documentsTreeView.resizeColumnToContents(1) | ||
48 | self.documentsTreeView.resizeColumnToContents(2) | 52 | self.documentsTreeView.resizeColumnToContents(2) | ||
Show All 38 Lines | 90 | for index in indexes: | |||
87 | document = self.documents[index] | 91 | document = self.documents[index] | ||
88 | document.refreshProjection() | 92 | document.refreshProjection() | ||
89 | 93 | | |||
90 | def applyFilterOverNode(self, node, document): | 94 | def applyFilterOverNode(self, node, document): | ||
91 | _filter = self.kritaInstance.filter(self.filterComboBox.currentText()) | 95 | _filter = self.kritaInstance.filter(self.filterComboBox.currentText()) | ||
92 | _filter.apply(node, 0, 0, document.width(), document.height()) | 96 | _filter.apply(node, 0, 0, document.width(), document.height()) | ||
93 | 97 | | |||
94 | def applyFilterOverDocument(self, document): | 98 | def applyFilterOverDocument(self, document): | ||
95 | """ This method applies the selected filter just to topLevelNodes, then | 99 | """This method applies the selected filter just to topLevelNodes, | ||
96 | if topLevelNodes are GroupLayers, that filter will not be applied. """ | 100 | then if topLevelNodes are GroupLayers, that filter will not be | ||
101 | applied.""" | ||||
97 | 102 | | |||
98 | for node in document.topLevelNodes(): | 103 | for node in document.topLevelNodes(): | ||
99 | self.applyFilterOverNode(node, document) | 104 | self.applyFilterOverNode(node, document) | ||
100 | 105 | | |||
101 | @property | 106 | @property | ||
102 | def filters(self): | 107 | def filters(self): | ||
103 | return self._filters | 108 | return self._filters | ||
104 | 109 | | |||
105 | @property | 110 | @property | ||
106 | def documents(self): | 111 | def documents(self): | ||
107 | return self._documents | 112 | return self._documents |