kis_duplicateop_settings.cpp 4.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
 *  Copyright (c) 2004-2008 Boudewijn Rempt <boud@valdyas.org>
 *  Copyright (c) 2004 Clarence Dang <dang@kde.org>
 *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
 *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
 *
 *  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.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "kis_duplicateop_settings.h"
24
#include "kis_duplicateop_option.h"
25 26
#include "kis_duplicateop_settings_widget.h"

27 28 29 30
#include <QDomElement>
#include <QDomDocument>

#include <KoPointerEvent.h>
31
#include <KoCompositeOpRegistry.h>
32 33

#include <kis_image.h>
Sven Langkamp's avatar
Sven Langkamp committed
34
#include <kis_brush_option_widget.h>
35
#include <kis_paintop_settings_widget.h>
36 37 38 39
#include <kis_pressure_darken_option.h>
#include <kis_pressure_opacity_option.h>
#include <kis_pressure_size_option.h>
#include <kis_paint_action_type_option.h>
40
#include <kis_perspective_grid.h>
41

Halla Rempt's avatar
Halla Rempt committed
42 43
KisDuplicateOpSettings::KisDuplicateOpSettings()
    : m_isOffsetNotUptodate(false)
44 45 46
{
}

Halla Rempt's avatar
Halla Rempt committed
47 48
KisDuplicateOpSettings::~KisDuplicateOpSettings()
{
49 50 51 52
}

bool KisDuplicateOpSettings::paintIncremental()
{
53
    return false;
54 55
}

56 57 58 59
QString KisDuplicateOpSettings::indirectPaintingCompositeOp() const
{
    return COMPOSITE_COPY;
}
60 61 62 63 64 65

QPointF KisDuplicateOpSettings::offset() const
{
    return m_offset;
}

66 67 68 69 70
QPointF KisDuplicateOpSettings::position() const
{
    return m_position;
}

71
bool KisDuplicateOpSettings::mousePressEvent(const KisPaintInformation &info, Qt::KeyboardModifiers modifiers, KisNodeWSP currentNode)
72
{
73
    bool ignoreEvent = true;
Halla Rempt's avatar
Halla Rempt committed
74

75
    if (modifiers == Qt::ControlModifier) {
76
        m_sourceNode = currentNode;
77
        m_position = info.pos();
78
        m_isOffsetNotUptodate = true;
79
        ignoreEvent = false;
80 81
    }
    else {
82
        if (m_isOffsetNotUptodate) {
83
            m_offset = info.pos() - m_position;
84 85
            m_isOffsetNotUptodate = false;
        }
86
        ignoreEvent = true;
87
    }
88

89
    return ignoreEvent;
90 91
}

92 93 94 95
KisNodeWSP KisDuplicateOpSettings::sourceNode() const
{
    return m_sourceNode;
}
96

97 98 99 100
void KisDuplicateOpSettings::activate()
{
}

101 102 103 104
void KisDuplicateOpSettings::fromXML(const QDomElement& elt)
{
    // First, call the parent class fromXML to make sure all the
    // properties are saved to the map
Halla Rempt's avatar
Halla Rempt committed
105
    KisPaintOpSettings::fromXML(elt);
106

107 108 109
    m_offset.setX(elt.attribute("OffsetX", "0.0").toDouble());
    m_offset.setY(elt.attribute("OffsetY", "0.0").toDouble());
    m_isOffsetNotUptodate = false;
110 111 112 113 114
}

void KisDuplicateOpSettings::toXML(QDomDocument& doc, QDomElement& rootElt) const
{
    // Then call the parent class fromXML
Sven Langkamp's avatar
Sven Langkamp committed
115
    KisPropertiesConfiguration::toXML(doc, rootElt);
116

117 118
    rootElt.setAttribute("OffsetX", QString::number(m_offset.x()));
    rootElt.setAttribute("OffsetY", QString::number(m_offset.y()));
119 120 121
}


Halla Rempt's avatar
Halla Rempt committed
122 123
KisPaintOpSettingsSP KisDuplicateOpSettings::clone() const
{
124 125
    KisPaintOpSettingsSP setting = KisPaintOpSettings::clone();
    KisDuplicateOpSettings* s = dynamic_cast<KisDuplicateOpSettings*>(setting.data());
126 127 128 129
    s->m_offset = m_offset;
    s->m_isOffsetNotUptodate = m_isOffsetNotUptodate;
    s->m_position = m_position;

130
    return setting;
131 132
}

133
QPainterPath KisDuplicateOpSettings::brushOutline(const KisPaintInformation &info, OutlineMode mode) const
134
{
135
    QPainterPath path;
136 137 138

    // clone tool should always show an outline
    path = KisBrushBasedPaintOpSettings::brushOutlineImpl(info, mode, 1.0, true);
139

140 141
    QPainterPath copy(path);
    QRectF rect2 = copy.boundingRect();
142
    if (m_isOffsetNotUptodate || !getBool(DUPLICATE_MOVE_SOURCE_POINT)) {
143
        copy.translate(m_position - info.pos());
144 145
    }
    else {
146 147
        copy.translate(-m_offset);
    }
148

149
    path.addPath(copy);
150

151 152 153
    qreal dx = rect2.width() / 4.0;
    qreal dy = rect2.height() / 4.0;
    rect2.adjust(dx, dy, -dx, -dy);
154

155 156
    path.moveTo(rect2.topLeft());
    path.lineTo(rect2.bottomRight());
157

158 159
    path.moveTo(rect2.topRight());
    path.lineTo(rect2.bottomLeft());
160

161
    return path;
162
}
Halla Rempt's avatar
Halla Rempt committed
163