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
editor/addresseditor/iconnamecache.cpp
editor/addresseditor/addresseslocationwidget.cpp
editor/addresseditor/selectaddresstypecombobox.cpp
editor/addresseditor/addresstypedialog.cpp
)
set(akonadicontact_editor_SRCS
......
......@@ -22,6 +22,7 @@
#include "addresslocationwidget.h"
#include "selectaddresstypecombobox.h"
#include <KComboBox>
#include <KLineEdit>
......@@ -38,6 +39,10 @@ AddressLocationWidget::AddressLocationWidget(QWidget *parent)
QGridLayout *topLayout = new QGridLayout;
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);
label->setObjectName(QStringLiteral("streetlabel"));
topLayout->addWidget(label, 1, 0);
......@@ -117,7 +122,7 @@ AddressLocationWidget::~AddressLocationWidget()
void AddressLocationWidget::setAddress(const KContacts::Address &address)
{
mAddress = address;
//mTypeCombo->setType(mAddress.type());
mTypeCombo->setType(mAddress.type());
//mStreetTextEdit->setPlainText(mAddress.street());
mRegionEdit->setText(address.region());
mLocalityEdit->setText(address.locality());
......@@ -139,7 +144,7 @@ KContacts::Address AddressLocationWidget::address() const
{
KContacts::Address address(mAddress);
//address.setType(mTypeCombo->type());
address.setType(mTypeCombo->type());
address.setLocality(mLocalityEdit->text());
address.setRegion(mRegionEdit->text());
address.setPostalCode(mPostalCodeEdit->text());
......
......@@ -30,6 +30,7 @@ class QCheckBox;
class KLineEdit;
class KComboBox;
class QPushButton;
class SelectAddressTypeComboBox;
class AddressLocationWidget : public QWidget
{
Q_OBJECT
......@@ -43,6 +44,7 @@ public:
void slotModifyAddress(const KContacts::Address &address, int currentIndex);
private:
KContacts::Address mAddress;
QCheckBox *mPreferredCheckBox;
KLineEdit *mPOBoxEdit;
KLineEdit *mLocalityEdit;
......@@ -51,7 +53,7 @@ private:
KLineEdit *mStreetEdit;
KComboBox *mCountryCombo;
QPushButton *mAddAddress;
KContacts::Address mAddress;
SelectAddressTypeComboBox *mTypeCombo;
};
#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)
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_test(addresslocationwidget addresslocationwidget)
ecm_mark_as_test(addresslocationwidget)
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
../addressgrantleeobject.cpp ../iconnamecache.cpp ../addresslocationwidget.cpp)
../addressgrantleeobject.cpp ../iconnamecache.cpp ../addresslocationwidget.cpp ../selectaddresstypecombobox.cpp)
add_executable(addresseslocationwidget ${addresseslocationwidget_SRCS})
add_test(addresseslocationwidget addresseslocationwidget)
ecm_mark_as_test(addresseslocationwidget)
......
......@@ -29,6 +29,7 @@
#include <KLineEdit>
#include <QTest>
#include <QCheckBox>
#include <editor/addresseditor/selectaddresstypecombobox.h>
AddressLocationWidgetTest::AddressLocationWidgetTest(QObject *parent)
: QObject(parent)
......@@ -45,6 +46,9 @@ void AddressLocationWidgetTest::shouldHaveDefaultValue()
{
AddressLocationWidget w;
SelectAddressTypeComboBox *typeAddress = w.findChild<SelectAddressTypeComboBox *>(QStringLiteral("typeaddress"));
QVERIFY(typeAddress);
QLabel *streetlabel = w.findChild<QLabel *>(QStringLiteral("streetlabel"));
QVERIFY(streetlabel);
KLineEdit *mStreetEdit = w.findChild<KLineEdit *>(QStringLiteral("streetlineedit"));
......
......@@ -30,7 +30,8 @@ SelectAddressTypeComboBox::SelectAddressTypeComboBox(QWidget *parent)
, mLastSelected(0)
{
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) {
mTypeList.append(KContacts::Address::typeList().at(i));
}
......@@ -38,8 +39,7 @@ SelectAddressTypeComboBox::SelectAddressTypeComboBox(QWidget *parent)
update();
connect(this, SIGNAL(activated(int)),
this, SLOT(selected(int)));
connect(this, SIGNAL(activated(int)), this, SLOT(selected(int)));
}
SelectAddressTypeComboBox::~SelectAddressTypeComboBox()
......@@ -71,6 +71,8 @@ void SelectAddressTypeComboBox::update()
for (int i = 0; i < mTypeList.count(); ++i) {
if (mTypeList.at(i) == -1) { // "Other..." entry
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 {
addItem(KContacts::Address::typeLabel(KContacts::Address::Type(mTypeList.at(i))));
}
......@@ -85,6 +87,8 @@ void SelectAddressTypeComboBox::selected(int pos)
{
if (mTypeList.at(pos) == -1) {
otherSelected();
} else if (mTypeList.at(pos) == -2) {
return;
} else {
mType = KContacts::Address::Type(mTypeList.at(pos));
mLastSelected = pos;
......
......@@ -20,7 +20,7 @@
*/
#include "addresseditwidget.h"
#include "editor/addresseditor/addresstypedialog.h"
#include "autoqpointer_p.h"
#include <QtCore/QEvent>
......@@ -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)
: KComboBox(parent)
......@@ -587,66 +569,3 @@ void AddressEditDialog::fillCountryCombo()
const QString currentCountry = QLocale::countryToString(QLocale().country());
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