aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Cullmann <cullmann@kde.org>2014-01-23 12:56:02 (GMT)
committerChristoph Cullmann <cullmann@kde.org>2014-01-23 12:56:02 (GMT)
commita355c5a1ba91c1fcff0f4faee0de1d4c880b64fa (patch)
tree8156ea2532af21dd323d954e07645f78e56498c9
parent7e3dcdf3e7ed66d5daafa94426f66dda74817e26 (diff)
better way to disable updates to avoid nasty flicker
-rw-r--r--kate/app/kateupdatedisabler.h57
-rw-r--r--kate/app/kateviewmanager.cpp25
2 files changed, 78 insertions, 4 deletions
diff --git a/kate/app/kateupdatedisabler.h b/kate/app/kateupdatedisabler.h
new file mode 100644
index 0000000..b5dea99
--- /dev/null
+++ b/kate/app/kateupdatedisabler.h
@@ -0,0 +1,57 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2014 Christoph Cullmann <cullmann@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KATE_UPDATE_DISABLER
+#define KATE_UPDATE_DISABLER
+
+#include <QPointer>
+#include <QWidget>
+
+class KateUpdateDisabler
+{
+public:
+ /**
+ * Disable updates for given widget.
+ * Will auto-enable them on destruction, like a mutex locker releases its lock.
+ * @param widget widget to disable updates for
+ */
+ explicit KateUpdateDisabler (QWidget *widget)
+ : m_widget ((widget && widget->updatesEnabled()) ? widget : nullptr)
+ {
+ if (m_widget)
+ m_widget->setUpdatesEnabled(false);
+ }
+
+ /**
+ * Enable updates again on destruction.
+ */
+ ~KateUpdateDisabler()
+ {
+ if (m_widget)
+ m_widget->setUpdatesEnabled(true);
+ }
+
+private:
+ /**
+ * pointer to widget, if not null, enable/disable widgets
+ */
+ QPointer<QWidget> m_widget;
+};
+
+#endif
diff --git a/kate/app/kateviewmanager.cpp b/kate/app/kateviewmanager.cpp
index 5e67601..92339b5 100644
--- a/kate/app/kateviewmanager.cpp
+++ b/kate/app/kateviewmanager.cpp
@@ -24,6 +24,7 @@
#include "katemainwindow.h"
#include "katedocmanager.h"
#include "kateviewspace.h"
+#include "kateupdatedisabler.h"
#include "katedebug.h"
#include <KTextEditor/View>
@@ -551,6 +552,9 @@ void KateViewManager::activateView(KTextEditor::View *view)
#endif
if (!m_activeStates[view]) {
+ // avoid flicker
+ KateUpdateDisabler disableUpdates (mainWindow());
+
if (!activeViewSpace()->showView(view)) {
// since it wasn't found, give'em a new one
createView(view->document());
@@ -559,7 +563,6 @@ void KateViewManager::activateView(KTextEditor::View *view)
setActiveView(view);
- mainWindow()->setUpdatesEnabled(false);
bool toolbarVisible = mainWindow()->toolBar()->isVisible();
if (toolbarVisible) {
mainWindow()->toolBar()->hide(); // hide to avoid toolbar flickering
@@ -578,7 +581,6 @@ void KateViewManager::activateView(KTextEditor::View *view)
if (toolbarVisible) {
mainWindow()->toolBar()->show();
}
- mainWindow()->setUpdatesEnabled(true);
// remember age of this view
m_lruViews[view] = m_minAge--;
@@ -665,7 +667,10 @@ void KateViewManager::closeViews(KTextEditor::Document *doc)
return;
}
- setUpdatesEnabled(false);
+ /**
+ * disable updates hard (we can't use KateUpdateDisabler here, we have delayed signal
+ */
+ mainWindow()->setUpdatesEnabled(false);
QTimer::singleShot(0, this, SLOT(slotDelayedViewChanged()));
}
@@ -684,7 +689,10 @@ void KateViewManager::slotDelayedViewChanged()
emit viewChanged(newActiveView);
- setUpdatesEnabled(true);
+ /**
+ * enable updates hard (we can't use KateUpdateDisabler here, we have delayed signal
+ */
+ mainWindow()->setUpdatesEnabled(true);
}
void KateViewManager::splitViewSpace(KateViewSpace *vs, // = 0
@@ -703,6 +711,9 @@ void KateViewManager::splitViewSpace(KateViewSpace *vs, // = 0
if (!currentSplitter) {
return;
}
+
+ // avoid flicker
+ KateUpdateDisabler disableUpdates (mainWindow());
// index where to insert new splitter/viewspace
const int index = currentSplitter->indexOf(vs);
@@ -770,6 +781,9 @@ void KateViewManager::removeViewSpace(KateViewSpace *viewspace)
if (!currentSplitter) {
return;
}
+
+ // avoid flicker
+ KateUpdateDisabler disableUpdates (mainWindow());
// delete views of the viewspace
while (viewspace->currentView()) {
@@ -830,6 +844,9 @@ void KateViewManager::slotCloseCurrentViewSpace()
void KateViewManager::slotCloseOtherViews()
{
+ // avoid flicker
+ KateUpdateDisabler disableUpdates (mainWindow());
+
KateViewSpace *active = activeViewSpace();
foreach(KateViewSpace * v, m_viewSpaceList) {
if (active != v) {