Clang tidy (#2372)

* Added missing braces

* applied some clang modernize

* clarified auto pointer

* clang-tidy
This commit is contained in:
borgmanJeremy
2022-02-06 12:12:09 -06:00
committed by GitHub
parent 3c2a2f98cf
commit 0ac48f5c4b
39 changed files with 174 additions and 137 deletions

View File

@@ -44,8 +44,9 @@ QString optionsToString(const QList<CommandOption>& options,
}
// check the length of the arguments
for (auto const& arg : arguments) {
if (arg.name().length() > size)
if (arg.name().length() > size) {
size = arg.name().length();
}
}
// generate the text
QString result;
@@ -172,8 +173,9 @@ bool CommandLineParser::processOptions(const QStringList& args,
ok = option.checkValue(valueStr);
if (!ok) {
QString msg = option.errorMsg();
if (!msg.endsWith(QLatin1String(".")))
if (!msg.endsWith(QLatin1String("."))) {
msg += QLatin1String(".");
}
err << msg;
return ok;
}
@@ -338,11 +340,13 @@ void CommandLineParser::printHelp(QStringList args, const Node* node)
// add command options and subarguments
QList<CommandArgument> subArgs;
for (const Node& n : node->subNodes)
for (const Node& n : node->subNodes) {
subArgs.append(n.argument);
}
auto modifiedOptions = node->options;
if (m_withHelp)
if (m_withHelp) {
modifiedOptions << helpOption;
}
if (m_withVersion && node == &m_parseTree) {
modifiedOptions << versionOption;
}

View File

@@ -30,7 +30,7 @@ void ButtonListView::initButtonList()
m_buttonTypeByName.insert(tool->name(), t);
// init the menu option
QListWidgetItem* m_buttonItem = new QListWidgetItem(this);
auto* m_buttonItem = new QListWidgetItem(this);
// when the background is lighter than gray, it uses the white icons
QColor bgColor = this->palette().color(QWidget::backgroundRole());

View File

@@ -36,7 +36,7 @@ ColorPickerEditor::ColorPickerEditor(QWidget* parent)
m_colorWheel->setMinimumSize(size, size);
m_gLayout->addWidget(m_colorWheel, 1, 0);
QVBoxLayout* m_vLocalLayout1 = new QVBoxLayout();
auto* m_vLocalLayout1 = new QVBoxLayout();
m_vLocalLayout1->addStretch();
m_colorSpinboxLabel = new QLabel(tr("Select Preset:"), this);
@@ -66,7 +66,7 @@ ColorPickerEditor::ColorPickerEditor(QWidget* parent)
m_gLayout->addLayout(m_vLocalLayout1, 0, 1);
QVBoxLayout* m_vLocalLayout2 = new QVBoxLayout();
auto* m_vLocalLayout2 = new QVBoxLayout();
m_vLocalLayout2->addStretch();
m_addPresetLabel = new QLabel(tr("Add Preset:"), this);
@@ -103,8 +103,9 @@ void ColorPickerEditor::addPreset()
ConfigHandler config;
QVector<QColor> colors = config.userColors();
if (colors.contains(m_color))
if (colors.contains(m_color)) {
return;
}
colors << m_color;

View File

@@ -21,7 +21,7 @@ ConfigErrorDetails::ConfigErrorDetails(QWidget* parent)
setLayout(new QVBoxLayout(this));
// Add text display
QTextEdit* textDisplay = new QTextEdit(this);
auto* textDisplay = new QTextEdit(this);
textDisplay->setPlainText(str);
textDisplay->setReadOnly(true);
layout()->addWidget(textDisplay);

View File

@@ -97,7 +97,7 @@ void ConfigResolver::populate()
++row;
}
QFrame* separator = new QFrame(this);
auto* separator = new QFrame(this);
separator->setFrameShape(QFrame::HLine);
separator->setFrameShadow(QFrame::Sunken);
layout()->addWidget(separator, row, 0, 1, 2);
@@ -109,18 +109,20 @@ void ConfigResolver::populate()
auto* buttons = new BBox(this);
layout()->addWidget(buttons, row, 0, 1, 2, Qt::AlignCenter);
if (anyErrors) {
QPushButton* resolveAll = new QPushButton(tr("Resolve all"));
auto* resolveAll = new QPushButton(tr("Resolve all"));
resolveAll->setToolTip(tr("Resolve all listed errors."));
buttons->addButton(resolveAll, BBox::ResetRole);
connect(resolveAll, &QPushButton::clicked, this, [=]() {
for (const auto& key : semanticallyWrong)
for (const auto& key : semanticallyWrong) {
ConfigHandler().resetValue(key);
for (const auto& key : unrecognized)
}
for (const auto& key : unrecognized) {
ConfigHandler().remove(key);
}
});
}
QPushButton* details = new QPushButton(tr("Details"));
auto* details = new QPushButton(tr("Details"));
buttons->addButton(details, BBox::HelpRole);
connect(details, &QPushButton::clicked, this, [this]() {
(new ConfigErrorDetails(this))->exec();

View File

@@ -32,7 +32,7 @@ ConfigWindow::ConfigWindow(QWidget* parent)
: QWidget(parent)
{
// We wrap QTabWidget in a QWidget because of a Qt bug
auto layout = new QVBoxLayout(this);
auto* layout = new QVBoxLayout(this);
m_tabWidget = new QTabWidget(this);
m_tabWidget->tabBar()->setUsesScrollButtons(false);
layout->addWidget(m_tabWidget);
@@ -54,7 +54,7 @@ ConfigWindow::ConfigWindow(QWidget* parent)
// visuals
m_visuals = new VisualsEditor();
m_visualsTab = new QWidget();
QVBoxLayout* visualsLayout = new QVBoxLayout(m_visualsTab);
auto* visualsLayout = new QVBoxLayout(m_visualsTab);
m_visualsTab->setLayout(visualsLayout);
visualsLayout->addWidget(m_visuals);
m_tabWidget->addTab(
@@ -63,7 +63,7 @@ ConfigWindow::ConfigWindow(QWidget* parent)
// filename
m_filenameEditor = new FileNameEditor();
m_filenameEditorTab = new QWidget();
QVBoxLayout* filenameEditorLayout = new QVBoxLayout(m_filenameEditorTab);
auto* filenameEditorLayout = new QVBoxLayout(m_filenameEditorTab);
m_filenameEditorTab->setLayout(filenameEditorLayout);
filenameEditorLayout->addWidget(m_filenameEditor);
m_tabWidget->addTab(m_filenameEditorTab,
@@ -73,7 +73,7 @@ ConfigWindow::ConfigWindow(QWidget* parent)
// general
m_generalConfig = new GeneralConf();
m_generalConfigTab = new QWidget();
QVBoxLayout* generalConfigLayout = new QVBoxLayout(m_generalConfigTab);
auto* generalConfigLayout = new QVBoxLayout(m_generalConfigTab);
m_generalConfigTab->setLayout(generalConfigLayout);
generalConfigLayout->addWidget(m_generalConfig);
m_tabWidget->addTab(
@@ -82,7 +82,7 @@ ConfigWindow::ConfigWindow(QWidget* parent)
// shortcuts
m_shortcuts = new ShortcutsWidget();
m_shortcutsTab = new QWidget();
QVBoxLayout* shortcutsLayout = new QVBoxLayout(m_shortcutsTab);
auto* shortcutsLayout = new QVBoxLayout(m_shortcutsTab);
m_shortcutsTab->setLayout(shortcutsLayout);
shortcutsLayout->addWidget(m_shortcuts);
m_tabWidget->addTab(
@@ -118,9 +118,9 @@ void ConfigWindow::keyPressEvent(QKeyEvent* e)
void ConfigWindow::initErrorIndicator(QWidget* tab, QWidget* widget)
{
QLabel* label = new QLabel(tab);
QPushButton* btnResolve = new QPushButton(tr("Resolve"), tab);
QHBoxLayout* btnLayout = new QHBoxLayout();
auto* label = new QLabel(tab);
auto* btnResolve = new QPushButton(tr("Resolve"), tab);
auto* btnLayout = new QHBoxLayout();
// Set up label
label->setText(tr(
@@ -137,7 +137,7 @@ void ConfigWindow::initErrorIndicator(QWidget* tab, QWidget* widget)
widget->setEnabled(!ConfigHandler().hasError());
// Add label and button to the parent widget's layout
QBoxLayout* layout = static_cast<QBoxLayout*>(tab->layout());
auto* layout = static_cast<QBoxLayout*>(tab->layout());
if (layout != nullptr) {
layout->insertWidget(0, label);
layout->insertLayout(1, btnLayout);

View File

@@ -21,7 +21,7 @@ FileNameEditor::FileNameEditor(QWidget* parent)
void FileNameEditor::initLayout()
{
m_layout = new QVBoxLayout(this);
auto infoLabel = new QLabel(tr("Edit the name of your captures:"), this);
auto* infoLabel = new QLabel(tr("Edit the name of your captures:"), this);
infoLabel->setFixedHeight(20);
m_layout->addWidget(infoLabel);
m_layout->addWidget(m_helperButtons);
@@ -30,7 +30,7 @@ void FileNameEditor::initLayout()
m_layout->addWidget(new QLabel(tr("Preview:")));
m_layout->addWidget(m_outputLabel);
QHBoxLayout* horizLayout = new QHBoxLayout();
auto* horizLayout = new QHBoxLayout();
horizLayout->addWidget(m_saveButton);
horizLayout->addWidget(m_resetButton);
horizLayout->addWidget(m_clearButton);

View File

@@ -210,7 +210,7 @@ void GeneralConf::initScrollArea()
m_scrollArea = new QScrollArea(this);
m_layout->addWidget(m_scrollArea);
QWidget* content = new QWidget(m_scrollArea);
auto* content = new QWidget(m_scrollArea);
m_scrollArea->setWidget(content);
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
@@ -290,8 +290,8 @@ void GeneralConf::initHistoryConfirmationToDelete()
void GeneralConf::initConfigButtons()
{
QHBoxLayout* buttonLayout = new QHBoxLayout();
QGroupBox* box = new QGroupBox(tr("Configuration File"));
auto* buttonLayout = new QHBoxLayout();
auto* box = new QGroupBox(tr("Configuration File"));
box->setFlat(true);
box->setLayout(buttonLayout);
m_layout->addWidget(box);
@@ -420,14 +420,14 @@ void GeneralConf::initSaveAfterCopy()
this,
&GeneralConf::saveAfterCopyChanged);
QGroupBox* box = new QGroupBox(tr("Save Path"));
auto* box = new QGroupBox(tr("Save Path"));
box->setFlat(true);
m_layout->addWidget(box);
QVBoxLayout* vboxLayout = new QVBoxLayout();
auto* vboxLayout = new QVBoxLayout();
box->setLayout(vboxLayout);
QHBoxLayout* pathLayout = new QHBoxLayout();
auto* pathLayout = new QHBoxLayout();
QString path = ConfigHandler().savePath();
m_savePath = new QLineEdit(path, this);
@@ -453,7 +453,7 @@ void GeneralConf::initSaveAfterCopy()
vboxLayout->addLayout(pathLayout);
vboxLayout->addWidget(m_screenshotPathFixedCheck);
QHBoxLayout* extensionLayout = new QHBoxLayout();
auto* extensionLayout = new QHBoxLayout();
extensionLayout->addWidget(
new QLabel(tr("Preferred save file extension:")));
@@ -486,11 +486,11 @@ void GeneralConf::historyConfirmationToDelete(bool checked)
void GeneralConf::inituploadHistoryMax()
{
QGroupBox* box = new QGroupBox(tr("Latest Uploads Max Size"));
auto* box = new QGroupBox(tr("Latest Uploads Max Size"));
box->setFlat(true);
m_layout->addWidget(box);
QVBoxLayout* vboxLayout = new QVBoxLayout();
auto* vboxLayout = new QVBoxLayout();
box->setLayout(vboxLayout);
m_uploadHistoryMax = new QSpinBox(this);
@@ -513,11 +513,11 @@ void GeneralConf::uploadHistoryMaxChanged(int max)
void GeneralConf::initUndoLimit()
{
QGroupBox* box = new QGroupBox(tr("Undo limit"));
auto* box = new QGroupBox(tr("Undo limit"));
box->setFlat(true);
m_layout->addWidget(box);
QVBoxLayout* vboxLayout = new QVBoxLayout();
auto* vboxLayout = new QVBoxLayout();
box->setLayout(vboxLayout);
m_undoLimit = new QSpinBox(this);

View File

@@ -20,12 +20,12 @@ SetShortcutDialog::SetShortcutDialog(QDialog* parent, QString shortcutName)
m_layout = new QVBoxLayout(this);
m_layout->setAlignment(Qt::AlignHCenter);
QLabel* infoTop = new QLabel(tr("Enter new shortcut to change "));
auto* infoTop = new QLabel(tr("Enter new shortcut to change "));
infoTop->setMargin(10);
infoTop->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoTop);
QLabel* infoIcon = new QLabel();
auto* infoIcon = new QLabel();
infoIcon->setAlignment(Qt::AlignCenter);
infoIcon->setPixmap(QPixmap(":/img/app/keyboard.svg"));
m_layout->addWidget(infoIcon);
@@ -45,7 +45,7 @@ SetShortcutDialog::SetShortcutDialog(QDialog* parent, QString shortcutName)
msg +=
"\n" + tr("Flameshot must be restarted for changes to take effect.");
}
QLabel* infoBottom = new QLabel(msg);
auto* infoBottom = new QLabel(msg);
infoBottom->setMargin(10);
infoBottom->setAlignment(Qt::AlignCenter);
m_layout->addWidget(infoBottom);
@@ -58,14 +58,18 @@ const QKeySequence& SetShortcutDialog::shortcut()
void SetShortcutDialog::keyPressEvent(QKeyEvent* ke)
{
if (ke->modifiers() & Qt::ShiftModifier)
if (ke->modifiers() & Qt::ShiftModifier) {
m_modifier += "Shift+";
if (ke->modifiers() & Qt::ControlModifier)
}
if (ke->modifiers() & Qt::ControlModifier) {
m_modifier += "Ctrl+";
if (ke->modifiers() & Qt::AltModifier)
}
if (ke->modifiers() & Qt::AltModifier) {
m_modifier += "Alt+";
if (ke->modifiers() & Qt::MetaModifier)
}
if (ke->modifiers() & Qt::MetaModifier) {
m_modifier += "Meta+";
}
QString key = QKeySequence(ke->key()).toString();
m_ks = QKeySequence(m_modifier + key);

View File

@@ -94,8 +94,7 @@ void ShortcutsWidget::populateInfoTable()
m_table->setItem(i, 0, new QTableWidgetItem(description));
#if defined(Q_OS_MACOS)
QTableWidgetItem* item =
new QTableWidgetItem(nativeOSHotKeyText(key_sequence));
auto* item = new QTableWidgetItem(nativeOSHotKeyText(key_sequence));
#else
QTableWidgetItem* item = new QTableWidgetItem(key_sequence);
#endif
@@ -130,8 +129,7 @@ void ShortcutsWidget::onShortcutCellClicked(int row, int col)
}
QString shortcutName = m_shortcuts.at(row).at(0);
SetShortcutDialog* setShortcutDialog =
new SetShortcutDialog(nullptr, shortcutName);
auto* setShortcutDialog = new SetShortcutDialog(nullptr, shortcutName);
if (0 != setShortcutDialog->exec()) {
QKeySequence shortcutValue = setShortcutDialog->shortcut();
@@ -163,9 +161,10 @@ void ShortcutsWidget::loadShortcuts()
CaptureTool* tool = ToolFactory().CreateTool(t);
QString shortcutName = QVariant::fromValue(t).toString();
appendShortcut(shortcutName, tool->description());
if (shortcutName == "TYPE_COPY")
if (shortcutName == "TYPE_COPY") {
m_shortcuts << (QStringList() << "" << tool->description()
<< "Left Double-click");
}
delete tool;
}

View File

@@ -9,7 +9,7 @@
StrftimeChooserWidget::StrftimeChooserWidget(QWidget* parent)
: QWidget(parent)
{
QGridLayout* layout = new QGridLayout(this);
auto* layout = new QGridLayout(this);
auto k = m_buttonData.keys();
int middle = k.length() / 2;
// add the buttons in 2 columns (they need to be even)
@@ -18,7 +18,7 @@ StrftimeChooserWidget::StrftimeChooserWidget(QWidget* parent)
QString key = k.last();
k.pop_back();
QString variable = m_buttonData.value(key);
QPushButton* button = new QPushButton(this);
auto* button = new QPushButton(this);
button->setText(tr(key.toStdString().data()));
button->setToolTip(variable);
button->setSizePolicy(QSizePolicy::Expanding,

View File

@@ -98,13 +98,13 @@ void UIcolorEditor::initButtons()
m_vLayout->addWidget(new QLabel(tr("Select a Button to modify it"), this));
QGroupBox* frame = new QGroupBox();
auto* frame = new QGroupBox();
frame->setFixedSize(frameSize, frameSize);
m_buttonMainColor = new CaptureToolButton(m_buttonIconType, frame);
m_buttonMainColor->move(m_buttonMainColor->x() + extraSize / 2,
m_buttonMainColor->y() + extraSize / 2);
QHBoxLayout* h1 = new QHBoxLayout();
auto* h1 = new QHBoxLayout();
h1->addWidget(frame);
m_labelMain = new ClickableLabel(tr("Main Color"), this);
h1->addWidget(m_labelMain);
@@ -113,12 +113,12 @@ void UIcolorEditor::initButtons()
m_buttonMainColor->setToolTip(tr("Click on this button to set the edition"
" mode of the main color."));
QGroupBox* frame2 = new QGroupBox();
auto* frame2 = new QGroupBox();
m_buttonContrast = new CaptureToolButton(m_buttonIconType, frame2);
m_buttonContrast->move(m_buttonContrast->x() + extraSize / 2,
m_buttonContrast->y() + extraSize / 2);
QHBoxLayout* h2 = new QHBoxLayout();
auto* h2 = new QHBoxLayout();
h2->addWidget(frame2);
frame2->setFixedSize(frameSize, frameSize);
m_labelContrast = new ClickableLabel(tr("Contrast Color"), this);

View File

@@ -32,12 +32,12 @@ void VisualsEditor::initOpacitySlider()
m_opacitySlider->setFocusPolicy(Qt::NoFocus);
m_opacitySlider->setOrientation(Qt::Horizontal);
m_opacitySlider->setRange(0, 100);
QHBoxLayout* localLayout = new QHBoxLayout();
auto* localLayout = new QHBoxLayout();
localLayout->addWidget(new QLabel(QStringLiteral("0%")));
localLayout->addWidget(m_opacitySlider);
localLayout->addWidget(new QLabel(QStringLiteral("100%")));
QLabel* label = new QLabel();
auto* label = new QLabel();
QString labelMsg = tr("Opacity of area outside selection:") + " %1%";
ExtendedSlider* opacitySlider = m_opacitySlider;
connect(m_opacitySlider,
@@ -62,28 +62,27 @@ void VisualsEditor::initWidgets()
m_colorEditor = new UIcolorEditor();
m_colorEditorTab = new QWidget();
QVBoxLayout* colorEditorLayout = new QVBoxLayout(m_colorEditorTab);
auto* colorEditorLayout = new QVBoxLayout(m_colorEditorTab);
m_colorEditorTab->setLayout(colorEditorLayout);
colorEditorLayout->addWidget(m_colorEditor);
m_tabWidget->addTab(m_colorEditorTab, tr("UI Color Editor"));
m_colorpickerEditor = new ColorPickerEditor();
m_colorpickerEditorTab = new QWidget();
QVBoxLayout* colorpickerEditorLayout =
new QVBoxLayout(m_colorpickerEditorTab);
auto* colorpickerEditorLayout = new QVBoxLayout(m_colorpickerEditorTab);
colorpickerEditorLayout->addWidget(m_colorpickerEditor);
m_tabWidget->addTab(m_colorpickerEditorTab, tr("Colorpicker Editor"));
initOpacitySlider();
auto boxButtons = new QGroupBox();
auto* boxButtons = new QGroupBox();
boxButtons->setTitle(tr("Button Selection"));
auto listLayout = new QVBoxLayout(boxButtons);
auto* listLayout = new QVBoxLayout(boxButtons);
m_buttonList = new ButtonListView();
m_layout->addWidget(boxButtons);
listLayout->addWidget(m_buttonList);
QPushButton* setAllButtons = new QPushButton(tr("Select All"));
auto* setAllButtons = new QPushButton(tr("Select All"));
connect(setAllButtons,
&QPushButton::clicked,
m_buttonList,

View File

@@ -173,7 +173,7 @@ bool Controller::resolveAnyConfigErrors()
bool resolved = true;
ConfigHandler config;
if (!config.checkUnrecognizedSettings() || !config.checkSemantics()) {
ConfigResolver* resolver = new ConfigResolver();
auto* resolver = new ConfigResolver();
QObject::connect(
resolver, &ConfigResolver::rejected, [resolver, &resolved]() {
resolved = false;
@@ -346,8 +346,9 @@ void Controller::startVisualCapture(const CaptureRequest& req)
void Controller::startScreenGrab(CaptureRequest req, const int screenNumber)
{
if (!resolveAnyConfigErrors())
if (!resolveAnyConfigErrors()) {
return;
}
bool ok = true;
QScreen* screen;

View File

@@ -184,7 +184,7 @@ void FlameshotDaemon::quitIfIdle()
void FlameshotDaemon::attachPin(QPixmap pixmap, QRect geometry)
{
PinWidget* pinWidget = new PinWidget(pixmap, geometry);
auto* pinWidget = new PinWidget(pixmap, geometry);
m_widgets.append(pinWidget);
connect(pinWidget, &QObject::destroyed, this, [=]() {
m_widgets.removeOne(pinWidget);

View File

@@ -124,7 +124,7 @@ int main(int argc, char* argv[])
qApp->installTranslator(&qtTranslator);
qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
auto c = Controller::getInstance();
auto* c = Controller::getInstance();
FlameshotDaemon::start();
#if !(defined(Q_OS_MACOS) || defined(Q_OS_WIN))

View File

@@ -131,7 +131,7 @@ QRect ArrowTool::boundingRect() const
CaptureTool* ArrowTool::copy(QObject* parent)
{
ArrowTool* tool = new ArrowTool(parent);
auto* tool = new ArrowTool(parent);
copyParams(this, tool);
return tool;
}

View File

@@ -97,11 +97,11 @@ void ImgUploaderBase::setInfoLabelText(const QString& text)
void ImgUploaderBase::startDrag()
{
QMimeData* mimeData = new QMimeData;
auto* mimeData = new QMimeData;
mimeData->setUrls(QList<QUrl>{ m_imageURL });
mimeData->setImageData(m_pixmap);
QDrag* dragHandler = new QDrag(this);
auto* dragHandler = new QDrag(this);
dragHandler->setMimeData(mimeData);
dragHandler->setPixmap(m_pixmap.scaled(
256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
@@ -115,7 +115,7 @@ void ImgUploaderBase::showPostUploadDialog()
m_notification = new NotificationWidget();
m_vLayout->addWidget(m_notification);
ImageLabel* imageLabel = new ImageLabel();
auto* imageLabel = new ImageLabel();
imageLabel->setScreenshot(m_pixmap);
imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(imageLabel,

View File

@@ -167,7 +167,7 @@ void AppLauncherWidget::initListWidget()
continue;
}
QListWidget* itemsWidget = new QListWidget();
auto* itemsWidget = new QListWidget();
configureListView(itemsWidget);
const QVector<DesktopAppData>& appList = m_appsMap[cat];
@@ -234,7 +234,7 @@ void AppLauncherWidget::addAppsToListWidget(
const QVector<DesktopAppData>& appList)
{
for (const DesktopAppData& app : appList) {
QListWidgetItem* buttonItem = new QListWidgetItem(widget);
auto* buttonItem = new QListWidgetItem(widget);
buttonItem->setData(Qt::DecorationRole, app.icon);
buttonItem->setData(Qt::DisplayRole, app.name);
buttonItem->setData(Qt::UserRole, app.exec);

View File

@@ -22,7 +22,7 @@ void LauncherItemDelegate::paint(QPainter* painter,
rect.x(), rect.y(), rect.width() - 1, rect.height() - 1);
painter->restore();
}
QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
auto icon = index.data(Qt::DecorationRole).value<QIcon>();
const int iconSide = static_cast<int>(GlobalValues::buttonBaseSize() * 1.3);
const int halfIcon = iconSide / 2;

View File

@@ -40,7 +40,7 @@ void showOpenWithMenu(const QPixmap& capture)
info.oaifInFlags = OAIF_ALLOW_REGISTRATION | OAIF_EXEC;
SHOpenWithDialog(nullptr, &info);
#else
auto w = new AppLauncherWidget(capture);
auto* w = new AppLauncherWidget(capture);
w->show();
#endif
}

View File

@@ -55,10 +55,9 @@ void PixelateTool::process(QPainter& painter, const QPixmap& pixmap)
// If thickness is less than 1, use old blur process
if (size() <= 1) {
QGraphicsBlurEffect* blur = new QGraphicsBlurEffect;
auto* blur = new QGraphicsBlurEffect;
blur->setBlurRadius(10);
QGraphicsPixmapItem* item =
new QGraphicsPixmapItem(pixmap.copy(selectionScaled));
auto* item = new QGraphicsPixmapItem(pixmap.copy(selectionScaled));
item->setGraphicsEffect(blur);
QGraphicsScene scene;

View File

@@ -37,7 +37,7 @@ QString SelectionTool::description() const
CaptureTool* SelectionTool::copy(QObject* parent)
{
SelectionTool* tool = new SelectionTool(parent);
auto* tool = new SelectionTool(parent);
copyParams(this, tool);
return tool;
}

View File

@@ -72,7 +72,7 @@ TextConfig::TextConfig(QWidget* parent)
this,
&TextConfig::fontItalicChanged);
m_italicButton->setToolTip(tr("Italic"));
QHBoxLayout* modifiersLayout = new QHBoxLayout();
auto* modifiersLayout = new QHBoxLayout();
m_leftAlignButton =
new QPushButton(QIcon(iconPrefix + "leftalign.svg"), QLatin1String(""));
@@ -101,7 +101,7 @@ TextConfig::TextConfig(QWidget* parent)
});
m_rightAlignButton->setToolTip(tr("Right Align"));
QHBoxLayout* alignmentLayout = new QHBoxLayout();
auto* alignmentLayout = new QHBoxLayout();
alignmentLayout->addWidget(m_leftAlignButton);
alignmentLayout->addWidget(m_centerAlignButton);
alignmentLayout->addWidget(m_rightAlignButton);

View File

@@ -161,7 +161,7 @@ QWidget* TextTool::configurationWidget()
CaptureTool* TextTool::copy(QObject* parent)
{
TextTool* tt = new TextTool(parent);
auto* tt = new TextTool(parent);
if (m_confW) {
connect(
m_confW, &TextConfig::fontFamilyChanged, tt, &TextTool::updateFamily);

View File

@@ -545,16 +545,20 @@ bool ConfigHandler::checkUnrecognizedSettings(AbstractLogger* log,
bool ok = generalKeys.isEmpty() && shortcutKeys.isEmpty();
if (log != nullptr || offenders != nullptr) {
for (const QString& key : generalKeys) {
if (log)
if (log) {
*log << tr("Unrecognized setting: '%1'\n").arg(key);
if (offenders)
}
if (offenders) {
offenders->append(key);
}
}
for (const QString& key : shortcutKeys) {
if (log)
if (log) {
*log << tr("Unrecognized shortcut name: '%1'.\n").arg(key);
if (offenders)
}
if (offenders) {
offenders->append(CONFIG_GROUP_SHORTCUTS "/" + key);
}
}
}
return ok;
@@ -629,15 +633,17 @@ bool ConfigHandler::checkSemantics(AbstractLogger* log,
if (val.isValid() && !valueHandler->check(val)) {
// Key does not pass the check
ok = false;
if (log == nullptr && offenders == nullptr)
if (log == nullptr && offenders == nullptr) {
break;
}
if (log != nullptr) {
*log << tr("Bad value in '%1'. Expected: %2\n")
.arg(key)
.arg(valueHandler->expected());
}
if (offenders != nullptr)
if (offenders != nullptr) {
offenders->append(key);
}
}
}
return ok;

View File

@@ -45,7 +45,7 @@ void ScreenshotSaver::saveToClipboardMime(const QPixmap& capture,
imageType.toUpper().toUtf8());
if (isLoaded) {
auto mimeData = new QMimeData();
auto* mimeData = new QMimeData();
#ifdef USE_WAYLAND_CLIPBOARD
mimeData->setImageData(formattedPixmap.toImage());

View File

@@ -317,7 +317,7 @@ void sortButtons(BList& buttons)
QVariant ButtonList::process(const QVariant& val)
{
QList<int> intButtons = val.value<QList<int>>();
auto intButtons = val.value<QList<int>>();
auto buttons = ButtonList::fromIntList(intButtons);
sortButtons(buttons);
return QVariant::fromValue(buttons);
@@ -348,8 +348,9 @@ QList<CaptureTool::Type> ButtonList::fromIntList(const QList<int>& l)
{
QList<CaptureTool::Type> buttons;
buttons.reserve(l.size());
for (auto const i : l)
for (auto const i : l) {
buttons << static_cast<CaptureTool::Type>(i);
}
return buttons;
}
@@ -357,8 +358,9 @@ QList<int> ButtonList::toIntList(const QList<CaptureTool::Type>& l)
{
QList<int> buttons;
buttons.reserve(l.size());
for (auto const i : l)
for (auto const i : l) {
buttons << static_cast<int>(i);
}
return buttons;
}
@@ -445,7 +447,7 @@ QString UserColors::expected()
QVariant UserColors::representation(const QVariant& val)
{
QVector<QColor> colors = val.value<QVector<QColor>>();
auto colors = val.value<QVector<QColor>>();
QStringList strColors;
@@ -464,20 +466,23 @@ QVariant UserColors::representation(const QVariant& val)
bool SaveFileExtension::check(const QVariant& val)
{
if (!val.canConvert(QVariant::String) || val.toString().isEmpty())
if (!val.canConvert(QVariant::String) || val.toString().isEmpty()) {
return false;
}
QString extension = val.toString();
if (extension.startsWith("."))
if (extension.startsWith(".")) {
extension.remove(0, 1);
}
QStringList imageFormatList;
foreach (auto imageFormat, QImageWriter::supportedImageFormats())
imageFormatList.append(imageFormat);
if (!imageFormatList.contains(extension))
if (!imageFormatList.contains(extension)) {
return false;
}
return true;
}
@@ -486,8 +491,9 @@ QVariant SaveFileExtension::process(const QVariant& val)
{
QString extension = val.toString();
if (extension.startsWith("."))
if (extension.startsWith(".")) {
extension.remove(0, 1);
}
return QVariant::fromValue(extension);
}
@@ -512,8 +518,9 @@ QVariant Region::process(const QVariant& val)
// FIXME: This is temporary, just before D-Bus is removed
char** argv = new char*[1];
int* argc = new int{ 0 };
if (QGuiApplication::screens().empty())
if (QGuiApplication::screens().empty()) {
new QApplication(*argc, argv);
}
QString str = val.toString();

View File

@@ -25,8 +25,9 @@ ButtonHandler::ButtonHandler(QObject* parent)
void ButtonHandler::hide()
{
for (CaptureToolButton* b : m_vectorButtons)
for (CaptureToolButton* b : m_vectorButtons) {
b->hide();
}
}
void ButtonHandler::show()
@@ -34,8 +35,9 @@ void ButtonHandler::show()
if (m_vectorButtons.isEmpty() || m_vectorButtons.first()->isVisible()) {
return;
}
for (CaptureToolButton* b : m_vectorButtons)
for (CaptureToolButton* b : m_vectorButtons) {
b->animatedShow();
}
}
bool ButtonHandler::isVisible() const
@@ -335,7 +337,7 @@ void ButtonHandler::moveButtonsToPoints(const QVector<QPoint>& points,
int& index)
{
for (const QPoint& p : points) {
auto button = m_vectorButtons[index];
auto* button = m_vectorButtons[index];
button->move(p);
++index;
}
@@ -353,11 +355,13 @@ void ButtonHandler::adjustHorizontalCenter(QPoint& center)
// setButtons redefines the buttons of the button handler
void ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
{
if (v.isEmpty())
if (v.isEmpty()) {
return;
}
for (CaptureToolButton* b : m_vectorButtons)
for (CaptureToolButton* b : m_vectorButtons) {
delete (b);
}
m_vectorButtons = v;
m_buttonBaseSize = GlobalValues::buttonBaseSize();
m_buttonExtendedSize = m_buttonBaseSize + m_separator;

View File

@@ -32,7 +32,7 @@ void CaptureButton::init()
setCursor(Qt::ArrowCursor);
setFocusPolicy(Qt::NoFocus);
auto dsEffect = new QGraphicsDropShadowEffect(this);
auto* dsEffect = new QGraphicsDropShadowEffect(this);
dsEffect->setBlurRadius(5);
dsEffect->setOffset(0);
dsEffect->setColor(QColor(Qt::black));

View File

@@ -183,9 +183,10 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
initSelection(); // button handler must be initialized before
initShortcuts(); // must be called after initSelection
// init magnify
if (m_config.showMagnifier())
if (m_config.showMagnifier()) {
m_magnifier = new MagnifierWidget(
m_context.screenshot, m_uiColor, m_config.squareMagnifier(), this);
}
// Init color picker
m_colorPicker = new ColorPicker(this);
@@ -289,7 +290,7 @@ void CaptureWidget::initButtons()
// Add all buttons but hide those that were disabled in the Interface config
// This will allow keyboard shortcuts for those buttons to work
for (CaptureTool::Type t : allButtonTypes) {
CaptureToolButton* b = new CaptureToolButton(t, this);
auto* b = new CaptureToolButton(t, this);
if (t == CaptureTool::TYPE_SELECTIONINDICATOR) {
m_sizeIndButton = b;
}
@@ -1600,8 +1601,9 @@ void CaptureWidget::restoreCircleCountState()
if (toolItem->type() != CaptureTool::TYPE_CIRCLECOUNT) {
continue;
}
if (toolItem->count() > largest)
if (toolItem->count() > largest) {
largest = toolItem->count();
}
}
m_context.circleCount = largest + 1;
}

View File

@@ -35,10 +35,11 @@ MagnifierWidget::MagnifierWidget(const QPixmap& p,
void MagnifierWidget::paintEvent(QPaintEvent*)
{
QPainter p(this);
if (m_square)
if (m_square) {
drawMagnifier(p);
else
} else {
drawMagnifierCircle(p);
}
}
void MagnifierWidget::drawMagnifierCircle(QPainter& painter)
@@ -89,7 +90,7 @@ void MagnifierWidget::drawMagnifierCircle(QPainter& painter)
painter.drawPixmapFragments(
&frag, 1, m_paddedScreenshot, QPainter::OpaqueHint);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
for (auto& rect :
for (const auto& rect :
{ crossHairTop, crossHairRight, crossHairBottom, crossHairLeft }) {
painter.fillRect(rect, m_color);
}
@@ -165,7 +166,7 @@ void MagnifierWidget::drawMagnifier(QPainter& painter)
painter.fillRect(crossHairBorder, m_borderColor);
painter.drawPixmapFragments(&frag, 1, m_screenshot, QPainter::OpaqueHint);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
for (auto& rect :
for (const auto& rect :
{ crossHairTop, crossHairRight, crossHairBottom, crossHairLeft }) {
painter.fillRect(rect, m_color);
}

View File

@@ -218,12 +218,14 @@ void SelectionWidget::parentMouseMoveEvent(QMouseEvent* e)
&newTop = newTopLeft.ry(), &newBottom = newBottomRight.ry();
switch (mouseSide) {
case TOPLEFT_SIDE:
if (m_activeSide)
if (m_activeSide) {
newTopLeft = pos;
}
break;
case BOTTOMRIGHT_SIDE:
if (m_activeSide)
if (m_activeSide) {
newBottomRight = pos;
}
break;
case TOPRIGHT_SIDE:
if (m_activeSide) {
@@ -238,20 +240,24 @@ void SelectionWidget::parentMouseMoveEvent(QMouseEvent* e)
}
break;
case LEFT_SIDE:
if (m_activeSide)
if (m_activeSide) {
newLeft = pos.x();
}
break;
case RIGHT_SIDE:
if (m_activeSide)
if (m_activeSide) {
newRight = pos.x();
}
break;
case TOP_SIDE:
if (m_activeSide)
if (m_activeSide) {
newTop = pos.y();
}
break;
case BOTTOM_SIDE:
if (m_activeSide)
if (m_activeSide) {
newBottom = pos.y();
}
break;
default:
if (m_activeSide) {
@@ -429,10 +435,12 @@ void SelectionWidget::setGeometryByKeyboard(const QRect& r)
{
static QTimer timer;
QRect rect = r.intersected(parentWidget()->rect());
if (rect.width() <= 0)
if (rect.width() <= 0) {
rect.setWidth(1);
if (rect.height() <= 0)
}
if (rect.height() <= 0) {
rect.setHeight(1);
}
setGeometry(rect);
connect(
&timer,

View File

@@ -43,7 +43,7 @@ void ColorPickerWidget::repaint(int i, QPainter& painter)
{
// draw the highlight when we have to draw the selected color
if (i == m_selectedIndex) {
QColor c = QColor(m_uiColor);
auto c = QColor(m_uiColor);
c.setAlpha(155);
painter.setBrush(c);
c.setAlpha(100);

View File

@@ -15,12 +15,12 @@ void DraggableWidgetMaker::makeDraggable(QWidget* widget)
bool DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
{
auto widget = static_cast<QWidget*>(obj);
auto* widget = static_cast<QWidget*>(obj);
// based on https://stackoverflow.com/a/12221360/964478
switch (event->type()) {
case QEvent::MouseButtonPress: {
auto mouseEvent = static_cast<QMouseEvent*>(event);
auto* mouseEvent = static_cast<QMouseEvent*>(event);
m_isPressing = false;
m_isDragging = false;
@@ -31,7 +31,7 @@ bool DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
}
} break;
case QEvent::MouseMove: {
auto mouseEvent = static_cast<QMouseEvent*>(event);
auto* mouseEvent = static_cast<QMouseEvent*>(event);
if (m_isPressing) {
QPoint widgetPos = widget->mapToGlobal(widget->pos());

View File

@@ -30,7 +30,7 @@ NotificationWidget::NotificationWidget(QWidget* parent)
connect(
m_hideAnimation, &QPropertyAnimation::finished, m_label, &QLabel::hide);
auto mainLayout = new QVBoxLayout();
auto* mainLayout = new QVBoxLayout();
setLayout(mainLayout);
mainLayout->addWidget(m_content);

View File

@@ -30,10 +30,10 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
parent->installEventFilter(this);
}
QGridLayout* colorLayout = new QGridLayout();
auto* colorLayout = new QGridLayout();
// Create Active Tool Size
QLabel* activeToolSizeText = new QLabel(tr("Active tool size: "));
auto* activeToolSizeText = new QLabel(tr("Active tool size: "));
m_toolSizeSlider = new QSlider(Qt::Horizontal);
m_toolSizeSlider->setRange(1, maxToolSize);
@@ -44,8 +44,8 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
colorLayout->addWidget(m_toolSizeSlider, 1, 0);
// Create Active Color
QHBoxLayout* colorHBox = new QHBoxLayout();
QLabel* colorText = new QLabel(tr("Active Color: "));
auto* colorHBox = new QHBoxLayout();
auto* colorText = new QLabel(tr("Active Color: "));
m_colorLabel = new QLabel();
m_colorLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

View File

@@ -116,7 +116,7 @@ void UtilityPanel::initInternalPanel()
{
m_internalPanel = new QScrollArea(this);
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);
QWidget* widget = new QWidget();
auto* widget = new QWidget();
m_internalPanel->setWidget(widget);
m_internalPanel->setWidgetResizable(true);
@@ -141,7 +141,7 @@ void UtilityPanel::initInternalPanel()
this,
SLOT(onCurrentRowChanged(int)));
QHBoxLayout* layersButtons = new QHBoxLayout();
auto* layersButtons = new QHBoxLayout();
m_layersLayout->addLayout(layersButtons);
m_layersLayout->addWidget(m_captureTools);
@@ -186,7 +186,7 @@ void UtilityPanel::initInternalPanel()
&UtilityPanel::slotDownClicked);
// Bottom
QPushButton* closeButton = new QPushButton(this);
auto* closeButton = new QPushButton(this);
closeButton->setText(tr("Close"));
connect(closeButton, &QPushButton::clicked, this, &UtilityPanel::toggle);
m_bottomLayout->addWidget(closeButton);
@@ -200,7 +200,7 @@ void UtilityPanel::fillCaptureTools(
m_captureTools->addItem(tr("<Empty>"));
for (auto toolItem : captureToolObjects) {
QListWidgetItem* item = new QListWidgetItem(
auto* item = new QListWidgetItem(
toolItem->icon(QColor(Qt::white), false), toolItem->info());
m_captureTools->addItem(item);
}

View File

@@ -94,7 +94,7 @@ void UpdateNotificationWidget::initInternalPanel()
{
m_internalPanel = new QScrollArea(this);
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);
QWidget* widget = new QWidget();
auto* widget = new QWidget();
m_internalPanel->setWidget(widget);
m_internalPanel->setWidgetResizable(true);
@@ -113,13 +113,13 @@ void UpdateNotificationWidget::initInternalPanel()
m_layout->addWidget(m_notification);
// buttons layout
QHBoxLayout* buttonsLayout = new QHBoxLayout();
QSpacerItem* bottonsSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding);
auto* buttonsLayout = new QHBoxLayout();
auto* bottonsSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding);
buttonsLayout->addSpacerItem(bottonsSpacer);
m_layout->addLayout(buttonsLayout);
// ignore
QPushButton* ignoreBtn = new QPushButton(tr("Ignore"), this);
auto* ignoreBtn = new QPushButton(tr("Ignore"), this);
buttonsLayout->addWidget(ignoreBtn);
connect(ignoreBtn,
&QPushButton::clicked,
@@ -127,7 +127,7 @@ void UpdateNotificationWidget::initInternalPanel()
&UpdateNotificationWidget::ignoreButton);
// later
QPushButton* laterBtn = new QPushButton(tr("Later"), this);
auto* laterBtn = new QPushButton(tr("Later"), this);
buttonsLayout->addWidget(laterBtn);
connect(laterBtn,
&QPushButton::clicked,
@@ -135,7 +135,7 @@ void UpdateNotificationWidget::initInternalPanel()
&UpdateNotificationWidget::laterButton);
// update
QPushButton* updateBtn = new QPushButton(tr("Update"), this);
auto* updateBtn = new QPushButton(tr("Update"), this);
buttonsLayout->addWidget(updateBtn);
connect(updateBtn,
&QPushButton::clicked,