krita

kis_view.cc

00001 /* This file is part of KimageShop^WKrayon^WKrita
00002  *
00003  *  Copyright (c) 1999 Matthias Elter  <me@kde.org>
00004  *                1999 Michael Koch    <koch@kde.org>
00005  *                1999 Carsten Pfeiffer <pfeiffer@kde.org>
00006  *                2002 Patrick Julien <freak@codepimps.org>
00007  *                2003-2005 Boudewijn Rempt <boud@valdyas.org>
00008  *                2004 Clarence Dang <dang@kde.org>
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00023  */
00024 
00025 #include <algorithm>
00026 #include <cmath>
00027 
00028 // Qt
00029 #include <qapplication.h>
00030 #include <qbutton.h>
00031 #include <qcursor.h>
00032 #include <qevent.h>
00033 #include <qpainter.h>
00034 #include <qscrollbar.h>
00035 #include <qspinbox.h>
00036 #include <qdockarea.h>
00037 #include <qstringlist.h>
00038 #include <qstyle.h>
00039 #include <qpopupmenu.h>
00040 #include <qvaluelist.h>
00041 #include <qstringlist.h>
00042 #include <qobjectlist.h>
00043 
00044 // KDE
00045 #include <kis_meta_registry.h>
00046 #include <kglobalsettings.h>
00047 #include <dcopobject.h>
00048 #include <kaction.h>
00049 #include <kcolordialog.h>
00050 #include <kiconloader.h>
00051 #include <kfiledialog.h>
00052 #include <klocale.h>
00053 #include <kmessagebox.h>
00054 #include <knotifyclient.h>
00055 #include <kprinter.h>
00056 #include <kpushbutton.h>
00057 #include <kstatusbar.h>
00058 #include <kstdaction.h>
00059 #include <kinputdialog.h>
00060 #include <kurldrag.h>
00061 #include <kpopupmenu.h>
00062 #include <kdebug.h>
00063 #include <ksharedptr.h>
00064 #include <ktoolbar.h>
00065 #include <kparts/plugin.h>
00066 #include <kservice.h>
00067 #include <ktrader.h>
00068 #include <kparts/componentfactory.h>
00069 #include <kparts/event.h>
00070 
00071 // KOffice
00072 #include <KoPartSelectAction.h>
00073 #include <KoFilterManager.h>
00074 #include <KoMainWindow.h>
00075 #include <KoView.h>
00076 #include <KoTabBar.h>
00077 #include <ko_gray_widget.h>
00078 #include <ko_hsv_widget.h>
00079 #include <ko_rgb_widget.h>
00080 #include <kopalettemanager.h>
00081 #include <kopalette.h>
00082 
00083 // Local
00084 #include "kis_brush.h"
00085 #include "kis_button_press_event.h"
00086 #include "kis_button_release_event.h"
00087 #include "kis_canvas.h"
00088 #include "kis_canvas_painter.h"
00089 #include "kis_color.h"
00090 #include "kis_colorspace_factory_registry.h"
00091 #include "kis_config.h"
00092 #include "kis_controlframe.h"
00093 #include "kis_cursor.h"
00094 #include "kis_doc.h"
00095 #include "kis_double_click_event.h"
00096 #include "kis_factory.h"
00097 #include "kis_filter_strategy.h"
00098 #include "kis_gradient.h"
00099 #include "kis_group_layer.h"
00100 #include "kis_adjustment_layer.h"
00101 #include "kis_paint_device.h"
00102 #include "kis_tool_freehand.h"
00103 //#include "kis_guide.h"
00104 
00105 #include "kis_layerbox.h"
00106 
00107 #include "kis_layer.h"
00108 #include "kis_paint_layer.h"
00109 #include "kis_move_event.h"
00110 #include "kis_paint_device.h"
00111 #include "kis_painter.h"
00112 #include "kis_paintop_registry.h"
00113 #include "kis_part_layer.h"
00114 #include "kis_part_layer_handler.h"
00115 #include "kis_pattern.h"
00116 #include "kis_profile.h"
00117 #include "kis_rect.h"
00118 #include "kis_resource.h"
00119 #include "kis_palette.h"
00120 #include "kis_ruler.h"
00121 #include "kis_selection.h"
00122 #include "KoToolBox.h"
00123 #include "kis_tool.h"
00124 #include "kis_tool_manager.h"
00125 #include "kis_transaction.h"
00126 #include "kis_types.h"
00127 #include "kis_undo_adapter.h"
00128 #include "kis_view.h"
00129 #include "kis_view_iface.h"
00130 #include "kis_label_progress.h"
00131 #include "kis_opengl_image_context.h"
00132 #include "kis_background.h"
00133 #include "kis_paint_device_action.h"
00134 #include "kis_filter_configuration.h"
00135 #include "kis_transform_worker.h"
00136 #include "kis_shear_visitor.h"
00137 
00138 #include <kis_resourceserver.h>
00139 #include <kis_resource_mediator.h>
00140 
00141 #include "kis_icon_item.h"
00142 #include "kis_palette_widget.h"
00143 #include "kis_birdeye_box.h"
00144 #include "kis_color.h"
00145 #include "kis_factory.h"
00146 
00147 // Dialog boxes
00148 #include "kis_dlg_new_layer.h"
00149 #include "kis_dlg_layer_properties.h"
00150 #include "kis_dlg_preferences.h"
00151 #include "kis_dlg_image_properties.h"
00152 #include "kis_dlg_adjustment_layer.h"
00153 #include "kis_dlg_adj_layer_props.h"
00154 
00155 // Action managers
00156 #include "kis_selection_manager.h"
00157 #include "kis_filter_manager.h"
00158 #include "kis_grid_manager.h"
00159 
00160 #include "kis_custom_palette.h"
00161 #include "wdgpalettechooser.h"
00162 
00163 #include <fixx11h.h>
00164 
00165 // Time in ms that must pass after a tablet event before a mouse event is allowed to
00166 // change the input device to the mouse. This is needed because mouse events are always
00167 // sent to a receiver if it does not accept the tablet event.
00168 #define MOUSE_CHANGE_EVENT_DELAY 100
00169 
00170 KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const char *name)
00171     : super(doc, parent, name)
00172     , KXMLGUIBuilder( shell() )
00173     , m_panning( false )
00174     , m_oldTool( 0 )
00175     , m_doc( doc )
00176     , m_canvas( 0 )
00177     , m_popup( 0 )
00178     , m_partHandler( 0 )
00179     , m_gridManager( 0 )
00180     , m_selectionManager( 0 )
00181     , m_filterManager( 0 )
00182     , m_paletteManager( 0 )
00183     , m_toolManager( 0 )
00184     , m_actLayerVis( false )
00185     , m_hRuler( 0 )
00186     , m_vRuler( 0 )
00187     , m_imgFlatten( 0 )
00188     , m_imgMergeLayer( 0 )
00189     , m_imgRename( 0 )
00190     , m_imgResizeToLayer( 0 )
00191     , m_imgScan( 0 )
00192     , m_actionPartLayer( 0 )
00193     , m_layerAdd( 0 )
00194     , m_layerBottom( 0 )
00195     , m_layerDup( 0 )
00196     , m_layerHide( 0 )
00197     , m_layerLower( 0 )
00198     , m_layerProperties( 0 )
00199     , m_layerRaise( 0 )
00200     , m_layerRm( 0 )
00201     , m_layerSaveAs( 0 )
00202     , m_layerTop( 0 )
00203     , m_zoomIn( 0 )
00204     , m_zoomOut( 0 )
00205     , m_actualPixels( 0 )
00206     , m_actualSize( 0 )
00207     , m_fitToCanvas( 0 )
00208     , m_fullScreen( 0 )
00209     , m_imgProperties( 0 )
00210     , m_RulerAction( 0 )
00211     , m_guideAction( 0 )
00212     , m_dcop( 0 )
00213     , m_hScroll( 0 )
00214     , m_vScroll( 0 )
00215     , m_scrollX( 0 )
00216     , m_scrollY( 0 )
00217     , m_canvasXOffset( 0)
00218     , m_canvasYOffset( 0)
00219     , m_paintViewEnabled( false )
00220     , m_guiActivateEventReceived( false )
00221     , m_showEventReceived( false )
00222     , m_imageLoaded( false )
00223 //    , m_currentGuide( 0 )
00224     , m_adapter( adapter )
00225     , m_statusBarZoomLabel( 0 )
00226     , m_statusBarSelectionLabel( 0 )
00227     , m_statusBarProfileLabel( 0 )
00228     , m_progress( 0 )
00229     , m_layerBox( 0 )
00230     , m_toolBox( 0 )
00231     , m_brush( 0 )
00232     , m_pattern( 0 )
00233     , m_gradient( 0 )
00234     , m_toolIsPainting( false )
00235     , m_monitorProfile( 0 )
00236     , m_HDRExposure( 0 )
00237 {
00238 
00239     Q_ASSERT(doc);
00240     Q_ASSERT(adapter);
00241     Q_ASSERT(parent);
00242 
00243     KisConfig cfg;
00244     
00245     m_currentColorChooserDisplay = KisID("BLA");
00246     setFocusPolicy( QWidget::StrongFocus );
00247 
00248     // Must come before input devices are referenced as this detects them.
00249 #ifdef Q_WS_X11
00250     KisCanvasWidget::initX11Support();
00251 #endif
00252     // Install event filter before we create any child widgets so they can see
00253     // the tablet events.
00254     qApp->installEventFilter(this);
00255 
00256     m_tabletEventTimer.start();
00257     m_inputDevice = KisInputDevice::mouse();
00258 
00259     connect(&m_initialZoomTimer, SIGNAL(timeout()), SLOT(slotInitialZoomTimeout()));
00260 
00261     m_paletteManager = new KoPaletteManager(this, actionCollection(), "Krita palette manager");
00262     if (cfg.fixDockerWidth()) m_paletteManager->setFixedWidth( 360 );
00263     
00264     m_paletteManager->createPalette( krita::CONTROL_PALETTE, i18n("Control box"));
00265     m_paletteManager->createPalette( krita::COLORBOX, i18n("Colors"));
00266     m_paletteManager->createPalette( krita::LAYERBOX, i18n("Layers"));
00267 
00268     m_selectionManager = new KisSelectionManager(this, doc);
00269     m_filterManager = new KisFilterManager(this, doc);
00270     m_toolManager = new KisToolManager(canvasSubject(), getCanvasController());
00271     m_gridManager = new KisGridManager(this);
00272 
00273     // This needs to be set before the dockers are created.
00274     m_image = m_doc->currentImage();
00275     KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getRGB8();
00276     m_fg = KisColor(Qt::black, cs);
00277     m_bg = KisColor(Qt::white, cs);
00278 
00279     createDockers();
00280 
00281     setInstance(KisFactory::instance(), false);
00282     setClientBuilder( this );
00283 
00284     if (!doc->isReadWrite())
00285         setXMLFile("krita_readonly.rc");
00286     else
00287         setXMLFile("krita.rc");
00288 
00289     KStdAction::keyBindings( mainWindow()->guiFactory(), SLOT( configureShortcuts() ), actionCollection() );
00290 
00291     createLayerBox();
00292 
00293     setupCanvas();
00294     m_canvas->hide();
00295     setupRulers();
00296     setupScrollBars();
00297     setupStatusBar();
00298 
00299     setupActions();
00300     dcopObject();
00301 
00302 
00303     connect(this, SIGNAL(autoScroll(const QPoint &)), SLOT(slotAutoScroll(const QPoint &)));
00304 
00305     setMouseTracking(true);
00306 
00307     resetMonitorProfile();
00308 
00309     layersUpdated();
00310 
00311     m_brushesAndStuffToolBar = new KisControlFrame(mainWindow(), this);
00312 
00313     // Load all plugins
00314     KTrader::OfferList offers = KTrader::self()->query(QString::fromLatin1("Krita/ViewPlugin"),
00315                                                          QString::fromLatin1("(Type == 'Service') and "
00316                                                                              "([X-Krita-Version] == 2)"));
00317     KTrader::OfferList::ConstIterator iter;
00318     for(iter = offers.begin(); iter != offers.end(); ++iter)
00319     {
00320         KService::Ptr service = *iter;
00321         int errCode = 0;
00322         KParts::Plugin* plugin =
00323              KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, QStringList(), &errCode);
00324         if ( plugin ) {
00325             kdDebug(41006) << "found plugin " << service->property("Name").toString() << "\n";
00326             insertChildClient(plugin);
00327         }
00328         else {
00329             kdDebug(41006) << "found plugin " << service->property("Name").toString() << ", " << errCode << "\n";
00330         if( errCode == KParts::ComponentFactory::ErrNoLibrary)
00331         {
00332         kdWarning(41006) << " Error loading plugin was : ErrNoLibrary " << KLibLoader::self()->lastErrorMessage() << endl;
00333         }
00334         }
00335     }
00336 
00337     if(!doc->isLoading())
00338     {
00339         slotLoadingFinished();
00340     } else {
00341         connect(doc, SIGNAL(loadingFinished()), this, SLOT(slotLoadingFinished()));
00342     }
00343 
00344     setFocus();
00345 }
00346 
00347 KisView::~KisView()
00348 {
00349     KisConfig cfg;
00350     cfg.setShowRulers( m_RulerAction->isChecked() );
00351 
00352     delete m_dcop;
00353     delete m_paletteManager;
00354     delete m_selectionManager;
00355     delete m_filterManager;
00356     delete m_toolManager;
00357 
00358 }
00359 
00360 
00361 static Qt::Dock stringToDock( const QString& attrPosition )
00362 {
00363     KToolBar::Dock dock = KToolBar::DockTop;
00364     if ( !attrPosition.isEmpty() ) {
00365         if ( attrPosition == "top" )
00366             dock = Qt::DockTop;
00367         else if ( attrPosition == "left" )
00368             dock = Qt::DockLeft;
00369         else if ( attrPosition == "right" )
00370             dock = Qt::DockRight;
00371         else if ( attrPosition == "bottom" )
00372             dock = Qt::DockBottom;
00373         else if ( attrPosition == "floating" )
00374             dock = Qt::DockTornOff;
00375         else if ( attrPosition == "flat" )
00376             dock = Qt::DockMinimized;
00377     }
00378     return dock;
00379 }
00380 
00381 QWidget * KisView::createContainer( QWidget *parent, int index, const QDomElement &element, int &id )
00382 {
00383     if( element.attribute( "name" ) == "ToolBox" )
00384     {
00385         m_toolBox = new KoToolBox(mainWindow(), "ToolBox", KisFactory::instance(), NUMBER_OF_TOOLTYPES);
00386         m_toolBox->setLabel(i18n("Krita"));
00387         m_toolManager->setUp(m_toolBox, m_paletteManager, actionCollection());
00388 
00389         Dock dock = stringToDock( element.attribute( "position" ).lower() );
00390 
00391         mainWindow()->addDockWindow( m_toolBox, dock, false);
00392         mainWindow()->moveDockWindow( m_toolBox, dock, false, 0, 0 );
00393     }
00394 
00395     return KXMLGUIBuilder::createContainer( parent, index, element, id );
00396 
00397 }
00398 
00399 void KisView::removeContainer( QWidget *container, QWidget *parent, QDomElement &element, int id )
00400 {
00401     Q_ASSERT(container);
00402 
00403     if( shell() && container == m_toolBox )
00404     {
00405         delete m_toolBox;
00406         m_toolManager->youAintGotNoToolBox();
00407     }
00408     else {
00409         KXMLGUIBuilder::removeContainer( container, parent, element, id );
00410     }
00411 }
00412 
00413 KoPaletteManager * KisView::paletteManager()
00414 {
00415     if (!m_paletteManager) {
00416         m_paletteManager = new KoPaletteManager(this, actionCollection(), "Krita palette manager");
00417         Q_CHECK_PTR(m_paletteManager);
00418     }
00419     return m_paletteManager;
00420 }
00421 
00422 void KisView::createLayerBox()
00423 {
00424     m_layerBox = new KisLayerBox(this);
00425     m_layerBox->setCaption(i18n("Layers"));
00426 
00427     connect(m_layerBox, SIGNAL(sigRequestLayer(KisGroupLayerSP, KisLayerSP)),
00428             this, SLOT(addLayer(KisGroupLayerSP, KisLayerSP)));
00429     connect(m_layerBox, SIGNAL(sigRequestGroupLayer(KisGroupLayerSP, KisLayerSP)),
00430             this, SLOT(addGroupLayer(KisGroupLayerSP, KisLayerSP)));
00431     connect(m_layerBox, SIGNAL(sigRequestAdjustmentLayer(KisGroupLayerSP, KisLayerSP)),
00432             this, SLOT(addAdjustmentLayer(KisGroupLayerSP, KisLayerSP)));
00433     connect(m_layerBox, SIGNAL(sigRequestPartLayer(KisGroupLayerSP, KisLayerSP, const KoDocumentEntry&)),
00434             this, SLOT(addPartLayer(KisGroupLayerSP, KisLayerSP, const KoDocumentEntry&)));
00435     connect(m_layerBox, SIGNAL(sigRequestLayerProperties(KisLayerSP)),
00436             this, SLOT(showLayerProperties(KisLayerSP)));
00437     connect(m_layerBox, SIGNAL(sigOpacityChanged(int, bool)), this, SLOT(layerOpacity(int, bool)));
00438     connect(m_layerBox, SIGNAL(sigOpacityFinishedChanging(int, int)),
00439             this, SLOT(layerOpacityFinishedChanging(int, int)));
00440     connect(m_layerBox, SIGNAL(sigItemComposite(const KisCompositeOp&)), this, SLOT(layerCompositeOp(const KisCompositeOp&)));
00441 
00442     paletteManager()->addWidget(m_layerBox, "layerbox", krita::LAYERBOX, 0);
00443 
00444 }
00445 
00446 DCOPObject* KisView::dcopObject()
00447 {
00448     if (!m_dcop) {
00449         m_dcop = new KisViewIface(this);
00450         Q_CHECK_PTR(m_dcop);
00451     }
00452     return m_dcop;
00453 }
00454 
00455 void KisView::setupScrollBars()
00456 {
00457     m_scrollX = 0;
00458     m_scrollY = 0;
00459     m_vScroll = new QScrollBar(QScrollBar::Vertical, this);
00460     Q_CHECK_PTR(m_vScroll);
00461 
00462     m_hScroll = new QScrollBar(QScrollBar::Horizontal, this);
00463     Q_CHECK_PTR(m_hScroll);
00464 
00465     m_vScroll->setGeometry(width() - 16, 20, 16, height() - 36);
00466     m_hScroll->setGeometry(20, height() - 16, width() - 36, 16);
00467     m_hScroll->setValue(0);
00468     m_vScroll->setValue(0);
00469     QObject::connect(m_vScroll, SIGNAL(valueChanged(int)), this, SLOT(scrollV(int)));
00470     QObject::connect(m_hScroll, SIGNAL(valueChanged(int)), this, SLOT(scrollH(int)));
00471 }
00472 
00473 void KisView::setupRulers()
00474 {
00475     m_hRuler = new KisRuler(Qt::Horizontal, this);
00476     Q_CHECK_PTR(m_hRuler);
00477 
00478     m_vRuler = new KisRuler(Qt::Vertical, this);
00479     Q_CHECK_PTR(m_vRuler);
00480 
00481     m_hRuler->setGeometry(20, 0, width() - 20, 20);
00482     m_vRuler->setGeometry(0, 20, 20, height() - 20);
00483 
00484     if (statusBar()) {
00485         m_hRuler->installEventFilter(this);
00486         m_vRuler->installEventFilter(this);
00487     }
00488 }
00489 
00490 #define EPSILON 1e-6
00491 
00492 void KisView::updateStatusBarZoomLabel ()
00493 {
00494     if (zoom() < 1 - EPSILON) {
00495         m_statusBarZoomLabel->setText(i18n("Zoom %1%").arg(zoom() * 100, 0, 'g', 4));
00496     } else {
00497         m_statusBarZoomLabel->setText(i18n("Zoom %1%").arg(zoom() * 100, 0, 'f', 0));
00498     }
00499     m_statusBarZoomLabel->setMaximumWidth(m_statusBarZoomLabel->fontMetrics().width(i18n("Zoom %1%").arg("0.8888  ")));
00500 }
00501 
00502 void KisView::updateStatusBarSelectionLabel()
00503 {
00504     if (m_statusBarSelectionLabel == 0) {
00505         return;
00506     }
00507 
00508     KisImageSP img = currentImg();
00509     if (img) {
00510         KisPaintDeviceSP dev = img->activeDevice();
00511         if (dev) {
00512             if (dev->hasSelection()) {
00513                 QRect r = dev->selection()->selectedExactRect();
00514                 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()));
00515                 return;
00516             }
00517         }
00518     }
00519 
00520     m_statusBarSelectionLabel->setText(i18n("No Selection"));
00521 }
00522 
00523 void KisView::updateStatusBarProfileLabel()
00524 {
00525     if (m_statusBarProfileLabel == 0) {
00526         return;
00527     }
00528 
00529     KisImageSP img = currentImg();
00530     if (!img) return;
00531 
00532     if (img->getProfile() == 0) {
00533         m_statusBarProfileLabel->setText(i18n("No profile"));
00534     }
00535     else {
00536         m_statusBarProfileLabel->setText(img->colorSpace()->id().name() + "  " + img->getProfile()->productName());
00537     }
00538 }
00539 
00540 
00541 KisProfile *  KisView::monitorProfile()
00542 {
00543     if (m_monitorProfile == 0) {
00544         resetMonitorProfile();
00545     }
00546     return m_monitorProfile;
00547 }
00548 
00549 
00550 void KisView::resetMonitorProfile()
00551 {
00552     m_monitorProfile = KisProfile::getScreenProfile();
00553 
00554     if (m_monitorProfile == 0) {
00555         KisConfig cfg;
00556         QString monitorProfileName = cfg.monitorProfile();
00557         m_monitorProfile = KisMetaRegistry::instance()->csRegistry()->getProfileByName(monitorProfileName);
00558     }
00559 
00560 }
00561 
00562 void KisView::setupStatusBar()
00563 {
00564     KStatusBar *sb = statusBar();
00565 
00566     if (sb) {
00567         m_statusBarZoomLabel = new QLabel(sb);
00568         addStatusBarItem(m_statusBarZoomLabel,1);
00569         updateStatusBarZoomLabel();
00570 
00571         m_statusBarSelectionLabel = new KSqueezedTextLabel(sb);
00572         addStatusBarItem(m_statusBarSelectionLabel,2);
00573         updateStatusBarSelectionLabel();
00574 
00575         m_statusBarProfileLabel = new KSqueezedTextLabel(sb);
00576         addStatusBarItem(m_statusBarProfileLabel,3);
00577         updateStatusBarProfileLabel();
00578 
00579         //int height = m_statusBarProfileLabel->height();
00580 
00581         m_progress = new KisLabelProgress(this);
00582         m_progress->setMaximumWidth(225);
00583         m_progress->setMinimumWidth(225);
00584         m_progress->setMaximumHeight(fontMetrics().height() );
00585         addStatusBarItem(m_progress, 2, true);
00586 
00587         m_progress->hide();
00588     }
00589 }
00590 
00591 void KisView::setupActions()
00592 {
00593     KisConfig cfg;
00594 
00595     m_selectionManager->setup(actionCollection());
00596     m_filterManager->setup(actionCollection());
00597     m_gridManager->setup(actionCollection());
00598 
00599     m_fullScreen = KStdAction::fullScreen( NULL, NULL, actionCollection(), this );
00600     connect( m_fullScreen, SIGNAL( toggled( bool )), this, SLOT( slotUpdateFullScreen( bool )));
00601 
00602     m_imgProperties = new KAction(i18n("Image Properties..."), 0, this, SLOT(slotImageProperties()), actionCollection(), "img_properties");
00603     m_imgScan = 0; // How the hell do I get a KAction to the scan plug-in?!?
00604     m_imgResizeToLayer = new KAction(i18n("Resize Image to Size of Current Layer"), 0, this, SLOT(imgResizeToActiveLayer()), actionCollection(), "resizeimgtolayer");
00605 
00606     // view actions
00607     m_zoomIn = KStdAction::zoomIn(this, SLOT(slotZoomIn()), actionCollection(), "zoom_in");
00608     m_zoomOut = KStdAction::zoomOut(this, SLOT(slotZoomOut()), actionCollection(), "zoom_out");
00609     m_actualPixels = new KAction(i18n("Actual Pixels"), "Ctrl+0", this, SLOT(slotActualPixels()), actionCollection(), "actual_pixels");
00610     m_actualSize = KStdAction::actualSize(this, SLOT(slotActualSize()), actionCollection(), "actual_size");
00611     m_actualSize->setEnabled(false);
00612     m_fitToCanvas = KStdAction::fitToPage(this, SLOT(slotFitToCanvas()), actionCollection(), "fit_to_canvas");
00613 
00614     // layer actions
00615     m_layerAdd = new KAction(i18n("&Add..."), "Ctrl+Shift+N", this, SLOT(layerAdd()), actionCollection(), "insert_layer");
00616 
00617     m_actionPartLayer = new KoPartSelectAction( i18n( "&Object Layer" ), "frame_query",
00618                                                     this, SLOT( addPartLayer() ),
00619                                                     actionCollection(), "insert_part_layer" );
00620 
00621 
00622     m_actionAdjustmentLayer = new KAction( i18n( "&Adjustment Layer" ), 0,
00623             this, SLOT( addAdjustmentLayer() ),
00624             actionCollection(), "insert_adjustment_layer" );
00625 
00626 
00627     m_layerRm = new KAction(i18n("&Remove"), 0, this, SLOT(layerRemove()), actionCollection(), "remove_layer");
00628     m_layerDup = new KAction(i18n("Duplicate"), 0, this, SLOT(layerDuplicate()), actionCollection(), "duplicate_layer");
00629     m_layerHide = new KAction(i18n("&Hide/Show"), 0, this, SLOT(layerToggleVisible()), actionCollection(), "hide_layer");
00630     m_layerRaise = new KAction(i18n("Raise"), "raise", "Ctrl+]", this, SLOT(layerRaise()), actionCollection(), "raiselayer");
00631     m_layerLower = new KAction(i18n("Lower"), "lower", "Ctrl+[", this, SLOT(layerLower()), actionCollection(), "lowerlayer");
00632     m_layerTop = new KAction(i18n("To Top"), "bring_forward", "Ctrl+Shift+]", this, SLOT(layerFront()), actionCollection(), "toplayer");
00633     m_layerBottom = new KAction(i18n("To Bottom"), "send_backward", "Ctrl+Shift+[", this, SLOT(layerBack()), actionCollection(), "bottomlayer");
00634     m_layerProperties = new KAction(i18n("Properties..."), 0, this, SLOT(layerProperties()), actionCollection(), "layer_properties");
00635     (void)new KAction(i18n("I&nsert Image as Layer..."), 0, this, SLOT(slotInsertImageAsLayer()), actionCollection(), "insert_image_as_layer");
00636     m_layerSaveAs = new KAction(i18n("Save Layer as Image..."), "filesave", this, SLOT(saveLayerAsImage()), actionCollection(), "save_layer_as_image");
00637     (void)new KAction(i18n("Flip on &X Axis"), "view_left_right", 0, this, SLOT(mirrorLayerX()), actionCollection(), "mirrorLayerX");
00638     (void)new KAction(i18n("Flip on &Y Axis"), "view_top_bottom", 0, this, SLOT(mirrorLayerY()), actionCollection(), "mirrorLayerY");
00639 
00640     // image actions
00641     m_imgFlatten = new KAction(i18n("&Flatten image"), "Ctrl+Shift+E", this, SLOT(flattenImage()), actionCollection(), "flatten_image");
00642     m_imgMergeLayer = new KAction(i18n("&Merge with Layer Below"), "Ctrl+E", this, SLOT(mergeLayer()), actionCollection(), "merge_layer");
00643 
00644     // setting actions
00645     KStdAction::preferences(this, SLOT(preferences()), actionCollection(), "preferences");
00646 
00647     m_RulerAction = new KToggleAction( i18n( "Show Rulers" ), "Ctrl+R", this, SLOT( showRuler() ), actionCollection(), "view_ruler" );
00648     m_RulerAction->setChecked(cfg.showRulers());
00649     m_RulerAction->setCheckedState(i18n("Hide Rulers"));
00650     m_RulerAction->setWhatsThis( i18n("The rulers show the horizontal and vertical positions of the mouse on the image "
00651                                       "and can be used to position your mouse at the right place on the canvas. <p>Uncheck this to disable "
00652                                       "the rulers from being displayed." ) );
00653 
00654     //m_guideAction = new KToggleAction( i18n( "Guide Lines" ), 0, this, SLOT( viewGuideLines() ), actionCollection(), "view_guidelines" );
00655 
00656     // Add new palette
00657     new KAction(i18n("Add New Palette..."), 0, this, SLOT(slotAddPalette()),
00658                 actionCollection(), "add_palette");
00659     new KAction(i18n("Edit Palette..."), 0, this, SLOT(slotEditPalette()),
00660                 actionCollection(), "edit_palette");
00661 
00662     // XXX: This triggers a repaint of the image, but way too early
00663     //showRuler();
00664 
00665 }
00666 
00667 void KisView::resizeEvent(QResizeEvent *)
00668 {
00669     if (!m_paintViewEnabled) {
00670         startInitialZoomTimerIfReady();
00671     }
00672 
00673     KisImageSP img = currentImg();
00674     Q_INT32 scrollBarExtent = style().pixelMetric(QStyle::PM_ScrollBarExtent);
00675     Q_INT32 drawH;
00676     Q_INT32 drawW;
00677     Q_INT32 docW;
00678     Q_INT32 docH;
00679 
00680 //    if (img) {
00681 //        KisGuideMgr *mgr = img->guides();
00682 //        mgr->resize(size());
00683 //    }
00684 
00685     docW = static_cast<Q_INT32>(ceil(docWidth() * zoom()));
00686     docH = static_cast<Q_INT32>(ceil(docHeight() * zoom()));
00687 
00688     m_rulerThickness = m_RulerAction->isChecked() ? RULER_THICKNESS : 0;
00689     drawH = height() - m_rulerThickness;
00690     drawW = width() - m_rulerThickness;
00691 
00692     if (drawH < docH) {
00693         // Will need vert scrollbar
00694         drawW -= scrollBarExtent;
00695         if (drawW < docW)
00696             // Will need horiz scrollbar
00697             drawH -= scrollBarExtent;
00698     } else if (drawW < docW) {
00699         // Will need horiz scrollbar
00700         drawH -= scrollBarExtent;
00701         if (drawH < docH)
00702             // Will need vert scrollbar
00703             drawW -= scrollBarExtent;
00704     }
00705 
00706     m_vScroll->setEnabled(docH > drawH);
00707     m_hScroll->setEnabled(docW > drawW);
00708 
00709     if (docH <= drawH && docW <= drawW) {
00710         // we need no scrollbars
00711         m_vScroll->hide();
00712         m_hScroll->hide();
00713         m_vScroll->setValue(0);
00714         m_hScroll->setValue(0);
00715         m_vScrollBarExtent = 0;
00716         m_hScrollBarExtent = 0;
00717     } else if (docH <= drawH) {
00718         // we need a horizontal scrollbar only
00719         m_vScroll->hide();
00720         m_vScroll->setValue(0);
00721         m_hScroll->setRange(0, docW - drawW);
00722         m_hScroll->setGeometry(m_rulerThickness,
00723                      height() - scrollBarExtent,
00724                      width() - m_rulerThickness,
00725                      scrollBarExtent);
00726         m_hScroll->show();
00727         m_hScrollBarExtent = scrollBarExtent;
00728         m_hScrollBarExtent = scrollBarExtent;
00729     } else if(docW <= drawW) {
00730         // we need a vertical scrollbar only
00731         m_hScroll->hide();
00732         m_hScroll->setValue(0);
00733         m_vScroll->setRange(0, docH - drawH);
00734         m_vScroll->setGeometry(width() - scrollBarExtent, m_rulerThickness, scrollBarExtent, height()  - m_rulerThickness);
00735         m_vScroll->show();
00736         m_vScrollBarExtent = scrollBarExtent;
00737     } else {
00738         // we need both scrollbars
00739         m_vScroll->setRange(0, docH - drawH);
00740         m_vScroll->setGeometry(width() - scrollBarExtent,
00741                     m_rulerThickness,
00742                     scrollBarExtent,
00743                     height() -2* m_rulerThickness);
00744         m_hScroll->setRange(0, docW - drawW);
00745         m_hScroll->setGeometry(m_rulerThickness,
00746                      height() - scrollBarExtent,
00747                      width() - 2*m_rulerThickness,
00748                      scrollBarExtent);
00749         m_vScroll->show();
00750         m_hScroll->show();
00751         m_vScrollBarExtent = scrollBarExtent;
00752         m_hScrollBarExtent = scrollBarExtent;
00753     }
00754 
00755     Q_INT32 oldCanvasXOffset = m_canvasXOffset;
00756     Q_INT32 oldCanvasYOffset = m_canvasYOffset;
00757 
00758     if (docW < drawW) {
00759         m_canvasXOffset = (drawW - docW) / 2;
00760     } else {
00761         m_canvasXOffset = 0;
00762     }
00763 
00764     if (docH < drawH) {
00765         m_canvasYOffset = (drawH - docH) / 2;
00766     } else {
00767         m_canvasYOffset = 0;
00768     }
00769 
00770     //Check if rulers are visible
00771     if( m_RulerAction->isChecked() )
00772         m_canvas->setGeometry(m_rulerThickness, m_rulerThickness, drawW, drawH);
00773     else
00774         m_canvas->setGeometry(0, 0, drawW, drawH);
00775     m_canvas->show();
00776 
00777     if (!m_canvas->isOpenGLCanvas()) {
00778 
00779         if (m_canvasPixmap.size() != QSize(drawW, drawH)) {
00780 
00781             Q_INT32 oldCanvasWidth = m_canvasPixmap.width();
00782             Q_INT32 oldCanvasHeight = m_canvasPixmap.height();
00783 
00784             Q_INT32 newCanvasWidth = drawW;
00785             Q_INT32 newCanvasHeight = drawH;
00786 
00787             QRegion exposedRegion = QRect(0, 0, newCanvasWidth, newCanvasHeight);
00788 
00789             // Increase size first so that we can copy the old image area to the new one.
00790             m_canvasPixmap.resize(QMAX(oldCanvasWidth, newCanvasWidth), QMAX(oldCanvasHeight, newCanvasHeight));
00791 
00792             if (!m_canvasPixmap.isNull()) {
00793 
00794                 if (oldCanvasXOffset != m_canvasXOffset || oldCanvasYOffset != m_canvasYOffset) {
00795 
00796                     Q_INT32 srcX;
00797                     Q_INT32 srcY;
00798                     Q_INT32 srcWidth;
00799                     Q_INT32 srcHeight;
00800                     Q_INT32 dstX;
00801                     Q_INT32 dstY;
00802 
00803                     if (oldCanvasXOffset <= m_canvasXOffset) {
00804                         // Move to the right
00805                         srcX = 0;
00806                         dstX = m_canvasXOffset - oldCanvasXOffset;
00807                         srcWidth = oldCanvasWidth;
00808                     } else {
00809                         // Move to the left
00810                         srcX = oldCanvasXOffset - m_canvasXOffset;
00811                         dstX = 0;
00812                         srcWidth = newCanvasWidth;
00813                     }
00814 
00815                     if (oldCanvasYOffset <= m_canvasYOffset) {
00816                         // Move down
00817                         srcY = 0;
00818                         dstY = m_canvasYOffset - oldCanvasYOffset;
00819                         srcHeight = oldCanvasHeight;
00820                     } else {
00821                         // Move up
00822                         srcY = oldCanvasYOffset - m_canvasYOffset;
00823                         dstY = 0;
00824                         srcHeight = newCanvasHeight;
00825                     }
00826 
00827                     bitBlt(&m_canvasPixmap, dstX, dstY, &m_canvasPixmap, srcX, srcY, srcWidth, srcHeight);
00828                     exposedRegion -= QRegion(QRect(dstX, dstY, srcWidth, srcHeight));
00829                 } else {
00830                     exposedRegion -= QRegion(QRect(0, 0, oldCanvasWidth, oldCanvasHeight));
00831                 }
00832             }
00833 
00834             m_canvasPixmap.resize(newCanvasWidth, newCanvasHeight);
00835 
00836             if (!m_canvasPixmap.isNull() && !exposedRegion.isEmpty()) {
00837 
00838                 QMemArray<QRect> rects = exposedRegion.rects();
00839 
00840                 for (unsigned int i = 0; i < rects.count(); i++) {
00841                     QRect r = rects[i];
00842                     updateQPaintDeviceCanvas(viewToWindow(r));
00843                 }
00844             }
00845         }
00846     }
00847 
00848     int fontheight = QFontMetrics(KGlobalSettings::generalFont()).height() * 3;
00849     m_vScroll->setPageStep(drawH);
00850     m_vScroll->setLineStep(fontheight);
00851     m_hScroll->setPageStep(drawW);
00852     m_hScroll->setLineStep(fontheight);
00853 
00854     m_hRuler->setGeometry(m_rulerThickness + m_canvasXOffset, 0, QMIN(docW, drawW), m_rulerThickness);
00855     m_vRuler->setGeometry(0, m_rulerThickness + m_canvasYOffset, m_rulerThickness, QMIN(docH, drawH));
00856 
00857     if (m_vScroll->isVisible())
00858         m_vRuler->updateVisibleArea(0, m_vScroll->value());
00859     else
00860         m_vRuler->updateVisibleArea(0, 0);
00861 
00862     if (m_hScroll->isVisible())
00863         m_hRuler->updateVisibleArea(m_hScroll->value(), 0);
00864     else
00865         m_hRuler->updateVisibleArea(0, 0);
00866 
00867     if( m_RulerAction->isChecked() )
00868     {
00869         m_hRuler->show();
00870         m_vRuler->show();
00871     }
00872     else {
00873         m_hRuler->hide();
00874         m_vRuler->hide();
00875     }
00876 
00877     emit viewTransformationsChanged();
00878 }
00879 
00880 void KisView::styleChange(QStyle& oldStyle)
00881 {
00882     Q_UNUSED(oldStyle);
00883     m_canvas->updateGeometry();
00884     refreshKisCanvas();
00885 }
00886 
00887 void KisView::paletteChange(const QPalette& oldPalette)
00888 {
00889     Q_UNUSED(oldPalette);
00890     refreshKisCanvas();
00891 }
00892 
00893 void KisView::showEvent(QShowEvent *)
00894 {
00895     if (!m_showEventReceived) {
00896         m_showEventReceived = true;
00897         startInitialZoomTimerIfReady();
00898     }
00899 }
00900 
00901 void KisView::updateReadWrite(bool readwrite)
00902 {
00903     layerUpdateGUI(readwrite);
00904 }
00905 
00906 Q_INT32 KisView::horzValue() const
00907 {
00908     return m_hScroll->value() - m_canvasXOffset;
00909 }
00910 
00911 Q_INT32 KisView::vertValue() const
00912 {
00913     return m_vScroll->value() - m_canvasYOffset;
00914 }
00915 
00916 void KisView::updateQPaintDeviceCanvas(const QRect& imageRect)
00917 {
00918     QRect vr = windowToView(imageRect);
00919     vr &= QRect(0, 0, m_canvas->width(), m_canvas->height());
00920 
00921     if (!vr.isEmpty()) {
00922 
00923         QPainter gc;
00924 
00925         if (gc.begin(&m_canvasPixmap)) {
00926 
00927             KisImageSP img = currentImg();
00928 
00929             if (img && m_paintViewEnabled) {
00930 
00931                 QRect wr = viewToWindow(vr);
00932 
00933                 if (wr.left() < 0 || wr.right() >= img->width() || wr.top() < 0 || wr.bottom() >= img->height()) {
00934                     // Erase areas outside document
00935                     QRegion rg(vr);
00936                     rg -= QRegion(windowToView(QRect(0, 0, img->width(), img->height())));
00937 
00938                     QMemArray<QRect> rects = rg.rects();
00939 
00940                     for (unsigned int i = 0; i < rects.count(); i++) {
00941                         QRect er = rects[i];
00942                         gc.fillRect(er, colorGroup().mid());
00943                     }
00944                     wr &= QRect(0, 0, img->width(), img->height());
00945                 }
00946 
00947                 if (!wr.isEmpty()) {
00948 
00949                     KisImage::PaintFlags paintFlags = (KisImage::PaintFlags)KisImage::PAINT_BACKGROUND;
00950 
00951                     if (m_actLayerVis) {
00952                         paintFlags = (KisImage::PaintFlags)(paintFlags|KisImage::PAINT_MASKINACTIVELAYERS);
00953                     }
00954 
00955                     if (m_selectionManager->displaySelection())
00956                     {
00957                         paintFlags = (KisImage::PaintFlags)(paintFlags|KisImage::PAINT_SELECTION);
00958                     }
00959 
00960                     if (zoom() > 1.0 - EPSILON) {
00961 
00962                         gc.setWorldXForm(true);
00963                         gc.translate(-horzValue(), -vertValue());
00964                         gc.scale(zoomFactor(), zoomFactor());
00965 
00966                         m_image->renderToPainter(wr.left(), wr.top(),
00967                             wr.right(), wr.bottom(), gc, monitorProfile(),
00968                             paintFlags, HDRExposure());
00969                     } else {
00970 
00971                         QRect canvasRect = windowToView(wr);
00972                         QRect scaledImageRect = canvasRect;
00973                         scaledImageRect.moveBy(horzValue(), vertValue());
00974 
00975                         QSize scaledImageSize(static_cast<Q_INT32>(ceil(docWidth() * zoom())),
00976                                             static_cast<Q_INT32>(ceil(docHeight() * zoom())));
00977 
00978                         QImage image = m_image->convertToQImage(scaledImageRect, scaledImageSize,
00979                                                                 monitorProfile(), paintFlags, HDRExposure());
00980 
00981                         gc.drawImage(canvasRect.topLeft(), image, image.rect());
00982 
00983                         // Set up for the grid drawer.
00984                         gc.setWorldXForm(true);
00985                         gc.translate(-horzValue(), -vertValue());
00986                         gc.scale(zoomFactor(), zoomFactor());
00987                     }
00988 
00989                     m_gridManager->drawGrid( wr, &gc );
00990                 }
00991 //                    paintGuides();
00992             } else {
00993                 gc.fillRect(vr, colorGroup().mid());
00994             }
00995         }
00996     }
00997 }
00998 
00999 void KisView::paintQPaintDeviceView(const QRegion& canvasRegion)
01000 {
01001     Q_ASSERT(m_canvas->QPaintDeviceWidget() != 0);
01002 
01003     if (m_canvas->QPaintDeviceWidget() != 0 && !m_canvasPixmap.isNull()) {
01004         QMemArray<QRect> rects = canvasRegion.rects();
01005 
01006         for (unsigned int i = 0; i < rects.count(); i++) {
01007             QRect r = rects[i];
01008 
01009             bitBlt(m_canvas->QPaintDeviceWidget(), r.x(), r.y(), &m_canvasPixmap,
01010                    r.x(), r.y(), r.width(), r.height());
01011         }
01012 
01013         paintToolOverlay(canvasRegion);
01014     }
01015 }
01016 
01017 void KisView::updateOpenGLCanvas(const QRect& imageRect)
01018 {
01019 #ifdef HAVE_GL
01020     KisImageSP img = currentImg();
01021 
01022     if (img && m_paintViewEnabled) {
01023         Q_ASSERT(m_OpenGLImageContext != 0);
01024 
01025         if (m_OpenGLImageContext != 0) {
01026             m_OpenGLImageContext->update(imageRect);
01027         }
01028     }
01029 #else
01030     Q_UNUSED(imageRect);
01031 #endif
01032 }
01033 
01034 void KisView::paintOpenGLView(const QRect& canvasRect)
01035 {
01036 #ifdef HAVE_GL
01037     if (!m_canvas->isUpdatesEnabled()) {
01038         return;
01039     }
01040 
01041     m_canvas->OpenGLWidget()->makeCurrent();
01042 
01043     glDrawBuffer(GL_BACK);
01044 
01045     QColor widgetBackgroundColor = colorGroup().mid();
01046 
01047     glClearColor(widgetBackgroundColor.red() / 255.0, widgetBackgroundColor.green() / 255.0, widgetBackgroundColor.blue() / 255.0, 1.0);
01048     glClear(GL_COLOR_BUFFER_BIT);
01049 
01050     KisImageSP img = currentImg();
01051 
01052     if (img && m_paintViewEnabled) {
01053 
01054         QRect vr = canvasRect;
01055         vr &= QRect(0, 0, m_canvas->width(), m_canvas->height());
01056 
01057         if (!vr.isNull()) {
01058 
01059             glMatrixMode(GL_PROJECTION);
01060             glLoadIdentity();
01061             glViewport(0, 0, m_canvas->width(), m_canvas->height());
01062             glOrtho(0, m_canvas->width(), m_canvas->height(), 0, -1, 1);
01063 
01064             glMatrixMode(GL_MODELVIEW);
01065             glLoadIdentity();
01066 
01067             glBindTexture(GL_TEXTURE_2D, m_OpenGLImageContext->backgroundTexture());
01068 
01069             glTranslatef(m_canvasXOffset, m_canvasYOffset, 0.0);
01070 
01071             glEnable(GL_TEXTURE_2D);
01072             glBegin(GL_QUADS);
01073 
01074             glTexCoord2f(0.0, 0.0);
01075             glVertex2f(0.0, 0.0);
01076 
01077             glTexCoord2f((img->width() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_WIDTH, 0.0);
01078             glVertex2f(img->width() * zoom(), 0.0);
01079 
01080             glTexCoord2f((img->width() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_WIDTH,
01081                          (img->height() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_HEIGHT);
01082             glVertex2f(img->width() * zoom(), img->height() * zoom());
01083 
01084             glTexCoord2f(0.0, (img->height() * zoom()) / KisOpenGLImageContext::BACKGROUND_TEXTURE_HEIGHT);
01085             glVertex2f(0.0, img->height() * zoom());
01086 
01087             glEnd();
01088 
01089             glTranslatef(-m_canvasXOffset, -m_canvasYOffset, 0.0);
01090 
01091             glTranslatef(-horzValue(), -vertValue(), 0.0);
01092             glScalef(zoomFactor(), zoomFactor(), 1.0);
01093 
01094             glEnable(GL_BLEND);
01095             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
01096 
01097             QRect wr = viewToWindow(QRect(0, 0, m_canvas->width(), m_canvas->height()));
01098             wr &= QRect(0, 0, img->width(), img->height());
01099 
01100             m_OpenGLImageContext->setHDRExposure(HDRExposure());
01101 
01102             m_canvas->OpenGLWidget()->makeCurrent();
01103 
01104             for (int x = (wr.left() / m_OpenGLImageContext->imageTextureTileWidth()) * m_OpenGLImageContext->imageTextureTileWidth();
01105                   x <= wr.right();
01106                   x += m_OpenGLImageContext->imageTextureTileWidth()) {
01107                 for (int y = (wr.top() / m_OpenGLImageContext->imageTextureTileHeight()) * m_OpenGLImageContext->imageTextureTileHeight();
01108                       y <= wr.bottom();
01109                       y += m_OpenGLImageContext->imageTextureTileHeight()) {
01110 
01111                     glBindTexture(GL_TEXTURE_2D, m_OpenGLImageContext->imageTextureTile(x, y));
01112 
01113                     glBegin(GL_QUADS);
01114 
01115                     glTexCoord2f(0.0, 0.0);
01116                     glVertex2f(x, y);
01117 
01118                     glTexCoord2f(1.0, 0.0);
01119                     glVertex2f(x + m_OpenGLImageContext->imageTextureTileWidth(), y);
01120 
01121                     glTexCoord2f(1.0, 1.0);
01122                     glVertex2f(x + m_OpenGLImageContext->imageTextureTileWidth(), y + m_OpenGLImageContext->imageTextureTileHeight());
01123 
01124                     glTexCoord2f(0.0, 1.0);
01125                     glVertex2f(x, y + m_OpenGLImageContext->imageTextureTileHeight());
01126 
01127                     glEnd();
01128                 }
01129             }
01130 
01131             glDisable(GL_TEXTURE_2D);
01132             glDisable(GL_BLEND);
01133 
01134             m_gridManager->drawGrid(wr, 0, true);
01135 
01136             // Unbind the texture otherwise the ATI driver crashes when the canvas context is
01137             // made current after the textures are deleted following an image resize.
01138             glBindTexture(GL_TEXTURE_2D, 0);
01139 
01140             //paintGuides();
01141         }
01142     }
01143 
01144     m_canvas->OpenGLWidget()->swapBuffers();
01145 
01146     paintToolOverlay(QRegion(canvasRect));
01147 
01148 #else
01149     Q_UNUSED(canvasRect);
01150 #endif
01151 }
01152 
01153 void KisView::setInputDevice(KisInputDevice inputDevice)
01154 {
01155     if (inputDevice != m_inputDevice) {
01156         m_inputDevice = inputDevice;
01157 
01158         m_toolManager->setToolForInputDevice(m_inputDevice, inputDevice);
01159 
01160         if (m_toolManager->currentTool() == 0) {
01161             m_toolManager->setCurrentTool(m_toolManager->findTool("tool_brush", m_inputDevice));
01162         }
01163         else {
01164             m_toolManager->setCurrentTool(m_toolManager->currentTool());
01165         }
01166         m_toolManager->activateCurrentTool();
01167 
01168         emit sigInputDeviceChanged(inputDevice);
01169     }
01170 
01171 }
01172 
01173 KisInputDevice KisView::currentInputDevice() const
01174 {
01175     return m_inputDevice;
01176 }
01177 
01178 
01179 KisCanvas *KisView::kiscanvas() const
01180 {
01181     return m_canvas;
01182 }
01183 
01184 void KisView::updateCanvas()
01185 {
01186     if (m_image) {
01187         updateCanvas(m_image->bounds());
01188     }
01189 }
01190 
01191 void KisView::updateCanvas(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h)
01192 {
01193     updateCanvas(QRect(x, y, w, h));
01194 }
01195 
01196 void KisView::updateCanvas(const QRect& imageRect)
01197 {
01198     if (m_canvas->isOpenGLCanvas()) {
01199         updateOpenGLCanvas(imageRect);
01200         paintOpenGLView(windowToView(imageRect));
01201     } else {
01202         updateQPaintDeviceCanvas(imageRect);
01203         //m_canvas->update(windowToView(imageRect));
01204         m_canvas->repaint(windowToView(imageRect));
01205     }
01206 }
01207 
01208 void KisView::refreshKisCanvas()
01209 {
01210     QRect imageRect = viewToWindow(QRect(0, 0, m_canvas->width(), m_canvas->height()));
01211 
01212     if (m_image) {
01213         imageRect |= m_image->bounds();
01214     }
01215 
01216     updateCanvas(imageRect);
01217 
01218     // Enable this if updateCanvas does an m_canvas->update()
01219     //m_canvas->repaint();
01220 }
01221 
01222 void KisView::selectionDisplayToggled(bool displaySelection)
01223 {
01224 #ifdef HAVE_GL
01225     if (m_canvas->isOpenGLCanvas()) {
01226         if (m_OpenGLImageContext) {
01227             m_OpenGLImageContext->setSelectionDisplayEnabled(displaySelection);
01228         }
01229     }
01230 #else
01231     Q_UNUSED(displaySelection);
01232 #endif
01233     updateCanvas();
01234 }
01235 
01236 void KisView::layerUpdateGUI(bool enable)
01237 {
01238     KisImageSP img = currentImg();
01239 
01240     KisLayerSP layer;
01241     Q_INT32 nlayers = 0;
01242     Q_INT32 nvisible = 0;
01243 
01244     
01245     
01246     if (img) {
01247         layer = img->activeLayer();
01248         nlayers = img->nlayers();
01249         nvisible = nlayers - img->nHiddenLayers();
01250     }
01251 
01252     KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(layer.data());
01253         
01254     if (pl && ( m_currentColorChooserDisplay != KisID("BLA") ||
01255                 pl->paintDevice()->colorSpace()->id() != m_currentColorChooserDisplay)) {
01256         if (pl->paintDevice()->colorSpace()->id() == KisID("WET")) {
01257             m_paletteManager->hideWidget( "hsvwidget" );
01258             m_paletteManager->hideWidget( "rgbwidget" );
01259             m_paletteManager->hideWidget( "graywidget" );
01260             m_paletteManager->hideWidget( "palettewidget" );
01261             m_paletteManager->showWidget( "watercolor docker" );
01262         }
01263         else {
01264             m_paletteManager->hideWidget( "watercolor docker" );
01265             m_paletteManager->showWidget( "palettewidget" );
01266             m_paletteManager->showWidget( "graywidget" );
01267             m_paletteManager->showWidget( "rgbwidget" );
01268             m_paletteManager->showWidget( "hsvwidget" );
01269         }
01270         m_currentColorChooserDisplay = pl->paintDevice()->colorSpace()->id();
01271     }
01272 
01273     enable = enable && img && layer && layer->visible() && !layer->locked();
01274     m_layerDup->setEnabled(enable);
01275     m_layerRm->setEnabled(enable);
01276     m_layerHide->setEnabled(img && layer);
01277     m_layerProperties->setEnabled(enable);
01278     m_layerSaveAs->setEnabled(enable);
01279     m_layerRaise->setEnabled(enable && layer->prevSibling());
01280     m_layerLower->setEnabled(enable && layer->nextSibling());
01281     m_layerTop->setEnabled(enable && nlayers > 1 && layer != img->rootLayer()->firstChild());
01282     m_layerBottom->setEnabled(enable && nlayers > 1 && layer != img->rootLayer()->lastChild());
01283 
01284     // XXX these should be named layer instead of img
01285     m_imgFlatten->setEnabled(nlayers > 1);
01286     m_imgMergeLayer->setEnabled(nlayers > 1 && layer && layer->nextSibling());
01287 
01288 
01289     m_selectionManager->updateGUI();
01290     m_filterManager->updateGUI();
01291     m_toolManager->updateGUI();
01292     m_gridManager->updateGUI();
01293 
01294 
01295     KisPartLayer * partLayer = dynamic_cast<KisPartLayer*>(layer.data());
01296     if (partLayer) {
01297         setCanvasCursor( KisCursor::arrowCursor() ); 
01298     }
01299     
01300     if (img && img->activeDevice())
01301         emit currentColorSpaceChanged(img->activeDevice()->colorSpace());
01302 
01303     imgUpdateGUI();
01304 }
01305 
01306 
01307 void KisView::imgUpdateGUI()
01308 {
01309     KisImageSP img = currentImg();
01310 
01311     m_imgResizeToLayer->setEnabled(img && img->activeLayer());
01312 
01313     updateStatusBarProfileLabel();
01314 }
01315 
01316 static const double zoomLevels[] = {
01317     1.0 / 500,
01318     1.0 / 333.333333,
01319     1.0 / 250,
01320     1.0 / 200,
01321     1.0 / 150,
01322     1.0 / 100,
01323     1.0 / 66.666667,
01324     1.0 / 50,
01325     1.0 / 33.333333,
01326     1.0 / 25,
01327     1.0 / 20,
01328     1.0 / 16,
01329     1.0 / 12,
01330     1.0 / 8,
01331     1.0 / 6,
01332     1.0 / 4,
01333     1.0 / 3,
01334     1.0 / 2,
01335     1.0 / 1.5,
01336     1,
01337     2,
01338     3,
01339     4,
01340     5,
01341     6,
01342     7,
01343     8,
01344     12,
01345     16
01346 };
01347 
01348 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
01349 #define NUM_ZOOM_LEVELS ARRAY_SIZE(zoomLevels)
01350 
01351 #define FIRST_ZOOM_LEVEL_INDEX 0
01352 #define LAST_ZOOM_LEVEL_INDEX (NUM_ZOOM_LEVELS - 1)
01353 
01354 #define KISVIEW_MIN_ZOOM (zoomLevels[FIRST_ZOOM_LEVEL_INDEX])
01355 #define KISVIEW_MAX_ZOOM (zoomLevels[LAST_ZOOM_LEVEL_INDEX])
01356 
01357 double KisView::nextZoomInLevel() const
01358 {
01359     uint zoomLevelIndex = FIRST_ZOOM_LEVEL_INDEX;
01360 
01361     while (zoom() >= zoomLevels[zoomLevelIndex] && zoomLevelIndex < LAST_ZOOM_LEVEL_INDEX) {
01362         zoomLevelIndex++;
01363     }
01364 
01365     return zoomLevels[zoomLevelIndex];
01366 }
01367 
01368 double KisView::nextZoomOutLevel(double zoomLevel) const
01369 {
01370     int zoomLevelIndex = LAST_ZOOM_LEVEL_INDEX;
01371 
01372     while (zoomLevel <= zoomLevels[zoomLevelIndex] && zoomLevelIndex > FIRST_ZOOM_LEVEL_INDEX) {
01373         zoomLevelIndex--;
01374     }
01375 
01376     return zoomLevels[zoomLevelIndex];
01377 }
01378 
01379 double KisView::nextZoomOutLevel() const
01380 {
01381     return nextZoomOutLevel(zoom());
01382 }
01383 
01384 void KisView::zoomAroundPoint(double x, double y, double zf)
01385 {
01386     // Disable updates while we change the scrollbar settings.
01387     m_canvas->setUpdatesEnabled(false);
01388     m_hScroll->setUpdatesEnabled(false);
01389     m_vScroll->setUpdatesEnabled(false);
01390 
01391     if (x < 0 || y < 0) {
01392         // Zoom about the centre of the current display
01393         KisImageSP img = currentImg();
01394 
01395         if (img) {
01396             if (m_hScroll->isVisible()) {
01397                 KisPoint c = viewToWindow(KisPoint(m_canvas->width() / 2.0, m_canvas->height() / 2.0));
01398                 x = c.x();
01399             }
01400             else {
01401                 x = img->width() / 2.0;
01402             }
01403 
01404             if (m_vScroll->isVisible()) {
01405                 KisPoint c = viewToWindow(KisPoint(m_canvas->width() / 2.0, m_canvas->height() / 2.0));
01406                 y = c.y();
01407             }
01408             else {
01409                 y = img->height() / 2.0;
01410             }
01411         }
01412         else {
01413             x = 0;
01414             y = 0;
01415         }
01416     }
01417 
01418     setZoom(zf);
01419 
01420     Q_ASSERT(m_zoomIn);
01421     Q_ASSERT(m_zoomOut);
01422 
01423     updateStatusBarZoomLabel ();
01424 
01425     m_zoomIn->setEnabled(zf < KISVIEW_MAX_ZOOM);
01426     m_zoomOut->setEnabled(zf > KISVIEW_MIN_ZOOM);
01427     resizeEvent(0);
01428 
01429     m_hRuler->setZoom(zf);
01430     m_vRuler->setZoom(zf);
01431 
01432     if (m_hScroll->isVisible()) {
01433         double vcx = m_canvas->width() / 2.0;
01434         Q_INT32 scrollX = qRound(x * zoom() - vcx);
01435         m_hScroll->setValue(scrollX);
01436     }
01437 
01438     if (m_vScroll->isVisible()) {
01439         double vcy = m_canvas->height() / 2.0;
01440         Q_INT32 scrollY = qRound(y * zoom() - vcy);
01441         m_vScroll->setValue(scrollY);
01442     }
01443 
01444     // Now update everything.
01445     m_canvas->setUpdatesEnabled(true);
01446     m_hScroll->setUpdatesEnabled(true);
01447     m_vScroll->setUpdatesEnabled(true);
01448     m_hScroll->update();
01449     m_vScroll->update();
01450 
01451     if (m_canvas->isOpenGLCanvas()) {
01452         paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
01453     } else {
01454         refreshKisCanvas();
01455     }
01456 
01457     emit viewTransformationsChanged();
01458 }
01459 
01460 void KisView::zoomTo(const KisRect& r)
01461 {
01462     if (!r.isNull()) {
01463 
01464         double wZoom = fabs(m_canvas->width() / r.width());
01465         double hZoom = fabs(m_canvas->height() / r.height());
01466 
01467         double zf = kMin(wZoom, hZoom);
01468 
01469         if (zf < KISVIEW_MIN_ZOOM) {
01470             zf = KISVIEW_MIN_ZOOM;
01471         }
01472         else
01473             if (zf > KISVIEW_MAX_ZOOM) {
01474                 zf = KISVIEW_MAX_ZOOM;
01475             }
01476 
01477         zoomAroundPoint(r.center().x(), r.center().y(), zf);
01478     }
01479 }
01480 
01481 void KisView::zoomTo(const QRect& r)
01482 {
01483     zoomTo(KisRect(r));
01484 }
01485 
01486 void KisView::zoomTo(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h)
01487 {
01488     zoomTo(KisRect(x, y, w, h));
01489 }
01490 
01491 void KisView::zoomIn(Q_INT32 x, Q_INT32 y)
01492 {
01493     zoomAroundPoint(x, y, nextZoomInLevel());
01494 }
01495 
01496 void KisView::zoomOut(Q_INT32 x, Q_INT32 y)
01497 {
01498     zoomAroundPoint(x, y, nextZoomOutLevel());
01499 }
01500 
01501 void KisView::zoomIn()
01502 {
01503     slotZoomIn();
01504 }
01505 
01506 void KisView::zoomOut()
01507 {
01508     slotZoomOut();
01509 }
01510 
01511 void KisView::slotZoomIn()
01512 {
01513     zoomIn(-1, -1);
01514 }
01515 
01516 void KisView::slotZoomOut()
01517 {
01518     zoomOut(-1, -1);
01519 }
01520 
01521 void KisView::slotActualPixels()
01522 {
01523     zoomAroundPoint(-1, -1, 1.0);
01524 }
01525 
01526 void KisView::slotActualSize()
01527 {
01528     //XXX later this should be update to take screen res and image res into consideration
01529     zoomAroundPoint(-1, -1, 1.0);
01530 }
01531 
01532 double KisView::fitToCanvasZoomLevel() const
01533 {
01534     int fullCanvasWidth = width();
01535 
01536     if (m_vRuler->isVisible()) {
01537         fullCanvasWidth -= m_vRuler->width();
01538     }
01539 
01540     int fullCanvasHeight = height();
01541 
01542     if (m_hRuler->isVisible()) {
01543         fullCanvasHeight -= m_hRuler->height();
01544     }
01545 
01546     KisImageSP img = currentImg();
01547     if (img) {
01548         double xZoomLevel = static_cast<double>(fullCanvasWidth) / img->width();
01549         double yZoomLevel = static_cast<double>(fullCanvasHeight) / img->height();
01550 
01551         return QMIN(xZoomLevel, yZoomLevel);
01552     }
01553     else {
01554         return 1;
01555     }
01556 }
01557 
01558 void KisView::slotFitToCanvas()
01559 {
01560     zoomAroundPoint(-1, -1, fitToCanvasZoomLevel());
01561 }
01562 
01563 void KisView::setInitialZoomLevel()
01564 {
01565     double zoomLevel = fitToCanvasZoomLevel();
01566 
01567     if (zoomLevel > 1) {
01568         zoomLevel = 1;
01569     } else {
01570         zoomLevel = nextZoomOutLevel(zoomLevel);
01571     }
01572 
01573     zoomAroundPoint(-1, -1, zoomLevel);
01574 }
01575 
01576 void KisView::imgResizeToActiveLayer()
01577 {
01578     KisImageSP img = currentImg();
01579     KisLayerSP layer;
01580 
01581     if (img && (layer = img->activeLayer())) {
01582 
01583         if (m_adapter && m_adapter->undo()) {
01584             m_adapter->beginMacro(i18n("Resize Image to Size of Current Layer"));
01585         }
01586 
01587         img->lock();
01588 
01589         QRect r = layer->exactBounds();
01590         img->resize(r.width(), r.height(), r.x(), r.y(), true);
01591 
01592         img->unlock();
01593 
01594         if (m_adapter && m_adapter->undo()) {
01595             m_adapter->endMacro();
01596         }
01597     }
01598 }
01599 
01600 void KisView::slotImageProperties()
01601 {
01602     KisImageSP img = currentImg();
01603 
01604     if (!img) return;
01605 
01606     KisDlgImageProperties dlg(img, this);
01607 
01608     if (dlg.exec() == QDialog::Accepted) {
01609         if (dlg.imageWidth() != img->width() ||
01610             dlg.imageHeight() != img->height()) {
01611 
01612             resizeCurrentImage(dlg.imageWidth(),
01613                                dlg.imageHeight());
01614         }
01615         Q_INT32 opacity = dlg.opacity();
01616         opacity = opacity * 255 / 100;
01617         img->setName(dlg.imageName());
01618         img->setColorSpace(dlg.colorSpace());
01619         img->setResolution(dlg.resolution(), dlg.resolution());
01620         img->setDescription(dlg.description());
01621         img->setProfile(dlg.profile());
01622     }
01623 }
01624 
01625 void KisView::slotInsertImageAsLayer()
01626 {
01627     if (importImage() > 0)
01628         m_doc->setModified(true);
01629 }
01630 
01631 void KisView::slotAddPalette()
01632 {
01633     KDialogBase* base = new KDialogBase(this, 0, true, i18n("Add Palette"), KDialogBase::Ok | KDialogBase::Cancel);
01634     KisCustomPalette* p = new KisCustomPalette(base, "add palette", i18n("Add Palette"), this);
01635     base->setMainWidget(p);
01636     base->show();
01637 }
01638 
01639 void KisView::slotEditPalette()
01640 {
01641     KisPaletteChooser chooser(this);
01642     KisResourceServerBase* srv = KisResourceServerRegistry::instance()->get("PaletteServer");
01643     if (!srv) {
01644         return;
01645     }
01646     QValueList<KisResource*> resources = srv->resources();
01647     QValueList<KisPalette*> palettes;
01648 
01649     for(uint i = 0; i < resources.count(); i++) {
01650         KisPalette* palette = dynamic_cast<KisPalette*>(*resources.at(i));
01651 
01652         chooser.paletteList->insertItem(palette->name());
01653         palettes.append(palette);
01654     }
01655 
01656     if (chooser.exec() != QDialog::Accepted ) {
01657         return;
01658     }
01659 
01660     int index = chooser.paletteList->currentItem();
01661     if (index < 0) {
01662         KMessageBox::error(this, i18n("No palette selected."), i18n("Palette"));
01663         return;
01664     }
01665 
01666     KDialogBase* base = new KDialogBase(this, 0, true, i18n("Edit Palette") , KDialogBase::Ok);
01667     KisCustomPalette* cp = new KisCustomPalette(base, "edit palette",
01668             i18n("Edit Palette"), this);
01669     cp->setEditMode(true);
01670     cp->setPalette(*palettes.at(index));
01671     base->setMainWidget(cp);
01672     base->show();
01673 }
01674 
01675 void KisView::saveLayerAsImage()
01676 {
01677     QStringList listMimeFilter = KoFilterManager::mimeFilter("application/x-krita", KoFilterManager::Export);
01678     QString mimelist = listMimeFilter.join(" ");
01679 
01680     KFileDialog fd (QString::null, mimelist, this, "Export Layer", true);
01681     fd.setCaption(i18n("Export Layer"));
01682     fd.setMimeFilter(listMimeFilter);
01683     fd.setOperationMode(KFileDialog::Saving);
01684 
01685     if (!fd.exec()) return;
01686 
01687     KURL url = fd.selectedURL();
01688     QString mimefilter = fd.currentMimeFilter();
01689 
01690     if (url.isEmpty())
01691         return;
01692 
01693 
01694     KisImageSP img = currentImg();
01695     if (!img) return;
01696 
01697     KisLayerSP l = img->activeLayer();
01698     if (!l) return;
01699 
01700     QRect r = l->exactBounds();
01701 
01702     KisDoc d;
01703     d.prepareForImport();
01704 
01705     KisImageSP dst = new KisImage(d.undoAdapter(), r.width(), r.height(), img->colorSpace(), l->name());
01706     d.setCurrentImage( dst );
01707     dst->addLayer(l->clone(),dst->rootLayer(),0);
01708 
01709     d.setOutputMimeType(mimefilter.latin1());
01710     d.exp0rt(url);
01711 }
01712 
01713 
01714 
01715 Q_INT32 KisView::importImage(const KURL& urlArg)
01716 {
01717     KisImageSP currentImage = currentImg();
01718 
01719     if (!currentImage) {
01720         return 0;
01721     }
01722 
01723     KURL::List urls;
01724     Q_INT32 rc = 0;
01725 
01726     if (urlArg.isEmpty()) {
01727         QString mimelist = KoFilterManager::mimeFilter("application/x-krita", KoFilterManager::Import).join(" ");
01728         urls = KFileDialog::getOpenURLs(QString::null, mimelist, 0, i18n("Import Image"));
01729     } else {
01730         urls.push_back(urlArg);
01731     }
01732 
01733     if (urls.empty())
01734         return 0;
01735 
01736     for (KURL::List::iterator it = urls.begin(); it != urls.end(); ++it) {
01737         KURL url = *it;
01738         KisDoc d;
01739         d.import(url);
01740         KisImageSP importedImage = d.currentImage();
01741 
01742         if (importedImage) {
01743             KisLayerSP importedImageLayer = importedImage->rootLayer().data();
01744 
01745             if (importedImageLayer != 0) {
01746 
01747                 if (importedImageLayer->numLayers() == 2) {
01748                     // Don't import the root if this is not a layered image (1 group layer
01749                     // plus 1 other).
01750                     importedImageLayer = importedImageLayer->firstChild();
01751                     importedImageLayer->parent()->removeLayer(importedImageLayer);
01752                 }
01753 
01754                 importedImageLayer->setName(url.prettyURL());
01755 
01756                 KisGroupLayerSP parent = 0;
01757                 KisLayerSP currentActiveLayer = currentImage->activeLayer();
01758 
01759                 if (currentActiveLayer) {
01760                     parent = currentActiveLayer->parent();
01761                 }
01762 
01763                 if (parent == 0) {
01764                     parent = currentImage->rootLayer();
01765                 }
01766 
01767                 currentImage->addLayer(importedImageLayer.data(), parent, currentActiveLayer);
01768                 rc += importedImageLayer->numLayers();
01769             }
01770         }
01771     }
01772 
01773     updateCanvas();
01774 
01775     return rc;
01776 }
01777 
01778 void KisView::rotateLayer180()
01779 {
01780     rotateLayer( 180 );
01781 }
01782 
01783 void KisView::rotateLayerLeft90()
01784 {
01785     rotateLayer( 270 );
01786 }
01787 
01788 void KisView::rotateLayerRight90()
01789 {
01790     rotateLayer( 90 );
01791 }
01792 
01793 void KisView::mirrorLayerX()
01794 {
01795     if (!currentImg()) return;
01796     KisPaintDeviceSP dev = currentImg()->activeDevice();
01797     if (!dev) return;
01798 
01799     KisTransaction * t = 0;
01800     if (undoAdapter() && undoAdapter()->undo()) {
01801         t = new KisTransaction(i18n("Mirror Layer X"), dev);
01802         Q_CHECK_PTR(t);
01803     }
01804 
01805     dev->mirrorX();
01806 
01807     if (t) undoAdapter()->addCommand(t);
01808 
01809     m_doc->setModified(true);
01810     layersUpdated();
01811     updateCanvas();
01812 }
01813 
01814 void KisView::mirrorLayerY()
01815 {
01816     if (!currentImg()) return;
01817     KisPaintDeviceSP dev = currentImg()->activeDevice();
01818     if (!dev) return;
01819 
01820     KisTransaction * t = 0;
01821     if (undoAdapter() && undoAdapter()->undo()) {
01822         t = new KisTransaction(i18n("Mirror Layer Y"), dev);
01823         Q_CHECK_PTR(t);
01824     }
01825 
01826     dev->mirrorY();
01827 
01828     if (t) undoAdapter()->addCommand(t);
01829 
01830     m_doc->setModified(true);
01831     layersUpdated();
01832     updateCanvas();
01833 }
01834 
01835 void KisView::scaleLayer(double sx, double sy, KisFilterStrategy *filterStrategy)
01836 {
01837     if (!currentImg()) return;
01838 
01839     KisPaintDeviceSP dev = currentImg()->activeDevice();
01840     if (!dev) return;
01841 
01842     KisTransaction * t = 0;
01843     if (undoAdapter() && undoAdapter()->undo()) {
01844         t = new KisTransaction(i18n("Scale Layer"), dev);
01845         Q_CHECK_PTR(t);
01846     }
01847 
01848     KisTransformWorker worker(dev, sx, sy, 0, 0, 0.0, 0, 0, m_progress, filterStrategy);
01849     worker.run();
01850 
01851     if (t) undoAdapter()->addCommand(t);
01852 
01853     m_doc->setModified(true);
01854     layersUpdated();
01855     updateCanvas();
01856 }
01857 
01858 void KisView::rotateLayer(double angle)
01859 {
01860     if (!currentImg()) return;
01861 
01862     KisPaintDeviceSP dev = currentImg()->activeDevice();
01863     if (!dev) return;
01864 
01865     KisTransaction * t = 0;
01866     if (undoAdapter() && undoAdapter()->undo()) {
01867         t = new KisTransaction(i18n("Rotate Layer"), dev);
01868         Q_CHECK_PTR(t);
01869     }
01870 
01871     KisFilterStrategy *filter = KisFilterStrategyRegistry::instance()->get(KisID("Triangle"));
01872     angle *= M_PI/180;
01873     Q_INT32 w = currentImg()->width();
01874     Q_INT32 h = currentImg()->height();
01875     Q_INT32 tx = Q_INT32((w*cos(angle) - h*sin(angle) - w) / 2 + 0.5);
01876     Q_INT32 ty = Q_INT32((h*cos(angle) + w*sin(angle) - h) / 2 + 0.5);
01877 
01878     KisTransformWorker tw(dev, 1.0, 1.0, 0, 0, angle, -tx, -ty, m_progress, filter);
01879     tw.run();
01880 
01881     if (t) undoAdapter()->addCommand(t);
01882 
01883     m_doc->setModified(true);
01884     layersUpdated();
01885     updateCanvas();
01886 }
01887 
01888 void KisView::shearLayer(double angleX, double angleY)
01889 {
01890     if (!currentImg()) return;
01891 
01892     KisLayerSP layer = currentImg()->activeLayer();
01893     if (!layer) return;
01894 
01895     KisUndoAdapter * undo = 0;
01896     if ((undo = currentImg()->undoAdapter())) {
01897         undo->beginMacro(i18n("Shear layer"));
01898     }
01899 
01900     KisShearVisitor v(angleX, angleY, m_progress);
01901     v.setUndoAdapter(undo);
01902     layer->accept(v);
01903 
01904     if (undo) undo->endMacro();
01905 
01906     m_doc->setModified(true);
01907     layersUpdated();
01908     updateCanvas();
01909 }
01910 
01911 void KisView::flattenImage()
01912 {
01913     KisImageSP img = currentImg();
01914 
01915     if (img) {
01916         bool doIt = true;
01917 
01918         if (img->nHiddenLayers() > 0) {
01919             int answer = KMessageBox::warningYesNo(this,
01920                                    i18n("The image contains hidden layers that will be lost."),
01921                                    i18n("Flatten Image"),
01922                                    i18n("&Flatten Image"),
01923                                    KStdGuiItem::cancel());
01924 
01925             if (answer != KMessageBox::Yes) {
01926                 doIt = false;
01927             }
01928         }
01929 
01930         if (doIt) {
01931             img->flatten();
01932         }
01933     }
01934 }
01935 
01936 void KisView::mergeLayer()
01937 {
01938     KisImageSP img = currentImg();
01939     if (!img) return;
01940 
01941     KisLayerSP layer = img->activeLayer();
01942     if (!layer) return;
01943 
01944     img->mergeLayer(layer);
01945 }
01946 
01947 void KisView::preferences()
01948 {
01949 #ifdef HAVE_GL
01950     bool canvasWasOpenGL = m_canvas->isOpenGLCanvas();
01951 #endif
01952 
01953     if (PreferencesDialog::editPreferences())
01954     {
01955         KisConfig cfg;
01956         m_paletteManager->slotResetFont();
01957         resetMonitorProfile();
01958 
01959 #ifdef HAVE_GL
01960         if (cfg.useOpenGL() != canvasWasOpenGL) {
01961 
01962             disconnectCurrentImg();
01963 
01964             //XXX: Need to notify other views that this global setting has changed.
01965             if (cfg.useOpenGL()) {
01966                 m_OpenGLImageContext = KisOpenGLImageContext::getImageContext(m_image, monitorProfile());
01967                 m_canvas->createOpenGLCanvas(m_OpenGLImageContext->sharedContextWidget());
01968             } else
01969             {
01970                 m_OpenGLImageContext = 0;
01971                 m_canvas->createQPaintDeviceCanvas();
01972             }
01973 
01974             connectCurrentImg();
01975 
01976             resizeEvent(0);
01977         }
01978 
01979         if (cfg.useOpenGL()) {
01980             m_OpenGLImageContext->setMonitorProfile(monitorProfile());
01981         }
01982 #endif
01983 
01984         refreshKisCanvas();
01985 
01986         if (m_toolManager->currentTool()) {
01987             setCanvasCursor(m_toolManager->currentTool()->cursor());
01988         }
01989 
01990 #if defined(EXTENDED_X11_TABLET_SUPPORT)
01991         m_canvas->selectTabletDeviceEvents();
01992 #endif
01993 
01994     }
01995 }
01996 
01997 void KisView::layerCompositeOp(const KisCompositeOp& compositeOp)
01998 {
01999     KisImageSP img = currentImg();
02000     if (!img) return;
02001 
02002     KisLayerSP layer = img->activeLayer();
02003     if (!layer) return;
02004 
02005     if (img->undo()) {
02006         KNamedCommand *cmd = layer->setCompositeOpCommand(compositeOp);
02007         cmd->execute();
02008         undoAdapter()->addCommand(cmd);
02009     }
02010 }
02011 
02012 // range: 0 - 100
02013 void KisView::layerOpacity(int opacity, bool dontundo)
02014 {
02015     KisImageSP img = currentImg();
02016     if (!img) return;
02017 
02018     KisLayerSP layer = img->activeLayer();
02019     if (!layer) return;
02020 
02021     opacity = int(float(opacity * 255) / 100 + 0.5);
02022     if (opacity > 255)
02023         opacity = 255;
02024 
02025     if (opacity == layer->opacity()) return;
02026 
02027     if (dontundo)
02028         layer->setOpacity( opacity );
02029     else
02030     {
02031         if (img->undo()) {
02032             KNamedCommand *cmd = layer->setOpacityCommand(opacity);
02033             cmd->execute();
02034             undoAdapter()->addCommand(cmd);
02035         }
02036     }
02037 }
02038 
02039 void KisView::layerOpacityFinishedChanging( int previous, int opacity )
02040 {
02041     KisImageSP img = currentImg();
02042     if (!img) return;
02043 
02044     KisLayerSP layer = img->activeLayer();
02045     if (!layer) return;
02046 
02047     opacity = int(float(opacity * 255) / 100 + 0.5);
02048     if (opacity > 255)
02049         opacity = 255;
02050 
02051     previous = int(float(previous * 255) / 100 + 0.5);
02052     if (previous > 255)
02053         previous = 255;
02054 
02055     if (previous == opacity) return;
02056 
02057     if (img->undo()) {
02058         KNamedCommand *cmd = layer->setOpacityCommand(previous, opacity);
02059         m_adapter->addCommand(cmd);
02060     }
02061 }
02062 
02063 
02064 void KisView::showRuler()
02065 {
02066     if( m_RulerAction->isChecked() )
02067     {
02068         m_hRuler->show();
02069         m_vRuler->show();
02070     }
02071     else
02072     {
02073         m_hRuler->hide();
02074         m_vRuler->hide();
02075     }
02076 
02077     resizeEvent(0);
02078     refreshKisCanvas();
02079 }
02080 
02081 void KisView::slotUpdateFullScreen(bool toggle)
02082 {
02083     if (KoView::shell()) {
02084 
02085         uint newState = KoView::shell()->windowState();
02086 
02087         if (toggle) {
02088             newState |= Qt::WindowFullScreen;
02089         } else {
02090             newState &= ~Qt::WindowFullScreen;
02091         }
02092 
02093         KoView::shell()->setWindowState(newState);
02094     }
02095 }
02096 
02097 Q_INT32 KisView::docWidth() const
02098 {
02099     return currentImg() ? currentImg()->width() : 0;
02100 }
02101 
02102 Q_INT32 KisView::docHeight() const
02103 {
02104     return currentImg() ? currentImg()->height() : 0;
02105 }
02106 
02107 void KisView::scrollTo(Q_INT32 x, Q_INT32 y)
02108 {
02109     if (m_hScroll->isVisible()) {
02110         m_hScroll->setValue(x);
02111     }
02112     if (m_vScroll->isVisible()) {
02113         m_vScroll->setValue(y);
02114     }
02115 }
02116 
02117 void KisView::brushActivated(KisResource *brush)
02118 {
02119 
02120     m_brush = dynamic_cast<KisBrush*>(brush);
02121 
02122     if (m_brush )
02123     {
02124         emit brushChanged(m_brush);
02125         notifyObservers();
02126     }
02127 }
02128 
02129 void KisView::patternActivated(KisResource *pattern)
02130 {
02131     m_pattern = dynamic_cast<KisPattern*>(pattern);
02132 
02133     if (m_pattern) {
02134         emit patternChanged(m_pattern);
02135         notifyObservers();
02136     }
02137 }
02138 
02139 void KisView::gradientActivated(KisResource *gradient)
02140 {
02141 
02142     m_gradient = dynamic_cast<KisGradient*>(gradient);
02143 
02144     if (m_gradient) {
02145         emit gradientChanged(m_gradient);
02146         notifyObservers();
02147     }
02148 }
02149 
02150 void KisView::paintopActivated(const KisID & paintop, const KisPaintOpSettings *paintopSettings)
02151 {
02152     if (paintop.id().isNull() || paintop.id().isEmpty()) {
02153         return;
02154     }
02155 
02156     m_paintop = paintop;
02157     m_paintopSettings = paintopSettings;
02158     emit paintopChanged(m_paintop, paintopSettings);
02159     notifyObservers();
02160 }
02161 
02162 void KisView::setBGColor(const KisColor& c)
02163 {
02164     m_bg = c;
02165     notifyObservers();
02166     emit sigBGQColorChanged( c.toQColor() );
02167 }
02168 
02169 void KisView::setFGColor(const KisColor& c)
02170 {
02171     m_fg = c;
02172     notifyObservers();
02173     emit sigFGQColorChanged( c.toQColor() );
02174 }
02175 
02176 void KisView::slotSetFGColor(const KisColor& c)
02177 {
02178 
02179     m_fg = c;
02180     notifyObservers();
02181 }
02182 
02183 void KisView::slotSetBGColor(const KisColor& c)
02184 {
02185 
02186     m_bg = c;
02187     notifyObservers();
02188 }
02189 
02190 void KisView::slotSetFGQColor(const QColor& c)
02191 {
02192     KisColorSpace * monitorSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA"), m_monitorProfile);
02193     setFGColor(KisColor(c, monitorSpace));
02194     emit sigFGQColorChanged(c);
02195 }
02196 
02197 void KisView::slotSetBGQColor(const QColor& c)
02198 {
02199     KisColorSpace * monitorSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA"), m_monitorProfile);
02200     setBGColor(KisColor(c, monitorSpace));
02201     emit sigBGQColorChanged(c);
02202 }
02203 
02204 
02205 void KisView::setupPrinter(KPrinter& printer)
02206 {
02207     KisImageSP img = currentImg();
02208 
02209     if (img) {
02210         printer.setPageSelection(KPrinter::ApplicationSide);
02211         printer.setPageSize(KPrinter::A4);
02212         printer.setOrientation(KPrinter::Portrait);
02213     }
02214 }
02215 
02216 void KisView::print(KPrinter& printer)
02217 {
02218     QPainter gc(&printer);
02219 
02220     KisImageSP img = currentImg();
02221     if (!img) return;
02222 
02223     printer.setFullPage(true);
02224     gc.setClipping(false);
02225 
02226     KisConfig cfg;
02227     QString printerProfileName = cfg.printerProfile();
02228     KisProfile *  printerProfile = KisMetaRegistry::instance()->csRegistry() ->getProfileByName(printerProfileName);
02229 
02230     QRect r = img->bounds();
02231     img->renderToPainter(r.x(), r.y(), r.width(), r.height(), gc, printerProfile, KisImage::PAINT_IMAGE_ONLY, HDRExposure());
02232 }
02233 
02234 void KisView::paintToolOverlay(const QRegion& region)
02235 {
02236     if (!region.isEmpty() && m_toolManager->currentTool() && !m_toolIsPainting) {
02237         KisCanvasPainter gc(m_canvas);
02238 
02239         gc.setClipRegion(region);
02240         gc.setClipping(true);
02241 
02242         // Prevent endless loop if the tool needs to have the canvas repainted
02243         m_toolIsPainting = true;
02244         m_toolManager->currentTool()->paint(gc, region.boundingRect());
02245         m_toolIsPainting = false;
02246     }
02247 }
02248 
02249 void KisView::canvasGotPaintEvent(QPaintEvent *event)
02250 {
02251     if (m_canvas->isOpenGLCanvas()) {
02252         paintOpenGLView(event->rect());
02253     } else {
02254         paintQPaintDeviceView(event->region());
02255     }
02256 }
02257 
02258 void KisView::canvasGotButtonPressEvent(KisButtonPressEvent *e)
02259 {
02260 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02261     // The event filter doesn't see tablet events going to the canvas.
02262     if (e->device() != KisInputDevice::mouse()) {
02263         m_tabletEventTimer.start();
02264     }
02265 #endif // EXTENDED_X11_TABLET_SUPPORT
02266 
02267     if (e->device() != currentInputDevice()) {
02268         if (e->device() == KisInputDevice::mouse()) {
02269             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02270                 setInputDevice(KisInputDevice::mouse());
02271             }
02272         } else {
02273             setInputDevice(e->device());
02274         }
02275     }
02276 
02277     KisImageSP img = currentImg();
02278 
02279 //    if (img) {
02280 //        QPoint pt = mapToScreen(e->pos().floorQPoint());
02281 //        KisGuideMgr *mgr = img->guides();
02282 //
02283 //        m_lastGuidePoint = mapToScreen(e->pos().floorQPoint());
02284 //        m_currentGuide = 0;
02285 //
02286 //        if ((e->state() & ~Qt::ShiftButton) == Qt::NoButton) {
02287 //            KisGuideSP gd = mgr->find(static_cast<Q_INT32>(pt.x() / zoom()), static_cast<Q_INT32>(pt.y() / zoom()), QMAX(2.0, 2.0 / zoom()));
02288 //
02289 //            if (gd) {
02290 //                m_currentGuide = gd;
02291 //
02292 //                if ((e->button() == Qt::RightButton) || ((e->button() & Qt::ShiftButton) == Qt::ShiftButton)) {
02293 //                    if (gd->isSelected())
02294 //                        mgr->unselect(gd);
02295 //                    else
02296 //                        mgr->select(gd);
02297 //              } else {
02298 //                    if (!gd->isSelected()) {
02299 //                        mgr->unselectAll();
02300 //                        mgr->select(gd);
02301 //                    }
02302 //                }
02303 //
02304 //                updateGuides();
02305 //                return;
02306 //            }
02307 //        }
02308 //    }
02309     if (e->button() == Qt::RightButton) {
02310 
02311         if (m_popup == 0 && factory()) {
02312             Q_ASSERT(factory());
02313             m_popup = (QPopupMenu *)factory()->container("image_popup", this);
02314         }
02315         if (m_popup) m_popup->popup(e->globalPos().roundQPoint());
02316     }
02317     else if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02318         KisPoint p = viewToWindow(e->pos());
02319         // somewhat of a hack: we should actually test if we intersect with the scrollers,
02320         // but the globalPos seems to be off by a few pixels
02321         if (m_vScroll->draggingSlider() || m_hScroll->draggingSlider())
02322             return;
02323 
02324         if (m_toolManager->currentTool()->wantsAutoScroll()) {
02325             enableAutoScroll();
02326         }
02327 
02328         KisButtonPressEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
02329         m_toolManager->currentTool()->buttonPress(&ev);
02330     }
02331 }
02332 
02333 void KisView::canvasGotMoveEvent(KisMoveEvent *e)
02334 {
02335 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02336     // The event filter doesn't see tablet events going to the canvas.
02337     if (e->device() != KisInputDevice::mouse()) {
02338         m_tabletEventTimer.start();
02339     }
02340 #endif // EXTENDED_X11_TABLET_SUPPORT
02341 
02342     if (e->device() != currentInputDevice()) {
02343         if (e->device() == KisInputDevice::mouse()) {
02344             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02345                 setInputDevice(KisInputDevice::mouse());
02346             }
02347         } else {
02348             setInputDevice(e->device());
02349         }
02350     }
02351 
02352     KisImageSP img = currentImg();
02353 
02354     m_hRuler->updatePointer(e->pos().floorX() - m_canvasXOffset, e->pos().floorY() - m_canvasYOffset);
02355     m_vRuler->updatePointer(e->pos().floorX() - m_canvasXOffset, e->pos().floorY() - m_canvasYOffset);
02356 
02357     KisPoint wp = viewToWindow(e->pos());
02358 
02359 #if 0
02360     if (img && m_currentGuide) {
02361         QPoint p = mapToScreen(e->pos().floorQPoint());
02362         KisGuideMgr *mgr = img->guides();
02363 
02364         if (((e->state() & Qt::LeftButton) == Qt::LeftButton) && mgr->hasSelected()) {
02365             eraseGuides();
02366             p -= m_lastGuidePoint;
02367 
02368             if (p.x())
02369                 mgr->moveSelectedByX(p.x() / zoom());
02370 
02371             if (p.y())
02372                 mgr->moveSelectedByY(p.y() / zoom());
02373 
02374             m_doc->setModified(true);
02375             paintGuides();
02376         }
02377     } else
02378 #endif
02379     if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02380         KisMoveEvent ev(e->device(), wp, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->state());
02381 
02382         m_toolManager->currentTool()->move(&ev);
02383     }
02384 
02385 //    m_lastGuidePoint = mapToScreen(e->pos().floorQPoint());
02386     emit cursorPosition(wp.floorX(), wp.floorY());
02387 }
02388 
02389 int KisView::leftBorder() const
02390 {
02391   return m_rulerThickness;
02392 }
02393 
02394 int KisView::rightBorder() const
02395 {
02396   return m_hScrollBarExtent;
02397 }
02398 
02399 int KisView::topBorder() const
02400 {
02401   return m_rulerThickness;
02402 }
02403 
02404 int KisView::bottomBorder() const
02405 {
02406   return m_vScrollBarExtent;
02407 }
02408 
02409 void KisView::mouseMoveEvent(QMouseEvent *e)
02410 {
02411     KisMoveEvent ke(currentInputDevice(), e->pos(), e->globalPos(), PRESSURE_DEFAULT, 0, 0, e->state());
02412     canvasGotMoveEvent(&ke);
02413 }
02414 
02415 void KisView::slotAutoScroll(const QPoint &p)
02416 {
02417     scrollTo(horzValue()+p.x(), vertValue()+p.y());
02418 }
02419 
02420 void KisView::canvasGotButtonReleaseEvent(KisButtonReleaseEvent *e)
02421 {
02422 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02423     // The event filter doesn't see tablet events going to the canvas.
02424     if (e->device() != KisInputDevice::mouse()) {
02425         m_tabletEventTimer.start();
02426     }
02427 #endif // EXTENDED_X11_TABLET_SUPPORT
02428 
02429     if (e->device() != currentInputDevice()) {
02430         if (e->device() == KisInputDevice::mouse()) {
02431             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02432                 setInputDevice(KisInputDevice::mouse());
02433             }
02434         } else {
02435             setInputDevice(e->device());
02436         }
02437     }
02438 
02439     KisImageSP img = currentImg();
02440 
02441 //    if (img && m_currentGuide) {
02442 //        m_currentGuide = 0;
02443 //    } else
02444     if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02445         KisPoint p = viewToWindow(e->pos());
02446         KisButtonReleaseEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
02447 
02448         disableAutoScroll();
02449         if (m_toolManager->currentTool()) {
02450             m_toolManager->currentTool()->buttonRelease(&ev);
02451         }
02452     }
02453 }
02454 
02455 void KisView::canvasGotDoubleClickEvent(KisDoubleClickEvent *e)
02456 {
02457 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02458     // The event filter doesn't see tablet events going to the canvas.
02459     if (e->device() != KisInputDevice::mouse()) {
02460         m_tabletEventTimer.start();
02461     }
02462 #endif // EXTENDED_X11_TABLET_SUPPORT
02463 
02464     if (e->device() != currentInputDevice()) {
02465         if (e->device() == KisInputDevice::mouse()) {
02466             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02467                 setInputDevice(KisInputDevice::mouse());
02468             }
02469         } else {
02470             setInputDevice(e->device());
02471         }
02472     }
02473 
02474     if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02475         KisPoint p = viewToWindow(e->pos());
02476         KisDoubleClickEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
02477 
02478         if (m_toolManager->currentTool()) {
02479             m_toolManager->currentTool()->doubleClick(&ev);
02480         }
02481     }
02482 }
02483 
02484 void KisView::canvasGotEnterEvent(QEvent *e)
02485 {
02486     if (m_toolManager->currentTool())
02487         m_toolManager->currentTool()->enter(e);
02488 }
02489 
02490 void KisView::canvasGotLeaveEvent (QEvent *e)
02491 {
02492     if (m_toolManager->currentTool())
02493         m_toolManager->currentTool()->leave(e);
02494 }
02495 
02496 void KisView::canvasGotMouseWheelEvent(QWheelEvent *event)
02497 {
02498     //if(event->state() == ControlButton )
02499     //{
02500         if(event->delta() / 120 != 0)
02501         {
02502             if(event->delta() > 0)
02503             {
02504                 zoomIn();
02505             } else {
02506                 zoomOut();
02507             }
02508         }
02509     //} else {
02510     //    QApplication::sendEvent(m_vScroll, event);
02511     //}
02512 }
02513 
02514 void KisView::canvasGotKeyPressEvent(QKeyEvent *event)
02515 {
02516     if (!m_toolManager->currentTool()) {
02517         event->ignore();
02518         return;
02519     }
02520 
02521     if (event->key() == Qt::Key_Space) {
02522         if (!m_panning) {
02523             // Set tool temporarily to pan
02524             m_panning = true;
02525             m_oldTool = m_toolManager->currentTool();
02526             m_toolManager->setCurrentTool( "tool_pan" );
02527         }
02528         else {
02529             // Unset panning
02530             m_panning = false;
02531             m_toolManager->setCurrentTool( m_oldTool );
02532             m_oldTool = 0;
02533         }
02534     }
02535     if (m_toolManager->currentTool())
02536         m_toolManager->currentTool()->keyPress(event);
02537 }
02538 
02539 void KisView::canvasGotKeyReleaseEvent(QKeyEvent *event)
02540 {
02541     if (m_toolManager->currentTool())
02542         m_toolManager->currentTool()->keyRelease(event);
02543 }
02544 
02545 void KisView::canvasGotDragEnterEvent(QDragEnterEvent *event)
02546 {
02547     bool accept = false;
02548 
02549     // Only accept drag if we're not busy, particularly as we may
02550     // be showing a progress bar and calling qApp->processEvents().
02551     if (KURLDrag::canDecode(event) && QApplication::overrideCursor() == 0) {
02552         accept = true;
02553     }
02554 
02555     event->accept(accept);
02556 }
02557 
02558 void KisView::canvasGotDropEvent(QDropEvent *event)
02559 {
02560     KURL::List urls;
02561 
02562     if (KURLDrag::decode(event, urls))
02563     {
02564         if (urls.count() > 0) {
02565             enum enumActionId {
02566                 addLayerId = 1,
02567                 addDocumentId = 2,
02568                 cancelId
02569             };
02570 
02571             KPopupMenu popup(this, "drop_popup");
02572 
02573             if (urls.count() == 1) {
02574                 if (currentImg() != 0) {
02575                     popup.insertItem(i18n("Insert as New Layer"), addLayerId);
02576                 }
02577                 popup.insertItem(i18n("Open in New Document"), addDocumentId);
02578             }
02579             else {
02580                 if (currentImg() != 0) {
02581                     popup.insertItem(i18n("Insert as New Layers"), addLayerId);
02582                 }
02583                 popup.insertItem(i18n("Open in New Documents"), addDocumentId);
02584             }
02585 
02586             popup.insertSeparator();
02587             popup.insertItem(i18n("Cancel"), cancelId);
02588 
02589             int actionId = popup.exec(QCursor::pos());
02590 
02591             if (actionId >= 0 && actionId != cancelId) {
02592                 for (KURL::List::ConstIterator it = urls.begin (); it != urls.end (); ++it) {
02593                     KURL url = *it;
02594 
02595                     switch (actionId) {
02596                     case addLayerId:
02597                         importImage(url);
02598                         break;
02599                     case addDocumentId:
02600                         if (shell() != 0) {
02601                             shell()->openDocument(url);
02602                         }
02603                         break;
02604                     }
02605                 }
02606             }
02607         }
02608     }
02609 }
02610 
02611 void KisView::layerProperties()
02612 {
02613     if (currentImg() && currentImg()->activeLayer())
02614         showLayerProperties(currentImg()->activeLayer());
02615 }
02616 
02617 void KisView::showLayerProperties(KisLayerSP layer)
02618 {
02619     Q_ASSERT( layer );
02620     if ( !layer ) return;
02621 
02622     KisColorSpace * cs = 0;
02623     KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>( layer.data() );
02624     if ( pl ) {
02625         cs = pl->paintDevice()->colorSpace();
02626     }
02627     else {
02628         cs = layer->image()->colorSpace();
02629     }
02630 
02631 
02632     if (KisAdjustmentLayerSP alayer = dynamic_cast<KisAdjustmentLayer*>(layer.data()))
02633     {
02634         KisDlgAdjLayerProps dlg(alayer, alayer->name(), i18n("Adjustment Layer Properties"), this, "dlgadjlayerprops");
02635         if (dlg.exec() == QDialog::Accepted)
02636         {
02637             QApplication::setOverrideCursor(KisCursor::waitCursor());
02638             alayer->setFilter( dlg.filterConfiguration() );
02639             alayer->setDirty();
02640             QApplication::restoreOverrideCursor();
02641             m_doc->setModified( true );
02642         }
02643     }
02644     else
02645     {
02646         KisDlgLayerProperties dlg(layer->name(),
02647                                   layer->opacity(),
02648                                   layer->compositeOp(),
02649                                   cs);
02650         if (dlg.exec() == QDialog::Accepted)
02651         {
02652             if (layer->name() != dlg.getName() ||
02653                 layer->opacity() != dlg.getOpacity() ||
02654                 layer->compositeOp() != dlg.getCompositeOp())
02655             {
02656                 QApplication::setOverrideCursor(KisCursor::waitCursor());
02657                 m_adapter->beginMacro(i18n("Property Changes"));
02658                 layer->image()->setLayerProperties(layer, dlg.getOpacity(), dlg.getCompositeOp(), dlg.getName());
02659                 layer->setDirty();
02660                 m_adapter->endMacro();
02661                 QApplication::restoreOverrideCursor();
02662                 m_doc->setModified( true );
02663             }
02664         }
02665     }
02666 }
02667 
02668 void KisView::layerAdd()
02669 {
02670     KisImageSP img = currentImg();
02671     if (img && img->activeLayer()) {
02672         addLayer(img->activeLayer()->parent(), img->activeLayer());
02673     }
02674     else if (img)
02675         addLayer(static_cast<KisGroupLayer*>(img->rootLayer().data()), 0);
02676 }
02677 
02678 void KisView::addLayer(KisGroupLayerSP parent, KisLayerSP above)
02679 {
02680     KisImageSP img = currentImg();
02681     if (img) {
02682         KisConfig cfg;
02683         QString profilename;
02684         if(img->colorSpace()->getProfile())
02685             profilename = img->colorSpace()->getProfile()->productName();
02686         NewLayerDialog dlg(img->colorSpace()->id(), profilename, img->nextLayerName(), this);
02687 
02688         if (dlg.exec() == QDialog::Accepted) {
02689             KisColorSpace* cs = KisMetaRegistry::instance()-> csRegistry() ->
02690                     getColorSpace(dlg.colorSpaceID(),dlg.profileName());
02691             KisLayerSP layer = new KisPaintLayer(img, dlg.layerName(), dlg.opacity(), cs);
02692             if (layer) {
02693                 layer->setCompositeOp(dlg.compositeOp());
02694                 img->addLayer(layer, parent.data(), above);
02695                 updateCanvas();
02696             } else {
02697                 KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
02698             }
02699         }
02700         else {
02701             img->rollBackLayerName();
02702         }
02703     }
02704 }
02705 
02706 void KisView::addGroupLayer(KisGroupLayerSP parent, KisLayerSP above)
02707 {
02708     KisImageSP img = currentImg();
02709     if (img) {
02710         QString profilename;
02711         if(img->colorSpace()->getProfile())
02712             profilename = img->colorSpace()->getProfile()->productName();
02713         KisConfig cfg;
02714         NewLayerDialog dlg(img->colorSpace()->id(), profilename, img->nextLayerName(), this);
02715         dlg.setColorSpaceEnabled(false);
02716 
02717         if (dlg.exec() == QDialog::Accepted) {
02718             KisLayerSP layer = new KisGroupLayer(img, dlg.layerName(), dlg.opacity());
02719             if (layer) {
02720                 layer->setCompositeOp(dlg.compositeOp());
02721                 img->addLayer(layer, parent.data(), above);
02722                 updateCanvas();
02723             } else {
02724                 KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
02725             }
02726         }
02727     }
02728 }
02729 
02730 void KisView::addPartLayer()
02731 {
02732     KisImageSP img = currentImg();
02733     if (!img) return;
02734 
02735     addPartLayer(img->rootLayer(), img->rootLayer()->firstChild(), m_actionPartLayer->documentEntry());
02736 }
02737 
02738 void KisView::addPartLayer(KisGroupLayerSP parent, KisLayerSP above, const KoDocumentEntry& entry)
02739 {
02740     delete m_partHandler; // Only one at a time
02741     m_partHandler = new KisPartLayerHandler(this, entry, parent, above);
02742 
02743     disconnect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)), this, 0);
02744     disconnect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)), this, 0);
02745     disconnect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)), this, 0);
02746     disconnect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)), this, 0);
02747 
02748     connect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)),
02749             m_partHandler, SLOT(gotButtonPressEvent(KisButtonPressEvent*)));
02750     connect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)),
02751             m_partHandler, SLOT(gotButtonReleaseEvent(KisButtonReleaseEvent*)));
02752     connect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
02753             m_partHandler, SLOT(gotMoveEvent(KisMoveEvent*)));
02754     connect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)),
02755             m_partHandler, SLOT(gotKeyPressEvent(QKeyEvent*)));
02756 
02757     connect(m_partHandler, SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
02758             this, SLOT(canvasGotMoveEvent(KisMoveEvent*)));
02759     connect(m_partHandler, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)),
02760             this, SLOT(canvasGotKeyPressEvent(QKeyEvent*)));
02761     connect(m_partHandler, SIGNAL(handlerDone()),
02762             this, SLOT(reconnectAfterPartInsert()));
02763 }
02764 
02765 void KisView::insertPart(const QRect& viewRect, const KoDocumentEntry& entry,
02766                          KisGroupLayerSP parent, KisLayerSP above) {
02767     KisImageSP img = currentImg();
02768     if (!img) return;
02769 
02770     KoDocument* doc = entry.createDoc(m_doc);
02771     if ( !doc )
02772         return;
02773 
02774     if ( !doc->showEmbedInitDialog(this) )
02775         return;
02776 
02777     QRect rect = viewToWindow(viewRect);
02778 
02779     KisChildDoc * childDoc = m_doc->createChildDoc(rect, doc);
02780 
02781     KisPartLayerImpl* partLayer = new KisPartLayerImpl(img, childDoc);
02782     partLayer->setDocType(entry.service()->genericName());
02783     img->addLayer(partLayer, parent, above);
02784     m_doc->setModified(true);
02785 
02786     reconnectAfterPartInsert();
02787 }
02788 
02789 void KisView::reconnectAfterPartInsert() {
02790     connect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)),
02791             this, SLOT(canvasGotButtonPressEvent(KisButtonPressEvent*)));
02792     connect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)),
02793             this, SLOT(canvasGotButtonReleaseEvent(KisButtonReleaseEvent*)));
02794     connect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
02795             this, SLOT(canvasGotMoveEvent(KisMoveEvent*)));
02796     connect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)),
02797             this, SLOT(canvasGotKeyPressEvent(QKeyEvent*)));
02798 
02799     delete m_partHandler;
02800     m_partHandler = 0;
02801 }
02802 
02803 void KisView::addAdjustmentLayer()
02804 {
02805     KisImageSP img = currentImg();
02806     if (!img) return;
02807 
02808     addAdjustmentLayer( img->activeLayer()->parent(), img->activeLayer() );
02809 }
02810 
02811 void KisView::addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above)
02812 {
02813     Q_ASSERT(parent);
02814     Q_ASSERT(above);
02815 
02816     KisImageSP img = currentImg();
02817     if (!img) return;
02818 
02819     KisLayerSP l = img->activeLayer();
02820 
02821     KisPaintDeviceSP dev;
02822 
02823     //  Argh! I hate having to cast, cast and cast again to see what kind of a layer I've got!
02824     KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(l.data());
02825     if (pl) {
02826         dev = pl->paintDevice();
02827     }
02828     else {
02829         KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(l.data());
02830         if (gl) {
02831             dev = gl->projection(img->bounds());
02832         }
02833         else {
02834             KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(l.data());
02835             if (al) {
02836                 dev = al->cachedPaintDevice();
02837             }
02838             else {
02839                 return;
02840             }
02841         }
02842     }
02843 
02844     KisDlgAdjustmentLayer dlg(img, img->nextLayerName(), i18n("New Adjustment Layer"), this, "dlgadjustmentlayer");
02845     if (dlg.exec() == QDialog::Accepted) {
02846         KisSelectionSP selection = 0;
02847         if (dev->hasSelection()) {
02848             selection = dev->selection();
02849         }
02850         KisFilterConfiguration * filter = dlg.filterConfiguration();
02851         QString name = dlg.layerName();
02852 
02853         addAdjustmentLayer( parent, above, name, filter, selection);
02854 
02855     }
02856 }
02857 
02858 void KisView::addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above, const QString & name,
02859                                  KisFilterConfiguration * filter, KisSelectionSP selection)
02860 {
02861     Q_ASSERT(parent);
02862     Q_ASSERT(above);
02863     Q_ASSERT(filter);
02864 
02865     KisImageSP img = currentImg();
02866     if (!img) return;
02867 
02868     KisAdjustmentLayer * l = new KisAdjustmentLayer(img, name, filter, selection);
02869     img->addLayer(l, parent, above);
02870 }
02871 
02872 void KisView::slotChildActivated(bool a) {
02873     // It should be so that the only part (child) we can activate, is the current layer:
02874     if (currentImg() && currentImg()->activeLayer())
02875     {
02876         if (a) {
02877             currentImg()->activeLayer()->activate();
02878         } else {
02879             currentImg()->activeLayer()->deactivate();
02880         }
02881     }
02882 
02883     super::slotChildActivated(a);
02884 }
02885 
02886 void KisView::layerRemove()
02887 {
02888     KisImageSP img = currentImg();
02889 
02890     if (img) {
02891         KisLayerSP layer = img->activeLayer();
02892 
02893         if (layer) {
02894 
02895 
02896             img->removeLayer(layer);
02897 
02898             if (layer->parent())
02899                 layer->parent()->setDirty(layer->extent());
02900 
02901             updateCanvas();
02902             layerUpdateGUI(img->activeLayer() != 0);
02903         }
02904     }
02905 }
02906 
02907 void KisView::layerDuplicate()
02908 {
02909     KisImageSP img = currentImg();
02910 
02911     if (!img)
02912         return;
02913 
02914     KisLayerSP active = img->activeLayer();
02915 
02916     if (!active)
02917         return;
02918 
02919     KisLayerSP dup = active->clone();
02920     dup->setName(QString(i18n("Duplicate of '%1'")).arg(active->name()));
02921     img->addLayer(dup, active->parent().data(), active);
02922     if (dup) {
02923         img->activate( dup );
02924         updateCanvas();
02925     } else {
02926         KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
02927     }
02928 }
02929 
02930 void KisView::layerRaise()
02931 {
02932     KisImageSP img = currentImg();
02933     KisLayerSP layer;
02934 
02935     if (!img)
02936         return;
02937 
02938     layer = img->activeLayer();
02939 
02940     img->raiseLayer(layer);
02941 }
02942 
02943 void KisView::layerLower()
02944 {
02945     KisImageSP img = currentImg();
02946     KisLayerSP layer;
02947 
02948     if (!img)
02949         return;
02950 
02951     layer = img->activeLayer();
02952 
02953     img->lowerLayer(layer);
02954 }
02955 
02956 void KisView::layerFront()
02957 {
02958     KisImageSP img = currentImg();
02959     KisLayerSP layer;
02960 
02961     if (!img)
02962         return;
02963 
02964     layer = img->activeLayer();
02965     img->toTop(layer);
02966 }
02967 
02968 void KisView::layerBack()
02969 {
02970     KisImageSP img = currentImg();
02971     if (!img) return;
02972 
02973     KisLayerSP layer;
02974 
02975     layer = img->activeLayer();
02976     img->toBottom(layer);
02977 }
02978 
02979 void KisView::layersUpdated()
02980 {
02981     KisImageSP img = currentImg();
02982     if (!img) return;
02983 
02984     KisLayerSP layer = img->activeLayer();
02985 
02986     layerUpdateGUI(img && layer);
02987 
02988     notifyObservers();
02989 }
02990 
02991 void KisView::layerToggleVisible()
02992 {
02993     KisImageSP img = currentImg();
02994     if (!img) return;
02995 
02996     KisLayerSP layer = img->activeLayer();
02997     if (!layer) return;
02998 
02999     layer->setVisible(!layer->visible());
03000 }
03001 
03002 void KisView::layerToggleLocked()
03003 {
03004     KisImageSP img = currentImg();
03005     if (!img) return;
03006 
03007     KisLayerSP layer = img->activeLayer();
03008     if (!layer) return;
03009 
03010     layer->setLocked(!layer->locked());
03011 }
03012 
03013 void KisView::actLayerVisChanged(int show)
03014 {
03015     m_actLayerVis = (show != 0);
03016 }
03017 
03018 bool KisView::activeLayerHasSelection()
03019 {
03020     return m_image && m_image->activeDevice() && m_image->activeDevice()->hasSelection();
03021 }
03022 
03023 void KisView::scrollH(int value)
03024 {
03025     m_hRuler->updateVisibleArea(value, 0);
03026 
03027     int xShift = m_scrollX - value;
03028     m_scrollX = value;
03029 
03030     if (m_canvas->isUpdatesEnabled()) {
03031         if (xShift > 0) {
03032 
03033             if (m_canvas->isOpenGLCanvas()) {
03034                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03035             } else {
03036                 QRect drawRect(0, 0, xShift, m_canvasPixmap.height());
03037 
03038                 bitBlt(&m_canvasPixmap, xShift, 0, &m_canvasPixmap, 0, 0, m_canvasPixmap.width() - xShift, m_canvasPixmap.height());
03039 
03040                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03041                 m_canvas->repaint();
03042             }
03043         } else if (xShift < 0) {
03044 
03045             QRect drawRect(m_canvasPixmap.width() + xShift, 0, -xShift, m_canvasPixmap.height());
03046 
03047             if (m_canvas->isOpenGLCanvas()) {
03048                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03049             } else {
03050                 bitBlt(&m_canvasPixmap, 0, 0, &m_canvasPixmap, -xShift, 0, m_canvasPixmap.width() + xShift, m_canvasPixmap.height());
03051 
03052                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03053                 m_canvas->repaint();
03054             }
03055         }
03056     }
03057 
03058     if (xShift != 0) {
03059         // XXX do sth with the childframe or so
03060     }
03061     emit viewTransformationsChanged();
03062 }
03063 
03064 void KisView::scrollV(int value)
03065 {
03066     m_vRuler->updateVisibleArea(0, value);
03067 
03068     int yShift = m_scrollY - value;
03069     m_scrollY = value;
03070 
03071     if (m_canvas->isUpdatesEnabled()) {
03072         if (yShift > 0) {
03073 
03074             if (m_canvas->isOpenGLCanvas()) {
03075                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03076             } else {
03077                 QRect drawRect(0, 0, m_canvasPixmap.width(), yShift);
03078 
03079                 bitBlt(&m_canvasPixmap, 0, yShift, &m_canvasPixmap, 0, 0, m_canvasPixmap.width(), m_canvasPixmap.height() - yShift);
03080 
03081                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03082                 m_canvas->repaint();
03083             }
03084         } else if (yShift < 0) {
03085 
03086             if (m_canvas->isOpenGLCanvas()) {
03087                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03088             } else {
03089                 QRect drawRect(0, m_canvasPixmap.height() + yShift, m_canvasPixmap.width(), -yShift);
03090 
03091                 bitBlt(&m_canvasPixmap, 0, 0, &m_canvasPixmap, 0, -yShift, m_canvasPixmap.width(), m_canvasPixmap.height() + yShift);
03092 
03093                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03094                 m_canvas->repaint();
03095             }
03096         }
03097     }
03098 
03099     if (yShift != 0) {
03100         // XXX do sth with the childframe or so
03101     }
03102     emit viewTransformationsChanged();
03103 }
03104 
03105 void KisView::setupCanvas()
03106 {
03107     m_canvas = new KisCanvas(this, "kis_canvas");
03108     m_canvas->setFocusPolicy( QWidget::StrongFocus );
03109     QObject::connect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)), this, SLOT(canvasGotButtonPressEvent(KisButtonPressEvent*)));
03110     QObject::connect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)), this, SLOT(canvasGotButtonReleaseEvent(KisButtonReleaseEvent*)));
03111     QObject::connect(m_canvas, SIGNAL(sigGotDoubleClickEvent(KisDoubleClickEvent*)), this, SLOT(canvasGotDoubleClickEvent(KisDoubleClickEvent*)));
03112     QObject::connect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)), this, SLOT(canvasGotMoveEvent(KisMoveEvent*)));
03113     QObject::connect(m_canvas, SIGNAL(sigGotPaintEvent(QPaintEvent*)), this, SLOT(canvasGotPaintEvent(QPaintEvent*)));
03114     QObject::connect(m_canvas, SIGNAL(sigGotEnterEvent(QEvent*)), this, SLOT(canvasGotEnterEvent(QEvent*)));
03115     QObject::connect(m_canvas, SIGNAL(sigGotLeaveEvent(QEvent*)), this, SLOT(canvasGotLeaveEvent(QEvent*)));
03116     QObject::connect(m_canvas, SIGNAL(sigGotMouseWheelEvent(QWheelEvent*)), this, SLOT(canvasGotMouseWheelEvent(QWheelEvent*)));
03117     QObject::connect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)), this, SLOT(canvasGotKeyPressEvent(QKeyEvent*)));
03118     QObject::connect(m_canvas, SIGNAL(sigGotKeyReleaseEvent(QKeyEvent*)), this, SLOT(canvasGotKeyReleaseEvent(QKeyEvent*)));
03119     QObject::connect(m_canvas, SIGNAL(sigGotDragEnterEvent(QDragEnterEvent*)), this, SLOT(canvasGotDragEnterEvent(QDragEnterEvent*)));
03120     QObject::connect(m_canvas, SIGNAL(sigGotDropEvent(QDropEvent*)), this, SLOT(canvasGotDropEvent(QDropEvent*)));
03121 }
03122 
03123 void KisView::connectCurrentImg()
03124 {
03125     if (m_image) {
03126         connect(m_image, SIGNAL(sigActiveSelectionChanged(KisImageSP)), m_selectionManager, SLOT(imgSelectionChanged(KisImageSP)));
03127         connect(m_image, SIGNAL(sigActiveSelectionChanged(KisImageSP)), this, SLOT(updateCanvas()));
03128         connect(m_image, SIGNAL(sigColorSpaceChanged(KisColorSpace *)), this, SLOT(updateStatusBarProfileLabel()));
03129         connect(m_image, SIGNAL(sigProfileChanged(KisProfile * )), SLOT(profileChanged(KisProfile * )));
03130 
03131         connect(m_image, SIGNAL(sigLayersChanged(KisGroupLayerSP)), SLOT(layersUpdated()));
03132         connect(m_image, SIGNAL(sigLayerAdded(KisLayerSP)), SLOT(layersUpdated()));
03133         connect(m_image, SIGNAL(sigLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), SLOT(layersUpdated()));
03134         connect(m_image, SIGNAL(sigLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), SLOT(layersUpdated()));
03135         connect(m_image, SIGNAL(sigLayerActivated(KisLayerSP)), SLOT(layersUpdated()));
03136         connect(m_image, SIGNAL(sigLayerActivated(KisLayerSP)), SLOT(updateCanvas()));
03137         connect(m_image, SIGNAL(sigLayerPropertiesChanged(KisLayerSP)), SLOT(layersUpdated()));
03138 
03139         KisConnectPartLayerVisitor v(m_image, this, true);
03140         m_image->rootLayer()->accept(v);
03141         connect(m_image, SIGNAL(sigLayerAdded(KisLayerSP)),
03142                 SLOT(handlePartLayerAdded(KisLayerSP)));
03143 
03144 #ifdef HAVE_GL
03145         if (m_OpenGLImageContext != 0) {
03146             connect(m_OpenGLImageContext, SIGNAL(sigImageUpdated(QRect)), SLOT(slotOpenGLImageUpdated(QRect)));
03147             connect(m_OpenGLImageContext, SIGNAL(sigSizeChanged(Q_INT32, Q_INT32)), SLOT(slotImageSizeChanged(Q_INT32, Q_INT32)));
03148         } else
03149 #endif
03150         {
03151             connect(m_image, SIGNAL(sigImageUpdated(QRect)), SLOT(imgUpdated(QRect)));
03152             connect(m_image, SIGNAL(sigSizeChanged(Q_INT32, Q_INT32)), SLOT(slotImageSizeChanged(Q_INT32, Q_INT32)));
03153         }
03154     }
03155 
03156     m_layerBox->setImage(m_image);
03157     m_birdEyeBox->setImage(m_image);
03158 }
03159 
03160 void KisView::disconnectCurrentImg()
03161 {
03162     if (m_image) {
03163         m_image->disconnect(this);
03164         m_layerBox->setImage(0);
03165         m_birdEyeBox->setImage(0);
03166 
03167         KisConnectPartLayerVisitor v(m_image, this, false);
03168         m_image->rootLayer()->accept(v);
03169     }
03170 
03171 #ifdef HAVE_GL
03172     if (m_OpenGLImageContext != 0) {
03173         m_OpenGLImageContext->disconnect(this);
03174     }
03175 #endif
03176 }
03177 
03178 void KisView::handlePartLayerAdded(KisLayerSP layer)
03179 {
03180     KisPartLayer* l = dynamic_cast<KisPartLayer*>(layer.data());
03181     if (!l)
03182         return;
03183 
03184     connect(this, SIGNAL(childActivated(KoDocumentChild*)),
03185             layer, SLOT(childActivated(KoDocumentChild*)));
03186 }
03187 
03188 void KisView::imgUpdated(QRect rc)
03189 {
03190     updateCanvas(rc);
03191 }
03192 
03193 void KisView::slotOpenGLImageUpdated(QRect rc)
03194 {
03195     paintOpenGLView(windowToView(rc));
03196 }
03197 
03198 void KisView::profileChanged(KisProfile *  /*profile*/)
03199 {
03200     updateStatusBarProfileLabel();
03201 }
03202 
03203 void KisView::slotImageSizeChanged(Q_INT32 /*w*/, Q_INT32 /*h*/)
03204 {
03205     resizeEvent(0);
03206     refreshKisCanvas();
03207 }
03208 
03209 void KisView::resizeCurrentImage(Q_INT32 w, Q_INT32 h, bool cropLayers)
03210 {
03211     if (!currentImg()) return;
03212 
03213     currentImg()->resize(w, h, cropLayers);
03214     m_doc->setModified(true);
03215     layersUpdated();
03216 }
03217 
03218 void KisView::scaleCurrentImage(double sx, double sy, KisFilterStrategy *filterStrategy)
03219 {
03220     if (!currentImg()) return;
03221     currentImg()->scale(sx, sy, m_progress, filterStrategy);
03222     m_doc->setModified(true);
03223     layersUpdated();
03224 }
03225 
03226 void KisView::rotateCurrentImage(double angle)
03227 {
03228     if (!currentImg()) return;
03229     currentImg()->rotate(angle, m_progress);
03230     m_doc->setModified(true);
03231     layersUpdated();
03232 }
03233 
03234 void KisView::shearCurrentImage(double angleX, double angleY)
03235 {
03236     if (!currentImg()) return;
03237     currentImg()->shear(angleX, angleY, m_progress);
03238     m_doc->setModified(true);
03239     layersUpdated();
03240 }
03241 
03242 
03243 QPoint KisView::viewToWindow(const QPoint& pt)
03244 {
03245     QPoint converted;
03246 
03247     converted.rx() = static_cast<int>((pt.x() + horzValue()) / zoom());
03248     converted.ry() = static_cast<int>((pt.y() + vertValue()) / zoom());
03249 
03250     return converted;
03251 }
03252 
03253 QPoint KisView::viewToWindow(const QPoint& pt) const
03254 {
03255     QPoint converted;
03256 
03257     converted.rx() = static_cast<int>((pt.x() + horzValue()) / zoom());
03258     converted.ry() = static_cast<int>((pt.y() + vertValue()) / zoom());
03259 
03260     return converted;
03261 }
03262 
03263 KisPoint KisView::viewToWindow(const KisPoint& pt)
03264 {
03265     KisPoint converted;
03266 
03267     converted.setX((pt.x() + horzValue()) / zoom());
03268     converted.setY((pt.y() + vertValue()) / zoom());
03269 
03270     return converted;
03271 }
03272 
03273 QRect KisView::viewToWindow(const QRect& rc)
03274 {
03275     QRect r;
03276 
03277     r.setTopLeft(viewToWindow(rc.topLeft()));
03278     r.setRight((int)(ceil((rc.right() + 1.0 + horzValue()) / zoom()) - 1));
03279     r.setBottom((int)(ceil((rc.bottom() + 1.0 + vertValue()) / zoom()) - 1));
03280 
03281     return r;
03282 }
03283 
03284 KisRect KisView::viewToWindow(const KisRect& rc)
03285 {
03286     KisRect r;
03287     KisPoint p = viewToWindow(KisPoint(rc.x(), rc.y()));
03288     r.setX(p.x());
03289     r.setY(p.y());
03290     r.setWidth(rc.width() / zoom());
03291     r.setHeight(rc.height() / zoom());
03292 
03293     return r;
03294 }
03295 
03296 void KisView::viewToWindow(Q_INT32 *x, Q_INT32 *y)
03297 {
03298     if (x && y) {
03299         QPoint p = viewToWindow(QPoint(*x, *y));
03300         *x = p.x();
03301         *y = p.y();
03302     }
03303 }
03304 
03305 QPoint KisView::windowToView(const QPoint& pt)
03306 {
03307     QPoint p;
03308     p.setX(static_cast<int>(pt.x() * zoom() - horzValue()));
03309     p.setY(static_cast<int>(pt.y() * zoom() - vertValue()));
03310 
03311     return p;
03312 }
03313 
03314 QPoint KisView::windowToView(const QPoint& pt) const
03315 {
03316     QPoint p;
03317     p.setX(static_cast<int>(pt.x() * zoom() - horzValue()));
03318     p.setY(static_cast<int>(pt.y() * zoom() - vertValue()));
03319 
03320     return p;
03321 }
03322 
03323 KisPoint KisView::windowToView(const KisPoint& pt)
03324 {
03325     KisPoint p;
03326     p.setX(pt.x() * zoom() - horzValue());
03327     p.setY(pt.y() * zoom() - vertValue());
03328 
03329     return p;
03330 }
03331 
03332 QRect KisView::windowToView(const QRect& rc)
03333 {
03334     QRect r;
03335 
03336     r.setTopLeft(windowToView(rc.topLeft()));
03337     r.setRight((int)(ceil((rc.right() + 1.0) * zoom()) - horzValue() - 1));
03338     r.setBottom((int)(ceil((rc.bottom() + 1.0) * zoom()) - vertValue() - 1));
03339 
03340     return r;
03341 }
03342 
03343 KisRect KisView::windowToView(const KisRect& rc)
03344 {
03345     KisRect r;
03346     KisPoint p = windowToView(KisPoint(rc.x(), rc.y()));
03347     r.setX(p.x());
03348     r.setY(p.y());
03349     r.setWidth(rc.width() * zoom());
03350     r.setHeight(rc.height() * zoom());
03351 
03352     return r;
03353 }
03354 
03355 void KisView::windowToView(Q_INT32 *x, Q_INT32 *y)
03356 {
03357     if (x && y) {
03358         QPoint p = windowToView(QPoint(*x, *y));
03359         *x = p.x();
03360         *y = p.y();
03361     }
03362 }
03363 
03364 void KisView::guiActivateEvent(KParts::GUIActivateEvent *event)
03365 {
03366     Q_ASSERT(event);
03367 
03368     if (event->activated()) {
03369 
03370         KStatusBar *sb = statusBar();
03371         if (sb) {
03372             sb->show();
03373         }
03374 
03375         if (!m_guiActivateEventReceived) {
03376             m_guiActivateEventReceived = true;
03377             startInitialZoomTimerIfReady();
03378         }
03379     }
03380 
03381     super::guiActivateEvent(event);
03382 }
03383 
03384 bool KisView::eventFilter(QObject *o, QEvent *e)
03385 {
03386     Q_ASSERT(o);
03387     Q_ASSERT(e);
03388 
03389     switch (e->type()) {
03390     case QEvent::TabletMove:
03391     case QEvent::TabletPress:
03392     case QEvent::TabletRelease:
03393     {
03394         QTabletEvent *te = static_cast<QTabletEvent *>(e);
03395         KisInputDevice device;
03396 
03397         switch (te->device()) {
03398         default:
03399         case QTabletEvent::Stylus:
03400         case QTabletEvent::NoDevice:
03401             device = KisInputDevice::stylus();
03402             break;
03403         case QTabletEvent::Puck:
03404             device = KisInputDevice::puck();
03405             break;
03406         case QTabletEvent::Eraser:
03407             device = KisInputDevice::eraser();
03408             break;
03409         }
03410 
03411         setInputDevice(device);
03412 
03413         // We ignore device change due to mouse events for a short duration
03414         // after a tablet event, since these are almost certainly mouse events
03415         // sent to receivers that don't accept the tablet event.
03416         m_tabletEventTimer.start();
03417         break;
03418     }
03419     case QEvent::MouseButtonPress:
03420     case QEvent::MouseMove:
03421     case QEvent::MouseButtonRelease:
03422     {
03423 #ifdef EXTENDED_X11_TABLET_SUPPORT
03424         KisInputDevice device = KisCanvasWidget::findActiveInputDevice();
03425 
03426         if (device != KisInputDevice::mouse()) {
03427             setInputDevice(device);
03428             m_tabletEventTimer.start();
03429         } else
03430 #endif
03431         {
03432             if (currentInputDevice() != KisInputDevice::mouse() && m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
03433                 setInputDevice(KisInputDevice::mouse());
03434             }
03435         }
03436         break;
03437     }
03438     case QEvent::KeyPress:
03439     case QEvent::KeyRelease:
03440     {
03441         if (m_canvas->cursorIsOverCanvas()) {
03442             m_canvas->handleKeyEvent(e);
03443             return true;
03444         }
03445         break;
03446     }
03447 #ifdef EXTENDED_X11_TABLET_SUPPORT
03448     case QEvent::ChildInserted:
03449     {
03450         QChildEvent *childEvent = static_cast<QChildEvent *>(e);
03451         QObject *child = childEvent->child();
03452 
03453         child->installEventFilter(this);
03454 
03455         QObjectList *objectList = child->queryList("QWidget");
03456         QObjectListIt it(*objectList);
03457         QObject *obj;
03458 
03459         while ((obj = it.current()) != 0) {
03460            obj->installEventFilter(this);
03461            ++it;
03462         }
03463 
03464         delete objectList;
03465     }
03466 #endif
03467     default:
03468         // Ignore
03469         break;
03470     }
03471 
03472 #if 0
03473     if ((o == m_hRuler || o == m_vRuler) && (e->type() == QEvent::MouseMove || e->type() == QEvent::MouseButtonRelease)) {
03474         QMouseEvent *me = dynamic_cast<QMouseEvent*>(e);
03475         QPoint pt = mapFromGlobal(me->globalPos());
03476         KisImageSP img = currentImg();
03477         KisGuideMgr *mgr;
03478 
03479         if (!img)
03480             return super::eventFilter(o, e);
03481 
03482         mgr = img->guides();
03483 
03484         if (e->type() == QEvent::MouseMove && (me->state() & Qt::LeftButton)) {
03485             bool flag = geometry().contains(pt);
03486             KisGuideSP gd;
03487 
03488             if (m_currentGuide == 0 && flag) {
03489                 // No guide is being edited and moving mouse over the canvas.
03490                 // Create a new guide.
03491                 enterEvent(0);
03492                 eraseGuides();
03493                 mgr->unselectAll();
03494 
03495                 if (o == m_vRuler)
03496                     gd = mgr->add((pt.x() - m_vRuler->width() + horzValue()) / zoom(), Qt::Vertical);
03497                 else
03498                     gd = mgr->add((pt.y() - m_hRuler->height() + vertValue()) / zoom(), Qt::Horizontal);
03499 
03500                 m_currentGuide = gd;
03501                 mgr->select(gd);
03502                 m_lastGuidePoint = mapToScreen(pt);
03503             } else if (m_currentGuide) {
03504                 if (flag) {
03505                     // moved an existing guide.
03506                     KisMoveEvent kme(currentInputDevice(), pt, me->globalPos(), PRESSURE_DEFAULT, 0, 0, me->state());
03507                     canvasGotMoveEvent(&kme);
03508                 } else {
03509                     //  moved a guide out of the frame, destroy it
03510                     leaveEvent(0);
03511                     eraseGuides();
03512                     mgr->remove(m_currentGuide);
03513                     paintGuides();
03514                     m_currentGuide = 0;
03515                 }
03516             }
03517         } else if (e->type() == QEvent::MouseButtonRelease && m_currentGuide) {
03518             eraseGuides();
03519             mgr->unselect(m_currentGuide);
03520             paintGuides();
03521             m_currentGuide = 0;
03522             enterEvent(0);
03523             KisMoveEvent kme(currentInputDevice(), pt, me->globalPos(), PRESSURE_DEFAULT, 0, 0, Qt::NoButton);
03524             canvasGotMoveEvent(&kme);
03525         }
03526     }
03527 #endif
03528 
03529     return super::eventFilter(o, e);
03530 }
03531 
03532 #if 0
03533 void KisView::eraseGuides()
03534 {
03535     KisImageSP img = currentImg();
03536 
03537     if (img) {
03538         KisGuideMgr *mgr = img->guides();
03539 
03540         if (mgr)
03541             mgr->erase(&m_canvasPixmap, this, horzValue(), vertValue(), zoom());
03542     }
03543 }
03544 
03545 void KisView::paintGuides()
03546 {
03547     KisImageSP img = currentImg();
03548 
03549     if (img) {
03550         KisGuideMgr *mgr = img->guides();
03551 
03552         if (mgr)
03553             mgr->paint(&m_canvasPixmap, this, horzValue(), vertValue(), zoom());
03554     }
03555 }
03556 
03557 void KisView::updateGuides()
03558 {
03559     eraseGuides();
03560     paintGuides();
03561 }
03562 #endif
03563 
03564 //void KisView::viewGuideLines()
03565 //{
03566 //}
03567 
03568 QPoint KisView::mapToScreen(const QPoint& pt)
03569 {
03570     QPoint converted;
03571 
03572     converted.rx() = pt.x() + horzValue();
03573     converted.ry() = pt.y() + vertValue();
03574     return converted;
03575 }
03576 
03577 void KisView::attach(KisCanvasObserver *observer)
03578 {
03579     Q_ASSERT(observer);
03580     if (observer)
03581         m_observers.push_back(observer);
03582 }
03583 
03584 void KisView::detach(KisCanvasObserver *observer)
03585 {
03586     Q_ASSERT(observer);
03587     if (observer) {
03588         vKisCanvasObserver_it it = std::find(m_observers.begin(), m_observers.end(), observer);
03589 
03590         if (it != m_observers.end())
03591             m_observers.erase(it);
03592     }
03593 }
03594 
03595 void KisView::notifyObservers()
03596 {
03597     for (vKisCanvasObserver_it it = m_observers.begin(); it != m_observers.end(); ++it) {
03598         (*it)->update(this);
03599     }
03600 }
03601 
03602 KisImageSP KisView::currentImg() const
03603 {
03604     return m_image;
03605 }
03606 
03607 void KisView::setCurrentImage(KisImageSP image)
03608 {
03609     if(!image) return;
03610 
03611     disconnectCurrentImg();
03612     m_image = image;
03613 
03614     KisConfig cfg;
03615 
03616 #ifdef HAVE_GL
03617     if (cfg.useOpenGL()) {
03618         m_OpenGLImageContext = KisOpenGLImageContext::getImageContext(image, monitorProfile());
03619         m_canvas->createOpenGLCanvas(m_OpenGLImageContext->sharedContextWidget());
03620     }
03621 #endif
03622     connectCurrentImg();
03623     m_layerBox->setImage(currentImg());
03624 
03625     zoomAroundPoint(0, 0, 1.0);
03626 
03627     if (!currentImg())
03628         layersUpdated();
03629 
03630     imgUpdateGUI();
03631 
03632     image->blockSignals(false);
03633 }
03634 
03635 KisColor KisView::bgColor() const
03636 {
03637     return m_bg;
03638 }
03639 
03640 KisColor KisView::fgColor() const
03641 {
03642     return m_fg;
03643 }
03644 
03645 KisBrush *KisView::currentBrush() const
03646 {
03647     return m_brush;
03648 }
03649 
03650 KisPattern *KisView::currentPattern() const
03651 {
03652     return m_pattern;
03653 }
03654 
03655 KisGradient *KisView::currentGradient() const
03656 {
03657     return m_gradient;
03658 }
03659 
03660 KisID KisView::currentPaintop() const
03661 {
03662     return m_paintop;
03663 }
03664 
03665 const KisPaintOpSettings *KisView::currentPaintopSettings() const
03666 {
03667     return m_paintopSettings;
03668 }
03669 
03670 double KisView::zoomFactor() const
03671 {
03672     return zoom();
03673 }
03674 
03675 KisUndoAdapter *KisView::undoAdapter() const
03676 {
03677     return m_adapter;
03678 }
03679 
03680 KisCanvasController *KisView::canvasController() const
03681 {
03682     return const_cast<KisCanvasController*>(static_cast<const KisCanvasController*>(this));
03683 }
03684 
03685 KisToolControllerInterface *KisView::toolController() const
03686 {
03687     return const_cast<KisToolControllerInterface*>(static_cast<const KisToolControllerInterface*>(m_toolManager));
03688 }
03689 
03690 KisDoc *KisView::document() const
03691 {
03692     return m_doc;
03693 }
03694 
03695 KisProgressDisplayInterface *KisView::progressDisplay() const
03696 {
03697     return m_progress;
03698 }
03699 
03700 QCursor KisView::setCanvasCursor(const QCursor & cursor)
03701 {
03702     QCursor oldCursor = m_canvas->cursor();
03703     QCursor newCursor;
03704 
03705     KisConfig cfg;
03706 
03707     switch (cfg.cursorStyle()) {
03708     case CURSOR_STYLE_TOOLICON:
03709         newCursor = cursor;
03710         break;
03711     case CURSOR_STYLE_CROSSHAIR:
03712         newCursor = KisCursor::crossCursor();
03713         break;
03714     case CURSOR_STYLE_POINTER:
03715         newCursor = KisCursor::arrowCursor();
03716         break;
03717     case CURSOR_STYLE_OUTLINE:
03718         newCursor = cursor;
03719         break;
03720     default:
03721         newCursor = cursor;
03722     }
03723 
03724     m_canvas->setCursor(newCursor);
03725     return oldCursor;
03726 }
03727 
03728 float KisView::HDRExposure() const
03729 {
03730     return m_HDRExposure;
03731 }
03732 
03733 void KisView::setHDRExposure(float exposure)
03734 {
03735     if (exposure != m_HDRExposure) {
03736         m_HDRExposure = exposure;
03737         notifyObservers();
03738         updateCanvas();
03739     }
03740 }
03741 
03742 void KisView::createDockers()
03743 {
03744 
03745     m_birdEyeBox = new KisBirdEyeBox(this);
03746     m_birdEyeBox->setCaption(i18n("Overview"));
03747     m_paletteManager->addWidget( m_birdEyeBox, "birdeyebox", krita::CONTROL_PALETTE);
03748 
03749     m_hsvwidget = new KoHSVWidget(this, "hsv");
03750     m_hsvwidget->setCaption(i18n("HSV"));
03751 
03752     connect(m_hsvwidget, SIGNAL(sigFgColorChanged(const QColor &)), this, SLOT(slotSetFGQColor(const QColor &)));
03753     connect(m_hsvwidget, SIGNAL(sigBgColorChanged(const QColor &)), this, SLOT(slotSetBGQColor(const QColor &)));
03754     connect(this, SIGNAL(sigFGQColorChanged(const QColor &)), m_hsvwidget, SLOT(setFgColor(const QColor &)));
03755     connect(this, SIGNAL(sigBGQColorChanged(const QColor &)), m_hsvwidget, SLOT(setBgColor(const QColor &)));
03756     m_paletteManager->addWidget( m_hsvwidget, "hsvwidget", krita::COLORBOX, 0, PALETTE_DOCKER, true);
03757 
03758     m_rgbwidget = new KoRGBWidget(this, "rgb");
03759     m_rgbwidget->setCaption(i18n("RGB"));
03760     connect(m_rgbwidget, SIGNAL(sigFgColorChanged(const QColor &)), this, SLOT(slotSetFGQColor(const QColor &)));
03761     connect(m_rgbwidget, SIGNAL(sigBgColorChanged(const QColor &)), this, SLOT(slotSetBGQColor(const QColor &)));
03762     connect(this, SIGNAL(sigFGQColorChanged(const QColor &)), m_rgbwidget, SLOT(setFgColor(const QColor &)));
03763     connect(this, SIGNAL(sigBGQColorChanged(const QColor &)), m_rgbwidget, SLOT(setBgColor(const QColor &)));
03764     m_paletteManager->addWidget( m_rgbwidget, "rgbwidget", krita::COLORBOX);
03765 
03766     m_graywidget = new KoGrayWidget(this, "gray");
03767     m_graywidget->setCaption(i18n("Gray"));
03768     connect(m_graywidget, SIGNAL(sigFgColorChanged(const QColor &)), this, SLOT(slotSetFGQColor(const QColor &)));
03769     connect(m_graywidget, SIGNAL(sigBgColorChanged(const QColor &)), this, SLOT(slotSetBGQColor(const QColor &)));
03770     connect(this, SIGNAL(sigFGQColorChanged(const QColor &)), m_graywidget, SLOT(setFgColor(const QColor &)));
03771     connect(this, SIGNAL(sigBGQColorChanged(const QColor &)), m_graywidget, SLOT(setBgColor(const QColor &)));
03772     m_paletteManager->addWidget( m_graywidget, "graywidget", krita::COLORBOX);
03773 
03774     //make sure the color chooser get right default values
03775     emit sigFGQColorChanged(m_fg.toQColor());
03776     emit sigBGQColorChanged(m_bg.toQColor());
03777 
03778     m_palettewidget = new KisPaletteWidget(this);
03779     m_palettewidget->setCaption(i18n("Palettes"));
03780     connect(m_palettewidget, SIGNAL(colorSelected(const QColor &)),
03781             this, SLOT(slotSetFGQColor(const QColor &)));
03782     // No BGColor or reverse slotFGChanged->palette connections, since that's not useful here
03783 
03784     KisResourceServerBase* rServer;
03785     rServer = KisResourceServerRegistry::instance()->get("PaletteServer");
03786     QValueList<KisResource*> resources = rServer->resources();
03787     QValueList<KisResource*>::iterator it;
03788     for ( it = resources.begin(); it != resources.end(); ++it ) {
03789         m_palettewidget->slotAddPalette( *it );
03790     }
03791     connect(m_palettewidget, SIGNAL(colorSelected(const KisColor &)), this, SLOT(slotSetFGColor(const KisColor &)));
03792     m_paletteManager->addWidget( m_palettewidget, "palettewidget", krita::COLORBOX, 10, PALETTE_DOCKER, true);
03793 }
03794 
03795 QPoint KisView::applyViewTransformations(const QPoint& p) const {
03796     QPoint point(windowToView(p));
03797 
03798     if (m_hRuler->isShown())
03799         point.ry() += m_hRuler->height();
03800     if (m_vRuler -> isShown())
03801         point.rx() += m_vRuler->width();
03802 
03803     return point;
03804 }
03805 
03806 QPoint KisView::reverseViewTransformations(const QPoint& p) const {
03807     // Since we now zoom ourselves, the only thing super::~ does is nothing anymore.
03808     // Hence, zoom ourselves, like super would
03809     // viewToWindow doesn't take the rulers into account, do that ourselves
03810     QPoint point(p);
03811     if (m_hRuler -> isShown())
03812         point.ry() -= m_hRuler -> height();
03813     if (m_vRuler -> isShown())
03814         point.rx() -= m_vRuler -> width();
03815 
03816     return viewToWindow(point);
03817 }
03818 
03819 void KisView::canvasAddChild(KoViewChild *child) {
03820     super::canvasAddChild(child);
03821     connect(this, SIGNAL(viewTransformationsChanged()), child, SLOT(reposition()));
03822     m_vScroll->raise();
03823     m_hScroll->raise();
03824     m_vScroll->raise();
03825     m_hRuler->raise();
03826     m_vRuler->raise();
03827 }
03828 
03829 void KisView::slotLoadingFinished()
03830 {
03831     // Set the current image for real now everything is ready to go.
03832     setCurrentImage(document()->currentImage());
03833     m_paletteManager->showWidget( "layerbox" );
03834     m_canvas->show();
03835     disconnect(document(), SIGNAL(loadingFinished()), this, SLOT(slotLoadingFinished()));
03836 
03837     m_imageLoaded = true;
03838     startInitialZoomTimerIfReady();
03839 }
03840 
03841 void KisView::startInitialZoomTimerIfReady()
03842 {
03843     if (m_imageLoaded && m_showEventReceived && m_guiActivateEventReceived) {
03844         m_initialZoomTimer.start(250, true);
03845     }
03846 }
03847 
03848 void KisView::slotInitialZoomTimeout()
03849 {
03850     Q_ASSERT(!m_paintViewEnabled);
03851 
03852     m_paintViewEnabled = true;
03853     setInitialZoomLevel();
03854 }
03855 
03856 #include "kis_view.moc"
03857 
KDE Home | KDE Accessibility Home | Description of Access Keys