カスタムを書くためにQtは33アニメーション画像スイッチを制御します

I.はじめに

多くのプラグインソフトでは、タイムスイッチは、写真を撮ったり、アニメーショントランジションのトランジション効果は、このような、どんなに多くの種類の効果の、左下隅に、両方のコアを飛んでいないとして、主に透明度を変更する、などブラインドなどの一部を、魅了、実際には、より人間的なように見えますQPainterのは、持ち運び画像様々なアニメーション効果に対応する動的計算領域、プロット、フライに入るように、アニメーションプロパティQPropertyAnimation線形補間を生成するように協働して、彼らはすぐに中間端遅くすることができます。現在のアニメーションの9種類があり、後者は増加していきます。

  • 1:1と徐々に画像をフェードイン、画像は徐々に2に表示されます
  • 2:シェード効果
  • 3:右から左に画像を反転
  • 4:水平分割で外部から
  • 5:ながら、画像の可視領域を終了し、左から右へ1表示領域2に、左から右へ画像
  • 6:ながら、左から右へ1出口画像可視領域、可視領域2に、左から右へ画像
  • 底出口画像可視領域から1、可視領域に底部から一方の画像2:7
  • 8:1底出口可視領域上からの画像を、一方で可視領域2に上から下へ画像
  • 9:1の画像は、2右下から左上に画像が、移動しません

第二に、機能の実現

  • 1:円弧線スタイルのリングスタイルを回転円弧状のスタイルのスタイルスタイルの三角形を待つために様々なスタイルをサポート
  • 2:設定可能範囲と電流値
  • 3:前景背景色を提供することができます
  • 4:反時計回りの回転が設けられていてもよいです
  • 5:任意のサイズのスケーリングをサポートしています
  • 6:回転速度間隔の設定をサポート

第三に、レンダリング

第四に、ヘッダファイルのコード

#ifndef IMAGEANIMATION_H
#define IMAGEANIMATION_H

/**
 * 图片切换动画控件 作者:赵彦博(QQ:408815041 [email protected]) 2019-6-10
 * 1:可设置动画类型,默认9种,后期会增加更多
 * FadeEffect = 0,             //图像1渐渐变淡,图像2渐渐显现
 * BlindsEffect = 1,           //百叶窗效果
 * FlipRightToLeft = 2,        //图像从右向左翻转
 * OutsideToInside = 3,        //从外到内水平分割
 * MoveLeftToRightEffect = 4,  //图像1从左至右退出可视区域,同时图像2从左至右进入可视区域
 * MoveRightToLeftEffect = 5,  //图像1从左至右退出可视区域,同时图像2从左至右进入可视区域
 * MoveBottomToUpEffect = 6,   //图像1从下至上退出可视区域,同时图像2从下至上进入可视区域
 * MoveUpToBottomEffect = 7,   //图像1从上至下退出可视区域,同时图像2从上至下进入可视区域
 * MoveBottomToLeftUpEffect = 8//图像1不动,同时图像2从右下到左上
 * 2:可设置两张图片的路径名称或者图片
 * 3:可设置动画因子
 */

#include <QWidget>

class QPropertyAnimation;

#ifdef quc
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
#include <QtDesigner/QDesignerExportWidget>
#else
#include <QtUiPlugin/QDesignerExportWidget>
#endif

class QDESIGNER_WIDGET_EXPORT ImageAnimation : public QWidget
#else
class ImageAnimation : public QWidget
#endif

{
    Q_OBJECT
    Q_ENUMS(AnimationType)
    Q_PROPERTY(float factor READ getFactor WRITE setFactor)
    Q_PROPERTY(QString imageName1 READ getImageName1 WRITE setImageName1)
    Q_PROPERTY(QString imageName2 READ getImageName2 WRITE setImageName2)
    Q_PROPERTY(QPixmap pixmap1 READ getPixmap1 WRITE setPixmap1)
    Q_PROPERTY(QPixmap pixmap2 READ getPixmap2 WRITE setPixmap2)
    Q_PROPERTY(AnimationType animationType READ getAnimationType WRITE setAnimationType)

public:
    enum AnimationType {
        FadeEffect = 0,             //图像1渐渐变淡,图像2渐渐显现
        BlindsEffect = 1,           //百叶窗效果
        FlipRightToLeft = 2,        //图像从右向左翻转
        OutsideToInside = 3,        //从外到内水平分割
        MoveLeftToRightEffect = 4,  //图像1从左至右退出可视区域,同时图像2从左至右进入可视区域
        MoveRightToLeftEffect = 5,  //图像1从左至右退出可视区域,同时图像2从左至右进入可视区域
        MoveBottomToUpEffect = 6,   //图像1从下至上退出可视区域,同时图像2从下至上进入可视区域
        MoveUpToBottomEffect = 7,   //图像1从上至下退出可视区域,同时图像2从上至下进入可视区域
        MoveBottomToLeftUpEffect = 8//图像1不动,同时图像2从右下到左上
    };

    explicit ImageAnimation(QWidget *parent = 0);
    ~ImageAnimation();

protected:
    void paintEvent(QPaintEvent *);
    void fadeEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void blindsEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void flipRightToLeft(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void outsideToInside(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void moveLeftToRightEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void moveRightToLeftEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void moveBottomToUpEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void moveUpToBottomEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);
    void moveBottomToLeftUpEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2);

private:
    float factor;                   //动画因子(0 - 1.0之间变化)
    QString imageName1;             //图片1路径名称
    QString imageName2;             //图片2路径名称
    QPixmap pixmap1;                //图片1
    QPixmap pixmap2;                //图片2
    AnimationType animationType;    //动画效果类型

    QPropertyAnimation *animation;  //动画属性

public:
    float getFactor()               const;
    QString getImageName1()         const;
    QString getImageName2()         const;
    QPixmap getPixmap1()            const;
    QPixmap getPixmap2()            const;
    AnimationType getAnimationType()const;

    QSize sizeHint()                const;
    QSize minimumSizeHint()         const;

public Q_SLOTS:
    //设置动画因子
    void setFactor(float factor);

    //设置图片1+图片2路径名称
    void setImageName1(const QString &imageName1);
    void setImageName2(const QString &imageName2);

    //设置图片1+图片2
    void setPixmap1(const QPixmap &pixmap1);
    void setPixmap2(const QPixmap &pixmap2);

    //设置动画类型
    void setAnimationType(const AnimationType &animationType);

    //启动+停止动画
    void start();
    void stop();
};

#endif // IMAGEANIMATION_H

第五に、コアコード

void ImageAnimation::paintEvent(QPaintEvent *)
{
    if (pixmap1.isNull() || pixmap2.isNull()) {
        return;
    }

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);

    switch (animationType) {
    case 0:
        fadeEffect(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 1:
        blindsEffect(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 2:
        flipRightToLeft(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 3:
        outsideToInside(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 4:
        moveLeftToRightEffect(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 5:
        moveRightToLeftEffect(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 6:
        moveBottomToUpEffect(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 7:
        moveUpToBottomEffect(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    case 8:
        moveBottomToLeftUpEffect(&painter, geometry(), factor, pixmap1, pixmap2);
        break;
    default:
        break;
    }
}

void ImageAnimation::fadeEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2)
{
    int w = rect.width();
    int h = rect.height();
    int alpha = 255 * (1.0f - factor);

    QPixmap alphaPixmap(pixmap1.size());
    alphaPixmap.fill(Qt::transparent);

    QPainter p1(&alphaPixmap);
    p1.setCompositionMode(QPainter::CompositionMode_Source);
    p1.drawPixmap(0, 0, pixmap1);
    p1.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    p1.fillRect(alphaPixmap.rect(), QColor(0, 0, 0, alpha));
    p1.end();

    int x = (w - pixmap1.width()) / 2;
    int y = (h - pixmap1.height()) / 2;
    painter->drawPixmap(x, y, alphaPixmap);

    alpha = 255 * (factor);
    alphaPixmap.fill(Qt::transparent);
    QPainter p2(&alphaPixmap);
    p2.setCompositionMode(QPainter::CompositionMode_Source);
    p2.drawPixmap(0, 0, pixmap2);
    p2.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    p2.fillRect(alphaPixmap.rect(), QColor(0, 0, 0, alpha));
    p2.end();

    painter->drawPixmap(x, y, alphaPixmap);
}

void ImageAnimation::blindsEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2)
{
    int i, n, w, h, x1, y1, x2, y2, dh, ddh;

    w = rect.width();
    h = rect.height();
    x1 = (w - pixmap1.width()) / 2;
    y1 = (h - pixmap1.height()) / 2;
    x2 = (w - pixmap2.width()) / 2;
    y2 = (h - pixmap2.height()) / 2;

    painter->drawPixmap(x1, y1, pixmap1);

    n = 10;
    dh = pixmap2.height() / n;
    ddh = factor * dh;
    if (ddh < 1) {
        ddh = 1;
    }

    for(i = 0; i < n; i++) {
        painter->drawPixmap(x2, y2 + i * dh, pixmap2, 0, i * dh, pixmap2.width(), ddh);
    }
}

void ImageAnimation::flipRightToLeft(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2)
{
    int x1, y1, x2, y2, w, h;
    float rot;
    QTransform trans;

    w = rect.width();
    h = rect.height();
    x1 = (w - pixmap1.width()) / 2;
    y1 = (h - pixmap1.height()) / 2;
    x2 = (w - pixmap2.width()) / 2;
    y2 = (h - pixmap2.height()) / 2;

    rot = factor * 90.0f;
    trans.translate(w * (1 - factor), h / 2);
    trans.rotate(rot, Qt::YAxis);
    trans.translate(-w, -h / 2);

    painter->setTransform(trans);
    painter->drawPixmap(x1, y1, pixmap1);
    painter->resetTransform();

    trans.reset();
    rot = 90 * (factor - 1);
    trans.translate(w * (1 - factor), h / 2);
    trans.rotate(rot, Qt::YAxis);
    trans.translate(0, -h / 2);

    painter->setTransform(trans);
    painter->drawPixmap(x2, y2, pixmap2);
    painter->resetTransform();
}

void ImageAnimation::outsideToInside(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2)
{
    int   w, h, x1, y1, x2, y2, x3, y3, dh, ddh;

    w = rect.width();
    h = rect.height();
    x1 = (w - pixmap1.width()) / 2;
    y1 = (h - pixmap1.height()) / 2;
    painter->drawPixmap(x1, y1, pixmap1);

    dh = pixmap2.height() / 2;
    ddh = factor * dh;
    if (ddh < 1) {
        ddh = 1;
    }

    x2 = (w - pixmap2.width()) / 2;
    y2 = (h - pixmap2.height()) / 2;
    painter->drawPixmap(x2, y2, pixmap2, 0, 0, pixmap2.width(), ddh);

    x3 = (w - pixmap2.width()) / 2;
    y3 =  dh * (1.0f - factor) + h / 2;
    if(y3 != h / 2) {
        y3 += 1;
    }

    painter->drawPixmap(x3, y3, pixmap2, 0, pixmap2.height() - ddh, pixmap2.width(), ddh);
}

void ImageAnimation::moveLeftToRightEffect(QPainter *painter, const QRect &rect, float factor, const QPixmap &pixmap1, const QPixmap &pixmap2)
{
    int x, y, w, h, x1, y1, x2, y2;

    w = rect.width();
    h = rect.height();
    x1 = (w - pixmap1.width()) / 2;
    y1 = (h - pixmap1.height()) / 2;
    x2 = (w - pixmap2.width()) / 2;
    y2 = (h - pixmap2.height()) / 2;

    x = x1 + w * factor;
    y = y1;
    painter->drawPixmap(x, y, pixmap1);

    x = x2 + w * (factor - 1);
    y = y2;
    painter->drawPixmap(x, y, pixmap2);
}

第六に、コントロールが説明します

  1. 以上149絶妙な制御、ように太陰暦、セレクタをスライドさせ、ボタンを強調表示し、ダッシュボードのさまざま、プログレスバー、ボール、コンパス、グラフ、スケール、温度計、ナビゲーションバー、ナビゲーションバー、flatuiの進行を覆い。コントロールの統合の数よりもはるかに多くのQWT。
  2. 各クラスは、以下のプロジェクトのソースコード形式に統合個々の制御を容易にするために、ゼロが符号量を達成するために、各制御ファイルおよびヘッダファイルを結合する、別の対照として、独立して他のファイルとは無関係であることができます。QWT性の高い結合されたコントロールクラスを、連動、すべてのコードが含まれている必要があり、コントロールのいずれかを使用します。
  3. 、描画するために、任意のQtバージョンQt4.6 Qt5.12などmingwの、MSVC、GCCコンパイラのサポートをサポートするために、そのような窓+ Linuxの+マック+文字化けしません組み込みLinuxのような任意のオペレーティングシステムをサポートするすべての純粋なQtの、QWidgetの+ QPainterのを書きます直接のQt Creatorを、組み込みコントロールに統合されており、同じを使用することができ、効果のほとんどは、限り、いくつかのプロパティが設定されているように非常に便利です。
  4. 各制御に対応する制御を含有するDEMO別のソースは、便利な参照を有します。また、すべてのコントロールDEMOの統合された使用を提供します。
  5. 各コントロールのソースコードは、中国の注釈を詳細なカスタムコントロールを書くことを学ぶのは簡単、統一された設計仕様に基づいて作成されています。
  6. 各コントロールのデフォルトの色とデモに対応する色がとても美しいです。
  7. 130以上の可視制御六の不可視コントロール。
  8. 一部のコントロールは、スタイルのスタイルの選択、複数の選択肢のスタイルインジケータを数多く提供しています。
  9. すべてのコントロールは、適応伸ばしフォームを変更します。
  10. ドラッグデザインをサポートする統合デザインカスタム属性、WYSIWYGは、XML形式でインポートおよびエクスポートをサポートしています。
  11. デモに付属しているActiveXコントロールは、すべてのコントロールは、ブラウザのIEで直接実行することができます。
  12. Fontawesome統合グラフィックスフォント+グラフィックフォントの何百ものAlibabaのiconfontコレクション、フォント楽しいグラフィックがもたらします。
  13. 最終的にはすべてのコントロールとDLLの動的ライブラリファイルを生成するには、ドラッグでの使用のために設計されqtcreatorに直接統合することができます。
  14. 次に、ユーザは、大きな需要がある場合は、既にQMLバージョンでは、後者は、PyQtはバージョンを検討します。

七、SDKのダウンロード

  • SDKのダウンロードリンクします。https://pan.baidu.com/s/1A5Gd77kExm8Co5ckT51vvQ抽出コード:877p
  • リンクは、動的ライブラリファイルのさまざまなバージョン、すべてのコントロールのヘッダファイル、デモの使用、カスタムコントロール+プロパティのデザイナーに含まれてダウンロードしてください。
  • オープンプラグインのカスタム動的ライブラリのdllを使用(永久無料)、及び任意の制限なし、バックドア、使いやすさ。
  • qt5.12.3 msvc2017 32 + 64 mingwの32 + 64内を含む26現在利用可能バージョンのDLL、。
  • コントロールを向上させ、コントロールを改善するために、随時、定期的に更新SDK、すべての提案を歓迎するために、ありがとうございました!
  • ウィジェットバージョン(QQ:517216493)QMLバージョン(QQ:373955953)sambongラクダ(QQ:278969898)。
  • Qtの高度な列はほとんどTaogeの道を知っているhttps://zhuanlan.zhihu.com/TaoQt
  • スキルを書くようこそ懸念公共マイクロチャネル番号] [効率的なプログラマー、コンテンツC ++ / Pythonの、学習、人気の高い技術、キャリア開発、乾燥品の多くは、多くの利益をもたらします!

おすすめ

転載: www.cnblogs.com/feiyangqingyun/p/11223002.html