All Classes Namespaces Functions Variables Enumerations Properties Pages
toolspage.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 
18 #include "toolspage.h"
19 
20 #include <QtMath>
21 
22 #include "preferencemanager.h"
23 
24 #include "ui_toolspage.h"
25 
26 ToolsPage::ToolsPage() : ui(new Ui::ToolsPage)
27 {
28  ui->setupUi(this);
29 
30  connect(ui->useQuickSizingBox, &QCheckBox::stateChanged, this, &ToolsPage::quickSizingChange);
31  connect(ui->rotationIncrementSlider, &QSlider::valueChanged, this, &ToolsPage::rotationIncrementChange);
32 }
33 
34 ToolsPage::~ToolsPage()
35 {
36  delete ui;
37 }
38 
39 void ToolsPage::updateValues()
40 {
41  ui->useQuickSizingBox->setChecked(mManager->isOn(SETTING::QUICK_SIZING));
42  setRotationIncrement(mManager->getInt(SETTING::ROTATION_INCREMENT));
43 }
44 
45 void ToolsPage::quickSizingChange(int b)
46 {
47  mManager->set(SETTING::QUICK_SIZING, b != Qt::Unchecked);
48 }
49 
50 void ToolsPage::setRotationIncrement(int angle)
51 {
52  int value = qSqrt((angle - 1) / 359.0) * 359;
53  ui->rotationIncrementSlider->setValue(value);
54 }
55 
56 void ToolsPage::rotationIncrementChange(int value)
57 {
58  // Use log scale
59  int angle = qPow(value / 359.0, 2) * 359 + 1;
60  // Basically round up to the nearest number that is a divisor of 360
61  while (360 % angle != 0) {
62  angle++;
63  }
64  ui->rotationIncrementDisplay->setText(tr("%1 degrees").arg(angle)); // don't use tr()'s plural settings, it breaks Transifex.
65  mManager->set(SETTING::ROTATION_INCREMENT, angle);
66 }
QString tr(const char *sourceText, const char *disambiguation, int n)
void stateChanged(int state)
void valueChanged(int value)
Unchecked
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)