KDevelop API Documentation

cindent.cpp

Go to the documentation of this file.
00001  /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qt Designer.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file COPYING included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
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 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:23 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003