init commit
This commit is contained in:
commit
2d92479892
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# User files
|
||||
*.user
|
41
PineapplePictures.pro
Normal file
41
PineapplePictures.pro
Normal file
|
@ -0,0 +1,41 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2019-09-26T23:36:07
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = PineapplePictures
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
graphicsview.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
graphicsview.h
|
||||
|
||||
FORMS +=
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
59
graphicsview.cpp
Normal file
59
graphicsview.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "graphicsview.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
GraphicsView::GraphicsView(QWidget *parent)
|
||||
: QGraphicsView (parent)
|
||||
{
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setStyleSheet("background-color: rgba(0, 0, 0, 180);"
|
||||
"border-radius: 3px;");
|
||||
}
|
||||
|
||||
void GraphicsView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem *item = itemAt(event->pos());
|
||||
if (!item) {
|
||||
event->ignore();
|
||||
// blumia: return here, or the QMouseEvent event transparency won't
|
||||
// work if we set a QGraphicsView::ScrollHandDrag drag mode.
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << item;
|
||||
|
||||
return QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void GraphicsView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem *item = itemAt(event->pos());
|
||||
if (!item) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
return QGraphicsView::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void GraphicsView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem *item = itemAt(event->pos());
|
||||
if (!item) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
return QGraphicsView::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void GraphicsView::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if(event->delta() > 0) {
|
||||
scale(1.25, 1.25);
|
||||
} else {
|
||||
scale(0.8, 0.8);
|
||||
}
|
||||
}
|
18
graphicsview.h
Normal file
18
graphicsview.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef GRAPHICSVIEW_H
|
||||
#define GRAPHICSVIEW_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
class GraphicsView : public QGraphicsView
|
||||
{
|
||||
public:
|
||||
GraphicsView(QWidget *parent = nullptr);
|
||||
|
||||
private:
|
||||
void mousePressEvent(QMouseEvent * event) override;
|
||||
void mouseMoveEvent(QMouseEvent * event) override;
|
||||
void mouseReleaseEvent(QMouseEvent * event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
};
|
||||
|
||||
#endif // GRAPHICSVIEW_H
|
11
main.cpp
Normal file
11
main.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
108
mainwindow.cpp
Normal file
108
mainwindow.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include "graphicsview.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QMovie>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsTextItem>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent)
|
||||
{
|
||||
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
this->setMinimumSize(610, 410);
|
||||
|
||||
m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity");
|
||||
m_fadeOutAnimation->setDuration(300);
|
||||
m_fadeOutAnimation->setStartValue(1);
|
||||
m_fadeOutAnimation->setEndValue(0);
|
||||
m_floatUpAnimation = new QPropertyAnimation(this, "geometry");
|
||||
m_floatUpAnimation->setDuration(300);
|
||||
m_floatUpAnimation->setEasingCurve(QEasingCurve::OutCirc);
|
||||
m_exitAnimationGroup = new QParallelAnimationGroup;
|
||||
m_exitAnimationGroup->addAnimation(m_fadeOutAnimation);
|
||||
m_exitAnimationGroup->addAnimation(m_floatUpAnimation);
|
||||
connect(m_exitAnimationGroup, &QParallelAnimationGroup::finished,
|
||||
this, &QMainWindow::close);
|
||||
|
||||
QGraphicsScene * scene = new QGraphicsScene(this);
|
||||
QGraphicsTextItem * textItem = scene->addText("Hello, world!");
|
||||
textItem->setDefaultTextColor(QColor("White"));
|
||||
|
||||
GraphicsView * test = new GraphicsView(this);
|
||||
test->setScene(scene);
|
||||
this->setCentralWidget(test);
|
||||
|
||||
m_closeButton = new QPushButton(test);
|
||||
m_closeButton->setFlat(true);
|
||||
m_closeButton->setFixedSize(50, 50);
|
||||
m_closeButton->setStyleSheet("QPushButton {"
|
||||
"background: transparent;"
|
||||
"}"
|
||||
"QPushButton:hover {"
|
||||
"background: red;"
|
||||
"}");
|
||||
|
||||
connect(m_closeButton, &QAbstractButton::clicked,
|
||||
this, &MainWindow::closeWindow);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton) {
|
||||
m_clickedOnWindow = true;
|
||||
m_oldMousePos = event->pos();
|
||||
qDebug() << m_oldMousePos;
|
||||
event->accept();
|
||||
}
|
||||
|
||||
return QMainWindow::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (event->buttons() & Qt::LeftButton && m_clickedOnWindow) {
|
||||
move(event->globalPos() - m_oldMousePos);
|
||||
event->accept();
|
||||
}
|
||||
|
||||
return QMainWindow::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
m_clickedOnWindow = false;
|
||||
|
||||
return QMainWindow::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
closeWindow();
|
||||
|
||||
return QMainWindow::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
m_closeButton->move(width() - m_closeButton->width(), 0);
|
||||
|
||||
return QMainWindow::resizeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::closeWindow()
|
||||
{
|
||||
QRect windowRect(this->geometry());
|
||||
m_floatUpAnimation->setStartValue(windowRect);
|
||||
m_floatUpAnimation->setEndValue(windowRect.adjusted(0, -80, 0, 0));
|
||||
m_floatUpAnimation->setStartValue(QRect(this->geometry().x(), this->geometry().y(), this->geometry().width(), this->geometry().height()));
|
||||
m_floatUpAnimation->setEndValue(QRect(this->geometry().x(), this->geometry().y()-80, this->geometry().width(), this->geometry().height()));
|
||||
m_exitAnimationGroup->start();
|
||||
}
|
35
mainwindow.h
Normal file
35
mainwindow.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QPushButton>
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
protected slots:
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
void closeWindow();
|
||||
|
||||
private:
|
||||
QPoint m_oldMousePos;
|
||||
QPropertyAnimation *m_fadeOutAnimation;
|
||||
QPropertyAnimation *m_floatUpAnimation;
|
||||
QParallelAnimationGroup *m_exitAnimationGroup;
|
||||
QPushButton *m_closeButton;
|
||||
bool m_clickedOnWindow = false;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
Loading…
Reference in New Issue
Block a user