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
|
||||
#endif
|
||||
|
||||
namespace Layouting {
|
||||
class Item;
|
||||
class ItemContainer;
|
||||
}
|
||||
|
||||
namespace KDDockWidgets
|
||||
{
|
||||
class MultiSplitter;
|
||||
class DropArea;
|
||||
|
||||
enum Location {
|
||||
Location_None,
|
||||
Location_OnLeft, ///> Left docking location
|
||||
@@ -45,6 +53,18 @@ namespace KDDockWidgets
|
||||
};
|
||||
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 {
|
||||
StartVisible = 0, ///< The dock widget is made visible when docked
|
||||
StartHidden ///< Don't show the dock widget when adding it
|
||||
@@ -99,6 +119,17 @@ namespace KDDockWidgets
|
||||
* height will simply fill the whole layout.
|
||||
*/
|
||||
//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
|
||||
|
||||
@@ -137,9 +137,9 @@ void DropArea::addDockWidget(DockWidgetBase *dw, Location location,
|
||||
}
|
||||
|
||||
if (option.startsHidden()) {
|
||||
addWidget(dw, location, relativeToFrame, Layouting::Item::DefaultSizeMode::Fair, option);
|
||||
addWidget(dw, location, relativeToFrame, option);
|
||||
} else {
|
||||
addWidget(frame, location, relativeToFrame, Layouting::Item::DefaultSizeMode::Fair, option);
|
||||
addWidget(frame, location, relativeToFrame, option);
|
||||
}
|
||||
|
||||
if (hadSingleFloatingFrame && !hasSingleFloatingFrame()) {
|
||||
@@ -320,14 +320,14 @@ bool DropArea::drop(QWidgetOrQuick *droppedWindow, KDDockWidgets::Location locat
|
||||
|
||||
auto frame = Config::self().frameworkWidgetFactory()->createFrame();
|
||||
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)) {
|
||||
if (!validateAffinity(floatingWindow))
|
||||
return false;
|
||||
|
||||
const bool hadSingleFloatingFrame = hasSingleFloatingFrame();
|
||||
addMultiSplitter(floatingWindow->dropArea(), location, relativeTo,
|
||||
Layouting::Item::DefaultSizeMode::FairButFloor);
|
||||
DefaultSizeMode::FairButFloor);
|
||||
if (hadSingleFloatingFrame != hasSingleFloatingFrame())
|
||||
updateFloatingActions();
|
||||
|
||||
|
||||
@@ -161,7 +161,6 @@ bool MultiSplitter::validateInputs(QWidgetOrQuick *widget,
|
||||
|
||||
void MultiSplitter::addWidget(QWidgetOrQuick *w, Location location,
|
||||
Frame *relativeToWidget,
|
||||
Layouting::Item::DefaultSizeMode defaultSizeMode,
|
||||
InitialOption option)
|
||||
{
|
||||
auto frame = qobject_cast<Frame*>(w);
|
||||
@@ -219,8 +218,7 @@ void MultiSplitter::addWidget(QWidgetOrQuick *w, Location location,
|
||||
}
|
||||
|
||||
Q_ASSERT(!newItem->geometry().isEmpty());
|
||||
relativeTo->insertItem(newItem, Layouting::Item::Location(location),
|
||||
Layouting::Item::DefaultSizeMode(defaultSizeMode), option);
|
||||
relativeTo->insertItem(newItem, Layouting::Item::Location(location), option);
|
||||
|
||||
if (dw && option.startsHidden())
|
||||
delete frame;
|
||||
@@ -228,10 +226,10 @@ void MultiSplitter::addWidget(QWidgetOrQuick *w, Location location,
|
||||
|
||||
void MultiSplitter::addMultiSplitter(MultiSplitter *sourceMultiSplitter, Location location,
|
||||
Frame *relativeTo,
|
||||
Layouting::Item::DefaultSizeMode defaultSizeMode)
|
||||
InitialOption option)
|
||||
{
|
||||
qCDebug(addwidget) << Q_FUNC_INFO << sourceMultiSplitter << location << relativeTo;
|
||||
addWidget(sourceMultiSplitter, location, relativeTo, defaultSizeMode);
|
||||
addWidget(sourceMultiSplitter, location, relativeTo, option);
|
||||
}
|
||||
|
||||
void MultiSplitter::removeItem(Layouting::Item *item)
|
||||
|
||||
@@ -70,8 +70,7 @@ public:
|
||||
*/
|
||||
void addWidget(QWidgetOrQuick *widget, KDDockWidgets::Location location,
|
||||
Frame *relativeTo = nullptr,
|
||||
Layouting::Item::DefaultSizeMode = Layouting::Item::DefaultSizeMode::Fair,
|
||||
InitialOption option = {});
|
||||
InitialOption option = DefaultSizeMode::Fair);
|
||||
|
||||
/**
|
||||
* 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,
|
||||
Frame *relativeTo = nullptr,
|
||||
Layouting::Item::DefaultSizeMode = Layouting::Item::DefaultSizeMode::Fair);
|
||||
InitialOption option = DefaultSizeMode::Fair);
|
||||
|
||||
/**
|
||||
* @brief Removes an item from this MultiSplitter.
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
// clazy:excludeall=missing-typeinfo,old-style-connect
|
||||
|
||||
using namespace Layouting;
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
int Layouting::Item::separatorThickness = 5;
|
||||
|
||||
@@ -472,8 +473,7 @@ int Item::pos(Qt::Orientation o) const
|
||||
return o == Qt::Vertical ? y() : x();
|
||||
}
|
||||
|
||||
void Item::insertItem(Item *item, Location loc,
|
||||
DefaultSizeMode defaultSizeMode, KDDockWidgets::InitialOption option)
|
||||
void Item::insertItem(Item *item, Location loc, KDDockWidgets::InitialOption option)
|
||||
{
|
||||
Q_ASSERT(item != this);
|
||||
|
||||
@@ -494,10 +494,10 @@ void Item::insertItem(Item *item, Location loc,
|
||||
m_parent->setOrientation(orientation);
|
||||
}
|
||||
|
||||
m_parent->insertItem(item, indexInParent, defaultSizeMode);
|
||||
m_parent->insertItem(item, indexInParent, option);
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
|
||||
int defaultLengthFor(Item *item, DefaultSizeMode) const;
|
||||
int defaultLengthFor(Item *item, InitialOption option) const;
|
||||
bool isOverflowing() const;
|
||||
void relayoutIfNeeded();
|
||||
const Item *itemFromPath(const QVector<int> &path) const;
|
||||
@@ -1317,7 +1317,7 @@ ItemContainer *ItemContainer::convertChildToContainer(Item *leaf)
|
||||
return container;
|
||||
}
|
||||
|
||||
void ItemContainer::insertItem(Item *item, Location loc, DefaultSizeMode defaultSizeMode,
|
||||
void ItemContainer::insertItem(Item *item, Location loc,
|
||||
KDDockWidgets::InitialOption initialOption)
|
||||
{
|
||||
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();
|
||||
insertItem(item, index, defaultSizeMode);
|
||||
insertItem(item, index, initialOption);
|
||||
} else {
|
||||
// Inserting directly in a container ? Only if it's root.
|
||||
Q_ASSERT(isRoot());
|
||||
@@ -1350,7 +1350,7 @@ void ItemContainer::insertItem(Item *item, Location loc, DefaultSizeMode default
|
||||
insertItem(container, 0, DefaultSizeMode::None);
|
||||
|
||||
// Now we have the correct orientation, we can insert
|
||||
insertItem(item, loc, defaultSizeMode, initialOption);
|
||||
insertItem(item, loc, initialOption);
|
||||
|
||||
if (!container->hasVisibleChildren())
|
||||
container->setGeometry(QRect());
|
||||
@@ -1756,11 +1756,11 @@ void ItemContainer::setLength_recursive(int length, Qt::Orientation o)
|
||||
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
|
||||
const int suggestedLength = d->defaultLengthFor(item, defaultSizeMode);
|
||||
const int suggestedLength = d->defaultLengthFor(item, option);
|
||||
item->setLength_recursive(suggestedLength, d->m_orientation);
|
||||
}
|
||||
|
||||
@@ -3600,10 +3600,10 @@ void SizingInfo::fromVariantMap(const QVariantMap &map)
|
||||
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;
|
||||
switch (mode) {
|
||||
switch (option.sizeMode) {
|
||||
case DefaultSizeMode::None:
|
||||
break;
|
||||
case DefaultSizeMode::Fair: {
|
||||
|
||||
@@ -240,17 +240,6 @@ public:
|
||||
};
|
||||
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);
|
||||
~Item() override;
|
||||
|
||||
@@ -262,8 +251,7 @@ public:
|
||||
|
||||
virtual int visibleCount_recursive() const;
|
||||
virtual void insertItem(Item *item, Location,
|
||||
DefaultSizeMode defaultSizeMode = DefaultSizeMode::Fair,
|
||||
KDDockWidgets::InitialOption = {});
|
||||
KDDockWidgets::InitialOption = KDDockWidgets::DefaultSizeMode::Fair);
|
||||
|
||||
/**
|
||||
* @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();
|
||||
void insertItem(Item *item, int index, DefaultSizeMode);
|
||||
void insertItem(Item *item, Location, DefaultSizeMode defaultSizeMode = DefaultSizeMode::Fair,
|
||||
void insertItem(Item *item, int index, KDDockWidgets::InitialOption option = KDDockWidgets::DefaultSizeMode::Fair);
|
||||
void insertItem(Item *item, Location,
|
||||
KDDockWidgets::InitialOption = {}) override;
|
||||
|
||||
void requestSeparatorMove(Separator *separator, int delta);
|
||||
int minPosForSeparator(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);
|
||||
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);
|
||||
QVERIFY(serializeDeserializeTest(root));
|
||||
}
|
||||
@@ -1250,7 +1250,7 @@ void TestMultiSplitter::tst_insertHiddenContainer()
|
||||
auto root1 = createRoot();
|
||||
auto root2 = createRoot();
|
||||
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(root2->checkSanity());
|
||||
|
||||
Reference in New Issue
Block a user