@@ -37,12 +37,12 @@ NotesManagement::~NotesManagement()
37
37
void NotesManagement::setWsClient (WSClient *c)
38
38
{
39
39
wsClient = c;
40
- connect (wsClient, &WSClient::notesFetched, this , &NotesManagement::loadNodes );
40
+ connect (wsClient, &WSClient::notesFetched, this , &NotesManagement::loadNotes );
41
41
connect (wsClient, &WSClient::noteSaved, this , &NotesManagement::onNoteSaved);
42
42
connect (wsClient, &WSClient::noteDeleted, this , &NotesManagement::onNoteDeleted);
43
43
}
44
44
45
- void NotesManagement::loadNodes (const QJsonArray ¬es)
45
+ void NotesManagement::loadNotes (const QJsonArray ¬es)
46
46
{
47
47
clearNotes ();
48
48
for (auto noteObj : notes)
@@ -51,17 +51,28 @@ void NotesManagement::loadNodes(const QJsonArray ¬es)
51
51
QString noteName = jsonObject.value (" name" ).toString ();
52
52
53
53
addNewIcon (noteName);
54
+ m_noteList.append (noteName);
55
+ }
56
+ }
57
+
58
+ void NotesManagement::refreshNotes ()
59
+ {
60
+ clearNotes (false );
61
+ for (const auto & noteName : m_noteList)
62
+ {
63
+ addNewIcon (noteName);
54
64
}
55
65
}
56
66
57
67
void NotesManagement::addNewIcon (const QString &name)
58
68
{
59
- auto * vertLayout = new QVBoxLayout ();
69
+
70
+ auto * vertIconNameLayout = new QVBoxLayout ();
60
71
auto * labelIcon = new ClickableLabel ();
61
72
labelIcon->setAlignment (Qt::AlignCenter);
62
73
labelIcon->setPixmap (QString::fromUtf8 (" :/note.png" ));
63
- labelIcon->setMaximumSize (200 ,200 );
64
- labelIcon->setPixmap (labelIcon->pixmap ()->scaled (200 ,200 , Qt::KeepAspectRatio));
74
+ labelIcon->setMaximumSize (160 ,200 );
75
+ labelIcon->setPixmap (labelIcon->pixmap ()->scaled (160 ,200 , Qt::KeepAspectRatio));
65
76
labelIcon->setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Preferred);
66
77
labelIcon->setAlignment (Qt::AlignCenter);
67
78
@@ -71,8 +82,17 @@ void NotesManagement::addNewIcon(const QString &name)
71
82
emit changeNote ();
72
83
});
73
84
85
+ vertIconNameLayout->addWidget (labelIcon);
86
+
87
+ auto * labelName = new QLabel ();
88
+ labelName->setAlignment (Qt::AlignCenter);
89
+ labelName->setText (name);
90
+
91
+ vertIconNameLayout->addWidget (labelName);
92
+ vertIconNameLayout->addItem (new QSpacerItem (20 , 40 , QSizePolicy::Minimum, QSizePolicy::Expanding));
93
+
74
94
auto * iconHorizontalLayout = new QHBoxLayout ();
75
- iconHorizontalLayout->addWidget (labelIcon );
95
+ iconHorizontalLayout->addItem (vertIconNameLayout );
76
96
77
97
QToolButton *buttonRemove = new QToolButton;
78
98
buttonRemove->setToolButtonStyle (Qt::ToolButtonIconOnly);
@@ -90,36 +110,36 @@ void NotesManagement::addNewIcon(const QString &name)
90
110
91
111
auto * removeLayout = new QVBoxLayout ();
92
112
removeLayout->addWidget (buttonRemove);
93
- removeLayout->addItem (new QSpacerItem (20 , 120 , QSizePolicy::Minimum, QSizePolicy::Preferred));
94
- iconHorizontalLayout->addItem (removeLayout);
95
-
96
- vertLayout->addItem (iconHorizontalLayout);
113
+ removeLayout->addItem (new QSpacerItem (20 , 60 , QSizePolicy::Minimum, QSizePolicy::Expanding));
114
+ iconHorizontalLayout->addLayout (removeLayout);
97
115
98
- auto * labelName = new QLabel ();
99
- labelName->setAlignment (Qt::AlignCenter);
100
- labelName->setText (name);
101
-
102
- vertLayout->addWidget (labelName);
103
- vertLayout->addItem (new QSpacerItem (20 , 40 , QSizePolicy::Minimum, QSizePolicy::Expanding));
116
+ auto * vertLayout = new QVBoxLayout ();
117
+ vertLayout->addLayout (iconHorizontalLayout);
104
118
105
119
int row = ui->gridLayoutNotes ->rowCount () - 1 ;
106
120
if (m_actColumn == 4 )
107
121
{
108
122
m_actColumn = 0 ;
109
123
++row;
110
124
}
111
- ui->gridLayoutNotes ->addLayout (vertLayout, row, m_actColumn++, 1 , 1 );
112
- m_noteList.append (name);
125
+
126
+ QWidget *iconWidget = new QWidget ();
127
+ iconWidget->setLayout (vertLayout);
128
+ iconWidget->setMaximumWidth (190 );
129
+ ui->gridLayoutNotes ->addWidget (iconWidget, row, m_actColumn++, 1 , 1 );
113
130
}
114
131
115
- void NotesManagement::clearNotes ()
132
+ void NotesManagement::clearNotes (bool clearNoteList /* = true */ )
116
133
{
117
134
for (int i = 0 ; i < ui->gridLayoutNotes ->rowCount (); ++i)
118
135
{
119
136
GridLayoutUtil::removeRow (ui->gridLayoutNotes , i);
120
137
}
121
138
m_actColumn = 0 ;
122
- m_noteList.clear ();
139
+ if (clearNoteList)
140
+ {
141
+ m_noteList.clear ();
142
+ }
123
143
}
124
144
125
145
void NotesManagement::on_pushButtonAddNote_clicked ()
@@ -192,6 +212,7 @@ void NotesManagement::onNoteSaved(const QString ¬e, bool success)
192
212
if (m_isNewFile)
193
213
{
194
214
addNewIcon (note);
215
+ m_noteList.append (note);
195
216
}
196
217
}
197
218
else
@@ -238,7 +259,7 @@ void NotesManagement::onEditingFinished()
238
259
void NotesManagement::on_textEditNote_textChanged ()
239
260
{
240
261
QString note = ui->textEditNote ->toPlainText ();
241
- if (note == m_noteContentClone || note.isEmpty () || !m_validNoteName)
262
+ if (note == m_noteContentClone || note.isEmpty () || (m_isNewFile && !m_validNoteName) )
242
263
{
243
264
ui->pushButtonSave ->hide ();
244
265
}
@@ -254,8 +275,8 @@ void NotesManagement::onNoteDeleted(bool success, const QString ¬e)
254
275
emit updateTabs ();
255
276
if (success)
256
277
{
257
- clearNotes ( );
258
- wsClient-> sendFetchNotes ();
278
+ m_noteList. removeOne (note );
279
+ refreshNotes ();
259
280
QMessageBox::information (this , tr (" Note Deleted" ), tr (" '%1' note was deleted successfully!" ).arg (note));
260
281
}
261
282
else
0 commit comments