Commit aca15c31 authored by Moritz Molch's avatar Moritz Molch

BUG:329999 Don't switch focus to the canvas while editing Layer names

and values in sliders
parent 589864c6
......@@ -23,6 +23,8 @@
#include "KisDocumentSectionModel.h"
#include "KisDocumentSectionToolTip.h"
#include "KisDocumentSectionView.h"
#include "KisPart.h"
#include "input/kis_input_manager.h"
#include <QtDebug>
#include <QApplication>
......@@ -48,6 +50,11 @@ public:
static const int margin = 1;
};
void KisDocumentSectionDelegate::slotOnCloseEditor()
{
KisPart::currentInputManager()->slotFocusOnEnter(true);
}
KisDocumentSectionDelegate::KisDocumentSectionDelegate(KisDocumentSectionView *view, QObject *parent)
: QAbstractItemDelegate(parent)
, d(new Private)
......@@ -55,6 +62,8 @@ KisDocumentSectionDelegate::KisDocumentSectionDelegate(KisDocumentSectionView *v
d->view = view;
view->setItemDelegate(this);
QApplication::instance()->installEventFilter(this);
connect(this, SIGNAL(closeEditor(QWidget*)), this, SLOT(slotOnCloseEditor()));
}
KisDocumentSectionDelegate::~KisDocumentSectionDelegate()
......@@ -194,6 +203,7 @@ bool KisDocumentSectionDelegate::editorEvent(QEvent *event, QAbstractItemModel *
QWidget *KisDocumentSectionDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem&, const QModelIndex&) const
{
KisPart::currentInputManager()->slotFocusOnEnter(false);
d->edit = new QLineEdit(parent);
d->edit->installEventFilter(const_cast<KisDocumentSectionDelegate*>(this)); //hack?
return d->edit;
......
......@@ -71,6 +71,9 @@ private:
void drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void drawProgressBar(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private Q_SLOTS:
void slotOnCloseEditor();
};
#endif
......@@ -1186,6 +1186,11 @@ bool KisMainWindow::restoreWorkspace(const QByteArray &state)
return success;
}
KisViewManager *KisMainWindow::viewManager() const
{
return d->viewManager;
}
void KisMainWindow::slotDocumentInfo()
{
if (!d->activeView->document())
......
......@@ -43,6 +43,7 @@ class KisPrintJob;
class KoDockFactoryBase;
class QDockWidget;
class KisView;
class KisViewManager;
// Calligra class but not in main module
......@@ -146,6 +147,8 @@ public:
*/
bool restoreWorkspace(const QByteArray &state);
KisViewManager *viewManager() const;
Q_SIGNALS:
/**
......
......@@ -641,7 +641,10 @@ void KisPart::startCustomDocument(KisDocument* doc)
d->startupWidget->hide();
}
KisInputManager* KisPart::currentInputManager()
{
return instance()->currentMainwindow()->viewManager()->inputManager();
}
#include <KisPart.moc>
......@@ -181,6 +181,8 @@ Q_SIGNALS:
public:
static KisInputManager *currentInputManager();
//------------------ view management ------------------
/**
......
......@@ -84,6 +84,8 @@ public:
, moveEventCompressor(10 /* ms */, KisSignalCompressor::FIRST_ACTIVE)
, testingAcceptCompressedTabletEvents(false)
, testingCompressBrushEvents(false)
, focusOnEnter(true)
, containsPointer(true)
{
KisConfig cfg;
disableTouchOnCanvas = cfg.disableTouchOnCanvas();
......@@ -142,6 +144,9 @@ public:
class CanvasSwitcher;
QPointer<CanvasSwitcher> canvasSwitcher;
bool focusOnEnter;
bool containsPointer;
};
template <class Event, bool useBlocking>
......@@ -576,6 +581,19 @@ void KisInputManager::stopIgnoringEvents()
stop_ignore_cursor_events();
}
void KisInputManager::slotFocusOnEnter(bool value)
{
if (d->focusOnEnter == value) {
return;
}
d->focusOnEnter = value;
if (d->focusOnEnter && d->containsPointer) {
d->canvas->canvasWidget()->setFocus();
}
}
#if defined (__clang__)
#pragma GCC diagnostic ignored "-Wswitch"
#endif
......@@ -718,10 +736,13 @@ bool KisInputManager::eventFilter(QObject* object, QEvent* event)
}
case QEvent::Enter:
d->debugEvent<QEvent, false>(event);
d->containsPointer = true;
//Make sure the input actions know we are active.
KisAbstractInputAction::setInputManager(this);
//Ensure we have focus so we get key events.
d->canvas->canvasWidget()->setFocus();
if (d->focusOnEnter) {
d->canvas->canvasWidget()->setFocus();
}
stop_ignore_cursor_events();
touch_stop_block_press_events();
......@@ -729,6 +750,7 @@ bool KisInputManager::eventFilter(QObject* object, QEvent* event)
break;
case QEvent::Leave:
d->debugEvent<QEvent, false>(event);
d->containsPointer = false;
/**
* We won't get a TabletProximityLeave event when the tablet
* is hovering above some other widget, so restore cursor
......
......@@ -116,6 +116,7 @@ public:
public Q_SLOTS:
void stopIgnoringEvents();
void slotFocusOnEnter(bool value);
private Q_SLOTS:
void slotToolChanged();
......
......@@ -32,6 +32,9 @@
#include <QtDebug>
#include <QDoubleSpinBox>
#include "KisPart.h"
#include "input/kis_input_manager.h"
class KisAbstractSliderSpinBoxPrivate {
public:
QLineEdit* edit;
......@@ -112,6 +115,7 @@ void KisAbstractSliderSpinBox::showEdit()
d->edit->show();
d->edit->setFocus(Qt::OtherFocusReason);
update();
KisPart::currentInputManager()->slotFocusOnEnter(false);
}
void KisAbstractSliderSpinBox::hideEdit()
......@@ -119,6 +123,7 @@ void KisAbstractSliderSpinBox::hideEdit()
Q_D(KisAbstractSliderSpinBox);
d->edit->hide();
update();
KisPart::currentInputManager()->slotFocusOnEnter(true);
}
void KisAbstractSliderSpinBox::paintEvent(QPaintEvent* e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment