* reduce spacing in layout list

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23638 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-03-10 15:41:30 +00:00
parent 2ab77c16f6
commit 06a5803eab

View File

@ -46,6 +46,7 @@
#include <QAbstractItemDelegate> #include <QAbstractItemDelegate>
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QApplication> #include <QApplication>
#include <QClearLook>
#include <QComboBox> #include <QComboBox>
#include <QFontMetrics> #include <QFontMetrics>
#include <QHeaderView> #include <QHeaderView>
@ -54,6 +55,7 @@
#include <QListView> #include <QListView>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
#include <QPlastiqueStyle>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStandardItem> #include <QStandardItem>
#include <QStandardItemModel> #include <QStandardItemModel>
@ -267,7 +269,6 @@ public:
painter->eraseRect(opt.rect); painter->eraseRect(opt.rect);
QFontMetrics fm(opt.font);
QString text = underlineFilter(opt.text); QString text = underlineFilter(opt.text);
opt.text = QString(); opt.text = QString();
@ -284,7 +285,8 @@ public:
paintCategoryHeader(painter, opt, paintCategoryHeader(painter, opt,
category(*index.model(), index.row())); category(*index.model(), index.row()));
opt.rect.setTop(opt.rect.top() + headerHeight(opt)); // move rect down below header
opt.rect.moveTop(opt.rect.top() + headerHeight(opt));
opt.menuRect = opt.rect; opt.menuRect = opt.rect;
} }
} }
@ -313,7 +315,7 @@ public:
doc.rootFrame()->setFrameFormat(fmt); doc.rootFrame()->setFrameFormat(fmt);
painter->translate(opt.rect.x() + 5, painter->translate(opt.rect.x() + 5,
opt.rect.y() + (opt.rect.height() - fm.height()) / 2); opt.rect.y() + (opt.rect.height() - opt.fontMetrics.height()) / 2);
doc.documentLayout()->draw(painter, context); doc.documentLayout()->draw(painter, context);
painter->restore(); painter->restore();
} }
@ -325,10 +327,13 @@ public:
GuiLayoutBox * combo = static_cast<GuiLayoutBox *>(parent()); GuiLayoutBox * combo = static_cast<GuiLayoutBox *>(parent());
QSortFilterProxyModel const * model QSortFilterProxyModel const * model
= static_cast<QSortFilterProxyModel const *>(index.model()); = static_cast<QSortFilterProxyModel const *>(index.model());
// we use a compressed menu style here
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, opt.rect.size(), combo);
size.setHeight(opt.rect.height());
/// QComboBox uses the first row height to estimate the /// QComboBox uses the first row height to estimate the
/// complete popup height during QComboBox::showPopup(). /// complete popup height during QComboBox::showPopup().
/// To avoid scrolling we have to sneak in space for the headers. /// To avoid scrolling we have to sneak in space for the headers.
@ -389,8 +394,7 @@ private:
/// ///
int headerHeight(QStyleOptionMenuItem const & opt) const int headerHeight(QStyleOptionMenuItem const & opt) const
{ {
QFontMetrics fm(opt.font); return opt.fontMetrics.height() * 8 / 10;
return fm.height() * 8 / 10;
} }
/// ///
void paintCategoryHeader(QPainter * painter, QStyleOptionMenuItem const & opt, void paintCategoryHeader(QPainter * painter, QStyleOptionMenuItem const & opt,
@ -412,7 +416,7 @@ private:
// draw the centered text // draw the centered text
QFontMetrics fm(font); QFontMetrics fm(font);
int w = fm.width(category); int w = opt.fontMetrics.width(category);
int x = opt.rect.x() + (opt.rect.width() - w) / 2; int x = opt.rect.x() + (opt.rect.width() - w) / 2;
int y = opt.rect.y() + fm.ascent(); int y = opt.rect.y() + fm.ascent();
int left = x; int left = x;
@ -473,10 +477,11 @@ private:
QStyleOptionMenuItem menuOption; QStyleOptionMenuItem menuOption;
menuOption.palette = QApplication::palette("QMenu"); menuOption.palette = QApplication::palette("QMenu");
menuOption.state = QStyle::State_Active | QStyle::State_Enabled; menuOption.state = QStyle::State_Active | QStyle::State_Enabled;
menuOption.menuRect = option.rect;
menuOption.rect = option.rect;
menuOption.font = combo->font(); menuOption.font = combo->font();
menuOption.fontMetrics = QFontMetrics(menuOption.font); menuOption.fontMetrics = QFontMetrics(menuOption.font);
menuOption.rect = option.rect;
menuOption.rect.setHeight(menuOption.fontMetrics.height() + 2);
menuOption.menuRect = menuOption.rect;
menuOption.tabWidth = 0; menuOption.tabWidth = 0;
menuOption.text = index.model()->data(index, Qt::DisplayRole).toString() menuOption.text = index.model()->data(index, Qt::DisplayRole).toString()
.replace(QLatin1Char('&'), QLatin1String("&&")); .replace(QLatin1Char('&'), QLatin1String("&&"));