2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +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

@@ -19,7 +19,69 @@ Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
using "basic.style";
using "basic_types.style";
dialogsDraft: icon {
{ "dialogs_draft", #ffffff, point(5px, 4px) },
};
dialogsUnreadFg: #ffffff;
dialogsUnreadFgActive: #5b94bf;
dialogsUnreadBg: #009ce6;//#6fc766;
dialogsUnreadBgMuted: #bbb;
dialogsUnreadBgActive: #ffffff;
dialogsUnreadBgMutedActive: #d3e2ee;
dialogsUnreadFont: font(12px bold);
dialogsUnreadHeight: 19px;
dialogsUnreadTop: 1px;
dialogsUnreadPadding: 5px;
dialogsBg: windowBg;
dialogsBgOver: #f5f5f5;
dialogsBgActive: #6a91b1;
dialogsTextFont: font(fsize);
dialogsTextFg: #888888;
dialogsTextFgService: #4981af;
dialogsTextFgActive: #ffffff;
dialogsDateFont: font(13px);
dialogsDateFgActive: #ffffff;
dialogsDateFg: #a8a8a8;
dialogsDateSkip: 5px;
dialogsNameFg: #000;
dialogsNameTop: 2px;
dialogsRowHeight: 62px;
dialogsFilterPadding: 10px;
dialogsPhotoSize: 46px;
dialogsPhotoPadding: 12px;
dialogsPadding: point(10px, 8px);
dialogsImportantBarHeight: 37px;
dialogsSkip: 8px;
dialogsWidthMin: 260px;
dialogsWidthMax: 540px;
dialogsTextWidthMin: 150px;
dialogsScroll: flatScroll(scrollDef) {
topsh: 0px;
bottomsh: 0px;
}
dialogsChatImgPos: point(1px, 4px);
dialogsChannelImgPos: point(3px, 4px);
dialogsImgSkip: 22px;
dialogsCheckLeft: 5px;
dialogsCheckTop: 4px;
dialogsCheckSkip: 3px;
dialogsTextStyle: textStyle(defaultTextStyle) {
linkFg: dialogsTextFgService;
linkFgDown: dialogsTextFgService;
linkFlagsOver: font(fsize);
}
dialogsTextStyleDraft: textStyle(dialogsTextStyle) {
linkFg: #dd4b39;
linkFgDown: #dd4b39;
}
dialogsTextStyleActive: textStyle(dialogsTextStyle) {
linkFg: dialogsTextFgActive;
linkFgDown: dialogsTextFgActive;
}

View File

@@ -42,80 +42,68 @@ void paintRowDate(Painter &p, const QDateTime &date, QRect &rectForName, bool ac
} else {
dt = lastDate.toString(qsl("d.MM.yy"));
}
int32 dtWidth = st::dlgDateFont->width(dt);
rectForName.setWidth(rectForName.width() - dtWidth - st::dlgDateSkip);
p.setFont(st::dlgDateFont);
p.setPen(active ? st::dlgActiveDateColor : st::dlgDateColor);
p.drawText(rectForName.left() + rectForName.width() + st::dlgDateSkip, rectForName.top() + st::msgNameFont->height - st::msgDateFont->descent, dt);
int32 dtWidth = st::dialogsDateFont->width(dt);
rectForName.setWidth(rectForName.width() - dtWidth - st::dialogsDateSkip);
p.setFont(st::dialogsDateFont);
p.setPen(active ? st::dialogsDateFgActive : st::dialogsDateFg);
p.drawText(rectForName.left() + rectForName.width() + st::dialogsDateSkip, rectForName.top() + st::msgNameFont->height - st::msgDateFont->descent, dt);
}
template <typename PaintItemCallback>
void paintRow(Painter &p, History *history, HistoryItem *item, HistoryDraft *draft, int w, bool active, bool selected, bool onlyBackground, PaintItemCallback paintItemCallback) {
QRect fullRect(0, 0, w, st::dlgHeight);
p.fillRect(fullRect, active ? st::dlgActiveBG : (selected ? st::dlgHoverBG : st::dlgBG));
QRect fullRect(0, 0, w, st::dialogsRowHeight);
p.fillRect(fullRect, active ? st::dialogsBgActive : (selected ? st::dialogsBgOver : st::dialogsBg));
if (onlyBackground) return;
PeerData *userpicPeer = (history->peer->migrateTo() ? history->peer->migrateTo() : history->peer);
userpicPeer->paintUserpicLeft(p, st::dlgPhotoSize, st::dlgPaddingHor, st::dlgPaddingVer, w);
userpicPeer->paintUserpicLeft(p, st::dialogsPhotoSize, st::dialogsPadding.x(), st::dialogsPadding.y(), w);
int32 nameleft = st::dlgPaddingHor + st::dlgPhotoSize + st::dlgPhotoPadding;
int32 namewidth = w - nameleft - st::dlgPaddingHor;
QRect rectForName(nameleft, st::dlgPaddingVer + st::dlgNameTop, namewidth, st::msgNameFont->height);
int32 nameleft = st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPhotoPadding;
int32 namewidth = w - nameleft - st::dialogsPadding.x();
QRect rectForName(nameleft, st::dialogsPadding.y() + st::dialogsNameTop, namewidth, st::msgNameFont->height);
// draw chat icon
if (history->peer->isChat() || history->peer->isMegagroup()) {
p.drawSprite(QPoint(rectForName.left() + st::dlgChatImgPos.x(), rectForName.top() + st::dlgChatImgPos.y()), (active ? st::dlgActiveChatImg : st::dlgChatImg));
rectForName.setLeft(rectForName.left() + st::dlgImgSkip);
p.drawSprite(QPoint(rectForName.left() + st::dialogsChatImgPos.x(), rectForName.top() + st::dialogsChatImgPos.y()), (active ? st::dlgActiveChatImg : st::dlgChatImg));
rectForName.setLeft(rectForName.left() + st::dialogsImgSkip);
} else if (history->peer->isChannel()) {
p.drawSprite(QPoint(rectForName.left() + st::dlgChannelImgPos.x(), rectForName.top() + st::dlgChannelImgPos.y()), (active ? st::dlgActiveChannelImg : st::dlgChannelImg));
rectForName.setLeft(rectForName.left() + st::dlgImgSkip);
p.drawSprite(QPoint(rectForName.left() + st::dialogsChannelImgPos.x(), rectForName.top() + st::dialogsChannelImgPos.y()), (active ? st::dlgActiveChannelImg : st::dlgChannelImg));
rectForName.setLeft(rectForName.left() + st::dialogsImgSkip);
}
int texttop = st::dlgPaddingVer + st::dlgFont->height + st::dlgSep;
int texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
if (draft) {
paintRowDate(p, draft->date, rectForName, active);
// draw check
if (draft->saveRequestId) {
auto check = active ? &st::dlgActiveSendImg : &st::dlgSendImg;
rectForName.setWidth(rectForName.width() - check->pxWidth() - st::dlgCheckSkip);
p.drawSprite(QPoint(rectForName.left() + rectForName.width() + st::dlgCheckLeft, rectForName.top() + st::dlgCheckTop), *check);
rectForName.setWidth(rectForName.width() - check->pxWidth() - st::dialogsCheckSkip);
p.drawSprite(QPoint(rectForName.left() + rectForName.width() + st::dialogsCheckLeft, rectForName.top() + st::dialogsCheckTop), *check);
}
bool hasDraftIcon = !active;
if (hasDraftIcon) {
QString counter;
bool mutedCounter = false;
int unreadRight = w - st::dlgPaddingHor;
int unreadTop = texttop + st::dlgHistFont->ascent - st::dlgUnreadFont->ascent - st::dlgUnreadTop;
int unreadWidth = 0;
paintUnreadCount(p, counter, unreadRight, unreadTop, style::al_right, active, mutedCounter, &unreadWidth);
st::dialogsDraft.paint(p, QPoint(w - st::dlgPaddingHor - st::dlgUnreadHeight, unreadTop), w);
namewidth -= unreadWidth + st::dlgUnreadPaddingHor;
}
p.setFont(st::dlgHistFont);
p.setPen(active ? st::dlgActiveColor : st::dlgSystemColor);
p.setFont(st::dialogsTextFont);
p.setPen(active ? st::dialogsTextFgActive : st::dialogsTextFgService);
if (history->typing.isEmpty() && history->sendActions.isEmpty()) {
if (history->cloudDraftTextCache.isEmpty()) {
TextCustomTagsMap custom;
custom.insert(QChar('c'), qMakePair(textcmdStartLink(1), textcmdStopLink()));
QString msg = lng_message_with_from(lt_from, textRichPrepare(lang(lng_from_draft)), lt_message, textRichPrepare(draft->textWithTags.text));
history->cloudDraftTextCache.setRichText(st::dlgHistFont, msg, _textDlgOptions, custom);
history->cloudDraftTextCache.setRichText(st::dialogsTextFont, msg, _textDlgOptions, custom);
}
textstyleSet(&(active ? st::dlgActiveTextStyle : st::dlgTextStyle));
p.setFont(st::dlgHistFont);
p.setPen(active ? st::dlgActiveColor : st::dlgTextColor);
history->cloudDraftTextCache.drawElided(p, nameleft, texttop, namewidth, st::dlgFont->height / st::dlgHistFont->height);
textstyleSet(&(active ? st::dialogsTextStyleActive : st::dialogsTextStyleDraft));
p.setFont(st::dialogsTextFont);
p.setPen(active ? st::dialogsTextFgActive : st::dialogsTextFg);
history->cloudDraftTextCache.drawElided(p, nameleft, texttop, namewidth, 1);
textstyleRestore();
} else {
history->typingText.drawElided(p, nameleft, texttop, namewidth);
}
} else if (!item) {
p.setFont(st::dlgHistFont);
p.setPen(active ? st::dlgActiveColor : st::dlgSystemColor);
p.setFont(st::dialogsTextFont);
p.setPen(active ? st::dialogsTextFgActive : st::dialogsTextFgService);
if (history->typing.isEmpty() && history->sendActions.isEmpty()) {
p.drawText(nameleft, texttop + st::dlgFont->ascent, lang(lng_empty_history));
p.drawText(nameleft, texttop + st::msgNameFont->ascent, lang(lng_empty_history));
} else {
history->typingText.drawElided(p, nameleft, texttop, namewidth);
}
@@ -134,8 +122,8 @@ void paintRow(Painter &p, History *history, HistoryItem *item, HistoryDraft *dra
} else {
check = active ? &st::dlgActiveSendImg : &st::dlgSendImg;
}
rectForName.setWidth(rectForName.width() - check->pxWidth() - st::dlgCheckSkip);
p.drawSprite(QPoint(rectForName.left() + rectForName.width() + st::dlgCheckLeft, rectForName.top() + st::dlgCheckTop), *check);
rectForName.setWidth(rectForName.width() - check->pxWidth() - st::dialogsCheckSkip);
p.drawSprite(QPoint(rectForName.left() + rectForName.width() + st::dialogsCheckLeft, rectForName.top() + st::dialogsCheckTop), *check);
}
paintItemCallback(nameleft, namewidth, item);
@@ -146,7 +134,7 @@ void paintRow(Painter &p, History *history, HistoryItem *item, HistoryDraft *dra
p.drawSprite(rectForName.topLeft() + QPoint(qMin(history->peer->dialogName().maxWidth(), rectForName.width()), 0) + st::verifiedCheckPos, (active ? st::verifiedCheckInv : st::verifiedCheck));
}
p.setPen(active ? st::dlgActiveColor : st::dlgNameColor);
p.setPen(active ? st::dialogsTextFgActive : st::dialogsNameFg);
history->peer->dialogName().drawElided(p, rectForName.left(), rectForName.top(), rectForName.width());
}
@@ -154,7 +142,7 @@ class UnreadBadgeStyle : public StyleSheet {
public:
QImage circle;
QPixmap left[4], right[4];
style::color bg[4] = { st::dlgUnreadBG, st::dlgActiveUnreadBG, st::dlgUnreadMutedBG, st::dlgActiveUnreadMutedBG };
style::color bg[4] = { st::dialogsUnreadBg, st::dialogsUnreadBgActive, st::dialogsUnreadBgMuted, st::dialogsUnreadBgMutedActive };
};
StyleSheetPointer<UnreadBadgeStyle> unreadBadgeStyle;
@@ -203,9 +191,9 @@ void paintUnreadBadge(Painter &p, const QRect &rect, bool active, bool muted) {
}
void paintUnreadCount(Painter &p, const QString &text, int x, int y, style::align align, bool active, bool muted, int *outUnreadWidth) {
int unreadWidth = st::dlgUnreadFont->width(text);
int unreadRectWidth = unreadWidth + 2 * st::dlgUnreadPaddingHor;
int unreadRectHeight = st::dlgUnreadHeight;
int unreadWidth = st::dialogsUnreadFont->width(text);
int unreadRectWidth = unreadWidth + 2 * st::dialogsUnreadPadding;
int unreadRectHeight = st::dialogsUnreadHeight;
accumulate_max(unreadRectWidth, unreadRectHeight);
int unreadRectLeft = x;
@@ -221,9 +209,9 @@ void paintUnreadCount(Painter &p, const QString &text, int x, int y, style::alig
paintUnreadBadge(p, QRect(unreadRectLeft, unreadRectTop, unreadRectWidth, unreadRectHeight), active, muted);
p.setFont(st::dlgUnreadFont);
p.setPen(active ? st::dlgActiveUnreadColor : st::dlgUnreadColor);
p.drawText(unreadRectLeft + (unreadRectWidth - unreadWidth) / 2, unreadRectTop + st::dlgUnreadTop + st::dlgUnreadFont->ascent, text);
p.setFont(st::dialogsUnreadFont);
p.setPen(active ? st::dialogsUnreadFgActive : st::dialogsUnreadFg);
p.drawText(unreadRectLeft + (unreadRectWidth - unreadWidth) / 2, unreadRectTop + st::dialogsUnreadTop + st::dialogsUnreadFont->ascent, text);
}
void RowPainter::paint(Painter &p, const Row *row, int w, bool active, bool selected, bool onlyBackground) {
@@ -241,30 +229,20 @@ void RowPainter::paint(Painter &p, const Row *row, int w, bool active, bool sele
}
}
int availableWidth = namewidth;
int texttop = st::dlgPaddingVer + st::dlgFont->height + st::dlgSep;
auto cloudDraft = history->cloudDraft();
bool hasDraftIcon = active ? false : (cloudDraft && cloudDraft->date.isValid());
if (unread || hasDraftIcon) {
QString counter;
bool mutedCounter = false;
bool showUnreadCounter = unread && (!hasDraftIcon || !history->mute());
if (showUnreadCounter) {
counter = QString::number(unread);
mutedCounter = history->mute();
}
int unreadRight = w - st::dlgPaddingHor;
int unreadTop = texttop + st::dlgHistFont->ascent - st::dlgUnreadFont->ascent - st::dlgUnreadTop;
int texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
if (unread) {
auto counter = QString::number(unread);
auto mutedCounter = history->mute();
int unreadRight = w - st::dialogsPadding.x();
int unreadTop = texttop + st::dialogsTextFont->ascent - st::dialogsUnreadFont->ascent - st::dialogsUnreadTop;
int unreadWidth = 0;
paintUnreadCount(p, counter, unreadRight, unreadTop, style::al_right, active, mutedCounter, &unreadWidth);
if (!showUnreadCounter) {
st::dialogsDraft.paint(p, QPoint(w - st::dlgPaddingHor - st::dlgUnreadHeight, unreadTop), w);
}
availableWidth -= unreadWidth + st::dlgUnreadPaddingHor;
availableWidth -= unreadWidth + st::dialogsUnreadPadding;
}
if (history->typing.isEmpty() && history->sendActions.isEmpty()) {
item->drawInDialog(p, QRect(nameleft, texttop, availableWidth, st::dlgFont->height), active, history->textCachedFor, history->lastItemTextCache);
item->drawInDialog(p, QRect(nameleft, texttop, availableWidth, st::dialogsTextFont->height), active, history->textCachedFor, history->lastItemTextCache);
} else {
p.setPen(active ? st::dlgActiveColor : st::dlgSystemColor);
p.setPen(active ? st::dialogsTextFgActive : st::dialogsTextFgService);
history->typingText.drawElided(p, nameleft, texttop, availableWidth);
}
});
@@ -274,13 +252,13 @@ void RowPainter::paint(Painter &p, const FakeRow *row, int w, bool active, bool
auto item = row->item();
auto history = item->history();
paintRow(p, history, item, nullptr, w, active, selected, onlyBackground, [&p, row, active](int nameleft, int namewidth, HistoryItem *item) {
int lastWidth = namewidth, texttop = st::dlgPaddingVer + st::dlgFont->height + st::dlgSep;
item->drawInDialog(p, QRect(nameleft, texttop, lastWidth, st::dlgFont->height), active, row->_cacheFor, row->_cache);
int lastWidth = namewidth, texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip;
item->drawInDialog(p, QRect(nameleft, texttop, lastWidth, st::dialogsTextFont->height), active, row->_cacheFor, row->_cache);
});
}
void paintImportantSwitch(Painter &p, Mode current, int w, bool selected, bool onlyBackground) {
p.fillRect(0, 0, w, st::dlgImportantHeight, selected ? st::dlgHoverBG : st::white);
p.fillRect(0, 0, w, st::dialogsImportantBarHeight, selected ? st::dialogsBgOver : st::white);
if (onlyBackground) {
return;
}
@@ -288,15 +266,15 @@ void paintImportantSwitch(Painter &p, Mode current, int w, bool selected, bool o
p.setFont(st::semiboldFont);
p.setPen(st::black);
int unreadTop = (st::dlgImportantHeight - st::dlgUnreadHeight) / 2;
int unreadTop = (st::dialogsImportantBarHeight - st::dialogsUnreadHeight) / 2;
bool mutedHidden = (current == Dialogs::Mode::Important);
QString text = mutedHidden ? qsl("Show all chats") : qsl("Hide muted chats");
int textBaseline = unreadTop + st::dlgUnreadTop + st::dlgUnreadFont->ascent;
p.drawText(st::dlgPaddingHor, textBaseline, text);
int textBaseline = unreadTop + st::dialogsUnreadTop + st::dialogsUnreadFont->ascent;
p.drawText(st::dialogsPadding.x(), textBaseline, text);
if (mutedHidden) {
if (int32 unread = App::histories().unreadMutedCount()) {
int unreadRight = w - st::dlgPaddingHor;
int unreadRight = w - st::dialogsPadding.x();
paintUnreadCount(p, QString::number(unread), unreadRight, unreadTop, style::al_right, false, true, nullptr);
}
}

View File

@@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "dialogs/dialogs_list.h"
#include "dialogs/dialogs_layout.h"
#include "styles/style_dialogs.h"
#include "mainwidget.h"
namespace Dialogs {
@@ -47,16 +48,16 @@ void List::adjustCurrent(int32 y, int32 h) const {
}
void List::paint(Painter &p, int32 w, int32 hFrom, int32 hTo, PeerData *act, PeerData *sel, bool onlyBackground) const {
adjustCurrent(hFrom, st::dlgHeight);
adjustCurrent(hFrom, st::dialogsRowHeight);
Row *row = _current;
p.translate(0, row->_pos * st::dlgHeight);
while (row != _end && row->_pos * st::dlgHeight < hTo) {
p.translate(0, row->_pos * st::dialogsRowHeight);
while (row != _end && row->_pos * st::dialogsRowHeight < hTo) {
bool active = (row->history()->peer == act) || (row->history()->peer->migrateTo() && row->history()->peer->migrateTo() == act);
bool selected = (row->history()->peer == sel);
Layout::RowPainter::paint(p, row, w, active, selected, onlyBackground);
row = row->_next;
p.translate(0, st::dlgHeight);
p.translate(0, st::dialogsRowHeight);
}
}

View File

@@ -0,0 +1,31 @@
/*
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 "dialogs/dialogs_row.h"
#include "styles/style_dialogs.h"
namespace Dialogs {
FakeRow::FakeRow(HistoryItem *item) : _item(item), _cache(st::dialogsTextWidthMin) {
}
} // namespace Dialogs

View File

@@ -59,8 +59,7 @@ private:
class FakeRow {
public:
FakeRow(HistoryItem *item) : _item(item) {
}
FakeRow(HistoryItem *item);
HistoryItem *item() const {
return _item;
@@ -71,7 +70,7 @@ private:
HistoryItem *_item;
mutable const HistoryItem *_cacheFor = nullptr;
mutable Text _cache = Text{ int(st::dlgRichMinWidth) };
mutable Text _cache;
};