From b1c56960a6c58a235e6a3e0b749153a04222a2b8 Mon Sep 17 00:00:00 2001 From: tianduanrui <2407223896@qq.com> Date: Sat, 18 Nov 2017 11:38:00 +0800 Subject: [PATCH] fix svg widget qt4 build --- examples/svgtest/mainwindow.cpp | 15 +++++++++------ examples/svgtest/mainwindow.h | 7 +++++-- src/svgwidgets/qqtgraphicssvgitem.h | 5 +++-- src/svgwidgets/qqtsvgcheckbox.h | 5 +++-- src/svgwidgets/qqtsvglabel.cpp | 29 +++++++++++++++++------------ src/svgwidgets/qqtsvglabel.h | 9 +++++---- src/svgwidgets/qqtsvgprogressbar.h | 1 + src/svgwidgets/qqtsvgpushbutton.h | 5 +++-- src/svgwidgets/qqtsvgradiobutton.h | 5 +++-- src/svgwidgets/qqtsvgwidget.h | 1 + src/widgets/qqttreeview.h | 8 ++++---- src/widgets/qqttreewidget.cpp | 5 ++--- 12 files changed, 56 insertions(+), 39 deletions(-) diff --git a/examples/svgtest/mainwindow.cpp b/examples/svgtest/mainwindow.cpp index 3c864dec..6b72c605 100644 --- a/examples/svgtest/mainwindow.cpp +++ b/examples/svgtest/mainwindow.cpp @@ -36,15 +36,12 @@ MainWindow::MainWindow ( QWidget* parent ) : "/Users/abel/Develop/d1-product/App/skin/default/bt_stir_press.svg" ); ui->p0->setRange ( 0, 100 ); ui->p0->setValue ( 60 ); + QTimer* timer = new QTimer ( this ); timer->setInterval ( 100 ); timer->setSingleShot ( false ); - QObject::connect ( timer, &QTimer::timeout, - [this] - { - static int i = 0; - ui->p0->setValue ( i++ % 100 ); - } ) ; + QObject::connect ( timer, SIGNAL ( timeout() ), + this, SLOT ( updateProgress() ) ) ; timer->start(); } @@ -52,3 +49,9 @@ MainWindow::~MainWindow() { delete ui; } + +void MainWindow::updateProgress() +{ + static int i = 0; + ui->p0->setValue ( i++ % 100 ); +} diff --git a/examples/svgtest/mainwindow.h b/examples/svgtest/mainwindow.h index a3948a91..aa8115fa 100644 --- a/examples/svgtest/mainwindow.h +++ b/examples/svgtest/mainwindow.h @@ -12,11 +12,14 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow ( QWidget* parent = 0 ); ~MainWindow(); +private slots: + void updateProgress(); + private: - Ui::MainWindow *ui; + Ui::MainWindow* ui; }; #endif // MAINWINDOW_H diff --git a/src/svgwidgets/qqtgraphicssvgitem.h b/src/svgwidgets/qqtgraphicssvgitem.h index ce22928d..2685b101 100644 --- a/src/svgwidgets/qqtgraphicssvgitem.h +++ b/src/svgwidgets/qqtgraphicssvgitem.h @@ -3,13 +3,14 @@ #include #include +#include class QQTSHARED_EXPORT QQtGraphicsSvgItem : public QGraphicsSvgItem { Q_OBJECT public: - explicit QQtGraphicsSvgItem(QQtGraphicsSvgItem* parent = nullptr); - explicit QQtGraphicsSvgItem(const QString& fileName, QQtGraphicsSvgItem* parentItem = nullptr); + explicit QQtGraphicsSvgItem ( QQtGraphicsSvgItem* parent = nullptr ); + explicit QQtGraphicsSvgItem ( const QString& fileName, QQtGraphicsSvgItem* parentItem = nullptr ); signals: diff --git a/src/svgwidgets/qqtsvgcheckbox.h b/src/svgwidgets/qqtsvgcheckbox.h index e0d0b348..4864fe57 100644 --- a/src/svgwidgets/qqtsvgcheckbox.h +++ b/src/svgwidgets/qqtsvgcheckbox.h @@ -5,12 +5,13 @@ #include #include #include +#include class QQTSHARED_EXPORT QQtSvgCheckBox : public QQtCheckBox { Q_OBJECT public: - explicit QQtSvgCheckBox(QWidget* parent = nullptr); + explicit QQtSvgCheckBox ( QWidget* parent = nullptr ); /** * @brief renderToVariable @@ -23,7 +24,7 @@ public slots: // QWidget interface protected: - virtual void paintEvent(QPaintEvent* event) override; + virtual void paintEvent ( QPaintEvent* event ) override; private: QSvgRenderer r[BTN_MAX]; }; diff --git a/src/svgwidgets/qqtsvglabel.cpp b/src/svgwidgets/qqtsvglabel.cpp index 33a28c9b..703e53b4 100644 --- a/src/svgwidgets/qqtsvglabel.cpp +++ b/src/svgwidgets/qqtsvglabel.cpp @@ -2,32 +2,37 @@ #include #include -QQtSvgLabel::QQtSvgLabel(QWidget* parent) : QQtLabel(parent) +QQtSvgLabel::QQtSvgLabel ( QWidget* parent ) : QQtLabel ( parent ) { } -void QQtSvgLabel::setSvgFile(QString& filename) +void QQtSvgLabel::setSvgFile ( QString& filename ) { - mSvgRender.load(filename); + mSvgRender.load ( filename ); } -void QQtSvgLabel::setSvgContent(QByteArray& bytes) +void QQtSvgLabel::setSvgContent ( QByteArray& bytes ) { - mSvgRender.load(bytes); + mSvgRender.load ( bytes ); } -void QQtSvgLabel::paintEvent(QPaintEvent* event) +void QQtSvgLabel::paintEvent ( QPaintEvent* event ) { - Q_UNUSED(event) + Q_UNUSED ( event ) - QStylePainter p(this); - if (mSvgRender.isValid()) - mSvgRender.render(&p); + QStylePainter p ( this ); + + if ( mSvgRender.isValid() ) + mSvgRender.render ( &p ); bool enabled = isEnabled(); +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + p.drawItemText ( rect(), alignment(), palette(), enabled, text() ); +#else QStyleOptionFrame opt; - initStyleOption(&opt); - p.drawItemText(rect(), alignment(), opt.palette, enabled, text()); + initStyleOption ( &opt ); + p.drawItemText ( rect(), alignment(), opt.palette, enabled, text() ); +#endif } diff --git a/src/svgwidgets/qqtsvglabel.h b/src/svgwidgets/qqtsvglabel.h index 894e4d47..69e7317b 100644 --- a/src/svgwidgets/qqtsvglabel.h +++ b/src/svgwidgets/qqtsvglabel.h @@ -4,15 +4,16 @@ #include #include #include +#include class QQTSHARED_EXPORT QQtSvgLabel : public QQtLabel { Q_OBJECT public: - explicit QQtSvgLabel(QWidget* parent = nullptr); + explicit QQtSvgLabel ( QWidget* parent = nullptr ); - void setSvgFile(QString& filename); - void setSvgContent(QByteArray& bytes); + void setSvgFile ( QString& filename ); + void setSvgContent ( QByteArray& bytes ); signals: @@ -20,7 +21,7 @@ public slots: // QWidget interface protected: - virtual void paintEvent(QPaintEvent* event) override; + virtual void paintEvent ( QPaintEvent* event ) override; private: QSvgRenderer mSvgRender; diff --git a/src/svgwidgets/qqtsvgprogressbar.h b/src/svgwidgets/qqtsvgprogressbar.h index 42627998..a1338838 100644 --- a/src/svgwidgets/qqtsvgprogressbar.h +++ b/src/svgwidgets/qqtsvgprogressbar.h @@ -4,6 +4,7 @@ #include #include #include +#include class QQTSHARED_EXPORT QQtSvgProgressBar : public QQtSvgWidget { diff --git a/src/svgwidgets/qqtsvgpushbutton.h b/src/svgwidgets/qqtsvgpushbutton.h index 122079da..6dacce4b 100644 --- a/src/svgwidgets/qqtsvgpushbutton.h +++ b/src/svgwidgets/qqtsvgpushbutton.h @@ -5,12 +5,13 @@ #include #include #include +#include class QQTSHARED_EXPORT QQtSvgPushButton : public QQtPushButton { Q_OBJECT public: - explicit QQtSvgPushButton(QWidget* parent = nullptr); + explicit QQtSvgPushButton ( QWidget* parent = nullptr ); virtual ~QQtSvgPushButton() {} /** @@ -25,7 +26,7 @@ public slots: // QWidget interface protected: - virtual void paintEvent(QPaintEvent* event) override; + virtual void paintEvent ( QPaintEvent* event ) override; private: QSvgRenderer r[BTN_MAX]; diff --git a/src/svgwidgets/qqtsvgradiobutton.h b/src/svgwidgets/qqtsvgradiobutton.h index 959d0e66..b668642c 100644 --- a/src/svgwidgets/qqtsvgradiobutton.h +++ b/src/svgwidgets/qqtsvgradiobutton.h @@ -5,12 +5,13 @@ #include #include #include +#include class QQTSHARED_EXPORT QQtSvgRadioButton : public QQtRadioButton { Q_OBJECT public: - explicit QQtSvgRadioButton(QWidget* parent = nullptr); + explicit QQtSvgRadioButton ( QWidget* parent = nullptr ); /** * @brief renderToVariable * call this function after iconTable() set. @@ -22,7 +23,7 @@ public slots: // QWidget interface protected: - virtual void paintEvent(QPaintEvent* event) override; + virtual void paintEvent ( QPaintEvent* event ) override; private: QSvgRenderer r[BTN_MAX]; }; diff --git a/src/svgwidgets/qqtsvgwidget.h b/src/svgwidgets/qqtsvgwidget.h index e12a825a..e345fd5d 100644 --- a/src/svgwidgets/qqtsvgwidget.h +++ b/src/svgwidgets/qqtsvgwidget.h @@ -3,6 +3,7 @@ #include #include +#include class QQTSHARED_EXPORT QQtSvgWidget : public QSvgWidget { diff --git a/src/widgets/qqttreeview.h b/src/widgets/qqttreeview.h index 7ec1d2f6..df964aea 100644 --- a/src/widgets/qqttreeview.h +++ b/src/widgets/qqttreeview.h @@ -9,15 +9,15 @@ class QQTSHARED_EXPORT QQtTreeView : public QTreeView Q_OBJECT public: - explicit QQtTreeView(QWidget* parent = 0); + explicit QQtTreeView ( QWidget* parent = 0 ); virtual ~QQtTreeView(); private: - // QQTTreeView interface + // QQtTreeView interface protected: - void drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const; - void drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const; + void drawRow ( QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index ) const; + void drawBranches ( QPainter* painter, const QRect& rect, const QModelIndex& index ) const; }; #endif // QQTTREEVIEW_H diff --git a/src/widgets/qqttreewidget.cpp b/src/widgets/qqttreewidget.cpp index a6ec5dc5..20fa9366 100644 --- a/src/widgets/qqttreewidget.cpp +++ b/src/widgets/qqttreewidget.cpp @@ -1,9 +1,8 @@ #include "qqttreewidget.h" -#include "ui_qqttreewidget.h" #include "qqtxmltreemodel.h" -QQtTreeWidget::QQtTreeWidget(QWidget* parent) : - QQtTreeView(parent) +QQtTreeWidget::QQtTreeWidget ( QWidget* parent ) : + QQtTreeView ( parent ) { }