Changeset View
Changeset View
Standalone View
Standalone View
src/basketscene.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License * | 14 | * You should have received a copy of the GNU General Public License * | ||
15 | * along with this program; if not, write to the * | 15 | * along with this program; if not, write to the * | ||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "basketscene.h" | 20 | #include "basketscene.h" | ||
21 | 21 | | |||
22 | #include <QtCore/QFile> | 22 | #include <QFile> | ||
23 | #include <QtCore/QFileInfo> | 23 | #include <QFileInfo> | ||
24 | #include <QtCore/QDir> | 24 | #include <QDir> | ||
25 | #include <QtCore/QPoint> | 25 | #include <QPoint> | ||
26 | #include <QtCore/QList> | 26 | #include <QList> | ||
27 | #include <QtCore/QStringList> | 27 | #include <QStringList> | ||
28 | #include <QtCore/QDateTime> // seed for rand() | 28 | #include <QDateTime> // seed for rand() | ||
29 | #include <QtCore/QTimeLine> | 29 | #include <QTimeLine> | ||
30 | #include <QApplication> | 30 | #include <QApplication> | ||
31 | #include <QtGui/QDrag> | 31 | #include <QDrag> | ||
32 | #include <QtGui/QDragMoveEvent> | 32 | #include <QDragMoveEvent> | ||
33 | #include <QtGui/QDragEnterEvent> | 33 | #include <QDragEnterEvent> | ||
34 | #include <QtGui/QDragLeaveEvent> | 34 | #include <QDragLeaveEvent> | ||
35 | #include <QtGui/QDropEvent> | 35 | #include <QDropEvent> | ||
36 | #include <QtGui/QMouseEvent> | 36 | #include <QMouseEvent> | ||
37 | #include <QtGui/QWheelEvent> | 37 | #include <QWheelEvent> | ||
38 | #include <QtGui/QKeyEvent> | 38 | #include <QKeyEvent> | ||
39 | #include <QtGui/QContextMenuEvent> | 39 | #include <QContextMenuEvent> | ||
40 | #include <QtGui/QFocusEvent> | 40 | #include <QFocusEvent> | ||
41 | #include <QtGui/QResizeEvent> | 41 | #include <QResizeEvent> | ||
42 | #include <QtGui/QPainter> | 42 | #include <QPainter> | ||
43 | #include <QFrame> | 43 | #include <QFrame> | ||
44 | #include <QLabel> | 44 | #include <QLabel> | ||
45 | #include <QPushButton> | 45 | #include <QPushButton> | ||
46 | #include <QtGui/QTextDocument> | 46 | #include <QTextDocument> | ||
47 | #include <QtGui/QAbstractTextDocumentLayout> | 47 | #include <QAbstractTextDocumentLayout> | ||
48 | #include <QGridLayout> | 48 | #include <QGridLayout> | ||
49 | #include <QToolTip> | 49 | #include <QToolTip> | ||
50 | #include <QtGui/QCursor> | 50 | #include <QCursor> | ||
51 | #include <QtGui/QClipboard> | 51 | #include <QClipboard> | ||
52 | #include <QInputDialog> | 52 | #include <QInputDialog> | ||
53 | #include <QGraphicsProxyWidget> | 53 | #include <QGraphicsProxyWidget> | ||
54 | #include <QScrollBar> | 54 | #include <QScrollBar> | ||
55 | #include <QtXml/QDomDocument> | 55 | #include <QDomDocument> | ||
56 | #include <QFileDialog> | 56 | #include <QFileDialog> | ||
57 | #include <QLocale> | 57 | #include <QLocale> | ||
58 | #include <QLineEdit> | 58 | #include <QLineEdit> | ||
59 | #include <QSaveFile> | 59 | #include <QSaveFile> | ||
60 | #include <QMenu> | 60 | #include <QMenu> | ||
61 | 61 | | |||
62 | #include <KTextEdit> | 62 | #include <KTextEdit> | ||
63 | 63 | | |||
64 | #include <KColorScheme> // for KStatefulBrush | 64 | #include <KColorScheme> // for KStatefulBrush | ||
65 | #include <KOpenWithDialog> | 65 | #include <KOpenWithDialog> | ||
66 | #include <KService> | 66 | #include <KService> | ||
67 | #include <KAboutData> | 67 | #include <KAboutData> | ||
68 | #include <KAuthorized> | 68 | #include <KAuthorized> | ||
69 | #include <KIconLoader> | 69 | #include <KIconLoader> | ||
70 | #include <KRun> | 70 | #include <KRun> | ||
71 | #include <KMessageBox> | 71 | #include <KMessageBox> | ||
72 | #include <KDirWatch> | 72 | #include <KDirWatch> | ||
73 | #include <KGlobalAccel> | 73 | #include <KGlobalAccel> | ||
74 | #include <KLocalizedString> | 74 | #include <KLocalizedString> | ||
75 | #include <KActionCollection> | 75 | #include <KActionCollection> | ||
76 | 76 | | |||
77 | #include <KIO/CopyJob> | 77 | #include <KIO/CopyJob> | ||
78 | 78 | | |||
79 | #include <stdlib.h> // rand() function | 79 | #include <cstdlib> // rand() function | ||
80 | 80 | | |||
81 | #include "basketview.h" | 81 | #include "basketview.h" | ||
82 | #include "decoratedbasket.h" | 82 | #include "decoratedbasket.h" | ||
83 | #include "diskerrordialog.h" | 83 | #include "diskerrordialog.h" | ||
84 | #include "note.h" | 84 | #include "note.h" | ||
85 | #include "notedrag.h" | 85 | #include "notedrag.h" | ||
86 | #include "notefactory.h" | 86 | #include "notefactory.h" | ||
87 | #include "noteedit.h" | 87 | #include "noteedit.h" | ||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Line(s) | |||||
292 | 292 | | |||
293 | void BasketScene::preparePlug(Note *note) | 293 | void BasketScene::preparePlug(Note *note) | ||
294 | { | 294 | { | ||
295 | // Select only the new notes, compute the new notes count and the new number of found notes: | 295 | // Select only the new notes, compute the new notes count and the new number of found notes: | ||
296 | if (m_loaded) | 296 | if (m_loaded) | ||
297 | unselectAll(); | 297 | unselectAll(); | ||
298 | int count = 0; | 298 | int count = 0; | ||
299 | int founds = 0; | 299 | int founds = 0; | ||
300 | Note *last = 0; | 300 | Note *last = nullptr; | ||
301 | for (Note *n = note; n; n = n->next()) { | 301 | for (Note *n = note; n; n = n->next()) { | ||
302 | if (m_loaded) | 302 | if (m_loaded) | ||
303 | n->setSelectedRecursively(true); // Notes should have a parent basket (and they have, so that's OK). | 303 | n->setSelectedRecursively(true); // Notes should have a parent basket (and they have, so that's OK). | ||
304 | count += n->count(); | 304 | count += n->count(); | ||
305 | founds += n->newFilter(decoration()->filterData()); | 305 | founds += n->newFilter(decoration()->filterData()); | ||
306 | last = n; | 306 | last = n; | ||
307 | } | 307 | } | ||
308 | m_count += count; | 308 | m_count += count; | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 367 | } | |||
368 | // Ungroup if still 1 note inside parent group: | 368 | // Ungroup if still 1 note inside parent group: | ||
369 | else if (! note->parentNote()->firstChild()->next()) | 369 | else if (! note->parentNote()->firstChild()->next()) | ||
370 | { | 370 | { | ||
371 | ungroupNote(note->parentNote()); | 371 | ungroupNote(note->parentNote()); | ||
372 | } | 372 | } | ||
373 | } | 373 | } | ||
374 | } | 374 | } | ||
375 | 375 | | |||
376 | note->setParentNote(0); | 376 | note->setParentNote(nullptr); | ||
377 | note->setPrev(0); | 377 | note->setPrev(nullptr); | ||
378 | note->setNext(0); | 378 | note->setNext(nullptr); | ||
379 | 379 | | |||
380 | // Reste focus and hover note if necessary | 380 | // Reste focus and hover note if necessary | ||
381 | if(m_focusedNote == note) m_focusedNote = 0; | 381 | if(m_focusedNote == note) m_focusedNote = nullptr; | ||
382 | if(m_hoveredNote == note) m_hoveredNote = 0; | 382 | if(m_hoveredNote == note) m_hoveredNote = nullptr; | ||
383 | 383 | | |||
384 | // 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. | 384 | // 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. | ||
385 | } | 385 | } | ||
386 | 386 | | |||
387 | void BasketScene::ungroupNote(Note *group) | 387 | void BasketScene::ungroupNote(Note *group) | ||
388 | { | 388 | { | ||
389 | Note *note = group->firstChild(); | 389 | Note *note = group->firstChild(); | ||
390 | Note *lastGroupedNote = group; | 390 | Note *lastGroupedNote = group; | ||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | 554 | if (note) { | |||
563 | if (note->hasResizer() || note->isColumn()) | 563 | if (note->hasResizer() || note->isColumn()) | ||
564 | note->setGroupWidth(e.attribute("width", "200").toInt()); | 564 | note->setGroupWidth(e.attribute("width", "200").toInt()); | ||
565 | // Group Properties: | 565 | // Group Properties: | ||
566 | if (note->isGroup() && !note->isColumn() && XMLWork::trueOrFalse(e.attribute("folded", "false"))) | 566 | if (note->isGroup() && !note->isColumn() && XMLWork::trueOrFalse(e.attribute("folded", "false"))) | ||
567 | note->toggleFolded(); | 567 | note->toggleFolded(); | ||
568 | // Tags: | 568 | // Tags: | ||
569 | if (note->content()) { | 569 | if (note->content()) { | ||
570 | QString tagsString = XMLWork::getElementText(e, "tags", ""); | 570 | QString tagsString = XMLWork::getElementText(e, "tags", ""); | ||
571 | QStringList tagsId = tagsString.split(';'); | 571 | QStringList tagsId = tagsString.split(';'); | ||
572 | for (QStringList::iterator it = tagsId.begin(); it != tagsId.end(); ++it) { | 572 | for (auto & it : tagsId) { | ||
alex: Add const for the tagId list, and no space after & | |||||
alex: I meant adding a `const` here ;-) | |||||
573 | State *state = Tag::stateForId(*it); | 573 | State *state = Tag::stateForId(it); | ||
574 | if (state) | 574 | if (state) | ||
575 | note->addState(state, /*orReplace=*/true); | 575 | note->addState(state, /*orReplace=*/true); | ||
576 | } | 576 | } | ||
577 | } | 577 | } | ||
578 | } | 578 | } | ||
579 | qApp->processEvents(); | 579 | qApp->processEvents(); | ||
580 | } | 580 | } | ||
581 | } | 581 | } | ||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | |||||
713 | } | 713 | } | ||
714 | 714 | | |||
715 | void BasketScene::unsubscribeBackgroundImages() | 715 | void BasketScene::unsubscribeBackgroundImages() | ||
716 | { | 716 | { | ||
717 | if (hasBackgroundImage()) { | 717 | if (hasBackgroundImage()) { | ||
718 | Global::backgroundManager->unsubscribe(m_backgroundImageName); | 718 | Global::backgroundManager->unsubscribe(m_backgroundImageName); | ||
719 | Global::backgroundManager->unsubscribe(m_backgroundImageName, this->backgroundColor()); | 719 | Global::backgroundManager->unsubscribe(m_backgroundImageName, this->backgroundColor()); | ||
720 | Global::backgroundManager->unsubscribe(m_backgroundImageName, selectionRectInsideColor()); | 720 | Global::backgroundManager->unsubscribe(m_backgroundImageName, selectionRectInsideColor()); | ||
721 | m_backgroundPixmap = 0; | 721 | m_backgroundPixmap = nullptr; | ||
722 | m_opaqueBackgroundPixmap = 0; | 722 | m_opaqueBackgroundPixmap = nullptr; | ||
723 | m_selectedBackgroundPixmap = 0; | 723 | m_selectedBackgroundPixmap = nullptr; | ||
724 | } | 724 | } | ||
725 | } | 725 | } | ||
726 | 726 | | |||
727 | void BasketScene::setAppearance(const QString &icon, const QString &name, const QString &backgroundImage, const QColor &backgroundColor, const QColor &textColor) | 727 | void BasketScene::setAppearance(const QString &icon, const QString &name, const QString &backgroundImage, const QColor &backgroundColor, const QColor &textColor) | ||
728 | { | 728 | { | ||
729 | unsubscribeBackgroundImages(); | 729 | unsubscribeBackgroundImages(); | ||
730 | 730 | | |||
731 | m_icon = icon; | 731 | m_icon = icon; | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 777 | if (currentDisposition == COLUMNS_LAYOUT && disposition == COLUMNS_LAYOUT) { | |||
778 | if (firstNote() && columnCount > m_columnsCount) { | 778 | if (firstNote() && columnCount > m_columnsCount) { | ||
779 | // Insert each new columns: | 779 | // Insert each new columns: | ||
780 | for (int i = m_columnsCount; i < columnCount; ++i) { | 780 | for (int i = m_columnsCount; i < columnCount; ++i) { | ||
781 | Note *newColumn = new Note(this); | 781 | Note *newColumn = new Note(this); | ||
782 | insertNote(newColumn, /*clicked=*/lastNote(), /*zone=*/Note::BottomInsert, QPointF(), /*animateNewPosition=*/false); | 782 | insertNote(newColumn, /*clicked=*/lastNote(), /*zone=*/Note::BottomInsert, QPointF(), /*animateNewPosition=*/false); | ||
783 | } | 783 | } | ||
784 | } else if (firstNote() && columnCount < m_columnsCount) { | 784 | } else if (firstNote() && columnCount < m_columnsCount) { | ||
785 | Note *column = firstNote(); | 785 | Note *column = firstNote(); | ||
786 | Note *cuttedNotes = 0; | 786 | Note *cuttedNotes = nullptr; | ||
787 | for (int i = 1; i <= m_columnsCount; ++i) { | 787 | for (int i = 1; i <= m_columnsCount; ++i) { | ||
788 | Note *columnToRemove = column; | 788 | Note *columnToRemove = column; | ||
789 | column = column->next(); | 789 | column = column->next(); | ||
790 | if (i > columnCount) { | 790 | if (i > columnCount) { | ||
791 | // Remove the columns that are too much: | 791 | // Remove the columns that are too much: | ||
792 | unplugNote(columnToRemove); | 792 | unplugNote(columnToRemove); | ||
793 | // "Cut" the content in the columns to be deleted: | 793 | // "Cut" the content in the columns to be deleted: | ||
794 | if (columnToRemove->firstChild()) { | 794 | if (columnToRemove->firstChild()) { | ||
795 | for (Note *it = columnToRemove->firstChild(); it; it = it->next()) | 795 | for (Note *it = columnToRemove->firstChild(); it; it = it->next()) | ||
796 | it->setParentNote(0); | 796 | it->setParentNote(nullptr); | ||
797 | if (!cuttedNotes) | 797 | if (!cuttedNotes) | ||
798 | cuttedNotes = columnToRemove->firstChild(); | 798 | cuttedNotes = columnToRemove->firstChild(); | ||
799 | else { | 799 | else { | ||
800 | Note *lastCuttedNote = cuttedNotes; | 800 | Note *lastCuttedNote = cuttedNotes; | ||
801 | while (lastCuttedNote->next()) | 801 | while (lastCuttedNote->next()) | ||
802 | lastCuttedNote = lastCuttedNote->next(); | 802 | lastCuttedNote = lastCuttedNote->next(); | ||
803 | lastCuttedNote->setNext(columnToRemove->firstChild()); | 803 | lastCuttedNote->setNext(columnToRemove->firstChild()); | ||
804 | columnToRemove->firstChild()->setPrev(lastCuttedNote); | 804 | columnToRemove->firstChild()->setPrev(lastCuttedNote); | ||
805 | } | 805 | } | ||
806 | columnToRemove->setFirstChild(0); | 806 | columnToRemove->setFirstChild(nullptr); | ||
807 | } | 807 | } | ||
808 | delete columnToRemove; | 808 | delete columnToRemove; | ||
809 | } | 809 | } | ||
810 | } | 810 | } | ||
811 | // Paste the content in the last column: | 811 | // Paste the content in the last column: | ||
812 | if (cuttedNotes) | 812 | if (cuttedNotes) | ||
813 | insertNote(cuttedNotes, /*clicked=*/lastNote(), /*zone=*/Note::BottomColumn, QPointF(), /*animateNewPosition=*/true); | 813 | insertNote(cuttedNotes, /*clicked=*/lastNote(), /*zone=*/Note::BottomColumn, QPointF(), /*animateNewPosition=*/true); | ||
814 | unselectAll(); | 814 | unselectAll(); | ||
Show All 14 Lines | 820 | } else if (currentDisposition == COLUMNS_LAYOUT && (disposition == FREE_LAYOUT || disposition == MINDMAPS_LAYOUT)) { | |||
829 | unselectAll(); | 829 | unselectAll(); | ||
830 | m_mindMap = (disposition == MINDMAPS_LAYOUT); | 830 | m_mindMap = (disposition == MINDMAPS_LAYOUT); | ||
831 | relayoutNotes(true); | 831 | relayoutNotes(true); | ||
832 | } else if ((currentDisposition == FREE_LAYOUT || currentDisposition == MINDMAPS_LAYOUT) && disposition == COLUMNS_LAYOUT) { | 832 | } else if ((currentDisposition == FREE_LAYOUT || currentDisposition == MINDMAPS_LAYOUT) && disposition == COLUMNS_LAYOUT) { | ||
833 | if (firstNote()) { | 833 | if (firstNote()) { | ||
834 | // TODO: Reorder notes! | 834 | // TODO: Reorder notes! | ||
835 | // Remove all notes (but keep a reference to them, we're not crazy ;-) ): | 835 | // Remove all notes (but keep a reference to them, we're not crazy ;-) ): | ||
836 | Note *notes = m_firstNote; | 836 | Note *notes = m_firstNote; | ||
837 | m_firstNote = 0; | 837 | m_firstNote = nullptr; | ||
838 | m_count = 0; | 838 | m_count = 0; | ||
839 | m_countFounds = 0; | 839 | m_countFounds = 0; | ||
840 | // Insert the number of columns that is needed: | 840 | // Insert the number of columns that is needed: | ||
841 | Note *lastInsertedColumn = 0; | 841 | Note *lastInsertedColumn = nullptr; | ||
842 | for (int i = 0; i < columnCount; ++i) { | 842 | for (int i = 0; i < columnCount; ++i) { | ||
843 | Note *column = new Note(this); | 843 | Note *column = new Note(this); | ||
844 | if (lastInsertedColumn) | 844 | if (lastInsertedColumn) | ||
845 | insertNote(column, /*clicked=*/lastInsertedColumn, /*zone=*/Note::BottomInsert, QPointF(), /*animateNewPosition=*/false); | 845 | insertNote(column, /*clicked=*/lastInsertedColumn, /*zone=*/Note::BottomInsert, QPointF(), /*animateNewPosition=*/false); | ||
846 | else | 846 | else | ||
847 | m_firstNote = column; | 847 | m_firstNote = column; | ||
848 | lastInsertedColumn = column; | 848 | lastInsertedColumn = column; | ||
849 | } | 849 | } | ||
850 | // Reinsert the old notes in the first column: | 850 | // Reinsert the old notes in the first column: | ||
851 | insertNote(notes, /*clicked=*/firstNote(), /*zone=*/Note::BottomColumn, QPointF(), /*animateNewPosition=*/true); | 851 | insertNote(notes, /*clicked=*/firstNote(), /*zone=*/Note::BottomColumn, QPointF(), /*animateNewPosition=*/true); | ||
852 | unselectAll(); | 852 | unselectAll(); | ||
853 | } else { | 853 | } else { | ||
854 | // Insert the number of columns that is needed: | 854 | // Insert the number of columns that is needed: | ||
855 | Note *lastInsertedColumn = 0; | 855 | Note *lastInsertedColumn = nullptr; | ||
856 | for (int i = 0; i < columnCount; ++i) { | 856 | for (int i = 0; i < columnCount; ++i) { | ||
857 | Note *column = new Note(this); | 857 | Note *column = new Note(this); | ||
858 | if (lastInsertedColumn) | 858 | if (lastInsertedColumn) | ||
859 | insertNote(column, /*clicked=*/lastInsertedColumn, /*zone=*/Note::BottomInsert, QPointF(), /*animateNewPosition=*/false); | 859 | insertNote(column, /*clicked=*/lastInsertedColumn, /*zone=*/Note::BottomInsert, QPointF(), /*animateNewPosition=*/false); | ||
860 | else | 860 | else | ||
861 | m_firstNote = column; | 861 | m_firstNote = column; | ||
862 | lastInsertedColumn = column; | 862 | lastInsertedColumn = column; | ||
863 | } | 863 | } | ||
864 | } | 864 | } | ||
865 | m_columnsCount = (columnCount <= 0 ? 1 : columnCount); | 865 | m_columnsCount = (columnCount <= 0 ? 1 : columnCount); | ||
866 | equalizeColumnSizes(); // Will relayoutNotes() | 866 | equalizeColumnSizes(); // Will relayoutNotes() | ||
867 | } | 867 | } | ||
868 | } | 868 | } | ||
869 | 869 | | |||
870 | void BasketScene::equalizeColumnSizes() | 870 | void BasketScene::equalizeColumnSizes() | ||
871 | { | 871 | { | ||
872 | if (!firstNote()) | 872 | if (!firstNote()) | ||
873 | return; | 873 | return; | ||
874 | 874 | | |||
875 | // Necessary to know the available space; | 875 | // Necessary to know the available space; | ||
876 | relayoutNotes(true); | 876 | relayoutNotes(true); | ||
877 | 877 | | |||
878 | int availableSpace = m_view->viewport()->width(); | 878 | int availableSpace = m_view->viewport()->width(); | ||
879 | int columnWidth = (availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnsCount(); | 879 | int columnWidth = (int)(availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnsCount(); | ||
880 | int columnCount = columnsCount(); | 880 | int columnCount = columnsCount(); | ||
881 | Note *column = firstNote(); | 881 | Note *column = firstNote(); | ||
882 | while (column) { | 882 | while (column) { | ||
883 | int minGroupWidth = column->minRight() - column->x(); | 883 | int minGroupWidth = (int)column->minRight() - column->x(); | ||
884 | if (minGroupWidth > columnWidth) { | 884 | if (minGroupWidth > columnWidth) { | ||
885 | availableSpace -= minGroupWidth; | 885 | availableSpace -= minGroupWidth; | ||
886 | --columnCount; | 886 | --columnCount; | ||
887 | } | 887 | } | ||
888 | column = column->next(); | 888 | column = column->next(); | ||
889 | } | 889 | } | ||
890 | columnWidth = (availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnCount; | 890 | columnWidth = (int)(availableSpace - (columnsCount() - 1) * Note::GROUP_WIDTH) / columnCount; | ||
891 | 891 | | |||
892 | column = firstNote(); | 892 | column = firstNote(); | ||
893 | while (column) { | 893 | while (column) { | ||
894 | int minGroupWidth = column->minRight() - column->x(); | 894 | int minGroupWidth = (int)column->minRight() - column->x(); | ||
895 | if (minGroupWidth > columnWidth) | 895 | if (minGroupWidth > columnWidth) | ||
896 | column->setGroupWidth(minGroupWidth); | 896 | column->setGroupWidth(minGroupWidth); | ||
897 | else | 897 | else | ||
898 | column->setGroupWidth(columnWidth); | 898 | column->setGroupWidth(columnWidth); | ||
899 | column = column->next(); | 899 | column = column->next(); | ||
900 | } | 900 | } | ||
901 | 901 | | |||
902 | relayoutNotes(true); | 902 | relayoutNotes(true); | ||
Show All 18 Lines | 914 | { | |||
921 | QXmlStreamWriter stream(&data); | 921 | QXmlStreamWriter stream(&data); | ||
922 | XMLWork::setupXmlStream(stream, "basket"); | 922 | XMLWork::setupXmlStream(stream, "basket"); | ||
923 | 923 | | |||
924 | // Create Properties Element and Populate It: | 924 | // Create Properties Element and Populate It: | ||
925 | saveProperties(stream); | 925 | saveProperties(stream); | ||
926 | 926 | | |||
927 | // Create Notes Element and Populate It: | 927 | // Create Notes Element and Populate It: | ||
928 | stream.writeStartElement("notes"); | 928 | stream.writeStartElement("notes"); | ||
929 | saveNotes(stream, NULL); | 929 | saveNotes(stream, nullptr); | ||
930 | stream.writeEndElement(); | 930 | stream.writeEndElement(); | ||
931 | 931 | | |||
932 | stream.writeEndElement(); | 932 | stream.writeEndElement(); | ||
933 | stream.writeEndDocument(); | 933 | stream.writeEndDocument(); | ||
934 | 934 | | |||
935 | // Write to Disk: | 935 | // Write to Disk: | ||
936 | if (!saveToFile(fullPath() + ".basket", data)) { | 936 | if (!saveToFile(fullPath() + ".basket", data)) { | ||
937 | DEBUG_WIN << "Basket[" + folderName() + "]: <font color=red>FAILED to save</font>!"; | 937 | DEBUG_WIN << "Basket[" + folderName() + "]: <font color=red>FAILED to save</font>!"; | ||
Show All 21 Lines | |||||
959 | 959 | | |||
960 | void BasketScene::aboutToBeActivated() | 960 | void BasketScene::aboutToBeActivated() | ||
961 | { | 961 | { | ||
962 | if (m_finishLoadOnFirstShow) { | 962 | if (m_finishLoadOnFirstShow) { | ||
963 | FOR_EACH_NOTE(note) | 963 | FOR_EACH_NOTE(note) | ||
964 | note->finishLazyLoad(); | 964 | note->finishLazyLoad(); | ||
965 | 965 | | |||
966 | //relayoutNotes(/*animate=*/false); | 966 | //relayoutNotes(/*animate=*/false); | ||
967 | setFocusedNote(0); // So that during the focusInEvent that will come shortly, the FIRST note is focused. | 967 | setFocusedNote(nullptr); // So that during the focusInEvent that will come shortly, the FIRST note is focused. | ||
968 | 968 | | |||
969 | if (Settings::playAnimations() && !decoration()->filterBar()->filterData().isFiltering && Global::bnpView->currentBasket() == this) // No animation when filtering all! | 969 | if (Settings::playAnimations() && !decoration()->filterBar()->filterData().isFiltering && Global::bnpView->currentBasket() == this) // No animation when filtering all! | ||
970 | animateLoad();//QTimer::singleShot( 0, this, SLOT(animateLoad()) ); | 970 | animateLoad();//QTimer::singleShot( 0, this, SLOT(animateLoad()) ); | ||
971 | 971 | | |||
972 | m_finishLoadOnFirstShow = false; | 972 | m_finishLoadOnFirstShow = false; | ||
973 | } | 973 | } | ||
974 | } | 974 | } | ||
975 | 975 | | |||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 990 | { | |||
1029 | QDomElement notes = XMLWork::getElement(docElem, "notes"); | 1029 | QDomElement notes = XMLWork::getElement(docElem, "notes"); | ||
1030 | if (notes.isNull()) | 1030 | if (notes.isNull()) | ||
1031 | notes = XMLWork::getElement(docElem, "items"); | 1031 | notes = XMLWork::getElement(docElem, "items"); | ||
1032 | m_watcher->stopScan(); | 1032 | m_watcher->stopScan(); | ||
1033 | m_shouldConvertPlainTextNotes = false; // Convert Pre-0.6.0 baskets: plain text notes should be converted to rich text ones once all is loaded! | 1033 | m_shouldConvertPlainTextNotes = false; // Convert Pre-0.6.0 baskets: plain text notes should be converted to rich text ones once all is loaded! | ||
1034 | 1034 | | |||
1035 | // Load notes | 1035 | // Load notes | ||
1036 | m_finishLoadOnFirstShow = (Global::bnpView->currentBasket() != this); | 1036 | m_finishLoadOnFirstShow = (Global::bnpView->currentBasket() != this); | ||
1037 | loadNotes(notes, 0L); | 1037 | loadNotes(notes, nullptr); | ||
1038 | if (m_shouldConvertPlainTextNotes) | 1038 | if (m_shouldConvertPlainTextNotes) | ||
1039 | convertTexts(); | 1039 | convertTexts(); | ||
1040 | m_watcher->startScan(); | 1040 | m_watcher->startScan(); | ||
1041 | 1041 | | |||
1042 | signalCountsChanged(); | 1042 | signalCountsChanged(); | ||
1043 | if (isColumnsLayout()) { | 1043 | if (isColumnsLayout()) { | ||
1044 | // Count the number of columns: | 1044 | // Count the number of columns: | ||
1045 | int columnsCount = 0; | 1045 | int columnsCount = 0; | ||
Show All 40 Lines | 1083 | //StopWatch::start(20); | |||
1086 | for (Note *note = firstNote(); note; note = note->next()) | 1086 | for (Note *note = firstNote(); note; note = note->next()) | ||
1087 | m_countFounds += note->newFilter(data); | 1087 | m_countFounds += note->newFilter(data); | ||
1088 | 1088 | | |||
1089 | relayoutNotes(true); | 1089 | relayoutNotes(true); | ||
1090 | signalCountsChanged(); | 1090 | signalCountsChanged(); | ||
1091 | 1091 | | |||
1092 | if (hasFocus()) // if (!hasFocus()), focusANote() will be called at focusInEvent() | 1092 | if (hasFocus()) // if (!hasFocus()), focusANote() will be called at focusInEvent() | ||
1093 | focusANote(); // so, we avoid de-focus a note if it will be re-shown soon | 1093 | focusANote(); // so, we avoid de-focus a note if it will be re-shown soon | ||
1094 | if (andEnsureVisible && m_focusedNote != 0L) | 1094 | if (andEnsureVisible && m_focusedNote != nullptr) | ||
1095 | ensureNoteVisible(m_focusedNote); | 1095 | ensureNoteVisible(m_focusedNote); | ||
1096 | 1096 | | |||
1097 | Global::bnpView->setFiltering(data.isFiltering); | 1097 | Global::bnpView->setFiltering(data.isFiltering); | ||
1098 | 1098 | | |||
1099 | //StopWatch::check(20); | 1099 | //StopWatch::check(20); | ||
1100 | } | 1100 | } | ||
1101 | 1101 | | |||
1102 | bool BasketScene::isFiltering() | 1102 | bool BasketScene::isFiltering() | ||
1103 | { | 1103 | { | ||
1104 | return decoration()->filterBar()->filterData().isFiltering; | 1104 | return decoration()->filterBar()->filterData().isFiltering; | ||
1105 | } | 1105 | } | ||
1106 | 1106 | | |||
1107 | | ||||
1108 | | ||||
1109 | QString BasketScene::fullPath() | 1107 | QString BasketScene::fullPath() | ||
1110 | { | 1108 | { | ||
1111 | return Global::basketsFolder() + folderName(); | 1109 | return Global::basketsFolder() + folderName(); | ||
1112 | } | 1110 | } | ||
1113 | 1111 | | |||
1114 | QString BasketScene::fullPathForFileName(const QString &fileName) | 1112 | QString BasketScene::fullPathForFileName(const QString &fileName) | ||
1115 | { | 1113 | { | ||
1116 | return fullPath() + fileName; | 1114 | return fullPath() + fileName; | ||
▲ Show 20 Lines • Show All 469 Lines • ▼ Show 20 Line(s) | |||||
1586 | } | 1584 | } | ||
1587 | 1585 | | |||
1588 | void BasketScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) | 1586 | void BasketScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) | ||
1589 | { | 1587 | { | ||
1590 | if (event->reason() == QGraphicsSceneContextMenuEvent::Keyboard) { | 1588 | if (event->reason() == QGraphicsSceneContextMenuEvent::Keyboard) { | ||
1591 | if (countFounds/*countShown*/() == 0) { // TODO: Count shown!! | 1589 | if (countFounds/*countShown*/() == 0) { // TODO: Count shown!! | ||
1592 | QMenu *menu = Global::bnpView->popupMenu("insert_popup"); | 1590 | QMenu *menu = Global::bnpView->popupMenu("insert_popup"); | ||
1593 | setInsertPopupMenu(); | 1591 | setInsertPopupMenu(); | ||
1594 | connect(menu, SIGNAL(aboutToHide()), this, SLOT(delayedCancelInsertPopupMenu())); | 1592 | connect(menu, &QMenu::aboutToHide, this, &BasketScene::delayedCancelInsertPopupMenu); | ||
1595 | connect(menu, SIGNAL(aboutToHide()), this, SLOT(unlockHovering())); | 1593 | connect(menu, &QMenu::aboutToHide, this, &BasketScene::unlockHovering); | ||
1596 | connect(menu, SIGNAL(aboutToHide()), this, SLOT(disableNextClick())); | 1594 | connect(menu, &QMenu::aboutToHide, this, &BasketScene::disableNextClick); | ||
1597 | removeInserter(); | 1595 | removeInserter(); | ||
1598 | m_lockedHovering = true; | 1596 | m_lockedHovering = true; | ||
1599 | menu->exec(m_view->mapToGlobal(QPoint(0, 0))); | 1597 | menu->exec(m_view->mapToGlobal(QPoint(0, 0))); | ||
1600 | } else { | 1598 | } else { | ||
1601 | if (! m_focusedNote->isSelected()) | 1599 | if (! m_focusedNote->isSelected()) | ||
1602 | unselectAllBut(m_focusedNote); | 1600 | unselectAllBut(m_focusedNote); | ||
1603 | setFocusedNote(m_focusedNote); /// /// /// | 1601 | setFocusedNote(m_focusedNote); /// /// /// | ||
1604 | m_startOfShiftSelectionNote = (m_focusedNote->isGroup() ? m_focusedNote->firstRealChild() : m_focusedNote); | 1602 | m_startOfShiftSelectionNote = (m_focusedNote->isGroup() ? m_focusedNote->firstRealChild() : m_focusedNote); | ||
1605 | // Popup at bottom (or top) of the focused note, if visible : | 1603 | // Popup at bottom (or top) of the focused note, if visible : | ||
1606 | QMenu *menu = Global::bnpView->popupMenu("note_popup"); | 1604 | QMenu *menu = Global::bnpView->popupMenu("note_popup"); | ||
1607 | connect(menu, SIGNAL(aboutToHide()), this, SLOT(unlockHovering())); | 1605 | connect(menu, &QMenu::aboutToHide, this, &BasketScene::unlockHovering); | ||
1608 | connect(menu, SIGNAL(aboutToHide()), this, SLOT(disableNextClick())); | 1606 | connect(menu, &QMenu::aboutToHide, this, &BasketScene::disableNextClick); | ||
1609 | doHoverEffects(m_focusedNote, Note::Content); // In the case where another popup menu was open, we should do that manually! | 1607 | doHoverEffects(m_focusedNote, Note::Content); // In the case where another popup menu was open, we should do that manually! | ||
1610 | m_lockedHovering = true; | 1608 | m_lockedHovering = true; | ||
1611 | menu->exec(noteVisibleRect(m_focusedNote).bottomLeft().toPoint()); | 1609 | menu->exec(noteVisibleRect(m_focusedNote).bottomLeft().toPoint()); | ||
1612 | } | 1610 | } | ||
1613 | } | 1611 | } | ||
1614 | } | 1612 | } | ||
1615 | 1613 | | |||
1616 | QRectF BasketScene::noteVisibleRect(Note *note) | 1614 | QRectF BasketScene::noteVisibleRect(Note *note) | ||
▲ Show 20 Lines • Show All 910 Lines • ▼ Show 20 Line(s) | |||||
2527 | { | 2525 | { | ||
2528 | if (redirectEditActions()) { | 2526 | if (redirectEditActions()) { | ||
2529 | if (m_editor->textEdit()) | 2527 | if (m_editor->textEdit()) | ||
2530 | m_editor->textEdit()->selectAll(); | 2528 | m_editor->textEdit()->selectAll(); | ||
2531 | else if (m_editor->lineEdit()) | 2529 | else if (m_editor->lineEdit()) | ||
2532 | m_editor->lineEdit()->selectAll(); | 2530 | m_editor->lineEdit()->selectAll(); | ||
2533 | } else { | 2531 | } else { | ||
2534 | // First select all in the group, then in the parent group... | 2532 | // First select all in the group, then in the parent group... | ||
2535 | Note *child = m_focusedNote; | 2533 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); | ||
2536 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); | | |||
2537 | while (parent) { | 2534 | while (parent) { | ||
2538 | if (!parent->allSelected()) { | 2535 | if (!parent->allSelected()) { | ||
2539 | parent->setSelectedRecursively(true); | 2536 | parent->setSelectedRecursively(true); | ||
2540 | return; | 2537 | return; | ||
2541 | } | 2538 | } | ||
2542 | child = parent; | | |||
2543 | parent = parent->parentNote(); | 2539 | parent = parent->parentNote(); | ||
2544 | } | 2540 | } | ||
2545 | // Then, select all: | 2541 | // Then, select all: | ||
2546 | FOR_EACH_NOTE(note) | 2542 | FOR_EACH_NOTE(note) | ||
2547 | note->setSelectedRecursively(true); | 2543 | note->setSelectedRecursively(true); | ||
2548 | } | 2544 | } | ||
2549 | } | 2545 | } | ||
2550 | 2546 | | |||
▲ Show 20 Lines • Show All 396 Lines • ▼ Show 20 Line(s) | 2941 | if (isColumnsLayout()) { | |||
2947 | while (column) { | 2943 | while (column) { | ||
2948 | if (x >= column->x() && x < column->rightLimit()) | 2944 | if (x >= column->x() && x < column->rightLimit()) | ||
2949 | return column; | 2945 | return column; | ||
2950 | column = column->next(); | 2946 | column = column->next(); | ||
2951 | } | 2947 | } | ||
2952 | } | 2948 | } | ||
2953 | 2949 | | |||
2954 | // Nothing found, no note is hovered: | 2950 | // Nothing found, no note is hovered: | ||
2955 | return NULL; | 2951 | return nullptr; | ||
2956 | } | 2952 | } | ||
2957 | 2953 | | |||
2958 | BasketScene::~BasketScene() | 2954 | BasketScene::~BasketScene() | ||
2959 | { | 2955 | { | ||
2960 | m_commitdelay.stop(); //we don't know how long deleteNotes() last so we want to make extra sure that nobody will commit in between | 2956 | m_commitdelay.stop(); //we don't know how long deleteNotes() last so we want to make extra sure that nobody will commit in between | ||
2961 | if (m_decryptBox) | 2957 | if (m_decryptBox) | ||
2962 | delete m_decryptBox; | 2958 | delete m_decryptBox; | ||
2963 | #ifdef HAVE_LIBGPGME | 2959 | #ifdef HAVE_LIBGPGME | ||
▲ Show 20 Lines • Show All 777 Lines • ▼ Show 20 Line(s) | |||||
3741 | 3737 | | |||
3742 | void BasketScene::editorCursorPositionChanged() | 3738 | void BasketScene::editorCursorPositionChanged() | ||
3743 | { | 3739 | { | ||
3744 | if (!isDuringEdit()) | 3740 | if (!isDuringEdit()) | ||
3745 | return; | 3741 | return; | ||
3746 | 3742 | | |||
3747 | FocusedTextEdit *textEdit = dynamic_cast<FocusedTextEdit*>(m_editor->textEdit()); | 3743 | FocusedTextEdit *textEdit = dynamic_cast<FocusedTextEdit*>(m_editor->textEdit()); | ||
3748 | 3744 | | |||
3749 | if( textEdit ) | 3745 | /* if (textEdit) { | ||
3750 | { | | |||
3751 | QPoint cursorPoint = textEdit->viewport()->mapToGlobal(textEdit->cursorRect().center()); | 3746 | QPoint cursorPoint = textEdit->viewport()->mapToGlobal(textEdit->cursorRect().center()); | ||
3752 | 3747 | | |||
3753 | //QPointF contentsCursor = m_view->mapToScene( m_view->viewport()->mapFromGlobal(cursorPoint) ); | 3748 | //QPointF contentsCursor = m_view->mapToScene( m_view->viewport()->mapFromGlobal(cursorPoint) ); | ||
3754 | //m_view->ensureVisible(contentsCursor.x(), contentsCursor.y(),1,1); | 3749 | //m_view->ensureVisible(contentsCursor.x(), contentsCursor.y(),1,1); | ||
3755 | } | 3750 | } */ | ||
3756 | } | 3751 | } | ||
3757 | 3752 | | |||
3758 | void BasketScene::closeEditorDelayed() | 3753 | void BasketScene::closeEditorDelayed() | ||
3759 | { | 3754 | { | ||
3760 | setFocus(); | 3755 | setFocus(); | ||
3761 | QTimer::singleShot(0, this, SLOT(closeEditor())); | 3756 | QTimer::singleShot(0, this, SLOT(closeEditor())); | ||
3762 | } | 3757 | } | ||
3763 | 3758 | | |||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 3886 | if (selection.firstChild->note->isColumn()) { | |||
3893 | NoteSelection *nextNode; | 3888 | NoteSelection *nextNode; | ||
3894 | NoteSelection *nextSubNode; | 3889 | NoteSelection *nextSubNode; | ||
3895 | for (NoteSelection *node = selection.firstChild; node; node = nextNode) { | 3890 | for (NoteSelection *node = selection.firstChild; node; node = nextNode) { | ||
3896 | nextNode = node->next; | 3891 | nextNode = node->next; | ||
3897 | if (node->note->isColumn()) { | 3892 | if (node->note->isColumn()) { | ||
3898 | for (NoteSelection *subNode = node->firstChild; subNode; subNode = nextSubNode) { | 3893 | for (NoteSelection *subNode = node->firstChild; subNode; subNode = nextSubNode) { | ||
3899 | nextSubNode = subNode->next; | 3894 | nextSubNode = subNode->next; | ||
3900 | tmpSelection.append(subNode); | 3895 | tmpSelection.append(subNode); | ||
3901 | subNode->parent = 0; | 3896 | subNode->parent = nullptr; | ||
3902 | subNode->next = 0; | 3897 | subNode->next = nullptr; | ||
3903 | } | 3898 | } | ||
3904 | } else { | 3899 | } else { | ||
3905 | tmpSelection.append(node); | 3900 | tmpSelection.append(node); | ||
3906 | node->parent = 0; | 3901 | node->parent = nullptr; | ||
3907 | node->next = 0; | 3902 | node->next = nullptr; | ||
3908 | } | 3903 | } | ||
3909 | } | 3904 | } | ||
3910 | // debugSel(tmpSelection.firstChild); | 3905 | // debugSel(tmpSelection.firstChild); | ||
3911 | return tmpSelection.firstChild; | 3906 | return tmpSelection.firstChild; | ||
3912 | } else { | 3907 | } else { | ||
3913 | // debugSel(selection.firstChild); | 3908 | // debugSel(selection.firstChild); | ||
3914 | return selection.firstChild; | 3909 | return selection.firstChild; | ||
3915 | } | 3910 | } | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 3955 | placeEditorAndEnsureVisible(); // placeEditor(); // FIXME: After? | |||
3961 | m_redirectEditActions = m_editor->lineEdit() || m_editor->textEdit(); | 3956 | m_redirectEditActions = m_editor->lineEdit() || m_editor->textEdit(); | ||
3962 | if (m_redirectEditActions) { | 3957 | if (m_redirectEditActions) { | ||
3963 | // In case there is NO text, "Select All" is disabled. But if the user press a key the there is now a text: | 3958 | // In case there is NO text, "Select All" is disabled. But if the user press a key the there is now a text: | ||
3964 | // selection has not changed but "Select All" should be re-enabled: | 3959 | // selection has not changed but "Select All" should be re-enabled: | ||
3965 | m_editor->connectActions(this); | 3960 | m_editor->connectActions(this); | ||
3966 | } | 3961 | } | ||
3967 | 3962 | | |||
3968 | m_editor->graphicsWidget()->setFocus(); | 3963 | m_editor->graphicsWidget()->setFocus(); | ||
3969 | connect(m_editor, SIGNAL(askValidation()), | 3964 | connect(m_editor, &NoteEditor::askValidation, | ||
3970 | this, SLOT(closeEditorDelayed())); | 3965 | this, &BasketScene::closeEditorDelayed); | ||
3971 | connect(m_editor, SIGNAL(mouseEnteredEditorWidget()), | 3966 | connect(m_editor, &NoteEditor::mouseEnteredEditorWidget, | ||
3972 | this, SLOT(mouseEnteredEditorWidget())); | 3967 | this, &BasketScene::mouseEnteredEditorWidget); | ||
3973 | 3968 | | |||
3974 | if (clickedPoint != QPoint()) { | 3969 | if (clickedPoint != QPoint()) { | ||
3975 | m_editor->setCursorTo(clickedPoint); | 3970 | m_editor->setCursorTo(clickedPoint); | ||
3976 | updateEditorAppearance(); | 3971 | updateEditorAppearance(); | ||
3977 | } | 3972 | } | ||
3978 | 3973 | | |||
3979 | // qApp->processEvents(); // Show the editor toolbar before ensuring the note is visible | 3974 | // qApp->processEvents(); // Show the editor toolbar before ensuring the note is visible | ||
3980 | ensureNoteVisible(note); // because toolbar can create a new line and then partially hide the note | 3975 | ensureNoteVisible(note); // because toolbar can create a new line and then partially hide the note | ||
3981 | m_editor->graphicsWidget()->setFocus(); // When clicking in the basket, a QTimer::singleShot(0, ...) focus the basket! So we focus the widget after qApp->processEvents() | 3976 | m_editor->graphicsWidget()->setFocus(); // When clicking in the basket, a QTimer::singleShot(0, ...) focus the basket! So we focus the widget after qApp->processEvents() | ||
3982 | emit resetStatusBarText(); // Display "Editing. ... to validate." | 3977 | emit resetStatusBarText(); // Display "Editing. ... to validate." | ||
3983 | } else { | 3978 | } else { | ||
3984 | // Delete the note user have canceled the addition: | 3979 | // Delete the note user have canceled the addition: | ||
3985 | if ((justAdded && editor->canceled()) || editor->isEmpty() /*) && editor->note()->states().count() <= 0*/) { | 3980 | if ((justAdded && editor->canceled()) || editor->isEmpty() /*) && editor->note()->states().count() <= 0*/) { | ||
3986 | focusANonSelectedNoteAboveOrThenBelow(); | 3981 | focusANonSelectedNoteAboveOrThenBelow(); | ||
3987 | editor->note()->setSelected(true); | 3982 | editor->note()->setSelected(true); | ||
3988 | editor->note()->deleteSelectedNotes(); | 3983 | editor->note()->deleteSelectedNotes(); | ||
3989 | if( m_hoveredNote == editor->note() ) m_hoveredNote = 0; | 3984 | if( m_hoveredNote == editor->note() ) m_hoveredNote = nullptr; | ||
3990 | if( m_focusedNote == editor->note() ) m_focusedNote = 0; | 3985 | if( m_focusedNote == editor->note() ) m_focusedNote = nullptr; | ||
3991 | delete editor->note(); | 3986 | delete editor->note(); | ||
3992 | save(); | 3987 | save(); | ||
3993 | } | 3988 | } | ||
3994 | editor->deleteLater(); | 3989 | editor->deleteLater(); | ||
3995 | unlockHovering(); | 3990 | unlockHovering(); | ||
3996 | filterAgain(); | 3991 | filterAgain(); | ||
3997 | unselectAll(); | 3992 | unselectAll(); | ||
3998 | } | 3993 | } | ||
3999 | // Must set focus to the editor, otherwise edit cursor is not seen and precomposed characters cannot be entered | 3994 | // Must set focus to the editor, otherwise edit cursor is not seen and precomposed characters cannot be entered | ||
4000 | if (m_editor != NULL && m_editor->textEdit() != NULL) | 3995 | if (m_editor != nullptr && m_editor->textEdit() != NULL) | ||
4001 | m_editor->textEdit()->setFocus(); | 3996 | m_editor->textEdit()->setFocus(); | ||
4002 | 3997 | | |||
4003 | Global::bnpView->m_actEditNote->setEnabled(false); | 3998 | Global::bnpView->m_actEditNote->setEnabled(false); | ||
4004 | } | 3999 | } | ||
4005 | 4000 | | |||
4006 | void BasketScene::noteDelete() | 4001 | void BasketScene::noteDelete() | ||
4007 | { | 4002 | { | ||
4008 | if (redirectEditActions()) { | 4003 | if (redirectEditActions()) { | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | |||||
4103 | void BasketScene::doCopy(CopyMode copyMode) | 4098 | void BasketScene::doCopy(CopyMode copyMode) | ||
4104 | { | 4099 | { | ||
4105 | QClipboard *cb = QApplication::clipboard(); | 4100 | QClipboard *cb = QApplication::clipboard(); | ||
4106 | QClipboard::Mode mode = ((copyMode == CopyToSelection) ? QClipboard::Selection : QClipboard::Clipboard); | 4101 | QClipboard::Mode mode = ((copyMode == CopyToSelection) ? QClipboard::Selection : QClipboard::Clipboard); | ||
4107 | 4102 | | |||
4108 | NoteSelection *selection = selectedNotes(); | 4103 | NoteSelection *selection = selectedNotes(); | ||
4109 | int countCopied = countSelecteds(); | 4104 | int countCopied = countSelecteds(); | ||
4110 | if (selection->firstStacked()) { | 4105 | if (selection->firstStacked()) { | ||
4111 | QDrag *d = NoteDrag::dragObject(selection, copyMode == CutToClipboard, /*source=*/0); // d will be deleted by QT | 4106 | QDrag *d = NoteDrag::dragObject(selection, copyMode == CutToClipboard, /*source=*/nullptr); // d will be deleted by QT | ||
4112 | // /*bool shouldRemove = */d->drag(); | 4107 | // /*bool shouldRemove = */d->drag(); | ||
4113 | // delete selection; | 4108 | // delete selection; | ||
4114 | cb->setMimeData(d->mimeData(), mode); // NoteMultipleDrag will be deleted by QT | 4109 | cb->setMimeData(d->mimeData(), mode); // NoteMultipleDrag will be deleted by QT | ||
4115 | // if (copyMode == CutToClipboard && !note->useFile()) // If useFile(), NoteDrag::dragObject() will delete it TODO | 4110 | // if (copyMode == CutToClipboard && !note->useFile()) // If useFile(), NoteDrag::dragObject() will delete it TODO | ||
4116 | // note->slotDelete(); | 4111 | // note->slotDelete(); | ||
4117 | 4112 | | |||
4118 | if (copyMode == CutToClipboard) | 4113 | if (copyMode == CutToClipboard) | ||
4119 | { | 4114 | { | ||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 4185 | } else { | |||
4192 | KRun::run(customCommand, urls, m_view->window()); | 4187 | KRun::run(customCommand, urls, m_view->window()); | ||
4193 | } | 4188 | } | ||
4194 | } | 4189 | } | ||
4195 | } | 4190 | } | ||
4196 | 4191 | | |||
4197 | /** Code from bool KRun::displayOpenWithDialog(const KUrl::List& lst, bool tempFiles) | 4192 | /** Code from bool KRun::displayOpenWithDialog(const KUrl::List& lst, bool tempFiles) | ||
4198 | * It does not allow to set a text, so I ripped it to do that: | 4193 | * It does not allow to set a text, so I ripped it to do that: | ||
4199 | */ | 4194 | */ | ||
4200 | bool KRun__displayOpenWithDialog(const QList<QUrl>& lst, QWidget *window, bool tempFiles, const QString &text) | 4195 | bool KRun__displayOpenWithDialog(const QList<QUrl> &lst, QWidget *window, bool tempFiles, const QString text) | ||
4201 | { | 4196 | { | ||
4202 | if (qApp && !KAuthorized::authorizeKAction("openwith")) { | 4197 | if (!KAuthorized::authorizeAction(QStringLiteral("openwith"))) { | ||
4203 | KMessageBox::sorry(window, i18n("You are not authorized to open this file.")); // TODO: Better message, i18n freeze :-( | 4198 | KMessageBox::sorry(window, | ||
4199 | i18n("You are not authorized to select an application to open this file.")); | ||||
4204 | return false; | 4200 | return false; | ||
4205 | } | 4201 | } | ||
4206 | KOpenWithDialog l(lst, text, QString(), 0L); | 4202 | | ||
4207 | if (l.exec()) { | 4203 | KOpenWithDialog dialog(lst, text, QString(), window); | ||
4208 | KService::Ptr service = l.service(); | 4204 | dialog.setWindowModality(Qt::WindowModal); | ||
4209 | if (!!service) | 4205 | if (dialog.exec()) { | ||
4210 | return KRun::run(*service, lst, window, tempFiles); | 4206 | KService::Ptr service = dialog.service(); | ||
4211 | //qDebug(250) << "No service set, running " << l.text() << endl; | 4207 | if (!service) { | ||
4212 | return KRun::run(l.text(), lst, window); // TODO handle tempFiles | 4208 | //qDebug() << "No service set, running " << dialog.text(); | ||
4209 | service = KService::Ptr(new KService(QString() /*name*/, dialog.text(), QString() /*icon*/)); | ||||
4210 | } | ||||
4211 | const KRun::RunFlags flags = tempFiles ? KRun::DeleteTemporaryFiles : KRun::RunFlags(); | ||||
4212 | return KRun::runApplication(*service, lst, window, flags); | ||||
4213 | } | 4213 | } | ||
4214 | return false; | 4214 | return false; | ||
4215 | } | 4215 | } | ||
4216 | 4216 | | |||
4217 | void BasketScene::noteOpenWith(Note *note) | 4217 | void BasketScene::noteOpenWith(Note *note) | ||
4218 | { | 4218 | { | ||
4219 | if (!note) | 4219 | if (!note) | ||
4220 | note = theSelectedNote(); | 4220 | note = theSelectedNote(); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 4261 | if (selectedGroup) { | |||
4267 | return selectedGroup; | 4267 | return selectedGroup; | ||
4268 | } | 4268 | } | ||
4269 | } | 4269 | } | ||
4270 | return 0; | 4270 | return 0; | ||
4271 | } | 4271 | } | ||
4272 | 4272 | | |||
4273 | bool BasketScene::selectionIsOneGroup() | 4273 | bool BasketScene::selectionIsOneGroup() | ||
4274 | { | 4274 | { | ||
4275 | return (selectedGroup() != 0); | 4275 | return (selectedGroup() != nullptr); | ||
4276 | } | 4276 | } | ||
4277 | 4277 | | |||
4278 | Note* BasketScene::firstSelected() | 4278 | Note* BasketScene::firstSelected() | ||
4279 | { | 4279 | { | ||
4280 | Note *first = 0; | 4280 | Note *first = nullptr; | ||
4281 | FOR_EACH_NOTE(note) { | 4281 | FOR_EACH_NOTE(note) { | ||
4282 | first = note->firstSelected(); | 4282 | first = note->firstSelected(); | ||
4283 | if (first) | 4283 | if (first) | ||
4284 | return first; | 4284 | return first; | ||
4285 | } | 4285 | } | ||
4286 | return 0; | 4286 | return 0; | ||
4287 | } | 4287 | } | ||
4288 | 4288 | | |||
4289 | Note* BasketScene::lastSelected() | 4289 | Note* BasketScene::lastSelected() | ||
4290 | { | 4290 | { | ||
4291 | Note *last = 0, *tmp = 0; | 4291 | Note *last = nullptr, *tmp = nullptr; | ||
4292 | FOR_EACH_NOTE(note) { | 4292 | FOR_EACH_NOTE(note) { | ||
4293 | tmp = note->lastSelected(); | 4293 | tmp = note->lastSelected(); | ||
4294 | if (tmp) | 4294 | if (tmp) | ||
4295 | last = tmp; | 4295 | last = tmp; | ||
4296 | } | 4296 | } | ||
4297 | return last; | 4297 | return last; | ||
4298 | } | 4298 | } | ||
4299 | 4299 | | |||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 4399 | if (toUnplug->note->isGroup()) { | |||
4402 | Note *fakeNote = NoteFactory::createNoteColor(Qt::red, this); | 4402 | Note *fakeNote = NoteFactory::createNoteColor(Qt::red, this); | ||
4403 | insertNote(fakeNote, group, Note::BottomColumn, QPointF(), /*animateNewPosition=*/false); | 4403 | insertNote(fakeNote, group, Note::BottomColumn, QPointF(), /*animateNewPosition=*/false); | ||
4404 | insertSelection(toUnplug->firstChild, fakeNote); | 4404 | insertSelection(toUnplug->firstChild, fakeNote); | ||
4405 | unplugNote(fakeNote); | 4405 | unplugNote(fakeNote); | ||
4406 | delete fakeNote; | 4406 | delete fakeNote; | ||
4407 | after = group; | 4407 | after = group; | ||
4408 | } else { | 4408 | } else { | ||
4409 | Note *note = toUnplug->note; | 4409 | Note *note = toUnplug->note; | ||
4410 | note->setPrev(0); | 4410 | note->setPrev(nullptr); | ||
4411 | note->setNext(0); | 4411 | note->setNext(nullptr); | ||
4412 | insertNote(note, after, Note::BottomInsert, QPointF(), /*animateNewPosition=*/true); | 4412 | insertNote(note, after, Note::BottomInsert, QPointF(), /*animateNewPosition=*/true); | ||
4413 | after = note; | 4413 | after = note; | ||
4414 | } | 4414 | } | ||
4415 | } | 4415 | } | ||
4416 | } | 4416 | } | ||
4417 | 4417 | | |||
4418 | void BasketScene::selectSelection(NoteSelection *selection) | 4418 | void BasketScene::selectSelection(NoteSelection *selection) | ||
4419 | { | 4419 | { | ||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Line(s) | |||||
4626 | { | 4626 | { | ||
4627 | // Don't focus an hidden note: | 4627 | // Don't focus an hidden note: | ||
4628 | if (note != 0L && !note->isShown()) | 4628 | if (note != 0L && !note->isShown()) | ||
4629 | return; | 4629 | return; | ||
4630 | // When clicking a group, this group gets focused. But only content-based notes should be focused: | 4630 | // When clicking a group, this group gets focused. But only content-based notes should be focused: | ||
4631 | if (note && note->isGroup()) | 4631 | if (note && note->isGroup()) | ||
4632 | note = note->firstRealChild(); | 4632 | note = note->firstRealChild(); | ||
4633 | // The first time a note is focused, it becomes the start of the Shift selection: | 4633 | // The first time a note is focused, it becomes the start of the Shift selection: | ||
4634 | if (m_startOfShiftSelectionNote == 0) | 4634 | if (m_startOfShiftSelectionNote == nullptr) | ||
4635 | m_startOfShiftSelectionNote = note; | 4635 | m_startOfShiftSelectionNote = note; | ||
4636 | // Unfocus the old focused note: | 4636 | // Unfocus the old focused note: | ||
4637 | if (m_focusedNote != 0L) | 4637 | if (m_focusedNote != nullptr) | ||
4638 | m_focusedNote->setFocused(false); | 4638 | m_focusedNote->setFocused(false); | ||
4639 | // Notify the new one to draw a focus rectangle... only if the basket is focused: | 4639 | // Notify the new one to draw a focus rectangle... only if the basket is focused: | ||
4640 | if (hasFocus() && note != 0L) | 4640 | if (hasFocus() && note != 0L) | ||
4641 | note->setFocused(true); | 4641 | note->setFocused(true); | ||
4642 | // Save the new focused note: | 4642 | // Save the new focused note: | ||
4643 | m_focusedNote = note; | 4643 | m_focusedNote = note; | ||
4644 | } | 4644 | } | ||
4645 | 4645 | | |||
4646 | /** If no shown note is currently focused, try to find a shown note and focus it | 4646 | /** If no shown note is currently focused, try to find a shown note and focus it | ||
4647 | * Also update m_focusedNote to the new one (or null if there isn't) | 4647 | * Also update m_focusedNote to the new one (or null if there isn't) | ||
4648 | */ | 4648 | */ | ||
4649 | void BasketScene::focusANote() | 4649 | void BasketScene::focusANote() | ||
4650 | { | 4650 | { | ||
4651 | if (countFounds() == 0) { // No note to focus | 4651 | if (countFounds() == 0) { // No note to focus | ||
4652 | setFocusedNote(0L); | 4652 | setFocusedNote(nullptr); | ||
4653 | // m_startOfShiftSelectionNote = 0; | 4653 | // m_startOfShiftSelectionNote = 0; | ||
4654 | return; | 4654 | return; | ||
4655 | } | 4655 | } | ||
4656 | 4656 | | |||
4657 | if (m_focusedNote == 0L) { // No focused note yet : focus the first shown | 4657 | if (m_focusedNote == nullptr) { // No focused note yet : focus the first shown | ||
4658 | Note *toFocus = (isFreeLayout() ? noteOnHome() : firstNoteShownInStack()); | 4658 | Note *toFocus = (isFreeLayout() ? noteOnHome() : firstNoteShownInStack()); | ||
4659 | setFocusedNote(toFocus); | 4659 | setFocusedNote(toFocus); | ||
4660 | // m_startOfShiftSelectionNote = m_focusedNote; | 4660 | // m_startOfShiftSelectionNote = m_focusedNote; | ||
4661 | return; | 4661 | return; | ||
4662 | } | 4662 | } | ||
4663 | 4663 | | |||
4664 | // Search a visible note to focus if the focused one isn't shown : | 4664 | // Search a visible note to focus if the focused one isn't shown : | ||
4665 | Note *toFocus = m_focusedNote; | 4665 | Note *toFocus = m_focusedNote; | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 4708 | { | |||
4709 | Note *last = lastNoteInStack(); | 4709 | Note *last = lastNoteInStack(); | ||
4710 | while (last && !last->isShown()) | 4710 | while (last && !last->isShown()) | ||
4711 | last = last->prevInStack(); | 4711 | last = last->prevInStack(); | ||
4712 | return last; | 4712 | return last; | ||
4713 | } | 4713 | } | ||
4714 | 4714 | | |||
4715 | Note* BasketScene::noteOn(NoteOn side) | 4715 | Note* BasketScene::noteOn(NoteOn side) | ||
4716 | { | 4716 | { | ||
4717 | Note *bestNote = 0; | 4717 | Note *bestNote = nullptr; | ||
4718 | int distance = -1; | 4718 | int distance = -1; | ||
4719 | // int bestDistance = contentsWidth() * contentsHeight() * 10; | 4719 | // int bestDistance = contentsWidth() * contentsHeight() * 10; | ||
4720 | int bestDistance = sceneRect().width() * sceneRect().height() * 10; | 4720 | int bestDistance = sceneRect().width() * sceneRect().height() * 10; | ||
4721 | 4721 | | |||
4722 | Note *note = firstNoteShownInStack(); | 4722 | Note *note = firstNoteShownInStack(); | ||
4723 | Note *primary = m_focusedNote->parentPrimaryNote(); | 4723 | Note *primary = m_focusedNote->parentPrimaryNote(); | ||
4724 | while (note) { | 4724 | while (note) { | ||
4725 | switch (side) { | 4725 | switch (side) { | ||
Show All 10 Lines | |||||
4736 | } | 4736 | } | ||
4737 | 4737 | | |||
4738 | return bestNote; | 4738 | return bestNote; | ||
4739 | } | 4739 | } | ||
4740 | 4740 | | |||
4741 | Note* BasketScene::firstNoteInGroup() | 4741 | Note* BasketScene::firstNoteInGroup() | ||
4742 | { | 4742 | { | ||
4743 | Note *child = m_focusedNote; | 4743 | Note *child = m_focusedNote; | ||
4744 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); | 4744 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); | ||
4745 | while (parent) { | 4745 | while (parent) { | ||
4746 | if (parent->firstChild() != child && !parent->isColumn()) | 4746 | if (parent->firstChild() != child && !parent->isColumn()) | ||
4747 | return parent->firstRealChild(); | 4747 | return parent->firstRealChild(); | ||
4748 | child = parent; | 4748 | child = parent; | ||
4749 | parent = parent->parentNote(); | 4749 | parent = parent->parentNote(); | ||
4750 | } | 4750 | } | ||
4751 | return 0; | 4751 | return 0; | ||
4752 | } | 4752 | } | ||
4753 | 4753 | | |||
4754 | Note* BasketScene::noteOnHome() | 4754 | Note* BasketScene::noteOnHome() | ||
4755 | { | 4755 | { | ||
4756 | // First try to find the first note of the group containing the focused note: | 4756 | // First try to find the first note of the group containing the focused note: | ||
4757 | Note *child = m_focusedNote; | 4757 | Note *child = m_focusedNote; | ||
4758 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); | 4758 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); | ||
4759 | while (parent) { | 4759 | while (parent) { | ||
4760 | if (parent->nextShownInStack() != m_focusedNote) | 4760 | if (parent->nextShownInStack() != m_focusedNote) | ||
4761 | return parent->nextShownInStack(); | 4761 | return parent->nextShownInStack(); | ||
4762 | child = parent; | 4762 | child = parent; | ||
4763 | parent = parent->parentNote(); | 4763 | parent = parent->parentNote(); | ||
4764 | } | 4764 | } | ||
4765 | 4765 | | |||
4766 | // If it was not found, then focus the very first note in the basket: | 4766 | // If it was not found, then focus the very first note in the basket: | ||
Show All 10 Lines | 4767 | if (isFreeLayout()) { | |||
4777 | return first; | 4777 | return first; | ||
4778 | } else | 4778 | } else | ||
4779 | return firstNoteShownInStack(); | 4779 | return firstNoteShownInStack(); | ||
4780 | } | 4780 | } | ||
4781 | 4781 | | |||
4782 | Note* BasketScene::noteOnEnd() | 4782 | Note* BasketScene::noteOnEnd() | ||
4783 | { | 4783 | { | ||
4784 | Note *child = m_focusedNote; | 4784 | Note *child = m_focusedNote; | ||
4785 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : 0); | 4785 | Note *parent = (m_focusedNote ? m_focusedNote->parentNote() : nullptr); | ||
4786 | Note *lastChild; | 4786 | Note *lastChild; | ||
4787 | while (parent) { | 4787 | while (parent) { | ||
4788 | lastChild = parent->lastRealChild(); | 4788 | lastChild = parent->lastRealChild(); | ||
4789 | if (lastChild && lastChild != m_focusedNote) { | 4789 | if (lastChild && lastChild != m_focusedNote) { | ||
4790 | if (lastChild->isShown()) | 4790 | if (lastChild->isShown()) | ||
4791 | return lastChild; | 4791 | return lastChild; | ||
4792 | lastChild = lastChild->prevShownInStack(); | 4792 | lastChild = lastChild->prevShownInStack(); | ||
4793 | if (lastChild && lastChild->isShown() && lastChild != m_focusedNote) | 4793 | if (lastChild && lastChild->isShown() && lastChild != m_focusedNote) | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 4826 | closeEditor(); | |||
4838 | } | 4838 | } | ||
4839 | 4839 | | |||
4840 | if (countFounds() == 0) | 4840 | if (countFounds() == 0) | ||
4841 | return; | 4841 | return; | ||
4842 | 4842 | | |||
4843 | if (!m_focusedNote) | 4843 | if (!m_focusedNote) | ||
4844 | return; | 4844 | return; | ||
4845 | 4845 | | |||
4846 | Note *toFocus = 0L; | 4846 | Note *toFocus = nullptr; | ||
4847 | 4847 | | |||
4848 | switch (event->key()) { | 4848 | switch (event->key()) { | ||
4849 | case Qt::Key_Down: | 4849 | case Qt::Key_Down: | ||
4850 | toFocus = (isFreeLayout() ? noteOn(BOTTOM_SIDE) : m_focusedNote->nextShownInStack()); | 4850 | toFocus = (isFreeLayout() ? noteOn(BOTTOM_SIDE) : m_focusedNote->nextShownInStack()); | ||
4851 | if (toFocus) | 4851 | if (toFocus) | ||
4852 | break; | 4852 | break; | ||
4853 | // scrollBy(0, 30); // This cases do not move focus to another note... | 4853 | // scrollBy(0, 30); // This cases do not move focus to another note... | ||
4854 | return; | 4854 | return; | ||
Show All 10 Lines | 4864 | for (int i = 0; i < 10 && m_focusedNote; ++i) | |||
4865 | m_focusedNote = noteOn(BOTTOM_SIDE); | 4865 | m_focusedNote = noteOn(BOTTOM_SIDE); | ||
4866 | toFocus = m_focusedNote; | 4866 | toFocus = m_focusedNote; | ||
4867 | m_focusedNote = lastFocused; | 4867 | m_focusedNote = lastFocused; | ||
4868 | } else { | 4868 | } else { | ||
4869 | toFocus = m_focusedNote; | 4869 | toFocus = m_focusedNote; | ||
4870 | for (int i = 0; i < 10 && toFocus; ++i) | 4870 | for (int i = 0; i < 10 && toFocus; ++i) | ||
4871 | toFocus = toFocus->nextShownInStack(); | 4871 | toFocus = toFocus->nextShownInStack(); | ||
4872 | } | 4872 | } | ||
4873 | if (toFocus == 0L) | 4873 | if (toFocus == nullptr) | ||
4874 | toFocus = (isFreeLayout() ? noteOnEnd() : lastNoteShownInStack()); | 4874 | toFocus = (isFreeLayout() ? noteOnEnd() : lastNoteShownInStack()); | ||
4875 | if (toFocus && toFocus != m_focusedNote) | 4875 | if (toFocus && toFocus != m_focusedNote) | ||
4876 | break; | 4876 | break; | ||
4877 | // scrollBy(0, visibleHeight() / 2); // This cases do not move focus to another note... | 4877 | // scrollBy(0, visibleHeight() / 2); // This cases do not move focus to another note... | ||
4878 | // scrollBy(0, viewport()->height() / 2); // This cases do not move focus to another note... | 4878 | // scrollBy(0, viewport()->height() / 2); // This cases do not move focus to another note... | ||
4879 | return; | 4879 | return; | ||
4880 | case Qt::Key_PageUp: | 4880 | case Qt::Key_PageUp: | ||
4881 | if (isFreeLayout()) { | 4881 | if (isFreeLayout()) { | ||
4882 | Note *lastFocused = m_focusedNote; | 4882 | Note *lastFocused = m_focusedNote; | ||
4883 | for (int i = 0; i < 10 && m_focusedNote; ++i) | 4883 | for (int i = 0; i < 10 && m_focusedNote; ++i) | ||
4884 | m_focusedNote = noteOn(TOP_SIDE); | 4884 | m_focusedNote = noteOn(TOP_SIDE); | ||
4885 | toFocus = m_focusedNote; | 4885 | toFocus = m_focusedNote; | ||
4886 | m_focusedNote = lastFocused; | 4886 | m_focusedNote = lastFocused; | ||
4887 | } else { | 4887 | } else { | ||
4888 | toFocus = m_focusedNote; | 4888 | toFocus = m_focusedNote; | ||
4889 | for (int i = 0; i < 10 && toFocus; ++i) | 4889 | for (int i = 0; i < 10 && toFocus; ++i) | ||
4890 | toFocus = toFocus->prevShownInStack(); | 4890 | toFocus = toFocus->prevShownInStack(); | ||
4891 | } | 4891 | } | ||
4892 | if (toFocus == 0L) | 4892 | if (toFocus == nullptr) | ||
4893 | toFocus = (isFreeLayout() ? noteOnHome() : firstNoteShownInStack()); | 4893 | toFocus = (isFreeLayout() ? noteOnHome() : firstNoteShownInStack()); | ||
4894 | if (toFocus && toFocus != m_focusedNote) | 4894 | if (toFocus && toFocus != m_focusedNote) | ||
4895 | break; | 4895 | break; | ||
4896 | // scrollBy(0, - visibleHeight() / 2); // This cases do not move focus to another note... | 4896 | // scrollBy(0, - visibleHeight() / 2); // This cases do not move focus to another note... | ||
4897 | // scrollBy(0, - viewport()->height() / 2); // This cases do not move focus to another note... | 4897 | // scrollBy(0, - viewport()->height() / 2); // This cases do not move focus to another note... | ||
4898 | return; | 4898 | return; | ||
4899 | case Qt::Key_Home: | 4899 | case Qt::Key_Home: | ||
4900 | toFocus = noteOnHome(); | 4900 | toFocus = noteOnHome(); | ||
Show All 23 Lines | 4922 | if (m_focusedNote) { | |||
4924 | event->accept(); | 4924 | event->accept(); | ||
4925 | } else | 4925 | } else | ||
4926 | event->ignore(); | 4926 | event->ignore(); | ||
4927 | return; // ... so we return after the process | 4927 | return; // ... so we return after the process | ||
4928 | default: | 4928 | default: | ||
4929 | return; | 4929 | return; | ||
4930 | } | 4930 | } | ||
4931 | 4931 | | |||
4932 | if (toFocus == 0L) { // If no direction keys have been pressed OR reached out the begin or end | 4932 | if (toFocus == nullptr) { // If no direction keys have been pressed OR reached out the begin or end | ||
4933 | event->ignore(); // Important !! | 4933 | event->ignore(); // Important !! | ||
4934 | return; | 4934 | return; | ||
4935 | } | 4935 | } | ||
4936 | 4936 | | |||
4937 | if (event->modifiers() & Qt::ShiftModifier) { // Shift+arrowKeys selection | 4937 | if (event->modifiers() & Qt::ShiftModifier) { // Shift+arrowKeys selection | ||
4938 | if (m_startOfShiftSelectionNote == 0L) | 4938 | if (m_startOfShiftSelectionNote == nullptr) | ||
4939 | m_startOfShiftSelectionNote = toFocus; | 4939 | m_startOfShiftSelectionNote = toFocus; | ||
4940 | ensureNoteVisible(toFocus); // Important: this line should be before the other ones because else repaint would be done on the wrong part! | 4940 | ensureNoteVisible(toFocus); // Important: this line should be before the other ones because else repaint would be done on the wrong part! | ||
4941 | selectRange(m_startOfShiftSelectionNote, toFocus); | 4941 | selectRange(m_startOfShiftSelectionNote, toFocus); | ||
4942 | setFocusedNote(toFocus); | 4942 | setFocusedNote(toFocus); | ||
4943 | event->accept(); | 4943 | event->accept(); | ||
4944 | return; | 4944 | return; | ||
4945 | } else /*if (toFocus != m_focusedNote)*/ { // Move focus to ANOTHER note... | 4945 | } else /*if (toFocus != m_focusedNote)*/ { // Move focus to ANOTHER note... | ||
4946 | ensureNoteVisible(toFocus); // Important: this line should be before the other ones because else repaint would be done on the wrong part! | 4946 | ensureNoteVisible(toFocus); // Important: this line should be before the other ones because else repaint would be done on the wrong part! | ||
Show All 9 Lines | |||||
4956 | } | 4956 | } | ||
4957 | 4957 | | |||
4958 | /** Select a range of notes and deselect the others. | 4958 | /** Select a range of notes and deselect the others. | ||
4959 | * The order between start and end has no importance (end could be before start) | 4959 | * The order between start and end has no importance (end could be before start) | ||
4960 | */ | 4960 | */ | ||
4961 | void BasketScene::selectRange(Note *start, Note *end, bool unselectOthers /*= true*/) | 4961 | void BasketScene::selectRange(Note *start, Note *end, bool unselectOthers /*= true*/) | ||
4962 | { | 4962 | { | ||
4963 | Note *cur; | 4963 | Note *cur; | ||
4964 | Note *realEnd = 0L; | 4964 | Note *realEnd = nullptr; | ||
4965 | 4965 | | |||
4966 | // Avoid crash when start (or end) is null | 4966 | // Avoid crash when start (or end) is null | ||
4967 | if (start == 0L) | 4967 | if (start == nullptr) | ||
4968 | start = end; | 4968 | start = end; | ||
4969 | else if (end == 0L) | 4969 | else if (end == nullptr) | ||
4970 | end = start; | 4970 | end = start; | ||
4971 | // And if *both* are null | 4971 | // And if *both* are null | ||
4972 | if (start == 0L) { | 4972 | if (start == nullptr) { | ||
4973 | if (unselectOthers) | 4973 | if (unselectOthers) | ||
4974 | unselectAll(); | 4974 | unselectAll(); | ||
4975 | return; | 4975 | return; | ||
4976 | } | 4976 | } | ||
4977 | // In case there is only one note to select | 4977 | // In case there is only one note to select | ||
4978 | if (start == end) { | 4978 | if (start == end) { | ||
4979 | if (unselectOthers) | 4979 | if (unselectOthers) | ||
4980 | unselectAllBut(start); | 4980 | unselectAllBut(start); | ||
4981 | else | 4981 | else | ||
4982 | start->setSelected(true); | 4982 | start->setSelected(true); | ||
4983 | return; | 4983 | return; | ||
4984 | } | 4984 | } | ||
4985 | 4985 | | |||
4986 | // Free layout baskets should select range as if we were drawing a rectangle between start and end: | 4986 | // Free layout baskets should select range as if we were drawing a rectangle between start and end: | ||
4987 | if (isFreeLayout()) { | 4987 | if (isFreeLayout()) { | ||
4988 | QRectF startRect(start->x(), start->y(), start->width(), start->height()); | 4988 | QRectF startRect(start->x(), start->y(), start->width(), start->height()); | ||
4989 | QRectF endRect(end->x(), end->y(), end->width(), end->height()); | 4989 | QRectF endRect(end->x(), end->y(), end->width(), end->height()); | ||
4990 | QRectF toSelect = startRect.united(endRect); | 4990 | QRectF toSelect = startRect.united(endRect); | ||
4991 | selectNotesIn(toSelect, /*invertSelection=*/false, unselectOthers); | 4991 | selectNotesIn(toSelect, /*invertSelection=*/false, unselectOthers); | ||
4992 | return; | 4992 | return; | ||
4993 | } | 4993 | } | ||
4994 | 4994 | | |||
4995 | // Search the REAL first (and deselect the others before it) : | 4995 | // Search the REAL first (and deselect the others before it) : | ||
4996 | for (cur = firstNoteInStack(); cur != 0L; cur = cur->nextInStack()) { | 4996 | for (cur = firstNoteInStack(); cur != nullptr; cur = cur->nextInStack()) { | ||
4997 | if (cur == start || cur == end) | 4997 | if (cur == start || cur == end) | ||
4998 | break; | 4998 | break; | ||
4999 | if (unselectOthers) | 4999 | if (unselectOthers) | ||
5000 | cur->setSelected(false); | 5000 | cur->setSelected(false); | ||
5001 | } | 5001 | } | ||
5002 | 5002 | | |||
5003 | // Select the notes after REAL start, until REAL end : | 5003 | // Select the notes after REAL start, until REAL end : | ||
5004 | if (cur == start) | 5004 | if (cur == start) | ||
5005 | realEnd = end; | 5005 | realEnd = end; | ||
5006 | else if (cur == end) | 5006 | else if (cur == end) | ||
5007 | realEnd = start; | 5007 | realEnd = start; | ||
5008 | 5008 | | |||
5009 | for (/*cur = cur*/; cur != 0L; cur = cur->nextInStack()) { | 5009 | for (/*cur = cur*/; cur != nullptr; cur = cur->nextInStack()) { | ||
5010 | cur->setSelected(cur->isShown()); // Select all notes in the range, but only if they are shown | 5010 | cur->setSelected(cur->isShown()); // Select all notes in the range, but only if they are shown | ||
5011 | if (cur == realEnd) | 5011 | if (cur == realEnd) | ||
5012 | break; | 5012 | break; | ||
5013 | } | 5013 | } | ||
5014 | 5014 | | |||
5015 | if (!unselectOthers) | 5015 | if (!unselectOthers) | ||
5016 | return; | 5016 | return; | ||
5017 | 5017 | | |||
5018 | // Deselect the remaining notes : | 5018 | // Deselect the remaining notes : | ||
5019 | if (cur) | 5019 | if (cur) | ||
5020 | cur = cur->nextInStack(); | 5020 | cur = cur->nextInStack(); | ||
5021 | for (/*cur = cur*/; cur != 0L; cur = cur->nextInStack()) | 5021 | for (/*cur = cur*/; cur != nullptr; cur = cur->nextInStack()) | ||
5022 | cur->setSelected(false); | 5022 | cur->setSelected(false); | ||
5023 | } | 5023 | } | ||
5024 | 5024 | | |||
5025 | void BasketScene::focusInEvent(QFocusEvent *event) | 5025 | void BasketScene::focusInEvent(QFocusEvent *event) | ||
5026 | { | 5026 | { | ||
5027 | // Focus cannot be get with Tab when locked, but a click can focus the basket! | 5027 | // Focus cannot be get with Tab when locked, but a click can focus the basket! | ||
5028 | if (isLocked()) { | 5028 | if (isLocked()) { | ||
5029 | if (m_button) | 5029 | if (m_button) | ||
5030 | { | 5030 | { | ||
5031 | QGraphicsScene::focusInEvent(event); | 5031 | QGraphicsScene::focusInEvent(event); | ||
5032 | QTimer::singleShot(0, m_button, SLOT(setFocus())); | 5032 | QTimer::singleShot(0, m_button, SLOT(setFocus())); | ||
5033 | } | 5033 | } | ||
5034 | } else { | 5034 | } else { | ||
5035 | QGraphicsScene::focusInEvent(event); | 5035 | QGraphicsScene::focusInEvent(event); | ||
5036 | focusANote(); // hasFocus() is true at this stage, note will be focused | 5036 | focusANote(); // hasFocus() is true at this stage, note will be focused | ||
5037 | } | 5037 | } | ||
5038 | } | 5038 | } | ||
5039 | 5039 | | |||
5040 | void BasketScene::focusOutEvent(QFocusEvent*) | 5040 | void BasketScene::focusOutEvent(QFocusEvent*) | ||
5041 | { | 5041 | { | ||
5042 | if (m_focusedNote != 0L) | 5042 | if (m_focusedNote != nullptr) | ||
5043 | m_focusedNote->setFocused(false); | 5043 | m_focusedNote->setFocused(false); | ||
5044 | } | 5044 | } | ||
5045 | 5045 | | |||
5046 | void BasketScene::ensureNoteVisible(Note *note) | 5046 | void BasketScene::ensureNoteVisible(Note *note) | ||
5047 | { | 5047 | { | ||
5048 | if (!note->isShown()) // Logical! | 5048 | if (!note->isShown()) // Logical! | ||
5049 | return; | 5049 | return; | ||
5050 | 5050 | | |||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 5094 | while (selection) { | |||
5096 | selection = selection->nextStacked(); | 5096 | selection = selection->nextStacked(); | ||
5097 | } | 5097 | } | ||
5098 | } | 5098 | } | ||
5099 | DEBUG_WIN << "Watcher>Removed : <font color=blue>" + fullPath + "</font>"; | 5099 | DEBUG_WIN << "Watcher>Removed : <font color=blue>" + fullPath + "</font>"; | ||
5100 | } | 5100 | } | ||
5101 | 5101 | | |||
5102 | void BasketScene::updateModifiedNotes() | 5102 | void BasketScene::updateModifiedNotes() | ||
5103 | { | 5103 | { | ||
5104 | for (QList<QString>::iterator it = m_modifiedFiles.begin(); it != m_modifiedFiles.end(); ++it) { | 5104 | for (auto & m_modifiedFile : m_modifiedFiles) { | ||
alex: Formatting and use qAsConst(m_modifiedFiles) | |||||
5105 | Note *note = noteForFullPath(*it); | 5105 | Note *note = noteForFullPath(m_modifiedFile); | ||
5106 | if (note) | 5106 | if (note) | ||
5107 | note->content()->loadFromFile(/*lazyLoad=*/false); | 5107 | note->content()->loadFromFile(/*lazyLoad=*/false); | ||
5108 | } | 5108 | } | ||
5109 | m_modifiedFiles.clear(); | 5109 | m_modifiedFiles.clear(); | ||
5110 | } | 5110 | } | ||
5111 | 5111 | | |||
5112 | bool BasketScene::setProtection(int type, QString key) | 5112 | bool BasketScene::setProtection(int type, QString key) | ||
5113 | { | 5113 | { | ||
Show All 14 Lines | 5126 | } else { | |||
5128 | m_encryptionKey = savedKey; | 5128 | m_encryptionKey = savedKey; | ||
5129 | m_gpg->clearCache(); | 5129 | m_gpg->clearCache(); | ||
5130 | return false; | 5130 | return false; | ||
5131 | } | 5131 | } | ||
5132 | } | 5132 | } | ||
5133 | return true; | 5133 | return true; | ||
5134 | #else | 5134 | #else | ||
5135 | m_encryptionType = type; | 5135 | m_encryptionType = type; | ||
5136 | m_encryptionKey = key; | 5136 | m_encryptionKey = std::move(key); | ||
5137 | 5137 | | |||
5138 | return false; | 5138 | return false; | ||
5139 | #endif | 5139 | #endif | ||
5140 | } | 5140 | } | ||
5141 | 5141 | | |||
5142 | bool BasketScene::saveAgain() | 5142 | bool BasketScene::saveAgain() | ||
5143 | { | 5143 | { | ||
5144 | bool result = false; | 5144 | bool result = false; | ||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | |||||
5289 | { | 5289 | { | ||
5290 | // Modulus operandi: | 5290 | // Modulus operandi: | ||
5291 | // 1. Use QSaveFile to try and save the file | 5291 | // 1. Use QSaveFile to try and save the file | ||
5292 | // 2. Show a modal dialog (with the error) when bad things happen | 5292 | // 2. Show a modal dialog (with the error) when bad things happen | ||
5293 | // 3. We keep trying (at increasing intervals, up until every minute) | 5293 | // 3. We keep trying (at increasing intervals, up until every minute) | ||
5294 | // until we finally save the file. | 5294 | // until we finally save the file. | ||
5295 | 5295 | | |||
5296 | // The error dialog is static to make sure we never show the dialog twice, | 5296 | // The error dialog is static to make sure we never show the dialog twice, | ||
5297 | static DiskErrorDialog *dialog = 0; | 5297 | static DiskErrorDialog *dialog = nullptr; | ||
5298 | static const uint maxDelay = 60 * 1000; // ms | 5298 | static const uint maxDelay = 60 * 1000; // ms | ||
5299 | uint retryDelay = 1000; // ms | 5299 | uint retryDelay = 1000; // ms | ||
5300 | bool success = false; | 5300 | bool success = false; | ||
5301 | do { | 5301 | do { | ||
5302 | QSaveFile saveFile(fullPath); | 5302 | QSaveFile saveFile(fullPath); | ||
5303 | if (saveFile.open(QIODevice::WriteOnly)) { | 5303 | if (saveFile.open(QIODevice::WriteOnly)) { | ||
5304 | saveFile.write(array, length); | 5304 | saveFile.write(array, length); | ||
5305 | if (saveFile.commit()) | 5305 | if (saveFile.commit()) | ||
Show All 16 Lines | 5309 | if (!success) { | |||
5322 | } | 5322 | } | ||
5323 | // Double the retry delay, but don't go over the max. | 5323 | // Double the retry delay, but don't go over the max. | ||
5324 | retryDelay = qMin(maxDelay, retryDelay * 2); // ms | 5324 | retryDelay = qMin(maxDelay, retryDelay * 2); // ms | ||
5325 | } | 5325 | } | ||
5326 | } while (!success); | 5326 | } while (!success); | ||
5327 | 5327 | | |||
5328 | if (dialog) | 5328 | if (dialog) | ||
5329 | dialog->deleteLater(); | 5329 | dialog->deleteLater(); | ||
5330 | dialog = NULL; | 5330 | dialog = nullptr; | ||
5331 | 5331 | | |||
5332 | return true; // Guess we can't really return a fail | 5332 | return true; // Guess we can't really return a fail | ||
5333 | } | 5333 | } | ||
5334 | 5334 | | |||
5335 | /*static*/ bool BasketScene::safelySaveToFile(const QString& fullPath, const QString& string) | 5335 | /*static*/ bool BasketScene::safelySaveToFile(const QString& fullPath, const QString& string) | ||
5336 | { | 5336 | { | ||
5337 | QByteArray bytes = string.toUtf8(); | 5337 | QByteArray bytes = string.toUtf8(); | ||
5338 | return safelySaveToFile(fullPath, bytes, bytes.length()); | 5338 | return safelySaveToFile(fullPath, bytes, bytes.length()); | ||
Show All 14 Lines |
Add const for the tagId list, and no space after &