diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index be6f42516..a10cd9242 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -217,6 +217,9 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_settings_upload" = "Set Profile Photo"; "lng_settings_crop_profile" = "Select a square area for your profile photo"; "lng_settings_uploading_photo" = "Uploading photo..."; +"lng_settings_edit" = "Edit"; + +"lng_settings_drop_area_subtitle" = "to set it as your photo"; "lng_username_title" = "Username"; "lng_username_about" = "You can choose a username on Telegram.\nIf you do, other people will be able to find\nyou by this username and contact you\nwithout knowing your phone number.\n\nYou can use a-z, 0-9 and underscores.\nMinimum length is 5 characters."; @@ -231,7 +234,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_username_link" = "This link opens a chat with you:"; "lng_username_copied" = "Link copied to clipboard."; -"lng_settings_section_contact_info" = "Contact info"; +"lng_settings_section_info" = "Info"; "lng_settings_phone_number" = "Phone number:"; "lng_settings_username" = "Username:"; "lng_settings_choose_username" = "Choose username"; @@ -264,10 +267,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_settings_auto_start" = "Launch Telegram when system starts"; "lng_settings_start_min" = "Launch minimized"; "lng_settings_add_sendto" = "Place Telegram in «Send to» menu"; -"lng_settings_scale_label" = "Interface scale"; +"lng_settings_section_scale" = "Interface Scale"; "lng_settings_scale_auto" = "Auto ({cur})"; -"lng_settings_section_chat" = "Chat options"; +"lng_settings_section_chat_settings" = "Chat Settings"; "lng_settings_replace_emojis" = "Replace emoji"; "lng_settings_view_emojis" = "View list"; "lng_settings_emoji_list" = "Supported emoji"; @@ -301,7 +304,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org "lng_download_path_cleared" = "Cleared!"; "lng_download_path_clear_failed" = "Clear failed :("; -"lng_settings_section_cache" = "Local storage"; +"lng_settings_section_privacy" = "Privacy and Security"; + "lng_settings_no_data_cached" = "No cached data found!"; "lng_settings_images_cached" = "{count:_not_used_|# image|# images}, {size}"; "lng_settings_audios_cached" = "{count:_not_used_|# voice message|# voice messages}, {size}"; diff --git a/Telegram/SourceFiles/layerwidget.cpp b/Telegram/SourceFiles/layerwidget.cpp index b315056b0..e312b8189 100644 --- a/Telegram/SourceFiles/layerwidget.cpp +++ b/Telegram/SourceFiles/layerwidget.cpp @@ -41,8 +41,9 @@ public: , _shadow(st::boxShadow) { } - void setLayerBox(const QRect &box) { + void setLayerBox(const QRect &box, const QRect &hiddenSpecialBox) { _box = box; + _hiddenSpecialBox = hiddenSpecialBox; update(); } void setOpacity(float64 opacity) { @@ -64,11 +65,15 @@ protected: p.setClipRegion(clip); p.setOpacity(_opacity); _shadow.paint(p, _box, st::boxShadowShift); + if (!_hiddenSpecialBox.isNull()) { + p.setClipRegion(QRegion(rect()) - _hiddenSpecialBox); + _shadow.paint(p, _hiddenSpecialBox, st::boxShadowShift); + } } } private: - QRect _box; + QRect _box, _hiddenSpecialBox; float64 _opacity = 0.; BoxShadow _shadow; @@ -93,6 +98,9 @@ void LayerStackWidget::paintEvent(QPaintEvent *e) { Painter p(this); p.setClipRect(rect()); p.setOpacity(a_layer.current()); + if (!_hiddenSpecialLayerCache.isNull()) { + p.drawPixmap(_hiddenSpecialLayerCacheBox.topLeft(), _hiddenSpecialLayerCache); + } p.drawPixmap(_layerCacheBox.topLeft(), _layerCache); } } @@ -104,7 +112,11 @@ void LayerStackWidget::keyPressEvent(QKeyEvent *e) { } void LayerStackWidget::mousePressEvent(QMouseEvent *e) { - onClose(); + if (layer()) { + onCloseLayers(); + } else { + onClose(); + } } void LayerStackWidget::onCloseLayers() { @@ -144,6 +156,7 @@ void LayerStackWidget::onLayerClosed(LayerWidget *l) { fixOrder(); if (App::wnd()) App::wnd()->setInnerFocus(); updateLayerBox(); + sendFakeMouseEvent(); } else { for (auto i = _layers.begin(), e = _layers.end(); i != e; ++i) { if (l == *i) { @@ -169,7 +182,15 @@ void LayerStackWidget::updateLayerBox() { } return QRect(); }; - _background->setLayerBox(getLayerBox()); + auto getSpecialLayerBox = [this]() { + if (!_layerCache.isNull()) { + return _hiddenSpecialLayerCacheBox; + } else if (auto l = layer()) { + return _specialLayer ? _specialLayer->geometry() : QRect(); + } + return QRect(); + }; + _background->setLayerBox(getLayerBox(), getSpecialLayerBox()); update(); } @@ -202,6 +223,10 @@ void LayerStackWidget::startAnimation(float64 toOpacity) { if (auto cacheLayer = layer() ? layer() : _specialLayer) { _layerCache = myGrab(cacheLayer); _layerCacheBox = cacheLayer->geometry(); + if (layer() && _specialLayer) { + _hiddenSpecialLayerCache = myGrab(_specialLayer); + _hiddenSpecialLayerCacheBox = _specialLayer->geometry(); + } } } if (_specialLayer) { @@ -294,6 +319,8 @@ void LayerStackWidget::clearLayers() { oldLayer->deleteLater(); } _layers.clear(); + updateLayerBox(); + sendFakeMouseEvent(); } void LayerStackWidget::initChildLayer(LayerWidget *l) { @@ -315,6 +342,7 @@ void LayerStackWidget::activateLayer(LayerWidget *l) { updateLayerBox(); } fixOrder(); + sendFakeMouseEvent(); } void LayerStackWidget::fixOrder() { @@ -326,13 +354,17 @@ void LayerStackWidget::fixOrder() { } } +void LayerStackWidget::sendFakeMouseEvent() { + sendSynteticMouseEvent(this, QEvent::MouseMove, Qt::NoButton); +} + void LayerStackWidget::step_background(float64 ms, bool timer) { float64 dt = ms / (_hiding ? st::layerHideDuration : st::layerSlideDuration); if (dt >= 1) { a_bg.finish(); a_layer.finish(); _a_background.stop(); - _layerCache = QPixmap(); + _layerCache = _hiddenSpecialLayerCache = QPixmap(); if (_hiding) { App::wnd()->layerFinishedHide(this); } else { diff --git a/Telegram/SourceFiles/layerwidget.h b/Telegram/SourceFiles/layerwidget.h index 9dc5090f8..825829e76 100644 --- a/Telegram/SourceFiles/layerwidget.h +++ b/Telegram/SourceFiles/layerwidget.h @@ -95,6 +95,7 @@ private: void activateLayer(LayerWidget *l); void updateLayerBox(); void fixOrder(); + void sendFakeMouseEvent(); void startShow(); void startHide(); @@ -122,6 +123,8 @@ private: QPixmap _layerCache; QRect _layerCacheBox; + QPixmap _hiddenSpecialLayerCache; + QRect _hiddenSpecialLayerCacheBox; bool _hiding = false; diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index e907b9fdd..d11a71f43 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -682,12 +682,29 @@ void MainWindow::showSettings() { return; } - if (!layerBg) { - layerBg = new LayerStackWidget(this); + if (true) { + if (!layerBg) { + layerBg = new LayerStackWidget(this); + } + settings = new Settings::Widget(); + connect(settings, SIGNAL(destroyed(QObject*)), this, SLOT(onSettingsDestroyed(QObject*))); + layerBg->showSpecialLayer(settings); + } else { + QPixmap bg = grabInner(); + + if (intro) { + intro->stop_show(); + intro->hide(); + } else if (main) { + main->animStop_show(); + main->hide(); + } + auto settings = new SettingsWidget(this); + settings->animShow(bg); + title->updateBackButton(); + + fixOrder(); } - settings = new Settings::Widget(); - connect(settings, SIGNAL(destroyed(QObject*)), this, SLOT(onSettingsDestroyed(QObject*))); - layerBg->showSpecialLayer(settings); } void MainWindow::ui_hideSettingsAndLayer(ShowLayerOptions options) { diff --git a/Telegram/SourceFiles/profile/profile_cover.cpp b/Telegram/SourceFiles/profile/profile_cover.cpp index b4e590449..b3504b829 100644 --- a/Telegram/SourceFiles/profile/profile_cover.cpp +++ b/Telegram/SourceFiles/profile/profile_cover.cpp @@ -159,9 +159,9 @@ void CoverWidget::refreshNameGeometry(int newWidth) { // for each text button. But currently we use only one, so it is done easily: // There can be primary + secondary + icon buttons. If primary + secondary fit, // then icon is hidden, otherwise secondary is hidden and icon is shown. -void CoverWidget::moveAndToggleButtons(int newWiddth) { +void CoverWidget::moveAndToggleButtons(int newWidth) { int buttonLeft = _userpicButton->x() + _userpicButton->width() + st::profileButtonLeft; - int buttonsRight = newWiddth - st::profileButtonSkip; + int buttonsRight = newWidth - st::profileButtonSkip; for (int i = 0, count = _buttons.size(); i < count; ++i) { auto &button = _buttons.at(i); button.widget->moveToLeft(buttonLeft, st::profileButtonTop); @@ -315,9 +315,10 @@ void CoverWidget::dropEvent(QDropEvent *e) { } void CoverWidget::paintDivider(Painter &p) { - st::profileDividerLeft.paint(p, QPoint(st::lineWidth, _dividerTop), width()); + auto dividerLeft = (Adaptive::OneColumn() ? 0 : st::lineWidth); + st::profileDividerLeft.paint(p, QPoint(dividerLeft, _dividerTop), width()); - int toFillLeft = st::lineWidth + st::profileDividerLeft.width(); + int toFillLeft = dividerLeft + st::profileDividerLeft.width(); QRect toFill = rtlrect(toFillLeft, _dividerTop, width() - toFillLeft, st::profileDividerFill.height(), width()); st::profileDividerFill.fill(p, toFill); } @@ -346,6 +347,7 @@ void CoverWidget::refreshStatusText() { if (auto app = App::app()) { if (app->isPhotoUpdating(_peer->id)) { _statusText = lang(lng_settings_uploading_photo); + _statusTextIsOnline = false; if (!_cancelPhotoUpload) { _cancelPhotoUpload = new LinkButton(this, lang(lng_cancel), st::btnDefLink); connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload())); diff --git a/Telegram/SourceFiles/profile/profile_cover.h b/Telegram/SourceFiles/profile/profile_cover.h index 768a77349..d7034ef93 100644 --- a/Telegram/SourceFiles/profile/profile_cover.h +++ b/Telegram/SourceFiles/profile/profile_cover.h @@ -88,7 +88,7 @@ private: PhotoData *validatePhoto() const; void refreshNameGeometry(int newWidth); - void moveAndToggleButtons(int newWiddth); + void moveAndToggleButtons(int newWidth); void refreshNameText(); void refreshStatusText(); diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index 8a4875336..16094e9cc 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -49,4 +49,55 @@ settingsFixedBarClose: IconButton { settingsFixedBarShadowBg1: #00000021; settingsFixedBarShadowBg2: #0000000b; -settingsPhotoLeft: -8px; \ No newline at end of file +settingsMarginTop: 34px; +settingsPhotoSize: 112px; +settingsPhotoLeft: -8px; +settingsPhotoDuration: 500; +settingsNameLeft: 26px; +settingsNameTop: 9px; +settingsNameLabel: flatLabel(labelDefFlat) { + margin: margins(10px, 5px, 10px, 5px); + font: font(16px semibold); + width: 160px; + maxHeight: 24px; + textFg: #333333; +} +settingsNameTextStyle: textStyle(defaultTextStyle) { +} +settingsStatusLeft: 27px; +settingsStatusTop: 35px; +settingsStatusFont: normalFont; +settingsStatusFg: windowSubTextFg; +settingsStatusFgActive: windowActiveTextFg; +settingsMarginBottom: 35px; + +settingsButtonLeft: 27px; +settingsButtonTop: 75px; +settingsButtonSkip: 10px; +settingsPrimaryButton: RoundButton(defaultActiveButton) { +} +settingsSecondaryButton: RoundButton(settingsPrimaryButton) { + textFg: semiboldButtonBlueText; + textFgOver: semiboldButtonBlueText; + textBg: #ffffff; + textBgOver: #f2f7fa; +} + +settingsBlocksTop: 7px; +settingsBlocksBottom: 20px; +settingsBlockMarginTop: 14px; +settingsBlockMarginBottom: 7px; +settingsBlockTitleHeight: 24px; +settingsBlockTitleFont: font(14px semibold); +settingsBlockTitleFg: #333333; +settingsBlockTitleTop: 0px; +settingsBlockLabel: flatLabel(labelDefFlat) { + textFg: windowSubTextFg; +} +settingsBlockOneLineTextPart: flatLabel(labelDefFlat) { + width: 0px; // No need to set minWidth in one-line text. + margin: margins(5px, 5px, 5px, 5px); + maxHeight: 20px; +} +settingsBlockOneLineSkip: 9px; +settingsBlockOneLineWidthMax: 240px; diff --git a/Telegram/SourceFiles/settings/settings_advanced_widget.cpp b/Telegram/SourceFiles/settings/settings_advanced_widget.cpp new file mode 100644 index 000000000..dab88d9e8 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_advanced_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_advanced_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +AdvancedWidget::AdvancedWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_advanced)) { + refreshControls(); +} + +void AdvancedWidget::refreshControls() { +} + +int AdvancedWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_advanced_widget.h b/Telegram/SourceFiles/settings/settings_advanced_widget.h new file mode 100644 index 000000000..bc284ed91 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_advanced_widget.h @@ -0,0 +1,40 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +namespace Settings { + +class AdvancedWidget : public BlockWidget { +public: + AdvancedWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + void refreshControls(); + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_background_widget.cpp b/Telegram/SourceFiles/settings/settings_background_widget.cpp new file mode 100644 index 000000000..b5dc57957 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_background_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_background_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +BackgroundWidget::BackgroundWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_background)) { + refreshControls(); +} + +void BackgroundWidget::refreshControls() { +} + +int BackgroundWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_background_widget.h b/Telegram/SourceFiles/settings/settings_background_widget.h new file mode 100644 index 000000000..44ba85667 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_background_widget.h @@ -0,0 +1,40 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +namespace Settings { + +class BackgroundWidget : public BlockWidget { +public: + BackgroundWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + void refreshControls(); + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_block_widget.cpp b/Telegram/SourceFiles/settings/settings_block_widget.cpp new file mode 100644 index 000000000..fe7e0697d --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_block_widget.cpp @@ -0,0 +1,57 @@ +/* +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 "settings/settings_block_widget.h" + +#include "styles/style_settings.h" + +namespace Settings { + +BlockWidget::BlockWidget(QWidget *parent, UserData *self, const QString &title) : ScrolledWidget(parent) +, _self(self) +, _title(title) { +} + +void BlockWidget::setContentLeft(int contentLeft) { + _contentLeft = contentLeft; +} + +int BlockWidget::contentTop() const { + return emptyTitle() ? 0 : (st::settingsBlockMarginTop + st::settingsBlockTitleHeight); +} + +void BlockWidget::paintEvent(QPaintEvent *e) { + Painter p(this); + + paintTitle(p); + paintContents(p); +} + +void BlockWidget::paintTitle(Painter &p) { + if (emptyTitle()) return; + + p.setFont(st::settingsBlockTitleFont); + p.setPen(st::settingsBlockTitleFg); + int titleTop = st::settingsBlockMarginTop + st::settingsBlockTitleTop; + p.drawTextLeft(contentLeft(), titleTop, width(), _title); +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_block_widget.h b/Telegram/SourceFiles/settings/settings_block_widget.h new file mode 100644 index 000000000..4df35cd90 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_block_widget.h @@ -0,0 +1,71 @@ +/* +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 +*/ +#pragma once + +#include "core/observer.h" + +namespace Settings { + +class BlockWidget : public ScrolledWidget, public Notify::Observer, public base::Subscriber { + Q_OBJECT + +public: + BlockWidget(QWidget *parent, UserData *self, const QString &title); + + void setContentLeft(int contentLeft); + +protected: + void paintEvent(QPaintEvent *e) override; + virtual void paintContents(Painter &p) { + } + + // Where does the block content start (after the title). + int contentLeft() const { + return _contentLeft; + } + int contentTop() const; + + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override = 0; + + void contentSizeUpdated() { + resizeToWidth(width()); + emit heightUpdated(); + } + + UserData *self() const { + return _self; + } + + bool emptyTitle() const { + return _title.isEmpty(); + } + +private: + void paintTitle(Painter &p); + + int _contentLeft = 0; + UserData *_self; + QString _title; + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp new file mode 100644 index 000000000..405174c55 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_chat_settings_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_chat_settings_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +ChatSettingsWidget::ChatSettingsWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_chat_settings)) { + refreshControls(); +} + +void ChatSettingsWidget::refreshControls() { +} + +int ChatSettingsWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_chat_settings_widget.h b/Telegram/SourceFiles/settings/settings_chat_settings_widget.h new file mode 100644 index 000000000..726bf4cfe --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_chat_settings_widget.h @@ -0,0 +1,40 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +namespace Settings { + +class ChatSettingsWidget : public BlockWidget { +public: + ChatSettingsWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + void refreshControls(); + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_cover.cpp b/Telegram/SourceFiles/settings/settings_cover.cpp new file mode 100644 index 000000000..40f39160d --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_cover.cpp @@ -0,0 +1,336 @@ +/* +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 "settings/settings_cover.h" + +#include "ui/flatlabel.h" +#include "ui/buttons/round_button.h" +#include "observer_peer.h" +#include "lang.h" +#include "application.h" +#include "apiwrap.h" +#include "profile/profile_userpic_button.h" +#include "profile/profile_cover_drop_area.h" +#include "boxes/confirmbox.h" +#include "boxes/photocropbox.h" +#include "boxes/addcontactbox.h" + +#include "styles/style_settings.h" +#include "styles/style_profile.h" // for divider + +namespace Settings { + +CoverWidget::CoverWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, QString()) +, _self(App::self()) +, _userpicButton(this, _self) +, _name(this, st::settingsNameLabel) +, _setPhoto(this, lang(lng_settings_upload), st::settingsPrimaryButton) +, _editName(this, lang(lng_settings_edit), st::settingsSecondaryButton) { + setAcceptDrops(true); + + _name->setSelectable(true); + _name->setContextCopyText(lang(lng_profile_copy_fullname)); + + _setPhoto->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + connect(_setPhoto, SIGNAL(clicked()), this, SLOT(onSetPhoto())); + _editName->setTextTransform(Ui::RoundButton::TextTransform::ToUpper); + connect(_editName, SIGNAL(clicked()), this, SLOT(onEditName())); + + auto observeEvents = Notify::PeerUpdate::Flag::NameChanged; + Notify::registerPeerObserver(observeEvents, this, &CoverWidget::notifyPeerUpdated); + FileDialog::registerObserver(this, &CoverWidget::notifyFileQueryUpdated); + + connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); + connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId))); + + connect(_userpicButton, SIGNAL(clicked()), this, SLOT(onPhotoShow())); + validatePhoto(); + + refreshNameText(); + refreshStatusText(); +} + +PhotoData *CoverWidget::validatePhoto() const { + PhotoData *photo = (_self->photoId && _self->photoId != UnknownPeerPhotoId) ? App::photo(_self->photoId) : nullptr; + if ((_self->photoId == UnknownPeerPhotoId) || (_self->photoId && (!photo || !photo->date))) { + App::api()->requestFullPeer(_self); + return nullptr; + } + return photo; +} + +void CoverWidget::onPhotoShow() { + if (auto photo = validatePhoto()) { + App::wnd()->showPhoto(photo, _self); + } +} + +void CoverWidget::onCancelPhotoUpload() { + if (auto app = App::app()) { + app->cancelPhotoUpdate(_self->id); + refreshStatusText(); + } +} + +int CoverWidget::resizeGetHeight(int newWidth) { + int newHeight = 0; + + newHeight += st::settingsMarginTop; + + _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) { + _cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::settingsStatusFont->width(_statusText) + st::settingsStatusFont->spacew, _statusPosition.y()); + } + + int buttonLeft = _userpicButton->x() + _userpicButton->width() + st::settingsButtonLeft; + 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(); + } + + newHeight += st::settingsPhotoSize; + newHeight += st::settingsMarginBottom; + + _dividerTop = newHeight; + newHeight += st::profileDividerFill.height(); + + newHeight += st::settingsBlocksTop; + + resizeDropArea(); + return newHeight; +} + +void CoverWidget::refreshNameGeometry(int newWidth) { + int infoLeft = _userpicButton->x() + _userpicButton->width(); + 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; + int marginsAdd = st::settingsNameLabel.margin.left() + st::settingsNameLabel.margin.right(); + _name->resizeToWidth(qMin(nameWidth - marginsAdd, _name->naturalWidth()) + marginsAdd); + _name->moveToLeft(nameLeft, nameTop); +} + +void CoverWidget::showFinished() { + _userpicButton->showFinished(); +} + +void CoverWidget::paintContents(Painter &p) { + p.setFont(st::settingsStatusFont); + p.setPen(_statusTextIsOnline ? st::settingsStatusFgActive : st::settingsStatusFg); + p.drawTextLeft(_statusPosition.x(), _statusPosition.y(), width(), _statusText); + + paintDivider(p); +} + +void CoverWidget::resizeDropArea() { + if (_dropArea) { + _dropArea->setGeometry(0, 0, width(), _dividerTop); + } +} + +void CoverWidget::dropAreaHidden(Profile::CoverDropArea *dropArea) { + if (_dropArea == dropArea) { + _dropArea.destroyDelayed(); + } +} + +bool CoverWidget::mimeDataHasImage(const QMimeData *mimeData) const { + if (!mimeData) return false; + + if (mimeData->hasImage()) return true; + + auto uriListFormat = qsl("text/uri-list"); + if (!mimeData->hasFormat(uriListFormat)) return false; + + const auto &urls = mimeData->urls(); + if (urls.size() != 1) return false; + + auto &url = urls.at(0); + if (!url.isLocalFile()) return false; + + auto file = psConvertFileUrl(url); + + QFileInfo info(file); + if (info.isDir()) return false; + + quint64 s = info.size(); + if (s >= MaxUploadDocumentSize) return false; + + for (auto &ext : cImgExtensions()) { + if (file.endsWith(ext, Qt::CaseInsensitive)) { + return true; + } + } + return false; +} + +void CoverWidget::dragEnterEvent(QDragEnterEvent *e) { + if (!mimeDataHasImage(e->mimeData())) { + e->ignore(); + return; + } + if (!_dropArea) { + auto title = lang(lng_profile_drop_area_title); + auto subtitle = lang(lng_settings_drop_area_subtitle); + _dropArea = new Profile::CoverDropArea(this, title, subtitle); + resizeDropArea(); + } + _dropArea->showAnimated(); + e->setDropAction(Qt::CopyAction); + e->accept(); +} + +void CoverWidget::dragLeaveEvent(QDragLeaveEvent *e) { + if (_dropArea && !_dropArea->hiding()) { + _dropArea->hideAnimated(func(this, &CoverWidget::dropAreaHidden)); + } +} + +void CoverWidget::dropEvent(QDropEvent *e) { + auto mimeData = e->mimeData(); + + QImage img; + if (mimeData->hasImage()) { + img = qvariant_cast(mimeData->imageData()); + } else { + const auto &urls = mimeData->urls(); + if (urls.size() == 1) { + auto &url = urls.at(0); + if (url.isLocalFile()) { + img = App::readImage(psConvertFileUrl(url)); + } + } + } + + if (!_dropArea->hiding()) { + _dropArea->hideAnimated(func(this, &CoverWidget::dropAreaHidden)); + } + e->acceptProposedAction(); + + showSetPhotoBox(img); +} + +void CoverWidget::paintDivider(Painter &p) { + st::profileDividerLeft.paint(p, QPoint(0, _dividerTop), width()); + + int toFillLeft = st::profileDividerLeft.width(); + QRect toFill = rtlrect(toFillLeft, _dividerTop, width() - toFillLeft, st::profileDividerFill.height(), width()); + st::profileDividerFill.fill(p, toFill); +} + +void CoverWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) { + if (update.peer != _self) { + return; + } + if (update.flags & Notify::PeerUpdate::Flag::NameChanged) { + refreshNameText(); + } + //if (update.flags & UpdateFlag::UserOnlineChanged) { // TODO + // refreshStatusText(); + //} +} + +void CoverWidget::refreshNameText() { + _name->setText(App::peerName(_self)); + refreshNameGeometry(width()); +} + +void CoverWidget::refreshStatusText() { + if (auto app = App::app()) { + if (app->isPhotoUpdating(_self->id)) { + _statusText = lang(lng_settings_uploading_photo); + _statusTextIsOnline = false; + if (!_cancelPhotoUpload) { + _cancelPhotoUpload = new LinkButton(this, lang(lng_cancel), st::btnDefLink); + connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload())); + _cancelPhotoUpload->show(); + _cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::settingsStatusFont->width(_statusText) + st::settingsStatusFont->spacew, _statusPosition.y()); + } + update(); + return; + } + } + + _cancelPhotoUpload.destroy(); + _statusText = lang(lng_status_online); + _statusTextIsOnline = true; + update(); +} + +void CoverWidget::onSetPhoto() { + QStringList imgExtensions(cImgExtensions()); + QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter()); + + _setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_images), filter); +} + +void CoverWidget::onEditName() { + Ui::showLayer(new EditNameTitleBox(self())); +} + +void CoverWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) { + if (_setPhotoFileQueryId != update.queryId) { + return; + } + _setPhotoFileQueryId = 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()); + } + + showSetPhotoBox(img); +} + +void CoverWidget::showSetPhotoBox(const QImage &img) { + if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) { + Ui::showLayer(new InformBox(lang(lng_bad_photo))); + return; + } + + auto box = new PhotoCropBox(img, _self); + connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(onPhotoUploadStatusChanged())); + Ui::showLayer(box); +} + +void CoverWidget::onPhotoUploadStatusChanged(PeerId peerId) { + if (!peerId || peerId == _self->id) { + refreshStatusText(); + } +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_cover.h b/Telegram/SourceFiles/settings/settings_cover.h new file mode 100644 index 000000000..1dd635ac7 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_cover.h @@ -0,0 +1,111 @@ +/* +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 +*/ +#pragma once + +#include "core/observer.h" +#include "ui/filedialog.h" + +#include "settings/settings_block_widget.h" + +class FlatLabel; +class LinkButton; + +namespace Ui { +class RoundButton; +} // namespace Ui + +namespace Notify { +struct PeerUpdate; +} // namespace Notify + +namespace Profile { +class UserpicButton; +class CoverDropArea; +} // namespace Profile + +namespace Settings { + +class CoverWidget final : public BlockWidget { + Q_OBJECT + +public: + CoverWidget(QWidget *parent, UserData *self); + + void showFinished(); + +private slots: + void onPhotoShow(); + void onPhotoUploadStatusChanged(PeerId peerId = 0); + void onCancelPhotoUpload(); + + void onSetPhoto(); + void onEditName(); + +protected: + void dragEnterEvent(QDragEnterEvent *e) override; + void dragLeaveEvent(QDragLeaveEvent *e) override; + void dropEvent(QDropEvent *e) override; + + void paintContents(Painter &p) override; + + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + // Observed notifications. + void notifyPeerUpdated(const Notify::PeerUpdate &update); + void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update); + + PhotoData *validatePhoto() const; + + void refreshNameGeometry(int newWidth); + void refreshNameText(); + void refreshStatusText(); + + void paintDivider(Painter &p); + + void showSetPhotoBox(const QImage &img); + void resizeDropArea(); + void dropAreaHidden(Profile::CoverDropArea *dropArea); + bool mimeDataHasImage(const QMimeData *mimeData) const; + + UserData *_self; + + ChildWidget _userpicButton; + ChildWidget _dropArea = { nullptr }; + + ChildWidget _name; + ChildWidget _cancelPhotoUpload = { nullptr }; + + QPoint _statusPosition; + QString _statusText; + bool _statusTextIsOnline = false; + + ChildWidget _setPhoto; + ChildWidget _editName; + + int _dividerTop = 0; + + FileDialog::QueryId _setPhotoFileQueryId = 0; + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_general_widget.cpp b/Telegram/SourceFiles/settings/settings_general_widget.cpp new file mode 100644 index 000000000..b624cae16 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_general_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_general_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +GeneralWidget::GeneralWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_general)) { + refreshControls(); +} + +void GeneralWidget::refreshControls() { +} + +int GeneralWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_general_widget.h b/Telegram/SourceFiles/settings/settings_general_widget.h new file mode 100644 index 000000000..af337f8b8 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_general_widget.h @@ -0,0 +1,40 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +namespace Settings { + +class GeneralWidget : public BlockWidget { +public: + GeneralWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + void refreshControls(); + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_info_widget.cpp b/Telegram/SourceFiles/settings/settings_info_widget.cpp new file mode 100644 index 000000000..b7f17c04d --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_info_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_info_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +InfoWidget::InfoWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_info)) { + refreshControls(); +} + +void InfoWidget::refreshControls() { +} + +int InfoWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_info_widget.h b/Telegram/SourceFiles/settings/settings_info_widget.h new file mode 100644 index 000000000..b963a2601 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_info_widget.h @@ -0,0 +1,64 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +class FlatLabel; + +namespace Notify { +struct PeerUpdate; +} // namespace Notify + +namespace Settings { + +class InfoWidget : public BlockWidget { +public: + InfoWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + // Observed notifications. + void notifyPeerUpdated(const Notify::PeerUpdate &update); + + void refreshControls(); + void refreshMobileNumber(); + void refreshUsername(); + void refreshLink(); + + // labelWidget may be nullptr. + void setLabeledText(ChildWidget *labelWidget, const QString &label, + ChildWidget *textWidget, const TextWithEntities &textWithEntities, const QString ©Text); + + ChildWidget _mobileNumberLabel = { nullptr }; + ChildWidget _mobileNumber = { nullptr }; + ChildWidget _usernameLabel = { nullptr }; + ChildWidget _username = { nullptr }; + ChildWidget _linkLabel = { nullptr }; + ChildWidget _link = { nullptr }; + ChildWidget _linkShort = { nullptr }; + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_inner_widget.cpp b/Telegram/SourceFiles/settings/settings_inner_widget.cpp index d85c5eabe..4b600f6be 100644 --- a/Telegram/SourceFiles/settings/settings_inner_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_inner_widget.cpp @@ -21,10 +21,51 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "stdafx.h" #include "settings/settings_inner_widget.h" +#include "styles/style_settings.h" +#include "settings/settings_cover.h" +#include "settings/settings_block_widget.h" +#include "settings/settings_info_widget.h" +#include "settings/settings_notifications_widget.h" +#include "settings/settings_general_widget.h" +#include "settings/settings_chat_settings_widget.h" +#include "settings/settings_scale_widget.h" +#include "settings/settings_background_widget.h" +#include "settings/settings_privacy_widget.h" +#include "settings/settings_advanced_widget.h" + namespace Settings { InnerWidget::InnerWidget(QWidget *parent) : TWidget(parent) -{ +, _self(App::self()) { + if (_self) { + _cover = new CoverWidget(this, _self); + } + refreshBlocks(); +} + +void InnerWidget::refreshBlocks() { + for_const (auto block, _blocks) { + block->deleteLater(); + } + _blocks.clear(); + if (_self) { + _blocks.push_back(new Settings::InfoWidget(this, _self)); + _blocks.push_back(new Settings::NotificationsWidget(this, _self)); + } + _blocks.push_back(new Settings::GeneralWidget(this, _self)); + _blocks.push_back(new Settings::ScaleWidget(this, _self)); + if (_self) { + _blocks.push_back(new Settings::ChatSettingsWidget(this, _self)); + _blocks.push_back(new Settings::BackgroundWidget(this, _self)); + _blocks.push_back(new Settings::PrivacyWidget(this, _self)); + } + _blocks.push_back(new Settings::AdvancedWidget(this, _self)); +} + +void InnerWidget::showFinished() { + if (_cover) { + _cover->showFinished(); + } } void InnerWidget::resizeToWidth(int newWidth, int contentLeft) { @@ -34,16 +75,22 @@ void InnerWidget::resizeToWidth(int newWidth, int contentLeft) { int InnerWidget::resizeGetHeight(int newWidth, int contentLeft) { int result = 0; - //if (_cover) { - // result += _cover->height(); - //} - //for_const (auto blockData, _blocks) { - // if (blockData->isHidden()) { - // continue; - // } + if (_cover) { + _cover->setContentLeft(contentLeft); + _cover->resizeToWidth(newWidth); + result += _cover->height(); + } + result += st::settingsBlocksTop; + for_const (auto block, _blocks) { + if (block->isHidden()) { + continue; + } - // result += blockData->height(); - //} + block->moveToLeft(0, result); + block->setContentLeft(contentLeft); + block->resizeToWidth(newWidth); + result += block->height(); + } return result; } @@ -51,10 +98,10 @@ void InnerWidget::setVisibleTopBottom(int visibleTop, int visibleBottom) { _visibleTop = visibleTop; _visibleBottom = visibleBottom; - //for_const (auto blockData, _blocks) { - // int blockY = blockData->y(); - // blockData->setVisibleTopBottom(visibleTop - blockY, visibleBottom - blockY); - //} + for_const (auto block, _blocks) { + int blockY = block->y(); + block->setVisibleTopBottom(visibleTop - blockY, visibleBottom - blockY); + } } } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_inner_widget.h b/Telegram/SourceFiles/settings/settings_inner_widget.h index cb21d3112..658e3d47a 100644 --- a/Telegram/SourceFiles/settings/settings_inner_widget.h +++ b/Telegram/SourceFiles/settings/settings_inner_widget.h @@ -35,13 +35,19 @@ public: // Updates the area that is visible inside the scroll container. void setVisibleTopBottom(int visibleTop, int visibleBottom); + void showFinished(); + private: + void refreshBlocks(); + // Resizes content and counts natural widget height for the desired width. int resizeGetHeight(int newWidth, int contentLeft); ChildWidget _cover = { nullptr }; QList _blocks; + UserData *_self = nullptr; + int _visibleTop = 0; int _visibleBottom = 0; diff --git a/Telegram/SourceFiles/settings/settings_notifications_widget.cpp b/Telegram/SourceFiles/settings/settings_notifications_widget.cpp new file mode 100644 index 000000000..bfa5a108c --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_notifications_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_notifications_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +NotificationsWidget::NotificationsWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_notify)) { + refreshControls(); +} + +void NotificationsWidget::refreshControls() { +} + +int NotificationsWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_notifications_widget.h b/Telegram/SourceFiles/settings/settings_notifications_widget.h new file mode 100644 index 000000000..502f338b0 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_notifications_widget.h @@ -0,0 +1,40 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +namespace Settings { + +class NotificationsWidget : public BlockWidget { +public: + NotificationsWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + void refreshControls(); + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_privacy_widget.cpp b/Telegram/SourceFiles/settings/settings_privacy_widget.cpp new file mode 100644 index 000000000..91933504f --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_privacy_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_privacy_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +PrivacyWidget::PrivacyWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_privacy)) { + refreshControls(); +} + +void PrivacyWidget::refreshControls() { +} + +int PrivacyWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_privacy_widget.h b/Telegram/SourceFiles/settings/settings_privacy_widget.h new file mode 100644 index 000000000..256a882a8 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_privacy_widget.h @@ -0,0 +1,40 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +namespace Settings { + +class PrivacyWidget : public BlockWidget { +public: + PrivacyWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + void refreshControls(); + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_scale_widget.cpp b/Telegram/SourceFiles/settings/settings_scale_widget.cpp new file mode 100644 index 000000000..849951b33 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_scale_widget.cpp @@ -0,0 +1,43 @@ +/* +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 "settings/settings_scale_widget.h" + +#include "styles/style_settings.h" +#include "lang.h" + +namespace Settings { + +ScaleWidget::ScaleWidget(QWidget *parent, UserData *self) : BlockWidget(parent, self, lang(lng_settings_section_scale)) { + refreshControls(); +} + +void ScaleWidget::refreshControls() { +} + +int ScaleWidget::resizeGetHeight(int newWidth) { + int newHeight = contentTop(); + + newHeight += st::settingsBlockMarginBottom; + return newHeight; +} + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_scale_widget.h b/Telegram/SourceFiles/settings/settings_scale_widget.h new file mode 100644 index 000000000..a36ee7552 --- /dev/null +++ b/Telegram/SourceFiles/settings/settings_scale_widget.h @@ -0,0 +1,40 @@ +/* +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 +*/ +#pragma once + +#include "settings/settings_block_widget.h" + +namespace Settings { + +class ScaleWidget : public BlockWidget { +public: + ScaleWidget(QWidget *parent, UserData *self); + +protected: + // Resizes content and counts natural widget height for the desired width. + int resizeGetHeight(int newWidth) override; + +private: + void refreshControls(); + +}; + +} // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_widget.cpp b/Telegram/SourceFiles/settings/settings_widget.cpp index a1cfc4a6a..c24625b19 100644 --- a/Telegram/SourceFiles/settings/settings_widget.cpp +++ b/Telegram/SourceFiles/settings/settings_widget.cpp @@ -41,6 +41,7 @@ Widget::Widget() : LayerWidget() _fixedBar->move(0, 0); _fixedBarShadow1->move(0, _fixedBar->y() + st::settingsFixedBarHeight); _fixedBarShadow2->move(0, _fixedBarShadow1->y() + st::lineWidth); + _scroll->move(0, st::settingsFixedBarHeight); } void Widget::parentResized() { @@ -84,6 +85,10 @@ void Widget::parentResized() { update(); } +void Widget::showDone() { + _inner->showFinished(); +} + void Widget::paintEvent(QPaintEvent *e) { Painter p(this); p.fillRect(rect(), st::windowBg); diff --git a/Telegram/SourceFiles/settings/settings_widget.h b/Telegram/SourceFiles/settings/settings_widget.h index d729fbab0..34757f001 100644 --- a/Telegram/SourceFiles/settings/settings_widget.h +++ b/Telegram/SourceFiles/settings/settings_widget.h @@ -32,6 +32,7 @@ public: Widget(); void parentResized() override; + void showDone() override; protected: void paintEvent(QPaintEvent *e) override; diff --git a/Telegram/SourceFiles/settingswidget.cpp b/Telegram/SourceFiles/settingswidget.cpp index 2aeac5548..8dca3ec10 100644 --- a/Telegram/SourceFiles/settingswidget.cpp +++ b/Telegram/SourceFiles/settingswidget.cpp @@ -450,7 +450,7 @@ void SettingsInner::paintEvent(QPaintEvent *e) { // contact info p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); - p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_contact_info)); +// p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_contact_info)); top += st::setHeaderSkip; p.setFont(st::linkFont->f); @@ -520,7 +520,7 @@ void SettingsInner::paintEvent(QPaintEvent *e) { if (!cRetina()) { p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); - p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_scale_label)); +// p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_scale_label)); top += st::setHeaderSkip; top += _dpiAutoScale.height() + st::setLittleSkip; @@ -547,7 +547,7 @@ void SettingsInner::paintEvent(QPaintEvent *e) { // chat options p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); - p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_chat)); +// p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_chat)); top += st::setHeaderSkip; top += _replaceEmojis.height() + st::setLittleSkip; @@ -581,7 +581,7 @@ void SettingsInner::paintEvent(QPaintEvent *e) { // local storage p.setFont(st::setHeaderFont->f); p.setPen(st::setHeaderColor->p); - p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_cache)); +// p.drawText(_left + st::setHeaderLeft, top + st::setHeaderTop + st::setHeaderFont->ascent, lang(lng_settings_section_cache)); p.setFont(st::linkFont->f); p.setPen(st::black->p); diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index 01b17232b..cbf8f386d 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -332,10 +332,30 @@ '<(src_loc)/serialize/serialize_common.h', '<(src_loc)/serialize/serialize_document.cpp', '<(src_loc)/serialize/serialize_document.h', + '<(src_loc)/settings/settings_advanced_widget.cpp', + '<(src_loc)/settings/settings_advanced_widget.h', + '<(src_loc)/settings/settings_background_widget.cpp', + '<(src_loc)/settings/settings_background_widget.h', + '<(src_loc)/settings/settings_block_widget.cpp', + '<(src_loc)/settings/settings_block_widget.h', + '<(src_loc)/settings/settings_chat_settings_widget.cpp', + '<(src_loc)/settings/settings_chat_settings_widget.h', + '<(src_loc)/settings/settings_cover.cpp', + '<(src_loc)/settings/settings_cover.h', '<(src_loc)/settings/settings_fixed_bar.cpp', '<(src_loc)/settings/settings_fixed_bar.h', + '<(src_loc)/settings/settings_general_widget.cpp', + '<(src_loc)/settings/settings_general_widget.h', + '<(src_loc)/settings/settings_info_widget.cpp', + '<(src_loc)/settings/settings_info_widget.h', '<(src_loc)/settings/settings_inner_widget.cpp', '<(src_loc)/settings/settings_inner_widget.h', + '<(src_loc)/settings/settings_notifications_widget.cpp', + '<(src_loc)/settings/settings_notifications_widget.h', + '<(src_loc)/settings/settings_privacy_widget.cpp', + '<(src_loc)/settings/settings_privacy_widget.h', + '<(src_loc)/settings/settings_scale_widget.cpp', + '<(src_loc)/settings/settings_scale_widget.h', '<(src_loc)/settings/settings_widget.cpp', '<(src_loc)/settings/settings_widget.h', '<(src_loc)/ui/buttons/history_down_button.cpp',