> > Andre'? Is there a way to obtain this feature in Qt?
> 
> From a theoretical point of view there is 
> 
>   void QComboBox::setItemDelegate(QAbstractItemDelegate *)
> 
> which in turn has
> 
>   void paint(QPainter * painter, const QStyleOptionViewItem & option,
>     const QModelIndex & index) const;
> 
> So you could draw whatever you want if, say index.row() == 5.
> 
> From a practical point of view I never tried it.

below is the patch polished according to the comments and i consider
it to be the fix for 2739.

i dropped on-top feature and will look on the suggestion above
later and as separate issue. what do you think ?

pavel
Index: src/LyXRC.h
===================================================================
--- src/LyXRC.h (revision 21005)
+++ src/LyXRC.h (working copy)
@@ -80,6 +80,7 @@
                RC_LANGUAGE_GLOBAL_OPTIONS,
                RC_LANGUAGE_PACKAGE,
                RC_LANGUAGE_USE_BABEL,
+               RC_LAYOUTS_SORTED,
                RC_USELASTFILEPOS,
                RC_LOADSESSION,
                RC_MAKE_BACKUP,
@@ -370,6 +371,8 @@
        bool use_converter_cache;
        /// The maximum age of cache files in seconds
        unsigned int converter_cache_maxage;
+       /// Sort layouts alphabetically
+       bool layouts_sorted;
 };
 
 
Index: src/frontends/LyXView.h
===================================================================
--- src/frontends/LyXView.h     (revision 21005)
+++ src/frontends/LyXView.h     (working copy)
@@ -141,7 +141,7 @@
        void setBuffer(Buffer * b); ///< \c Buffer to set.
 
        /// updates the possible layouts selectable
-       virtual void updateLayoutChoice() = 0;
+       virtual void updateLayoutChoice(bool force) = 0;
 
        /// update the toolbar
        virtual void updateToolbars() = 0;
Index: src/frontends/qt4/GuiToolbar.h
===================================================================
--- src/frontends/qt4/GuiToolbar.h      (revision 21005)
+++ src/frontends/qt4/GuiToolbar.h      (working copy)
@@ -43,6 +43,8 @@
        void set(docstring const & layout);
        /// Populate the layout combobox.
        void updateContents();
+       /// Add Item to Layout box according to sorting settings from 
preferences
+       void addSortItem(QString const & item, bool sorted);
 
 private Q_SLOTS:
        void selected(const QString & str);
Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (revision 21005)
+++ src/frontends/qt4/GuiView.h (working copy)
@@ -76,7 +76,7 @@
        void showMiniBuffer(bool);
        void openMenu(docstring const &);
        void openLayoutList();
-       void updateLayoutChoice();
+       void updateLayoutChoice(bool force);
        bool isToolbarVisible(std::string const & id);
        void updateToolbars();
        ToolbarInfo * getToolbarInfo(std::string const & name);
Index: src/frontends/qt4/GuiToolbars.cpp
===================================================================
--- src/frontends/qt4/GuiToolbars.cpp   (revision 21005)
+++ src/frontends/qt4/GuiToolbars.cpp   (working copy)
@@ -291,10 +291,10 @@
 }
 
 
-bool GuiToolbars::updateLayoutList(TextClassPtr textclass)
+bool GuiToolbars::updateLayoutList(TextClassPtr textclass, bool force)
 {
        // update the layout display
-       if (last_textclass_ != textclass) {
+       if (last_textclass_ != textclass || force) {
                if (layout_)
                        layout_->updateContents();
                last_textclass_ = textclass;
Index: src/frontends/qt4/GuiToolbar.cpp
===================================================================
--- src/frontends/qt4/GuiToolbar.cpp    (revision 21005)
+++ src/frontends/qt4/GuiToolbar.cpp    (working copy)
@@ -32,6 +32,7 @@
 #include "Action.h"
 #include "qt_helpers.h"
 #include "InsertTableWidget.h"
+#include "LyXRC.h"
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
@@ -250,6 +251,28 @@
 }
 
 
+void GuiLayoutBox::addSortItem(QString const & item, bool sorted)
+{
+       int end = count();
+       int i = 1;      //Let Standard be at the beginning
+
+       if (!sorted || end<2 || !(item[0].category() == 
QChar::Letter_Uppercase)) {
+               addItem(item);
+               return;
+       }
+
+       for (setCurrentIndex(i); currentText() < item; ) {
+               if (! (currentText()[0].category() == QChar::Letter_Uppercase))
+                       break;  //e.g.--Separator--
+               if (++i == end)
+                       break;
+               setCurrentIndex(i);
+       }
+
+       insertItem(i, item);
+}
+
+
 void GuiLayoutBox::updateContents()
 {
        TextClass const & tc = textClass(owner_);
@@ -262,8 +285,10 @@
        for (; it != end; ++it) {
                // ignore obsolete entries
                if ((*it)->obsoleted_by().empty())
-                       addItem(toqstr(translateIfPossible((*it)->name())));
+                       addSortItem(toqstr(translateIfPossible((*it)->name())), 
lyxrc.layouts_sorted);
        }
+       //set standard as default
+       setCurrentIndex(0);
 
        // needed to recalculate size hint
        hide();
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp       (revision 21005)
+++ src/frontends/qt4/GuiView.cpp       (working copy)
@@ -618,7 +618,7 @@
        // require bv_->text.
        getDialogs().updateBufferDependent(true);
        updateToolbars();
-       updateLayoutChoice();
+       updateLayoutChoice(false);
        updateWindowTitle();
        updateStatusBar();
 }
@@ -895,7 +895,7 @@
 }
 
 
-void GuiViewBase::updateLayoutChoice()
+void GuiViewBase::updateLayoutChoice(bool force)
 {
        // Don't show any layouts without a buffer
        if (!buffer()) {
@@ -904,7 +904,7 @@
        }
 
        // Update the layout display
-       if 
(d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr())) {
+       if 
(d.toolbars_->updateLayoutList(buffer()->params().getTextClassPtr(),force)) {
                d.current_layout = 
buffer()->params().getTextClass().defaultLayoutName();
        }
 
Index: src/frontends/qt4/GuiWorkArea.cpp
===================================================================
--- src/frontends/qt4/GuiWorkArea.cpp   (revision 21005)
+++ src/frontends/qt4/GuiWorkArea.cpp   (working copy)
@@ -259,7 +259,7 @@
 
        if (lyxrc.cursor_follows_scrollbar) {
                buffer_view_->setCursorFromScrollbar();
-               lyx_view_->updateLayoutChoice();
+               lyx_view_->updateLayoutChoice(false);
        }
        // Show the cursor immediately after any operation.
        startBlinkingCursor();
Index: src/frontends/qt4/GuiToolbars.h
===================================================================
--- src/frontends/qt4/GuiToolbars.h     (revision 21005)
+++ src/frontends/qt4/GuiToolbars.h     (working copy)
@@ -63,7 +63,7 @@
        /** Populate the layout combox - returns whether we did a full
         *  update or not
         */
-       bool updateLayoutList(TextClassPtr textclass);
+       bool updateLayoutList(TextClassPtr textclass, bool force);
 
        /// Drop down the layout list.
        void openLayoutList();
Index: src/frontends/qt4/GuiPrefs.cpp
===================================================================
--- src/frontends/qt4/GuiPrefs.cpp      (revision 21005)
+++ src/frontends/qt4/GuiPrefs.cpp      (working copy)
@@ -1605,6 +1605,8 @@
                this, SIGNAL(changed()));
        connect(cursorFollowsCB, SIGNAL(clicked()),
                this, SIGNAL(changed()));
+       connect(sortEnvironmentsCB, SIGNAL(clicked()),
+               this, SIGNAL(changed()));
        connect(autoSaveSB, SIGNAL(valueChanged(int)),
                this, SIGNAL(changed()));
        connect(autoSaveCB, SIGNAL(clicked()),
@@ -1629,6 +1631,7 @@
        }
        rc.geometry_xysaved = loadWindowLocationCB->isChecked();
        rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
+       rc.layouts_sorted = sortEnvironmentsCB->isChecked();
        rc.autosave = autoSaveSB->value() * 60;
        rc.make_backup = autoSaveCB->isChecked();
        rc.num_lastfiles = lastfilesSB->value();
@@ -1648,6 +1651,7 @@
        }
        loadWindowLocationCB->setChecked(rc.geometry_xysaved);
        cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
+       sortEnvironmentsCB->setChecked(rc.layouts_sorted);
        // convert to minutes
        int mins(rc.autosave / 60);
        if (rc.autosave && !mins)
Index: src/frontends/qt4/ui/PrefUi.ui
===================================================================
--- src/frontends/qt4/ui/PrefUi.ui      (revision 21005)
+++ src/frontends/qt4/ui/PrefUi.ui      (working copy)
@@ -6,13 +6,13 @@
     <x>0</x>
     <y>0</y>
     <width>398</width>
-    <height>418</height>
+    <height>492</height>
    </rect>
   </property>
   <property name="sizePolicy" >
    <sizepolicy>
-    <hsizetype>1</hsizetype>
-    <vsizetype>1</vsizetype>
+    <hsizetype>0</hsizetype>
+    <vsizetype>0</vsizetype>
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
@@ -43,7 +43,7 @@
    <item row="4" column="0" colspan="3" >
     <widget class="QGroupBox" name="scrollGB" >
      <property name="title" >
-      <string>Scrolling</string>
+      <string>Editing options</string>
      </property>
      <property name="alignment" >
       <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
@@ -65,6 +65,16 @@
         </property>
        </widget>
       </item>
+      <item row="1" column="0" >
+       <widget class="QCheckBox" name="sortEnvironmentsCB" >
+        <property name="toolTip" >
+         <string>Alphabetically</string>
+        </property>
+        <property name="text" >
+         <string>&amp;Sort Environments alphabetically</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
@@ -187,8 +197,8 @@
     <widget class="QGroupBox" name="GeometryGB" >
      <property name="sizePolicy" >
       <sizepolicy>
-       <hsizetype>5</hsizetype>
-       <vsizetype>5</vsizetype>
+       <hsizetype>0</hsizetype>
+       <vsizetype>0</vsizetype>
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
Index: src/frontends/WorkArea.cpp
===================================================================
--- src/frontends/WorkArea.cpp  (revision 21005)
+++ src/frontends/WorkArea.cpp  (working copy)
@@ -207,7 +207,7 @@
 
        // Skip these when selecting
        if (cmd.action != LFUN_MOUSE_MOTION) {
-               lyx_view_->updateLayoutChoice();
+               lyx_view_->updateLayoutChoice(false);
                lyx_view_->updateToolbars();
        }
 
@@ -231,7 +231,7 @@
        // We are already inside a paint event.
        lyx_view_->busy(true);
        buffer_view_->resize(width(), height());
-       lyx_view_->updateLayoutChoice();
+       lyx_view_->updateLayoutChoice(false);
        lyx_view_->busy(false);
 }
 
Index: src/LyXFunc.cpp
===================================================================
--- src/LyXFunc.cpp     (revision 21005)
+++ src/LyXFunc.cpp     (working copy)
@@ -1879,6 +1879,9 @@
 
                        actOnUpdatedPrefs(lyxrc_orig, lyxrc);
 
+                       if (lyx_view_ && lyx_view_->buffer())
+                               lyx_view_->updateLayoutChoice(true);
+
                        /// We force the redraw in any case because there might 
be
                        /// some screen font changes.
                        /// FIXME: only the current view will be updated. the 
Gui
@@ -1964,7 +1967,7 @@
                        
theSelection().haveSelection(view()->cursor().selection());
 
                        if (view()->cursor().inTexted()) {
-                               lyx_view_->updateLayoutChoice();
+                               lyx_view_->updateLayoutChoice(false);
                        }
                }
        }
@@ -2455,6 +2458,7 @@
        case LyXRC::RC_USE_PERS_DICT:
        case LyXRC::RC_USE_SPELL_LIB:
        case LyXRC::RC_VIEWDVI_PAPEROPTION:
+       case LyXRC::RC_LAYOUTS_SORTED:
        case LyXRC::RC_VIEWER:
        case LyXRC::RC_LAST:
                break;
Index: src/LyXRC.cpp
===================================================================
--- src/LyXRC.cpp       (revision 21005)
+++ src/LyXRC.cpp       (working copy)
@@ -106,6 +106,7 @@
        { "\\language_global_options", LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS },
        { "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE },
        { "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL },
+       { "\\layouts_sorted", LyXRC::RC_LAYOUTS_SORTED },
        { "\\load_session", LyXRC::RC_LOADSESSION },
        { "\\make_backup", LyXRC::RC_MAKE_BACKUP },
        { "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE },
@@ -266,6 +267,7 @@
        language_package = "\\usepackage{babel}";
        language_command_begin = "\\selectlanguage{$$lang}";
        language_command_local = "\\foreignlanguage{$$lang}{";
+       layouts_sorted = false;
        default_language = "english";
        show_banner = true;
        windows_style_tex_paths = false;
@@ -1163,6 +1165,11 @@
                                        convert<unsigned 
int>(lexrc.getString());
                        break;
 
+               case RC_LAYOUTS_SORTED:
+                       if (lexrc.next())
+                               layouts_sorted = lexrc.getBool();
+                       break;
+
                case RC_LAST: break; // this is just a dummy
                }
        }
@@ -1315,7 +1322,14 @@
                }
                if (tag != RC_LAST)
                        break;
-
+       case RC_LAYOUTS_SORTED:
+               if (ignore_system_lyxrc ||
+                   layouts_sorted != system_lyxrc.layouts_sorted) {
+                       os << "# Sort layouts alphabetically.\n"
+                          << "\\layouts_sorted " << 
convert<string>(layouts_sorted) << '\n';
+               }
+               if (tag != RC_LAST)
+                       break;
        case RC_VIEWDVI_PAPEROPTION:
                if (ignore_system_lyxrc ||
                    view_dvi_paper_option

Reply via email to