OSDN Git Service

サムネイルモードの実装
[gefu/Gefu.git] / historydialog.cpp
1 #include "foldermodel.h"
2 #include "historydialog.h"
3 #include "ui_historydialog.h"
4
5 HistoryDialog::HistoryDialog(QWidget *parent) :
6     QDialog(parent),
7     ui(new Ui::HistoryDialog),
8     m_leftModel(NULL),
9     m_rightModel(NULL),
10     m_activeModel(NULL)
11 {
12     ui->setupUi(this);
13     resize(parent->width() * 0.8, height());
14 }
15
16 HistoryDialog::~HistoryDialog()
17 {
18     delete ui;
19 }
20
21 void HistoryDialog::setModel(const FolderModel *left, const FolderModel *right, FolderModel *active)
22 {
23     m_leftModel = left;
24     m_rightModel = right;
25     m_activeModel = active;
26
27     if (active == left) {
28         ui->radioLeft->click();
29     }
30     else {
31         ui->radioRight->click();
32     }
33
34     for (int n = left->history().size() - 1; n >= 0; --n) {
35         ui->listLeft->addItem(left->history().at(n));
36     }
37     for (int n = right->history().size() - 1; n >= 0; --n) {
38         ui->listRight->addItem(right->history().at(n));
39     }
40 }
41
42 void HistoryDialog::on_radioLeft_clicked()
43 {
44     ui->listRight->setVisible(false);
45     ui->listLeft->setVisible(true);
46 }
47
48 void HistoryDialog::on_radioRight_clicked()
49 {
50     ui->listLeft->setVisible(false);
51     ui->listRight->setVisible(true);
52 }
53
54 void HistoryDialog::accept()
55 {
56     QString path;
57     const FolderModel *selected;
58     if (ui->radioLeft->isChecked()) {
59         selected = m_leftModel;
60         path = ui->listLeft->currentItem()->text();
61     }
62     else {
63         selected = m_rightModel;
64         path = ui->listRight->currentItem()->text();
65     }
66
67     if (selected == m_activeModel) {
68         m_activeModel->setHistoryAt(path);
69     }
70     else {
71         m_activeModel->setRootPath(path);
72     }
73 }