Files
cutdex/lib/features/properties/project_settings_dialog.dart
T
lingjhf 7ebe0c8e2e feat(inspector): separate input and output color controls
Give video clips a dedicated color tab with immediate input interpretation,
automatic detection, and reset controls. Clarify project output color space,
source-stream scope, and unavailable metadata across localized UI text.

Share unknown-source color defaults with the SDK and retain independent
property tab scroll state. Include localized resources and control previews.

Validation: full application analysis, 1261 Flutter tests passed
(9 skipped), generated-code verification, and 171 tool tests.
2026-10-10 22:43:35 +08:00

228 lines
7.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:cutdex/l10n/l10n.dart';
import 'package:cutdex_sdk/editor.dart';
import 'package:cutdex_sdk/runtime/contracts.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:cutdex_ui/theme.dart';
import '../../workspace/timeline_session.dart';
class ProjectSettingsDialog extends StatefulWidget {
const ProjectSettingsDialog({super.key, required this.session});
final EditorTimelineSession session;
@override
State<ProjectSettingsDialog> createState() => _ProjectSettingsDialogState();
}
class _ProjectSettingsDialogState extends State<ProjectSettingsDialog> {
static final _rates = <String, RationalTime>{
'23.976': RationalTime(1001, 24000),
'24': RationalTime(1, 24),
'25': RationalTime(1, 25),
'29.97': RationalTime(1001, 30000),
'30': RationalTime(1, 30),
'50': RationalTime(1, 50),
'59.94': RationalTime(1001, 60000),
'60': RationalTime(1, 60),
'120': RationalTime(1, 120),
};
static const _sizes = <String, (int, int)>{
'1920 × 1080': (1920, 1080),
'3840 × 2160': (3840, 2160),
'1280 × 720': (1280, 720),
'1080 × 1920': (1080, 1920),
'1080 × 1080': (1080, 1080),
};
final _form = GlobalKey<FormState>();
late final TextEditingController _width;
late final TextEditingController _height;
late RationalTime _frame;
late RenderColorSpace _color;
String? _preset;
@override
void initState() {
super.initState();
final canvas = widget.session.canvas;
_width = TextEditingController(text: canvas.width.toStringAsFixed(0));
_height = TextEditingController(text: canvas.height.toStringAsFixed(0));
_frame = widget.session.activeSequenceId == null
? TimelineFormat.fps24.frameDuration
: widget.session.persistence
.timeline(widget.session.activeSequenceId!)
.format
.frameDuration;
_color = widget.session.projectOutputColorSpace;
_preset = _sizes.entries
.where((e) => e.value.$1 == canvas.width && e.value.$2 == canvas.height)
.firstOrNull
?.key;
}
@override
void dispose() {
_width.dispose();
_height.dispose();
super.dispose();
}
void _save() {
if (!_form.currentState!.validate()) return;
widget.session.setProjectProperties(
sequence: widget.session.activeSequenceId,
canvas: ProjectCanvas(
double.parse(_width.text),
double.parse(_height.text),
),
frameDuration: _frame,
colorSpace: _color,
);
Navigator.of(context).pop();
}
Widget _dimension(
TextEditingController controller,
String label,
String key,
) => FormField<String>(
initialValue: controller.text,
validator: (_) {
final value = int.tryParse(controller.text);
return value == null || !ProjectCanvas.isValidDimension(value.toDouble())
? context.l10n.projectResolutionInvalid
: null;
},
builder: (field) => AppTextField(
key: ValueKey(key),
controller: controller,
label: label,
errorText: field.errorText,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
onChanged: (value) {
field.didChange(value);
setState(() => _preset = null);
},
),
);
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final rates = {..._rates};
if (!rates.values.contains(_frame)) {
rates[(_frame.denominator / _frame.numerator).toStringAsFixed(3)] =
_frame;
}
return AppDialog(
title: l10n.projectSettings,
width: 440,
description: l10n.projectSettingsDescription,
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(l10n.cancel),
),
FilledButton(
key: const ValueKey('project-settings-save'),
onPressed: _save,
child: Text(l10n.save),
),
],
child: SingleChildScrollView(
child: Form(
key: _form,
child: AppFieldGroup(
children: [
AppField(
label: l10n.canvasSize,
child: AppFieldGroup(
children: [
AppSelect<String>(
emptyLabel: context.l10n.noMatchingOptions,
key: const ValueKey('project-resolution'),
value: _preset ?? 'custom',
label: l10n.canvasSize,
options: [
for (final name in _sizes.keys)
AppSelectOption(name, name),
AppSelectOption('custom', l10n.custom),
],
onChanged: (value) => setState(() {
_preset = value == 'custom' ? null : value;
final size = _sizes[value];
if (size != null) {
_width.text = '${size.$1}';
_height.text = '${size.$2}';
}
}),
),
Row(
spacing: AppSpacing.compact,
children: [
Expanded(
child: _dimension(
_width,
l10n.projectWidth,
'project-width',
),
),
Expanded(
child: _dimension(
_height,
l10n.projectHeight,
'project-height',
),
),
],
),
],
),
),
AppField(
label: l10n.frameRate,
child: AppSelect<RationalTime>(
emptyLabel: context.l10n.noMatchingOptions,
key: const ValueKey('project-frame-rate'),
value: _frame,
label: l10n.frameRate,
options: [
for (final rate in rates.entries)
AppSelectOption(rate.value, '${rate.key} fps'),
],
onChanged: (value) => setState(() => _frame = value),
),
),
AppField(
label: l10n.projectOutputColorSpace,
child: AppSelect<RenderColorSpace>(
emptyLabel: context.l10n.noMatchingOptions,
key: const ValueKey('project-color-space'),
value: _color,
label: l10n.projectOutputColorSpace,
options: const [
AppSelectOption(RenderColorSpace.rec709, 'SDR · Rec.709'),
AppSelectOption(
RenderColorSpace.rec2020HLG,
'HDR · Rec.2020 HLG',
),
AppSelectOption(
RenderColorSpace.rec2020PQ,
'HDR · Rec.2020 PQ',
),
],
onChanged: (value) => setState(() => _color = value),
),
),
],
),
),
),
);
}
}