diff --git a/pip b/pip index 3965e54..f033119 160000 --- a/pip +++ b/pip @@ -1 +1 @@ -Subproject commit 3965e54e38cbb23e8103e1e09a49910d5b5957b3 +Subproject commit f033119a8bf82633146c458d1165377661df1c9f diff --git a/piqt/utils/qpicalculator/CMakeLists.txt b/piqt/utils/qpicalculator/CMakeLists.txt new file mode 100644 index 0000000..27ecf2c --- /dev/null +++ b/piqt/utils/qpicalculator/CMakeLists.txt @@ -0,0 +1,14 @@ +project(qpicalc) +if(APPLE) + set(APP_ICON "") +elseif(WIN32) + set(APP_ICON "icons/qpicalculator.ico") +else() + set(APP_ICON "icons/qpicalculator.png") +endif() +set(APP_INFO "Small calculator ang grapher") +qad_application(${PROJECT_NAME} "Gui;Widgets" "qad_utils;qad_widgets;qad_graphic") +if (Qt5_FOUND) + import_version(${PROJ_NAME}5 ${PROJECT_NAME}) + deploy_target(${PROJECT_NAME}5 DEPLOY_DIR ${CMAKE_CURRENT_BINARY_DIR} DESTINATION ${ROOT_DIR}/release) +endif() diff --git a/piqt/utils/qpicalculator/icons/qpicalculator.ico b/piqt/utils/qpicalculator/icons/qpicalculator.ico new file mode 100644 index 0000000..99388c5 Binary files /dev/null and b/piqt/utils/qpicalculator/icons/qpicalculator.ico differ diff --git a/piqt/utils/qpicalculator/icons/qpicalculator.png b/piqt/utils/qpicalculator/icons/qpicalculator.png new file mode 100644 index 0000000..dad22b7 Binary files /dev/null and b/piqt/utils/qpicalculator/icons/qpicalculator.png differ diff --git a/piqt/utils/qpicalculator/main.cpp b/piqt/utils/qpicalculator/main.cpp new file mode 100644 index 0000000..afb41cf --- /dev/null +++ b/piqt/utils/qpicalculator/main.cpp @@ -0,0 +1,13 @@ +#include +#include "mainwindow.h" + + +int main(int argc, char *argv[]) { + QApplication a(argc, argv); +#if QT_VERSION >= 0x050000 + a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); +#endif + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/piqt/utils/qpicalculator/mainwindow.cpp b/piqt/utils/qpicalculator/mainwindow.cpp new file mode 100644 index 0000000..4381f41 --- /dev/null +++ b/piqt/utils/qpicalculator/mainwindow.cpp @@ -0,0 +1,261 @@ +#include "mainwindow.h" + + +MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow() { + setupUi(this); + active_ = false; + lineInput->setFocus(); +#if QT_VERSION >= 0x050000 + treeGraphics->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + treeGraphics->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); +#else + treeGraphics->header()->setResizeMode(0, QHeaderView::ResizeToContents); + treeGraphics->header()->setResizeMode(1, QHeaderView::ResizeToContents); +#endif + npal = epal = lineInput->palette(); + epal.setColor(lineInput->backgroundRole(), QColor(Qt::red).lighter(150)); + connect(&session, SIGNAL(loading(QPIConfig & )), this, SLOT(loading(QPIConfig & ))); + connect(&session, SIGNAL(saving(QPIConfig & )), this, SLOT(saving(QPIConfig & ))); + session.setFile("session_qpicalc.conf"); + session.addEntry(this); + session.addEntry(lineInput); + session.addEntry(tabWidget); + session.load(); + ans = evaluator.setVariable("ans"); + on_lineInput_returnPressed(); +} + + +MainWindow::~MainWindow() {session.save(); +} + + +void MainWindow::changeEvent(QEvent * e) { + QMainWindow::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + retranslateUi(this); + break; + default: + break; + } +} + + +void MainWindow::updateGraphics() { + graphic->setGraphicsCount(treeGraphics->topLevelItemCount()); + for (int i = 0; i < treeGraphics->topLevelItemCount(); ++i) + graphic->setGraphicColor(treeGraphics->topLevelItem(i)->data(0, Qt::DecorationRole).value(), i); + redrawGraphics(); +} + + +void MainWindow::redrawGraphics() { + QRectF sr = graphic->visualRect(); + double dx = (sr.right() - sr.left()) / graphic->width(), sx = sr.left(), fx = sr.right(), cx; + QPolygonF pol; + evaluator.setVariable("x"); + int vi = evaluator.variableIndex("x"); + graphic->setAutoUpdate(false); + for (int i = 0; i < treeGraphics->topLevelItemCount(); ++i) { + QTreeWidgetItem * ti = treeGraphics->topLevelItem(i); + graphic->setGraphicName(ti->text(1), i); + pol.clear(); + if (ti->checkState(0) == Qt::Checked) { + if (evaluator.check(ti->text(1))) { + cx = sx; + while (cx < fx) { + evaluator.setVariable(vi, complexd(cx, 0.)); + pol << QPointF(cx, evaluator.evaluate().real()); + cx += dx; + } + } + } + graphic->setGraphicVisible(ti->checkState(0) == Qt::Checked, i); + graphic->setGraphicData(pol, i); + } + graphic->setAutoUpdate(true); + graphic->update(true); +} + + +void MainWindow::loading(QPIConfig & conf) { + active_ = false; + QStringList vars = conf.getValue("variables").toStringList(); + int vc = vars.size() / 2; + for (int i = 0; i < vc; ++i) { + QTreeWidgetItem * ti = new QTreeWidgetItem(treeVariables); + ti->setText(0, vars[i * 2]); + ti->setText(1, vars[i * 2 + 1]); + ti->setFlags(ti->flags() | Qt::ItemIsEditable); + treeVariables->addTopLevelItem(ti); + } + buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0); + QByteArray ba = conf.getValue("graphics").toByteArray(); + QDataStream s(ba); + QVector g; + if (!ba.isEmpty()) s >> g; + graphic->setAllGraphics(g); + for (int i = 0; i < graphic->graphicsCount(); ++i) { + graphic->setCurrentGraphic(i); + QTreeWidgetItem * ti = new QTreeWidgetItem(treeGraphics); + ti->setFlags(ti->flags() | Qt::ItemIsEditable); + ti->setCheckState(0, graphic->graphicVisible() ? Qt::Checked : Qt::Unchecked); + ti->setData(0, Qt::DecorationRole, graphic->graphicColor()); + ti->setText(1, graphic->graphicName()); + treeGraphics->addTopLevelItem(ti); + } + buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0); + graphic->setVisualRect(conf.getValue("graphicRect", QRectF(-1., -1., 2., 2.)).toRectF()); + ba = conf.getValue("graphic_state").toByteArray(); + if (!ba.isEmpty()) + graphic->load(ba); + on_tabWidget_currentChanged(0); + redrawGraphics(); + active_ = true; +} + + +void MainWindow::saving(QPIConfig & conf) { + QStringList vars; + int vc = treeVariables->topLevelItemCount(); + for (int i = 0; i < vc; ++i) { + QTreeWidgetItem * ti = treeVariables->topLevelItem(i); + vars << ti->text(0) << ti->text(1); + } + conf.setValue("variables", vars); + + QVector g; + vc = treeGraphics->topLevelItemCount(); + for (int i = 0; i < vc; ++i) { + QTreeWidgetItem * ti = treeGraphics->topLevelItem(i); + vars << QString::number(ti->background(1).color().rgb()) << ti->text(2); + } + QByteArray ba; QDataStream s(&ba, QIODevice::WriteOnly); + s << graphic->allGraphics(); + conf.setValue("graphics", QByteArray2QString(ba)); + conf.setValue("graphicRect", graphic->visualRect()); + conf.setValue("graphic_state", graphic->save()); +} + + +void MainWindow::on_lineInput_textChanged(QString text) { + if (evaluator.check(text)) lineInput->setPalette(npal); + else lineInput->setPalette(epal); + labelParsed->setText(evaluator.expression()); + labelError->setText(evaluator.error()); +} + + +void MainWindow::on_lineInput_returnPressed() { + bool ret = evaluator.check(lineInput->text()); + if (ret) lineInput->setPalette(npal); + else lineInput->setPalette(epal); + labelParsed->setText(evaluator.expression()); + labelError->setText(evaluator.error()); + if (!ret) return; + complexd val = evaluator.evaluate(); + evaluator.setVariable(ans, val); + if (val.imag() == 0) labelResult->setText(QString::number(val.real())); + else { + if (val.real() == 0) labelResult->setText(QString::number(val.imag()) + "i"); + else { + if (val.imag() > 0) labelResult->setText(QString::number(val.real()) + + " + " + QString::number(val.imag()) + "i"); + else labelResult->setText(QString::number(val.real()) + + " - " + QString::number(fabs(val.imag())) + "i"); + } + } + if (lineInput->text().trimmed().isEmpty()) return; + QTreeWidgetItem * ti = 0, * pti = 0; + if (treeHistory->topLevelItemCount() > 0) + pti = treeHistory->topLevelItem(treeHistory->topLevelItemCount() - 1); + if (pti != 0) + if (pti->text(0) == lineInput->text()) + return; + ti = new QTreeWidgetItem(treeHistory); + ti->setText(0, lineInput->text()); + ti->setText(1, labelResult->text()); + treeHistory->addTopLevelItem(ti); + if (treeHistory->verticalScrollBar()->value() == treeHistory->verticalScrollBar()->maximum()) + treeHistory->scrollToBottom(); +} + + +void MainWindow::on_treeGraphics_itemDoubleClicked(QTreeWidgetItem * item, int column) { + Qt::ItemFlags f = item->flags(); + if (column != 1) f &= ~Qt::ItemIsEditable; + else f |= Qt::ItemIsEditable; + item->setFlags(f); + if (column != 0) return; + QColor col = QColorDialog::getColor(item->data(0, Qt::DecorationRole).value(), this, "Select color for graphic", QColorDialog::ShowAlphaChannel); + if (!col.isValid()) return; + item->setData(0, Qt::DecorationRole, col); + updateGraphics(); +} + + +void MainWindow::on_buttonVarAdd_clicked() { + QTreeWidgetItem * ti = new QTreeWidgetItem(treeVariables); + ti->setSelected(true); + ti->setFlags(ti->flags() | Qt::ItemIsEditable); + treeVariables->addTopLevelItem(ti); + treeVariables->setFocus(); + treeVariables->editItem(ti); + buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0); +} + + +void MainWindow::on_buttonVarDel_clicked() { + QList si = treeVariables->selectedItems(); + foreach (QTreeWidgetItem * i, si) + delete i; + buttonVarClear->setEnabled(treeVariables->topLevelItemCount() > 0); +} + + +void MainWindow::on_buttonGraphicAdd_clicked() { + graphic->setGraphicsCount(graphic->graphicsCount() + 1); + graphic->setCurrentGraphic(graphic->graphicsCount() - 1); + QTreeWidgetItem * ti = new QTreeWidgetItem(treeGraphics); + ti->setSelected(true); + ti->setFlags(ti->flags() | Qt::ItemIsEditable); + ti->setCheckState(0, Qt::Checked); + ti->setData(0, Qt::DecorationRole, graphic->graphicColor()); + treeGraphics->addTopLevelItem(ti); + treeGraphics->setFocus(); + treeGraphics->editItem(ti, 1); + buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0); + updateGraphics(); +} + + +void MainWindow::on_buttonGraphicDel_clicked() { + QList si = treeGraphics->selectedItems(); + foreach (QTreeWidgetItem * i, si) + delete i; + buttonGraphicClear->setEnabled(treeGraphics->topLevelItemCount() > 0); + updateGraphics(); +} + + +void MainWindow::on_buttonGraphicClear_clicked() { + treeGraphics->clear(); + buttonGraphicClear->setEnabled(false); + updateGraphics(); +} + + +void MainWindow::on_tabWidget_currentChanged(int index) { + QPIEvaluator eval; + evaluator.clearCustomVariables(); + for (int i = 0; i < treeVariables->topLevelItemCount(); ++i) { + QString vn, vv; + vn = treeVariables->topLevelItem(i)->text(0); + vv = treeVariables->topLevelItem(i)->text(1); + eval.check(vv); + evaluator.setVariable(vn, eval.evaluate()); + } + if (index == 0) on_lineInput_returnPressed(); + if (index == 2) redrawGraphics(); +} diff --git a/piqt/utils/qpicalculator/mainwindow.h b/piqt/utils/qpicalculator/mainwindow.h new file mode 100644 index 0000000..efb44b9 --- /dev/null +++ b/piqt/utils/qpicalculator/mainwindow.h @@ -0,0 +1,56 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include "ui_mainwindow.h" +#include "qpievaluator.h" +#include "session_manager.h" + + +class MainWindow: public QMainWindow, private Ui::MainWindow +{ + Q_OBJECT +public: + MainWindow(QWidget * parent = 0); + ~MainWindow(); + +protected: + void changeEvent(QEvent * e); + +private: + void updateGraphics(); + void redrawGraphics(); + + QPIEvaluator evaluator; + QPalette npal, epal; + SessionManager session; + int ans; + bool active_; + +private slots: + void loading(QPIConfig & conf); + void saving(QPIConfig & conf); + void on_lineInput_textChanged(QString s); + void on_lineInput_returnPressed(); + void on_treeHistory_itemDoubleClicked(QTreeWidgetItem * item, int column) {lineInput->setText(item->text(0));} + void on_treeVariables_itemSelectionChanged() {buttonVarDel->setDisabled(treeVariables->selectedItems().isEmpty());} + void on_treeGraphics_itemSelectionChanged() {buttonGraphicDel->setDisabled(treeGraphics->selectedItems().isEmpty());} + void on_treeGraphics_itemChanged(QTreeWidgetItem * , int col) { if (active_) redrawGraphics();} + void on_treeGraphics_itemDoubleClicked(QTreeWidgetItem * item, int column); + void on_buttonVarAdd_clicked(); + void on_buttonVarDel_clicked(); + void on_buttonVarClear_clicked() {treeVariables->clear(); buttonVarClear->setEnabled(false);} + void on_buttonGraphicAdd_clicked(); + void on_buttonGraphicDel_clicked(); + void on_buttonGraphicClear_clicked(); + void on_tabWidget_currentChanged(int index); + void on_graphic_visualRectChanged() {redrawGraphics();} + +}; + +#endif // MAINWINDOW_H diff --git a/piqt/utils/qpicalculator/mainwindow.ui b/piqt/utils/qpicalculator/mainwindow.ui new file mode 100644 index 0000000..dae08e6 --- /dev/null +++ b/piqt/utils/qpicalculator/mainwindow.ui @@ -0,0 +1,379 @@ + + + MainWindow + + + + 0 + 0 + 780 + 521 + + + + QPICalculator + + + + :/icons/qpicalculator.png:/icons/qpicalculator.png + + + + + + + 2 + + + + Calculator + + + + + + Qt::ScrollBarAlwaysOff + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + true + + + 300 + + + + Expression + + + + + Result + + + + + + + + + + + Correct + + + + + + + 0 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + 14 + 75 + true + + + + 0 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + Variables + + + + + + Qt::ScrollBarAlwaysOff + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + true + + + 200 + + + + Name + + + + + Value + + + + + + + + + + + :/icons/list-add.png:/icons/list-add.png + + + + + + + false + + + + :/icons/edit-delete.png:/icons/edit-delete.png + + + Del + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + false + + + + :/icons/edit-clear.png:/icons/edit-clear.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Graphics + + + + + + Qt::Horizontal + + + + + + + Qt::ScrollBarAlwaysOff + + + QAbstractItemView::ExtendedSelection + + + QAbstractItemView::ScrollPerPixel + + + QAbstractItemView::ScrollPerPixel + + + false + + + false + + + true + + + false + + + 50 + + + + On + + + + + Function + + + + + + + + + + + :/icons/list-add.png:/icons/list-add.png + + + + + + + false + + + + :/icons/edit-delete.png:/icons/edit-delete.png + + + Del + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + false + + + + :/icons/edit-clear.png:/icons/edit-clear.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Graphic::BorderInputs|Graphic::Configure|Graphic::CursorAxis|Graphic::Fullscreen|Graphic::Grid|Graphic::Save + + + true + + + false + + + false + + + + + + + + + + + + + + + Graphic + QFrame +
graphic.h
+
+ + CLineEdit + QLineEdit +
clineedit.h
+
+
+ + + + + +
diff --git a/piqt/utils/qpicalculator/qpicalculator.qrc b/piqt/utils/qpicalculator/qpicalculator.qrc new file mode 100644 index 0000000..1a48626 --- /dev/null +++ b/piqt/utils/qpicalculator/qpicalculator.qrc @@ -0,0 +1,5 @@ + + + icons/qpicalculator.png + +