mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-06 05:14:21 -04:00
added for plugins own dir
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1850 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
97d8640f3a
commit
87344de7d4
809 changed files with 790 additions and 722 deletions
264
plugins/calculator_plugin/calculator.js
Normal file
264
plugins/calculator_plugin/calculator.js
Normal file
|
@ -0,0 +1,264 @@
|
|||
//! [0]
|
||||
function Plugin(ui)
|
||||
{
|
||||
this.ui = ui;
|
||||
|
||||
this.pendingAdditiveOperator = "";
|
||||
this.pendingMultiplicativeOperator = "";
|
||||
this.sumInMemory = 0;
|
||||
this.sumSoFar = 0;
|
||||
this.factorSoFar = 0;
|
||||
this.waitingForOperand = true;
|
||||
|
||||
with (ui) {
|
||||
display.text = "0";
|
||||
|
||||
zeroButton.clicked.connect(this, this.digitClicked);
|
||||
oneButton.clicked.connect(this, "digitClicked");
|
||||
twoButton.clicked.connect(this, "digitClicked");
|
||||
threeButton.clicked.connect(this, "digitClicked");
|
||||
fourButton.clicked.connect(this, "digitClicked");
|
||||
fiveButton.clicked.connect(this, "digitClicked");
|
||||
sixButton.clicked.connect(this, "digitClicked");
|
||||
sevenButton.clicked.connect(this, "digitClicked");
|
||||
eightButton.clicked.connect(this, "digitClicked");
|
||||
nineButton.clicked.connect(this, "digitClicked");
|
||||
|
||||
pointButton.clicked.connect(this, "pointClicked");
|
||||
changeSignButton.clicked.connect(this, "changeSignClicked");
|
||||
|
||||
backspaceButton.clicked.connect(this, "backspaceClicked");
|
||||
clearButton.clicked.connect(this, "clear");
|
||||
clearAllButton.clicked.connect(this, "clearAll");
|
||||
|
||||
clearMemoryButton.clicked.connect(this, "clearMemory");
|
||||
readMemoryButton.clicked.connect(this, "readMemory");
|
||||
setMemoryButton.clicked.connect(this, "setMemory");
|
||||
addToMemoryButton.clicked.connect(this, "addToMemory");
|
||||
|
||||
divisionButton.clicked.connect(this, "multiplicativeOperatorClicked");
|
||||
timesButton.clicked.connect(this, "multiplicativeOperatorClicked");
|
||||
minusButton.clicked.connect(this, "additiveOperatorClicked");
|
||||
plusButton.clicked.connect(this, "additiveOperatorClicked");
|
||||
|
||||
squareRootButton.clicked.connect(this, "unaryOperatorClicked");
|
||||
powerButton.clicked.connect(this, "unaryOperatorClicked");
|
||||
reciprocalButton.clicked.connect(this, "unaryOperatorClicked");
|
||||
equalButton.clicked.connect(this, "equalClicked");
|
||||
}
|
||||
}
|
||||
//! [0]
|
||||
|
||||
Plugin.prototype.abortOperation = function()
|
||||
{
|
||||
this.clearAll();
|
||||
this.ui.display.text = "####";
|
||||
}
|
||||
|
||||
Plugin.prototype.calculate = function(rightOperand, pendingOperator)
|
||||
{
|
||||
if (pendingOperator == "+") {
|
||||
this.sumSoFar += rightOperand;
|
||||
} else if (pendingOperator == "-") {
|
||||
this.sumSoFar -= rightOperand;
|
||||
} else if (pendingOperator == "*") {
|
||||
this.factorSoFar *= rightOperand;
|
||||
} else if (pendingOperator == "/") {
|
||||
if (rightOperand == 0)
|
||||
return false;
|
||||
this.factorSoFar /= rightOperand;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//! [1]
|
||||
Plugin.prototype.digitClicked = function()
|
||||
{
|
||||
var digitValue = __qt_sender__.text - 0;
|
||||
if ((digitValue == 0) && (this.ui.display.text == "0"))
|
||||
return;
|
||||
if (this.waitingForOperand) {
|
||||
this.ui.display.clear();
|
||||
this.waitingForOperand = false;
|
||||
}
|
||||
this.ui.display.text += digitValue;
|
||||
}
|
||||
//! [1]
|
||||
|
||||
Plugin.prototype.unaryOperatorClicked = function()
|
||||
{
|
||||
var operand = this.ui.display.text - 0;
|
||||
var result = 0;
|
||||
if (__qt_sender__.text == "Sqrt") {
|
||||
if (operand < 0) {
|
||||
this.abortOperation();
|
||||
return;
|
||||
}
|
||||
result = Math.sqrt(operand);
|
||||
} else if (__qt_sender__.text == "x^2") {
|
||||
result = Math.pow(operand, 2);
|
||||
} else if (__qt_sender__.text == "1/x") {
|
||||
if (operand == 0.0) {
|
||||
this.abortOperation();
|
||||
return;
|
||||
}
|
||||
result = 1 / operand;
|
||||
}
|
||||
this.ui.display.text = result + "";
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
|
||||
Plugin.prototype.additiveOperatorClicked = function()
|
||||
{
|
||||
var operand = this.ui.display.text - 0;
|
||||
|
||||
if (this.pendingMultiplicativeOperator.length != 0) {
|
||||
if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
|
||||
this.abortOperation();
|
||||
return;
|
||||
}
|
||||
this.ui.display.text = this.factorSoFar + "";
|
||||
operand = this.factorSoFar;
|
||||
this.factorSoFar = 0;
|
||||
this.pendingMultiplicativeOperator = "";
|
||||
}
|
||||
|
||||
if (this.pendingAdditiveOperator.length != 0) {
|
||||
if (!this.calculate(operand, this.pendingAdditiveOperator)) {
|
||||
this.abortOperation();
|
||||
return;
|
||||
}
|
||||
this.ui.display.text = this.sumSoFar + "";
|
||||
} else {
|
||||
this.sumSoFar = operand;
|
||||
}
|
||||
|
||||
this.pendingAdditiveOperator = __qt_sender__.text;
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
|
||||
Plugin.prototype.multiplicativeOperatorClicked = function()
|
||||
{
|
||||
var operand = this.ui.display.text - 0;
|
||||
|
||||
if (this.pendingMultiplicativeOperator.length != 0) {
|
||||
if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
|
||||
this.abortOperation();
|
||||
return;
|
||||
}
|
||||
this.ui.display.text = this.factorSoFar + "";
|
||||
} else {
|
||||
this.factorSoFar = operand;
|
||||
}
|
||||
|
||||
this.pendingMultiplicativeOperator = __qt_sender__.text;
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
|
||||
Plugin.prototype.equalClicked = function()
|
||||
{
|
||||
var operand = this.ui.display.text - 0;
|
||||
|
||||
if (this.pendingMultiplicativeOperator.length != 0) {
|
||||
if (!this.calculate(operand, this.pendingMultiplicativeOperator)) {
|
||||
this.abortOperation();
|
||||
return;
|
||||
}
|
||||
operand = this.factorSoFar;
|
||||
this.factorSoFar = 0.0;
|
||||
this.pendingMultiplicativeOperator = "";
|
||||
}
|
||||
if (this.pendingAdditiveOperator.length != 0) {
|
||||
if (!this.calculate(operand, this.pendingAdditiveOperator)) {
|
||||
this.abortOperation();
|
||||
return;
|
||||
}
|
||||
this.pendingAdditiveOperator = "";
|
||||
} else {
|
||||
this.sumSoFar = operand;
|
||||
}
|
||||
|
||||
this.ui.display.text = this.sumSoFar + "";
|
||||
this.sumSoFar = 0.0;
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
|
||||
Plugin.prototype.pointClicked = function()
|
||||
{
|
||||
if (this.waitingForOperand)
|
||||
this.ui.display.text = "0";
|
||||
if (this.ui.display.text.indexOf(".") == -1)
|
||||
this.ui.display.text += ".";
|
||||
this.waitingForOperand = false;
|
||||
}
|
||||
|
||||
//! [2]
|
||||
Plugin.prototype.changeSignClicked = function()
|
||||
{
|
||||
var text = this.ui.display.text;
|
||||
var value = text - 0;
|
||||
|
||||
if (value > 0) {
|
||||
text = "-" + text;
|
||||
} else if (value < 0) {
|
||||
text = text.slice(1);
|
||||
}
|
||||
this.ui.display.text = text;
|
||||
}
|
||||
//! [2]
|
||||
|
||||
Plugin.prototype.backspaceClicked = function()
|
||||
{
|
||||
if (this.waitingForOperand)
|
||||
return;
|
||||
|
||||
var text = this.ui.display.text;
|
||||
text = text.slice(0, -1);
|
||||
if (text.length == 0) {
|
||||
text = "0";
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
this.ui.display.text = text;
|
||||
}
|
||||
|
||||
Plugin.prototype.clear = function()
|
||||
{
|
||||
if (this.waitingForOperand)
|
||||
return;
|
||||
|
||||
this.ui.display.text = "0";
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
|
||||
Plugin.prototype.clearAll = function()
|
||||
{
|
||||
this.sumSoFar = 0.0;
|
||||
this.factorSoFar = 0.0;
|
||||
this.pendingAdditiveOperator = "";
|
||||
this.pendingMultiplicativeOperator = "";
|
||||
this.ui.display.text = "0";
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
|
||||
Plugin.prototype.clearMemory = function()
|
||||
{
|
||||
this.sumInMemory = 0.0;
|
||||
}
|
||||
|
||||
Plugin.prototype.readMemory = function()
|
||||
{
|
||||
this.ui.display.text = this.sumInMemory + "";
|
||||
this.waitingForOperand = true;
|
||||
}
|
||||
|
||||
Plugin.prototype.setMemory = function()
|
||||
{
|
||||
this.equalClicked();
|
||||
this.sumInMemory = this.ui.display.text - 0;
|
||||
}
|
||||
|
||||
Plugin.prototype.addToMemory = function()
|
||||
{
|
||||
this.equalClicked();
|
||||
this.sumInMemory += this.ui.display.text - 0;
|
||||
}
|
406
plugins/calculator_plugin/calculator.ui
Normal file
406
plugins/calculator_plugin/calculator.ui
Normal file
|
@ -0,0 +1,406 @@
|
|||
<ui version="4.0" >
|
||||
<class>Calculator</class>
|
||||
<widget class="QWidget" name="Calculator" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>314</width>
|
||||
<height>301</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>314</width>
|
||||
<height>301</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>314</width>
|
||||
<height>301</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Calculator</string>
|
||||
</property>
|
||||
<widget class="QToolButton" name="backspaceButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>50</y>
|
||||
<width>91</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Backspace</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="clearButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>50</y>
|
||||
<width>91</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Clear :)</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="clearAllButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>50</y>
|
||||
<width>91</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Clear All</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="clearMemoryButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>100</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>MC</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="readMemoryButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>150</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>MR</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="setMemoryButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>200</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>MS</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="addToMemoryButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>250</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>M+</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="sevenButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>100</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>7</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="eightButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>100</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>8</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="nineButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>100</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>9</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="fourButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>150</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>4</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="fiveButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>150</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>5</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="sixButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>150</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>6</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="oneButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>200</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>1</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="twoButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>200</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>2</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="threeButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>200</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>3</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="zeroButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>60</x>
|
||||
<y>250</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="pointButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>250</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>.</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="changeSignButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>250</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>+-</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="plusButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>250</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>+</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="divisionButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>100</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>/</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="timesButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>150</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>*</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="minusButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>200</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>-</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="squareRootButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>100</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Sqrt</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="powerButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>150</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>x^2</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="reciprocalButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>200</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>1/x</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolButton" name="equalButton" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>250</y>
|
||||
<width>41</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>=</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="display" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>291</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="maxLength" >
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="alignment" >
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="readOnly" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Add table
Add a link
Reference in a new issue