#include "GuiApplication.h"
+#include "ToolTipFormatter.h"
#include "ColorCache.h"
#include "ColorSet.h"
#include "GuiClipboard.h"
#include "BufferView.h"
#include "CmdDef.h"
#include "Color.h"
+#include "Converter.h"
#include "CutAndPaste.h"
#include "ErrorList.h"
#include "Font.h"
#include "support/ExceptionMessage.h"
#include "support/FileName.h"
#include "support/filetools.h"
-#include "support/foreach.h"
#include "support/ForkedCalls.h"
#include "support/gettext.h"
#include "support/lassert.h"
#include <queue>
+#include <QFontDatabase>
#include <QByteArray>
#include <QClipboard>
#include <QDateTime>
#ifdef Q_WS_X11
#include <X11/Xatom.h>
#include <X11/Xlib.h>
+#include <QX11Info>
#undef CursorShape
#undef None
#elif defined(QPA_XCB)
#include <xcb/xcb.h>
+#ifdef HAVE_QT5_X11_EXTRAS
+#include <QtX11Extras/QX11Info>
+#endif
#endif
#if (QT_VERSION < 0x050000) || (QT_VERSION >= 0x050400)
#include <QMacPasteboardMime>
#endif // Q_OS_MAC
-#include "support/bind.h"
#include <boost/crc.hpp>
#include <exception>
if (qt_formats.empty())
LYXERR(Debug::GRAPHICS, "\nQt4 Problem: No Format available!");
+ bool jpeg_found = false;
+ bool jpg_found = false;
for (QList<QByteArray>::const_iterator it = qt_formats.begin(); it != qt_formats.end(); ++it) {
LYXERR(Debug::GRAPHICS, (const char *) *it << ", ");
string ext = ascii_lowercase((const char *) *it);
// special case
- if (ext == "jpeg")
+ if (ext == "jpeg") {
+ jpeg_found = true;
+ if (jpg_found)
+ continue;
ext = "jpg";
+ }
+ else if (ext == "jpg") {
+ jpg_found = true;
+ if (jpeg_found)
+ continue;
+ }
+ else if (lyxrc.use_converter_cache &&
+ (ext == "svg" || ext == "svgz") &&
+ theConverters().isReachable("svg", "png"))
+ // Qt only supports SVG 1.2 tiny. See #9778. We prefer displaying
+ // the SVG as in the output. However we require that the converter
+ // cache is enabled since this is expensive. We also require that
+ // an explicit svg->png converter is defined, since the default
+ // converter could produce bad quality as well. This assumes that
+ // png can always be loaded.
+ continue;
fmts.push_back(ext);
}
namespace {
-struct PngMap {
+struct ImgMap {
QString key;
QString value;
};
-bool operator<(PngMap const & lhs, PngMap const & rhs)
+bool operator<(ImgMap const & lhs, ImgMap const & rhs)
{
return lhs.key < rhs.key;
}
class CompareKey {
public:
CompareKey(QString const & name) : name_(name) {}
- bool operator()(PngMap const & other) const { return other.key == name_; }
+ bool operator()(ImgMap const & other) const { return other.key == name_; }
private:
QString const name_;
};
// Upper case comes before lower case
// Please don't change the formatting, this list is parsed by
// development/tools/generate_symbols_images.py.
-PngMap sorted_png_map[] = {
+ImgMap sorted_img_map[] = {
{ "Arrownot", "arrownot2"},
{ "Arrowvert", "arrowvert2"},
{ "Bowtie", "bowtie2" },
};
-size_t const nr_sorted_png_map = sizeof(sorted_png_map) / sizeof(PngMap);
+size_t const nr_sorted_img_map = sizeof(sorted_img_map) / sizeof(ImgMap);
// This list specifies which system's theme icon is related to which lyx
// command. It was based on:
// http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
// this must be sorted alphabetically
// Upper case comes before lower case
-PngMap sorted_theme_icon_map[] = {
+ImgMap sorted_theme_icon_map[] = {
{ "bookmark-goto 0", "go-jump" },
{ "buffer-new", "document-new" },
{ "buffer-write", "document-save" },
{ "window-new", "window-new" }
};
-size_t const nr_sorted_theme_icon_map = sizeof(sorted_theme_icon_map) / sizeof(PngMap);
+size_t const nr_sorted_theme_icon_map = sizeof(sorted_theme_icon_map) / sizeof(ImgMap);
-QString findPng(QString const & name)
+QString findImg(QString const & name)
{
- PngMap const * const begin = sorted_png_map;
- PngMap const * const end = begin + nr_sorted_png_map;
+ ImgMap const * const begin = sorted_img_map;
+ ImgMap const * const end = begin + nr_sorted_img_map;
LATTEST(sorted(begin, end));
- PngMap const * const it = find_if(begin, end, CompareKey(name));
+ ImgMap const * const it = find_if(begin, end, CompareKey(name));
- QString png_name;
+ QString img_name;
if (it != end) {
- png_name = it->value;
+ img_name = it->value;
} else {
- png_name = name;
- png_name.replace('_', "underscore");
- png_name.replace(' ', '_');
+ img_name = name;
+ img_name.replace('_', "underscore");
+ img_name.replace(' ', '_');
// This way we can have "math-delim { }" on the toolbar.
- png_name.replace('(', "lparen");
- png_name.replace(')', "rparen");
- png_name.replace('[', "lbracket");
- png_name.replace(']', "rbracket");
- png_name.replace('{', "lbrace");
- png_name.replace('}', "rbrace");
- png_name.replace('|', "bars");
- png_name.replace(',', "thinspace");
- png_name.replace(':', "mediumspace");
- png_name.replace(';', "thickspace");
- png_name.replace('!', "negthinspace");
+ img_name.replace('(', "lparen");
+ img_name.replace(')', "rparen");
+ img_name.replace('[', "lbracket");
+ img_name.replace(']', "rbracket");
+ img_name.replace('{', "lbrace");
+ img_name.replace('}', "rbrace");
+ img_name.replace('|', "bars");
+ img_name.replace(',', "thinspace");
+ img_name.replace(':', "mediumspace");
+ img_name.replace(';', "thickspace");
+ img_name.replace('!', "negthinspace");
}
- LYXERR(Debug::GUI, "findPng(" << name << ")\n"
- << "Looking for math PNG called \"" << png_name << '"');
- return png_name;
+ LYXERR(Debug::GUI, "findImg(" << name << ")\n"
+ << "Looking for math icon called \"" << img_name << '"');
+ return img_name;
}
} // namespace anon
QString themeIconName(QString const & action)
{
- PngMap const * const begin = sorted_theme_icon_map;
- PngMap const * const end = begin + nr_sorted_theme_icon_map;
+ ImgMap const * const begin = sorted_theme_icon_map;
+ ImgMap const * const end = begin + nr_sorted_theme_icon_map;
LASSERT(sorted(begin, end), /**/);
- PngMap const * const it = find_if(begin, end, CompareKey(action));
+ ImgMap const * const it = find_if(begin, end, CompareKey(action));
if (it != end)
return it->value;
case LFUN_MATH_INSERT:
if (!f.argument().empty()) {
path = "math/";
- name1 = findPng(toqstr(f.argument()).mid(1));
+ name1 = findImg(toqstr(f.argument()).mid(1));
}
break;
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM:
path = "math/";
- name1 = findPng(toqstr(f.argument()));
+ name1 = findImg(toqstr(f.argument()));
break;
case LFUN_CALL:
path = "commands/";
docstring firstcom;
docstring dummy = split(f.argument(), firstcom, ';');
name1 = toqstr(firstcom);
- // FIXME: we should rename the icons to tabular-xxx instead of
- // "tabular-feature-xxx"
- name1.replace("inset-modify tabular", "tabular-feature");
name1.replace(' ', '_');
break;
}
- case LFUN_INSET_MODIFY: {
- // FIXME: we should rename the icons to tabular-xxx instead of
- // "tabular-feature-xxx" and generalize this naming to all
- // insets, not to tabular using ones.
- string inset_name;
- string const command = split(to_utf8(f.argument()), inset_name, ' ');
- if (insetCode(inset_name) == TABULAR_CODE) {
- name1 = "tabular-feature "+ toqstr(command);
- name1.replace(' ', '_');
- break;
- }
- }
default:
name2 = toqstr(lyxaction.getActionName(f.action()));
name1 = name2;
FileName fname = imageLibFileSearch(imagedir, "unknown", "svgz,png", mode);
if (fname.exists())
return toqstr(fname.absFileName());
- return QString(":/images/unknown.png");
+ return QString(":/images/unknown.svgz");
}
return QString();
bool getPixmap(QPixmap & pixmap, QString const & path)
{
- if (pixmap.load(path)) {
-#if QT_VERSION >= 0x050000
- if (path.endsWith(".svgz") || path.endsWith(".svg") ) {
- GuiApplication const * guiApp = theGuiApp();
- if (guiApp != 0) {
- pixmap.setDevicePixelRatio(guiApp->pixelRatio());
- }
- }
-#endif
- return true;
- }
- return false;
+ return pixmap.load(path);
}
{
#if (QT_VERSION >= 0x040600)
if (lyxrc.use_system_theme_icons) {
+ // use the icons from system theme that are available
QString action = toqstr(lyxaction.getActionName(f.action()));
if (!f.argument().empty())
action += " " + toqstr(f.argument());
QString const theme_icon = themeIconName(action);
- if (QIcon::hasThemeIcon(theme_icon))
- return QIcon::fromTheme(theme_icon);
+ if (QIcon::hasThemeIcon(theme_icon)) {
+ QIcon const thmicn = QIcon::fromTheme(theme_icon);
+ if (!thmicn.isNull())
+ return thmicn;
+ }
}
#endif
public:
QWindowsMimeMetafile() {}
- bool canConvertFromMime(FORMATETC const & formatetc,
- QMimeData const * mimedata) const
+ bool canConvertFromMime(FORMATETC const & /*formatetc*/,
+ QMimeData const * /*mimedata*/) const
{
return false;
}
return pDataObj->QueryGetData(&formatetc) == S_OK;
}
- bool convertFromMime(FORMATETC const & formatetc,
- const QMimeData * mimedata, STGMEDIUM * pmedium) const
+ bool convertFromMime(FORMATETC const & /*formatetc*/,
+ const QMimeData * /*mimedata*/, STGMEDIUM * /*pmedium*/) const
{
return false;
}
QVariant convertToMime(QString const & mimetype, IDataObject * pDataObj,
- QVariant::Type preferredType) const
+ QVariant::Type /*preferredType*/) const
{
QByteArray data;
if (!canConvertToMime(mimetype, pDataObj))
QVector<FORMATETC> formatsForMime(QString const & mimetype,
- QMimeData const * mimedata) const
+ QMimeData const * /*mimedata*/) const
{
QVector<FORMATETC> formats;
if (mimetype == emfMimeType() || mimetype == wmfMimeType())
QCoreApplication::setOrganizationName(app_name);
QCoreApplication::setOrganizationDomain("lyx.org");
QCoreApplication::setApplicationName(lyx_package);
+#if QT_VERSION >= 0x050000
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+#endif
qsrand(QDateTime::currentDateTime().toTime_t());
// This is clearly not enough in a time where we use threads for
// document preview and/or export. 20 should be OK.
QThreadPool::globalInstance()->setMaxThreadCount(20);
+
+ // make sure tooltips are formatted
+ installEventFilter(new ToolTipFormatter(this));
}
double GuiApplication::pixelRatio() const
{
#if QT_VERSION >= 0x050000
- return devicePixelRatio();
+ return qt_scale_factor * devicePixelRatio();
#else
return 1.0;
#endif
docstring Application::mathIcon(docstring const & c)
{
- return qstring_to_ucs4(findPng(toqstr(c)));
+ return qstring_to_ucs4(findImg(toqstr(c)));
}
if (dr.needBufferUpdate()) {
bv->cursor().clearBufferUpdate();
bv->buffer().updateBuffer();
+ } else if (dr.needChangesUpdate()) {
+ // updateBuffer() already updates the change-tracking presence flag
+ bv->buffer().updateChangesPresent();
}
// BufferView::update() updates the ViewMetricsInfo and
// also initializes the position cache for all insets in
// if the current buffer is not that one, switch to it.
BufferView * doc_bv = current_view_ ?
current_view_->documentBufferView() : 0;
+ // FIXME It's possible that doc_bv is null!!
+ // See coverity #102061
Cursor const old = doc_bv->cursor();
if (!doc_bv || doc_bv->buffer().fileName() != tmp.filename) {
if (switchToBuffer) {
boost::crc_32_type crc;
crc = for_each(fname.begin(), fname.end(), crc);
createView(crc.checksum());
+ // we know current_view_ is non-null, because createView sets it.
+ // but let's make sure
+ LASSERT(current_view_, break);
current_view_->openDocument(fname);
- if (current_view_ && !current_view_->documentBufferView())
+ if (!current_view_->documentBufferView())
current_view_->close();
- } else
+ else if (cmd.origin() == FuncRequest::LYXSERVER) {
+ current_view_->raise();
+ current_view_->activateWindow();
+ current_view_->showNormal();
+ }
+ } else {
+ // we know !d->views.empty(), so this should be ok
+ // but let's make sure
+ LASSERT(current_view_, break);
current_view_->openDocument(fname);
+ if (cmd.origin() == FuncRequest::LYXSERVER) {
+ current_view_->raise();
+ current_view_->activateWindow();
+ current_view_->showNormal();
+ }
+ }
break;
}
QList<GuiView *> allViews = d->views_.values();
- // this foreach does not modify any buffer. It just collects info on local visibility of buffers
- // and on which buffer is active in each view.
+ // this for does not modify any buffer. It just collects info on local
+ // visibility of buffers and on which buffer is active in each view.
Buffer * const last = theBufferList().last();
- foreach (GuiView * view, allViews) {
- // all of the buffers might be locally hidden. That is, there is no active buffer.
+ for(GuiView * view : allViews) {
+ // all of the buffers might be locally hidden. That is, there is no
+ // active buffer.
if (!view || !view->currentBufferView())
activeBuffers[view] = 0;
else
}
// put things back to how they were (if possible).
- foreach (GuiView * view, allViews) {
+ for (GuiView * view : allViews) {
Buffer * originalBuf = activeBuffers[view];
// there might not have been an active buffer in this view or it might have been closed by the LFUN.
if (theBufferList().isLoaded(originalBuf))
}
+//Keep this in sync with GuiApplication::processKeySym below
+bool GuiApplication::queryKeySym(KeySymbol const & keysym,
+ KeyModifier state) const
+{
+ // Do nothing if we have nothing
+ if (!keysym.isOK() || keysym.isModifier())
+ return false;
+ // Do a one-deep top-level lookup for cancel and meta-fake keys.
+ KeySequence seq;
+ FuncRequest func = seq.addkey(keysym, state);
+ // When not cancel or meta-fake, do the normal lookup.
+ if ((func.action() != LFUN_CANCEL) && (func.action() != LFUN_META_PREFIX)) {
+ seq = d->keyseq;
+ func = seq.addkey(keysym, (state | d->meta_fake_bit));
+ }
+ // Maybe user can only reach the key via holding down shift.
+ // Let's see. But only if shift is the only modifier
+ if (func.action() == LFUN_UNKNOWN_ACTION && state == ShiftModifier)
+ // If addkey looked up a command and did not find further commands then
+ // seq has been reset at this point
+ func = seq.addkey(keysym, NoModifier);
+
+ LYXERR(Debug::KEY, " Key (queried) [action=" << func.action() << "]["
+ << seq.print(KeySequence::Portable) << ']');
+ return func.action() != LFUN_UNKNOWN_ACTION;
+}
+
+
+//Keep this in sync with GuiApplication::queryKeySym above
void GuiApplication::processKeySym(KeySymbol const & keysym, KeyModifier state)
{
LYXERR(Debug::KEY, "KeySym is " << keysym.getSymbolName());
// Do nothing if we have nothing (JMarc)
- if (!keysym.isOK()) {
- LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
- if (current_view_)
- current_view_->restartCursor();
- return;
- }
-
- if (keysym.isModifier()) {
+ if (!keysym.isOK() || keysym.isModifier()) {
+ if (!keysym.isOK())
+ LYXERR(Debug::KEY, "Empty kbd action (probably composing)");
if (current_view_)
current_view_->restartCursor();
return;
// Let's see. But only if shift is the only modifier
if (func.action() == LFUN_UNKNOWN_ACTION && state == ShiftModifier) {
LYXERR(Debug::KEY, "Trying without shift");
+ // If addkey looked up a command and did not find further commands then
+ // seq has been reset at this point
func = d->keyseq.addkey(keysym, NoModifier);
LYXERR(Debug::KEY, "Action now " << func.action());
}
// must not be inserted (#5704)
if (!isPrintable(encoded_last_key)) {
LYXERR(Debug::KEY, "Non-printable character! Omitting.");
- current_view_->restartCursor();
+ if (current_view_)
+ current_view_->restartCursor();
return;
}
+ // The following modifier check is not needed on Mac.
+ // The keysym is either not text or it is different
+ // from the non-modifier keysym. See #9875 for the
+ // broken alt-modifier effect of having this code active.
+#if !defined(Q_OS_MAC)
// If a non-Shift Modifier is used we have a non-bound key sequence
// (such as Alt+j = j). This should be omitted (#5575).
// On Windows, AltModifier and ControlModifier are both
#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN)
&& !(state & AltModifier && state & ControlModifier)
#endif
- ) {
- current_view_->message(_("Unknown function."));
- current_view_->restartCursor();
+ )
+ {
+ if (current_view_) {
+ current_view_->message(_("Unknown function."));
+ current_view_->restartCursor();
+ }
return;
}
+#endif
// Since all checks above were passed, we now really have text that
// is to be inserted (e.g., AltGr-bound symbols). Thus change the
// func to LFUN_SELF_INSERT and thus cause the text to be inserted
QString const GuiApplication::typewriterFontName()
{
- QFont font;
- font.setStyleHint(QFont::TypeWriter);
- font.setFamily("monospace");
+ return QFontInfo(typewriterSystemFont()).family();
+}
- return QFontInfo(font).family();
+
+namespace {
+ // We cannot use QFont::fixedPitch() because it doesn't
+ // return the fact but only if it is requested.
+ static bool isFixedPitch(const QFont & font) {
+ const QFontInfo fi(font);
+ return fi.fixedPitch();
+ }
+}
+
+
+QFont const GuiApplication::typewriterSystemFont()
+{
+#if QT_VERSION >= 0x050200
+ QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
+#else
+ QFont font("monospace");
+#endif
+ if (!isFixedPitch(font)) {
+ // try to enforce a real monospaced font
+ font.setStyleHint(QFont::Monospace);
+ if (!isFixedPitch(font)) {
+ font.setStyleHint(QFont::TypeWriter);
+ if (!isFixedPitch(font)) font.setFamily("courier");
+ }
+ }
+#ifdef Q_OS_MAC
+ // On a Mac the result is too small and it's not practical to
+ // rely on Qtconfig utility to change the system settings of Qt.
+ font.setPointSize(12);
+#endif
+ return font;
}
theSession().lastOpened().clear();
QList<GuiView *> const views = d->views_.values();
- foreach (GuiView * view, views) {
+ for (GuiView * view : views) {
if (!view->closeScheduled())
return false;
}
return true;
QList<GuiView *> const views = d->views_.values();
- foreach (GuiView * view, views) {
+ for (GuiView * view : views) {
if (!view->prepareAllBuffersForLogout())
return false;
}
void GuiApplication::hideDialogs(string const & name, Inset * inset) const
{
QList<GuiView *> const views = d->views_.values();
- foreach (GuiView * view, views)
+ for (GuiView * view : views)
view->hideDialog(name, inset);
}
QString const file = toqstr(lex.getString());
bool const success = readUIFile(file, true);
if (!success) {
- LYXERR0("Failed to read inlcuded file: " << fromqstr(file));
+ LYXERR0("Failed to read included file: " << fromqstr(file));
return ReadError;
}
break;
BufferView * bv = current_view_->currentBufferView();
if (bv) {
docstring const sel = bv->requestSelection();
- if (!sel.empty())
+ if (!sel.empty()) {
d->selection_.put(sel);
+ // Refresh the selection request timestamp.
+ // We have to do this by ourselves as Qt seems
+ // not doing that, maybe because of our
+ // "persistent selection" implementation
+ // (see comments in GuiSelection.cpp).
+ XSelectionEvent nev;
+ nev.type = SelectionNotify;
+ nev.display = xev->xselectionrequest.display;
+ nev.requestor = xev->xselectionrequest.requestor;
+ nev.selection = xev->xselectionrequest.selection;
+ nev.target = xev->xselectionrequest.target;
+ nev.property = 0L; // None
+ nev.time = CurrentTime;
+ XSendEvent(QX11Info::display(),
+ nev.requestor, False, 0,
+ reinterpret_cast<XEvent *>(&nev));
+ return true;
+ }
}
break;
}
BufferView * bv = current_view_->currentBufferView();
if (bv) {
docstring const sel = bv->requestSelection();
- if (!sel.empty())
+ if (!sel.empty()) {
d->selection_.put(sel);
+#ifdef HAVE_QT5_X11_EXTRAS
+ // Refresh the selection request timestamp.
+ // We have to do this by ourselves as Qt seems
+ // not doing that, maybe because of our
+ // "persistent selection" implementation
+ // (see comments in GuiSelection.cpp).
+ xcb_selection_notify_event_t nev;
+ nev.response_type = XCB_SELECTION_NOTIFY;
+ nev.requestor = srev->requestor;
+ nev.selection = srev->selection;
+ nev.target = srev->target;
+ nev.property = XCB_NONE;
+ nev.time = XCB_CURRENT_TIME;
+ xcb_connection_t * con = QX11Info::connection();
+ xcb_send_event(con, 0, srev->requestor,
+ XCB_EVENT_MASK_NO_EVENT,
+ reinterpret_cast<char const *>(&nev));
+ xcb_flush(con);
+#endif
+ return true;
+ }
}
break;
}