File indexing completed on 2025-02-02 04:11:33

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QIcon>
0010 
0011 #include "glaxnimate_app.hpp"
0012 #include "model/animation/keyframe_transition.hpp"
0013 
0014 namespace glaxnimate::gui {
0015 
0016 struct KeyframeTransitionData
0017 {
0018     static constexpr const int count = model::KeyframeTransition::Custom + 1;
0019 
0020     enum Side
0021     {
0022         Full,
0023         Start,
0024         Finish,
0025     };
0026 
0027     QString name;
0028     Side side;
0029     const char* icon_slug;
0030     model::KeyframeTransition::Descriptive value;
0031 
0032     QIcon icon(Side side) const
0033     {
0034         const char* side_path = "";
0035         if ( side == Start )
0036             side_path = "/start";
0037         else if ( side == Finish )
0038             side_path = "/finish";
0039 
0040         return QIcon(GlaxnimateApp::instance()->data_file(QString("images/keyframe%1/%2.svg").arg(side_path).arg(icon_slug)));
0041     }
0042 
0043     QIcon icon() const
0044     {
0045         return icon(side);
0046     }
0047 
0048     QVariant variant() const
0049     {
0050         return QVariant::fromValue(value);
0051     }
0052 
0053     static KeyframeTransitionData data(model::KeyframeTransition::Descriptive value, Side side = Full)
0054     {
0055         switch ( value )
0056         {
0057             case model::KeyframeTransition::Hold:
0058                 return {i18n("Hold"), side, "hold", value};
0059             case model::KeyframeTransition::Linear:
0060                 return {i18n("Linear"), side, "linear", value};
0061             case model::KeyframeTransition::Ease:
0062                 return {ease_name(side), side, "ease", value};
0063             case model::KeyframeTransition::Fast:
0064                 return {i18n("Fast"), side, "fast", value};
0065             case model::KeyframeTransition::Overshoot:
0066                 return {overshoot_name(side), side, "overshoot", value};
0067             default:
0068             case model::KeyframeTransition::Custom:
0069                 return {i18n("Custom"), side, "custom", value};
0070         }
0071     }
0072 
0073     static KeyframeTransitionData from_index(int index, Side side = Full)
0074     {
0075         return data(model::KeyframeTransition::Descriptive(index), side);
0076     }
0077 
0078 private:
0079     static QString ease_name(Side side)
0080     {
0081         switch ( side )
0082         {
0083             case Start:
0084                 return i18n("Ease In");
0085             case Finish:
0086                 return i18n("Ease Out");
0087             default:
0088             case Full:
0089                 return i18n("Ease");
0090         }
0091     }
0092 
0093     static QString overshoot_name(Side side)
0094     {
0095         switch ( side )
0096         {
0097             case Start:
0098                 return i18n("Anticipate");
0099             case Finish:
0100                 return i18n("Overshoot");
0101             default:
0102             case Full:
0103                 return i18n("Overshoot");
0104         }
0105     }
0106 };
0107 
0108 } // namespace glaxnimate::gui