summaryrefslogtreecommitdiffstats
path: root/part/kxe_viewelement.cpp
blob: 21c1ee5f9c240258af844dda2304f95a790b5199 (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
/***************************************************************************
                          kxe_viewelement.cpp  -  description
                             -------------------
    begin                : Mon Oct 15 2001
    copyright            : (C) 2001, 2002, 2003 by The KXMLEditor Team
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "kxe_viewelement.h"
#include "kxe_viewattributes.h"
#include "kxesyntaxhighlighter.h"

#include "kxmleditorfactory.h"
#include "kxeconfiguration.h"
#include "kxetextviewsettings.h"

#include <kconfig.h>
#include <ktextedit.h>

#include <qdom.h>
#include <qcolor.h>
#include <qpalette.h>


#include "qdom_add.h"

#define CONFIG_SPLITTER_SIZES "View Element splitter sizes"

KXE_ViewElement::KXE_ViewElement( QWidget * pParent, KConfig *pConfig, const char * pszName )
	: QSplitter( Qt::Vertical, pParent, pszName )
{
	setOpaqueResize(true);
	m_pConfig = pConfig;
	m_pViewAttributes = new KXE_ViewAttributes( this, "table of element attributes");
	connect( m_pViewAttributes, SIGNAL(sigContextMenuRequested(const QString&,const QPoint&)), this, SIGNAL(sigContextMenuRequested(const QString&,const QPoint&)) );

  connect( m_pViewAttributes, SIGNAL(sigAttributeNameChangedInplace(const QDomAttr&, const QString)), this, SIGNAL(sigAttributeNameChangedInplace(const QDomAttr&, const QString)) );
  connect( m_pViewAttributes, SIGNAL(sigAttributeValueChangedInplace(const QDomAttr&, const QString)), this, SIGNAL(sigAttributeValueChangedInplace(const QDomAttr&, const QString)) );

	m_pViewPlainXML = new KTextEdit( this, "plain XML" );
	m_pViewPlainXML->setReadOnly(true);
	m_pViewPlainXML->setTextFormat(KTextEdit::PlainText);
	m_pViewPlainXML->setPaletteBackgroundColor(pParent->palette().active().base()); // Owerwrite read-only background color
  m_pViewPlainXML->setWordWrap( QTextEdit::NoWrap );
  m_pSyntaxHighlighter = new KXESyntaxHighlighter(m_pViewPlainXML);

  	// configuring splitter sizes
	if (m_pConfig)
	{
		QValueList<int> list = m_pConfig->readIntListEntry(CONFIG_SPLITTER_SIZES);
		if (!list.isEmpty())
			setSizes(list);
  }

	// Apply current configuration
	slotTextViewSettingsChanged();
	// and make sure to be informed about its changes.
	connect( KXMLEditorFactory::configuration()->textview(), SIGNAL(sigChanged()), this, SLOT(slotTextViewSettingsChanged()) );
}

KXE_ViewElement::~KXE_ViewElement()
{
	// saving splitter sizes
	if (m_pConfig)
		m_pConfig->writeEntry( CONFIG_SPLITTER_SIZES, sizes() );

  delete m_pSyntaxHighlighter;
}

QDomAttr KXE_ViewElement::getSelectedAttribute() const
{
	return m_pViewAttributes->getSelectedAttribute();
}

void KXE_ViewElement::setReadWrite( bool fReadWrite )
{
	m_pViewAttributes->setReadWrite(fReadWrite);
}

void KXE_ViewElement::slotChange( const QDomElement & element )
{
	// change attribute view
	m_pViewAttributes->slotChange(element);

  int iIndent = KXMLEditorFactory::configuration()->textview()->indentSteps();

	// change plain XML view
	m_pViewPlainXML->setText( domTool_save(element, iIndent) );
}

//////////////////////////////////////////////////////////////
// configuration slots
//////////////////////////////////////////////////////////////

void KXE_ViewElement::slotTextViewSettingsChanged()
{
	m_pSyntaxHighlighter->setColorDefaultText( KXMLEditorFactory::configuration()->textview()->colorDfltText() );
	m_pSyntaxHighlighter->setColorElementNames( KXMLEditorFactory::configuration()->textview()->colorElemNames() );
	m_pSyntaxHighlighter->setColorAttributeNames( KXMLEditorFactory::configuration()->textview()->colorAttrNames() );
	m_pSyntaxHighlighter->setColorAttributeValues( KXMLEditorFactory::configuration()->textview()->colorAttrValues() );
	m_pSyntaxHighlighter->setColorXmlSyntaxChars( KXMLEditorFactory::configuration()->textview()->colorSyntaxChars() );
	m_pSyntaxHighlighter->setColorComments( KXMLEditorFactory::configuration()->textview()->colorComments() );
	m_pSyntaxHighlighter->setColorSyntaxError( KXMLEditorFactory::configuration()->textview()->colorErrors() );

	if(KXMLEditorFactory::configuration()->textview()->isWrapOn())
	{
		m_pViewPlainXML->setHScrollBarMode(QScrollView::AlwaysOff);
		m_pViewPlainXML->setWordWrap(QTextEdit::WidgetWidth);
	}
	else
	{
		m_pViewPlainXML->setHScrollBarMode(QScrollView::Auto);
		m_pViewPlainXML->setWordWrap(QTextEdit::NoWrap);
	}
	
	m_pSyntaxHighlighter->rehighlight();
}

#include "kxe_viewelement.moc"