How to add zooming capabilities to RGraphicsViewQt

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

How to add zooming capabilities to RGraphicsViewQt

Postby s4eed » Sat Sep 28, 2013 9:13 pm

I successfully loaded a DXF file using this code :
Code: Select all
   RGraphicsViewQt *view = new RGraphicsViewQt;
   RMemoryStorage* storage = new RMemoryStorage();
   RSpatialIndexNavel* spatialIndex = new RSpatialIndexNavel();
   RDocument * document = new RDocument(*storage, *spatialIndex);

   RDxfImporter *importer = new RDxfImporter(*document);
   importer->importFile(fileName, "DXF 2000");
   RDocumentInterface * documentInterface = new RDocumentInterface(*document);
   //   documentInterface->importFile("2.dxf", "DXF 2000");

   RGraphicsSceneQt *scene = new RGraphicsSceneQt(*documentInterface);
   view->setScene(scene);
   documentInterface->regenerateScenes();
   documentInterface->autoZoom();

But now I want to be able to zoom in and zoom out using scrolling with middle mouse button. I haven't found any thing in the source code of QCad.
Thank you !
s4eed
Junior Member
 
Posts: 18
Joined: Fri Sep 27, 2013 3:23 pm

Re: How to add zooming capabilities to RGraphicsViewQt

Postby andrew » Sat Sep 28, 2013 9:44 pm

All user interaction including mouse panning, mouse zooming, scroll bars, selecting entities, etc. is implemented as scripts:

Navigation (panning, zooming, ...):
scripts/Navigation/DefaultNavigation/DefaultNavigation.js

Default behavior (selecting entities, drag and drop, ...):
scripts/DefaultAction.js

It's generally possible to use these script classes from C++, and do all this initialization manually, but there is a script class 'Viewport' that does it all for you.

I've attached a C++ example project that creates a simple drawing view with scroll bars and basic navigation, loads a DXF file into it and does some other interesting things.
Everything that does not rely on scripts is implemented in C++. The scripts that come with QCAD are used for creating and initializing the graphics view, adding navigation to it, etc.

If you place the files in your QCAD directory under support/examples/mainwindow, compilation should be as easy as qmake, make.
Attachments
MainWindow.zip
(12.11 KiB) Downloaded 129 times
User avatar
andrew
Site Admin
 
Posts: 2590
Joined: Fri Mar 30, 2007 6:07 am

Re: How to add zooming capabilities to RGraphicsViewQt

Postby s4eed » Sat Sep 28, 2013 9:58 pm

I can't say anything :-| YOU ARE AWESOME :-* . GREAT APPLICATION .
Excuse me because of this off topic !
s4eed
Junior Member
 
Posts: 18
Joined: Fri Sep 27, 2013 3:23 pm

Re: How to add zooming capabilities to RGraphicsViewQt

Postby josh.wu » Sun Jan 19, 2014 10:59 am

How can I make the support/example/mainwindow can respond to mouse selection entities, drag and drop entities,editing entities. Thank you!
josh.wu
Newbie Member
 
Posts: 5
Joined: Sun Jan 19, 2014 10:03 am

Re: How to add zooming capabilities to RGraphicsViewQt

Postby josh.wu » Mon Jan 20, 2014 1:49 pm

andrew wrote:All user interaction including mouse panning, mouse zooming, scroll bars, selecting entities, etc. is implemented as scripts:

Navigation (panning, zooming, ...):
scripts/Navigation/DefaultNavigation/DefaultNavigation.js

Default behavior (selecting entities, drag and drop, ...):
scripts/DefaultAction.js

It's generally possible to use these script classes from C++, and do all this initialization manually, but there is a script class 'Viewport' that does it all for you.

I've attached a C++ example project that creates a simple drawing view with scroll bars and basic navigation, loads a DXF file into it and does some other interesting things.
Everything that does not rely on scripts is implemented in C++. The scripts that come with QCAD are used for creating and initializing the graphics view, adding navigation to it, etc.

If you place the files in your QCAD directory under support/examples/mainwindow, compilation should be as easy as qmake, make.


I have built it successful ,but mouse can not selecting entities, drag and drop, ...
josh.wu
Newbie Member
 
Posts: 5
Joined: Sun Jan 19, 2014 10:03 am

Re: How to add zooming capabilities to RGraphicsViewQt

Postby andrew » Mon Jan 20, 2014 3:46 pm

josh.wu wrote:How can I make the support/example/mainwindow can respond to mouse selection entities, drag and drop entities,editing entities. Thank you!


All tools, including entity selection, drag and drop, drawing, modification, etc. are implemented as scripts in QCAD. If you need those tools, you can either use the same scripts that QCAD uses (see 'scripts' directory) or write your own implementations.

Depending on what you are trying to achieve, it might be easier to start with the full blown QCAD add the tools you wish to add as scripts.
User avatar
andrew
Site Admin
 
Posts: 2590
Joined: Fri Mar 30, 2007 6:07 am

Re: How to add zooming capabilities to RGraphicsViewQt

Postby josh.wu » Fri Jan 24, 2014 9:03 am

I modified init_viewport.js:

Code: Select all
include('scripts/Widgets/Viewport/Viewport.js');
include("scripts/DefaultAction.js");

var viewports = Viewport.getViewports(widget, documentInterface);

// creates a scene for the view,
// attaches the scene to the document interface,
// sets default navigation,
// adds scrollbars and rulers:
Viewport.initializeViewports(viewports);

// init event handlers for drag and drop and scrolling:
Viewport.initEventHandler(viewports);

var idleGuiAction = RGuiAction.getByScriptFile("scripts/DefaultAction.js");
if (typeof(DefaultAction)!=="undefined") {
   var idleAction = new DefaultAction(idleGuiAction);
   documentInterface.setDefaultAction(idleAction);
}
RGuiAction.triggerGroupDefaults();


and then support/example/mainwindow can respond to mouse selection entities,
but can not respond to mouse drag and drop entities,editing entities.

I‘m just getting started with QT and scripts, can you give me more examples about QCad based app?

I'm very sorry to trouble you!
josh.wu
Newbie Member
 
Posts: 5
Joined: Sun Jan 19, 2014 10:03 am


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 0 guests