Warning, file /graphics/glaxnimate/src/gui/widgets/view_transform_widget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "view_transform_widget.hpp" 0008 #include "ui_view_transform_widget.h" 0009 #include <QEvent> 0010 #include <QtMath> 0011 0012 using namespace glaxnimate::gui; 0013 0014 ViewTransformWidget::ViewTransformWidget(QWidget* parent) 0015 : QWidget(parent), d(std::make_unique<Ui::ViewTransformWidget>()) 0016 { 0017 d->setupUi(this); 0018 connect(d->btn_angle_reset, &QAbstractButton::clicked, [this](){ 0019 d->spin_angle->setValue(0); 0020 }); 0021 connect(d->btn_zoom_reset, &QAbstractButton::clicked, [this](){ 0022 d->spin_zoom->setValue(100); 0023 }); 0024 connect(d->btn_zoom_in, &QAbstractButton::clicked, this, &ViewTransformWidget::zoom_in); 0025 connect(d->btn_zoom_out, &QAbstractButton::clicked, this, &ViewTransformWidget::zoom_out); 0026 using func = void (QDoubleSpinBox::*)(qreal); 0027 connect(d->spin_angle, (func)&QDoubleSpinBox::valueChanged, this, &ViewTransformWidget::fuckyoumoc_on_angle_changed); 0028 connect(d->spin_zoom, (func)&QDoubleSpinBox::valueChanged, this, &ViewTransformWidget::fuckyoumoc_on_zoom_changed); 0029 connect(d->btn_view_fit, &QAbstractButton::clicked, this, &ViewTransformWidget::view_fit); 0030 connect(d->btn_flip_view, &QAbstractButton::clicked, this, &ViewTransformWidget::flip_view); 0031 0032 #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) 0033 d->spin_zoom->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType); 0034 #endif 0035 0036 } 0037 0038 ViewTransformWidget::~ViewTransformWidget() = default; 0039 0040 void ViewTransformWidget::changeEvent(QEvent* e) 0041 { 0042 0043 QWidget::changeEvent(e); 0044 switch ( e->type() ) 0045 { 0046 case QEvent::LanguageChange: 0047 d->retranslateUi(this); 0048 break; 0049 default: 0050 break; 0051 } 0052 } 0053 0054 void ViewTransformWidget::set_angle(qreal radians) 0055 { 0056 bool block = d->spin_angle->blockSignals(true); 0057 d->spin_angle->setValue(qRadiansToDegrees(radians)); 0058 d->spin_angle->blockSignals(block); 0059 } 0060 0061 void ViewTransformWidget::set_zoom(qreal percent) 0062 { 0063 bool block = d->spin_zoom->blockSignals(true); 0064 d->spin_zoom->setValue(percent*100); 0065 d->spin_zoom->blockSignals(block); 0066 } 0067 0068 void ViewTransformWidget::fuckyoumoc_on_angle_changed(qreal degrees) 0069 { 0070 Q_EMIT angle_changed(qDegreesToRadians(degrees)); 0071 } 0072 0073 void ViewTransformWidget::fuckyoumoc_on_zoom_changed(qreal percent) 0074 { 0075 Q_EMIT zoom_changed(percent/100); 0076 } 0077 0078 void ViewTransformWidget::set_flip(bool flipped) 0079 { 0080 d->btn_flip_view->setChecked(flipped); 0081 }