~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to krita/ui/kis_rgb_widget.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-10-11 14:49:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051011144950-lwpngbifzp8nk0ds
Tags: 1:1.4.1-0ubuntu7
* SECURITY UPDATE: fix heap based buffer overflow in the RTF importer of KWord
* Opening specially crafted RTF files in KWord can cause
  execution of abitrary code.
* Add kubuntu_01_rtfimport_heap_overflow.diff
* References:
  CAN-2005-2971
  CESA-2005-005
  http://www.koffice.org/security/advisory-20051011-1.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * This file is part of Krita
 
3
 *
 
4
 * Copyright (c) 1999 Matthias Elter (me@kde.org)
 
5
 * Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation; either version 2 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  This program is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with this program; if not, write to the Free Software
 
19
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "kis_rgb_widget.h"
 
23
 
 
24
#include <qlayout.h>
 
25
#include <qhbox.h>
 
26
#include <qlabel.h>
 
27
#include <qspinbox.h>
 
28
 
 
29
#include <koFrameButton.h>
 
30
#include <koColorSlider.h>
 
31
#include <kcolordialog.h>
 
32
#include <kdualcolorbutton.h>
 
33
 
 
34
#include <qcolor.h>
 
35
 
 
36
KisRGBWidget::KisRGBWidget(QWidget *parent, const char *name) : super(parent, name)
 
37
{
 
38
        m_subject = 0;
 
39
 
 
40
        m_ColorButton = new KDualColorButton(this);
 
41
        m_ColorButton ->  setFixedSize(m_ColorButton->sizeHint());
 
42
        QGridLayout *mGrid = new QGridLayout(this, 3, 5, 5, 2);
 
43
 
 
44
        /* setup color sliders */
 
45
        mRSlider = new KoColorSlider(this);
 
46
        mRSlider->setMaximumHeight(20);
 
47
        mRSlider->slotSetRange(0, 255);
 
48
 
 
49
        mGSlider = new KoColorSlider(this);
 
50
        mGSlider->setMaximumHeight(20);
 
51
        mGSlider->slotSetRange(0, 255);
 
52
 
 
53
        mBSlider = new KoColorSlider(this);
 
54
        mBSlider->setMaximumHeight(20);
 
55
        mBSlider->slotSetRange(0, 255);
 
56
 
 
57
        /* setup slider labels */
 
58
        mRLabel = new QLabel("R", this);
 
59
        mRLabel->setFixedWidth(12);
 
60
        mRLabel->setFixedHeight(20);
 
61
        mGLabel = new QLabel("G", this);
 
62
        mGLabel->setFixedWidth(12);
 
63
        mGLabel->setFixedHeight(20);
 
64
        mBLabel = new QLabel("B", this);
 
65
        mBLabel->setFixedWidth(12);
 
66
        mBLabel->setFixedHeight(20);
 
67
 
 
68
        /* setup spin box */
 
69
        mRIn = new QSpinBox(0, 255, 1, this);
 
70
        mRIn->setFixedWidth(50);
 
71
        mRIn->setFixedHeight(20);
 
72
        mGIn = new QSpinBox(0, 255, 1, this);
 
73
        mGIn->setFixedWidth(50);
 
74
        mGIn->setFixedHeight(20);
 
75
        mBIn = new QSpinBox(0, 255, 1, this);
 
76
        mBIn->setFixedWidth(50);
 
77
        mBIn->setFixedHeight(20);
 
78
 
 
79
        mGrid->addMultiCellWidget(m_ColorButton, 0, 3, 0, 0, Qt::AlignTop);
 
80
        mGrid->addWidget(mRLabel, 0, 1);
 
81
        mGrid->addWidget(mGLabel, 1, 1);
 
82
        mGrid->addWidget(mBLabel, 2, 1);
 
83
        mGrid->addMultiCellWidget(mRSlider, 0, 0, 2, 3);
 
84
        mGrid->addMultiCellWidget(mGSlider, 1, 1, 2, 3);
 
85
        mGrid->addMultiCellWidget(mBSlider, 2, 2, 2, 3);
 
86
        mGrid->addWidget(mRIn, 0, 4);
 
87
        mGrid->addWidget(mGIn, 1, 4);
 
88
        mGrid->addWidget(mBIn, 2, 4);
 
89
 
 
90
        connect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
 
91
        connect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
 
92
 
 
93
        /* connect color sliders */
 
94
        connect(mRSlider, SIGNAL(valueChanged(int)), this, SLOT(slotRChanged(int)));
 
95
        connect(mGSlider, SIGNAL(valueChanged(int)), this, SLOT(slotGChanged(int)));
 
96
        connect(mBSlider, SIGNAL(valueChanged(int)), this, SLOT(slotBChanged(int)));
 
97
 
 
98
        /* connect spin box */
 
99
        connect(mRIn, SIGNAL(valueChanged(int)), this, SLOT(slotRChanged(int)));
 
100
        connect(mGIn, SIGNAL(valueChanged(int)), this, SLOT(slotGChanged(int)));
 
101
        connect(mBIn, SIGNAL(valueChanged(int)), this, SLOT(slotBChanged(int)));
 
102
}
 
103
 
 
104
void KisRGBWidget::slotRChanged(int r)
 
105
{
 
106
        if (m_ColorButton->current() == KDualColorButton::Foreground){
 
107
                m_fgColor.setRgb(r, m_fgColor.green(), m_fgColor.blue());
 
108
                m_ColorButton->setCurrent(KDualColorButton::Foreground);
 
109
                if(m_subject)
 
110
                        m_subject->setFGColor(m_fgColor);;
 
111
        }
 
112
        else{
 
113
                m_bgColor.setRgb(r, m_bgColor.green(), m_bgColor.blue());
 
114
                m_ColorButton->setCurrent(KDualColorButton::Background);
 
115
                if(m_subject)
 
116
                        m_subject->setBGColor(m_bgColor);
 
117
        }
 
118
}
 
119
 
 
120
void KisRGBWidget::slotGChanged(int g)
 
121
{
 
122
        if (m_ColorButton->current() == KDualColorButton::Foreground){
 
123
                m_fgColor.setRgb(m_fgColor.red(), g, m_fgColor.blue());
 
124
                m_ColorButton->setCurrent(KDualColorButton::Foreground);
 
125
                if(m_subject)
 
126
                        m_subject->setFGColor(m_fgColor);
 
127
        }
 
128
        else{
 
129
                m_bgColor.setRgb(m_bgColor.red(), g, m_bgColor.blue());
 
130
                m_ColorButton->setCurrent(KDualColorButton::Background);
 
131
                if(m_subject)
 
132
                        m_subject->setBGColor(m_bgColor);
 
133
        }
 
134
}
 
135
 
 
136
void KisRGBWidget::slotBChanged(int b)
 
137
{
 
138
        if (m_ColorButton->current() == KDualColorButton::Foreground){
 
139
                m_fgColor.setRgb(m_fgColor.red(), m_fgColor.green(), b);
 
140
                m_ColorButton->setCurrent(KDualColorButton::Foreground);
 
141
                if(m_subject)
 
142
                        m_subject->setFGColor(m_fgColor);
 
143
        }
 
144
        else{
 
145
                m_bgColor.setRgb(m_bgColor.red(), m_bgColor.green(), b);
 
146
                m_ColorButton->setCurrent(KDualColorButton::Background);
 
147
                if(m_subject)
 
148
                        m_subject->setBGColor(m_bgColor);
 
149
        }
 
150
}
 
151
 
 
152
void KisRGBWidget::update(KisCanvasSubject *subject)
 
153
{
 
154
        m_subject = subject;
 
155
        m_fgColor = subject->fgColor();
 
156
        m_bgColor = subject->bgColor();
 
157
 
 
158
        QColor color = (m_ColorButton->current() == KDualColorButton::Foreground)? m_fgColor : m_bgColor;
 
159
 
 
160
        int r = color.red();
 
161
        int g = color.green();
 
162
        int b = color.blue();
 
163
 
 
164
        disconnect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
 
165
        disconnect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
 
166
 
 
167
        m_ColorButton->setForeground( m_fgColor );
 
168
        m_ColorButton->setBackground( m_bgColor );
 
169
 
 
170
        connect(m_ColorButton, SIGNAL(fgChanged(const QColor &)), this, SLOT(slotFGColorSelected(const QColor &)));
 
171
        connect(m_ColorButton, SIGNAL(bgChanged(const QColor &)), this, SLOT(slotBGColorSelected(const QColor &)));
 
172
 
 
173
        mRSlider->slotSetColor1(QColor(0, g, b));
 
174
        mRSlider->slotSetColor2(QColor(255, g, b));
 
175
        mRSlider->slotSetValue(r);
 
176
        mRIn->setValue(r);
 
177
 
 
178
        mGSlider->slotSetColor1(QColor(r, 0, b));
 
179
        mGSlider->slotSetColor2(QColor(r, 255, b));
 
180
        mGSlider->slotSetValue(g);
 
181
        mGIn->setValue(g);
 
182
 
 
183
        mBSlider->slotSetColor1(QColor(r, g, 0));
 
184
        mBSlider->slotSetColor2(QColor(r, g, 255));
 
185
        mBSlider->slotSetValue(b);
 
186
        mBIn->setValue(b);
 
187
}
 
188
 
 
189
void KisRGBWidget::slotFGColorSelected(const QColor& c)
 
190
{
 
191
        m_fgColor = QColor(c);
 
192
        if(m_subject)
 
193
        {
 
194
                QColor bgColor = m_ColorButton -> background();
 
195
                m_subject->setFGColor(m_fgColor);
 
196
                //Background signal could be blocked so do that manually 
 
197
                //see bug 106919
 
198
                m_subject->setBGColor(bgColor);
 
199
        }
 
200
}
 
201
 
 
202
void KisRGBWidget::slotBGColorSelected(const QColor& c)
 
203
{
 
204
        m_bgColor = QColor(c);
 
205
        if(m_subject)
 
206
                m_subject->setBGColor(m_bgColor);
 
207
}
 
208
 
 
209
#include "kis_rgb_widget.moc"