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.
33 #include <QRadioButton>
38 #include <QApplication>
40 #include <QDesktopWidget>
44 #include <kfiledialog.h>
45 #include <kfilemetainfo.h>
47 #include <kiconloader.h>
50 #include <kstandarddirs.h>
51 #include <kstringhandler.h>
52 #include <kurlrequester.h>
53 #include <kwindowsystem.h>
54 #include <kdesktopfile.h>
55 #include <kimagefilepreview.h>
56 #include <knewstuff2/engine.h>
60 #include "bgmonitor.h"
61 #include "bgwallpaper.h"
62 #include "bgadvanced.h"
65 #define NR_PREDEF_PATTERNS 6
67 BGDialog::BGDialog(QWidget
* parent
, const KSharedConfigPtr
&_config
)
68 : BGDialog_UI(parent
), m_readOnly( false )
70 m_pGlobals
= new KGlobalBackgroundSettings(_config
);
71 m_pDirs
= KGlobal::dirs();
72 m_previewUpdates
= true;
74 m_numScreens
= QApplication::desktop()->numScreens();
76 QString multiHead
= getenv("KDE_MULTIHEAD");
77 if (multiHead
.toLower() == "true")
82 m_screen
= QApplication::desktop()->screenNumber(this);
83 if (m_screen
>= (int)m_numScreens
)
84 m_screen
= m_numScreens
-1;
87 m_copyAllScreens
= true;
91 m_comboScreen
->hide();
92 m_buttonIdentifyScreens
->hide();
97 connect(m_buttonIdentifyScreens
, SIGNAL(clicked()), SLOT(slotIdentifyScreens()));
100 m_pMonitorArrangement
= new BGMonitorArrangement(m_screenArrangement
);
101 m_pMonitorArrangement
->setObjectName("monitor arrangement");
102 connect(m_pMonitorArrangement
, SIGNAL(imageDropped(const QString
&)), SLOT(slotImageDropped(const QString
&)));
103 if (m_numScreens
> 1)
105 connect(m_comboScreen
, SIGNAL(activated(int)),
106 SLOT(slotSelectScreen(int)));
109 // background image settings
110 QIcon iconSet
= KIcon(QLatin1String("document-open"));
111 QPixmap pixMap
= iconSet
.pixmap(
112 style()->pixelMetric( QStyle::PM_SmallIconSize
), QIcon::Normal
);
113 m_urlWallpaperButton
->setIcon( iconSet
);
114 m_urlWallpaperButton
->setFixedSize( pixMap
.width()+8, pixMap
.height()+8 );
115 m_urlWallpaperButton
->setToolTip( i18n("Open file dialog"));
117 connect(m_buttonGroupBackground
, SIGNAL(clicked(int)),
118 SLOT(slotWallpaperTypeChanged(int)));
119 connect(m_urlWallpaperBox
, SIGNAL(activated(int)),
120 SLOT(slotWallpaper(int)));
121 connect(m_urlWallpaperButton
, SIGNAL(clicked()),
122 SLOT(slotWallpaperSelection()));
123 connect(m_comboWallpaperPos
, SIGNAL(activated(int)),
124 SLOT(slotWallpaperPos(int)));
125 connect(m_buttonSetupWallpapers
, SIGNAL(clicked()),
126 SLOT(slotSetupMulti()));
128 // set up the background colour stuff
129 connect(m_colorPrimary
, SIGNAL(changed(const QColor
&)),
130 SLOT(slotPrimaryColor(const QColor
&)));
131 connect(m_colorSecondary
, SIGNAL(changed(const QColor
&)),
132 SLOT(slotSecondaryColor(const QColor
&)));
133 connect(m_comboPattern
, SIGNAL(activated(int)),
134 SLOT(slotPattern(int)));
137 connect(m_comboBlend
, SIGNAL(activated(int)), SLOT(slotBlendMode(int)));
138 connect(m_sliderBlend
, SIGNAL(valueChanged(int)),
139 SLOT(slotBlendBalance(int)));
140 connect(m_cbBlendReverse
, SIGNAL(toggled(bool)),
141 SLOT(slotBlendReverse(bool)));
144 connect(m_buttonAdvanced
, SIGNAL(clicked()),
145 SLOT(slotAdvanced()));
147 connect(m_buttonGetNew
, SIGNAL(clicked()),
148 SLOT(slotGetNewStuff()));
151 if (m_numScreens
> 1)
153 m_renderer
.resize(m_numScreens
+2);
154 m_renderer
.setAutoDelete(true);
156 // Setup the merged-screen renderer
157 KBackgroundRenderer
* r
= new KBackgroundRenderer(0, false, _config
);
158 m_renderer
.insert( 0, r
);
159 connect( r
, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)) );
161 // Setup the common-screen renderer
162 r
= new KBackgroundRenderer(0, true, _config
);
163 m_renderer
.insert( 1, r
);
164 connect( r
, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)) );
166 // Setup the remaining renderers for each screen
167 for (unsigned j
=0; j
< m_numScreens
; ++j
)
169 r
= new KBackgroundRenderer(j
, true, _config
);
170 m_renderer
.insert( j
+2, r
);
171 connect( r
, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)) );
176 m_renderer
.resize(1);
177 m_renderer
.setAutoDelete(true);
179 // set up the common desktop renderer
180 KBackgroundRenderer
* r
= new KBackgroundRenderer(0, false, _config
);
181 m_renderer
.insert(0, r
);
182 connect(r
, SIGNAL(imageDone(int)), SLOT(slotPreviewDone(int)));
186 m_slideShowRandom
= eRenderer()->multiWallpaperMode();
187 if (m_slideShowRandom
== KBackgroundSettings::NoMultiRandom
)
188 m_slideShowRandom
= KBackgroundSettings::Random
;
189 if (m_slideShowRandom
== KBackgroundSettings::NoMulti
)
190 m_slideShowRandom
= KBackgroundSettings::InOrder
;
192 // Wallpaper Position
193 m_wallpaperPos
= eRenderer()->wallpaperMode();
194 if (m_wallpaperPos
== KBackgroundSettings::NoWallpaper
)
195 m_wallpaperPos
= KBackgroundSettings::Centred
; // Default
197 if (KGlobal::dirs()->isRestrictedResource("wallpaper"))
199 m_urlWallpaperButton
->hide();
200 m_buttonSetupWallpapers
->hide();
201 m_radioSlideShow
->hide();
207 connect( qApp
->desktop(), SIGNAL( resized( int )), SLOT( desktopResized())); // RANDR support
210 BGDialog::~BGDialog()
215 KBackgroundRenderer
* BGDialog::eRenderer()
217 return m_renderer
[m_eScreen
];
220 void BGDialog::getEScreen()
222 if ( m_pGlobals
->drawBackgroundPerScreen() )
223 m_eScreen
= m_pGlobals
->commonScreenBackground() ? 1 : m_screen
+2;
227 if ( m_numScreens
== 1 )
229 else if ( m_eScreen
> int(m_numScreens
+1) )
230 m_eScreen
= m_numScreens
+1;
233 void BGDialog::makeReadOnly()
236 m_pMonitorArrangement
->setEnabled( false );
237 m_comboScreen
->setEnabled( false );
238 m_colorPrimary
->setEnabled( false );
239 m_colorSecondary
->setEnabled( false );
240 m_comboPattern
->setEnabled( false );
241 m_radioNoPicture
->setEnabled( false );
242 m_radioPicture
->setEnabled( false );
243 m_radioSlideShow
->setEnabled( false );
244 m_urlWallpaperBox
->setEnabled( false );
245 m_urlWallpaperButton
->setEnabled( false );
246 m_comboWallpaperPos
->setEnabled( false );
247 m_buttonSetupWallpapers
->setEnabled( false );
248 m_comboBlend
->setEnabled( false );
249 m_sliderBlend
->setEnabled( false );
250 m_cbBlendReverse
->setEnabled( false );
251 m_buttonAdvanced
->setEnabled( false );
252 m_buttonGetNew
->setEnabled( false );
255 void BGDialog::load()
257 m_pGlobals
->readSettings();
260 for (unsigned screen
= 0; screen
< m_renderer
.size(); ++screen
)
262 unsigned eScreen
= screen
>1 ? screen
-2 : 0;
263 m_renderer
[screen
]->load( eScreen
, (screen
>0), true );
266 m_copyAllScreens
= true;
269 m_slideShowRandom
= eRenderer()->multiWallpaperMode();
270 if (m_slideShowRandom
== KBackgroundSettings::NoMultiRandom
)
271 m_slideShowRandom
= KBackgroundSettings::Random
;
272 if (m_slideShowRandom
== KBackgroundSettings::NoMulti
)
273 m_slideShowRandom
= KBackgroundSettings::InOrder
;
275 // Wallpaper Position
276 m_wallpaperPos
= eRenderer()->wallpaperMode();
277 if (m_wallpaperPos
== KBackgroundSettings::NoWallpaper
)
278 m_wallpaperPos
= KBackgroundSettings::Centred
; // Default
284 void BGDialog::save()
286 m_pGlobals
->writeSettings();
288 // write out the common desktop or the "Screen 1" settings
289 // depending on which are the real settings
290 // they both share Screen[0] in the config file
292 for (unsigned screen
= 0; screen
< m_renderer
.size(); ++screen
)
294 if (screen
== 1 && !m_pGlobals
->commonScreenBackground())
297 if (screen
== 2 && m_pGlobals
->commonScreenBackground())
300 m_renderer
[screen
]->writeSettings();
306 void BGDialog::defaults()
308 m_pGlobals
->setCommonScreenBackground(_defCommonScreen
);
309 m_pGlobals
->setLimitCache(_defLimitCache
);
310 m_pGlobals
->setCacheSize(_defCacheSize
);
311 m_comboWallpaperPos
->setCurrentIndex( 0 );
315 m_pGlobals
->setDrawBackgroundPerScreen( false );
317 KBackgroundRenderer
*r
= eRenderer();
322 if (QPixmap::defaultDepth() > 8)
324 r
->setBackgroundMode(_defBackgroundMode
);
328 r
->setBackgroundMode(KBackgroundSettings::Flat
);
331 r
->setColorA(_defColorA
);
332 r
->setColorB(_defColorB
);
333 r
->setWallpaperMode(_defWallpaperMode
);
334 r
->setMultiWallpaperMode(_defMultiMode
);
336 m_slideShowRandom
= _defMultiMode
;
337 if (m_slideShowRandom
== KBackgroundSettings::NoMultiRandom
)
338 m_slideShowRandom
= KBackgroundSettings::Random
;
339 if (m_slideShowRandom
== KBackgroundSettings::NoMulti
)
340 m_slideShowRandom
= KBackgroundSettings::InOrder
;
342 r
->setBlendMode(_defBlendMode
);
343 r
->setBlendBalance(_defBlendBalance
);
344 r
->setReverseBlending(_defReverseBlending
);
348 m_copyAllScreens
= true;
352 QString
BGDialog::quickHelp() const
354 return i18n("<p><h1>Background</h1> This module allows you to control the"
355 " appearance of the virtual desktops. KDE offers a variety of options"
356 " for customization, including the ability to specify different settings"
357 " for each virtual desktop, or a common background for all of them.</p>"
358 " <p>The appearance of the desktop results from the combination of its"
359 " background colors and patterns, and optionally, wallpaper, which is"
360 " based on the image from a graphic file.</p>"
361 " <p>The background can be made up of a single color, or a pair of colors"
362 " which can be blended in a variety of patterns. Wallpaper is also"
363 " customizable, with options for tiling and stretching images. The"
364 " wallpaper can be overlaid opaquely, or blended in different ways with"
365 " the background colors and patterns.</p>"
366 " <p>KDE allows you to have the wallpaper change automatically at specified"
367 " intervals of time. You can also replace the background with a program"
368 " that updates the desktop dynamically. For example, the \"kdeworld\""
369 " program shows a day/night map of the world which is updated periodically.</p>");
372 void BGDialog::slotIdentifyScreens()
374 // Taken from PositionTab::showIdentify in kdebase/kcontrol/kicker/positiontab_impl.cpp
375 for(unsigned s
= 0; s
< m_numScreens
; s
++)
377 QLabel
*screenLabel
= new QLabel(0, Qt::X11BypassWindowManagerHint
);
378 screenLabel
->setObjectName("Screen Identify");
380 QFont
identifyFont(KGlobalSettings::generalFont());
381 identifyFont
.setPixelSize(100);
382 screenLabel
->setFont(identifyFont
);
384 screenLabel
->setFrameStyle(QFrame::Panel
);
385 screenLabel
->setFrameShadow(QFrame::Plain
);
387 screenLabel
->setAlignment(Qt::AlignCenter
);
388 screenLabel
->setNum(int(s
+ 1));
389 // BUGLET: we should not allow the identification to be entered again
390 // until the timer fires.
391 QTimer::singleShot(1500, screenLabel
, SLOT(deleteLater()));
393 QPoint
screenCenter(QApplication::desktop()->screenGeometry(s
).center());
394 QRect
targetGeometry(QPoint(0,0),screenLabel
->sizeHint());
395 targetGeometry
.moveCenter(screenCenter
);
397 screenLabel
->setGeometry(targetGeometry
);
403 void BGDialog::initUI()
406 for (unsigned i
= 0; i
< m_numScreens
; ++i
)
407 m_comboScreen
->addItem( i18n("Screen %1", i
+1) );
410 m_comboPattern
->addItem(i18n("Single Color"));
411 m_comboPattern
->addItem(i18n("Horizontal Gradient"));
412 m_comboPattern
->addItem(i18n("Vertical Gradient"));
413 m_comboPattern
->addItem(i18n("Pyramid Gradient"));
414 m_comboPattern
->addItem(i18n("Pipecross Gradient"));
415 m_comboPattern
->addItem(i18n("Elliptic Gradient"));
417 m_patterns
= KBackgroundPattern::list();
418 m_patterns
.sort(); // Defined order
419 QStringList::const_iterator it
;
420 for (it
=m_patterns
.constBegin(); it
!= m_patterns
.constEnd(); ++it
)
422 KBackgroundPattern
pat(*it
);
423 if (pat
.isAvailable())
424 m_comboPattern
->addItem(pat
.comment());
427 loadWallpaperFilesList();
429 // Wallpaper tilings: again they must match the ones from bgrender.cc
430 m_comboWallpaperPos
->addItem(i18n("Centered"));
431 m_comboWallpaperPos
->addItem(i18n("Tiled"));
432 m_comboWallpaperPos
->addItem(i18n("Center Tiled"));
433 m_comboWallpaperPos
->addItem(i18n("Centered Maxpect"));
434 m_comboWallpaperPos
->addItem(i18n("Tiled Maxpect"));
435 m_comboWallpaperPos
->addItem(i18n("Scaled"));
436 m_comboWallpaperPos
->addItem(i18n("Centered Auto Fit"));
437 m_comboWallpaperPos
->addItem(i18n("Scale & Crop"));
439 // Blend modes: make sure these match with kdesktop/bgrender.cc !!
440 m_comboBlend
->addItem(i18n("No Blending"));
441 m_comboBlend
->addItem(i18n("Flat"));
442 m_comboBlend
->addItem(i18n("Horizontal"));
443 m_comboBlend
->addItem(i18n("Vertical"));
444 m_comboBlend
->addItem(i18n("Pyramid"));
445 m_comboBlend
->addItem(i18n("Pipecross"));
446 m_comboBlend
->addItem(i18n("Elliptic"));
447 m_comboBlend
->addItem(i18n("Intensity"));
448 m_comboBlend
->addItem(i18n("Saturation"));
449 m_comboBlend
->addItem(i18n("Contrast"));
450 m_comboBlend
->addItem(i18n("Hue Shift"));
453 void BGDialog::loadWallpaperFilesList() {
456 // the following QMap is lower cased names mapped to cased names and URLs
457 // this way we get case insensitive sorting
458 QMap
<QString
, QPair
<QString
, QString
> > papers
;
460 //search for .desktop files before searching for images without .desktop files
461 QStringList lst
= m_pDirs
->findAllResources("wallpaper", "*desktop", KStandardDirs::NoDuplicates
);
463 for (QStringList::ConstIterator it
= lst
.constBegin(); it
!= lst
.constEnd(); ++it
)
465 KDesktopFile
fileConfig(*it
);
466 KConfigGroup cg
= fileConfig
.group("Wallpaper");
468 QString imageCaption
= cg
.readEntry("Name");
469 QString fileName
= cg
.readEntry("File");
471 if (imageCaption
.isEmpty())
473 imageCaption
= fileName
;
474 imageCaption
.replace('_', ' ');
475 imageCaption
= KStringHandler::capwords(imageCaption
);
478 // avoid name collisions
479 QString rs
= imageCaption
;
480 QString lrs
= rs
.toLower();
481 for (int n
= 1; papers
.find(lrs
) != papers
.end(); ++n
)
483 rs
= imageCaption
+ " (" + QString::number(n
) + ')';
486 int slash
= (*it
).lastIndexOf('/') + 1;
487 QString directory
= (*it
).left(slash
);
488 if ( cg
.readEntry("ImageType") == "pixmap" ) {
489 papers
[lrs
] = qMakePair(rs
, directory
+ fileName
);
490 files
.append(directory
+ fileName
);
494 //now find any wallpapers that don't have a .desktop file
495 lst
= m_pDirs
->findAllResources("wallpaper", "*", KStandardDirs::NoDuplicates
);
496 for (QStringList::ConstIterator it
= lst
.constBegin(); it
!= lst
.constEnd(); ++it
)
498 if ( !(*it
).endsWith(".desktop") && files
.filter(*it
).empty() ) {
499 // First try to see if we have a comment describing the image. If we do
500 // just use the first line of said comment.
501 KFileMetaInfo
metaInfo(*it
);
502 QString imageCaption
;
504 if (metaInfo
.isValid() && metaInfo
.item("Comment").isValid())
505 imageCaption
= metaInfo
.item("Comment").value().toString().section('\n', 0, 0);
507 if (imageCaption
.isEmpty())
509 int slash
= (*it
).lastIndexOf('/') + 1;
510 int endDot
= (*it
).lastIndexOf('.');
512 // strip the extension if it exists
513 if (endDot
!= -1 && endDot
> slash
)
514 imageCaption
= (*it
).mid(slash
, endDot
- slash
);
516 imageCaption
= (*it
).mid(slash
);
518 imageCaption
.replace('_', ' ');
519 imageCaption
= KStringHandler::capwords(imageCaption
);
522 // avoid name collisions
523 QString rs
= imageCaption
;
524 QString lrs
= rs
.toLower();
525 for (int n
= 1; papers
.find(lrs
) != papers
.end(); ++n
)
527 rs
= imageCaption
+ " (" + QString::number(n
) + ')';
530 papers
[lrs
] = qMakePair(rs
, *it
);
534 KComboBox
*comboWallpaper
= m_urlWallpaperBox
;
535 comboWallpaper
->clear();
538 for (QMap
<QString
, QPair
<QString
, QString
> >::Iterator it
= papers
.begin();
542 comboWallpaper
->addItem(it
.value().first
);
543 m_wallpaper
[it
.value().second
] = i
;
548 void BGDialog::setWallpaper(const QString
&s
)
550 KComboBox
*comboWallpaper
= m_urlWallpaperBox
;
551 int i
= comboWallpaper
->count();
554 comboWallpaper
->blockSignals(true);
556 if (m_wallpaper
.find(s
) == m_wallpaper
.end())
558 QString imageCaption
;
559 int slash
= s
.lastIndexOf('/') + 1;
560 int endDot
= s
.lastIndexOf('.');
562 // strip the extension if it exists
563 if (endDot
!= -1 && endDot
> slash
)
564 imageCaption
= s
.mid(slash
, endDot
- slash
);
566 imageCaption
= s
.mid(slash
);
567 if (comboWallpaper
->itemText(i
-1) == imageCaption
)
570 comboWallpaper
->removeItem(i
);
572 comboWallpaper
->addItem(imageCaption
);
574 comboWallpaper
->setCurrentIndex(i
);
578 comboWallpaper
->setCurrentIndex(m_wallpaper
[s
]);
580 comboWallpaper
->blockSignals(false);
583 void BGDialog::slotWallpaperSelection()
586 KFileDialog
dlg( u
, QString(), this);
588 KImageFilePreview
* previewWidget
= new KImageFilePreview(&dlg
);
589 dlg
.setPreviewWidget(previewWidget
);
591 QStringList mimeTypes
= KImageIO::mimeTypes( KImageIO::Reading
);
592 mimeTypes
+= "image/svg+xml";
593 dlg
.setFilter( mimeTypes
.join( " " ) );
594 dlg
.setMode( KFile::File
| KFile::ExistingOnly
| KFile::LocalOnly
);
595 dlg
.setCaption( i18n("Select Wallpaper") );
597 int j
= m_urlWallpaperBox
->currentIndex();
599 for(QMap
<QString
,int>::ConstIterator it
= m_wallpaper
.constBegin();
600 it
!= m_wallpaper
.constEnd();
610 if ( !uri
.isEmpty() ) {
611 dlg
.setSelection( uri
);
614 if ( dlg
.exec() == QDialog::Accepted
)
616 setWallpaper(dlg
.selectedFile());
618 int optionID
= m_buttonGroupBackground
->id(m_radioPicture
);
619 m_buttonGroupBackground
->setButton( optionID
);
620 slotWallpaperTypeChanged( optionID
);
626 void BGDialog::updateUI()
628 KBackgroundRenderer
*r
= eRenderer();
629 m_comboScreen
->setCurrentIndex(m_eScreen
);
631 m_colorPrimary
->setColor(r
->colorA());
632 m_colorSecondary
->setColor(r
->colorB());
634 int wallpaperMode
= r
->wallpaperMode();
635 int multiMode
= r
->multiWallpaperMode();
637 if (r
->backgroundMode() == KBackgroundSettings::Program
&&
638 wallpaperMode
== KBackgroundSettings::NoWallpaper
)
639 groupBox3
->setEnabled( false );
641 groupBox3
->setEnabled( true );
643 if ((multiMode
== KBackgroundSettings::NoMultiRandom
) ||
644 (multiMode
== KBackgroundSettings::NoMulti
))
647 if (wallpaperMode
== KBackgroundSettings::NoWallpaper
)
650 m_urlWallpaperBox
->setEnabled(false);
651 m_urlWallpaperButton
->setEnabled(false);
652 m_buttonSetupWallpapers
->setEnabled(false);
653 m_comboWallpaperPos
->setEnabled(false);
654 m_lblWallpaperPos
->setEnabled(false);
656 m_buttonGroupBackground
->setButton(
657 m_buttonGroupBackground
->id(m_radioNoPicture
) );
664 m_urlWallpaperBox
->setEnabled(true);
665 m_urlWallpaperButton
->setEnabled(true);
666 m_buttonSetupWallpapers
->setEnabled(false);
667 m_comboWallpaperPos
->setEnabled(true);
668 m_lblWallpaperPos
->setEnabled(true);
670 setWallpaper(r
->wallpaper());
671 m_buttonGroupBackground
->setButton(
672 m_buttonGroupBackground
->id(m_radioPicture
) );
680 m_urlWallpaperBox
->setEnabled(false);
681 m_urlWallpaperButton
->setEnabled(false);
682 m_buttonSetupWallpapers
->setEnabled(true);
683 m_comboWallpaperPos
->setEnabled(true);
684 m_lblWallpaperPos
->setEnabled(true);
686 m_buttonGroupBackground
->setButton(
687 m_buttonGroupBackground
->id(m_radioSlideShow
) );
690 m_comboWallpaperPos
->setCurrentIndex(r
->wallpaperMode()-1);
692 bool bSecondaryEnabled
= true;
693 m_comboPattern
->blockSignals(true);
694 switch (r
->backgroundMode()) {
695 case KBackgroundSettings::Flat
:
696 m_comboPattern
->setCurrentIndex(0);
697 bSecondaryEnabled
= false;
700 case KBackgroundSettings::Pattern
:
702 int i
= m_patterns
.indexOf(r
->KBackgroundPattern::name());
704 m_comboPattern
->setCurrentIndex(NR_PREDEF_PATTERNS
+i
);
706 m_comboPattern
->setCurrentIndex(0);
710 case KBackgroundSettings::Program
:
711 m_comboPattern
->setCurrentIndex(0);
712 bSecondaryEnabled
= false;
716 m_comboPattern
->setCurrentIndex(
717 1 + r
->backgroundMode() - KBackgroundSettings::HorizontalGradient
);
720 m_comboPattern
->blockSignals(false);
722 m_colorSecondary
->setEnabled(bSecondaryEnabled
&& !m_readOnly
);
724 int mode
= r
->blendMode();
726 m_comboBlend
->blockSignals(true);
727 m_sliderBlend
->blockSignals(true);
729 m_comboBlend
->setCurrentIndex(mode
);
730 m_cbBlendReverse
->setChecked(r
->reverseBlending());
731 m_sliderBlend
->setValue( r
->blendBalance() / 10 );
733 m_comboBlend
->blockSignals(false);
734 m_sliderBlend
->blockSignals(false);
736 // turn it off if there is no background picture set!
737 setBlendingEnabled(wallpaperMode
!= KBackgroundSettings::NoWallpaper
);
739 // Start preview renderer(s)
740 if ( m_eScreen
== 0 )
742 r
->setPreview( m_pMonitorArrangement
->combinedPreviewSize() );
745 else if ( m_eScreen
== 1 )
747 r
->setPreview( m_pMonitorArrangement
->maxPreviewSize() );
752 for (unsigned j
= 0; j
< m_numScreens
; ++j
)
754 m_renderer
[j
+2]->stop();
755 m_renderer
[j
+2]->setPreview( m_pMonitorArrangement
->monitor(j
)->size() );
756 m_renderer
[j
+2]->start(true);
761 void BGDialog::slotPreviewDone(int screen_done
)
763 if (!m_previewUpdates
)
766 KBackgroundRenderer
* r
= m_renderer
[(m_eScreen
>1) ? (screen_done
+2) : m_eScreen
];
768 if (r
->image().isNull())
773 QPixmap pm
= QPixmap::fromImage(r
->image());
775 if ( m_eScreen
== 0 )
777 m_pMonitorArrangement
->setPixmap(pm
);
779 else if ( m_eScreen
== 1 )
781 for (unsigned i
= 0; i
< m_pMonitorArrangement
->numMonitors(); ++i
)
782 m_pMonitorArrangement
->monitor(i
)->setPixmap(pm
);
786 m_pMonitorArrangement
->monitor(screen_done
)->setPixmap(pm
);
790 void BGDialog::slotImageDropped(const QString
&uri
)
794 int optionID
= m_buttonGroupBackground
->id(m_radioPicture
);
795 m_buttonGroupBackground
->setButton( optionID
);
796 slotWallpaperTypeChanged( optionID
);
799 void BGDialog::slotWallpaperTypeChanged(int i
)
801 KBackgroundRenderer
*r
= eRenderer();
805 if (i
== m_buttonGroupBackground
->id(m_radioNoPicture
)) //None
807 m_urlWallpaperBox
->setEnabled(false);
808 m_urlWallpaperButton
->setEnabled(false);
809 m_buttonSetupWallpapers
->setEnabled(false);
810 m_comboWallpaperPos
->setEnabled(false);
811 m_lblWallpaperPos
->setEnabled(false);
812 r
->setWallpaperMode(KBackgroundSettings::NoWallpaper
);
814 if (m_slideShowRandom
== KBackgroundSettings::InOrder
)
815 r
->setMultiWallpaperMode(KBackgroundSettings::NoMulti
);
817 r
->setMultiWallpaperMode(KBackgroundSettings::NoMultiRandom
);
819 setBlendingEnabled(false);
823 else if (i
== m_buttonGroupBackground
->id(m_radioSlideShow
))
825 m_urlWallpaperBox
->setEnabled(false);
826 m_urlWallpaperButton
->setEnabled(false);
827 m_buttonSetupWallpapers
->setEnabled(true);
828 m_comboWallpaperPos
->setEnabled(true);
829 m_lblWallpaperPos
->setEnabled(true);
830 setBlendingEnabled(true);
832 m_comboWallpaperPos
->blockSignals(true);
833 m_comboWallpaperPos
->setCurrentIndex(m_wallpaperPos
-1);
834 m_comboWallpaperPos
->blockSignals(false);
836 if (r
->wallpaperList().count() == 0)
837 r
->setWallpaperMode( KBackgroundSettings::NoWallpaper
);
839 r
->setWallpaperMode(m_wallpaperPos
);
841 r
->setMultiWallpaperMode(m_slideShowRandom
);
842 setWallpaper(r
->wallpaper());
843 setBlendingEnabled(true);
847 else if (i
== m_buttonGroupBackground
->id(m_radioPicture
))
849 m_urlWallpaperBox
->setEnabled(true);
850 m_urlWallpaperButton
->setEnabled(true);
851 m_buttonSetupWallpapers
->setEnabled(false);
852 m_lblWallpaperPos
->setEnabled(true);
853 m_comboWallpaperPos
->setEnabled(true);
854 setBlendingEnabled(true);
856 if (m_slideShowRandom
== KBackgroundSettings::InOrder
)
857 r
->setMultiWallpaperMode(KBackgroundSettings::NoMulti
);
859 r
->setMultiWallpaperMode(KBackgroundSettings::NoMultiRandom
);
861 int j
= m_urlWallpaperBox
->currentIndex();
863 for(QMap
<QString
,int>::ConstIterator it
= m_wallpaper
.constBegin();
864 it
!= m_wallpaper
.constEnd();
874 KFileMetaInfo
metaInfo(path
);
875 if (metaInfo
.isValid() && metaInfo
.item("Dimensions").isValid())
877 // If the image is greater than 800x600 default to using scaled mode,
878 // otherwise default to tiled.
880 QSize s
= metaInfo
.item("Dimensions").value().toSize();
881 if (s
.width() >= 800 && s
.height() >= 600)
882 m_wallpaperPos
= KBackgroundSettings::Scaled
;
884 m_wallpaperPos
= KBackgroundSettings::Tiled
;
886 else if (KMimeType::findByPath(path
)->is("image/svg+xml"))
888 m_wallpaperPos
= KBackgroundSettings::Scaled
;
891 r
->setWallpaperMode(m_wallpaperPos
);
892 m_comboWallpaperPos
->blockSignals(true);
893 m_comboWallpaperPos
->setCurrentIndex(m_wallpaperPos
-1);
894 m_comboWallpaperPos
->blockSignals(false);
896 r
->setWallpaper(path
);
900 m_copyAllScreens
= true;
904 void BGDialog::slotWallpaper(int)
906 slotWallpaperTypeChanged(m_buttonGroupBackground
->id(m_radioPicture
));
910 void BGDialog::setBlendingEnabled(bool enable
)
914 int mode
= eRenderer()->blendMode();
916 bool b
= !(mode
== KBackgroundSettings::NoBlending
);
917 m_lblBlending
->setEnabled(enable
);
918 m_comboBlend
->setEnabled(enable
);
919 m_lblBlendBalance
->setEnabled(enable
&& b
);
920 m_sliderBlend
->setEnabled(enable
&& b
);
922 b
= !(mode
< KBackgroundSettings::IntensityBlending
);
923 m_cbBlendReverse
->setEnabled(enable
&& b
);
926 void BGDialog::slotWallpaperPos(int mode
)
928 KBackgroundRenderer
*r
= eRenderer();
931 m_wallpaperPos
= mode
;
933 if (mode
== r
->wallpaperMode())
937 r
->setWallpaperMode(mode
);
939 m_copyAllScreens
= true;
943 void BGDialog::slotSetupMulti()
945 KBackgroundRenderer
*r
= eRenderer();
947 BGMultiWallpaperDialog
dlg(r
, window());
948 if (dlg
.exec() == QDialog::Accepted
) {
950 m_slideShowRandom
= r
->multiWallpaperMode();
951 r
->setWallpaperMode(m_wallpaperPos
);
953 m_copyAllScreens
= true;
958 void BGDialog::slotPrimaryColor(const QColor
&color
)
960 KBackgroundRenderer
*r
= eRenderer();
962 if (color
== r
->colorA())
968 m_copyAllScreens
= true;
972 void BGDialog::slotSecondaryColor(const QColor
&color
)
974 KBackgroundRenderer
*r
= eRenderer();
976 if (color
== r
->colorB())
982 m_copyAllScreens
= true;
986 void BGDialog::slotPattern(int pattern
)
988 KBackgroundRenderer
*r
= eRenderer();
990 bool bSecondaryEnabled
= true;
991 if (pattern
< NR_PREDEF_PATTERNS
)
995 r
->setBackgroundMode(KBackgroundSettings::Flat
);
996 bSecondaryEnabled
= false;
1000 r
->setBackgroundMode(pattern
- 1 + KBackgroundSettings::HorizontalGradient
);
1005 r
->setBackgroundMode(KBackgroundSettings::Pattern
);
1006 r
->setPatternName(m_patterns
[pattern
- NR_PREDEF_PATTERNS
]);
1009 m_colorSecondary
->setEnabled(bSecondaryEnabled
);
1011 m_copyAllScreens
= true;
1015 void BGDialog::slotSelectScreen(int screen
)
1017 // Copy the settings from "All screens" to all the other screens
1018 // at a suitable point
1019 if (m_pGlobals
->commonScreenBackground() && (screen
>1) && m_copyAllScreens
)
1022 KBackgroundRenderer
*master
= m_renderer
[1];
1023 for (unsigned screen
= 0; screen
< m_numScreens
; ++screen
)
1025 m_renderer
[screen
+2]->copyConfig(master
);
1029 if (screen
== m_eScreen
)
1031 return; // Nothing to do
1034 m_copyAllScreens
= false;
1036 bool drawBackgroundPerScreen
= screen
> 0;
1037 bool commonScreenBackground
= screen
< 2;
1039 m_pGlobals
->setDrawBackgroundPerScreen(drawBackgroundPerScreen
);
1041 m_pGlobals
->setCommonScreenBackground(commonScreenBackground
);
1047 for (unsigned i
= 0; i
< m_renderer
.size(); ++i
)
1049 if ( m_renderer
[i
]->isActive() )
1050 m_renderer
[i
]->stop();
1058 void BGDialog::slotAdvanced()
1060 KBackgroundRenderer
*r
= eRenderer();
1062 m_previewUpdates
= false;
1063 BGAdvancedDialog
dlg(r
, window());
1065 if (!m_pMonitorArrangement
->isEnabled()) {
1072 if (m_pGlobals
->limitCache())
1073 dlg
.setCacheSize( m_pGlobals
->cacheSize() );
1075 dlg
.setCacheSize( 0 );
1080 m_previewUpdates
= true;
1085 int cacheSize
= dlg
.cacheSize();
1088 m_pGlobals
->setCacheSize(cacheSize
);
1089 m_pGlobals
->setLimitCache(true);
1093 m_pGlobals
->setLimitCache(false);
1098 m_previewUpdates
= true;
1105 void BGDialog::slotGetNewStuff()
1107 // We use the more complicated KNewStuff2 API here because these settings
1108 // might affect both kcmshell and kcontrol
1110 KNS::Engine
*engine
= new KNS::Engine(this);
1111 engine
->init("background.knsrc");
1112 //FIXME (KNS2): monday change
1113 //engine->setTitle(i18n("Get New Wallpapers"));
1114 engine
->downloadDialogModal();
1117 // FIXME (KNS2): engine->download gives us meta infos, write those into
1118 // the .desktop files
1119 loadWallpaperFilesList();
1122 void BGDialog::slotBlendMode(int mode
)
1124 if (mode
== eRenderer()->blendMode())
1127 bool b
= !(mode
== KBackgroundSettings::NoBlending
);
1128 m_sliderBlend
->setEnabled( b
);
1129 m_lblBlendBalance
->setEnabled( b
);
1131 b
= !(mode
< KBackgroundSettings::IntensityBlending
);
1132 m_cbBlendReverse
->setEnabled(b
);
1135 eRenderer()->stop();
1136 eRenderer()->setBlendMode(mode
);
1137 eRenderer()->start(true);
1140 void BGDialog::slotBlendBalance(int value
)
1143 if (value
== eRenderer()->blendBalance())
1147 eRenderer()->stop();
1148 eRenderer()->setBlendBalance(value
);
1149 eRenderer()->start(true);
1152 void BGDialog::slotBlendReverse(bool b
)
1154 if (b
== eRenderer()->reverseBlending())
1158 eRenderer()->stop();
1159 eRenderer()->setReverseBlending(b
);
1160 eRenderer()->start(true);
1163 void BGDialog::desktopResized()
1165 for (unsigned j
= 0; j
< m_renderer
.size(); ++j
)
1167 KBackgroundRenderer
* r
= m_renderer
[j
];
1170 r
->desktopResized();
1172 eRenderer()->start(true);
1176 #include "bgdialog.moc"