2
kate: space-indent on; indent-width 3; indent-mode cstyle;
4
This file is part of the KDE libraries
6
Copyright (c) 2005 David Saxton <david@bluehaze.org>
7
Copyright (c) 2003 Waldo Bastian <bastian@kde.org>
8
Copyright (c) 1999 Geert Jansen <g.t.jansen@stud.tue.nl>
9
Copyright (c) 1996 Martin R. Jones
10
Copyright (c) 1997 Matthias Hoelzer
11
Copyright (c) 1997 Mark Donohoe
12
Copyright (c) 1998 Stephan Kulow
13
Copyright (c) 1998 Matej Koss
15
This program is free software; you can redistribute it and/or
16
modify it under the terms of the GNU General Public License
17
version 2 as published by the Free Software Foundation.
19
This library is distributed in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22
Library General Public License for more details.
24
You should have received a copy of the GNU Library General Public License
25
along with this library; see the file COPYING.LIB. If not, write to
26
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27
Boston, MA 02110-1301, USA.
35
#include <QApplication>
37
#include <QDesktopWidget>
41
#include <kfiledialog.h>
42
#include <kfilemetainfo.h>
44
#include <kiconloader.h>
47
#include <kstandarddirs.h>
48
#include <kstringhandler.h>
49
#include <kurlrequester.h>
50
#include <kwindowsystem.h>
51
#include <kdesktopfile.h>
52
#include <kimagefilepreview.h>
53
#include <knewstuff3/downloaddialog.h>
57
#include "bgmonitor.h"
58
#include "bgwallpaper.h"
59
#include "bgadvanced.h"
62
#include "kworkspace/screenpreviewwidget.h"
64
#define NR_PREDEF_PATTERNS 6
66
BGDialog::BGDialog(QWidget *parent, const KSharedConfigPtr &_config)
67
: BGDialog_UI(parent), m_readOnly(false)
69
m_pGlobals = new KGlobalBackgroundSettings(_config);
70
m_pDirs = KGlobal::dirs();
71
m_previewUpdates = true;
73
m_numScreens = QApplication::desktop()->numScreens();
75
QString multiHead = getenv("KDE_MULTIHEAD");
76
if (multiHead.toLower() == "true")
79
m_screen = QApplication::desktop()->screenNumber(this);
80
if (m_screen >= (int)m_numScreens)
81
m_screen = m_numScreens - 1;
84
m_copyAllScreens = true;
86
if (m_numScreens < 2) {
87
m_comboScreen->hide();
88
m_buttonIdentifyScreens->hide();
93
connect(m_buttonIdentifyScreens, SIGNAL(clicked()), SLOT(slotIdentifyScreens()));
96
m_pMonitorArrangement = new BGMonitorArrangement(m_screenArrangement);
97
m_pMonitorArrangement->setObjectName("monitor arrangement");
98
connect(m_pMonitorArrangement, SIGNAL(imageDropped(const QString &)), SLOT(slotImageDropped(const QString &)));
99
if (m_numScreens > 1) {
100
connect(m_comboScreen, SIGNAL(activated(int)),
101
SLOT(slotSelectScreen(int)));
104
// background image settings
105
QIcon iconSet = KIcon(QLatin1String("document-open"));
106
QPixmap pixMap = iconSet.pixmap(
107
style()->pixelMetric(QStyle::PM_SmallIconSize), QIcon::Normal);
108
m_urlWallpaperButton->setIcon(iconSet);
109
m_urlWallpaperButton->setFixedSize(pixMap.width() + 8, pixMap.height() + 8);
110
m_urlWallpaperButton->setToolTip(i18n("Open file dialog"));
112
connect(m_buttonGroupBackground, SIGNAL(clicked(int)),
113
SLOT(slotWallpaperTypeChanged(int)));
114
connect(m_urlWallpaperBox, SIGNAL(activated(int)),
115
SLOT(slotWallpaper(int)));
116
connect(m_urlWallpaperButton, SIGNAL(clicked()),
117
SLOT(slotWallpaperSelection()));
118
connect(m_comboWallpaperPos, SIGNAL(activated(int)),
119
SLOT(slotWallpaperPos(int)));
120
connect(m_buttonSetupWallpapers, SIGNAL(clicked()),
121
SLOT(slotSetupMulti()));
123
// set up the background colour stuff
124
connect(m_colorPrimary, SIGNAL(changed(const QColor &)),
125
SLOT(slotPrimaryColor(const QColor &)));
126
connect(m_colorSecondary, SIGNAL(changed(const QColor &)),
127
SLOT(slotSecondaryColor(const QColor &)));
128
connect(m_comboPattern, SIGNAL(activated(int)),
129
SLOT(slotPattern(int)));
132
connect(m_comboBlend, SIGNAL(activated(int)), SLOT(slotBlendMode(int)));
133
connect(m_sliderBlend, SIGNAL(valueChanged(int)),
134
SLOT(slotBlendBalance(int)));
135
connect(m_cbBlendReverse, SIGNAL(toggled(bool)),
136
SLOT(slotBlendReverse(bool)));
139
connect(m_buttonAdvanced, SIGNAL(clicked()),
140
SLOT(slotAdvanced()));
142
connect(m_buttonGetNew, SIGNAL(clicked()),
143
SLOT(slotGetNewStuff()));
146
if (m_numScreens > 1) {
147
// Setup the merged-screen renderer
148
KBackgroundRenderer *r = new KBackgroundRenderer(0, false, _config);
149
m_renderer.insert(0, r);
150
connect(r, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)));
152
// Setup the common-screen renderer
153
r = new KBackgroundRenderer(0, true, _config);
154
m_renderer.insert(1, r);
155
connect(r, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)));
157
// Setup the remaining renderers for each screen
158
for (unsigned j = 0; j < m_numScreens; ++j) {
159
r = new KBackgroundRenderer(j, true, _config);
160
m_renderer.insert(j + 2, r);
161
connect(r, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)));
164
// set up the common desktop renderer
165
KBackgroundRenderer *r = new KBackgroundRenderer(0, false, _config);
166
m_renderer.insert(0, r);
167
connect(r, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)));
171
m_slideShowRandom = eRenderer()->multiWallpaperMode();
172
if (m_slideShowRandom == KBackgroundSettings::NoMultiRandom)
173
m_slideShowRandom = KBackgroundSettings::Random;
174
if (m_slideShowRandom == KBackgroundSettings::NoMulti)
175
m_slideShowRandom = KBackgroundSettings::InOrder;
177
// Wallpaper Position
178
m_wallpaperPos = eRenderer()->wallpaperMode();
179
if (m_wallpaperPos == KBackgroundSettings::NoWallpaper)
180
m_wallpaperPos = KBackgroundSettings::Centred; // Default
182
if (KGlobal::dirs()->isRestrictedResource("wallpaper")) {
183
m_urlWallpaperButton->hide();
184
m_buttonSetupWallpapers->hide();
185
m_radioSlideShow->hide();
191
connect(qApp->desktop(), SIGNAL(resized(int)), SLOT(desktopResized())); // RANDR support
194
BGDialog::~BGDialog()
197
qDeleteAll(m_renderer);
200
KBackgroundRenderer *BGDialog::eRenderer()
202
return m_renderer[m_eScreen];
205
void BGDialog::getEScreen()
207
if (m_pGlobals->drawBackgroundPerScreen())
208
m_eScreen = m_pGlobals->commonScreenBackground() ? 1 : m_screen + 2;
212
if (m_numScreens == 1)
214
else if (m_eScreen > int(m_numScreens + 1))
215
m_eScreen = m_numScreens + 1;
218
void BGDialog::makeReadOnly()
221
m_pMonitorArrangement->setEnabled(false);
222
m_comboScreen->setEnabled(false);
223
m_colorPrimary->setEnabled(false);
224
m_colorSecondary->setEnabled(false);
225
m_comboPattern->setEnabled(false);
226
m_radioNoPicture->setEnabled(false);
227
m_radioPicture->setEnabled(false);
228
m_radioSlideShow->setEnabled(false);
229
m_urlWallpaperBox->setEnabled(false);
230
m_urlWallpaperButton->setEnabled(false);
231
m_comboWallpaperPos->setEnabled(false);
232
m_buttonSetupWallpapers->setEnabled(false);
233
m_comboBlend->setEnabled(false);
234
m_sliderBlend->setEnabled(false);
235
m_cbBlendReverse->setEnabled(false);
236
m_buttonAdvanced->setEnabled(false);
237
m_buttonGetNew->setEnabled(false);
240
void BGDialog::load()
242
m_pGlobals->readSettings();
245
for (int screen = 0; screen < m_renderer.size(); ++screen) {
246
unsigned eScreen = screen > 1 ? screen - 2 : 0;
247
m_renderer[screen]->load(eScreen, (screen > 0), true);
250
m_copyAllScreens = true;
253
m_slideShowRandom = eRenderer()->multiWallpaperMode();
254
if (m_slideShowRandom == KBackgroundSettings::NoMultiRandom)
255
m_slideShowRandom = KBackgroundSettings::Random;
256
if (m_slideShowRandom == KBackgroundSettings::NoMulti)
257
m_slideShowRandom = KBackgroundSettings::InOrder;
259
// Wallpaper Position
260
m_wallpaperPos = eRenderer()->wallpaperMode();
261
if (m_wallpaperPos == KBackgroundSettings::NoWallpaper)
262
m_wallpaperPos = KBackgroundSettings::Centred; // Default
268
void BGDialog::save()
270
m_pGlobals->writeSettings();
272
// write out the common desktop or the "Screen 1" settings
273
// depending on which are the real settings
274
// they both share Screen[0] in the config file
276
for (int screen = 0; screen < m_renderer.size(); ++screen) {
277
if (screen == 1 && !m_pGlobals->commonScreenBackground())
280
if (screen == 2 && m_pGlobals->commonScreenBackground())
283
m_renderer[screen]->writeSettings();
289
void BGDialog::defaults()
291
m_pGlobals->setCommonScreenBackground(_defCommonScreen);
292
m_pGlobals->setLimitCache(_defLimitCache);
293
m_pGlobals->setCacheSize(_defCacheSize);
294
m_comboWallpaperPos->setCurrentIndex(0);
298
m_pGlobals->setDrawBackgroundPerScreen(false);
300
KBackgroundRenderer *r = eRenderer();
305
if (QPixmap::defaultDepth() > 8)
306
r->setBackgroundMode(_defBackgroundMode);
308
r->setBackgroundMode(KBackgroundSettings::Flat);
310
r->setColorA(_defColorA);
311
r->setColorB(_defColorB);
312
r->setWallpaperMode(_defWallpaperMode);
313
r->setMultiWallpaperMode(_defMultiMode);
315
m_slideShowRandom = _defMultiMode;
316
if (m_slideShowRandom == KBackgroundSettings::NoMultiRandom)
317
m_slideShowRandom = KBackgroundSettings::Random;
318
if (m_slideShowRandom == KBackgroundSettings::NoMulti)
319
m_slideShowRandom = KBackgroundSettings::InOrder;
321
r->setBlendMode(_defBlendMode);
322
r->setBlendBalance(_defBlendBalance);
323
r->setReverseBlending(_defReverseBlending);
327
m_copyAllScreens = true;
331
QString BGDialog::quickHelp() const
334
"<p><h1>Background</h1> This module allows you to control the"
335
" appearance of the virtual desktops. KDE offers a variety of options"
336
" for customization, including the ability to specify different settings"
337
" for each virtual desktop, or a common background for all of them.</p>"
338
" <p>The appearance of the desktop results from the combination of its"
339
" background colors and patterns, and optionally, wallpaper, which is"
340
" based on the image from a graphic file.</p>"
341
" <p>The background can be made up of a single color, or a pair of colors"
342
" which can be blended in a variety of patterns. Wallpaper is also"
343
" customizable, with options for tiling and stretching images. The"
344
" wallpaper can be overlaid opaquely, or blended in different ways with"
345
" the background colors and patterns.</p>"
346
" <p>KDE allows you to have the wallpaper change automatically at specified"
347
" intervals of time. You can also replace the background with a program"
348
" that updates the desktop dynamically. For example, the \"kdeworld\""
349
" program shows a day/night map of the world which is updated periodically.</p>");
352
void BGDialog::slotIdentifyScreens()
354
// Taken from PositionTab::showIdentify in kdebase/kcontrol/kicker/positiontab_impl.cpp
355
for (unsigned s = 0; s < m_numScreens; s++) {
356
QLabel *screenLabel = new QLabel(0, Qt::X11BypassWindowManagerHint);
357
screenLabel->setObjectName("Screen Identify");
359
QFont identifyFont(KGlobalSettings::generalFont());
360
identifyFont.setPixelSize(100);
361
screenLabel->setFont(identifyFont);
363
screenLabel->setFrameStyle(QFrame::Panel);
364
screenLabel->setFrameShadow(QFrame::Plain);
366
screenLabel->setAlignment(Qt::AlignCenter);
367
screenLabel->setNum(int(s + 1));
368
// BUGLET: we should not allow the identification to be entered again
369
// until the timer fires.
370
QTimer::singleShot(1500, screenLabel, SLOT(deleteLater()));
372
QPoint screenCenter(QApplication::desktop()->screenGeometry(s).center());
373
QRect targetGeometry(QPoint(0, 0), screenLabel->sizeHint());
374
targetGeometry.moveCenter(screenCenter);
376
screenLabel->setGeometry(targetGeometry);
382
void BGDialog::initUI()
385
for (unsigned i = 0; i < m_numScreens; ++i)
386
m_comboScreen->addItem(i18n("Screen %1", i + 1));
389
m_comboPattern->addItem(i18n("Single Color"));
390
m_comboPattern->addItem(i18n("Horizontal Gradient"));
391
m_comboPattern->addItem(i18n("Vertical Gradient"));
392
m_comboPattern->addItem(i18n("Pyramid Gradient"));
393
m_comboPattern->addItem(i18n("Pipecross Gradient"));
394
m_comboPattern->addItem(i18n("Elliptic Gradient"));
396
m_patterns = KBackgroundPattern::list();
397
m_patterns.sort(); // Defined order
398
QStringList::const_iterator it;
399
for (it = m_patterns.constBegin(); it != m_patterns.constEnd(); ++it) {
400
KBackgroundPattern pat(*it);
401
if (pat.isAvailable())
402
m_comboPattern->addItem(pat.comment());
405
loadWallpaperFilesList();
407
// Wallpaper tilings: again they must match the ones from bgrender.cc
408
m_comboWallpaperPos->addItem(i18n("Centered"));
409
m_comboWallpaperPos->addItem(i18n("Tiled"));
410
m_comboWallpaperPos->addItem(i18n("Center Tiled"));
411
m_comboWallpaperPos->addItem(i18n("Centered Maxpect"));
412
m_comboWallpaperPos->addItem(i18n("Tiled Maxpect"));
413
m_comboWallpaperPos->addItem(i18n("Scaled"));
414
m_comboWallpaperPos->addItem(i18n("Centered Auto Fit"));
415
m_comboWallpaperPos->addItem(i18n("Scale & Crop"));
417
// Blend modes: make sure these match with kdesktop/bgrender.cc !!
418
m_comboBlend->addItem(i18n("No Blending"));
419
m_comboBlend->addItem(i18n("Flat"));
420
m_comboBlend->addItem(i18n("Horizontal"));
421
m_comboBlend->addItem(i18n("Vertical"));
422
m_comboBlend->addItem(i18n("Pyramid"));
423
m_comboBlend->addItem(i18n("Pipecross"));
424
m_comboBlend->addItem(i18n("Elliptic"));
425
m_comboBlend->addItem(i18n("Intensity"));
426
m_comboBlend->addItem(i18n("Saturation"));
427
m_comboBlend->addItem(i18n("Contrast"));
428
m_comboBlend->addItem(i18n("Hue Shift"));
431
void BGDialog::loadWallpaperFilesList()
435
// the following QMap is lower cased names mapped to cased names and URLs
436
// this way we get case insensitive sorting
437
QMap<QString, QPair<QString, QString> > papers;
439
//search for .desktop files before searching for images without .desktop files
440
QStringList lst = m_pDirs->findAllResources("wallpaper", "*desktop", KStandardDirs::NoDuplicates);
442
for (QStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it) {
443
KDesktopFile fileConfig(*it);
444
KConfigGroup cg = fileConfig.group("Wallpaper");
446
QString imageCaption = cg.readEntry("Name");
447
QString fileName = cg.readEntry("File");
449
if (imageCaption.isEmpty()) {
450
imageCaption = fileName;
451
imageCaption.replace('_', ' ');
452
imageCaption = KStringHandler::capwords(imageCaption);
455
// avoid name collisions
456
QString rs = imageCaption;
457
QString lrs = rs.toLower();
458
for (int n = 1; papers.find(lrs) != papers.end(); ++n) {
459
rs = imageCaption + " (" + QString::number(n) + ')';
462
int slash = (*it).lastIndexOf('/') + 1;
463
QString directory = (*it).left(slash);
464
if (cg.readEntry("ImageType") == QLatin1String("pixmap")) {
465
papers[lrs] = qMakePair(rs, QString(directory + fileName));
466
files.append(directory + fileName);
470
//now find any wallpapers that don't have a .desktop file
471
lst = m_pDirs->findAllResources("wallpaper", "*", KStandardDirs::NoDuplicates);
472
for (QStringList::ConstIterator it = lst.constBegin(); it != lst.constEnd(); ++it) {
473
if (!(*it).endsWith(".desktop") && files.filter(*it).empty()) {
474
// First try to see if we have a comment describing the image. If we do
475
// just use the first line of said comment.
476
KFileMetaInfo metaInfo(*it);
477
QString imageCaption;
479
if (metaInfo.isValid() && metaInfo.item("Comment").isValid())
480
imageCaption = metaInfo.item("Comment").value().toString().section('\n', 0, 0);
482
if (imageCaption.isEmpty()) {
483
int slash = (*it).lastIndexOf('/') + 1;
484
int endDot = (*it).lastIndexOf('.');
486
// strip the extension if it exists
487
if (endDot != -1 && endDot > slash)
488
imageCaption = (*it).mid(slash, endDot - slash);
490
imageCaption = (*it).mid(slash);
492
imageCaption.replace('_', ' ');
493
imageCaption = KStringHandler::capwords(imageCaption);
496
// avoid name collisions
497
QString rs = imageCaption;
498
QString lrs = rs.toLower();
499
for (int n = 1; papers.find(lrs) != papers.end(); ++n) {
500
rs = imageCaption + " (" + QString::number(n) + ')';
503
papers[lrs] = qMakePair(rs, *it);
507
KComboBox *comboWallpaper = m_urlWallpaperBox;
508
comboWallpaper->clear();
511
for (QMap<QString, QPair<QString, QString> >::Iterator it = papers.begin();
514
comboWallpaper->addItem(it.value().first);
515
m_wallpaper[it.value().second] = i;
520
void BGDialog::setWallpaper(const QString &s)
522
KComboBox *comboWallpaper = m_urlWallpaperBox;
523
int i = comboWallpaper->count();
526
comboWallpaper->blockSignals(true);
528
if (m_wallpaper.find(s) == m_wallpaper.end()) {
529
QString imageCaption;
530
int slash = s.lastIndexOf('/') + 1;
531
int endDot = s.lastIndexOf('.');
533
// strip the extension if it exists
534
if (endDot != -1 && endDot > slash)
535
imageCaption = s.mid(slash, endDot - slash);
537
imageCaption = s.mid(slash);
538
if (comboWallpaper->itemText(i - 1) == imageCaption) {
540
comboWallpaper->removeItem(i);
542
comboWallpaper->addItem(imageCaption);
544
comboWallpaper->setCurrentIndex(i);
546
comboWallpaper->setCurrentIndex(m_wallpaper[s]);
548
comboWallpaper->blockSignals(false);
551
void BGDialog::slotWallpaperSelection()
554
KFileDialog dlg(u, QString(), this);
556
KImageFilePreview *previewWidget = new KImageFilePreview(&dlg);
557
dlg.setPreviewWidget(previewWidget);
559
QStringList mimeTypes = KImageIO::mimeTypes(KImageIO::Reading);
560
mimeTypes += "image/svg+xml";
561
dlg.setFilter(mimeTypes.join(" "));
562
dlg.setMode(KFile::File | KFile::ExistingOnly | KFile::LocalOnly);
563
dlg.setCaption(i18n("Select Wallpaper"));
565
int j = m_urlWallpaperBox->currentIndex();
567
for (QMap<QString, int>::ConstIterator it = m_wallpaper.constBegin();
568
it != m_wallpaper.constEnd();
570
if (it.value() == j) {
576
if (!uri.isEmpty()) {
577
dlg.setSelection(uri);
580
if (dlg.exec() == QDialog::Accepted) {
581
setWallpaper(dlg.selectedFile());
583
int optionID = m_buttonGroupBackground->id(m_radioPicture);
584
m_buttonGroupBackground->setSelected(optionID);
585
slotWallpaperTypeChanged(optionID);
591
void BGDialog::updateUI()
593
KBackgroundRenderer *r = eRenderer();
594
m_comboScreen->setCurrentIndex(m_eScreen);
596
m_colorPrimary->setColor(r->colorA());
597
m_colorSecondary->setColor(r->colorB());
599
int wallpaperMode = r->wallpaperMode();
600
int multiMode = r->multiWallpaperMode();
602
if (r->backgroundMode() == KBackgroundSettings::Program &&
603
wallpaperMode == KBackgroundSettings::NoWallpaper)
604
groupBox3->setEnabled(false);
606
groupBox3->setEnabled(true);
608
if ((multiMode == KBackgroundSettings::NoMultiRandom) ||
609
(multiMode == KBackgroundSettings::NoMulti)) {
611
if (wallpaperMode == KBackgroundSettings::NoWallpaper) {
613
m_urlWallpaperBox->setEnabled(false);
614
m_urlWallpaperButton->setEnabled(false);
615
m_buttonSetupWallpapers->setEnabled(false);
616
m_comboWallpaperPos->setEnabled(false);
617
m_lblWallpaperPos->setEnabled(false);
619
m_buttonGroupBackground->setSelected(
620
m_buttonGroupBackground->id(m_radioNoPicture));
626
m_urlWallpaperBox->setEnabled(true);
627
m_urlWallpaperButton->setEnabled(true);
628
m_buttonSetupWallpapers->setEnabled(false);
629
m_comboWallpaperPos->setEnabled(true);
630
m_lblWallpaperPos->setEnabled(true);
632
setWallpaper(r->wallpaper());
633
m_buttonGroupBackground->setSelected(
634
m_buttonGroupBackground->id(m_radioPicture));
641
m_urlWallpaperBox->setEnabled(false);
642
m_urlWallpaperButton->setEnabled(false);
643
m_buttonSetupWallpapers->setEnabled(true);
644
m_comboWallpaperPos->setEnabled(true);
645
m_lblWallpaperPos->setEnabled(true);
647
m_buttonGroupBackground->setSelected(
648
m_buttonGroupBackground->id(m_radioSlideShow));
651
m_comboWallpaperPos->setCurrentIndex(r->wallpaperMode() - 1);
653
bool bSecondaryEnabled = true;
654
m_comboPattern->blockSignals(true);
655
switch (r->backgroundMode()) {
656
case KBackgroundSettings::Flat:
657
m_comboPattern->setCurrentIndex(0);
658
bSecondaryEnabled = false;
661
case KBackgroundSettings::Pattern: {
662
int i = m_patterns.indexOf(r->KBackgroundPattern::name());
664
m_comboPattern->setCurrentIndex(NR_PREDEF_PATTERNS + i);
666
m_comboPattern->setCurrentIndex(0);
670
case KBackgroundSettings::Program:
671
m_comboPattern->setCurrentIndex(0);
672
bSecondaryEnabled = false;
676
m_comboPattern->setCurrentIndex(
677
1 + r->backgroundMode() - KBackgroundSettings::HorizontalGradient);
680
m_comboPattern->blockSignals(false);
682
m_colorSecondary->setEnabled(bSecondaryEnabled && !m_readOnly);
684
int mode = r->blendMode();
686
m_comboBlend->blockSignals(true);
687
m_sliderBlend->blockSignals(true);
689
m_comboBlend->setCurrentIndex(mode);
690
m_cbBlendReverse->setChecked(r->reverseBlending());
691
m_sliderBlend->setValue(r->blendBalance() / 10);
693
m_comboBlend->blockSignals(false);
694
m_sliderBlend->blockSignals(false);
696
// turn it off if there is no background picture set!
697
setBlendingEnabled(wallpaperMode != KBackgroundSettings::NoWallpaper);
699
// Start preview renderer(s)
700
if (m_eScreen == 0) {
701
r->setPreview(m_pMonitorArrangement->combinedPreviewSize());
703
} else if (m_eScreen == 1) {
704
r->setPreview(m_pMonitorArrangement->maxPreviewSize());
707
for (unsigned j = 0; j < m_numScreens; ++j) {
708
m_renderer[j+2]->stop();
709
m_renderer[j+2]->setPreview(m_pMonitorArrangement->monitor(j)->previewRect().size());
710
m_renderer[j+2]->start(true);
715
void BGDialog::slotPreviewDone(int screen_done)
717
if (!m_previewUpdates)
720
KBackgroundRenderer *r = m_renderer[(m_eScreen>1) ? (screen_done+2) : m_eScreen];
722
if (r->image().isNull())
727
QPixmap pm = QPixmap::fromImage(r->image());
729
if (m_eScreen == 0) {
730
m_pMonitorArrangement->setPixmap(pm);
731
} else if (m_eScreen == 1) {
732
for (unsigned i = 0; i < m_pMonitorArrangement->numMonitors(); ++i)
733
m_pMonitorArrangement->monitor(i)->setPreview(pm);
735
m_pMonitorArrangement->monitor(screen_done)->setPreview(pm);
739
void BGDialog::slotImageDropped(const QString &uri)
743
int optionID = m_buttonGroupBackground->id(m_radioPicture);
744
m_buttonGroupBackground->setSelected(optionID);
745
slotWallpaperTypeChanged(optionID);
748
void BGDialog::slotWallpaperTypeChanged(int i)
750
KBackgroundRenderer *r = eRenderer();
754
if (i == m_buttonGroupBackground->id(m_radioNoPicture)) { //None
755
m_urlWallpaperBox->setEnabled(false);
756
m_urlWallpaperButton->setEnabled(false);
757
m_buttonSetupWallpapers->setEnabled(false);
758
m_comboWallpaperPos->setEnabled(false);
759
m_lblWallpaperPos->setEnabled(false);
760
r->setWallpaperMode(KBackgroundSettings::NoWallpaper);
762
if (m_slideShowRandom == KBackgroundSettings::InOrder)
763
r->setMultiWallpaperMode(KBackgroundSettings::NoMulti);
765
r->setMultiWallpaperMode(KBackgroundSettings::NoMultiRandom);
767
setBlendingEnabled(false);
771
else if (i == m_buttonGroupBackground->id(m_radioSlideShow)) {
772
m_urlWallpaperBox->setEnabled(false);
773
m_urlWallpaperButton->setEnabled(false);
774
m_buttonSetupWallpapers->setEnabled(true);
775
m_comboWallpaperPos->setEnabled(true);
776
m_lblWallpaperPos->setEnabled(true);
777
setBlendingEnabled(true);
779
m_comboWallpaperPos->blockSignals(true);
780
m_comboWallpaperPos->setCurrentIndex(m_wallpaperPos - 1);
781
m_comboWallpaperPos->blockSignals(false);
783
if (r->wallpaperList().count() == 0)
784
r->setWallpaperMode(KBackgroundSettings::NoWallpaper);
786
r->setWallpaperMode(m_wallpaperPos);
788
r->setMultiWallpaperMode(m_slideShowRandom);
789
setWallpaper(r->wallpaper());
790
setBlendingEnabled(true);
794
else if (i == m_buttonGroupBackground->id(m_radioPicture)) {
795
m_urlWallpaperBox->setEnabled(true);
796
m_urlWallpaperButton->setEnabled(true);
797
m_buttonSetupWallpapers->setEnabled(false);
798
m_lblWallpaperPos->setEnabled(true);
799
m_comboWallpaperPos->setEnabled(true);
800
setBlendingEnabled(true);
802
if (m_slideShowRandom == KBackgroundSettings::InOrder)
803
r->setMultiWallpaperMode(KBackgroundSettings::NoMulti);
805
r->setMultiWallpaperMode(KBackgroundSettings::NoMultiRandom);
807
int j = m_urlWallpaperBox->currentIndex();
809
for (QMap<QString, int>::ConstIterator it = m_wallpaper.constBegin();
810
it != m_wallpaper.constEnd();
812
if (it.value() == j) {
818
KFileMetaInfo metaInfo(path);
819
if (metaInfo.isValid() && metaInfo.item("Dimensions").isValid()) {
820
// If the image is greater than 800x600 default to using scaled mode,
821
// otherwise default to tiled.
823
QSize s = metaInfo.item("Dimensions").value().toSize();
824
if (s.width() >= 800 && s.height() >= 600)
825
m_wallpaperPos = KBackgroundSettings::Scaled;
827
m_wallpaperPos = KBackgroundSettings::Tiled;
828
} else if (KMimeType::findByPath(path)->is("image/svg+xml")) {
829
m_wallpaperPos = KBackgroundSettings::Scaled;
832
r->setWallpaperMode(m_wallpaperPos);
833
m_comboWallpaperPos->blockSignals(true);
834
m_comboWallpaperPos->setCurrentIndex(m_wallpaperPos - 1);
835
m_comboWallpaperPos->blockSignals(false);
837
r->setWallpaper(path);
841
m_copyAllScreens = true;
845
void BGDialog::slotWallpaper(int)
847
slotWallpaperTypeChanged(m_buttonGroupBackground->id(m_radioPicture));
851
void BGDialog::setBlendingEnabled(bool enable)
855
int mode = eRenderer()->blendMode();
857
bool b = !(mode == KBackgroundSettings::NoBlending);
858
m_lblBlending->setEnabled(enable);
859
m_comboBlend->setEnabled(enable);
860
m_lblBlendBalance->setEnabled(enable && b);
861
m_sliderBlend->setEnabled(enable && b);
863
b = !(mode < KBackgroundSettings::IntensityBlending);
864
m_cbBlendReverse->setEnabled(enable && b);
867
void BGDialog::slotWallpaperPos(int mode)
869
KBackgroundRenderer *r = eRenderer();
872
m_wallpaperPos = mode;
874
if (mode == r->wallpaperMode())
878
r->setWallpaperMode(mode);
880
m_copyAllScreens = true;
884
void BGDialog::slotSetupMulti()
886
KBackgroundRenderer *r = eRenderer();
888
BGMultiWallpaperDialog dlg(r, window());
889
if (dlg.exec() == QDialog::Accepted) {
891
m_slideShowRandom = r->multiWallpaperMode();
892
r->setWallpaperMode(m_wallpaperPos);
894
m_copyAllScreens = true;
899
void BGDialog::slotPrimaryColor(const QColor &color)
901
KBackgroundRenderer *r = eRenderer();
903
if (color == r->colorA())
909
m_copyAllScreens = true;
913
void BGDialog::slotSecondaryColor(const QColor &color)
915
KBackgroundRenderer *r = eRenderer();
917
if (color == r->colorB())
923
m_copyAllScreens = true;
927
void BGDialog::slotPattern(int pattern)
929
KBackgroundRenderer *r = eRenderer();
931
bool bSecondaryEnabled = true;
932
if (pattern < NR_PREDEF_PATTERNS) {
934
r->setBackgroundMode(KBackgroundSettings::Flat);
935
bSecondaryEnabled = false;
937
r->setBackgroundMode(pattern - 1 + KBackgroundSettings::HorizontalGradient);
940
r->setBackgroundMode(KBackgroundSettings::Pattern);
941
r->setPatternName(m_patterns[pattern - NR_PREDEF_PATTERNS]);
944
m_colorSecondary->setEnabled(bSecondaryEnabled);
946
m_copyAllScreens = true;
950
void BGDialog::slotSelectScreen(int screen)
952
// Copy the settings from "All screens" to all the other screens
953
// at a suitable point
954
if (m_pGlobals->commonScreenBackground() && (screen > 1) && m_copyAllScreens) {
956
KBackgroundRenderer *master = m_renderer[1];
957
for (unsigned screen = 0; screen < m_numScreens; ++screen) {
958
m_renderer[screen+2]->copyConfig(master);
962
if (screen == m_eScreen) {
963
return; // Nothing to do
966
m_copyAllScreens = false;
968
bool drawBackgroundPerScreen = screen > 0;
969
bool commonScreenBackground = screen < 2;
971
m_pGlobals->setDrawBackgroundPerScreen(drawBackgroundPerScreen);
973
m_pGlobals->setCommonScreenBackground(commonScreenBackground);
978
for (int i = 0; i < m_renderer.size(); ++i) {
979
if (m_renderer[i]->isActive())
980
m_renderer[i]->stop();
988
void BGDialog::slotAdvanced()
990
KBackgroundRenderer *r = eRenderer();
992
m_previewUpdates = false;
993
BGAdvancedDialog dlg(r, window());
995
if (!m_pMonitorArrangement->isEnabled()) {
1002
if (m_pGlobals->limitCache())
1003
dlg.setCacheSize(m_pGlobals->cacheSize());
1005
dlg.setCacheSize(0);
1009
m_previewUpdates = true;
1014
int cacheSize = dlg.cacheSize();
1016
m_pGlobals->setCacheSize(cacheSize);
1017
m_pGlobals->setLimitCache(true);
1019
m_pGlobals->setLimitCache(false);
1024
m_previewUpdates = true;
1031
void BGDialog::slotGetNewStuff()
1033
// We use the more complicated KNewStuff2 API here because these settings
1034
// might affect both kcmshell and kcontrol
1036
KNS3::DownloadDialog dialog("background.knsrc", this);
1038
//FIXME (KNS2): monday change
1039
//engine->setTitle(i18n("Get New Wallpapers"));
1041
// FIXME (KNS2): engine->download gives us meta infos, write those into
1042
// the .desktop files
1043
loadWallpaperFilesList();
1046
void BGDialog::slotBlendMode(int mode)
1048
if (mode == eRenderer()->blendMode())
1051
bool b = !(mode == KBackgroundSettings::NoBlending);
1052
m_sliderBlend->setEnabled(b);
1053
m_lblBlendBalance->setEnabled(b);
1055
b = !(mode < KBackgroundSettings::IntensityBlending);
1056
m_cbBlendReverse->setEnabled(b);
1059
eRenderer()->stop();
1060
eRenderer()->setBlendMode(mode);
1061
eRenderer()->start(true);
1064
void BGDialog::slotBlendBalance(int value)
1067
if (value == eRenderer()->blendBalance())
1071
eRenderer()->stop();
1072
eRenderer()->setBlendBalance(value);
1073
eRenderer()->start(true);
1076
void BGDialog::slotBlendReverse(bool b)
1078
if (b == eRenderer()->reverseBlending())
1082
eRenderer()->stop();
1083
eRenderer()->setReverseBlending(b);
1084
eRenderer()->start(true);
1087
void BGDialog::desktopResized()
1089
for (int j = 0; j < m_renderer.size(); ++j) {
1090
KBackgroundRenderer *r = m_renderer[j];
1093
r->desktopResized();
1095
eRenderer()->start(true);
1098
#include "bgdialog.moc"