ui: Improved scrolling and layouting in QtCodeView and colored locations of active TokenId differently

This commit is contained in:
Eberhard Graether
2014-07-04 15:33:51 +02:00
parent 610aa2eb09
commit a70a9009cc
15 changed files with 142 additions and 33 deletions
+21 -13
View File
@@ -1,7 +1,8 @@
#include "qt/view/QtCodeView.h"
#include <iostream>
#include <QtWidgets>
#include <QFrame>
#include <QScrollArea>
#include <QVBoxLayout>
#include "data/location/TokenLocationFile.h"
#include "qt/element/QtCodeFile.h"
@@ -13,7 +14,7 @@
QtCodeView::QtCodeView(ViewLayout* viewLayout)
: CodeView(viewLayout)
, m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this))
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3))
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
{
}
@@ -23,7 +24,7 @@ QtCodeView::~QtCodeView()
void QtCodeView::createWidgetWrapper()
{
setWidgetWrapper(std::make_shared<QtWidgetWrapper>(std::make_shared<QFrame>()));
setWidgetWrapper(std::make_shared<QtWidgetWrapper>(std::make_shared<QScrollArea>()));
}
void QtCodeView::initGui()
@@ -31,15 +32,22 @@ void QtCodeView::initGui()
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
utility::setWidgetBackgroundColor(widget, Colori(255, 125, 0, 255));
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
layout->setSpacing(3);
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(3, 3, 3, 3);
widget->setLayout(layout);
layout->setAlignment(Qt::AlignTop);
m_frame->setLayout(layout);
scroll->setWidgetResizable(true);
scroll->setWidget(m_frame.get());
}
void QtCodeView::addCodeSnippet(const std::string& str, const TokenLocationFile& locationFile, int startLineNumber)
void QtCodeView::addCodeSnippet(const CodeSnippetParams params)
{
m_addCodeSnippetFunctor(str, locationFile, startLineNumber);
m_addCodeSnippetFunctor(params);
}
void QtCodeView::clearCodeSnippets()
@@ -53,9 +61,9 @@ void QtCodeView::activateToken(Id tokenId) const
message.dispatch();
}
void QtCodeView::doAddCodeSnippet(const std::string& str, const TokenLocationFile& locationFile, int startLineNumber)
void QtCodeView::doAddCodeSnippet(const CodeSnippetParams params)
{
std::string fileName = FileSystem::fileName(locationFile.getFilePath());
std::string fileName = FileSystem::fileName(params.locationFile.getFilePath());
QtCodeFile* file = nullptr;
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
@@ -74,10 +82,10 @@ void QtCodeView::doAddCodeSnippet(const std::string& str, const TokenLocationFil
m_files.push_back(filePtr);
file = filePtr.get();
widget->layout()->addWidget(file);
m_frame->layout()->addWidget(file);
}
file->addCodeSnippet(str, locationFile, startLineNumber);
file->addCodeSnippet(params.code, params.locationFile, params.startLineNumber, params.activeTokenId);
}
void QtCodeView::doClearCodeSnippets()