Skip to content

Commit

Permalink
new GUI (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeryStk authored Nov 18, 2024
1 parent 6b8fe81 commit 8f48b58
Show file tree
Hide file tree
Showing 19 changed files with 997 additions and 61 deletions.
2 changes: 1 addition & 1 deletion common_utils/common_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool make_string(const string& src,

int find_separator(const std::string& src,
char& separator) {
std::vector<char> ignored_chars = {'+', '-', 'e', '.', '\r', ','};
std::vector<char> ignored_chars = {'+', '-', 'e', 'E', '.', '\r', ','};
std::set<char> unique_chars;
bool is_service_char = false;
bool is_dot_present = false;
Expand Down
106 changes: 105 additions & 1 deletion davis_one/davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,79 @@ const char kNoFileFoundedPage[] = R"(<!DOCTYPE html>

extern const char kWarningIcon[] = R"davis_delimeter(<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 156.262 144.407"><path d="M-109.166 7.227a2 2 0 0 0-.406.046c-3.195.03-6.176 1.695-7.785 4.483l-31.25 54.127-31.25 54.127h.002c-3.42 5.922 1.017 13.609 7.855 13.61h125.002c6.839-.001 11.277-7.688 7.857-13.61l-31.25-54.127-31.252-54.127c-1.465-2.539-4.079-4.164-6.978-4.45a2 2 0 0 0-.445-.077h-.004a2.006 2.006 0 0 0-.094-.002z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fff" d="M-109.165 9.227a7.081 7.081 0 0 0-6.46 3.529l-31.25 54.127-31.25 54.127c-2.674 4.631.777 10.609 6.126 10.61h125.002c5.348-.001 8.8-5.979 6.125-10.61l-31.25-54.127-31.252-54.127a7.079 7.079 0 0 0-5.79-3.53h-.001z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path d="M-109.26 11.225a5.073 5.073 0 0 0-4.632 2.53l-31.25 54.128-31.25 54.127c-1.953 3.381.488 7.609 4.393 7.61h125.002c3.905-.001 6.345-4.229 4.392-7.61l-31.25-54.127-31.252-54.127a5.073 5.073 0 0 0-4.152-2.531z" color="#000" style="solid-color:#000" transform="translate(186.615 2.437) scale(.99073)"/><path fill="#fc0" d="M140.053 125.83H16.209L47.17 72.204l30.961-53.626 30.961 53.626z"/><g transform="translate(.295 2.437) scale(.99073)"><circle cx="78.564" cy="111.117" r="8.817"/><path d="M78.564 42.955a8.817 8.817 0 0 0-8.818 8.816l3.156 37.461a5.662 5.662 0 0 0 11.325 0l3.154-37.46a8.817 8.817 0 0 0-8.817-8.817z"/></g></svg>)davis_delimeter";



extern const char kHtmlDateTimeModel[] = R"davis_delimeter(
<head>
<script src="%1" charset="utf-8"></script>
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
id="gd"></div></div>
<script>
var data = [
{
x: [%2],
y: [%3],
type: 'scatter'
}
];
var config = {
editable: true,
showLink: true,
plotlyServerURL: "https://chart-studio.plotly.com"
};
Plotly.newPlot('gd', data);
</script>
</body>
)davis_delimeter";



extern const char kHtmlMultiChartBlock[] = R"davis_delimeter(
var trace%1 = {
x: [%2],
y: [%3],
type: 'scatter'
};
)davis_delimeter";




extern const char kHtmlMultiChartModel[] = R"davis_delimeter(
<head>
<script src="%1" charset="utf-8"></script>
</head>
<body><div style = "display: flex;
align-items:center;height:100%; width:100%;background:#dddfd4;
justify-content: center;"><div style="height:95%; aspect-ratio: 1/1;"
id="gd"></div></div>
<script>
%2
var data = [%3];
var config = {
editable: true,
showLink: true,
plotlyServerURL: "https://chart-studio.plotly.com"
};
Plotly.newPlot('gd', data);
</script>
</body>
)davis_delimeter";


// *INDENT-ON*

} // namespace dvs end
Expand Down Expand Up @@ -584,7 +657,7 @@ bool make_string(const string& src,

int find_separator(const std::string& src,
char& separator) {
std::vector<char> ignored_chars = {'+', '-', 'e', '.', '\r', ','};
std::vector<char> ignored_chars = {'+', '-', 'e', 'E', '.', '\r', ','};
std::set<char> unique_chars;
bool is_service_char = false;
bool is_dot_present = false;
Expand Down Expand Up @@ -990,6 +1063,37 @@ void showMatrixSizesAreNotTheSame(int badRow) {
text);
}

void showDateTimeChart(const string& date_time_values,
const vector<double>& yValues) {

string out;
string davis_dir;
#ifdef _WIN32
davis_dir = "\\davis_htmls";
#elif __linux__
davis_dir = "/davis_htmls";
#endif
vector<string>args {ARGS_DATE_TIME_PAGE_SIZE, ""};
args[ARG_JS_NAME] = kPlotlyJsName;
args[ARG_DATE_TIME_VALUES] = date_time_values;

std::string values;
for (size_t i = 0; i < yValues.size(); ++i) {
std::string value = std::to_string(yValues[i]);
values.append(value);
if (i != yValues.size() - 1) {
values.append(",");
}
}

args[ARG_Y_DATE_TIME_VALUES] = values;
make_string(kHtmlDateTimeModel, args, out);
saveStringToFile(kReportPagePath, out);
openFileBySystem(kReportPagePath);


}


} // namespace dvs end

26 changes: 26 additions & 0 deletions davis_one/davis.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,22 @@ enum ARGS_REPORT_PAGE_INDEX {
ARGS_REPORT_PAGE_SIZE
};

enum ARGS_DATE_TIME_PAGE_INDEX {
ARG_JS_NAME, //%1
ARG_DATE_TIME_VALUES, //%2
ARG_Y_DATE_TIME_VALUES, //%3
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_DATE_TIME_PAGE_SIZE
};

enum ARGS_MULTI_CHARTS_PAGE {
ARG_JS_MC_NAME,
ARG_TRACES_BLOCKS,
ARG_DATA_OF_TRACES,
// ADD NEW ENUM BEFORE THIS COMMENT
ARGS_MULTI_CHARTS_PAGE_SIZE
};


extern const char kHtmlModel[];
extern const char kColorMapDefaultPart[];
Expand All @@ -160,6 +176,13 @@ extern const char kNoFileFoundedPage[];

extern const char kWarningIcon[];

extern const char kHtmlDateTimeModel[];


extern const char kHtmlMultiChartBlock[];
extern const char kHtmlMultiChartModel[];


} // namespace dvs end

namespace dvs {
Expand Down Expand Up @@ -332,6 +355,9 @@ void showReportFileEmpty();

void showMatrixSizesAreNotTheSame(int badRow);

void showDateTimeChart(const string& date_time_values,
const vector<double>& yValues);


} // namespace dvs end

Expand Down
4 changes: 4 additions & 0 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ set(PROJECT_SOURCES
davis_gui.h
about_window.h
about_window.cpp
animated_button.h
animated_button.cpp
davis_gui.ui
about_window.ui
json_utils.h
json_utils.cpp
)

qt5_add_resources(PROJECT_SOURCES res.qrc)
Expand Down
2 changes: 1 addition & 1 deletion gui/about_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QLabel" name="label_wiki">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Read documentation at our &lt;/span&gt;&lt;a href=&quot;https://github.com/DevToolsOrganization/matrix-data-visualization-DAVIS/wiki&quot;&gt;&lt;span style=&quot; font-size:12pt; text-decoration: underline; color:#75bcff;&quot;&gt;WIKI&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-size:12pt;&quot;&gt;Read &lt;/span&gt;&lt;a href=&quot;https://devtoolsorganization.github.io/matrix-data-visualization-DAVIS/#/&quot;&gt;&lt;span style=&quot; font-size:12pt; text-decoration: underline; color:#75bcff;&quot;&gt;online documentation&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
Expand Down
74 changes: 74 additions & 0 deletions gui/animated_button.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "animated_button.h"
#include <QTimer>
#include <QDebug>
#include <QPropertyAnimation>

QString buttonStyle(
"QPushButton {"
" background-color: %1;"
" border: none;"
" color:white;" // text color
" text-align: center;"
" font-size: 13px;"
" border-radius: 14px;"
"}"
);


AnimatedButton::AnimatedButton(const QString& text, QColor startColor, QColor endColor, QWidget* parent) : QPushButton(text, parent) {
setStyleSheet(buttonStyle.arg(startColor.name()));
m_startColor = startColor;
m_endColor = endColor;
connect(this, &QPushButton::pressed, this, &AnimatedButton::animateButtonPress);
connect(this, &QPushButton::released, this, &AnimatedButton::animateButtonRelease);
}

void AnimatedButton::enterEvent(QEvent* event) {
QPropertyAnimation* animation = new QPropertyAnimation(this, "backgroundColor");
animation->setDuration(250);
animation->setStartValue(m_startColor);
animation->setEndValue(m_endColor);
animation->start(QAbstractAnimation::DeleteWhenStopped);
QPushButton::enterEvent(event);
QPushButton::enterEvent(event);
}

void AnimatedButton::leaveEvent(QEvent* event) {
QPropertyAnimation* animation = new QPropertyAnimation(this, "backgroundColor");
animation->setDuration(250);
animation->setStartValue(m_endColor);
animation->setEndValue(m_startColor);
animation->start(QAbstractAnimation::DeleteWhenStopped);
QPushButton::leaveEvent(event);
}

void AnimatedButton::animateButtonPress() {
QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(100);
animation->setStartValue(geometry());
animation->setEndValue(QRect(m_originalGeometry.x(), m_originalGeometry.y() + 5,
m_originalGeometry.width(), m_originalGeometry.height()));
animation->start(QAbstractAnimation::DeleteWhenStopped);
}

void AnimatedButton::animateButtonRelease() {
QPropertyAnimation* animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(100);
animation->setStartValue(geometry());
animation->setEndValue(m_originalGeometry);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}


void AnimatedButton::setOriginalGeometry(const QRect& newOriginalGeometry) {
m_originalGeometry = newOriginalGeometry;
}

QColor AnimatedButton::backgroundColor() const {
return m_backgroundColor;
}

void AnimatedButton::setBackgroundColor(const QColor& color) {
m_backgroundColor = color;
setStyleSheet(buttonStyle.arg(color.name()));
}
42 changes: 42 additions & 0 deletions gui/animated_button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef ANIMATED_BUTTON_H
#define ANIMATED_BUTTON_H
#include <QApplication>
#include <QPushButton>
#include <QPropertyAnimation>
#include <QGraphicsColorizeEffect>
#include <QEvent>

class AnimatedButton : public QPushButton {
Q_OBJECT
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)

public:
AnimatedButton(const QString& text, QColor startColor, QColor endColor, QWidget* parent = nullptr);

void setOriginalGeometry(const QRect& newOriginalGeometry);

QColor backgroundColor() const;

void setBackgroundColor(const QColor& color);

protected:
void enterEvent(QEvent* event) override;

void leaveEvent(QEvent* event) override;

private slots:
void animateButtonPress();

void animateButtonRelease();

private:
QColor m_startColor;
QColor m_endColor;
QColor m_backgroundColor;
QRect m_originalGeometry;
};




#endif // ANIMATED_BUTTON_H
6 changes: 6 additions & 0 deletions gui/date_time_formats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"dd/MM/yyyy hh:mm",
"yyyy/MM/dd hh:mm:ss",
"yyyy.MM.dd_hh:mm:ss",
"yyyy/MM/dd hh_mm_ss"
]
Loading

0 comments on commit 8f48b58

Please sign in to comment.