2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2015-10-03 13:16:42 +00:00
|
|
|
Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
#include "layerwidget.h"
|
|
|
|
#include "application.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "gui/filedialog.h"
|
|
|
|
|
2015-09-16 13:04:08 +00:00
|
|
|
BackgroundWidget::BackgroundWidget(QWidget *parent, LayeredWidget *w) : QWidget(parent), w(w),
|
2015-05-22 11:14:52 +00:00
|
|
|
aBackground(0), aBackgroundFunc(anim::easeOutCirc), hiding(false), shadow(st::boxShadow) {
|
2014-05-30 08:53:19 +00:00
|
|
|
w->setParent(this);
|
2015-10-15 11:51:10 +00:00
|
|
|
if (App::app()) App::app()->mtpPause();
|
2014-05-30 08:53:19 +00:00
|
|
|
setGeometry(0, 0, App::wnd()->width(), App::wnd()->height());
|
|
|
|
aBackground.start(1);
|
|
|
|
anim::start(this);
|
|
|
|
show();
|
|
|
|
connect(w, SIGNAL(closed()), this, SLOT(onInnerClose()));
|
|
|
|
connect(w, SIGNAL(resized()), this, SLOT(update()));
|
2014-12-12 16:27:03 +00:00
|
|
|
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*)));
|
2014-05-30 08:53:19 +00:00
|
|
|
w->setFocus();
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
void BackgroundWidget::showFast() {
|
|
|
|
animStep(st::layerSlideDuration + 1);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void BackgroundWidget::paintEvent(QPaintEvent *e) {
|
2014-12-12 16:27:03 +00:00
|
|
|
if (!w) return;
|
2014-05-30 08:53:19 +00:00
|
|
|
bool trivial = (rect() == e->rect());
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
if (!trivial) {
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
}
|
|
|
|
p.setOpacity(st::layerAlpha * aBackground.current());
|
2015-10-11 08:37:24 +00:00
|
|
|
p.fillRect(rect(), st::layerBg->b);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
p.setOpacity(aBackground.current());
|
2015-10-01 14:05:05 +00:00
|
|
|
shadow.paint(p, w->geometry(), st::boxShadowShift);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundWidget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Escape) {
|
2015-10-15 11:51:10 +00:00
|
|
|
onClose();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundWidget::mousePressEvent(QMouseEvent *e) {
|
2014-10-10 12:46:20 +00:00
|
|
|
onClose();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundWidget::onClose() {
|
|
|
|
startHide();
|
|
|
|
}
|
|
|
|
|
2014-11-25 12:15:29 +00:00
|
|
|
bool BackgroundWidget::onInnerClose() {
|
2015-09-16 13:04:08 +00:00
|
|
|
if (_hidden.isEmpty()) {
|
2014-05-30 08:53:19 +00:00
|
|
|
onClose();
|
2014-11-25 12:15:29 +00:00
|
|
|
return true;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-11-25 12:15:29 +00:00
|
|
|
w->deleteLater();
|
2015-09-16 13:04:08 +00:00
|
|
|
w = _hidden.back();
|
|
|
|
_hidden.pop_back();
|
2014-11-25 12:15:29 +00:00
|
|
|
w->show();
|
|
|
|
resizeEvent(0);
|
|
|
|
w->animStep(1);
|
|
|
|
update();
|
|
|
|
return false;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundWidget::startHide() {
|
2015-09-16 13:04:08 +00:00
|
|
|
if (hiding) return;
|
2015-10-15 11:51:10 +00:00
|
|
|
if (App::app()) App::app()->mtpPause();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
hiding = true;
|
2015-09-16 13:04:08 +00:00
|
|
|
if (App::wnd()) App::wnd()->setInnerFocus();
|
2014-05-30 08:53:19 +00:00
|
|
|
aBackground.start(0);
|
|
|
|
anim::start(this);
|
|
|
|
w->startHide();
|
|
|
|
}
|
|
|
|
|
2015-09-16 13:04:08 +00:00
|
|
|
bool BackgroundWidget::canSetFocus() const {
|
|
|
|
return w && !hiding;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundWidget::setInnerFocus() {
|
|
|
|
if (w) {
|
|
|
|
w->setInnerFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 14:05:05 +00:00
|
|
|
bool BackgroundWidget::contentOverlapped(const QRect &globalRect) {
|
|
|
|
if (isHidden()) return false;
|
|
|
|
return w && w->overlaps(globalRect);
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void BackgroundWidget::resizeEvent(QResizeEvent *e) {
|
|
|
|
w->parentResized();
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
void BackgroundWidget::updateWideMode() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
void BackgroundWidget::replaceInner(LayeredWidget *n) {
|
2015-09-16 13:04:08 +00:00
|
|
|
_hidden.push_back(w);
|
|
|
|
w->hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
w = n;
|
|
|
|
w->setParent(this);
|
|
|
|
connect(w, SIGNAL(closed()), this, SLOT(onInnerClose()));
|
|
|
|
connect(w, SIGNAL(resized()), this, SLOT(update()));
|
2014-12-12 16:27:03 +00:00
|
|
|
connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*)));
|
2014-05-30 08:53:19 +00:00
|
|
|
w->show();
|
|
|
|
resizeEvent(0);
|
|
|
|
w->animStep(1);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2015-10-27 02:39:02 +00:00
|
|
|
void BackgroundWidget::showLayerLast(LayeredWidget *n) {
|
|
|
|
_hidden.push_front(n);
|
|
|
|
n->setParent(this);
|
|
|
|
connect(n, SIGNAL(closed()), this, SLOT(onInnerClose()));
|
|
|
|
connect(n, SIGNAL(resized()), this, SLOT(update()));
|
|
|
|
connect(n, SIGNAL(destroyed(QObject*)), this, SLOT(boxDestroyed(QObject*)));
|
|
|
|
n->parentResized();
|
|
|
|
n->animStep(1);
|
|
|
|
n->hide();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
bool BackgroundWidget::animStep(float64 ms) {
|
|
|
|
float64 dt = ms / (hiding ? st::layerHideDuration : st::layerSlideDuration);
|
|
|
|
w->animStep(dt);
|
|
|
|
bool res = true;
|
|
|
|
if (dt >= 1) {
|
|
|
|
aBackground.finish();
|
|
|
|
if (hiding) {
|
2014-12-12 16:27:03 +00:00
|
|
|
App::wnd()->layerFinishedHide(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2014-12-12 16:27:03 +00:00
|
|
|
anim::stop(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
res = false;
|
2015-10-15 11:51:10 +00:00
|
|
|
if (App::app()) App::app()->mtpUnpause();
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
aBackground.update(dt, aBackgroundFunc);
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-12-12 16:27:03 +00:00
|
|
|
void BackgroundWidget::boxDestroyed(QObject *obj) {
|
|
|
|
if (obj == w) {
|
|
|
|
if (App::wnd()) App::wnd()->layerFinishedHide(this);
|
|
|
|
w = 0;
|
2015-09-16 13:04:08 +00:00
|
|
|
} else {
|
|
|
|
int32 index = _hidden.indexOf(static_cast<LayeredWidget*>(obj));
|
|
|
|
if (index >= 0) {
|
|
|
|
_hidden.removeAt(index);
|
|
|
|
}
|
2014-12-12 16:27:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
BackgroundWidget::~BackgroundWidget() {
|
|
|
|
if (App::wnd()) App::wnd()->noBox(this);
|
|
|
|
w->deleteLater();
|
2015-09-16 13:04:08 +00:00
|
|
|
for (HiddenLayers::const_iterator i = _hidden.cbegin(), e = _hidden.cend(); i != e; ++i) {
|
|
|
|
(*i)->deleteLater();
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|