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

Most of the new Settings are done.

Left: auto update, privacy and security, local storage box +
some minor things, like design fixes, codes like loadlang and
clearing of the local storage (box) and temp download folder.
This commit is contained in:
John Preston
2016-08-26 22:49:18 -06:00
parent 993b91ac15
commit fdab386178
66 changed files with 1259 additions and 656 deletions

View File

@@ -20,6 +20,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
using "basic.style";
using "basic_types.style";
using "dialogs/dialogs.style";
settingsMaxWidth: 520px;
settingsMaxPadding: 48px;
@@ -82,6 +83,22 @@ settingsSecondaryButton: RoundButton(settingsPrimaryButton) {
textBg: #ffffff;
textBgOver: #f2f7fa;
}
settingsEditButton: RoundButton {
width: 24px;
height: 34px;
icon: settingsEditIcon;
textTop: 0px;
downTextTop: 1px;
textFg: transparent;
textFgOver: transparent;
secondaryTextFg: transparent;
secondaryTextFgOver: transparent;
textBg: transparent;
textBgOver: transparent;
}
settingsBlocksTop: 7px;
settingsBlocksBottom: 20px;
@@ -117,3 +134,5 @@ settingsSliderLabelTop: 17px;
settingsSliderLabelFont: normalFont;
settingsSliderLabelFg: #1485c2;
settingsSliderDuration: 200;
settingsBackgroundSize: 120px;

View File

@@ -32,6 +32,11 @@ namespace Settings {
AdvancedWidget::AdvancedWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_advanced_settings)) {
createControls();
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
subscribe(Global::RefConnectionTypeChanged(), [this]() {
connectionTypeUpdated();
});
#endif // TDESKTOP_DISABLE_NETWORK_PROXY
}
void AdvancedWidget::createControls() {
@@ -43,6 +48,7 @@ void AdvancedWidget::createControls() {
}
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
addChildRow(_connectionType, marginLarge, lang(lng_connection_type), lang(lng_connection_auto_connecting));
connectionTypeUpdated();
connect(_connectionType->link(), SIGNAL(clicked()), this, SLOT(onConnectionType()));
#endif // TDESKTOP_DISABLE_NETWORK_PROXY
if (self()) {
@@ -59,6 +65,23 @@ void AdvancedWidget::onManageLocalStorage() {
}
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
void AdvancedWidget::connectionTypeUpdated() {
QString connection;
switch (Global::ConnectionType()) {
case dbictAuto: {
QString transport = MTP::dctransport();
connection = transport.isEmpty() ? lang(lng_connection_auto_connecting) : lng_connection_auto(lt_transport, transport);
} break;
case dbictHttpProxy:
case dbictTcpProxy: {
QString transport = MTP::dctransport();
connection = transport.isEmpty() ? lang(lng_connection_proxy_connecting) : lng_connection_proxy(lt_transport, transport);
} break;
}
_connectionType->link()->setText(connection);
resizeToWidth(width());
}
void AdvancedWidget::onConnectionType() {
Ui::showLayer(new ConnectionBox());
}

View File

@@ -43,6 +43,9 @@ private slots:
private:
void createControls();
#ifndef TDESKTOP_DISABLE_NETWORK_PROXY
void connectionTypeUpdated();
#endif // TDESKTOP_DISABLE_NETWORK_PROXY
void supportGot(const MTPhelp_Support &support);
ChildWidget<LinkButton> _manageLocalStorage = { nullptr };

View File

@@ -23,21 +23,237 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "styles/style_settings.h"
#include "lang.h"
#include "mainwidget.h"
#include "boxes/backgroundbox.h"
#include "ui/widgets/widget_slide_wrap.h"
#include "localstorage.h"
#include "mainwindow.h"
#include "window/chat_background.h"
namespace Settings {
BackgroundRow::BackgroundRow(QWidget *parent) : TWidget(parent)
, _chooseFromGallery(this, lang(lng_settings_bg_from_gallery))
, _chooseFromFile(this, lang(lng_settings_bg_from_file))
, _radial(animation(this, &BackgroundRow::step_radial)) {
Window::chatBackground()->initIfEmpty();
updateImage();
connect(_chooseFromGallery, SIGNAL(clicked()), this, SIGNAL(chooseFromGallery()));
connect(_chooseFromFile, SIGNAL(clicked()), this, SIGNAL(chooseFromFile()));
}
void BackgroundRow::paintEvent(QPaintEvent *e) {
Painter p(this);
bool radial = false;
float64 radialOpacity = 0;
if (_radial.animating()) {
_radial.step(getms());
radial = _radial.animating();
radialOpacity = _radial.opacity();
}
if (radial) {
auto backThumb = App::main() ? App::main()->newBackgroundThumb() : ImagePtr();
if (backThumb->isNull()) {
p.drawPixmap(0, 0, _background);
} else {
const QPixmap &pix = App::main()->newBackgroundThumb()->pixBlurred(st::setBackgroundSize);
p.drawPixmap(0, 0, st::setBackgroundSize, st::setBackgroundSize, pix, 0, (pix.height() - st::setBackgroundSize) / 2, st::setBackgroundSize, st::setBackgroundSize);
}
auto outer = radialRect();
QRect inner(QPoint(outer.x() + (outer.width() - st::radialSize.width()) / 2, outer.y() + (outer.height() - st::radialSize.height()) / 2), st::radialSize);
p.setPen(Qt::NoPen);
p.setBrush(st::black);
p.setOpacity(radialOpacity * st::radialBgOpacity);
p.setRenderHint(QPainter::HighQualityAntialiasing);
p.drawEllipse(inner);
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
p.setOpacity(1);
QRect arc(inner.marginsRemoved(QMargins(st::radialLine, st::radialLine, st::radialLine, st::radialLine)));
_radial.draw(p, arc, st::radialLine, st::white);
} else {
p.drawPixmap(0, 0, _background);
}
}
int BackgroundRow::resizeGetHeight(int newWidth) {
int linkLeft = st::settingsBackgroundSize + st::settingsSmallSkip;
int linkWidth = newWidth - linkLeft;
_chooseFromGallery->resizeToWidth(qMin(linkWidth, _chooseFromGallery->naturalWidth()));
_chooseFromFile->resizeToWidth(qMin(linkWidth, _chooseFromFile->naturalWidth()));
_chooseFromGallery->moveToLeft(linkLeft, 0);
_chooseFromFile->moveToLeft(linkLeft, _chooseFromGallery->height() + st::settingsSmallSkip);
return st::settingsBackgroundSize;
}
float64 BackgroundRow::radialProgress() const {
if (auto m = App::main()) {
return m->chatBackgroundProgress();
}
return 1.;
}
bool BackgroundRow::radialLoading() const {
if (auto m = App::main()) {
if (m->chatBackgroundLoading()) {
m->checkChatBackground();
if (m->chatBackgroundLoading()) {
return true;
} else {
const_cast<BackgroundRow*>(this)->updateImage();
}
}
}
return false;
}
QRect BackgroundRow::radialRect() const {
return QRect(0, 0, st::setBackgroundSize, st::setBackgroundSize);
}
void BackgroundRow::radialStart() {
if (radialLoading() && !_radial.animating()) {
_radial.start(radialProgress());
if (auto shift = radialTimeShift()) {
_radial.update(radialProgress(), !radialLoading(), getms() + shift);
}
}
}
uint64 BackgroundRow::radialTimeShift() const {
return st::radialDuration;
}
void BackgroundRow::step_radial(uint64 ms, bool timer) {
_radial.update(radialProgress(), !radialLoading(), ms + radialTimeShift());
if (timer && _radial.animating()) {
rtlupdate(radialRect());
}
}
void BackgroundRow::updateImage() {
int32 size = st::setBackgroundSize * cIntRetinaFactor();
QImage back(size, size, QImage::Format_ARGB32_Premultiplied);
back.setDevicePixelRatio(cRetinaFactor());
{
QPainter p(&back);
auto &pix = Window::chatBackground()->image();
int sx = (pix.width() > pix.height()) ? ((pix.width() - pix.height()) / 2) : 0;
int sy = (pix.height() > pix.width()) ? ((pix.height() - pix.width()) / 2) : 0;
int s = (pix.width() > pix.height()) ? pix.height() : pix.width();
p.setRenderHint(QPainter::SmoothPixmapTransform);
p.drawPixmap(0, 0, st::setBackgroundSize, st::setBackgroundSize, pix, sx, sy, s, s);
}
imageRound(back, ImageRoundRadius::Small);
_background = App::pixmapFromImageInPlace(std_::move(back));
_background.setDevicePixelRatio(cRetinaFactor());
rtlupdate(radialRect());
if (radialLoading()) {
radialStart();
}
}
BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_background)) {
refreshControls();
FileDialog::registerObserver(this, &BackgroundWidget::notifyFileQueryUpdated);
createControls();
subscribe(Window::chatBackground(), [this](const Window::ChatBackgroundUpdate &update) {
using Update = Window::ChatBackgroundUpdate;
if (update.type == Update::Type::New) {
_background->updateImage();
} else if (update.type == Update::Type::Start) {
needBackgroundUpdate(update.tiled);
}
});
subscribe(Adaptive::Changed(), [this]() {
if (Global::AdaptiveLayout() == Adaptive::WideLayout) {
_adaptive->slideDown();
} else {
_adaptive->slideUp();
}
});
}
void BackgroundWidget::refreshControls() {
void BackgroundWidget::createControls() {
style::margins margin(0, 0, 0, st::settingsSmallSkip);
style::margins slidedPadding(0, margin.bottom() / 2, 0, margin.bottom() - (margin.bottom() / 2));
addChildRow(_background, margin);
connect(_background, SIGNAL(chooseFromGallery()), this, SLOT(onChooseFromGallery()));
connect(_background, SIGNAL(chooseFromFile()), this, SLOT(onChooseFromFile()));
addChildRow(_tile, margin, lang(lng_settings_bg_tile), SLOT(onTile()), Window::chatBackground()->tile());
addChildRow(_adaptive, margin, slidedPadding, lang(lng_settings_adaptive_wide), SLOT(onAdaptive()), Global::AdaptiveForWide());
if (Global::AdaptiveLayout() != Adaptive::WideLayout) {
_adaptive->hideFast();
}
}
int BackgroundWidget::resizeGetHeight(int newWidth) {
int newHeight = contentTop();
void BackgroundWidget::onChooseFromGallery() {
Ui::showLayer(new BackgroundBox());
}
newHeight += st::settingsBlockMarginBottom;
return newHeight;
void BackgroundWidget::needBackgroundUpdate(bool tile) {
_tile->setChecked(tile);
_background->updateImage();
}
void BackgroundWidget::onChooseFromFile() {
QStringList imgExtensions(cImgExtensions());
QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter());
_chooseFromFileQueryId = FileDialog::queryReadFile(lang(lng_choose_images), filter);
}
void BackgroundWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
if (_chooseFromFileQueryId != update.queryId) {
return;
}
_chooseFromFileQueryId = 0;
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
return;
}
QImage img;
if (!update.remoteContent.isEmpty()) {
img = App::readImage(update.remoteContent);
} else {
img = App::readImage(update.filePaths.front());
}
if (img.isNull() || img.width() <= 0 || img.height() <= 0) return;
if (img.width() > 4096 * img.height()) {
img = img.copy((img.width() - 4096 * img.height()) / 2, 0, 4096 * img.height(), img.height());
} else if (img.height() > 4096 * img.width()) {
img = img.copy(0, (img.height() - 4096 * img.width()) / 2, img.width(), 4096 * img.width());
}
App::initBackground(-1, img);
_tile->setChecked(false);
_background->updateImage();
}
void BackgroundWidget::onTile() {
Window::chatBackground()->setTile(_tile->checked());
}
void BackgroundWidget::onAdaptive() {
if (Global::AdaptiveForWide() != _adaptive->entity()->checked()) {
Global::SetAdaptiveForWide(_adaptive->entity()->checked());
Adaptive::Changed().notify();
Local::writeUserSettings();
}
}
} // namespace Settings

View File

@@ -21,19 +21,72 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#pragma once
#include "settings/settings_block_widget.h"
#include "ui/filedialog.h"
class LinkButton;
class Checkbox;
namespace Ui {
template <typename Widget>
class WidgetSlideWrap;
} // namespace Ui;
namespace Settings {
class BackgroundRow : public TWidget {
Q_OBJECT
public:
BackgroundRow(QWidget *parent);
void updateImage();
protected:
void paintEvent(QPaintEvent *e) override;
int resizeGetHeight(int newWidth) override;
signals:
void chooseFromGallery();
void chooseFromFile();
private:
float64 radialProgress() const;
bool radialLoading() const;
QRect radialRect() const;
void radialStart();
uint64 radialTimeShift() const;
void step_radial(uint64 ms, bool timer);
QPixmap _background;
ChildWidget<LinkButton> _chooseFromGallery;
ChildWidget<LinkButton> _chooseFromFile;
RadialAnimation _radial;
};
class BackgroundWidget : public BlockWidget {
Q_OBJECT
public:
BackgroundWidget(QWidget *parent, UserData *self);
protected:
// Resizes content and counts natural widget height for the desired width.
int resizeGetHeight(int newWidth) override;
private slots:
void onChooseFromGallery();
void onChooseFromFile();
void onTile();
void onAdaptive();
private:
void refreshControls();
void createControls();
void needBackgroundUpdate(bool tile);
void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update);
ChildWidget<BackgroundRow> _background = { nullptr };
ChildWidget<Checkbox> _tile = { nullptr };
ChildWidget<Ui::WidgetSlideWrap<Checkbox>> _adaptive = { nullptr };
FileDialog::QueryId _chooseFromFileQueryId = 0;
};

View File

@@ -96,7 +96,7 @@ void BlockWidget::createChildRow(ChildWidget<Radiobutton> &child, style::margins
void BlockWidget::createChildRow(ChildWidget<LinkButton> &child, style::margins &margin, const QString &text, const char *slot) {
child = new LinkButton(this, text);
connect(child, SIGNAL(changed()), this, slot);
connect(child, SIGNAL(clicked()), this, slot);
}
} // namespace Settings

View File

@@ -32,7 +32,7 @@ class WidgetSlideWrap;
namespace Settings {
class BlockWidget : public ScrolledWidget, public Notify::Observer, public base::Subscriber {
class BlockWidget : public ScrolledWidget, public Notify::Observer, protected base::Subscriber {
Q_OBJECT
public:

View File

@@ -36,8 +36,23 @@ namespace Settings {
ChatSettingsWidget::ChatSettingsWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_chat_settings)) {
createControls();
subscribe(Global::RefDownloadPathChanged(), [this]() {
_downloadPath->entity()->link()->setText(downloadPathText());
resizeToWidth(width());
});
}
QString ChatSettingsWidget::downloadPathText() const {
if (Global::DownloadPath().isEmpty()) {
return lang(lng_download_path_default);
} else if (Global::DownloadPath() == qsl("tmp")) {
return lang(lng_download_path_temp);
}
return QDir::toNativeSeparators(Global::DownloadPath());
};
void ChatSettingsWidget::createControls() {
style::margins marginSmall(0, 0, 0, st::settingsSmallSkip);
style::margins marginSkip(0, 0, 0, st::settingsSkip);
@@ -48,18 +63,13 @@ void ChatSettingsWidget::createControls() {
style::margins marginList(st::defaultCheckbox.textPosition.x(), 0, 0, st::settingsSkip);
addChildRow(_viewList, marginList, slidedPadding, lang(lng_settings_view_emojis), SLOT(onViewList()));
addChildRow(_dontAskDownloadPath, marginSub, lang(lng_download_path_dont_ask), SLOT(onDontAskDownloadPath()), !cAskDownloadPath());
auto downloadPathText = []() -> QString {
if (cDownloadPath().isEmpty()) {
return lang(lng_download_path_default);
} else if (cDownloadPath() == qsl("tmp")) {
return lang(lng_download_path_temp);
}
return QDir::toNativeSeparators(cDownloadPath());
};
addChildRow(_dontAskDownloadPath, marginSub, lang(lng_download_path_dont_ask), SLOT(onDontAskDownloadPath()), !Global::AskDownloadPath());
style::margins marginPath(st::defaultCheckbox.textPosition.x(), 0, 0, st::settingsSkip);
addChildRow(_downloadPath, marginPath, slidedPadding, lang(lng_download_path_label), downloadPathText());
connect(_downloadPath->entity()->link(), SIGNAL(clicked()), this, SLOT(onDownloadPath()));
if (Global::AskDownloadPath()) {
_downloadPath->hideFast();
}
addChildRow(_sendByEnter, marginSmall, qsl("send_key"), 0, lang(lng_settings_send_enter), SLOT(onSendByEnter()), !cCtrlEnter());
addChildRow(_sendByCtrlEnter, marginSkip, qsl("send_key"), 1, lang((cPlatform() == dbipMac || cPlatform() == dbipMacOld) ? lng_settings_send_cmdenter : lng_settings_send_ctrlenter), SLOT(onSendByCtrlEnter()), cCtrlEnter());
@@ -104,7 +114,7 @@ void ChatSettingsWidget::onViewList() {
}
void ChatSettingsWidget::onDontAskDownloadPath() {
cSetAskDownloadPath(!_dontAskDownloadPath->checked());
Global::SetAskDownloadPath(!_dontAskDownloadPath->checked());
Local::writeUserSettings();
if (_dontAskDownloadPath->checked()) {
_downloadPath->slideDown();

View File

@@ -65,6 +65,7 @@ private slots:
private:
void createControls();
QString downloadPathText() const;
ChildWidget<Checkbox> _replaceEmoji = { nullptr };
ChildWidget<Ui::WidgetSlideWrap<LinkButton>> _viewList = { nullptr };

View File

@@ -42,6 +42,7 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent,
, _self(App::self())
, _userpicButton(this, _self)
, _name(this, st::settingsNameLabel)
, _editNameInline(this, QString(), st::settingsEditButton)
, _setPhoto(this, lang(lng_settings_upload), st::settingsPrimaryButton)
, _editName(this, lang(lng_settings_edit), st::settingsSecondaryButton) {
setAcceptDrops(true);
@@ -53,6 +54,7 @@ CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent,
connect(_setPhoto, SIGNAL(clicked()), this, SLOT(onSetPhoto()));
_editName->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
connect(_editName, SIGNAL(clicked()), this, SLOT(onEditName()));
connect(_editNameInline, SIGNAL(clicked()), this, SLOT(onEditName()));
auto observeEvents = Notify::PeerUpdate::Flag::NameChanged;
Notify::registerPeerObserver(observeEvents, this, &CoverWidget::notifyPeerUpdated);
@@ -97,8 +99,6 @@ int CoverWidget::resizeGetHeight(int newWidth) {
_userpicButton->moveToLeft(contentLeft() + st::settingsPhotoLeft, newHeight);
refreshNameGeometry(newWidth);
int infoLeft = _userpicButton->x() + _userpicButton->width();
_statusPosition = QPoint(infoLeft + st::settingsStatusLeft, _userpicButton->y() + st::settingsStatusTop);
if (_cancelPhotoUpload) {
@@ -109,12 +109,11 @@ int CoverWidget::resizeGetHeight(int newWidth) {
int buttonsRight = newWidth - st::settingsButtonSkip;
_setPhoto->moveToLeft(buttonLeft, _userpicButton->y() + st::settingsButtonTop);
buttonLeft += _setPhoto->width() + st::settingsButtonSkip;
_editName->moveToLeft(buttonLeft, _setPhoto->y()); // TODO
if (buttonLeft + _editName->width() + st::settingsButtonSkip > newWidth) {
_editName->hide();
} else {
_editName->show();
}
_editName->moveToLeft(buttonLeft, _setPhoto->y());
_editNameVisible = (buttonLeft + _editName->width() + st::settingsButtonSkip <= newWidth);
_editName->setVisible(_editNameVisible);
refreshNameGeometry(newWidth);
newHeight += st::settingsPhotoSize;
newHeight += st::settingsMarginBottom;
@@ -133,9 +132,17 @@ void CoverWidget::refreshNameGeometry(int newWidth) {
int nameLeft = infoLeft + st::settingsNameLeft - st::settingsNameLabel.margin.left();
int nameTop = _userpicButton->y() + st::settingsNameTop - st::settingsNameLabel.margin.top();
int nameWidth = newWidth - infoLeft - st::settingsNameLeft;
auto editNameInlineVisible = !_editNameVisible;
if (editNameInlineVisible) {
nameWidth -= _editNameInline->width();
}
int marginsAdd = st::settingsNameLabel.margin.left() + st::settingsNameLabel.margin.right();
_name->resizeToWidth(qMin(nameWidth - marginsAdd, _name->naturalWidth()) + marginsAdd);
_name->moveToLeft(nameLeft, nameTop);
_editNameInline->moveToLeft(nameLeft + _name->width(), nameTop);
_editNameInline->setVisible(editNameInlineVisible);
}
void CoverWidget::showFinished() {

View File

@@ -93,6 +93,7 @@ private:
ChildWidget<Profile::CoverDropArea> _dropArea = { nullptr };
ChildWidget<FlatLabel> _name;
ChildWidget<Ui::RoundButton> _editNameInline;
ChildWidget<LinkButton> _cancelPhotoUpload = { nullptr };
QPoint _statusPosition;
@@ -101,6 +102,7 @@ private:
ChildWidget<Ui::RoundButton> _setPhoto;
ChildWidget<Ui::RoundButton> _editName;
bool _editNameVisible = true;
int _dividerTop = 0;

View File

@@ -52,6 +52,7 @@ QString currentVersion() {
GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_general))
, _changeLanguage(this, lang(lng_settings_change_lang)) {
connect(_changeLanguage, SIGNAL(clicked()), this, SLOT(onChangeLanguage()));
refreshControls();
}
@@ -73,9 +74,9 @@ void GeneralWidget::refreshControls() {
#endif // TDESKTOP_DISABLE_AUTOUPDATE
if (cPlatform() == dbipWindows || cSupportTray()) {
addChildRow(_enableTrayIcon, marginSmall, lang(lng_settings_workmode_tray), SLOT(onWorkmodeChange()), (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray));
addChildRow(_enableTrayIcon, marginSmall, lang(lng_settings_workmode_tray), SLOT(onEnableTrayIcon()), (cWorkMode() == dbiwmTrayOnly || cWorkMode() == dbiwmWindowAndTray));
if (cPlatform() == dbipWindows) {
addChildRow(_enableTaskbarIcon, marginLarge, lang(lng_settings_workmode_window), SLOT(onWorkmodeChange()), (cWorkMode() == dbiwmWindowOnly || cWorkMode() == dbiwmWindowAndTray));
addChildRow(_enableTaskbarIcon, marginLarge, lang(lng_settings_workmode_window), SLOT(onEnableTaskbarIcon()), (cWorkMode() == dbiwmWindowOnly || cWorkMode() == dbiwmWindowAndTray));
addChildRow(_autoStart, marginSmall, lang(lng_settings_auto_start), SLOT(onAutoStart()), cAutoStart());
addChildRow(_startMinimized, marginLarge, slidedPadding, lang(lng_settings_start_min), SLOT(onStartMinimized()), cStartMinimized());

View File

@@ -37,18 +37,34 @@ namespace Settings {
InnerWidget::InnerWidget(QWidget *parent) : TWidget(parent)
, _self(App::self()) {
if (_self) {
_cover = new CoverWidget(this, _self);
}
refreshBlocks();
subscribe(Global::RefSelfChanged(), [this]() { selfUpdated(); });
}
void InnerWidget::selfUpdated() {
_self = App::self();
refreshBlocks();
if (_cover) {
_cover->setContentLeft(_contentLeft);
_cover->resizeToWidth(width());
}
for_const (auto block, _blocks) {
block->setContentLeft(_contentLeft);
block->resizeToWidth(width());
}
onBlockHeightUpdated();
}
void InnerWidget::refreshBlocks() {
_cover.destroyDelayed();
for_const (auto block, _blocks) {
block->deleteLater();
}
_blocks.clear();
if (_self) {
_cover = new CoverWidget(this, _self);
_blocks.push_back(new Settings::InfoWidget(this, _self));
_blocks.push_back(new Settings::NotificationsWidget(this, _self));
}
@@ -60,7 +76,12 @@ void InnerWidget::refreshBlocks() {
_blocks.push_back(new Settings::PrivacyWidget(this, _self));
}
_blocks.push_back(new Settings::AdvancedWidget(this, _self));
if (_cover) {
_cover->show();
}
for_const (auto block, _blocks) {
block->show();
connect(block, SIGNAL(heightUpdated()), this, SLOT(onBlockHeightUpdated()));
}
}
@@ -102,6 +123,7 @@ void InnerWidget::onBlockHeightUpdated() {
int newHeight = refreshBlocksPositions();
if (newHeight != height()) {
resize(width(), newHeight);
emit heightUpdated();
}
}

View File

@@ -25,7 +25,7 @@ namespace Settings {
class CoverWidget;
class BlockWidget;
class InnerWidget : public TWidget {
class InnerWidget : public TWidget, private base::Subscriber {
Q_OBJECT
public:
@@ -42,6 +42,9 @@ public:
void showFinished();
signals:
void heightUpdated();
private slots:
void onBlockHeightUpdated();
@@ -50,6 +53,7 @@ protected:
int resizeGetHeight(int newWidth) override;
private:
void selfUpdated();
void refreshBlocks();
// Returns the new height value.

View File

@@ -32,14 +32,24 @@ namespace Settings {
NotificationsWidget::NotificationsWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_notify)) {
createControls();
subscribe(Global::RefNotifySettingsChanged(), [this](const Notify::ChangeType &type) {
if (type == Notify::ChangeType::DesktopEnabled) {
desktopEnabledUpdated();
} else if (type == Notify::ChangeType::ViewParams) {
viewParamUpdated();
} else if (type == Notify::ChangeType::SoundEnabled) {
_playSound->setChecked(Global::SoundNotify());
}
});
}
void NotificationsWidget::createControls() {
style::margins margin(0, 0, 0, st::settingsSmallSkip);
style::margins slidedPadding(0, margin.bottom() / 2, 0, margin.bottom() - (margin.bottom() / 2));
addChildRow(_desktopNotifications, margin, lang(lng_settings_desktop_notify), SLOT(onDesktopNotifications()), cDesktopNotify());
addChildRow(_showSenderName, margin, slidedPadding, lang(lng_settings_show_name), SLOT(onShowSenderName()), cNotifyView() <= dbinvShowName);
addChildRow(_showMessagePreview, margin, slidedPadding, lang(lng_settings_show_preview), SLOT(onShowMessagePreview()), cNotifyView() <= dbinvShowPreview);
addChildRow(_desktopNotifications, margin, lang(lng_settings_desktop_notify), SLOT(onDesktopNotifications()), Global::DesktopNotify());
addChildRow(_showSenderName, margin, slidedPadding, lang(lng_settings_show_name), SLOT(onShowSenderName()), Global::NotifyView() <= dbinvShowName);
addChildRow(_showMessagePreview, margin, slidedPadding, lang(lng_settings_show_preview), SLOT(onShowMessagePreview()), Global::NotifyView() <= dbinvShowPreview);
if (!_showSenderName->entity()->checked()) {
_showMessagePreview->hideFast();
}
@@ -49,79 +59,105 @@ void NotificationsWidget::createControls() {
}
#ifdef Q_OS_WIN
if (App::wnd()->psHasNativeNotifications()) {
addChildRow(_windowsNative, margin, lang(lng_settings_use_windows), SLOT(onWindowsNative()), cWindowsNotifications());
addChildRow(_windowsNative, margin, lang(lng_settings_use_windows), SLOT(onWindowsNative()), Global::WindowsNotifications());
}
#endif // Q_OS_WIN
addChildRow(_playSound, margin, lang(lng_settings_sound_notify), SLOT(onPlaySound()), cSoundNotify());
addChildRow(_includeMuted, margin, lang(lng_settings_include_muted), SLOT(onIncludeMuted()), cIncludeMuted());
addChildRow(_playSound, margin, lang(lng_settings_sound_notify), SLOT(onPlaySound()), Global::SoundNotify());
addChildRow(_includeMuted, margin, lang(lng_settings_include_muted), SLOT(onIncludeMuted()), Global::IncludeMuted());
}
void NotificationsWidget::onDesktopNotifications() {
cSetDesktopNotify(_desktopNotifications->checked());
if (Global::DesktopNotify() == _desktopNotifications->checked()) {
return;
}
Global::SetDesktopNotify(_desktopNotifications->checked());
Local::writeUserSettings();
if (App::wnd()) App::wnd()->updateTrayMenu();
Global::RefNotifySettingsChanged().notify(Notify::ChangeType::DesktopEnabled);
}
if (_desktopNotifications->checked()) {
void NotificationsWidget::desktopEnabledUpdated() {
_desktopNotifications->setChecked(Global::DesktopNotify());
if (Global::DesktopNotify()) {
_showSenderName->slideDown();
if (_showSenderName->entity()->checked()) {
_showMessagePreview->slideDown();
}
} else {
App::wnd()->notifyClear();
_showSenderName->slideUp();
_showMessagePreview->slideUp();
}
}
void NotificationsWidget::onShowSenderName() {
auto viewParam = ([this]() {
if (!_showSenderName->entity()->checked()) {
return dbinvShowNothing;
} else if (!_showMessagePreview->entity()->checked()) {
return dbinvShowName;
}
return dbinvShowPreview;
})();
if (viewParam == Global::NotifyView()) {
return;
}
Global::SetNotifyView(viewParam);
Local::writeUserSettings();
Global::RefNotifySettingsChanged().notify(Notify::ChangeType::ViewParams);
}
void NotificationsWidget::onShowMessagePreview() {
auto viewParam = ([this]() {
if (_showMessagePreview->entity()->checked()) {
return dbinvShowPreview;
} else if (_showSenderName->entity()->checked()) {
return dbinvShowName;
}
return dbinvShowNothing;
})();
if (viewParam == Global::NotifyView()) {
return;
}
Global::SetNotifyView(viewParam);
Local::writeUserSettings();
Global::RefNotifySettingsChanged().notify(Notify::ChangeType::ViewParams);
}
void NotificationsWidget::viewParamUpdated() {
if (_showSenderName->entity()->checked()) {
_showMessagePreview->slideDown();
} else {
_showMessagePreview->slideUp();
}
if (!_showSenderName->entity()->checked()) {
cSetNotifyView(dbinvShowNothing);
} else if (!_showMessagePreview->entity()->checked()) {
cSetNotifyView(dbinvShowName);
} else {
cSetNotifyView(dbinvShowPreview);
}
Local::writeUserSettings();
App::wnd()->notifyUpdateAll();
}
void NotificationsWidget::onShowMessagePreview() {
if (_showMessagePreview->entity()->checked()) {
cSetNotifyView(dbinvShowPreview);
} else if (_showSenderName->entity()->checked()) {
cSetNotifyView(dbinvShowName);
} else {
cSetNotifyView(dbinvShowNothing);
}
Local::writeUserSettings();
App::wnd()->notifyUpdateAll();
}
#ifdef Q_OS_WIN
void NotificationsWidget::onWindowsNative() {
if (cPlatform() != dbipWindows) return;
cSetWindowsNotifications(!cWindowsNotifications());
App::wnd()->notifyClearFast();
cSetCustomNotifies(!cWindowsNotifications());
#ifdef Q_OS_WIN
if (Global::WindowsNotifications() == _windowsNative->checked()) {
return;
}
Global::SetWindowsNotifications(_windowsNative->checked());
Global::SetCustomNotifies(!Global::WindowsNotifications());
Local::writeUserSettings();
}
Global::RefNotifySettingsChanged().notify(Notify::ChangeType::UseNative);
#endif // Q_OS_WIN
}
void NotificationsWidget::onPlaySound() {
cSetSoundNotify(_playSound->checked());
if (_playSound->checked() == Global::SoundNotify()) {
return;
}
Global::SetSoundNotify(_playSound->checked());
Local::writeUserSettings();
Global::RefNotifySettingsChanged().notify(Notify::ChangeType::SoundEnabled);
}
void NotificationsWidget::onIncludeMuted() {
cSetIncludeMuted(_includeMuted->checked());
Notify::unreadCounterUpdated();
Global::SetIncludeMuted(_includeMuted->checked());
Local::writeUserSettings();
Global::RefNotifySettingsChanged().notify(Notify::ChangeType::IncludeMuted);
}
} // namespace Settings

View File

@@ -34,14 +34,14 @@ private slots:
void onDesktopNotifications();
void onShowSenderName();
void onShowMessagePreview();
#ifdef Q_OS_WIN
void onWindowsNative();
#endif // Q_OS_WIN
void onPlaySound();
void onIncludeMuted();
private:
void createControls();
void desktopEnabledUpdated();
void viewParamUpdated();
ChildWidget<Checkbox> _desktopNotifications = { nullptr };
ChildWidget<Ui::WidgetSlideWrap<Checkbox>> _showSenderName = { nullptr };

View File

@@ -42,6 +42,8 @@ Widget::Widget() : LayerWidget()
_fixedBarShadow1->move(0, _fixedBar->y() + st::settingsFixedBarHeight);
_fixedBarShadow2->move(0, _fixedBarShadow1->y() + st::lineWidth);
_scroll->move(0, st::settingsFixedBarHeight);
connect(_inner, SIGNAL(heightUpdated()), this, SLOT(onInnerHeightUpdated()));
}
void Widget::parentResized() {
@@ -70,6 +72,17 @@ void Widget::parentResized() {
// resize it here, not in the resizeEvent() handler.
_inner->resizeToWidth(newWidth, newContentLeft);
resizeUsingInnerHeight(newWidth, newContentLeft);
}
void Widget::onInnerHeightUpdated() {
resizeUsingInnerHeight(width(), _contentLeft);
}
void Widget::resizeUsingInnerHeight(int newWidth, int newContentLeft) {
if (!App::wnd()) return;
int windowWidth = App::wnd()->width();
int windowHeight = App::wnd()->height();
int maxHeight = st::settingsFixedBarHeight + _inner->height();
int newHeight = maxHeight;

View File

@@ -28,6 +28,8 @@ class InnerWidget;
class FixedBar;
class Widget : public LayerWidget {
Q_OBJECT
public:
Widget();
@@ -38,7 +40,12 @@ protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private slots:
void onInnerHeightUpdated();
private:
void resizeUsingInnerHeight(int newWidth, int newContentLeft);
ChildWidget<ScrollArea> _scroll;
ChildWidget<InnerWidget> _inner;
ChildWidget<FixedBar> _fixedBar;