explicit RtlItemDelegate(QObject * parent = 0)
: QItemDelegate(parent) {}
+ void setEnabled(bool enabled = true)
+ {
+ enabled_ = enabled;
+ }
+
protected:
virtual void drawDisplay(QPainter * painter,
QStyleOptionViewItem const & option,
QRect const & rect, QString const & text) const
{
+ if (!enabled_)
+ return QItemDelegate::drawDisplay(painter, option, rect, text);
+
// FIXME: do this more elegantly
docstring stltext = qstring_to_ucs4(text);
reverse(stltext.begin(), stltext.end());
QItemDelegate::drawDisplay(painter, option, rect, toqstr(stltext));
}
+
+private:
+ bool enabled_;
};
if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant();
- if (index.column() == 0) {
- docstring const word = list_->data(index.row());
- return toqstr(word);
- } else if (index.column() == 1) {
+ if (index.column() == 0)
+ return toqstr(list_->data(index.row()));
+ else if (index.column() == 1) {
// get icon from cache
QPixmap scaled;
QString const name = ":" + toqstr(list_->icon(index.row()));
setPopup(listView);
popup()->setItemDelegateForColumn(1, new PixmapItemDelegate(this));
rtlItemDelegate_ = new RtlItemDelegate(this);
-
+ popup()->setItemDelegateForColumn(0, rtlItemDelegate_);
+
// create timeout timers
popup_timer_.setSingleShot(true);
inline_timer_.setSingleShot(true);
// turn the direction of the strings in the popup.
// Qt does not do that itself.
- popup()->setItemDelegateForColumn(0, rtl ? rtlItemDelegate_ : 0);
+ rtlItemDelegate_->setEnabled(rtl);
// set new model
Inset::CompletionList const * list = cur.inset().createCompletionList(cur);
docstring GuiCompleter::longestUniqueCompletion() const
{
QAbstractItemModel const & model = *popup()->model();
- QString s = currentCompletion();
size_t n = model.rowCount();
-
+ if (n == 0)
+ return docstring();
+ QString s = model.data(model.index(0, 0), Qt::EditRole).toString();
+
if (modelSorting() == QCompleter::UnsortedModel) {
// For unsorted model we cannot do more than iteration.
// Iterate through the completions and cut off where s differs