2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

version 0.6.16 - document/video paths storage, username not found box support, download/upload sessions stop/resume

This commit is contained in:
John Preston
2014-12-05 16:44:27 +03:00
parent e91f93bfed
commit a7a43e4031
26 changed files with 504 additions and 145 deletions

View File

@@ -22,23 +22,53 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
#include "mainwidget.h"
#include "window.h"
ConfirmBox::ConfirmBox(QString text, QString doneText, QString cancelText) :
_confirm(this, doneText.isEmpty() ? lang(lng_continue) : doneText, st::btnSelectDone),
_cancel(this, cancelText.isEmpty() ? lang(lng_cancel) : cancelText, st::btnSelectCancel),
_text(100), _hiding(false), a_opacity(0, 1), af_opacity(anim::linear) {
TextParseOptions _confirmBoxTextOptions = {
TextParseLinks | TextParseMultiline | TextParseRichText, // flags
0, // maxw
0, // maxh
Qt::LayoutDirectionAuto, // dir
};
_text.setText(st::boxFont, text, _textPlainOptions);
ConfirmBox::ConfirmBox(const QString &text, const QString &doneText, const QString &cancelText) : _infoMsg(false),
_confirm(this, doneText.isEmpty() ? lang(lng_continue) : doneText, st::btnSelectDone),
_cancel(this, cancelText.isEmpty() ? lang(lng_cancel) : cancelText, st::btnSelectCancel),
_close(this, QString(), st::btnInfoClose),
_text(100), _hiding(false), a_opacity(0, 1), af_opacity(anim::linear) {
init(text);
}
ConfirmBox::ConfirmBox(const QString &text, bool noDone, const QString &cancelText) : _infoMsg(true),
_confirm(this, QString(), st::btnSelectDone),
_cancel(this, QString(), st::btnSelectCancel),
_close(this, cancelText.isEmpty() ? lang(lng_close) : cancelText, st::btnInfoClose),
_text(100), _hiding(false), a_opacity(0, 1), af_opacity(anim::linear) {
init(text);
}
void ConfirmBox::init(const QString &text) {
_text.setText(st::boxFont, text, (_infoMsg ? _confirmBoxTextOptions : _textPlainOptions));
_width = st::confirmWidth;
_textWidth = _width - st::boxPadding.left() - st::boxPadding.right();
_textHeight = _text.countHeight(_textWidth);
_height = st::boxPadding.top() + _textHeight + st::boxPadding.bottom() + _confirm.height();
_height = st::boxPadding.top() + _textHeight + st::boxPadding.bottom() + (_infoMsg ? _close.height() : _confirm.height());
_confirm.move(_width - _confirm.width(), st::boxPadding.top() + _textHeight + st::boxPadding.bottom());
_cancel.move(0, st::boxPadding.top() + _textHeight + st::boxPadding.bottom());
if (_infoMsg) {
_confirm.hide();
_cancel.hide();
_close.move(0, st::boxPadding.top() + _textHeight + st::boxPadding.bottom());
connect(&_confirm, SIGNAL(clicked()), this, SIGNAL(confirmed()));
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onCancel()));
connect(&_close, SIGNAL(clicked()), this, SLOT(onCancel()));
setMouseTracking(_text.hasLinks());
} else {
_confirm.move(_width - _confirm.width(), st::boxPadding.top() + _textHeight + st::boxPadding.bottom());
_cancel.move(0, st::boxPadding.top() + _textHeight + st::boxPadding.bottom());
_close.hide();
connect(&_confirm, SIGNAL(clicked()), this, SIGNAL(confirmed()));
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onCancel()));
}
resize(_width, _height);
@@ -47,14 +77,73 @@ ConfirmBox::ConfirmBox(QString text, QString doneText, QString cancelText) :
hideAll();
}
void ConfirmBox::mouseMoveEvent(QMouseEvent *e) {
_lastMousePos = e->globalPos();
updateHover();
}
void ConfirmBox::mousePressEvent(QMouseEvent *e) {
_lastMousePos = e->globalPos();
updateHover();
if (textlnkOver()) {
textlnkDown(textlnkOver());
update();
}
}
void ConfirmBox::mouseReleaseEvent(QMouseEvent *e) {
_lastMousePos = e->globalPos();
updateHover();
if (textlnkOver() && textlnkOver() == textlnkDown()) {
App::wnd()->hideLayer();
textlnkOver()->onClick(e->button());
}
textlnkDown(TextLinkPtr());
}
void ConfirmBox::leaveEvent(QEvent *e) {
if (_myLink) {
if (textlnkOver() == _myLink) {
textlnkOver(TextLinkPtr());
update();
}
_myLink = TextLinkPtr();
setCursor(style::cur_default);
update();
}
}
void ConfirmBox::updateLink() {
_lastMousePos = QCursor::pos();
updateHover();
}
void ConfirmBox::updateHover() {
QPoint m(mapFromGlobal(_lastMousePos));
bool wasMy = (_myLink == textlnkOver());
_myLink = _text.link(m.x() - st::boxPadding.left(), m.y() - st::boxPadding.top(), _textWidth, (_text.maxWidth() < _width) ? style::al_center : style::al_left);
if (_myLink != textlnkOver()) {
if (wasMy || _myLink || rect().contains(m)) {
textlnkOver(_myLink);
}
setCursor(_myLink ? style::cur_pointer : style::cur_default);
update();
}
}
void ConfirmBox::hideAll() {
_confirm.hide();
_cancel.hide();
_close.hide();
}
void ConfirmBox::showAll() {
_confirm.show();
_cancel.show();
if (_infoMsg) {
_close.show();
} else {
_confirm.show();
_cancel.show();
}
}
void ConfirmBox::keyPressEvent(QKeyEvent *e) {
@@ -78,11 +167,13 @@ void ConfirmBox::paintEvent(QPaintEvent *e) {
// fill bg
p.fillRect(0, 0, _width, _height, st::boxBG->b);
// paint shadows
p.fillRect(0, _height - st::btnSelectCancel.height - st::scrollDef.bottomsh, _width, st::scrollDef.bottomsh, st::scrollDef.shColor->b);
if (!_infoMsg) {
// paint shadows
p.fillRect(0, _height - st::btnSelectCancel.height - st::scrollDef.bottomsh, _width, st::scrollDef.bottomsh, st::scrollDef.shColor->b);
// paint button sep
p.fillRect(st::btnSelectCancel.width, _height - st::btnSelectCancel.height, st::lineWidth, st::btnSelectCancel.height, st::btnSelectSep->b);
// paint button sep
p.fillRect(st::btnSelectCancel.width, _height - st::btnSelectCancel.height, st::lineWidth, st::btnSelectCancel.height, st::btnSelectSep->b);
}
// draw box title / text
p.setFont(st::boxFont->f);