-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathaccountcard.cpp
157 lines (130 loc) · 3.8 KB
/
accountcard.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "accountcard.h"
#include <QDebug>
AccountCard::AccountCard( MagCard *_card ) {
QLabel *label;
layout = new QVBoxLayout;
setLayout( layout );
#ifdef Q_WS_MAEMO_5
smallFont.setPointSize( 32 );
medFont.setPointSize( 32 );
#else
smallFont.setPointSize( 12 );
medFont.setPointSize( 16 );
#endif
accountNumber = new QLabel;
layout->addWidget( accountNumber, 1, Qt::AlignHCenter );
accountHolder = new QLabel;
accountHolder->setFont( smallFont );
layout->addWidget( accountHolder, 1, Qt::AlignHCenter );
label = new QLabel( "Expiration Date" );
label->setFont( smallFont );
vboxExpirationDate = new QVBoxLayout;
vboxExpirationDate->addWidget( label, 1, Qt::AlignHCenter );
expirationDate = new QLabel;
expirationDate->setFont( smallFont );
vboxExpirationDate->addWidget( expirationDate, 1, Qt::AlignHCenter );
vWidgetExpirationDate = new QWidget;
vWidgetExpirationDate->setLayout( vboxExpirationDate );
label = new QLabel( "Issuer" );
label->setFont( smallFont );
vboxAccountIssuer = new QVBoxLayout;
vboxAccountIssuer->addWidget( label, 1, Qt::AlignHCenter );
accountIssuer = new QLabel;
accountIssuer->setFont( smallFont );
vboxAccountIssuer->addWidget( accountIssuer, 1, Qt::AlignHCenter );
vWidgetAccountIssuer = new QWidget;
vWidgetAccountIssuer->setLayout( vboxAccountIssuer );
vFlexBox = new QVBoxLayout;
vFlexBox->addWidget( vWidgetExpirationDate );
vFlexBox->addWidget( vWidgetAccountIssuer );
hFlexBox = new QHBoxLayout;
hFlexBox->addWidget( vWidgetExpirationDate );
hFlexBox->addWidget( vWidgetAccountIssuer );
layout->addLayout( vFlexBox );
//Setup the auto-reorientation
orientation = UNSET;
reorient();
installEventFilter( this );
if( _card ) {
card = _card;
showData();
};
}
void AccountCard::reorient() {
#ifdef Q_OS_SYMBIAN
// for some reason, this works only on symbian, and the else works on everything but symbian
QRect geometry = QApplication::desktop()->screenGeometry();
#else
QSize geometry = size();
#endif
if( geometry.width() > geometry.height() ) {
//landscape
if( orientation != LANDSCAPE ) {
qDebug() << "Landscape Mode";
#ifdef Q_WS_MAEMO_5
accountNumberFont.setPointSize( 48 );
#else
accountNumberFont.setPointSize( 18 );
#endif
accountNumber->setFont( accountNumberFont );
layout->removeItem( layout->itemAt( 2 ) );
hFlexBox->setParent( 0 );
layout->addLayout( hFlexBox );
orientation = LANDSCAPE;
}
} else {
//portrait
if( orientation != PORTRAIT ) {
qDebug() << "Portrait Mode";
#ifdef Q_WS_MAEMO_5
accountNumberFont.setPointSize( 32 );
#else
accountNumberFont.setPointSize( 12 );
#endif
accountNumber->setFont( accountNumberFont );
layout->removeItem( layout->itemAt( 2 ) );
vFlexBox->setParent( 0 );
layout->addLayout( vFlexBox );
orientation = PORTRAIT;
}
}
}
bool AccountCard::eventFilter( QObject *obj, QEvent *event ) {
if( event->type() == QEvent::Resize )
reorient();
return QObject::eventFilter( obj, event );
}
void AccountCard::setCard( MagCard *_card ) {
card = _card;
if( card )
showData();
}
void AccountCard::showData() {
QString tmpStr;
/* Account Number */
tmpStr = card->accountNumber;
if( card->type == MagCard::CARD_AMEX ) {
tmpStr.insert( 10, ' ' );
tmpStr.insert( 4, ' ' );
} else {
tmpStr.insert( 12, ' ' );
tmpStr.insert( 8, ' ' );
tmpStr.insert( 4, ' ' );
}
accountNumber->setText( tmpStr );
if( !card->accountHolder.isEmpty() )
accountHolder->setText( card->accountHolder );
else {
accountHolder->hide();
accountHolder->clear();
}
/* Expiration Date */
tmpStr = card->expirationDate.toString( "MMM dd, yyyy" );
if( card->expirationDate < QDate::currentDate() ) {
tmpStr.prepend( "<font color=\"red\">" );
tmpStr.append( "</font>" );
}
expirationDate->setText( tmpStr );
/* Account Issuer */
accountIssuer->setText( card->accountIssuer );
}