KDevelop API Documentation

parts/astyle/astyle_widget.cpp

Go to the documentation of this file.
00001 #include "astyle_widget.h" 00002 00003 #include <qradiobutton.h> 00004 #include <qtabwidget.h> 00005 #include <qmultilineedit.h> 00006 #include <qbuttongroup.h> 00007 #include <qcheckbox.h> 00008 #include <qspinbox.h> 00009 00010 #include <kconfig.h> 00011 #include <kapplication.h> 00012 #include <kdebug.h> 00013 00014 #include <kdevcore.h> 00015 00016 00017 AStyleWidget::AStyleWidget(QWidget *parent, const char *name) 00018 : AStyleConfig(parent, name) 00019 { 00020 connect(StyleGroup, SIGNAL(clicked(int)), this, SLOT(styleChanged(int))); 00021 00022 // load settings 00023 KConfig *config = kapp->config(); 00024 config->setGroup("AStyle"); 00025 00026 // style 00027 QString s = config->readEntry("Style"); 00028 int id=0; 00029 if (s == "ANSI") id=1; 00030 if (s == "KR") id=2; 00031 if (s == "Linux") id=3; 00032 if (s == "GNU") id=4; 00033 if (s == "JAVA") id=5; 00034 StyleGroup->setButton(id); 00035 styleChanged(id); 00036 00037 // fill 00038 if (config->readEntry("Fill", "Tabs") == "Tabs") 00039 Fill_Tabs->setChecked(true); 00040 else 00041 Fill_Spaces->setChecked(true); 00042 Fill_SpaceCount->setValue(config->readNumEntry("FillSpaces",2)); 00043 00044 // indent 00045 Indent_Switches->setChecked(config->readBoolEntry("IndentSwitches", false)); 00046 Indent_Cases->setChecked(config->readBoolEntry("IndentCases", false)); 00047 Indent_Classes->setChecked(config->readBoolEntry("IndentClasses", false)); 00048 Indent_Brackets->setChecked(config->readBoolEntry("IndentBrackets", false)); 00049 Indent_Namespaces->setChecked(config->readBoolEntry("IndentNamespaces", true)); 00050 Indent_Labels->setChecked(config->readBoolEntry("IndentLabels", true)); 00051 00052 // contiuation 00053 Continue_MaxStatement->setValue(config->readNumEntry("MaxStatement", 40)); 00054 Continue_MinConditional->setValue(config->readNumEntry("MinConditional", -1)); 00055 00056 // brackets 00057 s = config->readEntry("Brackets", "Break"); 00058 Brackets_Break->setChecked(s == "Break"); 00059 Brackets_Attach->setChecked(s == "Attach"); 00060 Brackets_Linux->setChecked(s == "Linux"); 00061 00062 // padding 00063 Pad_Parentheses->setChecked(config->readBoolEntry("PadParentheses", false)); 00064 Pad_Operators->setChecked(config->readBoolEntry("PadOperators", false)); 00065 00066 // oneliner 00067 Keep_Statements->setChecked(config->readBoolEntry("KeepStatements", false)); 00068 Keep_Blocks->setChecked(config->readBoolEntry("KeepBlocks", false)); 00069 } 00070 00071 00072 AStyleWidget::~AStyleWidget() 00073 { 00074 } 00075 00076 00077 void AStyleWidget::accept() 00078 { 00079 // save settings 00080 KConfig *config = kapp->config(); 00081 config->setGroup("AStyle"); 00082 00083 // style 00084 if (Style_UserDefined->isChecked()) 00085 config->writeEntry("Style", "UserDefined"); 00086 else if (Style_ANSI->isChecked()) 00087 config->writeEntry("Style", "ANSI"); 00088 else if (Style_KR->isChecked()) 00089 config->writeEntry("Style", "KR"); 00090 else if (Style_Linux->isChecked()) 00091 config->writeEntry("Style", "Linux"); 00092 else if (Style_GNU->isChecked()) 00093 config->writeEntry("Style", "GNU"); 00094 else if (Style_JAVA->isChecked()) 00095 config->writeEntry("Style", "JAVA"); 00096 00097 // fill 00098 if (Fill_Tabs->isChecked()) 00099 config->writeEntry("Fill", "Tabs"); 00100 else 00101 config->writeEntry("Fill", "Spaces"); 00102 config->writeEntry("FillSpaces", Fill_SpaceCount->value()); 00103 00104 // indent 00105 config->writeEntry("IndentSwitches", Indent_Switches->isChecked()); 00106 config->writeEntry("IndentCases", Indent_Cases->isChecked()); 00107 config->writeEntry("IndentClasses", Indent_Classes->isChecked()); 00108 config->writeEntry("IndentBrackets", Indent_Brackets->isChecked()); 00109 config->writeEntry("IndentNamespaces", Indent_Namespaces->isChecked()); 00110 config->writeEntry("IndentLabels", Indent_Labels->isChecked()); 00111 00112 // continuation 00113 config->writeEntry("MaxStatement", Continue_MaxStatement->value()); 00114 config->writeEntry("MinConditional", Continue_MinConditional->value()); 00115 00116 // brackets 00117 if (Brackets_Break->isChecked()) 00118 config->writeEntry("Brackets", "Break"); 00119 else if (Brackets_Attach->isChecked()) 00120 config->writeEntry("Brackets", "Attach"); 00121 else 00122 config->writeEntry("Brackets", "Linux"); 00123 00124 // padding 00125 config->writeEntry("PadParentheses", Pad_Parentheses->isChecked()); 00126 config->writeEntry("PadOperators", Pad_Operators->isChecked()); 00127 00128 // oneliner 00129 config->writeEntry("KeepStatements", Keep_Statements->isChecked()); 00130 config->writeEntry("KeepBlocks", Keep_Blocks->isChecked()); 00131 00132 config->sync(); 00133 } 00134 00135 00136 void AStyleWidget::styleChanged(int id) 00137 { 00138 ConfigTabs->setTabEnabled(tab_2, id == 0); 00139 ConfigTabs->setTabEnabled(tab_3, id == 0); 00140 00141 StyleExample->clear(); 00142 00143 switch (id) 00144 { 00145 case 0: 00146 break; 00147 00148 case 1: 00149 StyleExample->setText("" 00150 "namespace foospace\n" 00151 "{\n" 00152 " int Foo()\n" 00153 " {\n" 00154 " if (isBar)\n" 00155 " {\n" 00156 " bar();\n" 00157 " return 1;\n" 00158 " }\n" 00159 " else\n" 00160 " return 0;\n" 00161 " }\n" 00162 "}\n" 00163 ""); 00164 break; 00165 00166 case 2: 00167 StyleExample->setText("" 00168 "namespace foospace {\n" 00169 " int Foo() {\n" 00170 " if (isBar) {\n" 00171 " bar();\n" 00172 " return 1;\n" 00173 " } else\n" 00174 " return 0;\n" 00175 " }\n" 00176 "}\n" 00177 ""); 00178 break; 00179 00180 case 3: 00181 StyleExample->setText("" 00182 "namespace foospace\n" 00183 "{\n" 00184 " int Foo()\n" 00185 " {\n" 00186 " if (isBar) {\n" 00187 " bar();\n" 00188 " return 1;\n" 00189 " } else\n" 00190 " return 0;\n" 00191 " }\n" 00192 "}\n" 00193 ""); 00194 break; 00195 00196 case 4: 00197 StyleExample->setText("" 00198 "namespace foospace\n" 00199 " {\n" 00200 " int Foo()\n" 00201 " {\n" 00202 " if (isBar)\n" 00203 " {\n" 00204 " bar();\n" 00205 " return 1;\n" 00206 " }\n" 00207 " else\n" 00208 " return 0;\n" 00209 " }\n" 00210 " }\n" 00211 ""); 00212 break; 00213 00214 case 5: 00215 StyleExample->setText("" 00216 "class foospace {\n" 00217 " int Foo() {\n" 00218 " if (isBar) {\n" 00219 " bar();\n" 00220 " return 1;\n" 00221 " } else\n" 00222 " return 0;\n" 00223 " }\n" 00224 "}\n" 00225 ""); 00226 } 00227 } 00228 00229 00230 #include "astyle_widget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Oct 19 08:01:49 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003