zz_historyDialog.cpp

changeset 96
2f175b3d8211
child 97
52bcca21579e
equal deleted inserted replaced
95:0a8ad4e3e7c1 96:2f175b3d8211
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013 Santeri `arezey` Piippo
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "zz_historyDialog.h"
20 #include "history.h"
21 #include <qboxlayout.h>
22 #include <qmessagebox.h>
23
24 EXTERN_ACTION (undo);
25 EXTERN_ACTION (redo);
26
27 // =============================================================================
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
29 // =============================================================================
30 HistoryDialog::HistoryDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
31 qHistoryList = new QListWidget;
32 qUndoButton = new QPushButton ("Undo");
33 qRedoButton = new QPushButton ("Redo");
34 qClearButton = new QPushButton ("Clear");
35 qButtons = new QDialogButtonBox (QDialogButtonBox::Close);
36
37 qUndoButton->setIcon (getIcon ("undo"));
38 qRedoButton->setIcon (getIcon ("redo"));
39
40 connect (qUndoButton, SIGNAL (clicked ()), this, SLOT (slot_undo ()));
41 connect (qRedoButton, SIGNAL (clicked ()), this, SLOT (slot_redo ()));
42 connect (qClearButton, SIGNAL (clicked ()), this, SLOT (slot_clear ()));
43 connect (qButtons, SIGNAL (rejected ()), this, SLOT (reject ()));
44
45 QVBoxLayout* qButtonLayout = new QVBoxLayout;
46 qButtonLayout->setDirection (QBoxLayout::TopToBottom);
47 qButtonLayout->addWidget (qUndoButton);
48 qButtonLayout->addWidget (qRedoButton);
49 qButtonLayout->addWidget (qClearButton);
50 qButtonLayout->addStretch ();
51
52 QGridLayout* qLayout = new QGridLayout;
53 qLayout->addWidget (qHistoryList, 0, 0, 2, 1);
54 qLayout->addLayout (qButtonLayout, 0, 1);
55 qLayout->addWidget (qButtons, 1, 1);
56
57 setLayout (qLayout);
58 setWindowIcon (getIcon ("history"));
59 setWindowTitle (APPNAME_DISPLAY " - Edit history");
60
61 populateList ();
62 updateButtons ();
63 }
64
65 // =============================================================================
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
67 // =============================================================================
68 void HistoryDialog::populateList () {
69 qHistoryList->clear ();
70
71 for (HistoryEntry* entry : History::entries) {
72 str zText;
73
74 switch (entry->type ()) {
75 case HISTORY_Addition:
76 {
77 AdditionHistory* addentry = static_cast<AdditionHistory*> (entry);
78 zText.format ("Added %s", LDObject::objectListContents (addentry->paObjs).chars());
79 }
80 break;
81
82 case HISTORY_QuadSplit:
83 {
84 QuadSplitHistory* splitentry = static_cast<QuadSplitHistory*> (entry);
85 ulong ulCount = splitentry->paQuads.size ();
86 zText.format ("Split %lu quad%s to triangles", ulCount, PLURAL (ulCount));
87 break;
88 }
89
90 default:
91 zText = "???";
92 break;
93 }
94
95 QListWidgetItem* qItem = new QListWidgetItem;
96 qItem->setText (zText);
97 qHistoryList->addItem (qItem);
98 }
99 }
100
101 // =============================================================================
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
103 // =============================================================================
104 void HistoryDialog::slot_undo () {
105 History::undo ();
106 updateButtons ();
107 }
108
109 // =============================================================================
110 void HistoryDialog::slot_redo () {
111 History::redo ();
112 updateButtons ();
113 }
114
115 // =============================================================================
116 void HistoryDialog::slot_clear () {
117 if (QMessageBox::question (this, "Confirm", "Are you sure you want to "
118 "clear the edit history?\nThis cannot be undone.",
119 (QMessageBox::Yes | QMessageBox::No), QMessageBox::No) != QMessageBox::Yes)
120 {
121 // Canceled
122 return;
123 }
124
125 History::clear ();
126 populateList ();
127 }
128
129 // =============================================================================
130 void HistoryDialog::updateButtons () {
131 qUndoButton->setEnabled (ACTION_NAME (undo)->isEnabled ());
132 qRedoButton->setEnabled (ACTION_NAME (redo)->isEnabled ());
133 }

mercurial