Code refactoring - change code style to the new clang-format rules

This commit is contained in:
Yuriy Puchkov
2020-09-23 15:24:16 +03:00
parent 5a62cd3b13
commit b88a5fbce8
175 changed files with 6200 additions and 5356 deletions

View File

@@ -21,34 +21,38 @@
#include <QListWidgetItem>
#include <algorithm>
ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) {
ButtonListView::ButtonListView(QWidget* parent)
: QListWidget(parent)
{
setMouseTracking(true);
setFlow(QListWidget::TopToBottom);
initButtonList();
updateComponents();
connect(this, &QListWidget::itemClicked, this,
&ButtonListView::reverseItemCheck);
connect(
this, &QListWidget::itemClicked, this, &ButtonListView::reverseItemCheck);
}
void ButtonListView::initButtonList() {
void ButtonListView::initButtonList()
{
ToolFactory factory;
auto listTypes = CaptureButton::getIterableButtonTypes();
for (const CaptureButton::ButtonType t: listTypes) {
CaptureTool *tool = factory.CreateTool(t);
for (const CaptureButton::ButtonType t : listTypes) {
CaptureTool* tool = factory.CreateTool(t);
// add element to the local map
m_buttonTypeByName.insert(tool->name(), t);
// init the menu option
QListWidgetItem *m_buttonItem = new QListWidgetItem(this);
QListWidgetItem* m_buttonItem = new QListWidgetItem(this);
// when the background is lighter than gray, it uses the white icons
QColor bgColor = this->palette().color(QWidget::backgroundRole());
m_buttonItem->setIcon(tool->icon(bgColor, false));
m_buttonItem->setFlags(Qt::ItemIsUserCheckable);
QColor foregroundColor = this->palette().color(QWidget::foregroundRole());
QColor foregroundColor =
this->palette().color(QWidget::foregroundRole());
m_buttonItem->setForeground(foregroundColor);
m_buttonItem->setText(tool->name());
@@ -57,15 +61,16 @@ void ButtonListView::initButtonList() {
}
}
void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
void ButtonListView::updateActiveButtons(QListWidgetItem* item)
{
CaptureButton::ButtonType bType = m_buttonTypeByName[item->text()];
if (item->checkState() == Qt::Checked) {
m_listButtons.append(bType);
// TODO refactor so we don't need external sorts
using bt = CaptureButton::ButtonType;
std::sort(m_listButtons.begin(), m_listButtons.end(), [](bt a, bt b){
std::sort(m_listButtons.begin(), m_listButtons.end(), [](bt a, bt b) {
return CaptureButton::getPriorityByButton(a) <
CaptureButton::getPriorityByButton(b);
CaptureButton::getPriorityByButton(b);
});
} else {
m_listButtons.remove(m_listButtons.indexOf(bType));
@@ -73,7 +78,8 @@ void ButtonListView::updateActiveButtons(QListWidgetItem *item) {
ConfigHandler().setButtons(m_listButtons);
}
void ButtonListView::reverseItemCheck(QListWidgetItem *item){
void ButtonListView::reverseItemCheck(QListWidgetItem* item)
{
if (item->checkState() == Qt::Checked) {
item->setCheckState(Qt::Unchecked);
} else {
@@ -82,18 +88,20 @@ void ButtonListView::reverseItemCheck(QListWidgetItem *item){
updateActiveButtons(item);
}
void ButtonListView::selectAll() {
void ButtonListView::selectAll()
{
ConfigHandler().setAllTheButtons();
for(int i = 0; i < this->count(); ++i) {
for (int i = 0; i < this->count(); ++i) {
QListWidgetItem* item = this->item(i);
item->setCheckState(Qt::Checked);
}
}
void ButtonListView::updateComponents() {
void ButtonListView::updateComponents()
{
m_listButtons = ConfigHandler().getButtons();
auto listTypes = CaptureButton::getIterableButtonTypes();
for(int i = 0; i < this->count(); ++i) {
for (int i = 0; i < this->count(); ++i) {
QListWidgetItem* item = this->item(i);
auto elem = static_cast<CaptureButton::ButtonType>(listTypes.at(i));
if (m_listButtons.contains(elem)) {

View File

@@ -20,16 +20,17 @@
#include "src/widgets/capture/capturebutton.h"
#include <QListWidget>
class ButtonListView : public QListWidget {
class ButtonListView : public QListWidget
{
public:
explicit ButtonListView(QWidget *parent= nullptr);
explicit ButtonListView(QWidget* parent = nullptr);
public slots:
void selectAll();
void updateComponents();
private slots:
void reverseItemCheck(QListWidgetItem *);
void reverseItemCheck(QListWidgetItem*);
protected:
void initButtonList();
@@ -38,5 +39,5 @@ private:
QVector<CaptureButton::ButtonType> m_listButtons;
QMap<QString, CaptureButton::ButtonType> m_buttonTypeByName;
void updateActiveButtons(QListWidgetItem *);
void updateActiveButtons(QListWidgetItem*);
};

View File

@@ -17,14 +17,17 @@
#include "clickablelabel.h"
ClickableLabel::ClickableLabel(QWidget *parent) : QLabel(parent) {
ClickableLabel::ClickableLabel(QWidget* parent)
: QLabel(parent)
{}
}
ClickableLabel::ClickableLabel(QString s, QWidget *parent) : QLabel(parent) {
ClickableLabel::ClickableLabel(QString s, QWidget* parent)
: QLabel(parent)
{
setText(s);
}
void ClickableLabel::mousePressEvent(QMouseEvent *) {
void ClickableLabel::mousePressEvent(QMouseEvent*)
{
emit clicked();
}

View File

@@ -19,15 +19,16 @@
#include <QLabel>
class ClickableLabel : public QLabel {
class ClickableLabel : public QLabel
{
Q_OBJECT
public:
explicit ClickableLabel(QWidget *parent = nullptr);
ClickableLabel(QString s, QWidget *parent = nullptr);
explicit ClickableLabel(QWidget* parent = nullptr);
ClickableLabel(QString s, QWidget* parent = nullptr);
signals:
void clicked();
private:
void mousePressEvent (QMouseEvent *);
void mousePressEvent(QMouseEvent*);
};

View File

@@ -17,34 +17,40 @@
#include "extendedslider.h"
ExtendedSlider::ExtendedSlider(QWidget *parent)
: QSlider(parent)
ExtendedSlider::ExtendedSlider(QWidget* parent)
: QSlider(parent)
{
connect(this, &ExtendedSlider::valueChanged,
this, &ExtendedSlider::updateTooltip);
connect(this, &ExtendedSlider::sliderMoved,
this, &ExtendedSlider::fireTimer);
connect(this,
&ExtendedSlider::valueChanged,
this,
&ExtendedSlider::updateTooltip);
connect(
this, &ExtendedSlider::sliderMoved, this, &ExtendedSlider::fireTimer);
m_timer.setSingleShot(true);
connect(&m_timer, &QTimer::timeout,
this, &ExtendedSlider::modificationsEnded);
connect(
&m_timer, &QTimer::timeout, this, &ExtendedSlider::modificationsEnded);
}
int ExtendedSlider::mappedValue(int min, int max) {
int ExtendedSlider::mappedValue(int min, int max)
{
qreal progress =
((value() - minimum())) / static_cast<qreal>(maximum() - minimum());
((value() - minimum())) / static_cast<qreal>(maximum() - minimum());
return min + (max - min) * progress;
}
void ExtendedSlider::setMapedValue(int min, int val, int max) {
void ExtendedSlider::setMapedValue(int min, int val, int max)
{
qreal progress = ((val - min) + 1) / static_cast<qreal>(max - min);
int value = minimum() + (maximum() - minimum()) * progress;
setValue(value);
}
void ExtendedSlider::updateTooltip() {
setToolTip(QString::number(value())+"%");
void ExtendedSlider::updateTooltip()
{
setToolTip(QString::number(value()) + "%");
}
void ExtendedSlider::fireTimer() {
void ExtendedSlider::fireTimer()
{
m_timer.start(500);
}

View File

@@ -20,10 +20,11 @@
#include <QSlider>
#include <QTimer>
class ExtendedSlider : public QSlider {
class ExtendedSlider : public QSlider
{
Q_OBJECT
public:
explicit ExtendedSlider(QWidget *parent = nullptr);
explicit ExtendedSlider(QWidget* parent = nullptr);
int mappedValue(int min, int max);
void setMapedValue(int min, int val, int max);

View File

@@ -16,21 +16,24 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "filenameeditor.h"
#include "src/utils/filenamehandler.h"
#include "src/utils/confighandler.h"
#include "src/config/strftimechooserwidget.h"
#include <QVBoxLayout>
#include "src/utils/confighandler.h"
#include "src/utils/filenamehandler.h"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
FileNameEditor::FileNameEditor(QWidget *parent) : QWidget(parent) {
FileNameEditor::FileNameEditor(QWidget* parent)
: QWidget(parent)
{
initWidgets();
initLayout();
}
void FileNameEditor::initLayout() {
void FileNameEditor::initLayout()
{
m_layout = new QVBoxLayout(this);
auto infoLabel = new QLabel(tr("Edit the name of your captures:"), this);
infoLabel->setFixedHeight(20);
@@ -41,14 +44,15 @@ void FileNameEditor::initLayout() {
m_layout->addWidget(new QLabel(tr("Preview:")));
m_layout->addWidget(m_outputLabel);
QHBoxLayout *horizLayout = new QHBoxLayout();
QHBoxLayout* horizLayout = new QHBoxLayout();
horizLayout->addWidget(m_saveButton);
horizLayout->addWidget(m_resetButton);
horizLayout->addWidget(m_clearButton);
m_layout->addLayout(horizLayout);
}
void FileNameEditor::initWidgets() {
void FileNameEditor::initWidgets()
{
m_nameHandler = new FileNameHandler(this);
// editor
@@ -61,55 +65,67 @@ void FileNameEditor::initWidgets() {
QString foreground = this->palette().foreground().color().name();
m_outputLabel->setStyleSheet(QStringLiteral("color: %1").arg(foreground));
QPalette pal = m_outputLabel->palette();
QColor color = pal.color(QPalette::Disabled, m_outputLabel->backgroundRole());
QColor color =
pal.color(QPalette::Disabled, m_outputLabel->backgroundRole());
pal.setColor(QPalette::Active, m_outputLabel->backgroundRole(), color);
m_outputLabel->setPalette(pal);
connect(m_nameEditor, &QLineEdit::textChanged, this,
connect(m_nameEditor,
&QLineEdit::textChanged,
this,
&FileNameEditor::showParsedPattern);
updateComponents();
// helper buttons
m_helperButtons = new StrftimeChooserWidget(this);
connect(m_helperButtons, &StrftimeChooserWidget::variableEmitted,
this, &FileNameEditor::addToNameEditor);
connect(m_helperButtons,
&StrftimeChooserWidget::variableEmitted,
this,
&FileNameEditor::addToNameEditor);
// save
m_saveButton = new QPushButton(tr("Save"), this);
connect(m_saveButton, &QPushButton::clicked, this, &FileNameEditor::savePattern);
connect(
m_saveButton, &QPushButton::clicked, this, &FileNameEditor::savePattern);
m_saveButton->setToolTip(tr("Saves the pattern"));
// reset
m_resetButton = new QPushButton(tr("Reset"), this);
connect(m_resetButton, &QPushButton::clicked,
this, &FileNameEditor::resetName);
connect(
m_resetButton, &QPushButton::clicked, this, &FileNameEditor::resetName);
m_resetButton->setToolTip(tr("Restores the saved pattern"));
// clear
m_clearButton = new QPushButton(tr("Clear"), this);
connect(m_clearButton, &QPushButton::clicked, this,
[this](){ m_nameEditor->setText(QString());
connect(m_clearButton, &QPushButton::clicked, this, [this]() {
m_nameEditor->setText(QString());
});
m_clearButton->setToolTip(tr("Deletes the name"));}
m_clearButton->setToolTip(tr("Deletes the name"));
}
void FileNameEditor::savePattern() {
void FileNameEditor::savePattern()
{
QString pattern = m_nameEditor->text();
m_nameHandler->setPattern(pattern);
}
void FileNameEditor::showParsedPattern(const QString &p) {
void FileNameEditor::showParsedPattern(const QString& p)
{
QString output = m_nameHandler->parseFilename(p);
m_outputLabel->setText(output);
}
void FileNameEditor::resetName() {
void FileNameEditor::resetName()
{
m_nameEditor->setText(ConfigHandler().filenamePatternValue());
}
void FileNameEditor::addToNameEditor(QString s) {
void FileNameEditor::addToNameEditor(QString s)
{
m_nameEditor->setText(m_nameEditor->text() + s);
m_nameEditor->setFocus();
}
void FileNameEditor::updateComponents() {
void FileNameEditor::updateComponents()
{
m_nameEditor->setText(ConfigHandler().filenamePatternValue());
m_outputLabel->setText(m_nameHandler->parsedPattern());
}

View File

@@ -17,8 +17,8 @@
#pragma once
#include <QWidget>
#include <QPointer>
#include <QWidget>
class QVBoxLayout;
class QLineEdit;
@@ -26,20 +26,21 @@ class FileNameHandler;
class QPushButton;
class StrftimeChooserWidget;
class FileNameEditor : public QWidget {
class FileNameEditor : public QWidget
{
Q_OBJECT
public:
explicit FileNameEditor(QWidget *parent = nullptr);
explicit FileNameEditor(QWidget* parent = nullptr);
private:
QVBoxLayout *m_layout;
QLineEdit *m_outputLabel;
QLineEdit *m_nameEditor;
FileNameHandler *m_nameHandler;
StrftimeChooserWidget *m_helperButtons;
QPushButton *m_saveButton;
QPushButton *m_resetButton;
QPushButton *m_clearButton;
QVBoxLayout* m_layout;
QLineEdit* m_outputLabel;
QLineEdit* m_nameEditor;
FileNameHandler* m_nameHandler;
StrftimeChooserWidget* m_helperButtons;
QPushButton* m_saveButton;
QPushButton* m_resetButton;
QPushButton* m_clearButton;
void initLayout();
void initWidgets();
@@ -50,6 +51,6 @@ public slots:
private slots:
void savePattern();
void showParsedPattern(const QString &);
void showParsedPattern(const QString&);
void resetName();
};

View File

@@ -1,56 +1,69 @@
#include "filepathconfiguration.h"
#include "src/utils/filenamehandler.h"
#include "src/config/strftimechooserwidget.h"
#include "src/utils/confighandler.h"
#include "src/utils/filenamehandler.h"
#include <QCheckBox>
#include <QFileDialog>
#include <QDir>
#include <QVBoxLayout>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include "src/utils/confighandler.h"
#include <QVBoxLayout>
FilePathConfiguration::FilePathConfiguration(QWidget *parent) : QWidget(parent) {
FilePathConfiguration::FilePathConfiguration(QWidget* parent)
: QWidget(parent)
{
initWidgets();
initLayout();
}
void FilePathConfiguration::initLayout() {
void FilePathConfiguration::initLayout()
{
m_layout = new QVBoxLayout(this);
m_layout->addWidget(new QLabel(tr("Screenshot path default:")));
m_layout->addWidget(m_screenshotPathFixed);
m_layout->addWidget(m_screenshotPathFixedDefault);
m_layout->addStretch();
QHBoxLayout *horizScreenshotButtonsLayout = new QHBoxLayout();
QHBoxLayout* horizScreenshotButtonsLayout = new QHBoxLayout();
horizScreenshotButtonsLayout->addStretch();
horizScreenshotButtonsLayout->addWidget(m_screenshotPathFixedClear);
horizScreenshotButtonsLayout->addWidget(m_screenshotPathFixedBrowse);
m_layout->addLayout(horizScreenshotButtonsLayout);
}
void FilePathConfiguration::initWidgets() {
void FilePathConfiguration::initWidgets()
{
ConfigHandler config;
// Screenshot path default
m_screenshotPathFixed = new QCheckBox(tr("Use fixed path for screenshots to save"), this);
m_screenshotPathFixed =
new QCheckBox(tr("Use fixed path for screenshots to save"), this);
m_screenshotPathFixed->setChecked(!config.savePathFixed().isEmpty());
connect(m_screenshotPathFixed, SIGNAL(toggled(bool)), this, SLOT(sreenshotPathFixed()));
connect(m_screenshotPathFixed,
SIGNAL(toggled(bool)),
this,
SLOT(sreenshotPathFixed()));
m_screenshotPathFixedDefault = new QLineEdit(this);
m_screenshotPathFixedDefault->setText(config.savePathFixed());
m_screenshotPathFixedDefault->setDisabled(config.savePathFixed().isEmpty());
m_screenshotPathFixedBrowse = new QPushButton(tr("Browse"), this);
m_screenshotPathFixedBrowse->setDisabled(config.savePathFixed().isEmpty());
connect(m_screenshotPathFixedBrowse, SIGNAL(released()),this, SLOT (screenshotPathFixedSet()));
connect(m_screenshotPathFixedBrowse,
SIGNAL(released()),
this,
SLOT(screenshotPathFixedSet()));
m_screenshotPathFixedClear = new QPushButton(tr("Clear"), this);
m_screenshotPathFixedClear->setDisabled(config.savePathFixed().isEmpty());
connect(m_screenshotPathFixedClear, SIGNAL(released()),this, SLOT (screenshotPathFixedClear()));
connect(m_screenshotPathFixedClear,
SIGNAL(released()),
this,
SLOT(screenshotPathFixedClear()));
}
void FilePathConfiguration::sreenshotPathFixed() {
void FilePathConfiguration::sreenshotPathFixed()
{
bool status = m_screenshotPathFixedDefault->isEnabled();
m_screenshotPathFixedDefault->setEnabled(!status);
m_screenshotPathFixedBrowse->setEnabled(!status);
@@ -58,8 +71,10 @@ void FilePathConfiguration::sreenshotPathFixed() {
screenshotPathFixedClear();
}
void FilePathConfiguration::screenshotPathFixedSet() {
QFileDialog *dirDialog = new QFileDialog(this, tr("Select default path for Screenshots"));
void FilePathConfiguration::screenshotPathFixedSet()
{
QFileDialog* dirDialog =
new QFileDialog(this, tr("Select default path for Screenshots"));
dirDialog->setFileMode(QFileDialog::DirectoryOnly);
dirDialog->setOption(QFileDialog::ShowDirsOnly, true);
if (dirDialog->exec()) {
@@ -71,7 +86,8 @@ void FilePathConfiguration::screenshotPathFixedSet() {
}
}
void FilePathConfiguration::screenshotPathFixedClear() {
void FilePathConfiguration::screenshotPathFixedClear()
{
ConfigHandler config;
m_screenshotPathFixedDefault->setText("");
config.setSavePathFixed(m_screenshotPathFixedDefault->text());

View File

@@ -9,17 +9,18 @@ class QCheckBox;
class FileNameHandler;
class QPushButton;
class FilePathConfiguration : public QWidget {
class FilePathConfiguration : public QWidget
{
Q_OBJECT
public:
explicit FilePathConfiguration(QWidget *parent = nullptr);
explicit FilePathConfiguration(QWidget* parent = nullptr);
private:
QVBoxLayout *m_layout;
QCheckBox *m_screenshotPathFixed;
QLineEdit *m_screenshotPathFixedDefault;
QPushButton *m_screenshotPathFixedBrowse;
QPushButton *m_screenshotPathFixedClear;
QVBoxLayout* m_layout;
QCheckBox* m_screenshotPathFixed;
QLineEdit* m_screenshotPathFixedDefault;
QPushButton* m_screenshotPathFixedBrowse;
QPushButton* m_screenshotPathFixedClear;
void initLayout();
void initWidgets();

View File

@@ -1,11 +1,12 @@
#include "setshortcutwidget.h"
#include <QKeyEvent>
#include <QLayout>
#include <QLabel>
#include <QIcon>
#include <QKeyEvent>
#include <QLabel>
#include <QLayout>
#include <QPixmap>
SetShortcutDialog::SetShortcutDialog(QDialog *parent) : QDialog(parent)
SetShortcutDialog::SetShortcutDialog(QDialog* parent)
: QDialog(parent)
{
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowIcon(QIcon(":img/app/flameshot.svg"));
@@ -15,29 +16,32 @@ SetShortcutDialog::SetShortcutDialog(QDialog *parent) : QDialog(parent)
m_layout = new QVBoxLayout(this);
m_layout->setAlignment(Qt::AlignHCenter);
QLabel *infoTop = new QLabel(tr("Enter new shortcut to change "));
QLabel* infoTop = new QLabel(tr("Enter new shortcut to change "));
infoTop->setMargin(10);
infoTop->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoTop);
QLabel *infoIcon = new QLabel();
QLabel* infoIcon = new QLabel();
infoIcon->setAlignment(Qt::AlignCenter);
infoIcon->setPixmap(QPixmap(":/img/app/keyboard.svg"));
m_layout->addWidget(infoIcon);
m_layout->addWidget(infoIcon);
QLabel *infoBottom = new QLabel(tr("Press Esc to cancel or Backspace to disable the keyboard shortcut."));
QLabel* infoBottom = new QLabel(
tr("Press Esc to cancel or Backspace to disable the keyboard shortcut."));
infoBottom->setMargin(10);
infoBottom->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoBottom);
}
const QKeySequence& SetShortcutDialog::shortcut() {
const QKeySequence& SetShortcutDialog::shortcut()
{
return m_ks;
}
void SetShortcutDialog::keyPressEvent(QKeyEvent *ke) {
void SetShortcutDialog::keyPressEvent(QKeyEvent* ke)
{
if (ke->modifiers() & Qt::ShiftModifier)
m_modifier += "Shift+";
if (ke->modifiers() & Qt::ControlModifier)
@@ -51,7 +55,8 @@ void SetShortcutDialog::keyPressEvent(QKeyEvent *ke) {
m_ks = QKeySequence(m_modifier + key);
}
void SetShortcutDialog::keyReleaseEvent(QKeyEvent *event) {
void SetShortcutDialog::keyReleaseEvent(QKeyEvent* event)
{
if (m_ks == QKeySequence(Qt::Key_Escape)) {
reject();
}

View File

@@ -1,28 +1,27 @@
#ifndef SETSHORTCUTWIDGET_H
#define SETSHORTCUTWIDGET_H
#include <QObject>
#include <QDialog>
#include <QKeySequence>
#include <QObject>
class QVBoxLayout;
class SetShortcutDialog : public QDialog
{
Q_OBJECT
public:
explicit SetShortcutDialog(QDialog *parent = nullptr);
explicit SetShortcutDialog(QDialog* parent = nullptr);
const QKeySequence& shortcut();
public:
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *event);
void keyPressEvent(QKeyEvent*);
void keyReleaseEvent(QKeyEvent* event);
signals:
private:
QVBoxLayout *m_layout;
QVBoxLayout* m_layout;
QString m_modifier;
QKeySequence m_ks;
};

View File

@@ -1,32 +1,33 @@
#include "shortcutswidget.h"
#include "setshortcutwidget.h"
#include <QIcon>
#include <QVBoxLayout>
#include <QTableWidget>
#include <QHeaderView>
#include <QLabel>
#include <QIcon>
#include <QKeyEvent>
#include <QLabel>
#include <QStringList>
#include <QTableWidget>
#include <QVBoxLayout>
#include <QVector>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QCursor>
#include <QGuiApplication>
#include <QRect>
#include <QScreen>
#include <QGuiApplication>
#endif
#include <QDebug>
ShortcutsWidget::ShortcutsWidget(QWidget *parent) : QWidget(parent) {
ShortcutsWidget::ShortcutsWidget(QWidget* parent)
: QWidget(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowIcon(QIcon(":img/app/flameshot.svg"));
setWindowTitle(tr("Hot Keys"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
QRect position = frameGeometry();
QScreen *screen = QGuiApplication::screenAt(QCursor::pos());
QScreen* screen = QGuiApplication::screenAt(QCursor::pos());
position.moveCenter(screen->availableGeometry().center());
move(position.topLeft());
#endif
@@ -39,11 +40,13 @@ ShortcutsWidget::ShortcutsWidget(QWidget *parent) : QWidget(parent) {
show();
}
const QVector<QStringList> &ShortcutsWidget::shortcuts() {
const QVector<QStringList>& ShortcutsWidget::shortcuts()
{
return m_shortcuts;
}
void ShortcutsWidget::initInfoTable() {
void ShortcutsWidget::initInfoTable()
{
m_table = new QTableWidget(this);
m_table->setToolTip(tr("Available shortcuts in the screen capture mode."));
@@ -59,17 +62,20 @@ void ShortcutsWidget::initInfoTable() {
QStringList names;
names << tr("Description") << tr("Key");
m_table->setHorizontalHeaderLabels(names);
connect(m_table, SIGNAL(cellClicked(int, int)), this, SLOT(slotShortcutCellClicked(int, int)));
connect(m_table,
SIGNAL(cellClicked(int, int)),
this,
SLOT(slotShortcutCellClicked(int, int)));
//add content
for (int i= 0; i < shortcuts().size(); ++i){
// add content
for (int i = 0; i < shortcuts().size(); ++i) {
m_table->setItem(i, 0, new QTableWidgetItem(m_shortcuts.at(i).at(1)));
QTableWidgetItem* item = new QTableWidgetItem(m_shortcuts.at(i).at(2));
item->setTextAlignment( Qt::AlignCenter );
item->setTextAlignment(Qt::AlignCenter);
m_table->setItem(i, 1, item);
if( m_shortcuts.at(i).at(0).isEmpty() ) {
if (m_shortcuts.at(i).at(0).isEmpty()) {
QFont font;
font.setBold(true);
item->setFont(font);
@@ -81,7 +87,7 @@ void ShortcutsWidget::initInfoTable() {
// Read-only table items
for (int x = 0; x < m_table->rowCount(); ++x) {
for (int y = 0; y < m_table->columnCount(); ++y) {
QTableWidgetItem *item = m_table->item(x, y);
QTableWidgetItem* item = m_table->item(x, y);
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
}
}
@@ -97,14 +103,16 @@ void ShortcutsWidget::initInfoTable() {
QSizePolicy::Expanding);
}
void ShortcutsWidget::slotShortcutCellClicked(int row, int col) {
void ShortcutsWidget::slotShortcutCellClicked(int row, int col)
{
if (col == 1) {
// Ignore non-changable shortcuts
if( Qt::ItemIsEnabled != (Qt::ItemIsEnabled & m_table->item(row, col)->flags()) ) {
if (Qt::ItemIsEnabled !=
(Qt::ItemIsEnabled & m_table->item(row, col)->flags())) {
return;
}
SetShortcutDialog *setShortcutDialog = new SetShortcutDialog();
SetShortcutDialog* setShortcutDialog = new SetShortcutDialog();
if (0 != setShortcutDialog->exec()) {
QString shortcutName = m_shortcuts.at(row).at(0);
QKeySequence shortcutValue = setShortcutDialog->shortcut();
@@ -115,8 +123,9 @@ void ShortcutsWidget::slotShortcutCellClicked(int row, int col) {
}
if (m_config.setShortcut(shortcutName, shortcutValue.toString())) {
QTableWidgetItem* item = new QTableWidgetItem(shortcutValue.toString());
item->setTextAlignment( Qt::AlignCenter );
QTableWidgetItem* item =
new QTableWidgetItem(shortcutValue.toString());
item->setTextAlignment(Qt::AlignCenter);
item->setFlags(item->flags() ^ Qt::ItemIsEditable);
m_table->setItem(row, col, item);
}

View File

@@ -2,10 +2,9 @@
#define HOTKEYSCONFIG_H
#include "src/utils/confighandler.h"
#include <QWidget>
#include <QVector>
#include <QStringList>
#include <QVector>
#include <QWidget>
class SetShortcutDialog;
class QTableWidget;
@@ -15,8 +14,8 @@ class ShortcutsWidget : public QWidget
{
Q_OBJECT
public:
explicit ShortcutsWidget(QWidget *parent = nullptr);
const QVector<QStringList> &shortcuts();
explicit ShortcutsWidget(QWidget* parent = nullptr);
const QVector<QStringList>& shortcuts();
private:
void initInfoTable();
@@ -26,8 +25,8 @@ private slots:
private:
ConfigHandler m_config;
QTableWidget *m_table;
QVBoxLayout *m_layout;
QTableWidget* m_table;
QVBoxLayout* m_layout;
QVector<QStringList> m_shortcuts;
};

View File

@@ -16,53 +16,57 @@
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "strftimechooserwidget.h"
#include <QMap>
#include <QGridLayout>
#include <QMap>
#include <QPushButton>
StrftimeChooserWidget::StrftimeChooserWidget(QWidget *parent) : QWidget(parent) {
QGridLayout *layout = new QGridLayout(this);
StrftimeChooserWidget::StrftimeChooserWidget(QWidget* parent)
: QWidget(parent)
{
QGridLayout* layout = new QGridLayout(this);
auto k = m_buttonData.keys();
int middle = k.length()/2;
int middle = k.length() / 2;
// add the buttons in 2 columns (they need to be even)
for (int i = 0; i < 2; i++) {
for (int j = 0; j < middle; j++) {
QString key = k.last();
k.pop_back();
QString variable = m_buttonData.value(key);
QPushButton *button = new QPushButton(this);
QPushButton* button = new QPushButton(this);
button->setText(tr(key.toStdString().data()));
button->setToolTip(variable);
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
button->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
button->setMinimumHeight(25);
layout->addWidget(button, j, i);
connect(button, &QPushButton::clicked,
this, [variable, this](){emit variableEmitted(variable);});
connect(button, &QPushButton::clicked, this, [variable, this]() {
emit variableEmitted(variable);
});
}
}
setLayout(layout);
}
QMap<QString, QString> StrftimeChooserWidget::m_buttonData {
{ QT_TR_NOOP("Century (00-99)"), "%C"},
{ QT_TR_NOOP("Year (00-99)"), "%y"},
{ QT_TR_NOOP("Year (2000)"), "%Y"},
{ QT_TR_NOOP("Month Name (jan)"), "%b"},
{ QT_TR_NOOP("Month Name (january)"), "%B"},
{ QT_TR_NOOP("Month (01-12)"), "%m"},
{ QT_TR_NOOP("Week Day (1-7)"), "%u"},
{ QT_TR_NOOP("Week (01-53)"), "%V"},
{ QT_TR_NOOP("Day Name (mon)"), "%a"},
{ QT_TR_NOOP("Day Name (monday)"), "%A"},
{ QT_TR_NOOP("Day (01-31)"), "%d"},
{ QT_TR_NOOP("Day of Month (1-31)"), "%e"},
{ QT_TR_NOOP("Day (001-366)"), "%j"},
{ QT_TR_NOOP("Time (%H-%M-%S)"), "%T"},
{ QT_TR_NOOP("Time (%H-%M)"), "%R"},
{ QT_TR_NOOP("Hour (00-23)"), "%H"},
{ QT_TR_NOOP("Hour (01-12)"), "%I"},
{ QT_TR_NOOP("Minute (00-59)"), "%M"},
{ QT_TR_NOOP("Second (00-59)"), "%S"},
{ QT_TR_NOOP("Full Date (%m/%d/%y)"), "%D"},
{ QT_TR_NOOP("Full Date (%Y-%m-%d)"), "%F"},
QMap<QString, QString> StrftimeChooserWidget::m_buttonData{
{ QT_TR_NOOP("Century (00-99)"), "%C" },
{ QT_TR_NOOP("Year (00-99)"), "%y" },
{ QT_TR_NOOP("Year (2000)"), "%Y" },
{ QT_TR_NOOP("Month Name (jan)"), "%b" },
{ QT_TR_NOOP("Month Name (january)"), "%B" },
{ QT_TR_NOOP("Month (01-12)"), "%m" },
{ QT_TR_NOOP("Week Day (1-7)"), "%u" },
{ QT_TR_NOOP("Week (01-53)"), "%V" },
{ QT_TR_NOOP("Day Name (mon)"), "%a" },
{ QT_TR_NOOP("Day Name (monday)"), "%A" },
{ QT_TR_NOOP("Day (01-31)"), "%d" },
{ QT_TR_NOOP("Day of Month (1-31)"), "%e" },
{ QT_TR_NOOP("Day (001-366)"), "%j" },
{ QT_TR_NOOP("Time (%H-%M-%S)"), "%T" },
{ QT_TR_NOOP("Time (%H-%M)"), "%R" },
{ QT_TR_NOOP("Hour (00-23)"), "%H" },
{ QT_TR_NOOP("Hour (01-12)"), "%I" },
{ QT_TR_NOOP("Minute (00-59)"), "%M" },
{ QT_TR_NOOP("Second (00-59)"), "%S" },
{ QT_TR_NOOP("Full Date (%m/%d/%y)"), "%D" },
{ QT_TR_NOOP("Full Date (%Y-%m-%d)"), "%F" },
};

View File

@@ -19,13 +19,14 @@
#include <QWidget>
class StrftimeChooserWidget : public QWidget {
class StrftimeChooserWidget : public QWidget
{
Q_OBJECT
public:
explicit StrftimeChooserWidget(QWidget *parent = nullptr);
explicit StrftimeChooserWidget(QWidget* parent = nullptr);
signals:
void variableEmitted(const QString &);
void variableEmitted(const QString&);
private:
static QMap<QString, QString> m_buttonData;

View File

@@ -15,18 +15,20 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see <http://www.gnu.org/licenses/>.
#include "src/utils/confighandler.h"
#include "uicoloreditor.h"
#include "clickablelabel.h"
#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
#include <QHBoxLayout>
#include <QApplication>
#include <QVBoxLayout>
#include <QComboBox>
#include <QHBoxLayout>
#include <QMap>
#include <QSpacerItem>
#include <QVBoxLayout>
UIcolorEditor::UIcolorEditor(QWidget *parent) : QGroupBox(parent) {
UIcolorEditor::UIcolorEditor(QWidget* parent)
: QGroupBox(parent)
{
setTitle(tr("UI Color Editor"));
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_hLayout = new QHBoxLayout;
@@ -46,7 +48,8 @@ UIcolorEditor::UIcolorEditor(QWidget *parent) : QGroupBox(parent) {
updateComponents();
}
void UIcolorEditor::updateComponents() {
void UIcolorEditor::updateComponents()
{
ConfigHandler config;
m_uiColor = config.uiMainColorValue();
m_contrastColor = config.uiContrastColorValue();
@@ -60,7 +63,8 @@ void UIcolorEditor::updateComponents() {
}
// updateUIcolor updates the appearance of the buttons
void UIcolorEditor::updateUIcolor() {
void UIcolorEditor::updateUIcolor()
{
ConfigHandler config;
if (m_lastButtonPressed == m_buttonMainColor) {
config.setUIMainColor(m_uiColor);
@@ -70,7 +74,8 @@ void UIcolorEditor::updateUIcolor() {
}
// updateLocalColor updates the local button
void UIcolorEditor::updateLocalColor(const QColor c) {
void UIcolorEditor::updateLocalColor(const QColor c)
{
if (m_lastButtonPressed == m_buttonMainColor) {
m_uiColor = c;
} else {
@@ -79,16 +84,21 @@ void UIcolorEditor::updateLocalColor(const QColor c) {
m_lastButtonPressed->setColor(c);
}
void UIcolorEditor::initColorWheel() {
void UIcolorEditor::initColorWheel()
{
m_colorWheel = new color_widgets::ColorWheel(this);
connect(m_colorWheel, &color_widgets::ColorWheel::mouseReleaseOnColor, this,
connect(m_colorWheel,
&color_widgets::ColorWheel::mouseReleaseOnColor,
this,
&UIcolorEditor::updateUIcolor);
connect(m_colorWheel, &color_widgets::ColorWheel::colorChanged, this,
connect(m_colorWheel,
&color_widgets::ColorWheel::colorChanged,
this,
&UIcolorEditor::updateLocalColor);
const int size = GlobalValues::buttonBaseSize() * 3;
m_colorWheel->setMinimumSize(size, size);
m_colorWheel->setMaximumSize(size*2, size*2);
m_colorWheel->setMaximumSize(size * 2, size * 2);
m_colorWheel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_colorWheel->setToolTip(tr("Change the color moving the selectors and see"
" the changes in the preview buttons."));
@@ -96,32 +106,34 @@ void UIcolorEditor::initColorWheel() {
m_hLayout->addWidget(m_colorWheel);
}
void UIcolorEditor::initButtons() {
void UIcolorEditor::initButtons()
{
const int extraSize = GlobalValues::buttonBaseSize() / 3;
int frameSize = GlobalValues::buttonBaseSize() + extraSize;
m_vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this));
QGroupBox *frame = new QGroupBox();
QGroupBox* frame = new QGroupBox();
frame->setFixedSize(frameSize, frameSize);
m_buttonMainColor = new CaptureButton(m_buttonIconType, frame);
m_buttonMainColor->move(m_buttonMainColor->x() + extraSize/2, m_buttonMainColor->y() + extraSize/2);
QHBoxLayout *h1 = new QHBoxLayout();
m_buttonMainColor->move(m_buttonMainColor->x() + extraSize / 2,
m_buttonMainColor->y() + extraSize / 2);
QHBoxLayout* h1 = new QHBoxLayout();
h1->addWidget(frame);
m_labelMain = new ClickableLabel(tr("Main Color"), this);
h1->addWidget(m_labelMain);
m_vLayout->addLayout(h1);
m_buttonMainColor->setToolTip(tr("Click on this button to set the edition"
" mode of the main color."));
" mode of the main color."));
QGroupBox *frame2 = new QGroupBox();
QGroupBox* frame2 = new QGroupBox();
m_buttonContrast = new CaptureButton(m_buttonIconType, frame2);
m_buttonContrast->move(m_buttonContrast->x() + extraSize/2,
m_buttonContrast->y() + extraSize/2);
m_buttonContrast->move(m_buttonContrast->x() + extraSize / 2,
m_buttonContrast->y() + extraSize / 2);
QHBoxLayout *h2 = new QHBoxLayout();
QHBoxLayout* h2 = new QHBoxLayout();
h2->addWidget(frame2);
frame2->setFixedSize(frameSize, frameSize);
m_labelContrast = new ClickableLabel(tr("Contrast Color"), this);
@@ -130,22 +142,29 @@ void UIcolorEditor::initButtons() {
m_vLayout->addLayout(h2);
m_buttonContrast->setToolTip(tr("Click on this button to set the edition"
" mode of the contrast color."));
" mode of the contrast color."));
connect(m_buttonMainColor, &CaptureButton::pressedButton,
this, &UIcolorEditor::changeLastButton);
connect(m_buttonContrast, &CaptureButton::pressedButton,
this, &UIcolorEditor::changeLastButton);
connect(m_buttonMainColor,
&CaptureButton::pressedButton,
this,
&UIcolorEditor::changeLastButton);
connect(m_buttonContrast,
&CaptureButton::pressedButton,
this,
&UIcolorEditor::changeLastButton);
// clicking the labels changes the button too
connect(m_labelMain, &ClickableLabel::clicked,
this, [this]{ changeLastButton(m_buttonMainColor); });
connect(m_labelContrast, &ClickableLabel::clicked,
this, [this]{ changeLastButton(m_buttonContrast); });
connect(m_labelMain, &ClickableLabel::clicked, this, [this] {
changeLastButton(m_buttonMainColor);
});
connect(m_labelContrast, &ClickableLabel::clicked, this, [this] {
changeLastButton(m_buttonContrast);
});
m_lastButtonPressed = m_buttonMainColor;
}
// visual update for the selected button
void UIcolorEditor::changeLastButton(CaptureButton *b) {
void UIcolorEditor::changeLastButton(CaptureButton* b)
{
if (m_lastButtonPressed != b) {
m_lastButtonPressed = b;

View File

@@ -26,10 +26,11 @@ class QHBoxLayout;
class CaptureButton;
class ClickableLabel;
class UIcolorEditor : public QGroupBox {
class UIcolorEditor : public QGroupBox
{
Q_OBJECT
public:
explicit UIcolorEditor(QWidget *parent = nullptr);
explicit UIcolorEditor(QWidget* parent = nullptr);
public slots:
void updateComponents();
@@ -37,21 +38,22 @@ public slots:
private slots:
void updateUIcolor();
void updateLocalColor(const QColor);
void changeLastButton(CaptureButton *);
void changeLastButton(CaptureButton*);
private:
QColor m_uiColor, m_contrastColor;
CaptureButton *m_buttonMainColor;
ClickableLabel *m_labelMain;
CaptureButton *m_buttonContrast;
ClickableLabel *m_labelContrast;
CaptureButton *m_lastButtonPressed;
color_widgets::ColorWheel *m_colorWheel;
CaptureButton* m_buttonMainColor;
ClickableLabel* m_labelMain;
CaptureButton* m_buttonContrast;
ClickableLabel* m_labelContrast;
CaptureButton* m_lastButtonPressed;
color_widgets::ColorWheel* m_colorWheel;
static const CaptureButton::ButtonType m_buttonIconType = CaptureButton::TYPE_CIRCLE;
static const CaptureButton::ButtonType m_buttonIconType =
CaptureButton::TYPE_CIRCLE;
QHBoxLayout *m_hLayout;
QVBoxLayout *m_vLayout;
QHBoxLayout* m_hLayout;
QVBoxLayout* m_vLayout;
void initColorWheel();
void initButtons();

View File

@@ -17,44 +17,50 @@
#include "visualseditor.h"
#include "src/config/buttonlistview.h"
#include "src/config/extendedslider.h"
#include "src/config/uicoloreditor.h"
#include "src/utils/confighandler.h"
#include "src/config/extendedslider.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
VisualsEditor::VisualsEditor(QWidget *parent) : QWidget(parent) {
m_layout= new QVBoxLayout();
VisualsEditor::VisualsEditor(QWidget* parent)
: QWidget(parent)
{
m_layout = new QVBoxLayout();
setLayout(m_layout);
initWidgets();
}
void VisualsEditor::updateComponents() {
void VisualsEditor::updateComponents()
{
m_buttonList->updateComponents();
m_colorEditor->updateComponents();
int opacity = ConfigHandler().contrastOpacityValue();
m_opacitySlider->setMapedValue(0, opacity, 255);
}
void VisualsEditor::initOpacitySlider() {
void VisualsEditor::initOpacitySlider()
{
m_opacitySlider = new ExtendedSlider();
m_opacitySlider->setFocusPolicy(Qt::NoFocus);
m_opacitySlider->setOrientation(Qt::Horizontal);
m_opacitySlider->setRange(0, 100);
connect(m_opacitySlider, &ExtendedSlider::modificationsEnded,
this, &VisualsEditor::saveOpacity);
QHBoxLayout *localLayout = new QHBoxLayout();
connect(m_opacitySlider,
&ExtendedSlider::modificationsEnded,
this,
&VisualsEditor::saveOpacity);
QHBoxLayout* localLayout = new QHBoxLayout();
localLayout->addWidget(new QLabel(QStringLiteral("0%")));
localLayout->addWidget(m_opacitySlider);
localLayout->addWidget(new QLabel(QStringLiteral("100%")));
QLabel *label = new QLabel();
QLabel* label = new QLabel();
QString labelMsg = tr("Opacity of area outside selection:") + " %1%";
connect(m_opacitySlider, &ExtendedSlider::valueChanged,
this, [labelMsg, label](int val){
label->setText(labelMsg.arg(val));
});
connect(m_opacitySlider,
&ExtendedSlider::valueChanged,
this,
[labelMsg, label](int val) { label->setText(labelMsg.arg(val)); });
m_layout->addWidget(label);
m_layout->addLayout(localLayout);
@@ -62,12 +68,14 @@ void VisualsEditor::initOpacitySlider() {
m_opacitySlider->setMapedValue(0, opacity, 255);
}
void VisualsEditor::saveOpacity() {
void VisualsEditor::saveOpacity()
{
int value = m_opacitySlider->mappedValue(0, 255);
ConfigHandler().setContrastOpacity(value);
}
void VisualsEditor::initWidgets() {
void VisualsEditor::initWidgets()
{
m_colorEditor = new UIcolorEditor();
m_layout->addWidget(m_colorEditor);
@@ -81,7 +89,9 @@ void VisualsEditor::initWidgets() {
listLayout->addWidget(m_buttonList);
QPushButton* setAllButtons = new QPushButton(tr("Select All"));
connect(setAllButtons, &QPushButton::clicked,
m_buttonList, &ButtonListView::selectAll);
connect(setAllButtons,
&QPushButton::clicked,
m_buttonList,
&ButtonListView::selectAll);
listLayout->addWidget(setAllButtons);
}

View File

@@ -24,10 +24,11 @@ class QVBoxLayout;
class ButtonListView;
class UIcolorEditor;
class VisualsEditor : public QWidget {
class VisualsEditor : public QWidget
{
Q_OBJECT
public:
explicit VisualsEditor(QWidget *parent = nullptr);
explicit VisualsEditor(QWidget* parent = nullptr);
public slots:
void updateComponents();
@@ -36,10 +37,10 @@ private slots:
void saveOpacity();
private:
QVBoxLayout *m_layout;
ButtonListView *m_buttonList;
UIcolorEditor *m_colorEditor;
ExtendedSlider *m_opacitySlider;
QVBoxLayout* m_layout;
ButtonListView* m_buttonList;
UIcolorEditor* m_colorEditor;
ExtendedSlider* m_opacitySlider;
void initWidgets();
void initOpacitySlider();