File: animationpage.cpp

package info (click to toggle)
fraqtive 0.4.3-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 988 kB
  • ctags: 1,249
  • sloc: cpp: 8,387; sh: 103; makefile: 45
file content (121 lines) | stat: -rw-r--r-- 3,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**************************************************************************
* This file is part of the Fraqtive program
* Copyright (C) 2004-2008 Michał Męciński
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
**************************************************************************/

#include "animationpage.h"

#include "fractalmodel.h"

AnimationPage::AnimationPage( QWidget* parent ) : QWidget( parent ),
    m_model( NULL ),
    m_loading( false )
{
    m_ui.setupUi( this );

    m_ui.sliderScrolling->setScaledRange( -0.5, 0.5 );
    m_ui.sliderRotation->setScaledRange( -0.25, 0.25 );
}

AnimationPage::~AnimationPage()
{
}

void AnimationPage::setModel( FractalModel* model )
{
    m_model = model;

    connect( m_model, SIGNAL( animationSettingsChanged() ), this, SLOT( animationSettingsChanged() ) );
    connect( m_model, SIGNAL( viewModeChanged() ), this, SLOT( viewModeChanged() ) );
}

void AnimationPage::on_sliderScrolling_valueChanged()
{
    saveSettings();
    updateButtons();
}

void AnimationPage::on_sliderRotation_valueChanged()
{
    saveSettings();
    updateButtons();
}

void AnimationPage::on_stopScrolling_clicked()
{
    AnimationSettings settings = m_model->animationSettings();

    settings.setScrollingEnabled( false );
    settings.setScrollingSpeed( 0.0 );

    m_model->setAnimationSettings( settings );
}

void AnimationPage::on_stopRotation_clicked()
{
    AnimationSettings settings = m_model->animationSettings();

    settings.setRotationEnabled( false );
    settings.setRotationSpeed( 0.0 );

    m_model->setAnimationSettings( settings );
}

void AnimationPage::animationSettingsChanged()
{
    loadSettings();
}

void AnimationPage::viewModeChanged()
{
    m_ui.sliderRotation->setEnabled( m_model->viewMode() == MeshViewMode );

    updateButtons();
}

void AnimationPage::updateButtons()
{
    AnimationSettings settings = m_model->animationSettings();

    m_ui.stopScrolling->setEnabled( settings.isScrollingEnabled() );

    if ( m_model->viewMode() == MeshViewMode )
        m_ui.stopRotation->setEnabled( settings.isRotationEnabled() );
    else
        m_ui.stopRotation->setEnabled( false );
}

void AnimationPage::loadSettings()
{
    m_loading = true;

    AnimationSettings settings = m_model->animationSettings();

    m_ui.sliderScrolling->setScaledValue( settings.scrollingSpeed() );
    m_ui.sliderRotation->setScaledValue( settings.rotationSpeed() );

    m_loading = false;
}

void AnimationPage::saveSettings()
{
    if ( m_loading )
        return;

    AnimationSettings settings = m_model->animationSettings();

    settings.setScrollingSpeed( m_ui.sliderScrolling->scaledValue() );
    settings.setRotationSpeed( m_ui.sliderRotation->scaledValue() );

    if ( settings.scrollingSpeed() != 0.0 )
        settings.setScrollingEnabled( true );
    if ( settings.rotationSpeed() != 0.0 )
        settings.setRotationEnabled( true );

    m_model->setAnimationSettings( settings );
}