diff options
author | Tomas Junnonen <tomas.junnonen@nokia.com> | 2010-06-17 12:30:13 +0300 |
---|---|---|
committer | Tomas Junnonen <tomas.junnonen@nokia.com> | 2010-06-17 12:30:47 +0300 |
commit | 25695240c2e6c10dc23ee4d8447bbd6ff8d488b2 (patch) | |
tree | f98ad744231b33dba4875408c3e108deca89ceff /demos | |
parent | f8816dce00d983a92f8a31b7f84635cf358555a1 (diff) |
Changes: Improved the documentation of the button group page, added an exclusive group
RevBy: TrustMe
Diffstat (limited to 'demos')
-rw-r--r-- | demos/widgetsgallery/buttongrouppage.cpp | 139 | ||||
-rw-r--r-- | demos/widgetsgallery/buttongrouppage.h | 10 |
2 files changed, 104 insertions, 45 deletions
diff --git a/demos/widgetsgallery/buttongrouppage.cpp b/demos/widgetsgallery/buttongrouppage.cpp index 352a0047..19edc46b 100644 --- a/demos/widgetsgallery/buttongrouppage.cpp +++ b/demos/widgetsgallery/buttongrouppage.cpp @@ -28,6 +28,7 @@ #include <MButtonGroup> #include <MDebug> #include <MApplication> +#include <MButtonGroup> ButtonGroupPage::ButtonGroupPage() : TemplatePage(TemplatePage::Buttons), @@ -37,8 +38,10 @@ ButtonGroupPage::ButtonGroupPage() : pushButton4(NULL), pushButton5(NULL), pushButton6(NULL), - hLabel(NULL), + hLabel1(NULL), + hLabel2(NULL), vLabel(NULL) + { } @@ -55,53 +58,89 @@ void ButtonGroupPage::createContent() { TemplatePage::createContent(); - //init horizontal button group - MLayout* hLayout = new MLayout; - MLinearLayoutPolicy* hPolicy = new MLinearLayoutPolicy(hLayout, Qt::Horizontal); - hPolicy->setNotifyWidgetsOfLayoutPositionEnabled(true); - hPolicy->setObjectName("buttongroup"); + // Init horizontal button group, default style + MLayout* hLayout1 = new MLayout; + MLinearLayoutPolicy* hPolicy1 = new MLinearLayoutPolicy(hLayout1, Qt::Horizontal); + // The policy notifies the widgets of their relative position inside the layout, + // this causes the buttons to be rendered with different backgrounds for each position + hPolicy1->setNotifyWidgetsOfLayoutPositionEnabled(true); + pushButton1 = new MButton(); - pushButton1->setCheckable(true); + // The group type makes the button use the MButton[group] CSS block from the theme, + // this allows for gapless groups by modifying the margins. pushButton1->setViewType(MButton::groupType); pushButton2 = new MButton(); - pushButton2->setCheckable(true); pushButton2->setViewType(MButton::groupType); pushButton3 = new MButton(); - pushButton3->setCheckable(true); pushButton3->setViewType(MButton::groupType); - hPolicy->addItem(pushButton1); - hPolicy->addItem(pushButton2); - hPolicy->addItem(pushButton3); - - //init vertical button group - MLayout* vLayout = new MLayout; - MLinearLayoutPolicy* vPolicy = new MLinearLayoutPolicy(vLayout, Qt::Vertical); - vPolicy->setNotifyWidgetsOfLayoutPositionEnabled(true); - vPolicy->setObjectName("buttongroup"); + hPolicy1->addItem(pushButton1); + hPolicy1->addItem(pushButton2); + hPolicy1->addItem(pushButton3); + + // Init horizontal button group, exclusive + MLayout* hLayout2 = new MLayout; + MLinearLayoutPolicy* hPolicy2 = new MLinearLayoutPolicy(hLayout2, Qt::Horizontal); + hPolicy2->setNotifyWidgetsOfLayoutPositionEnabled(true); pushButton4 = new MButton(); pushButton4->setCheckable(true); pushButton4->setViewType(MButton::groupType); pushButton5 = new MButton(); pushButton5->setCheckable(true); + pushButton5->setChecked(true); // Let's make this our default pushButton5->setViewType(MButton::groupType); pushButton6 = new MButton(); pushButton6->setCheckable(true); pushButton6->setViewType(MButton::groupType); - vPolicy->addItem(pushButton4); - vPolicy->addItem(pushButton5); - vPolicy->addItem(pushButton6); + hPolicy2->addItem(pushButton4); + hPolicy2->addItem(pushButton5); + hPolicy2->addItem(pushButton6); + // The group enforces the logical exclusivity + MButtonGroup* group = new MButtonGroup(); + group->addButton(pushButton4); + group->addButton(pushButton5); + group->addButton(pushButton6); + + // Init vertical button group, checkable + MLayout* vLayout = new MLayout; + MLinearLayoutPolicy* vPolicy = new MLinearLayoutPolicy(vLayout, Qt::Vertical); + vPolicy->setNotifyWidgetsOfLayoutPositionEnabled(true); + vPolicy->setObjectName("buttongroup"); + pushButton7 = new MButton(); + pushButton7->setCheckable(true); + pushButton7->setViewType(MButton::groupType); + pushButton8 = new MButton(); + pushButton8->setCheckable(true); + pushButton8->setViewType(MButton::groupType); + pushButton9 = new MButton(); + pushButton9->setCheckable(true); + pushButton9->setViewType(MButton::groupType); + vPolicy->addItem(pushButton7); + vPolicy->addItem(pushButton8); + vPolicy->addItem(pushButton9); + + //add label and horizontal button group into page + hLabel1 = new MLabel(); + containerPolicy->addItem(hLabel1); + containerPolicy->addItem(hLayout1); + + //add small spacer between button groups + QGraphicsWidget* spacer1 = new QGraphicsWidget; + spacer1->setMinimumSize(0, 20); + spacer1->setPreferredSize(0, 20); + spacer1->setMaximumSize(0, 20); + containerPolicy->addItem(spacer1); //add label and horizontal button group into page - hLabel = new MLabel(); - containerPolicy->addItem(hLabel); - containerPolicy->addItem(hLayout); + hLabel2 = new MLabel(); + containerPolicy->addItem(hLabel2); + containerPolicy->addItem(hLayout2); - //add small spacer between horizontal and vertical button groups - QGraphicsWidget* spacer = new QGraphicsWidget; - spacer->setMinimumSize(0, 20); - spacer->setPreferredSize(0, 20); - spacer->setMaximumSize(0, 20); - containerPolicy->addItem(spacer); + //add small spacer between button groups + QGraphicsWidget* spacer2 = new QGraphicsWidget; + spacer2->setMinimumSize(0, 20); + spacer2->setPreferredSize(0, 20); + spacer2->setMaximumSize(0, 20); + containerPolicy->addItem(spacer2); //add label and vertical button group into page vLabel = new MLabel(); @@ -118,26 +157,40 @@ void ButtonGroupPage::retranslateUi() if (!isContentCreated()) return; - //% "Button group information label." + /*% "Buttons can be grouped together based on visual or logic requirements.\n\n" + "The basic group is formed by placing buttons together " + "into a layout. Depending on the theme, the buttons are typically " + "drawn as connected with each other.\n\n" + "Logical exclusivity can be added to a group, which ensures only one " + "of the buttons can be selected at a time. If a group is not exclusive, " + "multiple options from the group can be selected." + */ infoLabel->setText("<a></a>" + qtTrId("xx_button_group_page_info_label")); - //% "Horizontal button group:" - hLabel->setText(qtTrId("xx_button_group_page_hlabel")); - //% "Lorem" + //% "Horizontal group" + hLabel1->setText(qtTrId("xx_button_group_page_hlabel1")); + //% "Yes" pushButton1->setText(qtTrId("xx_button_group_page_button1")); - //% "Ipsum" + //% "No" pushButton2->setText(qtTrId("xx_button_group_page_button2")); - //% "Dolor" + //% "Maybe" pushButton3->setText(qtTrId("xx_button_group_page_button3")); - //% "Vertical button group:" - vLabel->setText(qtTrId("xx_button_group_page_vlabel")); - //% "Consectetur" + //% "Horizontal group, exclusive" + hLabel2->setText(qtTrId("xx_button_group_page_vlabel2")); + //% "Cost" pushButton4->setText(qtTrId("xx_button_group_page_button4")); - //% "Adipisicing" + //% "Quality" pushButton5->setText(qtTrId("xx_button_group_page_button5")); - //% "Elit" + //% "Schedule" pushButton6->setText(qtTrId("xx_button_group_page_button6")); -} - + //% "Vertical group, checkable" + vLabel->setText(qtTrId("xx_button_group_page_vlabel")); + //% "Milk" + pushButton7->setText(qtTrId("xx_button_group_page_button7")); + //% "Sugar" + pushButton8->setText(qtTrId("xx_button_group_page_button8")); + //% "Biscotti" + pushButton9->setText(qtTrId("xx_button_group_page_button9")); +} diff --git a/demos/widgetsgallery/buttongrouppage.h b/demos/widgetsgallery/buttongrouppage.h index af69750d..ddc908e5 100644 --- a/demos/widgetsgallery/buttongrouppage.h +++ b/demos/widgetsgallery/buttongrouppage.h @@ -35,8 +35,10 @@ public: virtual ~ButtonGroupPage(); virtual QString timedemoTitle(); virtual void createContent(); + protected: virtual void retranslateUi(); + private: MButton *pushButton1; MButton *pushButton2; @@ -44,8 +46,12 @@ private: MButton *pushButton4; MButton *pushButton5; MButton *pushButton6; - - MLabel* hLabel; + MButton *pushButton7; + MButton *pushButton8; + MButton *pushButton9; + + MLabel* hLabel1; + MLabel* hLabel2; MLabel* vLabel; }; |