diff --git a/CMakeLists.txt b/CMakeLists.txt index 7046114..8bb49ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(qad) set(qad_MAJOR 1) -set(qad_MINOR 12) -set(qad_REVISION 1) +set(qad_MINOR 13) +set(qad_REVISION 0) set(qad_SUFFIX ) set(qad_COMPANY SHS) set(qad_DOMAIN org.SHS) diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index 7a6b00b..55c6109 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -647,6 +647,11 @@ void Graphic::setGraphicsDataRaw(const QByteArray & ba) { } +void Graphic::setFloatingAxisEnabled(bool on) { + ui->checkGuides->setChecked(on); +} + + void Graphic::setButtons(Graphic::Buttons b) { buttons_ = b; ui->buttonAutofit->setVisible(b.testFlag(Autofit)); diff --git a/libs/graphic/graphic.h b/libs/graphic/graphic.h index 25d0800..5aca02f 100644 --- a/libs/graphic/graphic.h +++ b/libs/graphic/graphic.h @@ -297,6 +297,7 @@ public slots: void setGraduationSteps(double sx, double sy) {gridx = sx; gridy = sy; if (aupdate) update();} void setAxisType(AxisType t) {axis_type_x = t; if (aupdate) update();} void setFloatingAxisType(FloatingAxisType t) {floating_axis_type = t; setGuidesCursor(); if (aupdate) update();} + void setFloatingAxisEnabled(bool on); void addPoint(const QPointF & p, int graphic, bool update_ = true); void addPoint(const QPointF & p, bool update = true) {addPoint(p, curGraphic, update);} diff --git a/libs/widgets/qcodeedit.cpp b/libs/widgets/qcodeedit.cpp index e6ad0ff..b9bb956 100644 --- a/libs/widgets/qcodeedit.cpp +++ b/libs/widgets/qcodeedit.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) # include #endif @@ -58,7 +59,7 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent) { } lbl_help[lhF1]->setIcon(QIcon(":/icons/f1.png")); lbl_help[lhF1]->setText(tr("Press F1 for details")); - lbl_help[lhF1]->setVisible(false); + help_visible = true; completer = new QCodeEditCompleter(); ui->textCode->setCursorWidth(qMax(qRound(fontHeight() / 10.), 1)); @@ -117,6 +118,8 @@ QCodeEdit::QCodeEdit(QWidget * parent): QWidget(parent) { addAction(a);*/ connect(completer, SIGNAL(itemDoubleClicked(QTreeWidgetItem * ,int)), this, SLOT(commitCompletition())); + connect(completer, SIGNAL(commit()), this, SLOT(commitCompletition())); + connect(completer, SIGNAL(gotoHRef(QCodeEdit::ACEntry)), this, SLOT(gotoHelpHRef(QCodeEdit::ACEntry))); connect(ui->textCode->verticalScrollBar(), SIGNAL(valueChanged(int)), ui->textLines->verticalScrollBar(), SLOT(setValue(int))); connect(ui->textCode->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(hideHelp())); connect(ui->textCode, SIGNAL(textChanged()), this, SLOT(textEdit_textChanged())); @@ -237,7 +240,12 @@ bool QCodeEdit::showLineNumbers() const { void QCodeEdit::setHelpHintVisible(bool on) { - lbl_help[lhF1]->setVisible(on); + help_visible = on; +} + + +bool QCodeEdit::isHelpHintVisible() const { + return help_visible; } @@ -436,10 +444,11 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) { QKeyEvent * ke; QChar kc(0); switch (e->type()) { - case QEvent::ToolTip: { - QTextCursor tc = ui->textCode->cursorForPosition(((QHelpEvent*)e)->pos()); - tc.select(QTextCursor::WordUnderCursor); - raiseHelp(tc); + case QEvent::ToolTip: + if (completer->isHidden()) { + QTextCursor tc = ui->textCode->cursorForPosition(((QHelpEvent*)e)->pos()); + tc.select(QTextCursor::WordUnderCursor); + raiseHelp(tc); } break; case QEvent::KeyPress: @@ -534,6 +543,10 @@ bool QCodeEdit::eventFilter(QObject * o, QEvent * e) { case Qt::Key_Control: showLink(); break; + case Qt::Key_F1: + if (widget_help->isVisible()) + gotoHelpHRef(help_entry); + break; default: break; } if (!ke->text().isEmpty()) @@ -1161,6 +1174,7 @@ void QCodeEdit::raiseHelp(QTextCursor tc, int arg) { applyExtraSelection(); //tc.movePosition(QTextCursor::StartOfWord, QTextCursor::MoveAnchor); lbl_help[lhMain]->setFont(font()); + lbl_help[lhF1]->setVisible(!e.help_href.isEmpty() && help_visible); qApp->processEvents(); widget_help->adjustSize(); widget_help->resize(widget_help->sizeHint()); @@ -1178,13 +1192,21 @@ void QCodeEdit::raiseHelp(QTextCursor tc, int arg) { widget_help->move(ui->textCode->viewport()->mapToGlobal(whp)); widget_help->show(); widget_help->raise(); + help_entry = e; cursor_scope = scope.first; cursor_scope << scope.second; //qDebug() << "tooltip" << st; } +void QCodeEdit::gotoHelpHRef(QCodeEdit::ACEntry e) { + if (e.help_href.isEmpty()) return; + QDesktopServices::openUrl(e.help_href); +} + + void QCodeEdit::hideHelp() { + help_entry = ACEntry(); widget_help->hide(); es_cursor.cursor = QTextCursor(); cursor_scope.clear(); @@ -1313,7 +1335,7 @@ void QCodeEdit::invokeAutoCompletition(bool force) { hideHelp(); return; } - if (word_complet) acl << wordsCompletitionList(scope.second); + if (word_complete) acl << wordsCompletitionList(scope.second); QFont bf(font()); bf.setBold(true); foreach (const ACSection & ac, acl) { @@ -1498,3 +1520,11 @@ void QCodeEdit::on_buttonReplaceAll_clicked() { _replacing = false; textEdit_textChanged(); } + + + + +QString QCodeEdit::ACEntry::declaration() const { + if (declaration_pos < 0 || declaration_file.isEmpty()) return QString(); + return (declaration_file + ": %1").arg(declaration_pos); +} diff --git a/libs/widgets/qcodeedit.h b/libs/widgets/qcodeedit.h index 67a6fc3..9521df0 100644 --- a/libs/widgets/qcodeedit.h +++ b/libs/widgets/qcodeedit.h @@ -58,10 +58,16 @@ public: ACEntry(const QString & t = QString(), const QString & n = QString(), const QString & h = QString()): type(t), name(n), hint(h) {declaration_pos = -1;} bool isNull() const {return type.isEmpty() && name.isEmpty();} + QString declaration() const; + ACEntry & addHint(QString h) {hint = h; return *this;} + ACEntry & addHelpHRef(QUrl h) {help_href = h; return *this;} + ACEntry & addCustomData(QVariant d) {custom_data = d; return *this;} QString type; QString name; QString hint; int declaration_pos; + QString declaration_file; + QUrl help_href; QVariant custom_data; }; @@ -80,6 +86,7 @@ public: bool showSpaces() const {return spaces_;} bool showLineNumbers() const; void setHelpHintVisible(bool on); + bool isHelpHintVisible() const; void setEditorFont(QFont f); QFont editorFont() const; @@ -88,7 +95,7 @@ public: void registerAutoCompletitionClass(int id, ACClassType ac_class, const QString & name, const QIcon & icon = QIcon()); - bool wordCompletitionEnabled() const {return word_complet;} + bool wordCompletitionEnabled() const {return word_complete;} protected: typedef QPair StringsPair; @@ -136,10 +143,10 @@ private: QList es_selected, es_custom, es_brackets, es_search_list; QMap ac_classes; QStringList cursor_scope; - ACEntry link_entry; + ACEntry link_entry, help_entry; int prev_lc, auto_comp_pl, timer, cur_search_ind, pos_press, pos_el_press; bool spaces_, _ignore_focus_out, _first, _destructor, _replacing; - bool word_complet; + bool word_complete, help_visible; bool eventFilter(QObject * o, QEvent * e) override; void showEvent(QShowEvent * ) override; @@ -155,6 +162,7 @@ private: private slots: void _activateLink(QCodeEdit::ACEntry e) {linkClicked(e);} + void gotoHelpHRef(QCodeEdit::ACEntry e); void syncScrolls(); void scrollUp(); void scrollDown(); @@ -195,7 +203,7 @@ public slots: void searchNext(bool next = true); void searchPrevious(); void hideSearch(); - void setWordCompletitionEnabled(bool on) {word_complet = on;} + void setWordCompletitionEnabled(bool on) {word_complete = on;} signals: void textChanged(); diff --git a/libs/widgets/qcodeedit_completer_p.cpp b/libs/widgets/qcodeedit_completer_p.cpp index 1167e9b..412a0d6 100644 --- a/libs/widgets/qcodeedit_completer_p.cpp +++ b/libs/widgets/qcodeedit_completer_p.cpp @@ -65,6 +65,7 @@ void QCodeEditCompleter::addItems(QFont f, const QCodeEdit::ACClass & cl, const ni->setIcon(0, cl.icon); ni->setText(0, s.type); ni->setText(1, s.name); + ni->setData(0, Qt::UserRole, s.help_href); addTopLevelItem(ni); } } @@ -95,6 +96,26 @@ QString QCodeEditCompleter::currentValue() const { } +void QCodeEditCompleter::keyPressEvent(QKeyEvent * e) { + switch (e->key()) { + case Qt::Key_Escape: + hide(); + break; + case Qt::Key_Return: + emit commit(); + break; + case Qt::Key_F1: + if (currentItem()) { + QString href = currentItem()->data(0, Qt::UserRole).toString(); + emit gotoHRef(QCodeEdit::ACEntry().addHelpHRef(href)); + } + break; + default: break; + } + QTreeWidget::keyPressEvent(e); +} + + void QCodeEditCompleter::adjust() { int sz = sizeHint().width(); resize(sz, fontHeight() * 16); diff --git a/libs/widgets/qcodeedit_completer_p.h b/libs/widgets/qcodeedit_completer_p.h index 3afcfa0..f72d56d 100644 --- a/libs/widgets/qcodeedit_completer_p.h +++ b/libs/widgets/qcodeedit_completer_p.h @@ -40,11 +40,14 @@ public: QString currentValue() const; private: + void keyPressEvent(QKeyEvent * e) override; private slots: void adjust(); signals: + void commit(); + void gotoHRef(QCodeEdit::ACEntry e); };