• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_bgnddlg.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3  Copyright (c) 1999 David Faure <faure@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include <tqbuttongroup.h>
22 #include <tqlabel.h>
23 #include <tqlayout.h>
24 #include <tqradiobutton.h>
25 
26 #include <kcolorbutton.h>
27 #include <kcombobox.h>
28 #include <kdebug.h>
29 #include <kimagefilepreview.h>
30 #include <tdelocale.h>
31 //#include <tderecentdocument.h>
32 #include <kstandarddirs.h>
33 #include <kurlrequester.h>
34 
35 #include "konq_bgnddlg.h"
36 
37 
38 KonqBgndDialog::KonqBgndDialog( TQWidget* parent,
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 )
44 {
45  TQWidget* page = new TQWidget( this );
46  setMainWidget( page );
47  TQVBoxLayout* mainLayout = new TQVBoxLayout( page, 0, KDialog::spacingHint() );
48 
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 );
56 
57  connect( m_buttonGroup, TQ_SIGNAL( clicked(int) ),
58  this, TQ_SLOT( slotBackgroundModeChanged() ) );
59 
60  // color
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 );
67 
68  connect( m_buttonColor, TQ_SIGNAL( changed( const TQColor& ) ),
69  this, TQ_SLOT( slotColorChanged() ) );
70 
71  // picture
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 );
76  initPictures();
77 
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() ) );
82 
83  TQSpacerItem* spacer1 = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding,
84  TQSizePolicy::Minimum );
85  groupLayout->addItem( spacer1, 0, 2 );
86 
87  // preview title
88  TQHBoxLayout* hlay = new TQHBoxLayout( mainLayout, KDialog::spacingHint() );
89  //mainLayout->addLayout( hlay );
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 );
97 
98  // preview 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 );
105 
106  if ( !pixmapFile.isEmpty() ) {
107  loadPicture( pixmapFile );
108  m_buttonColor->setColor( defaultColor );
109  m_radioPicture->setChecked( true );
110  }
111  else {
112  m_buttonColor->setColor( theColor );
113  m_comboPicture->comboBox()->setCurrentItem( 0 );
114  m_radioColor->setChecked( true );
115  }
116  slotBackgroundModeChanged();
117 }
118 
119 KonqBgndDialog::~KonqBgndDialog()
120 {
121 }
122 
123 TQColor KonqBgndDialog::color() const
124 {
125  if ( m_radioColor->isChecked() )
126  return m_buttonColor->color();
127 
128  return TQColor();
129 }
130 
131 void KonqBgndDialog::initPictures()
132 {
133  TDEGlobal::dirs()->addResourceType( "tiles",
134  TDEGlobal::dirs()->kde_default("data") + "konqueror/tiles/");
135  kdDebug(1203) << TDEGlobal::dirs()->kde_default("data") + "konqueror/tiles/" << endl;
136 
137  TQStringList list = TDEGlobal::dirs()->findAllResources("tiles");
138 
139  if ( list.isEmpty() )
140  m_comboPicture->comboBox()->insertItem( i18n("None") );
141  else {
142  TQStringList::ConstIterator it;
143  for ( it = list.begin(); it != list.end(); it++ )
144  m_comboPicture->comboBox()->insertItem(
145  ( (*it).at(0) == '/' ) ? // if absolute path
146  KURL( *it ).fileName() : // then only fileName
147  *it );
148  }
149 }
150 
151 void KonqBgndDialog::loadPicture( const TQString& fileName )
152 {
153  int i ;
154  for ( i = 0; i < m_comboPicture->comboBox()->count(); i++ ) {
155  if ( fileName == m_comboPicture->comboBox()->text( i ) ) {
156  m_comboPicture->comboBox()->setCurrentItem( i );
157  return;
158  }
159  }
160 
161  if ( !fileName.isEmpty() ) {
162  m_comboPicture->comboBox()->insertItem( fileName );
163  m_comboPicture->comboBox()->setCurrentItem( i );
164  }
165  else
166  m_comboPicture->comboBox()->setCurrentItem( 0 );
167 }
168 
169 void KonqBgndDialog::slotPictureChanged()
170 {
171  m_pixmapFile = m_comboPicture->comboBox()->currentText();
172  TQString file = locate( "tiles", m_pixmapFile );
173  if ( file.isEmpty() )
174  file = locate("wallpaper", m_pixmapFile); // add fallback for compatibility
175  if ( file.isEmpty() ) {
176  kdWarning(1203) << "Couldn't locate wallpaper " << m_pixmapFile << endl;
177  m_preview->unsetPalette();
178  m_pixmap = TQPixmap();
179  m_pixmapFile = "";
180  }
181  else {
182  m_pixmap.load( file );
183 
184  if ( m_pixmap.isNull() )
185  kdWarning(1203) << "Could not load wallpaper " << file << endl;
186  }
187  m_preview->setPaletteBackgroundPixmap( m_pixmap );
188 }
189 
190 void KonqBgndDialog::slotColorChanged()
191 {
192  m_preview->setPaletteBackgroundColor( m_buttonColor->color() );
193 }
194 
195 void KonqBgndDialog::slotBackgroundModeChanged()
196 {
197  if ( m_radioColor->isChecked() ) {
198  m_buttonColor->setEnabled( true );
199  m_comboPicture->setEnabled( false );
200  m_pixmapFile = "";
201  slotColorChanged();
202  }
203  else { // m_comboPicture->isChecked() == true
204  m_comboPicture->setEnabled( true );
205  m_buttonColor->setEnabled( false );
206  slotPictureChanged();
207  }
208 }
209 
210 
211 #include "konq_bgnddlg.moc"
KonqBgndDialog::KonqBgndDialog
KonqBgndDialog(TQWidget *parent, const TQString &pixmapFile, const TQColor &theColor, const TQColor &defaultColor)
Constructor.
Definition: konq_bgnddlg.cpp:38

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.9.1
This website is maintained by Timothy Pearson.