summaryrefslogtreecommitdiffstats
path: root/kview/kviewcanvas/config/confmodules.cpp
blob: 04b3cf3ae13ef7bd8f1dd69a37eded5e5ef58268 (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
/*  This file is part of the KDE project
    Copyright (C) 2002-2003 Matthias Kretz <kretz@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2
    as published by the Free Software Foundation.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/

#include "confmodules.h"
#include "generalconfigwidget.h"
#include "defaults.h"

#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqframe.h>

#include <klocale.h>
#include <ksimpleconfig.h>
#include <kcolorbutton.h>
#include <tdelistview.h>
#include <knuminput.h>
#include <kgenericfactory.h>

typedef KGenericFactory<KViewCanvasConfig, TQWidget> KViewCanvasConfigFactory;
K_EXPORT_COMPONENT_FACTORY( kcm_kviewcanvasconfig, KViewCanvasConfigFactory( "kcm_kviewcanvasconfig" ) )

KViewCanvasConfig::KViewCanvasConfig( TQWidget * parent, const char *, const TQStringList & args )
	: TDECModule( KViewCanvasConfigFactory::instance(), parent, args )
	, m_config( new TDEConfig( "kviewcanvasrc" ) )
{
	TQBoxLayout * layout = new TQVBoxLayout( this );
	layout->setAutoAdd( true );

	m_pWidget = new GeneralConfigWidget( this );
	m_pWidget->m_pMinWidth ->setRange( 1, 200 );
	m_pWidget->m_pMinHeight->setRange( 1, 200 );
	m_pWidget->m_pMaxWidth ->setRange( 1, 10000 );
	m_pWidget->m_pMaxHeight->setRange( 1, 10000 );

	// clear m_items
	m_items.clear();

	for( unsigned int i = 1; i <= Defaults::numOfBlendEffects; ++i )
	{
		TQCheckListItem * item = new TQCheckListItem( m_pWidget->m_pListView, i18n( Defaults::blendEffectDescription[ i ] ), TQCheckListItem::CheckBox );
		m_items.append( item );
	}

	connect( m_pWidget->m_pListView, TQT_SIGNAL( clicked( TQListViewItem * ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_pListView, TQT_SIGNAL( spacePressed( TQListViewItem * ) ), this, TQT_SLOT( configChanged() ) );

	connect( m_pWidget->m_pSmoothScaling, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_pKeepRatio, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_pCenterImage, TQT_SIGNAL( toggled( bool ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_bgColor, TQT_SIGNAL( changed( const TQColor & ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_pMinWidth, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_pMaxWidth, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_pMinHeight, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( configChanged() ) );
	connect( m_pWidget->m_pMaxHeight, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( configChanged() ) );

	load();
}

KViewCanvasConfig::~KViewCanvasConfig()
{
}

void KViewCanvasConfig::save()
{
	TDEConfigGroup cfgGroup( m_config, "Settings" );
	cfgGroup.writeEntry( "Smooth Scaling", m_pWidget->m_pSmoothScaling->isChecked() );
	cfgGroup.writeEntry( "Keep Aspect Ratio", m_pWidget->m_pKeepRatio->isChecked() );
	cfgGroup.writeEntry( "Center Image", m_pWidget->m_pCenterImage->isChecked() );

	cfgGroup.writeEntry( "Background Color", m_pWidget->m_bgColor->color() );

	cfgGroup.writeEntry( "Minimum Width" , m_pWidget->m_pMinWidth->value() );
	cfgGroup.writeEntry( "Minimum Height", m_pWidget->m_pMinHeight->value() );
	cfgGroup.writeEntry( "Maximum Width" , m_pWidget->m_pMaxWidth->value() );
	cfgGroup.writeEntry( "Maximum Height", m_pWidget->m_pMaxHeight->value() );

	TDEConfigGroup cfgGroup2( m_config, "Blend Effects" );
	TQCheckListItem *item = m_items.first();
	for( int i = 1; item; item = m_items.next(), ++i )
		cfgGroup2.writeEntry( TQString::number( i ), item->isOn() );
	m_config->sync();
}

void KViewCanvasConfig::load()
{
	TDEConfigGroup cfgGroup( m_config, "Settings" );
	m_pWidget->m_pSmoothScaling->setChecked( cfgGroup.readBoolEntry( "Smooth Scaling", Defaults::smoothScaling ) );
	m_pWidget->m_pKeepRatio->setChecked( cfgGroup.readBoolEntry( "Keep Aspect Ratio", Defaults::keepAspectRatio ) );
	m_pWidget->m_pCenterImage->setChecked( cfgGroup.readBoolEntry( "Center Image", Defaults::centerImage ) );
	
	m_pWidget->m_bgColor->setColor( cfgGroup.readColorEntry( "Background Color", &Defaults::bgColor ) );

	m_pWidget->m_pMinWidth ->setValue( cfgGroup.readNumEntry( "Minimum Width" , Defaults::minSize.width() ) );
	m_pWidget->m_pMinHeight->setValue( cfgGroup.readNumEntry( "Minimum Height", Defaults::minSize.height() ) );
	m_pWidget->m_pMaxWidth ->setValue( cfgGroup.readNumEntry( "Maximum Width" , Defaults::maxSize.width() ) );
	m_pWidget->m_pMaxHeight->setValue( cfgGroup.readNumEntry( "Maximum Height", Defaults::maxSize.height() ) );

	TDEConfigGroup cfgGroup2( m_config, "Blend Effects" );
	TQCheckListItem * item = m_items.first();
	for( int i = 1; item; item = m_items.next(), ++i )
		item->setOn( cfgGroup2.readBoolEntry( TQString::number( i ), false ) );
}

void KViewCanvasConfig::defaults()
{
	m_pWidget->m_pSmoothScaling->setChecked( Defaults::smoothScaling );
	m_pWidget->m_pKeepRatio->setChecked( Defaults::keepAspectRatio );
	m_pWidget->m_pCenterImage->setChecked( Defaults::centerImage );
	
	m_pWidget->m_bgColor->setColor( Defaults::bgColor );

	m_pWidget->m_pMinWidth ->setValue( Defaults::minSize.width() );
	m_pWidget->m_pMinHeight->setValue( Defaults::minSize.height() );
	m_pWidget->m_pMaxWidth ->setValue( Defaults::maxSize.width() );
	m_pWidget->m_pMaxHeight->setValue( Defaults::maxSize.height() );

	TQCheckListItem * item = m_items.first();
	for( int i = 1; item; item = m_items.next(), ++i )
		item->setOn( false );
	emit changed( true );
}

void KViewCanvasConfig::configChanged()
{
	emit changed( true );
}

// vim:sw=4:ts=4

#include "confmodules.moc"