1 Star 0 Fork 4

ysx1993/maple_album

forked from 屁股大象/maple_album 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
photoview.cpp 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
#include "photoview.h"
#include <QMouseEvent>
#include "photoscene.h"
#include <QFile>
#include <photo/photoitem.h>
#include <QKeyEvent>
PhotoView::PhotoView(QWidget *parent) : QGraphicsView(parent)
{
setAcceptDrops(true);
QFile file(":/resource/style/photo_view.qss");
if(file.open(QIODevice::ReadOnly))
{
QString qss = file.readAll();
file.close();
setStyleSheet(qss);
}
}
PhotoView::~PhotoView()
{
}
//void PhotoView::drawBackground(QPainter *painter, const QRectF &rect)
//{
// painter->fillRect(rect, QBrush(Qt::black));
//}
//void PhotoView::paintEvent(QPaintEvent *event)
//{
// QPainter p(this);
// p.fillRect(rect(), QBrush(Qt::black));
//// QGraphicsView::paintEvent(event);
//}
void PhotoView::wheelEvent(QWheelEvent *event)
{
PhotoScene* s = dynamic_cast<PhotoScene*>(const_cast<QGraphicsScene*>(scene()));
if(s)
{
PhotoItem* item = dynamic_cast<PhotoItem*>(s->GetSelected());
if(item)
{
int n = event->angleDelta().y();
item->ScaleItem(n > 0 ? 1 : -1);
return;
}
}
QGraphicsView::wheelEvent(event);
}
void PhotoView::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete)
{
auto list = scene()->selectedItems();
if(list.size() > 0)
{
QGraphicsItem* pItem = list[0];
scene()->removeItem(pItem);
delete pItem;
pItem = nullptr;
}
}
QGraphicsView::keyPressEvent(event);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/YinShiXing/maple_album.git
git@gitee.com:YinShiXing/maple_album.git
YinShiXing
maple_album
maple_album
master

搜索帮助