libkonq Library API Documentation

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., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <qcombobox.h>
00022 #include <qpushbutton.h>
00023 #include <qlayout.h>
00024 
00025 #include <kfiledialog.h>
00026 #include <klocale.h>
00027 #include <kmessagebox.h>
00028 #include <kstandarddirs.h>
00029 #include <kdebug.h>
00030 #include <kimagefilepreview.h>
00031 #include <krecentdocument.h>
00032 
00033 #include "konq_bgnddlg.h"
00034 
00035 
00036 KonqBgndDialog::KonqBgndDialog( const QString & pixmapFile,
00037                 KInstance *instance )
00038   : KDialogBase( Plain,
00039          i18n("Select Background Image"),
00040                  Ok|Cancel,
00041                  Ok,
00042          0L, // no parent,
00043                  "KonqBgndDialog",
00044                  true, //modal
00045                  false, // no separator
00046                  i18n( "Set as default" )
00047     )
00048 {
00049     KGlobal::dirs()->addResourceType("tiles",
00050                                      KGlobal::dirs()->kde_default("data") + "konqueror/tiles/");
00051     kdDebug(1203) << KGlobal::dirs()->kde_default("data") + "konqueror/tiles/" << endl;
00052     QFrame *page = plainPage();
00053     QLayout *layout = new QVBoxLayout( page );
00054     layout->setAutoAdd( true );
00055     m_propsPage = new KBgndDialogPage( page, pixmapFile, instance, "tiles" );
00056 }
00057 
00058 KonqBgndDialog::~KonqBgndDialog()
00059 {
00060 }
00061 
00062 KBgndDialogPage::KBgndDialogPage( QWidget * parent, const QString & pixmapFile,
00063                   KInstance *instance, const char * resource )
00064   : QGroupBox( parent, "KBgndDialogPage" ),
00065     m_resource( resource )
00066 {
00067     setTitle( i18n("Background") );
00068     m_instance = instance;
00069 
00070     m_wallBox = new QComboBox( false, this, "ComboBox_1" );
00071     m_wallBox->insertItem( i18n("None") );
00072 
00073     QStringList list = KGlobal::dirs()->findAllResources(resource);
00074 
00075     for (QStringList::ConstIterator it = list.begin(); it != list.end(); it++)
00076         m_wallBox->insertItem( ( (*it).at(0)=='/' ) ?    // if absolute path
00077                    KURL( *it ).fileName() :  // then only fileName
00078                    *it );
00079 
00080     m_wallBox->adjustSize();
00081 
00082     m_browseButton = new QPushButton( i18n("&Browse..."), this );
00083     m_browseButton->adjustSize();
00084     connect( m_browseButton, SIGNAL( clicked() ), SLOT( slotBrowse() ) );
00085 
00086     m_wallWidget = new QFrame( this );
00087     m_wallWidget->setLineWidth( 2 );
00088     m_wallWidget->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
00089 
00090     showSettings( pixmapFile );
00091 
00092     connect( m_wallBox, SIGNAL( activated( int ) ),
00093          this, SLOT( slotWallPaperChanged( int ) ) );
00094 
00095     setMinimumSize( QSize( 400, 300 ) );
00096 }
00097 
00098 KBgndDialogPage::~KBgndDialogPage()
00099 {
00100 }
00101 
00102 void KBgndDialogPage::showSettings( const QString& fileName )
00103 {
00104   for ( int i = 1; i < m_wallBox->count(); i++ )
00105     {
00106       if ( fileName == m_wallBox->text( i ) )
00107         {
00108           m_wallBox->setCurrentItem( i );
00109           loadWallPaper();
00110           return;
00111         }
00112     }
00113 
00114   if ( !fileName.isEmpty() )
00115     {
00116       m_wallBox->insertItem( fileName );
00117       m_wallBox->setCurrentItem( m_wallBox->count()-1 );
00118       m_wallBox->adjustSize();
00119     }
00120   else m_wallBox->setCurrentItem( 0 );
00121 
00122   loadWallPaper();
00123 }
00124 
00125 void KBgndDialogPage::slotBrowse( )
00126 {
00127     KURL url = KFileDialog::getImageOpenURL( QString::null, this, 
00128                                              i18n("Select Image" ) );
00129 
00130     if (!url.isValid())
00131       return;
00132 
00133     if (!url.isLocalFile()) {
00134       KMessageBox::sorry(this, i18n("Currently only local wallpapers are allowed."));
00135     } else
00136       showSettings( url.path() );
00137 }
00138 
00139 void KBgndDialogPage::slotWallPaperChanged( int )
00140 {
00141     loadWallPaper();
00142 }
00143 
00144 void KBgndDialogPage::loadWallPaper()
00145 {
00146     int i = m_wallBox->currentItem();
00147     if ( i == -1 || i == 0 )  // 0 is 'None'
00148     {
00149         m_wallPixmap.resize(0,0);
00150         m_wallFile = "";
00151     }
00152     else
00153     {
00154         m_wallFile = m_wallBox->text( i );
00155         QString file = locate(m_resource.data(), m_wallFile);
00156         if ( file.isEmpty() && m_resource != "wallpaper") // add fallback for compatibility
00157             file = locate("wallpaper", m_wallFile);
00158         if ( file.isEmpty() )
00159         {
00160           kdWarning(1203) << "Couldn't locate wallpaper " << m_wallFile << endl;
00161           m_wallPixmap.resize(0,0);
00162           m_wallFile = "";
00163         }
00164         else
00165         {
00166           m_wallPixmap.load( file );
00167 
00168           if ( m_wallPixmap.isNull() )
00169               kdWarning(1203) << "Could not load wallpaper " << file << endl;
00170         }
00171     }
00172     m_wallWidget->setBackgroundPixmap( m_wallPixmap );
00173 }
00174 
00175 void KBgndDialogPage::resizeEvent ( QResizeEvent *e )
00176 {
00177     QGroupBox::resizeEvent( e );
00178     int fontHeight = fontMetrics().height();
00179     m_wallBox->move( KDialog::marginHint(), KDialog::marginHint() + fontHeight );
00180     int x = m_wallBox->x() + m_wallBox->width() + KDialog::spacingHint();
00181     int y = m_wallBox->y() + (m_wallBox->height() - m_browseButton->height()) / 2;
00182     m_browseButton->move( x, y );
00183 
00184     imageX = m_wallBox->x();
00185     imageY = m_browseButton->y()+m_browseButton->height()+KDialog::spacingHint(); // under the browse button
00186     imageW = width() - imageX - KDialog::marginHint();
00187     imageH = height() - imageY - KDialog::marginHint()*2;
00188 
00189     m_wallWidget->setGeometry( imageX, imageY, imageW, imageH );
00190 }
00191 
00192 #include "konq_bgnddlg.moc"
KDE Logo
This file is part of the documentation for libkonq Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Apr 29 21:20:28 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003