File indexing completed on 2024-05-12 03:48:24
0001 /* 0002 File : PartMdiView.cpp 0003 Project : LabPlot 0004 Description : QMdiSubWindow wrapper for aspect views. 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2013-2019 Alexander Semke <alexander.semke@web.de> 0007 SPDX-FileCopyrightText: 2007, 2008 Tilman Benkert <thzs@gmx.net> 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "commonfrontend/core/ContentDockWidget.h" 0012 #include "backend/core/AbstractPart.h" 0013 #include "backend/worksheet/Worksheet.h" 0014 0015 #include <DockWidget.h> 0016 0017 #include <QCloseEvent> 0018 #include <QIcon> 0019 #include <QUuid> 0020 0021 /*! 0022 * \class PartMdiView 0023 * 0024 * \brief QMdiSubWindow wrapper for aspect views. 0025 * 0026 * In addition to the functionality provided by QMdiSubWindow, 0027 * this class automatically updates the window title when AbstractAspect::caption() is changed 0028 * and holds the connection to the actual data visualized in this window via the pointer to \c AbstractPart. 0029 */ 0030 ContentDockWidget::ContentDockWidget(AbstractPart* part) 0031 : ads::CDockWidget(part->name()) 0032 , m_part(part) { 0033 setWindowIcon(m_part->icon()); 0034 setWidget(m_part->view()); 0035 handleAspectDescriptionChanged(m_part); 0036 0037 // resize the MDI sub window to fit the content of the view 0038 resize(m_part->view()->size()); 0039 // Must be unique and must not be changed after the dock was added to the dockmanager, because 0040 // the objectname is used in the content manager map 0041 setObjectName(m_part->uuid().toString()); 0042 0043 connect(m_part, &AbstractPart::aspectDescriptionChanged, this, &ContentDockWidget::handleAspectDescriptionChanged); 0044 connect(m_part, QOverload<const AbstractAspect*>::of(&AbstractPart::childAspectAboutToBeRemoved), this, &ContentDockWidget::handleAspectAboutToBeRemoved); 0045 } 0046 0047 ContentDockWidget::~ContentDockWidget() { 0048 m_closing = true; 0049 } 0050 0051 AbstractPart* ContentDockWidget::part() const { 0052 return m_part; 0053 } 0054 0055 void ContentDockWidget::handleAspectDescriptionChanged(const AbstractAspect* aspect) { 0056 if (aspect != m_part) 0057 return; 0058 0059 setWindowTitle(m_part->name()); 0060 } 0061 0062 void ContentDockWidget::handleAspectAboutToBeRemoved(const AbstractAspect* aspect) { 0063 if (aspect != m_part) 0064 return; 0065 0066 close(); 0067 } 0068 0069 void ContentDockWidget::slotWindowStateChanged(Qt::WindowStates /*oldState*/, Qt::WindowStates newState) { 0070 if (m_closing) 0071 return; 0072 0073 if (newState.testFlag(Qt::WindowActive) || newState.testFlag(Qt::WindowMaximized)) 0074 m_part->registerShortcuts(); 0075 else 0076 m_part->unregisterShortcuts(); 0077 }