-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: IonutMuthi <[email protected]>
- Loading branch information
1 parent
72ef3a8
commit a2a08fe
Showing
14 changed files
with
757 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,5 @@ function disconnect(){ | |
scopy.disconnectDevice() | ||
exit(0) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include/scripting/scopy-scripting_export.h | ||
include/scripting/scopy-scripting_config.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
|
||
set(SCOPY_MODULE scripting) | ||
|
||
message(STATUS "building plugin: " ${SCOPY_MODULE}) | ||
|
||
project(scopy-${SCOPY_MODULE} VERSION 0.1 LANGUAGES CXX) | ||
|
||
set(PLUGIN_DISPLAY_NAME "Scripting") | ||
set(PLUGIN_DESCRIPTION ""THIS TOOL IS USED FOR RUNNING SCPITS USING API CALLS FROM SCOPY"") | ||
|
||
include(GenerateExportHeader) | ||
|
||
# TODO: split stylesheet/resources and add here TODO: export header files correctly | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/ui) | ||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
|
||
set(CMAKE_CXX_VISIBILITY_PRESET hidden) | ||
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) | ||
|
||
file(GLOB SRC_LIST src/*.cpp src/*.cc) | ||
file(GLOB HEADER_LIST include/${SCOPY_MODULE}/*.h include/${SCOPY_MODULE}/*.hpp) | ||
file(GLOB UI_LIST ui/*.ui) | ||
|
||
set(ENABLE_TESTING ON) | ||
if(ENABLE_TESTING) | ||
add_subdirectory(test) | ||
endif() | ||
|
||
set(PROJECT_SOURCES ${SRC_LIST} ${HEADER_LIST} ${UI_LIST}) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED Widgets Core) | ||
|
||
qt_add_resources(PROJECT_RESOURCES res/resources.qrc) | ||
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES}) | ||
|
||
generate_export_header( | ||
${PROJECT_NAME} EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_export.h | ||
) | ||
|
||
configure_file( | ||
include/${SCOPY_MODULE}/scopy-${SCOPY_MODULE}_config.h.cmakein | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/scopy-${SCOPY_MODULE}_config.h @ONLY | ||
) | ||
|
||
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}) | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC scopy-pluginbase scopy-gui) | ||
|
||
target_link_libraries( | ||
${PROJECT_NAME} | ||
PUBLIC Qt::Widgets | ||
Qt::Core | ||
scopy-pluginbase | ||
scopy-gui | ||
scopy-iioutil | ||
) | ||
|
||
|
||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||
configureinstallersettings(${SCOPY_MODULE} ${PLUGIN_DESCRIPTION} FALSE) | ||
endif() | ||
|
||
set(scripting_TARGET_NAME ${PROJECT_NAME} PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef SCRIPTING_H | ||
#define SCRIPTING_H | ||
|
||
#define SCOPY_PLUGIN_NAME Scripting | ||
|
||
#include "scopy-scripting_export.h" | ||
#include <QObject> | ||
#include <pluginbase/plugin.h> | ||
#include <pluginbase/pluginbase.h> | ||
|
||
namespace scopy { | ||
namespace scripting { | ||
|
||
class SCOPY_SCRIPTING_EXPORT Scripting : public QObject, public PluginBase | ||
{ | ||
Q_OBJECT | ||
SCOPY_PLUGIN; | ||
|
||
public: | ||
bool compatible(QString m_param, QString category) override; | ||
bool loadPage() override; | ||
bool loadIcon() override; | ||
void loadToolList() override; | ||
void unload() override; | ||
void initMetadata() override; | ||
QString description() override; | ||
|
||
QWidget *getTool(); | ||
|
||
public Q_SLOTS: | ||
bool onConnect() override; | ||
bool onDisconnect() override; | ||
|
||
private: | ||
QWidget *m_scriptingWidget = nullptr; | ||
}; | ||
} // namespace scripting | ||
} // namespace scopy | ||
#endif // SCRIPTING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "scopycodeeditor.h" | ||
|
||
#include <QPainter> | ||
#include <QTextBlock> | ||
#include <style.h> | ||
|
||
using namespace scopy; | ||
using namespace scripting; | ||
|
||
ScopyCodeEditor::ScopyCodeEditor(QWidget *parent) | ||
: QPlainTextEdit{parent} | ||
{ | ||
lineNumberArea = new LineNumberArea(this); | ||
|
||
connect(this, &ScopyCodeEditor::blockCountChanged, this, &ScopyCodeEditor::updateLineNumberAreaWidth); | ||
connect(this, &ScopyCodeEditor::updateRequest, this, &ScopyCodeEditor::updateLineNumberArea); | ||
connect(this, &ScopyCodeEditor::cursorPositionChanged, this, &ScopyCodeEditor::highlightCurrentLine); | ||
|
||
updateLineNumberAreaWidth(0); | ||
highlightCurrentLine(); | ||
} | ||
|
||
void ScopyCodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event) | ||
{ | ||
QPainter painter(lineNumberArea); | ||
painter.fillRect(event->rect(), Qt::lightGray); | ||
QTextBlock block = firstVisibleBlock(); | ||
int blockNumber = block.blockNumber(); | ||
int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top()); | ||
int bottom = top + qRound(blockBoundingRect(block).height()); | ||
while (block.isValid() && top <= event->rect().bottom()) { | ||
if (block.isVisible() && bottom >= event->rect().top()) { | ||
QString number = QString::number(blockNumber + 1); | ||
painter.setPen(Qt::black); | ||
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(), | ||
Qt::AlignRight, number); | ||
} | ||
|
||
block = block.next(); | ||
top = bottom; | ||
bottom = top + qRound(blockBoundingRect(block).height()); | ||
++blockNumber; | ||
} | ||
} | ||
|
||
int ScopyCodeEditor::lineNumberAreaWidth() | ||
{ | ||
int digits = 1; | ||
int max = qMax(1, blockCount()); | ||
while (max >= 10) { | ||
max /= 10; | ||
++digits; | ||
} | ||
|
||
int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits; | ||
|
||
return space; | ||
} | ||
|
||
void ScopyCodeEditor::resizeEvent(QResizeEvent *event) | ||
{ | ||
QPlainTextEdit::resizeEvent(event); | ||
QRect cr = contentsRect(); | ||
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height())); | ||
} | ||
|
||
void ScopyCodeEditor::updateLineNumberAreaWidth(int newBlockCount) | ||
{ | ||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0); | ||
} | ||
|
||
void ScopyCodeEditor::highlightCurrentLine() | ||
{ | ||
QList<QTextEdit::ExtraSelection> extraSelections; | ||
|
||
if (!isReadOnly()) { | ||
QTextEdit::ExtraSelection selection; | ||
|
||
QColor lineColor = Style::getColor(json::theme::interactive_subtle_hover); | ||
|
||
selection.format.setBackground(lineColor); | ||
selection.format.setProperty(QTextFormat::FullWidthSelection, true); | ||
selection.cursor = textCursor(); | ||
selection.cursor.clearSelection(); | ||
extraSelections.append(selection); | ||
} | ||
|
||
setExtraSelections(extraSelections); | ||
} | ||
|
||
void ScopyCodeEditor::updateLineNumberArea(const QRect &rect, int dy) | ||
{ | ||
if (dy) | ||
lineNumberArea->scroll(0, dy); | ||
else | ||
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); | ||
|
||
if (rect.contains(viewport()->rect())) | ||
updateLineNumberAreaWidth(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef SCOPYCODEEDITOR_H | ||
#define SCOPYCODEEDITOR_H | ||
|
||
#include <QPlainTextEdit> | ||
|
||
namespace scopy { | ||
namespace scripting { | ||
|
||
class ScopyCodeEditor : public QPlainTextEdit | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit ScopyCodeEditor(QWidget *parent = nullptr); | ||
|
||
void lineNumberAreaPaintEvent(QPaintEvent *event); | ||
int lineNumberAreaWidth(); | ||
|
||
protected: | ||
void resizeEvent(QResizeEvent *event) override; | ||
|
||
private slots: | ||
void updateLineNumberAreaWidth(int newBlockCount); | ||
void highlightCurrentLine(); | ||
void updateLineNumberArea(const QRect &rect, int dy); | ||
|
||
private: | ||
QWidget *lineNumberArea; | ||
}; | ||
|
||
|
||
class LineNumberArea : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
LineNumberArea(ScopyCodeEditor *editor) : QWidget(editor), codeEditor(editor) | ||
{} | ||
|
||
QSize sizeHint() const override | ||
{ | ||
return QSize(codeEditor->lineNumberAreaWidth(), 0); | ||
} | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event) override | ||
{ | ||
codeEditor->lineNumberAreaPaintEvent(event); | ||
} | ||
|
||
private: | ||
ScopyCodeEditor *codeEditor; | ||
}; | ||
|
||
|
||
} // namespace scripting | ||
} // namespace scopy | ||
#endif // SCOPYCODEEDITOR_H |
Oops, something went wrong.