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 QString const date = QDateTime::fromTime_t(c.changetime)
74 .toString(Qt::DefaultLocaleLongDate);
75 if (!date.isEmpty()) {
76 if (!author.isEmpty())
77 text += qt_(" on[[date]] %1").arg(date);
79 text += inserted ? qt_("Inserted on %1").arg(date)
80 : qt_("Deleted on %1").arg(date);
82 QString changedcontent = toqstr(bufferview()->cursor().selectionAsString(false));
83 if (!changedcontent.isEmpty()) {
84 text += ":<br><br><b>";
86 text += "<u><span style=\"color:blue\">";
88 text += "<s><span style=\"color:red\">";
89 text += changedcontent;
91 text += "</u></span></b>";
93 text += "</s></span></b>";
96 changeTB->setHtml(text);
100 void GuiChanges::nextChange()
102 dispatch(FuncRequest(LFUN_CHANGE_NEXT));
106 void GuiChanges::previousChange()
108 dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
112 void GuiChanges::acceptChange()
114 dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
119 void GuiChanges::rejectChange()
121 dispatch(FuncRequest(LFUN_CHANGE_REJECT));
126 } // namespace frontend
129 #include "moc_GuiChanges.cpp"