///
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;
///
void countCategories();
///
CategorizedCombo * p;
-
- /** the layout model:
+
+ /** the layout model:
* 1st column: translated GUI name,
* 2nd column: raw item name,
* 3rd column: category,
opt.state = state;
// draw category header
- drawCategoryHeader(painter, opt,
+ drawCategoryHeader(painter, opt,
categoryCC(*index.model(), index.row()));
// move rect down below header
QFontMetrics fm(font);
int w = fm.width(category);
int x = opt.rect.x() + (opt.rect.width() - w) / 2;
- int y = opt.rect.y() + 1.5 * fm.ascent();
+ int y = opt.rect.y() + 3 * fm.ascent() / 2;
int left = x;
int right = x + w;
painter->drawText(x, y, category);
// step through data item and put "(x)" for every matching character
QString r;
int lastp = -1;
- cc_->filter();
for (int i = 0; i < f.length(); ++i) {
int p = s.indexOf(f[i], lastp + 1, Qt::CaseInsensitive);
- LASSERT(p != -1, /**/);
+ 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(charFilterRegExpCC(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.
p->QComboBox::showPopup();
inShowPopup_ = false;
}
-
+
p->view()->setUpdatesEnabled(enabled);
}
: QComboBox(parent), d(new Private(this))
{
setSizeAdjustPolicy(QComboBox::AdjustToContents);
- setFocusPolicy(Qt::ClickFocus);
setMinimumWidth(sizeHint().width());
setMaxVisibleItems(100);
// for the filtering we have to intercept characters
view()->installEventFilter(this);
view()->setItemDelegateForColumn(0, d->CCItemDelegate_);
-
+
updateCombo();
}
if (n == 0)
return;
- QString prevCat = model_->index(0, 2).data().toString();
+ QString prevCat = model_->index(0, 2).data().toString();
// count categories
for (int i = 1; i < n; ++i) {
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()) {
if (sortedByCat) {
// If sortCats == true, sort categories alphabetically, uncategorized at the end.
while (i < end && d->model_->item(i, 2)->text() != qcat
- && (!sortCats
+ && (!sortCats
|| (!uncategorized && d->model_->item(i, 2)->text().localeAwareCompare(qcat) < 0
&& d->model_->item(i, 2)->text() != qt_("Uncategorized"))
|| (uncategorized && d->model_->item(i, 2)->text() != qt_("Uncategorized"))))
void CategorizedCombo::updateCombo()
{
d->countCategories();
-
+
// needed to recalculate size hint
hide();
setMinimumWidth(sizeHint().width());
return d->filter_;
}
-} // namespace frontend
-} // namespace lyx
+} // namespace frontend
+} // namespace lyx
#include "moc_CategorizedCombo.cpp"