You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
549 lines
20 KiB
549 lines
20 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2000 Matthias Kalle Dalheimer <kalle@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
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,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kchartBackgroundPixmapConfigPage.h"
|
||
|
#include "kchartBackgroundPixmapConfigPage.moc"
|
||
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdeglobal.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdefilemetainfo.h>
|
||
15 years ago
|
#include <kstringhandler.h>
|
||
|
|
||
14 years ago
|
#include <tqcombobox.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqbuttongroup.h>
|
||
|
#include <tqspinbox.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqhbox.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqwhatsthis.h>
|
||
|
#include <tqlistbox.h>
|
||
15 years ago
|
#include <kcolorbutton.h>
|
||
|
|
||
|
#include "kchart_params.h"
|
||
|
|
||
|
namespace KChart
|
||
|
{
|
||
|
|
||
14 years ago
|
KChartBackgroundPixmapConfigPage::KChartBackgroundPixmapConfigPage( KChartParams* params, TQWidget* parent )
|
||
|
: TQWidget( parent, "KChartBackgroundPixmapConfigPage" ),
|
||
15 years ago
|
_params( params )
|
||
|
{
|
||
14 years ago
|
TQWhatsThis::add( this,
|
||
15 years ago
|
i18n( "On this page, you can select colors or images "
|
||
|
"to be displayed behind the different areas. You "
|
||
|
"can also select whether the images should be "
|
||
|
"stretched or scaled or centered or used as "
|
||
|
"background tiles." ) );
|
||
|
|
||
14 years ago
|
TQHBoxLayout* toplevel = new TQHBoxLayout( this, 10 );
|
||
15 years ago
|
|
||
|
#if 0
|
||
14 years ago
|
TQVBoxLayout* left=new TQVBoxLayout(10);
|
||
15 years ago
|
toplevel->addLayout(left,2);
|
||
14 years ago
|
regionList=new TQListBox(this);
|
||
15 years ago
|
left->addWidget(regionList);
|
||
|
#endif
|
||
|
|
||
14 years ago
|
TQVBoxLayout* center = new TQVBoxLayout( 10 );
|
||
15 years ago
|
toplevel->addLayout( center, 2 );
|
||
|
|
||
|
|
||
14 years ago
|
TQLabel* backgroundLA = new TQLabel( i18n( "&Background color:" ), this );
|
||
15 years ago
|
center->addWidget( backgroundLA );
|
||
|
_backgroundCB = new KColorButton( this );
|
||
|
backgroundLA->setBuddy( _backgroundCB );
|
||
|
center->addWidget( _backgroundCB);
|
||
14 years ago
|
TQString wtstr = i18n( "Here you set the color in which the background "
|
||
15 years ago
|
"of the chart is painted." );
|
||
14 years ago
|
TQWhatsThis::add( backgroundLA, wtstr );
|
||
|
TQWhatsThis::add( _backgroundCB, wtstr );
|
||
15 years ago
|
|
||
|
|
||
14 years ago
|
TQLabel* wallpaperLA = new TQLabel( i18n( "Background wallpaper:" ), this );
|
||
15 years ago
|
center->addWidget( wallpaperLA );
|
||
|
|
||
14 years ago
|
wallCB = new TQComboBox( false, this, "wallCombo" );
|
||
15 years ago
|
wallpaperLA->setBuddy(wallCB);
|
||
14 years ago
|
TQWhatsThis::add( wallCB, i18n( "You can select a background image from "
|
||
13 years ago
|
"this list. Initially, the installed TDE "
|
||
15 years ago
|
"wallpapers will be offered. If you do not "
|
||
|
"find what you are looking for here, you can "
|
||
|
"select any image file by clicking on the "
|
||
|
"<i>Browse</i> button below." ) );
|
||
|
center->addWidget( wallCB );
|
||
|
wallCB->insertItem( i18n("None") );
|
||
|
|
||
|
loadWallpaperFilesList();
|
||
14 years ago
|
TQPushButton* browsePB = new TQPushButton( i18n("&Browse..."), this );
|
||
|
TQWhatsThis::add( browsePB, i18n( "Click this button to select a background "
|
||
15 years ago
|
"image not yet present in the list above. " ) );
|
||
|
center->addWidget( browsePB );
|
||
14 years ago
|
connect( browsePB, TQT_SIGNAL( clicked() ), TQT_SLOT( slotBrowse() ) );
|
||
15 years ago
|
|
||
14 years ago
|
wallWidget = new TQWidget( this );
|
||
|
TQWhatsThis::add( wallWidget, i18n( "This area will always display the "
|
||
15 years ago
|
"currently selected background image. "
|
||
|
"Note that the image will be scaled and "
|
||
|
"thus might have a different ratio than "
|
||
|
"it originally had." ) );
|
||
|
center->addWidget( wallWidget );
|
||
|
|
||
14 years ago
|
connect( wallCB, TQT_SIGNAL( activated( int ) ),
|
||
|
this, TQT_SLOT( slotWallPaperChanged( int ) ) );
|
||
15 years ago
|
|
||
14 years ago
|
right = new TQVGroupBox( i18n( "Wallpaper Configuration" ), this );
|
||
|
TQWhatsThis::add( right, i18n( "In this box, you can set various settings "
|
||
15 years ago
|
"that control how the background image is "
|
||
|
"displayed." ) );
|
||
|
toplevel->addWidget( right );
|
||
|
|
||
14 years ago
|
TQHBox* intensityHB = new TQHBox( right );
|
||
15 years ago
|
intensityHB->setSpacing( 10 );
|
||
14 years ago
|
TQLabel* intensityLA = new TQLabel(
|
||
15 years ago
|
// xgettext:no-c-format
|
||
|
i18n( "&Intensity in %:" ), intensityHB );
|
||
14 years ago
|
intensitySB = new TQSpinBox( 1, 100, 1, intensityHB );
|
||
15 years ago
|
intensityLA->setBuddy( intensitySB );
|
||
|
// xgettext:no-c-format
|
||
14 years ago
|
TQString ttstr = i18n( "Here you can select how much the image should be "
|
||
15 years ago
|
"brightened up so that it does not disturb the "
|
||
|
"selected area too much.<br> Different images require "
|
||
|
"different settings, but 25% is a good value to start "
|
||
|
"with." );
|
||
14 years ago
|
TQWhatsThis::add( intensityLA, ttstr );
|
||
|
TQWhatsThis::add( intensitySB, ttstr );
|
||
15 years ago
|
|
||
|
|
||
14 years ago
|
stretchedRB = new TQRadioButton( i18n( "Stretched" ), right );
|
||
|
TQWhatsThis::add( stretchedRB,
|
||
15 years ago
|
i18n( "If you check this box, the selected image will "
|
||
|
"be scaled to fit the total size of the selected "
|
||
|
"area. Image ratio will be adjusted to match "
|
||
|
"the area size and height if necessary." ) );
|
||
|
stretchedRB->setChecked( true );
|
||
14 years ago
|
scaledRB = new TQRadioButton( i18n( "Scaled" ), right );
|
||
|
TQWhatsThis::add( scaledRB,
|
||
15 years ago
|
i18n( "If you check this box, the selected image will "
|
||
|
"be scaled to match the height or width of the "
|
||
|
"selected area - whichever is reached first." ) );
|
||
14 years ago
|
centeredRB = new TQRadioButton( i18n( "Centered" ), right );
|
||
|
TQWhatsThis::add( centeredRB,
|
||
15 years ago
|
i18n( "If you check this box, the selected image will "
|
||
|
"be centered over the selected area. If the image "
|
||
|
"is larger then the area, you will only see the "
|
||
|
"middle part of it." ) );
|
||
|
|
||
14 years ago
|
tiledRB = new TQRadioButton( i18n( "Tiled" ), right );
|
||
|
TQWhatsThis::add( tiledRB,
|
||
15 years ago
|
i18n( "If you check this box, the selected image will "
|
||
|
"be used as a background tile. If the image is "
|
||
|
"larger then the selected area, you will only see "
|
||
|
"the upper left part of it." ) );
|
||
14 years ago
|
TQButtonGroup* alignmentBG;
|
||
|
alignmentBG = new TQButtonGroup( right, "GroupBox_Alignment" );
|
||
|
alignmentBG->setFrameStyle( TQFrame::NoFrame );
|
||
|
alignmentBG->insert( stretchedRB );
|
||
|
alignmentBG->insert( scaledRB );
|
||
|
alignmentBG->insert( centeredRB );
|
||
|
alignmentBG->insert( tiledRB );
|
||
15 years ago
|
|
||
|
intensitySB->hide(); //the property doesn't work atm
|
||
|
}
|
||
|
|
||
4 years ago
|
//Code from kcontrol/background/bgdialog.cpp
|
||
15 years ago
|
void KChartBackgroundPixmapConfigPage::loadWallpaperFilesList()
|
||
|
{
|
||
|
// Wallpapers
|
||
14 years ago
|
// the following TQMap is lower cased names mapped to cased names and URLs
|
||
15 years ago
|
// this way we get case insensitive sorting
|
||
14 years ago
|
TQMap<TQString, TQPair<TQString, TQString> > papers;
|
||
15 years ago
|
|
||
|
//search for .desktop files before searching for images without .desktop files
|
||
12 years ago
|
TQStringList lst = TDEGlobal::dirs()->findAllResources("wallpaper", "*desktop", false, true);
|
||
14 years ago
|
TQStringList files;
|
||
|
for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
|
||
15 years ago
|
{
|
||
|
KSimpleConfig fileConfig(*it);
|
||
|
fileConfig.setGroup("Wallpaper");
|
||
|
|
||
14 years ago
|
TQString imageCaption = fileConfig.readEntry("Name");
|
||
|
TQString fileName = fileConfig.readEntry("File");
|
||
15 years ago
|
|
||
|
if (imageCaption.isEmpty())
|
||
|
{
|
||
|
imageCaption = fileName;
|
||
14 years ago
|
imageCaption.replace('_', ' ');
|
||
15 years ago
|
imageCaption = KStringHandler::capwords(imageCaption);
|
||
|
}
|
||
|
|
||
|
// avoid name collisions
|
||
14 years ago
|
TQString rs = imageCaption;
|
||
|
TQString lrs = rs.lower();
|
||
14 years ago
|
for (int n = 1; papers.find(lrs) != papers.end(); ++n)
|
||
15 years ago
|
{
|
||
14 years ago
|
rs = imageCaption + " (" + TQString::number(n) + ')';
|
||
15 years ago
|
lrs = rs.lower();
|
||
|
}
|
||
14 years ago
|
int slash = (*it).findRev('/') + 1;
|
||
14 years ago
|
TQString directory = (*it).left(slash);
|
||
15 years ago
|
bool canLoadScaleable = false;
|
||
|
#ifdef HAVE_LIBART
|
||
|
canLoadScaleable = true;
|
||
|
#endif
|
||
|
if ( fileConfig.readEntry("ImageType") == "pixmap" || canLoadScaleable ) {
|
||
14 years ago
|
papers[lrs] = tqMakePair(rs, directory + fileName);
|
||
15 years ago
|
files.append(directory + fileName);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//now find any wallpapers that don't have a .desktop file
|
||
12 years ago
|
lst = TDEGlobal::dirs()->findAllResources("wallpaper", "*", false, true);
|
||
14 years ago
|
for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
|
||
15 years ago
|
{
|
||
|
if ( !(*it).endsWith(".desktop") && files.grep(*it).empty() ) {
|
||
|
// First try to see if we have a comment describing the image. If we do
|
||
|
// just use the first line of said comment.
|
||
|
KFileMetaInfo metaInfo(*it);
|
||
14 years ago
|
TQString imageCaption;
|
||
15 years ago
|
|
||
|
if (metaInfo.isValid() && metaInfo.item("Comment").isValid())
|
||
|
imageCaption = metaInfo.item("Comment").string().section('\n', 0, 0);
|
||
|
|
||
|
if (imageCaption.isEmpty())
|
||
|
{
|
||
14 years ago
|
int slash = (*it).findRev('/') + 1;
|
||
|
int endDot = (*it).findRev('.');
|
||
15 years ago
|
|
||
|
// strip the extension if it exists
|
||
|
if (endDot != -1 && endDot > slash)
|
||
|
imageCaption = (*it).mid(slash, endDot - slash);
|
||
|
else
|
||
|
imageCaption = (*it).mid(slash);
|
||
|
|
||
14 years ago
|
imageCaption.replace('_', ' ');
|
||
15 years ago
|
imageCaption = KStringHandler::capwords(imageCaption);
|
||
|
}
|
||
|
|
||
|
// avoid name collisions
|
||
14 years ago
|
TQString rs = imageCaption;
|
||
|
TQString lrs = rs.lower();
|
||
14 years ago
|
for (int n = 1; papers.find(lrs) != papers.end(); ++n)
|
||
15 years ago
|
{
|
||
14 years ago
|
rs = imageCaption + " (" + TQString::number(n) + ')';
|
||
15 years ago
|
lrs = rs.lower();
|
||
|
}
|
||
14 years ago
|
papers[lrs] = tqMakePair(rs, *it);
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
m_wallpaper.clear();
|
||
|
//don't start to 0, we have None element
|
||
|
int i = 1;
|
||
14 years ago
|
for (TQMap<TQString, TQPair<TQString, TQString> >::Iterator it = papers.begin();
|
||
15 years ago
|
it != papers.end();
|
||
|
++it)
|
||
|
{
|
||
|
wallCB->insertItem(it.data().first);
|
||
|
m_wallpaper[it.data().second] = i;
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KChartBackgroundPixmapConfigPage::init()
|
||
|
{
|
||
|
#if 0
|
||
14 years ago
|
TQStringList lst;
|
||
15 years ago
|
lst.append(i18n( "Outermost Region" ));
|
||
|
lst.append(i18n( "Innermost Region" ));
|
||
|
lst.append(i18n( "Header+Title+Subtitle" ));
|
||
|
lst.append(i18n( "Footers" ));
|
||
|
lst.append(i18n( "Data+Axes+Legend" ));
|
||
|
lst.append(i18n( "Data+Axes" ));
|
||
|
lst.append(i18n( "Data" ));
|
||
|
lst.append(i18n( "Legend" ));
|
||
|
lst.append(i18n( "Left Axis" ));
|
||
|
lst.append(i18n( "Bottom Axis" ));
|
||
|
lst.append(i18n( "Right Axis" ));
|
||
|
lst.append(i18n( "Header A" ));
|
||
|
lst.append(i18n( "Header B" ));
|
||
|
lst.append(i18n( "Header C" ));
|
||
|
lst.append(i18n( "Title A" ));
|
||
|
lst.append(i18n( "Title B" ));
|
||
|
lst.append(i18n( "Title C" ));
|
||
|
lst.append(i18n( "Subtitle A" ));
|
||
|
lst.append(i18n( "Subtitle B" ));
|
||
|
lst.append(i18n( "Subtitle C" ));
|
||
|
lst.append(i18n( "Footer 1 A" ));
|
||
|
lst.append(i18n( "Footer 1 B" ));
|
||
|
lst.append(i18n( "Footer 1 C" ));
|
||
|
lst.append(i18n( "Footer 2 A" ));
|
||
|
lst.append(i18n( "Footer 2 B" ));
|
||
|
lst.append(i18n( "Footer 2 C" ));
|
||
|
lst.append(i18n( "Footer 3 A" ));
|
||
|
lst.append(i18n( "Footer 3 B" ));
|
||
|
lst.append(i18n( "Footer 3 C" ));
|
||
|
regionList->insertStringList(lst);
|
||
|
#endif
|
||
|
// PENDING(kalle) Readapt
|
||
|
// showSettings( _params->backgroundPixmapName );
|
||
|
// intensitySB->setValue( (int)(_params->backgroundPixmapIntensity * 100.0) );
|
||
|
// scaledCB->setChecked( _params->backgroundPixmapScaled );
|
||
|
// centeredCB->setChecked( _params->backgroundPixmapCentered );
|
||
|
|
||
|
bool bFound;
|
||
|
const KDChartParams::KDChartFrameSettings * innerFrame =
|
||
|
_params->frameSettings( KDChartEnums::AreaInnermost, bFound );
|
||
|
if( bFound )
|
||
|
{
|
||
14 years ago
|
const TQPixmap* backPixmap;
|
||
15 years ago
|
bool isTiledMode = false;
|
||
|
KDFrame::BackPixmapMode backPixmapMode;
|
||
14 years ago
|
const TQBrush& background = innerFrame->frame().background( backPixmap, backPixmapMode );
|
||
|
const TQColor backColor( background.color() );
|
||
15 years ago
|
|
||
|
// Bg color has to be be set in any case,
|
||
|
// even when a (tiled) pixmap is specified:
|
||
|
_backgroundCB->setColor( backColor );
|
||
|
|
||
|
|
||
|
if( !backPixmap || backPixmap->isNull() )
|
||
|
{
|
||
|
// A pixmap can be in the brush, if used as Tile.
|
||
|
backPixmap = background.pixmap();
|
||
|
if( backPixmap )
|
||
|
isTiledMode = true;
|
||
|
}
|
||
|
|
||
|
if( !backPixmap || backPixmap->isNull() ) //color as background
|
||
|
{
|
||
|
right->setEnabled( false );
|
||
|
wallCB->setCurrentItem( 0 );
|
||
|
}
|
||
|
else //pixmap as background
|
||
|
{
|
||
|
_backgroundCB->setEnabled( false );
|
||
|
wallWidget->setPaletteBackgroundPixmap( *backPixmap );
|
||
|
wallCB->setCurrentItem( 1 );
|
||
|
if( isTiledMode )
|
||
|
{
|
||
|
tiledRB->setChecked( true );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
switch( backPixmapMode ){
|
||
|
case KDFrame::PixCentered:
|
||
|
centeredRB->setChecked( true );
|
||
|
break;
|
||
|
case KDFrame::PixScaled:
|
||
|
scaledRB->setChecked( true );
|
||
|
break;
|
||
|
default:
|
||
|
stretchedRB->setChecked( true );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
14 years ago
|
_backgroundCB->setColor(TQColor(230, 222, 222) );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KChartBackgroundPixmapConfigPage::apply()
|
||
|
{
|
||
|
// PENDING(kalle) Readapt
|
||
|
// if( wallCB->currentText() != _params->backgroundPixmapName ) {
|
||
|
// bool load=true;
|
||
|
// if(wallCB->currentText()==i18n("None")) {
|
||
|
// load=false;
|
||
|
// } else {
|
||
|
// _params->backgroundPixmapName = wallCB->currentText();
|
||
|
// bool load=_params->backgroundPixmap.load( locate( "wallpaper", _params->backgroundPixmapName ) );
|
||
|
// if(load)
|
||
|
// _params->backgroundPixmapIsDirty = true;
|
||
|
// }
|
||
|
|
||
|
// if( !load ) {
|
||
|
// _params->backgroundPixmapName = "";
|
||
14 years ago
|
// _params->backgroundPixmap=TQPixmap("");
|
||
15 years ago
|
// _params->backgroundPixmapIsDirty = false;
|
||
|
// }
|
||
|
// }
|
||
|
// if( (int)(_params->backgroundPixmapIntensity * 100.0) !=
|
||
|
// intensitySB->value() ) {
|
||
|
// _params->backgroundPixmapIntensity = (float)(intensitySB->value()) / 100.0;
|
||
|
// _params->backgroundPixmapIsDirty = true;
|
||
|
// }
|
||
|
|
||
|
// if( _params->backgroundPixmapScaled !=
|
||
|
// scaledCB->isChecked() ) {
|
||
|
// _params->backgroundPixmapScaled = scaledCB->isChecked();
|
||
|
// _params->backgroundPixmapIsDirty = true;
|
||
|
// }
|
||
|
// if( _params->backgroundPixmapCentered !=
|
||
|
// centeredCB->isChecked() ) {
|
||
|
// _params->backgroundPixmapCentered = centeredCB->isChecked();
|
||
|
// _params->backgroundPixmapIsDirty = true;
|
||
|
// }
|
||
|
|
||
|
//
|
||
|
// temp. hack: the background is removed if "None" is selected in the combo box
|
||
|
//
|
||
|
// For KOffice 1.5/2.0 this is to be removed by a checkbox.
|
||
|
bool bFound;
|
||
|
const KDChartParams::KDChartFrameSettings * innerFrame =
|
||
|
_params->frameSettings( KDChartEnums::AreaInnermost, bFound );
|
||
|
if( bFound )
|
||
|
{
|
||
14 years ago
|
const TQColor backColor( _backgroundCB->color() );
|
||
15 years ago
|
KDFrame& frame( const_cast<KDFrame&>(innerFrame->frame()) );
|
||
|
if ( wallCB->currentItem() == 0 )
|
||
|
{
|
||
|
frame.setBackPixmap( 0 );
|
||
|
frame.setBackground( backColor );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
const TQPixmap* pixmap = wallWidget->paletteBackgroundPixmap();
|
||
15 years ago
|
if ( tiledRB->isChecked() ){
|
||
|
// We remove the frame's extra pixmap,
|
||
|
frame.setBackPixmap( 0 );
|
||
14 years ago
|
// because a tiled image is set via a TQBrush.
|
||
15 years ago
|
if( pixmap )
|
||
14 years ago
|
frame.setBackground( TQBrush( backColor, *pixmap ) );
|
||
15 years ago
|
else
|
||
|
frame.setBackground( backColor );
|
||
|
}else{
|
||
|
KDFrame::BackPixmapMode backPixmapMode;
|
||
|
if ( centeredRB->isChecked() )
|
||
|
backPixmapMode = KDFrame::PixCentered;
|
||
|
else if ( scaledRB->isChecked() )
|
||
|
backPixmapMode = KDFrame::PixScaled;
|
||
|
else
|
||
|
backPixmapMode = KDFrame::PixStretched;
|
||
|
// We reset the background color, removing any tiled brush,
|
||
|
frame.setBackground( backColor );
|
||
|
// because we specify an extra pixmap instead.
|
||
|
frame.setBackPixmap( pixmap, backPixmapMode );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KChartBackgroundPixmapConfigPage::showSettings( const TQString& fileName )
|
||
15 years ago
|
{
|
||
|
wallCB->blockSignals(true);
|
||
|
|
||
14 years ago
|
if (m_wallpaper.find(fileName) == m_wallpaper.end())
|
||
15 years ago
|
{
|
||
|
int i = wallCB->count();
|
||
14 years ago
|
TQString imageCaption;
|
||
14 years ago
|
int slash = fileName.findRev('/') + 1;
|
||
|
int endDot = fileName.findRev('.');
|
||
15 years ago
|
|
||
|
// strip the extension if it exists
|
||
|
if (endDot != -1 && endDot > slash)
|
||
|
imageCaption = fileName.mid(slash, endDot - slash);
|
||
|
else
|
||
|
imageCaption = fileName.mid(slash);
|
||
|
if (wallCB->text(i-1) == imageCaption)
|
||
|
{
|
||
|
i--;
|
||
|
wallCB->removeItem(i);
|
||
|
}
|
||
|
wallCB->insertItem(imageCaption);
|
||
|
m_wallpaper[fileName] = i;
|
||
|
wallCB->setCurrentItem(i);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
wallCB->setCurrentItem(m_wallpaper[fileName]);
|
||
|
}
|
||
|
wallCB->blockSignals(false);
|
||
|
loadWallPaper();
|
||
|
}
|
||
|
|
||
|
|
||
|
void KChartBackgroundPixmapConfigPage::slotBrowse()
|
||
|
{
|
||
|
//TODO: Support non-local wallpapers
|
||
|
KURL url = KFileDialog::getOpenFileName( 0 );
|
||
|
if( url.isEmpty() )
|
||
|
return;
|
||
|
showSettings( url.path() );
|
||
|
}
|
||
|
|
||
|
void KChartBackgroundPixmapConfigPage::slotWallPaperChanged( int index )
|
||
|
{
|
||
|
if ( index != 0 && loadWallPaper() )
|
||
|
{
|
||
|
_backgroundCB->setEnabled( false );
|
||
|
right->setEnabled( true );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
wallWidget->setPaletteBackgroundPixmap( 0 );
|
||
|
_backgroundCB->setEnabled( true );
|
||
|
right->setEnabled( false );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
bool KChartBackgroundPixmapConfigPage::loadWallPaper()
|
||
|
{
|
||
|
int i = wallCB->currentItem();
|
||
|
if ( i == -1 || i == 0 ) { // 0 is 'None'
|
||
|
wallPixmap.resize(0,0);
|
||
|
wallFile = "";
|
||
|
} else {
|
||
14 years ago
|
for(TQMap<TQString,int>::ConstIterator it = m_wallpaper.begin();
|
||
15 years ago
|
it != m_wallpaper.end();
|
||
|
++it)
|
||
|
{
|
||
|
if (it.data() == i)
|
||
|
{
|
||
|
wallFile = it.key();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
TQString file = locate("wallpaper", wallFile);
|
||
15 years ago
|
if( file.isEmpty() ) {
|
||
|
kdWarning(35001) << "Couldn't locate wallpaper " << wallFile << endl;
|
||
|
wallPixmap.resize(0,0);
|
||
|
wallFile = "";
|
||
|
return false;
|
||
|
} else {
|
||
|
wallPixmap.load( file );
|
||
|
|
||
|
if( wallPixmap.isNull() )
|
||
|
return false;
|
||
|
// kdWarning(35001) << "Could not load wallpaper " << file << endl;
|
||
|
}
|
||
|
}
|
||
|
wallWidget->setPaletteBackgroundPixmap( wallPixmap );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
} //KChart namespace
|