Skip to content

Commit

Permalink
doc: update docs for diconbutton
Browse files Browse the repository at this point in the history
更新diconbutton的文档,添加示例代码及运行图片

Log: update docs

Issue: linuxdeepin/dtk#94
  • Loading branch information
lavender9527 authored and Whale107 committed Aug 28, 2024
1 parent ef8bede commit 86309b6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 21 deletions.
Binary file added docs/images/DIconButton_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 76 additions & 4 deletions docs/widgets/diconbutton.zh_CN.dox
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,83 @@
@~chinese
@file diconbutton.h
@ingroup button
@class
@brief
@details

TODO: 添加类简介、示例代码、示例截图和函数使用说明等
@class Dtk::Widget::DIconButton
@brief 按钮的图标
@details 定制化的按钮图标,可以根据传入的图标参数具体调整
### 示例代码
#### main.cpp
```cpp
#include <QVBoxLayout>
#include <DApplication>
#include <DMainWindow>
#include <DIconButton>

DWIDGET_USE_NAMESPACE

int main(int argc, char *argv[])
{
DApplication app(argc, argv);
DMainWindow window;
window.setMinimumSize(QSize(600, 200));

QWidget *centralWidget = new QWidget(&window);
QVBoxLayout *layout = new QVBoxLayout(centralWidget);

DIconButton *button1 = new DIconButton(QStyle::SP_DirIcon);
button1->setNewNotification(true); // 显示小红点
button1->setIconSize(QSize(32, 32)); // 设置图标尺寸为 32x32
layout->addWidget(button1);

DIconButton *button2 = new DIconButton();
button2->setIcon(QIcon("image.jpg")); // 使用本地的图片作为icon
button2->setIconSize(QSize(48, 48)); // 设置图标尺寸为 48x48
layout->addWidget(button2);

DIconButton *button3 = new DIconButton(QStyle::SP_ComputerIcon);
button3->setIconSize(QSize(64, 64)); // 设置图标尺寸为 64x64
layout->addWidget(button3);

window.setCentralWidget(centralWidget);
window.show();

return app.exec();
}
```
### demo运行图片
@image html DIconButton_example.png

@fn DIconButton::DIconButton(QWidget *parent)
@brief 实现一个方便定义图标的button
@param[in] parent

@fn void DIconButton::setIcon(const QIcon &icon)
@brief 设置button的图标
@param[in] icon button的图标

@fn void DIconButton::setIcon(QStyle::StandardPixmap iconType)
@brief 设置button图标的类型,传入QT预定义枚举值
@param[in] iconType icon类型

@fn void DIconButton::setIcon(DStyle::StandardPixmap iconType)
@brief 设置button图标的类型,传入DTK预定义枚举值
@param[in] iconType icon类型

@fn QSize DIconButton::iconSize() const
@brief icon的尺寸
@return 返回icon的尺寸

@fn bool DIconButton::isFlat() const
@brief button图标有无边框
@return true无边框 false有边框

@fn void DIconButton::setFlat(bool flat)
@brief 设置是否保留边框
@param[in] flat true无边框 false有边框

@fn void DIconButton::setNewNotification(const bool set_new)
@brief 设置是否显示小红点
@param[in] set_new true有红点 false无红点

*/

49 changes: 32 additions & 17 deletions src/widgets/diconbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ DIconButtonPrivate::DIconButtonPrivate(DIconButton *qq)
}

/*!
\brief DIconButton::DIconButton 实现一个方便定义图标的button
\a parent
@~english
@class Dtk::Widget::DIconButton
@brief the button icon
@details Customized button icons that can be adjusted according to the input icon parameters.
*/

/*!
@~english
@brief DIconButton::DIconButton implement a button easy to define icons
@param[in] parent
*/
DIconButton::DIconButton(QWidget *parent)
: DIconButton(*new DIconButtonPrivate(this), parent)
Expand Down Expand Up @@ -53,8 +61,9 @@ DIconButton::~DIconButton()
}

/*!
\brief DIconButton::setIcon 设置button的图标
\a icon button的图标
@~english
@brief DIconButton::setIcon set the button icon
@param[in] icon the button icon
*/
void DIconButton::setIcon(const QIcon &icon)
{
Expand All @@ -65,8 +74,9 @@ void DIconButton::setIcon(const QIcon &icon)
}

/*!
\brief DIconButton::setIcon 设置button图标的类型,传入QT预定义枚举值
\a iconType icon类型
@~english
@brief DIconButton::setIcon Set the type of the Button icon and pass the predefined enumeration value of QT.
@param[in] iconType type of icon
*/
void DIconButton::setIcon(QStyle::StandardPixmap iconType)
{
Expand All @@ -77,8 +87,9 @@ void DIconButton::setIcon(QStyle::StandardPixmap iconType)
}

/*!
\brief DIconButton::setIcon 设置button图标的类型,传入DTK预定义枚举值
\a iconType icon类型
@~english
@brief DIconButton::setIcon Set the type of the Button icon and pass the predefined enumeration value of DTK.
@param[in] iconType type of icon
*/
void DIconButton::setIcon(DStyle::StandardPixmap iconType)
{
Expand Down Expand Up @@ -131,8 +142,9 @@ QSize DIconButton::minimumSizeHint() const
}

/*!
\brief DIconButton::iconSize
\return 返回ICON的尺寸
@~english
@brief DIconButton::iconSize
@return size of icon
*/
QSize DIconButton::iconSize() const
{
Expand All @@ -153,8 +165,9 @@ QSize DIconButton::iconSize() const
}

/*!
\brief DIconButton::isFlat
\return true无边框 false有边框
@~english
@brief DIconButton::isFlat
@return "true":no frame "false":frame
*/
bool DIconButton::isFlat() const
{
Expand Down Expand Up @@ -182,8 +195,9 @@ bool DIconButton::enabledCircle() const
}

/*!
\brief DIconButton::setFlat 设置是否保留边框
\a flat true无边框 false有边框
@~english
@brief DIconButton::setFlat set whether to keep the frame
@param[in] flat "true":no frame "false":frame
*/
void DIconButton::setFlat(bool flat)
{
Expand Down Expand Up @@ -270,8 +284,9 @@ void DIconButton::keyPressEvent(QKeyEvent *event)
}

/*!
\brief DIconButton::setNewNotification 设置是否显示小红点
\a set_new true有红点 false无红点
@~english
@brief DIconButton::setNewNotification set whether to show small red dots
@param[in] set_new "true":small red dots "false":no small red dots
*/
void DIconButton::setNewNotification(const bool set_new)
{
Expand Down Expand Up @@ -302,7 +317,7 @@ bool DIconButton::event(QEvent *e)
}
}
} else if (e->type() == QEvent::ShowToParent) {
// 默认调整大小,否则可能会导致按钮显示后为 QWidget 的默认大小
// Resize by default, otherwise it may cause the button to display at the default size of QWidget.
resize(sizeHint());
}

Expand Down

0 comments on commit 86309b6

Please sign in to comment.