File: colorsettingspage.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 (167 lines) | stat: -rw-r--r-- 4,426 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**************************************************************************
* 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 "colorsettingspage.h"

#include <QColorDialog>
#include <QMessageBox>

#include "fractalmodel.h"
#include "gradientdialog.h"
#include "loadpresetdialog.h"
#include "savepresetdialog.h"
#include "datafunctions.h"

ColorSettingsPage::ColorSettingsPage( QWidget* parent ) : QWidget( parent ),
    m_model( NULL )
{
    m_ui.setupUi( this );

    m_ui.sliderScale->setScaledRange( 0.02, 0.2 );
    m_ui.sliderOffset->setScaledRange( 0.0, 1.0 );
}

ColorSettingsPage::~ColorSettingsPage()
{
}

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

    connect( model, SIGNAL( gradientChanged() ), this, SLOT( gradientChanged() ) );
    connect( model, SIGNAL( backgroundColorChanged() ), this, SLOT( backgroundColorChanged() ) );
    connect( model, SIGNAL( colorMappingChanged() ), this, SLOT( colorMappingChanged() ) );
}

void ColorSettingsPage::on_buttonBackground_clicked()
{
    QColor color = QColorDialog::getColor( m_model->backgroundColor(), this );
    if ( color.isValid() )
        m_model->setBackgroundColor( color );
}

void ColorSettingsPage::on_buttonGradient_clicked()
{
    GradientDialog dialog( this );
    dialog.setGradient( m_model->gradient() );

    connect( &dialog, SIGNAL( applyGradient( const Gradient& ) ), this, SLOT( applyGradient( const Gradient& ) ) );

    dialog.exec();
}

void ColorSettingsPage::applyGradient( const Gradient& gradient )
{
    m_model->setGradient( gradient );
}

void ColorSettingsPage::on_sliderScale_valueChanged()
{
    saveMapping();
}

void ColorSettingsPage::on_sliderOffset_valueChanged()
{
    saveMapping();
}

void ColorSettingsPage::on_checkMirrored_toggled()
{
    saveMapping();
}

void ColorSettingsPage::on_checkReversed_toggled()
{
    saveMapping();
}

void ColorSettingsPage::on_buttonRestore_clicked()
{
    m_model->loadDefaultColorSettings();
}

void ColorSettingsPage::on_buttonStore_clicked()
{
    if ( QMessageBox::warning( this, tr( "Warning" ), tr( "Are you sure you want to store current color settings\nas the default settings?" ),
        QMessageBox::Ok | QMessageBox::Cancel ) == QMessageBox::Ok ) {
        m_model->saveDefaultColorSettings();
        updateButtons();
    }
}

void ColorSettingsPage::on_buttonLoad_clicked()
{
    LoadPresetDialog dialog( this );
    dialog.setModel( m_model );
    dialog.exec();
}

void ColorSettingsPage::on_buttonSave_clicked()
{
    SavePresetDialog dialog( this );
    dialog.setModel( m_model );
    dialog.exec();
}

void ColorSettingsPage::gradientChanged()
{
    loadGradient();
    updateButtons();
}

void ColorSettingsPage::backgroundColorChanged()
{
    loadBackground();
    updateButtons();
}

void ColorSettingsPage::colorMappingChanged()
{
    loadMapping();
    updateButtons();
}

void ColorSettingsPage::loadBackground()
{
    m_ui.widgetBackground->setBackgroundColor( m_model->backgroundColor() );
}

void ColorSettingsPage::loadGradient()
{
    QGradientStops stops = DataFunctions::calculateGradientStops( m_model->gradient() );
    m_ui.widgetGradient->setGradientStops( stops );
}

void ColorSettingsPage::loadMapping()
{
    ColorMapping mapping = m_model->colorMapping();
    m_ui.sliderScale->setScaledValue( mapping.scale() );
    m_ui.sliderOffset->setScaledValue( mapping.offset() );
    m_ui.checkMirrored->setChecked( mapping.isMirrored() );
    m_ui.checkReversed->setChecked( mapping.isReversed() );
}

void ColorSettingsPage::saveMapping()
{
    ColorMapping mapping;
    mapping.setScale( m_ui.sliderScale->scaledValue() );
    mapping.setOffset( m_ui.sliderOffset->scaledValue() );
    mapping.setMirrored( m_ui.checkMirrored->isChecked() );
    mapping.setReversed( m_ui.checkReversed->isChecked() );
    m_model->setColorMapping( mapping );
}

void ColorSettingsPage::updateButtons()
{
    bool enabled = !m_model->hasDefaultColorSettings();
    m_ui.buttonRestore->setEnabled( enabled );
    m_ui.buttonStore->setEnabled( enabled );
}