1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 13:33:50 +03:00

details:add colors functionality

This commit is contained in:
Michail Vourlakos 2020-07-30 10:14:39 +03:00
parent 3c94aa8d75
commit d8b339ac7b
4 changed files with 76 additions and 15 deletions

View File

@ -95,8 +95,15 @@ void DetailsHandler::init()
reload();
//! connect combobox after the selected layout has been loaded
connect(m_ui->layoutsCmb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailsHandler::on_currentIndexChanged);
//! connect layout combobox after the selected layout has been loaded
connect(m_ui->layoutsCmb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailsHandler::on_currentLayoutIndexChanged);
//! connect colors combobox after the selected layout has been loaded
connect(m_ui->colorsCmb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailsHandler::on_currentColorIndexChanged);
connect(this, &DetailsHandler::dataChanged, this, [&]() {
loadLayout(c_data);
});
}
void DetailsHandler::reload()
@ -113,11 +120,14 @@ void DetailsHandler::loadLayout(const Data::Layout &data)
{
if (data.backgroundStyle == Latte::Layout::ColorBackgroundStyle) {
m_ui->colorRadioBtn->setChecked(true);
m_ui->backRadioBtn->setChecked(false);
} else {
m_ui->colorRadioBtn->setChecked(false);
m_ui->backRadioBtn->setChecked(true);
}
m_ui->colorPatternWidget->setBackground(m_parentDialog->layoutsController()->colorPath(data.color));
m_ui->colorPatternWidget->setBackground(m_colorsModel->colorPath(data.color));
m_ui->colorsCmb->setCurrentIndex(m_colorsModel->row(data.color));
m_ui->backPatternWidget->setBackground(data.background);
m_ui->colorPatternWidget->setTextColor(Layout::AbstractLayout::defaultTextColor(data.color));
@ -159,7 +169,13 @@ void DetailsHandler::save()
{
}
void DetailsHandler::on_currentIndexChanged(int row)
void DetailsHandler::on_currentColorIndexChanged(int row)
{
QString selectedColor = m_ui->colorsCmb->itemData(row, Model::Colors::IDROLE).toString();
setColor(selectedColor);
}
void DetailsHandler::on_currentLayoutIndexChanged(int row)
{
QString layoutId = m_layoutsProxyModel->data(m_layoutsProxyModel->index(row, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
m_parentDialog->layoutsController()->selectRow(layoutId);
@ -170,22 +186,52 @@ void DetailsHandler::on_currentIndexChanged(int row)
void DetailsHandler::setBackground(const QString &background)
{
if (c_data.background == background) {
return;
}
c_data.background = background;
emit dataChanged();
}
void DetailsHandler::setColor(const QString &color)
{
if (c_data.color == color) {
return;
}
c_data.color = color;
emit dataChanged();
}
void DetailsHandler::setTextColor(const QString &textColor)
{
if (c_data.textColor == textColor) {
return;
}
c_data.textColor = textColor;
emit dataChanged();
}
void DetailsHandler::setIsShownInMenu(bool inMenu)
{
if (c_data.isShownInMenu == inMenu) {
return;
}
c_data.isShownInMenu = inMenu;
emit dataChanged();
}
void DetailsHandler::setHasDisabledBorders(bool disabled)
{
if (c_data.hasDisabledBorders == disabled) {
return;
}
c_data.hasDisabledBorders = disabled;
emit dataChanged();
}
void DetailsHandler::selectBackground()

View File

@ -74,17 +74,12 @@ public:
Data::Layout currentData() const;
void setIsShownInMenu(bool inMenu);
void setHasDisabledBorders(bool disabled);
void setBackground(const QString &background);
void setTextColor(const QString &textColor);
signals:
void currentLayoutChanged();
private:
void on_currentIndexChanged(int row);
void on_currentLayoutIndexChanged(int row);
void on_currentColorIndexChanged(int row);
private:
void init();
@ -92,6 +87,13 @@ private:
void selectTextColor();
void reload();
void setIsShownInMenu(bool inMenu);
void setHasDisabledBorders(bool disabled);
void setBackground(const QString &background);
void setTextColor(const QString &textColor);
void setColor(const QString &color);
void loadLayout(const Data::Layout &data);
private:

View File

@ -91,6 +91,17 @@ int Colors::columnCount(const QModelIndex &parent) const
return TEXTCOLORROLE+1;
}
int Colors::row(const QString &id)
{
for (int i=0; i<m_colorsTable.count(); ++i){
if (m_colorsTable[i].id == id) {
return i;
}
}
return -1;
}
QVariant Colors::data(const QModelIndex &index, int role) const
{
const int row = index.row();

View File

@ -41,7 +41,7 @@ class Colors : public QAbstractTableModel
public:
enum ColorsRoles
{
IDROLE = 0,
IDROLE = Qt::UserRole + 1,
NAMEROLE,
PATHROLE,
TEXTCOLORROLE
@ -54,13 +54,15 @@ public:
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
int row(const QString &id);
QString colorPath(const QString &color);
QVariant data(const QModelIndex &index, int role) const override;
private:
void init();
void add(const QString &newid, const QString &newname, const QString &newpath, const QString &newtextcolor);
QString colorPath(const QString &color);
void add(const QString &newid, const QString &newname, const QString &newpath, const QString &newtextcolor);
private:
QString m_colorsPath;