Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/translations/Internationalization_uk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2594,7 +2594,7 @@ You can find me in the system tray.</source>
<message>
<location filename="../../src/utils/screengrabber.cpp" line="202"/>
<source>Screenshot cancelled</source>
<translation type="unfinished"></translation>
<translation>袟薪褨屑芯泻 械泻褉邪薪邪 褋泻邪褋芯胁邪薪芯</translation>
</message>
<message>
<location filename="../../src/utils/screengrabber.cpp" line="218"/>
Expand Down
5 changes: 3 additions & 2 deletions src/config/generalconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,12 @@ void GeneralConf::setInsecurePixelate(bool checked)
void GeneralConf::initCaptureActiveMonitor()
{
m_captureActiveMonitor = new QCheckBox(
tr("Capture active monitor in X11 (skip monitor selection)"), this);
tr("Capture active monitor in X11 and Windows (skip monitor selection)"),
this);
m_captureActiveMonitor->setToolTip(
tr("Automatically capture the monitor where the cursor is located "
"instead of showing the monitor selection dialog. "
"This feature is not supported on Wayland."));
"This feature is not supported on macOS and Wayland."));
m_scrollAreaLayout->addWidget(m_captureActiveMonitor);

connect(m_captureActiveMonitor,
Expand Down
14 changes: 1 addition & 13 deletions src/core/capturerequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors

#include "capturerequest.h"
#include "config/cacheutils.h"
#include "utils/confighandler.h"

#include <QApplication>
#include <QClipboard>
#include <QDateTime>
#include <stdexcept>
#include <utility>

Expand All @@ -21,14 +16,7 @@ CaptureRequest::CaptureRequest(CaptureRequest::CaptureMode mode,
, m_data(std::move(data))
, m_selectedMonitor(-1)
, m_hasSelectedMonitor(false)
{

ConfigHandler config;
if (m_mode == CaptureRequest::CaptureMode::GRAPHICAL_MODE &&
config.saveLastRegion()) {
setInitialSelection(getLastRegion());
}
}
{}

CaptureRequest::CaptureMode CaptureRequest::captureMode() const
{
Expand Down
10 changes: 9 additions & 1 deletion src/core/flameshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ constexpr const char* visibleInDockProperty = "_visibleInDock";
#include <CoreGraphics/CoreGraphics.h>
#endif

#include "config/cacheutils.h"
#include "config/configresolver.h"
#include "config/configwindow.h"
#include "core/qguiappcurrentscreen.h"
Expand Down Expand Up @@ -125,6 +126,13 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req)
return nullptr;
}

CaptureRequest request = req;
if (request.captureMode() == CaptureRequest::GRAPHICAL_MODE &&
request.initialSelection().isNull() &&
ConfigHandler().saveLastRegion()) {
request.setInitialSelection(getLastRegion());
}

#if defined(Q_OS_MACOS)
// This is required on MacOS because of Mission Control. If you'll switch to
// another Desktop you cannot take a new screenshot from the tray, you have
Expand Down Expand Up @@ -157,7 +165,7 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req)
return nullptr;
}

m_captureWindow = new CaptureWidget(req);
m_captureWindow = new CaptureWidget(request);

#ifdef Q_OS_WIN
m_captureWindow->show();
Expand Down
4 changes: 3 additions & 1 deletion src/tools/capturetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class CaptureTool : public QObject
// increase tool size for all tools
REQ_INCREASE_TOOL_SIZE,
// decrease tool size for all tools
REQ_DECREASE_TOOL_SIZE
REQ_DECREASE_TOOL_SIZE,
// Commit the active tool.
REQ_COMMIT_CURRENT_TOOL
};

explicit CaptureTool(QObject* parent = nullptr)
Expand Down
6 changes: 6 additions & 0 deletions src/tools/text/texttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ QWidget* TextTool::widget()
m_widget->setText(m_text);
m_widget->selectAll();
connect(m_widget, &TextWidget::textUpdated, this, &TextTool::updateText);
connect(
m_widget,
&TextWidget::editingFinished,
this,
[this]() { emit requestAction(REQ_COMMIT_CURRENT_TOOL); },
Qt::QueuedConnection);
return m_widget;
}

Expand Down
27 changes: 27 additions & 0 deletions src/tools/text/textwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "textwidget.h"

#include <QEvent>
#include <QKeyEvent>

TextWidget::TextWidget(QWidget* parent)
: QTextEdit(parent)
{
Expand All @@ -14,6 +17,30 @@ TextWidget::TextWidget(QWidget* parent)
setContextMenuPolicy(Qt::NoContextMenu);
}

bool TextWidget::event(QEvent* e)
{
if (e->type() == QEvent::ShortcutOverride) {
auto* keyEvent = static_cast<QKeyEvent*>(e);
if (keyEvent->key() == Qt::Key_Escape) {
keyEvent->accept();
return true;
}
}

return QTextEdit::event(e);
}

void TextWidget::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape) {
emit editingFinished();
e->accept();
return;
}

QTextEdit::keyPressEvent(e);
}

void TextWidget::showEvent(QShowEvent* e)
{
QFont font;
Expand Down
10 changes: 8 additions & 2 deletions src/tools/text/textwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include <QTextEdit>

class QEvent;
class QKeyEvent;

class TextWidget : public QTextEdit
{
Q_OBJECT
Expand All @@ -15,11 +18,14 @@ class TextWidget : public QTextEdit
void setFont(const QFont& f);

protected:
void showEvent(QShowEvent* e);
void resizeEvent(QResizeEvent* e);
bool event(QEvent* e) override;
void keyPressEvent(QKeyEvent* e) override;
void showEvent(QShowEvent* e) override;
void resizeEvent(QResizeEvent* e) override;

signals:
void textUpdated(const QString& s);
void editingFinished();

public slots:
void setTextColor(const QColor& c);
Expand Down
113 changes: 79 additions & 34 deletions src/utils/monitorpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,48 @@ MonitorPreview::MonitorPreview(int monitorIndex,
QWidget* parent)
: QWidget(parent)
, m_monitorIndex(monitorIndex)
, m_selected(false)
, m_mouseHovered(false)
, m_imageLabel(nullptr)
, m_keyLabel(nullptr)
, m_textLabel(nullptr)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(10, 10, 10, 10);
layout->setSpacing(10);

QLabel* imageLabel = new QLabel(this);
imageLabel->setAlignment(Qt::AlignCenter);
imageLabel->setPixmap(thumbnail);
imageLabel->setStyleSheet(
"QLabel { background-color: black; border-radius: 8px; }");
imageLabel->setScaledContents(false);

m_textLabel = new QLabel(tr("Monitor %1: %2\nClick to select")
.arg(m_monitorIndex + 1)
.arg(screen->name()),
this);
m_imageLabel = new QLabel(this);
m_imageLabel->setAlignment(Qt::AlignCenter);
m_imageLabel->setPixmap(thumbnail);
m_imageLabel->setScaledContents(false);

if (m_monitorIndex < 9) {
m_keyLabel =
new QLabel(QString::number(m_monitorIndex + 1), m_imageLabel);
m_keyLabel->setAlignment(Qt::AlignCenter);
m_keyLabel->setFixedSize(28, 28);
m_keyLabel->move(8, 8);
m_keyLabel->raise();
m_keyLabel->setAttribute(Qt::WA_TransparentForMouseEvents);
}

const QString labelText =
m_monitorIndex < 9 ? tr("Monitor %1: %2\nClick or press %1 to select")
.arg(m_monitorIndex + 1)
.arg(screen->name())
: tr("Monitor %1: %2\nClick to select")
.arg(m_monitorIndex + 1)
.arg(screen->name());
m_textLabel = new QLabel(labelText, this);
m_textLabel->setAlignment(Qt::AlignCenter);

layout->addWidget(imageLabel);
layout->addWidget(m_imageLabel);
layout->addWidget(m_textLabel);

m_uiColor = ConfigHandler().uiColor();
m_contrastColor = ColorUtils::contrastColor(m_uiColor);

// Apply initial themed background to text label only
QString normalStyle =
QString("QLabel { color: white; background-color: rgba(%1, %2, %3, 200); "
"padding: 5px; font-size: 12pt; border-radius: 3px; }")
.arg(m_uiColor.red())
.arg(m_uiColor.green())
.arg(m_uiColor.blue());
m_textLabel->setStyleSheet(normalStyle);
updateStyle();
}

void MonitorPreview::mousePressEvent(QMouseEvent* event)
Expand All @@ -59,24 +69,59 @@ void MonitorPreview::mousePressEvent(QMouseEvent* event)
void MonitorPreview::enterEvent(QEnterEvent* event)
{
Q_UNUSED(event)
QColor hoverBg = m_contrastColor;
QString hoverStyle =
QString("QLabel { color: white; background-color: rgba(%1, %2, %3, 220); "
"padding: 5px; font-size: 12pt; border-radius: 3px; }")
.arg(hoverBg.red())
.arg(hoverBg.green())
.arg(hoverBg.blue());
m_textLabel->setStyleSheet(hoverStyle);
m_mouseHovered = true;
updateStyle();
}

void MonitorPreview::leaveEvent(QEvent* event)
{
Q_UNUSED(event)
QString normalStyle =
QString("QLabel { color: white; background-color: rgba(%1, %2, %3, 200); "
m_mouseHovered = false;
updateStyle();
}

void MonitorPreview::setSelected(bool selected)
{
if (m_selected == selected) {
return;
}

m_selected = selected;
updateStyle();
}

void MonitorPreview::updateStyle()
{
const bool highlighted = m_selected || m_mouseHovered;
const QColor backgroundColor = highlighted ? m_contrastColor : m_uiColor;
const int textAlpha = highlighted ? 220 : 200;
const int borderAlpha = highlighted ? 255 : 0;

QString textStyle =
QString("QLabel { color: white; background-color: rgba(%1, %2, %3, %4); "
"padding: 5px; font-size: 12pt; border-radius: 3px; }")
.arg(m_uiColor.red())
.arg(m_uiColor.green())
.arg(m_uiColor.blue());
m_textLabel->setStyleSheet(normalStyle);
.arg(backgroundColor.red())
.arg(backgroundColor.green())
.arg(backgroundColor.blue())
.arg(textAlpha);
m_textLabel->setStyleSheet(textStyle);

QString imageStyle =
QString("QLabel { background-color: black; border: 2px solid "
"rgba(%1, %2, %3, %4); border-radius: 8px; }")
.arg(backgroundColor.red())
.arg(backgroundColor.green())
.arg(backgroundColor.blue())
.arg(borderAlpha);
m_imageLabel->setStyleSheet(imageStyle);

if (m_keyLabel) {
QString keyStyle = QString("QLabel { color: white; font-weight: bold; "
"background-color: rgba(%1, %2, %3, 230); "
"border-radius: 14px; }")
.arg(backgroundColor.red())
.arg(backgroundColor.green())
.arg(backgroundColor.blue());
m_keyLabel->setStyleSheet(keyStyle);
}
}
7 changes: 7 additions & 0 deletions src/utils/monitorpreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MonitorPreview : public QWidget
QWidget* parent = nullptr);

int monitorIndex() const { return m_monitorIndex; }
void setSelected(bool selected);

signals:
void monitorSelected(int index);
Expand All @@ -30,8 +31,14 @@ class MonitorPreview : public QWidget
void leaveEvent(QEvent* event) override;

private:
void updateStyle();

int m_monitorIndex;
bool m_selected;
bool m_mouseHovered;
QColor m_uiColor;
QColor m_contrastColor;
QLabel* m_imageLabel;
QLabel* m_keyLabel;
QLabel* m_textLabel;
};
Loading
Loading