Add a private method to get control widget by enum to TitleControls
This commit is contained in:
parent
cc05f8174b
commit
3bc42db7bc
2 changed files with 37 additions and 37 deletions
|
|
@ -138,37 +138,53 @@ void TitleControls::raise() {
|
|||
_close->raise();
|
||||
}
|
||||
|
||||
Ui::IconButton *TitleControls::controlWidget(Control control) const {
|
||||
switch (control) {
|
||||
case Control::Minimize: return _minimize;
|
||||
case Control::Maximize: return _maximizeRestore;
|
||||
case Control::Close: return _close;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void TitleControls::updateControlsPosition() {
|
||||
const auto controlsLayout = TitleControlsLayout();
|
||||
auto controlsLeft = controlsLayout.left;
|
||||
auto controlsRight = controlsLayout.right;
|
||||
|
||||
if (!_resizeEnabled) {
|
||||
const auto controlPresent = [&](Control control) {
|
||||
return ranges::contains(controlsLeft, control)
|
||||
|| ranges::contains(controlsRight, control);
|
||||
};
|
||||
|
||||
const auto eraseControl = [&](Control control) {
|
||||
controlsLeft.erase(
|
||||
ranges::remove(controlsLeft, Control::Maximize),
|
||||
ranges::remove(controlsLeft, control),
|
||||
end(controlsLeft));
|
||||
|
||||
controlsRight.erase(
|
||||
ranges::remove(controlsRight, Control::Maximize),
|
||||
ranges::remove(controlsRight, control),
|
||||
end(controlsRight));
|
||||
};
|
||||
|
||||
if (!_resizeEnabled) {
|
||||
eraseControl(Control::Maximize);
|
||||
}
|
||||
|
||||
if (ranges::contains(controlsLeft, Control::Minimize)
|
||||
|| ranges::contains(controlsRight, Control::Minimize)) {
|
||||
if (controlPresent(Control::Minimize)) {
|
||||
_minimize->show();
|
||||
} else {
|
||||
_minimize->hide();
|
||||
}
|
||||
|
||||
if (ranges::contains(controlsLeft, Control::Maximize)
|
||||
|| ranges::contains(controlsRight, Control::Maximize)) {
|
||||
if (controlPresent(Control::Maximize)) {
|
||||
_maximizeRestore->show();
|
||||
} else {
|
||||
_maximizeRestore->hide();
|
||||
}
|
||||
|
||||
if (ranges::contains(controlsLeft, Control::Close)
|
||||
|| ranges::contains(controlsRight, Control::Close)) {
|
||||
if (controlPresent(Control::Close)) {
|
||||
_close->show();
|
||||
} else {
|
||||
_close->hide();
|
||||
|
|
@ -187,35 +203,18 @@ void TitleControls::updateControlsPositionBySide(
|
|||
|
||||
auto position = 0;
|
||||
for (const auto &control : preparedControls) {
|
||||
switch (control) {
|
||||
case Control::Minimize:
|
||||
if (right) {
|
||||
_minimize->moveToRight(position, 0);
|
||||
} else {
|
||||
_minimize->moveToLeft(position, 0);
|
||||
}
|
||||
|
||||
position += _minimize->width();
|
||||
break;
|
||||
case Control::Maximize:
|
||||
if (right) {
|
||||
_maximizeRestore->moveToRight(position, 0);
|
||||
} else {
|
||||
_maximizeRestore->moveToLeft(position, 0);
|
||||
}
|
||||
|
||||
position += _maximizeRestore->width();
|
||||
break;
|
||||
case Control::Close:
|
||||
if (right) {
|
||||
_close->moveToRight(position, 0);
|
||||
} else {
|
||||
_close->moveToLeft(position, 0);
|
||||
}
|
||||
|
||||
position += _close->width();
|
||||
break;
|
||||
const auto widget = controlWidget(control);
|
||||
if (!widget) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (right) {
|
||||
widget->moveToRight(position, 0);
|
||||
} else {
|
||||
widget->moveToLeft(position, 0);
|
||||
}
|
||||
|
||||
position += widget->width();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public:
|
|||
private:
|
||||
[[nodiscard]] not_null<RpWidget*> parent() const;
|
||||
[[nodiscard]] not_null<QWidget*> window() const;
|
||||
[[nodiscard]] Ui::IconButton *controlWidget(Control control) const;
|
||||
|
||||
void init(Fn<void(bool maximized)> maximize);
|
||||
void updateButtonsState();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue