ui: improved ui of maximized code file window
* Annotations updated when active token Id changes * FileName in window title * Maximize button not shown * Scrolls roughly to the maximized location. * Maximizing also on double click in code snippet
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "qt/view/QtCodeView.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "qt/element/QtCodeFileList.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
#include "utility/FileSystem.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
@@ -11,6 +14,7 @@ QtCodeView::QtCodeView(ViewLayout* viewLayout)
|
||||
, m_showCodeFileFunctor(std::bind(&QtCodeView::doShowCodeFile, this, std::placeholders::_1))
|
||||
, m_addCodeSnippetFunctor(std::bind(&QtCodeView::doAddCodeSnippet, this, std::placeholders::_1))
|
||||
{
|
||||
m_widget = createQtCodeFileList();
|
||||
}
|
||||
|
||||
QtCodeView::~QtCodeView()
|
||||
@@ -19,9 +23,7 @@ QtCodeView::~QtCodeView()
|
||||
|
||||
void QtCodeView::createWidgetWrapper()
|
||||
{
|
||||
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(
|
||||
std::shared_ptr<QtCodeFileList>(createQtCodeFileList())
|
||||
));
|
||||
setWidgetWrapper(std::make_shared<QtViewWidgetWrapper>(m_widget));
|
||||
}
|
||||
|
||||
void QtCodeView::initView()
|
||||
@@ -50,39 +52,69 @@ void QtCodeView::clearCodeSnippets()
|
||||
|
||||
void QtCodeView::doRefreshView()
|
||||
{
|
||||
setStyleSheet(getQtCodeFileList());
|
||||
setStyleSheet(m_widget.get());
|
||||
|
||||
clearClosedWindows();
|
||||
for (std::shared_ptr<QtCodeFileList> window: m_windows)
|
||||
{
|
||||
setStyleSheet(window.get());
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
|
||||
{
|
||||
QtCodeFileList* list = createQtCodeFileList();
|
||||
list->addCodeSnippet(1, params.code, params.locationFile, params.activeTokenIds);
|
||||
list->show();
|
||||
std::shared_ptr<QtCodeFileList> ptr = createQtCodeFileList();
|
||||
m_windows.push_back(ptr);
|
||||
|
||||
ptr->setShowMaximizeButton(false);
|
||||
ptr->addCodeSnippet(1, params.code, params.locationFile, params.activeTokenIds);
|
||||
|
||||
ptr->setWindowTitle(FileSystem::fileName(params.locationFile.getFilePath()).c_str());
|
||||
ptr->show();
|
||||
|
||||
float percent = float(params.startLineNumber + params.endLineNumber) / float(params.lineCount) / 2;
|
||||
float min = ptr->verticalScrollBar()->minimum();
|
||||
float max = ptr->verticalScrollBar()->maximum();
|
||||
|
||||
ptr->verticalScrollBar()->setValue(min + (max - min) * percent);
|
||||
}
|
||||
|
||||
void QtCodeView::doAddCodeSnippet(const CodeSnippetParams& params)
|
||||
{
|
||||
getQtCodeFileList()->addCodeSnippet(params.startLineNumber, params.code, params.locationFile, params.activeTokenIds);
|
||||
m_widget->addCodeSnippet(params.startLineNumber, params.code, params.locationFile, params.activeTokenIds);
|
||||
|
||||
clearClosedWindows();
|
||||
for (std::shared_ptr<QtCodeFileList> window: m_windows)
|
||||
{
|
||||
window->setActiveTokenIds(params.activeTokenIds);
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeView::doClearCodeSnippets()
|
||||
{
|
||||
getQtCodeFileList()->clearCodeSnippets();
|
||||
m_widget->clearCodeSnippets();
|
||||
}
|
||||
|
||||
QtCodeFileList* QtCodeView::getQtCodeFileList() const
|
||||
std::shared_ptr<QtCodeFileList> QtCodeView::createQtCodeFileList() const
|
||||
{
|
||||
return dynamic_cast<QtCodeFileList*>(QtViewWidgetWrapper::getWidgetOfView(this));
|
||||
}
|
||||
|
||||
QtCodeFileList* QtCodeView::createQtCodeFileList() const
|
||||
{
|
||||
QtCodeFileList* list = new QtCodeFileList();
|
||||
setStyleSheet(list);
|
||||
return list;
|
||||
std::shared_ptr<QtCodeFileList> ptr = std::make_shared<QtCodeFileList>();
|
||||
setStyleSheet(ptr.get());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void QtCodeView::setStyleSheet(QWidget* widget) const
|
||||
{
|
||||
widget->setStyleSheet(TextAccess::createFromFile("data/gui/code_view/code_view.css")->getText().c_str());
|
||||
}
|
||||
|
||||
void QtCodeView::clearClosedWindows()
|
||||
{
|
||||
for (size_t i = 0; i < m_windows.size(); i++)
|
||||
{
|
||||
if (!m_windows[i]->isVisible())
|
||||
{
|
||||
m_windows.erase(m_windows.begin() + i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,15 +34,19 @@ private:
|
||||
void doAddCodeSnippet(const CodeSnippetParams& params);
|
||||
void doClearCodeSnippets();
|
||||
|
||||
QtCodeFileList* getQtCodeFileList() const;
|
||||
QtCodeFileList* createQtCodeFileList() const;
|
||||
std::shared_ptr<QtCodeFileList> createQtCodeFileList() const;
|
||||
|
||||
void setStyleSheet(QWidget* widget) const;
|
||||
|
||||
void clearClosedWindows();
|
||||
|
||||
QtThreadedFunctor<> m_refreshViewFunctor;
|
||||
QtThreadedFunctor<> m_clearCodeSnippetsFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_showCodeFileFunctor;
|
||||
QtThreadedFunctor<const CodeSnippetParams&> m_addCodeSnippetFunctor;
|
||||
|
||||
std::shared_ptr<QtCodeFileList> m_widget;
|
||||
std::vector<std::shared_ptr<QtCodeFileList>> m_windows;
|
||||
};
|
||||
|
||||
# endif // QT_CODE_VIEW_H
|
||||
|
||||
Reference in New Issue
Block a user