2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Dialog styles moved from basic.style to dialogs.style.

Many minor design improvements in the new profiles.
New drafts design in the dialogs list: no icon, red badge.
Verified checkbox added to the new profile implementation.
Drafts saving to cloud is delayed for 1 second when switching chats.
Before quitting the app makes an attempt to save drafts (timeout 1.5s).
This commit is contained in:
John Preston
2016-06-07 22:59:39 +03:00
parent 6aca90c478
commit 1859b83e8d
56 changed files with 725 additions and 801 deletions

View File

@@ -27,6 +27,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "shortcuts.h"
#include "lang.h"
#include "ui/buttons/peer_avatar_button.h"
#include "ui/buttons/round_button.h"
#include "ui/flatbutton.h"
namespace Window {
@@ -37,19 +38,15 @@ TopBarWidget::TopBarWidget(MainWidget *w) : TWidget(w)
, _selPeer(0)
, _selCount(0)
, _canDelete(false)
, _selStrLeft(-st::topBarButton.width / 2)
, _selStrLeft((-st::topBarClearButton.width + st::topBarClearButton.padding.left() + st::topBarClearButton.padding.right()) / 2)
, _selStrWidth(0)
, _animating(false)
, _clearSelection(this, lang(lng_selected_clear), st::topBarButton)
, _clearSelection(this, lang(lng_selected_clear), st::topBarClearButton)
, _forward(this, lang(lng_selected_forward), st::topBarActionButton)
, _delete(this, lang(lng_selected_delete), st::topBarActionButton)
, _selectionButtonsWidth(_clearSelection->width() + _forward->width() + _delete->width())
, _forwardDeleteWidth(qMax(_forward->textWidth(), _delete->textWidth()))
, _info(this, nullptr, st::infoButton)
, _edit(this, lang(lng_profile_edit_contact), st::topBarButton)
, _leaveGroup(this, lang(lng_profile_delete_and_exit), st::topBarButton)
, _addContact(this, lang(lng_profile_add_contact), st::topBarButton)
, _deleteContact(this, lang(lng_profile_delete_contact), st::topBarButton)
, _mediaType(this, lang(lng_media_type), st::topBarButton)
, _search(this, st::topBarSearch) {
@@ -57,10 +54,6 @@ TopBarWidget::TopBarWidget(MainWidget *w) : TWidget(w)
connect(_delete, SIGNAL(clicked()), this, SLOT(onDeleteSelection()));
connect(_clearSelection, SIGNAL(clicked()), this, SLOT(onClearSelection()));
connect(_info, SIGNAL(clicked()), this, SLOT(onInfoClicked()));
connect(_addContact, SIGNAL(clicked()), this, SLOT(onAddContact()));
connect(_deleteContact, SIGNAL(clicked()), this, SLOT(onDeleteContact()));
connect(_edit, SIGNAL(clicked()), this, SLOT(onEdit()));
connect(_leaveGroup, SIGNAL(clicked()), this, SLOT(onDeleteAndExit()));
connect(_search, SIGNAL(clicked()), this, SLOT(onSearch()));
setCursor(style::cur_pointer);
@@ -84,65 +77,6 @@ void TopBarWidget::onInfoClicked() {
if (p) Ui::showPeerProfile(p);
}
void TopBarWidget::onAddContact() {
PeerData *p = nullptr;// App::main() ? App::main()->profilePeer() : 0;
UserData *u = p ? p->asUser() : 0;
if (u) Ui::showLayer(new AddContactBox(u->firstName, u->lastName, u->phone().isEmpty() ? App::phoneFromSharedContact(peerToUser(u->id)) : u->phone()));
}
void TopBarWidget::onEdit() {
PeerData *p = nullptr;// App::main() ? App::main()->profilePeer() : 0;
if (p) {
if (p->isChannel()) {
Ui::showLayer(new EditChannelBox(p->asChannel()));
} else if (p->isChat()) {
Ui::showLayer(new EditNameTitleBox(p));
} else if (p->isUser()) {
Ui::showLayer(new AddContactBox(p->asUser()));
}
}
}
void TopBarWidget::onDeleteContact() {
PeerData *p = nullptr;// App::main() ? App::main()->profilePeer() : 0;
UserData *u = p ? p->asUser() : 0;
if (u) {
ConfirmBox *box = new ConfirmBox(lng_sure_delete_contact(lt_contact, p->name), lang(lng_box_delete));
connect(box, SIGNAL(confirmed()), this, SLOT(onDeleteContactSure()));
Ui::showLayer(box);
}
}
void TopBarWidget::onDeleteContactSure() {
PeerData *p = nullptr;// App::main() ? App::main()->profilePeer() : 0;
UserData *u = p ? p->asUser() : 0;
if (u) {
Ui::showChatsList();
Ui::hideLayer();
MTP::send(MTPcontacts_DeleteContact(u->inputUser), App::main()->rpcDone(&MainWidget::deletedContact, u));
}
}
void TopBarWidget::onDeleteAndExit() {
PeerData *p = nullptr;// App::main() ? App::main()->profilePeer() : 0;
ChatData *c = p ? p->asChat() : 0;
if (c) {
ConfirmBox *box = new ConfirmBox(lng_sure_delete_and_exit(lt_group, p->name), lang(lng_box_leave), st::attentionBoxButton);
connect(box, SIGNAL(confirmed()), this, SLOT(onDeleteAndExitSure()));
Ui::showLayer(box);
}
}
void TopBarWidget::onDeleteAndExitSure() {
PeerData *p = nullptr;// App::main() ? App::main()->profilePeer() : 0;
ChatData *c = p ? p->asChat() : 0;
if (c) {
Ui::showChatsList();
Ui::hideLayer();
MTP::send(MTPmessages_DeleteChatUser(c->inputChat, App::self()->inputUser), App::main()->rpcDone(&MainWidget::deleteHistoryAfterLeave, p), App::main()->rpcFail(&MainWidget::leaveChatFailed, p));
}
}
void TopBarWidget::onSearch() {
Shortcuts::launch(qsl("search"));
}
@@ -197,7 +131,7 @@ void TopBarWidget::paintEvent(QPaintEvent *e) {
} else {
p.setFont(st::linkFont);
p.setPen(st::btnDefLink.color);
p.drawText(_selStrLeft, st::topBarButton.textTop + st::linkFont->ascent, _selStr);
p.drawText(_selStrLeft, st::topBarClearButton.padding.top() + st::topBarClearButton.textTop + st::linkFont->ascent, _selStr);
}
}
@@ -211,8 +145,10 @@ void TopBarWidget::mousePressEvent(QMouseEvent *e) {
void TopBarWidget::resizeEvent(QResizeEvent *e) {
int32 r = width();
if (!_forward->isHidden() || !_delete->isHidden()) {
int32 fullW = r - (_selectionButtonsWidth + (_selStrWidth - st::topBarButton.width) + st::topBarActionSkip);
int32 selectedClearWidth = st::topBarButton.width, forwardDeleteWidth = st::topBarActionButton.width - _forwardDeleteWidth, skip = st::topBarActionSkip;
int fullW = r - (_selectionButtonsWidth + (_selStrWidth - st::topBarClearButton.width + st::topBarClearButton.padding.left() + st::topBarClearButton.padding.right()) + st::topBarActionSkip);
int selectedClearWidth = st::topBarClearButton.width - st::topBarClearButton.padding.left() - st::topBarClearButton.padding.right();
int forwardDeleteWidth = st::topBarActionButton.width - _forwardDeleteWidth;
int skip = st::topBarActionSkip;
while (fullW < 0) {
int fit = 0;
if (selectedClearWidth < -2 * (st::topBarMinPadding + 1)) {
@@ -245,7 +181,7 @@ void TopBarWidget::resizeEvent(QResizeEvent *e) {
}
if (fullW >= 0 || fit >= 3) break;
}
_clearSelection->setWidth(selectedClearWidth);
_clearSelection->setFullWidth(selectedClearWidth);
_forward->setWidth(_forwardDeleteWidth + forwardDeleteWidth);
_delete->setWidth(_forwardDeleteWidth + forwardDeleteWidth);
_selStrLeft = -selectedClearWidth / 2;
@@ -262,20 +198,12 @@ void TopBarWidget::resizeEvent(QResizeEvent *e) {
_clearSelection->move(r -= _clearSelection->width(), 0);
}
if (!_info->isHidden()) _info->move(r -= _info->width(), 0);
if (!_deleteContact->isHidden()) _deleteContact->move(r -= _deleteContact->width(), 0);
if (!_leaveGroup->isHidden()) _leaveGroup->move(r -= _leaveGroup->width(), 0);
if (!_edit->isHidden()) _edit->move(r -= _edit->width(), 0);
if (!_addContact->isHidden()) _addContact->move(r -= _addContact->width(), 0);
if (!_mediaType->isHidden()) _mediaType->move(r -= _mediaType->width(), 0);
_search->move(width() - (_info->isHidden() ? st::topBarForwardPadding.right() : _info->width()) - _search->width(), 0);
}
void TopBarWidget::startAnim() {
_info->hide();
_edit->hide();
_leaveGroup->hide();
_addContact->hide();
_deleteContact->hide();
_clearSelection->hide();
_delete->hide();
_forward->hide();
@@ -295,74 +223,37 @@ void TopBarWidget::showAll() {
resizeEvent(0);
return;
}
PeerData *p = nullptr/*App::main() ? App::main()->profilePeer() : 0*/, *h = App::main() ? App::main()->historyPeer() : 0, *o = App::main() ? App::main()->overviewPeer() : 0;
if (p && (p->isChat() || (p->isUser() && (p->asUser()->contact >= 0 || !App::phoneFromSharedContact(peerToUser(p->id)).isEmpty())))) {
if (p->isChat()) {
if (p->asChat()->canEdit()) {
_edit->show();
} else {
_edit->hide();
}
_leaveGroup->show();
_addContact->hide();
_deleteContact->hide();
} else if (p->asUser()->contact > 0) {
_edit->show();
_leaveGroup->hide();
_addContact->hide();
_deleteContact->show();
PeerData *h = App::main() ? App::main()->historyPeer() : 0, *o = App::main() ? App::main()->overviewPeer() : 0;
if (_selCount) {
_clearSelection->show();
if (_canDelete) {
_delete->show();
} else {
_edit->hide();
_leaveGroup->hide();
_addContact->show();
_deleteContact->hide();
_delete->hide();
}
_forward->show();
_mediaType->hide();
} else {
_clearSelection->hide();
_info->hide();
_delete->hide();
_forward->hide();
_mediaType->hide();
_search->hide();
} else {
if (p && p->isChannel() && (p->asChannel()->amCreator() || (p->isMegagroup() && p->asChannel()->amEditor()))) {
_edit->show();
if (App::main() && App::main()->mediaTypeSwitch()) {
_mediaType->show();
} else {
_edit->hide();
}
_leaveGroup->hide();
_addContact->hide();
_deleteContact->hide();
if (!p && _selCount) {
_clearSelection->show();
if (_canDelete) {
_delete->show();
} else {
_delete->hide();
}
_forward->show();
_mediaType->hide();
} else {
_clearSelection->hide();
_delete->hide();
_forward->hide();
if (App::main() && App::main()->mediaTypeSwitch()) {
_mediaType->show();
} else {
_mediaType->hide();
}
}
if (h && !o && !p && _clearSelection->isHidden()) {
if (Adaptive::OneColumn()) {
_info->setPeer(h);
_info->show();
} else {
_info->hide();
}
_search->show();
}
if (h && !o && _clearSelection->isHidden()) {
if (Adaptive::OneColumn()) {
_info->setPeer(h);
_info->show();
} else {
_search->hide();
_info->hide();
}
_search->show();
} else {
_search->hide();
_info->hide();
}
resizeEvent(nullptr);
}
@@ -382,7 +273,7 @@ void TopBarWidget::updateAdaptiveLayout() {
showAll();
}
FlatButton *TopBarWidget::mediaTypeButton() {
Ui::RoundButton *TopBarWidget::mediaTypeButton() {
return _mediaType;
}