Merge branch 'master' of https://github.com/josefpavlik/openscad into josefpavlik-master
This commit is contained in:
commit
5f4ec8d206
3 changed files with 152 additions and 1 deletions
|
|
@ -218,6 +218,7 @@ MainWindow::MainWindow(const QString &filename)
|
|||
Preferences::inst()->fireEditorConfigChanged();
|
||||
}
|
||||
#endif
|
||||
connect(editor, SIGNAL(previewRequest()), this, SLOT(actionRenderPreview()));
|
||||
|
||||
editorDockContents->layout()->addWidget(editor);
|
||||
|
||||
|
|
@ -1593,7 +1594,6 @@ void MainWindow::findBufferChanged() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::eventFilter(QObject* obj, QEvent *event)
|
||||
{
|
||||
if (obj == find_panel)
|
||||
|
|
@ -1803,9 +1803,13 @@ void MainWindow::csgReloadRender()
|
|||
|
||||
void MainWindow::actionRenderPreview()
|
||||
{
|
||||
static bool preview_requested;
|
||||
|
||||
preview_requested=true;
|
||||
if (GuiLocker::isLocked()) return;
|
||||
GuiLocker::lock();
|
||||
autoReloadTimer->stop();
|
||||
preview_requested=false;
|
||||
setCurrentOutput();
|
||||
|
||||
PRINT("Parsing design (AST generation)...");
|
||||
|
|
@ -1813,6 +1817,12 @@ void MainWindow::actionRenderPreview()
|
|||
this->afterCompileSlot = "csgRender";
|
||||
this->procevents = !viewActionAnimate->isChecked();
|
||||
compile(false);
|
||||
if (preview_requested) {
|
||||
// if the action was called when the gui was locked, we must request it one more time
|
||||
// however, it's not possible to call it directly NOR make the loop
|
||||
// it must be called from the mainloop
|
||||
QTimer::singleShot(0, this, SLOT(actionRenderPreview()));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::csgRender()
|
||||
|
|
|
|||
|
|
@ -149,6 +149,7 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
|
|||
|
||||
connect(qsci, SIGNAL(textChanged()), this, SIGNAL(contentsChanged()));
|
||||
connect(qsci, SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool)));
|
||||
qsci->installEventFilter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -602,3 +603,136 @@ QString ScintillaEditor::selectedText()
|
|||
{
|
||||
return qsci->selectedText();
|
||||
}
|
||||
|
||||
bool ScintillaEditor::eventFilter(QObject* obj, QEvent *e)
|
||||
{
|
||||
static bool wasChanged=false;
|
||||
|
||||
if (obj != qsci) return EditorInterface::eventFilter(obj, e);
|
||||
|
||||
if ( e->type()==QEvent::KeyPress
|
||||
|| e->type()==QEvent::KeyRelease
|
||||
) {
|
||||
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
|
||||
|
||||
if (ke->key()==Qt::Key_Alt && ke->type()==QEvent::KeyRelease) wasChanged=false;
|
||||
if ( ke->modifiers()==Qt::AltModifier )
|
||||
{
|
||||
switch (ke->key())
|
||||
{
|
||||
case Qt::Key_Left:
|
||||
case Qt::Key_Right:
|
||||
if (e->type()==QEvent::KeyPress) {
|
||||
navigateOnNumber(ke->key());
|
||||
}
|
||||
return true;
|
||||
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Down:
|
||||
if (e->type()==QEvent::KeyPress) {
|
||||
if (modifyNumber(ke->key())) wasChanged=true;
|
||||
}
|
||||
return true;
|
||||
|
||||
case Qt::Key_Backspace:
|
||||
if (e->type()==QEvent::KeyPress && wasChanged) {
|
||||
QTimer::singleShot(0,this,SIGNAL(previewRequest()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ScintillaEditor::navigateOnNumber(int key)
|
||||
{
|
||||
int line, index;
|
||||
qsci->getCursorPosition(&line, &index);
|
||||
QString text=qsci->text(line);
|
||||
QString left=text.left(index);
|
||||
bool dotOnLeft=left.contains(QRegExp("\\.\\d*$"));
|
||||
bool dotJustLeft=index>1 && text[index-2]=='.';
|
||||
bool dotJustRight=text[index]=='.';
|
||||
bool numOnLeft=left.contains(QRegExp("\\d\\.?$")) || left.endsWith("-.");
|
||||
bool numOnRight=text.indexOf(QRegExp("\\.?\\d"),index)==index;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case Qt::Key_Left:
|
||||
if (numOnLeft)
|
||||
qsci->setCursorPosition(line, index-(dotJustLeft?2:1));
|
||||
break;
|
||||
|
||||
case Qt::Key_Right:
|
||||
if (numOnRight)
|
||||
qsci->setCursorPosition(line, index+(dotJustRight?2:1));
|
||||
else if (numOnLeft) {
|
||||
// add trailing zero
|
||||
if (!dotOnLeft) {
|
||||
qsci->insert(".0");
|
||||
index++;
|
||||
} else {
|
||||
qsci->insert("0");
|
||||
}
|
||||
qsci->setCursorPosition(line, index+1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool ScintillaEditor::modifyNumber(int key)
|
||||
{
|
||||
int line, index;
|
||||
qsci->getCursorPosition(&line, &index);
|
||||
QString text=qsci->text(line);
|
||||
|
||||
int lineFrom, indexFrom, lineTo, indexTo;
|
||||
qsci->getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo);
|
||||
bool hadSelection=qsci->hasSelectedText();
|
||||
|
||||
int begin=QRegExp("[-+]?\\d*\\.?\\d*$").indexIn(text.left(index));
|
||||
int end=text.indexOf(QRegExp("[^0-9.]"),index);
|
||||
if (end<0) end=text.length();
|
||||
QString nr=text.mid(begin,end-begin);
|
||||
if ( !(nr.contains(QRegExp("^[-+]?\\d*\\.?\\d*$")) && nr.contains(QRegExp("\\d"))) ) return false;
|
||||
bool sign=nr[0]=='+'||nr[0]=='-';
|
||||
if (nr.endsWith('.')) nr=nr.left(nr.length()-1);
|
||||
int curpos=index-begin;
|
||||
int dotpos=nr.indexOf('.');
|
||||
int decimals=dotpos<0?0:nr.length()-dotpos-1;
|
||||
long long int number=(dotpos<0)?nr.toLongLong():(nr.left(dotpos)+nr.mid(dotpos+1)).toLongLong();
|
||||
int tail=nr.length()-curpos;
|
||||
int exponent=tail-((dotpos>=curpos)?1:0);
|
||||
long long int step=1;
|
||||
for (int i=exponent; i>0; i--) step*=10;
|
||||
|
||||
switch (key) {
|
||||
case Qt::Key_Up: number+=step; break;
|
||||
case Qt::Key_Down: number-=step; break;
|
||||
}
|
||||
bool negative=number<0;
|
||||
if (negative) number=-number;
|
||||
QString newnr=QString::number(number);
|
||||
if (decimals) {
|
||||
if (newnr.length()<=decimals) newnr.prepend(QString(decimals-newnr.length()+1,'0'));
|
||||
newnr=newnr.left(newnr.length()-decimals)+"."+newnr.right(decimals);
|
||||
}
|
||||
if (tail>newnr.length()) {
|
||||
newnr.prepend(QString(tail-newnr.length(),'0'));
|
||||
}
|
||||
if (negative) newnr.prepend('-');
|
||||
else if (sign) newnr.prepend('+');
|
||||
qsci->setSelection(line, begin, line, end);
|
||||
qsci->replaceSelectedText(newnr);
|
||||
|
||||
qsci->selectAll(false);
|
||||
if (hadSelection)
|
||||
{
|
||||
qsci->setSelection(lineFrom, indexFrom, lineTo, indexTo);
|
||||
}
|
||||
qsci->setCursorPosition(line, begin+newnr.length()-tail);
|
||||
emit previewRequest();
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,13 @@ private:
|
|||
QColor readColor(const boost::property_tree::ptree &pt, const std::string name, const QColor defaultColor);
|
||||
void enumerateColorSchemesInPath(colorscheme_set_t &result_set, const fs::path path);
|
||||
colorscheme_set_t enumerateColorSchemes();
|
||||
|
||||
virtual bool eventFilter(QObject* obj, QEvent *event);
|
||||
void navigateOnNumber(int key);
|
||||
bool modifyNumber(int key);
|
||||
|
||||
signals:
|
||||
void previewRequest(void);
|
||||
|
||||
public slots:
|
||||
void zoomIn();
|
||||
|
|
|
|||
Loading…
Reference in a new issue