2006-04-15 14:13:41 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiViewSource.cpp
|
2006-04-15 14:13:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Bo Peng
|
2007-03-25 01:25:29 +00:00
|
|
|
* \author Abdelrazak Younes
|
2006-04-15 14:13:41 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-18 20:36:52 +00:00
|
|
|
#include "GuiApplication.h"
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiViewSource.h"
|
2007-10-06 19:03:41 +00:00
|
|
|
#include "LaTeXHighlighter.h"
|
2006-04-15 14:13:41 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-10-03 14:21:15 +00:00
|
|
|
|
2011-05-13 19:39:56 +00:00
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
2007-10-06 15:03:58 +00:00
|
|
|
#include "Cursor.h"
|
2010-12-10 10:34:24 +00:00
|
|
|
#include "Format.h"
|
2016-09-07 00:36:55 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "LyX.h"
|
2007-10-06 15:03:58 +00:00
|
|
|
#include "Paragraph.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "TexRow.h"
|
2007-08-13 15:22:13 +00:00
|
|
|
|
2008-10-18 13:51:48 +00:00
|
|
|
#include "support/debug.h"
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2015-10-11 13:50:32 +00:00
|
|
|
#include "support/docstring_list.h"
|
2007-11-29 22:38:53 +00:00
|
|
|
#include "support/gettext.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
|
2008-10-18 14:14:58 +00:00
|
|
|
#include <boost/crc.hpp>
|
|
|
|
|
2013-05-05 06:05:51 +00:00
|
|
|
#include <QBoxLayout>
|
2015-07-31 00:05:54 +00:00
|
|
|
#include <QComboBox>
|
2015-08-04 22:16:40 +00:00
|
|
|
#include <QScrollBar>
|
2008-05-14 14:24:55 +00:00
|
|
|
#include <QSettings>
|
2007-08-13 15:22:13 +00:00
|
|
|
#include <QTextCursor>
|
2007-04-24 14:08:53 +00:00
|
|
|
#include <QTextDocument>
|
2008-05-14 14:24:55 +00:00
|
|
|
#include <QVariant>
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-10-06 15:03:58 +00:00
|
|
|
|
2006-04-15 14:13:41 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2016-10-09 22:36:26 +00:00
|
|
|
ViewSourceWidget::ViewSourceWidget(QWidget * parent)
|
|
|
|
: QWidget(parent),
|
|
|
|
document_(new QTextDocument(this)),
|
|
|
|
highlighter_(new LaTeXHighlighter(document_))
|
2007-04-24 14:08:53 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2011-10-29 21:00:23 +00:00
|
|
|
connect(contentsCO, SIGNAL(activated(int)),
|
|
|
|
this, SLOT(contentsChanged()));
|
2007-04-24 14:08:53 +00:00
|
|
|
connect(autoUpdateCB, SIGNAL(toggled(bool)),
|
|
|
|
updatePB, SLOT(setDisabled(bool)));
|
2009-04-01 20:32:26 +00:00
|
|
|
connect(autoUpdateCB, SIGNAL(toggled(bool)),
|
2015-07-31 00:05:54 +00:00
|
|
|
this, SLOT(contentsChanged()));
|
2012-10-05 12:30:20 +00:00
|
|
|
connect(masterPerspectiveCB, SIGNAL(toggled(bool)),
|
2015-07-31 00:05:54 +00:00
|
|
|
this, SLOT(contentsChanged()));
|
2007-04-24 14:08:53 +00:00
|
|
|
connect(updatePB, SIGNAL(clicked()),
|
2016-10-09 22:36:26 +00:00
|
|
|
this, SIGNAL(needUpdate()));
|
2010-12-10 10:34:24 +00:00
|
|
|
connect(outputFormatCO, SIGNAL(activated(int)),
|
2015-07-31 00:05:54 +00:00
|
|
|
this, SLOT(setViewFormat(int)));
|
2015-07-31 00:05:54 +00:00
|
|
|
|
2007-04-24 14:08:53 +00:00
|
|
|
// setting a document at this point trigger an assertion in Qt
|
|
|
|
// so we disable the signals here:
|
2007-10-09 09:43:56 +00:00
|
|
|
document_->blockSignals(true);
|
|
|
|
viewSourceTV->setDocument(document_);
|
2015-08-04 22:16:40 +00:00
|
|
|
// reset selections
|
|
|
|
setText();
|
2007-10-09 09:43:56 +00:00
|
|
|
document_->blockSignals(false);
|
2007-04-24 14:08:53 +00:00
|
|
|
viewSourceTV->setReadOnly(true);
|
|
|
|
///dialog_->viewSourceTV->setAcceptRichText(false);
|
|
|
|
// this is personal. I think source code should be in fixed-size font
|
2016-04-15 09:49:04 +00:00
|
|
|
viewSourceTV->setFont(guiApp->typewriterSystemFont());
|
2007-04-24 14:08:53 +00:00
|
|
|
// again, personal taste
|
|
|
|
viewSourceTV->setWordWrapMode(QTextOption::NoWrap);
|
2016-09-07 00:36:55 +00:00
|
|
|
|
|
|
|
// catch double click events
|
|
|
|
viewSourceTV->viewport()->installEventFilter(this);
|
2007-04-24 14:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-09 22:36:26 +00:00
|
|
|
void ViewSourceWidget::getContent(BufferView const & view,
|
2015-08-04 22:16:40 +00:00
|
|
|
Buffer::OutputWhat output, docstring & str, string const & format,
|
|
|
|
bool master)
|
2008-10-18 13:20:17 +00:00
|
|
|
{
|
|
|
|
// get the *top* level paragraphs that contain the cursor,
|
|
|
|
// or the selected text
|
|
|
|
pit_type par_begin;
|
|
|
|
pit_type par_end;
|
|
|
|
|
2016-10-09 22:36:26 +00:00
|
|
|
if (!view.cursor().selection()) {
|
|
|
|
par_begin = view.cursor().bottom().pit();
|
2008-10-18 13:20:17 +00:00
|
|
|
par_end = par_begin;
|
|
|
|
} else {
|
2016-10-09 22:36:26 +00:00
|
|
|
par_begin = view.cursor().selectionBegin().bottom().pit();
|
|
|
|
par_end = view.cursor().selectionEnd().bottom().pit();
|
2008-10-18 13:20:17 +00:00
|
|
|
}
|
|
|
|
if (par_begin > par_end)
|
|
|
|
swap(par_begin, par_end);
|
|
|
|
odocstringstream ostr;
|
2016-10-09 22:36:26 +00:00
|
|
|
texrow_ = view.buffer()
|
2016-06-02 20:58:52 +00:00
|
|
|
.getSourceCode(ostr, format, par_begin, par_end + 1, output, master);
|
2015-09-15 04:56:01 +00:00
|
|
|
//ensure that the last line can always be selected in its full width
|
|
|
|
str = ostr.str() + "\n";
|
2008-10-18 13:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-04 22:16:40 +00:00
|
|
|
bool ViewSourceWidget::setText(QString const & qstr)
|
|
|
|
{
|
|
|
|
bool const changed = document_->toPlainText() != qstr;
|
|
|
|
viewSourceTV->setExtraSelections(QList<QTextEdit::ExtraSelection>());
|
|
|
|
if (changed)
|
|
|
|
document_->setPlainText(qstr);
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 21:00:23 +00:00
|
|
|
void ViewSourceWidget::contentsChanged()
|
2011-01-04 00:00:20 +00:00
|
|
|
{
|
|
|
|
if (autoUpdateCB->isChecked())
|
2016-10-09 22:36:26 +00:00
|
|
|
Q_EMIT needUpdate();
|
2011-01-04 00:00:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-31 00:05:54 +00:00
|
|
|
void ViewSourceWidget::setViewFormat(int const index)
|
2011-12-09 19:48:50 +00:00
|
|
|
{
|
2015-07-31 00:05:54 +00:00
|
|
|
outputFormatCO->setCurrentIndex(index);
|
2016-08-28 20:57:17 +00:00
|
|
|
string format = fromqstr(outputFormatCO->itemData(index).toString());
|
|
|
|
if (view_format_ != format) {
|
|
|
|
view_format_ = format;
|
2016-10-09 22:36:26 +00:00
|
|
|
Q_EMIT needUpdate();
|
2016-08-28 20:57:17 +00:00
|
|
|
}
|
2011-12-09 19:48:50 +00:00
|
|
|
}
|
|
|
|
|
2012-03-10 16:49:20 +00:00
|
|
|
|
2016-10-09 22:36:26 +00:00
|
|
|
int ViewSourceWidget::updateDelay() const
|
2015-07-31 00:05:54 +00:00
|
|
|
{
|
|
|
|
const int long_delay = 400;
|
|
|
|
const int short_delay = 60;
|
|
|
|
// a shorter delay if just the current paragraph is shown
|
2016-10-09 22:36:26 +00:00
|
|
|
return (contentsCO->currentIndex() == 0) ? short_delay : long_delay;
|
2015-07-31 00:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 12:15:02 +00:00
|
|
|
|
2016-10-09 22:36:26 +00:00
|
|
|
void GuiViewSource::scheduleUpdate()
|
|
|
|
{
|
|
|
|
update_timer_->start(widget_->updateDelay());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiViewSource::scheduleUpdateNow()
|
2015-07-31 00:05:54 +00:00
|
|
|
{
|
|
|
|
update_timer_->start(0);
|
|
|
|
}
|
|
|
|
|
2015-10-11 13:50:32 +00:00
|
|
|
|
2016-10-09 22:36:26 +00:00
|
|
|
void GuiViewSource::realUpdateView()
|
2007-04-24 14:08:53 +00:00
|
|
|
{
|
2016-10-09 22:36:26 +00:00
|
|
|
widget_->updateView(bufferview());
|
|
|
|
updateTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ViewSourceWidget::updateView(BufferView const * bv)
|
|
|
|
{
|
|
|
|
if (!bv) {
|
2015-08-04 22:16:40 +00:00
|
|
|
setText();
|
2008-05-13 21:28:04 +00:00
|
|
|
setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-10 10:34:24 +00:00
|
|
|
|
2009-01-24 12:38:05 +00:00
|
|
|
setEnabled(true);
|
2007-04-24 14:08:53 +00:00
|
|
|
|
2015-08-04 22:16:40 +00:00
|
|
|
// we will try to get that much space around the cursor
|
|
|
|
int const v_margin = 3;
|
|
|
|
int const h_margin = 10;
|
|
|
|
// we will try to preserve this
|
|
|
|
int const h_scroll = viewSourceTV->horizontalScrollBar()->value();
|
|
|
|
|
2011-10-29 21:00:23 +00:00
|
|
|
Buffer::OutputWhat output = Buffer::CurrentParagraph;
|
|
|
|
if (contentsCO->currentIndex() == 1)
|
|
|
|
output = Buffer::FullSource;
|
|
|
|
else if (contentsCO->currentIndex() == 2)
|
|
|
|
output = Buffer::OnlyPreamble;
|
|
|
|
else if (contentsCO->currentIndex() == 3)
|
|
|
|
output = Buffer::OnlyBody;
|
|
|
|
|
2015-08-04 22:16:40 +00:00
|
|
|
docstring content;
|
2016-10-09 22:36:26 +00:00
|
|
|
getContent(*bv, output, content, view_format_,
|
2016-08-28 20:57:17 +00:00
|
|
|
masterPerspectiveCB->isChecked());
|
2015-08-04 22:16:40 +00:00
|
|
|
QString old = document_->toPlainText();
|
|
|
|
QString qcontent = toqstr(content);
|
2015-10-11 13:50:32 +00:00
|
|
|
#ifdef DEVEL_VERSION
|
2015-11-15 12:15:02 +00:00
|
|
|
// output tex<->row correspondences in the source panel if the "-dbg latex"
|
|
|
|
// option is given.
|
2016-06-02 20:58:52 +00:00
|
|
|
if (texrow_ && lyx::lyxerr.debugging(Debug::LATEX)) {
|
2015-11-15 12:15:02 +00:00
|
|
|
QStringList list = qcontent.split(QChar('\n'));
|
|
|
|
docstring_list dlist;
|
|
|
|
for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
|
|
|
|
dlist.push_back(from_utf8(fromqstr(*it)));
|
|
|
|
texrow_->prepend(dlist);
|
|
|
|
qcontent.clear();
|
|
|
|
for (docstring_list::iterator it = dlist.begin(); it != dlist.end(); ++it)
|
|
|
|
qcontent += toqstr(*it) + '\n';
|
|
|
|
}
|
2015-10-11 13:50:32 +00:00
|
|
|
#endif
|
|
|
|
// prevent gotoCursor()
|
2016-10-09 22:36:26 +00:00
|
|
|
QSignalBlocker blocker(viewSourceTV);
|
2015-08-04 22:16:40 +00:00
|
|
|
bool const changed = setText(qcontent);
|
|
|
|
|
2016-06-02 20:58:52 +00:00
|
|
|
if (changed && !texrow_) {
|
2015-08-04 22:16:40 +00:00
|
|
|
// position-to-row is unavailable
|
|
|
|
// we jump to the first modification
|
2016-12-19 23:15:58 +00:00
|
|
|
int length = min(old.length(), qcontent.length());
|
2015-08-04 22:16:40 +00:00
|
|
|
int pos = 0;
|
2016-12-19 23:15:58 +00:00
|
|
|
for (; pos < length && old.at(pos) == qcontent.at(pos); ++pos) {}
|
2015-08-04 22:16:40 +00:00
|
|
|
QTextCursor c = QTextCursor(viewSourceTV->document());
|
|
|
|
//get some space below the cursor
|
|
|
|
c.setPosition(pos);
|
|
|
|
c.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor,v_margin);
|
|
|
|
viewSourceTV->setTextCursor(c);
|
|
|
|
//get some space on the right of the cursor
|
|
|
|
viewSourceTV->horizontalScrollBar()->setValue(h_scroll);
|
|
|
|
c.setPosition(pos);
|
|
|
|
const int block = c.blockNumber();
|
|
|
|
for (int i = h_margin; i && block == c.blockNumber(); --i) {
|
|
|
|
c.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor);
|
|
|
|
}
|
|
|
|
c.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
|
|
|
|
viewSourceTV->setTextCursor(c);
|
|
|
|
//back to the position
|
|
|
|
c.setPosition(pos);
|
|
|
|
//c.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,1);
|
|
|
|
viewSourceTV->setTextCursor(c);
|
|
|
|
|
2016-06-02 20:58:52 +00:00
|
|
|
} else if (texrow_) {
|
2015-08-04 22:16:40 +00:00
|
|
|
// Use the available position-to-row conversion to highlight
|
|
|
|
// the current selection in the source
|
2016-10-09 22:36:26 +00:00
|
|
|
std::pair<int,int> rows = texrow_->rowFromCursor(bv->cursor());
|
2015-10-13 19:26:21 +00:00
|
|
|
int const beg_row = rows.first;
|
|
|
|
int const end_row = rows.second;
|
2015-08-04 22:16:40 +00:00
|
|
|
|
|
|
|
QTextCursor c = QTextCursor(viewSourceTV->document());
|
|
|
|
|
|
|
|
c.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor,
|
|
|
|
beg_row - 1);
|
|
|
|
const int beg_sel = c.position();
|
|
|
|
//get some space above the cursor
|
|
|
|
c.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor,
|
|
|
|
v_margin);
|
|
|
|
viewSourceTV->setTextCursor(c);
|
|
|
|
c.setPosition(beg_sel, QTextCursor::MoveAnchor);
|
|
|
|
|
|
|
|
c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
|
|
|
|
end_row - beg_row +1);
|
|
|
|
const int end_sel = c.position();
|
|
|
|
//get some space below the cursor
|
|
|
|
c.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor,
|
|
|
|
v_margin - 1);
|
|
|
|
viewSourceTV->setTextCursor(c);
|
|
|
|
c.setPosition(end_sel, QTextCursor::KeepAnchor);
|
|
|
|
|
|
|
|
viewSourceTV->setTextCursor(c);
|
|
|
|
|
|
|
|
//the real highlighting is done with an ExtraSelection
|
|
|
|
QTextCharFormat format;
|
2016-04-14 15:24:18 +00:00
|
|
|
{
|
|
|
|
// We create a new color with the lightness of AlternateBase and
|
|
|
|
// the hue and saturation of Highlight
|
2015-08-04 22:16:40 +00:00
|
|
|
QPalette palette = viewSourceTV->palette();
|
2016-04-14 15:24:18 +00:00
|
|
|
QBrush alt = palette.alternateBase();
|
|
|
|
QColor high = palette.highlight().color().toHsl();
|
|
|
|
QColor col = QColor::fromHsl(high.hue(),
|
|
|
|
high.hslSaturation(),
|
|
|
|
alt.color().lightness());
|
|
|
|
alt.setColor(col);
|
|
|
|
format.setBackground(alt);
|
|
|
|
}
|
2015-08-04 22:16:40 +00:00
|
|
|
format.setProperty(QTextFormat::FullWidthSelection, true);
|
|
|
|
QTextEdit::ExtraSelection sel;
|
|
|
|
sel.format = format;
|
|
|
|
sel.cursor = c;
|
|
|
|
viewSourceTV->setExtraSelections(
|
|
|
|
QList<QTextEdit::ExtraSelection>() << sel);
|
|
|
|
|
|
|
|
//clean up
|
|
|
|
c.clearSelection();
|
|
|
|
viewSourceTV->setTextCursor(c);
|
|
|
|
viewSourceTV->horizontalScrollBar()->setValue(h_scroll);
|
2015-09-15 04:56:01 +00:00
|
|
|
} // else if (texrow)
|
2007-04-24 14:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-28 19:57:54 +00:00
|
|
|
docstring ViewSourceWidget::currentFormatName(BufferView const * bv) const
|
2016-08-28 20:57:17 +00:00
|
|
|
{
|
|
|
|
// Compute the actual format used
|
2016-09-28 19:57:54 +00:00
|
|
|
string const format = !bv ? ""
|
|
|
|
: flavor2format(bv->buffer().params().getOutputFlavor(view_format_));
|
2017-03-14 03:33:40 +00:00
|
|
|
Format const * f = theFormats().getFormat(format.empty() ? view_format_ : format);
|
2016-08-28 20:57:17 +00:00
|
|
|
return f ? f->prettyname() : from_utf8(view_format_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-07 00:36:55 +00:00
|
|
|
bool ViewSourceWidget::eventFilter(QObject * obj, QEvent * ev)
|
|
|
|
{
|
|
|
|
// this event filter is installed on the viewport of the QTextView
|
|
|
|
if (obj == viewSourceTV->viewport() &&
|
|
|
|
ev->type() == QEvent::MouseButtonDblClick) {
|
|
|
|
goToCursor();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ViewSourceWidget::goToCursor() const
|
2015-10-11 13:50:32 +00:00
|
|
|
{
|
2016-09-07 00:36:55 +00:00
|
|
|
if (!texrow_)
|
2015-10-11 13:50:32 +00:00
|
|
|
return;
|
|
|
|
int row = viewSourceTV->textCursor().blockNumber() + 1;
|
2016-10-11 09:22:20 +00:00
|
|
|
dispatch(texrow_->goToFuncFromRow(row));
|
2015-10-11 13:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-09 22:36:26 +00:00
|
|
|
void ViewSourceWidget::updateDefaultFormat(BufferView const & bv)
|
2010-12-10 10:34:24 +00:00
|
|
|
{
|
2016-10-09 22:36:26 +00:00
|
|
|
QSignalBlocker blocker(outputFormatCO);
|
2010-12-10 10:34:24 +00:00
|
|
|
outputFormatCO->clear();
|
|
|
|
outputFormatCO->addItem(qt_("Default"),
|
2017-05-01 22:28:22 +00:00
|
|
|
QVariant(QString("default")));
|
2011-12-09 19:48:50 +00:00
|
|
|
|
2012-03-10 16:49:20 +00:00
|
|
|
int index = 0;
|
2017-05-01 22:28:22 +00:00
|
|
|
for (string const & fmt_name : bv.buffer().params().backends()) {
|
|
|
|
Format const * fmt = theFormats().getFormat(fmt_name);
|
2012-05-09 07:14:11 +00:00
|
|
|
if (!fmt) {
|
2017-05-01 22:28:22 +00:00
|
|
|
LYXERR0("Can't find format for backend " << fmt_name << "!");
|
2012-05-10 19:44:25 +00:00
|
|
|
continue;
|
2017-05-01 22:28:22 +00:00
|
|
|
}
|
2016-08-28 00:27:37 +00:00
|
|
|
QString const pretty = toqstr(translateIfPossible(fmt->prettyname()));
|
2017-05-01 22:28:22 +00:00
|
|
|
outputFormatCO->addItem(pretty, QVariant(toqstr(fmt_name)));
|
|
|
|
if (fmt_name == view_format_)
|
|
|
|
index = outputFormatCO->count() - 1;
|
2011-12-09 19:48:50 +00:00
|
|
|
}
|
2015-07-31 00:05:54 +00:00
|
|
|
setViewFormat(index);
|
2010-12-10 10:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-06 21:50:23 +00:00
|
|
|
void ViewSourceWidget::resizeEvent (QResizeEvent * event)
|
2013-05-05 06:05:51 +00:00
|
|
|
{
|
2013-05-06 21:50:23 +00:00
|
|
|
QSize const & formSize = formLayout->sizeHint();
|
|
|
|
// minimize the size of the part that contains the buttons
|
|
|
|
if (width() * formSize.height() < height() * formSize.width()) {
|
2013-05-05 06:05:51 +00:00
|
|
|
layout_->setDirection(QBoxLayout::TopToBottom);
|
|
|
|
} else {
|
|
|
|
layout_->setDirection(QBoxLayout::LeftToRight);
|
|
|
|
}
|
2013-05-06 21:50:23 +00:00
|
|
|
QWidget::resizeEvent(event);
|
2013-05-05 06:05:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 22:28:22 +00:00
|
|
|
|
2015-07-31 00:05:54 +00:00
|
|
|
void ViewSourceWidget::saveSession(QString const & session_key) const
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2016-08-28 20:57:17 +00:00
|
|
|
settings.setValue(session_key + "/output", toqstr(view_format_));
|
2015-07-31 00:05:54 +00:00
|
|
|
settings.setValue(session_key + "/contents", contentsCO->currentIndex());
|
|
|
|
settings.setValue(session_key + "/autoupdate", autoUpdateCB->isChecked());
|
|
|
|
settings.setValue(session_key + "/masterview",
|
|
|
|
masterPerspectiveCB->isChecked());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ViewSourceWidget::restoreSession(QString const & session_key)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
2016-08-28 20:57:17 +00:00
|
|
|
view_format_ = fromqstr(settings.value(session_key + "/output", 0)
|
|
|
|
.toString());
|
2015-07-31 00:05:54 +00:00
|
|
|
contentsCO->setCurrentIndex(settings
|
|
|
|
.value(session_key + "/contents", 0)
|
|
|
|
.toInt());
|
|
|
|
masterPerspectiveCB->setChecked(settings
|
|
|
|
.value(session_key + "/masterview", false)
|
|
|
|
.toBool());
|
|
|
|
bool const checked = settings
|
|
|
|
.value(session_key + "/autoupdate", true)
|
|
|
|
.toBool();
|
|
|
|
autoUpdateCB->setChecked(checked);
|
|
|
|
if (checked)
|
2016-10-09 22:36:26 +00:00
|
|
|
Q_EMIT needUpdate();
|
2015-07-31 00:05:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-05 06:05:51 +00:00
|
|
|
|
2007-11-29 22:12:19 +00:00
|
|
|
GuiViewSource::GuiViewSource(GuiView & parent,
|
|
|
|
Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
2016-10-09 22:36:26 +00:00
|
|
|
: DockView(parent, "view-source", qt_("Code Preview"), area, flags),
|
|
|
|
widget_(new ViewSourceWidget(this)),
|
|
|
|
update_timer_(new QTimer(this))
|
2007-10-09 09:43:56 +00:00
|
|
|
{
|
|
|
|
setWidget(widget_);
|
2016-10-09 22:36:26 +00:00
|
|
|
|
|
|
|
// setting the update timer
|
|
|
|
update_timer_->setSingleShot(true);
|
|
|
|
connect(update_timer_, SIGNAL(timeout()),
|
|
|
|
this, SLOT(realUpdateView()));
|
|
|
|
|
|
|
|
connect(widget_, SIGNAL(needUpdate()), this, SLOT(scheduleUpdateNow()));
|
2007-10-09 09:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-09 22:37:35 +00:00
|
|
|
void GuiViewSource::onBufferViewChanged()
|
2007-10-09 09:43:56 +00:00
|
|
|
{
|
2016-10-09 22:36:26 +00:00
|
|
|
widget_->setText();
|
|
|
|
widget_->setEnabled((bool)bufferview());
|
2007-10-09 09:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiViewSource::updateView()
|
|
|
|
{
|
2009-04-01 20:32:26 +00:00
|
|
|
if (widget_->autoUpdateCB->isChecked()) {
|
2016-10-09 22:36:26 +00:00
|
|
|
widget_->setEnabled((bool)bufferview());
|
|
|
|
scheduleUpdate();
|
2008-10-18 13:20:17 +00:00
|
|
|
}
|
2012-10-05 12:30:20 +00:00
|
|
|
widget_->masterPerspectiveCB->setEnabled(buffer().parent());
|
2016-08-28 20:57:17 +00:00
|
|
|
updateTitle();
|
2007-10-09 09:43:56 +00:00
|
|
|
}
|
2007-10-06 15:03:58 +00:00
|
|
|
|
|
|
|
|
2008-05-13 21:28:04 +00:00
|
|
|
void GuiViewSource::enableView(bool enable)
|
|
|
|
{
|
2016-10-09 22:36:26 +00:00
|
|
|
widget_->setEnabled((bool)bufferview());
|
|
|
|
if (bufferview())
|
|
|
|
widget_->updateDefaultFormat(*bufferview());
|
2009-01-24 12:38:05 +00:00
|
|
|
if (!enable)
|
2008-05-13 21:28:04 +00:00
|
|
|
// In the opposite case, updateView() will be called anyway.
|
2015-07-31 00:05:54 +00:00
|
|
|
widget_->contentsChanged();
|
2008-05-13 21:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-09 09:43:56 +00:00
|
|
|
bool GuiViewSource::initialiseParams(string const & /*source*/)
|
2007-10-06 15:03:58 +00:00
|
|
|
{
|
2016-08-28 20:57:17 +00:00
|
|
|
updateTitle();
|
2007-10-06 15:03:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-28 20:57:17 +00:00
|
|
|
void GuiViewSource::updateTitle()
|
2007-10-06 15:03:58 +00:00
|
|
|
{
|
2016-09-28 19:57:54 +00:00
|
|
|
docstring const format = widget_->currentFormatName(bufferview());
|
2016-08-28 20:57:17 +00:00
|
|
|
QString const title = format.empty() ? qt_("Code Preview")
|
|
|
|
: qt_("%1[[preview format name]] Preview")
|
|
|
|
.arg(toqstr(translateIfPossible(format)));
|
|
|
|
setTitle(title);
|
|
|
|
setWindowTitle(title);
|
2007-10-06 15:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-14 14:24:55 +00:00
|
|
|
void GuiViewSource::saveSession() const
|
|
|
|
{
|
|
|
|
Dialog::saveSession();
|
2015-07-31 00:05:54 +00:00
|
|
|
widget_->saveSession(sessionKey());
|
2008-05-14 14:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiViewSource::restoreSession()
|
|
|
|
{
|
2008-10-03 13:34:10 +00:00
|
|
|
DockView::restoreSession();
|
2015-07-31 00:05:54 +00:00
|
|
|
widget_->restoreSession(sessionKey());
|
2008-05-14 14:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiViewSource(GuiView & lv)
|
2007-10-06 15:03:58 +00:00
|
|
|
{
|
2007-11-29 22:12:19 +00:00
|
|
|
return new GuiViewSource(lv);
|
2007-10-06 15:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-15 14:13:41 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2006-05-18 08:51:12 +00:00
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiViewSource.cpp"
|