mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-23 13:33:50 +03:00
update shareto line settings indicator
--improve its appearance in general and its behavior also
This commit is contained in:
parent
20602acbfb
commit
97e5345f40
@ -609,6 +609,11 @@ bool Layouts::importLayoutsFromV1ConfigFile(QString file)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Layouts::on_sharedToInEditChanged(const int &row, const bool &inEdit)
|
||||
{
|
||||
m_model->setData(m_model->index(row, Model::Layouts::SHAREDCOLUMN), inEdit, Model::Layouts::SHAREDTOINEDIT);
|
||||
}
|
||||
|
||||
void Layouts::reset()
|
||||
{
|
||||
setOriginalInMultipleMode(o_originalInMultipleMode);
|
||||
|
@ -87,6 +87,10 @@ public:
|
||||
signals:
|
||||
void dataChanged();
|
||||
|
||||
public slots:
|
||||
//! needed for Delegate::Shared
|
||||
void on_sharedToInEditChanged(const int &row, const bool &inEdit);
|
||||
|
||||
private slots:
|
||||
void saveColumnWidths();
|
||||
void on_nameDuplicatedFrom(const QString &provenId, const QString &trialId);
|
||||
|
@ -44,7 +44,7 @@ namespace Layout {
|
||||
namespace Delegate {
|
||||
|
||||
Activities::Activities(QObject *parent)
|
||||
: QItemDelegate(parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ bool Activities::editorEvent(QEvent *event, QAbstractItemModel *model, const QSt
|
||||
return false;
|
||||
}
|
||||
|
||||
return QItemDelegate::editorEvent(event, model, option, index);
|
||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
void Activities::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
@ -243,16 +243,19 @@ void Activities::paint(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
|
||||
painter->restore();
|
||||
} else {
|
||||
bool sharedInEdit = index.data(Model::Layouts::SHAREDTOINEDIT).toBool();
|
||||
|
||||
// Disabled
|
||||
bool isSelected{Latte::isSelected(option)};
|
||||
QPalette::ColorRole backColorRole = isSelected ? QPalette::Highlight : QPalette::Base;
|
||||
QPalette::ColorRole textColorRole = isSelected ? QPalette::HighlightedText : QPalette::Text;
|
||||
|
||||
// background
|
||||
painter->fillRect(option.rect, option.palette.brush(Latte::colorGroup(option), backColorRole));
|
||||
//! draw background
|
||||
//! HIDDENTEXTCOLUMN is just needed to draw empty background rectangles properly based on states
|
||||
QStyledItemDelegate::paint(painter, option, index.model()->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
|
||||
|
||||
// text
|
||||
QPen pen(Qt::DashDotDotLine);
|
||||
QPen pen(Qt::DotLine);
|
||||
QColor textColor = option.palette.brush(Latte::colorGroup(option), textColorRole).color();
|
||||
|
||||
pen.setWidth(2); pen.setColor(textColor);
|
||||
@ -262,34 +265,38 @@ void Activities::paint(QPainter *painter, const QStyleOptionViewItem &option, co
|
||||
|
||||
painter->setPen(pen);
|
||||
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
painter->drawLine(option.rect.x(), y,
|
||||
option.rect.x()+option.rect.width() - space, y);
|
||||
if (sharedInEdit) {
|
||||
//! shareto cell is in edit mode so circle indicator is moved inside
|
||||
//! the activities cell
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
painter->drawLine(option.rect.x(), y, option.rect.x()+option.rect.width() - space, y);
|
||||
|
||||
int xm = option.rect.x() + option.rect.width() - space;
|
||||
int thick = option.rect.height() / 2;
|
||||
int ym = option.rect.y() + ((option.rect.height() - thick) / 2);
|
||||
int xm = option.rect.x() + option.rect.width() - space;
|
||||
int thick = option.rect.height() / 2;
|
||||
int ym = option.rect.y() + ((option.rect.height() - thick) / 2);
|
||||
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(textColor);
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(textColor);
|
||||
|
||||
//! draw ending cirlce
|
||||
painter->drawEllipse(QPoint(xm, ym + thick/2), thick/4, thick/4);
|
||||
//! draw ending cirlce
|
||||
painter->drawEllipse(QPoint(xm, ym + thick/2), thick/4, thick/4);
|
||||
} else {
|
||||
painter->drawLine(option.rect.x() + space, y, option.rect.x() + option.rect.width(), y);
|
||||
|
||||
int xm = option.rect.x() + space;
|
||||
int thick = option.rect.height() / 2;
|
||||
int ym = option.rect.y() + ((option.rect.height() - thick) / 2);
|
||||
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(textColor);
|
||||
|
||||
//! draw ending cirlce
|
||||
painter->drawEllipse(QPoint(xm, ym + thick/2), thick/4, thick/4);
|
||||
}
|
||||
} else {
|
||||
painter->drawLine(option.rect.x() + space, y,
|
||||
option.rect.x() + option.rect.width(), y);
|
||||
|
||||
int xm = option.rect.x() + space;
|
||||
int thick = option.rect.height() / 2;
|
||||
int ym = option.rect.y() + ((option.rect.height() - thick) / 2);
|
||||
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(textColor);
|
||||
|
||||
//! draw ending cirlce
|
||||
painter->drawEllipse(QPoint(xm, ym + thick/2), thick/4, thick/4);
|
||||
painter->drawLine(option.rect.x(), y, option.rect.x()+option.rect.width(), y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "../data/activitydata.h"
|
||||
|
||||
// Qt
|
||||
#include <QItemDelegate>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class QModelIndex;
|
||||
class QWidget;
|
||||
@ -35,7 +35,7 @@ namespace Settings {
|
||||
namespace Layout {
|
||||
namespace Delegate {
|
||||
|
||||
class Activities : public QItemDelegate
|
||||
class Activities : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -59,11 +59,12 @@ void CheckBox::paint(QPainter *painter, const QStyleOptionViewItem &option, cons
|
||||
QPalette::ColorRole backColorRole = isSelected ? QPalette::Highlight : QPalette::Base;
|
||||
QPalette::ColorRole textColorRole = isSelected ? QPalette::HighlightedText : QPalette::Text;
|
||||
|
||||
// background
|
||||
painter->fillRect(option.rect, option.palette.brush(Latte::colorGroup(option), backColorRole));
|
||||
//! draw background
|
||||
//! HIDDENTEXTCOLUMN is just needed to draw empty background rectangles properly based on states
|
||||
QStyledItemDelegate::paint(painter, option, index.model()->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
|
||||
|
||||
// text
|
||||
QPen pen(Qt::DashDotDotLine);
|
||||
QPen pen(Qt::DotLine);
|
||||
pen.setWidth(2); pen.setColor(option.palette.brush(Latte::colorGroup(option), textColorRole).color());
|
||||
int y = option.rect.y()+option.rect.height()/2;
|
||||
|
||||
|
@ -45,8 +45,9 @@ namespace Layout {
|
||||
namespace Delegate {
|
||||
|
||||
|
||||
Shared::Shared(QObject *parent)
|
||||
: QItemDelegate(parent)
|
||||
Shared::Shared(Controller::Layouts *parent)
|
||||
: QStyledItemDelegate(parent),
|
||||
m_controller(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@ -88,6 +89,8 @@ QWidget *Shared::createEditor(QWidget *parent, const QStyleOptionViewItem &optio
|
||||
|
||||
updateButtonText(button, index);
|
||||
|
||||
m_controller->on_sharedToInEditChanged(index.row(), true);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
@ -109,6 +112,8 @@ void Shared::setModelData(QWidget *editor, QAbstractItemModel *model, const QMod
|
||||
}
|
||||
|
||||
model->setData(index, assignedLayouts, Qt::UserRole);
|
||||
|
||||
m_controller->on_sharedToInEditChanged(index.row(), false);
|
||||
}
|
||||
|
||||
void Shared::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
@ -120,8 +125,9 @@ void Shared::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &o
|
||||
|
||||
void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
bool sharedInEdit = index.data(Model::Layouts::SHAREDTOINEDIT).toBool();
|
||||
Data::LayoutsTable allLayouts = qvariant_cast<Data::LayoutsTable>(index.data(Model::Layouts::ALLLAYOUTSROLE));
|
||||
QStringList assignedIds = index.data(Qt::UserRole).toStringList();
|
||||
QStringList assignedIds = index.data(Qt::UserRole).toStringList();
|
||||
|
||||
Data::LayoutsTable assignedLayouts;
|
||||
|
||||
@ -137,8 +143,22 @@ void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const
|
||||
painter->save();
|
||||
|
||||
if (assignedLayouts.rowCount() > 0) {
|
||||
//! indicator
|
||||
if (!sharedInEdit) {
|
||||
paintSharedToIndicator(painter, myOptions, index);
|
||||
}
|
||||
|
||||
//! Text code
|
||||
myOptions.text = joined(assignedLayouts);
|
||||
|
||||
int thick = option.rect.height();
|
||||
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
myOptions.rect = QRect(myOptions.rect.x() + thick, myOptions.rect.y(), myOptions.rect.width() - thick, myOptions.rect.height());
|
||||
} else {
|
||||
myOptions.rect = QRect(myOptions.rect.x(), myOptions.rect.y(), myOptions.rect.width() - thick, myOptions.rect.height());
|
||||
}
|
||||
|
||||
QTextDocument doc;
|
||||
QString css;
|
||||
QString sharesText = myOptions.text;
|
||||
@ -174,6 +194,66 @@ void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void Shared::paintSharedToIndicator(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
// Disabled
|
||||
bool isSelected{Latte::isSelected(option)};
|
||||
QPalette::ColorRole backColorRole = isSelected ? QPalette::Highlight : QPalette::Base;
|
||||
QPalette::ColorRole textColorRole = isSelected ? QPalette::HighlightedText : QPalette::Text;
|
||||
|
||||
int space = option.rect.height() / 2;
|
||||
|
||||
//! draw background below icons
|
||||
//! HIDDENTEXTCOLUMN is just needed to draw empty background rectangles properly based on states
|
||||
QStyleOptionViewItem backOptions = option;
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
backOptions.rect = QRect(option.rect.x(), option.rect.y(), 2 * space, 2 * space);
|
||||
} else {
|
||||
backOptions.rect = QRect(option.rect.x() + option.rect.width() - (2*space), option.rect.y(), 2 * space, 2 * space);
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, backOptions, index.model()->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
|
||||
|
||||
// text
|
||||
QPen pen(Qt::DotLine);
|
||||
QColor textColor = option.palette.brush(Latte::colorGroup(option), textColorRole).color();
|
||||
|
||||
pen.setWidth(2); pen.setColor(textColor);
|
||||
int y = option.rect.y()+option.rect.height()/2;
|
||||
|
||||
painter->setPen(pen);
|
||||
|
||||
if (qApp->layoutDirection() == Qt::LeftToRight) {
|
||||
int xStart = option.rect.x();
|
||||
painter->drawLine(xStart, y, xStart + space, y);
|
||||
|
||||
int xm = option.rect.x() + space;
|
||||
int thick = option.rect.height() / 2;
|
||||
int ym = option.rect.y() + ((option.rect.height() - thick) / 2);
|
||||
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(textColor);
|
||||
|
||||
//! draw ending cirlce
|
||||
painter->drawEllipse(QPoint(xm, ym + thick/2), thick/4, thick/4);
|
||||
} else {
|
||||
int xEnd = option.rect.x() + option.rect.width();
|
||||
painter->drawLine(xEnd, y, xEnd-space, y);
|
||||
|
||||
int xm = option.rect.x() + option.rect.width() - space;
|
||||
int thick = option.rect.height() / 2;
|
||||
int ym = option.rect.y() + ((option.rect.height() - thick) / 2);
|
||||
|
||||
pen.setStyle(Qt::SolidLine);
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(textColor);
|
||||
|
||||
//! draw ending cirlce
|
||||
painter->drawEllipse(QPoint(xm, ym + thick/2), thick/4, thick/4);
|
||||
}
|
||||
}
|
||||
|
||||
void Shared::updateButtonText(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
if (!editor) {
|
||||
|
@ -22,9 +22,10 @@
|
||||
|
||||
// local
|
||||
#include "../data/layoutstable.h"
|
||||
#include "../controllers/layoutscontroller.h"
|
||||
|
||||
// Qt
|
||||
#include <QItemDelegate>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class QModelIndex;
|
||||
class QWidget;
|
||||
@ -34,11 +35,11 @@ namespace Settings {
|
||||
namespace Layout {
|
||||
namespace Delegate {
|
||||
|
||||
class Shared : public QItemDelegate
|
||||
class Shared : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Shared(QObject *parent);
|
||||
Shared(Controller::Layouts *parent);
|
||||
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||
@ -47,9 +48,14 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
void paintSharedToIndicator(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
void updateButtonText(QWidget *editor, const QModelIndex &index) const;
|
||||
|
||||
QString joined(const Data::LayoutsTable &layouts, bool formatText = true) const;
|
||||
|
||||
private:
|
||||
// we need it in order to send to the model the information when the SHARETO cell is edited
|
||||
Controller::Layouts *m_controller{nullptr};
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -350,6 +350,8 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
|
||||
QVariant layouts;
|
||||
layouts.setValue(m_layoutsTable);
|
||||
return layouts;
|
||||
} else if (role == SHAREDTOINEDIT) {
|
||||
return (m_sharedToInEditRow == row);
|
||||
}
|
||||
|
||||
switch (column) {
|
||||
@ -639,6 +641,14 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
case SHAREDCOLUMN:
|
||||
if (role == Qt::UserRole) {
|
||||
setShares(row, value.toStringList());
|
||||
return true;
|
||||
} else if (role == SHAREDTOINEDIT) {
|
||||
bool inEdit = value.toBool();
|
||||
m_sharedToInEditRow = inEdit ? row : -1;
|
||||
roles << Qt::DisplayRole;
|
||||
roles << Qt::UserRole;
|
||||
emit dataChanged(this->index(row, ACTIVITYCOLUMN), this->index(row, SHAREDCOLUMN), roles);
|
||||
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
@ -63,7 +63,8 @@ public:
|
||||
ASSIGNEDACTIVITIESROLE,
|
||||
ALLACTIVITIESSORTEDROLE,
|
||||
ALLACTIVITIESDATAROLE,
|
||||
ALLLAYOUTSROLE
|
||||
ALLLAYOUTSROLE,
|
||||
SHAREDTOINEDIT
|
||||
};
|
||||
|
||||
explicit Layouts(QObject *parent, Latte::Corona *corona);
|
||||
@ -133,6 +134,8 @@ private:
|
||||
bool m_inMultipleMode{false};
|
||||
Data::LayoutsTable m_layoutsTable;
|
||||
|
||||
int m_sharedToInEditRow{-1};
|
||||
|
||||
Data::ActivitiesMap m_activitiesMap;
|
||||
QHash<QString, KActivities::Info *> m_activitiesInfo;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user