Three settings were only half-wired: - autoPickByLanguage was saved but never read anywhere: delete it. - showUnstableTail had a checkbox and a setter, but nothing ever called the setter, so the checkbox did nothing: apply it in applyAppearance and re-render from the cached text instead of blanking the caption. - the language dropdown was hard-coded to auto/zh/en/ja while the registry declares up to 16 languages per model: build it from the selected model's own language list, with an ISO-code to display-name mapping (plus a unit test covering every code in the registry). The caption window's language pill now follows the setting too, instead of keeping whatever it showed at startup. windowPos is not dead -- it stores the dragged window position -- so it stays. 三个「半死」设置:autoPickByLanguage 存了但从没被读取,直接删掉;showUnstableTail 有复选框也有 setter,但从来没人调用 setter(复选框点了没用),改为在 applyAppearance 里生效并用缓存文本重画;「识别语言」下拉原来硬编码 自动/中/英/日,而注册表里每个模型 声明了最多 16 种语言,改为按所选模型的语言动态生成,并补 ISO 码→显示名映射与单元测试。 字幕窗的语言标签也跟着设置走了(原来只在启动时读一次)。windowPos 不是死设置(它存的 是拖动后的位置),保留。
74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <QPoint>
|
|
#include <QWidget>
|
|
|
|
class QLabel;
|
|
class QPushButton;
|
|
class QTextEdit;
|
|
|
|
namespace lc {
|
|
|
|
// 悬浮字幕窗(对应 Chrome 实时字幕那种样式):
|
|
// 无边框、置顶、不接受焦点;折叠时两行,展开后多行。
|
|
class CaptionWindow : public QWidget {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit CaptionWindow(QWidget * parent = nullptr);
|
|
|
|
// committed 为已稳定文本,tail 为不稳定尾部(暗色显示)
|
|
void setCaption(const QString & committed, const QString & tail);
|
|
void setLanguage(const QString & language);
|
|
|
|
bool isCollapsed() const { return collapsed_; }
|
|
void setCollapsed(bool collapsed);
|
|
|
|
// 背景不透明度(百分比)。范围限制在 20~100:
|
|
// 太低会让字幕在任何桌面背景下都读不清,所以不给到全透明。
|
|
void setPanelOpacity(int percent);
|
|
int panelOpacity() const { return opacityPercent_; }
|
|
|
|
void setTextFontSize(int px);
|
|
void setLineCounts(int collapsed, int expanded);
|
|
void setShowTail(bool on);
|
|
|
|
Q_SIGNALS:
|
|
void languageClicked();
|
|
void closed();
|
|
void moved(const QPoint & topLeft);
|
|
|
|
protected:
|
|
void mousePressEvent(QMouseEvent * e) override;
|
|
void mouseMoveEvent(QMouseEvent * e) override;
|
|
void mouseReleaseEvent(QMouseEvent * e) override;
|
|
void paintEvent(QPaintEvent * e) override;
|
|
|
|
private:
|
|
int lineHeight() const;
|
|
int textHeight() const; // 按折叠/展开计算文本区高度
|
|
void relayout();
|
|
void scrollToEnd();
|
|
void renderCaption(); // 按 showTail_ 重画缓存的文本
|
|
void applyStyle();
|
|
|
|
QPushButton * langPill_ = nullptr;
|
|
QPushButton * closeBtn_ = nullptr;
|
|
QPushButton * toggleBtn_ = nullptr;
|
|
QTextEdit * text_ = nullptr;
|
|
|
|
bool collapsed_ = true;
|
|
bool showTail_ = true;
|
|
int fontSize_ = 15;
|
|
int collapsedLines_ = 2;
|
|
int expandedLines_ = 8;
|
|
int opacityPercent_ = 84; // 背景不透明度(百分比)
|
|
bool dragging_ = false;
|
|
QPoint dragOffset_;
|
|
QString language_;
|
|
QString committed_;
|
|
QString tail_;
|
|
};
|
|
|
|
} // namespace lc
|