src: Removed unused Log component and QtSplashScreen

This commit is contained in:
Eberhard Graether
2017-09-21 01:59:36 +02:00
parent 1e7d934cb8
commit 83c24c5cd0
17 changed files with 0 additions and 818 deletions
-4
View File
@@ -29,8 +29,6 @@ add_files(
component/controller/GraphController.h
component/controller/IDECommunicationController.cpp
component/controller/IDECommunicationController.h
component/controller/LogController.cpp
component/controller/LogController.h
component/controller/RefreshController.cpp
component/controller/RefreshController.h
component/controller/ScreenSearchController.cpp
@@ -63,8 +61,6 @@ add_files(
component/view/GraphViewStyle.cpp
component/view/GraphViewStyle.h
component/view/GraphViewStyleImpl.h
component/view/LogView.cpp
component/view/LogView.h
component/view/MainView.cpp
component/view/MainView.h
component/view/RefreshView.cpp
-14
View File
@@ -6,7 +6,6 @@
#include "component/controller/CodeController.h"
#include "component/controller/ErrorController.h"
#include "component/controller/GraphController.h"
#include "component/controller/LogController.h"
#include "component/controller/RefreshController.h"
#include "component/controller/ScreenSearchController.h"
#include "component/controller/SearchController.h"
@@ -17,7 +16,6 @@
#include "component/view/BookmarkView.h"
#include "component/view/CodeView.h"
#include "component/view/ErrorView.h"
#include "component/view/LogView.h"
#include "component/view/RefreshView.h"
#include "component/view/ScreenSearchView.h"
#include "component/view/SearchView.h"
@@ -27,8 +25,6 @@
#include "component/view/UndoRedoView.h"
#include "component/view/ViewFactory.h"
#include "utility/logging/LogManager.h"
std::shared_ptr<ComponentFactory> ComponentFactory::create(ViewFactory* viewFactory, StorageAccess* storageAccess)
{
std::shared_ptr<ComponentFactory> ptr(new ComponentFactory());
@@ -92,16 +88,6 @@ std::shared_ptr<Component> ComponentFactory::createGraphComponent(ViewLayout* vi
return std::make_shared<Component>(view, controller);
}
std::shared_ptr<Component> ComponentFactory::createLogComponent(ViewLayout* viewLayout)
{
std::shared_ptr<LogView> view = m_viewFactory->createLogView(viewLayout);
std::shared_ptr<LogController> controller = std::make_shared<LogController>();
LogManager::getInstance()->addLogger(controller);
return std::make_shared<Component>(view, controller);
}
std::shared_ptr<Component> ComponentFactory::createRefreshComponent(ViewLayout* viewLayout)
{
std::shared_ptr<View> view = m_viewFactory->createRefreshView(viewLayout);
-1
View File
@@ -24,7 +24,6 @@ public:
std::shared_ptr<Component> createCodeComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createErrorComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createGraphComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createLogComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createRefreshComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createScreenSearchComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createSearchComponent(ViewLayout* viewLayout);
@@ -1,132 +0,0 @@
#include "component/controller/LogController.h"
#include "settings/ApplicationSettings.h"
LogController::LogController()
: Logger("WindowLogger")
, m_enabled(false)
{
}
LogController::~LogController()
{
}
void LogController::setEnabled(bool enabled)
{
m_enabled = enabled;
}
bool LogController::getEnabled() const
{
return m_enabled;
}
LogView* LogController::getView() const
{
return Controller::getView<LogView>();
}
void LogController::clear()
{
std::lock_guard<std::mutex> lock(m_logsMutex);
m_logs.clear();
getView()->clear();
}
void LogController::logInfo(const LogMessage& message )
{
if (!m_enabled)
{
return;
}
if (m_logLevel & Logger::LOG_INFOS)
{
addLog(LOG_INFOS, message);
}
}
void LogController::logError(const LogMessage& message )
{
if (!m_enabled)
{
return;
}
if (m_logLevel & Logger::LOG_ERRORS)
{
addLog(LOG_ERRORS, message);
}
}
void LogController::logWarning(const LogMessage& message )
{
if (!m_enabled)
{
return;
}
if (m_logLevel & Logger::LOG_WARNINGS)
{
addLog(LOG_WARNINGS, message);
}
}
void LogController::handleMessage(MessageLogFilterChanged* message)
{
m_logLevel = message->logFilter;
ApplicationSettings* settings = ApplicationSettings::getInstance().get();
settings->setLogFilter(m_logLevel);
settings->save();
syncLogs();
}
void LogController::handleMessage(MessageClearLogView* message)
{
clear();
}
void LogController::addLog(Logger::LogLevel type, const LogMessage& message)
{
std::lock_guard<std::mutex> lock(m_logsMutex);
m_logs.push_back(
Log(
type,
(message.getFileName().empty() ? "" : message.getFileName() + ": ") + message.message,
message.getTimeString("%H:%M:%S")
)
);
if (!m_waiting)
{
m_waiting = true;
std::thread([&]()
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
syncLogs();
m_waiting = false;
}
).detach();
}
}
void LogController::syncLogs()
{
std::lock_guard<std::mutex> lock(m_logsMutex);
int logCount = m_logs.size();
if (logCount > getView()->LogLimit)
{
m_logs.erase(m_logs.begin(), m_logs.begin() + logCount - LogView::LogLimit);
}
std::vector<Log> logs;
for (const Log& log : m_logs)
{
if (log.type & m_logLevel)
{
logs.push_back(log);
}
}
getView()->addLogs(logs);
}
@@ -1,54 +0,0 @@
#ifndef LOG_CONTROLLER_H
#define LOG_CONTROLLER_H
#include <mutex>
#include "component/controller/Controller.h"
#include "component/view/LogView.h"
#include "utility/logging/Logger.h"
#include "utility/logging/LogMessage.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageClearLogView.h"
#include "utility/messaging/type/MessageLogFilterChanged.h"
class StorageAccess;
class LogController
: public Controller
, public Logger
, public MessageListener<MessageClearLogView>
, public MessageListener<MessageLogFilterChanged>
{
public:
LogController();
~LogController();
void setEnabled(bool enabled);
bool getEnabled() const;
private:
bool m_enabled;
LogView* getView() const;
virtual void clear();
virtual void logInfo(const LogMessage& message);
virtual void logWarning(const LogMessage& message);
virtual void logError(const LogMessage& message);
virtual void handleMessage(MessageClearLogView* message);
virtual void handleMessage(MessageLogFilterChanged* message);
void addLog(Logger::LogLevel type, const LogMessage& message);
void syncLogs();
std::vector<Log> m_logs;
Logger::LogLevelMask m_logLevel;
std::mutex m_logsMutex;
bool m_waiting;
};
#endif // LOG_CONTROLLER_H
-22
View File
@@ -1,22 +0,0 @@
#include "component/view/LogView.h"
const int LogView::LogLimit = 500;
LogView::LogView(ViewLayout* viewLayout)
: View(viewLayout)
{
}
LogView::~LogView()
{
}
std::string LogView::getName() const
{
return "Logs";
}
bool LogView::hasLogLevel(const Logger::LogLevel type, const Logger::LogLevelMask mask) const
{
return mask & type;
}
-37
View File
@@ -1,37 +0,0 @@
#ifndef LOG_VIEW_H
#define LOG_VIEW_H
#include "component/view/View.h"
#include "utility/logging/LogMessage.h"
#include "utility/logging/Logger.h"
struct Log
{
Log(Logger::LogLevel type, std::string message, std::string timestamp)
: type(type)
, message(message)
, timestamp(timestamp){}
Logger::LogLevel type;
std::string message;
std::string timestamp;
};
class LogView
: public View
{
public:
LogView(ViewLayout* viewLayout);
virtual ~LogView();
virtual std::string getName() const;
virtual bool hasLogLevel(const Logger::LogLevel type, const Logger::LogLevelMask mask) const;
virtual void clear() = 0;
virtual void addLog(Logger::LogLevel type, const LogMessage& message) = 0;
virtual void addLogs(const std::vector<Log>& logs) = 0;
static const int LogLimit;
};
#endif // LOG_VIEW_H
-2
View File
@@ -11,7 +11,6 @@ class DialogView;
class ErrorView;
class GraphView;
class MainView;
class LogView;
class RefreshView;
class ScreenSearchView;
class SearchView;
@@ -38,7 +37,6 @@ public:
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<ErrorView> createErrorView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<LogView> createLogView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<RefreshView> createRefreshView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<ScreenSearchView> createScreenSearchView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const = 0;
-4
View File
@@ -141,8 +141,6 @@ add_files(
qt/view/QtGraphView.h
qt/view/QtGraphViewStyleImpl.cpp
qt/view/QtGraphViewStyleImpl.h
qt/view/QtLogView.cpp
qt/view/QtLogView.h
qt/view/QtMainView.cpp
qt/view/QtMainView.h
qt/view/QtRefreshView.cpp
@@ -223,8 +221,6 @@ add_files(
qt/window/QtPreferencesWindow.h
qt/window/QtSelectPathsDialog.cpp
qt/window/QtSelectPathsDialog.h
qt/window/QtSplashScreen.cpp
qt/window/QtSplashScreen.h
qt/window/QtStartScreen.cpp
qt/window/QtStartScreen.h
qt/window/QtTextEditDialog.cpp
-8
View File
@@ -6,8 +6,6 @@
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageWindowFocus.h"
#include "utility/logging/LogManager.h"
#include "component/controller/LogController.h"
#include "utility/utilityApp.h"
QtApplication::QtApplication(int& argc, char** argv)
@@ -18,12 +16,6 @@ QtApplication::QtApplication(int& argc, char** argv)
int QtApplication::exec()
{
LogController* log = dynamic_cast<LogController*>(LogManager::getInstance()->getLoggerByType("WindowLogger"));
if (log != nullptr)
{
log->setEnabled(true);
}
return QApplication::exec();
}
-309
View File
@@ -1,309 +0,0 @@
#include "qt/view/QtLogView.h"
#include <QBoxLayout>
#include <QFrame>
#include <QLabel>
#include <QCheckBox>
#include <QPushButton>
#include <QStandardItemModel>
#include "Application.h"
#include "settings/ApplicationSettings.h"
#include "settings/ColorScheme.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "utility/messaging/type/MessageClearLogView.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageLogFilterChanged.h"
#include "utility/ResourcePaths.h"
#include "qt/utility/utilityQt.h"
#include "utility/logging/LogManager.h"
#include "qt/element/QtTable.h"
QtLogView::QtLogView(ViewLayout* viewLayout)
: LogView(viewLayout)
, m_addLogFunctor(std::bind(&QtLogView::doAddLog, this, std::placeholders::_1, std::placeholders::_2))
, m_addLogsFunctor(std::bind(&QtLogView::doAddLogs, this, std::placeholders::_1 ))
, m_clearFunctor(std::bind(&QtLogView::doClear, this))
, m_refreshFunctor(std::bind(&QtLogView::doRefreshView, this))
{
}
QtLogView::~QtLogView()
{
}
void QtLogView::createWidgetWrapper()
{
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(new QFrame()));
}
void QtLogView::initView()
{
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
layout->setContentsMargins(0, 10, 0, 5);
layout->setSpacing(0);
widget->setLayout(layout);
QHBoxLayout* headerLayout = new QHBoxLayout();
headerLayout->addSpacing(10);
ApplicationSettings* settings = ApplicationSettings::getInstance().get();
m_viewEnabled = new QCheckBox("Logging enabled (file, console logging)");
m_viewEnabled->setChecked(settings->getLoggingEnabled());
connect(m_viewEnabled, &QCheckBox::stateChanged,
[=](int){
setLoggingEnabled(m_viewEnabled->isChecked());
}
);
headerLayout->addWidget(m_viewEnabled);
headerLayout->addSpacing(25);
m_showAstLogging = new QCheckBox("AST Logging");
m_showAstLogging->setEnabled(m_viewEnabled->isChecked());
m_showAstLogging->setChecked(settings->getVerboseIndexerLoggingEnabled());
connect(m_showAstLogging, &QCheckBox::stateChanged,
[=](int){
setAstLoggingEnabled(m_showAstLogging->isChecked());
}
);
headerLayout->addWidget(m_showAstLogging);
headerLayout->addStretch();
layout->addLayout(headerLayout);
m_table = new QtTable(this);
m_model = new QStandardItemModel(this);
m_table->setModel(m_model);
m_model->setColumnCount(3);
m_table->setColumnWidth(LOGVIEW_COLUMN::TYPE, 100);
m_table->setColumnWidth(LOGVIEW_COLUMN::TIMESTAMP, 150);
m_table->setColumnWidth(LOGVIEW_COLUMN::TYPE, 100);
QStringList headers;
headers << "Type" << "Timestamp" << "Message";
m_model->setHorizontalHeaderLabels(headers);
layout->addWidget(m_table);
QHBoxLayout* filters = new QHBoxLayout();
filters->addSpacing(15);
m_logLevel = settings->getLogFilter();
m_showErrors = createFilterCheckbox("error", filters, m_logLevel & Logger::LOG_ERRORS);
m_showWarnings = createFilterCheckbox("warnings", filters, m_logLevel & Logger::LOG_WARNINGS);
m_showInfo = createFilterCheckbox("info", filters, m_logLevel & Logger::LOG_INFOS);
filters->addStretch();
QPushButton* clearButton = new QPushButton("clear log");
connect(clearButton, &QPushButton::clicked,
[=]()
{
//doClear();
MessageClearLogView().dispatch();
});
filters->addWidget(clearButton);
filters->addSpacing(30);
updateMask();
layout->addLayout(filters);
doRefreshView();
}
QCheckBox* QtLogView::createFilterCheckbox(const QString& name, QBoxLayout* layout, bool checked)
{
QCheckBox* checkbox = new QCheckBox(name);
checkbox->setChecked(checked);
connect(checkbox, &QCheckBox::stateChanged,
[=](int)
{
m_table->selectionModel()->clearSelection();
updateMask();
updateTable();
}
);
layout->addWidget(checkbox);
layout->addSpacing(25);
return checkbox;
}
void QtLogView::setLoggingEnabled(bool enabled)
{
m_showAstLogging->setEnabled(enabled);
LogManager::getInstance()->setLoggingEnabled(enabled);
ApplicationSettings::getInstance()->setLoggingEnabled(enabled);
ApplicationSettings::getInstance()->save();
Application::getInstance()->loadSettings();
MessageRefresh msg;
msg.uiOnly = true;
msg.dispatchImmediately();
}
void QtLogView::setAstLoggingEnabled(bool enabled)
{
ApplicationSettings::getInstance()->setVerboseIndexerLoggingEnabled(enabled);
ApplicationSettings::getInstance()->save();
Application::getInstance()->loadSettings();
MessageRefresh msg;
msg.uiOnly = true;
msg.dispatchImmediately();
}
void QtLogView::refreshView()
{
m_refreshFunctor();
}
void QtLogView::clear()
{
m_clearFunctor();
}
void QtLogView::addLog(Logger::LogLevel type, const LogMessage& message)
{
m_addLogFunctor(type, message);
}
void QtLogView::addLogs(const std::vector<Log>& logs)
{
m_addLogsFunctor(logs);
}
void QtLogView::doClear()
{
if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty())
{
m_model->removeRows(0, m_model->rowCount());
}
m_logs.clear();
}
void QtLogView::doRefreshView()
{
setStyleSheet();
}
void QtLogView::setStyleSheet() const
{
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
utility::setWidgetBackgroundColor(widget, ColorScheme::getInstance()->getColor("error/background"));
QPalette palette(m_showErrors->palette());
palette.setColor(QPalette::WindowText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
//palette.setColor(QPalette::Text, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
//palette.setColor(QPalette::ButtonText, QColor(ColorScheme::getInstance()->getColor("error/text/normal").c_str()));
//m_showErrors->setAutoFillBackground(true);
//m_showErrors->setPalette(palette);
//m_showFatals->setPalette(palette);
//m_showNonIndexedErrors->setPalette(palette);
//m_showNonIndexedFatals->setPalette(palette);
widget->setStyleSheet(
utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("error_view/error_view.css"))).c_str()
);
m_table->updateRows();
}
const char* QtLogView::getLogType(Logger::LogLevel type) const
{
switch (type)
{
case Logger::LOG_INFOS:
return "INFO";
case Logger::LOG_WARNINGS:
return "WARNING";
case Logger::LOG_ERRORS:
return "ERROR";
case Logger::LOG_ALL:
return "UNKNOWN";
}
}
bool QtLogView::isCheckedType(const Logger::LogLevel type) const
{
return m_logLevel & type;
}
void QtLogView::updateTable()
{
if (!m_model->index(0, 0).data(Qt::DisplayRole).toString().isEmpty())
{
m_model->removeRows(0, m_model->rowCount());
}
for ( Log& log : m_logs )
{
if (log.type & m_logLevel)
{
addLogToTable(log);
}
}
}
void QtLogView::updateMask()
{
m_logLevel =
(m_showInfo->isChecked() ? Logger::LOG_INFOS : 0) +
(m_showWarnings->isChecked() ? Logger::LOG_WARNINGS : 0) +
(m_showErrors->isChecked() ? Logger::LOG_ERRORS : 0);
MessageLogFilterChanged(m_logLevel).dispatch();
}
void QtLogView::addLogToTable(Log log)
{
const int rowNumber = m_table->getFilledRowCount();
if (rowNumber < m_model->rowCount())
{
m_model->insertRow(rowNumber);
}
m_model->setItem(rowNumber, LOGVIEW_COLUMN::TYPE, new QStandardItem(getLogType(log.type)));
m_model->setItem(rowNumber, LOGVIEW_COLUMN::TIMESTAMP, new QStandardItem(log.timestamp.c_str()));
m_model->setItem(rowNumber, LOGVIEW_COLUMN::MESSAGE, new QStandardItem(log.message.c_str()));
m_table->updateRows();
}
void QtLogView::doAddLog(Logger::LogLevel type, const LogMessage& message)
{
if (type & m_logLevel)
{
Log log(
type,
(message.getFileName().empty() ? "" : message.getFileName() + ": ") + message.message,
message.getTimeString("%H:%M:%S"));
m_logs.push_back(log);
addLogToTable(log);
}
}
void QtLogView::doAddLogs(const std::vector<Log>& logs)
{
doClear();
for(const Log& log : logs)
{
if( log.type & m_logLevel )
{
addLogToTable(log);
}
}
}
-81
View File
@@ -1,81 +0,0 @@
#ifndef QT_LOG_VIEW_H
#define QT_LOG_VIEW_H
#include <QWidget>
#include "component/view/LogView.h"
#include "qt/utility/QtThreadedFunctor.h"
#include "utility/logging/Logger.h"
class QBoxLayout;
class QCheckBox;
class QPalette;
class QStandardItemModel;
class QtTable;
class QtLogView
: public QWidget
, public LogView
{
Q_OBJECT
public:
QtLogView(ViewLayout* viewLayout);
virtual ~QtLogView();
// View implementation
virtual void createWidgetWrapper();
virtual void initView();
virtual void refreshView();
// Log View Implementation
virtual void clear();
virtual void addLog(Logger::LogLevel type, const LogMessage& message);
virtual void addLogs(const std::vector<Log>& logs);
private:
enum LOGVIEW_COLUMN
{
TYPE = 0,
TIMESTAMP = 1,
MESSAGE = 2,
};
void doClear();
void doRefreshView();
void doAddLog(Logger::LogLevel type, const LogMessage& message);
void doAddLogs(const std::vector<Log>& logs);
std::vector<Log> m_logs;
const char* getLogType(Logger::LogLevel type) const;
void addLogToTable(Log log);
void setLogFilter();
bool isCheckedType(const Logger::LogLevel type) const;
QCheckBox* createFilterCheckbox(const QString& name, QBoxLayout* layout, bool checked = false);
void setStyleSheet() const;
void setLoggingEnabled(bool enabled);
void setAstLoggingEnabled(bool enabled);
void updateMask();
void updateTable();
Logger::LogLevelMask m_logLevel;
QtTable* m_table;
QStandardItemModel* m_model;
QCheckBox* m_viewEnabled;
QCheckBox* m_showAstLogging;
QCheckBox* m_showErrors;
QCheckBox* m_showWarnings;
QCheckBox* m_showInfo;
QtThreadedFunctor<Logger::LogLevel, const LogMessage&> m_addLogFunctor;
QtThreadedFunctor<const std::vector<Log>&> m_addLogsFunctor;
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_refreshFunctor;
};
#endif // QT_LOG_VIEW_H
-6
View File
@@ -8,7 +8,6 @@
#include "qt/view/QtErrorView.h"
#include "qt/view/QtGraphView.h"
#include "qt/view/QtGraphViewStyleImpl.h"
#include "qt/view/QtLogView.h"
#include "qt/view/QtMainView.h"
#include "qt/view/QtRefreshView.h"
#include "qt/view/QtScreenSearchView.h"
@@ -64,11 +63,6 @@ std::shared_ptr<ErrorView> QtViewFactory::createErrorView(ViewLayout* viewLayout
return View::createInitAndAddToLayout<QtErrorView>(viewLayout);
}
std::shared_ptr<LogView> QtViewFactory::createLogView(ViewLayout* viewLayout) const
{
return View::createInitAndAddToLayout<QtLogView>(viewLayout);
}
std::shared_ptr<StatusView> QtViewFactory::createStatusView(ViewLayout* viewLayout) const
{
return View::createInitAndAddToLayout<QtStatusView>(viewLayout);
-1
View File
@@ -18,7 +18,6 @@ public:
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<ErrorView> createErrorView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<LogView> createLogView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<RefreshView> createRefreshView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<ScreenSearchView> createScreenSearchView(ViewLayout* viewLayout) const;
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const;
-6
View File
@@ -10,7 +10,6 @@
#include <QTimer>
#include "Application.h"
#include "component/controller/LogController.h"
#include "component/view/CompositeView.h"
#include "component/view/TabbedView.h"
#include "component/view/View.h"
@@ -379,11 +378,6 @@ void QtMainWindow::contextMenuEvent(QContextMenuEvent* event)
void QtMainWindow::closeEvent(QCloseEvent* event)
{
LogController* log = dynamic_cast<LogController*>(LogManager::getInstance()->getLoggerByType("WindowLogger"));
if (log != nullptr)
{
log->setEnabled(false);
}
MessageWindowClosed().dispatchImmediately();
}
-98
View File
@@ -1,98 +0,0 @@
#include "qt/window/QtSplashScreen.h"
#include <QApplication>
#include <QThread>
#include <QTimer>
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "utility/ResourcePaths.h"
namespace
{
class InitThread : public QThread
{
public:
void run(void)
{
// Mininmum time the SplashScreen gets displayed.
QThread::msleep(5000);
}
};
}
QtSplashScreen::QtSplashScreen(const QPixmap &pixmap, Qt::WindowFlags f)
: QSplashScreen(pixmap, f)
, m_state(0)
{
QtDeviceScaledPixmap foreground((ResourcePaths::getGuiPath().str() + "splash_white.png").c_str());
foreground.scaleToHeight(pixmap.size().height() * 0.8);
m_foreground = foreground.pixmap();
QtDeviceScaledPixmap background((ResourcePaths::getGuiPath().str() + "splash_blue.png").c_str());
background.scaleToHeight(pixmap.size().height() * 0.9);
m_background = background.pixmap();
}
QtSplashScreen::~QtSplashScreen()
{
}
void QtSplashScreen::exec(QApplication& app)
{
m_state = 0;
QTimer* timer = new QTimer(this);
QObject::connect(timer, &QTimer::timeout, this, &QtSplashScreen::animate);
timer->start(150);
app.processEvents();
show();
repaint();
app.processEvents();
}
void QtSplashScreen::setMessage(const QString &str)
{
m_string = str;
repaint();
}
void QtSplashScreen::setVersion(const QString &str)
{
m_version = str;
repaint();
}
void QtSplashScreen::animate()
{
m_state = (m_state + 2) % 120;
repaint();
}
void QtSplashScreen::drawContents(QPainter *painter)
{
painter->save();
painter->translate(rect().width() / 2, rect().height() / 2);
painter->rotate(m_state * 3);
painter->drawPixmap(-rect().width() * 0.9 / 2, -rect().height() * 0.9 / 2, m_background);
painter->restore();
painter->drawPixmap(rect().width() * 0.1, rect().height() * 0.1, m_foreground);
QRect r = rect();
r.setRect(r.x() + 5, r.height() - 20, r.width() - 10, 20);
painter->drawText(r, Qt::AlignRight, QString("Sourcetrail v").append(m_version));
// Draw message at given position, limited to 43 chars
// If message is too long, string is truncated
if (m_string.length() > 40)
{
m_string.truncate(39);
m_string += "...";
}
painter->drawText(r, Qt::AlignLeft, m_string);
}
-39
View File
@@ -1,39 +0,0 @@
#ifndef QTSPLASHSCREEN_H
#define QTSPLASHSCREEN_H
#include <QSplashScreen>
#include <QPainter>
#include <QWidget>
class QApplication;
class QPixmap;
class QtSplashScreen
: public QSplashScreen
{
Q_OBJECT
public:
QtSplashScreen(const QPixmap& pixmap, Qt::WindowFlags f = 0);
virtual ~QtSplashScreen();
void exec(QApplication& app);
void setMessage(const QString& str);
void setVersion(const QString& str);
public slots:
void animate();
private:
void drawContents(QPainter* painter);
int m_state;
QString m_string;
QString m_version;
QPixmap m_background;
QPixmap m_foreground;
};
#endif //QTSPLASHSCREEN_H