ui: added maximize button to CodeSnippets that opens the full file in a separate window
This commit is contained in:
@@ -1,21 +1,14 @@
|
||||
#include "qt/view/QtCodeView.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "qt/element/QtCodeFileList.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
#include "utility/FileSystem.h"
|
||||
#include "utility/messaging/type/MessageActivateToken.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
: CodeView(viewLayout)
|
||||
, m_refreshViewFunctor(std::bind(&QtCodeView::doRefreshView, this))
|
||||
, m_clearCodeSnippetsFunctor(std::bind(&QtCodeView::doClearCodeSnippets, this))
|
||||
, m_showCodeFileFunctor(std::bind(&QtCodeView::doShowCodeFile, this, std::placeholders::_1))
|
||||
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
|
||||
{
|
||||
}
|
||||
@@ -26,27 +19,13 @@ QtCodeView::~QtCodeView()
|
||||
|
||||
void QtCodeView::createWidgetWrapper()
|
||||
{
|
||||
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(std::make_shared<QScrollArea>()));
|
||||
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(
|
||||
std::shared_ptr<QtCodeFileList>(createQtCodeFileList())
|
||||
));
|
||||
}
|
||||
|
||||
void QtCodeView::initView()
|
||||
{
|
||||
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
|
||||
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());
|
||||
|
||||
setStyleSheet();
|
||||
}
|
||||
|
||||
void QtCodeView::refreshView()
|
||||
@@ -54,7 +33,12 @@ void QtCodeView::refreshView()
|
||||
m_refreshViewFunctor();
|
||||
}
|
||||
|
||||
void QtCodeView::addCodeSnippet(const CodeSnippetParams params)
|
||||
void QtCodeView::showCodeFile(const CodeSnippetParams& params)
|
||||
{
|
||||
m_showCodeFileFunctor(params);
|
||||
}
|
||||
|
||||
void QtCodeView::addCodeSnippet(const CodeSnippetParams& params)
|
||||
{
|
||||
m_addCodeSnippetFunctor(params);
|
||||
}
|
||||
@@ -64,51 +48,41 @@ void QtCodeView::clearCodeSnippets()
|
||||
m_clearCodeSnippetsFunctor();
|
||||
}
|
||||
|
||||
void QtCodeView::activateToken(Id tokenId) const
|
||||
{
|
||||
MessageActivateToken message(tokenId);
|
||||
message.dispatch();
|
||||
}
|
||||
|
||||
void QtCodeView::doRefreshView()
|
||||
{
|
||||
setStyleSheet();
|
||||
setStyleSheet(getQtCodeFileList());
|
||||
}
|
||||
|
||||
void QtCodeView::doAddCodeSnippet(const CodeSnippetParams params)
|
||||
void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
|
||||
{
|
||||
std::string fileName = FileSystem::fileName(params.locationFile.getFilePath());
|
||||
QtCodeFile* file = nullptr;
|
||||
QtCodeFileList* list = createQtCodeFileList();
|
||||
list->addCodeSnippet(1, params.code, params.locationFile, params.activeTokenIds);
|
||||
list->show();
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
||||
{
|
||||
if (filePtr->getFileName() == fileName)
|
||||
{
|
||||
file = filePtr.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
QWidget* widget = QtViewWidgetWrapper::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.startLineNumber, params.code, params.locationFile, params.activeTokenIds);
|
||||
void QtCodeView::doAddCodeSnippet(const CodeSnippetParams& params)
|
||||
{
|
||||
getQtCodeFileList()->addCodeSnippet(params.startLineNumber, params.code, params.locationFile, params.activeTokenIds);
|
||||
}
|
||||
|
||||
void QtCodeView::doClearCodeSnippets()
|
||||
{
|
||||
m_files.clear();
|
||||
getQtCodeFileList()->clearCodeSnippets();
|
||||
}
|
||||
|
||||
void QtCodeView::setStyleSheet()
|
||||
QtCodeFileList* QtCodeView::getQtCodeFileList() const
|
||||
{
|
||||
return dynamic_cast<QtCodeFileList*>(QtViewWidgetWrapper::getWidgetOfView(this));
|
||||
}
|
||||
|
||||
QtCodeFileList* QtCodeView::createQtCodeFileList() const
|
||||
{
|
||||
QtCodeFileList* list = new QtCodeFileList();
|
||||
setStyleSheet(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
void QtCodeView::setStyleSheet(QWidget* widget) const
|
||||
{
|
||||
QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this);
|
||||
widget->setStyleSheet(TextAccess::createFromFile("data/gui/code_view/code_view.css")->getText().c_str());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#include "utility/types.h"
|
||||
|
||||
class QFrame;
|
||||
class QtCodeFile;
|
||||
class QtCodeFileList;
|
||||
class QWidget;
|
||||
|
||||
class QtCodeView: public CodeView
|
||||
{
|
||||
@@ -23,24 +24,25 @@ public:
|
||||
virtual void refreshView();
|
||||
|
||||
// CodeView implementation
|
||||
virtual void addCodeSnippet(const CodeSnippetParams params);
|
||||
virtual void showCodeFile(const CodeSnippetParams& params);
|
||||
virtual void addCodeSnippet(const CodeSnippetParams& params);
|
||||
virtual void clearCodeSnippets();
|
||||
|
||||
void activateToken(Id tokenId) const;
|
||||
|
||||
private:
|
||||
void doRefreshView();
|
||||
void doAddCodeSnippet(const CodeSnippetParams params);
|
||||
void doShowCodeFile(const CodeSnippetParams& params);
|
||||
void doAddCodeSnippet(const CodeSnippetParams& params);
|
||||
void doClearCodeSnippets();
|
||||
|
||||
void setStyleSheet();
|
||||
QtCodeFileList* getQtCodeFileList() const;
|
||||
QtCodeFileList* createQtCodeFileList() const;
|
||||
|
||||
std::shared_ptr<QFrame> m_frame;
|
||||
std::vector<std::shared_ptr<QtCodeFile> > m_files;
|
||||
void setStyleSheet(QWidget* widget) const;
|
||||
|
||||
QtThreadedFunctor<> m_refreshViewFunctor;
|
||||
QtThreadedFunctor<> m_clearCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams> m_addCodeSnippetFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_showCodeFileFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_addCodeSnippetFunctor;
|
||||
};
|
||||
|
||||
# endif // QT_CODE_VIEW_H
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "component/view/View.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
QWidget* QtViewWidgetWrapper::getWidgetOfView(View* view)
|
||||
QWidget* QtViewWidgetWrapper::getWidgetOfView(const View* view)
|
||||
{
|
||||
QtViewWidgetWrapper* widgetWrapper = dynamic_cast<QtViewWidgetWrapper*>(view->getWidgetWrapper());
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class View;
|
||||
class QtViewWidgetWrapper: public ViewWidgetWrapper
|
||||
{
|
||||
public:
|
||||
static QWidget* getWidgetOfView(View* view);
|
||||
static QWidget* getWidgetOfView(const View* view);
|
||||
|
||||
QtViewWidgetWrapper(std::shared_ptr<QWidget> widget);
|
||||
virtual ~QtViewWidgetWrapper();
|
||||
|
||||
Reference in New Issue
Block a user