konq_bgnddlg.cc
00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 00003 Copyright (c) 1999 David Faure <faure@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include <tqbuttongroup.h> 00022 #include <tqlabel.h> 00023 #include <tqlayout.h> 00024 #include <tqradiobutton.h> 00025 00026 #include <kcolorbutton.h> 00027 #include <kcombobox.h> 00028 #include <kdebug.h> 00029 #include <kimagefilepreview.h> 00030 #include <klocale.h> 00031 //#include <krecentdocument.h> 00032 #include <kstandarddirs.h> 00033 #include <kurlrequester.h> 00034 00035 #include "konq_bgnddlg.h" 00036 00037 00038 KonqBgndDialog::KonqBgndDialog( TQWidget* parent, 00039 const TQString& pixmapFile, 00040 const TQColor& theColor, 00041 const TQColor& defaultColor ) 00042 : KDialogBase( parent, "KonqBgndDialog", false, 00043 i18n("Background Settings"), Ok|Cancel, Ok, true ) 00044 { 00045 TQWidget* page = new TQWidget( this ); 00046 setMainWidget( page ); 00047 TQVBoxLayout* mainLayout = new TQVBoxLayout( page, 0, KDialog::spacingHint() ); 00048 00049 m_buttonGroup = new TQButtonGroup( i18n("Background"), page ); 00050 m_buttonGroup->setColumnLayout( 0, Qt::Vertical ); 00051 m_buttonGroup->layout()->setMargin( KDialog::marginHint() ); 00052 m_buttonGroup->layout()->setSpacing( KDialog::spacingHint() ); 00053 TQGridLayout* groupLayout = new TQGridLayout( m_buttonGroup->layout() ); 00054 groupLayout->setAlignment( Qt::AlignTop ); 00055 mainLayout->addWidget( m_buttonGroup ); 00056 00057 connect( m_buttonGroup, TQT_SIGNAL( clicked(int) ), 00058 this, TQT_SLOT( slotBackgroundModeChanged() ) ); 00059 00060 // color 00061 m_radioColor = new TQRadioButton( i18n("Co&lor:"), m_buttonGroup ); 00062 groupLayout->addWidget( m_radioColor, 0, 0 ); 00063 m_buttonColor = new KColorButton( theColor, defaultColor, m_buttonGroup ); 00064 m_buttonColor->setSizePolicy( TQSizePolicy::Preferred, 00065 TQSizePolicy::Minimum ); 00066 groupLayout->addWidget( m_buttonColor, 0, 1 ); 00067 00068 connect( m_buttonColor, TQT_SIGNAL( changed( const TQColor& ) ), 00069 this, TQT_SLOT( slotColorChanged() ) ); 00070 00071 // picture 00072 m_radioPicture = new TQRadioButton( i18n("&Picture:"), m_buttonGroup ); 00073 groupLayout->addWidget( m_radioPicture, 1, 0 ); 00074 m_comboPicture = new KURLComboRequester( m_buttonGroup ); 00075 groupLayout->addMultiCellWidget( m_comboPicture, 1, 1, 1, 2 ); 00076 initPictures(); 00077 00078 connect( m_comboPicture->comboBox(), TQT_SIGNAL( activated( int ) ), 00079 this, TQT_SLOT( slotPictureChanged() ) ); 00080 connect( m_comboPicture, TQT_SIGNAL( urlSelected(const TQString &) ), 00081 this, TQT_SLOT( slotPictureChanged() ) ); 00082 00083 TQSpacerItem* spacer1 = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, 00084 TQSizePolicy::Minimum ); 00085 groupLayout->addItem( spacer1, 0, 2 ); 00086 00087 // preview title 00088 TQHBoxLayout* hlay = new TQHBoxLayout( mainLayout, KDialog::spacingHint() ); 00089 //mainLayout->addLayout( hlay ); 00090 TQLabel* lbl = new TQLabel( i18n("Preview"), page ); 00091 hlay->addWidget( lbl ); 00092 TQFrame* frame = new TQFrame( page ); 00093 frame->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum ); 00094 frame->setFrameShape( TQFrame::HLine ); 00095 frame->setFrameShadow( TQFrame::Sunken ); 00096 hlay->addWidget( frame ); 00097 00098 // preview frame 00099 m_preview = new TQFrame( page ); 00100 m_preview->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ); 00101 m_preview->setMinimumSize( 370, 180 ); 00102 m_preview->setFrameShape( TQFrame::Panel ); 00103 m_preview->setFrameShadow( TQFrame::Raised ); 00104 mainLayout->addWidget( m_preview ); 00105 00106 if ( !pixmapFile.isEmpty() ) { 00107 loadPicture( pixmapFile ); 00108 m_buttonColor->setColor( defaultColor ); 00109 m_radioPicture->setChecked( true ); 00110 } 00111 else { 00112 m_buttonColor->setColor( theColor ); 00113 m_comboPicture->comboBox()->setCurrentItem( 0 ); 00114 m_radioColor->setChecked( true ); 00115 } 00116 slotBackgroundModeChanged(); 00117 } 00118 00119 KonqBgndDialog::~KonqBgndDialog() 00120 { 00121 } 00122 00123 TQColor KonqBgndDialog::color() const 00124 { 00125 if ( m_radioColor->isChecked() ) 00126 return m_buttonColor->color(); 00127 00128 return TQColor(); 00129 } 00130 00131 void KonqBgndDialog::initPictures() 00132 { 00133 KGlobal::dirs()->addResourceType( "tiles", 00134 KGlobal::dirs()->kde_default("data") + "konqueror/tiles/"); 00135 kdDebug(1203) << KGlobal::dirs()->kde_default("data") + "konqueror/tiles/" << endl; 00136 00137 TQStringList list = KGlobal::dirs()->findAllResources("tiles"); 00138 00139 if ( list.isEmpty() ) 00140 m_comboPicture->comboBox()->insertItem( i18n("None") ); 00141 else { 00142 TQStringList::ConstIterator it; 00143 for ( it = list.begin(); it != list.end(); it++ ) 00144 m_comboPicture->comboBox()->insertItem( 00145 ( (*it).at(0) == '/' ) ? // if absolute path 00146 KURL( *it ).fileName() : // then only fileName 00147 *it ); 00148 } 00149 } 00150 00151 void KonqBgndDialog::loadPicture( const TQString& fileName ) 00152 { 00153 int i ; 00154 for ( i = 0; i < m_comboPicture->comboBox()->count(); i++ ) { 00155 if ( fileName == m_comboPicture->comboBox()->text( i ) ) { 00156 m_comboPicture->comboBox()->setCurrentItem( i ); 00157 return; 00158 } 00159 } 00160 00161 if ( !fileName.isEmpty() ) { 00162 m_comboPicture->comboBox()->insertItem( fileName ); 00163 m_comboPicture->comboBox()->setCurrentItem( i ); 00164 } 00165 else 00166 m_comboPicture->comboBox()->setCurrentItem( 0 ); 00167 } 00168 00169 void KonqBgndDialog::slotPictureChanged() 00170 { 00171 m_pixmapFile = m_comboPicture->comboBox()->currentText(); 00172 TQString file = locate( "tiles", m_pixmapFile ); 00173 if ( file.isEmpty() ) 00174 file = locate("wallpaper", m_pixmapFile); // add fallback for compatibility 00175 if ( file.isEmpty() ) { 00176 kdWarning(1203) << "Couldn't locate wallpaper " << m_pixmapFile << endl; 00177 m_preview->unsetPalette(); 00178 m_pixmap = TQPixmap(); 00179 m_pixmapFile = ""; 00180 } 00181 else { 00182 m_pixmap.load( file ); 00183 00184 if ( m_pixmap.isNull() ) 00185 kdWarning(1203) << "Could not load wallpaper " << file << endl; 00186 } 00187 m_preview->setPaletteBackgroundPixmap( m_pixmap ); 00188 } 00189 00190 void KonqBgndDialog::slotColorChanged() 00191 { 00192 m_preview->setPaletteBackgroundColor( m_buttonColor->color() ); 00193 } 00194 00195 void KonqBgndDialog::slotBackgroundModeChanged() 00196 { 00197 if ( m_radioColor->isChecked() ) { 00198 m_buttonColor->setEnabled( true ); 00199 m_comboPicture->setEnabled( false ); 00200 m_pixmapFile = ""; 00201 slotColorChanged(); 00202 } 00203 else { // m_comboPicture->isChecked() == true 00204 m_comboPicture->setEnabled( true ); 00205 m_buttonColor->setEnabled( false ); 00206 slotPictureChanged(); 00207 } 00208 } 00209 00210 00211 #include "konq_bgnddlg.moc"