From: Abdelrazak Younes Date: Fri, 13 Jun 2008 07:34:55 +0000 (+0000) Subject: - Simplify prefs, graphics and external display options which are now true or false. X-Git-Tag: 1.6.10~4402 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4a1be58591ea5a7431d9426abb27d8b946c634cb;p=features.git - Simplify prefs, graphics and external display options which are now true or false. - the display combo in the prefs, external and graphics dialogs are gone - the lyxrc display_graphics option now overrides any local inset display option - The external template format has a new tag: Preview - format incremented to 337 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25245 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/development/FORMAT b/development/FORMAT index b56bdc510c..140e8a660e 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,9 @@ LyX file-format changes ----------------------- +2008-06-13 Abdelrazak Younes + * Format incremented to 337: convert/revert graphics display param. + 2008-06-04 Jürgen Spitzmüller * Format incremented to 336: new param \font_cjk. diff --git a/lib/external_templates b/lib/external_templates index edcac389aa..6aafd6857f 100644 --- a/lib/external_templates +++ b/lib/external_templates @@ -58,6 +58,13 @@ Template RasterImage Transform Resize Transform Clip Transform Extra + # LyX preview options: + # Off: LyX will not attempt to show this material on screen. + # Graphics: LyX will attempt to show this material as-is or via a + # conversion to a showable format. + # InstantPreview: LyX will attempt to use the 'instant preview' + # mechanism in order to show this material. + Preview Graphics Format LaTeX TransformOption Rotate RotationLatexOption TransformOption Resize ResizeLatexOption @@ -109,6 +116,7 @@ Template XFig AutomaticProduction true Transform Rotate Transform Resize + Preview InstantPreview Format LaTeX TransformCommand Rotate RotationLatexCommand TransformCommand Resize ResizeLatexCommand @@ -175,6 +183,7 @@ Template ChessDiagram InputFormat fen FileFilter "*.fen" AutomaticProduction true + Preview InstantPreview Format LaTeX Product "\\loadgame{$$AbsOrRelPathMaster$$Basename}\\showboard" Requirement "chess" @@ -211,6 +220,7 @@ Template LilyPond Transform Resize Transform Clip Transform Extra + Preview InstantPreview Format LaTeX TransformOption Rotate RotationLatexOption TransformOption Resize ResizeLatexOption @@ -293,6 +303,7 @@ Template Date InputFormat date FileFilter "*" AutomaticProduction true + Preview Off Format LaTeX Product "$$Contents(\"$$Tempname\")" UpdateFormat dateout diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 75e0ffe68a..e352014f17 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -2500,6 +2500,40 @@ def revert_InsetSpace(document): document.body[i] = document.body[i].replace('\\begin_inset space', '\\begin_inset Space') +def convert_display_enum(document): + " Convert 'display foo' to 'display false/true'" + i = 0 + while True: + i = find_token(document.body, "display", i) + if i == -1: + return + if check_token(i, "none"): + document.body[i] = document.body[i].replace('none', 'false') + if check_token(i, "default"): + document.body[i] = document.body[i].replace('default', 'true') + if check_token(i, "monochrome"): + document.body[i] = document.body[i].replace('monochrome', 'true') + if check_token(i, "grayscale"): + document.body[i] = document.body[i].replace('grayscale', 'true') + if check_token(i, "color"): + document.body[i] = document.body[i].replace('color', 'true') + if check_token(i, "preview"): + document.body[i] = document.body[i].replace('preview', 'true') + + +def revert_display_enum(document): + " Revert 'display false/true' to 'display none/color'" + i = 0 + while True: + i = find_token(document.body, "display", i) + if i == -1: + return + if check_token(i, "false"): + document.body[i] = document.body[i].replace('false', 'none') + if check_token(i, "true"): + document.body[i] = document.body[i].replace('true', 'default') + + def remove_fontsCJK(document): ' Remove font_cjk param ' i = find_token(document.header, "\\font_cjk", 0) @@ -2610,9 +2644,11 @@ convert = [[277, [fix_wrong_tables]], [334, [convert_paper_sizes]], [335, [convert_InsetSpace]], [336, []], + [337, [convert_display_enum]], ] -revert = [[335, [remove_fontsCJK]], +revert = [[336, [revert_display_enum]], + [335, [remove_fontsCJK]], [334, [revert_InsetSpace]], [333, [revert_paper_sizes]], [332, []], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 8abcb462ab..e52b6dbacf 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -115,7 +115,7 @@ namespace os = support::os; namespace { -int const LYX_FORMAT = 336; +int const LYX_FORMAT = 337; typedef map DepClean; typedef map > RefCache; diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index fa916ba242..cc60cdeb11 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -254,7 +254,7 @@ void LyXRC::setDefaults() load_session = false; make_backup = true; backupdir_path.erase(); - display_graphics = graphics::ColorDisplay; + display_graphics = true; // Spellchecker settings: use_spell_lib = true; isp_command = "ispell"; @@ -420,7 +420,7 @@ int LyXRC::read(Lexer & lexrc) case RC_DISPLAY_GRAPHICS: if (lexrc.next()) - display_graphics = graphics::displayTranslator().find(lexrc.getString()); + display_graphics = lexrc.getString() == "true"; break; case RC_TEX_EXPECTS_WINDOWS_PATHS: @@ -1224,10 +1224,9 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c if (ignore_system_lyxrc || display_graphics != system_lyxrc.display_graphics) { os << "# Display graphics within LyX\n" - << "# monochrome|grayscale|color|none\n" + << "# true|false\n" << "\\display_graphics " - << graphics::displayTranslator().find( - graphics::DisplayType(display_graphics)) + << (display_graphics ? "true" : "false") << '\n'; } if (tag != RC_LAST) diff --git a/src/LyXRC.h b/src/LyXRC.h index b7855f7ecd..e34492f200 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -376,8 +376,7 @@ public: /// int label_init_length; /// - ///graphics::DisplayType - int display_graphics; + bool display_graphics; /// bool show_banner; /// diff --git a/src/frontends/qt4/GuiExternal.cpp b/src/frontends/qt4/GuiExternal.cpp index 82bed17a3f..df0ce70f4f 100644 --- a/src/frontends/qt4/GuiExternal.cpp +++ b/src/frontends/qt4/GuiExternal.cpp @@ -98,12 +98,10 @@ GuiExternal::GuiExternal(GuiView & lv) connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); - connect(displayGB, SIGNAL(toggled(bool)), - showCO, SLOT(setEnabled(bool))); + /* connect(displayGB, SIGNAL(toggled(bool)), displayscaleED, SLOT(setEnabled(bool))); - connect(showCO, SIGNAL(activated(QString)), - this, SLOT(change_adaptor())); + */ connect(originCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); connect(aspectratioCB, SIGNAL(stateChanged(int)), @@ -168,7 +166,6 @@ GuiExternal::GuiExternal(GuiView & lv) bc().addReadOnly(externalCO); bc().addReadOnly(draftCB); bc().addReadOnly(displayscaleED); - bc().addReadOnly(showCO); bc().addReadOnly(displayGB); bc().addReadOnly(angleED); bc().addReadOnly(originCO); @@ -365,62 +362,6 @@ static Length::UNIT defaultUnit() } -static void setDisplay( - QGroupBox & displayGB, QComboBox & showCO, QLineEdit & scaleED, - external::DisplayType display, unsigned int scale, bool read_only) -{ - int item = 0; - switch (display) { - case external::DefaultDisplay: - item = 0; - break; - case external::MonochromeDisplay: - item = 1; - break; - case external::GrayscaleDisplay: - item = 2; - break; - case external::ColorDisplay: - item = 3; - break; - case external::PreviewDisplay: - item = 4; - break; - case external::NoDisplay: - item = 0; - break; - } - - showCO.setCurrentIndex(item); - bool const no_display = display == external::NoDisplay; - showCO.setEnabled(!no_display && !read_only); - displayGB.setChecked(!no_display); - scaleED.setEnabled(!no_display && !read_only); - scaleED.setText(QString::number(scale)); -} - - -static external::DisplayType display(QGroupBox const & displayGB, - QComboBox const & showCO) -{ - if (!displayGB.isChecked()) - return external::NoDisplay; - switch (showCO.currentIndex()) { - default: - case 0: - return external::DefaultDisplay; - case 1: - return external::MonochromeDisplay; - case 2: - return external::GrayscaleDisplay; - case 3: - return external::ColorDisplay; - case 4: - return external::PreviewDisplay; - } -} - - static void setRotation(QLineEdit & angleED, QComboBox & originCO, external::RotationData const & data) { @@ -569,8 +510,10 @@ void GuiExternal::updateContents() draftCB->setChecked(params_.draft); - setDisplay(*displayGB, *showCO, *displayscaleED, - params_.display, params_.lyxscale, isBufferReadonly()); + displayGB->setChecked(params_.display); + displayscaleED->setEnabled(params_.display && !isBufferReadonly()); + displayscaleED->setText(QString::number(params_.lyxscale)); + displayGB->setEnabled(lyxrc.display_graphics); setRotation(*angleED, *originCO, params_.rotationdata); @@ -654,7 +597,7 @@ void GuiExternal::applyView() params_.draft = draftCB->isChecked(); params_.lyxscale = displayscaleED->text().toInt(); - params_.display = display(*displayGB, *showCO); + params_.display = displayGB->isChecked(); if (rotationGB->isEnabled()) getRotation(params_.rotationdata, *angleED, *originCO); diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index 1ceb9af9a5..cea974402d 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -239,10 +239,7 @@ GuiGraphics::GuiGraphics(GuiView & lv) // setChecked(). Note, too, that clicked() would get called whenever it // is clicked, even right clicked (I think), not just whenever it is // toggled. - connect(displayGB, SIGNAL(toggled(bool)), - this, SLOT(change_adaptor())); - connect(showCB, SIGNAL(currentIndexChanged(int)), - this, SLOT(change_adaptor())); + connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); connect(displayscale, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(groupId, SIGNAL(textChanged(const QString&)), @@ -518,18 +515,8 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) draftCB->setChecked(igp.draft); clip->setChecked(igp.clip); unzipCB->setChecked(igp.noUnzip); - - int item = 0; - switch (igp.display) { - case graphics::DefaultDisplay: item = 0; break; - case graphics::MonochromeDisplay: item = 1; break; - case graphics::GrayscaleDisplay: item = 2; break; - case graphics::ColorDisplay: item = 3; break; - case graphics::NoDisplay: item = 0; break; - } - showCB->setCurrentIndex(item); + displayGB->setChecked(igp.display); displayscale->setText(toqstr(convert(igp.lyxscale))); - displayGB->setChecked(igp.display != graphics::NoDisplay); // the output section (width/height) @@ -540,6 +527,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) scaleCB->setChecked(scaleChecked); scaleCB->blockSignals(false); Scale->setEnabled(scaleChecked); + displayGB->setEnabled(lyxrc.display_graphics); groupId->setText(toqstr(igp.groupId)); @@ -636,17 +624,7 @@ void GuiGraphics::applyView() igp.draft = draftCB->isChecked(); igp.clip = clip->isChecked(); - - switch (showCB->currentIndex()) { - case 0: igp.display = graphics::DefaultDisplay; break; - case 1: igp.display = graphics::MonochromeDisplay; break; - case 2: igp.display = graphics::GrayscaleDisplay; break; - case 3: igp.display = graphics::ColorDisplay; break; - default:; - } - - if (!displayGB->isChecked()) - igp.display = graphics::NoDisplay; + igp.display = displayGB->isChecked(); //the graphics section if (scaleCB->isChecked() && !Scale->text().isEmpty()) { diff --git a/src/frontends/qt4/GuiImage.cpp b/src/frontends/qt4/GuiImage.cpp index b72e6157a5..3af803831f 100644 --- a/src/frontends/qt4/GuiImage.cpp +++ b/src/frontends/qt4/GuiImage.cpp @@ -78,58 +78,15 @@ bool GuiImage::load(FileName const & filename) } -// This code is taken from KImageEffect::toGray -static QPixmap toGray(QPixmap const & pix) -{ - if (pix.width() == 0 || pix.height() == 0) - return pix; - - QImage img = pix.toImage(); - int const pixels = img.depth() > 8 ? - img.width() * img.height() : img.numColors(); - - unsigned int *data = img.depth() > 8 ? - reinterpret_cast(img.bits()) : - reinterpret_cast(&img.colorTable()[0]); - - for(int i = 0; i < pixels; ++i){ - int const val = qGray(data[i]); - data[i] = qRgba(val, val, val, qAlpha(data[i])); - } - return QPixmap::fromImage(img); -} - - bool GuiImage::setPixmap(Params const & params) { - if (original_.isNull() || params.display == NoDisplay) + if (original_.isNull() || !params.display) return false; is_transformed_ = clip(params); is_transformed_ |= rotate(params); is_transformed_ |= scale(params); - switch (params.display) { - case GrayscaleDisplay: { - transformed_ = is_transformed_ - ? toGray(transformed_) : toGray(original_); - is_transformed_ = true; - break; - } - - case MonochromeDisplay: { - QImage img = is_transformed_ - ? transformed_.toImage() : original_.toImage(); - img.convertToFormat(img.format(), Qt::MonoOnly); - transformed_ = QPixmap::fromImage(img); - is_transformed_ = true; - break; - } - - default: - break; - } - if (!is_transformed_) // Clear it out to save some memory. transformed_ = QPixmap(); diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 40b855a27d..18bbad5bfc 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -864,10 +864,8 @@ PrefDisplay::PrefDisplay(GuiPreferences * form) : PrefModule(qt_(catLookAndFeel), qt_("Graphics"), form) { setupUi(this); - connect(instantPreviewCO, SIGNAL(activated(int)), - this, SIGNAL(changed())); - connect(displayGraphicsCO, SIGNAL(activated(int)), - this, SIGNAL(changed())); + connect(displayGraphicsCB, SIGNAL(toggled(int)), this, SIGNAL(changed())); + connect(instantPreviewCO, SIGNAL(activated(int)), this, SIGNAL(changed())); } @@ -879,15 +877,7 @@ void PrefDisplay::apply(LyXRC & rc) const case 2: rc.preview = LyXRC::PREVIEW_ON; break; } - graphics::DisplayType dtype; - switch (displayGraphicsCO->currentIndex()) { - case 3: dtype = graphics::NoDisplay; break; - case 2: dtype = graphics::ColorDisplay; break; - case 1: dtype = graphics::GrayscaleDisplay; break; - case 0: dtype = graphics::MonochromeDisplay; break; - default: dtype = graphics::GrayscaleDisplay; - } - rc.display_graphics = dtype; + rc.display_graphics = displayGraphicsCB->isChecked(); // FIXME!! The graphics cache no longer has a changeDisplay method. #if 0 @@ -913,15 +903,8 @@ void PrefDisplay::update(LyXRC const & rc) break; } - int item = 2; - switch (rc.display_graphics) { - case graphics::NoDisplay: item = 3; break; - case graphics::ColorDisplay: item = 2; break; - case graphics::GrayscaleDisplay: item = 1; break; - case graphics::MonochromeDisplay: item = 0; break; - default: break; - } - displayGraphicsCO->setCurrentIndex(item); + displayGraphicsCB->setChecked(rc.display_graphics); + instantPreviewCO->setEnabled(rc.display_graphics); } diff --git a/src/frontends/qt4/ui/ExternalUi.ui b/src/frontends/qt4/ui/ExternalUi.ui index 1bedc8dcde..82fd52dcbf 100644 --- a/src/frontends/qt4/ui/ExternalUi.ui +++ b/src/frontends/qt4/ui/ExternalUi.ui @@ -24,10 +24,21 @@ + + + - 0 + 2 + + + 0 + 0 + 362 + 375 + + F&ile @@ -98,7 +109,7 @@ QSizePolicy::Preferred - + 20 20 @@ -109,9 +120,7 @@ - - 3 - 0 + 0 0 @@ -127,17 +136,19 @@ + + + 0 + 0 + 362 + 375 + + LaTe&X and LyX options - - - 9 - - - 6 - - + + LaTeX Options @@ -184,10 +195,15 @@ - + - Display image in LyX + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">Enable LyX to preview this material; only if graphics previewing is not disabled at application level (see Preference dialog).</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p></body></html> &Show in LyX @@ -198,134 +214,58 @@ true - - - 9 - - - 6 - - - - - Qt::Horizontal - - - - 87 - 20 - - - - - - - - Screen display - - - - Default - - - - - Monochrome - - - - - Grayscale - - - - - Color - - - - - Preview - - - - - - - - 0 - - - 6 - - - - - true - - - - 5 - 0 - 0 - 0 - - - - Percentage to scale by in LyX - - - - - - - true - - - Qt::NoFocus - - - % - - - - - + - + - Screen display + Percentage to scale by in LyX - &Display: + Sca&le on Screen (%): - showCO + displayscaleED - + + + true + + + + 0 + 0 + + Percentage to scale by in LyX - - Sca&le: + + + + + + Qt::Horizontal - - displayscaleED + + + 40 + 20 + - + - + Qt::Vertical - + 81 196 @@ -336,6 +276,14 @@ + + + 0 + 0 + 362 + 375 + + Si&ze and Rotation @@ -369,7 +317,7 @@ QSizePolicy::Expanding - + 20 20 @@ -388,9 +336,7 @@ - - 3 - 0 + 0 0 @@ -457,7 +403,7 @@ 6 - + @@ -601,7 +547,7 @@ Qt::Horizontal - + 43 18 @@ -631,12 +577,12 @@ - - 0 - 6 + + 0 + @@ -645,7 +591,7 @@ QSizePolicy::Expanding - + 20 20 @@ -689,11 +635,13 @@ + tab + displayscaleLA LengthCombo - QWidget + QComboBox
LengthCombo.h
@@ -704,8 +652,6 @@ externalCO externalTB draftCB - showCO - displayscaleED angleED originCO okPB diff --git a/src/frontends/qt4/ui/GraphicsUi.ui b/src/frontends/qt4/ui/GraphicsUi.ui index 18ba74ca04..5988a26aac 100644 --- a/src/frontends/qt4/ui/GraphicsUi.ui +++ b/src/frontends/qt4/ui/GraphicsUi.ui @@ -121,15 +121,15 @@
- 0 + 2 0 0 - 562 - 293 + 593 + 295 @@ -371,8 +371,8 @@ 0 0 - 100 - 30 + 593 + 295
@@ -541,8 +541,8 @@ 0 0 - 595 - 293 + 593 + 295
@@ -600,6 +600,9 @@ Qt::StrongFocus + + Enable LyX to preview this graphics, only if graphics previewing is not disabled at application level (see Preference dialog). + Sho&w in LyX @@ -629,75 +632,6 @@
- - - - true - - - - 0 - 0 - - - - Percentage to scale by in LyX - - - - - - - Percentage to scale by in LyX - - - Sca&le on Screen (%): - - - displayscale - - - - - - - Screen display - - - - Default - - - - - Monochrome - - - - - Grayscale - - - - - Color - - - - - - - - Screen display - - - Scr&een Display: - - - showCB - - - @@ -727,6 +661,35 @@ + + + + true + + + + 0 + 0 + + + + Percentage to scale by in LyX + + + + + + + Percentage to scale by in LyX + + + Sca&le on Screen (%): + + + displayscale + + +
@@ -790,8 +753,6 @@ draftCB unzipCB displayGB - showCB - displayscale qt_i18n.h diff --git a/src/frontends/qt4/ui/PrefDisplayUi.ui b/src/frontends/qt4/ui/PrefDisplayUi.ui index 49c7b1079a..a8f16a5042 100644 --- a/src/frontends/qt4/ui/PrefDisplayUi.ui +++ b/src/frontends/qt4/ui/PrefDisplayUi.ui @@ -12,19 +12,20 @@ - - - 9 - - - 6 - + + + + + Display &Graphics + + + Qt::Horizontal - + 40 20 @@ -32,6 +33,16 @@ + + + + Instant &Preview: + + + instantPreviewCO + + + @@ -51,50 +62,6 @@ - - - - - Monochrome - - - - - Grayscale - - - - - Color - - - - - Do not display - - - - - - - - Display &Graphics: - - - displayGraphicsCO - - - - - - - Instant &Preview: - - - instantPreviewCO - - - @@ -103,7 +70,7 @@ QSizePolicy::Expanding - + 20 20 @@ -114,7 +81,6 @@ - displayGraphicsCO instantPreviewCO diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp index d2b712b60c..63b1ac4f18 100644 --- a/src/graphics/GraphicsLoader.cpp +++ b/src/graphics/GraphicsLoader.cpp @@ -207,10 +207,10 @@ Loader::Loader() {} -Loader::Loader(FileName const & file, DisplayType type) +Loader::Loader(FileName const & file, bool display) : pimpl_(new Impl) { - reset(file, type); + reset(file, display); } @@ -245,10 +245,10 @@ Loader & Loader::operator=(Loader const & other) } -void Loader::reset(FileName const & file, DisplayType type) const +void Loader::reset(FileName const & file, bool display) const { Params params; - params.display = type; + params.display = display; pimpl_->resetParams(params); pimpl_->resetFile(file); @@ -407,8 +407,7 @@ void Loader::Impl::statusChanged() void Loader::Impl::createPixmap() { - if (!cached_item_.get() || - params_.display == NoDisplay || status_ != Loaded) + if (!cached_item_.get() || !params_.display || status_ != Loaded) return; image_.reset(cached_item_->image()->clone()); diff --git a/src/graphics/GraphicsLoader.h b/src/graphics/GraphicsLoader.h index c4ed587f66..43fd85e695 100644 --- a/src/graphics/GraphicsLoader.h +++ b/src/graphics/GraphicsLoader.h @@ -42,7 +42,7 @@ public: /// Must use the reset methods to make this instance usable. Loader(); /// The image is not transformed, just displayed as-is. - Loader(support::FileName const & file_with_path, DisplayType = ColorDisplay); + Loader(support::FileName const & file_with_path, bool display = true); /// The image is transformed before display. Loader(support::FileName const & file_with_path, Params const &); /// @@ -53,8 +53,7 @@ public: Loader & operator=(Loader const &); /// The file can be changed, or the display params, or both. - void reset(support::FileName const & file_with_path, - DisplayType = ColorDisplay) const; + void reset(support::FileName const & file_with_path, bool display = true) const; /// void reset(support::FileName const & file_with_path, Params const &) const; /// diff --git a/src/graphics/GraphicsParams.cpp b/src/graphics/GraphicsParams.cpp index 659cbe84c0..a53d2c57b1 100644 --- a/src/graphics/GraphicsParams.cpp +++ b/src/graphics/GraphicsParams.cpp @@ -23,7 +23,7 @@ namespace lyx { namespace graphics { Params::Params() - : display(ColorDisplay), + : display(true), scale(100), angle(0) {} diff --git a/src/graphics/GraphicsParams.h b/src/graphics/GraphicsParams.h index a7b7c8ffa4..7213aaa3a1 100644 --- a/src/graphics/GraphicsParams.h +++ b/src/graphics/GraphicsParams.h @@ -55,7 +55,7 @@ class Params public: Params(); - DisplayType display; + bool display; unsigned int scale; /// The image filename. diff --git a/src/graphics/GraphicsTypes.cpp b/src/graphics/GraphicsTypes.cpp index 126bf55f6c..af25934cc0 100644 --- a/src/graphics/GraphicsTypes.cpp +++ b/src/graphics/GraphicsTypes.cpp @@ -19,30 +19,5 @@ using namespace std; namespace lyx { namespace graphics { -namespace { - -/// The translator between the Display enum and corresponding lyx string. -Translator const initTranslator() -{ - Translator translator(DefaultDisplay, "default"); - - // Fill the display translator - translator.addPair(MonochromeDisplay, "monochrome"); - translator.addPair(GrayscaleDisplay, "grayscale"); - translator.addPair(ColorDisplay, "color"); - translator.addPair(NoDisplay, "none"); - - return translator; -} - -} // namespace anon - -Translator const & displayTranslator() -{ - static Translator const translator = - initTranslator(); - return translator; -} - } // namespace graphics } // namespace lyx diff --git a/src/graphics/GraphicsTypes.h b/src/graphics/GraphicsTypes.h index 50533eb64a..45181d3a8b 100644 --- a/src/graphics/GraphicsTypes.h +++ b/src/graphics/GraphicsTypes.h @@ -50,24 +50,6 @@ enum ImageStatus { ErrorUnknown }; -/// How is the image to be displayed on the LyX screen? -enum DisplayType { - /// - DefaultDisplay, - /// - MonochromeDisplay, - /// - GrayscaleDisplay, - /// - ColorDisplay, - /// - NoDisplay -}; - - -/// The translator between the Display enum and corresponding lyx string. -Translator const & displayTranslator(); - } // namespace graphics } // namespace lyx diff --git a/src/insets/ExternalTemplate.cpp b/src/insets/ExternalTemplate.cpp index 7861e8a59f..600969dc45 100644 --- a/src/insets/ExternalTemplate.cpp +++ b/src/insets/ExternalTemplate.cpp @@ -102,8 +102,19 @@ public: << "\tHelpTextEnd\n" << "\tInputFormat " << et.inputFormat << '\n' << "\tFileFilter " << et.fileRegExp << '\n' - << "\tAutomaticProduction " << et.automaticProduction << '\n'; - + << "\tAutomaticProduction " << et.automaticProduction << '\n' + << "\tPreview "; + switch (et.preview_mode) { + case PREVIEW_OFF: + os_ << "Off\n"; + break; + case PREVIEW_GRAPHICS: + os_ << "Graphics\n"; + break; + case PREVIEW_INSTANT: + os_ << "InstantPreview\n"; + break; + } typedef vector IDs; IDs::const_iterator it = et.transformIds.begin(); IDs::const_iterator end = et.transformIds.end(); @@ -299,6 +310,7 @@ void Template::readTemplate(Lexer & lex) TO_INPUTFORMAT, TO_FILTER, TO_AUTOMATIC, + TO_PREVIEW, TO_TRANSFORM, TO_FORMAT, TO_END @@ -306,6 +318,7 @@ void Template::readTemplate(Lexer & lex) LexerKeyword templateoptiontags[] = { { "automaticproduction", TO_AUTOMATIC }, + { "preview", TO_PREVIEW }, { "filefilter", TO_FILTER }, { "format", TO_FORMAT }, { "guiname", TO_GUINAME }, @@ -345,6 +358,16 @@ void Template::readTemplate(Lexer & lex) automaticProduction = lex.getBool(); break; + case TO_PREVIEW: + lex >> token; + if (token == "InstantPreview") + preview_mode = PREVIEW_INSTANT; + else if (token == "Graphics") + preview_mode = PREVIEW_GRAPHICS; + else + preview_mode = PREVIEW_OFF; + break; + case TO_TRANSFORM: { lex >> token; TransformID id = transformIDTranslator().find(token); diff --git a/src/insets/ExternalTemplate.h b/src/insets/ExternalTemplate.h index 7afc65715b..23f1f78802 100644 --- a/src/insets/ExternalTemplate.h +++ b/src/insets/ExternalTemplate.h @@ -23,6 +23,12 @@ namespace support { class FileName; } class Lexer; +enum PreviewMode { + PREVIEW_OFF = 0, + PREVIEW_GRAPHICS, + PREVIEW_INSTANT +}; + namespace external { class Template { @@ -56,6 +62,8 @@ public: std::string fileRegExp; /// Should we do automatic production of the output? bool automaticProduction; + /// How should we preview the data in LyX? + PreviewMode preview_mode; /// A collection of transforms that we can use to transform the data. std::vector transformIds; diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 42efa6d289..a2b820c490 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -12,7 +12,6 @@ #include "InsetExternal.h" #include "insets/ExternalSupport.h" -#include "insets/ExternalTemplate.h" #include "insets/RenderButton.h" #include "insets/RenderGraphic.h" #include "insets/RenderPreview.h" @@ -54,8 +53,6 @@ using namespace lyx::support; namespace { -lyx::external::DisplayType const defaultDisplayType = lyx::external::NoDisplay; - unsigned int const defaultLyxScale = 100; string defaultTemplateName; @@ -98,39 +95,11 @@ TempName & TempName::operator=(TempName const & other) return *this; } - -namespace { - -/// The translator between the Display enum and corresponding lyx string. -Translator const initTranslator() -{ - Translator translator(DefaultDisplay, "default"); - - // Fill the display translator - translator.addPair(MonochromeDisplay, "monochrome"); - translator.addPair(GrayscaleDisplay, "grayscale"); - translator.addPair(ColorDisplay, "color"); - translator.addPair(PreviewDisplay, "preview"); - translator.addPair(NoDisplay, "none"); - - return translator; -} - -} // namespace anon - - -Translator const & displayTranslator() -{ - static Translator const translator = - initTranslator(); - return translator; -} - } // namespace external InsetExternalParams::InsetExternalParams() - : display(defaultDisplayType), + : display(true), lyxscale(defaultLyxScale), draft(false) { @@ -180,6 +149,9 @@ void InsetExternalParams::settemplate(string const & name) clearIfNotFound(extradata, external::Extra, ids); clearIfNotFound(resizedata, external::Resize, ids); clearIfNotFound(rotationdata, external::Rotate, ids); + + // + preview_mode = et->preview_mode; } @@ -191,10 +163,8 @@ void InsetExternalParams::write(Buffer const & buf, ostream & os) const if (!filename.empty()) os << "\tfilename " << filename.outputFilename(buf.filePath()) << '\n'; - if (display != defaultDisplayType) - os << "\tdisplay " - << external::displayTranslator().find(display) - << '\n'; + if (!display) + os << "\tdisplay false\n"; if (lyxscale != defaultLyxScale) os << "\tlyxscale " << convert(lyxscale) << '\n'; @@ -301,8 +271,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex) case EX_DISPLAY: { lex.next(); - string const name = lex.getString(); - display = external::displayTranslator().find(name); + display = lex.getString() != "false"; break; } @@ -499,33 +468,6 @@ void InsetExternal::draw(PainterInfo & pi, int x, int y) const namespace { -enum RenderType { - RENDERBUTTON, - RENDERGRAPHIC, - RENDERPREVIEW -}; - - -RenderType getRenderType(InsetExternalParams const & p) -{ - if (!external::getTemplatePtr(p) || - p.filename.empty() || - p.display == external::NoDisplay) - return RENDERBUTTON; - - if (p.display == external::PreviewDisplay) { - if (RenderPreview::status() != LyXRC::PREVIEW_OFF) - return RENDERPREVIEW; - return RENDERBUTTON; - } - - if (p.display == external::DefaultDisplay && - lyxrc.display_graphics == graphics::NoDisplay) - return RENDERBUTTON; - return RENDERGRAPHIC; -} - - graphics::Params get_grfx_params(InsetExternalParams const & eparams) { graphics::Params gparams; @@ -535,31 +477,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams) if (eparams.clipdata.clip) gparams.bb = eparams.clipdata.bbox; gparams.angle = convert(eparams.rotationdata.adjAngle()); - - switch (eparams.display) { - case external::DefaultDisplay: - gparams.display = graphics::DefaultDisplay; - break; - case external::MonochromeDisplay: - gparams.display = graphics::MonochromeDisplay; - break; - case external::GrayscaleDisplay: - gparams.display = graphics::GrayscaleDisplay; - break; - case external::ColorDisplay: - gparams.display = graphics::ColorDisplay; - break; - case external::NoDisplay: - gparams.display = graphics::NoDisplay; - break; - default: - LASSERT(false, /**/); - } - if (gparams.display == graphics::DefaultDisplay) - gparams.display = graphics::DisplayType(lyxrc.display_graphics); - // Override the above if we're not using a gui - if (!use_gui) - gparams.display = graphics::NoDisplay; + gparams.display = eparams.display; return gparams; } @@ -585,8 +503,7 @@ docstring screenLabel(InsetExternalParams const & params, static bool isPreviewWanted(InsetExternalParams const & params) { - return params.display == external::PreviewDisplay && - params.filename.isReadableFile(); + return params.display && params.filename.isReadableFile(); } @@ -632,44 +549,43 @@ void InsetExternal::setParams(InsetExternalParams const & p) // will use this. defaultTemplateName = params_.templatename(); - switch (getRenderType(params_)) { - case RENDERBUTTON: { + if (!external::getTemplatePtr(params_) || params_.filename.empty() + || !params_.display + || !lyxrc.display_graphics + || params_.preview_mode == PREVIEW_OFF + || (params_.preview_mode == PREVIEW_INSTANT + && RenderPreview::status() == LyXRC::PREVIEW_OFF)) { RenderButton * button_ptr = renderer_->asButton(); if (!button_ptr) { renderer_.reset(new RenderButton); button_ptr = renderer_->asButton(); } - button_ptr->update(screenLabel(params_, buffer()), true); - break; + return; } - case RENDERGRAPHIC: { + switch (params_.preview_mode) { + case PREVIEW_OFF: + // Already taken care of above. + LASSERT(false, return); + break; + case PREVIEW_INSTANT: { + RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview(); + renderer_.reset(new RenderMonitoredPreview(this)); + preview_ptr = renderer_->asMonitoredPreview(); + preview_ptr->fileChanged(boost::bind(&InsetExternal::fileChanged, this)); + if (preview_ptr->monitoring()) + preview_ptr->stopMonitoring(); + add_preview_and_start_loading(*preview_ptr, *this, buffer()); + break; + } + case PREVIEW_GRAPHICS: { RenderGraphic * graphic_ptr = renderer_->asGraphic(); if (!graphic_ptr) { renderer_.reset(new RenderGraphic(this)); graphic_ptr = renderer_->asGraphic(); } - graphic_ptr->update(get_grfx_params(params_)); - - break; - } - - case RENDERPREVIEW: { - RenderMonitoredPreview * preview_ptr = - renderer_->asMonitoredPreview(); - if (!preview_ptr) { - renderer_.reset(new RenderMonitoredPreview(this)); - preview_ptr = renderer_->asMonitoredPreview(); - preview_ptr->fileChanged( - boost::bind(&InsetExternal::fileChanged, this)); - } - - if (preview_ptr->monitoring()) - preview_ptr->stopMonitoring(); - add_preview_and_start_loading(*preview_ptr, *this, buffer()); - break; } } diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h index 22a9318a47..a9f8adbe53 100644 --- a/src/insets/InsetExternal.h +++ b/src/insets/InsetExternal.h @@ -13,6 +13,7 @@ #define INSET_EXTERNAL_H #include "Inset.h" +#include "ExternalTemplate.h" #include "ExternalTransforms.h" #include "support/FileName.h" @@ -44,20 +45,6 @@ private: support::FileName tempname_; }; -/// How is the image to be displayed on the LyX screen? -enum DisplayType { - DefaultDisplay, - MonochromeDisplay, - GrayscaleDisplay, - ColorDisplay, - PreviewDisplay, - NoDisplay -}; - - -/// The translator between the Display enum and corresponding lyx string. -Translator const & displayTranslator(); - } // namespace external @@ -78,8 +65,10 @@ public: /// The external file. support::DocFileName filename; - /// How the inset is to be displayed by LyX. - external::DisplayType display; + /// If the inset is to be displayed by LyX. + bool display; + /// If the inset is to use the preview mechanism. + PreviewMode preview_mode; /// The scale of the displayed graphic (if shown). unsigned int lyxscale; diff --git a/src/insets/InsetGraphicsParams.cpp b/src/insets/InsetGraphicsParams.cpp index b2b15f0ad3..ad796d7638 100644 --- a/src/insets/InsetGraphicsParams.cpp +++ b/src/insets/InsetGraphicsParams.cpp @@ -64,7 +64,7 @@ void InsetGraphicsParams::init() { filename.erase(); lyxscale = 100; // lyx scaling in percentage - display = graphics::DefaultDisplay; // display mode; see preferences + display = true; // may be overriden by display mode in preferences scale = string("100"); // output scaling in percentage width = Length(); height = Length(); @@ -144,8 +144,8 @@ void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const os << "\tfilename " << filename.outputFilename(buffer.filePath()) << '\n'; if (lyxscale != 100) os << "\tlyxscale " << lyxscale << '\n'; - if (display != graphics::DefaultDisplay) - os << "\tdisplay " << graphics::displayTranslator().find(display) << '\n'; + if (!display) + os << "\tdisplay false\n"; if (!scale.empty() && !float_equal(convert(scale), 0.0, 0.05)) { if (!float_equal(convert(scale), 100.0, 0.05)) os << "\tscale " << scale << '\n'; @@ -193,7 +193,7 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const & } else if (token == "display") { lex.next(); string const type = lex.getString(); - display = graphics::displayTranslator().find(type); + display = lex.getString() != "false"; } else if (token == "scale") { lex.next(); scale = lex.getString(); @@ -303,15 +303,11 @@ graphics::Params InsetGraphicsParams::as_grfxParams() const } } - if (display == graphics::DefaultDisplay) { - pars.display = graphics::DisplayType(lyxrc.display_graphics); - } else { - pars.display = display; - } + pars.display = display; // Override the above if we're not using a gui if (!use_gui) - pars.display = graphics::NoDisplay; + pars.display = false; return pars; } diff --git a/src/insets/InsetGraphicsParams.h b/src/insets/InsetGraphicsParams.h index 348e708406..0f9600971c 100644 --- a/src/insets/InsetGraphicsParams.h +++ b/src/insets/InsetGraphicsParams.h @@ -37,8 +37,8 @@ public: support::DocFileName filename; /// Scaling the Screen inside Lyx unsigned int lyxscale; - /// How to display the image inside LyX - graphics::DisplayType display; + /// If to display the image inside LyX + bool display; /// Scaling for output (LaTeX) std::string scale; /// sizes for output (LaTeX) diff --git a/src/insets/RenderGraphic.cpp b/src/insets/RenderGraphic.cpp index ca8008c65e..df1a93a180 100644 --- a/src/insets/RenderGraphic.cpp +++ b/src/insets/RenderGraphic.cpp @@ -67,8 +67,7 @@ namespace { bool displayGraphic(graphics::Params const & params) { - return params.display != graphics::NoDisplay && - lyxrc.display_graphics != graphics::NoDisplay; + return params.display && lyxrc.display_graphics; }