944 def openDialogOptions(self):
945 """Open dialog box to let user define channel extraction options"""
946
947 tmpDocument = None
948 previewBaSrc = QByteArray()
949 lblPreview = [QLabel(), QLabel(), QLabel(), QLabel()]
950 lblPreviewLbl = [QLabel(), QLabel(), QLabel(), QLabel()]
951
952
953
954
955 @pyqtSlot('QString')
956 def ledLayerGroupName_Changed(value):
957 self.__outputOptions['layerGroupName'] = value
958
959 @pyqtSlot('QString')
960 def ledLayerColorName_Changed(value):
961 self.__outputOptions['layerColorName'] = value
962
963 @pyqtSlot('QString')
964 def cmbOutputMode_Changed(value):
965 self.__outputOptions['outputMode'] = value
966 buildPreview()
967
968 @pyqtSlot('QString')
969 def cmbOriginalLayerAction_Changed(value):
970 self.__outputOptions['originalLayerAction'] = value
971
972 def buildPreview():
973 pbProgress.setVisible(True)
974
975 backupValue = self.__outputOptions['layerColorName']
976 self.__outputOptions['layerColorName'] = '{color:long}'
977
978
979 tmpDocument = Application.createDocument(imgThumbSrc.width(), imgThumbSrc.height(), "tmp", "RGBA", "U8", "", 120.0)
980
981
982 originalLayer = tmpDocument.createNode("Original", "paintlayer")
983 tmpDocument.rootNode().addChildNode(originalLayer, None)
984
985 originalLayer.setPixelData(previewBaSrc, 0, 0, tmpDocument.width(), tmpDocument.height())
986
987
988 groupLayer = self.process(tmpDocument, originalLayer, pbProgress)
989
990 self.__outputOptions['layerColorName'] = backupValue
991
992 originalLayer.setVisible(False)
993 groupLayer.setVisible(True)
994
995 for layer in groupLayer.childNodes():
996 layer.setBlendingMode('normal')
997 layer.setVisible(False)
998 tmpDocument.refreshProjection()
999
1000 index = 0
1001 for layer in groupLayer.childNodes():
1002 layer.setVisible(True)
1003 tmpDocument.refreshProjection()
1004
1005 lblPreview[index].setPixmap(QPixmap.fromImage(tmpDocument.projection(0, 0, tmpDocument.width(), tmpDocument.height())))
1006 lblPreviewLbl[index].setText("<i>{0}</i>".format(layer.name()))
1007 layer.setVisible(False)
1008
1009 index+=1
1010
1011 if index > 3:
1012 lblPreview[3].setVisible(True)
1013 lblPreviewLbl[3].setVisible(True)
1014 else:
1015 lblPreview[3].setVisible(False)
1016 lblPreviewLbl[3].setVisible(False)
1017
1018
1019 tmpDocument.close()
1020
1021 pbProgress.setVisible(False)
1022
1023
1024
1025
1026 dlgMain = QDialog(Application.activeWindow().qwindow())
1027 dlgMain.setWindowTitle(PLUGIN_DIALOG_TITLE)
1028
1029 dlgMain.setSizeGripEnabled(True)
1030 dlgMain.setMinimumSize(DOPT_MIN_WIDTH, DOPT_MIN_HEIGHT)
1031 dlgMain.setModal(True)
1032
1033
1034
1035 vbxMainContainer = QVBoxLayout(dlgMain)
1036
1037
1038 lblLayerName = QLabel("{0} <b><i>{1}</i></b>".format(i18n("Processing layer"), self.__sourceLayer.name()))
1039 lblLayerName.setFixedHeight(30)
1040 vbxMainContainer.addWidget(lblLayerName)
1041
1042
1043 gbxLayersMgt = QGroupBox("Layers management")
1044 vbxMainContainer.addWidget(gbxLayersMgt)
1045
1046
1047 gbxOutputResults = QGroupBox("Output results")
1048 vbxMainContainer.addWidget(gbxOutputResults)
1049
1050 vbxMainContainer.addStretch()
1051
1052
1053 dbbxOkCancel = QDialogButtonBox(dlgMain)
1054 dbbxOkCancel.setOrientation(Qt.Orientation.Horizontal)
1055 dbbxOkCancel.setStandardButtons(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
1056 dbbxOkCancel.accepted.connect(dlgMain.accept)
1057 dbbxOkCancel.rejected.connect(dlgMain.reject)
1058 vbxMainContainer.addWidget(dbbxOkCancel)
1059
1060
1061
1062 flLayersMgt = QFormLayout()
1063 gbxLayersMgt.setLayout(flLayersMgt)
1064
1065 ledLayerGroupName = QLineEdit()
1066 ledLayerGroupName.setText(self.__outputOptions['layerGroupName'])
1067 ledLayerGroupName.textChanged.connect(ledLayerGroupName_Changed)
1068 flLayersMgt.addRow(i18nc('The name for a new group layer; the generated layers will be placed in this group.', 'New layer group name'), ledLayerGroupName)
1069
1070 ledLayerColorName = QLineEdit()
1071 ledLayerColorName.setText(self.__outputOptions['layerColorName'])
1072 ledLayerColorName.textChanged.connect(ledLayerColorName_Changed)
1073 flLayersMgt.addRow(i18nc('Defines how the name for each layer created from the channel is generated.', 'New layers color name'), ledLayerColorName)
1074
1075 cmbOriginalLayerAction = QComboBox()
1076 cmbOriginalLayerAction.addItems([
1077 ORIGINAL_LAYER_KEEPUNCHANGED,
1078 ORIGINAL_LAYER_KEEPVISIBLE,
1079 ORIGINAL_LAYER_KEEPHIDDEN,
1080 ORIGINAL_LAYER_REMOVE
1081 ])
1082 cmbOriginalLayerAction.setCurrentText(self.__outputOptions['originalLayerAction'])
1083 cmbOriginalLayerAction.currentTextChanged.connect(cmbOriginalLayerAction_Changed)
1084 flLayersMgt.addRow(i18n("Original layer"), cmbOriginalLayerAction)
1085
1086
1087
1088 flOutputResults = QFormLayout()
1089 gbxOutputResults.setLayout(flOutputResults)
1090
1091 cmbOutputMode = QComboBox()
1092 cmbOutputMode.addItems([
1093 OUTPUT_MODE_RGB,
1094 OUTPUT_MODE_CMY,
1095 OUTPUT_MODE_CMYK,
1096 OUTPUT_MODE_LRGB,
1097 OUTPUT_MODE_LCMY,
1098 OUTPUT_MODE_LCMYK
1099 ])
1100 cmbOutputMode.setCurrentText(self.__outputOptions['outputMode'])
1101 cmbOutputMode.currentTextChanged.connect(cmbOutputMode_Changed)
1102 flOutputResults.addRow(i18n("Mode"), cmbOutputMode)
1103
1104 vbxPreviewLblContainer = QHBoxLayout()
1105 flOutputResults.addRow('', vbxPreviewLblContainer)
1106 vbxPreviewContainer = QHBoxLayout()
1107 flOutputResults.addRow('', vbxPreviewContainer)
1108
1109
1110 pbProgress = QProgressBar()
1111 pbProgress.setFixedHeight(8)
1112 pbProgress.setTextVisible(False)
1113 pbProgress.setVisible(False)
1114 pbProgress.setRange(0, 107)
1115 flOutputResults.addRow('', pbProgress)
1116
1117
1118 imageRatio = self.__sourceDocument.width() / self.__sourceDocument.height()
1119 rect = QRect(0, 0, OUTPUT_PREVIEW_MAXSIZE, OUTPUT_PREVIEW_MAXSIZE)
1120
1121
1122 if imageRatio < 1:
1123
1124 rect.setWidth(int(imageRatio * OUTPUT_PREVIEW_MAXSIZE))
1125 else:
1126
1127 rect.setHeight(int(OUTPUT_PREVIEW_MAXSIZE / imageRatio))
1128
1129 imgThumbSrc = self.toQImage(self.__sourceLayer, rect)
1130
1131 previewBaSrc.resize(imgThumbSrc.sizeInBytes())
1132 ptr = imgThumbSrc.bits()
1133 ptr.setsize(imgThumbSrc.sizeInBytes())
1134 previewBaSrc = QByteArray(ptr.asstring())
1135
1136
1137 lblPreviewSrc = QLabel()
1138 lblPreviewSrc.setPixmap(QPixmap.fromImage(imgThumbSrc))
1139 lblPreviewSrc.setFixedHeight(imgThumbSrc.height() + 4)
1140 lblPreviewSrc.setFixedWidth(imgThumbSrc.width() + 4)
1141 vbxPreviewContainer.addWidget(lblPreviewSrc)
1142
1143 lblPreviewLblSrc = QLabel(i18nc("the original layer", "Original"))
1144 lblPreviewLblSrc.setFixedWidth(imgThumbSrc.width() + 4)
1145 vbxPreviewLblContainer.addWidget(lblPreviewLblSrc)
1146
1147
1148 vbxPreviewLblContainer.addWidget(QLabel(" "))
1149 vbxPreviewContainer.addWidget(QLabel(">"))
1150
1151 lblPreview[3].setPixmap(QPixmap.fromImage(imgThumbSrc))
1152 lblPreview[3].setFixedHeight(imgThumbSrc.height() + 4)
1153 lblPreview[3].setFixedWidth(imgThumbSrc.width() + 4)
1154 vbxPreviewContainer.addWidget(lblPreview[3])
1155
1156 lblPreviewLbl[3] = QLabel(i18n("<i>Cyan</i>"))
1157 lblPreviewLbl[3].setIndent(10)
1158 lblPreviewLbl[3].setFixedWidth(imgThumbSrc.width() + 4)
1159 vbxPreviewLblContainer.addWidget(lblPreviewLbl[3])
1160
1161
1162 lblPreview[2] = QLabel()
1163 lblPreview[2].setPixmap(QPixmap.fromImage(imgThumbSrc))
1164 lblPreview[2].setFixedHeight(imgThumbSrc.height() + 4)
1165 lblPreview[2].setFixedWidth(imgThumbSrc.width() + 4)
1166 vbxPreviewContainer.addWidget(lblPreview[2])
1167
1168 lblPreviewLbl[2] = QLabel(i18n("<i>Magenta</i>"))
1169 lblPreviewLbl[2].setIndent(10)
1170 lblPreviewLbl[2].setFixedWidth(imgThumbSrc.width() + 4)
1171 vbxPreviewLblContainer.addWidget(lblPreviewLbl[2])
1172
1173
1174 lblPreview[1] = QLabel()
1175 lblPreview[1].setPixmap(QPixmap.fromImage(imgThumbSrc))
1176 lblPreview[1].setFixedHeight(imgThumbSrc.height() + 4)
1177 lblPreview[1].setFixedWidth(imgThumbSrc.width() + 4)
1178 vbxPreviewContainer.addWidget(lblPreview[1])
1179
1180 lblPreviewLbl[1] = QLabel(i18n("<i>Yellow</i>"))
1181 lblPreviewLbl[1].setIndent(10)
1182 lblPreviewLbl[1].setFixedWidth(imgThumbSrc.width() + 4)
1183 vbxPreviewLblContainer.addWidget(lblPreviewLbl[1])
1184
1185
1186 lblPreview[0] = QLabel()
1187 lblPreview[0].setPixmap(QPixmap.fromImage(imgThumbSrc))
1188 lblPreview[0].setFixedHeight(imgThumbSrc.height() + 4)
1189 lblPreview[0].setFixedWidth(imgThumbSrc.width() + 4)
1190 vbxPreviewContainer.addWidget(lblPreview[0])
1191
1192 lblPreviewLbl[0] = QLabel(i18n("<i>Black</i>"))
1193 lblPreviewLbl[0].setIndent(10)
1194 lblPreviewLbl[0].setFixedWidth(imgThumbSrc.width() + 4)
1195 vbxPreviewLblContainer.addWidget(lblPreviewLbl[0])
1196
1197
1198 vbxPreviewLblContainer.addStretch()
1199 vbxPreviewContainer.addStretch()
1200
1201 buildPreview()
1202
1203 returned = dlgMain.exec()
1204
1205 return returned
1206
1207