summaryrefslogtreecommitdiffstats
path: root/part/kxetreeviewsettings.cpp
blob: 3437a98b6ced31be2c24fcfb1481afd0c95722be (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
/***************************************************************************
                           kxetreeviewsettings.cpp
                           -----------------------
    begin                : Tue Dec 02 2003
    copyright            : (C) 2003 by The KXMLEditor Team
    email                : hartig@users.sourceforge.net
 ***************************************************************************/

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

#include "kxetreeviewsettings.h"
#include "kxetreeviewsettingspage.h"

#include <tdelocale.h>
#include <tdeconfig.h>
#include <kdebug.h>

#include <tqframe.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqbuttongroup.h>
#include <tqradiobutton.h>

#define CONF_ENTRY_NAME_ITEMS_ON_DEMAND "Create items on demand"
#define DFLT_VALUE_ITEMS_ON_DEMAND true

#define CONF_ENTRY_NAME_DFLT_EXP_LEVEL "Expand to level"
#define DFLT_VALUE_DFLT_EXP_LEVEL 5

#define CONF_ENTRY_NAME_DECORATE_ROOT "Root decorated"
#define DFLT_VALUE_DECORATE_ROOT false

#define CONF_ENTRY_NAME_ENABLE_DRAG "Enable Dragging"
#define DFLT_VALUE_ENABLE_DRAG true

#define CONF_ENTRY_NAME_ENABLE_DROP "Enable Dropping"
#define DFLT_VALUE_ENABLE_DROP true

#define CONF_ENTRY_NAME_ELEM_DISPL_MODE "Element display mode"
#define DFLT_VALUE_ELEM_DISPL_MODE NoAttributes


KXETreeViewSettings::KXETreeViewSettings( TQObject * pParent, const char * pszName )
 : KXESettings( "Tree View", pParent, pszName ),
   m_bCreateItemsOnDemand( DFLT_VALUE_ITEMS_ON_DEMAND ),
   m_iDfltExpLevel( DFLT_VALUE_DFLT_EXP_LEVEL ),
   m_bDecorateRoot( DFLT_VALUE_DECORATE_ROOT ),
   m_bEnableDragging( DFLT_VALUE_ENABLE_DRAG ),
   m_bEnableDropping( DFLT_VALUE_ENABLE_DROP ),
   m_enmElemDisplMode( DFLT_VALUE_ELEM_DISPL_MODE ),
   m_pDialogPage(0)
{
}

void KXETreeViewSettings::write( TDEConfig * pConfig ) const
{
	pConfig->writeEntry( CONF_ENTRY_NAME_ITEMS_ON_DEMAND, m_bCreateItemsOnDemand );
	pConfig->writeEntry( CONF_ENTRY_NAME_DFLT_EXP_LEVEL, m_iDfltExpLevel );
	pConfig->writeEntry( CONF_ENTRY_NAME_DECORATE_ROOT, m_bDecorateRoot );
	pConfig->writeEntry( CONF_ENTRY_NAME_ENABLE_DRAG, m_bEnableDragging );
	pConfig->writeEntry( CONF_ENTRY_NAME_ENABLE_DROP, m_bEnableDropping );
	pConfig->writeEntry( CONF_ENTRY_NAME_ELEM_DISPL_MODE, m_enmElemDisplMode );
}

void KXETreeViewSettings::read( const TDEConfig * pConfig )
{
	m_bCreateItemsOnDemand = pConfig->readBoolEntry( CONF_ENTRY_NAME_ITEMS_ON_DEMAND, DFLT_VALUE_ITEMS_ON_DEMAND );
	m_iDfltExpLevel = pConfig->readNumEntry( CONF_ENTRY_NAME_DFLT_EXP_LEVEL, DFLT_VALUE_DFLT_EXP_LEVEL );
	m_bDecorateRoot = pConfig->readBoolEntry( CONF_ENTRY_NAME_DECORATE_ROOT, DFLT_VALUE_DECORATE_ROOT );
	m_bEnableDragging = pConfig->readBoolEntry( CONF_ENTRY_NAME_ENABLE_DRAG, DFLT_VALUE_ENABLE_DRAG );
	m_bEnableDropping = pConfig->readBoolEntry( CONF_ENTRY_NAME_ENABLE_DROP, DFLT_VALUE_ENABLE_DROP );
	m_enmElemDisplMode = static_cast<AttributeVisibility> ( pConfig->readNumEntry( CONF_ENTRY_NAME_ELEM_DISPL_MODE, DFLT_VALUE_ELEM_DISPL_MODE ) );
}

TQString KXETreeViewSettings::dialogPageName() const
{
	return i18n( "Tree View" );
}

TQString KXETreeViewSettings::dialogPageHeader() const
{
	return i18n( "Tree view properties" );
}

TQString KXETreeViewSettings::dialogPageIcon() const
{
	return "view_tree";
}


TQWidget * KXETreeViewSettings::dialogPage( TQFrame * pParent )
{
	if ( ! m_pDialogPage )
	{
		// create the page if necessary
		m_pDialogPage = new KXETreeViewSettingsPage( pParent, "tree view config.dialog page" );

		// and fill its widgets with the corresponding values
		updatePage();

		connect( m_pDialogPage->m_pCreateItemsOnDemand, TQ_SIGNAL(toggled(bool)), this, TQ_SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pDecorateRoot, TQ_SIGNAL(toggled(bool)), this, TQ_SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pDfltExpLevel, TQ_SIGNAL(valueChanged(int)), this, TQ_SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pEnableDrag, TQ_SIGNAL(toggled(bool)), this, TQ_SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pEnableDrop, TQ_SIGNAL(toggled(bool)), this, TQ_SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pElemDisplMode1, TQ_SIGNAL(toggled(bool)), this, TQ_SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pElemDisplMode2, TQ_SIGNAL(toggled(bool)), this, TQ_SIGNAL(sigDialogPageChanged()) );
		connect( m_pDialogPage->m_pElemDisplMode3, TQ_SIGNAL(toggled(bool)), this, TQ_SIGNAL(sigDialogPageChanged()) );
	}

	return m_pDialogPage;
}


void KXETreeViewSettings::setFromPage()
{
	if ( m_pDialogPage )
	{
		m_bCreateItemsOnDemand = m_pDialogPage->m_pCreateItemsOnDemand->isChecked();
		m_bDecorateRoot = m_pDialogPage->m_pDecorateRoot->isChecked();
		m_iDfltExpLevel = m_pDialogPage->m_pDfltExpLevel->value();
		m_bEnableDragging = m_pDialogPage->m_pEnableDrag->isChecked();
		m_bEnableDropping = m_pDialogPage->m_pEnableDrop->isChecked();

		if ( m_pDialogPage->m_pElemDisplMode1->isChecked() )
			m_enmElemDisplMode = NoAttributes;
		else if ( m_pDialogPage->m_pElemDisplMode2->isChecked() )
			m_enmElemDisplMode = NamesOnly;
		else if ( m_pDialogPage->m_pElemDisplMode3->isChecked() )
			m_enmElemDisplMode = NamesAndValues;
	}
}

void KXETreeViewSettings::updatePage() const
{
	if ( m_pDialogPage )
	{
		m_pDialogPage->m_pCreateItemsOnDemand->setChecked( m_bCreateItemsOnDemand );
		m_pDialogPage->m_pDecorateRoot->setChecked( m_bDecorateRoot );
		m_pDialogPage->m_pDfltExpLevel->setValue( m_iDfltExpLevel );
		m_pDialogPage->m_pEnableDrag->setChecked( m_bEnableDragging );
		m_pDialogPage->m_pEnableDrop->setChecked( m_bEnableDropping );

		switch ( m_enmElemDisplMode )
		{
			case NoAttributes:
				m_pDialogPage->m_pElemDisplMode->setButton( m_pDialogPage->m_pElemDisplMode->id( m_pDialogPage->m_pElemDisplMode1 ) );
				break;
			case NamesOnly:
				m_pDialogPage->m_pElemDisplMode->setButton( m_pDialogPage->m_pElemDisplMode->id( m_pDialogPage->m_pElemDisplMode2 ) );
				break;
			case NamesAndValues:
				m_pDialogPage->m_pElemDisplMode->setButton( m_pDialogPage->m_pElemDisplMode->id( m_pDialogPage->m_pElemDisplMode3 ) );
				break;
			default:
				kdError() << "KXETreeViewSettings::updatePage: unknown element display mode" << endl;
		}
	}
}