Skip to content

Commit

Permalink
chore: update translation
Browse files Browse the repository at this point in the history
as title

Log: update translation
  • Loading branch information
Lighto-Ku committed Dec 24, 2024
1 parent 499d74c commit 72929d3
Show file tree
Hide file tree
Showing 28 changed files with 1,597 additions and 1,461 deletions.
57 changes: 0 additions & 57 deletions include/dfm-base/dfm_global_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,59 +26,6 @@ enum class ViewMode {
kAllViewMode = kIconMode | kListMode | kExtendMode
};

// view defines
inline constexpr int kIconSizeMax { 512 };
inline constexpr int kIconSizeMin { 24 };
inline constexpr int kIconSizeMiddle { 192 };
inline constexpr int kIconSizeNormalStep { 8 };
inline constexpr int kIconSizeLargeStep { 16 };
inline constexpr int kIconGridDensityMin { 60 };
inline constexpr int kIconGridDensityMax { 198 };
inline constexpr int kIconGridDensityStep { 6 };

inline QList<int> kIconSizeList()
{
static const QList<int> sizes = []() {
QList<int> list;
list.reserve(42); // 22(first range) + 20(second range) = 42
// range 24-192, step size 8
int size = kIconSizeMin;
while (size <= kIconSizeMiddle) {
list.append(size);
size += kIconSizeNormalStep;
}
// range 192-512, step size 16
size = kIconSizeMiddle + kIconSizeLargeStep;
while (size <= kIconSizeMax) {
list.append(size);
size += kIconSizeLargeStep;
}
return list;
}();
return sizes;
}

inline QList<int> kIconGridDensity()
{
static const QList<int> widths = []() {
QList<int> list;
list.reserve(24); // pre-allocate memory to avoid multiple reallocations
int size = kIconGridDensityMin;
while (size <= kIconGridDensityMax) {
list.append(size);
size += kIconGridDensityStep;
}
return list;
}();
return widths;
}

inline QList<int> kListHeight()
{
static const QList<int> heights { 24, 32, 48 };
return heights;
}

enum class TransparentStatus : uint8_t {
kDefault,
kTransparent,
Expand Down Expand Up @@ -252,10 +199,6 @@ inline constexpr char kDesktopLoadFilesTime[] { "LoadFilesTime" };
inline constexpr char kDesktopLoadFilesCount[] { "LoadFilesCount" };
} // namespace DataPersistence

namespace SettingDialog {
inline constexpr char kSettingSliderItem[] { "sliderWithSideIcon" };
} // namespace SettingDialog

} // namespace Global
} // namespace dfmbase

Expand Down
1 change: 1 addition & 0 deletions include/dfm-base/settingdialog/settingjsongenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SettingJsonGenerator
bool addCheckBoxConfig(const QString &key, const QString &text, bool defaultVal = true);
bool addComboboxConfig(const QString &key, const QString &name, const QStringList &options, int defaultVal = 0);
bool addComboboxConfig(const QString &key, const QString &name, const QVariantMap &options, QVariant defaultVal = QVariant());
bool addSliderConfig(const QString &key, const QString &name, int maxVal, int minVal, int defaultVal = 0);
bool addSliderConfig(const QString &key, const QString &name, const QString &leftIcon, const QString &rightIcon, int maxVal, int minVal, int defaultVal = 0);

protected:
Expand Down
10 changes: 0 additions & 10 deletions src/dfm-base/base/configs/dconfig/global_dconf_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ inline constexpr char kDisplayPreviewVisibleKey[] { "dfm.displaypreview.visible"
inline constexpr char kOpenFolderWindowsInASeparateProcess[] { "dfm.open.in.single.process" };
} // namespace BaseConfig

/*!
* \brief 视图相关配置项
*/
namespace ViewConfig {
inline constexpr char kIconSizeLevel[] { "dfm.icon.size.level" };
inline constexpr char kIconGridDensityLevel[] { "dfm.icon.griddensity.level" };
inline constexpr char kListHeightLevel[] { "dfm.list.height.level" };
} // namespace ViewConfig


/*!
* \brief 动画相关配置项
*/
Expand Down
53 changes: 10 additions & 43 deletions src/dfm-base/base/configs/settingbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <dfm-base/settingdialog/settingjsongenerator.h>

Check warning on line 9 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/settingdialog/settingjsongenerator.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/settingdialog/settingjsongenerator.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/settingdialog/customsettingitemregister.h>

Check warning on line 10 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/settingdialog/customsettingitemregister.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/settingdialog/customsettingitemregister.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/dfm_global_defines.h>

Check warning on line 11 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/dfm_global_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 11 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/dfm_global_defines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/utils/viewdefines.h>

Check warning on line 12 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/utils/viewdefines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 12 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/utils/viewdefines.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DSettings>

Check warning on line 14 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DLabel>

Check warning on line 15 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DLabel> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in src/dfm-base/base/configs/settingbackend.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DLabel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
Expand Down Expand Up @@ -220,9 +221,6 @@ void SettingBackend::onValueChanged(int attribute, const QVariant &value)

void SettingBackend::initPresetSettingConfig()
{
// register custom setting item type
CustomSettingItemRegister::instance()->registCustomSettingItemType(SettingDialog::kSettingSliderItem, &SettingBackend::createSliderWithSideIcon);

initBasicSettingConfig();
initWorkspaceSettingConfig();
initAdvanceSettingConfig();
Expand Down Expand Up @@ -327,7 +325,9 @@ void SettingBackend::initWorkspaceSettingConfig()
ins->addGroup(TOP_GROUP_WORKSPACE, tr("Workspace"));
ins->addGroup(LV2_GROUP_VIEW, tr("View"));

int iconSizeLevelMax = Global::kIconSizeList().size() - 1;
ViewDefines viewDefines;

int iconSizeLevelMax = viewDefines.iconSizeCount() - 1;
int iconSizeLevelMin = 0;
ins->addSliderConfig(LV2_GROUP_VIEW ".00_icon_size",
tr("Default icon size:"),
Expand All @@ -336,7 +336,7 @@ void SettingBackend::initWorkspaceSettingConfig()
iconSizeLevelMax,
iconSizeLevelMin,
5);
int iconGridDensityLevelMax = Global::kIconGridDensity().size() - 1;
int iconGridDensityLevelMax = viewDefines.iconGridDensityCount() - 1;
int iconGridDensityLevelMin = 0;
ins->addSliderConfig(LV2_GROUP_VIEW ".01_icon_grid_density",
tr("Default icon grid density:"),
Expand All @@ -345,7 +345,7 @@ void SettingBackend::initWorkspaceSettingConfig()
iconGridDensityLevelMax,
iconGridDensityLevelMin,
2);
int listHeightLevelMax = Global::kListHeight().size() - 1;
int listHeightLevelMax = viewDefines.listHeightCount() - 1;
int listHeightLevelMin = 0;
ins->addSliderConfig(LV2_GROUP_VIEW ".02_list_height",
tr("Default list height:"),
Expand All @@ -360,13 +360,13 @@ void SettingBackend::initWorkspaceSettingConfig()
viewModeValues.append(tr("Tree"));
viewModeKeys.append(8);
}
ins->addComboboxConfig(LV2_GROUP_VIEW ".03_view_mode",
ins->addComboboxConfig(LV2_GROUP_VIEW ".02_view_mode",
tr("Default view:"),
{ { "values", viewModeValues },
{ "keys", viewModeKeys } },
1);
ins->addConfig(LV2_GROUP_VIEW ".02_restore_view_mode",
{ { "key", "02_restore_view_mode" },
ins->addConfig(LV2_GROUP_VIEW ".03_restore_view_mode",
{ { "key", "03_restore_view_mode" },
{ "desc", tr("Restore default view mode for all directories") },
{ "text", tr("Restore default view mode") },
{ "type", "pushButton" },
Expand Down Expand Up @@ -474,37 +474,4 @@ QVariant SettingBackendPrivate::getByFunc(const QString &key)
return getter();
}
return QVariant();
}

QPair<QWidget *, QWidget *> SettingBackend::createSliderWithSideIcon(QObject *opt)
{
auto option = qobject_cast<Dtk::Core::DSettingsOption *>(opt);

const QString text = option->name();
DLabel *label = new DLabel(text);

DSlider *slider = new DSlider;
slider->setObjectName("OptionQSlider");
slider->setAccessibleName("OptionQSlider");
slider->slider()->setOrientation(Qt::Horizontal);
slider->setMaximum(option->data("max").toInt());
slider->setMinimum(option->data("min").toInt());
slider->setLeftIcon(QIcon::fromTheme(option->data("left-icon").toString()));
slider->setRightIcon(QIcon::fromTheme(option->data("right-icon").toString()));
slider->setValue(option->value().toInt());
slider->setIconSize(QSize(20, 20));

option->connect(slider, &DSlider::valueChanged,
option, [ = ](int value) {
slider->blockSignals(true);
option->setValue(value);
slider->blockSignals(false);
});
option->connect(option, &DTK_CORE_NAMESPACE::DSettingsOption::valueChanged,
slider, [ = ](const QVariant & value) {
slider->setValue(value.toInt());
slider->update();
});

return QPair<QWidget *, QWidget *>(label, slider);
}
}
2 changes: 0 additions & 2 deletions src/dfm-base/base/configs/settingbackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class SettingBackend : public DSettingsBackend
void addToSerialDataKey(const QString &key);
void removeSerialDataKey(const QString &key);

static QPair<QWidget *, QWidget *> createSliderWithSideIcon(QObject *opt);

Q_SIGNALS:
void optionSetted(const QString &key, const QVariant &value);

Expand Down
7 changes: 6 additions & 1 deletion src/dfm-base/base/configs/settingjsongenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ bool SettingJsonGenerator::addComboboxConfig(const QString &key, const QString &
return addConfig(key, config);
}

bool SettingJsonGenerator::addSliderConfig(const QString &key, const QString &name, int maxVal, int minVal, int defaultVal)
{
return addSliderConfig(key, name, "", "", maxVal, minVal, defaultVal);
}

bool SettingJsonGenerator::addSliderConfig(const QString &key,
const QString &name,
const QString &leftIcon,
Expand All @@ -225,7 +230,7 @@ bool SettingJsonGenerator::addSliderConfig(const QString &key,
QVariantMap config {
{ "key", key.mid(key.lastIndexOf(".") + 1) },
{ "name", name },
{ "type", SettingDialog::kSettingSliderItem },
{ "type", "sliderWithSideIcon" },
{ "max", maxVal},
{ "min", minVal},
{ "default", defaultVal },
Expand Down
43 changes: 43 additions & 0 deletions src/dfm-base/dialogs/settingsdialog/settingdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <DSettingsWidgetFactory>
#include <dsettingsbackend.h>
#include <DPushButton>
#include <DSlider>
#include <DLabel>

#include <QWindow>
#include <QFile>
Expand Down Expand Up @@ -151,6 +153,7 @@ void SettingDialog::initialze()

widgetFactory()->registerWidget("checkBoxWithMessage", &SettingDialog::createCheckBoxWithMessage);
widgetFactory()->registerWidget("pushButton", &SettingDialog::createPushButton);
widgetFactory()->registerWidget("sliderWithSideIcon", &SettingDialog::createSliderWithSideIcon);

auto creators = CustomSettingItemRegister::instance()->getCreators();
auto iter = creators.cbegin();
Expand Down Expand Up @@ -311,6 +314,46 @@ QPair<QWidget *, QWidget *> SettingDialog::createPushButton(QObject *opt)
return qMakePair(new QLabel(desc), rightWidget);
}


QPair<QWidget *, QWidget *> SettingDialog::createSliderWithSideIcon(QObject *opt)
{
auto option = qobject_cast<Dtk::Core::DSettingsOption *>(opt);

const QString &text = option->name();
DLabel *label = new DLabel(text);

DSlider *slider = new DSlider;
slider->setObjectName("OptionQSlider");
slider->setAccessibleName("OptionQSlider");
slider->slider()->setOrientation(Qt::Horizontal);
slider->setMaximum(option->data("max").toInt());
slider->setMinimum(option->data("min").toInt());
const QString &leftIcon = option->data("left-icon").toString();
const QString &rightIcon = option->data("right-icon").toString();
if (!leftIcon.isEmpty()) {
slider->setLeftIcon(QIcon::fromTheme(leftIcon));
}
if (!rightIcon.isEmpty()) {
slider->setRightIcon(QIcon::fromTheme(rightIcon));
}
slider->setValue(option->value().toInt());
slider->setIconSize(QSize(20, 20));

option->connect(slider, &DSlider::valueChanged,
option, [ = ](int value) {
slider->blockSignals(true);
option->setValue(value);
slider->blockSignals(false);
});
option->connect(option, &DTK_CORE_NAMESPACE::DSettingsOption::valueChanged,
slider, [ = ](const QVariant & value) {
slider->setValue(value.toInt());
slider->update();
});

return qMakePair(label, slider);
}

void SettingDialog::mountCheckBoxStateChangedHandle(DSettingsOption *option, int state)
{
if (state == 0) {
Expand Down
1 change: 1 addition & 0 deletions src/dfm-base/dialogs/settingsdialog/settingdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SettingDialog : public DSettingsDialog
[[nodiscard]] static QPair<QWidget *, QWidget *> createAutoMountOpenCheckBox(QObject *opt);
[[nodiscard]] static QPair<QWidget *, QWidget *> createCheckBoxWithMessage(QObject *opt);
[[nodiscard]] static QPair<QWidget *, QWidget *> createPushButton(QObject *opt);
[[nodiscard]] static QPair<QWidget *, QWidget *> createSliderWithSideIcon(QObject *opt);

static void mountCheckBoxStateChangedHandle(DSettingsOption *option, int state);
static void autoMountCheckBoxChangedHandle(DSettingsOption *option, int state);
Expand Down
85 changes: 85 additions & 0 deletions src/dfm-base/utils/viewdefines.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "viewdefines.h"

DFMBASE_USE_NAMESPACE

ViewDefines::ViewDefines()
{
initDefines();
}

int ViewDefines::iconSizeCount() const
{
return iconSizeList.size();
}

int ViewDefines::iconSize(int index) const
{
return iconSizeList.at(index);
}

int ViewDefines::indexOfIconSize(int size) const
{
return iconSizeList.indexOf(size);
}

int ViewDefines::iconGridDensityCount() const
{
return iconGridDensityList.size();
}

int ViewDefines::iconGridDensity(int index) const
{
return iconGridDensityList.at(index);
}

int ViewDefines::indexOfIconGridDensity(int density) const
{
return iconGridDensityList.indexOf(density);
}

int ViewDefines::listHeightCount() const
{
return listHeightList.size();
}

int ViewDefines::listHeight(int index) const
{
return listHeightList.at(index);
}

int ViewDefines::indexOfListHeight(int height) const
{
return listHeightList.indexOf(height);
}

void ViewDefines::initDefines()
{
// init icon size list
int size = kIconSizeMin;
// range 24-192, step size 8
while (size <= kIconSizeMiddle) {
iconSizeList.append(size);
size += kIconSizeNormalStep;
}
// range 192-512, step size 16
size = kIconSizeMiddle + kIconSizeLargeStep;
while (size <= kIconSizeMax) {
iconSizeList.append(size);
size += kIconSizeLargeStep;
}

// init icon grid density
int width = kIconGridDensityMin;
while (width <= kIconGridDensityMax) {
iconGridDensityList.append(width);
width += kIconGridDensityStep;
}

// init list height
listHeightList = { 24, 32, 48 };
}

Loading

0 comments on commit 72929d3

Please sign in to comment.