summaryrefslogtreecommitdiffstats
path: root/libkonq/konq_bgnddlg.cc
blob: 60f3aa63da2a9f559754c53987aa1597618cba07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
   Copyright (c) 1999 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include <tqbuttongroup.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqradiobutton.h>

#include <kcolorbutton.h>
#include <kcombobox.h>
#include <kdebug.h>
#include <kimagefilepreview.h>
#include <tdelocale.h>
//#include <tderecentdocument.h>
#include <kstandarddirs.h>
#include <kurlrequester.h>

#include "konq_bgnddlg.h"


KonqBgndDialog::KonqBgndDialog( TQWidget* parent,
                                const TQString& pixmapFile,
                                const TQColor& theColor,
                                const TQColor& defaultColor )
 : KDialogBase( parent, "KonqBgndDialog", false,
                i18n("Background Settings"), Ok|Cancel, Ok, true )
{
    TQWidget* page = new TQWidget( this );
    setMainWidget( page );
    TQVBoxLayout* mainLayout = new TQVBoxLayout( page, 0, KDialog::spacingHint() );

    m_buttonGroup = new TQButtonGroup( i18n("Background"), page );
    m_buttonGroup->setColumnLayout( 0, Qt::Vertical );
    m_buttonGroup->layout()->setMargin( KDialog::marginHint() );
    m_buttonGroup->layout()->setSpacing( KDialog::spacingHint() );
    TQGridLayout* groupLayout = new TQGridLayout( m_buttonGroup->layout() );
    groupLayout->setAlignment( Qt::AlignTop );
    mainLayout->addWidget( m_buttonGroup );

    connect( m_buttonGroup, TQT_SIGNAL( clicked(int) ),
             this, TQT_SLOT( slotBackgroundModeChanged() ) );

    // color
    m_radioColor = new TQRadioButton( i18n("Co&lor:"), m_buttonGroup );
    groupLayout->addWidget( m_radioColor, 0, 0 );
    m_buttonColor = new KColorButton( theColor, defaultColor, m_buttonGroup );
    m_buttonColor->setSizePolicy( TQSizePolicy::Preferred,
                                TQSizePolicy::Minimum );
    groupLayout->addWidget( m_buttonColor, 0, 1 );

    connect( m_buttonColor, TQT_SIGNAL( changed( const TQColor& ) ),
             this, TQT_SLOT( slotColorChanged() ) );

    // picture
    m_radioPicture = new TQRadioButton( i18n("&Picture:"), m_buttonGroup );
    groupLayout->addWidget( m_radioPicture, 1, 0 );
    m_comboPicture = new KURLComboRequester( m_buttonGroup );
    groupLayout->addMultiCellWidget( m_comboPicture, 1, 1, 1, 2 );
    initPictures();

    connect( m_comboPicture->comboBox(), TQT_SIGNAL( activated( int ) ),
	     this, TQT_SLOT( slotPictureChanged() ) );
    connect( m_comboPicture, TQT_SIGNAL( urlSelected(const TQString &) ),
             this, TQT_SLOT( slotPictureChanged() ) );

    TQSpacerItem* spacer1 = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding,
                                            TQSizePolicy::Minimum );
    groupLayout->addItem( spacer1, 0, 2 );

    // preview title
    TQHBoxLayout* hlay = new TQHBoxLayout( mainLayout, KDialog::spacingHint() );
    //mainLayout->addLayout( hlay );
    TQLabel* lbl = new TQLabel( i18n("Preview"), page );
    hlay->addWidget( lbl );
    TQFrame* frame = new TQFrame( page );
    frame->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum );
    frame->setFrameShape( TQFrame::HLine );
    frame->setFrameShadow( TQFrame::Sunken );
    hlay->addWidget( frame );

    // preview frame
    m_preview = new TQFrame( page );
    m_preview->setSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding );
    m_preview->setMinimumSize( 370, 180 );
    m_preview->setFrameShape( TQFrame::Panel );
    m_preview->setFrameShadow( TQFrame::Raised );
    mainLayout->addWidget( m_preview );

    if ( !pixmapFile.isEmpty() ) {
        loadPicture( pixmapFile );
        m_buttonColor->setColor( defaultColor );
        m_radioPicture->setChecked( true );
    }
    else {
        m_buttonColor->setColor( theColor );
        m_comboPicture->comboBox()->setCurrentItem( 0 );
        m_radioColor->setChecked( true );
    }
    slotBackgroundModeChanged();
}

KonqBgndDialog::~KonqBgndDialog()
{
}

TQColor KonqBgndDialog::color() const
{
    if ( m_radioColor->isChecked() )
        return m_buttonColor->color();

    return TQColor();
}

void KonqBgndDialog::initPictures()
{
    TDEGlobal::dirs()->addResourceType( "tiles",
        TDEGlobal::dirs()->kde_default("data") + "konqueror/tiles/");
    kdDebug(1203) << TDEGlobal::dirs()->kde_default("data") + "konqueror/tiles/" << endl;

    TQStringList list = TDEGlobal::dirs()->findAllResources("tiles");

    if ( list.isEmpty() )
        m_comboPicture->comboBox()->insertItem( i18n("None") );
    else {
        TQStringList::ConstIterator it;
        for ( it = list.begin(); it != list.end(); it++ )
            m_comboPicture->comboBox()->insertItem(
                ( (*it).at(0) == '/' ) ?    // if absolute path
                KURL( *it ).fileName() :  // then only fileName
                *it );
    }
}

void KonqBgndDialog::loadPicture( const TQString& fileName )
{
    int i ;
    for ( i = 0; i < m_comboPicture->comboBox()->count(); i++ ) {
        if ( fileName == m_comboPicture->comboBox()->text( i ) ) {
            m_comboPicture->comboBox()->setCurrentItem( i );
            return;
        }
    }

    if ( !fileName.isEmpty() ) {
        m_comboPicture->comboBox()->insertItem( fileName );
        m_comboPicture->comboBox()->setCurrentItem( i );
    }
    else
        m_comboPicture->comboBox()->setCurrentItem( 0 );
}

void KonqBgndDialog::slotPictureChanged()
{
    m_pixmapFile = m_comboPicture->comboBox()->currentText();
    TQString file = locate( "tiles", m_pixmapFile );
    if ( file.isEmpty() )
        file = locate("wallpaper", m_pixmapFile); // add fallback for compatibility
    if ( file.isEmpty() ) {
        kdWarning(1203) << "Couldn't locate wallpaper " << m_pixmapFile << endl;
        m_preview->unsetPalette();
        m_pixmap = TQPixmap();
        m_pixmapFile = "";
    }
    else {
        m_pixmap.load( file );

        if ( m_pixmap.isNull() )
            kdWarning(1203) << "Could not load wallpaper " << file << endl;
    }
    m_preview->setPaletteBackgroundPixmap( m_pixmap );
}

void KonqBgndDialog::slotColorChanged()
{
    m_preview->setPaletteBackgroundColor( m_buttonColor->color() );
}

void KonqBgndDialog::slotBackgroundModeChanged()
{
    if ( m_radioColor->isChecked() ) {
        m_buttonColor->setEnabled( true );
        m_comboPicture->setEnabled( false );
        m_pixmapFile = "";
        slotColorChanged();
    }
    else {  // m_comboPicture->isChecked() == true
        m_comboPicture->setEnabled( true );
        m_buttonColor->setEnabled( false );
        slotPictureChanged();
    }
}


#include "konq_bgnddlg.moc"