OSDN Git Service

Ver0.26
[gefu/Gefu.git] / historydialog.cpp
1 #include "foldermodel.h"
2 #include "historydialog.h"
3 #include "ui_historydialog.h"
4
5 ///////////////////////////////////////////////////////////////////////////////
6 /// \brief HistoryDialog::HistoryDialog
7 /// \param parent   親ウィジェット
8 ///
9 /// コンストラクタ
10 ///
11 HistoryDialog::HistoryDialog(QWidget *parent) :
12     QDialog(parent),
13     ui(new Ui::HistoryDialog),
14     m_leftModel(NULL),
15     m_rightModel(NULL),
16     m_activeModel(NULL)
17 {
18     ui->setupUi(this);
19     resize(parent->width() * 0.8, height());
20
21     connect(ui->listLeft, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
22     connect(ui->listRight, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(accept()));
23 }
24
25 ///////////////////////////////////////////////////////////////////////////////
26 /// \brief HistoryDialog::~HistoryDialog
27 ///
28 /// デストラクタ
29 ///
30 HistoryDialog::~HistoryDialog()
31 {
32     delete ui;
33 }
34
35 ///////////////////////////////////////////////////////////////////////////////
36 /// \brief HistoryDialog::setModel
37 /// \param left     左パネルのモデル
38 /// \param right    右パネルのモデル
39 /// \param active   アクティブモデル
40 ///
41 /// モデルを設定します。
42 ///
43 void HistoryDialog::setModel(const FolderModel *left, const FolderModel *right, FolderModel *active)
44 {
45     m_leftModel = left;
46     m_rightModel = right;
47     m_activeModel = active;
48
49     if (active == left) {
50         ui->radioLeft->click();
51     }
52     else {
53         ui->radioRight->click();
54     }
55
56     for (int n = left->history().size() - 1; n >= 0; --n) {
57         ui->listLeft->addItem(left->history().at(n));
58     }
59     for (int n = right->history().size() - 1; n >= 0; --n) {
60         ui->listRight->addItem(right->history().at(n));
61     }
62 }
63
64 ///////////////////////////////////////////////////////////////////////////////
65 /// \brief HistoryDialog::on_radioLeft_clicked
66 ///
67 /// 左パネルラジオボタンクリック時の処理を行います。
68 ///
69 void HistoryDialog::on_radioLeft_clicked()
70 {
71     ui->listRight->setVisible(false);
72     ui->listLeft->setVisible(true);
73 }
74
75 ///////////////////////////////////////////////////////////////////////////////
76 /// \brief HistoryDialog::on_radioRight_clicked
77 ///
78 /// 右パネルラジオボタンクリック時の処理を行います。
79 ///
80 void HistoryDialog::on_radioRight_clicked()
81 {
82     ui->listLeft->setVisible(false);
83     ui->listRight->setVisible(true);
84 }
85
86 ///////////////////////////////////////////////////////////////////////////////
87 /// \brief HistoryDialog::accept
88 ///
89 /// OKボタンクリック時の処理を行います。
90 ///
91 void HistoryDialog::accept()
92 {
93     QString path;
94     const FolderModel *selected;
95     if (ui->radioLeft->isChecked()) {
96         selected = m_leftModel;
97         path = ui->listLeft->currentItem()->text();
98     }
99     else {
100         selected = m_rightModel;
101         path = ui->listRight->currentItem()->text();
102     }
103
104     if (selected == m_activeModel) {
105         m_activeModel->setHistoryAt(path);
106     }
107     else {
108         m_activeModel->setRootPath(path);
109     }
110
111     QDialog::accept();
112 }