detailsdlg:draw scheme cmb properly

pull/22/head
Michail Vourlakos 4 years ago
parent 3bc3014863
commit 7dca67cb68

@ -4,6 +4,7 @@ set(lattedock-app_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/detailsdialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/detailshandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/patternwidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/schemescombobox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/schemesmodel.cpp
PARENT_SCOPE
)

@ -324,7 +324,7 @@
<item row="5" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QComboBox" name="customSchemeCmb">
<widget class="Latte::Settings::SchemesComboBox" name="customSchemeCmb">
<property name="minimumSize">
<size>
<width>358</width>
@ -740,6 +740,11 @@
<header>settings/detailsdialog/patternwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>Latte::Settings::SchemesComboBox</class>
<extends>QComboBox</extends>
<header>settings/detailsdialog/schemescombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>

@ -169,7 +169,9 @@ void DetailsHandler::loadLayout(const Latte::Data::Layout &data)
m_ui->patternClearBtn->setVisible(true);
}
m_ui->customSchemeCmb->setCurrentIndex(m_schemesModel->row(data.schemeFile));
int schind = m_schemesModel->row(data.schemeFile);
m_ui->customSchemeCmb->setCurrentIndex(schind);
updateCustomSchemeCmb(schind);
m_ui->colorPatternWidget->setBackground(m_colorsModel->colorPath(data.color));
m_ui->colorPatternWidget->setTextColor(Latte::Layout::AbstractLayout::defaultTextColor(data.color));
@ -287,8 +289,17 @@ void DetailsHandler::onCurrentLayoutIndexChanged(int row)
}
}
void DetailsHandler::updateCustomSchemeCmb(const int &row)
{
int scmind = row;
m_ui->customSchemeCmb->setCurrentText(m_ui->customSchemeCmb->itemData(scmind, Qt::DisplayRole).toString());
m_ui->customSchemeCmb->setTextColor(m_ui->customSchemeCmb->itemData(scmind, Model::Schemes::TEXTCOLORROLE).value<QColor>());
m_ui->customSchemeCmb->setBackgroundColor(m_ui->customSchemeCmb->itemData(scmind, Model::Schemes::BACKGROUNDCOLORROLE).value<QColor>());
}
void DetailsHandler::onCurrentSchemeIndexChanged(int row)
{
updateCustomSchemeCmb(row);
QString selectedScheme = m_ui->customSchemeCmb->itemData(row, Model::Schemes::IDROLE).toString();
setCustomSchemeFile(selectedScheme);
}

@ -79,6 +79,7 @@ private slots:
void selectIcon();
void selectTextColor();
void updateWindowTitle();
void updateCustomSchemeCmb(const int &row);
private:
void init();

@ -0,0 +1,94 @@
/*
SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "schemescombobox.h"
// local
#include "../generic/generictools.h"
// Qt
#include <QApplication>
#include <QDebug>
#include <QPalette>
#include <QStyleOptionComboBox>
#include <QStylePainter>
namespace Latte {
namespace Settings {
const int MARGIN = 2;
const int VERTMARGIN = 3;
SchemesComboBox::SchemesComboBox(QWidget *parent)
: QComboBox (parent)
{
}
QColor SchemesComboBox::backgroundColor() const
{
return m_backgroundColor;
}
void SchemesComboBox::setBackgroundColor(const QColor &color)
{
if (m_backgroundColor == color) {
return;
}
m_backgroundColor = color;
update();
}
QColor SchemesComboBox::textColor() const
{
return m_textColor;
}
void SchemesComboBox::setTextColor(const QColor &color)
{
if (m_textColor == color) {
return;
}
m_textColor = color;
update();
}
void SchemesComboBox::paintEvent(QPaintEvent *event)
{
QStylePainter painter(this);
painter.setPen(palette().color(QPalette::Text));
// draw the combobox frame, focusrect and selected etc.
QStyleOptionComboBox opt;
initStyleOption(&opt);
// background
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
// icon
QRect remained = Latte::remainedFromColorSchemeIcon(opt, Qt::AlignLeft, 3, 5);
Latte::drawColorSchemeIcon(&painter, opt, m_textColor, m_backgroundColor, Qt::AlignLeft, 7, 6);
opt.rect = remained;
// adjust text place, move it a bit to the left
QRect textRect;
int textnegativepad = MARGIN + 1;
if (qApp->layoutDirection() == Qt::LeftToRight) {
textRect = QRect(remained.x() - textnegativepad, opt.rect.y(), remained.width() + 2*textnegativepad, opt.rect.height());
} else {
textRect = QRect(remained.x(), opt.rect.y(), remained.width() + 2 * textnegativepad, opt.rect.height());
}
opt.rect = textRect;
// text
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
}
}
}

@ -0,0 +1,41 @@
/*
SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef SCHEMESCOMBOBOX_H
#define SCHEMESCOMBOBOX_H
//Qt
#include <QComboBox>
#include <QColor>
#include <QPaintEvent>
namespace Latte {
namespace Settings {
class SchemesComboBox : public QComboBox
{
Q_OBJECT
public:
SchemesComboBox(QWidget *parent = nullptr);
QColor backgroundColor() const;
void setBackgroundColor(const QColor &color);
QColor textColor() const;
void setTextColor(const QColor &color);
protected:
void paintEvent(QPaintEvent *event) override;
private:
QColor m_backgroundColor;
QColor m_textColor;
};
}
}
#endif

@ -326,9 +326,9 @@ void drawColorSchemeIcon(QPainter *painter, const QStyleOption &option, const QC
}
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setRenderHint(QPainter::Antialiasing, false);
int backImageMargin = 1; //most icon themes provide 1-2px. padding around icons //OLD CALCS: ICONMARGIN; //qMin(target.height()/4, ICONMARGIN+1);
int backImageMargin = 0; //most icon themes provide 1-2px. padding around icons //OLD CALCS: ICONMARGIN; //qMin(target.height()/4, ICONMARGIN+1);
QRect backTarget(target.x() + backImageMargin, target.y() + backImageMargin, target.width() - 2*backImageMargin, target.height() - 2*backImageMargin);
QPalette::ColorRole textColorRole = selected ? QPalette::HighlightedText : QPalette::Text;

Loading…
Cancel
Save