3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "GuiChanges.h"
16 #include "qt_helpers.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
24 #include "FuncRequest.h"
28 #include <QTextBrowser>
35 GuiChanges::GuiChanges(GuiView & lv)
36 : GuiDialog(lv, "changes", qt_("Merge Changes"))
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()));
47 bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
48 bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
52 void GuiChanges::updateContents()
54 bool const changesPresent = buffer().areChangesPresent();
55 nextPB->setEnabled(changesPresent);
56 previousPB->setEnabled(changesPresent);
57 changeTB->setEnabled(changesPresent);
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;
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);
73 #if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
75 QLocale().toString(QDateTime::fromSecsSinceEpoch(c.changetime),
79 QLocale().toString(QDateTime::fromTime_t(c.changetime),
82 if (!date.isEmpty()) {
83 if (!author.isEmpty())
84 text += qt_(" on[[date]] %1").arg(date);
86 text += inserted ? qt_("Inserted on %1").arg(date)
87 : qt_("Deleted on %1").arg(date);
89 QString changedcontent = toqstr(bufferview()->cursor().selectionAsString(false));
90 if (!changedcontent.isEmpty()) {
91 text += ":<br><br><b>";
93 text += "<u><span style=\"color:blue\">";
95 text += "<s><span style=\"color:red\">";
96 text += changedcontent;
98 text += "</u></span></b>";
100 text += "</s></span></b>";
103 changeTB->setHtml(text);
107 void GuiChanges::nextChange()
109 dispatch(FuncRequest(LFUN_CHANGE_NEXT));
113 void GuiChanges::previousChange()
115 dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
119 void GuiChanges::acceptChange()
121 dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
126 void GuiChanges::rejectChange()
128 dispatch(FuncRequest(LFUN_CHANGE_REJECT));
133 } // namespace frontend
136 #include "moc_GuiChanges.cpp"