Add capture help message
This commit is contained in:
parent
71b74bb286
commit
668c8f1183
@ -1,17 +1,22 @@
|
|||||||
#include "captureareaselector.h"
|
#include "captureareaselector.h"
|
||||||
#include "capturer.h"
|
#include "capturer.h"
|
||||||
|
#include "languagecodes.h"
|
||||||
|
#include "settings.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
||||||
CaptureAreaSelector::CaptureAreaSelector(Capturer &capturer)
|
CaptureAreaSelector::CaptureAreaSelector(Capturer &capturer,
|
||||||
|
const Settings &settings)
|
||||||
: capturer_(capturer)
|
: capturer_(capturer)
|
||||||
|
, settings_(settings)
|
||||||
{
|
{
|
||||||
setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
|
setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
|
||||||
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
|
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
|
||||||
setCursor(Qt::CrossCursor);
|
setCursor(Qt::CrossCursor);
|
||||||
|
setMouseTracking(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureAreaSelector::setScreen(QScreen &screen)
|
void CaptureAreaSelector::setScreen(QScreen &screen)
|
||||||
@ -30,6 +35,31 @@ void CaptureAreaSelector::setScreen(QScreen &screen)
|
|||||||
palette.setBrush(backgroundRole(), pixmap);
|
palette.setBrush(backgroundRole(), pixmap);
|
||||||
setPalette(palette);
|
setPalette(palette);
|
||||||
setGeometry(geometry);
|
setGeometry(geometry);
|
||||||
|
|
||||||
|
updateHelp();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CaptureAreaSelector::updateHelp()
|
||||||
|
{
|
||||||
|
LanguageCodes languages;
|
||||||
|
const auto source = languages.findById(settings_.sourceLanguage);
|
||||||
|
const auto sourceName =
|
||||||
|
source ? QObject::tr(source->name) : settings_.sourceLanguage;
|
||||||
|
const auto target = languages.findById(settings_.targetLanguage);
|
||||||
|
const auto targetName =
|
||||||
|
target ? QObject::tr(target->name) : settings_.targetLanguage;
|
||||||
|
|
||||||
|
help_ = tr(R"(Recognition language: %1
|
||||||
|
Translation language: %2)")
|
||||||
|
.arg(sourceName, targetName);
|
||||||
|
|
||||||
|
const auto rect = this->rect();
|
||||||
|
auto helpRect = fontMetrics().boundingRect({}, 0, help_);
|
||||||
|
helpRect.setSize(helpRect.size() * 1.4);
|
||||||
|
helpRects_ = std::vector<QRect>(2, helpRect);
|
||||||
|
helpRects_[0].moveTopLeft(rect.topLeft());
|
||||||
|
helpRects_[1].moveTopRight(rect.topRight());
|
||||||
|
currentHelpRect_ = helpRects_[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureAreaSelector::showEvent(QShowEvent * /*event*/)
|
void CaptureAreaSelector::showEvent(QShowEvent * /*event*/)
|
||||||
@ -45,11 +75,30 @@ void CaptureAreaSelector::keyPressEvent(QKeyEvent *event)
|
|||||||
|
|
||||||
void CaptureAreaSelector::paintEvent(QPaintEvent * /*event*/)
|
void CaptureAreaSelector::paintEvent(QPaintEvent * /*event*/)
|
||||||
{
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
|
const auto cursor = mapFromGlobal(QCursor::pos());
|
||||||
|
if (currentHelpRect_.contains(cursor)) {
|
||||||
|
for (const auto &rect : helpRects_) {
|
||||||
|
if (!rect.contains(cursor)) {
|
||||||
|
currentHelpRect_ = rect;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setBrush(QBrush(QColor(200, 200, 200, 200)));
|
||||||
|
painter.setPen(Qt::NoPen);
|
||||||
|
painter.drawRect(currentHelpRect_);
|
||||||
|
painter.setBrush({});
|
||||||
|
painter.setPen(Qt::black);
|
||||||
|
painter.drawText(currentHelpRect_, Qt::AlignCenter, help_);
|
||||||
|
|
||||||
auto selection = QRect(startSelectPos_, currentSelectPos_).normalized();
|
auto selection = QRect(startSelectPos_, currentSelectPos_).normalized();
|
||||||
if (!selection.isValid())
|
if (!selection.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QPainter painter(this);
|
painter.setBrush({});
|
||||||
painter.setPen(Qt::red);
|
painter.setPen(Qt::red);
|
||||||
painter.drawRect(selection);
|
painter.drawRect(selection);
|
||||||
}
|
}
|
||||||
@ -62,11 +111,14 @@ void CaptureAreaSelector::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
void CaptureAreaSelector::mouseMoveEvent(QMouseEvent *event)
|
void CaptureAreaSelector::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (startSelectPos_.isNull())
|
if (startSelectPos_.isNull()) {
|
||||||
|
if (currentHelpRect_.contains(event->pos()))
|
||||||
|
update();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
currentSelectPos_ = event->pos();
|
currentSelectPos_ = event->pos();
|
||||||
repaint();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureAreaSelector::mouseReleaseEvent(QMouseEvent *event)
|
void CaptureAreaSelector::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
@ -11,7 +11,7 @@ class CaptureAreaSelector : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CaptureAreaSelector(Capturer &capturer);
|
CaptureAreaSelector(Capturer &capturer, const Settings &settings);
|
||||||
|
|
||||||
void setScreen(QScreen &screen);
|
void setScreen(QScreen &screen);
|
||||||
|
|
||||||
@ -24,8 +24,14 @@ protected:
|
|||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateHelp();
|
||||||
|
|
||||||
Capturer &capturer_;
|
Capturer &capturer_;
|
||||||
|
const Settings &settings_;
|
||||||
QPixmap pixmap_;
|
QPixmap pixmap_;
|
||||||
QPoint startSelectPos_;
|
QPoint startSelectPos_;
|
||||||
QPoint currentSelectPos_;
|
QPoint currentSelectPos_;
|
||||||
|
QString help_;
|
||||||
|
QRect currentHelpRect_;
|
||||||
|
std::vector<QRect> helpRects_;
|
||||||
};
|
};
|
||||||
|
@ -54,7 +54,7 @@ void Capturer::showOverlays(bool capturePixmap)
|
|||||||
|
|
||||||
for (auto i = 0, end = screensSize; i < end; ++i) {
|
for (auto i = 0, end = screensSize; i < end; ++i) {
|
||||||
if (i == overlaysSize) {
|
if (i == overlaysSize) {
|
||||||
selectors_.push_back(new CaptureAreaSelector(*this));
|
selectors_.push_back(new CaptureAreaSelector(*this, settings_));
|
||||||
++overlaysSize;
|
++overlaysSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user