|
|
@ -17,25 +17,27 @@
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "activitycmbboxdelegate.h"
|
|
|
|
#include "activitiesdelegate.h"
|
|
|
|
|
|
|
|
|
|
|
|
// local
|
|
|
|
// local
|
|
|
|
|
|
|
|
#include "persistentmenu.h"
|
|
|
|
#include "../settingsdialog.h"
|
|
|
|
#include "../settingsdialog.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Qt
|
|
|
|
// Qt
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QComboBox>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QString>
|
|
|
|
#include <QString>
|
|
|
|
#include <QTextDocument>
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
|
|
|
|
|
|
|
// KDE
|
|
|
|
// KDE
|
|
|
|
#include <KActivities/Info>
|
|
|
|
#include <KActivities/Info>
|
|
|
|
|
|
|
|
|
|
|
|
ActivityCmbBoxDelegate::ActivityCmbBoxDelegate(QObject *parent)
|
|
|
|
ActivitiesDelegate::ActivitiesDelegate(QObject *parent)
|
|
|
|
: QItemDelegate(parent)
|
|
|
|
: QItemDelegate(parent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto *settingsDialog = qobject_cast<Latte::SettingsDialog *>(parent);
|
|
|
|
auto *settingsDialog = qobject_cast<Latte::SettingsDialog *>(parent);
|
|
|
@ -45,14 +47,12 @@ ActivityCmbBoxDelegate::ActivityCmbBoxDelegate(QObject *parent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *ActivityCmbBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
QWidget *ActivitiesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QComboBox *editor = new QComboBox(parent);
|
|
|
|
QPushButton *button = new QPushButton(parent);
|
|
|
|
|
|
|
|
PersistentMenu *menu = new PersistentMenu(button);
|
|
|
|
//! use focusPolicy as flag in order to update activities only when the user is clicking in the popup
|
|
|
|
button->setMenu(menu);
|
|
|
|
//! it was the only way I found to communicate between the activated (const) signal and the
|
|
|
|
menu->setMinimumWidth(option.rect.width());
|
|
|
|
//! setEditorData (const) function
|
|
|
|
|
|
|
|
editor->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
|
|
|
|
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
|
|
|
|
QStringList availableActivities = m_settingsDialog->availableActivities();
|
|
|
|
QStringList availableActivities = m_settingsDialog->availableActivities();
|
|
|
@ -67,70 +67,56 @@ QWidget *ActivityCmbBoxDelegate::createEditor(QWidget *parent, const QStyleOptio
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < shownActivities.count(); ++i) {
|
|
|
|
for (unsigned int i = 0; i < shownActivities.count(); ++i) {
|
|
|
|
|
|
|
|
|
|
|
|
KActivities::Info info(shownActivities[i]);
|
|
|
|
KActivities::Info info(shownActivities[i]);
|
|
|
|
|
|
|
|
|
|
|
|
QString indicator = " ";
|
|
|
|
if (info.state() != KActivities::Info::Invalid) {
|
|
|
|
|
|
|
|
QAction *action = new QAction(info.name());
|
|
|
|
|
|
|
|
action->setData(shownActivities[i]);
|
|
|
|
|
|
|
|
action->setCheckable(true);
|
|
|
|
|
|
|
|
action->setChecked(assignedActivities.contains(shownActivities[i]));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((info.state() == KActivities::Info::Running) || (info.state() == KActivities::Info::Starting)) {
|
|
|
|
|
|
|
|
QFont font = action->font();
|
|
|
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
|
|
|
action->setFont(font);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (assignedActivities.contains(shownActivities[i])) {
|
|
|
|
menu->addAction(action);
|
|
|
|
indicator = QString::fromUtf8("\u2714") + " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (info.state() != KActivities::Info::Invalid) {
|
|
|
|
connect(action, &QAction::toggled, this, [this, button]() {
|
|
|
|
editor->addItem(QIcon::fromTheme(info.icon()), QString(indicator + info.name()), QVariant(shownActivities[i]));
|
|
|
|
updateButton(button);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
connect(editor, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), [ = ](int index) {
|
|
|
|
return button;
|
|
|
|
editor->setFocusPolicy(Qt::ClickFocus);
|
|
|
|
|
|
|
|
editor->clearFocus();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return editor;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ActivityCmbBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|
|
|
void ActivitiesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = static_cast<QComboBox *>(editor);
|
|
|
|
updateButton(editor);
|
|
|
|
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int pos = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (assignedActivities.count() > 0) {
|
|
|
|
|
|
|
|
pos = comboBox->findData(QVariant(assignedActivities[0]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
comboBox->setCurrentIndex(pos);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ActivityCmbBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
|
|
|
void ActivitiesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QComboBox *comboBox = static_cast<QComboBox *>(editor);
|
|
|
|
QPushButton *button = static_cast<QPushButton *>(editor);
|
|
|
|
|
|
|
|
|
|
|
|
if (editor->focusPolicy() != Qt::ClickFocus) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editor->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
|
|
|
|
|
|
|
|
QString selectedActivity = comboBox->currentData().toString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (assignedActivities.contains(selectedActivity)) {
|
|
|
|
QStringList assignedActivities;
|
|
|
|
assignedActivities.removeAll(selectedActivity);
|
|
|
|
foreach (QAction *action, button->menu()->actions()) {
|
|
|
|
} else {
|
|
|
|
if (action->isChecked()) {
|
|
|
|
assignedActivities.append(selectedActivity);
|
|
|
|
assignedActivities << action->data().toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
model->setData(index, assignedActivities, Qt::UserRole);
|
|
|
|
model->setData(index, assignedActivities, Qt::UserRole);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ActivityCmbBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
void ActivitiesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
editor->setGeometry(option.rect);
|
|
|
|
editor->setGeometry(option.rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ActivityCmbBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
void ActivitiesDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QStyleOptionViewItem myOptions = option;
|
|
|
|
QStyleOptionViewItem myOptions = option;
|
|
|
|
//! Remove the focus dotted lines
|
|
|
|
//! Remove the focus dotted lines
|
|
|
@ -142,7 +128,7 @@ void ActivityCmbBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|
|
|
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 = assignedActivitiesText(index);
|
|
|
|
myOptions.text = joinedActivities(assignedActivities);
|
|
|
|
|
|
|
|
|
|
|
|
QTextDocument doc;
|
|
|
|
QTextDocument doc;
|
|
|
|
QString css;
|
|
|
|
QString css;
|
|
|
@ -220,31 +206,48 @@ void ActivityCmbBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString ActivityCmbBoxDelegate::assignedActivitiesText(const QModelIndex &index) const
|
|
|
|
QString ActivitiesDelegate::joinedActivities(const QStringList &activities, bool boldForActive) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString finalText;
|
|
|
|
QString finalText;
|
|
|
|
|
|
|
|
|
|
|
|
if (assignedActivities.count() > 0) {
|
|
|
|
int i = 0;
|
|
|
|
for (int i = 0; i < assignedActivities.count(); ++i) {
|
|
|
|
|
|
|
|
KActivities::Info info(assignedActivities[i]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (info.state() != KActivities::Info::Invalid) {
|
|
|
|
for (const auto &activityId : activities) {
|
|
|
|
if (i > 0) {
|
|
|
|
KActivities::Info info(activityId);
|
|
|
|
finalText += ", ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isActive{false};
|
|
|
|
if (info.state() != KActivities::Info::Invalid) {
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
|
|
|
finalText += ", ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
|
|
if ((info.state() == KActivities::Info::Running) || (info.state() == KActivities::Info::Starting)) {
|
|
|
|
bool isActive{false};
|
|
|
|
isActive = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
finalText += isActive ? "<b>" + info.name() + "</b>" : info.name();
|
|
|
|
if (boldForActive && (info.state() == KActivities::Info::Running) || (info.state() == KActivities::Info::Starting)) {
|
|
|
|
|
|
|
|
isActive = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
finalText += isActive ? "<b>" + info.name() + "</b>" : info.name();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return finalText;
|
|
|
|
return finalText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ActivitiesDelegate::updateButton(QWidget *editor) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!editor) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton *button = static_cast<QPushButton *>(editor);
|
|
|
|
|
|
|
|
QStringList assignedActivities;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (QAction *action, button->menu()->actions()) {
|
|
|
|
|
|
|
|
if (action->isChecked()) {
|
|
|
|
|
|
|
|
assignedActivities << action->data().toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button->setText(joinedActivities(assignedActivities,false));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|