Allow to query RpWindow-s frame margins.
This commit is contained in:
parent
b35d2d257a
commit
2d53ef070f
8 changed files with 54 additions and 25 deletions
|
|
@ -19,6 +19,7 @@ public:
|
|||
~WindowHelper();
|
||||
|
||||
not_null<RpWidget*> body() override;
|
||||
QMargins frameMargins() override;
|
||||
void setTitle(const QString &title) override;
|
||||
void setTitleStyle(const style::WindowTitle &st) override;
|
||||
void setMinimumSize(QSize size) override;
|
||||
|
|
|
|||
|
|
@ -300,11 +300,9 @@ void WindowHelper::Private::init() {
|
|||
WindowHelper::WindowHelper(not_null<RpWidget*> window)
|
||||
: BasicWindowHelper(window)
|
||||
, _private(std::make_unique<Private>(this))
|
||||
, _title(_private->customTitleHeight()
|
||||
? Ui::CreateChild<TitleWidget>(
|
||||
, _title(Ui::CreateChild<TitleWidget>(
|
||||
window.get(),
|
||||
_private->customTitleHeight())
|
||||
: nullptr)
|
||||
_private->customTitleHeight()))
|
||||
, _body(Ui::CreateChild<RpWidget>(window.get())) {
|
||||
if (_title->shouldBeHidden()) {
|
||||
updateCustomTitleVisibility();
|
||||
|
|
@ -319,26 +317,26 @@ not_null<RpWidget*> WindowHelper::body() {
|
|||
return _body;
|
||||
}
|
||||
|
||||
QMargins WindowHelper::frameMargins() {
|
||||
const auto titleHeight = !_title->isHidden() ? _title->height() : 0;
|
||||
return QMargins{ 0, titleHeight, 0, 0 };
|
||||
}
|
||||
|
||||
void WindowHelper::setTitle(const QString &title) {
|
||||
if (_title) {
|
||||
_title->setText(title);
|
||||
}
|
||||
window()->setWindowTitle(
|
||||
(!_title || !_titleVisible) ? title : QString());
|
||||
window()->setWindowTitle(_titleVisible ? QString() : title);
|
||||
}
|
||||
|
||||
void WindowHelper::setTitleStyle(const style::WindowTitle &st) {
|
||||
if (_title) {
|
||||
_title->setStyle(st);
|
||||
if (_title->shouldBeHidden()) {
|
||||
updateCustomTitleVisibility();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WindowHelper::updateCustomTitleVisibility(bool force) {
|
||||
auto visible = !_title->shouldBeHidden() && _titleVisible;
|
||||
if (!_title || (!force && _title->isHidden() != visible)) {
|
||||
const auto visible = !_title->shouldBeHidden() && _titleVisible;
|
||||
if (!force && _title->isHidden() != visible) {
|
||||
return;
|
||||
}
|
||||
_title->setVisible(visible);
|
||||
|
|
@ -346,15 +344,11 @@ void WindowHelper::updateCustomTitleVisibility(bool force) {
|
|||
}
|
||||
|
||||
void WindowHelper::setMinimumSize(QSize size) {
|
||||
window()->setMinimumSize(
|
||||
size.width(),
|
||||
(_title ? _title->height() : 0) + size.height());
|
||||
window()->setMinimumSize(size.width(), _title->height() + size.height());
|
||||
}
|
||||
|
||||
void WindowHelper::setFixedSize(QSize size) {
|
||||
window()->setFixedSize(
|
||||
size.width(),
|
||||
(_title ? _title->height() : 0) + size.height());
|
||||
window()->setFixedSize(size.width(), _title->height() + size.height());
|
||||
}
|
||||
|
||||
void WindowHelper::setStaysOnTop(bool enabled) {
|
||||
|
|
@ -362,8 +356,7 @@ void WindowHelper::setStaysOnTop(bool enabled) {
|
|||
}
|
||||
|
||||
void WindowHelper::setGeometry(QRect rect) {
|
||||
window()->setGeometry(
|
||||
rect.marginsAdded({ 0, (_title ? _title->height() : 0), 0, 0 }));
|
||||
window()->setGeometry(rect.marginsAdded({ 0, _title->height(), 0, 0 }));
|
||||
}
|
||||
|
||||
void WindowHelper::setupBodyTitleAreaEvents() {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ not_null<RpWidget*> BasicWindowHelper::body() {
|
|||
return _window;
|
||||
}
|
||||
|
||||
QMargins BasicWindowHelper::frameMargins() {
|
||||
return nativeFrameMargins();
|
||||
}
|
||||
|
||||
void BasicWindowHelper::setTitle(const QString &title) {
|
||||
_window->setWindowTitle(title);
|
||||
}
|
||||
|
|
@ -86,6 +90,16 @@ void BasicWindowHelper::setBodyTitleArea(
|
|||
setupBodyTitleAreaEvents();
|
||||
}
|
||||
|
||||
QMargins BasicWindowHelper::nativeFrameMargins() const {
|
||||
const auto inner = window()->geometry();
|
||||
const auto outer = window()->frameGeometry();
|
||||
return QMargins(
|
||||
inner.x() - outer.x(),
|
||||
inner.y() - outer.y(),
|
||||
outer.x() + outer.width() - inner.x() - inner.width(),
|
||||
outer.y() + outer.height() - inner.y() - inner.height());
|
||||
}
|
||||
|
||||
void BasicWindowHelper::setupBodyTitleAreaEvents() {
|
||||
// This is not done on macOS, because startSystemMove
|
||||
// doesn't work from event handler there.
|
||||
|
|
@ -243,6 +257,12 @@ not_null<RpWidget*> DefaultWindowHelper::body() {
|
|||
return _body;
|
||||
}
|
||||
|
||||
QMargins DefaultWindowHelper::frameMargins() {
|
||||
return _title->isHidden()
|
||||
? BasicWindowHelper::nativeFrameMargins()
|
||||
: QMargins{ 0, _title->height(), 0, 0 };
|
||||
}
|
||||
|
||||
bool DefaultWindowHelper::hasShadow() const {
|
||||
const auto center = window()->geometry().center();
|
||||
return WindowExtentsSupported() && TranslucentWindowsSupported(center);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public:
|
|||
virtual ~BasicWindowHelper() = default;
|
||||
|
||||
[[nodiscard]] virtual not_null<RpWidget*> body();
|
||||
[[nodiscard]] virtual QMargins frameMargins();
|
||||
virtual void setTitle(const QString &title);
|
||||
virtual void setTitleStyle(const style::WindowTitle &st);
|
||||
virtual void setNativeFrame(bool enabled);
|
||||
|
|
@ -51,6 +52,7 @@ protected:
|
|||
? _bodyTitleAreaTestMethod(point)
|
||||
: WindowTitleHitTestFlag();
|
||||
}
|
||||
[[nodiscard]] QMargins nativeFrameMargins() const;
|
||||
|
||||
private:
|
||||
virtual void setupBodyTitleAreaEvents();
|
||||
|
|
@ -66,6 +68,7 @@ public:
|
|||
explicit DefaultWindowHelper(not_null<RpWidget*> window);
|
||||
|
||||
not_null<RpWidget*> body() override;
|
||||
QMargins frameMargins() override;
|
||||
void setTitle(const QString &title) override;
|
||||
void setTitleStyle(const style::WindowTitle &st) override;
|
||||
void setNativeFrame(bool enabled) override;
|
||||
|
|
|
|||
|
|
@ -185,6 +185,12 @@ not_null<RpWidget*> WindowHelper::body() {
|
|||
return _body;
|
||||
}
|
||||
|
||||
QMargins WindowHelper::frameMargins() {
|
||||
return _title->isHidden()
|
||||
? BasicWindowHelper::nativeFrameMargins()
|
||||
: QMargins{ 0, _title->height(), 0, 0 };
|
||||
}
|
||||
|
||||
void WindowHelper::setTitle(const QString &title) {
|
||||
_title->setText(title);
|
||||
window()->setWindowTitle(title);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
~WindowHelper();
|
||||
|
||||
not_null<RpWidget*> body() override;
|
||||
QMargins frameMargins() override;
|
||||
void setTitle(const QString &title) override;
|
||||
void setTitleStyle(const style::WindowTitle &st) override;
|
||||
void setNativeFrame(bool enabled) override;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ not_null<const RpWidget*> RpWindow::body() const {
|
|||
return _helper->body().get();
|
||||
}
|
||||
|
||||
QMargins RpWindow::frameMargins() const {
|
||||
return _helper->frameMargins();
|
||||
}
|
||||
|
||||
void RpWindow::setTitle(const QString &title) {
|
||||
_helper->setTitle(title);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ public:
|
|||
|
||||
[[nodiscard]] not_null<RpWidget*> body();
|
||||
[[nodiscard]] not_null<const RpWidget*> body() const;
|
||||
[[nodiscard]] QMargins frameMargins() const;
|
||||
|
||||
void setTitle(const QString &title);
|
||||
void setTitleStyle(const style::WindowTitle &st);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue