Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -230,6 +230,8 @@ set (mainwindow_pythonconsole_sources
mainwindow/pythonconsole/pythonhighlighter.h
mainwindow/pythonconsole/pythonoutput.cpp
mainwindow/pythonconsole/pythonoutput.h
mainwindow/pythonconsole/zoomableplaintextedit.cpp
mainwindow/pythonconsole/zoomableplaintextedit.h
)
list (APPEND appleseed.studio_sources
${mainwindow_pythonconsole_sources}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <QApplication>
#include <QMessageBox>
#include <QSplitter>
#include <QTextDocumentFragment>
#include <QToolBar>
#include <QVBoxLayout>
#include <QWheelEvent>
Expand Down Expand Up @@ -75,8 +76,8 @@ PythonConsoleWidget::PythonConsoleWidget(QWidget* parent)

m_output = new PythonOutput(console_body);

console_body->addWidget(m_input);
console_body->addWidget(m_output);
console_body->addWidget(m_input);

m_action_new_file =
new QAction(load_icons("project_new"), "New Python Script", this);
Expand Down Expand Up @@ -135,6 +136,8 @@ PythonConsoleWidget::PythonConsoleWidget(QWidget* parent)
toolbar->addAction(m_action_execute_all);
toolbar->addAction(m_action_clear_selection);

connect(m_input, SIGNAL(selectionChanged()), this, SLOT(slot_change_exec_selection_button_state()));

QVBoxLayout* layout = new QVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(toolbar);
Expand Down Expand Up @@ -188,6 +191,12 @@ void PythonConsoleWidget::slot_clear_output()
m_output->clear();
}

void PythonConsoleWidget::slot_change_exec_selection_button_state()
{
const bool is_enabled = m_input->textCursor().selection().isEmpty();
m_action_execute_selection->setEnabled(is_enabled);
}

void PythonConsoleWidget::slot_new_file()
{
if (!can_close_file())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class PythonConsoleWidget

void slot_file_changed();

void slot_change_exec_selection_button_state();

private:
QPlainTextEdit* m_output;
QPlainTextEdit* m_input;
Expand Down
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)
: ZoomablePlainTextEdit(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)
event->setModifiers(event->modifiers() & ~Qt::ShiftModifier);
ZoomablePlainTextEdit::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/zoomableplaintextedit.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 ZoomablePlainTextEdit
{
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ void PythonSyntaxHighlighter::initializeRules()
// FF: originally: r'\bclass\b\s*(\w+)'
rules.append(HighlightingRule("\\bclass\\b\\s*(\\w+)", 1, basicStyles.value("defclass")));

// From '#' until a newline
// FF: originally: r'#[^\\n]*'
rules.append(HighlightingRule("#[^\\n]*", 0, basicStyles.value("comment")));

// Numeric literals
rules.append(HighlightingRule("\\b[+-]?[0-9]+[lL]?\\b", 0, basicStyles.value("numbers"))); // r'\b[+-]?[0-9]+[lL]?\b'
rules.append(HighlightingRule("\\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\\b", 0, basicStyles.value("numbers"))); // r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b'
rules.append(HighlightingRule("\\b[+-]?[0-9]+(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b", 0, basicStyles.value("numbers"))); // r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b'

// From '#' until a newline
// FF: originally: r'#[^\\n]*'
rules.append(HighlightingRule("#[^\\n]*", 0, basicStyles.value("comment")));
}

void PythonSyntaxHighlighter::highlightBlock(const QString &text)
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)
: ZoomablePlainTextEdit(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/zoomableplaintextedit.h"

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

class PythonOutput
: public QPlainTextEdit
: public ZoomablePlainTextEdit
{
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

//
// 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 "zoomableplaintextedit.h"

namespace appleseed {
namespace studio {

ZoomablePlainTextEdit::ZoomablePlainTextEdit(QWidget* parent)
: QPlainTextEdit(parent)
{
}

void ZoomablePlainTextEdit::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 ZoomablePlainTextEdit::wheelEvent(QWheelEvent* event)
{
if (event->modifiers() & Qt::ControlModifier)
change_font_size(event->delta() / 120);
else
QPlainTextEdit::wheelEvent(event);
}

void ZoomablePlainTextEdit::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
Loading