mirror of
https://github.com/ra3xdh/qucs_s
synced 2025-03-28 21:13:26 +00:00
Merge pull request #534 from iwbnwif/zoom_textdoc
Implement mouse wheel zoom of text documents
This commit is contained in:
commit
9e612955ee
@ -1983,6 +1983,7 @@ void QucsApp::slotChangeView()
|
||||
Doc = (QucsDoc*)d;
|
||||
// update menu entries, etc. if necessary
|
||||
magAll->setDisabled(true);
|
||||
magSel->setDisabled(true);
|
||||
if(cursorLeft->isEnabled())
|
||||
switchSchematicDoc (false);
|
||||
}
|
||||
@ -1991,6 +1992,7 @@ void QucsApp::slotChangeView()
|
||||
Schematic *d = (Schematic*)w;
|
||||
Doc = (QucsDoc*)d;
|
||||
magAll->setDisabled(false);
|
||||
magSel->setDisabled(false);
|
||||
// already in schematic?
|
||||
if(cursorLeft->isEnabled()) {
|
||||
// which mode: schematic or symbol editor ?
|
||||
|
@ -42,11 +42,10 @@ Copyright (C) 2014 by Guilherme Brondani Torri <guitorri@gmail.com>
|
||||
*/
|
||||
TextDoc::TextDoc(QucsApp *App_, const QString& Name_) : QPlainTextEdit(), QucsDoc(App_, Name_)
|
||||
{
|
||||
TextFont = QFont("Courier New");
|
||||
TextFont.setPointSize(QucsSettings.font.pointSize()-1);
|
||||
TextFont.setStyleHint(QFont::Courier);
|
||||
TextFont.setFixedPitch(true);
|
||||
document()->setDefaultFont(TextFont);
|
||||
QFont font("Courier New", QucsSettings.font.pointSize());
|
||||
font.setStyleHint(QFont::Courier);
|
||||
font.setFixedPitch(true);
|
||||
setFont(font);
|
||||
|
||||
simulation = true;
|
||||
Library = "";
|
||||
@ -55,7 +54,6 @@ TextDoc::TextDoc(QucsApp *App_, const QString& Name_) : QPlainTextEdit(), QucsDo
|
||||
devtype = DEV_DEF;
|
||||
|
||||
tmpPosX = tmpPosY = 1; // set to 1 to trigger line highlighting
|
||||
Scale = (float)TextFont.pointSize();
|
||||
setLanguage (Name_);
|
||||
|
||||
viewport()->setFocus();
|
||||
@ -416,37 +414,32 @@ int TextDoc::save ()
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief TextDoc::zoomBy increases/decreases the text font size.
|
||||
* \param s font size scaling factor
|
||||
* \return (required) final scale
|
||||
*
|
||||
* \fixme is the return value being saved on the saveSettings() ?
|
||||
* \brief Zooms the document in and out. Note, the zoom amount is fixed by Qt and the
|
||||
* amount passed is ignored.
|
||||
*/
|
||||
float TextDoc::zoomBy(float s)
|
||||
float TextDoc::zoomBy(float zoom)
|
||||
{
|
||||
if(s == 2.0) {
|
||||
QFont f = document()->defaultFont();
|
||||
f.setPointSize(f.pointSize()*2);
|
||||
document()->setDefaultFont(f);
|
||||
// qucs_actions defines zooming in as > 1.
|
||||
if (zoom > 1.0) {
|
||||
zoomIn();
|
||||
}
|
||||
|
||||
else {
|
||||
QFont f = document()->defaultFont();
|
||||
f.setPointSize(f.pointSize()*s);
|
||||
document()->setDefaultFont(f);
|
||||
zoomOut();
|
||||
}
|
||||
return Scale;
|
||||
|
||||
return zoom;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief TextDoc::showNoZoom resets the font scaling
|
||||
* \brief Resets the font scaling to default.
|
||||
*/
|
||||
void TextDoc::showNoZoom()
|
||||
{
|
||||
TextFont = QFont("Courier New");
|
||||
TextFont.setPointSize(QucsSettings.font.pointSize()-1);
|
||||
TextFont.setStyleHint(QFont::Courier);
|
||||
TextFont.setFixedPitch(true);
|
||||
document()->setDefaultFont(TextFont);
|
||||
// Get a copy of this editor's existing font and apply the default font size to it.
|
||||
QFont tempFont = font();
|
||||
tempFont.setPointSize(QucsSettings.font.pointSize());
|
||||
setFont(tempFont);
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -567,6 +560,27 @@ QString TextDoc::getModuleName (void)
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Handle mouse wheel events
|
||||
* Used to 'zoom' i.e., increase / reduce the font size.
|
||||
*/
|
||||
void TextDoc::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
if (event->modifiers() & Qt::CTRL) {
|
||||
if (event->angleDelta().y() > 0) {
|
||||
zoomIn();
|
||||
}
|
||||
|
||||
else {
|
||||
zoomOut();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
QPlainTextEdit::wheelEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief TextDoc::highlightCurrentLine mark the current line
|
||||
*/
|
||||
|
@ -53,8 +53,8 @@ public:
|
||||
void setName (const QString&);
|
||||
bool load ();
|
||||
int save ();
|
||||
float zoomBy (float);
|
||||
void showNoZoom ();
|
||||
virtual float zoomBy (float zoom) override;
|
||||
virtual void showNoZoom () override;
|
||||
void becomeCurrent (bool);
|
||||
bool loadSimulationTime (QString&);
|
||||
void commentSelected ();
|
||||
@ -63,8 +63,7 @@ public:
|
||||
void setLanguage (const QString&);
|
||||
QString getModuleName (void);
|
||||
|
||||
|
||||
QFont TextFont;
|
||||
virtual void wheelEvent(QWheelEvent* event) override;
|
||||
|
||||
bool simulation; // simulation or module
|
||||
QString Library; // library this document belongs to
|
||||
|
Loading…
x
Reference in New Issue
Block a user