Commit a355c5a1 authored by Christoph Cullmann's avatar Christoph Cullmann

better way to disable updates to avoid nasty flicker

parent 7e3dcdf3
/* 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
......@@ -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) {
......
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