namespace lyx {
namespace frontend {
-
+
class LayoutItemDelegate : public QItemDelegate {
public:
///
///
QSize sizeHint(QStyleOptionViewItem const & opt,
QModelIndex const & index) const;
-
+
private:
///
void drawCategoryHeader(QPainter * painter, QStyleOptionViewItem const & opt,
- QString const & category) const;
+ QString const & category) const;
///
QString underlineFilter(QString const & s) const;
///
GuiLayoutFilterModel(QObject * parent = 0)
: QSortFilterProxyModel(parent)
{}
-
+
///
void triggerLayoutChange()
{
DocumentClassConstPtr text_class_;
///
Inset const * inset_;
-
+
/// the layout model: 1st column translated, 2nd column raw layout name
QStandardItemModel * model_;
/// the proxy model filtering \c model_
opt.state = state;
// draw category header
- drawCategoryHeader(painter, opt,
+ drawCategoryHeader(painter, opt,
category(*index.model(), index.row()));
// move rect down below header
QModelIndex const & index) const
{
QSortFilterProxyModel const * model =
- static_cast<QSortFilterProxyModel const *>(index.model());
+ static_cast<QSortFilterProxyModel const *>(index.model());
QSize size = QItemDelegate::sizeHint(opt, index);
/// QComboBox uses the first row height to estimate the
unsigned n = layout_->model()->rowCount();
// so the needed average height (rounded upwards) is:
- size.setHeight((headerHeight(opt) * cats + itemHeight * n + n - 1) / n);
+ size.setHeight((headerHeight(opt) * cats + itemHeight * n + n - 1) / n);
return size;
}
// step through data item and put "(x)" for every matching character
QString r;
int lastp = -1;
- layout_->filter();
for (int i = 0; i < f.length(); ++i) {
int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
- LASSERT(p != -1, continue);
+ if (p < 0)
+ continue;
if (lastp == p - 1 && lastp != -1) {
// remove ")" and append "x)"
r = r.left(r.length() - 4) + s[p] + "</u>";
filter_ = s;
filterModel_->setFilterRegExp(charFilterRegExp(filter_));
countCategories();
-
+
// restore old selection
if (lastSel_ != -1) {
QModelIndex i = filterModel_->mapFromSource(model_->index(lastSel_, 0));
if (i.isValid())
p->setCurrentIndex(i.row());
}
-
+
// Workaround to resize to content size
// FIXME: There must be a better way. The QComboBox::AdjustToContents)
// does not help.
// The item delegate hack is off again. So trigger a relayout of the popup.
filterModel_->triggerLayoutChange();
-
+
if (!s.isEmpty())
owner_.message(bformat(_("Filtering layouts with \"%1$s\". "
"Press ESC to remove filter."),
else
owner_.message(_("Enter characters to filter the layout list."));
}
-
+
p->view()->setUpdatesEnabled(enabled);
}
// for the filtering we have to intercept characters
view()->installEventFilter(this);
view()->setItemDelegateForColumn(0, d->layoutItemDelegate_);
-
+
QObject::connect(this, SIGNAL(activated(int)),
this, SLOT(selected(int)));
return;
// skip the "Standard" category
- QString prevCat = model_->index(0, 2).data().toString();
+ QString prevCat = model_->index(0, 2).data().toString();
// count categories
for (int i = 0; i < n; ++i) {
d->inShowPopup_ = true;
QComboBox::showPopup();
d->inShowPopup_ = false;
-
+
// The item delegate hack is off again. So trigger a relayout of the popup.
d->filterModel_->triggerLayoutChange();
-
+
view()->setUpdatesEnabled(enabled);
}
bool modified = (ke->modifiers() == Qt::ControlModifier)
|| (ke->modifiers() == Qt::AltModifier)
|| (ke->modifiers() == Qt::MetaModifier);
-
+
switch (ke->key()) {
case Qt::Key_Escape:
if (!modified && !d->filter_.isEmpty()) {
return QComboBox::eventFilter(o, e);
}
-
+
void LayoutBox::setIconSize(QSize size)
{
#ifdef Q_OS_MAC
// skip the Standard layout
if (i == 0)
++i;
-
+
// the simple unsorted case
if (!sorted) {
if (sortedByCat) {
if (i < end) {
// find alphabetic position
while (i != end
- && d->model_->item(i, 0)->text().localeAwareCompare(titem) < 0
+ && d->model_->item(i, 0)->text().localeAwareCompare(titem) < 0
&& (!sortedByCat || d->model_->item(i, 2)->text() == qcat))
++i;
}
// obsoleted layouts are skipped as well
if (!lit->obsoleted_by().empty())
continue;
- addItemSort(name, lit->category(), lyxrc.sort_layouts,
+ addItemSort(name, lit->category(), lyxrc.sort_layouts,
lyxrc.group_layouts, lit->isUnknown());
}