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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
#include "astyle_part.h"
#include "astyle_widget.h"
#include <tqradiobutton.h>
#include <tqtabwidget.h>
#include <tqmultilineedit.h>
#include <tqbuttongroup.h>
#include <tqpushbutton.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kdevcore.h>
AStyleWidget::AStyleWidget(AStylePart * part, bool global, TQWidget *parent, const char *name)
: AStyleConfig(parent, name), m_part(part), isGlobalWidget(global)
{
// which style changed - disable the other pages.
connect(StyleGroup, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(styleChanged()));
connect(ConfigTabs, TQT_SIGNAL(currentChanged(TQWidget*)), this, TQT_SLOT(styleChanged()) );
connect(FillingGroup, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(styleChanged()));
connect(Fill_ForceTabs, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Fill_TabCount, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(styleChanged()));
connect(Fill_SpaceCount, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(styleChanged()));
connect(BracketGroup, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(styleChanged()));
connect(Brackets_CloseHeaders, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Switches, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Cases, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Classes, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Brackets, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Namespaces, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Labels, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Blocks, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Indent_Preprocessors, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Continue_MaxStatement, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(styleChanged()));
connect(Continue_MinConditional, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(styleChanged()));
connect(Block_Break, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Block_BreakAll, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Block_IfElse, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Pad_ParenthesesIn, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Pad_ParenthesesOut, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Pad_ParenthesesUn, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Pad_Operators, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Keep_Statements, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
connect(Keep_Blocks, TQT_SIGNAL(clicked()), this, TQT_SLOT(styleChanged()));
TQMap<TQString, TQVariant> option;
if ( isGlobalWidget){
Style_Global->hide();
option = m_part->getGlobalOptions();
}
else{
Style_Global->show();
option = m_part->getProjectOptions();
}
// style
TQString s = option["FStyle"].toString();
// fake the id so we disable the other pages.
int id=0;
if (s == "ANSI") id=1;
if (s == "KR") id=2;
if (s == "Linux") id=3;
if (s == "GNU") id=4;
if (s == "JAVA") id=5;
if (s == "GLOBAL") id = 6;
StyleGroup->setButton(id);
if ( isGlobalWidget ){
GeneralExtension->setText(m_part->getGlobalExtensions());
GeneralExtension->setEnabled(true);
globalOptions=true;
}
else{
if ( id == 6){
GeneralExtension->setText(m_part->getGlobalExtensions());
GeneralExtension->setEnabled(false);
globalOptions=true;
}
else{
GeneralExtension->setText(m_part->getProjectExtensions());
GeneralExtension->setEnabled(true);
globalOptions=false;
}
}
m_lastExt=GeneralExtension->text();
if (s == "UserDefined" || s =="GLOBAL" )
{
int wsCount = option["FillCount"].toInt();
if (option["Fill"].toString() == "Tabs")
{
Fill_Tabs->setChecked(true);
Fill_TabCount->setValue(wsCount);
Fill_TabCount->setEnabled(true);
Fill_ForceTabs->setChecked(option["FillForce"].toBool());
Fill_ForceTabs->setEnabled(true);
}
else
{
Fill_Spaces->setChecked(true);
Fill_SpaceCount->setValue(wsCount);
Fill_SpaceCount->setEnabled(true);
Fill_ConvertTabs->setChecked(option["FillForce"].toBool());
Fill_ConvertTabs->setEnabled(true);
}
Fill_EmptyLines->setChecked(option["FillEmptyLines"].toBool());
// indent
Indent_Switches->setChecked(option["IndentSwitches"].toBool());
Indent_Cases->setChecked(option["IndentCases"].toBool());
Indent_Classes->setChecked(option["IndentClasses"].toBool());
Indent_Brackets->setChecked(option["IndentBrackets"].toBool());
Indent_Namespaces->setChecked(option["IndentNamespaces"].toBool());
Indent_Labels->setChecked(option["IndentLabels"].toBool());
Indent_Blocks->setChecked(option["IndentBlocks"].toBool());
Indent_Preprocessors->setChecked(option["IndentPreprocessors"].toBool());
// contiuation
Continue_MaxStatement->setValue(option["MaxStatement"].toInt());
Continue_MinConditional->setValue(option["MinConditional"].toInt());
// brackets
s = option["Brackets"].toString();
if (s == "Break")
Brackets_Break->setChecked(true);
else if (s == "Attach")
Brackets_Attach->setChecked(true);
else if (s == "Linux")
Brackets_Linux->setChecked(true);
else
Brackets_None->setChecked(true);
Brackets_CloseHeaders->setChecked(option["BracketsCloseHeaders"].toBool());
Block_Break->setChecked(option["BlockBreak"].toBool());
Block_BreakAll->setChecked(option["BlockBreakAll"].toBool());
Block_IfElse->setChecked(option["BlockIfElse"].toBool());
// padding
Pad_ParenthesesIn->setChecked(option["PadParenthesesIn"].toBool());
Pad_ParenthesesOut->setChecked(option["PadParenthesesOut"].toBool());
Pad_ParenthesesUn->setChecked(option["PadParenthesesUn"].toBool());
Pad_Operators->setChecked(option["PadOperators"].toBool());
// oneliner
Keep_Statements->setChecked(option["KeepStatements"].toBool());
Keep_Blocks->setChecked(option["KeepBlocks"].toBool());
}
styleChanged();
}
AStyleWidget::~AStyleWidget()
{
}
void AStyleWidget::accept()
{
TQMap<TQString, TQVariant>* m_option;
if ( isGlobalWidget){
m_option = &(m_part->getGlobalOptions());
m_part->setExtensions(GeneralExtension->text(),true);
}
else{
m_option = &(m_part->getProjectOptions());
m_part->setExtensions(GeneralExtension->text(),false);
}
// style
if (Style_ANSI->isChecked())
(*m_option)["FStyle"] = "ANSI";
else if (Style_KR->isChecked())
(*m_option)["FStyle"] = "KR";
else if (Style_Linux->isChecked())
(*m_option)["FStyle"] = "Linux";
else if (Style_GNU->isChecked())
(*m_option)["FStyle"] = "GNU";
else if (Style_JAVA->isChecked())
(*m_option)["FStyle"] = "JAVA";
else if (Style_Global->isChecked()){
TQMap<TQString,TQVariant>& global = m_part->getGlobalOptions();
TQMap<TQString,TQVariant>& project = m_part->getProjectOptions();
project=global;
project["FStyle"]="GLOBAL";
}
else if (Style_UserDefined->isChecked())
{
(*m_option)["FStyle"] = "UserDefined";
// fill
if (Fill_Tabs->isChecked())
{
(*m_option)["Fill"] = "Tabs";
(*m_option)["FillCount"] = Fill_TabCount->value();
(*m_option)["FillForce"] = Fill_ForceTabs->isChecked();
}
else
{
(*m_option)["Fill"] = "Spaces";
(*m_option)["FillCount"] = Fill_SpaceCount->value();
(*m_option)["FillForce"] = Fill_ConvertTabs->isChecked();
}
(*m_option)["FillEmptyLines"] = Fill_EmptyLines->isChecked();
// indent
(*m_option)["IndentSwitches"] = Indent_Switches->isChecked();
(*m_option)["IndentCases"] = Indent_Cases->isChecked();
(*m_option)["IndentClasses"] = Indent_Classes->isChecked();
(*m_option)["IndentBrackets"] = Indent_Brackets->isChecked();
(*m_option)["IndentNamespaces"] = Indent_Namespaces->isChecked();
(*m_option)["IndentLabels"] = Indent_Labels->isChecked();
(*m_option)["IndentBlocks"] = Indent_Blocks->isChecked();
(*m_option)["IndentPreprocessors"] = Indent_Preprocessors->isChecked();
// continuation
(*m_option)["MaxStatement"] = Continue_MaxStatement->value();
(*m_option)["MinConditional"] = Continue_MinConditional->value();
// brackets
if ( Brackets_None->isChecked())
(*m_option)["Brackets"] = "None";
else if (Brackets_Break->isChecked())
(*m_option)["Brackets"] = "Break";
else if (Brackets_Attach->isChecked())
(*m_option)["Brackets"] = "Attach";
else if (Brackets_Linux->isChecked())
(*m_option)["Brackets"] = "Linux";
(*m_option)["BracketsCloseHeaders"] = Brackets_CloseHeaders->isChecked();
// blocks
(*m_option)["BlockBreak"] = Block_Break->isChecked();
(*m_option)["BlockBreakAll"] = Block_BreakAll->isChecked();
(*m_option)["BlockIfElse"] = Block_IfElse->isChecked();
// padding
(*m_option)["PadParenthesesIn"] = Pad_ParenthesesIn->isChecked();
(*m_option)["PadParenthesesOut"] = Pad_ParenthesesOut->isChecked();
(*m_option)["PadParenthesesUn"] = Pad_ParenthesesUn->isChecked();
(*m_option)["PadOperators"] = Pad_Operators->isChecked();
// oneliner
(*m_option)["KeepStatements"] = Keep_Statements->isChecked();
(*m_option)["KeepBlocks"] = Keep_Blocks->isChecked();
}
if ( isGlobalWidget){
TQMap<TQString, TQVariant>& project = m_part->getProjectOptions();
if ( project["FStyle"] == "GLOBAL"){
project = m_part->getGlobalOptions();
project["FStyle"] = "GLOBAL";
}
m_part->saveGlobal();
}
// for ( TQMap<TQString, TQVariant>::ConstIterator iter = m_option->begin();iter != m_option->end();iter++ )
// {
// kdDebug ( 9009 ) << "widget: " << iter.key() << "=" << iter.data() << endl;
// }
}
/**
* Change the sample formatting text depending on what tab is selected.
*
* @param id Tab selected
*/
void AStyleWidget::styleChanged( )
{
// disable the tabs for predefined sample
// only user define id==0, enables the other tabs
ConfigTabs->setTabEnabled(tab_2, Style_UserDefined->isChecked());
ConfigTabs->setTabEnabled(tab_3, Style_UserDefined->isChecked());
ConfigTabs->setTabEnabled(tab_4, Style_UserDefined->isChecked());
int id = ConfigTabs->currentPageIndex();
StyleExample->clear();
TQString bracketSample = "namespace foospace {\n\tint Foo(){\n\tif (isBar)\n{\nbar(); \n\treturn 1; } else \nreturn 0;}}\n\nvoid test(){\n\tif (isFoo){\n\tbar();\n} else\n{\n\tbar();\n}\n}\n";
TQString indentSample = "#define foobar(A)\\\n{Foo();Bar();}\n#define anotherFoo(B)\\\nreturn Bar()\n\nnamespace Bar\n{\nclass Foo\n{public:\nFoo();\nvirtual ~Foo();\n};\nswitch (foo)\n{\ncase 1:\na+=1;\nbreak;\ncase 2:\n{\na += 2;\n break;\n}\n}\nif (isFoo)\n{\nbar();\n}\nelse\n{\nanotherBar();\n}\nint foo()\n\twhile(isFoo)\n\t\t{\n\t\t\t...\n\t\t\tgoto error;\n\t\t....\n\t\terror:\n\t\t\t...\n\t\t}\n\t}\nfooArray[]={ red,\n\tgreen,\n\tdarkblue};\nfooFunction(barArg1,\n\tbarArg2,\n\tbarArg3);\n";
TQString formattingSample = "void func(){\n\tif(isFoo(a,b))\n\tbar(a,b);\nif(isFoo)\n\ta=bar((b-c)*a,*d--);\nif( isFoo( a,b ) )\n\tbar(a, b);\nif (isFoo) {isFoo=false;cat << isFoo <<endl;}\nif(isFoo)DoBar();if (isFoo){\n\tbar();\n}\n\telse if(isBar()){\n\tannotherBar();\n}\n}\n";
TQString styleSample = "\t//Tabs & Brackets\nnamespace foo{\n" + bracketSample + "}\n\t// Indentation\n" + indentSample + "\t// Formatting\n" + formattingSample;
switch(id){
case 1:
StyleExample->setText( m_part->formatSource( bracketSample, this,m_part->getProjectOptions() ) );
break;
case 2:
StyleExample->setText( m_part->formatSource( indentSample, this,m_part->getProjectOptions() ) );
break;
case 3:
StyleExample->setText( m_part->formatSource( formattingSample, this,m_part->getProjectOptions() ) );
break;
default:
{
if ( Style_Global->isChecked() ){
StyleExample->setText( m_part->formatSource( styleSample, 0, m_part->getGlobalOptions()) );
}
else
{
StyleExample->setText( m_part->formatSource( styleSample, this, m_part->getProjectOptions() ) );
}
}
}
if ( Style_Global->isChecked()){
if ( !globalOptions){
m_lastExt = GeneralExtension->text();
GeneralExtension->setEnabled ( false );
GeneralExtension->setText ( m_part->getGlobalExtensions() );
globalOptions=!globalOptions;
}
}
else{
if ( globalOptions){
GeneralExtension->setEnabled ( true );
GeneralExtension->setText ( m_lastExt );
globalOptions=!globalOptions;
}
}
}
#include "astyle_widget.moc"
|