diff --git a/commands/imagelib/effects/kpEffectBalanceCommand.cpp b/commands/imagelib/effects/kpEffectBalanceCommand.cpp --- a/commands/imagelib/effects/kpEffectBalanceCommand.cpp +++ b/commands/imagelib/effects/kpEffectBalanceCommand.cpp @@ -43,9 +43,7 @@ { } -kpEffectBalanceCommand::~kpEffectBalanceCommand () -{ -} +kpEffectBalanceCommand::~kpEffectBalanceCommand () = default; // protected virtual [base kpEffectCommandBase] diff --git a/commands/imagelib/effects/kpEffectBlurSharpenCommand.cpp b/commands/imagelib/effects/kpEffectBlurSharpenCommand.cpp --- a/commands/imagelib/effects/kpEffectBlurSharpenCommand.cpp +++ b/commands/imagelib/effects/kpEffectBlurSharpenCommand.cpp @@ -46,20 +46,17 @@ { } -kpEffectBlurSharpenCommand::~kpEffectBlurSharpenCommand () -{ -} +kpEffectBlurSharpenCommand::~kpEffectBlurSharpenCommand () = default; // public static QString kpEffectBlurSharpenCommand::nameForType (kpEffectBlurSharpen::Type type) { - if (type == kpEffectBlurSharpen::Blur) - return i18n ("Soften"); - else if (type == kpEffectBlurSharpen::Sharpen) - return i18n ("Sharpen"); - else - return QString(); + switch (type) { + case kpEffectBlurSharpen::Blur: return i18n ("Soften"); + case kpEffectBlurSharpen::Sharpen: return i18n ("Sharpen"); + default: return QString(); + } } diff --git a/commands/imagelib/effects/kpEffectClearCommand.cpp b/commands/imagelib/effects/kpEffectClearCommand.cpp --- a/commands/imagelib/effects/kpEffectClearCommand.cpp +++ b/commands/imagelib/effects/kpEffectClearCommand.cpp @@ -57,10 +57,7 @@ { QString opName = i18n ("Clear"); - if (m_actOnSelection) - return i18n ("Selection: %1", opName); - else - return opName; + return (m_actOnSelection) ? i18n ("Selection: %1", opName) : opName; } @@ -92,8 +89,9 @@ Q_ASSERT (sel); sel->fill (m_newColor); } - else + else { doc->fill (m_newColor); + } } // public virtual [base kpCommand] diff --git a/commands/imagelib/effects/kpEffectCommandBase.cpp b/commands/imagelib/effects/kpEffectCommandBase.cpp --- a/commands/imagelib/effects/kpEffectCommandBase.cpp +++ b/commands/imagelib/effects/kpEffectCommandBase.cpp @@ -39,7 +39,7 @@ struct kpEffectCommandBasePrivate { QString name; - bool actOnSelection; + bool actOnSelection{false}; kpImage oldImage; }; @@ -63,10 +63,7 @@ // public virtual [base kpCommand] QString kpEffectCommandBase::name () const { - if (d->actOnSelection) - return i18n ("Selection: %1", d->name); - else - return d->name; + return (d->actOnSelection) ? i18n ("Selection: %1", d->name) : d->name; } diff --git a/commands/imagelib/effects/kpEffectEmbossCommand.cpp b/commands/imagelib/effects/kpEffectEmbossCommand.cpp --- a/commands/imagelib/effects/kpEffectEmbossCommand.cpp +++ b/commands/imagelib/effects/kpEffectEmbossCommand.cpp @@ -44,9 +44,7 @@ { } -kpEffectEmbossCommand::~kpEffectEmbossCommand () -{ -} +kpEffectEmbossCommand::~kpEffectEmbossCommand () = default; // protected virtual [base kpEffectCommandBase] diff --git a/commands/imagelib/effects/kpEffectFlattenCommand.cpp b/commands/imagelib/effects/kpEffectFlattenCommand.cpp --- a/commands/imagelib/effects/kpEffectFlattenCommand.cpp +++ b/commands/imagelib/effects/kpEffectFlattenCommand.cpp @@ -45,9 +45,7 @@ { } -kpEffectFlattenCommand::~kpEffectFlattenCommand () -{ -} +kpEffectFlattenCommand::~kpEffectFlattenCommand () = default; // diff --git a/commands/imagelib/effects/kpEffectGrayscaleCommand.cpp b/commands/imagelib/effects/kpEffectGrayscaleCommand.cpp --- a/commands/imagelib/effects/kpEffectGrayscaleCommand.cpp +++ b/commands/imagelib/effects/kpEffectGrayscaleCommand.cpp @@ -44,9 +44,7 @@ { } -kpEffectGrayscaleCommand::~kpEffectGrayscaleCommand () -{ -} +kpEffectGrayscaleCommand::~kpEffectGrayscaleCommand () = default; // diff --git a/commands/imagelib/effects/kpEffectInvertCommand.cpp b/commands/imagelib/effects/kpEffectInvertCommand.cpp --- a/commands/imagelib/effects/kpEffectInvertCommand.cpp +++ b/commands/imagelib/effects/kpEffectInvertCommand.cpp @@ -51,9 +51,7 @@ { } -kpEffectInvertCommand::~kpEffectInvertCommand () -{ -} +kpEffectInvertCommand::~kpEffectInvertCommand () = default; // diff --git a/commands/imagelib/effects/kpEffectReduceColorsCommand.cpp b/commands/imagelib/effects/kpEffectReduceColorsCommand.cpp --- a/commands/imagelib/effects/kpEffectReduceColorsCommand.cpp +++ b/commands/imagelib/effects/kpEffectReduceColorsCommand.cpp @@ -49,23 +49,19 @@ // public QString kpEffectReduceColorsCommand::commandName (int depth, int dither) const { - if (depth == 1) - { - if (dither) + switch (depth) { + case 1: if (dither) { return i18n ("Reduce to Monochrome (Dithered)"); - else - return i18n ("Reduce to Monochrome"); - } - else if (depth == 8) - { - if (dither) + } + return i18n ("Reduce to Monochrome"); + + case 8: + if (dither) { return i18n ("Reduce to 256 Color (Dithered)"); - else - return i18n ("Reduce to 256 Color"); - } - else - { - return QString(); + } + return i18n ("Reduce to 256 Color"); + + default: return QString(); } } diff --git a/commands/imagelib/effects/kpEffectToneEnhanceCommand.cpp b/commands/imagelib/effects/kpEffectToneEnhanceCommand.cpp --- a/commands/imagelib/effects/kpEffectToneEnhanceCommand.cpp +++ b/commands/imagelib/effects/kpEffectToneEnhanceCommand.cpp @@ -43,9 +43,7 @@ { } -kpEffectToneEnhanceCommand::~kpEffectToneEnhanceCommand () -{ -} +kpEffectToneEnhanceCommand::~kpEffectToneEnhanceCommand () = default; // protected virtual [base kpEffectCommandBase] diff --git a/commands/imagelib/transforms/kpTransformFlipCommand.cpp b/commands/imagelib/transforms/kpTransformFlipCommand.cpp --- a/commands/imagelib/transforms/kpTransformFlipCommand.cpp +++ b/commands/imagelib/transforms/kpTransformFlipCommand.cpp @@ -52,9 +52,7 @@ //--------------------------------------------------------------------- -kpTransformFlipCommand::~kpTransformFlipCommand () -{ -} +kpTransformFlipCommand::~kpTransformFlipCommand () = default; //--------------------------------------------------------------------- // public virtual [base kpCommand] @@ -75,16 +73,17 @@ opName = i18n ("Flip vertically"); else { - qCCritical(kpLogCommands) << "kpTransformFlipCommand::name() not asked to flip" << endl; + qCCritical(kpLogCommands) << "kpTransformFlipCommand::name() not asked to flip"; return QString(); } #endif - if (m_actOnSelection) + if (m_actOnSelection) { return i18n ("Selection: %1", opName); - else - return opName; + } + + return opName; } //--------------------------------------------------------------------- diff --git a/commands/imagelib/transforms/kpTransformResizeScaleCommand.cpp b/commands/imagelib/transforms/kpTransformResizeScaleCommand.cpp --- a/commands/imagelib/transforms/kpTransformResizeScaleCommand.cpp +++ b/commands/imagelib/transforms/kpTransformResizeScaleCommand.cpp @@ -97,15 +97,19 @@ { if (m_actOnTextSelection) { - if (m_type == Resize) + if (m_type == Resize) { return i18n ("Text: Resize Box"); + } } else { - if (m_type == Scale) + if (m_type == Scale) { return i18n ("Selection: Scale"); - else if (m_type == SmoothScale) + } + + if (m_type == SmoothScale) { return i18n ("Selection: Smooth Scale"); + } } } else @@ -163,7 +167,7 @@ // public QSize kpTransformResizeScaleCommand::newSize () const { - return QSize (newWidth (), newHeight ()); + return {newWidth (), newHeight ()}; } // public virtual @@ -189,8 +193,7 @@ void kpTransformResizeScaleCommand::scaleSelectionRegionWithDocument () { #if DEBUG_KP_TOOL_RESIZE_SCALE_COMMAND - qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::scaleSelectionRegionWithDocument" - << endl; + qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::scaleSelectionRegionWithDocument"; #endif Q_ASSERT (m_oldSelectionPtr); @@ -218,10 +221,9 @@ -currentPoints.boundingRect ().x () + newX, -currentPoints.boundingRect ().y () + newY); - kpAbstractImageSelection *imageSel = - dynamic_cast (m_oldSelectionPtr); - kpTextSelection *textSel = - dynamic_cast (m_oldSelectionPtr); + auto *imageSel = dynamic_cast (m_oldSelectionPtr); + auto *textSel = dynamic_cast (m_oldSelectionPtr); + if (imageSel) { document ()->setSelection ( @@ -235,8 +237,9 @@ textSel->textLines (), textSel->textStyle ())); } - else + else { Q_ASSERT (!"Unknown selection type"); + } environ ()->somethingBelowTheCursorChanged (); @@ -251,18 +254,18 @@ << " oldWidth=" << m_oldWidth << " oldHeight=" << m_oldHeight << " newWidth=" << m_newWidth - << " newHeight=" << m_newHeight - << endl; + << " newHeight=" << m_newHeight; if (m_oldWidth == m_newWidth && m_oldHeight == m_newHeight) return; if (m_type == Resize) { if (m_actOnSelection) { - if (!m_actOnTextSelection) + if (!m_actOnTextSelection) { Q_ASSERT (!"kpTransformResizeScaleCommand::execute() resizing sel doesn't make sense"); + } QApplication::setOverrideCursor (Qt::WaitCursor); @@ -310,8 +313,9 @@ kpImage oldImage = document ()->image (m_actOnSelection); - if (!m_isLosslessScale) + if (!m_isLosslessScale) { m_oldImage = oldImage; + } kpImage newImage = kpPixmapFX::scale (oldImage, m_newWidth, m_newHeight, m_type == SmoothScale); @@ -326,12 +330,14 @@ if (m_actOnSelection) { - if (m_actOnTextSelection) + if (m_actOnTextSelection) { Q_ASSERT (!"kpTransformResizeScaleCommand::execute() scaling text sel doesn't make sense"); + } Q_ASSERT (m_oldSelectionPtr); - if ( !m_oldSelectionPtr ) // make coverity happy - return; + if ( !m_oldSelectionPtr ) { // make coverity happy + return; + } QRect newRect = QRect (m_oldSelectionPtr->x (), m_oldSelectionPtr->y (), newImage.width (), newImage.height ()); @@ -341,7 +347,7 @@ Q_ASSERT (dynamic_cast (m_oldSelectionPtr)); document ()->setSelection ( kpRectangularImageSelection (newRect, newImage, - static_cast (m_oldSelectionPtr) + dynamic_cast (m_oldSelectionPtr) ->transparency ())); environ ()->somethingBelowTheCursorChanged (); @@ -365,20 +371,22 @@ void kpTransformResizeScaleCommand::unexecute () { qCDebug(kpLogCommands) << "kpTransformResizeScaleCommand::unexecute() type=" - << m_type << endl; + << m_type; - if (m_oldWidth == m_newWidth && m_oldHeight == m_newHeight) + if (m_oldWidth == m_newWidth && m_oldHeight == m_newHeight) { return; + } kpDocument *doc = document (); Q_ASSERT (doc); if (m_type == Resize) { if (m_actOnSelection) { - if (!m_actOnTextSelection) + if (!m_actOnTextSelection) { Q_ASSERT (!"kpTransformResizeScaleCommand::unexecute() resizing sel doesn't make sense"); + } QApplication::setOverrideCursor (Qt::WaitCursor); @@ -431,21 +439,22 @@ kpImage oldImage; - if (!m_isLosslessScale) + if (!m_isLosslessScale) { oldImage = m_oldImage; - else + } else { oldImage = kpPixmapFX::scale (doc->image (m_actOnSelection), m_oldWidth, m_oldHeight); + } if (m_actOnSelection) { - if (m_actOnTextSelection) + if (m_actOnTextSelection) { Q_ASSERT (!"kpTransformResizeScaleCommand::unexecute() scaling text sel doesn't make sense"); + } Q_ASSERT (dynamic_cast (m_oldSelectionPtr)); - kpAbstractImageSelection *oldImageSel = - static_cast (m_oldSelectionPtr); + auto *oldImageSel = dynamic_cast (m_oldSelectionPtr); kpAbstractImageSelection *oldSelection = oldImageSel->clone (); oldSelection->setBaseImage (oldImage); diff --git a/commands/imagelib/transforms/kpTransformRotateCommand.cpp b/commands/imagelib/transforms/kpTransformRotateCommand.cpp --- a/commands/imagelib/transforms/kpTransformRotateCommand.cpp +++ b/commands/imagelib/transforms/kpTransformRotateCommand.cpp @@ -71,10 +71,7 @@ { QString opName = i18n ("Rotate"); - if (m_actOnSelection) - return i18n ("Selection: %1", opName); - else - return opName; + return (m_actOnSelection) ? i18n ("Selection: %1", opName) : opName; } @@ -96,18 +93,19 @@ QApplication::setOverrideCursor (Qt::WaitCursor); - if (!m_losslessRotation) + if (!m_losslessRotation) { m_oldImage = doc->image (m_actOnSelection); + } kpImage newImage = kpPixmapFX::rotate (doc->image (m_actOnSelection), m_angle, m_backgroundColor); - if (!m_actOnSelection) + if (!m_actOnSelection) { doc->setImage (newImage); - else - { + } + else { kpAbstractImageSelection *sel = doc->imageSelection (); Q_ASSERT (sel); @@ -163,8 +161,7 @@ << currentPoints.boundingRect () << " newPixmap: w=" << newImage.width () << " h=" << newImage.height () - << " (victim of rounding error and/or rotated-a-(rectangular)-pixmap-that-was-transparent-in-the-corners-making-sel-uselessly-bigger-than-needs-be)" - << endl; + << " (victim of rounding error and/or rotated-a-(rectangular)-pixmap-that-was-transparent-in-the-corners-making-sel-uselessly-bigger-than-needs-be)"; #endif doc->setSelection ( kpRectangularImageSelection ( @@ -206,10 +203,10 @@ } - if (!m_actOnSelection) + if (!m_actOnSelection) { doc->setImage (oldImage); - else - { + } + else { m_oldSelectionPtr->setBaseImage (oldImage); doc->setSelection (*m_oldSelectionPtr); delete m_oldSelectionPtr; m_oldSelectionPtr = nullptr; diff --git a/commands/imagelib/transforms/kpTransformSkewCommand.cpp b/commands/imagelib/transforms/kpTransformSkewCommand.cpp --- a/commands/imagelib/transforms/kpTransformSkewCommand.cpp +++ b/commands/imagelib/transforms/kpTransformSkewCommand.cpp @@ -74,10 +74,7 @@ { QString opName = i18n ("Skew"); - if (m_actOnSelection) - return i18n ("Selection: %1", opName); - else - return opName; + return (m_actOnSelection) ? i18n ("Selection: %1", opName) : opName; } @@ -150,8 +147,7 @@ << currentPoints.boundingRect () << " newPixmap: w=" << newImage.width () << " h=" << newImage.height () - << " (victim of rounding error and/or skewed-a-(rectangular)-pixmap-that-was-transparent-in-the-corners-making-sel-uselessly-bigger-than-needs-be))" - << endl; + << " (victim of rounding error and/or skewed-a-(rectangular)-pixmap-that-was-transparent-in-the-corners-making-sel-uselessly-bigger-than-needs-be))"; #endif doc->setSelection ( kpRectangularImageSelection ( diff --git a/commands/kpCommand.cpp b/commands/kpCommand.cpp --- a/commands/kpCommand.cpp +++ b/commands/kpCommand.cpp @@ -40,9 +40,7 @@ Q_ASSERT (environ); } -kpCommand::~kpCommand () -{ -} +kpCommand::~kpCommand () = default; kpCommandEnvironment *kpCommand::environ () const diff --git a/commands/kpCommandHistory.cpp b/commands/kpCommandHistory.cpp --- a/commands/kpCommandHistory.cpp +++ b/commands/kpCommandHistory.cpp @@ -44,22 +44,22 @@ { } -kpCommandHistory::~kpCommandHistory () -{ -} +kpCommandHistory::~kpCommandHistory () = default; static bool NextUndoCommandIsCreateBorder (kpCommandHistory *commandHistory) { Q_ASSERT (commandHistory); kpCommand *cmd = commandHistory->nextUndoCommand (); - if (!cmd) + if (!cmd) { return false; + } - kpToolSelectionCreateCommand *c = dynamic_cast (cmd); - if (!c) + auto *c = dynamic_cast (cmd); + if (!c) { return false; + } const kpAbstractSelection *sel = c->fromSelection (); Q_ASSERT (sel); @@ -80,11 +80,13 @@ if (::NextUndoCommandIsCreateBorder (this)) { setNextUndoCommand (cmd); - if (execute) + if (execute) { cmd->execute (); + } } - else + else { addCommand (cmd, execute); + } } //--------------------------------------------------------------------- @@ -98,8 +100,9 @@ qCDebug(kpLogCommands) << "\thas begun shape - cancel draw"; m_mainWindow->tool ()->cancelShapeInternal (); } - else + else { kpCommandHistoryBase::undo (); + } } //--------------------------------------------------------------------- @@ -117,8 +120,9 @@ // down). m_mainWindow->tool ()->cancelShapeInternal (); } - else + else { kpCommandHistoryBase::redo (); + } } diff --git a/commands/kpCommandHistoryBase.cpp b/commands/kpCommandHistoryBase.cpp --- a/commands/kpCommandHistoryBase.cpp +++ b/commands/kpCommandHistoryBase.cpp @@ -106,8 +106,9 @@ m_documentRestoredPosition = 0; - if (doReadConfig) + if (doReadConfig) { readConfig (); + } } kpCommandHistoryBase::~kpCommandHistoryBase () @@ -142,19 +143,18 @@ void kpCommandHistoryBase::setUndoMinLimit (int limit) { qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMinLimit(" - << limit << ")" - << endl; + << limit << ")"; if (limit < 1 || limit > 5000/*"ought to be enough for anybody"*/) { qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMinLimit(" - << limit << ")" - << endl; + << limit << ")"; return; } - if (limit == m_undoMinLimit) + if (limit == m_undoMinLimit) { return; + } m_undoMinLimit = limit; trimCommandListsUpdateActions (); @@ -171,19 +171,18 @@ void kpCommandHistoryBase::setUndoMaxLimit (int limit) { qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimit(" - << limit << ")" - << endl; + << limit << ")"; if (limit < 1 || limit > 5000/*"ought to be enough for anybody"*/) { qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimit(" - << limit << ")" - << endl; + << limit << ")"; return; } - if (limit == m_undoMaxLimit) + if (limit == m_undoMaxLimit) { return; + } m_undoMaxLimit = limit; trimCommandListsUpdateActions (); @@ -200,20 +199,19 @@ void kpCommandHistoryBase::setUndoMaxLimitSizeLimit (kpCommandSize::SizeType sizeLimit) { qCDebug(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimitSizeLimit(" - << sizeLimit << ")" - << endl; + << sizeLimit << ")"; if (sizeLimit < 0 || sizeLimit > (500 * 1048576)/*"ought to be enough for anybody"*/) { qCCritical(kpLogCommands) << "kpCommandHistoryBase::setUndoMaxLimitSizeLimit(" - << sizeLimit << ")" - << endl; + << sizeLimit << ")"; return; } - if (sizeLimit == m_undoMaxLimitSizeLimit) + if (sizeLimit == m_undoMaxLimitSizeLimit) { return; + } m_undoMaxLimitSizeLimit = sizeLimit; trimCommandListsUpdateActions (); @@ -255,25 +253,25 @@ { qCDebug(kpLogCommands) << "kpCommandHistoryBase::addCommand(" << command - << ",execute=" << execute << ")" - << endl; + << ",execute=" << execute << ")"; - if (execute) + if (execute) { command->execute (); + } m_undoCommandList.push_front (command); ::ClearPointerList (&m_redoCommandList); - qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition - << endl; + qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; if (m_documentRestoredPosition != INT_MAX) { - if (m_documentRestoredPosition > 0) + if (m_documentRestoredPosition > 0) { m_documentRestoredPosition = INT_MAX; - else + } + else { m_documentRestoredPosition--; - qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition - << endl; + } + qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition; } trimCommandListsUpdateActions (); @@ -300,25 +298,24 @@ qCDebug(kpLogCommands) << "kpCommandHistoryBase::undoInternal()"; kpCommand *undoCommand = nextUndoCommand (); - if (!undoCommand) + if (!undoCommand) { return; + } undoCommand->unexecute (); m_undoCommandList.erase (m_undoCommandList.begin ()); m_redoCommandList.push_front (undoCommand); - qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition - << endl; + qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; if (m_documentRestoredPosition != INT_MAX) { m_documentRestoredPosition++; if (m_documentRestoredPosition == 0) emit documentRestored (); - qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition - << endl; + qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition; } } @@ -330,24 +327,24 @@ qCDebug(kpLogCommands) << "kpCommandHistoryBase::redoInternal()"; kpCommand *redoCommand = nextRedoCommand (); - if (!redoCommand) + if (!redoCommand) { return; + } redoCommand->execute (); m_redoCommandList.erase (m_redoCommandList.begin ()); m_undoCommandList.push_front (redoCommand); - qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition - << endl; + qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; if (m_documentRestoredPosition != INT_MAX) { m_documentRestoredPosition--; - if (m_documentRestoredPosition == 0) + if (m_documentRestoredPosition == 0) { emit documentRestored (); - qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition - << endl; + } + qCDebug(kpLogCommands) << "\t\tdocumentRestoredPosition=" << m_documentRestoredPosition; } } @@ -411,44 +408,32 @@ { kpCommand *undoCommand = nextUndoCommand (); - if (undoCommand) - return i18n ("&Undo: %1", undoCommand->name ()); - else - return i18n ("&Undo"); + return (undoCommand) ? i18n ("&Undo: %1", undoCommand->name ()) : i18n ("&Undo"); } // protected QString kpCommandHistoryBase::redoActionText () const { kpCommand *redoCommand = nextRedoCommand (); - if (redoCommand) - return i18n ("&Redo: %1", redoCommand->name ()); - else - return i18n ("&Redo"); + return (redoCommand) ? i18n ("&Redo: %1", redoCommand->name ()) : i18n ("&Redo"); } // protected QString kpCommandHistoryBase::undoActionToolTip () const { kpCommand *undoCommand = nextUndoCommand (); - if (undoCommand) - return i18n ("Undo: %1", undoCommand->name ()); - else - return i18n ("Undo"); + return (undoCommand) ? i18n ("Undo: %1", undoCommand->name ()) : i18n ("Undo"); } // protected QString kpCommandHistoryBase::redoActionToolTip () const { kpCommand *redoCommand = nextRedoCommand (); - if (redoCommand) - return i18n ("Redo: %1", redoCommand->name ()); - else - return i18n ("Redo"); + return (redoCommand) ? i18n ("Redo: %1", redoCommand->name ()) : i18n ("Redo"); } @@ -469,17 +454,15 @@ if (!commandList) { - qCCritical(kpLogCommands) << "kpCommandHistoryBase::trimCommandList() passed 0 commandList" - << endl; + qCCritical(kpLogCommands) << "kpCommandHistoryBase::trimCommandList() passed 0 commandList"; return; } qCDebug(kpLogCommands) << "\tsize=" << commandList->size () << " undoMinLimit=" << m_undoMinLimit << " undoMaxLimit=" << m_undoMaxLimit - << " undoMaxLimitSizeLimit=" << m_undoMaxLimitSizeLimit - << endl; + << " undoMaxLimitSizeLimit=" << m_undoMaxLimitSizeLimit; if (static_cast (commandList->size ()) <= m_undoMinLimit) { qCDebug(kpLogCommands) << "\t\tsize under undoMinLimit - done"; @@ -505,8 +488,7 @@ qCDebug(kpLogCommands) << "\t\t" << upto << ":" << " name='" << (*it)->name () << "' size=" << (*it)->size () - << " sizeSoFar=" << sizeSoFar - << endl; + << " sizeSoFar=" << sizeSoFar; if (upto >= m_undoMinLimit) { @@ -522,8 +504,9 @@ } } - if (advanceIt) + if (advanceIt) { it++; + } upto++; } @@ -538,13 +521,11 @@ trimCommandList (&m_undoCommandList); trimCommandList (&m_redoCommandList); - qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition - << endl; + qCDebug(kpLogCommands) << "\tdocumentRestoredPosition=" << m_documentRestoredPosition; if (m_documentRestoredPosition != INT_MAX) { qCDebug(kpLogCommands) << "\t\tundoCmdList.size=" << m_undoCommandList.size () - << " redoCmdList.size=" << m_redoCommandList.size () - << endl; + << " redoCmdList.size=" << m_redoCommandList.size (); if (m_documentRestoredPosition > static_cast (m_redoCommandList.size ()) || -m_documentRestoredPosition > static_cast (m_undoCommandList.size ())) { @@ -559,8 +540,9 @@ const QString &undoOrRedo, const QLinkedList &commandList) { - if (!popupMenu) + if (!popupMenu) { return; + } popupMenu->clear (); @@ -605,7 +587,7 @@ i18n ("Undo"), m_undoCommandList); qCDebug(kpLogCommands) << "\tpopuplatePopupMenu undo=" << timer.elapsed () - << "ms" << endl;; + << "ms"; m_actionRedo->setEnabled (static_cast (nextRedoCommand ())); // Don't want to keep changing toolbar text. @@ -622,45 +604,43 @@ i18n ("Redo"), m_redoCommandList); qCDebug(kpLogCommands) << "\tpopuplatePopupMenu redo=" << timer.elapsed () - << "ms" << endl; + << "ms"; } // public kpCommand *kpCommandHistoryBase::nextUndoCommand () const { - if (m_undoCommandList.isEmpty ()) + if (m_undoCommandList.isEmpty ()) { return nullptr; + } return m_undoCommandList.first (); } // public kpCommand *kpCommandHistoryBase::nextRedoCommand () const { - if (m_redoCommandList.isEmpty ()) + if (m_redoCommandList.isEmpty ()) { return nullptr; + } return m_redoCommandList.first (); } // public void kpCommandHistoryBase::setNextUndoCommand (kpCommand *command) { - qCDebug(kpLogCommands) << "kpCommandHistoryBase::setNextUndoCommand(" - << command - << ")" - << endl; + qCDebug(kpLogCommands) << "kpCommandHistoryBase::setNextUndoCommand("<< command << ")"; - if (m_undoCommandList.isEmpty ()) + if (m_undoCommandList.isEmpty ()) { return; - + } delete *m_undoCommandList.begin (); *m_undoCommandList.begin () = command; - trimCommandListsUpdateActions (); } diff --git a/commands/kpCommandSize.cpp b/commands/kpCommandSize.cpp --- a/commands/kpCommandSize.cpp +++ b/commands/kpCommandSize.cpp @@ -62,8 +62,7 @@ << " h=" << height << " d=" << depth << " roundedDepth=" << roundedDepth - << " ret=" << ret - << endl; + << " ret=" << ret; return ret; } @@ -92,8 +91,7 @@ << " h=" << height << " d=" << depth << " roundedDepth=" << roundedDepth - << " ret=" << ret - << endl; + << " ret=" << ret; return ret; } @@ -130,8 +128,7 @@ { qCDebug(kpLogCommands) << "kpCommandSize::StringSize(" << string << ")" << " len=" << string.length () - << " sizeof(QChar)=" << sizeof (QChar) - << endl; + << " sizeof(QChar)=" << sizeof (QChar); return static_cast (static_cast (string.length ()) * sizeof (QChar)); } @@ -141,8 +138,7 @@ { qCDebug(kpLogCommands) << "kpCommandSize::PolygonSize() points.size=" << points.size () - << " sizeof(QPoint)=" << sizeof (QPoint) - << endl; + << " sizeof(QPoint)=" << sizeof (QPoint); return static_cast (static_cast (points.size ()) * sizeof (QPoint)); } diff --git a/commands/kpMacroCommand.cpp b/commands/kpMacroCommand.cpp --- a/commands/kpMacroCommand.cpp +++ b/commands/kpMacroCommand.cpp @@ -67,11 +67,10 @@ SizeType s = 0; qCDebug(kpLogCommands) << "\tcalculating:"; - foreach (kpCommand *cmd, m_commandList) + for (auto *cmd : m_commandList) { qCDebug(kpLogCommands) << "\t\tcurrentSize=" << s << " + " - << cmd->name () << ".size=" << cmd->size () - << endl; + << cmd->name () << ".size=" << cmd->size (); s += cmd->size (); } diff --git a/commands/tools/flow/kpToolFlowCommand.cpp b/commands/tools/flow/kpToolFlowCommand.cpp --- a/commands/tools/flow/kpToolFlowCommand.cpp +++ b/commands/tools/flow/kpToolFlowCommand.cpp @@ -106,8 +106,7 @@ qCDebug(kpLogCommands) << "kpToolFlowCommand::updateBoundingRect() existing=" << d->boundingRect << " plus=" - << rect - << endl; + << rect; d->boundingRect = d->boundingRect.united (rect); qCDebug(kpLogCommands) << "\tresult=" << d->boundingRect; } diff --git a/commands/tools/kpToolColorPickerCommand.cpp b/commands/tools/kpToolColorPickerCommand.cpp --- a/commands/tools/kpToolColorPickerCommand.cpp +++ b/commands/tools/kpToolColorPickerCommand.cpp @@ -50,9 +50,7 @@ { } -kpToolColorPickerCommand::~kpToolColorPickerCommand () -{ -} +kpToolColorPickerCommand::~kpToolColorPickerCommand () = default; // public virtual [base kpCommand] diff --git a/commands/tools/kpToolFloodFillCommand.cpp b/commands/tools/kpToolFloodFillCommand.cpp --- a/commands/tools/kpToolFloodFillCommand.cpp +++ b/commands/tools/kpToolFloodFillCommand.cpp @@ -46,7 +46,7 @@ struct kpToolFloodFillCommandPrivate { kpImage oldImage; - bool fillEntireImage; + bool fillEntireImage{false}; }; //--------------------------------------------------------------------- @@ -99,7 +99,7 @@ void kpToolFloodFillCommand::execute () { qCDebug(kpLogCommands) << "kpToolFloodFillCommand::execute() fillEntireImage=" - << d->fillEntireImage << endl; + << d->fillEntireImage; kpDocument *doc = document (); Q_ASSERT (doc); @@ -136,7 +136,7 @@ void kpToolFloodFillCommand::unexecute () { qCDebug(kpLogCommands) << "kpToolFloodFillCommand::unexecute() fillEntireImage=" - << d->fillEntireImage << endl; + << d->fillEntireImage; kpDocument *doc = document (); Q_ASSERT (doc); diff --git a/commands/tools/polygonal/kpToolPolygonalCommand.cpp b/commands/tools/polygonal/kpToolPolygonalCommand.cpp --- a/commands/tools/polygonal/kpToolPolygonalCommand.cpp +++ b/commands/tools/polygonal/kpToolPolygonalCommand.cpp @@ -39,13 +39,13 @@ struct kpToolPolygonalCommandPrivate { - kpToolPolygonalBase::DrawShapeFunc drawShapeFunc; + kpToolPolygonalBase::DrawShapeFunc drawShapeFunc{}; QPolygon points; QRect boundingRect; kpColor fcolor; - int penWidth; + int penWidth{}; kpColor bcolor; kpImage oldImage; diff --git a/commands/tools/rectangular/kpToolRectangularCommand.cpp b/commands/tools/rectangular/kpToolRectangularCommand.cpp --- a/commands/tools/rectangular/kpToolRectangularCommand.cpp +++ b/commands/tools/rectangular/kpToolRectangularCommand.cpp @@ -47,12 +47,12 @@ struct kpToolRectangularCommandPrivate { - kpToolRectangularBase::DrawShapeFunc drawShapeFunc; + kpToolRectangularBase::DrawShapeFunc drawShapeFunc{}; QRect rect; kpColor fcolor; - int penWidth; + int penWidth{}; kpColor bcolor; kpImage oldImage; diff --git a/commands/tools/selection/kpToolImageSelectionTransparencyCommand.cpp b/commands/tools/selection/kpToolImageSelectionTransparencyCommand.cpp --- a/commands/tools/selection/kpToolImageSelectionTransparencyCommand.cpp +++ b/commands/tools/selection/kpToolImageSelectionTransparencyCommand.cpp @@ -52,9 +52,7 @@ { } -kpToolImageSelectionTransparencyCommand::~kpToolImageSelectionTransparencyCommand () -{ -} +kpToolImageSelectionTransparencyCommand::~kpToolImageSelectionTransparencyCommand () = default; // public virtual [base kpCommand] @@ -73,8 +71,9 @@ environ ()->setImageSelectionTransparency (m_st, true/*force colour change*/); - if (imageSelection ()) + if (imageSelection ()) { imageSelection ()->setTransparency (m_st); + } } // public virtual [base kpCommand] @@ -86,7 +85,8 @@ environ ()->setImageSelectionTransparency (m_oldST, true/*force colour change*/); - if (imageSelection ()) + if (imageSelection ()) { imageSelection ()->setTransparency (m_oldST); + } } diff --git a/commands/tools/selection/kpToolSelectionCreateCommand.cpp b/commands/tools/selection/kpToolSelectionCreateCommand.cpp --- a/commands/tools/selection/kpToolSelectionCreateCommand.cpp +++ b/commands/tools/selection/kpToolSelectionCreateCommand.cpp @@ -102,24 +102,25 @@ if (m_fromSelection) { qCDebug(kpLogCommands) << "\tusing fromSelection"; - qCDebug(kpLogCommands) << "\t\thave sel=" << doc->selection () - << endl; - kpAbstractImageSelection *imageSel = - dynamic_cast (m_fromSelection); - kpTextSelection *textSel = - dynamic_cast (m_fromSelection); + qCDebug(kpLogCommands) << "\t\thave sel=" << doc->selection (); + auto *imageSel = dynamic_cast (m_fromSelection); + auto *textSel = dynamic_cast (m_fromSelection); + if (imageSel) { - if (imageSel->transparency () != environ ()->imageSelectionTransparency ()) + if (imageSel->transparency () != environ ()->imageSelectionTransparency ()) { environ ()->setImageSelectionTransparency (imageSel->transparency ()); + } } else if (textSel) { - if (textSel->textStyle () != environ ()->textStyle ()) + if (textSel->textStyle () != environ ()->textStyle ()) { environ ()->setTextStyle (textSel->textStyle ()); + } } - else + else { Q_ASSERT (!"Unknown selection type"); + } viewManager ()->setTextCursorPosition (m_textRow, m_textCol); doc->setSelection (*m_fromSelection); @@ -137,8 +138,9 @@ if (!doc->selection ()) { // Was just a border that got deselected? - if (m_fromSelection && !m_fromSelection->hasContent ()) + if (m_fromSelection && !m_fromSelection->hasContent ()) { return; + } Q_ASSERT (!"kpToolSelectionCreateCommand::unexecute() without sel region"); return; diff --git a/commands/tools/selection/kpToolSelectionDestroyCommand.cpp b/commands/tools/selection/kpToolSelectionDestroyCommand.cpp --- a/commands/tools/selection/kpToolSelectionDestroyCommand.cpp +++ b/commands/tools/selection/kpToolSelectionDestroyCommand.cpp @@ -89,8 +89,9 @@ m_oldDocImage = doc->getImageAt (doc->selection ()->boundingRect ()); doc->selectionPushOntoDocument (); } - else + else { doc->selectionDelete (); + } environ ()->somethingBelowTheCursorChanged (); } @@ -127,28 +128,31 @@ } qCDebug(kpLogCommands) << "\tsetting selection to: rect=" << m_oldSelectionPtr->boundingRect () - << " hasContent=" << m_oldSelectionPtr->hasContent () - << endl; - kpAbstractImageSelection *imageSel = - dynamic_cast (m_oldSelectionPtr); - kpTextSelection *textSel = - dynamic_cast (m_oldSelectionPtr); + << " hasContent=" << m_oldSelectionPtr->hasContent (); + auto *imageSel = dynamic_cast (m_oldSelectionPtr); + auto *textSel = dynamic_cast (m_oldSelectionPtr); + if (imageSel) { - if (imageSel->transparency () != environ ()->imageSelectionTransparency ()) + if (imageSel->transparency () != environ ()->imageSelectionTransparency ()) { environ ()->setImageSelectionTransparency (imageSel->transparency ()); - if (dynamic_cast (doc->selection())) + } + if (dynamic_cast (doc->selection())) { doc->selectionPushOntoDocument(); + } } else if (textSel) { - if (textSel->textStyle () != environ ()->textStyle ()) + if (textSel->textStyle () != environ ()->textStyle ()) { environ ()->setTextStyle (textSel->textStyle ()); - if (dynamic_cast (doc->selection())) + } + if (dynamic_cast (doc->selection())) { doc->selectionPushOntoDocument(); + } } - else + else { Q_ASSERT (!"Unknown selection type"); + } viewManager ()->setTextCursorPosition (m_textRow, m_textCol); doc->setSelection (*m_oldSelectionPtr); diff --git a/commands/tools/selection/kpToolSelectionMoveCommand.cpp b/commands/tools/selection/kpToolSelectionMoveCommand.cpp --- a/commands/tools/selection/kpToolSelectionMoveCommand.cpp +++ b/commands/tools/selection/kpToolSelectionMoveCommand.cpp @@ -54,9 +54,7 @@ m_startPoint = m_endPoint = doc->selection ()->topLeft (); } -kpToolSelectionMoveCommand::~kpToolSelectionMoveCommand () -{ -} +kpToolSelectionMoveCommand::~kpToolSelectionMoveCommand () = default; // public @@ -98,7 +96,7 @@ vm->setQueueUpdates (); { - foreach (const QPoint &p, m_copyOntoDocumentPoints) + for (const auto &p : m_copyOntoDocumentPoints) { sel->moveTo (p); doc->selectionCopyOntoDocument (); @@ -128,8 +126,9 @@ vm->setQueueUpdates (); - if (!m_oldDocumentImage.isNull ()) + if (!m_oldDocumentImage.isNull ()) { doc->setImageAt (m_oldDocumentImage, m_documentBoundingRect.topLeft ()); + } qCDebug(kpLogCommands) << "\tmove to startPoint=" << m_startPoint; sel->moveTo (m_startPoint); @@ -142,8 +141,7 @@ void kpToolSelectionMoveCommand::moveTo (const QPoint &point, bool moveLater) { qCDebug(kpLogCommands) << "kpToolSelectionMoveCommand::moveTo" << point - << " moveLater=" << moveLater - <() environ=" - << environ - << endl; + << environ; } -kpToolSelectionPullFromDocumentCommand::~kpToolSelectionPullFromDocumentCommand () -{ -} +kpToolSelectionPullFromDocumentCommand::~kpToolSelectionPullFromDocumentCommand () = default; // public virtual [base kpCommand] @@ -95,8 +92,9 @@ // b) image selection with no content, at an arbitrary location Q_ASSERT (!imageSelection () || !imageSelection ()->hasContent ()); - const kpAbstractImageSelection *originalImageSel = - static_cast (originalSelection ()); + const auto *originalImageSel = dynamic_cast + (originalSelection ()); + if (originalImageSel->transparency () != environ ()->imageSelectionTransparency ()) { diff --git a/commands/tools/selection/kpToolSelectionResizeScaleCommand.cpp b/commands/tools/selection/kpToolSelectionResizeScaleCommand.cpp --- a/commands/tools/selection/kpToolSelectionResizeScaleCommand.cpp +++ b/commands/tools/selection/kpToolSelectionResizeScaleCommand.cpp @@ -95,8 +95,9 @@ // public void kpToolSelectionResizeScaleCommand::moveTo (const QPoint &point) { - if (point == m_newTopLeft) + if (point == m_newTopLeft) { return; + } m_newTopLeft = point; selection ()->moveTo (m_newTopLeft); @@ -119,8 +120,9 @@ void kpToolSelectionResizeScaleCommand::resize (int width, int height, bool delayed) { - if (width == m_newWidth && height == m_newHeight) + if (width == m_newWidth && height == m_newHeight) { return; + } m_newWidth = width; m_newHeight = height; @@ -159,25 +161,23 @@ void kpToolSelectionResizeScaleCommand::resizeScaleAndMove (bool delayed) { qCDebug(kpLogCommands) << "kpToolSelectionResizeScaleCommand::resizeScaleAndMove(delayed=" - << delayed << ")" << endl; + << delayed << ")"; killSmoothScaleTimer (); kpAbstractSelection *newSelPtr = nullptr; if (textSelection ()) { Q_ASSERT (dynamic_cast (m_originalSelectionPtr)); - kpTextSelection *orgTextSel = - static_cast (m_originalSelectionPtr); + auto *orgTextSel = dynamic_cast (m_originalSelectionPtr); newSelPtr = orgTextSel->resized (m_newWidth, m_newHeight); } else { Q_ASSERT (dynamic_cast (m_originalSelectionPtr)); - kpAbstractImageSelection *imageSel = - static_cast (m_originalSelectionPtr); + auto *imageSel = dynamic_cast (m_originalSelectionPtr); newSelPtr = new kpRectangularImageSelection ( QRect (imageSel->x (), @@ -210,8 +210,7 @@ { qCDebug(kpLogCommands) << "kpToolSelectionResizeScaleCommand::finalize()" << " smoothScaleTimer->isActive=" - << m_smoothScaleTimer->isActive () - << endl; + << m_smoothScaleTimer->isActive (); // Make sure the selection contains the final image and the timer won't // fire afterwards. diff --git a/commands/tools/selection/text/kpToolTextBackspaceCommand.cpp b/commands/tools/selection/text/kpToolTextBackspaceCommand.cpp --- a/commands/tools/selection/text/kpToolTextBackspaceCommand.cpp +++ b/commands/tools/selection/text/kpToolTextBackspaceCommand.cpp @@ -45,13 +45,12 @@ { viewManager ()->setTextCursorPosition (m_row, m_col); - if (action == AddBackspaceNow) + if (action == AddBackspaceNow) { addBackspace (); + } } -kpToolTextBackspaceCommand::~kpToolTextBackspaceCommand () -{ -} +kpToolTextBackspaceCommand::~kpToolTextBackspaceCommand () = default; // public @@ -110,8 +109,9 @@ int oldNumBackspaces = m_numBackspaces; m_numBackspaces = 0; - for (int i = 0; i < oldNumBackspaces; i++) + for (int i = 0; i < oldNumBackspaces; i++) { addBackspace (); + } } // public virtual [base kpCommand] @@ -121,9 +121,9 @@ QList textLines = textSelection ()->textLines (); - for (int i = 0; i < static_cast (m_deletedText.length ()); i++) + for (auto && i : m_deletedText) { - if (m_deletedText [i] == '\n') + if (i == '\n') { const QString rightHalf = textLines [m_row].mid (m_col); @@ -138,7 +138,7 @@ const QString leftHalf = textLines [m_row].left (m_col); const QString rightHalf = textLines [m_row].mid (m_col); - textLines [m_row] = leftHalf + m_deletedText [i] + rightHalf; + textLines [m_row] = leftHalf + i + rightHalf; m_col++; } } diff --git a/commands/tools/selection/text/kpToolTextChangeStyleCommand.cpp b/commands/tools/selection/text/kpToolTextChangeStyleCommand.cpp --- a/commands/tools/selection/text/kpToolTextChangeStyleCommand.cpp +++ b/commands/tools/selection/text/kpToolTextChangeStyleCommand.cpp @@ -45,9 +45,7 @@ { } -kpToolTextChangeStyleCommand::~kpToolTextChangeStyleCommand () -{ -} +kpToolTextChangeStyleCommand::~kpToolTextChangeStyleCommand () = default; // public virtual [base kpCommand] @@ -66,13 +64,13 @@ << " isBold=" << m_newTextStyle.isBold () << " isItalic=" << m_newTextStyle.isItalic () << " isUnderline=" << m_newTextStyle.isUnderline () - << " isStrikeThru=" << m_newTextStyle.isStrikeThru () - << endl; + << " isStrikeThru=" << m_newTextStyle.isStrikeThru (); environ ()->setTextStyle (m_newTextStyle); - if (textSelection ()) + if (textSelection ()) { textSelection ()->setTextStyle (m_newTextStyle); + } } // public virtual [base kpCommand] @@ -84,8 +82,7 @@ << " isBold=" << m_newTextStyle.isBold () << " isItalic=" << m_newTextStyle.isItalic () << " isUnderline=" << m_newTextStyle.isUnderline () - << " isStrikeThru=" << m_newTextStyle.isStrikeThru () - << endl; + << " isStrikeThru=" << m_newTextStyle.isStrikeThru (); environ ()->setTextStyle (m_oldTextStyle); diff --git a/commands/tools/selection/text/kpToolTextDeleteCommand.cpp b/commands/tools/selection/text/kpToolTextDeleteCommand.cpp --- a/commands/tools/selection/text/kpToolTextDeleteCommand.cpp +++ b/commands/tools/selection/text/kpToolTextDeleteCommand.cpp @@ -45,13 +45,12 @@ { viewManager ()->setTextCursorPosition (m_row, m_col); - if (action == AddDeleteNow) + if (action == AddDeleteNow) { addDelete (); + } } -kpToolTextDeleteCommand::~kpToolTextDeleteCommand () -{ -} +kpToolTextDeleteCommand::~kpToolTextDeleteCommand () = default; // public @@ -102,8 +101,9 @@ int oldNumDeletes = m_numDeletes; m_numDeletes = 0; - for (int i = 0; i < oldNumDeletes; i++) + for (int i = 0; i < oldNumDeletes; i++) { addDelete (); + } } // public virtual [base kpCommand] @@ -113,9 +113,9 @@ QList textLines = textSelection ()->textLines (); - for (int i = 0; i < static_cast (m_deletedText.length ()); i++) + for (auto && i : m_deletedText) { - if (m_deletedText [i] == '\n') + if (i == '\n') { const QString rightHalf = textLines [m_row].mid (m_col); @@ -127,7 +127,7 @@ const QString leftHalf = textLines [m_row].left (m_col); const QString rightHalf = textLines [m_row].mid (m_col); - textLines [m_row] = leftHalf + m_deletedText [i] + rightHalf; + textLines [m_row] = leftHalf + i + rightHalf; } } diff --git a/commands/tools/selection/text/kpToolTextEnterCommand.cpp b/commands/tools/selection/text/kpToolTextEnterCommand.cpp --- a/commands/tools/selection/text/kpToolTextEnterCommand.cpp +++ b/commands/tools/selection/text/kpToolTextEnterCommand.cpp @@ -45,13 +45,12 @@ { viewManager ()->setTextCursorPosition (m_row, m_col); - if (action == AddEnterNow) + if (action == AddEnterNow) { addEnter (); + } } -kpToolTextEnterCommand::~kpToolTextEnterCommand () -{ -} +kpToolTextEnterCommand::~kpToolTextEnterCommand () = default; // public @@ -89,8 +88,9 @@ int oldNumEnters = m_numEnters; m_numEnters = 0; - for (int i = 0; i < oldNumEnters; i++) + for (int i = 0; i < oldNumEnters; i++) { addEnter (); + } } // public virtual [base kpCommand] @@ -104,8 +104,9 @@ { Q_ASSERT (m_col == 0); - if (m_row <= 0) + if (m_row <= 0) { break; + } int newRow = m_row - 1; int newCol = textLines [newRow].length (); diff --git a/commands/tools/selection/text/kpToolTextGiveContentCommand.cpp b/commands/tools/selection/text/kpToolTextGiveContentCommand.cpp --- a/commands/tools/selection/text/kpToolTextGiveContentCommand.cpp +++ b/commands/tools/selection/text/kpToolTextGiveContentCommand.cpp @@ -45,13 +45,10 @@ : kpAbstractSelectionContentCommand (originalSelBorder, name, environ) { qCDebug(kpLogCommands) << "kpToolTextGiveContentCommand::() environ=" - << environ - << endl; + << environ; } -kpToolTextGiveContentCommand::~kpToolTextGiveContentCommand () -{ -} +kpToolTextGiveContentCommand::~kpToolTextGiveContentCommand () = default; // public virtual [base kpCommand] @@ -96,10 +93,12 @@ // b) text selection with no content, at an arbitrary location Q_ASSERT (!textSelection () || !textSelection ()->hasContent ()); - const kpTextSelection *originalTextSel = - static_cast (originalSelection ()); - if (originalTextSel->textStyle () != environ ()->textStyle ()) + const auto *originalTextSel = dynamic_cast + (originalSelection ()); + + if (originalTextSel->textStyle () != environ ()->textStyle ()) { environ ()->setTextStyle (originalTextSel->textStyle ()); + } doc->setSelection (*originalSelection ()); diff --git a/commands/tools/selection/text/kpToolTextInsertCommand.h b/commands/tools/selection/text/kpToolTextInsertCommand.h --- a/commands/tools/selection/text/kpToolTextInsertCommand.h +++ b/commands/tools/selection/text/kpToolTextInsertCommand.h @@ -37,7 +37,7 @@ { public: kpToolTextInsertCommand (const QString &name, - int row, int col, QString newText, + int row, int col, const QString& newText, kpCommandEnvironment *environ); void addText (const QString &moreText); diff --git a/commands/tools/selection/text/kpToolTextInsertCommand.cpp b/commands/tools/selection/text/kpToolTextInsertCommand.cpp --- a/commands/tools/selection/text/kpToolTextInsertCommand.cpp +++ b/commands/tools/selection/text/kpToolTextInsertCommand.cpp @@ -38,7 +38,7 @@ //--------------------------------------------------------------------- kpToolTextInsertCommand::kpToolTextInsertCommand (const QString &name, - int row, int col, QString newText, + int row, int col, const QString& newText, kpCommandEnvironment *environ) : kpNamedCommand (name, environ), m_row (row), m_col (col) @@ -52,8 +52,9 @@ // public void kpToolTextInsertCommand::addText (const QString &moreText) { - if (moreText.isEmpty ()) + if (moreText.isEmpty ()) { return; + } QList textLines = textSelection ()->textLines (); const QString leftHalf = textLines [m_row].left (m_col); diff --git a/cursors/kpCursorLightCross.cpp b/cursors/kpCursorLightCross.cpp --- a/cursors/kpCursorLightCross.cpp +++ b/cursors/kpCursorLightCross.cpp @@ -72,11 +72,13 @@ break; } - if (colorValue) + if (colorValue) { colorBitmap [y * (width / 8) + (x / 8)] |= (1 << (x % 8)); + } - if (maskValue) + if (maskValue) { maskBitmap [y * (width / 8) + (x / 8)] |= (1 << (x % 8)); + } } @@ -86,8 +88,8 @@ const int side = 24; const int byteSize = (side * side) / 8; - unsigned char *colorBitmap = new unsigned char [byteSize]; - unsigned char *maskBitmap = new unsigned char [byteSize]; + auto *colorBitmap = new unsigned char [byteSize]; + auto *maskBitmap = new unsigned char [byteSize]; memset (colorBitmap, 0, byteSize); memset (maskBitmap, 0, byteSize); diff --git a/cursors/kpCursorProvider.cpp b/cursors/kpCursorProvider.cpp --- a/cursors/kpCursorProvider.cpp +++ b/cursors/kpCursorProvider.cpp @@ -40,8 +40,9 @@ QCursor kpCursorProvider::lightCross () { // TODO: don't leak (although it's cleaned up on exit by OS anyway) - if (!::TheLightCursor) + if (!::TheLightCursor) { ::TheLightCursor = kpCursorLightCrossCreate (); + } return *::TheLightCursor; } diff --git a/dialogs/imagelib/effects/kpEffectsDialog.cpp b/dialogs/imagelib/effects/kpEffectsDialog.cpp --- a/dialogs/imagelib/effects/kpEffectsDialog.cpp +++ b/dialogs/imagelib/effects/kpEffectsDialog.cpp @@ -83,19 +83,22 @@ setUpdatesEnabled (false); - if (actOnSelection) + if (actOnSelection) { setWindowTitle (i18nc ("@title:window", "More Image Effects (Selection)")); - else + } + else { setWindowTitle (i18nc ("@title:window", "More Image Effects")); + } m_delayedUpdateTimer->setSingleShot (true); connect (m_delayedUpdateTimer, &QTimer::timeout, this, &kpEffectsDialog::slotUpdateWithWaitCursor); QWidget *effectContainer = new QWidget (mainWidget ()); - QHBoxLayout *containerLayout = new QHBoxLayout (effectContainer); + + auto *containerLayout = new QHBoxLayout (effectContainer); containerLayout->setContentsMargins(0, 0, 0, 0); QLabel *label = new QLabel (i18n ("&Effect:"), effectContainer); @@ -152,17 +155,19 @@ // public virtual [base kpTransformPreviewDialog] bool kpEffectsDialog::isNoOp () const { - if (!m_effectWidget) + if (!m_effectWidget) { return true; + } return m_effectWidget->isNoOp (); } // public kpEffectCommandBase *kpEffectsDialog::createCommand () const { - if (!m_effectWidget) + if (!m_effectWidget) { return nullptr; + } return m_effectWidget->createCommand (m_environ->commandEnvironment ()); } @@ -172,23 +177,25 @@ QSize kpEffectsDialog::newDimensions () const { kpDocument *doc = document (); - if (!doc) - return QSize (); + if (!doc) { + return {}; + } - return QSize (doc->width (m_actOnSelection), - doc->height (m_actOnSelection)); + return {doc->width (m_actOnSelection), doc->height (m_actOnSelection)}; } // protected virtual [base kpTransformPreviewDialog] QImage kpEffectsDialog::transformPixmap (const QImage &pixmap, int targetWidth, int targetHeight) const { QImage pixmapWithEffect; - if (m_effectWidget && !m_effectWidget->isNoOp ()) + if (m_effectWidget && !m_effectWidget->isNoOp ()) { pixmapWithEffect = m_effectWidget->applyEffect (pixmap); - else + } + else { pixmapWithEffect = pixmap; + } return kpPixmapFX::scale (pixmapWithEffect, targetWidth, targetHeight); } @@ -213,8 +220,9 @@ return; } - if (which != m_effectsComboBox->currentIndex ()) + if (which != m_effectsComboBox->currentIndex ()) { m_effectsComboBox->setCurrentIndex (which); + } delete m_effectWidget; diff --git a/dialogs/imagelib/kpDocumentMetaInfoDialog.cpp b/dialogs/imagelib/kpDocumentMetaInfoDialog.cpp --- a/dialogs/imagelib/kpDocumentMetaInfoDialog.cpp +++ b/dialogs/imagelib/kpDocumentMetaInfoDialog.cpp @@ -119,15 +119,15 @@ setWindowTitle (i18nc ("@title:window", "Document Properties")); - QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Ok | + auto * buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect (buttons, &QDialogButtonBox::accepted, this, &kpDocumentMetaInfoDialog::accept); connect (buttons, &QDialogButtonBox::rejected, this, &kpDocumentMetaInfoDialog::reject); - QWidget *baseWidget = new QWidget (this); + auto *baseWidget = new QWidget (this); - QVBoxLayout *dialogLayout = new QVBoxLayout (this); + auto *dialogLayout = new QVBoxLayout (this); dialogLayout->addWidget (baseWidget); dialogLayout->addWidget (buttons); @@ -138,16 +138,16 @@ Q_ASSERT (::DpiInputMin < ::DpiInputMax); - QGroupBox *dpiGroupBox = new QGroupBox(i18n("Dots &Per Inch (DPI)"), baseWidget); + auto *dpiGroupBox = new QGroupBox(i18n("Dots &Per Inch (DPI)"), baseWidget); d->horizDpiInput = new QDoubleSpinBox(dpiGroupBox); d->horizDpiInput->setRange(::DpiInputMin, ::DpiInputMax); d->horizDpiInput->setValue(0.0); d->horizDpiInput->setSingleStep(::DpiInputStep); d->horizDpiInput->setDecimals(::DpiPrecision); d->horizDpiInput->setSpecialValueText(i18n("Unspecified")); - QLabel *dpiXLabel = new QLabel ( + auto *dpiXLabel = new QLabel ( i18nc ("Horizontal DPI 'x' Vertical DPI", " x "), dpiGroupBox); dpiXLabel->setAlignment (Qt::AlignCenter); @@ -159,7 +159,7 @@ d->vertDpiInput->setSpecialValueText(i18n("Unspecified")); - QGridLayout *dpiLay = new QGridLayout(dpiGroupBox); + auto *dpiLay = new QGridLayout(dpiGroupBox); dpiLay->addWidget(new QLabel(i18n("Horizontal:")), 0, 0, Qt::AlignHCenter); dpiLay->addWidget(d->horizDpiInput, 1, 0); @@ -202,15 +202,15 @@ // Offset Group Box // - QGroupBox *offsetGroupBox = new QGroupBox(i18n ("O&ffset"), baseWidget); + auto *offsetGroupBox = new QGroupBox(i18n ("O&ffset"), baseWidget); d->horizOffsetInput = new QSpinBox; d->horizOffsetInput->setRange(kpDocumentMetaInfo::MinOffset, kpDocumentMetaInfo::MaxOffset); d->vertOffsetInput = new QSpinBox; d->vertOffsetInput->setRange(kpDocumentMetaInfo::MinOffset, kpDocumentMetaInfo::MaxOffset); - QGridLayout *offsetLay = new QGridLayout(offsetGroupBox); + auto *offsetLay = new QGridLayout(offsetGroupBox); offsetLay->addWidget(new QLabel(i18n("Horizontal:")), 0, 0, Qt::AlignHCenter); offsetLay->addWidget(d->horizOffsetInput, 1, 0); @@ -238,7 +238,7 @@ // - QGroupBox *fieldsGroupBox = new QGroupBox (i18n ("&Text Fields"), + auto *fieldsGroupBox = new QGroupBox (i18n ("&Text Fields"), baseWidget); d->fieldsTableWidget = new QTableWidget (fieldsGroupBox); @@ -265,13 +265,13 @@ connect (d->fieldsResetButton, &QPushButton::clicked, this, &kpDocumentMetaInfoDialog::setUIToOriginalMetaInfo); - QHBoxLayout *fieldsButtonsLayout = new QHBoxLayout (); + auto *fieldsButtonsLayout = new QHBoxLayout (); fieldsButtonsLayout->addWidget (d->fieldsAddRowButton); fieldsButtonsLayout->addWidget (d->fieldsDeleteRowButton); fieldsButtonsLayout->addStretch (); fieldsButtonsLayout->addWidget (d->fieldsResetButton); - QVBoxLayout *fieldsLayout = new QVBoxLayout (fieldsGroupBox); + auto *fieldsLayout = new QVBoxLayout (fieldsGroupBox); fieldsLayout->addWidget (d->fieldsTableWidget); fieldsLayout->addLayout (fieldsButtonsLayout); @@ -296,9 +296,7 @@ // // Global Layout // - - - QGridLayout *baseLayout = new QGridLayout (baseWidget); + auto *baseLayout = new QGridLayout (baseWidget); baseLayout->setContentsMargins(0, 0, 0, 0); // Col 0 @@ -318,8 +316,9 @@ setUIToOriginalMetaInfo (); - if (::LastWidth > 0 && ::LastHeight > 0) + if (::LastWidth > 0 && ::LastHeight > 0) { resize (::LastWidth, ::LastHeight); + } } //--------------------------------------------------------------------- @@ -374,7 +373,7 @@ d->fieldsTableWidget->setHorizontalHeaderLabels (fieldsHeader); int row = 0; - foreach (const QString &key, d->originalMetaInfoPtr->textKeys ()) + for (const auto &key : d->originalMetaInfoPtr->textKeys ()) { d->fieldsTableWidget->setItem (row, 0/*1st col*/, new QTableWidgetItem (key)); @@ -425,15 +424,19 @@ kpDocumentMetaInfo ret; - if (d->horizDpiInput->value () < ::DpiLegalMin) + if (d->horizDpiInput->value () < ::DpiLegalMin) { ret.setDotsPerMeterX (0/*unspecified*/); - else + } + else { ret.setDotsPerMeterX (qRound (d->horizDpiInput->value () * KP_INCHES_PER_METER)); + } - if (d->vertDpiInput->value () < ::DpiLegalMin) + if (d->vertDpiInput->value () < ::DpiLegalMin) { ret.setDotsPerMeterY (0/*unspecified*/); - else + } + else { ret.setDotsPerMeterY (qRound (d->vertDpiInput->value () * KP_INCHES_PER_METER)); + } ret.setOffset (QPoint (d->horizOffsetInput->value (), @@ -455,21 +458,21 @@ continue; } // Value without a key? - else + + + if (errorMessage) { - if (errorMessage) - { - *errorMessage = + *errorMessage = ki18n ("The text value \"%1\" on line %2 requires a key.") - .subs (value).subs (r + 1/*count from 1*/).toString (); - - // Print only 1 error message per method invocation. - errorMessage = nullptr; - } + .subs (value).subs (r + 1/*count from 1*/).toString (); - // Ignore. - continue; + // Print only 1 error message per method invocation. + errorMessage = nullptr; } + + // Ignore. + continue; + } // Duplicate key? @@ -480,8 +483,9 @@ int q; for (q = 0; q < r; q++) { - if (d->fieldsTableWidget->item (q, 0)->text () == key) + if (d->fieldsTableWidget->item (q, 0)->text () == key) { break; + } } Q_ASSERT (q != r); @@ -514,8 +518,9 @@ void kpDocumentMetaInfoDialog::fieldsUpdateVerticalHeader () { QStringList vertLabels; - for (int r = 1; r <= d->fieldsTableWidget->rowCount (); r++) + for (int r = 1; r <= d->fieldsTableWidget->rowCount (); r++) { vertLabels << QString::number (r); + } d->fieldsTableWidget->setVerticalHeaderLabels (vertLabels); } @@ -562,7 +567,7 @@ { qCDebug(kpLogDialogs) << "kpDocumentMetaInfoDialog::fieldsDeleteRow(" << "row=" << r << ")" - << " currentRow=" << d->fieldsTableWidget->currentRow () << endl; + << " currentRow=" << d->fieldsTableWidget->currentRow (); Q_ASSERT (isFieldsRowDeleteable (r)); @@ -633,8 +638,7 @@ void kpDocumentMetaInfoDialog::slotFieldsItemChanged (QTableWidgetItem *it) { qCDebug(kpLogDialogs) << "kpDocumentMetaInfoDialog::slotFieldsItemChanged(" - << "item=" << it << ") rows=" << d->fieldsTableWidget->rowCount () - << endl; + << "item=" << it << ") rows=" << d->fieldsTableWidget->rowCount (); const int r = d->fieldsTableWidget->row (it); qCDebug(kpLogDialogs) << "\tr=" << r; @@ -668,8 +672,7 @@ void kpDocumentMetaInfoDialog::slotFieldsAddRowButtonClicked () { - qCDebug(kpLogDialogs) << "kpDocumentMetaInfoDialog::slotFieldsAddRowButtonClicked()" - << endl; + qCDebug(kpLogDialogs) << "kpDocumentMetaInfoDialog::slotFieldsAddRowButtonClicked()"; const int r = d->fieldsTableWidget->currentRow (); qCDebug(kpLogDialogs) << "\tr=" << r; @@ -687,8 +690,7 @@ // private slot void kpDocumentMetaInfoDialog::slotFieldsDeleteRowButtonClicked () { - qCDebug(kpLogDialogs) << "kpDocumentMetaInfoDialog::slotFieldsDeleteRowButtonClicked()" - << endl; + qCDebug(kpLogDialogs) << "kpDocumentMetaInfoDialog::slotFieldsDeleteRowButtonClicked()"; const int r = d->fieldsTableWidget->currentRow (); qCDebug(kpLogDialogs) << "\tr=" << r; diff --git a/dialogs/imagelib/transforms/kpTransformPreviewDialog.cpp b/dialogs/imagelib/transforms/kpTransformPreviewDialog.cpp --- a/dialogs/imagelib/transforms/kpTransformPreviewDialog.cpp +++ b/dialogs/imagelib/transforms/kpTransformPreviewDialog.cpp @@ -78,7 +78,7 @@ QWidget *baseWidget = new QWidget (this); m_mainWidget = baseWidget; - QVBoxLayout *dialogLayout = new QVBoxLayout (this); + auto *dialogLayout = new QVBoxLayout (this); dialogLayout->addWidget (baseWidget); dialogLayout->addWidget (buttons); @@ -94,11 +94,13 @@ } - if (features & Dimensions) + if (features & Dimensions) { createDimensionsGroupBox (); + } - if (features & Preview) + if (features & Preview) { createPreviewGroupBox (); + } m_gridLayout = new QGridLayout (baseWidget ); @@ -125,21 +127,19 @@ } m_gridLayout->setRowStretch (m_gridNumRows, 1); - m_gridNumRows++;; + m_gridNumRows++; } } -kpTransformPreviewDialog::~kpTransformPreviewDialog () -{ -} +kpTransformPreviewDialog::~kpTransformPreviewDialog () = default; // private void kpTransformPreviewDialog::createDimensionsGroupBox () { m_dimensionsGroupBox = new QGroupBox (i18n ("Dimensions"), mainWidget ()); - QLabel *originalLabel = new QLabel (i18n ("Original:"), m_dimensionsGroupBox); + auto *originalLabel = new QLabel (i18n ("Original:"), m_dimensionsGroupBox); QString originalDimensions; if (document ()) { @@ -150,16 +150,17 @@ // Stop the Dimensions Group Box from resizing so often const QString minimumLengthString ("100000 x 100000"); const int padLength = minimumLengthString.length (); - for (int i = originalDimensions.length (); i < padLength; i++) + for (int i = originalDimensions.length (); i < padLength; i++) { originalDimensions += ' '; + } } - QLabel *originalDimensionsLabel = new QLabel (originalDimensions, m_dimensionsGroupBox); + auto *originalDimensionsLabel = new QLabel (originalDimensions, m_dimensionsGroupBox); - QLabel *afterTransformLabel = new QLabel (m_afterActionText, m_dimensionsGroupBox); + auto *afterTransformLabel = new QLabel (m_afterActionText, m_dimensionsGroupBox); m_afterTransformDimensionsLabel = new QLabel (m_dimensionsGroupBox); - QGridLayout *dimensionsLayout = new QGridLayout (m_dimensionsGroupBox ); + auto *dimensionsLayout = new QGridLayout (m_dimensionsGroupBox ); dimensionsLayout->addWidget (originalLabel, 0, 0, Qt::AlignBottom); dimensionsLayout->addWidget (originalDimensionsLabel, 0, 1, Qt::AlignBottom); dimensionsLayout->addWidget (afterTransformLabel, 1, 0, Qt::AlignTop); @@ -182,7 +183,7 @@ this, &kpTransformPreviewDialog::slotUpdateWithWaitCursor); - QVBoxLayout *previewLayout = new QVBoxLayout (m_previewGroupBox); + auto *previewLayout = new QVBoxLayout (m_previewGroupBox); previewLayout->addWidget (m_previewPixmapLabel, 1/*stretch*/); previewLayout->addWidget (updatePushButton, 0/*stretch*/, Qt::AlignHCenter); } @@ -219,20 +220,23 @@ { QDialog::setUpdatesEnabled (enable); - if (enable) + if (enable) { slotUpdateWithWaitCursor (); + } } // private void kpTransformPreviewDialog::updateDimensions () { - if (!m_dimensionsGroupBox) + if (!m_dimensionsGroupBox) { return; + } kpDocument *doc = document (); - if (!doc) + if (!doc) { return; + } if (!updatesEnabled ()) { @@ -281,8 +285,9 @@ << " previewPixmapLabel.size=" << m_previewPixmapLabel->size (); - if (!m_previewGroupBox) + if (!m_previewGroupBox) { return; + } kpDocument *doc = document (); @@ -305,8 +310,9 @@ if (m_actOnSelection) { kpAbstractImageSelection *sel = doc->imageSelection ()->clone (); - if (!sel->hasContent ()) + if (!sel->hasContent ()) { sel->setBaseImage (doc->getSelectedBaseImage ()); + } image = sel->transparentImage (); delete sel; @@ -335,13 +341,15 @@ { qCDebug(kpLogDialogs) << "kpTransformPreviewDialog::updatePreview()"; - if (!m_previewGroupBox) + if (!m_previewGroupBox) { return; + } kpDocument *doc = document (); - if (!doc) + if (!doc) { return; + } if (!updatesEnabled ()) diff --git a/dialogs/imagelib/transforms/kpTransformResizeScaleDialog.cpp b/dialogs/imagelib/transforms/kpTransformResizeScaleDialog.cpp --- a/dialogs/imagelib/transforms/kpTransformResizeScaleDialog.cpp +++ b/dialogs/imagelib/transforms/kpTransformResizeScaleDialog.cpp @@ -99,15 +99,15 @@ QWidget *baseWidget = new QWidget (this); - QVBoxLayout *dialogLayout = new QVBoxLayout (this); + auto *dialogLayout = new QVBoxLayout (this); dialogLayout->addWidget (baseWidget); dialogLayout->addWidget (buttons); QWidget *actOnBox = createActOnBox(baseWidget); QGroupBox *operationGroupBox = createOperationGroupBox(baseWidget); QGroupBox *dimensionsGroupBox = createDimensionsGroupBox(baseWidget); - QVBoxLayout *baseLayout = new QVBoxLayout (baseWidget); + auto *baseLayout = new QVBoxLayout (baseWidget); baseLayout->setContentsMargins(0, 0, 0, 0); baseLayout->addWidget(actOnBox); baseLayout->addWidget(operationGroupBox); @@ -160,7 +160,7 @@ QWidget *actOnBox = new QWidget (baseWidget); - QLabel *actOnLabel = new QLabel (i18n ("Ac&t on:"), actOnBox); + auto *actOnLabel = new QLabel (i18n ("Ac&t on:"), actOnBox); m_actOnCombo = new QComboBox (actOnBox); @@ -171,8 +171,9 @@ { QString selName = i18n ("Selection"); - if (textSelection ()) + if (textSelection ()) { selName = i18n ("Text Box"); + } m_actOnCombo->insertItem (Selection, selName); m_actOnCombo->setCurrentIndex (Selection); @@ -183,13 +184,11 @@ m_actOnCombo->setEnabled (false); } - - QHBoxLayout *lay = new QHBoxLayout (actOnBox); + auto *lay = new QHBoxLayout (actOnBox); lay->setContentsMargins(0, 0, 0, 0); lay->addWidget (actOnLabel); lay->addWidget (m_actOnCombo, 1); - connect (m_actOnCombo, static_cast(&QComboBox::activated), this, &kpTransformResizeScaleDialog::slotActOnChanged); @@ -252,13 +251,13 @@ QLatin1String ("smooth_scale"), i18n ("S&mooth Scale")); - QButtonGroup *resizeScaleButtonGroup = new QButtonGroup (baseWidget); + auto *resizeScaleButtonGroup = new QButtonGroup (baseWidget); resizeScaleButtonGroup->addButton (m_resizeButton); resizeScaleButtonGroup->addButton (m_scaleButton); resizeScaleButtonGroup->addButton (m_smoothScaleButton); - QGridLayout *operationLayout = new QGridLayout (operationGroupBox ); + auto *operationLayout = new QGridLayout (operationGroupBox ); operationLayout->addWidget (m_resizeButton, 0, 0, Qt::AlignCenter); operationLayout->addWidget (m_scaleButton, 0, 1, Qt::AlignCenter); operationLayout->addWidget (m_smoothScaleButton, 0, 2, Qt::AlignCenter); @@ -280,36 +279,36 @@ { QGroupBox *dimensionsGroupBox = new QGroupBox (i18n ("Dimensions"), baseWidget); - QLabel *widthLabel = new QLabel (i18n ("Width:"), dimensionsGroupBox); + auto *widthLabel = new QLabel (i18n ("Width:"), dimensionsGroupBox); widthLabel->setAlignment (widthLabel->alignment () | Qt::AlignHCenter); - QLabel *heightLabel = new QLabel (i18n ("Height:"), dimensionsGroupBox); + auto *heightLabel = new QLabel (i18n ("Height:"), dimensionsGroupBox); heightLabel->setAlignment (heightLabel->alignment () | Qt::AlignHCenter); - QLabel *originalLabel = new QLabel (i18n ("Original:"), dimensionsGroupBox); + auto *originalLabel = new QLabel (i18n ("Original:"), dimensionsGroupBox); m_originalWidthInput = new QSpinBox; m_originalWidthInput->setRange(1, INT_MAX); m_originalWidthInput->setValue(document()->width(static_cast (selection()))); - QLabel *xLabel0 = new QLabel (i18n ("x"), dimensionsGroupBox); + auto *xLabel0 = new QLabel (i18n ("x"), dimensionsGroupBox); m_originalHeightInput = new QSpinBox; m_originalHeightInput->setRange(1, INT_MAX); m_originalHeightInput->setValue(document()->height(static_cast (selection()))); - QLabel *newLabel = new QLabel (i18n ("&New:"), dimensionsGroupBox); + auto *newLabel = new QLabel (i18n ("&New:"), dimensionsGroupBox); m_newWidthInput = new QSpinBox; m_newWidthInput->setRange(1, INT_MAX); - QLabel *xLabel1 = new QLabel (i18n ("x"), dimensionsGroupBox); + auto *xLabel1 = new QLabel (i18n ("x"), dimensionsGroupBox); m_newHeightInput = new QSpinBox; m_newHeightInput->setRange(1, INT_MAX); - QLabel *percentLabel = new QLabel (i18n ("&Percent:"), dimensionsGroupBox); + auto *percentLabel = new QLabel (i18n ("&Percent:"), dimensionsGroupBox); m_percentWidthInput = new QDoubleSpinBox; m_percentWidthInput->setRange(0.01, 1000000); m_percentWidthInput->setValue(100); m_percentWidthInput->setSingleStep(1); m_percentWidthInput->setDecimals(2); m_percentWidthInput->setSuffix(i18n("%")); - QLabel *xLabel2 = new QLabel (i18n ("x"), dimensionsGroupBox); + auto *xLabel2 = new QLabel (i18n ("x"), dimensionsGroupBox); m_percentHeightInput = new QDoubleSpinBox; m_percentHeightInput->setRange(0.01, 1000000); @@ -331,7 +330,7 @@ percentLabel->setBuddy (m_percentWidthInput); - QGridLayout *dimensionsLayout = new QGridLayout (dimensionsGroupBox); + auto *dimensionsLayout = new QGridLayout (dimensionsGroupBox); dimensionsLayout->setColumnStretch (1/*column*/, 1); dimensionsLayout->setColumnStretch (3/*column*/, 1); @@ -466,20 +465,25 @@ } else { - if (m_lastType == kpTransformResizeScaleCommand::Scale) + if (m_lastType == kpTransformResizeScaleCommand::Scale) { m_scaleButton->setChecked (true); - else + } + else { m_smoothScaleButton->setChecked (true); + } } } else { - if (m_lastType == kpTransformResizeScaleCommand::Resize) + if (m_lastType == kpTransformResizeScaleCommand::Resize) { m_resizeButton->setChecked (true); - else if (m_lastType == kpTransformResizeScaleCommand::Scale) + } + else if (m_lastType == kpTransformResizeScaleCommand::Scale) { m_scaleButton->setChecked (true); - else + } + else { m_smoothScaleButton->setChecked (true); + } } @@ -553,7 +557,7 @@ void kpTransformResizeScaleDialog::slotPercentWidthChanged (double percentWidth) { qCDebug(kpLogDialogs) << "kpTransformResizeScaleDialog::slotPercentWidthChanged(" - << percentWidth << ")" << endl; + << percentWidth << ")"; SET_VALUE_WITHOUT_SIGNAL_EMISSION (m_newWidthInput, qRound (percentWidth * originalWidth () / 100.0)); @@ -569,7 +573,7 @@ void kpTransformResizeScaleDialog::slotPercentHeightChanged (double percentHeight) { qCDebug(kpLogDialogs) << "kpTransformResizeScaleDialog::slotPercentHeightChanged(" - << percentHeight << ")" << endl; + << percentHeight << ")"; SET_VALUE_WITHOUT_SIGNAL_EMISSION (m_newHeightInput, qRound (percentHeight * originalHeight () / 100.0)); @@ -585,12 +589,14 @@ void kpTransformResizeScaleDialog::setKeepAspectRatio (bool on) { qCDebug(kpLogDialogs) << "kpTransformResizeScaleDialog::setKeepAspectRatio(" - << on << ")" << endl; - if (on != m_keepAspectRatioCheckBox->isChecked ()) + << on << ")"; + if (on != m_keepAspectRatioCheckBox->isChecked ()) { m_keepAspectRatioCheckBox->setChecked (on); + } - if (on) + if (on) { widthFitHeightToAspectRatio (); + } } //--------------------------------------------------------------------- @@ -644,12 +650,15 @@ kpTransformResizeScaleCommand::Type kpTransformResizeScaleDialog::type () const { - if (m_resizeButton->isChecked ()) + if (m_resizeButton->isChecked ()) { return kpTransformResizeScaleCommand::Resize; - else if (m_scaleButton->isChecked ()) + } + + if (m_scaleButton->isChecked ()) { return kpTransformResizeScaleCommand::Scale; - else - return kpTransformResizeScaleCommand::SmoothScale; + } + + return kpTransformResizeScaleCommand::SmoothScale; } //--------------------------------------------------------------------- diff --git a/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp b/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp --- a/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp +++ b/dialogs/imagelib/transforms/kpTransformRotateDialog.cpp @@ -77,8 +77,9 @@ createAngleGroupBox (); - if (s_lastWidth > 0 && s_lastHeight > 0) + if (s_lastWidth > 0 && s_lastHeight > 0) { resize (s_lastWidth, s_lastHeight); + } slotAngleCustomRadioButtonToggled (m_angleCustomRadioButton->isChecked ()); @@ -95,14 +96,14 @@ // private void kpTransformRotateDialog::createDirectionGroupBox () { - QGroupBox *directionGroupBox = new QGroupBox (i18n ("Direction"), mainWidget ()); + auto *directionGroupBox = new QGroupBox (i18n ("Direction"), mainWidget ()); addCustomWidget (directionGroupBox); - QLabel *antiClockwisePixmapLabel = new QLabel (directionGroupBox); + auto *antiClockwisePixmapLabel = new QLabel (directionGroupBox); antiClockwisePixmapLabel->setPixmap (UserIcon ("image_rotate_anticlockwise")); - QLabel *clockwisePixmapLabel = new QLabel (directionGroupBox); + auto *clockwisePixmapLabel = new QLabel (directionGroupBox); clockwisePixmapLabel->setPixmap (UserIcon ("image_rotate_clockwise")); @@ -114,7 +115,7 @@ m_clockwiseRadioButton->setChecked (s_lastIsClockwise); - QGridLayout *directionLayout = new QGridLayout (directionGroupBox ); + auto *directionLayout = new QGridLayout (directionGroupBox ); directionLayout->addWidget (antiClockwisePixmapLabel, 0, 0, Qt::AlignCenter); directionLayout->addWidget (clockwisePixmapLabel, 0, 1, Qt::AlignCenter); directionLayout->addWidget (m_antiClockwiseRadioButton, 1, 0, Qt::AlignCenter); @@ -131,7 +132,7 @@ // private void kpTransformRotateDialog::createAngleGroupBox () { - QGroupBox *angleGroupBox = new QGroupBox (i18n ("Angle"), mainWidget ()); + auto *angleGroupBox = new QGroupBox (i18n ("Angle"), mainWidget ()); addCustomWidget (angleGroupBox); @@ -144,13 +145,13 @@ m_angleCustomInput->setMinimum(-359); m_angleCustomInput->setMaximum(+359); m_angleCustomInput->setValue(s_lastAngleCustom); - QLabel *degreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); + auto *degreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); m_angleCustomRadioButton->setChecked (true); - QGridLayout *angleLayout = new QGridLayout (angleGroupBox ); + auto *angleLayout = new QGridLayout (angleGroupBox ); angleLayout->addWidget (m_angle90RadioButton, 0, 0, 1, 3); angleLayout->addWidget (m_angle180RadioButton, 1, 0, 1, 3); @@ -194,25 +195,32 @@ int retAngle; - if (m_angle90RadioButton->isChecked ()) + if (m_angle90RadioButton->isChecked ()) { retAngle = 90; - else if (m_angle180RadioButton->isChecked ()) + } + else if (m_angle180RadioButton->isChecked ()) { retAngle = 180; - else if (m_angle270RadioButton->isChecked ()) + } + else if (m_angle270RadioButton->isChecked ()) { retAngle = 270; - else // if (m_angleCustomRadioButton->isChecked ()) + } + else { // if (m_angleCustomRadioButton->isChecked ()) retAngle = m_angleCustomInput->value (); + } - if (m_antiClockwiseRadioButton->isChecked ()) + if (m_antiClockwiseRadioButton->isChecked ()) { retAngle *= -1; + } - if (retAngle < 0) + if (retAngle < 0) { retAngle += ((0 - retAngle) / 360 + 1) * 360; + } - if (retAngle >= 360) + if (retAngle >= 360) { retAngle -= ((retAngle - 360) / 360 + 1) * 360; + } return retAngle; @@ -242,8 +250,9 @@ { m_angleCustomInput->setEnabled (isChecked); - if (isChecked) + if (isChecked) { m_angleCustomInput->setFocus(); + } } // private slot virtual [base kpTransformPreviewDialog] diff --git a/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp b/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp --- a/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp +++ b/dialogs/imagelib/transforms/kpTransformSkewDialog.cpp @@ -77,8 +77,9 @@ createAngleGroupBox (); - if (s_lastWidth > 0 && s_lastHeight > 0) + if (s_lastWidth > 0 && s_lastHeight > 0) { resize (s_lastWidth, s_lastHeight); + } slotUpdate (); @@ -97,39 +98,39 @@ // private void kpTransformSkewDialog::createAngleGroupBox () { - QGroupBox *angleGroupBox = new QGroupBox (i18n ("Angle"), mainWidget ()); + auto *angleGroupBox = new QGroupBox (i18n ("Angle"), mainWidget ()); addCustomWidget (angleGroupBox); - QLabel *horizontalSkewPixmapLabel = new QLabel (angleGroupBox); + auto *horizontalSkewPixmapLabel = new QLabel (angleGroupBox); horizontalSkewPixmapLabel->setPixmap (UserIcon ("image_skew_horizontal")); - QLabel *horizontalSkewLabel = new QLabel (i18n ("&Horizontal:"), angleGroupBox); + auto *horizontalSkewLabel = new QLabel (i18n ("&Horizontal:"), angleGroupBox); m_horizontalSkewInput = new QSpinBox; m_horizontalSkewInput->setValue(s_lastHorizontalAngle); m_horizontalSkewInput->setMinimum(-89); m_horizontalSkewInput->setMaximum(+89); - QLabel *horizontalSkewDegreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); + auto *horizontalSkewDegreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); - QLabel *verticalSkewPixmapLabel = new QLabel (angleGroupBox); + auto *verticalSkewPixmapLabel = new QLabel (angleGroupBox); verticalSkewPixmapLabel->setPixmap (UserIcon ("image_skew_vertical")); - QLabel *verticalSkewLabel = new QLabel (i18n ("&Vertical:"), angleGroupBox); + auto *verticalSkewLabel = new QLabel (i18n ("&Vertical:"), angleGroupBox); m_verticalSkewInput = new QSpinBox; m_verticalSkewInput->setValue(s_lastVerticalAngle); m_verticalSkewInput->setMinimum(-89); m_verticalSkewInput->setMaximum(+89); - QLabel *verticalSkewDegreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); + auto *verticalSkewDegreesLabel = new QLabel (i18n ("degrees"), angleGroupBox); horizontalSkewLabel->setBuddy (m_horizontalSkewInput); verticalSkewLabel->setBuddy (m_verticalSkewInput); - QGridLayout *angleLayout = new QGridLayout (angleGroupBox); + auto *angleLayout = new QGridLayout (angleGroupBox); angleLayout->addWidget (horizontalSkewPixmapLabel, 0, 0); angleLayout->addWidget (horizontalSkewLabel, 0, 1); @@ -158,12 +159,12 @@ kpDocument *doc = document (); Q_ASSERT (doc); - QTransform skewMatrix = kpPixmapFX::skewMatrix (doc->image (), + auto skewMatrix = kpPixmapFX::skewMatrix (doc->image (), horizontalAngleForPixmapFX (), verticalAngleForPixmapFX ()); - QRect skewRect = skewMatrix.mapRect (doc->rect (m_actOnSelection)); + auto skewRect = skewMatrix.mapRect (doc->rect (m_actOnSelection)); - return QSize (skewRect.width (), skewRect.height ()); + return {skewRect.width (), skewRect.height ()}; } // private virtual [base kpTransformPreviewDialog] diff --git a/dialogs/kpColorSimilarityDialog.cpp b/dialogs/kpColorSimilarityDialog.cpp --- a/dialogs/kpColorSimilarityDialog.cpp +++ b/dialogs/kpColorSimilarityDialog.cpp @@ -45,35 +45,35 @@ : QDialog (parent) { setWindowTitle (i18nc ("@title:window", "Color Similarity")); - QDialogButtonBox *buttons = new QDialogButtonBox (QDialogButtonBox::Ok | + auto *buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect (buttons, &QDialogButtonBox::accepted, this, &kpColorSimilarityDialog::accept); connect (buttons, &QDialogButtonBox::rejected, this, &kpColorSimilarityDialog::reject); - QWidget *baseWidget = new QWidget (this); + auto *baseWidget = new QWidget (this); - QVBoxLayout *dialogLayout = new QVBoxLayout (this); + auto *dialogLayout = new QVBoxLayout (this); dialogLayout->addWidget (baseWidget); dialogLayout->addWidget (buttons); - QGroupBox *cubeGroupBox = new QGroupBox (i18n ("Preview"), baseWidget); + auto *cubeGroupBox = new QGroupBox (i18n ("Preview"), baseWidget); m_colorSimilarityFrame = new kpColorSimilarityFrame(cubeGroupBox); m_colorSimilarityFrame->setMinimumSize (240, 180); - QPushButton *updatePushButton = new QPushButton (i18n ("&Update"), cubeGroupBox); + auto *updatePushButton = new QPushButton (i18n ("&Update"), cubeGroupBox); - QVBoxLayout *cubeLayout = new QVBoxLayout (cubeGroupBox); + auto *cubeLayout = new QVBoxLayout (cubeGroupBox); cubeLayout->addWidget (m_colorSimilarityFrame, 1/*stretch*/); cubeLayout->addWidget (updatePushButton, 0/*stretch*/, Qt::AlignHCenter); connect (updatePushButton, &QPushButton::clicked, this, &kpColorSimilarityDialog::slotColorSimilarityValueChanged); - QGroupBox *inputGroupBox = new QGroupBox (i18n ("&RGB Color Cube Distance"), + auto *inputGroupBox = new QGroupBox (i18n ("&RGB Color Cube Distance"), baseWidget); m_colorSimilarityInput = new kpIntNumInput (inputGroupBox); @@ -93,7 +93,7 @@ this, &kpColorSimilarityDialog::slotWhatIsLabelClicked); - QVBoxLayout *inputLayout = new QVBoxLayout (inputGroupBox); + auto *inputLayout = new QVBoxLayout (inputGroupBox); inputLayout->addWidget (m_colorSimilarityInput); inputLayout->addWidget (m_whatIsLabel); @@ -105,15 +105,13 @@ this, &kpColorSimilarityDialog::slotColorSimilarityValueChanged); - QVBoxLayout *baseLayout = new QVBoxLayout (baseWidget); + auto *baseLayout = new QVBoxLayout (baseWidget); baseLayout->setContentsMargins(0, 0, 0, 0); baseLayout->addWidget (cubeGroupBox, 1/*stretch*/); baseLayout->addWidget (inputGroupBox); } -kpColorSimilarityDialog::~kpColorSimilarityDialog () -{ -} +kpColorSimilarityDialog::~kpColorSimilarityDialog () = default; // public diff --git a/dialogs/kpDocumentSaveOptionsPreviewDialog.cpp b/dialogs/kpDocumentSaveOptionsPreviewDialog.cpp --- a/dialogs/kpDocumentSaveOptionsPreviewDialog.cpp +++ b/dialogs/kpDocumentSaveOptionsPreviewDialog.cpp @@ -60,11 +60,11 @@ { setWindowTitle (i18nc ("@title:window", "Save Preview")); - QWidget *baseWidget = this;//new QWidget (this); + auto *baseWidget = this;//new QWidget (this); //setMainWidget (baseWidget); - QGridLayout *lay = new QGridLayout ( baseWidget ); + auto *lay = new QGridLayout ( baseWidget ); m_filePixmapLabel = new kpResizeSignallingLabel (baseWidget); m_fileSizeLabel = new QLabel (baseWidget); @@ -93,11 +93,10 @@ // public QSize kpDocumentSaveOptionsPreviewDialog::preferredMinimumSize () const { - const int contentsWidth = 180; - const int totalMarginsWidth = fontMetrics ().height (); + const auto contentsWidth = 180; + const auto totalMarginsWidth = fontMetrics ().height (); - return QSize (contentsWidth + totalMarginsWidth, - contentsWidth * 3 / 4 + totalMarginsWidth); + return {contentsWidth + totalMarginsWidth, contentsWidth * 3 / 4 + totalMarginsWidth}; } @@ -123,8 +122,7 @@ << " pixmapSize=" << pixmapSize << " fileSize=" << fileSize << " raw fileSize/pixmapSize%=" - << (pixmapSize ? (kpCommandSize::SizeType) fileSize * 100 / pixmapSize : 0) - << endl; + << (pixmapSize ? (kpCommandSize::SizeType) fileSize * 100 / pixmapSize : 0); m_fileSizeLabel->setText (i18np ("1 byte (approx. %2%)", "%1 bytes (approx. %2%)", m_fileSize, percent)); @@ -135,8 +133,7 @@ { qCDebug(kpLogDialogs) << "kpDocumentSaveOptionsPreviewDialog::updatePreviewPixmap()" << " filePixmapLabel.size=" << m_filePixmapLabel->size () - << " filePixmap.size=" << m_filePixmap->size () - << endl; + << " filePixmap.size=" << m_filePixmap->size (); if (m_filePixmap) { @@ -150,8 +147,7 @@ m_filePixmap->width (), m_filePixmap->height ()); qCDebug(kpLogDialogs) << "\tmaxNewWidth=" << maxNewWidth << " maxNewHeight=" << maxNewHeight - << " keepsAspect=" << keepsAspect - << endl; + << " keepsAspect=" << keepsAspect; const int newWidth = kpTransformPreviewDialog::scaleDimension ( @@ -165,8 +161,7 @@ 1, maxNewHeight); qCDebug(kpLogDialogs) << "\tnewWidth=" << newWidth - << " newHeight=" << newHeight - << endl; + << " newHeight=" << newHeight; QImage transformedPixmap = diff --git a/document/kpDocument.cpp b/document/kpDocument.cpp --- a/document/kpDocument.cpp +++ b/document/kpDocument.cpp @@ -148,11 +148,13 @@ // public bool kpDocument::isFromURL (bool checkURLStillExists) const { - if (!m_isFromURL) + if (!m_isFromURL) { return false; + } - if (!checkURLStillExists) + if (!checkURLStillExists) { return true; + } return (!m_url.isEmpty () && KIO::NetAccess::exists (m_url, KIO::NetAccess::SourceSide/*open*/, @@ -215,13 +217,15 @@ void kpDocument::setModified (bool yes) { - if (yes == m_modified) + if (yes == m_modified) { return; + } m_modified = yes; - if (yes) + if (yes) { emit documentModified (); + } } //--------------------------------------------------------------------- @@ -249,10 +253,7 @@ int kpDocument::width (bool ofSelection) const { - if (ofSelection && m_selection) - return m_selection->width (); - else - return m_image->width (); + return (ofSelection && m_selection) ? m_selection->width() : m_image->width(); } //--------------------------------------------------------------------- @@ -279,11 +280,8 @@ //--------------------------------------------------------------------- int kpDocument::height (bool ofSelection) const -{ - if (ofSelection && m_selection) - return m_selection->height (); - else - return m_image->height (); +{ + return (ofSelection && m_selection) ? m_selection->height() : m_image->height(); } //--------------------------------------------------------------------- @@ -303,11 +301,8 @@ //--------------------------------------------------------------------- QRect kpDocument::rect (bool ofSelection) const -{ - if (ofSelection && m_selection) - return m_selection->boundingRect (); - else - return m_image->rect (); +{ + return (ofSelection && m_selection) ? m_selection->boundingRect() : m_image->rect(); } //--------------------------------------------------------------------- @@ -327,8 +322,7 @@ << image.width () << ",h=" << image.height () << "), x=" << at.x () - << ",y=" << at.y () - << endl; + << ",y=" << at.y (); kpPixmapFX::setPixmapAt (m_image, at, image); slotContentsChanged (QRect (at.x (), at.y (), image.width (), image.height ())); @@ -348,8 +342,9 @@ ret = imageSel->baseImage (); } - else + else { ret = *m_image; + } return ret; } @@ -372,10 +367,12 @@ *m_image = image; - if (m_oldWidth == width () && m_oldHeight == height ()) + if (m_oldWidth == width () && m_oldHeight == height ()) { slotContentsChanged (image.rect ()); - else + } + else { slotSizeChanged (QSize (width (), height ())); + } } //--------------------------------------------------------------------- @@ -392,8 +389,9 @@ imageSel->setBaseImage (image); } - else + else { setImage (image); + } } //--------------------------------------------------------------------- @@ -416,11 +414,11 @@ m_oldHeight = height (); qCDebug(kpLogDocument) << "\toldWidth=" << m_oldWidth - << " oldHeight=" << m_oldHeight - << endl; + << " oldHeight=" << m_oldHeight; - if (w == m_oldWidth && h == m_oldHeight) + if (w == m_oldWidth && h == m_oldHeight) { return; + } kpPixmapFX::resize (m_image, w, h, backgroundColor); diff --git a/document/kpDocumentSaveOptions.cpp b/document/kpDocumentSaveOptions.cpp --- a/document/kpDocumentSaveOptions.cpp +++ b/document/kpDocumentSaveOptions.cpp @@ -47,9 +47,9 @@ { public: QString m_mimeType; - int m_colorDepth; - bool m_dither; - int m_quality; + int m_colorDepth{}; + bool m_dither{}; + int m_quality{}; }; //--------------------------------------------------------------------- @@ -140,8 +140,7 @@ << "mimeType=" << mimeType () << " colorDepth=" << colorDepth () << " dither=" << dither () - << " quality=" << quality () - << endl; + << " quality=" << quality (); } //--------------------------------------------------------------------- @@ -335,10 +334,8 @@ int kpDocumentSaveOptions::defaultQuality (const KConfigGroup &config) { int val = config.readEntry (kpSettingForcedQuality, -1); - if (qualityIsInvalid (val)) - val = -1; - return val; + return qualityIsInvalid (val) ? -1 : val; } //--------------------------------------------------------------------- @@ -436,7 +433,7 @@ static bool mimeTypeSupportsProperty (const QString &mimeType, const QString &property, const QStringList &defaultMimeTypesWithPropertyList) { - const QStringList mimeTypeList = mimeTypesSupportingProperty ( + const auto mimeTypeList = mimeTypesSupportingProperty ( property, defaultMimeTypesWithPropertyList); return mimeTypeList.contains (mimeType); @@ -505,17 +502,15 @@ defaultList << QLatin1String ("image/x-xbitmap:1"); - const QStringList mimeTypeList = mimeTypesSupportingProperty ( + const auto mimeTypeList = mimeTypesSupportingProperty ( kpSettingMimeTypeMaximumColorDepth, defaultList); const QString mimeTypeColon = mimeType + QLatin1String (":"); - for (QStringList::const_iterator it = mimeTypeList.begin (); - it != mimeTypeList.end (); - ++it) + for (const auto & it : mimeTypeList) { - if ((*it).startsWith (mimeTypeColon)) + if (it.startsWith (mimeTypeColon)) { - int number = (*it).mid (mimeTypeColon.length ()).toInt (); + int number = it.mid (mimeTypeColon.length ()).toInt (); if (!colorDepthIsInvalid (number)) { return number; @@ -596,7 +591,7 @@ // public int kpDocumentSaveOptions::isLossyForSaving (const QImage &image) const { - int ret = 0; + auto ret = 0; if (mimeTypeMaximumColorDepth () < image.depth ()) { diff --git a/document/kpDocument_Open.cpp b/document/kpDocument_Open.cpp --- a/document/kpDocument_Open.cpp +++ b/document/kpDocument_Open.cpp @@ -68,8 +68,9 @@ metaInfo.setOffset(image.offset()); QStringList keys = image.textKeys(); - for (int i = 0; i < keys.count(); i++) - metaInfo.setText(keys[i], image.text(keys[i])); + for (int i = 0; i < keys.count(); i++) { + metaInfo.setText(keys[i], image.text(keys[i])); + } } //--------------------------------------------------------------------- @@ -82,11 +83,13 @@ { qCDebug(kpLogDocument) << "kpDocument::getPixmapFromFile(" << url << "," << parent << ")"; - if (saveOptions) + if (saveOptions) { *saveOptions = kpDocumentSaveOptions (); + } - if (metaInfo) + if (metaInfo) { *metaInfo = kpDocumentMetaInfo (); + } QString tempFile; if (url.isEmpty () || !KIO::NetAccess::download (url, tempFile, parent)) @@ -108,8 +111,9 @@ QMimeDatabase db; QMimeType mimeType = db.mimeTypeForFile(tempFile); - if (saveOptions) + if (saveOptions) { saveOptions->setMimeType(mimeType.name()); + } qCDebug(kpLogDocument) << "\ttempFile=" << tempFile; qCDebug(kpLogDocument) << "\tmimetype=" << mimeType.name(); @@ -133,16 +137,17 @@ } qCDebug(kpLogDocument) << "\tpixmap: depth=" << image.depth () - << " hasAlphaChannel=" << image.hasAlphaChannel () - << endl; + << " hasAlphaChannel=" << image.hasAlphaChannel (); - if ( saveOptions && metaInfo ) - getDataFromImage(image, *saveOptions, *metaInfo); + if ( saveOptions && metaInfo ) { + getDataFromImage(image, *saveOptions, *metaInfo); + } // make sure we always have Format_ARGB32_Premultiplied as this is the fastest to draw on // and Qt can not draw onto Format_Indexed8 (Qt-4.7) - if ( image.format() != QImage::Format_ARGB32_Premultiplied ) + if ( image.format() != QImage::Format_ARGB32_Premultiplied ) { image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); + } return image; } @@ -220,10 +225,9 @@ return true; } - else - { - return false; - } + + return false; + } //--------------------------------------------------------------------- diff --git a/document/kpDocument_Save.cpp b/document/kpDocument_Save.cpp --- a/document/kpDocument_Save.cpp +++ b/document/kpDocument_Save.cpp @@ -73,8 +73,7 @@ << "overwritePrompt=" << overwritePrompt << ",lossyPrompt=" << lossyPrompt << ") url=" << m_url - << " savedAtLeastOnceBefore=" << savedAtLeastOnceBefore () - << endl; + << " savedAtLeastOnceBefore=" << savedAtLeastOnceBefore (); // TODO: check feels weak if (m_url.isEmpty () || m_saveOptions->mimeType ().isEmpty ()) @@ -168,25 +167,27 @@ QWidget *parent, bool *userCancelled) { - if (userCancelled) + if (userCancelled) { *userCancelled = false; + } QStringList types = KImageIO::typeForMime (saveOptions.mimeType ()); qCDebug(kpLogDocument) << "\ttypes=" << types; - if (types.isEmpty ()) + if (types.isEmpty ()) { return false; - + } // It's safe to arbitrarily choose the 0th type as any type in the list // should invoke the same KImageIO image loader. const QString type = types [0]; qCDebug(kpLogDocument) << "\tmimeType=" << saveOptions.mimeType () - << " type=" << type << endl; + << " type=" << type; if (lossyPrompt && !lossyPromptContinue (image, saveOptions, parent)) { - if (userCancelled) + if (userCancelled) { *userCancelled = true; + } qCDebug(kpLogDocument) << "\treturning false because of lossyPrompt"; return false; @@ -251,8 +252,9 @@ int quality = -1; // default - if (useSaveOptionsQuality) + if (useSaveOptionsQuality) { quality = saveOptions.quality (); + } qCDebug(kpLogDocument) << "\tsaving"; if (!imageToSave.save (device, type.toLatin1 (), quality)) @@ -300,7 +302,7 @@ << url << ",overwritePrompt=" << overwritePrompt << ",lossyPrompt=" << lossyPrompt - << ")" << endl; + << ")"; saveOptions.printDebug (QLatin1String ("\tsaveOptions")); metaInfo.printDebug (QLatin1String ("\tmetaInfo")); @@ -457,10 +459,8 @@ emit documentSaved (); return true; } - else - { - return false; - } + + return false; } //--------------------------------------------------------------------- diff --git a/document/kpDocument_Selection.cpp b/document/kpDocument_Selection.cpp --- a/document/kpDocument_Selection.cpp +++ b/document/kpDocument_Selection.cpp @@ -76,13 +76,12 @@ void kpDocument::setSelection (const kpAbstractSelection &selection) { qCDebug(kpLogDocument) << "kpDocument::setSelection() sel boundingRect=" - << selection.boundingRect () - << endl; + << selection.boundingRect (); d->environ->setQueueViewUpdates (); { const bool hadSelection = static_cast (m_selection); - kpAbstractSelection *oldSelection = m_selection; + auto *oldSelection = m_selection; // (must be called before giving the document a new selection, to @@ -118,30 +117,35 @@ // qCDebug(kpLogDocument) << "\tcheck sel " << (int *) m_selection - << " boundingRect=" << m_selection->boundingRect () - << endl; + << " boundingRect=" << m_selection->boundingRect (); if (oldSelection) { - if (oldSelection->hasContent ()) + if (oldSelection->hasContent ()) { slotContentsChanged (oldSelection->boundingRect ()); - else + } + else { emit contentsChanged (oldSelection->boundingRect ()); + } delete oldSelection; oldSelection = nullptr; } - if (m_selection->hasContent ()) + if (m_selection->hasContent ()) { slotContentsChanged (m_selection->boundingRect ()); - else + } + else { emit contentsChanged (m_selection->boundingRect ()); + } - if (!hadSelection) + if (!hadSelection) { emit selectionEnabled (true); + } - if (isTextChanged) + if (isTextChanged) { emit selectionIsTextChanged (textSelection ()); + } } d->environ->restoreQueueViewUpdates (); @@ -153,16 +157,17 @@ // public kpImage kpDocument::getSelectedBaseImage () const { - kpAbstractImageSelection *imageSel = imageSelection (); + auto *imageSel = imageSelection (); Q_ASSERT (imageSel); // Easy if we already have it :) - const kpImage image = imageSel->baseImage (); - if (!image.isNull ()) + const auto image = imageSel->baseImage (); + if (!image.isNull ()) { return image; + } - const QRect boundingRect = imageSel->boundingRect (); + const auto boundingRect = imageSel->boundingRect (); Q_ASSERT (boundingRect.isValid ()); // OPT: This is very slow. Image / More Effects ... calls us twice @@ -175,20 +180,20 @@ // public void kpDocument::imageSelectionPullFromDocument (const kpColor &backgroundColor) { - kpAbstractImageSelection *imageSel = imageSelection (); + auto *imageSel = imageSelection (); Q_ASSERT (imageSel); // Should not already have an image or we would not be pulling. Q_ASSERT (!imageSel->hasContent ()); - const QRect boundingRect = imageSel->boundingRect (); + const auto boundingRect = imageSel->boundingRect (); Q_ASSERT (boundingRect.isValid ()); // // Get selection image from document // - kpImage selectedImage = getSelectedBaseImage (); + auto selectedImage = getSelectedBaseImage (); d->environ->setQueueViewUpdates (); @@ -236,25 +241,28 @@ // public void kpDocument::selectionDelete () { - if ( !m_selection ) - return; + if ( !m_selection ) { + return; + } - const QRect boundingRect = m_selection->boundingRect (); + const auto boundingRect = m_selection->boundingRect (); Q_ASSERT (boundingRect.isValid ()); - const bool selectionHadContent = m_selection->hasContent (); + const auto selectionHadContent = m_selection->hasContent (); delete m_selection; m_selection = nullptr; // HACK to prevent document from being modified when // user cancels dragging out a new selection // REFACTOR: Extract this out into a method. - if (selectionHadContent) + if (selectionHadContent) { slotContentsChanged (boundingRect); - else + } + else { emit contentsChanged (boundingRect); + } emit selectionEnabled (false); } @@ -265,18 +273,21 @@ void kpDocument::selectionCopyOntoDocument (bool applySelTransparency) { // Empty selection, just doing nothing - if ( !m_selection || !m_selection->hasContent() ) - return; + if ( !m_selection || !m_selection->hasContent() ) { + return; + } const QRect boundingRect = m_selection->boundingRect (); Q_ASSERT (boundingRect.isValid ()); if (imageSelection ()) { - if (applySelTransparency) + if (applySelTransparency) { imageSelection ()->paint (m_image, rect ()); - else + } + else { imageSelection ()->paintWithBaseImage (m_image, rect ()); + } } else { @@ -310,18 +321,16 @@ if (m_selection) { qCDebug(kpLogDocument) << "\tselection @ " << m_selection->boundingRect (); - kpImage output = *m_image; + auto output = *m_image; // (this is a NOP for image selections without content) m_selection->paint (&output, rect ()); return output; } - else - { - qCDebug(kpLogDocument) << "\tno selection"; - return *m_image; - } + + qCDebug(kpLogDocument) << "\tno selection"; + return *m_image; } //--------------------------------------------------------------------- diff --git a/environments/document/kpDocumentEnvironment.cpp b/environments/document/kpDocumentEnvironment.cpp --- a/environments/document/kpDocumentEnvironment.cpp +++ b/environments/document/kpDocumentEnvironment.cpp @@ -91,13 +91,12 @@ qCDebug(kpLogEnvironments) << "kpDocumentEnvironment::switchToCompatibleTool(" << &selection << ")" << " mainwindow.tool=" - << (mainWindow ()->tool () ? mainWindow ()->tool ()->objectName () : 0) + << (mainWindow ()->tool () ? mainWindow ()->tool ()->objectName () : nullptr) << " mainWindow.toolIsTextTool=" << mainWindow ()->toolIsTextTool () << " current selection=" << document ()->selection () << " new selection is text=" - << dynamic_cast (&selection) - << endl; + << dynamic_cast (&selection); *isTextChanged = (mainWindow ()->toolIsTextTool () != @@ -143,8 +142,9 @@ qCDebug(kpLogEnvironments) << "\tswitch to text selection tool"; mainWindow ()->slotToolText (); } - else + else { Q_ASSERT (!"Unknown selection type"); + } } qCDebug(kpLogEnvironments) << "kpDocumentEnvironment::switchToCompatibleTool(" << &selection << ") finished"; @@ -157,21 +157,20 @@ { // Trap and try to recover from bugs. // TODO: See kpDocument::setSelection() API comment and determine best fix. - const kpAbstractImageSelection *imageSelection = - dynamic_cast (&selection); - const kpTextSelection *textSelection = - dynamic_cast (&selection); + const auto *imageSelection = dynamic_cast (&selection); + const auto *textSelection = dynamic_cast (&selection); + if (imageSelection) { if (imageSelection->transparency () != mainWindow ()->imageSelectionTransparency ()) { qCCritical(kpLogEnvironments) << "kpDocument::setSelection() sel's transparency differs " "from mainWindow's transparency - setting mainWindow's transparency " - "to sel" - << endl; + "to sel"; + qCCritical(kpLogEnvironments) << "\tisOpaque: sel=" << imageSelection->transparency ().isOpaque () - << " mainWindow=" << mainWindow ()->imageSelectionTransparency ().isOpaque () - << endl; + << " mainWindow=" << mainWindow ()->imageSelectionTransparency ().isOpaque (); + mainWindow ()->setImageSelectionTransparency (imageSelection->transparency ()); } } @@ -181,8 +180,8 @@ { qCCritical(kpLogEnvironments) << "kpDocument::setSelection() sel's textStyle differs " "from mainWindow's textStyle - setting mainWindow's textStyle " - "to sel" - << endl; + "to sel"; + mainWindow ()->setTextStyle (textSelection->textStyle ()); } } diff --git a/environments/tools/kpToolEnvironment.cpp b/environments/tools/kpToolEnvironment.cpp --- a/environments/tools/kpToolEnvironment.cpp +++ b/environments/tools/kpToolEnvironment.cpp @@ -98,8 +98,9 @@ kpToolToolBar *tb = toolToolBar (); // (don't end up with no tool selected) - if (!tb->previousTool ()) + if (!tb->previousTool ()) { return false; + } // endInternal() will be called by kpMainWindow (thanks to this line) // so we won't have the view anymore diff --git a/generic/kpWidgetMapper.cpp b/generic/kpWidgetMapper.cpp --- a/generic/kpWidgetMapper.cpp +++ b/generic/kpWidgetMapper.cpp @@ -39,38 +39,42 @@ QPoint fromGlobal (const QWidget *widget, const QPoint &point) { - if (!widget) + if (!widget) { return point; + } return widget->mapFromGlobal (point); } QRect fromGlobal (const QWidget *widget, const QRect &rect) { - if (!widget || !rect.isValid ()) + if (!widget || !rect.isValid ()) { return rect; + } - QPoint topLeft = fromGlobal (widget, rect.topLeft ()); - return QRect (topLeft.x (), topLeft.y (), rect.width (), rect.height ()); + auto topLeft = fromGlobal (widget, rect.topLeft ()); + return {topLeft.x (), topLeft.y (), rect.width (), rect.height ()}; } QPoint toGlobal (const QWidget *widget, const QPoint &point) { - if (!widget) + if (!widget) { return point; + } return widget->mapToGlobal (point); } QRect toGlobal (const QWidget *widget, const QRect &rect) { - if (!widget || !rect.isValid ()) + if (!widget || !rect.isValid ()) { return rect; + } - QPoint topLeft = toGlobal (widget, rect.topLeft ()); - return QRect (topLeft.x (), topLeft.y (), rect.width (), rect.height ()); + auto topLeft = toGlobal (widget, rect.topLeft ()); + return {topLeft.x (), topLeft.y (), rect.width (), rect.height ()}; } -} // namespace kpWidgetMapper { +} // namespace kpWidgetMapper diff --git a/generic/widgets/kpResizeSignallingLabel.cpp b/generic/widgets/kpResizeSignallingLabel.cpp --- a/generic/widgets/kpResizeSignallingLabel.cpp +++ b/generic/widgets/kpResizeSignallingLabel.cpp @@ -44,16 +44,14 @@ { } -kpResizeSignallingLabel::~kpResizeSignallingLabel () -{ -} +kpResizeSignallingLabel::~kpResizeSignallingLabel () = default; // protected virtual [base QLabel] void kpResizeSignallingLabel::resizeEvent (QResizeEvent *e) { qCDebug(kpLogMisc) << "kpResizeSignallingLabel::resizeEvent() newSize=" << e->size () - << " oldSize=" << e->oldSize () << endl; + << " oldSize=" << e->oldSize (); QLabel::resizeEvent (e); emit resized (); diff --git a/imagelib/effects/blitz.cpp b/imagelib/effects/blitz.cpp --- a/imagelib/effects/blitz.cpp +++ b/imagelib/effects/blitz.cpp @@ -124,8 +124,9 @@ bool equalize(QImage &img) { - if(img.isNull()) + if(img.isNull()) { return(false); + } HistogramListItem *histogram; IntegerPixel *map; @@ -182,15 +183,18 @@ high = map[255]; memset(equalize_map, 0, 256*sizeof(CharPixel)); for(i=0; i < 256; ++i){ - if(high.red != low.red) + if(high.red != low.red) { equalize_map[i].red = static_cast - ((255*(map[i].red-low.red))/(high.red-low.red)); - if(high.green != low.green) + ((255*(map[i].red-low.red))/(high.red-low.red)); + } + if(high.green != low.green) { equalize_map[i].green = static_cast - ((255*(map[i].green-low.green))/(high.green-low.green)); - if(high.blue != low.blue) + ((255*(map[i].green-low.green))/(high.green-low.green)); + } + if(high.blue != low.blue) { equalize_map[i].blue = static_cast - ((255*(map[i].blue-low.blue))/(high.blue-low.blue)); + ((255*(map[i].blue-low.blue))/(high.blue-low.blue)); + } } // stretch the histogram and write @@ -241,14 +245,16 @@ int a, r, g, b; int *as, *rs, *gs, *bs; - if(radius < 1 || img.isNull() || img.width() < (radius << 1)) + if(radius < 1 || img.isNull() || img.width() < (radius << 1)) { return(img); + } w = img.width(); h = img.height(); - if(img.depth() < 8) + if(img.depth() < 8) { img = img.convertToFormat(QImage::Format_Indexed8); + } QImage buffer(w, h, img.hasAlphaChannel() ? QImage::Format_ARGB32 : QImage::Format_RGB32); @@ -258,18 +264,20 @@ bs = new int[w]; QVector colorTable; - if(img.format() == QImage::Format_Indexed8) + if(img.format() == QImage::Format_Indexed8) { colorTable = img.colorTable(); + } for(y = 0; y < h; y++){ my = y - radius; mh = (radius << 1) + 1; if(my < 0){ mh += my; my = 0; } - if((my + mh) > h) + if((my + mh) > h) { mh = h - my; + } p1 = (QRgb *)buffer.scanLine(y); memset(as, 0, static_cast (w) * sizeof(int)); @@ -324,8 +332,9 @@ mw += mx; mx = 0; } - if((mx + mw) > w) + if((mx + mw) > w) { mw = w - mx; + } mt = mw * mh; for(xx = mx; xx < (mw + mx); xx++){ a += as[xx]; @@ -363,14 +372,16 @@ return(5); } - if(radius > 0.0f) + if(radius > 0.0f) { return(static_cast(2.0f * std::ceil(radius) + 1.0f)); + } matrix_size = 5; do{ normalize = 0.0; - for(i=(-matrix_size/2); i <= (matrix_size/2); ++i) + for(i=(-matrix_size/2); i <= (matrix_size/2); ++i) { normalize += std::exp(-(static_cast (i*i))/sigma2) / sigmaSQ2PI; + } i = matrix_size/2; value = std::exp(-(static_cast (i*i))/sigma2) / sigmaSQ2PI / normalize; matrix_size += 2; @@ -401,8 +412,9 @@ return(img); } - if(img.format() == QImage::Format_ARGB32_Premultiplied) + if(img.format() == QImage::Format_ARGB32_Premultiplied) { img = img.convertToFormat(QImage::Format_ARGB32); + } else if(img.depth() < 32){ img = img.convertToFormat(img.hasAlphaChannel() ? QImage::Format_ARGB32 : @@ -415,10 +427,12 @@ // create normalized matrix normalize = 0.0; - for(i=0; i < matrix_size*matrix_size; ++i) + for(i=0; i < matrix_size*matrix_size; ++i) { normalize += matrix[i]; - if(std::abs(normalize) <= static_cast (M_EPSILON)) + } + if(std::abs(normalize) <= static_cast (M_EPSILON)) { normalize = 1.0f; + } normalize = 1.0f/normalize; for(i=0; i < matrix_size*matrix_size; ++i){ normalize_matrix[i] = normalize*matrix[i]; @@ -573,8 +587,9 @@ for(x=(-half); x <= half; ++x, ++i){ alpha = std::exp(-(static_cast (x*x+y*y))/sigma2); matrix[i]=((x < 0) || (y < 0) ? -8.0f : 8.0f)*alpha/sigmaPI2; - if(x == j) + if(x == j) { matrix[i]=0.0; + } } } QImage result(convolve(img, matrix_size, matrix)); @@ -587,8 +602,9 @@ QImage& Blitz::flatten(QImage &img, const QColor &ca, const QColor &cb) { - if(img.isNull()) + if(img.isNull()) { return(img); + } if(img.depth() == 1) { img.setColor(0, ca.rgb()); @@ -666,8 +682,9 @@ } } - if(img.format() == QImage::Format_Indexed8) + if(img.format() == QImage::Format_Indexed8) { img.setColorTable(cTable); + } return(img); } diff --git a/imagelib/effects/kpEffectBalance.cpp b/imagelib/effects/kpEffectBalance.cpp --- a/imagelib/effects/kpEffectBalance.cpp +++ b/imagelib/effects/kpEffectBalance.cpp @@ -38,12 +38,15 @@ static inline int between0And255 (int val) { - if (val < 0) + if (val < 0) { return 0; - else if (val > 255) + } + + if (val > 255) { return 255; - else - return val; + } + + return val; } @@ -81,12 +84,15 @@ int green = qGreen (rgb); int blue = qBlue (rgb); - if (channels & kpEffectBalance::Red) + if (channels & kpEffectBalance::Red) { red = brightnessContrastGamma (red, brightness, contrast, gamma); - if (channels & kpEffectBalance::Green) + } + if (channels & kpEffectBalance::Green) { green = brightnessContrastGamma (green, brightness, contrast, gamma); - if (channels & kpEffectBalance::Blue) + } + if (channels & kpEffectBalance::Blue) { blue = brightnessContrastGamma (blue, brightness, contrast, gamma); + } return qRgba (red, green, blue, qAlpha (rgb)); } @@ -102,7 +108,7 @@ << ",brightness=" << brightness << ",contrast=" << contrast << ",gamma=" << gamma - << ")" << endl; + << ")"; QTime timer; timer.start (); QImage qimage = image; @@ -114,22 +120,28 @@ for (int i = 0; i < 256; i++) { - quint8 applied = static_cast (brightnessContrastGamma (i, brightness, contrast, gamma)); + auto applied = static_cast (brightnessContrastGamma (i, brightness, contrast, gamma)); - if (channels & kpEffectBalance::Red) + if (channels & kpEffectBalance::Red) { transformRed [i] = applied; - else + } + else { transformRed [i] = static_cast (i); + } - if (channels & kpEffectBalance::Green) + if (channels & kpEffectBalance::Green) { transformGreen [i] = applied; - else + } + else { transformGreen [i] = static_cast (i); + } - if (channels & kpEffectBalance::Blue) + if (channels & kpEffectBalance::Blue) { transformBlue [i] = applied; - else + } + else { transformBlue [i] = static_cast (i); + } } qCDebug(kpLogImagelib) << "\tbuild lookup=" << timer.restart (); @@ -142,10 +154,10 @@ { const QRgb rgb = qimage.pixel (x, y); - const quint8 red = static_cast (qRed (rgb)); - const quint8 green = static_cast (qGreen (rgb)); - const quint8 blue = static_cast (qBlue (rgb)); - const quint8 alpha = static_cast (qAlpha (rgb)); + const auto red = static_cast (qRed (rgb)); + const auto green = static_cast (qGreen (rgb)); + const auto blue = static_cast (qBlue (rgb)); + const auto alpha = static_cast (qAlpha (rgb)); qimage.setPixel (x, y, qRgba (transformRed [red], @@ -161,10 +173,10 @@ { const QRgb rgb = qimage.color (i); - const quint8 red = static_cast (qRed (rgb)); - const quint8 green = static_cast (qGreen (rgb)); - const quint8 blue = static_cast (qBlue (rgb)); - const quint8 alpha = static_cast (qAlpha (rgb)); + const auto red = static_cast (qRed (rgb)); + const auto green = static_cast (qGreen (rgb)); + const auto blue = static_cast (qBlue (rgb)); + const auto alpha = static_cast (qAlpha (rgb)); qimage.setColor (i, qRgba (transformRed [red], diff --git a/imagelib/effects/kpEffectBlurSharpen.cpp b/imagelib/effects/kpEffectBlurSharpen.cpp --- a/imagelib/effects/kpEffectBlurSharpen.cpp +++ b/imagelib/effects/kpEffectBlurSharpen.cpp @@ -55,8 +55,9 @@ static QImage BlurQImage(const QImage &qimage, int strength) { - if (strength == 0) + if (strength == 0) { return qimage; + } // The numbers that follow were picked by experimentation to try to get // an effect linearly proportional to and at the same time, @@ -72,8 +73,7 @@ (kpEffectBlurSharpen::MaxStrength - 1); qCDebug(kpLogImagelib) << "kpEffectBlurSharpen.cpp:BlurQImage(strength=" << strength << ")" - << " radius=" << radius - << endl; + << " radius=" << radius; QImage img(qimage); return Blitz::blur(img, qRound(radius)); @@ -84,8 +84,9 @@ static QImage SharpenQImage (const QImage &qimage_, int strength) { QImage qimage = qimage_; - if (strength == 0) + if (strength == 0) { return qimage; + } // The numbers that follow were picked by experimentation to try to get @@ -119,17 +120,16 @@ qCDebug(kpLogImagelib) << "kpEffectBlurSharpen.cpp:SharpenQImage(strength=" << strength << ")" << " radius=" << radius << " sigma=" << sigma - << " repeat=" << repeat - << endl; + << " repeat=" << repeat; for (int i = 0; i < repeat; i++) { QTime timer; timer.start (); qimage = Blitz::gaussianSharpen (qimage, static_cast (radius), static_cast (sigma)); qCDebug(kpLogImagelib) << "\titeration #" + QString::number (i) - << ": " + QString::number (timer.elapsed ()) << "ms" << endl; + << ": " + QString::number (timer.elapsed ()) << "ms"; } @@ -145,19 +145,22 @@ qCDebug(kpLogImagelib) << "kpEffectBlurSharpen::applyEffect(image.rect=" << image.rect () << ",type=" << int (type) << ",strength=" << strength - << ")" << endl; + << ")"; Q_ASSERT (strength >= MinStrength && strength <= MaxStrength); - if (type == Blur) + if (type == Blur) { return ::BlurQImage (image, strength); - else if (type == Sharpen) + } + + if (type == Sharpen) { return ::SharpenQImage (image, strength); - else if (type == MakeConfidential) - { + } + + if (type == MakeConfidential) { QImage img(image); return Blitz::blur(img, qMin(20, img.width() / 2)); } - else - return kpImage(); + + return kpImage(); } diff --git a/imagelib/effects/kpEffectEmboss.cpp b/imagelib/effects/kpEffectEmboss.cpp --- a/imagelib/effects/kpEffectEmboss.cpp +++ b/imagelib/effects/kpEffectEmboss.cpp @@ -39,21 +39,22 @@ static QImage EmbossQImage (const QImage &qimage_, int strength) { QImage qimage = qimage_; - if (strength == 0) + if (strength == 0) { return qimage; + } // The numbers that follow were picked by experimentation to try to get // an effect linearly proportional to and at the same time, // be fast enough. // // I still have no idea what "radius" and "sigma" mean. - const double radius = 0; + const auto radius = 0.0; - const double sigma = 1; + const auto sigma = 1.0; - const int repeat = 1; + const auto repeat = 1; for (int i = 0; i < repeat; i++) diff --git a/imagelib/effects/kpEffectFlatten.cpp b/imagelib/effects/kpEffectFlatten.cpp --- a/imagelib/effects/kpEffectFlatten.cpp +++ b/imagelib/effects/kpEffectFlatten.cpp @@ -33,8 +33,9 @@ void kpEffectFlatten::applyEffect (QImage *destImagePtr, const QColor &color1, const QColor &color2) { - if (!destImagePtr) + if (!destImagePtr) { return; + } Blitz::flatten (*destImagePtr/*ref*/, color1, color2); } diff --git a/imagelib/effects/kpEffectGrayscale.cpp b/imagelib/effects/kpEffectGrayscale.cpp --- a/imagelib/effects/kpEffectGrayscale.cpp +++ b/imagelib/effects/kpEffectGrayscale.cpp @@ -66,8 +66,9 @@ else { // 1- & 8- bit images use a color table - for (int i = 0; i < qimage.colorCount (); i++) + for (int i = 0; i < qimage.colorCount (); i++) { qimage.setColor (i, toGray (qimage.color (i))); + } } return qimage; diff --git a/imagelib/effects/kpEffectHSV.cpp b/imagelib/effects/kpEffectHSV.cpp --- a/imagelib/effects/kpEffectHSV.cpp +++ b/imagelib/effects/kpEffectHSV.cpp @@ -44,7 +44,7 @@ int r = qRed(c); int g = qGreen(c); int b = qBlue(c); - int min; + int min{}; if(b >= g && b >= r) { // Blue @@ -84,8 +84,9 @@ if(r != min) { *pHue = static_cast (g - b) / ((r - min) * 6); - if(*pHue < 0) + if(*pHue < 0) { (*pHue) += 1.0f; + } *pSaturation = 1.0f - static_cast (min) / static_cast (r); } else diff --git a/imagelib/effects/kpEffectInvert.cpp b/imagelib/effects/kpEffectInvert.cpp --- a/imagelib/effects/kpEffectInvert.cpp +++ b/imagelib/effects/kpEffectInvert.cpp @@ -47,8 +47,7 @@ (channels & Blue) ? 0xFF : 0, 0/*don't invert alpha*/); qCDebug(kpLogImagelib) << "kpEffectInvert::applyEffect(channels=" << channels - << ") mask=" << (int *) mask - << endl; + << ") mask=" << (int *) mask; if (destImagePtr->depth () > 8) { diff --git a/imagelib/effects/kpEffectReduceColors.cpp b/imagelib/effects/kpEffectReduceColors.cpp --- a/imagelib/effects/kpEffectReduceColors.cpp +++ b/imagelib/effects/kpEffectReduceColors.cpp @@ -74,11 +74,13 @@ << " to " << depth << " (dither=" << dither << ")"; - if (image.isNull ()) + if (image.isNull ()) { return image; + } - if (depth == image.depth ()) + if (depth == image.depth ()) { return image; + } for (int y = 0; y < image.height (); y++) @@ -111,40 +113,40 @@ monoImage.setColorCount (2); qCDebug(kpLogImagelib) << "\t\tinitialising output image w=" << monoImage.width () << ",h=" << monoImage.height () - << ",d=" << monoImage.depth () - << endl; + << ",d=" << monoImage.depth (); for (int y = 0; y < image.height (); y++) { for (int x = 0; x < image.width (); x++) { // (this can be transparent) QRgb imagePixel = image.pixel (x, y); - if (color0Valid && imagePixel == color0) + if (color0Valid && imagePixel == color0) { monoImage.setPixel (x, y, 0); - else if (color1Valid && imagePixel == color1) + } + else if (color1Valid && imagePixel == color1) { monoImage.setPixel (x, y, 1); - else if (!color0Valid) - { + } + else if (!color0Valid) { color0 = imagePixel; color0Valid = true; monoImage.setPixel (x, y, 0); qCDebug(kpLogImagelib) << "\t\t\tcolor0=" << (int *) color0 - << " at x=" << x << ",y=" << y << endl; + << " at x=" << x << ",y=" << y; } else if (!color1Valid) { color1 = imagePixel; color1Valid = true; monoImage.setPixel (x, y, 1); qCDebug(kpLogImagelib) << "\t\t\tcolor1=" << (int *) color1 - << " at x=" << x << ",y=" << y << endl; + << " at x=" << x << ",y=" << y; } else { qCDebug(kpLogImagelib) << "\t\t\timagePixel=" << (int *) imagePixel << " at x=" << x << ",y=" << y - << " moreThan2Colors - abort hack" << endl; + << " moreThan2Colors - abort hack"; moreThan2Colors = true; // Dijkstra, this is clearer than double break'ing or @@ -189,12 +191,14 @@ // public static void kpEffectReduceColors::applyEffect (QImage *destPtr, int depth, bool dither) { - if (!destPtr) + if (!destPtr) { return; + } // You can't "reduce" to 32-bit since it's the highest depth. - if (depth != 1 && depth != 8) + if (depth != 1 && depth != 8) { return; + } *destPtr = convertImageDepth(*destPtr, depth, dither); diff --git a/imagelib/effects/kpEffectToneEnhance.cpp b/imagelib/effects/kpEffectToneEnhance.cpp --- a/imagelib/effects/kpEffectToneEnhance.cpp +++ b/imagelib/effects/kpEffectToneEnhance.cpp @@ -119,8 +119,9 @@ void kpEffectToneEnhanceApplier::DeleteToneMaps() { int nToneMaps = m_nToneMapGranularity * m_nToneMapGranularity; - for(int i = 0; i < nToneMaps; i++) - delete[] m_pToneMaps[i]; + for(int i = 0; i < nToneMaps; i++) { + delete[] m_pToneMaps[i]; + } delete[] m_pToneMaps; m_pToneMaps = nullptr; m_nToneMapGranularity = 0; @@ -131,26 +132,32 @@ // protected unsigned int* kpEffectToneEnhanceApplier::MakeToneMap(QImage* pImage, int u, int v, int nGranularity) { - // Compute the region to make the tone map for - int xx, yy; - if(nGranularity > 1) - { - xx = u * (pImage->width() - 1) / (nGranularity - 1) - m_areaWid / 2; - if(xx < 0) - xx = 0; - else if(xx + m_areaWid > pImage->width()) - xx = pImage->width() - m_areaWid; - yy = v * (pImage->width() - 1) / (nGranularity - 1) - m_areaHgt / 2; - if(yy < 0) - yy = 0; - else if(yy + m_areaHgt > pImage->height()) - yy = pImage->height() - m_areaHgt; - } - else - { - xx = 0; - yy = 0; - } + // Compute the region to make the tone map for + int xx, yy; + if(nGranularity > 1) + { + xx = u * (pImage->width() - 1) / (nGranularity - 1) - m_areaWid / 2; + if(xx < 0) { + xx = 0; + } + else if(xx + m_areaWid > pImage->width()) { + xx = pImage->width() - m_areaWid; + } + + yy = v * (pImage->width() - 1) / (nGranularity - 1) - m_areaHgt / 2; + + if(yy < 0) { + yy = 0; + } + else if(yy + m_areaHgt > pImage->height()) { + yy = pImage->height() - m_areaHgt; + } + } + else + { + xx = 0; + yy = 0; + } // Make a tone histogram for the region memset(m_pHistogram, '\0', sizeof(unsigned int) * TONE_MAP_SIZE); @@ -166,15 +173,17 @@ } // Forward sum the tone histogram - int i; - for(i = 1; i < TONE_MAP_SIZE; i++) - m_pHistogram[i] += m_pHistogram[i - 1]; + int i{}; + for(i = 1; i < TONE_MAP_SIZE; i++) { + m_pHistogram[i] += m_pHistogram[i - 1]; + } // Compute the forward contribution to the tone map - unsigned int total = m_pHistogram[i - 1]; - unsigned int* pToneMap = new unsigned int[TONE_MAP_SIZE]; - for(i = 0; i < TONE_MAP_SIZE; i++) - pToneMap[i] = static_cast (static_cast (m_pHistogram[i] * MAX_TONE_VALUE / total)); + auto total = m_pHistogram[i - 1]; + auto *pToneMap = new unsigned int[TONE_MAP_SIZE]; + for(i = 0; i < TONE_MAP_SIZE; i++) { + pToneMap[i] = static_cast (static_cast (m_pHistogram[i] * MAX_TONE_VALUE / total)); + } /* // Undo the forward sum and reverse sum the tone histogram m_pHistogram[TONE_MAP_SIZE - 1] -= m_pHistogram[TONE_MAP_SIZE - 2]; @@ -206,8 +215,9 @@ int u, v; for(v = 0; v < nGranularity; v++) { - for(u = 0; u < nGranularity; u++) - m_pToneMaps[nGranularity * v + u] = MakeToneMap(pImage, u, v, nGranularity); + for(u = 0; u < nGranularity; u++) { + m_pToneMaps[nGranularity * v + u] = MakeToneMap(pImage, u, v, nGranularity); + } } } @@ -217,26 +227,29 @@ unsigned int kpEffectToneEnhanceApplier::InterpolateNewTone(QImage* pImage, unsigned int oldTone, int x, int y, int nGranularity) { oldTone = (oldTone >> TONE_DROP_BITS); - if(m_nToneMapGranularity <= 1) - return m_pToneMaps[0][oldTone]; - int u = x * (nGranularity - 1) / pImage->width(); - int v = y * (nGranularity - 1) / pImage->height(); - unsigned int x1y1 = m_pToneMaps[m_nToneMapGranularity * v + u][oldTone]; - unsigned int x2y1 = m_pToneMaps[m_nToneMapGranularity * v + u + 1][oldTone]; - unsigned int x1y2 = m_pToneMaps[m_nToneMapGranularity * (v + 1) + u][oldTone]; - unsigned int x2y2 = m_pToneMaps[m_nToneMapGranularity * (v + 1) + u + 1][oldTone]; - int hFac = x - (u * (pImage->width() - 1) / (nGranularity - 1)); - if(hFac > m_areaWid) - hFac = m_areaWid; + if(m_nToneMapGranularity <= 1) { + return m_pToneMaps[0][oldTone]; + } + auto u = x * (nGranularity - 1) / pImage->width(); + auto v = y * (nGranularity - 1) / pImage->height(); + auto x1y1 = m_pToneMaps[m_nToneMapGranularity * v + u][oldTone]; + auto x2y1 = m_pToneMaps[m_nToneMapGranularity * v + u + 1][oldTone]; + auto x1y2 = m_pToneMaps[m_nToneMapGranularity * (v + 1) + u][oldTone]; + auto x2y2 = m_pToneMaps[m_nToneMapGranularity * (v + 1) + u + 1][oldTone]; + auto hFac = x - (u * (pImage->width() - 1) / (nGranularity - 1)); + if(hFac > m_areaWid) { + hFac = m_areaWid; + } unsigned int y1 = (x1y1 * (static_cast (m_areaWid) - static_cast (hFac)) + x2y1 * static_cast (hFac)) / static_cast (m_areaWid); unsigned int y2 = (x1y2 * (static_cast (m_areaWid) - static_cast (hFac)) + x2y2 * static_cast (hFac)) / static_cast (m_areaWid); int vFac = y - (v * (pImage->height() - 1) / (nGranularity - 1)); - if(vFac > m_areaHgt) - vFac = m_areaHgt; + if(vFac > m_areaHgt) { + vFac = m_areaHgt; + } return (y1 * (static_cast (m_areaHgt) - static_cast (vFac)) + y2 * static_cast (vFac)) / static_cast (m_areaHgt); } @@ -246,15 +259,18 @@ // public void kpEffectToneEnhanceApplier::BalanceImageTone(QImage* pImage, double granularity, double amount) { - if(pImage->width() < MIN_IMAGE_DIM || pImage->height() < MIN_IMAGE_DIM) - return; // the image is not big enough to perform this operation + if(pImage->width() < MIN_IMAGE_DIM || pImage->height() < MIN_IMAGE_DIM) { + return; // the image is not big enough to perform this operation + } int nGranularity = static_cast (granularity * (MAX_GRANULARITY - 2)) + 1; m_areaWid = pImage->width() / nGranularity; - if(m_areaWid < MIN_IMAGE_DIM) + if(m_areaWid < MIN_IMAGE_DIM) { m_areaWid = MIN_IMAGE_DIM; + } m_areaHgt = pImage->height() / nGranularity; - if(m_areaHgt < MIN_IMAGE_DIM) + if(m_areaHgt < MIN_IMAGE_DIM) { m_areaHgt = MIN_IMAGE_DIM; + } ComputeToneMaps(pImage, nGranularity); int x, y; unsigned int oldTone, newTone, col; @@ -276,8 +292,9 @@ kpImage kpEffectToneEnhance::applyEffect (const kpImage &image, double granularity, double amount) { - if (amount == 0.0) + if (amount == 0.0) { return image; + } QImage qimage(image); diff --git a/imagelib/kpColor.cpp b/imagelib/kpColor.cpp --- a/imagelib/kpColor.cpp +++ b/imagelib/kpColor.cpp @@ -50,16 +50,16 @@ : m_rgba(0), m_colorCacheIsValid(false) { qCDebug(kpLogImagelib) << "kpColor::(r=" << red << ",g=" << green << ",b=" << blue - << ",isTrans=" << isTransparent << ")" << endl; + << ",isTrans=" << isTransparent << ")"; if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) { qCCritical(kpLogImagelib) << "kpColor::(r=" << red << ",g=" << green << ",b=" << blue << ",t=" << isTransparent - << ") passed out of range values" << endl; + << ") passed out of range values"; m_rgbaIsValid = false; return; } @@ -121,8 +121,9 @@ // (as soon as you add a ptr, you won't be complaining to me that this // method was unnecessary :)) - if (this == &rhs) + if (this == &rhs) { return *this; + } m_rgbaIsValid = rhs.m_rgbaIsValid; m_rgba = rhs.m_rgba; @@ -167,32 +168,37 @@ bool kpColor::isSimilarTo (const kpColor &rhs, int processedSimilarity) const { // Are we the same? - if (this == &rhs) + if (this == &rhs) { return true; + } // Do we dither in terms of validity? - if (isValid () != rhs.isValid ()) + if (isValid () != rhs.isValid ()) { return false; + } // Are both of us invalid? - if (!isValid ()) + if (!isValid ()) { return true; + } // --- both are now valid --- - if (m_rgba == rhs.m_rgba) + if (m_rgba == rhs.m_rgba) { return true; + } - if (processedSimilarity == kpColor::Exact) + if (processedSimilarity == kpColor::Exact) { return false; - else - { - return (square (qRed (m_rgba) - qRed (rhs.m_rgba)) + - square (qGreen (m_rgba) - qGreen (rhs.m_rgba)) + - square (qBlue (m_rgba) - qBlue (rhs.m_rgba)) - <= processedSimilarity); } + + + return (square (qRed (m_rgba) - qRed (rhs.m_rgba)) + + square (qGreen (m_rgba) - qGreen (rhs.m_rgba)) + + square (qBlue (m_rgba) - qBlue (rhs.m_rgba)) + <= processedSimilarity); + } //--------------------------------------------------------------------- @@ -210,7 +216,7 @@ { if (!m_rgbaIsValid) { - qCCritical(kpLogImagelib) << "kpColor::red() called with invalid kpColor" << endl; + qCCritical(kpLogImagelib) << "kpColor::red() called with invalid kpColor"; return 0; } @@ -224,7 +230,7 @@ { if (!m_rgbaIsValid) { - qCCritical(kpLogImagelib) << "kpColor::green() called with invalid kpColor" << endl; + qCCritical(kpLogImagelib) << "kpColor::green() called with invalid kpColor"; return 0; } @@ -238,7 +244,7 @@ { if (!m_rgbaIsValid) { - qCCritical(kpLogImagelib) << "kpColor::blue() called with invalid kpColor" << endl; + qCCritical(kpLogImagelib) << "kpColor::blue() called with invalid kpColor"; return 0; } @@ -252,7 +258,7 @@ { if (!m_rgbaIsValid) { - qCCritical(kpLogImagelib) << "kpColor::alpha() called with invalid kpColor" << endl; + qCCritical(kpLogImagelib) << "kpColor::alpha() called with invalid kpColor"; return 0; } @@ -274,7 +280,7 @@ { if (!m_rgbaIsValid) { - qCCritical(kpLogImagelib) << "kpColor::toQRgb() called with invalid kpColor" << endl; + qCCritical(kpLogImagelib) << "kpColor::toQRgb() called with invalid kpColor"; return 0; } @@ -288,12 +294,13 @@ { if (!m_rgbaIsValid) { - qCCritical(kpLogImagelib) << "kpColor::toQColor() called with invalid kpColor" << endl; + qCCritical(kpLogImagelib) << "kpColor::toQColor() called with invalid kpColor"; return Qt::black; } - if (m_colorCacheIsValid) + if (m_colorCacheIsValid) { return m_colorCache; + } m_colorCache = QColor(qRed(m_rgba), qGreen(m_rgba), qBlue(m_rgba), qAlpha(m_rgba)); m_colorCacheIsValid = true; diff --git a/imagelib/kpDocumentMetaInfo.cpp b/imagelib/kpDocumentMetaInfo.cpp --- a/imagelib/kpDocumentMetaInfo.cpp +++ b/imagelib/kpDocumentMetaInfo.cpp @@ -60,7 +60,7 @@ struct kpDocumentMetaInfoPrivate { - int m_dotsPerMeterX, m_dotsPerMeterY; + int m_dotsPerMeterX{}, m_dotsPerMeterY{}; QPoint m_offset; QMap m_textMap; @@ -120,8 +120,9 @@ // public kpDocumentMetaInfo &kpDocumentMetaInfo::operator= (const kpDocumentMetaInfo &rhs) { - if (this == &rhs) + if (this == &rhs) { return *this; + } d->m_dotsPerMeterX = rhs.dotsPerMeterX (); d->m_dotsPerMeterY = rhs.dotsPerMeterY (); @@ -142,16 +143,15 @@ qCDebug(kpLogImagelib) << "dotsPerMeter X=" << dotsPerMeterX () << " Y=" << dotsPerMeterY () - << " offset=" << offset () << endl; + << " offset=" << offset (); QList keyList = textKeys (); for (QList ::const_iterator it = keyList.constBegin (); it != keyList.constEnd (); ++it) { qCDebug(kpLogImagelib) << "key=" << (*it) - << " text=" << text (*it) - << endl; + << " text=" << text (*it); } qCDebug(kpLogImagelib) << usedPrefix << "ENDS"; @@ -164,7 +164,7 @@ { kpCommandSize::SizeType ret = 0; - foreach (const QString &key, d->m_textMap.keys ()) + for (const auto &key : d->m_textMap.keys ()) { ret += kpCommandSize::StringSize (key) + kpCommandSize::StringSize (d->m_textMap [key]); @@ -262,8 +262,9 @@ // public QString kpDocumentMetaInfo::text (const QString &key) const { - if (key.isEmpty ()) - return QString (); + if (key.isEmpty ()) { + return {}; + } return d->m_textMap [key]; } @@ -273,8 +274,9 @@ // public void kpDocumentMetaInfo::setText (const QString &key, const QString &value) { - if (key.isEmpty ()) + if (key.isEmpty ()) { return; + } d->m_textMap [key] = value; } diff --git a/imagelib/kpFloodFill.cpp b/imagelib/kpFloodFill.cpp --- a/imagelib/kpFloodFill.cpp +++ b/imagelib/kpFloodFill.cpp @@ -78,10 +78,10 @@ // Copy of whatever was passed to the constructor. // - kpImage *imagePtr; - int x, y; + kpImage *imagePtr{}; + int x{}, y{}; kpColor color; - int processedColorSimilarity; + int processedColorSimilarity{}; // @@ -100,7 +100,7 @@ QRect boundingRect; - bool prepared; + bool prepared{}; }; //--------------------------------------------------------------------- @@ -147,7 +147,7 @@ kpCommandSize::SizeType kpFloodFill::size () const { kpCommandSize::SizeType fillLinesCacheSize = 0; - foreach (const QLinkedList &linesList, d->fillLinesCache) + for (const auto &linesList : d->fillLinesCache) { fillLinesCacheSize += ::FillLinesListSize (linesList); } @@ -162,8 +162,9 @@ // public void kpFloodFill::prepareColorToChange () { - if (d->colorToChange.isValid ()) + if (d->colorToChange.isValid ()) { return; + } qCDebug(kpLogImagelib) << "kpFloodFill::prepareColorToChange()"; @@ -187,17 +188,19 @@ // private kpColor kpFloodFill::pixelColor (int x, int y, bool *beenHere) const { - if (beenHere) + if (beenHere) { *beenHere = false; + } Q_ASSERT (y >= 0 && y < static_cast (d->fillLinesCache.count ())); - foreach (const kpFillLine &line, d->fillLinesCache [y]) + for (const auto &line : d->fillLinesCache [y]) { if (x >= line.m_x1 && x <= line.m_x2) { - if (beenHere) + if (beenHere) { *beenHere = true; + } return d->color; } } @@ -223,13 +226,16 @@ { for (;;) { - if (x < 0) + if (x < 0) { return 0; + } - if (shouldGoTo (x, y)) + if (shouldGoTo (x, y)) { x--; - else + } + else { return x + 1; + } } } @@ -240,13 +246,16 @@ { for (;;) { - if (x > d->imagePtr->width () - 1) + if (x > d->imagePtr->width () - 1) { return d->imagePtr->width () - 1; + } - if (shouldGoTo (x, y)) + if (shouldGoTo (x, y)) { x++; - else + } + else { return x - 1; + } } } @@ -270,8 +279,9 @@ void kpFloodFill::findAndAddLines (const kpFillLine &fillLine, int dy) { // out of bounds? - if (fillLine.m_y + dy < 0 || fillLine.m_y + dy >= d->imagePtr->height ()) + if (fillLine.m_y + dy < 0 || fillLine.m_y + dy >= d->imagePtr->height ()) { return; + } for (int xnow = fillLine.m_x1; xnow <= fillLine.m_x2; xnow++) { @@ -296,8 +306,9 @@ // public void kpFloodFill::prepare () { - if (d->prepared) + if (d->prepared) { return; + } qCDebug(kpLogImagelib) << "kpFloodFill::prepare()"; @@ -319,8 +330,9 @@ qCDebug(kpLogImagelib) << "\tcreating fillLinesCache"; // ready cache - for (int i = 0; i < d->imagePtr->height (); i++) + for (int i = 0; i < d->imagePtr->height (); i++) { d->fillLinesCache.append (QLinkedList ()); + } qCDebug(kpLogImagelib) << "\tcreating fill lines"; @@ -378,17 +390,20 @@ // by definition, flood fill with a fully transparent color erases the pixels // and sets them to be fully transparent - if ( d->color.isTransparent() ) + if ( d->color.isTransparent() ) { painter.setCompositionMode(QPainter::CompositionMode_Clear); + } painter.setPen(d->color.toQColor()); - foreach (const kpFillLine &l, d->fillLines) + for (const auto &l : d->fillLines) { - if ( l.m_x1 == l.m_x2 ) + if ( l.m_x1 == l.m_x2 ) { painter.drawPoint(l.m_x1, l.m_y); - else + } + else { painter.drawLine(l.m_x1, l.m_y, l.m_x2, l.m_y); + } } QApplication::restoreOverrideCursor(); diff --git a/imagelib/kpPainter.cpp b/imagelib/kpPainter.cpp --- a/imagelib/kpPainter.cpp +++ b/imagelib/kpPainter.cpp @@ -107,8 +107,9 @@ int x = 0; int y = 0; - if (SHOULD_DRAW ()) + if (SHOULD_DRAW ()) { ret.append (QPoint (plotx, ploty)); + } for (int i = 0; i <= inc; i++) @@ -126,21 +127,25 @@ plot++; x -= inc; - if (dx < 0) + if (dx < 0) { plotx--; - else + } + else { plotx++; + } } if (y > inc) { plot++; y -= inc; - if (dy < 0) + if (dy < 0) { ploty--; - else + } + else { ploty++; + } } if (plot) @@ -152,12 +157,14 @@ // is more than 1 point, of course). This is in contrast to the // ordinary line algorithm which can create diagonal adjacencies. - if (SHOULD_DRAW ()) + if (SHOULD_DRAW ()) { ret.append (QPoint (plotx, oldploty)); + } } - if (SHOULD_DRAW ()) + if (SHOULD_DRAW ()) { ret.append (QPoint (plotx, ploty)); + } } } @@ -240,19 +247,22 @@ if (kpPixmapFX::getColorAtPixel (image, QPoint (x, y)).isSimilarTo (colorToReplace, processedColorSimilarity)) { fprintf (stderr, "similar\n"); - if (startDrawX < 0) + if (startDrawX < 0) { startDrawX = x; + } } else { fprintf (stderr, "different\n"); - if (startDrawX >= 0) + if (startDrawX >= 0) { FLUSH_LINE (); + } } } - if (startDrawX >= 0) + if (startDrawX >= 0) { FLUSH_LINE (); + } } #undef FLUSH_LINE @@ -266,9 +276,9 @@ { QPoint startPoint, endPoint; kpColor color; - int penWidth, penHeight; + int penWidth{}, penHeight{}; kpColor colorToReplace; - int processedColorSimilarity; + int processedColorSimilarity{}; QRect readableImageRect; QImage readableImage; @@ -312,15 +322,16 @@ { // Set the drawing colors for the painters. - if (rgbPainter) + if (rgbPainter) { rgbPainter->setPen (pack->color.toQColor()); + } } //--------------------------------------------------------------------- static QRect WashLineHelper (QPainter *rgbPainter, void *data) { - WashPack *pack = static_cast (data); + auto *pack = static_cast (data); // Setup painters. ::WashHelperSetup (rgbPainter, pack); @@ -376,7 +387,7 @@ static QRect WashRectHelper (QPainter *rgbPainter, void *data) { - WashPack *pack = static_cast (data); + auto *pack = static_cast (data); // Setup painters. ::WashHelperSetup (rgbPainter, pack); @@ -434,7 +445,7 @@ painter.setPen(color.toQColor()); - foreach (const QPoint &p, points) + for (const auto &p : points) { for (int i = 0; i < 10; i++) { @@ -444,8 +455,9 @@ // Make it look circular. // TODO: Can be done better by doing a random vector angle & length // but would sin and cos be too slow? - if ((dx * dx) + (dy * dy) > (radius * radius)) + if ((dx * dx) + (dy * dy) > (radius * radius)) { continue; + } const QPoint p2 (p.x () + dx, p.y () + dy); diff --git a/imagelib/transforms/kpTransformAutoCrop.cpp b/imagelib/transforms/kpTransformAutoCrop.cpp --- a/imagelib/transforms/kpTransformAutoCrop.cpp +++ b/imagelib/transforms/kpTransformAutoCrop.cpp @@ -174,17 +174,15 @@ if (m_referenceColor.isTransparent ()) return kpColor::Transparent; - else if (m_processedColorSimilarity == 0) + + if (m_processedColorSimilarity == 0) return m_referenceColor; - else - { - int numPixels = (m_rect.width () * m_rect.height ()); - Q_ASSERT (numPixels > 0); - return kpColor (m_redSum / numPixels, - m_greenSum / numPixels, - m_blueSum / numPixels); - } + int numPixels = (m_rect.width () * m_rect.height ()); + Q_ASSERT (numPixels > 0); + + return kpColor (m_redSum / numPixels, m_greenSum / numPixels, m_blueSum / numPixels); + } //--------------------------------------------------------------------- @@ -322,13 +320,13 @@ struct kpTransformAutoCropCommandPrivate { - bool actOnSelection; + bool actOnSelection{}; kpTransformAutoCropBorder leftBorder, rightBorder, topBorder, botBorder; - kpImage *leftImage, *rightImage, *topImage, *botImage; + kpImage *leftImage{}, *rightImage{}, *topImage{}, *botImage{}; QRect contentsRect; - int oldWidth, oldHeight; - kpAbstractImageSelection *oldSelectionPtr; + int oldWidth{}, oldHeight{}; + kpAbstractImageSelection *oldSelectionPtr{}; }; // REFACTOR: Move to /commands/ @@ -377,18 +375,17 @@ { if (actOnSelection) { - if (options & kpTransformAutoCropCommand::ShowAccel) + if (options & kpTransformAutoCropCommand::ShowAccel) { return i18n ("Remove Internal B&order"); - else - return i18n ("Remove Internal Border"); - } - else - { - if (options & kpTransformAutoCropCommand::ShowAccel) - return i18n ("Autocr&op"); - else - return i18n ("Autocrop"); + } + + return i18n ("Remove Internal Border"); } + + if (options & kpTransformAutoCropCommand::ShowAccel) + return i18n ("Autocr&op"); + + return i18n ("Autocrop"); } //--------------------------------------------------------------------- @@ -418,8 +415,7 @@ qCDebug(kpLogImagelib) << "kpTransformAutoCropCommand::getUndoImage()"; qCDebug(kpLogImagelib) << "\timage=" << image << " border: rect=" << border.rect () - << " isSingleColor=" << border.isSingleColor () - << endl; + << " isSingleColor=" << border.isSingleColor (); if (image && border.exists () && !border.isSingleColor ()) { @@ -460,8 +456,9 @@ // public virtual [base kpCommand] void kpTransformAutoCropCommand::execute () { - if (!d->contentsRect.isValid ()) + if (!d->contentsRect.isValid ()) { d->contentsRect = contentsRect (); + } getUndoImages (); @@ -476,10 +473,10 @@ d->contentsRect); - if (!d->actOnSelection) + if (!d->actOnSelection) { doc->setImage (imageWithoutBorder); - else - { + } + else { d->oldSelectionPtr = doc->imageSelection ()->clone (); d->oldSelectionPtr->setBaseImage (kpImage ()); @@ -532,15 +529,16 @@ const kpImage **p = images; for (const kpTransformAutoCropBorder **b = borders; *b; b++, p++) { - if (!(*b)->exists ()) + if (!(*b)->exists ()) { continue; + } if ((*b)->isSingleColor ()) { kpColor col = (*b)->referenceColor (); #if DEBUG_KP_TOOL_AUTO_CROP && 1 qCDebug(kpLogImagelib) << "\tdrawing border " << (*b)->rect () - << " rgb=" << (int *) col.toQRgb () /* %X hack */ << endl; + << " rgb=" << (int *) col.toQRgb () /* %X hack */; #endif const QRect r = (*b)->rect (); @@ -562,8 +560,9 @@ } - if (!d->actOnSelection) + if (!d->actOnSelection) { doc->setImage (image); + } else { d->oldSelectionPtr->setBaseImage (image); @@ -597,7 +596,7 @@ d->botBorder.rect ().top () - 1 : image.height () - 1); - return QRect (topLeft, botRight); + return {topLeft, botRight}; } @@ -673,30 +672,25 @@ qCDebug(kpLogImagelib) << "\tcan't find border; leftBorder.rect=" << leftBorder.rect () << " rightBorder.rect=" << rightBorder.rect () << " topBorder.rect=" << topBorder.rect () - << " botBorder.rect=" << botBorder.rect () - << endl; + << " botBorder.rect=" << botBorder.rect (); #endif ::ShowNothingToAutocropMessage (mainWindow, static_cast (doc->selection ())); return false; } qCDebug(kpLogImagelib) << "\tnumRegions=" << numRegions; qCDebug(kpLogImagelib) << "\t\tleft=" << leftBorder.rect () - << " refCol=" << (leftBorder.exists () ? (int *) leftBorder.referenceColor ().toQRgb () : 0) - << " avgCol=" << (leftBorder.exists () ? (int *) leftBorder.averageColor ().toQRgb () : 0) - << endl; + << " refCol=" << (leftBorder.exists () ? (int *) leftBorder.referenceColor ().toQRgb () : nullptr) + << " avgCol=" << (leftBorder.exists () ? (int *) leftBorder.averageColor ().toQRgb () : nullptr); qCDebug(kpLogImagelib) << "\t\tright=" << rightBorder.rect () - << " refCol=" << (rightBorder.exists () ? (int *) rightBorder.referenceColor ().toQRgb () : 0) - << " avgCol=" << (rightBorder.exists () ? (int *) rightBorder.averageColor ().toQRgb () : 0) - << endl; + << " refCol=" << (rightBorder.exists () ? (int *) rightBorder.referenceColor ().toQRgb () : nullptr) + << " avgCol=" << (rightBorder.exists () ? (int *) rightBorder.averageColor ().toQRgb () : nullptr); qCDebug(kpLogImagelib) << "\t\ttop=" << topBorder.rect () - << " refCol=" << (topBorder.exists () ? (int *) topBorder.referenceColor ().toQRgb () : 0) - << " avgCol=" << (topBorder.exists () ? (int *) topBorder.averageColor ().toQRgb () : 0) - << endl; + << " refCol=" << (topBorder.exists () ? (int *) topBorder.referenceColor ().toQRgb () : nullptr) + << " avgCol=" << (topBorder.exists () ? (int *) topBorder.averageColor ().toQRgb () : nullptr); qCDebug(kpLogImagelib) << "\t\tbot=" << botBorder.rect () - << " refCol=" << (botBorder.exists () ? (int *) botBorder.referenceColor ().toQRgb () : 0) - << " avgCol=" << (botBorder.exists () ? (int *) botBorder.averageColor ().toQRgb () : 0) - << endl; + << " refCol=" << (botBorder.exists () ? (int *) botBorder.referenceColor ().toQRgb () : nullptr) + << " avgCol=" << (botBorder.exists () ? (int *) botBorder.averageColor ().toQRgb () : nullptr); // In case e.g. the user pastes a solid, coloured-in rectangle, diff --git a/imagelib/transforms/kpTransformCrop.cpp b/imagelib/transforms/kpTransformCrop.cpp --- a/imagelib/transforms/kpTransformCrop.cpp +++ b/imagelib/transforms/kpTransformCrop.cpp @@ -59,18 +59,19 @@ mainWindow->commandEnvironment ()); - kpTextSelection *textSel = - dynamic_cast (sel); - kpAbstractImageSelection *imageSel = - dynamic_cast (sel); + auto *textSel = dynamic_cast (sel); + auto *imageSel = dynamic_cast (sel); // It's either a text selection or an image selection, but cannot be // neither or both. Q_ASSERT (!!textSel != !!imageSel); - if (textSel) + if (textSel) { ::kpTransformCrop_TextSelection (mainWindow, i18n ("Set as Image"), resizeDocCommand); - else if (imageSel) + } + else if (imageSel) { ::kpTransformCrop_ImageSelection (mainWindow, i18n ("Set as Image"), resizeDocCommand); - else + } + else { Q_ASSERT (!"unreachable"); + } } diff --git a/imagelib/transforms/kpTransformCrop_ImageSelection.cpp b/imagelib/transforms/kpTransformCrop_ImageSelection.cpp --- a/imagelib/transforms/kpTransformCrop_ImageSelection.cpp +++ b/imagelib/transforms/kpTransformCrop_ImageSelection.cpp @@ -138,24 +138,21 @@ newDocImage.fill(m_backgroundColor.toQRgb()); qCDebug(kpLogImagelib) << "\tsel: rect=" << m_fromSelectionPtr->boundingRect () - << " pm=" << m_fromSelectionPtr->hasContent () - << endl; + << " pm=" << m_fromSelectionPtr->hasContent (); QImage setTransparentImage; if (m_fromSelectionPtr->hasContent ()) { setTransparentImage = m_fromSelectionPtr->transparentImage (); qCDebug(kpLogImagelib) << "\thave pixmap; rect=" - << setTransparentImage.rect () - << endl; + << setTransparentImage.rect (); } else { setTransparentImage = m_imageIfFromSelectionDoesntHaveOne; qCDebug(kpLogImagelib) << "\tno pixmap in sel - get it; rect=" - << setTransparentImage.rect () - << endl; + << setTransparentImage.rect (); } kpPixmapFX::paintPixmapAt (&newDocImage, @@ -185,8 +182,7 @@ m_oldImage = kpImage (); qCDebug(kpLogImagelib) << "\tsel: rect=" << m_fromSelectionPtr->boundingRect () - << " pm=" << m_fromSelectionPtr->hasContent () - << endl; + << " pm=" << m_fromSelectionPtr->hasContent (); document ()->setSelection (*m_fromSelectionPtr); environ ()->somethingBelowTheCursorChanged (); @@ -201,20 +197,21 @@ const QString &commandName, kpCommand *resizeDocCommand) { // Save starting selection, minus the border. - kpAbstractImageSelection *borderImageSel = - dynamic_cast ( + auto *borderImageSel = dynamic_cast ( mainWindow->document ()->selection ()->clone ()); + Q_ASSERT (borderImageSel); - if ( !borderImageSel ) // make coverity happy - return; + if ( !borderImageSel ) { // make coverity happy + return; + } // (only interested in border) borderImageSel->deleteContent (); borderImageSel->moveTo (QPoint (0, 0)); - kpCommandEnvironment *environ = mainWindow->commandEnvironment (); - kpMacroCommand *macroCmd = new kpMacroCommand (commandName, environ); + auto *environ = mainWindow->commandEnvironment (); + auto *macroCmd = new kpMacroCommand (commandName, environ); // (must resize doc _before_ SetDocumentToSelectionImageCommand in case // doc needs to gets bigger - else selection image may not fit) diff --git a/imagelib/transforms/kpTransformCrop_TextSelection.cpp b/imagelib/transforms/kpTransformCrop_TextSelection.cpp --- a/imagelib/transforms/kpTransformCrop_TextSelection.cpp +++ b/imagelib/transforms/kpTransformCrop_TextSelection.cpp @@ -44,7 +44,7 @@ kpCommandEnvironment *environ = mainWindow->commandEnvironment (); - kpMacroCommand *macroCmd = new kpMacroCommand (commandName, environ); + auto *macroCmd = new kpMacroCommand (commandName, environ); macroCmd->addCommand (resizeDocCommand); diff --git a/kpThumbnail.cpp b/kpThumbnail.cpp --- a/kpThumbnail.cpp +++ b/kpThumbnail.cpp @@ -87,8 +87,9 @@ qCDebug(kpLogMisc) << "kpThumbnail::setView(" << view << ")"; #endif - if (d->view == view) + if (d->view == view) { return; + } if (d->view) @@ -146,7 +147,7 @@ { #if DEBUG_KP_THUMBNAIL qCDebug(kpLogMisc) << "kpThumbnail::resizeEvent(" << width () - << "," << height () << ")" << endl; + << "," << height () << ")"; #endif QWidget::resizeEvent (e); @@ -157,16 +158,18 @@ { d->mainWindow->notifyThumbnailGeometryChanged (); - if (d->mainWindow->tool ()) + if (d->mainWindow->tool ()) { d->mainWindow->tool ()->somethingBelowTheCursorChanged (); + } } } // protected virtual [base QWidget] void kpThumbnail::moveEvent (QMoveEvent * /*e*/) { - if (d->mainWindow) + if (d->mainWindow) { d->mainWindow->notifyThumbnailGeometryChanged (); + } } // protected virtual [base QWidget] diff --git a/kpViewScrollableContainer.cpp b/kpViewScrollableContainer.cpp --- a/kpViewScrollableContainer.cpp +++ b/kpViewScrollableContainer.cpp @@ -186,8 +186,9 @@ #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER qCDebug(kpLogMisc) << "kpGrip::cancel()"; #endif - if (m_currentPoint == KP_INVALID_POINT) + if (m_currentPoint == KP_INVALID_POINT) { return; + } m_startPoint = KP_INVALID_POINT; m_currentPoint = KP_INVALID_POINT; @@ -230,35 +231,38 @@ } else { - if (m_startPoint != KP_INVALID_POINT) + if (m_startPoint != KP_INVALID_POINT) { cancel (); + } } } //--------------------------------------------------------------------- // public QPoint kpGrip::viewDeltaPoint () const { - if (m_startPoint == KP_INVALID_POINT) + if (m_startPoint == KP_INVALID_POINT) { return KP_INVALID_POINT; + } const QPoint point = mapFromGlobal (QCursor::pos ()); // TODO: this is getting out of sync with m_currentPoint - return QPoint (((m_type & kpGrip::Right) ? point.x () - m_startPoint.x () : 0), - ((m_type & kpGrip::Bottom) ? point.y () - m_startPoint.y () : 0)); + return {(m_type & kpGrip::Right) ? point.x () - m_startPoint.x () : 0, + (m_type & kpGrip::Bottom) ? point.y () - m_startPoint.y () : 0}; } //--------------------------------------------------------------------- // public void kpGrip::mouseMovedTo (const QPoint &point, bool dueToDragScroll) { - if (m_startPoint == KP_INVALID_POINT) + if (m_startPoint == KP_INVALID_POINT) { return; + } m_currentPoint = point; @@ -274,14 +278,14 @@ { #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER qCDebug(kpLogMisc) << "kpGrip::mouseMoveEvent() m_startPoint=" << m_startPoint - << " stateAfter: buttons=" << (int *) (int) e->buttons () - << endl; + << " stateAfter: buttons=" << (int *) (int) e->buttons (); #endif if (m_startPoint == KP_INVALID_POINT) { - if ((e->buttons () & Qt::MouseButtonMask) == 0) + if ((e->buttons () & Qt::MouseButtonMask) == 0) { setUserMessage (haventBegunDrawUserMessage ()); + } return; } @@ -295,8 +299,7 @@ { #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER qCDebug(kpLogMisc) << "kpGrip::mouseReleaseEvent() m_startPoint=" << m_startPoint - << " stateAfter: buttons=" << (int *) (int) e->buttons () - << endl; + << " stateAfter: buttons=" << (int *) (int) e->buttons (); #endif if (m_startPoint != KP_INVALID_POINT) @@ -332,7 +335,7 @@ qCDebug(kpLogMisc) << "kpGrip::enterEvent()" << " m_startPoint=" << m_startPoint << " shouldReleaseMouseButtons=" - << m_shouldReleaseMouseButtons << endl; + << m_shouldReleaseMouseButtons; #endif if (m_startPoint == KP_INVALID_POINT && @@ -354,7 +357,7 @@ qCDebug(kpLogMisc) << "kpGrip::leaveEvent()" << " m_startPoint=" << m_startPoint << " shouldReleaseMouseButtons=" - << m_shouldReleaseMouseButtons << endl; + << m_shouldReleaseMouseButtons; #endif if (m_startPoint == KP_INVALID_POINT && !m_shouldReleaseMouseButtons) @@ -479,31 +482,37 @@ // protected QSize kpViewScrollableContainer::newDocSize (int viewDX, int viewDY) const { - if (!m_view) - return QSize (); + if (!m_view) { + return {}; + } - if (!docResizingGrip ()) - return QSize (); + if (!docResizingGrip ()) { + return {}; + } const int docX = static_cast (m_view->transformViewToDocX (m_view->width () + viewDX)); const int docY = static_cast (m_view->transformViewToDocY (m_view->height () + viewDY)); - return QSize (qMax (1, docX), qMax (1, docY)); + return {qMax (1, docX), qMax (1, docY)}; } //--------------------------------------------------------------------- // protected void kpViewScrollableContainer::calculateDocResizingGrip () { - if (m_bottomRightGrip->isDrawing ()) + if (m_bottomRightGrip->isDrawing ()) { m_docResizingGrip = m_bottomRightGrip; - else if (m_bottomGrip->isDrawing ()) + } + else if (m_bottomGrip->isDrawing ()) { m_docResizingGrip = m_bottomGrip; - else if (m_rightGrip->isDrawing ()) + } + else if (m_rightGrip->isDrawing ()) { m_docResizingGrip = m_rightGrip; - else + } + else { m_docResizingGrip = nullptr; + } } //--------------------------------------------------------------------- @@ -519,42 +528,49 @@ // protected int kpViewScrollableContainer::bottomResizeLineWidth () const { - if (!docResizingGrip ()) + if (!docResizingGrip ()) { return -1; + } - if (!m_view) + if (!m_view) { return -1; + } - if (docResizingGrip ()->type () & kpGrip::Bottom) + if (docResizingGrip ()->type () & kpGrip::Bottom) { return qMax (m_view->zoomLevelY () / 100, 1); - else - return 1; + } + + return 1; } //--------------------------------------------------------------------- // protected int kpViewScrollableContainer::rightResizeLineWidth () const { - if (!docResizingGrip ()) + if (!docResizingGrip ()) { return -1; + } - if (!m_view) + if (!m_view) { return -1; + } - if (docResizingGrip ()->type () & kpGrip::Right) + if (docResizingGrip ()->type () & kpGrip::Right) { return qMax (m_view->zoomLevelX () / 100, 1); - else - return 1; + } + + return 1; } //--------------------------------------------------------------------- // protected QRect kpViewScrollableContainer::bottomResizeLineRect () const { - if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) - return QRect (); + if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) { + return {}; + } QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); @@ -569,8 +585,9 @@ // protected QRect kpViewScrollableContainer::rightResizeLineRect () const { - if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) - return QRect (); + if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) { + return {}; + } QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); @@ -585,8 +602,9 @@ // protected QRect kpViewScrollableContainer::bottomRightResizeLineRect () const { - if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) - return QRect (); + if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) { + return {}; + } QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); @@ -601,8 +619,9 @@ // private QRect kpViewScrollableContainer::mapViewToViewport (const QRect &viewRect) { - if (!viewRect.isValid ()) - return QRect (); + if (!viewRect.isValid ()) { + return {}; + } QRect ret = viewRect; ret.translate (-horizontalScrollBar()->value() - viewport()->x(), -verticalScrollBar()->value() - viewport()->y()); @@ -668,8 +687,7 @@ << " oldViewX=" << m_resizeRoundedLastViewX << " oldViewY=" << m_resizeRoundedLastViewY << " viewDX=" << viewDX - << " viewDY=" << viewDY - << endl; + << " viewDY=" << viewDY; #endif @@ -701,8 +719,9 @@ // protected slot void kpViewScrollableContainer::slotGripBeganDraw () { - if (!m_view) + if (!m_view) { return; + } m_overlay->resize(viewport()->size()); // make it cover whole viewport m_overlay->move(viewport()->pos()); @@ -732,12 +751,12 @@ qCDebug(kpLogMisc) << "kpViewScrollableContainer::slotGripContinuedDraw(" << viewDX << "," << viewDY << ") size=" << newDocSize (viewDX, viewDY) - << " dueToDragScroll=" << dueToDragScroll - << endl; + << " dueToDragScroll=" << dueToDragScroll; #endif - if (!m_view) + if (!m_view) { return; + } if (!dueToDragScroll && beginDragScroll(m_view->zoomLevelX ())) @@ -747,8 +766,7 @@ viewDY = newViewDeltaPoint.y (); #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER qCDebug(kpLogMisc) << "\tdrag scrolled - new view delta point=" - << newViewDeltaPoint - << endl; + << newViewDeltaPoint; #endif } @@ -787,12 +805,12 @@ #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER qCDebug(kpLogMisc) << "kpViewScrollableContainer::slotGripEndedDraw(" << viewDX << "," << viewDY << ") size=" - << newDocSize (viewDX, viewDY) - << endl; + << newDocSize (viewDX, viewDY); #endif - if (!m_view) + if (!m_view) { return; + } const QSize newSize = newDocSize (viewDX, viewDY); @@ -815,8 +833,9 @@ // protected slot void kpViewScrollableContainer::slotGripStatusMessageChanged (const QString &string) { - if (string == m_gripStatusMessage) + if (string == m_gripStatusMessage) { return; + } m_gripStatusMessage = string; emit statusMessageChanged (string); @@ -832,8 +851,7 @@ qCDebug(kpLogMisc) << "\tQCursor::pos=" << QCursor::pos () << " global visibleRect=" << kpWidgetMapper::toGlobal (this, - QRect(0, 0, viewport->width(), viewport->height())) - << endl; + QRect(0, 0, viewport->width(), viewport->height())); #endif // HACK: After dragging to a new size, handles move so that they are now @@ -925,8 +943,9 @@ // public void kpViewScrollableContainer::setView (kpView *view) { - if (m_view == view) + if (m_view == view) { return; + } if (m_view) { @@ -990,8 +1009,9 @@ // public slot bool kpViewScrollableContainer::beginDragScroll(int zoomLevel, bool *didSomething) { - if (didSomething) + if (didSomething) { *didSomething = false; + } m_zoomLevel = zoomLevel; @@ -1018,11 +1038,13 @@ stopDragScroll = false; } - if (stopDragScroll) + if (stopDragScroll) { m_dragScrollTimer->stop (); + } - if (didSomething) + if (didSomething) { *didSomething = scrolled; + } return scrolled; } @@ -1046,24 +1068,27 @@ m_dragScrollTimer->stop (); return true; } - else - { - return false; - } + + return false; } //--------------------------------------------------------------------- static int distanceFromRectToMultiplier (int dist) { - if (dist < 0) + if (dist < 0) { return 0; - else if (dist < DragDistanceFromRectMaxFor1stMultiplier) + } + + if (dist < DragDistanceFromRectMaxFor1stMultiplier) { return 1; - else if (dist < DragDistanceFromRectMaxFor2ndMultiplier) + } + + if (dist < DragDistanceFromRectMaxFor2ndMultiplier) { return 2; - else - return 4; + } + + return 4; } //--------------------------------------------------------------------- @@ -1073,8 +1098,9 @@ { bool scrolled = false; - if (didSomething) + if (didSomething) { *didSomething = false; + } const QRect rect = noDragScrollRect (); @@ -1135,8 +1161,9 @@ m_dragScrollTimer->start (DragScrollInterval); m_scrollTimerRunOnce = true; - if (didSomething) + if (didSomething) { *didSomething = scrolled; + } return scrolled; } @@ -1149,20 +1176,22 @@ { e->ignore (); - if (m_view) + if (m_view) { m_view->wheelEvent (e); + } - if ( !e->isAccepted() ) + if ( !e->isAccepted() ) { QScrollArea::wheelEvent(e); + } } //--------------------------------------------------------------------------------- QRect kpViewScrollableContainer::noDragScrollRect () const { - return QRect (DragScrollLeftTopMargin, DragScrollLeftTopMargin, - width () - DragScrollLeftTopMargin - DragScrollRightBottomMargin, - height () - DragScrollLeftTopMargin - DragScrollRightBottomMargin); + return {DragScrollLeftTopMargin, DragScrollLeftTopMargin, + width () - DragScrollLeftTopMargin - DragScrollRightBottomMargin, + height () - DragScrollLeftTopMargin - DragScrollRightBottomMargin}; } //--------------------------------------------------------------------- diff --git a/layers/selections/image/kpAbstractImageSelection.cpp b/layers/selections/image/kpAbstractImageSelection.cpp --- a/layers/selections/image/kpAbstractImageSelection.cpp +++ b/layers/selections/image/kpAbstractImageSelection.cpp @@ -135,13 +135,14 @@ // public virtual [base kpAbstractSelection] bool kpAbstractImageSelection::readFromStream (QDataStream &stream) { - if (!kpAbstractSelection::readFromStream (stream )) + if (!kpAbstractSelection::readFromStream (stream )) { return false; + } QImage qimage; stream >> qimage; qCDebug(kpLogLayers) << "\timage: w=" << qimage.width () << " h=" << qimage.height () - << " depth=" << qimage.depth () << endl; + << " depth=" << qimage.depth (); if (!qimage.isNull ()) { @@ -157,8 +158,9 @@ } // (was just a selection border in the clipboard, even though KolourPaint's // GUI doesn't allow you to copy such a thing into the clipboard) - else + else { d->baseImage = kpImage (); + } // TODO: Reset transparency mask? // TODO: Concrete subclass need to emit changed()? @@ -268,8 +270,9 @@ << boundingRect (); Q_ASSERT (image.width () == width () && image.height () == height ()); - if (isRectangular ()) + if (isRectangular ()) { return image; + } const QRegion mRegion = shapeRegion ().translated (-topLeft ()); @@ -302,8 +305,9 @@ // public virtual [kpAbstractSelection] void kpAbstractImageSelection::deleteContent () { - if (!hasContent ()) + if (!hasContent ()) { return; + } setBaseImage (kpImage ()); } @@ -348,8 +352,9 @@ const kpImageSelectionTransparency &transparency, bool checkTransparentPixmapChanged) { - if (d->transparency == transparency) + if (d->transparency == transparency) { return false; + } d->transparency = transparency; @@ -387,14 +392,16 @@ } } - if (!changed) + if (!changed) { haveChanged = false; + } } } - if (haveChanged) + if (haveChanged) { emit changed (boundingRect ()); + } return haveChanged; } @@ -498,7 +505,7 @@ void kpAbstractImageSelection::flip (bool horiz, bool vert) { qCDebug(kpLogLayers) << "kpAbstractImageSelection::flip(horiz=" << horiz - << ",vert=" << vert << ")" << endl; + << ",vert=" << vert << ")"; if (!d->baseImage.isNull ()) { diff --git a/layers/selections/image/kpEllipticalImageSelection.cpp b/layers/selections/image/kpEllipticalImageSelection.cpp --- a/layers/selections/image/kpEllipticalImageSelection.cpp +++ b/layers/selections/image/kpEllipticalImageSelection.cpp @@ -138,7 +138,7 @@ const QList polygons = path.toSubpathPolygons (); Q_ASSERT (polygons.size () == 1); - const QPolygonF firstPolygonF = polygons.first (); + const QPolygonF& firstPolygonF = polygons.first (); return firstPolygonF.toPolygon (); } @@ -158,8 +158,9 @@ // public virtual [kpAbstractSelection] bool kpEllipticalImageSelection::contains (const QPoint &point) const { - if (!boundingRect ().contains (point)) + if (!boundingRect ().contains (point)) { return false; + } return shapeRegion ().contains (point); } @@ -171,8 +172,9 @@ void kpEllipticalImageSelection::paintBorder (QImage *destPixmap, const QRect &docRect, bool selectionFinished) const { - if ( !boundingRect().isValid() ) + if ( !boundingRect().isValid() ) { return; + } paintPolygonalBorder (calculatePoints (), destPixmap, docRect, diff --git a/layers/selections/image/kpFreeFormImageSelection.cpp b/layers/selections/image/kpFreeFormImageSelection.cpp --- a/layers/selections/image/kpFreeFormImageSelection.cpp +++ b/layers/selections/image/kpFreeFormImageSelection.cpp @@ -133,8 +133,9 @@ // public virtual [base kpAbstractImageSelection] bool kpFreeFormImageSelection::readFromStream (QDataStream &stream) { - if (!kpAbstractImageSelection::readFromStream (stream)) + if (!kpAbstractImageSelection::readFromStream (stream)) { return false; + } stream >> d->orgPoints; recalculateCardinallyAdjacentPoints (); @@ -175,24 +176,24 @@ static QPolygon RecalculateCardinallyAdjacentPoints (const QPolygon &points) { - qCDebug(kpLogLayers) << "kpFreeFormImageSelection.cpp:RecalculateCardinallyAdjacentPoints()" - << endl; + qCDebug(kpLogLayers) << "kpFreeFormImageSelection.cpp:RecalculateCardinallyAdjacentPoints()"; qCDebug(kpLogLayers) << "\tpoints=" << points; // Filter out duplicates. QPolygon noDups; - foreach (const QPoint &p, points) + for (const auto &p : points) { - if (!noDups.isEmpty () && p == noDups.last ()) + if (!noDups.isEmpty () && p == noDups.last ()) { continue; + } noDups.append (p); } qCDebug(kpLogLayers) << "\twithout dups=" << noDups; // Interpolate to ensure cardinal adjacency. QPolygon cardPoints; - foreach (const QPoint &p, noDups) + for (const auto &p : noDups) { if (!cardPoints.isEmpty () && !kpPainter::pointsAreCardinallyAdjacent (p, cardPoints.last ())) @@ -215,8 +216,9 @@ cardPoints.append (interpPoints [i]); } } - else + else { cardPoints.append (p); + } } qCDebug(kpLogLayers) << "\tcardinally adjacent=" << cardPoints; @@ -230,8 +232,9 @@ QPolygon pointsLoop = d->cardPointsCache; - if (!pointsLoop.isEmpty ()) + if (!pointsLoop.isEmpty ()) { pointsLoop.append (pointsLoop.first ()); + } // OPT: We know this method only needs to act on the last 2 points of // "pointLoop", since the previous points are definitely cardinally @@ -295,8 +298,9 @@ // public virtual [kpAbstractSelection] bool kpFreeFormImageSelection::contains (const QPoint &point) const { - if (!boundingRect ().contains (point)) + if (!boundingRect ().contains (point)) { return false; + } // We can't use the baseImage() (when non-null) and get the transparency of // the pixel at , instead of this region test, as the pixel may be @@ -371,12 +375,14 @@ void kpFreeFormImageSelection::paintBorder (QImage *destPixmap, const QRect &docRect, bool selectionFinished) const { - if (selectionFinished) + if (selectionFinished) { paintPolygonalBorder (cardinallyAdjacentPointsLoop (), destPixmap, docRect, selectionFinished); - else + } + else { paintPolygonalBorder (cardinallyAdjacentPoints (), destPixmap, docRect, selectionFinished); + } } diff --git a/layers/selections/image/kpImageSelectionTransparency.cpp b/layers/selections/image/kpImageSelectionTransparency.cpp --- a/layers/selections/image/kpImageSelectionTransparency.cpp +++ b/layers/selections/image/kpImageSelectionTransparency.cpp @@ -101,9 +101,7 @@ //--------------------------------------------------------------------- -kpImageSelectionTransparency::~kpImageSelectionTransparency () -{ -} +kpImageSelectionTransparency::~kpImageSelectionTransparency () = default; //--------------------------------------------------------------------- @@ -147,7 +145,7 @@ { // There are legitimate uses for this so no qCCritical(kpLogLayers) qCDebug(kpLogLayers) << "kpImageSelectionTransparency::transparentColor() " - "getting transparent color even though opaque" << endl; + "getting transparent color even though opaque"; } return m_transparentColor; @@ -170,7 +168,7 @@ if (m_colorSimilarity < 0 || m_colorSimilarity > kpColorSimilarityHolder::MaxColorSimilarity) { - qCCritical(kpLogLayers) << "kpImageSelectionTransparency::colorSimilarity() invalid colorSimilarity" << endl; + qCCritical(kpLogLayers) << "kpImageSelectionTransparency::colorSimilarity() invalid colorSimilarity"; return 0; } diff --git a/layers/selections/image/kpRectangularImageSelection.cpp b/layers/selections/image/kpRectangularImageSelection.cpp --- a/layers/selections/image/kpRectangularImageSelection.cpp +++ b/layers/selections/image/kpRectangularImageSelection.cpp @@ -116,8 +116,9 @@ { Q_ASSERT (boundingRect ().isValid ()); - if (nullForRectangular) - return QBitmap (); + if (nullForRectangular) { + return {}; + } QBitmap maskBitmap (width (), height ()); maskBitmap.fill (Qt::color1/*opaque*/); diff --git a/layers/selections/kpAbstractSelection.cpp b/layers/selections/kpAbstractSelection.cpp --- a/layers/selections/kpAbstractSelection.cpp +++ b/layers/selections/kpAbstractSelection.cpp @@ -61,8 +61,9 @@ // protected kpAbstractSelection &kpAbstractSelection::operator= (const kpAbstractSelection &rhs) { - if (this == &rhs) + if (this == &rhs) { return *this; + } d->rect = rhs.d->rect; @@ -95,7 +96,7 @@ { #if DEBUG_KP_SELECTION && 1 qCDebug(kpLogLayers) << "kpAbstractSelection::operator<<(sel: rect=" << - selection.boundingRect () << endl; + selection.boundingRect (); #endif stream << selection.serialID (); selection.writeToStream (stream); @@ -113,7 +114,7 @@ // public QSize kpAbstractSelection::minimumSize () const { - return QSize (minimumWidth (), minimumHeight ()); + return {minimumWidth (), minimumHeight ()}; } @@ -162,20 +163,24 @@ // OPT: not space optimal - current code adds duplicate corner points. // top - for (int x = 0; x < rect.width (); x++) + for (int x = 0; x < rect.width (); x++) { points.append (QPoint (rect.x () + x, rect.top ())); + } // right - for (int y = 0; y < rect.height (); y++) + for (int y = 0; y < rect.height (); y++) { points.append (QPoint (rect.right (), rect.y () + y)); + } // bottom - for (int x = rect.width () - 1; x >= 0; x--) + for (int x = rect.width () - 1; x >= 0; x--) { points.append (QPoint (rect.x () + x, rect.bottom ())); + } // left - for (int y = rect.height () - 1; y >= 0; y--) + for (int y = rect.height () - 1; y >= 0; y--) { points.append (QPoint (rect.left (), rect.y () + y)); + } return points; } @@ -195,8 +200,9 @@ qCDebug(kpLogLayers) << "kpAbstractSelection::moveBy(" << dx << "," << dy << ")"; #endif - if (dx == 0 && dy == 0) + if (dx == 0 && dy == 0) { return; + } QRect oldRect = boundingRect (); @@ -229,8 +235,9 @@ #if DEBUG_KP_SELECTION && 1 qCDebug(kpLogLayers) << "\toldBoundingRect=" << oldBoundingRect; #endif - if (topLeftPoint == oldBoundingRect.topLeft ()) + if (topLeftPoint == oldBoundingRect.topLeft ()) { return; + } QPoint delta (topLeftPoint - oldBoundingRect.topLeft ()); moveBy (delta.x (), delta.y ()); @@ -247,16 +254,15 @@ #if DEBUG_KP_SELECTION && 1 qCDebug(kpLogLayers) << "kpAbstractSelection::paintRectangularBorder() boundingRect=" - << boundingRect () << endl; + << boundingRect (); #endif #if DEBUG_KP_SELECTION && 1 qCDebug(kpLogLayers) << "\tselection border = rectangle"; qCDebug(kpLogLayers) << "\t\tx=" << boundingRect ().x () - docRect.x () << " y=" << boundingRect ().y () - docRect.y () << " w=" << boundingRect ().width () - << " h=" << boundingRect ().height () - << endl; + << " h=" << boundingRect ().height (); #endif kpPixmapFX::drawStippleRect(destPixmap, boundingRect ().x () - docRect.x (), @@ -277,7 +283,7 @@ { #if DEBUG_KP_SELECTION && 1 qCDebug(kpLogLayers) << "kpAbstractSelection::paintPolygonalBorder() boundingRect=" - << boundingRect () << endl; + << boundingRect (); #endif QPolygon pointsTranslated = points; diff --git a/layers/selections/kpSelectionDrag.cpp b/layers/selections/kpSelectionDrag.cpp --- a/layers/selections/kpSelectionDrag.cpp +++ b/layers/selections/kpSelectionDrag.cpp @@ -53,8 +53,7 @@ { #if DEBUG_KP_SELECTION_DRAG && 1 qCDebug(kpLogLayers) << "kpSelectionDrag() w=" << sel.width () - << " h=" << sel.height () - << endl; + << " h=" << sel.height (); #endif Q_ASSERT (sel.hasContent ()); @@ -72,17 +71,16 @@ const QImage image = sel.baseImage (); #if DEBUG_KP_SELECTION_DRAG && 1 qCDebug(kpLogLayers) << "\timage: w=" << image.width () - << " h=" << image.height () - << endl; + << " h=" << image.height (); #endif if (image.isNull ()) { // TODO: proper error handling. - qCCritical(kpLogLayers) << "kpSelectionDrag::setSelection() could not convert to image" - << endl; + qCCritical(kpLogLayers) << "kpSelectionDrag::setSelection() could not convert to image"; } - else + else { setImageData (image); + } } //--------------------------------------------------------------------- @@ -123,44 +121,45 @@ return kpSelectionFactory::FromStream (stream); } - else + + +#if DEBUG_KP_SELECTION_DRAG + qCDebug(kpLogLayers) << "\tmimeSource doesn't provide selection - try image"; +#endif + + QImage image = qvariant_cast (mimeData->imageData ()); + if (!image.isNull ()) { - #if DEBUG_KP_SELECTION_DRAG - qCDebug(kpLogLayers) << "\tmimeSource doesn't provide selection - try image"; - #endif +#if DEBUG_KP_SELECTION_DRAG + qCDebug(kpLogLayers) << "\tok w=" << image.width () << " h=" << image.height (); +#endif - QImage image = qvariant_cast (mimeData->imageData ()); - if (!image.isNull ()) - { - #if DEBUG_KP_SELECTION_DRAG - qCDebug(kpLogLayers) << "\tok w=" << image.width () << " h=" << image.height (); - #endif + return new kpRectangularImageSelection ( + QRect (0, 0, image.width (), image.height ()), image); + } - return new kpRectangularImageSelection ( - QRect (0, 0, image.width (), image.height ()), image); - } - else if ( mimeData->hasUrls() ) // no image, check for path to local image file - { - QList urls = mimeData->urls(); + if ( mimeData->hasUrls() ) // no image, check for path to local image file + { + QList urls = mimeData->urls(); - if ( urls.count() && urls[0].isLocalFile() ) - { + if ( urls.count() && urls[0].isLocalFile() ) + { image.load(urls[0].toLocalFile()); if ( !image.isNull() ) { - return new kpRectangularImageSelection( - QRect(0, 0, image.width(), image.height()), image); + return new kpRectangularImageSelection( + QRect(0, 0, image.width(), image.height()), image); } - } } + } #if DEBUG_KP_SELECTION_DRAG qCDebug(kpLogLayers) << "kpSelectionDrag::decode(kpAbstractSelection) mimeSource had no sel " - "and could not decode to image" << endl; + "and could not decode to image"; #endif return nullptr; - } + } //--------------------------------------------------------------------- diff --git a/layers/selections/text/kpPreeditText.cpp b/layers/selections/text/kpPreeditText.cpp --- a/layers/selections/text/kpPreeditText.cpp +++ b/layers/selections/text/kpPreeditText.cpp @@ -51,7 +51,7 @@ m_position (-1, -1) { m_preeditString = event->preeditString (); - foreach (const QInputMethodEvent::Attribute &attr, event->attributes ()) + for (const auto &attr : event->attributes ()) { switch (attr.type) { diff --git a/layers/selections/text/kpTextSelection.cpp b/layers/selections/text/kpTextSelection.cpp --- a/layers/selections/text/kpTextSelection.cpp +++ b/layers/selections/text/kpTextSelection.cpp @@ -167,8 +167,8 @@ // public static QSize kpTextSelection::MinimumSizeForTextStyle (const kpTextStyle &textStyle) { - return QSize (kpTextSelection::MinimumWidthForTextStyle (textStyle), - kpTextSelection::MinimumHeightForTextStyle (textStyle)); + return {kpTextSelection::MinimumWidthForTextStyle (textStyle), + kpTextSelection::MinimumHeightForTextStyle (textStyle)}; } @@ -213,8 +213,8 @@ // public static QSize kpTextSelection::PreferredMinimumSizeForTextStyle (const kpTextStyle &textStyle) { - return QSize (kpTextSelection::PreferredMinimumWidthForTextStyle (textStyle), - kpTextSelection::PreferredMinimumHeightForTextStyle (textStyle)); + return {kpTextSelection::PreferredMinimumWidthForTextStyle (textStyle), + kpTextSelection::PreferredMinimumHeightForTextStyle (textStyle)}; } @@ -227,10 +227,10 @@ // public QRect kpTextSelection::textAreaRect () const { - return QRect (x () + kpTextSelection::TextBorderSize (), - y () + kpTextSelection::TextBorderSize (), - width () - kpTextSelection::TextBorderSize () * 2, - height () - kpTextSelection::TextBorderSize () * 2); + return {x () + kpTextSelection::TextBorderSize (), + y () + kpTextSelection::TextBorderSize (), + width () - kpTextSelection::TextBorderSize () * 2, + height () - kpTextSelection::TextBorderSize () * 2}; } @@ -270,8 +270,9 @@ // public virtual [kpAbstractSelection] void kpTextSelection::deleteContent () { - if (!hasContent ()) + if (!hasContent ()) { return; + } setTextLines (QList ()); } @@ -295,8 +296,9 @@ // public static QString kpTextSelection::TextForTextLines (const QList &textLines) { - if (textLines.isEmpty ()) - return QString (); + if (textLines.isEmpty ()) { + return {}; + } QString bigString = textLines [0]; diff --git a/layers/selections/text/kpTextSelection_Cursor.cpp b/layers/selections/text/kpTextSelection_Cursor.cpp --- a/layers/selections/text/kpTextSelection_Cursor.cpp +++ b/layers/selections/text/kpTextSelection_Cursor.cpp @@ -46,25 +46,28 @@ // public int kpTextSelection::closestTextRowForPoint (const QPoint &point) const { - if (!pointIsInTextArea (point)) + if (!pointIsInTextArea (point)) { return -1; + } const QFontMetrics fontMetrics (d->textStyle.fontMetrics ()); int row = (point.y () - textAreaRect ().y ()) / fontMetrics.lineSpacing (); - if (row >= static_cast (d->textLines.size ())) + if (row >= static_cast (d->textLines.size ())) { row = d->textLines.size () - 1; + } return row; } // public int kpTextSelection::closestTextColForPoint (const QPoint &point) const { int row = closestTextRowForPoint (point); - if (row < 0 || row >= static_cast (d->textLines.size ())) + if (row < 0 || row >= static_cast (d->textLines.size ())) { return -1; + } const int localX = point.x () - textAreaRect ().x (); @@ -78,8 +81,9 @@ { // OPT: fontMetrics::charWidth() might be faster const int nextCharLocalLeft = fontMetrics.width (d->textLines [row], col + 1); - if (localX <= (charLocalLeft + nextCharLocalLeft) / 2) + if (localX <= (charLocalLeft + nextCharLocalLeft) / 2) { return col; + } charLocalLeft = nextCharLocalLeft; } @@ -103,8 +107,7 @@ << col << ") out of range" << " textLines='" << text () - << "'" - << endl; + << "'"; #endif return KP_INVALID_POINT; } diff --git a/layers/selections/text/kpTextSelection_Paint.cpp b/layers/selections/text/kpTextSelection_Paint.cpp --- a/layers/selections/text/kpTextSelection_Paint.cpp +++ b/layers/selections/text/kpTextSelection_Paint.cpp @@ -52,9 +52,9 @@ void kpTextSelection::drawPreeditString(QPainter &painter, int &x, int y, const kpPreeditText &preeditText) const { int i = 0; - QString preeditString = preeditText.preeditString (); + const QString& preeditString = preeditText.preeditString (); QString str; - foreach (const QInputMethodEvent::Attribute &attr, preeditText.textFormatList ()) + for (const auto &attr : preeditText.textFormatList ()) { int start = attr.start; int length = attr.length; @@ -65,7 +65,9 @@ length = length - i + start; start = i; } - if (length <= 0) continue; + if (length <= 0) { + continue; + } if (i < start) { @@ -118,15 +120,15 @@ qCDebug(kpLogLayers) << "kpTextSelection::paint() textStyle: fcol=" << (int *) d->textStyle.foregroundColor ().toQRgb () << " bcol=" - << (int *) d->textStyle.backgroundColor ().toQRgb () - << endl; + << (int *) d->textStyle.backgroundColor ().toQRgb (); #endif // Drawing text is slow so if the text box will be rendered completely // outside of , don't bother rendering it at all. const QRect modifyingRect = docRect.intersected (boundingRect ()); - if (modifyingRect.isEmpty ()) + if (modifyingRect.isEmpty ()) { return; + } // Is the text box completely invisible? @@ -154,17 +156,18 @@ << " leading=" << fontMetrics.leading () << " ascent=" << fontMetrics.ascent () << " descent=" << fontMetrics.descent () - << " lineSpacing=" << fontMetrics.lineSpacing () - << endl; + << " lineSpacing=" << fontMetrics.lineSpacing (); #endif QPainter painter(&floatImage); // Fill in the background using the transparent/opaque tool setting - if ( theTextStyle.isBackgroundTransparent() ) + if ( theTextStyle.isBackgroundTransparent() ) { painter.fillRect(theWholeAreaRect, Qt::transparent); - else + } + else { painter.fillRect(theWholeAreaRect, theTextStyle.backgroundColor().toQColor()); + } painter.setClipRect(theWholeAreaRect); painter.setPen(theTextStyle.foregroundColor().toQColor()); @@ -178,14 +181,15 @@ painter.setCompositionMode(QPainter::CompositionMode_Clear); int baseLine = theTextAreaRect.y () + fontMetrics.ascent (); - foreach (const QString &str, theTextLines) + for (const auto &str : theTextLines) { painter.drawText (theTextAreaRect.x (), baseLine, str); baseLine += fontMetrics.lineSpacing (); // if the next textline would already be below the visible text area, stop drawing - if ( (baseLine - fontMetrics.ascent()) > (theTextAreaRect.y() + theTextAreaRect.height()) ) + if ( (baseLine - fontMetrics.ascent()) > (theTextAreaRect.y() + theTextAreaRect.height()) ) { break; + } } // the next text drawing will now blend the text foreground color with // what is really below the text background @@ -212,7 +216,7 @@ int i = 0; int row = thePreeditText.position().y(); int col = thePreeditText.position().x(); - foreach (const QString &str, theTextLines) + for (const auto &str : theTextLines) { if (row == i && !thePreeditText.isEmpty()) { @@ -233,8 +237,9 @@ i++; // if the next textline would already be below the visible text area, stop drawing - if ( (baseLine - fontMetrics.ascent()) > (theTextAreaRect.y() + theTextAreaRect.height()) ) + if ( (baseLine - fontMetrics.ascent()) > (theTextAreaRect.y() + theTextAreaRect.height()) ) { break; + } } } diff --git a/layers/selections/text/kpTextStyle.cpp b/layers/selections/text/kpTextStyle.cpp --- a/layers/selections/text/kpTextStyle.cpp +++ b/layers/selections/text/kpTextStyle.cpp @@ -56,9 +56,7 @@ { } -kpTextStyle::~kpTextStyle () -{ -} +kpTextStyle::~kpTextStyle () = default; // friend diff --git a/layers/tempImage/kpTempImage.cpp b/layers/tempImage/kpTempImage.cpp --- a/layers/tempImage/kpTempImage.cpp +++ b/layers/tempImage/kpTempImage.cpp @@ -81,8 +81,9 @@ kpTempImage &kpTempImage::operator= (const kpTempImage &rhs) { - if (this == &rhs) + if (this == &rhs) { return *this; + } m_isBrush = rhs.m_isBrush; m_renderMode = rhs.m_renderMode; @@ -157,8 +158,7 @@ // public QRect kpTempImage::rect () const { - return QRect (m_topLeft.x (), m_topLeft.y (), - m_width, m_height); + return {m_topLeft.x (), m_topLeft.y (), m_width, m_height}; } //--------------------------------------------------------------------- diff --git a/lgpl/generic/kpColorCollection.cpp b/lgpl/generic/kpColorCollection.cpp --- a/lgpl/generic/kpColorCollection.cpp +++ b/lgpl/generic/kpColorCollection.cpp @@ -88,7 +88,7 @@ QStringList paths = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, "colors", QStandardPaths::LocateDirectory); - foreach (const QString &path, paths) { + for (const auto &path : paths) { paletteList.append(QDir(path).entryList(QStringList(), QDir::Files)); } @@ -255,7 +255,7 @@ str << "KDE RGB Palette\n"; str << description << "\n"; - foreach (const ColorNode &node, d->colorList) + for (const auto &node : d->colorList) { // Added for KolourPaint. if(!node.color.isValid ()) @@ -302,7 +302,7 @@ atomicFileWriter.cancelWriting (); qCDebug(kpLogMisc) << "\treturning false because could not open QSaveFile" - << " error=" << atomicFileWriter.error () << endl; + << " error=" << atomicFileWriter.error (); ::CouldNotSaveDialog (url, parent); return false; } diff --git a/lgpl/generic/widgets/kpColorCellsBase.cpp b/lgpl/generic/widgets/kpColorCellsBase.cpp --- a/lgpl/generic/widgets/kpColorCellsBase.cpp +++ b/lgpl/generic/widgets/kpColorCellsBase.cpp @@ -452,8 +452,7 @@ { qCDebug(kpLogMisc) << "kpColorCellsBase::dragEnterEvent() acceptDrags=" << d->acceptDrags - << " canDecode=" << KColorMimeData::canDecode(event->mimeData()) - << endl; + << " canDecode=" << KColorMimeData::canDecode(event->mimeData()); event->setAccepted( d->acceptDrags && KColorMimeData::canDecode( event->mimeData())); if (event->isAccepted ()) ::SetDropAction (this, event); @@ -464,8 +463,7 @@ { qCDebug(kpLogMisc) << "kpColorCellsBase::dragMoveEvent() acceptDrags=" << d->acceptDrags - << " canDecode=" << KColorMimeData::canDecode(event->mimeData()) - << endl; + << " canDecode=" << KColorMimeData::canDecode(event->mimeData()); // TODO: Disallow drag that isn't onto a cell. event->setAccepted( d->acceptDrags && KColorMimeData::canDecode( event->mimeData())); if (event->isAccepted ()) diff --git a/mainWindow/kpMainWindow.cpp b/mainWindow/kpMainWindow.cpp --- a/mainWindow/kpMainWindow.cpp +++ b/mainWindow/kpMainWindow.cpp @@ -118,8 +118,7 @@ { d->configOpenImagesInSameWindow = false; qCDebug(kpLogMainWindow) << "\tconfigOpenImagesInSameWindow: first time" - << " - writing default: " << d->configOpenImagesInSameWindow - << endl; + << " - writing default: " << d->configOpenImagesInSameWindow; // TODO: More hidden options have to write themselves out on startup, // not on use, to be discoverable (e.g. printing centered on page). cfg.writeEntry (kpSettingOpenImagesInSameWindow, @@ -155,8 +154,7 @@ qCDebug(kpLogMainWindow) << "\t\tThumbnail Settings: shown=" << d->configThumbnailShown << " geometry=" << d->configThumbnailGeometry << " zoomed=" << d->configZoomedThumbnail - << " showRectangle=" << d->configThumbnailShowRectangle - << endl; + << " showRectangle=" << d->configThumbnailShowRectangle; } //--------------------------------------------------------------------- @@ -167,7 +165,7 @@ { const QList menuToHide = findChildren("toolToolBarHiddenMenu"); // should only contain one but... - foreach (QMenu *menu, menuToHide) + for (auto *menu : menuToHide) { menu->menuAction()->setVisible(false); } @@ -382,8 +380,9 @@ // Get the kpTool to finish up. This makes sure that the kpTool destructor // will not need to access any other class (that might be deleted before // the destructor is called by the QObject child-deletion mechanism). - if (tool ()) + if (tool ()) { tool ()->endInternal (); + } // Delete document & views. // Note: This will disconnects signals from the current kpTool, so kpTool @@ -410,8 +409,9 @@ // public kpDocumentEnvironment *kpMainWindow::documentEnvironment () { - if (!d->documentEnvironment) + if (!d->documentEnvironment) { d->documentEnvironment = new kpDocumentEnvironment (this); + } return d->documentEnvironment; } @@ -460,8 +460,9 @@ kpCommandEnvironment *kpMainWindow::commandEnvironment () { - if (!d->commandEnvironment) + if (!d->commandEnvironment) { d->commandEnvironment = new kpCommandEnvironment (this); + } return d->commandEnvironment; } @@ -574,7 +575,7 @@ if (d->document) { qCDebug(kpLogMainWindow) << "\treparenting doc that may have been created into a" - << " different mainWindiow" << endl; + << " different mainWindiow"; d->document->setEnviron (documentEnvironment ()); d->viewManager = new kpViewManager (this); @@ -688,8 +689,9 @@ slotEnableReload (); slotEnableSettingsShowPath (); - if (d->commandHistory) + if (d->commandHistory) { d->commandHistory->clear (); + } qCDebug(kpLogMainWindow) << "\tdocument and views ready to go!"; } @@ -732,7 +734,7 @@ // However, you would need to prefix all possible error/warning // dialogs that might be called, with Qt::arrowCursor e.g. in // kpDocument and probably a lot more places. - foreach (const QUrl &u, urls) + for (const auto &u : urls) open (u); } else if (e->mimeData ()->hasText ()) @@ -763,8 +765,7 @@ << kpWidgetMapper::toGlobal (d->scrollView, QRect (0, 0, d->scrollView->viewport()->width (), - d->scrollView->viewport()->height ())) - << endl; + d->scrollView->viewport()->height ())); } if (d->thumbnailView && kpWidgetMapper::toGlobal (d->thumbnailView, d->thumbnailView->rect ()) @@ -861,8 +862,9 @@ // private slot void kpMainWindow::slotDocumentRestored () { - if (d->document) + if (d->document) { d->document->setModified (false); + } slotUpdateCaption (); } diff --git a/mainWindow/kpMainWindow_Colors.cpp b/mainWindow/kpMainWindow_Colors.cpp --- a/mainWindow/kpMainWindow_Colors.cpp +++ b/mainWindow/kpMainWindow_Colors.cpp @@ -70,8 +70,9 @@ static_cast(&KSelectAction::triggered), this, &kpMainWindow::slotColorsKDE); - foreach (const QString &colName, ::KDEColorCollectionNames ()) + for (const auto &colName : ::KDEColorCollectionNames ()) { d->actionColorsKDE->addAction (colName); + } d->actionColorsOpen = ac->addAction ("colors_open"); d->actionColorsOpen->setText (i18nc ("@item:inmenu colors", "&Open...")); @@ -184,8 +185,9 @@ toolEndShape (); - if (!colorCells ()->isModified ()) + if (!colorCells ()->isModified ()) { return true; // ok to close + } int result = KMessageBox::Cancel; @@ -250,8 +252,9 @@ // Call just in case. toolEndShape (); - if (!queryCloseColors ()) + if (!queryCloseColors ()) { return; + } openDefaultColors (); @@ -272,11 +275,9 @@ colorCells ()->setColorCollection (colorCol); return true; } - else - { - qCDebug(kpLogMainWindow) << "failed to open"; - return false; - } + + qCDebug(kpLogMainWindow) << "failed to open"; + return false; } //--------------------------------------------------------------------- @@ -294,30 +295,26 @@ deselectActionColorsKDE (); return; } - else - { - // queryCloseColors() calls slotColorSave(), which can call - // slotColorSaveAs(), which can call deselectActionColorsKDE(). - d->actionColorsKDE->setCurrentItem (curItem); - } + + // queryCloseColors() calls slotColorSave(), which can call + // slotColorSaveAs(), which can call deselectActionColorsKDE(). + d->actionColorsKDE->setCurrentItem (curItem); const QStringList colNames = ::KDEColorCollectionNames (); const int selected = d->actionColorsKDE->currentItem (); Q_ASSERT (selected >= 0 && selected < colNames.size ()); - if (!openKDEColors (colNames [selected])) + if (!openKDEColors (colNames [selected])) { deselectActionColorsKDE (); + } } //--------------------------------------------------------------------- // private bool kpMainWindow::openColors (const QUrl &url) { - if (!colorCells ()->openColorCollection (url)) - return false; - - return true; + return colorCells ()->openColorCollection (url); } //--------------------------------------------------------------------- @@ -334,12 +331,14 @@ if (fd.exec ()) { - if (!queryCloseColors ()) + if (!queryCloseColors ()) { return; + } QList selected = fd.selectedUrls(); - if ( selected.count() && openColors(selected[0]) ) + if ( selected.count() && openColors(selected[0]) ) { deselectActionColorsKDE(); + } } } @@ -390,8 +389,9 @@ qCDebug(kpLogMainWindow) << "result=" << result << "vs KMessageBox::Continue" << KMessageBox::Continue; - if (result != KMessageBox::Continue) + if (result != KMessageBox::Continue) { return; + } } @@ -402,10 +402,12 @@ else { const QString name = colorCells ()->colorCollection ()->name (); - if (!name.isEmpty ()) + if (!name.isEmpty ()) { openKDEColors (name); - else + } + else { openDefaultColors (); + } } } @@ -442,16 +444,17 @@ if (fd.exec ()) { QList selected = fd.selectedUrls(); - if ( !selected.count() || !colorCells ()->saveColorCollectionAs(selected[0]) ) + if ( !selected.count() || !colorCells ()->saveColorCollectionAs(selected[0]) ) { return false; + } // We're definitely using our own color collection now. deselectActionColorsKDE (); return true; } - else - return false; + + return false; } //--------------------------------------------------------------------- diff --git a/mainWindow/kpMainWindow_Edit.cpp b/mainWindow/kpMainWindow_Edit.cpp --- a/mainWindow/kpMainWindow_Edit.cpp +++ b/mainWindow/kpMainWindow_Edit.cpp @@ -181,7 +181,7 @@ static QMimeData *NewTextMimeData (const QString &text) { - QMimeData *md = new QMimeData (); + auto *md = new QMimeData (); md->setText (text); return md; } @@ -203,7 +203,7 @@ if (dynamic_cast (sel)) { - kpTextSelection *textSel = static_cast (sel); + auto *textSel = dynamic_cast (sel); if (!textSel->text ().isEmpty ()) { QApplication::clipboard ()->setMimeData ( @@ -234,29 +234,31 @@ } else if (dynamic_cast (sel)) { - kpAbstractImageSelection *imageSel = - static_cast (sel); + auto *imageSel = dynamic_cast (sel); // Transparency doesn't get sent across the aether so nuke it now // so that transparency mask doesn't get needlessly recalculated // if we ever call sel.setBaseImage(). imageSel->setTransparency (kpImageSelectionTransparency ()); kpImage rawImage; - if (imageSel->hasContent ()) + if (imageSel->hasContent ()) { rawImage = imageSel->baseImage (); - else + } + else { rawImage = d->document->getSelectedBaseImage (); + } imageSel->setBaseImage ( rawImage ); QApplication::clipboard ()->setMimeData ( new kpSelectionDrag (*imageSel), QClipboard::Clipboard); } - else + else { Q_ASSERT (!"Unknown selection type"); + } delete sel; } @@ -284,8 +286,7 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::calcUsefulPasteRect(" << imageWidth << "," << imageHeight - << ")" - << endl; + << ")"; Q_ASSERT (d->document); // TODO: 1st choice is to paste sel near but not overlapping last deselect point @@ -302,21 +303,19 @@ imageWidth <= docTopLeft.x () || imageHeight <= docTopLeft.y ()) { - return QRect (docTopLeft.x (), docTopLeft.y (), - imageWidth, imageHeight); + return {docTopLeft.x (), docTopLeft.y (), imageWidth, imageHeight}; } } - return QRect (0, 0, imageWidth, imageHeight); + return {0, 0, imageWidth, imageHeight}; } //--------------------------------------------------------------------- // private void kpMainWindow::paste(const kpAbstractSelection &sel, bool forceTopLeft) { - qCDebug(kpLogMainWindow) << "kpMainWindow::paste(forceTopLeft=" << forceTopLeft << ")" - << endl; + qCDebug(kpLogMainWindow) << "kpMainWindow::paste(forceTopLeft=" << forceTopLeft << ")"; kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); @@ -328,7 +327,7 @@ if (!d->document) { - kpDocument *newDoc = new kpDocument ( + auto *newDoc = new kpDocument ( sel.width (), sel.height (), documentEnvironment ()); // will also create viewManager @@ -339,16 +338,17 @@ // Paste as new selection // - const kpAbstractImageSelection *imageSel = - dynamic_cast (&sel); + const auto *imageSel = dynamic_cast (&sel); + if (imageSel && imageSel->hasContent () && imageSel->transparency ().isTransparent ()) { d->colorToolBar->flashColorSimilarityToolBarItem (); } kpAbstractSelection *selInUsefulPos = sel.clone (); - if (!forceTopLeft) + if (!forceTopLeft) { selInUsefulPos->moveTo (calcUsefulPasteRect (sel.width (), sel.height ()).topLeft ()); + } // TODO: Should use kpCommandHistory::addCreateSelectionCommand(), // as well, to really support pasting selection borders. addDeselectFirstCommand (new kpToolSelectionCreateCommand ( @@ -362,8 +362,7 @@ qCDebug(kpLogMainWindow) << "sel.size=" << QSize (sel.width (), sel.height ()) << " document.size=" - << QSize (d->document->width (), d->document->height ()) - << endl; + << QSize (d->document->width (), d->document->height ()); // If the selection is bigger than the document, automatically // resize the document (with the option of Undo'ing) to fit @@ -394,10 +393,11 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::pasteText(" << text << ",forceNewTextSelection=" << forceNewTextSelection << ",newTextSelectionTopLeft=" << newTextSelectionTopLeft - << ")" << endl; + << ")"; - if ( text.isEmpty() ) + if ( text.isEmpty() ) { return; + } kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); @@ -473,17 +473,19 @@ const QFontMetrics fontMetrics = ts.fontMetrics (); int height = textLines.size () * fontMetrics.height (); - if (textLines.size () >= 1) + if (textLines.size () >= 1) { height += (textLines.size () - 1) * fontMetrics.leading (); + } int width = 0; for (QList ::const_iterator it = textLines.constBegin (); it != textLines.constEnd (); ++it) { const int w = fontMetrics.width (*it); - if (w > width) + if (w > width) { width = w; + } } // limit the size to avoid memory overflow @@ -520,7 +522,7 @@ << ",point=" << point << ",allowNewTextSelectionPointShift=" << allowNewTextSelectionPointShift - << ")" << endl; + << ")"; kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); @@ -616,7 +618,7 @@ // Requirement 2. transparent pixels in the image must remain as transparent. // - kpMainWindow *win = new kpMainWindow (nullptr/*no document*/); + auto *win = new kpMainWindow (nullptr/*no document*/); win->show (); // Make "Edit / Paste in New Window" always paste white pixels as white. @@ -681,16 +683,18 @@ toolEndShape (); - if (d->document->selection ()) + if (d->document->selection ()) { slotDeselect (); + } // just the border - don't actually pull image from doc yet d->document->setSelection ( kpRectangularImageSelection (d->document->rect (), imageSelectionTransparency ())); - if (tool ()) + if (tool ()) { tool ()->somethingBelowTheCursorChanged (); + } } //--------------------------------------------------------------------- @@ -700,8 +704,7 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::addDeselectFirstCommand(" << cmd - << ")" - << endl; + << ")"; kpAbstractSelection *sel = d->document->selection (); @@ -716,11 +719,13 @@ { qCDebug(kpLogMainWindow) << "\tjust a fresh border - was nop - delete"; d->document->selectionDelete (); - if (tool ()) + if (tool ()) { tool ()->somethingBelowTheCursorChanged (); + } - if (cmd) + if (cmd) { d->commandHistory->addCommand (cmd); + } } else { @@ -740,14 +745,16 @@ macroCmd->addCommand (cmd); d->commandHistory->addCommand (macroCmd); } - else + else { d->commandHistory->addCommand (deselectCommand); + } } } else { - if (cmd) + if (cmd) { d->commandHistory->addCommand (cmd); + } } } @@ -774,8 +781,9 @@ toolEndShape (); - if (!d->document->selection ()) + if (!d->document->selection ()) { return; + } kpImage imageToSave; @@ -790,15 +798,17 @@ // image. imageToSave = d->document->getSelectedBaseImage (); } - else + else { imageToSave = imageSel->transparentImage (); + } } else if (d->document->textSelection ()) { imageToSave = d->document->textSelection ()->approximateImage (); } - else + else { Q_ASSERT (!"Unknown selection type"); + } kpDocumentSaveOptions chosenSaveOptions; @@ -815,8 +825,9 @@ &allowOverwritePrompt, &allowLossyPrompt); - if (chosenURL.isEmpty ()) + if (chosenURL.isEmpty ()) { return; + } if (!kpDocument::savePixmapToFile (imageToSave, @@ -852,17 +863,19 @@ QList urls = askForOpenURLs(i18nc ("@title:window", "Paste From File"), false/*only 1 URL*/); - if (urls.count () != 1) + if (urls.count () != 1) { return; + } QUrl url = urls.first (); kpImage image = kpDocument::getPixmapFromFile (url, false/*show error message if doesn't exist*/, this); - if (image.isNull ()) + if (image.isNull ()) { return; + } addRecentURL (url); diff --git a/mainWindow/kpMainWindow_File.cpp b/mainWindow/kpMainWindow_File.cpp --- a/mainWindow/kpMainWindow_File.cpp +++ b/mainWindow/kpMainWindow_File.cpp @@ -189,7 +189,7 @@ // To avoid the crash, make a copy of it before calling // loadEntries() and use this copy, instead of the to-be-dangling // ref. - const QUrl url = url_; + const QUrl& url = url_; qCDebug(kpLogMainWindow) << "kpMainWindow::addRecentURL(" << url << ")"; if (url.isEmpty ()) @@ -220,10 +220,10 @@ // TODO: Is this loop safe since a KMainWindow later along in the list, // could be closed as the code in the body almost certainly re-enters // the event loop? Problem for KDE 3 as well, I think. - foreach (KMainWindow *kmw, KMainWindow::memberList ()) + for (auto *kmw : KMainWindow::memberList ()) { Q_ASSERT (dynamic_cast (kmw)); - kpMainWindow *mw = static_cast (kmw); + auto *mw = dynamic_cast (kmw); qCDebug(kpLogMainWindow) << "\t\tmw=" << mw; @@ -239,7 +239,7 @@ mw->d->actionOpenRecent->loadEntries (cfg->group (kpSettingsGroupRecentFiles)); qCDebug(kpLogMainWindow) << "\t\t\tcheck recent URLs=" - << mw->d->actionOpenRecent->items () << endl; + << mw->d->actionOpenRecent->items (); } } } @@ -260,7 +260,7 @@ // A document -- empty or otherwise -- is open. // Force open a new window. In contrast, open() might not open // a new window in this case. - kpMainWindow *win = new kpMainWindow (); + auto *win = new kpMainWindow (); win->show (); } else @@ -340,7 +340,7 @@ !d->configOpenImagesInSameWindow) { // Send doc to new window. - kpMainWindow *win = new kpMainWindow (doc); + auto *win = new kpMainWindow (doc); win->show (); } else @@ -363,9 +363,9 @@ return nullptr; // Create/open doc. - kpDocument *newDoc = new kpDocument (fallbackDocSize.width (), - fallbackDocSize.height (), - documentEnvironment ()); + auto *newDoc = new kpDocument (fallbackDocSize.width (), + fallbackDocSize.height (), documentEnvironment ()); + if (!newDoc->open (url, newDocSameNameIfNotExist)) { qCDebug(kpLogMainWindow) << "\topen failed"; @@ -387,7 +387,7 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::open(" << url << ",newDocSameNameIfNotExist=" << newDocSameNameIfNotExist - << ")" << endl; + << ")"; kpDocument *newDoc = openInternal (url, defaultDocSize (), @@ -398,10 +398,8 @@ addRecentURL (url); return true; } - else - { - return false; - } + + return false; } //--------------------------------------------------------------------- @@ -412,10 +410,11 @@ QMimeDatabase db; QStringList filterList; QString filter; - foreach(const QByteArray &type, QImageReader::supportedMimeTypes()) + for (const auto &type : QImageReader::supportedMimeTypes()) { - if ( !filter.isEmpty() ) + if ( !filter.isEmpty() ) { filter += QLatin1Char(' '); + } QMimeType mime(db.mimeTypeForName(QString::fromLatin1(type))); if ( mime.isValid() ) @@ -439,13 +438,15 @@ fd.setOption(QFileDialog::HideNameFilterDetails); fd.setWindowTitle(caption); - if ( allowMultipleURLs ) + if ( allowMultipleURLs ) { fd.setFileMode(QFileDialog::ExistingFiles); + } - if ( fd.exec() ) + if ( fd.exec() ) { return fd.selectedUrls(); - else - return QList(); + } + + return QList(); } //--------------------------------------------------------------------- @@ -457,11 +458,9 @@ const QList urls = askForOpenURLs(i18nc("@title:window", "Open Image")); - for (QList::const_iterator it = urls.begin (); - it != urls.end (); - ++it) + for (const auto & url : urls) { - open (*it); + open (url); } } @@ -540,8 +539,9 @@ // scan dialogs are shown. We don't do this between KScanDialog::setup() // and KScanDialog::exec() as it could be confusing alternating between // scanning and KolourPaint dialogs. - if (!shouldOpen ()) + if (!shouldOpen ()) { return; + } qCDebug(kpLogMainWindow) << "\tcalling setup"; @@ -599,8 +599,7 @@ kpDocument::getDataFromImage(image, saveOptions, metaInfo); // Create document from image and meta info. - kpDocument *doc = new kpDocument (image.width (), image.height (), - documentEnvironment ()); + auto *doc = new kpDocument (image.width (), image.height (), documentEnvironment ()); doc->setImage (image); doc->setSaveOptions (saveOptions); doc->setMetaInfo (metaInfo); @@ -616,22 +615,22 @@ { toolEndShape(); - QDialog *dialog = new QDialog(this); - QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | + auto *dialog = new QDialog(this); + auto *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog); connect (buttons, &QDialogButtonBox::accepted, dialog, &QDialog::accept); connect (buttons, &QDialogButtonBox::rejected, dialog, &QDialog::reject); - QLabel *label = new QLabel(i18n("Snapshot Delay")); - KPluralHandlingSpinBox *seconds = new KPluralHandlingSpinBox; + auto *label = new QLabel(i18n("Snapshot Delay")); + auto *seconds = new KPluralHandlingSpinBox; seconds->setRange(0, 99); seconds->setSuffix(ki18np(" second", " seconds")); seconds->setSpecialValueText(i18n("No delay")); - QCheckBox *hideWindow = new QCheckBox(i18n("Hide Main Window")); + auto *hideWindow = new QCheckBox(i18n("Hide Main Window")); hideWindow->setChecked(true); - QVBoxLayout *vbox = new QVBoxLayout(dialog); + auto *vbox = new QVBoxLayout(dialog); vbox->addWidget(label); vbox->addWidget(seconds); vbox->addWidget(hideWindow); @@ -643,8 +642,9 @@ return; } - if ( hideWindow->isChecked() ) + if ( hideWindow->isChecked() ) { hide(); + } // at least 1 seconds to make sure the window is hidden and the hide effect already stopped QTimer::singleShot((seconds->value() + 1) * 1000, this, SLOT(slotMakeScreenshot())); @@ -659,7 +659,7 @@ QCoreApplication::processEvents(); QPixmap pixmap = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId()); - kpDocument *doc = new kpDocument(pixmap.width(), pixmap.height(), documentEnvironment()); + auto *doc = new kpDocument(pixmap.width(), pixmap.height(), documentEnvironment()); doc->setImage(pixmap.toImage()); // Send document to current or new window. @@ -703,17 +703,15 @@ { return saveAs (localOnly); } - else + + if (d->document->save (false/*no overwrite prompt*/, + !d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) { - if (d->document->save (false/*no overwrite prompt*/, - !d->document->savedAtLeastOnceBefore ()/*lossy prompt*/)) - { - addRecentURL (d->document->url ()); - return true; - } - else - return false; + addRecentURL (d->document->url ()); + return true; } + + return false; } //--------------------------------------------------------------------- @@ -761,37 +759,41 @@ KConfigGroup cfg (KSharedConfig::openConfig (), forcedSaveOptionsGroup); - if (chosenSaveOptions) + if (chosenSaveOptions) { *chosenSaveOptions = kpDocumentSaveOptions (); + } - if (allowOverwritePrompt) + if (allowOverwritePrompt) { *allowOverwritePrompt = true; // play it safe for now + } - if (allowLossyPrompt) + if (allowLossyPrompt) { *allowLossyPrompt = true; // play it safe for now + } kpDocumentSaveOptions fdSaveOptions = startSaveOptions; QStringList mimeTypes; - foreach(const QByteArray &type, QImageWriter::supportedMimeTypes()) + for (const auto &type : QImageWriter::supportedMimeTypes()) { mimeTypes << QString::fromLatin1(type); + } qCDebug(kpLogMainWindow) << "\tmimeTypes=" << mimeTypes - << "\tsortedMimeTypes=" << endl; + << "\tsortedMimeTypes="; if (mimeTypes.isEmpty ()) { - qCCritical(kpLogMainWindow) << "No output mimetypes!" << endl; + qCCritical(kpLogMainWindow) << "No output mimetypes!"; return QUrl (); } #define MIME_TYPE_IS_VALID() (!fdSaveOptions.mimeTypeIsInvalid () && \ mimeTypes.contains (fdSaveOptions.mimeType ())) if (!MIME_TYPE_IS_VALID ()) { qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () - << " not valid, get default" << endl; + << " not valid, get default"; SETUP_READ_CFG (); @@ -801,13 +803,16 @@ if (!MIME_TYPE_IS_VALID ()) { qCDebug(kpLogMainWindow) << "\tmimeType=" << fdSaveOptions.mimeType () - << " not valid, get hardcoded" << endl; - if (mimeTypes.contains ("image/png")) + << " not valid, get hardcoded"; + if (mimeTypes.contains ("image/png")) { fdSaveOptions.setMimeType ("image/png"); - else if (mimeTypes.contains ("image/bmp")) + } + else if (mimeTypes.contains ("image/bmp")) { fdSaveOptions.setMimeType ("image/bmp"); - else + } + else { fdSaveOptions.setMimeType (mimeTypes.first ()); + } } } #undef MIME_TYPE_IS_VALID @@ -828,7 +833,7 @@ } fdSaveOptions.printDebug ("\tcorrected saveOptions passed to fileDialog"); - kpDocumentSaveOptionsWidget *saveOptionsWidget = + auto *saveOptionsWidget = new kpDocumentSaveOptionsWidget (imageToBeSaved, fdSaveOptions, docMetaInfo, @@ -840,8 +845,9 @@ fd.setWindowTitle (caption); fd.setOperationMode (KFileDialog::Saving); fd.setMimeFilter (mimeTypes, fdSaveOptions.mimeType ()); - if (localOnly) + if (localOnly) { fd.setMode (KFile::File | KFile::LocalOnly); + } connect (&fd, &KFileDialog::filterChanged, saveOptionsWidget, &kpDocumentSaveOptionsWidget::setMimeType); @@ -859,8 +865,9 @@ cfg.sync (); - if (chosenSaveOptions) + if (chosenSaveOptions) { *chosenSaveOptions = newSaveOptions; + } bool shouldAllowOverwritePrompt = @@ -890,8 +897,8 @@ qCDebug(kpLogMainWindow) << "\tselectedUrl=" << fd.selectedUrl (); return fd.selectedUrl (); } - else - return QUrl (); + + return QUrl (); #undef SETUP_READ_CFG } @@ -915,8 +922,9 @@ &allowLossyPrompt); - if (chosenURL.isEmpty ()) + if (chosenURL.isEmpty ()) { return false; + } if (!d->document->saveAs (chosenURL, chosenSaveOptions, @@ -964,8 +972,9 @@ &allowLossyPrompt); - if (chosenURL.isEmpty ()) + if (chosenURL.isEmpty ()) { return false; + } if (!kpDocument::savePixmapToFile (d->document->imageWithSelection (), chosenURL, @@ -1034,8 +1043,9 @@ KGuiItem(i18n ("&Reload"))); } - if (result != KMessageBox::Continue) + if (result != KMessageBox::Continue) { return false; + } } @@ -1085,14 +1095,14 @@ dot = fileName.lastIndexOf ('.'); // file.ext but not .hidden-file? - if (dot > 0) + if (dot > 0) { fileName.truncate (dot); + } qCDebug(kpLogMainWindow) << "kpMainWindow::sendDocumentNameToPrinter() fileName=" << fileName << " dir=" - << url.path() - << endl; + << url.path(); printer->setDocName (fileName); } } @@ -1114,16 +1124,13 @@ // Get image DPI. - double imageDotsPerMeterX = - double (d->document->metaInfo ()->dotsPerMeterX ()); - double imageDotsPerMeterY = - double (d->document->metaInfo ()->dotsPerMeterY ()); + auto imageDotsPerMeterX = double (d->document->metaInfo ()->dotsPerMeterX ()); + auto imageDotsPerMeterY = double (d->document->metaInfo ()->dotsPerMeterY ()); qCDebug(kpLogMainWindow) << "kpMainWindow::sendImageToPrinter() image:" << " width=" << image.width () << " height=" << image.height () << " dotsPerMeterX=" << imageDotsPerMeterX - << " dotsPerMeterY=" << imageDotsPerMeterY - << endl; + << " dotsPerMeterY=" << imageDotsPerMeterY; // Image DPI invalid (e.g. new image, could not read from file // or Qt3 doesn't implement DPI for JPEG)? @@ -1152,8 +1159,8 @@ // TODO: mysteriously, someone else is setting this to 96dpi always. QPixmap arbitraryScreenElement(1, 1); const QPaintDevice *screenDevice = &arbitraryScreenElement; - const int dpiX = screenDevice->logicalDpiX (), - dpiY = screenDevice->logicalDpiY (); + const auto dpiX = screenDevice->logicalDpiX (); + const auto dpiY = screenDevice->logicalDpiY (); qCDebug(kpLogMainWindow) << "\tusing screen dpi: x=" << dpiX << " y=" << dpiY; imageDotsPerMeterX = dpiX * KP_INCHES_PER_METER; @@ -1168,41 +1175,37 @@ // m m m = margin // m m // mmmmm - const int printerWidthMM = printer->widthMM (); - const int printerHeightMM = printer->heightMM (); + const auto printerWidthMM = printer->widthMM (); + const auto printerHeightMM = printer->heightMM (); qCDebug(kpLogMainWindow) << "\tprinter: widthMM=" << printerWidthMM - << " heightMM=" << printerHeightMM - << endl; + << " heightMM=" << printerHeightMM; - double dpiX = imageDotsPerMeterX / KP_INCHES_PER_METER; - double dpiY = imageDotsPerMeterY / KP_INCHES_PER_METER; + auto dpiX = imageDotsPerMeterX / KP_INCHES_PER_METER; + auto dpiY = imageDotsPerMeterY / KP_INCHES_PER_METER; qCDebug(kpLogMainWindow) << "\timage: dpiX=" << dpiX << " dpiY=" << dpiY; # // // If image doesn't fit on page at intended DPI, change the DPI. // - const double scaleDpiX = - (image.width () / (printerWidthMM / KP_MILLIMETERS_PER_INCH)) - / dpiX; - const double scaleDpiY = - (image.height () / (printerHeightMM / KP_MILLIMETERS_PER_INCH)) - / dpiY; - const double scaleDpi = qMax (scaleDpiX, scaleDpiY); + const auto scaleDpiX = + (image.width () / (printerWidthMM / KP_MILLIMETERS_PER_INCH)) / dpiX; + const auto scaleDpiY = + (image.height () / (printerHeightMM / KP_MILLIMETERS_PER_INCH)) / dpiY; + const auto scaleDpi = qMax (scaleDpiX, scaleDpiY); qCDebug(kpLogMainWindow) << "\t\tscaleDpi: x=" << scaleDpiX << " y=" << scaleDpiY - << " --> scale at " << scaleDpi << " to fit?" - << endl; + << " --> scale at " << scaleDpi << " to fit?"; // Need to increase resolution to fit page? if (scaleDpi > 1.0) { dpiX *= scaleDpi; dpiY *= scaleDpi; qCDebug(kpLogMainWindow) << "\t\t\tto fit page, scaled to:" - << " dpiX=" << dpiX << " dpiY=" << dpiY << endl; + << " dpiX=" << dpiX << " dpiY=" << dpiY; } @@ -1214,7 +1217,7 @@ if (dpiX > dpiY) { qCDebug(kpLogMainWindow) << "\tdpiX > dpiY; stretching image height to equalise DPIs to dpiX=" - << dpiX << endl; + << dpiX; kpPixmapFX::scale (&image, image.width (), qMax (1, qRound (image.height () * dpiX / dpiY)), @@ -1225,7 +1228,7 @@ else if (dpiY > dpiX) { qCDebug(kpLogMainWindow) << "\tdpiY > dpiX; stretching image width to equalise DPIs to dpiY=" - << dpiY << endl; + << dpiY; kpPixmapFX::scale (&image, qMax (1, qRound (image.width () * dpiY / dpiX)), image.height (), @@ -1246,7 +1249,7 @@ if (showPrinterSetupDialog) { - kpPrintDialogPage *optionsPage = new kpPrintDialogPage (this); + auto *optionsPage = new kpPrintDialogPage (this); optionsPage->setPrintImageCenteredOnPage (d->configPrintImageCenteredOnPage); QPrintDialog *printDialog = @@ -1273,8 +1276,9 @@ delete printDialog; - if (!wantToPrint) + if (!wantToPrint) { return; + } } @@ -1369,8 +1373,9 @@ { toolEndShape (); - if (!d->document || !d->document->isModified ()) + if (!d->document || !d->document->isModified ()) { return true; // ok to close current doc + } int result = KMessageBox::warningYesNoCancel (this, i18n ("The document \"%1\" has been modified.\n" @@ -1400,11 +1405,13 @@ #endif toolEndShape (); - if (!queryCloseDocument ()) + if (!queryCloseDocument ()) { return false; + } - if (!queryCloseColors ()) + if (!queryCloseColors ()) { return false; + } return true; } @@ -1416,8 +1423,9 @@ { toolEndShape (); - if (!queryCloseDocument ()) + if (!queryCloseDocument ()) { return; + } setDocument (nullptr); } diff --git a/mainWindow/kpMainWindow_Image.cpp b/mainWindow/kpMainWindow_Image.cpp --- a/mainWindow/kpMainWindow_Image.cpp +++ b/mainWindow/kpMainWindow_Image.cpp @@ -235,15 +235,17 @@ "Select&ion"); Q_ASSERT (menuBar ()); - foreach (QAction *action, menuBar ()->actions ()) + for (auto *action : menuBar ()->actions ()) { if (action->text () == MenuBarItemTextImage || action->text () == MenuBarItemTextSelection) { - if (isSelectionActive ()) + if (isSelectionActive ()) { action->setText (MenuBarItemTextSelection); - else + } + else { action->setText (MenuBarItemTextImage); + } break; } @@ -276,13 +278,12 @@ // public kpColor kpMainWindow::backgroundColor (bool ofSelection) const { - if (ofSelection) + if (ofSelection) { return kpColor::Transparent; - else - { - Q_ASSERT (d->colorToolBar); - return d->colorToolBar->backgroundColor (); } + + Q_ASSERT (d->colorToolBar); + return d->colorToolBar->backgroundColor (); } //--------------------------------------------------------------------- @@ -295,30 +296,32 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::addImageOrSelectionCommand()" << " addSelCreateCmdIfSelAvail=" << addSelCreateCmdIfSelAvail - << " addSelContentCmdIfSelAvail=" << addSelContentCmdIfSelAvail - << endl; + << " addSelContentCmdIfSelAvail=" << addSelContentCmdIfSelAvail; Q_ASSERT (d->document); - if (d->viewManager) + if (d->viewManager) { d->viewManager->setQueueUpdates (); + } kpAbstractSelection *sel = d->document->selection (); qCDebug(kpLogMainWindow) << "\timage sel=" << sel - << " sel->hasContent=" << (sel ? sel->hasContent () : 0) - << endl; + << " sel->hasContent=" << (sel ? sel->hasContent () : 0); if (addSelCreateCmdIfSelAvail && sel && !sel->hasContent ()) { QString createCmdName; - if (dynamic_cast (sel)) + if (dynamic_cast (sel)) { createCmdName = i18n ("Selection: Create"); - else if (dynamic_cast (sel)) + } + else if (dynamic_cast (sel)) { createCmdName = i18n ("Text: Create Box"); - else + } + else { Q_ASSERT (!"Unknown selection type"); + } // create selection region commandHistory ()->addCreateSelectionCommand ( @@ -332,13 +335,12 @@ if (addSelContentCmdIfSelAvail && sel && !sel->hasContent ()) { - kpAbstractImageSelection *imageSel = - dynamic_cast (sel); - kpTextSelection *textSel = - dynamic_cast (sel); + auto *imageSel = dynamic_cast (sel); + auto *textSel = dynamic_cast (sel); - if (imageSel && imageSel->transparency ().isTransparent ()) + if (imageSel && imageSel->transparency ().isTransparent ()) { d->colorToolBar->flashColorSimilarityToolBarItem (); + } kpMacroCommand *macroCmd = new kpMacroCommand (cmd->name (), commandEnvironment ()); @@ -360,8 +362,9 @@ QString()/*uninteresting child of macro cmd*/, commandEnvironment ())); } - else + else { Q_ASSERT (!"Unknown selection type"); + } macroCmd->addCommand (cmd); @@ -373,8 +376,9 @@ } - if (d->viewManager) + if (d->viewManager) { d->viewManager->restoreQueueUpdates (); + } } //--------------------------------------------------------------------- @@ -388,7 +392,7 @@ if (dialog.exec () && !dialog.isNoOp ()) { - kpTransformResizeScaleCommand *cmd = new kpTransformResizeScaleCommand ( + auto *cmd = new kpTransformResizeScaleCommand ( dialog.actOnSelection (), dialog.imageWidth (), dialog.imageHeight (), dialog.type (), diff --git a/mainWindow/kpMainWindow_Settings.cpp b/mainWindow/kpMainWindow_Settings.cpp --- a/mainWindow/kpMainWindow_Settings.cpp +++ b/mainWindow/kpMainWindow_Settings.cpp @@ -68,7 +68,7 @@ connect (d->actionShowPath, &QAction::triggered, this, &kpMainWindow::slotShowPathToggled); slotEnableSettingsShowPath (); - KToggleAction *action = ac->add("settings_draw_antialiased"); + auto *action = ac->add("settings_draw_antialiased"); action->setText(i18n("Draw Anti-Aliased")); action->setChecked(kpToolEnvironment::drawAntiAliased); connect (action, &KToggleAction::triggered, this, &kpMainWindow::slotDrawAntiAliasedToggled); diff --git a/mainWindow/kpMainWindow_StatusBar.cpp b/mainWindow/kpMainWindow_StatusBar.cpp --- a/mainWindow/kpMainWindow_StatusBar.cpp +++ b/mainWindow/kpMainWindow_StatusBar.cpp @@ -109,11 +109,11 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::setStatusBarMessage(" << message - << ") ok=" << d->statusBarCreated - << endl; + << ") ok=" << d->statusBarCreated; - if (!d->statusBarCreated) + if (!d->statusBarCreated) { return; + } d->statusBarMessageLabel->setText (message); } @@ -126,11 +126,11 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::setStatusBarShapePoints(" << startPoint << "," << endPoint - << ") ok=" << d->statusBarCreated - << endl; + << ") ok=" << d->statusBarCreated; - if (!d->statusBarCreated) + if (!d->statusBarCreated) { return; + } if (d->statusBarShapeLastPointsInitialised && startPoint == d->statusBarShapeLastStartPoint && @@ -173,12 +173,12 @@ #if DEBUG_STATUS_BAR && 0 qCDebug(kpLogMainWindow) << "kpMainWindow::setStatusBarShapeSize(" << size - << ") ok=" << d->statusBarCreated - << endl; + << ") ok=" << d->statusBarCreated; #endif - if (!d->statusBarCreated) + if (!d->statusBarCreated) { return; + } if (d->statusBarShapeLastSizeInitialised && size == d->statusBarShapeLastSize) @@ -212,11 +212,11 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::setStatusBarDocSize(" << size - << ") ok=" << d->statusBarCreated - << endl; + << ") ok=" << d->statusBarCreated; - if (!d->statusBarCreated) + if (!d->statusBarCreated) { return; + } QLabel *statusBarLabel = d->statusBarLabels.at (StatusBarItemDocSize); if (size == KP_INVALID_SIZE) @@ -238,11 +238,11 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::setStatusBarDocDepth(" << depth - << ") ok=" << d->statusBarCreated - << endl; + << ") ok=" << d->statusBarCreated; - if (!d->statusBarCreated) + if (!d->statusBarCreated) { return; + } QLabel *statusBarLabel = d->statusBarLabels.at (StatusBarItemDocDepth); if (depth <= 0) @@ -262,11 +262,11 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::setStatusBarZoom(" << zoom - << ") ok=" << d->statusBarCreated - << endl; + << ") ok=" << d->statusBarCreated; - if (!d->statusBarCreated) + if (!d->statusBarCreated) { return; + } QLabel *statusBarLabel = d->statusBarLabels.at (StatusBarItemZoom); if (zoom <= 0) @@ -286,11 +286,9 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::recalculateStatusBarMessage()"; QString scrollViewMessage = d->scrollView->statusMessage (); qCDebug(kpLogMainWindow) << "\tscrollViewMessage=" << scrollViewMessage; - qCDebug(kpLogMainWindow) << "\tresizing doc? " << !d->scrollView->newDocSize ().isEmpty () - << endl; + qCDebug(kpLogMainWindow) << "\tresizing doc? " << !d->scrollView->newDocSize ().isEmpty (); qCDebug(kpLogMainWindow) << "\tviewUnderCursor? " - << (d->viewManager && d->viewManager->viewUnderCursor ()) - << endl; + << (d->viewManager && d->viewManager->viewUnderCursor ()); // HACK: To work around kpViewScrollableContainer's unreliable // status messages (which in turn is due to Qt not updating @@ -300,8 +298,7 @@ d->viewManager && d->viewManager->viewUnderCursor ()) { #if DEBUG_STATUS_BAR && 1 - qCDebug(kpLogMainWindow) << "\t\tnot resizing & viewUnderCursor - message is wrong - clearing" - << endl; + qCDebug(kpLogMainWindow) << "\t\tnot resizing & viewUnderCursor - message is wrong - clearing"; #endif d->scrollView->blockSignals (true); d->scrollView->clearStatusMessage (); @@ -344,7 +341,7 @@ { const QPoint startPoint (d->document->width (), d->document->height ()); qCDebug(kpLogMainWindow) << "\thavedMovedFromOrgSize=" - << d->scrollView->haveMovedFromOriginalDocSize () << endl; + << d->scrollView->haveMovedFromOriginalDocSize (); if (!d->scrollView->haveMovedFromOriginalDocSize ()) { setStatusBarShapePoints (startPoint); @@ -384,11 +381,11 @@ void kpMainWindow::recalculateStatusBar () { qCDebug(kpLogMainWindow) << "kpMainWindow::recalculateStatusBar() ok=" - << d->statusBarCreated - << endl; + << d->statusBarCreated; - if (!d->statusBarCreated) + if (!d->statusBarCreated) { return; + } recalculateStatusBarMessage (); recalculateStatusBarShape (); diff --git a/mainWindow/kpMainWindow_Text.cpp b/mainWindow/kpMainWindow_Text.cpp --- a/mainWindow/kpMainWindow_Text.cpp +++ b/mainWindow/kpMainWindow_Text.cpp @@ -150,11 +150,11 @@ << "fontFamily=" << d->actionTextFontFamily->font () << "action.currentItem=" - << d->actionTextFontFamily->currentItem () - << endl; + << d->actionTextFontFamily->currentItem (); - if (!d->isFullyConstructed) + if (!d->isFullyConstructed) { return; + } if (d->toolText && d->toolText->hasBegun ()) { @@ -165,8 +165,9 @@ // Since editable KSelectAction's steal focus from view, switch back to mainView // TODO: back to the last view - if (d->mainView) + if (d->mainView) { d->mainView->setFocus (); + } KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupText); cfg.writeEntry (kpSettingFontFamily, d->actionTextFontFamily->font ()); @@ -181,11 +182,11 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::slotTextFontSizeChanged() alive=" << d->isFullyConstructed << " fontSize=" - << d->actionTextFontSize->fontSize () - << endl; + << d->actionTextFontSize->fontSize (); - if (!d->isFullyConstructed) + if (!d->isFullyConstructed) { return; + } if (d->toolText && d->toolText->hasBegun ()) { @@ -196,8 +197,9 @@ // Since editable KSelectAction's steal focus from view, switch back to mainView // TODO: back to the last view - if (d->mainView) + if (d->mainView) { d->mainView->setFocus (); + } KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupText); cfg.writeEntry (kpSettingFontSize, d->actionTextFontSize->fontSize ()); @@ -212,11 +214,11 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::slotTextFontBoldChanged() alive=" << d->isFullyConstructed << " bold=" - << d->actionTextBold->isChecked () - << endl; + << d->actionTextBold->isChecked (); - if (!d->isFullyConstructed) + if (!d->isFullyConstructed) { return; + } if (d->toolText && d->toolText->hasBegun ()) { @@ -235,11 +237,11 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::slotTextFontItalicChanged() alive=" << d->isFullyConstructed << " bold=" - << d->actionTextItalic->isChecked () - << endl; + << d->actionTextItalic->isChecked (); - if (!d->isFullyConstructed) + if (!d->isFullyConstructed) { return; + } if (d->toolText && d->toolText->hasBegun ()) { @@ -258,11 +260,11 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::slotTextFontUnderlineChanged() alive=" << d->isFullyConstructed << " underline=" - << d->actionTextUnderline->isChecked () - << endl; + << d->actionTextUnderline->isChecked (); - if (!d->isFullyConstructed) + if (!d->isFullyConstructed) { return; + } if (d->toolText && d->toolText->hasBegun ()) { @@ -281,11 +283,11 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::slotTextStrikeThruChanged() alive=" << d->isFullyConstructed << " strikeThru=" - << d->actionTextStrikeThru->isChecked () - << endl; + << d->actionTextStrikeThru->isChecked (); - if (!d->isFullyConstructed) + if (!d->isFullyConstructed) { return; + } if (d->toolText && d->toolText->hasBegun ()) { diff --git a/mainWindow/kpMainWindow_Tools.cpp b/mainWindow/kpMainWindow_Tools.cpp --- a/mainWindow/kpMainWindow_Tools.cpp +++ b/mainWindow/kpMainWindow_Tools.cpp @@ -75,8 +75,9 @@ // private kpToolSelectionEnvironment *kpMainWindow::toolSelectionEnvironment () { - if (!d->toolSelectionEnvironment) + if (!d->toolSelectionEnvironment) { d->toolSelectionEnvironment = new kpToolSelectionEnvironment (this); + } return d->toolSelectionEnvironment; } @@ -191,8 +192,9 @@ updateActionDrawOpaqueChecked (); - foreach (kpTool *tool, d->tools) + for (auto *tool : d->tools) { d->toolToolBar->registerTool(tool); + } // (from config file) readLastTool (); @@ -213,14 +215,17 @@ // select tool for enabled Tool Box - if (previousTool) + if (previousTool) { d->toolToolBar->selectPreviousTool (); + } else { - if (d->lastToolNumber >= 0 && d->lastToolNumber < d->tools.count ()) + if (d->lastToolNumber >= 0 && d->lastToolNumber < d->tools.count ()) { d->toolToolBar->selectTool (d->tools.at (d->lastToolNumber)); - else + } + else { d->toolToolBar->selectTool (d->toolPen); + } } } else if (!enable && d->toolToolBar->isEnabled ()) @@ -233,11 +238,12 @@ d->toolToolBar->setEnabled (enable); - foreach (kpTool *tool, d->tools) + for (auto *tool : d->tools) { kpToolAction *action = tool->action(); - if (!enable && action->isChecked()) + if (!enable && action->isChecked()) { action->setChecked(false); + } action->setEnabled(enable); } @@ -294,9 +300,8 @@ const bool enable = d->toolActionsEnabled; qCDebug(kpLogMainWindow) << "\tenable=" << enable - << " tool=" << (tool () ? tool ()->objectName () : 0) - << " (is selection=" << toolIsASelectionTool () << ")" - << endl; + << " tool=" << (tool () ? tool ()->objectName () : nullptr) + << " (is selection=" << toolIsASelectionTool () << ")"; d->actionDrawOpaque->setEnabled (enable && toolIsASelectionTool ()); } @@ -306,8 +311,9 @@ // public QActionGroup *kpMainWindow::toolsActionGroup () { - if (!d->toolsActionGroup) + if (!d->toolsActionGroup) { d->toolsActionGroup = new QActionGroup (this); + } return d->toolsActionGroup; } @@ -356,8 +362,9 @@ // private void kpMainWindow::toolEndShape () { - if (toolHasBegunShape ()) + if (toolHasBegunShape ()) { tool ()->endShapeInternal (); + } } //--------------------------------------------------------------------- @@ -377,9 +384,8 @@ void kpMainWindow::setImageSelectionTransparency (const kpImageSelectionTransparency &transparency, bool forceColorChange) { qCDebug(kpLogMainWindow) << "kpMainWindow::setImageSelectionTransparency() isOpaque=" << transparency.isOpaque () - << " color=" << (transparency.transparentColor ().isValid () ? (int *) transparency.transparentColor ().toQRgb () : 0) - << " forceColorChange=" << forceColorChange - << endl; + << " color=" << (transparency.transparentColor ().isValid () ? (int *) transparency.transparentColor ().toQRgb () : nullptr) + << " forceColorChange=" << forceColorChange; kpToolWidgetOpaqueOrTransparent *oot = d->toolToolBar->toolWidgetOpaqueOrTransparent (); Q_ASSERT (oot); @@ -513,8 +519,9 @@ it != d->tools.constEnd (); ++it) { - if (*it == tool ()) + if (*it == tool ()) { return number; + } number++; } @@ -528,8 +535,9 @@ void kpMainWindow::saveLastTool () { int number = toolNumber (); - if (number < 0 || number >= d->tools.count ()) + if (number < 0 || number >= d->tools.count ()) { return; + } KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); @@ -559,17 +567,14 @@ Q_UNUSED(docLastPoint) qCDebug(kpLogMainWindow) << "kpMainWindow::slotDragScroll() maybeDragScrolling=" - << maybeDragScrollingMainView () - << endl; + << maybeDragScrollingMainView (); if (maybeDragScrollingMainView ()) { return d->scrollView->beginDragScroll(zoomLevel, scrolled); } - else - { - return false; - } + + return false; } //--------------------------------------------------------------------- @@ -678,11 +683,11 @@ void kpMainWindow::slotDocResizeMessageChanged (const QString &string) { qCDebug(kpLogMainWindow) << "kpMainWindow::slotDocResizeMessageChanged(" << string - << ") docResizeToBeCompleted=" << d->docResizeToBeCompleted - << endl; + << ") docResizeToBeCompleted=" << d->docResizeToBeCompleted; - if (d->docResizeToBeCompleted) + if (d->docResizeToBeCompleted) { return; + } recalculateStatusBarMessage (); } @@ -693,8 +698,9 @@ // private slot void kpMainWindow::slotActionPrevToolOptionGroup1 () { - if (!d->toolToolBar->shownToolWidget (0)) + if (!d->toolToolBar->shownToolWidget (0)) { return; + } // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. @@ -708,8 +714,9 @@ // private slot void kpMainWindow::slotActionNextToolOptionGroup1 () { - if (!d->toolToolBar->shownToolWidget (0)) + if (!d->toolToolBar->shownToolWidget (0)) { return; + } // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. @@ -724,8 +731,9 @@ // private slot void kpMainWindow::slotActionPrevToolOptionGroup2 () { - if (!d->toolToolBar->shownToolWidget (1)) + if (!d->toolToolBar->shownToolWidget (1)) { return; + } // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. @@ -739,8 +747,9 @@ // private slot void kpMainWindow::slotActionNextToolOptionGroup2 () { - if (!d->toolToolBar->shownToolWidget (1)) + if (!d->toolToolBar->shownToolWidget (1)) { return; + } // We don't call toolEndShape() here because we want #23 in the file BUGS // to later work. diff --git a/mainWindow/kpMainWindow_View.cpp b/mainWindow/kpMainWindow_View.cpp --- a/mainWindow/kpMainWindow_View.cpp +++ b/mainWindow/kpMainWindow_View.cpp @@ -133,8 +133,9 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::updateMainViewGrid ()"; - if (d->mainView) + if (d->mainView) { d->mainView->showGrid (d->actionShowGrid->isChecked ()); + } } //--------------------------------------------------------------------- diff --git a/mainWindow/kpMainWindow_View_Thumbnail.cpp b/mainWindow/kpMainWindow_View_Thumbnail.cpp --- a/mainWindow/kpMainWindow_View_Thumbnail.cpp +++ b/mainWindow/kpMainWindow_View_Thumbnail.cpp @@ -144,18 +144,17 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::saveThumbnailGeometry()"; - if (!d->thumbnail) + if (!d->thumbnail) { return; + } QRect rect (d->thumbnail->x (), d->thumbnail->y (), d->thumbnail->width (), d->thumbnail->height ()); qCDebug(kpLogMainWindow) << "\tthumbnail relative geometry=" << rect; d->configThumbnailGeometry = mapFromGlobal (rect); - qCDebug(kpLogMainWindow) << "\tCONFIG: saving thumbnail geometry " - << d->configThumbnailGeometry - << endl; + qCDebug(kpLogMainWindow) << "\tCONFIG: saving thumbnail geometry "; KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupThumbnail); @@ -184,10 +183,11 @@ void kpMainWindow::updateThumbnailZoomed () { qCDebug(kpLogMainWindow) << "kpMainWindow::updateThumbnailZoomed() zoomed=" - << d->actionZoomedThumbnail->isChecked () << endl; + << d->actionZoomedThumbnail->isChecked (); - if (!d->thumbnailView) + if (!d->thumbnailView) { return; + } destroyThumbnailView (); createThumbnailView (); @@ -299,27 +299,33 @@ qCDebug(kpLogMainWindow) << "\t\tgive kpThumbnail the kpView:"; - if (d->thumbnail) + if (d->thumbnail) { d->thumbnail->setView (d->thumbnailView); - else - qCCritical(kpLogMainWindow) << "kpMainWindow::createThumbnailView() no thumbnail" << endl; + } + else { + qCCritical(kpLogMainWindow) << "kpMainWindow::createThumbnailView() no thumbnail"; + } qCDebug(kpLogMainWindow) << "\t\tregistering the kpView:"; - if (d->viewManager) + if (d->viewManager) { d->viewManager->registerView (d->thumbnailView); + } } // private void kpMainWindow::destroyThumbnailView () { - if (!d->thumbnailView) + if (!d->thumbnailView) { return; + } - if (d->viewManager) + if (d->viewManager) { d->viewManager->unregisterView (d->thumbnailView); + } - if (d->thumbnail) + if (d->thumbnail) { d->thumbnail->setView (nullptr); + } d->thumbnailView->deleteLater (); d->thumbnailView = nullptr; } @@ -334,11 +340,11 @@ qCDebug(kpLogMainWindow) << "\tthumbnail=" << bool (d->thumbnail) << " action_isChecked=" - << enable - << endl; + << enable; - if (bool (d->thumbnail) == enable) + if (bool (d->thumbnail) == enable) { return; + } if (!d->thumbnail) { @@ -393,7 +399,7 @@ else { qCDebug(kpLogMainWindow) << "\tdestroying thumbnail d->thumbnail=" - << d->thumbnail << endl; + << d->thumbnail; if (d->thumbnailSaveConfigTimer && d->thumbnailSaveConfigTimer->isActive ()) { diff --git a/mainWindow/kpMainWindow_View_Zoom.cpp b/mainWindow/kpMainWindow_View_Zoom.cpp --- a/mainWindow/kpMainWindow_View_Zoom.cpp +++ b/mainWindow/kpMainWindow_View_Zoom.cpp @@ -68,10 +68,11 @@ int zoomLevel = string.toInt (&ok); qCDebug(kpLogMainWindow) << "\tzoomLevel=" << zoomLevel; - if (!ok || zoomLevel < kpView::MinZoomLevel || zoomLevel > kpView::MaxZoomLevel) + if (!ok || zoomLevel < kpView::MinZoomLevel || zoomLevel > kpView::MaxZoomLevel) { return 0; // error - else - return zoomLevel; + } + + return zoomLevel; } //--------------------------------------------------------------------- @@ -160,8 +161,9 @@ // KRecentFilesAction. bool e = d->actionZoom->isEnabled (); d->actionZoom->setItems (items); - if (e != d->actionZoom->isEnabled ()) + if (e != d->actionZoom->isEnabled ()) { d->actionZoom->setEnabled (e); + } } //--------------------------------------------------------------------- @@ -185,8 +187,9 @@ index++; } - if (zoomLevel != *it) + if (zoomLevel != *it) { d->zoomList.insert (it, zoomLevel); + } // OPT: We get called twice on startup. sendZoomListToActionZoom() is very slow. sendZoomListToActionZoom (); @@ -198,8 +201,7 @@ << " action=" << d->actionZoom->action (d->actionZoom->currentItem ()) << " checkedAction" - << d->actionZoom->selectableActionGroup ()->checkedAction () - << endl;; + << d->actionZoom->selectableActionGroup ()->checkedAction (); if (viewMenuDocumentActionsEnabled ()) @@ -212,8 +214,9 @@ // TODO: Is this actually needed? - if (d->viewManager) + if (d->viewManager) { d->viewManager->setQueueUpdates (); + } if (d->scrollView) { @@ -242,8 +245,9 @@ // The view magnified and moved beneath the cursor - if (tool ()) + if (tool ()) { tool ()->somethingBelowTheCursorChanged (); + } if (d->scrollView) @@ -253,8 +257,9 @@ d->scrollView->setUpdatesEnabled (true); } - if (d->viewManager && d->viewManager->queueUpdates ()/*just in case*/) + if (d->viewManager && d->viewManager->queueUpdates ()/*just in case*/) { d->viewManager->restoreQueueUpdates (); + } setStatusBarZoom (d->mainView ? d->mainView->zoomLevelX () : 0); @@ -279,8 +284,7 @@ << " visibleHeight=" << d->scrollView->viewport()->height () << " oldZoomX=" << d->mainView->zoomLevelX () << " oldZoomY=" << d->mainView->zoomLevelY () - << " newZoom=" << zoomLevel - << endl; + << " newZoom=" << zoomLevel; // TODO: when changing from no scrollbars to scrollbars, Qt lies about // visibleWidth() & visibleHeight() (doesn't take into account the @@ -309,8 +313,9 @@ targetDocY = vuc->transformViewToDocY (viewPoint.y ()); targetDocAvail = true; - if (vuc != d->mainView) + if (vuc != d->mainView) { viewPoint = vuc->transformViewToOtherView (viewPoint, d->mainView); + } viewX = viewPoint.x (); viewY = viewPoint.y (); @@ -333,10 +338,9 @@ d->mainView->setZoomLevel (zoomLevel, zoomLevel); qCDebug(kpLogMainWindow) << "\tvisibleWidth=" << d->scrollView->viewport()->width () - << " visibleHeight=" << d->scrollView->viewport()->height () - << endl; + << " visibleHeight=" << d->scrollView->viewport()->height (); qCDebug(kpLogMainWindow) << "\tnewCenterX=" << newCenterX - << " newCenterY=" << newCenterY << endl; + << " newCenterY=" << newCenterY; d->scrollView->horizontalScrollBar()->setValue(newCenterX - (d->scrollView->viewport()->width() / 2)); d->scrollView->verticalScrollBar()->setValue(newCenterY - (d->scrollView->viewport()->height() / 2)); @@ -351,16 +355,15 @@ kpView *const vuc = d->viewManager->viewUnderCursor (); qCDebug(kpLogMainWindow) << "\tcenterUnderCursor: reposition cursor; viewUnderCursor=" - << vuc->objectName () << endl; + << vuc->objectName (); - const double viewX = vuc->transformDocToViewX (targetDocX); - const double viewY = vuc->transformDocToViewY (targetDocY); + const auto viewX = vuc->transformDocToViewX (targetDocX); + const auto viewY = vuc->transformDocToViewY (targetDocY); // Rounding error from zooming in and out :( // TODO: do everything in terms of tool doc points in type "double". const QPoint viewPoint (static_cast (viewX), static_cast (viewY)); qCDebug(kpLogMainWindow) << "\t\tdoc: (" << targetDocX << "," << targetDocY << ")" - << " viewUnderCursor: (" << viewX << "," << viewY << ")" - << endl; + << " viewUnderCursor: (" << viewX << "," << viewY << ")"; if (vuc->visibleRegion ().contains (viewPoint)) { @@ -392,17 +395,16 @@ // on top of. else { - qCDebug(kpLogMainWindow) << "\t\twon't move cursor - would get outside view" - << endl; + qCDebug(kpLogMainWindow) << "\t\twon't move cursor - would get outside view"; // TODO: Sane cursor flashing indication that indicates // that the normal cursor movement didn't happen. } } qCDebug(kpLogMainWindow) << "\t\tcheck (contentsX=" << d->scrollView->horizontalScrollBar()->value () << ",contentsY=" << d->scrollView->verticalScrollBar()->value () - << ")" << endl; + << ")"; } @@ -472,7 +474,7 @@ qCDebug(kpLogMainWindow) << "\tzoomX=" << zoomX << " zoomY=" << zoomY - << " -> zoomLevel=" << zoomLevel << endl; + << " -> zoomLevel=" << zoomLevel; zoomToPre (zoomLevel); { @@ -554,12 +556,12 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::zoomIn(centerUnderCursor=" << centerUnderCursor << ") currentItem=" - << d->actionZoom->currentItem () - << endl; + << d->actionZoom->currentItem (); const int targetItem = d->actionZoom->currentItem () + 1; - if (targetItem >= static_cast (d->zoomList.count ())) + if (targetItem >= static_cast (d->zoomList.count ())) { return; + } d->actionZoom->setCurrentItem (targetItem); @@ -575,12 +577,12 @@ { qCDebug(kpLogMainWindow) << "kpMainWindow::zoomOut(centerUnderCursor=" << centerUnderCursor << ") currentItem=" - << d->actionZoom->currentItem () - << endl; + << d->actionZoom->currentItem (); const int targetItem = d->actionZoom->currentItem () - 1; - if (targetItem < 0) + if (targetItem < 0) { return; + } d->actionZoom->setCurrentItem (targetItem); @@ -617,8 +619,7 @@ qCDebug(kpLogMainWindow) << "kpMainWindow::zoomAccordingToZoomAction(centerUnderCursor=" << centerUnderCursor << ") currentItem=" << d->actionZoom->currentItem () - << " currentText=" << d->actionZoom->currentText () - << endl; + << " currentText=" << d->actionZoom->currentText (); // This might be a new zoom level the user has typed in. zoomTo (::ZoomLevelFromString (d->actionZoom->currentText ()), @@ -631,7 +632,7 @@ void kpMainWindow::slotZoom () { qCDebug(kpLogMainWindow) << "kpMainWindow::slotZoom () index=" << d->actionZoom->currentItem () - << " text='" << d->actionZoom->currentText () << "'" << endl; + << " text='" << d->actionZoom->currentText () << "'"; zoomAccordingToZoomAction (false/*don't center under cursor*/); } diff --git a/pixmapfx/kpPixmapFX_DrawShapes.cpp b/pixmapfx/kpPixmapFX_DrawShapes.cpp --- a/pixmapfx/kpPixmapFX_DrawShapes.cpp +++ b/pixmapfx/kpPixmapFX_DrawShapes.cpp @@ -49,13 +49,15 @@ // Returns whether there is only 1 distinct point in . bool kpPixmapFX::Only1PixelInPointArray (const QPolygon &points) { - if (points.count () == 0) + if (points.count () == 0) { return false; + } for (int i = 1; i < static_cast (points.count ()); i++) { - if (points [i] != points [0]) + if (points [i] != points [0]) { return false; + } } return true; @@ -188,11 +190,13 @@ fcolor, penWidth, fStippleColor); - if (bcolor.isValid ()) + if (bcolor.isValid ()) { p.setBrush (QBrush (bcolor.toQColor())); + } // HACK: seems to be needed if set_Pen_(Qt::color0) else fills with Qt::color0. - else + else { p.setBrush (Qt::NoBrush); + } // Qt bug: single point doesn't show up depending on penWidth. if (Only1PixelInPointArray (points)) @@ -205,11 +209,13 @@ // TODO: why aren't the ends rounded? p.drawPolygon(points, Qt::OddEvenFill); - if ( isFinal ) + if ( isFinal ) { return; + } - if ( points.count() <= 2 ) + if ( points.count() <= 2 ) { return; + } p.setCompositionMode(QPainter::RasterOp_SourceXorDestination); p.setPen(QPen(Qt::white)); @@ -243,10 +249,12 @@ const bool parity = ((dy + dx) / StippleSize) % 2; kpColor useColor; - if (!parity) + if (!parity) { useColor = color; - else + } + else { useColor = stippleColor; + } painter.fillRect (x + dx, y + dy, StippleSize, StippleSize, useColor.toQColor()); } diff --git a/pixmapfx/kpPixmapFX_GetSetPixmapParts.cpp b/pixmapfx/kpPixmapFX_GetSetPixmapParts.cpp --- a/pixmapfx/kpPixmapFX_GetSetPixmapParts.cpp +++ b/pixmapfx/kpPixmapFX_GetSetPixmapParts.cpp @@ -61,8 +61,7 @@ << destRect << ",src.rect=" << src.rect () - << ")" - << endl; + << ")"; Q_ASSERT (destPtr); @@ -122,8 +121,9 @@ // public static kpColor kpPixmapFX::getColorAtPixel (const QImage &img, const QPoint &at) { - if (!img.valid (at.x (), at.y ())) + if (!img.valid (at.x (), at.y ())) { return kpColor::Invalid; + } QRgb rgba = img.pixel(at); return kpColor (rgba); diff --git a/pixmapfx/kpPixmapFX_Transforms.cpp b/pixmapfx/kpPixmapFX_Transforms.cpp --- a/pixmapfx/kpPixmapFX_Transforms.cpp +++ b/pixmapfx/kpPixmapFX_Transforms.cpp @@ -52,20 +52,23 @@ { qCDebug(kpLogPixmapfx) << "kpPixmapFX::resize()"; - if (!destPtr) + if (!destPtr) { return; + } const int oldWidth = destPtr->width (); const int oldHeight = destPtr->height (); - if (w == oldWidth && h == oldHeight) + if (w == oldWidth && h == oldHeight) { return; + } QImage newImage (w, h, QImage::Format_ARGB32_Premultiplied); // Would have new undefined areas? - if (w > oldWidth || h > oldHeight) + if (w > oldWidth || h > oldHeight) { newImage.fill (backgroundColor.toQRgb ()); + } // Copy over old pixmap. QPainter painter(&newImage); @@ -93,8 +96,9 @@ // public static void kpPixmapFX::scale (QImage *destPtr, int w, int h, bool pretty) { - if (!destPtr) + if (!destPtr) { return; + } *destPtr = kpPixmapFX::scale (*destPtr, w, h, pretty); } @@ -108,11 +112,11 @@ << ",w=" << w << ",h=" << h << ",pretty=" << pretty - << ")" - << endl; + << ")"; - if (w == image.width () && h == image.height ()) + if (w == image.width () && h == image.height ()) { return image; + } return image.scaled(w, h, Qt::IgnoreAspectRatio, pretty ? Qt::SmoothTransformation : Qt::FastTransformation); @@ -126,7 +130,7 @@ / (2.0/*max error allowed*/ * 2.0/*for good measure*/); -static void MatrixDebug (const QString matrixName, const QTransform &matrix, +static void MatrixDebug (const QString& matrixName, const QTransform &matrix, int srcPixmapWidth = -1, int srcPixmapHeight = -1) { const int w = srcPixmapWidth, h = srcPixmapHeight; @@ -203,10 +207,11 @@ // QPainter::SmoothPixmapTransform is disabled. static double TrueMatrixFixInts (double x) { - if (std::fabs (x - qRound (x)) < TrueMatrixEpsilon) + if (std::fabs (x - qRound (x)) < TrueMatrixEpsilon) { return qRound (x); - else - return x; + } + + return x; } //--------------------------------------------------------------------- @@ -252,8 +257,7 @@ qCDebug(kpLogPixmapfx) << "kppixmapfx.cpp: TransformPixmap(pm.size=" << pm.size () << ",targetWidth=" << targetWidth << ",targetHeight=" << targetHeight - << ")" - << endl; + << ")"; QRect newRect = transformMatrix.mapRect (pm.rect ()); qCDebug(kpLogPixmapfx) << "\tmappedRect=" << newRect; @@ -277,11 +281,16 @@ // TODO: What is going on here??? Why isn't matrix * working properly? QTransform wrongMatrix = transformMatrix * scaleMatrix; QTransform oldHat = transformMatrix; - if (targetWidth > 0 && targetWidth != newRect.width ()) + + if (targetWidth > 0 && targetWidth != newRect.width ()) { oldHat.scale (double (targetWidth) / double (newRect.width ()), 1); - if (targetHeight > 0 && targetHeight != newRect.height ()) + } + if (targetHeight > 0 && targetHeight != newRect.height ()) { oldHat.scale (1, double (targetHeight) / double (newRect.height ())); + } + QTransform altHat = transformMatrix; + altHat.scale ((targetWidth > 0 && targetWidth != newRect.width ()) ? double (targetWidth) / double (newRect.width ()) : 1, (targetHeight > 0 && targetHeight != newRect.height ()) ? double (targetHeight) / double (newRect.height ()) : 1); QTransform correctMatrix = scaleMatrix * transformMatrix; @@ -293,31 +302,30 @@ << " dx=" << wrongMatrix.dx () << " dy=" << wrongMatrix.dy () << " rect=" << wrongMatrix.mapRect (pm.rect ()) - << endl + << "\n" << "\ti_used_to_use_thisMatrix: m11=" << oldHat.m11 () << " m12=" << oldHat.m12 () << " m21=" << oldHat.m21 () << " m22=" << oldHat.m22 () << " dx=" << oldHat.dx () << " dy=" << oldHat.dy () << " rect=" << oldHat.mapRect (pm.rect ()) - << endl + << "\n" << "\tabove but scaled at the same time: m11=" << altHat.m11 () << " m12=" << altHat.m12 () << " m21=" << altHat.m21 () << " m22=" << altHat.m22 () << " dx=" << altHat.dx () << " dy=" << altHat.dy () << " rect=" << altHat.mapRect (pm.rect ()) - << endl + << "\n" << "\tsupposedlyCorrectMatrix: m11=" << correctMatrix.m11 () << " m12=" << correctMatrix.m12 () << " m21=" << correctMatrix.m21 () << " m22=" << correctMatrix.m22 () << " dx=" << correctMatrix.dx () << " dy=" << correctMatrix.dy () - << " rect=" << correctMatrix.mapRect (pm.rect ()) - << endl; + << " rect=" << correctMatrix.mapRect (pm.rect ()); transformMatrix = transformMatrix * scaleMatrix; @@ -368,8 +376,7 @@ << ",targetWidth=" << targetWidth << ",targetHeight=" << targetHeight << ") newRect=" << newRect - << " (you are a victim of rounding error)" - << endl; + << " (you are a victim of rounding error)"; } // Note: Do _not_ use "p.setRenderHints (QPainter::SmoothPixmapTransform);" @@ -395,7 +402,7 @@ } p.end (); - qCDebug(kpLogPixmapfx) << "Done" << endl << endl; + qCDebug(kpLogPixmapfx) << "Done"; return newQImage; } @@ -408,7 +415,7 @@ if (std::fabs (hangle - 0) < kpPixmapFX::AngleInDegreesEpsilon && std::fabs (vangle - 0) < kpPixmapFX::AngleInDegreesEpsilon) { - return QTransform (); + return {}; } @@ -465,8 +472,9 @@ const kpColor &backgroundColor, int targetWidth, int targetHeight) { - if (!destPtr) + if (!destPtr) { return; + } *destPtr = kpPixmapFX::skew (*destPtr, hangle, vangle, backgroundColor, @@ -485,8 +493,7 @@ << " hangle=" << hangle << " vangle=" << vangle << " targetWidth=" << targetWidth - << " targetHeight=" << targetHeight - << endl; + << " targetHeight=" << targetHeight; if (std::fabs (hangle - 0) < kpPixmapFX::AngleInDegreesEpsilon && std::fabs (vangle - 0) < kpPixmapFX::AngleInDegreesEpsilon && @@ -498,7 +505,7 @@ if (std::fabs (hangle) > 90 - kpPixmapFX::AngleInDegreesEpsilon || std::fabs (vangle) > 90 - kpPixmapFX::AngleInDegreesEpsilon) { - qCCritical(kpLogPixmapfx) << "kpPixmapFX::skew() passed hangle and/or vangle out of range (-90 < x < 90)" << endl; + qCCritical(kpLogPixmapfx) << "kpPixmapFX::skew() passed hangle and/or vangle out of range (-90 < x < 90)"; return pm; } @@ -516,7 +523,7 @@ { if (std::fabs (angle - 0) < kpPixmapFX::AngleInDegreesEpsilon) { - return QTransform (); + return {}; } QTransform matrix; @@ -543,27 +550,26 @@ const double angleIn = angle; // Reflect angle into positive if negative - if (angle < 0) + if (angle < 0) { angle = -angle; + } // Remove multiples of 90 to make sure 0 <= angle <= 90 angle -= (static_cast (angle)) / 90 * 90; // "Impossible" situation? if (angle < 0 || angle > 90) { qCCritical(kpLogPixmapfx) << "kpPixmapFX::isLosslessRotation(" << angleIn - << ") result=" << angle - << endl; + << ") result=" << angle; return false; // better safe than sorry } const bool ret = (angle < kpPixmapFX::AngleInDegreesEpsilon || 90 - angle < kpPixmapFX::AngleInDegreesEpsilon); qCDebug(kpLogPixmapfx) << "kpPixmapFX::isLosslessRotation(" << angleIn << ")" << " residual angle=" << angle - << " returning " << ret - << endl; + << " returning " << ret; return ret; } @@ -575,8 +581,9 @@ const kpColor &backgroundColor, int targetWidth, int targetHeight) { - if (!destPtr) + if (!destPtr) { return; + } *destPtr = kpPixmapFX::rotate (*destPtr, angle, backgroundColor, diff --git a/scan/sanedialog.cpp b/scan/sanedialog.cpp --- a/scan/sanedialog.cpp +++ b/scan/sanedialog.cpp @@ -68,7 +68,7 @@ // either no scanner was found or then cancel was pressed. return false; } - if (m_ksanew->openDevice(m_openDev) == false) { + if (!m_ksanew->openDevice(m_openDev)) { // could not open the scanner KMessageBox::sorry(nullptr, i18n("Opening the selected scanner failed.")); m_openDev = QString(); @@ -82,8 +82,9 @@ if (configPtr->hasGroup(groupName)) { KConfigGroup group(configPtr, groupName); QStringList keys = group.keyList(); - for (int i = 0; i < keys.count(); i++) + for (int i = 0; i < keys.count(); i++) { m_ksanew->setOptVal(keys[i], group.readEntry(keys[i])); + } } return true; @@ -100,8 +101,9 @@ QMap opts; m_ksanew->getOptVals(opts); QMap::const_iterator i = opts.constBegin(); - for (; i != opts.constEnd(); ++i) + for (; i != opts.constEnd(); ++i) { group.writeEntry(i.key(), i.value(), KConfigGroup::Persistent); + } } } diff --git a/tools/flow/kpToolColorEraser.cpp b/tools/flow/kpToolColorEraser.cpp --- a/tools/flow/kpToolColorEraser.cpp +++ b/tools/flow/kpToolColorEraser.cpp @@ -56,18 +56,17 @@ //-------------------------------------------------------------------------------- -kpToolColorEraser::~kpToolColorEraser () -{ -} +kpToolColorEraser::~kpToolColorEraser () = default; //-------------------------------------------------------------------------------- // public virtual [base kpTool] void kpToolColorEraser::globalDraw () { qCDebug(kpLogTools) << "kpToolColorEraser::globalDraw()"; - if (!drawShouldProceed (QPoint ()/*unused*/, QPoint ()/*unused*/, QRect ()/*unused*/)) + if (!drawShouldProceed (QPoint ()/*unused*/, QPoint ()/*unused*/, QRect ()/*unused*/)) { return; + } QApplication::setOverrideCursor (Qt::WaitCursor); @@ -118,21 +117,16 @@ const QPoint & /*lastPoint*/, const QRect & /*normalizedRect*/) { - if (foregroundColor () == backgroundColor () && - processedColorSimilarity () == 0) - { - return false; - } - - return true; + return !(foregroundColor () == backgroundColor () && + processedColorSimilarity () == 0); } //-------------------------------------------------------------------------------- QRect kpToolColorEraser::drawLine (const QPoint &thisPoint, const QPoint &lastPoint) { qCDebug(kpLogTools) << "kpToolColorEraser::drawLine(thisPoint=" << thisPoint - << ",lastPoint=" << lastPoint << ")" << endl; + << ",lastPoint=" << lastPoint << ")"; environ ()->flashColorSimilarityToolBarItem (); @@ -152,7 +146,7 @@ return dirtyRect; } - return QRect (); + return {}; } //-------------------------------------------------------------------------------- diff --git a/tools/flow/kpToolFlowBase.cpp b/tools/flow/kpToolFlowBase.cpp --- a/tools/flow/kpToolFlowBase.cpp +++ b/tools/flow/kpToolFlowBase.cpp @@ -58,33 +58,33 @@ struct kpToolFlowBasePrivate { - kpToolWidgetBrush *toolWidgetBrush; - kpToolWidgetEraserSize *toolWidgetEraserSize; + kpToolWidgetBrush *toolWidgetBrush{}; + kpToolWidgetEraserSize *toolWidgetEraserSize{}; // // Cursor and Brush Data // (must be zero if unused) // - kpTempImage::UserFunctionType brushDrawFunc, cursorDrawFunc; + kpTempImage::UserFunctionType brushDrawFunc{}, cursorDrawFunc{}; // Can't use union since package types contain fields requiring // constructors. kpToolWidgetBrush::DrawPackage brushDrawPackageForMouseButton [2]; kpToolWidgetEraserSize::DrawPackage eraserDrawPackageForMouseButton [2]; // Each element points to one of the above (both elements from the same // array). - void *drawPackageForMouseButton [2]; + void *drawPackageForMouseButton [2]{}; - int brushWidth, brushHeight; - int cursorWidth, cursorHeight; + int brushWidth{}, brushHeight{}; + int cursorWidth{}, cursorHeight{}; - bool brushIsDiagonalLine; + bool brushIsDiagonalLine{}; - kpToolFlowCommand *currentCommand; + kpToolFlowCommand *currentCommand{}; }; //--------------------------------------------------------------------- @@ -191,11 +191,13 @@ kpViewManager *vm = viewManager (); Q_ASSERT (vm); - if (vm->tempImage () && vm->tempImage ()->isBrush ()) + if (vm->tempImage () && vm->tempImage ()->isBrush ()) { vm->invalidateTempImage (); + } - if (haveAnyBrushes ()) + if (haveAnyBrushes ()) { vm->unsetCursor (); + } clearBrushCursorData (); } @@ -250,8 +252,9 @@ // virtual void kpToolFlowBase::draw (const QPoint &thisPoint, const QPoint &lastPoint, const QRect &normalizedRect) { - if (!/*virtual*/drawShouldProceed (thisPoint, lastPoint, normalizedRect)) + if (!/*virtual*/drawShouldProceed (thisPoint, lastPoint, normalizedRect)) { return; + } // sync: remember to restoreFastUpdates() in all exit paths viewManager ()->setFastUpdates (); @@ -327,11 +330,11 @@ qCDebug(kpLogTools) << "kpToolFlowBase::color (" << which << ")"; // Pen & Brush - if (!colorsAreSwapped ()) + if (!colorsAreSwapped ()) { return kpTool::color (which); + } // only the (Color) Eraser uses the opposite color - else - return kpTool::color (which ? 0 : 1); // don't trust !0 == 1 + return kpTool::color (which ? 0 : 1); // don't trust !0 == 1 } //--------------------------------------------------------------------- @@ -455,10 +458,9 @@ * | * Center */ - return QRect (mousePoint.x () - brushWidth / 2, - mousePoint.y () - brushHeight / 2, - brushWidth, - brushHeight); + return {mousePoint.x () - brushWidth / 2, + mousePoint.y () - brushHeight / 2, + brushWidth, brushHeight}; } //--------------------------------------------------------------------- diff --git a/tools/flow/kpToolSpraycan.cpp b/tools/flow/kpToolSpraycan.cpp --- a/tools/flow/kpToolSpraycan.cpp +++ b/tools/flow/kpToolSpraycan.cpp @@ -119,16 +119,17 @@ { qCDebug(kpLogTools) << "CALL(thisPoint=" << thisPoint << ",lastPoint=" << lastPoint - << ")" << endl; + << ")"; QList docPoints = kpPainter::interpolatePoints (lastPoint, thisPoint, false/*no need for cardinally adjacency points*/, probability); qCDebug(kpLogTools) << "\tdocPoints=" << docPoints; // By chance no points to draw? - if (docPoints.empty ()) - return QRect (); + if (docPoints.empty ()) { + return {}; + } // For efficiency, only get image after NOP check above. QRect docRect = kpPainter::normalizedRect(thisPoint, lastPoint); @@ -143,7 +144,7 @@ // appearance. QList imagePoints; - foreach (const QPoint &dp, docPoints) + for (const auto &dp : docPoints) imagePoints.append (dp - docRect.topLeft ()); kpPainter::sprayPoints (&image, @@ -164,8 +165,7 @@ QRect kpToolSpraycan::drawPoint (const QPoint &point) { qCDebug(kpLogTools) << "kpToolSpraycan::drawPoint" << point - << " lastPoint=" << lastPoint () - << endl; + << " lastPoint=" << lastPoint (); // If this is the first in the flow or if the user is moving the spray, // make the spray line continuous. @@ -176,7 +176,7 @@ 1.0/*100% chance of drawing*/); } - return QRect (); + return {}; } // public virtual [base kpToolFlowBase] @@ -218,7 +218,7 @@ const QRect &normalizedRect) { qCDebug(kpLogTools) << "kpToolSpraycan::endDraw(thisPoint=" << thisPoint - << ")" << endl; + << ")"; m_timer->stop (); kpToolFlowBase::endDraw (thisPoint, normalizedRect); diff --git a/tools/kpTool.cpp b/tools/kpTool.cpp --- a/tools/kpTool.cpp +++ b/tools/kpTool.cpp @@ -84,8 +84,9 @@ kpTool::~kpTool () { // before destructing, stop using the tool - if (d->began) + if (d->began) { endInternal (); + } delete d->action; @@ -134,11 +135,11 @@ QString kpTool::toolTipForTextAndShortcut (const QString &text, const QList &shortcut) { - foreach(const QKeySequence &seq, shortcut) + for(const auto &seq : shortcut) { - if (seq.count () == 1 && ::KeyIsText (seq [0])) - return i18nc (" ()", - "%1 (%2)", text, seq.toString ().toUpper ()); + if (seq.count () == 1 && ::KeyIsText (seq [0])) { + return i18nc (" ()", "%1 (%2)", text, seq.toString ().toUpper ()); + } } return text; diff --git a/tools/kpToolAction.cpp b/tools/kpToolAction.cpp --- a/tools/kpToolAction.cpp +++ b/tools/kpToolAction.cpp @@ -42,8 +42,9 @@ ac->setDefaultShortcuts(this, shortcut); - if ( receiver && slot ) + if ( receiver && slot ) { connect (this, SIGNAL(triggered(bool)), receiver, slot); + } updateToolTip(); connect (this, &kpToolAction::changed, this, &kpToolAction::updateToolTip); @@ -59,8 +60,9 @@ const QString newToolTip = kpTool::toolTipForTextAndShortcut(text(), shortcuts()).remove(QLatin1Char('&')); - if ( newToolTip == toolTip() ) + if ( newToolTip == toolTip() ) { return; + } setToolTip(newToolTip); } diff --git a/tools/kpToolColorPicker.cpp b/tools/kpToolColorPicker.cpp --- a/tools/kpToolColorPicker.cpp +++ b/tools/kpToolColorPicker.cpp @@ -48,9 +48,7 @@ { } -kpToolColorPicker::~kpToolColorPicker () -{ -} +kpToolColorPicker::~kpToolColorPicker () = default; // private @@ -122,11 +120,8 @@ if (color.isValid ()) { - kpToolColorPickerCommand *cmd = - new kpToolColorPickerCommand ( - mouseButton (), - color, m_oldColor, - environ ()->commandEnvironment ()); + auto *cmd = new kpToolColorPickerCommand ( mouseButton (), color, m_oldColor, + environ ()->commandEnvironment ()); environ ()->commandHistory ()->addCommand (cmd, false/*no exec*/); setUserMessage (haventBegunDrawUserMessage ()); diff --git a/tools/kpToolZoom.cpp b/tools/kpToolZoom.cpp --- a/tools/kpToolZoom.cpp +++ b/tools/kpToolZoom.cpp @@ -56,7 +56,7 @@ const QPoint &topLeft, void *userData) { - DrawZoomRectPackage *pack = static_cast (userData); + auto *pack = static_cast (userData); kpPixmapFX::drawStippleRect(destImage, topLeft.x (), topLeft.y (), pack->normalizedRect.width (), pack->normalizedRect.height (), @@ -67,7 +67,7 @@ struct kpToolZoomPrivate { - bool dragHasBegun, dragCompleted; + bool dragHasBegun{}, dragCompleted{}; DrawZoomRectPackage drawPackage; }; @@ -163,16 +163,18 @@ if (!d->dragHasBegun) { - if (thisPoint == startPoint ()) + if (thisPoint == startPoint ()) { return; + } // Left mouse drags select an area to zoom into. // However, it wouldn't make sense to select an area to "zoom out of" // (using the right mouse button). Therefore, make RMB drags do the // same as RMB clicks i.e. a simple zoom out, with no "area" to worry // about. - if (mouseButton () == 1/*RMB*/) + if (mouseButton () == 1/*RMB*/) { return; + } d->dragHasBegun = true; } @@ -222,12 +224,14 @@ // Click? if (!d->dragHasBegun) { - if (mouseButton () == 0/*LMB*/) + if (mouseButton () == 0/*LMB*/) { environ ()->zoomIn (true/*center under cursor*/); - else + } + else { environ ()->zoomOut (false/*don't center under cursor - as is confusing behaviour when zooming out*/); + } } // Drag? else if (normalizedRect.isValid()) diff --git a/tools/kpTool_Drawing.cpp b/tools/kpTool_Drawing.cpp --- a/tools/kpTool_Drawing.cpp +++ b/tools/kpTool_Drawing.cpp @@ -184,8 +184,9 @@ if (d->began) { // before we can stop using the tool, we must stop the current drawing operation (if any) - if (hasBegunShape ()) + if (hasBegunShape ()) { endShapeInternal (d->currentPoint, normalizedRect ()); + } // call user virtual func end (); @@ -261,8 +262,7 @@ void kpTool::hover (const QPoint &point) { qCDebug(kpLogTools) << "kpTool::hover" << point - << " base implementation" - << endl; + << " base implementation"; setUserShapePoints (point); } @@ -312,8 +312,9 @@ emit cancelledShape (viewUnderCursor () ? d->currentPoint : KP_INVALID_POINT); - if (viewUnderCursor ()) + if (viewUnderCursor ()) { hover (d->currentPoint); + } else { d->currentPoint = KP_INVALID_POINT; @@ -349,10 +350,13 @@ { qCDebug(kpLogTools) << "kpTool::endDrawInternal() wantEndShape=" << wantEndShape; - if (wantEndShape && !hasBegunShape ()) + if (wantEndShape && !hasBegunShape ()) { return; - else if (!wantEndShape && !hasBegunDraw ()) + } + + if (!wantEndShape && !hasBegunDraw ()) { return; + } d->beganDraw = false; @@ -369,8 +373,9 @@ d->viewUnderStartPoint = nullptr; emit endedDraw (d->currentPoint); - if (viewUnderCursor ()) + if (viewUnderCursor ()) { hover (d->currentPoint); + } else { d->currentPoint = KP_INVALID_POINT; diff --git a/tools/kpTool_KeyboardEvents.cpp b/tools/kpTool_KeyboardEvents.cpp --- a/tools/kpTool_KeyboardEvents.cpp +++ b/tools/kpTool_KeyboardEvents.cpp @@ -105,10 +105,12 @@ case Qt::Key_PageDown: dxLocal = +1; dyLocal = +1; break; } - if (dx) + if (dx) { *dx = dxLocal; - if (dy) + } + if (dy) { *dy = dyLocal; + } } //--------------------------------------------------------------------- @@ -118,13 +120,15 @@ int dx, dy; arrowKeyPressDirection (e, &dx, &dy); - if (dx == 0 && dy == 0) + if (dx == 0 && dy == 0) { return; + } kpView * const view = viewUnderCursor (); - if (!view) + if (!view) { return; + } const QPoint oldPoint = view->mapFromGlobal (QCursor::pos ()); @@ -177,18 +181,21 @@ void kpTool::seeIfAndHandleBeginDrawKeyPress (QKeyEvent *e) { - if (e->isAutoRepeat ()) + if (e->isAutoRepeat ()) { return; + } - if (!isDrawKey (e->key ())) + if (!isDrawKey (e->key ())) { return; + } qCDebug(kpLogTools) << "kpTool::seeIfAndHandleBeginDrawKeyPress() accept"; // TODO: wrong for dragging lines outside of view (for e.g.) kpView * const view = viewUnderCursor (); - if (!view) + if (!view) { return; + } // TODO: what about the modifiers? @@ -208,17 +215,20 @@ << " isDrawKey=" << isDrawKey (e->key ()) << " view=" << viewUnderCursor (); - if (e->isAutoRepeat ()) + if (e->isAutoRepeat ()) { return; + } - if (!isDrawKey (e->key ())) + if (!isDrawKey (e->key ())) { return; + } qCDebug(kpLogTools) << "kpTool::seeIfAndHandleEndDrawKeyPress() accept"; kpView * const view = viewUnderCursor (); - if (!view) + if (!view) { return; + } // TODO: what about the modifiers? @@ -238,22 +248,24 @@ { qCDebug(kpLogTools) << "kpTool::keyPressEvent() key=" << (int *) e->key () << " stateAfter: modifiers=" << (int *) (int) e->modifiers () - << " isAutoRep=" << e->isAutoRepeat () - << endl; + << " isAutoRep=" << e->isAutoRepeat (); e->ignore (); seeIfAndHandleModifierKey (e); - if (e->isAccepted ()) + if (e->isAccepted ()) { return; + } seeIfAndHandleArrowKeyPress (e); - if (e->isAccepted ()) + if (e->isAccepted ()) { return; + } seeIfAndHandleBeginDrawKeyPress (e); - if (e->isAccepted ()) + if (e->isAccepted ()) { return; + } switch (e->key ()) { @@ -278,18 +290,19 @@ { qCDebug(kpLogTools) << "kpTool::keyReleaseEvent() key=" << (int *) e->key () << " stateAfter: modifiers=" << (int *) (int) e->modifiers () - << " isAutoRep=" << e->isAutoRepeat () - << endl; + << " isAutoRep=" << e->isAutoRepeat (); e->ignore (); seeIfAndHandleModifierKey (e); - if (e->isAccepted ()) + if (e->isAccepted ()) { return; + } seeIfAndHandleEndDrawKeyPress (e); - if (e->isAccepted ()) + if (e->isAccepted ()) { return; + } } //--------------------------------------------------------------------- @@ -329,8 +342,9 @@ { if (careAboutModifierState ()) { - if (d->beganDraw) + if (d->beganDraw) { draw (d->currentPoint, d->lastPoint, normalizedRect ()); + } else { d->currentPoint = calculateCurrentPoint (); @@ -344,8 +358,9 @@ void kpTool::setShiftPressed (bool pressed) { - if (pressed == d->shiftPressed) + if (pressed == d->shiftPressed) { return; + } d->shiftPressed = pressed; @@ -356,8 +371,9 @@ void kpTool::setControlPressed (bool pressed) { - if (pressed == d->controlPressed) + if (pressed == d->controlPressed) { return; + } d->controlPressed = pressed; @@ -368,8 +384,9 @@ void kpTool::setAltPressed (bool pressed) { - if (pressed == d->altPressed) + if (pressed == d->altPressed) { return; + } d->altPressed = pressed; diff --git a/tools/kpTool_MouseEvents.cpp b/tools/kpTool_MouseEvents.cpp --- a/tools/kpTool_MouseEvents.cpp +++ b/tools/kpTool_MouseEvents.cpp @@ -120,8 +120,9 @@ kpView *view = viewUnderCursor (); Q_ASSERT (view); - if (view) + if (view) { qCDebug(kpLogTools) << "\tview=" << view->objectName (); + } // let user know what mouse button is being used for entire draw d->mouseButton = mouseButton (e->buttons ()); @@ -199,8 +200,9 @@ drawInternal (); - if (dragScrolled) + if (dragScrolled) { viewManager ()->restoreFastUpdates (); + } d->lastPoint = d->currentPoint; } @@ -228,7 +230,7 @@ << " button=" << (int) e->button () << " stateAfter: buttons=" << (int *) (int) e->buttons () << " modifiers=" << (int *) (int) e->modifiers () - << " beganDraw=" << d->beganDraw << endl; + << " beganDraw=" << d->beganDraw; // Have _not_ already cancelShape()'ed by pressing other mouse button? // (e.g. you can cancel a line dragged out with the LMB, by pressing @@ -258,8 +260,7 @@ { qCDebug(kpLogTools) << "kpTool::wheelEvent() modifiers=" << (int *) (int) e->modifiers () << " hasBegunDraw=" << hasBegunDraw () - << " delta=" << e->delta () - << endl; + << " delta=" << e->delta (); e->ignore (); diff --git a/tools/kpTool_OtherEvents.cpp b/tools/kpTool_OtherEvents.cpp --- a/tools/kpTool_OtherEvents.cpp +++ b/tools/kpTool_OtherEvents.cpp @@ -69,8 +69,9 @@ { qCDebug(kpLogTools) << "kpTool::focusOutEvent() beganDraw=" << d->beganDraw; - if (d->beganDraw) + if (d->beganDraw) { endDrawInternal (d->currentPoint, normalizedRect ()); + } } //--------------------------------------------------------------------- @@ -108,8 +109,9 @@ slotColorsSwapped (newForegroundColor, newBackgroundColor); d->ignoreColorSignals = 2; } - else + else { d->ignoreColorSignals = 0; + } } //--------------------------------------------------------------------- diff --git a/tools/kpTool_UserNotifications.cpp b/tools/kpTool_UserNotifications.cpp --- a/tools/kpTool_UserNotifications.cpp +++ b/tools/kpTool_UserNotifications.cpp @@ -38,10 +38,11 @@ // public static QString kpTool::cancelUserMessage (int mouseButton) { - if (mouseButton == 0) + if (mouseButton == 0) { return i18n ("Right click to cancel."); - else - return i18n ("Left click to cancel."); + } + + return i18n ("Left click to cancel."); } //--------------------------------------------------------------------- @@ -67,10 +68,12 @@ { d->userMessage = userMessage; - if (d->userMessage.isEmpty ()) + if (d->userMessage.isEmpty ()) { d->userMessage = text (); - else + } + else { d->userMessage.prepend (i18n ("%1: ", text ())); + } emit userMessageChanged (d->userMessage); } diff --git a/tools/kpTool_Utilities.cpp b/tools/kpTool_Utilities.cpp --- a/tools/kpTool_Utilities.cpp +++ b/tools/kpTool_Utilities.cpp @@ -56,8 +56,9 @@ int x1, y1, x2, y2; rect.getCoords (&x1, &y1, &x2, &y2); - if (lineWidth < 1) + if (lineWidth < 1) { lineWidth = 1; + } // TODO: why not divide by 2? return QRect (QPoint (x1 - lineWidth + 1, y1 - lineWidth + 1), @@ -107,8 +108,9 @@ const QPoint viewPos = v->mapFromGlobal (globalPos); qCDebug(kpLogTools) << "\tglobalPos=" << globalPos << " viewPos=" << viewPos; - if (!zoomToDoc) + if (!zoomToDoc) { return viewPos; + } const QPoint docPos = v->transformViewToDoc (viewPos); @@ -164,8 +166,9 @@ bool kpTool::currentPointNextToLast () const { - if (d->lastPoint == QPoint (-1, -1)) + if (d->lastPoint == QPoint (-1, -1)) { return true; + } int dx = qAbs (d->currentPoint.x () - d->lastPoint.x ()); int dy = qAbs (d->currentPoint.y () - d->lastPoint.y ()); @@ -177,8 +180,9 @@ bool kpTool::currentPointCardinallyNextToLast () const { - if (d->lastPoint == QPoint (-1, -1)) + if (d->lastPoint == QPoint (-1, -1)) { return true; + } return (d->currentPoint == d->lastPoint || kpPainter::pointsAreCardinallyAdjacent (d->currentPoint, d->lastPoint)); @@ -191,20 +195,24 @@ int kpTool::mouseButton (Qt::MouseButtons mouseButtons) { // we have nothing to do with mid-buttons - if (mouseButtons & Qt::MidButton) + if (mouseButtons & Qt::MidButton) { return -1; + } // both left & right together is quite meaningless... const Qt::MouseButtons bothButtons = (Qt::LeftButton | Qt::RightButton); - if ((mouseButtons & bothButtons) == bothButtons) + if ((mouseButtons & bothButtons) == bothButtons) { return -1; + } - if (mouseButtons & Qt::LeftButton) + if (mouseButtons & Qt::LeftButton) { return 0; - else if (mouseButtons & Qt::RightButton) + } + if (mouseButtons & Qt::RightButton) { return 1; - else - return -1; + } + + return -1; } //--------------------------------------------------------------------- @@ -216,10 +224,8 @@ { return end - start + 1; } - else - { - return end - start - 1; - } + + return end - start - 1; } //--------------------------------------------------------------------- @@ -257,10 +263,8 @@ return (accept == KMessageBox::Continue); } - else - { - return true; - } + + return true; } //--------------------------------------------------------------------- diff --git a/tools/polygonal/kpToolCurve.cpp b/tools/polygonal/kpToolCurve.cpp --- a/tools/polygonal/kpToolCurve.cpp +++ b/tools/polygonal/kpToolCurve.cpp @@ -109,9 +109,7 @@ { } -kpToolCurve::~kpToolCurve () -{ -} +kpToolCurve::~kpToolCurve () = default; // protected virtual [base kpToolPolygonalBase] @@ -134,7 +132,7 @@ void kpToolCurve::endDraw (const QPoint &, const QRect &) { qCDebug(kpLogTools) << "kpToolCurve::endDraw() points=" - << points ()->toList () << endl; + << points ()->toList (); switch (points ()->count ()) { diff --git a/tools/polygonal/kpToolPolygon.cpp b/tools/polygonal/kpToolPolygon.cpp --- a/tools/polygonal/kpToolPolygon.cpp +++ b/tools/polygonal/kpToolPolygon.cpp @@ -56,18 +56,22 @@ return; } - if ( bcolor.isValid() ) + if ( bcolor.isValid() ) { painter.setBrush(QBrush(bcolor.toQColor())); - else + } + else { painter.setBrush(Qt::NoBrush); + } painter.drawPolygon(points, Qt::OddEvenFill); - if ( isFinal ) + if ( isFinal ) { return; + } - if ( points.count() <= 2 ) + if ( points.count() <= 2 ) { return; + } painter.setCompositionMode(QPainter::RasterOp_SourceXorDestination); painter.setPen(QPen(Qt::white)); @@ -149,14 +153,15 @@ void kpToolPolygon::endDraw (const QPoint &, const QRect &) { qCDebug(kpLogTools) << "kpToolPolygon::endDraw() points=" - << points ()->toList () << endl; + << points ()->toList (); // A click of the other mouse button (to finish shape, instead of adding // another control point) would have caused endShape() to have been // called in kpToolPolygonalBase::beginDraw(). The points list would now // be empty. We are being called by kpTool::mouseReleaseEvent(). - if (points ()->count () == 0) + if (points ()->count () == 0) { return; + } if (points ()->count () >= kpToolPolygonalBase::MaxPoints) { diff --git a/tools/polygonal/kpToolPolygonalBase.cpp b/tools/polygonal/kpToolPolygonalBase.cpp --- a/tools/polygonal/kpToolPolygonalBase.cpp +++ b/tools/polygonal/kpToolPolygonalBase.cpp @@ -141,7 +141,7 @@ void kpToolPolygonalBase::beginDraw () { qCDebug(kpLogTools) << "kpToolPolygonalBase::beginDraw() d->points=" << d->points.toList () - << ", startPoint=" << startPoint () << endl; + << ", startPoint=" << startPoint (); bool endedShape = false; @@ -197,36 +197,38 @@ << " endPt=" << lineEndPoint << " modifiers: shift=" << shiftPressed () << " alt=" << altPressed () - << " ctrl=" << controlPressed () - << endl; + << " ctrl=" << controlPressed (); // angles if (shiftPressed () || controlPressed ()) { int diffx = lineEndPoint.x () - lineStartPoint.x (); int diffy = lineEndPoint.y () - lineStartPoint.y (); double ratio; - if (diffx == 0) + if (diffx == 0) { ratio = DBL_MAX; - else + } + else { ratio = fabs (double (diffy) / double (diffx)); - qCDebug(kpLogTools) << "\tdiffx=" << diffx << " diffy=" << diffy - << " ratio=" << ratio - << endl; + } + qCDebug(kpLogTools) << "\tdiffx=" << diffx << " diffy=" << diffy << " ratio=" << ratio; // Shift = 0, 45, 90 // Ctrl = 0, 30, 60, 90 // Shift + Ctrl = 0, 30, 45, 60, 90 double angles [10]; // "ought to be enough for anybody" int numAngles = 0; angles [numAngles++] = 0; - if (controlPressed ()) + if (controlPressed ()) { angles [numAngles++] = M_PI / 6; - if (shiftPressed ()) + } + if (shiftPressed ()) { angles [numAngles++] = M_PI / 4; - if (controlPressed ()) + } + if (controlPressed ()) { angles [numAngles++] = M_PI / 3; + } angles [numAngles++] = M_PI / 2; Q_ASSERT (numAngles <= int (sizeof (angles) / sizeof (angles [0]))); @@ -272,8 +274,7 @@ qCDebug(kpLogTools) << "\t\tdiagonal line: dist=" << dist << " angle=" << (angle * 180 / M_PI) - << " endPoint=" << lineEndPoint - << endl; + << " endPoint=" << lineEndPoint; } } // if (shiftPressed () || controlPressed ()) { @@ -284,10 +285,12 @@ // = start - (end - start) // = start - end + start // = 2 * start - end - if (count == 2) + if (count == 2) { lineStartPoint += (lineStartPoint - lineEndPoint); - else + } + else { lineEndPoint += (lineEndPoint - lineStartPoint); + } } // if (altPressed ()) { } @@ -314,11 +317,12 @@ // another control point) would have caused endShape() to have been // called in kpToolPolygonalBase::beginDraw(). The points list would now // be empty. We are being called by kpTool::mouseReleaseEvent(). - if (d->points.count () == 0) + if (d->points.count () == 0) { return; + } qCDebug(kpLogTools) << "kpToolPolygonalBase::draw() d->points=" << d->points.toList () - << ", endPoint=" << currentPoint () << endl; + << ", endPoint=" << currentPoint (); // Update points() so that last point reflects current mouse position. const int count = d->points.count (); @@ -369,8 +373,9 @@ // protected slot void kpToolPolygonalBase::updateShape () { - if (d->points.count () == 0) + if (d->points.count () == 0) { return; + } const QRect boundingRect = kpTool::neededRect ( d->points.boundingRect (), @@ -415,8 +420,9 @@ void kpToolPolygonalBase::releasedAllButtons () { - if (!hasBegunShape ()) + if (!hasBegunShape ()) { setUserMessage (/*virtual*/haventBegunShapeUserMessage ()); + } // --- else case already handled by endDraw() --- } @@ -427,8 +433,9 @@ qCDebug(kpLogTools) << "kpToolPolygonalBase::endShape() d->points=" << d->points.toList (); - if (!hasBegunShape ()) + if (!hasBegunShape ()) { return; + } viewManager ()->invalidateTempImage (); diff --git a/tools/polygonal/kpToolPolyline.cpp b/tools/polygonal/kpToolPolyline.cpp --- a/tools/polygonal/kpToolPolyline.cpp +++ b/tools/polygonal/kpToolPolyline.cpp @@ -77,10 +77,12 @@ painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - if ( kpPixmapFX::Only1PixelInPointArray(points) ) + if ( kpPixmapFX::Only1PixelInPointArray(points) ) { painter.drawPoint(points[0]); - else + } + else { painter.drawPolyline(points); + } } //-------------------------------------------------------------------------------- @@ -90,15 +92,16 @@ { #if DEBUG_KP_TOOL_POLYLINE qCDebug(kpLogTools) << "kpToolPolyline::endDraw() points=" - << points ()->toList () << endl; + << points ()->toList (); #endif // A click of the other mouse button (to finish shape, instead of adding // another control point) would have caused endShape() to have been // called in kpToolPolygonalBase::beginDraw(). The points list would now // be empty. We are being called by kpTool::mouseReleaseEvent(). - if (points ()->count () == 0) + if (points ()->count () == 0) { return; + } if (points ()->count () >= kpToolPolygonalBase::MaxPoints) { diff --git a/tools/rectangular/kpToolEllipse.cpp b/tools/rectangular/kpToolEllipse.cpp --- a/tools/rectangular/kpToolEllipse.cpp +++ b/tools/rectangular/kpToolEllipse.cpp @@ -54,21 +54,25 @@ const kpColor &fcolor, int penWidth, const kpColor &bcolor) { - if ( (width == 0) || (height == 0) ) + if ( (width == 0) || (height == 0) ) { return; + } QPainter painter(image); painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased); - if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) + if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) { penWidth = qMin(width, height) / 2; + } painter.setPen(QPen(fcolor.toQColor(), penWidth)); - if ( bcolor.isValid() ) + if ( bcolor.isValid() ) { painter.setBrush(QBrush(bcolor.toQColor())); - else + } + else { painter.setBrush(Qt::NoBrush); + } int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0; diff --git a/tools/rectangular/kpToolRectangle.cpp b/tools/rectangular/kpToolRectangle.cpp --- a/tools/rectangular/kpToolRectangle.cpp +++ b/tools/rectangular/kpToolRectangle.cpp @@ -55,21 +55,25 @@ const kpColor &fcolor, int penWidth, const kpColor &bcolor) { - if ( (width == 0) || (height == 0) ) + if ( (width == 0) || (height == 0) ) { return; + } QPainter painter(image); painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased); - if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) + if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) { penWidth = qMin(width, height) / 2; + } painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); - if ( bcolor.isValid() ) + if ( bcolor.isValid() ) { painter.setBrush(QBrush(bcolor.toQColor())); - else + } + else { painter.setBrush(Qt::NoBrush); + } int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0; diff --git a/tools/rectangular/kpToolRectangularBase.cpp b/tools/rectangular/kpToolRectangularBase.cpp --- a/tools/rectangular/kpToolRectangularBase.cpp +++ b/tools/rectangular/kpToolRectangularBase.cpp @@ -56,10 +56,10 @@ struct kpToolRectangularBasePrivate { - kpToolRectangularBase::DrawShapeFunc drawShapeFunc; + kpToolRectangularBase::DrawShapeFunc drawShapeFunc{}; - kpToolWidgetLineWidth *toolWidgetLineWidth; - kpToolWidgetFillStyle *toolWidgetFillStyle; + kpToolWidgetLineWidth *toolWidgetLineWidth{}; + kpToolWidgetFillStyle *toolWidgetFillStyle{}; QRect toolRectangleRect; }; @@ -96,17 +96,19 @@ // private slot virtual void kpToolRectangularBase::slotLineWidthChanged () { - if (hasBegunDraw ()) + if (hasBegunDraw ()) { updateShape (); + } } //--------------------------------------------------------------------- // private slot virtual void kpToolRectangularBase::slotFillStyleChanged () { - if (hasBegunDraw ()) + if (hasBegunDraw ()) { updateShape (); + } } //--------------------------------------------------------------------- @@ -197,17 +199,21 @@ { if (rect.width () < rect.height ()) { - if (startPoint ().y () == rect.y ()) + if (startPoint ().y () == rect.y ()) { rect.setHeight (rect.width ()); - else + } + else { rect.setY (rect.bottom () - rect.width () + 1); + } } else { - if (startPoint ().x () == rect.x ()) + if (startPoint ().x () == rect.x ()) { rect.setWidth (rect.height ()); - else + } + else { rect.setX (rect.right () - rect.height () + 1); + } } } // have to maintain the center diff --git a/tools/rectangular/kpToolRoundedRectangle.cpp b/tools/rectangular/kpToolRoundedRectangle.cpp --- a/tools/rectangular/kpToolRoundedRectangle.cpp +++ b/tools/rectangular/kpToolRoundedRectangle.cpp @@ -54,21 +54,25 @@ const kpColor &fcolor, int penWidth, const kpColor &bcolor) { - if ( (width == 0) || (height == 0) ) + if ( (width == 0) || (height == 0) ) { return; + } QPainter painter(image); painter.setRenderHint(QPainter::Antialiasing, kpToolEnvironment::drawAntiAliased); - if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) + if ( ((2 * penWidth) > width) || ((2 * penWidth) > height) ) { penWidth = qMin(width, height) / 2; + } painter.setPen(QPen(fcolor.toQColor(), penWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin)); - if ( bcolor.isValid() ) + if ( bcolor.isValid() ) { painter.setBrush(QBrush(bcolor.toQColor())); - else + } + else { painter.setBrush(Qt::NoBrush); + } int offset = painter.testRenderHint(QPainter::Antialiasing) ? 1 : 0; diff --git a/tools/selection/image/kpAbstractImageSelectionTool.cpp b/tools/selection/image/kpAbstractImageSelectionTool.cpp --- a/tools/selection/image/kpAbstractImageSelectionTool.cpp +++ b/tools/selection/image/kpAbstractImageSelectionTool.cpp @@ -55,8 +55,9 @@ kpAbstractImageSelection *imageSel = document ()->imageSelection (); Q_ASSERT (imageSel && !imageSel->hasContent ()); - if (imageSel->transparency ().isTransparent ()) + if (imageSel->transparency ().isTransparent ()) { environ ()->flashColorSimilarityToolBarItem (); + } return new kpToolSelectionPullFromDocumentCommand ( *imageSel, diff --git a/tools/selection/image/kpAbstractImageSelectionTool_Transparency.cpp b/tools/selection/image/kpAbstractImageSelectionTool_Transparency.cpp --- a/tools/selection/image/kpAbstractImageSelectionTool_Transparency.cpp +++ b/tools/selection/image/kpAbstractImageSelectionTool_Transparency.cpp @@ -62,13 +62,14 @@ { #if DEBUG_KP_TOOL_SELECTION qCDebug(kpLogTools) << "\trecursion - abort setting selection transparency: " - << environ ()->settingImageSelectionTransparency () << endl; + << environ ()->settingImageSelectionTransparency (); #endif return false; } - if (!document ()->imageSelection ()) + if (!document ()->imageSelection ()) { return false; + } // TODO: Can probably return false if the selection transparency mode // is Opaque, since neither background color nor color similarity @@ -89,13 +90,15 @@ kpSetOverrideCursorSaver cursorSaver (Qt::WaitCursor); - if (hasBegunShape ()) + if (hasBegunShape ()) { endShapeInternal (); + } kpAbstractImageSelection *imageSel = document ()->imageSelection (); - if (imageSel->hasContent () && newTrans.isTransparent ()) + if (imageSel->hasContent () && newTrans.isTransparent ()) { environ ()->flashColorSimilarityToolBarItem (); + } imageSel->setTransparency (newTrans); @@ -145,8 +148,9 @@ qCDebug(kpLogTools) << "kpAbstractImageSelectionTool::slotIsOpaqueChanged()"; #endif - if (!shouldChangeImageSelectionTransparency ()) + if (!shouldChangeImageSelectionTransparency ()) { return; + } kpImageSelectionTransparency st = environ ()->imageSelectionTransparency (); @@ -167,8 +171,9 @@ qCDebug(kpLogTools) << "kpAbstractImageSelectionTool::slotBackgroundColorChanged()"; #endif - if (!shouldChangeImageSelectionTransparency ()) + if (!shouldChangeImageSelectionTransparency ()) { return; + } kpImageSelectionTransparency st = environ ()->imageSelectionTransparency (); @@ -187,8 +192,9 @@ qCDebug(kpLogTools) << "kpAbstractImageSelectionTool::slotColorSimilarityChanged()"; #endif - if (!shouldChangeImageSelectionTransparency ()) + if (!shouldChangeImageSelectionTransparency ()) { return; + } kpImageSelectionTransparency st = environ ()->imageSelectionTransparency (); diff --git a/tools/selection/image/kpToolEllipticalSelection.cpp b/tools/selection/image/kpToolEllipticalSelection.cpp --- a/tools/selection/image/kpToolEllipticalSelection.cpp +++ b/tools/selection/image/kpToolEllipticalSelection.cpp @@ -47,9 +47,7 @@ { } -kpToolEllipticalSelection::~kpToolEllipticalSelection () -{ -} +kpToolEllipticalSelection::~kpToolEllipticalSelection () = default; // protected virtual [base kpAbstractSelectionTool] diff --git a/tools/selection/image/kpToolFreeFormSelection.cpp b/tools/selection/image/kpToolFreeFormSelection.cpp --- a/tools/selection/image/kpToolFreeFormSelection.cpp +++ b/tools/selection/image/kpToolFreeFormSelection.cpp @@ -52,9 +52,7 @@ //--------------------------------------------------------------------- -kpToolFreeFormSelection::~kpToolFreeFormSelection () -{ -} +kpToolFreeFormSelection::~kpToolFreeFormSelection () = default; //--------------------------------------------------------------------- @@ -68,7 +66,7 @@ qCDebug(kpLogTools) << "kpToolFreeFormSelection::createMoreSelectionAndUpdateStatusBar(" << "dragAccepted=" << dragAccepted << ",accidentalDragAdjustedPoint=" << accidentalDragAdjustedPoint - << ")" << endl; + << ")"; #endif // Prevent unintentional creation of 1-pixel selections. @@ -103,8 +101,9 @@ // Not first point in drag. else { - if ( !oldPointsSel ) // assert above says we never reach this, but let's make coverity happy - return false; + if ( !oldPointsSel ) { // assert above says we never reach this, but let's make coverity happy + return false; + } // Get existing points in selection. points = oldPointsSel->cardinallyAdjacentPoints (); @@ -129,8 +128,7 @@ #if DEBUG_KP_TOOL_FREE_FROM_SELECTION && 1 qCDebug(kpLogTools) << "\t\tfreeform; #points=" - << document ()->selection ()->calculatePoints ().count () - << endl; + << document ()->selection ()->calculatePoints ().count (); #endif setUserShapePoints (accidentalDragAdjustedPoint); diff --git a/tools/selection/image/kpToolRectSelection.cpp b/tools/selection/image/kpToolRectSelection.cpp --- a/tools/selection/image/kpToolRectSelection.cpp +++ b/tools/selection/image/kpToolRectSelection.cpp @@ -45,9 +45,7 @@ { } -kpToolRectSelection::~kpToolRectSelection () -{ -} +kpToolRectSelection::~kpToolRectSelection () = default; // protected virtual [base kpAbstractSelectionTool] diff --git a/tools/selection/kpAbstractSelectionTool.cpp b/tools/selection/kpAbstractSelectionTool.cpp --- a/tools/selection/kpAbstractSelectionTool.cpp +++ b/tools/selection/kpAbstractSelectionTool.cpp @@ -142,7 +142,7 @@ { kpToolEnvironment *e = kpTool::environ (); Q_ASSERT (dynamic_cast (e)); - return static_cast (e); + return dynamic_cast (e); } //--------------------------------------------------------------------- @@ -160,7 +160,7 @@ { #if DEBUG_KP_TOOL_SELECTION && 1 qCDebug(kpLogTools) << "kpAbstractSelectionTool::pushOntoDocument() selection=" - << document ()->selection () << endl; + << document ()->selection (); #endif Q_ASSERT (document ()->selection ()); environ ()->deselectSelection (); @@ -174,11 +174,13 @@ kpAbstractSelection *sel = document ()->selection (); Q_ASSERT (sel); - if (sel->hasContent ()) + if (sel->hasContent ()) { return; + } - if (d->currentSelContentCommand) + if (d->currentSelContentCommand) { return; + } d->currentSelContentCommand = /*virtual*/newGiveContentCommand (); d->currentSelContentCommand->execute (); @@ -252,12 +254,12 @@ #if DEBUG_KP_TOOL_SELECTION && 0 qCDebug(kpLogTools) << "kpAbstractSelectionTool::haventBegunDrawUserMessage()" " cancelledShapeButStillHoldingButtons=" - << d->cancelledShapeButStillHoldingButtons - << endl; + << d->cancelledShapeButStillHoldingButtons; #endif - if (d->cancelledShapeButStillHoldingButtons) + if (d->cancelledShapeButStillHoldingButtons) { return i18n ("Let go of all the mouse buttons."); + } return operation (calculateDrawType (), HaventBegunDrawUserMessage).toString (); } @@ -313,8 +315,9 @@ qCDebug(kpLogTools) << "kpAbstractSelectionTool<" << objectName () << ">::end()"; #endif - if (document ()->selection ()) + if (document ()->selection ()) { pushOntoDocument (); + } endCreate (); @@ -353,8 +356,9 @@ qCDebug(kpLogTools) << "kpAbstractSelectionTool::reselect()"; #endif - if (document ()->selection ()) + if (document ()->selection ()) { pushOntoDocument (); + } } //--------------------------------------------------------------------- @@ -374,18 +378,22 @@ kpAbstractSelectionTool::DrawType kpAbstractSelectionTool::calculateDrawType () const { kpAbstractSelection *sel = document ()->selection (); - if (!sel) + if (!sel) { return Create; + } #if DEBUG_KP_TOOL_SELECTION qCDebug(kpLogTools) << "\thas sel region rect=" << sel->boundingRect (); #endif - if (onSelectionResizeHandle () && !controlOrShiftPressed ()) + if (onSelectionResizeHandle () && !controlOrShiftPressed ()) { return ResizeScale; - else if (sel->contains (currentPoint ())) + } + + if (sel->contains (currentPoint ())) { return /*virtual*/calculateDrawTypeInsideSelection (); - else - return Create; + } + + return Create; } //--------------------------------------------------------------------- @@ -397,8 +405,7 @@ qCDebug(kpLogTools) << "kpAbstractSelectionTool::beginDraw() startPoint ()=" << startPoint () << " QCursor::pos() view startPoint=" - << viewUnderStartPoint ()->mapFromGlobal (QCursor::pos ()) - << endl; + << viewUnderStartPoint ()->mapFromGlobal (QCursor::pos ()); #endif // endDraw() and cancelShape() should have taken care of these. @@ -449,8 +456,9 @@ } QString mess = haventBegunDrawUserMessage (); - if (mess != userMessage ()) + if (mess != userMessage ()) { setUserMessage (mess); + } } //--------------------------------------------------------------------- @@ -463,7 +471,7 @@ #if DEBUG_KP_TOOL_SELECTION && 1 qCDebug(kpLogTools) << "kpAbstractSelectionTool::draw (" << thisPoint << ",startPoint=" << startPoint () - << ",normalizedRect=" << normalizedRect << ")" << endl; + << ",normalizedRect=" << normalizedRect << ")"; #else Q_UNUSED (thisPoint); Q_UNUSED (normalizedRect); @@ -486,7 +494,7 @@ { #if DEBUG_KP_TOOL_SELECTION qCDebug(kpLogTools) << "kpAbstractSelectionTool::cancelShape() mouseButton=" - << mouseButton () << endl; + << mouseButton (); #endif const DrawType oldDrawType = d->drawType; @@ -591,8 +599,9 @@ ::AssertAllTimersInactive (d); - if (mouseButton () == 1/*right*/) + if (mouseButton () == 1/*right*/) { popupRMBMenu (); + } // WARNING: Do not place any code after the popupRMBMenu() call diff --git a/tools/selection/kpAbstractSelectionTool_Create.cpp b/tools/selection/kpAbstractSelectionTool_Create.cpp --- a/tools/selection/kpAbstractSelectionTool_Create.cpp +++ b/tools/selection/kpAbstractSelectionTool_Create.cpp @@ -140,8 +140,9 @@ // private void kpAbstractSelectionTool::beginDrawCreate () { - if (document ()->selection ()) + if (document ()->selection ()) { pushOntoDocument (); + } /*virtual*/setSelectionBorderForBeginDrawCreate (); @@ -157,13 +158,11 @@ const QRect &normalizedRect) { #if DEBUG_KP_TOOL_SELECTION && 1 - qCDebug(kpLogTools) << "\tnot moving - resizing rect to" << normalizedRect - << endl; + qCDebug(kpLogTools) << "\tnot moving - resizing rect to" << normalizedRect; qCDebug(kpLogTools) << "\t\tcreateNOPTimer->isActive()=" << d->createNOPTimer->isActive () << " viewManhattanLength from startPoint=" - << viewUnderStartPoint ()->transformDocToViewX ((thisPoint - startPoint ()).manhattanLength ()) - << endl; + << viewUnderStartPoint ()->transformDocToViewX ((thisPoint - startPoint ()).manhattanLength ()); #endif QPoint accidentalDragAdjustedPoint = thisPoint; @@ -197,8 +196,9 @@ d->dragAccepted, accidentalDragAdjustedPoint, normalizedRect); - if (oldDrawAcceptedAsDrag) + if (oldDrawAcceptedAsDrag) { Q_ASSERT (d->dragAccepted); + } if (d->dragAccepted) { #if DEBUG_KP_TOOL_SELECTION && 1 @@ -209,8 +209,9 @@ } // Did we just create a selection? - if (!hadSelection && document ()->selection ()) + if (!hadSelection && document ()->selection ()) { viewManager ()->setSelectionBorderVisible (true); + } } // private slot @@ -221,8 +222,7 @@ << hasBegunDraw () << " currentPoint=" << currentPoint () << " lastPoint=" << lastPoint () - << " startPoint=" << startPoint () - << endl; + << " startPoint=" << startPoint (); #endif // (just in case not called from single shot) @@ -245,8 +245,9 @@ d->createNOPTimer->stop (); // TODO: should we give the user back the selection s/he had before (if any)? - if (document ()->selection ()) + if (document ()->selection ()) { document ()->selectionDelete (); + } } // private diff --git a/tools/selection/kpAbstractSelectionTool_KeyboardEvents.cpp b/tools/selection/kpAbstractSelectionTool_KeyboardEvents.cpp --- a/tools/selection/kpAbstractSelectionTool_KeyboardEvents.cpp +++ b/tools/selection/kpAbstractSelectionTool_KeyboardEvents.cpp @@ -48,7 +48,7 @@ { #if DEBUG_KP_TOOL_SELECTION && 0 qCDebug(kpLogTools) << "kpAbstractSelectionTool::keyPressEvent(e->text='" - << e->text () << "')" << endl; + << e->text () << "')"; #endif e->ignore (); @@ -58,8 +58,7 @@ e->key () == Qt::Key_Escape) { #if DEBUG_KP_TOOL_SELECTION && 0 - qCDebug(kpLogTools) << "\tescape pressed with sel when not begun draw - deselecting" - << endl; + qCDebug(kpLogTools) << "\tescape pressed with sel when not begun draw - deselecting"; #endif pushOntoDocument (); @@ -70,8 +69,7 @@ #if DEBUG_KP_TOOL_SELECTION && 0 qCDebug(kpLogTools) << "\tkey processing did not accept (text was '" << e->text () - << "') - passing on event to kpTool" - << endl; + << "') - passing on event to kpTool"; #endif if ( document()->selection() && !hasBegunDraw() && diff --git a/tools/selection/kpAbstractSelectionTool_Move.cpp b/tools/selection/kpAbstractSelectionTool_Move.cpp --- a/tools/selection/kpAbstractSelectionTool_Move.cpp +++ b/tools/selection/kpAbstractSelectionTool_Move.cpp @@ -171,8 +171,9 @@ /*virtual*/setSelectionBorderForBeginDrawMove (); kpAbstractSelection * const sel = document ()->selection (); - if (sel) + if (sel) { setUserShapePoints (sel->topLeft ()); + } } //--------------------------------------------------------------------- @@ -195,22 +196,25 @@ qCDebug(kpLogTools) << "\t\tstartPoint=" << startPoint () << " thisPoint=" << thisPoint << " startDragFromSel=" << d->startMoveDragFromSelectionTopLeft - << " targetSelRect=" << targetSelRect - << endl; + << " targetSelRect=" << targetSelRect; #endif // Try to make sure selection still intersects document so that it's // reachable. - if (targetSelRect.right () < 0) + if (targetSelRect.right () < 0) { targetSelRect.translate (-targetSelRect.right (), 0); - else if (targetSelRect.left () >= document ()->width ()) + } + else if (targetSelRect.left () >= document ()->width ()) { targetSelRect.translate (document ()->width () - targetSelRect.left () - 1, 0); + } - if (targetSelRect.bottom () < 0) + if (targetSelRect.bottom () < 0) { targetSelRect.translate (0, -targetSelRect.bottom ()); - else if (targetSelRect.top () >= document ()->height ()) + } + else if (targetSelRect.top () >= document ()->height ()) { targetSelRect.translate (0, document ()->height () - targetSelRect.top () - 1); + } #if DEBUG_KP_TOOL_SELECTION && 1 qCDebug(kpLogTools) << "\t\t\tafter ensure sel rect clickable=" << targetSelRect; @@ -258,16 +262,19 @@ //viewManager ()->setQueueUpdates (); //viewManager ()->setFastUpdates (); - if (shiftPressed ()) + if (shiftPressed ()) { d->currentMoveCommandIsSmear = true; + } - if (!d->dragAccepted && (controlPressed () || shiftPressed ())) + if (!d->dragAccepted && (controlPressed () || shiftPressed ())) { d->currentMoveCommand->copyOntoDocument (); + } d->currentMoveCommand->moveTo (targetSelRect.topLeft ()); - if (shiftPressed ()) + if (shiftPressed ()) { d->currentMoveCommand->copyOntoDocument (); + } //viewManager ()->restoreFastUpdates (); //viewManager ()->restoreQueueUpdates (); @@ -296,8 +303,9 @@ d->RMBMoveUpdateGUITimer->stop (); // NOP drag? - if (!d->currentMoveCommand) + if (!d->currentMoveCommand) { return; + } #if DEBUG_KP_TOOL_SELECTION qCDebug(kpLogTools) << "\t\tundo currentMoveCommand"; @@ -324,8 +332,9 @@ d->RMBMoveUpdateGUITimer->stop (); // NOP drag? - if (!d->currentMoveCommand) + if (!d->currentMoveCommand) { return; + } d->currentMoveCommand->finalize (); diff --git a/tools/selection/kpAbstractSelectionTool_ResizeScale.cpp b/tools/selection/kpAbstractSelectionTool_ResizeScale.cpp --- a/tools/selection/kpAbstractSelectionTool_ResizeScale.cpp +++ b/tools/selection/kpAbstractSelectionTool_ResizeScale.cpp @@ -57,8 +57,9 @@ int kpAbstractSelectionTool::onSelectionResizeHandle () const { kpView *v = viewManager ()->viewUnderCursor (); - if (!v) + if (!v) { return 0; + } return v->mouseOnSelectionResizeHandle (currentViewPoint ()); } @@ -108,7 +109,7 @@ { #if DEBUG_KP_TOOL_SELECTION && 0 qCDebug(kpLogTools) << "\tonSelectionResizeHandle=" - << onSelectionResizeHandle () << endl; + << onSelectionResizeHandle (); #endif Qt::CursorShape shape = Qt::ArrowCursor; @@ -215,10 +216,12 @@ // If left, positive X drags decrease width. // If right, positive X drags increase width. int userXSign = 0; - if (d->resizeScaleType & kpView::Left) + if (d->resizeScaleType & kpView::Left) { userXSign = -1; - else if (d->resizeScaleType & kpView::Right) + } + else if (d->resizeScaleType & kpView::Right) { userXSign = +1; + } // Calcluate new width. *newWidth = originalSelection.width () + @@ -237,10 +240,12 @@ // If top, positive Y drags decrease height. // If bottom, positive Y drags increase height. int userYSign = 0; - if (d->resizeScaleType & kpView::Top) + if (d->resizeScaleType & kpView::Top) { userYSign = -1; - else if (d->resizeScaleType & kpView::Bottom) + } + else if (d->resizeScaleType & kpView::Bottom) { userYSign = +1; + } // Calcluate new height. *newHeight = originalSelection.height () + @@ -284,8 +289,7 @@ qCDebug(kpLogTools) << "\t\tnewX=" << *newX << " newY=" << *newY << " newWidth=" << *newWidth - << " newHeight=" << *newHeight - << endl; + << " newHeight=" << *newHeight; #endif } @@ -370,8 +374,9 @@ #endif // NOP drag? - if (!d->currentResizeScaleCommand) + if (!d->currentResizeScaleCommand) { return; + } #if DEBUG_KP_TOOL_SELECTION qCDebug(kpLogTools) << "\t\tundo currentResizeScaleCommand"; @@ -388,8 +393,9 @@ void kpAbstractSelectionTool::endDrawResizeScale () { // NOP drag? - if (!d->currentResizeScaleCommand) + if (!d->currentResizeScaleCommand) { return; + } d->currentResizeScaleCommand->finalize (); diff --git a/tools/selection/text/kpToolText.cpp b/tools/selection/text/kpToolText.cpp --- a/tools/selection/text/kpToolText.cpp +++ b/tools/selection/text/kpToolText.cpp @@ -72,7 +72,7 @@ #if DEBUG_KP_TOOL_TEXT qCDebug(kpLogTools) << "kpToolText::newGiveContentCommand()" << " textSel=" << textSel - << "; hasContent=" << textSel->hasContent () << endl; + << "; hasContent=" << textSel->hasContent (); #endif Q_ASSERT (textSel && !textSel->hasContent ()); @@ -174,16 +174,18 @@ qCDebug(kpLogTools) << "kpToolText::cancelShape()"; #endif - if (drawType () != None) + if (drawType () != None) { kpAbstractSelectionTool::cancelShape (); + } else if (hasBegunText ()) { endTypingCommands (); commandHistory ()->undo (); } - else + else { kpAbstractSelectionTool::cancelShape (); + } } @@ -194,23 +196,27 @@ qCDebug(kpLogTools) << "kpToolText::endShape()"; #endif - if (drawType () != None) + if (drawType () != None) { kpAbstractSelectionTool::endDraw (thisPoint, normalizedRect); - else if (hasBegunText ()) + } + else if (hasBegunText ()) { endTypingCommands (); - else + } + else { kpAbstractSelectionTool::endDraw (thisPoint, normalizedRect); + } } // protected virtual [base kpAbstractSelectionTool] QVariant kpToolText::operation (DrawType drawType, Operation op, const QVariant &data1, const QVariant &data2) { - if (drawType == SelectText) + if (drawType == SelectText) { return selectTextOperation (op, data1, data2); - else - return kpAbstractSelectionTool::operation (drawType, op, data1, data2); + } + + return kpAbstractSelectionTool::operation (drawType, op, data1, data2); } diff --git a/tools/selection/text/kpToolText_Create.cpp b/tools/selection/text/kpToolText_Create.cpp --- a/tools/selection/text/kpToolText_Create.cpp +++ b/tools/selection/text/kpToolText_Create.cpp @@ -131,71 +131,69 @@ return false; } // We are probably creating a new box. - else - { - // This drag is currently a click -- not a drag. - // As a special case, allow user to create a text box, - // of reasonable ("preferred minimum") size, using a single - // click. - // - // If the user drags further, the normal drag-to-create-a-textbox - // branch [x] will execute and the size will be determined based on - // the size of the drag instead. - #if DEBUG_KP_TOOL_TEXT && 1 - qCDebug(kpLogTools) << "\tclick creating text box"; - #endif - // (Click creating text box with RMB would not be obvious - // since RMB menu most likely hides text box immediately - // afterwards) - // TODO: I suspect this logic is simply too late - // TODO: We setUserShapePoints() on return but didn't before. - if (mouseButton () == 1) - return false/*do not create text box*/; + // This drag is currently a click -- not a drag. + // As a special case, allow user to create a text box, + // of reasonable ("preferred minimum") size, using a single + // click. + // + // If the user drags further, the normal drag-to-create-a-textbox + // branch [x] will execute and the size will be determined based on + // the size of the drag instead. +#if DEBUG_KP_TOOL_TEXT && 1 + qCDebug(kpLogTools) << "\tclick creating text box"; +#endif + + // (Click creating text box with RMB would not be obvious + // since RMB menu most likely hides text box immediately + // afterwards) + // TODO: I suspect this logic is simply too late + // TODO: We setUserShapePoints() on return but didn't before. + if (mouseButton () == 1) { + return false/*do not create text box*/; + } - // Calculate suggested width. - *minimumWidthOut = calcClickCreateDimension ( - startPoint ().x (), + + // Calculate suggested width. + *minimumWidthOut = calcClickCreateDimension ( + startPoint ().x (), accidentalDragAdjustedPoint.x (), - kpTextSelection::PreferredMinimumWidthForTextStyle (textStyle), + kpTextSelection::PreferredMinimumWidthForTextStyle (textStyle), kpTextSelection::MinimumWidthForTextStyle (textStyle), - document ()->width ()); + document ()->width ()); - // Calculate suggested height. - *minimumHeightOut = calcClickCreateDimension ( - startPoint ().y (), + // Calculate suggested height. + *minimumHeightOut = calcClickCreateDimension ( + startPoint ().y (), accidentalDragAdjustedPoint.y (), - kpTextSelection::PreferredMinimumHeightForTextStyle (textStyle), + kpTextSelection::PreferredMinimumHeightForTextStyle (textStyle), kpTextSelection::MinimumHeightForTextStyle (textStyle), - document ()->height ()); + document ()->height ()); - // Do _not_ set "newDragAccepted" to true as we want - // this text box to remain at the click-given size, in the absence - // of any dragging. In other words, if draw() is called again - // and therefore, we are called again, but the mouse has not - // moved, we do want this branch to execute again, not - // Branch [x]. - return true/*do create text box*/; - } + // Do _not_ set "newDragAccepted" to true as we want + // this text box to remain at the click-given size, in the absence + // of any dragging. In other words, if draw() is called again + // and therefore, we are called again, but the mouse has not + // moved, we do want this branch to execute again, not + // Branch [x]. + return true/*do create text box*/; } // Dragging to create a text box [x]. // // The size will be determined based on the size of the drag. - else - { - #if DEBUG_KP_TOOL_TEXT && 1 - qCDebug(kpLogTools) << "\tdrag creating text box"; - #endif - *minimumWidthOut = kpTextSelection::MinimumWidthForTextStyle (textStyle); - *minimumHeightOut = kpTextSelection::MinimumHeightForTextStyle (textStyle); - *newDragAccepted = true; - return true/*do create text box*/; - } +#if DEBUG_KP_TOOL_TEXT && 1 + qCDebug(kpLogTools) << "\tdrag creating text box"; +#endif + *minimumWidthOut = kpTextSelection::MinimumWidthForTextStyle (textStyle); + *minimumHeightOut = kpTextSelection::MinimumHeightForTextStyle (textStyle); + + *newDragAccepted = true; + return true/*do create text box*/; } // protected virtual [kpAbstractSelectionTool] @@ -230,27 +228,30 @@ // calculated. if (normalizedRect.width () < minimumWidth) { - if (accidentalDragAdjustedPoint.x () >= startPoint ().x ()) + if (accidentalDragAdjustedPoint.x () >= startPoint ().x ()) { normalizedRect.setWidth (minimumWidth); - else + } + else { normalizedRect.setX (normalizedRect.right () - minimumWidth + 1); + } } // Make sure the dragged out rectangle is of the minimum height we just // calculated. if (normalizedRect.height () < minimumHeight) { - if (accidentalDragAdjustedPoint.y () >= startPoint ().y ()) + if (accidentalDragAdjustedPoint.y () >= startPoint ().y ()) { normalizedRect.setHeight (minimumHeight); - else + } + else { normalizedRect.setY (normalizedRect.bottom () - minimumHeight + 1); + } } #if DEBUG_KP_TOOL_TEXT && 1 qCDebug(kpLogTools) << "\t\tnormalizedRect=" << normalizedRect << " kpTextSelection::preferredMinimumSize=" - << QSize (minimumWidth, minimumHeight) - << endl; + << QSize (minimumWidth, minimumHeight); #endif @@ -272,14 +273,18 @@ // QPoint actualEndPoint = KP_INVALID_POINT; - if (startPoint () == normalizedRect.topLeft ()) + if (startPoint () == normalizedRect.topLeft ()) { actualEndPoint = normalizedRect.bottomRight (); - else if (startPoint () == normalizedRect.bottomRight ()) + } + else if (startPoint () == normalizedRect.bottomRight ()) { actualEndPoint = normalizedRect.topLeft (); - else if (startPoint () == normalizedRect.topRight ()) + } + else if (startPoint () == normalizedRect.topRight ()) { actualEndPoint = normalizedRect.bottomLeft (); - else if (startPoint () == normalizedRect.bottomLeft ()) + } + else if (startPoint () == normalizedRect.bottomLeft ()) { actualEndPoint = normalizedRect.topRight (); + } setUserShapePoints (startPoint (), actualEndPoint); diff --git a/tools/selection/text/kpToolText_CursorCalc.cpp b/tools/selection/text/kpToolText_CursorCalc.cpp --- a/tools/selection/text/kpToolText_CursorCalc.cpp +++ b/tools/selection/text/kpToolText_CursorCalc.cpp @@ -68,8 +68,9 @@ bool kpToolText::CursorIsAtEnd (const QList &textLines, int cursorRow, int cursorCol) { - if (textLines.isEmpty ()) + if (textLines.isEmpty ()) { return (cursorRow == 0 && cursorCol == 0); + } return (cursorRow == textLines.size () - 1 && cursorCol == textLines [cursorRow].length ()); @@ -80,8 +81,9 @@ void kpToolText::MoveCursorLeft (const QList &textLines, int *cursorRow, int *cursorCol) { - if (textLines.isEmpty ()) + if (textLines.isEmpty ()) { return; + } (*cursorCol)--; @@ -93,17 +95,19 @@ *cursorRow = 0; *cursorCol = 0; } - else + else { *cursorCol = textLines [*cursorRow].length (); + } } } // protected static void kpToolText::MoveCursorRight (const QList &textLines, int *cursorRow, int *cursorCol) { - if (textLines.isEmpty ()) + if (textLines.isEmpty ()) { return; + } (*cursorCol)++; @@ -115,8 +119,9 @@ *cursorRow = textLines.size () - 1; *cursorCol = textLines [*cursorRow].length (); } - else + else { *cursorCol = 0; + } } } @@ -127,8 +132,9 @@ int kpToolText::MoveCursorToWordStart (const QList &textLines, int *cursorRow, int *cursorCol) { - if (textLines.isEmpty ()) + if (textLines.isEmpty ()) { return 0; + } int numMoves = 0; @@ -142,8 +148,9 @@ // (these comments will exclude the row=0,col=0 boundary case) - if (IS_ON_ANCHOR ()) + if (IS_ON_ANCHOR ()) { MOVE_CURSOR_LEFT (); + } // --- now we're not on an anchor point (start of word) --- @@ -173,8 +180,9 @@ int kpToolText::MoveCursorToNextWordStart (const QList &textLines, int *cursorRow, int *cursorCol) { - if (textLines.isEmpty ()) + if (textLines.isEmpty ()) { return 0; + } int numMoves = 0; diff --git a/tools/selection/text/kpToolText_InputMethodEvents.cpp b/tools/selection/text/kpToolText_InputMethodEvents.cpp --- a/tools/selection/text/kpToolText_InputMethodEvents.cpp +++ b/tools/selection/text/kpToolText_InputMethodEvents.cpp @@ -51,8 +51,7 @@ qCDebug(kpLogTools) << "kpToolText::inputMethodEvent() preeditString='" << e->preeditString () << "commitString = " << e->commitString () << " replacementStart=" << e->replacementStart () - << " replacementLength=" << e->replacementLength () - << endl; + << " replacementLength=" << e->replacementLength (); #endif kpTextSelection *textSel = document ()->textSelection (); if (hasBegunDraw() || !textSel) @@ -85,8 +84,9 @@ if (!commitString.isEmpty ()) { // commit string - if (!d->insertCommand) + if (!d->insertCommand) { addNewInsertCommand (&d->insertCommand); + } d->insertCommand->addText (commitString); } diff --git a/tools/selection/text/kpToolText_KeyboardEvents.cpp b/tools/selection/text/kpToolText_KeyboardEvents.cpp --- a/tools/selection/text/kpToolText_KeyboardEvents.cpp +++ b/tools/selection/text/kpToolText_KeyboardEvents.cpp @@ -61,19 +61,18 @@ #if DEBUG_KP_TOOL_TEXT && 0 qCDebug(kpLogTools) << "kpToolText::viewEvent() type=" << e->type () << " isShortcutOverrideEvent=" << isShortcutOverrideEvent - << " haveTextSel=" << haveTextSelection - << endl; + << " haveTextSel=" << haveTextSelection; #endif - if (!isShortcutOverrideEvent || !haveTextSelection) + if (!isShortcutOverrideEvent || !haveTextSelection) { return kpAbstractSelectionTool::viewEvent (e); + } - QKeyEvent *ke = static_cast (e); + auto *ke = dynamic_cast (e); #if DEBUG_KP_TOOL_TEXT qCDebug(kpLogTools) << "kpToolText::viewEvent() key=" << ke->key () << " modifiers=" << ke->modifiers () - << " QChar.isPrint()=" << QChar (ke->key ()).isPrint () - << endl; + << " QChar.isPrint()=" << QChar (ke->key ()).isPrint (); #endif // Can't be shortcut? @@ -202,8 +201,7 @@ #if DEBUG_KP_TOOL_TEXT qCDebug(kpLogTools) << "\tkey processing did not accept (text was '" << e->text () - << "') - passing on event to kpAbstractSelectionTool" - << endl; + << "') - passing on event to kpAbstractSelectionTool"; #endif //if (hasBegunShape ()) // endShape (currentPoint (), normalizedRect ()); diff --git a/tools/selection/text/kpToolText_KeyboardEvents_HandleArrowKeys.cpp b/tools/selection/text/kpToolText_KeyboardEvents_HandleArrowKeys.cpp --- a/tools/selection/text/kpToolText_KeyboardEvents_HandleArrowKeys.cpp +++ b/tools/selection/text/kpToolText_KeyboardEvents_HandleArrowKeys.cpp @@ -57,8 +57,9 @@ qCDebug(kpLogTools) << "\tup pressed"; #endif - if (hasBegunShape ()) + if (hasBegunShape ()) { endShape (currentPoint (), normalizedRect ()); + } if (!textLines.isEmpty () && cursorRow > 0) { @@ -78,8 +79,9 @@ qCDebug(kpLogTools) << "\tdown pressed"; #endif - if (hasBegunShape ()) + if (hasBegunShape ()) { endShape (currentPoint (), normalizedRect ()); + } if (!textLines.isEmpty () && cursorRow < textLines.size () - 1) { @@ -99,8 +101,9 @@ qCDebug(kpLogTools) << "\tleft pressed"; #endif - if (hasBegunShape ()) + if (hasBegunShape ()) { endShape (currentPoint (), normalizedRect ()); + } if (!textLines.isEmpty ()) { @@ -135,8 +138,9 @@ qCDebug(kpLogTools) << "\tright pressed"; #endif - if (hasBegunShape ()) + if (hasBegunShape ()) { endShape (currentPoint (), normalizedRect ()); + } if (!textLines.isEmpty ()) { @@ -172,13 +176,15 @@ qCDebug(kpLogTools) << "\thome pressed"; #endif - if (hasBegunShape ()) + if (hasBegunShape ()) { endShape (currentPoint (), normalizedRect ()); + } if (!textLines.isEmpty ()) { - if (e->modifiers () & Qt::ControlModifier) + if (e->modifiers () & Qt::ControlModifier) { cursorRow = 0; + } cursorCol = 0; @@ -196,13 +202,15 @@ qCDebug(kpLogTools) << "\tend pressed"; #endif - if (hasBegunShape ()) + if (hasBegunShape ()) { endShape (currentPoint (), normalizedRect ()); + } if (!textLines.isEmpty ()) { - if (e->modifiers () & Qt::ControlModifier) + if (e->modifiers () & Qt::ControlModifier) { cursorRow = textLines.size () - 1; + } cursorCol = textLines [cursorRow].length (); diff --git a/tools/selection/text/kpToolText_KeyboardEvents_HandleTypingKeys.cpp b/tools/selection/text/kpToolText_KeyboardEvents_HandleTypingKeys.cpp --- a/tools/selection/text/kpToolText_KeyboardEvents_HandleTypingKeys.cpp +++ b/tools/selection/text/kpToolText_KeyboardEvents_HandleTypingKeys.cpp @@ -61,23 +61,26 @@ { if ((e->modifiers () & Qt::ControlModifier) == 0) { - if (!d->backspaceCommand) + if (!d->backspaceCommand) { addNewBackspaceCommand (&d->backspaceCommand); + } d->backspaceCommand->addBackspace (); } else { - if (!d->backspaceWordCommand) + if (!d->backspaceWordCommand) { addNewBackspaceCommand (&d->backspaceWordCommand); + } const int numMoves = MoveCursorToWordStart (textLines, &cursorRow, &cursorCol); viewManager ()->setQueueUpdates (); { - for (int i = 0; i < numMoves; i++) + for (int i = 0; i < numMoves; i++) { d->backspaceWordCommand->addBackspace (); + } } viewManager ()->restoreQueueUpdates (); @@ -103,15 +106,17 @@ { if ((e->modifiers () & Qt::ControlModifier) == 0) { - if (!d->deleteCommand) + if (!d->deleteCommand) { addNewDeleteCommand (&d->deleteCommand); + } d->deleteCommand->addDelete (); } else { - if (!d->deleteWordCommand) + if (!d->deleteWordCommand) { addNewDeleteCommand (&d->deleteWordCommand); + } // We don't want to know the cursor pos of the next word start // as delete should keep cursor in same pos. @@ -122,8 +127,9 @@ viewManager ()->setQueueUpdates (); { - for (int i = 0; i < numMoves; i++) + for (int i = 0; i < numMoves; i++) { d->deleteWordCommand->addDelete (); + } } viewManager ()->restoreQueueUpdates (); @@ -148,8 +154,9 @@ // It's OK for to be empty. - if (!d->enterCommand) + if (!d->enterCommand) { addNewEnterCommand (&d->enterCommand); + } d->enterCommand->addEnter (); @@ -168,8 +175,9 @@ QString usableText; for (int i = 0; i < e->text ().length (); i++) { - if (e->text ().at (i).isPrint ()) + if (e->text ().at (i).isPrint ()) { usableText += e->text ().at (i); + } } #if DEBUG_KP_TOOL_TEXT qCDebug(kpLogTools) << "\tusableText=" << usableText; @@ -184,8 +192,9 @@ // --- It's OK for to be empty. --- - if (!d->insertCommand) + if (!d->insertCommand) { addNewInsertCommand (&d->insertCommand); + } d->insertCommand->addText (usableText); diff --git a/tools/selection/text/kpToolText_SelectText.cpp b/tools/selection/text/kpToolText_SelectText.cpp --- a/tools/selection/text/kpToolText_SelectText.cpp +++ b/tools/selection/text/kpToolText_SelectText.cpp @@ -43,8 +43,9 @@ bool kpToolText::onSelectionToSelectText () const { kpView *v = viewManager ()->viewUnderCursor (); - if (!v) - return 0; + if (!v) { + return false; + } return v->mouseOnSelectionToSelectText (currentViewPoint ()); } diff --git a/tools/selection/text/kpToolText_TextStyle.cpp b/tools/selection/text/kpToolText_TextStyle.cpp --- a/tools/selection/text/kpToolText_TextStyle.cpp +++ b/tools/selection/text/kpToolText_TextStyle.cpp @@ -55,8 +55,7 @@ { #if DEBUG_KP_TOOL_TEXT qCDebug(kpLogTools) << "\trecursion - abort setting text style: " - << environ ()->settingTextStyle () - << endl; + << environ ()->settingTextStyle (); #endif return false; } @@ -81,8 +80,9 @@ qCDebug(kpLogTools) << "kpToolText::changeTextStyle(" << name << ")"; #endif - if (hasBegunShape ()) + if (hasBegunShape ()) { endShape (currentPoint (), normalizedRect ()); + } commandHistory ()->addCommand ( new kpToolTextChangeStyleCommand ( @@ -100,8 +100,9 @@ qCDebug(kpLogTools) << "kpToolText::slotIsOpaqueChanged()"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -123,8 +124,9 @@ qCDebug(kpLogTools) << "kpToolText::slotColorsSwapped()"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -144,8 +146,9 @@ qCDebug(kpLogTools) << "kpToolText::slotForegroundColorChanged()"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -164,8 +167,9 @@ qCDebug(kpLogTools) << "kpToolText::slotBackgroundColorChanged()"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -193,14 +197,14 @@ qCDebug(kpLogTools) << "kpToolText::slotFontFamilyChanged() new=" << fontFamily << " old=" - << oldFontFamily - << endl; + << oldFontFamily; #else (void) fontFamily; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -220,14 +224,14 @@ qCDebug(kpLogTools) << "kpToolText::slotFontSizeChanged() new=" << fontSize << " old=" - << oldFontSize - << endl; + << oldFontSize; #else (void) fontSize; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -248,8 +252,9 @@ qCDebug(kpLogTools) << "kpToolText::slotBoldChanged(" << isBold << ")"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -269,8 +274,9 @@ qCDebug(kpLogTools) << "kpToolText::slotItalicChanged(" << isItalic << ")"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -290,8 +296,9 @@ qCDebug(kpLogTools) << "kpToolText::slotUnderlineChanged(" << isUnderline << ")"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); @@ -311,8 +318,9 @@ qCDebug(kpLogTools) << "kpToolText::slotStrikeThruChanged(" << isStrikeThru << ")"; #endif - if (!shouldChangeTextStyle ()) + if (!shouldChangeTextStyle ()) { return; + } kpTextStyle newTextStyle = environ ()->textStyle (); diff --git a/views/kpThumbnailView.cpp b/views/kpThumbnailView.cpp --- a/views/kpThumbnailView.cpp +++ b/views/kpThumbnailView.cpp @@ -48,9 +48,7 @@ { } -kpThumbnailView::~kpThumbnailView () -{ -} +kpThumbnailView::~kpThumbnailView () = default; // protected diff --git a/views/kpUnzoomedThumbnailView.cpp b/views/kpUnzoomedThumbnailView.cpp --- a/views/kpUnzoomedThumbnailView.cpp +++ b/views/kpUnzoomedThumbnailView.cpp @@ -91,8 +91,9 @@ // public slot virtual [base kpView] void kpUnzoomedThumbnailView::adjustToEnvironment () { - if (!buddyView () || !buddyViewScrollableContainer () || !document ()) + if (!buddyView () || !buddyViewScrollableContainer () || !document ()) { return; + } const int scrollViewContentsX = buddyViewScrollableContainer()->horizontalScrollBar()->value(); @@ -107,10 +108,10 @@ const int rightMostAllowedX = qMax (0, document ()->width () - width ()); qCDebug(kpLogViews) << "\tdocX=" << x << " docWidth=" << document ()->width () - << " rightMostAllowedX=" << rightMostAllowedX - << endl; - if (x > rightMostAllowedX) + << " rightMostAllowedX=" << rightMostAllowedX; + if (x > rightMostAllowedX) { x = rightMostAllowedX; + } } // Thumbnail width <= doc width else @@ -128,10 +129,10 @@ const int bottomMostAllowedY = qMax (0, document ()->height () - height ()); qCDebug(kpLogViews) << "\tdocY=" << y << " docHeight=" << document ()->height () - << " bottomMostAllowedY=" << bottomMostAllowedY - << endl; - if (y > bottomMostAllowedY) + << " bottomMostAllowedY=" << bottomMostAllowedY; + if (y > bottomMostAllowedY) { y = bottomMostAllowedY; + } } // Thumbnail height <= doc height else @@ -145,8 +146,9 @@ // But feels awkward for left-to-right users. So disabled for now. // Not totally tested. #else - if (!buddyViewScrollableContainer ()) + if (!buddyViewScrollableContainer ()) { return; + } QRect docRect = buddyView ()->transformViewToDoc ( QRect (buddyViewScrollableContainer ()->horizontalScrollBar()->value(), @@ -157,18 +159,22 @@ x = docRect.x () - (width () - docRect.width ()) / 2; qCDebug(kpLogViews) << "\tnew suggest x=" << x; const int rightMostAllowedX = qMax (0, document ()->width () - width ()); - if (x < 0) + if (x < 0) { x = 0; - if (x > rightMostAllowedX) + } + if (x > rightMostAllowedX) { x = rightMostAllowedX; + } y = docRect.y () - (height () - docRect.height ()) / 2; qCDebug(kpLogViews) << "\tnew suggest y=" << y; const int bottomMostAllowedY = qMax (0, document ()->height () - height ()); - if (y < 0) + if (y < 0) { y = 0; - if (y > bottomMostAllowedY) + } + if (y > bottomMostAllowedY) { y = bottomMostAllowedY; + } #endif @@ -185,8 +191,9 @@ // Above might be a NOP even if e.g. doc size changed so force // update - if (viewManager ()) + if (viewManager ()) { viewManager ()->updateView (this); + } } if (viewManager ()) diff --git a/views/kpView.cpp b/views/kpView.cpp --- a/views/kpView.cpp +++ b/views/kpView.cpp @@ -165,13 +165,13 @@ // public -int kpView::zoomLevelX (void) const +int kpView::zoomLevelX () const { return d->hzoom; } // public -int kpView::zoomLevelY (void) const +int kpView::zoomLevelY () const { return d->vzoom; } @@ -182,14 +182,16 @@ hzoom = qBound (MinZoomLevel, hzoom, MaxZoomLevel); vzoom = qBound (MinZoomLevel, vzoom, MaxZoomLevel); - if (hzoom == d->hzoom && vzoom == d->vzoom) + if (hzoom == d->hzoom && vzoom == d->vzoom) { return; + } d->hzoom = hzoom; d->vzoom = vzoom; - if (viewManager ()) + if (viewManager ()) { viewManager ()->updateView (this); + } emit zoomLevelChanged (hzoom, vzoom); } @@ -214,8 +216,9 @@ d->origin = origin; - if (viewManager ()) + if (viewManager ()) { viewManager ()->updateView (this); + } emit originChanged (origin); } @@ -239,16 +242,19 @@ // public void kpView::showGrid (bool yes) { - if (d->showGrid == yes) + if (d->showGrid == yes) { return; + } - if (yes && !canShowGrid ()) + if (yes && !canShowGrid ()) { return; + } d->showGrid = yes; - if (viewManager ()) + if (viewManager ()) { viewManager ()->updateView (this); + } } @@ -261,8 +267,9 @@ // public void kpView::showBuddyViewScrollableContainerRectangle (bool yes) { - if (yes == d->isBuddyViewScrollableContainerRectangleShown) + if (yes == d->isBuddyViewScrollableContainerRectangleShown) { return; + } d->isBuddyViewScrollableContainerRectangleShown = yes; @@ -347,8 +354,9 @@ // protected slot void kpView::updateBuddyViewScrollableContainerRectangle () { - if (viewManager ()) + if (viewManager ()) { viewManager ()->setQueueUpdates (); + } { if (d->buddyViewScrollableContainerRectangle.isValid ()) @@ -407,8 +415,9 @@ } } - if (viewManager ()) + if (viewManager ()) { viewManager ()->restoreQueueUpdates (); + } } //--------------------------------------------------------------------- @@ -432,8 +441,8 @@ // public QPoint kpView::transformViewToDoc (const QPoint &viewPoint) const { - return QPoint (static_cast (transformViewToDocX (viewPoint.x ())), - static_cast (transformViewToDocY (viewPoint.y ()))); + return {static_cast (transformViewToDocX (viewPoint.x ())), + static_cast (transformViewToDocY (viewPoint.y ()))}; } //--------------------------------------------------------------------- @@ -443,22 +452,19 @@ { if (zoomLevelX () == 100 && zoomLevelY () == 100) { - return QRect (viewRect.x () - origin ().x (), - viewRect.y () - origin ().y (), - viewRect.width (), - viewRect.height ()); + return {viewRect.x () - origin ().x (), viewRect.y () - origin ().y (), + viewRect.width (), viewRect.height ()}; } - else - { - const QPoint docTopLeft = transformViewToDoc (viewRect.topLeft ()); - // (don't call transformViewToDoc[XY]() - need to round up dimensions) - const int docWidth = qRound (double (viewRect.width ()) * 100.0 / double (zoomLevelX ())); - const int docHeight = qRound (double (viewRect.height ()) * 100.0 / double (zoomLevelY ())); + const QPoint docTopLeft = transformViewToDoc (viewRect.topLeft ()); + + // (don't call transformViewToDoc[XY]() - need to round up dimensions) + const auto docWidth = qRound (double (viewRect.width ()) * 100.0 / double (zoomLevelX ())); + const auto docHeight = qRound (double (viewRect.height ()) * 100.0 / double (zoomLevelY ())); + + // (like QWMatrix::Areas) + return {docTopLeft.x (), docTopLeft.y (), docWidth, docHeight}; - // (like QWMatrix::Areas) - return QRect (docTopLeft.x (), docTopLeft.y (), docWidth, docHeight); - } } //--------------------------------------------------------------------- @@ -478,48 +484,45 @@ // public QPoint kpView::transformDocToView (const QPoint &docPoint) const { - return QPoint (static_cast (transformDocToViewX (docPoint.x ())), - static_cast (transformDocToViewY (docPoint.y ()))); + return {static_cast (transformDocToViewX (docPoint.x ())), + static_cast (transformDocToViewY (docPoint.y ()))}; } // public QRect kpView::transformDocToView (const QRect &docRect) const { if (zoomLevelX () == 100 && zoomLevelY () == 100) { - return QRect (docRect.x () + origin ().x (), - docRect.y () + origin ().y (), - docRect.width (), - docRect.height ()); + return {docRect.x () + origin ().x (), docRect.y () + origin ().y (), + docRect.width (), docRect.height ()}; } - else - { - const QPoint viewTopLeft = transformDocToView (docRect.topLeft ()); - // (don't call transformDocToView[XY]() - need to round up dimensions) - const int viewWidth = qRound (double (docRect.width ()) * double (zoomLevelX ()) / 100.0); - const int viewHeight = qRound (double (docRect.height ()) * double (zoomLevelY ()) / 100.0); + const QPoint viewTopLeft = transformDocToView (docRect.topLeft ()); - // (like QWMatrix::Areas) - return QRect (viewTopLeft.x (), viewTopLeft.y (), viewWidth, viewHeight); - } + // (don't call transformDocToView[XY]() - need to round up dimensions) + const int viewWidth = qRound (double (docRect.width ()) * double (zoomLevelX ()) / 100.0); + const int viewHeight = qRound (double (docRect.height ()) * double (zoomLevelY ()) / 100.0); + + // (like QWMatrix::Areas) + return QRect (viewTopLeft.x (), viewTopLeft.y (), viewWidth, viewHeight); } // public QPoint kpView::transformViewToOtherView (const QPoint &viewPoint, const kpView *otherView) { - if (this == otherView) + if (this == otherView) { return viewPoint; + } const double docX = transformViewToDocX (viewPoint.x ()); const double docY = transformViewToDocY (viewPoint.y ()); const double otherViewX = otherView->transformDocToViewX (docX); const double otherViewY = otherView->transformDocToViewY (docY); - return QPoint (static_cast (otherViewX), static_cast (otherViewY)); + return {static_cast (otherViewX), static_cast (otherViewY)}; } @@ -540,18 +543,20 @@ void kpView::setHasMouse (bool yes) { kpViewManager *vm = viewManager (); - if (!vm) + if (!vm) { return; + } qCDebug(kpLogViews) << "kpView(" << objectName () << ")::setHasMouse(" << yes << ") existing viewUnderCursor=" - << (vm->viewUnderCursor () ? vm->viewUnderCursor ()->objectName () : "(none)") - << endl; - if (yes && vm->viewUnderCursor () != this) + << (vm->viewUnderCursor () ? vm->viewUnderCursor ()->objectName () : "(none)"); + if (yes && vm->viewUnderCursor () != this) { vm->setViewUnderCursor (this); - else if (!yes && vm->viewUnderCursor () == this) + } + else if (!yes && vm->viewUnderCursor () == this) { vm->setViewUnderCursor (nullptr); + } } //--------------------------------------------------------------------- @@ -598,14 +603,17 @@ << " fastUpdates=" << (vm && vm->fastUpdates ()) << " area=" << d->queuedUpdateArea; - if (!vm) + if (!vm) { return; + } - if (vm->queueUpdates ()) + if (vm->queueUpdates ()) { return; + } - if (!d->queuedUpdateArea.isEmpty ()) + if (!d->queuedUpdateArea.isEmpty ()) { vm->updateView (this, d->queuedUpdateArea); + } invalidateQueuedArea (); } @@ -615,14 +623,13 @@ // public QPoint kpView::mouseViewPoint (const QPoint &returnViewPoint) const { - if (returnViewPoint != KP_INVALID_POINT) + if (returnViewPoint != KP_INVALID_POINT) { return returnViewPoint; - else - { - // TODO: I don't think this is right for the main view since that's - // inside the scrollview (which can scroll). - return mapFromGlobal (QCursor::pos ()); } + + // TODO: I don't think this is right for the main view since that's + // inside the scrollview (which can scroll). + return mapFromGlobal (QCursor::pos ()); } //--------------------------------------------------------------------- diff --git a/views/kpView_Events.cpp b/views/kpView_Events.cpp --- a/views/kpView_Events.cpp +++ b/views/kpView_Events.cpp @@ -50,8 +50,9 @@ // of the mainView. setHasMouse (rect ().contains (e->pos ())); - if (tool ()) + if (tool ()) { tool ()->mouseMoveEvent (e); + } e->accept (); } @@ -64,8 +65,9 @@ setHasMouse (true); - if (tool ()) + if (tool ()) { tool ()->mousePressEvent (e); + } e->accept (); } @@ -80,8 +82,9 @@ setHasMouse (rect ().contains (e->pos ())); - if (tool ()) + if (tool ()) { tool ()->mouseReleaseEvent (e); + } e->accept (); } @@ -91,8 +94,9 @@ // public virtual [base QWidget] void kpView::wheelEvent (QWheelEvent *e) { - if (tool ()) + if (tool ()) { tool ()->wheelEvent (e); + } } //--------------------------------------------------------------------- @@ -102,8 +106,9 @@ { qCDebug(kpLogViews) << "kpView(" << objectName () << ")::keyPressEvent()" << e->text(); - if (tool ()) + if (tool ()) { tool ()->keyPressEvent (e); + } e->accept (); } @@ -115,8 +120,9 @@ { qCDebug(kpLogViews) << "kpView(" << objectName () << ")::keyReleaseEvent()"; - if (tool ()) + if (tool ()) { tool ()->keyReleaseEvent (e); + } e->accept (); } @@ -128,8 +134,9 @@ { qCDebug(kpLogViews) << "kpView(" << objectName () << ")::inputMethodEvent()"; - if (tool ()) + if (tool ()) { tool ()->inputMethodEvent (e); + } e->accept (); } @@ -152,16 +159,18 @@ void kpView::focusInEvent (QFocusEvent *e) { qCDebug(kpLogViews) << "kpView(" << objectName () << ")::focusInEvent()"; - if (tool ()) + if (tool ()) { tool ()->focusInEvent (e); + } } // protected virtual [base QWidget] void kpView::focusOutEvent (QFocusEvent *e) { qCDebug(kpLogViews) << "kpView(" << objectName () << ")::focusOutEvent()"; - if (tool ()) + if (tool ()) { tool ()->focusOutEvent (e); + } } @@ -181,18 +190,20 @@ // while RMB menu was up) and hence the cursor is not updated. setHasMouse (true); - if (tool ()) + if (tool ()) { tool ()->enterEvent (e); + } } // protected virtual [base QWidget] void kpView::leaveEvent (QEvent *e) { qCDebug(kpLogViews) << "kpView(" << objectName () << ")::leaveEvent()"; setHasMouse (false); - if (tool ()) + if (tool ()) { tool ()->leaveEvent (e); + } } diff --git a/views/kpView_Paint.cpp b/views/kpView_Paint.cpp --- a/views/kpView_Paint.cpp +++ b/views/kpView_Paint.cpp @@ -59,8 +59,9 @@ // From the "we aren't sure whether to round up or round down" department: - if (zoomLevelX () < 100 || zoomLevelY () < 100) + if (zoomLevelX () < 100 || zoomLevelY () < 100) { docRect = transformViewToDoc (viewRect); + } else { // think of a grid - you need to fully cover the zoomed-in pixels @@ -108,12 +109,14 @@ // TODO: % is unpredictable with negatives. int starty = viewRect.y (); - if ((starty - patternOrigin.y ()) % cellSize) + if ((starty - patternOrigin.y ()) % cellSize) { starty -= ((starty - patternOrigin.y ()) % cellSize); + } int startx = viewRect.x (); - if ((startx - patternOrigin.x ()) % cellSize) + if ((startx - patternOrigin.x ()) % cellSize) { startx -= ((startx - patternOrigin.x ()) % cellSize); + } qCDebug(kpLogViews) << "\tstartXY=" << QPoint (startx, starty); @@ -132,13 +135,16 @@ if (parity) { - if (!isPreview) + if (!isPreview) { col = QColor (213, 213, 213); - else + } + else { col = QColor (224, 224, 224); + } } - else + else { col = Qt::white; + } painter->fillRect (x, y, cellSize, cellSize, col); } @@ -154,11 +160,12 @@ { qCDebug(kpLogViews) << "kpView(" << objectName () << ")::paintEventDrawCheckerBoard(viewRect=" << viewRect - << ") origin=" << origin () << endl; + << ") origin=" << origin (); kpDocument *doc = document (); - if (!doc) + if (!doc) { return; + } QPoint patternOrigin = origin (); @@ -217,8 +224,7 @@ kpViewManager *vm = viewManager (); qCDebug(kpLogViews) << "\tsel border visible=" - << vm->selectionBorderVisible () - << endl; + << vm->selectionBorderVisible (); if (vm->selectionBorderVisible ()) { sel->paintBorder (destPixmap, docRect, vm->selectionBorderFinished ()); @@ -235,7 +241,7 @@ // // However, too much selection repaint code assumes that it // only paints inside its kpAbstractSelection::boundingRect(). - kpTextSelection *textSel = dynamic_cast (sel); + auto *textSel = dynamic_cast (sel); if (textSel && vm->textCursorEnabled () && (vm->textCursorBlinkState () || @@ -262,7 +268,7 @@ void kpView::paintEventDrawSelectionResizeHandles (const QRect &clipRect) { qCDebug(kpLogViews) << "kpView::paintEventDrawSelectionResizeHandles(" - << clipRect << ")" << endl; + << clipRect << ")"; if (!selectionLargeEnoughToHaveResizeHandles ()) { @@ -293,27 +299,30 @@ painter.setPen(Qt::black); painter.setBrush(Qt::cyan); - foreach (const QRect &r, selResizeHandlesRegion.rects()) + for (const auto &r : selResizeHandlesRegion.rects()) { painter.drawRect(r); + } } //--------------------------------------------------------------------- // protected void kpView::paintEventDrawTempImage (QImage *destPixmap, const QRect &docRect) { kpViewManager *vm = viewManager (); - if (!vm) + if (!vm) { return; + } const kpTempImage *tpi = vm->tempImage (); qCDebug(kpLogViews) << "kpView::paintEventDrawTempImage() tempImage=" << tpi << " isVisible=" << (tpi ? tpi->isVisible (vm) : false); - if (!tpi || !tpi->isVisible (vm)) + if (!tpi || !tpi->isVisible (vm)) { return; + } tpi->paint (destPixmap, docRect); } @@ -330,19 +339,23 @@ // horizontal lines int starty = viewRect.top(); - if (starty % vzoomMultiple) + if (starty % vzoomMultiple) { starty = (starty + vzoomMultiple) / vzoomMultiple * vzoomMultiple; + } - for (int y = starty; y <= viewRect.bottom(); y += vzoomMultiple) + for (int y = starty; y <= viewRect.bottom(); y += vzoomMultiple) { painter->drawLine(viewRect.left(), y, viewRect.right(), y); + } // vertical lines int startx = viewRect.left(); - if (startx % hzoomMultiple) + if (startx % hzoomMultiple) { startx = (startx + hzoomMultiple) / hzoomMultiple * hzoomMultiple; + } - for (int x = startx; x <= viewRect.right(); x += hzoomMultiple) + for (int x = startx; x <= viewRect.right(); x += hzoomMultiple) { painter->drawLine(x, viewRect.top (), x, viewRect.bottom()); + } } //--------------------------------------------------------------------- @@ -388,8 +401,9 @@ Q_ASSERT (vm); Q_ASSERT (doc); - if (viewRect.isEmpty ()) + if (viewRect.isEmpty ()) { return; + } QRect docRect = paintEventGetDocRect (viewRect); @@ -407,7 +421,7 @@ docPixmap = doc->getImageAt (docRect); qCDebug(kpLogViews) << "\tdocPixmap.hasAlphaChannel()=" - << docPixmap.hasAlphaChannel () << endl; + << docPixmap.hasAlphaChannel (); tempImageWillBeRendered = (!doc->selection () && @@ -485,8 +499,9 @@ << " viewRect=" << e->rect () << " topLeft=" << QPoint (x (), y ()); - if (!vm) + if (!vm) { return; + } if (vm->queueUpdates ()) { @@ -498,13 +513,14 @@ } kpDocument *doc = document (); - if (!doc) + if (!doc) { return; + } // It seems that e->region() is already clipped by Qt to the visible // part of the view (which could be quite small inside a scrollview). - QRegion viewRegion = e->region (); + const auto& viewRegion = e->region (); QVector rects = viewRegion.rects (); qCDebug(kpLogViews) << "\t#rects = " << rects.count (); @@ -520,7 +536,7 @@ // parts of nearby grid lines (which were drawn in a previous iteration) // with document pixels. Those grid line parts are probably not going to // be redrawn, so will appear to be missing. - foreach (const QRect &r, rects) + for (const auto &r : rects) { paintEventDrawDoc_Unclipped (r); } @@ -532,7 +548,7 @@ if ( isGridShown() ) { QPainter painter(this); - foreach (const QRect &r, rects) + for (const auto &r : rects) paintEventDrawGridLines(&painter, r); } diff --git a/views/kpView_Selections.cpp b/views/kpView_Selections.cpp --- a/views/kpView_Selections.cpp +++ b/views/kpView_Selections.cpp @@ -47,43 +47,49 @@ // public QPoint kpView::mouseViewPointRelativeToSelection (const QPoint &viewPoint) const { - if (!selection ()) + if (!selection ()) { return KP_INVALID_POINT; + } return mouseViewPoint (viewPoint) - transformDocToView (selection ()->topLeft ()); } // public bool kpView::mouseOnSelection (const QPoint &viewPoint) const { const QRect selViewRect = selectionViewRect (); - if (!selViewRect.isValid ()) + if (!selViewRect.isValid ()) { return false; + } return selViewRect.contains (mouseViewPoint (viewPoint)); } // public int kpView::textSelectionMoveBorderAtomicSize () const { - if (!textSelection ()) + if (!textSelection ()) { return 0; + } return qMax (4, zoomLevelX () / 100); } // public bool kpView::mouseOnSelectionToMove (const QPoint &viewPoint) const { - if (!mouseOnSelection (viewPoint)) + if (!mouseOnSelection (viewPoint)) { return false; + } - if (!textSelection ()) + if (!textSelection ()) { return true; + } - if (mouseOnSelectionResizeHandle (viewPoint)) + if (mouseOnSelectionResizeHandle (viewPoint)) { return false; + } const QPoint viewPointRelSel = mouseViewPointRelativeToSelection (viewPoint); @@ -111,8 +117,9 @@ // protected bool kpView::selectionLargeEnoughToHaveResizeHandlesIfAtomicSize (int atomicSize) const { - if (!selection ()) + if (!selection ()) { return false; + } const QRect selViewRect = selectionViewRect (); @@ -149,8 +156,9 @@ QRegion kpView::selectionResizeHandlesViewRegion (bool forRenderer) const { const int atomicLength = selectionResizeHandleAtomicSize (); - if (atomicLength <= 0) + if (atomicLength <= 0) { return QRegion (); + } // HACK: At low zoom (e.g. 100%), resize handles will probably be too @@ -169,20 +177,24 @@ { if (zoomLevelX () <= 150) { - if (normalAtomicLength > 1) + if (normalAtomicLength > 1) { normalAtomicLength--; + } - if (vertEdgeAtomicLength > 1) + if (vertEdgeAtomicLength > 1) { vertEdgeAtomicLength--; + } } // 1 line of text? if (textSelection () && textSelection ()->textLines ().size () == 1) { - if (zoomLevelX () <= 150) + if (zoomLevelX () <= 150) { vertEdgeAtomicLength = qMin (vertEdgeAtomicLength, qMax (2, zoomLevelX () / 100)); - else if (zoomLevelX () <= 250) + } + else if (zoomLevelX () <= 250) { vertEdgeAtomicLength = qMin (vertEdgeAtomicLength, qMax (3, zoomLevelX () / 100)); + } } } @@ -271,41 +283,47 @@ { return kpView::Bottom | kpView::Right; } - else if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, 0)) + + if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, 0)) { return kpView::Top | kpView::Right; } - else if (LOCAL_POINT_IN_BOX_AT (0, selViewRect.height () - atomicLength)) + + if (LOCAL_POINT_IN_BOX_AT (0, selViewRect.height () - atomicLength)) { return kpView::Bottom | kpView::Left; } - else if (LOCAL_POINT_IN_BOX_AT (0, 0)) + + if (LOCAL_POINT_IN_BOX_AT (0, 0)) { return kpView::Top | kpView::Left; } - else if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, + + if (LOCAL_POINT_IN_BOX_AT (selViewRect.width () - atomicLength, (selViewRect.height () - atomicLength) / 2)) { return kpView::Right; } - else if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, + + if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, selViewRect.height () - atomicLength)) { return kpView::Bottom; } - else if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, 0)) + + if (LOCAL_POINT_IN_BOX_AT ((selViewRect.width () - atomicLength) / 2, 0)) { return kpView::Top; } - else if (LOCAL_POINT_IN_BOX_AT (0, (selViewRect.height () - atomicLength) / 2)) + + if (LOCAL_POINT_IN_BOX_AT (0, (selViewRect.height () - atomicLength) / 2)) { return kpView::Left; } - else - { - qCDebug(kpLogViews) << "\tnot on sel resize handle"; - return 0; - } + + qCDebug(kpLogViews) << "\tnot on sel resize handle"; + return 0; + #undef LOCAL_POINT_IN_BOX_AT } diff --git a/views/kpZoomedThumbnailView.cpp b/views/kpZoomedThumbnailView.cpp --- a/views/kpZoomedThumbnailView.cpp +++ b/views/kpZoomedThumbnailView.cpp @@ -53,9 +53,7 @@ } -kpZoomedThumbnailView::~kpZoomedThumbnailView () -{ -} +kpZoomedThumbnailView::~kpZoomedThumbnailView () = default; // public virtual [base kpThumbnailView] @@ -68,30 +66,32 @@ // public slot virtual [base kpView] void kpZoomedThumbnailView::adjustToEnvironment () { - if (!document ()) + if (!document ()) { return; + } qCDebug(kpLogViews) << "\tdoc: width=" << document ()->width () << " height=" << document ()->height (); if (document ()->width () <= 0 || document ()->height () <= 0) { qCCritical(kpLogViews) << "kpZoomedThumbnailView::adjustToEnvironment() doc:" << " width=" << document ()->width () - << " height=" << document ()->height () - << endl; + << " height=" << document ()->height (); return; } int hzoom = qMax (1, width () * 100 / document ()->width ()); int vzoom = qMax (1, height () * 100 / document ()->height ()); // keep aspect ratio - if (hzoom < vzoom) + if (hzoom < vzoom) { vzoom = hzoom; - else + } + else { hzoom = vzoom; + } qCDebug(kpLogViews) << "\tproposed zoom=" << hzoom; if (hzoom > 100 || vzoom > 100) @@ -102,22 +102,25 @@ } - if (viewManager ()) + if (viewManager ()) { viewManager ()->setQueueUpdates (); + } { setZoomLevel (hzoom, vzoom); setOrigin (QPoint ((width () - zoomedDocWidth ()) / 2, (height () - zoomedDocHeight ()) / 2)); setMaskToCoverDocument (); - if (viewManager ()) + if (viewManager ()) { viewManager ()->updateView (this); + } } - if (viewManager ()) + if (viewManager ()) { viewManager ()->restoreQueueUpdates (); + } } diff --git a/views/kpZoomedView.cpp b/views/kpZoomedView.cpp --- a/views/kpZoomedView.cpp +++ b/views/kpZoomedView.cpp @@ -54,25 +54,25 @@ adjustToEnvironment (); } -kpZoomedView::~kpZoomedView () -{ -} +kpZoomedView::~kpZoomedView () = default; // public virtual [base kpView] void kpZoomedView::setZoomLevel (int hzoom, int vzoom) { - if (viewManager ()) + if (viewManager ()) { viewManager ()->setQueueUpdates (); + } { kpView::setZoomLevel (hzoom, vzoom); adjustToEnvironment (); } - if (viewManager ()) + if (viewManager ()) { viewManager ()->restoreQueueUpdates (); + } } diff --git a/views/manager/kpViewManager.cpp b/views/manager/kpViewManager.cpp --- a/views/manager/kpViewManager.cpp +++ b/views/manager/kpViewManager.cpp @@ -119,8 +119,9 @@ Q_ASSERT (view); Q_ASSERT (d->views.contains (view)); - if (view == d->viewUnderCursor) + if (view == d->viewUnderCursor) { d->viewUnderCursor = nullptr; + } view->unsetCursor (); d->views.removeAll (view); @@ -144,18 +145,18 @@ Q_ASSERT (!d->viewUnderCursor || d->views.contains (d->viewUnderCursor)); return d->viewUnderCursor; } - else + + + for (QLinkedList ::const_iterator it = d->views.begin (); + it != d->views.end (); + ++it) { - for (QLinkedList ::const_iterator it = d->views.begin (); - it != d->views.end (); - ++it) - { - if ((*it)->underMouse ()) - return (*it); + if ((*it)->underMouse ()) { + return (*it); } - - return nullptr; } + + return nullptr; } //--------------------------------------------------------------------- @@ -165,15 +166,16 @@ { qCDebug(kpLogViews) << "kpViewManager::setViewUnderCursor (" << (view ? view->objectName () : "(none)") << ")" - << " old=" << (d->viewUnderCursor ? d->viewUnderCursor->objectName () : "(none)") - << endl; - if (view == d->viewUnderCursor) + << " old=" << (d->viewUnderCursor ? d->viewUnderCursor->objectName () : "(none)"); + if (view == d->viewUnderCursor) { return; + } d->viewUnderCursor = view; - if (d->viewUnderCursor) + if (d->viewUnderCursor) { d->viewUnderCursor->setAttribute (Qt::WA_InputMethodEnabled, d->inputMethodEnabled); + } if (!d->viewUnderCursor) { @@ -203,8 +205,9 @@ it != d->views.end (); ++it) { - if ((*it)->isActiveWindow ()) + if ((*it)->isActiveWindow ()) { return true; + } } return false; @@ -257,7 +260,7 @@ << tempImage.isBrush () << ",topLeft=" << tempImage.topLeft () << ",image.rect=" << tempImage.image ().rect () - << ")" << endl; + << ")"; QRect oldRect; @@ -272,8 +275,9 @@ setQueueUpdates (); { - if (oldRect.isValid ()) + if (oldRect.isValid ()) { updateViews (oldRect); + } updateViews (d->tempImage->rect ()); } restoreQueueUpdates (); @@ -284,8 +288,9 @@ // public void kpViewManager::invalidateTempImage () { - if (!d->tempImage) + if (!d->tempImage) { return; + } QRect oldRect = d->tempImage->rect (); @@ -308,13 +313,15 @@ // public void kpViewManager::setSelectionBorderVisible (bool yes) { - if (d->selectionBorderVisible == yes) + if (d->selectionBorderVisible == yes) { return; + } d->selectionBorderVisible = yes; - if (document ()->selection ()) + if (document ()->selection ()) { updateViews (document ()->selection ()->boundingRect ()); + } } //--------------------------------------------------------------------- @@ -330,20 +337,23 @@ // public void kpViewManager::setSelectionBorderFinished (bool yes) { - if (d->selectionBorderFinished == yes) + if (d->selectionBorderFinished == yes) { return; + } d->selectionBorderFinished = yes; - if (document ()->selection ()) + if (document ()->selection ()) { updateViews (document ()->selection ()->boundingRect ()); + } } //--------------------------------------------------------------------- void kpViewManager::setInputMethodEnabled (bool inputMethodEnabled) { d->inputMethodEnabled = inputMethodEnabled; - if (d->viewUnderCursor) + if (d->viewUnderCursor) { d->viewUnderCursor->setAttribute (Qt::WA_InputMethodEnabled, inputMethodEnabled); + } } diff --git a/views/manager/kpViewManager_TextCursor.cpp b/views/manager/kpViewManager_TextCursor.cpp --- a/views/manager/kpViewManager_TextCursor.cpp +++ b/views/manager/kpViewManager_TextCursor.cpp @@ -77,8 +77,9 @@ { qCDebug(kpLogViews) << "kpViewManager::setTextCursorEnabled(" << yes << ")"; - if (yes == textCursorEnabled ()) + if (yes == textCursorEnabled ()) { return; + } delete d->textCursorBlinkTimer; d->textCursorBlinkTimer = nullptr; @@ -115,8 +116,9 @@ // public void kpViewManager::setTextCursorBlinkState (bool on) { - if (on == d->textCursorBlinkState) + if (on == d->textCursorBlinkState) { return; + } d->textCursorBlinkState = on; @@ -139,8 +141,9 @@ // public void kpViewManager::setTextCursorPosition (int row, int col) { - if (row == d->textCursorRow && col == d->textCursorCol) + if (row == d->textCursorRow && col == d->textCursorCol) { return; + } setFastUpdates (); setQueueUpdates (); @@ -165,25 +168,27 @@ QRect kpViewManager::textCursorRect () const { kpTextSelection *textSel = document ()->textSelection (); - if (!textSel) - return QRect (); + if (!textSel) { + return {}; + } QPoint topLeft = textSel->pointForTextRowCol (d->textCursorRow, d->textCursorCol); if (topLeft == KP_INVALID_POINT) { // Text cursor row/col hasn't been specified yet? - if (textSel->hasContent ()) - return QRect (); + if (textSel->hasContent ()) { + return {}; + } // Empty text box should still display a cursor so that the user // knows where typed text will go. topLeft = textSel->textAreaRect ().topLeft (); } Q_ASSERT (topLeft != KP_INVALID_POINT); - return QRect (topLeft.x (), topLeft.y (), - 1, textSel->textStyle ().fontMetrics ().height ()); + return {topLeft.x (), topLeft.y (), + 1, textSel->textStyle ().fontMetrics ().height ()}; } @@ -193,8 +198,9 @@ qCDebug(kpLogViews) << "kpViewManager::updateTextCursor()"; const QRect r = textCursorRect (); - if (!r.isValid ()) + if (!r.isValid ()) { return; + } setFastUpdates (); { @@ -208,7 +214,7 @@ void kpViewManager::slotTextCursorBlink () { qCDebug(kpLogViews) << "kpViewManager::slotTextCursorBlink() cursorBlinkState=" - << d->textCursorBlinkState << endl; + << d->textCursorBlinkState; if (d->textCursorBlinkTimer) { diff --git a/views/manager/kpViewManager_ViewUpdates.cpp b/views/manager/kpViewManager_ViewUpdates.cpp --- a/views/manager/kpViewManager_ViewUpdates.cpp +++ b/views/manager/kpViewManager_ViewUpdates.cpp @@ -66,7 +66,7 @@ { d->queueUpdatesCounter--; qCDebug(kpLogViews) << "kpViewManager::restoreQueueUpdates() counter=" - << d->queueUpdatesCounter << endl; + << d->queueUpdatesCounter; Q_ASSERT (d->queueUpdatesCounter >= 0); if (d->queueUpdatesCounter == 0) @@ -116,13 +116,16 @@ { if (!queueUpdates ()) { - if (fastUpdates ()) + if (fastUpdates ()) { v->repaint (viewRect); - else + } + else { v->update (viewRect); + } } - else + else { v->addToQueuedArea (viewRect); + } } // public slot @@ -136,21 +139,25 @@ { if (!queueUpdates ()) { - if (fastUpdates ()) + if (fastUpdates ()) { v->repaint (viewRegion); - else + } + else { v->update (viewRegion.boundingRect ()); + } } - else + else { v->addToQueuedArea (viewRegion); + } } // public slot void kpViewManager::updateViewRectangleEdges (kpView *v, const QRect &viewRect) { - if (viewRect.height () <= 0 || viewRect.width () <= 0) + if (viewRect.height () <= 0 || viewRect.width () <= 0) { return; + } // Top line updateView (v, QRect (viewRect.x (), viewRect.y (), diff --git a/widgets/colorSimilarity/kpColorSimilarityCubeRenderer.cpp b/widgets/colorSimilarity/kpColorSimilarityCubeRenderer.cpp --- a/widgets/colorSimilarity/kpColorSimilarityCubeRenderer.cpp +++ b/widgets/colorSimilarity/kpColorSimilarityCubeRenderer.cpp @@ -53,25 +53,27 @@ similarityDirection * 0.5 * colorSimilarity * kpColorSimilarityHolder::ColorCubeDiagonalDistance); - if (brightness < 0) + if (brightness < 0) { brightness = 0; - else if (brightness > 255) + } + else if (brightness > 255) { brightness = 255; + } switch (redOrGreenOrBlue) { default: - case 0: return QColor (brightness, highlight, highlight); - case 1: return QColor (highlight, brightness, highlight); - case 2: return QColor (highlight, highlight, brightness); + case 0: return {brightness, highlight, highlight}; + case 1: return {highlight, brightness, highlight}; + case 2: return {highlight, highlight, brightness}; } } //--------------------------------------------------------------------- static QPointF PointBetween(const QPointF &p, const QPointF &q) { - return QPointF((p.x() + q.x()) / 2.0, (p.y() + q.y()) / 2.0); + return {(p.x() + q.x()) / 2.0, (p.y() + q.y()) / 2.0}; } //--------------------------------------------------------------------- @@ -142,7 +144,7 @@ qCDebug(kpLogWidgets) << "\tmaxColorSimilarity=" << kpColorSimilarityHolder::MaxColorSimilarity << " colorCubeDiagDist=" << kpColorSimilarityHolder::ColorCubeDiagonalDistance - << endl + << "\n" << "\tbaseBrightness=" << baseBrightness << " color[0]=" << ((colors [0].rgba() & RGB_MASK) >> ((2 - redOrGreenOrBlue) * 8)) << " color[1]=" << ((colors [1].rgba() & RGB_MASK) >> ((2 - redOrGreenOrBlue) * 8)); diff --git a/widgets/colorSimilarity/kpColorSimilarityFrame.cpp b/widgets/colorSimilarity/kpColorSimilarityFrame.cpp --- a/widgets/colorSimilarity/kpColorSimilarityFrame.cpp +++ b/widgets/colorSimilarity/kpColorSimilarityFrame.cpp @@ -58,7 +58,7 @@ // protected virtual [base QWidget] QSize kpColorSimilarityFrame::sizeHint () const { - return QSize (52, 52); + return {52, 52}; } //--------------------------------------------------------------------- diff --git a/widgets/colorSimilarity/kpColorSimilarityHolder.cpp b/widgets/colorSimilarity/kpColorSimilarityHolder.cpp --- a/widgets/colorSimilarity/kpColorSimilarityHolder.cpp +++ b/widgets/colorSimilarity/kpColorSimilarityHolder.cpp @@ -58,9 +58,7 @@ { } -kpColorSimilarityHolder::~kpColorSimilarityHolder () -{ -} +kpColorSimilarityHolder::~kpColorSimilarityHolder () = default; // Don't cause the translators grief by appending strings etc. @@ -177,13 +175,16 @@ qCDebug(kpLogWidgets) << "kpColorSimilarityHolder::setColorSimilarity(" << similarity << ")"; #endif - if (m_colorSimilarity == similarity) + if (m_colorSimilarity == similarity) { return; + } - if (similarity < 0) + if (similarity < 0) { similarity = 0; - else if (similarity > MaxColorSimilarity) + } + else if (similarity > MaxColorSimilarity) { similarity = MaxColorSimilarity; + } m_colorSimilarity = similarity; } diff --git a/widgets/colorSimilarity/kpColorSimilarityToolBarItem.cpp b/widgets/colorSimilarity/kpColorSimilarityToolBarItem.cpp --- a/widgets/colorSimilarity/kpColorSimilarityToolBarItem.cpp +++ b/widgets/colorSimilarity/kpColorSimilarityToolBarItem.cpp @@ -143,25 +143,28 @@ qCDebug(kpLogWidgets) << "kpColorSimilarityToolBarItem::slotFlashTimerTimeout()" << " highlight=" << m_flashHighlight; int newHigh = m_flashHighlight - 20; - if (newHigh < 0) + if (newHigh < 0) { newHigh = 0; + } m_flashHighlight = newHigh; updateIcon (); - if (newHigh == 0) + if (newHigh == 0) { m_flashTimer->stop (); + } } //--------------------------------------------------------------------- // public void kpColorSimilarityToolBarItem::flash () { qCDebug(kpLogWidgets) << "kpColorSimilarityToolBarItem::flash()"; - if (isSuppressingFlash ()) + if (isSuppressingFlash ()) { return; + } if (m_flashHighlight == 255) { @@ -237,7 +240,7 @@ { const int side = width () * 6 / 8; qCDebug(kpLogWidgets) << "kpColorSimilarityToolBarItem::updateIcon() width=" << width () - << " side=" << side << endl; + << " side=" << side; QPixmap icon(side, side); icon.fill(Qt::transparent); @@ -256,7 +259,7 @@ void kpColorSimilarityToolBarItem::resizeEvent (QResizeEvent *e) { qCDebug(kpLogWidgets) << "kpColorSimilarityToolBarItem::resizeEvent() size=" << size () - << " oldSize=" << e->oldSize () << endl; + << " oldSize=" << e->oldSize (); QToolButton::resizeEvent (e); updateIcon (); diff --git a/widgets/imagelib/effects/kpEffectBalanceWidget.cpp b/widgets/imagelib/effects/kpEffectBalanceWidget.cpp --- a/widgets/imagelib/effects/kpEffectBalanceWidget.cpp +++ b/widgets/imagelib/effects/kpEffectBalanceWidget.cpp @@ -55,45 +55,44 @@ QWidget *parent) : kpEffectWidgetBase (actOnSelection, parent) { - QGridLayout *lay = new QGridLayout (this); + auto *lay = new QGridLayout (this); lay->setContentsMargins(0, 0, 0, 0); - - QLabel *brightnessLabel = new QLabel (i18n ("&Brightness:"), this); + auto *brightnessLabel = new QLabel (i18n ("&Brightness:"), this); m_brightnessInput = new kpIntNumInput (0/*value*/, this); m_brightnessInput->setRange (-50, 50); - QPushButton *brightnessResetPushButton = new QPushButton (i18n ("Re&set"), this); + auto *brightnessResetPushButton = new QPushButton (i18n ("Re&set"), this); - QLabel *contrastLabel = new QLabel (i18n ("Co&ntrast:"), this); + auto *contrastLabel = new QLabel (i18n ("Co&ntrast:"), this); m_contrastInput = new kpIntNumInput (0/*value*/, this); m_contrastInput->setRange (-50, 50); - QPushButton *contrastResetPushButton = new QPushButton (i18n ("&Reset"), this); + auto *contrastResetPushButton = new QPushButton (i18n ("&Reset"), this); - QLabel *gammaLabel = new QLabel (i18n ("&Gamma:"), this); + auto *gammaLabel = new QLabel (i18n ("&Gamma:"), this); m_gammaInput = new kpIntNumInput (0/*value*/, this); m_gammaInput->setRange (-50, 50); // TODO: This is what should be shown in the m_gammaInput spinbox m_gammaLabel = new QLabel (this); // TODO: This doesn't seem to be wide enough with some fonts so the // whole layout moves when we drag the gamma slider. m_gammaLabel->setMinimumWidth (m_gammaLabel->fontMetrics ().width (QLatin1String (" 10.00 "))); m_gammaLabel->setAlignment (m_gammaLabel->alignment () | Qt::AlignRight); - QPushButton *gammaResetPushButton = new QPushButton (i18n ("Rese&t"), this); + auto *gammaResetPushButton = new QPushButton (i18n ("Rese&t"), this); - QWidget *spaceWidget = new QLabel (this); + auto *spaceWidget = new QLabel (this); spaceWidget->setFixedSize (1, fontMetrics ().height () / 4); - QLabel *channelLabel = new QLabel (i18n ("C&hannels:"), this); + auto *channelLabel = new QLabel (i18n ("C&hannels:"), this); m_channelsComboBox = new QComboBox (this); m_channelsComboBox->addItem (i18n ("All")); m_channelsComboBox->addItem (i18n ("Red")); m_channelsComboBox->addItem (i18n ("Green")); m_channelsComboBox->addItem (i18n ("Blue")); - QPushButton *resetPushButton = new QPushButton (i18n ("Reset &All Values"), this); + auto *resetPushButton = new QPushButton (i18n ("Reset &All Values"), this); brightnessLabel->setBuddy (m_brightnessInput); @@ -154,9 +153,7 @@ recalculateGammaLabel (); } -kpEffectBalanceWidget::~kpEffectBalanceWidget () -{ -} +kpEffectBalanceWidget::~kpEffectBalanceWidget () = default; // public virtual [base kpEffectWidgetBase] @@ -246,47 +243,62 @@ // protected slot void kpEffectBalanceWidget::resetBrightness () { - if (brightness () == 0) + if (brightness () == 0) { return; + } bool sb = signalsBlocked (); - if (!sb) blockSignals (true); + if (!sb) { + blockSignals (true); + } m_brightnessInput->setValue (0); - if (!sb) blockSignals (false); + if (!sb) { + blockSignals (false); + } // Immediate update (if signals aren't blocked) emit settingsChanged (); } // protected slot void kpEffectBalanceWidget::resetContrast () { - if (contrast () == 0) + if (contrast () == 0) { return; + } bool sb = signalsBlocked (); - if (!sb) blockSignals (true); + if (!sb) { + blockSignals (true); + } m_contrastInput->setValue (0); - if (!sb) blockSignals (false); + if (!sb) { + blockSignals (false); + } // Immediate update (if signals aren't blocked) emit settingsChanged (); } // protected slot void kpEffectBalanceWidget::resetGamma () { - if (gamma () == 0) + if (gamma () == 0) { return; + } bool sb = signalsBlocked (); - if (!sb) blockSignals (true); + if (!sb) { + blockSignals (true); + } m_gammaInput->setValue (0); recalculateGammaLabel (); - if (!sb) blockSignals (false); + if (!sb) { + blockSignals (false); + } // Immediate update (if signals aren't blocked) emit settingsChanged (); @@ -296,8 +308,9 @@ // protected slot void kpEffectBalanceWidget::resetAll () { - if (isNoOp ()) + if (isNoOp ()) { return; + } // Prevent multiple settingsChanged() which would normally result in // redundant, expensive preview repaints diff --git a/widgets/imagelib/effects/kpEffectBlurSharpenWidget.cpp b/widgets/imagelib/effects/kpEffectBlurSharpenWidget.cpp --- a/widgets/imagelib/effects/kpEffectBlurSharpenWidget.cpp +++ b/widgets/imagelib/effects/kpEffectBlurSharpenWidget.cpp @@ -46,11 +46,10 @@ QWidget *parent) : kpEffectWidgetBase (actOnSelection, parent) { - QGridLayout *lay = new QGridLayout (this); + auto *lay = new QGridLayout (this); lay->setContentsMargins(0, 0, 0, 0); - - QLabel *amountLabel = new QLabel (i18n ("&Amount:"), this); + auto *amountLabel = new QLabel (i18n ("&Amount:"), this); m_amountInput = new kpIntNumInput (this); m_amountInput->setRange (-kpEffectBlurSharpen::MaxStrength/*- for blur*/, +kpEffectBlurSharpen::MaxStrength/*+ for sharpen*/); @@ -65,7 +64,7 @@ // We do this by setting the label to every possible string it could // contain and fixing its height to the maximum seen size hint height. - int h = m_typeLabel->sizeHint ().height (); + auto h = m_typeLabel->sizeHint ().height (); qCDebug(kpLogWidgets) << "initial size hint height=" << h; m_typeLabel->setText ( @@ -105,9 +104,7 @@ this, &kpEffectBlurSharpenWidget::slotUpdateTypeLabel); } -kpEffectBlurSharpenWidget::~kpEffectBlurSharpenWidget () -{ -} +kpEffectBlurSharpenWidget::~kpEffectBlurSharpenWidget () = default; // public virtual [base kpEffectWidgetBase] @@ -145,8 +142,7 @@ { QString text = kpEffectBlurSharpenCommand::nameForType (type ()); - qCDebug(kpLogWidgets) << "kpEffectBlurSharpenWidget::slotUpdateTypeLabel() text=" - << text << endl; + qCDebug(kpLogWidgets) << "kpEffectBlurSharpenWidget::slotUpdateTypeLabel() text=" << text; const int h = m_typeLabel->height (); m_typeLabel->setText (text); if (m_typeLabel->height () != h) @@ -161,12 +157,15 @@ // protected kpEffectBlurSharpen::Type kpEffectBlurSharpenWidget::type () const { - if (m_amountInput->value () == 0) + if (m_amountInput->value () == 0) { return kpEffectBlurSharpen::None; - else if (m_amountInput->value () < 0) + } + + if (m_amountInput->value () < 0) { return kpEffectBlurSharpen::Blur; - else - return kpEffectBlurSharpen::Sharpen; + } + + return kpEffectBlurSharpen::Sharpen; } // protected diff --git a/widgets/imagelib/effects/kpEffectEmbossWidget.cpp b/widgets/imagelib/effects/kpEffectEmbossWidget.cpp --- a/widgets/imagelib/effects/kpEffectEmbossWidget.cpp +++ b/widgets/imagelib/effects/kpEffectEmbossWidget.cpp @@ -45,10 +45,9 @@ QWidget *parent) : kpEffectWidgetBase (actOnSelection, parent) { - QGridLayout *lay = new QGridLayout (this); + auto *lay = new QGridLayout (this); lay->setContentsMargins(0, 0, 0, 0); - m_enableCheckBox = new QCheckBox (i18n ("E&nable"), this); @@ -62,9 +61,7 @@ this, &kpEffectEmbossWidget::settingsChangedDelayed); } -kpEffectEmbossWidget::~kpEffectEmbossWidget () -{ -} +kpEffectEmbossWidget::~kpEffectEmbossWidget () = default; // public virtual [base kpEffectWidgetBase] @@ -84,8 +81,9 @@ // public virtual [base kpEffectWidgetBase] kpImage kpEffectEmbossWidget::applyEffect (const kpImage &image) { - if (isNoOp ()) + if (isNoOp ()) { return image; + } return kpEffectEmboss::applyEffect (image, strength ()); } diff --git a/widgets/imagelib/effects/kpEffectFlattenWidget.cpp b/widgets/imagelib/effects/kpEffectFlattenWidget.cpp --- a/widgets/imagelib/effects/kpEffectFlattenWidget.cpp +++ b/widgets/imagelib/effects/kpEffectFlattenWidget.cpp @@ -58,12 +58,14 @@ KConfigGroup cfgGroupSaver (KSharedConfig::openConfig (), kpSettingsGroupFlattenEffect); s_lastColor1 = cfgGroupSaver.readEntry (kpSettingFlattenEffectColor1, QColor ()); - if (!s_lastColor1.isValid ()) + if (!s_lastColor1.isValid ()) { s_lastColor1 = Qt::red; + } s_lastColor2 = cfgGroupSaver.readEntry (kpSettingFlattenEffectColor2, QColor ()); - if (!s_lastColor2.isValid ()) + if (!s_lastColor2.isValid ()) { s_lastColor2 = Qt::blue; + } } @@ -76,14 +78,12 @@ m_color1Button->setEnabled (false); m_color2Button->setEnabled (false); - - QVBoxLayout *lay = new QVBoxLayout (this); + auto *lay = new QVBoxLayout (this); lay->setContentsMargins(0, 0, 0, 0); lay->addWidget (m_enableCheckBox); lay->addWidget (m_color1Button); lay->addWidget (m_color2Button); - connect (m_enableCheckBox, &QCheckBox::toggled, this, &kpEffectFlattenWidget::slotEnableChanged); @@ -144,8 +144,9 @@ qCDebug(kpLogWidgets) << "kpEffectFlattenWidget::applyEffect() nop=" << isNoOp (); - if (isNoOp ()) + if (isNoOp ()) { return image; + } return kpEffectFlatten::applyEffect (image, color1 (), color2 ()); } diff --git a/widgets/imagelib/effects/kpEffectHSVWidget.cpp b/widgets/imagelib/effects/kpEffectHSVWidget.cpp --- a/widgets/imagelib/effects/kpEffectHSVWidget.cpp +++ b/widgets/imagelib/effects/kpEffectHSVWidget.cpp @@ -42,12 +42,12 @@ kpEffectHSVWidget::kpEffectHSVWidget (bool actOnSelection, QWidget *parent) : kpEffectWidgetBase (actOnSelection, parent) { - QGridLayout *lay = new QGridLayout (this); + auto *lay = new QGridLayout (this); lay->setContentsMargins(0, 0, 0, 0); - QLabel *hueLabel = new QLabel (i18n ("&Hue:"), this); - QLabel *saturationLabel = new QLabel (i18n ("&Saturation:"), this); - QLabel *valueLabel = new QLabel (i18nc ("The V of HSV", "&Value:"), this); + auto *hueLabel = new QLabel (i18n ("&Hue:"), this); + auto *saturationLabel = new QLabel (i18n ("&Saturation:"), this); + auto *valueLabel = new QLabel (i18nc ("The V of HSV", "&Value:"), this); m_hueInput = new kpDoubleNumInput (this); m_hueInput->setRange (-180, 180, 15/*step*/); @@ -84,26 +84,21 @@ this, &kpEffectHSVWidget::settingsChangedDelayed); } -kpEffectHSVWidget::~kpEffectHSVWidget () -{ -} +kpEffectHSVWidget::~kpEffectHSVWidget () = default; // public virtual [base kpEffectWidgetBase] QString kpEffectHSVWidget::caption () const { // TODO: Why doesn't this have a caption? Ditto for the other effects. - return QString(); + return {}; } // public virtual [base kpEffectWidgetBase] bool kpEffectHSVWidget::isNoOp () const { - if (m_hueInput->value () == 0 && m_saturationInput->value () == 0 && m_valueInput->value () == 0) - return true; - else - return false; + return m_hueInput->value () == 0 && m_saturationInput->value () == 0 && m_valueInput->value () == 0; } // public virtual [base kpEffectWidgetBase] diff --git a/widgets/imagelib/effects/kpEffectInvertWidget.cpp b/widgets/imagelib/effects/kpEffectInvertWidget.cpp --- a/widgets/imagelib/effects/kpEffectInvertWidget.cpp +++ b/widgets/imagelib/effects/kpEffectInvertWidget.cpp @@ -48,22 +48,20 @@ QWidget *parent) : kpEffectWidgetBase (actOnSelection, parent) { - QVBoxLayout *topLevelLay = new QVBoxLayout (this); + auto *topLevelLay = new QVBoxLayout (this); topLevelLay->setContentsMargins(0, 0, 0, 0); - - QWidget *centerWidget = new QWidget (this); + auto *centerWidget = new QWidget (this); topLevelLay->addWidget (centerWidget, 0/*stretch*/, Qt::AlignCenter); - - QVBoxLayout *centerWidgetLay = new QVBoxLayout (centerWidget ); + auto *centerWidgetLay = new QVBoxLayout (centerWidget ); centerWidgetLay->setContentsMargins(0, 0, 0, 0); m_redCheckBox = new QCheckBox (i18n ("&Red"), centerWidget); m_greenCheckBox = new QCheckBox (i18n ("&Green"), centerWidget); m_blueCheckBox = new QCheckBox (i18n ("&Blue"), centerWidget); - QWidget *spaceWidget = new QWidget (centerWidget); + auto *spaceWidget = new QWidget (centerWidget); spaceWidget->setFixedSize (1, fontMetrics ().height () / 4); m_allCheckBox = new QCheckBox (i18n ("&All"), centerWidget); @@ -99,9 +97,7 @@ this, &kpEffectInvertWidget::slotAllCheckBoxToggled); } -kpEffectInvertWidget::~kpEffectInvertWidget () -{ -} +kpEffectInvertWidget::~kpEffectInvertWidget () = default; // public @@ -115,14 +111,17 @@ int channels = 0; - if (m_redCheckBox->isChecked ()) + if (m_redCheckBox->isChecked ()) { channels |= kpEffectInvert::Red; + } - if (m_greenCheckBox->isChecked ()) + if (m_greenCheckBox->isChecked ()) { channels |= kpEffectInvert::Green; + } - if (m_blueCheckBox->isChecked ()) + if (m_blueCheckBox->isChecked ()) { channels |= kpEffectInvert::Blue; + } qCDebug(kpLogWidgets) << "\treturning channels=" << (int *) channels; @@ -167,8 +166,9 @@ // protected slots void kpEffectInvertWidget::slotRGBCheckBoxToggled () { - if (m_inSignalHandler) + if (m_inSignalHandler) { return; + } m_inSignalHandler = true; @@ -186,8 +186,9 @@ // protected slot void kpEffectInvertWidget::slotAllCheckBoxToggled () { - if (m_inSignalHandler) + if (m_inSignalHandler) { return; + } m_inSignalHandler = true; diff --git a/widgets/imagelib/effects/kpEffectReduceColorsWidget.cpp b/widgets/imagelib/effects/kpEffectReduceColorsWidget.cpp --- a/widgets/imagelib/effects/kpEffectReduceColorsWidget.cpp +++ b/widgets/imagelib/effects/kpEffectReduceColorsWidget.cpp @@ -51,10 +51,9 @@ QWidget *parent) : kpEffectWidgetBase (actOnSelection, parent) { - QVBoxLayout *lay = new QVBoxLayout (this); + auto *lay = new QVBoxLayout (this); lay->setContentsMargins(0, 0, 0, 0); - m_blackAndWhiteRadioButton = new QRadioButton (i18n ("&Monochrome"), this); @@ -69,7 +68,7 @@ // LOCOMPAT: don't think this is needed - QButtonGroup *buttonGroup = new QButtonGroup (this); + auto *buttonGroup = new QButtonGroup (this); buttonGroup->addButton (m_blackAndWhiteRadioButton); buttonGroup->addButton (m_blackAndWhiteDitheredRadioButton); buttonGroup->addButton (m_8BitRadioButton); @@ -113,19 +112,19 @@ { return 1; } - else if (m_8BitRadioButton->isChecked () || + + if (m_8BitRadioButton->isChecked () || m_8BitDitheredRadioButton->isChecked ()) { return 8; } - else if (m_24BitRadioButton->isChecked ()) + + if (m_24BitRadioButton->isChecked ()) { return 32; } - else - { - return 0; - } + + return 0; } //--------------------------------------------------------------------- diff --git a/widgets/imagelib/effects/kpEffectToneEnhanceWidget.cpp b/widgets/imagelib/effects/kpEffectToneEnhanceWidget.cpp --- a/widgets/imagelib/effects/kpEffectToneEnhanceWidget.cpp +++ b/widgets/imagelib/effects/kpEffectToneEnhanceWidget.cpp @@ -47,47 +47,44 @@ m_amountInput (nullptr) { - QGridLayout *lay = new QGridLayout (this); + auto *lay = new QGridLayout (this); lay->setContentsMargins(0, 0, 0, 0); - // See kpEffectToneEnhance::applyEffect(). - { - QLabel *granularityLabel = new QLabel (i18n ("&Granularity:"), this); - QLabel *amountLabel = new QLabel (i18n ("&Amount:"), this); + auto *granularityLabel = new QLabel (i18n ("&Granularity:"), this); - m_granularityInput = new kpDoubleNumInput (this); - m_granularityInput->setRange (0, 1, 0.1/*step*/); + auto *amountLabel = new QLabel (i18n ("&Amount:"), this); - m_amountInput = new kpDoubleNumInput (this); - m_amountInput->setRange (0, 1, 0.1/*step*/); + m_granularityInput = new kpDoubleNumInput (this); + m_granularityInput->setRange (0, 1, 0.1/*step*/); - granularityLabel->setBuddy (m_granularityInput); - amountLabel->setBuddy (m_amountInput); + m_amountInput = new kpDoubleNumInput (this); + m_amountInput->setRange (0, 1, 0.1/*step*/); + granularityLabel->setBuddy (m_granularityInput); + amountLabel->setBuddy (m_amountInput); - lay->addWidget (granularityLabel, 0, 0); - lay->addWidget (m_granularityInput, 0, 1); - lay->addWidget (amountLabel, 1, 0); - lay->addWidget (m_amountInput, 1, 1); + lay->addWidget (granularityLabel, 0, 0); + lay->addWidget (m_granularityInput, 0, 1); - lay->setColumnStretch (1, 1); + lay->addWidget (amountLabel, 1, 0); + lay->addWidget (m_amountInput, 1, 1); + lay->setColumnStretch (1, 1); - connect (m_granularityInput, &kpDoubleNumInput::valueChanged, - this, &kpEffectToneEnhanceWidget::settingsChangedDelayed); - connect (m_amountInput, &kpDoubleNumInput::valueChanged, - this, &kpEffectToneEnhanceWidget::settingsChangedDelayed); - } -} + connect (m_granularityInput, &kpDoubleNumInput::valueChanged, + this, &kpEffectToneEnhanceWidget::settingsChangedDelayed); + + connect (m_amountInput, &kpDoubleNumInput::valueChanged, + this, &kpEffectToneEnhanceWidget::settingsChangedDelayed); -kpEffectToneEnhanceWidget::~kpEffectToneEnhanceWidget () -{ } +kpEffectToneEnhanceWidget::~kpEffectToneEnhanceWidget () = default; + // public virtual [base kpEffectWidgetBase] QString kpEffectToneEnhanceWidget::caption () const @@ -116,10 +113,11 @@ // If the "amount" is 0, nothing happens regardless of the granularity. // Note that if "granularity" is 0 but "amount" > 0, the effect _is_ active. // Therefore, "granularity" should have no involvement in this check. - if (amount () == 0) + if (amount () == 0) { return true; - else - return false; + } + + return false; } // public virtual [base kpEffectWidgetBase] diff --git a/widgets/imagelib/effects/kpEffectWidgetBase.cpp b/widgets/imagelib/effects/kpEffectWidgetBase.cpp --- a/widgets/imagelib/effects/kpEffectWidgetBase.cpp +++ b/widgets/imagelib/effects/kpEffectWidgetBase.cpp @@ -36,9 +36,7 @@ { } -kpEffectWidgetBase::~kpEffectWidgetBase () -{ -} +kpEffectWidgetBase::~kpEffectWidgetBase () = default; // public diff --git a/widgets/imagelib/effects/kpNumInput.cpp b/widgets/imagelib/effects/kpNumInput.cpp --- a/widgets/imagelib/effects/kpNumInput.cpp +++ b/widgets/imagelib/effects/kpNumInput.cpp @@ -327,7 +327,7 @@ w = qMax(w, priv->labelSize.width() + 4); } - return QSize(w, h); + return {w, h}; } void kpIntNumInput::doLayout() @@ -536,7 +536,7 @@ w = qMax(w, priv->labelSize.width() + 4); } - return QSize(w, h); + return {w, h}; } void kpDoubleNumInput::resizeEvent(QResizeEvent *e) diff --git a/widgets/kpColorCells.cpp b/widgets/kpColorCells.cpp --- a/widgets/kpColorCells.cpp +++ b/widgets/kpColorCells.cpp @@ -55,17 +55,19 @@ static int TableNumColumns (const kpColorCollection &colorCol) { - if (colorCol.count () == 0) + if (colorCol.count () == 0) { return 0; + } return ::TableDefaultNumColumns; } static int TableNumRows (const kpColorCollection &colorCol) { const int cols = ::TableNumColumns (colorCol); - if (cols == 0) + if (cols == 0) { return 0; + } return (colorCol.count () + (cols - 1)) / cols; } @@ -80,10 +82,11 @@ static int TableCellHeight (const kpColorCollection &colorCol) { - if (::TableNumRows (colorCol) <= 2) + if (::TableNumRows (colorCol) <= 2) { return ::TableDefaultHeight / 2; - else - return ::TableDefaultHeight / 3; + } + + return ::TableDefaultHeight / 3; } @@ -94,7 +97,7 @@ struct kpColorCellsPrivate { - Qt::Orientation orientation; + Qt::Orientation orientation{}; // REFACTOR: This is data duplication with kpColorCellsBase::color[]. // We've probably forgotten to synchronize them in some points. @@ -117,9 +120,9 @@ kpColorCollection colorCol; QUrl url; - bool isModified; + bool isModified{}; - bool blockColorChangedSig; + bool blockColorChangedSig{}; }; //--------------------------------------------------------------------- @@ -255,7 +258,7 @@ else { c = ::TableNumRows (d->colorCol); - r = ::TableNumColumns (d->colorCol);; + r = ::TableNumColumns (d->colorCol); } qCDebug(kpLogWidgets) << "kpColorCells::makeCellsMatchColorCollection():" @@ -282,10 +285,12 @@ // cells don't have exactly the sizes requested here. e.g. the // top row of cells is 1 pixel shorter than the bottom row. There // are probably other glitches. - for (int y = 0; y < r; y++) + for (int y = 0; y < r; y++) { setRowHeight (y, CellHeight); - for (int x = 0; x < c; x++) + } + for (int x = 0; x < c; x++) { setColumnWidth (x, CellWidth); + } const bool oldBlockColorChangedSig = d->blockColorChangedSig; @@ -311,7 +316,7 @@ pos = y * c + x; } qCDebug(kpLogWidgets) << "\tSetting cell " << i << ": y=" << y << " x=" << x - << " pos=" << pos << endl; + << " pos=" << pos; qCDebug(kpLogWidgets) << "\t\tcolor=" << (int *) d->colorCol.color (i).rgba() << "isValid=" << d->colorCol.color (i).isValid (); @@ -336,8 +341,9 @@ { qCDebug(kpLogWidgets) << "kpColorCells::setModified(" << yes << ")"; - if (yes == d->isModified) + if (yes == d->isModified) { return; + } d->isModified = yes; @@ -379,8 +385,9 @@ void kpColorCells::ensureHaveAtLeastOneRow () { - if (d->colorCol.count () == 0) + if (d->colorCol.count () == 0) { d->colorCol.resize (::TableDefaultNumColumns); + } } //--------------------------------------------------------------------- @@ -517,8 +524,7 @@ { qCDebug(kpLogWidgets) << "kpColorCells::slotColorSelected(cell=" << cell << ") mouseButton = " << button - << " rgb=" << (int *) color.rgba() - << endl; + << " rgb=" << (int *) color.rgba(); if (button == Qt::LeftButton) { @@ -563,12 +569,14 @@ qCDebug(kpLogWidgets) << "cell=" << cell << "color=" << (const int *) color.rgba() << "d->colorCol.count()=" << d->colorCol.count (); - if (d->blockColorChangedSig) + if (d->blockColorChangedSig) { return; + } // Cater for adding new colors to the end. - if (cell >= d->colorCol.count ()) + if (cell >= d->colorCol.count ()) { d->colorCol.resize (cell + 1); + } // TODO: We lose color names on a color swap (during drag-and-drop). const int ret = d->colorCol.changeColor (cell, color, diff --git a/widgets/kpDefaultColorCollection.cpp b/widgets/kpDefaultColorCollection.cpp --- a/widgets/kpDefaultColorCollection.cpp +++ b/widgets/kpDefaultColorCollection.cpp @@ -59,12 +59,10 @@ kpColor::Tan }; - for (int i = 0; i < static_cast (sizeof (colors) / sizeof (colors [0])); i++) + for (const auto & color : colors) { - addColor (colors [i].toQColor ()); + addColor (color.toQColor ()); } } -kpDefaultColorCollection::~kpDefaultColorCollection () -{ -} +kpDefaultColorCollection::~kpDefaultColorCollection () = default; diff --git a/widgets/kpDocumentSaveOptionsWidget.cpp b/widgets/kpDocumentSaveOptionsWidget.cpp --- a/widgets/kpDocumentSaveOptionsWidget.cpp +++ b/widgets/kpDocumentSaveOptionsWidget.cpp @@ -105,7 +105,7 @@ m_qualityLabel->setBuddy (m_qualityInput); - QHBoxLayout *lay = new QHBoxLayout (this); + auto *lay = new QHBoxLayout (this); lay->setContentsMargins(0, 0, 0, 0); lay->addWidget (m_colorDepthLabel, 0/*stretch*/, Qt::AlignLeft); @@ -246,12 +246,15 @@ m_baseDocumentSaveOptions.setMimeType (string); - if (mimeTypeHasConfigurableColorDepth ()) + if (mimeTypeHasConfigurableColorDepth ()) { setMode (ColorDepth); - else if (mimeTypeHasConfigurableQuality ()) + } + else if (mimeTypeHasConfigurableQuality ()) { setMode (Quality); - else + } + else { setMode (None); + } updatePreview (); } @@ -295,44 +298,31 @@ return (m_colorDepthCombo->currentIndex () == 1 || m_colorDepthCombo->currentIndex () == 3); } - else - { - return m_baseDocumentSaveOptions.dither (); - } + + return m_baseDocumentSaveOptions.dither (); } // protected static int kpDocumentSaveOptionsWidget::colorDepthComboItemFromColorDepthAndDither ( int depth, bool dither) { - if (depth == 1) - { - if (!dither) - { + switch (depth) { + case 1: + if (!dither) { return 0; } - else - { - return 1; - } - } - else if (depth == 8) - { - if (!dither) - { + return 1; + + case 8: + if (!dither) { return 2; } - else - { - return 3; - } - } - else if (depth == 32) - { + return 3; + + case 32: return 4; - } - else - { + + default: return -1; } } @@ -355,8 +345,9 @@ // This happens if this mimeType has configurable colour depth // and an incorrect maximum colour depth (less than a QImage of // this mimeType, opened by kpDocument). - if (comboItem >= 0 && comboItem < m_colorDepthCombo->count ()) + if (comboItem >= 0 && comboItem < m_colorDepthCombo->count ()) { m_colorDepthCombo->setCurrentIndex (comboItem); + } slotColorDepthSelected (); @@ -392,10 +383,8 @@ { return m_qualityInput->value (); } - else - { - return m_baseDocumentSaveOptions.quality (); - } + + return m_baseDocumentSaveOptions.quality (); } // public @@ -484,10 +473,12 @@ // protected slot void kpDocumentSaveOptionsWidget::repaintLabels () { - if (mode () != Quality) + if (mode () != Quality) { m_colorDepthLabel->repaint (); - if (mode () == Quality) + } + if (mode () == Quality) { m_qualityLabel->repaint (); + } } @@ -497,11 +488,13 @@ qCDebug(kpLogWidgets) << "kpDocumentSaveOptionsWidget::showPreview(" << yes << ")" << " m_previewDialog=" << bool (m_previewDialog); - if (yes == bool (m_previewDialog)) + if (yes == bool (m_previewDialog)) { return; + } - if (!m_visualParent) + if (!m_visualParent) { return; + } if (yes) { @@ -525,10 +518,10 @@ cfg.sync (); } - if (m_updatePreviewDelay < 0) + if (m_updatePreviewDelay < 0) { m_updatePreviewDelay = 0; - qCDebug(kpLogWidgets) << "\tread cfg preview dialog update delay=" - << m_updatePreviewDelay; + } + qCDebug(kpLogWidgets) << "\tread cfg preview dialog update delay=" << m_updatePreviewDelay; if (m_previewDialogLastRelativeGeometry.isEmpty ()) @@ -618,8 +611,9 @@ // protected slot void kpDocumentSaveOptionsWidget::hidePreview () { - if (m_previewButton->isChecked ()) + if (m_previewButton->isChecked ()) { m_previewButton->toggle (); + } } @@ -633,8 +627,9 @@ // protected slot void kpDocumentSaveOptionsWidget::updatePreview () { - if (!m_previewDialog || !m_documentPixmap) + if (!m_previewDialog || !m_documentPixmap) { return; + } m_updatePreviewTimer->stop (); @@ -693,8 +688,7 @@ QRect (m_previewDialog->x (), m_previewDialog->y (), m_previewDialog->width (), m_previewDialog->height ())); qCDebug(kpLogWidgets) << "\tcaching pos = " - << m_previewDialogLastRelativeGeometry - << endl; + << m_previewDialogLastRelativeGeometry; } else { diff --git a/widgets/kpDualColorButton.cpp b/widgets/kpDualColorButton.cpp --- a/widgets/kpDualColorButton.cpp +++ b/widgets/kpDualColorButton.cpp @@ -90,17 +90,20 @@ { Q_ASSERT (which == 0 || which == 1); - if (m_color [which] == color) + if (m_color [which] == color) { return; + } m_oldColor [which] = m_color [which]; m_color [which] = color; update (); - if (which == 0) + if (which == 0) { emit foregroundColorChanged (color); - else + } + else { emit backgroundColorChanged (color); + } } //--------------------------------------------------------------------- @@ -140,7 +143,7 @@ // public virtual [base QWidget] QSize kpDualColorButton::sizeHint () const { - return QSize (52, 52); + return {52, 52}; } //--------------------------------------------------------------------- @@ -151,46 +154,38 @@ { QPixmap swapPixmap = UserIcon ("colorbutton_swap_16x16"); - return QRect (contentsRect ().width () - swapPixmap.width (), - 0, - swapPixmap.width (), - swapPixmap.height ()); + return {contentsRect ().width () - swapPixmap.width (), 0, + swapPixmap.width (), swapPixmap.height ()}; } //--------------------------------------------------------------------- // protected QRect kpDualColorButton::foregroundBackgroundRect () const { QRect cr (contentsRect ()); - return QRect (cr.width () / 8, - cr.height () / 8, - cr.width () * 6 / 8, - cr.height () * 6 / 8); + return {cr.width () / 8, cr.height () / 8, + cr.width () * 6 / 8, cr.height () * 6 / 8}; } //--------------------------------------------------------------------- // protected QRect kpDualColorButton::foregroundRect () const { QRect fbr (foregroundBackgroundRect ()); - return QRect (fbr.x (), - fbr.y (), - fbr.width () * 3 / 4, - fbr.height () * 3 / 4); + return {fbr.x (), fbr.y (), + fbr.width () * 3 / 4, fbr.height () * 3 / 4}; } //--------------------------------------------------------------------- // protected QRect kpDualColorButton::backgroundRect () const { QRect fbr (foregroundBackgroundRect ()); - return QRect (fbr.x () + fbr.width () / 4, - fbr.y () + fbr.height () / 4, - fbr.width () * 3 / 4, - fbr.height () * 3 / 4); + return {fbr.x () + fbr.width () / 4, fbr.y () + fbr.height () / 4, + fbr.width () * 3 / 4, fbr.height () * 3 / 4}; } //--------------------------------------------------------------------- @@ -200,8 +195,7 @@ void kpDualColorButton::dragEnterEvent (QDragEnterEvent *e) { qCDebug(kpLogWidgets) << "kpDualColorButton::dragEnterEvent() canDecode=" - << KColorMimeData::canDecode (e->mimeData ()) - << endl; + << KColorMimeData::canDecode (e->mimeData ()); e->accept (); } @@ -211,8 +205,7 @@ void kpDualColorButton::dragMoveEvent (QDragMoveEvent *e) { qCDebug(kpLogWidgets) << "kpDualColorButton::dragMoveEvent() canDecode=" - << KColorMimeData::canDecode (e->mimeData ()) - << endl; + << KColorMimeData::canDecode (e->mimeData ()); e->setAccepted ( (foregroundRect ().contains (e->pos ()) || backgroundRect ().contains (e->pos ())) && @@ -227,14 +220,16 @@ QColor col = KColorMimeData::fromMimeData (e->mimeData ()); qCDebug(kpLogWidgets) << "kpDualColorButton::dropEvent() col=" << (int *) col.rgba() - << " (with alpha=" << (int *) col.rgba () << ")" << endl; + << " (with alpha=" << (int *) col.rgba () << ")"; if (col.isValid ()) { - if (foregroundRect ().contains (e->pos ())) + if (foregroundRect ().contains (e->pos ())) { setForegroundColor (kpColor (col.rgba())); - else if (backgroundRect ().contains (e->pos ())) + } + else if (backgroundRect ().contains (e->pos ())) { setBackgroundColor (kpColor (col.rgba())); + } } } @@ -248,8 +243,9 @@ m_dragStartPoint = KP_INVALID_POINT; - if (e->button () == Qt::LeftButton) + if (e->button () == Qt::LeftButton) { m_dragStartPoint = e->pos (); + } } //--------------------------------------------------------------------- @@ -260,8 +256,9 @@ << " buttons=" << e->buttons () << " dragStartPoint=" << m_dragStartPoint; - if (m_dragStartPoint == KP_INVALID_POINT) + if (m_dragStartPoint == KP_INVALID_POINT) { return; + } if (!(e->buttons () & Qt::LeftButton)) { @@ -279,22 +276,21 @@ kpColor color; - if (foregroundRect ().contains (m_dragStartPoint)) + if (foregroundRect ().contains (m_dragStartPoint)) { color = foregroundColor (); - else if (backgroundRect ().contains (m_dragStartPoint)) + } + else if (backgroundRect ().contains (m_dragStartPoint)) { color = backgroundColor (); - else - { - // "color" is left as invalid. } qCDebug(kpLogWidgets) << "\tcolor.isValid=" << color.isValid () << " rgb=" << (color.isValid () ? (int *) color.toQRgb () : 0); if (color.isValid ()) { - if (!color.isTransparent ()) + if (!color.isTransparent ()) { KColorMimeData::createDrag (color.toQColor (), this)->exec (); + } } m_dragStartPoint = KP_INVALID_POINT; @@ -334,18 +330,21 @@ { int whichColor = -1; - if (foregroundRect ().contains (e->pos ())) + if (foregroundRect ().contains (e->pos ())) { whichColor = 0; - else if (backgroundRect ().contains (e->pos ())) + } + else if (backgroundRect ().contains (e->pos ())) { whichColor = 1; + } if (whichColor == 0 || whichColor == 1) { QColorDialog dialog(this); dialog.setCurrentColor(color(whichColor).toQColor()); dialog.setOptions(QColorDialog::ShowAlphaChannel); - if ( dialog.exec() == QDialog::Accepted ) + if ( dialog.exec() == QDialog::Accepted ) { setColor(whichColor, kpColor(dialog.currentColor().rgba())); + } } } @@ -402,33 +401,40 @@ if (isEnabled ()) { qCDebug(kpLogWidgets) << "\tbackgroundColor=" << (int *) m_color [1].toQRgb (); - if (m_color [1].isTransparent ()) // only if fully transparent + if (m_color [1].isTransparent ()) { // only if fully transparent painter.drawPixmap (bgRectInside, UserIcon ("color_transparent_26x26")); - else + } + else { painter.fillRect (bgRectInside, m_color [1].toQColor ()); + } } - else + else { painter.fillRect (bgRectInside, palette().color (QPalette::Button)); + } qDrawShadePanel (&painter, bgRect, palette(), false/*not sunken*/, 2/*lineWidth*/, nullptr/*never fill*/); + // Draw foreground colour patch. // Must be drawn after background patch since we're on top. QRect fgRect = foregroundRect (); QRect fgRectInside = QRect (fgRect.x () + 2, fgRect.y () + 2, fgRect.width () - 4, fgRect.height () - 4); if (isEnabled ()) { qCDebug(kpLogWidgets) << "\tforegroundColor=" << (int *) m_color [0].toQRgb (); - if (m_color [0].isTransparent ()) // only if fully transparent + if (m_color [0].isTransparent ()) { // only if fully transparent painter.drawPixmap (fgRectInside, UserIcon ("color_transparent_26x26")); - else + } + else { painter.fillRect (fgRectInside, m_color [0].toQColor ()); + } } - else + else { painter.fillRect (fgRectInside, palette ().color (QPalette::Button)); + } qDrawShadePanel (&painter, fgRect, palette (), false/*not sunken*/, 2/*lineWidth*/, diff --git a/widgets/kpPrintDialogPage.cpp b/widgets/kpPrintDialogPage.cpp --- a/widgets/kpPrintDialogPage.cpp +++ b/widgets/kpPrintDialogPage.cpp @@ -60,7 +60,7 @@ d->printTopLeftRadio = new QRadioButton (i18n ("Top-&left of the page"), this); - QVBoxLayout *lay = new QVBoxLayout (this); + auto *lay = new QVBoxLayout (this); lay->addWidget (d->printCenteredRadio); lay->addWidget (d->printTopLeftRadio); lay->addStretch (); @@ -77,18 +77,20 @@ bool kpPrintDialogPage::printImageCenteredOnPage () { qCDebug(kpLogWidgets) << "kpPrintDialogPage::printImageCenteredOnPage()" - << " returning " << d->printCenteredRadio->isChecked() << endl; + << " returning " << d->printCenteredRadio->isChecked(); return d->printCenteredRadio->isChecked (); } void kpPrintDialogPage::setPrintImageCenteredOnPage (bool printCentered) { qCDebug(kpLogWidgets) << "kpPrintDialogPage::setOptions(" << printCentered << ")"; - if (printCentered) + if (printCentered) { d->printCenteredRadio->setChecked (true); - else + } + else { d->printTopLeftRadio->setChecked (true); + } } diff --git a/widgets/kpTransparentColorCell.cpp b/widgets/kpTransparentColorCell.cpp --- a/widgets/kpTransparentColorCell.cpp +++ b/widgets/kpTransparentColorCell.cpp @@ -60,8 +60,8 @@ // public virtual [base QWidget] QSize kpTransparentColorCell::sizeHint () const { - return QSize (m_pixmap.width () + frameWidth () * 2, - m_pixmap.height () + frameWidth () * 2); + return {m_pixmap.width () + frameWidth () * 2, + m_pixmap.height () + frameWidth () * 2}; } //--------------------------------------------------------------------- diff --git a/widgets/toolbars/kpColorToolBar.cpp b/widgets/toolbars/kpColorToolBar.cpp --- a/widgets/toolbars/kpColorToolBar.cpp +++ b/widgets/toolbars/kpColorToolBar.cpp @@ -175,7 +175,7 @@ void kpColorToolBar::setForegroundColor (const kpColor &color) { qCDebug(kpLogWidgets) << "kpColorToolBar::setForegroundColor(" - << (int *) color.toQRgb () << ")" << endl; + << (int *) color.toQRgb () << ")"; m_dualColorButton->setForegroundColor (color); } @@ -191,7 +191,7 @@ void kpColorToolBar::setBackgroundColor (const kpColor &color) { qCDebug(kpLogWidgets) << "kpColorToolBar::setBackgroundColor(" - << (int *) color.toQRgb () << ")" << endl; + << (int *) color.toQRgb () << ")"; m_dualColorButton->setBackgroundColor (color); } @@ -260,18 +260,22 @@ QString name; kpColorCells *colorCells = m_colorPalette->colorCells (); - if (!colorCells->url ().isEmpty ()) + if (!colorCells->url ().isEmpty ()) { name = kpUrlFormatter::PrettyFilename (colorCells->url ()); + } else { - if (!colorCells->name ().isEmpty ()) + if (!colorCells->name ().isEmpty ()) { name = colorCells->name (); - else + } + else { name = i18n ("KolourPaint Defaults"); + } } - if (name.isEmpty ()) + if (name.isEmpty ()) { name = i18n ("Untitled"); + } KLocalizedString labelStr; @@ -309,7 +313,7 @@ { // Grab the color drag for this widget, preventing it from being // handled by our parent, the main window. - e->setAccepted (KColorMimeData::canDecode (e->mimeData ()) == true); + e->setAccepted (KColorMimeData::canDecode (e->mimeData ())); qCDebug(kpLogWidgets) << "isAccepted=" << e->isAccepted (); } @@ -319,6 +323,6 @@ void kpColorToolBar::dragMoveEvent (QDragMoveEvent *e) { // Stop the grabbed drag from being dropped. - e->setAccepted (KColorMimeData::canDecode (e->mimeData ()) == false); + e->setAccepted (!KColorMimeData::canDecode (e->mimeData ())); qCDebug(kpLogWidgets) << "isAccepted=" << e->isAccepted (); } diff --git a/widgets/toolbars/kpToolToolBar.cpp b/widgets/toolbars/kpToolToolBar.cpp --- a/widgets/toolbars/kpToolToolBar.cpp +++ b/widgets/toolbars/kpToolToolBar.cpp @@ -65,8 +65,9 @@ protected: void mouseDoubleClickEvent(QMouseEvent *e) override { - if (e->button () == Qt::LeftButton && m_tool) + if (e->button () == Qt::LeftButton && m_tool) { m_tool->globalDraw (); + } } kpTool *m_tool; @@ -98,7 +99,7 @@ m_toolWidgets.append (m_toolWidgetSpraycanSize = new kpToolWidgetSpraycanSize (m_baseWidget, "Tool Widget Spraycan Size")); - foreach(kpToolWidgetBase *w, m_toolWidgets) + for (auto *w : m_toolWidgets) { connect (w, &kpToolWidgetBase::optionSelected, this, &kpToolToolBar::toolWidgetOptionSelected); @@ -128,22 +129,24 @@ kpToolToolBar::~kpToolToolBar() { - while ( !m_toolButtons.isEmpty() ) - delete m_toolButtons.takeFirst(); + while ( !m_toolButtons.isEmpty() ) { + delete m_toolButtons.takeFirst(); + } } //--------------------------------------------------------------------- // public void kpToolToolBar::registerTool (kpTool *tool) { - foreach (const kpToolButton *b, m_toolButtons) + for (const auto *b : m_toolButtons) { - if ( b->tool() == tool ) // already given - return; + if ( b->tool() == tool ) { // already given + return; + } } - kpToolButton *b = new kpToolButton(tool, m_baseWidget); + auto *b = new kpToolButton(tool, m_baseWidget); b->setToolButtonStyle(toolButtonStyle()); b->setIconSize(iconSize()); @@ -198,8 +201,9 @@ qCDebug(kpLogWidgets) << "kpToolToolBar::selectTool (tool=" << tool << ") currentTool=" << m_currentTool; - if (!reselectIfSameTool && tool == m_currentTool) + if (!reselectIfSameTool && tool == m_currentTool) { return; + } if (tool) { @@ -249,8 +253,9 @@ // public void kpToolToolBar::hideAllToolWidgets () { - foreach(kpToolWidgetBase *w, m_toolWidgets) + for (auto *w : m_toolWidgets) { w->hide (); + } } //--------------------------------------------------------------------- @@ -260,12 +265,13 @@ { int uptoVisibleWidget = 0; - foreach(kpToolWidgetBase *w, m_toolWidgets) + for(auto *w : m_toolWidgets) { if ( !w->isHidden() ) { - if (which == uptoVisibleWidget) + if (which == uptoVisibleWidget) { return w; + } uptoVisibleWidget++; } @@ -284,7 +290,7 @@ qCDebug(kpLogWidgets) << "kpToolToolBar::slotToolButtonClicked() button=" << b; kpTool *tool = nullptr; - foreach (const kpToolButton *button, m_toolButtons) + for (const auto *button : m_toolButtons) { if ( button == b ) { @@ -298,14 +304,16 @@ if (tool == m_currentTool) { - if (m_currentTool) + if (m_currentTool) { m_currentTool->reselect (); + } return; } - if (m_currentTool) + if (m_currentTool) { m_currentTool->endInternal (); + } m_previousTool = m_currentTool; m_currentTool = tool; @@ -331,7 +339,7 @@ // private slot void kpToolToolBar::slotToolActionActivated () { - const kpTool *tool = dynamic_cast(sender()); + const auto *tool = dynamic_cast(sender()); qCDebug(kpLogWidgets) << "kpToolToolBar::slotToolActionActivated() tool=" << (tool ? tool->objectName () : "null"); @@ -366,15 +374,15 @@ // (ownership is transferred to m_baseLayout) m_baseLayout->addItem (m_toolLayout); - int num = 0; + auto num = 0; - foreach (kpToolButton *b, m_toolButtons) + for (auto *b : m_toolButtons) { addButton(b, o, num); num++; } - foreach(kpToolWidgetBase *w, m_toolWidgets) + for (auto *w : m_toolWidgets) { m_baseLayout->addWidget(w, 0/*stretch*/, @@ -411,8 +419,9 @@ // private void kpToolToolBar::addButton(QAbstractButton *button, Qt::Orientation o, int num) { - if (o == Qt::Vertical) + if (o == Qt::Vertical) { m_toolLayout->addWidget (button, num / m_vertCols, num % m_vertCols); + } else { // maps Left (o = vertical) to Bottom (o = horizontal) @@ -425,8 +434,9 @@ void kpToolToolBar::slotIconSizeChanged(const QSize &size) { - foreach (kpToolButton *b, m_toolButtons) - b->setIconSize(size); + for (auto *b : m_toolButtons) { + b->setIconSize(size); + } m_baseLayout->activate(); adjustSizeConstraint(); @@ -436,8 +446,9 @@ void kpToolToolBar::slotToolButtonStyleChanged(Qt::ToolButtonStyle style) { - foreach (kpToolButton *b, m_toolButtons) - b->setToolButtonStyle(style); + for (auto *b : m_toolButtons) { + b->setToolButtonStyle(style); + } m_baseLayout->activate(); adjustSizeConstraint(); diff --git a/widgets/toolbars/options/kpToolWidgetBase.cpp b/widgets/toolbars/options/kpToolWidgetBase.cpp --- a/widgets/toolbars/options/kpToolWidgetBase.cpp +++ b/widgets/toolbars/options/kpToolWidgetBase.cpp @@ -64,17 +64,16 @@ //--------------------------------------------------------------------- -kpToolWidgetBase::~kpToolWidgetBase () -{ -} +kpToolWidgetBase::~kpToolWidgetBase () = default; //--------------------------------------------------------------------- // public void kpToolWidgetBase::addOption (const QPixmap &pixmap, const QString &toolTip) { - if (m_pixmaps.isEmpty ()) + if (m_pixmaps.isEmpty ()) { startNewOptionRow (); + } m_pixmaps.last ().append (pixmap); m_pixmapRects.last ().append (QRect ()); @@ -100,8 +99,7 @@ qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () << ")::kpToolWidgetBase(fallBack:row=" << fallBackRow << ",col=" << fallBackCol - << ")" - << endl; + << ")"; #endif relayoutOptions (); @@ -125,7 +123,7 @@ if (!setSelected (0, 0)) { qCCritical(kpLogWidgets) << "kpToolWidgetBase::finishConstruction() " - "can't even fall back to setSelected(row=0,col=0)" << endl; + "can't even fall back to setSelected(row=0,col=0)"; } } } @@ -136,32 +134,37 @@ // private QList kpToolWidgetBase::spreadOutElements (const QList &sizes, int max) { - if (sizes.count () == 0) + if (sizes.count () == 0) { return QList (); - else if (sizes.count () == 1) + } + + if (sizes.count () == 1) { QList ret; ret.append (sizes.first () > max ? 0 : 1/*margin*/); return ret; } QList retOffsets; - for (int i = 0; i < sizes.count (); i++) + for (int i = 0; i < sizes.count (); i++) { retOffsets.append (0); + } int totalSize = 0; - for (int i = 0; i < sizes.count (); i++) + for (int i = 0; i < sizes.count (); i++) { totalSize += sizes [i]; + } int margin = 1; // if don't fit with margin, then just return elements // packed right next to each other if (totalSize + margin * 2 > max) { retOffsets [0] = 0; - for (int i = 1; i < sizes.count (); i++) + for (int i = 1; i < sizes.count (); i++) { retOffsets [i] = retOffsets [i - 1] + sizes [i - 1]; + } return retOffsets; } @@ -212,8 +215,7 @@ #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () << ")::defaultSelectedRowAndCol() returning row=" << row - << " col=" << col - << endl; + << " col=" << col; #endif return qMakePair (row, col); @@ -243,11 +245,12 @@ #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () << ")::saveSelectedAsDefault() row=" << m_selectedRow - << " col=" << m_selectedCol << endl; + << " col=" << m_selectedCol; #endif - if (objectName ().isEmpty ()) + if (objectName ().isEmpty ()) { return; + } KConfigGroup cfg (KSharedConfig::openConfig (), kpSettingsGroupTools); @@ -275,24 +278,27 @@ m_toolTips.removeLast (); } - if (m_pixmaps.isEmpty ()) + if (m_pixmaps.isEmpty ()) { return; + } #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "\tsurvived killing of empty rows"; qCDebug(kpLogWidgets) << "\tfinding heights of rows:"; #endif QList maxHeightOfRow; - for (int r = 0; r < m_pixmaps.count (); r++) + for (int r = 0; r < m_pixmaps.count (); r++) { maxHeightOfRow.append (0); + } for (int r = 0; r < m_pixmaps.count (); r++) { for (int c = 0; c < m_pixmaps [r].count (); c++) { - if (c == 0 || m_pixmaps [r][c].height () > maxHeightOfRow [r]) + if (c == 0 || m_pixmaps [r][c].height () > maxHeightOfRow [r]) { maxHeightOfRow [r] = m_pixmaps [r][c].height (); + } } #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "\t\t" << r << ": " << maxHeightOfRow [r]; @@ -302,8 +308,9 @@ QList rowYOffset = spreadOutElements (maxHeightOfRow, height ()); #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "\tspread out offsets of rows:"; - for (int r = 0; r < (int) rowYOffset.count (); r++) + for (int r = 0; r < (int) rowYOffset.count (); r++) { qCDebug(kpLogWidgets) << "\t\t" << r << ": " << rowYOffset [r]; + } #endif for (int r = 0; r < m_pixmaps.count (); r++) @@ -317,15 +324,17 @@ widths.append (m_pixmaps [r][c].width ()); #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "\t\twidths of cols:"; - for (int c = 0; c < m_pixmaps [r].count (); c++) + for (int c = 0; c < m_pixmaps [r].count (); c++) { qCDebug(kpLogWidgets) << "\t\t\t" << c << ": " << widths [c]; + } #endif QList colXOffset = spreadOutElements (widths, width ()); #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "\t\tspread out offsets of cols:"; - for (int c = 0; c < colXOffset.count (); c++) + for (int c = 0; c < colXOffset.count (); c++) { qCDebug(kpLogWidgets) << "\t\t\t" << c << ": " << colXOffset [c]; + } #endif for (int c = 0; c < colXOffset.count (); c++) @@ -336,23 +345,29 @@ if (c == colXOffset.count () - 1) { - if (x + m_pixmaps [r][c].width () >= width ()) + if (x + m_pixmaps [r][c].width () >= width ()) { w = m_pixmaps [r][c].width (); - else + } + else { w = width () - 1 - x; + } } - else + else { w = colXOffset [c + 1] - x; + } if (r == m_pixmaps.count () - 1) { - if (y + m_pixmaps [r][c].height () >= height ()) + if (y + m_pixmaps [r][c].height () >= height ()) { h = m_pixmaps [r][c].height (); - else + } + else { h = height () - 1 - y; + } } - else + else { h = rowYOffset [r + 1] - y; + } m_pixmapRects [r][c] = QRect (x, y, w, h); } @@ -391,11 +406,13 @@ } int upto = 0; - for (int y = 0; y < m_selectedRow; y++) + for (int y = 0; y < m_selectedRow; y++) { upto += m_pixmaps [y].count (); + } - if (m_selectedCol >= m_pixmaps [m_selectedRow].count ()) + if (m_selectedCol >= m_pixmaps [m_selectedRow].count ()) { return -1; + } upto += m_selectedCol; @@ -411,38 +428,44 @@ #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () << ")::hasPreviousOption() current row=" << m_selectedRow - << " col=" << m_selectedCol - << endl; + << " col=" << m_selectedCol; #endif - if (row) + if (row) { *row = -1; - if (col) + } + if (col) { *col = -1; + } - if (m_selectedRow < 0 || m_selectedCol < 0) + if (m_selectedRow < 0 || m_selectedCol < 0) { return false; + } int newRow = m_selectedRow, newCol = m_selectedCol; newCol--; if (newCol < 0) { newRow--; - if (newRow < 0) + if (newRow < 0) { return false; + } newCol = m_pixmaps [newRow].count () - 1; - if (newCol < 0) + if (newCol < 0) { return false; + } } - if (row) + if (row) { *row = newRow; - if (col) + } + if (col) { *col = newCol; + } return true; } @@ -455,39 +478,45 @@ #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "kpToolWidgetBase(" << objectName () << ")::hasNextOption() current row=" << m_selectedRow - << " col=" << m_selectedCol - << endl; + << " col=" << m_selectedCol; #endif - if (row) + if (row) { *row = -1; - if (col) + } + if (col) { *col = -1; + } - if (m_selectedRow < 0 || m_selectedCol < 0) + if (m_selectedRow < 0 || m_selectedCol < 0) { return false; + } int newRow = m_selectedRow, newCol = m_selectedCol; newCol++; if (newCol >= m_pixmaps [newRow].count ()) { newRow++; - if (newRow >= m_pixmaps.count ()) + if (newRow >= m_pixmaps.count ()) { return false; + } newCol = 0; - if (newCol >= m_pixmaps [newRow].count ()) + if (newCol >= m_pixmaps [newRow].count ()) { return false; + } } - if (row) + if (row) { *row = newRow; - if (col) + } + if (col) { *col = newCol; + } return true; } @@ -502,8 +531,7 @@ qCDebug(kpLogWidgets) << "kpToolWidgetBase::setSelected(row=" << row << ",col=" << col << ",saveAsDefault=" << saveAsDefault - << ")" - << endl; + << ")"; #endif if (row < 0 || col < 0 || @@ -521,8 +549,9 @@ qCDebug(kpLogWidgets) << "\tNOP"; #endif - if (saveAsDefault) + if (saveAsDefault) { saveSelectedAsDefault (); + } return true; } @@ -546,8 +575,9 @@ qCDebug(kpLogWidgets) << "\tOK"; #endif - if (saveAsDefault) + if (saveAsDefault) { saveSelectedAsDefault (); + } emit optionSelected (row, col); return true; @@ -568,8 +598,9 @@ bool kpToolWidgetBase::selectPreviousOption () { int newRow, newCol; - if (!hasPreviousOption (&newRow, &newCol)) + if (!hasPreviousOption (&newRow, &newCol)) { return false; + } return setSelected (newRow, newCol); } @@ -580,8 +611,9 @@ bool kpToolWidgetBase::selectNextOption () { int newRow, newCol; - if (!hasNextOption (&newRow, &newCol)) + if (!hasNextOption (&newRow, &newCol)) { return false; + } return setSelected (newRow, newCol); } @@ -598,7 +630,7 @@ // its base which calls ignore() :) if (e->type () == QEvent::ToolTip) { - QHelpEvent *he = dynamic_cast (e); + auto *he = dynamic_cast (e); #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "kpToolWidgetBase::event() QHelpEvent pos=" << he->pos (); #endif @@ -613,7 +645,7 @@ const QString tip = m_toolTips [r][c]; #if DEBUG_KP_TOOL_WIDGET_BASE qCDebug(kpLogWidgets) << "\tin option: r=" << r << "c=" << c - << "tip='" << tip << "'" << endl; + << "tip='" << tip << "'"; #endif if (!tip.isEmpty ()) { @@ -638,8 +670,8 @@ return true; } - else - return QWidget::event (e); + + return QWidget::event (e); } //--------------------------------------------------------------------- @@ -650,8 +682,9 @@ { e->ignore (); - if (e->button () != Qt::LeftButton) + if (e->button () != Qt::LeftButton) { return; + } for (int i = 0; i < m_pixmapRects.count (); i++) @@ -706,8 +739,7 @@ qCDebug(kpLogWidgets) << "\t\t\tdraw pixmap @ x=" << rect.x () + (rect.width () - pixmap.width ()) / 2 << " y=" - << rect.y () + (rect.height () - pixmap.height ()) / 2 - << endl; + << rect.y () + (rect.height () - pixmap.height ()) / 2; #endif diff --git a/widgets/toolbars/options/kpToolWidgetBrush.cpp b/widgets/toolbars/options/kpToolWidgetBrush.cpp --- a/widgets/toolbars/options/kpToolWidgetBrush.cpp +++ b/widgets/toolbars/options/kpToolWidgetBrush.cpp @@ -59,14 +59,12 @@ static void Draw (kpImage *destImage, const QPoint &topLeft, void *userData) { - kpToolWidgetBrush::DrawPackage *pack = - static_cast (userData); + auto *pack = static_cast (userData); #if DEBUG_KP_TOOL_WIDGET_BRUSH qCDebug(kpLogWidgets) << "kptoolwidgetbrush.cpp:Draw(destImage,topLeft=" << topLeft << " pack: row=" << pack->row << " col=" << pack->col - << " color=" << (int *) pack->color.toQRgb () - << endl; + << " color=" << (int *) pack->color.toQRgb (); #endif const int size = ::BrushSizes [pack->row][pack->col]; #if DEBUG_KP_TOOL_WIDGET_BRUSH @@ -189,19 +187,18 @@ //--------------------------------------------------------------------- -kpToolWidgetBrush::~kpToolWidgetBrush () -{ -} +kpToolWidgetBrush::~kpToolWidgetBrush () = default; //--------------------------------------------------------------------- // private QString kpToolWidgetBrush::brushName (int shape, int whichSize) const { int s = ::BrushSizes [shape][whichSize]; - if (s == 1) + if (s == 1) { return i18n ("1x1"); + } QString shapeName; @@ -224,8 +221,9 @@ break; } - if (shapeName.isEmpty ()) - return QString(); + if (shapeName.isEmpty ()) { + return {}; + } return i18n ("%1x%2 %3", s, s, shapeName); } @@ -289,8 +287,9 @@ bool kpToolWidgetBrush::setSelected (int row, int col, bool saveAsDefault) { const bool ret = kpToolWidgetBase::setSelected (row, col, saveAsDefault); - if (ret) + if (ret) { emit brushChanged (); + } return ret; } diff --git a/widgets/toolbars/options/kpToolWidgetEraserSize.cpp b/widgets/toolbars/options/kpToolWidgetEraserSize.cpp --- a/widgets/toolbars/options/kpToolWidgetEraserSize.cpp +++ b/widgets/toolbars/options/kpToolWidgetEraserSize.cpp @@ -51,8 +51,7 @@ static void DrawImage (kpImage *destImage, const QPoint &topLeft, void *userData) { - kpToolWidgetEraserSize::DrawPackage *pack = - static_cast (userData); + auto *pack = static_cast (userData); const int size = ::EraserSizes [pack->selected]; @@ -66,15 +65,15 @@ ::DrawImage (destImage, topLeft, userData); - kpToolWidgetEraserSize::DrawPackage *pack = - static_cast (userData); + auto *pack = static_cast (userData); const int size = ::EraserSizes [pack->selected]; // Would 1-pixel border on all sides completely cover the color of the // eraser? - if (size <= 2) + if (size <= 2) { return; + } // Draw 1-pixel border on all sides. QPainter painter(destImage); @@ -88,8 +87,9 @@ { for (int i = 0; i < ::NumEraserSizes; i++) { - if (i == 3 || i == 5) + if (i == 3 || i == 5) { startNewOptionRow (); + } const int s = ::EraserSizes [i]; @@ -119,9 +119,7 @@ //--------------------------------------------------------------------- -kpToolWidgetEraserSize::~kpToolWidgetEraserSize () -{ -} +kpToolWidgetEraserSize::~kpToolWidgetEraserSize () = default; //--------------------------------------------------------------------- @@ -176,8 +174,9 @@ bool kpToolWidgetEraserSize::setSelected (int row, int col, bool saveAsDefault) { const bool ret = kpToolWidgetBase::setSelected (row, col, saveAsDefault); - if (ret) + if (ret) { emit eraserSizeChanged (eraserSize ()); + } return ret; } diff --git a/widgets/toolbars/options/kpToolWidgetFillStyle.cpp b/widgets/toolbars/options/kpToolWidgetFillStyle.cpp --- a/widgets/toolbars/options/kpToolWidgetFillStyle.cpp +++ b/widgets/toolbars/options/kpToolWidgetFillStyle.cpp @@ -64,9 +64,7 @@ //--------------------------------------------------------------------- -kpToolWidgetFillStyle::~kpToolWidgetFillStyle () -{ -} +kpToolWidgetFillStyle::~kpToolWidgetFillStyle () = default; //--------------------------------------------------------------------- @@ -137,8 +135,7 @@ { #if DEBUG_KP_TOOL_WIDGET_FILL_STYLE qCDebug(kpLogWidgets) << "kpToolWidgetFillStyle::fillStyle() selected=" - << selectedRow () - << endl; + << selectedRow (); #endif return static_cast (selectedRow ()); } @@ -168,8 +165,9 @@ bool kpToolWidgetFillStyle::setSelected (int row, int col, bool saveAsDefault) { const bool ret = kpToolWidgetBase::setSelected (row, col, saveAsDefault); - if (ret) + if (ret) { emit fillStyleChanged (fillStyle ()); + } return ret; } diff --git a/widgets/toolbars/options/kpToolWidgetLineWidth.cpp b/widgets/toolbars/options/kpToolWidgetLineWidth.cpp --- a/widgets/toolbars/options/kpToolWidgetLineWidth.cpp +++ b/widgets/toolbars/options/kpToolWidgetLineWidth.cpp @@ -68,9 +68,7 @@ finishConstruction (0, 0); } -kpToolWidgetLineWidth::~kpToolWidgetLineWidth () -{ -} +kpToolWidgetLineWidth::~kpToolWidgetLineWidth () = default; int kpToolWidgetLineWidth::lineWidth () const { @@ -81,8 +79,9 @@ bool kpToolWidgetLineWidth::setSelected (int row, int col, bool saveAsDefault) { const bool ret = kpToolWidgetBase::setSelected (row, col, saveAsDefault); - if (ret) + if (ret) { emit lineWidthChanged (lineWidth ()); + } return ret; } diff --git a/widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.cpp b/widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.cpp --- a/widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.cpp +++ b/widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.cpp @@ -49,9 +49,7 @@ //--------------------------------------------------------------------- -kpToolWidgetOpaqueOrTransparent::~kpToolWidgetOpaqueOrTransparent () -{ -} +kpToolWidgetOpaqueOrTransparent::~kpToolWidgetOpaqueOrTransparent () = default; //--------------------------------------------------------------------- @@ -92,11 +90,12 @@ { #if DEBUG_KP_TOOL_WIDGET_OPAQUE_OR_TRANSPARENT && 1 qCDebug(kpLogWidgets) << "kpToolWidgetOpaqueOrTransparent::setSelected(" - << row << "," << col << ")" << endl; + << row << "," << col << ")"; #endif const bool ret = kpToolWidgetBase::setSelected (row, col, saveAsDefault); - if (ret) + if (ret) { emit isOpaqueChanged (isOpaque ()); + } return ret; } diff --git a/widgets/toolbars/options/kpToolWidgetSpraycanSize.cpp b/widgets/toolbars/options/kpToolWidgetSpraycanSize.cpp --- a/widgets/toolbars/options/kpToolWidgetSpraycanSize.cpp +++ b/widgets/toolbars/options/kpToolWidgetSpraycanSize.cpp @@ -80,26 +80,26 @@ { for (int x = 0; x < image.width (); x++) { - if ((image.pixel (x, y) & RGB_MASK) == 0/*black*/) + if ((image.pixel (x, y) & RGB_MASK) == 0/*black*/) { painter.drawPoint (x, y); // mark as opaque + } } } painter.end (); pixmap.setMask (mask); addOption (pixmap, i18n ("%1x%2", s, s)/*tooltip*/); - if (i == 1) + if (i == 1) { startNewOptionRow (); + } } finishConstruction (0, 0); } -kpToolWidgetSpraycanSize::~kpToolWidgetSpraycanSize () -{ -} +kpToolWidgetSpraycanSize::~kpToolWidgetSpraycanSize () = default; // public @@ -112,8 +112,9 @@ bool kpToolWidgetSpraycanSize::setSelected (int row, int col, bool saveAsDefault) { const bool ret = kpToolWidgetBase::setSelected (row, col, saveAsDefault); - if (ret) + if (ret) { emit spraycanSizeChanged (spraycanSize ()); + } return ret; }