]> git.lyx.org Git - features.git/commitdiff
Prefer svg icons.
authorEnrico Forestieri <forenr@lyx.org>
Thu, 12 Mar 2015 23:47:21 +0000 (00:47 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Thu, 12 Mar 2015 23:47:21 +0000 (00:47 +0100)
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.

src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiCommandBuffer.cpp
src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/PanelStack.cpp
src/frontends/qt4/TocWidget.cpp
src/support/filetools.cpp

index 6812a2df58917bd305cf0b3ac15ce05b5fff1f08..39b73cf062060e6eb8f1e7e5ff347341885e73a4 100644 (file)
@@ -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) {
index f3179f0e84694f8ab145d16bd8af028026915ea5..c9ddf4a49ea539d5aab70582facda99737a5c1fe 100644 (file)
@@ -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);
index 6b5170d481974484e387c7c76c0b5c4274633685..15fe640a8b524ab5c827e4979860b5f0af51dedb 100644 (file)
@@ -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;
                }
        }
index 3cf797969d56b9de6e3f45bbb9f9a722aaeb7cfe..a85ccb1a8931e2b9a0eba4252a975bf2b4a7bc23 100644 (file)
@@ -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,
index b10548d89eb78f9ed78b12a5a12d759f1d960c94..d07f59a2b68f4d2b0f63b72faa087ddeb6e1fcb1 100644 (file)
@@ -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();
index c34a9aba5ddee49ab1b359ae601646874661e79b..fc1b1bd0946766b265551aea2b61f880938e5556 100644 (file)
@@ -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));
 
index ab1a5c6f817601f04d30a5af577c7602572b1217..b2024b11998a92d972b5d6bc2ac11a7586c83a24 100644 (file)
@@ -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);
index 83ac1bf12c2e3202860a463c951372dd4a3da701..d0ea0d30309d160eb0e880bf01faa574ec6ea689 100644 (file)
@@ -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);
index f5cdb277515714ba5c1a3a8791e8afe5461c4146..5704aa1e1106a4bc91165db18d6e5e2d46ed38f1 100644 (file)
@@ -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();
 }