2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2013-04-09 14:22:28 +02:00
|
|
|
#include "futureprogress.h"
|
2009-01-13 13:54:45 +01:00
|
|
|
#include "progressmanager_p.h"
|
2013-03-22 14:14:21 +01:00
|
|
|
#include "progressbar.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "progressview.h"
|
2013-03-22 14:14:21 +01:00
|
|
|
#include "../actionmanager/actionmanager.h"
|
2015-02-26 13:38:54 +01:00
|
|
|
#include "../actionmanager/command.h"
|
2013-03-22 14:14:21 +01:00
|
|
|
#include "../icontext.h"
|
|
|
|
|
#include "../coreconstants.h"
|
2012-09-27 17:20:00 +02:00
|
|
|
#include "../icore.h"
|
2018-01-24 17:41:53 +01:00
|
|
|
#include "../statusbarmanager.h"
|
2013-03-22 14:14:21 +01:00
|
|
|
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <utils/hostosinfo.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2013-03-22 14:14:21 +01:00
|
|
|
#include <utils/stylehelper.h>
|
Implement theming for QtCreator
Adds a 'Theme' tab to the environment settings and a '-theme' command
line option.
A theme is a combination of colors, gradients, flags and style
information.
There are two themes:
- 'default': preserves the current default look
- 'dark': uses a more flat for many widgets, dark color theme
for everything
This does not use a stylesheet (too limited), but rather sets
the palette via C++ and modifies drawing behavior.
Overall, the look is more flat (removed some gradients and bevels).
Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE
Desktop (Oxygen base style).
For a screenshot, see
https://gist.github.com/thorbenk/5ab06bea726de0aa7473
Changes:
- Introduce class Theme, defining the interface how to access theme
specific settings. The class reads a .creatortheme file (INI file, via
QSettings)
- Define named colors in the [Palette] section
(see dark.creatortheme for example usage)
- Use either named colors of AARRGGBB (hex) in the [Colors]
section
- A file ending with .creatortheme may be supplied
to the '-theme' command line option
- A global Theme instance can be accessed via creatorTheme()
- Query colors, gradients, icons and flags from the theme
were possible (TODO: use this in more places...)
- There are very many color roles. It seems better to me
to describe the role clearly, and then to consolidate later
in the actual theme by assigning the same color.
For example, one can set the text color of the output pane button
individualy.
- Many elements are also drawn differently.
For the dark theme, I wanted to have a flatter look.
- Introduce Theme::WidgetStyle enum, for now {Original, Flat}.
- The theme specifies which kind of widget style it wants.
- The drawing code queries the theme's style flag and
switches between the original, gradient based look and
the new, flat look.
- Create some custom icons which look better on dark background
(wip, currently folder/file icons)
- Let ManhattanStyle draw some elements for non-panelwidgets, too
(open/close arrows in QTreeView, custom folder/file icons)
- For the welcomescreen, pass the WelcomeTheme class.
WelcomeTheme exposes theme colors as Q_PROPERTY accessible from
.qml
- Themes can be modified via the 'Themes' tab in the environment
settings.
TODO:
* Unify image handling
* Avoid style name references
* Fix gradients
Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
|
|
|
#include <utils/theme/theme.h>
|
2019-04-09 17:10:22 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2013-03-22 14:14:21 +01:00
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QHBoxLayout>
|
2013-07-08 13:45:05 +02:00
|
|
|
#include <QMouseEvent>
|
2013-03-22 14:14:21 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
#include <QStyle>
|
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
#include <QTimer>
|
2013-05-27 10:38:49 +02:00
|
|
|
#include <QVariant>
|
|
|
|
|
|
2014-05-05 14:23:37 +02:00
|
|
|
#include <math.h>
|
|
|
|
|
|
2013-05-27 10:38:49 +02:00
|
|
|
static const char kSettingsGroup[] = "Progress";
|
|
|
|
|
static const char kDetailsPinned[] = "DetailsPinned";
|
2016-02-17 23:12:10 +02:00
|
|
|
static const int TimerInterval = 100; // 100 ms
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
Implement theming for QtCreator
Adds a 'Theme' tab to the environment settings and a '-theme' command
line option.
A theme is a combination of colors, gradients, flags and style
information.
There are two themes:
- 'default': preserves the current default look
- 'dark': uses a more flat for many widgets, dark color theme
for everything
This does not use a stylesheet (too limited), but rather sets
the palette via C++ and modifies drawing behavior.
Overall, the look is more flat (removed some gradients and bevels).
Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE
Desktop (Oxygen base style).
For a screenshot, see
https://gist.github.com/thorbenk/5ab06bea726de0aa7473
Changes:
- Introduce class Theme, defining the interface how to access theme
specific settings. The class reads a .creatortheme file (INI file, via
QSettings)
- Define named colors in the [Palette] section
(see dark.creatortheme for example usage)
- Use either named colors of AARRGGBB (hex) in the [Colors]
section
- A file ending with .creatortheme may be supplied
to the '-theme' command line option
- A global Theme instance can be accessed via creatorTheme()
- Query colors, gradients, icons and flags from the theme
were possible (TODO: use this in more places...)
- There are very many color roles. It seems better to me
to describe the role clearly, and then to consolidate later
in the actual theme by assigning the same color.
For example, one can set the text color of the output pane button
individualy.
- Many elements are also drawn differently.
For the dark theme, I wanted to have a flatter look.
- Introduce Theme::WidgetStyle enum, for now {Original, Flat}.
- The theme specifies which kind of widget style it wants.
- The drawing code queries the theme's style flag and
switches between the original, gradient based look and
the new, flat look.
- Create some custom icons which look better on dark background
(wip, currently folder/file icons)
- Let ManhattanStyle draw some elements for non-panelwidgets, too
(open/close arrows in QTreeView, custom folder/file icons)
- For the welcomescreen, pass the WelcomeTheme class.
WelcomeTheme exposes theme colors as Q_PROPERTY accessible from
.qml
- Themes can be modified via the 'Themes' tab in the environment
settings.
TODO:
* Unify image handling
* Avoid style name references
* Fix gradients
Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
2014-10-14 19:09:48 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-12-02 15:05:49 +01:00
|
|
|
/*!
|
|
|
|
|
\mainclass
|
|
|
|
|
\class Core::ProgressManager
|
|
|
|
|
\brief The ProgressManager class is used to show a user interface
|
|
|
|
|
for running tasks in Qt Creator.
|
|
|
|
|
|
|
|
|
|
It tracks the progress of a task that it is told
|
2013-11-15 17:11:34 +01:00
|
|
|
about, and shows a progress indicator in the lower right
|
2009-12-02 15:05:49 +01:00
|
|
|
of Qt Creator's main window to the user.
|
|
|
|
|
The progress indicator also allows the user to cancel the task.
|
|
|
|
|
|
|
|
|
|
You get the single instance of this class via the
|
2013-10-23 12:53:10 +02:00
|
|
|
ProgressManager::instance() function.
|
2009-12-02 15:05:49 +01:00
|
|
|
|
|
|
|
|
\section1 Registering a task
|
|
|
|
|
The ProgressManager API uses QtConcurrent as the basis for defining
|
|
|
|
|
tasks. A task consists of the following properties:
|
|
|
|
|
|
|
|
|
|
\table
|
|
|
|
|
\header
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Property
|
|
|
|
|
\li Type
|
|
|
|
|
\li Description
|
2009-12-02 15:05:49 +01:00
|
|
|
\row
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Task abstraction
|
|
|
|
|
\li \c QFuture<void>
|
|
|
|
|
\li A \c QFuture object that represents the task which is
|
2009-12-02 15:05:49 +01:00
|
|
|
responsible for reporting the state of the task. See below
|
|
|
|
|
for coding patterns how to create this object for your
|
|
|
|
|
specific task.
|
|
|
|
|
\row
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Title
|
|
|
|
|
\li \c QString
|
|
|
|
|
\li A very short title describing your task. This is shown
|
2009-12-02 15:05:49 +01:00
|
|
|
as a title over the progress bar.
|
|
|
|
|
\row
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Type
|
|
|
|
|
\li \c QString
|
|
|
|
|
\li A string identifier that is used to group different tasks that
|
2009-12-02 15:05:49 +01:00
|
|
|
belong together.
|
|
|
|
|
For example, all the search operations use the same type
|
|
|
|
|
identifier.
|
|
|
|
|
\row
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Flags
|
|
|
|
|
\li \l ProgressManager::ProgressFlags
|
|
|
|
|
\li Additional flags that specify how the progress bar should
|
2009-12-02 15:05:49 +01:00
|
|
|
be presented to the user.
|
|
|
|
|
\endtable
|
|
|
|
|
|
|
|
|
|
To register a task you create your \c QFuture<void> object, and call
|
2013-10-07 13:34:40 +02:00
|
|
|
addTask(). This function returns a
|
2009-12-02 15:05:49 +01:00
|
|
|
\l{Core::FutureProgress}{FutureProgress}
|
|
|
|
|
object that you can use to further customize the progress bar's appearance.
|
|
|
|
|
See the \l{Core::FutureProgress}{FutureProgress} documentation for
|
|
|
|
|
details.
|
|
|
|
|
|
|
|
|
|
In the following you will learn about two common patterns how to
|
|
|
|
|
create the \c QFuture<void> object for your task.
|
|
|
|
|
|
|
|
|
|
\section2 Create a threaded task with QtConcurrent
|
|
|
|
|
The first option is to directly use QtConcurrent to actually
|
|
|
|
|
start a task concurrently in a different thread.
|
2013-10-07 13:34:40 +02:00
|
|
|
QtConcurrent has several different functions to run e.g.
|
|
|
|
|
a class function in a different thread. Qt Creator itself
|
2009-12-02 15:05:49 +01:00
|
|
|
adds a few more in \c{src/libs/qtconcurrent/runextensions.h}.
|
2013-10-07 13:34:40 +02:00
|
|
|
The QtConcurrent functions to run a concurrent task return a
|
2009-12-02 15:05:49 +01:00
|
|
|
\c QFuture object. This is what you want to give the
|
2013-10-07 13:34:40 +02:00
|
|
|
ProgressManager in the addTask() function.
|
2009-12-02 15:05:49 +01:00
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
Have a look at e.g Core::ILocatorFilter. Locator filters implement
|
2013-10-07 13:34:40 +02:00
|
|
|
a function \c refresh which takes a \c QFutureInterface object
|
|
|
|
|
as a parameter. These functions look something like:
|
2009-12-02 15:05:49 +01:00
|
|
|
\code
|
|
|
|
|
void Filter::refresh(QFutureInterface<void> &future) {
|
|
|
|
|
future.setProgressRange(0, MAX);
|
|
|
|
|
...
|
|
|
|
|
while (!future.isCanceled()) {
|
|
|
|
|
// Do a part of the long stuff
|
|
|
|
|
...
|
|
|
|
|
future.setProgressValue(currentProgress);
|
|
|
|
|
...
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
The actual refresh, which calls all the filters' refresh functions
|
2009-12-02 15:05:49 +01:00
|
|
|
in a different thread, looks like this:
|
|
|
|
|
\code
|
2016-02-15 16:26:11 +01:00
|
|
|
QFuture<void> task = Utils::map(filters, &ILocatorFilter::refresh);
|
2013-10-23 12:53:10 +02:00
|
|
|
Core::FutureProgress *progress = Core::ProgressManager::addTask(task, tr("Indexing"),
|
|
|
|
|
Locator::Constants::TASK_INDEX);
|
2009-12-02 15:05:49 +01:00
|
|
|
\endcode
|
2016-02-15 16:26:11 +01:00
|
|
|
First, we to start an asynchronous operation which calls all the filters'
|
2013-10-07 13:34:40 +02:00
|
|
|
refresh function. After that we register the returned QFuture object
|
2009-12-02 15:05:49 +01:00
|
|
|
with the ProgressManager.
|
|
|
|
|
|
|
|
|
|
\section2 Manually create QtConcurrent objects for your thread
|
|
|
|
|
If your task has its own means to create and run a thread,
|
|
|
|
|
you need to create the necessary objects yourselves, and
|
|
|
|
|
report the start/stop state.
|
|
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
// We are already running in a different thread here
|
|
|
|
|
QFutureInterface<void> *progressObject = new QFutureInterface<void>;
|
|
|
|
|
progressObject->setProgressRange(0, MAX);
|
2013-10-23 12:53:10 +02:00
|
|
|
Core::ProgressManager::addTask(progressObject->future(), tr("DoIt"), MYTASKTYPE);
|
2009-12-02 15:05:49 +01:00
|
|
|
progressObject->reportStarted();
|
|
|
|
|
// Do something
|
|
|
|
|
...
|
|
|
|
|
progressObject->setProgressValue(currentProgress);
|
|
|
|
|
...
|
|
|
|
|
// We have done what we needed to do
|
|
|
|
|
progressObject->reportFinished();
|
|
|
|
|
delete progressObject;
|
|
|
|
|
\endcode
|
|
|
|
|
In the first line we create the QFutureInterface object that will be
|
|
|
|
|
our way for reporting the task's state.
|
|
|
|
|
The first thing we report is the expected range of the progress values.
|
|
|
|
|
We register the task with the ProgressManager, using the internal
|
|
|
|
|
QFuture object that has been created for our QFutureInterface object.
|
|
|
|
|
Next we report that the task has begun and start doing our actual
|
2013-10-07 13:34:40 +02:00
|
|
|
work, regularly reporting the progress via the functions
|
2009-12-02 15:05:49 +01:00
|
|
|
in QFutureInterface. After the long taking operation has finished,
|
|
|
|
|
we report so through the QFutureInterface object, and delete it
|
|
|
|
|
afterwards.
|
2009-12-21 17:11:47 +01:00
|
|
|
|
|
|
|
|
\section1 Customizing progress appearance
|
|
|
|
|
|
|
|
|
|
You can set a custom widget to show below the progress bar itself,
|
2013-10-07 13:34:40 +02:00
|
|
|
using the FutureProgress object returned by the addTask() function.
|
2009-12-21 17:11:47 +01:00
|
|
|
Also use this object to get notified when the user clicks on the
|
|
|
|
|
progress indicator.
|
2009-12-02 15:05:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\enum Core::ProgressManager::ProgressFlag
|
|
|
|
|
Additional flags that specify details in behavior. The
|
|
|
|
|
default for a task is to not have any of these flags set.
|
|
|
|
|
\value KeepOnFinish
|
|
|
|
|
The progress indicator stays visible after the task has finished.
|
|
|
|
|
\value ShowInApplicationIcon
|
|
|
|
|
The progress indicator for this task is additionally
|
|
|
|
|
shown in the application icon in the system's task bar or dock, on
|
|
|
|
|
platforms that support that (at the moment Windows 7 and Mac OS X).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn Core::ProgressManager::ProgressManager(QObject *parent = 0)
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn Core::ProgressManager::~ProgressManager()
|
|
|
|
|
\internal
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn FutureProgress *Core::ProgressManager::addTask(const QFuture<void> &future, const QString &title, const QString &type, ProgressFlags flags = 0)
|
|
|
|
|
|
2009-12-21 17:11:47 +01:00
|
|
|
Shows a progress indicator for task given by the QFuture object \a future.
|
2009-12-02 15:05:49 +01:00
|
|
|
The progress indicator shows the specified \a title along with the progress bar.
|
|
|
|
|
The \a type of a task will specify a logical grouping with other
|
|
|
|
|
running tasks. Via the \a flags parameter you can e.g. let the
|
|
|
|
|
progress indicator stay visible after the task has finished.
|
|
|
|
|
Returns an object that represents the created progress indicator,
|
2009-12-21 17:11:47 +01:00
|
|
|
which can be used to further customize. The FutureProgress object's
|
2011-11-09 11:35:43 +01:00
|
|
|
life is managed by the ProgressManager and is guaranteed to live only until
|
|
|
|
|
the next event loop cycle, or until the next call of addTask.
|
2013-10-07 13:34:40 +02:00
|
|
|
If you want to use the returned FutureProgress later than directly after calling this function,
|
|
|
|
|
you will need to use protective functions (like wrapping the returned object in QPointer and
|
2011-11-09 11:35:43 +01:00
|
|
|
checking for 0 whenever you use it).
|
2009-12-02 15:05:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn void Core::ProgressManager::setApplicationLabel(const QString &text)
|
|
|
|
|
|
|
|
|
|
Shows the given \a text in a platform dependent way in the application
|
|
|
|
|
icon in the system's task bar or dock. This is used
|
|
|
|
|
to show the number of build errors on Windows 7 and Mac OS X.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-03 15:18:37 +02:00
|
|
|
\fn void Core::ProgressManager::cancelTasks(Core::Id type)
|
2009-12-02 15:05:49 +01:00
|
|
|
|
|
|
|
|
Schedules a cancel for all running tasks of the given \a type.
|
|
|
|
|
Please note that the cancel functionality depends on the
|
|
|
|
|
running task to actually check the \c QFutureInterface::isCanceled
|
|
|
|
|
property.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-03 15:18:37 +02:00
|
|
|
\fn void Core::ProgressManager::taskStarted(Core::Id type)
|
2009-12-02 15:05:49 +01:00
|
|
|
|
|
|
|
|
Sent whenever a task of a given \a type is started.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-03 15:18:37 +02:00
|
|
|
\fn void Core::ProgressManager::allTasksFinished(Core::Id type)
|
2009-12-02 15:05:49 +01:00
|
|
|
|
|
|
|
|
Sent when all tasks of a \a type have finished.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
static ProgressManagerPrivate *m_instance = nullptr;
|
2014-05-30 12:57:49 +02:00
|
|
|
|
2013-08-30 15:10:49 +02:00
|
|
|
ProgressManagerPrivate::ProgressManagerPrivate()
|
2018-07-21 21:11:46 +02:00
|
|
|
: m_opacityEffect(new QGraphicsOpacityEffect(this))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-02-21 17:11:16 +01:00
|
|
|
m_opacityEffect->setOpacity(.999);
|
2014-05-30 12:57:49 +02:00
|
|
|
m_instance = this;
|
2008-12-02 12:01:29 +01:00
|
|
|
m_progressView = new ProgressView;
|
2013-03-22 14:14:21 +01:00
|
|
|
// withDelay, so the statusBarWidget has the chance to get the enter event
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(m_progressView.data(), &ProgressView::hoveredChanged, this, &ProgressManagerPrivate::updateVisibilityWithDelay);
|
|
|
|
|
connect(ICore::instance(), &ICore::coreAboutToClose, this, &ProgressManagerPrivate::cancelAllRunningTasks);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 13:54:45 +01:00
|
|
|
ProgressManagerPrivate::~ProgressManagerPrivate()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-11-21 10:00:54 +02:00
|
|
|
stopFadeOfSummaryProgress();
|
2013-04-09 14:22:28 +02:00
|
|
|
qDeleteAll(m_taskList);
|
|
|
|
|
m_taskList.clear();
|
2018-01-24 17:41:53 +01:00
|
|
|
StatusBarManager::destroyStatusBarWidget(m_statusBarWidget);
|
|
|
|
|
m_statusBarWidget = nullptr;
|
2009-11-30 19:38:02 +01:00
|
|
|
cleanup();
|
2018-07-21 21:11:46 +02:00
|
|
|
m_instance = nullptr;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-05-27 10:38:49 +02:00
|
|
|
void ProgressManagerPrivate::readSettings()
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = ICore::settings();
|
|
|
|
|
settings->beginGroup(QLatin1String(kSettingsGroup));
|
2015-08-12 12:06:43 +02:00
|
|
|
m_progressViewPinned = settings->value(QLatin1String(kDetailsPinned), false).toBool();
|
2013-05-27 10:38:49 +02:00
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 14:14:21 +01:00
|
|
|
void ProgressManagerPrivate::init()
|
|
|
|
|
{
|
2013-05-27 10:38:49 +02:00
|
|
|
readSettings();
|
|
|
|
|
|
2013-03-22 14:14:21 +01:00
|
|
|
m_statusBarWidget = new QWidget;
|
2018-12-10 17:10:17 +01:00
|
|
|
m_statusBarWidget->setObjectName("ProgressInfo"); // used for UI introduction
|
2018-07-21 21:11:46 +02:00
|
|
|
auto layout = new QHBoxLayout(m_statusBarWidget);
|
2013-03-22 14:14:21 +01:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
m_statusBarWidget->setLayout(layout);
|
2013-04-08 15:02:30 +02:00
|
|
|
m_summaryProgressWidget = new QWidget(m_statusBarWidget);
|
|
|
|
|
m_summaryProgressWidget->setVisible(!m_progressViewPinned);
|
|
|
|
|
m_summaryProgressWidget->setGraphicsEffect(m_opacityEffect);
|
|
|
|
|
m_summaryProgressLayout = new QHBoxLayout(m_summaryProgressWidget);
|
2016-03-15 13:23:18 +01:00
|
|
|
m_summaryProgressLayout->setContentsMargins(0, 0, 0, 2);
|
2013-04-08 15:02:30 +02:00
|
|
|
m_summaryProgressLayout->setSpacing(0);
|
|
|
|
|
m_summaryProgressWidget->setLayout(m_summaryProgressLayout);
|
|
|
|
|
m_summaryProgressBar = new ProgressBar(m_summaryProgressWidget);
|
2013-03-22 14:14:21 +01:00
|
|
|
m_summaryProgressBar->setMinimumWidth(70);
|
|
|
|
|
m_summaryProgressBar->setTitleVisible(false);
|
|
|
|
|
m_summaryProgressBar->setSeparatorVisible(false);
|
|
|
|
|
m_summaryProgressBar->setCancelEnabled(false);
|
2013-04-08 15:02:30 +02:00
|
|
|
m_summaryProgressLayout->addWidget(m_summaryProgressBar);
|
|
|
|
|
layout->addWidget(m_summaryProgressWidget);
|
2019-04-09 17:10:22 +02:00
|
|
|
auto toggleButton = new QToolButton(m_statusBarWidget);
|
2013-03-22 14:14:21 +01:00
|
|
|
layout->addWidget(toggleButton);
|
|
|
|
|
m_statusBarWidget->installEventFilter(this);
|
2018-01-24 17:41:53 +01:00
|
|
|
StatusBarManager::addStatusBarWidget(m_statusBarWidget, StatusBarManager::RightCorner);
|
2013-03-22 14:14:21 +01:00
|
|
|
|
2013-05-14 16:13:29 +02:00
|
|
|
QAction *toggleProgressView = new QAction(tr("Toggle Progress Details"), this);
|
2013-03-22 14:14:21 +01:00
|
|
|
toggleProgressView->setCheckable(true);
|
|
|
|
|
toggleProgressView->setChecked(m_progressViewPinned);
|
2019-04-09 17:10:22 +02:00
|
|
|
toggleProgressView->setIcon(Utils::Icons::TOGGLE_PROGRESSDETAILS_TOOLBAR.icon());
|
2013-03-22 14:14:21 +01:00
|
|
|
Command *cmd = ActionManager::registerAction(toggleProgressView,
|
2015-02-19 11:35:47 +01:00
|
|
|
"QtCreator.ToggleProgressDetails");
|
2017-04-19 11:58:48 +02:00
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(toggleProgressView, &QAction::toggled,
|
|
|
|
|
this, &ProgressManagerPrivate::progressDetailsToggled);
|
2013-03-22 14:14:21 +01:00
|
|
|
toggleButton->setDefaultAction(cmd->action());
|
2018-01-03 13:47:32 +01:00
|
|
|
m_progressView->setReferenceWidget(toggleButton);
|
2013-03-22 14:14:21 +01:00
|
|
|
|
2016-07-26 18:17:11 +02:00
|
|
|
updateVisibility();
|
2013-03-22 14:14:21 +01:00
|
|
|
|
|
|
|
|
initInternal();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 15:18:37 +02:00
|
|
|
void ProgressManagerPrivate::doCancelTasks(Id type)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-04 16:07:42 +01:00
|
|
|
bool found = false;
|
2013-09-03 15:18:37 +02:00
|
|
|
QMap<QFutureWatcher<void> *, Id>::iterator task = m_runningTasks.begin();
|
2008-12-02 12:01:29 +01:00
|
|
|
while (task != m_runningTasks.end()) {
|
|
|
|
|
if (task.value() != type) {
|
|
|
|
|
++task;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-11-04 16:07:42 +01:00
|
|
|
found = true;
|
2016-02-02 09:10:54 +02:00
|
|
|
disconnect(task.key(), &QFutureWatcherBase::finished, this, &ProgressManagerPrivate::taskFinished);
|
2009-11-26 15:51:10 +01:00
|
|
|
if (m_applicationTask == task.key())
|
|
|
|
|
disconnectApplicationTask();
|
2008-12-02 12:01:29 +01:00
|
|
|
task.key()->cancel();
|
|
|
|
|
delete task.key();
|
|
|
|
|
task = m_runningTasks.erase(task);
|
|
|
|
|
}
|
2013-03-22 14:14:21 +01:00
|
|
|
if (found) {
|
|
|
|
|
updateSummaryProgressBar();
|
2009-11-04 16:07:42 +01:00
|
|
|
emit allTasksFinished(type);
|
2013-03-22 14:14:21 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProgressManagerPrivate::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (obj == m_statusBarWidget && event->type() == QEvent::Enter) {
|
|
|
|
|
m_hovered = true;
|
|
|
|
|
updateVisibility();
|
|
|
|
|
} else if (obj == m_statusBarWidget && event->type() == QEvent::Leave) {
|
|
|
|
|
m_hovered = false;
|
|
|
|
|
// give the progress view the chance to get the mouse enter event
|
|
|
|
|
updateVisibilityWithDelay();
|
2013-07-08 13:45:05 +02:00
|
|
|
} else if (obj == m_statusBarWidget && event->type() == QEvent::MouseButtonPress
|
|
|
|
|
&& !m_taskList.isEmpty()) {
|
2018-07-21 21:11:46 +02:00
|
|
|
auto me = static_cast<QMouseEvent *>(event);
|
2013-07-08 13:45:05 +02:00
|
|
|
if (me->button() == Qt::LeftButton && !me->modifiers()) {
|
|
|
|
|
FutureProgress *progress = m_currentStatusDetailsProgress;
|
|
|
|
|
if (!progress)
|
|
|
|
|
progress = m_taskList.last();
|
|
|
|
|
// don't send signal directly from an event filter, event filters should
|
|
|
|
|
// do as little a possible
|
2016-02-02 09:10:54 +02:00
|
|
|
QTimer::singleShot(0, progress, &FutureProgress::clicked);
|
2013-07-08 13:45:05 +02:00
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-03-22 14:14:21 +01:00
|
|
|
}
|
|
|
|
|
return false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 13:54:45 +01:00
|
|
|
void ProgressManagerPrivate::cancelAllRunningTasks()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-09-03 15:18:37 +02:00
|
|
|
QMap<QFutureWatcher<void> *, Id>::const_iterator task = m_runningTasks.constBegin();
|
2008-12-02 12:01:29 +01:00
|
|
|
while (task != m_runningTasks.constEnd()) {
|
2016-02-02 09:10:54 +02:00
|
|
|
disconnect(task.key(), &QFutureWatcherBase::finished, this, &ProgressManagerPrivate::taskFinished);
|
2009-11-26 15:51:10 +01:00
|
|
|
if (m_applicationTask == task.key())
|
|
|
|
|
disconnectApplicationTask();
|
2008-12-02 12:01:29 +01:00
|
|
|
task.key()->cancel();
|
|
|
|
|
delete task.key();
|
|
|
|
|
++task;
|
|
|
|
|
}
|
|
|
|
|
m_runningTasks.clear();
|
2013-03-22 14:14:21 +01:00
|
|
|
updateSummaryProgressBar();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
FutureProgress *ProgressManagerPrivate::doAddTask(const QFuture<void> &future, const QString &title,
|
2013-09-03 15:18:37 +02:00
|
|
|
Id type, ProgressFlags flags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-04-09 14:22:28 +02:00
|
|
|
// watch
|
2018-07-21 21:11:46 +02:00
|
|
|
auto watcher = new QFutureWatcher<void>();
|
2008-12-02 12:01:29 +01:00
|
|
|
m_runningTasks.insert(watcher, type);
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(watcher, &QFutureWatcherBase::progressRangeChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::updateSummaryProgressBar);
|
|
|
|
|
connect(watcher, &QFutureWatcherBase::progressValueChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::updateSummaryProgressBar);
|
|
|
|
|
connect(watcher, &QFutureWatcherBase::finished, this, &ProgressManagerPrivate::taskFinished);
|
2013-04-09 14:22:28 +02:00
|
|
|
watcher->setFuture(future);
|
|
|
|
|
|
|
|
|
|
// handle application task
|
2009-11-26 15:51:10 +01:00
|
|
|
if (flags & ShowInApplicationIcon) {
|
2011-01-04 16:15:15 +01:00
|
|
|
if (m_applicationTask)
|
|
|
|
|
disconnectApplicationTask();
|
2009-11-26 15:51:10 +01:00
|
|
|
m_applicationTask = watcher;
|
2011-01-04 16:15:15 +01:00
|
|
|
setApplicationProgressRange(future.progressMinimum(), future.progressMaximum());
|
|
|
|
|
setApplicationProgressValue(future.progressValue());
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(m_applicationTask, &QFutureWatcherBase::progressRangeChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::setApplicationProgressRange);
|
|
|
|
|
connect(m_applicationTask, &QFutureWatcherBase::progressValueChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::setApplicationProgressValue);
|
2009-11-26 15:51:10 +01:00
|
|
|
setApplicationProgressVisible(true);
|
|
|
|
|
}
|
2013-04-09 14:22:28 +02:00
|
|
|
|
|
|
|
|
// create FutureProgress and manage task list
|
|
|
|
|
removeOldTasks(type);
|
|
|
|
|
if (m_taskList.size() == 10)
|
|
|
|
|
removeOneOldTask();
|
2018-07-21 21:11:46 +02:00
|
|
|
auto progress = new FutureProgress;
|
2013-04-09 14:22:28 +02:00
|
|
|
progress->setTitle(title);
|
|
|
|
|
progress->setFuture(future);
|
|
|
|
|
|
|
|
|
|
m_progressView->addProgressWidget(progress);
|
|
|
|
|
m_taskList.append(progress);
|
|
|
|
|
progress->setType(type);
|
|
|
|
|
if (flags.testFlag(ProgressManager::KeepOnFinish))
|
|
|
|
|
progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
|
|
|
|
|
else
|
|
|
|
|
progress->setKeepOnFinish(FutureProgress::HideOnFinish);
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(progress, &FutureProgress::hasErrorChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::updateSummaryProgressBar);
|
|
|
|
|
connect(progress, &FutureProgress::removeMe, this, &ProgressManagerPrivate::slotRemoveTask);
|
|
|
|
|
connect(progress, &FutureProgress::fadeStarted,
|
|
|
|
|
this, &ProgressManagerPrivate::updateSummaryProgressBar);
|
|
|
|
|
connect(progress, &FutureProgress::statusBarWidgetChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::updateStatusDetailsWidget);
|
2019-03-27 16:48:28 +01:00
|
|
|
connect(progress, &FutureProgress::subtitleInStatusBarChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::updateStatusDetailsWidget);
|
2013-04-08 15:02:30 +02:00
|
|
|
updateStatusDetailsWidget();
|
2013-04-09 14:22:28 +02:00
|
|
|
|
2009-11-04 16:07:42 +01:00
|
|
|
emit taskStarted(type);
|
2013-04-09 14:22:28 +02:00
|
|
|
return progress;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 14:14:21 +01:00
|
|
|
ProgressView *ProgressManagerPrivate::progressView()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
return m_progressView;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 13:54:45 +01:00
|
|
|
void ProgressManagerPrivate::taskFinished()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
QObject *taskObject = sender();
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(taskObject, return);
|
2018-07-21 21:11:46 +02:00
|
|
|
auto task = static_cast<QFutureWatcher<void> *>(taskObject);
|
2009-11-26 15:51:10 +01:00
|
|
|
if (m_applicationTask == task)
|
|
|
|
|
disconnectApplicationTask();
|
2013-09-03 15:18:37 +02:00
|
|
|
Id type = m_runningTasks.value(task);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_runningTasks.remove(task);
|
|
|
|
|
delete task;
|
2013-03-22 14:14:21 +01:00
|
|
|
updateSummaryProgressBar();
|
2009-11-04 16:07:42 +01:00
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!m_runningTasks.key(type, 0))
|
2009-11-04 16:07:42 +01:00
|
|
|
emit allTasksFinished(type);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-11-26 15:51:10 +01:00
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::disconnectApplicationTask()
|
|
|
|
|
{
|
2016-02-02 09:10:54 +02:00
|
|
|
disconnect(m_applicationTask, &QFutureWatcherBase::progressRangeChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::setApplicationProgressRange);
|
|
|
|
|
disconnect(m_applicationTask, &QFutureWatcherBase::progressValueChanged,
|
|
|
|
|
this, &ProgressManagerPrivate::setApplicationProgressValue);
|
2009-11-26 15:51:10 +01:00
|
|
|
setApplicationProgressVisible(false);
|
2018-07-21 21:11:46 +02:00
|
|
|
m_applicationTask = nullptr;
|
2009-11-26 15:51:10 +01:00
|
|
|
}
|
2013-03-22 14:14:21 +01:00
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::updateSummaryProgressBar()
|
|
|
|
|
{
|
2013-04-09 14:22:28 +02:00
|
|
|
m_summaryProgressBar->setError(hasError());
|
2013-03-22 14:14:21 +01:00
|
|
|
updateVisibility();
|
|
|
|
|
if (m_runningTasks.isEmpty()) {
|
|
|
|
|
m_summaryProgressBar->setFinished(true);
|
2013-04-09 14:22:28 +02:00
|
|
|
if (m_taskList.isEmpty() || isLastFading())
|
|
|
|
|
fadeAwaySummaryProgress();
|
2013-03-22 14:14:21 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 14:22:28 +02:00
|
|
|
stopFadeOfSummaryProgress();
|
2013-03-22 14:14:21 +01:00
|
|
|
|
|
|
|
|
m_summaryProgressBar->setFinished(false);
|
2013-09-03 15:18:37 +02:00
|
|
|
QMapIterator<QFutureWatcher<void> *, Id> it(m_runningTasks);
|
2013-05-24 14:14:35 +02:00
|
|
|
static const int TASK_RANGE = 100;
|
2013-03-22 14:14:21 +01:00
|
|
|
int value = 0;
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
QFutureWatcher<void> *watcher = it.key();
|
|
|
|
|
int min = watcher->progressMinimum();
|
2013-05-24 14:14:35 +02:00
|
|
|
int range = watcher->progressMaximum() - min;
|
|
|
|
|
if (range > 0)
|
|
|
|
|
value += TASK_RANGE * (watcher->progressValue() - min) / range;
|
2013-03-22 14:14:21 +01:00
|
|
|
}
|
2013-05-24 14:14:35 +02:00
|
|
|
m_summaryProgressBar->setRange(0, TASK_RANGE * m_runningTasks.size());
|
2013-03-22 14:14:21 +01:00
|
|
|
m_summaryProgressBar->setValue(value);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 14:22:28 +02:00
|
|
|
void ProgressManagerPrivate::fadeAwaySummaryProgress()
|
2013-03-22 14:14:21 +01:00
|
|
|
{
|
2013-04-09 14:22:28 +02:00
|
|
|
stopFadeOfSummaryProgress();
|
2013-03-22 14:14:21 +01:00
|
|
|
m_opacityAnimation = new QPropertyAnimation(m_opacityEffect, "opacity");
|
2015-02-03 23:48:19 +02:00
|
|
|
m_opacityAnimation->setDuration(StyleHelper::progressFadeAnimationDuration);
|
2013-03-22 14:14:21 +01:00
|
|
|
m_opacityAnimation->setEndValue(0.);
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(m_opacityAnimation.data(), &QAbstractAnimation::finished, this, &ProgressManagerPrivate::summaryProgressFinishedFading);
|
2013-03-22 14:14:21 +01:00
|
|
|
m_opacityAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 14:22:28 +02:00
|
|
|
void ProgressManagerPrivate::stopFadeOfSummaryProgress()
|
2013-03-22 14:14:21 +01:00
|
|
|
{
|
|
|
|
|
if (m_opacityAnimation) {
|
|
|
|
|
m_opacityAnimation->stop();
|
2018-02-21 17:11:16 +01:00
|
|
|
m_opacityEffect->setOpacity(.999);
|
2013-03-22 14:14:21 +01:00
|
|
|
delete m_opacityAnimation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 14:22:28 +02:00
|
|
|
bool ProgressManagerPrivate::hasError() const
|
|
|
|
|
{
|
|
|
|
|
foreach (FutureProgress *progress, m_taskList)
|
|
|
|
|
if (progress->hasError())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProgressManagerPrivate::isLastFading() const
|
|
|
|
|
{
|
|
|
|
|
if (m_taskList.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
foreach (FutureProgress *progress, m_taskList) {
|
|
|
|
|
if (!progress->isFading()) // we still have progress bars that are not fading
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::slotRemoveTask()
|
|
|
|
|
{
|
2018-07-21 21:11:46 +02:00
|
|
|
auto progress = qobject_cast<FutureProgress *>(sender());
|
2013-04-09 14:22:28 +02:00
|
|
|
QTC_ASSERT(progress, return);
|
2013-09-03 15:18:37 +02:00
|
|
|
Id type = progress->type();
|
2013-04-09 14:22:28 +02:00
|
|
|
removeTask(progress);
|
|
|
|
|
removeOldTasks(type, true);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 15:18:37 +02:00
|
|
|
void ProgressManagerPrivate::removeOldTasks(const Id type, bool keepOne)
|
2013-04-09 14:22:28 +02:00
|
|
|
{
|
|
|
|
|
bool firstFound = !keepOne; // start with false if we want to keep one
|
|
|
|
|
QList<FutureProgress *>::iterator i = m_taskList.end();
|
|
|
|
|
while (i != m_taskList.begin()) {
|
|
|
|
|
--i;
|
|
|
|
|
if ((*i)->type() == type) {
|
|
|
|
|
if (firstFound && ((*i)->future().isFinished() || (*i)->future().isCanceled())) {
|
|
|
|
|
deleteTask(*i);
|
|
|
|
|
i = m_taskList.erase(i);
|
|
|
|
|
}
|
|
|
|
|
firstFound = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-08 15:02:30 +02:00
|
|
|
updateSummaryProgressBar();
|
|
|
|
|
updateStatusDetailsWidget();
|
2013-04-09 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::removeOneOldTask()
|
|
|
|
|
{
|
|
|
|
|
if (m_taskList.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
// look for oldest ended process
|
|
|
|
|
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
|
|
|
|
|
if ((*i)->future().isFinished()) {
|
|
|
|
|
deleteTask(*i);
|
|
|
|
|
i = m_taskList.erase(i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// no ended process, look for a task type with multiple running tasks and remove the oldest one
|
|
|
|
|
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
|
2013-09-03 15:18:37 +02:00
|
|
|
Id type = (*i)->type();
|
2013-04-09 14:22:28 +02:00
|
|
|
|
|
|
|
|
int taskCount = 0;
|
|
|
|
|
foreach (FutureProgress *p, m_taskList)
|
|
|
|
|
if (p->type() == type)
|
|
|
|
|
++taskCount;
|
|
|
|
|
|
|
|
|
|
if (taskCount > 1) { // don't care for optimizations it's only a handful of entries
|
|
|
|
|
deleteTask(*i);
|
|
|
|
|
i = m_taskList.erase(i);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// no ended process, no type with multiple processes, just remove the oldest task
|
|
|
|
|
FutureProgress *task = m_taskList.takeFirst();
|
|
|
|
|
deleteTask(task);
|
2013-04-08 15:02:30 +02:00
|
|
|
updateSummaryProgressBar();
|
|
|
|
|
updateStatusDetailsWidget();
|
2013-04-09 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::removeTask(FutureProgress *task)
|
|
|
|
|
{
|
|
|
|
|
m_taskList.removeAll(task);
|
|
|
|
|
deleteTask(task);
|
2013-04-08 15:02:30 +02:00
|
|
|
updateSummaryProgressBar();
|
|
|
|
|
updateStatusDetailsWidget();
|
2013-04-09 14:22:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::deleteTask(FutureProgress *progress)
|
|
|
|
|
{
|
|
|
|
|
m_progressView->removeProgressWidget(progress);
|
|
|
|
|
progress->hide();
|
|
|
|
|
progress->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 14:14:21 +01:00
|
|
|
void ProgressManagerPrivate::updateVisibility()
|
|
|
|
|
{
|
|
|
|
|
m_progressView->setVisible(m_progressViewPinned || m_hovered || m_progressView->isHovered());
|
2013-04-08 15:02:30 +02:00
|
|
|
m_summaryProgressWidget->setVisible((!m_runningTasks.isEmpty() || !m_taskList.isEmpty())
|
2013-03-22 14:14:21 +01:00
|
|
|
&& !m_progressViewPinned);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::updateVisibilityWithDelay()
|
|
|
|
|
{
|
2016-02-02 09:10:54 +02:00
|
|
|
QTimer::singleShot(150, this, &ProgressManagerPrivate::updateVisibility);
|
2013-03-22 14:14:21 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 15:02:30 +02:00
|
|
|
void ProgressManagerPrivate::updateStatusDetailsWidget()
|
|
|
|
|
{
|
2018-07-21 21:11:46 +02:00
|
|
|
QWidget *candidateWidget = nullptr;
|
2013-04-08 15:02:30 +02:00
|
|
|
// get newest progress with a status bar widget
|
|
|
|
|
QList<FutureProgress *>::iterator i = m_taskList.end();
|
|
|
|
|
while (i != m_taskList.begin()) {
|
|
|
|
|
--i;
|
2019-03-27 16:48:28 +01:00
|
|
|
FutureProgress *progress = *i;
|
|
|
|
|
candidateWidget = progress->statusBarWidget();
|
2013-07-08 13:45:05 +02:00
|
|
|
if (candidateWidget) {
|
2019-03-27 16:48:28 +01:00
|
|
|
m_currentStatusDetailsProgress = progress;
|
|
|
|
|
break;
|
|
|
|
|
} else if (progress->isSubtitleVisibleInStatusBar() && !progress->subtitle().isEmpty()) {
|
|
|
|
|
if (!m_statusDetailsLabel) {
|
|
|
|
|
m_statusDetailsLabel = new QLabel(m_summaryProgressWidget);
|
|
|
|
|
QFont font(m_statusDetailsLabel->font());
|
|
|
|
|
font.setPointSizeF(StyleHelper::sidebarFontSize());
|
|
|
|
|
font.setBold(true);
|
|
|
|
|
m_statusDetailsLabel->setFont(font);
|
|
|
|
|
}
|
|
|
|
|
m_statusDetailsLabel->setText(progress->subtitle());
|
|
|
|
|
candidateWidget = m_statusDetailsLabel;
|
|
|
|
|
m_currentStatusDetailsProgress = progress;
|
2013-04-08 15:02:30 +02:00
|
|
|
break;
|
2013-07-08 13:45:05 +02:00
|
|
|
}
|
2013-04-08 15:02:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (candidateWidget == m_currentStatusDetailsWidget)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_currentStatusDetailsWidget) {
|
|
|
|
|
m_currentStatusDetailsWidget->hide();
|
|
|
|
|
m_summaryProgressLayout->removeWidget(m_currentStatusDetailsWidget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (candidateWidget) {
|
|
|
|
|
m_summaryProgressLayout->insertWidget(0, candidateWidget);
|
|
|
|
|
candidateWidget->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_currentStatusDetailsWidget = candidateWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 14:22:28 +02:00
|
|
|
void ProgressManagerPrivate::summaryProgressFinishedFading()
|
2013-03-22 14:14:21 +01:00
|
|
|
{
|
2013-04-08 15:02:30 +02:00
|
|
|
m_summaryProgressWidget->setVisible(false);
|
2018-02-21 17:11:16 +01:00
|
|
|
m_opacityEffect->setOpacity(.999);
|
2013-03-22 14:14:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressManagerPrivate::progressDetailsToggled(bool checked)
|
|
|
|
|
{
|
|
|
|
|
m_progressViewPinned = checked;
|
|
|
|
|
updateVisibility();
|
2013-05-27 10:38:49 +02:00
|
|
|
|
|
|
|
|
QSettings *settings = ICore::settings();
|
|
|
|
|
settings->beginGroup(QLatin1String(kSettingsGroup));
|
|
|
|
|
settings->setValue(QLatin1String(kDetailsPinned), m_progressViewPinned);
|
|
|
|
|
settings->endGroup();
|
2013-03-22 14:14:21 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
ProgressManager::ProgressManager() = default;
|
2013-08-30 09:22:42 +02:00
|
|
|
|
2018-07-21 21:11:46 +02:00
|
|
|
ProgressManager::~ProgressManager() = default;
|
2013-08-30 09:22:42 +02:00
|
|
|
|
2015-02-16 15:49:05 +01:00
|
|
|
ProgressManager *ProgressManager::instance()
|
2013-08-30 09:22:42 +02:00
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-03 15:18:37 +02:00
|
|
|
FutureProgress *ProgressManager::addTask(const QFuture<void> &future, const QString &title, Id type, ProgressFlags flags)
|
2013-08-30 09:22:42 +02:00
|
|
|
{
|
|
|
|
|
return m_instance->doAddTask(future, title, type, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 14:23:37 +02:00
|
|
|
/*!
|
|
|
|
|
Shows a progress indicator for task given by the QFuture given by
|
|
|
|
|
the QFutureInterface \a futureInterface.
|
|
|
|
|
The progress indicator shows the specified \a title along with the progress bar.
|
|
|
|
|
The progress indicator will increase monotonically with time, at \a expectedSeconds
|
|
|
|
|
it will reach about 80%, and continue to increase with a decreasingly slower rate.
|
|
|
|
|
|
|
|
|
|
\sa addTask
|
|
|
|
|
*/
|
|
|
|
|
|
2014-05-30 14:25:58 +02:00
|
|
|
FutureProgress *ProgressManager::addTimedTask(const QFutureInterface<void> &futureInterface, const QString &title,
|
2014-05-05 14:23:37 +02:00
|
|
|
Id type, int expectedSeconds, ProgressFlags flags)
|
|
|
|
|
{
|
2014-05-30 14:25:58 +02:00
|
|
|
QFutureInterface<void> dummy(futureInterface); // Need mutable to access .future()
|
|
|
|
|
FutureProgress *fp = m_instance->doAddTask(dummy.future(), title, type, flags);
|
2016-02-09 11:02:17 +02:00
|
|
|
(void) new ProgressTimer(futureInterface, expectedSeconds, fp);
|
2014-05-05 14:23:37 +02:00
|
|
|
return fp;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
void ProgressManager::setApplicationLabel(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
m_instance->doSetApplicationLabel(text);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
void ProgressManager::cancelTasks(Id type)
|
2013-08-30 09:22:42 +02:00
|
|
|
{
|
2013-09-03 15:18:37 +02:00
|
|
|
if (m_instance)
|
|
|
|
|
m_instance->doCancelTasks(type);
|
2013-08-30 09:22:42 +02:00
|
|
|
}
|
2014-05-05 14:23:37 +02:00
|
|
|
|
|
|
|
|
|
2016-02-09 11:02:17 +02:00
|
|
|
ProgressTimer::ProgressTimer(const QFutureInterfaceBase &futureInterface,
|
|
|
|
|
int expectedSeconds,
|
|
|
|
|
QObject *parent)
|
2016-02-06 21:57:14 +02:00
|
|
|
: QObject(parent),
|
2014-05-05 14:23:37 +02:00
|
|
|
m_futureInterface(futureInterface),
|
2018-07-21 21:11:46 +02:00
|
|
|
m_expectedTime(expectedSeconds)
|
2014-05-05 14:23:37 +02:00
|
|
|
{
|
2014-05-30 14:25:58 +02:00
|
|
|
m_futureInterface.setProgressRange(0, 100);
|
|
|
|
|
m_futureInterface.setProgressValue(0);
|
2014-05-05 14:23:37 +02:00
|
|
|
|
2016-02-06 21:57:14 +02:00
|
|
|
m_timer = new QTimer(this);
|
2016-02-17 23:12:10 +02:00
|
|
|
m_timer->setInterval(TimerInterval);
|
2016-02-06 21:57:14 +02:00
|
|
|
connect(m_timer, &QTimer::timeout, this, &ProgressTimer::handleTimeout);
|
|
|
|
|
m_timer->start();
|
2014-05-05 14:23:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressTimer::handleTimeout()
|
|
|
|
|
{
|
|
|
|
|
++m_currentTime;
|
|
|
|
|
|
|
|
|
|
// This maps expectation to atan(1) to Pi/4 ~= 0.78, i.e. snaps
|
|
|
|
|
// from 78% to 100% when expectations are met at the time the
|
|
|
|
|
// future finishes. That's not bad for a random choice.
|
2016-02-17 23:12:10 +02:00
|
|
|
const double mapped = atan2(double(m_currentTime) * TimerInterval / 1000.0,
|
|
|
|
|
double(m_expectedTime));
|
2014-05-05 14:23:37 +02:00
|
|
|
const double progress = 100 * 2 * mapped / 3.14;
|
2014-05-30 14:25:58 +02:00
|
|
|
m_futureInterface.setProgressValue(int(progress));
|
2014-05-05 14:23:37 +02:00
|
|
|
}
|
|
|
|
|
|