Skip to content

Commit

Permalink
implemented add/remove favorite path on FolderForm.(refs #78)
Browse files Browse the repository at this point in the history
  • Loading branch information
haraki committed Jun 12, 2019
1 parent 64f9316 commit 80c0d91
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
41 changes: 41 additions & 0 deletions folderform.cpp
Expand Up @@ -6,6 +6,7 @@
#include "folderform.h"
#include "ui_folderform.h"
#include "foldermodel.h"
#include "settings.h"

namespace Farman
{
Expand Down Expand Up @@ -299,6 +300,15 @@ void FolderForm::onDirectoryLoaded(const QString& path)
{
ui->folderView->setCursor(currentRootIndex);
}

if(Settings::getInstance()->searchFavoriteDirPath(path) >= 0)
{
ui->favoriteToolButton->setChecked(true);
}
else
{
ui->favoriteToolButton->setChecked(false);
}
}

void FolderForm::onLayoutChanged(const QList<QPersistentModelIndex> &parents/* = QList<QPersistentModelIndex>()*/, QAbstractItemModel::LayoutChangeHint hint/* = QAbstractItemModel::NoLayoutChangeHint*/)
Expand Down Expand Up @@ -385,6 +395,30 @@ int FolderForm::onSelectDir()
return setPath(dirPath);
}

int FolderForm::onFavoriteDir(bool marked)
{
const QModelIndex currentDirIndex = ui->folderView->rootIndex();
const QString currentPath = m_folderModel->filePath(currentDirIndex);
int index = Settings::getInstance()->searchFavoriteDirPath(currentPath);

if(marked)
{
if(index < 0)
{
Settings::getInstance()->insertFavoriteDirPath(currentPath);
}
}
else
{
if(index >= 0)
{
Settings::getInstance()->removeFavoriteDirPath(index);
}
}

return 0;
}

void FolderForm::refresh(bool clearSelected/* = false */)
{
if(clearSelected)
Expand Down Expand Up @@ -417,6 +451,13 @@ void FolderForm::on_selectFolderButton_clicked()
onSelectDir();
}

void FolderForm::on_favoriteToolButton_toggled(bool checked)
{
qDebug() << "FolderForm::on_favoriteToolButton_toggled() : " << checked;

onFavoriteDir(checked);
}

void FolderForm::emitCurrentChanged(const QFileInfo& newFileInfo, const QFileInfo& oldFileInfo)
{
emit currentChanged(newFileInfo, oldFileInfo);
Expand Down
3 changes: 3 additions & 0 deletions folderform.h
Expand Up @@ -67,6 +67,8 @@ class FolderForm : public QWidget
int onGoToChildDir();
int onGoToParentDir();
int onSelectDir();
int onFavoriteDir(bool marked);

void refresh(bool clearSelected = false);

Q_SIGNALS:
Expand All @@ -81,6 +83,7 @@ protected Q_SLOTS:

private Q_SLOTS:
void on_selectFolderButton_clicked();
void on_favoriteToolButton_toggled(bool checked);

void emitCurrentChanged(const QFileInfo& newFileInfo, const QFileInfo& oldFileInfo);
void emitFocusChanged(bool inFocus);
Expand Down
19 changes: 18 additions & 1 deletion folderform.ui
Expand Up @@ -34,6 +34,21 @@
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="favoriteToolButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/images/favorite_off.svg</normaloff>
<normalon>:/images/favorite_on.svg</normalon>:/images/favorite_off.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="folderPathEdit">
<property name="focusPolicy">
Expand Down Expand Up @@ -151,6 +166,8 @@
<tabstop>folderView</tabstop>
<tabstop>folderPathEdit</tabstop>
</tabstops>
<resources/>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 80c0d91

Please sign in to comment.