LCOV - code coverage report
Current view: top level - muse/framework/dockwindow/internal - dockbase.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 55.2 % 464 256
Test Date: 2026-11-19 04:14:36

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #include "dockbase.h"
      24              : 
      25              : #include <QRect>
      26              : #include <QTimer>
      27              : 
      28              : #include "log.h"
      29              : 
      30              : #include "kddockwidgets/src/core/DockWidget.h"
      31              : #include "kddockwidgets/src/core/FloatingWindow.h"
      32              : #include "kddockwidgets/src/core/Group.h"
      33              : #include "kddockwidgets/src/qtquick/views/DockWidget.h"
      34              : #include "kddockwidgets/src/qtquick/views/Group.h"
      35              : #include "kddockwidgets/src/qtquick/views/View.h"
      36              : #include "kddockwidgets/src/qtquick/Action.h"
      37              : 
      38              : // This include pulls in kdbindings/signal.h which is incompatible with
      39              : // Qt's `emit` macro being defined. Temporarily undefine it, then restore it.
      40              : #ifdef emit
      41              : #undef emit
      42              : #include "kddockwidgets/src/core/layouting/Item_p.h"
      43              : #define emit
      44              : #else
      45              : #include "kddockwidgets/src/core/layouting/Item_p.h"
      46              : #endif
      47              : 
      48              : #include "ui/qml/Muse/Ui/navigationsection.h"
      49              : 
      50              : #include "muse_framework_config.h"
      51              : 
      52              : namespace muse::dock {
      53            0 : static QSize adjustSizeByConstraints(const QSize& size, const QSize& min, const QSize& max)
      54              : {
      55            0 :     return size.expandedTo(min).boundedTo(max);
      56              : }
      57              : 
      58          276 : static KDDockWidgets::Core::Group* groupForDockWidget(KDDockWidgets::Core::DockWidget* dw)
      59              : {
      60          276 :     if (!dw) {
      61            0 :         return nullptr;
      62              :     }
      63          552 :     auto* view = qobject_cast<KDDockWidgets::QtQuick::DockWidget*>(
      64          276 :         KDDockWidgets::QtQuick::asQQuickItem(dw));
      65          276 :     return view ? view->group() : nullptr;
      66              : }
      67              : 
      68           12 : static KDDockWidgets::QtQuick::Group* groupViewFor(KDDockWidgets::Core::Group* group)
      69              : {
      70           12 :     if (!group) {
      71            0 :         return nullptr;
      72              :     }
      73           24 :     return qobject_cast<KDDockWidgets::QtQuick::Group*>(
      74           12 :         KDDockWidgets::QtQuick::asQQuickItem(group));
      75              : }
      76              : }
      77              : 
      78              : using namespace muse::dock;
      79              : 
      80           52 : DockBase::DockBase(DockType type, QQuickItem* parent)
      81           52 :     : QQuickItem(parent), Contextable(muse::iocCtxForQmlObject(this))
      82              : {
      83           52 :     Q_ASSERT(type != DockType::Undefined);
      84              : 
      85           52 :     m_properties.type = type;
      86           52 :     m_properties.floatable = true;
      87           52 :     m_properties.closable = true;
      88           52 :     m_properties.resizable = true;
      89           52 :     m_properties.separatorsVisible = true;
      90           52 : }
      91              : 
      92            0 : QString DockBase::title() const
      93              : {
      94            0 :     return m_title;
      95              : }
      96              : 
      97           68 : int DockBase::minimumWidth() const
      98              : {
      99           68 :     return m_minimumWidth;
     100              : }
     101              : 
     102            6 : int DockBase::minimumHeight() const
     103              : {
     104            6 :     return m_minimumHeight;
     105              : }
     106              : 
     107           68 : int DockBase::maximumWidth() const
     108              : {
     109           68 :     return m_maximumWidth;
     110              : }
     111              : 
     112            6 : int DockBase::maximumHeight() const
     113              : {
     114            6 :     return m_maximumHeight;
     115              : }
     116              : 
     117          133 : int DockBase::contentWidth() const
     118              : {
     119          133 :     return m_contentWidth;
     120              : }
     121              : 
     122            0 : int DockBase::contentHeight() const
     123              : {
     124            0 :     return m_contentHeight;
     125              : }
     126              : 
     127           12 : QSize DockBase::preferredSize() const
     128              : {
     129           12 :     return QSize(width(), height());
     130              : }
     131              : 
     132            0 : int DockBase::locationProperty() const
     133              : {
     134            0 :     return static_cast<int>(m_properties.location);
     135              : }
     136              : 
     137            3 : Location DockBase::location() const
     138              : {
     139            3 :     return m_properties.location;
     140              : }
     141              : 
     142            0 : QPoint DockBase::globalPosition() const
     143              : {
     144            0 :     if (!m_dockWidget) {
     145            0 :         return QPoint();
     146              :     }
     147              : 
     148            0 :     KDDockWidgets::Core::Group* group = groupForDockWidget(m_dockWidget);
     149            0 :     if (!group) {
     150            0 :         return QPoint();
     151              :     }
     152              : 
     153            0 :     QQuickItem* groupView = KDDockWidgets::QtQuick::asQQuickItem(group);
     154            0 :     if (!groupView) {
     155            0 :         return QPoint();
     156              :     }
     157              : 
     158            0 :     return groupView->mapToGlobal(QPointF(0, 0)).toPoint();
     159              : }
     160              : 
     161            0 : QVariantList DockBase::dropDestinationsProperty() const
     162              : {
     163            0 :     return m_dropDestinations;
     164              : }
     165              : 
     166            6 : QList<DropDestination> DockBase::dropDestinations() const
     167              : {
     168            6 :     QList<DropDestination> result;
     169              : 
     170            6 :     for (const QVariant& obj : m_dropDestinations) {
     171            0 :         QVariantMap map = obj.toMap();
     172              : 
     173            0 :         DropDestination destination;
     174            0 :         destination.dock = map["dock"].value<DockBase*>();
     175              : 
     176            0 :         if (map.contains("dropLocation")) {
     177            0 :             destination.dropLocation = static_cast<Location>(map["dropLocation"].toInt());
     178              :         } else {
     179            0 :             destination.dropLocation = Location::Left;
     180              :         }
     181              : 
     182            0 :         if (map.contains("dropDistance")) {
     183            0 :             destination.dropDistance = map["dropDistance"].toInt();
     184              :         }
     185              : 
     186            0 :         result << destination;
     187            0 :     }
     188              : 
     189            6 :     return result;
     190            0 : }
     191              : 
     192            0 : bool DockBase::closable() const
     193              : {
     194            0 :     return m_properties.closable;
     195              : }
     196              : 
     197            0 : bool DockBase::resizable() const
     198              : {
     199            0 :     return m_properties.resizable;
     200              : }
     201              : 
     202            0 : bool DockBase::separatorsVisible() const
     203              : {
     204            0 :     return m_properties.separatorsVisible;
     205              : }
     206              : 
     207           12 : bool DockBase::defaultVisibility() const
     208              : {
     209           12 :     return m_defaultVisibility;
     210              : }
     211              : 
     212           30 : bool DockBase::isCompact() const
     213              : {
     214           30 :     return m_isCompact;
     215              : }
     216              : 
     217           69 : int DockBase::compactPriorityOrder() const
     218              : {
     219           69 :     return m_compactPriorityOrder;
     220              : }
     221              : 
     222            7 : int DockBase::nonCompactWidth() const
     223              : {
     224            7 :     return m_nonCompactWidth;
     225              : }
     226              : 
     227           15 : bool DockBase::floatable() const
     228              : {
     229           15 :     return m_properties.floatable;
     230              : }
     231              : 
     232          101 : bool DockBase::floating() const
     233              : {
     234          101 :     return m_floating;
     235              : }
     236              : 
     237          127 : bool DockBase::inited() const
     238              : {
     239          127 :     return m_inited;
     240              : }
     241              : 
     242            0 : DockType DockBase::type() const
     243              : {
     244            0 :     return m_properties.type;
     245              : }
     246              : 
     247           54 : KDDockWidgets::Core::DockWidget* DockBase::dockWidget() const
     248              : {
     249           54 :     return m_dockWidget;
     250              : }
     251              : 
     252            0 : void DockBase::setTitle(const QString& title)
     253              : {
     254            0 :     if (title == m_title) {
     255            0 :         return;
     256              :     }
     257              : 
     258            0 :     m_title = title;
     259            0 :     emit titleChanged();
     260              : }
     261              : 
     262           49 : void DockBase::setMinimumWidth(int width)
     263              : {
     264           49 :     if (width == minimumWidth()) {
     265           13 :         return;
     266              :     }
     267              : 
     268           36 :     m_minimumWidth = width;
     269           36 :     emit minimumSizeChanged();
     270              : }
     271              : 
     272            6 : void DockBase::setMinimumHeight(int height)
     273              : {
     274            6 :     if (height == minimumHeight()) {
     275            0 :         return;
     276              :     }
     277              : 
     278            6 :     m_minimumHeight = height;
     279            6 :     emit minimumSizeChanged();
     280              : }
     281              : 
     282           49 : void DockBase::setMaximumWidth(int width)
     283              : {
     284           49 :     if (width == maximumWidth()) {
     285            1 :         return;
     286              :     }
     287              : 
     288           48 :     m_maximumWidth = width;
     289           48 :     emit maximumSizeChanged();
     290              : }
     291              : 
     292            6 : void DockBase::setMaximumHeight(int height)
     293              : {
     294            6 :     if (height == maximumHeight()) {
     295            0 :         return;
     296              :     }
     297              : 
     298            6 :     m_maximumHeight = height;
     299            6 :     emit maximumSizeChanged();
     300              : }
     301              : 
     302           53 : void DockBase::setContentWidth(int width)
     303              : {
     304           53 :     if (m_contentWidth == width) {
     305            0 :         return;
     306              :     }
     307              : 
     308           53 :     m_contentWidth = width;
     309           53 :     emit contentSizeChanged();
     310              : }
     311              : 
     312            6 : void DockBase::setContentHeight(int height)
     313              : {
     314            6 :     if (m_contentHeight == height) {
     315            0 :         return;
     316              :     }
     317              : 
     318            6 :     m_contentHeight = height;
     319            6 :     emit contentSizeChanged();
     320              : }
     321              : 
     322           49 : void DockBase::setLocation(int location)
     323              : {
     324           49 :     if (location == m_properties.location) {
     325            0 :         return;
     326              :     }
     327              : 
     328           49 :     m_properties.location = static_cast<Location>(location);
     329           49 :     emit locationChanged();
     330              : }
     331              : 
     332            0 : void DockBase::setDropDestinations(const QVariantList& destinations)
     333              : {
     334            0 :     if (m_dropDestinations == destinations) {
     335            0 :         return;
     336              :     }
     337              : 
     338            0 :     m_dropDestinations = destinations;
     339            0 :     emit dropDestinationsChanged();
     340              : }
     341              : 
     342            3 : void DockBase::setFloatable(bool floatable)
     343              : {
     344            3 :     if (floatable == m_properties.floatable) {
     345            0 :         return;
     346              :     }
     347              : 
     348            3 :     m_properties.floatable = floatable;
     349            3 :     emit floatableChanged();
     350              : }
     351              : 
     352            3 : void DockBase::setClosable(bool closable)
     353              : {
     354            3 :     if (closable == m_properties.closable) {
     355            0 :         return;
     356              :     }
     357              : 
     358            3 :     m_properties.closable = closable;
     359            3 :     emit closableChanged();
     360              : }
     361              : 
     362            0 : void DockBase::setResizable(bool resizable)
     363              : {
     364            0 :     if (resizable == m_properties.resizable) {
     365            0 :         return;
     366              :     }
     367              : 
     368            0 :     m_properties.resizable = resizable;
     369            0 :     emit resizableChanged();
     370              : }
     371              : 
     372            0 : void DockBase::setSeparatorsVisible(bool visible)
     373              : {
     374            0 :     if (visible == m_properties.separatorsVisible) {
     375            0 :         return;
     376              :     }
     377              : 
     378            0 :     m_properties.separatorsVisible = visible;
     379            0 :     emit separatorsVisibleChanged();
     380              : }
     381              : 
     382           11 : void DockBase::setIsCompact(bool compact)
     383              : {
     384           11 :     if (m_isCompact == compact) {
     385            0 :         return;
     386              :     }
     387              : 
     388           11 :     if (compact) {
     389            8 :         m_nonCompactWidth = width();
     390              :     }
     391              : 
     392           11 :     m_isCompact = compact;
     393           11 :     emit isCompactChanged();
     394              : }
     395              : 
     396           40 : void DockBase::setCompactPriorityOrder(int order)
     397              : {
     398           40 :     if (m_compactPriorityOrder == order) {
     399           24 :         return;
     400              :     }
     401              : 
     402           16 :     m_compactPriorityOrder = order;
     403           16 :     emit compactPriorityOrderChanged();
     404              : }
     405              : 
     406            0 : void DockBase::setFloating(bool floating)
     407              : {
     408            0 :     IF_ASSERT_FAILED(m_dockWidget) {
     409            0 :         return;
     410              :     }
     411              : 
     412            0 :     m_dockWidget->setFloating(floating);
     413              : }
     414              : 
     415            0 : void DockBase::setNavigationSection(ui::NavigationSection* section)
     416              : {
     417            0 :     if (m_navigationSection == section) {
     418            0 :         return;
     419              :     }
     420              : 
     421            0 :     m_navigationSection = section;
     422            0 :     emit navigationSectionChanged();
     423              : }
     424              : 
     425            0 : void DockBase::setContentNavigationPanelOrderStart(int order)
     426              : {
     427            0 :     if (m_contentNavigationPanelOrderStart == order) {
     428            0 :         return;
     429              :     }
     430              : 
     431            0 :     m_contentNavigationPanelOrderStart = order;
     432            0 :     emit contentNavigationPanelOrderStartChanged();
     433              : }
     434              : 
     435           12 : void DockBase::init()
     436              : {
     437           12 :     IF_ASSERT_FAILED(m_dockWidget) {
     438            0 :         return;
     439              :     }
     440              : 
     441           12 :     setVisible(m_dockWidget->isOpen());
     442           12 :     setInited(true);
     443              : 
     444           12 :     applySizeConstraints();
     445           12 :     updateFloatingStatus();
     446              : }
     447              : 
     448            0 : void DockBase::deinit()
     449              : {
     450            0 :     setInited(false);
     451            0 : }
     452              : 
     453           12 : bool DockBase::isOpen() const
     454              : {
     455           12 :     IF_ASSERT_FAILED(m_dockWidget) {
     456            0 :         return false;
     457              :     }
     458              : 
     459           12 :     return m_dockWidget->isOpen();
     460              : }
     461              : 
     462            0 : void DockBase::open()
     463              : {
     464            0 :     TRACEFUNC;
     465              : 
     466            0 :     IF_ASSERT_FAILED(m_dockWidget) {
     467            0 :         return;
     468              :     }
     469              : 
     470            0 :     setVisible(true);
     471            0 :     m_dockWidget->open();
     472              : 
     473            0 :     applySizeConstraints();
     474            0 : }
     475              : 
     476            0 : void DockBase::close()
     477              : {
     478            0 :     TRACEFUNC;
     479              : 
     480            0 :     IF_ASSERT_FAILED(m_dockWidget) {
     481            0 :         return;
     482              :     }
     483              : 
     484            0 :     m_dockWidget->close();
     485            0 :     setVisible(false);
     486            0 : }
     487              : 
     488            0 : void DockBase::showHighlighting(const QRect& highlightingRect)
     489              : {
     490            0 :     if (highlightingRect == m_properties.highlightingRect) {
     491            0 :         return;
     492              :     }
     493              : 
     494            0 :     m_properties.highlightingRect = highlightingRect;
     495            0 :     writeProperties();
     496              : }
     497              : 
     498            0 : void DockBase::hideHighlighting()
     499              : {
     500            0 :     showHighlighting(QRect());
     501            0 : }
     502              : 
     503            0 : QRect DockBase::frameGeometry() const
     504              : {
     505            0 :     if (m_dockWidget && m_dockWidget->isVisible()) {
     506            0 :         return m_dockWidget->groupGeometry();
     507              :     }
     508              : 
     509            0 :     return QRect();
     510              : }
     511              : 
     512            0 : bool DockBase::isInSameFrame(const DockBase* other) const
     513              : {
     514            0 :     IF_ASSERT_FAILED(other) {
     515            0 :         return false;
     516              :     }
     517              : 
     518            0 :     KDDockWidgets::Core::Group* group = groupForDockWidget(m_dockWidget);
     519            0 :     KDDockWidgets::Core::Group* otherGroup = groupForDockWidget(other->dockWidget());
     520              : 
     521            0 :     if (!group || !otherGroup) {
     522            0 :         return false;
     523              :     }
     524              : 
     525            0 :     return group == otherGroup;
     526              : }
     527              : 
     528            0 : void DockBase::setFramePanelOrder(int order)
     529              : {
     530            0 :     if (!m_dockWidget) {
     531            0 :         return;
     532              :     }
     533              : 
     534            0 :     KDDockWidgets::Core::Group* group = groupForDockWidget(m_dockWidget);
     535            0 :     if (!group) {
     536            0 :         return;
     537              :     }
     538              : 
     539            0 :     if (group->beingDeletedLater()) {
     540            0 :         return;
     541              :     }
     542              : 
     543            0 :     KDDockWidgets::QtQuick::Group* groupView = groupViewFor(group);
     544            0 :     if (!groupView) {
     545            0 :         return;
     546              :     }
     547              : 
     548            0 :     QQuickItem* frameVisualItem = groupView->visualItem();
     549            0 :     if (!frameVisualItem) {
     550            0 :         return;
     551              :     }
     552              : 
     553            0 :     frameVisualItem->setProperty("titleBarNavigationPanelOrder", order);
     554              : }
     555              : 
     556            0 : void DockBase::resetToDefault()
     557              : {
     558            0 :     setVisible(m_defaultVisibility);
     559            0 : }
     560              : 
     561            0 : void DockBase::resize(int width, int height)
     562              : {
     563            0 :     TRACEFUNC;
     564              : 
     565            0 :     if (!m_dockWidget) {
     566            0 :         return;
     567              :     }
     568              : 
     569            0 :     width = std::max(width, m_minimumWidth);
     570            0 :     height = std::max(height, m_minimumHeight);
     571              : 
     572            0 :     if (m_maximumWidth > 0) {
     573            0 :         width = std::min(width, std::max(m_maximumWidth, m_minimumWidth));
     574              :     }
     575              : 
     576            0 :     if (m_maximumHeight > 0) {
     577            0 :         height = std::min(height, std::max(m_maximumHeight, m_minimumHeight));
     578              :     }
     579              : 
     580              :     //! NOTE: Use the actual size in the layout, the item size may be overridden from QML
     581            0 :     const int deltaWidth = width - m_dockWidget->width();
     582            0 :     const int deltaHeight = height - m_dockWidget->height();
     583            0 :     if (deltaWidth == 0 && deltaHeight == 0) {
     584            0 :         return;
     585              :     }
     586              : 
     587            0 :     int left = 0;
     588            0 :     int top = 0;
     589            0 :     int right = 0;
     590            0 :     int bottom = 0;
     591              : 
     592            0 :     switch (location()) {
     593            0 :     case Location::Bottom: top = deltaHeight;
     594            0 :         break;
     595            0 :     case Location::Top: bottom = deltaHeight;
     596            0 :         break;
     597            0 :     case Location::Left: right = deltaWidth;
     598            0 :         break;
     599            0 :     case Location::Right: left = deltaWidth;
     600            0 :         break;
     601            0 :     case Location::Center:
     602            0 :     case Location::Undefined: break;
     603              :     }
     604              : 
     605            0 :     m_dockWidget->resizeInLayout(left, top, right, bottom);
     606            0 : }
     607              : 
     608            0 : muse::ui::INavigationSection* DockBase::navigationSection() const
     609              : {
     610            0 :     return m_navigationSection;
     611              : }
     612              : 
     613            0 : muse::ui::NavigationSection* DockBase::navigationSection_property() const
     614              : {
     615            0 :     return m_navigationSection;
     616              : }
     617              : 
     618            0 : int DockBase::contentNavigationPanelOrderStart() const
     619              : {
     620            0 :     return m_contentNavigationPanelOrderStart;
     621              : }
     622              : 
     623           12 : void DockBase::componentComplete()
     624              : {
     625           13 :     TRACEFUNC;
     626              : 
     627           12 :     QQuickItem::componentComplete();
     628              : 
     629           12 :     auto children = childItems();
     630           12 :     IF_ASSERT_FAILED_X(children.size() == 1, "Dock must have only one child as its content!") {
     631            0 :         return;
     632              :     }
     633              : 
     634           12 :     QQuickItem* content = children.first();
     635           12 :     IF_ASSERT_FAILED(content) {
     636            0 :         return;
     637              :     }
     638              : 
     639           12 :     const QString name = objectName();
     640              : 
     641           12 :     if (content->objectName().isEmpty()) {
     642           12 :         content->setObjectName(name + "_content");
     643              :     }
     644              : 
     645           12 :     auto* dockWidgetView = new KDDockWidgets::QtQuick::DockWidget(iocContext()->id, name);
     646           12 :     dockWidgetView->setObjectName(name);
     647           12 :     m_dockWidget = dockWidgetView->dockWidget();
     648           12 :     dockWidgetView->setGuestItem(content);
     649           12 :     m_dockWidget->setTitle(m_title);
     650              : 
     651           12 :     writeProperties();
     652           12 :     setUpFrameConnections();
     653              : 
     654           12 :     QQuickItem* dockWidgetItem = KDDockWidgets::QtQuick::asQQuickItem(m_dockWidget);
     655           12 :     connect(dockWidgetItem, &QQuickItem::widthChanged, this, [this]() {
     656           58 :         if (m_dockWidget) {
     657           58 :             setWidth(m_dockWidget->width());
     658           58 :             if (inited()) {
     659           16 :                 applySizeConstraints();
     660              :             }
     661              :         }
     662           58 :     });
     663              : 
     664           12 :     connect(dockWidgetItem, &QQuickItem::heightChanged, this, [this]() {
     665           69 :         if (m_dockWidget) {
     666           69 :             setHeight(m_dockWidget->height());
     667           69 :             if (inited()) {
     668           24 :                 applySizeConstraints();
     669              :             }
     670              :         }
     671           69 :     });
     672              : 
     673           12 :     connect(this, &DockBase::minimumSizeChanged, this, &DockBase::applySizeConstraints);
     674           12 :     connect(this, &DockBase::maximumSizeChanged, this, &DockBase::applySizeConstraints);
     675              : 
     676           12 :     m_defaultVisibility = isVisible();
     677           12 : }
     678              : 
     679           91 : void DockBase::applySizeConstraints()
     680              : {
     681           91 :     if (!m_dockWidget) {
     682            0 :         return;
     683              :     }
     684              : 
     685           92 :     TRACEFUNC;
     686              : 
     687           91 :     KDDockWidgets::Core::View* dockWidgetView = m_dockWidget->view();
     688              : 
     689           91 :     int minWidth = m_minimumWidth > 0 ? m_minimumWidth : dockWidgetView->minSize().width();
     690           91 :     int minHeight = m_minimumHeight > 0 ? m_minimumHeight : dockWidgetView->minSize().height();
     691           91 :     int maxWidth = m_maximumWidth > 0 ? m_maximumWidth : dockWidgetView->maxSizeHint().width();
     692           91 :     int maxHeight = m_maximumHeight > 0 ? m_maximumHeight : dockWidgetView->maxSizeHint().height();
     693              : 
     694           91 :     minWidth = std::min(minWidth, maxWidth);
     695           91 :     minHeight = std::min(minHeight, maxHeight);
     696           91 :     maxWidth = std::max(maxWidth, minWidth);
     697           91 :     maxHeight = std::max(maxHeight, minHeight);
     698              : 
     699           91 :     QSize minimumSize(minWidth, minHeight);
     700           91 :     QSize maximumSize(maxWidth, maxHeight);
     701              : 
     702           91 :     if (!m_properties.resizable) {
     703            0 :         maximumSize = minimumSize;
     704              :     }
     705              : 
     706           91 :     KDDockWidgets::Core::Group* group = groupForDockWidget(m_dockWidget);
     707              : 
     708              :     //! NOTE: Skip applying floating size constraints while the dock's group is still in the main
     709              :     //!       layout - fixes the top row growing taller on undock.
     710           91 :     if (m_floating && group && group->isInMainWindow()) {
     711            0 :         return;
     712              :     }
     713              : 
     714           91 :     if (group) {
     715           85 :         group->view()->setMinimumSize(minimumSize);
     716           85 :         group->view()->setMaximumSize(maximumSize);
     717              :     }
     718              : 
     719           91 :     dockWidgetView->setMinimumSize(minimumSize);
     720           91 :     dockWidgetView->setMaximumSize(maximumSize);
     721              : 
     722           91 :     if (KDDockWidgets::Core::FloatingWindow* window = m_dockWidget->floatingWindow()) {
     723              :         //! NOTE: The floating window draws shadow around the dock content (see DockFloatingWindow.qml),
     724              :         //! so the window must be larger than the content by that shadow on each side.
     725            0 :         const int shadow = 2 * (DOCK_WINDOW_SHADOW + 1 /*border*/);
     726            0 :         const QSize windowMinimumSize = minimumSize + QSize(shadow, shadow);
     727            0 :         const QSize windowMaximumSize = maximumSize + QSize(shadow, shadow);
     728              : 
     729            0 :         window->view()->setMinimumSize(windowMinimumSize);
     730            0 :         window->view()->setMaximumSize(windowMaximumSize);
     731              : 
     732            0 :         const QSize winSize = adjustSizeByConstraints(window->view()->geometry().size(), windowMinimumSize, windowMaximumSize);
     733            0 :         const QRect winRect(window->dragRect().topLeft(), winSize);
     734            0 :         window->view()->setGeometry(winRect);
     735              :     }
     736              : 
     737              :     //! NOTE: The group derives its minimum size from its dock widgets, so the layout
     738              :     //! picks up the old minimum when the group constraints are applied
     739           91 :     syncLayoutItemMinSize();
     740              : 
     741              :     //! NOTE: The layout doesn't shrink the item when the maximum size decreases
     742           91 :     fitSizeIntoMaximum();
     743           91 : }
     744              : 
     745           91 : void DockBase::fitSizeIntoMaximum()
     746              : {
     747           91 :     if (!m_dockWidget || !m_inited) {
     748           18 :         return;
     749              :     }
     750              : 
     751           73 :     KDDockWidgets::Core::Group* group = groupForDockWidget(m_dockWidget);
     752           73 :     if (!group || !group->isInMainWindow()) {
     753            0 :         return;
     754              :     }
     755              : 
     756              :     //! NOTE: The layout treats the maximum size only as a hint and doesn't shrink the item
     757              :     //! when it decreases, so shrink it explicitly. The side at the edge of the layout
     758              :     //! isn't changed, so shrink the opposite side if the excess remains
     759          152 :     auto excessWidth = [this]() {
     760          152 :         return m_maximumWidth > 0 ? m_dockWidget->width() - std::max(m_maximumWidth, m_minimumWidth) : 0;
     761           73 :     };
     762              : 
     763          236 :     auto excessHeight = [this]() {
     764          236 :         return m_maximumHeight > 0 ? m_dockWidget->height() - std::max(m_maximumHeight, m_minimumHeight) : 0;
     765           73 :     };
     766              : 
     767              :     //! NOTE: Left side
     768           73 :     if (excessWidth() > 0) {
     769            5 :         m_dockWidget->resizeInLayout(-excessWidth(), 0, 0, 0);
     770              :     }
     771              : 
     772              :     //! NOTE: Right side
     773           73 :     if (excessWidth() > 0) {
     774            1 :         m_dockWidget->resizeInLayout(0, 0, -excessWidth(), 0);
     775              :     }
     776              : 
     777              :     //! NOTE: Top side
     778           73 :     if (excessHeight() > 0) {
     779           45 :         m_dockWidget->resizeInLayout(0, -excessHeight(), 0, 0);
     780              :     }
     781              : 
     782              :     //! NOTE: Bottom side
     783           73 :     if (excessHeight() > 0) {
     784           45 :         m_dockWidget->resizeInLayout(0, 0, 0, -excessHeight());
     785              :     }
     786              : }
     787              : 
     788          100 : void DockBase::syncLayoutItemMinSize()
     789              : {
     790          100 :     if (!m_dockWidget) {
     791           18 :         return;
     792              :     }
     793              : 
     794          100 :     KDDockWidgets::Core::Group* group = groupForDockWidget(m_dockWidget);
     795          100 :     if (!group) {
     796            6 :         return;
     797              :     }
     798              : 
     799           94 :     KDDockWidgets::Core::Item* item = group->layoutItem();
     800           94 :     if (!item) {
     801           12 :         return;
     802              :     }
     803              : 
     804              :     //! NOTE: The layouting item caches the guest minimum; force it to match the group's current
     805              :     //! minimum so the container's minimum size reflects
     806           82 :     const QSize min = group->view()->minSize();
     807           82 :     if (item->minSize() != min) {
     808            9 :         item->setMinSize(min);
     809              :     }
     810              : }
     811              : 
     812           12 : void DockBase::setUpFrameConnections()
     813              : {
     814           12 :     IF_ASSERT_FAILED(m_dockWidget) {
     815            0 :         return;
     816              :     }
     817              : 
     818           12 :     QQuickItem* dockWidgetItem = KDDockWidgets::QtQuick::asQQuickItem(m_dockWidget);
     819           12 :     IF_ASSERT_FAILED(dockWidgetItem) {
     820            0 :         return;
     821              :     }
     822              : 
     823           12 :     auto floatingChangedConnection = std::make_shared<QMetaObject::Connection>();
     824           12 :     auto widgetChangedConnection = std::make_shared<QMetaObject::Connection>();
     825              : 
     826           12 :     connect(dockWidgetItem, &QQuickItem::parentChanged, this,
     827           24 :             [this, floatingChangedConnection, widgetChangedConnection]()
     828              :     {
     829           12 :         if (floatingChangedConnection) {
     830           12 :             disconnect(*floatingChangedConnection);
     831           12 :             doSetFloating(false);
     832              :         }
     833              : 
     834           12 :         if (widgetChangedConnection) {
     835           12 :             disconnect(*widgetChangedConnection);
     836              :         }
     837              : 
     838           12 :         QQuickItem* dockWidgetItem = KDDockWidgets::QtQuick::asQQuickItem(m_dockWidget);
     839           12 :         if (!m_dockWidget || !dockWidgetItem || !dockWidgetItem->parentItem()) {
     840            0 :             return;
     841              :         }
     842              : 
     843           12 :         KDDockWidgets::Core::Group* group = groupForDockWidget(m_dockWidget);
     844           12 :         if (!group) {
     845            0 :             return;
     846              :         }
     847              : 
     848              :         //! NOTE: window will be available later
     849              :         //! So it is important to apply size constraints
     850              :         //! and emit floatingChanged() after that
     851           12 :         QTimer::singleShot(0, this, [this]() {
     852           12 :             updateFloatingStatus();
     853              : 
     854           12 :             if (m_floating) {
     855            0 :                 applySizeConstraints();
     856              :             }
     857           12 :         });
     858              : 
     859           12 :         KDDockWidgets::QtQuick::Group* groupView = groupViewFor(group);
     860           12 :         if (groupView) {
     861           24 :             *floatingChangedConnection = connect(groupView, &QQuickItem::parentChanged,
     862           12 :                                                  this, &DockBase::onIsInMainWindowChanged,
     863           12 :                                                  Qt::UniqueConnection);
     864           24 :             *widgetChangedConnection = connect(groupView, &KDDockWidgets::QtQuick::Group::currentDockWidgetChanged,
     865           24 :                                                this, &DockBase::frameCurrentWidgetChanged,
     866           12 :                                                Qt::UniqueConnection);
     867              :         }
     868              :     });
     869              : 
     870           12 :     auto* action = static_cast<KDDockWidgets::QtQuick::Action*>(m_dockWidget->toggleAction());
     871           12 :     connect(action, &KDDockWidgets::QtQuick::Action::toggled, this, [this]() {
     872           12 :         if (!isOpen()) {
     873            0 :             doSetFloating(false);
     874              :         }
     875           12 :     });
     876           12 : }
     877              : 
     878           36 : void DockBase::updateFloatingStatus()
     879              : {
     880           36 :     bool floating = m_dockWidget && m_dockWidget->floatingWindow();
     881              : 
     882           36 :     doSetFloating(floating);
     883           36 : }
     884              : 
     885           12 : void DockBase::onIsInMainWindowChanged()
     886              : {
     887           12 :     updateFloatingStatus();
     888           12 :     applySizeConstraints();
     889           12 : }
     890              : 
     891           51 : void DockBase::doSetFloating(bool floating)
     892              : {
     893           51 :     if (m_floating == floating) {
     894           48 :         return;
     895              :     }
     896              : 
     897            3 :     m_floating = floating;
     898            3 :     emit floatingChanged();
     899              : }
     900              : 
     901           12 : void DockBase::writeProperties()
     902              : {
     903           12 :     if (m_dockWidget) {
     904           12 :         writePropertiesToObject(m_properties, *m_dockWidget);
     905              :     }
     906           12 : }
     907              : 
     908           12 : void DockBase::setInited(bool inited)
     909              : {
     910           12 :     if (m_inited == inited) {
     911            0 :         return;
     912              :     }
     913              : 
     914           12 :     m_inited = inited;
     915           12 :     emit initedChanged();
     916              : }
     917              : 
     918            0 : bool DropDestination::operator==(const DropDestination& dest) const
     919              : {
     920            0 :     return dock == dest.dock && dropLocation == dest.dropLocation && dropDistance == dest.dropDistance;
     921              : }
     922              : 
     923            0 : bool DropDestination::isValid() const
     924              : {
     925            0 :     return dock != nullptr;
     926              : }
     927              : 
     928            0 : void DropDestination::clear()
     929              : {
     930            0 :     dock = nullptr;
     931            0 :     dropLocation = Location::Undefined;
     932            0 :     dropDistance = 0;
     933            0 : }
        

Generated by: LCOV version 2.0-1