#ifndef NORMALMENU_H
#define NORMALMENU_H
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSpacerItem>
class NormalMenu : public QFrame
{
Q_OBJECT
public:
NormalMenu(QWidget *parent = 0);
void setTestName(QString name);
void setPicture(QString pictureDir);
~NormalMenu();
private:
QHBoxLayout *horlayout;
QVBoxLayout *Vlayout;
QLabel *imageLabel;
QLabel *testName;
QPushButton *esaybutton;
QPushButton *multbutton;
QPushButton *standardbutton;
QPushButton *mytestbutton;
QSpacerItem *horizontalSpacer;
};
#endif // WIDGET_H
#include "NormalMenu.h"
NormalMenu::NormalMenu(QWidget *parent)
: QFrame(parent)
{
QHBoxLayout *horlayout = new QHBoxLayout();
QVBoxLayout *Vlayout =new QVBoxLayout();
QLabel *testName = new QLabel();
testName->setText("Surge");
testName->setStyleSheet("QLabel {border: none;"
"background-color: black;"
"}");
testName->setAlignment(Qt::AlignCenter);
QPushButton *esaybutton = new QPushButton();
QPushButton *multbutton = new QPushButton();
QPushButton *standardbutton = new QPushButton();
QPushButton *mytestbutton = new QPushButton();
QSpacerItem *horizontalSpacer;
QString stylebutton("QPushButton {border: 2px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
"stop: 0 #766679, stop: 1 grey);"
"background-color: black;"
"border-bottom-color: grey;"
"color: white;"
"min-height: 30px;"
"min-width: 100px}"
"QPushButton:hover{border: 2px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
"stop: 0 #D2691E, stop: 1 grey);"
"border-bottom-color: grey;"
"background-color: black;"
"color: white;}"
"QPushButton::pressed{border: 2px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
"stop: 0 #c1c11e, stop: 1 white);"
"border-bottom-color: grey;"
"background-color: black;"
"color: white;}");
esaybutton->setStyleSheet(stylebutton);
multbutton->setStyleSheet(stylebutton);
standardbutton->setStyleSheet(stylebutton);
mytestbutton->setStyleSheet(stylebutton);
// QWidget *mywidget = new QWidget();
horizontalSpacer = new QSpacerItem(10, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
QLabel *imageLabel = new QLabel();
imageLabel->setStyleSheet("QLabel {border: none;"
"background-color: black;"
"}");
imageLabel->setAlignment(Qt::AlignCenter);
// imageLabel->setPixmap(QPixmap("://image/test1.png").scaled(QSize(100,80)));
esaybutton->setText("xx");
multbutton->setText("xx");
standardbutton->setText("xx");
mytestbutton->setText("xx");
horlayout->addWidget(standardbutton);
horlayout->addItem(horizontalSpacer);
horlayout->addWidget(mytestbutton);
horlayout->setSpacing(10);
Vlayout->addWidget(imageLabel);
Vlayout->addWidget(testName);
Vlayout->addWidget(esaybutton);
Vlayout->addWidget(multbutton);
Vlayout->addLayout(horlayout);
Vlayout->setSpacing(10);
setLayout(Vlayout);
setStyleSheet("QWidget{border: 4px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
"stop: 0 #ecb013, stop: 1 grey);"
"border-bottom-color: grey;"
"border-radius: 8px;"
"background-color: black;"
"color: white;""}");
// setAttribute(Qt::WA_NoSystemBackground);
// resize(160,380);
setMinimumSize(80,100);
}
void NormalMenu::setTestName(QString name)
{
testName->setText(name);
}
void NormalMenu::setPicture(QString pictureDir)
{
imageLabel->setPixmap(QPixmap(pictureDir).scaled(QSize(80,80)));
}
NormalMenu::~NormalMenu()
{
}
#ifndef VIEWWIDGET_H
#define VIEWWIDGET_H
#include <QWidget>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <QTimeLine>
#define PageMaxNub 5 //一页最大波形个数
#define OpacitySpeed 1.4 //透明度深度设置,越大约透明
#define scaleitSpeed 0.3 //波形尺寸缩小速度
#define OverlapLenth -60 //波形间距
#define HeightDecrease 100 //波形高度缩小多大
#define ScaleitMode 0
#define TiletMode 1
class ViewWidget : public QGraphicsView
{
Q_OBJECT
public:
ViewWidget(QWidget *parent = 0);
void addTestMenu(QString PixDir,QString TestTitle);
void CenterPageChange(quint8 page);
void DisplayModeSet(quint8 value);
void initDisplay(qreal initwith,qreal initheigh,int mode);
~ViewWidget();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private slots:
void Animatordisplay(int frame);
private:
QTimeLine m_pageAnimator;
QGraphicsScene scene;
QList<QGraphicsProxyWidget*> tab1;
quint8 DisplayMode;//模式选择,0为中间向两边缩小并透明度递增,1为平铺模式
bool m_bPressed;
bool Refresh;
QPoint m_point;
qreal m_offset;
// qreal xposition;
qreal PosYposition;
qreal CenterToCenter;
QRectF CenterGeometry;
qreal NormalHeight=380;
qreal NormalWith=230;
qreal m_translationChangeRate;
qreal m_scaleChangeRate;
qreal m_opacityChangeRate;
};
#endif // WIDGET_H
#include "ViewWidget.h"
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QScrollBar>
#include <QGraphicsItem>
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSpacerItem>
#include "NormalMenu.h"
#include <qdebug.h>
ViewWidget::ViewWidget(QWidget *parent)
: QGraphicsView(parent)
{
// resize(1280,800);
// setScene(&scene);
// scene.setSceneRect(0,0,1280,800);
// DisplayModeSet(0);
// scene.addPixmap(QPixmap("://image/bg.png"));
// addTestMenu("://image/test1.png","Surge");
// addTestMenu("://image/test1.png","Burst");
// addTestMenu("://image/test1.png","Dip");
// addTestMenu("://image/test1.png","PMF");
// addTestMenu("://image/test1.png","PFS");
// addTestMenu("://image/test1.png","PFMF");
// addTestMenu("://image/test1.png","APS");
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
setWindowFlag(Qt::FramelessWindowHint);
QGraphicsView::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QGraphicsView::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_bPressed=false;
connect(&m_pageAnimator, SIGNAL(frameChanged(int)), SLOT(Animatordisplay(int)));
m_pageAnimator.setDuration(1000);
m_pageAnimator.setFrameRange(0, 40);
}
void ViewWidget::addTestMenu(QString PixDir, QString TestTitle)
{
NormalMenu *my = new NormalMenu();
QList<QLabel *> text = my->findChildren<QLabel*>();
text.at(1)->setText(TestTitle);//.append(QString("%1").arg(tab1.count()))
text.at(0)->setPixmap(QPixmap(PixDir));//"://image/test1.png"
QGraphicsProxyWidget *pProxy = scene.addWidget(my);
pProxy->setMinimumSize(100,100);
tab1<<pProxy;
//requeue the test
quint8 initcenterlItem=1;
initcenterlItem=tab1.length()/2+1;
CenterPageChange(initcenterlItem);
}
//模式选择,0为中间向两边缩小并透明度递增,1为平铺模式
void ViewWidget::DisplayModeSet(quint8 value)
{
DisplayMode=value;
if(DisplayMode==ScaleitMode)
{
// CenterToCenter=scene.sceneRect().width()/PageMaxNub-10;
// NormalWith =scene.sceneRect().width()/PageMaxNub+100;
CenterToCenter=scene.sceneRect().width()/PageMaxNub-10;
NormalWith =scene.sceneRect().width()/PageMaxNub-OverlapLenth;
// NormalHeight =scene.height()*2/3;
NormalHeight =scene.height()-HeightDecrease;
CenterGeometry.setRect(scene.sceneRect().x()+scene.width()/2-NormalWith/2,scene.sceneRect().y()+scene.height()/2-NormalHeight/2,NormalWith,NormalHeight);
}
else
{
// CenterToCenter=NormalWith;
CenterToCenter=scene.sceneRect().width()/PageMaxNub-10;;
NormalHeight=scene.height()-HeightDecrease;
NormalWith=scene.width()/PageMaxNub-OverlapLenth;
// CenterGeometry.setRect(scene.sceneRect().x()+scene.width()/2-NormalWith/2,scene.sceneRect().y()+4,NormalWith,scene.height()-8);
CenterGeometry.setRect(scene.sceneRect().x()+scene.width()/2-NormalWith/2,scene.sceneRect().y()+scene.height()/2-NormalHeight/2,NormalWith,NormalHeight);
// NormalHeight=scene.height()-8;
}
// NormalWith=;
}
void ViewWidget::initDisplay(qreal initwith,qreal initheigh,int mode)
{
resize(initwith,initheigh);
setScene(&scene);
scene.setSceneRect(0,0,initwith,initheigh);
DisplayModeSet(mode);
// CenterGeometry.setRect(scene.sceneRect().x()+scene.width()/2-NormalWith/2,scene.sceneRect().y()+scene.height()/2-NormalHeight/2,NormalWith,NormalHeight);
scene.addPixmap(QPixmap("://image/bg.png"));
addTestMenu("://image/test1.png","a");
addTestMenu("://image/test1.png","b");
addTestMenu("://image/test1.png","c");
addTestMenu("://image/test1.png","d");
addTestMenu("://image/test1.png","e");
addTestMenu("://image/test1.png","f");
// addTestMenu("://image/test1.png","g");
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
scale(1,1);
setWindowFlag(Qt::FramelessWindowHint);
QGraphicsView::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QGraphicsView::setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_bPressed=false;
// connect(&m_pageAnimator, SIGNAL(frameChanged(int)), SLOT(Animatordisplay(int)));
// m_pageAnimator.setDuration(1000);
// m_pageAnimator.setFrameRange(0, 40);
}
void ViewWidget::CenterPageChange(quint8 page)
{
qreal xtemp;
qreal ytemp;
for(int i=0;i<tab1.length();i++)
{
qreal offx;
qreal scaleit=1;
// qreal o=1;
ytemp=CenterGeometry.y();
if((i+1)<page)
{
offx=(page-(i+1))*CenterToCenter;
xtemp=CenterGeometry.x()+NormalWith/2-offx-NormalWith/2;
tab1[i]->setGeometry(QRectF(xtemp,ytemp,NormalWith,NormalHeight));
}
else if ((i+1)>page)
{
offx=((i+1)-page)*CenterToCenter;
xtemp=CenterGeometry.x()+NormalWith/2+offx-NormalWith/2;
tab1[i]->setGeometry(QRectF(xtemp,ytemp,NormalWith,NormalHeight));
}
else
{
offx=0;
xtemp=CenterGeometry.x();
tab1[i]->setGeometry(QRectF(xtemp,ytemp,NormalWith,NormalHeight));
}
tab1[i]->setTransformOriginPoint(NormalWith/2,NormalHeight/2);
scaleit = 1-scaleitSpeed*(offx/(scene.sceneRect().width()/2));
if(DisplayMode==TiletMode)
{
scaleit = 1;
}
qreal Zvalue;
Zvalue=1000-abs(tab1[i]->pos().x()-CenterGeometry.x()+10)/10;
tab1[i]->setZValue(Zvalue);
tab1[i]->setScale(scaleit);
if(DisplayMode==TiletMode)
{
tab1[i]->setOpacity(1);
}
else
{
tab1[i]->setOpacity(1-offx/(scene.sceneRect().width()/OpacitySpeed));
}
qDebug() <<" i" <<i<<" " << scaleit;
}
}
ViewWidget::~ViewWidget()
{
}
void ViewWidget::mousePressEvent(QMouseEvent *event)
{
m_bPressed=true;
Refresh=false;
m_point = event->pos();
m_offset=0.0;
QGraphicsView::mousePressEvent(event);
}
void ViewWidget::mouseReleaseEvent(QMouseEvent *event)
{
m_bPressed=false;
if (m_pageAnimator.state() != QTimeLine::NotRunning)
{
m_pageAnimator.stop();
}
quint8 pagechange=0;
qreal Zvalue=0;
for(int i=0; i<tab1.length(); i++){
//get middle pos
if(Zvalue<tab1[i]->zValue())
{
pagechange=i+1;
Zvalue=tab1[i]->zValue();
}
}
// CenterPageChange(pagechange);
QGraphicsView::mouseReleaseEvent(event);
}
void ViewWidget::mouseMoveEvent(QMouseEvent *event)
{
if(m_bPressed){
if(Refresh==true)
{
m_point = event->pos();
Refresh=false;
}
m_offset = event->pos().x()-m_point.x();
// if(m_offset>0)
// {
// if(m_offset>28) m_offset=28;
// }
// else if(m_offset<0)
// {
// if(m_offset<-28) m_offset=-28;
// }
if (m_pageAnimator.state() == QTimeLine::NotRunning)
{
m_pageAnimator.start();
}
}
QGraphicsView::mouseMoveEvent(event);
}
void ViewWidget::Animatordisplay(int frame)
{
qreal tempOffSet=m_offset;
if(abs(tempOffSet)>=1)
{
for(int i=0; i<tab1.length(); i++){
qreal nowposX;
qreal nowposY;
qreal nowCentel;
qreal nowoffsetToMiddleScene;
nowCentel=tab1[i]->geometry().x()+tab1[i]->geometry().width()/2+tempOffSet;
nowoffsetToMiddleScene=abs(nowCentel-(CenterGeometry.x()+NormalWith/2));
nowposX=(nowCentel-NormalWith/2);
nowposY=CenterGeometry.y();
tab1[i]->setGeometry(QRectF(nowposX,nowposY,NormalWith,NormalHeight));
qreal scaleit = 1-scaleitSpeed*(nowoffsetToMiddleScene/(scene.sceneRect().width()/2));
if(DisplayMode==TiletMode)
{
scaleit = 1;
}
tab1[i]->setScale(scaleit);
qreal Zvalue;
Zvalue=1000-abs(tab1[i]->pos().x()-CenterGeometry.x()+10)/10;
tab1[i]->setZValue(Zvalue);
if(DisplayMode==TiletMode)
{
tab1[i]->setOpacity(1);
}
else
{
tab1[i]->setOpacity(1-nowoffsetToMiddleScene/(scene.sceneRect().width()/OpacitySpeed));
}
}
m_offset=0.0;
Refresh=true;
}
}