ui: added maximize button to CodeSnippets that opens the full file in a separate window
This commit is contained in:
@@ -5,9 +5,8 @@
|
||||
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
|
||||
QtCodeFile::QtCodeFile(QtCodeView* parentView, const std::string& fileName, QWidget *parent)
|
||||
QtCodeFile::QtCodeFile(const std::string& fileName, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_parentView(parentView)
|
||||
, m_fileName(fileName)
|
||||
{
|
||||
setObjectName("code_file");
|
||||
@@ -42,8 +41,7 @@ void QtCodeFile::addCodeSnippet(
|
||||
const std::vector<Id>& activeTokenIds
|
||||
){
|
||||
std::shared_ptr<QtCodeSnippet> snippet(
|
||||
new QtCodeSnippet(m_parentView, startLineNumber, code, locationFile, activeTokenIds, this)
|
||||
);
|
||||
new QtCodeSnippet(startLineNumber, code, locationFile, activeTokenIds, this));
|
||||
layout()->addWidget(snippet.get());
|
||||
m_snippets.push_back(snippet);
|
||||
|
||||
|
||||
@@ -10,13 +10,12 @@
|
||||
#include "utility/types.h"
|
||||
|
||||
class QtCodeSnippet;
|
||||
class QtCodeView;
|
||||
class TokenLocationFile;
|
||||
|
||||
class QtCodeFile : public QWidget
|
||||
{
|
||||
public:
|
||||
QtCodeFile(QtCodeView* parentView, const std::string& fileName, QWidget *parent);
|
||||
QtCodeFile(const std::string& fileName, QWidget *parent = 0);
|
||||
virtual ~QtCodeFile();
|
||||
|
||||
const std::string& getFileName() const;
|
||||
@@ -29,7 +28,6 @@ public:
|
||||
);
|
||||
|
||||
private:
|
||||
QtCodeView* m_parentView;
|
||||
std::vector<std::shared_ptr<QtCodeSnippet> > m_snippets;
|
||||
const std::string m_fileName;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "qt/element/QtCodeFileList.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "utility/FileSystem.h"
|
||||
|
||||
QtCodeFileList::QtCodeFileList(QWidget* parent)
|
||||
: QScrollArea(parent)
|
||||
{
|
||||
m_frame = std::make_shared<QFrame>(this);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(m_frame.get());
|
||||
layout->setSpacing(10);
|
||||
layout->setContentsMargins(15, 15, 15, 15);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
m_frame->setLayout(layout);
|
||||
|
||||
setWidgetResizable(true);
|
||||
setWidget(m_frame.get());
|
||||
|
||||
setObjectName("code_file_list");
|
||||
}
|
||||
|
||||
QtCodeFileList::~QtCodeFileList()
|
||||
{
|
||||
}
|
||||
|
||||
void QtCodeFileList::addCodeSnippet(
|
||||
int startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds
|
||||
){
|
||||
std::string fileName = FileSystem::fileName(locationFile.getFilePath());
|
||||
QtCodeFile* file = nullptr;
|
||||
|
||||
for (std::shared_ptr<QtCodeFile> filePtr : m_files)
|
||||
{
|
||||
if (filePtr->getFileName() == fileName)
|
||||
{
|
||||
file = filePtr.get();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(fileName, this);
|
||||
m_files.push_back(filePtr);
|
||||
|
||||
file = filePtr.get();
|
||||
m_frame->layout()->addWidget(file);
|
||||
}
|
||||
|
||||
file->addCodeSnippet(startLineNumber, code, locationFile, activeTokenIds);
|
||||
}
|
||||
|
||||
void QtCodeFileList::clearCodeSnippets()
|
||||
{
|
||||
m_files.clear();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef QT_CODE_FILE_LIST
|
||||
#define QT_CODE_FILE_LIST
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <QFrame>
|
||||
#include <QScrollArea>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class QtCodeFile;
|
||||
class TokenLocationFile;
|
||||
|
||||
class QtCodeFileList: public QScrollArea
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtCodeFileList(QWidget* parent = 0);
|
||||
virtual ~QtCodeFileList();
|
||||
|
||||
void addCodeSnippet(
|
||||
int startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
const std::vector<Id>& activeTokenIds
|
||||
);
|
||||
|
||||
void clearCodeSnippets();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QFrame> m_frame;
|
||||
std::vector<std::shared_ptr<QtCodeFile> > m_files;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_FILE_LIST
|
||||
@@ -1,14 +1,17 @@
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QtWidgets>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "ApplicationSettings.h"
|
||||
#include "data/location/TokenLocation.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "data/location/TokenLocationLine.h"
|
||||
#include "qt/utility/QtHighLighter.h"
|
||||
#include "qt/view/QtCodeView.h"
|
||||
#include "utility/messaging/type/MessageActivateToken.h"
|
||||
#include "utility/messaging/type/MessageShowFile.h"
|
||||
|
||||
QtCodeSnippet::LineNumberArea::LineNumberArea(QtCodeSnippet *codeSnippet)
|
||||
: QWidget(codeSnippet)
|
||||
@@ -33,7 +36,6 @@ void QtCodeSnippet::LineNumberArea::paintEvent(QPaintEvent *event)
|
||||
|
||||
|
||||
QtCodeSnippet::QtCodeSnippet(
|
||||
QtCodeView* parentView,
|
||||
int startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
@@ -41,10 +43,10 @@ QtCodeSnippet::QtCodeSnippet(
|
||||
QWidget *parent
|
||||
)
|
||||
: QPlainTextEdit(parent)
|
||||
, m_parentView(parentView)
|
||||
, m_startLineNumber(startLineNumber)
|
||||
, m_activeTokenIds(activeTokenIds)
|
||||
, m_digits(0)
|
||||
, m_filePath(locationFile.getFilePath())
|
||||
{
|
||||
setObjectName("code_snippet");
|
||||
m_lineNumberArea = new LineNumberArea(this);
|
||||
@@ -66,9 +68,22 @@ QtCodeSnippet::QtCodeSnippet(
|
||||
setPlainText(QString::fromUtf8(displayCode.c_str()));
|
||||
annotateText(locationFile);
|
||||
|
||||
QHBoxLayout* layout = new QHBoxLayout();
|
||||
layout->setMargin(0);
|
||||
layout->setSpacing(0);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
setLayout(layout);
|
||||
|
||||
m_maximizeButton = new QPushButton(this);
|
||||
m_maximizeButton->setObjectName("maximize_button");
|
||||
m_maximizeButton->setEnabled(false);
|
||||
layout->addWidget(m_maximizeButton);
|
||||
layout->setAlignment(m_maximizeButton, Qt::AlignRight);
|
||||
connect(m_maximizeButton, SIGNAL(clicked()), this, SLOT(clickedMaximizeButton()));
|
||||
|
||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(clickTokenLocation()));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(clickedTokenLocation()));
|
||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection()));
|
||||
|
||||
m_digits = lineNumberDigits();
|
||||
@@ -213,6 +228,16 @@ void QtCodeSnippet::showEvent(QShowEvent* event)
|
||||
setMaximumHeight(sizeHint().height());
|
||||
}
|
||||
|
||||
void QtCodeSnippet::enterEvent(QEvent* event)
|
||||
{
|
||||
m_maximizeButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void QtCodeSnippet::leaveEvent(QEvent* event)
|
||||
{
|
||||
m_maximizeButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void QtCodeSnippet::updateLineNumberAreaWidth(int /* newBlockCount */)
|
||||
{
|
||||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
|
||||
@@ -235,7 +260,7 @@ void QtCodeSnippet::updateLineNumberArea(const QRect &rect, int dy)
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::clickTokenLocation()
|
||||
void QtCodeSnippet::clickedTokenLocation()
|
||||
{
|
||||
int clickPosition = textCursor().position();
|
||||
int diff = endTextEditPosition() + 1;
|
||||
@@ -256,10 +281,15 @@ void QtCodeSnippet::clickTokenLocation()
|
||||
|
||||
if (tokenId)
|
||||
{
|
||||
m_parentView->activateToken(tokenId);
|
||||
MessageActivateToken(tokenId).dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeSnippet::clickedMaximizeButton()
|
||||
{
|
||||
MessageShowFile(m_filePath, m_startLineNumber, m_activeTokenIds).dispatch();
|
||||
}
|
||||
|
||||
void QtCodeSnippet::clearSelection()
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
#include "utility/types.h"
|
||||
|
||||
class QPaintEvent;
|
||||
class QPushButton;
|
||||
class QResizeEvent;
|
||||
class QSize;
|
||||
class QtCodeView;
|
||||
class QtHighlighter;
|
||||
class QWidget;
|
||||
class TokenLocationFile;
|
||||
@@ -29,14 +29,13 @@ public:
|
||||
QSize sizeHint() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void paintEvent(QPaintEvent* event);
|
||||
|
||||
private:
|
||||
QtCodeSnippet *m_codeSnippet;
|
||||
};
|
||||
|
||||
QtCodeSnippet(
|
||||
QtCodeView* parentView,
|
||||
int startLineNumber,
|
||||
const std::string& code,
|
||||
const TokenLocationFile& locationFile,
|
||||
@@ -57,11 +56,14 @@ public:
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
virtual void showEvent(QShowEvent* event);
|
||||
virtual void enterEvent(QEvent* event);
|
||||
virtual void leaveEvent(QEvent* event);
|
||||
|
||||
private slots:
|
||||
void updateLineNumberAreaWidth(int newBlockCount);
|
||||
void updateLineNumberArea(const QRect &, int);
|
||||
void clickTokenLocation();
|
||||
void clickedTokenLocation();
|
||||
void clickedMaximizeButton();
|
||||
void clearSelection();
|
||||
|
||||
private:
|
||||
@@ -76,15 +78,17 @@ private:
|
||||
int startTextEditPosition() const;
|
||||
int endTextEditPosition() const;
|
||||
|
||||
QtCodeView* m_parentView;
|
||||
QtHighlighter* m_highlighter;
|
||||
|
||||
QWidget *m_lineNumberArea;
|
||||
QWidget* m_lineNumberArea;
|
||||
QPushButton* m_maximizeButton;
|
||||
|
||||
const int m_startLineNumber;
|
||||
const std::vector<Id> m_activeTokenIds;
|
||||
std::vector<Annotation> m_annotations;
|
||||
int m_digits;
|
||||
|
||||
std::vector<Annotation> m_annotations;
|
||||
const std::string m_filePath;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_SNIPPET_H
|
||||
|
||||
Reference in New Issue
Block a user