parent
958e6f80bd
commit
44bb0e85c2
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (C) 2015 by authors
|
||||||
|
Author: Jan Boon <jan.boon@kaetemi.be>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NLQT_COMMON_H
|
||||||
|
#define NLQT_COMMON_H
|
||||||
|
#include <nel/misc/types_nl.h>
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QStyleFactory>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QPalette>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
namespace NLQT {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void preApplication()
|
||||||
|
{
|
||||||
|
QCoreApplication::libraryPaths();
|
||||||
|
QString app_location = QCoreApplication::applicationFilePath();
|
||||||
|
app_location.truncate(app_location.lastIndexOf(QLatin1Char('/')));
|
||||||
|
app_location = QDir(app_location).canonicalPath();
|
||||||
|
QCoreApplication::removeLibraryPath(app_location);
|
||||||
|
QCoreApplication::addLibraryPath("./platforms");
|
||||||
|
QCoreApplication::addLibraryPath("./qtwebengine");
|
||||||
|
QCoreApplication::addLibraryPath("./imageformats");
|
||||||
|
QCoreApplication::addLibraryPath("./iconengines");
|
||||||
|
QCoreApplication::addLibraryPath("./designer");
|
||||||
|
}
|
||||||
|
|
||||||
|
void postApplication()
|
||||||
|
{
|
||||||
|
QApplication::setStyle(QStyleFactory::create("Fusion"));
|
||||||
|
QPalette palette = qApp->palette();
|
||||||
|
palette.setColor(QPalette::Window, QColor(64, 64, 64));
|
||||||
|
palette.setColor(QPalette::WindowText, Qt::white);
|
||||||
|
palette.setColor(QPalette::Base, QColor(48, 48, 48));
|
||||||
|
palette.setColor(QPalette::AlternateBase, QColor(64, 64, 64));
|
||||||
|
palette.setColor(QPalette::ToolTipBase, Qt::white);
|
||||||
|
palette.setColor(QPalette::ToolTipText, Qt::white);
|
||||||
|
palette.setColor(QPalette::Text, Qt::white);
|
||||||
|
palette.setColor(QPalette::Button, QColor(64, 64, 64));
|
||||||
|
palette.setColor(QPalette::ButtonText, Qt::white);
|
||||||
|
palette.setColor(QPalette::BrightText, Qt::red);
|
||||||
|
palette.setColor(QPalette::Highlight, QColor(64, 128, 96));
|
||||||
|
palette.setColor(QPalette::HighlightedText, Qt::white);
|
||||||
|
qApp->setPalette(palette);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
#endif /* #ifndef NLQT_SERVICE_WINDOW_H */
|
||||||
|
|
||||||
|
/* end of file */
|
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (C) 2015 by authors
|
||||||
|
Author: Jan Boon <jan.boon@kaetemi.be>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NLQT_SERVICE_DISPLAYER_H
|
||||||
|
#define NLQT_SERVICE_DISPLAYER_H
|
||||||
|
#include <nel/misc/types_nl.h>
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/log.h>
|
||||||
|
#include <nel/misc/displayer.h>
|
||||||
|
#include <nel/misc/window_displayer.h>
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
|
||||||
|
namespace NLQT {
|
||||||
|
class CServiceWindow;
|
||||||
|
class CCommandLog;
|
||||||
|
|
||||||
|
class CServiceDisplayer : public NLMISC::CWindowDisplayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CServiceDisplayer(const char *displayerName);
|
||||||
|
virtual ~CServiceDisplayer();
|
||||||
|
|
||||||
|
virtual void setTitleBar(const std::string &titleBar);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void doDisplay(const NLMISC::CLog::TDisplayInfo& args, const char *message);
|
||||||
|
|
||||||
|
virtual void open(int argc, char **argv, std::string titleBar, bool iconified, sint x, sint y, sint w, sint h, sint hs, sint fs, const std::string &fn, bool ww, NLMISC::CLog *log);
|
||||||
|
|
||||||
|
virtual void display_main();
|
||||||
|
|
||||||
|
void commandExecute(const std::string &cmd);
|
||||||
|
void buttonCallback(QWidget *sender);
|
||||||
|
void timerCallback();
|
||||||
|
void exitCallback();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CServiceWindow *m_ServiceWindow;
|
||||||
|
CCommandLog *m_CommandLog;
|
||||||
|
NLMISC::CLog *m_Log;
|
||||||
|
NLMISC::CSynchronized<std::vector<std::pair<NLMISC::CLog::TDisplayInfo, std::string> > > m_DelayLog;
|
||||||
|
|
||||||
|
NLMISC::CSynchronized<std::string> m_SetTitleBar;
|
||||||
|
bool m_DoSetTitleBar;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CServiceDisplayer(const CServiceDisplayer &);
|
||||||
|
CServiceDisplayer &operator=(const CServiceDisplayer &);
|
||||||
|
|
||||||
|
}; /* class CServiceDisplayer */
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
#endif /* #ifndef NLQT_SERVICE_DISPLAYER_H */
|
||||||
|
|
||||||
|
/* end of file */
|
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (C) 2015 by authors
|
||||||
|
Author: Jan Boon <jan.boon@kaetemi.be>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NLQT_SERVICE_WINDOW_H
|
||||||
|
#define NLQT_SERVICE_WINDOW_H
|
||||||
|
#include <nel/misc/types_nl.h>
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/log.h>
|
||||||
|
#include <nel/misc/displayer.h>
|
||||||
|
#include <nel/misc/callback.h>
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
class QHBoxLayout;
|
||||||
|
class QVBoxLayout;
|
||||||
|
|
||||||
|
namespace NLQT {
|
||||||
|
class CCommandLog;
|
||||||
|
|
||||||
|
typedef NLMISC::CCallback<void, QWidget *> TDisplayerButtonCallback;
|
||||||
|
typedef NLMISC::CCallback<void> TDisplayerTimerCallback;
|
||||||
|
typedef NLMISC::CCallback<void> TDisplayerExitCallback;
|
||||||
|
|
||||||
|
class CServiceWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CServiceWindow(QWidget *parent = NULL, Qt::WindowFlags flags = 0);
|
||||||
|
virtual ~CServiceWindow();
|
||||||
|
|
||||||
|
inline void setButtonCallback(const TDisplayerButtonCallback &cb) { m_ButtonCallback = cb; }
|
||||||
|
inline void setTimerCallback(const TDisplayerTimerCallback &cb) { m_TimerCallback = cb; }
|
||||||
|
inline void setExitCallback(const TDisplayerExitCallback &cb) { m_ExitCallback = cb; }
|
||||||
|
inline CCommandLog *commandLog() { return m_CommandLog; }
|
||||||
|
|
||||||
|
QWidget *addLabel();
|
||||||
|
QWidget *addButton();
|
||||||
|
void addLine();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void buttonCallback();
|
||||||
|
void timerCallback();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CCommandLog *m_CommandLog;
|
||||||
|
TDisplayerButtonCallback m_ButtonCallback;
|
||||||
|
TDisplayerTimerCallback m_TimerCallback;
|
||||||
|
TDisplayerExitCallback m_ExitCallback;
|
||||||
|
|
||||||
|
QVBoxLayout *m_LabelVBox;
|
||||||
|
QHBoxLayout *m_LabelHBox;
|
||||||
|
|
||||||
|
QFont m_Font;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CServiceWindow(const CServiceWindow &);
|
||||||
|
CServiceWindow &operator=(const CServiceWindow &);
|
||||||
|
|
||||||
|
}; /* class CServiceWindow */
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
#endif /* #ifndef NLQT_SERVICE_WINDOW_H */
|
||||||
|
|
||||||
|
/* end of file */
|
@ -0,0 +1,274 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (C) 2015 by authors
|
||||||
|
Author: Jan Boon <jan.boon@kaetemi.be>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nel/misc/types_nl.h>
|
||||||
|
#include <nelqt/displayer/service_displayer.h>
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
#include <nel/misc/command.h>
|
||||||
|
#include <nel/misc/path.h>
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include <nelqt/common.h>
|
||||||
|
#include <nelqt/displayer/command_log.h>
|
||||||
|
#include <nelqt/displayer/service_window.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace NLMISC;
|
||||||
|
|
||||||
|
namespace NLQT {
|
||||||
|
|
||||||
|
CServiceDisplayer::CServiceDisplayer(const char *displayerName) : CWindowDisplayer(displayerName), m_DelayLog("CServiceDisplayer::m_DelayLog"), m_SetTitleBar("CServiceDisplayer::m_SetTitleBar"), m_CommandLog(NULL), m_DoSetTitleBar(false)
|
||||||
|
{
|
||||||
|
createLabel("@Clear|CLEAR");
|
||||||
|
|
||||||
|
INelContext::getInstance().setWindowedApplication(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
CServiceDisplayer::~CServiceDisplayer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::doDisplay(const CLog::TDisplayInfo& args, const char *message)
|
||||||
|
{
|
||||||
|
if (!m_Log)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_CommandLog)
|
||||||
|
{
|
||||||
|
m_CommandLog->doDisplay(args, message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NLMISC::CSynchronized<std::vector<std::pair<CLog::TDisplayInfo, std::string> > >::CAccessor access(&m_DelayLog);
|
||||||
|
access.value().push_back(std::pair<CLog::TDisplayInfo, std::string>(args, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::open(int argc, char **argv, std::string titleBar, bool iconified, sint x, sint y, sint w, sint h, sint hs, sint fs, const std::string &fn, bool ww, NLMISC::CLog *log)
|
||||||
|
{
|
||||||
|
if (w == -1)
|
||||||
|
w = 700;
|
||||||
|
if (h == -1)
|
||||||
|
h = 300;
|
||||||
|
if (hs == -1)
|
||||||
|
hs = 1000;
|
||||||
|
|
||||||
|
m_Log = log;
|
||||||
|
|
||||||
|
NLQT::preApplication();
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
NLQT::postApplication();
|
||||||
|
|
||||||
|
CServiceWindow serviceWindow;
|
||||||
|
// serviceWindow.move(x, y);
|
||||||
|
serviceWindow.resize(w, h);
|
||||||
|
serviceWindow.setWindowTitle(QString::fromUtf8(titleBar.c_str()));
|
||||||
|
m_ServiceWindow = &serviceWindow;
|
||||||
|
; {
|
||||||
|
NLMISC::CSynchronized<std::vector<std::pair<CLog::TDisplayInfo, std::string> > >::CAccessor access(&m_DelayLog);
|
||||||
|
for (std::vector<std::pair<CLog::TDisplayInfo, std::string> >::iterator it(access.value().begin()), end(access.value().end()); it != end; ++it)
|
||||||
|
serviceWindow.commandLog()->doDisplay(it->first, it->second.c_str());
|
||||||
|
access.value().clear();
|
||||||
|
}
|
||||||
|
m_CommandLog = serviceWindow.commandLog();
|
||||||
|
; {
|
||||||
|
NLMISC::CSynchronized<std::vector<std::pair<CLog::TDisplayInfo, std::string> > >::CAccessor access(&m_DelayLog);
|
||||||
|
for (std::vector<std::pair<CLog::TDisplayInfo, std::string> >::iterator it(access.value().begin()), end(access.value().end()); it != end; ++it)
|
||||||
|
serviceWindow.commandLog()->doDisplay(it->first, it->second.c_str());
|
||||||
|
access.value().clear();
|
||||||
|
}
|
||||||
|
serviceWindow.setButtonCallback(TDisplayerButtonCallback(this, &CServiceDisplayer::buttonCallback));
|
||||||
|
serviceWindow.setTimerCallback(TDisplayerTimerCallback(this, &CServiceDisplayer::timerCallback));
|
||||||
|
serviceWindow.setExitCallback(TDisplayerExitCallback(this, &CServiceDisplayer::exitCallback));
|
||||||
|
m_CommandLog->setExecCommand(TCommandExecute(this, &CServiceDisplayer::commandExecute));
|
||||||
|
serviceWindow.show();
|
||||||
|
app.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::display_main()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::commandExecute(const std::string &cmd) // DT
|
||||||
|
{
|
||||||
|
m_Log->displayRawNL("> %s", cmd.c_str());
|
||||||
|
|
||||||
|
{
|
||||||
|
CSynchronized<std::vector<std::string> >::CAccessor access(&_CommandsToExecute);
|
||||||
|
access.value().push_back(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::setTitleBar(const std::string &titleBar)
|
||||||
|
{
|
||||||
|
NLMISC::CSynchronized<std::string>::CAccessor access(&m_SetTitleBar);
|
||||||
|
access.value() = titleBar;
|
||||||
|
m_DoSetTitleBar = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
QString rstrip(const QString& str)
|
||||||
|
{
|
||||||
|
int n = str.size() - 1;
|
||||||
|
for (; n >= 0; --n)
|
||||||
|
{
|
||||||
|
if (!str.at(n).isSpace())
|
||||||
|
{
|
||||||
|
return str.left(n + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::buttonCallback(QWidget *sender) // DT
|
||||||
|
{
|
||||||
|
CSynchronized<std::vector<CWindowDisplayer::CLabelEntry> >::CAccessor access(&_Labels);
|
||||||
|
for (uint i = 0; i < access.value().size(); i++)
|
||||||
|
{
|
||||||
|
if (access.value()[i].Hwnd == sender)
|
||||||
|
{
|
||||||
|
if (access.value()[i].Value == "@Clear|CLEAR")
|
||||||
|
{
|
||||||
|
// special commands because the clear must be called by the display thread and not main thread
|
||||||
|
m_CommandLog->clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// the button was found, add the command in the command stack
|
||||||
|
CSynchronized<std::vector<std::string> >::CAccessor accessCommands(&_CommandsToExecute);
|
||||||
|
string str;
|
||||||
|
nlassert(!access.value()[i].Value.empty());
|
||||||
|
nlassert(access.value()[i].Value[0] == '@');
|
||||||
|
|
||||||
|
string::size_type pos = access.value()[i].Value.find("|");
|
||||||
|
if (pos != string::npos)
|
||||||
|
{
|
||||||
|
str = access.value()[i].Value.substr(pos + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str = access.value()[i].Value.substr(1);
|
||||||
|
}
|
||||||
|
if (!str.empty())
|
||||||
|
accessCommands.value().push_back(str);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::timerCallback() // DT
|
||||||
|
{
|
||||||
|
if (m_DoSetTitleBar)
|
||||||
|
{
|
||||||
|
NLMISC::CSynchronized<std::string>::CAccessor access(&m_SetTitleBar);
|
||||||
|
m_ServiceWindow->setWindowTitle(QString::fromUtf8(access.value().c_str()));
|
||||||
|
m_DoSetTitleBar = false;
|
||||||
|
access.value().clear();
|
||||||
|
}
|
||||||
|
; {
|
||||||
|
CSynchronized<std::vector<CLabelEntry> >::CAccessor access(&_Labels);
|
||||||
|
for (uint i = 0; i < access.value().size(); i++)
|
||||||
|
{
|
||||||
|
if (access.value()[i].NeedUpdate && !access.value()[i].Value.empty())
|
||||||
|
{
|
||||||
|
if (access.value()[i].Hwnd == NULL)
|
||||||
|
{
|
||||||
|
// empty char (on previous) is separator
|
||||||
|
if (i > 0 && access.value()[i - 1].Value.empty())
|
||||||
|
{
|
||||||
|
m_ServiceWindow->addLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a button for command and label for variables
|
||||||
|
if (access.value()[i].Value[0] == '@')
|
||||||
|
{
|
||||||
|
access.value()[i].Hwnd = m_ServiceWindow->addButton();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
access.value()[i].Hwnd = m_ServiceWindow->addLabel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string n;
|
||||||
|
|
||||||
|
// do this tricks to be sure that windows will clear what is after the number
|
||||||
|
if (access.value()[i].Value[0] != '@')
|
||||||
|
n = access.value()[i].Value + " ";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string::size_type pos = access.value()[i].Value.find('|');
|
||||||
|
if (pos != string::npos)
|
||||||
|
{
|
||||||
|
n = access.value()[i].Value.substr(1, pos - 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n = access.value()[i].Value.substr(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (access.value()[i].Value[0] == '@')
|
||||||
|
{
|
||||||
|
((QPushButton *)access.value()[i].Hwnd)->setText(rstrip(QString::fromUtf8(n.c_str())));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
((QLabel *)access.value()[i].Hwnd)->setText(rstrip(QString::fromUtf8(n.c_str())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceDisplayer::exitCallback() // DT
|
||||||
|
{
|
||||||
|
_Continue = false;
|
||||||
|
m_Log = NULL;
|
||||||
|
m_CommandLog = NULL;
|
||||||
|
m_ServiceWindow = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
/* end of file */
|
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (C) 2015 by authors
|
||||||
|
Author: Jan Boon <jan.boon@kaetemi.be>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nel/misc/types_nl.h>
|
||||||
|
#include <nelqt/displayer/service_window.h>
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QFontDatabase>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
#include <nel/misc/command.h>
|
||||||
|
#include <nel/misc/path.h>
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include <nelqt/displayer/command_log.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace NLMISC;
|
||||||
|
|
||||||
|
namespace NLQT {
|
||||||
|
|
||||||
|
CServiceWindow::CServiceWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), m_Font(QFontDatabase::systemFont(QFontDatabase::FixedFont))
|
||||||
|
{
|
||||||
|
m_LabelVBox = new QVBoxLayout(this);
|
||||||
|
m_LabelHBox = new QHBoxLayout(this);
|
||||||
|
m_LabelVBox->addLayout(m_LabelHBox);
|
||||||
|
|
||||||
|
QWidget *widget = new QWidget(this);
|
||||||
|
QVBoxLayout *vbox = new QVBoxLayout(widget);
|
||||||
|
vbox->addLayout(m_LabelVBox);
|
||||||
|
|
||||||
|
m_CommandLog = new CCommandLog(this);
|
||||||
|
m_CommandLog->layout()->setMargin(0);
|
||||||
|
vbox->addWidget(m_CommandLog);
|
||||||
|
|
||||||
|
widget->setLayout(vbox);
|
||||||
|
setCentralWidget(widget);
|
||||||
|
|
||||||
|
QTimer *timer = new QTimer(this);
|
||||||
|
connect(timer, SIGNAL(timeout()), this, SLOT(timerCallback()));
|
||||||
|
timer->start(25);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *CServiceWindow::addLabel()
|
||||||
|
{
|
||||||
|
QLabel *label = new QLabel(this);
|
||||||
|
label->setFont(m_Font);
|
||||||
|
m_LabelHBox->addWidget(label);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *CServiceWindow::addButton()
|
||||||
|
{
|
||||||
|
QPushButton *button = new QPushButton(this);
|
||||||
|
button->setFont(m_Font);
|
||||||
|
connect(button, SIGNAL(clicked()), this, SLOT(buttonCallback()));
|
||||||
|
m_LabelHBox->addWidget(button);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceWindow::addLine()
|
||||||
|
{
|
||||||
|
m_LabelHBox = new QHBoxLayout(this);
|
||||||
|
m_LabelVBox->addLayout(m_LabelHBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
CServiceWindow::~CServiceWindow()
|
||||||
|
{
|
||||||
|
if (m_ExitCallback)
|
||||||
|
{
|
||||||
|
m_ExitCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceWindow::timerCallback()
|
||||||
|
{
|
||||||
|
if (m_TimerCallback)
|
||||||
|
{
|
||||||
|
m_TimerCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CServiceWindow::buttonCallback()
|
||||||
|
{
|
||||||
|
if (m_ButtonCallback)
|
||||||
|
{
|
||||||
|
QWidget *s = (QWidget *)sender();
|
||||||
|
m_ButtonCallback(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
/* end of file */
|
Loading…
Reference in New Issue