Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/appleseed.studio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ source_group ("mainwindow\\project" FILES
)

set (mainwindow_pythonconsole_sources
mainwindow/pythonconsole/fontsizechangeable.cpp
mainwindow/pythonconsole/fontsizechangeable.h
mainwindow/pythonconsole/linenumberarea.cpp
mainwindow/pythonconsole/linenumberarea.h
mainwindow/pythonconsole/outputredirector.cpp
Expand Down
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
61 changes: 61 additions & 0 deletions src/appleseed.studio/mainwindow/pythonconsole/fontsizechangeable.h
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
Copy link
Copy Markdown
Member

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?

: 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
29 changes: 4 additions & 25 deletions src/appleseed.studio/mainwindow/pythonconsole/pythoneditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace appleseed {
namespace studio {

PythonEditor::PythonEditor(QWidget* parent)
: QPlainTextEdit(parent)
: FontSizeChangeable(parent)
{
setObjectName("python_editor");
setUndoRedoEnabled(true);
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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();
}
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 4 additions & 13 deletions src/appleseed.studio/mainwindow/pythonconsole/pythoneditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#ifndef APPLESEED_STUDIO_MAINWINDOW_PYTHONCONSOLE_PYTHONEDITOR_H
#define APPLESEED_STUDIO_MAINWINDOW_PYTHONCONSOLE_PYTHONEDITOR_H

// appleseed.studio headers.
#include "mainwindow/pythonconsole/fontsizechangeable.h"

// Qt headers.
#include <QObject>
#include <QPlainTextEdit>
Expand All @@ -38,17 +41,14 @@
#include <string>

// Forward declarations.
class QKeyEvent;
class QResizeEvent;
class QWheelEvent;
class QWidget;
namespace appleseed { namespace studio { class LineNumberArea; } }

namespace appleseed {
namespace studio {

class PythonEditor
: public QPlainTextEdit
: public FontSizeChangeable
{
Q_OBJECT

Expand All @@ -59,15 +59,8 @@ class PythonEditor
// Event used to update line number area.
void resizeEvent(QResizeEvent* event);

// Event used for indentation and font size change.
void keyPressEvent(QKeyEvent* event);

// Event used to change font size on wheel rotation.
void wheelEvent(QWheelEvent* event);

signals:
void fontChanged(QFont);

private slots:
void slot_highlight_current_line();

Expand All @@ -79,8 +72,6 @@ class PythonEditor
void indent();
void indent_like_previous(const std::string& previous);
void insert_spaces(const size_t count);

void change_font_size(const int delta);
};

} // namespace studio
Expand Down
33 changes: 1 addition & 32 deletions src/appleseed.studio/mainwindow/pythonconsole/pythonoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@
// Interface header.
#include "pythonoutput.h"

// Qt headers.
#include <QApplication>

namespace appleseed {
namespace studio {

PythonOutput::PythonOutput(QWidget* parent)
: QPlainTextEdit(parent)
: FontSizeChangeable(parent)
{
setObjectName("python_output");
setUndoRedoEnabled(false);
Expand All @@ -47,33 +44,5 @@ PythonOutput::PythonOutput(QWidget* parent)
Qt::TextSelectableByKeyboard);
}

void PythonOutput::keyPressEvent(QKeyEvent* event)
{
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);
}

void PythonOutput::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 PythonOutput::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);
}

} // namespace studio
} // namespace appleseed
15 changes: 4 additions & 11 deletions src/appleseed.studio/mainwindow/pythonconsole/pythonoutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#ifndef APPLESEED_STUDIO_MAINWINDOW_PYTHONCONSOLE_PYTHONOUTPUT_H
#define APPLESEED_STUDIO_MAINWINDOW_PYTHONCONSOLE_PYTHONOUTPUT_H

// appleseed.studio headers.
#include "mainwindow/pythonconsole/fontsizechangeable.h"

// Qt headers.
#include <QObject>
#include <QPlainTextEdit>
Expand All @@ -40,22 +43,12 @@ namespace appleseed {
namespace studio {

class PythonOutput
: public QPlainTextEdit
: public FontSizeChangeable
{
Q_OBJECT

public:
explicit PythonOutput(QWidget* parent);

protected:
// Event used for indentation and font size change.
void keyPressEvent(QKeyEvent* event);

// Event used to change font size on wheel rotation.
void wheelEvent(QWheelEvent* event);

private:
void change_font_size(const int delta);
};

} // namespace studio
Expand Down