forked from teamnwah/openmw-tes3coop
Create the custom completer popup to avoid the problem with the wrong height of the default popup
This commit is contained in:
parent
994c6833bc
commit
9e405b69fa
4 changed files with 53 additions and 1 deletions
|
@ -74,7 +74,7 @@ opencs_units_noqt (view/world
|
||||||
|
|
||||||
opencs_units (view/widget
|
opencs_units (view/widget
|
||||||
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun modebutton
|
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun modebutton
|
||||||
scenetooltoggle2
|
scenetooltoggle2 completerpopup
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units (view/render
|
opencs_units (view/render
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
|
|
||||||
|
#include "../../view/widget/completerpopup.hpp"
|
||||||
|
|
||||||
#include "data.hpp"
|
#include "data.hpp"
|
||||||
#include "idtablebase.hpp"
|
#include "idtablebase.hpp"
|
||||||
|
|
||||||
|
@ -121,6 +123,11 @@ void CSMWorld::IdCompletionManager::generateCompleters(CSMWorld::Data &data)
|
||||||
// The completion role must be Qt::DisplayRole to get the ID values from the model
|
// The completion role must be Qt::DisplayRole to get the ID values from the model
|
||||||
completer->setCompletionRole(Qt::DisplayRole);
|
completer->setCompletionRole(Qt::DisplayRole);
|
||||||
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
QAbstractItemView *popup = new CSVWidget::CompleterPopup();
|
||||||
|
completer->setPopup(popup); // The completer takes ownership of the popup
|
||||||
|
completer->setMaxVisibleItems(10);
|
||||||
|
|
||||||
mCompleters[current->first] = completer;
|
mCompleters[current->first] = completer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
apps/opencs/view/widget/completerpopup.cpp
Normal file
28
apps/opencs/view/widget/completerpopup.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "completerpopup.hpp"
|
||||||
|
|
||||||
|
CSVWidget::CompleterPopup::CompleterPopup(QWidget *parent)
|
||||||
|
: QListView(parent)
|
||||||
|
{
|
||||||
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSVWidget::CompleterPopup::sizeHintForRow(int row) const
|
||||||
|
{
|
||||||
|
if (model() == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (row < 0 || row >= model()->rowCount())
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ensurePolished();
|
||||||
|
QModelIndex index = model()->index(row, modelColumn());
|
||||||
|
QStyleOptionViewItem option = viewOptions();
|
||||||
|
QAbstractItemDelegate *delegate = itemDelegate(index);
|
||||||
|
return delegate->sizeHint(option, index).height();
|
||||||
|
}
|
17
apps/opencs/view/widget/completerpopup.hpp
Normal file
17
apps/opencs/view/widget/completerpopup.hpp
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef CSV_WIDGET_COMPLETERPOPUP_HPP
|
||||||
|
#define CSV_WIDGET_COMPLETERPOPUP_HPP
|
||||||
|
|
||||||
|
#include <QListView>
|
||||||
|
|
||||||
|
namespace CSVWidget
|
||||||
|
{
|
||||||
|
class CompleterPopup : public QListView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CompleterPopup(QWidget *parent = 0);
|
||||||
|
|
||||||
|
virtual int sizeHintForRow(int row) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue