From: Enrico Forestieri Date: Thu, 12 Mar 2015 23:47:21 +0000 (+0100) Subject: Prefer svg icons. X-Git-Tag: 2.2.0alpha1~1201 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=7be2a5d815d84470078773e5329bb6c9870aeb3d;p=features.git Prefer svg icons. If a compressed svg icon is present, load it instead of a png one. Also introduce two more sizes (huge and giant icons) that should be useful when using hires displays, as svg icons automatically scale to the desired size without loss of quality. --- diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 6812a2df58..39b73cf062 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -519,11 +519,11 @@ QString iconName(FuncRequest const & f, bool unknown) search_mode mode = theGuiApp()->imageSearchMode(); for (int i = 0; i < imagedirs.size(); ++i) { QString imagedir = imagedirs.at(i) + path; - FileName fname = imageLibFileSearch(imagedir, name1, "png", mode); + FileName fname = imageLibFileSearch(imagedir, name1, "svgz,png", mode); if (fname.exists()) return toqstr(fname.absFileName()); - fname = imageLibFileSearch(imagedir, name2, "png", mode); + fname = imageLibFileSearch(imagedir, name2, "svgz,png", mode); if (fname.exists()) return toqstr(fname.absFileName()); } @@ -534,25 +534,27 @@ QString iconName(FuncRequest const & f, bool unknown) LYXERR0("Directory " << path << " not found in resource!"); return QString(); } - name1 += ".png"; - if (res.exists(name1)) - return path + name1; + if (res.exists(name1 + ".svgz")) + return path + name1 + ".svgz"; + else if (res.exists(name1 + ".png")) + return path + name1 + ".png"; - name2 += ".png"; - if (res.exists(name2)) - return path + name2; + if (res.exists(name2 + ".svgz")) + return path + name2 + ".svgz"; + else if (res.exists(name2 + ".png")) + return path + name2 + ".png"; LYXERR(Debug::GUI, "Cannot find icon with filename " - << "\"" << name1 << "\"" + << "\"" << name1 << ".{svgz,png}\"" << " or filename " - << "\"" << name2 << "\"" + << "\"" << name2 << ".{svgz,png}\"" << " for command \"" << lyxaction.getActionName(f.action()) << '(' << to_utf8(f.argument()) << ")\""); if (unknown) { QString imagedir = "images/"; - FileName fname = imageLibFileSearch(imagedir, "unknown", "png", mode); + FileName fname = imageLibFileSearch(imagedir, "unknown", "svgz,png", mode); if (fname.exists()) return toqstr(fname.absFileName()); return QString(":/images/unknown.png"); @@ -566,19 +568,23 @@ QPixmap getPixmap(QString const & path, QString const & name, QString const & ex QPixmap pixmap; QString imagedir = path; FileName fname = imageLibFileSearch(imagedir, name, ext, theGuiApp()->imageSearchMode()); - QString path1 = toqstr(fname.absFileName()); - QString path2 = ":/" + path + name + "." + ext; + QString fpath = toqstr(fname.absFileName()); - if (pixmap.load(path1)) { - return pixmap; - } - else if (pixmap.load(path2)) { + if (pixmap.load(fpath)) { return pixmap; + } else { + QStringList exts = ext.split(","); + fpath = ":/" + path + name + "."; + for (int i = 0; i < exts.size(); ++i) { + if (pixmap.load(fpath + exts.at(i))) + return pixmap; + } } + bool const list = ext.contains(","); LYXERR0("Cannot load pixmap \"" - << path << name << '.' << ext - << "\", please verify resource system!"); + << path << name << "." << (list ? "{" : "") << ext + << (list ? "}" : "") << "\", please verify resource system!"); return QPixmap(); } @@ -2400,8 +2406,8 @@ QAbstractItemModel * GuiApplication::languageModel() QStandardItemModel * lang_model = new QStandardItemModel(this); lang_model->insertColumns(0, 3); int current_row; - QIcon speller(getPixmap("images/", "dialog-show_spellchecker", "png")); - QIcon saurus(getPixmap("images/", "thesaurus-entry", "png")); + QIcon speller(getPixmap("images/", "dialog-show_spellchecker", "svgz,png")); + QIcon saurus(getPixmap("images/", "thesaurus-entry", "svgz,png")); Languages::const_iterator it = lyx::languages.begin(); Languages::const_iterator end = lyx::languages.end(); for (; it != end; ++it) { diff --git a/src/frontends/qt4/GuiCommandBuffer.cpp b/src/frontends/qt4/GuiCommandBuffer.cpp index f3179f0e84..c9ddf4a49e 100644 --- a/src/frontends/qt4/GuiCommandBuffer.cpp +++ b/src/frontends/qt4/GuiCommandBuffer.cpp @@ -88,8 +88,8 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view) transform(lyxaction.func_begin(), lyxaction.func_end(), back_inserter(commands_), firster()); - QPixmap qpup = getPixmap("images/", "up", "png"); - QPixmap qpdown = getPixmap("images/", "down", "png"); + QPixmap qpup = getPixmap("images/", "up", "svgz,png"); + QPixmap qpdown = getPixmap("images/", "down", "svgz,png"); QVBoxLayout * top = new QVBoxLayout(this); QHBoxLayout * layout = new QHBoxLayout(0); diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index 6b5170d481..15fe640a8b 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -196,10 +196,10 @@ MenuButton::MenuButton(GuiToolbar * bar, ToolbarItem const & item, bool const st imagedirs << "images/math/" << "images/"; for (int i = 0; i < imagedirs.size(); ++i) { QString imagedir = imagedirs.at(i); - FileName const fname = imageLibFileSearch(imagedir, name, "png", + FileName const fname = imageLibFileSearch(imagedir, name, "svgz,png", theGuiApp()->imageSearchMode()); if (fname.exists()) { - setIcon(QIcon(getPixmap(imagedir, name, "png"))); + setIcon(QIcon(getPixmap(imagedir, name, "svgz,png"))); break; } } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 3cf797969d..a85ccb1a89 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -157,7 +157,7 @@ public: /// The text to be written on top of the pixmap QString const text = lyx_version ? qt_("version ") + lyx_version : qt_("unknown version"); - splash_ = getPixmap("images/", "banner", "png"); + splash_ = getPixmap("images/", "banner", "svgz,png"); QPainter pain(&splash_); pain.setPen(QColor(0, 0, 0)); @@ -247,6 +247,8 @@ struct GuiView::GuiViewPrivate smallIconSize = 16; // scaling problems normalIconSize = 20; // ok, default if iconsize.png is missing bigIconSize = 26; // better for some math icons + hugeIconSize = 32; // better for hires displays + giantIconSize = 48; // if it exists, use width of iconsize.png as normal size QString const dir = toqstr(addPath("images", lyxrc.icon_set)); @@ -255,8 +257,8 @@ struct GuiView::GuiViewPrivate QImage image(toqstr(fn.absFileName())); if (image.width() < int(smallIconSize)) normalIconSize = smallIconSize; - else if (image.width() > int(bigIconSize)) - normalIconSize = bigIconSize; + else if (image.width() > int(giantIconSize)) + normalIconSize = giantIconSize; else normalIconSize = image.width(); } @@ -318,6 +320,20 @@ struct GuiView::GuiViewPrivate parent, SLOT(bigSizedIcons())); menu->addAction(bigIcons); + QAction * hugeIcons = new QAction(iconSizeGroup); + hugeIcons->setText(qt_("Huge-sized icons")); + hugeIcons->setCheckable(true); + QObject::connect(hugeIcons, SIGNAL(triggered()), + parent, SLOT(hugeSizedIcons())); + menu->addAction(hugeIcons); + + QAction * giantIcons = new QAction(iconSizeGroup); + giantIcons->setText(qt_("Giant-sized icons")); + giantIcons->setCheckable(true); + QObject::connect(giantIcons, SIGNAL(triggered()), + parent, SLOT(giantSizedIcons())); + menu->addAction(giantIcons); + unsigned int cur = parent->iconSize().width(); if ( cur == parent->d.smallIconSize) smallIcons->setChecked(true); @@ -325,6 +341,10 @@ struct GuiView::GuiViewPrivate normalIcons->setChecked(true); else if (cur == parent->d.bigIconSize) bigIcons->setChecked(true); + else if (cur == parent->d.hugeIconSize) + hugeIcons->setChecked(true); + else if (cur == parent->d.giantIconSize) + giantIcons->setChecked(true); return menu; } @@ -412,6 +432,8 @@ public: unsigned int smallIconSize; unsigned int normalIconSize; unsigned int bigIconSize; + unsigned int hugeIconSize; + unsigned int giantIconSize; /// QTimer statusbar_timer_; /// auto-saving of buffers @@ -487,9 +509,9 @@ GuiView::GuiView(int id) // assign an icon to main form. We do not do it under Qt/Win or Qt/Mac, // since the icon is provided in the application bundle. We use a themed // version when available and use the bundled one as fallback. - setWindowIcon(QIcon::fromTheme("lyx", getPixmap("images/", "lyx", "png"))); + setWindowIcon(QIcon::fromTheme("lyx", getPixmap("images/", "lyx", "svg,png"))); #else - setWindowIcon(getPixmap("images/", "lyx", "png")); + setWindowIcon(getPixmap("images/", "lyx", "svg,png")); #endif #endif @@ -673,7 +695,9 @@ bool GuiView::restoreLayout() // Check whether session size changed. if (icon_size.width() != int(d.smallIconSize) && icon_size.width() != int(d.normalIconSize) && - icon_size.width() != int(d.bigIconSize)) { + icon_size.width() != int(d.bigIconSize) && + icon_size.width() != int(d.hugeIconSize) && + icon_size.width() != int(d.giantIconSize)) { icon_size.setWidth(d.normalIconSize); icon_size.setHeight(d.normalIconSize); } @@ -1017,6 +1041,18 @@ void GuiView::bigSizedIcons() } +void GuiView::hugeSizedIcons() +{ + setIconSize(QSize(d.hugeIconSize, d.hugeIconSize)); +} + + +void GuiView::giantSizedIcons() +{ + setIconSize(QSize(d.giantIconSize, d.giantIconSize)); +} + + void GuiView::clearMessage() { // FIXME: This code was introduced in r19643 to fix bug #4123. However, diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index b10548d89e..d07f59a2b6 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -229,6 +229,8 @@ private Q_SLOTS: void smallSizedIcons(); void normalSizedIcons(); void bigSizedIcons(); + void hugeSizedIcons(); + void giantSizedIcons(); /// For completion of autosave or export threads. void processingThreadStarted(); diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index c34a9aba5d..fc1b1bd094 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -1560,7 +1560,7 @@ TabWorkArea::TabWorkArea(QWidget * parent) closeBufferButton = new QToolButton(this); closeBufferButton->setPalette(pal); // FIXME: rename the icon to closebuffer.png - closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "png"))); + closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "svgz,png"))); closeBufferButton->setText("Close File"); closeBufferButton->setAutoRaise(true); closeBufferButton->setCursor(Qt::ArrowCursor); @@ -2026,9 +2026,9 @@ void TabWorkArea::showContextMenu(const QPoint & pos) // show tab popup QMenu popup; - popup.addAction(QIcon(getPixmap("images/", "hidetab", "png")), + popup.addAction(QIcon(getPixmap("images/", "hidetab", "svgz,png")), qt_("Hide tab"), this, SLOT(hideCurrentTab())); - popup.addAction(QIcon(getPixmap("images/", "closetab", "png")), + popup.addAction(QIcon(getPixmap("images/", "closetab", "svgz,png")), qt_("Close tab"), this, SLOT(closeCurrentBuffer())); popup.exec(tabBar()->mapToGlobal(pos)); diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp index ab1a5c6f81..b2024b1199 100644 --- a/src/frontends/qt4/PanelStack.cpp +++ b/src/frontends/qt4/PanelStack.cpp @@ -75,7 +75,7 @@ PanelStack::PanelStack(QWidget * parent) #endif #if QT_VERSION >= 0x040600 - search_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "png")); + search_->setButtonPixmap(FancyLineEdit::Right, getPixmap("images/", "editclear", "svgz,png")); search_->setButtonVisible(FancyLineEdit::Right, true); search_->setButtonToolTip(FancyLineEdit::Right, qt_("Clear text")); search_->setAutoHideButton(FancyLineEdit::Right, true); diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index 83ac1bf12c..d0ea0d3030 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -52,11 +52,11 @@ TocWidget::TocWidget(GuiView & gui_view, QWidget * parent) { setupUi(this); - moveOutTB->setIcon(QIcon(getPixmap("images/", "promote", "png"))); - moveInTB->setIcon(QIcon(getPixmap("images/", "demote", "png"))); - moveUpTB->setIcon(QIcon(getPixmap("images/", "up", "png"))); - moveDownTB->setIcon(QIcon(getPixmap("images/", "down", "png"))); - updateTB->setIcon(QIcon(getPixmap("images/", "reload", "png"))); + moveOutTB->setIcon(QIcon(getPixmap("images/", "promote", "svgz,png"))); + moveInTB->setIcon(QIcon(getPixmap("images/", "demote", "svgz,png"))); + moveUpTB->setIcon(QIcon(getPixmap("images/", "up", "svgz,png"))); + moveDownTB->setIcon(QIcon(getPixmap("images/", "down", "svgz,png"))); + updateTB->setIcon(QIcon(getPixmap("images/", "reload", "svgz,png"))); // avoid flickering tocTV->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index f5cdb27751..5704aa1e11 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -292,7 +292,7 @@ FileName const fileOpenSearch(string const & path, string const & name, // Returns the real name of file name in directory path, with optional // extension ext. FileName const fileSearch(string const & path, string const & name, - string const & ext, search_mode mode) + string const & exts, search_mode mode) { // if `name' is an absolute path, we ignore the setting of `path' // Expand Environmentvariables in 'name' @@ -301,21 +301,29 @@ FileName const fileSearch(string const & path, string const & name, // search first without extension, then with it. if (fullname.isReadableFile()) return fullname; - if (ext.empty()) + if (exts.empty()) // We are done. return mode == may_not_exist ? fullname : FileName(); - // Only add the extension if it is not already the extension of - // fullname. - if (getExtension(fullname.absFileName()) != ext) { - if (mode == check_hidpi) { - FileName fullname2x = FileName(addExtension(fullname.absFileName() + "@2x", ext)); - if (fullname2x.isReadableFile()) - return fullname2x; + int n = 0; + string ext = token(exts, ',', n); + while (!ext.empty()) { + // Only add the extension if it is not already the extension of + // fullname. + bool addext = getExtension(fullname.absFileName()) != ext; + if (addext) { + if (mode == check_hidpi) { + FileName fullname2x = FileName(addExtension(fullname.absFileName() + "@2x", ext)); + if (fullname2x.isReadableFile()) + return fullname2x; + } + fullname = FileName(addExtension(fullname.absFileName(), ext)); } - fullname = FileName(addExtension(fullname.absFileName(), ext)); + if (fullname.isReadableFile() || mode == may_not_exist) + return fullname; + if (addext) + fullname.changeExtension(""); + ext = token(exts, ',', ++n); } - if (fullname.isReadableFile() || mode == may_not_exist) - return fullname; return FileName(); }