00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kchartBackgroundPixmapConfigPage.h"
00021 #include "kchartBackgroundPixmapConfigPage.moc"
00022
00023 #include <klocale.h>
00024 #include <kglobal.h>
00025 #include <kstandarddirs.h>
00026 #include <kfiledialog.h>
00027 #include <kmessagebox.h>
00028 #include <kdebug.h>
00029
00030 #include <qcombobox.h>
00031 #include <qradiobutton.h>
00032 #include <qbuttongroup.h>
00033 #include <qspinbox.h>
00034 #include <qlayout.h>
00035 #include <qhbox.h>
00036 #include <qpushbutton.h>
00037 #include <qlabel.h>
00038 #include <qwhatsthis.h>
00039 #include <qlistbox.h>
00040 #include <kcolorbutton.h>
00041
00042 #include "kchart_params.h"
00043
00044 namespace KChart
00045 {
00046
00047 KChartBackgroundPixmapConfigPage::KChartBackgroundPixmapConfigPage( KChartParams* params, QWidget* parent )
00048 : QWidget( parent, "KChartBackgroundPixmapConfigPage" ),
00049 _params( params )
00050 {
00051 QWhatsThis::add( this,
00052 i18n( "On this page, you can select colors or images "
00053 "to be displayed behind the different areas. You "
00054 "can also select whether the images should be "
00055 "stretched or scaled or centered or used as "
00056 "background tiles." ) );
00057
00058 QHBoxLayout* toplevel = new QHBoxLayout( this, 10 );
00059
00060 #if 0
00061 QVBoxLayout* left=new QVBoxLayout(10);
00062 toplevel->addLayout(left,2);
00063 regionList=new QListBox(this);
00064 left->addWidget(regionList);
00065 #endif
00066
00067 QVBoxLayout* center = new QVBoxLayout( 10 );
00068 toplevel->addLayout( center, 2 );
00069
00070
00071 QLabel* backgroundLA = new QLabel( i18n( "&Background color:" ), this );
00072 center->addWidget( backgroundLA );
00073 _backgroundCB = new KColorButton( this );
00074 backgroundLA->setBuddy( _backgroundCB );
00075 center->addWidget( _backgroundCB);
00076 QString wtstr = i18n( "Here you set the color in which the background "
00077 "of the chart is painted." );
00078 QWhatsThis::add( backgroundLA, wtstr );
00079 QWhatsThis::add( _backgroundCB, wtstr );
00080
00081
00082 QLabel* wallpaperLA = new QLabel( i18n( "Background wallpaper:" ), this );
00083 center->addWidget( wallpaperLA );
00084
00085 wallCB = new QComboBox( false, this, "wallCombo" );
00086 wallpaperLA->setBuddy(wallCB);
00087 QWhatsThis::add( wallCB, i18n( "You can select a background image from "
00088 "this list. Initially, the installed KDE "
00089 "wallpapers will be offered. If you do not "
00090 "find what you are looking for here, you can "
00091 "select any image file by clicking on the "
00092 "<i>Browse</i> button below." ) );
00093 center->addWidget( wallCB );
00094 wallCB->insertItem( i18n("None") );
00095
00096 QStringList list = KGlobal::dirs()->findAllResources( "wallpaper" );
00097
00098 for( QStringList::ConstIterator it = list.begin(); it != list.end(); it++ )
00099 wallCB->insertItem( ( (*it).at(0)=='/' ) ?
00100 KURL( *it ).fileName() :
00101 *it );
00102
00103 QPushButton* browsePB = new QPushButton( i18n("&Browse..."), this );
00104 QWhatsThis::add( browsePB, i18n( "Click this button to select a background "
00105 "image not yet present in the list above. " ) );
00106 center->addWidget( browsePB );
00107 connect( browsePB, SIGNAL( clicked() ), SLOT( slotBrowse() ) );
00108
00109 wallWidget = new QWidget( this );
00110 QWhatsThis::add( wallWidget, i18n( "This area will always display the "
00111 "currently selected background image. "
00112 "Note that the image will be scaled and "
00113 "thus might have a different ratio than "
00114 "it originally had." ) );
00115 center->addWidget( wallWidget );
00116
00117 connect( wallCB, SIGNAL( activated( int ) ),
00118 this, SLOT( slotWallPaperChanged( int ) ) );
00119
00120 right = new QVGroupBox( i18n( "Wallpaper Configuration" ), this );
00121 QWhatsThis::add( right, i18n( "In this box, you can set various settings "
00122 "that control how the background image is "
00123 "displayed." ) );
00124 toplevel->addWidget( right );
00125
00126 QHBox* intensityHB = new QHBox( right );
00127 intensityHB->setSpacing( 10 );
00128 QLabel* intensityLA = new QLabel(
00129
00130 i18n( "&Intensity in %:" ), intensityHB );
00131 intensitySB = new QSpinBox( 1, 100, 1, intensityHB );
00132 intensityLA->setBuddy( intensitySB );
00133
00134 QString ttstr = i18n( "Here you can select how much the image should be "
00135 "brightened up so that it does not disturb the "
00136 "selected area too much.<br> Different images require "
00137 "different settings, but 25% is a good value to start "
00138 "with." );
00139 QWhatsThis::add( intensityLA, ttstr );
00140 QWhatsThis::add( intensitySB, ttstr );
00141
00142
00143 stretchedRB = new QRadioButton( i18n( "Stretched" ), right );
00144 QWhatsThis::add( stretchedRB,
00145 i18n( "If you check this box, the selected image will "
00146 "be scaled to fit the total size of the selected "
00147 "area. Image ratio will be adjusted to match "
00148 "the area size and height if necessary." ) );
00149 stretchedRB->setChecked( true );
00150 scaledRB = new QRadioButton( i18n( "Scaled" ), right );
00151 QWhatsThis::add( scaledRB,
00152 i18n( "If you check this box, the selected image will "
00153 "be scaled to match the height or width of the "
00154 "selected area - whichever is reached first." ) );
00155 centeredRB = new QRadioButton( i18n( "Centered" ), right );
00156 QWhatsThis::add( centeredRB,
00157 i18n( "If you check this box, the selected image will "
00158 "be centered over the selected area. If the image "
00159 "is larger then the area, you will only see the "
00160 "middle part of it." ) );
00161
00162
00163
00164
00165
00166
00167
00168 QButtonGroup* alignmentBG;
00169 alignmentBG = new QButtonGroup( right, "GroupBox_Alignment" );
00170 alignmentBG->setFrameStyle( QFrame::NoFrame );
00171 alignmentBG->insert( stretchedRB );
00172 alignmentBG->insert( scaledRB );
00173 alignmentBG->insert( centeredRB );
00174
00175
00176 intensitySB->hide();
00177 }
00178
00179
00180
00181 void KChartBackgroundPixmapConfigPage::init()
00182 {
00183 #if 0
00184 QStringList lst;
00185 lst.append(i18n( "Outermost Region" ));
00186 lst.append(i18n( "Innermost Region" ));
00187 lst.append(i18n( "Header+Title+Subtitle" ));
00188 lst.append(i18n( "Footers" ));
00189 lst.append(i18n( "Data+Axes+Legend" ));
00190 lst.append(i18n( "Data+Axes" ));
00191 lst.append(i18n( "Data" ));
00192 lst.append(i18n( "Legend" ));
00193 lst.append(i18n( "Left Axis" ));
00194 lst.append(i18n( "Bottom Axis" ));
00195 lst.append(i18n( "Right Axis" ));
00196 lst.append(i18n( "Header A" ));
00197 lst.append(i18n( "Header B" ));
00198 lst.append(i18n( "Header C" ));
00199 lst.append(i18n( "Title A" ));
00200 lst.append(i18n( "Title B" ));
00201 lst.append(i18n( "Title C" ));
00202 lst.append(i18n( "Subtitle A" ));
00203 lst.append(i18n( "Subtitle B" ));
00204 lst.append(i18n( "Subtitle C" ));
00205 lst.append(i18n( "Footer 1 A" ));
00206 lst.append(i18n( "Footer 1 B" ));
00207 lst.append(i18n( "Footer 1 C" ));
00208 lst.append(i18n( "Footer 2 A" ));
00209 lst.append(i18n( "Footer 2 B" ));
00210 lst.append(i18n( "Footer 2 C" ));
00211 lst.append(i18n( "Footer 3 A" ));
00212 lst.append(i18n( "Footer 3 B" ));
00213 lst.append(i18n( "Footer 3 C" ));
00214 regionList->insertStringList(lst);
00215 #endif
00216
00217
00218
00219
00220
00221
00222 bool bFound;
00223 const KDChartParams::KDChartFrameSettings * innerFrame =
00224 _params->frameSettings( KDChartEnums::AreaInnermost, bFound );
00225 if( bFound )
00226 {
00227 const QPixmap* backPixmap;
00228 KDFrame::BackPixmapMode backPixmapMode;
00229 const QBrush& background = innerFrame->frame().background( backPixmap, backPixmapMode );
00230 if( !backPixmap || backPixmap->isNull() )
00231 {
00232 _backgroundCB->setColor( background.color() );
00233 right->setEnabled( false );
00234 wallCB->setCurrentItem( 0 );
00235 }
00236 else
00237 {
00238 _backgroundCB->setEnabled( false );
00239 wallWidget->setPaletteBackgroundPixmap( *backPixmap );
00240 wallCB->setCurrentItem( 1 );
00241 }
00242
00243 if ( backPixmapMode == KDFrame::PixCentered )
00244 centeredRB->setChecked( true );
00245 else if ( backPixmapMode == KDFrame::PixScaled )
00246 scaledRB->setChecked( true );
00247 else
00248 stretchedRB->setChecked( true );
00249
00250
00251
00252 }
00253 else
00254 _backgroundCB->setColor(QColor(230, 222, 222) );
00255 }
00256
00257 void KChartBackgroundPixmapConfigPage::apply()
00258 {
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 const QColor backColor( _backgroundCB->color() );
00295
00296
00297
00298
00299 bool bFound;
00300 const KDChartParams::KDChartFrameSettings * innerFrame =
00301 _params->frameSettings( KDChartEnums::AreaInnermost, bFound );
00302 if( bFound )
00303 {
00304 KDFrame& frame( (KDFrame&)innerFrame->frame() );
00305 if ( wallCB->currentItem() == 0 )
00306 {
00307 frame.setBackPixmap( 0 );
00308 frame.setBackground( _backgroundCB->color() );
00309 }
00310 else
00311 {
00312 KDFrame::BackPixmapMode backPixmapMode;
00313 if ( centeredRB->isChecked() )
00314 backPixmapMode = KDFrame::PixScaled;
00315 else if ( scaledRB->isChecked() )
00316 backPixmapMode = KDFrame::PixCentered;
00317 else
00318 backPixmapMode = KDFrame::PixStretched;
00319 frame.setBackPixmap( wallWidget->paletteBackgroundPixmap(), backPixmapMode );
00320 }
00321 }
00322 }
00323
00324
00325 void KChartBackgroundPixmapConfigPage::showSettings( const QString& fileName )
00326 {
00327 for( int i = 1; i < wallCB->count(); i++ )
00328 {
00329 if( fileName == wallCB->text( i ) )
00330 {
00331 wallCB->setCurrentItem( i );
00332 loadWallPaper();
00333 return;
00334 }
00335 }
00336
00337 if( !fileName.isEmpty() )
00338 {
00339 wallCB->insertItem( fileName );
00340 wallCB->setCurrentItem( wallCB->count()-1 );
00341 }
00342 else
00343 wallCB->setCurrentItem( 0 );
00344
00345 loadWallPaper();
00346 }
00347
00348
00349 void KChartBackgroundPixmapConfigPage::slotBrowse()
00350 {
00351
00352 KURL url = KFileDialog::getOpenFileName( 0 );
00353 if( url.isEmpty() )
00354 return;
00355 showSettings( url.path() );
00356 }
00357
00358 void KChartBackgroundPixmapConfigPage::slotWallPaperChanged( int index )
00359 {
00360 if ( index != 0 && loadWallPaper() )
00361 {
00362 _backgroundCB->setEnabled( false );
00363 right->setEnabled( true );
00364 }
00365 else
00366 {
00367 wallWidget->setPaletteBackgroundPixmap( 0 );
00368 _backgroundCB->setEnabled( true );
00369 right->setEnabled( false );
00370 }
00371 }
00372
00373
00374 bool KChartBackgroundPixmapConfigPage::loadWallPaper()
00375 {
00376 int i = wallCB->currentItem();
00377 if ( i == -1 || i == 0 ) {
00378 wallPixmap.resize(0,0);
00379 wallFile = "";
00380 } else {
00381 wallFile = wallCB->text( i );
00382 QString file = locate("wallpaper", wallFile);
00383 if( file.isEmpty() ) {
00384 kdWarning(35001) << "Couldn't locate wallpaper " << wallFile << endl;
00385 wallPixmap.resize(0,0);
00386 wallFile = "";
00387 return false;
00388 } else {
00389 wallPixmap.load( file );
00390
00391 if( wallPixmap.isNull() )
00392 return false;
00393
00394 }
00395 }
00396 wallWidget->setPaletteBackgroundPixmap( wallPixmap );
00397 return true;
00398 }
00399
00400 }