1 #include "filereadworker.h"
2 #include "foldermodel.h"
3 #include "folderview.h"
7 #include "mainwindow.h"
8 #include "preferences.h"
16 ///////////////////////////////////////////////////////////////////////////////
17 /// \brief Panel::Panel
18 /// \param parent 親ウィジェット
22 Panel::Panel(QWidget *parent) :
28 ui->progressBar->setVisible(false);
29 ui->scrollArea->setVisible(false);
32 ///////////////////////////////////////////////////////////////////////////////
33 /// \brief Panel::~Panel
42 ///////////////////////////////////////////////////////////////////////////////
43 /// \brief Panel::folderPanel
44 /// \return フォルダパネルを返します。
46 FolderPanel *Panel::folderPanel() const
48 return ui->folderPanel;
51 ///////////////////////////////////////////////////////////////////////////////
52 /// \brief Panel::initialize
53 /// \param w メインウィンドウオブジェクト
57 void Panel::initialize(MainWindow *w)
59 qDebug() << "Panel::initialize()";
61 ui->folderPanel->initialize(w);
62 ui->progressBar->installEventFilter(w);
63 ui->scrollArea->installEventFilter(w);
66 ///////////////////////////////////////////////////////////////////////////////
67 /// \brief Panel::model
68 /// \return フォルダモデルを返します。
70 FolderModel *Panel::model() const
72 return ui->folderPanel->model();
75 ///////////////////////////////////////////////////////////////////////////////
76 /// \brief Panel::setModel
81 void Panel::setModel(FolderModel *m)
83 qDebug() << "Panel::setModel()";
85 ui->folderPanel->setModel(m);
88 ///////////////////////////////////////////////////////////////////////////////
89 /// \brief Panel::setViewItem
90 /// \param index 設定するアイテムのインデックス
92 /// ビューにアイテムを設定し、表示します。
94 void Panel::setViewItem(const QModelIndex &index)
96 qDebug() << "Panel::setViewItem()" << index;
102 ui->progressBar->setVisible(false);
103 ui->scrollArea->setVisible(false);
104 ui->folderPanel->setVisible(false);
105 if (!index.isValid()) {
106 ui->folderPanel->setVisible(true);
110 const FolderModel *m = static_cast<const FolderModel*>(index.model());
111 QString path = m->filePath(index);
112 if (m->isDir(index)) {
113 model()->setRootPath(path);
114 ui->folderPanel->setVisible(true);
118 m_worker = new FileReadWorker();
119 connect(m_worker, SIGNAL(size(int)), ui->progressBar, SLOT(setMaximum(int)));
120 connect(m_worker, SIGNAL(progress(int)), ui->progressBar, SLOT(setValue(int)));
121 connect(m_worker, SIGNAL(resultReady(QByteArray)), this, SLOT(onReady(QByteArray)));
122 ui->progressBar->setValue(0);
123 ui->progressBar->setVisible(true);
125 m_worker->open(path);
129 ///////////////////////////////////////////////////////////////////////////////
130 /// \brief Panel::updateAppearance
134 void Panel::updateAppearance(const Preferences &prefs)
136 qDebug() << "Panel::updateAppearance()";
140 pal = this->palette();
141 pal.setColor(this->backgroundRole(), prefs.folderViewBgColor(objectName() == "FPanel"));
142 this->setAutoFillBackground(true);
143 this->setPalette(pal);
145 ui->folderPanel->updateAppearance(prefs);
147 model()->updateAppearance(prefs);
151 ///////////////////////////////////////////////////////////////////////////////
152 /// \brief Panel::visibleView
153 /// \return 可視状態のビューを返します。
155 QWidget *Panel::visibleView() const
157 if (ui->scrollArea->isVisible()) {
158 return ui->scrollArea/*->widget()*/;
160 if (ui->folderPanel->isVisible()) {
161 return ui->folderPanel->itemView();
163 if (ui->progressBar->isVisible()) {
164 return ui->progressBar;
167 qDebug() << ">>>>>>>>>> visibleView() Logic error <<<<<<<<<<";
171 ///////////////////////////////////////////////////////////////////////////////
172 /// \brief Panel::onReady
173 /// \param data ファイルの内容
177 void Panel::onReady(const QByteArray &data)
180 if (parent()->objectName() == "splitter") {
181 mainWnd = static_cast<MainWindow*>(parent()->parent()->parent());
184 mainWnd = static_cast<MainWindow*>(parent()->parent());
186 ui->progressBar->setVisible(false);
187 ui->folderPanel->setVisible(false);
188 ui->scrollArea->setVisible(true);
189 QWidget *w = ui->scrollArea->widget();
195 if (pixmap.loadFromData(data)) {
196 ImageView *view = new ImageView(ui->scrollArea);
197 connect(view, SIGNAL(statusChanged(QString)), mainWnd, SLOT(view_statusChanged(QString)));
198 view->installEventFilter(mainWnd);
199 view->setData(pixmap);
200 emit showed(ui->scrollArea);
204 std::string code = detectCode(data.left(1024));
205 QTextCodec *codec = QTextCodec::codecForName(code.c_str());
207 TextView *view = new TextView(ui->scrollArea);
208 connect(view, SIGNAL(copyAvailable(bool)), mainWnd, SLOT(view_copyAvailable(bool)));
209 connect(view, SIGNAL(statusChanged(QString)), mainWnd, SLOT(view_statusChanged(QString)));
210 view->installEventFilter(mainWnd);
212 emit showed(ui->scrollArea);
216 HexView *view = new HexView(ui->scrollArea);
217 connect(view, SIGNAL(copyAvailable(bool)), mainWnd, SLOT(view_copyAvailable(bool)));
218 connect(view, SIGNAL(statusChanged(QString)), mainWnd, SLOT(view_statusChanged(QString)));
219 view->installEventFilter(mainWnd);
221 emit showed(ui->scrollArea);