Commit ab7ec66b authored by Guy Maurel's avatar Guy Maurel

Coding Style

REVIEWS: 114931 114939 114940 114943 114944 114946 114947 114948 114950 114951 114952 114953 114954
parent ccf73a7c
......@@ -30,47 +30,46 @@
#include <QHBoxLayout>
CategoriesEditWidget::CategoriesEditWidget( QWidget *parent )
: QWidget( parent )
CategoriesEditWidget::CategoriesEditWidget(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( KDialog::spacingHint() );
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(KDialog::spacingHint());
mTagWidget = new TagWidget( this );
layout->addWidget( mTagWidget );
mTagWidget = new TagWidget(this);
layout->addWidget(mTagWidget);
}
CategoriesEditWidget::~CategoriesEditWidget()
{
}
void CategoriesEditWidget::setReadOnly( bool readOnly )
void CategoriesEditWidget::setReadOnly(bool readOnly)
{
mTagWidget->setEnabled( !readOnly );
mTagWidget->setEnabled(!readOnly);
}
void CategoriesEditWidget::loadContact( const KABC::Addressee &contact )
void CategoriesEditWidget::loadContact(const KABC::Addressee &contact)
{
QVector<Nepomuk2::Tag> tags;
QVector<Nepomuk2::Tag> tags;
const QStringList categories = contact.categories();
foreach ( const QString &category, categories ) {
tags.append( Nepomuk2::Tag( category ) );
}
const QStringList categories = contact.categories();
foreach (const QString &category, categories) {
tags.append(Nepomuk2::Tag(category));
}
mTagWidget->setTags( tags );
mTagWidget->setTags(tags);
}
void CategoriesEditWidget::storeContact( KABC::Addressee &contact ) const
void CategoriesEditWidget::storeContact(KABC::Addressee &contact) const
{
QStringList categories;
QStringList categories;
const QVector<Nepomuk2::Tag> tags = mTagWidget->tags();
foreach ( const Nepomuk2::Tag &tag, tags ) {
categories.append( tag.genericLabel() );
}
const QVector<Nepomuk2::Tag> tags = mTagWidget->tags();
foreach (const Nepomuk2::Tag &tag, tags) {
categories.append(tag.genericLabel());
}
contact.setCategories( categories );
contact.setCategories(categories);
}
......@@ -33,18 +33,18 @@ class TagWidget;
*/
class CategoriesEditWidget : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
explicit CategoriesEditWidget( QWidget *parent = 0 );
public:
explicit CategoriesEditWidget(QWidget *parent = 0);
~CategoriesEditWidget();
void loadContact( const KABC::Addressee &contact );
void storeContact( KABC::Addressee &contact ) const;
void loadContact(const KABC::Addressee &contact);
void storeContact(KABC::Addressee &contact) const;
void setReadOnly( bool readOnly );
void setReadOnly(bool readOnly);
private:
private:
TagWidget *mTagWidget;
};
......
......@@ -29,67 +29,67 @@
#include <QFormLayout>
#include <QRegExpValidator>
CustomFieldEditorDialog::CustomFieldEditorDialog( QWidget *parent )
: KDialog( parent )
CustomFieldEditorDialog::CustomFieldEditorDialog(QWidget *parent)
: KDialog(parent)
{
setCaption( i18n( "Edit Custom Field" ) );
setButtons( Ok | Cancel | Details );
setCaption(i18n("Edit Custom Field"));
setButtons(Ok | Cancel | Details);
QWidget *widget = new QWidget( this );
setMainWidget( widget );
QWidget *widget = new QWidget(this);
setMainWidget(widget);
QFormLayout *layout = new QFormLayout( widget );
QFormLayout *layout = new QFormLayout(widget);
mKey = new KLineEdit;
mTitle = new KLineEdit;
mType = new KComboBox;
mScope = new QCheckBox( i18n( "Use field for all contacts" ) );
mKey = new KLineEdit;
mTitle = new KLineEdit;
mType = new KComboBox;
mScope = new QCheckBox(i18n("Use field for all contacts"));
layout->addRow( i18nc( "The title of a custom field", "Title" ), mTitle );
layout->addRow( i18nc( "The type of a custom field", "Type" ), mType );
layout->addRow( QString(), mScope );
layout->addRow(i18nc("The title of a custom field", "Title"), mTitle);
layout->addRow(i18nc("The type of a custom field", "Type"), mType);
layout->addRow(QString(), mScope);
QWidget *detailsWidget = new QWidget;
QFormLayout *detailsLayout = new QFormLayout( detailsWidget );
detailsLayout->addRow( i18n( "Key" ), mKey );
QWidget *detailsWidget = new QWidget;
QFormLayout *detailsLayout = new QFormLayout(detailsWidget);
detailsLayout->addRow(i18n("Key"), mKey);
setDetailsWidget( detailsWidget );
setButtonText( Details, i18nc( "@label Opens the advanced dialog", "Advanced" ) );
setDetailsWidget(detailsWidget);
setButtonText(Details, i18nc("@label Opens the advanced dialog", "Advanced"));
mType->addItem( i18n( "Text" ), CustomField::TextType );
mType->addItem( i18n( "Numeric" ), CustomField::NumericType );
mType->addItem( i18n( "Boolean" ), CustomField::BooleanType );
mType->addItem( i18n( "Date" ), CustomField::DateType );
mType->addItem( i18n( "Time" ), CustomField::TimeType );
mType->addItem( i18n( "DateTime" ), CustomField::DateTimeType );
mType->addItem( i18n( "Url" ), CustomField::UrlType );
mType->addItem(i18n("Text"), CustomField::TextType);
mType->addItem(i18n("Numeric"), CustomField::NumericType);
mType->addItem(i18n("Boolean"), CustomField::BooleanType);
mType->addItem(i18n("Date"), CustomField::DateType);
mType->addItem(i18n("Time"), CustomField::TimeType);
mType->addItem(i18n("DateTime"), CustomField::DateTimeType);
mType->addItem(i18n("Url"), CustomField::UrlType);
mKey->setValidator( new QRegExpValidator( QRegExp( QLatin1String( "[a-zA-Z0-9\\-]+" ) ), this ) );
mTitle->setFocus();
mKey->setValidator(new QRegExpValidator(QRegExp(QLatin1String("[a-zA-Z0-9\\-]+")), this));
mTitle->setFocus();
}
void CustomFieldEditorDialog::setCustomField( const CustomField &field )
void CustomFieldEditorDialog::setCustomField(const CustomField &field)
{
mCustomField = field;
mCustomField = field;
mKey->setText( mCustomField.key() );
mTitle->setText( mCustomField.title() );
mType->setCurrentIndex( mType->findData( mCustomField.type() ) );
mScope->setChecked( ( mCustomField.scope() == CustomField::GlobalScope ) );
mKey->setText(mCustomField.key());
mTitle->setText(mCustomField.title());
mType->setCurrentIndex(mType->findData(mCustomField.type()));
mScope->setChecked((mCustomField.scope() == CustomField::GlobalScope));
}
CustomField CustomFieldEditorDialog::customField() const
{
CustomField customField( mCustomField );
CustomField customField(mCustomField);
customField.setKey( mKey->text() );
customField.setTitle( mTitle->text() );
customField.setType( static_cast<CustomField::Type>( mType->itemData( mType->currentIndex() ).toInt() ) );
customField.setKey(mKey->text());
customField.setTitle(mTitle->text());
customField.setType(static_cast<CustomField::Type>(mType->itemData(mType->currentIndex()).toInt()));
if ( customField.scope() != CustomField::ExternalScope ) {
// do not change the scope for externally defined custom fields
customField.setScope( mScope->isChecked() ? CustomField::GlobalScope : CustomField::LocalScope );
}
if (customField.scope() != CustomField::ExternalScope) {
// do not change the scope for externally defined custom fields
customField.setScope(mScope->isChecked() ? CustomField::GlobalScope : CustomField::LocalScope);
}
return customField;
return customField;
}
......@@ -32,15 +32,15 @@ class QCheckBox;
class CustomFieldEditorDialog : public KDialog
{
Q_OBJECT
Q_OBJECT
public:
explicit CustomFieldEditorDialog( QWidget *parent = 0 );
public:
explicit CustomFieldEditorDialog(QWidget *parent = 0);
void setCustomField( const CustomField &field );
void setCustomField(const CustomField &field);
CustomField customField() const;
private:
private:
KLineEdit *mTitle;
KComboBox *mType;
QCheckBox *mScope;
......
......@@ -26,15 +26,15 @@
class CustomFieldsDelegate : public QStyledItemDelegate
{
public:
explicit CustomFieldsDelegate( QObject *parent = 0 );
public:
explicit CustomFieldsDelegate(QObject *parent = 0);
~CustomFieldsDelegate();
virtual QWidget* createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
virtual void setEditorData( QWidget *editor, const QModelIndex &index ) const;
virtual void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const;
virtual void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
#endif
......@@ -33,31 +33,31 @@ class Addressee;
class QPushButton;
class QTreeView;
void splitCustomField( const QString &str, QString &app, QString &name, QString &value );
void splitCustomField(const QString &str, QString &app, QString &name, QString &value);
class CustomFieldsEditWidget : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
explicit CustomFieldsEditWidget( QWidget *parent = 0 );
public:
explicit CustomFieldsEditWidget(QWidget *parent = 0);
~CustomFieldsEditWidget();
void loadContact( const KABC::Addressee &contact );
void storeContact( KABC::Addressee &contact ) const;
void loadContact(const KABC::Addressee &contact);
void storeContact(KABC::Addressee &contact) const;
void setReadOnly( bool readOnly );
void setReadOnly(bool readOnly);
void setLocalCustomFieldDescriptions( const QVariantList &descriptions );
void setLocalCustomFieldDescriptions(const QVariantList &descriptions);
QVariantList localCustomFieldDescriptions() const;
private Q_SLOTS:
private Q_SLOTS:
void slotAdd();
void slotEdit();
void slotRemove();
void slotUpdateButtons();
private:
private:
QTreeView *mView;
QPushButton *mAddButton;
......
......@@ -29,31 +29,31 @@
class CustomFieldsModel : public QAbstractItemModel
{
public:
public:
enum Role {
TypeRole = Qt::UserRole,
ScopeRole
TypeRole = Qt::UserRole,
ScopeRole
};
explicit CustomFieldsModel( QObject *parent = 0 );
explicit CustomFieldsModel(QObject *parent = 0);
~CustomFieldsModel();
void setCustomFields( const CustomField::List &addresses );
void setCustomFields(const CustomField::List &addresses);
CustomField::List customFields() const;
virtual QModelIndex index( int row, int col, const QModelIndex &parent = QModelIndex() ) const;
virtual QModelIndex parent( const QModelIndex &child ) const;
virtual QVariant data( const QModelIndex &index, int role ) const;
virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
virtual QModelIndex index(int row, int col, const QModelIndex &parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex &child) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() );
virtual bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
private:
private:
CustomField::List mCustomFields;
};
......
......@@ -33,114 +33,120 @@
#include <QLabel>
#include <QToolButton>
DateView::DateView( QWidget *parent )
: QLabel( parent )
DateView::DateView(QWidget *parent)
: QLabel(parent)
{
setTextInteractionFlags( Qt::TextSelectableByMouse );
setFrameShape( QFrame::StyledPanel );
setFrameShadow( QFrame::Sunken );
setTextInteractionFlags(Qt::TextSelectableByMouse);
setFrameShape(QFrame::StyledPanel);
setFrameShadow(QFrame::Sunken);
}
void DateView::contextMenuEvent( QContextMenuEvent *event )
void DateView::contextMenuEvent(QContextMenuEvent *event)
{
if ( text().isEmpty() ) {
return;
}
if (text().isEmpty()) {
return;
}
QMenu menu;
menu.addAction( i18n( "Remove" ), this, SLOT(emitSignal()) );
QMenu menu;
menu.addAction(i18n("Remove"), this, SLOT(emitSignal()));
menu.exec( event->globalPos() );
menu.exec(event->globalPos());
}
void DateView::emitSignal()
{
emit resetDate();
emit resetDate();
}
DateEditWidget::DateEditWidget( Type type, QWidget *parent )
: QWidget( parent ), mReadOnly( false )
DateEditWidget::DateEditWidget(Type type, QWidget *parent)
: QWidget(parent)
, mReadOnly(false)
{
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
mView = new DateView;
layout->addWidget( mView );
mClearButton = new QToolButton;
if ( layoutDirection() == Qt::LeftToRight ) {
mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-rtl" ) ) );
} else {
mClearButton->setIcon( KIcon( QLatin1String( "edit-clear-locationbar-ltr" ) ) );
}
layout->addWidget( mClearButton );
mSelectButton = new QToolButton;
mSelectButton->setPopupMode( QToolButton::InstantPopup );
switch ( type ) {
case General: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-day" ) ) ); break;
case Birthday: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-birthday" ) ) ); break;
case Anniversary: mSelectButton->setIcon( KIcon( QLatin1String( "view-calendar-wedding-anniversary" ) ) ); break;
}
layout->addWidget( mSelectButton );
setFocusProxy( mSelectButton );
setFocusPolicy( Qt::StrongFocus );
mMenu = new KDatePickerPopup( KDatePickerPopup::DatePicker, QDate(), this );
mSelectButton->setMenu( mMenu );
connect( mClearButton, SIGNAL(clicked()), SLOT(resetDate()) );
connect( mMenu, SIGNAL(dateChanged(QDate)), SLOT(dateSelected(QDate)) );
connect( mView, SIGNAL(resetDate()), SLOT(resetDate()) );
updateView();
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
mView = new DateView;
layout->addWidget(mView);
mClearButton = new QToolButton;
if (layoutDirection() == Qt::LeftToRight) {
mClearButton->setIcon(KIcon(QLatin1String("edit-clear-locationbar-rtl")));
} else {
mClearButton->setIcon(KIcon(QLatin1String("edit-clear-locationbar-ltr")));
}
layout->addWidget(mClearButton);
mSelectButton = new QToolButton;
mSelectButton->setPopupMode(QToolButton::InstantPopup);
switch (type) {
case General:
mSelectButton->setIcon(KIcon(QLatin1String("view-calendar-day")));
break;
case Birthday:
mSelectButton->setIcon(KIcon(QLatin1String("view-calendar-birthday")));
break;
case Anniversary:
mSelectButton->setIcon(KIcon(QLatin1String("view-calendar-wedding-anniversary")));
break;
}
layout->addWidget(mSelectButton);
setFocusProxy(mSelectButton);
setFocusPolicy(Qt::StrongFocus);
mMenu = new KDatePickerPopup(KDatePickerPopup::DatePicker, QDate(), this);
mSelectButton->setMenu(mMenu);
connect(mClearButton, SIGNAL(clicked()), SLOT(resetDate()));
connect(mMenu, SIGNAL(dateChanged(QDate)), SLOT(dateSelected(QDate)));
connect(mView, SIGNAL(resetDate()), SLOT(resetDate()));
updateView();
}
DateEditWidget::~DateEditWidget()
{
}
void DateEditWidget::setDate( const QDate &date )
void DateEditWidget::setDate(const QDate &date)
{
mDate = date;
mMenu->setDate( mDate );
updateView();
mDate = date;
mMenu->setDate(mDate);
updateView();
}
QDate DateEditWidget::date() const
{
return mDate;
return mDate;
}
void DateEditWidget::setReadOnly( bool readOnly )
void DateEditWidget::setReadOnly(bool readOnly)
{
mReadOnly = readOnly;
mReadOnly = readOnly;
mSelectButton->setEnabled( !readOnly );
mClearButton->setEnabled( !readOnly );
mSelectButton->setEnabled(!readOnly);
mClearButton->setEnabled(!readOnly);
}
void DateEditWidget::dateSelected(const QDate &date)
{
mDate = date;
updateView();
mDate = date;
updateView();
}
void DateEditWidget::resetDate()
{
mDate = QDate();
updateView();
mDate = QDate();
updateView();
}
void DateEditWidget::updateView()
{
if ( mDate.isValid() ) {
mView->setText( KGlobal::locale()->formatDate( mDate ) );
mClearButton->show();
} else {
mView->setText( QString() );
mClearButton->hide();
}
if (mDate.isValid()) {
mView->setText(KGlobal::locale()->formatDate(mDate));
mClearButton->show();
} else {
mView->setText(QString());
mClearButton->hide();
}
}
......@@ -33,46 +33,46 @@ class QToolButton;
class DateView : public QLabel
{
Q_OBJECT
Q_OBJECT
public:
explicit DateView( QWidget *parent = 0 );
public:
explicit DateView(QWidget *parent = 0);
Q_SIGNALS: