mirror of
https://github.com/Linloir/GraphBuilder.git
synced 2025-12-18 20:48:12 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e965427be4 | |||
| 629698c05c | |||
| 06fb056c09 | |||
| 6309cce382 | |||
| 5a5a3541bf | |||
| 002b291023 | |||
|
|
c2059dad4b | ||
| 354da102e5 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,6 +15,7 @@ object_script.*.Debug
|
|||||||
*_plugin_import.cpp
|
*_plugin_import.cpp
|
||||||
/.qmake.cache
|
/.qmake.cache
|
||||||
/.qmake.stash
|
/.qmake.stash
|
||||||
|
/build
|
||||||
*.pro.user
|
*.pro.user
|
||||||
*.pro.user.*
|
*.pro.user.*
|
||||||
*.qbs.user
|
*.qbs.user
|
||||||
|
|||||||
181
GraphBuilder_Commentary.md
Normal file
181
GraphBuilder_Commentary.md
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
# 从头开始完成GraphBuilder工程
|
||||||
|
|
||||||
|
## 实验要求
|
||||||
|
|
||||||
|
1. 以邻接多重表为存储结构,实现联通无向图的深度优先和广度优先遍历。以指定的节点为起点,分别输出每种遍历下的节点访问序列和相应生成树的边集。
|
||||||
|
2. 以邻接表为存储结构,建立深度优先生成树和广度优先生成树,并以树型输出生成树。
|
||||||
|
3. 测试数据如图:
|
||||||
|
|
||||||
|
## 分析需求
|
||||||
|
|
||||||
|
> 在本节中将分析上述题目要求,大致明确程序所需要完成的模块及功能
|
||||||
|
|
||||||
|
由于需要以树型输出生成树,因此最好能够实现**可视化控件**,其需要支持显示图结构
|
||||||
|
|
||||||
|
为了便于添加点和线,故可视化控件需要支持**添加及删除点和线**的功能
|
||||||
|
|
||||||
|
从测试数据图中看出,输入的数据为带权图,因此对于该控件还需要实现**添加及修改权重**的功能
|
||||||
|
|
||||||
|
由于需要进行遍历,为了体现遍历过程,该控件需要实现**创建节点和边的访问动画**功能
|
||||||
|
|
||||||
|
在数据结构层面,需要实现**邻接表**和**邻接多重表**两种数据结构
|
||||||
|
|
||||||
|
为了避免演示时不同数据结构需要分开建立测试数据,因此需要为两种不同的数据结构实现一个**虚基类**,并使两种不同的结构均从该虚基类继承并添加**转换函数**,实现两种不同数据结构的互相转换
|
||||||
|
|
||||||
|
## 程序设计
|
||||||
|
|
||||||
|
> 在本节中,将依据上述需求,对各个需要实现的模块进行更进一步的分析,并给出其实现的过程
|
||||||
|
|
||||||
|
从上述需求可以看出,实现最基本的功能大致需要将程序分为两个主要部分:
|
||||||
|
|
||||||
|
- **可视化控件**:类画板控件,负责处理图中点和线的元素对象的显示、修改等操作,并为数据结构提供功能接口,诸如调用动画等
|
||||||
|
- **数据结构**:需要使用要求的数据结构类将上述可视化控件中的元素对象组织起来,并调用其提供的接口实现如深度优先遍历等功能
|
||||||
|
|
||||||
|
下面将依次完成这两个主要部分
|
||||||
|
|
||||||
|
### 可视化控件(画板)
|
||||||
|
|
||||||
|
由于需要实现的这个可视化控件的主要功能是**对图元对象进行管理并使它们可视化**。
|
||||||
|
|
||||||
|
QT中已有的`QGraphicsView`具有相似的功能,在文档中有如下描述:
|
||||||
|
|
||||||
|
> The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene
|
||||||
|
>
|
||||||
|
> QGraphicsView类是一个将QGraphicsScene场景中的内容可视化显示出来的控件
|
||||||
|
|
||||||
|
其中,`QGraphicsScene`是管理所有图元的场景,其在文档中的描述如下:
|
||||||
|
|
||||||
|
> The QGraphicsScene class provides a surface for managing large number of 2D graphical items
|
||||||
|
>
|
||||||
|
> QGraphicsScene类提供了一个管理大量2D图形项的平台
|
||||||
|
|
||||||
|
而`QGraphicsScene`所管理的图形项均继承自`QGraphicsItem`,也就是说对于所有继承自`QGraphicsItem`的图形项目,都可以通过`QGraphicsScene`进行管理,并使用`QGraphicsView`来显示
|
||||||
|
|
||||||
|
但是由于不论是`QGraphicsView`还是`QGraphicsItem`,所提供的功能都不足以满足本次项目的功能,因此需要从它们继承并完成新类如下:
|
||||||
|
|
||||||
|
<!--
|
||||||
|
由上述`QGraphicsView`、`QGraphicsScene`以及`QGraphicsItem`的关系可以得知,本次需要完成如下新类:
|
||||||
|
-->
|
||||||
|
|
||||||
|
- `MyGraphicsView`:继承自`QGraphicsView`,添加对鼠标操作的判定和响应、动画队列等功能
|
||||||
|
- `MyGraphicsVexItem`:继承自`QGraphicsItem`,完成点的绘制和对应功能
|
||||||
|
- `MyGraphicsLineItem`:继承自`QGraphicsItem`,完成线的绘制和对应功能
|
||||||
|
|
||||||
|
下面,我将按照最初的设计思路带大家完成这三个类的实现:
|
||||||
|
|
||||||
|
#### 首先,绘制一个点
|
||||||
|
|
||||||
|
目前为止,我们面对的任务有:
|
||||||
|
|
||||||
|
- 设计点对应的`MyGraphicsVexItem`类
|
||||||
|
- 设计线对应的`MyGraphicsLineItem`类
|
||||||
|
- 设计视图框架`MyGraphicsView`将点和线联系起来
|
||||||
|
|
||||||
|
按照先挑软柿子捏的逻辑,`MyGraphicsVexItem`类应当是最先进行设计的
|
||||||
|
|
||||||
|
首先,先不考虑其他一切问题,如果仅仅只需要在视图场景中绘制一个点,由于点实际上的显示效果是一个圆,因此可以使用`QGraphicsEllipseItem`类:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsEllipseItem>
|
||||||
|
|
||||||
|
/* Declaration of Graphics View and Graphics Scene */
|
||||||
|
QGraphicsView* myView = new QGraphicsView;
|
||||||
|
QGraphicsScene* myScene = new QGraphicsScene;
|
||||||
|
myScene->setSceneRect(-100, -100, 200, 200);
|
||||||
|
myView->setScene(myScene);
|
||||||
|
|
||||||
|
/* Addition of a point */
|
||||||
|
//Create and set the top left pos of the new point to (-25, -25) and the radius to 25
|
||||||
|
QGraphicsEllipseItem* newPoint = new QGraphicsEllipseItem(-25, -25, 50, 50);
|
||||||
|
myScene->addItem(newPoint);
|
||||||
|
```
|
||||||
|
|
||||||
|
这样我们就以`(0,0)`为圆心,`25`为半径绘制了一个圆。但很显然,这不可能是我们想要的效果,我们需要在绘制出一个简单圆形的基础上添加一些特性,比如点的颜色属性、点的选择状态或是点的`Pop out`动画
|
||||||
|
|
||||||
|
为了**在画一个圆**的基础上实现这些额外的功能,我们从`QGraphicsEllipseItem`处继承得到`MyGraphicsVexItem`类
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
class MyGraphicsVexItem : public QGraphicsEllipseItem {
|
||||||
|
//Constructors, Properties, Methods, etc.
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 先别着急:搭建一个测试框架
|
||||||
|
|
||||||
|
在开始着手进行类的各种设计之前,为了明确我们到底设计了什么东西出来,我们需要先搭建一个测试效果用的简单程序框架,它不需要任何UI设计,只需要能够测试我们的类就足够了
|
||||||
|
|
||||||
|
首先创建一个工程,在`mainwindow.cpp`中添加如下头文件
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
```
|
||||||
|
|
||||||
|
在`MainWindow`构造函数中添加如下代码:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
//Set layout for central widget
|
||||||
|
QVBoxLayout* mainLayout = new QVBoxLayout();
|
||||||
|
ui->centralWidget->setLayout(mainLayout);
|
||||||
|
|
||||||
|
//Add GraphicsView widget
|
||||||
|
QGraphicsView* testView = new QGraphicsView(ui->centralWidget);
|
||||||
|
QGraphicsScene* testScene = new QGraphicsScene(ui->centralWidget);
|
||||||
|
testScene->setSceneRect(-150, -150, 300, 300);
|
||||||
|
testView->setScene(testScene);
|
||||||
|
|
||||||
|
//Add widget to layout
|
||||||
|
mainLayout->addWidget(testView);
|
||||||
|
```
|
||||||
|
|
||||||
|
编译程序,即可得到一个简单的GraphicsView显示窗口
|
||||||
|
|
||||||
|
后续的测试则通过在这个框架上添加或是修改特定的功能来测试效果
|
||||||
|
|
||||||
|
##### 迈出第一步:使用参数绘制点
|
||||||
|
|
||||||
|
为了能够在新的类里面使用给定的参数画出点,我们需要如下参数:
|
||||||
|
|
||||||
|
- `QPointF center` : 几何中心
|
||||||
|
- `qreal radius` : 半径
|
||||||
|
- `QBrush regBrush` : 默认画刷
|
||||||
|
|
||||||
|
由于考虑到其他方法也可能会访问或是修改这些参数,因此将他们作为类的成员变量。构造函数则在妥善设置和使用这些参数的基础上,结合父类构造函数完成
|
||||||
|
|
||||||
|
具体的修改代码如下:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
private:
|
||||||
|
//Geometry properties
|
||||||
|
QPointF center;
|
||||||
|
qreal radius;
|
||||||
|
|
||||||
|
//Brush properties
|
||||||
|
//default color
|
||||||
|
QBrush regBrush = QBrush(QColor(58, 143, 192));
|
||||||
|
|
||||||
|
public:
|
||||||
|
MyGraphicsVexItem(QPointF _center, qreal _radius, QGraphicsItem* parent = nullptr);
|
||||||
|
```
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
MyGraphicsVexItem::MyGraphicsVexItem(QPointF _center, qreal _radius, QGraphicsItem* parent) :
|
||||||
|
QGraphicsEllipseItem(_center.x() - _radius, _center.y() - _radius, 2 * _radius, 2 * _radius, parent),
|
||||||
|
center(_center),
|
||||||
|
radius(_radius)
|
||||||
|
{
|
||||||
|
this->setPen(Qt::NoPen);
|
||||||
|
this->setBrush(regBrush);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
此时我们在测试框架中用代码添加一个点测试效果:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
//Add a new vex
|
||||||
|
MyGraphicsVexItem* newVex = new MyGraphicsVexItem(QPointF(0, 0), 10);
|
||||||
|
testScene->addItem(newVex);
|
||||||
|
```
|
||||||
40
README.md
Normal file
40
README.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# GraphBuilder
|
||||||
|
|
||||||
|
This is a project inspired by my Data Structure & Algorithm Course homework, it's used to create and visualize graphs both directed or undirected, and supports underlaying data structure of either adjacent list or multiple adjacent list
|
||||||
|
|
||||||
|
## Functionalities
|
||||||
|
|
||||||
|
- Create, save or read multiple layers (or might say multiple palettes)
|
||||||
|
- Draw or remove nodes and edges
|
||||||
|
- Change name, position of nodes
|
||||||
|
- Change width, direction of edges
|
||||||
|
- Animate BFS, DFS and Dijkstra's algorithm
|
||||||
|
- Change animation speed
|
||||||
|
- Change the underlaying data structure
|
||||||
|
- Change the type of graph (directed or undirected)
|
||||||
|
- Display the generated minimum spanning tree (by hiding unvisited items)
|
||||||
|
- Support algorithms on forests
|
||||||
|
|
||||||
|
## Deploy and run
|
||||||
|
|
||||||
|
If you want to use the packed executable, you can download it from the [release page](https://github.com/Linloir/GraphBuilder/releases)
|
||||||
|
|
||||||
|
If you want to view the source code and run it from QT Creator, you might need:
|
||||||
|
|
||||||
|
- QT 6.1 or above
|
||||||
|
- QT Creator installed
|
||||||
|
- QT build kit (MSVC or MinGW) installed
|
||||||
|
|
||||||
|
Armed with the above, you can clone the repository and open the project from `GraphBuilder.pro` file in QT Creator.
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
87
cities.map
Normal file
87
cities.map
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
VFdGeWFXUnZaekl3TURJd05ESTE=
|
||||||
|
Railway Network
|
||||||
|
A map of railway network in China
|
||||||
|
128 1
|
||||||
|
25
|
||||||
|
38.599 19.965 10
|
||||||
|
Wu Lumuqi
|
||||||
|
178.354 190.333 10
|
||||||
|
Lan Zhou
|
||||||
|
278.179 58.564 10
|
||||||
|
Hu Hehaote
|
||||||
|
384.659 99.825 10
|
||||||
|
Bei Jing
|
||||||
|
485.815 137.093 10
|
||||||
|
Tian Jin
|
||||||
|
608.267 107.811 10
|
||||||
|
Shen Yang
|
||||||
|
685.465 50.578 10
|
||||||
|
Chang Chun
|
||||||
|
752.015 -2.662 10
|
||||||
|
Ha Erbin
|
||||||
|
602.943 185.009 10
|
||||||
|
Da Lian
|
||||||
|
451.209 246.235 10
|
||||||
|
Xu Zhou
|
||||||
|
347.391 240.911 10
|
||||||
|
Zheng Zhou
|
||||||
|
536.393 331.419 10
|
||||||
|
Shang Hai
|
||||||
|
419.265 400.631 10
|
||||||
|
Nan Chang
|
||||||
|
519.09 443.223 10
|
||||||
|
Fu Zhou
|
||||||
|
368.687 328.757 10
|
||||||
|
Wu Han
|
||||||
|
331.419 407.286 10
|
||||||
|
Zhu Zhou
|
||||||
|
252.89 232.925 10
|
||||||
|
Xi An
|
||||||
|
78.529 166.375 10
|
||||||
|
Xi Ning
|
||||||
|
145.079 310.123 10
|
||||||
|
Cheng Du
|
||||||
|
166.375 440.561 10
|
||||||
|
Gui Yang
|
||||||
|
81.191 455.202 10
|
||||||
|
Kun Ming
|
||||||
|
260.876 483.153 10
|
||||||
|
Liu Zhou
|
||||||
|
190.333 547.041 10
|
||||||
|
Nan Ning
|
||||||
|
336.743 493.801 10
|
||||||
|
Guang Zhou
|
||||||
|
448.547 563.013 10
|
||||||
|
Shen Zhen
|
||||||
|
30
|
||||||
|
0 1
|
||||||
|
1 2
|
||||||
|
2 3
|
||||||
|
3 4
|
||||||
|
4 5
|
||||||
|
5 6
|
||||||
|
6 7
|
||||||
|
5 8
|
||||||
|
4 9
|
||||||
|
3 10
|
||||||
|
10 9
|
||||||
|
9 11
|
||||||
|
11 12
|
||||||
|
12 13
|
||||||
|
10 14
|
||||||
|
14 15
|
||||||
|
15 12
|
||||||
|
10 16
|
||||||
|
16 1
|
||||||
|
1 17
|
||||||
|
16 18
|
||||||
|
18 19
|
||||||
|
18 20
|
||||||
|
20 19
|
||||||
|
19 15
|
||||||
|
15 21
|
||||||
|
21 19
|
||||||
|
21 22
|
||||||
|
15 23
|
||||||
|
23 24
|
||||||
|
1892 1145 668 137 704 305 242 397 674 695 349 651 825 622 534 409 367 511 676 216 842 967 1100 639 902 672 607 255 675 140
|
||||||
@ -377,7 +377,11 @@ void ScrollIndicator::mousePressEvent(QMouseEvent *event){
|
|||||||
pressed = true;
|
pressed = true;
|
||||||
//>note: globalPos -> globalPosition here due to deprecation
|
//>note: globalPos -> globalPosition here due to deprecation
|
||||||
//> may cause issues
|
//> may cause issues
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
lastY = event->globalPosition().y();
|
lastY = event->globalPosition().y();
|
||||||
|
#else
|
||||||
|
lastY = event->globalPos().y();
|
||||||
|
#endif
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,11 +389,19 @@ void ScrollIndicator::mouseMoveEvent(QMouseEvent *event){
|
|||||||
if(pressed && !aniPause->isActive()){
|
if(pressed && !aniPause->isActive()){
|
||||||
//>note: globalPos -> globalPosition here due to deprecation
|
//>note: globalPos -> globalPosition here due to deprecation
|
||||||
//> may cause issues
|
//> may cause issues
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
int dp = event->globalPosition().y() - lastY;
|
int dp = event->globalPosition().y() - lastY;
|
||||||
|
#else
|
||||||
|
int dp = event->globalPos().y() - lastY;
|
||||||
|
#endif
|
||||||
emit scrollPage(dp);
|
emit scrollPage(dp);
|
||||||
//>note: globalPos -> globalPosition here due to deprecation
|
//>note: globalPos -> globalPosition here due to deprecation
|
||||||
//> may cause issues
|
//> may cause issues
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
lastY = event->globalPosition().y();
|
lastY = event->globalPosition().y();
|
||||||
|
#else
|
||||||
|
lastY = event->globalPos().y();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
#define MAXSPEED 70
|
#define MAXSPEED 70
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,13 @@
|
|||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QFocusEvent>
|
#include <QFocusEvent>
|
||||||
|
|
||||||
|
#if (QT_VERSION > QT_VERSION_CHECK(6,3,0))
|
||||||
|
#include <QGraphicsOpacityEffect>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class customIcon : public QPushButton{
|
class customIcon : public QPushButton{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|||||||
BIN
fonts/corbel.ttf
Executable file
BIN
fonts/corbel.ttf
Executable file
Binary file not shown.
BIN
fonts/corbelb.ttf
Executable file
BIN
fonts/corbelb.ttf
Executable file
Binary file not shown.
BIN
fonts/corbeli.ttf
Executable file
BIN
fonts/corbeli.ttf
Executable file
Binary file not shown.
BIN
fonts/corbell.ttf
Executable file
BIN
fonts/corbell.ttf
Executable file
Binary file not shown.
BIN
fonts/corbelli.ttf
Executable file
BIN
fonts/corbelli.ttf
Executable file
Binary file not shown.
BIN
fonts/corbelz.ttf
Executable file
BIN
fonts/corbelz.ttf
Executable file
Binary file not shown.
@ -1,5 +1,4 @@
|
|||||||
#include "graph_view.h"
|
#include "graph_view.h"
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
viewLog::viewLog(QString log, QWidget *parent) :
|
viewLog::viewLog(QString log, QWidget *parent) :
|
||||||
QLabel(parent)
|
QLabel(parent)
|
||||||
@ -147,7 +146,11 @@ void MyGraphicsView::mouseMoveEvent(QMouseEvent *event){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MyGraphicsView::wheelEvent(QWheelEvent *event){
|
void MyGraphicsView::wheelEvent(QWheelEvent *event){
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
QPointF cursorPoint = event->position();
|
QPointF cursorPoint = event->position();
|
||||||
|
#else
|
||||||
|
QPointF cursorPoint = event->posF();
|
||||||
|
#endif
|
||||||
QPointF scenePos = this->mapToScene(QPoint(cursorPoint.x(), cursorPoint.y()));
|
QPointF scenePos = this->mapToScene(QPoint(cursorPoint.x(), cursorPoint.y()));
|
||||||
|
|
||||||
qreal viewWidth = this->viewport()->width();
|
qreal viewWidth = this->viewport()->width();
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
||||||
//Header for MyVex class
|
//Header for MyVex class
|
||||||
@ -25,6 +24,10 @@
|
|||||||
#include <QTimeLine>
|
#include <QTimeLine>
|
||||||
#include <QEasingCurve>
|
#include <QEasingCurve>
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||||
|
#include <QtMath>
|
||||||
|
#endif
|
||||||
|
|
||||||
class viewLog : public QLabel{
|
class viewLog : public QLabel{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
|||||||
8
main.cpp
8
main.cpp
@ -1,9 +1,17 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
//int id = QFontDatabase::addApplicationFont(":/fonts/fonts/corbel.ttf");
|
||||||
|
//qDebug() << id;
|
||||||
|
//QFontDatabase::addApplicationFont(":/fonts/fonts/corbell.ttf");
|
||||||
|
//Qt::AA_EnableHighDpiScaling;
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
#endif
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.setWindowFlag(Qt::FramelessWindowHint);
|
w.setWindowFlag(Qt::FramelessWindowHint);
|
||||||
|
|||||||
@ -5,12 +5,21 @@
|
|||||||
#include <QRegion>
|
#include <QRegion>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#if (QT_VERSION > QT_VERSION_CHECK(6,3,0))
|
||||||
|
#include <QFileDialog>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->centralwidget->setMouseTracking(true);
|
ui->centralwidget->setMouseTracking(true);
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
ui->verticalLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
cornerRadius = 0;
|
||||||
|
#endif
|
||||||
QTimer *t = new QTimer(this);
|
QTimer *t = new QTimer(this);
|
||||||
connect(t, &QTimer::timeout, this, [=](){Init();});
|
connect(t, &QTimer::timeout, this, [=](){Init();});
|
||||||
t->setSingleShot(true);
|
t->setSingleShot(true);
|
||||||
@ -21,8 +30,13 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
void MainWindow::Init(){
|
void MainWindow::Init(){
|
||||||
/* Create main widget and set mask, style sheet and shadow */
|
/* Create main widget and set mask, style sheet and shadow */
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRect(ui->mainWidget->rect());
|
||||||
|
#else
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
path.addRoundedRect(ui->mainWidget->rect(), cornerRadius - 1, cornerRadius - 1);
|
path.addRoundedRect(ui->mainWidget->rect(), cornerRadius - 1, cornerRadius - 1);
|
||||||
|
#endif
|
||||||
QRegion mask(path.toFillPolygon().toPolygon());
|
QRegion mask(path.toFillPolygon().toPolygon());
|
||||||
ui->mainWidget->setMask(mask);
|
ui->mainWidget->setMask(mask);
|
||||||
|
|
||||||
@ -30,15 +44,19 @@ void MainWindow::Init(){
|
|||||||
ui->mainWidget->setObjectName("mainWidget");
|
ui->mainWidget->setObjectName("mainWidget");
|
||||||
mainStyle = "QWidget#mainWidget{background-color:" + mainBackGround.name() + QString::asprintf(";border-radius:%dpx", cornerRadius) + "}";
|
mainStyle = "QWidget#mainWidget{background-color:" + mainBackGround.name() + QString::asprintf(";border-radius:%dpx", cornerRadius) + "}";
|
||||||
ui->mainWidget->setStyleSheet(mainStyle);
|
ui->mainWidget->setStyleSheet(mainStyle);
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
windowShadow = new QGraphicsDropShadowEffect(this);
|
windowShadow = new QGraphicsDropShadowEffect(this);
|
||||||
windowShadow->setBlurRadius(30);
|
windowShadow->setBlurRadius(30);
|
||||||
windowShadow->setColor(QColor(0, 0, 0));
|
windowShadow->setColor(QColor(0, 0, 0));
|
||||||
windowShadow->setOffset(0, 0);
|
windowShadow->setOffset(0, 0);
|
||||||
ui->mainWidget->setGraphicsEffect(windowShadow);
|
ui->mainWidget->setGraphicsEffect(windowShadow);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
/**********************************************************/
|
/**********************************************************/
|
||||||
|
|
||||||
/* Create border in order to cover the zigzag edge of the region */
|
/* Create border in order to cover the zigzag edge of the region */
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
border = new QWidget(this);
|
border = new QWidget(this);
|
||||||
border->move(ui->mainWidget->pos() - QPoint(1, 1));
|
border->move(ui->mainWidget->pos() - QPoint(1, 1));
|
||||||
border->resize(ui->mainWidget->size() + QSize(2, 2));
|
border->resize(ui->mainWidget->size() + QSize(2, 2));
|
||||||
@ -47,6 +65,7 @@ void MainWindow::Init(){
|
|||||||
border->setStyleSheet(borderStyle);
|
border->setStyleSheet(borderStyle);
|
||||||
border->setAttribute(Qt::WA_TransparentForMouseEvents);
|
border->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
border->show();
|
border->show();
|
||||||
|
#endif
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
|
|
||||||
/* Create about page */
|
/* Create about page */
|
||||||
@ -329,7 +348,11 @@ MainWindow::~MainWindow()
|
|||||||
void MainWindow::mousePressEvent(QMouseEvent *event){
|
void MainWindow::mousePressEvent(QMouseEvent *event){
|
||||||
if(event->button() == Qt::LeftButton){
|
if(event->button() == Qt::LeftButton){
|
||||||
mousePressed = true;
|
mousePressed = true;
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
lastPos = event->globalPosition().toPoint() - this->frameGeometry().topLeft();
|
lastPos = event->globalPosition().toPoint() - this->frameGeometry().topLeft();
|
||||||
|
#else
|
||||||
|
lastPos = event->globalPos() - this->frameGeometry().topLeft();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,14 +385,26 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event){
|
|||||||
if(maximized){
|
if(maximized){
|
||||||
qreal wRatio = (double)event->pos().x() / (double)ui->mainWidget->width();
|
qreal wRatio = (double)event->pos().x() / (double)ui->mainWidget->width();
|
||||||
controlWindowScale();
|
controlWindowScale();
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
this->move(QPoint(event->globalPosition().x() - ui->mainWidget->width() * wRatio, -30));
|
this->move(QPoint(event->globalPosition().x() - ui->mainWidget->width() * wRatio, -30));
|
||||||
|
#else
|
||||||
|
this->move(QPoint(event->globalPos().x() - ui->mainWidget->width() * wRatio, -30));
|
||||||
|
#endif
|
||||||
lastPos = QPoint(ui->mainWidget->width() * wRatio, event->pos().y());
|
lastPos = QPoint(ui->mainWidget->width() * wRatio, event->pos().y());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
this->move(event->globalPosition().toPoint() - lastPos);
|
this->move(event->globalPosition().toPoint() - lastPos);
|
||||||
|
#else
|
||||||
|
this->move(event->globalPos() - lastPos);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
QPoint d = event->globalPosition().toPoint() - frameGeometry().topLeft() - lastPos;
|
QPoint d = event->globalPosition().toPoint() - frameGeometry().topLeft() - lastPos;
|
||||||
|
#else
|
||||||
|
QPoint d = event->globalPos() - frameGeometry().topLeft() - lastPos;
|
||||||
|
#endif
|
||||||
if(mouseState & AT_LEFT){
|
if(mouseState & AT_LEFT){
|
||||||
this->move(this->frameGeometry().x() + d.x(), this->frameGeometry().y());
|
this->move(this->frameGeometry().x() + d.x(), this->frameGeometry().y());
|
||||||
this->resize(this->width() - d.x(), this->height());
|
this->resize(this->width() - d.x(), this->height());
|
||||||
@ -385,7 +420,11 @@ void MainWindow::mouseMoveEvent(QMouseEvent *event){
|
|||||||
this->resize(this->width(), this->height() + d.y());
|
this->resize(this->width(), this->height() + d.y());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
lastPos = event->globalPosition().toPoint() - this->frameGeometry().topLeft();
|
lastPos = event->globalPosition().toPoint() - this->frameGeometry().topLeft();
|
||||||
|
#else
|
||||||
|
lastPos = event->globalPos() - this->frameGeometry().topLeft();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,18 +435,23 @@ void MainWindow::resizeEvent(QResizeEvent *event){
|
|||||||
|
|
||||||
//Resize mask
|
//Resize mask
|
||||||
QPainterPath path;
|
QPainterPath path;
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
path.addRoundedRect(ui->mainWidget->rect(), cornerRadius - 1, cornerRadius - 1);
|
path.addRoundedRect(ui->mainWidget->rect(), cornerRadius - 1, cornerRadius - 1);
|
||||||
|
#else
|
||||||
|
path.addRect(ui->mainWidget->rect());
|
||||||
|
#endif
|
||||||
QRegion mask(path.toFillPolygon().toPolygon());
|
QRegion mask(path.toFillPolygon().toPolygon());
|
||||||
ui->mainWidget->setMask(mask);
|
ui->mainWidget->setMask(mask);
|
||||||
|
|
||||||
//Resize all pages
|
//Resize all pages
|
||||||
for(int i = 0; i < pageList.size(); i++){
|
for(int i = 0; i < pageList.size(); i++){
|
||||||
pageList[i]->resize(ui->mainWidget->width() * 0.3 < pageList[i]->preferWidth ? pageList[i]->preferWidth - 1 : ui->mainWidget->width() * 0.3 - 1, ui->mainWidget->height());
|
pageList[i]->resize(ui->mainWidget->width() * 0.4 < pageList[i]->preferWidth ? pageList[i]->preferWidth - 1 : ui->mainWidget->width() * 0.4 - 1, ui->mainWidget->height());
|
||||||
pageList[i]->resize(pageList[i]->width() + 1, pageList[i]->height());
|
pageList[i]->resize(pageList[i]->width() + 1, pageList[i]->height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::controlWindowScale(){
|
void MainWindow::controlWindowScale(){
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
if(!maximized){
|
if(!maximized){
|
||||||
lastGeometry = this->frameGeometry();
|
lastGeometry = this->frameGeometry();
|
||||||
windowShadow->setEnabled(false);
|
windowShadow->setEnabled(false);
|
||||||
@ -437,6 +481,7 @@ void MainWindow::controlWindowScale(){
|
|||||||
this->move(lastGeometry.x(), lastGeometry.y());
|
this->move(lastGeometry.x(), lastGeometry.y());
|
||||||
maximized = false;
|
maximized = false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MyCanvas* MainWindow::loadCanvas(const QString &path){
|
MyCanvas* MainWindow::loadCanvas(const QString &path){
|
||||||
|
|||||||
11
mainwindow.h
11
mainwindow.h
@ -48,7 +48,16 @@ private:
|
|||||||
QPoint lastPos;
|
QPoint lastPos;
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseReleaseEvent(QMouseEvent *event){mousePressed = false;if(event->globalPosition().y() < 2) controlWindowScale();}
|
void mouseReleaseEvent(QMouseEvent *event){
|
||||||
|
mousePressed = false;
|
||||||
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||||
|
if(event->globalPosition().y() < 2)
|
||||||
|
controlWindowScale();
|
||||||
|
#else
|
||||||
|
if(event->globalPos().y() < 2)
|
||||||
|
controlWindowScale();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
void resizeEvent(QResizeEvent *event);
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
bool maximized = false;
|
bool maximized = false;
|
||||||
|
|||||||
@ -7,6 +7,11 @@
|
|||||||
#include "graph_view.h"
|
#include "graph_view.h"
|
||||||
#include "graph_implement.h"
|
#include "graph_implement.h"
|
||||||
|
|
||||||
|
#if (QT_VERSION > QT_VERSION_CHECK(6,3,0))
|
||||||
|
#include <QFileDialog>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class MyCanvas : public QWidget
|
class MyCanvas : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
BIN
screenshots/BFS.gif
Normal file
BIN
screenshots/BFS.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 MiB |
BIN
screenshots/ChangeType.gif
Normal file
BIN
screenshots/ChangeType.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.8 MiB |
BIN
screenshots/CreatePalette.gif
Normal file
BIN
screenshots/CreatePalette.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.0 MiB |
BIN
screenshots/DFS.gif
Normal file
BIN
screenshots/DFS.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 MiB |
BIN
screenshots/Dijkstra.gif
Normal file
BIN
screenshots/Dijkstra.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 MiB |
@ -7,7 +7,7 @@ SlidePage::SlidePage(int radius, QString name, QWidget *parent) :
|
|||||||
{
|
{
|
||||||
//if(parent)
|
//if(parent)
|
||||||
// resize(parent->width() * 0.8 <= preferWidth ? parent->width() * 0.8 : preferWidth, parent->height());
|
// resize(parent->width() * 0.8 <= preferWidth ? parent->width() * 0.8 : preferWidth, parent->height());
|
||||||
resize(parent->width() * 0.3 <= preferWidth ? preferWidth : parent->width() * 0.3, parent->height());
|
resize(parent->width() * 0.4 <= preferWidth ? preferWidth : parent->width() * 0.4, parent->height());
|
||||||
this->move(QPoint(-this->width() - 30, 0));
|
this->move(QPoint(-this->width() - 30, 0));
|
||||||
|
|
||||||
pageContentContainer = new ScrollAreaCustom(this);
|
pageContentContainer = new ScrollAreaCustom(this);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user