1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-11 13:18:13 +03:00

support font style for FreeActivities record

This commit is contained in:
Michail Vourlakos 2020-03-08 21:40:20 +02:00
parent 5f7bcf565d
commit fca4db5962
4 changed files with 47 additions and 11 deletions

View File

@ -51,8 +51,8 @@ ActivitiesDelegate::ActivitiesDelegate(QObject *parent)
QWidget *ActivitiesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
int row = index.row();
QPushButton *button = new QPushButton(parent);
PersistentMenu *menu = new PersistentMenu(button);
button->setMenu(menu);
menu->setMinimumWidth(option.rect.width());
@ -75,6 +75,14 @@ QWidget *ActivitiesDelegate::createEditor(QWidget *parent, const QStyleOptionVie
action->setCheckable(true);
action->setChecked(isFreeActivitiesChecked);
bool isActive = m_settingsDialog->isActive(row);
if (isActive) {
QFont font = action->font();
font.setBold(true);
action->setFont(font);
}
menu->addAction(action);
if (isFreeActivitiesChecked) {
menu->setMasterIndex(i);
@ -191,7 +199,7 @@ void ActivitiesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
if (assignedActivities.count() > 0) {
myOptions.text = joinedActivities(assignedActivities);
myOptions.text = joinedActivities(assignedActivities, index.row());
QTextDocument doc;
QString css;
@ -278,7 +286,7 @@ void ActivitiesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
}
}
QString ActivitiesDelegate::joinedActivities(const QStringList &activities, bool boldForActive) const
QString ActivitiesDelegate::joinedActivities(const QStringList &activities, int index) const
{
QString finalText;
@ -288,10 +296,17 @@ QString ActivitiesDelegate::joinedActivities(const QStringList &activities, bool
for (const auto &activityId : activities) {
QString name;
bool isActive{false};
bool bold{false};
bool italic{false};
if (activityId == freeActivitiesId) {
name = m_settingsDialog->freeActivities_text();
if (index >= 0) {
bool isActive = m_settingsDialog->isActive(index);
bold = isActive;
italic = !isActive;
}
} else {
KActivities::Info info(activityId);
@ -301,17 +316,25 @@ QString ActivitiesDelegate::joinedActivities(const QStringList &activities, bool
}
i++;
bool isActive{false};
if (boldForActive && (info.state() == KActivities::Info::Running) || (info.state() == KActivities::Info::Starting)) {
isActive = true;
if ((info.state() == KActivities::Info::Running) || (info.state() == KActivities::Info::Starting)) {
bold = true;
}
name = info.name();
}
}
finalText += isActive ? "<b>" + name + "</b>" : name;
QString styledText = name;
if (bold) {
styledText = "<b>" + styledText + "</b>";
}
if (italic) {
styledText = "<i>" + styledText + "</i>";
}
finalText += styledText;
}
return finalText;
@ -331,6 +354,6 @@ void ActivitiesDelegate::updateButton(QWidget *editor) const
}
}
button->setText(joinedActivities(assignedActivities,false));
button->setText(joinedActivities(assignedActivities, -1));
}

View File

@ -46,11 +46,13 @@ public:
private:
void updateButton(QWidget *editor) const;
QString joinedActivities(const QStringList &activities, bool boldForActive = true) const;
QString joinedActivities(const QStringList &activities, int index = -1) const;
private:
Latte::SettingsDialog *m_settingsDialog{nullptr};
int m_lastCurrentIndex{-1};
};
#endif

View File

@ -2071,6 +2071,16 @@ bool SettingsDialog::inMultipleLayoutsLook() const
return inMemoryOption == Latte::Types::MultipleLayouts;
}
bool SettingsDialog::isActive(int row) const
{
QString id = m_model->data(m_model->index(row, IDCOLUMN), Qt::DisplayRole).toString();
if (m_originalLayoutNames.contains(id)){
return (m_corona->layoutsManager()->synchronizer()->layout(m_originalLayoutNames[id]) != nullptr);
}
return false;
}
bool SettingsDialog::isActive(QString layoutName) const
{
return (m_corona->layoutsManager()->synchronizer()->layout(layoutName) != nullptr);

View File

@ -71,6 +71,7 @@ public:
void updateShareAt(const int &row, const QString &fromId, const QString &toId);
bool inMultipleLayoutsLook() const;
bool isActive(int row) const;
bool isActive(QString layoutName) const;
bool isShared(int row) const;
bool isMenuCell(int column) const;