|
30 | 30 | #include "hal_core/utilities/log.h" |
31 | 31 |
|
32 | 32 | #include <QAction> |
| 33 | +#include <QApplication> |
33 | 34 | #include <QAudioOutput> |
34 | 35 | #include <QComboBox> |
35 | 36 | #include <QCursor> |
|
38 | 39 | #include <QHBoxLayout> |
39 | 40 | #include <QLabel> |
40 | 41 | #include <QMediaPlayer> |
| 42 | +#include <QPaintEvent> |
| 43 | +#include <QPainter> |
41 | 44 | #include <QShortcut> |
42 | 45 | #include <QSizePolicy> |
43 | 46 | #include <QSlider> |
@@ -163,6 +166,7 @@ namespace hal |
163 | 166 | // --------------------------------------------------------------- |
164 | 167 | // Assemble content layout |
165 | 168 | // --------------------------------------------------------------- |
| 169 | + mContentLayout->setContentsMargins(2, 2, 2, 2); |
166 | 170 | mContentLayout->addWidget(mDisplayStack, 1); |
167 | 171 | mContentLayout->addWidget(controlBar, 0); |
168 | 172 |
|
@@ -218,6 +222,7 @@ namespace hal |
218 | 222 | connect(mPlayer, &QMediaPlayer::durationChanged, this, &MediaViewer::handleDurationChanged); |
219 | 223 | connect(mPlayer, &QMediaPlayer::errorOccurred, this, &MediaViewer::handleMediaError); |
220 | 224 | connect(mPlayer, &QMediaPlayer::sourceChanged, this, &MediaViewer::handleSourceChanged); |
| 225 | + connect(qApp, &QApplication::focusChanged, this, &MediaViewer::handleFocusChanged); |
221 | 226 | } |
222 | 227 |
|
223 | 228 | MediaViewer::~MediaViewer() = default; |
@@ -432,6 +437,28 @@ namespace hal |
432 | 437 | mStopAction->setEnabled(!source.isEmpty()); |
433 | 438 | } |
434 | 439 |
|
| 440 | + void MediaViewer::handleFocusChanged(QWidget* /*old*/, QWidget* now) |
| 441 | + { |
| 442 | + bool wantFocus = (now != nullptr) && isAncestorOf(now); |
| 443 | + if (wantFocus != mHasFocusWithin) |
| 444 | + { |
| 445 | + mHasFocusWithin = wantFocus; |
| 446 | + update(); |
| 447 | + } |
| 448 | + } |
| 449 | + |
| 450 | + void MediaViewer::paintEvent(QPaintEvent* event) |
| 451 | + { |
| 452 | + ExternalContentWidget::paintEvent(event); |
| 453 | + if (!mHasFocusWithin) |
| 454 | + return; |
| 455 | + QPainter painter(this); |
| 456 | + painter.setRenderHint(QPainter::Antialiasing); |
| 457 | + painter.setBrush(Qt::NoBrush); |
| 458 | + painter.setPen(QPen(QColor(40, 200, 240), 1)); |
| 459 | + painter.drawRect(rect().adjusted(1, 1, -1, -1)); |
| 460 | + } |
| 461 | + |
435 | 462 | void MediaViewer::handleStopTriggered() |
436 | 463 | { |
437 | 464 | log_info("media_viewer", "Stopped and unloaded."); |
|
0 commit comments