Subversion Repositories Scribus

Rev

Rev 17638 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17560 jainbasil 1
/*
2
 * Copyright (C) 2011 Jain Basil Aliyas <jainbasil@gmail.com>
3
 *
4
 * For general Scribus (>=1.3.2) copyright and licensing information please refer
5
 * to the COPYING file provided with the program. Following this notice may exist
6
 * a copyright and/or license notice that predates the release of Scribus 1.3.2
7
 * for which a new license (GPL+exception) is in place.
8
 */
9
 
10
#include "api_color.h"
11
#include "sccolorengine.h"
12
#include "scribusdoc.h"
13
#include "scribuscore.h"
14
#include "commonstrings.h"
15
#include "sccolor.h"
16
#include "utils.h"
17
 
17638 jainbasil 18
ColorAPI::ColorAPI(ScColor *l, QString n) : QObject(COLLECTOR)
17560 jainbasil 19
{
17638 jainbasil 20
    qDebug() << "ColorAPI loaded";
21
    setObjectName("ColorAPI");
17560 jainbasil 22
        color = l;
23
        colorName = n;
24
}
25
 
17638 jainbasil 26
QString ColorAPI::name()
17560 jainbasil 27
{
28
        return colorName;
29
}
30
 
17638 jainbasil 31
void ColorAPI::setName(QString name)
17560 jainbasil 32
{
33
        colorName = name;
34
}
35
 
17638 jainbasil 36
bool ColorAPI::isSpotColor()
17560 jainbasil 37
{
38
        return color->isSpotColor();
39
}
40
 
17638 jainbasil 41
void ColorAPI::setSpotColor(bool value)
17560 jainbasil 42
{
43
        color->setSpotColor(value);
44
}
45
 
17638 jainbasil 46
void ColorAPI::replace(QString replace)
17560 jainbasil 47
{
48
        if(replace.isEmpty())
49
        {
50
                RAISE("Cannot replace a color with an empty name.");
51
        }
52
        if (ScCore->primaryMainWindow()->doc->PageColors.contains(colorName)
53
                && (ScCore->primaryMainWindow()->doc->PageColors.contains(replace)
54
                        || (replace == CommonStrings::None)))
55
                ReplaceColor(colorName, replace);
56
        else
57
        {
58
                RAISE("Color not found.");
59
        }
60
}
61
 
17638 jainbasil 62
void ColorAPI::remove(QString replace)
17560 jainbasil 63
{
64
        if (ScCore->primaryMainWindow()->HaveDoc)
65
        {
66
                if (ScCore->primaryMainWindow()->doc->PageColors.contains(colorName)
67
                        && (ScCore->primaryMainWindow()->doc->PageColors.contains(replace)
68
                                || (replace == CommonStrings::None)))
69
                {
70
                        ScCore->primaryMainWindow()->doc->PageColors.remove(colorName);
71
                        ReplaceColor(colorName, replace);
72
                }
73
                else
74
                {
75
                        RAISE("Color not found in document.");
76
                        return;
77
                }
78
        }
79
        else
80
        {
81
                ColorList* colorList=PrefsManager::instance()->colorSetPtr();
82
                if (colorList->contains(colorName))
83
                        colorList->remove(colorName);
84
                else
85
                {
86
                        RAISE("Color not found in default colors");
87
                        return;
88
                }
89
        }      
90
}
91
 
17638 jainbasil 92
void ColorAPI::changeCMYK(int c, int m, int y, int k)
17560 jainbasil 93
{
94
    if(ScCore->primaryMainWindow()->HaveDoc)
95
    {
96
        if(!ScCore->primaryMainWindow()->doc->PageColors.contains(colorName))
97
        {
98
            RAISE("Color not found in document");
99
        }
100
        ScCore->primaryMainWindow()->doc->PageColors[colorName].setColor(c, m, y, k);
101
    }
102
    else
103
    {
104
        ColorList* colorList=PrefsManager::instance()->colorSetPtr();
105
        if(!colorList->contains(colorName))
106
        {
107
            RAISE("Color not found in default colors.");
108
        }
109
        (*colorList)[colorName].setColor(c, m, y, k);
110
    }
111
}
112
 
17638 jainbasil 113
void ColorAPI::changeRGB(int r, int g, int b)
17560 jainbasil 114
{
115
        if(ScCore->primaryMainWindow()->HaveDoc)
116
        {
117
                if(!ScCore->primaryMainWindow()->doc->PageColors.contains(colorName))
118
                {
119
                        RAISE("Color not found in document");
120
                }
22333 jghali 121
                ScCore->primaryMainWindow()->doc->PageColors[colorName].setRgbColor(r, g, b);
17560 jainbasil 122
        }
123
        else
124
        {
125
                ColorList* colorList=PrefsManager::instance()->colorSetPtr();
126
                if(!colorList->contains(colorName))
127
                {
128
                        RAISE("Color not found in default colors");
129
                }
22333 jghali 130
                (*colorList)[colorName].setRgbColor(r, g, b);
17560 jainbasil 131
        }
132
}
133
 
17638 jainbasil 134
ColorAPI::~ColorAPI()
17560 jainbasil 135
{
136
        qDebug() << "ScColorWrapper deleted";
17638 jainbasil 137
}