Skip to content

Commit e20d140

Browse files
committed
Merge branch 'Right-to-left-layout-direction' into 'master'
[OpenCS] Add subview open direction preference Closes #721 See merge request OpenMW/openmw!5122
2 parents 6d3f9ca + c620f05 commit e20d140

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

apps/opencs/model/prefs/state.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void CSMPrefs::State::declare()
5959
.setTooltip("Minimum width of subviews.")
6060
.setRange(50, 10000);
6161
declareEnum(mValues->mWindows.mMainwindowScrollbar, "Main Window Horizontal Scrollbar Mode");
62+
declareEnum(mValues->mWindows.mSubviewOpenDirection, "Subview Open Direction")
63+
.setTooltip("Controls whether new subviews open to the right or left of existing ones.");
6264

6365
declareCategory("Records");
6466
declareEnum(mValues->mRecords.mStatusFormat, "Modification Status Display Format");

apps/opencs/model/prefs/values.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ namespace CSMPrefs
8181
"Grow then Scroll", "The view window grows. The scrollbar appears once it cannot grow any further." },
8282
};
8383

84+
static constexpr std::array<EnumValueView, 2> sSubviewOpenDirectionValues{
85+
EnumValueView{ "Open Right", "New subviews open to the right of existing ones." },
86+
EnumValueView{ "Open Left", "New subviews open to the left of existing ones." },
87+
};
88+
8489
Settings::SettingValue<int> mDefaultWidth{ mIndex, sName, "default-width", 800 };
8590
Settings::SettingValue<int> mDefaultHeight{ mIndex, sName, "default-height", 600 };
8691
Settings::SettingValue<bool> mShowStatusbar{ mIndex, sName, "show-statusbar", true };
@@ -90,6 +95,8 @@ namespace CSMPrefs
9095
Settings::SettingValue<int> mMinimumWidth{ mIndex, sName, "minimum-width", 325 };
9196
EnumSettingValue mMainwindowScrollbar{ mIndex, sName, "mainwindow-scrollbar", sMainwindowScrollbarValues, 0 };
9297
Settings::SettingValue<bool> mGrowLimit{ mIndex, sName, "grow-limit", false };
98+
EnumSettingValue mSubviewOpenDirection{ mIndex, sName, "subview-open-direction", sSubviewOpenDirectionValues,
99+
0 };
93100
};
94101

95102
struct RecordsCategory : Settings::WithIndex

apps/opencs/view/doc/view.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,31 @@ void CSVDoc::View::addSubView(const CSMWorld::UniversalId& id, const std::string
663663

664664
mSubViewWindow.addDockWidget(Qt::TopDockWidgetArea, view);
665665

666+
// Horizontal orientation doesn't respect layout direction, so we need to move the new view
667+
if (windows["subview-open-direction"].toString() == "Open Left" && mSubViews.size() > 1)
668+
{
669+
// Get list of top-area dock widget subviews sorted by coordinates
670+
QList<SubView*> orderedTopViews;
671+
for (const auto& windowView : mSubViews)
672+
if (windowView != view && mSubViewWindow.dockWidgetArea(windowView) == Qt::TopDockWidgetArea)
673+
orderedTopViews.append(windowView);
674+
if (!orderedTopViews.isEmpty())
675+
{
676+
std::sort(orderedTopViews.begin(), orderedTopViews.end(), [](auto* a, auto* b) {
677+
if (a->x() != b->x())
678+
return a->x() < b->x();
679+
else if (a->y() != b->y())
680+
return a->y() < b->y();
681+
return a->getUniversalId() < b->getUniversalId();
682+
});
683+
684+
// Split twice to make the new view the leftmost.
685+
// If the leftmost view is nested, the new view will be added above it.
686+
mSubViewWindow.splitDockWidget(orderedTopViews[0], view, Qt::Orientation::Horizontal);
687+
mSubViewWindow.splitDockWidget(view, orderedTopViews[0], Qt::Orientation::Horizontal);
688+
}
689+
}
690+
666691
updateSubViewIndices();
667692

668693
connect(view, &SubView::focusId, this, &View::addSubView);
@@ -706,7 +731,11 @@ void CSVDoc::View::moveScrollBarToEnd(int min, int max)
706731
{
707732
if (mScroll)
708733
{
709-
mScroll->horizontalScrollBar()->setValue(max);
734+
CSMPrefs::Category& windows = CSMPrefs::State::get()["Windows"];
735+
if (windows["subview-open-direction"].toString() == "Open Left")
736+
mScroll->horizontalScrollBar()->setValue(min);
737+
else
738+
mScroll->horizontalScrollBar()->setValue(max);
710739

711740
QObject::disconnect(mScroll->horizontalScrollBar(), &QScrollBar::rangeChanged, this, &View::moveScrollBarToEnd);
712741
}
@@ -1122,7 +1151,8 @@ void CSVDoc::View::updateWidth(bool isGrowLimit, int minSubViewWidth)
11221151
if (newWidth + frameWidth <= rect.width())
11231152
{
11241153
resize(newWidth, height());
1125-
// WARNING: below code assumes that new subviews are added to the right
1154+
// WARNING: below code assumes that the frame geometry expands to the right.
1155+
// This doesn't conflict with subview-open-direction.
11261156
if (x() > rect.width() - (newWidth + frameWidth))
11271157
move(rect.width() - (newWidth + frameWidth), y()); // shift left to stay within the screen
11281158
}

0 commit comments

Comments
 (0)