Commit 78d67341 authored by Emmanuel Promayon's avatar Emmanuel Promayon

NEW improved viewers and toolbar management

The MainWindow API is more clearly define. The distinction between
docked and central viewer is better, and now follow the same logic.
The viewer manages its own toolbar visibility while the MainWindow
manages the toolbar widget.
parent aa288e87
......@@ -85,7 +85,7 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") {
dockWidgetExplorer->raise();
}
showViewer(ActionViewer::getInstance(), false);
showDockViewer(ActionViewer::getInstance(), false);
ActionViewer::getInstance()->setSearchPanelVisible(true);
showStatusBar(true);
}
......@@ -292,9 +292,9 @@ void ImpMainWindow::initMenuBar() {
//--------------------------initToolBar-------------------------------
void ImpMainWindow::initToolBar() {
mainToolbar = addToolBar("Main toolbar");
mainToolbar = addToolBar("Main Toolbar");
// ensure object name is set for saving the state
mainToolbar->setObjectName("imp main toolbar");
mainToolbar->setObjectName("ImpMainWindow Main Toolbar");
mainToolbar->addAction(fileOpen);
mainToolbar->addAction(fileSave);
mainToolbar->addAction(QWhatsThis::createAction(this));
......@@ -387,21 +387,24 @@ void ImpMainWindow::resetWindows() {
addDockWidget(Qt::LeftDockWidgetArea, it.value());
it.value()->show();
}
else if (it.value()->widget() == FrameExplorer::getInstance()->getWidget(NULL)) {
removeDockWidget(it.value());
addDockWidget(Qt::LeftDockWidgetArea, it.value());
it.value()->show();
}
else if (it.value()->widget() == PropertyExplorer::getInstance()->getWidget()) {
removeDockWidget(it.value());
addDockWidget(Qt::LeftDockWidgetArea, it.value());
it.value()->show();
}
else if (it.value()->widget() == ActionViewer::getInstance()->getWidget()) {
removeDockWidget(it.value());
addDockWidget(Qt::RightDockWidgetArea, it.value());
it.value()->show();
}
else
if (it.value()->widget() == FrameExplorer::getInstance()->getWidget(NULL)) {
removeDockWidget(it.value());
addDockWidget(Qt::LeftDockWidgetArea, it.value());
it.value()->show();
}
else
if (it.value()->widget() == PropertyExplorer::getInstance()->getWidget()) {
removeDockWidget(it.value());
addDockWidget(Qt::LeftDockWidgetArea, it.value());
it.value()->show();
}
else
if (it.value()->widget() == ActionViewer::getInstance()->getWidget()) {
removeDockWidget(it.value());
addDockWidget(Qt::RightDockWidgetArea, it.value());
it.value()->show();
}
}
//Merge Explorer and FrameExplorer viewers in one layout
QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Explorer::getInstance(), NULL);
......@@ -489,6 +492,36 @@ void ImpMainWindow::updateViewMenu() {
}
}
// change the central viewer if there is more than one viewer in the central area
if (qobject_cast<QStackedWidget*>(centralWidget())->count() > 1) {
viewMenu->addSeparator()->setText(tr("Toggle Central Viewers"));
for(Viewer *v : viewers) {
int i = 0;
// beware that getWidget(..) requires a parent and as the widget was setup inside centralWidget()
// it was reparented to centralWidget() → use getWidget(centralWidget()) and not getWidget(this)
// in order not to modify the central widget parenting
while (i<qobject_cast<QStackedWidget*>(centralWidget())->count() && qobject_cast<QStackedWidget*>(centralWidget())->widget(i)!=v->getWidget(centralWidget()))
i++;
if (i<qobject_cast<QStackedWidget*>(centralWidget())->count()) {
viewMenu->addAction(v->objectName());
}
}
// // add a toggle action
// for (int i = 0; i < qobject_cast<QStackedWidget*>(centralWidget())->count(); i++) {
// QWidget* cWidget = qobject_cast<QStackedWidget*>(centralWidget())->widget(i);
// // get the viewer associated with the widget in the central area
// // beware that getWidget(..) requires a parent and as the widget was setup inside centralWidget()
// // it was reparented to centralWidget() → use getWidget(centralWidget()) and not getWidget(this)
// // in order not to modify the central widget parenting
// auto it = std::find_if(viewers.begin(), viewers.end(), [cWidget,centralWidget=centralWidget()](Viewer * v) {
// return v->getWidget(centralWidget) == cWidget;
// });
// Viewer* cViewer = (*it);
// viewMenu->addAction(cViewer->objectName());
// }
}
// insert viewers on/off actions
viewMenu->addSeparator()->setText(tr("Toggle Viewers"));
viewMenu->addAction(viewResetWindows);
......
......@@ -187,15 +187,10 @@ void MainWindow::setWindowSubtitle(QString subtitle) {
bool MainWindow::addViewer(Viewer* theViewer) {
if (!viewers.contains(theViewer)) {
viewers.append(theViewer);
// connect
connect(theViewer, SIGNAL(selectionChanged()), this, SLOT(refresh()));
// add the toolbar
if (theViewer->getToolBar()) {
QToolBar* viewerToolBar = theViewer->getToolBar();
addToolBar(viewerToolBar);
}
return true;
}
......@@ -207,10 +202,33 @@ bool MainWindow::removeViewer(Viewer* viewer) {
return true;
}
// ------------- showDockViewer -----------------
void MainWindow::showDockViewer(Viewer* theViewer, bool visible) {
if (dockWidgetMap.contains(theViewer)) {
// set visibility of the viewer
dockWidgetMap[theViewer]->setVisible(visible);
// set visibility of the toolbar
showViewerToolbar(theViewer, visible);
}
}
// ------------- showViewer -----------------
void MainWindow::showViewer(Viewer* theViewer, bool visible) {
if (viewers.contains(theViewer)) {
dockWidgetMap[theViewer]->setVisible(visible);
showDockViewer(theViewer, visible);
}
// ------------- showViewerToolbar -----------------
void MainWindow::showViewerToolbar(Viewer* theViewer, bool visible) {
QToolBar* viewerToolBar = theViewer->getToolBar();
if (viewerToolBar != nullptr) {
if (visible && theViewer->getToolBarVisibility()) {
addToolBar(viewerToolBar);
viewerToolBar->setVisible(true);
}
else {
removeToolBar(viewerToolBar);
viewerToolBar->setVisible(false);
}
}
}
......@@ -219,49 +237,56 @@ void MainWindow::refreshViewers() {
foreach (Viewer* v, viewers) {
v->refresh();
}
// update the central viewer toolbar visibility
showViewerToolbar(centralViewer, true);
}
// ------------- addDockViewer -----------------
void MainWindow::addDockViewer(Qt::DockWidgetArea dockingArea, Viewer* theViewer) {
if (addViewer(theViewer)) {
// create the dock widget and insert it
QDockWidget* viewerDock = new QDockWidget(theViewer->objectName(), this);
viewerDock->setObjectName(theViewer->objectName());
QWidget* viewerWidget = theViewer->getWidget(viewerDock);
// create the dock widget and insert it only if the viewer has a widget
QWidget* viewerWidget = theViewer->getWidget(this);
if (viewerWidget) {
// add the widget
QDockWidget* viewerDock = new QDockWidget(theViewer->objectName(), this);
viewerDock->setObjectName(theViewer->objectName());
viewerDock->setWidget(viewerWidget);
addDockWidget(dockingArea, viewerDock);
// update map
// update the map
dockWidgetMap.insert(theViewer, viewerDock);
}
else {
delete viewerDock;
}
}
else {
dockWidgetMap.value(theViewer)->show();
}
// show the viewer anyway
showDockViewer(theViewer, true);
}
// ------------- setCentralViewer -----------------
void MainWindow::setCentralViewer(Viewer* theViewer) {
// get the viewer widget (must have something to show as it is a viewer after all!)
QWidget *viewerWidget = theViewer->getWidget(this);
QWidget* viewerWidget = theViewer->getWidget(this);
if (viewerWidget != nullptr) {
// add the viewer to the list (if not already in the list)
addViewer(theViewer);
// if needed, create the default (empty) central widget inside which the central viewers can be added
if (centralWidget()==0) {
setCentralWidget(new QStackedWidget(this));
// if needed, create the default (empty) central widget inside which the central viewers can be added
if (centralWidget() == 0) {
setCentralWidget(new QStackedWidget(this));
}
else {
// there is already a central viewer, just hide its toolbar
showViewerToolbar(centralViewer, false);
}
// add the widget to the central widget
// add the viewer's widget
qobject_cast<QStackedWidget*>(centralWidget())->addWidget(viewerWidget);
qobject_cast<QStackedWidget*>(centralWidget())->setCurrentWidget(viewerWidget);
centralViewer = theViewer;
// show its toolbar
showViewerToolbar(centralViewer, true);
}
}
......@@ -278,6 +303,8 @@ void MainWindow::refresh() {
v->refresh();
}
}
// update the central viewer toolbar visibility
showViewerToolbar(centralViewer, true);
}
// ------------- showStatusBar -----------------
......@@ -290,7 +317,6 @@ QProgressBar* MainWindow::getProgressBar() {
return myProgressBar;
}
// ------------- setApplicationConsole -----------------
void MainWindow::redirectToConsole(bool visible) {
if (visible) {
......
......@@ -124,12 +124,28 @@ public:
/// @name Viewers
///@{
///@cond
/**
* TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 5.0
* @deprecated
*
* DEPRECATED (CamiTK 5.0) -> to be removed
* This method is now called showDockViewer.
*/
/// set the visibility for the given viewer (if it is in a dock)
virtual void showViewer(Viewer*, bool);
///@endcond
/// set the visibility for the given docked viewer and its toolbar
virtual void showDockViewer(Viewer*, bool);
/** add a Viewer to the application as a docking widget and specify where it has to be docked
* Note that MainWindow takes ownership of the Viewer pointer and deletes it at the appropriate time.
*
* This method calls addViewer(...).
* This method calls showDockViewer(..,true) and therefore showViewerToolbar(..,true)
*
* \note MainWindow takes ownership of the viewer pointer and deletes it when it is itself destroyed.
*/
virtual void addDockViewer(Qt::DockWidgetArea, Viewer*);
......@@ -137,16 +153,26 @@ public:
void refreshViewers();
/** set the central Viewer of the application.
* Note that MainWindow takes ownership of the Viewer pointer and deletes it at the appropriate time.
* This method calls addViewer(...).
* The central viewer has a specific behaviour in a MainWindow. It uses a QStackWidget to keep
* all the central viewer that are used. When a new central viewers is set, the previous central
* viewer (i.e., its widget) is hidden but not destroyed.
*
* This method calls addViewer(..).
* This method calls showViewerToolbar(..,true)
*
* \note MainWindow takes ownership of the viewer pointer and deletes it when it is itself destroyed.
*/
virtual void setCentralViewer(Viewer*);
/**
* @Return the actual central viewer.
* @return
* @return the current central viewer.
*/
virtual const Viewer& getCentralViewer() const;
/** Set the visibility of a viewer's toolbar.
* This method respect the toolbar visibility property of the viewer.
*/
virtual void showViewerToolbar(Viewer* theViewer, bool visible);
///@}
public slots:
......@@ -194,9 +220,10 @@ protected:
/**
* TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 5.0
* @deprecated
*
* DEPRECATED (CamiTK 5.0) -> to be removed
* Removing viewers can be harmful. Central viewer is now simply hidden, therefore there is no need to remove it.
* It will keep itself refreshed and when shown again will be up to date.
* DEPRECATED (CamiTK 5.0) -> to be removed
*
* @brief Remove the given viewer from the list of viewer.
* @note This tell all Component not to be visible anymore in this viewer instance, remove it from the list of viewers and delete it.
......@@ -217,12 +244,11 @@ private:
/**
* Add a viewer (called by addDockViewer and setCentralViewer), returns true if not already added.
* Note that MainWindow takes ownership of the Viewer pointer and deletes it at the appropriate time.
* This method connects the selectionChanged signal of the viewer to the refresh method.
* Before CamiTK 4.x this method was a public method.
* Note that MainWindow takes ownership of the Viewer pointer and deletes it when it is itself destroyed.
*
* This method connects the selectionChanged signal of the viewer to the refresh method of MainWindow.
*/
virtual bool addViewer(Viewer*);
///@endcond
/// the output stream for the application console
ConsoleStream cout;
......
......@@ -135,25 +135,13 @@ QWidget* MedicalImageViewer::getWidget(QWidget* parent) {
viewers.insert(VIEWER_CORONAL, InteractiveViewer::getCoronalViewer());
viewers.insert(VIEWER_SAGITTAL, InteractiveViewer::getSagittalViewer());
//-- add the InteractiveViewers
// topLeftLayout = new QVBoxLayout();
// frameLayout->addLayout(topLeftLayout, 0, 0);
// topLeftLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame)); // north-west
// topLeftLayout->addWidget(InteractiveViewer::getArbitraryViewer()->getWidget(frame)); // north-west
// frameLayout->addWidget(InteractiveViewer::getCoronalViewer()->getWidget(frame), 0, 1); // north-east
// frameLayout->addWidget(InteractiveViewer::getSagittalViewer()->getWidget(frame), 1, 0); // south-west
// frameLayout->addWidget(InteractiveViewer::get3DViewer()->getWidget(frame), 1, 1); // south-east
topLeftLayout = new QVBoxLayout();
frameLayout->addLayout(topLeftLayout, 0, 0);
topLeftLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame));
// frameLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame), 0, 0); // north-west
topLeftLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame)); // equivalent of addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame), 0, 0) = north-west
frameLayout->addWidget(InteractiveViewer::getCoronalViewer()->getWidget(frame), 1, 0); // north-east
frameLayout->addWidget(InteractiveViewer::getSagittalViewer()->getWidget(frame), 1, 1); // south-west
frameLayout->addWidget(InteractiveViewer::get3DViewer()->getWidget(frame), 0, 1); // south-east
//-- connect
foreach (LayoutVisibility v, viewerVisibility) {
if (viewers.value(v)) { // prevent ALL
......@@ -247,8 +235,13 @@ void MedicalImageViewer::updateLayout() {
viewers.value(visibleLayout)->getWidget(frame)->show();
}
if (autoUpdateToolbarVisibility && (visibleLayout == VIEWER_3D || visibleLayout == VIEWER_ALL)) {
getToolBar()->show();
if (autoUpdateToolbarVisibility) {
if (visibleLayout == VIEWER_3D || visibleLayout == VIEWER_ALL) {
setToolBarVisibility(true);
}
else {
setToolBarVisibility(false);
}
}
}
......@@ -268,12 +261,9 @@ void MedicalImageViewer::synchronizeSelection() {
}
// -------------------- setToolbarAutoVisibility --------------------
void MedicalImageViewer::setToolbarAutoVisibility(bool toolbarVisibility) {
autoUpdateToolbarVisibility = toolbarVisibility;
getToolBar()->setVisible(autoUpdateToolbarVisibility);
if (!autoUpdateToolbarVisibility) {
getToolBar()->close();
}
void MedicalImageViewer::setToolbarAutoVisibility(bool toolbarAutoVisibility) {
autoUpdateToolbarVisibility = toolbarAutoVisibility;
setToolBarVisibility(false);
}
}
......
......@@ -32,6 +32,7 @@ namespace camitk {
//---------------------- constructor ------------------------
Viewer::Viewer(QString name): QObject() {
setObjectName(name);
toolbarVisibility = true;
}
//---------------------- selectionChanged ------------------------
......@@ -54,5 +55,14 @@ void Viewer::clearSelection() {
emit selectionChanged();
}
//---------------------- setToolBarVisibility ------------------------
void Viewer::setToolBarVisibility(bool toolbarVisibility) {
this->toolbarVisibility = toolbarVisibility;
}
//---------------------- getToolBarVisibility ------------------------
bool Viewer::getToolBarVisibility() {
return toolbarVisibility;
}
}
......@@ -86,6 +86,14 @@ public:
return nullptr;
};
/** set the visibility of the toolbar in the main window (true by default).
* If the visibility is set to false, the next call to setCentralViewer(..) or addDockViwer(...) will remove it
*/
void setToolBarVisibility(bool);
/// get the current value of the toolbar visibility
bool getToolBarVisibility();
/// Update the whole tree of the representation of the Component.
/// Is actually useful (and defined) in Explorer.
virtual void refreshInterfaceNode(Component* comp) {};
......@@ -109,6 +117,9 @@ protected:
/// clear the selection
void clearSelection();
private:
/// the current toolbar visibility
bool toolbarVisibility;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment