Extract TitleControls from TitleWidget.
This commit is contained in:
parent
6735ee93dc
commit
b534567e11
3 changed files with 146 additions and 74 deletions
|
|
@ -538,7 +538,7 @@ notificationBg: windowBg; // custom notification window background
|
||||||
// calls
|
// calls
|
||||||
callBg: #26282cf2; // old phone call popup background
|
callBg: #26282cf2; // old phone call popup background
|
||||||
callBgOpaque: #1b1f23 | callBg; // phone call popup background
|
callBgOpaque: #1b1f23 | callBg; // phone call popup background
|
||||||
callBgButton: #1b1f2356 | callBg; // phone call window control buttons bg
|
callBgButton: #1b1f237f | callBg; // phone call window control buttons bg
|
||||||
callNameFg: #ffffff; // phone call popup name text
|
callNameFg: #ffffff; // phone call popup name text
|
||||||
callFingerprintBg: #00000066; // phone call popup emoji fingerprint background
|
callFingerprintBg: #00000066; // phone call popup emoji fingerprint background
|
||||||
callStatusFg: #aaabac; // phone call popup status text
|
callStatusFg: #aaabac; // phone call popup status text
|
||||||
|
|
|
||||||
|
|
@ -19,39 +19,59 @@
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
|
|
||||||
TitleWidget::TitleWidget(not_null<RpWidget*> parent)
|
TitleControls::TitleControls(
|
||||||
: RpWidget(parent)
|
not_null<RpWidget*> parent,
|
||||||
, _st(&st::defaultWindowTitle)
|
Fn<void(bool maximized)> maximize)
|
||||||
, _minimize(this, _st->minimize)
|
: _st(&st::defaultWindowTitle)
|
||||||
, _maximizeRestore(this, _st->maximize)
|
, _minimize(parent, _st->minimize)
|
||||||
, _close(this, _st->close)
|
, _maximizeRestore(parent, _st->maximize)
|
||||||
, _shadow(this, st::titleShadow)
|
, _close(parent, _st->close)
|
||||||
, _maximizedState(parent->windowState() & Qt::WindowMaximized)
|
, _maximizedState(parent->windowState()
|
||||||
|
& (Qt::WindowMaximized | Qt::WindowFullScreen))
|
||||||
, _activeState(parent->isActiveWindow()) {
|
, _activeState(parent->isActiveWindow()) {
|
||||||
init();
|
init(std::move(maximize));
|
||||||
|
|
||||||
|
_close->paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
const auto active = window()->isActiveWindow();
|
||||||
|
if (_activeState != active) {
|
||||||
|
_activeState = active;
|
||||||
|
updateButtonsState();
|
||||||
|
}
|
||||||
|
}, _close->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::setText(const QString &text) {
|
void TitleControls::setStyle(const style::WindowTitle &st) {
|
||||||
window()->setWindowTitle(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TitleWidget::setStyle(const style::WindowTitle &st) {
|
|
||||||
_st = &st;
|
_st = &st;
|
||||||
setGeometry(0, 0, window()->width(), _st->height);
|
|
||||||
updateButtonsState();
|
updateButtonsState();
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
not_null<RpWidget*> TitleWidget::window() const {
|
not_null<const style::WindowTitle*> TitleControls::st() const {
|
||||||
return static_cast<RpWidget*>(parentWidget());
|
return _st;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::setResizeEnabled(bool enabled) {
|
QRect TitleControls::geometry() const {
|
||||||
_resizeEnabled = enabled;
|
auto result = QRect();
|
||||||
updateControlsVisibility();
|
const auto add = [&](auto &&control) {
|
||||||
|
if (!control->isHidden()) {
|
||||||
|
result = result.united(control->geometry());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
add(_minimize);
|
||||||
|
add(_maximizeRestore);
|
||||||
|
add(_close);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::init() {
|
not_null<RpWidget*> TitleControls::parent() const {
|
||||||
|
return static_cast<RpWidget*>(_close->parentWidget());
|
||||||
|
}
|
||||||
|
|
||||||
|
not_null<QWidget*> TitleControls::window() const {
|
||||||
|
return _close->window();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TitleControls::init(Fn<void(bool maximized)> maximize) {
|
||||||
_minimize->setClickedCallback([=] {
|
_minimize->setClickedCallback([=] {
|
||||||
window()->setWindowState(
|
window()->setWindowState(
|
||||||
window()->windowState() | Qt::WindowMinimized);
|
window()->windowState() | Qt::WindowMinimized);
|
||||||
|
|
@ -59,9 +79,13 @@ void TitleWidget::init() {
|
||||||
});
|
});
|
||||||
_minimize->setPointerCursor(false);
|
_minimize->setPointerCursor(false);
|
||||||
_maximizeRestore->setClickedCallback([=] {
|
_maximizeRestore->setClickedCallback([=] {
|
||||||
window()->setWindowState(_maximizedState
|
if (maximize) {
|
||||||
? Qt::WindowNoState
|
maximize(!_maximizedState);
|
||||||
: Qt::WindowMaximized);
|
} else {
|
||||||
|
window()->setWindowState(_maximizedState
|
||||||
|
? Qt::WindowNoState
|
||||||
|
: Qt::WindowMaximized);
|
||||||
|
}
|
||||||
_maximizeRestore->clearState();
|
_maximizeRestore->clearState();
|
||||||
});
|
});
|
||||||
_maximizeRestore->setPointerCursor(false);
|
_maximizeRestore->setPointerCursor(false);
|
||||||
|
|
@ -71,32 +95,32 @@ void TitleWidget::init() {
|
||||||
});
|
});
|
||||||
_close->setPointerCursor(false);
|
_close->setPointerCursor(false);
|
||||||
|
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
parent()->widthValue(
|
||||||
|
|
||||||
window()->widthValue(
|
|
||||||
) | rpl::start_with_next([=](int width) {
|
) | rpl::start_with_next([=](int width) {
|
||||||
setGeometry(0, 0, width, _st->height);
|
updateControlsPosition();
|
||||||
}, lifetime());
|
}, _close->lifetime());
|
||||||
|
|
||||||
window()->createWinId();
|
window()->createWinId();
|
||||||
connect(
|
QObject::connect(
|
||||||
window()->windowHandle(),
|
window()->windowHandle(),
|
||||||
&QWindow::windowStateChanged,
|
&QWindow::windowStateChanged,
|
||||||
[=](Qt::WindowState state) { handleWindowStateChanged(state); });
|
[=](Qt::WindowState state) { handleWindowStateChanged(state); });
|
||||||
_activeState = isActiveWindow();
|
_activeState = parent()->isActiveWindow();
|
||||||
updateButtonsState();
|
updateButtonsState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::paintEvent(QPaintEvent *e) {
|
void TitleControls::setResizeEnabled(bool enabled) {
|
||||||
const auto active = isActiveWindow();
|
_resizeEnabled = enabled;
|
||||||
if (_activeState != active) {
|
updateControlsVisibility();
|
||||||
_activeState = active;
|
|
||||||
updateButtonsState();
|
|
||||||
}
|
|
||||||
QPainter(this).fillRect(e->rect(), active ? _st->bgActive : _st->bg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::updateControlsPosition() {
|
void TitleControls::raise() {
|
||||||
|
_minimize->raise();
|
||||||
|
_maximizeRestore->raise();
|
||||||
|
_close->raise();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TitleControls::updateControlsPosition() {
|
||||||
auto right = 0;
|
auto right = 0;
|
||||||
_close->moveToRight(right, 0); right += _close->width();
|
_close->moveToRight(right, 0); right += _close->width();
|
||||||
_maximizeRestore->moveToRight(right, 0);
|
_maximizeRestore->moveToRight(right, 0);
|
||||||
|
|
@ -106,28 +130,25 @@ void TitleWidget::updateControlsPosition() {
|
||||||
_minimize->moveToRight(right, 0);
|
_minimize->moveToRight(right, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::resizeEvent(QResizeEvent *e) {
|
void TitleControls::updateControlsVisibility() {
|
||||||
updateControlsPosition();
|
|
||||||
_shadow->setGeometry(0, height() - st::lineWidth, width(), st::lineWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TitleWidget::updateControlsVisibility() {
|
|
||||||
_maximizeRestore->setVisible(_resizeEnabled);
|
_maximizeRestore->setVisible(_resizeEnabled);
|
||||||
updateControlsPosition();
|
updateControlsPosition();
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::handleWindowStateChanged(Qt::WindowState state) {
|
void TitleControls::handleWindowStateChanged(Qt::WindowState state) {
|
||||||
if (state == Qt::WindowMinimized) return;
|
if (state == Qt::WindowMinimized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto maximized = (state == Qt::WindowMaximized);
|
auto maximized = (state == Qt::WindowMaximized)
|
||||||
|
|| (state == Qt::WindowFullScreen);
|
||||||
if (_maximizedState != maximized) {
|
if (_maximizedState != maximized) {
|
||||||
_maximizedState = maximized;
|
_maximizedState = maximized;
|
||||||
updateButtonsState();
|
updateButtonsState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleWidget::updateButtonsState() {
|
void TitleControls::updateButtonsState() {
|
||||||
const auto minimize = _activeState
|
const auto minimize = _activeState
|
||||||
? &_st->minimizeIconActive
|
? &_st->minimizeIconActive
|
||||||
: &_st->minimize.icon;
|
: &_st->minimize.icon;
|
||||||
|
|
@ -161,12 +182,45 @@ void TitleWidget::updateButtonsState() {
|
||||||
_close->setIconOverride(close, closeOver);
|
_close->setIconOverride(close, closeOver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TitleWidget::TitleWidget(not_null<RpWidget*> parent)
|
||||||
|
: RpWidget(parent)
|
||||||
|
, _controls(this)
|
||||||
|
, _shadow(this, st::titleShadow) {
|
||||||
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||||
|
|
||||||
|
parent->widthValue(
|
||||||
|
) | rpl::start_with_next([=](int width) {
|
||||||
|
setGeometry(0, 0, width, _controls.st()->height);
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TitleWidget::setText(const QString &text) {
|
||||||
|
window()->setWindowTitle(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TitleWidget::setStyle(const style::WindowTitle &st) {
|
||||||
|
_controls.setStyle(st);
|
||||||
|
setGeometry(0, 0, window()->width(), _controls.st()->height);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TitleWidget::setResizeEnabled(bool enabled) {
|
||||||
|
_controls.setResizeEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TitleWidget::paintEvent(QPaintEvent *e) {
|
||||||
|
const auto active = window()->isActiveWindow();
|
||||||
|
QPainter(this).fillRect(
|
||||||
|
e->rect(),
|
||||||
|
active ? _controls.st()->bgActive : _controls.st()->bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TitleWidget::resizeEvent(QResizeEvent *e) {
|
||||||
|
_shadow->setGeometry(0, height() - st::lineWidth, width(), st::lineWidth);
|
||||||
|
}
|
||||||
|
|
||||||
HitTestResult TitleWidget::hitTest(QPoint point) const {
|
HitTestResult TitleWidget::hitTest(QPoint point) const {
|
||||||
if (false
|
if (_controls.geometry().contains(point)) {
|
||||||
|| (_minimize->geometry().contains(point))
|
|
||||||
|| (_maximizeRestore->geometry().contains(point))
|
|
||||||
|| (_close->geometry().contains(point))
|
|
||||||
) {
|
|
||||||
return HitTestResult::SysButton;
|
return HitTestResult::SysButton;
|
||||||
} else if (rect().contains(point)) {
|
} else if (rect().contains(point)) {
|
||||||
return HitTestResult::Caption;
|
return HitTestResult::Caption;
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,40 @@ enum class HitTestResult {
|
||||||
TopLeft,
|
TopLeft,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TitleControls final {
|
||||||
|
public:
|
||||||
|
TitleControls(
|
||||||
|
not_null<RpWidget*> parent,
|
||||||
|
Fn<void(bool maximized)> maximize = nullptr);
|
||||||
|
|
||||||
|
void setStyle(const style::WindowTitle &st);
|
||||||
|
[[nodiscard]] not_null<const style::WindowTitle*> st() const;
|
||||||
|
[[nodiscard]] QRect geometry() const;
|
||||||
|
void setResizeEnabled(bool enabled);
|
||||||
|
void raise();
|
||||||
|
|
||||||
|
private:
|
||||||
|
[[nodiscard]] not_null<RpWidget*> parent() const;
|
||||||
|
[[nodiscard]] not_null<QWidget*> window() const;
|
||||||
|
|
||||||
|
void init(Fn<void(bool maximized)> maximize);
|
||||||
|
void updateControlsVisibility();
|
||||||
|
void updateButtonsState();
|
||||||
|
void updateControlsPosition();
|
||||||
|
void handleWindowStateChanged(Qt::WindowState state = Qt::WindowNoState);
|
||||||
|
|
||||||
|
not_null<const style::WindowTitle*> _st;
|
||||||
|
|
||||||
|
object_ptr<Ui::IconButton> _minimize;
|
||||||
|
object_ptr<Ui::IconButton> _maximizeRestore;
|
||||||
|
object_ptr<Ui::IconButton> _close;
|
||||||
|
|
||||||
|
bool _maximizedState = false;
|
||||||
|
bool _activeState = false;
|
||||||
|
bool _resizeEnabled = true;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
class TitleWidget : public RpWidget {
|
class TitleWidget : public RpWidget {
|
||||||
public:
|
public:
|
||||||
explicit TitleWidget(not_null<RpWidget*> parent);
|
explicit TitleWidget(not_null<RpWidget*> parent);
|
||||||
|
|
@ -52,25 +86,9 @@ protected:
|
||||||
void resizeEvent(QResizeEvent *e) override;
|
void resizeEvent(QResizeEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
not_null<RpWidget*> window() const;
|
TitleControls _controls;
|
||||||
|
|
||||||
void init();
|
|
||||||
void handleWindowStateChanged(Qt::WindowState state = Qt::WindowNoState);
|
|
||||||
void updateControlsVisibility();
|
|
||||||
void updateButtonsState();
|
|
||||||
void updateControlsPosition();
|
|
||||||
|
|
||||||
not_null<const style::WindowTitle*> _st;
|
|
||||||
|
|
||||||
object_ptr<Ui::IconButton> _minimize;
|
|
||||||
object_ptr<Ui::IconButton> _maximizeRestore;
|
|
||||||
object_ptr<Ui::IconButton> _close;
|
|
||||||
object_ptr<Ui::PlainShadow> _shadow;
|
object_ptr<Ui::PlainShadow> _shadow;
|
||||||
|
|
||||||
bool _maximizedState = false;
|
|
||||||
bool _activeState = false;
|
|
||||||
bool _resizeEnabled = true;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue