加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mainwindow.cpp 9.31 KB
一键复制 编辑 原始数据 按行查看 历史
编号001 提交于 2024-11-03 21:21 . init
#include "mainwindow.h"
#include <QPainter>
#include <QtStateMachine>
#include "RectItem.h"
#include "ReverseRectItem.h"
#include "UICanvasImageItem.h"
#include "animatedgifitem.h"
#include "chip.h"
#include<fstream>
#include <QScrollBar>
#include "ehome_img_btn.h"
#include "hv/http_client.hpp"
#include "hv/logger.hpp"
#include "hv/HttpClient.h"
using namespace std;
MainWindow *MainWindow::instance = 0;
MainWindow *MainWindow::Instance()
{
if (!instance) {
static QMutex mutex;
QMutexLocker locker(&mutex);
if (!instance) {
instance = new MainWindow;
}
}
return instance;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),scene(new QGraphicsScene(this)),
scene2(new MyScene()),m_header_buf(100),m_pixbuffer(5),
m_animation(this, "index")
{
setupUi(this);
graphic = new GraphicsItem;
scene2->addItem(graphic);
scene2->setGraphicsItem(graphic);
graphicsView->setRenderHint(QPainter::Antialiasing, false);
graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
m_animation.setDuration(400);
m_animation.setEasingCurve(QEasingCurve::InOutSine);
graphicsView->setRenderHint(QPainter::Antialiasing, true);
graphicsView->setFrameStyle(QFrame::NoFrame);
auto timer = new QTimer();
// QObject::connect(timer, &QTimer::timeout, [&]() {
// if(m_index ==m_lastindex ){
// qDebug()<<"============="<<m_index<<m_lastindex;
// return;
// }
// for (int i = 0; i < m_pixbuffer.size(); ++i) {
// QGraphicsItem *img = m_pixbuffer.at(i);
// int a = (i + m_index) ;
// qreal xs = 0;
// qreal ys = - 50 *(a%6);
// QPointF pos(xs, ys);
// // pos = QTransform().rotate(-20).map(pos);
// pos -= QPointF(0,50);
// img->setPos(pos);
// qDebug()<<ys<<xs;
// // static_cast<BlurEffect *>(icon->graphicsEffect())->setBaseLine(baseline);
// }
// m_lastindex = m_index;
// qDebug()<<"============="<<m_index;
// });
// timer->start(1000);
zoom->setMinimum(0);
zoom->setMaximum(500);
zoom->setValue(250);
this->graphicsView->setScene(scene);
this->graphicsView_2->setScene(scene2);
populateScene();
m_timer = new QTimer();
QObject::connect(m_timer, &QTimer::timeout, [&]() {
if(m_header_buf.size()>0){
QString filepath = m_header_buf.front();
if(QFile::exists(filepath)){
m_index=(m_index+1)%5;
QPixmap pix(filepath );
pix = pix.scaled(QSize(150,150),Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
if(pix.height()!=0){
auto item = new Pixmap(pix);
m_pixbuffer.push_back(item);
// m_textBuffer.push_back("感谢666");
scene->addItem(item);
}
} else{
// auto item = new Pixmap(filepath);
// item->setText(filepath);
// m_pixbuffer.push_back(item);
// scene->addItem(item);
}
m_header_buf.pop_front();
// for (int i = 0; i < m_pixbuffer.size(); ++i) {
// Pixmap *img = m_pixbuffer.at(i);
// img->setVisible(false);
// }
for (int i = 0; i < m_pixbuffer.size(); ++i) {
Pixmap *img = m_pixbuffer.at(i);
qreal xs = 0;
qreal ys = 160*i;
QPointF pos(xs, ys );
img->setZValue(1);
img->setPos(pos);
img->setVisible(true);
}
m_lastindex = m_index;
}
});
m_timer->start(1000);
// pushButton_3->m_resimg->getimage("http://p2-pro.a.yximgs.com/uhead/AB/2020/10/13/16/BMjAyMDEwMTMxNjM1MTNfNzI3NjE2OTQ2XzFfaGQyNjhfNjM=_s.jpg","23123123");
}
MainWindow::~MainWindow() {}
void MainWindow::append(QString name, QString msg)
{
// textEdit->append(name+" : "+msg.mid(1,msg.length()));
// m_header_buf.push_back(name+": "+msg.mid(1,msg.length()));
giftcontain->append(name+": "+msg.mid(1,msg.length()));
}
void MainWindow::appendGift(QString msg, QString usericon, QString gifticon)
{
auto list = msg.split("\n");
auto temp = list.at(list.length()-3)+" "+list.at(list.length()-2)+" "+list.at(list.length()-1);
auto m_AppPath = QGuiApplication::applicationDirPath()+"/";
if(!giftmap.contains(temp)){
giftmap.insert(temp,list.at(list.length()-1));
giftcontain->append(list.at(list.length()-3)+" "+list.at(list.length()-2)+" "+list.at(list.length()-1));
QString hname = list.at(list.length()-3);
QString gname = list.at(list.length()-2);
auto img = new ehome_img_btn();
img->m_resimg->getimage(usericon,hname);
// img->setMaximumSize(48,48);
// img->setMinimumSize(48,48);
// imagelist->addWidget(img);
m_header_buf.push_back(m_AppPath+"appres/"+hname+".jpg");
}
}
qreal MainWindow::index() const
{
return m_index;
}
void MainWindow::setIndex(qreal index)
{
m_index = index;
LOG_INFO<<"m_index:"<<m_index;
for (int i = 0; i < m_pixbuffer.size(); ++i) {
Pixmap *img = m_pixbuffer.at(i);
qreal xs = 0;
qreal posy = img->pixmap().height() * i;
QPointF pos(xs, posy+100);
img->setZValue(1);
img->setPos(pos);
}
}
void MainWindow::paintEvent(QPaintEvent *event)
{
}
void MainWindow::populateScene()
{
QImage image(":/1234.png");
QPixmap kineticPix(":/qt4logo.png");
QPixmap bgPix(":/1234.png");
bgPix = bgPix.scaled(QSize(100,100),Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
QList<Pixmap *> items;
// for (int i = 0; i < 10; ++i) {
// Pixmap *item = new Pixmap(bgPix);
// // item->setOffset(-bgPix.width()/2, -bgPix.height()/2);
// item->setZValue(i);
// item->setPos(QPointF(0, bgPix.height()* i));
// items << item;
// scene->addItem(item);
// }
// graphicsView->setBackgroundBrush(kineticPix);
}
void MainWindow::action(int idx)
{
m_index = idx;
LOG_INFO<<"m_index:"<<m_index;
}
void MainWindow::on_zoom_sliderMoved(int position)
{
qreal scale = qPow(qreal(2), (zoom->value() - 250) / qreal(50));
QTransform matrix;
matrix.scale(scale, scale);
graphicsView->setTransform(matrix);
// setResetButtonEnabled();
}
void MainWindow::on_pushButton_clicked()
{
}
#include <QLabel>
#include <QFileDialog>
void MainWindow::on_pushButton_2_clicked()
{
}
void MainWindow::on_pushButton_3_clicked()
{
QString url = QFileDialog::getOpenFileName(this, tr("Open Import File"), QString(),
tr("*.jpg;*.png;*.gif;"));
// QPixmap pix(url );
// graphicsView->setBackgroundBrush(pix);
auto temp = new RectItem(url);
// temp->setImage(url);
// temp->setItemResizeable(true);
auto sitem = new RectItem(url);
if (sitem) {
sitem->setParentItem(graphic);
// scene->setItemType(1);
}
// scene2->addItem(temp);
// scene2->addItem(sitem);
}
namespace hv{
static void test_http_async(HttpClient* cli, int seq, int* resp_cnt)
{
auto req = std::make_shared<HttpRequest>();
req->method = HTTP_GET;
req->url = "www.baidu.com";
req->timeout = 10;
cli->sendAsync(req, [seq, resp_cnt](const HttpResponsePtr& resp) {
std::string path = "async-result-" + std::to_string(seq) + ".log";
LOG_INFO << "CIES SDK Version: " << path;
*resp_cnt += 1;
});
}
}
#include <cpr/cpr.h>
void MainWindow::on_pushButton_4_clicked()
{
auto body = boost_json::serialize(boost_json::object{{"api_name","daily"},
{"params",{ {"ts_code", "688400.SH,688190.SH"}, {"trade_date","20241018"},
{"start_date","20241015"},
{"end_date","20241018"}}},
{"token", "9ad0f9ed0c45308e547940c674b658b18cc5a6972ff550a1d6c0b767"},
});
// auto body = boost_json::serialize(boost_json::object{{"api_name","realtime_quote"},
// {"params",{ {"ts_code", "688400.SH,688190.SH"}, {"src","dc"}}},
// {"token", "9ad0f9ed0c45308e547940c674b658b18cc5a6972ff550a1d6c0b767"},
// });
// LOG_INFO<<body;
cpr::Response r = cpr::Post(cpr::Url{"https://api.tushare.pro"},
cpr::Header{{"Content-Type", "application/json"}},
cpr::Body{body});
r.status_code; // 200
r.header["content-type"]; // application/json; charset=utf-8
r.text; // JSON text string
LOG_INFO << r.text;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化