summaryrefslogtreecommitdiffstats
path: root/kcontrol/background/bgmonitor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kcontrol/background/bgmonitor.cpp')
-rw-r--r--kcontrol/background/bgmonitor.cpp84
1 files changed, 53 insertions, 31 deletions
diff --git a/kcontrol/background/bgmonitor.cpp b/kcontrol/background/bgmonitor.cpp
index ac826a1ff..75fd56546 100644
--- a/kcontrol/background/bgmonitor.cpp
+++ b/kcontrol/background/bgmonitor.cpp
@@ -5,16 +5,16 @@
Copyright (C) 2002 Laurent Montel <montell@club-internet.fr>
Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
Copyright (C) 2005 David Saxton <david@bluehaze.org>
-
+
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
+ modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
-
+
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
-
+
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
@@ -30,6 +30,8 @@
#include <tqpixmap.h>
#include <tqwhatsthis.h>
+#include <memory>
+
#include "bgmonitor.h"
// Constants used (should they be placed somewhere?)
@@ -40,16 +42,10 @@
BGMonitorArrangement::BGMonitorArrangement(TQWidget *parent, const char *name)
: TQWidget(parent, name)
{
- m_pBGMonitor.resize( TQApplication::desktop()->numScreens(), 0l );
-
- for (int screen = 0; screen < TQApplication::desktop()->numScreens(); ++screen)
- {
- BGMonitorLabel * label = new BGMonitorLabel(this);
- m_pBGMonitor[screen] = label;
-
- connect( label->monitor(), TQ_SIGNAL(imageDropped(const TQString &)), this, TQ_SIGNAL(imageDropped(const TQString &)) );
- }
-
+ connect(TQApplication::desktop(), TQ_SIGNAL(screenCountChanged(int)),
+ this , TQ_SLOT(updateArrangement()));
+ connect(TQApplication::desktop(), TQ_SIGNAL(resized(int)),
+ this , TQ_SLOT(updateArrangement()));
parent->setFixedSize(200, 186);
setFixedSize(200, 186);
updateArrangement();
@@ -92,40 +88,66 @@ void BGMonitorArrangement::updateArrangement()
// value. The expanded value is used for setting the size of the monitor
// image that contains the preview of the background. The monitor image
// will set the background preview back to the normal value.
-
+
+ bool isVDesktop = TQApplication::desktop()->isVirtualDesktop();
TQRect overallGeometry;
- for (int screen = 0; screen < TQApplication::desktop()->numScreens(); ++screen)
- overallGeometry |= TQApplication::desktop()->screenGeometry(screen);
-
+ size_t screen_num = isVDesktop ? TQApplication::desktop()->numScreens() : 1;
+
+ // create/destroy monitors
+ if (m_pBGMonitor.size() != screen_num) {
+ size_t old_size = m_pBGMonitor.size();
+ if(old_size<screen_num) {
+ for (size_t screen = old_size; screen < screen_num; ++screen)
+ {
+ m_pBGMonitor.emplace_back(std::make_unique<BGMonitorLabel>(this));
+ connect( m_pBGMonitor[screen]->monitor(), TQ_SIGNAL(imageDropped(const TQString &)), this, TQ_SIGNAL(imageDropped(const TQString &)) );
+ }
+ } else {
+ m_pBGMonitor.resize(screen_num);
+ }
+ }
+ overallGeometry = TQApplication::desktop()->screenGeometry();
+ if (isVDesktop) {
+ for (size_t screen = 0; screen < screen_num; ++screen)
+ overallGeometry |= TQApplication::desktop()->screenGeometry(screen);
+ } else {
+ overallGeometry = TQApplication::desktop()->screenGeometry();
+ }
+
TQRect expandedOverallGeometry = expandToPreview(overallGeometry);
-
+
double scale = TQMIN(
double(width()) / double(expandedOverallGeometry.width()),
double(height()) / double(expandedOverallGeometry.height())
);
-
+
m_combinedPreviewSize = overallGeometry.size() * scale;
-
+
m_maxPreviewSize = TQSize(0,0);
int previousMax = 0;
-
- for (int screen = 0; screen < TQApplication::desktop()->numScreens(); ++screen)
- {
+
+ auto screenSetupWorker = [&](size_t screen){
TQPoint topLeft = (TQApplication::desktop()->screenGeometry(screen).topLeft() - overallGeometry.topLeft()) * scale;
- TQPoint expandedTopLeft = expandToPreview(topLeft);
-
TQSize previewSize = TQApplication::desktop()->screenGeometry(screen).size() * scale;
+
+ TQPoint expandedTopLeft = expandToPreview(topLeft);
TQSize expandedPreviewSize = expandToPreview(previewSize);
-
+
if ( (previewSize.width() * previewSize.height()) > previousMax )
{
previousMax = previewSize.width() * previewSize.height();
m_maxPreviewSize = previewSize;
}
-
+
m_pBGMonitor[screen]->setPreviewPosition( TQRect( topLeft, previewSize ) );
m_pBGMonitor[screen]->setGeometry( TQRect( expandedTopLeft, expandedPreviewSize ) );
m_pBGMonitor[screen]->updateMonitorGeometry();
+ };
+ if(isVDesktop) {
+ for (size_t screen = 0; screen < screen_num; ++screen)
+ screenSetupWorker(screen);
+ } else {
+ screenSetupWorker(TQApplication::desktop()->primaryScreen());
}
}
@@ -142,7 +164,7 @@ void BGMonitorArrangement::setPixmap( const KPixmap & pm )
for (unsigned screen = 0; screen < m_pBGMonitor.size(); ++screen)
{
TQRect position = m_pBGMonitor[screen]->previewPosition();
-
+
TQPixmap monitorPixmap( position.size(), pm.depth() );
copyBlt( &monitorPixmap, 0, 0, &pm, position.x(), position.y(), position.width(), position.height() );
m_pBGMonitor[screen]->monitor()->setPixmap(monitorPixmap);
@@ -160,7 +182,7 @@ BGMonitorLabel::BGMonitorLabel(TQWidget *parent, const char *name)
setScaledContents(true);
setPixmap( TQPixmap( locate("data", "kcontrol/pics/monitor.png") ) );
m_pBGMonitor = new BGMonitor(this);
-
+
TQWhatsThis::add( this, i18n("This picture of a monitor contains a preview of what the current settings will look like on your desktop.") );
}
@@ -169,7 +191,7 @@ void BGMonitorLabel::updateMonitorGeometry()
{
double scaleX = double(width()) / double(sizeHint().width());
double scaleY = double(height()) / double(sizeHint().height());
-
+
kdDebug() << k_funcinfo << " Setting geometry to " << TQRect( int(23*scaleX), int(14*scaleY), int(151*scaleX), int(115*scaleY) ) << endl;
m_pBGMonitor->setGeometry( int(23*scaleX), int(14*scaleY), int(151*scaleX), int(115*scaleY) );
}