1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
|
// SPDX-FileCopyrightText: 2020 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMenu>
#include <QScrollArea>
#include <QDebug>
#include <DDialog>
#include <DStyle>
#include <DPushButton>
#include <DMessageBox>
#include <DWarningButton>
#include <DSuggestButton>
#include <DFrame>
#include <DToolButton>
#include <DToolBar>
#include <DIconButton>
#include <DButtonBox>
#include <DFloatingButton>
#include <DSwitchButton>
#include <DRadioButton>
#include <DCheckBox>
#include <DComboBox>
#include <DFontComboBox>
#include <DListView>
#include <DSearchComboBox>
#include <DSizeMode>
#include "buttonexample.h"
DWIDGET_USE_NAMESPACE
ButtonExampleWindow::ButtonExampleWindow(QWidget *parent)
: PageWindowInterface(parent)
{
addExampleWindow(new DPushButtonExample(this));
addExampleWindow(new DWarningButtonExample(this));
addExampleWindow(new DSuggestButtonExample(this));
addExampleWindow(new DToolButtonExample(this));
addExampleWindow(new DIconButtonExample(this));
addExampleWindow(new DButtonBoxExample(this));
addExampleWindow(new DFloatingButtonExample(this));
addExampleWindow(new DSwitchButtonExample(this));
addExampleWindow(new DRadioButtonExample(this));
addExampleWindow(new DCheckButtonExample(this));
addExampleWindow(new DComboBoxExample(this));
addExampleWindow(new DFontComboBoxExample(this));
addExampleWindow(new DSearchComboBoxExample(this));
}
DPushButtonExample::DPushButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QHBoxLayout *pHBoxLayout_1 = new QHBoxLayout;
QHBoxLayout *pHBoxLayout_2 = new QHBoxLayout;
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
setLayout(pVBoxLayout);
pVBoxLayout->addStretch();
pVBoxLayout->addLayout(pHBoxLayout_1);
pVBoxLayout->addSpacing(20);
pVBoxLayout->addLayout(pHBoxLayout_2);
pVBoxLayout->addStretch();
DPushButton *pButtonNormal = new DPushButton("button normal", this);
pButtonNormal->setFixedWidth(200);
DPushButton *pButtonDisabled = new DPushButton("button disabled", this);
pButtonDisabled->setFixedSize(DSizeModeHelper::element(QSize(200, 24), QSize(200, 36)));
// connect `sizeModeChanged()` signal to update Size.
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, [pButtonDisabled](DGuiApplicationHelper::SizeMode mode) {
pButtonDisabled->setFixedSize(DSizeModeHelper::element(QSize(200, 24), QSize(200, 36)));
});
pButtonDisabled->setEnabled(false);
pHBoxLayout_1->addStretch();
pHBoxLayout_1->addWidget(pButtonNormal);
pHBoxLayout_1->addSpacing(20);
pHBoxLayout_1->addWidget(pButtonDisabled);
pHBoxLayout_1->addStretch();
DPushButton *pPushButton = new DPushButton("push button", this);
pPushButton->setFixedWidth(200);
pPushButton->setCheckable(true);
QMenu *pMenu = new QMenu(this);
pMenu->addAction("item_1");
pMenu->addAction("item_2");
pMenu->addAction("item_3");
pPushButton->setMenu(pMenu);
DPushButton *pPushButtonDisabled = new DPushButton("push button", this);
pPushButtonDisabled->setFixedWidth(200);
pPushButtonDisabled->setEnabled(false);
pPushButtonDisabled->setMenu(pMenu);
pHBoxLayout_2->addStretch();
pHBoxLayout_2->addWidget(pPushButton);
pHBoxLayout_2->addSpacing(20);
pHBoxLayout_2->addWidget(pPushButtonDisabled);
pHBoxLayout_2->addStretch();
connect(pButtonNormal, &DPushButton::clicked, this, [] {
DDialog dialog("", "名称push button已经被占用,请使用其他名称", nullptr);
dialog.setIcon(DStyle().standardIcon(DStyle::SP_MessageBoxWarning));
dialog.addButton("确定");
dialog.exec();
});
}
QString DPushButtonExample::getTitleName() const
{
return "DPushButton";
}
QString DPushButtonExample::getDescriptionInfo() const
{
return "普通的文字按钮和带菜单的文字按钮\n"
"按钮的文字随着菜单的选择而改变";
}
int DPushButtonExample::getFixedHeight() const
{
return 402;
}
DWarningButtonExample::DWarningButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QHBoxLayout *pHBoxLayout_1 = new QHBoxLayout;
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
setLayout(pVBoxLayout);
pVBoxLayout->addSpacing(40);
pVBoxLayout->addLayout(pHBoxLayout_1);
pVBoxLayout->addStretch();
DWarningButton *pWarningButton = new DWarningButton(this);
pWarningButton->setText("warning");
pWarningButton->setFixedWidth(200);
DWarningButton *pWarningButtonDisabled = new DWarningButton(this);
pWarningButtonDisabled->setText("warning disabled");
pWarningButtonDisabled->setEnabled(false);
pWarningButtonDisabled->setFixedWidth(200);
pHBoxLayout_1->addStretch();
pHBoxLayout_1->addWidget(pWarningButton);
pHBoxLayout_1->addSpacing(20);
pHBoxLayout_1->addWidget(pWarningButtonDisabled);
pHBoxLayout_1->addStretch();
connect(pWarningButton, &DWarningButton::clicked, this, [] {
DDialog dialog("", "格式化操作会清空该磁盘数据,您需要继续吗?\n此操作不可以恢复", nullptr);
dialog.setIcon(DStyle().standardIcon(DStyle::SP_DriveNetIcon));
dialog.addButton("取消");
dialog.addButton("格式化");
dialog.exec();
});
}
QString DWarningButtonExample::getTitleName() const
{
return "DWarningButton";
}
QString DWarningButtonExample::getDescriptionInfo() const
{
return "功能和普通的文字按钮一致,不过用在\n"
"警告语上,告诉用户有危险操作.";
}
int DWarningButtonExample::getFixedHeight() const
{
return 368;
}
DSuggestButtonExample::DSuggestButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QHBoxLayout *pHBoxLayout_1 = new QHBoxLayout;
QHBoxLayout *pHBoxLayout_2 = new QHBoxLayout;
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
setLayout(pVBoxLayout);
pVBoxLayout->addStretch();
pVBoxLayout->addLayout(pHBoxLayout_1);
pVBoxLayout->addSpacing(20);
pVBoxLayout->addLayout(pHBoxLayout_2);
pVBoxLayout->addStretch();
DSuggestButton *pRecommend = new DSuggestButton("recommend", this);
pRecommend->setFixedWidth(200);
DPushButton *pRecommendDisabled = new DPushButton("recommend disabled", this);
pRecommendDisabled->setFixedWidth(200);
pRecommendDisabled->setEnabled(false);
pHBoxLayout_1->addStretch();
pHBoxLayout_1->addWidget(pRecommend);
pHBoxLayout_1->addSpacing(20);
pHBoxLayout_1->addWidget(pRecommendDisabled);
pHBoxLayout_1->addStretch();
DSuggestButton *pHighlight = new DSuggestButton("highlight", this);
pHighlight->setFixedWidth(200);
pHighlight->setCheckable(true);
pHighlight->setFocus();
DPushButton *pHighlightDisabled = new DPushButton("highlight disabled", this);
pHighlightDisabled->setFixedWidth(200);
pHighlightDisabled->setEnabled(false);
pHBoxLayout_2->addStretch();
pHBoxLayout_2->addWidget(pHighlight);
pHBoxLayout_2->addSpacing(20);
pHBoxLayout_2->addWidget(pHighlightDisabled);
pHBoxLayout_2->addStretch();
connect(pRecommend, &DPushButton::clicked, this, [] {
DDialog dialog("", "这里现实简要出错信息XXXXXXXX", nullptr);
dialog.setIcon(DStyle().standardIcon(DStyle::SP_MessageBoxWarning));
dialog.addButton("显示详情");
dialog.addButton("确定");
dialog.exec();
});
}
QString DSuggestButtonExample::getTitleName() const
{
return "DSuggestButton";
}
QString DSuggestButtonExample::getDescriptionInfo() const
{
return "往往不会单独出现,绝大多数情况都是\n"
"和DPushButton一起出现,显示在\n"
"DPushButton的右边,主要是起引导用\n"
"户点击的作用.";
}
int DSuggestButtonExample::getFixedHeight() const
{
return 300;
}
DToolButtonExample::DToolButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout = new QHBoxLayout;
pHBoxLayout->setContentsMargins(20, 20, 20, 20);
pHBoxLayout->setSpacing(0);
auto showDialog = [](const QString &info) {
DDialog dialog("", info, nullptr);
dialog.setIcon(DStyle().standardIcon(DStyle::SP_MessageBoxInformation));
dialog.addButton("确定");
dialog.exec();
};
DToolBar *pToolBar = new DToolBar;
pToolBar->addAction(QIcon::fromTheme("icon_button"), "", this, [showDialog] {
showDialog("这是icon_button的图标");
});
pToolBar->addAction(QIcon::fromTheme("icon_edit"), "", this, [showDialog] {
showDialog("这是icon_edit的图标");
});
pToolBar->addAction(QIcon::fromTheme("icon_slider"), "", this, [showDialog] {
showDialog("这是icon_slider的图标");
});
pToolBar->addAction(QIcon::fromTheme("icon_ListView"), "", this, [showDialog] {
showDialog("这是icon_ListView的图标");
});
pToolBar->addAction(QIcon::fromTheme("icon_Window"), "", this, [showDialog] {
showDialog("这是icon_Window的图标");
});
pToolBar->addAction(QIcon::fromTheme("icon_Tooltip"), "", this, [showDialog] {
showDialog("这是icon_Tooltip的图标");
});
pToolBar->addAction(QIcon::fromTheme("icon_Dialog"), "", this, [] {
DDialog dialog("各种类型的ToolButton", "", nullptr);
dialog.setIcon(DStyle().standardIcon(DStyle::SP_MessageBoxInformation));
auto toolBar = new DToolBar;
toolBar->addAction(QIcon::fromTheme("icon_button"), "");
toolBar->addAction("文字");
toolBar->addAction("长文字123456");
{
auto action = toolBar->addAction("含菜单");
auto menu = new QMenu();
menu->addAction("Menu1");
action->setMenu(menu);
}
{
auto action = toolBar->addAction(QIcon::fromTheme("icon_button"), "");
auto menu = new QMenu();
menu->addAction("Menu1");
action->setMenu(menu);
}
{
auto action = toolBar->addAction(QIcon::fromTheme("icon_button"), "图标和文字");
if (auto widget = qobject_cast<QToolButton *>(toolBar->widgetForAction(action)))
widget->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
}
dialog.addContent(toolBar);
dialog.exec();
});
pHBoxLayout->addWidget(pToolBar);
pVBoxLayout->addSpacing(20);
pVBoxLayout->addLayout(pHBoxLayout);
pHBoxLayout->addSpacing(30);
QLabel *pLabel = new QLabel;
QPixmap pix(":/images/example/DToolButton.png");
pLabel->setFixedSize(570, 348);
pLabel->setPixmap(pix);
pLabel->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic = new QHBoxLayout;
pHBoxLayout_pic->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic->setSpacing(0);
pHBoxLayout_pic->addWidget(pLabel);
pVBoxLayout->addLayout(pHBoxLayout_pic);
}
QString DToolButtonExample::getTitleName() const
{
return "DToolButton";
}
QString DToolButtonExample::getDescriptionInfo() const
{
return "主要用在工具栏上作为应用的功能按\n"
"钮,比如画板左侧的工具栏图标.";
}
int DToolButtonExample::getFixedHeight() const
{
return 600;
}
DIconButtonExample::DIconButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout = new QHBoxLayout;
pHBoxLayout->setContentsMargins(10, 10, 10, 10);
pHBoxLayout->setSpacing(0);
DIconButton *pButton_1 = new DIconButton(DStyle::SP_IncreaseElement, this);
pButton_1->setNewNotification(true);
DIconButton *pButton_2 = new DIconButton(DStyle::SP_ArrowEnter, this);
DIconButton *pButton_3 = new DIconButton(DStyle::SP_IncreaseElement, this);
pButton_3->setEnabled(false);
DIconButton *pButton_4 = new DIconButton(DStyle::SP_ArrowEnter, this);
pButton_4->setEnabled(false);
DIconButton *pButton_5 = new DIconButton(DStyle::SP_DeleteButton, this);
pButton_5->setFlat(true);
pButton_5->setIconSize(QSize(16, 16));
DStyle::setFocusRectVisible(pButton_5, false);
DIconButton *pButton_6 = new DIconButton(DStyle::SP_AddButton, this);
pButton_6->setFlat(true);
pButton_6->setIconSize(QSize(16, 16));
DStyle::setFocusRectVisible(pButton_6, false);
DIconButton *pButton_7 = new DIconButton(DStyle::SP_DeleteButton, this);
pButton_7->setEnabled(false);
pButton_7->setFlat(true);
pButton_7->setIconSize(QSize(16, 16));
DStyle::setFocusRectVisible(pButton_7, false);
DIconButton *pButton_8 = new DIconButton(DStyle::SP_AddButton, this);
pButton_8->setEnabled(false);
pButton_8->setFlat(true);
pButton_8->setIconSize(QSize(16, 16));
DStyle::setFocusRectVisible(pButton_8, false);
auto updateButtonSize = [](QWidget *widget, int mode) {
for (auto button : widget->findChildren<DIconButton *>(QString(), Qt::FindDirectChildrenOnly)) {
if (button->iconSize() == QSize(16, 16)) {
button->setFixedSize(DSizeModeHelper::element(QSize(20, 20), QSize(24, 24)));
} else {
button->setFixedSize(DSizeModeHelper::element(QSize(24, 24), QSize(36, 36)));
}
}
};
updateButtonSize(this, DGuiApplicationHelper::instance()->sizeMode());
// connect `sizeModeChanged` signal for a control Widget to update size.
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::sizeModeChanged, this, [updateButtonSize, this](int mode) {
updateButtonSize(this, mode);
});
pHBoxLayout->addStretch();
pHBoxLayout->addWidget(pButton_1);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pButton_2);
pHBoxLayout->addSpacing(50);
pHBoxLayout->addWidget(pButton_3);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pButton_4);
pHBoxLayout->addSpacing(100);
pHBoxLayout->addWidget(pButton_5);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pButton_6);
pHBoxLayout->addSpacing(50);
pHBoxLayout->addWidget(pButton_7);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pButton_8);
pHBoxLayout->addStretch();
pVBoxLayout->addSpacing(20);
pVBoxLayout->addLayout(pHBoxLayout);
pHBoxLayout->addSpacing(20);
QLabel *pLabel = new QLabel;
QPixmap pix(":/images/example/DIconButton.png");
pLabel->setFixedSize(568, 444);
pLabel->setPixmap(pix);
pLabel->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic = new QHBoxLayout;
pHBoxLayout_pic->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic->setSpacing(0);
pHBoxLayout_pic->addWidget(pLabel);
pVBoxLayout->addLayout(pHBoxLayout_pic);
}
QString DIconButtonExample::getTitleName() const
{
return "DIconButton";
}
QString DIconButtonExample::getDescriptionInfo() const
{
return "性质和DPushButton一致,只不过是用\n"
"图形化代替文字,最常见的有新建,上\n"
"一个下一个等.";
}
int DIconButtonExample::getFixedHeight() const
{
return 600;
}
DButtonBoxExample::DButtonBoxExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout = new QHBoxLayout;
pHBoxLayout->setContentsMargins(0, 0, 0, 0);
pHBoxLayout->setSpacing(0);
DButtonBox *pButtonBox_1 = new DButtonBox;
DButtonBoxButton *pButton_1 = new DButtonBoxButton(DStyle().standardIcon(DStyle::SP_ArrowLeave));
DButtonBoxButton *pButton_2 = new DButtonBoxButton(DStyle().standardIcon(DStyle::SP_ArrowEnter));
pButtonBox_1->setButtonList(QList<DButtonBoxButton *>() << pButton_1 << pButton_2, true);
DButtonBox *pButtonBox_2 = new DButtonBox;
DButtonBoxButton *pButton_3 = new DButtonBoxButton(DStyle().standardIcon(DStyle::SP_ArrowLeave));
pButton_3->setEnabled(false);
DButtonBoxButton *pButton_4 = new DButtonBoxButton(DStyle().standardIcon(DStyle::SP_ArrowEnter));
pButton_4->setEnabled(false);
pButtonBox_2->setButtonList(QList<DButtonBoxButton *>() << pButton_3 << pButton_4, true);
DButtonBox *pButtonBox_3 = new DButtonBox;
DButtonBoxButton *pButton_5 = new DButtonBoxButton(DStyle().standardIcon(DStyle::SP_LockElement), "锁定设置");
pButton_3->setEnabled(false);
DButtonBoxButton *pButton_6 = new DButtonBoxButton(DStyle().standardIcon(DStyle::SP_UnlockElement), "解锁设置");
pButton_4->setEnabled(false);
pButtonBox_3->setButtonList(QList<DButtonBoxButton *>() << pButton_5 << pButton_6, true);
pHBoxLayout->addStretch();
pHBoxLayout->addWidget(pButtonBox_1);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pButtonBox_2);
pHBoxLayout->addSpacing(50);
pHBoxLayout->addWidget(pButtonBox_3);
pHBoxLayout->addStretch();
pVBoxLayout->addSpacing(20);
pVBoxLayout->addLayout(pHBoxLayout);
pHBoxLayout->addSpacing(20);
QLabel *pLabel = new QLabel;
QPixmap pix(":/images/example/DButtonBox.png");
pLabel->setFixedSize(570, 426);
pLabel->setPixmap(pix);
pLabel->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic = new QHBoxLayout;
pHBoxLayout_pic->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic->setSpacing(0);
pHBoxLayout_pic->addWidget(pLabel);
pVBoxLayout->addLayout(pHBoxLayout_pic);
updateButtonsSize();
}
QString DButtonBoxExample::getTitleName() const
{
return "DButtonBox";
}
QString DButtonBoxExample::getDescriptionInfo() const
{
return "群组按钮,几个连体按钮选项是为了一\n"
"个共同的功能服务,比如日历的切换视\n"
"图,还有常见的文字选项如加粗下划线\n"
"中横线等.";
}
int DButtonBoxExample::getFixedHeight() const
{
return 600;
}
void DButtonBoxExample::changeEvent(QEvent *event)
{
// override `event()` to update Size.
if (event->type() == QEvent::StyleChange) {
updateButtonsSize();
}
return ExampleWindowInterface::changeEvent(event);
}
void DButtonBoxExample::updateButtonsSize()
{
for (auto button : findChildren<DButtonBoxButton *>()) {
if (button->text().isEmpty()) {
button->setFixedSize(DSizeModeHelper::element(QSize(24, 24), QSize(36, 36)));
} else {
button->setFixedHeight(DSizeModeHelper::element(24, 36));
}
}
}
DFloatingButtonExample::DFloatingButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout = new QHBoxLayout;
pHBoxLayout->setContentsMargins(10, 10, 10, 10);
pHBoxLayout->setSpacing(0);
DFloatingButton *pFloatingButton_1 = new DFloatingButton(DStyle::SP_IncreaseElement, this);
DFloatingButton *pFloatingButton_2 = new DFloatingButton(DStyle::SP_IncreaseElement, this);
pFloatingButton_2->setEnabled(false);
pHBoxLayout->addStretch();
pHBoxLayout->addWidget(pFloatingButton_1);
pHBoxLayout->addSpacing(50);
pHBoxLayout->addWidget(pFloatingButton_2);
pHBoxLayout->addStretch();
pVBoxLayout->addSpacing(20);
pVBoxLayout->addLayout(pHBoxLayout);
QLabel *pLabel = new QLabel;
QPixmap pix(":/images/example/DFloatingButton.png");
pLabel->setFixedSize(568, 444);
pLabel->setPixmap(pix);
pLabel->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic = new QHBoxLayout;
pHBoxLayout_pic->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic->setSpacing(0);
pHBoxLayout_pic->addWidget(pLabel);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_pic);
pVBoxLayout->addSpacing(20);
}
QString DFloatingButtonExample::getTitleName() const
{
return "DFloatingButton";
}
QString DFloatingButtonExample::getDescriptionInfo() const
{
return "在一个场景中作为一个主要功能使用,\n"
"比如控制中心账户列表中作为添加账户\n"
"使用.这个按钮是悬浮的,不占据底下\n"
"内容的空间.";
}
int DFloatingButtonExample::getFixedHeight() const
{
return 600;
}
DSwitchButtonExample::DSwitchButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout = new QHBoxLayout;
pHBoxLayout->setContentsMargins(0, 0, 0, 0);
pHBoxLayout->setSpacing(0);
DSwitchButton *pSwitchButton_1 = new DSwitchButton;
DSwitchButton *pSwitchButton_2 = new DSwitchButton;
pSwitchButton_2->setEnabled(false);
pHBoxLayout->addStretch();
pHBoxLayout->addWidget(pSwitchButton_1);
pHBoxLayout->addSpacing(30);
pHBoxLayout->addWidget(pSwitchButton_2);
pHBoxLayout->addStretch();
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout);
QLabel *pLabel = new QLabel;
QPixmap pix(":/images/example/DSwitchButton.png");
pLabel->setFixedSize(568, 444);
pLabel->setPixmap(pix);
pLabel->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic = new QHBoxLayout;
pHBoxLayout_pic->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic->setSpacing(0);
pHBoxLayout_pic->addWidget(pLabel);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_pic);
pVBoxLayout->addSpacing(20);
}
QString DSwitchButtonExample::getTitleName() const
{
return "DSwitchButton";
}
QString DSwitchButtonExample::getDescriptionInfo() const
{
return "普通的开关控件,等价控件为\n"
"DCheckButton";
}
int DSwitchButtonExample::getFixedHeight() const
{
return 600;
}
DRadioButtonExample::DRadioButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout = new QHBoxLayout;
pHBoxLayout->setContentsMargins(0, 0, 0, 0);
pHBoxLayout->setSpacing(0);
DRadioButton *pRadioButton_1 = new DRadioButton;
//也可以不设置,默认是设置为互斥的
pRadioButton_1->setAutoExclusive(true);
DRadioButton *pRadioButton_2 = new DRadioButton;
pRadioButton_2->setAutoExclusive(true);
pHBoxLayout->addStretch();
pHBoxLayout->addWidget(pRadioButton_1);
pHBoxLayout->addSpacing(30);
pHBoxLayout->addWidget(pRadioButton_2);
pHBoxLayout->addStretch();
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout);
QLabel *pLabel = new QLabel;
QPixmap pix(":/images/example/DRadioButton.png");
pLabel->setFixedSize(568, 444);
pLabel->setPixmap(pix);
pLabel->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic = new QHBoxLayout;
pHBoxLayout_pic->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic->setSpacing(0);
pHBoxLayout_pic->addWidget(pLabel);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_pic);
pVBoxLayout->addSpacing(20);
}
QString DRadioButtonExample::getTitleName() const
{
return "DRadioButton";
}
QString DRadioButtonExample::getDescriptionInfo() const
{
return "常见于设置或者对话框中作为一个选项\n"
"存在,至少提供2个或者多个选项,选\n"
"项之间是互斥的.";
}
int DRadioButtonExample::getFixedHeight() const
{
return 600;
}
DCheckButtonExample::DCheckButtonExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout = new QHBoxLayout;
pHBoxLayout->setContentsMargins(0, 0, 0, 0);
pHBoxLayout->setSpacing(0);
DCheckBox *pCheckBox_1 = new DCheckBox("");
pCheckBox_1->setTristate(true);
pCheckBox_1->setCheckState(Qt::PartiallyChecked);
DCheckBox *pCheckBox_2 = new DCheckBox("");
DCheckBox *pCheckBox_3 = new DCheckBox("");
pCheckBox_3->setTristate(true);
pCheckBox_3->setCheckState(Qt::Unchecked);
pCheckBox_3->setEnabled(false);
DCheckBox *pCheckBox_4 = new DCheckBox("");
pCheckBox_4->setTristate(true);
pCheckBox_4->setCheckState(Qt::Checked);
pCheckBox_4->setEnabled(false);
DCheckBox *pCheckBox_5 = new DCheckBox("");
pCheckBox_5->setTristate(true);
pCheckBox_5->setCheckState(Qt::PartiallyChecked);
pCheckBox_5->setEnabled(false);
pHBoxLayout->addStretch();
pHBoxLayout->addWidget(pCheckBox_1);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pCheckBox_2);
pHBoxLayout->addSpacing(50);
pHBoxLayout->addWidget(pCheckBox_3);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pCheckBox_4);
pHBoxLayout->addSpacing(10);
pHBoxLayout->addWidget(pCheckBox_5);
pHBoxLayout->addStretch();
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout);
QLabel *pLabel = new QLabel;
QPixmap pix(":/images/example/DCheckButton.png");
pLabel->setFixedSize(568, 444);
pLabel->setPixmap(pix);
pLabel->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic = new QHBoxLayout;
pHBoxLayout_pic->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic->setSpacing(0);
pHBoxLayout_pic->addWidget(pLabel);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_pic);
pVBoxLayout->addSpacing(20);
}
QString DCheckButtonExample::getTitleName() const
{
return "DCheckButton";
}
QString DCheckButtonExample::getDescriptionInfo() const
{
return "和DRadioButton一致,也常用于设\n"
"置和对话框的选项,但每个选项之间是\n"
"独立的,不会产生冲突.每个选项的等\n"
"价控件是DSwitchButton.";
}
int DCheckButtonExample::getFixedHeight() const
{
return 600;
}
DComboBoxExample::DComboBoxExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout_1 = new QHBoxLayout;
pHBoxLayout_1->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_1->setSpacing(0);
DComboBox *pComboBox_1 = new DComboBox;
pComboBox_1->setFixedWidth(240);
for (int i = 0; i < 30; i++) {
pComboBox_1->addItem(QString("ComboBox button - %1").arg(i));
}
pHBoxLayout_1->addWidget(pComboBox_1);
QComboBox *pComboBox_1_count = new QComboBox();
pComboBox_1_count->setFixedWidth(100);
pComboBox_1_count->addItem(QString::number(10));
pComboBox_1_count->addItem(QString::number(20));
pComboBox_1_count->addItem(QString::number(30));
pComboBox_1_count->setCurrentIndex(pComboBox_1_count->count() - 1);
connect(pComboBox_1_count, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [pComboBox_1, pComboBox_1_count](int index){
pComboBox_1->clear();
for (int i = 0; i < pComboBox_1_count->itemText(index).toInt(); i++) {
pComboBox_1->addItem(QString("ComboBox button - %1").arg(i));
}
});
pHBoxLayout_1->addWidget(pComboBox_1_count);
QHBoxLayout *pHBoxLayout_2 = new QHBoxLayout;
pHBoxLayout_2->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_2->setSpacing(0);
DComboBox *pComboBox_2 = new DComboBox;
pComboBox_2->setFixedWidth(340);
pComboBox_2->addItem("/space");
pHBoxLayout_2->addWidget(pComboBox_2);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_1);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_2);
QLabel *pLabel_1 = new QLabel;
QPixmap pix_1(":/images/example/DComboBox_1.png");
pLabel_1->setFixedSize(568, 444);
pLabel_1->setPixmap(pix_1);
pLabel_1->setScaledContents(true);
QLabel *pLabel_2 = new QLabel;
QPixmap pix_2(":/images/example/DComboBox_2.png");
pLabel_2->setFixedSize(568, 444);
pLabel_2->setPixmap(pix_2);
pLabel_2->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic_1 = new QHBoxLayout;
pHBoxLayout_pic_1->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic_1->setSpacing(0);
pHBoxLayout_pic_1->addWidget(pLabel_1);
QHBoxLayout *pHBoxLayout_pic_2 = new QHBoxLayout;
pHBoxLayout_pic_2->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic_2->setSpacing(0);
pHBoxLayout_pic_2->addWidget(pLabel_2);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_pic_1);
pVBoxLayout->addSpacing(20);
pVBoxLayout->addLayout(pHBoxLayout_pic_2);
pVBoxLayout->addSpacing(20);
}
QString DComboBoxExample::getTitleName() const
{
return "DComboBox";
}
QString DComboBoxExample::getDescriptionInfo() const
{
return "作为一个选项存在,多数时候前面有标\n"
"题,但也有没有标题的情况.点击是出\n"
"现一个菜单,点击选项某一项菜单后菜\n"
"单收起,选项框上的文字显示菜单里激\n"
"活的那一项.";
}
int DComboBoxExample::getFixedHeight() const
{
return 1200;
}
DFontComboBoxExample::DFontComboBoxExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout_1 = new QHBoxLayout;
pHBoxLayout_1->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_1->setSpacing(0);
DFontComboBox *pComboBox_1 = new DFontComboBox;
pComboBox_1->setFixedWidth(240);
connect(pComboBox_1, &DFontComboBox::currentFontChanged, [](const QFont &f){
qDebug() << "selected font:" << f;
});
pHBoxLayout_1->addWidget(pComboBox_1);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_1);
pVBoxLayout->addSpacing(30);
QLabel *pLabel_1 = new QLabel;
QPixmap pix_1(":/images/example/DFontComboBox.png");
pLabel_1->setFixedSize(568, 444);
pLabel_1->setPixmap(pix_1);
pLabel_1->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic_1 = new QHBoxLayout;
pHBoxLayout_pic_1->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic_1->setSpacing(0);
pHBoxLayout_pic_1->addWidget(pLabel_1);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_pic_1);
pVBoxLayout->addSpacing(20);
}
QString DFontComboBoxExample::getTitleName() const
{
return "DFontComboBox";
}
QString DFontComboBoxExample::getDescriptionInfo() const
{
return "和DComboBox其实是一个控件,但这\n"
"里仅用于字体的选择.";
}
int DFontComboBoxExample::getFixedHeight() const
{
return 700;
}
DSearchComboBoxExample::DSearchComboBoxExample(QWidget *parent)
: ExampleWindowInterface(parent)
{
QVBoxLayout *pVBoxLayout = new QVBoxLayout;
pVBoxLayout->setContentsMargins(0, 0, 0, 0);
pVBoxLayout->setSpacing(0);
setLayout(pVBoxLayout);
QHBoxLayout *pHBoxLayout_1 = new QHBoxLayout;
pHBoxLayout_1->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_1->setSpacing(0);
DSearchComboBox *pComboBox_1 = new DSearchComboBox(this);
pComboBox_1->setEditable(false);
for (int i = 0; i < 16; ++i) {
pComboBox_1->addItem(QString("手动选择驱动方案%1").arg(i + 1));
}
pComboBox_1->setFixedWidth(240);
pHBoxLayout_1->addWidget(pComboBox_1);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_1);
pVBoxLayout->addSpacing(30);
QLabel *pLabel_1 = new QLabel;
QPixmap pix_1(":/images/example/DSearchComboBox.png");
pLabel_1->setFixedSize(568, 444);
pLabel_1->setPixmap(pix_1);
pLabel_1->setScaledContents(true);
QHBoxLayout *pHBoxLayout_pic_1 = new QHBoxLayout;
pHBoxLayout_pic_1->setContentsMargins(0, 0, 0, 0);
pHBoxLayout_pic_1->setSpacing(0);
pHBoxLayout_pic_1->addWidget(pLabel_1);
pVBoxLayout->addSpacing(30);
pVBoxLayout->addLayout(pHBoxLayout_pic_1);
pVBoxLayout->addSpacing(20);
}
QString DSearchComboBoxExample::getTitleName() const
{
return "DSearchComboBox";
}
QString DSearchComboBoxExample::getDescriptionInfo() const
{
return "一个带搜索功能的ComboBox控件.";
}
int DSearchComboBoxExample::getFixedHeight() const
{
return 700;
}
|