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));
49 bc().addReadOnly(acceptPB);
50 bc().addReadOnly(rejectPB);
54 void GuiChanges::updateContents()
56 bool const changesPresent = buffer().areChangesPresent();
57 nextPB->setEnabled(changesPresent);
58 previousPB->setEnabled(changesPresent);
59 changeTB->setEnabled(changesPresent);
61 Change const & c = bufferview()->getCurrentChange();
62 bool const changePresent = c.type != Change::UNCHANGED;
63 rejectPB->setEnabled(changePresent);
64 acceptPB->setEnabled(changePresent);
65 bool const inserted = c.type == Change::INSERTED;
69 QString const author =
70 toqstr(buffer().params().authors().get(c.author).nameAndEmail());
71 if (!author.isEmpty())
72 text += inserted ? qt_("Inserted by %1").arg(author)
73 : qt_("Deleted by %1").arg(author);
75 QString const date = QDateTime::fromTime_t(c.changetime)
76 .toString(Qt::DefaultLocaleLongDate);
77 if (!date.isEmpty()) {
78 if (!author.isEmpty())
79 text += qt_(" on[[date]] %1").arg(date);
81 text += inserted ? qt_("Inserted on %1").arg(date)
82 : qt_("Deleted on %1").arg(date);
84 QString changedcontent = toqstr(bufferview()->cursor().selectionAsString(false));
85 if (!changedcontent.isEmpty()) {
86 text += ":<br><br><b>";
88 text += "<u><span style=\"color:blue\">";
90 text += "<s><span style=\"color:red\">";
91 text += changedcontent;
93 text += "</u></span></b>";
95 text += "</s></span></b>";
98 changeTB->setHtml(text);
102 void GuiChanges::nextChange()
104 dispatch(FuncRequest(LFUN_CHANGE_NEXT));
108 void GuiChanges::previousChange()
110 dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS));
114 void GuiChanges::acceptChange()
116 dispatch(FuncRequest(LFUN_CHANGE_ACCEPT));
121 void GuiChanges::rejectChange()
123 dispatch(FuncRequest(LFUN_CHANGE_REJECT));
128 Dialog * createGuiChanges(GuiView & lv) { return new GuiChanges(lv); }
131 } // namespace frontend
134 #include "moc_GuiChanges.cpp"