21 #include <tqbuttongroup.h>
24 #include <tqradiobutton.h>
26 #include <kcolorbutton.h>
27 #include <kcombobox.h>
29 #include <kimagefilepreview.h>
30 #include <tdelocale.h>
32 #include <kstandarddirs.h>
33 #include <kurlrequester.h>
35 #include "konq_bgnddlg.h"
39 const TQString& pixmapFile,
40 const TQColor& theColor,
41 const TQColor& defaultColor )
42 : KDialogBase( parent,
"KonqBgndDialog", false,
43 i18n(
"Background Settings"), Ok|Cancel, Ok, true )
45 TQWidget* page =
new TQWidget(
this );
46 setMainWidget( page );
47 TQVBoxLayout* mainLayout =
new TQVBoxLayout( page, 0, KDialog::spacingHint() );
49 m_buttonGroup =
new TQButtonGroup( i18n(
"Background"), page );
50 m_buttonGroup->setColumnLayout( 0, TQt::Vertical );
51 m_buttonGroup->layout()->setMargin( KDialog::marginHint() );
52 m_buttonGroup->layout()->setSpacing( KDialog::spacingHint() );
53 TQGridLayout* groupLayout =
new TQGridLayout( m_buttonGroup->layout() );
54 groupLayout->setAlignment( TQt::AlignTop );
55 mainLayout->addWidget( m_buttonGroup );
57 connect( m_buttonGroup, TQ_SIGNAL( clicked(
int) ),
58 this, TQ_SLOT( slotBackgroundModeChanged() ) );
61 m_radioColor =
new TQRadioButton( i18n(
"Co&lor:"), m_buttonGroup );
62 groupLayout->addWidget( m_radioColor, 0, 0 );
63 m_buttonColor =
new KColorButton( theColor, defaultColor, m_buttonGroup );
64 m_buttonColor->setSizePolicy( TQSizePolicy::Preferred,
65 TQSizePolicy::Minimum );
66 groupLayout->addWidget( m_buttonColor, 0, 1 );
68 connect( m_buttonColor, TQ_SIGNAL( changed(
const TQColor& ) ),
69 this, TQ_SLOT( slotColorChanged() ) );
72 m_radioPicture =
new TQRadioButton( i18n(
"&Picture:"), m_buttonGroup );
73 groupLayout->addWidget( m_radioPicture, 1, 0 );
74 m_comboPicture =
new KURLComboRequester( m_buttonGroup );
75 groupLayout->addMultiCellWidget( m_comboPicture, 1, 1, 1, 2 );
78 connect( m_comboPicture->comboBox(), TQ_SIGNAL( activated(
int ) ),
79 this, TQ_SLOT( slotPictureChanged() ) );
80 connect( m_comboPicture, TQ_SIGNAL( urlSelected(
const TQString &) ),
81 this, TQ_SLOT( slotPictureChanged() ) );
83 TQSpacerItem* spacer1 =
new TQSpacerItem( 0, 0, TQSizePolicy::Expanding,
84 TQSizePolicy::Minimum );
85 groupLayout->addItem( spacer1, 0, 2 );
88 TQHBoxLayout* hlay =
new TQHBoxLayout( mainLayout, KDialog::spacingHint() );
90 TQLabel* lbl =
new TQLabel( i18n(
"Preview"), page );
91 hlay->addWidget( lbl );
92 TQFrame* frame =
new TQFrame( page );
93 frame->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum );
94 frame->setFrameShape( TQFrame::HLine );
95 frame->setFrameShadow( TQFrame::Sunken );
96 hlay->addWidget( frame );
99 m_preview =
new TQFrame( page );
100 m_preview->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding );
101 m_preview->setMinimumSize( 370, 180 );
102 m_preview->setFrameShape( TQFrame::Panel );
103 m_preview->setFrameShadow( TQFrame::Raised );
104 mainLayout->addWidget( m_preview );
106 if ( !pixmapFile.isEmpty() ) {
107 loadPicture( pixmapFile );
108 m_buttonColor->setColor( defaultColor );
109 m_radioPicture->setChecked(
true );
112 m_buttonColor->setColor( theColor );
113 m_comboPicture->comboBox()->setCurrentItem( 0 );
114 m_radioColor->setChecked(
true );
116 slotBackgroundModeChanged();
119 KonqBgndDialog::~KonqBgndDialog()
123 TQColor KonqBgndDialog::color()
const
125 if ( m_radioColor->isChecked() )
126 return m_buttonColor->color();
131 void KonqBgndDialog::initPictures()
133 TDEGlobal::dirs()->addResourceType(
"tiles",
134 TDEGlobal::dirs()->kde_default(
"data") +
"konqueror/tiles/");
135 kdDebug(1203) << TDEGlobal::dirs()->kde_default(
"data") +
"konqueror/tiles/" << endl;
137 TQStringList list = TDEGlobal::dirs()->findAllResources(
"tiles");
139 if ( list.isEmpty() )
140 m_comboPicture->comboBox()->insertItem( i18n(
"None") );
142 TQStringList::ConstIterator it;
143 for ( it = list.begin(); it != list.end(); it++ )
144 m_comboPicture->comboBox()->insertItem(
145 ( (*it).at(0) ==
'/' ) ?
146 KURL( *it ).fileName() :
151 void KonqBgndDialog::loadPicture(
const TQString& fileName )
154 for ( i = 0; i < m_comboPicture->comboBox()->count(); i++ ) {
155 if ( fileName == m_comboPicture->comboBox()->text( i ) ) {
156 m_comboPicture->comboBox()->setCurrentItem( i );
161 if ( !fileName.isEmpty() ) {
162 m_comboPicture->comboBox()->insertItem( fileName );
163 m_comboPicture->comboBox()->setCurrentItem( i );
166 m_comboPicture->comboBox()->setCurrentItem( 0 );
169 void KonqBgndDialog::slotPictureChanged()
171 m_pixmapFile = m_comboPicture->comboBox()->currentText();
172 TQString file = locate(
"tiles", m_pixmapFile );
173 if ( file.isEmpty() )
174 file = locate(
"wallpaper", m_pixmapFile);
175 if ( file.isEmpty() ) {
176 kdWarning(1203) <<
"Couldn't locate wallpaper " << m_pixmapFile << endl;
177 m_preview->unsetPalette();
178 m_pixmap = TQPixmap();
182 m_pixmap.load( file );
184 if ( m_pixmap.isNull() )
185 kdWarning(1203) <<
"Could not load wallpaper " << file << endl;
187 m_preview->setPaletteBackgroundPixmap( m_pixmap );
190 void KonqBgndDialog::slotColorChanged()
192 m_preview->setPaletteBackgroundColor( m_buttonColor->color() );
195 void KonqBgndDialog::slotBackgroundModeChanged()
197 if ( m_radioColor->isChecked() ) {
198 m_buttonColor->setEnabled(
true );
199 m_comboPicture->setEnabled(
false );
204 m_comboPicture->setEnabled(
true );
205 m_buttonColor->setEnabled(
false );
206 slotPictureChanged();
211 #include "konq_bgnddlg.moc"
KonqBgndDialog(TQWidget *parent, const TQString &pixmapFile, const TQColor &theColor, const TQColor &defaultColor)
Constructor.