~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to libkonq/konq_bgnddlg.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-04-05 05:22:13 UTC
  • mfrom: (0.4.2 experimental) (0.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20090405052213-39thr4l6p2ss07uj
Tags: 4:4.2.2-1
* New upstream release:
  - khtml fixes. (Closes: #290285, #359680)
  - Default konsole sessions can be deleted. (Closes: #286342)
  - Tag widget uses standard application palette. (Closes: #444800)
  - ... and surely many more but we have lost track...

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <qbuttongroup.h>
22
 
#include <qlabel.h>
23
 
#include <qlayout.h>
24
 
#include <qradiobutton.h>
25
 
 
26
 
#include <kcolorbutton.h>
27
 
#include <kcombobox.h>
28
 
#include <kdebug.h>
29
 
#include <kimagefilepreview.h>
30
 
#include <klocale.h>
31
 
//#include <krecentdocument.h>
32
 
#include <kstandarddirs.h>
33
 
#include <kurlrequester.h>
34
 
 
35
 
#include "konq_bgnddlg.h"
36
 
 
37
 
 
38
 
KonqBgndDialog::KonqBgndDialog( QWidget* parent,
39
 
                                const QString& pixmapFile,
40
 
                                const QColor& theColor,
41
 
                                const QColor& defaultColor )
42
 
 : KDialogBase( parent, "KonqBgndDialog", false,
43
 
                i18n("Background Settings"), Ok|Cancel, Ok, true )
44
 
{
45
 
    QWidget* page = new QWidget( this );
46
 
    setMainWidget( page );
47
 
    QVBoxLayout* mainLayout = new QVBoxLayout( page, 0, KDialog::spacingHint() );
48
 
 
49
 
    m_buttonGroup = new QButtonGroup( i18n("Background"), page );
50
 
    m_buttonGroup->setColumnLayout( 0, Qt::Vertical );
51
 
    m_buttonGroup->layout()->setMargin( KDialog::marginHint() );
52
 
    m_buttonGroup->layout()->setSpacing( KDialog::spacingHint() );
53
 
    QGridLayout* groupLayout = new QGridLayout( m_buttonGroup->layout() );
54
 
    groupLayout->setAlignment( Qt::AlignTop );
55
 
    mainLayout->addWidget( m_buttonGroup );
56
 
 
57
 
    connect( m_buttonGroup, SIGNAL( clicked(int) ),
58
 
             this, SLOT( slotBackgroundModeChanged() ) );
59
 
 
60
 
    // color
61
 
    m_radioColor = new QRadioButton( 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( QSizePolicy::Preferred,
65
 
                                QSizePolicy::Minimum );
66
 
    groupLayout->addWidget( m_buttonColor, 0, 1 );
67
 
 
68
 
    connect( m_buttonColor, SIGNAL( changed( const QColor& ) ),
69
 
             this, SLOT( slotColorChanged() ) );
70
 
 
71
 
    // picture
72
 
    m_radioPicture = new QRadioButton( 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(), SIGNAL( activated( int ) ),
79
 
             this, SLOT( slotPictureChanged() ) );
80
 
    connect( m_comboPicture, SIGNAL( urlSelected(const QString &) ),
81
 
             this, SLOT( slotPictureChanged() ) );
82
 
 
83
 
    QSpacerItem* spacer1 = new QSpacerItem( 0, 0, QSizePolicy::Expanding,
84
 
                                            QSizePolicy::Minimum );
85
 
    groupLayout->addItem( spacer1, 0, 2 );
86
 
 
87
 
    // preview title
88
 
    QHBoxLayout* hlay = new QHBoxLayout( mainLayout, KDialog::spacingHint() );
89
 
    //mainLayout->addLayout( hlay );
90
 
    QLabel* lbl = new QLabel( i18n("Preview"), page );
91
 
    hlay->addWidget( lbl );
92
 
    QFrame* frame = new QFrame( page );
93
 
    frame->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
94
 
    frame->setFrameShape( QFrame::HLine );
95
 
    frame->setFrameShadow( QFrame::Sunken );
96
 
    hlay->addWidget( frame );
97
 
 
98
 
    // preview frame
99
 
    m_preview = new QFrame( page );
100
 
    m_preview->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
101
 
    m_preview->setMinimumSize( 370, 180 );
102
 
    m_preview->setFrameShape( QFrame::Panel );
103
 
    m_preview->setFrameShadow( QFrame::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
 
QColor KonqBgndDialog::color() const
124
 
{
125
 
    if ( m_radioColor->isChecked() )
126
 
        return m_buttonColor->color();
127
 
 
128
 
    return QColor();
129
 
}
130
 
 
131
 
void KonqBgndDialog::initPictures()
132
 
{
133
 
    KGlobal::dirs()->addResourceType( "tiles",
134
 
        KGlobal::dirs()->kde_default("data") + "konqueror/tiles/");
135
 
    kdDebug(1203) << KGlobal::dirs()->kde_default("data") + "konqueror/tiles/" << endl;
136
 
 
137
 
    QStringList list = KGlobal::dirs()->findAllResources("tiles");
138
 
 
139
 
    if ( list.isEmpty() )
140
 
        m_comboPicture->comboBox()->insertItem( i18n("None") );
141
 
    else {
142
 
        QStringList::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 QString& 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
 
    QString 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 = QPixmap();
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"