File indexing completed on 2024-05-12 04:46:51

0001 /*
0002  * <one line to give the program's name and a brief idea of what it does.>
0003  * Copyright (C) 2019  camilo <chiguitar@unal.edu.co>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #pragma once
0020 #include <QObject>
0021 #include <QQmlEngine>
0022 
0023 /**
0024  * @brief The AppView class.
0025  * Represents the possible attachable properties to be use with the MauiKit AppViews control.
0026  * 
0027  * With this properties information can be attached to the AppViews children views, so the AppViews can - for example - place the view port buttons with the indicated icon and text title.
0028  * @see AppViews
0029  * @see AppViewLoader
0030  * 
0031  * @note This class is exposed as AppView to QML, and is meant to be used as n attached property in the AppViews children views.
0032  * 
0033  * @code
0034  * Item
0035  * {
0036  *  Maui.AppView.title: "View1"
0037  *  Maui.AppView.iconName: "folder"
0038  * }
0039  * @endcode
0040  */
0041 class AppView : public QObject
0042 {
0043     Q_OBJECT
0044      QML_ELEMENT
0045     QML_ATTACHED(AppView)
0046     QML_UNCREATABLE("Cannot be created Controls")
0047     /**
0048      * The title of the view
0049      */
0050     Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
0051     
0052     /**
0053      * The icon name to be used in the AppViews button port
0054      */
0055     Q_PROPERTY(QString iconName READ iconName WRITE setIconName NOTIFY iconNameChanged)
0056     
0057     /**
0058      * The text to be used as a badge in the AppViews button port.
0059      * If this is left empty, then not badge will be shown.
0060      */
0061     Q_PROPERTY(QString badgeText READ badgeText WRITE setBadgeText NOTIFY badgeTextChanged)
0062     
0063 public:
0064     /**
0065      * @private
0066      */
0067     static AppView *qmlAttachedProperties(QObject *object)
0068     {
0069         Q_UNUSED(object)
0070         return new AppView(object);
0071     }
0072     
0073     inline void setTitle(const QString &title)
0074     {
0075         if (title == m_title)
0076             return;
0077 
0078         m_title = title;
0079         Q_EMIT titleChanged();
0080     }
0081 
0082     inline void setIconName(const QString &iconName)
0083     {
0084         if (iconName == m_iconName)
0085             return;
0086 
0087         m_iconName = iconName;
0088         Q_EMIT iconNameChanged();
0089     }
0090     
0091     inline void setBadgeText(const QString &text)
0092     {
0093         if (text == m_badgeText)
0094             return;
0095         
0096         m_badgeText = text;
0097         Q_EMIT badgeTextChanged();
0098     }
0099 
0100     inline const QString title() const
0101     {
0102         return m_title;
0103     }
0104 
0105     inline const QString iconName() const
0106     {
0107         return m_iconName;
0108     }
0109     
0110     inline const QString badgeText() const
0111     {
0112         return m_badgeText;
0113     }    
0114 
0115 private:
0116     using QObject::QObject;
0117 
0118     QString m_title;
0119     QString m_iconName;
0120     QString m_badgeText;
0121 
0122 Q_SIGNALS:
0123     void titleChanged();
0124     void iconNameChanged();
0125     void badgeTextChanged();
0126 };
0127