long press context menu for android
This commit is contained in:
parent
5a0200dfab
commit
e295d8f5fe
|
@ -12,6 +12,7 @@
|
|||
#include <QLabel>
|
||||
#include <QHash>
|
||||
#include <QToolButton>
|
||||
#include <QTimer>
|
||||
#include "spellcheckerinterface.h"
|
||||
#include "settings.h"
|
||||
#include "highlight.h"
|
||||
|
@ -391,6 +392,7 @@ private:
|
|||
QHash<QString, QString> htmlSnippets;
|
||||
|
||||
int inputEventKey; // workaround for Android
|
||||
QTimer mousePressTimer;
|
||||
signals:
|
||||
void ready(int index);
|
||||
void statusBarText(int index, QString text);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QLineEdit>
|
||||
#include <QEvent>
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
|
||||
class FileBrowser : public QObject
|
||||
{
|
||||
|
@ -54,6 +55,7 @@ private:
|
|||
QString fileBrowserHomeDir;
|
||||
bool acceptEnter;
|
||||
bool editMode;
|
||||
QTimer mousePressTimer;
|
||||
public slots:
|
||||
void contextMenu();
|
||||
private slots:
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "settings.h"
|
||||
#include <QTreeWidget>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
|
||||
class GitBrowser : public QObject
|
||||
{
|
||||
|
@ -24,6 +25,7 @@ private:
|
|||
QTreeWidget * treeWidget;
|
||||
QColor errorColor;
|
||||
QColor msgColor;
|
||||
QTimer mousePressTimer;
|
||||
public slots:
|
||||
void contextMenu();
|
||||
private slots:
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <QTextLayout>
|
||||
#include <QDesktopWidget>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QTimer>
|
||||
#include <QFileInfo>
|
||||
#include <QDateTime>
|
||||
#include <QMenu>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<QMouseEvent *>(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) {
|
||||
|
|
|
@ -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<QMouseEvent *>(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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue