Commit 909b7960 authored by Emmanuel Promayon's avatar Emmanuel Promayon

NEW icon is now visible in the dock window title as well

parent ff4c6426
......@@ -152,4 +152,4 @@ set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_
set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/component/image CACHE INTERNAL "")
set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/component/mesh CACHE INTERNAL "")
set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/utils CACHE INTERNAL "")
set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/viewer CACHE INTERNAL "")
\ No newline at end of file
set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/viewer CACHE INTERNAL "")
......@@ -27,6 +27,7 @@
#include "Component.h"
#include "Application.h"
#include "MainWindow.h"
#include "ViewerDockStyle.h"
#include "Log.h"
......@@ -43,6 +44,7 @@ Viewer::Viewer(QString name, ViewerType type): QObject() {
this->type = type;
dockWidget = nullptr;
dockWidgetStyle = nullptr;
embedder = nullptr;
toolbarVisibility = true;
......@@ -52,6 +54,7 @@ Viewer::Viewer(QString name, ViewerType type): QObject() {
//---------------------- destructor ------------------------
Viewer::~Viewer() {
delete dockWidgetStyle;
}
// -------------------- setIcon --------------------
......@@ -127,6 +130,9 @@ bool Viewer::setDockWidget(QDockWidget* dockWidget) {
// set the object name and the visible window title
dockWidget->setObjectName(name);
dockWidget->setWindowTitle(name);
// set the style so that the icon is visible
dockWidgetStyle = new ViewerDockStyle(this);
dockWidget->setStyle(dockWidgetStyle);
// add the widget
dockWidget->setWidget(getWidget());
// store the pointer
......
......@@ -45,6 +45,7 @@ namespace camitk {
class Component;
class ViewerExtension;
class Property;
class ViewerDockStyle;
/**
* @ingroup group_sdk_libraries_core_viewer
......@@ -208,6 +209,9 @@ private:
/// the Viewer pixmap icon
QPixmap icon;
/// the style for the dock widget
ViewerDockStyle* dockWidgetStyle;
/// list of Component class name managed by this viewer
QStringList components;
......
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK 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 version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#include <ViewerDockStyle.h>
#include <Viewer.h>
namespace camitk {
//---------------------- constructor ------------------------
ViewerDockStyle::ViewerDockStyle(Viewer* viewer) : QProxyStyle(nullptr) {
icon = new QIcon(viewer->getIcon());
}
//---------------------- destructor ------------------------
ViewerDockStyle::~ViewerDockStyle() {
delete icon;
}
//---------------------- drawControl ------------------------
void ViewerDockStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const {
if (element == QStyle::CE_DockWidgetTitle) {
// width of the icon
int width = pixelMetric(QStyle::PM_ToolBarIconSize);
// margin of title from frame
int margin = baseStyle()->pixelMetric(QStyle::PM_DockWidgetTitleMargin);
// starting position of the icon
QPoint iconPosition(margin + option->rect.left(), margin + option->rect.center().y() - width / 2);
painter->drawPixmap(iconPosition, icon->pixmap(width, width));
const_cast<QStyleOption*>(option)->rect = option->rect.adjusted(width, 0, 0, 0);
}
baseStyle()->drawControl(element, option, painter, widget);
}
}
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK 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 version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#ifndef VIEWERDOCKSTYLE_H
#define VIEWERDOCKSTYLE_H
// -- Core stuff
#include "CamiTKAPI.h"
#include <QProxyStyle>
#include <QStyleOption>
#include <QPainter>
namespace camitk {
class Viewer;
/**
* @ingroup group_sdk_libraries_core_viewer
*
* @brief a specific style made for QDockWidget that adds an icon to the dock widget title
*
* Greatly inspired by https://stackoverflow.com/a/3482795
*/
class CAMITK_API ViewerDockStyle : public QProxyStyle {
Q_OBJECT
public:
/// constructor just set the viewer that is using this style
ViewerDockStyle(Viewer*);
/// destructor
virtual ~ViewerDockStyle();
/// override method from QProxyStyle
virtual void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0) const override;
private:
/// icon generated from the viewer pixmap
QIcon* icon;
};
}
#endif // VIEWERDOCKSTYLE_H
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