* center the line in the layout category headers in the middle of the lowercase chars

* some messages for the statusbar
    * configuration option for grouping of the layouts
    * put category headers above the first item of each category in the
      layout list.
      To avoid scrolling we have to sneak in space for the headers.
      So we tweak this value accordingly. It's not nice, but the
      only possible way it seems.

    Note 1: Because QComboBox uses the "first row's height * rowCount" to
    estimate the height of the popup, we have to fake some extra pixel
    lines to avoid scrolling because of the extra space taken by the
    headers. This is a hack, but I don't see a better way to establish that.

    Note 2: An alternative implementation is to insert headers as real list
    items. But it seems that QListView cannot skip them in cursor
    navigation then. So we stick to the upper approach.

    * remove checkbox in layout menu


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23626 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-03-10 13:02:57 +00:00
parent 29dca708f7
commit 473091fb82
6 changed files with 335 additions and 172 deletions

View File

@ -93,6 +93,7 @@ keyword_item lyxrcTags[] = {
{ "\\fullscreen_tabbar", LyXRC::RC_FULL_SCREEN_TABBAR }, { "\\fullscreen_tabbar", LyXRC::RC_FULL_SCREEN_TABBAR },
{ "\\fullscreen_toolbars", LyXRC::RC_FULL_SCREEN_TOOLBARS }, { "\\fullscreen_toolbars", LyXRC::RC_FULL_SCREEN_TOOLBARS },
{ "\\fullscreen_width", LyXRC::RC_FULL_SCREEN_WIDTH }, { "\\fullscreen_width", LyXRC::RC_FULL_SCREEN_WIDTH },
{ "\\group_layouts", LyXRC::RC_GROUP_LAYOUTS },
{ "\\index_command", LyXRC::RC_INDEX_COMMAND }, { "\\index_command", LyXRC::RC_INDEX_COMMAND },
{ "\\input", LyXRC::RC_INPUT }, { "\\input", LyXRC::RC_INPUT },
{ "\\kbmap", LyXRC::RC_KBMAP }, { "\\kbmap", LyXRC::RC_KBMAP },
@ -272,6 +273,7 @@ void LyXRC::setDefaults() {
language_command_begin = "\\selectlanguage{$$lang}"; language_command_begin = "\\selectlanguage{$$lang}";
language_command_local = "\\foreignlanguage{$$lang}{"; language_command_local = "\\foreignlanguage{$$lang}{";
sort_layouts = false; sort_layouts = false;
group_layouts = true;
default_language = "english"; default_language = "english";
show_banner = true; show_banner = true;
windows_style_tex_paths = false; windows_style_tex_paths = false;
@ -1270,6 +1272,10 @@ int LyXRC::read(Lexer & lexrc)
if (lexrc.next()) if (lexrc.next())
sort_layouts = lexrc.getBool(); sort_layouts = lexrc.getBool();
break; break;
case RC_GROUP_LAYOUTS:
if (lexrc.next())
group_layouts = lexrc.getBool();
break;
case RC_FULL_SCREEN_LIMIT: case RC_FULL_SCREEN_LIMIT:
if (lexrc.next()) if (lexrc.next())
full_screen_limit = lexrc.getBool(); full_screen_limit = lexrc.getBool();
@ -1461,6 +1467,14 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
} }
if (tag != RC_LAST) if (tag != RC_LAST)
break; break;
case RC_GROUP_LAYOUTS:
if (ignore_system_lyxrc ||
group_layouts != system_lyxrc.group_layouts) {
os << "# Group layouts by their category.\n"
<< "\\group_layouts " << convert<string>(group_layouts) << '\n';
}
if (tag != RC_LAST)
break;
case RC_VIEWDVI_PAPEROPTION: case RC_VIEWDVI_PAPEROPTION:
if (ignore_system_lyxrc || if (ignore_system_lyxrc ||
view_dvi_paper_option view_dvi_paper_option

View File

@ -79,6 +79,8 @@ public:
RC_FULL_SCREEN_TABBAR, RC_FULL_SCREEN_TABBAR,
RC_FULL_SCREEN_TOOLBARS, RC_FULL_SCREEN_TOOLBARS,
RC_FULL_SCREEN_WIDTH, RC_FULL_SCREEN_WIDTH,
RC_GEOMETRY_SESSION,
RC_GROUP_LAYOUTS,
RC_INDEX_COMMAND, RC_INDEX_COMMAND,
RC_INPUT, RC_INPUT,
RC_KBMAP, RC_KBMAP,
@ -93,8 +95,6 @@ public:
RC_LANGUAGE_GLOBAL_OPTIONS, RC_LANGUAGE_GLOBAL_OPTIONS,
RC_LANGUAGE_PACKAGE, RC_LANGUAGE_PACKAGE,
RC_LANGUAGE_USE_BABEL, RC_LANGUAGE_USE_BABEL,
RC_SORT_LAYOUTS,
RC_USELASTFILEPOS,
RC_LOADSESSION, RC_LOADSESSION,
RC_MACRO_EDIT_STYLE, RC_MACRO_EDIT_STYLE,
RC_MAKE_BACKUP, RC_MAKE_BACKUP,
@ -134,17 +134,18 @@ public:
RC_SCREEN_FONT_SIZES, RC_SCREEN_FONT_SIZES,
RC_SCREEN_FONT_TYPEWRITER, RC_SCREEN_FONT_TYPEWRITER,
RC_SCREEN_FONT_TYPEWRITER_FOUNDRY, RC_SCREEN_FONT_TYPEWRITER_FOUNDRY,
RC_GEOMETRY_SESSION,
RC_SCREEN_ZOOM, RC_SCREEN_ZOOM,
RC_SERVERPIPE, RC_SERVERPIPE,
RC_SET_COLOR, RC_SET_COLOR,
RC_SHOW_BANNER, RC_SHOW_BANNER,
RC_SORT_LAYOUTS,
RC_SPELL_COMMAND, RC_SPELL_COMMAND,
RC_TEMPDIRPATH, RC_TEMPDIRPATH,
RC_TEMPLATEPATH, RC_TEMPLATEPATH,
RC_TEX_ALLOWS_SPACES, RC_TEX_ALLOWS_SPACES,
RC_TEX_EXPECTS_WINDOWS_PATHS, RC_TEX_EXPECTS_WINDOWS_PATHS,
RC_UIFILE, RC_UIFILE,
RC_USELASTFILEPOS,
RC_USER_EMAIL, RC_USER_EMAIL,
RC_USER_NAME, RC_USER_NAME,
RC_USETEMPDIR, RC_USETEMPDIR,
@ -407,6 +408,8 @@ public:
unsigned int converter_cache_maxage; unsigned int converter_cache_maxage;
/// Sort layouts alphabetically /// Sort layouts alphabetically
bool sort_layouts; bool sort_layouts;
/// Group layout by their category
bool group_layouts;
/// Toggle toolbars in fullscreen mode? /// Toggle toolbars in fullscreen mode?
bool full_screen_toolbars; bool full_screen_toolbars;
/// Toggle scrollbar in fullscreen mode? /// Toggle scrollbar in fullscreen mode?

View File

@ -1797,6 +1797,8 @@ PrefUserInterface::PrefUserInterface(GuiPreferences * form, QWidget * parent)
this, SIGNAL(changed())); this, SIGNAL(changed()));
connect(sortEnvironmentsCB, SIGNAL(clicked()), connect(sortEnvironmentsCB, SIGNAL(clicked()),
this, SIGNAL(changed())); this, SIGNAL(changed()));
connect(groupEnvironmentsCB, SIGNAL(clicked()),
this, SIGNAL(changed()));
connect(macroEditStyleCO, SIGNAL(activated(int)), connect(macroEditStyleCO, SIGNAL(activated(int)),
this, SIGNAL(changed())); this, SIGNAL(changed()));
connect(autoSaveSB, SIGNAL(valueChanged(int)), connect(autoSaveSB, SIGNAL(valueChanged(int)),
@ -1829,6 +1831,7 @@ void PrefUserInterface::apply(LyXRC & rc) const
rc.allow_geometry_session = allowGeometrySessionCB->isChecked(); rc.allow_geometry_session = allowGeometrySessionCB->isChecked();
rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked(); rc.cursor_follows_scrollbar = cursorFollowsCB->isChecked();
rc.sort_layouts = sortEnvironmentsCB->isChecked(); rc.sort_layouts = sortEnvironmentsCB->isChecked();
rc.group_layouts = groupEnvironmentsCB->isChecked();
switch (macroEditStyleCO->currentIndex()) { switch (macroEditStyleCO->currentIndex()) {
case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break; case 0: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE_BOX; break;
case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break; case 1: rc.macro_edit_style = LyXRC::MACRO_EDIT_INLINE; break;
@ -1854,6 +1857,7 @@ void PrefUserInterface::update(LyXRC const & rc)
allowGeometrySessionCB->setChecked(rc.allow_geometry_session); allowGeometrySessionCB->setChecked(rc.allow_geometry_session);
cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar); cursorFollowsCB->setChecked(rc.cursor_follows_scrollbar);
sortEnvironmentsCB->setChecked(rc.sort_layouts); sortEnvironmentsCB->setChecked(rc.sort_layouts);
groupEnvironmentsCB->setChecked(rc.group_layouts);
macroEditStyleCO->setCurrentIndex(rc.macro_edit_style); macroEditStyleCO->setCurrentIndex(rc.macro_edit_style);
// convert to minutes // convert to minutes
int mins(rc.autosave / 60); int mins(rc.autosave / 60);

View File

@ -46,9 +46,11 @@
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QApplication> #include <QApplication>
#include <QComboBox> #include <QComboBox>
#include <QFontMetrics>
#include <QHeaderView> #include <QHeaderView>
#include <QKeyEvent> #include <QKeyEvent>
#include <QList> #include <QList>
#include <QListView>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
@ -61,6 +63,9 @@
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <map>
#include <vector>
using namespace std; using namespace std;
using namespace lyx::support; using namespace lyx::support;
@ -242,10 +247,10 @@ static QIcon getIcon(FuncRequest const & f, bool unknown)
// //
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
class FilterItemDelegate : public QAbstractItemDelegate { class LayoutItemDelegate : public QAbstractItemDelegate {
public: public:
/// ///
explicit FilterItemDelegate(QObject * parent = 0) explicit LayoutItemDelegate(QObject * parent = 0)
: QAbstractItemDelegate(parent) : QAbstractItemDelegate(parent)
{} {}
@ -254,60 +259,38 @@ public:
QModelIndex const & index) const QModelIndex const & index) const
{ {
QComboBox * combo = static_cast<QComboBox *>(parent()); QComboBox * combo = static_cast<QComboBox *>(parent());
QSortFilterProxyModel const * model
= static_cast<QSortFilterProxyModel const *>(index.model());
QStyleOptionMenuItem opt = getStyleOption(option, index); QStyleOptionMenuItem opt = getStyleOption(option, index);
painter->eraseRect(opt.rect);
// draw line with small text string for separator QString text = underlineFilter(opt.text);
if (opt.text.left(2) == "--") { opt.text = QString();
painter->save();
// category header?
// set options for the separator, the first 8/18 of the vertical space if (lyxrc.group_layouts) {
QStyleOptionMenuItem sopt = opt; QString stdCat = category(*model->sourceModel(), 0);
sopt.state = QStyle::State_Active | QStyle::State_Enabled; QString cat = category(*index.model(), index.row());
sopt.checked = false;
sopt.text = QString();
sopt.rect.setHeight(sopt.rect.height() * 8 / 18);
sopt.menuRect.setHeight(sopt.menuRect.height() * 8 / 18);
// use the style with an empty text to paint the background
painter->eraseRect(sopt.rect);
combo->style()->drawControl(QStyle::CE_MenuItem, &sopt, painter, combo->view());
// draw the centered text, small and bold
QPen pen;
pen.setWidth(1);
pen.setColor(sopt.palette.text().color());
painter->setPen(pen);
QFont font = sopt.font;
font.setBold(true);
font.setWeight(QFont::Black);
font.setPointSize(sopt.font.pointSize() * 8 / 10);
painter->setFont(font);
QRect brect;
painter->drawText(sopt.rect, Qt::AlignCenter, "Modules", &brect);
// draw the horizontal line // not the standard layout and not the same as in the previous line?
QColor lcol = sopt.palette.text().color(); if (stdCat != cat
lcol.setAlpha(127); && (index.row() == 0 || cat != category(*index.model(), index.row() - 1))) {
painter->setPen(lcol); // draw category header
painter->drawLine(sopt.rect.x(), sopt.rect.y() + sopt.rect.height() / 2 , paintBackground(painter, opt);
brect.left() - 1, sopt.rect.y() + sopt.rect.height() / 2); paintCategoryHeader(painter, opt,
painter->drawLine(brect.right() + 1, sopt.rect.y() + sopt.rect.height() / 2, category(*index.model(), index.row()));
sopt.rect.right(), sopt.rect.y() + sopt.rect.height() / 2);
QFontMetrics fm(opt.font);
painter->restore(); opt.rect.setTop(opt.rect.top() + headerHeight(opt));
opt.menuRect = opt.rect;
// move rect down 8/20 of the original height }
opt.rect.setTop(sopt.rect.y() + sopt.rect.height());
opt.menuRect = opt.rect;
} }
// Draw using the menu item style (this is how QComboBox does it). // Draw using the menu item style (this is how QComboBox does it).
// But for the rich text drawing below we will call it with an // But for the rich text drawing below we will call it with an
// empty string, and later then draw over it the real string. // empty string, and later then draw over it the real string.
painter->save(); painter->save();
QString text = underlineFilter(opt.text);
opt.text = QString();
painter->eraseRect(opt.rect);
combo->style()->drawControl(QStyle::CE_MenuItem, &opt, painter, combo->view()); combo->style()->drawControl(QStyle::CE_MenuItem, &opt, painter, combo->view());
painter->restore(); painter->restore();
@ -322,7 +305,7 @@ public:
QTextDocument doc; QTextDocument doc;
doc.setDefaultFont(opt.font); doc.setDefaultFont(opt.font);
doc.setHtml(text); doc.setHtml(text);
painter->translate(opt.rect.x() + 20, opt.rect.y()); painter->translate(opt.rect.x() + 5, opt.rect.y());
doc.documentLayout()->draw(painter, context); doc.documentLayout()->draw(painter, context);
painter->restore(); painter->restore();
} }
@ -331,17 +314,114 @@ public:
QSize sizeHint(QStyleOptionViewItem const & option, QSize sizeHint(QStyleOptionViewItem const & option,
QModelIndex const & index) const QModelIndex const & index) const
{ {
QComboBox * combo = static_cast<QComboBox *>(parent()); GuiLayoutBox * combo = static_cast<GuiLayoutBox *>(parent());
QSortFilterProxyModel const * model
= static_cast<QSortFilterProxyModel const *>(index.model());
QStyleOptionMenuItem opt = getStyleOption(option, index); QStyleOptionMenuItem opt = getStyleOption(option, index);
QSize size = combo->style()->sizeFromContents( QSize size = combo->style()->sizeFromContents(
QStyle::CT_MenuItem, &opt, option.rect.size(), combo); QStyle::CT_MenuItem, &opt, option.rect.size(), combo);
if (opt.text.left(2) == "--")
size.setHeight(size.height() * 18 / 10); /// QComboBox uses the first row height to estimate the
/// complete popup height during QComboBox::showPopup().
/// To avoid scrolling we have to sneak in space for the headers.
/// So we tweak this value accordingly. It's not nice, but the
/// only possible way it seems.
if (lyxrc.group_layouts && index.row() == 0 && combo->inShowPopup_) {
int itemHeight = size.height();
// we have to show \c cats many headers:
unsigned cats = combo->visibleCategories_;
// and we have \c n items to distribute the needed space over
unsigned n = combo->model()->rowCount();
// so the needed average height (rounded upwards) is:
size.setHeight((headerHeight(opt) * cats + itemHeight * n + n - 1) / n);
return size;
}
// Add space for the category headers here?
// Not for the standard layout though.
QString stdCat = category(*model->sourceModel(), 0);
QString cat = category(*index.model(), index.row());
if (lyxrc.group_layouts && stdCat != cat
&& (index.row() == 0 || cat != category(*index.model(), index.row() - 1))) {
size.setHeight(size.height() + headerHeight(opt));
}
return size; return size;
} }
private: private:
///
QString category(QAbstractItemModel const & model, int row) const
{
return model.data(model.index(row, 2), Qt::DisplayRole).toString();
}
///
void paintBackground(QPainter * painter, QStyleOptionMenuItem const & opt) const
{
QComboBox * combo = static_cast<QComboBox *>(parent());
// we only want to paint a background using the style, so
// disable every thing else
QStyleOptionMenuItem sopt = opt;
sopt.menuRect = sopt.rect;
sopt.state = QStyle::State_Active | QStyle::State_Enabled;
sopt.checked = false;
sopt.text = QString();
painter->save();
combo->style()->drawControl(QStyle::CE_MenuItem, &sopt,
painter, combo->view());
painter->restore();
}
///
int headerHeight(QStyleOptionMenuItem const & opt) const
{
QFontMetrics fm(opt.font);
return fm.height() * 8 / 10;
}
///
void paintCategoryHeader(QPainter * painter, QStyleOptionMenuItem const & opt,
QString const & category) const
{
painter->save();
// slightly blended color
QColor lcol = opt.palette.text().color();
lcol.setAlpha(127);
painter->setPen(lcol);
// set 80% scaled, bold font
QFont font = opt.font;
font.setBold(true);
font.setWeight(QFont::Black);
font.setPointSize(opt.font.pointSize() * 8 / 10);
painter->setFont(font);
// draw the centered text
QFontMetrics fm(font);
int w = fm.width(category);
int x = opt.rect.x() + (opt.rect.width() - w) / 2;
int y = opt.rect.y() + fm.ascent();
int left = x;
int right = x + w;
painter->drawText(x, y, category);
// the vertical position of the line: middle of lower case chars
int ymid = y - 1 - fm.xHeight() / 2; // -1 for the baseline
// draw the horizontal line
painter->drawLine(opt.rect.x(), ymid, left - 1, ymid);
painter->drawLine(right + 1, ymid, opt.rect.right(), ymid);
painter->restore();
}
/// ///
QString underlineFilter(QString const & s) const QString underlineFilter(QString const & s) const
{ {
@ -381,7 +461,6 @@ private:
// create the options for a menu item // create the options for a menu item
QStyleOptionMenuItem menuOption; QStyleOptionMenuItem menuOption;
menuOption.palette = QApplication::palette("QMenu"); menuOption.palette = QApplication::palette("QMenu");
menuOption.checkType = QStyleOptionMenuItem::NonExclusive;
menuOption.state = QStyle::State_Active | QStyle::State_Enabled; menuOption.state = QStyle::State_Active | QStyle::State_Enabled;
menuOption.menuRect = option.rect; menuOption.menuRect = option.rect;
menuOption.rect = option.rect; menuOption.rect = option.rect;
@ -393,41 +472,32 @@ private:
menuOption.menuItemType = QStyleOptionMenuItem::Normal; menuOption.menuItemType = QStyleOptionMenuItem::Normal;
if (option.state & QStyle::State_Selected) if (option.state & QStyle::State_Selected)
menuOption.state |= QStyle::State_Selected; menuOption.state |= QStyle::State_Selected;
menuOption.checked = combo->currentIndex() == index.row(); menuOption.checkType = QStyleOptionMenuItem::NotCheckable;
menuOption.checked = false;
return menuOption; return menuOption;
} }
}; };
class GuiFilterProxyModel : public QSortFilterProxyModel class GuiLayoutFilterModel : public QSortFilterProxyModel {
{
public: public:
/// ///
GuiFilterProxyModel(QObject * parent) GuiLayoutFilterModel(QObject * parent = 0)
: QSortFilterProxyModel(parent) {} : QSortFilterProxyModel(parent)
{}
/// ///
void setCharFilter(QString const & f) void triggerLayoutChange()
{ {
setFilterRegExp(charFilterRegExp(f)); layoutAboutToBeChanged();
dataChanged(index(0, 0), index(rowCount() - 1, 1)); layoutChanged();
}
private:
///
QString charFilterRegExp(QString const & filter)
{
QString re;
for (int i = 0; i < filter.length(); ++i)
re += ".*" + QRegExp::escape(filter[i]);
return re;
} }
}; };
GuiLayoutBox::GuiLayoutBox(GuiView & owner) GuiLayoutBox::GuiLayoutBox(GuiView & owner)
: owner_(owner), filterItemDelegate_(new FilterItemDelegate(this)) : owner_(owner), lastSel_(-1), layoutItemDelegate_(new LayoutItemDelegate(this)),
visibleCategories_(0), inShowPopup_(false)
{ {
setSizeAdjustPolicy(QComboBox::AdjustToContents); setSizeAdjustPolicy(QComboBox::AdjustToContents);
setFocusPolicy(Qt::ClickFocus); setFocusPolicy(Qt::ClickFocus);
@ -438,15 +508,13 @@ GuiLayoutBox::GuiLayoutBox(GuiView & owner)
// 1st: translated layout names // 1st: translated layout names
// 2nd: raw layout names // 2nd: raw layout names
model_ = new QStandardItemModel(0, 2, this); model_ = new QStandardItemModel(0, 2, this);
filterModel_ = new GuiFilterProxyModel(this); filterModel_ = new GuiLayoutFilterModel(this);
filterModel_->setSourceModel(model_); filterModel_->setSourceModel(model_);
filterModel_->setDynamicSortFilter(true);
filterModel_->setFilterCaseSensitivity(Qt::CaseInsensitive);
setModel(filterModel_); setModel(filterModel_);
// for the filtering we have to intercept characters // for the filtering we have to intercept characters
view()->installEventFilter(this); view()->installEventFilter(this);
view()->setItemDelegateForColumn(0, filterItemDelegate_); view()->setItemDelegateForColumn(0, layoutItemDelegate_);
QObject::connect(this, SIGNAL(activated(int)), QObject::connect(this, SIGNAL(activated(int)),
this, SLOT(selected(int))); this, SLOT(selected(int)));
@ -457,13 +525,23 @@ GuiLayoutBox::GuiLayoutBox(GuiView & owner)
void GuiLayoutBox::setFilter(QString const & s) void GuiLayoutBox::setFilter(QString const & s)
{ {
if (!s.isEmpty())
owner_.message(_("Filtering layouts with \"" + fromqstr(s) + "\". "
"Press ESC to remove filter."));
else
owner_.message(_("Enter characters to filter the layout list."));
bool enabled = view()->updatesEnabled();
view()->setUpdatesEnabled(false);
// remember old selection // remember old selection
int sel = currentIndex(); int sel = currentIndex();
if (sel != -1) if (sel != -1)
lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row(); lastSel_ = filterModel_->mapToSource(filterModel_->index(sel, 0)).row();
filter_ = s; filter_ = s;
filterModel_->setCharFilter(s); filterModel_->setFilterRegExp(charFilterRegExp(filter_));
countCategories();
// restore old selection // restore old selection
if (lastSel_ != -1) { if (lastSel_ != -1) {
@ -475,8 +553,56 @@ void GuiLayoutBox::setFilter(QString const & s)
// Workaround to resize to content size // Workaround to resize to content size
// FIXME: There must be a better way. The QComboBox::AdjustToContents) // FIXME: There must be a better way. The QComboBox::AdjustToContents)
// does not help. // does not help.
if (view()->isVisible()) if (view()->isVisible()) {
// call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
// the hack in the item delegate to make space for the headers.
// 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.
BOOST_ASSERT(!inShowPopup_);
inShowPopup_ = true;
QComboBox::showPopup(); QComboBox::showPopup();
inShowPopup_ = false;
// The item delegate hack is off again. So trigger a relayout of the popup.
filterModel_->triggerLayoutChange();
}
view()->setUpdatesEnabled(enabled);
}
void GuiLayoutBox::countCategories()
{
int n = filterModel_->rowCount();
visibleCategories_ = 0;
if (n == 0 || !lyxrc.group_layouts)
return;
// skip the "Standard" category
QString prevCat = model_->index(0, 2).data().toString();
// count categories
for (int i = 0; i < n; ++i) {
QString cat = filterModel_->index(i, 2).data().toString();
if (cat != prevCat)
++visibleCategories_;
prevCat = cat;
}
}
QString GuiLayoutBox::charFilterRegExp(QString const & filter)
{
QString re;
for (int i = 0; i < filter.length(); ++i) {
QChar c = filter[i];
if (c.isLower())
re += ".*[" + QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
else
re += ".*" + QRegExp::escape(c);
}
return re;
} }
@ -488,9 +614,24 @@ void GuiLayoutBox::resetFilter()
void GuiLayoutBox::showPopup() void GuiLayoutBox::showPopup()
{ {
resetFilter();
owner_.message(_("Enter characters to filter the layout list.")); owner_.message(_("Enter characters to filter the layout list."));
bool enabled = view()->updatesEnabled();
view()->setUpdatesEnabled(false);
resetFilter();
// call QComboBox::showPopup. But set the inShowPopup_ flag to switch on
// the hack in the item delegate to make space for the headers.
BOOST_ASSERT(!inShowPopup_);
inShowPopup_ = true;
QComboBox::showPopup(); QComboBox::showPopup();
inShowPopup_ = false;
// The item delegate hack is off again. So trigger a relayout of the popup.
filterModel_->triggerLayoutChange();
view()->setUpdatesEnabled(enabled);
} }
@ -565,40 +706,55 @@ void GuiLayoutBox::set(docstring const & layout)
} }
void GuiLayoutBox::addItemSort(docstring const & item, bool sorted) void GuiLayoutBox::addItemSort(docstring const & item, docstring const & category,
bool sorted, bool sortedByCat)
{ {
QString qitem = toqstr(item); QString qitem = toqstr(item);
QString titem = toqstr(translateIfPossible(item)); QString titem = toqstr(translateIfPossible(item));
QString qcat = toqstr(translateIfPossible(category));
QList<QStandardItem *> row; QList<QStandardItem *> row;
row.append(new QStandardItem(titem)); row.append(new QStandardItem(titem));
row.append(new QStandardItem(qitem)); row.append(new QStandardItem(qitem));
row.append(new QStandardItem(qcat));
// the simple unsorted case // the first entry is easy
int const end = model_->rowCount(); int const end = model_->rowCount();
if (!sorted || end < 2 || qitem[0].category() != QChar::Letter_Uppercase) { if (end == 0) {
model_->appendRow(row); model_->appendRow(row);
return; return;
} }
// find row to insert the item, after the separator if it exists // find category
int i = 1; // skip the Standard layout int i = 0;
if (sortedByCat) {
QList<QStandardItem *> sep = model_->findItems("--", Qt::MatchStartsWith); while (i < end && model_->item(i, 2)->text() != qcat)
if (!sep.isEmpty()) ++i;
i = sep.first()->index().row() + 1; }
if (i < model_->rowCount()) {
// find alphabetic position // skip the Standard layout
QString is = model_->item(i, 0)->text(); if (i == 0)
while (is.compare(titem) < 0) { ++i;
// e.g. --Separator--
if (is.at(0).category() != QChar::Letter_Uppercase) // the simple unsorted case
break; if (!sorted) {
if (sortedByCat) {
// jump to the end of the category group
while (i < end && model_->item(i, 2)->text() == qcat)
++i;
model_->insertRow(i, row);
} else
model_->appendRow(row);
return;
}
// find row to insert the item, after the separator if it exists
if (i < end) {
// find alphabetic position
while (i != end
&& model_->item(i, 0)->text().compare(titem) < 0
&& (!sortedByCat || model_->item(i, 2)->text() == qcat))
++i; ++i;
if (i == end)
break;
is = model_->item(i, 0)->text();
}
} }
model_->insertRow(i, row); model_->insertRow(i, row);
@ -645,11 +801,12 @@ void GuiLayoutBox::updateContents(bool reset)
if (name == text_class_->emptyLayoutName() && inset && if (name == text_class_->emptyLayoutName() && inset &&
!inset->forceEmptyLayout() && !inset->useEmptyLayout()) !inset->forceEmptyLayout() && !inset->useEmptyLayout())
continue; continue;
addItemSort(name, lyxrc.sort_layouts); addItemSort(name, lit->category(), lyxrc.sort_layouts, lyxrc.group_layouts);
} }
set(owner_.view()->cursor().innerParagraph().layout().name()); set(owner_.view()->cursor().innerParagraph().layout().name());
countCategories();
// needed to recalculate size hint // needed to recalculate size hint
hide(); hide();
setMinimumWidth(sizeHint().width()); setMinimumWidth(sizeHint().width());

View File

@ -18,26 +18,27 @@
#include "Session.h" #include "Session.h"
#include <QAbstractProxyModel>
#include <QComboBox>
#include <QList> #include <QList>
#include <QToolBar> #include <QToolBar>
#include <QComboBox>
class QSortFilterProxyModel;
class QStandardItemModel; class QStandardItemModel;
namespace lyx { namespace lyx {
class Inset;
class DocumentClass; class DocumentClass;
class Inset;
class ToolbarItem; class ToolbarItem;
namespace frontend { namespace frontend {
class FilterItemDelegate;
class GuiCommandBuffer;
class GuiFilterProxyModel;
class GuiView;
class Action; class Action;
class GuiCommandBuffer;
class GuiLayoutFilterModel;
class GuiView;
class LayoutItemDelegate;
class GuiLayoutBox : public QComboBox class GuiLayoutBox : public QComboBox
{ {
@ -50,7 +51,8 @@ public:
/// Populate the layout combobox. /// Populate the layout combobox.
void updateContents(bool reset); void updateContents(bool reset);
/// Add Item to Layout box according to sorting settings from preferences /// Add Item to Layout box according to sorting settings from preferences
void addItemSort(docstring const & item, bool sorted); void addItemSort(docstring const & item, docstring const & category,
bool sorted, bool sortedByCat);
/// ///
void showPopup(); void showPopup();
@ -65,11 +67,17 @@ private Q_SLOTS:
void selected(int index); void selected(int index);
private: private:
friend class LayoutItemDelegate;
/// ///
void resetFilter(); void resetFilter();
/// ///
void setFilter(QString const & s); void setFilter(QString const & s);
///
QString charFilterRegExp(QString const & filter);
///
void countCategories();
/// ///
GuiView & owner_; GuiView & owner_;
/// ///
@ -80,13 +88,17 @@ private:
/// the layout model: 1st column translated, 2nd column raw layout name /// the layout model: 1st column translated, 2nd column raw layout name
QStandardItemModel * model_; QStandardItemModel * model_;
/// the proxy model filtering \c model_ /// the proxy model filtering \c model_
GuiFilterProxyModel * filterModel_; GuiLayoutFilterModel * filterModel_;
/// the (model-) index of the last successful selection /// the (model-) index of the last successful selection
int lastSel_; int lastSel_;
/// the character filter /// the character filter
QString filter_; QString filter_;
/// ///
FilterItemDelegate * filterItemDelegate_; LayoutItemDelegate * layoutItemDelegate_;
///
unsigned visibleCategories_;
///
bool inShowPopup_;
}; };

View File

@ -5,14 +5,12 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>430</width> <width>459</width>
<height>582</height> <height>596</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -21,12 +19,6 @@
<string/> <string/>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="2" column="0" colspan="3" > <item row="2" column="0" colspan="3" >
<widget class="QGroupBox" name="GeometryGB" > <widget class="QGroupBox" name="GeometryGB" >
<property name="title" > <property name="title" >
@ -36,10 +28,10 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" > <property name="horizontalSpacing" >
<number>9</number> <number>4</number>
</property> </property>
<property name="spacing" > <property name="verticalSpacing" >
<number>4</number> <number>4</number>
</property> </property>
<item row="0" column="0" > <item row="0" column="0" >
@ -84,12 +76,6 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item rowspan="3" row="0" column="2" > <item rowspan="3" row="0" column="2" >
<widget class="QGroupBox" name="fullscreenLimitGB" > <widget class="QGroupBox" name="fullscreenLimitGB" >
<property name="title" > <property name="title" >
@ -99,20 +85,14 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" > <item row="0" column="1" >
<widget class="QSpinBox" name="fullscreenWidthSB" > <widget class="QSpinBox" name="fullscreenWidthSB" >
<property name="maximum" >
<number>10000</number>
</property>
<property name="minimum" > <property name="minimum" >
<number>0</number> <number>0</number>
</property> </property>
<property name="maximum" >
<number>10000</number>
</property>
<property name="singleStep" > <property name="singleStep" >
<number>10</number> <number>10</number>
</property> </property>
@ -164,9 +144,7 @@
<item row="0" column="0" > <item row="0" column="0" >
<widget class="QCheckBox" name="toggleToolbarsCB" > <widget class="QCheckBox" name="toggleToolbarsCB" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy> <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -191,10 +169,10 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" > <property name="horizontalSpacing" >
<number>9</number> <number>4</number>
</property> </property>
<property name="spacing" > <property name="verticalSpacing" >
<number>4</number> <number>4</number>
</property> </property>
<item row="0" column="0" > <item row="0" column="0" >
@ -207,11 +185,11 @@
<item row="1" column="0" > <item row="1" column="0" >
<widget class="QCheckBox" name="sortEnvironmentsCB" > <widget class="QCheckBox" name="sortEnvironmentsCB" >
<property name="text" > <property name="text" >
<string>Sort &amp;Environments alphabetically</string> <string>Sort &amp;environments alphabetically</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" > <item row="3" column="0" >
<widget class="QComboBox" name="macroEditStyleCO" > <widget class="QComboBox" name="macroEditStyleCO" >
<item> <item>
<property name="text" > <property name="text" >
@ -230,6 +208,13 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="2" column="0" >
<widget class="QCheckBox" name="groupEnvironmentsCB" >
<property name="text" >
<string>&amp;Group environments by their category</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -242,20 +227,8 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" colspan="4" > <item row="1" column="0" colspan="4" >
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item> <item>
<widget class="QLabel" name="lastfilesLA" > <widget class="QLabel" name="lastfilesLA" >
<property name="text" > <property name="text" >
@ -310,12 +283,12 @@
</item> </item>
<item row="0" column="1" > <item row="0" column="1" >
<widget class="QSpinBox" name="autoSaveSB" > <widget class="QSpinBox" name="autoSaveSB" >
<property name="maximum" >
<number>300</number>
</property>
<property name="minimum" > <property name="minimum" >
<number>1</number> <number>1</number>
</property> </property>
<property name="maximum" >
<number>300</number>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="0" > <item row="0" column="0" >
@ -353,10 +326,10 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" > <layout class="QGridLayout" >
<property name="margin" > <property name="horizontalSpacing" >
<number>9</number> <number>4</number>
</property> </property>
<property name="spacing" > <property name="verticalSpacing" >
<number>4</number> <number>4</number>
</property> </property>
<item row="0" column="0" > <item row="0" column="0" >