Skip to content
Permalink
Browse files

implemented add/remove favorite path on FolderForm.(refs #78)

  • Loading branch information...
haraki committed Jun 12, 2019
1 parent 8bac4a2 commit 3afe58eccab2bc605e9c63438962b958eb36c310
Showing with 62 additions and 1 deletion.
  1. +41 −0 folderform.cpp
  2. +3 −0 folderform.h
  3. +18 −1 folderform.ui
@@ -6,6 +6,7 @@
#include "folderform.h"
#include "ui_folderform.h"
#include "foldermodel.h"
#include "settings.h"

namespace Farman
{
@@ -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*/)
@@ -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)
@@ -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);
@@ -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:
@@ -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);
@@ -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">
@@ -151,6 +166,8 @@
<tabstop>folderView</tabstop>
<tabstop>folderPathEdit</tabstop>
</tabstops>
<resources/>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 3afe58e

Please sign in to comment.
You can’t perform that action at this time.