~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to wallpapers/pattern/pattern.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-26 13:35:18 UTC
  • mfrom: (1.1.37 upstream)
  • Revision ID: james.westby@ubuntu.com-20101126133518-oxz33xjsoi02ty9f
Tags: 4:4.5.80-0ubuntu1
* New upstream beta release
* Disable kubuntu_02_microblog_default_configuration.diff does not apply
* New package plasma-containments-addons

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
void PatternWallpaper::loadPattern()
62
62
{
63
63
    if (!m_patternName.isEmpty()) {
64
 
        const QString pattern = m_dirs->findResource(PATTERN_RESOURCE_TYPE, m_patternName);
65
 
        QImage m_patternImage;
66
 
 
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);
70
 
        } else {
71
 
            kDebug() << "pattern" << m_patternName << "at" << pattern << "failed to load";
72
 
        }
 
64
        m_pattern = generatePattern(m_patternName, m_fgColor, m_bgColor);
73
65
    }
74
66
}
75
67
 
112
104
            patternComment = fi.baseName();
113
105
        }
114
106
 
115
 
        m_ui.m_pattern->addItem(patternComment, patternFile);
 
107
        QListWidgetItem *item = new QListWidgetItem(patternComment, m_ui.m_pattern);
 
108
        item->setData(Qt::UserRole, patternFile);
 
109
 
 
110
        m_ui.m_pattern->addItem(item);
116
111
        ++i;
117
112
    }
 
113
 
 
114
    updateConfigThumbs();
 
115
 
118
116
    if (configuredPatternIndex != -1) {
119
 
        m_ui.m_pattern->setCurrentIndex(configuredPatternIndex);
 
117
        m_ui.m_pattern->setCurrentRow(configuredPatternIndex);
120
118
    }
121
119
 
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()));
125
123
 
126
124
    connect(this, SIGNAL(settingsChanged(bool)), parent, SLOT(settingsChanged(bool)));
127
125
    return configWidget;
128
126
}
129
127
 
 
128
QPixmap PatternWallpaper::generatePattern(const QString &patternFile, const QColor &fg, const QColor &bg) const
 
129
{
 
130
    QImage img;
 
131
    const QString path = m_dirs->findResource(PATTERN_RESOURCE_TYPE, patternFile);
 
132
 
 
133
    if (!img.load(path, 0)) {
 
134
        kDebug() << "pattern" << patternFile << "at" << path << "failed to load";
 
135
        return QPixmap();
 
136
    }
 
137
 
 
138
    return QPixmap::fromImage(Blitz::flatten(img, fg, bg));
 
139
}
 
140
 
130
141
void PatternWallpaper::save(KConfigGroup & config)
131
142
{
132
143
    config.writeEntry(FOREGROUND_COLOR_CONFIG_KEY, m_fgColor);
141
152
    }
142
153
}
143
154
 
 
155
void PatternWallpaper::updateConfigThumbs()
 
156
{
 
157
    for (int i = 0; i < m_ui.m_pattern->count(); ++i) {
 
158
        QListWidgetItem *item = m_ui.m_pattern->item(i);
 
159
        if (!item) {
 
160
            continue;
 
161
        }
 
162
 
 
163
        const QString patternFile = item->data(Qt::UserRole).toString();
 
164
 
 
165
        QPixmap pix(80, 80);
 
166
        QPainter p(&pix);
 
167
        p.drawTiledPixmap(pix.rect(), generatePattern(patternFile, m_fgColor, m_bgColor), QPoint(0,0));
 
168
        p.end();
 
169
 
 
170
        item->setIcon(QIcon(pix));
 
171
    }
 
172
}
 
173
 
144
174
void PatternWallpaper::widgetChanged()
145
175
{
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);
 
179
 
 
180
    m_fgColor = newFgColor;
 
181
    m_bgColor = newBgColor;
 
182
 
 
183
    if (updateThumbs) {
 
184
        updateConfigThumbs();
 
185
    }
 
186
 
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();
150
189
    }
 
190
 
151
191
    loadPattern();
152
192
    emit settingsChanged(true);
153
193
    emit update(boundingRect());