Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: now flameshot has ability to show screenshot history #3619

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
37 changes: 19 additions & 18 deletions src/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
target_sources(
flameshot
PRIVATE buttonlistview.cpp
cacheutils.cpp
clickablelabel.cpp
colorpickereditmode.cpp
colorpickereditor.cpp
configerrordetails.cpp
configresolver.cpp
configwindow.cpp
extendedslider.cpp
filenameeditor.cpp
generalconf.cpp
setshortcutwidget.cpp
shortcutswidget.cpp
strftimechooserwidget.cpp
styleoverride.cpp
uicoloreditor.cpp
visualseditor.cpp
flameshot
PRIVATE buttonlistview.cpp
cacheutils.cpp
clickablelabel.cpp
colorpickereditmode.cpp
colorpickereditor.cpp
configerrordetails.cpp
configresolver.cpp
configwindow.cpp
extendedslider.cpp
filenameeditor.cpp
generalconf.cpp
setshortcutwidget.cpp
shortcutswidget.cpp
strftimechooserwidget.cpp
styleoverride.cpp
uicoloreditor.cpp
visualseditor.cpp
backtrackingimpl.cpp
)
184 changes: 184 additions & 0 deletions src/config/backtrackingimpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#include "backtrackingimpl.h"

#include "abstractlogger.h"

#include <QLabel>
#include <QVBoxLayout>
#include <QtCore/qstandardpaths.h>
#include <QtCore/qstring.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qcheckbox.h>
#include <QtWidgets/qfiledialog.h>
#include <QtWidgets/qgroupbox.h>
#include <QtWidgets/qlayoutitem.h>
#include <QtWidgets/qlineedit.h>
#include <QtWidgets/qmessagebox.h>
#include <QtWidgets/qpushbutton.h>
#include <QtWidgets/qsizepolicy.h>
#include <QtWidgets/qspinbox.h>
#include <QtWidgets/qwidget.h>
#include <cacheutils.h>
#include <confighandler.h>

namespace btk {
class BackTrackerConfigPrivate
{
friend class BackTrackerConfigGroup;
constexpr static int limits_max = 200;
constexpr static int limits_min = 0;

public:
QCheckBox* enableBackTrackerCheckBox;
QLineEdit* backTrackerPath;
QPushButton* choosePathBtn;
QPushButton* rollbackBtn;
QSpinBox* cacheNumbersSpinBox;
};

BackTrackerConfigGroup::BackTrackerConfigGroup(QWidget* parent)
: QGroupBox(tr("BackTracking"), parent)
, p(new BackTrackerConfigPrivate)
{
init();
}
BackTrackerConfigGroup::~BackTrackerConfigGroup()
{
delete p;
p = nullptr;
}
void BackTrackerConfigGroup::init()
{
p->enableBackTrackerCheckBox = new QCheckBox(tr("enable"), this);
p->enableBackTrackerCheckBox->setToolTip(tr("If enable the backtraking"));
p->enableBackTrackerCheckBox->setChecked(
ConfigHandler().backtrackingEnable());
connect(p->enableBackTrackerCheckBox,
&QCheckBox::clicked,
this,
&BackTrackerConfigGroup::setEnable);
setFlat(true);
auto* vboxLayout = new QVBoxLayout();
setLayout(vboxLayout);

auto* firstHBoxLayout = new QHBoxLayout();
vboxLayout->addLayout(firstHBoxLayout);
firstHBoxLayout->addWidget(p->enableBackTrackerCheckBox);

auto* spinboxLabel = new QLabel(tr("cache size"));
spinboxLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);

p->cacheNumbersSpinBox = new QSpinBox();
p->cacheNumbersSpinBox->setValue(ConfigHandler().backtrackingCacheLimits());
p->cacheNumbersSpinBox->setFixedWidth(50);
p->cacheNumbersSpinBox->setMinimum(BackTrackerConfigPrivate::limits_min);
p->cacheNumbersSpinBox->setMaximum(BackTrackerConfigPrivate::limits_max);

connect(p->cacheNumbersSpinBox,
&QSpinBox::textChanged,
[this](QString text) { return setCacheLimits(text.toInt()); });

auto* hSpacer =
new QSpacerItem(40, 20, QSizePolicy::Preferred, QSizePolicy::Minimum);
firstHBoxLayout->addItem(hSpacer);
firstHBoxLayout->addWidget(p->cacheNumbersSpinBox);
firstHBoxLayout->addWidget(spinboxLabel);

auto* choosePathLayout = new QHBoxLayout();
vboxLayout->addLayout(choosePathLayout);

p->backTrackerPath = new QLineEdit();
p->backTrackerPath->setReadOnly(true);
p->backTrackerPath->setPlaceholderText(
tr("choose your path to save backtracking cache"));
p->backTrackerPath->setToolTip(
tr("choose your path to save backtracking cache\ndefaults to: %1")
.arg(getCachePath()));
p->backTrackerPath->setStyleSheet(R"(
border-right-width: 0px;
)");

choosePathLayout->addWidget(p->backTrackerPath);

p->rollbackBtn = new QPushButton(tr("↩️"));
p->rollbackBtn->setFixedWidth(20);
p->rollbackBtn->setToolTip(tr("set path to default"));
p->rollbackBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
p->rollbackBtn->setStyleSheet(QString(R"(
QPushButton{
margin-right: 14px;
// margin-top: 0px;
// margin-bottom: 0px;
border-width: 0px;
}
)"));
connect(p->rollbackBtn,
&QPushButton::clicked,
this,
&BackTrackerConfigGroup::pathRollBack);
choosePathLayout->addWidget(p->rollbackBtn);
choosePathLayout->setSpacing(0);

p->choosePathBtn = new QPushButton(tr("Change.."));
choosePathLayout->addWidget(p->choosePathBtn);
connect(p->choosePathBtn,
&QPushButton::clicked,
this,
&BackTrackerConfigGroup::browseFolder);

if (ConfigHandler().backtrackingCachePath().isEmpty()) {
ConfigHandler().setBacktrackingCachePath(getCachePath());
}
p->backTrackerPath->setText(ConfigHandler().backtrackingCachePath());
}
QString BackTrackerConfigGroup::chooseFolder(const QString& defaultPath)
{
QString path = defaultPath;
if (defaultPath.isEmpty()) {
path = getCachePath();
}
path = QFileDialog::getExistingDirectory(
this,
tr("Choose a Folder"),
path,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (path.isEmpty()) {
return path;
}

if (!QFileInfo(path).isWritable()) {
QMessageBox::about(
this, tr("Error"), tr("Unable to write to directory."));
return {};
}

return path;
}
void BackTrackerConfigGroup::browseFolder()
{
auto targetFolder = chooseFolder(ConfigHandler().backtrackingCachePath());
if (targetFolder.isEmpty()) {
AbstractLogger::error()
<< "backtracking: cache folder path you choose is empty";
return;
}
p->backTrackerPath->setText(targetFolder);
ConfigHandler().setBacktrackingCachePath(targetFolder);
}
void BackTrackerConfigGroup::setEnable(bool value)
{
ConfigHandler().setBacktrackingEnable(value);
}
void BackTrackerConfigGroup::pathRollBack()
{
ConfigHandler().setBacktrackingCachePath(getCachePath());
p->backTrackerPath->setText(getCachePath());
}
void BackTrackerConfigGroup::setCacheLimits(int val)
{
if (val > BackTrackerConfigPrivate::limits_max ||
val < BackTrackerConfigPrivate::limits_min) {
return;
}
ConfigHandler().setBacktrackingCacheLimits(val);
}
} // btk
42 changes: 42 additions & 0 deletions src/config/backtrackingimpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Created by michael on 24-6-5.
//

#ifndef BACKTRACKINGIMPL_H
#define BACKTRACKINGIMPL_H

#include <QtWidgets/qgroupbox.h>
#include <QtWidgets/qwidget.h>
#include <memory>
#include <qobjectdefs.h>

class QVBoxLayout;
class QCheckBox;
class QPushButton;
class QLabel;
class QLineEdit;
class QSpinBox;
class QComboBox;
namespace btk {

class BackTrackerConfigPrivate;
class BackTrackerConfigGroup : public QGroupBox
{
Q_OBJECT
public:
explicit BackTrackerConfigGroup(QWidget* parent = nullptr);
~BackTrackerConfigGroup() override;

private:
BackTrackerConfigPrivate* p;
void init();
QString chooseFolder(const QString& defaultPath);
public slots:
void browseFolder();
void setEnable(bool value);
void pathRollBack();
void setCacheLimits(int val);
};
} // btk

#endif // BACKTRACKINGIMPL_H
7 changes: 7 additions & 0 deletions src/config/generalconf.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
#include "generalconf.h"
#include "backtrackingimpl.h"
#include "src/core/flameshot.h"
#include "src/utils/confighandler.h"
#include <QCheckBox>
Expand Down Expand Up @@ -49,6 +50,7 @@ GeneralConf::GeneralConf(QWidget* parent)
initUseJpgForClipboard();
initCopyOnDoubleClick();
initSaveAfterCopy();
initBackTrackerSettings();
initCopyPathAfterSave();
initCopyAndCloseAfterUpload();
initUploadWithoutConfirmation();
Expand Down Expand Up @@ -798,6 +800,11 @@ void GeneralConf::initJpegQuality()
this,
&GeneralConf::setJpegQuality);
}
void GeneralConf::initBackTrackerSettings()
{
m_backTrackingConfig = new btk::BackTrackerConfigGroup(this);
m_layout->addWidget(m_backTrackingConfig);
}

void GeneralConf::setSelGeoHideTime(int v)
{
Expand Down
8 changes: 7 additions & 1 deletion src/config/generalconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class QLabel;
class QLineEdit;
class QSpinBox;
class QComboBox;

namespace btk {
class BackTrackerConfigGroup;
}
class GeneralConf : public QWidget
{
Q_OBJECT
Expand Down Expand Up @@ -93,6 +95,8 @@ private slots:
void initShowSelectionGeometry();
void initJpegQuality();

void initBackTrackerSettings();

void _updateComponents(bool allowEmptySavePath);

// class members
Expand Down Expand Up @@ -136,4 +140,6 @@ private slots:
QComboBox* m_selectGeometryLocation;
QSpinBox* m_xywhTimeout;
QSpinBox* m_jpegQuality;

btk::BackTrackerConfigGroup* m_backTrackingConfig;
};
2 changes: 1 addition & 1 deletion src/core/flameshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req)
m_captureWindow->raise();
#else
m_captureWindow->showFullScreen();
// m_captureWindow->show(); // For CaptureWidget Debugging under Linux
// m_captureWindow->show(); // For CaptureWidget Debugging under Linux
#endif
return m_captureWindow;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/capturetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CaptureTool : public QObject
{}

// TODO unused
virtual void setCapture(const QPixmap& pixmap){};
virtual void setCapture(const QPixmap& pixmap) {};

// Returns false when the tool is in an inconsistent state and shouldn't
// be included in the tool undo/redo stack.
Expand Down
2 changes: 2 additions & 0 deletions src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target_sources(
valuehandler.h
request.h
strfparse.h
capturehistoryutils.h
)

target_sources(
Expand All @@ -27,6 +28,7 @@ target_sources(
history.cpp
strfparse.cpp
request.cpp
capturehistoryutils.cpp
)

IF (WIN32)
Expand Down
Loading