mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-27 14:50:21 +03:00
update activities/shares from cell QMenu(s)
This commit is contained in:
parent
215d74092f
commit
46bf0c1229
@ -84,8 +84,14 @@ QWidget *ActivitiesDelegate::createEditor(QWidget *parent, const QStyleOptionVie
|
||||
|
||||
menu->addAction(action);
|
||||
|
||||
connect(action, &QAction::toggled, this, [this, button]() {
|
||||
connect(action, &QAction::toggled, this, [this, button, action]() {
|
||||
updateButton(button);
|
||||
|
||||
if (action->isChecked()) {
|
||||
m_settingsDialog->addActivityInCurrent(action->data().toString());
|
||||
} else {
|
||||
m_settingsDialog->removeActivityFromCurrent(action->data().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,14 @@ QWidget *SharedDelegate::createEditor(QWidget *parent, const QStyleOptionViewIte
|
||||
action->setChecked(assignedShares.contains(availableShares[i]));
|
||||
menu->addAction(action);
|
||||
|
||||
connect(action, &QAction::toggled, this, [this, button]() {
|
||||
connect(action, &QAction::toggled, this, [this, button, action]() {
|
||||
updateButtonText(button);
|
||||
|
||||
if (action->isChecked()) {
|
||||
m_settingsDialog->addShareInCurrent(action->data().toString());
|
||||
} else {
|
||||
m_settingsDialog->removeShareFromCurrent(action->data().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -115,11 +121,11 @@ void SharedDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
|
||||
}
|
||||
|
||||
if (assignedLayouts.count() > 0) {
|
||||
myOptions.text = joined(assignedLayouts);
|
||||
myOptions.text = joined(assignedLayouts, true);
|
||||
|
||||
QTextDocument doc;
|
||||
QString css;
|
||||
QString activitiesText = myOptions.text;
|
||||
QString sharesText = myOptions.text;
|
||||
|
||||
QPalette::ColorRole applyColor = Latte::isSelected(option) ? QPalette::HighlightedText : QPalette::Text;
|
||||
QBrush nBrush = option.palette.brush(Latte::colorGroup(option), applyColor);
|
||||
@ -135,7 +141,7 @@ void SharedDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
|
||||
//we need an offset to be in the same vertical center of TextEdit
|
||||
int offsetY = ((myOptions.rect.height() - doc.size().height()) / 2);
|
||||
|
||||
if ((qApp->layoutDirection() == Qt::RightToLeft) && !activitiesText.isEmpty()) {
|
||||
if ((qApp->layoutDirection() == Qt::RightToLeft) && !sharesText.isEmpty()) {
|
||||
int textWidth = doc.size().width();
|
||||
|
||||
painter->translate(qMax(myOptions.rect.left(), myOptions.rect.right() - textWidth), myOptions.rect.top() + offsetY + 1);
|
||||
@ -169,7 +175,26 @@ void SharedDelegate::updateButtonText(QWidget *editor) const
|
||||
button->setText(joined(assignedLayouts));
|
||||
}
|
||||
|
||||
QString SharedDelegate::joined(const QStringList &texts) const
|
||||
QString SharedDelegate::joined(const QStringList &layouts, bool boldForActive) const
|
||||
{
|
||||
return texts.join(", ");
|
||||
QString finalText;
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (const auto &layoutName : layouts) {
|
||||
if (i > 0) {
|
||||
finalText += ", ";
|
||||
}
|
||||
i++;
|
||||
|
||||
bool isActive{false};
|
||||
|
||||
if (boldForActive && m_settingsDialog->isActive(layoutName)) {
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
finalText += isActive ? "<b>" + layoutName + "</b>" : layoutName;
|
||||
}
|
||||
|
||||
return finalText;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
private:
|
||||
void updateButtonText(QWidget *editor) const;
|
||||
|
||||
QString joined(const QStringList &texts) const;
|
||||
QString joined(const QStringList &layouts, bool boldForActive = false) const;
|
||||
|
||||
private:
|
||||
Latte::SettingsDialog *m_settingsDialog{nullptr};
|
||||
|
@ -1825,6 +1825,46 @@ void SettingsDialog::updateActiveShares()
|
||||
m_sharesMap = currentSharesMap;
|
||||
}
|
||||
|
||||
void SettingsDialog::addActivityInCurrent(const QString &activityId)
|
||||
{
|
||||
int currentRow = ui->layoutsView->currentIndex().row();
|
||||
QStringList activities = m_model->data(m_model->index(currentRow, ACTIVITYCOLUMN), Qt::UserRole).toStringList();
|
||||
if (!activities.contains(activityId)) {
|
||||
activities << activityId;
|
||||
m_model->setData(m_model->index(currentRow, ACTIVITYCOLUMN), activities, Qt::UserRole);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::removeActivityFromCurrent(const QString &activityId)
|
||||
{
|
||||
int currentRow = ui->layoutsView->currentIndex().row();
|
||||
QStringList activities = m_model->data(m_model->index(currentRow, ACTIVITYCOLUMN), Qt::UserRole).toStringList();
|
||||
if (activities.contains(activityId)) {
|
||||
activities.removeAll(activityId);
|
||||
m_model->setData(m_model->index(currentRow, ACTIVITYCOLUMN), activities, Qt::UserRole);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::addShareInCurrent(const QString &layoutId)
|
||||
{
|
||||
int currentRow = ui->layoutsView->currentIndex().row();
|
||||
QStringList shares = m_model->data(m_model->index(currentRow, SHAREDCOLUMN), Qt::UserRole).toStringList();
|
||||
if (!shares.contains(layoutId)) {
|
||||
shares << layoutId;
|
||||
m_model->setData(m_model->index(currentRow, SHAREDCOLUMN), shares, Qt::UserRole);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::removeShareFromCurrent(const QString &layoutId)
|
||||
{
|
||||
int currentRow = ui->layoutsView->currentIndex().row();
|
||||
QStringList shares = m_model->data(m_model->index(currentRow, SHAREDCOLUMN), Qt::UserRole).toStringList();
|
||||
if (shares.contains(layoutId)) {
|
||||
shares.removeAll(layoutId);
|
||||
m_model->setData(m_model->index(currentRow, SHAREDCOLUMN), shares, Qt::UserRole);
|
||||
}
|
||||
}
|
||||
|
||||
bool SettingsDialog::idExistsInModel(QString id)
|
||||
{
|
||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||
@ -1868,6 +1908,11 @@ bool SettingsDialog::inMultipleLayoutsLook() const
|
||||
return inMemoryOption == Latte::Types::MultipleLayouts;
|
||||
}
|
||||
|
||||
bool SettingsDialog::isActive(QString layoutName) const
|
||||
{
|
||||
return (m_corona->layoutsManager()->layout(layoutName) != nullptr);
|
||||
}
|
||||
|
||||
bool SettingsDialog::isMenuCell(int column) const
|
||||
{
|
||||
return column == MENUCOLUMN;
|
||||
|
@ -57,7 +57,13 @@ public:
|
||||
|
||||
void setCurrentPage(Types::LatteConfigPage page);
|
||||
|
||||
void addActivityInCurrent(const QString &activityId);
|
||||
void removeActivityFromCurrent(const QString &activityId);
|
||||
void addShareInCurrent(const QString &layoutId);
|
||||
void removeShareFromCurrent(const QString &layoutId);
|
||||
|
||||
bool inMultipleLayoutsLook() const;
|
||||
bool isActive(QString layoutName) const;
|
||||
bool isShared(int row) const;
|
||||
bool isMenuCell(int column) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user