mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-27 14:50:21 +03:00
update shared layouts cell states
--enable/disable shared layouts cells accordingly
This commit is contained in:
parent
61621277d3
commit
4c0a3f5523
@ -135,51 +135,65 @@ void ActivityCmbBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
||||
QStyleOptionViewItem myOptions = option;
|
||||
//! Remove the focus dotted lines
|
||||
myOptions.state = (myOptions.state & ~QStyle::State_HasFocus);
|
||||
painter->save();
|
||||
|
||||
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
|
||||
if (myOptions.state & QStyle::State_Enabled) {
|
||||
painter->save();
|
||||
|
||||
if (assignedActivities.count() > 0) {
|
||||
myOptions.text = assignedActivitiesText(index);
|
||||
QStringList assignedActivities = index.model()->data(index, Qt::UserRole).toStringList();
|
||||
|
||||
QTextDocument doc;
|
||||
QString css;
|
||||
QString activitiesText = myOptions.text;
|
||||
if (assignedActivities.count() > 0) {
|
||||
myOptions.text = assignedActivitiesText(index);
|
||||
|
||||
QBrush nBrush;
|
||||
QTextDocument doc;
|
||||
QString css;
|
||||
QString activitiesText = myOptions.text;
|
||||
|
||||
if ((option.state & QStyle::State_Active) && (option.state & QStyle::State_Selected)) {
|
||||
nBrush = option.palette.brush(QPalette::Active, QPalette::HighlightedText);
|
||||
QBrush nBrush;
|
||||
|
||||
if ((option.state & QStyle::State_Active) && (option.state & QStyle::State_Selected)) {
|
||||
nBrush = option.palette.brush(QPalette::Active, QPalette::HighlightedText);
|
||||
} else {
|
||||
nBrush = option.palette.brush(QPalette::Inactive, QPalette::Text);
|
||||
}
|
||||
|
||||
css = QString("body { color : %1; }").arg(nBrush.color().name());
|
||||
|
||||
doc.setDefaultStyleSheet(css);
|
||||
doc.setHtml("<body>" + myOptions.text + "</body>");
|
||||
|
||||
myOptions.text = "";
|
||||
myOptions.widget->style()->drawControl(QStyle::CE_ItemViewItem, &myOptions, painter);
|
||||
|
||||
//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()) {
|
||||
int textWidth = doc.size().width();
|
||||
|
||||
painter->translate(qMax(myOptions.rect.left(), myOptions.rect.right() - textWidth), myOptions.rect.top() + offsetY + 1);
|
||||
} else {
|
||||
painter->translate(myOptions.rect.left(), myOptions.rect.top() + offsetY + 1);
|
||||
}
|
||||
|
||||
QRect clip(0, 0, myOptions.rect.width(), myOptions.rect.height());
|
||||
doc.drawContents(painter, clip);
|
||||
} else {
|
||||
nBrush = option.palette.brush(QPalette::Inactive, QPalette::Text);
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOptions, painter);
|
||||
}
|
||||
|
||||
css = QString("body { color : %1; }").arg(nBrush.color().name());
|
||||
|
||||
doc.setDefaultStyleSheet(css);
|
||||
doc.setHtml("<body>" + myOptions.text + "</body>");
|
||||
|
||||
myOptions.text = "";
|
||||
myOptions.widget->style()->drawControl(QStyle::CE_ItemViewItem, &myOptions, painter);
|
||||
|
||||
//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()) {
|
||||
int textWidth = doc.size().width();
|
||||
|
||||
painter->translate(qMax(myOptions.rect.left(), myOptions.rect.right() - textWidth), myOptions.rect.top() + offsetY + 1);
|
||||
} else {
|
||||
painter->translate(myOptions.rect.left(), myOptions.rect.top() + offsetY + 1);
|
||||
}
|
||||
|
||||
QRect clip(0, 0, myOptions.rect.width(), myOptions.rect.height());
|
||||
doc.drawContents(painter, clip);
|
||||
painter->restore();
|
||||
} else {
|
||||
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOptions, painter);
|
||||
}
|
||||
// Disabled
|
||||
QPalette palette;
|
||||
QPen pen(Qt::DashDotDotLine);
|
||||
|
||||
painter->restore();
|
||||
pen.setWidth(2); pen.setColor(palette.linkVisited().color());
|
||||
int ver = option.rect.y()+option.rect.height()/2;
|
||||
|
||||
painter->setPen(pen);
|
||||
painter->drawLine(option.rect.x(), ver,
|
||||
option.rect.x()+option.rect.width(), ver);
|
||||
}
|
||||
}
|
||||
|
||||
QString ActivityCmbBoxDelegate::assignedActivitiesText(const QModelIndex &index) const
|
||||
|
@ -41,10 +41,23 @@ void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||
//! Remove the focus dotted lines
|
||||
adjustedOption.state = (adjustedOption.state & ~QStyle::State_HasFocus);
|
||||
|
||||
QStandardItemModel *model = (QStandardItemModel *) index.model();
|
||||
QStyledItemDelegate::paint(painter, adjustedOption, model->index(index.row(), HIDDENTEXTCOLUMN));
|
||||
if (adjustedOption.state & QStyle::State_Enabled) {
|
||||
QStandardItemModel *model = (QStandardItemModel *) index.model();
|
||||
QStyledItemDelegate::paint(painter, adjustedOption, model->index(index.row(), HIDDENTEXTCOLUMN));
|
||||
|
||||
QStyledItemDelegate::paint(painter, adjustedOption, index);
|
||||
QStyledItemDelegate::paint(painter, adjustedOption, index);
|
||||
} else {
|
||||
// Disabled
|
||||
QPalette palette;
|
||||
QPen pen(Qt::DashDotDotLine);
|
||||
|
||||
pen.setWidth(2); pen.setColor(palette.linkVisited().color());
|
||||
int ver = option.rect.y()+option.rect.height()/2;
|
||||
|
||||
painter->setPen(pen);
|
||||
painter->drawLine(option.rect.x(), ver,
|
||||
option.rect.x()+option.rect.width(), ver);
|
||||
}
|
||||
}
|
||||
|
||||
bool CheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
|
||||
|
@ -951,6 +951,7 @@ void SettingsDialog::loadSettings()
|
||||
}
|
||||
|
||||
updatePerLayoutButtonsState();
|
||||
updateSharedLayoutsStates();
|
||||
|
||||
ui->autostartChkBox->setChecked(m_corona->universalSettings()->autostart());
|
||||
ui->infoWindowChkBox->setChecked(m_corona->universalSettings()->showInfoWindow());
|
||||
@ -1199,6 +1200,8 @@ void SettingsDialog::itemChanged(QStandardItem *item)
|
||||
font.setItalic(false);
|
||||
m_model->setData(m_model->index(currentRow, NAMECOLUMN), font, Qt::FontRole);
|
||||
}
|
||||
} else if (item->column() == SHAREDCOLUMN) {
|
||||
updateSharedLayoutsStates();
|
||||
}
|
||||
|
||||
updateApplyButtonsState();
|
||||
@ -1313,6 +1316,29 @@ void SettingsDialog::updatePerLayoutButtonsState()
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::updateSharedLayoutsStates()
|
||||
{
|
||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||
QStringList shares = m_model->data(m_model->index(i, SHAREDCOLUMN), Qt::UserRole).toStringList();
|
||||
|
||||
if (shares.isEmpty()) {
|
||||
QStandardItem *item = m_model->item(i, MENUCOLUMN);
|
||||
item->setEnabled(true);
|
||||
item = m_model->item(i, BORDERSCOLUMN);
|
||||
item->setEnabled(true);
|
||||
item = m_model->item(i,ACTIVITYCOLUMN);
|
||||
item->setEnabled(true);
|
||||
} else {
|
||||
QStandardItem *item = m_model->item(i, MENUCOLUMN);
|
||||
item->setEnabled(false);
|
||||
item = m_model->item(i, BORDERSCOLUMN);
|
||||
item->setEnabled(false);
|
||||
item = m_model->item(i,ACTIVITYCOLUMN);
|
||||
item->setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::recalculateAvailableActivities()
|
||||
{
|
||||
QStringList tempActivities = m_corona->layoutManager()->activities();
|
||||
|
@ -96,6 +96,7 @@ private:
|
||||
void insertLayoutInfoAtRow(int row, QString path, QString color, QString textColor, QString name, bool menu, bool disabledBorders,
|
||||
QStringList activities, bool locked = false);
|
||||
void updateApplyButtonsState();
|
||||
void updateSharedLayoutsStates();
|
||||
|
||||
bool dataAreAccepted();
|
||||
bool idExistsInModel(QString id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user