zz_historyDialog.cpp

changeset 135
c243df39913e
parent 117
7eb7a43a511b
child 160
edcb03f3ef75
equal deleted inserted replaced
134:7fd0784471df 135:c243df39913e
27 27
28 // ============================================================================= 28 // =============================================================================
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
30 // ============================================================================= 30 // =============================================================================
31 HistoryDialog::HistoryDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) { 31 HistoryDialog::HistoryDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
32 qHistoryList = new QListWidget; 32 historyList = new QListWidget;
33 qUndoButton = new QPushButton ("Undo"); 33 undoButton = new QPushButton ("Undo");
34 qRedoButton = new QPushButton ("Redo"); 34 redoButton = new QPushButton ("Redo");
35 qClearButton = new QPushButton ("Clear"); 35 clearButton = new QPushButton ("Clear");
36 qButtons = new QDialogButtonBox (QDialogButtonBox::Close); 36 buttons = new QDialogButtonBox (QDialogButtonBox::Close);
37 37
38 qHistoryList->setAlternatingRowColors (true); 38 historyList->setAlternatingRowColors (true);
39 39
40 qUndoButton->setIcon (getIcon ("undo")); 40 undoButton->setIcon (getIcon ("undo"));
41 qRedoButton->setIcon (getIcon ("redo")); 41 redoButton->setIcon (getIcon ("redo"));
42 42
43 connect (qUndoButton, SIGNAL (clicked ()), this, SLOT (slot_undo ())); 43 connect (undoButton, SIGNAL (clicked ()), this, SLOT (slot_undo ()));
44 connect (qRedoButton, SIGNAL (clicked ()), this, SLOT (slot_redo ())); 44 connect (redoButton, SIGNAL (clicked ()), this, SLOT (slot_redo ()));
45 connect (qClearButton, SIGNAL (clicked ()), this, SLOT (slot_clear ())); 45 connect (clearButton, SIGNAL (clicked ()), this, SLOT (slot_clear ()));
46 connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ())); 46 connect (buttons, SIGNAL (rejected ()), this, SLOT (reject ()));
47 connect (qHistoryList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selChanged ())); 47 connect (historyList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selChanged ()));
48 48
49 QVBoxLayout* qButtonLayout = new QVBoxLayout; 49 QVBoxLayout* qButtonLayout = new QVBoxLayout;
50 qButtonLayout->setDirection (QBoxLayout::TopToBottom); 50 qButtonLayout->setDirection (QBoxLayout::TopToBottom);
51 qButtonLayout->addWidget (qUndoButton); 51 qButtonLayout->addWidget (undoButton);
52 qButtonLayout->addWidget (qRedoButton); 52 qButtonLayout->addWidget (redoButton);
53 qButtonLayout->addWidget (qClearButton); 53 qButtonLayout->addWidget (clearButton);
54 qButtonLayout->addStretch (); 54 qButtonLayout->addStretch ();
55 55
56 QGridLayout* qLayout = new QGridLayout; 56 QGridLayout* qLayout = new QGridLayout;
57 qLayout->setColumnStretch (0, 1); 57 qLayout->setColumnStretch (0, 1);
58 qLayout->addWidget (qHistoryList, 0, 0, 2, 1); 58 qLayout->addWidget (historyList, 0, 0, 2, 1);
59 qLayout->addLayout (qButtonLayout, 0, 1); 59 qLayout->addLayout (qButtonLayout, 0, 1);
60 qLayout->addWidget (qButtons, 1, 1); 60 qLayout->addWidget (buttons, 1, 1);
61 61
62 setLayout (qLayout); 62 setLayout (qLayout);
63 setWindowIcon (getIcon ("history")); 63 setWindowIcon (getIcon ("history"));
64 setWindowTitle (APPNAME_DISPLAY " - Edit history"); 64 setWindowTitle (APPNAME_DISPLAY " - Edit history");
65 65
70 70
71 // ============================================================================= 71 // =============================================================================
72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 72 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
73 // ============================================================================= 73 // =============================================================================
74 void HistoryDialog::populateList () { 74 void HistoryDialog::populateList () {
75 qHistoryList->clear (); 75 historyList->clear ();
76 76
77 QListWidgetItem* qItem = new QListWidgetItem; 77 QListWidgetItem* qItem = new QListWidgetItem;
78 qItem->setText ("[[ initial state ]]"); 78 qItem->setText ("[[ initial state ]]");
79 qItem->setIcon (getIcon ("empty")); 79 qItem->setIcon (getIcon ("empty"));
80 qHistoryList->addItem (qItem); 80 historyList->addItem (qItem);
81 81
82 for (HistoryEntry* entry : History::entries) { 82 for (HistoryEntry* entry : History::entries) {
83 str zText; 83 str zText;
84 QIcon qEntryIcon; 84 QIcon qEntryIcon;
85 85
209 } 209 }
210 210
211 QListWidgetItem* qItem = new QListWidgetItem; 211 QListWidgetItem* qItem = new QListWidgetItem;
212 qItem->setText (zText); 212 qItem->setText (zText);
213 qItem->setIcon (qEntryIcon); 213 qItem->setIcon (qEntryIcon);
214 qHistoryList->addItem (qItem); 214 historyList->addItem (qItem);
215 } 215 }
216 } 216 }
217 217
218 // ============================================================================= 218 // =============================================================================
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
230 updateButtons (); 230 updateButtons ();
231 updateSelection (); 231 updateSelection ();
232 } 232 }
233 233
234 void HistoryDialog::updateSelection () { 234 void HistoryDialog::updateSelection () {
235 qHistoryList->setCurrentItem (qHistoryList->item (History::pos () + 1)); 235 historyList->setCurrentItem (historyList->item (History::pos () + 1));
236 } 236 }
237 237
238 // ============================================================================= 238 // =============================================================================
239 void HistoryDialog::slot_clear () { 239 void HistoryDialog::slot_clear () {
240 if (!confirm ("Are you sure you want to clear the edit history?\nThis cannot be undone.")) 240 if (!confirm ("Are you sure you want to clear the edit history?\nThis cannot be undone."))
245 updateButtons (); 245 updateButtons ();
246 } 246 }
247 247
248 // ============================================================================= 248 // =============================================================================
249 void HistoryDialog::updateButtons () { 249 void HistoryDialog::updateButtons () {
250 qUndoButton->setEnabled (ACTION_NAME (undo)->isEnabled ()); 250 undoButton->setEnabled (ACTION (undo)->isEnabled ());
251 qRedoButton->setEnabled (ACTION_NAME (redo)->isEnabled ()); 251 redoButton->setEnabled (ACTION (redo)->isEnabled ());
252 } 252 }
253 253
254 // ============================================================================= 254 // =============================================================================
255 void HistoryDialog::slot_selChanged () { 255 void HistoryDialog::slot_selChanged () {
256 if (qHistoryList->selectedItems ().size () != 1) 256 if (historyList->selectedItems ().size () != 1)
257 return; 257 return;
258 258
259 QListWidgetItem* qItem = qHistoryList->selectedItems ()[0]; 259 QListWidgetItem* qItem = historyList->selectedItems ()[0];
260 260
261 // Find the index of the edit 261 // Find the index of the edit
262 long lIdx; 262 long lIdx;
263 for (lIdx = 0; lIdx < qHistoryList->count (); ++lIdx) 263 for (lIdx = 0; lIdx < historyList->count (); ++lIdx)
264 if (qHistoryList->item (lIdx) == qItem) 264 if (historyList->item (lIdx) == qItem)
265 break; 265 break;
266 266
267 // qHistoryList is 0-based, History is -1-based, thus decrement 267 // qHistoryList is 0-based, History is -1-based, thus decrement
268 // the index now 268 // the index now
269 lIdx--; 269 lIdx--;

mercurial