diff --git a/src/Config.cpp b/src/Config.cpp index 78c77eb0..313e32c2 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -172,6 +172,36 @@ TabbingAllowedFunc Config::tabbingAllowedFunc() const return d->m_tabbingAllowedFunc; } +void Config::setAbsoluteWidgetMinSize(QSize size) +{ + if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/ false)) { + qWarning() << Q_FUNC_INFO << "Only use this function at startup before creating any DockWidget or MainWindow"; + return; + } + + Layouting::Item::hardcodedMinimumSize = size; +} + +QSize Config::absoluteWidgetMinSize() const +{ + return Layouting::Item::hardcodedMinimumSize; +} + +void Config::setAbsoluteWidgetMaxSize(QSize size) +{ + if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/ false)) { + qWarning() << Q_FUNC_INFO << "Only use this function at startup before creating any DockWidget or MainWindow"; + return; + } + + Layouting::Item::hardcodedMaximumSize = size; +} + +QSize Config::absoluteWidgetMaxSize() const +{ + return Layouting::Item::hardcodedMaximumSize; +} + #ifdef KDDOCKWIDGETS_QTQUICK void Config::setQmlEngine(QQmlEngine *qmlEngine) { diff --git a/src/Config.h b/src/Config.h index 22a121f6..ebf1cd88 100644 --- a/src/Config.h +++ b/src/Config.h @@ -23,6 +23,7 @@ QT_BEGIN_NAMESPACE class QQmlEngine; +class QSize; QT_END_NAMESPACE namespace KDDockWidgets @@ -187,6 +188,18 @@ public: ///@sa setTabbingAllowedFunc(). TabbingAllowedFunc tabbingAllowedFunc() const; + ///@brief Sets the minimum size a dock widget can have. + /// Widgets can still provide their own min-size and it will be respected, however it can never be + /// smaller than this one. + void setAbsoluteWidgetMinSize(QSize size); + QSize absoluteWidgetMinSize() const; + + ///@brief Sets the maximum size a dock widget can have. + /// Widgets can still provide their own max-size and it will be respected, however it can never be + /// bigger than this one. + void setAbsoluteWidgetMaxSize(QSize size); + QSize absoluteWidgetMaxSize() const; + #ifdef KDDOCKWIDGETS_QTQUICK ///@brief Sets the QQmlEngine to use. Applicable only when using QtQuick. void setQmlEngine(QQmlEngine *); diff --git a/src/private/multisplitter/Item.cpp b/src/private/multisplitter/Item.cpp index b9646b3f..f88dc064 100644 --- a/src/private/multisplitter/Item.cpp +++ b/src/private/multisplitter/Item.cpp @@ -34,8 +34,10 @@ using namespace Layouting; int Layouting::Item::separatorThickness = 5; -const QSize Layouting::Item::hardcodedMinimumSize = QSize(KDDOCKWIDGETS_MIN_WIDTH, KDDOCKWIDGETS_MIN_HEIGHT); -const QSize Layouting::Item::hardcodedMaximumSize = QSize(KDDOCKWIDGETS_MAX_WIDTH, KDDOCKWIDGETS_MAX_HEIGHT); + +// There are the defaults. They can be changed by the user via Config.h API. +QSize Layouting::Item::hardcodedMinimumSize = QSize(80, 90); +QSize Layouting::Item::hardcodedMaximumSize = QSize(16777215, 16777215); bool Layouting::ItemContainer::s_inhibitSimplify = false; @@ -446,7 +448,7 @@ QSize Item::minSize() const QSize Item::maxSizeHint() const { - return m_sizingInfo.maxSizeHint.boundedTo(QSize(KDDOCKWIDGETS_MAX_WIDTH, KDDOCKWIDGETS_MAX_HEIGHT)); + return m_sizingInfo.maxSizeHint.boundedTo(hardcodedMaximumSize); } void Item::setPos(QPoint pos) @@ -731,7 +733,7 @@ void Item::dumpLayout(int level) << m_sizingInfo.geometry// << "r=" << m_geometry.right() << "b=" << m_geometry.bottom() << "; min=" << minSize(); - if (maxSizeHint() != QSize(KDDOCKWIDGETS_MAX_WIDTH, KDDOCKWIDGETS_MAX_HEIGHT)) + if (maxSizeHint() != hardcodedMaximumSize) dbg << "; max=" << maxSizeHint(); if (!isVisible()) @@ -1908,8 +1910,8 @@ QSize ItemContainer::minSize() const QSize ItemContainer::maxSizeHint() const { - int maxW = isVertical() ? KDDOCKWIDGETS_MAX_WIDTH : 0; - int maxH = isVertical() ? 0 : KDDOCKWIDGETS_MAX_HEIGHT; + int maxW = isVertical() ? hardcodedMaximumSize.width() : 0; + int maxH = isVertical() ? 0 : hardcodedMaximumSize.height(); const Item::List visibleChildren = this->visibleChildren(/*includeBeingInserted=*/ false); if (!visibleChildren.isEmpty()) { @@ -1921,26 +1923,26 @@ QSize ItemContainer::maxSizeHint() const const int itemMaxHeight = itemMaxSz.height(); if (isVertical()) { maxW = qMin(maxW, itemMaxWidth); - maxH = qMin(maxH + itemMaxHeight, KDDOCKWIDGETS_MAX_HEIGHT); + maxH = qMin(maxH + itemMaxHeight, hardcodedMaximumSize.height()); } else { maxH = qMin(maxH, itemMaxHeight); - maxW = qMin(maxW + itemMaxWidth, KDDOCKWIDGETS_MAX_WIDTH); + maxW = qMin(maxW + itemMaxWidth, hardcodedMaximumSize.width()); } } const int separatorWaste = (visibleChildren.size() - 1) * separatorThickness; if (isVertical()) { - maxH = qMin(maxH + separatorWaste, KDDOCKWIDGETS_MAX_HEIGHT); + maxH = qMin(maxH + separatorWaste, hardcodedMaximumSize.height()); } else { - maxW = qMin(maxW + separatorWaste, KDDOCKWIDGETS_MAX_WIDTH); + maxW = qMin(maxW + separatorWaste, hardcodedMaximumSize.width()); } } if (maxW == 0) - maxW = KDDOCKWIDGETS_MAX_WIDTH; + maxW = hardcodedMaximumSize.width(); if (maxH == 0) - maxH = KDDOCKWIDGETS_MAX_HEIGHT; + maxH = hardcodedMaximumSize.height(); return QSize(maxW, maxH).expandedTo(d->minSize(visibleChildren)); } @@ -3568,6 +3570,13 @@ void ItemContainer::Private::updateWidgets_recursive() } } +SizingInfo::SizingInfo() + : minSize(Layouting::Item::hardcodedMinimumSize) + , maxSizeHint(Layouting::Item::hardcodedMaximumSize) +{ + +} + void SizingInfo::setOppositeLength(int l, Qt::Orientation o) { setLength(l, oppositeOrientation(o)); diff --git a/src/private/multisplitter/Item_p.h b/src/private/multisplitter/Item_p.h index bae1f733..aa59c6de 100644 --- a/src/private/multisplitter/Item_p.h +++ b/src/private/multisplitter/Item_p.h @@ -21,12 +21,6 @@ #include -#define KDDOCKWIDGETS_MIN_WIDTH 80 -#define KDDOCKWIDGETS_MIN_HEIGHT 90 - -#define KDDOCKWIDGETS_MAX_WIDTH 16777215 -#define KDDOCKWIDGETS_MAX_HEIGHT 16777215 - class TestMultiSplitter; namespace Layouting { @@ -114,6 +108,9 @@ inline QRect mapToRect(const QVariantMap &map) } struct SizingInfo { + + SizingInfo(); + QSize size() const { return geometry.size(); } @@ -202,8 +199,8 @@ struct SizingInfo { typedef QVector List; QRect geometry; - QSize minSize = QSize(KDDOCKWIDGETS_MIN_WIDTH, KDDOCKWIDGETS_MIN_HEIGHT); - QSize maxSizeHint = QSize(KDDOCKWIDGETS_MAX_WIDTH, KDDOCKWIDGETS_MAX_HEIGHT); // TODO: Not supported yet + QSize minSize; + QSize maxSizeHint; double percentageWithinParent = 0.0; bool isBeingInserted = false; }; @@ -274,8 +271,8 @@ public: /** * @brief No widget can have a minimum size smaller than this, regardless of their minimum size. */ - static const QSize hardcodedMinimumSize; - static const QSize hardcodedMaximumSize; + static QSize hardcodedMinimumSize; + static QSize hardcodedMaximumSize; static int separatorThickness; int x() const; diff --git a/src/private/multisplitter/Widget.cpp b/src/private/multisplitter/Widget.cpp index 2bc632ce..16ae0118 100644 --- a/src/private/multisplitter/Widget.cpp +++ b/src/private/multisplitter/Widget.cpp @@ -34,13 +34,13 @@ QString Widget::id() const QSize Widget::boundedMaxSize(QSize min, QSize max) { // Max should be bigger than min, but not bigger than the hardcoded max - max = max.boundedTo(QSize(KDDOCKWIDGETS_MAX_WIDTH, KDDOCKWIDGETS_MAX_HEIGHT)); + max = max.boundedTo(Layouting::Item::hardcodedMaximumSize); // 0 interpreted as not having max if (max.width() <= 0) - max.setWidth(KDDOCKWIDGETS_MAX_WIDTH); + max.setWidth(Layouting::Item::hardcodedMaximumSize.width()); if (max.height() <= 0) - max.setHeight(KDDOCKWIDGETS_MAX_HEIGHT); + max.setHeight(Layouting::Item::hardcodedMaximumSize.height()); max = max.expandedTo(min); diff --git a/src/private/quick/QWidgetAdapter_quick.cpp b/src/private/quick/QWidgetAdapter_quick.cpp index 1533ecca..050b1a57 100644 --- a/src/private/quick/QWidgetAdapter_quick.cpp +++ b/src/private/quick/QWidgetAdapter_quick.cpp @@ -145,14 +145,13 @@ void QWidgetAdapter::raise() QSize QWidgetAdapter::minimumSize() const { const QSize min = property("kddockwidgets_min_size").toSize(); - return min.expandedTo({KDDOCKWIDGETS_MIN_WIDTH, KDDOCKWIDGETS_MIN_HEIGHT}); + return min.expandedTo(Layouting::Item::hardcodedMinimumSize); } QSize QWidgetAdapter::maximumSize() const { const QSize max = property("kddockwidgets_max_size").toSize(); - const QSize defaultMax(KDDOCKWIDGETS_MAX_WIDTH, KDDOCKWIDGETS_MAX_HEIGHT); - return max.isEmpty() ? defaultMax + return max.isEmpty() ? Layouting::Item::hardcodedMaximumSize : max.boundedTo(defaultMax); } diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index 545e45d3..2c6acf51 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -5585,7 +5585,7 @@ void TestDocks::tst_fixedSizePolicy() QCOMPARE(dock1->sizePolicy().verticalPolicy(), button->sizePolicy().verticalPolicy()); QCOMPARE(dock1->sizePolicy().horizontalPolicy(), button->sizePolicy().horizontalPolicy()); - QCOMPARE(frame->maxSizeHint().height(), qMax(buttonMaxHeight, KDDOCKWIDGETS_MIN_HEIGHT)); + QCOMPARE(frame->maxSizeHint().height(), qMax(buttonMaxHeight, Layouting::Item::hardcodedMinimumSize.height())); delete dock1->window(); } diff --git a/tests/tst_multisplitter.cpp b/tests/tst_multisplitter.cpp index f7a0af27..d34c8700 100644 --- a/tests/tst_multisplitter.cpp +++ b/tests/tst_multisplitter.cpp @@ -100,7 +100,7 @@ Q_SIGNALS: void layoutInvalidated(); private: QSize m_minSize = QSize(200, 200); - QSize m_maxSize = QSize(KDDOCKWIDGETS_MAX_WIDTH, KDDOCKWIDGETS_MAX_HEIGHT); + QSize m_maxSize = Layouting::Item::hardcodedMaximumSize; }; static void fatalWarningsMessageHandler(QtMsgType t, const QMessageLogContext &context, const QString &msg)