-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathToolBarCustomDialog.vue
341 lines (316 loc) · 11.2 KB
/
ToolBarCustomDialog.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<template>
<QDialog
v-model="ToolBarCustomDialogOpenComputed"
maximized
transitionShow="jump-up"
transitionHide="jump-down"
class="tool-bar-custom-dialog transparent-backdrop"
>
<QLayout container view="hHh Lpr fFf" class="bg-background">
<QPageContainer class="root">
<QHeader class="q-py-sm">
<QToolbar>
<!-- close button -->
<QBtn
round
flat
icon="sym_r_close"
color="display"
@click="finishOrNotDialog"
/>
<QToolbarTitle class="text-display">
ツールバーのカスタマイズ
</QToolbarTitle>
<QBtn
outline
icon="sym_r_settings_backup_restore"
label="デフォルトに戻す"
textColor="warning"
class="text-no-wrap text-bold q-mr-sm"
:disable="isDefault"
@click="applyDefaultSetting"
/>
<QBtn
outline
icon="sym_r_save"
label="保存"
textColor="display"
class="text-no-wrap text-bold q-mr-sm"
:disable="!isChanged"
@click="saveCustomToolbar"
/>
</QToolbar>
</QHeader>
<QPage>
<QCard flat square class="preview-card">
<QToolbar class="bg-toolbar preview-toolbar">
<Draggable
v-model="toolbarButtons"
:itemKey="toolbarButtonKey"
@start="toolbarButtonDragging = true"
@end="toolbarButtonDragging = false"
>
<template
#item="{ element: button }: { element: ToolbarButtonTagType }"
>
<QBtn
unelevated
color="toolbar-button"
textColor="toolbar-button-display"
:icon="getToolbarButtonIcon(button)"
:class="
(button === 'EMPTY' ? ' radio-space' : ' radio') +
((button === 'PLAY' || button === 'STOP') ? ' play-stop-button' : '') +
(button.startsWith('SPACER') ? ' spacer' : '') +
' text-no-wrap text-bold q-px-sm q-mr-sm'
"
>
<!-- {{ getToolbarButtonName(button) }} -->
<QTooltip
:delay="150"
:offset="[0, 8]"
anchor="bottom middle"
self="top middle"
transitionShow="jump-down"
transitionHide="jump-up"
:style="{
display: toolbarButtonDragging ? 'none' : 'block',
}"
>{{ usableButtonsDesc[button] }}</QTooltip
>
</QBtn>
</template>
</Draggable>
<div class="preview-toolbar-drag-hint">
上のボタンをドラッグして、ボタンの順序を並び替えできます。
</div>
</QToolbar>
<QCardActions>
<div class="text-h5 q-pl-sm q-mt-sm q-mb-sm">
表示するボタンの選択
</div>
</QCardActions>
<QCardActions class="no-padding">
<QList class="usable-button-list bg-surface-darken">
<QItem
v-for="(desc, key) in usableButtonsDesc"
:key
v-ripple
tag="label"
>
<QItemSection>
<QItemLabel>{{ getToolbarButtonName(key) }}</QItemLabel>
<QItemLabel caption>{{ desc }}</QItemLabel>
</QItemSection>
<QItemSection avatar>
<QToggle v-model="toolbarButtons" :val="key" />
</QItemSection>
</QItem>
</QList>
</QCardActions>
</QCard>
</QPage>
</QPageContainer>
</QLayout>
</QDialog>
</template>
<script setup lang="ts">
import { computed, ref, watch, Ref } from "vue";
import Draggable from "vuedraggable";
import { useStore } from "@/store";
import { ToolbarButtonTagType, ToolbarSettingType } from "@/type/preload";
import { getToolbarButtonName, getToolbarButtonIcon } from "@/store/utility";
const props = defineProps<{
modelValue: boolean;
}>();
const emit = defineEmits<{
(e: "update:modelValue", val: boolean): void;
}>();
const store = useStore();
// computedだと値の編集ができないが、refにすると起動時に読み込まれる設定が反映されないので、watchしている
const toolbarButtons = ref([...store.state.toolbarSetting]);
const toolbarButtonKey = (button: ToolbarButtonTagType) => button;
const toolbarButtonDragging = ref(false);
const selectedButton: Ref<ToolbarButtonTagType | undefined> = ref(
toolbarButtons.value[0],
);
watch(
() => store.state.toolbarSetting,
(newData) => {
// このwatchはToolbar Setting更新時にも機能するが、
// 以下の処理はAivisSpeech起動時のみ機能してほしいので、toolbarButtonsのlengthが0の時だけ機能させる
if (!toolbarButtons.value.length) {
toolbarButtons.value = [...newData];
selectedButton.value = newData[0];
}
},
);
const defaultSetting: ToolbarSettingType = [];
void window.backend.getDefaultToolbarSetting().then((setting) => {
defaultSetting.push(...setting);
});
// const toggleToolbarButtons = (key: ToolbarButtonTagType) => {
// if (toolbarButtons.value.includes(key)) {
// toolbarButtons.value.splice(toolbarButtons.value.indexOf(key), 1);
// } else {
// toolbarButtons.value.push(key);
// }
// };
const usableButtonsDesc: Record<ToolbarButtonTagType, string> = {
UNDO: "操作を一つ戻します。",
REDO: "元に戻した操作をやり直します。",
SAVE_PROJECT: "プロジェクトを上書き保存します。",
PLAY_CONTINUOUSLY:
"選択されているテキスト以降のすべてのテキストを読み上げます。",
PLAY: "選択されているテキストを読み上げます。",
STOP: "テキストが読み上げられているときに、それを止めます。",
EXPORT_AUDIO_SELECTED:
"選択されているテキストの読み上げを音声ファイルに書き出します。",
EXPORT_AUDIO_ALL:
"入力されているすべてのテキストの読み上げを音声ファイルに書き出します。",
EXPORT_AUDIO_CONNECT_ALL:
"入力されているすべてのテキストの読み上げを一つの音声ファイルにつなげて書き出します。",
IMPORT_TEXT: "テキストファイル (.txt) を読み込みます。",
EMPTY:
"これはボタンではありません。レイアウトの調整に使います。また、実際には表示されません。",
SPACER_1: "これはボタンではありません。区切りの挿入に使います。また、実際には表示されません。",
SPACER_2: "これはボタンではありません。区切りの挿入に使います。また、実際には表示されません。",
SPACER_3: "これはボタンではありません。区切りの挿入に使います。また、実際には表示されません。",
};
const ToolBarCustomDialogOpenComputed = computed({
get: () => props.modelValue || isChanged.value,
set: (val) => emit("update:modelValue", val),
});
const isChanged = computed(() => {
const nowSetting = store.state.toolbarSetting;
return (
toolbarButtons.value.length != nowSetting.length ||
toolbarButtons.value.some((e, i) => e != nowSetting[i])
);
});
const isDefault = computed(() => {
return (
toolbarButtons.value.length == defaultSetting.length &&
toolbarButtons.value.every((e, i) => e == defaultSetting[i])
);
});
// ボタンが追加されたときはそれをフォーカスし、
// 削除されたときは一番最初のボタンをフォーカスするようにする
watch(
() => toolbarButtons.value,
(newData, oldData) => {
if (oldData.length < newData.length) {
selectedButton.value = newData[newData.length - 1];
} else if (
selectedButton.value != undefined &&
oldData.includes(selectedButton.value) &&
!newData.includes(selectedButton.value)
) {
selectedButton.value = newData[0];
}
},
);
const applyDefaultSetting = async () => {
const result = await store.actions.SHOW_WARNING_DIALOG({
title: "ツールバーをデフォルトに戻しますか?",
message: "今までのカスタマイズ内容は破棄されます。",
actionName: "デフォルトに戻す",
isWarningColorButton: true,
});
if (result === "OK") {
toolbarButtons.value = [...defaultSetting];
selectedButton.value = toolbarButtons.value[0];
}
};
const saveCustomToolbar = () => {
void store.actions.SET_TOOLBAR_SETTING({
data: [...toolbarButtons.value],
});
};
const finishOrNotDialog = async () => {
if (isChanged.value) {
const result = await store.actions.SHOW_WARNING_DIALOG({
title: "カスタマイズを終了しますか?",
message:
"保存せずに終了すると、カスタマイズ内容は破棄されます。",
actionName: "終了する",
isWarningColorButton: true,
});
if (result === "OK") {
toolbarButtons.value = [...store.state.toolbarSetting];
selectedButton.value = toolbarButtons.value[0];
ToolBarCustomDialogOpenComputed.value = false;
}
} else {
selectedButton.value = toolbarButtons.value[0];
ToolBarCustomDialogOpenComputed.value = false;
}
};
</script>
<style lang="scss">
.play-stop-button .material-symbols-rounded {
font-variation-settings: 'FILL' 1, 'wght' 300, 'GRAD' 200, 'opsz' 24 !important;
}
</style>
<style lang="scss" scoped>
@use "@/styles/variables" as vars;
@use "@/styles/colors" as colors;
.spacer {
width: 0px;
height: 36px;
padding-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
padding-right: 8px;
border-left: 2px solid var(--color-splitter);
margin-right: 0px;
background: transparent;
border-radius: 0px;
}
.tool-bar-custom-dialog .q-layout-container :deep(.absolute-full) {
right: 0 !important;
overflow-x: hidden;
> .scroll {
width: unset !important;
overflow: hidden;
}
}
.preview-toolbar {
height: calc(#{vars.$toolbar-height} + 16px);
display: block;
}
// draggableのdiv。
.preview-toolbar > div:not(.preview-toolbar-drag-hint) {
width: 100%;
display: inline-flex;
}
.preview-toolbar-drag-hint {
padding-top: 12px;
padding-bottom: 12px;
}
.preview-card {
width: 100%;
min-width: 460px;
background: var(--color-background);
}
.usable-button-list {
// menubar-height + toolbar-height * 2(main+preview) + window-border-width
// 52(preview part buttons) * 2 + 46(select part title) + 22(preview part hint)
height: calc(
100vh - #{vars.$menubar-height + (vars.$toolbar-height) +
vars.$window-border-width + 52px + 46px + 46px}
);
width: 100%;
overflow-y: scroll;
}
.radio {
&:hover {
cursor: grab;
}
}
.radio-space {
@extend .radio;
flex-grow: 1;
color: transparent;
}
</style>