-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranscriptpreview.cpp
More file actions
50 lines (42 loc) · 1.57 KB
/
Copy pathtranscriptpreview.cpp
File metadata and controls
50 lines (42 loc) · 1.57 KB
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
#include "transcriptpreview.h"
#include <QLabel>
#include <QVBoxLayout>
TranscriptPreview::TranscriptPreview(QWidget* parent)
: QWidget(parent,
Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint
| Qt::WindowDoesNotAcceptFocus)
{
// Never activate/steal focus from the app being dictated into, and stay
// visible while another app is frontmost (the dictation target has focus).
setAttribute(Qt::WA_ShowWithoutActivating);
setAttribute(Qt::WA_MacAlwaysShowToolWindow);
setFocusPolicy(Qt::NoFocus);
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(8, 5, 8, 5);
m_label = new QLabel;
m_label->setWordWrap(true);
m_label->setTextInteractionFlags(Qt::NoTextInteraction);
layout->addWidget(m_label);
// Reuse the app's dark/orange palette (matches the toolbar tooltip style).
setStyleSheet(
"QWidget { background: #1A1A1A; border: 1px solid #FFA600; border-radius: 4px; }"
"QLabel { color: #FFA600; font-size: 12px; background: transparent; border: none; }"
);
setMaximumWidth(360);
}
void TranscriptPreview::showText(const QString& text, const QRect& anchorGlobal)
{
if (text.isEmpty()) {
hide();
return;
}
m_label->setText(text);
adjustSize();
// Place just below the toolbar, left-aligned with it, clamped to its width.
const int w = qMax(width(), anchorGlobal.width());
setFixedWidth(qMin(w, maximumWidth()));
adjustSize();
move(anchorGlobal.left(), anchorGlobal.bottom() + 4);
if (!isVisible())
show();
}