summaryrefslogtreecommitdiffstats
blob: 7b0d02edc034f8926218b5514bfa2c08d58ec5fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright (c) 2012-2014 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include "QtVCardBirthdayField.h"

#include <QGridLayout>
#include <QHBoxLayout>
#include <boost/algorithm/string.hpp>

#include <Swift/QtUI/QtSwiftUtil.h>

namespace Swift {

QtVCardBirthdayField::QtVCardBirthdayField(QWidget* parent, QGridLayout *layout, bool editable) :
	QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Birthday"), false, false), birthdayLabel(NULL), birthdayDateEdit(NULL) {
	connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
}

QtVCardBirthdayField::~QtVCardBirthdayField() {
	disconnect(this, SLOT(handleEditibleChanged(bool)));
}

void QtVCardBirthdayField::setupContentWidgets() {
	birthdayLabel = new QLabel(this);
	birthdayLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
	birthdayDateEdit = new QDateEdit(this);
	birthdayDateEdit->setCalendarPopup(true);

	QHBoxLayout* birthdayLayout = new QHBoxLayout();
	birthdayLayout->addWidget(birthdayLabel);
	birthdayLayout->addWidget(birthdayDateEdit);

	getGridLayout()->addLayout(birthdayLayout, getGridLayout()->rowCount()-1, 2, Qt::AlignVCenter);

	getTagComboBox()->hide();
	birthdayLabel->hide();
	childWidgets << birthdayLabel << birthdayDateEdit;
}

bool QtVCardBirthdayField::isEmpty() const {
	return false;
}

void QtVCardBirthdayField::setBirthday(const boost::posix_time::ptime& birthday) {
	birthdayDateEdit->setDate(B2QDATE(birthday).date());
}

boost::posix_time::ptime QtVCardBirthdayField::getBirthday() const {
	return boost::posix_time::from_time_t(QDateTime(birthdayDateEdit->date()).toTime_t());
}

void QtVCardBirthdayField::handleEditibleChanged(bool isEditable) {
	birthdayLabel->setText(birthdayDateEdit->date().toString(Qt::DefaultLocaleLongDate));
	birthdayDateEdit->setVisible(isEditable);
	birthdayLabel->setVisible(!isEditable);
}

}