* another step for rtl completion: the popup is shown in the right direction. Still the right cursor position is missing. This also causes the popup to use a wrong position.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23146 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-02-22 21:57:57 +00:00
parent 3cdfa1708f
commit 5cc36c8c70

View File

@ -20,6 +20,7 @@
#include "GuiView.h" #include "GuiView.h"
#include "LyXFunc.h" #include "LyXFunc.h"
#include "LyXRC.h" #include "LyXRC.h"
#include "Paragraph.h"
#include "version.h" #include "version.h"
#include "support/debug.h" #include "support/debug.h"
@ -72,8 +73,9 @@ protected:
class GuiCompletionModel : public QAbstractListModel { class GuiCompletionModel : public QAbstractListModel {
public: public:
/// ///
GuiCompletionModel(QObject * parent, Inset::CompletionList const * l) GuiCompletionModel(QObject * parent,
: QAbstractListModel(parent), list_(l) {} Inset::CompletionList const * l, bool rtl)
: QAbstractListModel(parent), list_(l), rtl_(rtl) {}
/// ///
~GuiCompletionModel() ~GuiCompletionModel()
{ delete list_; } { delete list_; }
@ -103,9 +105,12 @@ public:
if (role != Qt::DisplayRole && role != Qt::EditRole) if (role != Qt::DisplayRole && role != Qt::EditRole)
return QVariant(); return QVariant();
if (index.column() == 0) if (index.column() == 0) {
return toqstr(list_->data(index.row())); docstring s = list_->data(index.row());
else if (index.column() == 1) { if (rtl_)
reverse(s.begin(), s.end());
return toqstr(s);
} else if (index.column() == 1) {
// get icon from cache // get icon from cache
QPixmap scaled; QPixmap scaled;
QString const name = ":" + toqstr(list_->icon(index.row())); QString const name = ":" + toqstr(list_->icon(index.row()));
@ -126,9 +131,17 @@ public:
return QVariant(); return QVariant();
} }
///
bool rtl() const
{
return rtl_;
}
private: private:
/// ///
Inset::CompletionList const * list_; Inset::CompletionList const * list_;
///
bool rtl_;
}; };
@ -136,7 +149,7 @@ GuiCompleter::GuiCompleter(GuiWorkArea * gui, QObject * parent)
: QCompleter(parent), gui_(gui), updateLock_(0) : QCompleter(parent), gui_(gui), updateLock_(0)
{ {
// Setup the completion popup // Setup the completion popup
setModel(new GuiCompletionModel(this, 0)); setModel(new GuiCompletionModel(this, 0, false));
setCompletionMode(QCompleter::PopupCompletion); setCompletionMode(QCompleter::PopupCompletion);
setWidget(gui_); setWidget(gui_);
@ -347,10 +360,16 @@ void GuiCompleter::updatePopup(Cursor & cur)
int x; int x;
int y; int y;
cur.inset().completionPosAndDim(cur, x, y, dim); cur.inset().completionPosAndDim(cur, x, y, dim);
QRect insetRect = QRect(x, y - dim.ascent() - 3, 200, dim.height() + 6);
// and calculate the rect of the popup
QRect rect;
if (static_cast<GuiCompletionModel const *>(model())->rtl())
rect = QRect(x + dim.width() - 200, y - dim.ascent() - 3, 200, dim.height() + 6);
else
rect = QRect(x, y - dim.ascent() - 3, 200, dim.height() + 6);
// show/update popup // show/update popup
complete(insetRect); complete(rect);
QTreeView * p = static_cast<QTreeView *>(popup()); QTreeView * p = static_cast<QTreeView *>(popup());
p->setColumnWidth(0, popup()->width() - 22 - p->verticalScrollBar()->width()); p->setColumnWidth(0, popup()->width() - 22 - p->verticalScrollBar()->width());
} }
@ -362,12 +381,22 @@ void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate
QString old = currentCompletion(); QString old = currentCompletion();
if (old.length() == 0) if (old.length() == 0)
old = last_selection_; old = last_selection_;
// set whether rtl
bool rtl = false;
if (cur.inTexted()) {
Paragraph const & par = cur.paragraph();
Font const font =
par.getFontSettings(cur.bv().buffer().params(), cur.pos());
rtl = font.isVisibleRightToLeft();
}
popup()->setLayoutDirection(rtl ? Qt::RightToLeft : Qt::LeftToRight);
// set new model // set new model
Inset::CompletionList const * list Inset::CompletionList const * list
= cur.inset().createCompletionList(cur); = cur.inset().createCompletionList(cur);
setModel(new GuiCompletionModel(this, list)); setModel(new GuiCompletionModel(this, list, rtl));
// show popup // show popup
if (popupUpdate) if (popupUpdate)
updatePopup(cur); updatePopup(cur);