ui: Indexing UI

* Added DialogView with QtDialogView implementation to handle information dialogs
* Implemented QtIndexingDialog class that covers all different dialogs for indexing
* Directly communicate with DialogView from Prpject and all Tasks involved in indexing
* Block QtMainWindow UI while indexing
This commit is contained in:
Eberhard Graether
2016-08-23 23:45:45 +02:00
parent 377f0ef34f
commit 2c90b75a9f
70 changed files with 1565 additions and 375 deletions
+397
View File
@@ -0,0 +1,397 @@
#include "qt/window/QtIndexingDialog.h"
#include <QLabel>
#include <QTimer>
#include <QPainter>
#include <QPushButton>
#include "qt/utility/utilityQt.h"
#include "qt/element/QtProgressBar.h"
#include "utility/messaging/type/MessageInterruptTasks.h"
#include "utility/ResourcePaths.h"
#include "utility/utility.h"
QtIndexingDialog::QtIndexingDialog(QWidget* parent)
: QtWindow(parent)
, m_type(DIALOG_MESSAGE)
, m_top(nullptr)
, m_topRatio(0)
, m_progressBar(nullptr)
, m_percentLabel(nullptr)
, m_messageLabel(nullptr)
, m_filePathLabel(nullptr)
, m_errorLabel(nullptr)
, m_sizeHint(QSize(450, 450))
, m_callback([](bool){})
{
// setWindowFlags(Qt::WindowStaysOnTopHint);
}
QSize QtIndexingDialog::sizeHint() const
{
return m_sizeHint;
}
QtIndexingDialog::DialogType QtIndexingDialog::getType() const
{
return m_type;
}
void QtIndexingDialog::setupStart(size_t cleanFileCount, size_t indexFileCount, std::function<void(bool)> callback)
{
QBoxLayout* layout = createLayout();
addTitle("Start Indexing", layout);
layout->addSpacing(5);
if (cleanFileCount)
{
QLabel* cleanLabel = new QLabel("Clear: " + QString::number(cleanFileCount) + " File" + (cleanFileCount > 1 ? "s" : ""));
cleanLabel->setObjectName("message");
cleanLabel->setAlignment(Qt::AlignRight);
layout->addWidget(cleanLabel, 0, Qt::AlignRight);
}
addMessageLabel(layout);
updateMessage("Index: " + QString::number(indexFileCount) + " File" + (indexFileCount > 1 ? "s" : ""));
layout->addStretch();
addButtons(layout);
updateNextButton("Start");
updateCloseButton("Cancel");
m_sizeHint = QSize(350, 250);
m_callback = callback;
finishSetup();
}
void QtIndexingDialog::setupProgress()
{
setType(DIALOG_PROGRESS);
QBoxLayout* layout = createLayout();
addTopAndProgressBar(0.5);
addTitle("Clearing", layout);
addMessageLabel(layout);
layout->addStretch();
m_sizeHint = QSize(350, 350);
m_progressBar->showUnknownProgressAnimated();
setCancelAble(false);
finishSetup();
}
void QtIndexingDialog::setupIndexing()
{
setType(DIALOG_INDEXING);
QBoxLayout* layout = createLayout();
addTopAndProgressBar(0.38);
addTitle("Indexing Files", layout);
addPercentLabel(layout);
addMessageLabel(layout);
addFilePathLabel(layout);
layout->addSpacing(12);
addErrorLabel(layout);
layout->addStretch();
addButtons(layout);
setNextVisible(false);
updateCloseButton("Stop");
m_sizeHint = QSize(350, 350);
finishSetup();
}
void QtIndexingDialog::setupReport(size_t fileCount, size_t totalFileCount, float time)
{
QBoxLayout* layout = createLayout();
addTitle("Finished Indexing", layout);
layout->addSpacing(5);
addMessageLabel(layout);
updateMessage(
QString::number(fileCount) + "/" + QString::number(totalFileCount) + " File" + (totalFileCount > 1 ? "s" : "")
);
QLabel* timeLabel = new QLabel("Total Time: " + QString::fromStdString(utility::timeToString(time)));
timeLabel->setObjectName("message");
timeLabel->setAlignment(Qt::AlignRight);
layout->addWidget(timeLabel, 0, Qt::AlignRight);
layout->addSpacing(12);
addErrorLabel(layout);
layout->addStretch();
addButtons(layout);
updateNextButton("OK");
setCloseVisible(false);
m_sizeHint = QSize(400, 260);
if (fileCount != totalFileCount)
{
updateTitle("Interrupted Indexing");
}
else
{
addFlag();
}
finishSetup();
}
void QtIndexingDialog::updateMessage(QString message)
{
if (m_messageLabel)
{
m_messageLabel->setText(message);
}
}
void QtIndexingDialog::updateIndexingProgress(size_t fileCount, size_t totalFileCount, std::string sourcePath)
{
updateMessage(QString::number(fileCount) + "/" + QString::number(totalFileCount) + " File" + (totalFileCount > 1 ? "s" : ""));
if (fileCount > 0)
{
fileCount--;
}
size_t percent = fileCount * 100 / totalFileCount;
m_progressBar->showProgress(percent);
m_percentLabel->setText(QString::number(percent) + "% Progress");
m_sourcePath = QString::fromStdString(sourcePath);
setGeometries();
}
void QtIndexingDialog::updateErrorCount(size_t errorCount, size_t fatalCount)
{
if (m_errorLabel && errorCount)
{
QString str = QString::number(errorCount) + " Error";
if (errorCount > 1)
{
str += "s";
}
if (fatalCount)
{
str += " (" + QString::number(fatalCount) + " Fatal)";
}
m_errorLabel->setText(str);
m_errorLabel->show();
}
}
void QtIndexingDialog::resizeEvent(QResizeEvent* event)
{
QtWindow::resizeEvent(event);
setGeometries();
}
void QtIndexingDialog::handleNext()
{
if (m_type == DIALOG_MESSAGE)
{
m_callback(true);
}
QtWindow::handleNext();
}
void QtIndexingDialog::handleClose()
{
if (m_type == DIALOG_MESSAGE)
{
m_callback(false);
}
if (m_type == DIALOG_INDEXING)
{
MessageInterruptTasks().dispatch();
return;
}
QtWindow::handleClose();
}
void QtIndexingDialog::setType(DialogType type)
{
m_type = type;
}
QBoxLayout* QtIndexingDialog::createLayout()
{
m_window->setStyleSheet(
m_window->styleSheet() +
"#window { "
"background: #2E3C86;"
"border: none;"
"}"
);
setStyleSheet((
utility::getStyleSheet(ResourcePaths::getGuiPath() + "window/window.css") +
utility::getStyleSheet(ResourcePaths::getGuiPath() + "indexing_dialog/indexing_dialog.css")
).c_str());
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(20, 20, 20, 0);
layout->setSpacing(3);
m_content->setLayout(layout);
return layout;
}
void QtIndexingDialog::addTopAndProgressBar(float topRatio)
{
m_topRatio = topRatio;
m_top = new QWidget(m_window);
m_top->setObjectName("topHalf");
m_top->setGeometry(0, 0, m_window->size().width(), m_window->size().height() * topRatio);
m_top->show();
m_top->lower();
m_progressBar = new QtProgressBar(m_window);
m_progressBar->setGeometry(0, m_window->size().height() * topRatio - 5, m_window->size().width(), 10);
}
void QtIndexingDialog::addTitle(QString title, QBoxLayout* layout)
{
m_title = new QLabel(title, this);
m_title->setObjectName("title");
m_title->setAlignment(Qt::AlignRight | Qt::AlignBottom);
if (m_top)
{
m_title->show();
}
else
{
layout->addWidget(m_title, 0, Qt::AlignRight);
}
}
void QtIndexingDialog::addPercentLabel(QBoxLayout* layout)
{
m_percentLabel = new QLabel("0% Progress");
m_percentLabel->setObjectName("percent");
layout->addWidget(m_percentLabel, 0, Qt::AlignRight);
}
void QtIndexingDialog::addMessageLabel(QBoxLayout* layout)
{
m_messageLabel = new QLabel();
m_messageLabel->setObjectName("message");
m_messageLabel->setAlignment(Qt::AlignRight);
layout->addWidget(m_messageLabel, 0, Qt::AlignRight);
}
void QtIndexingDialog::addFilePathLabel(QBoxLayout* layout)
{
m_filePathLabel = new QLabel();
m_filePathLabel->setObjectName("filePath");
m_filePathLabel->setAlignment(Qt::AlignRight);
layout->addWidget(m_filePathLabel);
}
void QtIndexingDialog::addErrorLabel(QBoxLayout* layout)
{
m_errorLabel = new QPushButton();
m_errorLabel->setObjectName("errorCount");
m_errorLabel->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
std::string text = ResourcePaths::getGuiPath() + "indexing_dialog/error.png";
m_errorLabel->setIcon(QPixmap(text.c_str()));
layout->addWidget(m_errorLabel, 0, Qt::AlignRight);
m_errorLabel->hide();
}
void QtIndexingDialog::addButtons(QBoxLayout* layout)
{
m_nextButton = new QPushButton("Next");
m_nextButton->setObjectName("windowButton");
connect(m_nextButton, SIGNAL(clicked()), this, SLOT(handleNextPress()));
m_closeButton = new QPushButton("Cancel");
m_closeButton->setObjectName("windowButton");
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(handleClosePress()));
QHBoxLayout* buttons = new QHBoxLayout();
buttons->addWidget(m_closeButton);
buttons->addStretch();
buttons->addWidget(m_nextButton);
layout->addLayout(buttons);
setNextDefault(true);
}
void QtIndexingDialog::addFlag()
{
QtDeviceScaledPixmap flag((ResourcePaths::getGuiPath() + "indexing_dialog/flag.png").c_str());
flag.scaleToWidth(120);
QLabel* flagLabel = new QLabel(this);
flagLabel->setPixmap(flag.pixmap());
flagLabel->resize(flag.width(), flag.height());
flagLabel->move(15, 75);
flagLabel->show();
}
void QtIndexingDialog::setGeometries()
{
if (m_top)
{
QMargins margins = m_content->layout()->contentsMargins();
margins.setTop(m_window->size().height() * m_topRatio + 10);
m_content->layout()->setContentsMargins(margins);
m_top->setGeometry(0, 0, m_window->size().width(), m_window->size().height() * m_topRatio);
m_title->setGeometry(
margins.left(),
m_window->size().height() * m_topRatio - 50,
m_window->size().width() - margins.left() - margins.right(),
40
);
}
if (m_progressBar)
{
m_progressBar->setGeometry(0, m_window->size().height() * m_topRatio - 5, m_window->size().width(), 10);
}
if (m_filePathLabel)
{
m_filePathLabel->setText(m_filePathLabel->fontMetrics().elidedText(
m_sourcePath, Qt::ElideLeft, m_filePathLabel->width()));
}
}
void QtIndexingDialog::finishSetup()
{
setGeometries();
setupDone();
}
+77
View File
@@ -0,0 +1,77 @@
#ifndef QT_INDEXING_WIZARD_WINDOW_H
#define QT_INDEXING_WIZARD_WINDOW_H
#include "qt/window/QtWindow.h"
class QLabel;
class QtProgressBar;
class QtIndexingDialog
: public QtWindow
{
Q_OBJECT
public:
enum DialogType
{
DIALOG_MESSAGE,
DIALOG_PROGRESS,
DIALOG_INDEXING
};
QtIndexingDialog(QWidget* parent = 0);
QSize sizeHint() const override;
DialogType getType() const;
void setupStart(size_t cleanFileCount, size_t indexFileCount, std::function<void(bool)> callback);
void setupProgress();
void setupIndexing();
void setupReport(size_t fileCount, size_t totalFileCount, float time);
void updateMessage(QString message);
void updateIndexingProgress(size_t fileCount, size_t totalFileCount, std::string sourcePath);
void updateErrorCount(size_t errorCount, size_t fatalCount);
protected:
void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
virtual void handleNext() override;
virtual void handleClose() override;
private:
void setType(DialogType type);
QBoxLayout* createLayout();
void addTopAndProgressBar(float topRatio);
void addTitle(QString title, QBoxLayout* layout);
void addPercentLabel(QBoxLayout* layout);
void addMessageLabel(QBoxLayout* layout);
void addFilePathLabel(QBoxLayout* layout);
void addErrorLabel(QBoxLayout* layout);
void addButtons(QBoxLayout* layout);
void addFlag();
void setGeometries();
void finishSetup();
DialogType m_type;
QWidget* m_top;
float m_topRatio;
QtProgressBar* m_progressBar;
QLabel* m_percentLabel;
QLabel* m_messageLabel;
QLabel* m_filePathLabel;
QPushButton* m_errorLabel;
QSize m_sizeHint;
std::function<void(bool)> m_callback;
QString m_sourcePath;
};
#endif // QT_INDEXING_WIZARD_WINDOW_H
+34 -34
View File
@@ -287,7 +287,7 @@ void QtMainWindow::forceEnterLicense(bool expired)
bool QtMainWindow::event(QEvent* event)
{
if (event->type() == QEvent::WindowActivate)
if (isEnabled() && event->type() == QEvent::WindowActivate)
{
MessageWindowFocus().dispatch();
}
@@ -499,6 +499,34 @@ void QtMainWindow::resetZoom()
MessageResetZoom().dispatch();
}
void QtMainWindow::openRecentProject()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
{
openProject(action->data().toString());
}
}
void QtMainWindow::updateRecentProjectMenu()
{
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
for (int i = 0; i < ApplicationSettings::getInstance()->getMaxRecentProjectsCount(); i++)
{
if ((size_t)i < recentProjects.size() && recentProjects[i].exists())
{
FilePath project = recentProjects[i];
m_recentProjectAction[i]->setVisible(true);
m_recentProjectAction[i]->setText(FileSystem::fileName(project.str()).c_str());
m_recentProjectAction[i]->setData(project.str().c_str());
}
else
{
m_recentProjectAction[i]->setVisible(false);
}
}
}
void QtMainWindow::toggleView(View* view, bool fromMenu)
{
DockWidget* dock = getDockWidgetForView(view);
@@ -513,6 +541,11 @@ void QtMainWindow::toggleView(View* view, bool fromMenu)
}
}
void QtMainWindow::toggleShowDockWidgetTitleBars()
{
setShowDockWidgetTitleBars(!m_showDockWidgetTitleBars);
}
void QtMainWindow::setupProjectMenu()
{
QMenu *menu = new QMenu(tr("&Project"), this);
@@ -551,39 +584,6 @@ void QtMainWindow::setupProjectMenu()
menu->addAction(tr("E&xit"), QCoreApplication::instance(), SLOT(quit()), QKeySequence::Quit);
}
void QtMainWindow::openRecentProject()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
{
openProject(action->data().toString());
}
}
void QtMainWindow::updateRecentProjectMenu()
{
std::vector<FilePath> recentProjects = ApplicationSettings::getInstance()->getRecentProjects();
for (int i = 0; i < ApplicationSettings::getInstance()->getMaxRecentProjectsCount(); i++)
{
if ((size_t)i < recentProjects.size() && recentProjects[i].exists())
{
FilePath project = recentProjects[i];
m_recentProjectAction[i]->setVisible(true);
m_recentProjectAction[i]->setText(FileSystem::fileName(project.str()).c_str());
m_recentProjectAction[i]->setData(project.str().c_str());
}
else
{
m_recentProjectAction[i]->setVisible(false);
}
}
}
void QtMainWindow::toggleShowDockWidgetTitleBars()
{
setShowDockWidgetTitleBars(!m_showDockWidgetTitleBars);
}
void QtMainWindow::setupEditMenu()
{
QMenu *menu = new QMenu(tr("&Edit"), this);
+4 -3
View File
@@ -47,6 +47,7 @@ private:
size_t m_forwardButton;
};
class MouseWheelFilter
: public QObject
{
@@ -111,7 +112,6 @@ public slots:
void newProjectFromSolution(const std::string& ideId, const std::string& solutionPath);
void openProject(const QString &path = QString());
void editProject();
void openRecentProject();
void find();
void findFulltext();
@@ -129,10 +129,11 @@ public slots:
void zoomOut();
void resetZoom();
void toggleView(View* view, bool fromMenu);
void openRecentProject();
void updateRecentProjectMenu();
void toggleView(View* view, bool fromMenu);
private slots:
void toggleShowDockWidgetTitleBars();
+63 -20
View File
@@ -20,7 +20,6 @@ QtWindow::QtWindow(QWidget* parent)
, m_closeButton(nullptr)
, m_cancelAble(true)
, m_scrollAble(false)
, m_showAsPopup(false)
, m_hasLogo(false)
, m_mousePressedInWindow(false)
{
@@ -84,6 +83,7 @@ QSize QtWindow::sizeHint() const
void QtWindow::setup()
{
setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath() + "window/window.css").c_str());
QVBoxLayout* layout = new QVBoxLayout();
layout->setContentsMargins(25, 30, 25, 0);
@@ -140,13 +140,6 @@ void QtWindow::setup()
m_content->setLayout(layout);
if (m_showAsPopup)
{
updateNextButton("Ok");
setCloseVisible(false);
setPreviousVisible(false);
}
setupDone();
}
@@ -162,21 +155,11 @@ void QtWindow::setScrollAble(bool scrollAble)
m_scrollAble = scrollAble;
}
void QtWindow::setShowAsPopup(bool showAsPopup)
{
m_showAsPopup = showAsPopup;
}
bool QtWindow::isScrollAble() const
{
return m_scrollAble;
}
bool QtWindow::isPopup() const
{
return m_showAsPopup;
}
void QtWindow::updateTitle(QString title)
{
if (m_title)
@@ -249,6 +232,30 @@ void QtWindow::setCloseVisible(bool visible)
}
}
void QtWindow::setNextDefault(bool isDefault)
{
if (m_nextButton)
{
m_nextButton->setDefault(isDefault);
}
}
void QtWindow::setPreviousDefault(bool isDefault)
{
if (m_previousButton)
{
m_previousButton->setDefault(isDefault);
}
}
void QtWindow::setCloseDefault(bool isDefault)
{
if (m_closeButton)
{
m_closeButton->setDefault(isDefault);
}
}
void QtWindow::showWindow()
{
show();
@@ -289,14 +296,50 @@ void QtWindow::resizeEvent(QResizeEvent *event)
m_window->move(5, displacement + 10);
}
void QtWindow::keyPressEvent(QKeyEvent *event)
void QtWindow::keyPressEvent(QKeyEvent* event)
{
if (m_cancelAble && event->key() == Qt::Key_Escape)
{
emit canceled();
handleClose();
return;
}
std::vector<QPushButton*> buttons;
if (m_nextButton && m_nextButton->isVisible()) buttons.push_back(m_nextButton);
if (m_closeButton && m_closeButton->isVisible()) buttons.push_back(m_closeButton);
if (m_previousButton && m_previousButton->isVisible()) buttons.push_back(m_previousButton);
if (event->key() == Qt::Key_Return)
{
for (QPushButton* button : buttons)
{
if (button->isDefault())
{
button->animateClick();
return;
}
}
}
if (event->key() == Qt::Key_Tab)
{
for (size_t i = 0; i < buttons.size(); i++)
{
if (buttons[i]->isDefault())
{
buttons[i]->setDefault(false);
buttons[(i + 1) % buttons.size()]->setDefault(true);
return;
}
}
if (buttons.size())
{
buttons[0]->setDefault(true);
return;
}
}
QWidget::keyPressEvent(event);
}
+5 -3
View File
@@ -26,10 +26,8 @@ public:
void setCancelAble(bool cancelAble);
void setScrollAble(bool scrollAble);
void setShowAsPopup(bool showAsPopup);
bool isScrollAble() const;
bool isPopup() const;
void updateTitle(QString title);
void updateNextButton(QString text);
@@ -43,10 +41,15 @@ public:
void setPreviousVisible(bool visible);
void setCloseVisible(bool visible);
void setNextDefault(bool isDefault);
void setPreviousDefault(bool isDefault);
void setCloseDefault(bool isDefault);
// QtWindowStackElement implementation
virtual void showWindow() override;
virtual void hideWindow() override;
signals:
void finished();
void canceled();
@@ -88,7 +91,6 @@ private slots:
private:
bool m_cancelAble;
bool m_scrollAble;
bool m_showAsPopup;
bool m_hasLogo;
@@ -47,8 +47,6 @@ private:
QtProjectWizzardWindow* createWindowWithSummary(
std::function<void(QtProjectWizzardWindow*, QtProjectWizzardContentSummary*)> func);
void connectShowFiles(QtProjectWizzardContent* content);
QtWindowStack m_windowStack;
std::shared_ptr<ProjectSettings> m_settings;
@@ -72,12 +72,6 @@ void QtProjectWizzardWindow::windowReady()
void QtProjectWizzardWindow::handleNext()
{
if (isPopup())
{
hide();
emit next();
}
m_content->save();
if (m_content->check())