mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-20 18:28:11 +00:00
Show reset scale button if window doesn't fit.
This commit is contained in:
parent
17cde3426a
commit
01b4e1946a
@ -340,7 +340,15 @@ void MainWindow::initSize() {
|
||||
|
||||
auto avail = QDesktopWidget().availableGeometry();
|
||||
bool maximized = false;
|
||||
auto geom = QRect(avail.x() + (avail.width() - st::windowDefaultWidth) / 2, avail.y() + (avail.height() - st::windowDefaultHeight) / 2, st::windowDefaultWidth, st::windowDefaultHeight);
|
||||
auto geom = QRect(
|
||||
avail.x() + std::max(
|
||||
(avail.width() - st::windowDefaultWidth) / 2,
|
||||
0),
|
||||
avail.y() + std::max(
|
||||
(avail.height() - st::windowDefaultHeight) / 2,
|
||||
0),
|
||||
st::windowDefaultWidth,
|
||||
st::windowDefaultHeight);
|
||||
if (position.w && position.h) {
|
||||
for (auto screen : QGuiApplication::screens()) {
|
||||
if (position.moncrc == screenNameChecksum(screen->name())) {
|
||||
|
@ -105,6 +105,11 @@ mainMenuCloudButton: IconButton {
|
||||
iconPosition: point(22px, 22px);
|
||||
}
|
||||
mainMenuCloudSize: 32px;
|
||||
mainMenuResetScaleFont: font(20px semibold);
|
||||
mainMenuResetScaleLeft: 36px;
|
||||
mainMenuResetScaleRight: 12px;
|
||||
mainMenuResetScaleTop: 2px;
|
||||
mainMenuResetScaleIconLeft: 5px;
|
||||
mainMenuCoverTextLeft: 30px;
|
||||
mainMenuCoverNameTop: 84px;
|
||||
mainMenuCoverStatusTop: 102px;
|
||||
|
@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "window/window_main_menu.h"
|
||||
|
||||
#include "styles/style_window.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "window/themes/window_theme.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
@ -27,13 +25,97 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "observer_peer.h"
|
||||
#include "auth_session.h"
|
||||
#include "mainwidget.h"
|
||||
#include "styles/style_window.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
namespace Window {
|
||||
namespace {
|
||||
|
||||
template <typename Object, typename Other, typename Value>
|
||||
auto qtSignalProducer(
|
||||
Object *object,
|
||||
void(Other::*signal)(Value)) {
|
||||
using Produced = std::remove_const_t<std::decay_t<Value>>;
|
||||
const auto guarded = make_weak(object);
|
||||
return rpl::make_producer<Produced>([=](auto consumer) {
|
||||
if (!guarded) {
|
||||
return rpl::lifetime();
|
||||
}
|
||||
auto listener = Ui::CreateChild<QObject>(guarded.data());
|
||||
QObject::connect(guarded, signal, listener, [=](Value value) {
|
||||
consumer.put_next_copy(value);
|
||||
});
|
||||
const auto weak = make_weak(listener);
|
||||
return rpl::lifetime([=] {
|
||||
if (weak) {
|
||||
delete weak;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class MainMenu::ResetScaleButton : public Ui::AbstractButton {
|
||||
public:
|
||||
ResetScaleButton(QWidget *parent);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
static constexpr auto kText = "100%";
|
||||
|
||||
};
|
||||
|
||||
MainMenu::ResetScaleButton::ResetScaleButton(QWidget *parent)
|
||||
: AbstractButton(parent) {
|
||||
const auto margin = st::mainMenuCloudButton.height
|
||||
- st::mainMenuCloudSize;
|
||||
const auto textWidth = st::mainMenuResetScaleFont->width(kText);
|
||||
const auto innerWidth = st::mainMenuResetScaleLeft
|
||||
+ textWidth
|
||||
+ st::mainMenuResetScaleRight;
|
||||
const auto width = margin + innerWidth;
|
||||
resize(width, st::mainMenuCloudButton.height);
|
||||
}
|
||||
|
||||
void MainMenu::ResetScaleButton::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
|
||||
const auto innerHeight = st::mainMenuCloudSize;
|
||||
const auto radius = innerHeight / 2;
|
||||
const auto margin = st::mainMenuCloudButton.height
|
||||
- st::mainMenuCloudSize;
|
||||
const auto textWidth = st::mainMenuResetScaleFont->width(kText);
|
||||
const auto innerWidth = st::mainMenuResetScaleLeft
|
||||
+ textWidth
|
||||
+ st::mainMenuResetScaleRight;
|
||||
const auto left = margin / 2;
|
||||
const auto top = margin / 2;
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush(st::mainMenuCloudBg);
|
||||
p.drawRoundedRect(left, top, innerWidth, innerHeight, radius, radius);
|
||||
|
||||
st::settingsIconInterfaceScale.paint(
|
||||
p,
|
||||
left + st::mainMenuResetScaleIconLeft,
|
||||
top + ((innerHeight - st::settingsIconInterfaceScale.height()) / 2),
|
||||
width(),
|
||||
st::mainMenuCloudFg->c);
|
||||
|
||||
p.setFont(st::mainMenuResetScaleFont);
|
||||
p.setPen(st::mainMenuCloudFg);
|
||||
p.drawText(
|
||||
left + st::mainMenuResetScaleLeft,
|
||||
top + st::mainMenuResetScaleTop + st::mainMenuResetScaleFont->ascent,
|
||||
kText);
|
||||
}
|
||||
|
||||
MainMenu::MainMenu(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller)
|
||||
: TWidget(parent)
|
||||
: RpWidget(parent)
|
||||
, _controller(controller)
|
||||
, _menu(this, st::mainMenu)
|
||||
, _telegram(this, st::mainMenuTelegramLabel)
|
||||
@ -91,6 +173,7 @@ MainMenu::MainMenu(
|
||||
}
|
||||
});
|
||||
updatePhone();
|
||||
initResetScaleButton();
|
||||
}
|
||||
|
||||
void MainMenu::refreshMenu() {
|
||||
@ -171,6 +254,9 @@ void MainMenu::updateControlsGeometry() {
|
||||
if (_cloudButton) {
|
||||
_cloudButton->moveToRight(0, st::mainMenuCoverHeight - _cloudButton->height());
|
||||
}
|
||||
if (_resetScaleButton) {
|
||||
_resetScaleButton->moveToRight(0, 0);
|
||||
}
|
||||
_menu->moveToLeft(0, st::mainMenuCoverHeight + st::mainMenuSkip);
|
||||
_telegram->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuTelegramBottom - _telegram->height());
|
||||
_version->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuVersionBottom - _version->height());
|
||||
@ -206,15 +292,6 @@ void MainMenu::paintEvent(QPaintEvent *e) {
|
||||
st::mainMenuCloudSize,
|
||||
st::mainMenuCloudBg,
|
||||
st::mainMenuCloudFg);
|
||||
//PainterHighQualityEnabler hq(p);
|
||||
//p.setPen(Qt::NoPen);
|
||||
//p.setBrush(st::mainMenuCloudBg);
|
||||
//auto cloudBg = QRect(
|
||||
// _cloudButton->x() + (_cloudButton->width() - st::mainMenuCloudSize) / 2,
|
||||
// _cloudButton->y() + (_cloudButton->height() - st::mainMenuCloudSize) / 2,
|
||||
// st::mainMenuCloudSize,
|
||||
// st::mainMenuCloudSize);
|
||||
//p.drawEllipse(cloudBg);
|
||||
}
|
||||
}
|
||||
auto other = QRect(0, st::mainMenuCoverHeight, width(), height() - st::mainMenuCoverHeight).intersected(clip);
|
||||
@ -223,4 +300,40 @@ void MainMenu::paintEvent(QPaintEvent *e) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainMenu::initResetScaleButton() {
|
||||
if (!window() || !window()->windowHandle()) {
|
||||
return;
|
||||
}
|
||||
const auto handle = window()->windowHandle();
|
||||
rpl::single(
|
||||
handle->screen()
|
||||
) | rpl::then(
|
||||
qtSignalProducer(handle, &QWindow::screenChanged)
|
||||
) | rpl::map([](QScreen *screen) {
|
||||
return rpl::single(
|
||||
screen->availableGeometry()
|
||||
) | rpl::then(
|
||||
qtSignalProducer(screen, &QScreen::availableGeometryChanged)
|
||||
);
|
||||
}) | rpl::flatten_latest(
|
||||
) | rpl::map([](QRect available) {
|
||||
return (available.width() >= st::windowMinWidth)
|
||||
&& (available.height() >= st::windowMinHeight);
|
||||
}) | rpl::distinct_until_changed(
|
||||
) | rpl::start_with_next([=](bool good) {
|
||||
if (good) {
|
||||
_resetScaleButton.destroy();
|
||||
} else {
|
||||
_resetScaleButton.create(this);
|
||||
_resetScaleButton->addClickHandler([] {
|
||||
cSetConfigScale(kInterfaceScaleDefault);
|
||||
Local::writeSettings();
|
||||
App::restart();
|
||||
});
|
||||
_resetScaleButton->show();
|
||||
updateControlsGeometry();
|
||||
}
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
} // namespace Window
|
||||
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#pragma once
|
||||
|
||||
#include "base/timer.h"
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
namespace Ui {
|
||||
class IconButton;
|
||||
@ -20,7 +21,7 @@ namespace Window {
|
||||
|
||||
class Controller;
|
||||
|
||||
class MainMenu : public TWidget, private base::Subscriber {
|
||||
class MainMenu : public Ui::RpWidget, private base::Subscriber {
|
||||
public:
|
||||
MainMenu(QWidget *parent, not_null<Controller*> controller);
|
||||
|
||||
@ -35,11 +36,14 @@ protected:
|
||||
private:
|
||||
void updateControlsGeometry();
|
||||
void updatePhone();
|
||||
void initResetScaleButton();
|
||||
void refreshMenu();
|
||||
|
||||
class ResetScaleButton;
|
||||
not_null<Controller*> _controller;
|
||||
object_ptr<Ui::UserpicButton> _userpicButton = { nullptr };
|
||||
object_ptr<Ui::IconButton> _cloudButton = { nullptr };
|
||||
object_ptr<ResetScaleButton> _resetScaleButton = { nullptr };
|
||||
object_ptr<Ui::Menu> _menu;
|
||||
object_ptr<Ui::FlatLabel> _telegram;
|
||||
object_ptr<Ui::FlatLabel> _version;
|
||||
|
Loading…
Reference in New Issue
Block a user