Skip to content

Commit 201056a

Browse files
authored
Merge pull request #50 from bullet-physics-playground/mingw64
Recent mingw64 fixes. Closes #49 .
2 parents dc23784 + 6f58d31 commit 201056a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+21478
-0
lines changed

src/src/cmd.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#include "cmd.h"
2+
3+
#include <QDebug>
4+
5+
#include <QKeyEvent>
6+
7+
CommandLine::CommandLine(QWidget *parent) : QLineEdit(parent) {
8+
historyPos = -1;
9+
connect(this, SIGNAL(returnPressed()), this, SLOT(executed()));
10+
11+
history = new QList<QString>();
12+
}
13+
14+
QList<QString>* CommandLine::getHistory() {
15+
return history;
16+
}
17+
18+
void CommandLine::executed() {
19+
QString cmd = text();
20+
21+
history->push_back(cmd);
22+
historyPos = -1;
23+
24+
setText("");
25+
26+
emit execute(cmd);
27+
}
28+
29+
void CommandLine::keyPressEvent(QKeyEvent *e) {
30+
if (e->key() == Qt::Key_Up) {
31+
int n = history->size();
32+
int pos = historyPos == -1 ? n - 1 : historyPos - 1;
33+
if ((pos >= 0) && (pos < n)) {
34+
setText(history->at(pos));
35+
historyPos = pos;
36+
}
37+
} else if (e->key() == Qt::Key_Down) {
38+
int n = history->size();
39+
int pos = historyPos == -1 ? n : historyPos + 1;
40+
if((pos >= 0) && (pos < n) ) {
41+
setText(history->at(pos));
42+
historyPos = pos;
43+
} else if (pos >= n) {
44+
QLineEdit::setText("");
45+
historyPos = -1;
46+
}
47+
} else {
48+
QLineEdit::keyPressEvent(e);
49+
}
50+
51+
// special case - accept return key which is also mapped to qglviewer start/stopAnimation()
52+
if (e->isAccepted() || e->key() == Qt::Key_Return) {
53+
return;
54+
}
55+
56+
// if the key press was not accepted, it probably is a user defindes shortcut
57+
58+
int keyInt = e->key();
59+
Qt::Key key = static_cast<Qt::Key>(keyInt);
60+
61+
if (key == Qt::Key_unknown) {
62+
qDebug() << "Unknown key from a macro probably";
63+
return;
64+
}
65+
66+
// the user have clicked just and only the special keys Ctrl, Shift, Alt, Meta.
67+
if(key == Qt::Key_Control ||
68+
key == Qt::Key_Shift ||
69+
key == Qt::Key_Alt ||
70+
key == Qt::Key_Meta)
71+
{
72+
// qDebug() << "Single click of special key: Ctrl, Shift, Alt or Meta";
73+
// qDebug() << "New KeySequence:" << QKeySequence(keyInt).toString(QKeySequence::NativeText);
74+
return;
75+
}
76+
77+
// check for a combination of user clicks
78+
Qt::KeyboardModifiers modifiers = e->modifiers();
79+
QString keyText = e->text();
80+
// if the keyText is empty than it's a special key like F1, F5, ...
81+
// qDebug() << "Pressed Key:" << keyText;
82+
83+
QList<Qt::Key> modifiersList;
84+
if (modifiers & Qt::ShiftModifier)
85+
keyInt += Qt::SHIFT;
86+
if (modifiers & Qt::ControlModifier)
87+
keyInt += Qt::CTRL;
88+
if (modifiers & Qt::AltModifier)
89+
keyInt += Qt::ALT;
90+
if (modifiers & Qt::MetaModifier)
91+
keyInt += Qt::META;
92+
93+
QString seq = QKeySequence(keyInt).toString(QKeySequence::NativeText);
94+
95+
// qDebug() << "CodeEditor::keyPressed(" << seq << ")";
96+
97+
emit keyPressed(e);
98+
}
99+

src/src/cmd.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef CMD_LINE_H
2+
#define CMD_LINE_H
3+
4+
#include <QLineEdit>
5+
#include <QList>
6+
#include <QString>
7+
8+
class CommandLine : public QLineEdit {
9+
Q_OBJECT
10+
11+
public:
12+
CommandLine(QWidget *parent = 0);
13+
QList<QString>* getHistory();
14+
15+
public slots:
16+
void executed();
17+
18+
signals:
19+
void keyPressed(QKeyEvent *e);
20+
void execute(QString cmd);
21+
22+
private:
23+
void keyPressEvent(QKeyEvent *e);
24+
25+
private:
26+
QList<QString> *history;
27+
int historyPos;
28+
};
29+
30+
#endif

src/src/code.cpp

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
#include "code.h"
2+
3+
#include <Qsci/qscilexerlua.h>
4+
#include <Qsci/qsciapis.h>
5+
6+
#include <QAction>
7+
#include <QFileDialog>
8+
#include <QTextStream>
9+
#include <QMessageBox>
10+
#include <QKeyEvent>
11+
#include <QDebug>
12+
13+
Code::Code(QSettings *s, QWidget *parent)
14+
: QsciScintilla(parent)
15+
{
16+
QString family = s->value("editor/fontfamily", "Courier").toString();
17+
uint size = s->value("editor/fontsize", 10).toUInt();
18+
19+
QsciLexerLua *l = new QsciLexerLua(this);
20+
21+
QsciAPIs* api = new QsciAPIs(l);
22+
23+
//l->setColor(Qt::blue, QsciLexerLua::Keyword);
24+
//l->setColor(QColor(0xff, 0x80, 0x00), QsciLexerLua::Number);
25+
//l->setColor(QColor(0xff, 0x80, 0x00), QsciLexerLua::);
26+
//l->setPaper(QColor(0x0, 0x0, 128));
27+
28+
/*
29+
QFont font = QFont();
30+
font.setFamily(family);
31+
//font.setFixedPitch(true);
32+
font.setPointSize(size);
33+
34+
*/
35+
api->prepare();
36+
//l->setDefaultFont(font);
37+
setLexer(l);
38+
39+
/*
40+
QsciScintilla::setFont(font);
41+
setMarginsFont(font);
42+
*/
43+
44+
// Line Highlight
45+
setCaretLineVisible(true);
46+
//setCaretForegroundColor(QColor("yellow"));
47+
//setCaretLineBackgroundColor(QColor("blue"));
48+
49+
// # Margin 0 is used for line numbers
50+
//QFontMetrics fontmetrics = QFontMetrics(font);
51+
//setMarginsFont(font);
52+
//setMarginWidth(0, fontmetrics.width("0000") + 6);
53+
setMarginLineNumbers(0, true);
54+
//setMarginsBackgroundColor(QColor("blue"));
55+
56+
// setEdgeMode(QsciScintilla::EdgeLine); setEdgeColumn(80); setEdgeColor(QColor("#FF0000"));
57+
58+
setFolding(QsciScintilla::BoxedTreeFoldStyle);
59+
setBraceMatching(QsciScintilla::SloppyBraceMatch);
60+
61+
//setFoldMarginColors(QColor("#99CC66"), QColor("#333300"));
62+
63+
SendScintilla(SCI_SETHSCROLLBAR, 0);
64+
setBraceMatching(SloppyBraceMatch);
65+
66+
QAction* a = new QAction(tr("Open a file"), this);
67+
a->setShortcut(tr("Ctrl+1"));
68+
a->setShortcutContext(Qt::WidgetShortcut);
69+
addAction(a);
70+
connect(a, SIGNAL(triggered()), this, SLOT(load()));
71+
72+
a = new QAction(tr("Save file"), this);
73+
a->setShortcut(tr("Ctrl+2"));
74+
a->setShortcutContext(Qt::WidgetShortcut);
75+
addAction(a);
76+
connect(a, SIGNAL(triggered()), this, SLOT(save()));
77+
78+
a = new QAction(tr("Save to file"), this);
79+
a->setShortcut(tr("Ctrl+3"));
80+
a->setShortcutContext(Qt::WidgetShortcut);
81+
addAction(a);
82+
connect(a, SIGNAL(triggered()), this, SLOT(saveAs()));
83+
}
84+
85+
bool Code::load(QString filename) {
86+
if (filename.isEmpty()) {
87+
filename = QString(".lua");
88+
filename = QFileDialog::getOpenFileName(this, "Open a script",
89+
script_filename, "Lua source (*.lua);;All files (*)");
90+
if (filename.isEmpty())
91+
return false;
92+
}
93+
94+
QFile file(filename);
95+
if (!file.open(QIODevice::ReadOnly)) {
96+
97+
/*
98+
QMessageBox::warning(this, tr("Application error"),
99+
tr("Cannot read file %1\n").arg(filename));
100+
*/
101+
return false;
102+
}
103+
104+
QTextStream os(&file);
105+
QString p = os.readAll();
106+
file.close();
107+
108+
setText(p);
109+
110+
script_filename = filename;
111+
emit scriptLoaded();
112+
113+
return true;
114+
}
115+
116+
bool Code::saveAs(QString filename) {
117+
if (filename.isEmpty()) {
118+
QFileDialog dialog(this, tr("Save a script"), script_filename,
119+
tr("Lua source (*.lua);;All files (*)"));
120+
dialog.setAcceptMode(QFileDialog::AcceptSave);
121+
dialog.setDefaultSuffix("lua");
122+
dialog.selectFile(script_filename);
123+
124+
if (dialog.exec())
125+
filename = dialog.selectedFiles().first();
126+
else
127+
return false;
128+
}
129+
130+
QFile file(filename);
131+
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
132+
QMessageBox::warning(this, tr("Application error"),
133+
tr("Cannot write file %1\n").arg(filename)) \
134+
;
135+
return false;
136+
}
137+
QTextStream os(&file);
138+
os << toPlainText();
139+
file.close();
140+
script_filename = filename;
141+
142+
emit scriptSaved();
143+
144+
return true;
145+
}
146+
147+
bool Code::save() {
148+
if (QString("no_name") == script_filename) {
149+
return saveAs("");
150+
} else {
151+
return saveAs(script_filename);
152+
}
153+
}
154+
155+
void Code::clear() {
156+
script_filename = QString();
157+
QsciScintilla::clear();
158+
}
159+
160+
QString Code::toPlainText() {
161+
return text();
162+
}
163+
164+
void Code::appendLine(QString line) {
165+
append("\n" + line);
166+
SendScintilla(QsciScintilla::SCI_GOTOLINE, toPlainText().lastIndexOf("\n") + 1);
167+
}
168+
169+
void Code::setFont(QString family, int size) {
170+
// qDebug() << " setFont " << family << size;
171+
//XXX set Lexer font here, too.
172+
//QFont *f = new QFont(family, size);
173+
//f->setFixedPitch(true);
174+
//QsciScintilla::setFont(*f);
175+
//QWidget::setFont(*f);
176+
}
177+
178+
void Code::keyPressEvent(QKeyEvent *e) {
179+
QsciScintilla::keyPressEvent(e);
180+
181+
if (e->isAccepted()) {
182+
return;
183+
}
184+
185+
int keyInt = e->key();
186+
Qt::Key key = static_cast<Qt::Key>(keyInt);
187+
188+
if (key == Qt::Key_unknown) {
189+
qDebug() << "Unknown key from a macro probably";
190+
return;
191+
}
192+
193+
// the user have clicked just and only the special keys Ctrl, Shift, Alt, Meta.
194+
if (key == Qt::Key_Control ||
195+
key == Qt::Key_Shift ||
196+
key == Qt::Key_Alt ||
197+
key == Qt::Key_Meta)
198+
{
199+
// qDebug() << "Single click of special key: Ctrl, Shift, Alt or Meta";
200+
// qDebug() << "New KeySequence:" << QKeySequence(keyInt).toString(QKeySequence::NativeText);
201+
// return;
202+
}
203+
204+
// check for a combination of user clicks
205+
Qt::KeyboardModifiers modifiers = e->modifiers();
206+
QString keyText = e->text();
207+
// if the keyText is empty than it's a special key like F1, F5, ...
208+
// qDebug() << "Pressed Key:" << keyText;
209+
210+
QList<Qt::Key> modifiersList;
211+
if (modifiers & Qt::ShiftModifier)
212+
keyInt += Qt::SHIFT;
213+
if (modifiers & Qt::ControlModifier)
214+
keyInt += Qt::CTRL;
215+
if (modifiers & Qt::AltModifier)
216+
keyInt += Qt::ALT;
217+
if (modifiers & Qt::MetaModifier)
218+
keyInt += Qt::META;
219+
220+
QString seq = QKeySequence(keyInt).toString(QKeySequence::NativeText);
221+
222+
// qDebug() << "CodeEditor::keyPressed(" << seq << ")";
223+
224+
emit keyPressed(e);
225+
}

src/src/code.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef CODE_H
2+
#define CODE_H
3+
4+
#include <QSettings>
5+
6+
#include <Qsci/qsciscintilla.h>
7+
8+
class Code : public QsciScintilla
9+
{
10+
Q_OBJECT
11+
public:
12+
explicit Code(QSettings *settings, QWidget *parent = nullptr);
13+
14+
QString script_filename;
15+
16+
public slots:
17+
bool load(QString fileName=QString());
18+
bool saveAs(QString fileName=QString());
19+
bool save();
20+
void clear();
21+
22+
QString toPlainText();
23+
void appendLine(QString line);
24+
25+
void setFont(QString family, int size);
26+
27+
signals:
28+
void scriptLoaded();
29+
void scriptSaved();
30+
void keyPressed(QKeyEvent *e);
31+
32+
protected:
33+
void keyPressEvent(QKeyEvent *e);
34+
35+
};
36+
37+
#endif // CODE_H

0 commit comments

Comments
 (0)