krita

kis_tool_paint.cc

00001 /*
00002  *  Copyright (c) 2003 Boudewijn Rempt
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include <qwidget.h>
00020 #include <qrect.h>
00021 #include <qlayout.h>
00022 #include <qlabel.h>
00023 #include <qpushbutton.h>
00024 #include <qwhatsthis.h>
00025 #include <qcheckbox.h>
00026 
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029 #include <knuminput.h>
00030 #include <kiconloader.h>
00031 
00032 #include "kis_colorspace.h"
00033 #include "kis_global.h"
00034 #include "kis_config.h"
00035 #include "kis_cursor.h"
00036 #include "kis_canvas_subject.h"
00037 #include "kis_tool_controller.h"
00038 #include "kis_tool_paint.h"
00039 #include "kis_cmb_composite.h"
00040 #include "kis_image.h"
00041 #include "kis_int_spinbox.h"
00042 #include "kis_paint_device.h"
00043 
00044 KisToolPaint::KisToolPaint(const QString& UIName)
00045     : super(UIName)
00046 {
00047     m_subject = 0;
00048 
00049     m_UIName = UIName;
00050 
00051     m_optionWidget = 0;
00052     m_optionWidgetLayout = 0;
00053 
00054     m_lbOpacity = 0;
00055     m_slOpacity = 0;
00056     m_lbComposite= 0;
00057     m_cmbComposite = 0;
00058 
00059     m_opacity = OPACITY_OPAQUE;
00060     m_compositeOp = COMPOSITE_OVER;
00061 }
00062 
00063 KisToolPaint::~KisToolPaint()
00064 {
00065 }
00066 
00067 void KisToolPaint::update(KisCanvasSubject *subject)
00068 {
00069     m_subject = subject;
00070     updateCompositeOpComboBox();
00071 }
00072 
00073 void KisToolPaint::paint(KisCanvasPainter&)
00074 {
00075 }
00076 
00077 void KisToolPaint::paint(KisCanvasPainter&, const QRect&)
00078 {
00079 }
00080 
00081 void KisToolPaint::deactivate()
00082 {
00083 }
00084 
00085 void KisToolPaint::enter(QEvent *)
00086 {
00087 }
00088 
00089 void KisToolPaint::leave(QEvent *)
00090 {
00091 }
00092 
00093 void KisToolPaint::buttonPress(KisButtonPressEvent *)
00094 {
00095 }
00096 
00097 void KisToolPaint::move(KisMoveEvent *)
00098 {
00099 }
00100 
00101 void KisToolPaint::buttonRelease(KisButtonReleaseEvent *)
00102 {
00103 }
00104 
00105 void KisToolPaint::doubleClick(KisDoubleClickEvent *)
00106 {
00107 }
00108 
00109 void KisToolPaint::keyPress(QKeyEvent *)
00110 {
00111 }
00112 
00113 void KisToolPaint::keyRelease(QKeyEvent *)
00114 {
00115 }
00116 
00117 QWidget* KisToolPaint::createOptionWidget(QWidget* parent)
00118 {
00119     m_optionWidget = new QWidget(parent);
00120     m_optionWidget->setCaption(m_UIName);
00121 
00122     m_lbOpacity = new QLabel(i18n("Opacity: "), m_optionWidget);
00123     m_slOpacity = new KisIntSpinbox( m_optionWidget, "int_m_optionwidget");
00124     m_slOpacity->setRange( 0, 100);
00125     m_slOpacity->setValue(m_opacity / OPACITY_OPAQUE * 100);
00126     connect(m_slOpacity, SIGNAL(valueChanged(int)), this, SLOT(slotSetOpacity(int)));
00127 
00128     m_lbComposite = new QLabel(i18n("Mode: "), m_optionWidget);
00129     m_cmbComposite = new KisCmbComposite(m_optionWidget);
00130     connect(m_cmbComposite, SIGNAL(activated(const KisCompositeOp&)), this, SLOT(slotSetCompositeMode(const KisCompositeOp&)));
00131 
00132     QVBoxLayout* verticalLayout = new QVBoxLayout(m_optionWidget);
00133     verticalLayout->setMargin(0);
00134     verticalLayout->setSpacing(3);
00135     
00136     m_optionWidgetLayout = new QGridLayout(verticalLayout, 2, 3, 6);
00137 
00138     m_optionWidgetLayout->addWidget(m_lbOpacity, 0, 0);
00139     m_optionWidgetLayout->addWidget(m_slOpacity, 0, 1);
00140 
00141     m_optionWidgetLayout->addWidget(m_lbComposite, 1, 0);
00142     m_optionWidgetLayout->addWidget(m_cmbComposite, 1, 1);
00143 
00144     verticalLayout->addItem(new QSpacerItem(0,0,QSizePolicy::Fixed,QSizePolicy::Expanding));
00145 
00146     if (!quickHelp().isEmpty()) {
00147         QPushButton* push = new QPushButton(SmallIconSet( "help" ), "", m_optionWidget);
00148         connect(push, SIGNAL(clicked()), this, SLOT(slotPopupQuickHelp()));
00149 
00150         QHBoxLayout* hLayout = new QHBoxLayout(m_optionWidget);
00151         hLayout->addWidget(push);
00152         hLayout->addItem(new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Fixed));
00153         verticalLayout->addLayout(hLayout);
00154     }
00155     return m_optionWidget;
00156 }
00157 
00158 QWidget* KisToolPaint::optionWidget()
00159 {
00160     return m_optionWidget;
00161 }
00162 
00163 void KisToolPaint::addOptionWidgetLayout(QLayout *layout)
00164 {
00165     Q_ASSERT(m_optionWidget != 0);
00166     Q_ASSERT(m_optionWidgetLayout != 0);
00167     int rowCount = m_optionWidgetLayout->numRows();
00168     m_optionWidgetLayout->addMultiCellLayout(layout, rowCount, rowCount, 0, 1);
00169 }
00170 
00171 void KisToolPaint::addOptionWidgetOption(QWidget *control, QWidget *label)
00172 {
00173     Q_ASSERT(m_optionWidget != 0);
00174     Q_ASSERT(m_optionWidgetLayout != 0);
00175     if(label)
00176     {
00177         m_optionWidgetLayout->addWidget(label, m_optionWidgetLayout->numRows(), 0);
00178         m_optionWidgetLayout->addWidget(control, m_optionWidgetLayout->numRows()-1, 1);
00179     }
00180     else
00181         m_optionWidgetLayout->addWidget(control, m_optionWidgetLayout->numRows(), 0);
00182 }
00183 
00184 void KisToolPaint::slotSetOpacity(int opacityPerCent)
00185 {
00186     m_opacity = opacityPerCent * OPACITY_OPAQUE / 100;
00187 }
00188 
00189 void KisToolPaint::slotSetCompositeMode(const KisCompositeOp& compositeOp)
00190 {
00191     m_compositeOp = compositeOp;
00192 }
00193 
00194 QCursor KisToolPaint::cursor()
00195 {
00196     return m_cursor;
00197 }
00198 
00199 void KisToolPaint::setCursor(const QCursor& cursor)
00200 {
00201     m_cursor = cursor;
00202 
00203     if (m_subject) {
00204         KisToolControllerInterface *controller = m_subject->toolController();
00205 
00206         if (controller && controller->currentTool() == this) {
00207             m_subject->canvasController()->setCanvasCursor(m_cursor);
00208         }
00209     }
00210 }
00211 
00212 void KisToolPaint::activate()
00213 {
00214     if (m_subject) {
00215         KisToolControllerInterface *controller = m_subject->toolController();
00216 
00217         if (controller)
00218             controller->setCurrentTool(this);
00219             
00220         updateCompositeOpComboBox();
00221 
00222         KisConfig cfg;
00223         m_paintOutline = (cfg.cursorStyle() == CURSOR_STYLE_OUTLINE);
00224     }
00225 }
00226 
00227 void KisToolPaint::notifyModified() const
00228 {
00229     if (m_subject && m_subject->currentImg()) {
00230         m_subject->currentImg()->setModified();
00231     }
00232 }
00233 
00234 void KisToolPaint::updateCompositeOpComboBox()
00235 {
00236     if (m_optionWidget && m_subject) {
00237         KisImageSP img = m_subject->currentImg();
00238 
00239         if (img) {
00240             KisPaintDeviceSP device = img->activeDevice();
00241 
00242             if (device) {
00243                 KisCompositeOpList compositeOps = device->colorSpace()->userVisiblecompositeOps();
00244                 m_cmbComposite->setCompositeOpList(compositeOps);
00245 
00246                 if (compositeOps.find(m_compositeOp) == compositeOps.end()) {
00247                     m_compositeOp = COMPOSITE_OVER;
00248                 }
00249                 m_cmbComposite->setCurrentItem(m_compositeOp);
00250             }
00251         }
00252     }
00253 }
00254 
00255 void KisToolPaint::slotPopupQuickHelp() {
00256     QWhatsThis::display(quickHelp());
00257 }
00258 
00259 #include "kis_tool_paint.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys