File indexing completed on 2024-12-22 04:15:07
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Lukáš Tvrdý <lukast.dev@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "dlg_offsetimage.h" 0008 0009 #include <klocalizedstring.h> 0010 #include <kis_debug.h> 0011 #include <kis_config.h> 0012 0013 #include "kis_document_aware_spin_box_unit_manager.h" 0014 0015 const QString DlgOffsetImage::PARAM_PREFIX = "imageoffsetdlg"; 0016 const QString DlgOffsetImage::PARAM_XOFFSET_UNIT = DlgOffsetImage::PARAM_PREFIX + "_xoffsetunit"; 0017 const QString DlgOffsetImage::PARAM_YOFFSET_UNIT = DlgOffsetImage::PARAM_PREFIX + "_yoffsetunit"; 0018 0019 DlgOffsetImage::DlgOffsetImage(QWidget * parent, const char * name, QSize imageSize) 0020 : KoDialog(parent), 0021 m_offsetSize(imageSize) 0022 { 0023 setCaption("BUG: No sane caption is set"); 0024 setButtons(Ok | Cancel); 0025 setDefaultButton(Ok); 0026 setObjectName(name); 0027 0028 0029 m_lock = false; 0030 0031 m_page = new WdgOffsetImage(this); 0032 Q_CHECK_PTR(m_page); 0033 m_page->setObjectName("offset_image"); 0034 0035 setMainWidget(m_page); 0036 resize(m_page->sizeHint()); 0037 0038 _widthUnitManager = new KisDocumentAwareSpinBoxUnitManager(this); 0039 _heightUnitManager = new KisDocumentAwareSpinBoxUnitManager(this, KisDocumentAwareSpinBoxUnitManager::PIX_DIR_Y); 0040 0041 _widthUnitManager->setApparentUnitFromSymbol("px"); 0042 _heightUnitManager->setApparentUnitFromSymbol("px"); 0043 0044 m_page->offsetXdoubleSpinBox->setUnitManager(_widthUnitManager); 0045 m_page->offsetYdoubleSpinBox->setUnitManager(_heightUnitManager); 0046 m_page->offsetXdoubleSpinBox->setDecimals(2); 0047 m_page->offsetYdoubleSpinBox->setDecimals(2); 0048 m_page->offsetXdoubleSpinBox->setDisplayUnit(false); 0049 m_page->offsetYdoubleSpinBox->setDisplayUnit(false); 0050 0051 m_page->offsetXdoubleSpinBox->setReturnUnit("px"); 0052 m_page->offsetYdoubleSpinBox->setReturnUnit("px"); 0053 0054 m_page->unitXComboBox->setModel(_widthUnitManager); 0055 m_page->unitYComboBox->setModel(_heightUnitManager); 0056 0057 KisConfig cfg(true); 0058 0059 QString unitx = cfg.readEntry<QString>(PARAM_XOFFSET_UNIT, "px"); 0060 QString unity = cfg.readEntry<QString>(PARAM_YOFFSET_UNIT, "px"); 0061 0062 _widthUnitManager->setApparentUnitFromSymbol(unitx); 0063 _heightUnitManager->setApparentUnitFromSymbol(unity); 0064 0065 const int xUnitIndex = _widthUnitManager->getsUnitSymbolList().indexOf(unitx); 0066 const int yUnitIndex = _heightUnitManager->getsUnitSymbolList().indexOf(unity); 0067 0068 m_page->unitXComboBox->setCurrentIndex(xUnitIndex); 0069 m_page->unitYComboBox->setCurrentIndex(yUnitIndex); 0070 0071 connect(this, SIGNAL(okClicked()),this, SLOT(okClicked())); 0072 connect(m_page->middleOffsetBtn, SIGNAL(clicked()), this, SLOT(slotMiddleOffset())); 0073 connect(m_page->offsetXdoubleSpinBox, SIGNAL(valueChangedPt(double)), this, SLOT(slotOffsetXChanged(double))); 0074 connect(m_page->offsetYdoubleSpinBox, SIGNAL(valueChangedPt(double)), this, SLOT(slotOffsetYChanged(double))); 0075 0076 connect(m_page->unitXComboBox, SIGNAL(currentIndexChanged(int)), _widthUnitManager, SLOT(selectApparentUnitFromIndex(int))); 0077 connect(m_page->unitYComboBox, SIGNAL(currentIndexChanged(int)), _heightUnitManager, SLOT(selectApparentUnitFromIndex(int))); 0078 connect(_widthUnitManager, SIGNAL(unitChanged(int)), m_page->unitXComboBox, SLOT(setCurrentIndex(int))); 0079 connect(_heightUnitManager, SIGNAL(unitChanged(int)), m_page->unitYComboBox, SLOT(setCurrentIndex(int))); 0080 0081 slotMiddleOffset(); 0082 } 0083 0084 DlgOffsetImage::~DlgOffsetImage() 0085 { 0086 KisConfig cfg(false); 0087 0088 cfg.writeEntry<QString>(PARAM_XOFFSET_UNIT, _widthUnitManager->getApparentUnitSymbol()); 0089 cfg.writeEntry<QString>(PARAM_YOFFSET_UNIT, _heightUnitManager->getApparentUnitSymbol()); 0090 0091 delete m_page; 0092 } 0093 0094 void DlgOffsetImage::slotOffsetXChanged(double newOffsetX) 0095 { 0096 m_offsetX = qRound(newOffsetX); 0097 } 0098 0099 void DlgOffsetImage::slotOffsetYChanged(double newOffsetY) 0100 { 0101 m_offsetY = qRound(newOffsetY); 0102 } 0103 0104 void DlgOffsetImage::slotMiddleOffset() 0105 { 0106 int offsetX = m_offsetSize.width() / 2; 0107 int offsetY = m_offsetSize.height() / 2; 0108 m_page->offsetXdoubleSpinBox->changeValue(offsetX); 0109 m_page->offsetYdoubleSpinBox->changeValue(offsetY); 0110 } 0111 0112 void DlgOffsetImage::okClicked() 0113 { 0114 accept(); 0115 } 0116 0117