-
Notifications
You must be signed in to change notification settings - Fork 6
/
contactdialog.cpp
93 lines (82 loc) · 3.23 KB
/
contactdialog.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
#include "contactdialog.h"
#include "ui_contactdialog.h"
#include "goopal.h"
#include <QDebug>
#include "debug_log.h"
ContactDialog::ContactDialog(QWidget *parent) :
QDialog(parent),
previousColorRow(0),
ui(new Ui::ContactDialog)
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
ui->setupUi(this);
setWindowFlags(Qt::Popup);
ui->contactsTableWidget->setShowGrid(false);
ui->contactsTableWidget->setSelectionMode(QAbstractItemView::NoSelection);
ui->contactsTableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->contactsTableWidget->setFocusPolicy(Qt::NoFocus);
ui->contactsTableWidget->setColumnWidth(0,8);
ui->contactsTableWidget->setColumnWidth(1,160);
ui->contactsTableWidget->setColumnWidth(2,160);
ui->contactsTableWidget->setMouseTracking(true);
updateContactsList();
DLOG_QT_WALLET_FUNCTION_END;
}
ContactDialog::~ContactDialog()
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
delete ui;
DLOG_QT_WALLET_FUNCTION_END;
}
void ContactDialog::updateContactsList()
{
DLOG_QT_WALLET_FUNCTION_BEGIN;
//if( !Goopal::getInstance()->contactsFile->open(QIODevice::ReadOnly))
if (true)
{
qDebug() << "contact.dat not exist";
}
QString str = "";//QByteArray::fromBase64( Goopal::getInstance()->contactsFile->readAll());
QStringList strList = str.split(";");
strList.removeLast();
int size = strList.size();
ui->contactsTableWidget->setRowCount(size);
for( int i = 0; i < size; i++)
{
QString str2 = strList.at(i);
if( str2.size() - 1 == str2.indexOf("=")) // 如果没有备注,第一列为空,第二列显示地址,第三列为空
{
ui->contactsTableWidget->setItem(i,1, new QTableWidgetItem( str2.left( str2.indexOf("="))));
ui->contactsTableWidget->setItem(i,0, new QTableWidgetItem( ""));
ui->contactsTableWidget->setItem(i,2, new QTableWidgetItem( ""));
}
else // 如果有备注,第一列为空,第二列显示备注,第三列保存地址
{
ui->contactsTableWidget->setItem(i,1, new QTableWidgetItem( str2.mid( str2.indexOf("=") + 1)));
ui->contactsTableWidget->setItem(i,0, new QTableWidgetItem( ""));
ui->contactsTableWidget->setItem(i,2, new QTableWidgetItem( str2.left( str2.indexOf("="))));
}
}
// Goopal::getInstance()->contactsFile->close();
DLOG_QT_WALLET_FUNCTION_END;
}
void ContactDialog::on_contactsTableWidget_cellClicked(int row, int column)
{
if( ui->contactsTableWidget->item( row,2)->text().isEmpty())
{
emit contactSelected(ui->contactsTableWidget->item( row,1)->text());
}
else
{
emit contactSelected(ui->contactsTableWidget->item( row,2)->text());
}
close();
}
void ContactDialog::on_contactsTableWidget_cellEntered(int row, int column)
{
ui->contactsTableWidget->item(previousColorRow,0)->setBackgroundColor(QColor(255,255,255));
ui->contactsTableWidget->item(row,0)->setBackgroundColor(QColor(51,153,255));
ui->contactsTableWidget->item(previousColorRow,1)->setBackgroundColor(QColor(255,255,255));
ui->contactsTableWidget->item(row,1)->setBackgroundColor(QColor(51,153,255));
previousColorRow = row;
}