chalk

kis_filter.cpp
1/*
2 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include "kis_filter.h"
19
20#include <tqstring.h>
21
22#include "kis_types.h"
23#include "kis_filter_configuration.h"
24
25KisFilter::KisFilter(const KisID& id, const TQString & category, const TQString & entry)
26 : KisProgressSubject(0, id.id().latin1())
27 , m_id(id)
28 , m_progressDisplay(0)
29 , m_category(category)
30 , m_entry(entry)
31{
32}
33
35{
36 return new KisFilterConfiguration(m_id.id(), 0);
37}
38
43
45{
46 return 0;
47}
48
49void KisFilter::setProgressDisplay(KisProgressDisplayInterface * progressDisplay)
50{
51 m_progressDisplay = progressDisplay;
52}
53
54
55void KisFilter::enableProgress() {
56 m_progressEnabled = true;
57 m_cancelRequested = false;
58}
59
60void KisFilter::disableProgress() {
61 m_progressEnabled = false;
62 m_cancelRequested = false;
63 m_progressDisplay = 0;
64}
65
66void KisFilter::setProgressTotalSteps(TQ_INT32 totalSteps)
67{
68 if (m_progressEnabled) {
69
70 m_progressTotalSteps = totalSteps;
71 m_lastProgressPerCent = 0;
72 m_progressSteps = 0;
73 emit notifyProgress(0);
74 }
75}
76
77void KisFilter::setProgress(TQ_INT32 progress)
78{
79 if (m_progressEnabled) {
80 TQ_INT32 progressPerCent = (progress * 100) / m_progressTotalSteps;
81 m_progressSteps = progress;
82
83 if (progressPerCent != m_lastProgressPerCent) {
84
85 m_lastProgressPerCent = progressPerCent;
86 emit notifyProgress(progressPerCent);
87 }
88 }
89}
90
91void KisFilter::incProgress()
92{
93 setProgress(++m_progressSteps);
94
95}
96
97void KisFilter::setProgressStage(const TQString& stage, TQ_INT32 progress)
98{
99 if (m_progressEnabled) {
100
101 TQ_INT32 progressPerCent = (progress * 100) / m_progressTotalSteps;
102
103 m_lastProgressPerCent = progressPerCent;
104 emit notifyProgressStage(stage, progressPerCent);
105 }
106}
107
108void KisFilter::setProgressDone()
109{
110 if (m_progressEnabled) {
111 emit notifyProgressDone();
112 }
113}
114
115
116bool KisFilter::autoUpdate() {
117 return m_autoUpdate;
118}
119
120void KisFilter::setAutoUpdate(bool set) {
121 m_autoUpdate = set;
122}
123
124TQRect KisFilter::enlargeRect(TQRect rect, KisFilterConfiguration* c) const {
125 int margin = overlapMarginNeeded(c);
126 rect.rLeft() -= margin;
127 rect.rTop() -= margin;
128 rect.rRight() += margin;
129 rect.rBottom() += margin;
130 return rect;
131}
132
133#include "kis_filter.moc"
A KisFilterConfiguration is the serializable representation of the filter parameters.
virtual int overlapMarginNeeded(KisFilterConfiguration *=0) const
Used when threading is used – the overlap margin is passed to the filter to use to compute pixels,...
Definition kis_filter.h:113
virtual KisFilterConfigWidget * createConfigurationWidget(TQWidget *parent, KisPaintDeviceSP dev)
KisFilter(const KisID &id, const TQString &category, const TQString &entry)
Construct a Chalk filter.
virtual TQRect enlargeRect(TQRect rect, KisFilterConfiguration *=0) const
Similar to overlapMarginNeeded: some filters will alter a lot of pixels that are near to each other a...
virtual KisFilterConfiguration * configuration()
Chalk has a large number of extensible resources.
Definition kis_id.h:57