diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_policy(SET CMP0063 NEW) set(BASKET_DISABLE_GPG "0" CACHE BOOL "Disables GPG Support") +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + include(FeatureSummary) find_package(X11 REQUIRED) diff --git a/src/basketscene.cpp b/src/basketscene.cpp --- a/src/basketscene.cpp +++ b/src/basketscene.cpp @@ -19,40 +19,40 @@ #include "basketscene.h" -#include -#include -#include -#include -#include -#include -#include // seed for rand() -#include +#include +#include +#include +#include +#include +#include +#include // seed for rand() +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include +#include +#include #include #include -#include -#include +#include +#include #include #include #include -#include +#include #include #include #include @@ -76,7 +76,7 @@ #include -#include // rand() function +#include // rand() function #include "basketview.h" #include "decoratedbasket.h" @@ -297,7 +297,7 @@ unselectAll(); int count = 0; int founds = 0; - Note *last = 0; + Note *last = nullptr; for (Note *n = note; n; n = n->next()) { if (m_loaded) n->setSelectedRecursively(true); // Notes should have a parent basket (and they have, so that's OK). @@ -373,13 +373,13 @@ } } - note->setParentNote(0); - note->setPrev(0); - note->setNext(0); + note->setParentNote(nullptr); + note->setPrev(nullptr); + note->setNext(nullptr); // Reste focus and hover note if necessary - if(m_focusedNote == note) m_focusedNote = 0; - if(m_hoveredNote == note) m_hoveredNote = 0; + if(m_focusedNote == note) m_focusedNote = nullptr; + if(m_hoveredNote == note) m_hoveredNote = nullptr; // recomputeBlankRects(); // FIXME: called too much time. It's here because when dragging and moving a note to another basket and then go back to the original basket, the note is deleted but the note rect is not painter anymore. } @@ -569,8 +569,8 @@ if (note->content()) { QString tagsString = XMLWork::getElementText(e, "tags", ""); QStringList tagsId = tagsString.split(';'); - for (QStringList::iterator it = tagsId.begin(); it != tagsId.end(); ++it) { - State *state = Tag::stateForId(*it); + for (auto & it : tagsId) { + State *state = Tag::stateForId(it); if (state) note->addState(state, /*orReplace=*/true); } @@ -718,9 +718,9 @@ Global::backgroundManager->unsubscribe(m_backgroundImageName); Global::backgroundManager->unsubscribe(m_backgroundImageName, this->backgroundColor()); Global::backgroundManager->unsubscribe(m_backgroundImageName, selectionRectInsideColor()); - m_backgroundPixmap = 0; - m_opaqueBackgroundPixmap = 0; - m_selectedBackgroundPixmap = 0; + m_backgroundPixmap = nullptr; + m_opaqueBackgroundPixmap = nullptr; + m_selectedBackgroundPixmap = nullptr; } } @@ -783,7 +783,7 @@ } } else if (firstNote() && columnCount < m_columnsCount) { Note *column = firstNote(); - Note *cuttedNotes = 0; + Note *cuttedNotes = nullptr; for (int i = 1; i <= m_columnsCount; ++i) { Note *columnToRemove = column; column = column->next(); @@ -793,7 +793,7 @@ // "Cut" the content in the columns to be deleted: if (columnToRemove->firstChild()) { for (Note *it = columnToRemove->firstChild(); it; it = it->next()) - it->setParentNote(0); + it->setParentNote(nullptr); if (!cuttedNotes) cuttedNotes = columnToRemove->firstChild(); else { @@ -803,7 +803,7 @@ lastCuttedNote->setNext(columnToRemove->firstChild()); columnToRemove->firstChild()->setPrev(lastCuttedNote); } - columnToRemove->setFirstChild(0); + columnToRemove->setFirstChild(nullptr); } delete columnToRemove; } @@ -834,11 +834,11 @@ // TODO: Reorder notes! // Remove all notes (but keep a reference to them, we're not crazy ;-) ): Note *notes = m_firstNote; - m_firstNote = 0; + m_firstNote = nullptr; m_count = 0; m_countFounds = 0; // Insert the number of columns that is needed: - Note *lastInsertedColumn = 0; + Note *lastInsertedColumn = nullptr; for (int i = 0; i < columnCount; ++i) { Note *column = new Note(this); if (lastInsertedColumn) @@ -852,7 +852,7 @@ unselectAll(); } else { // Insert the number of columns that is needed: - Note *lastInsertedColumn = 0; + Note *lastInsertedColumn = nullptr; for (int i = 0; i < columnCount; ++i) { Note *column = new Note(this); if (lastInsertedColumn) @@ -876,22 +876,22 @@ relayoutNotes(true); int availableSpace = m_view->viewport()->width(); - int columnWidth = (availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnsCount(); + int columnWidth = (int)(availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnsCount(); int columnCount = columnsCount(); Note *column = firstNote(); while (column) { - int minGroupWidth = column->minRight() - column->x(); + int minGroupWidth = (int)column->minRight() - column->x(); if (minGroupWidth > columnWidth) { availableSpace -= minGroupWidth; --columnCount; } column = column->next(); } - columnWidth = (availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnCount; + columnWidth = (int)(availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnCount; column = firstNote(); while (column) { - int minGroupWidth = column->minRight() - column->x(); + int minGroupWidth = (int)column->minRight() - column->x(); if (minGroupWidth > columnWidth) column->setGroupWidth(minGroupWidth); else @@ -926,7 +926,7 @@ // Create Notes Element and Populate It: stream.writeStartElement("notes"); - saveNotes(stream, NULL); + saveNotes(stream, nullptr); stream.writeEndElement(); stream.writeEndElement(); @@ -964,7 +964,7 @@ note->finishLazyLoad(); //relayoutNotes(/*animate=*/false); - setFocusedNote(0); // So that during the focusInEvent that will come shortly, the FIRST note is focused. + setFocusedNote(nullptr); // So that during the focusInEvent that will come shortly, the FIRST note is focused. if (Settings::playAnimations() && !decoration()->filterBar()->filterData().isFiltering && Global::bnpView->currentBasket() == this) // No animation when filtering all! animateLoad();//QTimer::singleShot( 0, this, SLOT(animateLoad()) ); @@ -1034,7 +1034,7 @@ // Load notes m_finishLoadOnFirstShow = (Global::bnpView->currentBasket() != this); - loadNotes(notes, 0L); + loadNotes(notes, nullptr); if (m_shouldConvertPlainTextNotes) convertTexts(); m_watcher->startScan(); @@ -1091,7 +1091,7 @@ if (hasFocus()) // if (!hasFocus()), focusANote() will be called at focusInEvent() focusANote(); // so, we avoid de-focus a note if it will be re-shown soon - if (andEnsureVisible && m_focusedNote != 0L) + if (andEnsureVisible && m_focusedNote != nullptr) ensureNoteVisible(m_focusedNote); Global::bnpView->setFiltering(data.isFiltering); @@ -1104,8 +1104,6 @@ return decoration()->filterBar()->filterData().isFiltering; } - - QString BasketScene::fullPath() { return Global::basketsFolder() + folderName(); @@ -1591,9 +1589,9 @@ if (countFounds/*countShown*/() == 0) { // TODO: Count shown!! QMenu *menu = Global::bnpView->popupMenu("insert_popup"); setInsertPopupMenu(); - connect(menu, SIGNAL(aboutToHide()), this, SLOT(delayedCancelInsertPopupMenu())); - connect(menu, SIGNAL(aboutToHide()), this, SLOT(unlockHovering())); - connect(menu, SIGNAL(aboutToHide()), this, SLOT(disableNextClick())); + connect(menu, &QMenu::aboutToHide, this, &BasketScene::delayedCancelInsertPopupMenu); + connect(menu, &QMenu::aboutToHide, this, &BasketScene::unlockHovering); + connect(menu, &QMenu::aboutToHide, this, &BasketScene::disableNextClick); removeInserter(); m_lockedHovering = true; menu->exec(m_view->mapToGlobal(QPoint(0, 0))); @@ -1604,8 +1602,8 @@ m_startOfShiftSelectionNote = (m_focusedNote->isGroup() ? m_focusedNote->firstRealChild() : m_focusedNote); // Popup at bottom (or top) of the focused note, if visible : QMenu *menu = Global::bnpView->popupMenu("note_popup"); - connect(menu, SIGNAL(aboutToHide()), this, SLOT(unlockHovering())); - connect(menu, SIGNAL(aboutToHide()), this, SLOT(disableNextClick())); + connect(menu, &QMenu::aboutToHide, this, &BasketScene::unlockHovering); + connect(menu, &QMenu::aboutToHide, this, &BasketScene::disableNextClick); doHoverEffects(m_focusedNote, Note::Content); // In the case where another popup menu was open, we should do that manually! m_lockedHovering = true; menu->exec(noteVisibleRect(m_focusedNote).bottomLeft().toPoint()); @@ -2532,14 +2530,12 @@ m_editor->lineEdit()->selectAll(); } else { // First select all in the group, then in the parent group... - Note *child = m_focusedNote; - Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); + Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); while (parent) { if (!parent->allSelected()) { parent->setSelectedRecursively(true); return; } - child = parent; parent = parent->parentNote(); } // Then, select all: @@ -2952,7 +2948,7 @@ } // Nothing found, no note is hovered: - return NULL; + return nullptr; } BasketScene::~BasketScene() @@ -3746,13 +3742,12 @@ FocusedTextEdit *textEdit = dynamic_cast(m_editor->textEdit()); - if( textEdit ) - { + /* if (textEdit) { QPoint cursorPoint = textEdit->viewport()->mapToGlobal(textEdit->cursorRect().center()); //QPointF contentsCursor = m_view->mapToScene( m_view->viewport()->mapFromGlobal(cursorPoint) ); //m_view->ensureVisible(contentsCursor.x(), contentsCursor.y(),1,1); - } + } */ } void BasketScene::closeEditorDelayed() @@ -3898,13 +3893,13 @@ for (NoteSelection *subNode = node->firstChild; subNode; subNode = nextSubNode) { nextSubNode = subNode->next; tmpSelection.append(subNode); - subNode->parent = 0; - subNode->next = 0; + subNode->parent = nullptr; + subNode->next = nullptr; } } else { tmpSelection.append(node); - node->parent = 0; - node->next = 0; + node->parent = nullptr; + node->next = nullptr; } } // debugSel(tmpSelection.firstChild); @@ -3966,10 +3961,10 @@ } m_editor->graphicsWidget()->setFocus(); - connect(m_editor, SIGNAL(askValidation()), - this, SLOT(closeEditorDelayed())); - connect(m_editor, SIGNAL(mouseEnteredEditorWidget()), - this, SLOT(mouseEnteredEditorWidget())); + connect(m_editor, &NoteEditor::askValidation, + this, &BasketScene::closeEditorDelayed); + connect(m_editor, &NoteEditor::mouseEnteredEditorWidget, + this, &BasketScene::mouseEnteredEditorWidget); if (clickedPoint != QPoint()) { m_editor->setCursorTo(clickedPoint); @@ -3986,8 +3981,8 @@ focusANonSelectedNoteAboveOrThenBelow(); editor->note()->setSelected(true); editor->note()->deleteSelectedNotes(); - if( m_hoveredNote == editor->note() ) m_hoveredNote = 0; - if( m_focusedNote == editor->note() ) m_focusedNote = 0; + if( m_hoveredNote == editor->note() ) m_hoveredNote = nullptr; + if( m_focusedNote == editor->note() ) m_focusedNote = nullptr; delete editor->note(); save(); } @@ -3997,7 +3992,7 @@ unselectAll(); } // Must set focus to the editor, otherwise edit cursor is not seen and precomposed characters cannot be entered - if (m_editor != NULL && m_editor->textEdit() != NULL) + if (m_editor != nullptr && m_editor->textEdit() != NULL) m_editor->textEdit()->setFocus(); Global::bnpView->m_actEditNote->setEnabled(false); @@ -4108,7 +4103,7 @@ NoteSelection *selection = selectedNotes(); int countCopied = countSelecteds(); if (selection->firstStacked()) { - QDrag *d = NoteDrag::dragObject(selection, copyMode == CutToClipboard, /*source=*/0); // d will be deleted by QT + QDrag *d = NoteDrag::dragObject(selection, copyMode == CutToClipboard, /*source=*/nullptr); // d will be deleted by QT // /*bool shouldRemove = */d->drag(); // delete selection; cb->setMimeData(d->mimeData(), mode); // NoteMultipleDrag will be deleted by QT @@ -4197,19 +4192,24 @@ /** Code from bool KRun::displayOpenWithDialog(const KUrl::List& lst, bool tempFiles) * It does not allow to set a text, so I ripped it to do that: */ -bool KRun__displayOpenWithDialog(const QList& lst, QWidget *window, bool tempFiles, const QString &text) +bool KRun__displayOpenWithDialog(const QList &lst, QWidget *window, bool tempFiles, const QString text) { - if (qApp && !KAuthorized::authorizeKAction("openwith")) { - KMessageBox::sorry(window, i18n("You are not authorized to open this file.")); // TODO: Better message, i18n freeze :-( + if (!KAuthorized::authorizeAction(QStringLiteral("openwith"))) { + KMessageBox::sorry(window, + i18n("You are not authorized to select an application to open this file.")); return false; } - KOpenWithDialog l(lst, text, QString(), 0L); - if (l.exec()) { - KService::Ptr service = l.service(); - if (!!service) - return KRun::run(*service, lst, window, tempFiles); - //qDebug(250) << "No service set, running " << l.text() << endl; - return KRun::run(l.text(), lst, window); // TODO handle tempFiles + + KOpenWithDialog dialog(lst, text, QString(), window); + dialog.setWindowModality(Qt::WindowModal); + if (dialog.exec()) { + KService::Ptr service = dialog.service(); + if (!service) { + //qDebug() << "No service set, running " << dialog.text(); + service = KService::Ptr(new KService(QString() /*name*/, dialog.text(), QString() /*icon*/)); + } + const KRun::RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : KRun::RunFlags(); + return KRun::runApplication(*service, lst, window, flags); } return false; } @@ -4272,12 +4272,12 @@ bool BasketScene::selectionIsOneGroup() { - return (selectedGroup() != 0); + return (selectedGroup() != nullptr); } Note* BasketScene::firstSelected() { - Note *first = 0; + Note *first = nullptr; FOR_EACH_NOTE(note) { first = note->firstSelected(); if (first) @@ -4288,7 +4288,7 @@ Note* BasketScene::lastSelected() { - Note *last = 0, *tmp = 0; + Note *last = nullptr, *tmp = nullptr; FOR_EACH_NOTE(note) { tmp = note->lastSelected(); if (tmp) @@ -4407,8 +4407,8 @@ after = group; } else { Note *note = toUnplug->note; - note->setPrev(0); - note->setNext(0); + note->setPrev(nullptr); + note->setNext(nullptr); insertNote(note, after, Note::BottomInsert, QPointF(), /*animateNewPosition=*/true); after = note; } @@ -4631,10 +4631,10 @@ if (note && note->isGroup()) note = note->firstRealChild(); // The first time a note is focused, it becomes the start of the Shift selection: - if (m_startOfShiftSelectionNote == 0) + if (m_startOfShiftSelectionNote == nullptr) m_startOfShiftSelectionNote = note; // Unfocus the old focused note: - if (m_focusedNote != 0L) + if (m_focusedNote != nullptr) m_focusedNote->setFocused(false); // Notify the new one to draw a focus rectangle... only if the basket is focused: if (hasFocus() && note != 0L) @@ -4649,12 +4649,12 @@ void BasketScene::focusANote() { if (countFounds() == 0) { // No note to focus - setFocusedNote(0L); + setFocusedNote(nullptr); // m_startOfShiftSelectionNote = 0; return; } - if (m_focusedNote == 0L) { // No focused note yet : focus the first shown + if (m_focusedNote == nullptr) { // No focused note yet : focus the first shown Note *toFocus = (isFreeLayout() ? noteOnHome() : firstNoteShownInStack()); setFocusedNote(toFocus); // m_startOfShiftSelectionNote = m_focusedNote; @@ -4714,7 +4714,7 @@ Note* BasketScene::noteOn(NoteOn side) { - Note *bestNote = 0; + Note *bestNote = nullptr; int distance = -1; // int bestDistance = contentsWidth() * contentsHeight() * 10; int bestDistance = sceneRect().width() * sceneRect().height() * 10; @@ -4741,7 +4741,7 @@ Note* BasketScene::firstNoteInGroup() { Note *child = m_focusedNote; - Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); + Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); while (parent) { if (parent->firstChild() != child && !parent->isColumn()) return parent->firstRealChild(); @@ -4755,7 +4755,7 @@ { // First try to find the first note of the group containing the focused note: Note *child = m_focusedNote; - Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); + Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); while (parent) { if (parent->nextShownInStack() != m_focusedNote) return parent->nextShownInStack(); @@ -4782,7 +4782,7 @@ Note* BasketScene::noteOnEnd() { Note *child = m_focusedNote; - Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); + Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); Note *lastChild; while (parent) { lastChild = parent->lastRealChild(); @@ -4843,7 +4843,7 @@ if (!m_focusedNote) return; - Note *toFocus = 0L; + Note *toFocus = nullptr; switch (event->key()) { case Qt::Key_Down: @@ -4870,7 +4870,7 @@ for (int i = 0; i < 10 && toFocus; ++i) toFocus = toFocus->nextShownInStack(); } - if (toFocus == 0L) + if (toFocus == nullptr) toFocus = (isFreeLayout() ? noteOnEnd() : lastNoteShownInStack()); if (toFocus && toFocus != m_focusedNote) break; @@ -4889,7 +4889,7 @@ for (int i = 0; i < 10 && toFocus; ++i) toFocus = toFocus->prevShownInStack(); } - if (toFocus == 0L) + if (toFocus == nullptr) toFocus = (isFreeLayout() ? noteOnHome() : firstNoteShownInStack()); if (toFocus && toFocus != m_focusedNote) break; @@ -4929,13 +4929,13 @@ return; } - if (toFocus == 0L) { // If no direction keys have been pressed OR reached out the begin or end + if (toFocus == nullptr) { // If no direction keys have been pressed OR reached out the begin or end event->ignore(); // Important !! return; } if (event->modifiers() & Qt::ShiftModifier) { // Shift+arrowKeys selection - if (m_startOfShiftSelectionNote == 0L) + if (m_startOfShiftSelectionNote == nullptr) m_startOfShiftSelectionNote = toFocus; ensureNoteVisible(toFocus); // Important: this line should be before the other ones because else repaint would be done on the wrong part! selectRange(m_startOfShiftSelectionNote, toFocus); @@ -4961,15 +4961,15 @@ void BasketScene::selectRange(Note *start, Note *end, bool unselectOthers /*= true*/) { Note *cur; - Note *realEnd = 0L; + Note *realEnd = nullptr; // Avoid crash when start (or end) is null - if (start == 0L) + if (start == nullptr) start = end; - else if (end == 0L) + else if (end == nullptr) end = start; // And if *both* are null - if (start == 0L) { + if (start == nullptr) { if (unselectOthers) unselectAll(); return; @@ -4993,7 +4993,7 @@ } // Search the REAL first (and deselect the others before it) : - for (cur = firstNoteInStack(); cur != 0L; cur = cur->nextInStack()) { + for (cur = firstNoteInStack(); cur != nullptr; cur = cur->nextInStack()) { if (cur == start || cur == end) break; if (unselectOthers) @@ -5006,7 +5006,7 @@ else if (cur == end) realEnd = start; - for (/*cur = cur*/; cur != 0L; cur = cur->nextInStack()) { + for (/*cur = cur*/; cur != nullptr; cur = cur->nextInStack()) { cur->setSelected(cur->isShown()); // Select all notes in the range, but only if they are shown if (cur == realEnd) break; @@ -5018,7 +5018,7 @@ // Deselect the remaining notes : if (cur) cur = cur->nextInStack(); - for (/*cur = cur*/; cur != 0L; cur = cur->nextInStack()) + for (/*cur = cur*/; cur != nullptr; cur = cur->nextInStack()) cur->setSelected(false); } @@ -5039,7 +5039,7 @@ void BasketScene::focusOutEvent(QFocusEvent*) { - if (m_focusedNote != 0L) + if (m_focusedNote != nullptr) m_focusedNote->setFocused(false); } @@ -5101,8 +5101,8 @@ void BasketScene::updateModifiedNotes() { - for (QList::iterator it = m_modifiedFiles.begin(); it != m_modifiedFiles.end(); ++it) { - Note *note = noteForFullPath(*it); + for (auto & m_modifiedFile : m_modifiedFiles) { + Note *note = noteForFullPath(m_modifiedFile); if (note) note->content()->loadFromFile(/*lazyLoad=*/false); } @@ -5133,7 +5133,7 @@ return true; #else m_encryptionType = type; - m_encryptionKey = key; + m_encryptionKey = std::move(key); return false; #endif @@ -5294,7 +5294,7 @@ // until we finally save the file. // The error dialog is static to make sure we never show the dialog twice, - static DiskErrorDialog *dialog = 0; + static DiskErrorDialog *dialog = nullptr; static const uint maxDelay = 60 * 1000; // ms uint retryDelay = 1000; // ms bool success = false; @@ -5327,7 +5327,7 @@ if (dialog) dialog->deleteLater(); - dialog = NULL; + dialog = nullptr; return true; // Guess we can't really return a fail } diff --git a/src/noteedit.h b/src/noteedit.h --- a/src/noteedit.h +++ b/src/noteedit.h @@ -121,7 +121,7 @@ virtual void validate() {} virtual void autoSave(bool /*toFileToo*/) {} // Same as validate(), but does not precede editor close and is triggered either while the editor widget changed size or after 3 seconds of inactivity. -signals: +Q_SIGNALS: void askValidation(); void mouseEnteredEditorWidget();