mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-09 00:58:15 +03:00
provide thick,length margins for layout icon
This commit is contained in:
parent
11c3f2a664
commit
2fc50d255a
@ -176,23 +176,26 @@ void drawBackground(QPainter *painter, const QStyle *style, const QStyleOptionMe
|
||||
style->drawControl(QStyle::CE_MenuItem, &backOption, painter);
|
||||
}
|
||||
|
||||
QRect remainedFromLayoutIcon(const QStyleOption &option, Qt::AlignmentFlag alignment)
|
||||
QRect remainedFromLayoutIcon(const QStyleOption &option, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
|
||||
{
|
||||
if (alignment == Qt::AlignHCenter) {
|
||||
return option.rect;
|
||||
}
|
||||
|
||||
return remainedFromIcon(option, alignment);
|
||||
return remainedFromIcon(option, alignment, lengthMargin, thickMargin);
|
||||
}
|
||||
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const bool &isBackgroundFile, const QString &iconName, Qt::AlignmentFlag alignment)
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const bool &isBackgroundFile, const QString &iconName, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
|
||||
{
|
||||
bool active = Latte::isActive(option);
|
||||
bool selected = Latte::isSelected(option);
|
||||
bool focused = Latte::isFocused(option);
|
||||
|
||||
int iconsize = option.rect.height() - 2*ICONMARGIN;
|
||||
int total = iconsize + 2*ICONMARGIN + 2*MARGIN;
|
||||
int lenmargin = (lengthMargin == -1 ? ICONMARGIN + MARGIN : lengthMargin);
|
||||
int thickmargin = (thickMargin == -1 ? ICONMARGIN : thickMargin);
|
||||
|
||||
int iconsize = option.rect.height() - 2*thickMargin;
|
||||
int total = iconsize + 2*lenmargin;
|
||||
|
||||
Qt::AlignmentFlag curalign = alignment;
|
||||
|
||||
@ -205,12 +208,12 @@ void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const bool &i
|
||||
QRect target;
|
||||
|
||||
if (curalign == Qt::AlignLeft) {
|
||||
target = QRect(option.rect.x() + MARGIN + ICONMARGIN, option.rect.y() + ICONMARGIN, iconsize, iconsize);
|
||||
target = QRect(option.rect.x() + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
|
||||
} else if (curalign == Qt::AlignRight) {
|
||||
target = QRect(option.rect.x() + option.rect.width() - total + ICONMARGIN + MARGIN, option.rect.y() + ICONMARGIN, iconsize, iconsize);
|
||||
target = QRect(option.rect.x() + option.rect.width() - total + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
|
||||
} else {
|
||||
//! centered
|
||||
target = QRect(option.rect.x() + ((option.rect.width() - total)/2) + ICONMARGIN + MARGIN, option.rect.y() + ICONMARGIN, iconsize, iconsize);
|
||||
target = QRect(option.rect.x() + ((option.rect.width() - total)/2) + lenmargin, option.rect.y() + thickmargin, iconsize, iconsize);
|
||||
}
|
||||
|
||||
painter->save();
|
||||
@ -242,10 +245,13 @@ void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const bool &i
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment)
|
||||
QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
|
||||
{
|
||||
int iconsize = option.rect.height() - 2*MARGIN;
|
||||
int total = iconsize + 2*ICONMARGIN + 2*MARGIN;
|
||||
int lenmargin = (lengthMargin == -1 ? ICONMARGIN + MARGIN : lengthMargin);
|
||||
int thickmargin = (thickMargin == -1 ? ICONMARGIN : thickMargin);
|
||||
|
||||
int iconsize = option.rect.height() - 2*thickMargin;
|
||||
int total = iconsize + 2*lenmargin;
|
||||
|
||||
Qt::AlignmentFlag curalign = alignment;
|
||||
|
||||
@ -262,10 +268,13 @@ QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment)
|
||||
return optionRemainedRect;
|
||||
}
|
||||
|
||||
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon, Qt::AlignmentFlag alignment)
|
||||
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon, Qt::AlignmentFlag alignment, int lengthMargin, int thickMargin)
|
||||
{
|
||||
int iconsize = option.rect.height() - 2*MARGIN;
|
||||
int total = iconsize + 2*ICONMARGIN + 2*MARGIN;
|
||||
int lenmargin = (lengthMargin == -1 ? ICONMARGIN + MARGIN : lengthMargin);
|
||||
int thickmargin = (thickMargin == -1 ? ICONMARGIN : thickMargin);
|
||||
|
||||
int iconsize = option.rect.height() - 2*thickMargin;
|
||||
int total = iconsize + 2*lenmargin;
|
||||
|
||||
bool active = Latte::isActive(option);
|
||||
bool selected = Latte::isSelected(option);
|
||||
@ -284,9 +293,9 @@ void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon
|
||||
QRect target;
|
||||
|
||||
if (curalign == Qt::AlignLeft) {
|
||||
target = QRect(option.rect.x() + MARGIN + ICONMARGIN, option.rect.y(), iconsize, iconsize);
|
||||
target = QRect(option.rect.x() + lenmargin, option.rect.y(), iconsize, iconsize);
|
||||
} else {
|
||||
target = QRect(option.rect.x() + option.rect.width() - total + ICONMARGIN + MARGIN, option.rect.y(), iconsize, iconsize);
|
||||
target = QRect(option.rect.x() + option.rect.width() - total + lenmargin, option.rect.y(), iconsize, iconsize);
|
||||
}
|
||||
|
||||
painter->drawPixmap(target, QIcon::fromTheme(icon).pixmap(target.height(), target.height(), mode));
|
||||
|
@ -50,12 +50,12 @@ void drawBackground(QPainter *painter, const QStyleOptionViewItem &option);
|
||||
void drawBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option);
|
||||
|
||||
//! simple icon
|
||||
QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment = Qt::AlignLeft);
|
||||
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon, Qt::AlignmentFlag alignment = Qt::AlignLeft);
|
||||
QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment = Qt::AlignLeft, int lengthMargin = -1, int thickMargin = -1);
|
||||
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon, Qt::AlignmentFlag alignment = Qt::AlignLeft, int lengthMargin = -1, int thickMargin = -1);
|
||||
|
||||
//! layout icon
|
||||
QRect remainedFromLayoutIcon(const QStyleOption &option, Qt::AlignmentFlag alignment = Qt::AlignLeft);
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const bool &isBackgroundFile, const QString &iconName, Qt::AlignmentFlag alignment = Qt::AlignLeft);
|
||||
QRect remainedFromLayoutIcon(const QStyleOption &option, Qt::AlignmentFlag alignment = Qt::AlignLeft, int lengthMargin = -1, int thickMargin = -1);
|
||||
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const bool &isBackgroundFile, const QString &iconName, Qt::AlignmentFlag alignment = Qt::AlignLeft, int lengthMargin = -1, int thickMargin = -1);
|
||||
|
||||
//! changes indicator
|
||||
QRect remainedFromChangesIndicator(const QStyleOptionViewItem &option);
|
||||
|
@ -63,27 +63,27 @@ void LayoutsComboBox::paintEvent(QPaintEvent *event)
|
||||
// draw the combobox frame, focusrect and selected etc.
|
||||
QStyleOptionComboBox opt;
|
||||
initStyleOption(&opt);
|
||||
|
||||
// background
|
||||
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
|
||||
|
||||
//! Adjust text and layout icon accordingly
|
||||
int thick = opt.rect.height() - 2 * VERTMARGIN;
|
||||
QStyleOptionComboBox iconOpt = opt;
|
||||
iconOpt.rect = QRect(opt.rect.x() + MARGIN, opt.rect.y() + VERTMARGIN, opt.rect.width() - 2*MARGIN, opt.rect.height() - 2 * VERTMARGIN);
|
||||
QRect remained = Latte::remainedFromLayoutIcon(iconOpt, Qt::AlignLeft);
|
||||
|
||||
Latte::drawLayoutIcon(&painter, iconOpt, m_layoutIcon.isBackgroundFile, m_layoutIcon.name, Qt::AlignLeft);
|
||||
// icon
|
||||
QRect remained = Latte::remainedFromLayoutIcon(opt, Qt::AlignLeft, 3, 3);
|
||||
Latte::drawLayoutIcon(&painter, opt, m_layoutIcon.isBackgroundFile, m_layoutIcon.name, Qt::AlignLeft, 7, 4);
|
||||
opt.rect = remained;
|
||||
|
||||
// adjust text place, move it a bit to the left
|
||||
QRect textRect;
|
||||
|
||||
int textnegativepad = MARGIN + 1;
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
textRect = QRect(remained.x() - 2*MARGIN, opt.rect.y(), remained.width() + 4*MARGIN, opt.rect.height());
|
||||
textRect = QRect(remained.x() - textnegativepad, opt.rect.y(), remained.width() + 2*textnegativepad, opt.rect.height());
|
||||
} else {
|
||||
textRect = QRect(remained.x(), opt.rect.y(), remained.width() + 4*MARGIN, opt.rect.height());
|
||||
textRect = QRect(remained.x(), opt.rect.y(), remained.width() + 2 * textnegativepad, opt.rect.height());
|
||||
}
|
||||
opt.rect = textRect;
|
||||
|
||||
QStyleOptionComboBox adjOpt = opt;
|
||||
adjOpt.rect = textRect;
|
||||
painter.drawControl(QStyle::CE_ComboBoxLabel, adjOpt);
|
||||
// text
|
||||
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
|
||||
|
||||
}
|
||||
|
||||
|
@ -49,9 +49,7 @@ void BackgroundDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
||||
|
||||
//! background
|
||||
Latte::drawBackground(painter, option);
|
||||
|
||||
myOptions.rect = QRect(option.rect.x(), option.rect.y() + 1, option.rect.width(), option.rect.height() - 2);
|
||||
Latte::drawLayoutIcon(painter, myOptions, icon.isBackgroundFile, icon.name, Qt::AlignHCenter);
|
||||
Latte::drawLayoutIcon(painter, option, icon.isBackgroundFile, icon.name, Qt::AlignHCenter, -1, 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,8 +35,6 @@ namespace Settings {
|
||||
namespace Layout {
|
||||
namespace Delegate {
|
||||
|
||||
const int MARGIN = 1;
|
||||
|
||||
LayoutCmbItemDelegate::LayoutCmbItemDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
@ -46,14 +44,16 @@ void LayoutCmbItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||
{
|
||||
QStyleOptionViewItem myOptions = option;
|
||||
|
||||
//! dbackground
|
||||
//! background
|
||||
Latte::drawBackground(painter, option);
|
||||
Latte::Data::LayoutIcon icon = index.data(Model::Layouts::BACKGROUNDUSERROLE).value<Latte::Data::LayoutIcon>();
|
||||
|
||||
QRect remained = Latte::remainedFromLayoutIcon(option, Qt::AlignLeft);
|
||||
Latte::drawLayoutIcon(painter, option, icon.isBackgroundFile, icon.name, Qt::AlignLeft);
|
||||
|
||||
//! icon
|
||||
QRect remained = Latte::remainedFromLayoutIcon(myOptions, Qt::AlignLeft, 4, 0);
|
||||
Latte::drawLayoutIcon(painter, myOptions, icon.isBackgroundFile, icon.name, Qt::AlignLeft, 5, 0); //+1px in order to take into account popup window border
|
||||
myOptions.rect = remained;
|
||||
|
||||
//!
|
||||
QStyledItemDelegate::paint(painter, myOptions, index);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ LayoutMenuItemWidget::LayoutMenuItemWidget(QAction* action, QWidget *parent)
|
||||
auto radiobtn = new QRadioButton(this);
|
||||
radiobtn->setCheckable(true);
|
||||
radiobtn->setChecked(action->isChecked());
|
||||
|
||||
radiobtn->setVisible(action->isVisible() && action->isCheckable());
|
||||
|
||||
l->addWidget(radiobtn);
|
||||
@ -80,8 +79,10 @@ void LayoutMenuItemWidget::paintEvent(QPaintEvent* e)
|
||||
opt.state |= QStyle::State_Selected;
|
||||
}
|
||||
|
||||
//! background
|
||||
Latte::drawBackground(&painter, style(), opt);
|
||||
|
||||
//! radio button
|
||||
int radiosize = opt.rect.height();
|
||||
QRect remained;
|
||||
|
||||
@ -93,26 +94,12 @@ void LayoutMenuItemWidget::paintEvent(QPaintEvent* e)
|
||||
|
||||
opt.rect = remained;
|
||||
|
||||
int iconlengthmargin = 4*MARGIN + ICONMARGIN;
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
remained = QRect(opt.rect.x() + radiosize - iconlengthmargin , opt.rect.y(), opt.rect.width() - radiosize - iconlengthmargin, opt.rect.height());
|
||||
} else {
|
||||
remained = QRect(opt.rect.x() , opt.rect.y(), opt.rect.width() - radiosize - iconlengthmargin, opt.rect.height());
|
||||
}
|
||||
|
||||
QStyleOptionMenuItem iconOpt = opt;
|
||||
int iconthickmargin = MARGIN + ICONMARGIN;
|
||||
int textlengthmargin = 2*MARGIN + ICONMARGIN;
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
iconOpt.rect = QRect(opt.rect.x() - textlengthmargin, opt.rect.y() + iconthickmargin, opt.rect.width(), opt.rect.height() - 2*iconthickmargin);
|
||||
} else {
|
||||
iconOpt.rect = QRect(opt.rect.x() + opt.rect.width() + textlengthmargin, opt.rect.y() + iconthickmargin, opt.rect.width(), opt.rect.height() - 2*iconthickmargin);
|
||||
}
|
||||
|
||||
//remained = Latte::remainedFromLayoutIcon(opt, Qt::AlignLeft);
|
||||
Latte::drawLayoutIcon(&painter, iconOpt, m_isBackgroundFile, m_iconName, Qt::AlignLeft);
|
||||
//! icon
|
||||
remained = Latte::remainedFromLayoutIcon(opt, Qt::AlignLeft, 0, 3);
|
||||
Latte::drawLayoutIcon(&painter, opt, m_isBackgroundFile, m_iconName, Qt::AlignLeft, 0, 3);
|
||||
opt.rect = remained;
|
||||
|
||||
//! text
|
||||
style()->drawControl(QStyle::CE_MenuItem, &opt, &painter, this);
|
||||
|
||||
painter.restore();
|
||||
|
Loading…
x
Reference in New Issue
Block a user