diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index f4b50b354..b4773f00a 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -251,8 +251,6 @@ PRIVATE boxes/peer_lists_box.h boxes/passcode_box.cpp boxes/passcode_box.h - boxes/photo_crop_box.cpp - boxes/photo_crop_box.h boxes/rate_call_box.cpp boxes/rate_call_box.h boxes/self_destruction_box.cpp diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 92cfdf6aa..b81576845 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/openssl_help.h" #include "boxes/confirm_box.h" #include "boxes/confirm_phone_box.h" // ExtractPhonePrefix. -#include "boxes/photo_crop_box.h" #include "boxes/peer_list_controllers.h" #include "boxes/peers/add_participants_box.h" #include "boxes/peers/edit_participant_box.h" diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index a8d865948..dbf4384fb 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -76,10 +76,6 @@ defaultFeedUserpicButton: FeedUserpicButton { innerPart: defaultUserpicButton; } -cropPointSize: 10px; -cropSkip: 13px; -cropMinSize: 20px; - confirmInviteTitle: FlatLabel(defaultFlatLabel) { align: align(center); minWidth: 320px; diff --git a/Telegram/SourceFiles/boxes/photo_crop_box.cpp b/Telegram/SourceFiles/boxes/photo_crop_box.cpp deleted file mode 100644 index 918b9a41b..000000000 --- a/Telegram/SourceFiles/boxes/photo_crop_box.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "boxes/photo_crop_box.h" - -#include "lang/lang_keys.h" -#include "ui/widgets/buttons.h" -#include "ui/ui_utility.h" -#include "app.h" -#include "styles/style_layers.h" -#include "styles/style_boxes.h" - -PhotoCropBox::PhotoCropBox( - QWidget*, - const QImage &img, - const QString &title) -: _title(title) -, _img(img) { -} - -void PhotoCropBox::prepare() { - addButton(tr::lng_settings_save(), [this] { sendPhoto(); }); - addButton(tr::lng_cancel(), [this] { closeBox(); }); - - int32 s = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(); - _thumb = App::pixmapFromImageInPlace(_img.scaled(s * cIntRetinaFactor(), s * cIntRetinaFactor(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - _thumb.setDevicePixelRatio(cRetinaFactor()); - _mask = QImage(_thumb.size(), QImage::Format_ARGB32_Premultiplied); - _mask.setDevicePixelRatio(cRetinaFactor()); - _fade = QImage(_thumb.size(), QImage::Format_ARGB32_Premultiplied); - _fade.setDevicePixelRatio(cRetinaFactor()); - _thumbw = _thumb.width() / cIntRetinaFactor(); - _thumbh = _thumb.height() / cIntRetinaFactor(); - if (_thumbw > _thumbh) { - _cropw = _thumbh - 20; - } else { - _cropw = _thumbw - 20; - } - _cropx = (_thumbw - _cropw) / 2; - _cropy = (_thumbh - _cropw) / 2; - - _thumbx = (st::boxWideWidth - _thumbw) / 2; - _thumby = st::boxPhotoPadding.top(); - setMouseTracking(true); - - setDimensions(st::boxWideWidth, st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxTextFont->height + st::cropSkip); -} - -void PhotoCropBox::mousePressEvent(QMouseEvent *e) { - if (e->button() == Qt::LeftButton) { - _downState = mouseState(e->pos()); - _fromposx = e->pos().x(); - _fromposy = e->pos().y(); - _fromcropx = _cropx; - _fromcropy = _cropy; - _fromcropw = _cropw; - } - return BoxContent::mousePressEvent(e); -} - -int PhotoCropBox::mouseState(QPoint p) { - p -= QPoint(_thumbx, _thumby); - int32 delta = st::cropPointSize, mdelta(-delta / 2); - if (QRect(_cropx + mdelta, _cropy + mdelta, delta, delta).contains(p)) { - return 1; - } else if (QRect(_cropx + _cropw + mdelta, _cropy + mdelta, delta, delta).contains(p)) { - return 2; - } else if (QRect(_cropx + _cropw + mdelta, _cropy + _cropw + mdelta, delta, delta).contains(p)) { - return 3; - } else if (QRect(_cropx + mdelta, _cropy + _cropw + mdelta, delta, delta).contains(p)) { - return 4; - } else if (QRect(_cropx, _cropy, _cropw, _cropw).contains(p)) { - return 5; - } - return 0; -} - -rpl::producer PhotoCropBox::ready() const { - return _readyImages.events(); -} - -void PhotoCropBox::mouseReleaseEvent(QMouseEvent *e) { - if (_downState) { - _downState = 0; - mouseMoveEvent(e); - } -} - -void PhotoCropBox::mouseMoveEvent(QMouseEvent *e) { - if (_downState && !(e->buttons() & Qt::LeftButton)) { - mouseReleaseEvent(e); - } - if (_downState) { - if (_downState == 1) { - int32 dx = e->pos().x() - _fromposx, dy = e->pos().y() - _fromposy, d = (dx < dy) ? dx : dy; - if (_fromcropx + d < 0) { - d = -_fromcropx; - } - if (_fromcropy + d < 0) { - d = -_fromcropy; - } - if (_fromcropw - d < st::cropMinSize) { - d = _fromcropw - st::cropMinSize; - } - if (_cropx != _fromcropx + d || _cropy != _fromcropy + d || _cropw != _fromcropw - d) { - _cropx = _fromcropx + d; - _cropy = _fromcropy + d; - _cropw = _fromcropw - d; - update(); - } - } else if (_downState == 2) { - int32 dx = _fromposx - e->pos().x(), dy = e->pos().y() - _fromposy, d = (dx < dy) ? dx : dy; - if (_fromcropx + _fromcropw - d > _thumbw) { - d = _fromcropx + _fromcropw - _thumbw; - } - if (_fromcropy + d < 0) { - d = -_fromcropy; - } - if (_fromcropw - d < st::cropMinSize) { - d = _fromcropw - st::cropMinSize; - } - if (_cropy != _fromcropy + d || _cropw != _fromcropw - d) { - _cropy = _fromcropy + d; - _cropw = _fromcropw - d; - update(); - } - } else if (_downState == 3) { - int32 dx = _fromposx - e->pos().x(), dy = _fromposy - e->pos().y(), d = (dx < dy) ? dx : dy; - if (_fromcropx + _fromcropw - d > _thumbw) { - d = _fromcropx + _fromcropw - _thumbw; - } - if (_fromcropy + _fromcropw - d > _thumbh) { - d = _fromcropy + _fromcropw - _thumbh; - } - if (_fromcropw - d < st::cropMinSize) { - d = _fromcropw - st::cropMinSize; - } - if (_cropw != _fromcropw - d) { - _cropw = _fromcropw - d; - update(); - } - } else if (_downState == 4) { - int32 dx = e->pos().x() - _fromposx, dy = _fromposy - e->pos().y(), d = (dx < dy) ? dx : dy; - if (_fromcropx + d < 0) { - d = -_fromcropx; - } - if (_fromcropy + _fromcropw - d > _thumbh) { - d = _fromcropy + _fromcropw - _thumbh; - } - if (_fromcropw - d < st::cropMinSize) { - d = _fromcropw - st::cropMinSize; - } - if (_cropx != _fromcropx + d || _cropw != _fromcropw - d) { - _cropx = _fromcropx + d; - _cropw = _fromcropw - d; - update(); - } - } else if (_downState == 5) { - int32 dx = e->pos().x() - _fromposx, dy = e->pos().y() - _fromposy; - if (_fromcropx + dx < 0) { - dx = -_fromcropx; - } else if (_fromcropx + _fromcropw + dx > _thumbw) { - dx = _thumbw - _fromcropx - _fromcropw; - } - if (_fromcropy + dy < 0) { - dy = -_fromcropy; - } else if (_fromcropy + _fromcropw + dy > _thumbh) { - dy = _thumbh - _fromcropy - _fromcropw; - } - if (_cropx != _fromcropx + dx || _cropy != _fromcropy + dy) { - _cropx = _fromcropx + dx; - _cropy = _fromcropy + dy; - update(); - } - } - } - int32 cursorState = _downState ? _downState : mouseState(e->pos()); - QCursor cur(style::cur_default); - if (cursorState == 1 || cursorState == 3) { - cur = style::cur_sizefdiag; - } else if (cursorState == 2 || cursorState == 4) { - cur = style::cur_sizebdiag; - } else if (cursorState == 5) { - cur = style::cur_sizeall; - } - setCursor(cur); -} - -void PhotoCropBox::keyPressEvent(QKeyEvent *e) { - if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) { - sendPhoto(); - } else { - BoxContent::keyPressEvent(e); - } -} - -void PhotoCropBox::paintEvent(QPaintEvent *e) { - BoxContent::paintEvent(e); - - Painter p(this); - - p.setFont(st::boxTextFont); - p.setPen(st::boxPhotoTextFg); - p.drawText(QRect(st::boxPhotoPadding.left(), st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom(), width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(), st::boxTextFont->height), _title, style::al_top); - - p.translate(_thumbx, _thumby); - p.drawPixmap(0, 0, _thumb); - _mask.fill(Qt::white); - { - Painter p(&_mask); - PainterHighQualityEnabler hq(p); - - p.setPen(Qt::NoPen); - p.setBrush(Qt::black); - p.drawEllipse(_cropx, _cropy, _cropw, _cropw); - } - style::colorizeImage(_mask, st::photoCropFadeBg->c, &_fade); - p.drawImage(0, 0, _fade); - - int delta = st::cropPointSize; - int mdelta = -delta / 2; - p.fillRect(QRect(_cropx + mdelta, _cropy + mdelta, delta, delta), st::photoCropPointFg); - p.fillRect(QRect(_cropx + _cropw + mdelta, _cropy + mdelta, delta, delta), st::photoCropPointFg); - p.fillRect(QRect(_cropx + _cropw + mdelta, _cropy + _cropw + mdelta, delta, delta), st::photoCropPointFg); - p.fillRect(QRect(_cropx + mdelta, _cropy + _cropw + mdelta, delta, delta), st::photoCropPointFg); -} - -void PhotoCropBox::sendPhoto() { - auto from = _img; - if (_img.width() < _thumb.width()) { - from = _thumb.toImage(); - } - float64 x = float64(_cropx) / _thumbw, y = float64(_cropy) / _thumbh, w = float64(_cropw) / _thumbw; - int32 ix = int32(x * from.width()), iy = int32(y * from.height()), iw = int32(w * from.width()); - if (ix < 0) { - ix = 0; - } - if (ix + iw > from.width()) { - iw = from.width() - ix; - } - if (iy < 0) { - iy = 0; - } - if (iy + iw > from.height()) { - iw = from.height() - iy; - } - int32 offset = ix * from.depth() / 8 + iy * from.bytesPerLine(); - QImage cropped(from.constBits() + offset, iw, iw, from.bytesPerLine(), from.format()), tosend; - if (from.format() == QImage::Format_Indexed8) { - cropped.setColorCount(from.colorCount()); - cropped.setColorTable(from.colorTable()); - } - if (cropped.width() > 1280) { - tosend = cropped.scaled(1280, 1280, Qt::KeepAspectRatio, Qt::SmoothTransformation); - } else if (cropped.width() < 320) { - tosend = cropped.scaled(320, 320, Qt::KeepAspectRatio, Qt::SmoothTransformation); - } else { - tosend = cropped.copy(); - } - - auto weak = Ui::MakeWeak(this); - _readyImages.fire(std::move(tosend)); - if (weak) { - closeBox(); - } -} diff --git a/Telegram/SourceFiles/boxes/photo_crop_box.h b/Telegram/SourceFiles/boxes/photo_crop_box.h deleted file mode 100644 index 32ee55629..000000000 --- a/Telegram/SourceFiles/boxes/photo_crop_box.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "boxes/abstract_box.h" - -class PhotoCropBox : public Ui::BoxContent { -public: - PhotoCropBox(QWidget*, const QImage &img, const QString &title); - - int32 mouseState(QPoint p); - - rpl::producer ready() const; - -protected: - void prepare() override; - - void keyPressEvent(QKeyEvent *e) override; - void paintEvent(QPaintEvent *e) override; - void mousePressEvent(QMouseEvent *e) override; - void mouseReleaseEvent(QMouseEvent *e) override; - void mouseMoveEvent(QMouseEvent *e) override; - -private: - void sendPhoto(); - - QString _title; - int32 _downState = 0; - int32 _thumbx, _thumby, _thumbw, _thumbh; - int32 _cropx, _cropy, _cropw; - int32 _fromposx, _fromposy, _fromcropx, _fromcropy, _fromcropw; - QImage _img; - QPixmap _thumb; - QImage _mask, _fade; - rpl::event_stream _readyImages; - -}; diff --git a/Telegram/SourceFiles/editor/editor.style b/Telegram/SourceFiles/editor/editor.style index b24cc28e5..c143feeca 100644 --- a/Telegram/SourceFiles/editor/editor.style +++ b/Telegram/SourceFiles/editor/editor.style @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ using "ui/basic.style"; -using "boxes/boxes.style"; using "ui/widgets/widgets.style"; using "ui/chat/chat.style"; @@ -55,3 +54,5 @@ photoEditorColorPickerCircleBigSize: 50px; photoEditorColorPickerCircleSkip: 50px; +photoEditorCropPointSize: 10px; +photoEditorCropMinSize: 20px; diff --git a/Telegram/SourceFiles/editor/editor_crop.cpp b/Telegram/SourceFiles/editor/editor_crop.cpp index c9cef08a9..7ef26b1f3 100644 --- a/Telegram/SourceFiles/editor/editor_crop.cpp +++ b/Telegram/SourceFiles/editor/editor_crop.cpp @@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "editor/editor_crop.h" -#include "styles/style_boxes.h" +#include "styles/style_editor.h" namespace Editor { namespace { @@ -47,7 +47,7 @@ Crop::Crop( const QSize &imageSize, EditorData data) : RpWidget(parent) -, _pointSize(st::cropPointSize) +, _pointSize(st::photoEditorCropPointSize) , _pointSizeH(_pointSize / 2.) , _innerMargins(QMarginsF(_pointSizeH, _pointSizeH, _pointSizeH, _pointSizeH) .toMargins()) @@ -108,7 +108,7 @@ void Crop::applyTransform( -cropHolderRotated.y() + _offset.y()); // Check boundaries. - const auto min = float64(st::cropMinSize); + const auto min = float64(st::photoEditorCropMinSize); if ((cropPaint.width() < min) || (cropPaint.height() < min)) { cropPaint.setWidth(std::max(min, cropPaint.width())); cropPaint.setHeight(std::max(min, cropPaint.height())); @@ -268,7 +268,7 @@ void Crop::performCrop(const QPoint &pos) { : QPoint(diff.y() * diffSign, diff.y()); } - const auto &minSize = st::cropMinSize; + const auto &minSize = st::photoEditorCropMinSize; const auto xMin = int(xFactor * crop.width() - xFactor * minSize * ((cropRatio > 1.) ? cropRatio : 1.)); const auto yMin = int(yFactor * crop.height() diff --git a/Telegram/SourceFiles/editor/editor_paint.cpp b/Telegram/SourceFiles/editor/editor_paint.cpp index 39ef644f2..48cea69b1 100644 --- a/Telegram/SourceFiles/editor/editor_paint.cpp +++ b/Telegram/SourceFiles/editor/editor_paint.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "editor/undo_controller.h" #include "base/event_filter.h" -#include "styles/style_boxes.h" #include #include diff --git a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp index 598b7b825..4507da66f 100644 --- a/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp +++ b/Telegram/SourceFiles/editor/photo_editor_layer_widget.cpp @@ -14,7 +14,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/attach/attach_prepare.h" #include "window/window_controller.h" #include "window/window_session_controller.h" -#include "styles/style_boxes.h" namespace Editor { namespace { diff --git a/Telegram/SourceFiles/intro/intro_signup.cpp b/Telegram/SourceFiles/intro/intro_signup.cpp index 6f654d9e3..f747a0983 100644 --- a/Telegram/SourceFiles/intro/intro_signup.cpp +++ b/Telegram/SourceFiles/intro/intro_signup.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "intro/intro_widget.h" #include "core/file_utilities.h" -#include "boxes/photo_crop_box.h" #include "boxes/confirm_box.h" #include "lang/lang_keys.h" #include "ui/widgets/buttons.h" diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 0bd2eb91c..d672ef56e 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -23,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/add_contact_box.h" #include "boxes/confirm_box.h" #include "boxes/change_phone_box.h" -#include "boxes/photo_crop_box.h" #include "boxes/username_box.h" #include "data/data_user.h" #include "info/profile/info_profile_values.h" diff --git a/Telegram/SourceFiles/ui/special_buttons.cpp b/Telegram/SourceFiles/ui/special_buttons.cpp index 0dc4db565..f9b06ec7f 100644 --- a/Telegram/SourceFiles/ui/special_buttons.cpp +++ b/Telegram/SourceFiles/ui/special_buttons.cpp @@ -27,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "core/file_utilities.h" #include "core/application.h" -#include "boxes/photo_crop_box.h" #include "boxes/confirm_box.h" #include "editor/photo_editor_layer_widget.h" #include "media/streaming/media_streaming_instance.h"