Commit 5bc9dba7 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Extract addresstypedialog.cpp. Add selectaddresstypecombobox.cpp

parent 11f75f00
...@@ -40,6 +40,7 @@ set(akonadicontact_addresslocation_editor_SRCS ...@@ -40,6 +40,7 @@ set(akonadicontact_addresslocation_editor_SRCS
editor/addresseditor/iconnamecache.cpp editor/addresseditor/iconnamecache.cpp
editor/addresseditor/addresseslocationwidget.cpp editor/addresseditor/addresseslocationwidget.cpp
editor/addresseditor/selectaddresstypecombobox.cpp editor/addresseditor/selectaddresstypecombobox.cpp
editor/addresseditor/addresstypedialog.cpp
) )
set(akonadicontact_editor_SRCS set(akonadicontact_editor_SRCS
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "addresslocationwidget.h" #include "addresslocationwidget.h"
#include "selectaddresstypecombobox.h"
#include <KComboBox> #include <KComboBox>
#include <KLineEdit> #include <KLineEdit>
...@@ -38,6 +39,10 @@ AddressLocationWidget::AddressLocationWidget(QWidget *parent) ...@@ -38,6 +39,10 @@ AddressLocationWidget::AddressLocationWidget(QWidget *parent)
QGridLayout *topLayout = new QGridLayout; QGridLayout *topLayout = new QGridLayout;
setLayout(topLayout); setLayout(topLayout);
mTypeCombo = new SelectAddressTypeComboBox(this);
mTypeCombo->setObjectName(QStringLiteral("typeaddress"));
topLayout->addWidget(mTypeCombo, 0, 0, 1, 2);
QLabel *label = new QLabel(KContacts::Address::streetLabel(), this); QLabel *label = new QLabel(KContacts::Address::streetLabel(), this);
label->setObjectName(QStringLiteral("streetlabel")); label->setObjectName(QStringLiteral("streetlabel"));
topLayout->addWidget(label, 1, 0); topLayout->addWidget(label, 1, 0);
...@@ -117,7 +122,7 @@ AddressLocationWidget::~AddressLocationWidget() ...@@ -117,7 +122,7 @@ AddressLocationWidget::~AddressLocationWidget()
void AddressLocationWidget::setAddress(const KContacts::Address &address) void AddressLocationWidget::setAddress(const KContacts::Address &address)
{ {
mAddress = address; mAddress = address;
//mTypeCombo->setType(mAddress.type()); mTypeCombo->setType(mAddress.type());
//mStreetTextEdit->setPlainText(mAddress.street()); //mStreetTextEdit->setPlainText(mAddress.street());
mRegionEdit->setText(address.region()); mRegionEdit->setText(address.region());
mLocalityEdit->setText(address.locality()); mLocalityEdit->setText(address.locality());
...@@ -139,7 +144,7 @@ KContacts::Address AddressLocationWidget::address() const ...@@ -139,7 +144,7 @@ KContacts::Address AddressLocationWidget::address() const
{ {
KContacts::Address address(mAddress); KContacts::Address address(mAddress);
//address.setType(mTypeCombo->type()); address.setType(mTypeCombo->type());
address.setLocality(mLocalityEdit->text()); address.setLocality(mLocalityEdit->text());
address.setRegion(mRegionEdit->text()); address.setRegion(mRegionEdit->text());
address.setPostalCode(mPostalCodeEdit->text()); address.setPostalCode(mPostalCodeEdit->text());
......
...@@ -30,6 +30,7 @@ class QCheckBox; ...@@ -30,6 +30,7 @@ class QCheckBox;
class KLineEdit; class KLineEdit;
class KComboBox; class KComboBox;
class QPushButton; class QPushButton;
class SelectAddressTypeComboBox;
class AddressLocationWidget : public QWidget class AddressLocationWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
...@@ -43,6 +44,7 @@ public: ...@@ -43,6 +44,7 @@ public:
void slotModifyAddress(const KContacts::Address &address, int currentIndex); void slotModifyAddress(const KContacts::Address &address, int currentIndex);
private: private:
KContacts::Address mAddress;
QCheckBox *mPreferredCheckBox; QCheckBox *mPreferredCheckBox;
KLineEdit *mPOBoxEdit; KLineEdit *mPOBoxEdit;
KLineEdit *mLocalityEdit; KLineEdit *mLocalityEdit;
...@@ -51,7 +53,7 @@ private: ...@@ -51,7 +53,7 @@ private:
KLineEdit *mStreetEdit; KLineEdit *mStreetEdit;
KComboBox *mCountryCombo; KComboBox *mCountryCombo;
QPushButton *mAddAddress; QPushButton *mAddAddress;
KContacts::Address mAddress; SelectAddressTypeComboBox *mTypeCombo;
}; };
#endif // ADDRESSLOCATIONWIDGET_H #endif // ADDRESSLOCATIONWIDGET_H
/*
This file is part of Akonadi Contact.
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "addresstypedialog.h"
#include <KLocalizedString>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QCheckBox>
#include <QButtonGroup>
AddressTypeDialog::AddressTypeDialog(KContacts::Address::Type type, QWidget *parent)
: QDialog(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
setWindowTitle(i18nc("street/postal", "Edit Address Type"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
okButton->setDefault(true);
QWidget *page = new QWidget(this);
mainLayout->addWidget(page);
mainLayout->addWidget(buttonBox);
QVBoxLayout *layout = new QVBoxLayout(page);
layout->setMargin(0);
QGroupBox *box = new QGroupBox(i18nc("street/postal", "Address Types"), page);
mainLayout->addWidget(box);
layout->addWidget(box);
mGroup = new QButtonGroup(box);
mGroup->setExclusive(false);
QGridLayout *buttonLayout = new QGridLayout(box);
mTypeList = KContacts::Address::typeList();
mTypeList.removeAll(KContacts::Address::Pref);
KContacts::Address::TypeList::ConstIterator it;
int i = 0;
int row = 0;
for (it = mTypeList.constBegin(); it != mTypeList.constEnd(); ++it, ++i) {
QCheckBox *cb = new QCheckBox(KContacts::Address::typeLabel(*it), box);
cb->setChecked(type & mTypeList[i]);
buttonLayout->addWidget(cb, row, i % 3);
if (i % 3 == 2) {
++row;
}
mGroup->addButton(cb);
}
}
AddressTypeDialog::~AddressTypeDialog()
{
}
KContacts::Address::Type AddressTypeDialog::type() const
{
KContacts::Address::Type type;
for (int i = 0; i < mGroup->buttons().count(); ++i) {
QCheckBox *box = qobject_cast<QCheckBox *>(mGroup->buttons().at(i));
if (box && box->isChecked()) {
type |= mTypeList[i];
}
}
return type;
}
/*
This file is part of Akonadi Contact.
Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef ADDRESSTYPEDIALOG_H
#define ADDRESSTYPEDIALOG_H
#include <QDialog>
#include <KContacts/Address>
class QButtonGroup;
/**
* Dialog for creating a new address types.
*
* @note This dialog is only used by AddressTypeCombo.
*/
class AddressTypeDialog : public QDialog
{
public:
AddressTypeDialog(KContacts::Address::Type type, QWidget *parent);
~AddressTypeDialog();
KContacts::Address::Type type() const;
private:
QButtonGroup *mGroup;
KContacts::Address::TypeList mTypeList;
};
#endif // ADDRESSTYPEDIALOG_H
...@@ -7,14 +7,14 @@ ecm_mark_as_test(addresseslocationviewer) ...@@ -7,14 +7,14 @@ ecm_mark_as_test(addresseslocationviewer)
target_link_libraries(addresseslocationviewer Qt5::Test Qt5::Widgets KF5::AkonadiContact KF5::Contacts KF5::I18n Qt5::WebKitWidgets Grantlee5::Templates KF5::IconThemes) target_link_libraries(addresseslocationviewer Qt5::Test Qt5::Widgets KF5::AkonadiContact KF5::Contacts KF5::I18n Qt5::WebKitWidgets Grantlee5::Templates KF5::IconThemes)
set(addresslocationwidget_SRCS addresslocationwidgettest.cpp ../addresslocationwidget.cpp) set(addresslocationwidget_SRCS addresslocationwidgettest.cpp ../addresslocationwidget.cpp ../selectaddresstypecombobox.cpp)
add_executable(addresslocationwidget ${addresslocationwidget_SRCS}) add_executable(addresslocationwidget ${addresslocationwidget_SRCS})
add_test(addresslocationwidget addresslocationwidget) add_test(addresslocationwidget addresslocationwidget)
ecm_mark_as_test(addresslocationwidget) ecm_mark_as_test(addresslocationwidget)
target_link_libraries(addresslocationwidget Qt5::Test Qt5::Widgets KF5::AkonadiContact KF5::Contacts KF5::I18n KF5::Completion) target_link_libraries(addresslocationwidget Qt5::Test Qt5::Widgets KF5::AkonadiContact KF5::Contacts KF5::I18n KF5::Completion)
set(addresseslocationwidget_SRCS addresseslocationwidgettest.cpp ../addresseslocationwidget.cpp ../addresseslocationviewer.cpp ../addresseslocationgrantleeformater.cpp set(addresseslocationwidget_SRCS addresseslocationwidgettest.cpp ../addresseslocationwidget.cpp ../addresseslocationviewer.cpp ../addresseslocationgrantleeformater.cpp
../addressgrantleeobject.cpp ../iconnamecache.cpp ../addresslocationwidget.cpp) ../addressgrantleeobject.cpp ../iconnamecache.cpp ../addresslocationwidget.cpp ../selectaddresstypecombobox.cpp)
add_executable(addresseslocationwidget ${addresseslocationwidget_SRCS}) add_executable(addresseslocationwidget ${addresseslocationwidget_SRCS})
add_test(addresseslocationwidget addresseslocationwidget) add_test(addresseslocationwidget addresseslocationwidget)
ecm_mark_as_test(addresseslocationwidget) ecm_mark_as_test(addresseslocationwidget)
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <KLineEdit> #include <KLineEdit>
#include <QTest> #include <QTest>
#include <QCheckBox> #include <QCheckBox>
#include <editor/addresseditor/selectaddresstypecombobox.h>
AddressLocationWidgetTest::AddressLocationWidgetTest(QObject *parent) AddressLocationWidgetTest::AddressLocationWidgetTest(QObject *parent)
: QObject(parent) : QObject(parent)
...@@ -45,6 +46,9 @@ void AddressLocationWidgetTest::shouldHaveDefaultValue() ...@@ -45,6 +46,9 @@ void AddressLocationWidgetTest::shouldHaveDefaultValue()
{ {
AddressLocationWidget w; AddressLocationWidget w;
SelectAddressTypeComboBox *typeAddress = w.findChild<SelectAddressTypeComboBox *>(QStringLiteral("typeaddress"));
QVERIFY(typeAddress);
QLabel *streetlabel = w.findChild<QLabel *>(QStringLiteral("streetlabel")); QLabel *streetlabel = w.findChild<QLabel *>(QStringLiteral("streetlabel"));
QVERIFY(streetlabel); QVERIFY(streetlabel);
KLineEdit *mStreetEdit = w.findChild<KLineEdit *>(QStringLiteral("streetlineedit")); KLineEdit *mStreetEdit = w.findChild<KLineEdit *>(QStringLiteral("streetlineedit"));
......
...@@ -30,7 +30,8 @@ SelectAddressTypeComboBox::SelectAddressTypeComboBox(QWidget *parent) ...@@ -30,7 +30,8 @@ SelectAddressTypeComboBox::SelectAddressTypeComboBox(QWidget *parent)
, mLastSelected(0) , mLastSelected(0)
{ {
const int count = KContacts::Address::typeList().count(); const int count = KContacts::Address::typeList().count();
mTypeList.reserve(count + 1); mTypeList.reserve(count + 2);
mTypeList.append(-2); // Add initial message
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
mTypeList.append(KContacts::Address::typeList().at(i)); mTypeList.append(KContacts::Address::typeList().at(i));
} }
...@@ -38,8 +39,7 @@ SelectAddressTypeComboBox::SelectAddressTypeComboBox(QWidget *parent) ...@@ -38,8 +39,7 @@ SelectAddressTypeComboBox::SelectAddressTypeComboBox(QWidget *parent)
update(); update();
connect(this, SIGNAL(activated(int)), connect(this, SIGNAL(activated(int)), this, SLOT(selected(int)));
this, SLOT(selected(int)));
} }
SelectAddressTypeComboBox::~SelectAddressTypeComboBox() SelectAddressTypeComboBox::~SelectAddressTypeComboBox()
...@@ -71,6 +71,8 @@ void SelectAddressTypeComboBox::update() ...@@ -71,6 +71,8 @@ void SelectAddressTypeComboBox::update()
for (int i = 0; i < mTypeList.count(); ++i) { for (int i = 0; i < mTypeList.count(); ++i) {
if (mTypeList.at(i) == -1) { // "Other..." entry if (mTypeList.at(i) == -1) { // "Other..." entry
addItem(i18nc("@item:inlistbox Category of contact info field", "Other...")); addItem(i18nc("@item:inlistbox Category of contact info field", "Other..."));
} else if (mTypeList.at(i) == -2) {
addItem(i18nc("@item:inlistbox Category of contact info field", "New Address Type"));
} else { } else {
addItem(KContacts::Address::typeLabel(KContacts::Address::Type(mTypeList.at(i)))); addItem(KContacts::Address::typeLabel(KContacts::Address::Type(mTypeList.at(i))));
} }
...@@ -85,6 +87,8 @@ void SelectAddressTypeComboBox::selected(int pos) ...@@ -85,6 +87,8 @@ void SelectAddressTypeComboBox::selected(int pos)
{ {
if (mTypeList.at(pos) == -1) { if (mTypeList.at(pos) == -1) {
otherSelected(); otherSelected();
} else if (mTypeList.at(pos) == -2) {
return;
} else { } else {
mType = KContacts::Address::Type(mTypeList.at(pos)); mType = KContacts::Address::Type(mTypeList.at(pos));
mLastSelected = pos; mLastSelected = pos;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
#include "addresseditwidget.h" #include "addresseditwidget.h"
#include "editor/addresseditor/addresstypedialog.h"
#include "autoqpointer_p.h" #include "autoqpointer_p.h"
#include <QtCore/QEvent> #include <QtCore/QEvent>
...@@ -83,24 +83,6 @@ protected: ...@@ -83,24 +83,6 @@ protected:
} }
}; };
/**
* Dialog for creating a new address types.
*
* @note This dialog is only used by AddressTypeCombo.
*/
class AddressTypeDialog : public QDialog
{
public:
AddressTypeDialog(KContacts::Address::Type type, QWidget *parent);
~AddressTypeDialog();
KContacts::Address::Type type() const;
private:
QButtonGroup *mGroup;
KContacts::Address::TypeList mTypeList;
};
AddressSelectionWidget::AddressSelectionWidget(QWidget *parent) AddressSelectionWidget::AddressSelectionWidget(QWidget *parent)
: KComboBox(parent) : KComboBox(parent)
...@@ -587,66 +569,3 @@ void AddressEditDialog::fillCountryCombo() ...@@ -587,66 +569,3 @@ void AddressEditDialog::fillCountryCombo()
const QString currentCountry = QLocale::countryToString(QLocale().country()); const QString currentCountry = QLocale::countryToString(QLocale().country());
mCountryCombo->setCurrentIndex(mCountryCombo->findText(currentCountry)); mCountryCombo->setCurrentIndex(mCountryCombo->findText(currentCountry));
} }
AddressTypeDialog::AddressTypeDialog(KContacts::Address::Type type, QWidget *parent)
: QDialog(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
setWindowTitle(i18nc("street/postal", "Edit Address Type"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
okButton->setDefault(true);
QWidget *page = new QWidget(this);
mainLayout->addWidget(page);
mainLayout->addWidget(buttonBox);
QVBoxLayout *layout = new QVBoxLayout(page);
layout->setMargin(0);
QGroupBox *box = new QGroupBox(i18nc("street/postal", "Address Types"), page);
mainLayout->addWidget(box);
layout->addWidget(box);
mGroup = new QButtonGroup(box);
mGroup->setExclusive(false);
QGridLayout *buttonLayout = new QGridLayout(box);
mTypeList = KContacts::Address::typeList();
mTypeList.removeAll(KContacts::Address::Pref);
KContacts::Address::TypeList::ConstIterator it;
int i = 0;
int row = 0;
for (it = mTypeList.constBegin(); it != mTypeList.constEnd(); ++it, ++i) {
QCheckBox *cb = new QCheckBox(KContacts::Address::typeLabel(*it), box);
cb->setChecked(type & mTypeList[i]);
buttonLayout->addWidget(cb, row, i % 3);
if (i % 3 == 2) {
++row;
}
mGroup->addButton(cb);
}
}
AddressTypeDialog::~AddressTypeDialog()
{
}
KContacts::Address::Type AddressTypeDialog::type() const
{
KContacts::Address::Type type;
for (int i = 0; i < mGroup->buttons().count(); ++i) {
QCheckBox *box = qobject_cast<QCheckBox *>(mGroup->buttons().at(i));
if (box && box->isChecked()) {
type |= mTypeList[i];
}
}
return type;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment