OSDN Git Service

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