├── .gitattributes ├── .gitignore ├── CustomWidgets ├── QCardDialog.cpp ├── QCardDialog.h ├── QFlowProgressBar.cpp ├── QFlowProgressBar.h ├── QFlowProgressBase.cpp ├── QFlowProgressBase.h ├── QFlowProgressTab.cpp ├── QFlowProgressTab.h ├── QGallery.cpp ├── QGallery.h ├── QGalleryCard.cpp ├── QGalleryCard.h ├── QGalleryCardManager.cpp ├── QGalleryCardManager.h ├── QToast.cpp ├── QToast.h ├── qpictureslides.cpp ├── qpictureslides.h ├── qpixmapobject.cpp └── qpixmapobject.h ├── CustomWidgetsDialog.cpp ├── CustomWidgetsDialog.h ├── CustomWidgetsDialog.ui ├── QtCustomWidgetsExample.pro ├── README.md ├── ScreenShorts ├── FlowProgress.gif ├── QCard.gif ├── QGallery.gif ├── Sildes.gif └── Toast.gif ├── VersionLog.md └── main.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | *.slo 3 | *.lo 4 | *.o 5 | *.a 6 | *.la 7 | *.lai 8 | *.so 9 | *.dll 10 | *.dylib 11 | 12 | # Qt-es 13 | object_script.*.Release 14 | object_script.*.Debug 15 | *_plugin_import.cpp 16 | /.qmake.cache 17 | /.qmake.stash 18 | *.pro.user 19 | *.pro.user.* 20 | *.qbs.user 21 | *.qbs.user.* 22 | *.moc 23 | moc_*.cpp 24 | moc_*.h 25 | qrc_*.cpp 26 | ui_*.h 27 | *.qmlc 28 | *.jsc 29 | Makefile* 30 | *build-* 31 | 32 | # Qt unit tests 33 | target_wrapper.* 34 | 35 | # QtCreator 36 | *.autosave 37 | 38 | # QtCreator Qml 39 | *.qmlproject.user 40 | *.qmlproject.user.* 41 | 42 | # QtCreator CMake 43 | CMakeLists.txt.user* 44 | -------------------------------------------------------------------------------- /CustomWidgets/QCardDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "QCardDialog.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | QCardDialog::QCardDialog(QWidget* parent):QDialog(parent), 9 | m_bIsCloseIconShow(false),m_nRectangleRadius(30) 10 | { 11 | setWindowFlags(windowFlags()|Qt::FramelessWindowHint|Qt::Popup); 12 | setAttribute(Qt::WA_TranslucentBackground); 13 | resize(400,300); 14 | m_backgroundColor.setRgb(255,255,255); 15 | m_bIsWindowMoveFlag=false; 16 | } 17 | 18 | QCardDialog::~QCardDialog() 19 | { 20 | 21 | } 22 | 23 | void QCardDialog::paintEvent(QPaintEvent* event) 24 | { 25 | Q_UNUSED(event); 26 | QPainter painter(this); 27 | painter.setRenderHint(QPainter::Antialiasing,true); 28 | QPen emptyPen(Qt::NoPen); 29 | QBrush emptyBrush(Qt::NoBrush); 30 | 31 | QRect dialogRect=rect(); 32 | dialogRect.setWidth(dialogRect.width()*0.95); 33 | dialogRect.setHeight(dialogRect.height()*0.95); 34 | 35 | if(dialogRect.isValid()) 36 | { 37 | painter.setBrush(emptyBrush); 38 | QColor clr(0,0,0,50); 39 | for(int i=0;i<10;i++) 40 | { 41 | QPainterPath path; 42 | path.setFillRule(Qt::WindingFill); 43 | path.addRoundedRect(i+2,i+2,dialogRect.width(),dialogRect.height(),m_nRectangleRadius,m_nRectangleRadius); 44 | clr.setAlpha(150-qSqrt(i)*50); 45 | painter.setPen(clr); 46 | painter.drawPath(path); 47 | } 48 | 49 | QBrush backgroundBrush(m_backgroundColor); 50 | painter.setBrush(backgroundBrush); 51 | painter.setPen(emptyPen); 52 | painter.drawRoundedRect(dialogRect,m_nRectangleRadius,m_nRectangleRadius); 53 | 54 | if(m_bIsCloseIconShow) 55 | { 56 | if(!m_btnCloseRegion.isEmpty()) 57 | { 58 | painter.save(); 59 | QRect rect=m_btnCloseRegion.boundingRect(); 60 | painter.translate(rect.x(),rect.y()); 61 | QPen blackPen(QBrush(QColor(30,30,30)),3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin); 62 | painter.setBrush(emptyBrush); 63 | painter.setPen(blackPen); 64 | painter.drawLine(1,1,rect.width()-1,rect.height()-1); 65 | painter.drawLine(1,rect.height()-1,rect.width()-1,1); 66 | painter.restore(); 67 | } 68 | } 69 | } 70 | } 71 | 72 | void QCardDialog::enterEvent(QEvent*) 73 | { 74 | m_bIsCloseIconShow=true; 75 | update(); 76 | } 77 | 78 | void QCardDialog::leaveEvent(QEvent*) 79 | { 80 | m_bIsCloseIconShow=false; 81 | update(); 82 | } 83 | 84 | void QCardDialog::mouseReleaseEvent(QMouseEvent* e) 85 | { 86 | m_bIsWindowMoveFlag=false; 87 | if(!m_btnCloseRegion.isEmpty() && 88 | m_btnCloseRegion.contains(e->pos())) 89 | { 90 | this->done(QDialog::Accepted); 91 | //this->finished(QDialog::Accepted); 92 | } 93 | } 94 | 95 | void QCardDialog::resizeEvent(QResizeEvent* e) 96 | { 97 | QSize newSize=e->size(); 98 | int nIconSize=static_cast(qMin(newSize.width()*0.04,newSize.height()*0.04)); 99 | if(nIconSize>10) 100 | { 101 | int nStartX=static_cast(newSize.width()-nIconSize-newSize.width()*0.1); 102 | int nStartY=static_cast(newSize.height()*0.05); 103 | m_btnCloseRegion=QRegion(nStartX,nStartY,nIconSize,nIconSize); 104 | } 105 | else 106 | { 107 | m_btnCloseRegion=QRegion(); 108 | } 109 | } 110 | 111 | void QCardDialog::mouseMoveEvent(QMouseEvent* event) 112 | { 113 | if(m_bIsWindowMoveFlag) 114 | { 115 | QPoint ptCurrentGlobal=event->globalPos(); 116 | int moveX=ptCurrentGlobal.x()-m_ptMousePress.x(); 117 | int moveY=ptCurrentGlobal.y()-m_ptMousePress.y(); 118 | //setGeometry(QRect(currenRect.x()+moveX,currenRect.y()+moveY,currenRect.width(),currenRect.height())); 119 | move(x()+moveX,y()+moveY); 120 | m_ptMousePress=ptCurrentGlobal; 121 | } 122 | QDialog::mouseMoveEvent(event); 123 | } 124 | 125 | void QCardDialog::mousePressEvent(QMouseEvent* event) 126 | { 127 | if(event->button()==Qt::LeftButton && 128 | event->pos().y()<=size().height()*0.15) 129 | { 130 | m_ptMousePress=event->globalPos(); 131 | m_bIsWindowMoveFlag=true; 132 | } 133 | else 134 | { 135 | m_bIsWindowMoveFlag=false; 136 | } 137 | QDialog::mousePressEvent(event); 138 | } 139 | -------------------------------------------------------------------------------- /CustomWidgets/QCardDialog.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * Copyright(C) 2019,保留所有权利。( All rights reserved. ) 3 | * FileName:QCardDialog.h 4 | * Author:Ln_Jan 5 | * Version:v1.0.0 6 | * Date:2019-04-16 7 | * Description:卡片式对话框 8 | * Others: 9 | * Function List: 10 | * History: 11 | * 12 | **********************************************************************************/ 13 | #ifndef QCARDDIALOG_H 14 | #define QCARDDIALOG_H 15 | #include 16 | #include 17 | #include 18 | 19 | class QCardDialog : public QDialog 20 | { 21 | public: 22 | QCardDialog(QWidget* parent=nullptr); 23 | ~QCardDialog(); 24 | void SetRectRadius(int nRadius){m_nRectangleRadius=nRadius;} 25 | int GetRectRadius(){return m_nRectangleRadius;} 26 | void SetBackgroundColor(const QColor& color){m_backgroundColor=color;} 27 | const QColor& GetBackgroundColor(){return m_backgroundColor;} 28 | protected: 29 | void paintEvent(QPaintEvent *event) override; 30 | void leaveEvent(QEvent *event) override; 31 | void enterEvent(QEvent *event) override; 32 | void mouseReleaseEvent(QMouseEvent *event) override; 33 | void resizeEvent(QResizeEvent *event) override; 34 | void mouseMoveEvent(QMouseEvent* event) override; 35 | void mousePressEvent(QMouseEvent* event) override; 36 | private: 37 | bool m_bIsCloseIconShow; 38 | int m_nRectangleRadius; 39 | QColor m_backgroundColor; 40 | QRegion m_btnCloseRegion; 41 | QPoint m_ptMousePress; 42 | bool m_bIsWindowMoveFlag; 43 | }; 44 | 45 | #endif // QCARDDIALOG_H 46 | -------------------------------------------------------------------------------- /CustomWidgets/QFlowProgressBar.cpp: -------------------------------------------------------------------------------- 1 | #include "QFlowProgressBar.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | QFlowProgressBar::QFlowProgressBar(QWidget* parent):QFlowProgressBase(parent), 9 | m_barStyle(Styles::PROGRESS_BAR_CIRCLE_1) 10 | { 11 | Init(); 12 | } 13 | 14 | QFlowProgressBar::QFlowProgressBar(const QStringList& strDetailList,const Styles& style,QWidget* parent) 15 | :QFlowProgressBase(strDetailList,parent),m_barStyle(style) 16 | { 17 | Init(); 18 | CalculeStepIconRect(m_vecStepIconRect); 19 | } 20 | 21 | void QFlowProgressBar::Init() 22 | { 23 | m_clrFinishNumber.setRgb(255,255,255); 24 | } 25 | 26 | 27 | void QFlowProgressBar::paintEvent(QPaintEvent* ) 28 | { 29 | QPainter painter(this); 30 | painter.setRenderHint(QPainter::Antialiasing); 31 | if(m_barStyle==Styles::PROGRESS_BAR_CIRCLE_1) 32 | { 33 | DrawCircle1Style(painter); 34 | } 35 | else if(m_barStyle==Styles::PROGRESS_BAR_CIRCLE_2) 36 | { 37 | DrawCircle2Style(painter); 38 | } 39 | else if(m_barStyle==Styles::PROGRESS_BAR_RECT) 40 | { 41 | DrawRectangleStyle(painter); 42 | } 43 | else 44 | { 45 | DrawCircle1Style(painter); 46 | } 47 | } 48 | 49 | void QFlowProgressBar::mouseReleaseEvent(QMouseEvent* e) 50 | { 51 | QPoint pt=e->pos(); 52 | int iPos=0; 53 | foreach(QRect rt,m_vecStepIconRect) 54 | { 55 | if(rt.contains(pt,true)) 56 | { 57 | qDebug()<<"iPos clicked"<(size().width()*0.9); 74 | int nProgressHeight=static_cast(size().height()*0.07); 75 | int nTotalStepIconLen=static_cast(nProgressLen*0.88); 76 | int nIconSize=static_cast((nTotalStepIconLen/(nStepNums-1))*0.15); 77 | //int nIconStep=(nTotalStepIconLen/(nStepNums-1))-nIconSize; 78 | int nIconStep=(nTotalStepIconLen/(nStepNums-1)); 79 | int nTextGap=0; 80 | int nTextMaxLen=static_cast(nIconStep*0.8); 81 | 82 | //画背景的进度条 83 | int nStartX=static_cast(size().width()*0.05); 84 | int nStartY=static_cast(size().height()*0.15); 85 | 86 | QBrush backgroundBrush(GetBackgroundColor()); 87 | QBrush finishedBrush(GetFinishedBackgroundColor()); 88 | QPen emptyPen(Qt::NoPen); 89 | painter.setPen(emptyPen); 90 | painter.setBrush(backgroundBrush); 91 | painter.drawRoundedRect(nStartX,nStartY,nProgressLen,nProgressHeight,nProgressHeight,nProgressHeight); 92 | 93 | //画出完成的进度 94 | if(GetCurrentStep()>0) 95 | { 96 | int nFinishedProgressLen=static_cast(nProgressLen*0.05+(GetCurrentStep()-1)*nIconStep+nIconStep/2); 97 | nFinishedProgressLen=qMin(nFinishedProgressLen,nProgressLen); 98 | painter.setBrush(finishedBrush); 99 | painter.drawRoundedRect(nStartX,nStartY,nFinishedProgressLen,nProgressHeight,nProgressHeight,nProgressHeight); 100 | } 101 | 102 | int nIconStartY=nStartY-(qMax(nIconSize-nProgressHeight,0)/2); 103 | 104 | QPen iconBorderPen(QBrush(GetBackgroundColor()),nIconSize*0.2); 105 | QBrush whiteBrush(Qt::white); 106 | QFont ftNumber; 107 | QFont ftText; 108 | ftNumber.setPointSize(9); 109 | ftText.setPointSize(12); 110 | 111 | painter.save(); 112 | 113 | painter.translate(nStartX+nProgressLen*0.05,nIconStartY); 114 | 115 | for(int i=0;i((nCurrentXOffset+nIconSize*0.5)-textSize.width()/2); 146 | int nTextStartY=static_cast(nIconSize*1.4+nTextGap); 147 | painter.setFont(ftText); 148 | if(i(size().width()*0.9); 162 | int nProgressHeight=static_cast(size().height()*0.07); 163 | int nTotalStepIconLen=static_cast(nProgressLen*0.88); 164 | int nIconSize=static_cast((nTotalStepIconLen/(nStepNums-1))*0.15); 165 | int nIconStep=(nTotalStepIconLen/(nStepNums-1)); 166 | int nTextGap=static_cast(size().height()*0.02); 167 | int nProgressGap=static_cast(size().height()*0.02); 168 | int nTextMaxLen=static_cast(nIconStep*0.8); 169 | 170 | //画背景的进度条 171 | int nStartX=static_cast(size().width()*0.05); 172 | int nStartY=static_cast(size().height()*0.15); 173 | 174 | int nProgressStartY=static_cast(nStartY+nIconSize*1.3+nProgressGap); 175 | 176 | QBrush backgroundBrush(GetBackgroundColor()); 177 | QBrush finishedBrush(GetFinishedBackgroundColor()); 178 | QPen emptyPen(Qt::NoPen); 179 | painter.setPen(emptyPen); 180 | painter.setBrush(backgroundBrush); 181 | painter.drawRoundedRect(nStartX,nProgressStartY,nProgressLen,nProgressHeight,nProgressHeight,nProgressHeight); 182 | 183 | //画出完成的进度 184 | if(GetCurrentStep()>0) 185 | { 186 | int nFinishedProgressLen=static_cast(nProgressLen*0.05+(GetCurrentStep()-1)*nIconStep+nIconStep/2); 187 | nFinishedProgressLen=qMin(nFinishedProgressLen,nProgressLen); 188 | painter.setBrush(finishedBrush); 189 | painter.drawRoundedRect(nStartX,nProgressStartY,nFinishedProgressLen,nProgressHeight,nProgressHeight,nProgressHeight); 190 | } 191 | 192 | QPen iconBorderPen(QBrush(GetBackgroundColor()),nIconSize*0.2); 193 | QBrush whiteBrush(Qt::white); 194 | QFont ftNumber; 195 | QFont ftText; 196 | ftNumber.setPointSize(9); 197 | ftText.setPointSize(12); 198 | 199 | 200 | painter.save(); 201 | painter.translate(nStartX+nProgressLen*0.05,nStartY); 202 | 203 | for(int i=0;i((nCurrentXOffset+nIconSize*0.5)-textSize.width()/2); 256 | int nTextStartY=static_cast(nIconSize*1.3+nTextGap+nProgressGap+nProgressHeight); 257 | painter.setFont(ftText); 258 | if(i(size().width()*0.9); 271 | int nProgressWeight=static_cast(size().height()*0.005); 272 | int nIconSize=static_cast((nProgressLen/(nStepNums-1))*0.15); 273 | int nIconStep=nProgressLen/(nStepNums-1); 274 | int nTextGap=static_cast(size().height()*0.04); 275 | int nTextMaxLen=static_cast(nIconStep*0.8); 276 | const int SPACE_GAP=4; 277 | 278 | QBrush backgroundBrush(GetBackgroundColor()); 279 | QPen backgroundPen(GetBackgroundColor()); 280 | QPen emptyPen(Qt::NoPen); 281 | QBrush whiteBrush(Qt::white); 282 | QPen finishedNumberPen(QBrush(m_clrFinishNumber),2); 283 | QBrush finishedBrush(GetFinishedBackgroundColor()); 284 | QPen finishedPen(QBrush(GetFinishedBackgroundColor()),2); 285 | QFont ftNumber; 286 | QFont ftText; 287 | QPen backgroundLinePen(backgroundBrush,nProgressWeight); 288 | QPen finishedLinePen(finishedBrush,nProgressWeight); 289 | 290 | ftNumber.setPointSize(9); 291 | ftText.setPointSize(12); 292 | 293 | int nDrawStartX=static_cast(size().width()*0.05); 294 | int nDrawStartY=static_cast(size().height()*0.15); 295 | 296 | painter.save(); 297 | painter.translate(nDrawStartX,nDrawStartY); 298 | 299 | for(int i=0;i((nCurrentXOffset+nIconSize*0.5)-textSize.width()/2); 338 | int nTextStartY=static_cast(nIconSize+nTextGap); 339 | painter.setFont(ftText); 340 | painter.drawText(QRect(nTextStartX,nTextStartY,textSize.width(),textSize.height()),Qt::AlignCenter,strShowText); 341 | painter.setPen(emptyPen); 342 | if(i& vec) 386 | { 387 | int nStepNums=GetStepNums(); 388 | int nProgressLen=static_cast(size().width()*0.9); 389 | int nIconSize=static_cast((nProgressLen/(nStepNums-1))*0.2); 390 | int nIconStep=m_barStyle==Styles::PROGRESS_BAR_RECT?nProgressLen/(nStepNums-1):static_cast((nProgressLen*0.9)/(nStepNums-1)); 391 | 392 | int nStartX=m_barStyle==Styles::PROGRESS_BAR_RECT?static_cast(size().width()*0.05):static_cast(size().width()*0.07); 393 | int nStartY=static_cast(size().height()*0.15); 394 | 395 | vec.clear(); 396 | for(int i=0;i 17 | #include 18 | 19 | class QFlowProgressBar:public QFlowProgressBase 20 | { 21 | public: 22 | enum Styles{PROGRESS_BAR_CIRCLE_1,PROGRESS_BAR_CIRCLE_2,PROGRESS_BAR_RECT}; 23 | QFlowProgressBar(QWidget* parent=nullptr); 24 | 25 | QFlowProgressBar(const QStringList& strDetailList,const Styles& style=Styles::PROGRESS_BAR_CIRCLE_1,QWidget* parent=nullptr); 26 | 27 | /** 28 | * @brief SetProgressBarStyle 设置进度条的样式 29 | * @param style 样式设定 30 | * @details 31 | */ 32 | void SetProgressBarStyle(Styles style){m_barStyle=style;} 33 | /** 34 | * @brief GetProgressBarStyle 获取进度条的样式 35 | * @return 36 | */ 37 | Styles GetProgressBarStyle(){return m_barStyle;} 38 | 39 | void SetFinishedNumberColor(const QColor& color){m_clrFinishNumber=color;} 40 | 41 | const QColor& GetFinishedNumberColor(){return m_clrFinishNumber;} 42 | 43 | void SetStepMessageList(const QStringList& list) override; 44 | protected: 45 | void paintEvent(QPaintEvent* event) override; 46 | void mouseReleaseEvent(QMouseEvent* event) override; 47 | void CalculeStepIconRect(QVector& vec); 48 | private: 49 | Styles m_barStyle; 50 | QColor m_clrFinishNumber; 51 | QVector m_vecStepIconRect; 52 | 53 | void DrawCircle1Style(QPainter& painter); 54 | void DrawCircle2Style(QPainter& painter); 55 | void DrawRectangleStyle(QPainter& painter); 56 | void Init(); 57 | }; 58 | 59 | #endif // QFLOWPROGRESSBAR_H 60 | -------------------------------------------------------------------------------- /CustomWidgets/QFlowProgressBase.cpp: -------------------------------------------------------------------------------- 1 | #include "QFlowProgressBase.h" 2 | 3 | QFlowProgressBase::QFlowProgressBase(QWidget* parent):QLabel(parent),m_nCurrentStep(0),m_bIsAutoTextWidth(false), 4 | m_listener(nullptr) 5 | { 6 | Init(); 7 | } 8 | 9 | QFlowProgressBase::QFlowProgressBase(const QStringList& strDetailList,QWidget* parent):QLabel(parent), 10 | m_strStepList(strDetailList),m_nCurrentStep(0),m_bIsAutoTextWidth(false),m_listener(nullptr) 11 | { 12 | Init(); 13 | } 14 | 15 | 16 | void QFlowProgressBase::Init() 17 | { 18 | m_clrBackground.setRgb(200,200,200); 19 | m_clrFinishBackground.setRgb(40,220,20); 20 | } 21 | 22 | QSize QFlowProgressBase::GetDrawTextSize(const QString& strText,const QFont& ft) 23 | { 24 | QFontMetrics metrics(ft); 25 | QStringList ls=strText.split(QRegExp("\r\n|\n")); 26 | int nWidthInPixel=0; 27 | for(int i=0;inWidthInPixel?tmpWidth:nWidthInPixel; 31 | } 32 | int nHeightInPixel=(metrics.height())*ls.length()+(metrics.leading()*(ls.length()-1)); 33 | return QSize(nWidthInPixel,nHeightInPixel); 34 | } 35 | 36 | QString QFlowProgressBase::SplitTextFixWidth(const QString& strText,const QFont& ft,int nMaxWidth) 37 | { 38 | QString strTextCpy=strText; 39 | strTextCpy.replace(QRegExp("\r\n|\n"),""); 40 | QFontMetrics metrics(ft); 41 | int nTextWidth=metrics.horizontalAdvance(strTextCpy); 42 | if(nTextWidth<=nMaxWidth) 43 | { 44 | return strTextCpy; 45 | } 46 | QVector vecSplitIndex; 47 | vecSplitIndex.reserve(10); 48 | int nSplitFragmentNums=nTextWidth/nMaxWidth+1; 49 | int nSplitFragmentLen=strTextCpy.length()/nSplitFragmentNums; 50 | 51 | vecSplitIndex.push_back(0); 52 | for(int i=1;inMaxWidth) 66 | { 67 | nLen--; 68 | } 69 | else 70 | { 71 | break; 72 | } 73 | }while(1); 74 | vecSplitIndex[j+1]=vecSplitIndex[j]+nLen; 75 | } 76 | 77 | if(vecSplitIndex[vecSplitIndex.size()-1]!=strTextCpy.length()) 78 | { 79 | vecSplitIndex.push_back(strTextCpy.length()); 80 | } 81 | 82 | for(int i=1;i 4 | #include 5 | #include 6 | 7 | typedef void(*OnStepClickListener)(int); 8 | 9 | class QFlowProgressBase:public QLabel 10 | { 11 | Q_OBJECT 12 | public: 13 | QFlowProgressBase(QWidget* parent=nullptr); 14 | QFlowProgressBase(const QStringList& strDetailList,QWidget* parent=nullptr); 15 | 16 | int GetStepNums() 17 | { 18 | if(m_strStepList.empty()) 19 | { 20 | return 0; 21 | } 22 | return m_strStepList.size(); 23 | } 24 | 25 | /** 26 | * @brief SetStepMessageList 设置进度条的文字描述 27 | * @param list 28 | */ 29 | virtual void SetStepMessageList(const QStringList& list){m_strStepList=list;} 30 | /** 31 | * @brief GetStepMessageList 获取进度条的文字描述 32 | * @return 33 | */ 34 | const QStringList& GetStepMessageList(){return m_strStepList;} 35 | /** 36 | * @brief NextStep 跳转到下一步 37 | */ 38 | void NextStep() 39 | { 40 | if(m_nCurrentStep0) 52 | { 53 | m_nCurrentStep--; 54 | update(); 55 | } 56 | } 57 | 58 | void ChangeCurrentStep(int nStep) 59 | { 60 | if(nStep>=0 && nStep<=GetStepNums()) 61 | { 62 | m_nCurrentStep=nStep; 63 | update(); 64 | } 65 | } 66 | 67 | /** 68 | * @brief GetCurrentStep 获取当前的进度 69 | * @return 70 | */ 71 | int GetCurrentStep(){return m_nCurrentStep;} 72 | 73 | void SetAutoTextWidth(bool bAuto){m_bIsAutoTextWidth=bAuto;} 74 | 75 | bool GetAutoTextWidth(){return m_bIsAutoTextWidth;} 76 | 77 | void SetBackgroundColor(const QColor& color){m_clrBackground=color;} 78 | 79 | const QColor& GetBackgroundColor(){return m_clrBackground;} 80 | 81 | void SetFinishedBackgroundColor(const QColor& color){m_clrFinishBackground=color;} 82 | 83 | const QColor& GetFinishedBackgroundColor(){return m_clrFinishBackground;} 84 | 85 | void SetOnStepClickListener(OnStepClickListener l){m_listener=l;} 86 | 87 | OnStepClickListener GetOnStepClickListener(){return m_listener;} 88 | 89 | signals: 90 | void signals_stepClicked(int); 91 | 92 | protected: 93 | virtual void paintEvent(QPaintEvent* event)=0; 94 | 95 | virtual QSize GetDrawTextSize(const QString& strText,const QFont& ft); 96 | 97 | /** 98 | * @brief SplitTextFixWidth 根据给定的长度裁剪字符串 99 | * @param strText 100 | * @param ft 101 | * @param nMaxWidth 102 | * @return 103 | */ 104 | virtual QString SplitTextFixWidth(const QString& strText,const QFont& ft,int nMaxWidth); 105 | private: 106 | QStringList m_strStepList; 107 | int m_nCurrentStep; 108 | bool m_bIsAutoTextWidth; 109 | QColor m_clrBackground; 110 | QColor m_clrFinishBackground; 111 | OnStepClickListener m_listener; 112 | 113 | void Init(); 114 | }; 115 | 116 | #endif // QFLOWPROGRESSBASE_H 117 | -------------------------------------------------------------------------------- /CustomWidgets/QFlowProgressTab.cpp: -------------------------------------------------------------------------------- 1 | #include "QFlowProgressTab.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static QPainterPath GetTabPainterPath(const QRect& rt,int nType) 8 | { 9 | QPainterPath resultPath; 10 | resultPath.moveTo(rt.topLeft()); 11 | if(nType==0) 12 | { 13 | resultPath.lineTo(rt.bottomLeft()); 14 | } 15 | else 16 | { 17 | QPoint offsetPoint(static_cast(rt.width()*0.1),rt.height()/2); 18 | QPoint dstPoint=rt.topLeft()+offsetPoint; 19 | resultPath.lineTo(dstPoint); 20 | resultPath.lineTo(rt.bottomLeft()); 21 | } 22 | resultPath.lineTo(rt.bottomRight()); 23 | if(nType==2) 24 | { 25 | resultPath.lineTo(rt.topRight()); 26 | } 27 | else 28 | { 29 | QPoint offsetPoint(static_cast(rt.width()*0.1),-rt.height()/2); 30 | QPoint dstPoint=rt.bottomRight()+offsetPoint; 31 | resultPath.lineTo(dstPoint); 32 | resultPath.lineTo(rt.topRight()); 33 | } 34 | resultPath.lineTo(rt.topLeft()); 35 | return resultPath; 36 | } 37 | 38 | QFlowProgressTab::QFlowProgressTab(QWidget* parent):QFlowProgressBase(parent) 39 | { 40 | Init(); 41 | } 42 | 43 | QFlowProgressTab::QFlowProgressTab(const QStringList& strMessageList,QWidget* parent):QFlowProgressBase(strMessageList,parent) 44 | { 45 | Init(); 46 | } 47 | 48 | void QFlowProgressTab::Init() 49 | { 50 | SetBackgroundColor(QColor(230,230,230)); 51 | m_clrNormalText.setRgb(0,0,0); 52 | m_clrFinishedText.setRgb(255,255,255); 53 | m_clrNormalCircle.setRgb(210,210,210); 54 | m_clrFinishedCircle.setRgb(255,255,255); 55 | m_clrNormalNumber.setRgb(255,255,255); 56 | m_clrFinishedNumber=GetFinishedBackgroundColor(); 57 | } 58 | 59 | 60 | void QFlowProgressTab::DrawTabStyle(QPainter& painter) 61 | { 62 | int nStepNums=GetStepNums(); 63 | int nProgressLen=static_cast(size().width()*0.9); 64 | int nProgressHeight=static_cast(size().height()*0.6); 65 | int nCircleIconSize=static_cast(nProgressHeight*0.4); 66 | int nIconStep=nProgressLen/nStepNums; 67 | int nIconColGap=static_cast(nCircleIconSize*0.15); 68 | int nTextMaxLen=static_cast(nIconStep*0.7-(nIconColGap+nCircleIconSize)); 69 | 70 | if(nTextMaxLen<=0) 71 | { 72 | qWarning()<<"请调整控件宽高"; 73 | return; 74 | } 75 | 76 | QBrush backgroundBrush(GetBackgroundColor()); 77 | QBrush finishedBackgroundBrush(GetFinishedBackgroundColor()); 78 | QPen emptyPen(Qt::NoPen); 79 | QPen finishedNumberPen(QBrush(m_clrFinishedNumber),4); 80 | QPen normalNumberPen(QBrush(m_clrNormalNumber),4); 81 | QPen normalTextPen(m_clrNormalText); 82 | QPen finishedTextPen(m_clrFinishedText); 83 | QBrush finishedCircleBrush(m_clrFinishedCircle); 84 | QBrush normalCircleBrush(m_clrNormalCircle); 85 | QPen spaceLinePen(QBrush(Qt::white),1); 86 | QFont ftNumber; 87 | QFont ftText; 88 | 89 | ftNumber.setPointSize(9); 90 | ftText.setPointSize(12); 91 | ftNumber.setBold(true); 92 | 93 | int nDrawStartX=static_cast(size().width()*0.05); 94 | int nDrawStartY=static_cast(size().height()*0.2); 95 | 96 | for(int i=0;i(nIconStep*0.15),nIconStartOffset); 116 | painter.save(); 117 | painter.translate(nDrawStartX+nOffsetPos,nDrawStartY); 118 | int nIconStartY=(nProgressHeight-nCircleIconSize)/2; 119 | if(i(startX1+nIconStep*0.1); 160 | int endY1=startY1+nProgressHeight/2; 161 | int endX2=startX1; 162 | int endY2=startY1+nProgressHeight; 163 | painter.drawLine(startX1,startY1,endX1,endY1); 164 | painter.drawLine(endX1,endY1,endX2,endY2); 165 | } 166 | } 167 | 168 | void QFlowProgressTab::paintEvent(QPaintEvent*) 169 | { 170 | QPainter painter(this); 171 | painter.setRenderHint(QPainter::Antialiasing); 172 | DrawTabStyle(painter); 173 | } 174 | 175 | void QFlowProgressTab::CalculeStepIconRect(QVector& vec) 176 | { 177 | int nStepNums=GetStepNums(); 178 | int nProgressLen=static_cast(size().width()*0.9); 179 | int nProgressHeight=static_cast(size().height()*0.6); 180 | int nIconStep=nProgressLen/nStepNums; 181 | int nStartX=static_cast(size().width()*0.05); 182 | int nStartY=static_cast(size().height()*0.2); 183 | vec.clear(); 184 | for(int i=0;i vec; 194 | CalculeStepIconRect(vec); 195 | QPoint pt=e->pos(); 196 | int iPos=0; 197 | foreach(QRect rt,vec) 198 | { 199 | if(rt.contains(pt,true)) 200 | { 201 | ChangeCurrentStep(iPos+1); 202 | emit signals_stepClicked(iPos); 203 | if(GetOnStepClickListener()!=nullptr) 204 | { 205 | GetOnStepClickListener()(iPos); 206 | break; 207 | } 208 | } 209 | iPos++; 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /CustomWidgets/QFlowProgressTab.h: -------------------------------------------------------------------------------- 1 | #ifndef QFLOWPROGRESSTAB_H 2 | #define QFLOWPROGRESSTAB_H 3 | #include "QFlowProgressBase.h" 4 | #include 5 | #include 6 | 7 | class QFlowProgressTab:public QFlowProgressBase 8 | { 9 | public: 10 | QFlowProgressTab(QWidget* parent=nullptr); 11 | QFlowProgressTab(const QStringList& strMessageList,QWidget* parent=nullptr); 12 | void SetNormalTextColor(const QColor& clr){m_clrNormalText=clr;} 13 | const QColor& GetNormalTextColor(){return m_clrNormalText;} 14 | void SetFinishedTextColor(const QColor& clr){m_clrFinishedText=clr;} 15 | const QColor& GetFinishedTextColor(){return m_clrFinishedText;} 16 | void SetNormalCircleColor(const QColor& clr){m_clrNormalCircle=clr;} 17 | const QColor& GetNormalCircleColor(){return m_clrNormalCircle;} 18 | void SetFinishedCircleColor(const QColor& clr){m_clrFinishedCircle=clr;} 19 | const QColor& GetFinishedCircleColor(){return m_clrFinishedCircle;} 20 | void SetNormalNumberColor(const QColor& clr){m_clrNormalNumber=clr;} 21 | const QColor& GetNormalNumberColor(){return m_clrNormalNumber;} 22 | void SetFinishedNumberColor(const QColor& clr){m_clrFinishedNumber=clr;} 23 | const QColor& GetFinishedNumberColor(){return m_clrFinishedNumber;} 24 | protected: 25 | void paintEvent(QPaintEvent* event) override; 26 | void mouseReleaseEvent(QMouseEvent* event) override; 27 | void CalculeStepIconRect(QVector& vec);; 28 | private: 29 | void DrawTabStyle(QPainter& painter); 30 | void Init(); 31 | 32 | QColor m_clrNormalText; 33 | QColor m_clrFinishedText; 34 | QColor m_clrNormalCircle; 35 | QColor m_clrFinishedCircle; 36 | QColor m_clrNormalNumber; 37 | QColor m_clrFinishedNumber; 38 | }; 39 | 40 | #endif // QFLOWPROGRESSTAB_H 41 | -------------------------------------------------------------------------------- /CustomWidgets/QGallery.cpp: -------------------------------------------------------------------------------- 1 | #include "QGallery.h" 2 | #include 3 | 4 | QGallery::QGallery(QWidget *parent) : QWidget(parent) 5 | { 6 | m_clrBackground.setRgb(30,30,30); 7 | m_nCurrentCardIndex=0; 8 | m_nShowCardNums=11; 9 | connect(&m_galleryManager,SIGNAL(signals_transformPlay(int,int)),this,SLOT(slots_transformPlay(int,int))); 10 | } 11 | 12 | QGallery::~QGallery() 13 | { 14 | disconnect(&m_galleryManager,SIGNAL(signals_transformPlay(int,int)),this,SLOT(slots_transformPlay(int,int))); 15 | } 16 | 17 | bool QGallery::InitImageList(const QStringList& strImagePaths) 18 | { 19 | m_lstImages.clear(); 20 | foreach(QString str,strImagePaths) 21 | { 22 | QPixmap readPixmap; 23 | if(readPixmap.load(str)) 24 | { 25 | m_lstImages.push_back(readPixmap); 26 | } 27 | } 28 | if(m_lstImages.empty()) 29 | { 30 | m_galleryManager.ClearCache(); 31 | } 32 | else 33 | { 34 | QList showList; 35 | int nShowIndex=0; 36 | GetCurrentGalleryCards(showList,nShowIndex); 37 | m_galleryManager.ChangeGalleryCard(showList,nShowIndex,size()); 38 | } 39 | update(); 40 | return true; 41 | } 42 | 43 | void QGallery::ClearAllImages() 44 | { 45 | m_lstImages.clear(); 46 | m_galleryManager.ClearCache(); 47 | update(); 48 | } 49 | 50 | void QGallery::GetCurrentGalleryCards(QList& resultList,int& nIndex) 51 | { 52 | resultList.clear(); 53 | if(m_lstImages.empty()) 54 | { 55 | return; 56 | } 57 | int nHalfCardNums=m_nShowCardNums/2; 58 | int nLeftIndex=qMax(m_nCurrentCardIndex-nHalfCardNums,0); 59 | int nRightIndex=m_nCurrentCardIndex+nHalfCardNums; 60 | nIndex=m_nCurrentCardIndex-nLeftIndex; 61 | for(int i=nLeftIndex;im_lstImages.size()-1) 67 | { 68 | //int nAddEmptyCardNum=nHalfCardNums-(nRightIndex-nIndex); 69 | int nAddEmptyCardNum=nRightIndex-m_lstImages.size()+1; 70 | while(nAddEmptyCardNum>0) 71 | { 72 | QPixmap emptyPixmap; 73 | resultList.push_back(emptyPixmap); 74 | nAddEmptyCardNum--; 75 | } 76 | } 77 | } 78 | 79 | bool QGallery::InsertImage(const QString& strImagePath) 80 | { 81 | QPixmap pixmap; 82 | if(pixmap.load(strImagePath)) 83 | { 84 | m_lstImages.push_back(pixmap); 85 | } 86 | else 87 | { 88 | return false; 89 | } 90 | 91 | QList showList; 92 | int nShowIndex=0; 93 | GetCurrentGalleryCards(showList,nShowIndex); 94 | m_galleryManager.ChangeGalleryCard(showList,nShowIndex,size()); 95 | update(); 96 | return true; 97 | } 98 | 99 | void QGallery::SetShowCardNums(int nNums) 100 | { 101 | 102 | m_nShowCardNums=nNums; 103 | 104 | QList showList; 105 | int nShowIndex=0; 106 | GetCurrentGalleryCards(showList,nShowIndex); 107 | m_galleryManager.ChangeGalleryCard(showList,nShowIndex,size()); 108 | update(); 109 | } 110 | 111 | void QGallery::paintEvent(QPaintEvent *event) 112 | { 113 | Q_UNUSED(event) 114 | QPainter painter(this); 115 | 116 | painter.fillRect(QRect(0,0,size().width(),size().height()),QBrush(m_clrBackground)); 117 | 118 | QList cardList=m_galleryManager.GetGalleryCardList(); 119 | 120 | if(!cardList.empty()) 121 | { 122 | int nShowIndex=0; 123 | for(int i=0;i(cardList[i].GetRoateAngle())==0) 126 | { 127 | nShowIndex=i; 128 | break; 129 | } 130 | //cardList[i].DrawCard(painter); 131 | } 132 | 133 | for(int i=0;inShowIndex;j--) 139 | { 140 | cardList[j].DrawCard(painter); 141 | } 142 | cardList[nShowIndex].DrawCard(painter); 143 | } 144 | 145 | } 146 | 147 | void QGallery::slots_transformPlay(int nType,int nStatus) 148 | { 149 | if(nStatus==1) 150 | { 151 | if(nType==0) 152 | { 153 | m_nCurrentCardIndex++; 154 | } 155 | else 156 | { 157 | m_nCurrentCardIndex--; 158 | } 159 | QList showList; 160 | int nShowIndex=0; 161 | GetCurrentGalleryCards(showList,nShowIndex); 162 | m_galleryManager.ChangeGalleryCard(showList,nShowIndex,size()); 163 | } 164 | update(); 165 | } 166 | 167 | void QGallery::MoveStep(int nType) 168 | { 169 | if(nType==1) 170 | { 171 | if(m_nCurrentCardIndex<1) 172 | { 173 | return; 174 | } 175 | } 176 | 177 | m_galleryManager.StartTransform(nType); 178 | } 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /CustomWidgets/QGallery.h: -------------------------------------------------------------------------------- 1 | #ifndef QGALLERY_H 2 | #define QGALLERY_H 3 | 4 | #include 5 | #include 6 | #include "QGalleryCardManager.h" 7 | 8 | class QGallery : public QWidget 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit QGallery(QWidget *parent = nullptr); 13 | virtual ~QGallery() override; 14 | void SetBackgroundColor(const QColor& color){m_clrBackground=color;} 15 | const QColor& GetBackgroundColor() const{return m_clrBackground;} 16 | bool InitImageList(const QStringList& strImagePaths); 17 | bool InsertImage(const QString& strImagePath); 18 | void ClearAllImages(); 19 | int GetCurrentCardIndex(){return m_nCurrentCardIndex;} 20 | void SetShowCardNums(int nNums); 21 | int GetShowCardNums(){return m_nShowCardNums;} 22 | void MoveStep(int nType); 23 | 24 | protected: 25 | virtual void paintEvent(QPaintEvent *event) override; 26 | //virtual void resizeEvent(QResizeEvent *event) override; 27 | //计算卡片的大小和位置 28 | signals: 29 | 30 | public slots: 31 | void slots_transformPlay(int nType,int nStatus); 32 | private: 33 | QColor m_clrBackground; 34 | QList m_lstImages; //保存所有图片 35 | QGalleryCardManager m_galleryManager; 36 | int m_nCurrentCardIndex; 37 | int m_nShowCardNums; 38 | 39 | void GetCurrentGalleryCards(QList& resultList,int& nIndex); 40 | }; 41 | 42 | #endif // QGALLERY_H 43 | -------------------------------------------------------------------------------- /CustomWidgets/QGalleryCard.cpp: -------------------------------------------------------------------------------- 1 | #include "QGalleryCard.h" 2 | #include 3 | #include 4 | 5 | QGalleryCard::QGalleryCard(qreal x,qreal y,int nWidth,int nHeight,const QPixmap& pixmap) 6 | { 7 | m_rtCardRegion.setRect(x,y,nWidth,nHeight); 8 | m_dRoateAngle=0; 9 | m_nOpacity=255; 10 | m_nScaleMode=Qt::AspectRatioMode::IgnoreAspectRatio; 11 | if(pixmap.isNull()) 12 | { 13 | m_backgroundPixmap=CreateDefaultPixmap(nWidth,nHeight); 14 | } 15 | else 16 | { 17 | AssignsPixmap(pixmap,m_rtCardRegion.width(),m_rtCardRegion.height()); 18 | } 19 | } 20 | 21 | QGalleryCard::QGalleryCard(qreal x,qreal y,int nWidth,int nHeight) 22 | { 23 | m_rtCardRegion.setRect(x,y,nWidth,nHeight); 24 | m_dRoateAngle=0; 25 | m_nOpacity=255; 26 | m_nScaleMode=Qt::AspectRatioMode::IgnoreAspectRatio; 27 | m_backgroundPixmap=CreateDefaultPixmap(nWidth,nHeight); 28 | } 29 | 30 | QGalleryCard::~QGalleryCard() 31 | { 32 | 33 | } 34 | 35 | void QGalleryCard::SetCardPosition(const QPointF& ptStart,qreal nWidth,qreal nHeight) 36 | { 37 | m_rtCardRegion.setTopLeft(ptStart); 38 | m_rtCardRegion.setWidth(nWidth); 39 | m_rtCardRegion.setHeight(nHeight); 40 | ScaleImage(m_backgroundPixmap); 41 | } 42 | 43 | void QGalleryCard::SetCardSize(qreal nWidth,qreal nHeight) 44 | { 45 | m_rtCardRegion.setWidth(nWidth); 46 | m_rtCardRegion.setHeight(nHeight); 47 | ScaleImage(m_backgroundPixmap); 48 | } 49 | 50 | void QGalleryCard::MoveTo(const QPointF& ptDest) 51 | { 52 | m_rtCardRegion.moveTo(ptDest); 53 | } 54 | 55 | void QGalleryCard::SetBackgroundPixmap(const QPixmap& pixmap) 56 | { 57 | if(pixmap.isNull()) 58 | { 59 | m_backgroundPixmap=CreateDefaultPixmap(m_rtCardRegion.width(),m_rtCardRegion.height()); 60 | } 61 | else 62 | { 63 | AssignsPixmap(pixmap,m_rtCardRegion.width(),m_rtCardRegion.height()); 64 | } 65 | } 66 | 67 | void QGalleryCard::AssignsPixmap(const QPixmap& pixmap,int nMaxWidth,int nMaxHeight) 68 | { 69 | if(pixmap.width()>nMaxWidth || pixmap.height()>nMaxHeight) 70 | { 71 | m_backgroundPixmap=pixmap.scaled(nMaxWidth,nMaxHeight,m_nScaleMode,Qt::TransformationMode::SmoothTransformation); 72 | } 73 | else 74 | { 75 | m_backgroundPixmap=pixmap; 76 | } 77 | } 78 | 79 | void QGalleryCard::DrawCard(QPainter& painter) 80 | { 81 | DrawCardImpl(painter); 82 | } 83 | 84 | void QGalleryCard::DrawCardImpl(QPainter& painter) 85 | { 86 | //painter.save(); 87 | //painter.translate(m_rtCardRegion.topLeft()); 88 | qreal nStartX=(m_rtCardRegion.width()-m_backgroundPixmap.width())/2+m_rtCardRegion.left(); 89 | qreal nStartY=m_rtCardRegion.height()-m_backgroundPixmap.height()+m_rtCardRegion.top(); 90 | painter.setOpacity(static_cast(m_nOpacity)/255); 91 | QTransform transform; 92 | //transform.translate(m_rtCardRegion.left(),m_rtCardRegion.top()); 93 | transform.translate(nStartX,nStartY); 94 | transform.rotate(m_dRoateAngle,Qt::Axis::YAxis); 95 | painter.setTransform(transform); 96 | painter.drawPixmap(0,0,m_backgroundPixmap); 97 | 98 | //画倒影 99 | painter.setOpacity(0.2); 100 | transform.scale(1,-1); 101 | painter.setTransform(transform); 102 | painter.drawPixmap(0,static_cast(-m_backgroundPixmap.height()*2.05),m_backgroundPixmap); 103 | painter.resetTransform(); 104 | //painter.restore(); 105 | } 106 | 107 | void QGalleryCard::ScaleImage(QPixmap& pixmap) 108 | { 109 | if(pixmap.isNull()) 110 | { 111 | pixmap=CreateDefaultPixmap(m_rtCardRegion.width(),m_rtCardRegion.height()); 112 | } 113 | else 114 | { 115 | pixmap=pixmap.scaled(m_rtCardRegion.width(),m_rtCardRegion.height(),m_nScaleMode,Qt::TransformationMode::SmoothTransformation); 116 | } 117 | } 118 | 119 | QPixmap QGalleryCard::CreateDefaultPixmap(int nWidth,int nHeight) 120 | { 121 | QPixmap defaultPixmap(nWidth,nHeight); 122 | QPainter painter; 123 | if(painter.begin(&defaultPixmap)) 124 | { 125 | QLinearGradient gradient(0,0,nWidth*3/4,nHeight); 126 | gradient.setColorAt(0,QColor(Qt::GlobalColor::black)); 127 | gradient.setColorAt(1,QColor(Qt::GlobalColor::white)); 128 | QBrush brush(gradient); 129 | painter.setBrush(brush); 130 | painter.fillRect(0,0,nWidth,nHeight,brush); 131 | painter.end(); 132 | } 133 | return defaultPixmap; 134 | } 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /CustomWidgets/QGalleryCard.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * Copyright(C) 2019,保留所有权利。( All rights reserved. ) 3 | * FileName: QGalleryCard.h 4 | * Author:Ln_Jan 5 | * Version:v1.0.0 6 | * Date:2019-05-09 7 | * Description:画廊卡片样式定义类 8 | * Others: 9 | * Function List: 10 | * History: 11 | * 12 | **********************************************************************************/ 13 | #ifndef QGALLERYCARD_H 14 | #define QGALLERYCARD_H 15 | #include 16 | #include 17 | 18 | class QGalleryCard 19 | { 20 | public: 21 | QGalleryCard(qreal x,qreal y,int nWidth,int nHeight,const QPixmap& pixmap); 22 | QGalleryCard(qreal x,qreal y,int nWidth,int nHeight); 23 | virtual ~QGalleryCard(); 24 | void SetCardPosition(const QPointF& ptStart,qreal nWidth,qreal nHeight); 25 | void SetCardPosition(const QRectF rtCardRegion){m_rtCardRegion=rtCardRegion;} 26 | void SetCardSize(qreal nWidth,qreal nHeight); 27 | const QRectF& GetCardRegion() const {return m_rtCardRegion;} 28 | void SetRoateAngle(double angle){m_dRoateAngle=angle;} 29 | double GetRoateAngle() const{return m_dRoateAngle;} 30 | void SetOpacity(int nOpacity){m_nOpacity=nOpacity;} 31 | int GetOpacity() const {return m_nOpacity;} 32 | void SetBackgroundPixmap(const QPixmap& pixmap); 33 | const QPixmap& GetBackgroundPixmap() const {return m_backgroundPixmap;} 34 | void SetPixmapScaleMode(Qt::AspectRatioMode mode){m_nScaleMode=mode;} 35 | Qt::AspectRatioMode GetPixmapScaleMode() const {return m_nScaleMode;} 36 | void MoveTo(const QPointF& ptDest); 37 | void DrawCard(QPainter& painter); 38 | protected: 39 | virtual void DrawCardImpl(QPainter& painter); 40 | private: 41 | QRectF m_rtCardRegion; //位置区域 42 | double m_dRoateAngle; //旋转角度 43 | int m_nOpacity; //透明度 44 | QPixmap m_backgroundPixmap; //背景图片 45 | Qt::AspectRatioMode m_nScaleMode; //缩放类型 46 | 47 | void AssignsPixmap(const QPixmap& pixmap,int nMaxWidth,int nMaxHeight); 48 | QPixmap CreateDefaultPixmap(int nWidth,int nHeight); 49 | void ScaleImage(QPixmap& pixmap); 50 | }; 51 | 52 | #endif // QGALLERYCARD_H 53 | -------------------------------------------------------------------------------- /CustomWidgets/QGalleryCardManager.cpp: -------------------------------------------------------------------------------- 1 | #include "QGalleryCardManager.h" 2 | #include 3 | 4 | static const double CARD_ANGLE=65.0; 5 | static const int CARD_OPACITY=200; 6 | static const int FAST_STEPS=30; 7 | static const int NORMAL_STEPS=50; 8 | static const int INTERVAL_TIMER=1200/NORMAL_STEPS; 9 | 10 | QGalleryCardManager::QGalleryCardManager(QObject* parent):QObject(parent) 11 | ,m_nTransferType(0),m_nSpeed(TRANSFER_SPEED::NORMAL),m_bIsTransferRunning(false),m_nTimerId(-1) 12 | ,m_nCardSpan(0),m_nTabCardSpan(0),m_nShowIndex(0),m_nScaleWidth(0),m_nScaleHeight(0) 13 | { 14 | 15 | } 16 | 17 | QGalleryCardManager::~QGalleryCardManager() 18 | { 19 | 20 | } 21 | 22 | void QGalleryCardManager::ChangeGalleryCard(const QList& showList,int nShowIndex,const QSize& windowSize) 23 | { 24 | QList cardSizeList=GetGalleryCardSize(nShowIndex,showList.size(),windowSize); 25 | m_lstCurrentShowCard.clear(); 26 | for(int i=0;i QGalleryCardManager::GetGalleryCardSize(int nShowIndex,int nTotalNums,const QSize& windowSize) 35 | { 36 | int nHeightTmp=windowSize.height()*2/3; 37 | int nCardHeight=nHeightTmp*4/5; 38 | int nCardWidth=static_cast(windowSize.width()/5.5); 39 | 40 | int nCardWidthSmall=static_cast(nCardWidth*0.95); 41 | int nCardHeightSmall=static_cast(nCardHeight*0.95); 42 | int nWidthScale=static_cast(nCardWidthSmall*0.01); 43 | int nHeightScale=static_cast(nCardHeightSmall*0.01); 44 | int nCardWidthMin=static_cast(nCardWidth*0.5); 45 | int nCardHeightMin=static_cast(nCardHeight*0.5); 46 | 47 | m_nScaleWidth=nCardWidth-nCardWidthSmall; 48 | m_nScaleHeight=nCardHeight-nCardHeightSmall; 49 | 50 | QList resultList; 51 | for(int i=0;i& lstCard,int nShowIndex,const QSize& windowSize) 77 | { 78 | int nCardNums=lstCard.size(); 79 | if(nCardNums>0) 80 | { 81 | int nLeftCards=nShowIndex; 82 | int nRightCards=nCardNums-nShowIndex-1; 83 | int nEndsSpace=static_cast(windowSize.width()*0.25); 84 | int nLeftCardSpan=nLeftCards>1?nEndsSpace/(nLeftCards-1):nEndsSpace/4; 85 | int nRightCardSpan=nRightCards>1?nEndsSpace/(nRightCards-1):nEndsSpace/4; 86 | //nLeftCardSpan=qMin(nLeftCardSpan,nEndsSpace/4); 87 | //nRightCardSpan=qMin(nRightCardSpan,nEndsSpace/4); 88 | int nCardSpan=qMin(nLeftCardSpan,nRightCardSpan); 89 | int nMaxCardWidth=lstCard[nShowIndex].GetCardRegion().width(); 90 | m_nCardSpan=nCardSpan; 91 | m_nShowIndex=nShowIndex; 92 | for(int i=0;i(windowSize.width()*0.95-nEndsSpace-nMaxCardWidth*(CARD_ANGLE/180)); 117 | lstCard[i].MoveTo(QPoint(nTmpX+(i-nShowIndex-1)*nCardSpan,nCardStartY)); 118 | } 119 | } 120 | m_nTabCardSpan=lstCard[nShowIndex].GetCardRegion().left()-static_cast(windowSize.width()*0.3); 121 | } 122 | } 123 | 124 | void QGalleryCardManager::timerEvent(QTimerEvent *event) 125 | { 126 | m_galleryTransfer.AddStep(); 127 | for(int i=0;itimerId()); 187 | m_bIsTransferRunning=false; 188 | } 189 | else 190 | { 191 | emit signals_transformPlay(m_nTransferType,0); 192 | } 193 | } 194 | 195 | void QGalleryCardManager::StartTransform(int nType) 196 | { 197 | if(nType!=0 && nType!=1) 198 | { 199 | return; 200 | } 201 | if(!m_bIsTransferRunning) 202 | { 203 | m_bIsTransferRunning=true; 204 | m_nTransferType=nType; 205 | int nTotalStep=m_nSpeed==TRANSFER_SPEED::NORMAL?NORMAL_STEPS:FAST_STEPS; 206 | double dRoate=CARD_ANGLE/nTotalStep; 207 | double dMoveStep=(double)(m_nCardSpan)/nTotalStep; 208 | double dRoateMoveStep=(double)(m_nTabCardSpan)/nTotalStep; 209 | double dScaleWidth=(double)(m_nScaleWidth)/nTotalStep; 210 | double dScaleHeight=(double)(m_nScaleHeight)/nTotalStep; 211 | if(nType==0) 212 | { 213 | dMoveStep=0-dMoveStep; 214 | dRoateMoveStep=0-dRoateMoveStep; 215 | } 216 | m_galleryTransfer.Reset(nTotalStep,dMoveStep,dRoate,dRoateMoveStep,dScaleWidth,dScaleHeight); 217 | m_nTimerId=startTimer(INTERVAL_TIMER); 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /CustomWidgets/QGalleryCardManager.h: -------------------------------------------------------------------------------- 1 | #ifndef QGALLERYCARDMANAGER_H 2 | #define QGALLERYCARDMANAGER_H 3 | #include 4 | #include 5 | #include "QGalleryCard.h" 6 | 7 | //typedef void (*transform_callback)(int,int); //0:正在执行 1:完成 -1:错误 8 | 9 | class QGalleryTransfer 10 | { 11 | public: 12 | QGalleryTransfer() 13 | { 14 | m_nCurrentStep=m_nTotalStep=0; 15 | m_nMoveStep=m_nRoateStep=m_nRoateMoveStep=m_dSizeHeightStep=m_dSizeWidthStep=0.0; 16 | } 17 | ~QGalleryTransfer() 18 | { 19 | 20 | } 21 | void Reset(int nTotalStep=0,double dMoveStep=0,double dRoateStep=0,double dRoateMoveStep=0 22 | ,double dSizeWidthStep=0,double dSizeHeightStep=0) 23 | { 24 | m_nCurrentStep=0; 25 | m_nTotalStep=nTotalStep; 26 | m_nMoveStep=dMoveStep; 27 | m_nRoateStep=dRoateStep; 28 | m_nRoateMoveStep=dRoateMoveStep; 29 | m_dSizeWidthStep=dSizeWidthStep; 30 | m_dSizeHeightStep=dSizeHeightStep; 31 | } 32 | void AddStep(){m_nCurrentStep++;} 33 | int GetCurrentStep(){return m_nCurrentStep;} 34 | bool IsFinished(){return m_nCurrentStep>=m_nTotalStep;} 35 | void SetMoveStep(double nMoveStep){m_nMoveStep=nMoveStep;} 36 | double GetMoveStep(){return m_nMoveStep;} 37 | void SetRoateMoveStep(double nStep){m_nRoateMoveStep=nStep;} 38 | double GetRoateMoveStep(){return m_nRoateMoveStep;} 39 | void SetRoateStep(double nStep){m_nRoateStep=nStep;} 40 | double GetRoateStep(){return m_nRoateStep;} 41 | double GetSizeWidthStep(){return m_dSizeWidthStep;} 42 | double GetSizeHeightStep(){return m_dSizeHeightStep;} 43 | 44 | private: 45 | int m_nCurrentStep; 46 | int m_nTotalStep; 47 | double m_nMoveStep; 48 | double m_nRoateMoveStep; 49 | double m_nRoateStep; 50 | double m_dSizeWidthStep; 51 | double m_dSizeHeightStep; 52 | }; 53 | 54 | class QGalleryCardManager:public QObject 55 | { 56 | Q_OBJECT 57 | public: 58 | enum TRANSFER_SPEED{NORMAL,FAST}; 59 | QGalleryCardManager(QObject* parent=nullptr); 60 | ~QGalleryCardManager() override; 61 | void ChangeGalleryCard(const QList& showList,int nShowIndex,const QSize& windowSize); 62 | void StartTransform(int nType); //开始转场动画 63 | //void SetTransformListener(transform_callback l){m_pTransformCallback=l;} 64 | void ClearCache(){m_lstCurrentShowCard.clear();} 65 | const QList& GetGalleryCardList(){return m_lstCurrentShowCard;} 66 | signals: 67 | void signals_transformPlay(int,int); 68 | 69 | protected: 70 | virtual void AdjustGalleryPosition(QList& lstCard,int nShowIndex,const QSize& windowSize); 71 | virtual void timerEvent(QTimerEvent *event) override; 72 | private: 73 | QList m_lstCurrentShowCard; 74 | QGalleryTransfer m_galleryTransfer; 75 | //transform_callback m_pTransformCallback; //动画转换状态回调 76 | int m_nTransferType; 77 | TRANSFER_SPEED m_nSpeed; 78 | bool m_bIsTransferRunning; 79 | int m_nTimerId; 80 | int m_nCardSpan; 81 | int m_nTabCardSpan; 82 | int m_nShowIndex; 83 | int m_nScaleWidth; 84 | int m_nScaleHeight; 85 | 86 | QList GetGalleryCardSize(int nShowIndex,int nTotalNums,const QSize& windowSize); 87 | }; 88 | 89 | #endif // QGALLERYCARDMANAGER_H 90 | -------------------------------------------------------------------------------- /CustomWidgets/QToast.cpp: -------------------------------------------------------------------------------- 1 | #include "QToast.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int QToast::LENGTH_LONG=4000; 13 | int QToast::LENGTH_SHORT=1500; 14 | static const int TIMER_INTERVAL=50; 15 | 16 | QToast::QToast(QString strContent,int nToastInterval,QWidget *parent) 17 | : QWidget(parent),m_strContent(strContent),m_nToastInterval(nToastInterval), 18 | m_nCurrentWindowOpacity(0),m_nCurrentStayTime(0),m_nStatus(0),m_bAutoDelete(true) 19 | { 20 | Init(); 21 | } 22 | 23 | QToast::~QToast() 24 | { 25 | qDebug()<<"QToast delete"; 26 | } 27 | 28 | 29 | QSize QToast::CalculateTextSize() 30 | { 31 | QFontMetrics metrice(m_drawFont); 32 | QStringList ls=m_strContent.split(QRegExp("\r\n|\n")); 33 | int nWidthInPixel=0; 34 | for(int i=0;inWidthInPixel?tmpWidth:nWidthInPixel; 38 | } 39 | int nHeightInPixel=metrice.height()*ls.length(); 40 | return QSize(nWidthInPixel,nHeightInPixel); 41 | } 42 | 43 | void QToast::Init() 44 | { 45 | setWindowFlags(Qt::FramelessWindowHint|Qt::SubWindow); 46 | setAttribute(Qt::WA_TranslucentBackground); 47 | m_drawFont.setPointSize(20); 48 | SetToastPos(TOAST_POS::BOTTOM); 49 | } 50 | 51 | 52 | void QToast::SetToastPos(TOAST_POS pos) 53 | { 54 | //获取主屏幕分辨率 55 | QRect screenRect = QGuiApplication::screens().at(0)->geometry(); 56 | QSize fontsize=CalculateTextSize(); 57 | QSize windowSize(fontsize.width()+fontsize.width()*0.4,fontsize.height()+fontsize.height()*0.4); 58 | int windowsX=(screenRect.width()-windowSize.width())/2; 59 | int windowsY=0; 60 | if(pos==TOAST_POS::TOP) 61 | { 62 | windowsY=screenRect.height() / 6; 63 | } 64 | else if(pos==TOAST_POS::BOTTOM) 65 | { 66 | windowsY=screenRect.height() * 4 / 5; 67 | } 68 | else 69 | { 70 | windowsY=(screenRect.height()-windowSize.height())/2; 71 | } 72 | 73 | setGeometry(windowsX,windowsY,windowSize.width(),windowSize.height()); 74 | } 75 | 76 | void QToast::paintEvent(QPaintEvent*) 77 | { 78 | 79 | QPainter painter(this); 80 | painter.setRenderHint(QPainter::Antialiasing, true); 81 | painter.setFont(m_drawFont); 82 | QSize widgetSize=size(); 83 | QPen textPen(Qt::PenStyle::SolidLine); 84 | textPen.setColor(QColor(255,255,255,m_nCurrentWindowOpacity*255/100)); 85 | textPen.setJoinStyle(Qt::PenJoinStyle::RoundJoin); 86 | 87 | 88 | QPen emptyPen(Qt::PenStyle::NoPen); 89 | 90 | //painter.setPen(textPen); 91 | painter.setPen(emptyPen); 92 | painter.setBrush(QBrush(QColor(100,100,100,m_nCurrentWindowOpacity*255/100))); 93 | painter.drawRoundRect(widgetSize.width()*0.05,widgetSize.height()*0.05,widgetSize.width()*0.9,widgetSize.height()*0.9,10,10); 94 | painter.setPen(textPen); 95 | painter.drawText(QRect(widgetSize.width()*0.15,widgetSize.height()*0.1,widgetSize.width()*0.8,widgetSize.height()*0.8),m_strContent); 96 | } 97 | 98 | void QToast::showEvent(QShowEvent*) 99 | { 100 | qDebug()<<"show event call"; 101 | if(m_nStatus==0x00) 102 | { 103 | m_nCurrentStayTime=0; 104 | m_nCurrentWindowOpacity=0; 105 | startTimer(TIMER_INTERVAL); 106 | m_nStatus=0x01; 107 | } 108 | } 109 | 110 | void QToast::timerEvent(QTimerEvent* e) 111 | { 112 | if(m_nStatus==0x01) 113 | { 114 | if(m_nCurrentWindowOpacity<100) 115 | { 116 | m_nCurrentWindowOpacity+=10; 117 | update(); 118 | } 119 | else 120 | { 121 | m_nStatus=0x02; 122 | } 123 | } 124 | else if(m_nStatus==0x02) 125 | { 126 | if(m_nCurrentStayTime0) 138 | { 139 | m_nCurrentWindowOpacity-=10; 140 | update(); 141 | } 142 | else 143 | { 144 | m_nStatus=0x04; 145 | } 146 | } 147 | else if(m_nStatus==0x04) 148 | { 149 | m_nStatus=0x00; 150 | emit signals_finished(); 151 | killTimer(e->timerId()); 152 | if(m_bAutoDelete) 153 | { 154 | this->deleteLater(); 155 | } 156 | } 157 | } 158 | 159 | QToast* QToast::CreateToast(QString strContent,int nToastInterval,QWidget *parent) 160 | { 161 | return new QToast(strContent,nToastInterval,parent); 162 | } 163 | -------------------------------------------------------------------------------- /CustomWidgets/QToast.h: -------------------------------------------------------------------------------- 1 | #ifndef QTOAST_H 2 | #define QTOAST_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class QToast : public QWidget 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | static int LENGTH_LONG; 15 | static int LENGTH_SHORT; 16 | enum TOAST_POS{TOP,CENTER,BOTTOM}; 17 | static QToast* CreateToast(QString strContent,int nToastInterval,QWidget *parent = nullptr); 18 | ~QToast(); 19 | void SetTextFont(const QFont& font){m_drawFont=font;} 20 | const QFont& GetTextFont(){return m_drawFont;} 21 | void SetToastPos(TOAST_POS pos); 22 | void SetAutoDelete(bool b){m_bAutoDelete=b;} 23 | signals: 24 | void signals_finished(); 25 | protected: 26 | virtual QSize CalculateTextSize(); 27 | virtual void Init(); 28 | void paintEvent(QPaintEvent *event); 29 | void showEvent(QShowEvent *event); 30 | void timerEvent(QTimerEvent *event); 31 | private: 32 | QString m_strContent; 33 | int m_nToastInterval; 34 | int m_nCurrentWindowOpacity; 35 | int m_nCurrentStayTime; 36 | int m_nStatus; 37 | bool m_bAutoDelete; 38 | QFont m_drawFont; 39 | 40 | QToast(QString strContent,int nToastInterval,QWidget *parent = nullptr); 41 | }; 42 | 43 | #endif // QTOAST_H 44 | -------------------------------------------------------------------------------- /CustomWidgets/qpictureslides.cpp: -------------------------------------------------------------------------------- 1 | #include "qpictureslides.h" 2 | #include "qpixmapobject.h" 3 | #include 4 | #include 5 | #include 6 | 7 | QPictureSlides::QPictureSlides(QWidget *parent) : QLabel(parent),m_bIsAutoChange(false),m_bIsScaledPicture(false) 8 | ,m_nChangeInterval(5000),m_nMouseEnterState(0),m_nCurrentPicIndex(0) 9 | { 10 | m_nTimerId=startTimer(m_nChangeInterval); 11 | setMouseTracking(true); 12 | } 13 | 14 | QPictureSlides::~QPictureSlides() 15 | { 16 | ClearAllPictures(); 17 | } 18 | 19 | void QPictureSlides::SetChangeInterval(int nInterval) 20 | { 21 | m_nChangeInterval=nInterval; 22 | killTimer(m_nTimerId); 23 | m_nTimerId=startTimer(m_nChangeInterval); 24 | } 25 | 26 | void QPictureSlides::paintEvent(QPaintEvent*) 27 | { 28 | QPainter painter; 29 | if(painter.begin(this)) 30 | { 31 | int nWidgetW=width(); 32 | int nWidgetH=height(); 33 | if(!m_lstPictures.empty()) 34 | { 35 | QObject* pCurrenObj=m_lstPictures.at(m_nCurrentPicIndex); 36 | if(pCurrenObj->metaObject()->className()==QStringLiteral("QPixmapObject")) //QPixmap 37 | { 38 | QPixmapObject* pPictureObj=qobject_cast(pCurrenObj); 39 | if(pPictureObj!=nullptr) 40 | { 41 | QPixmap pixmap=pPictureObj->GetPixmap(); 42 | QSize drawPicSize=pixmap.size(); 43 | if(m_bIsScaledPicture && 44 | (drawPicSize.width()>nWidgetW || drawPicSize.height()>nWidgetH)) 45 | { 46 | pixmap=pixmap.scaled(nWidgetW,nWidgetH,Qt::KeepAspectRatio); 47 | drawPicSize=pixmap.size(); 48 | } 49 | QTransform transForm; 50 | transForm.rotate(-45,Qt::Axis::YAxis); 51 | painter.setTransform(transForm); 52 | int nStartX=qMax((nWidgetW-drawPicSize.width())/2,0); 53 | int nStartY=qMax((nWidgetH-drawPicSize.height())/2,0); 54 | painter.drawPixmap(nStartX,nStartY,pixmap); 55 | painter.resetTransform(); 56 | } 57 | } 58 | else if(pCurrenObj->metaObject()->className()==QStringLiteral("QMovie")) 59 | { 60 | QMovie* pMovie=qobject_cast(pCurrenObj); 61 | if(pMovie!=nullptr) 62 | { 63 | QPixmap currentPixmap=pMovie->currentPixmap(); 64 | if(!currentPixmap.isNull()) 65 | { 66 | QSize picSize=currentPixmap.size(); 67 | if(m_bIsScaledPicture && 68 | (picSize.width()>nWidgetW || picSize.height()>nWidgetH)) 69 | { 70 | currentPixmap=currentPixmap.scaled(nWidgetW,nWidgetH,Qt::KeepAspectRatio); 71 | picSize=currentPixmap.size(); 72 | } 73 | int nStartX=qMax((nWidgetW-picSize.width())/2,0); 74 | int nStartY=qMax((nWidgetH-picSize.height())/2,0); 75 | painter.drawPixmap(nStartX,nStartY,currentPixmap); 76 | } 77 | } 78 | } 79 | else 80 | { 81 | painter.drawText(QRect(0,0,nWidgetW,nWidgetH),Qt::AlignCenter,QString("图片解析失败")); 82 | } 83 | if(m_nMouseEnterState!=0) //如果鼠标进入,绘制图片左右跳转的按钮 84 | { 85 | drawPictureChangeButton(painter); 86 | } 87 | drawProgressBar(painter); 88 | } 89 | else 90 | { 91 | painter.drawText(QRect(0,0,nWidgetW,nWidgetH),Qt::AlignCenter,QString("暂无图片")); 92 | } 93 | painter.end(); 94 | } 95 | else 96 | { 97 | qWarning()<<"QPictureSlides::paintEvent error"; 98 | } 99 | } 100 | 101 | void QPictureSlides::enterEvent(QEvent*) 102 | { 103 | m_nMouseEnterState=1; 104 | update(); 105 | } 106 | 107 | void QPictureSlides::leaveEvent(QEvent*) 108 | { 109 | m_nMouseEnterState=0; 110 | update(); 111 | } 112 | 113 | QRect QPictureSlides::GetButtonRect(int nType) 114 | { 115 | int nWidgetHeight=height(); 116 | int nWidgetWidth=width(); 117 | int nButtonSize=qMin(static_cast(nWidgetWidth*0.08),static_cast(nWidgetHeight*0.08)); 118 | int nRectStartY=(nWidgetHeight-nButtonSize)/2; 119 | if(nRectStartY<0 || nWidgetWidth<11 || nButtonSize<30) 120 | { 121 | return QRect(0,0,0,0); 122 | } 123 | int nRectStartX=0; 124 | if(nType==1) 125 | { 126 | nRectStartX=nWidgetWidth-nButtonSize-10; 127 | } 128 | else 129 | { 130 | nRectStartX=10; 131 | } 132 | return QRect(nRectStartX,nRectStartY,nButtonSize,nButtonSize); 133 | } 134 | 135 | void QPictureSlides::drawPictureChangeButton(QPainter& painter) 136 | { 137 | QRect lRect=GetButtonRect(0); 138 | if(lRect.isValid()) 139 | { 140 | painter.save(); 141 | painter.translate(lRect.topLeft()); 142 | QPainterPath painterPath; 143 | painterPath.arcMoveTo(0,0,lRect.height(),lRect.height(),90); 144 | QPointF pStartPos=painterPath.currentPosition(); 145 | painterPath.arcTo(0,0,lRect.height(),lRect.height(),90,-180); 146 | QPointF pArcEndPos=painterPath.currentPosition(); 147 | painterPath.lineTo(0,pArcEndPos.y()); 148 | painterPath.lineTo(0,pStartPos.y()); 149 | painterPath.closeSubpath(); 150 | QPen emptyPen(Qt::NoPen); 151 | painter.setPen(emptyPen); 152 | QBrush backgroundBrush=m_nMouseEnterState==0x02?QBrush(QColor(140,140,140,200)):QBrush(QColor(120,120,120,150)); 153 | painter.fillPath(painterPath,backgroundBrush); 154 | 155 | QBrush lineBrush=m_nMouseEnterState==0x02?QBrush(QColor(255,255,255)):QBrush(QColor(255,255,255,200)); 156 | QPen drawPen(lineBrush,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin); 157 | painter.setPen(drawPen); 158 | QPainterPath patternPath; 159 | patternPath.moveTo(lRect.width()*3/5,lRect.height()/3); 160 | patternPath.lineTo(lRect.width()/4,lRect.height()/2); 161 | patternPath.lineTo(lRect.width()*3/5,lRect.height()*2/3); 162 | painter.drawPath(patternPath); 163 | painter.restore(); 164 | } 165 | 166 | QRect rRect=GetButtonRect(1); 167 | if(rRect.isValid()) 168 | { 169 | painter.save(); 170 | painter.translate(rRect.topLeft()); 171 | QPainterPath painterPath; 172 | painterPath.arcMoveTo(0,0,rRect.height(),rRect.height(),-90); 173 | QPointF pStartPos=painterPath.currentPosition(); 174 | painterPath.arcTo(0,0,rRect.height(),rRect.height(),-90,-180); 175 | QPointF pArcEndPos=painterPath.currentPosition(); 176 | painterPath.lineTo(rRect.width(),pArcEndPos.y()); 177 | painterPath.lineTo(rRect.width(),pStartPos.y()); 178 | painterPath.closeSubpath(); 179 | QPen emptyPen(Qt::NoPen); 180 | painter.setPen(emptyPen); 181 | QBrush backgroundBrush=m_nMouseEnterState==0x03?QBrush(QColor(140,140,140,200)):QBrush(QColor(120,120,120,150)); 182 | painter.fillPath(painterPath,backgroundBrush); 183 | 184 | QBrush lineBrush=m_nMouseEnterState==0x02?QBrush(QColor(255,255,255)):QBrush(QColor(255,255,255,200)); 185 | QPen drawPen(lineBrush,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin); 186 | painter.setPen(drawPen); 187 | QPainterPath patternPath; 188 | patternPath.moveTo(rRect.width()*2/5,rRect.height()/3); 189 | patternPath.lineTo(rRect.width()*3/4,rRect.height()/2); 190 | patternPath.lineTo(rRect.width()*2/5,rRect.height()*2/3); 191 | painter.drawPath(patternPath); 192 | painter.restore(); 193 | } 194 | } 195 | 196 | void QPictureSlides::drawProgressBar(QPainter& painter) 197 | { 198 | int nWidgetHeight=height(); 199 | int nWidgetWidth=width(); 200 | if(nWidgetWidth<200 || nWidgetHeight<100) 201 | { 202 | return; 203 | } 204 | 205 | int nPointSize=static_cast(qMin(nWidgetWidth*0.02,nWidgetHeight*0.02)); 206 | int nPointSplit=nPointSize/3; 207 | 208 | if(m_lstPictures.size()<=5) 209 | { 210 | int nProgressWidth=m_lstPictures.size()*nPointSize+(m_lstPictures.size()-1)*nPointSplit; 211 | int nProgressStartX=(nWidgetWidth-nProgressWidth)/2; 212 | int nProgressStartY=(nWidgetHeight-nProgressWidth)*12/13; 213 | if(nProgressStartY<0) 214 | { 215 | return; 216 | } 217 | QPen emptyPen(Qt::NoPen); 218 | painter.setPen(emptyPen); 219 | for(int i=0;ipos())) 266 | { 267 | ChangePrevPicture(true); 268 | } 269 | 270 | QRect rRect=GetButtonRect(1); 271 | if(rRect.contains(event->pos())) 272 | { 273 | ChangeNextPicture(true); 274 | } 275 | } 276 | 277 | void QPictureSlides::mouseMoveEvent(QMouseEvent* event) 278 | { 279 | QRect lRect=GetButtonRect(0); 280 | if(lRect.contains(event->pos())) 281 | { 282 | m_nMouseEnterState=0x02; 283 | event->accept(); 284 | update(lRect); 285 | return; 286 | } 287 | 288 | QRect rRect=GetButtonRect(1); 289 | if(rRect.contains(event->pos())) 290 | { 291 | m_nMouseEnterState=0x03; 292 | event->accept(); 293 | update(rRect); 294 | return; 295 | } 296 | 297 | if(m_nMouseEnterState!=0x01) 298 | { 299 | update(); 300 | } 301 | 302 | m_nMouseEnterState=0x01; 303 | event->accept(); 304 | return; 305 | } 306 | 307 | QPainterPath QPictureSlides::CreateRoundRectPainterPath(int x,int y,int nWidth,int nHeight) 308 | { 309 | QPainterPath path; 310 | path.arcMoveTo(x,y,nHeight,nHeight,-90); 311 | path.arcTo(x,y,nHeight,nHeight,-90,-180); 312 | QPointF p1=path.currentPosition(); 313 | path.lineTo(x+nWidth-nHeight/2,p1.y()); 314 | path.arcTo(x+nWidth-nHeight,p1.y(),nHeight,nHeight,90,-180); 315 | path.closeSubpath(); 316 | return path; 317 | } 318 | 319 | void QPictureSlides::AddPictures(const QStringList& filePathList) 320 | { 321 | foreach(QString str,filePathList) 322 | { 323 | if(str.endsWith(".gif")) 324 | { 325 | QMovie* pMovie=new QMovie(str); 326 | if(pMovie->isValid()) 327 | { 328 | connect(pMovie,SIGNAL(updated(const QRect&)),this,SLOT(update())); 329 | m_lstPictures.push_back(qobject_cast(pMovie)); 330 | } 331 | else 332 | { 333 | delete pMovie; 334 | } 335 | } 336 | else 337 | { 338 | QPixmap pixmap; 339 | if(pixmap.load(str)) 340 | { 341 | QPixmapObject* pObject=new QPixmapObject(pixmap); 342 | m_lstPictures.push_back(qobject_cast(pObject)); 343 | } 344 | } 345 | } 346 | 347 | if(!m_lstPictures.empty() && m_nCurrentPicIndex==0 348 | && (m_lstPictures.at(0)->metaObject()->className()==QStringLiteral("QMovie"))) 349 | { 350 | QMovie* pMovie=qobject_cast(m_lstPictures.at(0)); 351 | if(pMovie->state()==QMovie::MovieState::NotRunning) 352 | { 353 | pMovie->start(); 354 | } 355 | } 356 | } 357 | 358 | void QPictureSlides::ClearAllPictures() 359 | { 360 | if(!m_lstPictures.empty()) 361 | { 362 | for(QList::iterator it=m_lstPictures.begin();it!=m_lstPictures.end();it++) 363 | { 364 | delete (*it); 365 | } 366 | m_lstPictures.clear(); 367 | } 368 | } 369 | 370 | 371 | void QPictureSlides::ChangeNextPicture(bool bKillTimer) 372 | { 373 | if(m_lstPictures.at(m_nCurrentPicIndex)->metaObject()->className()==QStringLiteral("QMovie")) 374 | { 375 | (qobject_cast(m_lstPictures.at(m_nCurrentPicIndex)))->stop(); 376 | } 377 | 378 | m_nCurrentPicIndex=m_nCurrentPicIndex==(m_lstPictures.size()-1)?0:(m_nCurrentPicIndex+1); 379 | 380 | if(bKillTimer) 381 | { 382 | killTimer(m_nTimerId); 383 | m_nTimerId=startTimer(m_nChangeInterval); 384 | } 385 | 386 | if(m_lstPictures.at(m_nCurrentPicIndex)->metaObject()->className()==QStringLiteral("QMovie")) 387 | { 388 | (qobject_cast(m_lstPictures.at(m_nCurrentPicIndex)))->start(); 389 | return; 390 | } 391 | update(); 392 | } 393 | 394 | void QPictureSlides::ChangePrevPicture(bool bKillTimer) 395 | { 396 | if(m_lstPictures.at(m_nCurrentPicIndex)->metaObject()->className()==QStringLiteral("QMovie")) 397 | { 398 | (qobject_cast(m_lstPictures.at(m_nCurrentPicIndex)))->stop(); 399 | } 400 | m_nCurrentPicIndex=m_nCurrentPicIndex==0?(m_lstPictures.size()-1):(m_nCurrentPicIndex-1); 401 | if(bKillTimer) 402 | { 403 | killTimer(m_nTimerId); 404 | m_nTimerId=startTimer(m_nChangeInterval); 405 | } 406 | 407 | if(m_lstPictures.at(m_nCurrentPicIndex)->metaObject()->className()==QStringLiteral("QMovie")) 408 | { 409 | (qobject_cast(m_lstPictures.at(m_nCurrentPicIndex)))->start(); 410 | return; 411 | } 412 | update(); 413 | } 414 | -------------------------------------------------------------------------------- /CustomWidgets/qpictureslides.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************* 2 | * Copyright(C) 2019,保留所有权利。( All rights reserved. ) 3 | * FileName:qpictureslides.h 4 | * Author:Ln_Jan 5 | * Version:v1.0.0 6 | * Date:2019-04-16 7 | * Description:导航页图片浏览器 8 | * Others: 9 | * Function List: 10 | * History: 11 | * 12 | **********************************************************************************/ 13 | #ifndef QPICTURESLIDES_H 14 | #define QPICTURESLIDES_H 15 | 16 | #include 17 | #include 18 | 19 | class QPictureSlides : public QLabel 20 | { 21 | Q_OBJECT 22 | public: 23 | explicit QPictureSlides(QWidget *parent = nullptr); 24 | virtual ~QPictureSlides() override; 25 | int GetPictureNums(){return m_lstPictures.size();} 26 | void AddPictures(const QStringList& filePathList); 27 | void ClearAllPictures(); 28 | void SetAutoChange(bool bChange){m_bIsAutoChange=bChange;} 29 | bool IsAutoChange(){return m_bIsAutoChange;} 30 | void SetScaledPicture(bool bScaled){m_bIsScaledPicture=bScaled;} 31 | bool IsScaledPicture(){return m_bIsScaledPicture;} 32 | void SetChangeInterval(int nInterval); 33 | int GetChangeInterval(){return m_nChangeInterval;} 34 | 35 | protected: 36 | void paintEvent(QPaintEvent *paintEvent) override; 37 | void enterEvent(QEvent *event) override; 38 | void leaveEvent(QEvent *event) override; 39 | void timerEvent(QTimerEvent *event) override; 40 | void mouseReleaseEvent(QMouseEvent *event) override; 41 | void mouseMoveEvent(QMouseEvent *event) override; 42 | 43 | virtual void drawPictureChangeButton(QPainter& painter); 44 | virtual void drawProgressBar(QPainter& painter); 45 | signals: 46 | 47 | private slots: 48 | 49 | private: 50 | QList m_lstPictures; 51 | bool m_bIsAutoChange; 52 | bool m_bIsScaledPicture; 53 | int m_nChangeInterval; 54 | int m_nMouseEnterState; //0:鼠标没进入控件 1:鼠标进入控件 2:鼠标在左按钮 3:鼠标在右按钮 55 | int m_nCurrentPicIndex; 56 | int m_nTimerId; 57 | 58 | QRect GetButtonRect(int nType); //0:left 1:right 59 | QPainterPath CreateRoundRectPainterPath(int x,int y,int nWidth,int nHeight); 60 | 61 | void ChangeNextPicture(bool bKillTimer=false); 62 | void ChangePrevPicture(bool bKillTimer=false); 63 | }; 64 | 65 | #endif // QPICTURESLIDES_H 66 | -------------------------------------------------------------------------------- /CustomWidgets/qpixmapobject.cpp: -------------------------------------------------------------------------------- 1 | #include "qpixmapobject.h" 2 | 3 | QPixmapObject::QPixmapObject(const QPixmap& pixmap,QObject *parent) : QObject(parent) 4 | ,m_pixmap(pixmap) 5 | { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /CustomWidgets/qpixmapobject.h: -------------------------------------------------------------------------------- 1 | #ifndef QPIXMAPOBJECT_H 2 | #define QPIXMAPOBJECT_H 3 | 4 | #include 5 | #include 6 | 7 | class QPixmapObject : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit QPixmapObject(const QPixmap& pixmap,QObject *parent = nullptr); 12 | const QPixmap& GetPixmap(){return m_pixmap;} 13 | 14 | signals: 15 | 16 | public slots: 17 | 18 | private: 19 | QPixmap m_pixmap; 20 | }; 21 | 22 | #endif // QPIXMAPOBJECT_H 23 | -------------------------------------------------------------------------------- /CustomWidgetsDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "CustomWidgetsDialog.h" 2 | #include "ui_CustomWidgetsDialog.h" 3 | #include "CustomWidgets/QToast.h" 4 | #include "CustomWidgets/QCardDialog.h" 5 | #include 6 | 7 | CustomWidgetsDialog::CustomWidgetsDialog(QWidget *parent) : 8 | QDialog(parent), 9 | ui(new Ui::CustomWidgetsDialog) 10 | { 11 | ui->setupUi(this); 12 | InitUi(); 13 | } 14 | 15 | CustomWidgetsDialog::~CustomWidgetsDialog() 16 | { 17 | delete ui; 18 | } 19 | 20 | void CustomWidgetsDialog::InitUi() 21 | { 22 | QStringList stepList; 23 | 24 | stepList<<"step1"<<"step2"<<"step3"<<"step4"<<"step5"; 25 | 26 | ui->label_circle1->SetProgressBarStyle(QFlowProgressBar::Styles::PROGRESS_BAR_CIRCLE_1); 27 | ui->label_circle1->SetStepMessageList(stepList); 28 | ui->label_circle1->SetAutoTextWidth(true); 29 | 30 | ui->label_circle2->SetProgressBarStyle(QFlowProgressBar::Styles::PROGRESS_BAR_CIRCLE_2); 31 | ui->label_circle2->SetStepMessageList(stepList); 32 | ui->label_circle2->SetAutoTextWidth(true); 33 | 34 | ui->label_rectangle->SetProgressBarStyle(QFlowProgressBar::Styles::PROGRESS_BAR_RECT); 35 | ui->label_rectangle->SetStepMessageList(stepList); 36 | ui->label_rectangle->SetAutoTextWidth(true); 37 | 38 | ui->label_tabstyle->SetStepMessageList(stepList); 39 | ui->label_tabstyle->SetAutoTextWidth(true); 40 | 41 | qDebug()<label_pictures->AddPictures(pictureLst); 49 | 50 | 51 | QStringList posList; 52 | posList<<"上部居中"<<"居中"<<"底部居中"; 53 | ui->comboBox_pos->addItems(posList); 54 | ui->comboBox_pos->setCurrentIndex(0); 55 | 56 | QStringList showTimeList; 57 | showTimeList<<"短"<<"长"; 58 | ui->comboBox_time->addItems(showTimeList); 59 | ui->comboBox_time->setCurrentIndex(0); 60 | 61 | ui->textEdit_toast->setText("测试显示"); 62 | 63 | QStringList galleryList; 64 | galleryList<gallery_main->InitImageList(galleryList); 71 | } 72 | 73 | void CustomWidgetsDialog::on_btn_next_clicked() 74 | { 75 | ui->label_circle1->NextStep(); 76 | ui->label_circle2->NextStep(); 77 | ui->label_rectangle->NextStep(); 78 | ui->label_tabstyle->NextStep(); 79 | } 80 | 81 | void CustomWidgetsDialog::on_btn_Prev_clicked() 82 | { 83 | ui->label_circle1->BackToPrevStep(); 84 | ui->label_circle2->BackToPrevStep(); 85 | ui->label_rectangle->BackToPrevStep(); 86 | ui->label_tabstyle->BackToPrevStep(); 87 | } 88 | 89 | void CustomWidgetsDialog::on_checkBox_auto_stateChanged(int arg1) 90 | { 91 | if(arg1==Qt::Checked) 92 | { 93 | int nInterval=ui->lineEdit->text().toInt(); 94 | if(nInterval>=3000) 95 | { 96 | ui->label_pictures->SetChangeInterval(nInterval); 97 | } 98 | ui->label_pictures->SetAutoChange(true); 99 | } 100 | else 101 | { 102 | ui->label_pictures->SetAutoChange(false); 103 | } 104 | } 105 | 106 | void CustomWidgetsDialog::on_pushButton_show_clicked() 107 | { 108 | QToast* pToast=nullptr; 109 | if(ui->comboBox_time->currentIndex()==0) 110 | { 111 | pToast=QToast::CreateToast(ui->textEdit_toast->toPlainText(),QToast::LENGTH_SHORT); 112 | } 113 | else 114 | { 115 | pToast=QToast::CreateToast(ui->textEdit_toast->toPlainText(),QToast::LENGTH_LONG); 116 | } 117 | pToast->SetAutoDelete(true); 118 | 119 | if(ui->comboBox_pos->currentIndex()==0) 120 | { 121 | pToast->SetToastPos(QToast::TOAST_POS::TOP); 122 | } 123 | else if(ui->comboBox_pos->currentIndex()==1) 124 | { 125 | pToast->SetToastPos(QToast::TOAST_POS::CENTER); 126 | } 127 | else 128 | { 129 | pToast->SetToastPos(QToast::TOAST_POS::BOTTOM); 130 | } 131 | pToast->show(); 132 | } 133 | 134 | void CustomWidgetsDialog::on_pushButton_card_clicked() 135 | { 136 | QCardDialog tmpCardDialog; 137 | tmpCardDialog.exec(); 138 | } 139 | 140 | void CustomWidgetsDialog::on_pushButton_nextStep_clicked() 141 | { 142 | ui->gallery_main->MoveStep(0); 143 | } 144 | 145 | void CustomWidgetsDialog::on_pushButton_prev_clicked() 146 | { 147 | ui->gallery_main->MoveStep(1); 148 | } 149 | -------------------------------------------------------------------------------- /CustomWidgetsDialog.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMWIDGETSDIALOG_H 2 | #define CUSTOMWIDGETSDIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class CustomWidgetsDialog; 8 | } 9 | 10 | class CustomWidgetsDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit CustomWidgetsDialog(QWidget *parent = nullptr); 16 | ~CustomWidgetsDialog(); 17 | 18 | private slots: 19 | void on_btn_next_clicked(); 20 | 21 | void on_btn_Prev_clicked(); 22 | 23 | void on_checkBox_auto_stateChanged(int arg1); 24 | 25 | void on_pushButton_show_clicked(); 26 | 27 | void on_pushButton_card_clicked(); 28 | 29 | void on_pushButton_nextStep_clicked(); 30 | 31 | void on_pushButton_prev_clicked(); 32 | 33 | private: 34 | Ui::CustomWidgetsDialog *ui; 35 | 36 | void InitUi(); 37 | }; 38 | 39 | #endif // CUSTOMWIDGETSDIALOG_H 40 | -------------------------------------------------------------------------------- /CustomWidgetsDialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | CustomWidgetsDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1280 10 | 720 11 | 12 | 13 | 14 | CustomWidgetsDialog 15 | 16 | 17 | 18 | 19 | 10 20 | 10 21 | 1251 22 | 691 23 | 24 | 25 | 26 | QTabWidget::North 27 | 28 | 29 | QTabWidget::Triangular 30 | 31 | 32 | 3 33 | 34 | 35 | 36 | 进度条 37 | 38 | 39 | 40 | 41 | 30 42 | 30 43 | 1181 44 | 111 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 30 55 | 170 56 | 1181 57 | 111 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 30 68 | 330 69 | 1181 70 | 111 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 30 81 | 490 82 | 1181 83 | 81 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 730 94 | 620 95 | 93 96 | 28 97 | 98 | 99 | 100 | Next 101 | 102 | 103 | 104 | 105 | 106 | 450 107 | 620 108 | 93 109 | 28 110 | 111 | 112 | 113 | Prev 114 | 115 | 116 | 117 | 118 | 119 | 图片导航 120 | 121 | 122 | 123 | 124 | 40 125 | 20 126 | 1161 127 | 541 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 80 138 | 630 139 | 91 140 | 19 141 | 142 | 143 | 144 | 自动换图 145 | 146 | 147 | 148 | 149 | 150 | 200 151 | 630 152 | 113 153 | 21 154 | 155 | 156 | 157 | 3000 158 | 159 | 160 | 161 | 162 | 163 | 320 164 | 630 165 | 72 166 | 15 167 | 168 | 169 | 170 | ms 171 | 172 | 173 | 174 | 175 | 176 | Toast 177 | 178 | 179 | 180 | 181 | 30 182 | 40 183 | 731 184 | 311 185 | 186 | 187 | 188 | Toast 189 | 190 | 191 | 192 | 193 | 40 194 | 40 195 | 72 196 | 15 197 | 198 | 199 | 200 | 弹出位置: 201 | 202 | 203 | 204 | 205 | 206 | 40 207 | 90 208 | 72 209 | 15 210 | 211 | 212 | 213 | 弹出时长: 214 | 215 | 216 | 217 | 218 | 219 | 140 220 | 40 221 | 151 222 | 22 223 | 224 | 225 | 226 | 227 | 228 | 229 | 140 230 | 90 231 | 151 232 | 22 233 | 234 | 235 | 236 | 237 | 238 | 239 | 620 240 | 270 241 | 93 242 | 31 243 | 244 | 245 | 246 | 显示 247 | 248 | 249 | 250 | 251 | 252 | 40 253 | 140 254 | 72 255 | 15 256 | 257 | 258 | 259 | 显示内容: 260 | 261 | 262 | 263 | 264 | 265 | 140 266 | 130 267 | 441 268 | 121 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 40 277 | 380 278 | 721 279 | 81 280 | 281 | 282 | 283 | 卡片对话框 284 | 285 | 286 | 287 | 288 | 192 289 | 30 290 | 321 291 | 28 292 | 293 | 294 | 295 | 显示卡片对话框 296 | 297 | 298 | 299 | 300 | 301 | 302 | Gallery 303 | 304 | 305 | 306 | 307 | 60 308 | 70 309 | 1111 310 | 541 311 | 312 | 313 | 314 | 315 | 316 | 317 | 750 318 | 630 319 | 93 320 | 28 321 | 322 | 323 | 324 | Next 325 | 326 | 327 | 328 | 329 | 330 | 410 331 | 630 332 | 93 333 | 28 334 | 335 | 336 | 337 | Prev 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | QFlowProgressBar 347 | QLabel 348 |
CustomWidgets\QFlowProgressBar.h
349 |
350 | 351 | QFlowProgressTab 352 | QLabel 353 |
CustomWidgets\QFlowProgressTab.h
354 |
355 | 356 | QPictureSlides 357 | QLabel 358 |
CustomWidgets\QPictureSlides.h
359 |
360 | 361 | QGallery 362 | QWidget 363 |
CustomWidgets\QGallery.h
364 | 1 365 |
366 |
367 | 368 | 369 |
370 | -------------------------------------------------------------------------------- /QtCustomWidgetsExample.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-04-28T19:32:00 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = QtCustomWidgetsExample 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | CustomWidgetsDialog.cpp \ 30 | CustomWidgets/QFlowProgressBar.cpp \ 31 | CustomWidgets/QFlowProgressBase.cpp \ 32 | CustomWidgets/QFlowProgressTab.cpp \ 33 | CustomWidgets/qpictureslides.cpp \ 34 | CustomWidgets/qpixmapobject.cpp \ 35 | CustomWidgets/QCardDialog.cpp \ 36 | CustomWidgets/QToast.cpp \ 37 | CustomWidgets/QGalleryCard.cpp \ 38 | CustomWidgets/QGallery.cpp \ 39 | CustomWidgets/QGalleryCardManager.cpp 40 | 41 | HEADERS += \ 42 | CustomWidgetsDialog.h \ 43 | CustomWidgets/QFlowProgressBar.h \ 44 | CustomWidgets/QFlowProgressBase.h \ 45 | CustomWidgets/QFlowProgressTab.h \ 46 | CustomWidgets/qpictureslides.h \ 47 | CustomWidgets/qpixmapobject.h \ 48 | CustomWidgets/QCardDialog.h \ 49 | CustomWidgets/QToast.h \ 50 | CustomWidgets/QGalleryCard.h \ 51 | CustomWidgets/QGallery.h \ 52 | CustomWidgets/QGalleryCardManager.h 53 | 54 | FORMS += \ 55 | CustomWidgetsDialog.ui 56 | 57 | # Default rules for deployment. 58 | qnx: target.path = /tmp/$${TARGET}/bin 59 | else: unix:!android: target.path = /opt/$${TARGET}/bin 60 | !isEmpty(target.path): INSTALLS += target 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QtCustomWidgets 2 | 一些Qt的自定义控件,从网上或参照移动端的一些好看的控件样式写成的Qt自定义控件
3 | ## 使用方法 4 | 目前控件没有提供Qt设计师界面,需要项目中包含源码。详细使用方法可以参考本项目例子 5 | ## 更新日志 6 | 后续对控件的修改和新增控件会在日志中体现,详细内容请参考[VersionLog](https://github.com/LnJan/QtCustomWidgets/blob/master/VersionLog.md) 7 | ## 效果展示 8 | ### QGallery 9 | 实现图片倒影效果的画廊
10 | ![画廊gif](https://github.com/LnJan/QtCustomWidgets/blob/master/ScreenShorts/QGallery.gif) 11 | ### QFlowProgressBar 12 | 流程进度的进度条目前有四种样式可选。进度条的颜色可自定义,效果如下:
13 | ![流程进度条gif](https://github.com/LnJan/QtCustomWidgets/blob/master/ScreenShorts/FlowProgress.gif) 14 | ### QPictureSlides 15 | 图片导航栏,可自动切换图片和手动切换图片
16 | ![图片导航栏gif](https://github.com/LnJan/QtCustomWidgets/blob/master/ScreenShorts/Sildes.gif) 17 | ### QToast 18 | 类似Android中的Toast功能
19 | ![QToast](https://github.com/LnJan/QtCustomWidgets/blob/master/ScreenShorts/Toast.gif) 20 | ### QCardDialog 21 | 卡片样式的悬浮对话框
22 | ![QCardDialog](https://github.com/LnJan/QtCustomWidgets/blob/master/ScreenShorts/QCard.gif) 23 | -------------------------------------------------------------------------------- /ScreenShorts/FlowProgress.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LnJan/QtCustomWidgets/128e6744ac276c23229ae7e92cbfc3b71f5e4004/ScreenShorts/FlowProgress.gif -------------------------------------------------------------------------------- /ScreenShorts/QCard.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LnJan/QtCustomWidgets/128e6744ac276c23229ae7e92cbfc3b71f5e4004/ScreenShorts/QCard.gif -------------------------------------------------------------------------------- /ScreenShorts/QGallery.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LnJan/QtCustomWidgets/128e6744ac276c23229ae7e92cbfc3b71f5e4004/ScreenShorts/QGallery.gif -------------------------------------------------------------------------------- /ScreenShorts/Sildes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LnJan/QtCustomWidgets/128e6744ac276c23229ae7e92cbfc3b71f5e4004/ScreenShorts/Sildes.gif -------------------------------------------------------------------------------- /ScreenShorts/Toast.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LnJan/QtCustomWidgets/128e6744ac276c23229ae7e92cbfc3b71f5e4004/ScreenShorts/Toast.gif -------------------------------------------------------------------------------- /VersionLog.md: -------------------------------------------------------------------------------- 1 | # 更新日志 2 | ### 2019.05.07 3 | 初次提交的版本,包含QCardDialog、QFlowProgressBar、QFlowProgressTab、QPictureSlides、QToast 4 | ### 2019.05.17 5 | 增加QGallery,图片画廊展示控件 6 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "CustomWidgetsDialog.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | CustomWidgetsDialog w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | --------------------------------------------------------------------------------