mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-12 17:17:50 +03:00
add lock layout button in settings
This commit is contained in:
parent
2d9b5376b7
commit
ece4d55f1c
@ -25,6 +25,9 @@
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStandardItemModel>
|
||||
|
||||
const int HIDDENTEXTCOLUMN = 1;
|
||||
|
||||
LayoutNameDelegate::LayoutNameDelegate(QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
@ -33,21 +36,41 @@ LayoutNameDelegate::LayoutNameDelegate(QObject *parent)
|
||||
|
||||
void LayoutNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QStyleOptionViewItem myOption = option;
|
||||
|
||||
bool isLocked = index.data(Qt::UserRole).toBool();
|
||||
|
||||
if (isLocked) {
|
||||
QStandardItemModel *model = (QStandardItemModel *) index.model();
|
||||
QString nameText = index.data(Qt::DisplayRole).toString();
|
||||
|
||||
//! font metrics
|
||||
QFontMetrics fm(option.font);
|
||||
int textWidth = fm.width(nameText);
|
||||
int thick = option.rect.height();
|
||||
myOption.rect.setWidth(option.rect.width() - thick);
|
||||
int startWidth = qBound(0, option.rect.width() - textWidth - thick , thick);
|
||||
|
||||
QStyledItemDelegate::paint(painter, myOption, index);
|
||||
QRect destinationS(option.rect.x(), option.rect.y(), startWidth, thick);
|
||||
QRect destinationE(option.rect.x() + option.rect.width() - thick, option.rect.y(), thick, thick);
|
||||
|
||||
QStyleOptionViewItem myOptionS = option;
|
||||
QStyleOptionViewItem myOptionE = option;
|
||||
QStyleOptionViewItem myOptionMain = option;
|
||||
myOptionS.rect = destinationS;
|
||||
myOptionE.rect = destinationE;
|
||||
myOptionMain.rect.setX(option.rect.x() + startWidth);
|
||||
myOptionMain.rect.setWidth(option.rect.width() - startWidth - thick);
|
||||
|
||||
QStyledItemDelegate::paint(painter, myOptionMain, index);
|
||||
//! draw background
|
||||
QStyledItemDelegate::paint(painter, myOptionS, model->index(index.row(), HIDDENTEXTCOLUMN));
|
||||
QStyledItemDelegate::paint(painter, myOptionE, model->index(index.row(), HIDDENTEXTCOLUMN));
|
||||
|
||||
//! draw icon
|
||||
QIcon lockIcon = QIcon::fromTheme("object-locked");
|
||||
QRect destination(option.rect.x() + option.rect.width() - thick, option.rect.y(), thick, thick);
|
||||
painter->drawPixmap(destination, lockIcon.pixmap(thick, thick));
|
||||
} else {
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
painter->drawPixmap(destinationE, lockIcon.pixmap(thick, thick));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,11 @@
|
||||
namespace Latte {
|
||||
|
||||
const int IDCOLUMN = 0;
|
||||
const int COLORCOLUMN = 1;
|
||||
const int NAMECOLUMN = 2;
|
||||
const int MENUCOLUMN = 3;
|
||||
const int ACTIVITYCOLUMN = 4;
|
||||
const int HIDDENTEXTCOLUMN = 1;
|
||||
const int COLORCOLUMN = 2;
|
||||
const int NAMECOLUMN = 3;
|
||||
const int MENUCOLUMN = 4;
|
||||
const int ACTIVITYCOLUMN = 5;
|
||||
|
||||
const int SCREENTRACKERDEFAULTVALUE = 2500;
|
||||
|
||||
@ -83,7 +84,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, DockCorona *corona)
|
||||
connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked
|
||||
, this, &SettingsDialog::restoreDefaults);
|
||||
|
||||
m_model = new QStandardItemModel(m_corona->layoutManager()->layouts().count(), 5, this);
|
||||
m_model = new QStandardItemModel(m_corona->layoutManager()->layouts().count(), 6, this);
|
||||
|
||||
ui->layoutsView->setModel(m_model);
|
||||
ui->layoutsView->horizontalHeader()->setStretchLastSection(true);
|
||||
@ -380,6 +381,24 @@ void SettingsDialog::on_removeButton_clicked()
|
||||
ui->layoutsView->selectRow(row);
|
||||
}
|
||||
|
||||
void SettingsDialog::on_lockedButton_clicked()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
int row = ui->layoutsView->currentIndex().row();
|
||||
|
||||
if (row < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool lockedModel = m_model->data(m_model->index(row, NAMECOLUMN), Qt::UserRole).toBool();
|
||||
|
||||
m_model->setData(m_model->index(row, NAMECOLUMN), QVariant(!lockedModel), Qt::UserRole);
|
||||
|
||||
updatePerLayoutButtonsState();
|
||||
updateApplyButtonsState();
|
||||
}
|
||||
|
||||
void SettingsDialog::on_importButton_clicked()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
@ -814,6 +833,7 @@ void SettingsDialog::loadSettings()
|
||||
|
||||
//! this line should be commented for debugging layouts window functionality
|
||||
ui->layoutsView->setColumnHidden(IDCOLUMN, true);
|
||||
ui->layoutsView->setColumnHidden(HIDDENTEXTCOLUMN, true);
|
||||
|
||||
ui->layoutsView->resizeColumnsToContents();
|
||||
|
||||
@ -901,6 +921,8 @@ void SettingsDialog::insertLayoutInfoAtRow(int row, QString path, QString color,
|
||||
{
|
||||
QStandardItem *pathItem = new QStandardItem(path);
|
||||
|
||||
QStandardItem *hiddenTextItem = new QStandardItem();
|
||||
|
||||
QStandardItem *colorItem = new QStandardItem();
|
||||
colorItem->setSelectable(false);
|
||||
|
||||
@ -918,6 +940,7 @@ void SettingsDialog::insertLayoutInfoAtRow(int row, QString path, QString color,
|
||||
QList<QStandardItem *> items;
|
||||
|
||||
items.append(pathItem);
|
||||
items.append(hiddenTextItem);
|
||||
items.append(colorItem);
|
||||
items.append(nameItem);
|
||||
items.append(menuItem);
|
||||
@ -1119,6 +1142,7 @@ void SettingsDialog::updatePerLayoutButtonsState()
|
||||
QString id = m_model->data(m_model->index(currentRow, IDCOLUMN), Qt::DisplayRole).toString();
|
||||
QString nameInModel = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::DisplayRole).toString();
|
||||
QString originalName = m_layouts.contains(id) ? m_layouts[id]->name() : "";
|
||||
bool lockedInModel = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::UserRole).toBool();
|
||||
|
||||
//! Switch Button
|
||||
if (id.startsWith("/tmp/") || originalName != nameInModel) {
|
||||
@ -1152,6 +1176,12 @@ void SettingsDialog::updatePerLayoutButtonsState()
|
||||
} else {
|
||||
ui->removeButton->setEnabled(true);
|
||||
}
|
||||
|
||||
if (lockedInModel) {
|
||||
ui->lockedButton->setChecked(true);
|
||||
} else {
|
||||
ui->lockedButton->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsDialog::recalculateAvailableActivities()
|
||||
|
@ -65,6 +65,7 @@ private slots:
|
||||
void on_newButton_clicked();
|
||||
void on_copyButton_clicked();
|
||||
void on_downloadButton_clicked();
|
||||
void on_lockedButton_clicked();
|
||||
void on_pauseButton_clicked();
|
||||
void on_removeButton_clicked();
|
||||
void on_switchButton_clicked();
|
||||
|
@ -169,7 +169,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@ -198,7 +198,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@ -248,6 +248,38 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_10">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>1</width>
|
||||
<height>11</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="lockedButton">
|
||||
<property name="toolTip">
|
||||
<string>Lock layout and make it read-only</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string comment="locked layout">Locked</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="object-locked"/>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
@ -259,7 +291,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@ -303,7 +335,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
<height>15</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
|
Loading…
Reference in New Issue
Block a user