Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Cantor
Commits
1f38382f
Commit
1f38382f
authored
May 27, 2020
by
Nikita Sirgienko
Browse files
[T12843][GSoC 2020] Add zoom widget
parent
b2d5ef8d
Pipeline
#21407
passed with stage
in 19 minutes and 54 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/cantor_part.cpp
View file @
1f38382f
...
...
@@ -22,6 +22,8 @@
#include
<config-cantor.h>
#include
<array>
#include
"cantor_part.h"
#include
"lib/assistant.h"
#include
"lib/backend.h"
...
...
@@ -45,6 +47,7 @@
#include
<KRun>
#include
<KStandardAction>
#include
<KToggleAction>
#include
<KSelectAction>
#include
<KXMLGUIFactory>
#include
<KZip>
...
...
@@ -59,7 +62,8 @@
#include
<QTextStream>
#include
<QTextEdit>
#include
<QTimer>
#include
<QRegularExpression>
#include
<QComboBox>
//A concrete implementation of the WorksheetAccesssInterface
class
WorksheetAccessInterfaceImpl
:
public
Cantor
::
WorksheetAccessInterface
...
...
@@ -223,6 +227,22 @@ CantorPart::CantorPart( QWidget *parentWidget, QObject *parent, const QVariantLi
connect
(
m_evaluate
,
&
QAction
::
triggered
,
this
,
&
CantorPart
::
evaluateOrInterrupt
);
m_editActions
.
push_back
(
m_evaluate
);
//
m_zoom
=
new
KSelectAction
(
QIcon
::
fromTheme
(
QLatin1String
(
"page-zoom"
)),
i18n
(
"Zoom"
),
collection
);
connect
(
m_zoom
,
static_cast
<
void
(
KSelectAction
::*
)(
const
QString
&
)
>
(
&
KSelectAction
::
triggered
),
this
,
&
CantorPart
::
zoomValueEdited
);
static
constexpr
std
::
array
<
double
,
8
>
ZoomValues
=
{
0.25
,
0.5
,
0.75
,
1.0
,
1.25
,
1.5
,
2.0
,
4.0
};
QStringList
zoomNames
;
for
(
double
zoomValue
:
ZoomValues
)
{
const
std
::
string
&
zoomName
=
std
::
to_string
(
static_cast
<
int
>
(
zoomValue
*
100
))
+
"%"
;
zoomNames
<<
i18n
(
zoomName
.
c_str
());
}
m_zoom
->
setItems
(
zoomNames
);
m_zoom
->
setEditable
(
true
);
Q_ASSERT
(
std
::
find
(
ZoomValues
.
begin
(),
ZoomValues
.
end
(),
1.0
)
!=
ZoomValues
.
end
());
m_zoom
->
setCurrentItem
(
std
::
distance
(
ZoomValues
.
begin
(),
std
::
find
(
ZoomValues
.
begin
(),
ZoomValues
.
end
(),
1.0
)));
collection
->
addAction
(
QLatin1String
(
"zoom_selection_action"
),
m_zoom
);
m_typeset
=
new
KToggleAction
(
i18n
(
"Typeset using LaTeX"
),
collection
);
m_typeset
->
setChecked
(
Settings
::
self
()
->
typesetDefault
());
// Disable until login, because we use session command for this action
...
...
@@ -1011,5 +1031,18 @@ void CantorPart::showImportantStatusMessage(const QString& message)
QTimer
::
singleShot
(
3000
,
this
,
SLOT
(
unblockStatusBar
()));
}
void
CantorPart
::
zoomValueEdited
(
const
QString
&
text
)
{
static
const
QRegularExpression
zoomRegexp
(
QLatin1String
(
"(?:(
\\
d+)%|(
\\
d+))"
));
QRegularExpressionMatch
match
=
zoomRegexp
.
match
(
text
);
if
(
match
.
hasMatch
())
{
double
zoom
=
match
.
captured
(
1
).
toDouble
()
/
100.0
;
if
(
m_worksheetview
)
m_worksheetview
->
setScaleFactor
(
zoom
);
}
}
K_PLUGIN_FACTORY_WITH_JSON
(
CantorPartFactory
,
"cantor_part.json"
,
registerPlugin
<
CantorPart
>
();)
#include
"cantor_part.moc"
src/cantor_part.h
View file @
1f38382f
...
...
@@ -36,6 +36,7 @@ class ScriptEditorWidget;
class
KAboutData
;
class
QAction
;
class
KToggleAction
;
class
KSelectAction
;
class
QProgressDialog
;
namespace
Cantor
{
...
...
@@ -116,6 +117,7 @@ protected Q_SLOTS:
void
exportToLatex
();
void
evaluateOrInterrupt
();
void
restartBackend
();
void
zoomValueEdited
(
const
QString
&
text
);
void
enableTypesetting
(
bool
enable
);
void
showBackendHelp
();
void
print
();
...
...
@@ -169,6 +171,7 @@ private:
bool
m_showProgressDlg
;
QAction
*
m_evaluate
;
QAction
*
m_restart
;
KSelectAction
*
m_zoom
;
QAction
*
m_save
;
QAction
*
m_findNext
;
QAction
*
m_findPrev
;
...
...
src/cantor_part.rc
View file @
1f38382f
...
...
@@ -70,6 +70,7 @@
<Action
name=
"evaluate_worksheet"
/>
<Action
name=
"restart_backend"
/>
<Action
name=
"backend_help"
/>
<Action
name=
"zoom_selection_action"
/>
<Separator/>
</ToolBar>
<ToolBar
noMerge=
"1"
name=
"textEditToolBar"
>
...
...
src/worksheetview.cpp
View file @
1f38382f
...
...
@@ -240,6 +240,13 @@ qreal WorksheetView::scaleFactor() const
return
m_scale
;
}
void
WorksheetView
::
setScaleFactor
(
qreal
zoom
)
{
scale
(
1
/
m_scale
*
zoom
,
1
/
m_scale
*
zoom
);
m_scale
=
zoom
;
updateSceneSize
();
}
void
WorksheetView
::
updateSceneSize
()
{
QSize
s
=
viewport
()
->
size
();
...
...
src/worksheetview.h
View file @
1f38382f
...
...
@@ -44,6 +44,7 @@ public:
QPointF
sceneCursorPos
()
const
;
QRectF
viewRect
()
const
;
qreal
scaleFactor
()
const
;
void
setScaleFactor
(
qreal
);
void
updateSceneSize
();
Q_SIGNALS:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment