From 0d4ab86261beff291b43f2dca9a465fdfc4d5c92 Mon Sep 17 00:00:00 2001 From: Bernhard Roider Date: Tue, 3 Jun 2008 22:00:47 +0000 Subject: [PATCH] Fix item delegate for qt 4.2: 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 | 50 ++++++++++++++++-------------- src/frontends/qt4/GuiCompleter.h | 7 +++-- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/frontends/qt4/GuiCompleter.cpp b/src/frontends/qt4/GuiCompleter.cpp index 1ce5c8fa1c..386f019575 100644 --- a/src/frontends/qt4/GuiCompleter.cpp +++ b/src/frontends/qt4/GuiCompleter.cpp @@ -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(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); } diff --git a/src/frontends/qt4/GuiCompleter.h b/src/frontends/qt4/GuiCompleter.h index 1ab2376bfa..46f9a15878 100644 --- a/src/frontends/qt4/GuiCompleter.h +++ b/src/frontends/qt4/GuiCompleter.h @@ -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 -- 2.39.2