File indexing completed on 2024-12-22 04:16:47
0001 /* 0002 SPDX-FileCopyrightText: 2012 Dan Leinir Turthra Jensen <admin@leinir.dk> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 0008 #include "kistoolcropconfigwidget.h" 0009 #include "kis_tool_crop.h" 0010 #include <kis_icon.h> 0011 #include <kis_acyclic_signal_connector.h> 0012 #include <QStandardItemModel> 0013 0014 0015 KisToolCropConfigWidget::KisToolCropConfigWidget(QWidget* parent, KisToolCrop* cropTool) 0016 : QWidget(parent) 0017 , m_cropTool(cropTool) 0018 { 0019 setupUi(this); 0020 0021 // update the UI based off data from crop tool 0022 cmbType->setCurrentIndex(m_cropTool->cropType()); 0023 QStandardItemModel *cmbTypeModel = qobject_cast<QStandardItemModel *>(cmbType->model()); 0024 // Disable "Layer" 0025 cmbTypeModel->item(2)->setEnabled(m_cropTool->cropTypeSelectable()); 0026 // Disable "Frame" 0027 cmbTypeModel->item(3)->setEnabled(m_cropTool->cropTypeSelectable()); 0028 0029 intHeight->setValue(m_cropTool->cropHeight()); 0030 intWidth->setValue(m_cropTool->cropWidth()); 0031 intX->setValue(m_cropTool->cropX()); 0032 intY->setValue(m_cropTool->cropY()); 0033 doubleRatio->setValue(m_cropTool->ratio()); 0034 cmbDecor->setCurrentIndex(m_cropTool->decoration()); 0035 boolGrow->setChecked(m_cropTool->allowGrow()); 0036 boolCenter->setChecked(m_cropTool->growCenter()); 0037 0038 lockRatioButton->setChecked(m_cropTool->lockRatio()); 0039 lockHeightButton->setChecked(m_cropTool->lockHeight()); 0040 lockWidthButton->setChecked(m_cropTool->lockWidth()); 0041 0042 QIcon lockedIcon = KisIconUtils::loadIcon("locked"); 0043 QIcon unlockedIcon = KisIconUtils::loadIcon("unlocked"); 0044 lockWidthButton->setIcon(lockWidthButton->isChecked() ? lockedIcon : unlockedIcon); 0045 lockHeightButton->setIcon(lockHeightButton->isChecked() ? lockedIcon : unlockedIcon); 0046 lockRatioButton->setIcon(lockRatioButton->isChecked() ? lockedIcon : unlockedIcon); 0047 0048 KisAcyclicSignalConnector *connector; 0049 connector = new KisAcyclicSignalConnector(this); 0050 connector->connectForwardBool(lockRatioButton, SIGNAL(toggled(bool)), this, SIGNAL(lockRatioChanged(bool))); 0051 connector->connectBackwardBool(cropTool, SIGNAL(lockRatioChanged(bool)), lockRatioButton, SLOT(setChecked(bool))); 0052 0053 connector = new KisAcyclicSignalConnector(this); 0054 connector->connectForwardBool(lockHeightButton, SIGNAL(toggled(bool)), this, SIGNAL(lockHeightChanged(bool))); 0055 connector->connectBackwardBool(cropTool, SIGNAL(lockHeightChanged(bool)), lockHeightButton, SLOT(setChecked(bool))); 0056 0057 connector = new KisAcyclicSignalConnector(this); 0058 connector->connectForwardBool(lockWidthButton, SIGNAL(toggled(bool)), this, SIGNAL(lockWidthChanged(bool))); 0059 connector->connectBackwardBool(cropTool, SIGNAL(lockWidthChanged(bool)), lockWidthButton, SLOT(setChecked(bool))); 0060 0061 connector = new KisAcyclicSignalConnector(this); 0062 connector->connectForwardDouble(doubleRatio, SIGNAL(valueChanged(double)), this, SIGNAL(ratioChanged(double))); 0063 connector->connectBackwardDouble(cropTool, SIGNAL(ratioChanged(double)), doubleRatio, SLOT(setValue(double))); 0064 0065 connector = new KisAcyclicSignalConnector(this); 0066 connector->connectForwardInt(intHeight, SIGNAL(valueChanged(int)), this, SIGNAL(cropHeightChanged(int))); 0067 connector->connectBackwardInt(cropTool, SIGNAL(cropHeightChanged(int)), intHeight, SLOT(setValue(int))); 0068 0069 connector = new KisAcyclicSignalConnector(this); 0070 connector->connectForwardInt(intWidth, SIGNAL(valueChanged(int)), this, SIGNAL(cropWidthChanged(int))); 0071 connector->connectBackwardInt(cropTool, SIGNAL(cropWidthChanged(int)), intWidth, SLOT(setValue(int))); 0072 0073 connector = new KisAcyclicSignalConnector(this); 0074 connector->connectForwardInt(intX, SIGNAL(valueChanged(int)), this, SIGNAL(cropXChanged(int))); 0075 connector->connectBackwardInt(cropTool, SIGNAL(cropXChanged(int)), intX, SLOT(setValue(int))); 0076 0077 connector = new KisAcyclicSignalConnector(this); 0078 connector->connectForwardInt(intY, SIGNAL(valueChanged(int)), this, SIGNAL(cropYChanged(int))); 0079 connector->connectBackwardInt(cropTool, SIGNAL(cropYChanged(int)), intY, SLOT(setValue(int))); 0080 0081 connector = new KisAcyclicSignalConnector(this); 0082 connector->connectForwardInt(cmbType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(cropTypeChanged(int))); 0083 connector->connectBackwardInt(cropTool, SIGNAL(cropTypeChanged(int)), cmbType, SLOT(setCurrentIndex(int))); 0084 0085 connector = new KisAcyclicSignalConnector(this); 0086 connector->connectForwardInt(cmbDecor, SIGNAL(currentIndexChanged(int)), this, SIGNAL(decorationChanged(int))); 0087 connector->connectBackwardInt(cropTool, SIGNAL(decorationChanged(int)), cmbDecor, SLOT(setCurrentIndex(int))); 0088 0089 connector = new KisAcyclicSignalConnector(this); 0090 connector->connectForwardBool(boolGrow, SIGNAL(toggled(bool)), this, SIGNAL(allowGrowChanged(bool))); 0091 connector->connectBackwardBool(cropTool, SIGNAL(canGrowChanged(bool)), boolGrow, SLOT(setChecked(bool))); 0092 0093 connector = new KisAcyclicSignalConnector(this); 0094 connector->connectForwardBool(boolCenter, SIGNAL(toggled(bool)), this, SIGNAL(growCenterChanged(bool))); 0095 connector->connectBackwardBool(cropTool, SIGNAL(isCenteredChanged(bool)), boolCenter, SLOT(setChecked(bool))); 0096 0097 connector = new KisAcyclicSignalConnector(this); 0098 //connector->connectForwardDouble(); 0099 connector->connectBackwardVoid(cropTool, SIGNAL(cropTypeSelectableChanged()), this, SLOT(cropTypeSelectableChanged())); 0100 0101 connect(lockWidthButton, SIGNAL(toggled(bool)), this, SLOT(updateLockWidthIcon())); 0102 connect(lockHeightButton, SIGNAL(toggled(bool)), this, SLOT(updateLockHeightIcon())); 0103 connect(lockRatioButton, SIGNAL(toggled(bool)), this, SLOT(updateLockRatioIcon())); 0104 0105 } 0106 0107 void KisToolCropConfigWidget::cropTypeSelectableChanged() 0108 { 0109 QStandardItemModel *cmbTypeModel = qobject_cast<QStandardItemModel *>(cmbType->model()); 0110 // Disable "Layer" 0111 cmbTypeModel->item(2)->setEnabled(m_cropTool->cropTypeSelectable()); 0112 // Disable "Frame" 0113 cmbTypeModel->item(3)->setEnabled(m_cropTool->cropTypeSelectable()); 0114 } 0115 0116 void KisToolCropConfigWidget::updateLockRatioIcon() 0117 { 0118 lockRatioButton->setIcon(lockRatioButton->isChecked() ? KisIconUtils::loadIcon("locked") : KisIconUtils::loadIcon("unlocked")); 0119 } 0120 0121 void KisToolCropConfigWidget::updateLockWidthIcon() 0122 { 0123 lockWidthButton->setIcon(lockWidthButton->isChecked() ? KisIconUtils::loadIcon("locked") : KisIconUtils::loadIcon("unlocked")); 0124 } 0125 0126 void KisToolCropConfigWidget::updateLockHeightIcon() 0127 { 0128 lockHeightButton->setIcon(lockHeightButton->isChecked() ? KisIconUtils::loadIcon("locked") : KisIconUtils::loadIcon("unlocked")); 0129 }