]> git.lyx.org Git - lyx.git/blob - src/frontends/qt/GuiChanges.cpp
b2f809b026a5bd9c620f339dd060552d09e551d7
[lyx.git] / src / frontends / qt / GuiChanges.cpp
1 /**
2  * \file GuiChanges.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Michael Gerz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "GuiChanges.h"
15
16 #include "qt_helpers.h"
17
18 #include "Author.h"
19 #include "Buffer.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
22 #include "Changes.h"
23 #include "Cursor.h"
24 #include "FuncRequest.h"
25 #include "LyXRC.h"
26
27 #include <QDateTime>
28 #include <QTextBrowser>
29
30
31 namespace lyx {
32 namespace frontend {
33
34
35 GuiChanges::GuiChanges(GuiView & lv)
36         : GuiDialog(lv, "changes", qt_("Merge Changes"))
37 {
38         setupUi(this);
39
40         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
41                 this, SLOT(slotButtonBox(QAbstractButton *)));
42         connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange()));
43         connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange()));
44         connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange()));
45         connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange()));
46
47         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
48         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
49 }
50
51
52 void GuiChanges::updateContents()
53 {
54         bool const changesPresent = buffer().areChangesPresent();
55         nextPB->setEnabled(changesPresent);
56         previousPB->setEnabled(changesPresent);
57         changeTB->setEnabled(changesPresent);
58
59         Change const & c = bufferview()->getCurrentChange();
60         bool const changePresent = c.type != Change::UNCHANGED;
61         rejectPB->setEnabled(changePresent && !isBufferReadonly());
62         acceptPB->setEnabled(changePresent && !isBufferReadonly());
63         bool const inserted = c.type == Change::INSERTED;
64
65         QString text;
66         if (changePresent) {
67                 QString const author =
68                         toqstr(buffer().params().authors().get(c.author).nameAndEmail());
69                 if (!author.isEmpty())
70                         text += inserted ? qt_("Inserted by %1").arg(author)
71                                          : qt_("Deleted by %1").arg(author);
72
73 #if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
74                 QString const date =
75                         QLocale().toString(QDateTime::fromSecsSinceEpoch(c.changetime),
76                                         QLocale::LongFormat);
77 #else
78                 QString const date =
79                         QLocale().toString(QDateTime::fromTime_t(c.changetime),
80                                         QLocale::LongFormat);
81 #endif
82                 if (!date.isEmpty()) {
83                         if (!author.isEmpty())
84                                 text += qt_(" on[[date]] %1").arg(date);
85                         else
86                                 text += inserted ? qt_("Inserted on %1").arg(date)
87                                                  : qt_("Deleted on %1").arg(date);
88                 }
89                 QString changedcontent = toqstr(bufferview()->cursor().selectionAsString(false));
90                 if (!changedcontent.isEmpty()) {
91                         text += ":<br><br><b>";
92                         if (inserted)
93                                 text += "<u><span style=\"color:blue\">";
94                         else
95                                 text += "<s><span style=\"color:red\">";
96                         text += changedcontent;
97                         if (inserted)
98                                 text += "</u></span></b>";
99                         else
100                                 text += "</s></span></b>";
101                 }
102         }
103         changeTB->setHtml(text);
104 }
105
106
107 void GuiChanges::nextChange()
108 {
109         dispatch(FuncRequest(LFUN_CHANGE_NEXT));
110 }
111
112
113 void GuiChanges::previousChange()
114 {
115         dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
116 }
117
118
119 void GuiChanges::acceptChange()
120 {
121         dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
122         nextChange();
123 }
124
125
126 void GuiChanges::rejectChange()
127 {
128         dispatch(FuncRequest(LFUN_CHANGE_REJECT));
129         nextChange();
130 }
131
132
133 } // namespace frontend
134 } // namespace lyx
135
136 #include "moc_GuiChanges.cpp"