QT:简易文本编辑器

news/2024/11/7 22:23:52/文章来源:https://www.cnblogs.com/samrv/p/18534118

 

 

效果

 

main.cpp 代码:

#include "imgprocessor.h"#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);QFont f("ZYSong18030",12);//设置显示字段格式a.setFont(f);ImgProcessor w;w.show();return a.exec();
}

  

imgprocessor.h 代码:

#ifndef IMGPROCESSOR_H
#define IMGPROCESSOR_H#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include <QComboBox>
#include <QFontComboBox>
#include <QToolBar>
#include <QToolButton>
#include <QTextCharFormat>
#include <QTextStream>
#include <QPrinter>
#include <QPrintDialog>
#include <QTextDocument>
#include <QPainter>#include "showwidget.h"class ImgProcessor : public QMainWindow
{Q_OBJECTpublic:ImgProcessor(QWidget *parent = nullptr);~ImgProcessor();void createActions();//创建动作void createMenus();//创建菜单void createToolBars();//创建工具栏void loadFile(QString filename);void mergeFormat(QTextCharFormat format);protected slots:void ShowNewFile(); // 新建文件void ShowOpenFile(); // 打开文件void ShowPrintText();// 打印文件void ShowPrintImage(); //图像打印void ShowZoomIn(); //放大void ShowZoomOut(); // 缩小void ShowRotate90(); //旋转90度void ShowRotate180();//旋转180度void ShowRotate270();//旋转270度void ShowMirrorVertical(); // 纵向镜像void ShowMirrorHorizontal();// 横向镜像/* 文本相关:槽 */void ShowFontComboBox(QString comboStr);void ShowSizeSpinBox(QString spinValue);void ShowBoldBtn();void ShowItalicBtn();void ShowUnderlineBtn();void ShowColorBtn();void ShowCurrentFormatChanged(const QTextCharFormat &fmt);/*  排版功能 */void ShowList(int );void ShowAlignment(QAction *act);void ShowCursorPositionChanged();private:QMenu *fileMenu; // 各项菜单栏QMenu *zoomMenu;QMenu *rotateMenu;QMenu *mirrorMenu;QImage img;QString fileName;ShowWidget *showWidget;QAction *openFileAction; //文件菜单项QAction *NewfileAction;QAction *PrintTextAction;QAction *PrintImageAction;QAction *exitAction;QAction *copyAction; //编辑菜单项QAction *cutAction;QAction *pasteAction;QAction *aboutAction;QAction *zoomInAction;QAction *zoomOutAction;QAction *rotate90Action; //旋转菜单项QAction *rotate180Action;QAction *rotate270Action;QAction *mirrorVerticalAction; //镜像菜单项QAction *mirrorHorizontalAction;QAction *undoAction;QAction *redoAction;QToolBar *fileTool; //工具栏QToolBar *zoomTool;QToolBar *rotateTool;QToolBar *mirrorTool;QToolBar *doToolBar;/*  文本相关工具 */QLabel *fontLabel1;QFontComboBox *fontComboBox;QLabel *fontLabel2;QComboBox *sizeComboBox;QToolButton *boldBtn;QToolButton *italicBtn;QToolButton *underlineBtn;QToolButton *colorBtn;QToolBar *fontToolBar; // 字体工具栏/*  排版功能 */QLabel *listLabel;  // 排序设置项QComboBox *listComboBox;QActionGroup *actGrp;QAction *leftAction;QAction *rightAction;QAction *centerAction;QAction *justifyAction;QToolBar *listToolBar; // 排版工具
};
#endif // IMGPROCESSOR_H

  

imgprocessor.cpp 代码:

#include "imgprocessor.h"
#include <QFile>
#include <QTextStream>
#include <QFileDialog>
#include <QPrinter>
#include <QColor>
#include <QColorDialog>
#include <QTextBlock>
#include <QTextList>ImgProcessor::ImgProcessor(QWidget *parent): QMainWindow(parent)
{setWindowTitle(tr("Easy Word")); //设置窗体标题showWidget = new ShowWidget(this);setCentralWidget(showWidget);// 在工具栏上嵌入控件//设置字体  p143fontLabel1 = new QLabel(tr("字体:"));fontComboBox = new QFontComboBox;fontComboBox->setFontFilters(QFontComboBox::ScalableFonts);fontLabel2 = new QLabel(tr("字号:"));sizeComboBox = new QComboBox;QFontDatabase db;foreach(int size ,db.standardSizes())sizeComboBox->addItem(QString::number(size));boldBtn = new QToolButton;boldBtn->setIcon(QIcon("./images/bold.png"));boldBtn->setCheckable(true);italicBtn = new QToolButton;italicBtn->setIcon(QIcon("./images/italic.png"));italicBtn->setCheckable(true);underlineBtn = new QToolButton;underlineBtn->setIcon(QIcon("./images/underline.png"));underlineBtn->setCheckable(true);colorBtn = new QToolButton;colorBtn->setIcon(QIcon("./images/color.png"));colorBtn->setCheckable(true);/*  排版功能 */listLabel = new QLabel(tr("排序"));listComboBox = new QComboBox;listComboBox->addItem("QTextListFormat::ListDisc");listComboBox->addItem("QTextListFormat::ListCircle");listComboBox->addItem("QTextListFormat::ListSquare");listComboBox->addItem("QTextListFormat::ListDecimal");listComboBox->addItem("QTextListFormat::ListLowerAlpha");listComboBox->addItem("QTextListFormat::ListUpperAlpa");listComboBox->addItem("QTextListFormat::ListLowerRoman");listComboBox->addItem("QTextListFormat::ListUpperRoman");/*创建动作、菜单、工具栏的函数*/createActions();createMenus();createToolBars();if(img.load("image.png")){// 在imageLabel对象中放置图片showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));}//新建文件connect(NewfileAction,SIGNAL(triggered()),this,SLOT(ShowNewFile()));connect(openFileAction,SIGNAL(triggered()),this,SLOT(ShowOpenFile()));connect(PrintTextAction,SIGNAL(triggered()),this,SLOT(ShowPrintText()));connect(PrintImageAction,SIGNAL(triggered()),this,SLOT(ShowPrintImage()));connect(zoomOutAction,SIGNAL(triggered()),this,SLOT(ShowZoomOut()));connect(zoomInAction,SIGNAL(triggered()),this,SLOT(ShowZoomIn()));connect(rotate90Action,SIGNAL(triggered()),this,SLOT(ShowRotate90()));connect(rotate180Action,SIGNAL(triggered()),this,SLOT(ShowRotate180()));connect(rotate270Action,SIGNAL(triggered()),this,SLOT(ShowRotate270()));connect(mirrorHorizontalAction,SIGNAL(triggered()),this,SLOT(ShowMirrorHorizontal()));connect(mirrorVerticalAction,SIGNAL(triggered()),this,SLOT(ShowMirrorVertical()));/* 事件关联 */connect(fontComboBox, SIGNAL(activated(QString)),this,SLOT(ShowFontComboBox(QString)));connect(sizeComboBox, SIGNAL(activated(QString)),this,SLOT(ShowSizeSpinBox(QString)));connect(boldBtn, SIGNAL(clicked()),this,SLOT(ShowboldBtn()));connect(italicBtn, SIGNAL(clicked()),this,SLOT(ShowItalicBtn()));connect(underlineBtn, SIGNAL(clicked()),this,SLOT(ShowUnderlineBtn()));connect(colorBtn, SIGNAL(clicked()),this,SLOT(ShowColorBtn()));connect(showWidget, SIGNAL(currentChartFormatChanged(QTextCharFormat&)),this,SLOT(ShowCurrentFormatChanged(QTextCharFormat&)));/*  排版功能 */connect(listComboBox, SIGNAL(activated(int)),this, SLOT(ShowList(int)));connect(showWidget->text->document(), SIGNAL(undoAvailable(bool)),redoAction, SLOT(setEnabled(bool)));connect(showWidget->text->document(), SIGNAL(redoAvailable(bool)),redoAction, SLOT(setEnabled(bool)));connect(showWidget->text, SIGNAL(cursorPositionChanged()),this, SLOT(ShowCursorPositionChanged()));
}ImgProcessor::~ImgProcessor()
{
}void ImgProcessor::createActions()
{//“打开” 动作openFileAction = new QAction(QIcon("./images/open.png"),tr("打开"),this);openFileAction->setShortcut(tr("Ctrl+O"));openFileAction->setStatusTip(tr("打开一个文件"));NewfileAction = new QAction(QIcon("./images/new.png"),tr("新建"),this);NewfileAction->setShortcut(tr("Ctrl+N"));NewfileAction->setStatusTip(tr("新建一个文件"));exitAction= new QAction(QIcon("./images/exit.png"),tr("退出"),this);exitAction->setShortcut(tr("Ctrl+Q"));exitAction->setStatusTip(tr("退出程序"));connect(exitAction,SIGNAL(triggered()),this,SLOT(close()));copyAction = new QAction(QIcon("./images/copy.png"),tr("复制"),this);copyAction->setShortcut(tr("Ctrl+C"));copyAction->setStatusTip(tr("复制文件"));connect(copyAction,SIGNAL(triggered()),showWidget->text,SLOT(copy()));cutAction = new QAction(QIcon("./images/cut.png"),tr("剪切"),this);cutAction->setShortcut(tr("Ctrl+X"));cutAction->setStatusTip(tr("剪切文件"));connect(cutAction,SIGNAL(triggered()),showWidget->text,SLOT(cut()));pasteAction = new QAction(QIcon("./images/paste.png"),tr("粘贴"),this);pasteAction->setShortcut(tr("Ctrl+V"));pasteAction->setStatusTip(tr("粘贴文件"));connect(pasteAction,SIGNAL(triggered()),showWidget->text,SLOT(paste()));// ”“关于”“动作aboutAction = new QAction(QIcon("./images/about.png"),tr("关于"),this);connect(aboutAction, SIGNAL(triggered()),this, SLOT(QApplication::aboutQt()));//打印文件 动作PrintTextAction = new QAction(QIcon("./images/printText.png"),tr("打印文本"),this);PrintTextAction->setStatusTip(tr("打印一个文本"));//打印图片 动作PrintImageAction = new QAction(QIcon("./images/printImage.png"),tr("打印图片"),this);PrintImageAction->setStatusTip(tr("打印一幅图片"));zoomInAction = new QAction(QIcon("./images/zoomIn.png"),tr("放大"),this);zoomInAction->setStatusTip(tr("放大一幅图片"));zoomOutAction = new QAction(QIcon("./images/zoomOut.png"),tr("缩小"),this);zoomOutAction->setStatusTip(tr("缩小一幅图片"));rotate90Action = new QAction(QIcon("./images/rotate90.png"),tr("旋转90度"),this);rotate90Action->setStatusTip(tr("将一幅图片旋转90"));rotate180Action = new QAction(QIcon("./images/rotate180.png"),tr("旋转180度"),this);rotate180Action->setStatusTip(tr("将一幅图片旋转180"));rotate270Action = new QAction(QIcon("./images/rotate270.png"),tr("旋转270度"),this);rotate270Action->setStatusTip(tr("将一幅图片旋转270"));mirrorVerticalAction = new QAction(QIcon("./images/mirrorVertical.png"),tr("纵向镜像"),this);mirrorVerticalAction->setStatusTip(tr("对一幅图做纵向镜像"));mirrorHorizontalAction = new QAction(QIcon("./images/mirrorHorizontal.png"),tr("横向镜像"),this);mirrorHorizontalAction->setStatusTip(tr("对一幅图做横向镜像"));undoAction = new QAction(QIcon("./images/undo.png"),tr("撤销"),this);connect(undoAction,SIGNAL(triggered()),showWidget->text,SLOT(undo()));redoAction = new QAction(QIcon("./images/redo.png"),tr("重做"),this);connect(redoAction,SIGNAL(triggered()),showWidget->text,SLOT(redo()));/*  排序: 左对齐、右对齐、居中和两端对齐 */actGrp = new QActionGroup(this);leftAction = new QAction(QIcon("./images/left.png"),"左对齐",actGrp);leftAction->setCheckable(true);rightAction = new QAction(QIcon("./images/right.png"),"右对齐",actGrp);rightAction->setCheckable(true);centerAction = new QAction(QIcon("./images/center.png"),"居中",actGrp);centerAction->setCheckable(true);justifyAction = new QAction(QIcon("./images/justify.png"),"两端对齐",actGrp);justifyAction->setCheckable(true);connect(actGrp,SIGNAL(triggered(QAction*)),this, SLOT(ShowAlignment(QAction*)));}void ImgProcessor::createMenus()
{  // 文件菜单fileMenu = menuBar()->addMenu(tr("文件"));fileMenu->addAction(openFileAction);fileMenu->addAction(NewfileAction);fileMenu->addAction(PrintTextAction);fileMenu->addAction(PrintImageAction);fileMenu->addSeparator();fileMenu->addAction(exitAction);// 缩放菜单zoomMenu = menuBar()->addMenu(tr("编辑"));zoomMenu->addAction(copyAction);zoomMenu->addAction(cutAction);zoomMenu->addAction(pasteAction);zoomMenu->addAction(aboutAction);zoomMenu->addSeparator();zoomMenu->addAction(zoomInAction);zoomMenu->addAction(zoomOutAction);// 旋转菜单rotateMenu = menuBar()->addMenu(tr("旋转"));rotateMenu->addAction(rotate90Action);rotateMenu->addAction(rotate180Action);rotateMenu->addAction(rotate270Action);// 镜像菜单mirrorMenu = menuBar()->addMenu("镜像");mirrorMenu->addAction(mirrorVerticalAction);mirrorMenu->addAction(mirrorHorizontalAction);}void ImgProcessor::createToolBars()
{  // 文件工具条fileTool = addToolBar("File");fileTool->addAction(openFileAction);fileTool->addAction(NewfileAction);fileTool->addAction(PrintTextAction);fileTool->addAction(PrintImageAction);//编辑工具条zoomTool = addToolBar("Edit");zoomTool->addAction(copyAction);zoomTool->addAction(cutAction);zoomTool->addAction(pasteAction);zoomTool->addSeparator();zoomTool->addAction(zoomInAction);zoomTool->addAction(zoomOutAction);//旋转工具条rotateTool =  addToolBar("rotate");rotateTool->addAction(rotate90Action);rotateTool->addAction(rotate180Action);rotateTool->addAction(rotate270Action);//撤销和重做工具条doToolBar = addToolBar("doEdit");doToolBar->addAction(undoAction);doToolBar->addAction(redoAction);//字体工具条fontToolBar = addToolBar("Font");fontToolBar->addWidget(fontLabel1);fontToolBar->addWidget(fontComboBox);fontToolBar->addWidget(fontLabel2);fontToolBar->addWidget(sizeComboBox);fontToolBar->addSeparator();fontToolBar->addWidget(boldBtn);fontToolBar->addWidget(italicBtn);fontToolBar->addWidget(underlineBtn);fontToolBar->addSeparator();fontToolBar->addWidget(colorBtn);//排序工具条listToolBar = addToolBar("list");listToolBar->addWidget(listLabel);listToolBar->addWidget(listComboBox);listToolBar->addSeparator();listToolBar->addActions(actGrp->actions());
}void ImgProcessor::loadFile(QString filename)
{// 读取文件内容功能printf("file Name:%s\n", (char*)filename.data());QFile file(filename);if(file.open(QIODevice::ReadOnly|QIODevice::Text)){QTextStream textStream(&file);while(!textStream.atEnd()){showWidget->text->append(textStream.readLine());printf("read line\n");}printf("end\n");}
}void ImgProcessor::ShowNewFile()
{// 新建文件功能ImgProcessor *newImgProcessor = new ImgProcessor;newImgProcessor->show();
}void ImgProcessor::ShowOpenFile()
{// 打开文件功能fileName = QFileDialog::getOpenFileName(this);if(!fileName.isEmpty()){if(showWidget->text->document()->isEmpty()){loadFile(fileName);}else{ImgProcessor *newImgProcessor = new ImgProcessor;newImgProcessor->show();newImgProcessor->loadFile(fileName);}}
}void ImgProcessor::ShowPrintText()
{// 实现打印文本功能QPrinter printer;QPrintDialog printDialog(&printer,this);if(printDialog.exec()){// 获得QTextEdit对象的文档QTextDocument *doc = showWidget->text->document();doc->print(&printer);}
}void ImgProcessor::ShowPrintImage()
{// 实现打印图像功能QPrinter printer; //新建一个QPainter对象QPrintDialog printDialog(&printer, this);if(printDialog.exec()){QPainter painter(&printer);QRect rect = painter.viewport();// 获得QPainter对象的视图矩形区域QSize size =  img.size();/* 按照图形的比例大小重新设置视图矩形区域**/size.scale(rect.size(), Qt::KeepAspectRatio);painter.setWindow(img.rect()); // 设置QPainter窗口大小为图像的大小painter.drawImage(0,0,img);// 打印图像}
}void ImgProcessor::ShowZoomIn()
{// 实现图形放大功能if(img.isNull()){return;}QMatrix matrix;matrix.scale(2,2); //按照2倍比例对水平和垂直方向进行放大img = img.transformed(matrix);showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}void ImgProcessor::ShowZoomOut()
{// 实现图形缩小功能if(img.isNull()){return;}QMatrix matrix;matrix.scale(0.5,0.5);//按照0.5倍比例对水平和垂直方向进行缩水img = img.transformed(matrix);showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}void ImgProcessor::ShowRotate90()
{// 旋转90度if(img.isNull())return;QMatrix matrix;matrix.rotate(90);img=img.transformed(matrix);showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}void ImgProcessor::ShowRotate180()
{// 旋转180度if(img.isNull())return;QMatrix matrix;matrix.rotate(180);img=img.transformed(matrix);showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}
void ImgProcessor::ShowRotate270()
{// 旋转270度if(img.isNull())return;QMatrix matrix;matrix.rotate(270);img=img.transformed(matrix);showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}void ImgProcessor::ShowMirrorVertical()
{ // 图形的纵向镜像if(img.isNull())return;img = img.mirrored(false,true);showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}void ImgProcessor::ShowMirrorHorizontal()
{// 图形的横向镜像if(img.isNull())return;img = img.mirrored(true,false);showWidget->imageLabel->setPixmap(QPixmap::fromImage(img));
}void ImgProcessor::ShowFontComboBox(QString comboStr)
{QTextCharFormat fmt;fmt.setFontFamily(comboStr);mergeFormat(fmt);
}void ImgProcessor::ShowSizeSpinBox(QString spinValue)
{QTextCharFormat fmt;fmt.setFontPointSize(spinValue.toFloat());showWidget->text->mergeCurrentCharFormat(fmt);
}void ImgProcessor::ShowBoldBtn()
{  // 设置粗体QTextCharFormat fmt;fmt.setFontWeight(boldBtn->isChecked()?QFont::Bold:QFont::Normal);showWidget->text->mergeCurrentCharFormat(fmt);
}void ImgProcessor::ShowItalicBtn()
{QTextCharFormat fmt;fmt.setFontItalic(italicBtn->isChecked());showWidget->text->mergeCurrentCharFormat(fmt);
}void ImgProcessor::ShowUnderlineBtn()
{QTextCharFormat fmt;fmt.setFontUnderline(underlineBtn->isChecked());showWidget->text->mergeCurrentCharFormat(fmt);
}void ImgProcessor::ShowColorBtn()
{QColor color = QColorDialog::getColor(Qt::red,this);if(color.isValid()){QTextCharFormat fmt;fmt.setForeground(color);showWidget->text->mergeCurrentCharFormat(fmt);}
}void ImgProcessor::ShowCurrentFormatChanged(const QTextCharFormat &fmt)
{fontComboBox->setCurrentIndex(fontComboBox->findText((fmt.fontFamily())));sizeComboBox->setCurrentIndex(sizeComboBox->findText(QString::number(fmt.fontPointSize())));boldBtn->setChecked(fmt.font().bold());italicBtn->setChecked(fmt.fontItalic());underlineBtn->setChecked(fmt.fontUnderline());
}void ImgProcessor::ShowList(int index)
{// 排序QTextCursor cursor = showWidget->text->textCursor();if(index!=0){QTextListFormat::Style style = QTextListFormat::ListDisc;switch(index){case 1:style = QTextListFormat::ListDisc;break;case 2:style = QTextListFormat::ListCircle;break;case 3:style = QTextListFormat::ListSquare;break;case 4:style = QTextListFormat::ListDecimal;break;case 5:style = QTextListFormat::ListLowerAlpha;break;case 6:style = QTextListFormat::ListUpperAlpha;break;case 7:style = QTextListFormat::ListLowerRoman;break;case 8:style = QTextListFormat::ListUpperRoman;break;}/*  设置缩进值 */cursor.beginEditBlock();QTextBlockFormat blockFmt = cursor.blockFormat();QTextListFormat listFmt;if(cursor.currentList()){listFmt = cursor.currentList()->format();}else{listFmt.setIndent(blockFmt.indent()+1);blockFmt.setIndent(0);cursor.setBlockFormat(blockFmt);}listFmt.setStyle(style);cursor.createList(listFmt);cursor.endEditBlock();}else{QTextBlockFormat bfmt;bfmt.setObjectIndex(-1);cursor.mergeBlockFormat(bfmt);}
}void ImgProcessor::ShowAlignment(QAction *act)
{// 段落对齐if(act==leftAction)showWidget->text->setAlignment(Qt::AlignLeft);if(act==rightAction)showWidget->text->setAlignment(Qt::AlignRight);if(act==centerAction)showWidget->text->setAlignment(Qt::AlignCenter);if(act==justifyAction)showWidget->text->setAlignment(Qt::AlignJustify);
}void ImgProcessor::ShowCursorPositionChanged()
{//响应文本中光标位置发生改变的信号if(showWidget->text->alignment()==Qt::AlignLeft)leftAction->setChecked(true);if(showWidget->text->alignment()==Qt::AlignRight)rightAction->setChecked(true);if(showWidget->text->alignment()==Qt::AlignCenter)centerAction->setChecked(true);if(showWidget->text->alignment()==Qt::AlignJustify)justifyAction->setChecked(true);
}void ImgProcessor::mergeFormat(QTextCharFormat format)
{QTextCursor cursor = showWidget->text->textCursor();if(!cursor.hasSelection())cursor.select(QTextCursor::WordUnderCursor);cursor.mergeCharFormat(format);showWidget->text->mergeCurrentCharFormat(format);
}

  

showwidget.h 代码:

#ifndef SHOWWIDGET_H
#define SHOWWIDGET_H#include <QWidget>
#include <QImage>
#include <QLabel>
#include <QTextEdit>
#include <QHBoxLayout>class ShowWidget : public QWidget
{Q_OBJECT
public:explicit ShowWidget(QWidget *parent = nullptr);QImage img;QLabel *imageLabel;QTextEdit *text;signals:
public slots:
};#endif // SHOWWIDGET_H

  

showwidget.cpp代码

#include "showwidget.h"ShowWidget::ShowWidget(QWidget *parent) : QWidget(parent)
{imageLabel =new QLabel;imageLabel->setScaledContents(true);text = new QTextEdit;QHBoxLayout *mainLayout = new QHBoxLayout(this);mainLayout->addWidget(imageLabel);mainLayout->addWidget(text);
}

  在Qt5中,主窗体(MainWindow)是应用程序的核心组件,它通常承载着应用的主要功能和界面元素。在这个"文本编辑器"案例中,我们将深入探讨如何利用Qt5库来创建一个功能丰富的文本编辑器。Qt是一个跨平台的C++图形用户界面应用程序框架,提供了丰富的API来处理UI设计、事件处理以及与其他系统交互等功能。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/828516.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

鸿蒙开发案例:水平仪

【1】引言(完整代码在最后面) 高仿纯血鸿蒙Next的水平仪效果。主要功能包括: 1. 倾斜角度检测:通过注册加速度传感器事件监听器,实时获取设备的前后倾斜角度(pitch)和左右倾斜角度(roll)。 2. 角度计算与更新:根据传感器数据计算新的倾斜角度,如果新角度与旧角度的变…

【YOLOv11改进 - 注意力机制】EMA(Efficient Multi-Scale Attention):基于跨空间学习的高效多尺度注意力

介绍摘要 通道或空间注意力机制在许多计算机视觉任务中表现出显著的效果,可以生成更清晰的特征表示。然而,通过通道维度缩减来建模跨通道关系可能会对提取深度视觉表示带来副作用。本文提出了一种新颖高效的多尺度注意力(EMA)模块。该模块着重于保留每个通道的信息并减少计…

UIAbility组件生命周期

当用户打开、切换和返回到对应应用时,应用中的UIAbility实例会在其生命周期的不同状态之间转换。UIAbility类提供了一系列回调,通过这些回调可以知道当前UIAbility实例的某个状态发生改变,会经过UIAbility实例的创建和销毁,或者UIAbility实例发生了前后台的状态切换。 UIAb…

quartz集群增强版

quartz集群增强版😘转载请著名出处https://www.cnblogs.com/funnyzpc/p/18534034 这是除了mee_admin之外,投入时间精力最多的一次开源了,quartz集群增强版前前后后花费了我四月有余的时间精力开发而来,实属不易~ 先简要的说下:quartz集群增强版由quartz的 2.3.2 版本改…

数据结构_链表_双向循环链表 栈 的初始化、插入、删除、修改、查询打印(基于C语言实现)

一、双向循环链表的原理与应用 双向循环链表与双向链表的区别:指的是双向循环链表的首结点中的prev指针成员指向链表的尾结点,并且双向循环链表的尾结点里的next指针成员指向链表的首结点,所以双向循环链表也属于环形结构。由于带头结点更加方便用户进行数据访问,所以本次创…

[63] (多校联训) A层冲刺NOIP2024模拟赛19

lhx 对 \((\ln n)^{\ln n}\) 求导求出一个形如 \(\frac{1}{n\ln n\ln\ln n}\) 的东西A.图书管理 说一种很好玩的 \(n^2\log n\) 做法(因为动态中位数我只会这个) 对顶堆: 就是你开一个大根堆和一个小根堆,然后把它们怼在一起,钦定比中位数大的放小根堆,小的放大根堆,这样…

基于Java+SpringBoot心理测评心理测试系统功能实现六

三、部分系统功能试卷试题信息业务逻辑层Service、试卷试题题型信息业务逻辑层Service、角色信息业务逻辑层Service、用户信息业务逻辑层Service、前台用户信息业务逻辑层Service一、前言介绍: 1.1 项目摘要 心理测评和心理测试系统在当代社会中扮演着越来越重要的角色。随着心…

基于Java+SpringBoot心理测评心理测试系统功能实现五

技术点:SpringBoot+SpringDataJPA+Mysql+HTML+Freemaker+Bootstrap 三、部分系统功能 关于我们信息业务逻辑层Service、封面图信息业务逻辑层Service、留言信息业务逻辑层Service、公告信息业务逻辑层Service、心理测试业务逻辑层Service一、前言介绍: 1.1 项目摘要 心理测评…

鸿蒙开发案例:七巧板

【1】引言(完整代码在最后面) 本文介绍的拖动七巧板游戏是一个简单的益智游戏,用户可以通过拖动和旋转不同形状的七巧板块来完成拼图任务。整个游戏使用鸿蒙Next框架开发,利用其强大的UI构建能力和数据响应机制,实现了流畅的用户体验。 【2】环境准备 电脑系统:windows 1…

windows MacBook 下载视频网站视频

下载yt-dlp github地址:https://github.com/yt-dlp/yt-dlp 下载:https://github.com/yt-dlp/yt-dlp/releases下载ffmpeg 官网:https://ffmpeg.org/解压后,只有bin下的这2个文件放C盘目录下 将下面这3个程序,挪到:C:\Windows\System32下载视频 在任意路径:cmd命令:yt-dl…

聊聊接口测试用例设计规范

1、通过性验证: 先按照接口文档传入所有必填字段并且字段值在正确范围内,预期返回正确结果 2、参数验证(正向/逆向):必填参数:针对每个必填参数,都设计一条参数为空的测试用例,接口错误信息返回正确 非必填参数:设计一条用例所有非必填的参数都传入值,非必填参数(类…

2287: 【例28.3】 数列分段

include <bits/stdc++.h> using namespace std; int n, m, sum, num; int main( ) { cin >> n >> m; for (int i=1;i<=n;i++) { int e; cin >> e; if (num+e>m) { sum++; num=e; } else { num+=e; } } cout << sum+1; return 0; } 反思:这…