-
Notifications
You must be signed in to change notification settings - Fork 350
Python console minor issues #1513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
f9d179e
ce0d81c
247d9b1
0475557
b11c06c
02d32f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
|
|
||
| // | ||
| // This source file is part of appleseed. | ||
| // Visit http://appleseedhq.net/ for additional information and resources. | ||
| // | ||
| // This software is released under the MIT license. | ||
| // | ||
| // Copyright (c) 2017 Gleb Mishchenko, The appleseedhq Organization | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| // Interface header. | ||
| #include "fontsizechangeable.h" | ||
|
|
||
| namespace appleseed { | ||
| namespace studio { | ||
|
|
||
| FontSizeChangeable::FontSizeChangeable(QWidget* parent) | ||
| : QPlainTextEdit(parent) | ||
| { | ||
| } | ||
|
|
||
| void FontSizeChangeable::keyPressEvent(QKeyEvent* event) | ||
| { | ||
| if (event->modifiers() & Qt::ControlModifier && | ||
| (event->key() == Qt::Key_Plus || event->key() == Qt::Key_Equal)) | ||
| change_font_size(1); | ||
| else if (event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_Minus) | ||
| change_font_size(-1); | ||
| else if (event->modifiers() & Qt::ControlModifier && event->key() == Qt::Key_0) | ||
| change_font_size(QFont().pointSize() - font().pointSize()); | ||
| else | ||
| QPlainTextEdit::keyPressEvent(event); | ||
| } | ||
|
|
||
| void FontSizeChangeable::wheelEvent(QWheelEvent* event) | ||
| { | ||
| if (event->modifiers() & Qt::ControlModifier) | ||
| // Minus here because if you turn wheel up delta is negative | ||
| // while font should be incremented. | ||
| change_font_size(- event->delta() / 120); | ||
| else | ||
| QPlainTextEdit::wheelEvent(event); | ||
| } | ||
|
|
||
| void FontSizeChangeable::change_font_size(const int delta) | ||
| { | ||
| int new_font_size = font().pointSize() + delta; | ||
| QFont new_font = font(); | ||
| new_font.setPointSize(new_font_size); | ||
| setFont(new_font); | ||
| emit(fontChanged(new_font)); | ||
| } | ||
|
|
||
| } // namespace studio | ||
| } // namespace appleseed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
|
|
||
| // | ||
| // This source file is part of appleseed. | ||
| // Visit http://appleseedhq.net/ for additional information and resources. | ||
| // | ||
| // This software is released under the MIT license. | ||
| // | ||
| // Copyright (c) 2017 Gleb Mishchenko, The appleseedhq Organization | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| #ifndef APPLESEED_STUDIO_MAINWINDOW_PYTHONCONSOLE_FONTSIZECHANGEABLE_H | ||
| #define APPLESEED_STUDIO_MAINWINDOW_PYTHONCONSOLE_FONTSIZECHANGEABLE_H | ||
|
|
||
| // Qt headers. | ||
| #include <QObject> | ||
| #include <QPlainTextEdit> | ||
|
|
||
| namespace appleseed { | ||
| namespace studio { | ||
|
|
||
| class FontSizeChangeable | ||
| : public QPlainTextEdit | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| FontSizeChangeable(QWidget* parent); | ||
|
|
||
| protected: | ||
| void keyPressEvent(QKeyEvent* event); | ||
| void wheelEvent(QWheelEvent* event); | ||
|
|
||
| private: | ||
| void change_font_size(const int delta); | ||
|
|
||
| signals: | ||
| void fontChanged(QFont); | ||
| }; | ||
|
|
||
| } // namespace studio | ||
| } // namespace appleseed | ||
|
|
||
| #endif // !APPLESEED_STUDIO_MAINWINDOW_PYTHONCONSOLE_FONTSIZECHANGEABLE_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,7 @@ namespace appleseed { | |
| namespace studio { | ||
|
|
||
| PythonEditor::PythonEditor(QWidget* parent) | ||
| : QPlainTextEdit(parent) | ||
| : FontSizeChangeable(parent) | ||
| { | ||
| setObjectName("python_editor"); | ||
| setUndoRedoEnabled(true); | ||
|
|
@@ -76,13 +76,11 @@ void PythonEditor::keyPressEvent(QKeyEvent* event) | |
| { | ||
| if (event->key() == Qt::Key_Tab) | ||
| insert_spaces(4); | ||
| else if (event->key() == Qt::Key_Plus || event->key() == Qt::Key_Equal) | ||
| change_font_size(1); | ||
| else if (event->key() == Qt::Key_Minus) | ||
| change_font_size(-1); | ||
| else | ||
| { | ||
| QPlainTextEdit::keyPressEvent(event); | ||
| if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you find the root cause of the problem causing Shift+Enter inserting "lines within the line"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think shift+enter insert something like soft return in Microsoft Word (https://www.computerhope.com/jargon/s/softretu.htm) but I can't find anything in docs
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've read it too. It's similar to how I solved it but my solution is simpler. I just unset shift modifier in case shift+enter is pressed |
||
| event->setModifiers(event->modifiers() & ~Qt::ShiftModifier); | ||
| FontSizeChangeable::keyPressEvent(event); | ||
| if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) | ||
| indent(); | ||
| } | ||
|
|
@@ -130,25 +128,6 @@ void PythonEditor::insert_spaces(const size_t count) | |
| insertPlainText(spaces.c_str()); | ||
| } | ||
|
|
||
| void PythonEditor::wheelEvent(QWheelEvent* event) | ||
| { | ||
| if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) | ||
| // Minus here because if you turn wheel up delta is negative | ||
| // while font should be incremented. | ||
| change_font_size(- event->delta() / 120); | ||
| else | ||
| QPlainTextEdit::wheelEvent(event); | ||
| } | ||
|
|
||
| void PythonEditor::change_font_size(const int delta) | ||
| { | ||
| int new_font_size = font().pointSize() + delta; | ||
| QFont new_font = font(); | ||
| new_font.setPointSize(new_font_size); | ||
| setFont(new_font); | ||
| emit(fontChanged(new_font)); | ||
| } | ||
|
|
||
| void PythonEditor::slot_highlight_current_line() | ||
| { | ||
| QTextEdit::ExtraSelection selection; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could call this class ZoomablePlainTextEdit?