2026-10-12 13:32:16 +08:00
|
|
|
#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_; }
|
|
|
|
|
|
2026-10-12 16:30:00 +08:00
|
|
|
void setTextFontSize(int px);
|
|
|
|
|
void setLineCounts(int collapsed, int expanded);
|
|
|
|
|
void setShowTail(bool on);
|
|
|
|
|
|
2026-10-12 13:32:16 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
|
void languageClicked();
|
|
|
|
|
void closed();
|
2026-10-12 16:30:00 +08:00
|
|
|
void moved(const QPoint & topLeft);
|
2026-10-12 13:32:16 +08:00
|
|
|
|
|
|
|
|
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();
|
2026-10-12 17:48:21 +08:00
|
|
|
void renderCaption(); // 按 showTail_ 重画缓存的文本
|
2026-10-12 13:32:16 +08:00
|
|
|
void applyStyle();
|
|
|
|
|
|
|
|
|
|
QPushButton * langPill_ = nullptr;
|
|
|
|
|
QPushButton * closeBtn_ = nullptr;
|
|
|
|
|
QPushButton * toggleBtn_ = nullptr;
|
|
|
|
|
QTextEdit * text_ = nullptr;
|
|
|
|
|
|
2026-10-12 16:30:00 +08:00
|
|
|
bool collapsed_ = true;
|
|
|
|
|
bool showTail_ = true;
|
|
|
|
|
int fontSize_ = 15;
|
|
|
|
|
int collapsedLines_ = 2;
|
|
|
|
|
int expandedLines_ = 8;
|
2026-10-12 13:32:16 +08:00
|
|
|
int opacityPercent_ = 84; // 背景不透明度(百分比)
|
|
|
|
|
bool dragging_ = false;
|
|
|
|
|
QPoint dragOffset_;
|
|
|
|
|
QString language_;
|
|
|
|
|
QString committed_;
|
|
|
|
|
QString tail_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace lc
|