KOffice – TDE office suite
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.

kis_tool_brush.cc 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * kis_tool_brush.cc - part of Chalk
  3. *
  4. * Copyright (c) 2003-2004 Boudewijn Rempt <boud@valdyas.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. #include <tqevent.h>
  21. #include <tqlabel.h>
  22. #include <tqlayout.h>
  23. #include <tqwidget.h>
  24. #include <tqtimer.h>
  25. #include <tqpushbutton.h>
  26. #include <tqpainter.h>
  27. #include <tqrect.h>
  28. #include <tqcheckbox.h>
  29. #include <kdebug.h>
  30. #include <tdeaction.h>
  31. #include <kcommand.h>
  32. #include <tdelocale.h>
  33. #include "kis_config.h"
  34. #include "kis_brush.h"
  35. #include "kis_paintop.h"
  36. #include "kis_paintop_registry.h"
  37. #include "kis_cmb_composite.h"
  38. #include "kis_cursor.h"
  39. #include "kis_painter.h"
  40. #include "kis_tool_brush.h"
  41. #include "kis_canvas_subject.h"
  42. #include "kis_boundary.h"
  43. #include "kis_move_event.h"
  44. #include "kis_canvas.h"
  45. #include "kis_layer.h"
  46. KisToolBrush::KisToolBrush()
  47. : super(i18n("Brush"))
  48. {
  49. setName("tool_brush");
  50. setCursor(KisCursor::load("tool_freehand_cursor.png", 5, 5));
  51. m_rate = 100; // Conveniently hardcoded for now
  52. m_timer = new TQTimer(this);
  53. TQ_CHECK_PTR(m_timer);
  54. connect(m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeoutPaint()));
  55. }
  56. KisToolBrush::~KisToolBrush()
  57. {
  58. delete m_timer;
  59. m_timer = 0;
  60. }
  61. void KisToolBrush::timeoutPaint()
  62. {
  63. if (currentImage() && painter()) {
  64. painter()->paintAt(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt);
  65. currentImage()->activeLayer()->setDirty(painter()->dirtyRect());
  66. }
  67. }
  68. void KisToolBrush::update(KisCanvasSubject *subject)
  69. {
  70. super::update(subject);
  71. }
  72. void KisToolBrush::initPaint(KisEvent *e)
  73. {
  74. super::initPaint(e);
  75. if (!m_painter) {
  76. kdWarning() << "Didn't create a painter! Something is wrong!\n";
  77. return;
  78. }
  79. KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), m_painter);
  80. if (!op) return;
  81. m_subject->canvasController()->kiscanvas()->update(); // remove the outline
  82. painter()->setPaintOp(op); // And now the painter owns the op and will destroy it.
  83. if (op->incremental()) {
  84. m_timer->start( m_rate );
  85. }
  86. }
  87. void KisToolBrush::endPaint()
  88. {
  89. m_timer->stop();
  90. super::endPaint();
  91. }
  92. void KisToolBrush::setup(TDEActionCollection *collection)
  93. {
  94. m_action = static_cast<TDERadioAction *>(collection->action(name()));
  95. if (m_action == 0) {
  96. m_action = new TDERadioAction(i18n("&Brush"),
  97. "tool_freehand", TQt::Key_B, this,
  98. TQT_SLOT(activate()), collection,
  99. name());
  100. m_action->setToolTip(i18n("Draw freehand"));
  101. m_action->setExclusiveGroup("tools");
  102. m_ownAction = true;
  103. }
  104. }
  105. void KisToolBrush::move(KisMoveEvent *e) {
  106. KisToolFreehand::move(e);
  107. KisConfig cfg;
  108. if (m_mode != PAINT && cfg.cursorStyle() == CURSOR_STYLE_OUTLINE)
  109. paintOutline(e->pos());
  110. }
  111. void KisToolBrush::leave(TQEvent */*e*/) {
  112. m_subject->canvasController()->kiscanvas()->update(); // remove the outline
  113. }
  114. void KisToolBrush::slotSetPaintingMode( int mode )
  115. {
  116. if (mode == TQButton::On) {
  117. // Direct painting
  118. m_paintIncremental = true;
  119. }
  120. else {
  121. m_paintIncremental = false;
  122. }
  123. }
  124. TQWidget* KisToolBrush::createOptionWidget(TQWidget* parent)
  125. {
  126. TQWidget *widget = super::createOptionWidget(parent);
  127. m_chkDirect = new TQCheckBox(i18n("Paint direct"), widget, "chkDirect");
  128. m_chkDirect->setChecked(true);
  129. connect(m_chkDirect, TQT_SIGNAL(stateChanged(int)), this, TQT_SLOT(slotSetPaintingMode(int)));
  130. m_optionLayout = new TQGridLayout(widget, 3, 2, 0, 6);
  131. TQ_CHECK_PTR(m_optionLayout);
  132. super::addOptionWidgetLayout(m_optionLayout);
  133. m_optionLayout->addWidget(m_chkDirect, 0, 0);
  134. return widget;
  135. }
  136. #include "kis_tool_brush.moc"