Commit 11cbea9c by Sebastian Eichelbaum

[MERGE] - merged in networkEditor from skiunke branch. This includes the…

[MERGE] - merged in networkEditor from skiunke branch. This includes the all-is-a-dock stuff and the save/load for window states. Removed Walnut.cfg options combineTreeAndRoiAndTextureSorter, dsbWidth, dsbInvisibleByDefault, dsbFloatingByDefault as they are not needed anymore. Simply click your GUI as you need it. The GUI gets restored automatically.
parents 960677b2 3da5ca1e
......@@ -50,11 +50,6 @@ compatiblesToolBarPos = 0 # position of the compatibles toolbar (overrides toolB
####################################################################
# Control panel
# combineTreeAndRoiAndTextureSorter = yes # should the module tree, ROI tree and the Texture Sorter be combined in ONE Tab widget?
# dsbWidth = 400 # the width of the control panel
# dsbInvisibleByDefault = yes # hide the control panel on startup. Can be shown using F9.
# dsbFloatingByDefault = yes # should the control panel be undocked on startup?
# Here you can put any key sequence you would like to result in removing modules or ROIs
# Examples:
# deleteKey = Backspace
......
......@@ -53,11 +53,6 @@ compatiblesToolBarPos = 0 # position of the compatibles toolbar (overrides toolB
####################################################################
# Control panel
# combineTreeAndRoiAndTextureSorter = yes # should the module tree, ROI tree and the Texture Sorter be combined in ONE Tab widget?
# dsbWidth = 400 # the width of the control panel
# dsbInvisibleByDefault = yes # hide the control panel on startup. Can be shown using F9.
# dsbFloatingByDefault = yes # should the control panel be undocked on startup?
# Here you can put any key sequence you would like to result in removing modules or ROIs
# Examples:
# deleteKey = Backspace
......
......@@ -35,6 +35,13 @@ SET(GUI_QT4_MOC_HDRS
controlPanel/WQtTreeWidget.h
controlPanel/WQtTreeItem.h
controlPanel/WQtTextureSorter.h
networkEditor/WQtNetworkEditor.h
networkEditor/WQtNetworkScene.h
networkEditor/WQtNetworkItem.h
networkEditor/WQtNetworkPort.h
networkEditor/WQtNetworkInputPort.h
networkEditor/WQtNetworkOutputPort.h
networkEditor/WQtNetworkArrow.h
)
IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
LIST( APPEND GUI_QT4_MOC_HDRS platformDependent/WQtGLWidgetMac.h )
......@@ -49,7 +56,7 @@ ENDIF()
QT4_WRAP_CPP(GUI_QT4_MOC_SRCS ${GUI_QT4_MOC_HDRS} )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*.cpp" "controlPanel/*.cpp" "ribbonMenu/*.cpp" "events/*.cpp" "*.h" "guiElements/*.h" "controlPanel/*.h" "ribbonMenu/*.h" "events/*.h" "../icons/WIcons.h" )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*.cpp" "controlPanel/*.cpp" "ribbonMenu/*.cpp" "events/*.cpp" "networkEditor/*.cpp" "*.h" "guiElements/*.h" "controlPanel/*.h" "ribbonMenu/*.h" "events/*.h" "networkEditor/*.h" "../icons/WIcons.h" )
IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetMac.cpp"
......
......@@ -41,6 +41,7 @@
#include <QtGui/QSlider>
#include <QtGui/QVBoxLayout>
#include <QtGui/QWidget>
#include <QtCore/QSettings>
#include "../../common/WColor.h"
#include "../../common/WPreferences.h"
......@@ -82,6 +83,11 @@ WMainWindow::WMainWindow() :
{
}
WMainWindow::~WMainWindow()
{
// cleanup
}
void WMainWindow::setupGUI()
{
m_iconManager.addIcon( std::string( "load" ), fileopen_xpm );
......@@ -95,7 +101,6 @@ void WMainWindow::setupGUI()
m_iconManager.addIcon( std::string( "remove" ), remove_xpm );
m_iconManager.addIcon( std::string( "config" ), preferences_system_xpm );
if( objectName().isEmpty() )
{
setObjectName( QString::fromUtf8( "MainWindow" ) );
......@@ -105,13 +110,28 @@ void WMainWindow::setupGUI()
setWindowIcon( m_iconManager.getIcon( "logo" ) );
setWindowTitle( QApplication::translate( "MainWindow", "OpenWalnut (development version)", 0, QApplication::UnicodeUTF8 ) );
setDockOptions( QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks );
//network Editor
m_networkEditor = new WQtNetworkEditor( this );
m_networkEditor->setFeatures( QDockWidget::AllDockWidgetFeatures );
// the control panel instance is needed for the menu
m_controlPanel = new WQtControlPanel( this );
m_controlPanel->setFeatures( QDockWidget::AllDockWidgetFeatures );
addDockWidget( Qt::RightDockWidgetArea, m_controlPanel );
m_controlPanel->addSubject( "Default Subject" );
// add all docks
addDockWidget( Qt::RightDockWidgetArea, m_controlPanel->getModuleDock() );
addDockWidget( Qt::RightDockWidgetArea, m_networkEditor );
tabifyDockWidget( m_networkEditor, m_controlPanel->getModuleDock() );
addDockWidget( Qt::RightDockWidgetArea, m_controlPanel->getTextureSorterDock() );
addDockWidget( Qt::RightDockWidgetArea, m_controlPanel->getRoiDock() );
tabifyDockWidget( m_controlPanel->getTextureSorterDock(), m_controlPanel->getRoiDock() );
addDockWidget( Qt::RightDockWidgetArea, m_controlPanel );
setupPermanentToolBar();
// we want the upper most tree item to be selected. This helps to make the always compatible modules
......@@ -126,20 +146,6 @@ void WMainWindow::setupGUI()
m_controlPanel->setMinimumWidth( controlPanelWidth );
}
// hide the control panel by default?
bool controlPanelInvisibleByDefault = false;
if( WPreferences::getPreference( "qt4gui.dsbInvisibleByDefault", &controlPanelInvisibleByDefault ) )
{
m_controlPanel->setVisible( !controlPanelInvisibleByDefault );
}
// undock the control panel by default?
bool controlPanelFloatingByDefault = false;
if( WPreferences::getPreference( "qt4gui.dsbFloatingByDefault", &controlPanelFloatingByDefault ) )
{
m_controlPanel->setFloating( controlPanelFloatingByDefault );
}
// NOTE: Please be aware that not every menu needs a shortcut key. If you add a shortcut, you should use one of the
// QKeySequence::StandardKey defaults and avoid ambiguities like Ctrl-C for the configure dialog is not the best choice as Ctrl-C, for the
// most users is the Copy shortcut.
......@@ -249,30 +255,36 @@ void WMainWindow::setupGUI()
}
// Default background color from config file
WColor bgColor( 1.0, 1.0, 1.0, 1.0 );
double r;
double g;
double b;
if( WPreferences::getPreference( "ge.bgColor.r", &r )
&& WPreferences::getPreference( "ge.bgColor.g", &g )
&& WPreferences::getPreference( "ge.bgColor.b", &b ) )
{
bgColor.set( r, g, b, 1.0 );
m_mainGLWidget->setBgColor( bgColor );
WColor bgColor( 1.0, 1.0, 1.0, 1.0 );
double r;
double g;
double b;
if( WPreferences::getPreference( "ge.bgColor.r", &r )
&& WPreferences::getPreference( "ge.bgColor.g", &g )
&& WPreferences::getPreference( "ge.bgColor.b", &b ) )
{
bgColor.set( r, g, b, 1.0 );
m_mainGLWidget->setBgColor( bgColor );
if( m_navAxial )
{
m_navAxial->getGLWidget()->setBgColor( bgColor );
}
if( m_navCoronal )
{
m_navCoronal->getGLWidget()->setBgColor( bgColor );
}
if( m_navSagittal )
{
m_navSagittal->getGLWidget()->setBgColor( bgColor );
}
if( m_navAxial )
{
m_navAxial->getGLWidget()->setBgColor( bgColor );
}
if( m_navCoronal )
{
m_navCoronal->getGLWidget()->setBgColor( bgColor );
}
if( m_navSagittal )
{
m_navSagittal->getGLWidget()->setBgColor( bgColor );
}
}
// after creating the GUI, restore its saved state
QSettings setting( "OpenWalnut.org", "OpenWalnut" );
QByteArray state = setting.value( "MainWindowState", "" ).toByteArray();
restoreGeometry( setting.value( "MainWindowGeometry", "" ).toByteArray() );
restoreState( state );
}
void WMainWindow::setupPermanentToolBar()
......@@ -644,6 +656,11 @@ WQtControlPanel* WMainWindow::getControlPanel()
return m_controlPanel;
}
WQtNetworkEditor* WMainWindow::getNetworkEditor()
{
return m_networkEditor;
}
void WMainWindow::projectSave( const std::vector< boost::shared_ptr< WProjectFileIO > >& writer )
{
QFileDialog fd;
......@@ -922,10 +939,16 @@ void WMainWindow::closeEvent( QCloseEvent* e )
// use some "Really Close?" Dialog here
bool reallyClose = true;
// handle close event
if( reallyClose )
{
// this saves the window state to some common location on the target OS in user scope.
QByteArray state = saveState();
QSettings setting( "OpenWalnut.org", "OpenWalnut" );
setting.setValue( "MainWindowState", state );
// NOTE: Qt Doc says that saveState also saves geometry. But this somehow is wrong (at least for 4.6.3)
setting.setValue( "MainWindowGeometry", saveGeometry() );
// signal everybody to shut down properly.
WKernel::getRunningKernel()->finalize();
......
......@@ -39,6 +39,7 @@
#include "WIconManager.h"
#include "WQtToolBar.h"
#include "WQtGLWidget.h"
#include "networkEditor/WQtNetworkEditor.h"
// forward declarations
class QMenuBar;
......@@ -65,7 +66,12 @@ public:
/**
* Constructor of the main window
*/
explicit WMainWindow();
WMainWindow();
/**
* Destructor. Stores window state.
*/
virtual ~WMainWindow();
/**
* Set up all widgets menus an buttons in the main window.
......@@ -73,6 +79,11 @@ public:
void setupGUI();
/**
* returns a pointer to the network editor object
*/
WQtNetworkEditor* getNetworkEditor();
/**
* returns a pointer to the control panel object
*/
WQtControlPanel* getControlPanel();
......@@ -322,6 +333,8 @@ private:
WQtControlPanel* m_controlPanel; //!< control panel
WQtNetworkEditor* m_networkEditor; //!< network editor
boost::shared_ptr< WQtGLWidget > m_mainGLWidget; //!< the main GL widget of the GUI
boost::shared_ptr< WQtNavGLWidget > m_navAxial; //!< the axial view widget GL widget of the GUI
boost::shared_ptr< WQtNavGLWidget > m_navCoronal; //!< the coronal view widget GL widget of the GUI
......
......@@ -243,6 +243,8 @@ int WQt4Gui::run()
// run
int qtRetCode = appl.exec();
delete m_mainWindow;
// signal everybody to shut down properly.
WKernel::getRunningKernel()->wait( true );
WKernel::getRunningKernel()->getGraphicsEngine()->wait( true );
......@@ -267,6 +269,7 @@ void WQt4Gui::slotAddDatasetOrModuleToTree( boost::shared_ptr< WModule > module
{
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleAssocEvent( module ) );
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleAssocEvent( module ) );
}
void WQt4Gui::slotAddRoiToTree( osg::ref_ptr< WROI > roi )
......@@ -284,6 +287,7 @@ void WQt4Gui::slotActivateDatasetOrModuleInTree( boost::shared_ptr< WModule > mo
// create a new event for this and insert it into event queue
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleReadyEvent( module ) );
QCoreApplication::postEvent( m_mainWindow, new WModuleReadyEvent( module ) );
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleReadyEvent( module ) );
}
void WQt4Gui::slotRemoveDatasetOrModuleInTree( boost::shared_ptr< WModule > module )
......@@ -294,6 +298,7 @@ void WQt4Gui::slotRemoveDatasetOrModuleInTree( boost::shared_ptr< WModule > modu
boost::shared_ptr< WMData > dataModule = boost::shared_dynamic_cast< WMData >( module );
WAssert( dataModule, "Internal failure." );
}
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleRemovedEvent( module ) );
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleRemovedEvent( module ) );
QCoreApplication::postEvent( m_mainWindow, new WModuleRemovedEvent( module ) );
}
......@@ -304,10 +309,12 @@ void WQt4Gui::slotConnectionEstablished( boost::shared_ptr<WModuleConnector> in,
if ( in->isInputConnector() )
{
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleConnectEvent( in, out ) );
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleConnectEvent( in, out ) );
}
else
{
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleConnectEvent( out, in ) );
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleConnectEvent( out, in ) );
}
}
......@@ -316,10 +323,12 @@ void WQt4Gui::slotConnectionClosed( boost::shared_ptr<WModuleConnector> in, boos
// create a new event for this and insert it into event queue
if ( in->isInputConnector() )
{
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleDisconnectEvent( in, out ) );
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleDisconnectEvent( in, out ) );
}
else
{
QCoreApplication::postEvent( m_mainWindow->getNetworkEditor(), new WModuleDisconnectEvent( out, in ) );
QCoreApplication::postEvent( m_mainWindow->getControlPanel(), new WModuleDisconnectEvent( out, in ) );
}
}
......
......@@ -280,13 +280,6 @@ void WQtConfigWidget::registerComponents()
ctbpos->setMax( 5 );
m_defaultProperties->addProperty( "qt4gui.hideMenuBar", "Hide the menu bar.", false, m_propCondition );
WPropInt controlPanelWidth = m_defaultProperties->addProperty( "qt4gui.dsbWidth", "The width of the control panel.", 250, m_propCondition );
controlPanelWidth->setMin( 0 );
controlPanelWidth->setMax( 1000 );
m_defaultProperties->addProperty( "qt4gui.dsbInvisibleByDefault", "Hide the control panel on startup?", false, m_propCondition );
m_defaultProperties->addProperty( "qt4gui.dsbFloatingByDefault", "Undock the control panel on startup?", false, m_propCondition );
WPropGroup moduleWhiteList = m_defaultProperties->addPropertyGroup( "modules.whiteListGroup", "moduleWhiteList" );
m_skipPropertyWrite.push_back( "modules.whiteListGroup" );
WPropString whiteList = moduleWhiteList->addProperty( "modules.whiteList", "Modules that are whitelisted",
......
......@@ -33,6 +33,8 @@ WQtCustomDockWidget::WQtCustomDockWidget( std::string title, QWidget* parent, WG
: QDockWidget( QString::fromStdString( title ), parent ),
m_useCount( 1 )
{
setObjectName( QString( "Custom Dock Window " ) + QString::fromStdString( title ) );
// setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
setFloating( true );
......
......@@ -40,6 +40,7 @@
WQtNavGLWidget::WQtNavGLWidget( QString title, QWidget* parent, std::string sliderTitle, const QGLWidget * shareWidget )
: QDockWidget( title, parent )
{
setObjectName( QString( "Navigation Window " ) + title );
propertyWidgetMap.clear();
m_sliderTitle = QString( sliderTitle.c_str() );
......
......@@ -64,6 +64,8 @@ WQtControlPanel::WQtControlPanel( WMainWindow* parent )
: QDockWidget( "Control Panel", parent ),
m_ignoreSelectionChange( false )
{
setObjectName( "Control Panel Dock" );
m_mainWindow = parent;
m_panel = new QWidget( this );
......@@ -108,31 +110,26 @@ WQtControlPanel::WQtControlPanel( WMainWindow* parent )
connect( m_deleteModuleAction, SIGNAL( triggered() ), this, SLOT( deleteModuleTreeItem() ) );
m_moduleTreeWidget->addAction( m_deleteModuleAction );
m_textureSorter = new WQtTextureSorter( this );
// the network editor also needs the context menu
// TODO(rfrohl): context menu gets not opened if a graphicitem is clicked. This should be fixed.
m_mainWindow->getNetworkEditor()->setContextMenuPolicy( Qt::ActionsContextMenu );
m_mainWindow->getNetworkEditor()->addAction( m_connectWithPrototypeAction );
m_mainWindow->getNetworkEditor()->addAction( m_connectWithModuleAction );
m_mainWindow->getNetworkEditor()->addAction( m_disconnectAction );
m_mainWindow->getNetworkEditor()->addAction( m_deleteModuleAction );
m_textureSorter = new WQtTextureSorter( m_mainWindow );
m_textureSorter->setToolTip( "Reorder the textures." );
m_tabWidget = new QTabWidget( m_panel );
m_tabWidget2 = new QTabWidget( m_panel );
m_tabWidget->setMinimumHeight( 250 );
// should the Tree, Texture Sorter and the ROI Display be combined in one tab widget?
bool combineThem = false;
WPreferences::getPreference( "qt4gui.combineTreeAndRoiAndTextureSorter", &combineThem );
m_splitter = new QSplitter( Qt::Vertical );
if ( !combineThem )
{
m_splitter->addWidget( m_moduleTreeWidget );
}
else
{
m_tabWidget2->addTab( m_moduleTreeWidget, QString( "Modules" ) );
}
m_splitter->addWidget( m_tabWidget2 );
m_tabWidget2->addTab( m_textureSorter, QString( "Texture Sorter" ) );
m_moduleDock = new QDockWidget( "Module Tree", m_mainWindow );
m_moduleDock->setObjectName( "Module Dock" );
m_moduleDock->setWidget( m_moduleTreeWidget );
m_roiDock = new QDockWidget( "ROIs", m_mainWindow );
m_roiDock->setObjectName( "ROI Dock" );
m_roiTreeWidget = new WQtTreeWidget();
m_roiTreeWidget->setToolTip( "Regions of intrest (ROIs) for selecting fiber clusters. Branches are combined using logic <b>or</b>, "
"inside the branches the ROIs are combined using logic <b>and</b>." );
......@@ -142,27 +139,15 @@ WQtControlPanel::WQtControlPanel( WMainWindow* parent )
m_roiTreeWidget->viewport()->setAcceptDrops( true );
m_roiTreeWidget->setDropIndicatorShown( true );
m_roiTreeWidget->setDragDropMode( QAbstractItemView::InternalMove );
m_tabWidget2->addTab( m_roiTreeWidget, QString( "ROIs" ) );
m_splitter->addWidget( m_tabWidget );
// set the initial sizes.
QList< int > splitterList;
splitterList.push_back( 200 );
if ( !combineThem )
{
splitterList.push_back( 200 );
}
splitterList.push_back( 400 );
m_splitter->setSizes( splitterList );
m_roiDock->setWidget( m_roiTreeWidget );
m_layout = new QVBoxLayout();
m_layout->addWidget( m_splitter );
m_layout->addWidget( m_tabWidget );
m_panel->setLayout( m_layout );
this->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
this->setFeatures( QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
this->setAllowedAreas( Qt::AllDockWidgetAreas );
this->setFeatures( QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
this->setWidget( m_panel );
m_tiModules = new WQtModuleHeaderTreeItem( m_moduleTreeWidget );
......@@ -579,7 +564,6 @@ void WQtControlPanel::addRoi( osg::ref_ptr< WROI > roi )
branchItem = m_tiRois->addBranch( WKernel::getRunningKernel()->getRoiManager()->getBranch( roi ) );
}
m_tabWidget2->setCurrentIndex( m_tabWidget2->indexOf( m_roiTreeWidget ) );
branchItem->setExpanded( true );
newItem = branchItem->addRoiItem( roi );
newItem->setDisabled( false );
......@@ -802,6 +786,20 @@ void WQtControlPanel::selectDataModule( boost::shared_ptr< WDataSet > dataSet )
selectTreeItem();
}
void WQtControlPanel::setNewActiveModule( boost::shared_ptr< WModule > module )
{
m_tabWidget->clear();
// NOTE: this handles null pointers properly.
createCompatibleButtons( module );
if ( module )
{
createCompatibleButtons( module );
buildPropTab( module->getProperties(), module->getInformationProperties() );
}
}
WQtPropertyGroupWidget* WQtControlPanel::buildPropWidget( boost::shared_ptr< WProperties > props )
{
WQtPropertyGroupWidget* tab = new WQtPropertyGroupWidget( props );
......@@ -1107,3 +1105,18 @@ void WQtControlPanel::handleDragDrop()
WLogger::getLogger()->addLogMessage( "Drag and drop handler not implemented yet!", "ControlPanel", LL_DEBUG );
}
QDockWidget* WQtControlPanel::getRoiDock() const
{
return m_roiDock;
}
QDockWidget* WQtControlPanel::getModuleDock() const
{
return m_moduleDock;
}
QDockWidget* WQtControlPanel::getTextureSorterDock() const
{
return m_textureSorter;
}
......@@ -168,6 +168,34 @@ public:
*/
void selectUpperMostEntry();
/**
* allows other objects to build the property tab (probably only for WQtNetworkeditor)
*
* \param module the module from which the property tab is created
**/
void setNewActiveModule( boost::shared_ptr< WModule > module );
/**
* Gets the ROI dock widget.
*
* \return the ROI dock.
*/
QDockWidget* getRoiDock() const;
/**
* Gets the module dock widget.
*
* \return the module dock
*/
QDockWidget* getModuleDock() const;
/**
* Gets the texture sorter dock
*
* \return the dock
*/
QDockWidget* getTextureSorterDock() const;
protected:
/**
......@@ -241,6 +269,9 @@ private:
bool m_showToolBarText; //!< Show tool bar icons with text
QDockWidget* m_roiDock; //!< the dock widget with the roi tree
QDockWidget* m_moduleDock; //!< the dock widget with the module tree
/**
* The action to remove a module from the tree.
*/
......
......@@ -47,12 +47,18 @@
WQtTextureSorter::WQtTextureSorter( QWidget* parent )
: QWidget( parent )
: QDockWidget( "Texture Sorter", parent )
{
setObjectName( "Texture Sorter Dock" );
m_textureListWidget = new QListWidget( this );
m_textureListWidget->setToolTip( "List of available textures. Only the upper <b>"
+ QString().setNum( wlimits::MAX_NUMBER_OF_TEXTURES )
+ "</b> textures will be applied." );
this->setAllowedAreas( Qt::AllDockWidgetAreas );
this->setFeatures( QDockWidget::DockWidgetClosable |QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
QWidget* panel = new QWidget( this );
m_layout = new QVBoxLayout();
......@@ -73,7 +79,8 @@ WQtTextureSorter::WQtTextureSorter( QWidget* parent )
connect( m_textureListWidget, SIGNAL( itemClicked( QListWidgetItem* ) ), this, SLOT( handleTextureClicked() ) );
setLayout( m_layout );
panel->setLayout( m_layout );
setWidget( panel );
}
WQtTextureSorter::~WQtTextureSorter()
......
......@@ -28,7 +28,7 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include <QtGui/QWidget>
#include <QtGui/QDockWidget>
#include <QtGui/QListWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
......@@ -41,7 +41,7 @@ class WDataSet;
/**
* container widget for a tree widget with context menu and some control widgets
*/
class WQtTextureSorter : public QWidget
class WQtTextureSorter : public QDockWidget
{
Q_OBJECT
......
......@@ -219,6 +219,7 @@ void WQtTreeItem::updateState()
if ( m_deleteInProgress && !m_module->isRunning().get() && m_needPostDeleteEvent )
{
m_needPostDeleteEvent = false; // this ensures the event is only posted once
QCoreApplication::postEvent( WQt4Gui::getMainWindow()->getNetworkEditor(), new WModuleDeleteEvent( this ) );
QCoreApplication::postEvent( WQt4Gui::getMainWindow()->getControlPanel(), new WModuleDeleteEvent( this ) );
}
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <math.h>
#include <string>
#include <iostream>
#include <QtGui/QGraphicsLineItem>
#include <QtGui/QStyleOptionGraphicsItem>
#include "WQtNetworkInputPort.h"
#include "WQtNetworkOutputPort.h"
#include "WQtNetworkArrow.h"
const qreal Pi = 3.14;
WQtNetworkArrow::WQtNetworkArrow( WQtNetworkOutputPort *startPort, WQtNetworkInputPort *endPort )
: QGraphicsLineItem()
{
m_startPort = startPort;
m_endPort = endPort;
setFlag( QGraphicsItem::ItemIsSelectable, true );
setPen( QPen( Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
setAcceptsHoverEvents( true );
}
WQtNetworkArrow::~WQtNetworkArrow()
{
m_startPort->removeArrow( this );
m_endPort->removeArrow( this );
}
int WQtNetworkArrow::type() const
{
return Type;
}
void WQtNetworkArrow::updatePosition()
{
QRectF sRect = m_startPort->rect();
QRectF eRect = m_startPort->rect();
QLineF tmpLine( mapFromItem( m_startPort, sRect.bottomRight()/2 ),
mapFromItem( m_endPort, eRect.bottomRight()/2 ) );
QLineF line( tmpLine.x1(), tmpLine.y1()+5, tmpLine.x2(), tmpLine.y2()-5 );
setLine( line );
}
WQtNetworkOutputPort* WQtNetworkArrow::getStartPort()
{
return m_startPort;
}
WQtNetworkInputPort* WQtNetworkArrow::getEndPort()
{
return m_endPort;
}
QVariant WQtNetworkArrow::itemChange( GraphicsItemChange change,
const QVariant &value )
{
if( change == QGraphicsItem::ItemSelectedHasChanged )
{
changeColor( Qt::black );
}
return value;
}
void WQtNetworkArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* w )
{
if( isSelected() &&
m_color != Qt::green )
{
changeColor( Qt::green );
}
QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*>( option );
o->state &= ~QStyle::State_Selected;
QGraphicsLineItem::paint( painter, o, w );
qreal arrowSize = 10;
double angle = ::acos( line().dx() / line().length() );
if ( line().dy() >= 0 )
angle = ( Pi * 2 ) - angle;
QPointF arrowP1 = line().p2() - QPointF( sin( angle + Pi / 3 ) * arrowSize,
cos( angle + Pi / 3 ) * arrowSize );
QPointF arrowP2 = line().p2() - QPointF( sin( angle + Pi - Pi / 3 ) * arrowSize,
cos( angle + Pi - Pi / 3 ) * arrowSize );
arrowHead.clear();
arrowHead << line().p2() << arrowP1 << arrowP2;
painter->setPen( QPen( m_color, 1, Qt::SolidLine ) );
painter->setBrush( m_color );
painter->drawPolygon( arrowHead );
}
QRectF WQtNetworkArrow::boundingRect() const
{
QRectF rect = shape().boundingRect();
// add a few extra pixels for the arrow and the pen
qreal penWidth = 1;
qreal extra = ( penWidth + 10 ) / 2.0;
rect.adjust( -extra, -extra, extra, extra );
return rect;
}
QPainterPath WQtNetworkArrow::shape() const
{
QPainterPath path = QGraphicsLineItem::shape();
path.addPolygon( arrowHead );
return path;
}
void WQtNetworkArrow::hoverEnterEvent( QGraphicsSceneHoverEvent * event )
{
Q_UNUSED( event );
changeColor( Qt::green );
updatePosition();
}
void WQtNetworkArrow::hoverLeaveEvent( QGraphicsSceneHoverEvent * event )
{
Q_UNUSED( event );
changeColor( Qt::black );
}
void WQtNetworkArrow::changeColor( QColor color )