Skip to content

Commit

Permalink
feat: convert documentation of C++ types to Doxygen
Browse files Browse the repository at this point in the history
  • Loading branch information
plfiorini committed Nov 1, 2024
1 parent 6b026fc commit 0598811
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 96 deletions.
18 changes: 0 additions & 18 deletions src/imports/controls/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,13 @@

#include "clipboard.h"

/*!
\qmltype Clipboard
\inqmlmodule Fluid
\ingroup fluid
\brief Clipboard.
*/

Clipboard::Clipboard(QObject *parent)
: QObject(parent)
, m_clipboard(QGuiApplication::clipboard())
{
connect(m_clipboard, &QClipboard::dataChanged, this, &Clipboard::textChanged);
}

/*!
\qmlproperty string Clipboard::text
This property holds the clipboard text.
*/
QString Clipboard::text() const
{
return m_clipboard->text();
Expand All @@ -47,11 +34,6 @@ void Clipboard::setText(const QString &text)
m_clipboard->setText(text);
}

/*!
\qmlmethod void Clipboard::clear()
Clear the global clipboard contents.
*/
void Clipboard::clear()
{
m_clipboard->clear();
Expand Down
9 changes: 9 additions & 0 deletions src/imports/controls/clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <QClipboard>
#include <QtQml/qqmlregistration.h>

/*!
\brief Clipboard.
*/
class Clipboard : public QObject
{
Q_OBJECT
Expand All @@ -26,8 +29,14 @@ class Clipboard : public QObject
public:
explicit Clipboard(QObject *parent = nullptr);

/*!
This property holds the clipboard text.
*/
QString text() const;

/*!
Clear the global clipboard contents.
*/
Q_INVOKABLE void clear();

public Q_SLOTS:
Expand Down
38 changes: 0 additions & 38 deletions src/imports/controls/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,16 @@

#include "color.h"

/*!
\qmltype Color
\instantiates Color
\inqmlmodule Fluid
\brief Utility functions for colors.
Utility functions to manipulate colors.
*/

Color::Color(QObject *parent)
: QObject(parent)
{
}

/*!
\qmlmethod color Fluid.Controls::Color::transparent(color color, real alpha)
A utility method for changing the \a alpha on \a color.
Returns a new object, and does not modify the original color at all.
*/
QColor Color::transparent(const QColor &color, qreal alpha)
{
return QColor(color.red(), color.green(), color.blue(), int(qBound<qreal>(0.0, alpha, 1.0) * 255));
}

/*!
\qmlmethod color Fluid.Controls::Color::blend(color color1, color color2, real alpha)
Blend \a color1 and \a color2 together and set alpha to \a alpha.
*/
QColor Color::blend(const QColor &color1, const QColor &color2, qreal alpha)
{
QColor color;
Expand All @@ -54,34 +33,17 @@ QColor Color::blend(const QColor &color1, const QColor &color2, qreal alpha)
return transparent(color, alpha);
}

/*!
\qmlmethod real Fluid.Controls::Color::luminance(color color)
Calculate luminance of \a color.
*/
qreal Color::luminance(const QColor &color)
{
return (color.redF() * 0.2126) + (color.greenF() * 0.7152) + (color.blueF() * 0.0722);
}

/*!
\qmlmethod bool Fluid.Controls::Color::isDarkColor(color color)
Returns \c true if \a color is dark and should have light content on top.
*/
bool Color::isDarkColor(const QColor &color)
{
auto a = 1.0 - (0.299 * color.redF() + 0.587 * color.greenF() + 0.114 * color.blueF());
return color.alphaF() > 0.0 && a >= 0.3;
}

/*!
\qmlmethod color Fluid.Controls::Color::lightDark(color background, color lightColor, color darkColor)
Select a color depending on whether \a background color is light or dark.
Returns \a lightColor if \a background is a light color, otherwise
returns \a darkColor.
*/
QColor Color::lightDark(const QColor &background, const QColor &lightColor, const QColor &darkColor)
{
return isDarkColor(background) ? darkColor : lightColor;
Expand Down
28 changes: 28 additions & 0 deletions src/imports/controls/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#include <QObject>
#include <QQmlEngine>

/*!
\brief Utility functions for colors.
Utility functions to manipulate colors.
*/
class Color : public QObject
{
Q_OBJECT
Expand All @@ -26,10 +31,33 @@ class Color : public QObject
public:
explicit Color(QObject *parent = nullptr);

/*!
A utility method for changing the \a alpha on \a color.
Returns a new object, and does not modify the original color at all.
*/
Q_INVOKABLE QColor transparent(const QColor &color, qreal alpha);


/*!
Blend \a color1 and \a color2 together and set alpha to \a alpha.
*/
Q_INVOKABLE QColor blend(const QColor &color1, const QColor &color2, qreal alpha);

/*!
Calculate luminance of \a color.
*/
Q_INVOKABLE qreal luminance(const QColor &color);

/*!
Returns \c true if \a color is dark and should have light content on top.
*/
Q_INVOKABLE bool isDarkColor(const QColor &color);

/*!
Select a color depending on whether \a background color is light or dark.
Returns \a lightColor if \a background is a light color, otherwise
returns \a darkColor.
*/
Q_INVOKABLE QColor lightDark(const QColor &background, const QColor &lightColor,
const QColor &darkColor);

Expand Down
40 changes: 0 additions & 40 deletions src/imports/controls/controlsutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,17 @@

#include "controlsutils.h"

/*!
\qmltype Fluid.Controls::Utils
\inqmlmodule Fluid
\ingroup fluid
\brief A collection of helpful utility methods.
*/
ControlsUtils::ControlsUtils(const QUrl &baseUrl, QObject *parent)
: QObject(parent)
, m_baseUrl(baseUrl)
{
}

/*!
\qmlmethod real Fluid::Utils::scale(real percent, real start, real end)
Scale \a percent in the range between \a start and \a end.
*/
qreal ControlsUtils::scale(qreal percent, qreal start, qreal end)
{
return start + ((end - start) * (percent / 100));
}

/*!
\qmlmethod url Fluid::Utils::iconUrl(string name)
Returns an URL for the Material Design icon \a name.
Use this URL with Image or icon grouped property with controls.
\code
import QtQuick
import Fluid as Fluid
Image {
source: Fluid.Utils.iconUrl("action/alarm")
width: 64
height: 64
}
\endcode
\code
import QtQuick
import QtQuick.Controls
import Fluid as Fluid
Button {
icon.source: Fluid.Utils.iconUrl("action/alarm")
text: qsTr("Alarm")
}
\endcode
*/
QUrl ControlsUtils::iconUrl(const QString &name)
{
#if FLUID_INSTALL_ICONS == 1
Expand Down
33 changes: 33 additions & 0 deletions src/imports/controls/controlsutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <QUrl>
#include <QQmlEngine>

/*!
\brief A collection of helpful utility methods.
*/
class ControlsUtils : public QObject
{
Q_OBJECT
Expand All @@ -26,7 +29,37 @@ class ControlsUtils : public QObject
public:
explicit ControlsUtils(const QUrl &baseUrl, QObject *parent = nullptr);

/*!
Scale \a percent in the range between \a start and \a end.
*/
Q_INVOKABLE qreal scale(qreal percent, qreal start, qreal end);

/*!
Returns an URL for the Material Design icon \a name.
Use this URL with Image or icon grouped property with controls.
\code{.qml}
import QtQuick
import Fluid as Fluid
Image {
source: Fluid.Utils.iconUrl("action/alarm")
width: 64
height: 64
}
\endcode
\code{.qml}
import QtQuick
import QtQuick.Controls
import Fluid as Fluid
Button {
icon.source: Fluid.Utils.iconUrl("action/alarm")
text: qsTr("Alarm")
}
\endcode
*/
Q_INVOKABLE QUrl iconUrl(const QString &name);

static ControlsUtils *create(QQmlEngine *engine, QJSEngine *jsEngine);
Expand Down

0 comments on commit 0598811

Please sign in to comment.