]> git.lyx.org Git - features.git/commitdiff
cleanup GuiLayoutBox.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 1 Oct 2007 21:26:25 +0000 (21:26 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 1 Oct 2007 21:26:25 +0000 (21:26 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20646 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/GuiToolbar.h
src/frontends/qt4/GuiToolbars.cpp

index f687ad4facc3b1d1b756811b74d2c0018cd2319f..76ea3efcd043472eacd0478f602bc18c4f1adb67 100644 (file)
@@ -66,19 +66,16 @@ static TextClass const & textClass(LyXView const & lv)
 //
 /////////////////////////////////////////////////////////////////////
 
-GuiLayoutBox::GuiLayoutBox(QToolBar * toolbar, GuiViewBase & owner)
+GuiLayoutBox::GuiLayoutBox(GuiViewBase & owner)
        : owner_(owner)
 {
-       combo_ = new QComboBox;
-       combo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
-       combo_->setFocusPolicy(Qt::ClickFocus);
-       combo_->setMinimumWidth(combo_->sizeHint().width());
-       combo_->setMaxVisibleItems(100);
+       setSizeAdjustPolicy(QComboBox::AdjustToContents);
+       setFocusPolicy(Qt::ClickFocus);
+       setMinimumWidth(sizeHint().width());
+       setMaxVisibleItems(100);
 
-       QObject::connect(combo_, SIGNAL(activated(QString)),
+       QObject::connect(this, SIGNAL(activated(QString)),
                         this, SLOT(selected(QString)));
-
-       toolbar->addWidget(combo_);
 }
 
 
@@ -89,18 +86,18 @@ void GuiLayoutBox::set(docstring const & layout)
        QString const & name = toqstr(translateIfPossible(tc[layout]->name()));
 
        int i = 0;
-       for (; i < combo_->count(); ++i) {
-               if (name == combo_->itemText(i))
+       for (; i < count(); ++i) {
+               if (name == itemText(i))
                        break;
        }
 
-       if (i == combo_->count()) {
+       if (i == count()) {
                lyxerr << "Trying to select non existent layout type "
                        << fromqstr(name) << endl;
                return;
        }
 
-       combo_->setCurrentIndex(i);
+       setCurrentIndex(i);
 }
 
 
@@ -108,45 +105,23 @@ void GuiLayoutBox::updateContents()
 {
        TextClass const & tc = textClass(owner_);
 
-       combo_->setUpdatesEnabled(false);
-       combo_->clear();
+       setUpdatesEnabled(false);
+       clear();
 
        TextClass::const_iterator it = tc.begin();
        TextClass::const_iterator const end = tc.end();
        for (; it != end; ++it) {
                // ignore obsolete entries
                if ((*it)->obsoleted_by().empty())
-                       combo_->addItem(toqstr(translateIfPossible((*it)->name())));
+                       addItem(toqstr(translateIfPossible((*it)->name())));
        }
 
        // needed to recalculate size hint
-       combo_->hide();
-       combo_->setMinimumWidth(combo_->sizeHint().width());
-       combo_->show();
-
-       combo_->setUpdatesEnabled(true);
-       combo_->update();
-}
-
-
-void GuiLayoutBox::clear()
-{
-       combo_->clear();
-}
+       hide();
+       setMinimumWidth(sizeHint().width());
+       show();
 
-
-void GuiLayoutBox::open()
-{
-       combo_->showPopup();
-}
-
-
-void GuiLayoutBox::setEnabled(bool enable)
-{
-       // Workaround for Qt bug where setEnabled(true) closes
-       // the popup
-       if (enable != combo_->isEnabled())
-               combo_->setEnabled(enable);
+       setUpdatesEnabled(true);
 }
 
 
@@ -220,7 +195,8 @@ void GuiToolbar::add(ToolbarItem const & item)
                addSeparator();
                break;
        case ToolbarItem::LAYOUTS:
-               layout_ = new GuiLayoutBox(this, owner_);
+               layout_ = new GuiLayoutBox(owner_);
+               addWidget(layout_);
                break;
        case ToolbarItem::MINIBUFFER:
                command_buffer_ = new GuiCommandBuffer(&owner_);
index eb0869b0f44990bd09ef715d4f4a96d0271362dc..a28c0a0c55b4ba8ff7ae1172acb54662dcfbc78d 100644 (file)
@@ -36,28 +36,21 @@ class GuiViewBase;
 class Action;
 
 
-class GuiLayoutBox : public QObject
+class GuiLayoutBox : public QComboBox
 {
        Q_OBJECT
 public:
-       GuiLayoutBox(QToolBar *, GuiViewBase &);
+       GuiLayoutBox(GuiViewBase &);
 
        /// select the right layout in the combobox.
        void set(docstring const & layout);
        /// Populate the layout combox.
        void updateContents();
-       /// Erase the layout list.
-       void clear();
-       /// Display the layout list.
-       void open();
-       /// Set the activation status of the combox.
-       void setEnabled(bool);
 
 private Q_SLOTS:
        void selected(const QString & str);
 
 private:
-       QComboBox * combo_;
        GuiViewBase & owner_;
 };
 
index c92f4cf27f9b0d2ab64f3ab70d2f17e47b33ffd8..0f8653d8ba684c72fb1de42a10455fb52251597a 100644 (file)
@@ -108,7 +108,7 @@ bool GuiToolbars::updateLayoutList(TextClassPtr textclass)
 void GuiToolbars::openLayoutList()
 {
        if (layout_)
-               layout_->open();
+               layout_->showPopup();
 }