2016-06-16 12:59:54 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-06-16 12:59:54 +00:00
|
|
|
*/
|
|
|
|
#include "window/main_window.h"
|
|
|
|
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2016-11-04 11:14:47 +00:00
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "platform/platform_window_title.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2017-06-21 21:38:31 +00:00
|
|
|
#include "window/window_controller.h"
|
2016-12-31 15:19:22 +00:00
|
|
|
#include "mediaview.h"
|
2017-05-12 15:27:19 +00:00
|
|
|
#include "messenger.h"
|
2016-12-31 15:19:22 +00:00
|
|
|
#include "mainwindow.h"
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
constexpr auto kInactivePressTimeout = 200;
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
QImage LoadLogo() {
|
|
|
|
return QImage(qsl(":/gui/art/logo_256.png"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage LoadLogoNoMargin() {
|
|
|
|
return QImage(qsl(":/gui/art/logo_256_no_margin.png"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon CreateOfficialIcon() {
|
|
|
|
auto useNoMarginLogo = (cPlatform() == dbipMac);
|
|
|
|
if (auto messenger = Messenger::InstancePointer()) {
|
|
|
|
return QIcon(App::pixmapFromImageInPlace(useNoMarginLogo ? messenger->logoNoMargin() : messenger->logo()));
|
|
|
|
}
|
|
|
|
return QIcon(App::pixmapFromImageInPlace(useNoMarginLogo ? LoadLogoNoMargin() : LoadLogo()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon CreateIcon() {
|
|
|
|
auto result = CreateOfficialIcon();
|
|
|
|
if (cPlatform() == dbipLinux32 || cPlatform() == dbipLinux64) {
|
|
|
|
return QIcon::fromTheme("telegram", result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-07 15:24:28 +00:00
|
|
|
MainWindow::MainWindow() : QWidget()
|
2016-11-04 11:14:47 +00:00
|
|
|
, _positionUpdatedTimer(this)
|
2016-11-09 08:34:38 +00:00
|
|
|
, _body(this)
|
2017-05-12 15:27:19 +00:00
|
|
|
, _icon(CreateIcon())
|
2017-06-21 21:38:31 +00:00
|
|
|
, _titleText(qsl("Telegram")) {
|
2016-12-31 13:34:41 +00:00
|
|
|
subscribe(Theme::Background(), [this](const Theme::BackgroundUpdate &data) {
|
2016-12-23 13:21:01 +00:00
|
|
|
if (data.paletteChanged()) {
|
2016-11-04 11:14:47 +00:00
|
|
|
if (_title) {
|
|
|
|
_title->update();
|
|
|
|
}
|
2016-12-31 13:34:41 +00:00
|
|
|
updatePalette();
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
});
|
2016-11-09 08:34:38 +00:00
|
|
|
subscribe(Global::RefUnreadCounterUpdate(), [this] { updateUnreadCounter(); });
|
2017-03-04 19:36:59 +00:00
|
|
|
subscribe(Global::RefWorkMode(), [this](DBIWorkMode mode) { workmodeUpdated(mode); });
|
2017-06-21 21:38:31 +00:00
|
|
|
subscribe(Messenger::Instance().authSessionChanged(), [this] { checkAuthSession(); });
|
|
|
|
checkAuthSession();
|
2017-01-01 16:45:20 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
_isActiveTimer.setCallback([this] { updateIsActive(0); });
|
|
|
|
_inactivePressTimer.setCallback([this] { setInactivePress(false); });
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
bool MainWindow::hideNoQuit() {
|
2017-08-08 09:56:10 +00:00
|
|
|
if (App::quitting()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-04 19:36:59 +00:00
|
|
|
if (Global::WorkMode().value() == dbiwmTrayOnly || Global::WorkMode().value() == dbiwmWindowAndTray) {
|
2016-12-31 15:19:22 +00:00
|
|
|
if (minimizeToTray()) {
|
|
|
|
Ui::showChatsList();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (cPlatform() == dbipMac || cPlatform() == dbipMacOld) {
|
|
|
|
closeWithoutDestroy();
|
|
|
|
updateIsActive(Global::OfflineBlurTimeout());
|
|
|
|
updateGlobalMenu();
|
|
|
|
Ui::showChatsList();
|
|
|
|
return true;
|
|
|
|
}
|
2017-01-01 16:45:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::clearWidgets() {
|
2017-09-20 10:23:57 +00:00
|
|
|
Ui::hideLayer(anim::type::instant);
|
2017-01-01 16:45:20 +00:00
|
|
|
clearWidgetsHook();
|
|
|
|
updateGlobalMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updateIsActive(int timeout) {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (timeout > 0) {
|
|
|
|
return _isActiveTimer.callOnce(timeout);
|
2017-01-01 16:45:20 +00:00
|
|
|
}
|
|
|
|
_isActive = computeIsActive();
|
|
|
|
updateIsActiveHook();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::computeIsActive() const {
|
|
|
|
return isActiveWindow() && isVisible() && !(windowState() & Qt::WindowMinimized);
|
2016-12-31 15:19:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onReActivate() {
|
|
|
|
if (auto w = App::wnd()) {
|
|
|
|
if (auto f = QApplication::focusWidget()) {
|
|
|
|
f->clearFocus();
|
|
|
|
}
|
|
|
|
w->windowHandle()->requestActivate();
|
|
|
|
w->activate();
|
|
|
|
if (auto f = QApplication::focusWidget()) {
|
|
|
|
f->clearFocus();
|
|
|
|
}
|
|
|
|
w->setInnerFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 15:27:19 +00:00
|
|
|
void MainWindow::updateWindowIcon() {
|
|
|
|
setWindowIcon(_icon);
|
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
void MainWindow::init() {
|
2017-10-16 14:16:01 +00:00
|
|
|
Expects(!windowHandle());
|
|
|
|
createWinId();
|
|
|
|
|
2016-11-08 14:07:25 +00:00
|
|
|
initHook();
|
2017-05-12 15:27:19 +00:00
|
|
|
updateWindowIcon();
|
2016-11-08 14:07:25 +00:00
|
|
|
|
2017-05-19 14:02:55 +00:00
|
|
|
connect(windowHandle(), &QWindow::activeChanged, this, [this] { handleActiveChanged(); }, Qt::QueuedConnection);
|
|
|
|
connect(windowHandle(), &QWindow::windowStateChanged, this, [this](Qt::WindowState state) { handleStateChanged(state); });
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
_positionUpdatedTimer->setSingleShot(true);
|
|
|
|
connect(_positionUpdatedTimer, SIGNAL(timeout()), this, SLOT(savePositionByTimer()));
|
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
updatePalette();
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2016-11-08 14:07:25 +00:00
|
|
|
if ((_title = Platform::CreateTitleWidget(this))) {
|
|
|
|
_title->init();
|
|
|
|
}
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2016-11-07 15:24:28 +00:00
|
|
|
initSize();
|
2016-11-15 11:56:49 +00:00
|
|
|
updateUnreadCounter();
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 14:02:55 +00:00
|
|
|
void MainWindow::handleStateChanged(Qt::WindowState state) {
|
|
|
|
stateChangedHook(state);
|
|
|
|
updateIsActive((state == Qt::WindowMinimized) ? Global::OfflineBlurTimeout() : Global::OnlineFocusTimeout());
|
|
|
|
psUserActionDone();
|
|
|
|
if (state == Qt::WindowMinimized && Global::WorkMode().value() == dbiwmTrayOnly) {
|
|
|
|
minimizeToTray();
|
|
|
|
}
|
|
|
|
savePosition(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::handleActiveChanged() {
|
2017-08-08 09:31:48 +00:00
|
|
|
if (isActiveWindow()) {
|
|
|
|
Messenger::Instance().checkMediaViewActivation();
|
2017-05-19 14:02:55 +00:00
|
|
|
}
|
|
|
|
App::CallDelayed(1, this, [this] {
|
|
|
|
updateTrayMenu();
|
2017-11-15 12:46:34 +00:00
|
|
|
handleActiveChangedHook();
|
2017-05-19 14:02:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-31 13:34:41 +00:00
|
|
|
void MainWindow::updatePalette() {
|
|
|
|
auto p = palette();
|
|
|
|
p.setColor(QPalette::Window, st::windowBg->c);
|
|
|
|
setPalette(p);
|
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
HitTestResult MainWindow::hitTest(const QPoint &p) const {
|
|
|
|
auto titleResult = _title ? _title->hitTest(p - _title->geometry().topLeft()) : Window::HitTestResult::None;
|
|
|
|
if (titleResult != Window::HitTestResult::None) {
|
|
|
|
return titleResult;
|
|
|
|
} else if (rect().contains(p)) {
|
|
|
|
return Window::HitTestResult::Client;
|
|
|
|
}
|
|
|
|
return Window::HitTestResult::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::initSize() {
|
|
|
|
setMinimumWidth(st::windowMinWidth);
|
|
|
|
setMinimumHeight((_title ? _title->height() : 0) + st::windowMinHeight);
|
|
|
|
|
2017-07-03 12:23:41 +00:00
|
|
|
auto position = cWindowPos();
|
|
|
|
DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized)));
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
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);
|
2017-07-03 12:23:41 +00:00
|
|
|
if (position.w && position.h) {
|
2016-11-04 11:14:47 +00:00
|
|
|
for (auto screen : QGuiApplication::screens()) {
|
2017-07-03 12:23:41 +00:00
|
|
|
if (position.moncrc == screenNameChecksum(screen->name())) {
|
2016-11-04 11:14:47 +00:00
|
|
|
auto screenGeometry = screen->geometry();
|
2017-07-03 12:23:41 +00:00
|
|
|
DEBUG_LOG(("Window Pos: Screen found, screen geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
auto w = screenGeometry.width(), h = screenGeometry.height();
|
|
|
|
if (w >= st::windowMinWidth && h >= st::windowMinHeight) {
|
2017-07-18 16:38:11 +00:00
|
|
|
if (position.x < 0) position.x = 0;
|
|
|
|
if (position.y < 0) position.y = 0;
|
2017-07-03 12:23:41 +00:00
|
|
|
if (position.w > w) position.w = w;
|
|
|
|
if (position.h > h) position.h = h;
|
|
|
|
position.x += screenGeometry.x();
|
|
|
|
position.y += screenGeometry.y();
|
|
|
|
if (position.x + st::windowMinWidth <= screenGeometry.x() + screenGeometry.width() &&
|
|
|
|
position.y + st::windowMinHeight <= screenGeometry.y() + screenGeometry.height()) {
|
|
|
|
DEBUG_LOG(("Window Pos: Resulting geometry is %1, %2, %3, %4").arg(position.x).arg(position.y).arg(position.w).arg(position.h));
|
|
|
|
geom = QRect(position.x, position.y, position.w, position.h);
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 12:23:41 +00:00
|
|
|
maximized = position.maximized;
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
2017-07-03 12:23:41 +00:00
|
|
|
DEBUG_LOG(("Window Pos: Setting first %1, %2, %3, %4").arg(geom.x()).arg(geom.y()).arg(geom.width()).arg(geom.height()));
|
2016-11-04 11:14:47 +00:00
|
|
|
setGeometry(geom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::positionUpdated() {
|
|
|
|
_positionUpdatedTimer->start(SaveWindowPositionTimeout);
|
|
|
|
}
|
|
|
|
|
2016-11-09 08:34:38 +00:00
|
|
|
bool MainWindow::titleVisible() const {
|
|
|
|
return _title && !_title->isHidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setTitleVisible(bool visible) {
|
2016-11-08 14:07:25 +00:00
|
|
|
if (_title && (_title->isHidden() == visible)) {
|
|
|
|
_title->setVisible(visible);
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
2016-11-09 08:34:38 +00:00
|
|
|
titleVisibilityChangedHook();
|
2016-11-08 14:07:25 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
int32 MainWindow::screenNameChecksum(const QString &name) const {
|
|
|
|
auto bytes = name.toUtf8();
|
|
|
|
return hashCrc32(bytes.constData(), bytes.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setPositionInited() {
|
|
|
|
_positionInited = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::resizeEvent(QResizeEvent *e) {
|
2016-11-08 14:07:25 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
rpl::producer<> MainWindow::leaveEvents() const {
|
|
|
|
return _leaveEvents.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::leaveEvent(QEvent *e) {
|
|
|
|
_leaveEvents.fire({});
|
|
|
|
}
|
|
|
|
|
2016-11-08 14:07:25 +00:00
|
|
|
void MainWindow::updateControlsGeometry() {
|
2016-11-04 11:14:47 +00:00
|
|
|
auto bodyTop = 0;
|
2017-02-03 20:07:26 +00:00
|
|
|
auto bodyWidth = width();
|
2016-11-08 14:07:25 +00:00
|
|
|
if (_title && !_title->isHidden()) {
|
|
|
|
_title->setGeometry(0, bodyTop, width(), _title->height());
|
2016-11-04 11:14:47 +00:00
|
|
|
bodyTop += _title->height();
|
|
|
|
}
|
2017-02-03 20:07:26 +00:00
|
|
|
if (_rightColumn) {
|
|
|
|
bodyWidth -= _rightColumn->width();
|
|
|
|
_rightColumn->setGeometry(bodyWidth, bodyTop, width() - bodyWidth, height() - bodyTop);
|
|
|
|
}
|
|
|
|
_body->setGeometry(0, bodyTop, bodyWidth, height() - bodyTop);
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 08:34:38 +00:00
|
|
|
void MainWindow::updateUnreadCounter() {
|
|
|
|
if (!Global::started() || App::quitting()) return;
|
|
|
|
|
|
|
|
auto counter = App::histories().unreadBadge();
|
|
|
|
_titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram");
|
|
|
|
|
|
|
|
unreadCounterChangedHook();
|
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
void MainWindow::savePosition(Qt::WindowState state) {
|
|
|
|
if (state == Qt::WindowActive) state = windowHandle()->windowState();
|
|
|
|
if (state == Qt::WindowMinimized || !positionInited()) return;
|
|
|
|
|
2017-07-03 12:23:41 +00:00
|
|
|
auto savedPosition = cWindowPos();
|
|
|
|
auto realPosition = savedPosition;
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
if (state == Qt::WindowMaximized) {
|
2017-07-03 12:23:41 +00:00
|
|
|
realPosition.maximized = 1;
|
2016-11-04 11:14:47 +00:00
|
|
|
} else {
|
2016-11-04 19:50:35 +00:00
|
|
|
auto r = geometry();
|
2017-07-03 12:23:41 +00:00
|
|
|
realPosition.x = r.x();
|
|
|
|
realPosition.y = r.y();
|
|
|
|
realPosition.w = r.width() - (_rightColumn ? _rightColumn->width() : 0);
|
|
|
|
realPosition.h = r.height();
|
|
|
|
realPosition.maximized = 0;
|
|
|
|
realPosition.moncrc = 0;
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
2017-07-03 12:23:41 +00:00
|
|
|
DEBUG_LOG(("Window Pos: Saving position: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2017-07-03 12:23:41 +00:00
|
|
|
auto centerX = realPosition.x + realPosition.w / 2;
|
|
|
|
auto centerY = realPosition.y + realPosition.h / 2;
|
2016-11-04 11:14:47 +00:00
|
|
|
int minDelta = 0;
|
2017-07-03 12:23:41 +00:00
|
|
|
QScreen *chosen = nullptr;
|
2016-11-04 11:14:47 +00:00
|
|
|
auto screens = QGuiApplication::screens();
|
|
|
|
for (auto screen : QGuiApplication::screens()) {
|
2017-07-03 12:23:41 +00:00
|
|
|
auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
|
2016-11-04 11:14:47 +00:00
|
|
|
if (!chosen || delta < minDelta) {
|
|
|
|
minDelta = delta;
|
|
|
|
chosen = screen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chosen) {
|
2017-07-03 12:23:41 +00:00
|
|
|
auto screenGeometry = chosen->geometry();
|
|
|
|
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
|
|
|
|
realPosition.x -= screenGeometry.x();
|
|
|
|
realPosition.y -= screenGeometry.y();
|
|
|
|
realPosition.moncrc = screenNameChecksum(chosen->name());
|
2016-11-04 11:14:47 +00:00
|
|
|
}
|
|
|
|
|
2017-07-03 12:23:41 +00:00
|
|
|
if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
|
|
|
|
if (realPosition.x != savedPosition.x
|
|
|
|
|| realPosition.y != savedPosition.y
|
|
|
|
|| realPosition.w != savedPosition.w
|
|
|
|
|| realPosition.h != savedPosition.h
|
|
|
|
|| realPosition.moncrc != savedPosition.moncrc
|
|
|
|
|| realPosition.maximized != savedPosition.maximized) {
|
|
|
|
DEBUG_LOG(("Window Pos: Writing: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
|
|
|
|
cSetWindowPos(realPosition);
|
2016-11-04 11:14:47 +00:00
|
|
|
Local::writeSettings();
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
bool MainWindow::minimizeToTray() {
|
2017-01-01 16:45:20 +00:00
|
|
|
if (App::quitting() || !hasTrayIcon()) return false;
|
2016-12-31 15:19:22 +00:00
|
|
|
|
|
|
|
closeWithoutDestroy();
|
|
|
|
updateIsActive(Global::OfflineBlurTimeout());
|
|
|
|
updateTrayMenu();
|
|
|
|
updateGlobalMenu();
|
2017-01-01 16:45:20 +00:00
|
|
|
showTrayTooltip();
|
2016-12-31 15:19:22 +00:00
|
|
|
return true;
|
2016-06-16 12:59:54 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
void MainWindow::showRightColumn(object_ptr<TWidget> widget) {
|
|
|
|
auto wasWidth = width();
|
|
|
|
auto wasRightWidth = _rightColumn ? _rightColumn->width() : 0;
|
2017-02-21 13:45:56 +00:00
|
|
|
_rightColumn = std::move(widget);
|
2017-02-03 20:07:26 +00:00
|
|
|
if (_rightColumn) {
|
|
|
|
_rightColumn->setParent(this);
|
|
|
|
_rightColumn->show();
|
|
|
|
_rightColumn->setFocus();
|
|
|
|
} else if (App::wnd()) {
|
|
|
|
App::wnd()->setInnerFocus();
|
|
|
|
}
|
|
|
|
auto nowRightWidth = _rightColumn ? _rightColumn->width() : 0;
|
|
|
|
setMinimumWidth(st::windowMinWidth + nowRightWidth);
|
|
|
|
if (!isMaximized()) {
|
2017-04-09 18:06:06 +00:00
|
|
|
tryToExtendWidthBy(wasWidth + nowRightWidth - wasRightWidth - width());
|
|
|
|
} else {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 16:43:52 +00:00
|
|
|
int MainWindow::maximalExtendBy() const {
|
2017-04-09 18:06:06 +00:00
|
|
|
auto desktop = QDesktopWidget().availableGeometry(this);
|
2017-11-16 16:43:52 +00:00
|
|
|
return std::max(desktop.width() - geometry().width(), 0);
|
2017-04-09 18:06:06 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 16:43:52 +00:00
|
|
|
bool MainWindow::canExtendNoMove(int extendBy) const {
|
2017-04-09 18:06:06 +00:00
|
|
|
auto desktop = QDesktopWidget().availableGeometry(this);
|
2017-11-16 16:43:52 +00:00
|
|
|
auto inner = geometry();
|
|
|
|
auto innerRight = (inner.x() + inner.width() + extendBy);
|
|
|
|
auto desktopRight = (desktop.x() + desktop.width());
|
|
|
|
return innerRight <= desktopRight;
|
|
|
|
}
|
|
|
|
|
|
|
|
int MainWindow::tryToExtendWidthBy(int addToWidth) {
|
|
|
|
auto desktop = QDesktopWidget().availableGeometry(this);
|
|
|
|
auto inner = geometry();
|
|
|
|
accumulate_min(
|
|
|
|
addToWidth,
|
|
|
|
std::max(desktop.width() - inner.width(), 0));
|
|
|
|
auto newWidth = inner.width() + addToWidth;
|
|
|
|
auto newLeft = std::min(
|
|
|
|
inner.x(),
|
|
|
|
desktop.x() + desktop.width() - newWidth);
|
|
|
|
if (inner.x() != newLeft || inner.width() != newWidth) {
|
|
|
|
setGeometry(newLeft, inner.y(), newWidth, inner.height());
|
2017-02-03 20:07:26 +00:00
|
|
|
} else {
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
2017-11-16 16:43:52 +00:00
|
|
|
return addToWidth;
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
|
|
|
|
auto weak = QPointer<MainWindow>(this);
|
|
|
|
auto drag = std::make_unique<QDrag>(App::wnd());
|
|
|
|
drag->setMimeData(data.release());
|
|
|
|
drag->exec(Qt::CopyAction);
|
|
|
|
|
|
|
|
// We don't receive mouseReleaseEvent when drag is finished.
|
|
|
|
ClickHandler::unpressed();
|
|
|
|
if (weak) {
|
|
|
|
weak->dragFinished().notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::checkAuthSession() {
|
|
|
|
if (AuthSession::Exists()) {
|
|
|
|
_controller = std::make_unique<Window::Controller>(this);
|
|
|
|
} else {
|
|
|
|
_controller = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setInactivePress(bool inactive) {
|
|
|
|
_wasInactivePress = inactive;
|
|
|
|
if (_wasInactivePress) {
|
|
|
|
_inactivePressTimer.callOnce(kInactivePressTimeout);
|
|
|
|
} else {
|
|
|
|
_inactivePressTimer.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
MainWindow::~MainWindow() = default;
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
} // namespace Window
|