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
KAlgebra
Commits
525bdfc9
Commit
525bdfc9
authored
Sep 22, 2011
by
Aleix Pol Gonzalez
🐧
Browse files
Ported KAlgebra Mobile to desktop components.
parent
eb533286
Changes
15
Hide whitespace changes
Inline
Side-by-side
analitzagui/functionsmodel.cpp
View file @
525bdfc9
...
...
@@ -59,7 +59,7 @@ QVariant FunctionsModel::data(const QModelIndex & index, int role) const
if
(
index
.
column
()
==
0
)
{
QPixmap
ico
(
15
,
15
);
ico
.
fill
(
f
.
color
());
ret
=
ico
;
ret
=
QIcon
(
ico
)
;
}
else
{
ret
=
QIcon
::
fromTheme
(
f
.
icon
());
}
...
...
mobile/CMakeLists.txt
View file @
525bdfc9
add_subdirectory
(
plugins
)
kde4_add_executable
(
kalgebramobile graph2dmobile.cpp
kde4_add_executable
(
kalgebramobile
pluginsmodel.cpp
graph2dmobile.cpp
analitzawrapper.cpp kalgebramobile.cpp main.cpp console.cpp
)
target_link_libraries
(
kalgebramobile
${
KDE4_KDECORE_LIBS
}
${
QT_QTSCRIPT_LIBRARY
}
${
QT_QTDECLARATIVE_LIBRARY
}
...
...
mobile/kalgebramobile.cpp
View file @
525bdfc9
...
...
@@ -45,6 +45,7 @@
#include
<qdeclarative.h>
#include
"graph2dmobile.h"
#include
<qdeclarativecontext.h>
#include
"pluginsmodel.h"
// #define DEBUG
...
...
@@ -52,153 +53,23 @@
// #include <QScriptEngineDebugger>
// #endif
class
PluginsModel
:
public
QStandardItemModel
{
public:
enum
Roles
{
PathRole
=
Qt
::
UserRole
+
1
,
PriorityRole
};
explicit
PluginsModel
(
QObject
*
parent
=
0
)
:
QStandardItemModel
(
parent
)
{
KStandardDirs
d
;
QStringList
basedirs
=
d
.
findDirs
(
"data"
,
"kalgebra/plugins"
);
QStringList
foundPlugins
;
foreach
(
const
QString
&
dir
,
basedirs
)
{
//we list <dir>/*/*.desktop
QDir
d
(
dir
);
QStringList
files
=
d
.
entryList
(
QStringList
(
"*.desktop"
));
qDebug
()
<<
"lalala"
<<
dir
<<
files
;
foreach
(
const
QString
&
plugin
,
files
)
{
foundPlugins
+=
d
.
absoluteFilePath
(
plugin
);
}
}
qDebug
()
<<
"Plugins found:"
<<
foundPlugins
;
m_plugins
=
KPluginInfo
::
fromFiles
(
foundPlugins
);
setSortRole
(
PriorityRole
);
foreach
(
const
KPluginInfo
&
info
,
m_plugins
)
{
// const KPluginInfo& info;
QStandardItem
*
item
=
new
QStandardItem
(
KIcon
(
info
.
icon
()),
info
.
name
());
QString
postfix
=
"kalgebra/plugins/"
+
info
.
pluginName
();
QString
scriptPath
=
KStandardDirs
::
locate
(
"data"
,
postfix
);
Q_ASSERT
(
!
scriptPath
.
isEmpty
());
QVariant
priority
=
info
.
property
(
"X-KAlgebra-Priority"
);
if
(
!
priority
.
isValid
())
priority
=
1000
;
item
->
setData
(
scriptPath
,
PathRole
);
item
->
setData
(
priority
,
PriorityRole
);
appendRow
(
item
);
}
setSortRole
(
PriorityRole
);
sort
(
0
);
}
private:
KPluginInfo
::
List
m_plugins
;
};
KAlgebraMobile
*
KAlgebraMobile
::
s_self
=
0
;
KAlgebraMobile
*
KAlgebraMobile
::
self
()
{
return
s_self
;
}
KAlgebraMobile
::
KAlgebraMobile
(
Q
Widge
t
*
parent
,
Qt
::
WindowFlags
flags
)
:
Q
MainWindow
(
parent
,
flags
),
m_functionsModel
(
0
),
m_vars
(
new
Analitza
::
Variables
)
KAlgebraMobile
::
KAlgebraMobile
(
Q
Objec
t
*
parent
)
:
Q
Object
(
parent
),
m_functionsModel
(
0
),
m_vars
(
new
Analitza
::
Variables
)
{
Q_ASSERT
(
s_self
==
0
);
s_self
=
this
;
setWindowTitle
(
i18n
(
"KAlgebra Mobile"
));
menuBar
()
->
addAction
(
i18n
(
"Select..."
),
this
,
SLOT
(
selectPlugin
()));
#ifdef DEBUG
menuBar
()
->
addSeparator
();
menuBar
()
->
addAction
(
KIcon
(
"debug-run"
),
i18n
(
"Debug"
),
this
,
SLOT
(
debug
()));
#endif
m_pluginsModel
=
new
PluginsModel
(
this
);
// m_uiconfig = new UiConfig(this);
qmlRegisterType
<
PluginsModel
>
(
"org.kde.analitza"
,
1
,
0
,
"PluginsModel"
);
qmlRegisterType
<
AnalitzaWrapper
>
(
"org.kde.analitza"
,
1
,
0
,
"Analitza"
);
qmlRegisterType
<
FunctionsModel
>
(
"org.kde.analitza"
,
1
,
0
,
"FunctionsModel"
);
qmlRegisterType
<
Graph2DMobile
>
(
"org.kde.analitza"
,
1
,
0
,
"Graph2D"
);
// global.setProperty("VariablesModel", varsmodel, QScriptValue::Undeletable|QScriptValue::ReadOnly);
setCentralWidget
(
new
QWidget
(
this
));
centralWidget
()
->
setLayout
(
new
QVBoxLayout
(
centralWidget
()));
findScripts
();
}
void
KAlgebraMobile
::
findScripts
()
{
m_pluginUI
.
resize
(
m_pluginsModel
->
rowCount
());
displayPlugin
(
0
);
}
void
KAlgebraMobile
::
selectPlugin
()
{
QPointer
<
QDialog
>
d
(
new
QDialog
);
d
->
setLayout
(
new
QVBoxLayout
);
QListView
*
combo
=
new
QListView
(
d
.
data
());
// combo->setViewMode(QListView::IconMode);
combo
->
setModel
(
m_pluginsModel
);
combo
->
setFrameStyle
(
QFrame
::
NoFrame
);
combo
->
setBackgroundRole
(
QPalette
::
NoRole
);
combo
->
setEditTriggers
(
0
);
connect
(
combo
,
SIGNAL
(
clicked
(
QModelIndex
)),
d
.
data
(),
SLOT
(
accept
()));
d
->
layout
()
->
addWidget
(
combo
);
QDialogButtonBox
*
buttons
=
new
QDialogButtonBox
(
QDialogButtonBox
::
Ok
|
QDialogButtonBox
::
Cancel
,
Qt
::
Horizontal
,
d
.
data
());
connect
(
buttons
,
SIGNAL
(
accepted
()),
d
.
data
(),
SLOT
(
accept
()));
connect
(
buttons
,
SIGNAL
(
rejected
()),
d
.
data
(),
SLOT
(
reject
()));
d
->
layout
()
->
addWidget
(
buttons
);
int
ret
=
d
->
exec
();
if
(
ret
==
QDialog
::
Accepted
)
{
displayPlugin
(
combo
->
currentIndex
().
row
());
}
delete
d
.
data
();
}
void
KAlgebraMobile
::
displayPlugin
(
int
plugin
)
{
Q_ASSERT
(
plugin
<
m_pluginUI
.
size
());
// qDebug() << "laalalala" << plugin;
if
(
!
m_pluginUI
[
plugin
])
{
QString
scriptFileName
=
m_pluginsModel
->
index
(
plugin
,
0
).
data
(
PluginsModel
::
PathRole
).
toString
();
QDeclarativeView
*
view
=
new
QDeclarativeView
(
this
);
view
->
setResizeMode
(
QDeclarativeView
::
SizeRootObjectToView
);
view
->
engine
()
->
setOutputWarningsToStandardError
(
true
);
view
->
engine
()
->
rootContext
()
->
setContextProperty
(
"app"
,
this
);
view
->
setSource
(
m_pluginsModel
->
item
(
plugin
)
->
data
(
PluginsModel
::
PathRole
).
toUrl
());
m_pluginUI
[
plugin
]
=
view
;
}
QLayout
*
layout
=
centralWidget
()
->
layout
();
while
(
!
layout
->
isEmpty
())
{
QLayoutItem
*
item
=
layout
->
takeAt
(
0
);;
item
->
widget
()
->
hide
();
delete
item
;
}
layout
->
addWidget
(
m_pluginUI
[
plugin
]);
m_pluginUI
[
plugin
]
->
show
();
}
// void KAlgebraMobile::handleException(const QScriptValue& exception)
// {
// QMessageBox::critical(this, i18n("Exception Thrown"), exception.toString());
// }
FunctionsModel
*
KAlgebraMobile
::
functionsModel
()
{
if
(
!
m_functionsModel
)
{
...
...
mobile/kalgebramobile.h
View file @
525bdfc9
...
...
@@ -19,7 +19,8 @@
#ifndef KALGEBRAMOBILE_H
#define KALGEBRAMOBILE_H
#include
<QMainWindow>
#include
<QObject>
#include
<QColor>
namespace
Analitza
{
class
Variables
;}
...
...
@@ -28,11 +29,11 @@ class PluginsModel;
class
FunctionsModel
;
class
AnalitzaWrapper
;
class
KAlgebraMobile
:
public
Q
MainWindow
class
KAlgebraMobile
:
public
Q
Object
{
Q_OBJECT
public:
explicit
KAlgebraMobile
(
Q
Widge
t
*
parent
=
0
,
Qt
::
WindowFlags
flags
=
0
);
explicit
KAlgebraMobile
(
Q
Objec
t
*
parent
=
0
);
void
displayPlugin
(
int
plugin
);
...
...
@@ -43,17 +44,10 @@ class KAlgebraMobile : public QMainWindow
Analitza
::
Variables
*
variables
()
const
;
QStringList
addFunction
(
const
QString
&
expression
,
const
QString
&
name
=
QString
(),
const
QColor
&
color
=
QColor
(),
double
up
=
0.
,
double
down
=
0.
);
private
slots
:
void
selectPlugin
();
private:
static
KAlgebraMobile
*
s_self
;
void
findScripts
();
QVector
<
QWidget
*>
m_pluginUI
;
FunctionsModel
*
m_functionsModel
;
PluginsModel
*
m_pluginsModel
;
Analitza
::
Variables
*
m_vars
;
};
...
...
mobile/main.cpp
View file @
525bdfc9
...
...
@@ -20,6 +20,11 @@
#include
<KAboutData>
#include
<KCmdLineArgs>
#include
"kalgebramobile.h"
#include
<QDeclarativeView>
#include
<KStandardDirs>
#include
<QDebug>
#include
<QDeclarativeEngine>
#include
<qdeclarativecontext.h>
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -29,12 +34,15 @@ int main(int argc, char *argv[])
KCmdLineArgs
::
init
(
argc
,
argv
,
&
about
);
KApplication
app
;
/*if(app.isSessionRestored()) {
RESTORE(KAlgebra);
} else {*/
KAlgebraMobile
*
widget
=
new
KAlgebraMobile
;
widget
->
show
();
//}
KAlgebraMobile
widget
;
QDeclarativeView
view
;
view
.
setResizeMode
(
QDeclarativeView
::
SizeRootObjectToView
);
view
.
engine
()
->
rootContext
()
->
setContextProperty
(
"app"
,
&
widget
);
QString
main
=
KStandardDirs
::
locate
(
"data"
,
"kalgebra/plugins/KAlgebraMobile.qml"
);
view
.
setSource
(
main
);
view
.
show
();
return
app
.
exec
();
}
mobile/plugins/CMakeLists.txt
View file @
525bdfc9
add_subdirectory
(
widgets
)
install
(
FILES
KAlgebraMobile.qml
Console.qml Plot2D.qml Tables.qml
kalgebraconsole.desktop kalgebraplot2d.desktop kalgebratables.desktop
DESTINATION
${
DATA_INSTALL_DIR
}
/kalgebra/plugins/
...
...
mobile/plugins/Console.qml
View file @
525bdfc9
import
QtQuick
1.0
import
QtDesktop
0.1
import
org
.
kde
.
analitza
1.0
import
"
widgets
"
Item
KAlgebraPage
{
// id: bg
width
:
640
;
height
:
500
...
...
@@ -31,9 +32,7 @@ Item
input
.
selectAll
()
}
ConsoleModel
{
id
:
itemModel
}
ListModel
{
id
:
itemModel
}
ExpressionInput
{
id
:
input
...
...
@@ -76,16 +75,21 @@ Item
anchors.right
:
parent
.
right
}
List
View
{
Table
View
{
model
:
itemModel
delegate
:
ConsoleDelegate
{}
// delegate: ConsoleDelegate {}
// itemDelegate: Row { Text { text: result } }
id
:
view
height
:
200
TableColumn
{
property
:
"
result
"
caption
:
"
Title
"
}
anchors.top
:
inputrow
.
bottom
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
width
:
parent
.
width
}
Keyboard
{
...
...
mobile/plugins/Plot2D.qml
View file @
525bdfc9
import
QtQuick
1.0
import
QtDesktop
0.1
import
org
.
kde
.
analitza
1.0
import
"
widgets
"
Rectangl
e
KAlgebraPag
e
{
width
:
500
height
:
500
Graph2D
{
id
:
view
height
:
parent
.
height
-
(
input
.
height
+
listview
.
height
)
width
:
parent
.
width
squares
:
true
model
:
app
.
functionsModel
()
anchors.top
:
parent
.
top
;
}
function
addFunc
()
{
app
.
addFunction
(
input
.
text
)
}
ListView
{
id
:
listview
model
:
app
.
functionsModel
()
delegate
:
Text
{
text
:
display
+
"
"
+
expression
}
highlight
:
Rectangle
{
color
:
"
lightsteelblue
"
;
radius
:
5
}
onCurrentIndexChanged
:
view
.
currentFunction
=
currentIndex
-
1
height
:
100
anchors.top
:
input
.
bottom
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
}
height
:
100
width
:
100
ExpressionInput
{
id
:
input
text
:
"
sin x
"
Keys.onReturnPressed
:
addFunc
()
Rectangle
{
w
id
th
:
parent
.
width
anchors.top
:
parent
.
top
anchors.bottom
:
controls
.
top
color
:
'
white
'
anchors.top
:
view
.
bottom
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
// anchors.bottom: parent.bottom
Graph2D
{
id
:
view
anchors.fill
:
parent
squares
:
true
model
:
app
.
functionsModel
()
}
}
Button
{
id
:
exec
text
:
"
Add
"
height
:
80
;
width
:
80
Column
{
id
:
controls
height
:
200
anchors.bottom
:
parent
.
bottom
anchors.right
:
parent
.
right
onClicked
:
addFunc
()
Row
{
width
:
parent
.
width
ExpressionInput
{
id
:
input
text
:
"
sin x
"
Keys.onReturnPressed
:
addFunc
()
}
Button
{
id
:
exec
text
:
"
Add
"
onClicked
:
addFunc
()
}
}
TableView
{
id
:
listview
model
:
app
.
functionsModel
()
// itemDelegate: Text { text: display + " " + expression }
// highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
onCurrentIndexChanged
:
view
.
currentFunction
=
currentIndex
-
1
TableColumn
{
property
:
"
display
"
caption
:
"
Name
"
}
TableColumn
{
property
:
"
expression
"
caption
:
"
Function
"
}
width
:
view
.
width
height
:
100
}
}
// Rectangle { color: "red"; anchors.fill: parent}
}
\ No newline at end of file
mobile/plugins/Tables.qml
View file @
525bdfc9
import
QtQuick
1.0
import
QtDesktop
0.1
import
org
.
kde
.
analitza
1.0
import
"
widgets
"
Rectangl
e
KAlgebraPag
e
{
id
:
bg
height
:
200
width
:
200
ListModel
{
id
:
resultsModel
}
Analitza
{
id
:
a
}
...
...
@@ -16,7 +15,7 @@ Rectangle
var
tmp
=
a
.
unusedVariableName
();
var
ret
=
a
.
execute
(
tmp
+
"
:=
"
+
input
.
text
,
true
)
var
ffrom
=
parseFloat
(
from
.
text
),
fto
=
parseFloat
(
to
.
text
),
fstep
=
parseFloat
(
step
.
text
)
;
var
ffrom
=
from
.
value
,
fto
=
to
.
value
,
fstep
=
step
.
value
;
// console.log("chancho (" + ffrom + ", " + fto + ") " + ret);
for
(
var
i
=
ffrom
;
i
<=
fto
;
i
+=
fstep
)
{
...
...
@@ -34,9 +33,9 @@ Rectangle
columns
:
2
Text
{
text
:
"
Input:
"
}
ExpressionInput
{
id
:
input
;
text
:
"
x->sin x
"
}
Text
{
text
:
"
From:
"
}
RealInput
{
id
:
from
;
text
:
"
0
"
}
Text
{
text
:
"
To:
"
}
RealInput
{
id
:
to
;
text
:
"
10
"
}
Text
{
text
:
"
Step:
"
}
RealInput
{
id
:
step
;
text
:
"
1
"
}
Text
{
text
:
"
From:
"
}
RealInput
{
id
:
from
;
value
:
0
}
Text
{
text
:
"
To:
"
}
RealInput
{
id
:
to
;
value
:
10
}
Text
{
text
:
"
Step:
"
}
RealInput
{
id
:
step
;
value
:
1
}
Button
{
text
:
"
Go!
"
...
...
@@ -47,13 +46,24 @@ Rectangle
Text
{
text
:
"
Results:
"
;
id
:
res
;
anchors.top
:
ins
.
bottom
}
List
View
{
Table
View
{
id
:
view
anchors.bottom
:
parent
.
bottom
anchors.top
:
res
.
bottom
model
:
resultsModel
width
:
bg
.
width
delegate
:
Text
{
text
:
value
+
"
->
"
+
result
}
// delegate: Text { text: value+" -> "+result}
TableColumn
{
property
:
"
value
"
caption
:
"
Value
"
width
:
50
}
TableColumn
{
property
:
"
result
"
caption
:
"
Image
"
}
}
}
mobile/plugins/widgets/Button.qml
View file @
525bdfc9
import
Qt
Quick
1.0
import
Qt
Desktop
0.1
Item
{
id
:
button
signal
clicked
property
bool
toggled
:
false
property
alias
text
:
text
.
text
width
:
80
height
:
40
Rectangle
{
anchors.fill
:
button
anchors.margins
:
mouseArea
.
pressed
?
3
:
2
radius
:
mouseArea
.
pressed
?
8
:
6
smooth
:
true
gradient
:
Gradient
{
GradientStop
{
position
:
0.0
;
color
:
"
#003
"
}
GradientStop
{
position
:
1.0
;
color
:
"
#004
"
}
}
Text
{
id
:
text
anchors.centerIn
:
parent
// font.pixelSize: mouseArea.pressed ? 12 : 14
color
:
"
white
"
horizontalAlignment
:
Text
.
AlignHCenter
verticalAlignment
:
Text
.
AlignVCenter
style
:
Text
.
Sunken
;
styleColor
:
"
black
"
;
smooth
:
true
}
MouseArea
{
id
:
mouseArea
anchors.fill
:
parent
hoverEnabled
:
true
onClicked
:
{
button
.
clicked
()
}
}
}
Rectangle
{
id
:
shade
anchors.fill
:
button
;
radius
:
10
;
color
:
"
black
"
;
opacity
:
0
Behavior
on
opacity
{
NumberAnimation
{
// properties: "opacity";
duration
:
100
}
}
}
states
:
[
State
{
name
:
"
pressed
"
;
when
:
mouseArea
.
pressed
==
true
PropertyChanges
{
target
:
shade
;
opacity
:
.
4
}
},
State
{
name
:
"
hovered
"
when
:
mouseArea
.
containsMouse
==
true
PropertyChanges
{
target
:
shade
;
opacity
:
.
2
}
}
]
}
Button
{}
mobile/plugins/widgets/CMakeLists.txt
View file @
525bdfc9
install
(
FILES
Button.qml CalcButton.qml CategoryDelegate.qml ConsoleDelegate.qml
ConsoleModel.qml
ExpressionInput.qml Keyboard.qml RealInput.qml ToolTip.qml
Button.qml CalcButton.qml CategoryDelegate.qml ConsoleDelegate.qml ExpressionInput.qml Keyboard.qml RealInput.qml ToolTip.qml
KAlgebraPage.qml
DESTINATION
${
DATA_INSTALL_DIR
}
/kalgebra/plugins/widgets/
)
mobile/plugins/widgets/CalcButton.qml
View file @
525bdfc9
...
...
@@ -2,7 +2,5 @@ import QtQuick 1.0
Button
{
onClicked
:
{
doOp
(
text
)
}
onClicked
:
doOp
(
text
)
}
\ No newline at end of file
mobile/plugins/widgets/ConsoleModel.qml
deleted
100644 → 0
View file @
eb533286
import
QtQuick
1.0
ListModel
{
ListElement
{
result
:
"
hola = 33
"
}
}
\ No newline at end of file
mobile/plugins/widgets/ExpressionInput.qml
View file @
525bdfc9
import
Qt
Quick
1.0
import
Qt
Desktop
0.1
Text
Input
Text
Field
{
id
:
input
color
:
"
black
"
Keys.onPressed
:
{
console
.
log
(
"
bum ::
"
+
text
);
// hints.text=text;
}
placeholderText
:
"
Enter the expression to calculate...
"
// Keys.onPressed: {
// console.log("bum :: "+text);