mirror of
https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio.git
synced 2025-01-24 07:38:15 +00:00
Introduce favorite list
Add a way to doubleclick and show a context menu in the favorite list.
This commit is contained in:
parent
9390e492ef
commit
0306795370
11 changed files with 276 additions and 23 deletions
|
@ -30,6 +30,7 @@ HEADERS += src/PluginsList.h \
|
|||
src/CustomSettings.h \
|
||||
src/SeekSlider.h \
|
||||
src/CustomMenuAction.h \
|
||||
src/FavoritesList.h \
|
||||
src/Logger.h
|
||||
|
||||
SOURCES += src/main.cpp \
|
||||
|
@ -43,4 +44,5 @@ SOURCES += src/main.cpp \
|
|||
src/CustomSettings.cpp \
|
||||
src/SeekSlider.cpp \
|
||||
src/CustomMenuAction.cpp \
|
||||
src/FavoritesList.cpp \
|
||||
src/Logger.cpp
|
|
@ -24,6 +24,22 @@ CustomSettings::lastIODirectory ()
|
|||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
CustomSettings::saveFavoriteList (const QStringList &favorite_list)
|
||||
{
|
||||
QSettings settings (COMPANY_NAME, APPLICATION_NAME);
|
||||
settings.setValue("favorite_list", QVariant::fromValue(favorite_list));
|
||||
}
|
||||
|
||||
QStringList
|
||||
CustomSettings::loadFavoriteList ()
|
||||
{
|
||||
QSettings settings (COMPANY_NAME, APPLICATION_NAME);
|
||||
QStringList data = settings.value("favorite_list").value<QStringList>();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void
|
||||
CustomSettings::saveMainWindowGeometry (const QByteArray &geometry)
|
||||
{
|
||||
|
|
|
@ -2,12 +2,15 @@
|
|||
#define CUSTOM_SETTINGS_H_
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QByteArray>
|
||||
|
||||
namespace CustomSettings
|
||||
{
|
||||
void saveLastIODirectory(const QString &name);
|
||||
QString lastIODirectory();
|
||||
void saveFavoriteList(const QStringList &name);
|
||||
QStringList loadFavoriteList();
|
||||
|
||||
void saveGstDebugString(const QString &name);
|
||||
QString lastGstDebugString();
|
||||
|
|
64
src/FavoritesList.cpp
Normal file
64
src/FavoritesList.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include "FavoritesList.h"
|
||||
#include "CustomSettings.h"
|
||||
#include "Logger.h"
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
|
||||
FavoritesList::FavoritesList (QWidget *pwgt)
|
||||
: QListWidget (pwgt)
|
||||
{
|
||||
loadFavorites();
|
||||
}
|
||||
|
||||
FavoritesList::~FavoritesList ()
|
||||
{
|
||||
}
|
||||
|
||||
int FavoritesList::isFavorite(const QString& plugin_name)
|
||||
{
|
||||
for (int i = 0; i < this->count (); i++) {
|
||||
QListWidgetItem *pitem = this->item (i);
|
||||
if (pitem->text () == plugin_name)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void FavoritesList::addFavorite (const QString& plugin_name)
|
||||
{
|
||||
if (isFavorite(plugin_name) == -1)
|
||||
this->addItem(plugin_name);
|
||||
saveFavorites();
|
||||
}
|
||||
|
||||
void FavoritesList::removeFavorite (const QString& plugin_name)
|
||||
{
|
||||
int favorite = isFavorite(plugin_name);
|
||||
if (favorite != -1)
|
||||
delete this->takeItem(this->row(this->item(favorite)));
|
||||
saveFavorites();
|
||||
}
|
||||
|
||||
void FavoritesList::loadFavorites()
|
||||
{
|
||||
QStringList favorites = CustomSettings::loadFavoriteList();
|
||||
foreach (QString plugin_name, favorites) {
|
||||
this->addItem(plugin_name);
|
||||
}
|
||||
LOG_INFO("Just load favorites");
|
||||
}
|
||||
|
||||
void FavoritesList::saveFavorites()
|
||||
{
|
||||
QStringList favorites;
|
||||
|
||||
for (int i = 0; i < this->count (); i++) {
|
||||
QListWidgetItem *pitem = this->item (i);
|
||||
favorites << pitem->text();
|
||||
}
|
||||
LOG_INFO("About to save favorites");
|
||||
CustomSettings::saveFavoriteList(favorites);
|
||||
}
|
24
src/FavoritesList.h
Normal file
24
src/FavoritesList.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef FAVORITES_LIST_H_
|
||||
#define FAVORITES_LIST_H_
|
||||
|
||||
#include <QString>
|
||||
#include <QListWidgetItem>
|
||||
|
||||
class FavoritesList: public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FavoritesList(QWidget *pwgt = NULL);
|
||||
~FavoritesList();
|
||||
|
||||
int isFavorite(const QString& plugin_name);
|
||||
|
||||
void addFavorite(const QString& plugin_name);
|
||||
void removeFavorite(const QString& plugin_name);
|
||||
|
||||
private:
|
||||
void loadFavorites();
|
||||
void saveFavorites();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -43,13 +43,11 @@ GraphManager::GraphManager ()
|
|||
m_pGraph = gst_pipeline_new ("pipeline");
|
||||
GST_DEBUG_CATEGORY_INIT(pipeviz_debug, "pipeviz", 0, "Pipeline vizualizer");
|
||||
|
||||
m_pluginsList = new PluginsList ();
|
||||
GST_WARNING("init");
|
||||
}
|
||||
|
||||
GraphManager::~GraphManager ()
|
||||
{
|
||||
delete m_pluginsList;
|
||||
}
|
||||
|
||||
QString
|
||||
|
|
|
@ -102,7 +102,6 @@ public:
|
|||
double GetPosition();
|
||||
bool SetPosition(double);
|
||||
|
||||
PluginsList* getPluginsList() { return m_pluginsList;}
|
||||
bool CanConnect(const char *srcName,const char *srcPadName, const char *destName, bool noANY = true);
|
||||
|
||||
|
||||
|
@ -113,7 +112,6 @@ public:
|
|||
QString getPadCaps(ElementInfo* elementInfo, PadInfo* padInfo, ePadCapsSubset subset, bool afTruncated = false);
|
||||
|
||||
GstElement *m_pGraph;
|
||||
PluginsList *m_pluginsList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "MainWindow.h"
|
||||
|
||||
#include "PluginsList.h"
|
||||
#include "FavoritesList.h"
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
|
@ -168,8 +169,15 @@ m_pGraph (new GraphManager)
|
|||
setCentralWidget (pscroll);
|
||||
m_pstatusBar = new QStatusBar;
|
||||
setStatusBar (m_pstatusBar);
|
||||
m_pluginListDlg = new PluginsListDialog (m_pGraph->getPluginsList (), this);
|
||||
m_pluginListDlg = new PluginsListDialog (this);
|
||||
m_pluginListDlg->setModal (false);
|
||||
|
||||
connect(m_pluginListDlg, SIGNAL(signalAddPluginToFav(const QString&)),
|
||||
this, SLOT(AddPluginToFavorites(const QString&)));
|
||||
connect(m_pluginListDlg, SIGNAL(signalRemPluginToFav(const QString&)),
|
||||
this, SLOT(RemovePluginToFavorites(const QString&)));
|
||||
|
||||
|
||||
restoreGeometry (CustomSettings::mainWindowGeometry ());
|
||||
createDockWindows();
|
||||
|
||||
|
@ -184,6 +192,7 @@ m_pGraph (new GraphManager)
|
|||
|
||||
void MainWindow::createDockWindows()
|
||||
{
|
||||
/* create the log list window */
|
||||
QDockWidget *dock = new QDockWidget(tr("logs"), this);
|
||||
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||
m_logList = new QListWidget(dock);
|
||||
|
@ -191,6 +200,58 @@ void MainWindow::createDockWindows()
|
|||
addDockWidget(Qt::BottomDockWidgetArea, dock);
|
||||
m_menu->addAction(dock->toggleViewAction());
|
||||
|
||||
/*create the favorite list window */
|
||||
dock = new QDockWidget(tr("favorite list"), this);
|
||||
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||
m_favoriteList = new FavoritesList(dock);
|
||||
dock->setWidget(m_favoriteList);
|
||||
addDockWidget(Qt::RightDockWidgetArea, dock);
|
||||
m_menu->addAction(dock->toggleViewAction());
|
||||
connect(m_favoriteList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(onFavoriteListItemDoubleClicked(QListWidgetItem*)));
|
||||
m_favoriteList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(m_favoriteList,SIGNAL(customContextMenuRequested(const QPoint &)),
|
||||
this,SLOT(ProvideContextMenu(const QPoint &)));
|
||||
|
||||
}
|
||||
FavoritesList* MainWindow::getFavoritesList()
|
||||
{
|
||||
return m_favoriteList;
|
||||
}
|
||||
|
||||
void MainWindow::AddPluginToFavorites(const QString& plugin_name)
|
||||
{
|
||||
m_favoriteList->addFavorite(plugin_name);
|
||||
}
|
||||
|
||||
void MainWindow::RemovePluginToFavorites(const QString& plugin_name)
|
||||
{
|
||||
m_favoriteList->removeFavorite(plugin_name);
|
||||
}
|
||||
|
||||
void MainWindow::onFavoriteListItemDoubleClicked(QListWidgetItem* pitem)
|
||||
{
|
||||
LOG_INFO("onFavoriteListItemDoubleClicked: " + pitem->text());
|
||||
if (!m_pGraph
|
||||
|| !m_pGraph->AddPlugin (pitem->text ().toStdString ().c_str (), NULL)) {
|
||||
QMessageBox::warning (
|
||||
this, "Plugin addition problem",
|
||||
"Plugin `" + pitem->text () + "` insertion was FAILED");
|
||||
LOG_INFO("Plugin `" + pitem->text () + "` insertion FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::ProvideContextMenu(const QPoint &pos)
|
||||
{
|
||||
QPoint item = m_favoriteList->mapToGlobal(pos);
|
||||
QMenu submenu;
|
||||
submenu.addAction("Delete");
|
||||
QAction* rightClickItem = submenu.exec(item);
|
||||
if (rightClickItem && rightClickItem->text().contains("Delete") ) {
|
||||
LOG_INFO("Delete item: " + m_favoriteList->currentItem()->text());
|
||||
RemovePluginToFavorites(m_favoriteList->currentItem()->text());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::InsertLogLine(const QString& line, int category)
|
||||
|
@ -268,7 +329,6 @@ MainWindow::OpenMediaUri ()
|
|||
std::vector<ElementInfo> info = m_pGraph->GetInfo ();
|
||||
m_pGraphDisplay->update (info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
class GraphDisplay;
|
||||
class PluginsListDialog;
|
||||
|
||||
class FavoritesList;
|
||||
|
||||
class MainWindow: public QMainWindow
|
||||
{
|
||||
|
@ -28,6 +28,7 @@ public:
|
|||
~MainWindow();
|
||||
|
||||
static MainWindow& instance();
|
||||
FavoritesList* getFavoritesList();
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *);
|
||||
|
@ -37,6 +38,8 @@ public slots:
|
|||
void InsertLogLine(const QString& line, int category);
|
||||
void AddPlugin();
|
||||
void ClearGraph();
|
||||
void AddPluginToFavorites(const QString& plugin_name);
|
||||
void RemovePluginToFavorites(const QString& plugin_name);
|
||||
|
||||
private slots:
|
||||
void OpenMediaFile();
|
||||
|
@ -53,6 +56,10 @@ private slots:
|
|||
|
||||
void About();
|
||||
|
||||
|
||||
void onFavoriteListItemDoubleClicked(QListWidgetItem* item);
|
||||
void ProvideContextMenu(const QPoint &pos);
|
||||
|
||||
private:
|
||||
QSharedPointer<GraphManager> m_pGraph;
|
||||
|
||||
|
@ -65,6 +72,7 @@ private:
|
|||
PluginsListDialog *m_pluginListDlg;
|
||||
QMenu *m_menu;
|
||||
QListWidget* m_logList;
|
||||
FavoritesList* m_favoriteList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "PluginsList.h"
|
||||
#include "MainWindow.h"
|
||||
#include "FavoritesList.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -6,6 +8,7 @@
|
|||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QScrollArea>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QEvent>
|
||||
#include <QKeyEvent>
|
||||
|
@ -29,10 +32,17 @@ plugins_sort_cb (gconstpointer a, gconstpointer b)
|
|||
}
|
||||
|
||||
PluginsList::PluginsList ()
|
||||
:m_pluginsList(NULL)
|
||||
{
|
||||
init ();
|
||||
}
|
||||
|
||||
PluginsList& PluginsList::instance()
|
||||
{
|
||||
static PluginsList instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
PluginsList::~PluginsList ()
|
||||
{
|
||||
//g_list_free(m_pluginsList);
|
||||
|
@ -111,12 +121,17 @@ PluginsList::getPluginListByCaps (GstPadDirection direction, GstCaps* caps)
|
|||
return caps_plugins_list;
|
||||
}
|
||||
|
||||
PluginsListDialog::PluginsListDialog (PluginsList* pluginList, QWidget *pwgt,
|
||||
|
||||
#define kBUTTON_FAVORITE_ADD "Add to favorites"
|
||||
#define kBUTTON_FAVORITE_REMOVE "Remove from favorites"
|
||||
|
||||
PluginsListDialog::PluginsListDialog (QWidget *pwgt,
|
||||
Qt::WindowFlags f)
|
||||
: QDialog (pwgt, f),
|
||||
m_pPluginsList (pluginList),
|
||||
m_pGraph (NULL)
|
||||
{
|
||||
m_main = (MainWindow*)pwgt;
|
||||
|
||||
m_pPlugins = new QListWidget;
|
||||
m_pPlugins->setSortingEnabled (true);
|
||||
m_plblInfo = new QLabel;
|
||||
|
@ -139,9 +154,14 @@ m_pGraph (NULL)
|
|||
QLineEdit *ple = new QLineEdit;
|
||||
phblayFind->addWidget (ple);
|
||||
phblayFind->addStretch (1);
|
||||
|
||||
ple->setPlaceholderText ("Search...");
|
||||
|
||||
m_favoriteListButton = new QPushButton(kBUTTON_FAVORITE_ADD);
|
||||
phblayFind->addWidget (m_favoriteListButton);
|
||||
//phblayFind->addStretch (1);
|
||||
QObject::connect (m_favoriteListButton, SIGNAL (clicked ()), this,
|
||||
SLOT (favoritesClicked ()));
|
||||
|
||||
QVBoxLayout *pvblay = new QVBoxLayout;
|
||||
pvblay->addLayout (phblayFind);
|
||||
pvblay->addLayout (phblay);
|
||||
|
@ -156,26 +176,33 @@ m_pGraph (NULL)
|
|||
QObject::connect(m_pPlugins, SIGNAL(itemDoubleClicked (QListWidgetItem *)),
|
||||
this, SLOT(insert(QListWidgetItem *)));
|
||||
|
||||
QObject::connect(ple, SIGNAL(textChanged(const QString &)), this, SLOT(filterPlagins(const QString &)));
|
||||
QObject::connect(m_pPlugins,SIGNAL(customContextMenuRequested(const QPoint &)),
|
||||
this,SLOT(ProvideContextMenu(const QPoint &)));
|
||||
|
||||
QObject::connect(ple, SIGNAL(textChanged(const QString &)), this, SLOT(filterPlugins(const QString &)));
|
||||
|
||||
installEventFilter (this);
|
||||
}
|
||||
|
||||
PluginsListDialog::~PluginsListDialog ()
|
||||
{
|
||||
if (m_pPluginsList)
|
||||
delete m_pPluginsList;
|
||||
}
|
||||
|
||||
void
|
||||
PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous)
|
||||
{
|
||||
|
||||
Q_UNUSED(previous);
|
||||
LOG_INFO("Show Info: " + pitem->text ());
|
||||
m_plblInfo->clear ();
|
||||
QString descr;
|
||||
descr += "<b>Plugin details</b><hr>";
|
||||
|
||||
if (m_main->getFavoritesList()->isFavorite( pitem->text ()) != -1)
|
||||
m_favoriteListButton->setText(kBUTTON_FAVORITE_REMOVE);
|
||||
else
|
||||
m_favoriteListButton->setText(kBUTTON_FAVORITE_ADD);
|
||||
|
||||
GstElementFactory *factory = gst_element_factory_find (
|
||||
pitem->text ().toStdString ().c_str ());
|
||||
if (!factory) {
|
||||
|
@ -283,12 +310,11 @@ PluginsListDialog::eventFilter (QObject *obj, QEvent *event)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return QDialog::eventFilter (obj, event);
|
||||
}
|
||||
|
||||
void
|
||||
PluginsListDialog::filterPlagins (const QString &text)
|
||||
PluginsListDialog::filterPlugins (const QString &text)
|
||||
{
|
||||
for (int i = 0; i < m_pPlugins->count (); i++) {
|
||||
QListWidgetItem *pitem = m_pPlugins->item (i);
|
||||
|
@ -300,13 +326,24 @@ PluginsListDialog::filterPlagins (const QString &text)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
PluginsListDialog::favoritesClicked ()
|
||||
{
|
||||
QListWidgetItem *pitem = m_pPlugins->currentItem();
|
||||
if(!pitem)
|
||||
return;
|
||||
if (m_main->getFavoritesList()->isFavorite(pitem->text ()) != -1) {
|
||||
emit signalRemPluginToFav (pitem->text ());
|
||||
}
|
||||
else {
|
||||
emit signalAddPluginToFav (pitem->text ());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
PluginsListDialog::InitPluginsList ()
|
||||
{
|
||||
if (!m_pPluginsList)
|
||||
m_pPluginsList = new PluginsList ();
|
||||
|
||||
GList* plugins_list = m_pPluginsList->getList ();
|
||||
GList* plugins_list = PluginsList::instance().getList ();
|
||||
GList* l;
|
||||
std::size_t num = 0;
|
||||
|
||||
|
@ -316,3 +353,33 @@ PluginsListDialog::InitPluginsList ()
|
|||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
void PluginsListDialog::ProvideContextMenu(const QPoint &pos)
|
||||
{
|
||||
QPoint item = m_pPlugins->mapToGlobal(pos);
|
||||
QListWidgetItem* current_item = m_pPlugins->currentItem();
|
||||
|
||||
QMenu submenu;
|
||||
if (m_main->getFavoritesList()->isFavorite(current_item->text ()) != -1) {
|
||||
emit signalRemPluginToFav (current_item->text ());
|
||||
}
|
||||
else {
|
||||
emit signalAddPluginToFav (current_item->text ());
|
||||
}
|
||||
|
||||
if (m_main->getFavoritesList()->isFavorite(current_item->text ()) != -1)
|
||||
submenu.addAction("Add to favorites");
|
||||
else
|
||||
submenu.addAction("Remove from favorites");
|
||||
|
||||
QAction* rightClickItem = submenu.exec(item);
|
||||
if (rightClickItem) {
|
||||
if(rightClickItem->text().contains("Add to favorites") ) {
|
||||
LOG_INFO("Delete item: " + current_item->text());
|
||||
emit signalAddPluginToFav (current_item->text ());
|
||||
} else if(rightClickItem->text().contains("Remove from favorites") ) {
|
||||
LOG_INFO("Delete item: " + current_item->text());
|
||||
emit signalRemPluginToFav (current_item->text ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QListWidgetItem>
|
||||
#include <QPushButton>
|
||||
|
||||
#include "GraphManager.h"
|
||||
|
||||
|
@ -30,21 +31,26 @@ public:
|
|||
PluginsList();
|
||||
~PluginsList();
|
||||
|
||||
static PluginsList& instance();
|
||||
|
||||
GList* getList() {return m_pluginsList;}
|
||||
GList* getSortedByRank();
|
||||
GList* getPluginListByCaps(GstPadDirection direction, GstCaps* caps);
|
||||
GList* getPluginListFavorite();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
GList* m_pluginsList;
|
||||
GList* m_pluginsList; //list of plugins
|
||||
};
|
||||
|
||||
class MainWindow;
|
||||
|
||||
class PluginsListDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PluginsListDialog(PluginsList* pluginList, QWidget *pwgt = NULL, Qt::WindowFlags f = Qt::Window);
|
||||
PluginsListDialog(QWidget *pwgt = NULL, Qt::WindowFlags f = Qt::Window);
|
||||
~PluginsListDialog();
|
||||
|
||||
void setGraph(GraphManager* graph) {m_pGraph = graph;}
|
||||
|
@ -60,13 +66,20 @@ public slots:
|
|||
void insert(QListWidgetItem *);
|
||||
|
||||
private slots:
|
||||
void filterPlagins(const QString &text);
|
||||
void filterPlugins(const QString &text);
|
||||
void favoritesClicked();
|
||||
void ProvideContextMenu(const QPoint &pos);
|
||||
|
||||
signals:
|
||||
void signalAddPluginToFav (const QString &plugin_name);
|
||||
void signalRemPluginToFav (const QString &plugin_name);
|
||||
|
||||
private:
|
||||
MainWindow * m_main;
|
||||
QLabel *m_plblInfo;
|
||||
QListWidget *m_pPlugins;
|
||||
PluginsList *m_pPluginsList;
|
||||
GraphManager *m_pGraph;
|
||||
QPushButton*m_favoriteListButton;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue