~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kcontrol/kicker/lookandfeeltab_impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  lookandfeeltab.cpp
3
 
 *
4
 
 *  Copyright (c) 2000 Matthias Elter <elter@kde.org>
5
 
 *  Copyright (c) 2000 Aaron J. Seigo <aseigo@olympusproject.org>
6
 
 *
7
 
 *  This program is free software; you can redistribute it and/or modify
8
 
 *  it under the terms of the GNU General Public License as published by
9
 
 *  the Free Software Foundation; either version 2 of the License, or
10
 
 *  (at your option) any later version.
11
 
 *
12
 
 *  This program is distributed in the hope that it will be useful,
13
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 *  GNU General Public License for more details.
16
 
 *
17
 
 *  You should have received a copy of the GNU General Public License
18
 
 *  along with this program; if not, write to the Free Software
19
 
 */
20
 
 
21
 
#include <qcheckbox.h>
22
 
#include <qlabel.h>
23
 
#include <qradiobutton.h>
24
 
#include <qregexp.h>
25
 
 
26
 
#include <kcolorbutton.h>
27
 
#include <kdebug.h>
28
 
#include <kfiledialog.h>
29
 
#include <kiconeffect.h>
30
 
#include <kimageio.h>
31
 
#include <klineedit.h>
32
 
#include <klocale.h>
33
 
#include <kmessagebox.h>
34
 
#include <kstandarddirs.h>
35
 
 
36
 
#include <kickerSettings.h>
37
 
#include "advancedDialog.h"
38
 
#include "global.h"
39
 
#include "main.h"
40
 
 
41
 
#include "lookandfeeltab_impl.h"
42
 
#include "lookandfeeltab_impl.moc"
43
 
 
44
 
#include <iostream>
45
 
using namespace std;
46
 
 
47
 
LookAndFeelTab::LookAndFeelTab( QWidget *parent, const char* name )
48
 
  : LookAndFeelTabBase(parent, name),
49
 
    m_advDialog(0)
50
 
{
51
 
    connect(m_kmenuTile, SIGNAL(activated(int)), SIGNAL(changed()));
52
 
    connect(m_desktopTile, SIGNAL(activated(int)), SIGNAL(changed()));
53
 
    connect(m_browserTile, SIGNAL(activated(int)), SIGNAL(changed()));
54
 
    connect(m_urlTile, SIGNAL(activated(int)), SIGNAL(changed()));
55
 
    connect(m_windowListTile, SIGNAL(activated(int)), SIGNAL(changed()));
56
 
 
57
 
    connect(m_kmenuTile, SIGNAL(activated(int)), SLOT(kmenuTileChanged(int)));
58
 
    connect(m_desktopTile, SIGNAL(activated(int)), SLOT(desktopTileChanged(int)));
59
 
    connect(m_browserTile, SIGNAL(activated(int)), SLOT(browserTileChanged(int)));
60
 
    connect(m_urlTile, SIGNAL(activated(int)), SLOT(urlTileChanged(int)));
61
 
    connect(m_windowListTile, SIGNAL(activated(int)), SLOT(wlTileChanged(int)));
62
 
 
63
 
    connect(kcfg_ColorizeBackground, SIGNAL(toggled(bool)), SLOT(browseTheme()));
64
 
 
65
 
    connect(kcfg_BackgroundTheme->lineEdit(), SIGNAL(lostFocus()), SLOT(browseTheme()));
66
 
    kcfg_BackgroundTheme->setFilter(KImageIO::pattern(KImageIO::Reading));
67
 
    kcfg_BackgroundTheme->setCaption(i18n("Select Image File"));
68
 
 
69
 
    fillTileCombos();
70
 
}
71
 
 
72
 
void LookAndFeelTab::browseTheme()
73
 
{
74
 
    browseTheme(kcfg_BackgroundTheme->url());
75
 
}
76
 
 
77
 
void LookAndFeelTab::browseTheme(const QString& newtheme)
78
 
{
79
 
    if (newtheme.isEmpty())
80
 
    {
81
 
        kcfg_BackgroundTheme->clear();
82
 
        m_backgroundLabel->setPixmap(QPixmap());
83
 
        emit changed();
84
 
        return;
85
 
    }
86
 
 
87
 
    previewBackground(newtheme, true);
88
 
}
89
 
 
90
 
void LookAndFeelTab::launchAdvancedDialog()
91
 
{
92
 
    if (!m_advDialog)
93
 
    {
94
 
        m_advDialog = new advancedDialog(this, "advancedDialog");
95
 
        connect(m_advDialog, SIGNAL(finished()), this, SLOT(finishAdvancedDialog()));
96
 
        m_advDialog->show();
97
 
    }
98
 
    m_advDialog->setActiveWindow();
99
 
}
100
 
 
101
 
void LookAndFeelTab::finishAdvancedDialog()
102
 
{
103
 
    m_advDialog->delayedDestruct();
104
 
    m_advDialog = 0;
105
 
}
106
 
 
107
 
void LookAndFeelTab::enableTransparency(bool useTransparency)
108
 
{
109
 
    bool useBgTheme = kcfg_UseBackgroundTheme->isChecked();
110
 
 
111
 
    kcfg_UseBackgroundTheme->setDisabled(useTransparency);
112
 
    kcfg_BackgroundTheme->setDisabled(useTransparency || !useBgTheme);
113
 
    m_backgroundLabel->setDisabled(useTransparency || !useBgTheme);
114
 
    kcfg_ColorizeBackground->setDisabled(useTransparency || !useBgTheme);
115
 
}
116
 
 
117
 
void LookAndFeelTab::previewBackground(const QString& themepath, bool isNew)
118
 
{
119
 
    QString theme = themepath;
120
 
    if (theme[0] != '/')
121
 
        theme = locate("data", "kicker/" + theme);
122
 
 
123
 
    QImage tmpImg(theme);
124
 
    if(!tmpImg.isNull())
125
 
    {
126
 
        tmpImg = tmpImg.smoothScale(m_backgroundLabel->contentsRect().width(),
127
 
                                    m_backgroundLabel->contentsRect().height());
128
 
        if (kcfg_ColorizeBackground->isChecked())
129
 
            KickerLib::colorize(tmpImg);
130
 
        theme_preview.convertFromImage(tmpImg);
131
 
        if(!theme_preview.isNull()) {
132
 
            // avoid getting changed(true) from KConfigDialogManager for the default value
133
 
            if( KickerSettings::backgroundTheme() == themepath )
134
 
                KickerSettings::setBackgroundTheme( theme );
135
 
            kcfg_BackgroundTheme->lineEdit()->setText(theme);
136
 
            m_backgroundLabel->setPixmap(theme_preview);
137
 
            if (isNew)
138
 
                emit changed();
139
 
            return;
140
 
        }
141
 
    }
142
 
 
143
 
    KMessageBox::error(this,
144
 
                       i18n("Error loading theme image file.\n\n%1\n%2")
145
 
                            .arg(theme, themepath));
146
 
    kcfg_BackgroundTheme->clear();
147
 
    m_backgroundLabel->setPixmap(QPixmap());
148
 
}
149
 
 
150
 
void LookAndFeelTab::load()
151
 
{
152
 
   load( false );
153
 
}
154
 
 
155
 
void LookAndFeelTab::load(bool useDefaults)
156
 
{
157
 
    KConfig config(KickerConfig::the()->configName(), false, false);
158
 
 
159
 
    config.setReadDefaults( useDefaults );
160
 
 
161
 
    config.setGroup("General");
162
 
 
163
 
    bool use_theme = kcfg_UseBackgroundTheme->isChecked();
164
 
    QString theme = kcfg_BackgroundTheme->lineEdit()->text().stripWhiteSpace();
165
 
 
166
 
    bool transparent = kcfg_Transparent->isChecked();
167
 
 
168
 
    kcfg_BackgroundTheme->setEnabled(use_theme);
169
 
    m_backgroundLabel->setEnabled(use_theme);
170
 
    kcfg_ColorizeBackground->setEnabled(use_theme);
171
 
    m_backgroundLabel->clear();
172
 
    if (theme.length() > 0)
173
 
    {
174
 
        previewBackground(theme, false);
175
 
    }
176
 
 
177
 
    QString tile;
178
 
    config.setGroup("buttons");
179
 
 
180
 
    kmenuTileChanged(m_kmenuTile->currentItem());
181
 
    desktopTileChanged(m_desktopTile->currentItem());
182
 
    urlTileChanged(m_urlTile->currentItem());
183
 
    browserTileChanged(m_browserTile->currentItem());
184
 
    wlTileChanged(m_windowListTile->currentItem());
185
 
 
186
 
    if (config.readBoolEntry("EnableTileBackground", false))
187
 
    {
188
 
        config.setGroup("button_tiles");
189
 
 
190
 
        if (config.readBoolEntry("EnableKMenuTiles", false))
191
 
        {
192
 
            tile = config.readEntry("KMenuTile", "solid_blue");
193
 
            m_kmenuTile->setCurrentItem(m_tilename.findIndex(tile));
194
 
            kcfg_KMenuTileColor->setEnabled(tile == "Colorize");
195
 
        }
196
 
 
197
 
        if (config.readBoolEntry("EnableDesktopButtonTiles", false))
198
 
        {
199
 
            tile = config.readEntry("DesktopButtonTile", "solid_orange");
200
 
            m_desktopTile->setCurrentItem(m_tilename.findIndex(tile));
201
 
            kcfg_DesktopButtonTileColor->setEnabled(tile == "Colorize");
202
 
        }
203
 
 
204
 
        if (config.readBoolEntry("EnableURLTiles", false))
205
 
        {
206
 
            tile = config.readEntry("URLTile", "solid_gray");
207
 
            m_urlTile->setCurrentItem(m_tilename.findIndex(tile));
208
 
            kcfg_URLTileColor->setEnabled(tile == "Colorize");
209
 
        }
210
 
 
211
 
        if (config.readBoolEntry("EnableBrowserTiles", false))
212
 
        {
213
 
            tile = config.readEntry("BrowserTile", "solid_green");
214
 
            m_browserTile->setCurrentItem(m_tilename.findIndex(tile));
215
 
            kcfg_BrowserTileColor->setEnabled(tile == "Colorize");
216
 
        }
217
 
 
218
 
        if (config.readBoolEntry("EnableWindowListTiles", false))
219
 
        {
220
 
            tile = config.readEntry("WindowListTile", "solid_green");
221
 
            m_windowListTile->setCurrentItem(m_tilename.findIndex(tile));
222
 
            kcfg_WindowListTileColor->setEnabled(tile == "Colorize");
223
 
        }
224
 
    }
225
 
    enableTransparency( transparent );
226
 
}
227
 
 
228
 
void LookAndFeelTab::save()
229
 
{
230
 
    KConfig config(KickerConfig::the()->configName(), false, false);
231
 
 
232
 
    config.setGroup("General");
233
 
 
234
 
    config.setGroup("button_tiles");
235
 
    bool enableTiles = false;
236
 
    int tile = m_kmenuTile->currentItem();
237
 
    if (tile > 0)
238
 
    {
239
 
        enableTiles = true;
240
 
        config.writeEntry("EnableKMenuTiles", true);
241
 
        config.writeEntry("KMenuTile", m_tilename[m_kmenuTile->currentItem()]);
242
 
    }
243
 
    else
244
 
    {
245
 
        config.writeEntry("EnableKMenuTiles", false);
246
 
    }
247
 
 
248
 
    tile = m_desktopTile->currentItem();
249
 
    if (tile > 0)
250
 
    {
251
 
        enableTiles = true;
252
 
        config.writeEntry("EnableDesktopButtonTiles", true);
253
 
        config.writeEntry("DesktopButtonTile", m_tilename[m_desktopTile->currentItem()]);
254
 
    }
255
 
    else
256
 
    {
257
 
        config.writeEntry("EnableDesktopButtonTiles", false);
258
 
    }
259
 
 
260
 
    tile = m_urlTile->currentItem();
261
 
    if (tile > 0)
262
 
    {
263
 
        enableTiles = true;
264
 
        config.writeEntry("EnableURLTiles", tile > 0);
265
 
        config.writeEntry("URLTile", m_tilename[m_urlTile->currentItem()]);
266
 
    }
267
 
    else
268
 
    {
269
 
        config.writeEntry("EnableURLTiles", false);
270
 
    }
271
 
 
272
 
    tile = m_browserTile->currentItem();
273
 
    if (tile > 0)
274
 
    {
275
 
        enableTiles = true;
276
 
        config.writeEntry("EnableBrowserTiles", tile > 0);
277
 
        config.writeEntry("BrowserTile", m_tilename[m_browserTile->currentItem()]);
278
 
    }
279
 
    else
280
 
    {
281
 
        config.writeEntry("EnableBrowserTiles", false);
282
 
    }
283
 
 
284
 
    tile = m_windowListTile->currentItem();
285
 
    if (tile > 0)
286
 
    {
287
 
        enableTiles = true;
288
 
        config.writeEntry("EnableWindowListTiles", tile > 0);
289
 
        config.writeEntry("WindowListTile", m_tilename[m_windowListTile->currentItem()]);
290
 
    }
291
 
    else
292
 
    {
293
 
        config.writeEntry("EnableWindowListTiles", false);
294
 
    }
295
 
 
296
 
    config.setGroup("buttons");
297
 
    config.writeEntry("EnableTileBackground", enableTiles);
298
 
 
299
 
    config.sync();
300
 
}
301
 
 
302
 
void LookAndFeelTab::defaults()
303
 
{
304
 
   load( true );
305
 
}
306
 
 
307
 
void LookAndFeelTab::fillTileCombos()
308
 
{
309
 
/*  m_kmenuTile->clear();
310
 
  m_kmenuTile->insertItem(i18n("Default"));
311
 
  m_desktopTile->clear();
312
 
  m_desktopTile->insertItem(i18n("Default"));
313
 
  m_urlTile->clear();
314
 
  m_urlTile->insertItem(i18n("Default"));
315
 
  m_browserTile->clear();
316
 
  m_browserTile->insertItem(i18n("Default"));
317
 
  m_windowListTile->clear();
318
 
  m_windowListTile->insertItem(i18n("Default"));*/
319
 
  m_tilename.clear();
320
 
  m_tilename << "" << "Colorize";
321
 
 
322
 
  QStringList list = KGlobal::dirs()->findAllResources("tiles","*_tiny_up.png");
323
 
  int minHeight = 0;
324
 
 
325
 
  for (QStringList::Iterator it = list.begin(); it != list.end(); ++it)
326
 
  {
327
 
    QString tile = (*it);
328
 
    QPixmap pix(tile);
329
 
    QFileInfo fi(tile);
330
 
    tile = fi.fileName();
331
 
    tile.truncate(tile.find("_tiny_up.png"));
332
 
    m_tilename << tile;
333
 
 
334
 
    // Transform tile to words with title case
335
 
    // The same is done when generating messages for translation
336
 
    QStringList words = QStringList::split(QRegExp("[_ ]"), tile);
337
 
    for (QStringList::iterator w = words.begin(); w != words.end(); ++w)
338
 
      (*w)[0] = (*w)[0].upper();
339
 
    tile = i18n(words.join(" ").utf8());
340
 
 
341
 
    m_kmenuTile->insertItem(pix, tile);
342
 
    m_desktopTile->insertItem(pix, tile);
343
 
    m_urlTile->insertItem(pix, tile);
344
 
    m_browserTile->insertItem(pix, tile);
345
 
    m_windowListTile->insertItem(pix, tile);
346
 
 
347
 
    if (pix.height() > minHeight)
348
 
    {
349
 
        minHeight = pix.height();
350
 
    }
351
 
  }
352
 
 
353
 
  minHeight += 6;
354
 
  m_kmenuTile->setMinimumHeight(minHeight);
355
 
  m_desktopTile->setMinimumHeight(minHeight);
356
 
  m_urlTile->setMinimumHeight(minHeight);
357
 
  m_browserTile->setMinimumHeight(minHeight);
358
 
  m_windowListTile->setMinimumHeight(minHeight);
359
 
}
360
 
 
361
 
void LookAndFeelTab::kmenuTileChanged(int i)
362
 
{
363
 
    kcfg_KMenuTileColor->setEnabled(i == 1);
364
 
}
365
 
 
366
 
void LookAndFeelTab::desktopTileChanged(int i)
367
 
{
368
 
    kcfg_DesktopButtonTileColor->setEnabled(i == 1);
369
 
}
370
 
 
371
 
void LookAndFeelTab::browserTileChanged(int i)
372
 
{
373
 
    kcfg_BrowserTileColor->setEnabled(i == 1);
374
 
}
375
 
 
376
 
void LookAndFeelTab::urlTileChanged(int i)
377
 
{
378
 
    kcfg_URLTileColor->setEnabled(i == 1);
379
 
}
380
 
 
381
 
void LookAndFeelTab::wlTileChanged(int i)
382
 
{
383
 
    kcfg_WindowListTileColor->setEnabled(i == 1);
384
 
}