cindent.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "cindent.h"
00022 #include "qregexp.h"
00023 #include "qeditor_part.h"
00024 #include "qeditor.h"
00025 #include "indentconfigpage.h"
00026
00027 #include <qvbox.h>
00028 #include <kdialogbase.h>
00029 #include <kdebug.h>
00030 #include <kconfig.h>
00031 #include <klocale.h>
00032 #include <kinstance.h>
00033
00034 extern int indentForBottomLine( const QStringList& program, QChar typedIn );
00035 extern void configureCIndent( const QMap<QString, QVariant>& values );
00036
00037 using namespace std;
00038
00039 CIndent::CIndent( QEditor* ed )
00040 : QEditorIndenter( ed )
00041 {
00042 KConfig* config = QEditorPartFactory::instance()->config();
00043 config->setGroup( "C++ Indent" );
00044
00045 m_values[ "TabSize" ] = ed->tabStop();
00046 m_values[ "IndentSize" ] = config->readNumEntry( "IndentSize", 4 );
00047 m_values[ "ContinuationSize" ] = config->readNumEntry( "ContinuationSize", 4 );
00048 m_values[ "CommentOffset" ] = config->readNumEntry( "CommentOffset", 2 );
00049
00050 configureCIndent( m_values );
00051 }
00052
00053 CIndent::~CIndent()
00054 {
00055 KConfig* config = QEditorPartFactory::instance()->config();
00056 config->setGroup( "C++ Indent" );
00057
00058 config->writeEntry( "IndentSize", m_values[ "IndentSize" ].toInt() );
00059 config->writeEntry( "ContinuationSize", m_values[ "ContinuationSize" ].toInt() );
00060 config->writeEntry( "CommentOffset", m_values[ "CommentOffset" ].toInt() );
00061
00062 config->sync();
00063 }
00064
00065 int CIndent::indentForLine( int line )
00066 {
00067 QStringList code;
00068
00069 for( int i=0; i<=line; ++i )
00070 code << editor()->text( i );
00071
00072 return indentForBottomLine( code, QChar::null );
00073 }
00074
00075 QWidget* CIndent::createConfigPage( QEditorPart* part, KDialogBase* parentWidget,
00076 const char* widgetName )
00077 {
00078 QVBox* vbox = parentWidget->addVBoxPage( i18n("Indent") );
00079
00080 IndentConfigPage* page = new IndentConfigPage( vbox, widgetName );
00081 page->setPart( part );
00082 QObject::connect( parentWidget, SIGNAL(okClicked()),
00083 page, SLOT(accept()) );
00084 return page;
00085 }
00086
00087 void CIndent::updateValues( const QMap<QString, QVariant>& values )
00088 {
00089 QEditorIndenter::updateValues( values );
00090 configureCIndent( values );
00091 }
This file is part of the documentation for KDevelop Version 3.1.2.