diff --git a/libs/libkis/Krita.h b/libs/libkis/Krita.h --- a/libs/libkis/Krita.h +++ b/libs/libkis/Krita.h @@ -107,6 +107,21 @@ Filter *filter(const QString &name) const; /** + * @brief colorModels creates a list with all color models id's registered. + * @return a list of all color models or a empty list if there is no such color models. + */ + QStringList colorModels() const; + + /** + * @brief colorDepths creates a list with the names of all color depths + * compatible with the given color model. + * @param colorModel the id of a color model. + * @return a list of all color depths or a empty list if there is no such + * color depths. + */ + QStringList colorDepths(const QString &colorModel) const; + + /** * @brief profiles creates a list with the names of all color profiles compatible * with the given color model and color depth. * @param colorModel A string describing the color model of the image: diff --git a/libs/libkis/Krita.cpp b/libs/libkis/Krita.cpp --- a/libs/libkis/Krita.cpp +++ b/libs/libkis/Krita.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -174,6 +175,26 @@ return filter; } +QStringList Krita::colorModels() const +{ + QSet colorModelsIds; + QList ids = KoColorSpaceRegistry::instance()->colorModelsList(KoColorSpaceRegistry::AllColorSpaces); + Q_FOREACH(KoID id, ids) { + colorModelsIds << id.id(); + } + return colorModelsIds.toList();; +} + +QStringList Krita::colorDepths(const QString &colorModel) const +{ + QSet colorDepthsIds; + QList ids = KoColorSpaceRegistry::instance()->colorDepthList(colorModel, KoColorSpaceRegistry::AllColorSpaces); + Q_FOREACH(KoID id, ids) { + colorDepthsIds << id.id(); + } + return colorDepthsIds.toList();; +} + QStringList Krita::profiles(const QString &colorModel, const QString &colorDepth) const { QSet profileNames; @@ -374,4 +395,3 @@ else return 0; } - diff --git a/plugins/extensions/pykrita/plugin/plugins/CMakeLists.txt b/plugins/extensions/pykrita/plugin/plugins/CMakeLists.txt --- a/plugins/extensions/pykrita/plugin/plugins/CMakeLists.txt +++ b/plugins/extensions/pykrita/plugin/plugins/CMakeLists.txt @@ -75,6 +75,7 @@ #install_pykrita_plugin(hello) install_pykrita_plugin(assignprofiledialog) install_pykrita_plugin(scripter) +install_pykrita_plugin(colorspace) #install_pykrita_plugin(highpass) install_pykrita_plugin(tenbrushes) diff --git a/plugins/extensions/pykrita/plugin/plugins/colorspace/__init__.py b/plugins/extensions/pykrita/plugin/plugins/colorspace/__init__.py new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/plugin/plugins/colorspace/__init__.py @@ -0,0 +1,2 @@ +# let's make a module +from .colorspace import * diff --git a/plugins/extensions/pykrita/plugin/plugins/colorspace/colorspace.py b/plugins/extensions/pykrita/plugin/plugins/colorspace/colorspace.py new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/plugin/plugins/colorspace/colorspace.py @@ -0,0 +1,23 @@ +import sys +from PyQt5.QtWidgets import QPushButton, QDialog, QDialogButtonBox, QVBoxLayout, QHBoxLayout +from PyQt5.QtCore import Qt +import krita +from colorspace import uicolorspace + + +class ColorSpaceExtension(krita.Extension): + + def __init__(self, parent): + super(ColorSpaceExtension, self).__init__(parent) + + def setup(self): + action = krita.Krita.instance().createAction("Color Space") + action.setToolTip("Plugin to change color space to selected documents") + action.triggered.connect(self.initialize) + + def initialize(self): + self.uicolorspace = uicolorspace.UIColorSpace() + self.uicolorspace.initialize() + + +Scripter.addExtension(ColorSpaceExtension(krita.Krita.instance())) diff --git a/plugins/extensions/pykrita/plugin/plugins/colorspace/colorspacedialog.py b/plugins/extensions/pykrita/plugin/plugins/colorspace/colorspacedialog.py new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/plugin/plugins/colorspace/colorspacedialog.py @@ -0,0 +1,10 @@ +from PyQt5.QtWidgets import QDialog + + +class ColorSpaceDialog(QDialog): + + def __init__(self, parent=None): + super(ColorSpaceDialog, self).__init__(parent) + + def closeEvent(self, event): + event.accept() diff --git a/plugins/extensions/pykrita/plugin/plugins/colorspace/kritapykrita_colorspace.desktop b/plugins/extensions/pykrita/plugin/plugins/colorspace/kritapykrita_colorspace.desktop new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/plugin/plugins/colorspace/kritapykrita_colorspace.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Type=Service +ServiceTypes=Krita/PythonPlugin +X-KDE-Library=colorspace +X-Python-2-Compatible=false +Name=Color Space +Name[en_GB]=Color Space +Name[pt]=Espaço de Cor +Comment=Plugin to change color space to selected documents +Comment[en_GB]=Plugin to change color space to selected documents +Comment[pt]='Plugin' para alterar o espaço de cor de documentos selecionados diff --git a/plugins/extensions/pykrita/plugin/plugins/colorspace/uicolorspace.py b/plugins/extensions/pykrita/plugin/plugins/colorspace/uicolorspace.py new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/plugin/plugins/colorspace/uicolorspace.py @@ -0,0 +1,113 @@ +from colorspace import colorspacedialog +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import (QFormLayout, QListWidget, QListWidgetItem, + QAbstractItemView, QComboBox, QDialogButtonBox, + QVBoxLayout, QFrame, QMessageBox) +import krita + + +class UIColorSpace(object): + def __init__(self): + self.mainDialog = colorspacedialog.ColorSpaceDialog() + self.mainLayout = QVBoxLayout(self.mainDialog) + self.formLayout = QFormLayout() + self.widgetDocuments = QListWidget() + self.colorModelComboBox = QComboBox() + self.colorDepthComboBox = QComboBox() + self.colorProfileComboBox = QComboBox() + self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + + self.kritaInstance = krita.Krita.instance() + self.documentsList = [] + self.colorModelsList = [] + self.colorDepthsList = [] + self.colorProfilesList = [] + + self.colorModelComboBox.currentTextChanged.connect(self.changedColorModelComboBox) + self.colorDepthComboBox.currentTextChanged.connect(self.changedColorDepthComboBox) + self.buttonBox.accepted.connect(self.confirmButton) + self.buttonBox.rejected.connect(self.mainDialog.close) + + self.mainDialog.setWindowModality(Qt.NonModal) + self.widgetDocuments.setSelectionMode(QAbstractItemView.MultiSelection) + + def initialize(self): + self.loadDocuments() + self.loadColorModels() + self.loadColorDepths() + self.loadColorProfiles() + + self.formLayout.addRow('Documents', self.widgetDocuments) + self.formLayout.addRow('Color Model', self.colorModelComboBox) + self.formLayout.addRow('Color Depth', self.colorDepthComboBox) + self.formLayout.addRow('Color Profile', self.colorProfileComboBox) + + self.line = QFrame() + self.line.setFrameShape(QFrame.HLine) + self.line.setFrameShadow(QFrame.Sunken) + + self.mainLayout.addLayout(self.formLayout) + self.mainLayout.addWidget(self.line) + self.mainLayout.addWidget(self.buttonBox) + + self.mainDialog.resize(500, 300) + self.mainDialog.setWindowTitle("Color Space") + self.mainDialog.setSizeGripEnabled(True) + self.mainDialog.show() + self.mainDialog.activateWindow() + + def loadColorModels(self): + self.colorModelsList = sorted(self.kritaInstance.colorModels()) + + self.colorModelComboBox.addItems(self.colorModelsList) + + def loadColorDepths(self, colorModel=None): + self.colorDepthComboBox.clear() + + if not colorModel: + colorModel = self.colorModelComboBox.currentText() + self.colorDepthsList = sorted(self.kritaInstance.colorDepths(colorModel)) + + self.colorDepthComboBox.addItems(self.colorDepthsList) + + def loadColorProfiles(self, colorModel=None, colorDepth=None): + self.colorProfileComboBox.clear() + + if not colorModel: + colorModel = self.colorModelComboBox.currentText() + if not colorDepth: + colorDepth = self.colorDepthComboBox.currentText() + + self.colorProfilesList = sorted(self.kritaInstance.profiles(colorModel, colorDepth)) + self.colorProfileComboBox.addItems(self.colorProfilesList) + + def loadDocuments(self): + self.widgetDocuments.clear() + + self.documentsList = [document for document in self.kritaInstance.documents() if document.fileName()] + + for document in self.documentsList: + self.widgetDocuments.addItem(document.fileName()) + + def changedColorModelComboBox(self, colorModel): + self.loadColorDepths(colorModel=colorModel) + + def changedColorDepthComboBox(self, colorDepth): + self.loadColorProfiles(colorDepth=colorDepth) + + def confirmButton(self): + selectedPaths = [item.text() for item in self.widgetDocuments.selectedItems()] + selectedDocuments = [document for document in self.documentsList for path in selectedPaths if path==document.fileName()] + + self.convertColorSpace(selectedDocuments) + + self.msgBox = QMessageBox(self.mainDialog) + self.msgBox.setText("The selected documents has been converted.") + self.msgBox.exec_() + + + def convertColorSpace(self, documents): + for document in documents: + document.setColorSpace(self.colorModelComboBox.currentText(), + self.colorDepthComboBox.currentText(), + self.colorProfileComboBox.currentText()) diff --git a/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py b/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py --- a/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py +++ b/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py @@ -5,7 +5,7 @@ from . import docwrapper import os from scripter import resources_rc -import importlib.util +import importlib class RunAction(QAction): diff --git a/plugins/extensions/pykrita/sip/krita/Krita.sip b/plugins/extensions/pykrita/sip/krita/Krita.sip --- a/plugins/extensions/pykrita/sip/krita/Krita.sip +++ b/plugins/extensions/pykrita/sip/krita/Krita.sip @@ -17,6 +17,8 @@ QList documents() const /Factory/; QStringList filters() const; Filter * filter(const QString &name) const /Factory/; + QStringList colorModels() const; + QStringList colorDepths(const QString &colorModel) const; QStringList profiles(const QString &colorModel, const QString &ColorDepth) const; bool addProfile(const QString &profilePath); Notifier * notifier() const;