20#include "kchartBackgroundPixmapConfigPage.h"
21#include "kchartBackgroundPixmapConfigPage.moc"
25#include <kstandarddirs.h>
26#include <tdefiledialog.h>
27#include <tdemessagebox.h>
29#include <tdefilemetainfo.h>
30#include <kstringhandler.h>
32#include <tqcombobox.h>
33#include <tqradiobutton.h>
34#include <tqbuttongroup.h>
38#include <tqpushbutton.h>
40#include <tqwhatsthis.h>
42#include <kcolorbutton.h>
44#include "kchart_params.h"
49KChartBackgroundPixmapConfigPage::KChartBackgroundPixmapConfigPage( KChartParams* params, TQWidget* parent )
50 : TQWidget( parent,
"KChartBackgroundPixmapConfigPage" ),
53 TQWhatsThis::add(
this,
54 i18n(
"On this page, you can select colors or images "
55 "to be displayed behind the different areas. You "
56 "can also select whether the images should be "
57 "stretched or scaled or centered or used as "
58 "background tiles." ) );
60 TQHBoxLayout* toplevel =
new TQHBoxLayout(
this, 10 );
63 TQVBoxLayout* left=
new TQVBoxLayout(10);
64 toplevel->addLayout(left,2);
65 regionList=
new TQListBox(
this);
66 left->addWidget(regionList);
69 TQVBoxLayout* center =
new TQVBoxLayout( 10 );
70 toplevel->addLayout( center, 2 );
73 TQLabel* backgroundLA =
new TQLabel( i18n(
"&Background color:" ),
this );
74 center->addWidget( backgroundLA );
75 _backgroundCB =
new KColorButton(
this );
76 backgroundLA->setBuddy( _backgroundCB );
77 center->addWidget( _backgroundCB);
78 TQString wtstr = i18n(
"Here you set the color in which the background "
79 "of the chart is painted." );
80 TQWhatsThis::add( backgroundLA, wtstr );
81 TQWhatsThis::add( _backgroundCB, wtstr );
84 TQLabel* wallpaperLA =
new TQLabel( i18n(
"Background wallpaper:" ),
this );
85 center->addWidget( wallpaperLA );
87 wallCB =
new TQComboBox(
false,
this,
"wallCombo" );
88 wallpaperLA->setBuddy(wallCB);
89 TQWhatsThis::add( wallCB, i18n(
"You can select a background image from "
90 "this list. Initially, the installed TDE "
91 "wallpapers will be offered. If you do not "
92 "find what you are looking for here, you can "
93 "select any image file by clicking on the "
94 "<i>Browse</i> button below." ) );
95 center->addWidget( wallCB );
96 wallCB->insertItem( i18n(
"None") );
98 loadWallpaperFilesList();
99 TQPushButton* browsePB =
new TQPushButton( i18n(
"&Browse..."),
this );
100 TQWhatsThis::add( browsePB, i18n(
"Click this button to select a background "
101 "image not yet present in the list above. " ) );
102 center->addWidget( browsePB );
103 connect( browsePB, TQ_SIGNAL( clicked() ), TQ_SLOT( slotBrowse() ) );
105 wallWidget =
new TQWidget(
this );
106 TQWhatsThis::add( wallWidget, i18n(
"This area will always display the "
107 "currently selected background image. "
108 "Note that the image will be scaled and "
109 "thus might have a different ratio than "
110 "it originally had." ) );
111 center->addWidget( wallWidget );
113 connect( wallCB, TQ_SIGNAL( activated(
int ) ),
114 this, TQ_SLOT( slotWallPaperChanged(
int ) ) );
116 right =
new TQVGroupBox( i18n(
"Wallpaper Configuration" ),
this );
117 TQWhatsThis::add( right, i18n(
"In this box, you can set various settings "
118 "that control how the background image is "
120 toplevel->addWidget( right );
122 TQHBox* intensityHB =
new TQHBox( right );
123 intensityHB->setSpacing( 10 );
124 TQLabel* intensityLA =
new TQLabel(
126 i18n(
"&Intensity in %:" ), intensityHB );
127 intensitySB =
new TQSpinBox( 1, 100, 1, intensityHB );
128 intensityLA->setBuddy( intensitySB );
130 TQString ttstr = i18n(
"Here you can select how much the image should be "
131 "brightened up so that it does not disturb the "
132 "selected area too much.<br> Different images require "
133 "different settings, but 25% is a good value to start "
135 TQWhatsThis::add( intensityLA, ttstr );
136 TQWhatsThis::add( intensitySB, ttstr );
139 stretchedRB =
new TQRadioButton( i18n(
"Stretched" ), right );
140 TQWhatsThis::add( stretchedRB,
141 i18n(
"If you check this box, the selected image will "
142 "be scaled to fit the total size of the selected "
143 "area. Image ratio will be adjusted to match "
144 "the area size and height if necessary." ) );
145 stretchedRB->setChecked(
true );
146 scaledRB =
new TQRadioButton( i18n(
"Scaled" ), right );
147 TQWhatsThis::add( scaledRB,
148 i18n(
"If you check this box, the selected image will "
149 "be scaled to match the height or width of the "
150 "selected area - whichever is reached first." ) );
151 centeredRB =
new TQRadioButton( i18n(
"Centered" ), right );
152 TQWhatsThis::add( centeredRB,
153 i18n(
"If you check this box, the selected image will "
154 "be centered over the selected area. If the image "
155 "is larger then the area, you will only see the "
156 "middle part of it." ) );
158 tiledRB =
new TQRadioButton( i18n(
"Tiled" ), right );
159 TQWhatsThis::add( tiledRB,
160 i18n(
"If you check this box, the selected image will "
161 "be used as a background tile. If the image is "
162 "larger then the selected area, you will only see "
163 "the upper left part of it." ) );
164 TQButtonGroup* alignmentBG;
165 alignmentBG =
new TQButtonGroup( right,
"GroupBox_Alignment" );
166 alignmentBG->setFrameStyle( TQFrame::NoFrame );
167 alignmentBG->insert( stretchedRB );
168 alignmentBG->insert( scaledRB );
169 alignmentBG->insert( centeredRB );
170 alignmentBG->insert( tiledRB );
176void KChartBackgroundPixmapConfigPage::loadWallpaperFilesList()
181 TQMap<TQString, TQPair<TQString, TQString> > papers;
184 TQStringList lst = TDEGlobal::dirs()->findAllResources(
"wallpaper",
"*desktop",
false,
true);
186 for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
188 KSimpleConfig fileConfig(*it);
189 fileConfig.setGroup(
"Wallpaper");
191 TQString imageCaption = fileConfig.readEntry(
"Name");
192 TQString fileName = fileConfig.readEntry(
"File");
194 if (imageCaption.isEmpty())
196 imageCaption = fileName;
197 imageCaption.replace(
'_',
' ');
198 imageCaption = KStringHandler::capwords(imageCaption);
202 TQString rs = imageCaption;
203 TQString lrs = rs.lower();
204 for (
int n = 1; papers.find(lrs) != papers.end(); ++n)
206 rs = imageCaption +
" (" + TQString::number(n) +
')';
209 int slash = (*it).findRev(
'/') + 1;
210 TQString directory = (*it).left(slash);
211 bool canLoadScaleable =
false;
213 canLoadScaleable =
true;
215 if ( fileConfig.readEntry(
"ImageType") ==
"pixmap" || canLoadScaleable ) {
216 papers[lrs] = qMakePair(rs, directory + fileName);
217 files.append(directory + fileName);
222 lst = TDEGlobal::dirs()->findAllResources(
"wallpaper",
"*",
false,
true);
223 for (TQStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
225 if ( !(*it).endsWith(
".desktop") && files.grep(*it).empty() ) {
228 KFileMetaInfo metaInfo(*it);
229 TQString imageCaption;
231 if (metaInfo.isValid() && metaInfo.item(
"Comment").isValid())
232 imageCaption = metaInfo.item(
"Comment").string().section(
'\n', 0, 0);
234 if (imageCaption.isEmpty())
236 int slash = (*it).findRev(
'/') + 1;
237 int endDot = (*it).findRev(
'.');
240 if (endDot != -1 && endDot > slash)
241 imageCaption = (*it).mid(slash, endDot - slash);
243 imageCaption = (*it).mid(slash);
245 imageCaption.replace(
'_',
' ');
246 imageCaption = KStringHandler::capwords(imageCaption);
250 TQString rs = imageCaption;
251 TQString lrs = rs.lower();
252 for (
int n = 1; papers.find(lrs) != papers.end(); ++n)
254 rs = imageCaption +
" (" + TQString::number(n) +
')';
257 papers[lrs] = qMakePair(rs, *it);
264 for (TQMap<TQString, TQPair<TQString, TQString> >::Iterator it = papers.begin();
268 wallCB->insertItem(it.data().first);
269 m_wallpaper[it.data().second] = i;
274void KChartBackgroundPixmapConfigPage::init()
278 lst.append(i18n(
"Outermost Region" ));
279 lst.append(i18n(
"Innermost Region" ));
280 lst.append(i18n(
"Header+Title+Subtitle" ));
281 lst.append(i18n(
"Footers" ));
282 lst.append(i18n(
"Data+Axes+Legend" ));
283 lst.append(i18n(
"Data+Axes" ));
284 lst.append(i18n(
"Data" ));
285 lst.append(i18n(
"Legend" ));
286 lst.append(i18n(
"Left Axis" ));
287 lst.append(i18n(
"Bottom Axis" ));
288 lst.append(i18n(
"Right Axis" ));
289 lst.append(i18n(
"Header A" ));
290 lst.append(i18n(
"Header B" ));
291 lst.append(i18n(
"Header C" ));
292 lst.append(i18n(
"Title A" ));
293 lst.append(i18n(
"Title B" ));
294 lst.append(i18n(
"Title C" ));
295 lst.append(i18n(
"Subtitle A" ));
296 lst.append(i18n(
"Subtitle B" ));
297 lst.append(i18n(
"Subtitle C" ));
298 lst.append(i18n(
"Footer 1 A" ));
299 lst.append(i18n(
"Footer 1 B" ));
300 lst.append(i18n(
"Footer 1 C" ));
301 lst.append(i18n(
"Footer 2 A" ));
302 lst.append(i18n(
"Footer 2 B" ));
303 lst.append(i18n(
"Footer 2 C" ));
304 lst.append(i18n(
"Footer 3 A" ));
305 lst.append(i18n(
"Footer 3 B" ));
306 lst.append(i18n(
"Footer 3 C" ));
307 regionList->insertStringList(lst);
317 _params->frameSettings( KDChartEnums::AreaInnermost, bFound );
320 const TQPixmap* backPixmap;
321 bool isTiledMode =
false;
323 const TQBrush& background = innerFrame->
frame().
background( backPixmap, backPixmapMode );
324 const TQColor backColor( background.color() );
328 _backgroundCB->setColor( backColor );
331 if( !backPixmap || backPixmap->isNull() )
334 backPixmap = background.pixmap();
339 if( !backPixmap || backPixmap->isNull() )
341 right->setEnabled(
false );
342 wallCB->setCurrentItem( 0 );
346 _backgroundCB->setEnabled(
false );
347 wallWidget->setPaletteBackgroundPixmap( *backPixmap );
348 wallCB->setCurrentItem( 1 );
351 tiledRB->setChecked(
true );
355 switch( backPixmapMode ){
356 case KDFrame::PixCentered:
357 centeredRB->setChecked(
true );
359 case KDFrame::PixScaled:
360 scaledRB->setChecked(
true );
363 stretchedRB->setChecked(
true );
369 _backgroundCB->setColor(TQColor(230, 222, 222) );
372void KChartBackgroundPixmapConfigPage::apply()
415 _params->frameSettings( KDChartEnums::AreaInnermost, bFound );
418 const TQColor backColor( _backgroundCB->color() );
420 if ( wallCB->currentItem() == 0 )
422 frame.setBackPixmap( 0 );
423 frame.setBackground( backColor );
427 const TQPixmap* pixmap = wallWidget->paletteBackgroundPixmap();
428 if ( tiledRB->isChecked() ){
430 frame.setBackPixmap( 0 );
433 frame.setBackground( TQBrush( backColor, *pixmap ) );
435 frame.setBackground( backColor );
438 if ( centeredRB->isChecked() )
439 backPixmapMode = KDFrame::PixCentered;
440 else if ( scaledRB->isChecked() )
441 backPixmapMode = KDFrame::PixScaled;
443 backPixmapMode = KDFrame::PixStretched;
445 frame.setBackground( backColor );
447 frame.setBackPixmap( pixmap, backPixmapMode );
454void KChartBackgroundPixmapConfigPage::showSettings(
const TQString& fileName )
456 wallCB->blockSignals(
true);
458 if (m_wallpaper.find(fileName) == m_wallpaper.end())
460 int i = wallCB->count();
461 TQString imageCaption;
462 int slash = fileName.findRev(
'/') + 1;
463 int endDot = fileName.findRev(
'.');
466 if (endDot != -1 && endDot > slash)
467 imageCaption = fileName.mid(slash, endDot - slash);
469 imageCaption = fileName.mid(slash);
470 if (wallCB->text(i-1) == imageCaption)
473 wallCB->removeItem(i);
475 wallCB->insertItem(imageCaption);
476 m_wallpaper[fileName] = i;
477 wallCB->setCurrentItem(i);
481 wallCB->setCurrentItem(m_wallpaper[fileName]);
483 wallCB->blockSignals(
false);
488void KChartBackgroundPixmapConfigPage::slotBrowse()
491 KURL url = KFileDialog::getOpenFileName( 0 );
494 showSettings( url.path() );
497void KChartBackgroundPixmapConfigPage::slotWallPaperChanged(
int index )
499 if ( index != 0 && loadWallPaper() )
501 _backgroundCB->setEnabled(
false );
502 right->setEnabled(
true );
506 wallWidget->setPaletteBackgroundPixmap( 0 );
507 _backgroundCB->setEnabled(
true );
508 right->setEnabled(
false );
513bool KChartBackgroundPixmapConfigPage::loadWallPaper()
515 int i = wallCB->currentItem();
516 if ( i == -1 || i == 0 ) {
517 wallPixmap.resize(0,0);
520 for(TQMap<TQString,int>::ConstIterator it = m_wallpaper.begin();
521 it != m_wallpaper.end();
530 TQString file = locate(
"wallpaper", wallFile);
531 if( file.isEmpty() ) {
532 kdWarning(35001) <<
"Couldn't locate wallpaper " << wallFile << endl;
533 wallPixmap.resize(0,0);
537 wallPixmap.load( file );
539 if( wallPixmap.isNull() )
544 wallWidget->setPaletteBackgroundPixmap( wallPixmap );
Stores the frame settings for one of the chart areas:
const KDFrame & frame() const
Return the KDFrame object used for drawing this areas frame.
The main class of KDFrame.
BackPixmapMode
These are ways how to display a pixmap that might be painted into the inner area.
const TQBrush & background(const TQPixmap *&backPixmap, BackPixmapMode &backPixmapMode) const
Returns the brush that is used to fill the inner area of this frame, or a TQBrush( \cNoBrush ) if no ...