From 5806be152841337f91f6a0500f7e07588e02ab3b Mon Sep 17 00:00:00 2001 From: Pavel Sanda Date: Fri, 3 Apr 2009 17:00:09 +0000 Subject: [PATCH] Fix bug http://www.lyx.org/trac/ticket/5812 (Icons replacement broken) Patch from Martin Engbers. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29057 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiApplication.cpp | 26 +++++++++++++++++++++++++- src/frontends/qt4/GuiApplication.h | 4 ++++ src/frontends/qt4/GuiCommandBuffer.cpp | 5 +++-- src/frontends/qt4/GuiToolbar.cpp | 2 +- src/frontends/qt4/GuiView.cpp | 4 ++-- src/frontends/qt4/GuiWorkArea.cpp | 6 +++--- src/frontends/qt4/TocWidget.cpp | 11 ++++++----- src/insets/InsetBranch.cpp | 10 ++++++++-- 8 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 9f2d37c67e..3b60972850 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -362,12 +362,36 @@ QString iconName(FuncRequest const & f, bool unknown) << lyxaction.getActionName(f.action) << '(' << to_utf8(f.argument()) << ")\""); - if (unknown) + if (unknown) { + fname = libFileSearch("images/", "unknown", "png"); + if (fname.exists()) + return toqstr(fname.absFilename()); return QString(":/images/unknown.png"); + } return QString(); } +QPixmap getPixmap(QString const & path, QString const & name, QString const & ext) +{ + QPixmap pixmap; + FileName fname = libFileSearch(path, name, ext); + QString path1 = toqstr(fname.absFilename()); + QString path2 = ":/" + path + name + "." + ext; + + if (pixmap.load(path1)) { + return pixmap; + } + else if (pixmap.load(path2)) { + return pixmap; + } + + LYXERR0("Cannot load pixmap \"" + << path << name << '.' << ext + << "\", please verify resource system!"); + + return QPixmap(); +} QIcon getIcon(FuncRequest const & f, bool unknown) { diff --git a/src/frontends/qt4/GuiApplication.h b/src/frontends/qt4/GuiApplication.h index 086a8322cd..b4236905ab 100644 --- a/src/frontends/qt4/GuiApplication.h +++ b/src/frontends/qt4/GuiApplication.h @@ -159,6 +159,10 @@ extern GuiApplication * guiApp; /// \return the icon file name for the given action. QString iconName(FuncRequest const & f, bool unknown); + +/// \return the pixmap for the given path, name and extension. +QPixmap getPixmap(QString const & path, QString const & name, QString const & ext); + /// \return an icon for the given action. QIcon getIcon(FuncRequest const & f, bool unknown); diff --git a/src/frontends/qt4/GuiCommandBuffer.cpp b/src/frontends/qt4/GuiCommandBuffer.cpp index 5f48010d76..d3d0487f04 100644 --- a/src/frontends/qt4/GuiCommandBuffer.cpp +++ b/src/frontends/qt4/GuiCommandBuffer.cpp @@ -14,6 +14,7 @@ #include "GuiCommandBuffer.h" +#include "GuiApplication.h" #include "GuiCommandEdit.h" #include "GuiView.h" #include "qt_helpers.h" @@ -87,8 +88,8 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view) transform(lyxaction.func_begin(), lyxaction.func_end(), back_inserter(commands_), firster()); - QPixmap qpup(":/images/up.png"); - QPixmap qpdown(":/images/down.png"); + QPixmap qpup = getPixmap("images/", "up", "png"); + QPixmap qpdown = getPixmap("images/", "down", "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 5dc66b6aa5..762cf6909e 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -805,7 +805,7 @@ public: setToolTip(label); setStatusTip(label); setText(label); - setIcon(QPixmap(":images/math/" + toqstr(tbitem_.name_) + ".png")); + setIcon(QIcon(getPixmap("images/math/", toqstr(tbitem_.name_), "png"))); connect(bar, SIGNAL(iconSizeChanged(QSize)), this, SLOT(setIconSize(QSize))); } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 867aa0e2fb..0def99acee 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -117,7 +117,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_ = QPixmap(":/images/banner.png"); + splash_ = getPixmap("images/", "banner", "png"); QPainter pain(&splash_); pain.setPen(QColor(0, 0, 0)); @@ -315,7 +315,7 @@ GuiView::GuiView(int id) #if (!defined(Q_WS_WIN) && !defined(Q_WS_MACX)) // 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. - setWindowIcon(QPixmap(":/images/lyx.png")); + setWindowIcon(getPixmap("images/", "lyx", "png")); #endif // For Drag&Drop. diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 3823401325..29789c7a25 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -1320,7 +1320,7 @@ TabWorkArea::TabWorkArea(QWidget * parent) closeBufferButton = new QToolButton(this); closeBufferButton->setPalette(pal); // FIXME: rename the icon to closebuffer.png - closeBufferButton->setIcon(QIcon(":/images/closetab.png")); + closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "png"))); closeBufferButton->setText("Close File"); closeBufferButton->setAutoRaise(true); closeBufferButton->setCursor(Qt::ArrowCursor); @@ -1721,9 +1721,9 @@ void TabWorkArea::showContextMenu(const QPoint & pos) // show tab popup QMenu popup; - popup.addAction(QIcon(":/images/hidetab.png"), + popup.addAction(QIcon(getPixmap("images/", "hidetab", "png")), qt_("Hide tab"), this, SLOT(closeCurrentTab())); - popup.addAction(QIcon(":/images/closetab.png"), + popup.addAction(QIcon(getPixmap("images/", "closetab", "png")), qt_("Close tab"), this, SLOT(closeCurrentBuffer())); popup.exec(tabBar()->mapToGlobal(pos)); diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index d3c12936d8..d9de4b6273 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -13,6 +13,7 @@ #include "TocWidget.h" +#include "GuiApplication.h" #include "GuiView.h" #include "qt_helpers.h" #include "TocModel.h" @@ -39,11 +40,11 @@ TocWidget::TocWidget(GuiView & gui_view, QWidget * parent) { setupUi(this); - moveOutTB->setIcon(QIcon(":/images/promote.png")); - moveInTB->setIcon(QIcon(":/images/demote.png")); - moveUpTB->setIcon(QIcon(":/images/up.png")); - moveDownTB->setIcon(QIcon(":/images/down.png")); - updateTB->setIcon(QIcon(":/images/reload.png")); + 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"))); // avoid flickering tocTV->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 45e4ebe72f..50a3147b81 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -205,8 +205,14 @@ bool InsetBranch::isBranchSelected() const Buffer const & realbuffer = *buffer().masterBuffer(); BranchList const & branchlist = realbuffer.params().branchlist(); Branch const * ourBranch = branchlist.find(params_.branch); - if (!ourBranch) - return false; + // this branch is defined in child only + if (!ourBranch) { + ourBranch = buffer().params().branchlist().find(params_.branch); + if (ourBranch) + return ourBranch->isSelected(); + else + return false; + } return ourBranch->isSelected(); } -- 2.39.5