chalk

kis_view.cpp
1/* This file is part of KimageShop^WKrayon^WChalk
2 *
3 * Copyright (c) 1999 Matthias Elter <me@kde.org>
4 * 1999 Michael Koch <koch@kde.org>
5 * 1999 Carsten Pfeiffer <pfeiffer@kde.org>
6 * 2002 Patrick Julien <freak@codepimps.org>
7 * 2003-2005 Boudewijn Rempt <boud@valdyas.org>
8 * 2004 Clarence Dang <dang@kde.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24
25#include <algorithm>
26#include <cmath>
27
28// TQt
29#include <tqapplication.h>
30#include <tqbutton.h>
31#include <tqcursor.h>
32#include <tqevent.h>
33#include <tqpainter.h>
34#include <tqscrollbar.h>
35#include <tqspinbox.h>
36#include <tqdockarea.h>
37#include <tqstringlist.h>
38#include <tqstyle.h>
39#include <tqpopupmenu.h>
40#include <tqvaluelist.h>
41#include <tqstringlist.h>
42#include <tqobjectlist.h>
43
44// KDE
45#include <kis_meta_registry.h>
46#include <tdeglobalsettings.h>
47#include <dcopobject.h>
48#include <tdeaction.h>
49#include <kcolordialog.h>
50#include <kiconloader.h>
51#include <tdefiledialog.h>
52#include <tdelocale.h>
53#include <tdemessagebox.h>
54#include <knotifyclient.h>
55#include <kprinter.h>
56#include <kpushbutton.h>
57#include <kstatusbar.h>
58#include <kstdaction.h>
59#include <kinputdialog.h>
60#include <kurldrag.h>
61#include <tdepopupmenu.h>
62#include <kdebug.h>
63#include <ksharedptr.h>
64#include <tdetoolbar.h>
65#include <tdeparts/plugin.h>
66#include <kservice.h>
67#include <ktrader.h>
68#include <tdeparts/componentfactory.h>
69#include <tdeparts/event.h>
70
71// KOffice
72#include <KoPartSelectAction.h>
73#include <KoFilterManager.h>
74#include <KoMainWindow.h>
75#include <KoView.h>
76#include <KoTabBar.h>
77#include <ko_gray_widget.h>
78#include <ko_hsv_widget.h>
79#include <ko_rgb_widget.h>
80#include <kopalettemanager.h>
81#include <kopalette.h>
82
83// Local
84#include "kis_brush.h"
85#include "kis_button_press_event.h"
86#include "kis_button_release_event.h"
87#include "kis_canvas.h"
88#include "kis_canvas_painter.h"
89#include "kis_color.h"
90#include "kis_colorspace_factory_registry.h"
91#include "kis_config.h"
92#include "kis_controlframe.h"
93#include "kis_cursor.h"
94#include "kis_doc.h"
95#include "kis_double_click_event.h"
96#include "kis_factory.h"
97#include "kis_filter_strategy.h"
98#include "kis_gradient.h"
99#include "kis_group_layer.h"
100#include "kis_adjustment_layer.h"
101#include "kis_paint_device.h"
102#include "kis_tool_freehand.h"
103//#include "kis_guide.h"
104#include "kis_layerbox.h"
105#include "kis_import_catcher.h"
106#include "kis_layer.h"
107#include "kis_paint_layer.h"
108#include "kis_move_event.h"
109#include "kis_paint_device.h"
110#include "kis_painter.h"
111#include "kis_paintop_registry.h"
112#include "kis_part_layer.h"
113#include "kis_part_layer_handler.h"
114#include "kis_pattern.h"
115#include "kis_profile.h"
116#include "kis_rect.h"
117#include "kis_resource.h"
118#include "kis_palette.h"
119#include "kis_ruler.h"
120#include "kis_selection.h"
121#include "KoToolBox.h"
122#include "kis_tool.h"
123#include "kis_tool_manager.h"
124#include "kis_transaction.h"
125#include "kis_selected_transaction.h"
126#include "kis_types.h"
127#include "kis_undo_adapter.h"
128#include "kis_view.h"
129#include "kis_view_iface.h"
130#include "kis_label_progress.h"
131#include "kis_opengl_image_context.h"
132#include "kis_background.h"
133#include "kis_paint_device_action.h"
134#include "kis_filter_configuration.h"
135#include "kis_transform_worker.h"
136#include "kis_shear_visitor.h"
137
138#include <kis_resourceserver.h>
139#include <kis_resource_mediator.h>
140
141#include "kis_icon_item.h"
142#include "kis_palette_widget.h"
143#include "kis_birdeye_box.h"
144#include "kis_color.h"
145#include "kis_factory.h"
146
147// Dialog boxes
148#include "kis_dlg_new_layer.h"
149#include "kis_dlg_layer_properties.h"
150#include "kis_dlg_preferences.h"
151#include "kis_dlg_image_properties.h"
152#include "kis_dlg_adjustment_layer.h"
153#include "kis_dlg_adj_layer_props.h"
154
155// Action managers
156#include "kis_selection_manager.h"
157#include "kis_filter_manager.h"
158#include "kis_grid_manager.h"
159#include "kis_perspective_grid_manager.h"
160
161#include "kis_custom_palette.h"
162#include "wdgpalettechooser.h"
163
164#include <fixx11h.h>
165
166// Time in ms that must pass after a tablet event before a mouse event is allowed to
167// change the input device to the mouse. This is needed because mouse events are always
168// sent to a receiver if it does not accept the tablet event.
169#define MOUSE_CHANGE_EVENT_DELAY 100
170
171KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, TQWidget *parent, const char *name)
172 : super(doc, parent, name)
173 , KXMLGUIBuilder( shell() )
174 , m_panning( false )
175 , m_oldTool( 0 )
176 , m_doc( doc )
177 , m_canvas( 0 )
178 , m_partHandler( 0 )
179 , m_gridManager( 0 )
180 , m_perspectiveGridManager( 0 )
181 , m_selectionManager( 0 )
182 , m_filterManager( 0 )
183 , m_paletteManager( 0 )
184 , m_toolManager( 0 )
185 , m_actLayerVis( false )
186 , m_hRuler( 0 )
187 , m_vRuler( 0 )
188 , m_imgFlatten( 0 )
189 , m_imgMergeLayer( 0 )
190 , m_imgRename( 0 )
191 , m_imgResizeToLayer( 0 )
192 , m_imgScan( 0 )
193 , m_actionPartLayer( 0 )
194 , m_layerAdd( 0 )
195 , m_layerBottom( 0 )
196 , m_layerDup( 0 )
197 , m_layerHide( 0 )
198 , m_layerLower( 0 )
199 , m_layerProperties( 0 )
200 , m_layerRaise( 0 )
201 , m_layerRm( 0 )
202 , m_layerSaveAs( 0 )
203 , m_layerTop( 0 )
204 , m_zoomIn( 0 )
205 , m_zoomOut( 0 )
206 , m_actualPixels( 0 )
207 , m_actualSize( 0 )
208 , m_fitToCanvas( 0 )
209 , m_fullScreen( 0 )
210 , m_imgProperties( 0 )
211 , m_RulerAction( 0 )
212 , m_guideAction( 0 )
213 , m_dcop( 0 )
214 , m_hScroll( 0 )
215 , m_vScroll( 0 )
216 , m_scrollX( 0 )
217 , m_scrollY( 0 )
218 , m_canvasXOffset( 0)
219 , m_canvasYOffset( 0)
220 , m_paintViewEnabled( false )
221 , m_guiActivateEventReceived( false )
222 , m_showEventReceived( false )
223 , m_imageLoaded( false )
224// , m_currentGuide( 0 )
225 , m_adapter( adapter )
226 , m_statusBarZoomLabel( 0 )
227 , m_statusBarSelectionLabel( 0 )
228 , m_statusBarProfileLabel( 0 )
229 , m_progress( 0 )
230 , m_layerBox( 0 )
231 , m_toolBox( 0 )
232 , m_brush( 0 )
233 , m_pattern( 0 )
234 , m_gradient( 0 )
235 , m_toolIsPainting( false )
236 , m_monitorProfile( 0 )
237 , m_HDRExposure( 0 )
238{
239
240 Q_ASSERT(doc);
241 Q_ASSERT(adapter);
242 Q_ASSERT(parent);
243
244 KisConfig cfg;
245
246 m_currentColorChooserDisplay = KisID("BLA");
247 setFocusPolicy( TQWidget::StrongFocus );
248
249 // Must come before input devices are referenced as this detects them.
250#ifdef TQ_WS_X11
251 KisCanvasWidget::initX11Support();
252#endif
253 // Install event filter before we create any child widgets so they can see
254 // the tablet events.
255 tqApp->installEventFilter(this);
256
257 m_tabletEventTimer.start();
258 m_inputDevice = KisInputDevice::mouse();
259
260 connect(&m_initialZoomTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotInitialZoomTimeout()));
261
262 m_paletteManager = new KoPaletteManager(this, actionCollection(), "Chalk palette manager");
263 if (cfg.fixDockerWidth()) m_paletteManager->setFixedWidth( 360 );
264
265 m_paletteManager->createPalette( chalk::CONTROL_PALETTE, i18n("Control box"));
266 m_paletteManager->createPalette( chalk::COLORBOX, i18n("Colors"));
267 m_paletteManager->createPalette( chalk::LAYERBOX, i18n("Layers"));
268
269 m_selectionManager = new KisSelectionManager(this, doc);
270 m_filterManager = new KisFilterManager(this, doc);
271 m_toolManager = new KisToolManager(canvasSubject(), getCanvasController());
272 m_gridManager = new KisGridManager(this);
273 m_perspectiveGridManager = new KisPerspectiveGridManager(this);
274
275 // This needs to be set before the dockers are created.
276 m_image = m_doc->currentImage();
277 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
278 m_fg = KisColor(TQt::black, cs);
279 m_bg = KisColor(TQt::white, cs);
280
281 createDockers();
282
283 setInstance(KisFactory::instance(), false);
284 setClientBuilder( this );
285
286 if (!doc->isReadWrite())
287 setXMLFile("chalk_readonly.rc");
288 else
289 setXMLFile("chalk.rc");
290
291 KStdAction::keyBindings( mainWindow()->guiFactory(), TQ_SLOT( configureShortcuts() ), actionCollection() );
292
293 createLayerBox();
294
295 setupCanvas();
296 m_canvas->hide();
297 setupRulers();
298 setupScrollBars();
299 setupStatusBar();
300
301 setupActions();
302 dcopObject();
303
304
305 connect(this, TQ_SIGNAL(autoScroll(const TQPoint &)), TQ_SLOT(slotAutoScroll(const TQPoint &)));
306
307 setMouseTracking(true);
308
309 resetMonitorProfile();
310
311 layersUpdated();
312
313 m_brushesAndStuffToolBar = new KisControlFrame(mainWindow(), this);
314
315 // Load all plugins
316 TDETrader::OfferList offers = TDETrader::self()->query(TQString::fromLatin1("Chalk/ViewPlugin"),
317 TQString::fromLatin1("(Type == 'Service') and "
318 "([X-Chalk-Version] == 2)"));
319 TDETrader::OfferList::ConstIterator iter;
320 for(iter = offers.begin(); iter != offers.end(); ++iter)
321 {
322 KService::Ptr service = *iter;
323 int errCode = 0;
324 KParts::Plugin* plugin =
325 KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, TQStringList(), &errCode);
326 if ( plugin ) {
327 kdDebug(41006) << "found plugin " << service->property("Name").toString() << "\n";
328 insertChildClient(plugin);
329 }
330 else {
331 kdDebug(41006) << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
332 if( errCode == KParts::ComponentFactory::ErrNoLibrary)
333 {
334 kdWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
335 }
336 }
337 }
338
339 if(!doc->isLoading())
340 {
341 slotLoadingFinished();
342 } else {
343 connect(doc, TQ_SIGNAL(loadingFinished()), this, TQ_SLOT(slotLoadingFinished()));
344 }
345
346 setFocus();
347}
348
349KisView::~KisView()
350{
351 KisConfig cfg;
352 cfg.setShowRulers( m_RulerAction->isChecked() );
353
354 delete m_dcop;
355 delete m_paletteManager;
356 delete m_selectionManager;
357 delete m_filterManager;
358 delete m_toolManager;
359
360}
361
362
363static TQt::Dock stringToDock( const TQString& attrPosition )
364{
365 TDEToolBar::Dock dock = TDEToolBar::DockTop;
366 if ( !attrPosition.isEmpty() ) {
367 if ( attrPosition == "top" )
368 dock = TQt::DockTop;
369 else if ( attrPosition == "left" )
370 dock = TQt::DockLeft;
371 else if ( attrPosition == "right" )
372 dock = TQt::DockRight;
373 else if ( attrPosition == "bottom" )
374 dock = TQt::DockBottom;
375 else if ( attrPosition == "floating" )
376 dock = TQt::DockTornOff;
377 else if ( attrPosition == "flat" )
378 dock = TQt::DockMinimized;
379 }
380 return dock;
381}
382
383TQWidget * KisView::createContainer( TQWidget *parent, int index, const TQDomElement &element, int &id )
384{
385 if( element.attribute( "name" ) == "ToolBox" )
386 {
387 m_toolBox = new KoToolBox(mainWindow(), "ToolBox", KisFactory::instance(), NUMBER_OF_TOOLTYPES);
388 m_toolBox->setLabel(i18n("Chalk"));
389 m_toolManager->setUp(m_toolBox, m_paletteManager, actionCollection());
390
391 Dock dock = stringToDock( element.attribute( "position" ).lower() );
392
393 mainWindow()->addDockWindow( m_toolBox, dock, false);
394 mainWindow()->moveDockWindow( m_toolBox, dock, false, 0, 0 );
395 }
396
397 return KXMLGUIBuilder::createContainer( parent, index, element, id );
398
399}
400
401void KisView::removeContainer( TQWidget *container, TQWidget *parent, TQDomElement &element, int id )
402{
403 Q_ASSERT(container);
404
405 if( shell() && container == m_toolBox )
406 {
407 delete m_toolBox;
408 m_toolManager->youAintGotNoToolBox();
409 }
410 else {
411 KXMLGUIBuilder::removeContainer( container, parent, element, id );
412 }
413}
414
415KoPaletteManager * KisView::paletteManager()
416{
417 if (!m_paletteManager) {
418 m_paletteManager = new KoPaletteManager(this, actionCollection(), "Chalk palette manager");
419 TQ_CHECK_PTR(m_paletteManager);
420 }
421 return m_paletteManager;
422}
423
424void KisView::createLayerBox()
425{
426 m_layerBox = new KisLayerBox(this);
427 m_layerBox->setCaption(i18n("Layers"));
428
429 connect(m_layerBox, TQ_SIGNAL(sigRequestLayer(KisGroupLayerSP, KisLayerSP)),
430 this, TQ_SLOT(addLayer(KisGroupLayerSP, KisLayerSP)));
431 connect(m_layerBox, TQ_SIGNAL(sigRequestGroupLayer(KisGroupLayerSP, KisLayerSP)),
432 this, TQ_SLOT(addGroupLayer(KisGroupLayerSP, KisLayerSP)));
433 connect(m_layerBox, TQ_SIGNAL(sigRequestAdjustmentLayer(KisGroupLayerSP, KisLayerSP)),
434 this, TQ_SLOT(addAdjustmentLayer(KisGroupLayerSP, KisLayerSP)));
435 connect(m_layerBox, TQ_SIGNAL(sigRequestPartLayer(KisGroupLayerSP, KisLayerSP, const KoDocumentEntry&)),
436 this, TQ_SLOT(addPartLayer(KisGroupLayerSP, KisLayerSP, const KoDocumentEntry&)));
437 connect(m_layerBox, TQ_SIGNAL(sigRequestLayerProperties(KisLayerSP)),
438 this, TQ_SLOT(showLayerProperties(KisLayerSP)));
439 connect(m_layerBox, TQ_SIGNAL(sigOpacityChanged(int, bool)), this, TQ_SLOT(layerOpacity(int, bool)));
440 connect(m_layerBox, TQ_SIGNAL(sigOpacityFinishedChanging(int, int)),
441 this, TQ_SLOT(layerOpacityFinishedChanging(int, int)));
442 connect(m_layerBox, TQ_SIGNAL(sigItemComposite(const KisCompositeOp&)), this, TQ_SLOT(layerCompositeOp(const KisCompositeOp&)));
443
444 paletteManager()->addWidget(m_layerBox, "layerbox", chalk::LAYERBOX, 0);
445
446}
447
448DCOPObject* KisView::dcopObject()
449{
450 if (!m_dcop) {
451 m_dcop = new KisViewIface(this);
452 TQ_CHECK_PTR(m_dcop);
453 }
454 return m_dcop;
455}
456
457void KisView::setupScrollBars()
458{
459 m_scrollX = 0;
460 m_scrollY = 0;
461 m_vScroll = new TQScrollBar(TQt::Vertical, this);
462 TQ_CHECK_PTR(m_vScroll);
463
464 m_hScroll = new TQScrollBar(TQt::Horizontal, this);
465 TQ_CHECK_PTR(m_hScroll);
466
467 m_vScroll->setGeometry(width() - 16, 20, 16, height() - 36);
468 m_hScroll->setGeometry(20, height() - 16, width() - 36, 16);
469 m_hScroll->setValue(0);
470 m_vScroll->setValue(0);
471 TQObject::connect(m_vScroll, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(scrollV(int)));
472 TQObject::connect(m_hScroll, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(scrollH(int)));
473}
474
475void KisView::setupRulers()
476{
477 m_hRuler = new KisRuler(TQt::Horizontal, this);
478 TQ_CHECK_PTR(m_hRuler);
479
480 m_vRuler = new KisRuler(TQt::Vertical, this);
481 TQ_CHECK_PTR(m_vRuler);
482
483 m_hRuler->setGeometry(20, 0, width() - 20, 20);
484 m_vRuler->setGeometry(0, 20, 20, height() - 20);
485
486 if (statusBar()) {
487 m_hRuler->installEventFilter(this);
488 m_vRuler->installEventFilter(this);
489 }
490}
491
492#define EPSILON 1e-6
493
494void KisView::updateStatusBarZoomLabel ()
495{
496 if (zoom() < 1 - EPSILON) {
497 m_statusBarZoomLabel->setText(i18n("Zoom %1%").arg(zoom() * 100, 0, 'g', 4));
498 } else {
499 m_statusBarZoomLabel->setText(i18n("Zoom %1%").arg(zoom() * 100, 0, 'f', 0));
500 }
501 m_statusBarZoomLabel->setMaximumWidth(m_statusBarZoomLabel->fontMetrics().width(i18n("Zoom %1%").arg("0.8888 ")));
502}
503
504void KisView::updateStatusBarSelectionLabel()
505{
506 if (m_statusBarSelectionLabel == 0) {
507 return;
508 }
509
510 KisImageSP img = currentImg();
511 if (img) {
512 KisPaintDeviceSP dev = img->activeDevice();
513 if (dev) {
514 if (dev->hasSelection()) {
515 TQRect r = dev->selection()->selectedExactRect();
516 m_statusBarSelectionLabel->setText( i18n("Selection Active: x = %1 y = %2 width = %3 height = %4").arg(r.x()).arg(r.y()).arg( r.width()).arg( r.height()));
517 return;
518 }
519 }
520 }
521
522 m_statusBarSelectionLabel->setText(i18n("No Selection"));
523}
524
525void KisView::updateStatusBarProfileLabel()
526{
527 if (m_statusBarProfileLabel == 0) {
528 return;
529 }
530
531 KisImageSP img = currentImg();
532 if (!img) return;
533
534 if (img->getProfile() == 0) {
535 m_statusBarProfileLabel->setText(i18n("No profile"));
536 }
537 else {
538 m_statusBarProfileLabel->setText(img->colorSpace()->id().name() + " " + img->getProfile()->productName());
539 }
540}
541
542
543KisProfile * KisView::monitorProfile()
544{
545 if (m_monitorProfile == 0) {
546 resetMonitorProfile();
547 }
548 return m_monitorProfile;
549}
550
551
552void KisView::resetMonitorProfile()
553{
554 m_monitorProfile = KisProfile::getScreenProfile();
555
556 if (m_monitorProfile == 0) {
557 KisConfig cfg;
558 TQString monitorProfileName = cfg.monitorProfile();
559 m_monitorProfile = KisMetaRegistry::instance()->csRegistry()->getProfileByName(monitorProfileName);
560 }
561
562}
563
564void KisView::setupStatusBar()
565{
566 KStatusBar *sb = statusBar();
567
568 if (sb) {
569 m_statusBarZoomLabel = new TQLabel(sb);
570 addStatusBarItem(m_statusBarZoomLabel,1);
571 updateStatusBarZoomLabel();
572
573 m_statusBarSelectionLabel = new KSqueezedTextLabel(sb);
574 addStatusBarItem(m_statusBarSelectionLabel,2);
575 updateStatusBarSelectionLabel();
576
577 m_statusBarProfileLabel = new KSqueezedTextLabel(sb);
578 addStatusBarItem(m_statusBarProfileLabel,3);
579 updateStatusBarProfileLabel();
580
581 //int height = m_statusBarProfileLabel->height();
582
583 m_progress = new KisLabelProgress(this);
584 m_progress->setMaximumWidth(225);
585 m_progress->setMinimumWidth(225);
586 m_progress->setMaximumHeight(fontMetrics().height() );
587 addStatusBarItem(m_progress, 2, true);
588
589 m_progress->hide();
590 }
591}
592
593void KisView::setupActions()
594{
595 KisConfig cfg;
596
597 m_selectionManager->setup(actionCollection());
598 m_filterManager->setup(actionCollection());
599 m_gridManager->setup(actionCollection());
600 m_perspectiveGridManager->setup(actionCollection());
601
602
603 m_fullScreen = KStdAction::fullScreen( NULL, NULL, actionCollection(), this );
604 connect( m_fullScreen, TQ_SIGNAL( toggled( bool )), this, TQ_SLOT( slotUpdateFullScreen( bool )));
605
606 m_imgProperties = new TDEAction(i18n("Image Properties"), 0, this, TQ_SLOT(slotImageProperties()), actionCollection(), "img_properties");
607 m_imgScan = 0; // How the hell do I get a TDEAction to the scan plug-in?!?
608 m_imgResizeToLayer = new TDEAction(i18n("Resize Image to Size of Current Layer"), 0, this, TQ_SLOT(imgResizeToActiveLayer()), actionCollection(), "resizeimgtolayer");
609
610 // view actions
611 m_zoomIn = KStdAction::zoomIn(this, TQ_SLOT(slotZoomIn()), actionCollection(), "zoom_in");
612 m_zoomOut = KStdAction::zoomOut(this, TQ_SLOT(slotZoomOut()), actionCollection(), "zoom_out");
613 m_actualPixels = new TDEAction(i18n("Actual Pixels"), "Ctrl+0", this, TQ_SLOT(slotActualPixels()), actionCollection(), "actual_pixels");
614 m_actualSize = KStdAction::actualSize(this, TQ_SLOT(slotActualSize()), actionCollection(), "actual_size");
615 m_actualSize->setEnabled(false);
616 m_fitToCanvas = KStdAction::fitToPage(this, TQ_SLOT(slotFitToCanvas()), actionCollection(), "fit_to_canvas");
617
618 // layer actions
619 m_layerAdd = new TDEAction(i18n("&Add..."), "Ctrl+Shift+N", this, TQ_SLOT(layerAdd()), actionCollection(), "insert_layer");
620
621 m_actionPartLayer = new KoPartSelectAction( i18n( "&Object Layer" ), "frame_query",
622 this, TQ_SLOT( addPartLayer() ),
623 actionCollection(), "insert_part_layer" );
624
625
626 m_actionAdjustmentLayer = new TDEAction( i18n( "&Adjustment Layer" ), 0,
627 this, TQ_SLOT( addAdjustmentLayer() ),
628 actionCollection(), "insert_adjustment_layer" );
629
630
631 m_layerRm = new TDEAction(i18n("&Remove"), 0, this, TQ_SLOT(layerRemove()), actionCollection(), "remove_layer");
632 m_layerDup = new TDEAction(i18n("Duplicate"), 0, this, TQ_SLOT(layerDuplicate()), actionCollection(), "duplicate_layer");
633 m_layerHide = new TDEToggleAction(i18n("&Hide"), 0, this, TQ_SLOT(layerToggleVisible()), actionCollection(), "hide_layer");
634 m_layerHide->setCheckedState(KGuiItem(i18n("&Show")));
635 m_layerHide->setChecked(false);
636
637 m_layerRaise = new TDEAction(i18n("Raise"), "raise", "Ctrl+]", this, TQ_SLOT(layerRaise()), actionCollection(), "raiselayer");
638 m_layerLower = new TDEAction(i18n("Lower"), "lower", "Ctrl+[", this, TQ_SLOT(layerLower()), actionCollection(), "lowerlayer");
639 m_layerTop = new TDEAction(i18n("To Top"), "bring_forward", "Ctrl+Shift+]", this, TQ_SLOT(layerFront()), actionCollection(), "toplayer");
640 m_layerBottom = new TDEAction(i18n("To Bottom"), "send_backward", "Ctrl+Shift+[", this, TQ_SLOT(layerBack()), actionCollection(), "bottomlayer");
641 m_layerProperties = new TDEAction(i18n("Properties"), 0, this, TQ_SLOT(layerProperties()), actionCollection(), "layer_properties");
642 (void)new TDEAction(i18n("I&nsert Image as Layer..."), 0, this, TQ_SLOT(slotInsertImageAsLayer()), actionCollection(), "insert_image_as_layer");
643 m_layerSaveAs = new TDEAction(i18n("Save Layer as Image..."), "document-save", this, TQ_SLOT(saveLayerAsImage()), actionCollection(), "save_layer_as_image");
644 (void)new TDEAction(i18n("Flip on &X Axis"), "view_left_right", 0, this, TQ_SLOT(mirrorLayerX()), actionCollection(), "mirrorLayerX");
645 (void)new TDEAction(i18n("Flip on &Y Axis"), "view_top_bottom", 0, this, TQ_SLOT(mirrorLayerY()), actionCollection(), "mirrorLayerY");
646
647 m_createMask = new TDEAction(i18n("Create Mask"), 0, this,
648 TQ_SLOT(slotCreateMask()), actionCollection(), "create_mask");
649 m_maskFromSelection = new TDEAction(i18n("Mask From Selection"), 0, this,
650 TQ_SLOT(slotMaskFromSelection()), actionCollection(),
651 "mask_fromsel");
652 m_maskToSelection = new TDEAction(i18n("Mask to Selection"), 0, this,
653 TQ_SLOT(slotMaskToSelection()), actionCollection(), "mask_tosel");
654 m_applyMask = new TDEAction(i18n("Apply Mask"), 0, this, TQ_SLOT(slotApplyMask()),
655 actionCollection(), "apply_mask");
656 m_removeMask = new TDEAction(i18n("Remove Mask"), 0, this,
657 TQ_SLOT(slotRemoveMask()), actionCollection(), "remove_mask");
658 m_showMask = new TDEToggleAction(i18n( "Show Mask" ), 0, this,
659 TQ_SLOT(slotShowMask()), actionCollection(), "show_mask");
660 m_editMask = new TDEToggleAction(i18n( "Edit Mask" ), 0, this,
661 TQ_SLOT(slotEditMask()), actionCollection(), "edit_mask");
662
663 // image actions
664 m_imgFlatten = new TDEAction(i18n("&Flatten Image"), "Ctrl+Shift+E", this, TQ_SLOT(flattenImage()), actionCollection(), "flatten_image");
665 m_imgMergeLayer = new TDEAction(i18n("&Merge with Layer Below"), "Ctrl+E", this, TQ_SLOT(mergeLayer()), actionCollection(), "merge_layer");
666
667 // setting actions
668 KStdAction::preferences(this, TQ_SLOT(preferences()), actionCollection(), "preferences");
669
670 m_RulerAction = new TDEToggleAction( i18n( "Show Rulers" ), "Ctrl+R", this, TQ_SLOT( showRuler() ), actionCollection(), "view_ruler" );
671 m_RulerAction->setChecked(cfg.showRulers());
672 m_RulerAction->setCheckedState(i18n("Hide Rulers"));
673 m_RulerAction->setWhatsThis( i18n("The rulers show the horizontal and vertical positions of the mouse on the image "
674 "and can be used to position your mouse at the right place on the canvas. <p>Uncheck this to disable "
675 "the rulers from being displayed." ) );
676
677 //m_guideAction = new TDEToggleAction( i18n( "Guide Lines" ), 0, this, TQ_SLOT( viewGuideLines() ), actionCollection(), "view_guidelines" );
678
679 // Add new palette
680 new TDEAction(i18n("Add New Palette..."), 0, this, TQ_SLOT(slotAddPalette()),
681 actionCollection(), "add_palette");
682 new TDEAction(i18n("Edit Palette..."), 0, this, TQ_SLOT(slotEditPalette()),
683 actionCollection(), "edit_palette");
684
685 // XXX: This triggers a repaint of the image, but way too early
686 //showRuler();
687
688}
689
690void KisView::resizeEvent(TQResizeEvent *)
691{
692 if (!m_paintViewEnabled) {
693 startInitialZoomTimerIfReady();
694 }
695
696 KisImageSP img = currentImg();
697 TQ_INT32 scrollBarExtent = style().pixelMetric(TQStyle::PM_ScrollBarExtent);
698 TQ_INT32 drawH;
699 TQ_INT32 drawW;
700 TQ_INT32 docW;
701 TQ_INT32 docH;
702
703// if (img) {
704// KisGuideMgr *mgr = img->guides();
705// mgr->resize(size());
706// }
707
708 docW = static_cast<TQ_INT32>(ceil(docWidth() * zoom()));
709 docH = static_cast<TQ_INT32>(ceil(docHeight() * zoom()));
710
711 m_rulerThickness = m_RulerAction->isChecked() ? RULER_THICKNESS : 0;
712 drawH = height() - m_rulerThickness;
713 drawW = width() - m_rulerThickness;
714
715 if (drawH < docH) {
716 // Will need vert scrollbar
717 drawW -= scrollBarExtent;
718 if (drawW < docW)
719 // Will need horiz scrollbar
720 drawH -= scrollBarExtent;
721 } else if (drawW < docW) {
722 // Will need horiz scrollbar
723 drawH -= scrollBarExtent;
724 if (drawH < docH)
725 // Will need vert scrollbar
726 drawW -= scrollBarExtent;
727 }
728
729 m_vScroll->setEnabled(docH > drawH);
730 m_hScroll->setEnabled(docW > drawW);
731
732 if (docH <= drawH && docW <= drawW) {
733 // we need no scrollbars
734 m_vScroll->hide();
735 m_hScroll->hide();
736 m_vScroll->setValue(0);
737 m_hScroll->setValue(0);
738 m_vScrollBarExtent = 0;
739 m_hScrollBarExtent = 0;
740 } else if (docH <= drawH) {
741 // we need a horizontal scrollbar only
742 m_vScroll->hide();
743 m_vScroll->setValue(0);
744 m_hScroll->setRange(0, docW - drawW);
745 m_hScroll->setGeometry(m_rulerThickness,
746 height() - scrollBarExtent,
747 width() - m_rulerThickness,
748 scrollBarExtent);
749 m_hScroll->show();
750 m_hScrollBarExtent = scrollBarExtent;
751 m_hScrollBarExtent = scrollBarExtent;
752 } else if(docW <= drawW) {
753 // we need a vertical scrollbar only
754 m_hScroll->hide();
755 m_hScroll->setValue(0);
756 m_vScroll->setRange(0, docH - drawH);
757 m_vScroll->setGeometry(width() - scrollBarExtent, m_rulerThickness, scrollBarExtent, height() - m_rulerThickness);
758 m_vScroll->show();
759 m_vScrollBarExtent = scrollBarExtent;
760 } else {
761 // we need both scrollbars
762 m_vScroll->setRange(0, docH - drawH);
763 m_vScroll->setGeometry(width() - scrollBarExtent,
764 m_rulerThickness,
765 scrollBarExtent,
766 height() -2* m_rulerThickness);
767 m_hScroll->setRange(0, docW - drawW);
768 m_hScroll->setGeometry(m_rulerThickness,
769 height() - scrollBarExtent,
770 width() - 2*m_rulerThickness,
771 scrollBarExtent);
772 m_vScroll->show();
773 m_hScroll->show();
774 m_vScrollBarExtent = scrollBarExtent;
775 m_hScrollBarExtent = scrollBarExtent;
776 }
777
778 TQ_INT32 oldCanvasXOffset = m_canvasXOffset;
779 TQ_INT32 oldCanvasYOffset = m_canvasYOffset;
780
781 if (docW < drawW) {
782 m_canvasXOffset = (drawW - docW) / 2;
783 } else {
784 m_canvasXOffset = 0;
785 }
786
787 if (docH < drawH) {
788 m_canvasYOffset = (drawH - docH) / 2;
789 } else {
790 m_canvasYOffset = 0;
791 }
792
793 //Check if rulers are visible
794 if( m_RulerAction->isChecked() )
795 m_canvas->setGeometry(m_rulerThickness, m_rulerThickness, drawW, drawH);
796 else
797 m_canvas->setGeometry(0, 0, drawW, drawH);
798 m_canvas->show();
799
800 if (!m_canvas->isOpenGLCanvas()) {
801
802 if (m_canvasPixmap.size() != TQSize(drawW, drawH)) {
803
804 TQ_INT32 oldCanvasWidth = m_canvasPixmap.width();
805 TQ_INT32 oldCanvasHeight = m_canvasPixmap.height();
806
807 TQ_INT32 newCanvasWidth = drawW;
808 TQ_INT32 newCanvasHeight = drawH;
809
810 TQRegion exposedRegion = TQRect(0, 0, newCanvasWidth, newCanvasHeight);
811
812 // Increase size first so that we can copy the old image area to the new one.
813 m_canvasPixmap.resize(TQMAX(oldCanvasWidth, newCanvasWidth), TQMAX(oldCanvasHeight, newCanvasHeight));
814
815 if (!m_canvasPixmap.isNull()) {
816
817 if (oldCanvasXOffset != m_canvasXOffset || oldCanvasYOffset != m_canvasYOffset) {
818
819 TQ_INT32 srcX;
820 TQ_INT32 srcY;
821 TQ_INT32 srcWidth;
822 TQ_INT32 srcHeight;
823 TQ_INT32 dstX;
824 TQ_INT32 dstY;
825
826 if (oldCanvasXOffset <= m_canvasXOffset) {
827 // Move to the right
828 srcX = 0;
829 dstX = m_canvasXOffset - oldCanvasXOffset;
830 srcWidth = oldCanvasWidth;
831 } else {
832 // Move to the left
833 srcX = oldCanvasXOffset - m_canvasXOffset;
834 dstX = 0;
835 srcWidth = newCanvasWidth;
836 }
837
838 if (oldCanvasYOffset <= m_canvasYOffset) {
839 // Move down
840 srcY = 0;
841 dstY = m_canvasYOffset - oldCanvasYOffset;
842 srcHeight = oldCanvasHeight;
843 } else {
844 // Move up
845 srcY = oldCanvasYOffset - m_canvasYOffset;
846 dstY = 0;
847 srcHeight = newCanvasHeight;
848 }
849
850 bitBlt(&m_canvasPixmap, dstX, dstY, &m_canvasPixmap, srcX, srcY, srcWidth, srcHeight);
851 exposedRegion -= TQRegion(TQRect(dstX, dstY, srcWidth, srcHeight));
852 } else {
853 exposedRegion -= TQRegion(TQRect(0, 0, oldCanvasWidth, oldCanvasHeight));
854 }
855 }
856
857 m_canvasPixmap.resize(newCanvasWidth, newCanvasHeight);
858
859 if (!m_canvasPixmap.isNull() && !exposedRegion.isEmpty()) {
860
861 TQMemArray<TQRect> rects = exposedRegion.rects();
862
863 for (unsigned int i = 0; i < rects.count(); i++) {
864 TQRect r = rects[i];
865 updateTQPaintDeviceCanvas(viewToWindow(r));
866 }
867 }
868 }
869 }
870
871 int fontheight = TQFontMetrics(TDEGlobalSettings::generalFont()).height() * 3;
872 m_vScroll->setPageStep(drawH);
873 m_vScroll->setLineStep(fontheight);
874 m_hScroll->setPageStep(drawW);
875 m_hScroll->setLineStep(fontheight);
876
877 m_hRuler->setGeometry(m_rulerThickness + m_canvasXOffset, 0, TQMIN(docW, drawW), m_rulerThickness);
878 m_vRuler->setGeometry(0, m_rulerThickness + m_canvasYOffset, m_rulerThickness, TQMIN(docH, drawH));
879
880 if (m_vScroll->isVisible())
881 m_vRuler->updateVisibleArea(0, m_vScroll->value());
882 else
883 m_vRuler->updateVisibleArea(0, 0);
884
885 if (m_hScroll->isVisible())
886 m_hRuler->updateVisibleArea(m_hScroll->value(), 0);
887 else
888 m_hRuler->updateVisibleArea(0, 0);
889
890 if( m_RulerAction->isChecked() )
891 {
892 m_hRuler->show();
893 m_vRuler->show();
894 }
895 else {
896 m_hRuler->hide();
897 m_vRuler->hide();
898 }
899
900 emit viewTransformationsChanged();
901}
902
903void KisView::styleChange(TQStyle& oldStyle)
904{
905 Q_UNUSED(oldStyle);
906 m_canvas->updateGeometry();
907 refreshKisCanvas();
908}
909
910void KisView::paletteChange(const TQPalette& oldPalette)
911{
912 Q_UNUSED(oldPalette);
913 refreshKisCanvas();
914}
915
916void KisView::showEvent(TQShowEvent *)
917{
918 if (!m_showEventReceived) {
919 m_showEventReceived = true;
920 startInitialZoomTimerIfReady();
921 }
922}
923
924void KisView::updateReadWrite(bool readwrite)
925{
926 layerUpdateGUI(readwrite);
927}
928
929TQ_INT32 KisView::horzValue() const
930{
931 return m_hScroll->value() - m_canvasXOffset;
932}
933
934TQ_INT32 KisView::vertValue() const
935{
936 return m_vScroll->value() - m_canvasYOffset;
937}
938
939void KisView::updateTQPaintDeviceCanvas(const TQRect& imageRect)
940{
941 TQRect vr = windowToView(imageRect);
942 vr &= TQRect(0, 0, m_canvas->width(), m_canvas->height());
943
944 if (!vr.isEmpty()) {
945
946 TQPainter gc;
947
948 if (!m_canvasPixmap.isNull() && gc.begin(&m_canvasPixmap)) {
949
950 KisImageSP img = currentImg();
951
952 if (img && m_paintViewEnabled) {
953
954 TQRect wr = viewToWindow(vr);
955
956 if (wr.left() < 0 || wr.right() >= img->width() || wr.top() < 0 || wr.bottom() >= img->height()) {
957 // Erase areas outside document
958 TQRegion rg(vr);
959 rg -= TQRegion(windowToView(TQRect(0, 0, img->width(), img->height())));
960
961 TQMemArray<TQRect> rects = rg.rects();
962
963 for (unsigned int i = 0; i < rects.count(); i++) {
964 TQRect er = rects[i];
965 gc.fillRect(er, colorGroup().mid());
966 }
967 wr &= TQRect(0, 0, img->width(), img->height());
968 }
969
970 if (!wr.isEmpty()) {
971
972 KisImage::PaintFlags paintFlags = (KisImage::PaintFlags)KisImage::PAINT_BACKGROUND;
973
974 if (m_actLayerVis) {
975 paintFlags = (KisImage::PaintFlags)(paintFlags|KisImage::PAINT_MASKINACTIVELAYERS);
976 }
977
978 if (m_selectionManager->displaySelection())
979 {
980 paintFlags = (KisImage::PaintFlags)(paintFlags|KisImage::PAINT_SELECTION);
981 }
982
983 if (zoom() > 1.0 - EPSILON) {
984
985 gc.setWorldXForm(true);
986 gc.translate(-horzValue(), -vertValue());
987 gc.scale(zoomFactor(), zoomFactor());
988
989 m_image->renderToPainter(wr.left(), wr.top(),
990 wr.right(), wr.bottom(), gc, monitorProfile(),
991 paintFlags, HDRExposure());
992 } else {
993
994 TQRect canvasRect = windowToView(wr);
995 TQRect scaledImageRect = canvasRect;
996 scaledImageRect.moveBy(horzValue(), vertValue());
997
998 TQSize scaledImageSize(static_cast<TQ_INT32>(ceil(docWidth() * zoom())),
999 static_cast<TQ_INT32>(ceil(docHeight() * zoom())));
1000
1001 TQImage image = m_image->convertToTQImage(scaledImageRect, scaledImageSize,
1002 monitorProfile(), paintFlags, HDRExposure());
1003
1004 gc.drawImage(canvasRect.topLeft(), image, image.rect());
1005
1006 // Set up for the grid drawer.
1007 gc.setWorldXForm(true);
1008 gc.translate(-horzValue(), -vertValue());
1009 gc.scale(zoomFactor(), zoomFactor());
1010 }
1011
1012 m_gridManager->drawGrid( wr, &gc );
1013 m_perspectiveGridManager->drawGrid( wr, &gc );
1014 }
1015// paintGuides();
1016 } else {
1017 gc.fillRect(vr, colorGroup().mid());
1018 }
1019 }
1020 }
1021}
1022
1023void KisView::paintTQPaintDeviceView(const TQRegion& canvasRegion)
1024{
1025 Q_ASSERT(m_canvas->TQPaintDeviceWidget() != 0);
1026
1027 if (m_canvas->TQPaintDeviceWidget() != 0 && !m_canvasPixmap.isNull()) {
1028 TQMemArray<TQRect> rects = canvasRegion.rects();
1029
1030 for (unsigned int i = 0; i < rects.count(); i++) {
1031 TQRect r = rects[i];
1032
1033 bitBlt(m_canvas->TQPaintDeviceWidget(), r.x(), r.y(), &m_canvasPixmap,
1034 r.x(), r.y(), r.width(), r.height());
1035 }
1036
1037 paintToolOverlay(canvasRegion);
1038 }
1039}
1040
1041void KisView::updateOpenGLCanvas(const TQRect& imageRect)
1042{
1043#ifdef HAVE_GL
1044 KisImageSP img = currentImg();
1045
1046 if (img && m_paintViewEnabled) {
1047 Q_ASSERT(m_OpenGLImageContext != 0);
1048
1049 if (m_OpenGLImageContext != 0) {
1050 m_OpenGLImageContext->update(imageRect);
1051 }
1052 }
1053#else
1054 Q_UNUSED(imageRect);
1055#endif
1056}
1057
1058void KisView::paintOpenGLView(const TQRect& canvasRect)
1059{
1060#ifdef HAVE_GL
1061 if (!m_canvas->isUpdatesEnabled()) {
1062 return;
1063 }
1064
1065 m_canvas->OpenGLWidget()->makeCurrent();
1066
1067 glDrawBuffer(GL_BACK);
1068
1069 TQColor widgetBackgroundColor = colorGroup().mid();
1070
1071 glClearColor(widgetBackgroundColor.red() / 255.0, widgetBackgroundColor.green() / 255.0, widgetBackgroundColor.blue() / 255.0, 1.0);
1072 glClear(GL_COLOR_BUFFER_BIT);
1073
1074 KisImageSP img = currentImg();
1075
1076 if (img && m_paintViewEnabled) {
1077
1078 TQRect vr = canvasRect;
1079 vr &= TQRect(0, 0, m_canvas->width(), m_canvas->height());
1080
1081 if (!vr.isNull()) {
1082
1083 glMatrixMode(GL_PROJECTION);
1084 glLoadIdentity();
1085 glViewport(0, 0, m_canvas->width(), m_canvas->height());
1086 glOrtho(0, m_canvas->width(), m_canvas->height(), 0, -1, 1);
1087
1088 glMatrixMode(GL_MODELVIEW);
1089 glLoadIdentity();
1090
1091 glBindTexture(GL_TEXTURE_2D, m_OpenGLImageContext->backgroundTexture());
1092
1093 glTranslatef(m_canvasXOffset, m_canvasYOffset, 0.0);
1094
1095 glEnable(GL_TEXTURE_2D);
1096 glBegin(GL_QUADS);
1097
1098 glTexCoord2f(0.0, 0.0);
1099 glVertex2f(0.0, 0.0);
1100
1101 glTexCoord2f((img->width() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_WIDTH, 0.0);
1102 glVertex2f(img->width() * zoom(), 0.0);
1103
1104 glTexCoord2f((img->width() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_WIDTH,
1105 (img->height() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_HEIGHT);
1106 glVertex2f(img->width() * zoom(), img->height() * zoom());
1107
1108 glTexCoord2f(0.0, (img->height() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_HEIGHT);
1109 glVertex2f(0.0, img->height() * zoom());
1110
1111 glEnd();
1112
1113 glTranslatef(-m_canvasXOffset, -m_canvasYOffset, 0.0);
1114
1115 glTranslatef(-horzValue(), -vertValue(), 0.0);
1116 glScalef(zoomFactor(), zoomFactor(), 1.0);
1117
1118 glEnable(GL_BLEND);
1119 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1120
1121 TQRect wr = viewToWindow(TQRect(0, 0, m_canvas->width(), m_canvas->height()));
1122 wr &= TQRect(0, 0, img->width(), img->height());
1123
1124 m_OpenGLImageContext->setHDRExposure(HDRExposure());
1125
1126 m_canvas->OpenGLWidget()->makeCurrent();
1127
1128 for (int x = (wr.left() / m_OpenGLImageContext->imageTextureTileWidth()) * m_OpenGLImageContext->imageTextureTileWidth();
1129 x <= wr.right();
1130 x += m_OpenGLImageContext->imageTextureTileWidth()) {
1131 for (int y = (wr.top() / m_OpenGLImageContext->imageTextureTileHeight()) * m_OpenGLImageContext->imageTextureTileHeight();
1132 y <= wr.bottom();
1133 y += m_OpenGLImageContext->imageTextureTileHeight()) {
1134
1135 glBindTexture(GL_TEXTURE_2D, m_OpenGLImageContext->imageTextureTile(x, y));
1136
1137 glBegin(GL_QUADS);
1138
1139 glTexCoord2f(0.0, 0.0);
1140 glVertex2f(x, y);
1141
1142 glTexCoord2f(1.0, 0.0);
1143 glVertex2f(x + m_OpenGLImageContext->imageTextureTileWidth(), y);
1144
1145 glTexCoord2f(1.0, 1.0);
1146 glVertex2f(x + m_OpenGLImageContext->imageTextureTileWidth(), y + m_OpenGLImageContext->imageTextureTileHeight());
1147
1148 glTexCoord2f(0.0, 1.0);
1149 glVertex2f(x, y + m_OpenGLImageContext->imageTextureTileHeight());
1150
1151 glEnd();
1152 }
1153 }
1154
1155 glDisable(GL_TEXTURE_2D);
1156 glDisable(GL_BLEND);
1157
1158 m_gridManager->drawGrid(wr, 0, true);
1159 m_perspectiveGridManager->drawGrid( wr, 0, true );
1160
1161 // Unbind the texture otherwise the ATI driver crashes when the canvas context is
1162 // made current after the textures are deleted following an image resize.
1163 glBindTexture(GL_TEXTURE_2D, 0);
1164
1165 //paintGuides();
1166 }
1167 }
1168
1169 m_canvas->OpenGLWidget()->swapBuffers();
1170
1171 paintToolOverlay(TQRegion(canvasRect));
1172
1173#else
1174 Q_UNUSED(canvasRect);
1175#endif
1176}
1177
1178void KisView::setInputDevice(KisInputDevice inputDevice)
1179{
1180 if (inputDevice != m_inputDevice) {
1181 m_inputDevice = inputDevice;
1182
1183 m_toolManager->setToolForInputDevice(m_inputDevice, inputDevice);
1184
1185 if (m_toolManager->currentTool() == 0) {
1186 m_toolManager->setCurrentTool(m_toolManager->findTool("tool_brush", m_inputDevice));
1187 }
1188 else {
1189 m_toolManager->setCurrentTool(m_toolManager->currentTool());
1190 }
1191 m_toolManager->activateCurrentTool();
1192
1193 emit sigInputDeviceChanged(inputDevice);
1194 }
1195
1196}
1197
1198KisInputDevice KisView::currentInputDevice() const
1199{
1200 return m_inputDevice;
1201}
1202
1203
1204KisCanvas *KisView::kiscanvas() const
1205{
1206 return m_canvas;
1207}
1208
1210{
1211 if (m_image) {
1212 updateCanvas(m_image->bounds());
1213 }
1214}
1215
1216void KisView::updateCanvas(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
1217{
1218 updateCanvas(TQRect(x, y, w, h));
1219}
1220
1221void KisView::updateCanvas(const TQRect& imageRect)
1222{
1223 if (m_canvas->isOpenGLCanvas()) {
1224 updateOpenGLCanvas(imageRect);
1225 paintOpenGLView(windowToView(imageRect));
1226 } else {
1227 updateTQPaintDeviceCanvas(imageRect);
1228 //m_canvas->update(windowToView(imageRect));
1229 m_canvas->repaint(windowToView(imageRect));
1230 }
1231}
1232
1233void KisView::refreshKisCanvas()
1234{
1235 TQRect imageRect = viewToWindow(TQRect(0, 0, m_canvas->width(), m_canvas->height()));
1236
1237 if (m_image) {
1238 imageRect |= m_image->bounds();
1239 }
1240
1241 updateCanvas(imageRect);
1242
1243 // Enable this if updateCanvas does an m_canvas->update()
1244 //m_canvas->repaint();
1245}
1246
1247void KisView::selectionDisplayToggled(bool displaySelection)
1248{
1249#ifdef HAVE_GL
1250 if (m_canvas->isOpenGLCanvas()) {
1251 if (m_OpenGLImageContext) {
1252 m_OpenGLImageContext->setSelectionDisplayEnabled(displaySelection);
1253 }
1254 }
1255#else
1256 Q_UNUSED(displaySelection);
1257#endif
1258 updateCanvas();
1259}
1260
1261void KisView::layerUpdateGUI(bool enable)
1262{
1263 KisImageSP img = currentImg();
1264
1265 KisLayerSP layer;
1266 TQ_INT32 nlayers = 0;
1267 TQ_INT32 nvisible = 0;
1268
1269
1270
1271 if (img) {
1272 layer = img->activeLayer();
1273 nlayers = img->nlayers();
1274 nvisible = nlayers - img->nHiddenLayers();
1275 }
1276
1277 KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(layer.data());
1278
1279 if (pl && ( m_currentColorChooserDisplay != KisID("BLA") ||
1280 pl->paintDevice()->colorSpace()->id() != m_currentColorChooserDisplay)) {
1281 if (pl->paintDevice()->colorSpace()->id() == KisID("WET")) {
1282 m_paletteManager->hideWidget( "hsvwidget" );
1283 m_paletteManager->hideWidget( "rgbwidget" );
1284 m_paletteManager->hideWidget( "graywidget" );
1285 m_paletteManager->hideWidget( "palettewidget" );
1286 m_paletteManager->showWidget( "watercolor docker" );
1287 }
1288 else {
1289 m_paletteManager->hideWidget( "watercolor docker" );
1290 m_paletteManager->showWidget( "palettewidget" );
1291 m_paletteManager->showWidget( "graywidget" );
1292 m_paletteManager->showWidget( "rgbwidget" );
1293 m_paletteManager->showWidget( "hsvwidget" );
1294 }
1295 m_currentColorChooserDisplay = pl->paintDevice()->colorSpace()->id();
1296 }
1297
1298 enable = enable && img && layer && layer->visible() && !layer->locked();
1299 m_layerDup->setEnabled(enable);
1300 m_layerRm->setEnabled(enable);
1301 m_layerHide->setEnabled(img && layer);
1302 m_layerProperties->setEnabled(enable);
1303 m_layerSaveAs->setEnabled(enable);
1304 m_layerRaise->setEnabled(enable && layer->prevSibling());
1305 m_layerLower->setEnabled(enable && layer->nextSibling());
1306 m_layerTop->setEnabled(enable && nlayers > 1 && layer != img->rootLayer()->firstChild());
1307 m_layerBottom->setEnabled(enable && nlayers > 1 && layer != img->rootLayer()->lastChild());
1308
1309 // XXX these should be named layer instead of img
1310 m_imgFlatten->setEnabled(nlayers > 1);
1311 m_imgMergeLayer->setEnabled(nlayers > 1 && layer && layer->nextSibling());
1312
1313
1314 m_selectionManager->updateGUI();
1315 m_filterManager->updateGUI();
1316 m_toolManager->updateGUI();
1317 m_gridManager->updateGUI();
1318 m_perspectiveGridManager->updateGUI();
1319
1320
1321 KisPartLayer * partLayer = dynamic_cast<KisPartLayer*>(layer.data());
1322 if (partLayer) {
1323 setCanvasCursor( KisCursor::arrowCursor() );
1324 }
1325
1326 if (img && img->activeDevice())
1327 emit currentColorSpaceChanged(img->activeDevice()->colorSpace());
1328
1329 imgUpdateGUI();
1330}
1331
1332
1333void KisView::imgUpdateGUI()
1334{
1335 KisImageSP img = currentImg();
1336
1337 m_imgResizeToLayer->setEnabled(img && img->activeLayer());
1338
1339 updateStatusBarProfileLabel();
1340}
1341
1342static const double zoomLevels[] = {
1343 1.0 / 500,
1344 1.0 / 333.333333,
1345 1.0 / 250,
1346 1.0 / 200,
1347 1.0 / 150,
1348 1.0 / 100,
1349 1.0 / 66.666667,
1350 1.0 / 50,
1351 1.0 / 33.333333,
1352 1.0 / 25,
1353 1.0 / 20,
1354 1.0 / 16,
1355 1.0 / 12,
1356 1.0 / 8,
1357 1.0 / 6,
1358 1.0 / 4,
1359 1.0 / 3,
1360 1.0 / 2,
1361 1.0 / 1.5,
1362 1,
1363 2,
1364 3,
1365 4,
1366 5,
1367 6,
1368 7,
1369 8,
1370 12,
1371 16
1372};
1373
1374#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
1375#define NUM_ZOOM_LEVELS ARRAY_SIZE(zoomLevels)
1376
1377#define FIRST_ZOOM_LEVEL_INDEX 0
1378#define LAST_ZOOM_LEVEL_INDEX (NUM_ZOOM_LEVELS - 1)
1379
1380#define KISVIEW_MIN_ZOOM (zoomLevels[FIRST_ZOOM_LEVEL_INDEX])
1381#define KISVIEW_MAX_ZOOM (zoomLevels[LAST_ZOOM_LEVEL_INDEX])
1382
1383double KisView::nextZoomInLevel() const
1384{
1385 uint zoomLevelIndex = FIRST_ZOOM_LEVEL_INDEX;
1386
1387 while (zoom() >= zoomLevels[zoomLevelIndex] && zoomLevelIndex < LAST_ZOOM_LEVEL_INDEX) {
1388 zoomLevelIndex++;
1389 }
1390
1391 return zoomLevels[zoomLevelIndex];
1392}
1393
1394double KisView::nextZoomOutLevel(double zoomLevel) const
1395{
1396 int zoomLevelIndex = LAST_ZOOM_LEVEL_INDEX;
1397
1398 while (zoomLevel <= zoomLevels[zoomLevelIndex] && zoomLevelIndex > FIRST_ZOOM_LEVEL_INDEX) {
1399 zoomLevelIndex--;
1400 }
1401
1402 return zoomLevels[zoomLevelIndex];
1403}
1404
1405double KisView::nextZoomOutLevel() const
1406{
1407 return nextZoomOutLevel(zoom());
1408}
1409
1410void KisView::zoomAroundPoint(double x, double y, double zf)
1411{
1412 // Disable updates while we change the scrollbar settings.
1413 m_canvas->setUpdatesEnabled(false);
1414 m_hScroll->setUpdatesEnabled(false);
1415 m_vScroll->setUpdatesEnabled(false);
1416
1417 if (x < 0 || y < 0) {
1418 // Zoom about the centre of the current display
1419 KisImageSP img = currentImg();
1420
1421 if (img) {
1422 if (m_hScroll->isVisible()) {
1423 KisPoint c = viewToWindow(KisPoint(m_canvas->width() / 2.0, m_canvas->height() / 2.0));
1424 x = c.x();
1425 }
1426 else {
1427 x = img->width() / 2.0;
1428 }
1429
1430 if (m_vScroll->isVisible()) {
1431 KisPoint c = viewToWindow(KisPoint(m_canvas->width() / 2.0, m_canvas->height() / 2.0));
1432 y = c.y();
1433 }
1434 else {
1435 y = img->height() / 2.0;
1436 }
1437 }
1438 else {
1439 x = 0;
1440 y = 0;
1441 }
1442 }
1443
1444 setZoom(zf);
1445
1446 Q_ASSERT(m_zoomIn);
1447 Q_ASSERT(m_zoomOut);
1448
1449 updateStatusBarZoomLabel ();
1450
1451 m_zoomIn->setEnabled(zf < KISVIEW_MAX_ZOOM);
1452 m_zoomOut->setEnabled(zf > KISVIEW_MIN_ZOOM);
1453 resizeEvent(0);
1454
1455 m_hRuler->setZoom(zf);
1456 m_vRuler->setZoom(zf);
1457
1458 if (m_hScroll->isVisible()) {
1459 double vcx = m_canvas->width() / 2.0;
1460 TQ_INT32 scrollX = tqRound(x * zoom() - vcx);
1461 m_hScroll->setValue(scrollX);
1462 }
1463
1464 if (m_vScroll->isVisible()) {
1465 double vcy = m_canvas->height() / 2.0;
1466 TQ_INT32 scrollY = tqRound(y * zoom() - vcy);
1467 m_vScroll->setValue(scrollY);
1468 }
1469
1470 // Now update everything.
1471 m_canvas->setUpdatesEnabled(true);
1472 m_hScroll->setUpdatesEnabled(true);
1473 m_vScroll->setUpdatesEnabled(true);
1474 m_hScroll->update();
1475 m_vScroll->update();
1476
1477 if (m_canvas->isOpenGLCanvas()) {
1478 paintOpenGLView(TQRect(0, 0, m_canvas->width(), m_canvas->height()));
1479 } else {
1480 refreshKisCanvas();
1481 }
1482
1483 emit viewTransformationsChanged();
1484}
1485
1486void KisView::zoomTo(const KisRect& r)
1487{
1488 if (!r.isNull()) {
1489
1490 double wZoom = fabs(m_canvas->width() / r.width());
1491 double hZoom = fabs(m_canvas->height() / r.height());
1492
1493 double zf = kMin(wZoom, hZoom);
1494
1495 if (zf < KISVIEW_MIN_ZOOM) {
1496 zf = KISVIEW_MIN_ZOOM;
1497 }
1498 else
1499 if (zf > KISVIEW_MAX_ZOOM) {
1500 zf = KISVIEW_MAX_ZOOM;
1501 }
1502
1503 zoomAroundPoint(r.center().x(), r.center().y(), zf);
1504 }
1505}
1506
1507void KisView::zoomTo(const TQRect& r)
1508{
1509 zoomTo(KisRect(r));
1510}
1511
1512void KisView::zoomTo(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
1513{
1514 zoomTo(KisRect(x, y, w, h));
1515}
1516
1517void KisView::zoomIn(TQ_INT32 x, TQ_INT32 y)
1518{
1519 zoomAroundPoint(x, y, nextZoomInLevel());
1520}
1521
1522void KisView::zoomOut(TQ_INT32 x, TQ_INT32 y)
1523{
1524 zoomAroundPoint(x, y, nextZoomOutLevel());
1525}
1526
1527void KisView::zoomIn()
1528{
1529 slotZoomIn();
1530}
1531
1532void KisView::zoomOut()
1533{
1534 slotZoomOut();
1535}
1536
1537void KisView::slotZoomIn()
1538{
1539 zoomIn(-1, -1);
1540}
1541
1542void KisView::slotZoomOut()
1543{
1544 zoomOut(-1, -1);
1545}
1546
1547void KisView::slotActualPixels()
1548{
1549 zoomAroundPoint(-1, -1, 1.0);
1550}
1551
1552void KisView::slotActualSize()
1553{
1554 //XXX later this should be update to take screen res and image res into consideration
1555 zoomAroundPoint(-1, -1, 1.0);
1556}
1557
1558double KisView::fitToCanvasZoomLevel() const
1559{
1560 int fullCanvasWidth = width();
1561
1562 if (m_vRuler->isVisible()) {
1563 fullCanvasWidth -= m_vRuler->width();
1564 }
1565
1566 int fullCanvasHeight = height();
1567
1568 if (m_hRuler->isVisible()) {
1569 fullCanvasHeight -= m_hRuler->height();
1570 }
1571
1572 KisImageSP img = currentImg();
1573 if (img) {
1574 double xZoomLevel = static_cast<double>(fullCanvasWidth) / img->width();
1575 double yZoomLevel = static_cast<double>(fullCanvasHeight) / img->height();
1576
1577 return TQMIN(xZoomLevel, yZoomLevel);
1578 }
1579 else {
1580 return 1;
1581 }
1582}
1583
1584void KisView::slotFitToCanvas()
1585{
1586 zoomAroundPoint(-1, -1, fitToCanvasZoomLevel());
1587}
1588
1589void KisView::setInitialZoomLevel()
1590{
1591 double zoomLevel = fitToCanvasZoomLevel();
1592
1593 if (zoomLevel > 1) {
1594 zoomLevel = 1;
1595 } else {
1596 zoomLevel = nextZoomOutLevel(zoomLevel);
1597 }
1598
1599 zoomAroundPoint(-1, -1, zoomLevel);
1600}
1601
1602void KisView::imgResizeToActiveLayer()
1603{
1604 KisImageSP img = currentImg();
1605 KisLayerSP layer;
1606
1607 if (img && (layer = img->activeLayer())) {
1608
1609 if (m_adapter && m_adapter->undo()) {
1610 m_adapter->beginMacro(i18n("Resize Image to Size of Current Layer"));
1611 }
1612
1613 img->lock();
1614
1615 TQRect r = layer->exactBounds();
1616 img->resize(r.width(), r.height(), r.x(), r.y(), true);
1617
1618 img->unlock();
1619
1620 if (m_adapter && m_adapter->undo()) {
1621 m_adapter->endMacro();
1622 }
1623 }
1624}
1625
1626void KisView::slotImageProperties()
1627{
1628 KisImageSP img = currentImg();
1629
1630 if (!img) return;
1631
1632 KisDlgImageProperties dlg(img, this);
1633
1634 if (dlg.exec() == TQDialog::Accepted) {
1635 if (dlg.imageWidth() != img->width() ||
1636 dlg.imageHeight() != img->height()) {
1637
1638 resizeCurrentImage(dlg.imageWidth(),
1639 dlg.imageHeight());
1640 }
1641 TQ_INT32 opacity = dlg.opacity();
1642 opacity = opacity * 255 / 100;
1643 img->setName(dlg.imageName());
1644 img->setColorSpace(dlg.colorSpace());
1645 img->setResolution(dlg.resolution(), dlg.resolution());
1646 img->setDescription(dlg.description());
1647 img->setProfile(dlg.profile());
1648 }
1649}
1650
1651void KisView::slotInsertImageAsLayer()
1652{
1653 if (importImage() > 0)
1654 m_doc->setModified(true);
1655}
1656
1657void KisView::slotAddPalette()
1658{
1659 KDialogBase* base = new KDialogBase(this, 0, true, i18n("Add Palette"), KDialogBase::Ok | KDialogBase::Cancel);
1660 KisCustomPalette* p = new KisCustomPalette(base, "add palette", i18n("Add Palette"), this);
1661 base->setMainWidget(p);
1662 base->show();
1663}
1664
1665void KisView::slotEditPalette()
1666{
1667 KisPaletteChooser chooser(this);
1668 KisResourceServerBase* srv = KisResourceServerRegistry::instance()->get("PaletteServer");
1669 if (!srv) {
1670 return;
1671 }
1672 TQValueList<KisResource*> resources = srv->resources();
1673 TQValueList<KisPalette*> palettes;
1674
1675 for(uint i = 0; i < resources.count(); i++) {
1676 KisPalette* palette = dynamic_cast<KisPalette*>(*resources.at(i));
1677
1678 chooser.paletteList->insertItem(palette->name());
1679 palettes.append(palette);
1680 }
1681
1682 if (chooser.exec() != TQDialog::Accepted ) {
1683 return;
1684 }
1685
1686 int index = chooser.paletteList->currentItem();
1687 if (index < 0) {
1688 KMessageBox::error(this, i18n("No palette selected."), i18n("Palette"));
1689 return;
1690 }
1691
1692 KDialogBase* base = new KDialogBase(this, 0, true, i18n("Edit Palette") , KDialogBase::Ok);
1693 KisCustomPalette* cp = new KisCustomPalette(base, "edit palette",
1694 i18n("Edit Palette"), this);
1695 cp->setEditMode(true);
1696 cp->setPalette(*palettes.at(index));
1697 base->setMainWidget(cp);
1698 base->show();
1699}
1700
1701void KisView::saveLayerAsImage()
1702{
1703 TQStringList listMimeFilter = KoFilterManager::mimeFilter("application/x-chalk", KoFilterManager::Export);
1704 TQString mimelist = listMimeFilter.join(" ");
1705
1706 KFileDialog fd (TQString(), mimelist, this, "Export Layer", true);
1707 fd.setCaption(i18n("Export Layer"));
1708 fd.setMimeFilter(listMimeFilter);
1709 fd.setOperationMode(KFileDialog::Saving);
1710
1711 if (!fd.exec()) return;
1712
1713 KURL url = fd.selectedURL();
1714 TQString mimefilter = fd.currentMimeFilter();
1715
1716 if (url.isEmpty())
1717 return;
1718
1719
1720 KisImageSP img = currentImg();
1721 if (!img) return;
1722
1723 KisLayerSP l = img->activeLayer();
1724 if (!l) return;
1725
1726 TQRect r = l->exactBounds();
1727
1728 KisDoc d;
1729 d.prepareForImport();
1730
1731 KisImageSP dst = new KisImage(d.undoAdapter(), r.width(), r.height(), img->colorSpace(), l->name());
1732 d.setCurrentImage( dst );
1733 dst->addLayer(l->clone(),dst->rootLayer(),0);
1734
1735 d.setOutputMimeType(mimefilter.latin1());
1736 d.exp0rt(url);
1737}
1738
1739
1740
1741TQ_INT32 KisView::importImage(const KURL& urlArg)
1742{
1743 KisImageSP currentImage = currentImg();
1744
1745 if (!currentImage) {
1746 return 0;
1747 }
1748
1749 KURL::List urls;
1750 TQ_INT32 rc = 0;
1751
1752 if (urlArg.isEmpty()) {
1753 TQString mimelist = KoFilterManager::mimeFilter("application/x-chalk", KoFilterManager::Import).join(" ");
1754 urls = KFileDialog::getOpenURLs(TQString(), mimelist, 0, i18n("Import Image"));
1755 } else {
1756 urls.push_back(urlArg);
1757 }
1758
1759 if (urls.empty())
1760 return 0;
1761
1762 for (KURL::List::iterator it = urls.begin(); it != urls.end(); ++it) {
1763 new KisImportCatcher( *it, currentImage );
1764 }
1765
1766 updateCanvas();
1767
1768 return rc;
1769}
1770
1771void KisView::rotateLayer180()
1772{
1773 rotateLayer( M_PI );
1774}
1775
1776void KisView::rotateLayerLeft90()
1777{
1778 rotateLayer( M_PI/2 - 2*M_PI );
1779}
1780
1781void KisView::rotateLayerRight90()
1782{
1783 rotateLayer( M_PI/2 );
1784}
1785
1786void KisView::mirrorLayerX()
1787{
1788 if (!currentImg()) return;
1789 KisPaintDeviceSP dev = currentImg()->activeDevice();
1790 if (!dev) return;
1791
1792 KisTransaction * t = 0;
1793 if (undoAdapter() && undoAdapter()->undo()) {
1794 t = new KisTransaction(i18n("Mirror Layer X"), dev);
1795 TQ_CHECK_PTR(t);
1796 }
1797
1798 dev->mirrorX();
1799
1800 if (t) undoAdapter()->addCommand(t);
1801
1802 m_doc->setModified(true);
1803 layersUpdated();
1804 updateCanvas();
1805}
1806
1807void KisView::mirrorLayerY()
1808{
1809 if (!currentImg()) return;
1810 KisPaintDeviceSP dev = currentImg()->activeDevice();
1811 if (!dev) return;
1812
1813 KisTransaction * t = 0;
1814 if (undoAdapter() && undoAdapter()->undo()) {
1815 t = new KisTransaction(i18n("Mirror Layer Y"), dev);
1816 TQ_CHECK_PTR(t);
1817 }
1818
1819 dev->mirrorY();
1820
1821 if (t) undoAdapter()->addCommand(t);
1822
1823 m_doc->setModified(true);
1824 layersUpdated();
1825 updateCanvas();
1826}
1827
1828void KisView::scaleLayer(double sx, double sy, KisFilterStrategy *filterStrategy)
1829{
1830 if (!currentImg()) return;
1831
1832 KisPaintDeviceSP dev = currentImg()->activeDevice();
1833 if (!dev) return;
1834
1835 KisSelectedTransaction * t = 0;
1836 if (undoAdapter() && undoAdapter()->undo()) {
1837 t = new KisSelectedTransaction(i18n("Scale Layer"), dev);
1838 TQ_CHECK_PTR(t);
1839 }
1840
1841 KisTransformWorker worker(dev, sx, sy, 0, 0, 0.0, 0, 0, m_progress, filterStrategy);
1842 worker.run();
1843
1844 if (t) undoAdapter()->addCommand(t);
1845 currentImg()->rootLayer()->setDirty(false);
1846 m_doc->setModified(true);
1847 layersUpdated();
1848 updateCanvas();
1849}
1850
1851void KisView::rotateLayer(double radians)
1852{
1853 if (!currentImg()) return;
1854
1855 KisPaintDeviceSP dev = currentImg()->activeDevice();
1856 if (!dev) return;
1857
1858 KisSelectedTransaction * t = 0;
1859 if (undoAdapter() && undoAdapter()->undo()) {
1860 t = new KisSelectedTransaction(i18n("Rotate Layer"), dev);
1861 TQ_CHECK_PTR(t);
1862 }
1863
1864 KisFilterStrategy *filter = KisFilterStrategyRegistry::instance()->get(KisID("Triangle"));
1865 TQRect r;
1866 if(dev->hasSelection())
1867 r = dev->selection()->selectedExactRect();
1868 else
1869 r = dev->exactBounds();
1870 double cx = r.x()+r.width()/2.0;
1871 double cy = r.y()+r.height()/2.0;
1872 TQ_INT32 tx = TQ_INT32(cx*cos(radians) - cy*sin(radians) - cx + 0.5);
1873 TQ_INT32 ty = TQ_INT32(cy*cos(radians) + cx*sin(radians) - cy + 0.5);
1874
1875 KisTransformWorker tw(dev, 1.0, 1.0, 0, 0, radians, -tx, -ty, m_progress, filter);
1876 tw.run();
1877
1878 if (t) undoAdapter()->addCommand(t);
1879
1880 m_doc->setModified(true);
1881 layersUpdated();
1882 updateCanvas();
1883}
1884
1885void KisView::shearLayer(double angleX, double angleY)
1886{
1887 if (!currentImg()) return;
1888
1889 KisLayerSP layer = currentImg()->activeLayer();
1890 if (!layer) return;
1891
1892 KisUndoAdapter * undo = 0;
1893 if ((undo = currentImg()->undoAdapter())) {
1894 undo->beginMacro(i18n("Shear layer"));
1895 }
1896
1897 KisShearVisitor v(angleX, angleY, m_progress);
1898 v.setUndoAdapter(undo);
1899 layer->accept(v);
1900
1901 if (undo) undo->endMacro();
1902
1903 m_doc->setModified(true);
1904 layersUpdated();
1905 updateCanvas();
1906}
1907
1908void KisView::flattenImage()
1909{
1910 KisImageSP img = currentImg();
1911
1912 if (img) {
1913 bool doIt = true;
1914
1915 if (img->nHiddenLayers() > 0) {
1916 int answer = KMessageBox::warningYesNo(this,
1917 i18n("The image contains hidden layers that will be lost."),
1918 i18n("Flatten Image"),
1919 i18n("&Flatten Image"),
1920 KStdGuiItem::cancel());
1921
1922 if (answer != KMessageBox::Yes) {
1923 doIt = false;
1924 }
1925 }
1926
1927 if (doIt) {
1928 img->flatten();
1929 }
1930 }
1931}
1932
1933void KisView::mergeLayer()
1934{
1935 KisImageSP img = currentImg();
1936 if (!img) return;
1937
1938 KisLayerSP layer = img->activeLayer();
1939 if (!layer) return;
1940
1941 img->mergeLayer(layer);
1942}
1943
1944void KisView::preferences()
1945{
1946#ifdef HAVE_GL
1947 bool canvasWasOpenGL = m_canvas->isOpenGLCanvas();
1948#endif
1949
1950 if (PreferencesDialog::editPreferences())
1951 {
1952 KisConfig cfg;
1953 m_paletteManager->slotResetFont();
1954 resetMonitorProfile();
1955
1956#ifdef HAVE_GL
1957 if (cfg.useOpenGL() != canvasWasOpenGL) {
1958
1959 disconnectCurrentImg();
1960
1961 //XXX: Need to notify other views that this global setting has changed.
1962 if (cfg.useOpenGL()) {
1963 m_OpenGLImageContext = KisOpenGLImageContext::getImageContext(m_image, monitorProfile());
1964 m_canvas->createOpenGLCanvas(m_OpenGLImageContext->sharedContextWidget());
1965 } else
1966 {
1967 m_OpenGLImageContext = 0;
1968 m_canvas->createTQPaintDeviceCanvas();
1969 }
1970
1971 connectCurrentImg();
1972
1973 resizeEvent(0);
1974 }
1975
1976 if (cfg.useOpenGL()) {
1977 m_OpenGLImageContext->setMonitorProfile(monitorProfile());
1978 }
1979#endif
1980
1981 refreshKisCanvas();
1982
1983 if (m_toolManager->currentTool()) {
1984 setCanvasCursor(m_toolManager->currentTool()->cursor());
1985 }
1986
1987#if defined(EXTENDED_X11_TABLET_SUPPORT)
1988 m_canvas->selectTabletDeviceEvents();
1989#endif
1990
1991 }
1992}
1993
1994void KisView::layerCompositeOp(const KisCompositeOp& compositeOp)
1995{
1996 KisImageSP img = currentImg();
1997 if (!img) return;
1998
1999 KisLayerSP layer = img->activeLayer();
2000 if (!layer) return;
2001
2002 if (img->undo()) {
2003 KNamedCommand *cmd = layer->setCompositeOpCommand(compositeOp);
2004 cmd->execute();
2005 undoAdapter()->addCommand(cmd);
2006 }
2007}
2008
2009// range: 0 - 100
2010void KisView::layerOpacity(int opacity, bool dontundo)
2011{
2012 KisImageSP img = currentImg();
2013 if (!img) return;
2014
2015 KisLayerSP layer = img->activeLayer();
2016 if (!layer) return;
2017
2018 opacity = int(float(opacity * 255) / 100 + 0.5);
2019 if (opacity > 255)
2020 opacity = 255;
2021
2022 if (opacity == layer->opacity()) return;
2023
2024 if (dontundo)
2025 layer->setOpacity( opacity );
2026 else
2027 {
2028 if (img->undo()) {
2029 KNamedCommand *cmd = layer->setOpacityCommand(opacity);
2030 cmd->execute();
2031 undoAdapter()->addCommand(cmd);
2032 }
2033 }
2034}
2035
2036void KisView::layerOpacityFinishedChanging( int previous, int opacity )
2037{
2038 KisImageSP img = currentImg();
2039 if (!img) return;
2040
2041 KisLayerSP layer = img->activeLayer();
2042 if (!layer) return;
2043
2044 opacity = int(float(opacity * 255) / 100 + 0.5);
2045 if (opacity > 255)
2046 opacity = 255;
2047
2048 previous = int(float(previous * 255) / 100 + 0.5);
2049 if (previous > 255)
2050 previous = 255;
2051
2052 if (previous == opacity) return;
2053
2054 if (img->undo()) {
2055 KNamedCommand *cmd = layer->setOpacityCommand(previous, opacity);
2056 m_adapter->addCommand(cmd);
2057 }
2058}
2059
2060
2061void KisView::showRuler()
2062{
2063 if( m_RulerAction->isChecked() )
2064 {
2065 m_hRuler->show();
2066 m_vRuler->show();
2067 }
2068 else
2069 {
2070 m_hRuler->hide();
2071 m_vRuler->hide();
2072 }
2073
2074 resizeEvent(0);
2075 refreshKisCanvas();
2076}
2077
2078void KisView::slotUpdateFullScreen(bool toggle)
2079{
2080 if (KoView::shell()) {
2081
2082 uint newState = KoView::shell()->windowState();
2083
2084 if (toggle) {
2085 newState |= TQt::WindowFullScreen;
2086 } else {
2087 newState &= ~TQt::WindowFullScreen;
2088 }
2089
2090 KoView::shell()->setWindowState(newState);
2091 }
2092}
2093
2094TQ_INT32 KisView::docWidth() const
2095{
2096 return currentImg() ? currentImg()->width() : 0;
2097}
2098
2099TQ_INT32 KisView::docHeight() const
2100{
2101 return currentImg() ? currentImg()->height() : 0;
2102}
2103
2104void KisView::scrollTo(TQ_INT32 x, TQ_INT32 y)
2105{
2106 if (m_hScroll->isVisible()) {
2107 m_hScroll->setValue(x);
2108 }
2109 if (m_vScroll->isVisible()) {
2110 m_vScroll->setValue(y);
2111 }
2112}
2113
2114void KisView::brushActivated(KisResource *brush)
2115{
2116
2117 m_brush = dynamic_cast<KisBrush*>(brush);
2118
2119 if (m_brush )
2120 {
2121 emit brushChanged(m_brush);
2123 }
2124}
2125
2126void KisView::patternActivated(KisResource *pattern)
2127{
2128 m_pattern = dynamic_cast<KisPattern*>(pattern);
2129
2130 if (m_pattern) {
2131 emit patternChanged(m_pattern);
2133 }
2134}
2135
2136void KisView::gradientActivated(KisResource *gradient)
2137{
2138
2139 m_gradient = dynamic_cast<KisGradient*>(gradient);
2140
2141 if (m_gradient) {
2142 emit gradientChanged(m_gradient);
2144 }
2145}
2146
2147void KisView::paintopActivated(const KisID & paintop, const KisPaintOpSettings *paintopSettings)
2148{
2149 if (paintop.id().isNull() || paintop.id().isEmpty()) {
2150 return;
2151 }
2152
2153 m_paintop = paintop;
2154 m_paintopSettings = paintopSettings;
2155 emit paintopChanged(m_paintop, paintopSettings);
2157}
2158
2159void KisView::setBGColor(const KisColor& c)
2160{
2161 m_bg = c;
2163 emit sigBGQColorChanged( c.toTQColor() );
2164}
2165
2166void KisView::setFGColor(const KisColor& c)
2167{
2168 m_fg = c;
2170 emit sigFGQColorChanged( c.toTQColor() );
2171}
2172
2173void KisView::slotSetFGColor(const KisColor& c)
2174{
2175
2176 m_fg = c;
2178}
2179
2180void KisView::slotSetBGColor(const KisColor& c)
2181{
2182
2183 m_bg = c;
2185}
2186
2187void KisView::slotSetFGQColor(const TQColor& c)
2188{
2189 KisColorSpace * monitorSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA"), m_monitorProfile);
2190 setFGColor(KisColor(c, monitorSpace));
2191 emit sigFGQColorChanged(c);
2192}
2193
2194void KisView::slotSetBGQColor(const TQColor& c)
2195{
2196 KisColorSpace * monitorSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA"), m_monitorProfile);
2197 setBGColor(KisColor(c, monitorSpace));
2198 emit sigBGQColorChanged(c);
2199}
2200
2201
2202void KisView::setupPrinter(KPrinter& printer)
2203{
2204 KisImageSP img = currentImg();
2205
2206 if (img) {
2207 printer.setPageSelection(KPrinter::ApplicationSide);
2208 printer.setPageSize(KPrinter::A4);
2209 printer.setOrientation(KPrinter::Portrait);
2210 }
2211}
2212
2213void KisView::print(KPrinter& printer)
2214{
2215 TQPainter gc(&printer);
2216
2217 KisImageSP img = currentImg();
2218 if (!img) return;
2219
2220 printer.setFullPage(true);
2221 gc.setClipping(false);
2222
2223 KisConfig cfg;
2224 TQString printerProfileName = cfg.printerProfile();
2225 KisProfile * printerProfile = KisMetaRegistry::instance()->csRegistry() ->getProfileByName(printerProfileName);
2226
2227 TQRect r = img->bounds();
2228 img->renderToPainter(r.x(), r.y(), r.width(), r.height(), gc, printerProfile, KisImage::PAINT_IMAGE_ONLY, HDRExposure());
2229}
2230
2231void KisView::paintToolOverlay(const TQRegion& region)
2232{
2233 if (!region.isEmpty() && m_toolManager->currentTool() && !m_toolIsPainting) {
2234 KisCanvasPainter gc(m_canvas);
2235
2236 gc.setClipRegion(region);
2237 gc.setClipping(true);
2238
2239 // Prevent endless loop if the tool needs to have the canvas repainted
2240 m_toolIsPainting = true;
2241 m_toolManager->currentTool()->paint(gc, region.boundingRect());
2242 m_toolIsPainting = false;
2243 }
2244}
2245
2246void KisView::canvasGotPaintEvent(TQPaintEvent *event)
2247{
2248 if (m_canvas->isOpenGLCanvas()) {
2249 paintOpenGLView(event->rect());
2250 } else {
2251 paintTQPaintDeviceView(event->region());
2252 }
2253}
2254
2255void KisView::canvasGotButtonPressEvent(KisButtonPressEvent *e)
2256{
2257#if defined(EXTENDED_X11_TABLET_SUPPORT)
2258 // The event filter doesn't see tablet events going to the canvas.
2259 if (e->device() != KisInputDevice::mouse()) {
2260 m_tabletEventTimer.start();
2261 }
2262#endif // EXTENDED_X11_TABLET_SUPPORT
2263
2264 if (e->device() != currentInputDevice()) {
2265 if (e->device() == KisInputDevice::mouse()) {
2266 if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
2267 setInputDevice(KisInputDevice::mouse());
2268 }
2269 } else {
2270 setInputDevice(e->device());
2271 }
2272 }
2273
2274 KisImageSP img = currentImg();
2275
2276// if (img) {
2277// TQPoint pt = mapToScreen(e->pos().floorTQPoint());
2278// KisGuideMgr *mgr = img->guides();
2279//
2280// m_lastGuidePoint = mapToScreen(e->pos().floorTQPoint());
2281// m_currentGuide = 0;
2282//
2283// if ((e->state() & ~TQt::ShiftButton) == TQt::NoButton) {
2284// KisGuideSP gd = mgr->find(static_cast<TQ_INT32>(pt.x() / zoom()), static_cast<TQ_INT32>(pt.y() / zoom()), TQMAX(2.0, 2.0 / zoom()));
2285//
2286// if (gd) {
2287// m_currentGuide = gd;
2288//
2289// if ((e->button() == TQt::RightButton) || ((e->button() & TQt::ShiftButton) == TQt::ShiftButton)) {
2290// if (gd->isSelected())
2291// mgr->unselect(gd);
2292// else
2293// mgr->select(gd);
2294// } else {
2295// if (!gd->isSelected()) {
2296// mgr->unselectAll();
2297// mgr->select(gd);
2298// }
2299// }
2300//
2301// updateGuides();
2302// return;
2303// }
2304// }
2305// }
2306 if (e->button() == TQt::RightButton) {
2307 TQPopupMenu * m_popup = 0;
2308 if (factory()) {
2309 Q_ASSERT(factory());
2310 m_popup = (TQPopupMenu *)factory()->container("image_popup", this);
2311 }
2312 if (m_popup) {
2313 m_popup->popup(e->globalPos().roundTQPoint());
2314 }
2315 }
2316 else if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
2317 KisPoint p = viewToWindow(e->pos());
2318 // somewhat of a hack: we should actually test if we intersect with the scrollers,
2319 // but the globalPos seems to be off by a few pixels
2320 if (m_vScroll->draggingSlider() || m_hScroll->draggingSlider())
2321 return;
2322
2323 if (m_toolManager->currentTool()->wantsAutoScroll()) {
2324 enableAutoScroll();
2325 }
2326
2327 KisButtonPressEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
2328 m_toolManager->currentTool()->buttonPress(&ev);
2329 }
2330}
2331
2332void KisView::canvasGotMoveEvent(KisMoveEvent *e)
2333{
2334#if defined(EXTENDED_X11_TABLET_SUPPORT)
2335 // The event filter doesn't see tablet events going to the canvas.
2336 if (e->device() != KisInputDevice::mouse()) {
2337 m_tabletEventTimer.start();
2338 }
2339#endif // EXTENDED_X11_TABLET_SUPPORT
2340
2341 if (e->device() != currentInputDevice()) {
2342 if (e->device() == KisInputDevice::mouse()) {
2343 if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
2344 setInputDevice(KisInputDevice::mouse());
2345 }
2346 } else {
2347 setInputDevice(e->device());
2348 }
2349 }
2350
2351 KisImageSP img = currentImg();
2352
2353 m_hRuler->updatePointer(e->pos().floorX() - m_canvasXOffset, e->pos().floorY() - m_canvasYOffset);
2354 m_vRuler->updatePointer(e->pos().floorX() - m_canvasXOffset, e->pos().floorY() - m_canvasYOffset);
2355
2356 KisPoint wp = viewToWindow(e->pos());
2357
2358#if 0
2359 if (img && m_currentGuide) {
2360 TQPoint p = mapToScreen(e->pos().floorTQPoint());
2361 KisGuideMgr *mgr = img->guides();
2362
2363 if (((e->state() & TQt::LeftButton) == TQt::LeftButton) && mgr->hasSelected()) {
2364 eraseGuides();
2365 p -= m_lastGuidePoint;
2366
2367 if (p.x())
2368 mgr->moveSelectedByX(p.x() / zoom());
2369
2370 if (p.y())
2371 mgr->moveSelectedByY(p.y() / zoom());
2372
2373 m_doc->setModified(true);
2374 paintGuides();
2375 }
2376 } else
2377#endif
2378 if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
2379 KisMoveEvent ev(e->device(), wp, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->state());
2380
2381 m_toolManager->currentTool()->move(&ev);
2382 }
2383
2384// m_lastGuidePoint = mapToScreen(e->pos().floorTQPoint());
2385 emit cursorPosition(wp.floorX(), wp.floorY());
2386}
2387
2388int KisView::leftBorder() const
2389{
2390 return m_rulerThickness;
2391}
2392
2393int KisView::rightBorder() const
2394{
2395 return m_hScrollBarExtent;
2396}
2397
2398int KisView::topBorder() const
2399{
2400 return m_rulerThickness;
2401}
2402
2403int KisView::bottomBorder() const
2404{
2405 return m_vScrollBarExtent;
2406}
2407
2408void KisView::mouseMoveEvent(TQMouseEvent *e)
2409{
2410 KisMoveEvent ke(currentInputDevice(), KisPoint(e->pos()), KisPoint(e->globalPos()), PRESSURE_DEFAULT, 0, 0, e->state());
2411 canvasGotMoveEvent(&ke);
2412}
2413
2414void KisView::slotAutoScroll(const TQPoint &p)
2415{
2416 scrollTo(horzValue()+p.x(), vertValue()+p.y());
2417}
2418
2419void KisView::canvasGotButtonReleaseEvent(KisButtonReleaseEvent *e)
2420{
2421#if defined(EXTENDED_X11_TABLET_SUPPORT)
2422 // The event filter doesn't see tablet events going to the canvas.
2423 if (e->device() != KisInputDevice::mouse()) {
2424 m_tabletEventTimer.start();
2425 }
2426#endif // EXTENDED_X11_TABLET_SUPPORT
2427
2428 if (e->device() != currentInputDevice()) {
2429 if (e->device() == KisInputDevice::mouse()) {
2430 if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
2431 setInputDevice(KisInputDevice::mouse());
2432 }
2433 } else {
2434 setInputDevice(e->device());
2435 }
2436 }
2437
2438 KisImageSP img = currentImg();
2439
2440// if (img && m_currentGuide) {
2441// m_currentGuide = 0;
2442// } else
2443 if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
2444 KisPoint p = viewToWindow(e->pos());
2445 KisButtonReleaseEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
2446
2447 disableAutoScroll();
2448 if (m_toolManager->currentTool()) {
2449 m_toolManager->currentTool()->buttonRelease(&ev);
2450 }
2451 }
2452}
2453
2454void KisView::canvasGotDoubleClickEvent(KisDoubleClickEvent *e)
2455{
2456#if defined(EXTENDED_X11_TABLET_SUPPORT)
2457 // The event filter doesn't see tablet events going to the canvas.
2458 if (e->device() != KisInputDevice::mouse()) {
2459 m_tabletEventTimer.start();
2460 }
2461#endif // EXTENDED_X11_TABLET_SUPPORT
2462
2463 if (e->device() != currentInputDevice()) {
2464 if (e->device() == KisInputDevice::mouse()) {
2465 if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
2466 setInputDevice(KisInputDevice::mouse());
2467 }
2468 } else {
2469 setInputDevice(e->device());
2470 }
2471 }
2472
2473 if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
2474 KisPoint p = viewToWindow(e->pos());
2475 KisDoubleClickEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
2476
2477 if (m_toolManager->currentTool()) {
2478 m_toolManager->currentTool()->doubleClick(&ev);
2479 }
2480 }
2481}
2482
2483void KisView::canvasGotEnterEvent(TQEvent *e)
2484{
2485 Q_UNUSED( e );
2486}
2487
2488void KisView::canvasGotLeaveEvent (TQEvent *e)
2489{
2490 Q_UNUSED( e );
2491}
2492
2493void KisView::canvasGotMouseWheelEvent(TQWheelEvent *event)
2494{
2495 //if(event->state() == ControlButton )
2496 //{
2497 if(event->delta() / 120 != 0)
2498 {
2499 if(event->delta() > 0)
2500 {
2501 zoomIn();
2502 } else {
2503 zoomOut();
2504 }
2505 if (m_oldTool) {
2506 KisCanvasPainter gc(m_canvas);
2507 m_oldTool->paint(gc);
2508 }
2509 }
2510 //} else {
2511 // TQApplication::sendEvent(m_vScroll, event);
2512 //}
2513}
2514
2515void KisView::canvasGotKeyPressEvent(TQKeyEvent *event)
2516{
2517 if (!m_toolManager->currentTool()) {
2518 event->ignore();
2519 return;
2520 }
2521
2522 if (event->key() == TQt::Key_Space) {
2523 if (!m_panning) {
2524 // Set tool temporarily to pan
2525 m_panning = true;
2526 m_oldTool = m_toolManager->currentTool();
2527 m_toolManager->setCurrentTool( "tool_pan" );
2528 }
2529 else {
2530 // Unset panning
2531 m_panning = false;
2532 m_toolManager->setCurrentTool( m_oldTool );
2533 m_oldTool = 0;
2534 }
2535 }
2536 if (m_toolManager->currentTool())
2537 m_toolManager->currentTool()->keyPress(event);
2538}
2539
2540void KisView::canvasGotKeyReleaseEvent(TQKeyEvent *event)
2541{
2542 if (m_toolManager->currentTool())
2543 m_toolManager->currentTool()->keyRelease(event);
2544}
2545
2546void KisView::canvasGotDragEnterEvent(TQDragEnterEvent *event)
2547{
2548 bool accept = false;
2549
2550 // Only accept drag if we're not busy, particularly as we may
2551 // be showing a progress bar and calling tqApp->processEvents().
2552 if (KURLDrag::canDecode(event) && TQApplication::overrideCursor() == 0) {
2553 accept = true;
2554 }
2555
2556 event->accept(accept);
2557}
2558
2559void KisView::canvasGotDropEvent(TQDropEvent *event)
2560{
2561 KURL::List urls;
2562
2563 if (KURLDrag::decode(event, urls))
2564 {
2565 if (urls.count() > 0) {
2566 enum enumActionId {
2567 addLayerId = 1,
2568 addDocumentId = 2,
2569 cancelId
2570 };
2571
2572 TDEPopupMenu popup(this, "drop_popup");
2573
2574 if (urls.count() == 1) {
2575 if (currentImg() != 0) {
2576 popup.insertItem(i18n("Insert as New Layer"), addLayerId);
2577 }
2578 popup.insertItem(i18n("Open in New Document"), addDocumentId);
2579 }
2580 else {
2581 if (currentImg() != 0) {
2582 popup.insertItem(i18n("Insert as New Layers"), addLayerId);
2583 }
2584 popup.insertItem(i18n("Open in New Documents"), addDocumentId);
2585 }
2586
2587 popup.insertSeparator();
2588 popup.insertItem(i18n("Cancel"), cancelId);
2589
2590 int actionId = popup.exec(TQCursor::pos());
2591
2592 if (actionId >= 0 && actionId != cancelId) {
2593 for (KURL::List::ConstIterator it = urls.begin (); it != urls.end (); ++it) {
2594 KURL url = *it;
2595
2596 switch (actionId) {
2597 case addLayerId:
2598 importImage(url);
2599 break;
2600 case addDocumentId:
2601 if (shell() != 0) {
2602 shell()->openDocument(url);
2603 }
2604 break;
2605 }
2606 }
2607 }
2608 }
2609 }
2610}
2611
2612void KisView::layerProperties()
2613{
2614 if (currentImg() && currentImg()->activeLayer())
2615 showLayerProperties(currentImg()->activeLayer());
2616}
2617
2618namespace {
2619 class KisChangeFilterCmd : public KNamedCommand {
2620 typedef KNamedCommand super;
2621
2622 public:
2623 // The TQStrings are the _serialized_ configs
2624 KisChangeFilterCmd(KisAdjustmentLayerSP layer,
2625 KisFilterConfiguration* config,
2626 const TQString& before,
2627 const TQString& after) : super(i18n("Change Filter"))
2628 {
2629 m_layer = layer;
2630 m_config = config;
2631 m_before = before;
2632 m_after = after;
2633 }
2634 public:
2635 virtual void execute()
2636 {
2637 TQApplication::setOverrideCursor(KisCursor::waitCursor());
2638 m_config->fromXML(m_after);
2639 //Q_ASSERT(m_after == m_config->toString());
2640 m_layer->setFilter(m_config);
2641 m_layer->setDirty();
2642 TQApplication::restoreOverrideCursor();
2643 }
2644
2645 virtual void unexecute()
2646 {
2647 TQApplication::setOverrideCursor(KisCursor::waitCursor());
2648 m_config->fromXML(m_before);
2649 //Q_ASSERT(m_before == m_config->toString());
2650 m_layer->setFilter(m_config);
2651 m_layer->setDirty();
2652 TQApplication::restoreOverrideCursor();
2653 }
2654 private:
2655 KisAdjustmentLayerSP m_layer;
2656 KisFilterConfiguration* m_config;
2657 TQString m_before;
2658 TQString m_after;
2659 };
2660}
2661
2662void KisView::showLayerProperties(KisLayerSP layer)
2663{
2664 Q_ASSERT( layer );
2665 if ( !layer ) return;
2666
2667 KisColorSpace * cs = 0;
2668 KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>( layer.data() );
2669 if ( pl ) {
2670 cs = pl->paintDevice()->colorSpace();
2671 }
2672 else {
2673 cs = layer->image()->colorSpace();
2674 }
2675
2676
2677 if (KisAdjustmentLayerSP alayer = dynamic_cast<KisAdjustmentLayer*>(layer.data()))
2678 {
2679 KisDlgAdjLayerProps dlg(alayer, alayer->name(), i18n("Adjustment Layer Properties"), this, "dlgadjlayerprops");
2680 TQString before = dlg.filterConfiguration()->toString();
2681 if (dlg.exec() == TQDialog::Accepted)
2682 {
2683 KisChangeFilterCmd * cmd = new KisChangeFilterCmd(alayer,
2684 dlg.filterConfiguration(),
2685 before,
2686 dlg.filterConfiguration()->toString());
2687 cmd->execute();
2688 m_adapter->addCommand(cmd);
2689 m_doc->setModified( true );
2690 }
2691 }
2692 else
2693 {
2694 KisDlgLayerProperties dlg(layer->name(),
2695 layer->opacity(),
2696 layer->compositeOp(),
2697 cs);
2698 if (dlg.exec() == TQDialog::Accepted)
2699 {
2700 if (layer->name() != dlg.getName() ||
2701 layer->opacity() != dlg.getOpacity() ||
2702 layer->compositeOp() != dlg.getCompositeOp())
2703 {
2704 TQApplication::setOverrideCursor(KisCursor::waitCursor());
2705 m_adapter->beginMacro(i18n("Property Changes"));
2706 layer->image()->setLayerProperties(layer, dlg.getOpacity(), dlg.getCompositeOp(), dlg.getName());
2707 layer->setDirty();
2708 m_adapter->endMacro();
2709 TQApplication::restoreOverrideCursor();
2710 m_doc->setModified( true );
2711 }
2712 }
2713 }
2714}
2715
2716void KisView::layerAdd()
2717{
2718 KisImageSP img = currentImg();
2719 if (img && img->activeLayer()) {
2720 addLayer(img->activeLayer()->parent(), img->activeLayer());
2721 }
2722 else if (img)
2723 addLayer(static_cast<KisGroupLayer*>(img->rootLayer().data()), 0);
2724}
2725
2726void KisView::addLayer(KisGroupLayerSP parent, KisLayerSP above)
2727{
2728 KisImageSP img = currentImg();
2729 if (img) {
2730 KisConfig cfg;
2731 TQString profilename;
2732 if(img->colorSpace()->getProfile())
2733 profilename = img->colorSpace()->getProfile()->productName();
2734 NewLayerDialog dlg(img->colorSpace()->id(), profilename, img->nextLayerName(), this);
2735
2736 if (dlg.exec() == TQDialog::Accepted) {
2737 KisColorSpace* cs = KisMetaRegistry::instance()-> csRegistry() ->
2738 getColorSpace(dlg.colorSpaceID(),dlg.profileName());
2739 KisLayerSP layer = new KisPaintLayer(img, dlg.layerName(), dlg.opacity(), cs);
2740 if (layer) {
2741 layer->setCompositeOp(dlg.compositeOp());
2742 img->addLayer(layer, parent.data(), above);
2743 updateCanvas();
2744 } else {
2745 KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
2746 }
2747 }
2748 else {
2749 img->rollBackLayerName();
2750 }
2751 }
2752}
2753
2754void KisView::addGroupLayer(KisGroupLayerSP parent, KisLayerSP above)
2755{
2756 KisImageSP img = currentImg();
2757 if (img) {
2758 TQString profilename;
2759 if(img->colorSpace()->getProfile())
2760 profilename = img->colorSpace()->getProfile()->productName();
2761 KisConfig cfg;
2762 NewLayerDialog dlg(img->colorSpace()->id(), profilename, img->nextLayerName(), this);
2763 dlg.setColorSpaceEnabled(false);
2764
2765 if (dlg.exec() == TQDialog::Accepted) {
2766 KisLayerSP layer = new KisGroupLayer(img, dlg.layerName(), dlg.opacity());
2767 if (layer) {
2768 layer->setCompositeOp(dlg.compositeOp());
2769 img->addLayer(layer, parent.data(), above);
2770 updateCanvas();
2771 } else {
2772 KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
2773 }
2774 }
2775 }
2776}
2777
2778void KisView::addPartLayer()
2779{
2780 KisImageSP img = currentImg();
2781 if (!img) return;
2782
2783 addPartLayer(img->rootLayer(), img->rootLayer()->firstChild(), m_actionPartLayer->documentEntry());
2784}
2785
2786void KisView::addPartLayer(KisGroupLayerSP parent, KisLayerSP above, const KoDocumentEntry& entry)
2787{
2788 delete m_partHandler; // Only one at a time
2789 m_partHandler = new KisPartLayerHandler(this, entry, parent, above);
2790
2791 disconnect(m_canvas, TQ_SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)), this, 0);
2792 disconnect(m_canvas, TQ_SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)), this, 0);
2793 disconnect(m_canvas, TQ_SIGNAL(sigGotMoveEvent(KisMoveEvent*)), this, 0);
2794 disconnect(m_canvas, TQ_SIGNAL(sigGotKeyPressEvent(TQKeyEvent*)), this, 0);
2795
2796 connect(m_canvas, TQ_SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)),
2797 m_partHandler, TQ_SLOT(gotButtonPressEvent(KisButtonPressEvent*)));
2798 connect(m_canvas, TQ_SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)),
2799 m_partHandler, TQ_SLOT(gotButtonReleaseEvent(KisButtonReleaseEvent*)));
2800 connect(m_canvas, TQ_SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
2801 m_partHandler, TQ_SLOT(gotMoveEvent(KisMoveEvent*)));
2802 connect(m_canvas, TQ_SIGNAL(sigGotKeyPressEvent(TQKeyEvent*)),
2803 m_partHandler, TQ_SLOT(gotKeyPressEvent(TQKeyEvent*)));
2804
2805 connect(m_partHandler, TQ_SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
2806 this, TQ_SLOT(canvasGotMoveEvent(KisMoveEvent*)));
2807 connect(m_partHandler, TQ_SIGNAL(sigGotKeyPressEvent(TQKeyEvent*)),
2808 this, TQ_SLOT(canvasGotKeyPressEvent(TQKeyEvent*)));
2809 connect(m_partHandler, TQ_SIGNAL(handlerDone()),
2810 this, TQ_SLOT(reconnectAfterPartInsert()));
2811}
2812
2813void KisView::insertPart(const TQRect& viewRect, const KoDocumentEntry& entry,
2814 KisGroupLayerSP parent, KisLayerSP above) {
2815 KisImageSP img = currentImg();
2816 if (!img) return;
2817
2818 KoDocument* doc = entry.createDoc(m_doc);
2819 if ( !doc )
2820 return;
2821
2822 if ( !doc->showEmbedInitDialog(this) )
2823 return;
2824
2825 TQRect rect = viewToWindow(viewRect);
2826
2827 KisChildDoc * childDoc = m_doc->createChildDoc(rect, doc);
2828
2829 KisPartLayerImpl* partLayer = new KisPartLayerImpl(img, childDoc);
2830 partLayer->setDocType(entry.service()->genericName());
2831 img->addLayer(partLayer, parent, above);
2832 m_doc->setModified(true);
2833
2834 reconnectAfterPartInsert();
2835}
2836
2837void KisView::reconnectAfterPartInsert() {
2838 connect(m_canvas, TQ_SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)),
2839 this, TQ_SLOT(canvasGotButtonPressEvent(KisButtonPressEvent*)));
2840 connect(m_canvas, TQ_SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)),
2841 this, TQ_SLOT(canvasGotButtonReleaseEvent(KisButtonReleaseEvent*)));
2842 connect(m_canvas, TQ_SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
2843 this, TQ_SLOT(canvasGotMoveEvent(KisMoveEvent*)));
2844 connect(m_canvas, TQ_SIGNAL(sigGotKeyPressEvent(TQKeyEvent*)),
2845 this, TQ_SLOT(canvasGotKeyPressEvent(TQKeyEvent*)));
2846
2847 delete m_partHandler;
2848 m_partHandler = 0;
2849}
2850
2851void KisView::addAdjustmentLayer()
2852{
2853 KisImageSP img = currentImg();
2854 if (!img) return;
2855
2856 addAdjustmentLayer( img->activeLayer()->parent(), img->activeLayer() );
2857}
2858
2859void KisView::addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above)
2860{
2861 Q_ASSERT(parent);
2862 Q_ASSERT(above);
2863
2864 KisImageSP img = currentImg();
2865 if (!img) return;
2866
2867 KisLayerSP l = img->activeLayer();
2868
2869 KisPaintDeviceSP dev;
2870
2871 // Argh! I hate having to cast, cast and cast again to see what kind of a layer I've got!
2872 KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(l.data());
2873 if (pl) {
2874 dev = pl->paintDevice();
2875 }
2876 else {
2877 KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(l.data());
2878 if (gl) {
2879 dev = gl->projection(img->bounds());
2880 }
2881 else {
2882 KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(l.data());
2883 if (al) {
2884 dev = al->cachedPaintDevice();
2885 }
2886 else {
2887 return;
2888 }
2889 }
2890 }
2891
2892 KisDlgAdjustmentLayer dlg(img, img->nextLayerName(), i18n("New Adjustment Layer"), this, "dlgadjustmentlayer");
2893 if (dlg.exec() == TQDialog::Accepted) {
2894 KisSelectionSP selection = 0;
2895 if (dev->hasSelection()) {
2896 selection = dev->selection();
2897 }
2898 KisFilterConfiguration * filter = dlg.filterConfiguration();
2899 TQString name = dlg.layerName();
2900
2901 addAdjustmentLayer( parent, above, name, filter, selection);
2902
2903 }
2904}
2905
2906void KisView::addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above, const TQString & name,
2907 KisFilterConfiguration * filter, KisSelectionSP selection)
2908{
2909 Q_ASSERT(parent);
2910 Q_ASSERT(above);
2911 Q_ASSERT(filter);
2912
2913 KisImageSP img = currentImg();
2914 if (!img) return;
2915
2916 KisAdjustmentLayer * l = new KisAdjustmentLayer(img, name, filter, selection);
2917 img->addLayer(l, parent, above);
2918}
2919
2920void KisView::slotChildActivated(bool a) {
2921 // It should be so that the only part (child) we can activate, is the current layer:
2922 if (currentImg() && currentImg()->activeLayer())
2923 {
2924 if (a) {
2925 currentImg()->activeLayer()->activate();
2926 } else {
2927 currentImg()->activeLayer()->deactivate();
2928 }
2929 }
2930
2931 super::slotChildActivated(a);
2932}
2933
2934void KisView::layerRemove()
2935{
2936 KisImageSP img = currentImg();
2937
2938 if (img) {
2939 KisLayerSP layer = img->activeLayer();
2940
2941 if (layer) {
2942
2943
2944 img->removeLayer(layer);
2945
2946 if (layer->parent())
2947 layer->parent()->setDirty(layer->extent());
2948
2949 updateCanvas();
2950 layerUpdateGUI(img->activeLayer() != 0);
2951 }
2952 }
2953}
2954
2955void KisView::layerDuplicate()
2956{
2957 KisImageSP img = currentImg();
2958
2959 if (!img)
2960 return;
2961
2962 KisLayerSP active = img->activeLayer();
2963
2964 if (!active)
2965 return;
2966
2967 KisLayerSP dup = active->clone();
2968 dup->setName(i18n("Duplicate of '%1'").arg(active->name()));
2969 img->addLayer(dup, active->parent().data(), active);
2970 if (dup) {
2971 img->activate( dup );
2972 updateCanvas();
2973 } else {
2974 KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
2975 }
2976}
2977
2978void KisView::layerRaise()
2979{
2980 KisImageSP img = currentImg();
2981 KisLayerSP layer;
2982
2983 if (!img)
2984 return;
2985
2986 layer = img->activeLayer();
2987
2988 img->raiseLayer(layer);
2989}
2990
2991void KisView::layerLower()
2992{
2993 KisImageSP img = currentImg();
2994 KisLayerSP layer;
2995
2996 if (!img)
2997 return;
2998
2999 layer = img->activeLayer();
3000
3001 img->lowerLayer(layer);
3002}
3003
3004void KisView::layerFront()
3005{
3006 KisImageSP img = currentImg();
3007 KisLayerSP layer;
3008
3009 if (!img)
3010 return;
3011
3012 layer = img->activeLayer();
3013 img->toTop(layer);
3014}
3015
3016void KisView::layerBack()
3017{
3018 KisImageSP img = currentImg();
3019 if (!img) return;
3020
3021 KisLayerSP layer;
3022
3023 layer = img->activeLayer();
3024 img->toBottom(layer);
3025}
3026
3027void KisView::layersUpdated()
3028{
3029 KisImageSP img = currentImg();
3030 if (!img) return;
3031
3032 KisLayerSP layer = img->activeLayer();
3033
3034 layerUpdateGUI(img && layer);
3035
3037}
3038
3039void KisView::layerToggleVisible()
3040{
3041 KisImageSP img = currentImg();
3042 if (!img) return;
3043
3044 KisLayerSP layer = img->activeLayer();
3045 if (!layer) return;
3046
3047 layer->setVisible(!layer->visible());
3048}
3049
3050void KisView::layerToggleLocked()
3051{
3052 KisImageSP img = currentImg();
3053 if (!img) return;
3054
3055 KisLayerSP layer = img->activeLayer();
3056 if (!layer) return;
3057
3058 layer->setLocked(!layer->locked());
3059}
3060
3061void KisView::actLayerVisChanged(int show)
3062{
3063 m_actLayerVis = (show != 0);
3064}
3065
3066bool KisView::activeLayerHasSelection()
3067{
3068 return m_image && m_image->activeDevice() && m_image->activeDevice()->hasSelection();
3069}
3070
3071void KisView::scrollH(int value)
3072{
3073 m_hRuler->updateVisibleArea(value, 0);
3074
3075 int xShift = m_scrollX - value;
3076 m_scrollX = value;
3077
3078 if (m_canvas->isUpdatesEnabled()) {
3079 if (xShift > 0) {
3080
3081 if (m_canvas->isOpenGLCanvas()) {
3082 paintOpenGLView(TQRect(0, 0, m_canvas->width(), m_canvas->height()));
3083 } else {
3084 TQRect drawRect(0, 0, xShift, m_canvasPixmap.height());
3085
3086 bitBlt(&m_canvasPixmap, xShift, 0, &m_canvasPixmap, 0, 0, m_canvasPixmap.width() - xShift, m_canvasPixmap.height());
3087
3088 updateTQPaintDeviceCanvas(viewToWindow(drawRect));
3089 m_canvas->repaint();
3090 }
3091 } else if (xShift < 0) {
3092
3093 TQRect drawRect(m_canvasPixmap.width() + xShift, 0, -xShift, m_canvasPixmap.height());
3094
3095 if (m_canvas->isOpenGLCanvas()) {
3096 paintOpenGLView(TQRect(0, 0, m_canvas->width(), m_canvas->height()));
3097 } else {
3098 bitBlt(&m_canvasPixmap, 0, 0, &m_canvasPixmap, -xShift, 0, m_canvasPixmap.width() + xShift, m_canvasPixmap.height());
3099
3100 updateTQPaintDeviceCanvas(viewToWindow(drawRect));
3101 m_canvas->repaint();
3102 }
3103 }
3104 if (m_oldTool) {
3105 KisCanvasPainter gc(m_canvas);
3106 m_oldTool->paint(gc);
3107 }
3108 }
3109
3110 if (xShift != 0) {
3111 // XXX do sth with the childframe or so
3112 }
3113 emit viewTransformationsChanged();
3114}
3115
3116void KisView::scrollV(int value)
3117{
3118 m_vRuler->updateVisibleArea(0, value);
3119
3120 int yShift = m_scrollY - value;
3121 m_scrollY = value;
3122
3123 if (m_canvas->isUpdatesEnabled()) {
3124 if (yShift > 0) {
3125
3126 if (m_canvas->isOpenGLCanvas()) {
3127 paintOpenGLView(TQRect(0, 0, m_canvas->width(), m_canvas->height()));
3128 } else {
3129 TQRect drawRect(0, 0, m_canvasPixmap.width(), yShift);
3130
3131 bitBlt(&m_canvasPixmap, 0, yShift, &m_canvasPixmap, 0, 0, m_canvasPixmap.width(), m_canvasPixmap.height() - yShift);
3132
3133 updateTQPaintDeviceCanvas(viewToWindow(drawRect));
3134 m_canvas->repaint();
3135 }
3136 } else if (yShift < 0) {
3137
3138 if (m_canvas->isOpenGLCanvas()) {
3139 paintOpenGLView(TQRect(0, 0, m_canvas->width(), m_canvas->height()));
3140 } else {
3141 TQRect drawRect(0, m_canvasPixmap.height() + yShift, m_canvasPixmap.width(), -yShift);
3142
3143 bitBlt(&m_canvasPixmap, 0, 0, &m_canvasPixmap, 0, -yShift, m_canvasPixmap.width(), m_canvasPixmap.height() + yShift);
3144
3145 updateTQPaintDeviceCanvas(viewToWindow(drawRect));
3146 m_canvas->repaint();
3147 }
3148 }
3149 if (m_oldTool) {
3150 KisCanvasPainter gc(m_canvas);
3151 m_oldTool->paint(gc);
3152 }
3153 }
3154
3155 if (yShift != 0) {
3156 // XXX do sth with the childframe or so
3157 }
3158 emit viewTransformationsChanged();
3159}
3160
3161void KisView::setupCanvas()
3162{
3163 m_canvas = new KisCanvas(this, "kis_canvas");
3164 m_canvas->setFocusPolicy( TQWidget::StrongFocus );
3165 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)), this, TQ_SLOT(canvasGotButtonPressEvent(KisButtonPressEvent*)));
3166 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)), this, TQ_SLOT(canvasGotButtonReleaseEvent(KisButtonReleaseEvent*)));
3167 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotDoubleClickEvent(KisDoubleClickEvent*)), this, TQ_SLOT(canvasGotDoubleClickEvent(KisDoubleClickEvent*)));
3168 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotMoveEvent(KisMoveEvent*)), this, TQ_SLOT(canvasGotMoveEvent(KisMoveEvent*)));
3169 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotPaintEvent(TQPaintEvent*)), this, TQ_SLOT(canvasGotPaintEvent(TQPaintEvent*)));
3170 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotEnterEvent(TQEvent*)), this, TQ_SLOT(canvasGotEnterEvent(TQEvent*)));
3171 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotLeaveEvent(TQEvent*)), this, TQ_SLOT(canvasGotLeaveEvent(TQEvent*)));
3172 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotMouseWheelEvent(TQWheelEvent*)), this, TQ_SLOT(canvasGotMouseWheelEvent(TQWheelEvent*)));
3173 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotKeyPressEvent(TQKeyEvent*)), this, TQ_SLOT(canvasGotKeyPressEvent(TQKeyEvent*)));
3174 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotKeyReleaseEvent(TQKeyEvent*)), this, TQ_SLOT(canvasGotKeyReleaseEvent(TQKeyEvent*)));
3175 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotDragEnterEvent(TQDragEnterEvent*)), this, TQ_SLOT(canvasGotDragEnterEvent(TQDragEnterEvent*)));
3176 TQObject::connect(m_canvas, TQ_SIGNAL(sigGotDropEvent(TQDropEvent*)), this, TQ_SLOT(canvasGotDropEvent(TQDropEvent*)));
3177}
3178
3179void KisView::connectCurrentImg()
3180{
3181 if (m_image) {
3182 connect(m_image, TQ_SIGNAL(sigActiveSelectionChanged(KisImageSP)), m_selectionManager, TQ_SLOT(imgSelectionChanged(KisImageSP)));
3183 connect(m_image, TQ_SIGNAL(sigActiveSelectionChanged(KisImageSP)), this, TQ_SLOT(updateCanvas()));
3184 connect(m_image, TQ_SIGNAL(sigColorSpaceChanged(KisColorSpace *)), this, TQ_SLOT(updateStatusBarProfileLabel()));
3185 connect(m_image, TQ_SIGNAL(sigProfileChanged(KisProfile * )), TQ_SLOT(profileChanged(KisProfile * )));
3186
3187 connect(m_image, TQ_SIGNAL(sigLayersChanged(KisGroupLayerSP)), TQ_SLOT(layersUpdated()));
3188 connect(m_image, TQ_SIGNAL(sigMaskInfoChanged()), TQ_SLOT(maskUpdated()));
3189 connect(m_image, TQ_SIGNAL(sigLayerAdded(KisLayerSP)), TQ_SLOT(layersUpdated()));
3190 connect(m_image, TQ_SIGNAL(sigLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), TQ_SLOT(layersUpdated()));
3191 connect(m_image, TQ_SIGNAL(sigLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), TQ_SLOT(layersUpdated()));
3192 connect(m_image, TQ_SIGNAL(sigLayerActivated(KisLayerSP)), TQ_SLOT(layersUpdated()));
3193 connect(m_image, TQ_SIGNAL(sigLayerActivated(KisLayerSP)), TQ_SLOT(updateCanvas()));
3194 connect(m_image, TQ_SIGNAL(sigLayerPropertiesChanged(KisLayerSP)), TQ_SLOT(layersUpdated()));
3195
3196 KisConnectPartLayerVisitor v(m_image, this, true);
3197 m_image->rootLayer()->accept(v);
3198 connect(m_image, TQ_SIGNAL(sigLayerAdded(KisLayerSP)),
3199 TQ_SLOT(handlePartLayerAdded(KisLayerSP)));
3200
3201 maskUpdated();
3202#ifdef HAVE_GL
3203 if (m_OpenGLImageContext != 0) {
3204 connect(m_OpenGLImageContext, TQ_SIGNAL(sigImageUpdated(TQRect)), TQ_SLOT(slotOpenGLImageUpdated(TQRect)));
3205 connect(m_OpenGLImageContext, TQ_SIGNAL(sigSizeChanged(TQ_INT32, TQ_INT32)), TQ_SLOT(slotImageSizeChanged(TQ_INT32, TQ_INT32)));
3206 } else
3207#endif
3208 {
3209 connect(m_image, TQ_SIGNAL(sigImageUpdated(TQRect)), TQ_SLOT(imgUpdated(TQRect)));
3210 connect(m_image, TQ_SIGNAL(sigSizeChanged(TQ_INT32, TQ_INT32)), TQ_SLOT(slotImageSizeChanged(TQ_INT32, TQ_INT32)));
3211 }
3212 }
3213
3214 m_layerBox->setImage(m_image);
3215 m_birdEyeBox->setImage(m_image);
3216}
3217
3218void KisView::disconnectCurrentImg()
3219{
3220 if (m_image) {
3221 m_image->disconnect(this);
3222 m_layerBox->setImage(0);
3223 m_birdEyeBox->setImage(0);
3224
3225 KisConnectPartLayerVisitor v(m_image, this, false);
3226 m_image->rootLayer()->accept(v);
3227 }
3228
3229#ifdef HAVE_GL
3230 if (m_OpenGLImageContext != 0) {
3231 m_OpenGLImageContext->disconnect(this);
3232 }
3233#endif
3234}
3235
3236void KisView::handlePartLayerAdded(KisLayerSP layer)
3237{
3238 KisPartLayer* l = dynamic_cast<KisPartLayer*>(layer.data());
3239 if (!l)
3240 return;
3241
3242 connect(this, TQ_SIGNAL(childActivated(KoDocumentChild*)),
3243 layer, TQ_SLOT(childActivated(KoDocumentChild*)));
3244}
3245
3246void KisView::imgUpdated(TQRect rc)
3247{
3248 updateCanvas(rc);
3249}
3250
3251void KisView::slotOpenGLImageUpdated(TQRect rc)
3252{
3253 paintOpenGLView(windowToView(rc));
3254}
3255
3256void KisView::profileChanged(KisProfile * /*profile*/)
3257{
3258 updateStatusBarProfileLabel();
3259}
3260
3261void KisView::slotImageSizeChanged(TQ_INT32 /*w*/, TQ_INT32 /*h*/)
3262{
3263 resizeEvent(0);
3264 refreshKisCanvas();
3265}
3266
3267void KisView::resizeCurrentImage(TQ_INT32 w, TQ_INT32 h, bool cropLayers)
3268{
3269 if (!currentImg()) return;
3270
3271 currentImg()->resize(w, h, cropLayers);
3272 m_doc->setModified(true);
3273 layersUpdated();
3274}
3275
3276void KisView::scaleCurrentImage(double sx, double sy, KisFilterStrategy *filterStrategy)
3277{
3278 if (!currentImg()) return;
3279 currentImg()->scale(sx, sy, m_progress, filterStrategy);
3280 m_doc->setModified(true);
3281 layersUpdated();
3282}
3283
3284void KisView::rotateCurrentImage(double radians)
3285{
3286 if (!currentImg()) return;
3287 currentImg()->rotate(radians, m_progress);
3288 m_doc->setModified(true);
3289 layersUpdated();
3290}
3291
3292void KisView::shearCurrentImage(double angleX, double angleY)
3293{
3294 if (!currentImg()) return;
3295 currentImg()->shear(angleX, angleY, m_progress);
3296 m_doc->setModified(true);
3297 layersUpdated();
3298}
3299
3300
3301TQPoint KisView::viewToWindow(const TQPoint& pt)
3302{
3303 TQPoint converted;
3304
3305 converted.rx() = static_cast<int>((pt.x() + horzValue()) / zoom());
3306 converted.ry() = static_cast<int>((pt.y() + vertValue()) / zoom());
3307
3308 return converted;
3309}
3310
3311TQPoint KisView::viewToWindow(const TQPoint& pt) const
3312{
3313 TQPoint converted;
3314
3315 converted.rx() = static_cast<int>((pt.x() + horzValue()) / zoom());
3316 converted.ry() = static_cast<int>((pt.y() + vertValue()) / zoom());
3317
3318 return converted;
3319}
3320
3321KisPoint KisView::viewToWindow(const KisPoint& pt)
3322{
3323 KisPoint converted;
3324
3325 converted.setX((pt.x() + horzValue()) / zoom());
3326 converted.setY((pt.y() + vertValue()) / zoom());
3327
3328 return converted;
3329}
3330
3331TQRect KisView::viewToWindow(const TQRect& rc)
3332{
3333 TQRect r;
3334
3335 r.setTopLeft(viewToWindow(rc.topLeft()));
3336 r.setRight((int)(ceil((rc.right() + 1.0 + horzValue()) / zoom()) - 1));
3337 r.setBottom((int)(ceil((rc.bottom() + 1.0 + vertValue()) / zoom()) - 1));
3338
3339 return r;
3340}
3341
3342KisRect KisView::viewToWindow(const KisRect& rc)
3343{
3344 KisRect r;
3345 KisPoint p = viewToWindow(KisPoint(rc.x(), rc.y()));
3346 r.setX(p.x());
3347 r.setY(p.y());
3348 r.setWidth(rc.width() / zoom());
3349 r.setHeight(rc.height() / zoom());
3350
3351 return r;
3352}
3353
3354void KisView::viewToWindow(TQ_INT32 *x, TQ_INT32 *y)
3355{
3356 if (x && y) {
3357 TQPoint p = viewToWindow(TQPoint(*x, *y));
3358 *x = p.x();
3359 *y = p.y();
3360 }
3361}
3362
3363TQPoint KisView::windowToView(const TQPoint& pt)
3364{
3365 TQPoint p;
3366 p.setX(static_cast<int>(pt.x() * zoom() - horzValue()));
3367 p.setY(static_cast<int>(pt.y() * zoom() - vertValue()));
3368
3369 return p;
3370}
3371
3372TQPoint KisView::windowToView(const TQPoint& pt) const
3373{
3374 TQPoint p;
3375 p.setX(static_cast<int>(pt.x() * zoom() - horzValue()));
3376 p.setY(static_cast<int>(pt.y() * zoom() - vertValue()));
3377
3378 return p;
3379}
3380
3381KisPoint KisView::windowToView(const KisPoint& pt)
3382{
3383 KisPoint p;
3384 p.setX(pt.x() * zoom() - horzValue());
3385 p.setY(pt.y() * zoom() - vertValue());
3386
3387 return p;
3388}
3389
3390TQRect KisView::windowToView(const TQRect& rc)
3391{
3392 TQRect r;
3393
3394 r.setTopLeft(windowToView(rc.topLeft()));
3395 r.setRight((int)(ceil((rc.right() + 1.0) * zoom()) - horzValue() - 1));
3396 r.setBottom((int)(ceil((rc.bottom() + 1.0) * zoom()) - vertValue() - 1));
3397
3398 return r;
3399}
3400
3401KisRect KisView::windowToView(const KisRect& rc)
3402{
3403 KisRect r;
3404 KisPoint p = windowToView(KisPoint(rc.x(), rc.y()));
3405 r.setX(p.x());
3406 r.setY(p.y());
3407 r.setWidth(rc.width() * zoom());
3408 r.setHeight(rc.height() * zoom());
3409
3410 return r;
3411}
3412
3413void KisView::windowToView(TQ_INT32 *x, TQ_INT32 *y)
3414{
3415 if (x && y) {
3416 TQPoint p = windowToView(TQPoint(*x, *y));
3417 *x = p.x();
3418 *y = p.y();
3419 }
3420}
3421
3422void KisView::guiActivateEvent(KParts::GUIActivateEvent *event)
3423{
3424 Q_ASSERT(event);
3425
3426 if (event->activated()) {
3427
3428 KStatusBar *sb = statusBar();
3429 if (sb) {
3430 sb->show();
3431 }
3432
3433 if (!m_guiActivateEventReceived) {
3434 m_guiActivateEventReceived = true;
3435 startInitialZoomTimerIfReady();
3436 }
3437 }
3438
3439 super::guiActivateEvent(event);
3440}
3441
3442bool KisView::eventFilter(TQObject *o, TQEvent *e)
3443{
3444 Q_ASSERT(o);
3445 Q_ASSERT(e);
3446
3447 switch (e->type()) {
3448 case TQEvent::TabletMove:
3449 case TQEvent::TabletPress:
3450 case TQEvent::TabletRelease:
3451 {
3452 TQTabletEvent *te = static_cast<TQTabletEvent*>(e);
3453 KisInputDevice device;
3454
3455 switch (te->device()) {
3456 default:
3457 case TQTabletEvent::Stylus:
3458 case TQTabletEvent::NoDevice:
3459 device = KisInputDevice::stylus();
3460 break;
3461 case TQTabletEvent::Puck:
3462 device = KisInputDevice::puck();
3463 break;
3464 case TQTabletEvent::Eraser:
3465 device = KisInputDevice::eraser();
3466 break;
3467 }
3468
3469 setInputDevice(device);
3470
3471 // We ignore device change due to mouse events for a short duration
3472 // after a tablet event, since these are almost certainly mouse events
3473 // sent to receivers that don't accept the tablet event.
3474 m_tabletEventTimer.start();
3475 break;
3476 }
3477 case TQEvent::MouseButtonPress:
3478 case TQEvent::MouseMove:
3479 case TQEvent::MouseButtonRelease:
3480 {
3481#ifdef EXTENDED_X11_TABLET_SUPPORT
3482 KisInputDevice device = KisCanvasWidget::findActiveInputDevice();
3483
3484 if (device != KisInputDevice::mouse()) {
3485 setInputDevice(device);
3486 m_tabletEventTimer.start();
3487 } else
3488#endif
3489 {
3490 if (currentInputDevice() != KisInputDevice::mouse() && m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
3491 setInputDevice(KisInputDevice::mouse());
3492 }
3493 }
3494 break;
3495 }
3496 case TQEvent::KeyPress:
3497 case TQEvent::KeyRelease:
3498 {
3499 if (m_canvas->cursorIsOverCanvas()) {
3500 m_canvas->handleKeyEvent(e);
3501 return true;
3502 }
3503 break;
3504 }
3505#if 0
3506 // This code is unnecessary now that there's an application event filter
3507 // This eventFilter is called for all widgets already, no need to install event filters multiple times
3508 // Even worse: with multiple views, they would all install event filters on each other's widgets,
3509 // due to the qapp event filter triggering in all views!
3510 case TQEvent::ChildInserted:
3511 {
3512 TQChildEvent *childEvent = static_cast<TQChildEvent *>(e);
3513 TQObject *child = childEvent->child();
3514 if ( child->isWidgetType() ) {
3515
3516 child->installEventFilter(this);
3517
3518 TQObjectList *objectList = child->queryList("TQWidget");
3519 TQObjectListIt it(*objectList);
3520 TQObject *obj;
3521 while ((obj = it.current()) != 0) {
3522 obj->installEventFilter(this);
3523 ++it;
3524 }
3525 delete objectList;
3526 }
3527 }
3528#endif
3529 default:
3530 // Ignore
3531 break;
3532 }
3533
3534#if 0
3535 if ((o == m_hRuler || o == m_vRuler) && (e->type() == TQEvent::MouseMove || e->type() == TQEvent::MouseButtonRelease)) {
3536 TQMouseEvent *me = dynamic_cast<TQMouseEvent*>(e);
3537 TQPoint pt = mapFromGlobal(me->globalPos());
3538 KisImageSP img = currentImg();
3539 KisGuideMgr *mgr;
3540
3541 if (!img)
3542 return super::eventFilter(o, e);
3543
3544 mgr = img->guides();
3545
3546 if (e->type() == TQEvent::MouseMove && (me->state() & TQt::LeftButton)) {
3547 bool flag = geometry().contains(pt);
3548 KisGuideSP gd;
3549
3550 if (m_currentGuide == 0 && flag) {
3551 // No guide is being edited and moving mouse over the canvas.
3552 // Create a new guide.
3553 enterEvent(0);
3554 eraseGuides();
3555 mgr->unselectAll();
3556
3557 if (o == m_vRuler)
3558 gd = mgr->add((pt.x() - m_vRuler->width() + horzValue()) / zoom(), TQt::Vertical);
3559 else
3560 gd = mgr->add((pt.y() - m_hRuler->height() + vertValue()) / zoom(), TQt::Horizontal);
3561
3562 m_currentGuide = gd;
3563 mgr->select(gd);
3564 m_lastGuidePoint = mapToScreen(pt);
3565 } else if (m_currentGuide) {
3566 if (flag) {
3567 // moved an existing guide.
3568 KisMoveEvent kme(currentInputDevice(), pt, me->globalPos(), PRESSURE_DEFAULT, 0, 0, me->state());
3569 canvasGotMoveEvent(&kme);
3570 } else {
3571 // moved a guide out of the frame, destroy it
3572 leaveEvent(0);
3573 eraseGuides();
3574 mgr->remove(m_currentGuide);
3575 paintGuides();
3576 m_currentGuide = 0;
3577 }
3578 }
3579 } else if (e->type() == TQEvent::MouseButtonRelease && m_currentGuide) {
3580 eraseGuides();
3581 mgr->unselect(m_currentGuide);
3582 paintGuides();
3583 m_currentGuide = 0;
3584 enterEvent(0);
3585 KisMoveEvent kme(currentInputDevice(), pt, me->globalPos(), PRESSURE_DEFAULT, 0, 0, TQt::NoButton);
3586 canvasGotMoveEvent(&kme);
3587 }
3588 }
3589#endif
3590
3591 return super::eventFilter(o, e);
3592}
3593
3594#if 0
3595void KisView::eraseGuides()
3596{
3597 KisImageSP img = currentImg();
3598
3599 if (img) {
3600 KisGuideMgr *mgr = img->guides();
3601
3602 if (mgr)
3603 mgr->erase(&m_canvasPixmap, this, horzValue(), vertValue(), zoom());
3604 }
3605}
3606
3607void KisView::paintGuides()
3608{
3609 KisImageSP img = currentImg();
3610
3611 if (img) {
3612 KisGuideMgr *mgr = img->guides();
3613
3614 if (mgr)
3615 mgr->paint(&m_canvasPixmap, this, horzValue(), vertValue(), zoom());
3616 }
3617}
3618
3619void KisView::updateGuides()
3620{
3621 eraseGuides();
3622 paintGuides();
3623}
3624#endif
3625
3626//void KisView::viewGuideLines()
3627//{
3628//}
3629
3630TQPoint KisView::mapToScreen(const TQPoint& pt)
3631{
3632 TQPoint converted;
3633
3634 converted.rx() = pt.x() + horzValue();
3635 converted.ry() = pt.y() + vertValue();
3636 return converted;
3637}
3638
3639void KisView::attach(KisCanvasObserver *observer)
3640{
3641 Q_ASSERT(observer);
3642 if (observer)
3643 m_observers.push_back(observer);
3644}
3645
3646void KisView::detach(KisCanvasObserver *observer)
3647{
3648 Q_ASSERT(observer);
3649 if (observer) {
3650 vKisCanvasObserver_it it = std::find(m_observers.begin(), m_observers.end(), observer);
3651
3652 if (it != m_observers.end())
3653 m_observers.erase(it);
3654 }
3655}
3656
3658{
3659 for (vKisCanvasObserver_it it = m_observers.begin(); it != m_observers.end(); ++it) {
3660 (*it)->update(this);
3661 }
3662}
3663
3664KisImageSP KisView::currentImg() const
3665{
3666 return m_image;
3667}
3668
3669void KisView::setCurrentImage(KisImageSP image)
3670{
3671 if(!image) return;
3672
3673 disconnectCurrentImg();
3674 m_image = image;
3675
3676 KisConfig cfg;
3677
3678#ifdef HAVE_GL
3679 if (cfg.useOpenGL()) {
3680 m_OpenGLImageContext = KisOpenGLImageContext::getImageContext(image, monitorProfile());
3681 m_canvas->createOpenGLCanvas(m_OpenGLImageContext->sharedContextWidget());
3682 }
3683#endif
3684 connectCurrentImg();
3685 m_layerBox->setImage(currentImg());
3686
3687 zoomAroundPoint(0, 0, 1.0);
3688
3689 if (!currentImg())
3690 layersUpdated();
3691
3692 imgUpdateGUI();
3693
3694 image->blockSignals(false);
3695}
3696
3698{
3699 return m_bg;
3700}
3701
3703{
3704 return m_fg;
3705}
3706
3707KisBrush *KisView::currentBrush() const
3708{
3709 return m_brush;
3710}
3711
3712KisPattern *KisView::currentPattern() const
3713{
3714 return m_pattern;
3715}
3716
3717KisGradient *KisView::currentGradient() const
3718{
3719 return m_gradient;
3720}
3721
3723{
3724 return m_paintop;
3725}
3726
3727const KisPaintOpSettings *KisView::currentPaintopSettings() const
3728{
3729 return m_paintopSettings;
3730}
3731
3732double KisView::zoomFactor() const
3733{
3734 return zoom();
3735}
3736
3737KisUndoAdapter *KisView::undoAdapter() const
3738{
3739 return m_adapter;
3740}
3741
3743{
3744 return const_cast<KisCanvasController*>(static_cast<const KisCanvasController*>(this));
3745}
3746
3747KisToolControllerInterface *KisView::toolController() const
3748{
3749 return const_cast<KisToolControllerInterface*>(static_cast<const KisToolControllerInterface*>(m_toolManager));
3750}
3751
3752KisDoc *KisView::document() const
3753{
3754 return m_doc;
3755}
3756
3757KisProgressDisplayInterface *KisView::progressDisplay() const
3758{
3759 return m_progress;
3760}
3761
3762TQCursor KisView::setCanvasCursor(const TQCursor & cursor)
3763{
3764 TQCursor oldCursor = m_canvas->cursor();
3765 TQCursor newCursor;
3766
3767 KisConfig cfg;
3768
3769 switch (cfg.cursorStyle()) {
3770 case CURSOR_STYLE_TOOLICON:
3771 newCursor = cursor;
3772 break;
3773 case CURSOR_STYLE_CROSSHAIR:
3774 newCursor = KisCursor::crossCursor();
3775 break;
3776 case CURSOR_STYLE_POINTER:
3777 newCursor = KisCursor::arrowCursor();
3778 break;
3779 case CURSOR_STYLE_OUTLINE:
3780 newCursor = cursor;
3781 break;
3782 default:
3783 newCursor = cursor;
3784 }
3785
3786 m_canvas->setCursor(newCursor);
3787 return oldCursor;
3788}
3789
3790float KisView::HDRExposure() const
3791{
3792 return m_HDRExposure;
3793}
3794
3795void KisView::setHDRExposure(float exposure)
3796{
3797 if (exposure != m_HDRExposure) {
3798 m_HDRExposure = exposure;
3800 updateCanvas();
3801 }
3802}
3803
3804void KisView::createDockers()
3805{
3806
3807 m_birdEyeBox = new KisBirdEyeBox(this);
3808 m_birdEyeBox->setCaption(i18n("Overview"));
3809 m_paletteManager->addWidget( m_birdEyeBox, "birdeyebox", chalk::CONTROL_PALETTE);
3810
3811 m_hsvwidget = new KoHSVWidget(this, "hsv");
3812 m_hsvwidget->setCaption(i18n("HSV"));
3813
3814 connect(m_hsvwidget, TQ_SIGNAL(sigFgColorChanged(const TQColor &)), this, TQ_SLOT(slotSetFGQColor(const TQColor &)));
3815 connect(m_hsvwidget, TQ_SIGNAL(sigBgColorChanged(const TQColor &)), this, TQ_SLOT(slotSetBGQColor(const TQColor &)));
3816 connect(this, TQ_SIGNAL(sigFGQColorChanged(const TQColor &)), m_hsvwidget, TQ_SLOT(setFgColor(const TQColor &)));
3817 connect(this, TQ_SIGNAL(sigBGQColorChanged(const TQColor &)), m_hsvwidget, TQ_SLOT(setBgColor(const TQColor &)));
3818 m_paletteManager->addWidget( m_hsvwidget, "hsvwidget", chalk::COLORBOX, 0, PALETTE_DOCKER, true);
3819
3820 m_rgbwidget = new KoRGBWidget(this, "rgb");
3821 m_rgbwidget->setCaption(i18n("RGB"));
3822 connect(m_rgbwidget, TQ_SIGNAL(sigFgColorChanged(const TQColor &)), this, TQ_SLOT(slotSetFGQColor(const TQColor &)));
3823 connect(m_rgbwidget, TQ_SIGNAL(sigBgColorChanged(const TQColor &)), this, TQ_SLOT(slotSetBGQColor(const TQColor &)));
3824 connect(this, TQ_SIGNAL(sigFGQColorChanged(const TQColor &)), m_rgbwidget, TQ_SLOT(setFgColor(const TQColor &)));
3825 connect(this, TQ_SIGNAL(sigBGQColorChanged(const TQColor &)), m_rgbwidget, TQ_SLOT(setBgColor(const TQColor &)));
3826 m_paletteManager->addWidget( m_rgbwidget, "rgbwidget", chalk::COLORBOX);
3827
3828 m_graywidget = new KoGrayWidget(this, "gray");
3829 m_graywidget->setCaption(i18n("Gray"));
3830 connect(m_graywidget, TQ_SIGNAL(sigFgColorChanged(const TQColor &)), this, TQ_SLOT(slotSetFGQColor(const TQColor &)));
3831 connect(m_graywidget, TQ_SIGNAL(sigBgColorChanged(const TQColor &)), this, TQ_SLOT(slotSetBGQColor(const TQColor &)));
3832 connect(this, TQ_SIGNAL(sigFGQColorChanged(const TQColor &)), m_graywidget, TQ_SLOT(setFgColor(const TQColor &)));
3833 connect(this, TQ_SIGNAL(sigBGQColorChanged(const TQColor &)), m_graywidget, TQ_SLOT(setBgColor(const TQColor &)));
3834 m_paletteManager->addWidget( m_graywidget, "graywidget", chalk::COLORBOX);
3835
3836 //make sure the color chooser get right default values
3837 emit sigFGQColorChanged(m_fg.toTQColor());
3838 emit sigBGQColorChanged(m_bg.toTQColor());
3839
3840 m_palettewidget = new KisPaletteWidget(this);
3841 m_palettewidget->setCaption(i18n("Palettes"));
3842 connect(m_palettewidget, TQ_SIGNAL(colorSelected(const TQColor &)),
3843 this, TQ_SLOT(slotSetFGQColor(const TQColor &)));
3844 // No BGColor or reverse slotFGChanged->palette connections, since that's not useful here
3845
3846 KisResourceServerBase* rServer;
3847 rServer = KisResourceServerRegistry::instance()->get("PaletteServer");
3848 TQValueList<KisResource*> resources = rServer->resources();
3849 TQValueList<KisResource*>::iterator it;
3850 for ( it = resources.begin(); it != resources.end(); ++it ) {
3851 m_palettewidget->slotAddPalette( *it );
3852 }
3853 connect(m_palettewidget, TQ_SIGNAL(colorSelected(const KisColor &)), this, TQ_SLOT(slotSetFGColor(const KisColor &)));
3854 m_paletteManager->addWidget( m_palettewidget, "palettewidget", chalk::COLORBOX, 10, PALETTE_DOCKER, true);
3855}
3856
3857TQPoint KisView::applyViewTransformations(const TQPoint& p) const {
3858 TQPoint point(windowToView(p));
3859
3860 if (m_hRuler->isShown())
3861 point.ry() += m_hRuler->height();
3862 if (m_vRuler -> isShown())
3863 point.rx() += m_vRuler->width();
3864
3865 return point;
3866}
3867
3868TQPoint KisView::reverseViewTransformations(const TQPoint& p) const {
3869 // Since we now zoom ourselves, the only thing super::~ does is nothing anymore.
3870 // Hence, zoom ourselves, like super would
3871 // viewToWindow doesn't take the rulers into account, do that ourselves
3872 TQPoint point(p);
3873 if (m_hRuler -> isShown())
3874 point.ry() -= m_hRuler -> height();
3875 if (m_vRuler -> isShown())
3876 point.rx() -= m_vRuler -> width();
3877
3878 return viewToWindow(point);
3879}
3880
3881void KisView::canvasAddChild(KoViewChild *child) {
3882 super::canvasAddChild(child);
3883 connect(this, TQ_SIGNAL(viewTransformationsChanged()), child, TQ_SLOT(reposition()));
3884 m_vScroll->raise();
3885 m_hScroll->raise();
3886 m_vScroll->raise();
3887 m_hRuler->raise();
3888 m_vRuler->raise();
3889}
3890
3891void KisView::slotLoadingFinished()
3892{
3893 // Set the current image for real now everything is ready to go.
3894 setCurrentImage(document()->currentImage());
3895 m_paletteManager->showWidget( "layerbox" );
3896 m_canvas->show();
3897 disconnect(document(), TQ_SIGNAL(loadingFinished()), this, TQ_SLOT(slotLoadingFinished()));
3898
3899 m_imageLoaded = true;
3900 startInitialZoomTimerIfReady();
3901}
3902
3903void KisView::startInitialZoomTimerIfReady()
3904{
3905 if (m_imageLoaded && m_showEventReceived && m_guiActivateEventReceived) {
3906 m_initialZoomTimer.start(250, true);
3907 }
3908}
3909
3910void KisView::slotInitialZoomTimeout()
3911{
3912 Q_ASSERT(!m_paintViewEnabled);
3913
3914 m_paintViewEnabled = true;
3915 setInitialZoomLevel();
3916}
3917
3918
3919void KisView::slotCreateMask() {
3920 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3921 if (!layer)
3922 return;
3923
3924 KNamedCommand *cmd = layer->createMaskCommand();
3925 cmd->execute();
3926 if (undoAdapter() && undoAdapter()->undo()) {
3927 undoAdapter()->addCommand(cmd);
3928 }
3929}
3930
3931void KisView::slotMaskFromSelection() {
3932 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3933 if (!layer)
3934 return;
3935
3936 KNamedCommand *cmd = layer->maskFromSelectionCommand();
3937 cmd->execute();
3938 if (undoAdapter() && undoAdapter()->undo()) {
3939 undoAdapter()->addCommand(cmd);
3940 }
3941}
3942
3943void KisView::slotMaskToSelection() {
3944 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3945 if (!layer)
3946 return;
3947
3948 KNamedCommand *cmd = layer->maskToSelectionCommand();
3949 cmd->execute();
3950 if (undoAdapter() && undoAdapter()->undo()) {
3951 undoAdapter()->addCommand(cmd);
3952 }
3953}
3954
3955void KisView::slotApplyMask() {
3956 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3957 if (!layer)
3958 return;
3959
3960 KNamedCommand *cmd = layer->applyMaskCommand();
3961 cmd->execute();
3962 if (undoAdapter() && undoAdapter()->undo()) {
3963 undoAdapter()->addCommand(cmd);
3964 }
3965}
3966
3967void KisView::slotRemoveMask() {
3968 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3969 if (!layer)
3970 return;
3971
3972 KNamedCommand *cmd = layer->removeMaskCommand();
3973 cmd->execute();
3974 if (undoAdapter() && undoAdapter()->undo()) {
3975 undoAdapter()->addCommand(cmd);
3976 }
3977}
3978
3979void KisView::slotEditMask() {
3980 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3981 if (!layer)
3982 return;
3983
3984 layer->setEditMask(m_editMask->isChecked());
3985}
3986
3987void KisView::slotShowMask() {
3988 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3989 if (!layer)
3990 return;
3991
3992 layer->setRenderMask(m_showMask->isChecked());
3993}
3994
3995void KisView::maskUpdated() {
3996 KisPaintLayer* layer = dynamic_cast<KisPaintLayer*>(currentImg()->activeLayer().data());
3997 if (!layer) {
3998 m_createMask->setEnabled(false);
3999 m_applyMask->setEnabled(false);
4000 m_removeMask->setEnabled(false);
4001 m_editMask->setEnabled(false);
4002 m_showMask->setEnabled(false);
4003 return;
4004 }
4005 m_createMask->setEnabled(!layer->hasMask());
4006 m_maskFromSelection->setEnabled(true); // Perhaps also update this to false when no selection?
4007 m_maskToSelection->setEnabled(layer->hasMask());
4008 m_applyMask->setEnabled(layer->hasMask());
4009 m_removeMask->setEnabled(layer->hasMask());
4010
4011 m_editMask->setEnabled(layer->hasMask());
4012 m_editMask->setChecked(layer->editMask());
4013 m_showMask->setEnabled(layer->hasMask());
4014 m_showMask->setChecked(layer->renderMask());
4015}
4016
4017#include "kis_view.moc"
4018
Interface for classes that implement a canvas; i.e., a widget where KisImages are painted onto.
virtual TQ_INT32 vertValue() const =0
virtual void zoomOut()=0
Decrease the zoomlevel one step.
virtual KisInputDevice currentInputDevice() const =0
virtual void zoomIn()=0
Increase the zoomlevel one step.
virtual void updateCanvas()=0
Tell all of the canvas to repaint itself.
virtual TQ_INT32 horzValue() const =0
virtual KisCanvas * kiscanvas() const =0
This is the base interface plugins use to implement the Observer design pattern.
virtual double zoomFactor() const =0
virtual float HDRExposure() const =0
virtual KisUndoAdapter * undoAdapter() const =0
retrieve the undo adapater – there is one undo adapter per document, and it collects all transactions
virtual KisDoc * document() const =0
XXX: Remove this method.
virtual KisPattern * currentPattern() const =0
virtual const KisPaintOpSettings * currentPaintopSettings() const =0
virtual KisToolControllerInterface * toolController() const =0
XXX: Remove this method.
virtual KisGradient * currentGradient() const =0
virtual KisProgressDisplayInterface * progressDisplay() const =0
XXX: Remove this method.
virtual KisColor fgColor() const =0
virtual KoPaletteManager * paletteManager()=0
XXX: Remove this method.
virtual KisCanvasController * canvasController() const =0
virtual KisColor bgColor() const =0
virtual KisProfile * monitorProfile()=0
Get the profile that this view uses to display itself on he monitor.
virtual KisImageSP currentImg() const =0
virtual KisBrush * currentBrush() const =0
virtual void notifyObservers()=0
Calling this method will notify all observers.
virtual KisID currentPaintop() const =0
KisColorSpace * getColorSpace(const KisID &csID, const TQString &profileName)
Return the colorspace + profile as named, or NULL if impossible combination.
KisProfile * getProfileByName(const TQString &name)
Return the profile associated with the given product name, or 0.
A colorspace is the definition of a certain color model in Chalk.
A KisColor describes a color in a certain colorspace.
Definition kis_color.h:33
void toTQColor(TQColor *c) const
To save the user the trouble of doing color->colorSpace()->toTQColor(color->data(),...
Control Frame - status display with access to color selector, brushes, patterns, and preview.
A KisFilterConfiguration is the serializable representation of the filter parameters.
Create all the filter actions for the specified view and implement re-apply filter.
_T get(const KisID &name) const
This function allow to get an object from its KisID.
virtual KisPaintDeviceSP projection(const TQRect &rect)
will copy from to, if !0, CoW!!
Chalk has a large number of extensible resources.
Definition kis_id.h:57
void setEditMask(bool b)
Sets the editMask property.
KNamedCommand * createMaskCommand()
Undoable version of createMask.
bool editMask() const
When this returns true, the KisPaintDevice returned in paintDevice will actually be the layer mask (i...
void setRenderMask(bool b)
Set the renderMask property.
KNamedCommand * applyMaskCommand()
Undoable version of applyMask.
KNamedCommand * maskFromSelectionCommand()
Undoable version of createMaskFromSelection.
KNamedCommand * removeMaskCommand()
Undoable version of removeMask.
bool renderMask() const
Returns true if the masked part of the mask will be rendered instead of being transparent.
bool hasMask() const
Does this layer have a layer mask?
KNamedCommand * maskToSelectionCommand()
Undoable, removes the current mask, but converts it to the current selection.
A double-based point class that can return it's coordinates approximated to integers.
Definition kis_point.h:28
A double-based rect class that can return a TQRect that encloses the KisRect.
Definition kis_rect.h:29
The KisResource class provides a representation of Chalk image resources.
The selection manager is responsible selections and the clipboard.
This class manages the activation and deactivation of tools for each input device.