Files
live-caption/src/ui/captionwindow.h
T
blumia 736ec14d5b refactor: split core/ui/apps targets and add unit tests
Move all business logic into liblivecaption_core (no Qt dependency) and
the widgets into liblivecaption_ui, leaving two executables: the caption
window and the CLI, which no longer links Qt Widgets. Abstract the ASR
backend behind IAsr so the streaming policy and the live pipeline can be
tested with a scripted fake backend instead of a real model.

把全部业务逻辑下沉到不依赖 Qt 的 liblivecaption_core,界面独立成
liblivecaption_ui,拆出悬浮窗与命令行两个可执行程序(CLI 不再链接 Qt
Widgets);并用 IAsr 抽象推理后端,使流式策略与实时管线可脱离真模型
用假实现做单元测试。测试还抓到一个真 bug:段恰好结束在 chunk 边界时
只提交了稳定部分,最后几个词被丢掉,已修。
2026-10-12 13:43:50 +08:00

64 lines
1.8 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_; }
Q_SIGNALS:
void languageClicked();
void closed();
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 applyStyle();
QPushButton * langPill_ = nullptr;
QPushButton * closeBtn_ = nullptr;
QPushButton * toggleBtn_ = nullptr;
QTextEdit * text_ = nullptr;
bool collapsed_ = true;
int opacityPercent_ = 84; // 背景不透明度(百分比)
bool dragging_ = false;
QPoint dragOffset_;
QString language_;
QString committed_;
QString tail_;
};
} // namespace lc