From 9390450049e8263290ca8033bc68a16a9ac93af7 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 15 Jan 2023 05:39:15 +0300 Subject: [PATCH] Moved out color editor to td_ui. --- Telegram/CMakeLists.txt | 2 -- .../SourceFiles/settings/settings_chat.cpp | 2 +- .../widgets/color_editor.cpp} | 22 +++++++++---------- .../widgets/color_editor.h} | 0 .../window/themes/window_theme_editor.cpp | 2 +- .../themes/window_theme_editor_block.cpp | 2 +- Telegram/cmake/td_ui.cmake | 2 ++ 7 files changed, 16 insertions(+), 16 deletions(-) rename Telegram/SourceFiles/{boxes/edit_color_box.cpp => ui/widgets/color_editor.cpp} (97%) rename Telegram/SourceFiles/{boxes/edit_color_box.h => ui/widgets/color_editor.h} (100%) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 0c7640276..633722197 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -243,8 +243,6 @@ PRIVATE boxes/download_path_box.h boxes/edit_caption_box.cpp boxes/edit_caption_box.h - boxes/edit_color_box.cpp - boxes/edit_color_box.h boxes/edit_privacy_box.cpp boxes/edit_privacy_box.h boxes/gift_premium_box.cpp diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index b9f227aac..883ea4f9c 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -18,11 +18,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/background_preview_box.h" #include "boxes/download_path_box.h" #include "boxes/local_storage_box.h" -#include "boxes/edit_color_box.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/checkbox.h" +#include "ui/widgets/color_editor.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/chat/attach/attach_extensions.h" diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/ui/widgets/color_editor.cpp similarity index 97% rename from Telegram/SourceFiles/boxes/edit_color_box.cpp rename to Telegram/SourceFiles/ui/widgets/color_editor.cpp index fde0ed2b6..0b7593c86 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/ui/widgets/color_editor.cpp @@ -5,7 +5,7 @@ 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/edit_color_box.h" +#include "ui/widgets/color_editor.h" #include "lang/lang_keys.h" #include "ui/widgets/shadow.h" @@ -69,8 +69,8 @@ QCursor ColorEditor::Picker::generateCursor() { auto diameter = style::ConvertScale(16); auto line = style::ConvertScale(1); auto size = ((diameter + 2 * line) >= 32) ? 64 : 32; - auto cursor = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - cursor.setDevicePixelRatio(cRetinaFactor()); + auto cursor = QImage(QSize(size, size) * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); + cursor.setDevicePixelRatio(style::DevicePixelRatio()); cursor.fill(Qt::transparent); { auto p = QPainter(&cursor); @@ -97,7 +97,7 @@ ColorEditor::Picker::Picker(QWidget *parent, Mode mode, QColor color) auto size = QSize(st::colorPickerSize, st::colorPickerSize); resize(size); - _palette = QImage(size * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); + _palette = QImage(size * style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); setFromColor(color); } @@ -149,7 +149,7 @@ void ColorEditor::Picker::preparePalette() { } else { preparePaletteHSL(); } - _palette.setDevicePixelRatio(cRetinaFactor()); + _palette.setDevicePixelRatio(style::DevicePixelRatio()); } void ColorEditor::Picker::preparePaletteRGBA() { @@ -400,9 +400,9 @@ void ColorEditor::Slider::mouseReleaseEvent(QMouseEvent *e) { } void ColorEditor::Slider::generatePixmap() { - auto size = (isHorizontal() ? width() : height()) * cIntRetinaFactor(); - auto image = QImage(size, cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); - image.setDevicePixelRatio(cRetinaFactor()); + auto size = (isHorizontal() ? width() : height()) * style::DevicePixelRatio(); + auto image = QImage(size, style::DevicePixelRatio(), QImage::Format_ARGB32_Premultiplied); + image.setDevicePixelRatio(style::DevicePixelRatio()); auto ints = reinterpret_cast(image.bits()); auto intsPerLine = image.bytesPerLine() / sizeof(uint32); auto intsPerLineAdded = intsPerLine - size; @@ -415,7 +415,7 @@ void ColorEditor::Slider::generatePixmap() { for (auto x = 0; x != size; ++x) { const auto color = QColor::fromHsv(x * 360 / size, 255, 255); const auto value = anim::getPremultiplied(color.toRgb()); - for (auto y = 0; y != cIntRetinaFactor(); ++y) { + for (auto y = 0; y != style::DevicePixelRatio(); ++y) { ints[y * intsPerLine] = value; } ++ints; @@ -427,7 +427,7 @@ void ColorEditor::Slider::generatePixmap() { } else if (_type == Type::Opacity) { auto color = anim::shifted(QColor(255, 255, 255, 255)); auto transparent = anim::shifted(QColor(255, 255, 255, 0)); - for (auto y = 0; y != cIntRetinaFactor(); ++y) { + for (auto y = 0; y != style::DevicePixelRatio(); ++y) { auto x_accumulated = 0; for (auto x = 0; x != size; ++x, x_accumulated += part) { auto x_ratio = x_accumulated >> (LargeBit - 8); @@ -451,7 +451,7 @@ void ColorEditor::Slider::generatePixmap() { _color.hslSaturation(), _lightnessMin + x * range / size); const auto value = anim::getPremultiplied(color.toRgb()); - for (auto y = 0; y != cIntRetinaFactor(); ++y) { + for (auto y = 0; y != style::DevicePixelRatio(); ++y) { ints[y * intsPerLine] = value; } ++ints; diff --git a/Telegram/SourceFiles/boxes/edit_color_box.h b/Telegram/SourceFiles/ui/widgets/color_editor.h similarity index 100% rename from Telegram/SourceFiles/boxes/edit_color_box.h rename to Telegram/SourceFiles/ui/widgets/color_editor.h diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index c97a38946..613006078 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "storage/localstorage.h" #include "ui/boxes/confirm_box.h" +#include "ui/widgets/color_editor.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" @@ -32,7 +33,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/call_delayed.h" #include "core/file_utilities.h" #include "core/application.h" -#include "boxes/edit_color_box.h" #include "lang/lang_keys.h" #include "styles/style_window.h" #include "styles/style_dialogs.h" diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp index baac02a9e..24a4b8e7d 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_block.cpp @@ -9,11 +9,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/call_delayed.h" #include "boxes/abstract_box.h" -#include "boxes/edit_color_box.h" #include "lang/lang_keys.h" #include "ui/effects/ripple_animation.h" #include "ui/layers/generic_box.h" #include "ui/painter.h" +#include "ui/widgets/color_editor.h" #include "ui/widgets/shadow.h" #include "styles/style_layers.h" #include "styles/style_window.h" diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index dc968acab..c4765ba4f 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -264,6 +264,8 @@ PRIVATE ui/text/text_options.cpp ui/text/text_options.h + ui/widgets/color_editor.cpp + ui/widgets/color_editor.h ui/widgets/continuous_sliders.cpp ui/widgets/continuous_sliders.h ui/widgets/discrete_sliders.cpp