support font style for FreeActivities record

pull/11/head
Michail Vourlakos 5 years ago
parent 5f7bcf565d
commit fca4db5962

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

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

@ -2071,6 +2071,16 @@ bool SettingsDialog::inMultipleLayoutsLook() const
return inMemoryOption == Latte::Types::MultipleLayouts; 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 bool SettingsDialog::isActive(QString layoutName) const
{ {
return (m_corona->layoutsManager()->synchronizer()->layout(layoutName) != nullptr); return (m_corona->layoutsManager()->synchronizer()->layout(layoutName) != nullptr);

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

Loading…
Cancel
Save