OSDN Git Service

Ver0.22
[gefu/Gefu.git] / panel.cpp
1 #include "foldermodel.h"
2 #include "folderview.h"
3 #include "mainwindow.h"
4 #include "preferences.h"
5 #include "panel.h"
6 #include "ui_panel.h"
7
8 #include <QDebug>
9
10 ///////////////////////////////////////////////////////////////////////////////
11 /// \brief Panel::Panel
12 /// \param parent   親ウィジェット
13 ///
14 /// コンストラクタ
15 ///
16 Panel::Panel(QWidget *parent) :
17     QWidget(parent),
18     ui(new Ui::Panel)
19 {
20     ui->setupUi(this);
21     ui->imageView->setVisible(false);
22     ui->textView->setVisible(false);
23 }
24
25 ///////////////////////////////////////////////////////////////////////////////
26 /// \brief Panel::~Panel
27 ///
28 /// デストラクタ
29 ///
30 Panel::~Panel()
31 {
32     delete ui;
33 }
34
35 ///////////////////////////////////////////////////////////////////////////////
36 /// \brief Panel::folderPanel
37 /// \return フォルダパネルを返します。
38 ///
39 FolderPanel *Panel::folderPanel() const
40 {
41     return ui->folderPanel;
42 }
43
44 ///////////////////////////////////////////////////////////////////////////////
45 /// \brief Panel::initialize
46 /// \param w メインウィンドウオブジェクト
47 ///
48 /// パネルを初期化します。
49 ///
50 void Panel::initialize(MainWindow *w)
51 {
52     qDebug() << "Panel::initialize()";
53
54     ui->imageView->initialize(w);
55     ui->folderPanel->initialize(w);
56     ui->textView->initialize(w);
57 }
58
59 ///////////////////////////////////////////////////////////////////////////////
60 /// \brief Panel::model
61 /// \return フォルダモデルを返します。
62 ///
63 FolderModel *Panel::model() const
64 {
65     return ui->folderPanel->model();
66 }
67
68 ///////////////////////////////////////////////////////////////////////////////
69 /// \brief Panel::setModel
70 /// \param m    設定するモデル
71 ///
72 /// モデルを設定します。
73 ///
74 void Panel::setModel(FolderModel *m)
75 {
76     qDebug() << "Panel::setModel()";
77
78     ui->folderPanel->setModel(m);
79 }
80
81 ///////////////////////////////////////////////////////////////////////////////
82 /// \brief Panel::setViewItem
83 /// \param index    設定するアイテムのインデックス
84 ///
85 /// ビューにアイテムを設定し、表示します。
86 ///
87 void Panel::setViewItem(const QModelIndex &index)
88 {
89     qDebug() << "Panel::setViewItem()" << index;
90
91     if (!index.isValid()) {
92         ui->imageView->setVisible(false);
93         ui->textView->setVisible(false);
94         ui->folderPanel->setVisible(true);
95         return;
96     }
97
98     const FolderModel *m = static_cast<const FolderModel*>(index.model());
99     QString path = m->filePath(index);
100     if (m->isDir(index)) {
101         model()->setRootPath(path);
102         ui->imageView->setVisible(false);
103         ui->textView->setVisible(false);
104         ui->folderPanel->setVisible(true);
105         return;
106     }
107
108     QPixmap pixmap(path);
109     if (!pixmap.isNull()) {
110         ui->imageView->setSource(pixmap);
111         ui->folderPanel->setVisible(false);
112         ui->textView->setVisible(false);
113         ui->imageView->setVisible(true);
114         return;
115     }
116
117     QFile file(path);
118     QByteArray data;
119     if (file.open(QIODevice::ReadOnly)) {
120         data = file.readAll();
121         file.close();
122     }
123
124     ui->textView->setSource(data);
125     ui->folderPanel->setVisible(false);
126     ui->imageView->setVisible(false);
127     ui->textView->setVisible(true);
128 }
129
130 ///////////////////////////////////////////////////////////////////////////////
131 /// \brief Panel::updateAppearance
132 ///
133 /// 外観を変更します。
134 ///
135 void Panel::updateAppearance(const Preferences &prefs)
136 {
137     qDebug() << "Panel::updateAppearance()";
138
139     QPalette pal;
140
141     pal = ui->imageView->palette();
142     pal.setColor(QPalette::Base, prefs.getImageViewBgColor());
143     ui->imageView->setPalette(pal);
144
145     pal = ui->textView->palette();
146     pal.setColor(QPalette::Base, prefs.getTextViewBgColor());
147     pal.setColor(QPalette::Text, prefs.getTextViewFgColor());
148     ui->textView->setPalette(pal);
149     ui->textView->setFont(prefs.getTextViewFont());
150
151     ui->folderPanel->updateAppearance(prefs);
152 }
153
154 ///////////////////////////////////////////////////////////////////////////////
155 /// \brief Panel::visibleView
156 /// \return 可視状態のビューを返します。
157 ///
158 QWidget *Panel::visibleView() const
159 {
160     if (ui->textView->isVisible()) {
161         return ui->textView;
162     }
163     if (ui->imageView->isVisible()) {
164         return ui->imageView;
165     }
166     if (ui->folderPanel->isVisible()) {
167         return ui->folderPanel->itemView();
168     }
169
170     qDebug() << ">>>>>>>>>> visibleView() Logic error <<<<<<<<<<";
171     return NULL;
172 }