File indexing completed on 2024-12-22 04:15:12
0001 /* 0002 * dlg_rotateimage.cc - part of KimageShop^WKrayon^WKrita 0003 * 0004 * SPDX-FileCopyrightText: 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "dlg_rotateimage.h" 0010 0011 #include <math.h> 0012 0013 #include <klocalizedstring.h> 0014 #include <kis_debug.h> 0015 #include <kis_icon.h> 0016 0017 DlgRotateImage::DlgRotateImage(QWidget * parent, 0018 const char * name) 0019 : KoDialog(parent) 0020 { 0021 setCaption(i18n("Rotate Image")); 0022 setButtons(Ok | Cancel); 0023 setDefaultButton(Ok); 0024 setObjectName(name); 0025 0026 m_lock = false; 0027 0028 m_page = new WdgRotateImage(this); 0029 Q_CHECK_PTR(m_page); 0030 m_page->setObjectName("rotate_image"); 0031 0032 setMainWidget(m_page); 0033 resize(m_page->sizeHint()); 0034 0035 m_page->angleSelectorCustom->setIncreasingDirection(KisAngleGauge::IncreasingDirection_Clockwise); 0036 0037 m_page->radioCCW->setIcon(KisIconUtils::loadIcon("transform_icons_liquify_rotateCCW")); 0038 m_page->radioCW->setIcon(KisIconUtils::loadIcon("transform_icons_liquify_rotate")); 0039 0040 connect(this, SIGNAL(okClicked()), 0041 this, SLOT(okClicked())); 0042 connect(m_page->angleSelectorCustom, SIGNAL(angleChanged(double)), 0043 this, SLOT(slotAngleValueChanged(double))); 0044 connect(m_page->radioCCW, SIGNAL(toggled(bool)), SLOT(slotRadioCCWToggled(bool))); 0045 connect(m_page->radioCW, SIGNAL(toggled(bool)), SLOT(slotRadioCWToggled(bool))); 0046 } 0047 0048 DlgRotateImage::~DlgRotateImage() 0049 { 0050 delete m_page; 0051 } 0052 0053 void DlgRotateImage::slotAngleValueChanged(double) 0054 { 0055 m_page->radioCustom->setChecked(true); 0056 } 0057 0058 void DlgRotateImage::setAngle(quint32 angle) 0059 { 0060 if (angle == 90) { 0061 m_page->radio90->setChecked(true); 0062 } else if (angle == 180) { 0063 m_page->radio180->setChecked(true); 0064 } else if (angle == 270) { 0065 m_page->radio270->setChecked(true); 0066 } else { 0067 m_page->radioCustom->setChecked(true); 0068 m_page->angleSelectorCustom->setAngle(angle); 0069 } 0070 0071 if (m_oldAngle != angle) 0072 resetPreview(); 0073 0074 m_oldAngle = angle; 0075 0076 } 0077 0078 double DlgRotateImage::angle() 0079 { 0080 double angle = 0; 0081 if (m_page->radio90->isChecked()) { 0082 angle = 90; 0083 } else if (m_page->radio180->isChecked()) { 0084 angle = 180; 0085 } else if (m_page->radio270->isChecked()) { 0086 angle = 270; 0087 } else { 0088 angle = m_page->angleSelectorCustom->angle(); 0089 } 0090 if (m_page->radioCW->isChecked()) { 0091 return angle; 0092 } else { 0093 return -angle; 0094 } 0095 } 0096 0097 void DlgRotateImage::setDirection(enumRotationDirection direction) 0098 { 0099 if (direction == CLOCKWISE) { 0100 m_page->radioCW->setChecked(true); 0101 } else if (direction == COUNTERCLOCKWISE) { 0102 m_page->radioCCW->setChecked(true); 0103 } 0104 } 0105 0106 enumRotationDirection DlgRotateImage::direction() 0107 { 0108 if (m_page->radioCCW->isChecked()) { 0109 return COUNTERCLOCKWISE; 0110 } else { 0111 return CLOCKWISE; 0112 } 0113 } 0114 0115 void DlgRotateImage::okClicked() 0116 { 0117 accept(); 0118 } 0119 0120 void DlgRotateImage::resetPreview() 0121 { 0122 // Code to update preview here. 0123 } 0124 0125 void DlgRotateImage::slotRadioCCWToggled(bool toggled) 0126 { 0127 if (!toggled) { 0128 return; 0129 } 0130 m_page->angleSelectorCustom->setIncreasingDirection(KisAngleGauge::IncreasingDirection_CounterClockwise); 0131 } 0132 0133 void DlgRotateImage::slotRadioCWToggled(bool toggled) 0134 { 0135 if (!toggled) { 0136 return; 0137 } 0138 m_page->angleSelectorCustom->setIncreasingDirection(KisAngleGauge::IncreasingDirection_Clockwise); 0139 }