Page 1 of 1

How to add zooming capabilities to RGraphicsViewQt

Posted: Sat Sep 28, 2013 9:13 pm
by s4eed
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 !

Re: How to add zooming capabilities to RGraphicsViewQt

Posted: Sat Sep 28, 2013 9:44 pm
by andrew
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.

Re: How to add zooming capabilities to RGraphicsViewQt

Posted: Sat Sep 28, 2013 9:58 pm
by s4eed
I can't say anything :-| YOU ARE AWESOME :-* . GREAT APPLICATION .
Excuse me because of this off topic !

Re: How to add zooming capabilities to RGraphicsViewQt

Posted: Sun Jan 19, 2014 10:59 am
by josh.wu
How can I make the support/example/mainwindow can respond to mouse selection entities, drag and drop entities,editing entities. Thank you!

Re: How to add zooming capabilities to RGraphicsViewQt

Posted: Mon Jan 20, 2014 1:49 pm
by josh.wu
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, ...

Re: How to add zooming capabilities to RGraphicsViewQt

Posted: Mon Jan 20, 2014 3:46 pm
by andrew
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.

Re: How to add zooming capabilities to RGraphicsViewQt

Posted: Fri Jan 24, 2014 9:03 am
by josh.wu
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!