summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_tool_paint.cc
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/ui/kis_tool_paint.cc
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/ui/kis_tool_paint.cc')
-rw-r--r--chalk/ui/kis_tool_paint.cc260
1 files changed, 260 insertions, 0 deletions
diff --git a/chalk/ui/kis_tool_paint.cc b/chalk/ui/kis_tool_paint.cc
new file mode 100644
index 00000000..d8d19f36
--- /dev/null
+++ b/chalk/ui/kis_tool_paint.cc
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2003 Boudewijn Rempt
+ *
+ * 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 <tqwidget.h>
+#include <tqrect.h>
+#include <tqlayout.h>
+#include <tqlabel.h>
+#include <tqpushbutton.h>
+#include <tqwhatsthis.h>
+#include <tqcheckbox.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <knuminput.h>
+#include <kiconloader.h>
+
+#include "kis_button_release_event.h"
+#include "kis_canvas_subject.h"
+#include "kis_cmb_composite.h"
+#include "kis_colorspace.h"
+#include "kis_config.h"
+#include "kis_cursor.h"
+#include "kis_global.h"
+#include "kis_image.h"
+#include "kis_int_spinbox.h"
+#include "kis_paint_device.h"
+#include "kis_tool_controller.h"
+#include "kis_tool_paint.h"
+
+KisToolPaint::KisToolPaint(const TQString& UIName)
+ : super(UIName)
+{
+ m_subject = 0;
+
+ m_UIName = UIName;
+
+ m_optionWidget = 0;
+ m_optionWidgetLayout = 0;
+
+ m_lbOpacity = 0;
+ m_slOpacity = 0;
+ m_lbComposite= 0;
+ m_cmbComposite = 0;
+
+ m_opacity = OPACITY_OPAQUE;
+ m_compositeOp = COMPOSITE_OVER;
+}
+
+KisToolPaint::~KisToolPaint()
+{
+}
+
+void KisToolPaint::update(KisCanvasSubject *subject)
+{
+ m_subject = subject;
+ updateCompositeOpComboBox();
+}
+
+void KisToolPaint::paint(KisCanvasPainter&)
+{
+}
+
+void KisToolPaint::paint(KisCanvasPainter&, const TQRect&)
+{
+}
+
+void KisToolPaint::deactivate()
+{
+}
+
+void KisToolPaint::buttonPress(KisButtonPressEvent *)
+{
+}
+
+void KisToolPaint::move(KisMoveEvent *)
+{
+}
+
+void KisToolPaint::buttonRelease(KisButtonReleaseEvent * e)
+{
+ kdDebug() << "buttonRelease" << endl;
+ if(e->button() == Qt::MidButton)
+ {
+ kdDebug() << "switch" << endl;
+ KisColor bg = m_subject->bgColor();
+ m_subject->setBGColor(m_subject->fgColor());
+ m_subject->setFGColor(bg);
+ }
+}
+
+void KisToolPaint::doubleClick(KisDoubleClickEvent *)
+{
+}
+
+void KisToolPaint::keyPress(TQKeyEvent *)
+{
+}
+
+void KisToolPaint::keyRelease(TQKeyEvent *)
+{
+}
+
+TQWidget* KisToolPaint::createOptionWidget(TQWidget* tqparent)
+{
+ m_optionWidget = new TQWidget(tqparent);
+ m_optionWidget->setCaption(m_UIName);
+
+ m_lbOpacity = new TQLabel(i18n("Opacity:"), m_optionWidget);
+ m_slOpacity = new KisIntSpinbox( m_optionWidget, "int_m_optionwidget");
+ m_slOpacity->setRange( 0, 100);
+ m_slOpacity->setValue(m_opacity / OPACITY_OPAQUE * 100);
+ connect(m_slOpacity, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetOpacity(int)));
+
+ m_lbComposite = new TQLabel(i18n("Mode:"), m_optionWidget);
+ m_cmbComposite = new KisCmbComposite(m_optionWidget);
+ connect(m_cmbComposite, TQT_SIGNAL(activated(const KisCompositeOp&)), this, TQT_SLOT(slotSetCompositeMode(const KisCompositeOp&)));
+
+ TQVBoxLayout* verticalLayout = new TQVBoxLayout(m_optionWidget);
+ verticalLayout->setMargin(0);
+ verticalLayout->setSpacing(3);
+
+ m_optionWidgetLayout = new TQGridLayout(verticalLayout, 2, 3, 6);
+
+ m_optionWidgetLayout->addWidget(m_lbOpacity, 0, 0);
+ m_optionWidgetLayout->addWidget(m_slOpacity, 0, 1);
+
+ m_optionWidgetLayout->addWidget(m_lbComposite, 1, 0);
+ m_optionWidgetLayout->addWidget(m_cmbComposite, 1, 1);
+
+ verticalLayout->addItem(new TQSpacerItem(0,0,TQSizePolicy::Fixed,TQSizePolicy::Expanding));
+
+ if (!quickHelp().isEmpty()) {
+ TQPushButton* push = new TQPushButton(SmallIconSet( "help" ), "", m_optionWidget);
+ connect(push, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotPopupQuickHelp()));
+
+ TQHBoxLayout* hLayout = new TQHBoxLayout(m_optionWidget);
+ hLayout->addWidget(push);
+ hLayout->addItem(new TQSpacerItem(0,0,TQSizePolicy::Expanding,TQSizePolicy::Fixed));
+ verticalLayout->addLayout(hLayout);
+ }
+ return m_optionWidget;
+}
+
+TQWidget* KisToolPaint::optionWidget()
+{
+ return m_optionWidget;
+}
+
+void KisToolPaint::addOptionWidgetLayout(TQLayout *tqlayout)
+{
+ Q_ASSERT(m_optionWidget != 0);
+ Q_ASSERT(m_optionWidgetLayout != 0);
+ int rowCount = m_optionWidgetLayout->numRows();
+ m_optionWidgetLayout->addMultiCellLayout(tqlayout, rowCount, rowCount, 0, 1);
+}
+
+void KisToolPaint::addOptionWidgetOption(TQWidget *control, TQWidget *label)
+{
+ Q_ASSERT(m_optionWidget != 0);
+ Q_ASSERT(m_optionWidgetLayout != 0);
+ if(label)
+ {
+ m_optionWidgetLayout->addWidget(label, m_optionWidgetLayout->numRows(), 0);
+ m_optionWidgetLayout->addWidget(control, m_optionWidgetLayout->numRows()-1, 1);
+ }
+ else
+ m_optionWidgetLayout->addMultiCellWidget(control, m_optionWidgetLayout->numRows(), m_optionWidgetLayout->numRows(), 0, 1);
+}
+
+void KisToolPaint::slotSetOpacity(int opacityPerCent)
+{
+ m_opacity = opacityPerCent * OPACITY_OPAQUE / 100;
+}
+
+void KisToolPaint::slotSetCompositeMode(const KisCompositeOp& compositeOp)
+{
+ m_compositeOp = compositeOp;
+}
+
+TQCursor KisToolPaint::cursor()
+{
+ return m_cursor;
+}
+
+void KisToolPaint::setCursor(const TQCursor& cursor)
+{
+ m_cursor = cursor;
+
+ if (m_subject) {
+ KisToolControllerInterface *controller = m_subject->toolController();
+
+ if (controller && controller->currentTool() == this) {
+ m_subject->canvasController()->setCanvasCursor(m_cursor);
+ }
+ }
+}
+
+void KisToolPaint::activate()
+{
+ if (m_subject) {
+ KisToolControllerInterface *controller = m_subject->toolController();
+
+ if (controller)
+ controller->setCurrentTool(this);
+
+ updateCompositeOpComboBox();
+
+ KisConfig cfg;
+ m_paintOutline = (cfg.cursorStyle() == CURSOR_STYLE_OUTLINE);
+ }
+}
+
+void KisToolPaint::notifyModified() const
+{
+ if (m_subject && m_subject->currentImg()) {
+ m_subject->currentImg()->setModified();
+ }
+}
+
+void KisToolPaint::updateCompositeOpComboBox()
+{
+ if (m_optionWidget && m_subject) {
+ KisImageSP img = m_subject->currentImg();
+
+ if (img) {
+ KisPaintDeviceSP device = img->activeDevice();
+
+ if (device) {
+ KisCompositeOpList compositeOps = device->colorSpace()->userVisiblecompositeOps();
+ m_cmbComposite->setCompositeOpList(compositeOps);
+
+ if (compositeOps.tqfind(m_compositeOp) == compositeOps.end()) {
+ m_compositeOp = COMPOSITE_OVER;
+ }
+ m_cmbComposite->setCurrentItem(m_compositeOp);
+ }
+ }
+ }
+}
+
+void KisToolPaint::slotPopupQuickHelp() {
+ TQWhatsThis::display(quickHelp());
+}
+
+#include "kis_tool_paint.moc"