diff options
Diffstat (limited to 'Swift/QtUI/QtVCardWidget')
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp | 37 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardWidget.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardWidget.ui | 45 |
3 files changed, 50 insertions, 35 deletions
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp index ee3ef96..d681fe9 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp @@ -39,7 +39,13 @@ QtVCardWidget::QtVCardWidget(QWidget* parent) : ui->cardFields->setColumnStretch(4,2); menu = new QMenu(this); - ui->toolButton->setMenu(menu); + toolButton = new QToolButton(this); + toolButton->setText(tr("Add Field")); + toolButton->setArrowType(Qt::NoArrow); + toolButton->setAutoRaise(false); + toolButton->setPopupMode(QToolButton::InstantPopup); + toolButton->hide(); + toolButton->setMenu(menu); addFieldType(menu, boost::make_shared<QtVCardInternetEMailField::FieldInfo>()); addFieldType(menu, boost::make_shared<QtVCardTelephoneField::FieldInfo>()); @@ -72,14 +78,7 @@ void QtVCardWidget::setEditable(bool editable) { foreach(QtVCardGeneralField* field, fields) { field->setEditable(editable); } - - if (editable) { - ui->toolButton->show(); - //if ((findChild<QtVCardBirthdayField*>() == 0)) { - //} - } else { - ui->toolButton->hide(); - } + toolButton->setVisible(editable); editableChanged(editable); } @@ -175,6 +174,7 @@ void QtVCardWidget::setVCard(VCard::ref vcard) { appendField(urlField); } + relayoutToolButton(); setEditable(editable); window()->resize(sizeHint().width(), size().height() < 200 ? 200 : size().height()); } @@ -294,6 +294,7 @@ void QtVCardWidget::addField() { newGeneralField->initialize(); } appendField(newGeneralField); + relayoutToolButton(); } } @@ -303,10 +304,12 @@ void QtVCardWidget::removeField(QtVCardGeneralField *field) { } void QtVCardWidget::addFieldType(QMenu* menu, boost::shared_ptr<QtVCardFieldInfo> fieldType) { - QAction* action = new QAction(tr("Add ") + fieldType->getMenuName(), this); - actionFieldInfo[action] = fieldType; - connect(action, SIGNAL(triggered()), this, SLOT(addField())); - menu->addAction(action); + if (!fieldType->getMenuName().isEmpty()) { + QAction* action = new QAction(tr("Add ") + fieldType->getMenuName(), this); + actionFieldInfo[action] = fieldType; + connect(action, SIGNAL(triggered()), this, SLOT(addField())); + menu->addAction(action); + } } int QtVCardWidget::fieldTypeInstances(boost::shared_ptr<QtVCardFieldInfo> fieldType) { @@ -324,6 +327,10 @@ void layoutDeleteChildren(QLayout *layout) { if (child->layout()) { layoutDeleteChildren(child->layout()); } + if (dynamic_cast<QToolButton*>(child->widget())) { + delete child; + break; + } delete child->widget(); delete child; } @@ -360,4 +367,8 @@ void QtVCardWidget::appendField(QtVCardGeneralField *field) { fields.push_back(field); } +void QtVCardWidget::relayoutToolButton() { + ui->cardFields->addWidget(toolButton, ui->cardFields->rowCount(), ui->cardFields->columnCount()-2, 1, 1, Qt::AlignRight); +} + } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.h b/Swift/QtUI/QtVCardWidget/QtVCardWidget.h index 07f528d..29ed499 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardWidget.h +++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.h @@ -7,6 +7,7 @@ #pragma once #include <QWidget> +#include <QToolButton> #include <Swiften/Elements/VCard.h> #include <boost/smart_ptr/make_shared.hpp> @@ -47,10 +48,12 @@ namespace Swift { void clearFields(); void clearEmptyFields(); void appendField(QtVCardGeneralField* field); + void relayoutToolButton(); private: VCard::ref vcard; Ui::QtVCardWidget* ui; + QToolButton* toolButton; bool editable; QMenu* menu; std::list<QtVCardGeneralField*> fields; diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.ui b/Swift/QtUI/QtVCardWidget/QtVCardWidget.ui index eae1006..4fc8605 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardWidget.ui +++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.ui @@ -13,8 +13,17 @@ <property name="windowTitle"> <string>Form</string> </property> - <layout class="QGridLayout" name="gridLayout" rowstretch="1,0" columnstretch="1,0"> - <property name="margin"> + <layout class="QGridLayout" name="gridLayout" rowstretch="1" columnstretch="1,0"> + <property name="leftMargin"> + <number>5</number> + </property> + <property name="topMargin"> + <number>5</number> + </property> + <property name="rightMargin"> + <number>5</number> + </property> + <property name="bottomMargin"> <number>5</number> </property> <item row="0" column="0" colspan="2"> @@ -64,7 +73,7 @@ <x>0</x> <y>0</y> <width>523</width> - <height>76</height> + <height>110</height> </rect> </property> <property name="sizePolicy"> @@ -77,12 +86,20 @@ <property name="sizeConstraint"> <enum>QLayout::SetMinAndMaxSize</enum> </property> - <property name="margin"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> <number>0</number> </property> <item> - <layout class="QGridLayout" name="cardFields"> - </layout> + <layout class="QGridLayout" name="cardFields"/> </item> <item> <spacer name="verticalSpacer"> @@ -106,22 +123,6 @@ </item> </layout> </item> - <item row="1" column="1"> - <widget class="QToolButton" name="toolButton"> - <property name="text"> - <string>Add Field</string> - </property> - <property name="popupMode"> - <enum>QToolButton::InstantPopup</enum> - </property> - <property name="autoRaise"> - <bool>false</bool> - </property> - <property name="arrowType"> - <enum>Qt::NoArrow</enum> - </property> - </widget> - </item> </layout> </widget> <customwidgets> |