From kde-commits Mon Mar 31 20:57:05 2014 From: Shivaraman Aiyer Date: Mon, 31 Mar 2014 20:57:05 +0000 To: kde-commits Subject: [calligra/krita-perspective_drawing-shivaraman] /: PerspectiveGridNg tool: Krita Crashes when adding Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=139629943915962 Git commit 93f40475e0003e2586b8c1255c2b26695a898d9a by Shivaraman Aiyer. Committed on 31/03/2014 at 20:44. Pushed by aiyer into branch 'krita-perspective_drawing-shivaraman'. PerspectiveGridNg tool: Krita Crashes when adding a new PerspectiveGridNg, = need to ask for the reason as unable to find it. M +579 -3 CMakeLists.txt.user M +1 -1 krita/plugins/tools/tool_perspectivegridng/CMakeLists.txt M +20 -15 krita/plugins/tools/tool_perspectivegridng/kis_tool_perspect= ivegridng.cc M +2 -1 krita/plugins/tools/tool_perspectivegridng/kis_tool_perspect= ivegridng.h D +0 -45 krita/plugins/tools/tool_perspectivegridng/kritatoolperspect= ivegrid.desktop A +7 -0 krita/plugins/tools/tool_perspectivegridng/kritatoolperspect= ivegridng.desktop M +1 -1 krita/plugins/tools/tool_perspectivegridng/tool_perspectiveg= ridng.cc M +2 -1 krita/ui/kis_perspective_grid_managerng.cpp M +307 -33 krita/ui/kis_perspective_gridng.cpp M +26 -10 krita/ui/kis_perspective_gridng.h M +7 -0 krita/ui/kis_view2.cpp http://commits.kde.org/calligra/93f40475e0003e2586b8c1255c2b26695a898d9a diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 6883295..6c8107b 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -35478,7 +35478,7 @@ false - -1 + 2 TestKoTableColumnAndRowStyleManager TestKoTableColumnAndRowStyleManager61 @@ -35490,6 +35490,390 @@ false true<= /value> + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager62 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager63 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager64 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager65 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager66 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager67 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager68 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager69 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + true @@ -35538,6 +35922,198 @@ false true<= /value> + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager70 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager71 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + 2 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager72 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + + + true + + false + false + false + false + true + 0.01 + 10 + tr= ue + 25 + + true + v= algrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + TestKoTableColumnAndRowStyleManager + + false + + -1 + + TestKoTableColumnAndRowStyleManager + TestKoTableColumnAndRowStyleManager73 + CMakeProjectManager.CMakeRunConfiguration.TestKoTableColumnAndRowStyleMan= ager + 3768<= /value> + false + true<= /value> + false + false + true<= /value> + true @@ -36690,7 +37266,7 @@ false true<= /value> - 762 + 774 diff --git a/krita/plugins/tools/tool_perspectivegridng/CMakeLists.txt b/kr= ita/plugins/tools/tool_perspectivegridng/CMakeLists.txt index f5f0c15..a6befa0 100644 --- a/krita/plugins/tools/tool_perspectivegridng/CMakeLists.txt +++ b/krita/plugins/tools/tool_perspectivegridng/CMakeLists.txt @@ -9,7 +9,7 @@ kde4_add_ui_files(kritatoolperspectivegridng_PART_SRCS Pers= pectiveGridNgToolOpti = kde4_add_plugin(kritatoolperspectivegridng ${kritatoolperspectivegridng_PA= RT_SRCS}) = -target_link_libraries(kritatoolperspectivegridng kritaui flake ${KDE4_KPAR= TS_LIBS} ${KDE4_KDEUI_LIBS} ) +target_link_libraries(kritatoolperspectivegridng kritaui ) = install(TARGETS kritatoolperspectivegridng DESTINATION ${PLUGIN_INSTALL_D= IR}) = diff --git a/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspectiv= egridng.cc b/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspectiv= egridng.cc index e640570..ec60c28 100644 --- a/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspectivegridng= .cc +++ b/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspectivegridng= .cc @@ -49,6 +49,7 @@ KisPerspectiveGridNgTool::KisPerspectiveGridNgTool(KoCanv= asBase * canvas) { Q_ASSERT(m_canvas); setObjectName("tool_perspectivegridng"); + qDebug()<<"Shiva: " << "KisPerspectiveGridNgTool"; } = KisPerspectiveGridNgTool::~KisPerspectiveGridNgTool() @@ -62,6 +63,7 @@ QPointF adjustPointF(const QPointF& _pt, const QRectF& _r= c) = void KisPerspectiveGridNgTool::activate(ToolActivation toolActivation, con= st QSet &shapes) { + qDebug()<<"Activating tool"; // Add code here to initialize your tool when it got activated KisTool::activate(toolActivation, shapes); = @@ -106,12 +108,14 @@ inline double norm2(const QPointF& p) = void KisPerspectiveGridNgTool::mousePressEvent(KoPointerEvent *event) { + qDebug()<<"Pressed button"; if(PRESS_CONDITION_OM(event, KisTool::HOVER_MODE, Qt::LeftButton, Qt::ShiftModifier)) { = setMode(KisTool::PAINT_MODE); = if (m_newAssistant) { + qDebug()<<"New Assistant Creation " << m_newAssistant ; m_internalMode =3D MODE_CREATION; *m_newAssistant->handles().back() =3D event->point; if (m_newAssistant->handles().size() =3D=3D m_newAssistant->nu= mHandles()) { @@ -248,8 +252,9 @@ void KisPerspectiveGridNgTool::mousePressEvent(KoPointe= rEvent *event) } } = - QString key =3D 0;//m_options.comboBox->model()->index( m_options.= comboBox->currentIndex(), 0 ).data(Qt::UserRole).toString(); - m_newAssistant =3D KisPerspectiveGridNgFactoryRegistry::instan= ce()->get(0)->createPerspectiveGridNg(); +// QString key =3D m_options.comboBox->model()->index( m_options.co= mboBox->currentIndex(), 0 ).data(Qt::UserRole).toString(); +// m_newAssistant =3D KisPerspectiveGridNgFactoryRegistry::inst= ance()->get(key)->createPerspectiveGridNg(); + m_newAssistant =3D KisPerspectiveGridNgFactoryRegistry::instance()= ->get("perspectivegridng")->createPerspectiveGridNg(); m_internalMode =3D MODE_CREATION; m_newAssistant->addHandle(new KisPerspectiveGridNgHandle(event= ->point)); if (m_newAssistant->numHandles() <=3D 1) { @@ -268,20 +273,20 @@ void KisPerspectiveGridNgTool::addAssistant() { m_canvas->view()->perspectiveGridNgManager()->addAssistant(m_newAssist= ant); m_handles =3D m_canvas->view()->perspectiveGridNgManager()->handles(); -// KisAbstractPerspectiveGrid* grid =3D dynamic_cast(m_newAssistant); -// if (grid) { -// m_canvas->view()->resourceProvider()->addPerspectiveGrid(grid); -// } + KisAbstractPerspectiveGrid* grid =3D dynamic_cast(m_newAssistant); + if (grid) { + m_canvas->view()->resourceProvider()->addPerspectiveGrid(grid); + } m_newAssistant =3D 0; } = = void KisPerspectiveGridNgTool::removeAssistant(KisPerspectiveGridNg* assis= tant) { -// KisAbstractPerspectiveGrid* grid =3D dynamic_cast(assistant); -// if (grid) { -// m_canvas->view()->resourceProvider()->removePerspectiveGrid(grid= ); -// } + KisAbstractPerspectiveGrid* grid =3D dynamic_cast(assistant); + if (grid) { + m_canvas->view()->resourceProvider()->removePerspectiveGrid(grid); + } m_canvas->view()->perspectiveGridNgManager()->removeAssistant(assistan= t); m_handles =3D m_canvas->view()->perspectiveGridNgManager()->handles(); } @@ -400,7 +405,7 @@ void KisPerspectiveGridNgTool::paint(QPainter& _gc, con= st KoViewConverter &_conv = foreach(const KisPerspectiveGridNgHandleSP handle, m_handles) { QRectF ellipse(_converter.documentToView(*handle) - QPointF(6, 6)= , QSizeF(12, 12)); - if (handle =3D=3D m_handleDrag || handle =3D=3D m_handleCombine) { + if (handle =3D=3D m_handleDrag /*|| handle =3D=3D m_handleCombine*= /) { _gc.save(); _gc.setPen(Qt::transparent); _gc.setBrush(handlesColor); @@ -554,10 +559,10 @@ void KisPerspectiveGridNgTool::openFinish(KJob* job) if (assistant) { if (assistant->handles().size() =3D=3D assistant->numH= andles()) { m_canvas->view()->perspectiveGridNgManager()->addA= ssistant(assistant); -// KisAbstractPerspectiveGrid* grid =3D dynamic_cas= t(assistant); -// if (grid) { -// m_canvas->view()->resourceProvider()->addPer= spectiveGrid(grid); -// } + KisAbstractPerspectiveGrid* grid =3D dynamic_cast<= KisAbstractPerspectiveGrid*>(assistant); + if (grid) { + m_canvas->view()->resourceProvider()->addPersp= ectiveGrid(grid); + } } else { errors =3D true; delete assistant; diff --git a/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspectiv= egridng.h b/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspective= gridng.h index 4122a3e..a469498 100644 --- a/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspectivegridng= .h +++ b/krita/plugins/tools/tool_perspectivegridng/kis_tool_perspectivegridng= .h @@ -75,7 +75,7 @@ protected: = protected: KisCanvas2* m_canvas; - QList m_handles, m_sideHandles; + QList m_handles, m_sideHandles,m_perspec= tiveHandles; KisPerspectiveGridNgHandleSP m_handleDrag; KisPerspectiveGridNgHandleSP m_handleCombine; KisPerspectiveGridNg* m_assistantDrag; @@ -97,6 +97,7 @@ class KisPerspectiveGridNgToolFactory : public KoToolFact= oryBase public: KisPerspectiveGridNgToolFactory() : KoToolFactoryBase("KisPerspectiveGridNgTool") { + qDebug()<<"Shiva: " << "KisPerspectiveGridNgToolFactory"; setToolTip(i18n("Perspective Grid Editor")); setToolType(TOOL_TYPE_VIEW); setIconName(koIconNameCStr("krita_tool_perspectivegridng")); diff --git a/krita/plugins/tools/tool_perspectivegridng/kritatoolperspectiv= egrid.desktop b/krita/plugins/tools/tool_perspectivegridng/kritatoolperspec= tivegrid.desktop deleted file mode 100644 index 76f47d1..0000000 --- a/krita/plugins/tools/tool_perspectivegridng/kritatoolperspectivegrid.d= esktop +++ /dev/null @@ -1,45 +0,0 @@ -[Desktop Entry] -Name=3DPerspective Grid Tool -Name[bg]=3D=D0=98=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BC=D0=B5=D0=BD=D1=82 = =D0=BF=D0=B5=D1=80=D1=81=D0=BF=D0=B5=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D0=B0 = =D0=BC=D1=80=D0=B5=D0=B6=D0=B0 -Name[bs]=3DAlati za perspektivnu mre=C5=BEu -Name[ca]=3DEina de graella de perspectiva -Name[ca@valencia]=3DEina de graella de perspectiva -Name[da]=3DPerspektivgitterv=C3=A6rkt=C3=B8j -Name[de]=3DPerspektive-Raster-Werkzeug -Name[el]=3D=CE=95=CF=81=CE=B3=CE=B1=CE=BB=CE=B5=CE=AF=CE=BF =CF=80=CF=81= =CE=BF=CE=BF=CF=80=CF=84=CE=B9=CE=BA=CE=BF=CF=8D =CE=BA=CE=B1=CE=BD=CE=BD= =CE=AC=CE=B2=CE=BF=CF=85 -Name[en_GB]=3DPerspective Grid Tool -Name[eo]=3DPerspektivkrado-ilo -Name[es]=3DHerramienta de cuadr=C3=ADcula en perspectiva -Name[et]=3DPerspektiivv=C3=B5rgu t=C3=B6=C3=B6riist -Name[fa]=3D=D8=A7=D8=A8=D8=B2=D8=A7=D8=B1 =D8=AA=D9=88=D8=B1=DB=8C =D8=A8= =D9=8F=D8=B9=D8=AF=D9=86=D9=85=D8=A7 -Name[fi]=3DPerspektiiviruudukko -Name[fr]=3DOutils de de grille en perspective -Name[fy]=3DPerspektive magnetyskfjild ark -Name[gl]=3DFerramenta de grade de perspectiva -Name[hi]=3D=E0=A4=AA=E0=A4=B0=E0=A5=8D=E0=A4=B8=E0=A4=AA=E0=A5=87=E0=A4=95= =E0=A5=8D=E0=A4=9F=E0=A4=BF=E0=A4=B5 =E0=A4=97=E0=A5=8D=E0=A4=B0=E0=A4=BF= =E0=A4=A1 =E0=A4=94=E0=A4=9C=E0=A4=BC=E0=A4=BE=E0=A4=B0 -Name[hne]=3D=E0=A4=AA=E0=A4=B0=E0=A5=8D=E0=A4=B8=E0=A4=AA=E0=A5=87=E0=A4= =95=E0=A5=8D=E0=A4=9F=E0=A4=BF=E0=A4=B5 =E0=A4=97=E0=A5=8D=E0=A4=B0=E0=A4= =BF=E0=A4=A1 =E0=A4=94=E0=A4=9C=E0=A4=BE=E0=A4=B0 -Name[hu]=3DPerspekt=C3=ADvar=C3=A1cs -Name[it]=3DStrumento di reticolo prospettico -Name[ja]=3D=E9=81=A0=E8=BF=91=E6=B3=95=E3=82=B0=E3=83=AA=E3=83=83=E3=83=89= =E3=83=84=E3=83=BC=E3=83=AB -Name[kk]=3D=D0=9F=D0=B5=D1=80=D1=81=D0=BF=D0=B5=D0=BA=D1=82=D0=B8=D0=B2=D0= =B0=D0=BD=D1=8B =D0=B1=D0=B0=D2=93=D1=8B=D1=82=D1=82=D0=B0=D1=83 =D2=9B=D2= =B1=D1=80=D0=B0=D0=BB=D1=8B -Name[lv]=3DPerspekt=C4=ABvas re=C5=BE=C4=A3a r=C4=ABks -Name[nb]=3DPerspektivnett-verkt=C3=B8y -Name[nds]=3DKiekwinkelgadder-Warkt=C3=BC=C3=BCch -Name[ne]=3D=E0=A4=A6=E0=A5=83=E0=A4=B6=E0=A5=8D=E0=A4=AF=E0=A4=BE=E0=A4=A4= =E0=A5=8D=E0=A4=AE=E0=A4=95 =E0=A4=97=E0=A5=8D=E0=A4=B0=E0=A5=80=E0=A4=A1 = =E0=A4=89=E0=A4=AA=E0=A4=95=E0=A4=B0=E0=A4=A3 -Name[nl]=3DPerspectiefraster-gereedschap -Name[pl]=3DNarz=C4=99dzie siatki perspektywy -Name[pt]=3DFerramenta de Grelha em Perspectiva -Name[pt_BR]=3DFerramenta de Grade em Perspectiva -Name[ru]=3D=D0=9F=D0=B5=D1=80=D1=81=D0=BF=D0=B5=D0=BA=D1=82=D0=B8=D0=B2=D0= =B0 -Name[sk]=3DPerspekt=C3=ADvna mrie=C5=BEka -Name[sl]=3DOrodja Mre=C5=BEa za perspektivo -Name[sv]=3DPerspektivrutn=C3=A4tsverktyg -Name[tr]=3DPerspektif Izgara Arac=C4=B1 -Name[uk]=3D=D0=97=D0=B0=D1=81=D1=96=D0=B1 =D2=91=D1=80=D0=B0=D1=82=D0=BA= =D0=B8 =D0=BF=D0=B5=D1=80=D1=81=D0=BF=D0=B5=D0=BA=D1=82=D0=B8=D0=B2=D0=B8 -Name[wa]=3DUsteye di grile di pespective -Name[x-test]=3DxxPerspective Grid Toolxx -Name[zh_TW]=3D=E9=80=8F=E8=A6=96=E6=A0=BC=E5=B7=A5=E5=85=B7 -X-KDE-ServiceTypes=3DKrita/Tool -Type=3DService -X-KDE-Library=3Dkritatoolperspectivegrid -X-Krita-Version=3D28 diff --git a/krita/plugins/tools/tool_perspectivegridng/kritatoolperspectiv= egridng.desktop b/krita/plugins/tools/tool_perspectivegridng/kritatoolpersp= ectivegridng.desktop new file mode 100644 index 0000000..2679439 --- /dev/null +++ b/krita/plugins/tools/tool_perspectivegridng/kritatoolperspectivegridng= .desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=3DPerspective GridNg Tool +X-KDE-ServiceTypes=3DKrita/Tool +Type=3DService +X-KDE-Library=3Dkritatoolperspectivegridng +X-Krita-Version=3D28 +Name[en]=3DPerspective GridNg Tool diff --git a/krita/plugins/tools/tool_perspectivegridng/tool_perspectivegri= dng.cc b/krita/plugins/tools/tool_perspectivegridng/tool_perspectivegridng.= cc index c5ceb30..65644e5 100644 --- a/krita/plugins/tools/tool_perspectivegridng/tool_perspectivegridng.cc +++ b/krita/plugins/tools/tool_perspectivegridng/tool_perspectivegridng.cc @@ -35,7 +35,7 @@ KisPerspectiveGridNgToolPlugin::KisPerspectiveGridNgToolP= lugin(QObject *parent, { KoToolRegistry * r =3D KoToolRegistry::instance(); r->add(new KisPerspectiveGridNgToolFactory()); - +// qDebug()<<"Shiva: " << "KisPerspectiveGridNgToolPlugin"; // KisPerspectiveGridNgFactoryRegistry::instance()->add(new RulerAssist= antFactory); // KisPerspectiveGridNgFactoryRegistry::instance()->add(new EllipseAssi= stantFactory); // KisPerspectiveGridNgFactoryRegistry::instance()->add(new SplineAssis= tantFactory); diff --git a/krita/ui/kis_perspective_grid_managerng.cpp b/krita/ui/kis_per= spective_grid_managerng.cpp index 456cca2..9a68418 100644 --- a/krita/ui/kis_perspective_grid_managerng.cpp +++ b/krita/ui/kis_perspective_grid_managerng.cpp @@ -38,9 +38,10 @@ struct KisPerspectiveGridNgManager::Private { }; = KisPerspectiveGridNgManager::KisPerspectiveGridNgManager(KisView2* parent)= : - KisCanvasDecoration("paintingAssistantsManager", i18n("Painting as= sistants"), parent), + KisCanvasDecoration("perspectiveGridNgManager", i18n("Perspective = GridNg"), parent), d(new Private) { + qDebug() << "Shiva --> KisPerspectiveGridNgManager"; } = KisPerspectiveGridNgManager::~KisPerspectiveGridNgManager() diff --git a/krita/ui/kis_perspective_gridng.cpp b/krita/ui/kis_perspective= _gridng.cpp index 9e5f881..97cc8e9 100644 --- a/krita/ui/kis_perspective_gridng.cpp +++ b/krita/ui/kis_perspective_gridng.cpp @@ -30,11 +30,25 @@ #include #include = +#include +#include + struct KisPerspectiveGridNgHandle::Private { QList assistants; char handle_type; }; = +// squared distance from a point to a line +inline qreal distsqr(const QPointF& pt, const QLineF& line) +{ + // distance =3D |(p2 - p1) x (p1 - pt)| / |p2 - p1| + + // magnitude of (p2 - p1) x (p1 - pt) + const qreal cross =3D (line.dx() * (line.y1() - pt.y()) - line.dy() * = (line.x1() - pt.x())); + + return cross * cross / (line.dx() * line.dx() + line.dy() * line.dy()); +} + KisPerspectiveGridNgHandle::KisPerspectiveGridNgHandle(double x, double y)= : QPointF(x, y), d(new Private) { } @@ -58,7 +72,7 @@ KisPerspectiveGridNgHandle& KisPerspectiveGridNgHandle::o= perator=3D(const QPointF = void KisPerspectiveGridNgHandle::setType(char type) { - d->handle_type =3D type; +// d->handle_type =3D type; } = char KisPerspectiveGridNgHandle::handleType() @@ -69,20 +83,20 @@ char KisPerspectiveGridNgHandle::handleType() = KisPerspectiveGridNgHandle::~KisPerspectiveGridNgHandle() { - Q_ASSERT(d->assistants.empty()); - delete d; +// Q_ASSERT(d->assistants.empty()); +// delete d; } = void KisPerspectiveGridNgHandle::registerAssistant(KisPerspectiveGridNg* a= ssistant) { - Q_ASSERT(!d->assistants.contains(assistant)); - d->assistants.append(assistant); +// Q_ASSERT(!d->assistants.contains(assistant)); +// d->assistants.append(assistant); } = void KisPerspectiveGridNgHandle::unregisterAssistant(KisPerspectiveGridNg*= assistant) { - d->assistants.removeOne(assistant); - Q_ASSERT(!d->assistants.contains(assistant)); +// d->assistants.removeOne(assistant); +// Q_ASSERT(!d->assistants.contains(assistant)); } = bool KisPerspectiveGridNgHandle::containsAssistant(KisPerspectiveGridNg* a= ssistant) @@ -92,31 +106,31 @@ bool KisPerspectiveGridNgHandle::containsAssistant(Kis= PerspectiveGridNg* assista = void KisPerspectiveGridNgHandle::mergeWith(KisPerspectiveGridNgHandleSP ha= ndle) { - if(this->handleType()=3D=3D'S' || handle.data()->handleType()=3D=3D 'S= ') - return; - foreach(KisPerspectiveGridNg* assistant, handle->d->assistants) { - if (!assistant->handles().contains(this)) { - assistant->replaceHandle(handle, this); - } - } +// if(this->handleType()=3D=3D'S' || handle.data()->handleType()=3D=3D = 'S') +// return; +// foreach(KisPerspectiveGridNg* assistant, handle->d->assistants) { +// if (!assistant->handles().contains(this)) { +// assistant->replaceHandle(handle, this); +// } +// } } = QList KisPerspectiveGridNgHandle::split() { QList newHandles; - foreach(KisPerspectiveGridNg* assistant, d->assistants) { - KisPerspectiveGridNgHandleSP newHandle(new KisPerspectiveGridNgHan= dle(*this)); - newHandles.append(newHandle); - assistant->replaceHandle(this, newHandle); - } +// foreach(KisPerspectiveGridNg* assistant, d->assistants) { +// KisPerspectiveGridNgHandleSP newHandle(new KisPerspectiveGridNgH= andle(*this)); +// newHandles.append(newHandle); +// assistant->replaceHandle(this, newHandle); +// } return newHandles; } = void KisPerspectiveGridNgHandle::uncache() { - foreach(KisPerspectiveGridNg* assistant, d->assistants) { - assistant->uncache(); - } +// foreach(KisPerspectiveGridNg* assistant, d->assistants) { +// assistant->uncache(); +// } } = = @@ -137,6 +151,11 @@ struct KisPerspectiveGridNg::Private { } cachedTransform; }; = +KisPerspectiveGridNg::KisPerspectiveGridNg() + : KisPerspectiveGridNg("perspectivegridng", i18n("Perspective Grid= Ng")) +{ +} + KisPerspectiveGridNg::KisPerspectiveGridNg(const QString& id, const QStrin= g& name) : d(new Private) { d->id =3D id; @@ -145,18 +164,65 @@ KisPerspectiveGridNg::KisPerspectiveGridNg(const QStr= ing& id, const QString& nam = void KisPerspectiveGridNg::drawPath(QPainter& painter, const QPainterPath = &path) { - painter.save(); - QPen pen_a(QColor(0, 0, 0, 100), 2); - pen_a.setCosmetic(true); - painter.setPen(pen_a); - painter.drawPath(path); - QPen pen_b(Qt::white, 0.9); - pen_b.setCosmetic(true); - painter.setPen(pen_b); - painter.drawPath(path); - painter.restore(); +// painter.save(); +// QPen pen_a(QColor(0, 0, 0, 100), 2); +// pen_a.setCosmetic(true); +// painter.setPen(pen_a); +// painter.drawPath(path); +// QPen pen_b(Qt::white, 0.9); +// pen_b.setCosmetic(true); +// painter.setPen(pen_b); +// painter.drawPath(path); +// painter.restore(); +} + +//qreal KisPerspectiveGridNg::distance(const QPointF& pt) const +//{ +// QPolygonF poly; +// QTransform transform; +// if (!getTransform(poly, transform)) return 1.0; +// bool invertible; +// QTransform inverse =3D transform.inverted(&invertible); +// if (!invertible) return 1.0; +// if (inverse.m13() * pt.x() + inverse.m23() * pt.y() + inverse.m33() = =3D=3D 0.0) { +// // point at infinity +// return 0.0; +// } +// return localScale(transform, inverse.map(pt)) * inverseMaxLocalScale= (transform); +//} + +bool KisPerspectiveGridNg::getTransform(QPolygonF& poly, QTransform& trans= form) const +{ + if (m_cachedPolygon.size() !=3D 0 && handles().size() =3D=3D 4) { + for (int i =3D 0; i <=3D 4; ++i) { + if (i =3D=3D 4) { + poly =3D m_cachedPolygon; + transform =3D m_cachedTransform; + return m_cacheValid; + } + if (m_cachedPoints[i] !=3D *handles()[i]) break; + } + } + m_cachedPolygon.clear(); + m_cacheValid =3D false; + if (!quad(poly)) { + m_cachedPolygon =3D poly; + return false; + } + if (!QTransform::squareToQuad(poly, transform)) { + qWarning("Failed to create perspective mapping"); + return false; + } + for (int i =3D 0; i < 4; ++i) { + m_cachedPoints[i] =3D *handles()[i]; + } + m_cachedPolygon =3D poly; + m_cachedTransform =3D transform; + m_cacheValid =3D true; + return true; } = + void KisPerspectiveGridNg::initHandles(QList= _handles) { Q_ASSERT(d->handles.isEmpty()); @@ -189,6 +255,25 @@ const QString& KisPerspectiveGridNg::name() const return d->name; } = +QPointF KisPerspectiveGridNg::adjustPosition(const QPointF& pt, const QPoi= ntF& strokeBegin) +{ + return project(pt, strokeBegin); +} + +void KisPerspectiveGridNg::endStroke() +{ + m_snapLine =3D QLineF(); +} + +QPointF KisPerspectiveGridNg::buttonPosition() const +{ + QPointF centroid(0, 0); + for (int i =3D 0; i < 4; ++i) centroid +=3D *handles()[i]; + return centroid * 0.25; +} + + + void KisPerspectiveGridNg::replaceHandle(KisPerspectiveGridNgHandleSP _han= dle, KisPerspectiveGridNgHandleSP _with) { Q_ASSERT(d->handles.contains(_handle)); @@ -214,8 +299,33 @@ void KisPerspectiveGridNg::addSideHandle(KisPerspectiv= eGridNgHandleSP handle) handle.data()->setType('S'); } = +inline QPainterPath drawX(const QPointF& pt) +{ + QPainterPath path; + path.moveTo(QPointF(pt.x() - 5.0, pt.y() - 5.0)); path.lineTo(QPointF(= pt.x() + 5.0, pt.y() + 5.0)); + path.moveTo(QPointF(pt.x() - 5.0, pt.y() + 5.0)); path.lineTo(QPointF(= pt.x() + 5.0, pt.y() - 5.0)); + return path; +} + void KisPerspectiveGridNg::drawAssistant(QPainter& gc, const QRectF& updat= eRect, const KisCoordinatesConverter* converter, bool useCache,KisCanvas2* = canvas) { + gc.save(); + gc.resetTransform(); + QTransform initialTransform =3D converter->documentToWidgetTransform(); + QPolygonF poly; + QTransform transform; // unused, but computed for caching purposes + if (getTransform(poly, transform)) { + // draw vanishing points + QPointF intersection(0, 0); + if (QLineF(poly[0], poly[1]).intersect(QLineF(poly[2], poly[3]), &= intersection) !=3D QLineF::NoIntersection) { + drawPath(gc, drawX(initialTransform.map(intersection))); + } + if (QLineF(poly[1], poly[2]).intersect(QLineF(poly[3], poly[0]), &= intersection) !=3D QLineF::NoIntersection) { + drawPath(gc, drawX(initialTransform.map(intersection))); + } + } + gc.restore(); + Q_UNUSED(updateRect); Q_UNUSED(canvas); findHandleLocation(); @@ -227,7 +337,7 @@ void KisPerspectiveGridNg::drawAssistant(QPainter& gc, = const QRectF& updateRect, } const QRect bound =3D boundingRect(); if (bound.isEmpty()) return; - const QTransform transform =3D converter->documentToWidgetTransform(); + /*const QTransform */transform =3D converter->documentToWidgetTransfor= m(); const QRect widgetBound =3D transform.mapRect(bound); = const QRect paintRect =3D transform.mapRect(bound).intersected(gc.view= port()); @@ -255,6 +365,43 @@ void KisPerspectiveGridNg::drawAssistant(QPainter& gc,= const QRectF& updateRect, gc.drawPixmap(paintRect, cached, paintRect.translated(-widgetBound.top= Left() - d->cachedRect.topLeft())); } = + + +void KisPerspectiveGridNg::drawCache(QPainter& gc, const KisCoordinatesCon= verter *converter) +{ + gc.setTransform(converter->documentToWidgetTransform()); + QPolygonF poly; + QTransform transform; + if (!getTransform(poly, transform)) { + // color red for an invalid transform, but not for an incomplete o= ne + if(handles().size() =3D=3D 4) + { + gc.setPen(QColor(255, 0, 0, 125)); + gc.drawPolygon(poly); + } else { + QPainterPath path; + path.addPolygon(poly); + drawPath(gc, path); + } + } else { + gc.setPen(QColor(0, 0, 0, 125)); + gc.setTransform(transform, true); + QPainterPath path; + for (int y =3D 0; y <=3D 8; ++y) + { + path.moveTo(QPointF(0.0, y * 0.125)); + path.lineTo(QPointF(1.0, y * 0.125)); + } + for (int x =3D 0; x <=3D 8; ++x) + { + path.moveTo(QPointF(x * 0.125, 0.0)); + path.lineTo(QPointF(x * 0.125, 1.0)); + } + drawPath(gc, path); + } +} + + void KisPerspectiveGridNg::uncache() { d->cached =3D QPixmapCache::Key(); @@ -464,6 +611,113 @@ void KisPerspectiveGridNg::findHandleLocation() { } } = +QPointF KisPerspectiveGridNg::project(const QPointF& pt, const QPointF& st= rokeBegin) +{ + const static QPointF nullPoint(std::numeric_limits::quiet_NaN()= , std::numeric_limits::quiet_NaN()); + Q_ASSERT(handles().size() =3D=3D 4); + if (m_snapLine.isNull()) { + QPolygonF poly; + QTransform transform; + if (!getTransform(poly, transform)) return nullPoint; + // avoid problems with multiple assistants: only snap if starting = in the grid + if (!poly.containsPoint(strokeBegin, Qt::OddEvenFill)) return null= Point; + + const qreal + dx =3D pt.x() - strokeBegin.x(), + dy =3D pt.y() - strokeBegin.y(); + if (dx * dx + dy * dy < 4.0) { + // allow some movement before snapping + return strokeBegin; + } + + // construct transformation + bool invertible; + const QTransform inverse =3D transform.inverted(&invertible); + if (!invertible) return nullPoint; // shouldn't happen + + // figure out which direction to go + const QPointF start =3D inverse.map(strokeBegin); + const QLineF + verticalLine =3D QLineF(strokeBegin, transform.map(start + QPo= intF(0, 1))), + horizontalLine =3D QLineF(strokeBegin, transform.map(start + Q= PointF(1, 0))); + // determine whether the horizontal or vertical line is closer to = the point + m_snapLine =3D distsqr(pt, verticalLine) < distsqr(pt, horizontalL= ine) ? verticalLine : horizontalLine; + } + + // snap to line + const qreal + dx =3D m_snapLine.dx(), + dy =3D m_snapLine.dy(), + dx2 =3D dx * dx, + dy2 =3D dy * dy, + invsqrlen =3D 1.0 / (dx2 + dy2); + QPointF r(dx2 * pt.x() + dy2 * m_snapLine.x1() + dx * dy * (pt.y() - m= _snapLine.y1()), + dx2 * m_snapLine.y1() + dy2 * pt.y() + dx * dy * (pt.x() - m= _snapLine.x1())); + r *=3D invsqrlen; + return r; + return QPointF(0,0); +} + +// perpendicular dot product +inline qreal pdot(const QPointF& a, const QPointF& b) +{ + return a.x() * b.y() - a.y() * b.x(); +} + +template int sign(T a) +{ + return (a > 0) - (a < 0); +} + + +bool KisPerspectiveGridNg::quad(QPolygonF& poly) const +{ + for (int i =3D 0; i < handles().size(); ++i) + poly.push_back(*handles()[i]); + if (handles().size() !=3D 4) { + return false; + } + int sum =3D 0; + int signs[4]; + for (int i =3D 0; i < 4; ++i) { + int j =3D (i =3D=3D 3) ? 0 : (i + 1); + int k =3D (j =3D=3D 3) ? 0 : (j + 1); + signs[i] =3D sign(pdot(poly[j] - poly[i], poly[k] - poly[j])); + sum +=3D signs[i]; + } + if (sum =3D=3D 0) { + // complex (crossed) + for (int i =3D 0; i < 4; ++i) { + int j =3D (i =3D=3D 3) ? 0 : (i + 1); + if (signs[i] * signs[j] =3D=3D -1) { + // opposite signs: uncross + qSwap(poly[i], poly[j]); + return true; + } + } + // okay, maybe it's just a line + return false; + } else if (sum !=3D 4 && sum !=3D -4) { + // concave, or a triangle + if (sum =3D=3D 2 || sum =3D=3D -2) { + // concave, let's return a triangle instead + for (int i =3D 0; i < 4; ++i) { + int j =3D (i =3D=3D 3) ? 0 : (i + 1); + if (signs[i] !=3D sign(sum)) { + // wrong sign: drop the inside node + poly.remove(j); + return false; + } + } + } + return false; + } + // convex + return true; +} + + + KisPerspectiveGridNgHandleSP KisPerspectiveGridNg::oppHandleOne() { QPointF intersection(0,0); @@ -481,6 +735,7 @@ KisPerspectiveGridNgHandleSP KisPerspectiveGridNg::oppH= andleOne() { return d->handles.at(3); } + return d->handles.at(0);//TODO: comment this line while running } = KisPerspectiveGridNgHandleSP KisPerspectiveGridNg::topLeft() @@ -591,6 +846,22 @@ KisPerspectiveGridNgFactory::~KisPerspectiveGridNgFact= ory() { } = +QString KisPerspectiveGridNgFactory::id() const +{ + return "perspectivegridng"; +} + +QString KisPerspectiveGridNgFactory::name() const +{ + return i18n("PerspectiveGridNg"); +} + + +KisPerspectiveGridNg* KisPerspectiveGridNgFactory::createPerspectiveGridNg= () const +{ + return new KisPerspectiveGridNg; +} + KisPerspectiveGridNgFactoryRegistry::KisPerspectiveGridNgFactoryRegistry() { } @@ -609,3 +880,6 @@ KisPerspectiveGridNgFactoryRegistry* KisPerspectiveGrid= NgFactoryRegistry::instan return s_instance; } = + + + diff --git a/krita/ui/kis_perspective_gridng.h b/krita/ui/kis_perspective_g= ridng.h index 67c1f59..7c8e548 100644 --- a/krita/ui/kis_perspective_gridng.h +++ b/krita/ui/kis_perspective_gridng.h @@ -41,6 +41,7 @@ class QRectF; class KisCoordinatesConverter; class KisDoc2; = +#include "kis_abstract_perspective_grid.h" #include #include = @@ -80,11 +81,12 @@ private: * A KisPerspectiveGridNg is an object that assist the drawing on the canv= as. * With this class you can implement virtual equivalent to ruler or compas. */ -class KRITAUI_EXPORT KisPerspectiveGridNg +class KRITAUI_EXPORT KisPerspectiveGridNg // : public KisAbstractPerspecti= veGrid { public: + KisPerspectiveGridNg(); KisPerspectiveGridNg(const QString& id, const QString& name); - virtual ~KisPerspectiveGridNg(); + ~KisPerspectiveGridNg(); const QString& id() const; const QString& name() const; /** @@ -92,10 +94,10 @@ public: * @param point the coordinates in point in the document reference * @param strokeBegin the coordinates of the beginning of the stroke */ - virtual QPointF adjustPosition(const QPointF& point, const QPointF& st= rokeBegin) =3D 0; - virtual void endStroke() { } - virtual QPointF buttonPosition() const =3D 0; - virtual int numHandles() const =3D 0; + virtual QPointF adjustPosition(const QPointF& point, const QPointF& st= rokeBegin); + virtual void endStroke(); + virtual QPointF buttonPosition() const; + virtual int numHandles() const{ return 4; } void replaceHandle(KisPerspectiveGridNgHandleSP _handle, KisPerspectiv= eGridNgHandleSP _with); void addHandle(KisPerspectiveGridNgHandleSP handle); void addSideHandle(KisPerspectiveGridNgHandleSP handle); @@ -138,10 +140,24 @@ public: static void drawPath(QPainter& painter, const QPainterPath& path); protected: virtual QRect boundingRect() const; - virtual void drawCache(QPainter& gc, const KisCoordinatesConverter *co= nverter) =3D 0; + virtual void drawCache(QPainter& gc, const KisCoordinatesConverter *co= nverter); void initHandles(QList _handles); QList m_handles; private: + bool getTransform(QPolygonF& poly, QTransform& transform) const; + QPointF project(const QPointF& pt, const QPointF& strokeBegin); + // creates the convex hull, returns false if it's not a quadrilateral + bool quad(QPolygonF& out) const; + // finds the transform from perspective coordinates (a unit square) to= the document +// bool getTransform(QPolygonF& polyOut, QTransform& transformOut) cons= t; + + // which direction to snap to (in transformed coordinates) + QLineF m_snapLine; + // cached information + mutable QTransform m_cachedTransform; + mutable QPolygonF m_cachedPolygon; + mutable QPointF m_cachedPoints[4]; + mutable bool m_cacheValid; struct Private; Private* const d; }; @@ -154,9 +170,9 @@ class KRITAUI_EXPORT KisPerspectiveGridNgFactory public: KisPerspectiveGridNgFactory(); virtual ~KisPerspectiveGridNgFactory(); - virtual QString id() const =3D 0; - virtual QString name() const =3D 0; - virtual KisPerspectiveGridNg* createPerspectiveGridNg() const =3D 0; + QString id() const; + QString name() const; + virtual KisPerspectiveGridNg* createPerspectiveGridNg() const; = }; = diff --git a/krita/ui/kis_view2.cpp b/krita/ui/kis_view2.cpp index 5b55c2a..3e7982f 100644 --- a/krita/ui/kis_view2.cpp +++ b/krita/ui/kis_view2.cpp @@ -90,6 +90,7 @@ #include "canvas/kis_canvas_controller.h" #include "canvas/kis_grid_manager.h" #include "canvas/kis_perspective_grid_manager.h" +#include "kis_perspective_grid_managerng.h" #include "dialogs/kis_dlg_preferences.h" #include "dialogs/kis_dlg_blacklist_cleanup.h" #include "kis_canvas_resource_provider.h" @@ -167,6 +168,7 @@ public: , imageManager(0) , gridManager(0) , perspectiveGridManager(0) + , perspectiveGridNgManager(0) , paintingAssistantManager(0) , actionManager(0) { @@ -186,6 +188,7 @@ public: delete imageManager; delete gridManager; delete perspectiveGridManager; + delete perspectiveGridNgManager; delete paintingAssistantManager; delete viewConverter; delete statusBar; @@ -795,6 +798,10 @@ void KisView2::createManagers() m_d->perspectiveGridManager->setup(actionCollection()); m_d->canvas->addDecoration(m_d->perspectiveGridManager); = + m_d->perspectiveGridNgManager =3D new KisPerspectiveGridNgManager(this= ); + m_d->perspectiveGridNgManager->setup(actionCollection()); + m_d->canvas->addDecoration(m_d->perspectiveGridNgManager); + m_d->paintingAssistantManager =3D new KisPaintingAssistantsManager(thi= s); m_d->paintingAssistantManager->setup(actionCollection()); m_d->canvas->addDecoration(m_d->paintingAssistantManager);