#include <QStandardItemModel>
#include <QTextFrame>
-using namespace std;
-using namespace lyx;
using namespace lyx::support;
+namespace lyx {
+namespace frontend {
+
class CCItemDelegate : public QItemDelegate {
public:
};
-static QString category(QAbstractItemModel const & model, int row)
+static QString categoryCC(QAbstractItemModel const & model, int row)
{
return model.data(model.index(row, 2), Qt::DisplayRole).toString();
}
-static int headerHeight(QStyleOptionViewItem const & opt)
+static int headerHeightCC(QStyleOptionViewItem const & opt)
{
return opt.fontMetrics.height();
}
// default background
painter->fillRect(opt.rect, opt.palette.color(QPalette::Base));
- QString cat = category(*index.model(), index.row());
+ QString cat = categoryCC(*index.model(), index.row());
// not the same as in the previous line?
- if (index.row() == 0 || cat != category(*index.model(), index.row() - 1)) {
+ if (index.row() == 0 || cat != categoryCC(*index.model(), index.row() - 1)) {
painter->save();
// draw unselected background
// draw category header
drawCategoryHeader(painter, opt,
- category(*index.model(), index.row()));
+ categoryCC(*index.model(), index.row()));
// move rect down below header
- opt.rect.setTop(opt.rect.top() + headerHeight(opt));
+ opt.rect.setTop(opt.rect.top() + headerHeightCC(opt));
painter->restore();
}
/// So we tweak this value accordingly. It's not nice, but the
/// only possible way it seems.
// Add space for the category headers here
- QString cat = category(*index.model(), index.row());
- if (index.row() == 0 || cat != category(*index.model(), index.row() - 1)) {
- size.setHeight(size.height() + headerHeight(opt));
+ QString cat = categoryCC(*index.model(), index.row());
+ if (index.row() == 0 || cat != categoryCC(*index.model(), index.row() - 1)) {
+ size.setHeight(size.height() + headerHeightCC(opt));
}
return size;
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>";
}
-static QString charFilterRegExp(QString const & filter)
+static QString charFilterRegExpCC(QString const & filter)
{
QString re;
for (int i = 0; i < filter.length(); ++i) {
lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
filter_ = s;
- filterModel_->setFilterRegExp(charFilterRegExp(filter_));
+ filterModel_->setFilterRegExp(charFilterRegExpCC(filter_));
countCategories();
// restore old selection
: QComboBox(parent), d(new Private(this))
{
setSizeAdjustPolicy(QComboBox::AdjustToContents);
- setFocusPolicy(Qt::ClickFocus);
setMinimumWidth(sizeHint().width());
setMaxVisibleItems(100);
void CategorizedCombo::setIconSize(QSize size)
{
-#ifdef Q_WS_MACX
+#ifdef Q_OS_MAC
bool small = size.height() < 20;
setAttribute(Qt::WA_MacSmallSize, small);
setAttribute(Qt::WA_MacNormalSize, !small);
QString CategorizedCombo::getData(int row) const
{
- return d->model_->data(d->model_->index(row, 1), Qt::DisplayRole).toString();
+ int srow = d->filterModel_->mapToSource(d->filterModel_->index(row, 1)).row();
+ return d->model_->data(d->model_->index(srow, 1), Qt::DisplayRole).toString();
}
return d->filter_;
}
+} // namespace frontend
+} // namespace lyx
+
#include "moc_CategorizedCombo.cpp"