61
61
void PatternWallpaper::loadPattern()
63
63
if (!m_patternName.isEmpty()) {
64
const QString pattern = m_dirs->findResource(PATTERN_RESOURCE_TYPE, m_patternName);
65
QImage m_patternImage;
67
if (m_patternImage.load(pattern, 0)) {
68
m_patternImage = Blitz::flatten(m_patternImage, m_fgColor, m_bgColor);
69
m_pattern = QPixmap::fromImage(m_patternImage);
71
kDebug() << "pattern" << m_patternName << "at" << pattern << "failed to load";
64
m_pattern = generatePattern(m_patternName, m_fgColor, m_bgColor);
112
104
patternComment = fi.baseName();
115
m_ui.m_pattern->addItem(patternComment, patternFile);
107
QListWidgetItem *item = new QListWidgetItem(patternComment, m_ui.m_pattern);
108
item->setData(Qt::UserRole, patternFile);
110
m_ui.m_pattern->addItem(item);
114
updateConfigThumbs();
118
116
if (configuredPatternIndex != -1) {
119
m_ui.m_pattern->setCurrentIndex(configuredPatternIndex);
117
m_ui.m_pattern->setCurrentRow(configuredPatternIndex);
122
120
connect(m_ui.m_fgColor, SIGNAL(changed(const QColor&)), SLOT(widgetChanged()));
123
121
connect(m_ui.m_bgColor, SIGNAL(changed(const QColor&)), SLOT(widgetChanged()));
124
connect(m_ui.m_pattern, SIGNAL(currentIndexChanged(int)), SLOT(widgetChanged()));
122
connect(m_ui.m_pattern, SIGNAL(currentRowChanged(int)), SLOT(widgetChanged()));
126
124
connect(this, SIGNAL(settingsChanged(bool)), parent, SLOT(settingsChanged(bool)));
127
125
return configWidget;
128
QPixmap PatternWallpaper::generatePattern(const QString &patternFile, const QColor &fg, const QColor &bg) const
131
const QString path = m_dirs->findResource(PATTERN_RESOURCE_TYPE, patternFile);
133
if (!img.load(path, 0)) {
134
kDebug() << "pattern" << patternFile << "at" << path << "failed to load";
138
return QPixmap::fromImage(Blitz::flatten(img, fg, bg));
130
141
void PatternWallpaper::save(KConfigGroup & config)
132
143
config.writeEntry(FOREGROUND_COLOR_CONFIG_KEY, m_fgColor);
155
void PatternWallpaper::updateConfigThumbs()
157
for (int i = 0; i < m_ui.m_pattern->count(); ++i) {
158
QListWidgetItem *item = m_ui.m_pattern->item(i);
163
const QString patternFile = item->data(Qt::UserRole).toString();
167
p.drawTiledPixmap(pix.rect(), generatePattern(patternFile, m_fgColor, m_bgColor), QPoint(0,0));
170
item->setIcon(QIcon(pix));
144
174
void PatternWallpaper::widgetChanged()
146
m_fgColor = m_ui.m_fgColor->color();
147
m_bgColor = m_ui.m_bgColor->color();
176
const QColor newFgColor = m_ui.m_fgColor->color();
177
const QColor newBgColor = m_ui.m_bgColor->color();
178
const bool updateThumbs = (m_fgColor != newFgColor) || (m_bgColor != newBgColor);
180
m_fgColor = newFgColor;
181
m_bgColor = newBgColor;
184
updateConfigThumbs();
148
187
if (m_ui.m_pattern->count()) {
149
m_patternName = m_ui.m_pattern->itemData(m_ui.m_pattern->currentIndex()).toString();
188
m_patternName = m_ui.m_pattern->item(m_ui.m_pattern->currentRow())->data(Qt::UserRole).toString();
152
192
emit settingsChanged(true);
153
193
emit update(boundingRect());