* updated spacings and colors in QtCodeView and QtCodeFile * using Source Code Pro Regular (had to remove light cut from the Fonts folder because it got always used) * updated syntax highlighted colors to fit design * changed colors of highlights * indent all QtCodeSnippets by maximum line number in QtCodeFile * fixed syntax highlighting to work with sole multiline comment end fortune cookie message = Your present plans are going to succeed.
97 lines
2.4 KiB
C++
97 lines
2.4 KiB
C++
#include "qt/view/QtCodeView.h"
|
|
|
|
#include <QFrame>
|
|
#include <QScrollArea>
|
|
#include <QVBoxLayout>
|
|
|
|
#include "data/location/TokenLocationFile.h"
|
|
#include "qt/element/QtCodeFile.h"
|
|
#include "qt/QtWidgetWrapper.h"
|
|
#include "qt/utility/utilityQt.h"
|
|
#include "utility/FileSystem.h"
|
|
#include "utility/messaging/type/MessageActivateToken.h"
|
|
#include "utility/text/TextAccess.h"
|
|
|
|
QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
|
: CodeView(viewLayout)
|
|
, m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this))
|
|
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
|
|
{
|
|
}
|
|
|
|
QtCodeView::~QtCodeView()
|
|
{
|
|
}
|
|
|
|
void QtCodeView::createWidgetWrapper()
|
|
{
|
|
setWidgetWrapper(std::make_shared<QtWidgetWrapper>(std::make_shared<QScrollArea>()));
|
|
}
|
|
|
|
void QtCodeView::initGui()
|
|
{
|
|
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
|
|
widget->setStyleSheet(TextAccess::createFromFile("data/gui/code_view/code_view.css")->getText().c_str());
|
|
widget->setObjectName("code_view");
|
|
|
|
QScrollArea* scroll = dynamic_cast<QScrollArea*>(widget);
|
|
m_frame = std::make_shared<QFrame>(scroll);
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(m_frame.get());
|
|
layout->setSpacing(10);
|
|
layout->setContentsMargins(15, 15, 15, 15);
|
|
layout->setAlignment(Qt::AlignTop);
|
|
m_frame->setLayout(layout);
|
|
|
|
scroll->setWidgetResizable(true);
|
|
scroll->setWidget(m_frame.get());
|
|
}
|
|
|
|
void QtCodeView::addCodeSnippet(const CodeSnippetParams params)
|
|
{
|
|
m_addCodeSnippetFunctor(params);
|
|
}
|
|
|
|
void QtCodeView::clearCodeSnippets()
|
|
{
|
|
m_clearCodeSnippetsFunctor();
|
|
}
|
|
|
|
void QtCodeView::activateToken(Id tokenId) const
|
|
{
|
|
MessageActivateToken message(tokenId);
|
|
message.dispatch();
|
|
}
|
|
|
|
void QtCodeView::doAddCodeSnippet(const CodeSnippetParams params)
|
|
{
|
|
std::string fileName = FileSystem::fileName(params.locationFile.getFilePath());
|
|
QtCodeFile* file = nullptr;
|
|
|
|
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
|
{
|
|
if (filePtr->getFileName() == fileName)
|
|
{
|
|
file = filePtr.get();
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!file)
|
|
{
|
|
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
|
|
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(this, fileName, widget);
|
|
|
|
m_files.push_back(filePtr);
|
|
file = filePtr.get();
|
|
m_frame->layout()->addWidget(file);
|
|
}
|
|
|
|
file->addCodeSnippet(params.code, params.locationFile, params.startLineNumber, params.activeTokenId);
|
|
}
|
|
|
|
void QtCodeView::doClearCodeSnippets()
|
|
{
|
|
m_files.clear();
|
|
}
|