zz_historyDialog.cpp

Thu, 11 Apr 2013 01:35:30 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 11 Apr 2013 01:35:30 +0300
changeset 97
52bcca21579e
parent 96
2f175b3d8211
child 98
5dcc551f260a
permissions
-rw-r--r--

Fleshed out the history dialog further

96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri `arezey` Piippo
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #include "zz_historyDialog.h"
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include "history.h"
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
21 #include "colors.h"
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <qboxlayout.h>
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <qmessagebox.h>
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 EXTERN_ACTION (undo);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 EXTERN_ACTION (redo);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 HistoryDialog::HistoryDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 qHistoryList = new QListWidget;
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 qUndoButton = new QPushButton ("Undo");
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 qRedoButton = new QPushButton ("Redo");
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 qClearButton = new QPushButton ("Clear");
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 qButtons = new QDialogButtonBox (QDialogButtonBox::Close);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
38 qHistoryList->setAlternatingRowColors (true);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
39
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 qUndoButton->setIcon (getIcon ("undo"));
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 qRedoButton->setIcon (getIcon ("redo"));
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 connect (qUndoButton, SIGNAL (clicked ()), this, SLOT (slot_undo ()));
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 connect (qRedoButton, SIGNAL (clicked ()), this, SLOT (slot_redo ()));
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 connect (qClearButton, SIGNAL (clicked ()), this, SLOT (slot_clear ()));
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ()));
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
47 connect (qHistoryList, SIGNAL (itemSelectionChanged ()), this, SLOT (slot_selChanged ()));
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 QVBoxLayout* qButtonLayout = new QVBoxLayout;
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 qButtonLayout->setDirection (QBoxLayout::TopToBottom);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 qButtonLayout->addWidget (qUndoButton);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 qButtonLayout->addWidget (qRedoButton);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 qButtonLayout->addWidget (qClearButton);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 qButtonLayout->addStretch ();
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 QGridLayout* qLayout = new QGridLayout;
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 qLayout->addWidget (qHistoryList, 0, 0, 2, 1);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 qLayout->addLayout (qButtonLayout, 0, 1);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 qLayout->addWidget (qButtons, 1, 1);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 setLayout (qLayout);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 setWindowIcon (getIcon ("history"));
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 setWindowTitle (APPNAME_DISPLAY " - Edit history");
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 populateList ();
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 updateButtons ();
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
67 updateSelection ();
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 void HistoryDialog::populateList () {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 qHistoryList->clear ();
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
76 QListWidgetItem* qItem = new QListWidgetItem;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
77 qItem->setText ("[[ initial state ]]");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
78 qItem->setIcon (getIcon ("empty"));
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
79 qHistoryList->addItem (qItem);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
80
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 for (HistoryEntry* entry : History::entries) {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 str zText;
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
83 QIcon qEntryIcon;
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 switch (entry->type ()) {
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
86 case HISTORY_Add:
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 {
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
88 AddHistory* addentry = static_cast<AddHistory*> (entry);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
89 ulong ulCount = addentry->paObjs.size ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
90 str zVerb = "Added";
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
91
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
92 switch (addentry->eType) {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
93 case AddHistory::Paste:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
94 zVerb = "Pasted";
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
95 qEntryIcon = getIcon ("paste");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
96 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
98 default:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
99 {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
100 // Determine a common type for these objects. If all objects are of the same
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
101 // type, we display its addition icon. Otherwise, we draw a subfile addition
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
102 // one as a default.
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
103 LDObjectType_e eCommonType = OBJ_Unidentified;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
104 for (LDObject* obj : addentry->paObjs) {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
105 if (eCommonType == OBJ_Unidentified or obj->getType() == eCommonType)
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
106 eCommonType = obj->getType ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
107 else {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
108 eCommonType = OBJ_Unidentified;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
109 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
110 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
111 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
112
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
113 // Set the icon based on the common type decided above.
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
114 if (eCommonType == OBJ_Unidentified)
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
115 qEntryIcon = getIcon ("add-subfile");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
116 else
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
117 qEntryIcon = getIcon (str::mkfmt ("add-%s", g_saObjTypeIcons[eCommonType]));
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
118 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
119 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
120 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
121
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
122 zText.format ("%s %lu objects\n%s", zVerb.chars(), ulCount,
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
123 LDObject::objectListContents (addentry->paObjs).chars());
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 break;
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 case HISTORY_QuadSplit:
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 QuadSplitHistory* splitentry = static_cast<QuadSplitHistory*> (entry);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 ulong ulCount = splitentry->paQuads.size ();
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 zText.format ("Split %lu quad%s to triangles", ulCount, PLURAL (ulCount));
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
132
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
133 qEntryIcon = getIcon ("quad-split");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
134 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
135 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
136
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
137 case HISTORY_Del:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
138 {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
139 DelHistory* delentry = static_cast<DelHistory*> (entry);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
140 ulong ulCount = delentry->cache.size ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
141 str zVerb = "Deleted";
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
142 qEntryIcon = getIcon ("delete");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
143
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
144 switch (delentry->eType) {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
145 case DelHistory::Cut:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
146 qEntryIcon = getIcon ("cut");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
147 zVerb = "Cut";
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
148 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
149
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
150 default:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
151 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
152 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
153
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
154 zText.format ("%s %lu objects:\n%s", zVerb.chars(), ulCount,
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
155 LDObject::objectListContents (delentry->cache).chars ());
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 }
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
157 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
158
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
159 case HISTORY_SetColor:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
160 {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
161 SetColorHistory* colentry = static_cast<SetColorHistory*> (entry);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
162 ulong ulCount = colentry->ulaIndices.size ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
163 zText.format ("Set color of %lu objects to %d (%s)", ulCount,
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
164 colentry->dNewColor, getColor (colentry->dNewColor)->zName.chars());
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
165
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
166 qEntryIcon = getIcon ("palette");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
167 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
168 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
169
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
170 case HISTORY_ListMove:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
171 {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
172 ListMoveHistory* moveentry = static_cast<ListMoveHistory*> (entry);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
173 ulong ulCount = moveentry->ulaIndices.size ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
174
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
175 zText.format ("Moved %lu objects %s", ulCount,
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
176 moveentry->bUp ? "up" : "down");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
177 qEntryIcon = getIcon (moveentry->bUp ? "arrow-up" : "arrow-down");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
178 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
179 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
180
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
181 case HISTORY_SetContents:
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
182 {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
183 SetContentsHistory* setentry = static_cast<SetContentsHistory*> (entry);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
184
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
185 zText.format ("Set contents of %s\n%s (%s)",
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
186 g_saObjTypeNames [setentry->oldObj->getType ()],
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
187 setentry->newObj->getContents ().chars (),
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
188 g_saObjTypeNames [setentry->newObj->getType ()]);
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
189 qEntryIcon = getIcon ("set-contents");
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
190 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
191 break;
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 default:
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 zText = "???";
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 break;
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 QListWidgetItem* qItem = new QListWidgetItem;
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199 qItem->setText (zText);
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
200 qItem->setIcon (qEntryIcon);
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 qHistoryList->addItem (qItem);
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 void HistoryDialog::slot_undo () {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 History::undo ();
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 updateButtons ();
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
211 updateSelection ();
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
212 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 void HistoryDialog::slot_redo () {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 History::redo ();
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217 updateButtons ();
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
218 updateSelection ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
219 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
220
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
221 void HistoryDialog::updateSelection () {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
222 qHistoryList->setCurrentItem (qHistoryList->item (History::pos () + 1));
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 void HistoryDialog::slot_clear () {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
227 if (QMessageBox::question (this, "Confirm", "Are you sure you want to "
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 "clear the edit history?\nThis cannot be undone.",
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes)
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 // Canceled
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 return;
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 History::clear ();
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 populateList ();
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
237 updateButtons ();
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 }
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 // =============================================================================
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 void HistoryDialog::updateButtons () {
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 qUndoButton->setEnabled (ACTION_NAME (undo)->isEnabled ());
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243 qRedoButton->setEnabled (ACTION_NAME (redo)->isEnabled ());
97
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
244 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
245
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
246 // =============================================================================
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
247 void HistoryDialog::slot_selChanged () {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
248 if (qHistoryList->selectedItems ().size () != 1)
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
249 return;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
250
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
251 QListWidgetItem* qItem = qHistoryList->selectedItems ()[0];
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
252
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
253 // Find the index of the edit
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
254 long idx = -1;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
255 QListWidgetItem* it;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
256 while ((it = qHistoryList->item (++idx)) != nullptr)
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
257 if (it == qItem)
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
258 break;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
259
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
260 idx--; // qHistoryList is 0-based, History is -1-based.
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
261
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
262 if (idx == History::pos ())
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
263 return;
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
264
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
265 // Seek to the selected edit by repeadetly undoing or redoing.
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
266 while (History::pos () != idx) {
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
267 if (History::pos () > idx)
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
268 History::undo ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
269 else
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
270 History::redo ();
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
271 }
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
272
52bcca21579e Fleshed out the history dialog further
Santeri Piippo <crimsondusk64@gmail.com>
parents: 96
diff changeset
273 updateButtons ();
96
2f175b3d8211 Added history dialog, cannot display all types yet
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 }

mercurial