Change overlay drawing
This commit is contained in:
parent
295353332f
commit
6336d3545a
@ -1,38 +1,33 @@
|
||||
#include "captureareaselector.h"
|
||||
#include "capturearea.h"
|
||||
#include "capturer.h"
|
||||
#include "languagecodes.h"
|
||||
#include "settings.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
CaptureAreaSelector::CaptureAreaSelector(Capturer &capturer,
|
||||
const Settings &settings)
|
||||
const Settings &settings,
|
||||
const QPixmap &pixmap)
|
||||
: capturer_(capturer)
|
||||
, settings_(settings)
|
||||
, pixmap_(pixmap)
|
||||
{
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
|
||||
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
|
||||
setCursor(Qt::CrossCursor);
|
||||
setMouseTracking(true);
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
}
|
||||
|
||||
void CaptureAreaSelector::activate()
|
||||
{
|
||||
setGeometry(pixmap_.rect());
|
||||
show();
|
||||
activateWindow();
|
||||
}
|
||||
|
||||
void CaptureAreaSelector::setPixmap(const QPixmap &pixmap)
|
||||
{
|
||||
pixmap_ = pixmap;
|
||||
auto palette = this->palette();
|
||||
palette.setBrush(backgroundRole(), pixmap);
|
||||
setPalette(palette);
|
||||
setGeometry(pixmap_.rect());
|
||||
}
|
||||
|
||||
void CaptureAreaSelector::setScreenRects(const std::vector<QRect> &screens)
|
||||
{
|
||||
auto helpRect = fontMetrics().boundingRect({}, 0, help_);
|
||||
@ -79,16 +74,9 @@ void CaptureAreaSelector::keyPressEvent(QKeyEvent *event)
|
||||
void CaptureAreaSelector::paintEvent(QPaintEvent * /*event*/)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(rect(), pixmap_);
|
||||
|
||||
for (auto &screenHelp : helpRects_) {
|
||||
painter.setBrush(QBrush(QColor(200, 200, 200, 200)));
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.drawRect(screenHelp.current);
|
||||
|
||||
painter.setBrush({});
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(screenHelp.current, Qt::AlignCenter, help_);
|
||||
}
|
||||
for (const auto &rect : helpRects_) drawHelpRects(painter, rect);
|
||||
|
||||
auto selection = QRect(startSelectPos_, currentSelectPos_).normalized();
|
||||
if (!selection.isValid())
|
||||
@ -121,6 +109,18 @@ bool CaptureAreaSelector::updateCurrentHelpRects()
|
||||
return changed;
|
||||
}
|
||||
|
||||
void CaptureAreaSelector::drawHelpRects(QPainter &painter,
|
||||
const HelpRect &rect) const
|
||||
{
|
||||
painter.setBrush(QBrush(QColor(200, 200, 200, 200)));
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.drawRect(rect.current);
|
||||
|
||||
painter.setBrush({});
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(rect.current, Qt::AlignCenter, help_);
|
||||
}
|
||||
|
||||
void CaptureAreaSelector::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (startSelectPos_.isNull())
|
||||
|
@ -9,10 +9,10 @@ class CaptureAreaSelector : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CaptureAreaSelector(Capturer &capturer, const Settings &settings);
|
||||
CaptureAreaSelector(Capturer &capturer, const Settings &settings,
|
||||
const QPixmap &pixmap);
|
||||
|
||||
void activate();
|
||||
void setPixmap(const QPixmap &pixmap);
|
||||
void setScreenRects(const std::vector<QRect> &screens);
|
||||
void updateSettings();
|
||||
|
||||
@ -31,10 +31,11 @@ private:
|
||||
};
|
||||
|
||||
bool updateCurrentHelpRects();
|
||||
void drawHelpRects(QPainter &painter, const HelpRect &rect) const;
|
||||
|
||||
Capturer &capturer_;
|
||||
const Settings &settings_;
|
||||
QPixmap pixmap_;
|
||||
const QPixmap &pixmap_;
|
||||
QPoint startSelectPos_;
|
||||
QPoint currentSelectPos_;
|
||||
QString help_;
|
||||
|
@ -12,7 +12,7 @@
|
||||
Capturer::Capturer(Manager &manager, const Settings &settings)
|
||||
: manager_(manager)
|
||||
, settings_(settings)
|
||||
, selector_(std::make_unique<CaptureAreaSelector>(*this, settings_))
|
||||
, selector_(std::make_unique<CaptureAreaSelector>(*this, settings_, pixmap_))
|
||||
{
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ void Capturer::updatePixmap()
|
||||
}
|
||||
|
||||
SOFT_ASSERT(selector_, return );
|
||||
selector_->setPixmap(combined);
|
||||
pixmap_ = combined;
|
||||
selector_->setScreenRects(screenRects);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include "stfwd.h"
|
||||
|
||||
#include <vector>
|
||||
#include <QPixmap>
|
||||
|
||||
class Capturer
|
||||
{
|
||||
@ -22,5 +22,6 @@ private:
|
||||
|
||||
Manager &manager_;
|
||||
const Settings &settings_;
|
||||
QPixmap pixmap_;
|
||||
std::unique_ptr<CaptureAreaSelector> selector_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user