From 2b7ad272272869162dbf2489dc3285aa88488930 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 5 Mar 2008 20:48:19 +0000 Subject: [PATCH 1/1] extend the idea of the previous patch a bit... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23490 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiDocument.cpp | 34 ++++++++++++------------ src/frontends/qt4/GuiPrefs.cpp | 4 +-- src/frontends/qt4/PanelStack.cpp | 43 ++++++++++++------------------- src/frontends/qt4/PanelStack.h | 28 +++++++++----------- 4 files changed, 47 insertions(+), 62 deletions(-) diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index ab66d2685b..3106737407 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -983,22 +983,22 @@ GuiDocument::GuiDocument(GuiView & lv) connect(floatModule, SIGNAL(changed()), this, SLOT(change_adaptor())); - docPS->addPanel(latexModule, _("Document Class")); - docPS->addPanel(fontModule, _("Fonts")); - docPS->addPanel(textLayoutModule, _("Text Layout")); - docPS->addPanel(pageLayoutModule, _("Page Layout")); - docPS->addPanel(marginsModule, _("Page Margins")); - docPS->addPanel(langModule, _("Language")); - docPS->addPanel(numberingModule, _("Numbering & TOC")); - docPS->addPanel(biblioModule, _("Bibliography")); - docPS->addPanel(pdfSupportModule, _("PDF Properties")); - docPS->addPanel(mathsModule, _("Math Options")); - docPS->addPanel(floatModule, _("Float Placement")); - docPS->addPanel(bulletsModule, _("Bullets")); - docPS->addPanel(branchesModule, _("Branches")); - docPS->addPanel(embeddedFilesModule, _("Embedded Files")); - docPS->addPanel(preambleModule, _("LaTeX Preamble")); - docPS->setCurrentPanel(_("Document Class")); + docPS->addPanel(latexModule, qt_("Document Class")); + docPS->addPanel(fontModule, qt_("Fonts")); + docPS->addPanel(textLayoutModule, qt_("Text Layout")); + docPS->addPanel(pageLayoutModule, qt_("Page Layout")); + docPS->addPanel(marginsModule, qt_("Page Margins")); + docPS->addPanel(langModule, qt_("Language")); + docPS->addPanel(numberingModule, qt_("Numbering & TOC")); + docPS->addPanel(biblioModule, qt_("Bibliography")); + docPS->addPanel(pdfSupportModule, qt_("PDF Properties")); + docPS->addPanel(mathsModule, qt_("Math Options")); + docPS->addPanel(floatModule, qt_("Float Placement")); + docPS->addPanel(bulletsModule, qt_("Bullets")); + docPS->addPanel(branchesModule, qt_("Branches")); + docPS->addPanel(embeddedFilesModule, qt_("Embedded Files")); + docPS->addPanel(preambleModule, qt_("LaTeX Preamble")); + docPS->setCurrentPanel(qt_("Document Class")); // FIXME: hack to work around resizing bug in Qt >= 4.2 // bug verified with Qt 4.2.{0-3} (JSpitzm) #if QT_VERSION >= 0x040200 @@ -1009,7 +1009,7 @@ GuiDocument::GuiDocument(GuiView & lv) void GuiDocument::showPreamble() { - docPS->setCurrentPanel(_("LaTeX Preamble")); + docPS->setCurrentPanel(qt_("LaTeX Preamble")); } diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 66614a61dd..e35e8cc7a1 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -2240,7 +2240,7 @@ GuiPreferences::GuiPreferences(GuiView & lv) add(converters); add(formats); - prefsPS->setCurrentPanel(_("User interface")); + prefsPS->setCurrentPanel(qt_("User interface")); // FIXME: hack to work around resizing bug in Qt >= 4.2 // bug verified with Qt 4.2.{0-3} (JSpitzm) #if QT_VERSION >= 0x040200 @@ -2258,7 +2258,7 @@ GuiPreferences::GuiPreferences(GuiView & lv) void GuiPreferences::add(PrefModule * module) { BOOST_ASSERT(module); - prefsPS->addPanel(module, module->title()); + prefsPS->addPanel(module, toqstr(module->title())); connect(module, SIGNAL(changed()), this, SLOT(change_adaptor())); modules_.push_back(module); } diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp index feb80b78be..eae495878a 100644 --- a/src/frontends/qt4/PanelStack.cpp +++ b/src/frontends/qt4/PanelStack.cpp @@ -55,34 +55,27 @@ PanelStack::PanelStack(QWidget * parent) } -void PanelStack::addCategory(docstring const & n, docstring const & parent) +void PanelStack::addCategory(QString const & name, QString const & parent) { QTreeWidgetItem * item = 0; - QString const name = toqstr(n); - LYXERR(Debug::GUI, "addCategory n= " << to_utf8(n) << " parent= "); + LYXERR(Debug::GUI, "addCategory n= " << fromqstr(name) << " parent= "); int depth = 1; - if (parent.empty()) { + if (parent.isEmpty()) { item = new QTreeWidgetItem(list_); item->setText(0, name); } else { - PanelMap::iterator it = panel_map_.find(parent); - //BOOST_ASSERT(it != panel_map_.end()); - if (it == panel_map_.end()) { + if (!panel_map_.contains(parent)) addCategory(parent); - it = panel_map_.find(parent); - } - BOOST_ASSERT(it != panel_map_.end()); - - item = new QTreeWidgetItem(it->second); + item = new QTreeWidgetItem(panel_map_.value(parent)); item->setText(0, name); depth = 2; } - panel_map_[n] = item; + panel_map_[name] = item; QFontMetrics fm(list_->font()); // calculate the real size the current item needs in the listview @@ -94,38 +87,34 @@ void PanelStack::addCategory(docstring const & n, docstring const & parent) } -void PanelStack::addPanel(QWidget * panel, docstring const & name, docstring const & parent) +void PanelStack::addPanel(QWidget * panel, QString const & name, QString const & parent) { addCategory(name, parent); - QTreeWidgetItem * item = panel_map_.find(name)->second; - + QTreeWidgetItem * item = panel_map_.value(name); widget_map_[item] = panel; stack_->addWidget(panel); stack_->setMinimumSize(panel->minimumSize()); } -void PanelStack::setCurrentPanel(docstring const & name) +void PanelStack::setCurrentPanel(QString const & name) { - PanelMap::const_iterator cit = panel_map_.find(name); - BOOST_ASSERT(cit != panel_map_.end()); + QTreeWidgetItem * item = panel_map_.value(name, 0); + BOOST_ASSERT(item); // force on first set - if (list_->currentItem() == cit->second) - switchPanel(cit->second); + if (list_->currentItem() == item) + switchPanel(item); - list_->setCurrentItem(cit->second); + list_->setCurrentItem(item); } void PanelStack::switchPanel(QTreeWidgetItem * item, QTreeWidgetItem * /*previous*/) { - WidgetMap::const_iterator cit = widget_map_.find(item); - if (cit == widget_map_.end()) - return; - - stack_->setCurrentWidget(cit->second); + if (QWidget * w = widget_map_.value(item, 0)) + stack_->setCurrentWidget(w); } diff --git a/src/frontends/qt4/PanelStack.h b/src/frontends/qt4/PanelStack.h index 1e38043b95..45ca24bb25 100644 --- a/src/frontends/qt4/PanelStack.h +++ b/src/frontends/qt4/PanelStack.h @@ -12,11 +12,8 @@ #ifndef PANELSTACK_H #define PANELSTACK_H -#include "support/docstring.h" - #include - -#include +#include class QTreeWidget; class QTreeWidgetItem; @@ -30,31 +27,30 @@ class PanelStack : public QWidget { Q_OBJECT public: + /// PanelStack(QWidget * parent = 0); /// add a category with no associated panel - void addCategory(docstring const & name, - docstring const & parent = docstring()); - + void addCategory(QString const & name, QString const & parent = QString()); /// add a widget panel with a given name, under the given parent - void addPanel(QWidget * panel, docstring const & name, - docstring const & parent = docstring()); - + void addPanel(QWidget * panel, QString const & name, + QString const & parent = QString()); /// set current panel by logical name - void setCurrentPanel(docstring const &); - - virtual QSize sizeHint() const; + void setCurrentPanel(QString const &); + /// + QSize sizeHint() const; public Q_SLOTS: /// set current panel from an item void switchPanel(QTreeWidgetItem * it, QTreeWidgetItem * previous = 0); private: - typedef std::map PanelMap; - + /// + typedef QHash PanelMap; + /// PanelMap panel_map_; - typedef std::map WidgetMap; + typedef QHash WidgetMap; WidgetMap widget_map_; -- 2.39.2