minor code cleanup

master
shaina7837 2014-08-18 09:43:43 +05:30
parent 91ed8723c3
commit b54710404a
6 changed files with 41 additions and 51 deletions

View File

@ -47,6 +47,7 @@ public slots:
virtual void paste(){ } virtual void paste(){ }
virtual void onTextChanged() { } virtual void onTextChanged() { }
virtual void initFont(const QString&, uint){ } virtual void initFont(const QString&, uint){ }
private: private:
Highlighter *highlighter; Highlighter *highlighter;
QSize initialSizeHint; QSize initialSizeHint;

View File

@ -183,38 +183,47 @@ QString LegacyEditor::toPlainText()
{ {
return textedit->toPlainText(); return textedit->toPlainText();
} }
QTextCursor LegacyEditor::textCursor() const QTextCursor LegacyEditor::textCursor() const
{ {
return textedit->textCursor(); return textedit->textCursor();
} }
void LegacyEditor::setTextCursor (const QTextCursor &cursor) void LegacyEditor::setTextCursor (const QTextCursor &cursor)
{ {
textedit->setTextCursor(cursor); textedit->setTextCursor(cursor);
} }
void LegacyEditor::insertPlainText(const QString &text) void LegacyEditor::insertPlainText(const QString &text)
{ {
textedit->insertPlainText(text); textedit->insertPlainText(text);
} }
void LegacyEditor::undo() void LegacyEditor::undo()
{ {
textedit->undo(); textedit->undo();
} }
void LegacyEditor::redo() void LegacyEditor::redo()
{ {
textedit->redo(); textedit->redo();
} }
void LegacyEditor::cut() void LegacyEditor::cut()
{ {
textedit->cut(); textedit->cut();
} }
void LegacyEditor::copy() void LegacyEditor::copy()
{ {
textedit->copy(); textedit->copy();
} }
void LegacyEditor::paste() void LegacyEditor::paste()
{ {
textedit->paste(); textedit->paste();
} }
LegacyEditor::~LegacyEditor() LegacyEditor::~LegacyEditor()
{ {
delete highlighter; delete highlighter;

View File

@ -169,20 +169,20 @@ MainWindow::MainWindow(const QString &filename)
{ {
setupUi(this); setupUi(this);
editortype = Preferences::inst()->getValue("editor/editortype").toString(); editortype = Preferences::inst()->getValue("editor/editortype").toString();
useScintilla = (editortype == "QScintilla Editor"); useScintilla = (editortype == "QScintilla Editor");
#ifdef USE_SCINTILLA_EDITOR #ifdef USE_SCINTILLA_EDITOR
if (useScintilla) { if (useScintilla) {
editor = new ScintillaEditor(editorDockContents); editor = new ScintillaEditor(editorDockContents);
this->editActionIndent->setVisible(false); this->editActionIndent->setVisible(false);
this->editActionUnindent->setVisible(false); this->editActionUnindent->setVisible(false);
this->editActionComment->setVisible(false); this->editActionComment->setVisible(false);
this->editActionUncomment->setVisible(false); this->editActionUncomment->setVisible(false);
} }
else else
#endif #endif
editor = new LegacyEditor(editorDockContents); editor = new LegacyEditor(editorDockContents);
editorDockContents->layout()->addWidget(editor); editorDockContents->layout()->addWidget(editor);
@ -432,6 +432,7 @@ MainWindow::MainWindow(const QString &filename)
editor, SLOT(setHighlightScheme(const QString&))); editor, SLOT(setHighlightScheme(const QString&)));
Preferences::inst()->apply(); Preferences::inst()->apply();
//find and replace panel
connect(this->findTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectFindType(int))); connect(this->findTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectFindType(int)));
connect(this->findInputField, SIGNAL(textChanged(QString)), this, SLOT(findString(QString))); connect(this->findInputField, SIGNAL(textChanged(QString)), this, SLOT(findString(QString)));
connect(this->findInputField, SIGNAL(returnPressed()), this->nextButton, SLOT(animateClick())); connect(this->findInputField, SIGNAL(returnPressed()), this->nextButton, SLOT(animateClick()));
@ -486,8 +487,7 @@ MainWindow::MainWindow(const QString &filename)
clearCurrentOutput(); clearCurrentOutput();
} }
void void MainWindow::loadViewSettings(){
MainWindow::loadViewSettings(){
QSettings settings; QSettings settings;
if (settings.value("view/showEdges").toBool()) { if (settings.value("view/showEdges").toBool()) {
viewActionShowEdges->setChecked(true); viewActionShowEdges->setChecked(true);
@ -514,8 +514,7 @@ MainWindow::loadViewSettings(){
updateUndockMode(settings.value("advanced/undockableWindows").toBool()); updateUndockMode(settings.value("advanced/undockableWindows").toBool());
} }
void void MainWindow::loadDesignSettings()
MainWindow::loadDesignSettings()
{ {
QSettings settings; QSettings settings;
if (settings.value("design/autoReload").toBool()) { if (settings.value("design/autoReload").toBool()) {
@ -607,8 +606,8 @@ void MainWindow::requestOpenFile(const QString &filename)
one is not empty. Otherwise the current window content is overwritten. one is not empty. Otherwise the current window content is overwritten.
Any check whether to replace the content have to be made before. Any check whether to replace the content have to be made before.
*/ */
void
MainWindow::openFile(const QString &new_filename) void MainWindow::openFile(const QString &new_filename)
{ {
if (MainWindow::mdiMode) { if (MainWindow::mdiMode) {
if (!editor->toPlainText().isEmpty()) { if (!editor->toPlainText().isEmpty()) {
@ -638,8 +637,7 @@ MainWindow::openFile(const QString &new_filename)
clearCurrentOutput(); clearCurrentOutput();
} }
void void MainWindow::setFileName(const QString &filename)
MainWindow::setFileName(const QString &filename)
{ {
if (filename.isEmpty()) { if (filename.isEmpty()) {
this->fileName.clear(); this->fileName.clear();
@ -1107,6 +1105,7 @@ void MainWindow::show_examples()
{ {
bool found_example = false; bool found_example = false;
QStringList categories; QStringList categories;
//categories in File menu item - Examples
categories << "Basics" << "Shapes" << "Extrusion" << "Advanced"; categories << "Basics" << "Shapes" << "Extrusion" << "Advanced";
foreach (const QString &cat, categories){ foreach (const QString &cat, categories){
@ -1498,10 +1497,8 @@ void MainWindow::compileTopLevelDocument()
this->root_module = NULL; this->root_module = NULL;
this->root_module = parse(fulltext.c_str(), this->root_module = parse(fulltext.c_str(),
this->fileName.isEmpty() ? this->fileName.isEmpty() ? "" :
"" : QFileInfo(this->fileName).absolutePath().toLocal8Bit(), false);
QFileInfo(this->fileName).absolutePath().toLocal8Bit(),
false);
updateCamera(); updateCamera();
} }
@ -1932,8 +1929,9 @@ void MainWindow::actionExportCSG()
} }
QString csg_filename = QFileDialog::getSaveFileName(this, "Export CSG File", QString csg_filename = QFileDialog::getSaveFileName(this, "Export CSG File",
this->fileName.isEmpty() ? "Untitled.csg" : QFileInfo(this->fileName).baseName()+".csg", this->fileName.isEmpty() ? "Untitled.csg" : QFileInfo(this->fileName).baseName()+".csg",
"CSG Files (*.csg)"); "CSG Files (*.csg)");
if (csg_filename.isEmpty()) { if (csg_filename.isEmpty()) {
PRINT("No filename specified. CSG export aborted."); PRINT("No filename specified. CSG export aborted.");
clearCurrentOutput(); clearCurrentOutput();
@ -2392,7 +2390,8 @@ void MainWindow::consoleOutput(const std::string &msg, void *userdata)
// originates in a worker thread. // originates in a worker thread.
MainWindow *thisp = static_cast<MainWindow*>(userdata); MainWindow *thisp = static_cast<MainWindow*>(userdata);
QMetaObject::invokeMethod(thisp->console, "append", Qt::QueuedConnection, QMetaObject::invokeMethod(thisp->console, "append", Qt::QueuedConnection,
Q_ARG(QString, QString::fromLocal8Bit(msg.c_str()))); Q_ARG(QString, QString::fromLocal8Bit(msg.c_str())));
if (thisp->procevents) QApplication::processEvents(); if (thisp->procevents) QApplication::processEvents();
} }
@ -2409,6 +2408,7 @@ void MainWindow::clearCurrentOutput()
void MainWindow::openCSGSettingsChanged() void MainWindow::openCSGSettingsChanged()
{ {
#ifdef ENABLE_OPENCSG #ifdef ENABLE_OPENCSG
OpenCSG::setOption(OpenCSG::AlgorithmSetting, Preferences::inst()->getValue("advanced/forceGoldfeather").toBool() ? OpenCSG::Goldfeather : OpenCSG::Automatic); OpenCSG::setOption(OpenCSG::AlgorithmSetting, Preferences::inst()->getValue("advanced/forceGoldfeather").toBool() ?
OpenCSG::Goldfeather : OpenCSG::Automatic);
#endif #endif
} }

View File

@ -2,12 +2,10 @@
ScadLexer::ScadLexer(QObject *parent) ScadLexer::ScadLexer(QObject *parent)
: QsciLexerCPP(parent) : QsciLexerCPP(parent)
{ { }
}
ScadLexer::~ScadLexer() ScadLexer::~ScadLexer()
{ { }
}
const char *ScadLexer::language() const const char *ScadLexer::language() const
{ {
@ -17,7 +15,7 @@ const char *ScadLexer::language() const
const char *ScadLexer::keywords(int set) const const char *ScadLexer::keywords(int set) const
{ {
if (set == 1) if (set == 1)
return "if else for module function intersection_for assign echo search " return "if else for module function intersection_for assign echo search "
" str let true false "; // -> Style: Keyword " str let true false "; // -> Style: Keyword

View File

@ -19,7 +19,6 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
qsci->setUtf8(true); qsci->setUtf8(true);
preferenceEditorOption = Preferences::inst()->getValue("editor/syntaxhighlight").toString(); preferenceEditorOption = Preferences::inst()->getValue("editor/syntaxhighlight").toString();
lexer = new ScadLexer(this); lexer = new ScadLexer(this);
// initFont();
initLexer(); initLexer();
initMargin(); initMargin();
qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4); qsci->setFolding(QsciScintilla::BoxedTreeFoldStyle, 4);
@ -27,22 +26,7 @@ ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
this->setHighlightScheme(preferenceEditorOption); this->setHighlightScheme(preferenceEditorOption);
} }
void ScintillaEditor::indentSelection()
{
}
void ScintillaEditor::unindentSelection()
{
}
void ScintillaEditor::commentSelection()
{
}
void ScintillaEditor::uncommentSelection()
{
}
void ScintillaEditor::setPlainText(const QString &text) void ScintillaEditor::setPlainText(const QString &text)
{ {
qsci->setText(text); qsci->setText(text);
@ -76,6 +60,7 @@ void ScintillaEditor::unhighlightLastError()
qsci->markerDeleteAll(markerNumber); qsci->markerDeleteAll(markerNumber);
} }
//Editor themes
void ScintillaEditor::forLightBackground() void ScintillaEditor::forLightBackground()
{ {
lexer->setPaper("#fff"); lexer->setPaper("#fff");
@ -234,6 +219,7 @@ void ScintillaEditor::initLexer()
{ {
qsci->setLexer(lexer); qsci->setLexer(lexer);
} }
void ScintillaEditor::initMargin() void ScintillaEditor::initMargin()
{ {
QFontMetrics fontmetrics = QFontMetrics(qsci->font()); QFontMetrics fontmetrics = QFontMetrics(qsci->font());

View File

@ -12,8 +12,8 @@
class ScintillaEditor : public EditorInterface class ScintillaEditor : public EditorInterface
{ {
public: public:
ScintillaEditor(QWidget *parent); ScintillaEditor(QWidget *parent);
QsciScintilla *qsci; QsciScintilla *qsci;
QString toPlainText(); QString toPlainText();
void initMargin(); void initMargin();
void initLexer(); void initLexer();
@ -28,10 +28,6 @@ public:
public slots: public slots:
void zoomIn(); void zoomIn();
void zoomOut(); void zoomOut();
void indentSelection();
void unindentSelection();
void commentSelection();
void uncommentSelection();
void setPlainText(const QString&); void setPlainText(const QString&);
bool isContentModified(); bool isContentModified();
void highlightError(int); void highlightError(int);
@ -47,7 +43,7 @@ public slots:
void initFont(const QString&, uint); void initFont(const QString&, uint);
private: private:
QVBoxLayout *scintillaLayout; QVBoxLayout *scintillaLayout;
const int indicatorNumber = 1; const int indicatorNumber = 1;
const int markerNumber = 2; const int markerNumber = 2;
ScadLexer *lexer; ScadLexer *lexer;