]> git.lyx.org Git - features.git/commitdiff
Fix item delegate for qt 4.2:
authorBernhard Roider <bernhard.roider@sonnenkinder.org>
Tue, 3 Jun 2008 22:00:47 +0000 (22:00 +0000)
committerBernhard Roider <bernhard.roider@sonnenkinder.org>
Tue, 3 Jun 2008 22:00:47 +0000 (22:00 +0000)
In the completion-listbox rtl-Text does not work like it does for newer qt and icons are not displayed for math symbols.
The rtl handling is incorrect atm but now it works the same way for all versions of qt.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25108 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiCompleter.cpp
src/frontends/qt4/GuiCompleter.h

index 1ce5c8fa1c92a1264367c6c3e220d35aa42a5c46..386f019575fb869a3dd3102473509880dae4e09c 100644 (file)
@@ -43,13 +43,16 @@ using namespace lyx::support;
 namespace lyx {
 namespace frontend {
 
-class RtlItemDelegate : public QItemDelegate
+class CompleterItemDelegate : public QItemDelegate
 {
 public:
-       explicit RtlItemDelegate(QObject * parent)
+       explicit CompleterItemDelegate(QObject * parent)
                : QItemDelegate(parent), enabled_(false)
        {}
 
+       ~CompleterItemDelegate()
+       {}
+
        void setEnabled(bool enabled = true)
        {
                enabled_ = enabled;
@@ -70,23 +73,14 @@ protected:
                reverse(stltext.begin(), stltext.end());
                QItemDelegate::drawDisplay(painter, option, rect, toqstr(stltext));
        }
-       
-private:
-       bool enabled_;
-};
-
-
-class PixmapItemDelegate : public QItemDelegate
-{
-public:
-       explicit PixmapItemDelegate(QObject * parent)
-               : QItemDelegate(parent)
-       {}
 
-protected:
        void paint(QPainter *painter, const QStyleOptionViewItem &option,
                   const QModelIndex &index) const
        {
+               if (index.column() == 0) {
+                       QItemDelegate::paint(painter, option, index);
+                       return;
+               }
                QStyleOptionViewItem opt = setOptions(index, option);
                QVariant value = index.data(Qt::DisplayRole);
                QPixmap pixmap = qvariant_cast<QPixmap>(value);
@@ -103,8 +97,10 @@ protected:
                drawFocus(painter, opt, option.rect);
                painter->restore();
        }
-};
 
+private:
+       bool enabled_;
+};
 
 class GuiCompletionModel : public QAbstractListModel
 {
@@ -116,6 +112,12 @@ public:
        ///
        ~GuiCompletionModel() { delete list_; }
        ///
+       void setList(CompletionList const * l) {
+               delete list_;
+               list_ = l;
+               reset();
+       }
+       ///
        bool sorted() const
        {
                if (list_)
@@ -183,7 +185,8 @@ GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
          modelActive_(false)
 {
        // Setup the completion popup
-       setModel(new GuiCompletionModel(this, 0));
+       model_ = new GuiCompletionModel(this, 0);
+       setModel(model_);
        setCompletionMode(QCompleter::PopupCompletion);
        setWidget(gui_);
        
@@ -198,9 +201,8 @@ GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
        listView->setUniformRowHeights(true);
        setPopup(listView);
        
-       rtlItemDelegate_ = new RtlItemDelegate(this);
-       popup()->setItemDelegateForColumn(0, rtlItemDelegate_);
-       popup()->setItemDelegateForColumn(1, new PixmapItemDelegate(this));
+       itemDelegate_ = new CompleterItemDelegate(this);
+       popup()->setItemDelegate(itemDelegate_);
        
        // create timeout timers
        popup_timer_.setSingleShot(true);
@@ -484,11 +486,11 @@ void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate
 
        // turn the direction of the strings in the popup.
        // Qt does not do that itself.
-       rtlItemDelegate_->setEnabled(rtl);
+       itemDelegate_->setEnabled(rtl);
 
        // set new model
        CompletionList const * list = cur.inset().createCompletionList(cur);
-       setModel(new GuiCompletionModel(this, list));
+       model_->setList(list);
        modelActive_ = true;
        if (list->sorted())
                setModelSorting(QCompleter::CaseSensitivelySortedModel);
@@ -556,7 +558,7 @@ void GuiCompleter::asyncHidePopup()
 {
        popup()->hide();
        if (!inlineVisible())
-               setModel(new GuiCompletionModel(this, 0));
+               model_->setList(0);
 }
 
 
@@ -591,7 +593,7 @@ void GuiCompleter::hideInline(Cursor & cur)
 void GuiCompleter::asyncHideInline()
 {
        if (!popupVisible())
-               setModel(new GuiCompletionModel(this, 0));
+               model_->setList(0);
 }
 
 
index 1ab2376bfad97c0669fa8efb3d854d0c963eb941..46f9a15878a16c5c3a115564fc3a0809d280b56c 100644 (file)
@@ -31,7 +31,8 @@ class Buffer;
 namespace frontend {
 
 class GuiWorkArea;
-class RtlItemDelegate;
+class CompleterItemDelegate;
+class GuiCompletionModel;
 
 class GuiCompleter : private QCompleter
 {
@@ -139,7 +140,9 @@ private:
        /// a coming reset here by setting it to false.
        bool modelActive_;
        ///
-       RtlItemDelegate * rtlItemDelegate_;
+       CompleterItemDelegate * itemDelegate_;
+       ///
+       GuiCompletionModel * model_;
 }; // GuiCompleter
 
 } // namespace frontend