You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
5.1 KiB
169 lines
5.1 KiB
14 years ago
|
/*
|
||
4 years ago
|
* kis_tool_select_brush.cpp - part of Chalk
|
||
14 years ago
|
*
|
||
|
* Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
|
||
|
*
|
||
|
* 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 <tqevent.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqwidget.h>
|
||
|
#include <tqrect.h>
|
||
|
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeaction.h>
|
||
14 years ago
|
#include <kcommand.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
14 years ago
|
|
||
|
#include "kis_brush.h"
|
||
|
#include "kis_button_press_event.h"
|
||
|
#include "kis_button_release_event.h"
|
||
|
#include "kis_cmb_composite.h"
|
||
|
#include "kis_cursor.h"
|
||
|
#include "kis_doc.h"
|
||
|
#include "kis_paintop.h"
|
||
|
#include "kis_paintop_registry.h"
|
||
|
#include "kis_move_event.h"
|
||
|
#include "kis_painter.h"
|
||
|
#include "kis_selection.h"
|
||
|
#include "kis_tool_select_brush.h"
|
||
|
#include "kis_types.h"
|
||
|
#include "kis_layer.h"
|
||
|
#include "kis_view.h"
|
||
|
#include "kis_selection_options.h"
|
||
|
#include "kis_selected_transaction.h"
|
||
|
|
||
|
KisToolSelectBrush::KisToolSelectBrush()
|
||
|
: super(i18n("SelectBrush"))
|
||
|
{
|
||
|
setName("tool_select_brush");
|
||
|
m_optWidget = 0;
|
||
|
setCursor(KisCursor::load("tool_brush_selection_cursor.png", 5, 5));
|
||
|
m_paintOnSelection = true;
|
||
|
}
|
||
|
|
||
|
KisToolSelectBrush::~KisToolSelectBrush()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void KisToolSelectBrush::activate()
|
||
|
{
|
||
|
super::activate();
|
||
|
|
||
|
if (!m_optWidget)
|
||
|
return;
|
||
|
|
||
|
m_optWidget->slotActivated();
|
||
|
}
|
||
|
|
||
|
void KisToolSelectBrush::initPaint(KisEvent* /*e*/)
|
||
|
{
|
||
|
if (!m_currentImage || !m_currentImage->activeDevice()) return;
|
||
|
|
||
|
m_mode = PAINT;
|
||
|
m_dragDist = 0;
|
||
|
|
||
|
// Create painter
|
||
|
KisPaintDeviceSP dev = m_currentImage->activeDevice();
|
||
|
if (m_painter)
|
||
|
delete m_painter;
|
||
|
bool hasSelection = dev->hasSelection();
|
||
|
if (m_currentImage->undo()) m_transaction = new KisSelectedTransaction(i18n("Selection Brush"), dev);
|
||
|
if(! hasSelection)
|
||
|
{
|
||
|
dev->selection()->clear();
|
||
|
dev->emitSelectionChanged();
|
||
|
}
|
||
|
KisSelectionSP selection = dev->selection();
|
||
|
|
||
|
m_target = selection;
|
||
|
m_painter = new KisPainter(selection.data());
|
||
13 years ago
|
TQ_CHECK_PTR(m_painter);
|
||
14 years ago
|
m_painter->setPaintColor(KisColor(TQt::black, selection->colorSpace()));
|
||
|
m_painter->setBrush(m_subject->currentBrush());
|
||
|
m_painter->setOpacity(OPACITY_OPAQUE);//m_subject->fgColor().colorSpace()->intensity8(m_subject->fgColor().data()));
|
||
|
m_painter->setCompositeOp(COMPOSITE_OVER);
|
||
|
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("paintbrush", 0, painter());
|
||
|
painter()->setPaintOp(op); // And now the painter owns the op and will destroy it.
|
||
|
|
||
14 years ago
|
// Set the cursor -- ideally. this should be a mask created from the brush,
|
||
14 years ago
|
// now that X11 can handle colored cursors.
|
||
|
#if 0
|
||
|
// Setting cursors has no effect until the tool is selected again; this
|
||
|
// should be fixed.
|
||
|
setCursor(KisCursor::brushCursor());
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void KisToolSelectBrush::endPaint()
|
||
|
{
|
||
|
m_mode = HOVER;
|
||
|
if (m_currentImage && m_currentImage->activeLayer()) {
|
||
|
if (m_currentImage->undo() && m_painter) {
|
||
|
// If painting in mouse release, make sure painter
|
||
|
// is destructed or end()ed
|
||
|
m_currentImage->undoAdapter()->addCommand(m_transaction);
|
||
|
}
|
||
|
delete m_painter;
|
||
|
m_painter = 0;
|
||
|
if (m_currentImage->activeDevice())
|
||
|
m_currentImage->activeDevice()->emitSelectionChanged();
|
||
|
notifyModified();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void KisToolSelectBrush::setup(TDEActionCollection *collection)
|
||
14 years ago
|
{
|
||
12 years ago
|
m_action = static_cast<TDERadioAction *>(collection->action(name()));
|
||
14 years ago
|
|
||
|
if (m_action == 0) {
|
||
12 years ago
|
m_action = new TDERadioAction(i18n("&Selection Brush"),
|
||
14 years ago
|
"tool_brush_selection", "Ctrl+Shift+B", this,
|
||
|
TQT_SLOT(activate()), collection,
|
||
|
name());
|
||
13 years ago
|
TQ_CHECK_PTR(m_action);
|
||
14 years ago
|
m_action->setToolTip(i18n("Paint a selection"));
|
||
|
m_action->setExclusiveGroup("tools");
|
||
|
m_ownAction = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
TQWidget* KisToolSelectBrush::createOptionWidget(TQWidget* parent)
|
||
14 years ago
|
{
|
||
14 years ago
|
Q_UNUSED(parent);
|
||
14 years ago
|
// Commented out due to the fact that this doesn't actually work if you change the action
|
||
|
#if 0
|
||
14 years ago
|
m_optWidget = new KisSelectionOptions(parent, m_subject);
|
||
13 years ago
|
TQ_CHECK_PTR(m_optWidget);
|
||
14 years ago
|
m_optWidget->setCaption(i18n("Selection Brush"));
|
||
|
|
||
13 years ago
|
TQVBoxLayout * l = dynamic_cast<TQVBoxLayout*>(m_optWidget->layout());
|
||
14 years ago
|
l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding));
|
||
|
|
||
|
return m_optWidget;
|
||
|
#endif
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
TQWidget* KisToolSelectBrush::optionWidget()
|
||
|
{
|
||
|
return m_optWidget;
|
||
|
}
|
||
|
|
||
|
#include "kis_tool_select_brush.moc"
|