diff --git a/include/editor.h b/include/editor.h index 4357425..0c02ff9 100644 --- a/include/editor.h +++ b/include/editor.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "spellcheckerinterface.h" #include "settings.h" #include "highlight.h" @@ -391,6 +392,7 @@ private: QHash htmlSnippets; int inputEventKey; // workaround for Android + QTimer mousePressTimer; signals: void ready(int index); void statusBarText(int index, QString text); diff --git a/include/filebrowser.h b/include/filebrowser.h index a834b75..34111b8 100644 --- a/include/filebrowser.h +++ b/include/filebrowser.h @@ -12,6 +12,7 @@ #include #include #include +#include class FileBrowser : public QObject { @@ -54,6 +55,7 @@ private: QString fileBrowserHomeDir; bool acceptEnter; bool editMode; + QTimer mousePressTimer; public slots: void contextMenu(); private slots: diff --git a/include/gitbrowser.h b/include/gitbrowser.h index a174e1d..e285602 100644 --- a/include/gitbrowser.h +++ b/include/gitbrowser.h @@ -4,6 +4,7 @@ #include "settings.h" #include #include +#include class GitBrowser : public QObject { @@ -24,6 +25,7 @@ private: QTreeWidget * treeWidget; QColor errorColor; QColor msgColor; + QTimer mousePressTimer; public slots: void contextMenu(); private slots: diff --git a/src/editor.cpp b/src/editor.cpp index 309118f..6d30c62 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -76,7 +75,8 @@ const int FIRST_BLOCK_BIN_SEARCH_SCROLL_VALUE = 300; const QString SNIPPET_PREFIX = "Snippet: @"; -Editor::Editor(SpellCheckerInterface * spellChecker, Settings * settings, HighlightWords * highlightWords, CompleteWords * completeWords, HelpWords * helpWords, SpellWords * spellWords, QWidget * parent) : QTextEdit(parent), spellChecker(spellChecker), tooltipLabel(settings) +Editor::Editor(SpellCheckerInterface * spellChecker, Settings * settings, HighlightWords * highlightWords, CompleteWords * completeWords, HelpWords * helpWords, SpellWords * spellWords, QWidget * parent): + QTextEdit(parent), spellChecker(spellChecker), tooltipLabel(settings), mousePressTimer(this) { setMinimumSize(0, 0); setMaximumSize(16777215, 16777215); @@ -496,6 +496,9 @@ Editor::Editor(SpellCheckerInterface * spellChecker, Settings * settings, Highli // for Android inputEventKey = -1; setInputMethodHints(Qt::ImhNoPredictiveText | Qt::ImhMultiLine); + mousePressTimer.setInterval(1000); + mousePressTimer.setSingleShot(true); + connect(&mousePressTimer, SIGNAL(timeout()), this, SLOT(contextMenu())); } Editor::~Editor() @@ -2388,6 +2391,9 @@ void Editor::verticalScrollbarValueChangedDelayed() void Editor::mousePressEvent(QMouseEvent *e) { hideCompletePopup(); + #if defined(Q_OS_ANDROID) + mousePressTimer.start(); + #endif QTextEdit::mousePressEvent(e); } @@ -2398,6 +2404,9 @@ void Editor::mouseReleaseEvent(QMouseEvent *e) } else { hideTooltip(); } + #if defined(Q_OS_ANDROID) + if (mousePressTimer.isActive()) mousePressTimer.stop(); + #endif QTextEdit::mouseReleaseEvent(e); } diff --git a/src/filebrowser.cpp b/src/filebrowser.cpp index 1433cad..33f4df9 100644 --- a/src/filebrowser.cpp +++ b/src/filebrowser.cpp @@ -31,7 +31,7 @@ const QString FB_ACTION_NAME_CUT = "fb_cut"; const QString FB_ACTION_NAME_PASTE = "fb_paste"; FileBrowser::FileBrowser(QTreeWidget * widget, QLineEdit * line, Settings * settings): - treeWidget(widget), pathLine(line), menu(widget) + treeWidget(widget), pathLine(line), menu(widget), mousePressTimer(this) { fbpath = ""; fbcopypath = ""; fbcutpath = ""; fbcopyitem = nullptr; fbcutitem = nullptr; @@ -45,6 +45,10 @@ FileBrowser::FileBrowser(QTreeWidget * widget, QLineEdit * line, Settings * sett QShortcut * shortcutContextMenu = new QShortcut(QKeySequence(shortcutContextMenuStr), treeWidget); shortcutContextMenu->setContext(Qt::WidgetShortcut); connect(shortcutContextMenu, SIGNAL(activated()), this, SLOT(contextMenu())); + + mousePressTimer.setInterval(1000); + mousePressTimer.setSingleShot(true); + connect(&mousePressTimer, SIGNAL(timeout()), this, SLOT(contextMenu())); } void FileBrowser::initFileBrowser(QString homeDir) @@ -66,6 +70,9 @@ void FileBrowser::initFileBrowser(QString homeDir) treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(fileBrowserContextMenuRequested(QPoint))); treeWidget->installEventFilter(this); + #if defined(Q_OS_ANDROID) + treeWidget->viewport()->installEventFilter(this); // for context menu + #endif pathLine->installEventFilter(this); } @@ -715,6 +722,16 @@ bool FileBrowser::eventFilter(QObject *watched, QEvent *event) } } } + // context menu for Android + if(watched == treeWidget->viewport() && event->type() == QEvent::MouseButtonPress) { + QMouseEvent * mouseEvent = dynamic_cast(event); + if (mouseEvent != nullptr && mouseEvent->buttons() == Qt::LeftButton) { + mousePressTimer.start(); + } + } + if(watched == treeWidget->viewport() && event->type() == QEvent::MouseButtonRelease) { + if (mousePressTimer.isActive()) mousePressTimer.stop(); + } // focus if(watched == pathLine && event->type() == QEvent::KeyPress) { if (keyEvent->key() == Qt::Key_Down) { diff --git a/src/gitbrowser.cpp b/src/gitbrowser.cpp index 3d0dc4c..3a2b2cf 100644 --- a/src/gitbrowser.cpp +++ b/src/gitbrowser.cpp @@ -9,7 +9,7 @@ const QString GB_ACTION_NAME_RESET = "reset"; const QString GB_ACTION_NAME_COMMIT = "commit"; GitBrowser::GitBrowser(QTreeWidget * widget, Settings * settings): - treeWidget(widget) + treeWidget(widget), mousePressTimer(this) { treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(gitBrowserContextMenuRequested(QPoint))); @@ -20,11 +20,18 @@ GitBrowser::GitBrowser(QTreeWidget * widget, Settings * settings): msgColor = QColor(msgColorStr); treeWidget->installEventFilter(this); + #if defined(Q_OS_ANDROID) + treeWidget->viewport()->installEventFilter(this); // for context menu + #endif QString shortcutContextMenuStr = QString::fromStdString(settings->get("shortcut_context_menu")); QShortcut * shortcutContextMenu = new QShortcut(QKeySequence(shortcutContextMenuStr), treeWidget); shortcutContextMenu->setContext(Qt::WidgetShortcut); connect(shortcutContextMenu, SIGNAL(activated()), this, SLOT(contextMenu())); + + mousePressTimer.setInterval(1000); + mousePressTimer.setSingleShot(true); + connect(&mousePressTimer, SIGNAL(timeout()), this, SLOT(contextMenu())); } void GitBrowser::clear() @@ -166,6 +173,16 @@ bool GitBrowser::eventFilter(QObject *watched, QEvent *event) gbAddRequested(item); } } + // context menu for Android + if(watched == treeWidget->viewport() && event->type() == QEvent::MouseButtonPress) { + QMouseEvent * mouseEvent = dynamic_cast(event); + if (mouseEvent != nullptr && mouseEvent->buttons() == Qt::LeftButton) { + mousePressTimer.start(); + } + } + if(watched == treeWidget->viewport() && event->type() == QEvent::MouseButtonRelease) { + if (mousePressTimer.isActive()) mousePressTimer.stop(); + } return false; }