Skip to content

Commit

Permalink
add more interface items
Browse files Browse the repository at this point in the history
-use standart freecad interface widgets as interface items
-rewrite anchoring to work well with many items
  • Loading branch information
ickby committed Jun 22, 2017
1 parent 526b815 commit b84bb9d
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 168 deletions.
4 changes: 3 additions & 1 deletion src/Gui/CMakeLists.txt
Expand Up @@ -822,6 +822,8 @@ SET(View3D_CPP_SRCS
CoinRiftWidget.cpp
View3DPy.cpp
View3DViewerPy.cpp
DynamicInterfaceManager.cpp
QmlTypes.cpp
)
SET(View3D_SRCS
${View3D_CPP_SRCS}
Expand All @@ -838,6 +840,7 @@ SET(View3D_SRCS
View3DInventorRiftViewer.h
CoinRiftWidget.h
View3DViewerPy.h
DynamicInterfaceManager.h
QmlTypes.h
)
SOURCE_GROUP("View3D" FILES ${View3D_SRCS})
Expand Down Expand Up @@ -994,7 +997,6 @@ SET(Widget_CPP_SRCS
WidgetFactory.cpp
Widgets.cpp
Window.cpp
QmlTypes.cpp
)
SET(Widget_HPP_SRCS
FileDialog.h
Expand Down
68 changes: 35 additions & 33 deletions src/Gui/MainWindow.cpp
Expand Up @@ -121,6 +121,7 @@
#include "SpaceballEvent.h"
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
#include "DynamicInterfaceManager.h"

#if defined(Q_OS_WIN32)
#define slots
Expand Down Expand Up @@ -261,7 +262,8 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags f)
instance = this;

// Create the layout containing the workspace and a tab bar
if(0) {
bool dynamicLayout = true;
if(!dynamicLayout) {
d->declarativeView = NULL;
d->mdiArea = new QMdiArea();
setCentralWidget(d->mdiArea);
Expand Down Expand Up @@ -298,6 +300,7 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags f)
d->declarativeView->setSource(QString::fromAscii("/home/stefan/Projects/FreeCAD_sf_master/src/Gui/Qml/MainLayout.qml"));
setCentralWidget(d->declarativeView);

GlobalDynamicInterfaceManager::get()->setManagedView(d->declarativeView);
d->mdiArea = NULL;
};

Expand Down Expand Up @@ -366,41 +369,55 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags f)
tree->setObjectName
(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Tree view")));
tree->setMinimumWidth(210);
pDockMgr->registerDockWindow("Std_TreeView", tree);
if(!dynamicLayout)
pDockMgr->registerDockWindow("Std_TreeView", tree);
else
GlobalDynamicInterfaceManager::get()->addInterfaceItem(tree, true);

// Property view
PropertyDockView* pcPropView = new PropertyDockView(0, this);
pcPropView->setObjectName
(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Property view")));
pcPropView->setMinimumWidth(210);
pDockMgr->registerDockWindow("Std_PropertyView", pcPropView);
if(!dynamicLayout)
pDockMgr->registerDockWindow("Std_PropertyView", pcPropView);
else
GlobalDynamicInterfaceManager::get()->addInterfaceItem(pcPropView, true);

// Selection view
SelectionView* pcSelectionView = new SelectionView(0, this);
pcSelectionView->setObjectName
(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Selection view")));
pcSelectionView->setMinimumWidth(210);
pDockMgr->registerDockWindow("Std_SelectionView", pcSelectionView);

if(!dynamicLayout)
pDockMgr->registerDockWindow("Std_SelectionView", pcSelectionView);
else
GlobalDynamicInterfaceManager::get()->addInterfaceItem(pcSelectionView, true);
/*
// Combo view
CombiView* pcCombiView = new CombiView(0, this);
pcCombiView->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Combo View")));
pcCombiView->setMinimumWidth(150);
pDockMgr->registerDockWindow("Std_CombiView", pcCombiView);
if(!dynamicLayout)
pDockMgr->registerDockWindow("Std_CombiView", pcCombiView);
else
GlobalDynamicInterfaceManager::get()->addInterfaceItem(pcCombiView, true);*/

#if QT_VERSION < 0x040500
// Report view
Gui::DockWnd::ReportView* pcReport = new Gui::DockWnd::ReportView(this);
pcReport->setObjectName
(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Report view")));
pDockMgr->registerDockWindow("Std_ReportView", pcReport);
pcReport->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Report view")));
if(!dynamicLayout)
pDockMgr->registerDockWindow("Std_ReportView", pcReport);
#else
// Report view (must be created before PythonConsole!)
ReportOutput* pcReport = new ReportOutput(this);
pcReport->setWindowIcon(BitmapFactory().pixmap("MacroEditor"));
pcReport->setObjectName
(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Report view")));
pDockMgr->registerDockWindow("Std_ReportView", pcReport);
pcReport->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Report view")));
if(!dynamicLayout)
pDockMgr->registerDockWindow("Std_ReportView", pcReport);
else
GlobalDynamicInterfaceManager::get()->addInterfaceItem(pcReport, true);

// Python console
PythonConsole* pcPython = new PythonConsole(this);
Expand All @@ -414,9 +431,11 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags f)
}

pcPython->setWindowIcon(Gui::BitmapFactory().iconFromTheme("applications-python"));
pcPython->setObjectName
(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Python console")));
pDockMgr->registerDockWindow("Std_PythonView", pcPython);
pcPython->setObjectName(QString::fromLatin1(QT_TRANSLATE_NOOP("QDockWidget","Python console")));
if(!dynamicLayout)
pDockMgr->registerDockWindow("Std_PythonView", pcPython);
else
GlobalDynamicInterfaceManager::get()->addInterfaceItem(pcPython, true);

//Dag View.
//work through parameter.
Expand Down Expand Up @@ -791,24 +810,7 @@ void MainWindow::addWindow(MDIView* view)
}
}

//create the component and set the view proxy
QDeclarativeComponent component(d->declarativeView->engine(),
QString::fromAscii("/home/stefan/Projects/FreeCAD_sf_master/src/Gui/Qml/MDIView.qml"));
QDeclarativeItem* item = qobject_cast<QDeclarativeItem*>(component.create());
item->setProperty("proxy", QVariant::fromValue(static_cast<QWidget*>(view)));

//make sure we can destroy it from within qml
d->declarativeView->engine()->setObjectOwnership(item, QDeclarativeEngine::JavaScriptOwnership);

//add it to the scene
QObject* mdiview = d->declarativeView->rootObject()->findChild<QObject*>(QString::fromAscii("mdiarea"));
if(mdiview) {
item->setParentItem(qobject_cast<QDeclarativeItem*>(mdiview));
}
else {
Base::Console().Error("No mdiview found, view can not be added to layout");
return;
}
GlobalDynamicInterfaceManager::get()->addView(view);
}

#if defined(Q_OS_WIN32)
Expand Down
117 changes: 103 additions & 14 deletions src/Gui/Qml/InterfaceItem.qml
Expand Up @@ -33,10 +33,10 @@ Item {
property Item area: parent

property alias title: titleItem.text
width: 200
height: 50

width: childrenRect.width
height: childrenRect.height

Rectangle {
id: titlebar
height:20
Expand All @@ -52,26 +52,27 @@ Item {
height: parent.height
anchors.leftMargin: 3
anchors.left: parent.left
anchors.right: buttons.left
elide: Text.ElideRight
}
MouseArea {
anchors.left: titleItem.left
anchors.right: titleItem.right
anchors.right: buttons.left
height: titleItem.height
drag.target: interfaceitem
drag.minimumX: 0
drag.maximumX: interfaceitem.parent.width - parent.width
drag.maximumX: interfaceitem.parent.width - interfaceitem.width
drag.minimumY: 0
drag.maximumY: interfaceitem.parent.height - parent.height
drag.maximumY: interfaceitem.parent.height - interfaceitem.height

onPressed: Util.setupHitPositions(interfaceitem, mouse);
onPositionChanged: Util.setAnchorsForPosition(mouse);
}
Row {
id:buttons
anchors.left: titleItem.right
anchors.right: parent.right
anchors.top: titlebar.top;
anchors.right: titlebar.right
width: childrenRect.width
height: titlebar.height
TitleButton{
width: 20
height: 20
Expand All @@ -86,12 +87,100 @@ Item {
}

//this item is used as placeholder for the interface item
Item {
Rectangle {
id: childarea

anchors.topMargin: 3
anchors.top: titlebar.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.top: titlebar.bottom

width: childrenRect.width
height: childrenRect.height
}

//we need to setup the anchor object arrays
Component.onCompleted: {
Util.anchors = new Object();
Util.anchors.anchorXlist = new Array();
Util.anchors.anchorYlist = new Array();
}

anchors.onTopChanged: {
if(!Util.anchors.controlledChange)
console.warning("Top anchor removed")
}
anchors.onBottomChanged: {
if(!Util.anchors.controlledChange)
console.warning("Bottom anchor removed")
}
anchors.onVerticalCenterChanged: {
if(!Util.anchors.controlledChange)
console.warning("Vertical Center anchor removed")
}

function setPassiveAnchor(anchorObject) {

if(anchorObject.isXtype)
Util.anchors.anchorXlist[Util.anchors.anchorXlist.length] = anchorObject;
else
Util.anchors.anchorYlist[Util.anchors.anchorYlist.length] = anchorObject;
}

function removePassiveAnchor(anchorObject) {

var list = anchorObject.isXtype ? Util.anchors.anchorXlist : Util.anchors.anchorYlist;
var index = list.indexOf(anchorObject);
list.splice(index, 1);
}

//if we set a anchor for this item we do not only need to set it but also to store the information
//that we did. Furthermore this information needs to be stored in the passive element too.
function setupAnchor(thisAnchor, item, itemAnchor) {

//console.debug("setup anchor:")
//console.debug("X anchor length: ", Util.anchors.anchorXlist.length);
//console.debug("Y anchor length: ", Util.anchors.anchorYlist.length);

Util.anchors.controlledChange = true;
anchors[thisAnchor] = item[itemAnchor];
Util.anchors.controlledChange = false;

var anchorObject = {active: interfaceitem, passive: item, activeAnchor: thisAnchor, passiveAnchor: itemAnchor};
if(thisAnchor == 'top' || thisAnchor == 'bottom' || thisAnchor == 'verticalCenter') {
anchorObject.isXtype = false;
Util.anchors.anchorYlist[Util.anchors.anchorYlist.length] = anchorObject;
}
else {
anchorObject.isXtype = false;
Util.anchors.anchorXlist[Util.anchors.anchorXlist.length] = anchorObject;
}

if('setPassiveAnchor' in item)
item.setPassiveAnchor(anchorObject);

//console.debug("done X anchor length: ", Util.anchors.anchorXlist.length);
//console.debug("done Y anchor length: ", Util.anchors.anchorYlist.length);
}

function removeAnchors(vertical) {

//console.debug("remove anchors")

var list = vertical ? Util.anchors.anchorYlist : Util.anchors.anchorXlist;

for (var i=0; i < list.length; ++i) {
//reset the anchor
Util.anchors.controlledChange = true;
list[i].active.anchors[list[i].activeAnchor] = undefined;
Util.anchors.controlledChange = false;

//inform the passive item that this anchor has gone
if('removePassiveAnchor' in list[i].passive)
list[i].passive.removePassiveAnchor(list[i]);
}
//clear the anchor list as all have been removed
if(vertical)
Util.anchors.anchorYlist = new Array();
else
Util.anchors.anchorXlist = new Array();
}
}

0 comments on commit b84bb9d

Please sign in to comment.