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()
{
//
/////////////////////////////////////////////////////////////////////
-struct LayoutBox::Private
+class LayoutBox::Private
{
+ /// noncopyable
+ Private(Private const &);
+ void operator=(Private const &);
+public:
Private(LayoutBox * parent, GuiView & gv) : p(parent), owner_(gv),
+ inset_(0),
// set the layout model with two columns
// 1st: translated layout names
// 2nd: raw layout names
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, /**/);
+ if (p < 0)
+ continue;
if (lastp == p - 1 && lastp != -1) {
// remove ")" and append "x)"
r = r.left(r.length() - 4) + s[p] + "</u>";
void LayoutBox::Private::setFilter(QString const & s)
{
+ // exit early if nothing has to be done
+ if (filter_ == s)
+ return;
+
bool enabled = p->view()->updatesEnabled();
p->view()->setUpdatesEnabled(false);
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.
// We do not call our implementation of showPopup because that
// would reset the filter again. This is only needed if the user clicks
// on the QComboBox.
- LASSERT(!inShowPopup_, /**/);
+ LATTEST(!inShowPopup_);
inShowPopup_ = true;
p->QComboBox::showPopup();
inShowPopup_ = false;
// 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) {
// call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
// the hack in the item delegate to make space for the headers.
- LASSERT(!d->inShowPopup_, /**/);
+ LATTEST(!d->inShowPopup_);
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_WS_MACX
+#ifdef Q_OS_MAC
bool small = size.height() < 20;
setAttribute(Qt::WA_MacSmallSize, small);
setAttribute(Qt::WA_MacNormalSize, !small);
{
d->resetFilter();
- if (!d->text_class_.get())
+ if (!d->text_class_)
return;
if (!d->text_class_->hasLayout(layout))
bool sorted, bool sortedByCat, bool unknown)
{
QString qitem = toqstr(item);
- // FIXME This is wrong for RTL, I'd suppose.
- QString titem = toqstr(translateIfPossible(item) +
- (unknown ? _(" (unknown)") : from_ascii("")));
+ docstring const loc_item = translateIfPossible(item);
+ QString titem = unknown ? toqstr(bformat(_("%1$s (unknown)"), loc_item))
+ : toqstr(loc_item);
QString qcat = toqstr(translateIfPossible(category));
QList<QStandardItem *> row;
// 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;
}
if (!bv) {
d->model_->clear();
setEnabled(false);
+ setMinimumWidth(sizeHint().width());
d->text_class_.reset();
d->inset_ = 0;
return;
// 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());
}
set(d->owner_.currentBufferView()->cursor().innerParagraph().layout().name());
d->countCategories();
-
- // needed to recalculate size hint
- hide();
+
setMinimumWidth(sizeHint().width());
setEnabled(!bv->buffer().isReadonly() &&
lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled());
- show();
}
d->model_->itemFromIndex(mindex)->text());
d->owner_.setFocus();
- if (!d->text_class_.get()) {
+ if (!d->text_class_) {
updateContents(false);
d->resetFilter();
return;