2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Add special filters icons.

This commit is contained in:
John Preston
2020-03-19 15:06:08 +04:00
parent 03da4a5680
commit 9ad5b8ff90
154 changed files with 180 additions and 74 deletions

View File

@@ -0,0 +1,50 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/filter_icons.h"
#include "styles/style_filter_icons.h"
namespace Ui {
namespace {
const auto kIcons = std::vector<FilterIcons>{
{ &st::filtersAll, &st::filtersAllActive },
{ &st::filtersUnread, &st::filtersAllActive },
{ &st::filtersUnmuted, &st::filtersAllActive },
{ &st::filtersBots, &st::filtersAllActive },
{ &st::filtersChannels, &st::filtersChannelsActive },
{ &st::filtersGroups, &st::filtersGroupsActive },
{ &st::filtersPrivate, &st::filtersPrivateActive },
{ &st::filtersCustom, &st::filtersCustomActive },
{ &st::filtersSetup, &st::filtersSetup },
{ &st::foldersCat, &st::foldersCatActive },
{ &st::foldersCrown, &st::foldersCrownActive },
{ &st::foldersFavorite, &st::foldersFavoriteActive },
{ &st::foldersFlower, &st::foldersFlowerActive },
{ &st::foldersGame, &st::foldersGameActive },
{ &st::foldersHome, &st::foldersHomeActive },
{ &st::foldersLove, &st::foldersLoveActive },
{ &st::foldersMask, &st::foldersMaskActive },
{ &st::foldersParty, &st::foldersPartyActive },
{ &st::foldersSport, &st::foldersSportActive },
{ &st::foldersStudy, &st::foldersStudyActive },
{ &st::foldersTrade, &st::foldersTrade },
{ &st::foldersTravel, &st::foldersTravelActive },
{ &st::foldersWork, &st::foldersWorkActive },
};
} // namespace
const FilterIcons &LookupFilterIcon(FilterIcon icon) {
Expects(static_cast<int>(icon) >= 0
&& static_cast<int>(icon) < kIcons.size());
return kIcons[static_cast<int>(icon)];
}
} // namespace Ui

View File

@@ -0,0 +1,52 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace style {
namespace internal {
class Icon;
} // namespace internal
} // namespace style
namespace Ui {
enum class FilterIcon : uchar {
All,
Unread,
Unmuted,
Bots,
Channels,
Groups,
Private,
Custom,
Setup,
Cat,
Crown,
Favorite,
Flower,
Game,
Home,
Love,
Mask,
Party,
Sport,
Study,
Trade,
Travel,
Work,
};
struct FilterIcons {
not_null<const style::internal::Icon*> normal;
not_null<const style::internal::Icon*> active;
};
[[nodiscard]] const FilterIcons &LookupFilterIcon(FilterIcon icon);
} // namespace Ui

View File

@@ -0,0 +1,54 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
using "ui/colors.palette";
filtersAll: icon {{ "filters/filters_all", sideBarIconFg }};
filtersAllActive: icon {{ "filters/filters_all_active", sideBarIconFgActive }};
filtersUnread: icon {{ "filters/filters_unread", sideBarIconFg }};
filtersUnreadActive: icon {{ "filters/filters_unread_active", sideBarIconFgActive }};
filtersUnmuted: icon {{ "filters/filters_unmuted", sideBarIconFg }};
filtersUnmutedActive: icon {{ "filters/filters_unmuted_active", sideBarIconFgActive }};
filtersBots: icon {{ "filters/filters_bots", sideBarIconFg }};
filtersBotsActive: icon {{ "filters/filters_bots_active", sideBarIconFgActive }};
filtersChannels: icon {{ "filters/filters_channels", sideBarIconFg }};
filtersChannelsActive: icon {{ "filters/filters_channels_active", sideBarIconFgActive }};
filtersGroups: icon {{ "filters/filters_groups", sideBarIconFg }};
filtersGroupsActive: icon {{ "filters/filters_groups_active", sideBarIconFgActive }};
filtersPrivate: icon {{ "filters/filters_private", sideBarIconFg }};
filtersPrivateActive: icon {{ "filters/filters_private_active", sideBarIconFgActive }};
filtersCustom: icon {{ "filters/filters_custom", sideBarIconFg }};
filtersCustomActive: icon {{ "filters/filters_custom_active", sideBarIconFgActive }};
filtersSetup: icon {{ "filters/filters_setup", sideBarIconFg }};
foldersCat: icon {{ "filters/folders_cat", sideBarIconFg }};
foldersCatActive: icon {{ "filters/folders_cat_active", sideBarIconFg }};
foldersCrown: icon {{ "filters/folders_crown", sideBarIconFg }};
foldersCrownActive: icon {{ "filters/folders_crown_active", sideBarIconFgActive }};
foldersFavorite: icon {{ "filters/folders_favorite", sideBarIconFg }};
foldersFavoriteActive: icon {{ "filters/folders_favorite_active", sideBarIconFgActive }};
foldersFlower: icon {{ "filters/folders_flower", sideBarIconFg }};
foldersFlowerActive: icon {{ "filters/folders_flower_active", sideBarIconFgActive }};
foldersGame: icon {{ "filters/folders_game", sideBarIconFg }};
foldersGameActive: icon {{ "filters/folders_game_active", sideBarIconFgActive }};
foldersHome: icon {{ "filters/folders_home", sideBarIconFg }};
foldersHomeActive: icon {{ "filters/folders_home_active", sideBarIconFgActive }};
foldersLove: icon {{ "filters/folders_love", sideBarIconFg }};
foldersLoveActive: icon {{ "filters/folders_love_active", sideBarIconFgActive }};
foldersMask: icon {{ "filters/folders_mask", sideBarIconFg }};
foldersMaskActive: icon {{ "filters/folders_mask_active", sideBarIconFgActive }};
foldersParty: icon {{ "filters/folders_party", sideBarIconFg }};
foldersPartyActive: icon {{ "filters/folders_party_active", sideBarIconFgActive }};
foldersSport: icon {{ "filters/folders_sport", sideBarIconFg }};
foldersSportActive: icon {{ "filters/folders_sport_active", sideBarIconFgActive }};
foldersStudy: icon {{ "filters/folders_study", sideBarIconFg }};
foldersStudyActive: icon {{ "filters/folders_study_active", sideBarIconFgActive }};
foldersTrade: icon {{ "filters/folders_trade", sideBarIconFg }};
foldersTravel: icon {{ "filters/folders_travel", sideBarIconFg }};
foldersTravelActive: icon {{ "filters/folders_travel_active", sideBarIconFgActive }};
foldersWork: icon {{ "filters/folders_work", sideBarIconFg }};
foldersWorkActive: icon {{ "filters/folders_work_active", sideBarIconFgActive }};

View File

@@ -268,41 +268,6 @@ windowFiltersMainMenu: SideBarButton(windowFiltersButton) {
iconPosition: point(-1px, -1px);
minHeight: 54px;
}
windowFiltersAll: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_all", sideBarIconFg }};
iconActive: icon {{ "filters_all_active", sideBarIconFgActive }};
}
windowFiltersUnread: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_unread", sideBarIconFg }};
iconActive: icon {{ "filters_unread_active", sideBarIconFgActive }};
}
windowFiltersUnmuted: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_unmuted", sideBarIconFg }};
iconActive: icon {{ "filters_unmuted_active", sideBarIconFgActive }};
}
windowFiltersBots: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_bots", sideBarIconFg }};
iconActive: icon {{ "filters_bots_active", sideBarIconFgActive }};
}
windowFiltersChannels: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_channels", sideBarIconFg }};
iconActive: icon {{ "filters_channels_active", sideBarIconFgActive }};
}
windowFiltersGroups: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_groups", sideBarIconFg }};
iconActive: icon {{ "filters_groups_active", sideBarIconFgActive }};
}
windowFiltersPrivate: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_private", sideBarIconFg }};
iconActive: icon {{ "filters_private_active", sideBarIconFgActive }};
}
windowFiltersCustom: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_custom", sideBarIconFg }};
iconActive: icon {{ "filters_custom_active", sideBarIconFgActive }};
}
windowFiltersSetup: SideBarButton(windowFiltersButton) {
icon: icon {{ "filters_setup", sideBarIconFg }};
}
windowFilterSmallItem: PeerListItem(defaultPeerListItem) {
height: 44px;
photoPosition: point(15px, 5px);

View File

@@ -15,23 +15,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_chat_filters.h"
#include "boxes/filters/manage_filters_box.h"
#include "lang/lang_keys.h"
#include "ui/filter_icons.h"
#include "styles/style_widgets.h"
#include "styles/style_window.h"
namespace Window {
namespace {
enum class Type {
Unread,
Unmuted,
People,
Groups,
Channels,
Bots,
Custom,
};
using Icon = Ui::FilterIcon;
[[nodiscard]] Type ComputeType(const Data::ChatFilter &filter) {
[[nodiscard]] Icon ComputeIcon(const Data::ChatFilter &filter) {
using Flag = Data::ChatFilter::Flag;
const auto all = Flag::Contacts
@@ -45,36 +38,23 @@ enum class Type {
if (!filter.always().empty()
|| !filter.never().empty()
|| !(filter.flags() & all)) {
return Type::Custom;
return Icon::Custom;
} else if ((filter.flags() & all) == Flag::Contacts
|| (filter.flags() & all) == Flag::NonContacts
|| (filter.flags() & all) == people) {
return Type::People;
return Icon::Private;
} else if ((filter.flags() & all) == Flag::Groups) {
return Type::Groups;
return Icon::Groups;
} else if ((filter.flags() & all) == Flag::Channels) {
return Type::Channels;
return Icon::Channels;
} else if ((filter.flags() & all) == Flag::Bots) {
return Type::Bots;
return Icon::Bots;
} else if ((filter.flags() & removed) == Flag::NoRead) {
return Type::Unread;
return Icon::Unread;
} else if ((filter.flags() & removed) == Flag::NoMuted) {
return Type::Unmuted;
return Icon::Unmuted;
}
return Type::Custom;
}
[[nodiscard]] const style::SideBarButton &ComputeStyle(Type type) {
switch (type) {
case Type::Unread: return st::windowFiltersUnread;
case Type::Unmuted: return st::windowFiltersUnmuted;
case Type::People: return st::windowFiltersPrivate;
case Type::Groups: return st::windowFiltersGroups;
case Type::Channels: return st::windowFiltersChannels;
case Type::Bots: return st::windowFiltersBots;
case Type::Custom: return st::windowFiltersCustom;
}
Unexpected("Filter type in FiltersMenu::refresh.");
return Icon::Custom;
}
} // namespace
@@ -108,7 +88,7 @@ void FiltersMenu::setup() {
if (!fill.isEmpty()) {
auto p = QPainter(&_outer);
p.setPen(Qt::NoPen);
p.setBrush(st::windowFiltersAll.textBg);
p.setBrush(st::windowFiltersButton.textBg);
p.drawRect(fill);
}
}, _outer.lifetime());
@@ -166,13 +146,15 @@ void FiltersMenu::refresh() {
const auto prepare = [&](
FilterId id,
const QString &title,
const style::SideBarButton &st,
Icon icon,
const QString &badge) {
auto button = base::unique_qptr<Ui::SideBarButton>(_container->add(
object_ptr<Ui::SideBarButton>(
_container,
title,
st)));
st::windowFiltersButton)));
const auto &icons = Ui::LookupFilterIcon(icon);
button->setIconOverride(icons.normal, icons.active);
if (id > 0) {
const auto list = filters->chatsList(id);
rpl::single(rpl::empty_value()) | rpl::then(
@@ -200,15 +182,15 @@ void FiltersMenu::refresh() {
});
now.emplace(id, std::move(button));
};
prepare(0, tr::lng_filters_all(tr::now), st::windowFiltersAll, {});
prepare(0, tr::lng_filters_all(tr::now), Icon::All, {});
for (const auto filter : filters->list()) {
prepare(
filter.id(),
filter.title(),
ComputeStyle(ComputeType(filter)),
ComputeIcon(filter),
QString());
}
prepare(-1, tr::lng_filters_setup(tr::now), st::windowFiltersSetup, {});
prepare(-1, tr::lng_filters_setup(tr::now), Icon::Setup, {});
_filters = std::move(now);
}