Skip to content

Commit

Permalink
Keep a global zoom level in the ScriptWindow.
Browse files Browse the repository at this point in the history
This allows it to be saved more easily and is probably what would
be expected.
Refs #2522
  • Loading branch information
martyngigg committed Oct 8, 2013
1 parent 3912d17 commit 2d90687
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 75 deletions.
63 changes: 57 additions & 6 deletions Code/Mantid/MantidPlot/src/MultiTabScriptInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
MultiTabScriptInterpreter::MultiTabScriptInterpreter(ScriptingEnv *env, QWidget *parent)
: QTabWidget(parent), Scripted(env), m_last_dir(""),
m_cursor_pos(), m_reportProgress(false), m_recentScriptList(), m_nullScript(new NullScriptFileInterpreter),
m_current(m_nullScript)
m_current(m_nullScript), m_globalZoomLevel(0)
{
connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabSelectionChanged(int)));
}
Expand Down Expand Up @@ -85,7 +85,7 @@ bool MultiTabScriptInterpreter::isExecuting()
*/
void MultiTabScriptInterpreter::newTab(int index, const QString & filename)
{
ScriptFileInterpreter *scriptRunner = new ScriptFileInterpreter(this);
ScriptFileInterpreter *scriptRunner = new ScriptFileInterpreter(this,"ScriptWindow");
scriptRunner->setup(*scriptingEnv(), filename);
scriptRunner->toggleProgressReporting(m_reportProgress);
connect(scriptRunner, SIGNAL(editorModificationChanged(bool)),
Expand All @@ -94,6 +94,12 @@ void MultiTabScriptInterpreter::newTab(int index, const QString & filename)
setCurrentIndex(index);
setTabTitle(scriptRunner, filename); // Make sure the tooltip is set
scriptRunner->setFocus();
scriptRunner->editor()->zoomIn(globalZoomLevel());
connect(scriptRunner->editor(), SIGNAL(textZoomedIn()), this, SLOT(zoomInAllButCurrent()));
connect(scriptRunner->editor(), SIGNAL(textZoomedIn()), this, SLOT(trackZoomIn()));
connect(scriptRunner->editor(), SIGNAL(textZoomedOut()), this, SLOT(zoomOutAllButCurrent()));
connect(scriptRunner->editor(), SIGNAL(textZoomedOut()), this, SLOT(trackZoomOut()));

emit newTabCreated(index);
emit tabCountChanged(count());
}
Expand Down Expand Up @@ -283,17 +289,61 @@ void MultiTabScriptInterpreter::evaluate()
QMessageBox::information(this, "MantidPlot", "Evaluate is not implemented.");
}

/// Increase font size
/// Tracks the global zoom level
void MultiTabScriptInterpreter::trackZoomIn()
{
++m_globalZoomLevel;
}

/// Tracks the global zoom level
void MultiTabScriptInterpreter::trackZoomOut()
{
--m_globalZoomLevel;
}

/// Increase font size on all tabs
void MultiTabScriptInterpreter::zoomIn()
{
m_current->zoomInOnScript();
for(int index = 0; index < count(); ++index)
{
interpreterAt(index)->editor()->zoomIn();
}
}

/**
* @param skipIndex The tab that should be skipped
*/
void MultiTabScriptInterpreter::zoomInAllButCurrent()
{
int skipIndex = this->currentIndex();
for(int i = 0; i < count(); ++i)
{
if(i != skipIndex) interpreterAt(i)->editor()->zoomIn();
}
}
/// Decrease font size

/// Decrease font size on all tabs
void MultiTabScriptInterpreter::zoomOut()
{
m_current->zoomOutOnScript();
for(int i = 0; i < count(); ++i)
{
interpreterAt(i)->editor()->zoomOut();
}
}

/**
* @param skipIndex The tab that should be skipped
*/
void MultiTabScriptInterpreter::zoomOutAllButCurrent()
{
int skipIndex = this->currentIndex();
for(int i = 0; i < count(); ++i)
{
if(i != skipIndex) interpreterAt(i)->editor()->zoomOut();
}
}


/**
* Toggle the progress arrow on/off
* @param state :: The state of the option
Expand Down Expand Up @@ -522,6 +572,7 @@ void MultiTabScriptInterpreter::closeTabAtIndex(int index)
{
ScriptFileInterpreter *interpreter = interpreterAt(index);
interpreter->prepareToClose();
emit tabClosing(index);
removeTab(index);
emit tabClosed(index);
const int nTabs = count();
Expand Down
16 changes: 16 additions & 0 deletions Code/Mantid/MantidPlot/src/MultiTabScriptInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class MultiTabScriptInterpreter : public QTabWidget, Scripted
/// Is a script running in the environment
bool isExecuting();

/// Returns the global zoom level
int globalZoomLevel() const { return m_globalZoomLevel; }

/// this method appends the file names of scripts
///in different tabs to a string and returns
QString saveToString();
Expand All @@ -85,6 +88,8 @@ class MultiTabScriptInterpreter : public QTabWidget, Scripted
signals:
/// Signal that a tab has been created
void newTabCreated(int);
/// Signal that a tab is about to close, parametrised by the index
void tabClosing(int);
/// Signal that a tab has closed, parametrised by the index
void tabClosed(int);
/// Signal that the last tab has closed
Expand Down Expand Up @@ -140,10 +145,19 @@ public slots:
/// Evaluate
void evaluate();

/// Tracks the global zoom level
void trackZoomIn();
/// Tracks the global zoom level
void trackZoomOut();

/// Increase font size
void zoomIn();
/// Increase font size on all tabs except that given
void zoomInAllButCurrent();
/// Decrease font size
void zoomOut();
/// Decrease font size on all tabs except that given
void zoomOutAllButCurrent();

/// Toggle the progress reporting arrow
void toggleProgressReporting(bool on);
Expand Down Expand Up @@ -199,6 +213,8 @@ private slots:
NullScriptFileInterpreter *m_nullScript;
/// A pointer to the current interpreter
ScriptFileInterpreter *m_current;
/// Store the current global zoom level
int m_globalZoomLevel;
};

#endif
16 changes: 3 additions & 13 deletions Code/Mantid/MantidPlot/src/ScriptFileInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* Construct a widget
* @param parent :: The parent widget
*/
ScriptFileInterpreter::ScriptFileInterpreter(QWidget *parent)
ScriptFileInterpreter::ScriptFileInterpreter(QWidget *parent, const QString & settingsGroup)
: QWidget(parent), m_splitter(new QSplitter(Qt::Vertical,this)),
m_editor(new ScriptEditor(this, NULL)),
m_editor(new ScriptEditor(this, NULL,settingsGroup)),
m_messages(new ScriptOutputDisplay), m_status(new QStatusBar),
m_runner()
{
Expand Down Expand Up @@ -249,17 +249,6 @@ void ScriptFileInterpreter::executeSelection(const Script::ExecutionMode mode)
}
}

/// Zoom in on script
void ScriptFileInterpreter::zoomInOnScript()
{
m_editor->zoomIn();
}
/// Zoom out on script
void ScriptFileInterpreter::zoomOutOnScript()
{
m_editor->zoomOut();
}

/// Toggles the progress reports on/off
void ScriptFileInterpreter::toggleProgressReporting(bool state)
{
Expand Down Expand Up @@ -316,6 +305,7 @@ void ScriptFileInterpreter::setupEditor(const ScriptingEnv & environ, const QStr
readFileIntoEditor(identifier);
}
m_editor->setLexer(environ.createCodeLexer());
m_editor->setSettingsGroup("ScriptWindow");
m_editor->padMargin();
m_editor->setAutoMarginResize();
m_editor->enableAutoCompletion();
Expand Down
8 changes: 3 additions & 5 deletions Code/Mantid/MantidPlot/src/ScriptFileInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ScriptFileInterpreter : public QWidget

public:
/// Construct the object
ScriptFileInterpreter(QWidget *parent = NULL);
ScriptFileInterpreter(QWidget *parent = NULL, const QString & settingsGroup = "");
/// Destroy the object
~ScriptFileInterpreter();
/// Make sure we are in a safe state to delete the widget
Expand All @@ -38,6 +38,8 @@ class ScriptFileInterpreter : public QWidget

/// Return the filename of the script in the editor
virtual QString filename() const;
///
inline ScriptEditor *editor() const { return m_editor; }
/// Has the script text been modified
virtual bool isScriptModified() const;
/// Is the script running
Expand Down Expand Up @@ -75,10 +77,6 @@ public slots:
/// Execute the current selection
virtual void executeSelection(const Script::ExecutionMode mode = Script::Asynchronous);

/// Zoom in on script
virtual void zoomInOnScript();
/// Zoom out on script
virtual void zoomOutOnScript();
/// Toggles the progress reports on/off
virtual void toggleProgressReporting(bool state);
/// Toggles the code folding on/off
Expand Down
11 changes: 10 additions & 1 deletion Code/Mantid/MantidPlot/src/ScriptingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
#include "ScriptingWindow.h"
#include "MultiTabScriptInterpreter.h"
#include "ScriptingEnv.h"
#include "ScriptFileInterpreter.h"
#include "pixmaps.h"

// Mantid
#include "MantidKernel/ConfigService.h"
#include "ApplicationWindow.h"

// MantidQt
#include "MantidQtMantidWidgets/ScriptEditor.h"

//Qt
#include <QTextEdit>
#include <QMenuBar>
Expand Down Expand Up @@ -82,6 +87,7 @@ void ScriptingWindow::saveSettings()
settings.setValue("/ProgressArrow", m_toggleProgress->isChecked());
settings.setValue("/LastDirectoryVisited", m_manager->m_last_dir);
settings.setValue("/RecentScripts",m_manager->recentScripts());
settings.setValue("/ZoomLevel",m_manager->globalZoomLevel());
settings.endGroup();
}

Expand All @@ -100,8 +106,9 @@ void ScriptingWindow::readSettings()
}
m_manager->m_last_dir = lastdir;
m_toggleProgress->setChecked(settings.value("ProgressArrow", true).toBool());

m_manager->setRecentScripts(settings.value("/RecentScripts").toStringList());
m_manager->m_globalZoomLevel = settings.value("ZoomLevel",0).toInt();

settings.endGroup();

}
Expand Down Expand Up @@ -532,10 +539,12 @@ void ScriptingWindow::initWindowMenuActions()
m_zoomIn->setShortcut(Qt::SHIFT+Qt::CTRL+Qt::Key_Equal);
m_zoomIn->setShortcut(Qt::CTRL+Qt::Key_Plus);
connect(m_zoomIn, SIGNAL(triggered()), m_manager, SLOT(zoomIn()));
connect(m_zoomIn, SIGNAL(triggered()), m_manager, SLOT(trackZoomIn()));

m_zoomOut = new QAction(("Decrease font size"), this);
m_zoomOut->setShortcut(QKeySequence::ZoomOut);
connect(m_zoomOut, SIGNAL(triggered()), m_manager, SLOT(zoomOut()));
connect(m_zoomOut, SIGNAL(triggered()), m_manager, SLOT(trackZoomOut()));

// Toggle the progress arrow
m_toggleProgress = new QAction(tr("&Progress Reporting"), this);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/ScriptingWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private slots:
void initExecMenuActions();
/// Create the window menu actions
void initWindowMenuActions();

/// Returns the current execution mode
Script::ExecutionMode getExecutionMode() const;

Expand Down Expand Up @@ -144,7 +145,6 @@ private slots:
/// Window actions
QAction *m_alwaysOnTop, *m_hide, *m_zoomIn, *m_zoomOut,
*m_toggleProgress, *m_toggleFolding;

/// Change scripting language
QAction *m_scripting_lang;
/// Flag to define whether we should accept a close event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,21 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS ScriptEditor : public QsciScintilla

public:
/// Constructor
ScriptEditor(QWidget* parent = 0, QsciLexer* lexer = NULL);
ScriptEditor(QWidget* parent = 0, QsciLexer* lexer = NULL,
const QString & settingsGroup = "");
///Destructor
~ScriptEditor();

// Set a new code lexer for this object
/// Set the name of the group to save the settings for
void setSettingsGroup(const QString & name);
/// Settings group
QString settingsGroup() const;
/// Read settings from persistent store
void readSettings();
/// Write settings from persistent store
void writeSettings();

/// Set a new code lexer for this object
void setLexer(QsciLexer *);
// Make the object resize to margin to fit the contents
void setAutoMarginResize();
Expand Down Expand Up @@ -179,6 +189,10 @@ public slots:
void undoAvailable(bool);
/// Inform observers that redo information is available
void redoAvailable(bool);
/// Emitted when a zoom in is requested
void textZoomedIn();
/// Emitted when a zoom in is requested
void textZoomedOut();

protected:
/// Write to the given device
Expand All @@ -187,12 +201,6 @@ public slots:
private slots:

private:
/// Settings group
QString settingsGroup() const;
/// Read settings from persistent store
void readSettings();
/// Write settings from persistent store
void writeSettings();
/// Forward a KeyPress event to QsciScintilla base class. Necessary due to bug in QsciScintilla
void forwardKeyPressToBase(QKeyEvent *event);

Expand All @@ -215,6 +223,8 @@ private slots:
int m_zoomLevel;
/// A pointer to the find replace dialog
FindReplaceDialog *m_findDialog;
/// Name of group that the settings are stored under
QString m_settingsGroup;
};


Expand Down

0 comments on commit 2d90687

Please sign in to comment.