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     KisUndoAdapter * undo = 0;
01800     KisTransaction * t = 0;
01801     if ((currentImg()->undo())) {
01802         t = new KisTransaction(i18n("Mirror Layer X"), dev);
01803         Q_CHECK_PTR(t);
01804     }
01805 
01806     dev->mirrorX();
01807 
01808     if (undo) undoAdapter()->addCommand(t);
01809 
01810     m_doc->setModified(true);
01811     layersUpdated();
01812     updateCanvas();
01813 }
01814 
01815 void KisView::mirrorLayerY()
01816 {
01817     if (!currentImg()) return;
01818     KisPaintDeviceSP dev = currentImg()->activeDevice();
01819     if (!dev) return;
01820 
01821     KisUndoAdapter * undo = 0;
01822     KisTransaction * t = 0;
01823     if ((currentImg()->undo())) {
01824         t = new KisTransaction(i18n("Mirror Layer Y"), dev);
01825         Q_CHECK_PTR(t);
01826     }
01827 
01828     dev->mirrorY();
01829 
01830     if (undo) undoAdapter()->addCommand(t);
01831 
01832     m_doc->setModified(true);
01833     layersUpdated();
01834     updateCanvas();
01835 }
01836 
01837 void KisView::scaleLayer(double sx, double sy, KisFilterStrategy *filterStrategy)
01838 {
01839     if (!currentImg()) return;
01840 
01841     KisPaintDeviceSP dev = currentImg()->activeDevice();
01842     if (!dev) return;
01843 
01844     KisUndoAdapter * undo = 0;
01845     KisTransaction * t = 0;
01846     if ((currentImg()->undo())) {
01847         t = new KisTransaction(i18n("Scale Layer"), dev);
01848         Q_CHECK_PTR(t);
01849     }
01850 
01851     KisTransformWorker worker(dev, sx, sy, 0, 0, 0.0, 0, 0, m_progress, filterStrategy);
01852     worker.run();
01853 
01854     if (undo) undoAdapter()->addCommand(t);
01855 
01856     m_doc->setModified(true);
01857     layersUpdated();
01858     updateCanvas();
01859 }
01860 
01861 void KisView::rotateLayer(double angle)
01862 {
01863     if (!currentImg()) return;
01864 
01865     KisPaintDeviceSP dev = currentImg()->activeDevice();
01866     if (!dev) return;
01867 
01868     KisUndoAdapter * undo = 0;
01869     KisTransaction * t = 0;
01870     if ((currentImg()->undo())) {
01871         t = new KisTransaction(i18n("Rotate Layer"), dev);
01872         Q_CHECK_PTR(t);
01873     }
01874 
01875     KisFilterStrategy *filter = KisFilterStrategyRegistry::instance()->get(KisID("Triangle"));
01876     angle *= M_PI/180;
01877     Q_INT32 w = currentImg()->width();
01878     Q_INT32 h = currentImg()->height();
01879     Q_INT32 tx = Q_INT32((w*cos(angle) - h*sin(angle) - w) / 2 + 0.5);
01880     Q_INT32 ty = Q_INT32((h*cos(angle) + w*sin(angle) - h) / 2 + 0.5);
01881 
01882     KisTransformWorker tw(dev, 1.0, 1.0, 0, 0, angle, -tx, -ty, m_progress, filter);
01883     tw.run();
01884 
01885     if (undo) undoAdapter()->addCommand(t);
01886 
01887     m_doc->setModified(true);
01888     layersUpdated();
01889     updateCanvas();
01890 }
01891 
01892 void KisView::shearLayer(double angleX, double angleY)
01893 {
01894     if (!currentImg()) return;
01895 
01896     KisLayerSP layer = currentImg()->activeLayer();
01897     if (!layer) return;
01898 
01899     KisUndoAdapter * undo = 0;
01900     if ((undo = currentImg()->undoAdapter())) {
01901         undo->beginMacro(i18n("Shear layer"));
01902     }
01903 
01904     KisShearVisitor v(angleX, angleY, m_progress);
01905     v.setUndoAdapter(undo);
01906     layer->accept(v);
01907 
01908     if (undo) undo->endMacro();
01909 
01910     m_doc->setModified(true);
01911     layersUpdated();
01912     updateCanvas();
01913 }
01914 
01915 void KisView::flattenImage()
01916 {
01917     KisImageSP img = currentImg();
01918 
01919     if (img) {
01920         bool doIt = true;
01921 
01922         if (img->nHiddenLayers() > 0) {
01923             int answer = KMessageBox::warningYesNo(this,
01924                                    i18n("The image contains hidden layers that will be lost."),
01925                                    i18n("Flatten Image"),
01926                                    i18n("&Flatten Image"),
01927                                    KStdGuiItem::cancel());
01928 
01929             if (answer != KMessageBox::Yes) {
01930                 doIt = false;
01931             }
01932         }
01933 
01934         if (doIt) {
01935             img->flatten();
01936         }
01937     }
01938 }
01939 
01940 void KisView::mergeLayer()
01941 {
01942     KisImageSP img = currentImg();
01943     if (!img) return;
01944 
01945     KisLayerSP layer = img->activeLayer();
01946     if (!layer) return;
01947 
01948     img->mergeLayer(layer);
01949 }
01950 
01951 void KisView::preferences()
01952 {
01953 #ifdef HAVE_GL
01954     bool canvasWasOpenGL = m_canvas->isOpenGLCanvas();
01955 #endif
01956 
01957     if (PreferencesDialog::editPreferences())
01958     {
01959         KisConfig cfg;
01960         m_paletteManager->slotResetFont();
01961         resetMonitorProfile();
01962 
01963 #ifdef HAVE_GL
01964         if (cfg.useOpenGL() != canvasWasOpenGL) {
01965 
01966             disconnectCurrentImg();
01967 
01968             //XXX: Need to notify other views that this global setting has changed.
01969             if (cfg.useOpenGL()) {
01970                 m_OpenGLImageContext = KisOpenGLImageContext::getImageContext(m_image, monitorProfile());
01971                 m_canvas->createOpenGLCanvas(m_OpenGLImageContext->sharedContextWidget());
01972             } else
01973             {
01974                 m_OpenGLImageContext = 0;
01975                 m_canvas->createQPaintDeviceCanvas();
01976             }
01977 
01978             connectCurrentImg();
01979 
01980             resizeEvent(0);
01981         }
01982 
01983         if (cfg.useOpenGL()) {
01984             m_OpenGLImageContext->setMonitorProfile(monitorProfile());
01985         }
01986 #endif
01987 
01988         refreshKisCanvas();
01989 
01990         if (m_toolManager->currentTool()) {
01991             setCanvasCursor(m_toolManager->currentTool()->cursor());
01992         }
01993 
01994 #if defined(EXTENDED_X11_TABLET_SUPPORT)
01995         m_canvas->selectTabletDeviceEvents();
01996 #endif
01997 
01998     }
01999 }
02000 
02001 void KisView::layerCompositeOp(const KisCompositeOp& compositeOp)
02002 {
02003     KisImageSP img = currentImg();
02004     if (!img) return;
02005 
02006     KisLayerSP layer = img->activeLayer();
02007     if (!layer) return;
02008 
02009     if (img->undo()) {
02010         KNamedCommand *cmd = layer->setCompositeOpCommand(compositeOp);
02011         cmd->execute();
02012         undoAdapter()->addCommand(cmd);
02013     }
02014 }
02015 
02016 // range: 0 - 100
02017 void KisView::layerOpacity(int opacity, bool dontundo)
02018 {
02019     KisImageSP img = currentImg();
02020     if (!img) return;
02021 
02022     KisLayerSP layer = img->activeLayer();
02023     if (!layer) return;
02024 
02025     opacity = int(float(opacity * 255) / 100 + 0.5);
02026     if (opacity > 255)
02027         opacity = 255;
02028 
02029     if (opacity == layer->opacity()) return;
02030 
02031     if (dontundo)
02032         layer->setOpacity( opacity );
02033     else
02034     {
02035         if (img->undo()) {
02036             KNamedCommand *cmd = layer->setOpacityCommand(opacity);
02037             cmd->execute();
02038             undoAdapter()->addCommand(cmd);
02039         }
02040     }
02041 }
02042 
02043 void KisView::layerOpacityFinishedChanging( int previous, int opacity )
02044 {
02045     KisImageSP img = currentImg();
02046     if (!img) return;
02047 
02048     KisLayerSP layer = img->activeLayer();
02049     if (!layer) return;
02050 
02051     opacity = int(float(opacity * 255) / 100 + 0.5);
02052     if (opacity > 255)
02053         opacity = 255;
02054 
02055     previous = int(float(previous * 255) / 100 + 0.5);
02056     if (previous > 255)
02057         previous = 255;
02058 
02059     if (previous == opacity) return;
02060 
02061     if (img->undo()) {
02062         KNamedCommand *cmd = layer->setOpacityCommand(previous, opacity);
02063         m_adapter->addCommand(cmd);
02064     }
02065 }
02066 
02067 
02068 void KisView::showRuler()
02069 {
02070     if( m_RulerAction->isChecked() )
02071     {
02072         m_hRuler->show();
02073         m_vRuler->show();
02074     }
02075     else
02076     {
02077         m_hRuler->hide();
02078         m_vRuler->hide();
02079     }
02080 
02081     resizeEvent(0);
02082     refreshKisCanvas();
02083 }
02084 
02085 void KisView::slotUpdateFullScreen(bool toggle)
02086 {
02087     if (KoView::shell()) {
02088 
02089         uint newState = KoView::shell()->windowState();
02090 
02091         if (toggle) {
02092             newState |= Qt::WindowFullScreen;
02093         } else {
02094             newState &= ~Qt::WindowFullScreen;
02095         }
02096 
02097         KoView::shell()->setWindowState(newState);
02098     }
02099 }
02100 
02101 Q_INT32 KisView::docWidth() const
02102 {
02103     return currentImg() ? currentImg()->width() : 0;
02104 }
02105 
02106 Q_INT32 KisView::docHeight() const
02107 {
02108     return currentImg() ? currentImg()->height() : 0;
02109 }
02110 
02111 void KisView::scrollTo(Q_INT32 x, Q_INT32 y)
02112 {
02113     if (m_hScroll->isVisible()) {
02114         m_hScroll->setValue(x);
02115     }
02116     if (m_vScroll->isVisible()) {
02117         m_vScroll->setValue(y);
02118     }
02119 }
02120 
02121 void KisView::brushActivated(KisResource *brush)
02122 {
02123 
02124     m_brush = dynamic_cast<KisBrush*>(brush);
02125 
02126     if (m_brush )
02127     {
02128         emit brushChanged(m_brush);
02129         notifyObservers();
02130     }
02131 }
02132 
02133 void KisView::patternActivated(KisResource *pattern)
02134 {
02135     m_pattern = dynamic_cast<KisPattern*>(pattern);
02136 
02137     if (m_pattern) {
02138         emit patternChanged(m_pattern);
02139         notifyObservers();
02140     }
02141 }
02142 
02143 void KisView::gradientActivated(KisResource *gradient)
02144 {
02145 
02146     m_gradient = dynamic_cast<KisGradient*>(gradient);
02147 
02148     if (m_gradient) {
02149         emit gradientChanged(m_gradient);
02150         notifyObservers();
02151     }
02152 }
02153 
02154 void KisView::paintopActivated(const KisID & paintop, const KisPaintOpSettings *paintopSettings)
02155 {
02156     if (paintop.id().isNull() || paintop.id().isEmpty()) {
02157         return;
02158     }
02159 
02160     m_paintop = paintop;
02161     m_paintopSettings = paintopSettings;
02162     emit paintopChanged(m_paintop, paintopSettings);
02163     notifyObservers();
02164 }
02165 
02166 void KisView::setBGColor(const KisColor& c)
02167 {
02168     m_bg = c;
02169     notifyObservers();
02170     emit sigBGQColorChanged( c.toQColor() );
02171 }
02172 
02173 void KisView::setFGColor(const KisColor& c)
02174 {
02175     m_fg = c;
02176     notifyObservers();
02177     emit sigFGQColorChanged( c.toQColor() );
02178 }
02179 
02180 void KisView::slotSetFGColor(const KisColor& c)
02181 {
02182 
02183     m_fg = c;
02184     notifyObservers();
02185 }
02186 
02187 void KisView::slotSetBGColor(const KisColor& c)
02188 {
02189 
02190     m_bg = c;
02191     notifyObservers();
02192 }
02193 
02194 void KisView::slotSetFGQColor(const QColor& c)
02195 {
02196     KisColorSpace * monitorSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA"), m_monitorProfile);
02197     setFGColor(KisColor(c, monitorSpace));
02198     emit sigFGQColorChanged(c);
02199 }
02200 
02201 void KisView::slotSetBGQColor(const QColor& c)
02202 {
02203     KisColorSpace * monitorSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA"), m_monitorProfile);
02204     setBGColor(KisColor(c, monitorSpace));
02205     emit sigBGQColorChanged(c);
02206 }
02207 
02208 
02209 void KisView::setupPrinter(KPrinter& printer)
02210 {
02211     KisImageSP img = currentImg();
02212 
02213     if (img) {
02214         printer.setPageSelection(KPrinter::ApplicationSide);
02215         printer.setPageSize(KPrinter::A4);
02216         printer.setOrientation(KPrinter::Portrait);
02217     }
02218 }
02219 
02220 void KisView::print(KPrinter& printer)
02221 {
02222     QPainter gc(&printer);
02223 
02224     KisImageSP img = currentImg();
02225     if (!img) return;
02226 
02227     printer.setFullPage(true);
02228     gc.setClipping(false);
02229 
02230     KisConfig cfg;
02231     QString printerProfileName = cfg.printerProfile();
02232     KisProfile *  printerProfile = KisMetaRegistry::instance()->csRegistry() ->getProfileByName(printerProfileName);
02233 
02234     QRect r = img->bounds();
02235     img->renderToPainter(r.x(), r.y(), r.width(), r.height(), gc, printerProfile, KisImage::PAINT_IMAGE_ONLY, HDRExposure());
02236 }
02237 
02238 void KisView::paintToolOverlay(const QRegion& region)
02239 {
02240     if (!region.isEmpty() && m_toolManager->currentTool() && !m_toolIsPainting) {
02241         KisCanvasPainter gc(m_canvas);
02242 
02243         gc.setClipRegion(region);
02244         gc.setClipping(true);
02245 
02246         // Prevent endless loop if the tool needs to have the canvas repainted
02247         m_toolIsPainting = true;
02248         m_toolManager->currentTool()->paint(gc, region.boundingRect());
02249         m_toolIsPainting = false;
02250     }
02251 }
02252 
02253 void KisView::canvasGotPaintEvent(QPaintEvent *event)
02254 {
02255     if (m_canvas->isOpenGLCanvas()) {
02256         paintOpenGLView(event->rect());
02257     } else {
02258         paintQPaintDeviceView(event->region());
02259     }
02260 }
02261 
02262 void KisView::canvasGotButtonPressEvent(KisButtonPressEvent *e)
02263 {
02264 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02265     // The event filter doesn't see tablet events going to the canvas.
02266     if (e->device() != KisInputDevice::mouse()) {
02267         m_tabletEventTimer.start();
02268     }
02269 #endif // EXTENDED_X11_TABLET_SUPPORT
02270 
02271     if (e->device() != currentInputDevice()) {
02272         if (e->device() == KisInputDevice::mouse()) {
02273             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02274                 setInputDevice(KisInputDevice::mouse());
02275             }
02276         } else {
02277             setInputDevice(e->device());
02278         }
02279     }
02280 
02281     KisImageSP img = currentImg();
02282 
02283 //    if (img) {
02284 //        QPoint pt = mapToScreen(e->pos().floorQPoint());
02285 //        KisGuideMgr *mgr = img->guides();
02286 //
02287 //        m_lastGuidePoint = mapToScreen(e->pos().floorQPoint());
02288 //        m_currentGuide = 0;
02289 //
02290 //        if ((e->state() & ~Qt::ShiftButton) == Qt::NoButton) {
02291 //            KisGuideSP gd = mgr->find(static_cast<Q_INT32>(pt.x() / zoom()), static_cast<Q_INT32>(pt.y() / zoom()), QMAX(2.0, 2.0 / zoom()));
02292 //
02293 //            if (gd) {
02294 //                m_currentGuide = gd;
02295 //
02296 //                if ((e->button() == Qt::RightButton) || ((e->button() & Qt::ShiftButton) == Qt::ShiftButton)) {
02297 //                    if (gd->isSelected())
02298 //                        mgr->unselect(gd);
02299 //                    else
02300 //                        mgr->select(gd);
02301 //              } else {
02302 //                    if (!gd->isSelected()) {
02303 //                        mgr->unselectAll();
02304 //                        mgr->select(gd);
02305 //                    }
02306 //                }
02307 //
02308 //                updateGuides();
02309 //                return;
02310 //            }
02311 //        }
02312 //    }
02313     if (e->button() == Qt::RightButton) {
02314 
02315         if (m_popup == 0 && factory()) {
02316             Q_ASSERT(factory());
02317             m_popup = (QPopupMenu *)factory()->container("image_popup", this);
02318         }
02319         if (m_popup) m_popup->popup(e->globalPos().roundQPoint());
02320     }
02321     else if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02322         KisPoint p = viewToWindow(e->pos());
02323         // somewhat of a hack: we should actually test if we intersect with the scrollers,
02324         // but the globalPos seems to be off by a few pixels
02325         if (m_vScroll->draggingSlider() || m_hScroll->draggingSlider())
02326             return;
02327 
02328         if (m_toolManager->currentTool()->wantsAutoScroll()) {
02329             enableAutoScroll();
02330         }
02331 
02332         KisButtonPressEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
02333         m_toolManager->currentTool()->buttonPress(&ev);
02334     }
02335 }
02336 
02337 void KisView::canvasGotMoveEvent(KisMoveEvent *e)
02338 {
02339 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02340     // The event filter doesn't see tablet events going to the canvas.
02341     if (e->device() != KisInputDevice::mouse()) {
02342         m_tabletEventTimer.start();
02343     }
02344 #endif // EXTENDED_X11_TABLET_SUPPORT
02345 
02346     if (e->device() != currentInputDevice()) {
02347         if (e->device() == KisInputDevice::mouse()) {
02348             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02349                 setInputDevice(KisInputDevice::mouse());
02350             }
02351         } else {
02352             setInputDevice(e->device());
02353         }
02354     }
02355 
02356     KisImageSP img = currentImg();
02357 
02358     m_hRuler->updatePointer(e->pos().floorX() - m_canvasXOffset, e->pos().floorY() - m_canvasYOffset);
02359     m_vRuler->updatePointer(e->pos().floorX() - m_canvasXOffset, e->pos().floorY() - m_canvasYOffset);
02360 
02361     KisPoint wp = viewToWindow(e->pos());
02362 
02363 #if 0
02364     if (img && m_currentGuide) {
02365         QPoint p = mapToScreen(e->pos().floorQPoint());
02366         KisGuideMgr *mgr = img->guides();
02367 
02368         if (((e->state() & Qt::LeftButton) == Qt::LeftButton) && mgr->hasSelected()) {
02369             eraseGuides();
02370             p -= m_lastGuidePoint;
02371 
02372             if (p.x())
02373                 mgr->moveSelectedByX(p.x() / zoom());
02374 
02375             if (p.y())
02376                 mgr->moveSelectedByY(p.y() / zoom());
02377 
02378             m_doc->setModified(true);
02379             paintGuides();
02380         }
02381     } else
02382 #endif
02383     if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02384         KisMoveEvent ev(e->device(), wp, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->state());
02385 
02386         m_toolManager->currentTool()->move(&ev);
02387     }
02388 
02389 //    m_lastGuidePoint = mapToScreen(e->pos().floorQPoint());
02390     emit cursorPosition(wp.floorX(), wp.floorY());
02391 }
02392 
02393 int KisView::leftBorder() const
02394 {
02395   return m_rulerThickness;
02396 }
02397 
02398 int KisView::rightBorder() const
02399 {
02400   return m_hScrollBarExtent;
02401 }
02402 
02403 int KisView::topBorder() const
02404 {
02405   return m_rulerThickness;
02406 }
02407 
02408 int KisView::bottomBorder() const
02409 {
02410   return m_vScrollBarExtent;
02411 }
02412 
02413 void KisView::mouseMoveEvent(QMouseEvent *e)
02414 {
02415     KisMoveEvent ke(currentInputDevice(), e->pos(), e->globalPos(), PRESSURE_DEFAULT, 0, 0, e->state());
02416     canvasGotMoveEvent(&ke);
02417 }
02418 
02419 void KisView::slotAutoScroll(const QPoint &p)
02420 {
02421     scrollTo(horzValue()+p.x(), vertValue()+p.y());
02422 }
02423 
02424 void KisView::canvasGotButtonReleaseEvent(KisButtonReleaseEvent *e)
02425 {
02426 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02427     // The event filter doesn't see tablet events going to the canvas.
02428     if (e->device() != KisInputDevice::mouse()) {
02429         m_tabletEventTimer.start();
02430     }
02431 #endif // EXTENDED_X11_TABLET_SUPPORT
02432 
02433     if (e->device() != currentInputDevice()) {
02434         if (e->device() == KisInputDevice::mouse()) {
02435             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02436                 setInputDevice(KisInputDevice::mouse());
02437             }
02438         } else {
02439             setInputDevice(e->device());
02440         }
02441     }
02442 
02443     KisImageSP img = currentImg();
02444 
02445 //    if (img && m_currentGuide) {
02446 //        m_currentGuide = 0;
02447 //    } else
02448     if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02449         KisPoint p = viewToWindow(e->pos());
02450         KisButtonReleaseEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
02451 
02452         disableAutoScroll();
02453         if (m_toolManager->currentTool()) {
02454             m_toolManager->currentTool()->buttonRelease(&ev);
02455         }
02456     }
02457 }
02458 
02459 void KisView::canvasGotDoubleClickEvent(KisDoubleClickEvent *e)
02460 {
02461 #if defined(EXTENDED_X11_TABLET_SUPPORT)
02462     // The event filter doesn't see tablet events going to the canvas.
02463     if (e->device() != KisInputDevice::mouse()) {
02464         m_tabletEventTimer.start();
02465     }
02466 #endif // EXTENDED_X11_TABLET_SUPPORT
02467 
02468     if (e->device() != currentInputDevice()) {
02469         if (e->device() == KisInputDevice::mouse()) {
02470             if (m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
02471                 setInputDevice(KisInputDevice::mouse());
02472             }
02473         } else {
02474             setInputDevice(e->device());
02475         }
02476     }
02477 
02478     if (e->device() == currentInputDevice() && m_toolManager->currentTool()) {
02479         KisPoint p = viewToWindow(e->pos());
02480         KisDoubleClickEvent ev(e->device(), p, e->globalPos(), e->pressure(), e->xTilt(), e->yTilt(), e->button(), e->state());
02481 
02482         if (m_toolManager->currentTool()) {
02483             m_toolManager->currentTool()->doubleClick(&ev);
02484         }
02485     }
02486 }
02487 
02488 void KisView::canvasGotEnterEvent(QEvent *e)
02489 {
02490     if (m_toolManager->currentTool())
02491         m_toolManager->currentTool()->enter(e);
02492 }
02493 
02494 void KisView::canvasGotLeaveEvent (QEvent *e)
02495 {
02496     if (m_toolManager->currentTool())
02497         m_toolManager->currentTool()->leave(e);
02498 }
02499 
02500 void KisView::canvasGotMouseWheelEvent(QWheelEvent *event)
02501 {
02502     //if(event->state() == ControlButton )
02503     //{
02504         if(event->delta() / 120 != 0)
02505         {
02506             if(event->delta() > 0)
02507             {
02508                 zoomIn();
02509             } else {
02510                 zoomOut();
02511             }
02512         }
02513     //} else {
02514     //    QApplication::sendEvent(m_vScroll, event);
02515     //}
02516 }
02517 
02518 void KisView::canvasGotKeyPressEvent(QKeyEvent *event)
02519 {
02520     if (!m_toolManager->currentTool()) {
02521         event->ignore();
02522         return;
02523     }
02524 
02525     if (event->key() == Qt::Key_Space) {
02526         if (!m_panning) {
02527             // Set tool temporarily to pan
02528             m_panning = true;
02529             m_oldTool = m_toolManager->currentTool();
02530             m_toolManager->setCurrentTool( "tool_pan" );
02531         }
02532         else {
02533             // Unset panning
02534             m_panning = false;
02535             m_toolManager->setCurrentTool( m_oldTool );
02536             m_oldTool = 0;
02537         }
02538     }
02539     if (m_toolManager->currentTool())
02540         m_toolManager->currentTool()->keyPress(event);
02541 }
02542 
02543 void KisView::canvasGotKeyReleaseEvent(QKeyEvent *event)
02544 {
02545     if (m_toolManager->currentTool())
02546         m_toolManager->currentTool()->keyRelease(event);
02547 }
02548 
02549 void KisView::canvasGotDragEnterEvent(QDragEnterEvent *event)
02550 {
02551     bool accept = false;
02552 
02553     // Only accept drag if we're not busy, particularly as we may
02554     // be showing a progress bar and calling qApp->processEvents().
02555     if (KURLDrag::canDecode(event) && QApplication::overrideCursor() == 0) {
02556         accept = true;
02557     }
02558 
02559     event->accept(accept);
02560 }
02561 
02562 void KisView::canvasGotDropEvent(QDropEvent *event)
02563 {
02564     KURL::List urls;
02565 
02566     if (KURLDrag::decode(event, urls))
02567     {
02568         if (urls.count() > 0) {
02569             enum enumActionId {
02570                 addLayerId = 1,
02571                 addDocumentId = 2,
02572                 cancelId
02573             };
02574 
02575             KPopupMenu popup(this, "drop_popup");
02576 
02577             if (urls.count() == 1) {
02578                 if (currentImg() != 0) {
02579                     popup.insertItem(i18n("Insert as New Layer"), addLayerId);
02580                 }
02581                 popup.insertItem(i18n("Open in New Document"), addDocumentId);
02582             }
02583             else {
02584                 if (currentImg() != 0) {
02585                     popup.insertItem(i18n("Insert as New Layers"), addLayerId);
02586                 }
02587                 popup.insertItem(i18n("Open in New Documents"), addDocumentId);
02588             }
02589 
02590             popup.insertSeparator();
02591             popup.insertItem(i18n("Cancel"), cancelId);
02592 
02593             int actionId = popup.exec(QCursor::pos());
02594 
02595             if (actionId >= 0 && actionId != cancelId) {
02596                 for (KURL::List::ConstIterator it = urls.begin (); it != urls.end (); ++it) {
02597                     KURL url = *it;
02598 
02599                     switch (actionId) {
02600                     case addLayerId:
02601                         importImage(url);
02602                         break;
02603                     case addDocumentId:
02604                         if (shell() != 0) {
02605                             shell()->openDocument(url);
02606                         }
02607                         break;
02608                     }
02609                 }
02610             }
02611         }
02612     }
02613 }
02614 
02615 void KisView::layerProperties()
02616 {
02617     if (currentImg() && currentImg()->activeLayer())
02618         showLayerProperties(currentImg()->activeLayer());
02619 }
02620 
02621 void KisView::showLayerProperties(KisLayerSP layer)
02622 {
02623     Q_ASSERT( layer );
02624     if ( !layer ) return;
02625 
02626     KisColorSpace * cs = 0;
02627     KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>( layer.data() );
02628     if ( pl ) {
02629         cs = pl->paintDevice()->colorSpace();
02630     }
02631     else {
02632         cs = layer->image()->colorSpace();
02633     }
02634 
02635 
02636     if (KisAdjustmentLayerSP alayer = dynamic_cast<KisAdjustmentLayer*>(layer.data()))
02637     {
02638         KisDlgAdjLayerProps dlg(alayer, alayer->name(), i18n("Adjustment Layer Properties"), this, "dlgadjlayerprops");
02639         if (dlg.exec() == QDialog::Accepted)
02640         {
02641             QApplication::setOverrideCursor(KisCursor::waitCursor());
02642             alayer->setFilter( dlg.filterConfiguration() );
02643             alayer->setDirty();
02644             QApplication::restoreOverrideCursor();
02645             m_doc->setModified( true );
02646         }
02647     }
02648     else
02649     {
02650         KisDlgLayerProperties dlg(layer->name(),
02651                                   layer->opacity(),
02652                                   layer->compositeOp(),
02653                                   cs);
02654         if (dlg.exec() == QDialog::Accepted)
02655         {
02656             if (layer->name() != dlg.getName() ||
02657                 layer->opacity() != dlg.getOpacity() ||
02658                 layer->compositeOp() != dlg.getCompositeOp())
02659             {
02660                 QApplication::setOverrideCursor(KisCursor::waitCursor());
02661                 m_adapter->beginMacro(i18n("Property Changes"));
02662                 layer->image()->setLayerProperties(layer, dlg.getOpacity(), dlg.getCompositeOp(), dlg.getName());
02663                 layer->setDirty();
02664                 m_adapter->endMacro();
02665                 QApplication::restoreOverrideCursor();
02666                 m_doc->setModified( true );
02667             }
02668         }
02669     }
02670 }
02671 
02672 void KisView::layerAdd()
02673 {
02674     KisImageSP img = currentImg();
02675     if (img && img->activeLayer()) {
02676         addLayer(img->activeLayer()->parent(), img->activeLayer());
02677     }
02678     else if (img)
02679         addLayer(static_cast<KisGroupLayer*>(img->rootLayer().data()), 0);
02680 }
02681 
02682 void KisView::addLayer(KisGroupLayerSP parent, KisLayerSP above)
02683 {
02684     KisImageSP img = currentImg();
02685     if (img) {
02686         KisConfig cfg;
02687         QString profilename;
02688         if(img->colorSpace()->getProfile())
02689             profilename = img->colorSpace()->getProfile()->productName();
02690         NewLayerDialog dlg(img->colorSpace()->id(), profilename, img->nextLayerName(), this);
02691 
02692         if (dlg.exec() == QDialog::Accepted) {
02693             KisColorSpace* cs = KisMetaRegistry::instance()-> csRegistry() ->
02694                     getColorSpace(dlg.colorSpaceID(),dlg.profileName());
02695             KisLayerSP layer = new KisPaintLayer(img, dlg.layerName(), dlg.opacity(), cs);
02696             if (layer) {
02697                 layer->setCompositeOp(dlg.compositeOp());
02698                 img->addLayer(layer, parent.data(), above);
02699                 updateCanvas();
02700             } else {
02701                 KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
02702             }
02703         }
02704         else {
02705             img->rollBackLayerName();
02706         }
02707     }
02708 }
02709 
02710 void KisView::addGroupLayer(KisGroupLayerSP parent, KisLayerSP above)
02711 {
02712     KisImageSP img = currentImg();
02713     if (img) {
02714         QString profilename;
02715         if(img->colorSpace()->getProfile())
02716             profilename = img->colorSpace()->getProfile()->productName();
02717         KisConfig cfg;
02718         NewLayerDialog dlg(img->colorSpace()->id(), profilename, img->nextLayerName(), this);
02719         dlg.setColorSpaceEnabled(false);
02720 
02721         if (dlg.exec() == QDialog::Accepted) {
02722             KisLayerSP layer = new KisGroupLayer(img, dlg.layerName(), dlg.opacity());
02723             if (layer) {
02724                 layer->setCompositeOp(dlg.compositeOp());
02725                 img->addLayer(layer, parent.data(), above);
02726                 updateCanvas();
02727             } else {
02728                 KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
02729             }
02730         }
02731     }
02732 }
02733 
02734 void KisView::addPartLayer()
02735 {
02736     KisImageSP img = currentImg();
02737     if (!img) return;
02738 
02739     addPartLayer(img->rootLayer(), img->rootLayer()->firstChild(), m_actionPartLayer->documentEntry());
02740 }
02741 
02742 void KisView::addPartLayer(KisGroupLayerSP parent, KisLayerSP above, const KoDocumentEntry& entry)
02743 {
02744     delete m_partHandler; // Only one at a time
02745     m_partHandler = new KisPartLayerHandler(this, entry, parent, above);
02746 
02747     disconnect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)), this, 0);
02748     disconnect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)), this, 0);
02749     disconnect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)), this, 0);
02750     disconnect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)), this, 0);
02751 
02752     connect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)),
02753             m_partHandler, SLOT(gotButtonPressEvent(KisButtonPressEvent*)));
02754     connect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)),
02755             m_partHandler, SLOT(gotButtonReleaseEvent(KisButtonReleaseEvent*)));
02756     connect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
02757             m_partHandler, SLOT(gotMoveEvent(KisMoveEvent*)));
02758     connect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)),
02759             m_partHandler, SLOT(gotKeyPressEvent(QKeyEvent*)));
02760 
02761     connect(m_partHandler, SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
02762             this, SLOT(canvasGotMoveEvent(KisMoveEvent*)));
02763     connect(m_partHandler, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)),
02764             this, SLOT(canvasGotKeyPressEvent(QKeyEvent*)));
02765     connect(m_partHandler, SIGNAL(handlerDone()),
02766             this, SLOT(reconnectAfterPartInsert()));
02767 }
02768 
02769 void KisView::insertPart(const QRect& viewRect, const KoDocumentEntry& entry,
02770                          KisGroupLayerSP parent, KisLayerSP above) {
02771     KisImageSP img = currentImg();
02772     if (!img) return;
02773 
02774     KoDocument* doc = entry.createDoc(m_doc);
02775     if ( !doc )
02776         return;
02777 
02778     if ( !doc->showEmbedInitDialog(this) )
02779         return;
02780 
02781     QRect rect = viewToWindow(viewRect);
02782 
02783     KisChildDoc * childDoc = m_doc->createChildDoc(rect, doc);
02784 
02785     KisPartLayerImpl* partLayer = new KisPartLayerImpl(img, childDoc);
02786     partLayer->setDocType(entry.service()->genericName());
02787     img->addLayer(partLayer, parent, above);
02788     m_doc->setModified(true);
02789 
02790     reconnectAfterPartInsert();
02791 }
02792 
02793 void KisView::reconnectAfterPartInsert() {
02794     connect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)),
02795             this, SLOT(canvasGotButtonPressEvent(KisButtonPressEvent*)));
02796     connect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)),
02797             this, SLOT(canvasGotButtonReleaseEvent(KisButtonReleaseEvent*)));
02798     connect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)),
02799             this, SLOT(canvasGotMoveEvent(KisMoveEvent*)));
02800     connect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)),
02801             this, SLOT(canvasGotKeyPressEvent(QKeyEvent*)));
02802 
02803     delete m_partHandler;
02804     m_partHandler = 0;
02805 }
02806 
02807 void KisView::addAdjustmentLayer()
02808 {
02809     KisImageSP img = currentImg();
02810     if (!img) return;
02811 
02812     addAdjustmentLayer( img->activeLayer()->parent(), img->activeLayer() );
02813 }
02814 
02815 void KisView::addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above)
02816 {
02817     Q_ASSERT(parent);
02818     Q_ASSERT(above);
02819 
02820     KisImageSP img = currentImg();
02821     if (!img) return;
02822 
02823     KisLayerSP l = img->activeLayer();
02824 
02825     KisPaintDeviceSP dev;
02826 
02827     //  Argh! I hate having to cast, cast and cast again to see what kind of a layer I've got!
02828     KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(l.data());
02829     if (pl) {
02830         dev = pl->paintDevice();
02831     }
02832     else {
02833         KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(l.data());
02834         if (gl) {
02835             dev = gl->projection(img->bounds());
02836         }
02837         else {
02838             KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(l.data());
02839             if (al) {
02840                 dev = al->cachedPaintDevice();
02841             }
02842             else {
02843                 return;
02844             }
02845         }
02846     }
02847 
02848     KisDlgAdjustmentLayer dlg(img, img->nextLayerName(), i18n("New Adjustment Layer"), this, "dlgadjustmentlayer");
02849     if (dlg.exec() == QDialog::Accepted) {
02850         KisSelectionSP selection = 0;
02851         if (dev->hasSelection()) {
02852             selection = dev->selection();
02853         }
02854         KisFilterConfiguration * filter = dlg.filterConfiguration();
02855         QString name = dlg.layerName();
02856 
02857         addAdjustmentLayer( parent, above, name, filter, selection);
02858 
02859     }
02860 }
02861 
02862 void KisView::addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above, const QString & name,
02863                                  KisFilterConfiguration * filter, KisSelectionSP selection)
02864 {
02865     Q_ASSERT(parent);
02866     Q_ASSERT(above);
02867     Q_ASSERT(filter);
02868 
02869     KisImageSP img = currentImg();
02870     if (!img) return;
02871 
02872     KisAdjustmentLayer * l = new KisAdjustmentLayer(img, name, filter, selection);
02873     img->addLayer(l, parent, above);
02874 }
02875 
02876 void KisView::slotChildActivated(bool a) {
02877     // It should be so that the only part (child) we can activate, is the current layer:
02878     if (currentImg() && currentImg()->activeLayer())
02879     {
02880         if (a) {
02881             currentImg()->activeLayer()->activate();
02882         } else {
02883             currentImg()->activeLayer()->deactivate();
02884         }
02885     }
02886 
02887     super::slotChildActivated(a);
02888 }
02889 
02890 void KisView::layerRemove()
02891 {
02892     KisImageSP img = currentImg();
02893 
02894     if (img) {
02895         KisLayerSP layer = img->activeLayer();
02896 
02897         if (layer) {
02898 
02899 
02900             img->removeLayer(layer);
02901 
02902             if (layer->parent())
02903                 layer->parent()->setDirty(layer->extent());
02904 
02905             updateCanvas();
02906             layerUpdateGUI(img->activeLayer() != 0);
02907         }
02908     }
02909 }
02910 
02911 void KisView::layerDuplicate()
02912 {
02913     KisImageSP img = currentImg();
02914 
02915     if (!img)
02916         return;
02917 
02918     KisLayerSP active = img->activeLayer();
02919 
02920     if (!active)
02921         return;
02922 
02923     KisLayerSP dup = active->clone();
02924     dup->setName(QString(i18n("Duplicate of '%1'")).arg(active->name()));
02925     img->addLayer(dup, active->parent().data(), active);
02926     if (dup) {
02927         img->activate( dup );
02928         updateCanvas();
02929     } else {
02930         KMessageBox::error(this, i18n("Could not add layer to image."), i18n("Layer Error"));
02931     }
02932 }
02933 
02934 void KisView::layerRaise()
02935 {
02936     KisImageSP img = currentImg();
02937     KisLayerSP layer;
02938 
02939     if (!img)
02940         return;
02941 
02942     layer = img->activeLayer();
02943 
02944     img->raiseLayer(layer);
02945 }
02946 
02947 void KisView::layerLower()
02948 {
02949     KisImageSP img = currentImg();
02950     KisLayerSP layer;
02951 
02952     if (!img)
02953         return;
02954 
02955     layer = img->activeLayer();
02956 
02957     img->lowerLayer(layer);
02958 }
02959 
02960 void KisView::layerFront()
02961 {
02962     KisImageSP img = currentImg();
02963     KisLayerSP layer;
02964 
02965     if (!img)
02966         return;
02967 
02968     layer = img->activeLayer();
02969     img->toTop(layer);
02970 }
02971 
02972 void KisView::layerBack()
02973 {
02974     KisImageSP img = currentImg();
02975     if (!img) return;
02976 
02977     KisLayerSP layer;
02978 
02979     layer = img->activeLayer();
02980     img->toBottom(layer);
02981 }
02982 
02983 void KisView::layersUpdated()
02984 {
02985     KisImageSP img = currentImg();
02986     if (!img) return;
02987 
02988     KisLayerSP layer = img->activeLayer();
02989 
02990     layerUpdateGUI(img && layer);
02991 
02992     notifyObservers();
02993 }
02994 
02995 void KisView::layerToggleVisible()
02996 {
02997     KisImageSP img = currentImg();
02998     if (!img) return;
02999 
03000     KisLayerSP layer = img->activeLayer();
03001     if (!layer) return;
03002 
03003     layer->setVisible(!layer->visible());
03004 }
03005 
03006 void KisView::layerToggleLocked()
03007 {
03008     KisImageSP img = currentImg();
03009     if (!img) return;
03010 
03011     KisLayerSP layer = img->activeLayer();
03012     if (!layer) return;
03013 
03014     layer->setLocked(!layer->locked());
03015 }
03016 
03017 void KisView::actLayerVisChanged(int show)
03018 {
03019     m_actLayerVis = (show != 0);
03020 }
03021 
03022 bool KisView::activeLayerHasSelection()
03023 {
03024     return m_image && m_image->activeDevice() && m_image->activeDevice()->hasSelection();
03025 }
03026 
03027 void KisView::scrollH(int value)
03028 {
03029     m_hRuler->updateVisibleArea(value, 0);
03030 
03031     int xShift = m_scrollX - value;
03032     m_scrollX = value;
03033 
03034     if (m_canvas->isUpdatesEnabled()) {
03035         if (xShift > 0) {
03036 
03037             if (m_canvas->isOpenGLCanvas()) {
03038                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03039             } else {
03040                 QRect drawRect(0, 0, xShift, m_canvasPixmap.height());
03041 
03042                 bitBlt(&m_canvasPixmap, xShift, 0, &m_canvasPixmap, 0, 0, m_canvasPixmap.width() - xShift, m_canvasPixmap.height());
03043 
03044                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03045                 m_canvas->repaint();
03046             }
03047         } else if (xShift < 0) {
03048 
03049             QRect drawRect(m_canvasPixmap.width() + xShift, 0, -xShift, m_canvasPixmap.height());
03050 
03051             if (m_canvas->isOpenGLCanvas()) {
03052                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03053             } else {
03054                 bitBlt(&m_canvasPixmap, 0, 0, &m_canvasPixmap, -xShift, 0, m_canvasPixmap.width() + xShift, m_canvasPixmap.height());
03055 
03056                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03057                 m_canvas->repaint();
03058             }
03059         }
03060     }
03061 
03062     if (xShift != 0) {
03063         // XXX do sth with the childframe or so
03064     }
03065     emit viewTransformationsChanged();
03066 }
03067 
03068 void KisView::scrollV(int value)
03069 {
03070     m_vRuler->updateVisibleArea(0, value);
03071 
03072     int yShift = m_scrollY - value;
03073     m_scrollY = value;
03074 
03075     if (m_canvas->isUpdatesEnabled()) {
03076         if (yShift > 0) {
03077 
03078             if (m_canvas->isOpenGLCanvas()) {
03079                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03080             } else {
03081                 QRect drawRect(0, 0, m_canvasPixmap.width(), yShift);
03082 
03083                 bitBlt(&m_canvasPixmap, 0, yShift, &m_canvasPixmap, 0, 0, m_canvasPixmap.width(), m_canvasPixmap.height() - yShift);
03084 
03085                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03086                 m_canvas->repaint();
03087             }
03088         } else if (yShift < 0) {
03089 
03090             if (m_canvas->isOpenGLCanvas()) {
03091                 paintOpenGLView(QRect(0, 0, m_canvas->width(), m_canvas->height()));
03092             } else {
03093                 QRect drawRect(0, m_canvasPixmap.height() + yShift, m_canvasPixmap.width(), -yShift);
03094 
03095                 bitBlt(&m_canvasPixmap, 0, 0, &m_canvasPixmap, 0, -yShift, m_canvasPixmap.width(), m_canvasPixmap.height() + yShift);
03096 
03097                 updateQPaintDeviceCanvas(viewToWindow(drawRect));
03098                 m_canvas->repaint();
03099             }
03100         }
03101     }
03102 
03103     if (yShift != 0) {
03104         // XXX do sth with the childframe or so
03105     }
03106     emit viewTransformationsChanged();
03107 }
03108 
03109 void KisView::setupCanvas()
03110 {
03111     m_canvas = new KisCanvas(this, "kis_canvas");
03112     m_canvas->setFocusPolicy( QWidget::StrongFocus );
03113     QObject::connect(m_canvas, SIGNAL(sigGotButtonPressEvent(KisButtonPressEvent*)), this, SLOT(canvasGotButtonPressEvent(KisButtonPressEvent*)));
03114     QObject::connect(m_canvas, SIGNAL(sigGotButtonReleaseEvent(KisButtonReleaseEvent*)), this, SLOT(canvasGotButtonReleaseEvent(KisButtonReleaseEvent*)));
03115     QObject::connect(m_canvas, SIGNAL(sigGotDoubleClickEvent(KisDoubleClickEvent*)), this, SLOT(canvasGotDoubleClickEvent(KisDoubleClickEvent*)));
03116     QObject::connect(m_canvas, SIGNAL(sigGotMoveEvent(KisMoveEvent*)), this, SLOT(canvasGotMoveEvent(KisMoveEvent*)));
03117     QObject::connect(m_canvas, SIGNAL(sigGotPaintEvent(QPaintEvent*)), this, SLOT(canvasGotPaintEvent(QPaintEvent*)));
03118     QObject::connect(m_canvas, SIGNAL(sigGotEnterEvent(QEvent*)), this, SLOT(canvasGotEnterEvent(QEvent*)));
03119     QObject::connect(m_canvas, SIGNAL(sigGotLeaveEvent(QEvent*)), this, SLOT(canvasGotLeaveEvent(QEvent*)));
03120     QObject::connect(m_canvas, SIGNAL(sigGotMouseWheelEvent(QWheelEvent*)), this, SLOT(canvasGotMouseWheelEvent(QWheelEvent*)));
03121     QObject::connect(m_canvas, SIGNAL(sigGotKeyPressEvent(QKeyEvent*)), this, SLOT(canvasGotKeyPressEvent(QKeyEvent*)));
03122     QObject::connect(m_canvas, SIGNAL(sigGotKeyReleaseEvent(QKeyEvent*)), this, SLOT(canvasGotKeyReleaseEvent(QKeyEvent*)));
03123     QObject::connect(m_canvas, SIGNAL(sigGotDragEnterEvent(QDragEnterEvent*)), this, SLOT(canvasGotDragEnterEvent(QDragEnterEvent*)));
03124     QObject::connect(m_canvas, SIGNAL(sigGotDropEvent(QDropEvent*)), this, SLOT(canvasGotDropEvent(QDropEvent*)));
03125 }
03126 
03127 void KisView::connectCurrentImg()
03128 {
03129     if (m_image) {
03130         connect(m_image, SIGNAL(sigActiveSelectionChanged(KisImageSP)), m_selectionManager, SLOT(imgSelectionChanged(KisImageSP)));
03131         connect(m_image, SIGNAL(sigActiveSelectionChanged(KisImageSP)), this, SLOT(updateCanvas()));
03132         connect(m_image, SIGNAL(sigColorSpaceChanged(KisColorSpace *)), this, SLOT(updateStatusBarProfileLabel()));
03133         connect(m_image, SIGNAL(sigProfileChanged(KisProfile * )), SLOT(profileChanged(KisProfile * )));
03134 
03135         connect(m_image, SIGNAL(sigLayersChanged(KisGroupLayerSP)), SLOT(layersUpdated()));
03136         connect(m_image, SIGNAL(sigLayerAdded(KisLayerSP)), SLOT(layersUpdated()));
03137         connect(m_image, SIGNAL(sigLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), SLOT(layersUpdated()));
03138         connect(m_image, SIGNAL(sigLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), SLOT(layersUpdated()));
03139         connect(m_image, SIGNAL(sigLayerActivated(KisLayerSP)), SLOT(layersUpdated()));
03140         connect(m_image, SIGNAL(sigLayerActivated(KisLayerSP)), SLOT(updateCanvas()));
03141         connect(m_image, SIGNAL(sigLayerPropertiesChanged(KisLayerSP)), SLOT(layersUpdated()));
03142 
03143         KisConnectPartLayerVisitor v(m_image, this, true);
03144         m_image->rootLayer()->accept(v);
03145         connect(m_image, SIGNAL(sigLayerAdded(KisLayerSP)),
03146                 SLOT(handlePartLayerAdded(KisLayerSP)));
03147 
03148 #ifdef HAVE_GL
03149         if (m_OpenGLImageContext != 0) {
03150             connect(m_OpenGLImageContext, SIGNAL(sigImageUpdated(QRect)), SLOT(slotOpenGLImageUpdated(QRect)));
03151             connect(m_OpenGLImageContext, SIGNAL(sigSizeChanged(Q_INT32, Q_INT32)), SLOT(slotImageSizeChanged(Q_INT32, Q_INT32)));
03152         } else
03153 #endif
03154         {
03155             connect(m_image, SIGNAL(sigImageUpdated(QRect)), SLOT(imgUpdated(QRect)));
03156             connect(m_image, SIGNAL(sigSizeChanged(Q_INT32, Q_INT32)), SLOT(slotImageSizeChanged(Q_INT32, Q_INT32)));
03157         }
03158     }
03159 
03160     m_layerBox->setImage(m_image);
03161     m_birdEyeBox->setImage(m_image);
03162 }
03163 
03164 void KisView::disconnectCurrentImg()
03165 {
03166     if (m_image) {
03167         m_image->disconnect(this);
03168         m_layerBox->setImage(0);
03169         m_birdEyeBox->setImage(0);
03170 
03171         KisConnectPartLayerVisitor v(m_image, this, false);
03172         m_image->rootLayer()->accept(v);
03173     }
03174 
03175 #ifdef HAVE_GL
03176     if (m_OpenGLImageContext != 0) {
03177         m_OpenGLImageContext->disconnect(this);
03178     }
03179 #endif
03180 }
03181 
03182 void KisView::handlePartLayerAdded(KisLayerSP layer)
03183 {
03184     KisPartLayer* l = dynamic_cast<KisPartLayer*>(layer.data());
03185     if (!l)
03186         return;
03187 
03188     connect(this, SIGNAL(childActivated(KoDocumentChild*)),
03189             layer, SLOT(childActivated(KoDocumentChild*)));
03190 }
03191 
03192 void KisView::imgUpdated(QRect rc)
03193 {
03194     updateCanvas(rc);
03195 }
03196 
03197 void KisView::slotOpenGLImageUpdated(QRect rc)
03198 {
03199     paintOpenGLView(windowToView(rc));
03200 }
03201 
03202 void KisView::profileChanged(KisProfile *  /*profile*/)
03203 {
03204     updateStatusBarProfileLabel();
03205 }
03206 
03207 void KisView::slotImageSizeChanged(Q_INT32 /*w*/, Q_INT32 /*h*/)
03208 {
03209     resizeEvent(0);
03210     refreshKisCanvas();
03211 }
03212 
03213 void KisView::resizeCurrentImage(Q_INT32 w, Q_INT32 h, bool cropLayers)
03214 {
03215     if (!currentImg()) return;
03216 
03217     currentImg()->resize(w, h, cropLayers);
03218     m_doc->setModified(true);
03219     layersUpdated();
03220 }
03221 
03222 void KisView::scaleCurrentImage(double sx, double sy, KisFilterStrategy *filterStrategy)
03223 {
03224     if (!currentImg()) return;
03225     currentImg()->scale(sx, sy, m_progress, filterStrategy);
03226     m_doc->setModified(true);
03227     layersUpdated();
03228 }
03229 
03230 void KisView::rotateCurrentImage(double angle)
03231 {
03232     if (!currentImg()) return;
03233     currentImg()->rotate(angle, m_progress);
03234     m_doc->setModified(true);
03235     layersUpdated();
03236 }
03237 
03238 void KisView::shearCurrentImage(double angleX, double angleY)
03239 {
03240     if (!currentImg()) return;
03241     currentImg()->shear(angleX, angleY, m_progress);
03242     m_doc->setModified(true);
03243     layersUpdated();
03244 }
03245 
03246 
03247 QPoint KisView::viewToWindow(const QPoint& pt)
03248 {
03249     QPoint converted;
03250 
03251     converted.rx() = static_cast<int>((pt.x() + horzValue()) / zoom());
03252     converted.ry() = static_cast<int>((pt.y() + vertValue()) / zoom());
03253 
03254     return converted;
03255 }
03256 
03257 QPoint KisView::viewToWindow(const QPoint& pt) const
03258 {
03259     QPoint converted;
03260 
03261     converted.rx() = static_cast<int>((pt.x() + horzValue()) / zoom());
03262     converted.ry() = static_cast<int>((pt.y() + vertValue()) / zoom());
03263 
03264     return converted;
03265 }
03266 
03267 KisPoint KisView::viewToWindow(const KisPoint& pt)
03268 {
03269     KisPoint converted;
03270 
03271     converted.setX((pt.x() + horzValue()) / zoom());
03272     converted.setY((pt.y() + vertValue()) / zoom());
03273 
03274     return converted;
03275 }
03276 
03277 QRect KisView::viewToWindow(const QRect& rc)
03278 {
03279     QRect r;
03280 
03281     r.setTopLeft(viewToWindow(rc.topLeft()));
03282     r.setRight((int)(ceil((rc.right() + 1.0 + horzValue()) / zoom()) - 1));
03283     r.setBottom((int)(ceil((rc.bottom() + 1.0 + vertValue()) / zoom()) - 1));
03284 
03285     return r;
03286 }
03287 
03288 KisRect KisView::viewToWindow(const KisRect& rc)
03289 {
03290     KisRect r;
03291     KisPoint p = viewToWindow(KisPoint(rc.x(), rc.y()));
03292     r.setX(p.x());
03293     r.setY(p.y());
03294     r.setWidth(rc.width() / zoom());
03295     r.setHeight(rc.height() / zoom());
03296 
03297     return r;
03298 }
03299 
03300 void KisView::viewToWindow(Q_INT32 *x, Q_INT32 *y)
03301 {
03302     if (x && y) {
03303         QPoint p = viewToWindow(QPoint(*x, *y));
03304         *x = p.x();
03305         *y = p.y();
03306     }
03307 }
03308 
03309 QPoint KisView::windowToView(const QPoint& pt)
03310 {
03311     QPoint p;
03312     p.setX(static_cast<int>(pt.x() * zoom() - horzValue()));
03313     p.setY(static_cast<int>(pt.y() * zoom() - vertValue()));
03314 
03315     return p;
03316 }
03317 
03318 QPoint KisView::windowToView(const QPoint& pt) const
03319 {
03320     QPoint p;
03321     p.setX(static_cast<int>(pt.x() * zoom() - horzValue()));
03322     p.setY(static_cast<int>(pt.y() * zoom() - vertValue()));
03323 
03324     return p;
03325 }
03326 
03327 KisPoint KisView::windowToView(const KisPoint& pt)
03328 {
03329     KisPoint p;
03330     p.setX(pt.x() * zoom() - horzValue());
03331     p.setY(pt.y() * zoom() - vertValue());
03332 
03333     return p;
03334 }
03335 
03336 QRect KisView::windowToView(const QRect& rc)
03337 {
03338     QRect r;
03339 
03340     r.setTopLeft(windowToView(rc.topLeft()));
03341     r.setRight((int)(ceil((rc.right() + 1.0) * zoom()) - horzValue() - 1));
03342     r.setBottom((int)(ceil((rc.bottom() + 1.0) * zoom()) - vertValue() - 1));
03343 
03344     return r;
03345 }
03346 
03347 KisRect KisView::windowToView(const KisRect& rc)
03348 {
03349     KisRect r;
03350     KisPoint p = windowToView(KisPoint(rc.x(), rc.y()));
03351     r.setX(p.x());
03352     r.setY(p.y());
03353     r.setWidth(rc.width() * zoom());
03354     r.setHeight(rc.height() * zoom());
03355 
03356     return r;
03357 }
03358 
03359 void KisView::windowToView(Q_INT32 *x, Q_INT32 *y)
03360 {
03361     if (x && y) {
03362         QPoint p = windowToView(QPoint(*x, *y));
03363         *x = p.x();
03364         *y = p.y();
03365     }
03366 }
03367 
03368 void KisView::guiActivateEvent(KParts::GUIActivateEvent *event)
03369 {
03370     Q_ASSERT(event);
03371 
03372     if (event->activated()) {
03373 
03374         KStatusBar *sb = statusBar();
03375         if (sb) {
03376             sb->show();
03377         }
03378 
03379         if (!m_guiActivateEventReceived) {
03380             m_guiActivateEventReceived = true;
03381             startInitialZoomTimerIfReady();
03382         }
03383     }
03384 
03385     super::guiActivateEvent(event);
03386 }
03387 
03388 bool KisView::eventFilter(QObject *o, QEvent *e)
03389 {
03390     Q_ASSERT(o);
03391     Q_ASSERT(e);
03392 
03393     switch (e->type()) {
03394     case QEvent::TabletMove:
03395     case QEvent::TabletPress:
03396     case QEvent::TabletRelease:
03397     {
03398         QTabletEvent *te = static_cast<QTabletEvent *>(e);
03399         KisInputDevice device;
03400 
03401         switch (te->device()) {
03402         default:
03403         case QTabletEvent::Stylus:
03404         case QTabletEvent::NoDevice:
03405             device = KisInputDevice::stylus();
03406             break;
03407         case QTabletEvent::Puck:
03408             device = KisInputDevice::puck();
03409             break;
03410         case QTabletEvent::Eraser:
03411             device = KisInputDevice::eraser();
03412             break;
03413         }
03414 
03415         setInputDevice(device);
03416 
03417         // We ignore device change due to mouse events for a short duration
03418         // after a tablet event, since these are almost certainly mouse events
03419         // sent to receivers that don't accept the tablet event.
03420         m_tabletEventTimer.start();
03421         break;
03422     }
03423     case QEvent::MouseButtonPress:
03424     case QEvent::MouseMove:
03425     case QEvent::MouseButtonRelease:
03426     {
03427 #ifdef EXTENDED_X11_TABLET_SUPPORT
03428         KisInputDevice device = KisCanvasWidget::findActiveInputDevice();
03429 
03430         if (device != KisInputDevice::mouse()) {
03431             setInputDevice(device);
03432             m_tabletEventTimer.start();
03433         } else
03434 #endif
03435         {
03436             if (currentInputDevice() != KisInputDevice::mouse() && m_tabletEventTimer.elapsed() > MOUSE_CHANGE_EVENT_DELAY) {
03437                 setInputDevice(KisInputDevice::mouse());
03438             }
03439         }
03440         break;
03441     }
03442     case QEvent::KeyPress:
03443     case QEvent::KeyRelease:
03444     {
03445         if (m_canvas->cursorIsOverCanvas()) {
03446             m_canvas->handleKeyEvent(e);
03447             return true;
03448         }
03449         break;
03450     }
03451 #ifdef EXTENDED_X11_TABLET_SUPPORT
03452     case QEvent::ChildInserted:
03453     {
03454         QChildEvent *childEvent = static_cast<QChildEvent *>(e);
03455         QObject *child = childEvent->child();
03456 
03457         child->installEventFilter(this);
03458 
03459         QObjectList *objectList = child->queryList("QWidget");
03460         QObjectListIt it(*objectList);
03461         QObject *obj;
03462 
03463         while ((obj = it.current()) != 0) {
03464            obj->installEventFilter(this);
03465            ++it;
03466         }
03467 
03468         delete objectList;
03469     }
03470 #endif
03471     default:
03472         // Ignore
03473         break;
03474     }
03475 
03476 #if 0
03477     if ((o == m_hRuler || o == m_vRuler) && (e->type() == QEvent::MouseMove || e->type() == QEvent::MouseButtonRelease)) {
03478         QMouseEvent *me = dynamic_cast<QMouseEvent*>(e);
03479         QPoint pt = mapFromGlobal(me->globalPos());
03480         KisImageSP img = currentImg();
03481         KisGuideMgr *mgr;
03482 
03483         if (!img)
03484             return super::eventFilter(o, e);
03485 
03486         mgr = img->guides();
03487 
03488         if (e->type() == QEvent::MouseMove && (me->state() & Qt::LeftButton)) {
03489             bool flag = geometry().contains(pt);
03490             KisGuideSP gd;
03491 
03492             if (m_currentGuide == 0 && flag) {
03493                 // No guide is being edited and moving mouse over the canvas.
03494                 // Create a new guide.
03495                 enterEvent(0);
03496                 eraseGuides();
03497                 mgr->unselectAll();
03498 
03499                 if (o == m_vRuler)
03500                     gd = mgr->add((pt.x() - m_vRuler->width() + horzValue()) / zoom(), Qt::Vertical);
03501                 else
03502                     gd = mgr->add((pt.y() - m_hRuler->height() + vertValue()) / zoom(), Qt::Horizontal);
03503 
03504                 m_currentGuide = gd;
03505                 mgr->select(gd);
03506                 m_lastGuidePoint = mapToScreen(pt);
03507             } else if (m_currentGuide) {
03508                 if (flag) {
03509                     // moved an existing guide.
03510                     KisMoveEvent kme(currentInputDevice(), pt, me->globalPos(), PRESSURE_DEFAULT, 0, 0, me->state());
03511                     canvasGotMoveEvent(&kme);
03512                 } else {
03513                     //  moved a guide out of the frame, destroy it
03514                     leaveEvent(0);
03515                     eraseGuides();
03516                     mgr->remove(m_currentGuide);
03517                     paintGuides();
03518                     m_currentGuide = 0;
03519                 }
03520             }
03521         } else if (e->type() == QEvent::MouseButtonRelease && m_currentGuide) {
03522             eraseGuides();
03523             mgr->unselect(m_currentGuide);
03524             paintGuides();
03525             m_currentGuide = 0;
03526             enterEvent(0);
03527             KisMoveEvent kme(currentInputDevice(), pt, me->globalPos(), PRESSURE_DEFAULT, 0, 0, Qt::NoButton);
03528             canvasGotMoveEvent(&kme);
03529         }
03530     }
03531 #endif
03532 
03533     return super::eventFilter(o, e);
03534 }
03535 
03536 #if 0
03537 void KisView::eraseGuides()
03538 {
03539     KisImageSP img = currentImg();
03540 
03541     if (img) {
03542         KisGuideMgr *mgr = img->guides();
03543 
03544         if (mgr)
03545             mgr->erase(&m_canvasPixmap, this, horzValue(), vertValue(), zoom());
03546     }
03547 }
03548 
03549 void KisView::paintGuides()
03550 {
03551     KisImageSP img = currentImg();
03552 
03553     if (img) {
03554         KisGuideMgr *mgr = img->guides();
03555 
03556         if (mgr)
03557             mgr->paint(&m_canvasPixmap, this, horzValue(), vertValue(), zoom());
03558     }
03559 }
03560 
03561 void KisView::updateGuides()
03562 {
03563     eraseGuides();
03564     paintGuides();
03565 }
03566 #endif
03567 
03568 //void KisView::viewGuideLines()
03569 //{
03570 //}
03571 
03572 QPoint KisView::mapToScreen(const QPoint& pt)
03573 {
03574     QPoint converted;
03575 
03576     converted.rx() = pt.x() + horzValue();
03577     converted.ry() = pt.y() + vertValue();
03578     return converted;
03579 }
03580 
03581 void KisView::attach(KisCanvasObserver *observer)
03582 {
03583     Q_ASSERT(observer);
03584     if (observer)
03585         m_observers.push_back(observer);
03586 }
03587 
03588 void KisView::detach(KisCanvasObserver *observer)
03589 {
03590     Q_ASSERT(observer);
03591     if (observer) {
03592         vKisCanvasObserver_it it = std::find(m_observers.begin(), m_observers.end(), observer);
03593 
03594         if (it != m_observers.end())
03595             m_observers.erase(it);
03596     }
03597 }
03598 
03599 void KisView::notifyObservers()
03600 {
03601     for (vKisCanvasObserver_it it = m_observers.begin(); it != m_observers.end(); ++it) {
03602         (*it)->update(this);
03603     }
03604 }
03605 
03606 KisImageSP KisView::currentImg() const
03607 {
03608     return m_image;
03609 }
03610 
03611 void KisView::setCurrentImage(KisImageSP image)
03612 {
03613     if(!image) return;
03614 
03615     disconnectCurrentImg();
03616     m_image = image;
03617 
03618     KisConfig cfg;
03619 
03620 #ifdef HAVE_GL
03621     if (cfg.useOpenGL()) {
03622         m_OpenGLImageContext = KisOpenGLImageContext::getImageContext(image, monitorProfile());
03623         m_canvas->createOpenGLCanvas(m_OpenGLImageContext->sharedContextWidget());
03624     }
03625 #endif
03626     connectCurrentImg();
03627     m_layerBox->setImage(currentImg());
03628 
03629     zoomAroundPoint(0, 0, 1.0);
03630 
03631     if (!currentImg())
03632         layersUpdated();
03633 
03634     imgUpdateGUI();
03635 
03636     image->blockSignals(false);
03637 }
03638 
03639 KisColor KisView::bgColor() const
03640 {
03641     return m_bg;
03642 }
03643 
03644 KisColor KisView::fgColor() const
03645 {
03646     return m_fg;
03647 }
03648 
03649 KisBrush *KisView::currentBrush() const
03650 {
03651     return m_brush;
03652 }
03653 
03654 KisPattern *KisView::currentPattern() const
03655 {
03656     return m_pattern;
03657 }
03658 
03659 KisGradient *KisView::currentGradient() const
03660 {
03661     return m_gradient;
03662 }
03663 
03664 KisID KisView::currentPaintop() const
03665 {
03666     return m_paintop;
03667 }
03668 
03669 const KisPaintOpSettings *KisView::currentPaintopSettings() const
03670 {
03671     return m_paintopSettings;
03672 }
03673 
03674 double KisView::zoomFactor() const
03675 {
03676     return zoom();
03677 }
03678 
03679 KisUndoAdapter *KisView::undoAdapter() const
03680 {
03681     return m_adapter;
03682 }
03683 
03684 KisCanvasController *KisView::canvasController() const
03685 {
03686     return const_cast<KisCanvasController*>(static_cast<const KisCanvasController*>(this));
03687 }
03688 
03689 KisToolControllerInterface *KisView::toolController() const
03690 {
03691     return const_cast<KisToolControllerInterface*>(static_cast<const KisToolControllerInterface*>(m_toolManager));
03692 }
03693 
03694 KisDoc *KisView::document() const
03695 {
03696     return m_doc;
03697 }
03698 
03699 KisProgressDisplayInterface *KisView::progressDisplay() const
03700 {
03701     return m_progress;
03702 }
03703 
03704 QCursor KisView::setCanvasCursor(const QCursor & cursor)
03705 {
03706     QCursor oldCursor = m_canvas->cursor();
03707     QCursor newCursor;
03708 
03709     KisConfig cfg;
03710 
03711     switch (cfg.cursorStyle()) {
03712     case CURSOR_STYLE_TOOLICON:
03713         newCursor = cursor;
03714         break;
03715     case CURSOR_STYLE_CROSSHAIR:
03716         newCursor = KisCursor::crossCursor();
03717         break;
03718     case CURSOR_STYLE_POINTER:
03719         newCursor = KisCursor::arrowCursor();
03720         break;
03721     case CURSOR_STYLE_OUTLINE:
03722         newCursor = cursor;
03723         break;
03724     default:
03725         newCursor = cursor;
03726     }
03727 
03728     m_canvas->setCursor(newCursor);
03729     return oldCursor;
03730 }
03731 
03732 float KisView::HDRExposure() const
03733 {
03734     return m_HDRExposure;
03735 }
03736 
03737 void KisView::setHDRExposure(float exposure)
03738 {
03739     if (exposure != m_HDRExposure) {
03740         m_HDRExposure = exposure;
03741         notifyObservers();
03742         updateCanvas();
03743     }
03744 }
03745 
03746 void KisView::createDockers()
03747 {
03748 
03749     m_birdEyeBox = new KisBirdEyeBox(this);
03750     m_birdEyeBox->setCaption(i18n("Overview"));
03751     m_paletteManager->addWidget( m_birdEyeBox, "birdeyebox", krita::CONTROL_PALETTE);
03752 
03753     m_hsvwidget = new KoHSVWidget(this, "hsv");
03754     m_hsvwidget->setCaption(i18n("HSV"));
03755 
03756     connect(m_hsvwidget, SIGNAL(sigFgColorChanged(const QColor &)), this, SLOT(slotSetFGQColor(const QColor &)));
03757     connect(m_hsvwidget, SIGNAL(sigBgColorChanged(const QColor &)), this, SLOT(slotSetBGQColor(const QColor &)));
03758     connect(this, SIGNAL(sigFGQColorChanged(const QColor &)), m_hsvwidget, SLOT(setFgColor(const QColor &)));
03759     connect(this, SIGNAL(sigBGQColorChanged(const QColor &)), m_hsvwidget, SLOT(setBgColor(const QColor &)));
03760     m_paletteManager->addWidget( m_hsvwidget, "hsvwidget", krita::COLORBOX, 0, PALETTE_DOCKER, true);
03761 
03762     m_rgbwidget = new KoRGBWidget(this, "rgb");
03763     m_rgbwidget->setCaption(i18n("RGB"));
03764     connect(m_rgbwidget, SIGNAL(sigFgColorChanged(const QColor &)), this, SLOT(slotSetFGQColor(const QColor &)));
03765     connect(m_rgbwidget, SIGNAL(sigBgColorChanged(const QColor &)), this, SLOT(slotSetBGQColor(const QColor &)));
03766     connect(this, SIGNAL(sigFGQColorChanged(const QColor &)), m_rgbwidget, SLOT(setFgColor(const QColor &)));
03767     connect(this, SIGNAL(sigBGQColorChanged(const QColor &)), m_rgbwidget, SLOT(setBgColor(const QColor &)));
03768     m_paletteManager->addWidget( m_rgbwidget, "rgbwidget", krita::COLORBOX);
03769 
03770     m_graywidget = new KoGrayWidget(this, "gray");
03771     m_graywidget->setCaption(i18n("Gray"));
03772     connect(m_graywidget, SIGNAL(sigFgColorChanged(const QColor &)), this, SLOT(slotSetFGQColor(const QColor &)));
03773     connect(m_graywidget, SIGNAL(sigBgColorChanged(const QColor &)), this, SLOT(slotSetBGQColor(const QColor &)));
03774     connect(this, SIGNAL(sigFGQColorChanged(const QColor &)), m_graywidget, SLOT(setFgColor(const QColor &)));
03775     connect(this, SIGNAL(sigBGQColorChanged(const QColor &)), m_graywidget, SLOT(setBgColor(const QColor &)));
03776     m_paletteManager->addWidget( m_graywidget, "graywidget", krita::COLORBOX);
03777 
03778     //make sure the color chooser get right default values
03779     emit sigFGQColorChanged(m_fg.toQColor());
03780     emit sigBGQColorChanged(m_bg.toQColor());
03781 
03782     m_palettewidget = new KisPaletteWidget(this);
03783     m_palettewidget->setCaption(i18n("Palettes"));
03784     connect(m_palettewidget, SIGNAL(colorSelected(const QColor &)),
03785             this, SLOT(slotSetFGQColor(const QColor &)));
03786     // No BGColor or reverse slotFGChanged->palette connections, since that's not useful here
03787 
03788     KisResourceServerBase* rServer;
03789     rServer = KisResourceServerRegistry::instance()->get("PaletteServer");
03790     QValueList<KisResource*> resources = rServer->resources();
03791     QValueList<KisResource*>::iterator it;
03792     for ( it = resources.begin(); it != resources.end(); ++it ) {
03793         m_palettewidget->slotAddPalette( *it );
03794     }
03795     connect(m_palettewidget, SIGNAL(colorSelected(const KisColor &)), this, SLOT(slotSetFGColor(const KisColor &)));
03796     m_paletteManager->addWidget( m_palettewidget, "palettewidget", krita::COLORBOX, 10, PALETTE_DOCKER, true);
03797 }
03798 
03799 QPoint KisView::applyViewTransformations(const QPoint& p) const {
03800     QPoint point(windowToView(p));
03801 
03802     if (m_hRuler->isShown())
03803         point.ry() += m_hRuler->height();
03804     if (m_vRuler -> isShown())
03805         point.rx() += m_vRuler->width();
03806 
03807     return point;
03808 }
03809 
03810 QPoint KisView::reverseViewTransformations(const QPoint& p) const {
03811     // Since we now zoom ourselves, the only thing super::~ does is nothing anymore.
03812     // Hence, zoom ourselves, like super would
03813     // viewToWindow doesn't take the rulers into account, do that ourselves
03814     QPoint point(p);
03815     if (m_hRuler -> isShown())
03816         point.ry() -= m_hRuler -> height();
03817     if (m_vRuler -> isShown())
03818         point.rx() -= m_vRuler -> width();
03819 
03820     return viewToWindow(point);
03821 }
03822 
03823 void KisView::canvasAddChild(KoViewChild *child) {
03824     super::canvasAddChild(child);
03825     connect(this, SIGNAL(viewTransformationsChanged()), child, SLOT(reposition()));
03826     m_vScroll->raise();
03827     m_hScroll->raise();
03828     m_vScroll->raise();
03829     m_hRuler->raise();
03830     m_vRuler->raise();
03831 }
03832 
03833 void KisView::slotLoadingFinished()
03834 {
03835     // Set the current image for real now everything is ready to go.
03836     setCurrentImage(document()->currentImage());
03837     m_paletteManager->showWidget( "layerbox" );
03838     m_canvas->show();
03839     disconnect(document(), SIGNAL(loadingFinished()), this, SLOT(slotLoadingFinished()));
03840 
03841     m_imageLoaded = true;
03842     startInitialZoomTimerIfReady();
03843 }
03844 
03845 void KisView::startInitialZoomTimerIfReady()
03846 {
03847     if (m_imageLoaded && m_showEventReceived && m_guiActivateEventReceived) {
03848         m_initialZoomTimer.start(250, true);
03849     }
03850 }
03851 
03852 void KisView::slotInitialZoomTimeout()
03853 {
03854     Q_ASSERT(!m_paintViewEnabled);
03855 
03856     m_paintViewEnabled = true;
03857     setInitialZoomLevel();
03858 }
03859 
03860 #include "kis_view.moc"
03861 
KDE Home | KDE Accessibility Home | Description of Access Keys