1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include <QPalette>
#include <QColorDialog>
#include <QSettings>
#include "lthemeengine.h"
#include "paletteeditdialog.h"
#include "ui_paletteeditdialog.h"
PaletteEditDialog::PaletteEditDialog(const QPalette &palette, QStyle *currentStyle, QWidget *parent) : QDialog(parent), m_ui(new Ui::PaletteEditDialog){
m_currentStyle = currentStyle;
m_ui->setupUi(this);
m_ui->tableWidget->setColumnCount(3);
m_ui->tableWidget->setRowCount(QPalette::NColorRoles);
m_ui->tableWidget->verticalHeader()->setDefaultSectionSize(fontMetrics().lineSpacing() + 10);
m_ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
m_ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
QStringList labels;
labels << tr("Active") << tr("Inactive") << tr("Disabled");
m_ui->tableWidget->setHorizontalHeaderLabels(labels);
setPalette(palette);
QSettings settings(lthemeengine::configFile(), QSettings::IniFormat);
restoreGeometry(settings.value("PaletteEditor/geometry").toByteArray());
}
PaletteEditDialog::~PaletteEditDialog(){
delete m_ui;
}
QPalette PaletteEditDialog::selectedPalette() const{
QPalette palette;
for(int i = 0; i < QPalette::NColorRoles; i++){
palette.setBrush(QPalette::Active, QPalette::ColorRole(i), m_ui->tableWidget->item(i,0)->backgroundColor());
palette.setBrush(QPalette::Inactive, QPalette::ColorRole(i), m_ui->tableWidget->item(i,1)->backgroundColor());
palette.setBrush(QPalette::Disabled, QPalette::ColorRole(i), m_ui->tableWidget->item(i,2)->backgroundColor());
}
return palette;
}
void PaletteEditDialog::setPalette(const QPalette &palette){
for(int i = 0; i < QPalette::NColorRoles; i++){
if(!m_ui->tableWidget->item(i,0)){ m_ui->tableWidget->setItem(i, 0, new QTableWidgetItem()); }
if(!m_ui->tableWidget->item(i,1)){ m_ui->tableWidget->setItem(i, 1, new QTableWidgetItem()); }
if(!m_ui->tableWidget->item(i,2)){ m_ui->tableWidget->setItem(i, 2, new QTableWidgetItem()); }
m_ui->tableWidget->item(i,0)->setBackgroundColor(palette.color(QPalette::Active, QPalette::ColorRole(i)));
m_ui->tableWidget->item(i,1)->setBackgroundColor(palette.color(QPalette::Inactive, QPalette::ColorRole(i)));
m_ui->tableWidget->item(i,2)->setBackgroundColor(palette.color(QPalette::Disabled, QPalette::ColorRole(i)));
}
QStringList labels;
labels << tr("Window text") << tr("Button background") << tr("Bright") << tr("Less bright") << tr("Dark") << tr("Less dark") << tr("Normal text") << tr("Bright text") << tr("Button text") << tr("Normal background") << tr("Window") << tr("Shadow") << tr("Highlight") << tr("Highlighted text") << tr("Link") << tr("Visited link") << tr("Alternate background") << tr("Default") << tr("Tooltip background") << tr("Tooltip text") << tr("Placeholder text");
m_ui->tableWidget->setVerticalHeaderLabels(labels);
}
void PaletteEditDialog::hideEvent(QHideEvent *){
QSettings settings(lthemeengine::configFile(), QSettings::IniFormat);
settings.setValue("PaletteEditor/geometry", saveGeometry());
}
void PaletteEditDialog::on_tableWidget_itemClicked(QTableWidgetItem *item){
QColor color = QColorDialog::getColor(item->backgroundColor(), this, tr("Select Color"));
if(color.isValid()){
item->setBackgroundColor(color);
emit paletteChanged(selectedPalette());
}
}
void PaletteEditDialog::on_resetPaletteButton_clicked(){
setPalette(m_currentStyle->standardPalette());
emit paletteChanged(selectedPalette());
}
void PaletteEditDialog::on_buildInactiveButton_clicked(){
QPalette palette = selectedPalette();
for(int i = 0; i < QPalette::NColorRoles; i++){
palette.setColor(QPalette::Inactive, QPalette::ColorRole(i),
palette.color(QPalette::Active, QPalette::ColorRole(i)));
}
setPalette(palette);
emit paletteChanged(selectedPalette());
}
void PaletteEditDialog::on_buildDisabledButton_clicked(){
QPalette palette = selectedPalette();
for(int i = 0; i < QPalette::NColorRoles; i++){
palette.setColor(QPalette::Disabled, QPalette::ColorRole(i),
palette.color(QPalette::Active, QPalette::ColorRole(i)));
}
palette.setColor(QPalette::Disabled, QPalette::ButtonText, Qt::darkGray);
palette.setColor(QPalette::Disabled, QPalette::WindowText, Qt::darkGray);
palette.setColor(QPalette::Disabled, QPalette::Text, Qt::darkGray);
palette.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::darkGray);
setPalette(palette);
emit paletteChanged(selectedPalette());
}
|