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
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "sysbuttons.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "lang.h"
|
2016-02-27 19:39:51 +00:00
|
|
|
#include "shortcuts.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "application.h"
|
2015-06-03 18:13:01 +00:00
|
|
|
#include "autoupdater.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
SysBtn::SysBtn(QWidget *parent, const style::sysButton &st, const QString &text) : Button(parent)
|
|
|
|
, _st(st)
|
|
|
|
, a_color(_st.color->c)
|
|
|
|
, _a_color(animation(this, &SysBtn::step_color))
|
|
|
|
, _overLevel(0)
|
|
|
|
, _text(text) {
|
2016-09-30 12:52:03 +00:00
|
|
|
int32 w = _st.size.width() + (_text.isEmpty() ? 0 : ((_st.size.width() - _st.icon.width()) / 2 + st::titleTextButton.font->width(_text)));
|
2014-11-18 12:41:33 +00:00
|
|
|
resize(w, _st.size.height());
|
2014-05-30 08:53:19 +00:00
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
|
2014-12-01 10:47:38 +00:00
|
|
|
void SysBtn::setText(const QString &text) {
|
|
|
|
_text = text;
|
2016-09-30 12:52:03 +00:00
|
|
|
int32 w = _st.size.width() + (_text.isEmpty() ? 0 : ((_st.size.width() - _st.icon.width()) / 2 + st::titleTextButton.font->width(_text)));
|
2014-12-01 10:47:38 +00:00
|
|
|
resize(w, _st.size.height());
|
|
|
|
}
|
|
|
|
|
2014-11-18 12:41:33 +00:00
|
|
|
void SysBtn::setOverLevel(float64 level) {
|
|
|
|
_overLevel = level;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-09-21 11:44:20 +00:00
|
|
|
void SysBtn::onStateChanged(int oldState, ButtonStateChangeSource source) {
|
2014-05-30 08:53:19 +00:00
|
|
|
a_color.start((_state & StateOver ? _st.overColor : _st.color)->c);
|
|
|
|
|
|
|
|
if (source == ButtonByUser || source == ButtonByPress) {
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_color.stop();
|
2014-05-30 08:53:19 +00:00
|
|
|
a_color.finish();
|
|
|
|
update();
|
|
|
|
} else {
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_color.start();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysBtn::paintEvent(QPaintEvent *e) {
|
2016-04-21 17:57:29 +00:00
|
|
|
Painter p(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-09-30 12:52:03 +00:00
|
|
|
int x = width() - ((_st.size.width() + _st.icon.width()) / 2), y = (height() - _st.icon.height()) / 2;
|
2014-11-18 12:41:33 +00:00
|
|
|
QColor c = a_color.current();
|
|
|
|
if (_overLevel > 0) {
|
|
|
|
if (_overLevel >= 1) {
|
|
|
|
c = _st.overColor->c;
|
|
|
|
} else {
|
|
|
|
c.setRedF(c.redF() * (1 - _overLevel) + _st.overColor->c.redF() * _overLevel);
|
|
|
|
c.setGreenF(c.greenF() * (1 - _overLevel) + _st.overColor->c.greenF() * _overLevel);
|
|
|
|
c.setBlueF(c.blueF() * (1 - _overLevel) + _st.overColor->c.blueF() * _overLevel);
|
|
|
|
}
|
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
p.fillRect(x, y, _st.icon.width(), _st.icon.height(), c);
|
|
|
|
_st.icon.paint(p, x, y, width());
|
2016-01-11 15:43:29 +00:00
|
|
|
|
2014-11-18 12:41:33 +00:00
|
|
|
if (!_text.isEmpty()) {
|
|
|
|
p.setFont(st::titleTextButton.font->f);
|
|
|
|
p.setPen(c);
|
2016-09-30 12:52:03 +00:00
|
|
|
p.drawText((_st.size.width() - _st.icon.width()) / 2, st::titleTextButton.textTop + st::titleTextButton.font->ascent, _text);
|
2014-11-18 12:41:33 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
void SysBtn::setSysBtnStyle(const style::sysButton &st) {
|
|
|
|
_st = st;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
HitTestType SysBtn::hitTest(const QPoint &p) const {
|
|
|
|
int x(p.x()), y(p.y()), w(width()), h(height());
|
|
|
|
if (x >= 0 && y >= 0 && x < w && y < h && isVisible()) {
|
2016-09-29 11:37:16 +00:00
|
|
|
return HitTestType::SysButton;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-09-29 11:37:16 +00:00
|
|
|
return HitTestType::None;
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void SysBtn::step_color(float64 ms, bool timer) {
|
2014-05-30 08:53:19 +00:00
|
|
|
float64 dt = ms / _st.duration;
|
|
|
|
if (dt >= 1) {
|
2015-12-08 12:33:37 +00:00
|
|
|
_a_color.stop();
|
2014-05-30 08:53:19 +00:00
|
|
|
a_color.finish();
|
|
|
|
} else {
|
|
|
|
a_color.update(dt, anim::linear);
|
|
|
|
}
|
2015-12-08 12:33:37 +00:00
|
|
|
if (timer) update();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:44:20 +00:00
|
|
|
MinimizeBtn::MinimizeBtn(QWidget *parent) : SysBtn(parent, st::sysMin) {
|
|
|
|
setClickedCallback([this]() {
|
|
|
|
window()->setWindowState(Qt::WindowMinimized);
|
|
|
|
});
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:44:20 +00:00
|
|
|
MaximizeBtn::MaximizeBtn(QWidget *parent) : SysBtn(parent, st::sysMax) {
|
|
|
|
setClickedCallback([this]() {
|
|
|
|
window()->setWindowState(Qt::WindowMaximized);
|
|
|
|
});
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:44:20 +00:00
|
|
|
RestoreBtn::RestoreBtn(QWidget *parent) : SysBtn(parent, st::sysRes) {
|
|
|
|
setClickedCallback([this]() {
|
|
|
|
window()->setWindowState(Qt::WindowNoState);
|
|
|
|
});
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:44:20 +00:00
|
|
|
CloseBtn::CloseBtn(QWidget *parent) : SysBtn(parent, st::sysCls) {
|
|
|
|
setClickedCallback([this]() {
|
|
|
|
window()->close();
|
|
|
|
});
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:44:20 +00:00
|
|
|
UpdateBtn::UpdateBtn(QWidget *parent) : SysBtn(parent, st::sysUpd, lang(lng_menu_update)) {
|
|
|
|
setClickedCallback([]() {
|
2016-01-30 16:31:10 +00:00
|
|
|
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
|
2016-09-21 11:44:20 +00:00
|
|
|
checkReadyUpdate();
|
|
|
|
if (Sandbox::updatingState() == Application::UpdatingReady) {
|
|
|
|
cSetRestartingUpdate(true);
|
|
|
|
} else
|
2016-01-30 16:31:10 +00:00
|
|
|
#endif
|
2016-09-21 11:44:20 +00:00
|
|
|
{
|
|
|
|
cSetRestarting(true);
|
|
|
|
cSetRestartingToSettings(false);
|
|
|
|
}
|
|
|
|
App::quit();
|
|
|
|
});
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:44:20 +00:00
|
|
|
LockBtn::LockBtn(QWidget *parent) : SysBtn(parent, st::sysLock) {
|
|
|
|
setClickedCallback([] {
|
|
|
|
Shortcuts::launch(qsl("lock_telegram"));
|
|
|
|
});
|
2015-03-02 12:34:16 +00:00
|
|
|
}
|