2016-11-04 08:23:50 +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
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "platform/win/window_title_win.h"
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-04 11:14:47 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2016-11-04 08:23:50 +00:00
|
|
|
#include "styles/style_window.h"
|
|
|
|
|
|
|
|
namespace Platform {
|
|
|
|
|
|
|
|
TitleWidget::TitleWidget(QWidget *parent) : Window::TitleWidget(parent)
|
|
|
|
, _minimize(this, st::titleButtonMinimize)
|
|
|
|
, _maximizeRestore(this, st::titleButtonMaximize)
|
|
|
|
, _close(this, st::titleButtonClose)
|
2016-11-06 18:45:50 +00:00
|
|
|
, _shadow(this, st::titleShadow)
|
|
|
|
, _maximized(parent->window()->windowState() & Qt::WindowMaximized) {
|
2016-11-04 08:23:50 +00:00
|
|
|
_minimize->setClickedCallback([this]() {
|
|
|
|
window()->setWindowState(Qt::WindowMinimized);
|
|
|
|
_minimize->clearState();
|
|
|
|
});
|
2016-12-31 13:34:41 +00:00
|
|
|
_minimize->setPointerCursor(false);
|
2016-11-04 08:23:50 +00:00
|
|
|
_maximizeRestore->setClickedCallback([this]() {
|
|
|
|
window()->setWindowState(_maximized ? Qt::WindowNoState : Qt::WindowMaximized);
|
|
|
|
_maximizeRestore->clearState();
|
|
|
|
});
|
2016-12-31 13:34:41 +00:00
|
|
|
_maximizeRestore->setPointerCursor(false);
|
2016-11-04 08:23:50 +00:00
|
|
|
_close->setClickedCallback([this]() {
|
|
|
|
window()->close();
|
|
|
|
_close->clearState();
|
|
|
|
});
|
2016-12-31 13:34:41 +00:00
|
|
|
_close->setPointerCursor(false);
|
2016-11-04 08:23:50 +00:00
|
|
|
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2016-11-08 14:07:25 +00:00
|
|
|
resize(width(), st::titleHeight);
|
2016-11-07 15:24:28 +00:00
|
|
|
}
|
2016-11-04 08:23:50 +00:00
|
|
|
|
2016-11-07 15:24:28 +00:00
|
|
|
void TitleWidget::init() {
|
|
|
|
connect(window()->windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(onWindowStateChanged(Qt::WindowState)));
|
|
|
|
_maximized = (window()->windowState() & Qt::WindowMaximized);
|
|
|
|
updateMaximizeRestoreButton();
|
2016-11-04 08:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TitleWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter(this).fillRect(rect(), st::titleBg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TitleWidget::updateControlsPosition() {
|
|
|
|
auto right = 0;
|
|
|
|
_close->moveToRight(right, 0); right += _close->width();
|
|
|
|
_maximizeRestore->moveToRight(right, 0); right += _maximizeRestore->width();
|
|
|
|
_minimize->moveToRight(right, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TitleWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
updateControlsPosition();
|
2016-11-04 11:14:47 +00:00
|
|
|
_shadow->setGeometry(0, height() - st::lineWidth, width(), st::lineWidth);
|
2016-11-04 08:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TitleWidget::updateControlsVisibility() {
|
|
|
|
updateControlsPosition();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TitleWidget::onWindowStateChanged(Qt::WindowState state) {
|
|
|
|
if (state == Qt::WindowMinimized) return;
|
|
|
|
|
|
|
|
auto maximized = (state == Qt::WindowMaximized);
|
|
|
|
if (_maximized != maximized) {
|
|
|
|
_maximized = maximized;
|
|
|
|
updateMaximizeRestoreButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TitleWidget::updateMaximizeRestoreButton() {
|
|
|
|
if (_maximized) {
|
2016-12-05 11:01:08 +00:00
|
|
|
_maximizeRestore->setIconOverride(&st::titleButtonRestoreIcon, &st::titleButtonRestoreIconOver);
|
2016-11-04 08:23:50 +00:00
|
|
|
} else {
|
2016-12-05 11:01:08 +00:00
|
|
|
_maximizeRestore->setIconOverride(nullptr, nullptr);
|
2016-11-04 08:23:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Window::HitTestResult TitleWidget::hitTest(const QPoint &p) const {
|
|
|
|
if (false
|
|
|
|
|| (_minimize->geometry().contains(p))
|
|
|
|
|| (_maximizeRestore->geometry().contains(p))
|
|
|
|
|| (_close->geometry().contains(p))
|
|
|
|
) {
|
|
|
|
return Window::HitTestResult::SysButton;
|
|
|
|
} else if (rect().contains(p)) {
|
|
|
|
return Window::HitTestResult::Caption;
|
|
|
|
}
|
|
|
|
return Window::HitTestResult::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Platform
|