mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-09 00:58:15 +03:00
improve layouts menu items spacing
This commit is contained in:
parent
cf1a008791
commit
e241a79385
@ -119,9 +119,17 @@ QStringList subtracted(const QStringList &original, const QStringList ¤t)
|
||||
|
||||
void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, const float textOpacity)
|
||||
{
|
||||
painter->save();
|
||||
drawFormattedText(painter, option, option.text, Latte::isTextCentered(option), textOpacity);
|
||||
}
|
||||
|
||||
bool isTextCentered = Latte::isTextCentered(option);
|
||||
void drawFormattedText(QPainter *painter, const QStyleOptionMenuItem &option, const float textOpacity)
|
||||
{
|
||||
drawFormattedText(painter, option, option.text, false, textOpacity);
|
||||
}
|
||||
|
||||
void drawFormattedText(QPainter *painter, const QStyleOption &option, const QString &text, const bool &isTextCentered, const float textOpacity)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QPalette::ColorRole applyColor = Latte::isSelected(option) ? QPalette::HighlightedText : QPalette::Text;
|
||||
QBrush nBrush = option.palette.brush(Latte::colorGroup(option), applyColor);
|
||||
@ -133,7 +141,7 @@ void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
|
||||
QTextDocument doc;
|
||||
doc.setDefaultStyleSheet(css);
|
||||
doc.setHtml("<body>" + option.text + "</body>");
|
||||
doc.setHtml("<body>" + text + "</body>");
|
||||
|
||||
//we need an offset to be in the same vertical center of TextEdit
|
||||
int offsetY = ((option.rect.height() - doc.size().height()) / 2);
|
||||
|
@ -44,6 +44,8 @@ QPalette::ColorGroup colorGroup(const QStyleOption &option);
|
||||
QStringList subtracted(const QStringList &original, const QStringList ¤t);
|
||||
|
||||
void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, const float textOpacity = 1.0);
|
||||
void drawFormattedText(QPainter *painter, const QStyleOptionMenuItem &option, const float textOpacity = 1.0);
|
||||
void drawFormattedText(QPainter *painter, const QStyleOption &option, const QString &text, const bool &isTextCentered = false, const float textOpacity = 1.0);
|
||||
|
||||
//! background
|
||||
void drawBackground(QPainter *painter, const QStyleOptionViewItem &option);
|
||||
|
@ -87,7 +87,8 @@ void CustomMenuItemWidget::paintEvent(QPaintEvent* e)
|
||||
|
||||
Latte::drawBackground(&painter, style(), opt);
|
||||
|
||||
int radiosize = opt.rect.height() + 2;
|
||||
//! radio button
|
||||
int radiosize = opt.rect.height();
|
||||
QRect remained;
|
||||
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
@ -109,7 +110,21 @@ void CustomMenuItemWidget::paintEvent(QPaintEvent* e)
|
||||
}
|
||||
|
||||
opt.rect = remained;
|
||||
style()->drawControl(QStyle::CE_MenuItem, &opt, &painter, this);
|
||||
|
||||
//! text
|
||||
opt.text = opt.text.remove("&");
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
//! add spacing
|
||||
remained = QRect(opt.rect.x() + 2 , opt.rect.y(), opt.rect.width() - 2, opt.rect.height());
|
||||
} else {
|
||||
//! add spacing
|
||||
remained = QRect(opt.rect.x() , opt.rect.y(), opt.rect.width() - 2, opt.rect.height());
|
||||
}
|
||||
|
||||
opt.rect = remained;
|
||||
|
||||
//style()->drawControl(QStyle::CE_MenuItem, &opt, &painter, this);
|
||||
Latte::drawFormattedText(&painter, opt);
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
@ -60,6 +60,7 @@ QSize LayoutMenuItemWidget::minimumSizeHint() const
|
||||
{
|
||||
QStyleOptionMenuItem opt;
|
||||
QSize contentSize = fontMetrics().size(Qt::TextSingleLine | Qt::TextShowMnemonic, m_action->text());
|
||||
|
||||
contentSize.setHeight(contentSize.height() + 9);
|
||||
contentSize.setWidth(contentSize.width() + 4 * contentSize.height());
|
||||
return style()->sizeFromContents(QStyle::CT_MenuItem, &opt, contentSize, this);
|
||||
@ -95,12 +96,14 @@ void LayoutMenuItemWidget::paintEvent(QPaintEvent* e)
|
||||
opt.rect = remained;
|
||||
|
||||
//! icon
|
||||
remained = Latte::remainedFromLayoutIcon(opt, Qt::AlignLeft, 0, 3);
|
||||
remained = Latte::remainedFromLayoutIcon(opt, Qt::AlignLeft, 2, 3); //we need this padding for spacing
|
||||
Latte::drawLayoutIcon(&painter, opt, m_isBackgroundFile, m_iconName, Qt::AlignLeft, 0, 3);
|
||||
opt.rect = remained;
|
||||
|
||||
//! text
|
||||
style()->drawControl(QStyle::CE_MenuItem, &opt, &painter, this);
|
||||
opt.text = opt.text.remove("&");
|
||||
//style()->drawControl(QStyle::CE_MenuItem, &opt, &painter, this);
|
||||
Latte::drawFormattedText(&painter, opt);
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user