OSDN Git Service

Ver0.15
[gefu/Gefu.git] / historydialog.cpp
1 #include "common.h"
2 #include "mainwindow.h"
3 #include "historydialog.h"
4 #include "ui_historydialog.h"
5
6 HistoryDialog::HistoryDialog(QWidget *parent) :
7     QDialog(parent),
8     ui(new Ui::HistoryDialog),
9     m_leftHistory(NULL),
10     m_rightHistory(NULL),
11     m_displaying(NULL)
12 {
13     ui->setupUi(this);
14     resize(parent->width() * 0.8, height());
15 }
16
17 HistoryDialog::~HistoryDialog()
18 {
19     delete ui;
20 }
21
22 void HistoryDialog::setHistory(const History *left, const History *right)
23 {
24     m_leftHistory = left;
25     m_rightHistory = right;
26 }
27
28 void HistoryDialog::setDefaultLeft(bool bLeft)
29 {
30     if (bLeft) {
31         ui->leftPane->setChecked(true);
32     }
33     else {
34         ui->rightPane->setChecked(true);
35     }
36 }
37
38 int HistoryDialog::selectedIndex() const
39 {
40     int row = ui->listWidget->currentIndex().row();
41     return m_displaying->size() - row - 1;
42 }
43
44 const QString HistoryDialog::selectedSide() const
45 {
46     if (ui->leftPane->isChecked()) {
47         return QString("Left");
48     }
49     else {
50         return QString("Right");
51     }
52 }
53
54 void HistoryDialog::showLeftHistory()
55 {
56     if (m_displaying != m_leftHistory) {
57         m_displaying = m_leftHistory;
58         showHistory();
59     }
60
61 }
62
63 void HistoryDialog::showRightHistory()
64 {
65     if (m_displaying != m_rightHistory) {
66         m_displaying = m_rightHistory;
67         showHistory();
68     }
69 }
70
71 void HistoryDialog::showHistory()
72 {
73     ui->listWidget->clear();
74     for (int n = 0; n < m_displaying->size(); n++) {
75         ui->listWidget->insertItem(0, m_displaying->at(n));
76     }
77     ui->listWidget->setCurrentRow(0);
78 }
79
80 void HistoryDialog::showEvent(QShowEvent *event)
81 {
82     Q_UNUSED(event);
83
84     if (ui->leftPane->isChecked()) {
85         showLeftHistory();
86     }
87     else {
88         showRightHistory();
89     }
90
91     connect(ui->leftPane, SIGNAL(clicked()), this, SLOT(showLeftHistory()));
92     connect(ui->rightPane, SIGNAL(clicked()), this, SLOT(showRightHistory()));
93     connect(ui->listWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
94 }