mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-11 13:18:13 +03:00
settings:decouple layout icon for active layout
--favorites icon is now moved in layout name edit box and is going to indicate only the Active layouts at some point
This commit is contained in:
parent
1348863b57
commit
4fa7831bc5
@ -79,16 +79,17 @@ void LayoutName::drawHasChangesIndicator(QPainter *painter, const QStyleOptionVi
|
||||
{
|
||||
//! draw changes circle indicator
|
||||
int csize{INDICATORCHANGESLENGTH};
|
||||
int tsize{INDICATORCHANGESLENGTH + INDICATORCHANGESMARGIN*2};
|
||||
|
||||
//! Draw indicator background
|
||||
QStandardItemModel *model = (QStandardItemModel *) index.model();
|
||||
if (qApp->layoutDirection() == Qt::RightToLeft) {
|
||||
QStyleOptionViewItem indicatorOption = option;
|
||||
indicatorOption.rect = QRect(option.rect.x(), option.rect.y(), csize + INDICATORCHANGESMARGIN, option.rect.height());
|
||||
indicatorOption.rect = QRect(option.rect.x(), option.rect.y(), tsize, option.rect.height());
|
||||
QStyledItemDelegate::paint(painter, indicatorOption, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
|
||||
} else {
|
||||
QStyleOptionViewItem indicatorOption = option;
|
||||
indicatorOption.rect = QRect(option.rect.x() + option.rect.width() - csize - INDICATORCHANGESMARGIN, option.rect.y(), csize + INDICATORCHANGESMARGIN, option.rect.height());
|
||||
indicatorOption.rect = QRect(option.rect.x() + option.rect.width() - tsize, option.rect.y(), tsize, option.rect.height());
|
||||
QStyledItemDelegate::paint(painter, indicatorOption, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
|
||||
}
|
||||
|
||||
@ -125,6 +126,7 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
QString name = index.data(Qt::UserRole).toString();
|
||||
|
||||
bool isChanged = (isNewLayout || hasChanges);
|
||||
bool drawTwoIcons = isLocked && isActive;
|
||||
|
||||
QStyleOptionViewItem adjustedOption = option;
|
||||
|
||||
@ -134,13 +136,13 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
int indicatorLength = INDICATORCHANGESLENGTH + INDICATORCHANGESMARGIN;
|
||||
int indicatorLength = INDICATORCHANGESLENGTH + INDICATORCHANGESMARGIN * 2;
|
||||
QRect optionRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x() + indicatorLength, option.rect.y(), option.rect.width() - indicatorLength, option.rect.height()) :
|
||||
QRect(option.rect.x(), option.rect.y(), option.rect.width() - indicatorLength, option.rect.height());
|
||||
|
||||
adjustedOption.rect = optionRect;
|
||||
|
||||
if (isLocked) {
|
||||
if (isLocked || isActive) {
|
||||
QStandardItemModel *model = (QStandardItemModel *) index.model();
|
||||
|
||||
bool active = Latte::isActive(option);
|
||||
@ -153,7 +155,7 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
QFontMetrics fm(option.font);
|
||||
int textWidth = fm.boundingRect(name).width();
|
||||
int thick = optionRect.height();
|
||||
int length = thick;
|
||||
int length = drawTwoIcons ? (2*thick /*+ 2*/) : thick;
|
||||
|
||||
int startWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? length : 0;
|
||||
int endWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? 0 : length;
|
||||
@ -180,15 +182,33 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
QStyledItemDelegate::paint(painter, myOptionS, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
|
||||
QStyledItemDelegate::paint(painter, myOptionE, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
|
||||
|
||||
//! First Icon
|
||||
QIcon firstIcon = isLocked && !drawTwoIcons ? QIcon::fromTheme("object-locked") : QIcon::fromTheme("favorites");
|
||||
QIcon::Mode mode = ((active && (selected || focused)) ? QIcon::Selected : QIcon::Normal);
|
||||
|
||||
if (isLocked) {
|
||||
QIcon lockIcon = QIcon::fromTheme("object-locked");
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
int firstIconX = optionRect.x() + optionRect.width() - endWidth;
|
||||
painter->drawPixmap(QRect(firstIconX, optionRect.y(), thick, thick), firstIcon.pixmap(thick, thick, mode));
|
||||
|
||||
if (qApp->layoutDirection() == Qt::RightToLeft) {
|
||||
painter->drawPixmap(QRect(optionRect.x(), optionRect.y(), thick, thick), lockIcon.pixmap(thick, thick, mode));
|
||||
} else {
|
||||
painter->drawPixmap(QRect(optionRect.x() + optionRect.width() - endWidth, optionRect.y(), thick, thick), lockIcon.pixmap(thick, thick, mode));
|
||||
//debug
|
||||
//painter->drawLine(firstIconX, optionRect.y(), firstIconX, optionRect.y()+thick);
|
||||
//painter->drawLine(firstIconX+thick - 1, optionRect.y(), firstIconX+thick - 1, optionRect.y()+thick);
|
||||
|
||||
if (drawTwoIcons) {
|
||||
int secondIconX = optionRect.x() + optionRect.width() - thick;
|
||||
QIcon secondIcon = QIcon::fromTheme("object-locked");
|
||||
painter->drawPixmap(QRect(secondIconX, optionRect.y(), thick, thick), secondIcon.pixmap(thick, thick, mode));
|
||||
|
||||
//debug
|
||||
//painter->drawLine(secondIconX, optionRect.y(), secondIconX, optionRect.y()+thick);
|
||||
//painter->drawLine(secondIconX + thick - 1, optionRect.y(), secondIconX + thick - 1,optionRect.y()+thick);
|
||||
}
|
||||
} else {
|
||||
painter->drawPixmap(QRect(optionRect.x(), optionRect.y(), thick, thick), firstIcon.pixmap(thick, thick, mode));
|
||||
|
||||
if (drawTwoIcons) {
|
||||
QIcon secondIcon = QIcon::fromTheme("object-locked");
|
||||
painter->drawPixmap(QRect(optionRect.x() + thick, optionRect.y(), thick, thick), secondIcon.pixmap(thick, thick, mode));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,6 +217,7 @@ void Layouts::resetData()
|
||||
clear();
|
||||
setOriginalInMultipleMode(o_inMultipleMode);
|
||||
setOriginalData(o_layoutsTable);
|
||||
updateActiveStates();
|
||||
}
|
||||
|
||||
void Layouts::removeLayout(const QString &id)
|
||||
@ -404,6 +405,15 @@ QList<Latte::Data::LayoutIcon> Layouts::iconsForCentralLayout(const int &row) co
|
||||
{
|
||||
QList<Latte::Data::LayoutIcon> icons;
|
||||
|
||||
if (!m_layoutsTable[row].icon.isEmpty()) {
|
||||
//! if there is specific icon set from the user for this layout we draw only that icon
|
||||
Latte::Data::LayoutIcon icon;
|
||||
icon.name = m_layoutsTable[row].icon;
|
||||
icon.isBackgroundFile = false;
|
||||
icons << icon;
|
||||
return icons;
|
||||
}
|
||||
|
||||
if (inMultipleMode()) {
|
||||
if (m_layoutsTable[row].activities.contains(Latte::Data::Layout::ALLACTIVITIESID)) {
|
||||
Latte::Data::LayoutIcon icon;
|
||||
@ -425,29 +435,14 @@ QList<Latte::Data::LayoutIcon> Layouts::iconsForCentralLayout(const int &row) co
|
||||
icon.name = m_activitiesTable[id].icon;
|
||||
icon.isBackgroundFile = false;
|
||||
icons << icon;
|
||||
//! first activity icon found
|
||||
return icons;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (o_layoutsTable.containsId(m_layoutsTable[row].id) && o_layoutsTable[m_layoutsTable[row].id].name == m_corona->universalSettings()->singleModeLayoutName()) {
|
||||
Latte::Data::LayoutIcon icon;
|
||||
icon.name = m_activitiesTable[Latte::Data::Layout::ALLACTIVITIESID].icon;
|
||||
icon.isBackgroundFile = false;
|
||||
icons << icon;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_layoutsTable[row].icon.isEmpty()) {
|
||||
//! if there is specific icon set from the user for this layout we draw only that icon
|
||||
icons.clear();
|
||||
Latte::Data::LayoutIcon icon;
|
||||
icon.name = m_layoutsTable[row].icon;
|
||||
icon.isBackgroundFile = false;
|
||||
icons << icon;
|
||||
return icons;
|
||||
}
|
||||
|
||||
//! background image
|
||||
//! fallback icon: background image
|
||||
if (icons.count() == 0) {
|
||||
QString colorPath;
|
||||
|
||||
@ -904,21 +899,21 @@ void Layouts::initActivities()
|
||||
Latte::Data::Activity allActivities;
|
||||
allActivities.id = Latte::Data::Layout::ALLACTIVITIESID;
|
||||
allActivities.name = QString("[ " + i18n("All Activities") + " ]");
|
||||
allActivities.icon = "favorites";
|
||||
allActivities.icon = "activities";
|
||||
allActivities.state = KActivities::Info::Stopped;
|
||||
m_activitiesTable << allActivities;
|
||||
|
||||
Latte::Data::Activity freeActivities;
|
||||
freeActivities.id = Latte::Data::Layout::FREEACTIVITIESID;
|
||||
freeActivities.name = QString("[ " + i18n("Free Activities") + " ]");
|
||||
freeActivities.icon = "favorites";
|
||||
freeActivities.icon = "activities";
|
||||
freeActivities.state = KActivities::Info::Stopped;
|
||||
m_activitiesTable << freeActivities;
|
||||
|
||||
Latte::Data::Activity currentActivity;
|
||||
currentActivity.id = Latte::Data::Layout::CURRENTACTIVITYID;
|
||||
currentActivity.name = QString("[ " + i18n("Current Activity") + " ]");
|
||||
currentActivity.icon = "favorites";
|
||||
currentActivity.icon = "dialog-yes";
|
||||
currentActivity.state = KActivities::Info::Stopped;
|
||||
m_activitiesTable << currentActivity;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user