Repository navigation
Expand file tree
/
Copy patheditframe.cpp
More file actions
135 lines (115 loc) · 3.6 KB
/
Copy patheditframe.cpp
File metadata and controls
135 lines (115 loc) · 3.6 KB
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
#include "editframe.h"
#include "spinparser.h"
/*
* Lots of interesting new code here, but it doesn't work.
* For some reason it crashes.
* Leave it out of the build for now.
*/
EditFrame::EditFrame(QWidget *parent) : tabNumber(0)
{
editor = new Editor(parent);
cbMethods = new QComboBox(this);
connect(cbMethods, SIGNAL(highlighted(int)), this, SLOT(showMethod(int)));
alphaBtn = new QCheckBox(this);
alphaBtn->setText("Sort Alphabetically");
alphaBtn->setToolTip("Sort Methods Alphabetically");
connect(alphaBtn, SIGNAL(clicked(bool)), this, SLOT(methodSortAlpha(bool)));
closeBtn = new QPushButton(this);
closeBtn->setText("X");
closeBtn->setToolTip("Close Method Browser");
connect(closeBtn, SIGNAL(clicked()), this, SLOT(hideMethods()));
hlayout.addWidget(cbMethods);
hlayout.addWidget(alphaBtn);
hlayout.addWidget(closeBtn);
vlayout.addLayout(&hlayout);
vlayout.addWidget(editor);
setLayout(&vlayout);
hideMethods();
}
EditFrame::~EditFrame()
{
delete editor;
}
void EditFrame::initSpin(SpinParser *parser)
{
editor->initSpin(parser);
}
void EditFrame::showMethods()
{
QString file = editorTabs->tabToolTip(tabNumber);
cbMethods->clear();
cbMethods->setAutoCompletion(true);
cbMethods->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
QStringList list = editor->getSpinParser()->spinMethods(file, "");
foreach(QString s, list) {
if (s.indexOf("PUB",Qt::CaseInsensitive) > 0 ||
s.indexOf("PRI",Qt::CaseInsensitive) > 0) {
s = s.mid(s.indexOf("\t")+1);
QVariant mstr = QVariant(s.mid(s.indexOf("\t")+1));
s = s.mid(3); // skip PUB/PRI
if(s.indexOf(":") > 0) {
methodList.append(s.mid(0,s.indexOf(":")).trimmed()+"::"+mstr.toString());
cbMethods->addItem(s.mid(0,s.indexOf(":")).trimmed(),QVariant(mstr));
}
else if(s.indexOf("|") > 0) {
methodList.append(s.mid(0,s.indexOf("|")).trimmed()+"::"+mstr.toString());
cbMethods->addItem(s.mid(0,s.indexOf("|")).trimmed(),QVariant(mstr));
}
else {
methodList.append(s.trimmed()+"::"+mstr.toString());
cbMethods->addItem(s.trimmed(),QVariant(mstr));
}
}
}
cbMethods->show();
alphaBtn->show();
closeBtn->show();
}
void EditFrame::hideMethods()
{
cbMethods->hide();
alphaBtn->hide();
closeBtn->hide();
}
void EditFrame::showMethod(int index)
{
QVariant vs = cbMethods->itemData(index, Qt::UserRole);
QString s = vs.toString();
QRegExp rs = QRegExp("\\b"+s+"\\b");
int pos = rs.indexIn(editor->toPlainText());
QTextCursor cur = editor->textCursor();
if(pos > -1) {
cur.setPosition(pos);
editor->setTextCursor(cur);
}
}
void EditFrame::methodSortAlpha(bool enable)
{
sortedList = methodList;
if(enable) sortedList.sort();
cbMethods->clear();
foreach(QString s, sortedList) {
QStringList list = s.split("::");
cbMethods->addItem(list[0],QVariant(list[1]));
}
cbMethods->show();
alphaBtn->show();
closeBtn->show();
}
Editor *EditFrame::getEditor()
{
return editor;
}
void EditFrame::setTabWidget(QTabWidget *tab)
{
editorTabs = tab;
}
void EditFrame::setEditor(int num, QString shortName, QString fileName, QString text)
{
editor->setPlainText(text);
editor->setHighlights(shortName);
editorTabs->setTabText(num,shortName);
editorTabs->setTabToolTip(num,fileName);
editorTabs->setCurrentIndex(num);
tabNumber = num;
}