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