Skip to content

Commit

Permalink
ENH: Switch to new Slicer logo in module panel
Browse files Browse the repository at this point in the history
Switch to the new Slicer logo: it is more compact than the old one and works with both dark and bright background (see #5367).

For crisp rendering of the new icon, Qt::AA_UseHighDpiPixmaps application option is now enabled.
If higher-resolution variants of icons are provided by ...@2x.png, ...@3x.png, ... names then they are now used on high-DPI displays.

Move the logo to the module panel dockable widget's header to save space. See discussion at #5820 for more details.

Co-authored-by: James Butler <jbutler@sonovol.com>
  • Loading branch information
lassoan and jamesobutler committed Sep 20, 2021
1 parent 5a44b5e commit d2d11dd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Applications/SlicerApp/Resources/SlicerApp.qrc
Expand Up @@ -8,5 +8,6 @@
<file alias="SplashScreen.png">Images/Slicer-SplashScreen.png</file>
<file alias="Logo.png">Images/Slicer-Logo.png</file>
<file alias="ModulePanelLogo.png">Images/Slicer-ModulePanelLogo.png</file>
<file alias="ModulePanelLogo@2x.png">Images/Slicer-ModulePanelLogo@2x.png</file>
</qresource>
</RCC>
15 changes: 14 additions & 1 deletion Applications/SlicerApp/qSlicerAppMainWindow.cxx
Expand Up @@ -23,6 +23,7 @@

// Qt includes
#include <QDesktopServices>
#include <QLabel>
#include <QPixmap>
#include <QStyle>
#include <QUrl>
Expand Down Expand Up @@ -117,7 +118,19 @@ void qSlicerAppMainWindowPrivate::setupUi(QMainWindow * mainWindow)
mainWindow->setWindowTitle("3D Slicer");
mainWindow->setWindowIcon(QIcon(":/Icons/Medium/DesktopIcon.png"));

this->LogoLabel->setPixmap(QPixmap(":/ModulePanelLogo.png"));
QLabel* logoLabel = new QLabel();
logoLabel->setObjectName("LogoLabel");
// QIcon stores multiple versions of the image (in different sizes)
// and uses the most suitable one (depending on DevicePixelRatio).
// QLabel cannot take a QIcon, therefore we need to get the most suitable
// QPixmap from the QIcon (base.png, base@2x, ...).
// To achieve this, we first determine the pixmap size in device independent units,
// which is the size of the base image (icon.availableSizes().first(), because for that
// DevicePixelRatio=1.0), and then we retieve the pixmap for this size.
QIcon icon = QIcon(":/ModulePanelLogo.png");
QPixmap logo = icon.pixmap(icon.availableSizes().first());
logoLabel->setPixmap(logo);
this->PanelDockWidget->setTitleBarWidget(logoLabel);

this->HelpMenu->addAction(helpKeyboardShortcutsAction);
this->HelpMenu->addAction(helpInterfaceDocumentationAction);
Expand Down
12 changes: 4 additions & 8 deletions Base/QTApp/Resources/UI/qSlicerMainWindow.ui
Expand Up @@ -45,13 +45,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="LogoLabel">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<widget class="qSlicerModulePanel" name="ModulePanel"/>
</item>
Expand All @@ -66,6 +59,9 @@
<property name="text">
<string>Data Probe</string>
</property>
<property name="collapsedHeight">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</widget>
</item>
Expand Down Expand Up @@ -217,7 +213,7 @@
<x>0</x>
<y>0</y>
<width>835</width>
<height>25</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="FileMenu">
Expand Down
9 changes: 9 additions & 0 deletions Libs/MRML/Widgets/qMRMLWidget.cxx
Expand Up @@ -130,6 +130,15 @@ void qMRMLWidget::preInitializeApplication()
// Enable automatic scaling based on the pixel density of the monitor
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

// Enable QIcon to provide higher-resolution pixmaps than the size in device independent units.
// These pixmaps render sharply on a high-dpi display.
// If Qt::AA_UseHighDpiPixmaps is enabled then when an icon is loaded by the filename "base.png" then the icon
// class will also look for higher-resolution variants of this image by the names base@2x.png, base@3x.png, etc.
// On a high-DPI monitor (with DevicePixelRatio > 1) QIcon will actually load a higher-resolution pixmap
// that best matches the DevicePixelRatio of the display, resulting in crisp rendering of the icon.
// See https://doc.qt.io/qt-5/qicon.html#pixmap for more details.
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

// Enables resource sharing between the OpenGL contexts used by classes like QOpenGLWidget and QQuickWidget
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
}
Expand Down

0 comments on commit d2d11dd

Please sign in to comment.