refactor: Move the DefaultSizingMode enum into InitialSizingOption
It's another enum that affects the initial sizing. No behaviour was change in this commit. Needed for issue #95
This commit is contained in:
@@ -29,8 +29,16 @@
|
|||||||
# define KDDOCKWIDGETS_SUPPORTS_NESTED_MAINWINDOWS
|
# define KDDOCKWIDGETS_SUPPORTS_NESTED_MAINWINDOWS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace Layouting {
|
||||||
|
class Item;
|
||||||
|
class ItemContainer;
|
||||||
|
}
|
||||||
|
|
||||||
namespace KDDockWidgets
|
namespace KDDockWidgets
|
||||||
{
|
{
|
||||||
|
class MultiSplitter;
|
||||||
|
class DropArea;
|
||||||
|
|
||||||
enum Location {
|
enum Location {
|
||||||
Location_None,
|
Location_None,
|
||||||
Location_OnLeft, ///> Left docking location
|
Location_OnLeft, ///> Left docking location
|
||||||
@@ -45,6 +53,18 @@ namespace KDDockWidgets
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(MainWindowOptions, MainWindowOption)
|
Q_DECLARE_FLAGS(MainWindowOptions, MainWindowOption)
|
||||||
|
|
||||||
|
///@internal
|
||||||
|
///@brief Describes some sizing strategies for the layouting engine.
|
||||||
|
///This is internal. The public API for dealing with sizing is InitialOption.
|
||||||
|
///@sa InitialOption
|
||||||
|
enum class DefaultSizeMode {
|
||||||
|
ItemSize, ///< Simply uses the Item::size() of the item being added. Actual used size might be smaller if our window isn't big enough.
|
||||||
|
Fair, ///< Gives an equal relative size as the items that are already in the layout
|
||||||
|
FairButFloor, ///< Equal to fair, but if the item we're adding is smaller than the fair suggestion, then that small size is used.
|
||||||
|
SizePolicy, ///< Uses the item's sizeHint() and sizePolicy()
|
||||||
|
None, ///< Don't do any sizing
|
||||||
|
};
|
||||||
|
|
||||||
enum class InitialVisibilityOption {
|
enum class InitialVisibilityOption {
|
||||||
StartVisible = 0, ///< The dock widget is made visible when docked
|
StartVisible = 0, ///< The dock widget is made visible when docked
|
||||||
StartHidden ///< Don't show the dock widget when adding it
|
StartHidden ///< Don't show the dock widget when adding it
|
||||||
@@ -99,6 +119,17 @@ namespace KDDockWidgets
|
|||||||
* height will simply fill the whole layout.
|
* height will simply fill the whole layout.
|
||||||
*/
|
*/
|
||||||
//const QSize preferredSize; not yet done.
|
//const QSize preferredSize; not yet done.
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class Layouting::Item;
|
||||||
|
friend class Layouting::ItemContainer;
|
||||||
|
friend class KDDockWidgets::MultiSplitter;
|
||||||
|
friend class KDDockWidgets::DropArea;
|
||||||
|
|
||||||
|
InitialOption(DefaultSizeMode mode)
|
||||||
|
: sizeMode(mode) {}
|
||||||
|
|
||||||
|
const DefaultSizeMode sizeMode = DefaultSizeMode::Fair;
|
||||||
};
|
};
|
||||||
|
|
||||||
///@internal
|
///@internal
|
||||||
|
|||||||
@@ -137,9 +137,9 @@ void DropArea::addDockWidget(DockWidgetBase *dw, Location location,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (option.startsHidden()) {
|
if (option.startsHidden()) {
|
||||||
addWidget(dw, location, relativeToFrame, Layouting::Item::DefaultSizeMode::Fair, option);
|
addWidget(dw, location, relativeToFrame, option);
|
||||||
} else {
|
} else {
|
||||||
addWidget(frame, location, relativeToFrame, Layouting::Item::DefaultSizeMode::Fair, option);
|
addWidget(frame, location, relativeToFrame, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hadSingleFloatingFrame && !hasSingleFloatingFrame()) {
|
if (hadSingleFloatingFrame && !hasSingleFloatingFrame()) {
|
||||||
@@ -320,14 +320,14 @@ bool DropArea::drop(QWidgetOrQuick *droppedWindow, KDDockWidgets::Location locat
|
|||||||
|
|
||||||
auto frame = Config::self().frameworkWidgetFactory()->createFrame();
|
auto frame = Config::self().frameworkWidgetFactory()->createFrame();
|
||||||
frame->addWidget(dock);
|
frame->addWidget(dock);
|
||||||
addWidget(frame, location, relativeTo, Layouting::Item::DefaultSizeMode::FairButFloor);
|
addWidget(frame, location, relativeTo, DefaultSizeMode::FairButFloor);
|
||||||
} else if (auto floatingWindow = qobject_cast<FloatingWindow *>(droppedWindow)) {
|
} else if (auto floatingWindow = qobject_cast<FloatingWindow *>(droppedWindow)) {
|
||||||
if (!validateAffinity(floatingWindow))
|
if (!validateAffinity(floatingWindow))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const bool hadSingleFloatingFrame = hasSingleFloatingFrame();
|
const bool hadSingleFloatingFrame = hasSingleFloatingFrame();
|
||||||
addMultiSplitter(floatingWindow->dropArea(), location, relativeTo,
|
addMultiSplitter(floatingWindow->dropArea(), location, relativeTo,
|
||||||
Layouting::Item::DefaultSizeMode::FairButFloor);
|
DefaultSizeMode::FairButFloor);
|
||||||
if (hadSingleFloatingFrame != hasSingleFloatingFrame())
|
if (hadSingleFloatingFrame != hasSingleFloatingFrame())
|
||||||
updateFloatingActions();
|
updateFloatingActions();
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,6 @@ bool MultiSplitter::validateInputs(QWidgetOrQuick *widget,
|
|||||||
|
|
||||||
void MultiSplitter::addWidget(QWidgetOrQuick *w, Location location,
|
void MultiSplitter::addWidget(QWidgetOrQuick *w, Location location,
|
||||||
Frame *relativeToWidget,
|
Frame *relativeToWidget,
|
||||||
Layouting::Item::DefaultSizeMode defaultSizeMode,
|
|
||||||
InitialOption option)
|
InitialOption option)
|
||||||
{
|
{
|
||||||
auto frame = qobject_cast<Frame*>(w);
|
auto frame = qobject_cast<Frame*>(w);
|
||||||
@@ -219,8 +218,7 @@ void MultiSplitter::addWidget(QWidgetOrQuick *w, Location location,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(!newItem->geometry().isEmpty());
|
Q_ASSERT(!newItem->geometry().isEmpty());
|
||||||
relativeTo->insertItem(newItem, Layouting::Item::Location(location),
|
relativeTo->insertItem(newItem, Layouting::Item::Location(location), option);
|
||||||
Layouting::Item::DefaultSizeMode(defaultSizeMode), option);
|
|
||||||
|
|
||||||
if (dw && option.startsHidden())
|
if (dw && option.startsHidden())
|
||||||
delete frame;
|
delete frame;
|
||||||
@@ -228,10 +226,10 @@ void MultiSplitter::addWidget(QWidgetOrQuick *w, Location location,
|
|||||||
|
|
||||||
void MultiSplitter::addMultiSplitter(MultiSplitter *sourceMultiSplitter, Location location,
|
void MultiSplitter::addMultiSplitter(MultiSplitter *sourceMultiSplitter, Location location,
|
||||||
Frame *relativeTo,
|
Frame *relativeTo,
|
||||||
Layouting::Item::DefaultSizeMode defaultSizeMode)
|
InitialOption option)
|
||||||
{
|
{
|
||||||
qCDebug(addwidget) << Q_FUNC_INFO << sourceMultiSplitter << location << relativeTo;
|
qCDebug(addwidget) << Q_FUNC_INFO << sourceMultiSplitter << location << relativeTo;
|
||||||
addWidget(sourceMultiSplitter, location, relativeTo, defaultSizeMode);
|
addWidget(sourceMultiSplitter, location, relativeTo, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiSplitter::removeItem(Layouting::Item *item)
|
void MultiSplitter::removeItem(Layouting::Item *item)
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void addWidget(QWidgetOrQuick *widget, KDDockWidgets::Location location,
|
void addWidget(QWidgetOrQuick *widget, KDDockWidgets::Location location,
|
||||||
Frame *relativeTo = nullptr,
|
Frame *relativeTo = nullptr,
|
||||||
Layouting::Item::DefaultSizeMode = Layouting::Item::DefaultSizeMode::Fair,
|
InitialOption option = DefaultSizeMode::Fair);
|
||||||
InitialOption option = {});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an entire MultiSplitter into this layout. The donor MultiSplitter will be deleted
|
* Adds an entire MultiSplitter into this layout. The donor MultiSplitter will be deleted
|
||||||
@@ -81,7 +80,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
void addMultiSplitter(MultiSplitter *splitter, KDDockWidgets::Location location,
|
void addMultiSplitter(MultiSplitter *splitter, KDDockWidgets::Location location,
|
||||||
Frame *relativeTo = nullptr,
|
Frame *relativeTo = nullptr,
|
||||||
Layouting::Item::DefaultSizeMode = Layouting::Item::DefaultSizeMode::Fair);
|
InitialOption option = DefaultSizeMode::Fair);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Removes an item from this MultiSplitter.
|
* @brief Removes an item from this MultiSplitter.
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
// clazy:excludeall=missing-typeinfo,old-style-connect
|
// clazy:excludeall=missing-typeinfo,old-style-connect
|
||||||
|
|
||||||
using namespace Layouting;
|
using namespace Layouting;
|
||||||
|
using namespace KDDockWidgets;
|
||||||
|
|
||||||
int Layouting::Item::separatorThickness = 5;
|
int Layouting::Item::separatorThickness = 5;
|
||||||
|
|
||||||
@@ -472,8 +473,7 @@ int Item::pos(Qt::Orientation o) const
|
|||||||
return o == Qt::Vertical ? y() : x();
|
return o == Qt::Vertical ? y() : x();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::insertItem(Item *item, Location loc,
|
void Item::insertItem(Item *item, Location loc, KDDockWidgets::InitialOption option)
|
||||||
DefaultSizeMode defaultSizeMode, KDDockWidgets::InitialOption option)
|
|
||||||
{
|
{
|
||||||
Q_ASSERT(item != this);
|
Q_ASSERT(item != this);
|
||||||
|
|
||||||
@@ -494,10 +494,10 @@ void Item::insertItem(Item *item, Location loc,
|
|||||||
m_parent->setOrientation(orientation);
|
m_parent->setOrientation(orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_parent->insertItem(item, indexInParent, defaultSizeMode);
|
m_parent->insertItem(item, indexInParent, option);
|
||||||
} else {
|
} else {
|
||||||
ItemContainer *container = m_parent->convertChildToContainer(this);
|
ItemContainer *container = m_parent->convertChildToContainer(this);
|
||||||
container->insertItem(item, loc, defaultSizeMode, option);
|
container->insertItem(item, loc, option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -937,7 +937,7 @@ struct ItemContainer::Private
|
|||||||
m_separators.clear();
|
m_separators.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int defaultLengthFor(Item *item, DefaultSizeMode) const;
|
int defaultLengthFor(Item *item, InitialOption option) const;
|
||||||
bool isOverflowing() const;
|
bool isOverflowing() const;
|
||||||
void relayoutIfNeeded();
|
void relayoutIfNeeded();
|
||||||
const Item *itemFromPath(const QVector<int> &path) const;
|
const Item *itemFromPath(const QVector<int> &path) const;
|
||||||
@@ -1317,7 +1317,7 @@ ItemContainer *ItemContainer::convertChildToContainer(Item *leaf)
|
|||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemContainer::insertItem(Item *item, Location loc, DefaultSizeMode defaultSizeMode,
|
void ItemContainer::insertItem(Item *item, Location loc,
|
||||||
KDDockWidgets::InitialOption initialOption)
|
KDDockWidgets::InitialOption initialOption)
|
||||||
{
|
{
|
||||||
Q_ASSERT(item != this);
|
Q_ASSERT(item != this);
|
||||||
@@ -1338,7 +1338,7 @@ void ItemContainer::insertItem(Item *item, Location loc, DefaultSizeMode default
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto index = locationIsSide1(loc) ? 0 : d->m_children.size();
|
const auto index = locationIsSide1(loc) ? 0 : d->m_children.size();
|
||||||
insertItem(item, index, defaultSizeMode);
|
insertItem(item, index, initialOption);
|
||||||
} else {
|
} else {
|
||||||
// Inserting directly in a container ? Only if it's root.
|
// Inserting directly in a container ? Only if it's root.
|
||||||
Q_ASSERT(isRoot());
|
Q_ASSERT(isRoot());
|
||||||
@@ -1350,7 +1350,7 @@ void ItemContainer::insertItem(Item *item, Location loc, DefaultSizeMode default
|
|||||||
insertItem(container, 0, DefaultSizeMode::None);
|
insertItem(container, 0, DefaultSizeMode::None);
|
||||||
|
|
||||||
// Now we have the correct orientation, we can insert
|
// Now we have the correct orientation, we can insert
|
||||||
insertItem(item, loc, defaultSizeMode, initialOption);
|
insertItem(item, loc, initialOption);
|
||||||
|
|
||||||
if (!container->hasVisibleChildren())
|
if (!container->hasVisibleChildren())
|
||||||
container->setGeometry(QRect());
|
container->setGeometry(QRect());
|
||||||
@@ -1756,11 +1756,11 @@ void ItemContainer::setLength_recursive(int length, Qt::Orientation o)
|
|||||||
setSize_recursive(sz);
|
setSize_recursive(sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemContainer::insertItem(Item *item, int index, DefaultSizeMode defaultSizeMode)
|
void ItemContainer::insertItem(Item *item, int index, InitialOption option)
|
||||||
{
|
{
|
||||||
if (defaultSizeMode != DefaultSizeMode::None) {
|
if (option.sizeMode != DefaultSizeMode::None) {
|
||||||
/// Choose a nice size for the item we're adding
|
/// Choose a nice size for the item we're adding
|
||||||
const int suggestedLength = d->defaultLengthFor(item, defaultSizeMode);
|
const int suggestedLength = d->defaultLengthFor(item, option);
|
||||||
item->setLength_recursive(suggestedLength, d->m_orientation);
|
item->setLength_recursive(suggestedLength, d->m_orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3600,10 +3600,10 @@ void SizingInfo::fromVariantMap(const QVariantMap &map)
|
|||||||
maxSizeHint = mapToSize(map[QStringLiteral("maxSize")].toMap());
|
maxSizeHint = mapToSize(map[QStringLiteral("maxSize")].toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
int ItemContainer::Private::defaultLengthFor(Item *item, DefaultSizeMode mode) const
|
int ItemContainer::Private::defaultLengthFor(Item *item, InitialOption option) const
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
switch (mode) {
|
switch (option.sizeMode) {
|
||||||
case DefaultSizeMode::None:
|
case DefaultSizeMode::None:
|
||||||
break;
|
break;
|
||||||
case DefaultSizeMode::Fair: {
|
case DefaultSizeMode::Fair: {
|
||||||
|
|||||||
@@ -240,17 +240,6 @@ public:
|
|||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(LayoutBorderLocations, LayoutBorderLocation)
|
Q_DECLARE_FLAGS(LayoutBorderLocations, LayoutBorderLocation)
|
||||||
|
|
||||||
|
|
||||||
///@brief When an item is added we need to figure out what's a decent size for it
|
|
||||||
///This enum specifies the different ways to calculate it
|
|
||||||
enum class DefaultSizeMode {
|
|
||||||
ItemSize, ///< Simply uses the Item::size() of the item being added. Actual used size might be smaller if our window isn't big enough.
|
|
||||||
Fair, ///< Gives an equal relative size as the items that are already in the layout
|
|
||||||
FairButFloor, ///< Equal to fair, but if the item we're adding is smaller than the fair suggestion, then that small size is used.
|
|
||||||
SizePolicy, ///< Uses the item's sizeHint() and sizePolicy()
|
|
||||||
None, ///< Don't do any sizing
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit Item(Widget *hostWidget, ItemContainer *parent = nullptr);
|
explicit Item(Widget *hostWidget, ItemContainer *parent = nullptr);
|
||||||
~Item() override;
|
~Item() override;
|
||||||
|
|
||||||
@@ -262,8 +251,7 @@ public:
|
|||||||
|
|
||||||
virtual int visibleCount_recursive() const;
|
virtual int visibleCount_recursive() const;
|
||||||
virtual void insertItem(Item *item, Location,
|
virtual void insertItem(Item *item, Location,
|
||||||
DefaultSizeMode defaultSizeMode = DefaultSizeMode::Fair,
|
KDDockWidgets::InitialOption = KDDockWidgets::DefaultSizeMode::Fair);
|
||||||
KDDockWidgets::InitialOption = {});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief No widget can have a minimum size smaller than this, regardless of their minimum size.
|
* @brief No widget can have a minimum size smaller than this, regardless of their minimum size.
|
||||||
@@ -382,9 +370,10 @@ public:
|
|||||||
explicit ItemContainer(Widget *hostWidget, ItemContainer *parent);
|
explicit ItemContainer(Widget *hostWidget, ItemContainer *parent);
|
||||||
explicit ItemContainer(Widget *hostWidget);
|
explicit ItemContainer(Widget *hostWidget);
|
||||||
~ItemContainer();
|
~ItemContainer();
|
||||||
void insertItem(Item *item, int index, DefaultSizeMode);
|
void insertItem(Item *item, int index, KDDockWidgets::InitialOption option = KDDockWidgets::DefaultSizeMode::Fair);
|
||||||
void insertItem(Item *item, Location, DefaultSizeMode defaultSizeMode = DefaultSizeMode::Fair,
|
void insertItem(Item *item, Location,
|
||||||
KDDockWidgets::InitialOption = {}) override;
|
KDDockWidgets::InitialOption = {}) override;
|
||||||
|
|
||||||
void requestSeparatorMove(Separator *separator, int delta);
|
void requestSeparatorMove(Separator *separator, int delta);
|
||||||
int minPosForSeparator(Separator *, bool honourMax = true) const;
|
int minPosForSeparator(Separator *, bool honourMax = true) const;
|
||||||
int maxPosForSeparator(Separator *, bool honourMax = true) const;
|
int maxPosForSeparator(Separator *, bool honourMax = true) const;
|
||||||
|
|||||||
@@ -1178,7 +1178,7 @@ void TestMultiSplitter::tst_numSeparators()
|
|||||||
|
|
||||||
root->insertItem(item5, Item::Location_OnLeft);
|
root->insertItem(item5, Item::Location_OnLeft);
|
||||||
QCOMPARE(root->separators_recursive().size(), 0);
|
QCOMPARE(root->separators_recursive().size(), 0);
|
||||||
root->insertItem(item6, Item::Location_OnLeft, Item::DefaultSizeMode::Fair, KDDockWidgets::InitialVisibilityOption::StartHidden);
|
root->insertItem(item6, Item::Location_OnLeft, KDDockWidgets::InitialVisibilityOption::StartHidden);
|
||||||
QCOMPARE(root->separators_recursive().size(), 0);
|
QCOMPARE(root->separators_recursive().size(), 0);
|
||||||
QVERIFY(serializeDeserializeTest(root));
|
QVERIFY(serializeDeserializeTest(root));
|
||||||
}
|
}
|
||||||
@@ -1250,7 +1250,7 @@ void TestMultiSplitter::tst_insertHiddenContainer()
|
|||||||
auto root1 = createRoot();
|
auto root1 = createRoot();
|
||||||
auto root2 = createRoot();
|
auto root2 = createRoot();
|
||||||
Item *item2 = createItem();
|
Item *item2 = createItem();
|
||||||
root2->insertItem(item2, Item::Location_OnLeft, Item::DefaultSizeMode::Fair, KDDockWidgets::InitialVisibilityOption::StartHidden);
|
root2->insertItem(item2, Item::Location_OnLeft, KDDockWidgets::InitialVisibilityOption::StartHidden);
|
||||||
|
|
||||||
QVERIFY(root1->checkSanity());
|
QVERIFY(root1->checkSanity());
|
||||||
QVERIFY(root2->checkSanity());
|
QVERIFY(root2->checkSanity());
|
||||||
|
|||||||
Reference in New Issue
Block a user